Title: [246747] branches/safari-607-branch
Revision
246747
Author
[email protected]
Date
2019-06-24 11:52:46 -0700 (Mon, 24 Jun 2019)

Log Message

Cherry-pick r243626. rdar://problem/51927634

    CodeBlock::jettison() should disallow repatching its own calls
    https://bugs.webkit.org/show_bug.cgi?id=196359
    <rdar://problem/48973663>

    Reviewed by Saam Barati.

    JSTests:

    * stress/call-link-info-osrexit-repatch.js: Added.
    (foo):

    Source/_javascript_Core:

    CodeBlock::jettison() calls CommonData::invalidate, which replaces the `hlt`
    instruction with the jump to OSR exit. However, if the `hlt` was immediately
    followed by a call to the CodeBlock being jettisoned, we would write over the
    OSR exit address while unlinking all the incoming CallLinkInfos later in
    CodeBlock::jettison().

    Change it so that we set a flag, `clearedByJettison`, in all the CallLinkInfos
    owned by the CodeBlock being jettisoned. If the flag is set, we will avoid
    repatching the call during unlinking. This is safe because this call will never
    be reachable again after the CodeBlock is jettisoned.

    * bytecode/CallLinkInfo.cpp:
    (JSC::CallLinkInfo::CallLinkInfo):
    (JSC::CallLinkInfo::setCallee):
    (JSC::CallLinkInfo::clearCallee):
    (JSC::CallLinkInfo::setCodeBlock):
    (JSC::CallLinkInfo::clearCodeBlock):
    * bytecode/CallLinkInfo.h:
    (JSC::CallLinkInfo::clearedByJettison):
    (JSC::CallLinkInfo::setClearedByJettison):
    * bytecode/CodeBlock.cpp:
    (JSC::CodeBlock::jettison):
    * jit/Repatch.cpp:
    (JSC::revertCall):

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@243626 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Added Paths

Diff

Modified: branches/safari-607-branch/JSTests/ChangeLog (246746 => 246747)


--- branches/safari-607-branch/JSTests/ChangeLog	2019-06-24 18:52:43 UTC (rev 246746)
+++ branches/safari-607-branch/JSTests/ChangeLog	2019-06-24 18:52:46 UTC (rev 246747)
@@ -1,5 +1,61 @@
 2019-06-24  Kocsen Chung  <[email protected]>
 
+        Cherry-pick r243626. rdar://problem/51927634
+
+    CodeBlock::jettison() should disallow repatching its own calls
+    https://bugs.webkit.org/show_bug.cgi?id=196359
+    <rdar://problem/48973663>
+    
+    Reviewed by Saam Barati.
+    
+    JSTests:
+    
+    * stress/call-link-info-osrexit-repatch.js: Added.
+    (foo):
+    
+    Source/_javascript_Core:
+    
+    CodeBlock::jettison() calls CommonData::invalidate, which replaces the `hlt`
+    instruction with the jump to OSR exit. However, if the `hlt` was immediately
+    followed by a call to the CodeBlock being jettisoned, we would write over the
+    OSR exit address while unlinking all the incoming CallLinkInfos later in
+    CodeBlock::jettison().
+    
+    Change it so that we set a flag, `clearedByJettison`, in all the CallLinkInfos
+    owned by the CodeBlock being jettisoned. If the flag is set, we will avoid
+    repatching the call during unlinking. This is safe because this call will never
+    be reachable again after the CodeBlock is jettisoned.
+    
+    * bytecode/CallLinkInfo.cpp:
+    (JSC::CallLinkInfo::CallLinkInfo):
+    (JSC::CallLinkInfo::setCallee):
+    (JSC::CallLinkInfo::clearCallee):
+    (JSC::CallLinkInfo::setCodeBlock):
+    (JSC::CallLinkInfo::clearCodeBlock):
+    * bytecode/CallLinkInfo.h:
+    (JSC::CallLinkInfo::clearedByJettison):
+    (JSC::CallLinkInfo::setClearedByJettison):
+    * bytecode/CodeBlock.cpp:
+    (JSC::CodeBlock::jettison):
+    * jit/Repatch.cpp:
+    (JSC::revertCall):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@243626 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-03-28  Tadeu Zagallo  <[email protected]>
+
+            CodeBlock::jettison() should disallow repatching its own calls
+            https://bugs.webkit.org/show_bug.cgi?id=196359
+            <rdar://problem/48973663>
+
+            Reviewed by Saam Barati.
+
+            * stress/call-link-info-osrexit-repatch.js: Added.
+            (foo):
+
+2019-06-24  Kocsen Chung  <[email protected]>
+
         Cherry-pick r246505. rdar://problem/51927642
 
     [JSC] Introduce DisposableCallSiteIndex to enforce type-safety

