<!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>[185597] 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/185597">185597</a></dd>
<dt>Author</dt> <dd>akling@apple.com</dd>
<dt>Date</dt> <dd>2015-06-16 11:38:04 -0700 (Tue, 16 Jun 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>[JSC] Pre-bake final Structure for RegExp matches arrays.
&lt;https://webkit.org/b/146006&gt;

Reviewed by Darin Adler.

Since we always add the &quot;index&quot; and &quot;input&quot; fields to RegExp matches arrays,
cache a finished structure on the global object so we can create these arrays without
starting from scratch with a bare array every time.

10% progression on Octane/regexp (on my MBP.)

* runtime/JSArray.h:
(JSC::JSArray::create):
(JSC::JSArray::tryCreateUninitialized):
(JSC::JSArray::createWithButterfly): Factored out JSArray construction into a helper
so we can call this from RegExpMatchesArray.cpp.

* runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::init):
(JSC::JSGlobalObject::visitChildren):
* runtime/JSGlobalObject.h:
(JSC::JSGlobalObject::regExpMatchesArrayStructure): Add a cached Structure for RegExp
subpattern matches arrays.

* runtime/JSObject.h:
(JSC::JSNonFinalObject::finishCreation): Tweak assertion that used to check that
JSNonFinalObjects always start out with zero capacity. Since RegExp matches arrays now
start out with capacity for 2 properties, that won't work. Change it to check that we
don't have inline storage instead, since that should only be used by final objects.

* runtime/RegExpMatchesArray.h:
* runtime/RegExpMatchesArray.cpp:
(JSC::tryCreateUninitializedRegExpMatchesArray): Helper to construct a JSArray with
the cached Structure and a Butterfly with 2 slots of property storage.

