Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: cherry-pick b87d408 from upstream V8 #24272

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

# Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8.
'v8_embedder_string': '-node.37',
'v8_embedder_string': '-node.39',

# Enable disassembler for `--print-code` v8 options
'v8_enable_disassembler': 1,
Expand Down
9 changes: 8 additions & 1 deletion deps/v8/src/profiler/heap-profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ HeapProfiler::~HeapProfiler() = default;

void HeapProfiler::DeleteAllSnapshots() {
snapshots_.clear();
names_.reset(new StringsStorage());
MaybeClearStringsStorage();
}

void HeapProfiler::MaybeClearStringsStorage() {
if (snapshots_.empty() && !sampling_heap_profiler_ && !allocation_tracker_) {
names_.reset(new StringsStorage());
}
}

void HeapProfiler::RemoveSnapshot(HeapSnapshot* snapshot) {
snapshots_.erase(
Expand Down Expand Up @@ -126,6 +131,7 @@ bool HeapProfiler::StartSamplingHeapProfiler(

void HeapProfiler::StopSamplingHeapProfiler() {
sampling_heap_profiler_.reset();
MaybeClearStringsStorage();
}


Expand Down Expand Up @@ -159,6 +165,7 @@ void HeapProfiler::StopHeapObjectsTracking() {
ids_->StopHeapObjectsTracking();
if (allocation_tracker_) {
allocation_tracker_.reset();
MaybeClearStringsStorage();
heap()->RemoveHeapObjectAllocationTracker(this);
}
}
Expand Down
2 changes: 2 additions & 0 deletions deps/v8/src/profiler/heap-profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ class HeapProfiler : public HeapObjectAllocationTracker {
v8::PersistentValueVector<v8::Object>* objects);

private:
void MaybeClearStringsStorage();

Heap* heap() const;

// Mapping from HeapObject addresses to objects' uids.
Expand Down
42 changes: 42 additions & 0 deletions deps/v8/test/cctest/test-heap-profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3690,3 +3690,45 @@ TEST(WeakReference) {
const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot();
CHECK(ValidateSnapshot(snapshot));
}

TEST(Bug8373_1) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();

heap_profiler->StartSamplingHeapProfiler(100);

heap_profiler->TakeHeapSnapshot();
// Causes the StringsStorage to be deleted.
heap_profiler->DeleteAllHeapSnapshots();

// Triggers an allocation sample that tries to use the StringsStorage.
for (int i = 0; i < 2 * 1024; ++i) {
CompileRun(
"new Array(64);"
"new Uint8Array(16);");
}

heap_profiler->StopSamplingHeapProfiler();
}

TEST(Bug8373_2) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();

heap_profiler->StartTrackingHeapObjects(true);

heap_profiler->TakeHeapSnapshot();
// Causes the StringsStorage to be deleted.
heap_profiler->DeleteAllHeapSnapshots();

// Triggers an allocations that try to use the StringsStorage.
for (int i = 0; i < 2 * 1024; ++i) {
CompileRun(
"new Array(64);"
"new Uint8Array(16);");
}

heap_profiler->StopTrackingHeapObjects();
}