Changeset 36766 in webkit


Ignore:
Timestamp:
Sep 22, 2008 8:03:52 AM (16 years ago)
Author:
mjs@apple.com
Message:

JavaScriptCore:

2008-09-22 Maciej Stachowiak <mjs@apple.com>

Reviewed by Cameron Zwarich.


  • speed up instanceof operator by replacing implementsHasInstance method with a TypeInfo flag

Partial work towards <https://bugs.webkit.org/show_bug.cgi?id=20818>


2.2% speedup on EarleyBoyer benchmark.

  • API/JSCallbackConstructor.cpp:
  • API/JSCallbackConstructor.h: (JSC::JSCallbackConstructor::createStructureID):
  • API/JSCallbackFunction.cpp:
  • API/JSCallbackFunction.h: (JSC::JSCallbackFunction::createStructureID):
  • API/JSCallbackObject.h: (JSC::JSCallbackObject::createStructureID):
  • API/JSCallbackObjectFunctions.h: (JSC::::hasInstance):
  • API/JSValueRef.cpp: (JSValueIsInstanceOfConstructor):
  • JavaScriptCore.exp:
  • VM/Machine.cpp: (JSC::Machine::privateExecute): (JSC::Machine::cti_op_instanceof):
  • kjs/InternalFunction.cpp:
  • kjs/InternalFunction.h: (JSC::InternalFunction::createStructureID):
  • kjs/JSObject.cpp:
  • kjs/JSObject.h:
  • kjs/TypeInfo.h: (JSC::TypeInfo::implementsHasInstance):

WebCore:

2008-09-22 Maciej Stachowiak <mjs@apple.com>

Reviewed by Cameron Zwarich.

  • speed up instanceof operator by replacing implementsHasInstance method with a TypeInfo flag

Partial work towards <https://bugs.webkit.org/show_bug.cgi?id=20818>


2.2% speedup on EarleyBoyer benchmark.

  • bindings/js/JSQuarantinedObjectWrapper.cpp:
  • bindings/js/JSQuarantinedObjectWrapper.h: (WebCore::JSQuarantinedObjectWrapper::createStructureID):
  • bindings/scripts/CodeGeneratorJS.pm:
