Changeset 190546 in webkit


Ignore:
Timestamp:
Oct 3, 2015 6:45:21 PM (9 years ago)
Author:
commit-queue@webkit.org
Message:

Unreviewed, rolling out r190522.
https://bugs.webkit.org/show_bug.cgi?id=149787

Caused a lot of leaks (Requested by ap on #webkit).

Reverted changeset:

"Unreviewed, rolling back in r190450"
https://bugs.webkit.org/show_bug.cgi?id=149727
http://trac.webkit.org/changeset/190522

Location:
trunk/Source/JavaScriptCore
Files:
56 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r190542 r190546  
     12015-10-03  Commit Queue  <commit-queue@webkit.org>
     2
     3        Unreviewed, rolling out r190522.
     4        https://bugs.webkit.org/show_bug.cgi?id=149787
     5
     6        Caused a lot of leaks (Requested by ap on #webkit).
     7
     8        Reverted changeset:
     9
     10        "Unreviewed, rolling back in r190450"
     11        https://bugs.webkit.org/show_bug.cgi?id=149727
     12        http://trac.webkit.org/changeset/190522
     13
    1142015-10-02  Matt Baker  <mattbaker@apple.com>
    215
  • trunk/Source/JavaScriptCore/bytecode/CodeBlock.cpp

    r190522 r190546  
    8383namespace JSC {
    8484
    85 const ClassInfo CodeBlock::s_info = {
    86     "CodeBlock", 0, 0,
    87     CREATE_METHOD_TABLE(CodeBlock)
    88 };
    89 
    90 const ClassInfo FunctionCodeBlock::s_info = {
    91     "FunctionCodeBlock", &Base::s_info, 0,
    92     CREATE_METHOD_TABLE(FunctionCodeBlock)
    93 };
    94 
    95 #if ENABLE(WEBASSEMBLY)
    96 const ClassInfo WebAssemblyCodeBlock::s_info = {
    97     "WebAssemblyCodeBlock", &Base::s_info, 0,
    98     CREATE_METHOD_TABLE(WebAssemblyCodeBlock)
    99 };
    100 #endif
    101 
    102 const ClassInfo GlobalCodeBlock::s_info = {
    103     "GlobalCodeBlock", &Base::s_info, 0,
    104     CREATE_METHOD_TABLE(GlobalCodeBlock)
    105 };
    106 
    107 const ClassInfo ProgramCodeBlock::s_info = {
    108     "ProgramCodeBlock", &Base::s_info, 0,
    109     CREATE_METHOD_TABLE(ProgramCodeBlock)
    110 };
    111 
    112 const ClassInfo ModuleProgramCodeBlock::s_info = {
    113     "ModuleProgramCodeBlock", &Base::s_info, 0,
    114     CREATE_METHOD_TABLE(ModuleProgramCodeBlock)
    115 };
    116 
    117 const ClassInfo EvalCodeBlock::s_info = {
    118     "EvalCodeBlock", &Base::s_info, 0,
    119     CREATE_METHOD_TABLE(EvalCodeBlock)
    120 };
    121 
    122 void FunctionCodeBlock::destroy(JSCell* cell)
    123 {
    124     jsCast<FunctionCodeBlock*>(cell)->~FunctionCodeBlock();
    125 }
    126 
    127 #if ENABLE(WEBASSEMBLY)
    128 void WebAssemblyCodeBlock::destroy(JSCell* cell)
    129 {
    130     jsCast<WebAssemblyCodeBlock*>(cell)->~WebAssemblyCodeBlock();
    131 }
    132 #endif
    133 
    134 void ProgramCodeBlock::destroy(JSCell* cell)
    135 {
    136     jsCast<ProgramCodeBlock*>(cell)->~ProgramCodeBlock();
    137 }
    138 
    139 void ModuleProgramCodeBlock::destroy(JSCell* cell)
    140 {
    141     jsCast<ModuleProgramCodeBlock*>(cell)->~ModuleProgramCodeBlock();
    142 }
    143 
    144 void EvalCodeBlock::destroy(JSCell* cell)
    145 {
    146     jsCast<EvalCodeBlock*>(cell)->~EvalCodeBlock();
    147 }
    148 
    14985CString CodeBlock::inferredName() const
    15086{
     
    218154    out.print(":[", RawPointer(this), "->");
    219155    if (!!m_alternative)
    220         out.print(RawPointer(alternative()), "->");
     156        out.print(RawPointer(m_alternative.get()), "->");
    221157    out.print(RawPointer(ownerExecutable()), ", ", jitType, codeType());
    222158
     
    16501586} // anonymous namespace
    16511587
    1652 CodeBlock::CodeBlock(VM* vm, Structure* structure, CopyParsedBlockTag, CodeBlock& other)
    1653     : JSCell(*vm, structure)
    1654     , m_globalObject(other.m_globalObject)
     1588CodeBlock::CodeBlock(CopyParsedBlockTag, CodeBlock& other)
     1589    : m_globalObject(other.m_globalObject)
    16551590    , m_heap(other.m_heap)
    16561591    , m_numCalleeRegisters(other.m_numCalleeRegisters)
     
    16601595    , m_didFailFTLCompilation(false)
    16611596    , m_hasBeenCompiledWithFTL(false)
    1662     , m_unlinkedCode(*other.m_vm, this, other.m_unlinkedCode.get())
     1597    , m_unlinkedCode(*other.m_vm, other.m_ownerExecutable.get(), other.m_unlinkedCode.get())
    16631598    , m_hasDebuggerStatement(false)
    16641599    , m_steppingMode(SteppingModeDisabled)
    16651600    , m_numBreakpoints(0)
    1666     , m_ownerExecutable(*other.m_vm, this, other.m_ownerExecutable.get())
     1601    , m_ownerExecutable(*other.m_vm, other.m_ownerExecutable.get(), other.m_ownerExecutable.get())
    16671602    , m_vm(other.m_vm)
    16681603    , m_instructions(other.m_instructions)
     
    16891624#endif
    16901625{
    1691     m_visitWeaklyHasBeenCalled.store(false, std::memory_order_relaxed);
     1626    m_visitStronglyHasBeenCalled.store(false, std::memory_order_relaxed);
     1627    m_visitAggregateHasBeenCalled.store(false, std::memory_order_relaxed);
    16921628
    16931629    ASSERT(m_heap->isDeferred());
     
    16951631
    16961632    setNumParameters(other.numParameters());
    1697 }
    1698 
    1699 void CodeBlock::finishCreation(VM& vm, CopyParsedBlockTag, CodeBlock& other)
    1700 {
    1701     Base::finishCreation(vm);
    1702 
    17031633    optimizeAfterWarmUp();
    17041634    jitAfterWarmUp();
     
    17141644   
    17151645    m_heap->m_codeBlocks.add(this);
    1716 }
    1717 
    1718 CodeBlock::CodeBlock(VM* vm, Structure* structure, ScriptExecutable* ownerExecutable, UnlinkedCodeBlock* unlinkedCodeBlock,
    1719     JSScope* scope, PassRefPtr<SourceProvider> sourceProvider, unsigned sourceOffset, unsigned firstLineColumnOffset)
    1720     : JSCell(*vm, structure)
    1721     , m_globalObject(scope->globalObject()->vm(), this, scope->globalObject())
     1646    m_heap->reportExtraMemoryAllocated(sizeof(CodeBlock));
     1647}
     1648
     1649CodeBlock::CodeBlock(ScriptExecutable* ownerExecutable, UnlinkedCodeBlock* unlinkedCodeBlock, JSScope* scope, PassRefPtr<SourceProvider> sourceProvider, unsigned sourceOffset, unsigned firstLineColumnOffset)
     1650    : m_globalObject(scope->globalObject()->vm(), ownerExecutable, scope->globalObject())
    17221651    , m_heap(&m_globalObject->vm().heap)
    17231652    , m_numCalleeRegisters(unlinkedCodeBlock->m_numCalleeRegisters)
     
    17271656    , m_didFailFTLCompilation(false)
    17281657    , m_hasBeenCompiledWithFTL(false)
    1729     , m_unlinkedCode(m_globalObject->vm(), this, unlinkedCodeBlock)
     1658    , m_unlinkedCode(m_globalObject->vm(), ownerExecutable, unlinkedCodeBlock)
    17301659    , m_hasDebuggerStatement(false)
    17311660    , m_steppingMode(SteppingModeDisabled)
    17321661    , m_numBreakpoints(0)
    1733     , m_ownerExecutable(m_globalObject->vm(), this, ownerExecutable)
     1662    , m_ownerExecutable(m_globalObject->vm(), ownerExecutable, ownerExecutable)
    17341663    , m_vm(unlinkedCodeBlock->vm())
    17351664    , m_thisRegister(unlinkedCodeBlock->thisRegister())
     
    17501679#endif
    17511680{
    1752     m_visitWeaklyHasBeenCalled.store(false, std::memory_order_relaxed);
     1681    m_visitStronglyHasBeenCalled.store(false, std::memory_order_relaxed);
     1682    m_visitAggregateHasBeenCalled.store(false, std::memory_order_relaxed);
    17531683
    17541684    ASSERT(m_heap->isDeferred());
     
    17571687    ASSERT(m_source);
    17581688    setNumParameters(unlinkedCodeBlock->numParameters());
    1759 }
    1760 
    1761 void CodeBlock::finishCreation(VM& vm, ScriptExecutable* ownerExecutable, UnlinkedCodeBlock* unlinkedCodeBlock,
    1762     JSScope* scope)
    1763 {
    1764     Base::finishCreation(vm);
    1765 
    1766     if (vm.typeProfiler() || vm.controlFlowProfiler())
    1767         vm.functionHasExecutedCache()->removeUnexecutedRange(ownerExecutable->sourceID(), ownerExecutable->typeProfilingStartOffset(), ownerExecutable->typeProfilingEndOffset());
     1689
     1690    if (vm()->typeProfiler() || vm()->controlFlowProfiler())
     1691        vm()->functionHasExecutedCache()->removeUnexecutedRange(ownerExecutable->sourceID(), ownerExecutable->typeProfilingStartOffset(), ownerExecutable->typeProfilingEndOffset());
    17681692
    17691693    setConstantRegisters(unlinkedCodeBlock->constantRegisters(), unlinkedCodeBlock->constantsSourceCodeRepresentation());
    17701694    if (unlinkedCodeBlock->usesGlobalObject())
    1771         m_constantRegisters[unlinkedCodeBlock->globalObjectRegister().toConstantIndex()].set(*m_vm, this, m_globalObject.get());
     1695        m_constantRegisters[unlinkedCodeBlock->globalObjectRegister().toConstantIndex()].set(*m_vm, ownerExecutable, m_globalObject.get());
    17721696
    17731697    for (unsigned i = 0; i < LinkTimeConstantCount; i++) {
    17741698        LinkTimeConstant type = static_cast<LinkTimeConstant>(i);
    17751699        if (unsigned registerIndex = unlinkedCodeBlock->registerIndexForLinkTimeConstant(type))
    1776             m_constantRegisters[registerIndex].set(*m_vm, this, m_globalObject->jsCellForLinkTimeConstant(type));
     1700            m_constantRegisters[registerIndex].set(*m_vm, ownerExecutable, m_globalObject->jsCellForLinkTimeConstant(type));
    17771701    }
    17781702
     
    17891713                    symbolTable->prepareForTypeProfiling(locker);
    17901714                }
    1791                 m_constantRegisters[i].set(*m_vm, this, symbolTable->cloneScopePart(*m_vm));
     1715                m_constantRegisters[i].set(*m_vm, ownerExecutable, symbolTable->cloneScopePart(*m_vm));
    17921716                clonedConstantSymbolTables.add(i + FirstConstantRegisterIndex);
    17931717            }
     
    18091733    for (size_t count = unlinkedCodeBlock->numberOfFunctionDecls(), i = 0; i < count; ++i) {
    18101734        UnlinkedFunctionExecutable* unlinkedExecutable = unlinkedCodeBlock->functionDecl(i);
    1811         if (vm.typeProfiler() || vm.controlFlowProfiler())
    1812             vm.functionHasExecutedCache()->insertUnexecutedRange(ownerExecutable->sourceID(), unlinkedExecutable->typeProfilingStartOffset(), unlinkedExecutable->typeProfilingEndOffset());
    1813         m_functionDecls[i].set(*m_vm, this, unlinkedExecutable->link(*m_vm, ownerExecutable->source()));
     1735        if (vm()->typeProfiler() || vm()->controlFlowProfiler())
     1736            vm()->functionHasExecutedCache()->insertUnexecutedRange(ownerExecutable->sourceID(), unlinkedExecutable->typeProfilingStartOffset(), unlinkedExecutable->typeProfilingEndOffset());
     1737        m_functionDecls[i].set(*m_vm, ownerExecutable, unlinkedExecutable->link(*m_vm, ownerExecutable->source()));
    18141738    }
    18151739
     
    18171741    for (size_t count = unlinkedCodeBlock->numberOfFunctionExprs(), i = 0; i < count; ++i) {
    18181742        UnlinkedFunctionExecutable* unlinkedExecutable = unlinkedCodeBlock->functionExpr(i);
    1819         if (vm.typeProfiler() || vm.controlFlowProfiler())
    1820             vm.functionHasExecutedCache()->insertUnexecutedRange(ownerExecutable->sourceID(), unlinkedExecutable->typeProfilingStartOffset(), unlinkedExecutable->typeProfilingEndOffset());
    1821         m_functionExprs[i].set(*m_vm, this, unlinkedExecutable->link(*m_vm, ownerExecutable->source()));
     1743        if (vm()->typeProfiler() || vm()->controlFlowProfiler())
     1744            vm()->functionHasExecutedCache()->insertUnexecutedRange(ownerExecutable->sourceID(), unlinkedExecutable->typeProfilingStartOffset(), unlinkedExecutable->typeProfilingEndOffset());
     1745        m_functionExprs[i].set(*m_vm, ownerExecutable, unlinkedExecutable->link(*m_vm, ownerExecutable->source()));
    18221746    }
    18231747
     
    18981822        unsigned opLength = opcodeLength(pc[0].u.opcode);
    18991823
    1900         instructions[i] = vm.interpreter->getOpcode(pc[0].u.opcode);
     1824        instructions[i] = vm()->interpreter->getOpcode(pc[0].u.opcode);
    19011825        for (size_t j = 1; j < opLength; ++j) {
    19021826            if (sizeof(int32_t) != sizeof(intptr_t))
     
    19571881
    19581882            instructions[i + opLength - 1] = objectAllocationProfile;
    1959             objectAllocationProfile->initialize(vm,
     1883            objectAllocationProfile->initialize(*vm(),
    19601884                ownerExecutable, m_globalObject->objectPrototype(), inferredInlineCapacity);
    19611885            break;
     
    20061930                    if (stronglyReferencedModuleEnvironments.add(jsCast<JSModuleEnvironment*>(op.lexicalEnvironment)).isNewEntry)
    20071931                        addConstant(op.lexicalEnvironment);
    2008                     instructions[i + 6].u.jsCell.set(vm, this, op.lexicalEnvironment);
     1932                    instructions[i + 6].u.jsCell.set(*vm(), ownerExecutable, op.lexicalEnvironment);
    20091933                } else
    2010                     instructions[i + 6].u.symbolTable.set(vm, this, op.lexicalEnvironment->symbolTable());
     1934                    instructions[i + 6].u.symbolTable.set(*vm(), ownerExecutable, op.lexicalEnvironment->symbolTable());
    20111935            } else if (JSScope* constantScope = JSScope::constantScopeForCodeBlock(op.type, this))
    2012                 instructions[i + 6].u.jsCell.set(vm, this, constantScope);
     1936                instructions[i + 6].u.jsCell.set(*vm(), ownerExecutable, constantScope);
    20131937            else
    20141938                instructions[i + 6].u.pointer = nullptr;
     
    20431967                instructions[i + 5].u.watchpointSet = op.watchpointSet;
    20441968            else if (op.structure)
    2045                 instructions[i + 5].u.structure.set(vm, this, op.structure);
     1969                instructions[i + 5].u.structure.set(*vm(), ownerExecutable, op.structure);
    20461970            instructions[i + 6].u.pointer = reinterpret_cast<void*>(op.operand);
    20471971            break;
     
    20802004                    op.watchpointSet->invalidate(PutToScopeFireDetail(this, ident));
    20812005            } else if (op.structure)
    2082                 instructions[i + 5].u.structure.set(vm, this, op.structure);
     2006                instructions[i + 5].u.structure.set(*vm(), ownerExecutable, op.structure);
    20832007            instructions[i + 6].u.pointer = reinterpret_cast<void*>(op.operand);
    20842008
     
    20872011
    20882012        case op_profile_type: {
    2089             RELEASE_ASSERT(vm.typeProfiler());
     2013            RELEASE_ASSERT(vm()->typeProfiler());
    20902014            // The format of this instruction is: op_profile_type regToProfile, TypeLocation*, flag, identifier?, resolveType?
    20912015            size_t instructionOffset = i + opLength - 1;
     
    21172041                    // If our parent scope was created while profiling was disabled, it will not have prepared for profiling yet.
    21182042                    symbolTable->prepareForTypeProfiling(locker);
    2119                     globalVariableID = symbolTable->uniqueIDForVariable(locker, impl, vm);
    2120                     globalTypeSet = symbolTable->globalTypeSetForVariable(locker, impl, vm);
     2043                    globalVariableID = symbolTable->uniqueIDForVariable(locker, impl, *vm());
     2044                    globalTypeSet = symbolTable->globalTypeSetForVariable(locker, impl, *vm());
    21212045                } else
    21222046                    globalVariableID = TypeProfilerNoGlobalIDExists;
     
    21312055                ConcurrentJITLocker locker(symbolTable->m_lock);
    21322056                // If our parent scope was created while profiling was disabled, it will not have prepared for profiling yet.
    2133                 globalVariableID = symbolTable->uniqueIDForVariable(locker, ident.impl(), vm);
    2134                 globalTypeSet = symbolTable->globalTypeSetForVariable(locker, ident.impl(), vm);
     2057                globalVariableID = symbolTable->uniqueIDForVariable(locker, ident.impl(), *vm());
     2058                globalTypeSet = symbolTable->globalTypeSetForVariable(locker, ident.impl(), *vm());
    21352059
    21362060                break;
     
    21582082            }
    21592083
    2160             std::pair<TypeLocation*, bool> locationPair = vm.typeProfiler()->typeLocationCache()->getTypeLocation(globalVariableID,
    2161                 ownerExecutable->sourceID(), divotStart, divotEnd, globalTypeSet, &vm);
     2084            std::pair<TypeLocation*, bool> locationPair = vm()->typeProfiler()->typeLocationCache()->getTypeLocation(globalVariableID,
     2085                ownerExecutable->sourceID(), divotStart, divotEnd, globalTypeSet, vm());
    21622086            TypeLocation* location = locationPair.first;
    21632087            bool isNewLocation = locationPair.second;
     
    21672091
    21682092            if (shouldAnalyze && isNewLocation)
    2169                 vm.typeProfiler()->insertNewLocation(location);
     2093                vm()->typeProfiler()->insertNewLocation(location);
    21702094
    21712095            instructions[i + 2].u.location = location;
     
    21852109    }
    21862110
    2187     if (vm.controlFlowProfiler())
     2111    if (vm()->controlFlowProfiler())
    21882112        insertBasicBlockBoundariesForControlFlowProfiler(instructions);
    21892113
     
    22052129   
    22062130    m_heap->m_codeBlocks.add(this);
    2207     m_heap->reportExtraMemoryAllocated(m_instructions.size() * sizeof(Instruction));
     2131    m_heap->reportExtraMemoryAllocated(sizeof(CodeBlock) + m_instructions.size() * sizeof(Instruction));
    22082132}
    22092133
    22102134#if ENABLE(WEBASSEMBLY)
    2211 CodeBlock::CodeBlock(VM* vm, Structure* structure, WebAssemblyExecutable* ownerExecutable, VM& vm, JSGlobalObject* globalObject)
    2212     : JSCell(vm, structure)
    2213     , m_globalObject(globalObject->vm(), this, globalObject)
     2135CodeBlock::CodeBlock(WebAssemblyExecutable* ownerExecutable, VM& vm, JSGlobalObject* globalObject)
     2136    : m_globalObject(globalObject->vm(), ownerExecutable, globalObject)
    22142137    , m_heap(&m_globalObject->vm().heap)
    22152138    , m_numCalleeRegisters(0)
     
    22222145    , m_steppingMode(SteppingModeDisabled)
    22232146    , m_numBreakpoints(0)
    2224     , m_ownerExecutable(m_globalObject->vm(), this, ownerExecutable)
     2147    , m_ownerExecutable(m_globalObject->vm(), ownerExecutable, ownerExecutable)
    22252148    , m_vm(&vm)
    22262149    , m_isStrictMode(false)
     
    22362159{
    22372160    ASSERT(m_heap->isDeferred());
    2238 }
    2239 
    2240 void CodeBlock::finishCreation(VM& vm, WebAssemblyExecutable*, JSGlobalObject*)
    2241 {
    2242     Base::finishCreation(vm);
    22432161
    22442162    m_heap->m_codeBlocks.add(this);
     2163    m_heap->reportExtraMemoryAllocated(sizeof(CodeBlock));
    22452164}
    22462165#endif
     
    22542173    dumpValueProfiles();
    22552174#endif
    2256 
     2175    while (m_incomingLLIntCalls.begin() != m_incomingLLIntCalls.end())
     2176        m_incomingLLIntCalls.begin()->remove();
     2177#if ENABLE(JIT)
    22572178    // We may be destroyed before any CodeBlocks that refer to us are destroyed.
    22582179    // Consider that two CodeBlocks become unreachable at the same time. There
     
    22612182    // CodeBlock(s) that have calls into us, then the CallLinkInfo vector's
    22622183    // destructor will try to remove nodes from our (no longer valid) linked list.
    2263     unlinkIncomingCalls();
     2184    while (m_incomingCalls.begin() != m_incomingCalls.end())
     2185        m_incomingCalls.begin()->remove();
     2186    while (m_incomingPolymorphicCalls.begin() != m_incomingPolymorphicCalls.end())
     2187        m_incomingPolymorphicCalls.begin()->remove();
    22642188   
    22652189    // Note that our outgoing calls will be removed from other CodeBlocks'
     
    22672191    // destructors.
    22682192
    2269 #if ENABLE(JIT)
    22702193    for (Bag<StructureStubInfo>::iterator iter = m_stubInfos.begin(); !!iter; ++iter)
    22712194        (*iter)->deref();
    22722195#endif // ENABLE(JIT)
    2273 }
    2274 
    2275 void CodeBlock::setAlternative(VM& vm, CodeBlock* alternative)
    2276 {
    2277     m_alternative.set(vm, this, alternative);
    22782196}
    22792197
     
    22982216        return 0;
    22992217    DFG::JITCode* jitCode = m_jitCode->dfg();
    2300     return jitCode->osrEntryBlock();
     2218    return jitCode->osrEntryBlock.get();
    23012219#else // ENABLE(FTL_JIT)
    23022220    return 0;
     
    23042222}
    23052223
    2306 void CodeBlock::visitWeakly(SlotVisitor& visitor)
    2307 {
    2308     bool setByMe = m_visitWeaklyHasBeenCalled.compareExchangeStrong(false, true);
     2224void CodeBlock::visitStrongly(SlotVisitor& visitor)
     2225{
     2226    bool setByMe = m_visitStronglyHasBeenCalled.compareExchangeStrong(false, true);
    23092227    if (!setByMe)
    23102228        return;
    23112229
    2312     if (Heap::isMarked(this))
     2230    visitAggregate(visitor);
     2231
     2232    stronglyVisitStrongReferences(visitor);
     2233    stronglyVisitWeakReferences(visitor);
     2234    propagateTransitions(visitor);
     2235}
     2236
     2237void CodeBlock::visitAggregate(SlotVisitor& visitor)
     2238{
     2239    // I may be asked to scan myself more than once, and it may even happen concurrently.
     2240    // To this end, use an atomic operation to check (and set) if I've been called already.
     2241    // Only one thread may proceed past this point - whichever one wins the atomic set race.
     2242    bool setByMe = m_visitAggregateHasBeenCalled.compareExchangeStrong(false, true);
     2243    if (!setByMe)
    23132244        return;
    2314 
    2315     if (shouldVisitStrongly()) {
    2316         visitor.appendUnbarrieredReadOnlyPointer(this);
    2317         return;
    2318     }
     2245   
     2246    if (!!m_alternative)
     2247        m_alternative->visitAggregate(visitor);
     2248   
     2249    if (CodeBlock* otherBlock = specialOSREntryBlockOrNull())
     2250        otherBlock->visitAggregate(visitor);
     2251
     2252    visitor.reportExtraMemoryVisited(ownerExecutable(), sizeof(CodeBlock));
     2253    if (m_jitCode)
     2254        visitor.reportExtraMemoryVisited(ownerExecutable(), m_jitCode->size());
     2255    if (m_instructions.size()) {
     2256        // Divide by refCount() because m_instructions points to something that is shared
     2257        // by multiple CodeBlocks, and we only want to count it towards the heap size once.
     2258        // Having each CodeBlock report only its proportional share of the size is one way
     2259        // of accomplishing this.
     2260        visitor.reportExtraMemoryVisited(ownerExecutable(), m_instructions.size() * sizeof(Instruction) / m_instructions.refCount());
     2261    }
     2262
     2263    visitor.append(&m_unlinkedCode);
    23192264
    23202265    // There are two things that may use unconditional finalizers: inline cache clearing
     
    23222267    // is probably quite close to 1. So we add one no matter what and when it runs, it
    23232268    // figures out whether it has any work to do.
    2324     visitor.addUnconditionalFinalizer(&m_unconditionalFinalizer);
    2325 
     2269    visitor.addUnconditionalFinalizer(this);
     2270   
     2271    m_allTransitionsHaveBeenMarked = false;
     2272   
     2273    if (shouldVisitStrongly()) {
     2274        visitStrongly(visitor);
     2275        return;
     2276    }
     2277   
    23262278    if (!JITCode::isOptimizingJIT(jitType()))
    23272279        return;
    23282280
    2329     // If we jettison ourselves we'll install our alternative, so make sure that it
    2330     // survives GC even if we don't.
    2331     visitor.append(&m_alternative);
    2332    
    23332281    // There are two things that we use weak reference harvesters for: DFG fixpoint for
    23342282    // jettisoning, and trying to find structures that would be live based on some
    23352283    // inline cache. So it makes sense to register them regardless.
    2336     visitor.addWeakReferenceHarvester(&m_weakReferenceHarvester);
     2284    visitor.addWeakReferenceHarvester(this);
    23372285
    23382286#if ENABLE(DFG_JIT)
     
    23452293    // other reasons, that this iteration should run again; it will notify us of this
    23462294    // decision by calling harvestWeakReferences().
    2347 
    2348     m_allTransitionsHaveBeenMarked = false;
     2295   
     2296    m_jitCode->dfgCommon()->livenessHasBeenProved = false;
     2297   
    23492298    propagateTransitions(visitor);
    2350 
    2351     m_jitCode->dfgCommon()->livenessHasBeenProved = false;
    23522299    determineLiveness(visitor);
    23532300#endif // ENABLE(DFG_JIT)
    2354 }
    2355 
    2356 void CodeBlock::visitChildren(JSCell* cell, SlotVisitor& visitor)
    2357 {
    2358     CodeBlock* thisObject = jsCast<CodeBlock*>(cell);
    2359     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
    2360     JSCell::visitChildren(thisObject, visitor);
    2361     thisObject->visitChildren(visitor);
    2362 }
    2363 
    2364 void CodeBlock::visitChildren(SlotVisitor& visitor)
    2365 {
    2366     // There are two things that may use unconditional finalizers: inline cache clearing
    2367     // and jettisoning. The probability of us wanting to do at least one of those things
    2368     // is probably quite close to 1. So we add one no matter what and when it runs, it
    2369     // figures out whether it has any work to do.
    2370     visitor.addUnconditionalFinalizer(&m_unconditionalFinalizer);
    2371 
    2372     if (CodeBlock* otherBlock = specialOSREntryBlockOrNull())
    2373         visitor.appendUnbarrieredReadOnlyPointer(otherBlock);
    2374 
    2375     if (m_jitCode)
    2376         visitor.reportExtraMemoryVisited(this, m_jitCode->size());
    2377     if (m_instructions.size())
    2378         visitor.reportExtraMemoryVisited(this, m_instructions.size() * sizeof(Instruction) / m_instructions.refCount());
    2379 
    2380     visitor.append(&m_unlinkedCode);
    2381 
    2382     stronglyVisitStrongReferences(visitor);
    2383     stronglyVisitWeakReferences(visitor);
    2384 
    2385     m_allTransitionsHaveBeenMarked = false;
    2386     propagateTransitions(visitor);
    23872301}
    23882302
     
    24142328    // - Code blocks that don't have any dead weak references.
    24152329
    2416     return Heap::isMarked(this);
     2330    if (m_visitStronglyHasBeenCalled.load(std::memory_order_relaxed))
     2331        return true;
     2332
     2333#if ENABLE(DFG_JIT)
     2334    if (JITCode::isOptimizingJIT(jitType())) {
     2335        if (m_jitCode->dfgCommon()->livenessHasBeenProved)
     2336            return true;
     2337    }
     2338#endif
     2339
     2340    return false;
    24172341}
    24182342
     
    24242348}
    24252349
    2426 static std::chrono::milliseconds timeToLive(JITCode::JITType jitType)
    2427 {
    2428     switch (jitType) {
    2429     case JITCode::InterpreterThunk:
    2430         return std::chrono::duration_cast<std::chrono::milliseconds>(
    2431             std::chrono::seconds(5));
    2432     case JITCode::BaselineJIT:
    2433         // Effectively 10 additional seconds, since BaselineJIT and
    2434         // InterpreterThunk share a CodeBlock.
    2435         return std::chrono::duration_cast<std::chrono::milliseconds>(
    2436             std::chrono::seconds(15));
    2437     case JITCode::DFGJIT:
    2438         return std::chrono::duration_cast<std::chrono::milliseconds>(
    2439             std::chrono::seconds(20));
    2440     case JITCode::FTLJIT:
    2441         return std::chrono::duration_cast<std::chrono::milliseconds>(
    2442             std::chrono::seconds(60));
    2443     default:
    2444         return std::chrono::milliseconds::max();
    2445     }
    2446 }
    2447 
    24482350bool CodeBlock::shouldJettisonDueToOldAge()
    24492351{
    2450     if (Heap::isMarked(this))
     2352    if (m_visitStronglyHasBeenCalled.load(std::memory_order_relaxed))
    24512353        return false;
    24522354
    2453     if (timeSinceCreation() < timeToLive(jitType()))
     2355    if (timeSinceCreation() < JITCode::timeToLive(jitType()))
    24542356        return false;
    24552357
     
    26042506    // come back here again, and scan the strong references.
    26052507    dfgCommon->livenessHasBeenProved = true;
    2606     visitor.appendUnbarrieredReadOnlyPointer(this);
     2508    stronglyVisitStrongReferences(visitor);
    26072509#endif // ENABLE(DFG_JIT)
    26082510}
    26092511
    2610 void CodeBlock::WeakReferenceHarvester::visitWeakReferences(SlotVisitor& visitor)
    2611 {
    2612     CodeBlock* codeBlock =
    2613         bitwise_cast<CodeBlock*>(
    2614             bitwise_cast<char*>(this) - OBJECT_OFFSETOF(CodeBlock, m_weakReferenceHarvester));
    2615 
    2616     codeBlock->propagateTransitions(visitor);
    2617     codeBlock->determineLiveness(visitor);
     2512void CodeBlock::visitWeakReferences(SlotVisitor& visitor)
     2513{
     2514    propagateTransitions(visitor);
     2515    determineLiveness(visitor);
    26182516}
    26192517
     
    27352633}
    27362634
    2737 void CodeBlock::UnconditionalFinalizer::finalizeUnconditionally()
    2738 {
    2739     CodeBlock* codeBlock = bitwise_cast<CodeBlock*>(
    2740         bitwise_cast<char*>(this) - OBJECT_OFFSETOF(CodeBlock, m_unconditionalFinalizer));
    2741 
     2635void CodeBlock::finalizeUnconditionally()
     2636{
    27422637#if ENABLE(DFG_JIT)
    2743     if (codeBlock->shouldJettisonDueToWeakReference()) {
    2744         codeBlock->jettison(Profiler::JettisonDueToWeakReference);
     2638    if (shouldJettisonDueToWeakReference()) {
     2639        jettison(Profiler::JettisonDueToWeakReference);
    27452640        return;
    27462641    }
    27472642#endif // ENABLE(DFG_JIT)
    27482643
    2749     if (codeBlock->shouldJettisonDueToOldAge()) {
    2750         codeBlock->jettison(Profiler::JettisonDueToOldAge);
     2644    if (shouldJettisonDueToOldAge()) {
     2645        jettison(Profiler::JettisonDueToOldAge);
    27512646        return;
    27522647    }
    27532648
    2754     if (JITCode::couldBeInterpreted(codeBlock->jitType()))
    2755         codeBlock->finalizeLLIntInlineCaches();
     2649    if (JITCode::couldBeInterpreted(jitType()))
     2650        finalizeLLIntInlineCaches();
    27562651
    27572652#if ENABLE(JIT)
    2758     if (!!codeBlock->jitCode())
    2759         codeBlock->finalizeBaselineJITInlineCaches();
     2653    if (!!jitCode())
     2654        finalizeBaselineJITInlineCaches();
    27602655#endif
    27612656}
     
    28522747    // the OSR exit against.
    28532748
    2854     visitor.append(&m_alternative);
     2749    alternative()->visitStrongly(visitor);
    28552750
    28562751#if ENABLE(DFG_JIT)
     
    28582753    if (dfgCommon->inlineCallFrames) {
    28592754        for (auto* inlineCallFrame : *dfgCommon->inlineCallFrames) {
    2860             ASSERT(inlineCallFrame->baselineCodeBlock);
    2861             visitor.append(&inlineCallFrame->baselineCodeBlock);
     2755            ASSERT(inlineCallFrame->baselineCodeBlock());
     2756            inlineCallFrame->baselineCodeBlock()->visitStrongly(visitor);
    28622757        }
    28632758    }
     
    30682963        m_incomingLLIntCalls.begin()->unlink();
    30692964#if ENABLE(JIT)
     2965    if (m_incomingCalls.isEmpty() && m_incomingPolymorphicCalls.isEmpty())
     2966        return;
    30702967    while (m_incomingCalls.begin() != m_incomingCalls.end())
    30712968        m_incomingCalls.begin()->unlink(*vm());
     
    30812978}
    30822979
    3083 CodeBlock* CodeBlock::newReplacement()
     2980PassRefPtr<CodeBlock> CodeBlock::newReplacement()
    30842981{
    30852982    return ownerScriptExecutable()->newReplacementCodeBlockFor(specializationKind());
     
    30872984
    30882985#if ENABLE(JIT)
    3089 CodeBlock* CodeBlock::replacement()
    3090 {
    3091     const ClassInfo* classInfo = this->classInfo();
    3092 
    3093     if (classInfo == FunctionCodeBlock::info())
    3094         return jsCast<FunctionExecutable*>(ownerExecutable())->codeBlockFor(m_isConstructor ? CodeForConstruct : CodeForCall);
    3095 
    3096     if (classInfo == EvalCodeBlock::info())
    3097         return jsCast<EvalExecutable*>(ownerExecutable())->codeBlock();
    3098 
    3099     if (classInfo == ProgramCodeBlock::info())
    3100         return jsCast<ProgramExecutable*>(ownerExecutable())->codeBlock();
    3101 
    3102     if (classInfo == ModuleProgramCodeBlock::info())
    3103         return jsCast<ModuleProgramExecutable*>(ownerExecutable())->codeBlock();
     2986CodeBlock* ProgramCodeBlock::replacement()
     2987{
     2988    return jsCast<ProgramExecutable*>(ownerExecutable())->codeBlock();
     2989}
     2990
     2991CodeBlock* ModuleProgramCodeBlock::replacement()
     2992{
     2993    return jsCast<ModuleProgramExecutable*>(ownerExecutable())->codeBlock();
     2994}
     2995
     2996CodeBlock* EvalCodeBlock::replacement()
     2997{
     2998    return jsCast<EvalExecutable*>(ownerExecutable())->codeBlock();
     2999}
     3000
     3001CodeBlock* FunctionCodeBlock::replacement()
     3002{
     3003    return jsCast<FunctionExecutable*>(ownerExecutable())->codeBlockFor(m_isConstructor ? CodeForConstruct : CodeForCall);
     3004}
     3005
     3006DFG::CapabilityLevel ProgramCodeBlock::capabilityLevelInternal()
     3007{
     3008    return DFG::programCapabilityLevel(this);
     3009}
     3010
     3011DFG::CapabilityLevel ModuleProgramCodeBlock::capabilityLevelInternal()
     3012{
     3013    return DFG::programCapabilityLevel(this);
     3014}
     3015
     3016DFG::CapabilityLevel EvalCodeBlock::capabilityLevelInternal()
     3017{
     3018    return DFG::evalCapabilityLevel(this);
     3019}
     3020
     3021DFG::CapabilityLevel FunctionCodeBlock::capabilityLevelInternal()
     3022{
     3023    if (m_isConstructor)
     3024        return DFG::functionForConstructCapabilityLevel(this);
     3025    return DFG::functionForCallCapabilityLevel(this);
     3026}
    31043027
    31053028#if ENABLE(WEBASSEMBLY)
    3106     if (classInfo == WebAssemblyCodeBlock::info())
    3107         return nullptr
     3029CodeBlock* WebAssemblyCodeBlock::replacement()
     3030{
     3031    return nullptr;
     3032}
     3033
     3034DFG::CapabilityLevel WebAssemblyCodeBlock::capabilityLevelInternal()
     3035{
     3036    return DFG::CannotCompile;
     3037}
    31083038#endif
    3109 
    3110     RELEASE_ASSERT_NOT_REACHED();
    3111     return nullptr;
    3112 }
    3113 
    3114 DFG::CapabilityLevel CodeBlock::computeCapabilityLevel()
    3115 {
    3116     const ClassInfo* classInfo = this->classInfo();
    3117 
    3118     if (classInfo == FunctionCodeBlock::info()) {
    3119         if (m_isConstructor)
    3120             return DFG::functionForConstructCapabilityLevel(this);
    3121         return DFG::functionForCallCapabilityLevel(this);
    3122     }
    3123 
    3124     if (classInfo == EvalCodeBlock::info())
    3125         return DFG::evalCapabilityLevel(this);
    3126 
    3127     if (classInfo == ProgramCodeBlock::info())
    3128         return DFG::programCapabilityLevel(this);
    3129 
    3130     if (classInfo == ModuleProgramCodeBlock::info())
    3131         return DFG::programCapabilityLevel(this);
    3132 
    3133 #if ENABLE(WEBASSEMBLY)
    3134     if (classInfo == WebAssemblyCodeBlock::info())
    3135         return DFG::CannotCompile;
    31363039#endif
    3137 
    3138     RELEASE_ASSERT_NOT_REACHED();
    3139     return DFG::CannotCompile;
    3140 }
    3141 
    3142 #endif // ENABLE(JIT)
    31433040
    31443041void CodeBlock::jettison(Profiler::JettisonReason reason, ReoptimizationMode mode, const FireDetail* detail)
     
    32443141    if (!codeOrigin.inlineCallFrame)
    32453142        return globalObject();
    3246     return codeOrigin.inlineCallFrame->baselineCodeBlock->globalObject();
     3143    return jsCast<FunctionExecutable*>(codeOrigin.inlineCallFrame->executable.get())->eitherCodeBlock()->globalObject();
    32473144}
    32483145
     
    40843981DFG::CapabilityLevel CodeBlock::capabilityLevel()
    40853982{
    4086     DFG::CapabilityLevel result = computeCapabilityLevel();
     3983    DFG::CapabilityLevel result = capabilityLevelInternal();
    40873984    m_capabilityLevelState = result;
    40883985    return result;
  • trunk/Source/JavaScriptCore/bytecode/CodeBlock.h

    r190522 r190546  
    3939#include "CodeBlockHash.h"
    4040#include "CodeBlockSet.h"
     41#include "ConcurrentJITLock.h"
    4142#include "CodeOrigin.h"
    4243#include "CodeType.h"
    4344#include "CompactJITCodeMap.h"
    44 #include "ConcurrentJITLock.h"
    4545#include "DFGCommon.h"
    4646#include "DFGExitProfile.h"
     
    5050#include "ExpressionRangeInfo.h"
    5151#include "HandlerInfo.h"
     52#include "ObjectAllocationProfile.h"
     53#include "Options.h"
     54#include "PutPropertySlot.h"
    5255#include "Instruction.h"
    5356#include "JITCode.h"
    5457#include "JITWriteBarrier.h"
    55 #include "JSCell.h"
    5658#include "JSGlobalObject.h"
    5759#include "JumpTable.h"
    5860#include "LLIntCallLinkInfo.h"
    5961#include "LazyOperandValueProfile.h"
    60 #include "ObjectAllocationProfile.h"
    61 #include "Options.h"
    6262#include "ProfilerCompilation.h"
    6363#include "ProfilerJettisonReason.h"
    64 #include "PutPropertySlot.h"
    6564#include "RegExpObject.h"
    6665#include "StructureStubInfo.h"
     
    8786enum ReoptimizationMode { DontCountReoptimization, CountReoptimization };
    8887
    89 class CodeBlock : public JSCell {
    90     typedef JSCell Base;
     88class CodeBlock : public ThreadSafeRefCounted<CodeBlock>, public UnconditionalFinalizer, public WeakReferenceHarvester {
     89    WTF_MAKE_FAST_ALLOCATED;
    9190    friend class BytecodeLivenessAnalysis;
    9291    friend class JIT;
    9392    friend class LLIntOffsetsExtractor;
    94 
    95     class UnconditionalFinalizer : public JSC::UnconditionalFinalizer {
    96         virtual void finalizeUnconditionally() override;
    97     };
    98 
    99     class WeakReferenceHarvester : public JSC::WeakReferenceHarvester {
    100         virtual void visitWeakReferences(SlotVisitor&) override;
    101     };
    102 
    10393public:
    10494    enum CopyParsedBlockTag { CopyParsedBlock };
    105 
    106     static const unsigned StructureFlags = Base::StructureFlags | StructureIsImmortal;
    107 
    108     DECLARE_INFO;
    109 
    11095protected:
    111     CodeBlock(VM*, Structure*, CopyParsedBlockTag, CodeBlock& other);
    112     CodeBlock(VM*, Structure*, ScriptExecutable* ownerExecutable, UnlinkedCodeBlock*, JSScope*, PassRefPtr<SourceProvider>, unsigned sourceOffset, unsigned firstLineColumnOffset);
     96    CodeBlock(CopyParsedBlockTag, CodeBlock& other);
     97       
     98    CodeBlock(ScriptExecutable* ownerExecutable, UnlinkedCodeBlock*, JSScope*, PassRefPtr<SourceProvider>, unsigned sourceOffset, unsigned firstLineColumnOffset);
    11399#if ENABLE(WEBASSEMBLY)
    114     CodeBlock(VM*, Structure*, WebAssemblyExecutable* ownerExecutable, VM&, JSGlobalObject*);
    115 #endif
    116 
    117     void finishCreation(VM&, CopyParsedBlockTag, CodeBlock& other);
    118     void finishCreation(VM&, ScriptExecutable* ownerExecutable, UnlinkedCodeBlock*, JSScope*);
    119 #if ENABLE(WEBASSEMBLY)
    120     void finishCreation(VM&, WebAssemblyExecutable* ownerExecutable, JSGlobalObject*);
     100    CodeBlock(WebAssemblyExecutable* ownerExecutable, VM&, JSGlobalObject*);
    121101#endif
    122102
     
    125105
    126106public:
    127     JS_EXPORT_PRIVATE ~CodeBlock();
     107    JS_EXPORT_PRIVATE virtual ~CodeBlock();
    128108
    129109    UnlinkedCodeBlock* unlinkedCodeBlock() const { return m_unlinkedCode.get(); }
     
    145125    static ptrdiff_t offsetOfNumParameters() { return OBJECT_OFFSETOF(CodeBlock, m_numParameters); }
    146126
    147     CodeBlock* alternative() const { return static_cast<CodeBlock*>(m_alternative.get()); }
    148     void setAlternative(VM&, CodeBlock*);
     127    CodeBlock* alternative() { return m_alternative.get(); }
     128    void setAlternative(PassRefPtr<CodeBlock> alternative) { m_alternative = alternative; }
    149129
    150130    template <typename Functor> void forEachRelatedCodeBlock(Functor&& functor)
     
    169149        return specializationFromIsConstruct(m_isConstructor);
    170150    }
    171 
    172     CodeBlock* alternativeForJettison();   
     151   
    173152    CodeBlock* baselineAlternative();
    174153   
     
    177156    CodeBlock* baselineVersion();
    178157
    179     static void visitChildren(JSCell*, SlotVisitor&);
    180     void visitChildren(SlotVisitor&);
    181     void visitWeakly(SlotVisitor&);
    182     void clearVisitWeaklyHasBeenCalled();
     158    void clearMarks();
     159    void visitAggregate(SlotVisitor&);
     160    void visitStrongly(SlotVisitor&);
    183161
    184162    void dumpSource();
     
    288266
    289267    // Exactly equivalent to codeBlock->ownerExecutable()->newReplacementCodeBlockFor(codeBlock->specializationKind())
    290     CodeBlock* newReplacement();
     268    PassRefPtr<CodeBlock> newReplacement();
    291269   
    292270    void setJITCode(PassRefPtr<JITCode> code)
     
    314292   
    315293#if ENABLE(JIT)
    316     CodeBlock* replacement();
    317 
    318     DFG::CapabilityLevel computeCapabilityLevel();
     294    virtual CodeBlock* replacement() = 0;
     295
     296    virtual DFG::CapabilityLevel capabilityLevelInternal() = 0;
    319297    DFG::CapabilityLevel capabilityLevel();
    320298    DFG::CapabilityLevel capabilityLevelState() { return m_capabilityLevelState; }
     
    566544        unsigned result = m_constantRegisters.size();
    567545        m_constantRegisters.append(WriteBarrier<Unknown>());
    568         m_constantRegisters.last().set(m_globalObject->vm(), this, v);
     546        m_constantRegisters.last().set(m_globalObject->vm(), m_ownerExecutable.get(), v);
    569547        m_constantsSourceCodeRepresentation.append(SourceCodeRepresentation::Other);
    570548        return result;
     
    918896
    919897protected:
     898    virtual void visitWeakReferences(SlotVisitor&) override;
     899    virtual void finalizeUnconditionally() override;
    920900    void finalizeLLIntInlineCaches();
    921901    void finalizeBaselineJITInlineCaches();
     
    944924        m_constantRegisters.resizeToFit(count);
    945925        for (size_t i = 0; i < count; i++)
    946             m_constantRegisters[i].set(*m_vm, this, constants[i].get());
     926            m_constantRegisters[i].set(*m_vm, ownerExecutable(), constants[i].get());
    947927        m_constantsSourceCodeRepresentation = constantsSourceCodeRepresentation;
    948928    }
     
    951931    {
    952932        ASSERT(isConstantRegisterIndex(index) && static_cast<size_t>(index - FirstConstantRegisterIndex) < m_constantRegisters.size());
    953         m_constantRegisters[index - FirstConstantRegisterIndex].set(m_globalObject->vm(), this, value);
     933        m_constantRegisters[index - FirstConstantRegisterIndex].set(m_globalObject->vm(), m_ownerExecutable.get(), value);
    954934    }
    955935
     
    10231003    bool m_needsActivation;
    10241004
    1025     Atomic<bool> m_visitWeaklyHasBeenCalled;
     1005    Atomic<bool> m_visitAggregateHasBeenCalled;
     1006    Atomic<bool> m_visitStronglyHasBeenCalled;
    10261007
    10271008    RefPtr<SourceProvider> m_source;
     
    10651046    Vector<WriteBarrier<FunctionExecutable>> m_functionExprs;
    10661047
    1067     WriteBarrier<CodeBlock> m_alternative;
     1048    RefPtr<CodeBlock> m_alternative;
    10681049   
    10691050    BaselineExecutionCounter m_llintExecuteCounter;
     
    10851066    DFG::CapabilityLevel m_capabilityLevelState;
    10861067#endif
    1087 
    1088     UnconditionalFinalizer m_unconditionalFinalizer;
    1089     WeakReferenceHarvester m_weakReferenceHarvester;
    10901068};
    10911069
     
    10941072
    10951073class GlobalCodeBlock : public CodeBlock {
    1096     typedef CodeBlock Base;
    1097     DECLARE_INFO;
    1098 
    10991074protected:
    1100     GlobalCodeBlock(VM* vm, Structure* structure, CopyParsedBlockTag, GlobalCodeBlock& other)
    1101         : CodeBlock(vm, structure, CopyParsedBlock, other)
    1102     {
    1103     }
    1104 
    1105     GlobalCodeBlock(VM* vm, Structure* structure, ScriptExecutable* ownerExecutable, UnlinkedCodeBlock* unlinkedCodeBlock, JSScope* scope, PassRefPtr<SourceProvider> sourceProvider, unsigned sourceOffset, unsigned firstLineColumnOffset)
    1106         : CodeBlock(vm, structure, ownerExecutable, unlinkedCodeBlock, scope, sourceProvider, sourceOffset, firstLineColumnOffset)
     1075    GlobalCodeBlock(CopyParsedBlockTag, GlobalCodeBlock& other)
     1076    : CodeBlock(CopyParsedBlock, other)
     1077    {
     1078    }
     1079       
     1080    GlobalCodeBlock(ScriptExecutable* ownerExecutable, UnlinkedCodeBlock* unlinkedCodeBlock, JSScope* scope, PassRefPtr<SourceProvider> sourceProvider, unsigned sourceOffset, unsigned firstLineColumnOffset)
     1081        : CodeBlock(ownerExecutable, unlinkedCodeBlock, scope, sourceProvider, sourceOffset, firstLineColumnOffset)
    11071082    {
    11081083    }
     
    11111086class ProgramCodeBlock : public GlobalCodeBlock {
    11121087public:
    1113     typedef GlobalCodeBlock Base;
    1114     DECLARE_INFO;
    1115 
    1116     static ProgramCodeBlock* create(VM* vm, CopyParsedBlockTag, ProgramCodeBlock& other)
    1117     {
    1118         ProgramCodeBlock* instance = new (NotNull, allocateCell<ProgramCodeBlock>(vm->heap))
    1119             ProgramCodeBlock(vm, vm->programCodeBlockStructure.get(), CopyParsedBlock, other);
    1120         instance->finishCreation(*vm, CopyParsedBlock, other);
    1121         return instance;
    1122     }
    1123 
    1124     static ProgramCodeBlock* create(VM* vm, ProgramExecutable* ownerExecutable, UnlinkedProgramCodeBlock* unlinkedCodeBlock,
    1125         JSScope* scope, PassRefPtr<SourceProvider> sourceProvider, unsigned firstLineColumnOffset)
    1126     {
    1127         ProgramCodeBlock* instance = new (NotNull, allocateCell<ProgramCodeBlock>(vm->heap))
    1128             ProgramCodeBlock(vm, vm->programCodeBlockStructure.get(), ownerExecutable, unlinkedCodeBlock, scope, sourceProvider, firstLineColumnOffset);
    1129         instance->finishCreation(*vm, ownerExecutable, unlinkedCodeBlock, scope);
    1130         return instance;
    1131     }
    1132 
    1133     static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
    1134     {
    1135         return Structure::create(vm, globalObject, prototype, TypeInfo(CellType, StructureFlags), info());
    1136     }
    1137 
    1138 private:
    1139     ProgramCodeBlock(VM* vm, Structure* structure, CopyParsedBlockTag, ProgramCodeBlock& other)
    1140         : GlobalCodeBlock(vm, structure, CopyParsedBlock, other)
    1141     {
    1142     }
    1143 
    1144     ProgramCodeBlock(VM* vm, Structure* structure, ProgramExecutable* ownerExecutable, UnlinkedProgramCodeBlock* unlinkedCodeBlock,
    1145         JSScope* scope, PassRefPtr<SourceProvider> sourceProvider, unsigned firstLineColumnOffset)
    1146         : GlobalCodeBlock(vm, structure, ownerExecutable, unlinkedCodeBlock, scope, sourceProvider, 0, firstLineColumnOffset)
    1147     {
    1148     }
    1149 
    1150     static void destroy(JSCell*);
     1088    ProgramCodeBlock(CopyParsedBlockTag, ProgramCodeBlock& other)
     1089    : GlobalCodeBlock(CopyParsedBlock, other)
     1090    {
     1091    }
     1092
     1093    ProgramCodeBlock(ProgramExecutable* ownerExecutable, UnlinkedProgramCodeBlock* unlinkedCodeBlock, JSScope* scope, PassRefPtr<SourceProvider> sourceProvider, unsigned firstLineColumnOffset)
     1094        : GlobalCodeBlock(ownerExecutable, unlinkedCodeBlock, scope, sourceProvider, 0, firstLineColumnOffset)
     1095    {
     1096    }
     1097
     1098#if ENABLE(JIT)
     1099protected:
     1100    virtual CodeBlock* replacement() override;
     1101    virtual DFG::CapabilityLevel capabilityLevelInternal() override;
     1102#endif
    11511103};
    11521104
    11531105class ModuleProgramCodeBlock : public GlobalCodeBlock {
    11541106public:
    1155     typedef GlobalCodeBlock Base;
    1156     DECLARE_INFO;
    1157 
    1158     static ModuleProgramCodeBlock* create(VM* vm, CopyParsedBlockTag, ModuleProgramCodeBlock& other)
    1159     {
    1160         ModuleProgramCodeBlock* instance = new (NotNull, allocateCell<ModuleProgramCodeBlock>(vm->heap))
    1161             ModuleProgramCodeBlock(vm, vm->moduleProgramCodeBlockStructure.get(), CopyParsedBlock, other);
    1162         instance->finishCreation(*vm, CopyParsedBlock, other);
    1163         return instance;
    1164     }
    1165 
    1166     static ModuleProgramCodeBlock* create(VM* vm, ModuleProgramExecutable* ownerExecutable, UnlinkedModuleProgramCodeBlock* unlinkedCodeBlock,
    1167         JSScope* scope, PassRefPtr<SourceProvider> sourceProvider, unsigned firstLineColumnOffset)
    1168     {
    1169         ModuleProgramCodeBlock* instance = new (NotNull, allocateCell<ModuleProgramCodeBlock>(vm->heap))
    1170             ModuleProgramCodeBlock(vm, vm->moduleProgramCodeBlockStructure.get(), ownerExecutable, unlinkedCodeBlock, scope, sourceProvider, firstLineColumnOffset);
    1171         instance->finishCreation(*vm, ownerExecutable, unlinkedCodeBlock, scope);
    1172         return instance;
    1173     }
    1174 
    1175     static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
    1176     {
    1177         return Structure::create(vm, globalObject, prototype, TypeInfo(CellType, StructureFlags), info());
    1178     }
    1179 
    1180 private:
    1181     ModuleProgramCodeBlock(VM* vm, Structure* structure, CopyParsedBlockTag, ModuleProgramCodeBlock& other)
    1182         : GlobalCodeBlock(vm, structure, CopyParsedBlock, other)
    1183     {
    1184     }
    1185 
    1186     ModuleProgramCodeBlock(VM* vm, Structure* structure, ModuleProgramExecutable* ownerExecutable, UnlinkedModuleProgramCodeBlock* unlinkedCodeBlock,
    1187         JSScope* scope, PassRefPtr<SourceProvider> sourceProvider, unsigned firstLineColumnOffset)
    1188         : GlobalCodeBlock(vm, structure, ownerExecutable, unlinkedCodeBlock, scope, sourceProvider, 0, firstLineColumnOffset)
    1189     {
    1190     }
    1191 
    1192     static void destroy(JSCell*);
     1107    ModuleProgramCodeBlock(CopyParsedBlockTag, ModuleProgramCodeBlock& other)
     1108        : GlobalCodeBlock(CopyParsedBlock, other)
     1109    {
     1110    }
     1111
     1112    ModuleProgramCodeBlock(ModuleProgramExecutable* ownerExecutable, UnlinkedModuleProgramCodeBlock* unlinkedCodeBlock, JSScope* scope, PassRefPtr<SourceProvider> sourceProvider, unsigned firstLineColumnOffset)
     1113        : GlobalCodeBlock(ownerExecutable, unlinkedCodeBlock, scope, sourceProvider, 0, firstLineColumnOffset)
     1114    {
     1115    }
     1116
     1117#if ENABLE(JIT)
     1118protected:
     1119    virtual CodeBlock* replacement() override;
     1120    virtual DFG::CapabilityLevel capabilityLevelInternal() override;
     1121#endif
    11931122};
    11941123
    11951124class EvalCodeBlock : public GlobalCodeBlock {
    11961125public:
    1197     typedef GlobalCodeBlock Base;
    1198     DECLARE_INFO;
    1199 
    1200     static EvalCodeBlock* create(VM* vm, CopyParsedBlockTag, EvalCodeBlock& other)
    1201     {
    1202         EvalCodeBlock* instance = new (NotNull, allocateCell<EvalCodeBlock>(vm->heap))
    1203             EvalCodeBlock(vm, vm->evalCodeBlockStructure.get(), CopyParsedBlock, other);
    1204         instance->finishCreation(*vm, CopyParsedBlock, other);
    1205         return instance;
    1206     }
    1207 
    1208     static EvalCodeBlock* create(VM* vm, EvalExecutable* ownerExecutable, UnlinkedEvalCodeBlock* unlinkedCodeBlock,
    1209         JSScope* scope, PassRefPtr<SourceProvider> sourceProvider)
    1210     {
    1211         EvalCodeBlock* instance = new (NotNull, allocateCell<EvalCodeBlock>(vm->heap))
    1212             EvalCodeBlock(vm, vm->evalCodeBlockStructure.get(), ownerExecutable, unlinkedCodeBlock, scope, sourceProvider);
    1213         instance->finishCreation(*vm, ownerExecutable, unlinkedCodeBlock, scope);
    1214         return instance;
    1215     }
    1216 
    1217     static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
    1218     {
    1219         return Structure::create(vm, globalObject, prototype, TypeInfo(CellType, StructureFlags), info());
    1220     }
    1221 
     1126    EvalCodeBlock(CopyParsedBlockTag, EvalCodeBlock& other)
     1127        : GlobalCodeBlock(CopyParsedBlock, other)
     1128    {
     1129    }
     1130       
     1131    EvalCodeBlock(EvalExecutable* ownerExecutable, UnlinkedEvalCodeBlock* unlinkedCodeBlock, JSScope* scope, PassRefPtr<SourceProvider> sourceProvider)
     1132        : GlobalCodeBlock(ownerExecutable, unlinkedCodeBlock, scope, sourceProvider, 0, 1)
     1133    {
     1134    }
     1135   
    12221136    const Identifier& variable(unsigned index) { return unlinkedEvalCodeBlock()->variable(index); }
    12231137    unsigned numVariables() { return unlinkedEvalCodeBlock()->numVariables(); }
    12241138   
    1225 private:
    1226     EvalCodeBlock(VM* vm, Structure* structure, CopyParsedBlockTag, EvalCodeBlock& other)
    1227         : GlobalCodeBlock(vm, structure, CopyParsedBlock, other)
    1228     {
    1229     }
    1230        
    1231     EvalCodeBlock(VM* vm, Structure* structure, EvalExecutable* ownerExecutable, UnlinkedEvalCodeBlock* unlinkedCodeBlock,
    1232         JSScope* scope, PassRefPtr<SourceProvider> sourceProvider)
    1233         : GlobalCodeBlock(vm, structure, ownerExecutable, unlinkedCodeBlock, scope, sourceProvider, 0, 1)
    1234     {
    1235     }
    1236    
    1237     static void destroy(JSCell*);
    1238 
     1139#if ENABLE(JIT)
     1140protected:
     1141    virtual CodeBlock* replacement() override;
     1142    virtual DFG::CapabilityLevel capabilityLevelInternal() override;
     1143#endif
     1144   
    12391145private:
    12401146    UnlinkedEvalCodeBlock* unlinkedEvalCodeBlock() const { return jsCast<UnlinkedEvalCodeBlock*>(unlinkedCodeBlock()); }
     
    12431149class FunctionCodeBlock : public CodeBlock {
    12441150public:
    1245     typedef CodeBlock Base;
    1246     DECLARE_INFO;
    1247 
    1248     static FunctionCodeBlock* create(VM* vm, CopyParsedBlockTag, FunctionCodeBlock& other)
    1249     {
    1250         FunctionCodeBlock* instance = new (NotNull, allocateCell<FunctionCodeBlock>(vm->heap))
    1251             FunctionCodeBlock(vm, vm->functionCodeBlockStructure.get(), CopyParsedBlock, other);
    1252         instance->finishCreation(*vm, CopyParsedBlock, other);
    1253         return instance;
    1254     }
    1255 
    1256     static FunctionCodeBlock* create(VM* vm, FunctionExecutable* ownerExecutable, UnlinkedFunctionCodeBlock* unlinkedCodeBlock, JSScope* scope,
    1257         PassRefPtr<SourceProvider> sourceProvider, unsigned sourceOffset, unsigned firstLineColumnOffset)
    1258     {
    1259         FunctionCodeBlock* instance = new (NotNull, allocateCell<FunctionCodeBlock>(vm->heap))
    1260             FunctionCodeBlock(vm, vm->functionCodeBlockStructure.get(), ownerExecutable, unlinkedCodeBlock, scope, sourceProvider, sourceOffset, firstLineColumnOffset);
    1261         instance->finishCreation(*vm, ownerExecutable, unlinkedCodeBlock, scope);
    1262         return instance;
    1263     }
    1264 
    1265     static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
    1266     {
    1267         return Structure::create(vm, globalObject, prototype, TypeInfo(CellType, StructureFlags), info());
    1268     }
    1269 
    1270 private:
    1271     FunctionCodeBlock(VM* vm, Structure* structure, CopyParsedBlockTag, FunctionCodeBlock& other)
    1272         : CodeBlock(vm, structure, CopyParsedBlock, other)
    1273     {
    1274     }
    1275 
    1276     FunctionCodeBlock(VM* vm, Structure* structure, FunctionExecutable* ownerExecutable, UnlinkedFunctionCodeBlock* unlinkedCodeBlock, JSScope* scope,
    1277         PassRefPtr<SourceProvider> sourceProvider, unsigned sourceOffset, unsigned firstLineColumnOffset)
    1278         : CodeBlock(vm, structure, ownerExecutable, unlinkedCodeBlock, scope, sourceProvider, sourceOffset, firstLineColumnOffset)
    1279     {
    1280     }
    1281    
    1282     static void destroy(JSCell*);
     1151    FunctionCodeBlock(CopyParsedBlockTag, FunctionCodeBlock& other)
     1152        : CodeBlock(CopyParsedBlock, other)
     1153    {
     1154    }
     1155
     1156    FunctionCodeBlock(FunctionExecutable* ownerExecutable, UnlinkedFunctionCodeBlock* unlinkedCodeBlock, JSScope* scope, PassRefPtr<SourceProvider> sourceProvider, unsigned sourceOffset, unsigned firstLineColumnOffset)
     1157        : CodeBlock(ownerExecutable, unlinkedCodeBlock, scope, sourceProvider, sourceOffset, firstLineColumnOffset)
     1158    {
     1159    }
     1160   
     1161#if ENABLE(JIT)
     1162protected:
     1163    virtual CodeBlock* replacement() override;
     1164    virtual DFG::CapabilityLevel capabilityLevelInternal() override;
     1165#endif
    12831166};
    12841167
     
    12861169class WebAssemblyCodeBlock : public CodeBlock {
    12871170public:
    1288     DECLARE_INFO;
    1289 
    1290     static WebAssemblyCodeBlock* create(VM* vm, CopyParsedBlockTag, WebAssemblyCodeBlock& other)
    1291     {
    1292         WebAssemblyCodeBlock* instance = new (NotNull, allocateCell<WebAssemblyCodeBlock>(vm->heap))
    1293             WebAssemblyCodeBlock(vm, vm->webAssemblyCodeBlockStructure.get(), CopyParsedBlock, other);
    1294         instance->finishCreation(*vm);
    1295         return instance;
    1296     }
    1297 
    1298     static WebAssemblyCodeBlock* create(VM* vm, WebAssemblyExecutable* ownerExecutable, JSGlobalObject* globalObject)
    1299     {
    1300         WebAssemblyCodeBlock* instance = new (NotNull, allocateCell<WebAssemblyCodeBlock>(vm->heap))
    1301             WebAssemblyCodeBlock(vm, vm->webAssemblyCodeBlockStructure.get(), ownerExecutable, globalObject);
    1302         instance->finishCreation(*vm);
    1303         return instance;
    1304     }
    1305 
    1306     static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
    1307     {
    1308         return Structure::create(vm, globalObject, prototype, TypeInfo(CellType, StructureFlags), info());
    1309     }
    1310 
    1311 private:
    1312     WebAssemblyCodeBlock(VM& vm, Structure* structure, CopyParsedBlockTag, WebAssemblyCodeBlock& other)
    1313         : CodeBlock(vm, structure, CopyParsedBlock, other)
    1314     {
    1315     }
    1316 
    1317     WebAssemblyCodeBlock(VM& vm, Structure* structure, WebAssemblyExecutable* ownerExecutable, JSGlobalObject* globalObject)
    1318         : CodeBlock(vm, structure, ownerExecutable, vm, globalObject)
    1319     {
    1320     }
    1321 
    1322     static void destroy(JSCell*);
     1171    WebAssemblyCodeBlock(CopyParsedBlockTag, WebAssemblyCodeBlock& other)
     1172        : CodeBlock(CopyParsedBlock, other)
     1173    {
     1174    }
     1175
     1176    WebAssemblyCodeBlock(WebAssemblyExecutable* ownerExecutable, VM& vm, JSGlobalObject* globalObject)
     1177        : CodeBlock(ownerExecutable, vm, globalObject)
     1178    {
     1179    }
     1180
     1181#if ENABLE(JIT)
     1182protected:
     1183    virtual CodeBlock* replacement() override;
     1184    virtual DFG::CapabilityLevel capabilityLevelInternal() override;
     1185#endif
    13231186};
    13241187#endif
     
    13481211}
    13491212
    1350 inline void CodeBlock::clearVisitWeaklyHasBeenCalled()
     1213inline void CodeBlock::clearMarks()
    13511214{
    1352     m_visitWeaklyHasBeenCalled.store(false, std::memory_order_relaxed);
     1215    m_visitStronglyHasBeenCalled.store(false, std::memory_order_relaxed);
     1216    m_visitAggregateHasBeenCalled.store(false, std::memory_order_relaxed);
    13531217}
    13541218
     
    13751239    if (!codeBlock)
    13761240        return;
    1377 
    1378     // Try to recover gracefully if we forget to execute a barrier for a
    1379     // CodeBlock that does value profiling. This is probably overkill, but we
    1380     // have always done it.
    1381     Heap::heap(codeBlock)->writeBarrier(codeBlock);
     1241   
     1242    // Force GC to visit all CodeBlocks on the stack, including old CodeBlocks
     1243    // that have not executed a barrier. This is overkill, but we have always
     1244    // done this, and it might help us recover gracefully if we forget to execute
     1245    // a barrier when a CodeBlock needs it.
     1246    codeBlock->clearMarks();
    13821247
    13831248    m_currentlyExecuting.add(codeBlock);
     
    13881253    switch (type()) {
    13891254    case ProgramExecutableType: {
    1390         if (CodeBlock* codeBlock = static_cast<CodeBlock*>(jsCast<ProgramExecutable*>(this)->m_programCodeBlock.get()))
     1255        if (CodeBlock* codeBlock = jsCast<ProgramExecutable*>(this)->m_programCodeBlock.get())
    13911256            codeBlock->forEachRelatedCodeBlock(std::forward<Functor>(functor));
    13921257        break;
     
    13941259
    13951260    case EvalExecutableType: {
    1396         if (CodeBlock* codeBlock = static_cast<CodeBlock*>(jsCast<EvalExecutable*>(this)->m_evalCodeBlock.get()))
     1261        if (CodeBlock* codeBlock = jsCast<EvalExecutable*>(this)->m_evalCodeBlock.get())
    13971262            codeBlock->forEachRelatedCodeBlock(std::forward<Functor>(functor));
    13981263        break;
     
    14021267        Functor f(std::forward<Functor>(functor));
    14031268        FunctionExecutable* executable = jsCast<FunctionExecutable*>(this);
    1404         if (CodeBlock* codeBlock = static_cast<CodeBlock*>(executable->m_codeBlockForCall.get()))
     1269        if (CodeBlock* codeBlock = executable->m_codeBlockForCall.get())
    14051270            codeBlock->forEachRelatedCodeBlock(f);
    1406         if (CodeBlock* codeBlock = static_cast<CodeBlock*>(executable->m_codeBlockForConstruct.get()))
     1271        if (CodeBlock* codeBlock = executable->m_codeBlockForConstruct.get())
    14071272            codeBlock->forEachRelatedCodeBlock(f);
    14081273        break;
     
    14101275
    14111276    case ModuleProgramExecutableType: {
    1412         if (CodeBlock* codeBlock = static_cast<CodeBlock*>(jsCast<ModuleProgramExecutable*>(this)->m_moduleProgramCodeBlock.get()))
     1277        if (CodeBlock* codeBlock = jsCast<ModuleProgramExecutable*>(this)->m_moduleProgramCodeBlock.get())
    14131278            codeBlock->forEachRelatedCodeBlock(std::forward<Functor>(functor));
    14141279        break;
  • trunk/Source/JavaScriptCore/bytecode/CodeOrigin.cpp

    r190522 r190546  
    7676            return true;
    7777       
    78         if (a.inlineCallFrame->baselineCodeBlock.get() != b.inlineCallFrame->baselineCodeBlock.get())
     78        if (a.inlineCallFrame->executable.get() != b.inlineCallFrame->executable.get())
    7979            return false;
    8080       
     
    9999            return result;
    100100       
    101         result += WTF::PtrHash<JSCell*>::hash(codeOrigin.inlineCallFrame->baselineCodeBlock.get());
     101        result += WTF::PtrHash<JSCell*>::hash(codeOrigin.inlineCallFrame->executable.get());
    102102       
    103103        codeOrigin = codeOrigin.inlineCallFrame->directCaller;
     
    116116}
    117117
    118 CodeBlock* CodeOrigin::codeOriginOwner() const
     118ScriptExecutable* CodeOrigin::codeOriginOwner() const
    119119{
    120120    if (!inlineCallFrame)
    121121        return 0;
    122     return inlineCallFrame->baselineCodeBlock.get();
     122    return inlineCallFrame->executable.get();
    123123}
    124124
     
    144144       
    145145        if (InlineCallFrame* frame = stack[i].inlineCallFrame) {
    146             out.print(frame->briefFunctionInformation(), ":<", RawPointer(frame->baselineCodeBlock.get()), "> ");
     146            out.print(frame->briefFunctionInformation(), ":<", RawPointer(frame->executable.get()), "> ");
    147147            if (frame->isClosureCall)
    148148                out.print("(closure) ");
  • trunk/Source/JavaScriptCore/bytecode/CodeOrigin.h

    r190522 r190546  
    8888    // If the code origin corresponds to inlined code, gives you the heap object that
    8989    // would have owned the code if it had not been inlined. Otherwise returns 0.
    90     CodeBlock* codeOriginOwner() const;
     90    ScriptExecutable* codeOriginOwner() const;
    9191   
    9292    int stackOffset() const;
  • trunk/Source/JavaScriptCore/bytecode/DeferredCompilationCallback.cpp

    r190522 r190546  
    3434DeferredCompilationCallback::~DeferredCompilationCallback() { }
    3535
    36 void DeferredCompilationCallback::compilationDidComplete(CodeBlock* codeBlock, CodeBlock*, CompilationResult result)
     36void DeferredCompilationCallback::compilationDidComplete(CodeBlock* codeBlock, CompilationResult result)
    3737{
    3838    dumpCompiledSourcesIfNeeded();
  • trunk/Source/JavaScriptCore/bytecode/DeferredCompilationCallback.h

    r190522 r190546  
    4343    virtual ~DeferredCompilationCallback();
    4444
    45     virtual void compilationDidBecomeReadyAsynchronously(CodeBlock*, CodeBlock* profiledDFGCodeBlock) = 0;
    46     virtual void compilationDidComplete(CodeBlock*, CodeBlock* profiledDFGCodeBlock, CompilationResult);
     45    virtual void compilationDidBecomeReadyAsynchronously(CodeBlock*) = 0;
     46    virtual void compilationDidComplete(CodeBlock*, CompilationResult);
    4747
    4848    Vector<DeferredSourceDump>& ensureDeferredSourceDump();
  • trunk/Source/JavaScriptCore/bytecode/EvalCodeCache.h

    r190522 r190546  
    5252        }
    5353       
    54         EvalExecutable* getSlow(ExecState* exec, JSCell* owner, bool inStrictContext, ThisTDZMode thisTDZMode, const String& evalSource, JSScope* scope)
     54        EvalExecutable* getSlow(ExecState* exec, ScriptExecutable* owner, bool inStrictContext, ThisTDZMode thisTDZMode, const String& evalSource, JSScope* scope)
    5555        {
    5656            VariableEnvironment variablesUnderTDZ;
  • trunk/Source/JavaScriptCore/bytecode/InlineCallFrame.cpp

    r190522 r190546  
    4848CodeBlockHash InlineCallFrame::hash() const
    4949{
    50     return baselineCodeBlock->hash();
     50    return jsCast<FunctionExecutable*>(executable.get())->codeBlockFor(
     51        specializationKind())->hash();
    5152}
    5253
    5354CString InlineCallFrame::hashAsStringIfPossible() const
    5455{
    55     return baselineCodeBlock->hashAsStringIfPossible();
     56    return jsCast<FunctionExecutable*>(executable.get())->codeBlockFor(
     57        specializationKind())->hashAsStringIfPossible();
    5658}
    5759
    5860CString InlineCallFrame::inferredName() const
    5961{
    60     return jsCast<FunctionExecutable*>(baselineCodeBlock->ownerExecutable())->inferredName().utf8();
     62    return jsCast<FunctionExecutable*>(executable.get())->inferredName().utf8();
     63}
     64
     65CodeBlock* InlineCallFrame::baselineCodeBlock() const
     66{
     67    return jsCast<FunctionExecutable*>(executable.get())->baselineCodeBlockFor(specializationKind());
    6168}
    6269
     
    6875void InlineCallFrame::dumpInContext(PrintStream& out, DumpContext* context) const
    6976{
    70     out.print(briefFunctionInformation(), ":<", RawPointer(baselineCodeBlock.get()));
    71     if (isStrictMode())
     77    out.print(briefFunctionInformation(), ":<", RawPointer(executable.get()));
     78    if (executable->isStrictMode())
    7279        out.print(" (StrictMode)");
    7380    out.print(", bc#", directCaller.bytecodeIndex, ", ", static_cast<Kind>(kind));
  • trunk/Source/JavaScriptCore/bytecode/InlineCallFrame.h

    r190522 r190546  
    3030#include "CodeBlockHash.h"
    3131#include "CodeOrigin.h"
     32#include "Executable.h"
    3233#include "ValueRecovery.h"
    3334#include "WriteBarrier.h"
     
    4243struct InlineCallFrame;
    4344class ExecState;
     45class ScriptExecutable;
    4446class JSFunction;
    4547
     
    173175   
    174176    Vector<ValueRecovery> arguments; // Includes 'this'.
    175     WriteBarrier<CodeBlock> baselineCodeBlock;
     177    WriteBarrier<ScriptExecutable> executable;
    176178    ValueRecovery calleeRecovery;
    177179    CodeOrigin directCaller;
     
    208210    CString hashAsStringIfPossible() const;
    209211   
     212    CodeBlock* baselineCodeBlock() const;
     213   
    210214    void setStackOffset(signed offset)
    211215    {
     
    216220    ptrdiff_t callerFrameOffset() const { return stackOffset * sizeof(Register) + CallFrame::callerFrameOffset(); }
    217221    ptrdiff_t returnPCOffset() const { return stackOffset * sizeof(Register) + CallFrame::returnPCOffset(); }
    218 
    219     bool isStrictMode() const { return baselineCodeBlock->isStrictMode(); }
    220222
    221223    void dumpBriefFunctionInformation(PrintStream&) const;
     
    230232{
    231233    RELEASE_ASSERT(inlineCallFrame);
    232     return inlineCallFrame->baselineCodeBlock.get();
     234    ScriptExecutable* executable = inlineCallFrame->executable.get();
     235    RELEASE_ASSERT(executable->structure()->classInfo() == FunctionExecutable::info());
     236    return static_cast<FunctionExecutable*>(executable)->baselineCodeBlockFor(inlineCallFrame->specializationKind());
    233237}
    234238
  • trunk/Source/JavaScriptCore/bytecode/PolymorphicAccess.cpp

    r190522 r190546  
    412412
    413413        // We will emit code that has a weak reference that isn't otherwise listed anywhere.
    414         state.weakReferences.append(WriteBarrier<JSCell>(vm, codeBlock, structure));
     414        state.weakReferences.append(WriteBarrier<JSCell>(vm, codeBlock->ownerExecutable(), structure));
    415415       
    416416        jit.move(CCallHelpers::TrustedImmPtr(condition.object()), scratchGPR);
     
    11711171        doesCalls |= entry->doesCalls();
    11721172   
    1173     m_stubRoutine = createJITStubRoutine(code, vm, codeBlock, doesCalls);
     1173    m_stubRoutine = createJITStubRoutine(code, vm, codeBlock->ownerExecutable(), doesCalls);
    11741174    m_watchpoints = WTF::move(state.watchpoints);
    11751175    if (!state.weakReferences.isEmpty())
  • trunk/Source/JavaScriptCore/bytecode/StructureStubInfo.cpp

    r190522 r190546  
    6363   
    6464    std::unique_ptr<AccessCase> previousCase =
    65         AccessCase::fromStructureStubInfo(vm, codeBlock, *this);
     65        AccessCase::fromStructureStubInfo(vm, codeBlock->ownerExecutable(), *this);
    6666    if (previousCase)
    6767        accessCases.append(WTF::move(previousCase));
  • trunk/Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp

    r190522 r190546  
    46344634       
    46354635        m_inlineCallFrame = byteCodeParser->m_graph.m_plan.inlineCallFrames->add();
    4636         byteCodeParser->m_graph.freeze(codeBlock->baselineVersion());
     4636        byteCodeParser->m_graph.freeze(codeBlock->ownerExecutable());
    46374637        // The owner is the machine code block, and we already have a barrier on that when the
    46384638        // plan finishes.
    4639         m_inlineCallFrame->baselineCodeBlock.setWithoutWriteBarrier(codeBlock->baselineVersion());
     4639        m_inlineCallFrame->executable.setWithoutWriteBarrier(codeBlock->ownerScriptExecutable());
    46404640        m_inlineCallFrame->setStackOffset(inlineCallFrameStart.offset() - JSStack::CallFrameHeaderSize);
    46414641        if (callee) {
     
    48294829        dataLog("Parsing ", *m_codeBlock, "\n");
    48304830   
    4831     m_dfgCodeBlock = m_graph.m_plan.profiledDFGCodeBlock;
     4831    m_dfgCodeBlock = m_graph.m_plan.profiledDFGCodeBlock.get();
    48324832    if (isFTL(m_graph.m_plan.mode) && m_dfgCodeBlock
    48334833        && Options::enablePolyvariantDevirtualization()) {
  • trunk/Source/JavaScriptCore/dfg/DFGCommonData.cpp

    r190522 r190546  
    9090            }
    9191           
    92             if (CodeBlock* baselineCodeBlock = inlineCallFrame->baselineCodeBlock.get())
    93                 trackedReferences.check(baselineCodeBlock);
     92            if (ScriptExecutable* executable = inlineCallFrame->executable.get())
     93                trackedReferences.check(executable);
    9494           
    9595            if (inlineCallFrame->calleeRecovery.isConstant())
  • trunk/Source/JavaScriptCore/dfg/DFGDesiredTransitions.cpp

    r190522 r190546  
    3535namespace JSC { namespace DFG {
    3636
    37 DesiredTransition::DesiredTransition(CodeBlock* codeBlock, CodeBlock* codeOriginOwner, Structure* oldStructure, Structure* newStructure)
     37DesiredTransition::DesiredTransition(CodeBlock* codeBlock, ScriptExecutable* codeOriginOwner, Structure* oldStructure, Structure* newStructure)
    3838    : m_codeBlock(codeBlock)
    3939    , m_codeOriginOwner(codeOriginOwner)
     
    4747    common->transitions.append(
    4848        WeakReferenceTransition(
    49             vm, m_codeBlock,
     49            vm, m_codeBlock->ownerExecutable(),
    5050            m_codeOriginOwner,
    5151            m_oldStructure, m_newStructure));
     
    6767}
    6868
    69 void DesiredTransitions::addLazily(CodeBlock* codeBlock, CodeBlock* codeOriginOwner, Structure* oldStructure, Structure* newStructure)
     69void DesiredTransitions::addLazily(CodeBlock* codeBlock, ScriptExecutable* codeOriginOwner, Structure* oldStructure, Structure* newStructure)
    7070{
    7171    m_transitions.append(DesiredTransition(codeBlock, codeOriginOwner, oldStructure, newStructure));
  • trunk/Source/JavaScriptCore/dfg/DFGDesiredTransitions.h

    r190522 r190546  
    4545class DesiredTransition {
    4646public:
    47     DesiredTransition(CodeBlock*, CodeBlock* codeOriginOwner, Structure*, Structure*);
     47    DesiredTransition(CodeBlock*, ScriptExecutable*, Structure*, Structure*);
    4848
    4949    void reallyAdd(VM&, CommonData*);
     
    5353private:
    5454    CodeBlock* m_codeBlock;
    55     CodeBlock* m_codeOriginOwner;
     55    ScriptExecutable* m_codeOriginOwner;
    5656    Structure* m_oldStructure;
    5757    Structure* m_newStructure;
     
    6363    ~DesiredTransitions();
    6464
    65     void addLazily(CodeBlock*, CodeBlock* codeOriginOwner, Structure*, Structure*);
     65    void addLazily(CodeBlock*, ScriptExecutable*, Structure*, Structure*);
    6666    void reallyAdd(VM&, CommonData*);
    6767    void visitChildren(SlotVisitor&);
  • trunk/Source/JavaScriptCore/dfg/DFGDesiredWeakReferences.cpp

    r190522 r190546  
    7171        if (Structure* structure = jsDynamicCast<Structure*>(target)) {
    7272            common->weakStructureReferences.append(
    73                 WriteBarrier<Structure>(vm, m_codeBlock, structure));
     73                WriteBarrier<Structure>(vm, m_codeBlock->ownerExecutable(), structure));
    7474        } else {
    7575            common->weakReferences.append(
    76                 WriteBarrier<JSCell>(vm, m_codeBlock, target));
     76                WriteBarrier<JSCell>(vm, m_codeBlock->ownerExecutable(), target));
    7777        }
    7878    }
  • trunk/Source/JavaScriptCore/dfg/DFGDriver.cpp

    r190522 r190546  
    122122        callback);
    123123    if (result != CompilationDeferred)
    124         callback->compilationDidComplete(codeBlock, profiledDFGCodeBlock, result);
     124        callback->compilationDidComplete(codeBlock, result);
    125125    return result;
    126126}
  • trunk/Source/JavaScriptCore/dfg/DFGGraph.cpp

    r190522 r190546  
    6262    : m_vm(vm)
    6363    , m_plan(plan)
    64     , m_codeBlock(m_plan.codeBlock)
     64    , m_codeBlock(m_plan.codeBlock.get())
    6565    , m_profiledBlock(m_codeBlock->alternative())
    6666    , m_allocator(longLivedState.m_allocator)
  • trunk/Source/JavaScriptCore/dfg/DFGGraph.h

    r190522 r190546  
    349349            return m_codeBlock->ownerScriptExecutable();
    350350       
    351         return inlineCallFrame->baselineCodeBlock->ownerScriptExecutable();
     351        return inlineCallFrame->executable.get();
    352352    }
    353353   
     
    373373        if (!codeOrigin.inlineCallFrame)
    374374            return m_codeBlock->isStrictMode();
    375         return codeOrigin.inlineCallFrame->isStrictMode();
     375        return jsCast<FunctionExecutable*>(codeOrigin.inlineCallFrame->executable.get())->isStrictMode();
    376376    }
    377377   
  • trunk/Source/JavaScriptCore/dfg/DFGJITCode.h

    r190522 r190546  
    2929#if ENABLE(DFG_JIT)
    3030
    31 #include "CodeBlock.h"
    3231#include "CompilationResult.h"
    3332#include "DFGCommonData.h"
     
    116115   
    117116    void shrinkToFit();
    118 
    119 #if ENABLE(FTL_JIT)
    120     CodeBlock* osrEntryBlock() { return m_osrEntryBlock.get(); }
    121     void setOSREntryBlock(VM& vm, const JSCell* owner, CodeBlock* osrEntryBlock) { m_osrEntryBlock.set(vm, owner, osrEntryBlock); }
    122     void clearOSREntryBlock() { m_osrEntryBlock.clear(); }
    123 #endif
    124117   
    125118private:
     
    136129    uint8_t nestedTriggerIsSet { 0 };
    137130    UpperTierExecutionCounter tierUpCounter;
    138     WriteBarrier<CodeBlock> m_osrEntryBlock;
     131    RefPtr<CodeBlock> osrEntryBlock;
    139132    unsigned osrEntryRetry;
    140133    bool abandonOSREntry;
  • trunk/Source/JavaScriptCore/dfg/DFGJITFinalizer.cpp

    r190522 r190546  
    5858{
    5959    m_jitCode->initializeCodeRef(
    60         FINALIZE_DFG_CODE(*m_linkBuffer, ("DFG JIT code for %s", toCString(CodeBlockWithJITType(m_plan.codeBlock, JITCode::DFGJIT)).data())),
     60        FINALIZE_DFG_CODE(*m_linkBuffer, ("DFG JIT code for %s", toCString(CodeBlockWithJITType(m_plan.codeBlock.get(), JITCode::DFGJIT)).data())),
    6161        MacroAssemblerCodePtr());
    6262   
     
    7272    RELEASE_ASSERT(!m_withArityCheck.isEmptyValue());
    7373    m_jitCode->initializeCodeRef(
    74         FINALIZE_DFG_CODE(*m_linkBuffer, ("DFG JIT code for %s", toCString(CodeBlockWithJITType(m_plan.codeBlock, JITCode::DFGJIT)).data())),
     74        FINALIZE_DFG_CODE(*m_linkBuffer, ("DFG JIT code for %s", toCString(CodeBlockWithJITType(m_plan.codeBlock.get(), JITCode::DFGJIT)).data())),
    7575        m_withArityCheck);
    7676    m_plan.codeBlock->setJITCode(m_jitCode);
     
    8484{
    8585#if ENABLE(FTL_JIT)
    86     m_jitCode->optimizeAfterWarmUp(m_plan.codeBlock);
     86    m_jitCode->optimizeAfterWarmUp(m_plan.codeBlock.get());
    8787#endif // ENABLE(FTL_JIT)
    8888   
  • trunk/Source/JavaScriptCore/dfg/DFGOSRExitCompilerCommon.cpp

    r190522 r190546  
    7070                AssemblyHelpers::NonZero,
    7171                AssemblyHelpers::AbsoluteAddress(
    72                     inlineCallFrame->baselineCodeBlock->ownerScriptExecutable()->addressOfDidTryToEnterInLoop())));
     72                    inlineCallFrame->executable->addressOfDidTryToEnterInLoop())));
    7373    }
    7474   
     
    269269void adjustAndJumpToTarget(CCallHelpers& jit, const OSRExitBase& exit, bool isExitingToOpCatch)
    270270{
    271     CodeBlock* baselineCodeBlock = jit.baselineCodeBlockFor(exit.m_codeOrigin);
    272     jit.move(AssemblyHelpers::TrustedImmPtr(baselineCodeBlock), GPRInfo::argumentGPR1);
     271    jit.move(AssemblyHelpers::TrustedImmPtr(jit.codeBlock()->ownerExecutable()), GPRInfo::argumentGPR1);
    273272    osrWriteBarrier(jit, GPRInfo::argumentGPR1, GPRInfo::nonArgGPR0);
    274273    InlineCallFrameSet* inlineCallFrames = jit.codeBlock()->jitCode()->dfgCommon()->inlineCallFrames.get();
    275274    if (inlineCallFrames) {
    276275        for (InlineCallFrame* inlineCallFrame : *inlineCallFrames) {
    277             CodeBlock* baselineCodeBlock = inlineCallFrame->baselineCodeBlock.get();
    278             jit.move(AssemblyHelpers::TrustedImmPtr(baselineCodeBlock), GPRInfo::argumentGPR1);
     276            ScriptExecutable* ownerExecutable = inlineCallFrame->executable.get();
     277            jit.move(AssemblyHelpers::TrustedImmPtr(ownerExecutable), GPRInfo::argumentGPR1);
    279278            osrWriteBarrier(jit, GPRInfo::argumentGPR1, GPRInfo::nonArgGPR0);
    280279        }
     
    284283        jit.addPtr(AssemblyHelpers::TrustedImm32(exit.m_codeOrigin.inlineCallFrame->stackOffset * sizeof(EncodedJSValue)), GPRInfo::callFrameRegister);
    285284
     285    CodeBlock* baselineCodeBlock = jit.baselineCodeBlockFor(exit.m_codeOrigin);
    286286    Vector<BytecodeAndMachineOffset>& decodedCodeMap = jit.decodedCodeMapFor(baselineCodeBlock);
    287287   
  • trunk/Source/JavaScriptCore/dfg/DFGOSRExitPreparation.cpp

    r190522 r190546  
    4343   
    4444    for (; codeOrigin.inlineCallFrame; codeOrigin = codeOrigin.inlineCallFrame->directCaller) {
    45         CodeBlock* codeBlock = codeOrigin.inlineCallFrame->baselineCodeBlock.get();
     45        CodeBlock* codeBlock = codeOrigin.inlineCallFrame->baselineCodeBlock();
    4646        if (codeBlock->jitType() == JSC::JITCode::BaselineJIT)
    4747            continue;
  • trunk/Source/JavaScriptCore/dfg/DFGOperations.cpp

    r190522 r190546  
    13081308    bool didTryToEnterIntoInlinedLoops = false;
    13091309    for (InlineCallFrame* inlineCallFrame = exit->m_codeOrigin.inlineCallFrame; inlineCallFrame; inlineCallFrame = inlineCallFrame->directCaller.inlineCallFrame) {
    1310         if (inlineCallFrame->baselineCodeBlock->ownerScriptExecutable()->didTryToEnterInLoop()) {
     1310        if (inlineCallFrame->executable->didTryToEnterInLoop()) {
    13111311            didTryToEnterIntoInlinedLoops = true;
    13121312            break;
     
    13781378    // We need to compile the code.
    13791379    compile(
    1380         *vm, codeBlock->newReplacement(), codeBlock, FTLMode, UINT_MAX,
    1381         Operands<JSValue>(), ToFTLDeferredCompilationCallback::create());
     1380        *vm, codeBlock->newReplacement().get(), codeBlock, FTLMode, UINT_MAX,
     1381        Operands<JSValue>(), ToFTLDeferredCompilationCallback::create(codeBlock));
    13821382}
    13831383
     
    14641464        return 0;
    14651465   
    1466     if (CodeBlock* entryBlock = jitCode->osrEntryBlock()) {
     1466    if (CodeBlock* entryBlock = jitCode->osrEntryBlock.get()) {
    14671467        void* address = FTL::prepareOSREntry(
    14681468            exec, codeBlock, entryBlock, bytecodeIndex, streamIndex);
     
    14781478        // OSR entry failed. Oh no! This implies that we need to retry. We retry
    14791479        // without exponential backoff and we only do this for the entry code block.
    1480         jitCode->clearOSREntryBlock();
     1480        jitCode->osrEntryBlock = nullptr;
    14811481        jitCode->osrEntryRetry = 0;
    14821482        return 0;
     
    14951495    jitCode->reconstruct(
    14961496        exec, codeBlock, CodeOrigin(bytecodeIndex), streamIndex, mustHandleValues);
    1497     CodeBlock* replacementCodeBlock = codeBlock->newReplacement();
     1497    RefPtr<CodeBlock> replacementCodeBlock = codeBlock->newReplacement();
    14981498    CompilationResult forEntryResult = compile(
    1499         *vm, replacementCodeBlock, codeBlock, FTLForOSREntryMode, bytecodeIndex,
    1500         mustHandleValues, ToFTLForOSREntryDeferredCompilationCallback::create());
    1501    
    1502     if (forEntryResult != CompilationSuccessful)
     1499        *vm, replacementCodeBlock.get(), codeBlock, FTLForOSREntryMode, bytecodeIndex,
     1500        mustHandleValues, ToFTLForOSREntryDeferredCompilationCallback::create(codeBlock));
     1501   
     1502    if (forEntryResult != CompilationSuccessful) {
     1503        ASSERT(forEntryResult == CompilationDeferred || replacementCodeBlock->hasOneRef());
    15031504        return 0;
     1505    }
    15041506
    15051507    // It's possible that the for-entry compile already succeeded. In that case OSR
     
    15071509    // We signal to try again after a while if that happens.
    15081510    void* address = FTL::prepareOSREntry(
    1509         exec, codeBlock, jitCode->osrEntryBlock(), bytecodeIndex, streamIndex);
     1511        exec, codeBlock, jitCode->osrEntryBlock.get(), bytecodeIndex, streamIndex);
    15101512    return static_cast<char*>(address);
    15111513}
  • trunk/Source/JavaScriptCore/dfg/DFGPlan.cpp

    r190522 r190546  
    132132} // anonymous namespace
    133133
    134 Plan::Plan(CodeBlock* passedCodeBlock, CodeBlock* profiledDFGCodeBlock,
     134Plan::Plan(PassRefPtr<CodeBlock> passedCodeBlock, CodeBlock* profiledDFGCodeBlock,
    135135    CompilationMode mode, unsigned osrEntryBytecodeIndex,
    136136    const Operands<JSValue>& mustHandleValues)
     
    141141    , osrEntryBytecodeIndex(osrEntryBytecodeIndex)
    142142    , mustHandleValues(mustHandleValues)
    143     , compilation(codeBlock->vm()->m_perBytecodeProfiler ? adoptRef(new Profiler::Compilation(codeBlock->vm()->m_perBytecodeProfiler->ensureBytecodesFor(codeBlock), profilerCompilationKindForMode(mode))) : 0)
     143    , compilation(codeBlock->vm()->m_perBytecodeProfiler ? adoptRef(new Profiler::Compilation(codeBlock->vm()->m_perBytecodeProfiler->ensureBytecodesFor(codeBlock.get()), profilerCompilationKindForMode(mode))) : 0)
    144144    , inlineCallFrames(adoptRef(new InlineCallFrameSet()))
    145     , identifiers(codeBlock)
    146     , weakReferences(codeBlock)
     145    , identifiers(codeBlock.get())
     146    , weakReferences(codeBlock.get())
    147147    , willTryToTierUp(false)
    148148    , stage(Preparing)
     
    536536void Plan::reallyAdd(CommonData* commonData)
    537537{
    538     watchpoints.reallyAdd(codeBlock, *commonData);
     538    watchpoints.reallyAdd(codeBlock.get(), *commonData);
    539539    identifiers.reallyAdd(vm, commonData);
    540540    weakReferences.reallyAdd(vm, commonData);
     
    554554void Plan::notifyReady()
    555555{
    556     callback->compilationDidBecomeReadyAsynchronously(codeBlock, profiledDFGCodeBlock);
     556    callback->compilationDidBecomeReadyAsynchronously(codeBlock.get());
    557557    stage = Ready;
    558558}
     
    561561{
    562562    // We will establish new references from the code block to things. So, we need a barrier.
    563     vm.heap.writeBarrier(codeBlock);
     563    vm.heap.writeBarrier(codeBlock->ownerExecutable());
    564564   
    565565    if (!isStillValid())
     
    597597void Plan::finalizeAndNotifyCallback()
    598598{
    599     callback->compilationDidComplete(codeBlock, profiledDFGCodeBlock, finalizeWithoutNotifyingCallback());
     599    callback->compilationDidComplete(codeBlock.get(), finalizeWithoutNotifyingCallback());
    600600}
    601601
     
    605605}
    606606
    607 void Plan::rememberCodeBlocks()
     607void Plan::clearCodeBlockMarks()
    608608{
    609609    // Compilation writes lots of values to a CodeBlock without performing
     
    611611    // all our CodeBlocks must be visited during GC.
    612612
    613     Heap::heap(codeBlock)->writeBarrier(codeBlock);
     613    codeBlock->clearMarks();
     614    codeBlock->alternative()->clearMarks();
    614615    if (profiledDFGCodeBlock)
    615         Heap::heap(profiledDFGCodeBlock)->writeBarrier(profiledDFGCodeBlock);
     616        profiledDFGCodeBlock->clearMarks();
    616617}
    617618
     
    624625        visitor.appendUnbarrieredValue(&mustHandleValues[i]);
    625626
    626     visitor.appendUnbarrieredReadOnlyPointer(codeBlock);
    627     visitor.appendUnbarrieredReadOnlyPointer(profiledDFGCodeBlock);
     627    codeBlock->visitStrongly(visitor);
     628    codeBlock->alternative()->visitStrongly(visitor);
     629    if (profiledDFGCodeBlock)
     630        profiledDFGCodeBlock->visitStrongly(visitor);
    628631
    629632    if (inlineCallFrames) {
    630633        for (auto* inlineCallFrame : *inlineCallFrames) {
    631             ASSERT(inlineCallFrame->baselineCodeBlock.get());
    632             visitor.appendUnbarrieredReadOnlyPointer(inlineCallFrame->baselineCodeBlock.get());
     634            ASSERT(inlineCallFrame->baselineCodeBlock());
     635            inlineCallFrame->baselineCodeBlock()->visitStrongly(visitor);
    633636        }
    634637    }
  • trunk/Source/JavaScriptCore/dfg/DFGPlan.h

    r190522 r190546  
    5656struct Plan : public ThreadSafeRefCounted<Plan> {
    5757    Plan(
    58         CodeBlock* codeBlockToCompile, CodeBlock* profiledDFGCodeBlock,
     58        PassRefPtr<CodeBlock> codeBlockToCompile, CodeBlock* profiledDFGCodeBlock,
    5959        CompilationMode, unsigned osrEntryBytecodeIndex,
    6060        const Operands<JSValue>& mustHandleValues);
     
    7272    CompilationKey key();
    7373   
    74     void rememberCodeBlocks();
     74    void clearCodeBlockMarks();
    7575    void checkLivenessAndVisitChildren(SlotVisitor&);
    7676    bool isKnownToBeLiveDuringGC();
     
    7878   
    7979    VM& vm;
    80 
    81     // These can be raw pointers because we visit them during every GC in checkLivenessAndVisitChildren.
    82     CodeBlock* codeBlock;
    83     CodeBlock* profiledDFGCodeBlock;
    84 
     80    RefPtr<CodeBlock> codeBlock;
     81    RefPtr<CodeBlock> profiledDFGCodeBlock;
    8582    CompilationMode mode;
    8683    const unsigned osrEntryBytecodeIndex;
  • trunk/Source/JavaScriptCore/dfg/DFGToFTLDeferredCompilationCallback.cpp

    r190522 r190546  
    3636namespace JSC { namespace DFG {
    3737
    38 ToFTLDeferredCompilationCallback::ToFTLDeferredCompilationCallback()
     38ToFTLDeferredCompilationCallback::ToFTLDeferredCompilationCallback(
     39    PassRefPtr<CodeBlock> dfgCodeBlock)
     40    : m_dfgCodeBlock(dfgCodeBlock)
    3941{
    4042}
     
    4244ToFTLDeferredCompilationCallback::~ToFTLDeferredCompilationCallback() { }
    4345
    44 Ref<ToFTLDeferredCompilationCallback> ToFTLDeferredCompilationCallback::create()
     46Ref<ToFTLDeferredCompilationCallback> ToFTLDeferredCompilationCallback::create(PassRefPtr<CodeBlock> dfgCodeBlock)
    4547{
    46     return adoptRef(*new ToFTLDeferredCompilationCallback());
     48    return adoptRef(*new ToFTLDeferredCompilationCallback(dfgCodeBlock));
    4749}
    4850
    4951void ToFTLDeferredCompilationCallback::compilationDidBecomeReadyAsynchronously(
    50     CodeBlock* codeBlock, CodeBlock* profiledDFGCodeBlock)
     52    CodeBlock* codeBlock)
    5153{
    5254    if (Options::verboseOSR()) {
    5355        dataLog(
    54             "Optimizing compilation of ", *codeBlock, " (for ", *profiledDFGCodeBlock,
     56            "Optimizing compilation of ", *codeBlock, " (for ", *m_dfgCodeBlock,
    5557            ") did become ready.\n");
    5658    }
    5759   
    58     profiledDFGCodeBlock->jitCode()->dfg()->forceOptimizationSlowPathConcurrently(
    59         profiledDFGCodeBlock);
     60    m_dfgCodeBlock->jitCode()->dfg()->forceOptimizationSlowPathConcurrently(
     61        m_dfgCodeBlock.get());
    6062}
    6163
    6264void ToFTLDeferredCompilationCallback::compilationDidComplete(
    63     CodeBlock* codeBlock, CodeBlock* profiledDFGCodeBlock, CompilationResult result)
     65    CodeBlock* codeBlock, CompilationResult result)
    6466{
    6567    if (Options::verboseOSR()) {
    6668        dataLog(
    67             "Optimizing compilation of ", *codeBlock, " (for ", *profiledDFGCodeBlock,
     69            "Optimizing compilation of ", *codeBlock, " (for ", *m_dfgCodeBlock,
    6870            ") result: ", result, "\n");
    6971    }
    7072   
    71     if (profiledDFGCodeBlock->replacement() != profiledDFGCodeBlock) {
     73    if (m_dfgCodeBlock->replacement() != m_dfgCodeBlock) {
    7274        if (Options::verboseOSR()) {
    7375            dataLog(
    7476                "Dropping FTL code block ", *codeBlock, " on the floor because the "
    75                 "DFG code block ", *profiledDFGCodeBlock, " was jettisoned.\n");
     77                "DFG code block ", *m_dfgCodeBlock, " was jettisoned.\n");
    7678        }
    7779        return;
     
    8183        codeBlock->ownerScriptExecutable()->installCode(codeBlock);
    8284   
    83     profiledDFGCodeBlock->jitCode()->dfg()->setOptimizationThresholdBasedOnCompilationResult(
    84         profiledDFGCodeBlock, result);
     85    m_dfgCodeBlock->jitCode()->dfg()->setOptimizationThresholdBasedOnCompilationResult(
     86        m_dfgCodeBlock.get(), result);
    8587
    86     DeferredCompilationCallback::compilationDidComplete(codeBlock, profiledDFGCodeBlock, result);
     88    DeferredCompilationCallback::compilationDidComplete(codeBlock, result);
    8789}
    8890
  • trunk/Source/JavaScriptCore/dfg/DFGToFTLDeferredCompilationCallback.h

    r190522 r190546  
    4141class ToFTLDeferredCompilationCallback : public DeferredCompilationCallback {
    4242protected:
    43     ToFTLDeferredCompilationCallback();
     43    ToFTLDeferredCompilationCallback(PassRefPtr<CodeBlock> dfgCodeBlock);
    4444
    4545public:
    4646    virtual ~ToFTLDeferredCompilationCallback();
    4747
    48     static Ref<ToFTLDeferredCompilationCallback> create();
     48    static Ref<ToFTLDeferredCompilationCallback> create(PassRefPtr<CodeBlock> dfgCodeBlock);
    4949   
    50     virtual void compilationDidBecomeReadyAsynchronously(CodeBlock*, CodeBlock* profiledDFGCodeBlock);
    51     virtual void compilationDidComplete(CodeBlock*, CodeBlock* profiledDFGCodeBlock, CompilationResult);
     50    virtual void compilationDidBecomeReadyAsynchronously(CodeBlock*);
     51    virtual void compilationDidComplete(CodeBlock*, CompilationResult);
     52
     53private:
     54    RefPtr<CodeBlock> m_dfgCodeBlock;
    5255};
    5356
  • trunk/Source/JavaScriptCore/dfg/DFGToFTLForOSREntryDeferredCompilationCallback.cpp

    r190522 r190546  
    3636namespace JSC { namespace DFG {
    3737
    38 ToFTLForOSREntryDeferredCompilationCallback::ToFTLForOSREntryDeferredCompilationCallback()
     38ToFTLForOSREntryDeferredCompilationCallback::ToFTLForOSREntryDeferredCompilationCallback(
     39    PassRefPtr<CodeBlock> dfgCodeBlock)
     40    : m_dfgCodeBlock(dfgCodeBlock)
    3941{
    4042}
     
    4446}
    4547
    46 Ref<ToFTLForOSREntryDeferredCompilationCallback>ToFTLForOSREntryDeferredCompilationCallback::create()
     48Ref<ToFTLForOSREntryDeferredCompilationCallback>ToFTLForOSREntryDeferredCompilationCallback::create(
     49    PassRefPtr<CodeBlock> dfgCodeBlock)
    4750{
    48     return adoptRef(*new ToFTLForOSREntryDeferredCompilationCallback());
     51    return adoptRef(*new ToFTLForOSREntryDeferredCompilationCallback(dfgCodeBlock));
    4952}
    5053
    5154void ToFTLForOSREntryDeferredCompilationCallback::compilationDidBecomeReadyAsynchronously(
    52     CodeBlock* codeBlock, CodeBlock* profiledDFGCodeBlock)
     55    CodeBlock* codeBlock)
    5356{
    5457    if (Options::verboseOSR()) {
    5558        dataLog(
    56             "Optimizing compilation of ", *codeBlock, " (for ", *profiledDFGCodeBlock,
     59            "Optimizing compilation of ", *codeBlock, " (for ", *m_dfgCodeBlock,
    5760            ") did become ready.\n");
    5861    }
    5962   
    60     profiledDFGCodeBlock->jitCode()->dfg()->forceOptimizationSlowPathConcurrently(
    61         profiledDFGCodeBlock);
     63    m_dfgCodeBlock->jitCode()->dfg()->forceOptimizationSlowPathConcurrently(
     64        m_dfgCodeBlock.get());
    6265}
    6366
    6467void ToFTLForOSREntryDeferredCompilationCallback::compilationDidComplete(
    65     CodeBlock* codeBlock, CodeBlock* profiledDFGCodeBlock, CompilationResult result)
     68    CodeBlock* codeBlock, CompilationResult result)
    6669{
    6770    if (Options::verboseOSR()) {
    6871        dataLog(
    69             "Optimizing compilation of ", *codeBlock, " (for ", *profiledDFGCodeBlock,
     72            "Optimizing compilation of ", *codeBlock, " (for ", *m_dfgCodeBlock,
    7073            ") result: ", result, "\n");
    7174    }
    7275   
    73     JITCode* jitCode = profiledDFGCodeBlock->jitCode()->dfg();
     76    JITCode* jitCode = m_dfgCodeBlock->jitCode()->dfg();
    7477       
    7578    switch (result) {
    7679    case CompilationSuccessful:
    77         jitCode->setOSREntryBlock(*codeBlock->vm(), profiledDFGCodeBlock, codeBlock);
     80        jitCode->osrEntryBlock = codeBlock;
    7881        break;
    7982    case CompilationFailed:
     
    8891    }
    8992   
    90     DeferredCompilationCallback::compilationDidComplete(codeBlock, profiledDFGCodeBlock, result);
     93    DeferredCompilationCallback::compilationDidComplete(codeBlock, result);
    9194}
    9295
  • trunk/Source/JavaScriptCore/dfg/DFGToFTLForOSREntryDeferredCompilationCallback.h

    r190522 r190546  
    4141class ToFTLForOSREntryDeferredCompilationCallback : public DeferredCompilationCallback {
    4242protected:
    43     ToFTLForOSREntryDeferredCompilationCallback();
     43    ToFTLForOSREntryDeferredCompilationCallback(PassRefPtr<CodeBlock> dfgCodeBlock);
    4444
    4545public:
    4646    virtual ~ToFTLForOSREntryDeferredCompilationCallback();
    4747
    48     static Ref<ToFTLForOSREntryDeferredCompilationCallback> create();
     48    static Ref<ToFTLForOSREntryDeferredCompilationCallback> create(PassRefPtr<CodeBlock> dfgCodeBlock);
    4949   
    50     virtual void compilationDidBecomeReadyAsynchronously(CodeBlock*, CodeBlock* profiledDFGCodeBlock);
    51     virtual void compilationDidComplete(CodeBlock*, CodeBlock* profiledDFGCodeBlock, CompilationResult);
     50    virtual void compilationDidBecomeReadyAsynchronously(CodeBlock*);
     51    virtual void compilationDidComplete(CodeBlock*, CompilationResult);
     52
     53private:
     54    RefPtr<CodeBlock> m_dfgCodeBlock;
    5255};
    5356
  • trunk/Source/JavaScriptCore/dfg/DFGWorklist.cpp

    r190522 r190546  
    208208}
    209209
    210 void Worklist::rememberCodeBlocks(VM& vm)
     210void Worklist::clearCodeBlockMarks(VM& vm)
    211211{
    212212    LockHolder locker(m_lock);
     
    215215        if (&plan->vm != &vm)
    216216            continue;
    217         plan->rememberCodeBlocks();
     217        plan->clearCodeBlockMarks();
    218218    }
    219219}
     
    468468}
    469469
    470 void rememberCodeBlocks(VM& vm)
     470void clearCodeBlockMarks(VM& vm)
    471471{
    472472    for (unsigned i = DFG::numberOfWorklists(); i--;) {
    473473        if (DFG::Worklist* worklist = DFG::worklistForIndexOrNull(i))
    474             worklist->rememberCodeBlocks(vm);
     474            worklist->clearCodeBlockMarks(vm);
    475475    }
    476476}
  • trunk/Source/JavaScriptCore/dfg/DFGWorklist.h

    r190522 r190546  
    5858    void completeAllPlansForVM(VM&);
    5959
    60     void rememberCodeBlocks(VM&);
     60    void clearCodeBlockMarks(VM&);
    6161
    6262    void waitUntilAllPlansForVMAreReady(VM&);
     
    142142
    143143void completeAllPlansForVM(VM&);
    144 void rememberCodeBlocks(VM&);
     144void clearCodeBlockMarks(VM&);
    145145
    146146} } // namespace JSC::DFG
  • trunk/Source/JavaScriptCore/ftl/FTLJITFinalizer.cpp

    r190522 r190546  
    100100            FINALIZE_DFG_CODE(
    101101                *exitThunksLinkBuffer,
    102                 ("FTL exit thunks for %s", toCString(CodeBlockWithJITType(m_plan.codeBlock, JITCode::FTLJIT)).data())));
     102                ("FTL exit thunks for %s", toCString(CodeBlockWithJITType(m_plan.codeBlock.get(), JITCode::FTLJIT)).data())));
    103103    } // else this function had no OSR exits, so no exit thunks.
    104104   
     
    117117            *sideCodeLinkBuffer,
    118118            ("FTL side code for %s",
    119                 toCString(CodeBlockWithJITType(m_plan.codeBlock, JITCode::FTLJIT)).data()))
     119                toCString(CodeBlockWithJITType(m_plan.codeBlock.get(), JITCode::FTLJIT)).data()))
    120120            .executableMemory());
    121121    }
     
    125125            *handleExceptionsLinkBuffer,
    126126            ("FTL exception handler for %s",
    127                 toCString(CodeBlockWithJITType(m_plan.codeBlock, JITCode::FTLJIT)).data()))
     127                toCString(CodeBlockWithJITType(m_plan.codeBlock.get(), JITCode::FTLJIT)).data()))
    128128            .executableMemory());
    129129    }
     
    138138        FINALIZE_DFG_CODE(
    139139            *entrypointLinkBuffer,
    140             ("FTL entrypoint thunk for %s with LLVM generated code at %p", toCString(CodeBlockWithJITType(m_plan.codeBlock, JITCode::FTLJIT)).data(), function)));
     140            ("FTL entrypoint thunk for %s with LLVM generated code at %p", toCString(CodeBlockWithJITType(m_plan.codeBlock.get(), JITCode::FTLJIT)).data(), function)));
    141141   
    142142    m_plan.codeBlock->setJITCode(jitCode);
  • trunk/Source/JavaScriptCore/heap/CodeBlockSet.cpp

    r190522 r190546  
    4242CodeBlockSet::~CodeBlockSet()
    4343{
     44    for (CodeBlock* codeBlock : m_oldCodeBlocks)
     45        codeBlock->deref();
     46
     47    for (CodeBlock* codeBlock : m_newCodeBlocks)
     48        codeBlock->deref();
    4449}
    4550
    46 void CodeBlockSet::add(CodeBlock* codeBlock)
     51void CodeBlockSet::add(PassRefPtr<CodeBlock> codeBlock)
    4752{
    48     bool isNewEntry = m_newCodeBlocks.add(codeBlock).isNewEntry;
     53    CodeBlock* block = codeBlock.leakRef();
     54    bool isNewEntry = m_newCodeBlocks.add(block).isNewEntry;
    4955    ASSERT_UNUSED(isNewEntry, isNewEntry);
    5056}
     
    5965{
    6066    for (CodeBlock* codeBlock : m_oldCodeBlocks)
    61         codeBlock->clearVisitWeaklyHasBeenCalled();
     67        codeBlock->clearMarks();
    6268
    6369    // We promote after we clear marks on the old generation CodeBlocks because
     
    6672}
    6773
     74void CodeBlockSet::clearMarksForEdenCollection(const Vector<const JSCell*>& rememberedSet)
     75{
     76    // This ensures that we will revisit CodeBlocks in remembered Executables even if they were previously marked.
     77    for (const JSCell* cell : rememberedSet) {
     78        ScriptExecutable* executable = const_cast<ScriptExecutable*>(jsDynamicCast<const ScriptExecutable*>(cell));
     79        if (!executable)
     80            continue;
     81        executable->forEachCodeBlock([this](CodeBlock* codeBlock) {
     82            codeBlock->clearMarks();
     83            m_remembered.add(codeBlock);
     84        });
     85    }
     86}
     87
    6888void CodeBlockSet::deleteUnmarkedAndUnreferenced(HeapOperation collectionType)
    6989{
    7090    HashSet<CodeBlock*>& set = collectionType == EdenCollection ? m_newCodeBlocks : m_oldCodeBlocks;
    71     Vector<CodeBlock*> unmarked;
    72     for (CodeBlock* codeBlock : set) {
    73         if (Heap::isMarked(codeBlock))
    74             continue;
    75         unmarked.append(codeBlock);
    76     }
    7791
    78     for (CodeBlock* codeBlock : unmarked) {
    79         codeBlock->classInfo()->methodTable.destroy(codeBlock);
    80         set.remove(codeBlock);
     92    // This needs to be a fixpoint because code blocks that are unmarked may
     93    // refer to each other. For example, a DFG code block that is owned by
     94    // the GC may refer to an FTL for-entry code block that is also owned by
     95    // the GC.
     96    Vector<CodeBlock*, 16> toRemove;
     97    if (verbose)
     98        dataLog("Fixpointing over unmarked, set size = ", set.size(), "...\n");
     99    for (;;) {
     100        for (CodeBlock* codeBlock : set) {
     101            if (!codeBlock->hasOneRef())
     102                continue;
     103            codeBlock->deref();
     104            toRemove.append(codeBlock);
     105        }
     106        if (verbose)
     107            dataLog("    Removing ", toRemove.size(), " blocks.\n");
     108        if (toRemove.isEmpty())
     109            break;
     110        for (CodeBlock* codeBlock : toRemove)
     111            set.remove(codeBlock);
     112        toRemove.resize(0);
    81113    }
    82114
     
    88120void CodeBlockSet::remove(CodeBlock* codeBlock)
    89121{
     122    codeBlock->deref();
    90123    if (m_oldCodeBlocks.contains(codeBlock)) {
    91124        m_oldCodeBlocks.remove(codeBlock);
     
    96129}
    97130
     131void CodeBlockSet::traceMarked(SlotVisitor& visitor)
     132{
     133    if (verbose)
     134        dataLog("Tracing ", m_currentlyExecuting.size(), " code blocks.\n");
     135
     136    // We strongly visit the currently executing set because jettisoning code
     137    // is not valuable once it's on the stack. We're past the point where
     138    // jettisoning would avoid the cost of OSR exit.
     139    for (const RefPtr<CodeBlock>& codeBlock : m_currentlyExecuting)
     140        codeBlock->visitStrongly(visitor);
     141
     142    // We strongly visit the remembered set because jettisoning old code during
     143    // Eden GC is unsound. There might be an old object with a strong reference
     144    // to the code.
     145    for (const RefPtr<CodeBlock>& codeBlock : m_remembered)
     146        codeBlock->visitStrongly(visitor);
     147}
     148
    98149void CodeBlockSet::rememberCurrentlyExecutingCodeBlocks(Heap* heap)
    99150{
    100151    if (verbose)
    101152        dataLog("Remembering ", m_currentlyExecuting.size(), " code blocks.\n");
    102     for (CodeBlock* codeBlock : m_currentlyExecuting)
    103         heap->addToRememberedSet(codeBlock);
     153    for (const RefPtr<CodeBlock>& codeBlock : m_currentlyExecuting)
     154        heap->addToRememberedSet(codeBlock->ownerExecutable());
     155
     156    // It's safe to clear these RefPtr sets because we won't delete the CodeBlocks
     157    // in them until the next GC, and we'll recompute them at that time.
    104158    m_currentlyExecuting.clear();
     159    m_remembered.clear();
    105160}
    106161
     
    117172    out.print("], currentlyExecuting = [");
    118173    comma = CommaPrinter();
    119     for (CodeBlock* codeBlock : m_currentlyExecuting)
    120         out.print(comma, pointerDump(codeBlock));
     174    for (const RefPtr<CodeBlock>& codeBlock : m_currentlyExecuting)
     175        out.print(comma, pointerDump(codeBlock.get()));
    121176    out.print("]}");
    122177}
  • trunk/Source/JavaScriptCore/heap/CodeBlockSet.h

    r190522 r190546  
    5454   
    5555    // Add a CodeBlock. This is only called by CodeBlock constructors.
    56     void add(CodeBlock*);
     56    void add(PassRefPtr<CodeBlock>);
    5757   
     58    // Clear mark bits for certain CodeBlocks depending on the type of collection.
     59    void clearMarksForEdenCollection(const Vector<const JSCell*>&);
     60
    5861    // Clear all mark bits for all CodeBlocks.
    5962    void clearMarksForFullCollection();
     
    7073    void remove(CodeBlock*);
    7174   
     75    // Trace all marked code blocks. The CodeBlock is free to make use of
     76    // mayBeExecuting.
     77    void traceMarked(SlotVisitor&);
     78
    7279    // Add all currently executing CodeBlocks to the remembered set to be
    7380    // re-scanned during the next collection.
     
    98105    void promoteYoungCodeBlocks();
    99106
     107    // This is not a set of RefPtr<CodeBlock> because we need to be able to find
     108    // arbitrary bogus pointers. I could have written a thingy that had peek types
     109    // and all, but that seemed like overkill.
    100110    HashSet<CodeBlock*> m_oldCodeBlocks;
    101111    HashSet<CodeBlock*> m_newCodeBlocks;
    102     HashSet<CodeBlock*> m_currentlyExecuting;
     112    HashSet<RefPtr<CodeBlock>> m_currentlyExecuting;
     113    HashSet<RefPtr<CodeBlock>> m_remembered;
    103114};
    104115
  • trunk/Source/JavaScriptCore/heap/Heap.cpp

    r190527 r190546  
    521521    ASSERT(isValidThreadState(m_vm));
    522522
     523    Vector<const JSCell*> rememberedSet(m_slotVisitor.markStack().size());
     524    m_slotVisitor.markStack().fillVector(rememberedSet);
     525
     526#if ENABLE(DFG_JIT)
     527    DFG::clearCodeBlockMarks(*m_vm);
     528#endif
     529    if (m_operationInProgress == EdenCollection)
     530        m_codeBlocks.clearMarksForEdenCollection(rememberedSet);
     531    else
     532        m_codeBlocks.clearMarksForFullCollection();
     533
    523534    // We gather conservative roots before clearing mark bits because conservative
    524535    // gathering uses the mark bits to determine whether a reference is valid.
     
    528539    gatherScratchBufferRoots(conservativeRoots);
    529540
    530 #if ENABLE(DFG_JIT)
    531     DFG::rememberCodeBlocks(*m_vm);
    532 #endif
    533 
    534     if (m_operationInProgress == FullCollection) {
     541    clearLivenessData();
     542
     543    if (m_operationInProgress == FullCollection)
    535544        m_opaqueRoots.clear();
    536         m_slotVisitor.clearMarkStack();
    537     }
    538 
    539     Vector<const JSCell*> rememberedSet(m_slotVisitor.markStack().size());
    540     m_slotVisitor.markStack().fillVector(rememberedSet);
    541 
    542     clearLivenessData();
    543 
    544545
    545546    m_shouldHashCons = m_vm->haveEnoughNewStringsToHashCons();
     
    582583        ParallelModeEnabler enabler(m_slotVisitor);
    583584
    584         m_slotVisitor.donateAndDrain();
    585585        visitExternalRememberedSet();
    586586        visitSmallStrings();
     
    698698{
    699699    GCPHASE(ClearLivenessData);
    700     if (m_operationInProgress == FullCollection)
    701         m_codeBlocks.clearMarksForFullCollection();
    702 
    703700    m_objectSpace.clearNewlyAllocated();
    704701    m_objectSpace.clearMarks();
     
    822819{
    823820    GCPHASE(TraceCodeBlocksAndJITStubRoutines);
     821    m_codeBlocks.traceMarked(m_slotVisitor);
    824822    m_jitStubRoutines.traceMarkedStubRoutines(m_slotVisitor);
    825823
     
    966964    // we'll end up returning to deleted code.
    967965    RELEASE_ASSERT(!m_vm->entryScope);
    968     ASSERT(m_operationInProgress == NoOperation);
    969966
    970967    completeAllDFGPlans();
    971968
    972     for (ExecutableBase* executable : m_executables)
    973         executable->clearCode();
     969    for (ExecutableBase* current : m_executables) {
     970        if (!current->isFunctionExecutable())
     971            continue;
     972        static_cast<FunctionExecutable*>(current)->clearCode();
     973    }
     974
     975    ASSERT(m_operationInProgress == FullCollection || m_operationInProgress == NoOperation);
     976    m_codeBlocks.clearMarksForFullCollection();
     977    m_codeBlocks.deleteUnmarkedAndUnreferenced(FullCollection);
    974978}
    975979
     
    991995            continue;
    992996
    993         // Eagerly dereference the Executable's JITCode in order to run watchpoint
    994         // destructors. Otherwise, watchpoints might fire for deleted CodeBlocks.
    995         current->clearCode();
     997        // We do this because executable memory is limited on some platforms and because
     998        // CodeBlock requires eager finalization.
     999        ExecutableBase::clearCodeVirtual(current);
    9961000        std::swap(m_executables[i], m_executables.last());
    9971001        m_executables.removeLast();
     
    11471151    if (shouldDoFullCollection(collectionType)) {
    11481152        m_operationInProgress = FullCollection;
     1153        m_slotVisitor.clearMarkStack();
    11491154        m_shouldDoFullCollection = false;
    11501155        if (Options::logGC())
  • trunk/Source/JavaScriptCore/interpreter/Interpreter.cpp

    r190522 r190546  
    174174
    175175        ThisTDZMode thisTDZMode = callerCodeBlock->unlinkedCodeBlock()->constructorKind() == ConstructorKind::Derived ? ThisTDZMode::AlwaysCheck : ThisTDZMode::CheckIfNeeded;
    176         eval = callerCodeBlock->evalCodeCache().getSlow(callFrame, callerCodeBlock, callerCodeBlock->isStrictMode(), thisTDZMode, programSource, callerScopeChain);
     176        eval = callerCodeBlock->evalCodeCache().getSlow(callFrame, callerCodeBlock->ownerScriptExecutable(), callerCodeBlock->isStrictMode(), thisTDZMode, programSource, callerScopeChain);
    177177        if (!eval)
    178178            return jsUndefined();
  • trunk/Source/JavaScriptCore/interpreter/StackVisitor.cpp

    r190522 r190546  
    171171        else
    172172            m_frame.m_argumentCountIncludingThis = inlineCallFrame->arguments.size();
    173         m_frame.m_codeBlock = inlineCallFrame->baselineCodeBlock.get();
     173        m_frame.m_codeBlock = inlineCallFrame->baselineCodeBlock();
    174174        m_frame.m_bytecodeOffset = codeOrigin->bytecodeIndex;
    175175
  • trunk/Source/JavaScriptCore/jit/AssemblyHelpers.cpp

    r190522 r190546  
    3939        return m_codeBlock->ownerExecutable();
    4040   
    41     return codeOrigin.inlineCallFrame->baselineCodeBlock->ownerExecutable();
     41    return codeOrigin.inlineCallFrame->executable.get();
    4242}
    4343
  • trunk/Source/JavaScriptCore/jit/AssemblyHelpers.h

    r190522 r190546  
    10751075        if (!codeOrigin.inlineCallFrame)
    10761076            return codeBlock()->isStrictMode();
    1077         return codeOrigin.inlineCallFrame->isStrictMode();
     1077        return jsCast<FunctionExecutable*>(codeOrigin.inlineCallFrame->executable.get())->isStrictMode();
    10781078    }
    10791079   
  • trunk/Source/JavaScriptCore/jit/GCAwareJITStubRoutine.h

    r190522 r190546  
    116116// that codeBlock gets "executed" more than once.
    117117#define FINALIZE_CODE_FOR_GC_AWARE_STUB(codeBlock, patchBuffer, makesCalls, cell, dataLogFArguments) \
    118     (createJITStubRoutine(FINALIZE_CODE_FOR((codeBlock), (patchBuffer), dataLogFArguments), *(codeBlock)->vm(), (codeBlock), (makesCalls), (cell)))
     118    (createJITStubRoutine(FINALIZE_CODE_FOR((codeBlock), (patchBuffer), dataLogFArguments), *(codeBlock)->vm(), (codeBlock)->ownerExecutable(), (makesCalls), (cell)))
    119119
    120120} // namespace JSC
  • trunk/Source/JavaScriptCore/jit/JITCode.h

    r190522 r190546  
    122122    }
    123123
     124    static std::chrono::milliseconds timeToLive(JITType jitType)
     125    {
     126        switch (jitType) {
     127        case InterpreterThunk:
     128            return std::chrono::duration_cast<std::chrono::milliseconds>(
     129                std::chrono::seconds(5));
     130        case BaselineJIT:
     131            // Effectively 10 additional seconds, since BaselineJIT and
     132            // InterpreterThunk share a CodeBlock.
     133            return std::chrono::duration_cast<std::chrono::milliseconds>(
     134                std::chrono::seconds(15));
     135        case DFGJIT:
     136            return std::chrono::duration_cast<std::chrono::milliseconds>(
     137                std::chrono::seconds(20));
     138        case FTLJIT:
     139            return std::chrono::duration_cast<std::chrono::milliseconds>(
     140                std::chrono::seconds(60));
     141        default:
     142            return std::chrono::milliseconds::max();
     143        }
     144    }
     145
    124146    static bool isLowerTier(JITType expectedLower, JITType expectedHigher)
    125147    {
  • trunk/Source/JavaScriptCore/jit/JITOpcodes.cpp

    r190522 r190546  
    667667        emitInitRegister(virtualRegisterForLocal(j).offset());
    668668
    669     emitWriteBarrier(m_codeBlock);
     669    emitWriteBarrier(m_codeBlock->ownerExecutable());
    670670
    671671    emitEnterOptimizationCheck();
  • trunk/Source/JavaScriptCore/jit/JITOperations.cpp

    r190522 r190546  
    12741274        }
    12751275
    1276         CodeBlock* replacementCodeBlock = codeBlock->newReplacement();
     1276        RefPtr<CodeBlock> replacementCodeBlock = codeBlock->newReplacement();
    12771277        CompilationResult result = DFG::compile(
    1278             vm, replacementCodeBlock, nullptr, DFG::DFGMode, bytecodeIndex,
     1278            vm, replacementCodeBlock.get(), 0, DFG::DFGMode, bytecodeIndex,
    12791279            mustHandleValues, JITToDFGDeferredCompilationCallback::create());
    12801280       
    1281         if (result != CompilationSuccessful)
     1281        if (result != CompilationSuccessful) {
     1282            ASSERT(result == CompilationDeferred || replacementCodeBlock->hasOneRef());
    12821283            return encodeResult(0, 0);
     1284        }
    12831285    }
    12841286   
  • trunk/Source/JavaScriptCore/jit/JITToDFGDeferredCompilationCallback.cpp

    r190522 r190546  
    4444
    4545void JITToDFGDeferredCompilationCallback::compilationDidBecomeReadyAsynchronously(
    46     CodeBlock* codeBlock, CodeBlock* profiledDFGCodeBlock)
     46    CodeBlock* codeBlock)
    4747{
    48     ASSERT_UNUSED(profiledDFGCodeBlock, !profiledDFGCodeBlock);
    4948    ASSERT(codeBlock->alternative()->jitType() == JITCode::BaselineJIT);
    5049   
     
    5655
    5756void JITToDFGDeferredCompilationCallback::compilationDidComplete(
    58     CodeBlock* codeBlock, CodeBlock* profiledDFGCodeBlock, CompilationResult result)
     57    CodeBlock* codeBlock, CompilationResult result)
    5958{
    60     ASSERT(!profiledDFGCodeBlock);
    6159    ASSERT(codeBlock->alternative()->jitType() == JITCode::BaselineJIT);
    6260   
     
    6967    codeBlock->alternative()->setOptimizationThresholdBasedOnCompilationResult(result);
    7068
    71     DeferredCompilationCallback::compilationDidComplete(codeBlock, profiledDFGCodeBlock, result);
     69    DeferredCompilationCallback::compilationDidComplete(codeBlock, result);
    7270}
    7371
  • trunk/Source/JavaScriptCore/jit/JITToDFGDeferredCompilationCallback.h

    r190522 r190546  
    4545    static Ref<JITToDFGDeferredCompilationCallback> create();
    4646   
    47     virtual void compilationDidBecomeReadyAsynchronously(CodeBlock*, CodeBlock* profiledDFGCodeBlock) override;
    48     virtual void compilationDidComplete(CodeBlock*, CodeBlock* profiledDFGCodeBlock, CompilationResult) override;
     47    virtual void compilationDidBecomeReadyAsynchronously(CodeBlock*) override;
     48    virtual void compilationDidComplete(CodeBlock*, CompilationResult) override;
    4949};
    5050
  • trunk/Source/JavaScriptCore/jit/Repatch.cpp

    r190522 r190546  
    228228
    229229    CodeBlock* codeBlock = exec->codeBlock();
     230    ScriptExecutable* owner = codeBlock->ownerScriptExecutable();
    230231    VM& vm = exec->vm();
    231232
     
    233234
    234235    if (isJSArray(baseValue) && propertyName == exec->propertyNames().length)
    235         newCase = AccessCase::getLength(vm, codeBlock, AccessCase::ArrayLength);
     236        newCase = AccessCase::getLength(vm, owner, AccessCase::ArrayLength);
    236237    else if (isJSString(baseValue) && propertyName == exec->propertyNames().length)
    237         newCase = AccessCase::getLength(vm, codeBlock, AccessCase::StringLength);
     238        newCase = AccessCase::getLength(vm, owner, AccessCase::StringLength);
    238239    else {
    239240        if (!slot.isCacheable() && !slot.isUnset())
     
    266267            structure->startWatchingPropertyForReplacements(vm, slot.cachedOffset());
    267268            repatchByIdSelfAccess(codeBlock, stubInfo, structure, slot.cachedOffset(), operationGetByIdOptimize, true);
    268             stubInfo.initGetByIdSelf(vm, codeBlock, structure, slot.cachedOffset());
     269            stubInfo.initGetByIdSelf(vm, codeBlock->ownerExecutable(), structure, slot.cachedOffset());
    269270            return RetryCacheLater;
    270271        }
     
    279280            if (slot.isUnset()) {
    280281                conditionSet = generateConditionsForPropertyMiss(
    281                     vm, codeBlock, exec, structure, propertyName.impl());
     282                    vm, codeBlock->ownerExecutable(), exec, structure, propertyName.impl());
    282283            } else {
    283284                conditionSet = generateConditionsForPrototypePropertyHit(
    284                     vm, codeBlock, exec, structure, slot.slotBase(),
     285                    vm, codeBlock->ownerExecutable(), exec, structure, slot.slotBase(),
    285286                    propertyName.impl());
    286287            }
     
    303304
    304305        newCase = AccessCase::get(
    305             vm, codeBlock, type, offset, structure, conditionSet, loadTargetFromProxy,
     306            vm, owner, type, offset, structure, conditionSet, loadTargetFromProxy,
    306307            slot.watchpointSet(), slot.isCacheableCustom() ? slot.customGetter() : nullptr,
    307308            slot.isCacheableCustom() ? slot.slotBase() : nullptr);
     
    357358   
    358359    CodeBlock* codeBlock = exec->codeBlock();
     360    ScriptExecutable* owner = codeBlock->ownerScriptExecutable();
    359361    VM& vm = exec->vm();
    360362
     
    384386                    appropriateOptimizingPutByIdFunction(slot, putKind), false);
    385387                stubInfo.initPutByIdReplace(
    386                     vm, codeBlock, structure, slot.cachedOffset());
     388                    vm, codeBlock->ownerExecutable(), structure, slot.cachedOffset());
    387389                return RetryCacheLater;
    388390            }
    389391
    390             newCase = AccessCase::replace(vm, codeBlock, structure, slot.cachedOffset());
     392            newCase = AccessCase::replace(vm, owner, structure, slot.cachedOffset());
    391393        } else {
    392394            ASSERT(slot.type() == PutPropertySlot::NewProperty);
     
    410412                conditionSet =
    411413                    generateConditionsForPropertySetterMiss(
    412                         vm, codeBlock, exec, newStructure, ident.impl());
     414                        vm, owner, exec, newStructure, ident.impl());
    413415                if (!conditionSet.isValid())
    414416                    return GiveUpOnCache;
    415417            }
    416418
    417             newCase = AccessCase::transition(vm, codeBlock, structure, newStructure, offset, conditionSet);
     419            newCase = AccessCase::transition(vm, owner, structure, newStructure, offset, conditionSet);
    418420        }
    419421    } else if (slot.isCacheableCustom() || slot.isCacheableSetter()) {
     
    424426                conditionSet =
    425427                    generateConditionsForPrototypePropertyHitCustom(
    426                         vm, codeBlock, exec, structure, slot.base(), ident.impl());
     428                        vm, owner, exec, structure, slot.base(), ident.impl());
    427429                if (!conditionSet.isValid())
    428430                    return GiveUpOnCache;
     
    430432
    431433            newCase = AccessCase::setter(
    432                 vm, codeBlock, AccessCase::CustomSetter, structure, invalidOffset, conditionSet,
     434                vm, owner, AccessCase::CustomSetter, structure, invalidOffset, conditionSet,
    433435                slot.customSetter(), slot.base());
    434436        } else {
     
    439441                conditionSet =
    440442                    generateConditionsForPrototypePropertyHit(
    441                         vm, codeBlock, exec, structure, slot.base(), ident.impl());
     443                        vm, owner, exec, structure, slot.base(), ident.impl());
    442444                if (!conditionSet.isValid())
    443445                    return GiveUpOnCache;
     
    447449
    448450            newCase = AccessCase::setter(
    449                 vm, codeBlock, AccessCase::Setter, structure, offset, conditionSet);
     451                vm, owner, AccessCase::Setter, structure, offset, conditionSet);
    450452        }
    451453    }
     
    490492   
    491493    CodeBlock* codeBlock = exec->codeBlock();
     494    ScriptExecutable* owner = codeBlock->ownerScriptExecutable();
    492495    VM& vm = exec->vm();
    493496    Structure* structure = base->structure(vm);
     
    497500        if (slot.slotBase() != base) {
    498501            conditionSet = generateConditionsForPrototypePropertyHit(
    499                 vm, codeBlock, exec, structure, slot.slotBase(), ident.impl());
     502                vm, codeBlock->ownerExecutable(), exec, structure, slot.slotBase(), ident.impl());
    500503        }
    501504    } else {
    502505        conditionSet = generateConditionsForPropertyMiss(
    503             vm, codeBlock, exec, structure, ident.impl());
     506            vm, codeBlock->ownerExecutable(), exec, structure, ident.impl());
    504507    }
    505508    if (!conditionSet.isValid())
     
    507510
    508511    std::unique_ptr<AccessCase> newCase = AccessCase::in(
    509         vm, codeBlock, wasFound ? AccessCase::InHit : AccessCase::InMiss, structure, conditionSet);
     512        vm, owner, wasFound ? AccessCase::InHit : AccessCase::InMiss, structure, conditionSet);
    510513
    511514    MacroAssemblerCodePtr codePtr = stubInfo.addAccessCase(vm, codeBlock, ident, WTF::move(newCase));
     
    556559   
    557560    ASSERT(!callLinkInfo.isLinked());
    558     callLinkInfo.setCallee(exec->callerFrame()->vm(), callLinkInfo.hotPathBegin(), callerCodeBlock, callee);
    559     callLinkInfo.setLastSeenCallee(exec->callerFrame()->vm(), callerCodeBlock, callee);
     561    callLinkInfo.setCallee(exec->callerFrame()->vm(), callLinkInfo.hotPathBegin(), callerCodeBlock->ownerExecutable(), callee);
     562    callLinkInfo.setLastSeenCallee(exec->callerFrame()->vm(), callerCodeBlock->ownerExecutable(), callee);
    560563    if (shouldShowDisassemblyFor(callerCodeBlock))
    561564        dataLog("Linking call in ", *callerCodeBlock, " at ", callLinkInfo.codeOrigin(), " to ", pointerDump(calleeCodeBlock), ", entrypoint at ", codePtr, "\n");
     
    874877                toCString(*callerCodeBlock).data(), callLinkInfo.callReturnLocation().labelAtOffset(0).executableAddress(),
    875878                toCString(listDump(callCases)).data())),
    876         *vm, callerCodeBlock, exec->callerFrame(), callLinkInfo, callCases,
     879        *vm, callerCodeBlock->ownerExecutable(), exec->callerFrame(), callLinkInfo, callCases,
    877880        WTF::move(fastCounts)));
    878881   
  • trunk/Source/JavaScriptCore/llint/LLIntSlowPaths.cpp

    r190522 r190546  
    577577            && !structure->typeInfo().prohibitsPropertyCaching()
    578578            && !structure->typeInfo().newImpurePropertyFiresWatchpoints()) {
    579             vm.heap.writeBarrier(codeBlock);
     579            vm.heap.writeBarrier(codeBlock->ownerExecutable());
    580580           
    581581            ConcurrentJITLocker locker(codeBlock->m_lock);
     
    642642            && baseCell == slot.base()) {
    643643
    644             vm.heap.writeBarrier(codeBlock);
     644            vm.heap.writeBarrier(codeBlock->ownerExecutable());
    645645           
    646646            if (slot.type() == PutPropertySlot::NewProperty) {
     
    659659                            ASSERT(chain);
    660660                            pc[7].u.structureChain.set(
    661                                 vm, codeBlock, chain);
     661                                vm, codeBlock->ownerExecutable(), chain);
    662662                        }
    663663                        pc[8].u.putByIdFlags = static_cast<PutByIdFlags>(
     
    11911191        if (callLinkInfo->isOnList())
    11921192            callLinkInfo->remove();
    1193         callLinkInfo->callee.set(vm, callerCodeBlock, callee);
    1194         callLinkInfo->lastSeenCallee.set(vm, callerCodeBlock, callee);
     1193        callLinkInfo->callee.set(vm, callerCodeBlock->ownerExecutable(), callee);
     1194        callLinkInfo->lastSeenCallee.set(vm, callerCodeBlock->ownerExecutable(), callee);
    11951195        callLinkInfo->machineCodeTarget = codePtr;
    11961196        if (codeBlock)
  • trunk/Source/JavaScriptCore/profiler/ProfilerOriginStack.cpp

    r190522 r190546  
    5353    for (unsigned i = 1; i < stack.size(); ++i) {
    5454        append(Origin(
    55             database.ensureBytecodesFor(stack[i].inlineCallFrame->baselineCodeBlock.get()),
     55            database.ensureBytecodesFor(stack[i].inlineCallFrame->baselineCodeBlock()),
    5656            stack[i].bytecodeIndex));
    5757    }
  • trunk/Source/JavaScriptCore/runtime/CommonSlowPaths.cpp

    r190522 r190546  
    232232    auto& cacheWriteBarrier = pc[4].u.jsCell;
    233233    if (!cacheWriteBarrier)
    234         cacheWriteBarrier.set(exec->vm(), exec->codeBlock(), constructor);
     234        cacheWriteBarrier.set(exec->vm(), exec->codeBlock()->ownerExecutable(), constructor);
    235235    else if (cacheWriteBarrier.unvalidatedGet() != JSCell::seenMultipleCalleeObjects() && cacheWriteBarrier.get() != constructor)
    236236        cacheWriteBarrier.setWithoutWriteBarrier(JSCell::seenMultipleCalleeObjects());
     
    251251            if (otherStructure)
    252252                pc[3].u.toThisStatus = ToThisConflicted;
    253             pc[2].u.structure.set(vm, exec->codeBlock(), myStructure);
     253            pc[2].u.structure.set(vm, exec->codeBlock()->ownerExecutable(), myStructure);
    254254        }
    255255    } else {
     
    527527{
    528528    BEGIN();
    529     CodeBlock* codeBlock = exec->codeBlock();
    530     Heap::heap(codeBlock)->writeBarrier(codeBlock);
     529    ExecutableBase* ownerExecutable = exec->codeBlock()->ownerExecutable();
     530    Heap::heap(ownerExecutable)->writeBarrier(ownerExecutable);
    531531    END();
    532532}
  • trunk/Source/JavaScriptCore/runtime/CommonSlowPaths.h

    r190522 r190546  
    130130
    131131        ConcurrentJITLocker locker(codeBlock->m_lock);
    132         pc[5].u.structure.set(exec->vm(), codeBlock, scope->structure());
     132        pc[5].u.structure.set(exec->vm(), codeBlock->ownerExecutable(), scope->structure());
    133133        pc[6].u.operand = slot.cachedOffset();
    134134    }
     
    163163            {
    164164                ConcurrentJITLocker locker(codeBlock->m_lock);
    165                 pc[5].u.structure.set(exec->vm(), codeBlock, structure);
     165                pc[5].u.structure.set(exec->vm(), codeBlock->ownerExecutable(), structure);
    166166                pc[6].u.operand = slot.cachedOffset();
    167167            }
  • trunk/Source/JavaScriptCore/runtime/Executable.cpp

    r190522 r190546  
    6161    m_numParametersForCall = NUM_PARAMETERS_NOT_COMPILED;
    6262    m_numParametersForConstruct = NUM_PARAMETERS_NOT_COMPILED;
    63 
    64     if (classInfo() == FunctionExecutable::info()) {
    65         FunctionExecutable* executable = jsCast<FunctionExecutable*>(this);
    66         executable->m_codeBlockForCall.clear();
    67         executable->m_codeBlockForConstruct.clear();
    68         return;
    69     }
    70 
    71     if (classInfo() == EvalExecutable::info()) {
    72         EvalExecutable* executable = jsCast<EvalExecutable*>(this);
    73         executable->m_evalCodeBlock.clear();
    74         executable->m_unlinkedEvalCodeBlock.clear();
    75         return;
    76     }
    77    
    78     if (classInfo() == ProgramExecutable::info()) {
    79         ProgramExecutable* executable = jsCast<ProgramExecutable*>(this);
    80         executable->m_programCodeBlock.clear();
    81         executable->m_unlinkedProgramCodeBlock.clear();
    82         return;
    83     }
    84 
    85     if (classInfo() == ModuleProgramExecutable::info()) {
    86         ModuleProgramExecutable* executable = jsCast<ModuleProgramExecutable*>(this);
    87         executable->m_moduleProgramCodeBlock.clear();
    88         executable->m_unlinkedModuleProgramCodeBlock.clear();
    89         executable->m_moduleEnvironmentSymbolTable.clear();
    90         return;
    91     }
    92    
    93 #if ENABLE(WEBASSEMBLY)
    94     if (classInfo() == WebAssemblyExecutable::info()) {
    95         WebAssemblyExecutable* executable = jsCast<WebAssemblyExecutable*>(this);
    96         executable->m_codeBlockForCall.clear();
    97         return;
    98     }
    99 #endif
    100 
    101     ASSERT(classInfo() == NativeExecutable::info());
    10263}
    10364
     
    163124    ASSERT(vm.heap.isDeferred());
    164125   
    165     CodeBlock* oldCodeBlock = nullptr;
     126    RefPtr<CodeBlock> oldCodeBlock;
    166127   
    167128    switch (codeType) {
     
    172133        ASSERT(kind == CodeForCall);
    173134       
    174         oldCodeBlock = executable->m_programCodeBlock.get();
    175         executable->m_programCodeBlock.setMayBeNull(vm, this, codeBlock);
     135        oldCodeBlock = executable->m_programCodeBlock;
     136        executable->m_programCodeBlock = codeBlock;
    176137        break;
    177138    }
     
    183144        ASSERT(kind == CodeForCall);
    184145
    185         oldCodeBlock = executable->m_moduleProgramCodeBlock.get();
    186         executable->m_moduleProgramCodeBlock.setMayBeNull(vm, this, codeBlock);
     146        oldCodeBlock = executable->m_moduleProgramCodeBlock;
     147        executable->m_moduleProgramCodeBlock = codeBlock;
    187148        break;
    188149    }
     
    194155        ASSERT(kind == CodeForCall);
    195156       
    196         oldCodeBlock = executable->m_evalCodeBlock.get();
    197         executable->m_evalCodeBlock.setMayBeNull(vm, this, codeBlock);
     157        oldCodeBlock = executable->m_evalCodeBlock;
     158        executable->m_evalCodeBlock = codeBlock;
    198159        break;
    199160    }
     
    205166        switch (kind) {
    206167        case CodeForCall:
    207             oldCodeBlock = executable->m_codeBlockForCall.get();
    208             executable->m_codeBlockForCall.setMayBeNull(vm, this, codeBlock);
     168            oldCodeBlock = executable->m_codeBlockForCall;
     169            executable->m_codeBlockForCall = codeBlock;
    209170            break;
    210171        case CodeForConstruct:
    211             oldCodeBlock = executable->m_codeBlockForConstruct.get();
    212             executable->m_codeBlockForConstruct.setMayBeNull(vm, this, codeBlock);
     172            oldCodeBlock = executable->m_codeBlockForConstruct;
     173            executable->m_codeBlockForConstruct = codeBlock;
    213174            break;
    214175        }
     
    250211}
    251212
    252 CodeBlock* ScriptExecutable::newCodeBlockFor(
     213RefPtr<CodeBlock> ScriptExecutable::newCodeBlockFor(
    253214    CodeSpecializationKind kind, JSFunction* function, JSScope* scope, JSObject*& exception)
    254215{
     
    264225        RELEASE_ASSERT(!executable->m_evalCodeBlock);
    265226        RELEASE_ASSERT(!function);
    266         return EvalCodeBlock::create(vm,
     227        return adoptRef(new EvalCodeBlock(
    267228            executable, executable->m_unlinkedEvalCodeBlock.get(), scope,
    268             executable->source().provider());
     229            executable->source().provider()));
    269230    }
    270231   
     
    274235        RELEASE_ASSERT(!executable->m_programCodeBlock);
    275236        RELEASE_ASSERT(!function);
    276         return ProgramCodeBlock::create(vm,
     237        return adoptRef(new ProgramCodeBlock(
    277238            executable, executable->m_unlinkedProgramCodeBlock.get(), scope,
    278             executable->source().provider(), executable->source().startColumn());
     239            executable->source().provider(), executable->source().startColumn()));
    279240    }
    280241
     
    284245        RELEASE_ASSERT(!executable->m_moduleProgramCodeBlock);
    285246        RELEASE_ASSERT(!function);
    286         return ModuleProgramCodeBlock::create(vm,
     247        return adoptRef(new ModuleProgramCodeBlock(
    287248            executable, executable->m_unlinkedModuleProgramCodeBlock.get(), scope,
    288             executable->source().provider(), executable->source().startColumn());
     249            executable->source().provider(), executable->source().startColumn()));
    289250    }
    290251
     
    316277    unsigned startColumn = executable->source().startColumn();
    317278
    318     return FunctionCodeBlock::create(vm,
    319         executable, unlinkedCodeBlock, scope, provider, sourceOffset, startColumn);
    320 }
    321 
    322 CodeBlock* ScriptExecutable::newReplacementCodeBlockFor(
     279    return adoptRef(new FunctionCodeBlock(
     280        executable, unlinkedCodeBlock, scope, provider, sourceOffset, startColumn));
     281}
     282
     283PassRefPtr<CodeBlock> ScriptExecutable::newReplacementCodeBlockFor(
    323284    CodeSpecializationKind kind)
    324285{
     
    328289        EvalCodeBlock* baseline = static_cast<EvalCodeBlock*>(
    329290            executable->m_evalCodeBlock->baselineVersion());
    330         EvalCodeBlock* result = EvalCodeBlock::create(vm(),
    331             CodeBlock::CopyParsedBlock, *baseline);
    332         result->setAlternative(*vm(), baseline);
     291        RefPtr<EvalCodeBlock> result = adoptRef(new EvalCodeBlock(
     292            CodeBlock::CopyParsedBlock, *baseline));
     293        result->setAlternative(baseline);
    333294        return result;
    334295    }
     
    339300        ProgramCodeBlock* baseline = static_cast<ProgramCodeBlock*>(
    340301            executable->m_programCodeBlock->baselineVersion());
    341         ProgramCodeBlock* result = ProgramCodeBlock::create(vm(),
    342             CodeBlock::CopyParsedBlock, *baseline);
    343         result->setAlternative(*vm(), baseline);
     302        RefPtr<ProgramCodeBlock> result = adoptRef(new ProgramCodeBlock(
     303            CodeBlock::CopyParsedBlock, *baseline));
     304        result->setAlternative(baseline);
    344305        return result;
    345306    }
     
    350311        ModuleProgramCodeBlock* baseline = static_cast<ModuleProgramCodeBlock*>(
    351312            executable->m_moduleProgramCodeBlock->baselineVersion());
    352         ModuleProgramCodeBlock* result = ModuleProgramCodeBlock::create(vm(),
    353             CodeBlock::CopyParsedBlock, *baseline);
    354         result->setAlternative(*vm(), baseline);
     313        RefPtr<ModuleProgramCodeBlock> result = adoptRef(new ModuleProgramCodeBlock(
     314            CodeBlock::CopyParsedBlock, *baseline));
     315        result->setAlternative(baseline);
    355316        return result;
    356317    }
     
    360321    FunctionCodeBlock* baseline = static_cast<FunctionCodeBlock*>(
    361322        executable->codeBlockFor(kind)->baselineVersion());
    362     FunctionCodeBlock* result = FunctionCodeBlock::create(vm(),
    363         CodeBlock::CopyParsedBlock, *baseline);
    364     result->setAlternative(*vm(), baseline);
     323    RefPtr<FunctionCodeBlock> result = adoptRef(new FunctionCodeBlock(
     324        CodeBlock::CopyParsedBlock, *baseline));
     325    result->setAlternative(baseline);
    365326    return result;
    366327}
     
    390351   
    391352    JSObject* exception = 0;
    392     CodeBlock* codeBlock = newCodeBlockFor(kind, function, scope, exception);
     353    RefPtr<CodeBlock> codeBlock = newCodeBlockFor(kind, function, scope, exception);
    393354    if (!codeBlock) {
    394355        RELEASE_ASSERT(exception);
     
    400361   
    401362    if (Options::useLLInt())
    402         setupLLInt(vm, codeBlock);
     363        setupLLInt(vm, codeBlock.get());
    403364    else
    404         setupJIT(vm, codeBlock);
    405    
    406     installCode(*codeBlock->vm(), codeBlock, codeBlock->codeType(), codeBlock->specializationKind());
     365        setupJIT(vm, codeBlock.get());
     366   
     367    installCode(*codeBlock->vm(), codeBlock.get(), codeBlock->codeType(), codeBlock->specializationKind());
    407368    return 0;
    408369}
     
    542503    ASSERT_GC_OBJECT_INHERITS(thisObject, info());
    543504    ScriptExecutable::visitChildren(thisObject, visitor);
     505    if (thisObject->m_evalCodeBlock)
     506        thisObject->m_evalCodeBlock->visitAggregate(visitor);
    544507    visitor.append(&thisObject->m_unlinkedEvalCodeBlock);
    545     if (thisObject->m_evalCodeBlock)
    546         thisObject->m_evalCodeBlock->visitWeakly(visitor);
     508}
     509
     510void EvalExecutable::clearCode()
     511{
     512    m_evalCodeBlock = nullptr;
     513    m_unlinkedEvalCodeBlock.clear();
     514    Base::clearCode();
    547515}
    548516
     
    651619    visitor.append(&thisObject->m_unlinkedProgramCodeBlock);
    652620    if (thisObject->m_programCodeBlock)
    653         thisObject->m_programCodeBlock->visitWeakly(visitor);
     621        thisObject->m_programCodeBlock->visitAggregate(visitor);
     622}
     623
     624void ProgramExecutable::clearCode()
     625{
     626    m_programCodeBlock = nullptr;
     627    m_unlinkedProgramCodeBlock.clear();
     628    Base::clearCode();
    654629}
    655630
     
    662637    visitor.append(&thisObject->m_moduleEnvironmentSymbolTable);
    663638    if (thisObject->m_moduleProgramCodeBlock)
    664         thisObject->m_moduleProgramCodeBlock->visitWeakly(visitor);
     639        thisObject->m_moduleProgramCodeBlock->visitAggregate(visitor);
     640}
     641
     642void ModuleProgramExecutable::clearCode()
     643{
     644    m_moduleProgramCodeBlock = nullptr;
     645    m_unlinkedModuleProgramCodeBlock.clear();
     646    m_moduleEnvironmentSymbolTable.clear();
     647    Base::clearCode();
    665648}
    666649
     
    685668    ScriptExecutable::visitChildren(thisObject, visitor);
    686669    if (thisObject->m_codeBlockForCall)
    687         thisObject->m_codeBlockForCall->visitWeakly(visitor);
     670        thisObject->m_codeBlockForCall->visitAggregate(visitor);
    688671    if (thisObject->m_codeBlockForConstruct)
    689         thisObject->m_codeBlockForConstruct->visitWeakly(visitor);
     672        thisObject->m_codeBlockForConstruct->visitAggregate(visitor);
    690673    visitor.append(&thisObject->m_unlinkedExecutable);
    691674    visitor.append(&thisObject->m_singletonFunction);
     675}
     676
     677void FunctionExecutable::clearCode()
     678{
     679    m_codeBlockForCall = nullptr;
     680    m_codeBlockForConstruct = nullptr;
     681    Base::clearCode();
    692682}
    693683
     
    727717    ExecutableBase::visitChildren(thisObject, visitor);
    728718    if (thisObject->m_codeBlockForCall)
    729         thisObject->m_codeBlockForCall->visitWeakly(visitor);
     719        thisObject->m_codeBlockForCall->visitAggregate(visitor);
    730720    visitor.append(&thisObject->m_module);
     721}
     722
     723void WebAssemblyExecutable::clearCode()
     724{
     725    m_codeBlockForCall = nullptr;
     726    Base::clearCode();
    731727}
    732728
     
    739735    DeferGC deferGC(vm.heap);
    740736
    741     WebAssemblyCodeBlock* codeBlock = WebAssemblyCodeBlock::create(vm,
    742         this, exec->lexicalGlobalObject()));
    743 
    744     WASMFunctionParser::compile(vm, codeBlock, m_module.get(), m_source, m_functionIndex);
     737    RefPtr<WebAssemblyCodeBlock> codeBlock = adoptRef(new WebAssemblyCodeBlock(
     738        this, vm, exec->lexicalGlobalObject()));
     739
     740    WASMFunctionParser::compile(vm, codeBlock.get(), m_module.get(), m_source, m_functionIndex);
    745741
    746742    m_jitCodeForCall = codeBlock->jitCode();
     
    748744    m_numParametersForCall = codeBlock->numParameters();
    749745
    750     m_codeBlockForCall.set(vm, this, codeBlock);
     746    m_codeBlockForCall = codeBlock;
    751747
    752748    Heap::heap(this)->writeBarrier(this);
  • trunk/Source/JavaScriptCore/runtime/Executable.h

    r190522 r190546  
    140140
    141141public:
     142    static void clearCodeVirtual(ExecutableBase*);
     143
    142144    PassRefPtr<JITCode> generatedJITCodeForCall()
    143145    {
     
    305307
    306308private:
    307     friend class ExecutableBase;
    308 
    309309    NativeExecutable(VM& vm, NativeFunction function, NativeFunction constructor)
    310310        : ExecutableBase(vm, vm.nativeExecutableStructure.get(), NUM_PARAMETERS_IS_HOST)
     
    377377    void installCode(CodeBlock*);
    378378    void installCode(VM&, CodeBlock*, CodeType, CodeSpecializationKind);
    379     CodeBlock* newCodeBlockFor(CodeSpecializationKind, JSFunction*, JSScope*, JSObject*& exception);
    380     CodeBlock* newReplacementCodeBlockFor(CodeSpecializationKind);
     379    RefPtr<CodeBlock> newCodeBlockFor(CodeSpecializationKind, JSFunction*, JSScope*, JSObject*& exception);
     380    PassRefPtr<CodeBlock> newReplacementCodeBlockFor(CodeSpecializationKind);
    381381   
    382382    JSObject* prepareForExecution(ExecState* exec, JSFunction* function, JSScope* scope, CodeSpecializationKind kind)
     
    390390
    391391private:
    392     friend class ExecutableBase;
    393392    JSObject* prepareForExecutionImpl(ExecState*, JSFunction*, JSScope*, CodeSpecializationKind);
    394393
     
    449448    DECLARE_INFO;
    450449
     450    void clearCode();
     451
    451452    ExecutableInfo executableInfo() const { return ExecutableInfo(needsActivation(), usesEval(), isStrictMode(), false, false, ConstructorKind::None, false); }
    452453
     
    455456
    456457private:
    457     friend class ExecutableBase;
    458458    friend class ScriptExecutable;
    459459    EvalExecutable(ExecState*, const SourceCode&, bool);
     
    461461    static void visitChildren(JSCell*, SlotVisitor&);
    462462
    463     WriteBarrier<EvalCodeBlock> m_evalCodeBlock;
     463    RefPtr<EvalCodeBlock> m_evalCodeBlock;
    464464    WriteBarrier<UnlinkedEvalCodeBlock> m_unlinkedEvalCodeBlock;
    465465};
     
    502502    DECLARE_INFO;
    503503
     504    void clearCode();
     505
    504506    ExecutableInfo executableInfo() const { return ExecutableInfo(needsActivation(), usesEval(), isStrictMode(), false, false, ConstructorKind::None, false); }
    505507
    506508private:
    507     friend class ExecutableBase;
    508509    friend class ScriptExecutable;
    509510
     
    513514
    514515    WriteBarrier<UnlinkedProgramCodeBlock> m_unlinkedProgramCodeBlock;
    515     WriteBarrier<ProgramCodeBlock> m_programCodeBlock;
     516    RefPtr<ProgramCodeBlock> m_programCodeBlock;
    516517};
    517518
     
    543544    DECLARE_INFO;
    544545
     546    void clearCode();
     547
    545548    ExecutableInfo executableInfo() const { return ExecutableInfo(needsActivation(), usesEval(), isStrictMode(), false, false, ConstructorKind::None, false); }
    546549    UnlinkedModuleProgramCodeBlock* unlinkedModuleProgramCodeBlock() { return m_unlinkedModuleProgramCodeBlock.get(); }
     
    549552
    550553private:
    551     friend class ExecutableBase;
    552554    friend class ScriptExecutable;
    553555
     
    558560    WriteBarrier<UnlinkedModuleProgramCodeBlock> m_unlinkedModuleProgramCodeBlock;
    559561    WriteBarrier<SymbolTable> m_moduleEnvironmentSymbolTable;
    560     WriteBarrier<ModuleProgramCodeBlock> m_moduleProgramCodeBlock;
     562    RefPtr<ModuleProgramCodeBlock> m_moduleProgramCodeBlock;
    561563};
    562564
     
    599601    bool isGeneratedForCall() const
    600602    {
    601         return !!m_codeBlockForCall;
     603        return m_codeBlockForCall;
    602604    }
    603605
     
    609611    bool isGeneratedForConstruct() const
    610612    {
    611         return m_codeBlockForConstruct.get();
     613        return m_codeBlockForConstruct;
    612614    }
    613615
     
    675677    DECLARE_INFO;
    676678
     679    void clearCode();
     680   
    677681    InferredValue* singletonFunction() { return m_singletonFunction.get(); }
    678682
    679683private:
    680     friend class ExecutableBase;
    681684    FunctionExecutable(
    682685        VM&, const SourceCode&, UnlinkedFunctionExecutable*, unsigned firstLine,
     
    688691   
    689692    WriteBarrier<UnlinkedFunctionExecutable> m_unlinkedExecutable;
    690     WriteBarrier<FunctionCodeBlock> m_codeBlockForCall;
    691     WriteBarrier<FunctionCodeBlock> m_codeBlockForConstruct;
     693    RefPtr<FunctionCodeBlock> m_codeBlockForCall;
     694    RefPtr<FunctionCodeBlock> m_codeBlockForConstruct;
    692695    RefPtr<TypeSet> m_returnStatementTypeSet;
    693696    unsigned m_parametersStartOffset;
     
    717720    DECLARE_INFO;
    718721
     722    void clearCode();
     723
    719724    void prepareForExecution(ExecState*);
    720725
     
    725730
    726731private:
    727     friend class ExecutableBase;
    728732    WebAssemblyExecutable(VM&, const SourceCode&, JSWASMModule*, unsigned functionIndex);
    729733
     
    734738    unsigned m_functionIndex;
    735739
    736     WriteBarrier<WebAssemblyCodeBlock> m_codeBlockForCall;
     740    RefPtr<WebAssemblyCodeBlock> m_codeBlockForCall;
    737741};
    738742#endif
    739743
    740 } // namespace JSC
    741 
    742 #endif // Executable_h
     744inline void ExecutableBase::clearCodeVirtual(ExecutableBase* executable)
     745{
     746    switch (executable->type()) {
     747    case EvalExecutableType:
     748        return jsCast<EvalExecutable*>(executable)->clearCode();
     749    case ProgramExecutableType:
     750        return jsCast<ProgramExecutable*>(executable)->clearCode();
     751    case FunctionExecutableType:
     752        return jsCast<FunctionExecutable*>(executable)->clearCode();
     753#if ENABLE(WEBASSEMBLY)
     754    case WebAssemblyExecutableType:
     755        return jsCast<WebAssemblyExecutable*>(executable)->clearCode();
     756#endif
     757    case ModuleProgramExecutableType:
     758        return jsCast<ModuleProgramExecutable*>(executable)->clearCode();
     759    default:
     760        return jsCast<NativeExecutable*>(executable)->clearCode();
     761    }
     762}
     763
     764}
     765
     766#endif
  • trunk/Source/JavaScriptCore/runtime/VM.cpp

    r190522 r190546  
    249249    promiseDeferredStructure.set(*this, JSPromiseDeferred::createStructure(*this, 0, jsNull()));
    250250    internalPromiseDeferredStructure.set(*this, JSInternalPromiseDeferred::createStructure(*this, 0, jsNull()));
    251     programCodeBlockStructure.set(*this, ProgramCodeBlock::createStructure(*this, 0, jsNull()));
    252     moduleProgramCodeBlockStructure.set(*this, ModuleProgramCodeBlock::createStructure(*this, 0, jsNull()));
    253     evalCodeBlockStructure.set(*this, EvalCodeBlock::createStructure(*this, 0, jsNull()));
    254     functionCodeBlockStructure.set(*this, FunctionCodeBlock::createStructure(*this, 0, jsNull()));
    255 #if ENABLE(WEBASSEMBLY)
    256     webAssemblyCodeBlockStructure.set(*this, WebAssemblyCodeBlock::createStructure(*this, 0, jsNull()));
    257 #endif
    258 
    259251    iterationTerminator.set(*this, JSFinalObject::create(*this, JSFinalObject::createStructure(*this, 0, jsNull(), 1)));
    260252    nativeStdFunctionCellStructure.set(*this, NativeStdFunctionCell::createStructure(*this, 0, jsNull()));
  • trunk/Source/JavaScriptCore/runtime/VM.h

    r190522 r190546  
    310310    Strong<Structure> internalPromiseDeferredStructure;
    311311    Strong<Structure> nativeStdFunctionCellStructure;
    312     Strong<Structure> programCodeBlockStructure;
    313     Strong<Structure> moduleProgramCodeBlockStructure;
    314     Strong<Structure> evalCodeBlockStructure;
    315     Strong<Structure> functionCodeBlockStructure;
    316     Strong<Structure> webAssemblyCodeBlockStructure;
    317 
    318312    Strong<JSCell> iterationTerminator;
    319313    Strong<JSCell> emptyPropertyNameEnumerator;
Note: See TracChangeset for help on using the changeset viewer.