Added: branches/safari-607-branch/JSTests/stress/call-link-info-osrexit-repatch.js (0 => 246747)


--- branches/safari-607-branch/JSTests/stress/call-link-info-osrexit-repatch.js	                        (rev 0)
+++ branches/safari-607-branch/JSTests/stress/call-link-info-osrexit-repatch.js	2019-06-24 18:52:46 UTC (rev 246747)
@@ -0,0 +1,18 @@
+//@ runFTLEager("--watchdog=1000", "--watchdog-exception-ok")
+
+function foo(a, b) {
+    'use strict';
+    if (a === 0) {
+        return;
+    }
+    if (a === 0) {
+        return foo(a + 0);
+    }
+    if (a === 0) {
+        return foo(+a, 0);
+    }
+    return foo(b / 1, a, 0);
+    0 === 0
+}
+
+foo(1, 5);

Modified: branches/safari-607-branch/Source/_javascript_Core/ChangeLog (246746 => 246747)


--- branches/safari-607-branch/Source/_javascript_Core/ChangeLog	2019-06-24 18:52:43 UTC (rev 246746)
+++ branches/safari-607-branch/Source/_javascript_Core/ChangeLog	2019-06-24 18:52:46 UTC (rev 246747)
@@ -1,5 +1,83 @@
 2019-06-24  Kocsen Chung  <[email protected]>
 
+        Cherry-pick r243626. rdar://problem/51927634
+
+    CodeBlock::jettison() should disallow repatching its own calls
+    https://bugs.webkit.org/show_bug.cgi?id=196359
+    <rdar://problem/48973663>
+    
+    Reviewed by Saam Barati.
+    
+    JSTests:
+    
+    * stress/call-link-info-osrexit-repatch.js: Added.
+    (foo):
+    
+    Source/_javascript_Core:
+    
+    CodeBlock::jettison() calls CommonData::invalidate, which replaces the `hlt`
+    instruction with the jump to OSR exit. However, if the `hlt` was immediately
+    followed by a call to the CodeBlock being jettisoned, we would write over the
+    OSR exit address while unlinking all the incoming CallLinkInfos later in
+    CodeBlock::jettison().
+    
+    Change it so that we set a flag, `clearedByJettison`, in all the CallLinkInfos
+    owned by the CodeBlock being jettisoned. If the flag is set, we will avoid
+    repatching the call during unlinking. This is safe because this call will never
+    be reachable again after the CodeBlock is jettisoned.
+    
+    * bytecode/CallLinkInfo.cpp:
+    (JSC::CallLinkInfo::CallLinkInfo):
+    (JSC::CallLinkInfo::setCallee):
+    (JSC::CallLinkInfo::clearCallee):
+    (JSC::CallLinkInfo::setCodeBlock):
+    (JSC::CallLinkInfo::clearCodeBlock):
+    * bytecode/CallLinkInfo.h:
+    (JSC::CallLinkInfo::clearedByJettison):
+    (JSC::CallLinkInfo::setClearedByJettison):
+    * bytecode/CodeBlock.cpp:
+    (JSC::CodeBlock::jettison):
+    * jit/Repatch.cpp:
+    (JSC::revertCall):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@243626 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-03-28  Tadeu Zagallo  <[email protected]>
+
+            CodeBlock::jettison() should disallow repatching its own calls
+            https://bugs.webkit.org/show_bug.cgi?id=196359
+            <rdar://problem/48973663>
+
+            Reviewed by Saam Barati.
+
+            CodeBlock::jettison() calls CommonData::invalidate, which replaces the `hlt`
+            instruction with the jump to OSR exit. However, if the `hlt` was immediately
+            followed by a call to the CodeBlock being jettisoned, we would write over the
+            OSR exit address while unlinking all the incoming CallLinkInfos later in
+            CodeBlock::jettison().
+
+            Change it so that we set a flag, `clearedByJettison`, in all the CallLinkInfos
+            owned by the CodeBlock being jettisoned. If the flag is set, we will avoid
+            repatching the call during unlinking. This is safe because this call will never
+            be reachable again after the CodeBlock is jettisoned.
+
+            * bytecode/CallLinkInfo.cpp:
+            (JSC::CallLinkInfo::CallLinkInfo):
+            (JSC::CallLinkInfo::setCallee):
+            (JSC::CallLinkInfo::clearCallee):
+            (JSC::CallLinkInfo::setCodeBlock):
+            (JSC::CallLinkInfo::clearCodeBlock):
+            * bytecode/CallLinkInfo.h:
+            (JSC::CallLinkInfo::clearedByJettison):
+            (JSC::CallLinkInfo::setClearedByJettison):
+            * bytecode/CodeBlock.cpp:
+            (JSC::CodeBlock::jettison):
+            * jit/Repatch.cpp:
+            (JSC::revertCall):
+
+2019-06-24  Kocsen Chung  <[email protected]>
+
         Cherry-pick r246507. rdar://problem/51927645
 
     Concurrent GC should check the conn before starting a new collection cycle

