JavaScriptCore:
authormjs@apple.com <mjs@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 22 Sep 2008 15:03:52 +0000 (15:03 +0000)
committermjs@apple.com <mjs@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 22 Sep 2008 15:03:52 +0000 (15:03 +0000)
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:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@36766 268f45cc-cd09-0410-ab3c-d52691b4dbfc

19 files changed:
JavaScriptCore/API/JSCallbackConstructor.cpp
JavaScriptCore/API/JSCallbackConstructor.h
JavaScriptCore/API/JSCallbackFunction.cpp
JavaScriptCore/API/JSCallbackFunction.h
JavaScriptCore/API/JSCallbackObject.h
JavaScriptCore/API/JSCallbackObjectFunctions.h
JavaScriptCore/API/JSValueRef.cpp
JavaScriptCore/ChangeLog
JavaScriptCore/JavaScriptCore.exp
JavaScriptCore/VM/Machine.cpp
JavaScriptCore/kjs/InternalFunction.cpp
JavaScriptCore/kjs/InternalFunction.h
JavaScriptCore/kjs/JSObject.cpp
JavaScriptCore/kjs/JSObject.h
JavaScriptCore/kjs/TypeInfo.h
WebCore/ChangeLog
WebCore/bindings/js/JSQuarantinedObjectWrapper.cpp
WebCore/bindings/js/JSQuarantinedObjectWrapper.h
WebCore/bindings/scripts/CodeGeneratorJS.pm

index 805f60377e473c6af3bb90e2a494a5c4afc0e978..974c1e7ca88b79bac913bc02c6f55c2d2ae74455 100644 (file)
@@ -51,11 +51,6 @@ JSCallbackConstructor::~JSCallbackConstructor()
         JSClassRelease(m_class);
 }
 
