<!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>[173799] 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/173799">173799</a></dd>
<dt>Author</dt> <dd>fpizlo@apple.com</dd>
<dt>Date</dt> <dd>2014-09-21 16:52:31 -0700 (Sun, 21 Sep 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Structure should have a method for concurrently getting all of the property map entries, and this method shouldn't involve copy-paste
https://bugs.webkit.org/show_bug.cgi?id=136983

Reviewed by Mark Hahnenberg.

* runtime/PropertyMapHashTable.h:
(JSC::PropertyMapEntry::PropertyMapEntry): Moved PropertyMapEntry struct to Structure.h so that Structure can refer to it.
* runtime/Structure.cpp:
(JSC::Structure::getConcurrently): Switch to using the new forEachPropertyConcurrently() method.
(JSC::Structure::getPropertiesConcurrently): The subject of this patch. It will be useful for object allocation sinking (bug 136330).
(JSC::Structure::dump): Switch to using the new forEachPropertyConcurrently() method.
* runtime/Structure.h:
(JSC::PropertyMapEntry::PropertyMapEntry): Moved from PropertyMapHashTable.h.
* runtime/StructureInlines.h:
(JSC::Structure::forEachPropertyConcurrently): Capture this very common concurrent structure iteration pattern into a template method.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimePropertyMapHashTableh">trunk/Source/JavaScriptCore/runtime/PropertyMapHashTable.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeStructurecpp">trunk/Source/JavaScriptCore/runtime/Structure.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeStructureh">trunk/Source/JavaScriptCore/runtime/Structure.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeStructureInlinesh">trunk/Source/JavaScriptCore/runtime/StructureInlines.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (173798 => 173799)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2014-09-21 20:30:10 UTC (rev 173798)
+++ trunk/Source/JavaScriptCore/ChangeLog        2014-09-21 23:52:31 UTC (rev 173799)
</span><span class="lines">@@ -1,5 +1,23 @@
</span><span class="cx"> 2014-09-21  Filip Pizlo  &lt;fpizlo@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Structure should have a method for concurrently getting all of the property map entries, and this method shouldn't involve copy-paste
+        https://bugs.webkit.org/show_bug.cgi?id=136983
+
+        Reviewed by Mark Hahnenberg.
+
+        * runtime/PropertyMapHashTable.h:
+        (JSC::PropertyMapEntry::PropertyMapEntry): Moved PropertyMapEntry struct to Structure.h so that Structure can refer to it.
+        * runtime/Structure.cpp:
+        (JSC::Structure::getConcurrently): Switch to using the new forEachPropertyConcurrently() method.
+        (JSC::Structure::getPropertiesConcurrently): The subject of this patch. It will be useful for object allocation sinking (bug 136330).
+        (JSC::Structure::dump): Switch to using the new forEachPropertyConcurrently() method.
+        * runtime/Structure.h:
+        (JSC::PropertyMapEntry::PropertyMapEntry): Moved from PropertyMapHashTable.h.
+        * runtime/StructureInlines.h:
+        (JSC::Structure::forEachPropertyConcurrently): Capture this very common concurrent structure iteration pattern into a template method.
+
+2014-09-21  Filip Pizlo  &lt;fpizlo@apple.com&gt;
+
</ins><span class="cx">         Structure::getConcurrently() doesn't need to take a VM&amp; argument.
</span><span class="cx"> 
</span><span class="cx">         Rubber stamped by Dan Bernstein.
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimePropertyMapHashTableh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/PropertyMapHashTable.h (173798 => 173799)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/PropertyMapHashTable.h        2014-09-21 20:30:10 UTC (rev 173798)
+++ trunk/Source/JavaScriptCore/runtime/PropertyMapHashTable.h        2014-09-21 23:52:31 UTC (rev 173799)
</span><span class="lines">@@ -78,19 +78,6 @@
</span><span class="cx">     return v;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-struct PropertyMapEntry {
-    StringImpl* key;
-    PropertyOffset offset;
-    unsigned attributes;
-
-    PropertyMapEntry(StringImpl* key, PropertyOffset offset, unsigned attributes)
-        : key(key)
-        , offset(offset)
-        , attributes(attributes)
-    {
-    }
-};
-
</del><span class="cx"> class PropertyTable : public JSCell {
</span><span class="cx"> 
</span><span class="cx">     // This is the implementation for 'iterator' and 'const_iterator',
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeStructurecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/Structure.cpp (173798 => 173799)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/Structure.cpp        2014-09-21 20:30:10 UTC (rev 173798)
+++ trunk/Source/JavaScriptCore/runtime/Structure.cpp        2014-09-21 23:52:31 UTC (rev 173799)
</span><span class="lines">@@ -852,33 +852,32 @@
</span><span class="cx"> 
</span><span class="cx"> PropertyOffset Structure::getConcurrently(StringImpl* uid, unsigned&amp; attributes)
</span><span class="cx"> {
</span><del>-    Vector&lt;Structure*, 8&gt; structures;
-    Structure* structure;
-    PropertyTable* table;
</del><ins>+    PropertyOffset result = invalidOffset;
</ins><span class="cx">     
</span><del>-    findStructuresAndMapForMaterialization(structures, structure, table);
</del><ins>+    forEachPropertyConcurrently(
+        [&amp;] (const PropertyMapEntry&amp; candidate) -&gt; bool {
+            if (candidate.key != uid)
+                return true;
+            
+            result = candidate.offset;
+            attributes = candidate.attributes;
+            return false;
+        });
</ins><span class="cx">     
</span><del>-    if (table) {
-        PropertyMapEntry* entry = table-&gt;get(uid);
-        if (entry) {
-            attributes = entry-&gt;attributes;
-            PropertyOffset result = entry-&gt;offset;
-            structure-&gt;m_lock.unlock();
-            return result;
-        }
-        structure-&gt;m_lock.unlock();
-    }
</del><ins>+    return result;
+}
+
+Vector&lt;PropertyMapEntry&gt; Structure::getPropertiesConcurrently()
+{
+    Vector&lt;PropertyMapEntry&gt; result;
+
+    forEachPropertyConcurrently(
+        [&amp;] (const PropertyMapEntry&amp; entry) -&gt; bool {
+            result.append(entry);
+            return true;
+        });
</ins><span class="cx">     
</span><del>-    for (unsigned i = structures.size(); i--;) {
-        structure = structures[i];
-        if (structure-&gt;m_nameInPrevious.get() != uid)
-            continue;
-        
-        attributes = structure-&gt;attributesInPrevious();
-        return structure-&gt;m_offset;
-    }
-    
-    return invalidOffset;
</del><ins>+    return result;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> PropertyOffset Structure::add(VM&amp; vm, PropertyName propertyName, unsigned attributes)
</span><span class="lines">@@ -1110,31 +1109,14 @@
</span><span class="cx"> {
</span><span class="cx">     out.print(RawPointer(this), &quot;:[&quot;, classInfo()-&gt;className, &quot;, {&quot;);
</span><span class="cx">     
</span><del>-    Vector&lt;Structure*, 8&gt; structures;
-    Structure* structure;
-    PropertyTable* table;
-    
-    const_cast&lt;Structure*&gt;(this)-&gt;findStructuresAndMapForMaterialization(
-        structures, structure, table);
-    
</del><span class="cx">     CommaPrinter comma;
</span><span class="cx">     
</span><del>-    if (table) {
-        PropertyTable::iterator iter = table-&gt;begin();
-        PropertyTable::iterator end = table-&gt;end();
-        for (; iter != end; ++iter)
-            out.print(comma, iter-&gt;key, &quot;:&quot;, static_cast&lt;int&gt;(iter-&gt;offset));
-        
-        structure-&gt;m_lock.unlock();
-    }
</del><ins>+    const_cast&lt;Structure*&gt;(this)-&gt;forEachPropertyConcurrently(
+        [&amp;] (const PropertyMapEntry&amp; entry) -&gt; bool {
+            out.print(comma, entry.key, &quot;:&quot;, static_cast&lt;int&gt;(entry.offset));
+            return true;
+        });
</ins><span class="cx">     
</span><del>-    for (unsigned i = structures.size(); i--;) {
-        Structure* structure = structures[i];
-        if (!structure-&gt;m_nameInPrevious)
-            continue;
-        out.print(comma, structure-&gt;m_nameInPrevious.get(), &quot;:&quot;, static_cast&lt;int&gt;(structure-&gt;m_offset));
-    }
-    
</del><span class="cx">     out.print(&quot;}, &quot;, IndexingTypeDump(indexingType()));
</span><span class="cx">     
</span><span class="cx">     if (m_prototype.get().isCell())
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeStructureh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/Structure.h (173798 => 173799)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/Structure.h        2014-09-21 20:30:10 UTC (rev 173798)
+++ trunk/Source/JavaScriptCore/runtime/Structure.h        2014-09-21 23:52:31 UTC (rev 173799)
</span><span class="lines">@@ -73,6 +73,26 @@
</span><span class="cx"> // initial allocation.
</span><span class="cx"> static const unsigned outOfLineGrowthFactor = 2;
</span><span class="cx"> 
</span><ins>+struct PropertyMapEntry {
+    StringImpl* key;
+    PropertyOffset offset;
+    unsigned attributes;
+
+    PropertyMapEntry()
+        : key(nullptr)
+        , offset(invalidOffset)
+        , attributes(0)
+    {
+    }
+    
+    PropertyMapEntry(StringImpl* key, PropertyOffset offset, unsigned attributes)
+        : key(key)
+        , offset(offset)
+        , attributes(attributes)
+    {
+    }
+};
+
</ins><span class="cx"> class Structure : public JSCell {
</span><span class="cx"> public:
</span><span class="cx">     friend class StructureTransitionTable;
</span><span class="lines">@@ -262,9 +282,18 @@
</span><span class="cx">     PropertyOffset get(VM&amp;, PropertyName);
</span><span class="cx">     PropertyOffset get(VM&amp;, PropertyName, unsigned&amp; attributes);
</span><span class="cx"> 
</span><ins>+    // This is a somewhat internalish method. It will call your functor while possibly holding the
+    // Structure's lock. There is no guarantee whether the lock is held or not in any particular
+    // call. So, you have to assume the worst. Also, the functor returns true if it wishes for you
+    // to continue or false if it's done.
+    template&lt;typename Functor&gt;
+    void forEachPropertyConcurrently(const Functor&amp;);
+    
</ins><span class="cx">     PropertyOffset getConcurrently(StringImpl* uid);
</span><span class="cx">     PropertyOffset getConcurrently(StringImpl* uid, unsigned&amp; attributes);
</span><span class="cx">     
</span><ins>+    Vector&lt;PropertyMapEntry&gt; getPropertiesConcurrently();
+    
</ins><span class="cx">     void setHasGetterSetterPropertiesWithProtoCheck(bool is__proto__)
</span><span class="cx">     {
</span><span class="cx">         setHasGetterSetterProperties(true);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeStructureInlinesh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/StructureInlines.h (173798 => 173799)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/StructureInlines.h        2014-09-21 20:30:10 UTC (rev 173798)
+++ trunk/Source/JavaScriptCore/runtime/StructureInlines.h        2014-09-21 23:52:31 UTC (rev 173799)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2013 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2013, 2014 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -104,6 +104,35 @@
</span><span class="cx">     return entry-&gt;offset;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+template&lt;typename Functor&gt;
+void Structure::forEachPropertyConcurrently(const Functor&amp; functor)
+{
+    Vector&lt;Structure*, 8&gt; structures;
+    Structure* structure;
+    PropertyTable* table;
+    
+    findStructuresAndMapForMaterialization(structures, structure, table);
+    
+    if (table) {
+        for (auto&amp; entry : *table) {
+            if (!functor(entry)) {
+                structure-&gt;m_lock.unlock();
+                return;
+            }
+        }
+        structure-&gt;m_lock.unlock();
+    }
+    
+    for (unsigned i = structures.size(); i--;) {
+        structure = structures[i];
+        if (!structure-&gt;m_nameInPrevious)
+            continue;
+        
+        if (!functor(PropertyMapEntry(structure-&gt;m_nameInPrevious.get(), structure-&gt;m_offset, structure-&gt;attributesInPrevious())))
+            return;
+    }
+}
+
</ins><span class="cx"> inline PropertyOffset Structure::getConcurrently(StringImpl* uid)
</span><span class="cx"> {
</span><span class="cx">     unsigned attributesIgnored;
</span></span></pre>
</div>
</div>

</body>
</html>