2010-02-21 Maciej Stachowiak <mjs@apple.com>
authormjs@apple.com <mjs@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 22 Feb 2010 09:28:30 +0000 (09:28 +0000)
committermjs@apple.com <mjs@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 22 Feb 2010 09:28:30 +0000 (09:28 +0000)
        Reviewed by Darin Adler.

        Cache JavaScript wrappers inline in DOM nodes
        https://bugs.webkit.org/show_bug.cgi?id=35226
        <rdar://problem/7664202>

        8.8% speedup on Dromaeo DOM Core tests.
        3.3% speedup on Hixie DOM Core tests.

        * bindings/js/JSDOMBinding.cpp:
        (WebCore::forgetDOMNode): Clear wrapper pointer.
        (WebCore::cacheDOMNodeWrapper): Cache inline too if caching for normal world.
        * bindings/js/JSDOMBinding.h:
        (WebCore::DOMObjectWrapperMapFor):
        * bindings/js/JSDocumentCustom.cpp:
        (WebCore::toJS): Remove unneeded argument from getCachedDOMNodeWrapper.
        * bindings/js/JSNodeCustom.cpp:
        (WebCore::createWrapperInline): Renamed version of original createWrapper.
        (WebCore::createWrapper): Call createWrapperInline. Out-of-line version.
        (WebCore::toJSNewlyCreated): Call createWrapperInline instead of createWrapper.
        * bindings/js/JSNodeCustom.h: Added.
        (WebCore::getCachedDOMNodeWrapper): Moved here so it can be inlined.
        (WebCore::toJS): Moved here so it can be inlined.
        * bindings/js/ScriptWrappable.h:
        (WebCore::ScriptWrappable::ScriptWrappable): Implement this in the obvious
        way for JavaScriptCore.
        (WebCore::ScriptWrappable::wrapper):
        (WebCore::ScriptWrappable::setWrapper):
        (WebCore::ScriptWrappable::clearWrapper):
        * bindings/scripts/CodeGeneratorJS.pm: Include CustomHeader heaaders
        in the header, not just the impl file, so they can add inlining.
        * dom/Node.idl: Add CustomHeader directive.

        Add new files to build.

        * GNUmakefile.am:
        * WebCore.gypi:
        * WebCore.pro:
        * WebCore.vcproj/WebCore.vcproj:

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

13 files changed:
WebCore/ChangeLog
WebCore/GNUmakefile.am
WebCore/WebCore.gypi
WebCore/WebCore.pro
WebCore/WebCore.vcproj/WebCore.vcproj
WebCore/bindings/js/JSDOMBinding.cpp
WebCore/bindings/js/JSDOMBinding.h
WebCore/bindings/js/JSDocumentCustom.cpp
WebCore/bindings/js/JSNodeCustom.cpp
WebCore/bindings/js/JSNodeCustom.h [new file with mode: 0644]
WebCore/bindings/js/ScriptWrappable.h
WebCore/bindings/scripts/CodeGeneratorJS.pm
WebCore/dom/Node.idl

