⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 284576 in webkit


Ignore:
Timestamp:
Oct 20, 2021, 3:08:45 PM (5 years ago)
Author:
Justin Michaud
Message:

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.

Location:
trunk/Source/JavaScriptCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r284573 r284576  
     12021-10-20  Justin Michaud  <justin_michaud@apple.com>
     2
     3        We should watch isHavingABadTime if we read from the structureCache
     4        https://bugs.webkit.org/show_bug.cgi?id=232019
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        We should lock the structure cache when we clear it, and the compiler thread should
     9        watch isHavingABadTime in the case that the cache might get cleared.
     10
     11        * dfg/DFGAbstractInterpreterInlines.h:
     12        (JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects):
     13        * dfg/DFGConstantFoldingPhase.cpp:
     14        (JSC::DFG::ConstantFoldingPhase::foldConstants):
     15        * runtime/JSGlobalObject.cpp:
     16        (JSC::JSGlobalObject::haveABadTime):
     17        * runtime/StructureCache.cpp:
     18        (JSC::StructureCache::clear):
     19        * runtime/StructureCache.h:
     20        (JSC::StructureCache::clear): Deleted.
     21
    1222021-10-20  Michael Saboff  <msaboff@apple.com>
    223
  • trunk/Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h

    r284330 r284576  
    31273127            if (base.isNull())
    31283128                structure = globalObject->nullPrototypeObjectStructure();
    3129             else if (base.isObject())
    3130                 structure = m_vm.structureCache.emptyObjectStructureConcurrently(globalObject, base.getObject(), JSFinalObject::defaultInlineCapacity());
     3129            else if (base.isObject()) {
     3130                // Having a bad time clears the structureCache, and so it should invalidate this structure.
     3131                bool isHavingABadTime = globalObject->isHavingABadTime();
     3132                WTF::loadLoadFence();
     3133                if (!isHavingABadTime)
     3134                    m_graph.watchpoints().addLazily(globalObject->havingABadTimeWatchpoint());
     3135                // Normally, we would always install a watchpoint. In this case, however, if we haveABadTime, we
     3136                // still want to optimize. There is no watchpoint for that case though, so we need to make sure this load
     3137                // does not get hoisted above the check.
     3138                WTF::loadLoadFence();
     3139                structure = m_vm.structureCache
     3140                    .emptyObjectStructureConcurrently(globalObject, base.getObject(), JSFinalObject::defaultInlineCapacity());
     3141            }
    31313142           
    31323143            if (structure) {
  • trunk/Source/JavaScriptCore/dfg/DFGConstantFoldingPhase.cpp

    r284330 r284576  
    842842                    if (base.isNull())
    843843                        structure = globalObject->nullPrototypeObjectStructure();
    844                     else if (base.isObject())
    845                         structure = globalObject->vm().structureCache.emptyObjectStructureConcurrently(globalObject, base.getObject(), JSFinalObject::defaultInlineCapacity());
     844                    else if (base.isObject()) {
     845                        // Having a bad time clears the structureCache, and so it should invalidate this structure.
     846                        bool isHavingABadTime = globalObject->isHavingABadTime();
     847                        WTF::loadLoadFence();
     848                        if (!isHavingABadTime)
     849                            m_graph.watchpoints().addLazily(globalObject->havingABadTimeWatchpoint());
     850                        // Normally, we would always install a watchpoint. In this case, however, if we haveABadTime, we
     851                        // still want to optimize. There is no watchpoint for that case though, so we need to make sure this load
     852                        // does not get hoisted above the check.
     853                        WTF::loadLoadFence();
     854                        structure = globalObject->vm().structureCache
     855                            .emptyObjectStructureConcurrently(globalObject, base.getObject(), JSFinalObject::defaultInlineCapacity());
     856                    }
    846857                   
    847858                    if (structure) {
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp

    r284435 r284576  
    19851985        return;
    19861986
     1987    // This must happen first, because the compiler thread may race with haveABadTime.
     1988    // Let R_BT, W_BT <- Read/Fire the watchpoint, R_SC, W_SC <- Read/clear the structure cache.
     1989    // The possible interleavings are:
     1990    // R_BT, R_SC, W_SC, W_BT: Compiler thread installs a watchpoint, and the code is discarded.
     1991    // R_BT, W_SC, R_SC, W_BT: ^ Same
     1992    // R_BT, W_SC, W_BT, W_SC: ^ Same
     1993    // W_SC, R_BT, R_SC, W_BT: ^ Same
     1994    // W_SC, R_BT, W_BT, R_SC: ^ Same
     1995    // W_SC, W_BT, R_BT, R_SC: No watchpoint is installed, but we could not see old structures from the cache.
    19871996    vm.structureCache.clear(); // We may be caching array structures in here.
    19881997
  • trunk/Source/JavaScriptCore/runtime/StructureCache.cpp

    r277909 r284576  
    3131
    3232namespace JSC {
     33
     34void StructureCache::clear()
     35{
     36    Locker locker { m_lock };
     37    m_structures.clear();
     38}
    3339
    3440inline Structure* StructureCache::createEmptyStructure(JSGlobalObject* globalObject, JSObject* prototype, const TypeInfo& typeInfo, const ClassInfo* classInfo, IndexingType indexingType, unsigned inlineCapacity, bool makePolyProtoStructure, FunctionExecutable* executable)
  • trunk/Source/JavaScriptCore/runtime/StructureCache.h

    r244313 r284576  
    4949    }
    5050
    51     void clear() { m_structures.clear(); }
     51    JS_EXPORT_PRIVATE void clear();
    5252
    5353    JS_EXPORT_PRIVATE Structure* emptyObjectStructureForPrototype(JSGlobalObject*, JSObject*, unsigned inlineCapacity, bool makePolyProtoStructure = false, FunctionExecutable* = nullptr);
Note: See TracChangeset for help on using the changeset viewer.