Title: [284808] branches/safari-612-branch/Source/_javascript_Core
Revision
284808
Author
[email protected]
Date
2021-10-25 12:10:00 -0700 (Mon, 25 Oct 2021)

Log Message

Cherry-pick r284576. rdar://problem/84338462

    We should watch isHavingABadTime if we read from the structureCache
    https://bugs.webkit.org/show_bug.cgi?id=232019

    Reviewed by Yusuke Suzuki.

    We should lock the structure cache when we clear it, and the compiler thread should
    watch isHavingABadTime in the case that the cache might get cleared.

    * dfg/DFGAbstractInterpreterInlines.h:
    (JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects):
    * dfg/DFGConstantFoldingPhase.cpp:
    (JSC::DFG::ConstantFoldingPhase::foldConstants):
    * runtime/JSGlobalObject.cpp:
    (JSC::JSGlobalObject::haveABadTime):
    * runtime/StructureCache.cpp:
    (JSC::StructureCache::clear):
    * runtime/StructureCache.h:
    (JSC::StructureCache::clear): Deleted.

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

Modified Paths

Diff

Modified: branches/safari-612-branch/Source/_javascript_Core/ChangeLog (284807 => 284808)


--- branches/safari-612-branch/Source/_javascript_Core/ChangeLog	2021-10-25 19:09:56 UTC (rev 284807)
+++ branches/safari-612-branch/Source/_javascript_Core/ChangeLog	2021-10-25 19:10:00 UTC (rev 284808)
@@ -1,5 +1,52 @@
 2021-10-25  Null  <[email protected]>
 
+        Cherry-pick r284576. rdar://problem/84338462
+
+    We should watch isHavingABadTime if we read from the structureCache
+    https://bugs.webkit.org/show_bug.cgi?id=232019
+    
+    Reviewed by Yusuke Suzuki.
+    
+    We should lock the structure cache when we clear it, and the compiler thread should
+    watch isHavingABadTime in the case that the cache might get cleared.
+    
+    * dfg/DFGAbstractInterpreterInlines.h:
+    (JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects):
+    * dfg/DFGConstantFoldingPhase.cpp:
+    (JSC::DFG::ConstantFoldingPhase::foldConstants):
+    * runtime/JSGlobalObject.cpp:
+    (JSC::JSGlobalObject::haveABadTime):
+    * runtime/StructureCache.cpp:
+    (JSC::StructureCache::clear):
+    * runtime/StructureCache.h:
+    (JSC::StructureCache::clear): Deleted.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@284576 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-10-20  Justin Michaud  <[email protected]>
+
+            We should watch isHavingABadTime if we read from the structureCache
+            https://bugs.webkit.org/show_bug.cgi?id=232019
+
+            Reviewed by Yusuke Suzuki.
+
+            We should lock the structure cache when we clear it, and the compiler thread should
+            watch isHavingABadTime in the case that the cache might get cleared.
+
+            * dfg/DFGAbstractInterpreterInlines.h:
+            (JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects):
+            * dfg/DFGConstantFoldingPhase.cpp:
+            (JSC::DFG::ConstantFoldingPhase::foldConstants):
+            * runtime/JSGlobalObject.cpp:
+            (JSC::JSGlobalObject::haveABadTime):
+            * runtime/StructureCache.cpp:
+            (JSC::StructureCache::clear):
+            * runtime/StructureCache.h:
+            (JSC::StructureCache::clear): Deleted.
+
+2021-10-25  Null  <[email protected]>
+
         Cherry-pick r284573. rdar://problem/84329018
 
     Add missing overflow checks to DFGIntegerRangeOptimizationPhase::isEquivalentTo()

Modified: branches/safari-612-branch/Source/_javascript_Core/dfg/DFGAbstractInterpreterInlines.h (284807 => 284808)


--- branches/safari-612-branch/Source/_javascript_Core/dfg/DFGAbstractInterpreterInlines.h	2021-10-25 19:09:56 UTC (rev 284807)
+++ branches/safari-612-branch/Source/_javascript_Core/dfg/DFGAbstractInterpreterInlines.h	2021-10-25 19:10:00 UTC (rev 284808)
@@ -3141,8 +3141,19 @@
             Structure* structure = nullptr;
             if (base.isNull())
                 structure = globalObject->nullPrototypeObjectStructure();
