diff options
Diffstat (limited to 'chromium/v8/src/platform-win32.cc')
-rw-r--r-- | chromium/v8/src/platform-win32.cc | 202 |
1 files changed, 73 insertions, 129 deletions
diff --git a/chromium/v8/src/platform-win32.cc b/chromium/v8/src/platform-win32.cc index ea4f7ea11f4..ea11806cb41 100644 --- a/chromium/v8/src/platform-win32.cc +++ b/chromium/v8/src/platform-win32.cc @@ -133,11 +133,6 @@ intptr_t OS::MaxVirtualMemory() { } -double ceiling(double x) { - return ceil(x); -} - - #if V8_TARGET_ARCH_IA32 static void MemMoveWrapper(void* dest, const void* src, size_t size) { memmove(dest, src, size); @@ -240,12 +235,16 @@ void MathSetup() { class Win32Time { public: // Constructors. + Win32Time(); explicit Win32Time(double jstime); Win32Time(int year, int mon, int day, int hour, int min, int sec); // Convert timestamp to JavaScript representation. double ToJSTime(); + // Set timestamp to current time. + void SetToCurrentTime(); + // Returns the local timezone offset in milliseconds east of UTC. This is // the number of milliseconds you must add to UTC to get local time, i.e. // LocalOffset(CET) = 3600000 and LocalOffset(PST) = -28800000. This @@ -314,6 +313,12 @@ char Win32Time::std_tz_name_[kTzNameSize]; char Win32Time::dst_tz_name_[kTzNameSize]; +// Initialize timestamp to start of epoc. +Win32Time::Win32Time() { + t() = 0; +} + + // Initialize timestamp from a JavaScript timestamp. Win32Time::Win32Time(double jstime) { t() = static_cast<int64_t>(jstime) * kTimeScaler + kTimeEpoc; @@ -340,6 +345,62 @@ double Win32Time::ToJSTime() { } +// Set timestamp to current time. +void Win32Time::SetToCurrentTime() { + // The default GetSystemTimeAsFileTime has a ~15.5ms resolution. + // Because we're fast, we like fast timers which have at least a + // 1ms resolution. + // + // timeGetTime() provides 1ms granularity when combined with + // timeBeginPeriod(). If the host application for v8 wants fast + // timers, it can use timeBeginPeriod to increase the resolution. + // + // Using timeGetTime() has a drawback because it is a 32bit value + // and hence rolls-over every ~49days. + // + // To use the clock, we use GetSystemTimeAsFileTime as our base; + // and then use timeGetTime to extrapolate current time from the + // start time. To deal with rollovers, we resync the clock + // any time when more than kMaxClockElapsedTime has passed or + // whenever timeGetTime creates a rollover. + + static bool initialized = false; + static TimeStamp init_time; + static DWORD init_ticks; + static const int64_t kHundredNanosecondsPerSecond = 10000000; + static const int64_t kMaxClockElapsedTime = + 60*kHundredNanosecondsPerSecond; // 1 minute + + // If we are uninitialized, we need to resync the clock. + bool needs_resync = !initialized; + + // Get the current time. + TimeStamp time_now; + GetSystemTimeAsFileTime(&time_now.ft_); + DWORD ticks_now = timeGetTime(); + + // Check if we need to resync due to clock rollover. + needs_resync |= ticks_now < init_ticks; + + // 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_); + init_ticks = ticks_now = timeGetTime(); + initialized = true; + } + + // Finally, compute the actual time. Why is this so hard. + DWORD elapsed = ticks_now - init_ticks; + this->time_.t_ = init_time.t_ + (static_cast<int64_t>(elapsed) * 10000); +} + + // Guess the name of the timezone from the bias. // The guess is very biased towards the northern hemisphere. const char* Win32Time::GuessTimezoneNameFromBias(int bias) { @@ -891,11 +952,6 @@ void OS::DebugBreak() { } -void OS::DumpBacktrace() { - // Currently unsupported. -} - - class Win32MemoryMappedFile : public OS::MemoryMappedFile { public: Win32MemoryMappedFile(HANDLE file, @@ -1208,133 +1264,21 @@ void OS::SignalCodeMovingGC() { } -// Walk the stack using the facilities in dbghelp.dll and tlhelp32.dll - -// Switch off warning 4748 (/GS can not protect parameters and local variables -// from local buffer overrun because optimizations are disabled in function) as -// it is triggered by the use of inline assembler. -#pragma warning(push) -#pragma warning(disable : 4748) -int OS::StackWalk(Vector<OS::StackFrame> frames) { - BOOL ok; - - // Load the required functions from DLL's. - if (!LoadDbgHelpAndTlHelp32()) return kStackWalkError; - - // Get the process and thread handles. - HANDLE process_handle = GetCurrentProcess(); - HANDLE thread_handle = GetCurrentThread(); - - // Read the symbols. - if (!LoadSymbols(Isolate::Current(), process_handle)) return kStackWalkError; - - // Capture current context. - CONTEXT context; - RtlCaptureContext(&context); - - // Initialize the stack walking - STACKFRAME64 stack_frame; - memset(&stack_frame, 0, sizeof(stack_frame)); -#ifdef _WIN64 - stack_frame.AddrPC.Offset = context.Rip; - stack_frame.AddrFrame.Offset = context.Rbp; - stack_frame.AddrStack.Offset = context.Rsp; -#else - stack_frame.AddrPC.Offset = context.Eip; - stack_frame.AddrFrame.Offset = context.Ebp; - stack_frame.AddrStack.Offset = context.Esp; -#endif - stack_frame.AddrPC.Mode = AddrModeFlat; - stack_frame.AddrFrame.Mode = AddrModeFlat; - stack_frame.AddrStack.Mode = AddrModeFlat; - int frames_count = 0; - - // Collect stack frames. - int frames_size = frames.length(); - while (frames_count < frames_size) { - ok = _StackWalk64( - IMAGE_FILE_MACHINE_I386, // MachineType - process_handle, // hProcess - thread_handle, // hThread - &stack_frame, // StackFrame - &context, // ContextRecord - NULL, // ReadMemoryRoutine - _SymFunctionTableAccess64, // FunctionTableAccessRoutine - _SymGetModuleBase64, // GetModuleBaseRoutine - NULL); // TranslateAddress - if (!ok) break; - - // Store the address. - ASSERT((stack_frame.AddrPC.Offset >> 32) == 0); // 32-bit address. - frames[frames_count].address = - reinterpret_cast<void*>(stack_frame.AddrPC.Offset); - - // Try to locate a symbol for this frame. - DWORD64 symbol_displacement; - SmartArrayPointer<IMAGEHLP_SYMBOL64> symbol( - NewArray<IMAGEHLP_SYMBOL64>(kStackWalkMaxNameLen)); - if (symbol.is_empty()) return kStackWalkError; // Out of memory. - memset(*symbol, 0, sizeof(IMAGEHLP_SYMBOL64) + kStackWalkMaxNameLen); - (*symbol)->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL64); - (*symbol)->MaxNameLength = kStackWalkMaxNameLen; - ok = _SymGetSymFromAddr64(process_handle, // hProcess - stack_frame.AddrPC.Offset, // Address - &symbol_displacement, // Displacement - *symbol); // Symbol - if (ok) { - // Try to locate more source information for the symbol. - IMAGEHLP_LINE64 Line; - memset(&Line, 0, sizeof(Line)); - Line.SizeOfStruct = sizeof(Line); - DWORD line_displacement; - ok = _SymGetLineFromAddr64( - process_handle, // hProcess - stack_frame.AddrPC.Offset, // dwAddr - &line_displacement, // pdwDisplacement - &Line); // Line - // Format a text representation of the frame based on the information - // available. - if (ok) { - SNPrintF(MutableCStrVector(frames[frames_count].text, - kStackWalkMaxTextLen), - "%s %s:%d:%d", - (*symbol)->Name, Line.FileName, Line.LineNumber, - line_displacement); - } else { - SNPrintF(MutableCStrVector(frames[frames_count].text, - kStackWalkMaxTextLen), - "%s", - (*symbol)->Name); - } - // Make sure line termination is in place. - frames[frames_count].text[kStackWalkMaxTextLen - 1] = '\0'; - } else { - // No text representation of this frame - frames[frames_count].text[0] = '\0'; - - // Continue if we are just missing a module (for non C/C++ frames a - // module will never be found). - int err = GetLastError(); - if (err != ERROR_MOD_NOT_FOUND) { - break; - } - } - - frames_count++; +uint64_t OS::TotalPhysicalMemory() { + MEMORYSTATUSEX memory_info; + memory_info.dwLength = sizeof(memory_info); + if (!GlobalMemoryStatusEx(&memory_info)) { + UNREACHABLE(); + return 0; } - // Return the number of frames filled in. - return frames_count; + return static_cast<uint64_t>(memory_info.ullTotalPhys); } -// Restore warnings to previous settings. -#pragma warning(pop) - #else // __MINGW32__ void OS::LogSharedLibraryAddresses(Isolate* isolate) { } void OS::SignalCodeMovingGC() { } -int OS::StackWalk(Vector<OS::StackFrame> frames) { return 0; } #endif // __MINGW32__ |