(JSC::createRegExpMatchesArray):
(JSC::createRegExpMatchesArrayStructure): Creates the array Structure that gets cached
by the JSGlobalObject.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSArrayh">trunk/Source/JavaScriptCore/runtime/JSArray.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSGlobalObjectcpp">trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSGlobalObjecth">trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSObjecth">trunk/Source/JavaScriptCore/runtime/JSObject.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeRegExpMatchesArraycpp">trunk/Source/JavaScriptCore/runtime/RegExpMatchesArray.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeRegExpMatchesArrayh">trunk/Source/JavaScriptCore/runtime/RegExpMatchesArray.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (185596 => 185597)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2015-06-16 18:34:24 UTC (rev 185596)
+++ trunk/Source/JavaScriptCore/ChangeLog        2015-06-16 18:38:04 UTC (rev 185597)
</span><span class="lines">@@ -1,3 +1,44 @@
</span><ins>+2015-06-16  Andreas Kling  &lt;akling@apple.com&gt;
+
+        [JSC] Pre-bake final Structure for RegExp matches arrays.
+        &lt;https://webkit.org/b/146006&gt;
+
+        Reviewed by Darin Adler.
+
+        Since we always add the &quot;index&quot; and &quot;input&quot; fields to RegExp matches arrays,
+        cache a finished structure on the global object so we can create these arrays without
+        starting from scratch with a bare array every time.
+
+        10% progression on Octane/regexp (on my MBP.)
+
+        * runtime/JSArray.h:
+        (JSC::JSArray::create):
+        (JSC::JSArray::tryCreateUninitialized):
+        (JSC::JSArray::createWithButterfly): Factored out JSArray construction into a helper
+        so we can call this from RegExpMatchesArray.cpp.
+
+        * runtime/JSGlobalObject.cpp:
+        (JSC::JSGlobalObject::init):
+        (JSC::JSGlobalObject::visitChildren):
+        * runtime/JSGlobalObject.h:
+        (JSC::JSGlobalObject::regExpMatchesArrayStructure): Add a cached Structure for RegExp
+        subpattern matches arrays.
+
+        * runtime/JSObject.h:
+        (JSC::JSNonFinalObject::finishCreation): Tweak assertion that used to check that
+        JSNonFinalObjects always start out with zero capacity. Since RegExp matches arrays now
+        start out with capacity for 2 properties, that won't work. Change it to check that we
+        don't have inline storage instead, since that should only be used by final objects.
+
+        * runtime/RegExpMatchesArray.h:
+        * runtime/RegExpMatchesArray.cpp:
+        (JSC::tryCreateUninitializedRegExpMatchesArray): Helper to construct a JSArray with
+        the cached Structure and a Butterfly with 2 slots of property storage.
+
+        (JSC::createRegExpMatchesArray):
+        (JSC::createRegExpMatchesArrayStructure): Creates the array Structure that gets cached
+        by the JSGlobalObject.
+
</ins><span class="cx"> 2015-06-16  Saam Barati  &lt;saambarati1@gmail.com&gt;
</span><span class="cx"> 
</span><span class="cx">         LLInt's code path for get_from_scope with case GlobalVarWithVarInjectionChecks has dead code
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSArrayh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSArray.h (185596 => 185597)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSArray.h        2015-06-16 18:34:24 UTC (rev 185596)
+++ trunk/Source/JavaScriptCore/runtime/JSArray.h        2015-06-16 18:38:04 UTC (rev 185597)
</span><span class="lines">@@ -53,6 +53,7 @@
</span><span class="cx"> 
</span><span class="cx"> public:
</span><span class="cx">     static JSArray* create(VM&amp;, Structure*, unsigned initialLength = 0);
</span><ins>+    static JSArray* createWithButterfly(VM&amp;, Structure*, Butterfly*);
</ins><span class="cx"> 
</span><span class="cx">     // tryCreateUninitialized is used for fast construction of arrays whose size and
</span><span class="cx">     // contents are known at time of creation. Clients of this interface must:
</span><span class="lines">@@ -213,9 +214,8 @@
</span><span class="cx">             || structure-&gt;indexingType() == ArrayWithArrayStorage);
</span><span class="cx">         butterfly = createArrayButterfly(vm, 0, initialLength);
</span><span class="cx">     }
</span><del>-    JSArray* array = new (NotNull, allocateCell&lt;JSArray&gt;(vm.heap)) JSArray(vm, structure, butterfly);
-    array-&gt;finishCreation(vm);
-    return array;
</del><ins>+
+    return createWithButterfly(vm, structure, butterfly);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> inline JSArray* JSArray::tryCreateUninitialized(VM&amp; vm, Structure* structure, unsigned initialLength)
</span><span class="lines">@@ -253,7 +253,12 @@
</span><span class="cx">         storage-&gt;m_sparseMap.clear();
</span><span class="cx">         storage-&gt;m_numValuesInVector = initialLength;
</span><span class="cx">     }
</span><del>-        
</del><ins>+
+    return createWithButterfly(vm, structure, butterfly);
+}
+
+inline JSArray* JSArray::createWithButterfly(VM&amp; vm, Structure* structure, Butterfly* butterfly)
+{
</ins><span class="cx">     JSArray* array = new (NotNull, allocateCell&lt;JSArray&gt;(vm.heap)) JSArray(vm, structure, butterfly);
</span><span class="cx">     array-&gt;finishCreation(vm);
</span><span class="cx">     return array;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSGlobalObjectcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp (185596 => 185597)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp        2015-06-16 18:34:24 UTC (rev 185596)
+++ trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp        2015-06-16 18:38:04 UTC (rev 185597)
</span><span class="lines">@@ -316,6 +316,7 @@
</span><span class="cx">     
</span><span class="cx">     m_regExpPrototype.set(vm, this, RegExpPrototype::create(vm, RegExpPrototype::createStructure(vm, this, m_objectPrototype.get()), emptyRegex));
</span><span class="cx">     m_regExpStructure.set(vm, this, RegExpObject::createStructure(vm, this, m_regExpPrototype.get()));
</span><ins>+    m_regExpMatchesArrayStructure.set(vm, this, createRegExpMatchesArrayStructure(vm, *this));
</ins><span class="cx">     
</span><span class="cx"> #if ENABLE(PROMISES)
</span><span class="cx">     m_promisePrototype.set(vm, this, JSPromisePrototype::create(exec, this, JSPromisePrototype::createStructure(vm, this, m_objectPrototype.get())));
</span><span class="lines">@@ -778,6 +779,7 @@
</span><span class="cx">     visitor.append(&amp;thisObject-&gt;m_namedFunctionStructure);
</span><span class="cx">     visitor.append(&amp;thisObject-&gt;m_symbolObjectStructure);
</span><span class="cx">     visitor.append(&amp;thisObject-&gt;m_regExpStructure);
</span><ins>+    visitor.append(&amp;thisObject-&gt;m_regExpMatchesArrayStructure);
</ins><span class="cx">     visitor.append(&amp;thisObject-&gt;m_consoleStructure);
</span><span class="cx">     visitor.append(&amp;thisObject-&gt;m_dollarVMStructure);
</span><span class="cx">     visitor.append(&amp;thisObject-&gt;m_internalFunctionStructure);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSGlobalObjecth"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h (185596 => 185597)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h        2015-06-16 18:34:24 UTC (rev 185596)
+++ trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h        2015-06-16 18:38:04 UTC (rev 185597)
</span><span class="lines">@@ -248,6 +248,8 @@
</span><span class="cx">     
</span><span class="cx">     WriteBarrier&lt;Structure&gt; m_iteratorResultStructure;
</span><span class="cx"> 
</span><ins>+    WriteBarrier&lt;Structure&gt; m_regExpMatchesArrayStructure;
+
</ins><span class="cx"> #if ENABLE(PROMISES)
</span><span class="cx">     WriteBarrier&lt;Structure&gt; m_promiseStructure;
</span><span class="cx"> #endif // ENABLE(PROMISES)
</span><span class="lines">@@ -488,6 +490,7 @@
</span><span class="cx">     Structure* symbolObjectStructure() const { return m_symbolObjectStructure.get(); }
</span><span class="cx">     Structure* iteratorResultStructure() const { return m_iteratorResultStructure.get(); }
</span><span class="cx">     static ptrdiff_t iteratorResultStructureOffset() { return OBJECT_OFFSETOF(JSGlobalObject, m_iteratorResultStructure); }
</span><ins>+    Structure* regExpMatchesArrayStructure() const { return m_regExpMatchesArrayStructure.get(); }
</ins><span class="cx"> 
</span><span class="cx"> #if ENABLE(PROMISES)
</span><span class="cx">     Structure* promiseStructure() const { return m_promiseStructure.get(); }
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSObjecth"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSObject.h (185596 => 185597)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSObject.h        2015-06-16 18:34:24 UTC (rev 185596)
+++ trunk/Source/JavaScriptCore/runtime/JSObject.h        2015-06-16 18:38:04 UTC (rev 185597)
</span><span class="lines">@@ -1011,7 +1011,7 @@
</span><span class="cx">     void finishCreation(VM&amp; vm)
</span><span class="cx">     {
</span><span class="cx">         Base::finishCreation(vm);
</span><del>-        ASSERT(!this-&gt;structure()-&gt;totalStorageCapacity());
</del><ins>+        ASSERT(!this-&gt;structure()-&gt;hasInlineStorage());
</ins><span class="cx">         ASSERT(classInfo());
</span><span class="cx">     }
</span><span class="cx"> };
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeRegExpMatchesArraycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/RegExpMatchesArray.cpp (185596 => 185597)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/RegExpMatchesArray.cpp        2015-06-16 18:34:24 UTC (rev 185596)
+++ trunk/Source/JavaScriptCore/runtime/RegExpMatchesArray.cpp        2015-06-16 18:38:04 UTC (rev 185597)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2012-2014 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2012-2015 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">@@ -31,11 +31,30 @@
</span><span class="cx"> 
</span><span class="cx"> namespace JSC {
</span><span class="cx"> 
</span><ins>+static const PropertyOffset indexPropertyOffset = 100;
+static const PropertyOffset inputPropertyOffset = 101;
+
+static JSArray* tryCreateUninitializedRegExpMatchesArray(VM&amp; vm, Structure* structure, unsigned initialLength)
+{
+    unsigned vectorLength = std::max(BASE_VECTOR_LEN, initialLength);
+    if (vectorLength &gt; MAX_STORAGE_VECTOR_LENGTH)
+        return 0;
+
+    void* temp;
+    if (!vm.heap.tryAllocateStorage(0, Butterfly::totalSize(0, structure-&gt;outOfLineCapacity(), true, vectorLength * sizeof(EncodedJSValue)), &amp;temp))
+        return 0;
+    Butterfly* butterfly = Butterfly::fromBase(temp, 0, structure-&gt;outOfLineCapacity());
+    butterfly-&gt;setVectorLength(vectorLength);
+    butterfly-&gt;setPublicLength(initialLength);
+
+    return JSArray::createWithButterfly(vm, structure, butterfly);
+}
+
</ins><span class="cx"> JSArray* createRegExpMatchesArray(ExecState* exec, JSString* input, RegExp* regExp, MatchResult result)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(result);
</span><span class="cx">     VM&amp; vm = exec-&gt;vm();
</span><del>-    JSArray* array = JSArray::tryCreateUninitialized(vm, exec-&gt;lexicalGlobalObject()-&gt;arrayStructureForIndexingTypeDuringAllocation(ArrayWithContiguous), regExp-&gt;numSubpatterns() + 1);
</del><ins>+    JSArray* array = tryCreateUninitializedRegExpMatchesArray(vm, exec-&gt;lexicalGlobalObject()-&gt;regExpMatchesArrayStructure(), regExp-&gt;numSubpatterns() + 1);
</ins><span class="cx">     RELEASE_ASSERT(array);
</span><span class="cx"> 
</span><span class="cx">     SamplingRegion samplingRegion(&quot;Reifying substring properties&quot;);
</span><span class="lines">@@ -58,10 +77,21 @@
</span><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    array-&gt;putDirect(vm, vm.propertyNames-&gt;index, jsNumber(result.start));
-    array-&gt;putDirect(vm, vm.propertyNames-&gt;input, input);
</del><ins>+    array-&gt;putDirect(vm, indexPropertyOffset, jsNumber(result.start));
+    array-&gt;putDirect(vm, inputPropertyOffset, input);
</ins><span class="cx"> 
</span><span class="cx">     return array;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+Structure* createRegExpMatchesArrayStructure(VM&amp; vm, JSGlobalObject&amp; globalObject)
+{
+    Structure* structure = globalObject.arrayStructureForIndexingTypeDuringAllocation(ArrayWithContiguous);
+    PropertyOffset offset;
+    structure = structure-&gt;addPropertyTransition(vm, structure, vm.propertyNames-&gt;index, 0, offset);
+    ASSERT(offset == indexPropertyOffset);
+    structure = structure-&gt;addPropertyTransition(vm, structure, vm.propertyNames-&gt;input, 0, offset);
+    ASSERT(offset == inputPropertyOffset);
+    return structure;
+}
+
</ins><span class="cx"> } // namespace JSC
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeRegExpMatchesArrayh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/RegExpMatchesArray.h (185596 => 185597)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/RegExpMatchesArray.h        2015-06-16 18:34:24 UTC (rev 185596)
+++ trunk/Source/JavaScriptCore/runtime/RegExpMatchesArray.h        2015-06-16 18:38:04 UTC (rev 185597)
</span><span class="lines">@@ -27,6 +27,7 @@
</span><span class="cx"> namespace JSC {
</span><span class="cx"> 
</span><span class="cx"> JSArray* createRegExpMatchesArray(ExecState*, JSString*, RegExp*, MatchResult);
</span><ins>+Structure* createRegExpMatchesArrayStructure(VM&amp;, JSGlobalObject&amp;);
</ins><span class="cx"> 
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>