Ignore:
Timestamp:
Feb 4, 2020, 11:05:17 AM (6 years ago)
Author:
[email protected]
Message:

[JSC] Introduce UnlinkedCodeBlockGenerator and reduce sizeof(UnlinkedCodeBlock)
https://bugs.webkit.org/show_bug.cgi?id=207087

Reviewed by Tadeu Zagallo.

Source/JavaScriptCore:

While UnlinkedCodeBlock is immutable once it is created from BytecodeGenerator, it has many mutable Vectors.
This is because we are using UnlinkedCodeBlock as a builder of UnlinkedCodeBlock itself too in BytecodeGenerator.
Since Vector takes 16 bytes to allow efficient expansions, it is nice if we can use RefCountedArray instead when
we know this Vector is immutable.

In this patch, we introduce UnlinkedCodeBlockGenerator wrapper. BytecodeGenerator, BytecodeRewriter, BytecodeDumper,
and BytecodeGeneratorification interact with UnlinkedCodeBlockGenerator instead of UnlinkedCodeBlock. And UnlinkedCodeBlockGenerator
will generate the finalized UnlinkedCodeBlock. This design allows us to use RefCountedArray for data in UnlinkedCodeBlock,
which is (1) smaller and (2) doing shrinkToFit operation when creating it from Vector.

This patch reduces sizeof(UnlinkedCodeBlock) from 256 to 168, 88 bytes reduction.

  • JavaScriptCore.xcodeproj/project.pbxproj:
  • Sources.txt:
  • bytecode/BytecodeBasicBlock.cpp:

(JSC::BytecodeBasicBlock::compute):

  • bytecode/BytecodeBasicBlock.h:
  • bytecode/BytecodeDumper.cpp:
  • bytecode/BytecodeGeneratorification.cpp:

(JSC::BytecodeGeneratorification::BytecodeGeneratorification):
(JSC::GeneratorLivenessAnalysis::run):
(JSC::BytecodeGeneratorification::run):
(JSC::performGeneratorification):

  • bytecode/BytecodeGeneratorification.h:
  • bytecode/BytecodeRewriter.h:

(JSC::BytecodeRewriter::BytecodeRewriter):

  • bytecode/CodeBlock.cpp:

(JSC::CodeBlock::finishCreation):
(JSC::CodeBlock::setConstantIdentifierSetRegisters):
(JSC::CodeBlock::setConstantRegisters):
(JSC::CodeBlock::handlerForIndex):
(JSC::CodeBlock::insertBasicBlockBoundariesForControlFlowProfiler):

  • bytecode/CodeBlock.h:

(JSC::CodeBlock::numberOfSwitchJumpTables const):
(JSC::CodeBlock::numberOfStringSwitchJumpTables const):
(JSC::CodeBlock::addSwitchJumpTable): Deleted.
(JSC::CodeBlock::addStringSwitchJumpTable): Deleted.

  • bytecode/HandlerInfo.h:

(JSC::HandlerInfoBase::handlerForIndex):

  • bytecode/JumpTable.h:

(JSC::SimpleJumpTable::add): Deleted.

  • bytecode/PreciseJumpTargets.cpp:

(JSC::computePreciseJumpTargets):
(JSC::recomputePreciseJumpTargets):
(JSC::findJumpTargetsForInstruction):

  • bytecode/PreciseJumpTargets.h:
  • bytecode/UnlinkedCodeBlock.cpp:

(JSC::UnlinkedCodeBlock::UnlinkedCodeBlock):
(JSC::UnlinkedCodeBlock::visitChildren):
(JSC::UnlinkedCodeBlock::dumpExpressionRangeInfo):
(JSC::UnlinkedCodeBlock::expressionRangeForBytecodeIndex const):
(JSC::UnlinkedCodeBlock::handlerForIndex):
(JSC::UnlinkedCodeBlock::addExpressionInfo): Deleted.
(JSC::UnlinkedCodeBlock::addTypeProfilerExpressionInfo): Deleted.
(JSC::UnlinkedCodeBlock::setInstructions): Deleted.
(JSC::UnlinkedCodeBlock::applyModification): Deleted.
(JSC::UnlinkedCodeBlock::shrinkToFit): Deleted.
(JSC::UnlinkedCodeBlock::addOutOfLineJumpTarget): Deleted.

  • bytecode/UnlinkedCodeBlock.h:

