diff --git a/v8/src/profiler/profile-generator.cc b/v8/src/profiler/profile-generator.cc --- a/v8/src/profiler/profile-generator.cc +++ b/v8/src/profiler/profile-generator.cc @@ -269,8 +269,15 @@ CpuProfileDeoptInfo CodeEntry::GetDeoptInfo() { } CodeEntry::RareData* CodeEntry::EnsureRareData() { if (!rare_data_) { - rare_data_.reset(new RareData()); + // rare_data_ is published from the SamplingEventsProcessor thread (via + // CodeDisableOpt/CodeDeopt event handling) and read on the main thread in + // bailout_reason()/has_deopt_info() while serializing a stopped profile + // that is not the last one (processor thread still running). Ensure the + // RareData constructor's field stores are visible before the pointer is. + RareData* rd = new RareData(); + std::atomic_thread_fence(std::memory_order_release); + rare_data_.reset(rd); } return rare_data_.get(); }