Ignore:
Timestamp:
Apr 16, 2009, 4:36:07 AM (16 years ago)
Author:
[email protected]
Message:

Improve performance of read-write-modify operators

Reviewed by Gavin Barraclough

Implement cross scope optimisation for read-write-modify
operators, to avoid unnecessary calls to property resolve
helper functions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp

    r42337 r42574  
    223223    , m_codeType(GlobalCode)
    224224    , m_nextGlobalIndex(-1)
     225    , m_globalConstantIndex(0)
    225226    , m_globalData(&scopeChain.globalObject()->globalExec()->globalData())
    226227    , m_lastOpcodeID(op_end)
     
    305306    , m_baseScopeDepth(0)
    306307    , m_codeType(FunctionCode)
     308    , m_globalConstantIndex(0)
    307309    , m_globalData(&scopeChain.globalObject()->globalExec()->globalData())
    308310    , m_lastOpcodeID(op_end)
     
    379381    , m_baseScopeDepth(codeBlock->baseScopeDepth())
    380382    , m_codeType(EvalCode)
     383    , m_globalConstantIndex(0)
    381384    , m_globalData(&scopeChain.globalObject()->globalExec()->globalData())
    382385    , m_lastOpcodeID(op_end)
     
    755758{
    756759    return m_codeBlock->addUnexpectedConstant(v);
     760}
     761
     762RegisterID* BytecodeGenerator::emitLoadGlobalObject(RegisterID* dst, JSObject* globalObject)
     763{
     764    if (!m_globalConstantIndex)
     765        m_globalConstantIndex = m_codeBlock->addUnexpectedConstant(globalObject);
     766    emitOpcode(op_unexpected_load);
     767    instructions().append(dst->index());
     768    instructions().append(m_globalConstantIndex);
     769    return dst;
    757770}
    758771
     
    11001113RegisterID* BytecodeGenerator::emitResolveWithBase(RegisterID* baseDst, RegisterID* propDst, const Identifier& property)
    11011114{
    1102     emitOpcode(op_resolve_with_base);
    1103     instructions().append(baseDst->index());
     1115    size_t depth = 0;
     1116    int index = 0;
     1117    JSObject* globalObject = 0;
     1118    if (!findScopedProperty(property, index, depth, false, globalObject) || !globalObject) {
     1119        // We can't optimise at all :-(
     1120        emitOpcode(op_resolve_with_base);
     1121        instructions().append(baseDst->index());
     1122        instructions().append(propDst->index());
     1123        instructions().append(addConstant(property));
     1124        return baseDst;
     1125    }
     1126
     1127    bool forceGlobalResolve = false;
     1128    if (m_regeneratingForExceptionInfo) {
     1129#if ENABLE(JIT)
     1130        forceGlobalResolve = m_codeBlockBeingRegeneratedFrom->hasGlobalResolveInfoAtBytecodeOffset(instructions().size());
     1131#else
     1132        forceGlobalResolve = m_codeBlockBeingRegeneratedFrom->hasGlobalResolveInstructionAtBytecodeOffset(instructions().size());
     1133#endif
     1134    }
     1135
     1136    // Global object is the base
     1137    emitLoadGlobalObject(baseDst, globalObject);
     1138
     1139    if (index != missingSymbolMarker() && !forceGlobalResolve) {
     1140        // Directly index the property lookup across multiple scopes.
     1141        emitGetScopedVar(propDst, depth, index, globalObject);
     1142        return baseDst;
     1143    }
     1144
     1145#if ENABLE(JIT)
     1146    m_codeBlock->addGlobalResolveInfo(instructions().size());
     1147#else
     1148    m_codeBlock->addGlobalResolveInstruction(instructions().size());
     1149#endif
     1150    emitOpcode(op_resolve_global);
    11041151    instructions().append(propDst->index());
     1152    instructions().append(globalObject);
    11051153    instructions().append(addConstant(property));
     1154    instructions().append(0);
     1155    instructions().append(0);
    11061156    return baseDst;
    11071157}
Note: See TracChangeset for help on using the changeset viewer.