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

Changeset 99810 in webkit


Ignore:
Timestamp:
Nov 9, 2011, 8:37:32 PM (15 years ago)
Author:
fpizlo@apple.com
Message:

Multiple CodeBlock should be able to share the same instruction
stream without copying
https://bugs.webkit.org/show_bug.cgi?id=71978

Reviewed by Oliver Hunt.

This refactors CodeBlock::m_instructions to be a Vector boxed in a
ref-counted object, but otherwise does not take advantage of this.

This is performance neutral.

  • bytecode/CodeBlock.cpp:

(JSC::CodeBlock::printStructure):
(JSC::CodeBlock::printStructures):
(JSC::CodeBlock::dump):
(JSC::CodeBlock::CodeBlock):
(JSC::CodeBlock::visitAggregate):
(JSC::CodeBlock::shrinkToFit):

  • bytecode/CodeBlock.h:

(JSC::CodeBlock::hasInstructions):
(JSC::CodeBlock::numberOfInstructions):
(JSC::CodeBlock::instructions):

  • jit/JIT.cpp:

(JSC::JIT::JIT):

Location:
trunk/Source/JavaScriptCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r99798 r99810  
     12011-11-09  Filip Pizlo  <fpizlo@apple.com>
     2
     3        Multiple CodeBlock should be able to share the same instruction
     4        stream without copying
     5        https://bugs.webkit.org/show_bug.cgi?id=71978
     6
     7        Reviewed by Oliver Hunt.
     8       
     9        This refactors CodeBlock::m_instructions to be a Vector boxed in a
     10        ref-counted object, but otherwise does not take advantage of this.
     11       
     12        This is performance neutral.
     13
     14        * bytecode/CodeBlock.cpp:
     15        (JSC::CodeBlock::printStructure):
     16        (JSC::CodeBlock::printStructures):
     17        (JSC::CodeBlock::dump):
     18        (JSC::CodeBlock::CodeBlock):
     19        (JSC::CodeBlock::visitAggregate):
     20        (JSC::CodeBlock::shrinkToFit):
     21        * bytecode/CodeBlock.h:
     22        (JSC::CodeBlock::hasInstructions):
     23        (JSC::CodeBlock::numberOfInstructions):
     24        (JSC::CodeBlock::instructions):
     25        * jit/JIT.cpp:
     26        (JSC::JIT::JIT):
     27
    1282011-11-09  Gavin Barraclough  <barraclough@apple.com>
    229
  • trunk/Source/JavaScriptCore/bytecode/CodeBlock.cpp

    r99375 r99810  
    285285void CodeBlock::printStructure(const char* name, const Instruction* vPC, int operand) const
    286286{
    287     unsigned instructionOffset = vPC - m_instructions.begin();
     287    unsigned instructionOffset = vPC - instructions().begin();
    288288    printf("  [%4d] %s: %s\n", instructionOffset, name, pointerToSourceString(vPC[operand].u.structure).utf8().data());
    289289}
     
    292292{
    293293    Interpreter* interpreter = m_globalData->interpreter;
    294     unsigned instructionOffset = vPC - m_instructions.begin();
     294    unsigned instructionOffset = vPC - instructions().begin();
    295295
    296296    if (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id)) {
     
    337337void CodeBlock::dump(ExecState* exec) const
    338338{
    339     if (m_instructions.isEmpty()) {
     339    if (!m_instructions) {
    340340        printf("No instructions available.\n");
    341341        return;
     
    344344    size_t instructionCount = 0;
    345345
    346     for (size_t i = 0; i < m_instructions.size(); i += opcodeLengths[exec->interpreter()->getOpcodeID(m_instructions[i].u.opcode)])
     346    for (size_t i = 0; i < instructions().size(); i += opcodeLengths[exec->interpreter()->getOpcodeID(instructions()[i].u.opcode)])
    347347        ++instructionCount;
    348348
    349349    printf("%lu m_instructions; %lu bytes at %p; %d parameter(s); %d callee register(s)\n\n",
    350350        static_cast<unsigned long>(instructionCount),
    351         static_cast<unsigned long>(m_instructions.size() * sizeof(Instruction)),
     351        static_cast<unsigned long>(instructions().size() * sizeof(Instruction)),
    352352        this, m_numParameters, m_numCalleeRegisters);
    353353
    354     Vector<Instruction>::const_iterator begin = m_instructions.begin();
    355     Vector<Instruction>::const_iterator end = m_instructions.end();
     354    Vector<Instruction>::const_iterator begin = instructions().begin();
     355    Vector<Instruction>::const_iterator end = instructions().end();
    356356    for (Vector<Instruction>::const_iterator it = begin; it != end; ++it)
    357357        dump(exec, begin, it);
     
    391391        size_t i = 0;
    392392        do {
    393              printGlobalResolveInfo(m_globalResolveInfos[i], instructionOffsetForNth(exec, m_instructions, i + 1, isGlobalResolve));
     393             printGlobalResolveInfo(m_globalResolveInfos[i], instructionOffsetForNth(exec, instructions(), i + 1, isGlobalResolve));
    394394             ++i;
    395395        } while (i < m_globalResolveInfos.size());
     
    398398        size_t i = 0;
    399399        do {
    400             printStructureStubInfo(m_structureStubInfos[i], instructionOffsetForNth(exec, m_instructions, i + 1, isPropertyAccess));
     400            printStructureStubInfo(m_structureStubInfos[i], instructionOffsetForNth(exec, instructions(), i + 1, isPropertyAccess));
    401401             ++i;
    402402        } while (i < m_structureStubInfos.size());
     
    410410        size_t i = 0;
    411411        do {
    412              printStructures(&m_instructions[m_globalResolveInstructions[i]]);
     412             printStructures(&instructions()[m_globalResolveInstructions[i]]);
    413413             ++i;
    414414        } while (i < m_globalResolveInstructions.size());
     
    417417        size_t i = 0;
    418418        do {
    419             printStructures(&m_instructions[m_propertyAccessInstructions[i]]);
     419            printStructures(&instructions()[m_propertyAccessInstructions[i]]);
    420420             ++i;
    421421        } while (i < m_propertyAccessInstructions.size());
     
    14171417    , m_ownerExecutable(globalObject->globalData(), ownerExecutable, ownerExecutable)
    14181418    , m_globalData(0)
    1419 #ifndef NDEBUG
     1419    , m_instructions(adoptRef(new Instructions))
    14201420    , m_instructionCount(0)
    1421 #endif
    14221421    , m_argumentsRegister(-1)
    14231422    , m_needsFullScopeChain(ownerExecutable->needsActivation())
     
    15551554#if ENABLE(INTERPRETER)
    15561555    for (size_t size = m_propertyAccessInstructions.size(), i = 0; i < size; ++i)
    1557         visitStructures(visitor, &m_instructions[m_propertyAccessInstructions[i]]);
     1556        visitStructures(visitor, &instructions()[m_propertyAccessInstructions[i]]);
    15581557    for (size_t size = m_globalResolveInstructions.size(), i = 0; i < size; ++i)
    1559         visitStructures(visitor, &m_instructions[m_globalResolveInstructions[i]]);
     1558        visitStructures(visitor, &instructions()[m_globalResolveInstructions[i]]);
    15601559#endif
    15611560#if ENABLE(JIT)
     
    17231722void CodeBlock::shrinkToFit()
    17241723{
    1725     m_instructions.shrinkToFit();
     1724    instructions().shrinkToFit();
    17261725
    17271726#if ENABLE(INTERPRETER)
  • trunk/Source/JavaScriptCore/bytecode/CodeBlock.h

    r99787 r99810  
    439439        bool isNumericCompareFunction() { return m_isNumericCompareFunction; }
    440440
    441         Vector<Instruction>& instructions() { return m_instructions; }
     441        bool hasInstructions() const { return !!m_instructions; }
     442        unsigned numberOfInstructions() const { return !m_instructions ? 0 : m_instructions->m_instructions.size(); }
     443        Vector<Instruction>& instructions() { return m_instructions->m_instructions; }
     444        const Vector<Instruction>& instructions() const { return m_instructions->m_instructions; }
    442445        void discardBytecode() { m_instructions.clear(); }
    443446
     
    10161019        JSGlobalData* m_globalData;
    10171020
    1018         Vector<Instruction> m_instructions;
     1021        struct Instructions : public RefCounted<Instructions> {
     1022            Vector<Instruction> m_instructions;
     1023        };
     1024        RefPtr<Instructions> m_instructions;
    10191025        unsigned m_instructionCount;
    10201026
  • trunk/Source/JavaScriptCore/jit/JIT.cpp

    r99633 r99810  
    7474    , m_globalData(globalData)
    7575    , m_codeBlock(codeBlock)
    76     , m_labels(codeBlock ? codeBlock->instructions().size() : 0)
     76    , m_labels(codeBlock ? codeBlock->numberOfInstructions() : 0)
    7777    , m_bytecodeOffset((unsigned)-1)
    7878#if USE(JSVALUE32_64)
Note: See TracChangeset for help on using the changeset viewer.