Title: [251475] trunk/Source
Revision
251475
Author
[email protected]
Date
2019-10-22 22:16:51 -0700 (Tue, 22 Oct 2019)

Log Message

Make `JSGlobalObject*` threading change more stabilized by adding tests and assertions
https://bugs.webkit.org/show_bug.cgi?id=203274

Reviewed by Saam Barati.

Source/_javascript_Core:

This patch does some follow-up changes after r251425.

1. Add tests that tests vm.topCallFrame from C++ world to ensure that `vm.topCallFrame` is kept nullptr if it is accessed from C++ world even after executing some scripts.
2. Add assertion to ensure that `DECLARE_CALL_FRAME` is only called in JIT operation's prologue.
3. Remove some of ExecState::deprecatedVM call.
4. Define `USE(BUILTIN_FRAME_ADDRESS)` when using __builtin_frame_address to get CallFrame.

* API/tests/testapi.cpp:
(TestAPI::topCallFrameAccess):
(testCAPIViaCpp):
* interpreter/CallFrame.cpp:
(JSC::isFromJSCode):
* interpreter/CallFrame.h:
* jit/CCallHelpers.h:
(JSC::CCallHelpers::prepareCallOperation):
* tools/VMInspector.cpp:
(JSC::VMInspector::dumpRegisters):

Source/WTF:

* wtf/Platform.h:

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/API/tests/testapi.cpp (251474 => 251475)


--- trunk/Source/_javascript_Core/API/tests/testapi.cpp	2019-10-23 03:51:33 UTC (rev 251474)
+++ trunk/Source/_javascript_Core/API/tests/testapi.cpp	2019-10-23 05:16:51 UTC (rev 251475)
@@ -143,6 +143,7 @@
     void promiseUnhandledRejection();
     void promiseUnhandledRejectionFromUnhandledRejectionCallback();
     void promiseEarlyHandledRejections();
+    void topCallFrameAccess();
 
     int failed() const { return m_failed; }
 
@@ -591,6 +592,34 @@
     check(!callbackCalled, "unhandled rejection callback should not be called for asynchronous early-handled rejection");
 }
 
+void TestAPI::topCallFrameAccess()
+{
+    {
+        JSObjectRef function = JSValueToObject(context, evaluateScript("(function () { })").value(), nullptr);
+        APIString argumentsString("arguments");
+        auto arguments = JSObjectGetProperty(context, function, argumentsString, nullptr);
+        check(JSValueIsNull(context, arguments), "vm.topCallFrame access from C++ world should use nullptr internally for arguments");
+    }
+    {
+        JSObjectRef arguments = JSValueToObject(context, evaluateScript("(function ok(v) { return ok.arguments; })(42)").value(), nullptr);
+        check(!JSValueIsNull(context, arguments), "vm.topCallFrame is materialized and we found the caller function's arguments");
+    }
+    {
+        JSObjectRef function = JSValueToObject(context, evaluateScript("(function () { })").value(), nullptr);
+        APIString callerString("caller");
+        auto caller = JSObjectGetProperty(context, function, callerString, nullptr);
+        check(JSValueIsNull(context, caller), "vm.topCallFrame access from C++ world should use nullptr internally for caller");
+    }
+    {
+        JSObjectRef caller = JSValueToObject(context, evaluateScript("(function () { return (function ok(v) { return ok.caller; })(42); })()").value(), nullptr);
+        check(!JSValueIsNull(context, caller), "vm.topCallFrame is materialized and we found the caller function's caller");
+    }
+    {
+        JSObjectRef caller = JSValueToObject(context, evaluateScript("(function ok(v) { return ok.caller; })(42)").value(), nullptr);
+        check(JSValueIsNull(context, caller), "vm.topCallFrame is materialized and we found the caller function's caller, but the caller is global code");
+    }
+}
+
 void configureJSCForTesting()
 {
     JSC::Config::configureForTesting();
@@ -617,6 +646,7 @@
         return !filter || WTF::findIgnoringASCIICaseWithoutLength(testName, filter) != WTF::notFound;
     };
 