Modified: branches/safari-607-branch/Source/_javascript_Core/bytecode/CallLinkInfo.cpp (246746 => 246747)


--- branches/safari-607-branch/Source/_javascript_Core/bytecode/CallLinkInfo.cpp	2019-06-24 18:52:43 UTC (rev 246746)
+++ branches/safari-607-branch/Source/_javascript_Core/bytecode/CallLinkInfo.cpp	2019-06-24 18:52:46 UTC (rev 246747)
@@ -61,7 +61,7 @@
     , m_clearedByGC(false)
     , m_clearedByVirtual(false)
     , m_allowStubs(true)
-    , m_isLinked(false)
+    , m_clearedByJettison(false)
     , m_callType(None)
     , m_calleeGPR(255)
     , m_maxNumArguments(0)
@@ -127,7 +127,6 @@
     RELEASE_ASSERT(!isDirect());
     MacroAssembler::repatchPointer(hotPathBegin(), callee);
     m_calleeOrCodeBlock.set(vm, owner, callee);
-    m_isLinked = true;
 }
 
 void CallLinkInfo::clearCallee()
@@ -135,7 +134,6 @@
     RELEASE_ASSERT(!isDirect());
     MacroAssembler::repatchPointer(hotPathBegin(), nullptr);
     m_calleeOrCodeBlock.clear();
-    m_isLinked = false;
 }
 
 JSObject* CallLinkInfo::callee()
@@ -148,7 +146,6 @@
 {
     RELEASE_ASSERT(isDirect());
     m_calleeOrCodeBlock.setMayBeNull(vm, owner, codeBlock);
-    m_isLinked = true;
 }
 
 void CallLinkInfo::clearCodeBlock()
@@ -155,7 +152,6 @@
 {
     RELEASE_ASSERT(isDirect());
     m_calleeOrCodeBlock.clear();
-    m_isLinked = false;
 }
 
 FunctionCodeBlock* CallLinkInfo::codeBlock()

Modified: branches/safari-607-branch/Source/_javascript_Core/bytecode/CallLinkInfo.h (246746 => 246747)


--- branches/safari-607-branch/Source/_javascript_Core/bytecode/CallLinkInfo.h	2019-06-24 18:52:43 UTC (rev 246746)
+++ branches/safari-607-branch/Source/_javascript_Core/bytecode/CallLinkInfo.h	2019-06-24 18:52:46 UTC (rev 246747)
@@ -270,10 +270,20 @@
         return m_clearedByVirtual;
     }
 
+    bool clearedByJettison()
+    {
+        return m_clearedByJettison;
+    }
+
     void setClearedByVirtual()
     {
         m_clearedByVirtual = true;
     }
