Skip to content

Commit a2a5a49

Browse files
ofrobotsCommit Bot
authored andcommitted
[profiler] specially mark allocations during deopt
Deoptimization may materialize values on the heap, which may get sampled by the heap profiler. Such samples have imprecise stack. Indicate this. BUG=v8:7314 Change-Id: I21ab079c36fc0492b05b546cc1d6a8e6c042aeb8 Reviewed-on: https://chromium-review.googlesource.com/877119 Commit-Queue: Ali Ijaz Sheikh <[email protected]> Reviewed-by: Michael Stanton <[email protected]> Reviewed-by: Michael Starzinger <[email protected]> Cr-Commit-Position: refs/heads/master@{#50775}
1 parent 37cb3f5 commit a2a5a49

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

src/profiler/sampling-heap-profiler.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ SamplingHeapProfiler::AllocationNode* SamplingHeapProfiler::AddStack() {
148148
std::vector<SharedFunctionInfo*> stack;
149149
JavaScriptFrameIterator it(isolate_);
150150
int frames_captured = 0;
151+
bool found_arguments_marker_frames = false;
151152
while (!it.done() && frames_captured < stack_depth_) {
152153
JavaScriptFrame* frame = it.frame();
153154
// If we are materializing objects during deoptimization, inlined
@@ -159,6 +160,8 @@ SamplingHeapProfiler::AllocationNode* SamplingHeapProfiler::AddStack() {
159160
SharedFunctionInfo* shared = frame->function()->shared();
160161
stack.push_back(shared);
161162
frames_captured++;
163+
} else {
164+
found_arguments_marker_frames = true;
162165
}
163166
it.Advance();
164167
}
@@ -206,6 +209,12 @@ SamplingHeapProfiler::AllocationNode* SamplingHeapProfiler::AddStack() {
206209
}
207210
node = node->FindOrAddChildNode(name, script_id, shared->start_position());
208211
}
212+
213+
if (found_arguments_marker_frames) {
214+
node =
215+
node->FindOrAddChildNode("(deopt)", v8::UnboundScript::kNoScriptId, 0);
216+
}
217+
209218
return node;
210219
}
211220

test/cctest/test-heap-profiler.cc

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3080,7 +3080,7 @@ TEST(SamplingHeapProfilerPretenuredInlineAllocations) {
30803080
// Suppress randomness to avoid flakiness in tests.
30813081
v8::internal::FLAG_sampling_heap_profiler_suppress_randomness = true;
30823082

3083-
// Grow new space unitl maximum capacity reached.
3083+
// Grow new space until maximum capacity reached.
30843084
while (!CcTest::heap()->new_space()->IsAtMaximumCapacity()) {
30853085
CcTest::heap()->new_space()->Grow();
30863086
}
@@ -3171,3 +3171,49 @@ TEST(HeapSnapshotPrototypeNotJSReceiver) {
31713171
const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot();
31723172
CHECK(ValidateSnapshot(snapshot));
31733173
}
3174+
3175+
TEST(SamplingHeapProfilerSampleDuringDeopt) {
3176+
i::FLAG_allow_natives_syntax = true;
3177+
3178+
v8::HandleScope scope(v8::Isolate::GetCurrent());
3179+
LocalContext env;
3180+
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
3181+
3182+
// Suppress randomness to avoid flakiness in tests.
3183+
v8::internal::FLAG_sampling_heap_profiler_suppress_randomness = true;
3184+
3185+
// Small sample interval to force each object to be sampled.
3186+
heap_profiler->StartSamplingHeapProfiler(i::kPointerSize);
3187+
3188+
// Lazy deopt from runtime call from inlined callback function.
3189+
const char* source =
3190+
"var b = "
3191+
" [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25];"
3192+
"(function f() {"
3193+
" var result = 0;"
3194+
" var lazyDeopt = function(deopt) {"
3195+
" var callback = function(v,i,o) {"
3196+
" result += i;"
3197+
" if (i == 13 && deopt) {"
3198+
" %DeoptimizeNow();"
3199+
" }"
3200+
" return v;"
3201+
" };"
3202+
" b.map(callback);"
3203+
" };"
3204+
" lazyDeopt();"
3205+
" lazyDeopt();"
3206+
" %OptimizeFunctionOnNextCall(lazyDeopt);"
3207+
" lazyDeopt();"
3208+
" lazyDeopt(true);"
3209+
" lazyDeopt();"
3210+
"})();";
3211+
3212+
CompileRun(source);
3213+
// Should not crash.
3214+
3215+
std::unique_ptr<v8::AllocationProfile> profile(
3216+
heap_profiler->GetAllocationProfile());
3217+
CHECK(profile);
3218+
heap_profiler->StopSamplingHeapProfiler();
3219+
}

0 commit comments

Comments
 (0)