<!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>[186986] 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/186986">186986</a></dd>
<dt>Author</dt> <dd>fpizlo@apple.com</dd>
<dt>Date</dt> <dd>2015-07-17 22:51:06 -0700 (Fri, 17 Jul 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>DFG should have some obvious mitigations against watching structures that are unprofitable to watch
https://bugs.webkit.org/show_bug.cgi?id=147034

Reviewed by Mark Lam and Michael Saboff.
        
This implements two guards against the DFG watching structures that are likely to fire
their watchpoints:
        
- Don't watch dictionaries or any structure that had a dictionary in its past. Dictionaries
  can be flattened, and then they can transform back to dictionaries.
        
- Don't watch structures whose past structures were transitioned-away from while their
  transition watchpoints were being watched. This property gives us monotonicity: if we
  recompile because we watched structure S1 of object O, then we won't make the same mistake
  again when object O has structure S2, S3, and so on.
        
This is a 1.5% speed-up on Kraken. It does penalize some Octane tests, but it also seems to
help some of them, so on Octane it's basically neutral.

* bytecode/Watchpoint.h:
(JSC::WatchpointSet::invalidate):
(JSC::WatchpointSet::isBeingWatched):
(JSC::WatchpointSet::addressOfState):
(JSC::WatchpointSet::addressOfSetIsNotEmpty):
(JSC::InlineWatchpointSet::touch):
(JSC::InlineWatchpointSet::isBeingWatched):
* runtime/JSGlobalObject.h:
(JSC::JSGlobalObject::createStructure):
(JSC::JSGlobalObject::registerWeakMap):
* runtime/Structure.cpp:
(JSC::Structure::Structure):
(JSC::Structure::toDictionaryTransition):
(JSC::Structure::didTransitionFromThisStructure):
* runtime/Structure.h:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCorebytecodeWatchpointh">trunk/Source/JavaScriptCore/bytecode/Watchpoint.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSGlobalObjecth">trunk/Source/JavaScriptCore/runtime/JSGlobalObject.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>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (186985 => 186986)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2015-07-18 05:49:32 UTC (rev 186985)
+++ trunk/Source/JavaScriptCore/ChangeLog        2015-07-18 05:51:06 UTC (rev 186986)
</span><span class="lines">@@ -1,3 +1,40 @@
</span><ins>+2015-07-17  Filip Pizlo  &lt;fpizlo@apple.com&gt;
+
+        DFG should have some obvious mitigations against watching structures that are unprofitable to watch
+        https://bugs.webkit.org/show_bug.cgi?id=147034
+
+        Reviewed by Mark Lam and Michael Saboff.
+        
+        This implements two guards against the DFG watching structures that are likely to fire
+        their watchpoints:
+        
+        - Don't watch dictionaries or any structure that had a dictionary in its past. Dictionaries
+          can be flattened, and then they can transform back to dictionaries.
+        
+        - Don't watch structures whose past structures were transitioned-away from while their
+          transition watchpoints were being watched. This property gives us monotonicity: if we
+          recompile because we watched structure S1 of object O, then we won't make the same mistake
+          again when object O has structure S2, S3, and so on.
+        
+        This is a 1.5% speed-up on Kraken. It does penalize some Octane tests, but it also seems to
+        help some of them, so on Octane it's basically neutral.
+
+        * bytecode/Watchpoint.h:
+        (JSC::WatchpointSet::invalidate):
+        (JSC::WatchpointSet::isBeingWatched):
+        (JSC::WatchpointSet::addressOfState):
+        (JSC::WatchpointSet::addressOfSetIsNotEmpty):
+        (JSC::InlineWatchpointSet::touch):
+        (JSC::InlineWatchpointSet::isBeingWatched):
+        * runtime/JSGlobalObject.h:
+        (JSC::JSGlobalObject::createStructure):
+        (JSC::JSGlobalObject::registerWeakMap):
+        * runtime/Structure.cpp:
+        (JSC::Structure::Structure):
+        (JSC::Structure::toDictionaryTransition):
+        (JSC::Structure::didTransitionFromThisStructure):
+        * runtime/Structure.h:
+
</ins><span class="cx"> 2015-07-16  Filip Pizlo  &lt;fpizlo@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Remove DFG::DesiredWriteBarriers because it's just a very difficult way of saying &quot;please barrier the machine code block owner&quot;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebytecodeWatchpointh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/bytecode/Watchpoint.h (186985 => 186986)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/bytecode/Watchpoint.h        2015-07-18 05:49:32 UTC (rev 186985)
+++ trunk/Source/JavaScriptCore/bytecode/Watchpoint.h        2015-07-18 05:51:06 UTC (rev 186986)
</span><span class="lines">@@ -188,6 +188,11 @@
</span><span class="cx">         invalidate(StringFireDetail(reason));
</span><span class="cx">     }
</span><span class="cx">     
</span><ins>+    bool isBeingWatched() const
+    {
+        return m_setIsNotEmpty;
+    }
+    
</ins><span class="cx">     int8_t* addressOfState() { return &amp;m_state; }
</span><span class="cx">     int8_t* addressOfSetIsNotEmpty() { return &amp;m_setIsNotEmpty; }
</span><span class="cx">     
</span><span class="lines">@@ -331,6 +336,13 @@
</span><span class="cx">         touch(StringFireDetail(reason));
</span><span class="cx">     }
</span><span class="cx">     
</span><ins>+    bool isBeingWatched() const
+    {
+        if (isFat())
+            return fat()-&gt;isBeingWatched();
+        return false;
+    }
+    
</ins><span class="cx"> private:
</span><span class="cx">     static const uintptr_t IsThinFlag        = 1;
</span><span class="cx">     static const uintptr_t StateMask         = 6;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSGlobalObjecth"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h (186985 => 186986)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h        2015-07-18 05:49:32 UTC (rev 186985)
+++ trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h        2015-07-18 05:51:06 UTC (rev 186986)
</span><span class="lines">@@ -613,7 +613,9 @@
</span><span class="cx"> 
</span><span class="cx">     static Structure* createStructure(VM&amp; vm, JSValue prototype)
</span><span class="cx">     {
</span><del>-        return Structure::create(vm, 0, prototype, TypeInfo(GlobalObjectType, StructureFlags), info());
</del><ins>+        Structure* result = Structure::create(vm, 0, prototype, TypeInfo(GlobalObjectType, StructureFlags), info());
+        result-&gt;setTransitionWatchpointIsLikelyToBeFired(true);
+        return result;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     void registerWeakMap(OpaqueJSWeakObjectMap* map)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeStructurecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/Structure.cpp (186985 => 186986)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/Structure.cpp        2015-07-18 05:49:32 UTC (rev 186985)
+++ trunk/Source/JavaScriptCore/runtime/Structure.cpp        2015-07-18 05:51:06 UTC (rev 186986)
</span><span class="lines">@@ -171,6 +171,7 @@
</span><span class="cx">     setDidTransition(false);
</span><span class="cx">     setStaticFunctionsReified(false);
</span><span class="cx">     setHasRareData(false);
</span><ins>+    setTransitionWatchpointIsLikelyToBeFired(false);
</ins><span class="cx">  
</span><span class="cx">     ASSERT(inlineCapacity &lt;= JSFinalObject::maxInlineCapacity());
</span><span class="cx">     ASSERT(static_cast&lt;PropertyOffset&gt;(inlineCapacity) &lt; firstOutOfLineOffset);
</span><span class="lines">@@ -201,6 +202,7 @@
</span><span class="cx">     setDidTransition(false);
</span><span class="cx">     setStaticFunctionsReified(false);
</span><span class="cx">     setHasRareData(false);
</span><ins>+    setTransitionWatchpointIsLikelyToBeFired(false);
</ins><span class="cx">  
</span><span class="cx">     TypeInfo typeInfo = TypeInfo(CellType, StructureFlags);
</span><span class="cx">     m_blob = StructureIDBlob(vm.heap.structureIDTable().allocateID(this), 0, typeInfo);
</span><span class="lines">@@ -239,6 +241,10 @@
</span><span class="cx">     setPreviousID(vm, previous);
</span><span class="cx"> 
</span><span class="cx">     previous-&gt;didTransitionFromThisStructure(deferred);
</span><ins>+    
+    // Copy this bit now, in case previous was being watched.
+    setTransitionWatchpointIsLikelyToBeFired(previous-&gt;transitionWatchpointIsLikelyToBeFired());
+
</ins><span class="cx">     if (previous-&gt;m_globalObject)
</span><span class="cx">         m_globalObject.set(vm, this, previous-&gt;m_globalObject.get());
</span><span class="cx">     ASSERT(hasReadOnlyOrGetterSetterPropertiesExcludingProto() || !m_classInfo-&gt;hasStaticSetterOrReadonlyProperties());
</span><span class="lines">@@ -495,6 +501,7 @@
</span><span class="cx">     transition-&gt;m_offset = structure-&gt;m_offset;
</span><span class="cx">     transition-&gt;setDictionaryKind(kind);
</span><span class="cx">     transition-&gt;pin();
</span><ins>+    transition-&gt;setTransitionWatchpointIsLikelyToBeFired(true);
</ins><span class="cx"> 
</span><span class="cx">     transition-&gt;checkOffsetConsistency();
</span><span class="cx">     return transition;
</span><span class="lines">@@ -975,6 +982,12 @@
</span><span class="cx"> 
</span><span class="cx"> void Structure::didTransitionFromThisStructure(DeferredStructureTransitionWatchpointFire* deferred) const
</span><span class="cx"> {
</span><ins>+    // If the structure is being watched, and this is the kind of structure that the DFG would
+    // like to watch, then make sure to note for all future versions of this structure that it's
+    // unwise to watch it.
+    if (m_transitionWatchpointSet.isBeingWatched())
+        const_cast&lt;Structure*&gt;(this)-&gt;setTransitionWatchpointIsLikelyToBeFired(true);
+    
</ins><span class="cx">     if (deferred)
</span><span class="cx">         deferred-&gt;add(this);
</span><span class="cx">     else
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeStructureh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/Structure.h (186985 => 186986)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/Structure.h        2015-07-18 05:49:32 UTC (rev 186985)
+++ trunk/Source/JavaScriptCore/runtime/Structure.h        2015-07-18 05:51:06 UTC (rev 186986)
</span><span class="lines">@@ -413,6 +413,13 @@
</span><span class="cx">         // watching it. We should come up with a comprehensive story for not watching things that
</span><span class="cx">         // aren't profitable to watch.
</span><span class="cx">         // https://bugs.webkit.org/show_bug.cgi?id=133625
</span><ins>+        
+        // - We don't watch Structures that either decided not to be watched, or whose predecessors
+        //   decided not to be watched. This happens either when a transition is fired while being
+        //   watched, or if a dictionary transition occurs.
+        if (transitionWatchpointIsLikelyToBeFired())
+            return false;
+        
</ins><span class="cx">         return true;
</span><span class="cx">     }
</span><span class="cx">     
</span><span class="lines">@@ -502,6 +509,7 @@
</span><span class="cx">     DEFINE_BITFIELD(bool, hasBeenFlattenedBefore, HasBeenFlattenedBefore, 1, 24);
</span><span class="cx">     DEFINE_BITFIELD(bool, hasCustomGetterSetterProperties, HasCustomGetterSetterProperties, 1, 25);
</span><span class="cx">     DEFINE_BITFIELD(bool, didWatchInternalProperties, DidWatchInternalProperties, 1, 26);
</span><ins>+    DEFINE_BITFIELD(bool, transitionWatchpointIsLikelyToBeFired, TransitionWatchpointIsLikelyToBeFired, 1, 27);
</ins><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     friend class LLIntOffsetsExtractor;
</span></span></pre>
</div>
</div>

</body>
</html>