Commit 345518a0 authored by Dominik Inführ's avatar Dominik Inführ Committed by Commit Bot

[execution][heap] Make Isolate::is_profiling relaxed atomic

Concurrent allocation uses Isolate::is_profiling() to determine
whether logging is on. This races with the main thread when the
value in is_profiling is switched on/off by the cpu profiler.

Fix this by making is_profiling relaxed atomic. The profiler doesn't
turn off logging for correctness reasons, so it is fine when background
threads may read an old value and continue logging a bit longer. It is
also okay when background threads start logging again a bit longer when
profiling is stopped.

Bug: v8:10315
Change-Id: Id52d06f7a8239e10dfa63da38e761b2c00a2da4b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2404779
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarPeter Marshall <petermarshall@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69882}
parent dfcd2579
......@@ -5,6 +5,7 @@
#ifndef V8_EXECUTION_ISOLATE_H_
#define V8_EXECUTION_ISOLATE_H_
#include <atomic>
#include <cstddef>
#include <functional>
#include <memory>
......@@ -432,8 +433,6 @@ using DebugObjectCache = std::vector<Handle<HeapObject>>;
V(int, code_and_metadata_size, 0) \
V(int, bytecode_and_metadata_size, 0) \
V(int, external_script_source_size, 0) \
/* true if being profiled. Causes collection of extra compile info. */ \
V(bool, is_profiling, false) \
/* Number of CPU profilers running on the isolate. */ \
V(size_t, num_cpu_profilers, 0) \
/* true if a trace is being formatted through Error.prepareStackTrace. */ \
......@@ -1073,7 +1072,16 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
Debug* debug() { return debug_; }
bool* is_profiling_address() { return &is_profiling_; }
void* is_profiling_address() { return &is_profiling_; }
bool is_profiling() const {
return is_profiling_.load(std::memory_order_relaxed);
}
void set_is_profiling(bool enabled) {
is_profiling_.store(enabled, std::memory_order_relaxed);
}
CodeEventDispatcher* code_event_dispatcher() const {
return code_event_dispatcher_.get();
}
......@@ -1732,6 +1740,9 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
#endif // V8_INTL_SUPPORT
// true if being profiled. Causes collection of extra compile info.
std::atomic<bool> is_profiling_{false};
// Whether the isolate has been created for snapshotting.
bool serializer_enabled_ = false;
......
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