Commit 1099a5ff authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[platform] Refactor lazily initialized singletons

Use the new macro to define lazily initialized leaky singletons. Avoid
the clumsy LazyInstance, which we can hopefully remove soon.

R=mlippautz@chromium.org

Bug: v8:8600
Change-Id: Ib4d23f275c7ff5ca71fa9b47345284935330ead7
Reviewed-on: https://chromium-review.googlesource.com/c/1397711Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58594}
parent 4eec4449
...@@ -92,8 +92,8 @@ bool g_hard_abort = false; ...@@ -92,8 +92,8 @@ bool g_hard_abort = false;
const char* g_gc_fake_mmap = nullptr; const char* g_gc_fake_mmap = nullptr;
static LazyInstance<RandomNumberGenerator>::type DEFINE_LAZY_LEAKY_OBJECT_GETTER(RandomNumberGenerator,
platform_random_number_generator = LAZY_INSTANCE_INITIALIZER; GetPlatformRandomNumberGenerator);
static LazyMutex rng_mutex = LAZY_MUTEX_INITIALIZER; static LazyMutex rng_mutex = LAZY_MUTEX_INITIALIZER;
#if !V8_OS_FUCHSIA #if !V8_OS_FUCHSIA
...@@ -188,7 +188,7 @@ size_t OS::CommitPageSize() { ...@@ -188,7 +188,7 @@ size_t OS::CommitPageSize() {
void OS::SetRandomMmapSeed(int64_t seed) { void OS::SetRandomMmapSeed(int64_t seed) {
if (seed) { if (seed) {
MutexGuard guard(rng_mutex.Pointer()); MutexGuard guard(rng_mutex.Pointer());
platform_random_number_generator.Pointer()->SetSeed(seed); GetPlatformRandomNumberGenerator()->SetSeed(seed);
} }
} }
...@@ -197,8 +197,7 @@ void* OS::GetRandomMmapAddr() { ...@@ -197,8 +197,7 @@ void* OS::GetRandomMmapAddr() {
uintptr_t raw_addr; uintptr_t raw_addr;
{ {
MutexGuard guard(rng_mutex.Pointer()); MutexGuard guard(rng_mutex.Pointer());
platform_random_number_generator.Pointer()->NextBytes(&raw_addr, GetPlatformRandomNumberGenerator()->NextBytes(&raw_addr, sizeof(raw_addr));
sizeof(raw_addr));
} }
#if defined(V8_USE_ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \ #if defined(V8_USE_ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \
defined(THREAD_SANITIZER) || defined(LEAK_SANITIZER) defined(THREAD_SANITIZER) || defined(LEAK_SANITIZER)
......
...@@ -689,8 +689,8 @@ void OS::StrNCpy(char* dest, int length, const char* src, size_t n) { ...@@ -689,8 +689,8 @@ void OS::StrNCpy(char* dest, int length, const char* src, size_t n) {
#undef _TRUNCATE #undef _TRUNCATE
#undef STRUNCATE #undef STRUNCATE
static LazyInstance<RandomNumberGenerator>::type DEFINE_LAZY_LEAKY_OBJECT_GETTER(RandomNumberGenerator,
platform_random_number_generator = LAZY_INSTANCE_INITIALIZER; GetPlatformRandomNumberGenerator);
static LazyMutex rng_mutex = LAZY_MUTEX_INITIALIZER; static LazyMutex rng_mutex = LAZY_MUTEX_INITIALIZER;
void OS::Initialize(bool hard_abort, const char* const gc_fake_mmap) { void OS::Initialize(bool hard_abort, const char* const gc_fake_mmap) {
...@@ -724,7 +724,7 @@ size_t OS::CommitPageSize() { ...@@ -724,7 +724,7 @@ size_t OS::CommitPageSize() {
void OS::SetRandomMmapSeed(int64_t seed) { void OS::SetRandomMmapSeed(int64_t seed) {
if (seed) { if (seed) {
MutexGuard guard(rng_mutex.Pointer()); MutexGuard guard(rng_mutex.Pointer());
platform_random_number_generator.Pointer()->SetSeed(seed); GetPlatformRandomNumberGenerator()->SetSeed(seed);
} }
} }
...@@ -745,8 +745,7 @@ void* OS::GetRandomMmapAddr() { ...@@ -745,8 +745,7 @@ void* OS::GetRandomMmapAddr() {
uintptr_t address; uintptr_t address;
{ {
MutexGuard guard(rng_mutex.Pointer()); MutexGuard guard(rng_mutex.Pointer());
platform_random_number_generator.Pointer()->NextBytes(&address, GetPlatformRandomNumberGenerator()->NextBytes(&address, sizeof(address));
sizeof(address));
} }
address <<= kPageSizeBits; address <<= kPageSizeBits;
address += kAllocationRandomAddressMin; address += kAllocationRandomAddressMin;
......
...@@ -313,21 +313,13 @@ class Clock final { ...@@ -313,21 +313,13 @@ class Clock final {
Mutex mutex_; Mutex mutex_;
}; };
namespace {
DEFINE_LAZY_LEAKY_OBJECT_GETTER(Clock, GetClock);
};
static LazyStaticInstance<Clock, DefaultConstructTrait<Clock>, Time Time::Now() { return GetClock()->Now(); }
ThreadSafeInitOnceTrait>::type clock =
LAZY_STATIC_INSTANCE_INITIALIZER;
Time Time::Now() {
return clock.Pointer()->Now();
}
Time Time::NowFromSystemTime() {
return clock.Pointer()->NowFromSystemTime();
}
Time Time::NowFromSystemTime() { return GetClock()->NowFromSystemTime(); }
// Time between windows epoch and standard epoch. // Time between windows epoch and standard epoch.
static const int64_t kTimeToEpochInMicroseconds = int64_t{11644473600000000}; static const int64_t kTimeToEpochInMicroseconds = int64_t{11644473600000000};
......
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