(JSC::UnlinkedCodeBlock::expressionInfo):
(JSC::UnlinkedCodeBlock::setNumParameters):
(JSC::UnlinkedCodeBlock::numberOfIdentifiers const):
(JSC::UnlinkedCodeBlock::identifiers const):
(JSC::UnlinkedCodeBlock::bitVector):
(JSC::UnlinkedCodeBlock::constantRegisters):
(JSC::UnlinkedCodeBlock::constantsSourceCodeRepresentation):
(JSC::UnlinkedCodeBlock::constantIdentifierSets):
(JSC::UnlinkedCodeBlock::numberOfJumpTargets const):
(JSC::UnlinkedCodeBlock::numberOfSwitchJumpTables const):
(JSC::UnlinkedCodeBlock::numberOfStringSwitchJumpTables const):
(JSC::UnlinkedCodeBlock::numberOfFunctionDecls):
(JSC::UnlinkedCodeBlock::numberOfExceptionHandlers const):
(JSC::UnlinkedCodeBlock::opProfileControlFlowBytecodeOffsets const):
(JSC::UnlinkedCodeBlock::createRareDataIfNecessary):
(JSC::UnlinkedCodeBlock::addParameter): Deleted.
(JSC::UnlinkedCodeBlock::addIdentifier): Deleted.
(JSC::UnlinkedCodeBlock::addBitVector): Deleted.
(JSC::UnlinkedCodeBlock::addSetConstant): Deleted.
(JSC::UnlinkedCodeBlock::addConstant): Deleted.
(JSC::UnlinkedCodeBlock::addJumpTarget): Deleted.
(JSC::UnlinkedCodeBlock::addSwitchJumpTable): Deleted.
(JSC::UnlinkedCodeBlock::addStringSwitchJumpTable): Deleted.
(JSC::UnlinkedCodeBlock::addFunctionDecl): Deleted.
(JSC::UnlinkedCodeBlock::addFunctionExpr): Deleted.
(JSC::UnlinkedCodeBlock::addExceptionHandler): Deleted.
(JSC::UnlinkedCodeBlock::addOpProfileControlFlowBytecodeOffset): Deleted.
(JSC::UnlinkedCodeBlock::replaceOutOfLineJumpTargets): Deleted.

  • bytecode/UnlinkedCodeBlockGenerator.cpp: Added.

(JSC::UnlinkedCodeBlockGenerator::getLineAndColumn const):
(JSC::UnlinkedCodeBlockGenerator::addExpressionInfo):
(JSC::UnlinkedCodeBlockGenerator::addTypeProfilerExpressionInfo):
(JSC::UnlinkedCodeBlockGenerator::finalize):
(JSC::UnlinkedCodeBlockGenerator::handlerForBytecodeIndex):
(JSC::UnlinkedCodeBlockGenerator::handlerForIndex):
(JSC::UnlinkedCodeBlockGenerator::applyModification):
(JSC::UnlinkedCodeBlockGenerator::addOutOfLineJumpTarget):
(JSC::UnlinkedCodeBlockGenerator::outOfLineJumpOffset):
(JSC::UnlinkedCodeBlockGenerator::dump const):

  • bytecode/UnlinkedCodeBlockGenerator.h: Added.

