Ignore:
Timestamp:
Dec 12, 2008, 12:02:09 AM (16 years ago)
Author:
[email protected]
Message:

2008-12-11 Sam Weinig <[email protected]>

Reviewed by Geoffrey Garen.

Remove dependancy on having the Instruction buffer in order to
deref Structures used for property access and global resolves.
Instead, we put references to the necessary Structures in axillary
data structures on the CodeBlock. This is not an ideal solution,
as we still pay for having the Structures in two places and we
would like to eventually just hold on to offsets into the machine
code buffer.

  • Also removes CodeBlock bloat in non-JIT by #ifdefing the JIT only data structures.
  • GNUmakefile.am:
  • JavaScriptCore.pri:
  • JavaScriptCore.scons:
  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • JavaScriptCoreSources.bkl:
  • bytecode/CodeBlock.cpp: (JSC::isGlobalResolve): (JSC::isPropertyAccess): (JSC::instructionOffsetForNth): (JSC::printGlobalResolveInfo): (JSC::printStructureStubInfo): (JSC::CodeBlock::printStructures): (JSC::CodeBlock::dump): (JSC::CodeBlock::~CodeBlock): (JSC::CodeBlock::shrinkToFit):
  • bytecode/CodeBlock.h: (JSC::GlobalResolveInfo::GlobalResolveInfo): (JSC::getNativePC): (JSC::CodeBlock::instructions): (JSC::CodeBlock::getStubInfo): (JSC::CodeBlock::getBytecodeIndex): (JSC::CodeBlock::addPropertyAccessInstruction): (JSC::CodeBlock::addGlobalResolveInstruction): (JSC::CodeBlock::numberOfStructureStubInfos): (JSC::CodeBlock::addStructureStubInfo): (JSC::CodeBlock::structureStubInfo): (JSC::CodeBlock::addGlobalResolveInfo): (JSC::CodeBlock::globalResolveInfo): (JSC::CodeBlock::numberOfCallLinkInfos): (JSC::CodeBlock::addCallLinkInfo): (JSC::CodeBlock::callLinkInfo):
  • bytecode/Instruction.h: (JSC::PolymorphicAccessStructureList::PolymorphicStubInfo::set): (JSC::PolymorphicAccessStructureList::PolymorphicAccessStructureList):
  • bytecode/Opcode.h: (JSC::):
  • bytecode/StructureStubInfo.cpp: Copied from bytecode/CodeBlock.cpp. (JSC::StructureStubInfo::deref):
  • bytecode/StructureStubInfo.h: Copied from bytecode/CodeBlock.h. (JSC::StructureStubInfo::StructureStubInfo): (JSC::StructureStubInfo::initGetByIdSelf): (JSC::StructureStubInfo::initGetByIdProto): (JSC::StructureStubInfo::initGetByIdChain): (JSC::StructureStubInfo::initGetByIdSelfList): (JSC::StructureStubInfo::initGetByIdProtoList): (JSC::StructureStubInfo::initPutByIdTransition): (JSC::StructureStubInfo::initPutByIdReplace): (JSC::StructureStubInfo::):
  • bytecompiler/BytecodeGenerator.cpp: (JSC::BytecodeGenerator::emitResolve): (JSC::BytecodeGenerator::emitGetById): (JSC::BytecodeGenerator::emitPutById): (JSC::BytecodeGenerator::emitCall): (JSC::BytecodeGenerator::emitConstruct): (JSC::BytecodeGenerator::emitCatch):
  • interpreter/Interpreter.cpp: (JSC::Interpreter::tryCTICachePutByID): (JSC::Interpreter::tryCTICacheGetByID): (JSC::Interpreter::cti_op_get_by_id_self_fail): (JSC::getPolymorphicAccessStructureListSlot): (JSC::Interpreter::cti_op_get_by_id_proto_list): (JSC::Interpreter::cti_op_resolve_global):
  • jit/JIT.cpp: (JSC::JIT::JIT): (JSC::JIT::privateCompileMainPass): (JSC::JIT::privateCompileSlowCases): (JSC::JIT::privateCompile):
  • jit/JITPropertyAccess.cpp: (JSC::JIT::compileGetByIdHotPath): (JSC::JIT::compilePutByIdHotPath): (JSC::JIT::compileGetByIdSlowCase): (JSC::JIT::compilePutByIdSlowCase): (JSC::JIT::privateCompileGetByIdSelfList): (JSC::JIT::privateCompileGetByIdProtoList): (JSC::JIT::privateCompileGetByIdChainList):