-bool JSCallbackConstructor::implementsHasInstance() const
-{
-    return true;
-}
-
 static JSObject* constructJSCallback(ExecState* exec, JSObject* constructor, const ArgList& args)
 {
     JSContextRef ctx = toRef(exec);
index a319550e6589a161ea5746f2481f6411d2b5e2d2..c54e3ed2cb6b42d308186ffe0d9c4ad55b3db4e7 100644 (file)
@@ -39,8 +39,12 @@ public:
     JSObjectCallAsConstructorCallback callback() const { return m_callback; }
     static const ClassInfo info;
     
+    static PassRefPtr<StructureID> createStructureID(JSValue* proto) 
+    { 
+        return StructureID::create(proto, TypeInfo(ObjectType, ImplementsHasInstance)); 
+    }
+
 private:
-    virtual bool implementsHasInstance() const;    
     virtual ConstructType getConstructData(ConstructData&);
     virtual const ClassInfo* classInfo() const { return &info; }
 
index 3d7cbe0afa92ec047f7eb60138d6ed5ffd845c1c..5203969767afd81de22997ac0860905e8095d10d 100644 (file)
@@ -46,13 +46,6 @@ JSCallbackFunction::JSCallbackFunction(ExecState* exec, JSObjectCallAsFunctionCa
 {
 }
 
-// InternalFunction mish-mashes constructor and function behavior -- we should 
-// refactor the code so this override isn't necessary
-bool JSCallbackFunction::implementsHasInstance() const
-{ 
-    return false; 
-}
-
 JSValue* JSCallbackFunction::call(ExecState* exec, JSObject* functionObject, JSValue* thisValue, const ArgList& args)
 {
     JSContextRef execRef = toRef(exec);
index e52c1fffc3bd86e83e9ea284d6da2d3ee71a9636..9b3f2d59043d81ab87f61d4cb9e33083543f3db7 100644 (file)
@@ -37,8 +37,14 @@ public:
 
     static const ClassInfo info;
     
+    // InternalFunction mish-mashes constructor and function behavior -- we should 
+    // refactor the code so this override isn't necessary
+    static PassRefPtr<StructureID> createStructureID(JSValue* proto) 
+    { 
+        return StructureID::create(proto, TypeInfo(ObjectType)); 
+    }
+
 private:
-    virtual bool implementsHasInstance() const;
     virtual CallType getCallData(CallData&);
     virtual const ClassInfo* classInfo() const { return &info; }
 
index 7b52b9e04f3a55204e900008bd1cea0de1bf7bc6..bc035f803abe5590d826b49eeb027b5914cb15e3 100644 (file)
@@ -48,6 +48,11 @@ public:
     JSClassRef classRef() const { return m_callbackObjectData->jsClass; }
     bool inherits(JSClassRef) const;
 
+    static PassRefPtr<StructureID> createStructureID(JSValue* proto) 
+    { 
+        return StructureID::create(proto, TypeInfo(ObjectType, ImplementsHasInstance)); 
+    }
+
 private:
     virtual UString className() const;
 
@@ -59,7 +64,6 @@ private:
     virtual bool deleteProperty(ExecState*, const Identifier&);
     virtual bool deleteProperty(ExecState*, unsigned);
 
-    virtual bool implementsHasInstance() const;
     virtual bool hasInstance(ExecState* exec, JSValue* value, JSValue* proto);
 
     virtual void getPropertyNames(ExecState*, PropertyNameArray&);
index 17c5070a316e5212424498ce8c192947b3d35c65..c95db249915bcb75dae970e5ba8f7f77d84ef8b7 100644 (file)
@@ -272,16 +272,6 @@ JSObject* JSCallbackObject<Base>::construct(ExecState* exec, JSObject* construct
     return 0;
 }
 
-template <class Base>
-bool JSCallbackObject<Base>::implementsHasInstance() const
-{
-    for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass)
-        if (jsClass->hasInstance)
-            return true;
-    
-    return false;
-}
-
 template <class Base>
 bool JSCallbackObject<Base>::hasInstance(ExecState* exec, JSValue* value, JSValue*)
 {
@@ -294,8 +284,7 @@ bool JSCallbackObject<Base>::hasInstance(ExecState* exec, JSValue* value, JSValu
             return hasInstance(execRef, thisRef, toRef(value), toRef(exec->exceptionSlot()));
         }
     }
-    ASSERT_NOT_REACHED(); // implementsHasInstance should prevent us from reaching here
-    return 0;
+    return false;
 }
 
 template <class Base>
index ba9b38e62db9b48730e87754c19dc9aae46646b4..f2509e44bac513cb5bab7e86d6e367127c351d28 100644 (file)
@@ -144,7 +144,7 @@ bool JSValueIsInstanceOfConstructor(JSContextRef ctx, JSValueRef value, JSObject
 
     JSValue* jsValue = toJS(value);
     JSObject* jsConstructor = toJS(constructor);
-    if (!jsConstructor->implementsHasInstance())
+    if (!jsConstructor->structureID()->typeInfo().implementsHasInstance())
         return false;
     bool result = jsConstructor->hasInstance(exec, jsValue, jsConstructor->get(exec, exec->propertyNames().prototype)); // false if an exception is thrown
     if (exec->hadException()) {
index d895f429f642aa1a911434f38471e14a3f5e2a8b..56f13df72cdb08c2892e44fb7900d5abb9015a6f 100644 (file)
@@ -1,3 +1,37 @@
+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):
+
 2008-09-22  Maciej Stachowiak  <mjs@apple.com>
 
         Reviewed by Dave Hyatt.
index 96c03c3d7cb1d2a4e8e28b6f5e9528d9bd63c3f9..38deaa5d19313e33d76dccfc878f5e33e1a8279e 100644 (file)
@@ -291,7 +291,6 @@ __ZNK3JSC12StringObject12toThisStringEPNS_9ExecStateE
 __ZNK3JSC12StringObject8toStringEPNS_9ExecStateE
 __ZNK3JSC14JSGlobalObject14isDynamicScopeEv
 __ZNK3JSC14JSGlobalObject14toGlobalObjectEPNS_9ExecStateE
-__ZNK3JSC16InternalFunction21implementsHasInstanceEv
 __ZNK3JSC16JSVariableObject16isVariableObjectEv
 __ZNK3JSC16JSVariableObject21getPropertyAttributesEPNS_9ExecStateERKNS_10IdentifierERj
 __ZNK3JSC17DebuggerCallFrame10thisObjectEv
@@ -328,7 +327,6 @@ __ZNK3JSC8JSObject12defaultValueEPNS_9ExecStateENS_7JSValue22PreferredPrimitiveT
 __ZNK3JSC8JSObject12toThisObjectEPNS_9ExecStateE
 __ZNK3JSC8JSObject14toGlobalObjectEPNS_9ExecStateE
 __ZNK3JSC8JSObject21getPropertyAttributesEPNS_9ExecStateERKNS_10IdentifierERj
-__ZNK3JSC8JSObject21implementsHasInstanceEv
 __ZNK3JSC8JSObject8toNumberEPNS_9ExecStateE
 __ZNK3JSC8JSObject8toObjectEPNS_9ExecStateE
 __ZNK3JSC8JSObject8toStringEPNS_9ExecStateE
index 44d99a696b100653c71019d0c601374650c3577d..4f43f439d7562676e4731e31ad1bc382f7089537 100644 (file)
@@ -2123,7 +2123,7 @@ JSValue* Machine::privateExecute(ExecutionFlag flag, ExecState* exec, RegisterFi
             goto vm_throw;
 
         JSObject* baseObj = static_cast<JSObject*>(baseVal);
-        r[dst] = jsBoolean(baseObj->implementsHasInstance() ? baseObj->hasInstance(exec, r[value].jsValue(exec), r[baseProto].jsValue(exec)) : false);
+        r[dst] = jsBoolean(baseObj->structureID()->typeInfo().implementsHasInstance() ? baseObj->hasInstance(exec, r[value].jsValue(exec), r[baseProto].jsValue(exec)) : false);
 
         ++vPC;
         NEXT_OPCODE;
@@ -4304,7 +4304,7 @@ JSValue* Machine::cti_op_instanceof(CTI_ARGS)
 
     JSObject* baseObj = static_cast<JSObject*>(baseVal);
     JSValue* basePrototype = ARG_src3;
-    JSValue* result = jsBoolean(baseObj->implementsHasInstance() ? baseObj->hasInstance(exec,  ARG_src1, basePrototype) : false);
+    JSValue* result = jsBoolean(baseObj->structureID()->typeInfo().implementsHasInstance() ? baseObj->hasInstance(exec,  ARG_src1, basePrototype) : false);
     VM_CHECK_EXCEPTION_AT_END();
     return result;
 }
index 6508f0f3e89a3f6570e46f5578212a9bbc7c6b6d..c619a40cd1b09bc0b6fb158c23694528f3fd1365 100644 (file)
@@ -51,9 +51,4 @@ const UString& InternalFunction::name(ExecState* exec)
     return static_cast<JSString*>(v)->value();
 }
 
-bool InternalFunction::implementsHasInstance() const
-{
-    return true;
-}
-
 } // namespace JSC