(JSC::UnlinkedCodeBlockGenerator::UnlinkedCodeBlockGenerator):
(JSC::UnlinkedCodeBlockGenerator::vm):
(JSC::UnlinkedCodeBlockGenerator::isConstructor const):
(JSC::UnlinkedCodeBlockGenerator::constructorKind const):
(JSC::UnlinkedCodeBlockGenerator::superBinding const):
(JSC::UnlinkedCodeBlockGenerator::scriptMode const):
(JSC::UnlinkedCodeBlockGenerator::needsClassFieldInitializer const):
(JSC::UnlinkedCodeBlockGenerator::isStrictMode const):
(JSC::UnlinkedCodeBlockGenerator::usesEval const):
(JSC::UnlinkedCodeBlockGenerator::parseMode const):
(JSC::UnlinkedCodeBlockGenerator::isArrowFunction):
(JSC::UnlinkedCodeBlockGenerator::derivedContextType const):
(JSC::UnlinkedCodeBlockGenerator::evalContextType const):
(JSC::UnlinkedCodeBlockGenerator::isArrowFunctionContext const):
(JSC::UnlinkedCodeBlockGenerator::isClassContext const):
(JSC::UnlinkedCodeBlockGenerator::numCalleeLocals const):
(JSC::UnlinkedCodeBlockGenerator::numVars const):
(JSC::UnlinkedCodeBlockGenerator::numParameters const):
(JSC::UnlinkedCodeBlockGenerator::thisRegister const):
(JSC::UnlinkedCodeBlockGenerator::scopeRegister const):
(JSC::UnlinkedCodeBlockGenerator::wasCompiledWithDebuggingOpcodes const):
(JSC::UnlinkedCodeBlockGenerator::hasCheckpoints const):
(JSC::UnlinkedCodeBlockGenerator::hasTailCalls const):
(JSC::UnlinkedCodeBlockGenerator::setHasCheckpoints):
(JSC::UnlinkedCodeBlockGenerator::setHasTailCalls):
(JSC::UnlinkedCodeBlockGenerator::setNumCalleeLocals):
(JSC::UnlinkedCodeBlockGenerator::setNumVars):
(JSC::UnlinkedCodeBlockGenerator::setThisRegister):
(JSC::UnlinkedCodeBlockGenerator::setScopeRegister):
(JSC::UnlinkedCodeBlockGenerator::setNumParameters):
(JSC::UnlinkedCodeBlockGenerator::metadata):
(JSC::UnlinkedCodeBlockGenerator::addOpProfileControlFlowBytecodeOffset):
(JSC::UnlinkedCodeBlockGenerator::numberOfJumpTargets const):
(JSC::UnlinkedCodeBlockGenerator::addJumpTarget):
(JSC::UnlinkedCodeBlockGenerator::jumpTarget const):
(JSC::UnlinkedCodeBlockGenerator::lastJumpTarget const):
(JSC::UnlinkedCodeBlockGenerator::numberOfSwitchJumpTables const):
(JSC::UnlinkedCodeBlockGenerator::addSwitchJumpTable):
(JSC::UnlinkedCodeBlockGenerator::switchJumpTable):
(JSC::UnlinkedCodeBlockGenerator::numberOfStringSwitchJumpTables const):
(JSC::UnlinkedCodeBlockGenerator::addStringSwitchJumpTable):
(JSC::UnlinkedCodeBlockGenerator::stringSwitchJumpTable):
(JSC::UnlinkedCodeBlockGenerator::numberOfExceptionHandlers const):
(JSC::UnlinkedCodeBlockGenerator::exceptionHandler):
(JSC::UnlinkedCodeBlockGenerator::addExceptionHandler):
(JSC::UnlinkedCodeBlockGenerator::bitVector):
(JSC::UnlinkedCodeBlockGenerator::addBitVector):
(JSC::UnlinkedCodeBlockGenerator::numberOfConstantIdentifierSets const):
(JSC::UnlinkedCodeBlockGenerator::constantIdentifierSets):
(JSC::UnlinkedCodeBlockGenerator::addSetConstant):
(JSC::UnlinkedCodeBlockGenerator::constantRegister const):
(JSC::UnlinkedCodeBlockGenerator::constantRegisters):
(JSC::UnlinkedCodeBlockGenerator::getConstant const):
(JSC::UnlinkedCodeBlockGenerator::constantsSourceCodeRepresentation):
(JSC::UnlinkedCodeBlockGenerator::addConstant):
(JSC::UnlinkedCodeBlockGenerator::addFunctionDecl):
(JSC::UnlinkedCodeBlockGenerator::addFunctionExpr):
(JSC::UnlinkedCodeBlockGenerator::numberOfIdentifiers const):
(JSC::UnlinkedCodeBlockGenerator::identifier const):
(JSC::UnlinkedCodeBlockGenerator::addIdentifier):
(JSC::UnlinkedCodeBlockGenerator::outOfLineJumpOffset):
(JSC::UnlinkedCodeBlockGenerator::replaceOutOfLineJumpTargets):
(JSC::UnlinkedCodeBlockGenerator::metadataSizeInBytes):

  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::generate):
(JSC::BytecodeGenerator::BytecodeGenerator):
(JSC::BytecodeGenerator::initializeNextParameter):
(JSC::BytecodeGenerator::emitPushFunctionNameScope):
(JSC::prepareJumpTableForSwitch):
(JSC::ForInContext::finalize):
(JSC::StructureForInContext::finalize):
(JSC::IndexedForInContext::finalize):

  • bytecompiler/BytecodeGenerator.h:
  • bytecompiler/BytecodeGeneratorBaseInlines.h:

(JSC::BytecodeGeneratorBase<Traits>::newRegister):
(JSC::BytecodeGeneratorBase<Traits>::addVar):

  • runtime/CachedTypes.cpp:

(JSC::CachedVector::encode):
(JSC::CachedVector::decode const):

  • wasm/WasmFunctionCodeBlock.h:

(JSC::Wasm::FunctionCodeBlock::setNumVars):
(JSC::Wasm::FunctionCodeBlock::setNumCalleeLocals):

Source/WTF:

Add more useful methods for RefCountedArray.

  • wtf/RefCountedArray.h:

(WTF::RefCountedArray::operator=):
(WTF::RefCountedArray::isEmpty const):
(WTF::RefCountedArray::front):
(WTF::RefCountedArray::front const):
(WTF::RefCountedArray::last):
(WTF::RefCountedArray::last const):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/bytecode/CodeBlock.cpp

    r255542 r255687  
    474474                UnlinkedSimpleJumpTable& sourceTable = unlinkedCodeBlock->switchJumpTable(i);
    475475                SimpleJumpTable& destTable = m_rareData->m_switchJumpTables[i];
    476                 destTable.branchOffsets = sourceTable.branchOffsets;
     476                destTable.branchOffsets.resizeToFit(sourceTable.branchOffsets.size());
     477                std::copy(sourceTable.branchOffsets.begin(), sourceTable.branchOffsets.end(), destTable.branchOffsets.begin());
    477478                destTable.min = sourceTable.min;
    478479            }
     
    867868}
    868869
    869 void CodeBlock::setConstantIdentifierSetRegisters(VM& vm, const Vector<ConstantIdentifierSetEntry>& constants)
     870void CodeBlock::setConstantIdentifierSetRegisters(VM& vm, const RefCountedArray<ConstantIdentifierSetEntry>& constants)
    870871{
    871872    auto scope = DECLARE_THROW_SCOPE(vm);
     
    889890}
    890891
    891 void CodeBlock::setConstantRegisters(const Vector<WriteBarrier<Unknown>>& constants, const Vector<SourceCodeRepresentation>& constantsSourceCodeRepresentation, ScriptExecutable* topLevelExecutable)
     892void CodeBlock::setConstantRegisters(const RefCountedArray<WriteBarrier<Unknown>>& constants, const RefCountedArray<SourceCodeRepresentation>& constantsSourceCodeRepresentation, ScriptExecutable* topLevelExecutable)
    892893{
    893894    VM& vm = *m_vm;
     
    900901        ConcurrentJSLocker locker(m_lock);
    901902        m_constantRegisters.resizeToFit(count);
     903        m_constantsSourceCodeRepresentation.resizeToFit(count);
    902904    }
    903905    for (size_t i = 0; i < count; i++) {
    904906        JSValue constant = constants[i].get();
    905         switch (constantsSourceCodeRepresentation[i]) {
     907        SourceCodeRepresentation representation = constantsSourceCodeRepresentation[i];
     908        m_constantsSourceCodeRepresentation[i] = representation;
     909        switch (representation) {
    906910        case SourceCodeRepresentation::LinkTimeConstant:
    907911            constant = globalObject->linkTimeConstant(static_cast<LinkTimeConstant>(constant.asInt32AsAnyInt()));
     
    935939        m_constantRegisters[i].set(vm, this, constant);
    936940    }
    937 
    938     m_constantsSourceCodeRepresentation = constantsSourceCodeRepresentation;
    939941}
    940942
     
    18091811    if (!m_rareData)
    18101812        return 0;
    1811     return HandlerInfo::handlerForIndex(m_rareData->m_exceptionHandlers, index, requiredHandler);
     1813    return HandlerInfo::handlerForIndex<HandlerInfo>(m_rareData->m_exceptionHandlers, index, requiredHandler);
    18121814}
    18131815
     
    31963198    if (!unlinkedCodeBlock()->hasOpProfileControlFlowBytecodeOffsets())
    31973199        return;
    3198     const Vector<InstructionStream::Offset>& bytecodeOffsets = unlinkedCodeBlock()->opProfileControlFlowBytecodeOffsets();
     3200    const RefCountedArray<InstructionStream::Offset>& bytecodeOffsets = unlinkedCodeBlock()->opProfileControlFlowBytecodeOffsets();
    31993201    for (size_t i = 0, offsetsLength = bytecodeOffsets.size(); i < offsetsLength; i++) {
    32003202        // Because op_profile_control_flow is emitted at the beginning of every basic block, finding
Note: See TracChangeset for help on using the changeset viewer.