Removed virtual destructor from JSGlobalObjectData to eliminate pointer
authorggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Sep 2009 17:54:39 +0000 (17:54 +0000)
committerggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Sep 2009 17:54:39 +0000 (17:54 +0000)
fix-ups when accessing JSGlobalObject::d.

Patch by Geoffrey Garen <ggaren@apple.com> on 2009-09-28
Reviewed by Sam Weinig.

JavaScriptCore:

Replaced with an explicit destructor function pointer.

6% speedup on bench-alloc-nonretained.js.

* JavaScriptCore.exp:
* runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::~JSGlobalObject):
(JSC::JSGlobalObject::destroyJSGlobalObjectData):
* runtime/JSGlobalObject.h:
(JSC::JSGlobalObject::JSGlobalObjectData::JSGlobalObjectData):
(JSC::JSGlobalObject::JSGlobalObject):

JavaScriptGlue:

Replaced with an explicit destructor function pointer.

* JSRun.cpp:
(JSGlueGlobalObject::destroyData):
* JSRun.h:
(JSGlueGlobalObject::Data::Data):

WebCore:

Replaced with an explicit destructor function pointer.

* bindings/js/JSDOMGlobalObject.cpp:
(WebCore::JSDOMGlobalObject::destroyJSDOMGlobalObjectData):
* bindings/js/JSDOMGlobalObject.h:
(WebCore::JSDOMGlobalObject::JSDOMGlobalObjectData::JSDOMGlobalObjectData):

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

JavaScriptCore/ChangeLog
JavaScriptCore/JavaScriptCore.exp
JavaScriptCore/runtime/JSGlobalObject.cpp
JavaScriptCore/runtime/JSGlobalObject.h
JavaScriptGlue/ChangeLog
JavaScriptGlue/JSRun.cpp
JavaScriptGlue/JSRun.h
WebCore/ChangeLog
WebCore/bindings/js/JSDOMGlobalObject.cpp
WebCore/bindings/js/JSDOMGlobalObject.h

index 7b6055f..a6029eb 100644 (file)
@@ -1,3 +1,22 @@
+2009-09-28  Geoffrey Garen  <ggaren@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        Removed virtual destructor from JSGlobalObjectData to eliminate pointer
+        fix-ups when accessing JSGlobalObject::d.
+        
+        Replaced with an explicit destructor function pointer.
+        
+        6% speedup on bench-alloc-nonretained.js.
+
+        * JavaScriptCore.exp:
+        * runtime/JSGlobalObject.cpp:
+        (JSC::JSGlobalObject::~JSGlobalObject):
+        (JSC::JSGlobalObject::destroyJSGlobalObjectData):
+        * runtime/JSGlobalObject.h:
+        (JSC::JSGlobalObject::JSGlobalObjectData::JSGlobalObjectData):
+        (JSC::JSGlobalObject::JSGlobalObject):
+
 2009-09-29  Janne Koskinen  <janne.p.koskinen@digia.com>
 
         Reviewed by David Kilzer.
index 813cf93..6182161 100644 (file)
@@ -132,6 +132,7 @@ __ZN3JSC14JSGlobalObject12defineGetterEPNS_9ExecStateERKNS_10IdentifierEPNS_8JSO
 __ZN3JSC14JSGlobalObject12defineSetterEPNS_9ExecStateERKNS_10IdentifierEPNS_8JSObjectEj
 __ZN3JSC14JSGlobalObject12markChildrenERNS_9MarkStackE
 __ZN3JSC14JSGlobalObject17putWithAttributesEPNS_9ExecStateERKNS_10IdentifierENS_7JSValueEj
+__ZN3JSC14JSGlobalObject25destroyJSGlobalObjectDataEPv
 __ZN3JSC14JSGlobalObject3putEPNS_9ExecStateERKNS_10IdentifierENS_7JSValueERNS_15PutPropertySlotE  
 __ZN3JSC14JSGlobalObject4initEPNS_8JSObjectE
 __ZN3JSC14JSGlobalObjectD2Ev
index 9907a8f..3bb281e 100644 (file)
@@ -121,7 +121,7 @@ JSGlobalObject::~JSGlobalObject()
         registerFile.setGlobalObject(0);
         registerFile.setNumGlobals(0);
     }
-    delete d();
+    d()->destructor(d());
 }
 
 void JSGlobalObject::init(JSObject* thisValue)
@@ -455,4 +455,9 @@ void* JSGlobalObject::operator new(size_t size, JSGlobalData* globalData)
 #endif
 }
 
+void JSGlobalObject::destroyJSGlobalObjectData(void* jsGlobalObjectData)
+{
+    delete static_cast<JSGlobalObjectData*>(jsGlobalObjectData);
+}
+
 } // namespace JSC