+    RUN(topCallFrameAccess());
     RUN(basicSymbol());
     RUN(symbolsTypeof());
     RUN(symbolsDescription());

Modified: trunk/Source/_javascript_Core/ChangeLog (251474 => 251475)


--- trunk/Source/_javascript_Core/ChangeLog	2019-10-23 03:51:33 UTC (rev 251474)
+++ trunk/Source/_javascript_Core/ChangeLog	2019-10-23 05:16:51 UTC (rev 251475)
@@ -1,5 +1,30 @@
 2019-10-22  Yusuke Suzuki  <[email protected]>
 
+        Make `JSGlobalObject*` threading change more stabilized by adding tests and assertions
+        https://bugs.webkit.org/show_bug.cgi?id=203274
+
+        Reviewed by Saam Barati.
+
+        This patch does some follow-up changes after r251425.
+
+        1. Add tests that tests vm.topCallFrame from C++ world to ensure that `vm.topCallFrame` is kept nullptr if it is accessed from C++ world even after executing some scripts.
+        2. Add assertion to ensure that `DECLARE_CALL_FRAME` is only called in JIT operation's prologue.
+        3. Remove some of ExecState::deprecatedVM call.
+        4. Define `USE(BUILTIN_FRAME_ADDRESS)` when using __builtin_frame_address to get CallFrame.
+
+        * API/tests/testapi.cpp:
+        (TestAPI::topCallFrameAccess):
+        (testCAPIViaCpp):
+        * interpreter/CallFrame.cpp:
+        (JSC::isFromJSCode):
+        * interpreter/CallFrame.h:
+        * jit/CCallHelpers.h:
+        (JSC::CCallHelpers::prepareCallOperation):
+        * tools/VMInspector.cpp:
+        (JSC::VMInspector::dumpRegisters):
+
+2019-10-22  Yusuke Suzuki  <[email protected]>
+
         Unreviewed, WinCairo build fix after r251468
         https://bugs.webkit.org/show_bug.cgi?id=203276
 

Modified: trunk/Source/_javascript_Core/interpreter/CallFrame.cpp (251474 => 251475)


--- trunk/Source/_javascript_Core/interpreter/CallFrame.cpp	2019-10-23 03:51:33 UTC (rev 251474)
+++ trunk/Source/_javascript_Core/interpreter/CallFrame.cpp	2019-10-23 05:16:51 UTC (rev 251475)
@@ -27,10 +27,12 @@
 #include "CallFrame.h"
 
 #include "CodeBlock.h"
+#include "ExecutableAllocator.h"
 #include "InlineCallFrame.h"
 #include "Interpreter.h"
 #include "JSCInlines.h"
 #include "JSWebAssemblyInstance.h"
+#include "LLIntPCRanges.h"
 #include "VMEntryScope.h"
 #include "WasmContextInlines.h"
 #include "WasmInstance.h"
@@ -355,4 +357,18 @@
     setArgumentCountIncludingThis(0);
 }
 
+bool isFromJSCode(void* returnAddress)
+{
+    UNUSED_PARAM(returnAddress);
+#if ENABLE(JIT)
+    if (isJITPC(returnAddress))
+        return true;
+#endif
+#if ENABLE(C_LOOP)
+    return true;
+#else
+    return LLInt::isLLIntPC(returnAddress);
+#endif
+}
+
 } // namespace JSC

Modified: trunk/Source/_javascript_Core/interpreter/CallFrame.h (251474 => 251475)


--- trunk/Source/_javascript_Core/interpreter/CallFrame.h	2019-10-23 03:51:33 UTC (rev 251474)
+++ trunk/Source/_javascript_Core/interpreter/CallFrame.h	2019-10-23 05:16:51 UTC (rev 251475)
@@ -324,9 +324,14 @@
 
 // Helper function to get VM& from JSGlobalObject* if JSGlobalObject.h is not included.
 VM& getVM(JSGlobalObject*);
+JS_EXPORT_PRIVATE bool isFromJSCode(void* returnAddress);
 
