[execution] Move v8::Locker::WasEverUsed() flag into Isolate
So far this flag was process-global, so if one isolate used v8::Locker all isolates were forced to use v8::Locker. With the shared isolate now being a thing that routinely gets migrated between different threads, all users of the shared isolate would be forced to use v8::Locker. So we now store that flag on the isolate such that using v8::Locker for the shared isolate does not affect other isolates. Deprecate v8::Locker::WasEverUsed() at the same time. Bug: v8:11708 Change-Id: I60531f084cc1b1b113620c46f5bed20511f52c26 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3401595 Reviewed-by: Camillo Bruni <cbruni@chromium.org> Reviewed-by: Michael Lippautz <mlippautz@chromium.org> Reviewed-by: Igor Sheludko <ishell@chromium.org> Commit-Queue: Dominik Inführ <dinfuehr@chromium.org> Cr-Commit-Position: refs/heads/main@{#78712}
This commit is contained in:
parent
3221e74a2e
commit
116ca00f20
@ -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();
|
||||
|
@ -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<i::Isolate*>(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);
|
||||
|
@ -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<bool> was_locker_ever_used_{false};
|
||||
StringStream* incomplete_message_ = nullptr;
|
||||
Address isolate_addresses_[kIsolateAddressCount + 1] = {};
|
||||
Bootstrapper* bootstrapper_ = nullptr;
|
||||
|
@ -31,8 +31,11 @@ void Locker::Initialize(v8::Isolate* isolate) {
|
||||
has_lock_ = false;
|
||||
top_level_ = true;
|
||||
isolate_ = reinterpret_cast<i::Isolate*>(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();
|
||||
|
@ -944,7 +944,7 @@ class Ticker : public sampler::Sampler {
|
||||
void SampleStack(const v8::RegisterState& state) override {
|
||||
if (!profiler_) return;
|
||||
Isolate* isolate = reinterpret_cast<Isolate*>(this->isolate());
|
||||
if (v8::Locker::WasEverUsed() &&
|
||||
if (isolate->was_locker_ever_used() &&
|
||||
(!isolate->thread_manager()->IsLockedByThread(
|
||||
perThreadData_->thread_id()) ||
|
||||
perThreadData_->thread_state() != nullptr))
|
||||
|
@ -40,7 +40,7 @@ class CpuSampler : public sampler::Sampler {
|
||||
|
||||
void SampleStack(const v8::RegisterState& regs) override {
|
||||
Isolate* isolate = reinterpret_cast<Isolate*>(this->isolate());
|
||||
if (v8::Locker::WasEverUsed() &&
|
||||
if (isolate->was_locker_ever_used() &&
|
||||
(!isolate->thread_manager()->IsLockedByThread(
|
||||
perThreadData_->thread_id()) ||
|
||||
perThreadData_->thread_state() != nullptr)) {
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user