<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[165796] trunk/Source/JavaScriptCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/165796">165796</a></dd>
<dt>Author</dt> <dd>akling@apple.com</dd>
<dt>Date</dt> <dd>2014-03-17 20:28:19 -0700 (Mon, 17 Mar 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add one-deep cache to opaque roots hashset.
&lt;https://webkit.org/b/130357&gt;

The vast majority of WebCore JS wrappers will have their Document*
as the root(). This change adds a simple optimization where we cache
the last lookup and avoid going to the hashset for repeated queries.

Looks like 0.4% progression on DYEB on my MBP.

Reviewed by Mark Hahnenberg.

* JavaScriptCore.xcodeproj/project.pbxproj:
* heap/OpaqueRootSet.h: Added.
(JSC::OpaqueRootSet::OpaqueRootSet):
(JSC::OpaqueRootSet::contains):
(JSC::OpaqueRootSet::isEmpty):
(JSC::OpaqueRootSet::clear):
(JSC::OpaqueRootSet::add):
(JSC::OpaqueRootSet::size):
(JSC::OpaqueRootSet::begin):
(JSC::OpaqueRootSet::end):
* heap/SlotVisitor.h:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreJavaScriptCorexcodeprojprojectpbxproj">trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceJavaScriptCoreheapSlotVisitorh">trunk/Source/JavaScriptCore/heap/SlotVisitor.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreheapOpaqueRootSeth">trunk/Source/JavaScriptCore/heap/OpaqueRootSet.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (165795 => 165796)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2014-03-18 03:21:22 UTC (rev 165795)
+++ trunk/Source/JavaScriptCore/ChangeLog        2014-03-18 03:28:19 UTC (rev 165796)
</span><span class="lines">@@ -1,3 +1,28 @@
</span><ins>+2014-03-17  Andreas Kling  &lt;akling@apple.com&gt;
+
+        Add one-deep cache to opaque roots hashset.
+        &lt;https://webkit.org/b/130357&gt;
+
+        The vast majority of WebCore JS wrappers will have their Document*
+        as the root(). This change adds a simple optimization where we cache
+        the last lookup and avoid going to the hashset for repeated queries.
+
+        Looks like 0.4% progression on DYEB on my MBP.
+
+        Reviewed by Mark Hahnenberg.
+
+        * JavaScriptCore.xcodeproj/project.pbxproj:
+        * heap/OpaqueRootSet.h: Added.
+        (JSC::OpaqueRootSet::OpaqueRootSet):
+        (JSC::OpaqueRootSet::contains):
+        (JSC::OpaqueRootSet::isEmpty):
+        (JSC::OpaqueRootSet::clear):
+        (JSC::OpaqueRootSet::add):
+        (JSC::OpaqueRootSet::size):
+        (JSC::OpaqueRootSet::begin):
+        (JSC::OpaqueRootSet::end):
+        * heap/SlotVisitor.h:
+
</ins><span class="cx"> 2014-03-17  Tibor Meszaros  &lt;tmeszaros.u-szeged@partner.samsung.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Implement Math.hypot
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreJavaScriptCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj (165795 => 165796)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj        2014-03-18 03:21:22 UTC (rev 165795)
+++ trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj        2014-03-18 03:28:19 UTC (rev 165796)
</span><span class="lines">@@ -1280,6 +1280,7 @@
</span><span class="cx">                 A7FB61001040C38B0017A286 /* PropertyDescriptor.h in Headers */ = {isa = PBXBuildFile; fileRef = A7FB604B103F5EAB0017A286 /* PropertyDescriptor.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 A7FCC26D17A0B6AA00786D1A /* FTLSwitchCase.h in Headers */ = {isa = PBXBuildFile; fileRef = A7FCC26C17A0B6AA00786D1A /* FTLSwitchCase.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 A8A4748E151A8306004123FF /* libWTF.a in Frameworks */ = {isa = PBXBuildFile; fileRef = A8A4748D151A8306004123FF /* libWTF.a */; };
</span><ins>+                ADDB1F6318D77DBE009B58A8 /* OpaqueRootSet.h in Headers */ = {isa = PBXBuildFile; fileRef = ADDB1F6218D77DB7009B58A8 /* OpaqueRootSet.h */; settings = {ATTRIBUTES = (Private, ); }; };
</ins><span class="cx">                 ADE39FFF16DD144B0003CD4A /* PropertyTable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AD1CF06816DCAB2D00B97123 /* PropertyTable.cpp */; };
</span><span class="cx">                 B59F89391891F29F00D5CCDC /* UnlinkedInstructionStream.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B59F89381891ADB500D5CCDC /* UnlinkedInstructionStream.cpp */; };
</span><span class="cx">                 BC02E90D0E1839DB000F9297 /* ErrorConstructor.h in Headers */ = {isa = PBXBuildFile; fileRef = BC02E9050E1839DB000F9297 /* ErrorConstructor.h */; };
</span><span class="lines">@@ -2834,6 +2835,7 @@
</span><span class="cx">                 A8E894310CD0602400367179 /* JSCallbackObjectFunctions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSCallbackObjectFunctions.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 A8E894330CD0603F00367179 /* JSGlobalObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSGlobalObject.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 AD1CF06816DCAB2D00B97123 /* PropertyTable.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PropertyTable.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                ADDB1F6218D77DB7009B58A8 /* OpaqueRootSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OpaqueRootSet.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 B59F89371891AD3300D5CCDC /* UnlinkedInstructionStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UnlinkedInstructionStream.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 B59F89381891ADB500D5CCDC /* UnlinkedInstructionStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UnlinkedInstructionStream.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 BC021BF2136900C300FC5467 /* ToolExecutable.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = ToolExecutable.xcconfig; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -3505,6 +3507,7 @@
</span><span class="cx">                 142E312A134FF0A600AFADB5 /* heap */ = {
</span><span class="cx">                         isa = PBXGroup;
</span><span class="cx">                         children = (
</span><ins>+                                ADDB1F6218D77DB7009B58A8 /* OpaqueRootSet.h */,
</ins><span class="cx">                                 2AACE63A18CA5A0300ED0191 /* GCActivityCallback.cpp */,
</span><span class="cx">                                 2AACE63B18CA5A0300ED0191 /* GCActivityCallback.h */,
</span><span class="cx">                                 14816E19154CC56C00B8054C /* BlockAllocator.cpp */,
</span><span class="lines">@@ -5331,6 +5334,7 @@
</span><span class="cx">                                 FEF6835F174343CC00A32E25 /* JITStubsARMv7.h in Headers */,
</span><span class="cx">                                 FEF68361174343CC00A32E25 /* JITStubsX86.h in Headers */,
</span><span class="cx">                                 FEF68360174343CC00A32E25 /* JITStubsX86_64.h in Headers */,
</span><ins>+                                ADDB1F6318D77DBE009B58A8 /* OpaqueRootSet.h in Headers */,
</ins><span class="cx">                                 A7A4AE1017973B4D005612B1 /* JITStubsX86Common.h in Headers */,
</span><span class="cx">                                 0F5EF91F16878F7D003E5C25 /* JITThunks.h in Headers */,
</span><span class="cx">                                 0FC712E317CD8793008CC93C /* JITToDFGDeferredCompilationCallback.h in Headers */,
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreheapOpaqueRootSeth"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/heap/OpaqueRootSet.h (0 => 165796)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/heap/OpaqueRootSet.h                                (rev 0)
+++ trunk/Source/JavaScriptCore/heap/OpaqueRootSet.h        2014-03-18 03:28:19 UTC (rev 165796)
</span><span class="lines">@@ -0,0 +1,94 @@
</span><ins>+/*
+ * Copyright (C) 2014 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 INC. AND ITS CONTRIBUTORS ``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 INC. OR ITS 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 OpaqueRootSet_h
+#define OpaqueRootSet_h
+
+#include &lt;wtf/HashSet.h&gt;
+
+namespace JSC {
+
+class OpaqueRootSet {
+    WTF_MAKE_NONCOPYABLE(OpaqueRootSet);
+public:
+    OpaqueRootSet()
+        : m_lastQueriedRoot(nullptr)
+        , m_containsLastQueriedRoot(false)
+    {
+    }
+
+    bool contains(void* root) const
+    {
+        if (root != m_lastQueriedRoot) {
+            m_lastQueriedRoot = root;
+            m_containsLastQueriedRoot = m_roots.contains(root);
+        }
+        return m_containsLastQueriedRoot;
+    }
+
+    bool isEmpty() const
+    {
+        return m_roots.isEmpty();
+    }
+
+    void clear()
+    {
+        m_roots.clear();
+        m_lastQueriedRoot = nullptr;
+        m_containsLastQueriedRoot = false;
+    }
+
+    void add(void* root)
+    {
+        if (root == m_lastQueriedRoot)
+            m_containsLastQueriedRoot = true;
+        m_roots.add(root);
+    }
+
+    int size() const
+    {
+        return m_roots.size();
+    }
+
+    HashSet&lt;void*&gt;::const_iterator begin() const
+    {
+        return m_roots.begin();
+    }
+
+    HashSet&lt;void*&gt;::const_iterator end() const
+    {
+        return m_roots.end();
+    }
+
+
+private:
+    HashSet&lt;void*&gt; m_roots;
+    mutable void* m_lastQueriedRoot;
+    mutable bool m_containsLastQueriedRoot;
+};
+
+} // namespace JSC
+
+#endif // OpaqueRootSet_h
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoreheapSlotVisitorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/heap/SlotVisitor.h (165795 => 165796)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/heap/SlotVisitor.h        2014-03-18 03:21:22 UTC (rev 165795)
+++ trunk/Source/JavaScriptCore/heap/SlotVisitor.h        2014-03-18 03:28:19 UTC (rev 165796)
</span><span class="lines">@@ -29,6 +29,7 @@
</span><span class="cx"> #include &quot;CopyToken.h&quot;
</span><span class="cx"> #include &quot;HandleTypes.h&quot;
</span><span class="cx"> #include &quot;MarkStack.h&quot;
</span><ins>+#include &quot;OpaqueRootSet.h&quot;
</ins><span class="cx"> 
</span><span class="cx"> #include &lt;wtf/HashSet.h&gt;
</span><span class="cx"> #include &lt;wtf/text/StringHash.h&gt;
</span><span class="lines">@@ -134,7 +135,7 @@
</span><span class="cx">     void donateKnownParallel();
</span><span class="cx"> 
</span><span class="cx">     MarkStackArray m_stack;
</span><del>-    HashSet&lt;void*&gt; m_opaqueRoots; // Handle-owning data structures not visible to the garbage collector.
</del><ins>+    OpaqueRootSet m_opaqueRoots; // Handle-owning data structures not visible to the garbage collector.
</ins><span class="cx">     
</span><span class="cx">     size_t m_bytesVisited;
</span><span class="cx">     size_t m_bytesCopied;
</span></span></pre>
</div>
</div>

</body>
</html>