<!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>[172099] trunk</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/172099">172099</a></dd>
<dt>Author</dt> <dd>akling@apple.com</dd>
<dt>Date</dt> <dd>2014-08-05 16:10:38 -0700 (Tue, 05 Aug 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>The JIT should cache property lookup misses.
&lt;https://webkit.org/b/135578&gt;

Source/JavaScriptCore:

Add support for inline caching of object properties that don't exist.
Previously we'd fall back to the C++ slow-path whenever a property was missing.

It's implemented as a simple GetById-style stub that returns jsUndefined() as
long as the Structure chain check passes.

10x speedup on the included microbenchmark.

Reviewed by Geoffrey Garen.

* jit/Repatch.cpp:
(JSC::toString):
(JSC::kindFor):
(JSC::generateByIdStub):
(JSC::tryCacheGetByID):
(JSC::patchJumpToGetByIdStub):
* runtime/PropertySlot.h:
(JSC::PropertySlot::isUnset):

LayoutTests:

Add a JS microbenchmark that accesses an undefined property in a hot loop.

Reviewed by Geoffrey Garen.

* js/regress/script-tests/undefined-property-access.js: Added.
(foo):
* js/regress/undefined-property-access-expected.txt: Added.
* js/regress/undefined-property-access.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCorejitRepatchcpp">trunk/Source/JavaScriptCore/jit/Repatch.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimePropertySloth">trunk/Source/JavaScriptCore/runtime/PropertySlot.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsjsregressscripttestsundefinedpropertyaccessjs">trunk/LayoutTests/js/regress/script-tests/undefined-property-access.js</a></li>
<li><a href="#trunkLayoutTestsjsregressundefinedpropertyaccessexpectedtxt">trunk/LayoutTests/js/regress/undefined-property-access-expected.txt</a></li>
<li><a href="#trunkLayoutTestsjsregressundefinedpropertyaccesshtml">trunk/LayoutTests/js/regress/undefined-property-access.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (172098 => 172099)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2014-08-05 23:06:03 UTC (rev 172098)
+++ trunk/LayoutTests/ChangeLog        2014-08-05 23:10:38 UTC (rev 172099)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2014-08-05  Andreas Kling  &lt;akling@apple.com&gt;
+
+        The JIT should cache property lookup misses.
+        &lt;https://webkit.org/b/135578&gt;
+
+        Add a JS microbenchmark that accesses an undefined property in a hot loop.
+
+        Reviewed by Geoffrey Garen.
+
+        * js/regress/script-tests/undefined-property-access.js: Added.
+        (foo):
+        * js/regress/undefined-property-access-expected.txt: Added.
+        * js/regress/undefined-property-access.html: Added.
+
</ins><span class="cx"> 2014-08-05  Martin Hodovan  &lt;mhodovan.u-szeged@partner.samsung.com&gt;
</span><span class="cx"> 
</span><span class="cx">         ASSERTION FAILED: name[0] == '@' &amp;&amp; length &gt;= 2 in WebCore::CSSParser::detectAtToken
</span></span></pre></div>
<a id="trunkLayoutTestsjsregressscripttestsundefinedpropertyaccessjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/regress/script-tests/undefined-property-access.js (0 => 172099)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/regress/script-tests/undefined-property-access.js                                (rev 0)
+++ trunk/LayoutTests/js/regress/script-tests/undefined-property-access.js        2014-08-05 23:10:38 UTC (rev 172099)
</span><span class="lines">@@ -0,0 +1,9 @@
</span><ins>+someGlobal = 0;
+
+function foo() {
+    var myObject = {};
+    for (var i = 0; i &lt; 10000000; ++i) {
+        someGlobal = myObject.undefinedProperty;
+    }
+}
+foo();
</ins></span></pre></div>
<a id="trunkLayoutTestsjsregressundefinedpropertyaccessexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/regress/undefined-property-access-expected.txt (0 => 172099)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/regress/undefined-property-access-expected.txt                                (rev 0)
+++ trunk/LayoutTests/js/regress/undefined-property-access-expected.txt        2014-08-05 23:10:38 UTC (rev 172099)
</span><span class="lines">@@ -0,0 +1,10 @@
</span><ins>+JSRegress/undefined-property-access
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+PASS no exception thrown
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsjsregressundefinedpropertyaccesshtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/regress/undefined-property-access.html (0 => 172099)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/regress/undefined-property-access.html                                (rev 0)
+++ trunk/LayoutTests/js/regress/undefined-property-access.html        2014-08-05 23:10:38 UTC (rev 172099)
</span><span class="lines">@@ -0,0 +1,12 @@
</span><ins>+&lt;!DOCTYPE HTML PUBLIC &quot;-//IETF//DTD HTML//EN&quot;&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;script src=&quot;../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;script src=&quot;../../resources/regress-pre.js&quot;&gt;&lt;/script&gt;
+&lt;script src=&quot;script-tests/undefined-property-access.js&quot;&gt;&lt;/script&gt;
+&lt;script src=&quot;../../resources/regress-post.js&quot;&gt;&lt;/script&gt;
+&lt;script src=&quot;../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (172098 => 172099)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2014-08-05 23:06:03 UTC (rev 172098)
+++ trunk/Source/JavaScriptCore/ChangeLog        2014-08-05 23:10:38 UTC (rev 172099)
</span><span class="lines">@@ -1,3 +1,27 @@
</span><ins>+2014-08-05  Andreas Kling  &lt;akling@apple.com&gt;
+
+        The JIT should cache property lookup misses.
+        &lt;https://webkit.org/b/135578&gt;
+
+        Add support for inline caching of object properties that don't exist.
+        Previously we'd fall back to the C++ slow-path whenever a property was missing.
+
+        It's implemented as a simple GetById-style stub that returns jsUndefined() as
+        long as the Structure chain check passes.
+
+        10x speedup on the included microbenchmark.
+
+        Reviewed by Geoffrey Garen.
+
+        * jit/Repatch.cpp:
+        (JSC::toString):
+        (JSC::kindFor):
+        (JSC::generateByIdStub):
+        (JSC::tryCacheGetByID):
+        (JSC::patchJumpToGetByIdStub):
+        * runtime/PropertySlot.h:
+        (JSC::PropertySlot::isUnset):
+
</ins><span class="cx"> 2014-08-05  Commit Queue  &lt;commit-queue@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed, rolling out r172009.
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorejitRepatchcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/jit/Repatch.cpp (172098 => 172099)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/jit/Repatch.cpp        2014-08-05 23:06:03 UTC (rev 172098)
+++ trunk/Source/JavaScriptCore/jit/Repatch.cpp        2014-08-05 23:10:38 UTC (rev 172099)
</span><span class="lines">@@ -52,6 +52,8 @@
</span><span class="cx"> 
</span><span class="cx"> namespace JSC {
</span><span class="cx"> 
</span><ins>+static void patchJumpToGetByIdStub(CodeBlock*, StructureStubInfo&amp;, JITStubRoutine*);
+
</ins><span class="cx"> // Beware: in this code, it is not safe to assume anything about the following registers
</span><span class="cx"> // that would ordinarily have well-known values:
</span><span class="cx"> // - tagTypeNumberRegister
</span><span class="lines">@@ -226,6 +228,7 @@
</span><span class="cx"> 
</span><span class="cx"> enum ByIdStubKind {
</span><span class="cx">     GetValue,
</span><ins>+    GetUndefined,
</ins><span class="cx">     CallGetter,
</span><span class="cx">     CallCustomGetter,
</span><span class="cx">     CallSetter,
</span><span class="lines">@@ -237,6 +240,8 @@
</span><span class="cx">     switch (kind) {
</span><span class="cx">     case GetValue:
</span><span class="cx">         return &quot;GetValue&quot;;
</span><ins>+    case GetUndefined:
+        return &quot;GetUndefined&quot;;
</ins><span class="cx">     case CallGetter:
</span><span class="cx">         return &quot;CallGetter&quot;;
</span><span class="cx">     case CallCustomGetter:
</span><span class="lines">@@ -255,6 +260,8 @@
</span><span class="cx"> {
</span><span class="cx">     if (slot.isCacheableValue())
</span><span class="cx">         return GetValue;
</span><ins>+    if (slot.isUnset())
+        return GetUndefined;
</ins><span class="cx">     if (slot.isCacheableCustom())
</span><span class="cx">         return CallCustomGetter;
</span><span class="cx">     RELEASE_ASSERT(slot.isCacheableGetter());
</span><span class="lines">@@ -299,7 +306,7 @@
</span><span class="cx">         static_cast&lt;GPRReg&gt;(stubInfo.patch.valueGPR));
</span><span class="cx">     GPRReg scratchGPR = TempRegisterSet(stubInfo.patch.usedRegisters).getFreeGPR();
</span><span class="cx">     bool needToRestoreScratch = scratchGPR == InvalidGPRReg;
</span><del>-    RELEASE_ASSERT(!needToRestoreScratch || kind == GetValue);
</del><ins>+    RELEASE_ASSERT(!needToRestoreScratch || (kind == GetValue || kind == GetUndefined));
</ins><span class="cx">     
</span><span class="cx">     CCallHelpers stubJit(&amp;exec-&gt;vm(), exec-&gt;codeBlock());
</span><span class="cx">     if (needToRestoreScratch) {
</span><span class="lines">@@ -357,24 +364,28 @@
</span><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx">     
</span><del>-    GPRReg baseForAccessGPR;
-    if (chain) {
-        // We could have clobbered scratchGPR earlier, so we have to reload from baseGPR to get the target.
-        if (loadTargetFromProxy)
-            stubJit.loadPtr(MacroAssembler::Address(baseGPR, JSProxy::targetOffset()), baseForGetGPR);
-        stubJit.move(MacroAssembler::TrustedImmPtr(protoObject), scratchGPR);
-        baseForAccessGPR = scratchGPR;
-    } else {
-        // For proxy objects, we need to do all the Structure checks before moving the baseGPR into 
-        // baseForGetGPR because if we fail any of the checks then we would have the wrong value in baseGPR
-        // on the slow path.
-        if (loadTargetFromProxy)
-            stubJit.move(scratchGPR, baseForGetGPR);
-        baseForAccessGPR = baseForGetGPR;
</del><ins>+    GPRReg baseForAccessGPR = InvalidGPRReg;
+    if (kind != GetUndefined) {
+        if (chain) {
+            // We could have clobbered scratchGPR earlier, so we have to reload from baseGPR to get the target.
+            if (loadTargetFromProxy)
+                stubJit.loadPtr(MacroAssembler::Address(baseGPR, JSProxy::targetOffset()), baseForGetGPR);
+            stubJit.move(MacroAssembler::TrustedImmPtr(protoObject), scratchGPR);
+            baseForAccessGPR = scratchGPR;
+        } else {
+            // For proxy objects, we need to do all the Structure checks before moving the baseGPR into
+            // baseForGetGPR because if we fail any of the checks then we would have the wrong value in baseGPR
+            // on the slow path.
+            if (loadTargetFromProxy)
+                stubJit.move(scratchGPR, baseForGetGPR);
+            baseForAccessGPR = baseForGetGPR;
+        }
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     GPRReg loadedValueGPR = InvalidGPRReg;
</span><del>-    if (kind != CallCustomGetter &amp;&amp; kind != CallCustomSetter) {
</del><ins>+    if (kind == GetUndefined)
+        stubJit.moveTrustedValue(jsUndefined(), valueRegs);
+    else if (kind != CallCustomGetter &amp;&amp; kind != CallCustomSetter) {
</ins><span class="cx">         if (kind == GetValue)
</span><span class="cx">             loadedValueGPR = valueRegs.payloadGPR();
</span><span class="cx">         else
</span><span class="lines">@@ -408,7 +419,7 @@
</span><span class="cx">     std::unique_ptr&lt;CallLinkInfo&gt; callLinkInfo;
</span><span class="cx"> 
</span><span class="cx">     MacroAssembler::Jump success, fail;
</span><del>-    if (kind != GetValue) {
</del><ins>+    if (kind != GetValue &amp;&amp; kind != GetUndefined) {
</ins><span class="cx">         // Need to make sure that whenever this call is made in the future, we remember the
</span><span class="cx">         // place that we made it from. It just so happens to be the place that we are at
</span><span class="cx">         // right now!
</span><span class="lines">@@ -729,15 +740,46 @@
</span><span class="cx">     // FIXME: Cache property access for immediates.
</span><span class="cx">     if (!baseValue.isCell())
</span><span class="cx">         return GiveUpOnCache;
</span><ins>+
+    if (!slot.isCacheable() &amp;&amp; !slot.isUnset())
+        return GiveUpOnCache;
+
</ins><span class="cx">     JSCell* baseCell = baseValue.asCell();
</span><span class="cx">     Structure* structure = baseCell-&gt;structure();
</span><del>-    if (!slot.isCacheable())
-        return GiveUpOnCache;
</del><span class="cx"> 
</span><span class="cx">     InlineCacheAction action = actionForCell(*vm, baseCell);
</span><span class="cx">     if (action != AttemptToCache)
</span><span class="cx">         return action;
</span><span class="cx"> 
</span><ins>+    if (slot.isUnset()) {
+        // Property lookup miss - let's try to cache that.
+        size_t count = normalizePrototypeChain(exec, baseCell);
+        if (count == InvalidPrototypeChain)
+            return GiveUpOnCache;
+        StructureChain* prototypeChain = structure-&gt;prototypeChain(exec);
+        PolymorphicGetByIdList* list = PolymorphicGetByIdList::from(stubInfo);
+        if (list-&gt;isFull()) {
+            // We need this extra check because of recursion.
+            return GiveUpOnCache;
+        }
+
+        RefPtr&lt;JITStubRoutine&gt; stubRoutine;
+        generateByIdStub(
+            exec, GetUndefined, propertyName, FunctionPtr(), stubInfo, prototypeChain, count, invalidOffset,
+            structure, false, nullptr,
+            stubInfo.callReturnLocation.labelAtOffset(stubInfo.patch.deltaCallToDone),
+            CodeLocationLabel(list-&gt;currentSlowPathTarget(stubInfo)), stubRoutine);
+
+        list-&gt;addAccess(GetByIdAccess(
+            *vm, codeBlock-&gt;ownerExecutable(),
+            GetByIdAccess::SimpleInline,
+            stubRoutine, structure, prototypeChain, count));
+
+        patchJumpToGetByIdStub(codeBlock, stubInfo, stubRoutine.get());
+
+        return list-&gt;isFull() ? GiveUpOnCache : RetryCacheLater;
+    }
+
</ins><span class="cx">     // Optimize self access.
</span><span class="cx">     if (slot.slotBase() == baseValue
</span><span class="cx">         &amp;&amp; slot.isCacheableValue()
</span><span class="lines">@@ -760,7 +802,7 @@
</span><span class="cx">         repatchCall(exec-&gt;codeBlock(), stubInfo.callReturnLocation, operationGetById);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static void patchJumpToGetByIdStub(CodeBlock* codeBlock, StructureStubInfo&amp; stubInfo, JITStubRoutine* stubRoutine)
</del><ins>+void patchJumpToGetByIdStub(CodeBlock* codeBlock, StructureStubInfo&amp; stubInfo, JITStubRoutine* stubRoutine)
</ins><span class="cx"> {
</span><span class="cx">     RELEASE_ASSERT(stubInfo.accessType == access_get_by_id_list);
</span><span class="cx">     RepatchBuffer repatchBuffer(codeBlock);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimePropertySloth"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/PropertySlot.h (172098 => 172099)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/PropertySlot.h        2014-08-05 23:06:03 UTC (rev 172098)
+++ trunk/Source/JavaScriptCore/runtime/PropertySlot.h        2014-08-05 23:10:38 UTC (rev 172099)
</span><span class="lines">@@ -78,6 +78,7 @@
</span><span class="cx">     JSValue getValue(ExecState*, unsigned propertyName) const;
</span><span class="cx"> 
</span><span class="cx">     bool isCacheable() const { return m_cacheability == CachingAllowed &amp;&amp; m_offset != invalidOffset; }
</span><ins>+    bool isUnset() const { return m_propertyType == TypeUnset; }
</ins><span class="cx">     bool isValue() const { return m_propertyType == TypeValue; }
</span><span class="cx">     bool isAccessor() const { return m_propertyType == TypeGetter; }
</span><span class="cx">     bool isCustom() const { return m_propertyType == TypeCustom; }
</span></span></pre>
</div>
</div>

</body>
</html>