-            else if (base.isObject())
-                structure = m_vm.structureCache.emptyObjectStructureConcurrently(globalObject, base.getObject(), JSFinalObject::defaultInlineCapacity());
+            else if (base.isObject()) {
+                // Having a bad time clears the structureCache, and so it should invalidate this structure.
+                bool isHavingABadTime = globalObject->isHavingABadTime();
+                WTF::loadLoadFence();
+                if (!isHavingABadTime)
+                    m_graph.watchpoints().addLazily(globalObject->havingABadTimeWatchpoint());
+                // Normally, we would always install a watchpoint. In this case, however, if we haveABadTime, we
+                // still want to optimize. There is no watchpoint for that case though, so we need to make sure this load
+                // does not get hoisted above the check.
+                WTF::loadLoadFence();
+                structure = m_vm.structureCache
+                    .emptyObjectStructureConcurrently(globalObject, base.getObject(), JSFinalObject::defaultInlineCapacity());
+            }
             
             if (structure) {
                 m_state.setShouldTryConstantFolding(true);

Modified: branches/safari-612-branch/Source/_javascript_Core/dfg/DFGConstantFoldingPhase.cpp (284807 => 284808)


--- branches/safari-612-branch/Source/_javascript_Core/dfg/DFGConstantFoldingPhase.cpp	2021-10-25 19:09:56 UTC (rev 284807)
+++ branches/safari-612-branch/Source/_javascript_Core/dfg/DFGConstantFoldingPhase.cpp	2021-10-25 19:10:00 UTC (rev 284808)
@@ -841,8 +841,19 @@
                     Structure* structure = nullptr;
                     if (base.isNull())
                         structure = globalObject->nullPrototypeObjectStructure();
-                    else if (base.isObject())
-                        structure = globalObject->vm().structureCache.emptyObjectStructureConcurrently(globalObject, base.getObject(), JSFinalObject::defaultInlineCapacity());
+                    else if (base.isObject()) {
+                        // Having a bad time clears the structureCache, and so it should invalidate this structure.
+                        bool isHavingABadTime = globalObject->isHavingABadTime();
+                        WTF::loadLoadFence();
+                        if (!isHavingABadTime)
+                            m_graph.watchpoints().addLazily(globalObject->havingABadTimeWatchpoint());
+                        // Normally, we would always install a watchpoint. In this case, however, if we haveABadTime, we
+                        // still want to optimize. There is no watchpoint for that case though, so we need to make sure this load
+                        // does not get hoisted above the check.
+                        WTF::loadLoadFence();
+                        structure = globalObject->vm().structureCache
+                            .emptyObjectStructureConcurrently(globalObject, base.getObject(), JSFinalObject::defaultInlineCapacity());
+                    }
                     
                     if (structure) {
                         node->convertToNewObject(m_graph.registerStructure(structure));

Modified: branches/safari-612-branch/Source/_javascript_Core/runtime/JSGlobalObject.cpp (284807 => 284808)


--- branches/safari-612-branch/Source/_javascript_Core/runtime/JSGlobalObject.cpp	2021-10-25 19:09:56 UTC (rev 284807)
+++ branches/safari-612-branch/Source/_javascript_Core/runtime/JSGlobalObject.cpp	2021-10-25 19:10:00 UTC (rev 284808)
@@ -1928,6 +1928,15 @@
     if (isHavingABadTime())
         return;
 
+    // This must happen first, because the compiler thread may race with haveABadTime.
+    // Let R_BT, W_BT <- Read/Fire the watchpoint, R_SC, W_SC <- Read/clear the structure cache.
+    // The possible interleavings are:
+    // R_BT, R_SC, W_SC, W_BT: Compiler thread installs a watchpoint, and the code is discarded.
+    // R_BT, W_SC, R_SC, W_BT: ^ Same
+    // R_BT, W_SC, W_BT, W_SC: ^ Same
+    // W_SC, R_BT, R_SC, W_BT: ^ Same
+    // W_SC, R_BT, W_BT, R_SC: ^ Same
+    // W_SC, W_BT, R_BT, R_SC: No watchpoint is installed, but we could not see old structures from the cache.
     vm.structureCache.clear(); // We may be caching array structures in here.
 
     DeferGC deferGC(vm.heap);

Modified: branches/safari-612-branch/Source/_javascript_Core/runtime/StructureCache.cpp (284807 => 284808)


--- branches/safari-612-branch/Source/_javascript_Core/runtime/StructureCache.cpp	2021-10-25 19:09:56 UTC (rev 284807)
+++ branches/safari-612-branch/Source/_javascript_Core/runtime/StructureCache.cpp	2021-10-25 19:10:00 UTC (rev 284808)
@@ -31,6 +31,12 @@
 
 namespace JSC {
 
+void StructureCache::clear()
+{
+    Locker locker { m_lock };
+    m_structures.clear();
+}
+
 inline Structure* StructureCache::createEmptyStructure(JSGlobalObject* globalObject, JSObject* prototype, const TypeInfo& typeInfo, const ClassInfo* classInfo, IndexingType indexingType, unsigned inlineCapacity, bool makePolyProtoStructure, FunctionExecutable* executable)
 {
     RELEASE_ASSERT(!!prototype); // We use nullptr inside the HashMap for prototype to mean poly proto, so user's of this API must provide non-null prototypes.

Modified: branches/safari-612-branch/Source/_javascript_Core/runtime/StructureCache.h (284807 => 284808)


--- branches/safari-612-branch/Source/_javascript_Core/runtime/StructureCache.h	2021-10-25 19:09:56 UTC (rev 284807)
+++ branches/safari-612-branch/Source/_javascript_Core/runtime/StructureCache.h	2021-10-25 19:10:00 UTC (rev 284808)
@@ -48,7 +48,7 @@
     {
     }
 
-    void clear() { m_structures.clear(); }
+    JS_EXPORT_PRIVATE void clear();
 
     JS_EXPORT_PRIVATE Structure* emptyObjectStructureForPrototype(JSGlobalObject*, JSObject*, unsigned inlineCapacity, bool makePolyProtoStructure = false, FunctionExecutable* = nullptr);
     JS_EXPORT_PRIVATE Structure* emptyStructureForPrototypeFromBaseStructure(JSGlobalObject*, JSObject*, Structure*);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to