diff options
author | Refael Ackermann <refack@gmail.com> | 2019-05-28 08:46:21 -0400 |
---|---|---|
committer | Refael Ackermann <refack@gmail.com> | 2019-06-01 09:55:12 -0400 |
commit | ed74896b1fae1c163b3906163f3bf46326618ddb (patch) | |
tree | 7fb05c5a19808e0c5cd95837528e9005999cf540 /deps/v8/src/base/platform | |
parent | 2a850cd0664a4eee51f44d0bb8c2f7a3fe444154 (diff) | |
download | node-new-ed74896b1fae1c163b3906163f3bf46326618ddb.tar.gz |
deps: update V8 to 7.5.288.22
PR-URL: https://github.com/nodejs/node/pull/27375
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'deps/v8/src/base/platform')
-rw-r--r-- | deps/v8/src/base/platform/condition-variable.h | 11 | ||||
-rw-r--r-- | deps/v8/src/base/platform/mutex.h | 22 | ||||
-rw-r--r-- | deps/v8/src/base/platform/platform-aix.cc | 2 | ||||
-rw-r--r-- | deps/v8/src/base/platform/platform-cygwin.cc | 2 | ||||
-rw-r--r-- | deps/v8/src/base/platform/platform-freebsd.cc | 2 | ||||
-rw-r--r-- | deps/v8/src/base/platform/platform-fuchsia.cc | 2 | ||||
-rw-r--r-- | deps/v8/src/base/platform/platform-linux.cc | 2 | ||||
-rw-r--r-- | deps/v8/src/base/platform/platform-macos.cc | 20 | ||||
-rw-r--r-- | deps/v8/src/base/platform/platform-openbsd.cc | 2 | ||||
-rw-r--r-- | deps/v8/src/base/platform/platform-posix.cc | 24 | ||||
-rw-r--r-- | deps/v8/src/base/platform/platform-qnx.cc | 2 | ||||
-rw-r--r-- | deps/v8/src/base/platform/platform-solaris.cc | 2 | ||||
-rw-r--r-- | deps/v8/src/base/platform/platform-win32.cc | 87 | ||||
-rw-r--r-- | deps/v8/src/base/platform/platform.h | 9 | ||||
-rw-r--r-- | deps/v8/src/base/platform/semaphore.h | 10 | ||||
-rw-r--r-- | deps/v8/src/base/platform/time.cc | 59 | ||||
-rw-r--r-- | deps/v8/src/base/platform/time.h | 1 |
17 files changed, 159 insertions, 100 deletions
diff --git a/deps/v8/src/base/platform/condition-variable.h b/deps/v8/src/base/platform/condition-variable.h index 2cdcb07b59..e864f32872 100644 --- a/deps/v8/src/base/platform/condition-variable.h +++ b/deps/v8/src/base/platform/condition-variable.h @@ -61,9 +61,9 @@ class V8_BASE_EXPORT ConditionVariable final { // The implementation-defined native handle type. #if V8_OS_POSIX - typedef pthread_cond_t NativeHandle; + using NativeHandle = pthread_cond_t; #elif V8_OS_WIN - typedef CONDITION_VARIABLE NativeHandle; + using NativeHandle = CONDITION_VARIABLE; #endif NativeHandle& native_handle() { @@ -89,9 +89,10 @@ class V8_BASE_EXPORT ConditionVariable final { // MutexGuard lock_guard(&my_mutex); // my_condvar.Pointer()->Wait(&my_mutex); // } -typedef LazyStaticInstance< - ConditionVariable, DefaultConstructTrait<ConditionVariable>, - ThreadSafeInitOnceTrait>::type LazyConditionVariable; +using LazyConditionVariable = + LazyStaticInstance<ConditionVariable, + DefaultConstructTrait<ConditionVariable>, + ThreadSafeInitOnceTrait>::type; #define LAZY_CONDITION_VARIABLE_INITIALIZER LAZY_STATIC_INSTANCE_INITIALIZER diff --git a/deps/v8/src/base/platform/mutex.h b/deps/v8/src/base/platform/mutex.h index ea589d5b98..2b8b55eeb5 100644 --- a/deps/v8/src/base/platform/mutex.h +++ b/deps/v8/src/base/platform/mutex.h @@ -55,9 +55,9 @@ class V8_BASE_EXPORT Mutex final { // The implementation-defined native handle type. #if V8_OS_POSIX - typedef pthread_mutex_t NativeHandle; + using NativeHandle = pthread_mutex_t; #elif V8_OS_WIN - typedef SRWLOCK NativeHandle; + using NativeHandle = SRWLOCK; #endif NativeHandle& native_handle() { @@ -101,8 +101,8 @@ class V8_BASE_EXPORT Mutex final { // // Do something. // } // -typedef LazyStaticInstance<Mutex, DefaultConstructTrait<Mutex>, - ThreadSafeInitOnceTrait>::type LazyMutex; +using LazyMutex = LazyStaticInstance<Mutex, DefaultConstructTrait<Mutex>, + ThreadSafeInitOnceTrait>::type; #define LAZY_MUTEX_INITIALIZER LAZY_STATIC_INSTANCE_INITIALIZER @@ -153,9 +153,9 @@ class V8_BASE_EXPORT RecursiveMutex final { private: // The implementation-defined native handle type. #if V8_OS_POSIX - typedef pthread_mutex_t NativeHandle; + using NativeHandle = pthread_mutex_t; #elif V8_OS_WIN - typedef CRITICAL_SECTION NativeHandle; + using NativeHandle = CRITICAL_SECTION; #endif NativeHandle native_handle_; @@ -177,9 +177,9 @@ class V8_BASE_EXPORT RecursiveMutex final { // // Do something. // } // -typedef LazyStaticInstance<RecursiveMutex, - DefaultConstructTrait<RecursiveMutex>, - ThreadSafeInitOnceTrait>::type LazyRecursiveMutex; +using LazyRecursiveMutex = + LazyStaticInstance<RecursiveMutex, DefaultConstructTrait<RecursiveMutex>, + ThreadSafeInitOnceTrait>::type; #define LAZY_RECURSIVE_MUTEX_INITIALIZER LAZY_STATIC_INSTANCE_INITIALIZER @@ -241,9 +241,9 @@ class V8_BASE_EXPORT SharedMutex final { private: // The implementation-defined native handle type. #if V8_OS_POSIX - typedef pthread_rwlock_t NativeHandle; + using NativeHandle = pthread_rwlock_t; #elif V8_OS_WIN - typedef SRWLOCK NativeHandle; + using NativeHandle = SRWLOCK; #endif NativeHandle native_handle_; diff --git a/deps/v8/src/base/platform/platform-aix.cc b/deps/v8/src/base/platform/platform-aix.cc index 406462cdd2..e3d7c426b4 100644 --- a/deps/v8/src/base/platform/platform-aix.cc +++ b/deps/v8/src/base/platform/platform-aix.cc @@ -127,5 +127,7 @@ std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() { void OS::SignalCodeMovingGC() {} +void OS::AdjustSchedulingParams() {} + } // namespace base } // namespace v8 diff --git a/deps/v8/src/base/platform/platform-cygwin.cc b/deps/v8/src/base/platform/platform-cygwin.cc index f2976301ed..17f9aa3f17 100644 --- a/deps/v8/src/base/platform/platform-cygwin.cc +++ b/deps/v8/src/base/platform/platform-cygwin.cc @@ -268,5 +268,7 @@ void OS::SignalCodeMovingGC() { // Nothing to do on Cygwin. } +void OS::AdjustSchedulingParams() {} + } // namespace base } // namespace v8 diff --git a/deps/v8/src/base/platform/platform-freebsd.cc b/deps/v8/src/base/platform/platform-freebsd.cc index 2b9779b843..d40452f3d4 100644 --- a/deps/v8/src/base/platform/platform-freebsd.cc +++ b/deps/v8/src/base/platform/platform-freebsd.cc @@ -86,5 +86,7 @@ std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() { void OS::SignalCodeMovingGC() {} +void OS::AdjustSchedulingParams() {} + } // namespace base } // namespace v8 diff --git a/deps/v8/src/base/platform/platform-fuchsia.cc b/deps/v8/src/base/platform/platform-fuchsia.cc index 7dd29dc39e..5d878c91a6 100644 --- a/deps/v8/src/base/platform/platform-fuchsia.cc +++ b/deps/v8/src/base/platform/platform-fuchsia.cc @@ -163,5 +163,7 @@ int OS::GetUserTime(uint32_t* secs, uint32_t* usecs) { return 0; } +void OS::AdjustSchedulingParams() {} + } // namespace base } // namespace v8 diff --git a/deps/v8/src/base/platform/platform-linux.cc b/deps/v8/src/base/platform/platform-linux.cc index 10815f29c5..059f393eb6 100644 --- a/deps/v8/src/base/platform/platform-linux.cc +++ b/deps/v8/src/base/platform/platform-linux.cc @@ -172,5 +172,7 @@ void OS::SignalCodeMovingGC() { fclose(f); } +void OS::AdjustSchedulingParams() {} + } // namespace base } // namespace v8 diff --git a/deps/v8/src/base/platform/platform-macos.cc b/deps/v8/src/base/platform/platform-macos.cc index 081e434589..72a41c8491 100644 --- a/deps/v8/src/base/platform/platform-macos.cc +++ b/deps/v8/src/base/platform/platform-macos.cc @@ -73,5 +73,25 @@ TimezoneCache* OS::CreateTimezoneCache() { return new PosixDefaultTimezoneCache(); } +void OS::AdjustSchedulingParams() { +#if V8_TARGET_ARCH_X64 || V8_TARGET_ARCH_IA32 + { + // Check availability of scheduling params. + uint32_t val = 0; + size_t valSize = sizeof(val); + int rc = sysctlbyname("kern.tcsm_available", &val, &valSize, NULL, 0); + if (rc < 0 || !val) return; + } + + { + // Adjust scheduling params. + uint32_t val = 1; + int rc = sysctlbyname("kern.tcsm_enable", NULL, NULL, &val, sizeof(val)); + DCHECK_GE(rc, 0); + USE(rc); + } +#endif +} + } // namespace base } // namespace v8 diff --git a/deps/v8/src/base/platform/platform-openbsd.cc b/deps/v8/src/base/platform/platform-openbsd.cc index 9084c3075e..c133ffb68d 100644 --- a/deps/v8/src/base/platform/platform-openbsd.cc +++ b/deps/v8/src/base/platform/platform-openbsd.cc @@ -120,5 +120,7 @@ void OS::SignalCodeMovingGC() { fclose(f); } +void OS::AdjustSchedulingParams() {} + } // namespace base } // namespace v8 diff --git a/deps/v8/src/base/platform/platform-posix.cc b/deps/v8/src/base/platform/platform-posix.cc index 33a9371a92..2301c26688 100644 --- a/deps/v8/src/base/platform/platform-posix.cc +++ b/deps/v8/src/base/platform/platform-posix.cc @@ -43,7 +43,7 @@ #include "src/base/utils/random-number-generator.h" #ifdef V8_FAST_TLS_SUPPORTED -#include "src/base/atomicops.h" +#include <atomic> #endif #if V8_OS_MACOSX @@ -444,15 +444,22 @@ class PosixMemoryMappedFile final : public OS::MemoryMappedFile { // static -OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) { - if (FILE* file = fopen(name, "r+")) { +OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name, + FileMode mode) { + const char* fopen_mode = (mode == FileMode::kReadOnly) ? "r" : "r+"; + if (FILE* file = fopen(name, fopen_mode)) { if (fseek(file, 0, SEEK_END) == 0) { long size = ftell(file); // NOLINT(runtime/int) if (size == 0) return new PosixMemoryMappedFile(file, nullptr, 0); if (size > 0) { + int prot = PROT_READ; + int flags = MAP_PRIVATE; + if (mode == FileMode::kReadWrite) { + prot |= PROT_WRITE; + flags = MAP_SHARED; + } void* const memory = - mmap(OS::GetRandomMmapAddr(), size, PROT_READ | PROT_WRITE, - MAP_SHARED, fileno(file), 0); + mmap(OS::GetRandomMmapAddr(), size, prot, flags, fileno(file), 0); if (memory != MAP_FAILED) { return new PosixMemoryMappedFile(file, memory, size); } @@ -463,7 +470,6 @@ OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) { return nullptr; } - // static OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, size_t size, void* initial) { @@ -815,7 +821,7 @@ static pthread_key_t LocalKeyToPthreadKey(Thread::LocalStorageKey local_key) { #ifdef V8_FAST_TLS_SUPPORTED -static Atomic32 tls_base_offset_initialized = 0; +static std::atomic<bool> tls_base_offset_initialized{false}; intptr_t kMacTlsBaseOffset = 0; // It's safe to do the initialization more that once, but it has to be @@ -851,7 +857,7 @@ static void InitializeTlsBaseOffset() { kMacTlsBaseOffset = 0; } - Release_Store(&tls_base_offset_initialized, 1); + tls_base_offset_initialized.store(true, std::memory_order_release); } @@ -871,7 +877,7 @@ static void CheckFastTls(Thread::LocalStorageKey key) { Thread::LocalStorageKey Thread::CreateThreadLocalKey() { #ifdef V8_FAST_TLS_SUPPORTED bool check_fast_tls = false; - if (tls_base_offset_initialized == 0) { + if (!tls_base_offset_initialized.load(std::memory_order_acquire)) { check_fast_tls = true; InitializeTlsBaseOffset(); } diff --git a/deps/v8/src/base/platform/platform-qnx.cc b/deps/v8/src/base/platform/platform-qnx.cc index 640b77c816..f1ba3c6d45 100644 --- a/deps/v8/src/base/platform/platform-qnx.cc +++ b/deps/v8/src/base/platform/platform-qnx.cc @@ -146,5 +146,7 @@ std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() { void OS::SignalCodeMovingGC() {} +void OS::AdjustSchedulingParams() {} + } // namespace base } // namespace v8 diff --git a/deps/v8/src/base/platform/platform-solaris.cc b/deps/v8/src/base/platform/platform-solaris.cc index 477149db1b..b5b16dac56 100644 --- a/deps/v8/src/base/platform/platform-solaris.cc +++ b/deps/v8/src/base/platform/platform-solaris.cc @@ -63,5 +63,7 @@ std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() { void OS::SignalCodeMovingGC() {} +void OS::AdjustSchedulingParams() {} + } // namespace base } // namespace v8 diff --git a/deps/v8/src/base/platform/platform-win32.cc b/deps/v8/src/base/platform/platform-win32.cc index c82ec5335a..6dc2053fcd 100644 --- a/deps/v8/src/base/platform/platform-win32.cc +++ b/deps/v8/src/base/platform/platform-win32.cc @@ -973,27 +973,34 @@ class Win32MemoryMappedFile final : public OS::MemoryMappedFile { // static -OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) { +OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name, + FileMode mode) { // Open a physical file. - HANDLE file = CreateFileA(name, GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, - OPEN_EXISTING, 0, nullptr); + DWORD access = GENERIC_READ; + if (mode == FileMode::kReadWrite) { + access |= GENERIC_WRITE; + } + HANDLE file = CreateFileA(name, access, FILE_SHARE_READ | FILE_SHARE_WRITE, + nullptr, OPEN_EXISTING, 0, nullptr); if (file == INVALID_HANDLE_VALUE) return nullptr; DWORD size = GetFileSize(file, nullptr); if (size == 0) return new Win32MemoryMappedFile(file, nullptr, nullptr, 0); + DWORD protection = + (mode == FileMode::kReadOnly) ? PAGE_READONLY : PAGE_READWRITE; // Create a file mapping for the physical file. HANDLE file_mapping = - CreateFileMapping(file, nullptr, PAGE_READWRITE, 0, size, nullptr); + CreateFileMapping(file, nullptr, protection, 0, size, nullptr); if (file_mapping == nullptr) return nullptr; // Map a view of the file into memory. - void* memory = MapViewOfFile(file_mapping, FILE_MAP_ALL_ACCESS, 0, 0, size); + DWORD view_access = + (mode == FileMode::kReadOnly) ? FILE_MAP_READ : FILE_MAP_ALL_ACCESS; + void* memory = MapViewOfFile(file_mapping, view_access, 0, 0, size); return new Win32MemoryMappedFile(file, file_mapping, memory, size); } - // static OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, size_t size, void* initial) { @@ -1065,58 +1072,44 @@ Win32MemoryMappedFile::~Win32MemoryMappedFile() { // DbgHelp isn't supported on MinGW yet #ifndef __MINGW32__ // DbgHelp.h functions. -typedef BOOL (__stdcall *DLL_FUNC_TYPE(SymInitialize))(IN HANDLE hProcess, - IN PSTR UserSearchPath, - IN BOOL fInvadeProcess); -typedef DWORD (__stdcall *DLL_FUNC_TYPE(SymGetOptions))(VOID); -typedef DWORD (__stdcall *DLL_FUNC_TYPE(SymSetOptions))(IN DWORD SymOptions); -typedef BOOL (__stdcall *DLL_FUNC_TYPE(SymGetSearchPath))( - IN HANDLE hProcess, - OUT PSTR SearchPath, - IN DWORD SearchPathLength); -typedef DWORD64 (__stdcall *DLL_FUNC_TYPE(SymLoadModule64))( - IN HANDLE hProcess, - IN HANDLE hFile, - IN PSTR ImageName, - IN PSTR ModuleName, - IN DWORD64 BaseOfDll, - IN DWORD SizeOfDll); -typedef BOOL (__stdcall *DLL_FUNC_TYPE(StackWalk64))( - DWORD MachineType, - HANDLE hProcess, - HANDLE hThread, - LPSTACKFRAME64 StackFrame, - PVOID ContextRecord, +using DLL_FUNC_TYPE(SymInitialize) = BOOL(__stdcall*)(IN HANDLE hProcess, + IN PSTR UserSearchPath, + IN BOOL fInvadeProcess); +using DLL_FUNC_TYPE(SymGetOptions) = DWORD(__stdcall*)(VOID); +using DLL_FUNC_TYPE(SymSetOptions) = DWORD(__stdcall*)(IN DWORD SymOptions); +using DLL_FUNC_TYPE(SymGetSearchPath) = BOOL(__stdcall*)( + IN HANDLE hProcess, OUT PSTR SearchPath, IN DWORD SearchPathLength); +using DLL_FUNC_TYPE(SymLoadModule64) = DWORD64(__stdcall*)( + IN HANDLE hProcess, IN HANDLE hFile, IN PSTR ImageName, IN PSTR ModuleName, + IN DWORD64 BaseOfDll, IN DWORD SizeOfDll); +using DLL_FUNC_TYPE(StackWalk64) = BOOL(__stdcall*)( + DWORD MachineType, HANDLE hProcess, HANDLE hThread, + LPSTACKFRAME64 StackFrame, PVOID ContextRecord, PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine, PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine, PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine, PTRANSLATE_ADDRESS_ROUTINE64 TranslateAddress); -typedef BOOL (__stdcall *DLL_FUNC_TYPE(SymGetSymFromAddr64))( - IN HANDLE hProcess, - IN DWORD64 qwAddr, - OUT PDWORD64 pdwDisplacement, +using DLL_FUNC_TYPE(SymGetSymFromAddr64) = BOOL(__stdcall*)( + IN HANDLE hProcess, IN DWORD64 qwAddr, OUT PDWORD64 pdwDisplacement, OUT PIMAGEHLP_SYMBOL64 Symbol); -typedef BOOL (__stdcall *DLL_FUNC_TYPE(SymGetLineFromAddr64))( - IN HANDLE hProcess, - IN DWORD64 qwAddr, - OUT PDWORD pdwDisplacement, - OUT PIMAGEHLP_LINE64 Line64); +using DLL_FUNC_TYPE(SymGetLineFromAddr64) = + BOOL(__stdcall*)(IN HANDLE hProcess, IN DWORD64 qwAddr, + OUT PDWORD pdwDisplacement, OUT PIMAGEHLP_LINE64 Line64); // DbgHelp.h typedefs. Implementation found in dbghelp.dll. -typedef PVOID (__stdcall *DLL_FUNC_TYPE(SymFunctionTableAccess64))( +using DLL_FUNC_TYPE(SymFunctionTableAccess64) = PVOID(__stdcall*)( HANDLE hProcess, DWORD64 AddrBase); // DbgHelp.h typedef PFUNCTION_TABLE_ACCESS_ROUTINE64 -typedef DWORD64 (__stdcall *DLL_FUNC_TYPE(SymGetModuleBase64))( +using DLL_FUNC_TYPE(SymGetModuleBase64) = DWORD64(__stdcall*)( HANDLE hProcess, DWORD64 AddrBase); // DbgHelp.h typedef PGET_MODULE_BASE_ROUTINE64 // TlHelp32.h functions. -typedef HANDLE (__stdcall *DLL_FUNC_TYPE(CreateToolhelp32Snapshot))( - DWORD dwFlags, - DWORD th32ProcessID); -typedef BOOL (__stdcall *DLL_FUNC_TYPE(Module32FirstW))(HANDLE hSnapshot, - LPMODULEENTRY32W lpme); -typedef BOOL (__stdcall *DLL_FUNC_TYPE(Module32NextW))(HANDLE hSnapshot, +using DLL_FUNC_TYPE(CreateToolhelp32Snapshot) = + HANDLE(__stdcall*)(DWORD dwFlags, DWORD th32ProcessID); +using DLL_FUNC_TYPE(Module32FirstW) = BOOL(__stdcall*)(HANDLE hSnapshot, LPMODULEENTRY32W lpme); +using DLL_FUNC_TYPE(Module32NextW) = BOOL(__stdcall*)(HANDLE hSnapshot, + LPMODULEENTRY32W lpme); #undef IN #undef VOID @@ -1404,5 +1397,7 @@ void Thread::SetThreadLocal(LocalStorageKey key, void* value) { DCHECK(result); } +void OS::AdjustSchedulingParams() {} + } // namespace base } // namespace v8 diff --git a/deps/v8/src/base/platform/platform.h b/deps/v8/src/base/platform/platform.h index e51d5cd547..78b1bcbaff 100644 --- a/deps/v8/src/base/platform/platform.h +++ b/deps/v8/src/base/platform/platform.h @@ -188,11 +188,14 @@ class V8_BASE_EXPORT OS { class V8_BASE_EXPORT MemoryMappedFile { public: + enum class FileMode { kReadOnly, kReadWrite }; + virtual ~MemoryMappedFile() = default; virtual void* memory() const = 0; virtual size_t size() const = 0; - static MemoryMappedFile* open(const char* name); + static MemoryMappedFile* open(const char* name, + FileMode mode = FileMode::kReadWrite); static MemoryMappedFile* create(const char* name, size_t size, void* initial); }; @@ -246,6 +249,8 @@ class V8_BASE_EXPORT OS { static int GetCurrentThreadId(); + static void AdjustSchedulingParams(); + static void ExitProcess(int exit_code); private: @@ -308,7 +313,7 @@ inline void EnsureConsoleOutput() { class V8_BASE_EXPORT Thread { public: // Opaque data type for thread-local storage keys. - typedef int32_t LocalStorageKey; + using LocalStorageKey = int32_t; class Options { public: diff --git a/deps/v8/src/base/platform/semaphore.h b/deps/v8/src/base/platform/semaphore.h index 62c9c93988..11ff0b9199 100644 --- a/deps/v8/src/base/platform/semaphore.h +++ b/deps/v8/src/base/platform/semaphore.h @@ -50,11 +50,11 @@ class V8_BASE_EXPORT Semaphore final { bool WaitFor(const TimeDelta& rel_time) V8_WARN_UNUSED_RESULT; #if V8_OS_MACOSX - typedef semaphore_t NativeHandle; + using NativeHandle = semaphore_t; #elif V8_OS_POSIX - typedef sem_t NativeHandle; + using NativeHandle = sem_t; #elif V8_OS_WIN - typedef HANDLE NativeHandle; + using NativeHandle = HANDLE; #endif NativeHandle& native_handle() { @@ -90,8 +90,8 @@ struct CreateSemaphoreTrait { template <int N> struct LazySemaphore { - typedef typename LazyDynamicInstance<Semaphore, CreateSemaphoreTrait<N>, - ThreadSafeInitOnceTrait>::type type; + using typename LazyDynamicInstance<Semaphore, CreateSemaphoreTrait<N>, + ThreadSafeInitOnceTrait>::type; }; #define LAZY_SEMAPHORE_INITIALIZER LAZY_DYNAMIC_INSTANCE_INITIALIZER diff --git a/deps/v8/src/base/platform/time.cc b/deps/v8/src/base/platform/time.cc index 5339e14ade..ecbd70fd74 100644 --- a/deps/v8/src/base/platform/time.cc +++ b/deps/v8/src/base/platform/time.cc @@ -19,7 +19,6 @@ #include <ostream> #if V8_OS_WIN -#include "src/base/atomicops.h" #include "src/base/lazy-instance.h" #include "src/base/win32-headers.h" #endif @@ -40,13 +39,23 @@ int64_t ComputeThreadTicks() { &thread_info_count); CHECK_EQ(kr, KERN_SUCCESS); - v8::base::CheckedNumeric<int64_t> absolute_micros( - thread_info_data.user_time.seconds + - thread_info_data.system_time.seconds); - absolute_micros *= v8::base::Time::kMicrosecondsPerSecond; - absolute_micros += (thread_info_data.user_time.microseconds + - thread_info_data.system_time.microseconds); - return absolute_micros.ValueOrDie(); + // We can add the seconds into a {int64_t} without overflow. + CHECK_LE(thread_info_data.user_time.seconds, + std::numeric_limits<int64_t>::max() - + thread_info_data.system_time.seconds); + int64_t seconds = + thread_info_data.user_time.seconds + thread_info_data.system_time.seconds; + // Multiplying the seconds by {kMicrosecondsPerSecond}, and adding something + // in [0, 2 * kMicrosecondsPerSecond) must result in a valid {int64_t}. + static constexpr int64_t kSecondsLimit = + (std::numeric_limits<int64_t>::max() / + v8::base::Time::kMicrosecondsPerSecond) - + 2; + CHECK_GT(kSecondsLimit, seconds); + int64_t micros = seconds * v8::base::Time::kMicrosecondsPerSecond; + micros += (thread_info_data.user_time.microseconds + + thread_info_data.system_time.microseconds); + return micros; } #elif V8_OS_POSIX // Helper function to get results from clock_gettime() and convert to a @@ -70,8 +79,14 @@ V8_INLINE int64_t ClockNow(clockid_t clk_id) { if (clock_gettime(clk_id, &ts) != 0) { UNREACHABLE(); } - v8::base::internal::CheckedNumeric<int64_t> result(ts.tv_sec); - result *= v8::base::Time::kMicrosecondsPerSecond; + // Multiplying the seconds by {kMicrosecondsPerSecond}, and adding something + // in [0, kMicrosecondsPerSecond) must result in a valid {int64_t}. + static constexpr int64_t kSecondsLimit = + (std::numeric_limits<int64_t>::max() / + v8::base::Time::kMicrosecondsPerSecond) - + 1; + CHECK_GT(kSecondsLimit, ts.tv_sec); + int64_t result = int64_t{ts.tv_sec} * v8::base::Time::kMicrosecondsPerSecond; #if defined(V8_OS_AIX) if (clk_id == CLOCK_THREAD_CPUTIME_ID) { result += (tc.stime / v8::base::Time::kNanosecondsPerMicrosecond); @@ -81,7 +96,7 @@ V8_INLINE int64_t ClockNow(clockid_t clk_id) { #else result += (ts.tv_nsec / v8::base::Time::kNanosecondsPerMicrosecond); #endif - return result.ValueOrDie(); + return result; #else // Monotonic clock not supported. return 0; #endif @@ -493,7 +508,7 @@ DWORD (*g_tick_function)(void) = &timeGetTimeWrapper; // "rollover" counter. union LastTimeAndRolloversState { // The state as a single 32-bit opaque value. - base::Atomic32 as_opaque_32; + int32_t as_opaque_32; // The state as usable values. struct { @@ -509,7 +524,7 @@ union LastTimeAndRolloversState { uint16_t rollovers; } as_values; }; -base::Atomic32 g_last_time_and_rollovers = 0; +std::atomic<int32_t> g_last_time_and_rollovers{0}; static_assert(sizeof(LastTimeAndRolloversState) <= sizeof(g_last_time_and_rollovers), "LastTimeAndRolloversState does not fit in a single atomic word"); @@ -523,12 +538,12 @@ TimeTicks RolloverProtectedNow() { LastTimeAndRolloversState state; DWORD now; // DWORD is always unsigned 32 bits. + // Fetch the "now" and "last" tick values, updating "last" with "now" and + // incrementing the "rollovers" counter if the tick-value has wrapped back + // around. Atomic operations ensure that both "last" and "rollovers" are + // always updated together. + int32_t original = g_last_time_and_rollovers.load(std::memory_order_acquire); while (true) { - // Fetch the "now" and "last" tick values, updating "last" with "now" and - // incrementing the "rollovers" counter if the tick-value has wrapped back - // around. Atomic operations ensure that both "last" and "rollovers" are - // always updated together. - int32_t original = base::Acquire_Load(&g_last_time_and_rollovers); state.as_opaque_32 = original; now = g_tick_function(); uint8_t now_8 = static_cast<uint8_t>(now >> 24); @@ -540,11 +555,13 @@ TimeTicks RolloverProtectedNow() { // Save the changed state. If the existing value is unchanged from the // original, exit the loop. - int32_t check = base::Release_CompareAndSwap(&g_last_time_and_rollovers, - original, state.as_opaque_32); - if (check == original) break; + if (g_last_time_and_rollovers.compare_exchange_weak( + original, state.as_opaque_32, std::memory_order_acq_rel)) { + break; + } // Another thread has done something in between so retry from the top. + // {original} has been updated by the {compare_exchange_weak}. } return TimeTicks() + diff --git a/deps/v8/src/base/platform/time.h b/deps/v8/src/base/platform/time.h index fd8ef10b55..afe4724382 100644 --- a/deps/v8/src/base/platform/time.h +++ b/deps/v8/src/base/platform/time.h @@ -14,7 +14,6 @@ #include "src/base/base-export.h" #include "src/base/bits.h" #include "src/base/macros.h" -#include "src/base/safe_math.h" #if V8_OS_WIN #include "src/base/win32-headers.h" #endif |