Commit d78d8b7d authored by Camillo Bruni's avatar Camillo Bruni Committed by V8 LUCI CQ

[api] Rename v8::Locker::IsActive to v8::Locker::WasEverUsed

IsActive is misleading as the current implementation forces to use
v8::Locker for all Isolate access once any Locker has been used in
the same process.

Bug: chromium:1240851
Change-Id: Ieb2cfa352313b6f2cbec1bafdbc94a3fc718f3d6
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3190093Reviewed-by: 's avatarDan Elphick <delphick@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77243}
parent a1e6efd8
......@@ -64,7 +64,7 @@ class Isolate;
* given thread. This can be useful if you have code that can be called either
* from code that holds the lock or from code that does not. The Unlocker is
* not recursive so you can not have several Unlockers on the stack at once, and
* you can not use an Unlocker in a thread that is not inside a Locker's scope.
* you cannot use an Unlocker in a thread that is not inside a Locker's scope.
*
* An unlocker will unlock several lockers if it has to and reinstate the
* correct depth of locking on its destruction, e.g.:
......@@ -122,8 +122,13 @@ class V8_EXPORT Locker {
static bool IsLocked(Isolate* isolate);
/**
* Returns whether v8::Locker is being used by this V8 instance.
* Returns whether any v8::Locker has ever been used in this process.
* TODO(cbruni, chromium:1240851): Fix locking checks on a per-thread basis.
* The current implementation is quite confusing and leads to unexpected
* results if anybody uses v8::Locker in the current process.
*/
static bool WasEverUsed();
V8_DEPRECATE_SOON("Use WasEverUsed instead")
static bool IsActive();
// Disallow copying and assigning.
......
......@@ -947,7 +947,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::IsActive() ||
!v8::Locker::WasEverUsed() ||
internal_isolate->thread_manager()->IsLockedByCurrentThread() ||
internal_isolate->serializer_enabled(),
"HandleScope::HandleScope",
......@@ -9036,7 +9036,7 @@ void Isolate::IsolateInBackgroundNotification() {
void Isolate::MemoryPressureNotification(MemoryPressureLevel level) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
bool on_isolate_thread =
v8::Locker::IsActive()
v8::Locker::WasEverUsed()
? isolate->thread_manager()->IsLockedByCurrentThread()
: i::ThreadId::Current() == isolate->thread_id();
isolate->heap()->MemoryPressureNotification(level, on_isolate_thread);
......
......@@ -20,7 +20,7 @@ namespace {
// Track whether this V8 instance has ever called v8::Locker. This allows the
// API code to verify that the lock is always held when V8 is being entered.
base::Atomic32 g_locker_was_ever_used_ = 0;
base::AtomicWord g_locker_was_ever_used_ = 0;
} // namespace
......@@ -53,8 +53,12 @@ bool Locker::IsLocked(v8::Isolate* isolate) {
return internal_isolate->thread_manager()->IsLockedByCurrentThread();
}
bool Locker::IsActive() {
return !!base::Relaxed_Load(&g_locker_was_ever_used_);
// static
bool Locker::IsActive() { return WasEverUsed(); }
// static
bool Locker::WasEverUsed() {
return base::Relaxed_Load(&g_locker_was_ever_used_) != 0;
}
Locker::~Locker() {
......
......@@ -944,7 +944,8 @@ 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::IsActive() && (!isolate->thread_manager()->IsLockedByThread(
if (v8::Locker::WasEverUsed() &&
(!isolate->thread_manager()->IsLockedByThread(
perThreadData_->thread_id()) ||
perThreadData_->thread_state() != nullptr))
return;
......
......@@ -40,7 +40,8 @@ class CpuSampler : public sampler::Sampler {
void SampleStack(const v8::RegisterState& regs) override {
Isolate* isolate = reinterpret_cast<Isolate*>(this->isolate());
if (v8::Locker::IsActive() && (!isolate->thread_manager()->IsLockedByThread(
if (v8::Locker::WasEverUsed() &&
(!isolate->thread_manager()->IsLockedByThread(
perThreadData_->thread_id()) ||
perThreadData_->thread_state() != nullptr)) {
ProfilerStats::Instance()->AddReason(
......
......@@ -122,7 +122,7 @@ void CcTest::Run() {
DCHECK_EQ(active_isolates, i::Isolate::non_disposed_isolates());
#endif // DEBUG
if (initialize_) {
if (v8::Locker::IsActive()) {
if (v8::Locker::WasEverUsed()) {
v8::Locker locker(isolate_);
EmptyMessageQueues(isolate_);
} else {
......
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