Commit 08c4224d authored by Andrew Comminos's avatar Andrew Comminos Committed by Commit Bot

Update the CodeEventObserver of a ProfilerListener when a v8::CpuProfiler is restarted

Fixes a segfault that occurs when v8::CpuProfilers are restarted caused
by the reuse of a stale CodeEventObserver.

Bug: chromium:929928
Change-Id: I5d5f7eaf5cd903910130cdb0cfec8c3fd6608edd
Reviewed-on: https://chromium-review.googlesource.com/c/1459740Reviewed-by: 's avatarAlexei Filippov <alph@chromium.org>
Reviewed-by: 's avatarPeter Marshall <petermarshall@chromium.org>
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59506}
parent 58ebbf34
......@@ -382,7 +382,9 @@ void CpuProfiler::StartProcessorIfNotStarted() {
}
processor_.reset(new SamplingEventsProcessor(isolate_, generator_.get(),
sampling_interval_));
if (!profiler_listener_) {
if (profiler_listener_) {
profiler_listener_->set_observer(processor_.get());
} else {
profiler_listener_.reset(new ProfilerListener(isolate_, processor_.get()));
}
logger->AddCodeEventListener(profiler_listener_.get());
......
......@@ -75,6 +75,8 @@ class ProfilerListener : public CodeEventListener {
return function_and_resource_names_.GetConsName(prefix, name);
}
void set_observer(CodeEventObserver* observer) { observer_ = observer; }
private:
void AttachDeoptInlinedFrames(Code code, CodeDeoptEventRecord* rec);
Name InferScriptName(Name name, SharedFunctionInfo info);
......
......@@ -2688,6 +2688,22 @@ TEST(MultipleProfilers) {
profiler2->StopProfiling("2");
}
// Tests that logged CodeCreateEvent calls do not crash a reused CpuProfiler.
// crbug.com/929928
TEST(CrashReusedProfiler) {
LocalContext env;
i::Isolate* isolate = CcTest::i_isolate();
i::HandleScope scope(isolate);
std::unique_ptr<CpuProfiler> profiler(new CpuProfiler(isolate));
profiler->StartProfiling("1");
profiler->StopProfiling("1");
profiler->StartProfiling("2");
CreateCode(&env);
profiler->StopProfiling("2");
}
void ProfileSomeCode(v8::Isolate* isolate) {
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope scope(isolate);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment