Title: [193842] trunk/Source/_javascript_Core
Revision
193842
Author
sbar...@apple.com
Date
2015-12-09 10:31:24 -0800 (Wed, 09 Dec 2015)

Log Message

we should emit op_watchdog after op_enter
https://bugs.webkit.org/show_bug.cgi?id=151972

Reviewed by Mark Lam.

This also solves the issue of watchdog not being
observed when we loop purely through tail calls.

* API/tests/ExecutionTimeLimitTest.cpp:
(testExecutionTimeLimit):
* bytecompiler/BytecodeGenerator.cpp:
(JSC::BytecodeGenerator::BytecodeGenerator):
(JSC::BytecodeGenerator::emitProfiledOpcode):
(JSC::BytecodeGenerator::emitEnter):
(JSC::BytecodeGenerator::emitLoopHint):
* bytecompiler/BytecodeGenerator.h:

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/API/tests/ExecutionTimeLimitTest.cpp (193841 => 193842)


--- trunk/Source/_javascript_Core/API/tests/ExecutionTimeLimitTest.cpp	2015-12-09 18:24:35 UTC (rev 193841)
+++ trunk/Source/_javascript_Core/API/tests/ExecutionTimeLimitTest.cpp	2015-12-09 18:31:24 UTC (rev 193842)
@@ -171,6 +171,49 @@
             testResetAfterTimeout(failed);
         }
 
+        /* Test script timeout with tail calls: */
+        timeLimit = (100 + tierAdjustmentMillis) / 1000.0;
+        JSContextGroupSetExecutionTimeLimit(contextGroup, timeLimit, shouldTerminateCallback, 0);
+        {
+            unsigned timeAfterWatchdogShouldHaveFired = 300 + tierAdjustmentMillis;
+
+            StringBuilder scriptBuilder;
+            scriptBuilder.append("var startTime = currentCPUTime();"
+                                 "function recurse(i) {"
+                                     "'use strict';"
+                                     "if (i % 1000 === 0) {"
+                                        "if (currentCPUTime() - startTime >");
+            scriptBuilder.appendNumber(timeAfterWatchdogShouldHaveFired / 1000.0);
+            scriptBuilder.append("       ) { return; }");
+            scriptBuilder.append("    }");
+            scriptBuilder.append("    return recurse(i + 1); }");
+            scriptBuilder.append("recurse(0);");
+
+            JSStringRef script = JSStringCreateWithUTF8CString(scriptBuilder.toString().utf8().data());
+            exception = nullptr;
+            shouldTerminateCallbackWasCalled = false;
+            auto startTime = currentCPUTime();
+            JSEvaluateScript(context, script, nullptr, nullptr, 1, &exception);
+            auto endTime = currentCPUTime();
+
+            if (((endTime - startTime) < milliseconds(timeAfterWatchdogShouldHaveFired)) && shouldTerminateCallbackWasCalled)
+                printf("PASS: %s script with infinite tail calls timed out as expected .\n", tierOptions.tier);
+            else {
+                if ((endTime - startTime) >= milliseconds(timeAfterWatchdogShouldHaveFired))
+                    printf("FAIL: %s script with infinite tail calls did not time out as expected.\n", tierOptions.tier);
+                if (!shouldTerminateCallbackWasCalled)
+                    printf("FAIL: %s script with infinite tail calls' timeout callback was not called.\n", tierOptions.tier);
+                failed = true;
+            }
+            
+            if (!exception) {
+                printf("FAIL: %s TerminatedExecutionException was not thrown.\n", tierOptions.tier);
+                failed = true;
+            }
+
+            testResetAfterTimeout(failed);
+        }
+
         /* Test the script timeout's TerminatedExecutionException should NOT be catchable: */
         timeLimit = (100 + tierAdjustmentMillis) / 1000.0;
         JSContextGroupSetExecutionTimeLimit(contextGroup, timeLimit, shouldTerminateCallback, 0);

Modified: trunk/Source/_javascript_Core/ChangeLog (193841 => 193842)


--- trunk/Source/_javascript_Core/ChangeLog	2015-12-09 18:24:35 UTC (rev 193841)
+++ trunk/Source/_javascript_Core/ChangeLog	2015-12-09 18:31:24 UTC (rev 193842)
@@ -1,3 +1,22 @@
+2015-12-09  Saam barati  <sbar...@apple.com>
+
+        we should emit op_watchdog after op_enter
+        https://bugs.webkit.org/show_bug.cgi?id=151972
+
+        Reviewed by Mark Lam.
+
+        This also solves the issue of watchdog not being
+        observed when we loop purely through tail calls.
+
+        * API/tests/ExecutionTimeLimitTest.cpp:
+        (testExecutionTimeLimit):
+        * bytecompiler/BytecodeGenerator.cpp:
+        (JSC::BytecodeGenerator::BytecodeGenerator):
+        (JSC::BytecodeGenerator::emitProfiledOpcode):
+        (JSC::BytecodeGenerator::emitEnter):
+        (JSC::BytecodeGenerator::emitLoopHint):
+        * bytecompiler/BytecodeGenerator.h:
+
 2015-12-08  Benjamin Poulain  <bpoul...@apple.com>
 
         [JSC] Improve how B3 lowers Add() and Sub() on x86

Modified: trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.cpp (193841 => 193842)


--- trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.cpp	2015-12-09 18:24:35 UTC (rev 193841)
+++ trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.cpp	2015-12-09 18:31:24 UTC (rev 193842)
@@ -169,7 +169,7 @@
 
     m_codeBlock->setNumParameters(1); // Allocate space for "this"
 
-    emitOpcode(op_enter);
+    emitEnter();
 
     allocateAndEmitScope();
 
@@ -287,7 +287,7 @@
         return captures(uid) ? VarKind::Scope : VarKind::Stack;
     };
 
-    emitOpcode(op_enter);
+    emitEnter();
 
     allocateAndEmitScope();
     
@@ -603,7 +603,7 @@
 
     m_codeBlock->setNumParameters(1);
 
-    emitOpcode(op_enter);
+    emitEnter();
 
     allocateAndEmitScope();
 
@@ -686,7 +686,7 @@
         return captures(uid) ? VarKind::Scope : VarKind::Stack;
     };
 
-    emitOpcode(op_enter);
+    emitEnter();
 
     allocateAndEmitScope();
 
@@ -1092,6 +1092,12 @@
     return result;
 }
 
+void BytecodeGenerator::emitEnter()
+{
+    emitOpcode(op_enter);
+    emitWatchdog();
+}
+
 void BytecodeGenerator::emitLoopHint()
 {
     emitOpcode(op_loop_hint);

Modified: trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.h (193841 => 193842)


--- trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.h	2015-12-09 18:24:35 UTC (rev 193841)
+++ trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.h	2015-12-09 18:31:24 UTC (rev 193842)
@@ -600,6 +600,7 @@
         PassRefPtr<Label> emitJumpIfNotFunctionApply(RegisterID* cond, Label* target);
         void emitPopScopes(RegisterID* srcDst, int targetScopeDepth);
 
+        void emitEnter();
         void emitWatchdog();
 
         RegisterID* emitHasIndexedProperty(RegisterID* dst, RegisterID* base, RegisterID* propertyName);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to