Title: [188338] trunk/Source/_javascript_Core
Revision
188338
Author
[email protected]
Date
2015-08-12 11:14:02 -0700 (Wed, 12 Aug 2015)

Log Message

Add a JSC option to enable the watchdog for testing.
https://bugs.webkit.org/show_bug.cgi?id=147939

Reviewed by Michael Saboff.

* API/JSContextRef.cpp:
(JSContextGroupSetExecutionTimeLimit):
(createWatchdogIfNeeded): Deleted.
* runtime/Options.h:
* runtime/VM.cpp:
(JSC::VM::VM):
(JSC::VM::~VM):
(JSC::VM::sharedInstanceInternal):
(JSC::VM::ensureWatchdog):
(JSC::thunkGeneratorForIntrinsic):
* runtime/VM.h:

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/API/JSContextRef.cpp (188337 => 188338)


--- trunk/Source/_javascript_Core/API/JSContextRef.cpp	2015-08-12 17:53:55 UTC (rev 188337)
+++ trunk/Source/_javascript_Core/API/JSContextRef.cpp	2015-08-12 18:14:02 UTC (rev 188338)
@@ -92,24 +92,11 @@
     return callback(contextRef, callbackData);
 }
 
-static void createWatchdogIfNeeded(VM& vm)
-{
-    if (!vm.watchdog) {
-        vm.watchdog = adoptRef(new Watchdog());
-
-        // The LLINT peeks into the Watchdog object directly. In order to do that,
-        // the LLINT assumes that the internal shape of a std::unique_ptr is the
-        // same as a plain C++ pointer, and loads the address of Watchdog from it.
-        RELEASE_ASSERT(*reinterpret_cast<Watchdog**>(&vm.watchdog) == vm.watchdog.get());
-    }
-}
-
 void JSContextGroupSetExecutionTimeLimit(JSContextGroupRef group, double limit, JSShouldTerminateCallback callback, void* callbackData)
 {
     VM& vm = *toJS(group);
     JSLockHolder locker(&vm);
-    createWatchdogIfNeeded(vm);
-    Watchdog& watchdog = *vm.watchdog;
+    Watchdog& watchdog = vm.ensureWatchdog();
     if (callback) {
         void* callbackPtr = reinterpret_cast<void*>(callback);
         watchdog.setTimeLimit(vm, std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::duration<double>(limit)), internalScriptTimeoutCallback, callbackPtr, callbackData);

Modified: trunk/Source/_javascript_Core/ChangeLog (188337 => 188338)


--- trunk/Source/_javascript_Core/ChangeLog	2015-08-12 17:53:55 UTC (rev 188337)
+++ trunk/Source/_javascript_Core/ChangeLog	2015-08-12 18:14:02 UTC (rev 188338)
@@ -1,3 +1,22 @@
+2015-08-12  Mark Lam  <[email protected]>
+
+        Add a JSC option to enable the watchdog for testing.
+        https://bugs.webkit.org/show_bug.cgi?id=147939
+
+        Reviewed by Michael Saboff.
+
+        * API/JSContextRef.cpp:
+        (JSContextGroupSetExecutionTimeLimit):
+        (createWatchdogIfNeeded): Deleted.
+        * runtime/Options.h:
+        * runtime/VM.cpp:
+        (JSC::VM::VM):
+        (JSC::VM::~VM):
+        (JSC::VM::sharedInstanceInternal):
+        (JSC::VM::ensureWatchdog):
+        (JSC::thunkGeneratorForIntrinsic):
+        * runtime/VM.h:
+
 2015-08-11  Mark Lam  <[email protected]>
 
         Implementation _javascript_ watchdog using WTF::WorkQueue.

Modified: trunk/Source/_javascript_Core/runtime/Options.h (188337 => 188338)


--- trunk/Source/_javascript_Core/runtime/Options.h	2015-08-12 17:53:55 UTC (rev 188337)
+++ trunk/Source/_javascript_Core/runtime/Options.h	2015-08-12 18:14:02 UTC (rev 188338)
@@ -320,6 +320,8 @@
     \
     v(bool, enableDollarVM, false, "installs the $vm debugging tool in global objects") \
     v(optionString, functionOverrides, nullptr, "file with debugging overrides for function bodies") \
+    \
+    v(unsigned, watchdog, 0, "watchdog timeout (0 = Disabled, N = a timeout period of N milliseconds)") \
 
 class Options {
 public:

Modified: trunk/Source/_javascript_Core/runtime/VM.cpp (188337 => 188338)


--- trunk/Source/_javascript_Core/runtime/VM.cpp	2015-08-12 17:53:55 UTC (rev 188337)
+++ trunk/Source/_javascript_Core/runtime/VM.cpp	2015-08-12 18:14:02 UTC (rev 188338)
@@ -286,6 +286,12 @@
         enableTypeProfiler();
     if (Options::enableControlFlowProfiler())
         enableControlFlowProfiler();
+
+    if (Options::watchdog()) {
+        std::chrono::milliseconds timeoutMillis(Options::watchdog());
+        Watchdog& watchdog = ensureWatchdog();
+        watchdog.setTimeLimit(*this, timeoutMillis);
+    }
 }
 
 VM::~VM()
@@ -371,6 +377,19 @@
     return sharedInstance;
 }
 
+Watchdog& VM::ensureWatchdog()
+{
+    if (!watchdog) {
+        watchdog = adoptRef(new Watchdog());
+        
+        // The LLINT peeks into the Watchdog object directly. In order to do that,
+        // the LLINT assumes that the internal shape of a std::unique_ptr is the
+        // same as a plain C++ pointer, and loads the address of Watchdog from it.
+        RELEASE_ASSERT(*reinterpret_cast<Watchdog**>(&watchdog) == watchdog.get());
+    }
+    return *watchdog;
+}
+
 #if ENABLE(JIT)
 static ThunkGenerator thunkGeneratorForIntrinsic(Intrinsic intrinsic)
 {

Modified: trunk/Source/_javascript_Core/runtime/VM.h (188337 => 188338)


--- trunk/Source/_javascript_Core/runtime/VM.h	2015-08-12 17:53:55 UTC (rev 188337)
+++ trunk/Source/_javascript_Core/runtime/VM.h	2015-08-12 18:14:02 UTC (rev 188338)
@@ -237,6 +237,8 @@
     static Ref<VM> createContextGroup(HeapType = SmallHeap);
     JS_EXPORT_PRIVATE ~VM();
 
+    Watchdog& ensureWatchdog();
+
 private:
     RefPtr<JSLock> m_apiLock;
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to