index fe87ec69b3f97129c8135f5c209acb155ad117d0..de8055f2c1faa7012b42412b5bc0198c10af7042 100644 (file)
@@ -1,3 +1,45 @@
+2010-02-21  Maciej Stachowiak  <mjs@apple.com>
+
+        Reviewed by Darin Adler.
+
+        Cache JavaScript wrappers inline in DOM nodes
+        https://bugs.webkit.org/show_bug.cgi?id=35226
+        <rdar://problem/7664202>
+
+        8.8% speedup on Dromaeo DOM Core tests.
+        3.3% speedup on Hixie DOM Core tests.
+        
+        * bindings/js/JSDOMBinding.cpp:
+        (WebCore::forgetDOMNode): Clear wrapper pointer.
+        (WebCore::cacheDOMNodeWrapper): Cache inline too if caching for normal world.
+        * bindings/js/JSDOMBinding.h:
+        (WebCore::DOMObjectWrapperMapFor): 
+        * bindings/js/JSDocumentCustom.cpp:
+        (WebCore::toJS): Remove unneeded argument from getCachedDOMNodeWrapper.
+        * bindings/js/JSNodeCustom.cpp:
+        (WebCore::createWrapperInline): Renamed version of original createWrapper.
+        (WebCore::createWrapper): Call createWrapperInline. Out-of-line version.
+        (WebCore::toJSNewlyCreated): Call createWrapperInline instead of createWrapper.
+        * bindings/js/JSNodeCustom.h: Added.
+        (WebCore::getCachedDOMNodeWrapper): Moved here so it can be inlined.
+        (WebCore::toJS): Moved here so it can be inlined.
+        * bindings/js/ScriptWrappable.h:
+        (WebCore::ScriptWrappable::ScriptWrappable): Implement this in the obvious
+        way for JavaScriptCore.
+        (WebCore::ScriptWrappable::wrapper):
+        (WebCore::ScriptWrappable::setWrapper):
+        (WebCore::ScriptWrappable::clearWrapper):
+        * bindings/scripts/CodeGeneratorJS.pm: Include CustomHeader heaaders
+        in the header, not just the impl file, so they can add inlining.
+        * dom/Node.idl: Add CustomHeader directive.
+        
+        Add new files to build.
+
+        * GNUmakefile.am:
+        * WebCore.gypi:
+        * WebCore.pro:
+        * WebCore.vcproj/WebCore.vcproj:
+
 2010-02-22  Pavel Feldman  <pfeldman@chromium.org>
 
         Not reviewed: windows build fix.
index 3aecf9bbbd2e3db5ecaa224e20713bcadccfcd42..e28e348b723fec30d805aaff3aa9a7f2155f80da 100644 (file)
@@ -437,6 +437,7 @@ webcore_sources += \
        WebCore/bindings/js/JSNamedNodeMapCustom.cpp \
        WebCore/bindings/js/JSNavigatorCustom.cpp \
        WebCore/bindings/js/JSNodeCustom.cpp \
+       WebCore/bindings/js/JSNodeCustom.h \
        WebCore/bindings/js/JSNodeFilterCondition.cpp \
        WebCore/bindings/js/JSNodeFilterCondition.h \
        WebCore/bindings/js/JSNodeFilterCustom.cpp \
index 6fe815c4d49db857c96e3a7b349515a73be3d984..d6f2f5e48feaf12137029949226faa667be4614d 100644 (file)
             'bindings/js/JSNamedNodesCollection.h',
             'bindings/js/JSNavigatorCustom.cpp',
             'bindings/js/JSNodeCustom.cpp',
+            'bindings/js/JSNodeCustom.h',
             'bindings/js/JSNodeFilterCondition.cpp',
             'bindings/js/JSNodeFilterCondition.h',
             'bindings/js/JSNodeFilterCustom.cpp',
index 2e8e47efebdce6dec4adf56f5761fd36abacc4f5..badef2ea1e9141536fe749d29a8ec809c3f15bfb 100644 (file)
@@ -1018,6 +1018,7 @@ HEADERS += \
     bindings/js/JSLazyEventListener.h \
     bindings/js/JSLocationCustom.h \
     bindings/js/JSMessageChannelConstructor.h \
+    bindings/js/JSNodeCustom.h \
     bindings/js/JSNodeFilterCondition.h \
     bindings/js/JSOptionConstructor.h \
     bindings/js/JSPluginElementFunctions.h \
index 44ea3514fec8961fd187cd837a1ff88202fe0cff..20eaa75b131cf656690ff35c74951283d5c06d66 100644 (file)
                                                />\r
                                        </FileConfiguration>\r
                                </File>\r
+                               <File\r
+                                       RelativePath="..\bindings\js\JSNodeCustom.h"\r
+                                       >\r
+                               </File>\r
                                <File\r
                                        RelativePath="..\bindings\js\JSNodeFilterCondition.cpp"\r
                                        >\r
