Changeset 36802 in webkit for trunk/JavaScriptCore/VM/Machine.cpp


Ignore:
Timestamp:
Sep 23, 2008, 12:46:55 AM (17 years ago)
Author:
[email protected]
Message:

JavaScriptCore:

2008-09-23 Maciej Stachowiak <[email protected]>

Reviewed by Darin.


~2% speedup on EarleyBoyer

The idea here is to record in the StructureID whether the class
needs a special hasInstance or if it can use the normal logic from
JSObject.


Based on this I inlined the real work directly into
cti_op_instanceof and put the fastest checks up front and the
error handling at the end (so it should be fairly straightforward
to split off the beginning to be inlined if desired).

I only did this for CTI, not the bytecode interpreter.


  • API/JSCallbackObject.h: (JSC::JSCallbackObject::createStructureID):
  • ChangeLog:
  • VM/Machine.cpp: (JSC::Machine::cti_op_instanceof):
  • kjs/JSImmediate.h: (JSC::JSImmediate::isAnyImmediate):
  • kjs/TypeInfo.h: (JSC::TypeInfo::overridesHasInstance): (JSC::TypeInfo::flags):

WebCore:

2008-09-23 Maciej Stachowiak <[email protected]>

Reviewed by Darin.

~2% speedup on EarleyBoyer

(WebCore updates.)


  • bindings/js/JSQuarantinedObjectWrapper.h: (WebCore::JSQuarantinedObjectWrapper::createStructureID):
File:
1 edited

Legend:

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

    r36766 r36802  
    42934293{
    42944294    ExecState* exec = ARG_exec;
     4295    JSValue* value = ARG_src1;
    42954296    JSValue* baseVal = ARG_src2;
    4296 
     4297    JSValue* proto = ARG_src3;
     4298
     4299    if (UNLIKELY(JSImmediate::isAnyImmediate(value, baseVal, proto)))
     4300        goto slow_cases;
     4301
     4302    JSCell* valueCell = static_cast<JSCell*>(value);
     4303    JSCell* baseCell = static_cast<JSCell*>(baseVal);
     4304    JSCell* protoCell = static_cast<JSCell*>(proto);
     4305
     4306    if (UNLIKELY(!valueCell->isObject() | !baseCell->isObject() | !protoCell->isObject()))
     4307        goto slow_cases;
     4308
     4309    if (UNLIKELY((baseCell->structureID()->typeInfo().flags() & (ImplementsHasInstance | OverridesHasInstance)) != ImplementsHasInstance))
     4310        goto slow_cases;
     4311
     4312    JSObject* testPrototype = static_cast<JSObject*>(static_cast<JSObject*>(valueCell)->prototype());
     4313
     4314    if (testPrototype == proto)
     4315        return jsBoolean(true);
     4316
     4317    while (testPrototype != jsNull()) {
     4318        testPrototype = static_cast<JSObject*>(testPrototype->prototype());
     4319        if (testPrototype == proto)
     4320            return jsBoolean(true);
     4321    }
     4322
     4323    return jsBoolean(false);
     4324
     4325 slow_cases:     
    42974326    if (!baseVal->isObject()) {
    42984327        CodeBlock* codeBlock = ARG_codeBlock;
     
    43034332    }
    43044333
    4305     JSObject* baseObj = static_cast<JSObject*>(baseVal);
    4306     JSValue* basePrototype = ARG_src3;
    4307     JSValue* result = jsBoolean(baseObj->structureID()->typeInfo().implementsHasInstance() ? baseObj->hasInstance(exec,  ARG_src1, basePrototype) : false);
     4334    baseCell = static_cast<JSCell*>(baseVal);
     4335    if (!baseCell->structureID()->typeInfo().implementsHasInstance())
     4336        return jsBoolean(false);
     4337
     4338    if (!proto->isObject()) {
     4339        throwError(exec, TypeError, "instanceof called on an object with an invalid prototype property.");
     4340        VM_CHECK_EXCEPTION(JSValue*);
     4341    }
     4342       
     4343    if (!value->isObject())
     4344        return jsBoolean(false);
     4345
     4346    ASSERT(baseCell->structureID()->typeInfo().implementsHasInstance());
     4347
     4348    JSValue* result = jsBoolean(static_cast<JSObject*>(baseCell)->hasInstance(exec, value, proto));
    43084349    VM_CHECK_EXCEPTION_AT_END();
     4350
    43094351    return result;
    43104352}
Note: See TracChangeset for help on using the changeset viewer.