Commit 3512fab3 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

Refactor lazily initialized singletons in simulators

Use the slimmer base::LeakyObject instead of base::LazyInstance.

R=tebbi@chromium.org

Bug: v8:8600
Change-Id: I71755db9fe3ea9c61be2cdf009a006947ef5560a
Reviewed-on: https://chromium-review.googlesource.com/c/1392203Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58544}
parent aaec5fd5
This diff is collapsed.
...@@ -447,8 +447,6 @@ class Simulator : public SimulatorBase { ...@@ -447,8 +447,6 @@ class Simulator : public SimulatorBase {
class GlobalMonitor { class GlobalMonitor {
public: public:
GlobalMonitor();
class Processor { class Processor {
public: public:
Processor(); Processor();
...@@ -484,16 +482,21 @@ class Simulator : public SimulatorBase { ...@@ -484,16 +482,21 @@ class Simulator : public SimulatorBase {
// Called when the simulator is destroyed. // Called when the simulator is destroyed.
void RemoveProcessor(Processor* processor); void RemoveProcessor(Processor* processor);
static GlobalMonitor* Get();
private: private:
// Private constructor. Call {GlobalMonitor::Get()} to get the singleton.
GlobalMonitor() = default;
friend class base::LeakyObject<GlobalMonitor>;
bool IsProcessorInLinkedList_Locked(Processor* processor) const; bool IsProcessorInLinkedList_Locked(Processor* processor) const;
void PrependProcessor_Locked(Processor* processor); void PrependProcessor_Locked(Processor* processor);
Processor* head_; Processor* head_ = nullptr;
}; };
LocalMonitor local_monitor_; LocalMonitor local_monitor_;
GlobalMonitor::Processor global_monitor_processor_; GlobalMonitor::Processor global_monitor_processor_;
static base::LazyInstance<GlobalMonitor>::type global_monitor_;
}; };
} // namespace internal } // namespace internal
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "src/arm64/decoder-arm64-inl.h" #include "src/arm64/decoder-arm64-inl.h"
#include "src/assembler-inl.h" #include "src/assembler-inl.h"
#include "src/base/lazy-instance.h"
#include "src/codegen.h" #include "src/codegen.h"
#include "src/disasm.h" #include "src/disasm.h"
#include "src/macro-assembler.h" #include "src/macro-assembler.h"
...@@ -57,9 +58,8 @@ TEXT_COLOUR clr_debug_number = FLAG_log_colour ? COLOUR_BOLD(YELLOW) : ""; ...@@ -57,9 +58,8 @@ TEXT_COLOUR clr_debug_number = FLAG_log_colour ? COLOUR_BOLD(YELLOW) : "";
TEXT_COLOUR clr_debug_message = FLAG_log_colour ? COLOUR(YELLOW) : ""; TEXT_COLOUR clr_debug_message = FLAG_log_colour ? COLOUR(YELLOW) : "";
TEXT_COLOUR clr_printf = FLAG_log_colour ? COLOUR(GREEN) : ""; TEXT_COLOUR clr_printf = FLAG_log_colour ? COLOUR(GREEN) : "";
// static DEFINE_LAZY_LEAKY_OBJECT_GETTER(Simulator::GlobalMonitor,
base::LazyInstance<Simulator::GlobalMonitor>::type Simulator::global_monitor_ = Simulator::GlobalMonitor::Get);
LAZY_INSTANCE_INITIALIZER;
// This is basically the same as PrintF, with a guard for FLAG_trace_sim. // This is basically the same as PrintF, with a guard for FLAG_trace_sim.
void Simulator::TraceSim(const char* format, ...) { void Simulator::TraceSim(const char* format, ...) {
...@@ -367,7 +367,7 @@ void Simulator::ResetState() { ...@@ -367,7 +367,7 @@ void Simulator::ResetState() {
Simulator::~Simulator() { Simulator::~Simulator() {
global_monitor_.Pointer()->RemoveProcessor(&global_monitor_processor_); GlobalMonitor::Get()->RemoveProcessor(&global_monitor_processor_);
delete[] reinterpret_cast<byte*>(stack_); delete[] reinterpret_cast<byte*>(stack_);
if (FLAG_log_instruction_stats) { if (FLAG_log_instruction_stats) {
delete instrument_; delete instrument_;
...@@ -1779,12 +1779,12 @@ void Simulator::LoadStoreHelper(Instruction* instr, ...@@ -1779,12 +1779,12 @@ void Simulator::LoadStoreHelper(Instruction* instr,
uintptr_t stack = 0; uintptr_t stack = 0;
{ {
base::MutexGuard lock_guard(&global_monitor_.Pointer()->mutex); base::MutexGuard lock_guard(&GlobalMonitor::Get()->mutex);
if (instr->IsLoad()) { if (instr->IsLoad()) {
local_monitor_.NotifyLoad(); local_monitor_.NotifyLoad();
} else { } else {
local_monitor_.NotifyStore(); local_monitor_.NotifyStore();
global_monitor_.Pointer()->NotifyStore_Locked(&global_monitor_processor_); GlobalMonitor::Get()->NotifyStore_Locked(&global_monitor_processor_);
} }
} }
...@@ -1913,12 +1913,12 @@ void Simulator::LoadStorePairHelper(Instruction* instr, ...@@ -1913,12 +1913,12 @@ void Simulator::LoadStorePairHelper(Instruction* instr,
uintptr_t stack = 0; uintptr_t stack = 0;
{ {
base::MutexGuard lock_guard(&global_monitor_.Pointer()->mutex); base::MutexGuard lock_guard(&GlobalMonitor::Get()->mutex);
if (instr->IsLoad()) { if (instr->IsLoad()) {
local_monitor_.NotifyLoad(); local_monitor_.NotifyLoad();
} else { } else {
local_monitor_.NotifyStore(); local_monitor_.NotifyStore();
global_monitor_.Pointer()->NotifyStore_Locked(&global_monitor_processor_); GlobalMonitor::Get()->NotifyStore_Locked(&global_monitor_processor_);
} }
} }
...@@ -2064,7 +2064,7 @@ void Simulator::VisitLoadLiteral(Instruction* instr) { ...@@ -2064,7 +2064,7 @@ void Simulator::VisitLoadLiteral(Instruction* instr) {
unsigned rt = instr->Rt(); unsigned rt = instr->Rt();
{ {
base::MutexGuard lock_guard(&global_monitor_.Pointer()->mutex); base::MutexGuard lock_guard(&GlobalMonitor::Get()->mutex);
local_monitor_.NotifyLoad(); local_monitor_.NotifyLoad();
} }
...@@ -2155,12 +2155,12 @@ void Simulator::VisitLoadStoreAcquireRelease(Instruction* instr) { ...@@ -2155,12 +2155,12 @@ void Simulator::VisitLoadStoreAcquireRelease(Instruction* instr) {
unsigned access_size = 1 << instr->LoadStoreXSizeLog2(); unsigned access_size = 1 << instr->LoadStoreXSizeLog2();
uintptr_t address = LoadStoreAddress(rn, 0, AddrMode::Offset); uintptr_t address = LoadStoreAddress(rn, 0, AddrMode::Offset);
DCHECK_EQ(address % access_size, 0); DCHECK_EQ(address % access_size, 0);
base::MutexGuard lock_guard(&global_monitor_.Pointer()->mutex); base::MutexGuard lock_guard(&GlobalMonitor::Get()->mutex);
if (is_load != 0) { if (is_load != 0) {
if (is_exclusive) { if (is_exclusive) {
local_monitor_.NotifyLoadExcl(address, get_transaction_size(access_size)); local_monitor_.NotifyLoadExcl(address, get_transaction_size(access_size));
global_monitor_.Pointer()->NotifyLoadExcl_Locked( GlobalMonitor::Get()->NotifyLoadExcl_Locked(address,
address, &global_monitor_processor_); &global_monitor_processor_);
} else { } else {
local_monitor_.NotifyLoad(); local_monitor_.NotifyLoad();
} }
...@@ -2192,7 +2192,7 @@ void Simulator::VisitLoadStoreAcquireRelease(Instruction* instr) { ...@@ -2192,7 +2192,7 @@ void Simulator::VisitLoadStoreAcquireRelease(Instruction* instr) {
DCHECK_NE(rs, rn); DCHECK_NE(rs, rn);
if (local_monitor_.NotifyStoreExcl(address, if (local_monitor_.NotifyStoreExcl(address,
get_transaction_size(access_size)) && get_transaction_size(access_size)) &&
global_monitor_.Pointer()->NotifyStoreExcl_Locked( GlobalMonitor::Get()->NotifyStoreExcl_Locked(
address, &global_monitor_processor_)) { address, &global_monitor_processor_)) {
switch (op) { switch (op) {
case STLXR_b: case STLXR_b:
...@@ -2217,7 +2217,7 @@ void Simulator::VisitLoadStoreAcquireRelease(Instruction* instr) { ...@@ -2217,7 +2217,7 @@ void Simulator::VisitLoadStoreAcquireRelease(Instruction* instr) {
} }
} else { } else {
local_monitor_.NotifyStore(); local_monitor_.NotifyStore();
global_monitor_.Pointer()->NotifyStore_Locked(&global_monitor_processor_); GlobalMonitor::Get()->NotifyStore_Locked(&global_monitor_processor_);
switch (op) { switch (op) {
case STLR_b: case STLR_b:
MemoryWrite<uint8_t>(address, wreg(rt)); MemoryWrite<uint8_t>(address, wreg(rt));
...@@ -4531,12 +4531,12 @@ void Simulator::NEONLoadStoreMultiStructHelper(const Instruction* instr, ...@@ -4531,12 +4531,12 @@ void Simulator::NEONLoadStoreMultiStructHelper(const Instruction* instr,
} }
{ {
base::MutexGuard lock_guard(&global_monitor_.Pointer()->mutex); base::MutexGuard lock_guard(&GlobalMonitor::Get()->mutex);
if (log_read) { if (log_read) {
local_monitor_.NotifyLoad(); local_monitor_.NotifyLoad();
} else { } else {
local_monitor_.NotifyStore(); local_monitor_.NotifyStore();
global_monitor_.Pointer()->NotifyStore_Locked(&global_monitor_processor_); GlobalMonitor::Get()->NotifyStore_Locked(&global_monitor_processor_);
} }
} }
...@@ -4777,12 +4777,12 @@ void Simulator::NEONLoadStoreSingleStructHelper(const Instruction* instr, ...@@ -4777,12 +4777,12 @@ void Simulator::NEONLoadStoreSingleStructHelper(const Instruction* instr,
} }
{ {
base::MutexGuard lock_guard(&global_monitor_.Pointer()->mutex); base::MutexGuard lock_guard(&GlobalMonitor::Get()->mutex);
if (do_load) { if (do_load) {
local_monitor_.NotifyLoad(); local_monitor_.NotifyLoad();
} else { } else {
local_monitor_.NotifyStore(); local_monitor_.NotifyStore();
global_monitor_.Pointer()->NotifyStore_Locked(&global_monitor_processor_); GlobalMonitor::Get()->NotifyStore_Locked(&global_monitor_processor_);
} }
} }
...@@ -5860,8 +5860,6 @@ bool Simulator::GlobalMonitor::Processor::NotifyStoreExcl_Locked( ...@@ -5860,8 +5860,6 @@ bool Simulator::GlobalMonitor::Processor::NotifyStoreExcl_Locked(
return false; return false;
} }
Simulator::GlobalMonitor::GlobalMonitor() : head_(nullptr) {}
void Simulator::GlobalMonitor::NotifyLoadExcl_Locked(uintptr_t addr, void Simulator::GlobalMonitor::NotifyLoadExcl_Locked(uintptr_t addr,
Processor* processor) { Processor* processor) {
processor->NotifyLoadExcl_Locked(addr); processor->NotifyLoadExcl_Locked(addr);
......
...@@ -2230,8 +2230,6 @@ class Simulator : public DecoderVisitor, public SimulatorBase { ...@@ -2230,8 +2230,6 @@ class Simulator : public DecoderVisitor, public SimulatorBase {
class GlobalMonitor { class GlobalMonitor {
public: public:
GlobalMonitor();
class Processor { class Processor {
public: public:
Processor(); Processor();
...@@ -2267,16 +2265,21 @@ class Simulator : public DecoderVisitor, public SimulatorBase { ...@@ -2267,16 +2265,21 @@ class Simulator : public DecoderVisitor, public SimulatorBase {
// Called when the simulator is destroyed. // Called when the simulator is destroyed.
void RemoveProcessor(Processor* processor); void RemoveProcessor(Processor* processor);
static GlobalMonitor* Get();
private: private:
// Private constructor. Call {GlobalMonitor::Get()} to get the singleton.
GlobalMonitor() = default;
friend class base::LeakyObject<GlobalMonitor>;
bool IsProcessorInLinkedList_Locked(Processor* processor) const; bool IsProcessorInLinkedList_Locked(Processor* processor) const;
void PrependProcessor_Locked(Processor* processor); void PrependProcessor_Locked(Processor* processor);
Processor* head_; Processor* head_ = nullptr;
}; };
LocalMonitor local_monitor_; LocalMonitor local_monitor_;
GlobalMonitor::Processor global_monitor_processor_; GlobalMonitor::Processor global_monitor_processor_;
static base::LazyInstance<GlobalMonitor>::type global_monitor_;
private: private:
void Init(FILE* stream); void Init(FILE* stream);
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "src/assembler-inl.h" #include "src/assembler-inl.h"
#include "src/base/bits.h" #include "src/base/bits.h"
#include "src/base/lazy-instance.h"
#include "src/codegen.h" #include "src/codegen.h"
#include "src/disasm.h" #include "src/disasm.h"
#include "src/macro-assembler.h" #include "src/macro-assembler.h"
...@@ -24,9 +25,8 @@ ...@@ -24,9 +25,8 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
// static DEFINE_LAZY_LEAKY_OBJECT_GETTER(Simulator::GlobalMonitor,
base::LazyInstance<Simulator::GlobalMonitor>::type Simulator::global_monitor_ = Simulator::GlobalMonitor::Get);
LAZY_INSTANCE_INITIALIZER;
// Utils functions. // Utils functions.
bool HaveSameSign(int32_t a, int32_t b) { bool HaveSameSign(int32_t a, int32_t b) {
...@@ -917,7 +917,7 @@ Simulator::Simulator(Isolate* isolate) : isolate_(isolate) { ...@@ -917,7 +917,7 @@ Simulator::Simulator(Isolate* isolate) : isolate_(isolate) {
} }
Simulator::~Simulator() { Simulator::~Simulator() {
global_monitor_.Pointer()->RemoveLinkedAddress(&global_monitor_thread_); GlobalMonitor::Get()->RemoveLinkedAddress(&global_monitor_thread_);
free(stack_); free(stack_);
} }
...@@ -2000,8 +2000,8 @@ void Simulator::WriteW(int32_t addr, int value, Instruction* instr) { ...@@ -2000,8 +2000,8 @@ void Simulator::WriteW(int32_t addr, int value, Instruction* instr) {
} }
if ((addr & kPointerAlignmentMask) == 0 || IsMipsArchVariant(kMips32r6)) { if ((addr & kPointerAlignmentMask) == 0 || IsMipsArchVariant(kMips32r6)) {
local_monitor_.NotifyStore(); local_monitor_.NotifyStore();
base::MutexGuard lock_guard(&global_monitor_.Pointer()->mutex); base::MutexGuard lock_guard(&GlobalMonitor::Get()->mutex);
global_monitor_.Pointer()->NotifyStore_Locked(&global_monitor_thread_); GlobalMonitor::Get()->NotifyStore_Locked(&global_monitor_thread_);
intptr_t* ptr = reinterpret_cast<intptr_t*>(addr); intptr_t* ptr = reinterpret_cast<intptr_t*>(addr);
TraceMemWr(addr, value, WORD); TraceMemWr(addr, value, WORD);
*ptr = value; *ptr = value;
...@@ -2024,12 +2024,12 @@ void Simulator::WriteConditionalW(int32_t addr, int32_t value, ...@@ -2024,12 +2024,12 @@ void Simulator::WriteConditionalW(int32_t addr, int32_t value,
dbg.Debug(); dbg.Debug();
} }
if ((addr & kPointerAlignmentMask) == 0 || IsMipsArchVariant(kMips32r6)) { if ((addr & kPointerAlignmentMask) == 0 || IsMipsArchVariant(kMips32r6)) {
base::MutexGuard lock_guard(&global_monitor_.Pointer()->mutex); base::MutexGuard lock_guard(&GlobalMonitor::Get()->mutex);
if (local_monitor_.NotifyStoreConditional(addr, TransactionSize::Word) && if (local_monitor_.NotifyStoreConditional(addr, TransactionSize::Word) &&
global_monitor_.Pointer()->NotifyStoreConditional_Locked( GlobalMonitor::Get()->NotifyStoreConditional_Locked(
addr, &global_monitor_thread_)) { addr, &global_monitor_thread_)) {
local_monitor_.NotifyStore(); local_monitor_.NotifyStore();
global_monitor_.Pointer()->NotifyStore_Locked(&global_monitor_thread_); GlobalMonitor::Get()->NotifyStore_Locked(&global_monitor_thread_);
TraceMemWr(addr, value, WORD); TraceMemWr(addr, value, WORD);
int* ptr = reinterpret_cast<int*>(addr); int* ptr = reinterpret_cast<int*>(addr);
*ptr = value; *ptr = value;
...@@ -2062,8 +2062,8 @@ double Simulator::ReadD(int32_t addr, Instruction* instr) { ...@@ -2062,8 +2062,8 @@ double Simulator::ReadD(int32_t addr, Instruction* instr) {
void Simulator::WriteD(int32_t addr, double value, Instruction* instr) { void Simulator::WriteD(int32_t addr, double value, Instruction* instr) {
if ((addr & kDoubleAlignmentMask) == 0 || IsMipsArchVariant(kMips32r6)) { if ((addr & kDoubleAlignmentMask) == 0 || IsMipsArchVariant(kMips32r6)) {
local_monitor_.NotifyStore(); local_monitor_.NotifyStore();
base::MutexGuard lock_guard(&global_monitor_.Pointer()->mutex); base::MutexGuard lock_guard(&GlobalMonitor::Get()->mutex);
global_monitor_.Pointer()->NotifyStore_Locked(&global_monitor_thread_); GlobalMonitor::Get()->NotifyStore_Locked(&global_monitor_thread_);
double* ptr = reinterpret_cast<double*>(addr); double* ptr = reinterpret_cast<double*>(addr);
*ptr = value; *ptr = value;
return; return;
...@@ -2108,8 +2108,8 @@ int16_t Simulator::ReadH(int32_t addr, Instruction* instr) { ...@@ -2108,8 +2108,8 @@ int16_t Simulator::ReadH(int32_t addr, Instruction* instr) {
void Simulator::WriteH(int32_t addr, uint16_t value, Instruction* instr) { void Simulator::WriteH(int32_t addr, uint16_t value, Instruction* instr) {
if ((addr & 1) == 0 || IsMipsArchVariant(kMips32r6)) { if ((addr & 1) == 0 || IsMipsArchVariant(kMips32r6)) {
local_monitor_.NotifyStore(); local_monitor_.NotifyStore();
base::MutexGuard lock_guard(&global_monitor_.Pointer()->mutex); base::MutexGuard lock_guard(&GlobalMonitor::Get()->mutex);
global_monitor_.Pointer()->NotifyStore_Locked(&global_monitor_thread_); GlobalMonitor::Get()->NotifyStore_Locked(&global_monitor_thread_);
uint16_t* ptr = reinterpret_cast<uint16_t*>(addr); uint16_t* ptr = reinterpret_cast<uint16_t*>(addr);
TraceMemWr(addr, value, HALF); TraceMemWr(addr, value, HALF);
*ptr = value; *ptr = value;
...@@ -2125,8 +2125,8 @@ void Simulator::WriteH(int32_t addr, uint16_t value, Instruction* instr) { ...@@ -2125,8 +2125,8 @@ void Simulator::WriteH(int32_t addr, uint16_t value, Instruction* instr) {
void Simulator::WriteH(int32_t addr, int16_t value, Instruction* instr) { void Simulator::WriteH(int32_t addr, int16_t value, Instruction* instr) {
if ((addr & 1) == 0 || IsMipsArchVariant(kMips32r6)) { if ((addr & 1) == 0 || IsMipsArchVariant(kMips32r6)) {
local_monitor_.NotifyStore(); local_monitor_.NotifyStore();
base::MutexGuard lock_guard(&global_monitor_.Pointer()->mutex); base::MutexGuard lock_guard(&GlobalMonitor::Get()->mutex);
global_monitor_.Pointer()->NotifyStore_Locked(&global_monitor_thread_); GlobalMonitor::Get()->NotifyStore_Locked(&global_monitor_thread_);
int16_t* ptr = reinterpret_cast<int16_t*>(addr); int16_t* ptr = reinterpret_cast<int16_t*>(addr);
TraceMemWr(addr, value, HALF); TraceMemWr(addr, value, HALF);
*ptr = value; *ptr = value;
...@@ -2157,8 +2157,8 @@ int32_t Simulator::ReadB(int32_t addr) { ...@@ -2157,8 +2157,8 @@ int32_t Simulator::ReadB(int32_t addr) {
void Simulator::WriteB(int32_t addr, uint8_t value) { void Simulator::WriteB(int32_t addr, uint8_t value) {
local_monitor_.NotifyStore(); local_monitor_.NotifyStore();
base::MutexGuard lock_guard(&global_monitor_.Pointer()->mutex); base::MutexGuard lock_guard(&GlobalMonitor::Get()->mutex);
global_monitor_.Pointer()->NotifyStore_Locked(&global_monitor_thread_); GlobalMonitor::Get()->NotifyStore_Locked(&global_monitor_thread_);
uint8_t* ptr = reinterpret_cast<uint8_t*>(addr); uint8_t* ptr = reinterpret_cast<uint8_t*>(addr);
TraceMemWr(addr, value, BYTE); TraceMemWr(addr, value, BYTE);
*ptr = value; *ptr = value;
...@@ -2167,8 +2167,8 @@ void Simulator::WriteB(int32_t addr, uint8_t value) { ...@@ -2167,8 +2167,8 @@ void Simulator::WriteB(int32_t addr, uint8_t value) {
void Simulator::WriteB(int32_t addr, int8_t value) { void Simulator::WriteB(int32_t addr, int8_t value) {
local_monitor_.NotifyStore(); local_monitor_.NotifyStore();
base::MutexGuard lock_guard(&global_monitor_.Pointer()->mutex); base::MutexGuard lock_guard(&GlobalMonitor::Get()->mutex);
global_monitor_.Pointer()->NotifyStore_Locked(&global_monitor_thread_); GlobalMonitor::Get()->NotifyStore_Locked(&global_monitor_thread_);
int8_t* ptr = reinterpret_cast<int8_t*>(addr); int8_t* ptr = reinterpret_cast<int8_t*>(addr);
TraceMemWr(addr, value, BYTE); TraceMemWr(addr, value, BYTE);
*ptr = value; *ptr = value;
...@@ -2192,8 +2192,8 @@ T Simulator::ReadMem(int32_t addr, Instruction* instr) { ...@@ -2192,8 +2192,8 @@ T Simulator::ReadMem(int32_t addr, Instruction* instr) {
template <typename T> template <typename T>
void Simulator::WriteMem(int32_t addr, T value, Instruction* instr) { void Simulator::WriteMem(int32_t addr, T value, Instruction* instr) {
local_monitor_.NotifyStore(); local_monitor_.NotifyStore();
base::MutexGuard lock_guard(&global_monitor_.Pointer()->mutex); base::MutexGuard lock_guard(&GlobalMonitor::Get()->mutex);
global_monitor_.Pointer()->NotifyStore_Locked(&global_monitor_thread_); GlobalMonitor::Get()->NotifyStore_Locked(&global_monitor_thread_);
int alignment_mask = (1 << sizeof(T)) - 1; int alignment_mask = (1 << sizeof(T)) - 1;
if ((addr & alignment_mask) == 0 || IsMipsArchVariant(kMips32r6)) { if ((addr & alignment_mask) == 0 || IsMipsArchVariant(kMips32r6)) {
T* ptr = reinterpret_cast<T*>(addr); T* ptr = reinterpret_cast<T*>(addr);
...@@ -6788,12 +6788,12 @@ void Simulator::DecodeTypeImmediate() { ...@@ -6788,12 +6788,12 @@ void Simulator::DecodeTypeImmediate() {
} }
case LL: { case LL: {
DCHECK(!IsMipsArchVariant(kMips32r6)); DCHECK(!IsMipsArchVariant(kMips32r6));
base::MutexGuard lock_guard(&global_monitor_.Pointer()->mutex); base::MutexGuard lock_guard(&GlobalMonitor::Get()->mutex);
addr = rs + se_imm16; addr = rs + se_imm16;
set_register(rt_reg, ReadW(addr, instr_.instr())); set_register(rt_reg, ReadW(addr, instr_.instr()));
local_monitor_.NotifyLoadLinked(addr, TransactionSize::Word); local_monitor_.NotifyLoadLinked(addr, TransactionSize::Word);
global_monitor_.Pointer()->NotifyLoadLinked_Locked( GlobalMonitor::Get()->NotifyLoadLinked_Locked(addr,
addr, &global_monitor_thread_); &global_monitor_thread_);
break; break;
} }
case SC: { case SC: {
...@@ -6870,14 +6870,14 @@ void Simulator::DecodeTypeImmediate() { ...@@ -6870,14 +6870,14 @@ void Simulator::DecodeTypeImmediate() {
switch (instr_.FunctionFieldRaw()) { switch (instr_.FunctionFieldRaw()) {
case LL_R6: { case LL_R6: {
DCHECK(IsMipsArchVariant(kMips32r6)); DCHECK(IsMipsArchVariant(kMips32r6));
base::MutexGuard lock_guard(&global_monitor_.Pointer()->mutex); base::MutexGuard lock_guard(&GlobalMonitor::Get()->mutex);
int32_t base = get_register(instr_.BaseValue()); int32_t base = get_register(instr_.BaseValue());
int32_t offset9 = instr_.Imm9Value(); int32_t offset9 = instr_.Imm9Value();
addr = base + offset9; addr = base + offset9;
DCHECK_EQ(addr & kPointerAlignmentMask, 0); DCHECK_EQ(addr & kPointerAlignmentMask, 0);
set_register(rt_reg, ReadW(base + offset9, instr_.instr())); set_register(rt_reg, ReadW(base + offset9, instr_.instr()));
local_monitor_.NotifyLoadLinked(addr, TransactionSize::Word); local_monitor_.NotifyLoadLinked(addr, TransactionSize::Word);
global_monitor_.Pointer()->NotifyLoadLinked_Locked( GlobalMonitor::Get()->NotifyLoadLinked_Locked(
addr, &global_monitor_thread_); addr, &global_monitor_thread_);
break; break;
} }
...@@ -7280,8 +7280,6 @@ bool Simulator::GlobalMonitor::LinkedAddress::NotifyStoreConditional_Locked( ...@@ -7280,8 +7280,6 @@ bool Simulator::GlobalMonitor::LinkedAddress::NotifyStoreConditional_Locked(
return false; return false;
} }
Simulator::GlobalMonitor::GlobalMonitor() : head_(nullptr) {}
void Simulator::GlobalMonitor::NotifyLoadLinked_Locked( void Simulator::GlobalMonitor::NotifyLoadLinked_Locked(
uintptr_t addr, LinkedAddress* linked_address) { uintptr_t addr, LinkedAddress* linked_address) {
linked_address->NotifyLoadLinked_Locked(addr); linked_address->NotifyLoadLinked_Locked(addr);
......
...@@ -597,8 +597,6 @@ class Simulator : public SimulatorBase { ...@@ -597,8 +597,6 @@ class Simulator : public SimulatorBase {
class GlobalMonitor { class GlobalMonitor {
public: public:
GlobalMonitor();
class LinkedAddress { class LinkedAddress {
public: public:
LinkedAddress(); LinkedAddress();
...@@ -636,16 +634,21 @@ class Simulator : public SimulatorBase { ...@@ -636,16 +634,21 @@ class Simulator : public SimulatorBase {
// Called when the simulator is destroyed. // Called when the simulator is destroyed.
void RemoveLinkedAddress(LinkedAddress* linked_address); void RemoveLinkedAddress(LinkedAddress* linked_address);
static GlobalMonitor* Get();
private: private:
// Private constructor. Call {GlobalMonitor::Get()} to get the singleton.
GlobalMonitor() = default;
friend class base::LeakyObject<GlobalMonitor>;
bool IsProcessorInLinkedList_Locked(LinkedAddress* linked_address) const; bool IsProcessorInLinkedList_Locked(LinkedAddress* linked_address) const;
void PrependProcessor_Locked(LinkedAddress* linked_address); void PrependProcessor_Locked(LinkedAddress* linked_address);
LinkedAddress* head_; LinkedAddress* head_ = nullptr;
}; };
LocalMonitor local_monitor_; LocalMonitor local_monitor_;
GlobalMonitor::LinkedAddress global_monitor_thread_; GlobalMonitor::LinkedAddress global_monitor_thread_;
static base::LazyInstance<GlobalMonitor>::type global_monitor_;
}; };
} // namespace internal } // namespace internal
......
This diff is collapsed.
...@@ -621,8 +621,6 @@ class Simulator : public SimulatorBase { ...@@ -621,8 +621,6 @@ class Simulator : public SimulatorBase {
class GlobalMonitor { class GlobalMonitor {
public: public:
GlobalMonitor();
class LinkedAddress { class LinkedAddress {
public: public:
LinkedAddress(); LinkedAddress();
...@@ -660,16 +658,21 @@ class Simulator : public SimulatorBase { ...@@ -660,16 +658,21 @@ class Simulator : public SimulatorBase {
// Called when the simulator is destroyed. // Called when the simulator is destroyed.
void RemoveLinkedAddress(LinkedAddress* linked_address); void RemoveLinkedAddress(LinkedAddress* linked_address);
static GlobalMonitor* Get();
private: private:
// Private constructor. Call {GlobalMonitor::Get()} to get the singleton.
GlobalMonitor() = default;
friend class base::LeakyObject<GlobalMonitor>;
bool IsProcessorInLinkedList_Locked(LinkedAddress* linked_address) const; bool IsProcessorInLinkedList_Locked(LinkedAddress* linked_address) const;
void PrependProcessor_Locked(LinkedAddress* linked_address); void PrependProcessor_Locked(LinkedAddress* linked_address);
LinkedAddress* head_; LinkedAddress* head_ = nullptr;
}; };
LocalMonitor local_monitor_; LocalMonitor local_monitor_;
GlobalMonitor::LinkedAddress global_monitor_thread_; GlobalMonitor::LinkedAddress global_monitor_thread_;
static base::LazyInstance<GlobalMonitor>::type global_monitor_;
}; };
} // namespace internal } // namespace internal
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "src/assembler.h" #include "src/assembler.h"
#include "src/base/bits.h" #include "src/base/bits.h"
#include "src/base/lazy-instance.h"
#include "src/codegen.h" #include "src/codegen.h"
#include "src/disasm.h" #include "src/disasm.h"
#include "src/macro-assembler.h" #include "src/macro-assembler.h"
...@@ -26,9 +27,8 @@ ...@@ -26,9 +27,8 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
// static DEFINE_LAZY_LEAKY_OBJECT_GETTER(Simulator::GlobalMonitor,
base::LazyInstance<Simulator::GlobalMonitor>::type Simulator::global_monitor_ = Simulator::GlobalMonitor::Get);
LAZY_INSTANCE_INITIALIZER;
// This macro provides a platform independent use of sscanf. The reason for // This macro provides a platform independent use of sscanf. The reason for
// SScanF not being implemented in a platform independent way through // SScanF not being implemented in a platform independent way through
...@@ -3952,12 +3952,6 @@ uintptr_t Simulator::PopAddress() { ...@@ -3952,12 +3952,6 @@ uintptr_t Simulator::PopAddress() {
return address; return address;
} }
Simulator::GlobalMonitor::GlobalMonitor()
: access_state_(MonitorAccess::Open),
tagged_addr_(0),
size_(TransactionSize::None),
thread_id_(ThreadId::Invalid()) {}
void Simulator::GlobalMonitor::Clear() { void Simulator::GlobalMonitor::Clear() {
access_state_ = MonitorAccess::Open; access_state_ = MonitorAccess::Open;
tagged_addr_ = 0; tagged_addr_ = 0;
......
...@@ -248,14 +248,14 @@ class Simulator : public SimulatorBase { ...@@ -248,14 +248,14 @@ class Simulator : public SimulatorBase {
// Read and write memory. // Read and write memory.
template <typename T> template <typename T>
inline void Read(uintptr_t address, T* value) { inline void Read(uintptr_t address, T* value) {
base::MutexGuard lock_guard(&global_monitor_.Pointer()->mutex); base::MutexGuard lock_guard(&GlobalMonitor::Get()->mutex);
memcpy(value, reinterpret_cast<const char*>(address), sizeof(T)); memcpy(value, reinterpret_cast<const char*>(address), sizeof(T));
} }
template <typename T> template <typename T>
inline void ReadEx(uintptr_t address, T* value) { inline void ReadEx(uintptr_t address, T* value) {
base::MutexGuard lock_guard(&global_monitor_.Pointer()->mutex); base::MutexGuard lock_guard(&GlobalMonitor::Get()->mutex);
global_monitor_.Pointer()->NotifyLoadExcl( GlobalMonitor::Get()->NotifyLoadExcl(
address, static_cast<TransactionSize>(sizeof(T)), address, static_cast<TransactionSize>(sizeof(T)),
isolate_->thread_id()); isolate_->thread_id());
memcpy(value, reinterpret_cast<const char*>(address), sizeof(T)); memcpy(value, reinterpret_cast<const char*>(address), sizeof(T));
...@@ -263,17 +263,17 @@ class Simulator : public SimulatorBase { ...@@ -263,17 +263,17 @@ class Simulator : public SimulatorBase {
template <typename T> template <typename T>
inline void Write(uintptr_t address, T value) { inline void Write(uintptr_t address, T value) {
base::MutexGuard lock_guard(&global_monitor_.Pointer()->mutex); base::MutexGuard lock_guard(&GlobalMonitor::Get()->mutex);
global_monitor_.Pointer()->NotifyStore( GlobalMonitor::Get()->NotifyStore(address,
address, static_cast<TransactionSize>(sizeof(T)), static_cast<TransactionSize>(sizeof(T)),
isolate_->thread_id()); isolate_->thread_id());
memcpy(reinterpret_cast<char*>(address), &value, sizeof(T)); memcpy(reinterpret_cast<char*>(address), &value, sizeof(T));
} }
template <typename T> template <typename T>
inline int32_t WriteEx(uintptr_t address, T value) { inline int32_t WriteEx(uintptr_t address, T value) {
base::MutexGuard lock_guard(&global_monitor_.Pointer()->mutex); base::MutexGuard lock_guard(&GlobalMonitor::Get()->mutex);
if (global_monitor_.Pointer()->NotifyStoreExcl( if (GlobalMonitor::Get()->NotifyStoreExcl(
address, static_cast<TransactionSize>(sizeof(T)), address, static_cast<TransactionSize>(sizeof(T)),
isolate_->thread_id())) { isolate_->thread_id())) {
memcpy(reinterpret_cast<char*>(address), &value, sizeof(T)); memcpy(reinterpret_cast<char*>(address), &value, sizeof(T));
...@@ -386,8 +386,6 @@ class Simulator : public SimulatorBase { ...@@ -386,8 +386,6 @@ class Simulator : public SimulatorBase {
class GlobalMonitor { class GlobalMonitor {
public: public:
GlobalMonitor();
// Exposed so it can be accessed by Simulator::{Read,Write}Ex*. // Exposed so it can be accessed by Simulator::{Read,Write}Ex*.
base::Mutex mutex; base::Mutex mutex;
...@@ -397,16 +395,20 @@ class Simulator : public SimulatorBase { ...@@ -397,16 +395,20 @@ class Simulator : public SimulatorBase {
bool NotifyStoreExcl(uintptr_t addr, TransactionSize size, bool NotifyStoreExcl(uintptr_t addr, TransactionSize size,
ThreadId thread_id); ThreadId thread_id);
static GlobalMonitor* Get();
private: private:
// Private constructor. Call {GlobalMonitor::Get()} to get the singleton.
GlobalMonitor() = default;
friend class base::LeakyObject<GlobalMonitor>;
void Clear(); void Clear();
MonitorAccess access_state_; MonitorAccess access_state_ = MonitorAccess::Open;
uintptr_t tagged_addr_; uintptr_t tagged_addr_ = 0;
TransactionSize size_; TransactionSize size_ = TransactionSize::None;
ThreadId thread_id_; ThreadId thread_id_ = ThreadId::Invalid();
}; };
static base::LazyInstance<GlobalMonitor>::type global_monitor_;
}; };
} // namespace internal } // namespace internal
......
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