Location:
trunk
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/API/JSCallbackConstructor.cpp

    r36726 r36766  
    5252}
    5353
    54 bool JSCallbackConstructor::implementsHasInstance() const
    55 {
    56     return true;
    57 }
    58 
    5954static JSObject* constructJSCallback(ExecState* exec, JSObject* constructor, const ArgList& args)
    6055{
  • trunk/JavaScriptCore/API/JSCallbackConstructor.h

    r36726 r36766  
    4040    static const ClassInfo info;
    4141   
     42    static PassRefPtr<StructureID> createStructureID(JSValue* proto)
     43    {
     44        return StructureID::create(proto, TypeInfo(ObjectType, ImplementsHasInstance));
     45    }
     46
    4247private:
    43     virtual bool implementsHasInstance() const;   
    4448    virtual ConstructType getConstructData(ConstructData&);
    4549    virtual const ClassInfo* classInfo() const { return &info; }
  • trunk/JavaScriptCore/API/JSCallbackFunction.cpp

    r36726 r36766  
    4747}
    4848
    49 // InternalFunction mish-mashes constructor and function behavior -- we should
    50 // refactor the code so this override isn't necessary
    51 bool JSCallbackFunction::implementsHasInstance() const
    52 {
    53     return false;
    54 }
    55 
    5649JSValue* JSCallbackFunction::call(ExecState* exec, JSObject* functionObject, JSValue* thisValue, const ArgList& args)
    5750{
  • trunk/JavaScriptCore/API/JSCallbackFunction.h

    r36263 r36766  
    3838    static const ClassInfo info;
    3939   
     40    // InternalFunction mish-mashes constructor and function behavior -- we should
     41    // refactor the code so this override isn't necessary
     42    static PassRefPtr<StructureID> createStructureID(JSValue* proto)
     43    {
     44        return StructureID::create(proto, TypeInfo(ObjectType));
     45    }
     46
    4047private:
    41     virtual bool implementsHasInstance() const;
    4248    virtual CallType getCallData(CallData&);
    4349    virtual const ClassInfo* classInfo() const { return &info; }
  • trunk/JavaScriptCore/API/JSCallbackObject.h

    r36726 r36766  
    4949    bool inherits(JSClassRef) const;
    5050
     51    static PassRefPtr<StructureID> createStructureID(JSValue* proto)
     52    {
     53        return StructureID::create(proto, TypeInfo(ObjectType, ImplementsHasInstance));
     54    }
     55
    5156private:
    5257    virtual UString className() const;
     
    6065    virtual bool deleteProperty(ExecState*, unsigned);
    6166
    62     virtual bool implementsHasInstance() const;
    6367    virtual bool hasInstance(ExecState* exec, JSValue* value, JSValue* proto);
    6468
  • trunk/JavaScriptCore/API/JSCallbackObjectFunctions.h

    r36726 r36766  
    274274
    275275template <class Base>
    276 bool JSCallbackObject<Base>::implementsHasInstance() const
    277 {
    278     for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass)
    279         if (jsClass->hasInstance)
    280             return true;
    281    
     276bool JSCallbackObject<Base>::hasInstance(ExecState* exec, JSValue* value, JSValue*)
     277{
     278    JSContextRef execRef = toRef(exec);
     279    JSObjectRef thisRef = toRef(this);
     280   
     281    for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
     282        if (JSObjectHasInstanceCallback hasInstance = jsClass->hasInstance) {
     283            JSLock::DropAllLocks dropAllLocks(exec);
     284            return hasInstance(execRef, thisRef, toRef(value), toRef(exec->exceptionSlot()));
     285        }
     286    }
    282287    return false;
    283 }
    284 
    285 template <class Base>
    286 bool JSCallbackObject<Base>::hasInstance(ExecState* exec, JSValue* value, JSValue*)
    287 {
    288     JSContextRef execRef = toRef(exec);
    289     JSObjectRef thisRef = toRef(this);
    290    
    291     for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
    292         if (JSObjectHasInstanceCallback hasInstance = jsClass->hasInstance) {
    293             JSLock::DropAllLocks dropAllLocks(exec);
    294             return hasInstance(execRef, thisRef, toRef(value), toRef(exec->exceptionSlot()));
    295         }
    296     }
    297     ASSERT_NOT_REACHED(); // implementsHasInstance should prevent us from reaching here
    298     return 0;
    299288}
    300289
  • trunk/JavaScriptCore/API/JSValueRef.cpp

    r36417 r36766  
    145145    JSValue* jsValue = toJS(value);
    146146    JSObject* jsConstructor = toJS(constructor);
    147     if (!jsConstructor->implementsHasInstance())
     147    if (!jsConstructor->structureID()->typeInfo().implementsHasInstance())
    148148        return false;
    149149    bool result = jsConstructor->hasInstance(exec, jsValue, jsConstructor->get(exec, exec->propertyNames().prototype)); // false if an exception is thrown
  • trunk/JavaScriptCore/ChangeLog

    r36764 r36766  
     12008-09-22  Maciej Stachowiak  <mjs@apple.com>
     2
     3        Reviewed by Cameron Zwarich.
     4       
     5        - speed up instanceof operator by replacing implementsHasInstance method with a TypeInfo flag
     6
     7        Partial work towards <https://bugs.webkit.org/show_bug.cgi?id=20818>
     8       
     9        2.2% speedup on EarleyBoyer benchmark.
     10
     11        * API/JSCallbackConstructor.cpp:
     12        * API/JSCallbackConstructor.h:
     13        (JSC::JSCallbackConstructor::createStructureID):
     14        * API/JSCallbackFunction.cpp:
     15        * API/JSCallbackFunction.h:
     16        (JSC::JSCallbackFunction::createStructureID):
     17        * API/JSCallbackObject.h:
     18        (JSC::JSCallbackObject::createStructureID):
     19        * API/JSCallbackObjectFunctions.h:
     20        (JSC::::hasInstance):
     21        * API/JSValueRef.cpp:
     22        (JSValueIsInstanceOfConstructor):
     23        * JavaScriptCore.exp:
     24        * VM/Machine.cpp:
     25        (JSC::Machine::privateExecute):
     26        (JSC::Machine::cti_op_instanceof):
     27        * kjs/InternalFunction.cpp:
     28        * kjs/InternalFunction.h:
     29        (JSC::InternalFunction::createStructureID):
     30        * kjs/JSObject.cpp:
     31        * kjs/JSObject.h:
     32        * kjs/TypeInfo.h:
     33        (JSC::TypeInfo::implementsHasInstance):
     34
    1352008-09-22  Maciej Stachowiak  <mjs@apple.com>
    236
  • trunk/JavaScriptCore/JavaScriptCore.exp

    r36755 r36766  
    292292__ZNK3JSC14JSGlobalObject14isDynamicScopeEv
    293293__ZNK3JSC14JSGlobalObject14toGlobalObjectEPNS_9ExecStateE
    294 __ZNK3JSC16InternalFunction21implementsHasInstanceEv
    295294__ZNK3JSC16JSVariableObject16isVariableObjectEv
    296295__ZNK3JSC16JSVariableObject21getPropertyAttributesEPNS_9ExecStateERKNS_10IdentifierERj
     
    329328__ZNK3JSC8JSObject14toGlobalObjectEPNS_9ExecStateE
    330329__ZNK3JSC8JSObject21getPropertyAttributesEPNS_9ExecStateERKNS_10IdentifierERj
    331 __ZNK3JSC8JSObject21implementsHasInstanceEv
    332330__ZNK3JSC8JSObject8toNumberEPNS_9ExecStateE
    333331__ZNK3JSC8JSObject8toObjectEPNS_9ExecStateE
  • trunk/JavaScriptCore/VM/Machine.cpp

    r36764 r36766  
    21242124
    21252125        JSObject* baseObj = static_cast<JSObject*>(baseVal);
    2126         r[dst] = jsBoolean(baseObj->implementsHasInstance() ? baseObj->hasInstance(exec, r[value].jsValue(exec), r[baseProto].jsValue(exec)) : false);
     2126        r[dst] = jsBoolean(baseObj->structureID()->typeInfo().implementsHasInstance() ? baseObj->hasInstance(exec, r[value].jsValue(exec), r[baseProto].jsValue(exec)) : false);
    21272127
    21282128        ++vPC;
     
    43054305    JSObject* baseObj = static_cast<JSObject*>(baseVal);
    43064306    JSValue* basePrototype = ARG_src3;
    4307     JSValue* result = jsBoolean(baseObj->implementsHasInstance() ? baseObj->hasInstance(exec,  ARG_src1, basePrototype) : false);
     4307    JSValue* result = jsBoolean(baseObj->structureID()->typeInfo().implementsHasInstance() ? baseObj->hasInstance(exec,  ARG_src1, basePrototype) : false);
    43084308    VM_CHECK_EXCEPTION_AT_END();
    43094309    return result;
  • trunk/JavaScriptCore/kjs/InternalFunction.cpp

    r36726 r36766  
    5252}
    5353
    54 bool InternalFunction::implementsHasInstance() const
    55 {
    56     return true;
    57 }
    58 
    5954} // namespace JSC
  • trunk/JavaScriptCore/kjs/InternalFunction.h

    r36726 r36766  
    3939        const UString& name(ExecState*);
    4040
     41        static PassRefPtr<StructureID> createStructureID(JSValue* proto)
     42        {
     43            return StructureID::create(proto, TypeInfo(ObjectType, ImplementsHasInstance));
     44        }
     45
    4146    protected:
    4247        InternalFunction(PassRefPtr<StructureID> structure) : JSObject(structure) { }
     
    4651    private:
    4752        virtual CallType getCallData(CallData&) = 0;
    48         virtual bool implementsHasInstance() const;
    4953    };
    5054
  • trunk/JavaScriptCore/kjs/JSObject.cpp

    r36755 r36766  
    385385}
    386386
    387 bool JSObject::implementsHasInstance() const
    388 {
    389     return false;
    390 }
    391 
    392387bool JSObject::hasInstance(ExecState* exec, JSValue* value, JSValue* proto)
    393388{
  • trunk/JavaScriptCore/kjs/JSObject.h

    r36755 r36766  
    104104        virtual JSValue* defaultValue(ExecState*, PreferredPrimitiveType) const;
    105105
    106         virtual bool implementsHasInstance() const;
    107106        virtual bool hasInstance(ExecState*, JSValue*, JSValue* prototypeProperty);
    108107
  • trunk/JavaScriptCore/kjs/TypeInfo.h

    r36764 r36766  
    3434    // WebCore uses this to make document.all and style.filter undetectable.
    3535    static const unsigned MasqueradesAsUndefined = 0x1;
     36    static const unsigned ImplementsHasInstance = 0x2;
    3637
    3738    class TypeInfo {
     
    4344
    4445        bool masqueradesAsUndefined() const { return m_flags & MasqueradesAsUndefined; }
     46        bool implementsHasInstance() const { return m_flags & ImplementsHasInstance; }
    4547
    4648    private:
  • trunk/WebCore/ChangeLog

    r36765 r36766  
     12008-09-22  Maciej Stachowiak  <mjs@apple.com>
     2
     3        Reviewed by Cameron Zwarich.
     4
     5        - speed up instanceof operator by replacing implementsHasInstance method with a TypeInfo flag
     6
     7        Partial work towards <https://bugs.webkit.org/show_bug.cgi?id=20818>
     8       
     9        2.2% speedup on EarleyBoyer benchmark.
     10
     11        * bindings/js/JSQuarantinedObjectWrapper.cpp:
     12        * bindings/js/JSQuarantinedObjectWrapper.h:
     13        (WebCore::JSQuarantinedObjectWrapper::createStructureID):
     14        * bindings/scripts/CodeGeneratorJS.pm:
     15
    1162008-09-22  Adam Roben  <aroben@apple.com>
    217
  • trunk/WebCore/bindings/js/JSQuarantinedObjectWrapper.cpp

    r36675 r36766  
    220220}
    221221
    222 bool JSQuarantinedObjectWrapper::implementsHasInstance() const
    223 {
    224     return m_unwrappedObject->implementsHasInstance();
    225 }
    226 
    227222bool JSQuarantinedObjectWrapper::hasInstance(ExecState* exec, JSValue* value, JSValue* proto)
    228223{
  • trunk/WebCore/bindings/js/JSQuarantinedObjectWrapper.h

    r36675 r36766  
    4545        static const JSC::ClassInfo s_info;
    4646
     47        static PassRefPtr<JSC::StructureID> createStructureID(JSC::JSValue* proto)
     48        {
     49            return JSC::StructureID::create(proto, JSC::TypeInfo(JSC::ObjectType, JSC::ImplementsHasInstance));
     50        }
     51
    4752    protected:
    4853        JSQuarantinedObjectWrapper(JSC::ExecState* unwrappedExec, JSC::JSObject* unwrappedObject, PassRefPtr<JSC::StructureID>);
     
    6368        virtual JSC::ConstructType getConstructData(JSC::ConstructData&);
    6469
    65         virtual bool implementsHasInstance() const;
    6670        virtual bool hasInstance(JSC::ExecState*, JSC::JSValue*, JSC::JSValue* proto);
    6771
  • trunk/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r36755 r36766  
    18211821    static const ClassInfo s_info;
    18221822
    1823     virtual bool implementsHasInstance() const { return true; }
     1823    static PassRefPtr<StructureID> createStructureID(JSValue* proto)
     1824    {
     1825        return StructureID::create(proto, TypeInfo(ObjectType, ImplementsHasInstance));
     1826    }
    18241827EOF
    18251828
Note: See TracChangeset for help on using the changeset viewer.