-#if COMPILER(GCC_COMPATIBLE) && (CPU(ARM64) || CPU(X86_64)) && (OS(LINUX) || OS(DARWIN))
-#define DECLARE_CALL_FRAME(vm) (bitwise_cast<JSC::CallFrame*>(__builtin_frame_address(1)))
+#if USE(BUILTIN_FRAME_ADDRESS)
+#define DECLARE_CALL_FRAME(vm) \
+    ({ \
+        ASSERT(JSC::isFromJSCode(removeCodePtrTag<void*>(__builtin_return_address(0)))); \
+        bitwise_cast<JSC::CallFrame*>(__builtin_frame_address(1)); \
+    })
 #else
 #define DECLARE_CALL_FRAME(vm) ((vm).topCallFrame)
 #endif

Modified: trunk/Source/_javascript_Core/jit/CCallHelpers.h (251474 => 251475)


--- trunk/Source/_javascript_Core/jit/CCallHelpers.h	2019-10-23 03:51:33 UTC (rev 251474)
+++ trunk/Source/_javascript_Core/jit/CCallHelpers.h	2019-10-23 05:16:51 UTC (rev 251475)
@@ -86,7 +86,7 @@
 
     void prepareCallOperation(VM& vm)
     {
-#if COMPILER(GCC_COMPATIBLE) && (CPU(ARM64) || CPU(X86_64)) && (OS(LINUX) || OS(DARWIN))
+#if USE(BUILTIN_FRAME_ADDRESS)
         UNUSED_PARAM(vm);
 #else
         storePtr(GPRInfo::callFrameRegister, &vm.topCallFrame);

Modified: trunk/Source/_javascript_Core/tools/VMInspector.cpp (251474 => 251475)


--- trunk/Source/_javascript_Core/tools/VMInspector.cpp	2019-10-23 03:51:33 UTC (rev 251474)
+++ trunk/Source/_javascript_Core/tools/VMInspector.cpp	2019-10-23 05:16:51 UTC (rev 251475)
@@ -421,7 +421,7 @@
     dataLogLn(codeBlock);
     --it;
 #if ENABLE(JIT)
-    AbstractPC pc = callFrame->abstractReturnPC(callFrame->deprecatedVM());
+    AbstractPC pc = callFrame->abstractReturnPC(vm);
     if (pc.hasJITReturnAddress())
         dataLogF("[ReturnPC]                 | %10p | %p \n", it, pc.jitReturnAddress().value());
     --it;

Modified: trunk/Source/WTF/ChangeLog (251474 => 251475)


--- trunk/Source/WTF/ChangeLog	2019-10-23 03:51:33 UTC (rev 251474)
+++ trunk/Source/WTF/ChangeLog	2019-10-23 05:16:51 UTC (rev 251475)
@@ -1,3 +1,12 @@
+2019-10-22  Yusuke Suzuki  <[email protected]>
+
+        Make `JSGlobalObject*` threading change more stabilized by adding tests and assertions
+        https://bugs.webkit.org/show_bug.cgi?id=203274
+
+        Reviewed by Saam Barati.
+
+        * wtf/Platform.h:
+
 2019-10-22  Antti Koivisto  <[email protected]>
 
         operator==(Vector, Vector) should work with different inline capacities

Modified: trunk/Source/WTF/wtf/Platform.h (251474 => 251475)


--- trunk/Source/WTF/wtf/Platform.h	2019-10-23 03:51:33 UTC (rev 251474)
+++ trunk/Source/WTF/wtf/Platform.h	2019-10-23 05:16:51 UTC (rev 251475)
@@ -1000,6 +1000,11 @@
 #define USE_LLINT_EMBEDDED_OPCODE_ID 1
 #endif
 
+/* Use __builtin_frame_address(1) to get CallFrame* */
+#if COMPILER(GCC_COMPATIBLE) && (CPU(ARM64) || CPU(X86_64)) && (OS(LINUX) || OS(DARWIN))
+#define USE_BUILTIN_FRAME_ADDRESS 1
+#endif
+
 /* Regular _expression_ Tracing - Set to 1 to trace RegExp's in jsc.  Results dumped at exit */
 #define ENABLE_REGEXP_TRACING 0
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to