diff options
Diffstat (limited to 'deps/v8/src/platform-win32.cc')
-rw-r--r-- | deps/v8/src/platform-win32.cc | 128 |
1 files changed, 72 insertions, 56 deletions
diff --git a/deps/v8/src/platform-win32.cc b/deps/v8/src/platform-win32.cc index 2801b711bf..9e377a1977 100644 --- a/deps/v8/src/platform-win32.cc +++ b/deps/v8/src/platform-win32.cc @@ -51,6 +51,22 @@ int strncasecmp(const char* s1, const char* s2, int n) { // the Microsoft Visual Studio C++ CRT. #ifdef __MINGW32__ + +#ifndef __MINGW64_VERSION_MAJOR + +#define _TRUNCATE 0 +#define STRUNCATE 80 + +inline void MemoryBarrier() { + int barrier = 0; + __asm__ __volatile__("xchgl %%eax,%0 ":"=r" (barrier)); +} + +#endif // __MINGW64_VERSION_MAJOR + + +#ifndef MINGW_HAS_SECURE_API + int localtime_s(tm* out_tm, const time_t* time) { tm* posix_local_time_struct = localtime(time); if (posix_local_time_struct == NULL) return 1; @@ -64,21 +80,6 @@ int fopen_s(FILE** pFile, const char* filename, const char* mode) { return *pFile != NULL ? 0 : 1; } - -#ifndef __MINGW64_VERSION_MAJOR - -// Not sure this the correct interpretation of _mkgmtime -time_t _mkgmtime(tm* timeptr) { - return mktime(timeptr); -} - - -#define _TRUNCATE 0 -#define STRUNCATE 80 - -#endif // __MINGW64_VERSION_MAJOR - - int _vsnprintf_s(char* buffer, size_t sizeOfBuffer, size_t count, const char* format, va_list argptr) { ASSERT(count == _TRUNCATE); @@ -112,16 +113,7 @@ int strncpy_s(char* dest, size_t dest_size, const char* source, size_t count) { return 0; } - -#ifndef __MINGW64_VERSION_MAJOR - -inline void MemoryBarrier() { - int barrier = 0; - __asm__ __volatile__("xchgl %%eax,%0 ":"=r" (barrier)); -} - -#endif // __MINGW64_VERSION_MAJOR - +#endif // MINGW_HAS_SECURE_API #endif // __MINGW32__ @@ -149,20 +141,11 @@ static Mutex* limit_mutex = NULL; #if defined(V8_TARGET_ARCH_IA32) static OS::MemCopyFunction memcopy_function = NULL; -static LazyMutex memcopy_function_mutex = LAZY_MUTEX_INITIALIZER; // Defined in codegen-ia32.cc. OS::MemCopyFunction CreateMemCopyFunction(); // Copy memory area to disjoint memory area. void OS::MemCopy(void* dest, const void* src, size_t size) { - if (memcopy_function == NULL) { - ScopedLock lock(memcopy_function_mutex.Pointer()); - if (memcopy_function == NULL) { - OS::MemCopyFunction temp = CreateMemCopyFunction(); - MemoryBarrier(); - memcopy_function = temp; - } - } // Note: here we rely on dependent reads being ordered. This is true // on all architectures we currently support. (*memcopy_function)(dest, src, size); @@ -175,7 +158,6 @@ void OS::MemCopy(void* dest, const void* src, size_t size) { #ifdef _WIN64 typedef double (*ModuloFunction)(double, double); static ModuloFunction modulo_function = NULL; -V8_DECLARE_ONCE(modulo_function_init_once); // Defined in codegen-x64.cc. ModuloFunction CreateModuloFunction(); @@ -184,7 +166,6 @@ void init_modulo_function() { } double modulo(double x, double y) { - CallOnce(&modulo_function_init_once, &init_modulo_function); // Note: here we rely on dependent reads being ordered. This is true // on all architectures we currently support. return (*modulo_function)(x, y); @@ -207,13 +188,10 @@ double modulo(double x, double y) { #define UNARY_MATH_FUNCTION(name, generator) \ static UnaryMathFunction fast_##name##_function = NULL; \ -V8_DECLARE_ONCE(fast_##name##_init_once); \ void init_fast_##name##_function() { \ fast_##name##_function = generator; \ } \ double fast_##name(double x) { \ - CallOnce(&fast_##name##_init_once, \ - &init_fast_##name##_function); \ return (*fast_##name##_function)(x); \ } @@ -226,6 +204,18 @@ UNARY_MATH_FUNCTION(sqrt, CreateSqrtFunction()) #undef MATH_FUNCTION +void MathSetup() { +#ifdef _WIN64 + init_modulo_function(); +#endif + init_fast_sin_function(); + init_fast_cos_function(); + init_fast_tan_function(); + init_fast_log_function(); + init_fast_sqrt_function(); +} + + // ---------------------------------------------------------------------------- // The Time class represents time on win32. A timestamp is represented as // a 64-bit integer in 100 nanoseconds since January 1, 1601 (UTC). JavaScript @@ -470,6 +460,9 @@ void Time::SetToCurrentTime() { // Check if we need to resync due to elapsed time. needs_resync |= (time_now.t_ - init_time.t_) > kMaxClockElapsedTime; + // Check if we need to resync due to backwards time change. + needs_resync |= time_now.t_ < init_time.t_; + // Resync the clock if necessary. if (needs_resync) { GetSystemTimeAsFileTime(&init_time.ft_); @@ -511,11 +504,14 @@ int64_t Time::LocalOffset() { // Convert to local time, as struct with fields for day, hour, year, etc. tm posix_local_time_struct; if (localtime_s(&posix_local_time_struct, &posix_time)) return 0; - // Convert local time in struct to POSIX time as if it were a UTC time. - time_t local_posix_time = _mkgmtime(&posix_local_time_struct); - Time localtime(1000.0 * local_posix_time); - return localtime.Diff(&rounded_to_second); + if (posix_local_time_struct.tm_isdst > 0) { + return (tzinfo_.Bias + tzinfo_.DaylightBias) * -kMsPerMinute; + } else if (posix_local_time_struct.tm_isdst == 0) { + return (tzinfo_.Bias + tzinfo_.StandardBias) * -kMsPerMinute; + } else { + return tzinfo_.Bias * -kMsPerMinute; + } } @@ -558,15 +554,13 @@ char* Time::LocalTimezone() { } -void OS::SetUp() { - // Seed the random number generator. - // Convert the current time to a 64-bit integer first, before converting it - // to an unsigned. Going directly can cause an overflow and the seed to be - // set to all ones. The seed will be identical for different instances that - // call this setup code within the same millisecond. - uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis()); - srand(static_cast<unsigned int>(seed)); - limit_mutex = CreateMutex(); +void OS::PostSetUp() { + // Math functions depend on CPU features therefore they are initialized after + // CPU. + MathSetup(); +#if defined(V8_TARGET_ARCH_IA32) + memcopy_function = CreateMemCopyFunction(); +#endif } @@ -1955,8 +1949,11 @@ class SamplerThread : public Thread { : Thread(Thread::Options("SamplerThread", kSamplerThreadStackSize)), interval_(interval) {} + static void SetUp() { if (!mutex_) mutex_ = OS::CreateMutex(); } + static void TearDown() { delete mutex_; } + static void AddActiveSampler(Sampler* sampler) { - ScopedLock lock(mutex_.Pointer()); + ScopedLock lock(mutex_); SamplerRegistry::AddActiveSampler(sampler); if (instance_ == NULL) { instance_ = new SamplerThread(sampler->interval()); @@ -1967,7 +1964,7 @@ class SamplerThread : public Thread { } static void RemoveActiveSampler(Sampler* sampler) { - ScopedLock lock(mutex_.Pointer()); + ScopedLock lock(mutex_); SamplerRegistry::RemoveActiveSampler(sampler); if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); @@ -2053,7 +2050,7 @@ class SamplerThread : public Thread { RuntimeProfilerRateLimiter rate_limiter_; // Protects the process wide state below. - static LazyMutex mutex_; + static Mutex* mutex_; static SamplerThread* instance_; private: @@ -2061,10 +2058,29 @@ class SamplerThread : public Thread { }; -LazyMutex SamplerThread::mutex_ = LAZY_MUTEX_INITIALIZER; +Mutex* SamplerThread::mutex_ = NULL; SamplerThread* SamplerThread::instance_ = NULL; +void OS::SetUp() { + // Seed the random number generator. + // Convert the current time to a 64-bit integer first, before converting it + // to an unsigned. Going directly can cause an overflow and the seed to be + // set to all ones. The seed will be identical for different instances that + // call this setup code within the same millisecond. + uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis()); + srand(static_cast<unsigned int>(seed)); + limit_mutex = CreateMutex(); + SamplerThread::SetUp(); +} + + +void OS::TearDown() { + SamplerThread::TearDown(); + delete limit_mutex; +} + + Sampler::Sampler(Isolate* isolate, int interval) : isolate_(isolate), interval_(interval), |