index abba40525ef071ff61807bb73ca41934b6471499..0efee81eca3339b1867f4e1180a793541092126c 100644 (file)
@@ -221,11 +221,6 @@ const JSC::HashTable* getHashTableForGlobalData(JSGlobalData& globalData, const
     return DOMObjectHashTableMap::mapFor(globalData).get(staticTable);
 }
 
-static inline DOMObjectWrapperMap& DOMObjectWrapperMapFor(JSC::ExecState* exec)
-{
-    return currentWorld(exec)->m_wrappers;
-}
-
 bool hasCachedDOMObjectWrapperUnchecked(JSGlobalData* globalData, void* objectHandle)
 {
     for (JSGlobalDataWorldIterator worldIter(globalData); worldIter; ++worldIter) {
@@ -246,13 +241,13 @@ bool hasCachedDOMObjectWrapper(JSGlobalData* globalData, void* objectHandle)
 
 DOMObject* getCachedDOMObjectWrapper(JSC::ExecState* exec, void* objectHandle) 
 {
-    return DOMObjectWrapperMapFor(exec).get(objectHandle);
+    return domObjectWrapperMapFor(exec).get(objectHandle);
 }
 
 void cacheDOMObjectWrapper(JSC::ExecState* exec, void* objectHandle, DOMObject* wrapper) 
 {
     willCacheWrapper(wrapper);
-    DOMObjectWrapperMapFor(exec).set(objectHandle, wrapper);
+    domObjectWrapperMapFor(exec).set(objectHandle, wrapper);
 }
 
 bool hasCachedDOMNodeWrapperUnchecked(Document* document, Node* node)
@@ -268,13 +263,6 @@ bool hasCachedDOMNodeWrapperUnchecked(Document* document, Node* node)
     return false;
 }
 
-JSNode* getCachedDOMNodeWrapper(JSC::ExecState* exec, Document* document, Node* node)
-{
-    if (document)
-        return document->getWrapperCache(currentWorld(exec))->get(node);
-    return static_cast<JSNode*>(DOMObjectWrapperMapFor(exec).get(node));
-}
-
 void forgetDOMObject(DOMObject* wrapper, void* objectHandle)
 {
     JSC::JSGlobalData* globalData = Heap::heap(wrapper)->globalData();
@@ -303,6 +291,9 @@ void forgetDOMNode(JSNode* wrapper, Node* node, Document* document)
         forgetDOMObject(wrapper, node);
         return;
     }
+    
+    if (node->wrapper() == wrapper)
+        node->clearWrapper();
 
     // We can't guarantee that a wrapper is in the cache when it uncaches itself,
     // since a new wrapper may be cached before the old wrapper's destructor runs.
@@ -316,13 +307,15 @@ void forgetDOMNode(JSNode* wrapper, Node* node, Document* document)
 
 void cacheDOMNodeWrapper(JSC::ExecState* exec, Document* document, Node* node, JSNode* wrapper)
 {
-    if (!document) {
-        willCacheWrapper(wrapper);
-        DOMObjectWrapperMapFor(exec).set(node, wrapper);
-        return;
-    }
     willCacheWrapper(wrapper);
-    document->getWrapperCache(currentWorld(exec))->set(node, wrapper);
+
+    if (!document)
+        domObjectWrapperMapFor(exec).set(node, wrapper);
+    else
+        document->getWrapperCache(currentWorld(exec))->set(node, wrapper);
+
+    if (currentWorld(exec)->isNormal())
+        node->setWrapper(wrapper);
 }
 
 void forgetAllDOMNodesForDocument(Document* document)
index 807bf822d638c3051d062728cea7aa1c4cf04de2..720888dd139ed9a035594d6171390bfacca8d26b 100644 (file)
@@ -235,7 +235,7 @@ namespace WebCore {
     void forgetDOMNode(JSNode* wrapper, Node* node, Document* document);
     void forgetDOMObject(DOMObject* wrapper, void* objectHandle);
 
-    JSNode* getCachedDOMNodeWrapper(JSC::ExecState*, Document*, Node*);
+    JSNode* getCachedDOMNodeWrapper(JSC::ExecState*, Node*);
     void cacheDOMNodeWrapper(JSC::ExecState*, Document*, Node*, JSNode* wrapper);
     void forgetAllDOMNodesForDocument(Document*);
     void forgetWorldOfDOMNodesForDocument(Document*, DOMWrapperWorld*);
@@ -446,6 +446,11 @@ namespace WebCore {
         return jsStringSlowCase(exec, stringCache, stringImpl);
     }
 
+    inline DOMObjectWrapperMap& domObjectWrapperMapFor(JSC::ExecState* exec)
+    {
+        return currentWorld(exec)->m_wrappers;
+    }
+
 } // namespace WebCore
 
 #endif // JSDOMBinding_h
index eda153e2f4ae5bc78f748fd68e0c5f06fbfb9133..6942f03ec24d75a59f8114475c4ca8fb099eeced 100644 (file)
@@ -96,7 +96,7 @@ JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, Document* documen
     if (!document)
         return jsNull();
 
-    DOMObject* wrapper = getCachedDOMNodeWrapper(exec, document, document);
+    DOMObject* wrapper = getCachedDOMNodeWrapper(exec, document);
     if (wrapper)
         return wrapper;
 
index 46a30a4d2d7928090bb2b414d5bda55a44b1351a..134c5813a2b39ef11f4879466acb6df38f17f189 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007, 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2007, 2009, 2010 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -172,7 +172,7 @@ void JSNode::markChildren(MarkStack& markStack)
         markDOMNodeWrapper(markStack, m_impl->document(), nodeToMark);
 }
 
