Commit c92a1dda authored by Peter Marshall's avatar Peter Marshall Committed by Commit Bot

[cpu-profiler] Fix a bug which caused a pure virtual function call

We need to remove each Sampler from the SamplerManager before we call
the Sampler destructor. This is because the signal handler can interrupt
the destructor, and call DoSampler(), which calls sampler->SampleStack()
on the sampler being destructed, causing general unhappiness and
"Pure virtual function called!" crashes.

Bug: v8:8346, v8:5193
Change-Id: Iaa595a196eab33fb1af31584e9a68fd1ce0a18f6
Reviewed-on: https://chromium-review.googlesource.com/c/1293949
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Reviewed-by: 's avatarAlexei Filippov <alph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56882}
parent fcbb023b
......@@ -615,13 +615,18 @@ Sampler::Sampler(Isolate* isolate)
data_ = new PlatformData;
}
Sampler::~Sampler() {
DCHECK(!IsActive());
void Sampler::UnregisterIfRegistered() {
#if defined(USE_SIGNALS)
if (IsRegistered()) {
SamplerManager::instance()->RemoveSampler(this);
SetRegistered(false);
}
#endif
}
Sampler::~Sampler() {
DCHECK(!IsActive());
DCHECK(!IsRegistered());
delete data_;
}
......
......@@ -60,6 +60,12 @@ class Sampler {
// with the CpuProfiler.
bool IsRegistered() const { return base::Relaxed_Load(&registered_) != 0; }
// The sampler must be unregistered with the SamplerManager before ~Sampler()
// is called. If this doesn't happen, the signal handler might interrupt
// during the destructor and call DoSample(), which calls the pure virtual
// function Sampler::SampleStack(), causing a crash.
void UnregisterIfRegistered();
void DoSample();
void SetHasProcessingThread(bool value) {
......
......@@ -65,6 +65,7 @@ SamplingEventsProcessor::SamplingEventsProcessor(Isolate* isolate,
SamplingEventsProcessor::~SamplingEventsProcessor() {
sampler_->DecreaseProfilingDepth();
sampler_->UnregisterIfRegistered();
}
ProfilerEventsProcessor::~ProfilerEventsProcessor() = default;
......
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