index 289a2c4..2106783 100644 (file)
@@ -52,14 +52,22 @@ namespace JSC {
     struct HashTable;
 
     typedef Vector<ExecState*, 16> ExecStateStack;
-
+    
     class JSGlobalObject : public JSVariableObject {
     protected:
         using JSVariableObject::JSVariableObjectData;
 
         struct JSGlobalObjectData : public JSVariableObjectData {
-            JSGlobalObjectData()
+            // We use an explicit destructor function pointer instead of a
+            // virtual destructor because we want to avoid adding a vtable
+            // pointer to this struct. Adding a vtable pointer would force the
+            // compiler to emit costly pointer fixup code when casting from
+            // JSVariableObjectData* to JSGlobalObjectData*.
+            typedef void (*Destructor)(void*);
+
+            JSGlobalObjectData(Destructor destructor)
                 : JSVariableObjectData(&symbolTable, 0)
+                , destructor(destructor)
                 , registerArraySize(0)
                 , globalScopeChain(NoScopeChain())
                 , regExpConstructor(0)
@@ -85,10 +93,8 @@ namespace JSC {
             {
             }
             
-            virtual ~JSGlobalObjectData()
-            {
-            }
-
+            Destructor destructor;
+            
             size_t registerArraySize;
 
             JSGlobalObject* next;
@@ -153,7 +159,7 @@ namespace JSC {
         void* operator new(size_t, JSGlobalData*);
 
         explicit JSGlobalObject()
-            : JSVariableObject(JSGlobalObject::createStructure(jsNull()), new JSGlobalObjectData)
+            : JSVariableObject(JSGlobalObject::createStructure(jsNull()), new JSGlobalObjectData(destroyJSGlobalObjectData))
         {
             init(this);
         }
@@ -280,6 +286,8 @@ namespace JSC {
         void addStaticGlobals(GlobalPropertyInfo*, int count);
 
     private:
+        static void destroyJSGlobalObjectData(void*);
+
         // FIXME: Fold reset into init.
         void init(JSObject* thisValue);
         void reset(JSValue prototype);
index f552c61..87f87f0 100644 (file)
@@ -1,3 +1,17 @@
+2009-09-28  Geoffrey Garen  <ggaren@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        Removed virtual destructor from JSGlobalObjectData to eliminate pointer
+        fix-ups when accessing JSGlobalObject::d.
+        
+        Replaced with an explicit destructor function pointer.
+
+        * JSRun.cpp:
+        (JSGlueGlobalObject::destroyData):
+        * JSRun.h:
+        (JSGlueGlobalObject::Data::Data):
+
 2009-09-12  Oliver Hunt  <oliver@apple.com>
 
         Reviewed by Maciej Stachowiak.
index 23d9c9c..03fc431 100644 (file)
@@ -40,6 +40,11 @@ JSGlueGlobalObject::JSGlueGlobalObject(PassRefPtr<Structure> structure, JSFlags
     d()->userObjectStructure = UserObjectImp::createStructure(jsNull());
 }
 
+void JSGlueGlobalObject::destroyData(void* data)
+{
+    delete static_cast<Data*>(data);
+}
+
 JSRun::JSRun(CFStringRef source, JSFlags inFlags)
     :   JSBase(kJSRunTypeID),
         fSource(CFStringToUString(source)),
index 44b42cc..15d495b 100644 (file)
@@ -41,10 +41,17 @@ class JSGlueGlobalObject : public JSGlobalObject {
 
     private:
         struct Data : JSGlobalObjectData {
+            Data()
+                : JSGlobalObjectData(destroyData)
+            {
+            }
+            
             RefPtr<Structure> userObjectStructure;
             JSFlags flags;
         };
 
+        static void destroyData(void*);
+
         Data* d() const { return static_cast<Data*>(JSGlobalObject::d()); }
 };
 
index a10fc3b..4542bf4 100644 (file)
@@ -1,3 +1,17 @@
+2009-09-28  Geoffrey Garen  <ggaren@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        Removed virtual destructor from JSGlobalObjectData to eliminate pointer
+        fix-ups when accessing JSGlobalObject::d.
+        
+        Replaced with an explicit destructor function pointer.
+
+        * bindings/js/JSDOMGlobalObject.cpp:
+        (WebCore::JSDOMGlobalObject::destroyJSDOMGlobalObjectData):
+        * bindings/js/JSDOMGlobalObject.h:
+        (WebCore::JSDOMGlobalObject::JSDOMGlobalObjectData::JSDOMGlobalObjectData):
+
 2009-09-29  Kenneth Rohde Christiansen  <kenneth@webkit.org>
 
         Reviewed by Simon Hausmann.
index 817cdfd..8947767 100644 (file)
@@ -40,11 +40,6 @@ using namespace JSC;
 
 namespace WebCore {
 
-JSDOMGlobalObject::JSDOMGlobalObjectData::JSDOMGlobalObjectData()
-    : evt(0)
-{
-}
-
 JSDOMGlobalObject::JSDOMGlobalObject(NonNullPassRefPtr<Structure> structure, JSDOMGlobalObject::JSDOMGlobalObjectData* data, JSObject* thisValue)
     : JSGlobalObject(structure, data, thisValue)
 {
@@ -81,6 +76,11 @@ Event* JSDOMGlobalObject::currentEvent() const
     return d()->evt;
 }
 
+void JSDOMGlobalObject::destroyJSDOMGlobalObjectData(void* jsDOMGlobalObjectData)
+{
+    delete static_cast<JSDOMGlobalObjectData*>(jsDOMGlobalObjectData);
+}
+
 JSDOMGlobalObject* toJSDOMGlobalObject(Document* document)
 {
     return toJSDOMWindow(document->frame());
index 9378613..00c3bbf 100644 (file)
@@ -67,7 +67,11 @@ namespace WebCore {
 
     protected:
         struct JSDOMGlobalObjectData : public JSC::JSGlobalObject::JSGlobalObjectData {
-            JSDOMGlobalObjectData();
+            JSDOMGlobalObjectData()
+                : JSGlobalObjectData(destroyJSDOMGlobalObjectData)
+                , evt(0)
+            {
+            }
 
             JSDOMStructureMap structures;
             JSDOMConstructorMap constructors;
@@ -76,6 +80,8 @@ namespace WebCore {
         };
 
     private:
+        static void destroyJSDOMGlobalObjectData(void*);
+
         JSDOMGlobalObjectData* d() const { return static_cast<JSDOMGlobalObjectData*>(JSC::JSVariableObject::d); }
     };