-static ALWAYS_INLINE JSValue createWrapper(ExecState* exec, JSDOMGlobalObject* globalObject, Node* node)
+static ALWAYS_INLINE JSValue createWrapperInline(ExecState* exec, JSDOMGlobalObject* globalObject, Node* node)
 {
     ASSERT(node);
     ASSERT(!getCachedDOMNodeWrapper(exec, node->document(), node));
@@ -228,25 +228,18 @@ static ALWAYS_INLINE JSValue createWrapper(ExecState* exec, JSDOMGlobalObject* g
 
     return wrapper;    
 }
-    
-JSValue toJSNewlyCreated(ExecState* exec, JSDOMGlobalObject* globalObject, Node* node)
+
+JSValue createWrapper(ExecState* exec, JSDOMGlobalObject* globalObject, Node* node)
 {
-    if (!node)
-        return jsNull();
-    
-    return createWrapper(exec, globalObject, node);
+    return createWrapperInline(exec, globalObject, node);
 }
     
-JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, Node* node)
+JSValue toJSNewlyCreated(ExecState* exec, JSDOMGlobalObject* globalObject, Node* node)
 {
     if (!node)
         return jsNull();
-
-    JSNode* wrapper = getCachedDOMNodeWrapper(exec, node->document(), node);
-    if (wrapper)
-        return wrapper;
-
-    return createWrapper(exec, globalObject, node);
+    
+    return createWrapperInline(exec, globalObject, node);
 }
 
 } // namespace WebCore
