Changeset 41126 in webkit for trunk/JavaScriptCore/interpreter/Interpreter.cpp
- Timestamp:
- Feb 22, 2009, 3:26:07 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/interpreter/Interpreter.cpp
r41100 r41126 67 67 #endif 68 68 69 #if PLATFORM(DARWIN)70 #include <mach/mach.h>71 #endif72 73 #if HAVE(SYS_TIME_H)74 #include <sys/time.h>75 #endif76 77 #if PLATFORM(WIN_OS)78 #include <windows.h>79 #endif80 81 #if PLATFORM(QT)82 #include <QDateTime>83 #endif84 85 69 using namespace std; 86 70 87 71 namespace JSC { 88 89 // Preferred number of milliseconds between each timeout check90 static const int preferredScriptCheckTimeInterval = 1000;91 72 92 73 static ALWAYS_INLINE unsigned bytecodeOffsetForPC(CallFrame* callFrame, CodeBlock* codeBlock, void* pc) … … 375 356 #endif 376 357 , m_reentryDepth(0) 377 , m_timeoutTime(0)378 , m_timeAtLastCheckTimeout(0)379 , m_timeExecuting(0)380 , m_timeoutCheckCount(0)381 , m_ticksUntilNextTimeoutCheck(initialTickCountThreshold)382 358 { 383 initTimeout();384 359 privateExecute(InitializeAndReturn, 0, 0, 0); 385 360 … … 887 862 } 888 863 889 void Interpreter::resetTimeoutCheck()890 {891 m_ticksUntilNextTimeoutCheck = initialTickCountThreshold;892 m_timeAtLastCheckTimeout = 0;893 m_timeExecuting = 0;894 }895 896 // Returns the time the current thread has spent executing, in milliseconds.897 static inline unsigned getCPUTime()898 {899 #if PLATFORM(DARWIN)900 mach_msg_type_number_t infoCount = THREAD_BASIC_INFO_COUNT;901 thread_basic_info_data_t info;902 903 // Get thread information904 mach_port_t threadPort = mach_thread_self();905 thread_info(threadPort, THREAD_BASIC_INFO, reinterpret_cast<thread_info_t>(&info), &infoCount);906 mach_port_deallocate(mach_task_self(), threadPort);907 908 unsigned time = info.user_time.seconds * 1000 + info.user_time.microseconds / 1000;909 time += info.system_time.seconds * 1000 + info.system_time.microseconds / 1000;910 911 return time;912 #elif HAVE(SYS_TIME_H)913 // FIXME: This should probably use getrusage with the RUSAGE_THREAD flag.914 struct timeval tv;915 gettimeofday(&tv, 0);916 return tv.tv_sec * 1000 + tv.tv_usec / 1000;917 #elif PLATFORM(QT)918 QDateTime t = QDateTime::currentDateTime();919 return t.toTime_t() * 1000 + t.time().msec();920 #elif PLATFORM(WIN_OS)921 union {922 FILETIME fileTime;923 unsigned long long fileTimeAsLong;924 } userTime, kernelTime;925 926 // GetThreadTimes won't accept NULL arguments so we pass these even though927 // they're not used.928 FILETIME creationTime, exitTime;929 930 GetThreadTimes(GetCurrentThread(), &creationTime, &exitTime, &kernelTime.fileTime, &userTime.fileTime);931 932 return userTime.fileTimeAsLong / 10000 + kernelTime.fileTimeAsLong / 10000;933 #else934 #error Platform does not have getCurrentTime function935 #endif936 }937 938 bool Interpreter::checkTimeout(JSGlobalObject* globalObject)939 {940 unsigned currentTime = getCPUTime();941 942 if (!m_timeAtLastCheckTimeout) {943 // Suspicious amount of looping in a script -- start timing it944 m_timeAtLastCheckTimeout = currentTime;945 return false;946 }947 948 unsigned timeDiff = currentTime - m_timeAtLastCheckTimeout;949 950 if (timeDiff == 0)951 timeDiff = 1;952 953 m_timeExecuting += timeDiff;954 m_timeAtLastCheckTimeout = currentTime;955 956 // Adjust the tick threshold so we get the next checkTimeout call in the interval specified in957 // preferredScriptCheckTimeInterval958 m_ticksUntilNextTimeoutCheck = static_cast<unsigned>((static_cast<float>(preferredScriptCheckTimeInterval) / timeDiff) * m_ticksUntilNextTimeoutCheck);959 // If the new threshold is 0 reset it to the default threshold. This can happen if the timeDiff is higher than the960 // preferred script check time interval.961 if (m_ticksUntilNextTimeoutCheck == 0)962 m_ticksUntilNextTimeoutCheck = initialTickCountThreshold;963 964 if (m_timeoutTime && m_timeExecuting > m_timeoutTime) {965 if (globalObject->shouldInterruptScript())966 return true;967 968 resetTimeoutCheck();969 }970 971 return false;972 }973 974 864 NEVER_INLINE ScopeChainNode* Interpreter::createExceptionScope(CallFrame* callFrame, const Instruction* vPC) 975 865 { … … 1196 1086 Instruction* vPC = callFrame->codeBlock()->instructions().begin(); 1197 1087 Profiler** enabledProfilerReference = Profiler::enabledProfilerReference(); 1198 unsigned tickCount = m_ticksUntilNextTimeoutCheck + 1;1088 unsigned tickCount = globalData->timeoutChecker.ticksUntilNextCheck(); 1199 1089 1200 1090 #define CHECK_FOR_EXCEPTION() \ … … 1212 1102 #define CHECK_FOR_TIMEOUT() \ 1213 1103 if (!--tickCount) { \ 1214 if ( checkTimeout(callFrame->dynamicGlobalObject())) { \1104 if (globalData->timeoutChecker.didTimeOut(callFrame)) { \ 1215 1105 exceptionValue = jsNull(); \ 1216 1106 goto vm_throw; \ 1217 1107 } \ 1218 tickCount = m_ticksUntilNextTimeoutCheck; \1108 tickCount = globalData->timeoutChecker.ticksUntilNextCheck(); \ 1219 1109 } 1220 1110
Note:
See TracChangeset
for help on using the changeset viewer.