Ignore:
Timestamp:
Sep 10, 2008, 2:23:35 AM (17 years ago)
Author:
[email protected]
Message:

Add optimised access to known properties on the global object.

Reviewed by Maciej Stachowiak

Improve cross scope access to the global object by emitting
code to access it directly rather than by walking the scope chain.

This is a 0.8% win in SunSpider and a 1.7% win in the v8 benchmarks.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/VM/CodeGenerator.cpp

    r36263 r36317  
    678678}
    679679
    680 bool CodeGenerator::findScopedProperty(const Identifier& property, int& index, size_t& stackDepth, bool forWriting)
     680bool CodeGenerator::findScopedProperty(const Identifier& property, int& index, size_t& stackDepth, bool forWriting, JSValue*& globalObject)
    681681{
    682682    // Cases where we cannot optimise the lookup
     
    703703                stackDepth = 0;
    704704                index = missingSymbolMarker();
     705                if (++iter == end)
     706                    globalObject = currentVariableObject;
    705707                return false;
    706708            }
    707709            stackDepth = depth;
    708710            index = entry.getIndex();
     711            if (++iter == end)
     712                globalObject = currentVariableObject;
    709713            return true;
    710714        }
     
    716720    stackDepth = depth;
    717721    index = missingSymbolMarker();
     722    JSObject* scope = *iter;
     723    if (++iter == end)
     724        globalObject = scope;
    718725    return true;
    719726}
     
    723730    size_t depth = 0;
    724731    int index = 0;
    725     if (!findScopedProperty(property, index, depth, false)) {
     732    JSValue* globalObject = 0;
     733    if (!findScopedProperty(property, index, depth, false, globalObject)) {
    726734        // We can't optimise at all :-(
    727735        emitOpcode(op_resolve);
     
    742750
    743751    // Directly index the property lookup across multiple scopes.  Yay!
    744     return emitGetScopedVar(dst, depth, index);
    745 }
    746 
    747 RegisterID* CodeGenerator::emitGetScopedVar(RegisterID* dst, size_t depth, int index)
    748 {
     752    return emitGetScopedVar(dst, depth, index, globalObject);
     753}
     754
     755RegisterID* CodeGenerator::emitGetScopedVar(RegisterID* dst, size_t depth, int index, JSValue* globalObject)
     756{
     757    if (globalObject) {
     758        emitOpcode(op_get_global_var);
     759        instructions().append(dst->index());
     760        instructions().append(static_cast<JSCell*>(globalObject));
     761        instructions().append(index);
     762        return dst;
     763    }
     764
    749765    emitOpcode(op_get_scoped_var);
    750766    instructions().append(dst->index());
     
    754770}
    755771
    756 RegisterID* CodeGenerator::emitPutScopedVar(size_t depth, int index, RegisterID* value)
    757 {
     772RegisterID* CodeGenerator::emitPutScopedVar(size_t depth, int index, RegisterID* value, JSValue* globalObject)
     773{
     774    if (globalObject) {
     775        emitOpcode(op_put_global_var);
     776        instructions().append(static_cast<JSCell*>(globalObject));
     777        instructions().append(index);
     778        instructions().append(value->index());
     779        return value;
     780    }
    758781    emitOpcode(op_put_scoped_var);
    759782    instructions().append(index);
Note: See TracChangeset for help on using the changeset viewer.