diff --git a/WebCore/bindings/js/JSNodeCustom.h b/WebCore/bindings/js/JSNodeCustom.h
new file mode 100644 (file)
index 0000000..2534692
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2007, 2009, 2010 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#ifndef JSNodeCustom_h
+#define JSNodeCustom_h
+
+#include "JSDOMBinding.h"
+#include <wtf/AlwaysInline.h>
+
+namespace WebCore {
+
+inline JSNode* getCachedDOMNodeWrapper(JSC::ExecState* exec, Node* node)
+{
+    if (currentWorld(exec)->isNormal())
+        return static_cast<JSNode*>(node->wrapper());
+    return static_cast<JSNode*>(domObjectWrapperMapFor(exec).get(node));
+}
+
+JSC::JSValue createWrapper(JSC::ExecState*, JSDOMGlobalObject*, Node*);
+
+inline JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, Node* node)
+{
+    if (!node)
+        return JSC::jsNull();
+
+    JSNode* wrapper = getCachedDOMNodeWrapper(exec, node);
+    if (wrapper)
+        return wrapper;
+
+    return createWrapper(exec, globalObject, node);
+}
+
+}
+
+#endif // JSDOMNodeCustom_h
index d70cab75918b812c5e2c357b38e2cb34ba12fa07..7950cf36d6fe72063afe1adb6fd42134a06b902f 100644 (file)
 
 namespace WebCore {
 
+class DOMObject;
+
 class ScriptWrappable {
 public:
-    ScriptWrappable() { }
+    ScriptWrappable() : m_wrapper() { }
+    
+    DOMObject* wrapper() const
+    {
+        return m_wrapper;
+    }
+    
+    void setWrapper(DOMObject* wrapper)
+    {
+        ASSERT(wrapper);
+        m_wrapper = wrapper;
+    }
+    
+    void clearWrapper() { m_wrapper = 0; }
+    
+private:
+    DOMObject* m_wrapper;
 };
 
 } // namespace WebCore
index 94fc2b850978498edcc2f7bfe961c78d417498ba..ece6df25d51eb8a1287b39f7319fb0d46e3491ca 100644 (file)
@@ -32,6 +32,7 @@ my $writeDependencies = 0;
 my @headerContentHeader = ();
 my @headerContent = ();
 my %headerIncludes = ();
+my %headerTrailingIncludes = ();
 
 my @implContentHeader = ();
 my @implContent = ();
@@ -551,7 +552,9 @@ sub GenerateHeader
     # Prototype
     push(@headerContent, "    static JSC::JSObject* createPrototype(JSC::ExecState*, JSC::JSGlobalObject*);\n") unless ($dataNode->extendedAttributes->{"ExtendsDOMGlobalObject"});
 
-    $implIncludes{"${className}Custom.h"} = 1 if $dataNode->extendedAttributes->{"CustomHeader"} || $dataNode->extendedAttributes->{"CustomPutFunction"} || $dataNode->extendedAttributes->{"DelegatingPutFunction"};
+    $headerTrailingIncludes{"${className}Custom.h"} = 1 if $dataNode->extendedAttributes->{"CustomHeader"};
+
+    $implIncludes{"${className}Custom.h"} = 1 if !$dataNode->extendedAttributes->{"CustomHeader"} && ($dataNode->extendedAttributes->{"CustomPutFunction"} || $dataNode->extendedAttributes->{"DelegatingPutFunction"});
 
     my $hasGetter = $numAttributes > 0 
                  || !($dataNode->extendedAttributes->{"OmitConstructor"}
@@ -2246,12 +2249,23 @@ sub WriteData
         }
 
         print $HEADER @headerContent;
+
+        @includes = ();
+        foreach my $include (keys %headerTrailingIncludes) {
+            $include = "\"$include\"" unless $include =~ /^["<]/; # "
+            push @includes, $include;
+        }
+        foreach my $include (sort @includes) {
+            print $HEADER "#include $include\n";
+        }
+
         close($HEADER);
         undef($HEADER);
 
         @headerContentHeader = ();
         @headerContent = ();
         %headerIncludes = ();
+        %headerTrailingIncludes = ();
     }
 
     if (defined($DEPS)) {
index c6cd4b94e67fb9d6d2129b2a6075e815e648e968..a2b2455cab99e2e04e7d3d6b06c4b432d17e2f31 100644 (file)
@@ -21,6 +21,7 @@
 module core {
 
     interface [
+        CustomHeader,
         CustomMarkFunction,
         CustomPushEventHandlerScope,
         CustomToJS,