| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0c87776 commit b8529a7
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,7 +36,7 @@ | |||
| 36 | 36 | ||
| 37 | 37 | # Reset this number to 0 on major V8 upgrades. | |
| 38 | 38 | # Increment by one for each non-official patch applied to deps/v8. | |
| 39 | - 'v8_embedder_string': '-node.16', | ||
| 39 | + 'v8_embedder_string': '-node.17', | ||
| 40 | 40 | ||
| 41 | 41 | ##### V8 defaults for Node.js ##### | |
| 42 | 42 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10745,7 +10745,8 @@ static i::HeapSnapshot* ToInternal(const HeapSnapshot* snapshot) { | |||
| 10745 | 10745 | ||
| 10746 | 10746 | void HeapSnapshot::Delete() { | |
| 10747 | 10747 | i::Isolate* isolate = ToInternal(this)->profiler()->isolate(); | |
| 10748 | - if (isolate->heap_profiler()->GetSnapshotsCount() > 1) { | ||
| 10748 | + if (isolate->heap_profiler()->GetSnapshotsCount() > 1 || | ||
| 10749 | + isolate->heap_profiler()->IsTakingSnapshot()) { | ||
| 10749 | 10750 | ToInternal(this)->Delete(); | |
| 10750 | 10751 | } else { | |
| 10751 | 10752 | // If this is the last snapshot, clean up all accessory data as well. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,7 +18,8 @@ namespace internal { | |||
| 18 | 18 | HeapProfiler::HeapProfiler(Heap* heap) | |
| 19 | 19 | : ids_(new HeapObjectsMap(heap)), | |
| 20 | 20 | names_(new StringsStorage()), | |
| 21 | - is_tracking_object_moves_(false) {} | ||
| 21 | + is_tracking_object_moves_(false), | ||
| 22 | + is_taking_snapshot_(false) {} | ||
| 22 | 23 | ||
| 23 | 24 | HeapProfiler::~HeapProfiler() = default; | |
| 24 | 25 | ||
@@ -28,7 +29,8 @@ void HeapProfiler::DeleteAllSnapshots() { | |||
| 28 | 29 | } | |
| 29 | 30 | ||
| 30 | 31 | void HeapProfiler::MaybeClearStringsStorage() { | |
| 31 | - if (snapshots_.empty() && !sampling_heap_profiler_ && !allocation_tracker_) { | ||
| 32 | + if (snapshots_.empty() && !sampling_heap_profiler_ && !allocation_tracker_ && | ||
| 33 | + !is_taking_snapshot_) { | ||
| 32 | 34 | names_.reset(new StringsStorage()); | |
| 33 | 35 | } | |
| 34 | 36 | } | |
@@ -66,6 +68,7 @@ HeapSnapshot* HeapProfiler::TakeSnapshot( | |||
| 66 | 68 | v8::ActivityControl* control, | |
| 67 | 69 | v8::HeapProfiler::ObjectNameResolver* resolver, | |
| 68 | 70 | bool treat_global_objects_as_roots) { | |
| 71 | + is_taking_snapshot_ = true; | ||
| 69 | 72 | HeapSnapshot* result = new HeapSnapshot(this, treat_global_objects_as_roots); | |
| 70 | 73 | { | |
| 71 | 74 | HeapSnapshotGenerator generator(result, control, resolver, heap()); | |
@@ -78,6 +81,7 @@ HeapSnapshot* HeapProfiler::TakeSnapshot( | |||
| 78 | 81 | } | |
| 79 | 82 | ids_->RemoveDeadEntries(); | |
| 80 | 83 | is_tracking_object_moves_ = true; | |
| 84 | + is_taking_snapshot_ = false; | ||
| 81 | 85 | ||
| 82 | 86 | heap()->isolate()->debug()->feature_tracker()->Track( | |
| 83 | 87 | DebugFeatureTracker::kHeapSnapshot); | |
@@ -138,10 +142,12 @@ void HeapProfiler::StopHeapObjectsTracking() { | |||
| 138 | 142 | } | |
| 139 | 143 | } | |
| 140 | 144 | ||
| 141 | - int HeapProfiler::GetSnapshotsCount() { | ||
| 145 | + int HeapProfiler::GetSnapshotsCount() const { | ||
| 142 | 146 | return static_cast<int>(snapshots_.size()); | |
| 143 | 147 | } | |
| 144 | 148 | ||
| 149 | + bool HeapProfiler::IsTakingSnapshot() const { return is_taking_snapshot_; } | ||
| 150 | + | ||
| 145 | 151 | HeapSnapshot* HeapProfiler::GetSnapshot(int index) { | |
| 146 | 152 | return snapshots_.at(index).get(); | |
| 147 | 153 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -49,7 +49,8 @@ class HeapProfiler : public HeapObjectAllocationTracker { | |||
| 49 | 49 | ||
| 50 | 50 | SnapshotObjectId PushHeapObjectsStats(OutputStream* stream, | |
| 51 | 51 | int64_t* timestamp_us); | |
| 52 | - int GetSnapshotsCount(); | ||
| 52 | + int GetSnapshotsCount() const; | ||
| 53 | + bool IsTakingSnapshot() const; | ||
| 53 | 54 | HeapSnapshot* GetSnapshot(int index); | |
| 54 | 55 | SnapshotObjectId GetSnapshotObjectId(Handle<Object> obj); | |
| 55 | 56 | SnapshotObjectId GetSnapshotObjectId(NativeObject obj); | |
@@ -93,6 +94,7 @@ class HeapProfiler : public HeapObjectAllocationTracker { | |||
| 93 | 94 | std::unique_ptr<StringsStorage> names_; | |
| 94 | 95 | std::unique_ptr<AllocationTracker> allocation_tracker_; | |
| 95 | 96 | bool is_tracking_object_moves_; | |
| 97 | + bool is_taking_snapshot_; | ||
| 96 | 98 | base::Mutex profiler_mutex_; | |
| 97 | 99 | std::unique_ptr<SamplingHeapProfiler> sampling_heap_profiler_; | |
| 98 | 100 | std::vector<std::pair<v8::HeapProfiler::BuildEmbedderGraphCallback, void*>> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4126,3 +4126,40 @@ TEST(Bug8373_2) { | |||
| 4126 | 4126 | ||
| 4127 | 4127 | heap_profiler->StopTrackingHeapObjects(); | |
| 4128 | 4128 | } | |
| 4129 | + | ||
| 4130 | + TEST(HeapSnapshotDeleteDuringTakeSnapshot) { | ||
| 4131 | + // Check that a heap snapshot can be deleted during GC while another one | ||
| 4132 | + // is being taken. | ||
| 4133 | + | ||
| 4134 | + LocalContext env; | ||
| 4135 | + v8::HandleScope scope(env->GetIsolate()); | ||
| 4136 | + v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | ||
| 4137 | + int gc_calls = 0; | ||
| 4138 | + v8::Global<v8::Object> handle; | ||
| 4139 | + | ||
| 4140 | + { | ||
| 4141 | + struct WeakData { | ||
| 4142 | + const v8::HeapSnapshot* snapshot; | ||
| 4143 | + int* gc_calls; | ||
| 4144 | + v8::Global<v8::Object>* handle; | ||
| 4145 | + }; | ||
| 4146 | + WeakData* data = | ||
| 4147 | + new WeakData{heap_profiler->TakeHeapSnapshot(), &gc_calls, &handle}; | ||
| 4148 | + | ||
| 4149 | + v8::HandleScope scope(env->GetIsolate()); | ||
| 4150 | + handle.Reset(env->GetIsolate(), v8::Object::New(env->GetIsolate())); | ||
| 4151 | + handle.SetWeak( | ||
| 4152 | + data, | ||
| 4153 | + [](const v8::WeakCallbackInfo<WeakData>& data) { | ||
| 4154 | + std::unique_ptr<WeakData> weakdata{data.GetParameter()}; | ||
| 4155 | + const_cast<v8::HeapSnapshot*>(weakdata->snapshot)->Delete(); | ||
| 4156 | + ++*weakdata->gc_calls; | ||
| 4157 | + weakdata->handle->Reset(); | ||
| 4158 | + }, | ||
| 4159 | + v8::WeakCallbackType::kParameter); | ||
| 4160 | + } | ||
| 4161 | + CHECK_EQ(gc_calls, 0); | ||
| 4162 | + | ||
| 4163 | + CHECK(ValidateSnapshot(heap_profiler->TakeHeapSnapshot())); | ||
| 4164 | + CHECK_EQ(gc_calls, 1); | ||
| 4165 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments