<!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>[168635] branches/ftlopt</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/168635">168635</a></dd>
<dt>Author</dt> <dd>fpizlo@apple.com</dd>
<dt>Date</dt> <dd>2014-05-12 12:23:47 -0700 (Mon, 12 May 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>jsSubstring() should be lazy
https://bugs.webkit.org/show_bug.cgi?id=132556
Reviewed by Andreas Kling.
Source/JavaScriptCore:
jsSubstring() is now lazy by using a special rope that is a substring instead of a
concatenation. To make this patch super simple, we require that a substring's base is
never a rope. Hence, when resolving a rope, we either go down a non-recursive substring
path, or we go down a concatenation path which may see exactly one level of substrings in
its fibers.
This is up to a 50% speed-up on microbenchmarks and a 10% speed-up on Octane/regexp.
Relanding this with assertion fixes.
* heap/MarkedBlock.cpp:
(JSC::MarkedBlock::specializedSweep):
* runtime/JSString.cpp:
(JSC::JSRopeString::visitFibers):
(JSC::JSRopeString::resolveRopeInternal8):
(JSC::JSRopeString::resolveRopeInternal16):
(JSC::JSRopeString::clearFibers):
(JSC::JSRopeString::resolveRope):
(JSC::JSRopeString::resolveRopeSlowCase8):
(JSC::JSRopeString::resolveRopeSlowCase):
* runtime/JSString.h:
(JSC::JSRopeString::finishCreation):
(JSC::JSRopeString::append):
(JSC::JSRopeString::create):
(JSC::JSRopeString::offsetOfFibers):
(JSC::JSRopeString::fiber):
(JSC::JSRopeString::substringBase):
(JSC::JSRopeString::substringOffset):
(JSC::JSRopeString::notSubstringSentinel):
(JSC::JSRopeString::substringSentinel):
(JSC::JSRopeString::isSubstring):
(JSC::JSRopeString::setIsSubstring):
(JSC::jsSubstring):
* runtime/RegExpMatchesArray.cpp:
(JSC::RegExpMatchesArray::reifyAllProperties):
* runtime/StringPrototype.cpp:
(JSC::stringProtoFuncSubstring):
LayoutTests:
These tests get 35-50% faster.
* js/regress/script-tests/substring-concat-weird.js: Added.
(foo):
* js/regress/script-tests/substring-concat.js: Added.
(foo):
* js/regress/script-tests/substring.js: Added.
(foo):
* js/regress/substring-concat-expected.txt: Added.
* js/regress/substring-concat-weird-expected.txt: Added.
* js/regress/substring-concat-weird.html: Added.
* js/regress/substring-concat.html: Added.
* js/regress/substring-expected.txt: Added.
* js/regress/substring.html: Added.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#branchesftloptLayoutTestsChangeLog">branches/ftlopt/LayoutTests/ChangeLog</a></li>
<li><a href="#branchesftloptSourceJavaScriptCoreChangeLog">branches/ftlopt/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#branchesftloptSourceJavaScriptCoreheapMarkedBlockcpp">branches/ftlopt/Source/JavaScriptCore/heap/MarkedBlock.cpp</a></li>
<li><a href="#branchesftloptSourceJavaScriptCoreruntimeJSStringcpp">branches/ftlopt/Source/JavaScriptCore/runtime/JSString.cpp</a></li>
<li><a href="#branchesftloptSourceJavaScriptCoreruntimeJSStringh">branches/ftlopt/Source/JavaScriptCore/runtime/JSString.h</a></li>
<li><a href="#branchesftloptSourceJavaScriptCoreruntimeRegExpMatchesArraycpp">branches/ftlopt/Source/JavaScriptCore/runtime/RegExpMatchesArray.cpp</a></li>
<li><a href="#branchesftloptSourceJavaScriptCoreruntimeStringPrototypecpp">branches/ftlopt/Source/JavaScriptCore/runtime/StringPrototype.cpp</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#branchesftloptLayoutTestsjsregressscripttestssubstringconcatweirdjs">branches/ftlopt/LayoutTests/js/regress/script-tests/substring-concat-weird.js</a></li>
<li><a href="#branchesftloptLayoutTestsjsregressscripttestssubstringconcatjs">branches/ftlopt/LayoutTests/js/regress/script-tests/substring-concat.js</a></li>
<li><a href="#branchesftloptLayoutTestsjsregressscripttestssubstringjs">branches/ftlopt/LayoutTests/js/regress/script-tests/substring.js</a></li>
<li><a href="#branchesftloptLayoutTestsjsregresssubstringconcatexpectedtxt">branches/ftlopt/LayoutTests/js/regress/substring-concat-expected.txt</a></li>
<li><a href="#branchesftloptLayoutTestsjsregresssubstringconcatweirdexpectedtxt">branches/ftlopt/LayoutTests/js/regress/substring-concat-weird-expected.txt</a></li>
<li><a href="#branchesftloptLayoutTestsjsregresssubstringconcatweirdhtml">branches/ftlopt/LayoutTests/js/regress/substring-concat-weird.html</a></li>
<li><a href="#branchesftloptLayoutTestsjsregresssubstringconcathtml">branches/ftlopt/LayoutTests/js/regress/substring-concat.html</a></li>
<li><a href="#branchesftloptLayoutTestsjsregresssubstringexpectedtxt">branches/ftlopt/LayoutTests/js/regress/substring-expected.txt</a></li>
<li><a href="#branchesftloptLayoutTestsjsregresssubstringhtml">branches/ftlopt/LayoutTests/js/regress/substring.html</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchesftloptLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: branches/ftlopt/LayoutTests/ChangeLog (168634 => 168635)</h4>
<pre class="diff"><span>
<span class="info">--- branches/ftlopt/LayoutTests/ChangeLog        2014-05-12 19:20:21 UTC (rev 168634)
+++ branches/ftlopt/LayoutTests/ChangeLog        2014-05-12 19:23:47 UTC (rev 168635)
</span><span class="lines">@@ -1,3 +1,25 @@
</span><ins>+2014-05-08 Filip Pizlo <fpizlo@apple.com>
+
+ jsSubstring() should be lazy
+ https://bugs.webkit.org/show_bug.cgi?id=132556
+
+ Reviewed by Andreas Kling.
+
+ These tests get 35-50% faster.
+
+ * js/regress/script-tests/substring-concat-weird.js: Added.
+ (foo):
+ * js/regress/script-tests/substring-concat.js: Added.
+ (foo):
+ * js/regress/script-tests/substring.js: Added.
+ (foo):
+ * js/regress/substring-concat-expected.txt: Added.
+ * js/regress/substring-concat-weird-expected.txt: Added.
+ * js/regress/substring-concat-weird.html: Added.
+ * js/regress/substring-concat.html: Added.
+ * js/regress/substring-expected.txt: Added.
+ * js/regress/substring.html: Added.
+
</ins><span class="cx"> 2014-05-08 Commit Queue <commit-queue@webkit.org>
</span><span class="cx">
</span><span class="cx"> Unreviewed, rolling out r168498.
</span></span></pre></div>
<a id="branchesftloptLayoutTestsjsregressscripttestssubstringconcatweirdjs"></a>
<div class="addfile"><h4>Added: branches/ftlopt/LayoutTests/js/regress/script-tests/substring-concat-weird.js (0 => 168635)</h4>
<pre class="diff"><span>
<span class="info">--- branches/ftlopt/LayoutTests/js/regress/script-tests/substring-concat-weird.js         (rev 0)
+++ branches/ftlopt/LayoutTests/js/regress/script-tests/substring-concat-weird.js        2014-05-12 19:23:47 UTC (rev 168635)
</span><span class="lines">@@ -0,0 +1,18 @@
</span><ins>+function foo() {
+ return a + b;
+}
+
+var array = Array(10007);
+
+var string = foo.toString();
+
+for (var i = 0; i < 500000; ++i) {
+ array[i % array.length] = "foo " + string.substring(i % string.length, (i / string.length) % string.length) + " bar";
+ array[i % array.length] = "this " + array[i % array.length] + " that";
+}
+
+for (var i = 0; i < array.length; ++i) {
+ var thing = array[i].substring(9, array[i].length - 9);
+ if (string.indexOf(thing) < 0)
+ throw "Error: bad substring: " + thing;
+}
</ins></span></pre></div>
<a id="branchesftloptLayoutTestsjsregressscripttestssubstringconcatjs"></a>
<div class="addfile"><h4>Added: branches/ftlopt/LayoutTests/js/regress/script-tests/substring-concat.js (0 => 168635)</h4>
<pre class="diff"><span>
<span class="info">--- branches/ftlopt/LayoutTests/js/regress/script-tests/substring-concat.js         (rev 0)
+++ branches/ftlopt/LayoutTests/js/regress/script-tests/substring-concat.js        2014-05-12 19:23:47 UTC (rev 168635)
</span><span class="lines">@@ -0,0 +1,17 @@
</span><ins>+function foo() {
+ return a + b;
+}
+
+var array = Array(10007);
+
+var string = foo.toString();
+
+for (var i = 0; i < 700000; ++i) {
+ array[i % array.length] = "foo " + string.substring(i % string.length, (i / string.length) % string.length) + " bar";
+}
+
+for (var i = 0; i < array.length; ++i) {
+ var thing = array[i].substring(4, array[i].length - 4);
+ if (string.indexOf(thing) < 0)
+ throw "Error: bad substring: \"" + thing + "\"";
+}
</ins></span></pre></div>
<a id="branchesftloptLayoutTestsjsregressscripttestssubstringjs"></a>
<div class="addfile"><h4>Added: branches/ftlopt/LayoutTests/js/regress/script-tests/substring.js (0 => 168635)</h4>
<pre class="diff"><span>
<span class="info">--- branches/ftlopt/LayoutTests/js/regress/script-tests/substring.js         (rev 0)
+++ branches/ftlopt/LayoutTests/js/regress/script-tests/substring.js        2014-05-12 19:23:47 UTC (rev 168635)
</span><span class="lines">@@ -0,0 +1,16 @@
</span><ins>+function foo() {
+ return a + b;
+}
+
+var array = Array(10007);
+
+var string = foo.toString();
+
+for (var i = 0; i < 1000000; ++i) {
+ array[i % array.length] = string.substring(i % string.length, (i / string.length) % string.length);
+}
+
+for (var i = 0; i < array.length; ++i) {
+ if (string.indexOf(array[i]) < 0)
+ throw "Error: bad substring: " + array[i];
+}
</ins></span></pre></div>
<a id="branchesftloptLayoutTestsjsregresssubstringconcatexpectedtxt"></a>
<div class="addfile"><h4>Added: branches/ftlopt/LayoutTests/js/regress/substring-concat-expected.txt (0 => 168635)</h4>
<pre class="diff"><span>
<span class="info">--- branches/ftlopt/LayoutTests/js/regress/substring-concat-expected.txt         (rev 0)
+++ branches/ftlopt/LayoutTests/js/regress/substring-concat-expected.txt        2014-05-12 19:23:47 UTC (rev 168635)
</span><span class="lines">@@ -0,0 +1,10 @@
</span><ins>+JSRegress/substring-concat
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS no exception thrown
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="branchesftloptLayoutTestsjsregresssubstringconcatweirdexpectedtxt"></a>
<div class="addfile"><h4>Added: branches/ftlopt/LayoutTests/js/regress/substring-concat-weird-expected.txt (0 => 168635)</h4>
<pre class="diff"><span>
<span class="info">--- branches/ftlopt/LayoutTests/js/regress/substring-concat-weird-expected.txt         (rev 0)
+++ branches/ftlopt/LayoutTests/js/regress/substring-concat-weird-expected.txt        2014-05-12 19:23:47 UTC (rev 168635)
</span><span class="lines">@@ -0,0 +1,10 @@
</span><ins>+JSRegress/substring-concat-weird
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS no exception thrown
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="branchesftloptLayoutTestsjsregresssubstringconcatweirdhtml"></a>
<div class="addfile"><h4>Added: branches/ftlopt/LayoutTests/js/regress/substring-concat-weird.html (0 => 168635)</h4>
<pre class="diff"><span>
<span class="info">--- branches/ftlopt/LayoutTests/js/regress/substring-concat-weird.html         (rev 0)
+++ branches/ftlopt/LayoutTests/js/regress/substring-concat-weird.html        2014-05-12 19:23:47 UTC (rev 168635)
</span><span class="lines">@@ -0,0 +1,12 @@
</span><ins>+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+</head>
+<body>
+<script src="../../resources/regress-pre.js"></script>
+<script src="script-tests/substring-concat-weird.js"></script>
+<script src="../../resources/regress-post.js"></script>
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
</ins></span></pre></div>
<a id="branchesftloptLayoutTestsjsregresssubstringconcathtml"></a>
<div class="addfile"><h4>Added: branches/ftlopt/LayoutTests/js/regress/substring-concat.html (0 => 168635)</h4>
<pre class="diff"><span>
<span class="info">--- branches/ftlopt/LayoutTests/js/regress/substring-concat.html         (rev 0)
+++ branches/ftlopt/LayoutTests/js/regress/substring-concat.html        2014-05-12 19:23:47 UTC (rev 168635)
</span><span class="lines">@@ -0,0 +1,12 @@
</span><ins>+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+</head>
+<body>
+<script src="../../resources/regress-pre.js"></script>
+<script src="script-tests/substring-concat.js"></script>
+<script src="../../resources/regress-post.js"></script>
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
</ins></span></pre></div>
<a id="branchesftloptLayoutTestsjsregresssubstringexpectedtxt"></a>
<div class="addfile"><h4>Added: branches/ftlopt/LayoutTests/js/regress/substring-expected.txt (0 => 168635)</h4>
<pre class="diff"><span>
<span class="info">--- branches/ftlopt/LayoutTests/js/regress/substring-expected.txt         (rev 0)
+++ branches/ftlopt/LayoutTests/js/regress/substring-expected.txt        2014-05-12 19:23:47 UTC (rev 168635)
</span><span class="lines">@@ -0,0 +1,10 @@
</span><ins>+JSRegress/substring
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS no exception thrown
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="branchesftloptLayoutTestsjsregresssubstringhtml"></a>
<div class="addfile"><h4>Added: branches/ftlopt/LayoutTests/js/regress/substring.html (0 => 168635)</h4>
<pre class="diff"><span>
<span class="info">--- branches/ftlopt/LayoutTests/js/regress/substring.html         (rev 0)
+++ branches/ftlopt/LayoutTests/js/regress/substring.html        2014-05-12 19:23:47 UTC (rev 168635)
</span><span class="lines">@@ -0,0 +1,12 @@
</span><ins>+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+</head>
+<body>
+<script src="../../resources/regress-pre.js"></script>
+<script src="script-tests/substring.js"></script>
+<script src="../../resources/regress-post.js"></script>
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
</ins></span></pre></div>
<a id="branchesftloptSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/ftlopt/Source/JavaScriptCore/ChangeLog (168634 => 168635)</h4>
<pre class="diff"><span>
<span class="info">--- branches/ftlopt/Source/JavaScriptCore/ChangeLog        2014-05-12 19:20:21 UTC (rev 168634)
+++ branches/ftlopt/Source/JavaScriptCore/ChangeLog        2014-05-12 19:23:47 UTC (rev 168635)
</span><span class="lines">@@ -1,3 +1,48 @@
</span><ins>+2014-05-08 Filip Pizlo <fpizlo@apple.com>
+
+ jsSubstring() should be lazy
+ https://bugs.webkit.org/show_bug.cgi?id=132556
+
+ Reviewed by Andreas Kling.
+
+ jsSubstring() is now lazy by using a special rope that is a substring instead of a
+ concatenation. To make this patch super simple, we require that a substring's base is
+ never a rope. Hence, when resolving a rope, we either go down a non-recursive substring
+ path, or we go down a concatenation path which may see exactly one level of substrings in
+ its fibers.
+
+ This is up to a 50% speed-up on microbenchmarks and a 10% speed-up on Octane/regexp.
+
+ Relanding this with assertion fixes.
+
+ * heap/MarkedBlock.cpp:
+ (JSC::MarkedBlock::specializedSweep):
+ * runtime/JSString.cpp:
+ (JSC::JSRopeString::visitFibers):
+ (JSC::JSRopeString::resolveRopeInternal8):
+ (JSC::JSRopeString::resolveRopeInternal16):
+ (JSC::JSRopeString::clearFibers):
+ (JSC::JSRopeString::resolveRope):
+ (JSC::JSRopeString::resolveRopeSlowCase8):
+ (JSC::JSRopeString::resolveRopeSlowCase):
+ * runtime/JSString.h:
+ (JSC::JSRopeString::finishCreation):
+ (JSC::JSRopeString::append):
+ (JSC::JSRopeString::create):
+ (JSC::JSRopeString::offsetOfFibers):
+ (JSC::JSRopeString::fiber):
+ (JSC::JSRopeString::substringBase):
+ (JSC::JSRopeString::substringOffset):
+ (JSC::JSRopeString::notSubstringSentinel):
+ (JSC::JSRopeString::substringSentinel):
+ (JSC::JSRopeString::isSubstring):
+ (JSC::JSRopeString::setIsSubstring):
+ (JSC::jsSubstring):
+ * runtime/RegExpMatchesArray.cpp:
+ (JSC::RegExpMatchesArray::reifyAllProperties):
+ * runtime/StringPrototype.cpp:
+ (JSC::stringProtoFuncSubstring):
+
</ins><span class="cx"> 2014-05-08 Mark Hahnenberg <mhahnenberg@apple.com>
</span><span class="cx">
</span><span class="cx"> Base case for get-by-id inline cache doesn't check for HasImpureGetOwnPropertySlot
</span></span></pre></div>
<a id="branchesftloptSourceJavaScriptCoreheapMarkedBlockcpp"></a>
<div class="modfile"><h4>Modified: branches/ftlopt/Source/JavaScriptCore/heap/MarkedBlock.cpp (168634 => 168635)</h4>
<pre class="diff"><span>
<span class="info">--- branches/ftlopt/Source/JavaScriptCore/heap/MarkedBlock.cpp        2014-05-12 19:20:21 UTC (rev 168634)
+++ branches/ftlopt/Source/JavaScriptCore/heap/MarkedBlock.cpp        2014-05-12 19:23:47 UTC (rev 168635)
</span><span class="lines">@@ -70,6 +70,8 @@
</span><span class="cx"> ASSERT(blockState != Allocated && blockState != FreeListed);
</span><span class="cx"> ASSERT(!(dtorType == MarkedBlock::None && sweepMode == SweepOnly));
</span><span class="cx">
</span><ins>+ SamplingRegion samplingRegion((dtorType != MarkedBlock::None && blockState != New) ? "Calling destructors" : "sweeping");
+
</ins><span class="cx"> // This produces a free list that is ordered in reverse through the block.
</span><span class="cx"> // This is fine, since the allocation code makes no assumptions about the
</span><span class="cx"> // order of the free list.
</span></span></pre></div>
<a id="branchesftloptSourceJavaScriptCoreruntimeJSStringcpp"></a>
<div class="modfile"><h4>Modified: branches/ftlopt/Source/JavaScriptCore/runtime/JSString.cpp (168634 => 168635)</h4>
<pre class="diff"><span>
<span class="info">--- branches/ftlopt/Source/JavaScriptCore/runtime/JSString.cpp        2014-05-12 19:20:21 UTC (rev 168634)
+++ branches/ftlopt/Source/JavaScriptCore/runtime/JSString.cpp        2014-05-12 19:23:47 UTC (rev 168635)
</span><span class="lines">@@ -82,24 +82,39 @@
</span><span class="cx">
</span><span class="cx"> void JSRopeString::visitFibers(SlotVisitor& visitor)
</span><span class="cx"> {
</span><del>- for (size_t i = 0; i < s_maxInternalRopeLength && m_fibers[i]; ++i)
- visitor.append(&m_fibers[i]);
</del><ins>+ if (isSubstring()) {
+ visitor.append(&substringBase());
+ return;
+ }
+ for (size_t i = 0; i < s_maxInternalRopeLength && fiber(i); ++i)
+ visitor.append(&fiber(i));
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> static const unsigned maxLengthForOnStackResolve = 2048;
</span><span class="cx">
</span><span class="cx"> void JSRopeString::resolveRopeInternal8(LChar* buffer) const
</span><span class="cx"> {
</span><del>- for (size_t i = 0; i < s_maxInternalRopeLength && m_fibers[i]; ++i) {
- if (m_fibers[i]->isRope()) {
</del><ins>+ if (isSubstring()) {
+ StringImpl::copyChars(
+ buffer, substringBase()->m_value.characters8() + substringOffset(), m_length);
+ return;
+ }
+
+ resolveRopeInternal8NoSubstring(buffer);
+}
+
+void JSRopeString::resolveRopeInternal8NoSubstring(LChar* buffer) const
+{
+ for (size_t i = 0; i < s_maxInternalRopeLength && fiber(i); ++i) {
+ if (fiber(i)->isRope()) {
</ins><span class="cx"> resolveRopeSlowCase8(buffer);
</span><span class="cx"> return;
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> LChar* position = buffer;
</span><del>- for (size_t i = 0; i < s_maxInternalRopeLength && m_fibers[i]; ++i) {
- const StringImpl& fiberString = *m_fibers[i]->m_value.impl();
</del><ins>+ for (size_t i = 0; i < s_maxInternalRopeLength && fiber(i); ++i) {
+ const StringImpl& fiberString = *fiber(i)->m_value.impl();
</ins><span class="cx"> unsigned length = fiberString.length();
</span><span class="cx"> StringImpl::copyChars(position, fiberString.characters8(), length);
</span><span class="cx"> position += length;
</span><span class="lines">@@ -109,16 +124,27 @@
</span><span class="cx">
</span><span class="cx"> void JSRopeString::resolveRopeInternal16(UChar* buffer) const
</span><span class="cx"> {
</span><del>- for (size_t i = 0; i < s_maxInternalRopeLength && m_fibers[i]; ++i) {
- if (m_fibers[i]->isRope()) {
</del><ins>+ if (isSubstring()) {
+ StringImpl::copyChars(
+ buffer, substringBase()->m_value.characters16() + substringOffset(), m_length);
+ return;
+ }
+
+ resolveRopeInternal16NoSubstring(buffer);
+}
+
+void JSRopeString::resolveRopeInternal16NoSubstring(UChar* buffer) const
+{
+ for (size_t i = 0; i < s_maxInternalRopeLength && fiber(i); ++i) {
+ if (fiber(i)->isRope()) {
</ins><span class="cx"> resolveRopeSlowCase(buffer);
</span><span class="cx"> return;
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> UChar* position = buffer;
</span><del>- for (size_t i = 0; i < s_maxInternalRopeLength && m_fibers[i]; ++i) {
- const StringImpl& fiberString = *m_fibers[i]->m_value.impl();
</del><ins>+ for (size_t i = 0; i < s_maxInternalRopeLength && fiber(i); ++i) {
+ const StringImpl& fiberString = *fiber(i)->m_value.impl();
</ins><span class="cx"> unsigned length = fiberString.length();
</span><span class="cx"> if (fiberString.is8Bit())
</span><span class="cx"> StringImpl::copyChars(position, fiberString.characters8(), length);
</span><span class="lines">@@ -156,8 +182,8 @@
</span><span class="cx">
</span><span class="cx"> void JSRopeString::clearFibers() const
</span><span class="cx"> {
</span><del>- for (size_t i = 0; i < s_maxInternalRopeLength && m_fibers[i]; ++i)
- m_fibers[i].clear();
</del><ins>+ for (size_t i = 0; i < s_maxInternalRopeLength; ++i)
+ u[i].number = 0;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> AtomicStringImpl* JSRopeString::resolveRopeToExistingAtomicString(ExecState* exec) const
</span><span class="lines">@@ -171,7 +197,7 @@
</span><span class="cx"> }
</span><span class="cx"> return nullptr;
</span><span class="cx"> }
</span><del>-
</del><ins>+
</ins><span class="cx"> if (is8Bit()) {
</span><span class="cx"> LChar buffer[maxLengthForOnStackResolve];
</span><span class="cx"> resolveRopeInternal8(buffer);
</span><span class="lines">@@ -196,7 +222,14 @@
</span><span class="cx"> void JSRopeString::resolveRope(ExecState* exec) const
</span><span class="cx"> {
</span><span class="cx"> ASSERT(isRope());
</span><del>-
</del><ins>+
+ if (isSubstring()) {
+ ASSERT(!substringBase()->isRope());
+ m_value = substringBase()->m_value.substring(substringOffset(), m_length);
+ substringBase().clear();
+ return;
+ }
+
</ins><span class="cx"> if (is8Bit()) {
</span><span class="cx"> LChar* buffer;
</span><span class="cx"> if (RefPtr<StringImpl> newImpl = StringImpl::tryCreateUninitialized(m_length, buffer)) {
</span><span class="lines">@@ -206,7 +239,7 @@
</span><span class="cx"> outOfMemory(exec);
</span><span class="cx"> return;
</span><span class="cx"> }
</span><del>- resolveRopeInternal8(buffer);
</del><ins>+ resolveRopeInternal8NoSubstring(buffer);
</ins><span class="cx"> clearFibers();
</span><span class="cx"> ASSERT(!isRope());
</span><span class="cx"> return;
</span><span class="lines">@@ -221,7 +254,7 @@
</span><span class="cx"> return;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- resolveRopeInternal16(buffer);
</del><ins>+ resolveRopeInternal16NoSubstring(buffer);
</ins><span class="cx"> clearFibers();
</span><span class="cx"> ASSERT(!isRope());
</span><span class="cx"> }
</span><span class="lines">@@ -241,24 +274,32 @@
</span><span class="cx"> LChar* position = buffer + m_length; // We will be working backwards over the rope.
</span><span class="cx"> Vector<JSString*, 32, UnsafeVectorOverflow> workQueue; // Putting strings into a Vector is only OK because there are no GC points in this method.
</span><span class="cx">
</span><del>- for (size_t i = 0; i < s_maxInternalRopeLength && m_fibers[i]; ++i)
- workQueue.append(m_fibers[i].get());
</del><ins>+ for (size_t i = 0; i < s_maxInternalRopeLength && fiber(i); ++i)
+ workQueue.append(fiber(i).get());
</ins><span class="cx">
</span><span class="cx"> while (!workQueue.isEmpty()) {
</span><span class="cx"> JSString* currentFiber = workQueue.last();
</span><span class="cx"> workQueue.removeLast();
</span><span class="cx">
</span><ins>+ const LChar* characters;
+
</ins><span class="cx"> if (currentFiber->isRope()) {
</span><span class="cx"> JSRopeString* currentFiberAsRope = static_cast<JSRopeString*>(currentFiber);
</span><del>- for (size_t i = 0; i < s_maxInternalRopeLength && currentFiberAsRope->m_fibers[i]; ++i)
- workQueue.append(currentFiberAsRope->m_fibers[i].get());
- continue;
- }
-
- StringImpl* string = static_cast<StringImpl*>(currentFiber->m_value.impl());
- unsigned length = string->length();
</del><ins>+ if (!currentFiberAsRope->isSubstring()) {
+ for (size_t i = 0; i < s_maxInternalRopeLength && currentFiberAsRope->fiber(i); ++i)
+ workQueue.append(currentFiberAsRope->fiber(i).get());
+ continue;
+ }
+ ASSERT(!currentFiberAsRope->substringBase()->isRope());
+ characters =
+ currentFiberAsRope->substringBase()->m_value.characters8() +
+ currentFiberAsRope->substringOffset();
+ } else
+ characters = currentFiber->m_value.characters8();
+
+ unsigned length = currentFiber->length();
</ins><span class="cx"> position -= length;
</span><del>- StringImpl::copyChars(position, string->characters8(), length);
</del><ins>+ StringImpl::copyChars(position, characters, length);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> ASSERT(buffer == position);
</span><span class="lines">@@ -269,8 +310,8 @@
</span><span class="cx"> UChar* position = buffer + m_length; // We will be working backwards over the rope.
</span><span class="cx"> Vector<JSString*, 32, UnsafeVectorOverflow> workQueue; // These strings are kept alive by the parent rope, so using a Vector is OK.
</span><span class="cx">
</span><del>- for (size_t i = 0; i < s_maxInternalRopeLength && m_fibers[i]; ++i)
- workQueue.append(m_fibers[i].get());
</del><ins>+ for (size_t i = 0; i < s_maxInternalRopeLength && fiber(i); ++i)
+ workQueue.append(fiber(i).get());
</ins><span class="cx">
</span><span class="cx"> while (!workQueue.isEmpty()) {
</span><span class="cx"> JSString* currentFiber = workQueue.last();
</span><span class="lines">@@ -278,8 +319,21 @@
</span><span class="cx">
</span><span class="cx"> if (currentFiber->isRope()) {
</span><span class="cx"> JSRopeString* currentFiberAsRope = static_cast<JSRopeString*>(currentFiber);
</span><del>- for (size_t i = 0; i < s_maxInternalRopeLength && currentFiberAsRope->m_fibers[i]; ++i)
- workQueue.append(currentFiberAsRope->m_fibers[i].get());
</del><ins>+ if (currentFiberAsRope->isSubstring()) {
+ ASSERT(!currentFiberAsRope->substringBase()->isRope());
+ StringImpl* string = static_cast<StringImpl*>(
+ currentFiberAsRope->substringBase()->m_value.impl());
+ unsigned offset = currentFiberAsRope->substringOffset();
+ unsigned length = currentFiberAsRope->length();
+ position -= length;
+ if (string->is8Bit())
+ StringImpl::copyChars(position, string->characters8() + offset, length);
+ else
+ StringImpl::copyChars(position, string->characters16() + offset, length);
+ continue;
+ }
+ for (size_t i = 0; i < s_maxInternalRopeLength && currentFiberAsRope->fiber(i); ++i)
+ workQueue.append(currentFiberAsRope->fiber(i).get());
</ins><span class="cx"> continue;
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="branchesftloptSourceJavaScriptCoreruntimeJSStringh"></a>
<div class="modfile"><h4>Modified: branches/ftlopt/Source/JavaScriptCore/runtime/JSString.h (168634 => 168635)</h4>
<pre class="diff"><span>
<span class="info">--- branches/ftlopt/Source/JavaScriptCore/runtime/JSString.h        2014-05-12 19:20:21 UTC (rev 168634)
+++ branches/ftlopt/Source/JavaScriptCore/runtime/JSString.h        2014-05-12 19:23:47 UTC (rev 168635)
</span><span class="lines">@@ -273,8 +273,10 @@
</span><span class="cx"> Base::finishCreation(vm);
</span><span class="cx"> m_length = s1->length() + s2->length();
</span><span class="cx"> setIs8Bit(s1->is8Bit() && s2->is8Bit());
</span><del>- m_fibers[0].set(vm, this, s1);
- m_fibers[1].set(vm, this, s2);
</del><ins>+ setIsSubstring(false);
+ fiber(0).set(vm, this, s1);
+ fiber(1).set(vm, this, s2);
+ fiber(2).clear();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void finishCreation(VM& vm, JSString* s1, JSString* s2, JSString* s3)
</span><span class="lines">@@ -282,19 +284,37 @@
</span><span class="cx"> Base::finishCreation(vm);
</span><span class="cx"> m_length = s1->length() + s2->length() + s3->length();
</span><span class="cx"> setIs8Bit(s1->is8Bit() && s2->is8Bit() && s3->is8Bit());
</span><del>- m_fibers[0].set(vm, this, s1);
- m_fibers[1].set(vm, this, s2);
- m_fibers[2].set(vm, this, s3);
</del><ins>+ setIsSubstring(false);
+ fiber(0).set(vm, this, s1);
+ fiber(1).set(vm, this, s2);
+ fiber(2).set(vm, this, s3);
</ins><span class="cx"> }
</span><ins>+
+ void finishCreation(VM& vm, JSString* base, unsigned offset, unsigned length)
+ {
+ Base::finishCreation(vm);
+ ASSERT(!base->isRope());
+ ASSERT(!sumOverflows<int32_t>(offset, length));
+ ASSERT(offset + length <= base->length());
+ m_length = length;
+ setIs8Bit(base->is8Bit());
+ setIsSubstring(true);
+ substringBase().set(vm, this, base);
+ substringOffset() = offset;
+ }
</ins><span class="cx">
</span><span class="cx"> void finishCreation(VM& vm)
</span><span class="cx"> {
</span><span class="cx"> JSString::finishCreation(vm);
</span><ins>+ setIsSubstring(false);
+ fiber(0).clear();
+ fiber(1).clear();
+ fiber(2).clear();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void append(VM& vm, size_t index, JSString* jsString)
</span><span class="cx"> {
</span><del>- m_fibers[index].set(vm, this, jsString);
</del><ins>+ fiber(index).set(vm, this, jsString);
</ins><span class="cx"> m_length += jsString->m_length;
</span><span class="cx"> RELEASE_ASSERT(static_cast<int32_t>(m_length) >= 0);
</span><span class="cx"> setIs8Bit(is8Bit() && jsString->is8Bit());
</span><span class="lines">@@ -320,10 +340,17 @@
</span><span class="cx"> newString->finishCreation(vm, s1, s2, s3);
</span><span class="cx"> return newString;
</span><span class="cx"> }
</span><ins>+
+ static JSString* create(VM& vm, JSString* base, unsigned offset, unsigned length)
+ {
+ JSRopeString* newString = new (NotNull, allocateCell<JSRopeString>(vm.heap)) JSRopeString(vm);
+ newString->finishCreation(vm, base, offset, length);
+ return newString;
+ }
</ins><span class="cx">
</span><span class="cx"> void visitFibers(SlotVisitor&);
</span><span class="cx">
</span><del>- static ptrdiff_t offsetOfFibers() { return OBJECT_OFFSETOF(JSRopeString, m_fibers); }
</del><ins>+ static ptrdiff_t offsetOfFibers() { return OBJECT_OFFSETOF(JSRopeString, u); }
</ins><span class="cx">
</span><span class="cx"> static const unsigned s_maxInternalRopeLength = 3;
</span><span class="cx">
</span><span class="lines">@@ -338,12 +365,54 @@
</span><span class="cx"> void resolveRopeSlowCase(UChar*) const;
</span><span class="cx"> void outOfMemory(ExecState*) const;
</span><span class="cx"> void resolveRopeInternal8(LChar*) const;
</span><ins>+ void resolveRopeInternal8NoSubstring(LChar*) const;
</ins><span class="cx"> void resolveRopeInternal16(UChar*) const;
</span><ins>+ void resolveRopeInternal16NoSubstring(UChar*) const;
</ins><span class="cx"> void clearFibers() const;
</span><span class="cx">
</span><span class="cx"> JS_EXPORT_PRIVATE JSString* getIndexSlowCase(ExecState*, unsigned);
</span><ins>+
+ WriteBarrierBase<JSString>& fiber(unsigned i) const
+ {
+ ASSERT(!isSubstring());
+ ASSERT(i < s_maxInternalRopeLength);
+ return u[i].string;
+ }
+
+ WriteBarrierBase<JSString>& substringBase() const
+ {
+ return u[1].string;
+ }
+
+ uintptr_t& substringOffset() const
+ {
+ return u[2].number;
+ }
+
+ static uintptr_t notSubstringSentinel()
+ {
+ return 0;
+ }
+
+ static uintptr_t substringSentinel()
+ {
+ return 1;
+ }
+
+ bool isSubstring() const
+ {
+ return u[0].number == substringSentinel();
+ }
+
+ void setIsSubstring(bool isSubstring)
+ {
+ u[0].number = isSubstring ? substringSentinel() : notSubstringSentinel();
+ }
</ins><span class="cx">
</span><del>- mutable std::array<WriteBarrier<JSString>, s_maxInternalRopeLength> m_fibers;
</del><ins>+ mutable union {
+ uintptr_t number;
+ WriteBarrierBase<JSString> string;
+ } u[s_maxInternalRopeLength];
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx">
</span><span class="lines">@@ -454,10 +523,11 @@
</span><span class="cx"> ASSERT(offset <= static_cast<unsigned>(s->length()));
</span><span class="cx"> ASSERT(length <= static_cast<unsigned>(s->length()));
</span><span class="cx"> ASSERT(offset + length <= static_cast<unsigned>(s->length()));
</span><del>- VM* vm = &exec->vm();
</del><ins>+ VM& vm = exec->vm();
</ins><span class="cx"> if (!length)
</span><del>- return vm->smallStrings.emptyString();
- return jsSubstring(vm, s->value(exec), offset, length);
</del><ins>+ return vm.smallStrings.emptyString();
+ s->value(exec); // For effect. We need to ensure that any string that is used as a substring base is not a rope.
+ return JSRopeString::create(vm, s, offset, length);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> inline JSString* jsSubstring8(VM* vm, const String& s, unsigned offset, unsigned length)
</span></span></pre></div>
<a id="branchesftloptSourceJavaScriptCoreruntimeRegExpMatchesArraycpp"></a>
<div class="modfile"><h4>Modified: branches/ftlopt/Source/JavaScriptCore/runtime/RegExpMatchesArray.cpp (168634 => 168635)</h4>
<pre class="diff"><span>
<span class="info">--- branches/ftlopt/Source/JavaScriptCore/runtime/RegExpMatchesArray.cpp        2014-05-12 19:20:21 UTC (rev 168634)
+++ branches/ftlopt/Source/JavaScriptCore/runtime/RegExpMatchesArray.cpp        2014-05-12 19:23:47 UTC (rev 168635)
</span><span class="lines">@@ -74,6 +74,8 @@
</span><span class="cx"> ASSERT(m_state != ReifiedAll);
</span><span class="cx"> ASSERT(m_result);
</span><span class="cx">
</span><ins>+ SamplingRegion samplingRegion("Reifying substring properties");
+
</ins><span class="cx"> reifyMatchPropertyIfNecessary(exec);
</span><span class="cx">
</span><span class="cx"> if (unsigned numSubpatterns = m_regExp->numSubpatterns()) {
</span></span></pre></div>
<a id="branchesftloptSourceJavaScriptCoreruntimeStringPrototypecpp"></a>
<div class="modfile"><h4>Modified: branches/ftlopt/Source/JavaScriptCore/runtime/StringPrototype.cpp (168634 => 168635)</h4>
<pre class="diff"><span>
<span class="info">--- branches/ftlopt/Source/JavaScriptCore/runtime/StringPrototype.cpp        2014-05-12 19:20:21 UTC (rev 168634)
+++ branches/ftlopt/Source/JavaScriptCore/runtime/StringPrototype.cpp        2014-05-12 19:23:47 UTC (rev 168635)
</span><span class="lines">@@ -1218,6 +1218,7 @@
</span><span class="cx">
</span><span class="cx"> EncodedJSValue JSC_HOST_CALL stringProtoFuncSubstring(ExecState* exec)
</span><span class="cx"> {
</span><ins>+ SamplingRegion samplingRegion("Doing substringing");
</ins><span class="cx"> JSValue thisValue = exec->thisValue();
</span><span class="cx"> if (!checkObjectCoercible(thisValue))
</span><span class="cx"> return throwVMTypeError(exec);
</span></span></pre>
</div>
</div>
</body>
</html>