File:
1 edited

Legend:

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

    r39182 r39229  
    176176}
    177177
     178#if ENABLE(JIT)
     179static bool isGlobalResolve(OpcodeID opcodeID)
     180{
     181    return opcodeID == op_resolve_global;
     182}
     183
     184static bool isPropertyAccess(OpcodeID opcodeID)
     185{
     186    switch (opcodeID) {
     187        case op_get_by_id_self:
     188        case op_get_by_id_proto:
     189        case op_get_by_id_chain:
     190        case op_get_by_id_self_list:
     191        case op_get_by_id_proto_list:
     192        case op_put_by_id_transition:
     193        case op_put_by_id_replace:
     194        case op_get_by_id:
     195        case op_put_by_id:
     196        case op_get_by_id_generic:
     197        case op_put_by_id_generic:
     198        case op_get_array_length:
     199        case op_get_string_length:
     200            return true;
     201        default:
     202            return false;
     203    }
     204}
     205
     206static unsigned instructionOffsetForNth(ExecState* exec, const Vector<Instruction>& instructions, int nth, bool (*predicate)(OpcodeID))
     207{
     208    size_t i = 0;
     209    while (i < instructions.size()) {
     210        OpcodeID currentOpcode = exec->interpreter()->getOpcodeID(instructions[i].u.opcode);
     211        if (predicate(exec->interpreter()->getOpcodeID(instructions[i].u.opcode))) {
     212            if (!--nth)
     213                return i;
     214        }
     215        i += opcodeLengths[currentOpcode];
     216    }
     217
     218    ASSERT_NOT_REACHED();
     219    return 0;
     220}
     221
     222static void printGlobalResolveInfo(const GlobalResolveInfo& resolveInfo, unsigned instructionOffset)
     223{
     224    printf("  [%4d] %s: %s\n", instructionOffset, "resolve_global", pointerToSourceString(resolveInfo.structure).UTF8String().c_str());
     225}
     226
     227static void printStructureStubInfo(const StructureStubInfo& stubInfo, unsigned instructionOffset)
     228{
     229    switch (stubInfo.opcodeID) {
     230    case op_get_by_id_self:
     231        printf("  [%4d] %s: %s\n", instructionOffset, "get_by_id_self", pointerToSourceString(stubInfo.u.getByIdSelf.baseObjectStructure).UTF8String().c_str());
     232        return;
     233    case op_get_by_id_proto:
     234        printf("  [%4d] %s: %s, %s\n", instructionOffset, "get_by_id_proto", pointerToSourceString(stubInfo.u.getByIdProto.baseObjectStructure).UTF8String().c_str(), pointerToSourceString(stubInfo.u.getByIdProto.prototypeStructure).UTF8String().c_str());
     235        return;
     236    case op_get_by_id_chain:
     237        printf("  [%4d] %s: %s, %s\n", instructionOffset, "get_by_id_chain", pointerToSourceString(stubInfo.u.getByIdChain.baseObjectStructure).UTF8String().c_str(), pointerToSourceString(stubInfo.u.getByIdChain.chain).UTF8String().c_str());
     238        return;
     239    case op_get_by_id_self_list:
     240        printf("  [%4d] %s: %s (%d)\n", instructionOffset, "op_get_by_id_self_list", pointerToSourceString(stubInfo.u.getByIdSelfList.structureList).UTF8String().c_str(), stubInfo.u.getByIdSelfList.listSize);
     241        return;
     242    case op_get_by_id_proto_list:
     243        printf("  [%4d] %s: %s (%d)\n", instructionOffset, "op_get_by_id_proto_list", pointerToSourceString(stubInfo.u.getByIdProtoList.structureList).UTF8String().c_str(), stubInfo.u.getByIdProtoList.listSize);
     244        return;
     245    case op_put_by_id_transition:
     246        printf("  [%4d] %s: %s, %s, %s\n", instructionOffset, "put_by_id_transition", pointerToSourceString(stubInfo.u.putByIdTransition.previousStructure).UTF8String().c_str(), pointerToSourceString(stubInfo.u.putByIdTransition.structure).UTF8String().c_str(), pointerToSourceString(stubInfo.u.putByIdTransition.chain).UTF8String().c_str());
     247        return;
     248    case op_put_by_id_replace:
     249        printf("  [%4d] %s: %s\n", instructionOffset, "put_by_id_replace", pointerToSourceString(stubInfo.u.putByIdReplace.baseObjectStructure).UTF8String().c_str());
     250        return;
     251    case op_get_by_id:
     252        printf("  [%4d] %s\n", instructionOffset, "get_by_id");
     253        return;
     254    case op_put_by_id:
     255        printf("  [%4d] %s\n", instructionOffset, "put_by_id");
     256        return;
     257    case op_get_by_id_generic:
     258        printf("  [%4d] %s\n", instructionOffset, "op_get_by_id_generic");
     259        return;
     260    case op_put_by_id_generic:
     261        printf("  [%4d] %s\n", instructionOffset, "op_put_by_id_generic");
     262        return;
     263    case op_get_array_length:
     264        printf("  [%4d] %s\n", instructionOffset, "op_get_array_length");
     265        return;
     266    case op_get_string_length:
     267        printf("  [%4d] %s\n", instructionOffset, "op_get_string_length");
     268        return;
     269    default:
     270        ASSERT_NOT_REACHED();
     271    }
     272}
     273#endif
     274
    178275void CodeBlock::printStructure(const char* name, const Instruction* vPC, int operand) const
    179276{
     
    200297    }
    201298    if (vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id_transition)) {
    202         printf("  [%4d] %s: %s, %s, %s\n", instructionOffset, "put_by_id_new", pointerToSourceString(vPC[4].u.structure).UTF8String().c_str(), pointerToSourceString(vPC[5].u.structure).UTF8String().c_str(), pointerToSourceString(vPC[6].u.structureChain).UTF8String().c_str());
     299        printf("  [%4d] %s: %s, %s, %s\n", instructionOffset, "put_by_id_transition", pointerToSourceString(vPC[4].u.structure).UTF8String().c_str(), pointerToSourceString(vPC[5].u.structure).UTF8String().c_str(), pointerToSourceString(vPC[6].u.structureChain).UTF8String().c_str());
    203300        return;
    204301    }
     
    226323void CodeBlock::dump(ExecState* exec) const
    227324{
    228     Vector<Instruction>::const_iterator begin = m_instructions.begin();
    229     Vector<Instruction>::const_iterator end = m_instructions.end();
    230 
    231325    size_t instructionCount = 0;
    232     for (Vector<Instruction>::const_iterator it = begin; it != end; ++it)
    233         if (exec->interpreter()->isOpcode(it->u.opcode))
    234             ++instructionCount;
     326
     327    for (size_t i = 0; i < m_instructions.size(); i += opcodeLengths[exec->interpreter()->getOpcodeID(m_instructions[i].u.opcode)])
     328        ++instructionCount;
    235329
    236330    printf("%lu m_instructions; %lu bytes at %p; %d parameter(s); %d callee register(s)\n\n",
     
    238332        static_cast<unsigned long>(m_instructions.size() * sizeof(Instruction)),
    239333        this, m_numParameters, m_numCalleeRegisters);
    240    
     334
     335    Vector<Instruction>::const_iterator begin = m_instructions.begin();
     336    Vector<Instruction>::const_iterator end = m_instructions.end();
    241337    for (Vector<Instruction>::const_iterator it = begin; it != end; ++it)
    242338        dump(exec, begin, it);
     
    280376    }
    281377
     378#if ENABLE(JIT)
     379    if (!m_globalResolveInfos.isEmpty() || !m_structureStubInfos.isEmpty())
     380        printf("\nStructures:\n");
     381
     382    if (!m_globalResolveInfos.isEmpty()) {
     383        size_t i = 0;
     384        do {
     385             printGlobalResolveInfo(m_globalResolveInfos[i], instructionOffsetForNth(exec, m_instructions, i + 1, isGlobalResolve));
     386             ++i;
     387        } while (i < m_globalResolveInfos.size());
     388    }
     389    if (!m_structureStubInfos.isEmpty()) {
     390        size_t i = 0;
     391        do {
     392            printStructureStubInfo(m_structureStubInfos[i], instructionOffsetForNth(exec, m_instructions, i + 1, isPropertyAccess));
     393             ++i;
     394        } while (i < m_structureStubInfos.size());
     395    }
     396#else
    282397    if (!m_globalResolveInstructions.isEmpty() || !m_propertyAccessInstructions.isEmpty())
    283398        printf("\nStructures:\n");
     
    293408        size_t i = 0;
    294409        do {
    295              printStructures(&m_instructions[m_propertyAccessInstructions[i].bytecodeIndex]);
     410            printStructures(&m_instructions[m_propertyAccessInstructions[i]]);
    296411             ++i;
    297412        } while (i < m_propertyAccessInstructions.size());
    298413    }
    299  
     414#endif
     415
    300416    if (m_rareData && !m_rareData->m_exceptionHandlers.isEmpty()) {
    301417        printf("\nException Handlers:\n");
     
    9631079#define FOR_EACH_MEMBER_VECTOR(macro) \
    9641080    macro(instructions) \
    965     macro(globalResolveInstructions) \
    966     macro(propertyAccessInstructions) \
     1081    macro(globalResolveInfos) \
     1082    macro(structureStubInfos) \
    9671083    macro(callLinkInfos) \
    9681084    macro(linkedCallerList) \
     
    10751191CodeBlock::~CodeBlock()
    10761192{
     1193#if !ENABLE(JIT)
    10771194    for (size_t size = m_globalResolveInstructions.size(), i = 0; i < size; ++i)
    10781195        derefStructures(&m_instructions[m_globalResolveInstructions[i]]);
    10791196
    1080     for (size_t size = m_propertyAccessInstructions.size(), i = 0; i < size; ++i) {
    1081         derefStructures(&m_instructions[m_propertyAccessInstructions[i].bytecodeIndex]);
    1082     }
     1197    for (size_t size = m_propertyAccessInstructions.size(), i = 0; i < size; ++i)
     1198        derefStructures(&m_instructions[m_propertyAccessInstructions[i]]);
     1199#else
     1200    for (size_t size = m_globalResolveInfos.size(), i = 0; i < size; ++i) {
     1201        if (m_globalResolveInfos[i].structure)
     1202            m_globalResolveInfos[i].structure->deref();
     1203    }
     1204
     1205    for (size_t size = m_structureStubInfos.size(), i = 0; i < size; ++i)
     1206        m_structureStubInfos[i].deref();
    10831207
    10841208    for (size_t size = m_callLinkInfos.size(), i = 0; i < size; ++i) {
     
    10881212    }
    10891213
    1090 #if ENABLE(JIT)
    10911214    unlinkCallers();
    10921215#endif
     
    12911414    m_instructions.shrinkToFit();
    12921415
     1416#if !ENABLE(JIT)
     1417    m_propertyAccessInstructions.shrinkToFit();
    12931418    m_globalResolveInstructions.shrinkToFit();
    1294     m_propertyAccessInstructions.shrinkToFit();
     1419#else
     1420    m_structureStubInfos.shrinkToFit();
     1421    m_globalResolveInfos.shrinkToFit();
    12951422    m_callLinkInfos.shrinkToFit();
    12961423    m_linkedCallerList.shrinkToFit();
     1424#endif
     1425
    12971426    m_expressionInfo.shrinkToFit();
    12981427    m_lineInfo.shrinkToFit();
     1428
    12991429    m_identifiers.shrinkToFit();
    13001430    m_functionExpressions.shrinkToFit();
Note: See TracChangeset for help on using the changeset viewer.