Skip to content

Commit 2837cb3

Browse files
ofrobotsCommit bot
authored andcommitted
disallow left-trim fast path when sampling heap profiler is active
Left trimming assumes that nobody other than the JSArray has a reference to the backing store. Sampling heap profiler may profile the backing store and keep a reference too it. This reference was never updated on a left-trim, causing a crash. [email protected], [email protected], [email protected] BUG= Review URL: https://codereview.chromium.org/1885723002 Cr-Commit-Position: refs/heads/master@{#35449}
1 parent 98401b8 commit 2837cb3

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

src/heap/heap.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3075,6 +3075,9 @@ void Heap::CreateFillerObjectAt(Address addr, int size,
30753075
bool Heap::CanMoveObjectStart(HeapObject* object) {
30763076
if (!FLAG_move_object_start) return false;
30773077

3078+
// Sampling heap profiler may have a reference to the object.
3079+
if (isolate()->heap_profiler()->is_sampling_allocations()) return false;
3080+
30783081
Address address = object->address();
30793082

30803083
if (lo_space()->Contains(object)) return false;

src/profiler/heap-profiler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class HeapProfiler {
3232

3333
bool StartSamplingHeapProfiler(uint64_t sample_interval, int stack_depth);
3434
void StopSamplingHeapProfiler();
35+
bool is_sampling_allocations() { return !sampling_heap_profiler_.is_empty(); }
3536
AllocationProfile* GetAllocationProfile();
3637

3738
void StartHeapObjectsTracking(bool track_allocations);

test/cctest/test-heap-profiler.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3040,3 +3040,28 @@ TEST(SamplingHeapProfilerApiAllocation) {
30403040

30413041
heap_profiler->StopSamplingHeapProfiler();
30423042
}
3043+
3044+
TEST(SamplingHeapProfilerLeftTrimming) {
3045+
v8::HandleScope scope(v8::Isolate::GetCurrent());
3046+
LocalContext env;
3047+
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
3048+
3049+
// Suppress randomness to avoid flakiness in tests.
3050+
v8::internal::FLAG_sampling_heap_profiler_suppress_randomness = true;
3051+
3052+
heap_profiler->StartSamplingHeapProfiler(64);
3053+
3054+
CompileRun(
3055+
"for (var j = 0; j < 500; ++j) {\n"
3056+
" var a = [];\n"
3057+
" for (var i = 0; i < 5; ++i)\n"
3058+
" a[i] = i;\n"
3059+
" for (var i = 0; i < 3; ++i)\n"
3060+
" a.shift();\n"
3061+
"}\n");
3062+
3063+
CcTest::heap()->CollectGarbage(v8::internal::NEW_SPACE);
3064+
// Should not crash.
3065+
3066+
heap_profiler->StopSamplingHeapProfiler();
3067+
}

0 commit comments

Comments
 (0)