From 3e9f8a4f635e2d946651d6a4df81378266f32dc9 Mon Sep 17 00:00:00 2001 From: Peter Marshall Date: Tue, 8 May 2018 11:57:11 +0200 Subject: [PATCH] [cpu-profiler] Add a HandleScope to limit memory consumption. The handles created for each SharedFunctionInfo within SourcePosition::InliningStack live for the life of the profile, reaching 5MiB+ on an example server application for Node. This HandleScope limits their lifetime locally, given that the handles do not escape. This saves ~10% of peak memory. Bug: v8:7719 Change-Id: I97ce0fd3658be89fdd9cb9c1369ea5bfae0ce579 Reviewed-on: https://chromium-review.googlesource.com/1049647 Reviewed-by: Tobias Tebbi Reviewed-by: Alexei Filippov Commit-Queue: Peter Marshall Cr-Commit-Position: refs/heads/master@{#53085} --- src/profiler/profiler-listener.cc | 8 +++++++- src/profiler/profiler-listener.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/profiler/profiler-listener.cc b/src/profiler/profiler-listener.cc index 3b5a69c637..ecb1b952a9 100644 --- a/src/profiler/profiler-listener.cc +++ b/src/profiler/profiler-listener.cc @@ -17,7 +17,8 @@ namespace internal { ProfilerListener::ProfilerListener(Isolate* isolate, CodeEventObserver* observer) - : observer_(observer), + : isolate_(isolate), + observer_(observer), function_and_resource_names_(isolate->heap()->HashSeed()) {} ProfilerListener::~ProfilerListener() = default; @@ -276,6 +277,11 @@ void ProfilerListener::RecordDeoptInlinedFrames(CodeEntry* entry, int deopt_id = static_cast(info->data()); DCHECK(last_position.IsKnown()); std::vector inlined_frames; + + // SourcePosition::InliningStack allocates a handle for the SFI of each + // frame. These don't escape this function, but quickly add up. This + // scope limits their lifetime. + HandleScope scope(isolate_); for (SourcePositionInfo& pos_info : last_position.InliningStack(code)) { if (pos_info.position.ScriptOffset() == kNoSourcePosition) continue; if (!pos_info.function->script()->IsScript()) continue; diff --git a/src/profiler/profiler-listener.h b/src/profiler/profiler-listener.h index 42f98d9cfb..60021fe7b0 100644 --- a/src/profiler/profiler-listener.h +++ b/src/profiler/profiler-listener.h @@ -84,6 +84,7 @@ class ProfilerListener : public CodeEventListener { observer_->CodeEventHandler(evt_rec); } + Isolate* isolate_; CodeEventObserver* observer_; StringsStorage function_and_resource_names_; std::deque> code_entries_;