<!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>[225071] 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/225071">225071</a></dd>
<dt>Author</dt> <dd>utatane.tea@gmail.com</dd>
<dt>Date</dt> <dd>2017-11-21 02:07:50 -0800 (Tue, 21 Nov 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>[JSC] Allow poly proto for intrinsic getters
https://bugs.webkit.org/show_bug.cgi?id=179550

Reviewed by Saam Barati.

JSTests:

This change is also tested by existing tests.

    1. stress/intrinsic-getter-with-poly-proto.js
    2. stress/poly-proto-intrinsic-getter-correctness.js

* stress/intrinsic-getter-with-poly-proto-getter-change.js: Added.
(shouldBe):
(makePolyProtoObject.foo.C):
(makePolyProtoObject.foo):
(makePolyProtoObject):
(target):
* stress/intrinsic-getter-with-poly-proto-proto-change.js: Added.
(shouldBe):
(makePolyProtoObject.foo.C):
(makePolyProtoObject.foo):
(makePolyProtoObject):
(target):

Source/JavaScriptCore:

This patch allows intrinsic getters to accept poly proto.
We propagate PolyProtoAccessChain in IntrinsicGetterAccessCase to perform
poly proto checks. And we extend UnderscoreProtoIntrinsic to emit
code for poly proto case.

* bytecode/IntrinsicGetterAccessCase.cpp:
(JSC::IntrinsicGetterAccessCase::IntrinsicGetterAccessCase):
(JSC::IntrinsicGetterAccessCase::create):
* bytecode/IntrinsicGetterAccessCase.h:
* jit/IntrinsicEmitter.cpp:
(JSC::IntrinsicGetterAccessCase::canEmitIntrinsicGetter):
(JSC::IntrinsicGetterAccessCase::emitIntrinsicGetter):
* jit/Repatch.cpp:
(JSC::tryCacheGetByID):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkJSTestsChangeLog">trunk/JSTests/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCorebytecodeIntrinsicGetterAccessCasecpp">trunk/Source/JavaScriptCore/bytecode/IntrinsicGetterAccessCase.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorebytecodeIntrinsicGetterAccessCaseh">trunk/Source/JavaScriptCore/bytecode/IntrinsicGetterAccessCase.h</a></li>
<li><a href="#trunkSourceJavaScriptCorejitIntrinsicEmittercpp">trunk/Source/JavaScriptCore/jit/IntrinsicEmitter.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorejitRepatchcpp">trunk/Source/JavaScriptCore/jit/Repatch.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkJSTestsstressintrinsicgetterwithpolyprotogetterchangejs">trunk/JSTests/stress/intrinsic-getter-with-poly-proto-getter-change.js</a></li>
<li><a href="#trunkJSTestsstressintrinsicgetterwithpolyprotoprotochangejs">trunk/JSTests/stress/intrinsic-getter-with-poly-proto-proto-change.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkJSTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/JSTests/ChangeLog (225070 => 225071)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/JSTests/ChangeLog  2017-11-21 09:19:17 UTC (rev 225070)
+++ trunk/JSTests/ChangeLog     2017-11-21 10:07:50 UTC (rev 225071)
</span><span class="lines">@@ -1,3 +1,28 @@
</span><ins>+2017-11-21  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        [JSC] Allow poly proto for intrinsic getters
+        https://bugs.webkit.org/show_bug.cgi?id=179550
+
+        Reviewed by Saam Barati.
+
+        This change is also tested by existing tests.
+
+            1. stress/intrinsic-getter-with-poly-proto.js
+            2. stress/poly-proto-intrinsic-getter-correctness.js
+
+        * stress/intrinsic-getter-with-poly-proto-getter-change.js: Added.
+        (shouldBe):
+        (makePolyProtoObject.foo.C):
+        (makePolyProtoObject.foo):
+        (makePolyProtoObject):
+        (target):
+        * stress/intrinsic-getter-with-poly-proto-proto-change.js: Added.
+        (shouldBe):
+        (makePolyProtoObject.foo.C):
+        (makePolyProtoObject.foo):
+        (makePolyProtoObject):
+        (target):
+
</ins><span class="cx"> 2017-11-20  Guillaume Emont  <guijemont@igalia.com>
</span><span class="cx"> 
</span><span class="cx">         Skip stress/unshiftCountSlowCase-correct-postCapacity.js on embedded Linux
</span></span></pre></div>
<a id="trunkJSTestsstressintrinsicgetterwithpolyprotogetterchangejs"></a>
<div class="addfile"><h4>Added: trunk/JSTests/stress/intrinsic-getter-with-poly-proto-getter-change.js (0 => 225071)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/JSTests/stress/intrinsic-getter-with-poly-proto-getter-change.js                           (rev 0)
+++ trunk/JSTests/stress/intrinsic-getter-with-poly-proto-getter-change.js      2017-11-21 10:07:50 UTC (rev 225071)
</span><span class="lines">@@ -0,0 +1,33 @@
</span><ins>+function shouldBe(actual, expected) {
+    if (actual !== expected)
+        throw new Error('bad value: ' + actual);
+}
+
+function makePolyProtoObject() {
+    function foo() {
+        class C {
+            constructor() {
+                this._field = 42;
+            }
+        };
+        return new C;
+    }
+    for (let i = 0; i < 15; ++i)
+        foo();
+    return foo();
+}
+
+function target(object)
+{
+    return object.__proto__;
+}
+noInline(target);
+
+var polyProtoObject = makePolyProtoObject();
+var prototype = Reflect.getPrototypeOf(polyProtoObject);
+for (var i = 0; i < 1e5; ++i)
+    shouldBe(target(polyProtoObject), prototype);
+Object.defineProperty(Object.prototype, "__proto__", {
+    get: function () { return null; }
+});
+shouldBe(target(polyProtoObject), null);
</ins></span></pre></div>
<a id="trunkJSTestsstressintrinsicgetterwithpolyprotoprotochangejs"></a>
<div class="addfile"><h4>Added: trunk/JSTests/stress/intrinsic-getter-with-poly-proto-proto-change.js (0 => 225071)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/JSTests/stress/intrinsic-getter-with-poly-proto-proto-change.js                            (rev 0)
+++ trunk/JSTests/stress/intrinsic-getter-with-poly-proto-proto-change.js       2017-11-21 10:07:50 UTC (rev 225071)
</span><span class="lines">@@ -0,0 +1,32 @@
</span><ins>+function shouldBe(actual, expected) {
+    if (actual !== expected)
+        throw new Error('bad value: ' + actual);
+}
+
+function makePolyProtoObject() {
+    function foo() {
+        class C {
+            constructor() {
+                this._field = 42;
+            }
+        };
+        return new C;
+    }
+    for (let i = 0; i < 15; ++i)
+        foo();
+    return foo();
+}
+
+function target(object)
+{
+    return object.__proto__;
+}
+noInline(target);
+
+var polyProtoObject = makePolyProtoObject();
+var prototype = Reflect.getPrototypeOf(polyProtoObject);
+for (var i = 0; i < 1e5; ++i)
+    shouldBe(target(polyProtoObject), prototype);
+
+polyProtoObject.__proto__ = null
+shouldBe(target(polyProtoObject), undefined)
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (225070 => 225071)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog    2017-11-21 09:19:17 UTC (rev 225070)
+++ trunk/Source/JavaScriptCore/ChangeLog       2017-11-21 10:07:50 UTC (rev 225071)
</span><span class="lines">@@ -1,3 +1,25 @@
</span><ins>+2017-11-21  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        [JSC] Allow poly proto for intrinsic getters
+        https://bugs.webkit.org/show_bug.cgi?id=179550
+
+        Reviewed by Saam Barati.
+
+        This patch allows intrinsic getters to accept poly proto.
+        We propagate PolyProtoAccessChain in IntrinsicGetterAccessCase to perform
+        poly proto checks. And we extend UnderscoreProtoIntrinsic to emit
+        code for poly proto case.
+
+        * bytecode/IntrinsicGetterAccessCase.cpp:
+        (JSC::IntrinsicGetterAccessCase::IntrinsicGetterAccessCase):
+        (JSC::IntrinsicGetterAccessCase::create):
+        * bytecode/IntrinsicGetterAccessCase.h:
+        * jit/IntrinsicEmitter.cpp:
+        (JSC::IntrinsicGetterAccessCase::canEmitIntrinsicGetter):
+        (JSC::IntrinsicGetterAccessCase::emitIntrinsicGetter):
+        * jit/Repatch.cpp:
+        (JSC::tryCacheGetByID):
+
</ins><span class="cx"> 2017-11-20  Don Olmstead  <don.olmstead@sony.com>
</span><span class="cx"> 
</span><span class="cx">         Detect __declspec within JSBase.h
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebytecodeIntrinsicGetterAccessCasecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/bytecode/IntrinsicGetterAccessCase.cpp (225070 => 225071)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/bytecode/IntrinsicGetterAccessCase.cpp       2017-11-21 09:19:17 UTC (rev 225070)
+++ trunk/Source/JavaScriptCore/bytecode/IntrinsicGetterAccessCase.cpp  2017-11-21 10:07:50 UTC (rev 225071)
</span><span class="lines">@@ -32,15 +32,15 @@
</span><span class="cx"> 
</span><span class="cx"> namespace JSC {
</span><span class="cx"> 
</span><del>-IntrinsicGetterAccessCase::IntrinsicGetterAccessCase(VM& vm, JSCell* owner, PropertyOffset offset, Structure* structure, const ObjectPropertyConditionSet& conditionSet, JSFunction* intrinsicFunction)
-    : Base(vm, owner, IntrinsicGetter, offset, structure, conditionSet, nullptr)
</del><ins>+IntrinsicGetterAccessCase::IntrinsicGetterAccessCase(VM& vm, JSCell* owner, PropertyOffset offset, Structure* structure, const ObjectPropertyConditionSet& conditionSet, JSFunction* intrinsicFunction, std::unique_ptr<PolyProtoAccessChain> prototypeAccessChain)
+    : Base(vm, owner, IntrinsicGetter, offset, structure, conditionSet, WTFMove(prototypeAccessChain))
</ins><span class="cx"> {
</span><span class="cx">     m_intrinsicFunction.set(vm, owner, intrinsicFunction);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-std::unique_ptr<AccessCase> IntrinsicGetterAccessCase::create(VM& vm, JSCell* owner, PropertyOffset offset, Structure* structure, const ObjectPropertyConditionSet& conditionSet, JSFunction* intrinsicFunction)
</del><ins>+std::unique_ptr<AccessCase> IntrinsicGetterAccessCase::create(VM& vm, JSCell* owner, PropertyOffset offset, Structure* structure, const ObjectPropertyConditionSet& conditionSet, JSFunction* intrinsicFunction, std::unique_ptr<PolyProtoAccessChain> prototypeAccessChain)
</ins><span class="cx"> {
</span><del>-    return std::unique_ptr<AccessCase>(new IntrinsicGetterAccessCase(vm, owner, offset, structure, conditionSet, intrinsicFunction));
</del><ins>+    return std::unique_ptr<AccessCase>(new IntrinsicGetterAccessCase(vm, owner, offset, structure, conditionSet, intrinsicFunction, WTFMove(prototypeAccessChain)));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> IntrinsicGetterAccessCase::~IntrinsicGetterAccessCase()
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebytecodeIntrinsicGetterAccessCaseh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/bytecode/IntrinsicGetterAccessCase.h (225070 => 225071)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/bytecode/IntrinsicGetterAccessCase.h 2017-11-21 09:19:17 UTC (rev 225070)
+++ trunk/Source/JavaScriptCore/bytecode/IntrinsicGetterAccessCase.h    2017-11-21 10:07:50 UTC (rev 225071)
</span><span class="lines">@@ -42,9 +42,7 @@
</span><span class="cx">     static bool canEmitIntrinsicGetter(JSFunction*, Structure*);
</span><span class="cx">     void emitIntrinsicGetter(AccessGenerationState&);
</span><span class="cx"> 
</span><del>-    // FIXME: Make this work with poly proto:
-    // https://bugs.webkit.org/show_bug.cgi?id=177318
-    static std::unique_ptr<AccessCase> create(VM&, JSCell*, PropertyOffset, Structure*, const ObjectPropertyConditionSet&, JSFunction* intrinsicFunction);
</del><ins>+    static std::unique_ptr<AccessCase> create(VM&, JSCell*, PropertyOffset, Structure*, const ObjectPropertyConditionSet&, JSFunction* intrinsicFunction, std::unique_ptr<PolyProtoAccessChain>);
</ins><span class="cx"> 
</span><span class="cx">     std::unique_ptr<AccessCase> clone() const override;
</span><span class="cx"> 
</span><span class="lines">@@ -51,7 +49,7 @@
</span><span class="cx">     ~IntrinsicGetterAccessCase();
</span><span class="cx"> 
</span><span class="cx"> private:
</span><del>-    IntrinsicGetterAccessCase(VM&, JSCell*, PropertyOffset, Structure*, const ObjectPropertyConditionSet&, JSFunction* intrinsicFunction);
</del><ins>+    IntrinsicGetterAccessCase(VM&, JSCell*, PropertyOffset, Structure*, const ObjectPropertyConditionSet&, JSFunction* intrinsicFunction, std::unique_ptr<PolyProtoAccessChain>);
</ins><span class="cx"> 
</span><span class="cx">     WriteBarrier<JSFunction> m_intrinsicFunction;
</span><span class="cx"> };
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorejitIntrinsicEmittercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/jit/IntrinsicEmitter.cpp (225070 => 225071)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/jit/IntrinsicEmitter.cpp     2017-11-21 09:19:17 UTC (rev 225070)
+++ trunk/Source/JavaScriptCore/jit/IntrinsicEmitter.cpp        2017-11-21 10:07:50 UTC (rev 225071)
</span><span class="lines">@@ -64,8 +64,6 @@
</span><span class="cx">         return true;
</span><span class="cx">     }
</span><span class="cx">     case UnderscoreProtoIntrinsic: {
</span><del>-        if (structure->hasPolyProto())
-            return false;
</del><span class="cx">         auto getPrototypeMethod = structure->classInfo()->methodTable.getPrototype;
</span><span class="cx">         MethodTable::GetPrototypeFunctionPtr defaultGetPrototype = JSObject::getPrototype;
</span><span class="cx">         return getPrototypeMethod == defaultGetPrototype;
</span><span class="lines">@@ -133,8 +131,10 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     case UnderscoreProtoIntrinsic: {
</span><del>-        ASSERT(structure()->hasMonoProto());
-        jit.moveValue(structure()->storedPrototype(), valueRegs);
</del><ins>+        if (structure()->hasPolyProto())
+            jit.loadValue(CCallHelpers::Address(baseGPR, offsetRelativeToBase(knownPolyProtoOffset)), valueRegs);
+        else
+            jit.moveValue(structure()->storedPrototype(), valueRegs);
</ins><span class="cx">         state.succeed();
</span><span class="cx">         return;
</span><span class="cx">     }
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorejitRepatchcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/jit/Repatch.cpp (225070 => 225071)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/jit/Repatch.cpp      2017-11-21 09:19:17 UTC (rev 225070)
+++ trunk/Source/JavaScriptCore/jit/Repatch.cpp 2017-11-21 10:07:50 UTC (rev 225071)
</span><span class="lines">@@ -321,13 +321,9 @@
</span><span class="cx">                     RELEASE_ASSERT_NOT_REACHED();
</span><span class="cx"> 
</span><span class="cx">                 newCase = ProxyableAccessCase::create(vm, codeBlock, type, offset, structure, conditionSet, loadTargetFromProxy, slot.watchpointSet(), WTFMove(prototypeAccessChain));
</span><del>-            } else if (!loadTargetFromProxy && getter && IntrinsicGetterAccessCase::canEmitIntrinsicGetter(getter, structure) && !prototypeAccessChain) {
-                // FIXME: We should make this work with poly proto, but for our own sanity, we probably
-                // want to do a pointer check on the actual getter. A good time to make this work would
-                // be when we can inherit from builtin types in poly proto fashion:
-                // https://bugs.webkit.org/show_bug.cgi?id=177318
-                newCase = IntrinsicGetterAccessCase::create(vm, codeBlock, slot.cachedOffset(), structure, conditionSet, getter);
-            } else {
</del><ins>+            } else if (!loadTargetFromProxy && getter && IntrinsicGetterAccessCase::canEmitIntrinsicGetter(getter, structure))
+                newCase = IntrinsicGetterAccessCase::create(vm, codeBlock, slot.cachedOffset(), structure, conditionSet, getter, WTFMove(prototypeAccessChain));
+            else {
</ins><span class="cx">                 if (slot.isCacheableValue() || slot.isUnset()) {
</span><span class="cx">                     newCase = ProxyableAccessCase::create(vm, codeBlock, slot.isUnset() ? AccessCase::Miss : AccessCase::Load,
</span><span class="cx">                         offset, structure, conditionSet, loadTargetFromProxy, slot.watchpointSet(), WTFMove(prototypeAccessChain));
</span></span></pre>
</div>
</div>

</body>
</html>