index 20e86f61cbd7f11691675edcec26a9e8dbb2ddeb..b42ef99dba4f58c70ac4c64b06cec6850318f241 100644 (file)
@@ -38,6 +38,11 @@ namespace JSC {
         
         const UString& name(ExecState*);
 
+        static PassRefPtr<StructureID> createStructureID(JSValue* proto) 
+        { 
+            return StructureID::create(proto, TypeInfo(ObjectType, ImplementsHasInstance)); 
+        }
+
     protected:
         InternalFunction(PassRefPtr<StructureID> structure) : JSObject(structure) { }
         InternalFunction(ExecState*);
@@ -45,7 +50,6 @@ namespace JSC {
 
     private:
         virtual CallType getCallData(CallData&) = 0;
-        virtual bool implementsHasInstance() const;
     };
 
 } // namespace JSC
index 93f7bbf627086b87aa30b132326f5c2eb4c84dba..4a94e1ed662909238ff50155778f27583ead8582 100644 (file)
@@ -384,11 +384,6 @@ JSValue* JSObject::lookupSetter(ExecState*, const Identifier& propertyName)
     }
 }
 
-bool JSObject::implementsHasInstance() const
-{
-    return false;
-}
-
 bool JSObject::hasInstance(ExecState* exec, JSValue* value, JSValue* proto)
 {
     if (!proto->isObject()) {
index c60e16ae8f9b6562bc932309e17e1dc630e0b5fc..64681bc2095d77e905a54432d3f8b2435a51c157 100644 (file)
@@ -103,7 +103,6 @@ namespace JSC {
 
         virtual JSValue* defaultValue(ExecState*, PreferredPrimitiveType) const;
 
-        virtual bool implementsHasInstance() const;
         virtual bool hasInstance(ExecState*, JSValue*, JSValue* prototypeProperty);
 
         virtual void getPropertyNames(ExecState*, PropertyNameArray&);
index b4d33d472860747614d3946d32d66cd22c8402b7..319daa089d9bbbfec9e213c2d11d47ee7d91178b 100644 (file)
@@ -33,6 +33,7 @@ namespace JSC {
 
     // WebCore uses this to make document.all and style.filter undetectable.
     static const unsigned MasqueradesAsUndefined = 0x1;
+    static const unsigned ImplementsHasInstance = 0x2;
 
     class TypeInfo {
         friend class CTI;
@@ -42,6 +43,7 @@ namespace JSC {
         JSType type() const { return m_type; }
 
         bool masqueradesAsUndefined() const { return m_flags & MasqueradesAsUndefined; }
+        bool implementsHasInstance() const { return m_flags & ImplementsHasInstance; }
 
     private:
         JSType m_type;
index 51403f17f09f83977e63cc131e17796ff876cee7..d9ee4c9c219335d9fb5d36924a4598d6270428a1 100644 (file)
@@ -1,3 +1,18 @@
+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:
+
 2008-09-22  Adam Roben  <aroben@apple.com>
 
         Windows build fix
index b8b05eaf334faf2c07e5b430828837dad8404c67..12a23bf6f19b5cbbac9e4b76c69af92646ce1bf3 100644 (file)
@@ -219,11 +219,6 @@ ConstructType JSQuarantinedObjectWrapper::getConstructData(ConstructData& constr
     return ConstructTypeHost;
 }
 
-bool JSQuarantinedObjectWrapper::implementsHasInstance() const
-{
-    return m_unwrappedObject->implementsHasInstance();
-}
-
 bool JSQuarantinedObjectWrapper::hasInstance(ExecState* exec, JSValue* value, JSValue* proto)
 {
     if (!allowsHasInstance())
index a190b25eab3d2b8e1ec480d16193b818df9965d3..c76ca0d2c5330f9d9cd281926a2f3eb0c5037b73 100644 (file)
@@ -44,6 +44,11 @@ namespace WebCore {
 
         static const JSC::ClassInfo s_info;
 
+        static PassRefPtr<JSC::StructureID> createStructureID(JSC::JSValue* proto) 
+        { 
+            return JSC::StructureID::create(proto, JSC::TypeInfo(JSC::ObjectType, JSC::ImplementsHasInstance)); 
+        }
+
     protected:
         JSQuarantinedObjectWrapper(JSC::ExecState* unwrappedExec, JSC::JSObject* unwrappedObject, PassRefPtr<JSC::StructureID>);
 
@@ -62,7 +67,6 @@ namespace WebCore {
         virtual JSC::CallType getCallData(JSC::CallData&);
         virtual JSC::ConstructType getConstructData(JSC::ConstructData&);
 
-        virtual bool implementsHasInstance() const;
         virtual bool hasInstance(JSC::ExecState*, JSC::JSValue*, JSC::JSValue* proto);
 
         virtual void getPropertyNames(JSC::ExecState*, JSC::PropertyNameArray&);
index 6b467eebc7d7ec712a97828dab59b99977613950..5298d113041f4ad309130041db0d4ac000d67c07 100644 (file)
@@ -1820,7 +1820,10 @@ public:
     virtual const ClassInfo* classInfo() const { return &s_info; }
     static const ClassInfo s_info;
 
-    virtual bool implementsHasInstance() const { return true; }
+    static PassRefPtr<StructureID> createStructureID(JSValue* proto) 
+    { 
+        return StructureID::create(proto, TypeInfo(ObjectType, ImplementsHasInstance)); 
+    }
 EOF
 
     if ($canConstruct) {