Commit 6d78dbdb authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

Switch Isolate to std::atomic

Remove another use of atomicops.

R=mstarzinger@chromium.org

Bug: v8:8834
Change-Id: Ide1aa87f4bb4cdc4346fe7b1bf78b8118592c7ae
Reviewed-on: https://chromium-review.googlesource.com/c/1491603
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59935}
parent ca5a4ed9
......@@ -296,11 +296,15 @@ size_t Isolate::HashIsolateForEmbeddedBlob() {
base::Thread::LocalStorageKey Isolate::isolate_key_;
base::Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_;
base::Atomic32 Isolate::isolate_counter_ = 0;
#if DEBUG
base::Atomic32 Isolate::isolate_key_created_ = 0;
std::atomic<bool> Isolate::isolate_key_created_{false};
#endif
namespace {
// A global counter for all generated Isolates, might overflow.
std::atomic<int> isolate_counter{0};
} // namespace
Isolate::PerIsolateThreadData*
Isolate::FindOrAllocatePerThreadDataForThisThread() {
ThreadId thread_id = ThreadId::Current();
......@@ -352,7 +356,9 @@ Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThread(
void Isolate::InitializeOncePerProcess() {
isolate_key_ = base::Thread::CreateThreadLocalKey();
#if DEBUG
base::Relaxed_Store(&isolate_key_created_, 1);
bool expected = false;
DCHECK_EQ(true, isolate_key_created_.compare_exchange_strong(
expected, true, std::memory_order_relaxed));
#endif
per_isolate_thread_data_key_ = base::Thread::CreateThreadLocalKey();
}
......@@ -2817,7 +2823,7 @@ void Isolate::Delete(Isolate* isolate) {
// direct pointer. We don't use Enter/Exit here to avoid
// initializing the thread data.
PerIsolateThreadData* saved_data = isolate->CurrentPerIsolateThreadData();
DCHECK_EQ(base::Relaxed_Load(&isolate_key_created_), 1);
DCHECK_EQ(true, isolate_key_created_.load(std::memory_order_relaxed));
Isolate* saved_isolate = reinterpret_cast<Isolate*>(
base::Thread::GetThreadLocal(isolate->isolate_key_));
SetIsolateThreadLocals(isolate, nullptr);
......@@ -2846,7 +2852,7 @@ v8::PageAllocator* Isolate::page_allocator() {
Isolate::Isolate(std::unique_ptr<i::IsolateAllocator> isolate_allocator)
: isolate_allocator_(std::move(isolate_allocator)),
id_(base::Relaxed_AtomicIncrement(&isolate_counter_, 1)),
id_(isolate_counter.fetch_add(1, std::memory_order_relaxed)),
stack_guard_(this),
allocator_(FLAG_trace_zone_stats ? new VerboseAccountingAllocator(
&heap_, 256 * KB, 128 * KB)
......@@ -4497,12 +4503,12 @@ double Isolate::LoadStartTimeMs() {
}
void Isolate::SetRAILMode(RAILMode rail_mode) {
RAILMode old_rail_mode = rail_mode_.Value();
RAILMode old_rail_mode = rail_mode_.load();
if (old_rail_mode != PERFORMANCE_LOAD && rail_mode == PERFORMANCE_LOAD) {
base::MutexGuard guard(&rail_mutex_);
load_start_time_ms_ = heap()->MonotonicallyIncreasingTimeInMs();
}
rail_mode_.SetValue(rail_mode);
rail_mode_.store(rail_mode);
if (old_rail_mode == PERFORMANCE_LOAD && rail_mode != PERFORMANCE_LOAD) {
heap()->incremental_marking()->incremental_marking_job()->ScheduleTask(
heap());
......
......@@ -16,7 +16,6 @@
#include "include/v8-internal.h"
#include "include/v8.h"
#include "src/allocation.h"
#include "src/base/atomicops.h"
#include "src/base/macros.h"
#include "src/builtins/builtins.h"
#include "src/contexts.h"
......@@ -499,7 +498,7 @@ class Isolate final : private HiddenFactory {
// Returns the isolate inside which the current thread is running or nullptr.
V8_INLINE static Isolate* TryGetCurrent() {
DCHECK_EQ(base::Relaxed_Load(&isolate_key_created_), 1);
DCHECK_EQ(true, isolate_key_created_.load(std::memory_order_relaxed));
return reinterpret_cast<Isolate*>(
base::Thread::GetExistingThreadLocal(isolate_key_));
}
......@@ -1248,7 +1247,7 @@ class Isolate final : private HiddenFactory {
// compile dispatcher's queue.
void AbortConcurrentOptimization(BlockingBehavior blocking_behavior);
int id() const { return static_cast<int>(id_); }
int id() const { return id_; }
CompilationStatistics* GetTurboStatistics();
CodeTracer* GetCodeTracer();
......@@ -1450,7 +1449,7 @@ class Isolate final : private HiddenFactory {
void SetRAILMode(RAILMode rail_mode);
RAILMode rail_mode() { return rail_mode_.Value(); }
RAILMode rail_mode() { return rail_mode_.load(); }
double LoadStartTimeMs();
......@@ -1548,11 +1547,8 @@ class Isolate final : private HiddenFactory {
static base::Thread::LocalStorageKey per_isolate_thread_data_key_;
static base::Thread::LocalStorageKey isolate_key_;
// A global counter for all generated Isolates, might overflow.
static base::Atomic32 isolate_counter_;
#if DEBUG
static base::Atomic32 isolate_key_created_;
#ifdef DEBUG
static std::atomic<bool> isolate_key_created_;
#endif
void Deinit();
......@@ -1599,7 +1595,7 @@ class Isolate final : private HiddenFactory {
std::unique_ptr<IsolateAllocator> isolate_allocator_;
Heap heap_;
base::Atomic32 id_;
const int id_;
EntryStackItem* entry_stack_ = nullptr;
int stack_trace_nesting_level_ = 0;
StringStream* incomplete_message_ = nullptr;
......@@ -1641,7 +1637,7 @@ class Isolate final : private HiddenFactory {
DateCache* date_cache_ = nullptr;
base::RandomNumberGenerator* random_number_generator_ = nullptr;
base::RandomNumberGenerator* fuzzer_rng_ = nullptr;
base::AtomicValue<RAILMode> rail_mode_;
std::atomic<RAILMode> rail_mode_;
v8::Isolate::AtomicsWaitCallback atomics_wait_callback_ = nullptr;
void* atomics_wait_callback_data_ = nullptr;
PromiseHook promise_hook_ = nullptr;
......
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