diff --git a/include/v8-locker.h b/include/v8-locker.h index 88ce4beb62..7ca5bf6e42 100644 --- a/include/v8-locker.h +++ b/include/v8-locker.h @@ -127,6 +127,7 @@ class V8_EXPORT Locker { * The current implementation is quite confusing and leads to unexpected * results if anybody uses v8::Locker in the current process. */ + V8_DEPRECATE_SOON("This method will be removed.") static bool WasEverUsed(); V8_DEPRECATED("Use WasEverUsed instead") static bool IsActive(); diff --git a/src/api/api.cc b/src/api/api.cc index 5e49882331..2011f4ac4b 100644 --- a/src/api/api.cc +++ b/src/api/api.cc @@ -961,7 +961,7 @@ void HandleScope::Initialize(Isolate* isolate) { // We make an exception if the serializer is enabled, which means that the // Isolate is exclusively used to create a snapshot. Utils::ApiCheck( - !v8::Locker::WasEverUsed() || + !internal_isolate->was_locker_ever_used() || internal_isolate->thread_manager()->IsLockedByCurrentThread() || internal_isolate->serializer_enabled(), "HandleScope::HandleScope", @@ -9306,7 +9306,7 @@ void Isolate::IsolateInBackgroundNotification() { void Isolate::MemoryPressureNotification(MemoryPressureLevel level) { i::Isolate* isolate = reinterpret_cast(this); bool on_isolate_thread = - v8::Locker::WasEverUsed() + isolate->was_locker_ever_used() ? isolate->thread_manager()->IsLockedByCurrentThread() : i::ThreadId::Current() == isolate->thread_id(); isolate->heap()->MemoryPressureNotification(level, on_isolate_thread); diff --git a/src/execution/isolate.h b/src/execution/isolate.h index 89e09c3f4e..4d53fcd3fb 100644 --- a/src/execution/isolate.h +++ b/src/execution/isolate.h @@ -1484,6 +1484,13 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory { int id() const { return id_; } + bool was_locker_ever_used() const { + return was_locker_ever_used_.load(std::memory_order_relaxed); + } + void set_was_locker_ever_used() { + was_locker_ever_used_.store(true, std::memory_order_relaxed); + } + CompilationStatistics* GetTurboStatistics(); CodeTracer* GetCodeTracer(); @@ -2056,6 +2063,7 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory { const int id_; EntryStackItem* entry_stack_ = nullptr; int stack_trace_nesting_level_ = 0; + std::atomic was_locker_ever_used_{false}; StringStream* incomplete_message_ = nullptr; Address isolate_addresses_[kIsolateAddressCount + 1] = {}; Bootstrapper* bootstrapper_ = nullptr; diff --git a/src/execution/v8threads.cc b/src/execution/v8threads.cc index 9fb8f1c30c..e06f49c5c0 100644 --- a/src/execution/v8threads.cc +++ b/src/execution/v8threads.cc @@ -31,8 +31,11 @@ void Locker::Initialize(v8::Isolate* isolate) { has_lock_ = false; top_level_ = true; isolate_ = reinterpret_cast(isolate); + // Record that the Locker has been used at least once. base::Relaxed_Store(&g_locker_was_ever_used_, 1); + isolate_->set_was_locker_ever_used(); + // Get the big lock if necessary. if (!isolate_->thread_manager()->IsLockedByCurrentThread()) { isolate_->thread_manager()->Lock(); diff --git a/src/logging/log.cc b/src/logging/log.cc index 05ecbed7ae..ec6beb95e8 100644 --- a/src/logging/log.cc +++ b/src/logging/log.cc @@ -944,7 +944,7 @@ class Ticker : public sampler::Sampler { void SampleStack(const v8::RegisterState& state) override { if (!profiler_) return; Isolate* isolate = reinterpret_cast(this->isolate()); - if (v8::Locker::WasEverUsed() && + if (isolate->was_locker_ever_used() && (!isolate->thread_manager()->IsLockedByThread( perThreadData_->thread_id()) || perThreadData_->thread_state() != nullptr)) diff --git a/src/profiler/cpu-profiler.cc b/src/profiler/cpu-profiler.cc index 5c5cb6d0fd..1c718d300b 100644 --- a/src/profiler/cpu-profiler.cc +++ b/src/profiler/cpu-profiler.cc @@ -40,7 +40,7 @@ class CpuSampler : public sampler::Sampler { void SampleStack(const v8::RegisterState& regs) override { Isolate* isolate = reinterpret_cast(this->isolate()); - if (v8::Locker::WasEverUsed() && + if (isolate->was_locker_ever_used() && (!isolate->thread_manager()->IsLockedByThread( perThreadData_->thread_id()) || perThreadData_->thread_state() != nullptr)) { diff --git a/test/cctest/cctest.cc b/test/cctest/cctest.cc index e25f4a4020..1d32660076 100644 --- a/test/cctest/cctest.cc +++ b/test/cctest/cctest.cc @@ -122,7 +122,7 @@ void CcTest::Run() { DCHECK_EQ(active_isolates, i::Isolate::non_disposed_isolates()); #endif // DEBUG if (initialize_) { - if (v8::Locker::WasEverUsed()) { + if (i_isolate()->was_locker_ever_used()) { v8::Locker locker(isolate_); EmptyMessageQueues(isolate_); } else {