<!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>[199162] 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/199162">199162</a></dd>
<dt>Author</dt> <dd>fpizlo@apple.com</dd>
<dt>Date</dt> <dd>2016-04-07 10:59:24 -0700 (Thu, 07 Apr 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Rationalize the handling of PutById transitions a bit
https://bugs.webkit.org/show_bug.cgi?id=156330

Reviewed by Mark Lam.

* bytecode/PolymorphicAccess.cpp:
(JSC::AccessCase::generate): Get rid of the specialized slow calls. We can just use the failAndIgnore jump target. We just need to make sure that we don't make observable effects until we're done with all of the fast path checks.
* bytecode/StructureStubInfo.cpp:
(JSC::StructureStubInfo::addAccessCase): MadeNoChanges indicates that we should keep trying to repatch. Currently PutById transitions might trigger the case that addAccessCase() sees null, if the transition involves an indexing header. Doing repatching in that case is probably not good. But, we should just fix this the right way eventually.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCorebytecodePolymorphicAccesscpp">trunk/Source/JavaScriptCore/bytecode/PolymorphicAccess.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorebytecodeStructureStubInfocpp">trunk/Source/JavaScriptCore/bytecode/StructureStubInfo.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (199161 => 199162)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2016-04-07 17:40:48 UTC (rev 199161)
+++ trunk/Source/JavaScriptCore/ChangeLog        2016-04-07 17:59:24 UTC (rev 199162)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2016-04-07  Filip Pizlo  &lt;fpizlo@apple.com&gt;
+
+        Rationalize the handling of PutById transitions a bit
+        https://bugs.webkit.org/show_bug.cgi?id=156330
+
+        Reviewed by Mark Lam.
+
+        * bytecode/PolymorphicAccess.cpp:
+        (JSC::AccessCase::generate): Get rid of the specialized slow calls. We can just use the failAndIgnore jump target. We just need to make sure that we don't make observable effects until we're done with all of the fast path checks.
+        * bytecode/StructureStubInfo.cpp:
+        (JSC::StructureStubInfo::addAccessCase): MadeNoChanges indicates that we should keep trying to repatch. Currently PutById transitions might trigger the case that addAccessCase() sees null, if the transition involves an indexing header. Doing repatching in that case is probably not good. But, we should just fix this the right way eventually.
+
</ins><span class="cx"> 2016-04-07  Per Arne Vollan  &lt;peavo@outlook.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [Win] Fix for JSC stress test failures.
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebytecodePolymorphicAccesscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/bytecode/PolymorphicAccess.cpp (199161 => 199162)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/bytecode/PolymorphicAccess.cpp        2016-04-07 17:40:48 UTC (rev 199161)
+++ trunk/Source/JavaScriptCore/bytecode/PolymorphicAccess.cpp        2016-04-07 17:59:24 UTC (rev 199162)
</span><span class="lines">@@ -1034,7 +1034,8 @@
</span><span class="cx">         } else if (verbose)
</span><span class="cx">             dataLog(&quot;Don't have type.\n&quot;);
</span><span class="cx">         
</span><del>-        CCallHelpers::JumpList slowPath;
</del><ins>+        bool allocating = newStructure()-&gt;outOfLineCapacity() != structure()-&gt;outOfLineCapacity();
+        bool reallocating = allocating &amp;&amp; structure()-&gt;outOfLineCapacity();
</ins><span class="cx"> 
</span><span class="cx">         ScratchRegisterAllocator allocator(stubInfo.patch.usedRegisters);
</span><span class="cx">         allocator.lock(baseGPR);
</span><span class="lines">@@ -1046,25 +1047,23 @@
</span><span class="cx"> 
</span><span class="cx">         GPRReg scratchGPR2 = allocator.allocateScratchGPR();
</span><span class="cx">         GPRReg scratchGPR3;
</span><del>-        if (newStructure()-&gt;outOfLineCapacity() != structure()-&gt;outOfLineCapacity()
-            &amp;&amp; structure()-&gt;outOfLineCapacity())
</del><ins>+        if (allocating)
</ins><span class="cx">             scratchGPR3 = allocator.allocateScratchGPR();
</span><span class="cx">         else
</span><span class="cx">             scratchGPR3 = InvalidGPRReg;
</span><span class="cx"> 
</span><span class="cx">         ScratchRegisterAllocator::PreservedState preservedState =
</span><span class="cx">             allocator.preserveReusedRegistersByPushing(jit, ScratchRegisterAllocator::ExtraStackSpace::SpaceForCCall);
</span><ins>+        
+        CCallHelpers::JumpList slowPath;
</ins><span class="cx"> 
</span><span class="cx">         ASSERT(structure()-&gt;transitionWatchpointSetHasBeenInvalidated());
</span><span class="cx"> 
</span><del>-        bool scratchGPRHasStorage = false;
-        bool needsToMakeRoomOnStackForCCall = !preservedState.numberOfBytesPreserved &amp;&amp; codeBlock-&gt;jitType() == JITCode::FTLJIT;
-
-        if (newStructure()-&gt;outOfLineCapacity() != structure()-&gt;outOfLineCapacity()) {
</del><ins>+        if (allocating) {
</ins><span class="cx">             size_t newSize = newStructure()-&gt;outOfLineCapacity() * sizeof(JSValue);
</span><span class="cx">             CopiedAllocator* copiedAllocator = &amp;vm.heap.storageAllocator();
</span><span class="cx"> 
</span><del>-            if (!structure()-&gt;outOfLineCapacity()) {
</del><ins>+            if (!reallocating) {
</ins><span class="cx">                 jit.loadPtr(&amp;copiedAllocator-&gt;m_currentRemaining, scratchGPR);
</span><span class="cx">                 slowPath.append(
</span><span class="cx">                     jit.branchSubPtr(
</span><span class="lines">@@ -1104,16 +1103,8 @@
</span><span class="cx">                             -static_cast&lt;ptrdiff_t&gt;(offset + sizeof(JSValue) + sizeof(void*))));
</span><span class="cx">                 }
</span><span class="cx">             }
</span><del>-
-            jit.storePtr(scratchGPR, CCallHelpers::Address(baseGPR, JSObject::butterflyOffset()));
-            scratchGPRHasStorage = true;
</del><span class="cx">         }
</span><span class="cx"> 
</span><del>-        uint32_t structureBits = bitwise_cast&lt;uint32_t&gt;(newStructure()-&gt;id());
-        jit.store32(
-            CCallHelpers::TrustedImm32(structureBits),
-            CCallHelpers::Address(baseGPR, JSCell::structureIDOffset()));
-
</del><span class="cx">         if (isInlineOffset(m_offset)) {
</span><span class="cx">             jit.storeValue(
</span><span class="cx">                 valueRegs,
</span><span class="lines">@@ -1122,100 +1113,55 @@
</span><span class="cx">                     JSObject::offsetOfInlineStorage() +
</span><span class="cx">                     offsetInInlineStorage(m_offset) * sizeof(JSValue)));
</span><span class="cx">         } else {
</span><del>-            if (!scratchGPRHasStorage)
</del><ins>+            if (!allocating)
</ins><span class="cx">                 jit.loadPtr(CCallHelpers::Address(baseGPR, JSObject::butterflyOffset()), scratchGPR);
</span><span class="cx">             jit.storeValue(
</span><span class="cx">                 valueRegs,
</span><span class="cx">                 CCallHelpers::Address(scratchGPR, offsetInButterfly(m_offset) * sizeof(JSValue)));
</span><span class="cx">         }
</span><del>-
-        ScratchBuffer* scratchBuffer = nullptr;
-        if (newStructure()-&gt;outOfLineCapacity() != structure()-&gt;outOfLineCapacity())
-            scratchBuffer = vm.scratchBufferForSize(allocator.desiredScratchBufferSizeForCall());
-
-        if (newStructure()-&gt;outOfLineCapacity() != structure()-&gt;outOfLineCapacity()) {
-            CCallHelpers::Call callFlushWriteBarrierBuffer;
</del><ins>+        
+        if (allocating) {
</ins><span class="cx">             CCallHelpers::Jump ownerIsRememberedOrInEden = jit.jumpIfIsRememberedOrInEden(baseGPR);
</span><span class="cx">             WriteBarrierBuffer&amp; writeBarrierBuffer = jit.vm()-&gt;heap.writeBarrierBuffer();
</span><span class="cx">             jit.load32(writeBarrierBuffer.currentIndexAddress(), scratchGPR2);
</span><del>-            CCallHelpers::Jump needToFlush =
</del><ins>+            slowPath.append(
</ins><span class="cx">                 jit.branch32(
</span><span class="cx">                     CCallHelpers::AboveOrEqual, scratchGPR2,
</span><del>-                    CCallHelpers::TrustedImm32(writeBarrierBuffer.capacity()));
</del><ins>+                    CCallHelpers::TrustedImm32(writeBarrierBuffer.capacity())));
</ins><span class="cx"> 
</span><span class="cx">             jit.add32(CCallHelpers::TrustedImm32(1), scratchGPR2);
</span><span class="cx">             jit.store32(scratchGPR2, writeBarrierBuffer.currentIndexAddress());
</span><span class="cx"> 
</span><del>-            jit.move(CCallHelpers::TrustedImmPtr(writeBarrierBuffer.buffer()), scratchGPR);
</del><ins>+            jit.move(CCallHelpers::TrustedImmPtr(writeBarrierBuffer.buffer()), scratchGPR3);
</ins><span class="cx">             // We use an offset of -sizeof(void*) because we already added 1 to scratchGPR2.
</span><span class="cx">             jit.storePtr(
</span><span class="cx">                 baseGPR,
</span><span class="cx">                 CCallHelpers::BaseIndex(
</span><del>-                    scratchGPR, scratchGPR2, CCallHelpers::ScalePtr,
</del><ins>+                    scratchGPR3, scratchGPR2, CCallHelpers::ScalePtr,
</ins><span class="cx">                     static_cast&lt;int32_t&gt;(-sizeof(void*))));
</span><del>-
-            CCallHelpers::Jump doneWithBarrier = jit.jump();
-            needToFlush.link(&amp;jit);
-
-            // FIXME: We should restoreReusedRegistersByPopping() before this. Then, we wouldn't need
-            // padding in preserveReusedRegistersByPushing(). Or, maybe it would be even better if the
-            // barrier slow path was just the normal slow path, below.
-            // https://bugs.webkit.org/show_bug.cgi?id=149030
-            allocator.preserveUsedRegistersToScratchBufferForCall(jit, scratchBuffer, scratchGPR2);
-            if (needsToMakeRoomOnStackForCCall)
-                jit.makeSpaceOnStackForCCall();
-            jit.setupArgumentsWithExecState(baseGPR);
-            callFlushWriteBarrierBuffer = jit.call();
-            if (needsToMakeRoomOnStackForCCall)
-                jit.reclaimSpaceOnStackForCCall();
-            allocator.restoreUsedRegistersFromScratchBufferForCall(
-                jit, scratchBuffer, scratchGPR2);
-
-            doneWithBarrier.link(&amp;jit);
</del><span class="cx">             ownerIsRememberedOrInEden.link(&amp;jit);
</span><del>-
-            state.callbacks.append(
-                [=] (LinkBuffer&amp; linkBuffer) {
-                    linkBuffer.link(callFlushWriteBarrierBuffer, operationFlushWriteBarrierBuffer);
-                });
</del><span class="cx">         }
</span><span class="cx">         
</span><ins>+        // We set the new butterfly and the structure last. Doing it this way ensures that whatever
+        // we had done up to this point is forgotten if we choose to branch to slow path.
+        
+        if (allocating)
+            jit.storePtr(scratchGPR, CCallHelpers::Address(baseGPR, JSObject::butterflyOffset()));
+        
+        uint32_t structureBits = bitwise_cast&lt;uint32_t&gt;(newStructure()-&gt;id());
+        jit.store32(
+            CCallHelpers::TrustedImm32(structureBits),
+            CCallHelpers::Address(baseGPR, JSCell::structureIDOffset()));
+
</ins><span class="cx">         allocator.restoreReusedRegistersByPopping(jit, preservedState);
</span><span class="cx">         state.succeed();
</span><del>-
-        if (newStructure()-&gt;outOfLineCapacity() != structure()-&gt;outOfLineCapacity()) {
</del><ins>+        
+        if (allocator.didReuseRegisters()) {
</ins><span class="cx">             slowPath.link(&amp;jit);
</span><span class="cx">             allocator.restoreReusedRegistersByPopping(jit, preservedState);
</span><del>-            allocator.preserveUsedRegistersToScratchBufferForCall(jit, scratchBuffer, scratchGPR);
-            if (needsToMakeRoomOnStackForCCall)
-                jit.makeSpaceOnStackForCCall();
-            jit.store32(
-                CCallHelpers::TrustedImm32(state.originalCallSiteIndex().bits()),
-                CCallHelpers::tagFor(static_cast&lt;VirtualRegister&gt;(JSStack::ArgumentCount)));
-#if USE(JSVALUE64)
-            jit.setupArgumentsWithExecState(
-                baseGPR,
-                CCallHelpers::TrustedImmPtr(newStructure()),
-                CCallHelpers::TrustedImm32(m_offset),
-                valueRegs.gpr());
-#else
-            jit.setupArgumentsWithExecState(
-                baseGPR,
-                CCallHelpers::TrustedImmPtr(newStructure()),
-                CCallHelpers::TrustedImm32(m_offset),
-                valueRegs.payloadGPR(), valueRegs.tagGPR());
-#endif
-            CCallHelpers::Call operationCall = jit.call();
-            if (needsToMakeRoomOnStackForCCall)
-                jit.reclaimSpaceOnStackForCCall();
-            allocator.restoreUsedRegistersFromScratchBufferForCall(jit, scratchBuffer, scratchGPR);
-            state.succeed();
-
-            state.callbacks.append(
-                [=] (LinkBuffer&amp; linkBuffer) {
-                    linkBuffer.link(operationCall, operationReallocateStorageAndFinishPut);
-                });
-        }
</del><ins>+            state.failAndIgnore.append(jit.jump());
+        } else
+            state.failAndIgnore.append(slowPath);
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebytecodeStructureStubInfocpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/bytecode/StructureStubInfo.cpp (199161 => 199162)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/bytecode/StructureStubInfo.cpp        2016-04-07 17:40:48 UTC (rev 199161)
+++ trunk/Source/JavaScriptCore/bytecode/StructureStubInfo.cpp        2016-04-07 17:59:24 UTC (rev 199162)
</span><span class="lines">@@ -110,7 +110,7 @@
</span><span class="cx">     VM&amp; vm = *codeBlock-&gt;vm();
</span><span class="cx">     
</span><span class="cx">     if (!accessCase)
</span><del>-        return AccessGenerationResult::MadeNoChanges;
</del><ins>+        return AccessGenerationResult::GaveUp;
</ins><span class="cx">     
</span><span class="cx">     if (cacheType == CacheType::Stub)
</span><span class="cx">         return u.stub-&gt;regenerateWithCase(vm, codeBlock, *this, ident, WTFMove(accessCase));
</span></span></pre>
</div>
</div>

</body>
</html>