No subject


Mon Jan 28 08:41:14 PST 2013


On a debug build on OSX:
1. Stack usage different between recursive calls to interpreter entry:
   7744 bytes
On a release build on OSX:
2. Stack usage difference between recursive calls to interpreter entry:
   6352 bytes

Using these as a guide, we'll pick the following values for the
StackPolicy:
   requiredStack: 32K
   errorModeRequiredStack: 16K

The requiredStack is chosen to be 4x the measured usage above. The
additional 3x is a conservative estimate to account for stack space
that may be needed by other native functions called while in the
interpreter.

The errorModeRequiredStack has to be less than the requiredStack or we
won't be able to reenter the interpreter to do error handling work when
an imminent stack overflow is detected. It is assumed that the error
handling code will only do minimal work to allocate an exception and its
stack trace, and not run any arbitrary JS code. As such, it is safe to
allow re-entry into the interpreter with only 2x the measured usage in
this case.

* interpreter/Interpreter.cpp:
(JSC::Interpreter::StackPolicy::StackPolicy):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href=3D"#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScri=
ptCore/ChangeLog</a></li>
<li><a href=3D"#trunkSourceJavaScriptCoreinterpreterInterpretercpp">trunk=
/Source/JavaScriptCore/interpreter/Interpreter.cpp</a></li>
</ul>

</div>
<div id=3D"patch">
<h3>Diff</h3>
<a id=3D"trunkSourceJavaScriptCoreChangeLog"></a>
<div class=3D"modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLo=
g (151807 =3D> 151808)</h4>
<pre class=3D"diff"><span>
<span class=3D"info">--- trunk/Source/JavaScriptCore/ChangeLog	2013-06-20=
 22:15:34 UTC (rev 151807)
+++ trunk/Source/JavaScriptCore/ChangeLog	2013-06-20 22:17:27 UTC (rev 15=
1808)
</span><span class=3D"lines">@@ -1,3 +1,59 @@
</span><ins>+2013-06-20  Mark Lam  &lt;mark.lam at apple.com&gt;
+
+        Change stack capacity requirement to be more reasonable.
+        https://bugs.webkit.org/show_bug.cgi?id=3D117801.
+
+        Reviewed by Geoffrey Garen.
+
+        Previously, the requiredStack in StackPolicy::StackPolicy() was =
set to
+        to a high value like 256K to reduce the chances of encountering =
an
+        undetected stack overflow in a scenario where we have a combinat=
ion of
+        deeply nested divs and a large amount recursive re-entries into =
the VM.
+
+        However, this high value of requiredStack still does not complet=
ely
+        ensure that we will never encounter an undetected stack overflow=
. It
+        only lessens the probability of encountering it.
+
+        Secondly, on some platforms, the total stack size can be less th=
an 256K
+        to start with. Hence, this high value requiredStack renders the =
VM
+        unuseable on those platforms.
+
+        This patch will fix the requiredStack to be more reasonable base=
d on
+        real world stack usage by the VM. We won't (and cannot) try to p=
revent
+        undetected stack overflows outside of JSC as well. External code=
 that
+        do deep recursion (e.g. Documnet::updateLayout()) should do thei=
r own
+        stack checks.
+
+        From a previous experiment, we measured the following:
+
+        On a debug build on OSX:
+        1. Stack usage different between recursive calls to interpreter =
entry:
+           7744 bytes
+        On a release build on OSX:
+        2. Stack usage difference between recursive calls to interpreter=
 entry:
+           6352 bytes
+
+        Using these as a guide, we'll pick the following values for the
+        StackPolicy:
+           requiredStack: 32K
+           errorModeRequiredStack: 16K
+
+        The requiredStack is chosen to be 4x the measured usage above. T=
he
+        additional 3x is a conservative estimate to account for stack sp=
ace
+        that may be needed by other native functions called while in the
+        interpreter.
+
+        The errorModeRequiredStack has to be less than the requiredStack=
 or we
+        won't be able to reenter the interpreter to do error handling wo=
rk when
+        an imminent stack overflow is detected. It is assumed that the e=
rror
+        handling code will only do minimal work to allocate an exception=
 and its
+        stack trace, and not run any arbitrary JS code. As such, it is s=
afe to
+        allow re-entry into the interpreter with only 2x the measured us=
age in
+        this case.
+
+        * interpreter/Interpreter.cpp:
+        (JSC::Interpreter::StackPolicy::StackPolicy):
+
</ins><span class=3D"cx"> 2013-06-20  Mikhail Pozdnyakov  &lt;mikhail.poz=
dnyakov at intel.com&gt;
</span><span class=3D"cx">=20
</span><span class=3D"cx">         HashSet: reverse the order of the temp=
late arguments at alternate 'find', 'contains' and 'add' methods
</span></span></pre></div>
<a id=3D"trunkSourceJavaScriptCoreinterpreterInterpretercpp"></a>
<div class=3D"modfile"><h4>Modified: trunk/Source/JavaScriptCore/interpre=
ter/Interpreter.cpp (151807 =3D> 151808)</h4>
<pre class=3D"diff"><span>
<span class=3D"info">--- trunk/Source/JavaScriptCore/interpreter/Interpre=
ter.cpp	2013-06-20 22:15:34 UTC (rev 151807)
+++ trunk/Source/JavaScriptCore/interpreter/Interpreter.cpp	2013-06-20 22=
:17:27 UTC (rev 151808)
</span><span class=3D"lines">@@ -126,12 +126,12 @@
</span><span class=3D"cx">     //
</span><span class=3D"cx">     // These sizes were derived from the stack=
 usage of a number of sites when
</span><span class=3D"cx">     // layout occurs when we've already consum=
ed most of the C stack.
</span><del>-    const size_t requiredStack =3D 256 * KB;
-    const size_t errorModeRequiredStack =3D 64 * KB;
</del><ins>+    const size_t requiredStack =3D 32 * KB;
+    const size_t errorModeRequiredStack =3D 16 * KB;
</ins><span class=3D"cx">=20
</span><span class=3D"cx">     size_t requiredCapacity =3D m_interpreter.=
m_errorHandlingModeReentry ? errorModeRequiredStack : requiredStack;
</span><span class=3D"cx">=20
</span><del>-    RELEASE_ASSERT(size &gt; requiredCapacity);
</del><ins>+    RELEASE_ASSERT(size &gt;=3D requiredCapacity);
</ins><span class=3D"cx">    =20
</span><span class=3D"cx">     m_requiredCapacity =3D requiredCapacity;  =
 =20
</span><span class=3D"cx"> }
</span></span></pre>
</div>
</div>

</body>
</html>


More information about the webkit-changes mailing list