+
+    void setClearedByJettison()
+    {
+        m_clearedByJettison = true;
+    }
     
     void setCallType(CallType callType)
     {
@@ -350,7 +360,7 @@
     bool m_clearedByGC : 1;
     bool m_clearedByVirtual : 1;
     bool m_allowStubs : 1;
-    bool m_isLinked : 1;
+    bool m_clearedByJettison : 1;
     unsigned m_callType : 4; // CallType
     unsigned m_calleeGPR : 8;
     uint32_t m_maxNumArguments; // For varargs: the profiled maximum number of arguments. For direct: the number of stack slots allocated for arguments.

Modified: branches/safari-607-branch/Source/_javascript_Core/bytecode/CodeBlock.cpp (246746 => 246747)


--- branches/safari-607-branch/Source/_javascript_Core/bytecode/CodeBlock.cpp	2019-06-24 18:52:43 UTC (rev 246746)
+++ branches/safari-607-branch/Source/_javascript_Core/bytecode/CodeBlock.cpp	2019-06-24 18:52:46 UTC (rev 246747)
@@ -1976,6 +1976,16 @@
     if (vm.heap.isCurrentThreadBusy() && !Heap::isMarked(ownerScriptExecutable()))
         return;
 
+#if ENABLE(JIT)
+    {
+        ConcurrentJSLocker locker(m_lock);
+        if (JITData* jitData = m_jitData.get()) {
+            for (CallLinkInfo* callLinkInfo : jitData->m_callLinkInfos)
+                callLinkInfo->setClearedByJettison();
+        }
+    }
+#endif
+
     // This accomplishes (2).
     ownerScriptExecutable()->installCode(vm, alternative(), codeType(), specializationKind());
 

Modified: branches/safari-607-branch/Source/_javascript_Core/jit/Repatch.cpp (246746 => 246747)


--- branches/safari-607-branch/Source/_javascript_Core/jit/Repatch.cpp	2019-06-24 18:52:43 UTC (rev 246746)
+++ branches/safari-607-branch/Source/_javascript_Core/jit/Repatch.cpp	2019-06-24 18:52:46 UTC (rev 246747)
@@ -895,18 +895,20 @@
 
 static void revertCall(VM* vm, CallLinkInfo& callLinkInfo, MacroAssemblerCodeRef<JITStubRoutinePtrTag> codeRef)
 {
-    if (callLinkInfo.isDirect()) {
-        callLinkInfo.clearCodeBlock();
-        if (callLinkInfo.callType() == CallLinkInfo::DirectTailCall)
-            MacroAssembler::repatchJump(callLinkInfo.patchableJump(), callLinkInfo.slowPathStart());
-        else
-            MacroAssembler::repatchNearCall(callLinkInfo.hotPathOther(), callLinkInfo.slowPathStart());
-    } else {
-        MacroAssembler::revertJumpReplacementToBranchPtrWithPatch(
-            MacroAssembler::startOfBranchPtrWithPatchOnRegister(callLinkInfo.hotPathBegin()),
-            static_cast<MacroAssembler::RegisterID>(callLinkInfo.calleeGPR()), 0);
-        linkSlowFor(vm, callLinkInfo, codeRef);
-        callLinkInfo.clearCallee();
+    if (!callLinkInfo.clearedByJettison()) {
+        if (callLinkInfo.isDirect()) {
+            callLinkInfo.clearCodeBlock();
+            if (callLinkInfo.callType() == CallLinkInfo::DirectTailCall)
+                MacroAssembler::repatchJump(callLinkInfo.patchableJump(), callLinkInfo.slowPathStart());
+            else
+                MacroAssembler::repatchNearCall(callLinkInfo.hotPathOther(), callLinkInfo.slowPathStart());
+        } else {
+            MacroAssembler::revertJumpReplacementToBranchPtrWithPatch(
+                MacroAssembler::startOfBranchPtrWithPatchOnRegister(callLinkInfo.hotPathBegin()),
+                static_cast<MacroAssembler::RegisterID>(callLinkInfo.calleeGPR()), 0);
+            linkSlowFor(vm, callLinkInfo, codeRef);
+            callLinkInfo.clearCallee();
+        }
     }
     callLinkInfo.clearSeen();
     callLinkInfo.clearStub();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to