Bug 98928 - JSC: A reliable topCallFrame
Summary: JSC: A reliable topCallFrame
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Mark Lam
URL:
Keywords: InRadar
Depends on: 99872
Blocks:
  Show dependency treegraph
 
Reported: 2012-10-10 11:07 PDT by Mark Lam
Modified: 2012-10-23 05:06 PDT (History)
18 users (show)

See Also:


Attachments
preliminary (59.72 KB, patch)
2012-10-10 12:59 PDT, Mark Lam
buildbot: commit-queue-
Details | Formatted Diff | Diff
Draft 1. (84.64 KB, patch)
2012-10-14 23:35 PDT, Mark Lam
buildbot: commit-queue-
Details | Formatted Diff | Diff
Draft 2: not ready for review yet, just testing fix for ews reported issues. (130.20 KB, patch)
2012-10-18 23:41 PDT, Mark Lam
buildbot: commit-queue-
Details | Formatted Diff | Diff
Fix. (59.76 KB, patch)
2012-10-22 17:29 PDT, Mark Lam
ggaren: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Lam 2012-10-10 11:07:27 PDT
Fix the topCallFrame pointer usage so that it is reliable and more accurate.

<rdar://problem/11721461>
<rdar://problem/11721462>
Comment 1 Mark Lam 2012-10-10 12:59:59 PDT
Created attachment 168058 [details]
preliminary
Comment 2 Geoffrey Garen 2012-10-10 13:45:24 PDT
Comment on attachment 168058 [details]
preliminary

View in context: https://bugs.webkit.org/attachment.cgi?id=168058&action=review

> Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h:365
> +            const size_t stackRedZoneSize = 16 * 1024;
> +            return m_stack.recursionCheck(stackRedZoneSize)

Should we just change s_defaultAvailabilityDelta to 16kB?

> Source/JavaScriptCore/interpreter/Interpreter.cpp:731
> +    if (checker.isInRedZone() || (m_reentryDepth >= MaxSmallThreadReentryDepth && m_reentryDepth >= callFrame->globalData().maxReentryDepth))

Since you're using a precise check, you should remove m_reentryDepth and its associated less precise checks.
Comment 3 Build Bot 2012-10-10 16:03:54 PDT
Comment on attachment 168058 [details]
preliminary

Attachment 168058 [details] did not pass mac-ews (mac):
Output: http://queues.webkit.org/results/14260200

New failing tests:
fast/js/global-recursion-on-full-stack.html
Comment 4 Mark Lam 2012-10-14 23:35:32 PDT
Created attachment 168631 [details]
Draft 1.

(In reply to comment #2)
> > Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h:365
> > +            const size_t stackRedZoneSize = 16 * 1024;
> > +            return m_stack.recursionCheck(stackRedZoneSize)
> 
> Should we just change s_defaultAvailabilityDelta to 16kB?

I've changed this to 32kB to be consistent with the estimated worst case in the Interpreter loop entry points.  Will run some more test for this value.

> > Source/JavaScriptCore/interpreter/Interpreter.cpp:731
> > +    if (checker.isInRedZone() || (m_reentryDepth >= MaxSmallThreadReentryDepth && m_reentryDepth >= callFrame->globalData().maxReentryDepth))
> 
> Since you're using a precise check, you should remove m_reentryDepth and its associated less precise checks.

Done.
Comment 5 Build Bot 2012-10-15 00:09:41 PDT
Comment on attachment 168631 [details]
Draft 1.

Attachment 168631 [details] did not pass win-ews (win):
Output: http://queues.webkit.org/results/14293628
Comment 6 Build Bot 2012-10-15 00:42:09 PDT
Comment on attachment 168631 [details]
Draft 1.

Attachment 168631 [details] did not pass mac-ews (mac):
Output: http://queues.webkit.org/results/14298633

New failing tests:
fast/xmlhttprequest/xmlhttprequest-recursive-sync-event.html
Comment 7 Mark Lam 2012-10-18 23:41:48 PDT
Created attachment 169560 [details]
Draft 2: not ready for review yet, just testing fix for ews reported issues.
Comment 8 Build Bot 2012-10-19 02:25:48 PDT
Comment on attachment 169560 [details]
Draft 2: not ready for review yet, just testing fix for ews reported issues.

Attachment 169560 [details] did not pass mac-ews (mac):
Output: http://queues.webkit.org/results/14464369

New failing tests:
svg/foreignObject/viewport-foreignobject-crash.html
Comment 9 Mark Lam 2012-10-22 17:29:15 PDT
Created attachment 170034 [details]
Fix.
Comment 10 Mark Lam 2012-10-22 17:59:10 PDT
Comment on attachment 170034 [details]
Fix.

Win EWS bot is happy.  It's ready for a review.
Comment 11 Geoffrey Garen 2012-10-22 21:25:00 PDT
Comment on attachment 170034 [details]
Fix.

View in context: https://bugs.webkit.org/attachment.cgi?id=170034&action=review

r=me

> Source/JavaScriptCore/jit/JITStubs.cpp:2145
> +    callFrame->setCodeBlock(0);

Why did you need to do this? Your ChangeLog doesn't say.

> Source/JavaScriptCore/jit/JITStubs.cpp:2227
> +    callFrame->setCodeBlock(0);

Why did you need to do this? Your ChangeLog doesn't say.
Comment 12 Mark Lam 2012-10-22 23:36:20 PDT
(In reply to comment #11)
> (From update of attachment 170034 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=170034&action=review
> 
> r=me
> 
> > Source/JavaScriptCore/jit/JITStubs.cpp:2145
> > +    callFrame->setCodeBlock(0);
> 
> Why did you need to do this? Your ChangeLog doesn't say.
> 
> > Source/JavaScriptCore/jit/JITStubs.cpp:2227
> > +    callFrame->setCodeBlock(0);
> 
> Why did you need to do this? Your ChangeLog doesn't say.

These were done in the jitCompileFor() and lazyLinkFor() JIT stub helper functions.  Both of these functions were called from JIT stub functions which in turn were called by JIT glue trampoline code which are trying to call a callee function (for call or construct), but the callee needs to be linked or JIT compiled.  In both cases, a call frame has been pushed and partially initialized.  It is expected that the prologue of the callee will handle the initialization of the frame's codeBlock field.

But this these cases, the callee is not known yet (which is why we're doing a link and JIT compile), and hence has not been called yet.  But these JIT stub helpers will do work that may trigger a GC.  The GC will scan the JSStack and step on an uninitialized codeBlock pointer.  Hence, we initialize the codeBlock pointer to be 0 here to keep the GC happy.

I will capture the above in comments in the code before I land the change.  Thanks for the review.
Comment 13 Mark Lam 2012-10-23 00:13:52 PDT
Landed in r132182: <http://trac.webkit.org/changeset/132182>.
Comment 14 Thiago Marcos P. Santos 2012-10-23 03:17:21 PDT
I'm afraid this patch caused a regression. Some API tests are asserting on EFL.

http://build.webkit.org/builders/EFL%20Linux%2064-bit%20Debug%20WK2/builds/4926/steps/API%20tests/logs/stdio

ASSERTION FAILED: (requiredCapacity >= 0) && (requiredCapacity < size)
/home/buildslave-1/webkit-buildslave/efl-linux-64-debug-wk2/build/Source/JavaScriptCore/interpreter/Interpreter.cpp(195) : JSC::Interpreter::StackPolicy::StackPolicy(JSC::Interpreter&, const WTF::StackBounds&)
1   0x2b94f7b3393e JSC::Interpreter::StackPolicy::StackPolicy(JSC::Interpreter&, WTF::StackBounds const&)
2   0x2b94f7b36bb4 JSC::Interpreter::execute(JSC::ProgramExecutable*, JSC::ExecState*, JSC::JSObject*)
3   0x2b94f7bf69fc JSC::evaluate(JSC::ExecState*, JSC::SourceCode const&, JSC::JSValue, JSC::JSValue*)
4   0x2b94f26ba4dd WebCore::JSMainThreadExecState::evaluate(JSC::ExecState*, JSC::SourceCode const&, JSC::JSValue, JSC::JSValue*)
5   0x2b94f26d7234 WebCore::ScriptController::evaluateInWorld(WebCore::ScriptSourceCode const&, WebCore::DOMWrapperWorld*)
6   0x2b94f26d7336 WebCore::ScriptController::evaluate(WebCore::ScriptSourceCode const&)
7   0x2b94f1c58347 WebCore::ScriptElement::executeScript(WebCore::ScriptSourceCode const&)
8   0x2b94f1c57b9f WebCore::ScriptElement::prepareScript(WTF::TextPosition const&, WebCore::ScriptElement::LegacyTypeSupport)
9   0x2b94f1e491f8 WebCore::HTMLScriptRunner::runScript(WebCore::Element*, WTF::TextPosition const&)
10  0x2b94f1e48845 WebCore::HTMLScriptRunner::execute(WTF::PassRefPtr<WebCore::Element>, WTF::TextPosition const&)
11  0x2b94f1e39b6b WebCore::HTMLDocumentParser::runScriptsForPausedTreeBuilder()
12  0x2b94f1e39c1d WebCore::HTMLDocumentParser::canTakeNextToken(WebCore::HTMLDocumentParser::SynchronousMode, WebCore::PumpSession&)
13  0x2b94f1e3a030 WebCore::HTMLDocumentParser::pumpTokenizer(WebCore::HTMLDocumentParser::SynchronousMode)
14  0x2b94f1e39a18 WebCore::HTMLDocumentParser::pumpTokenizerIfPossible(WebCore::HTMLDocumentParser::SynchronousMode)
15  0x2b94f1e3a5c2 WebCore::HTMLDocumentParser::append(WebCore::SegmentedString const&)
16  0x2b94f1b6531d WebCore::DecodedDataDocumentParser::flush(WebCore::DocumentWriter*)
17  0x2b94f1fb272f WebCore::DocumentWriter::end()
18  0x2b94f1f9f6b1 WebCore::DocumentLoader::finishedLoading()
19  0x2b94f1fdbfb9 WebCore::MainResourceLoader::didFinishLoading(double)
20  0x2b94f1feeda5 WebCore::ResourceLoader::didFinishLoading(WebCore::ResourceHandle*, double)
21  0x2b94f2b3a14a
22  0x2b94f66b9775
23  0x2b94f66ce8dd g_simple_async_result_complete
24  0x2b94f66ce978
25  0x2b94f6381e53 g_main_context_dispatch
26  0x2b94f54bd16e
27  0x2b94f54b6dc9
28  0x2b94f54b7955
29  0x2b94f54b7c57 ecore_main_loop_begin
30  0x2b94f2b1cee9 WebCore::RunLoop::run()
31  0x2b94eec5cb88 WebProcessMainEfl
Comment 15 Thiago Marcos P. Santos 2012-10-23 05:06:10 PDT
(In reply to comment #14)
> I'm afraid this patch caused a regression. Some API tests are asserting on EFL.
> 
> http://build.webkit.org/builders/EFL%20Linux%2064-bit%20Debug%20WK2/builds/4926/steps/API%20tests/logs/stdio
> 
> ASSERTION FAILED: (requiredCapacity >= 0) && (requiredCapacity < size)
> /home/buildslave-1/webkit-buildslave/efl-linux-64-debug-wk2/build/Source/JavaScriptCore/interpreter/Interpreter.cpp(195) : JSC::Interpreter::StackPolicy::StackPolicy(JSC::Interpreter&, const WTF::StackBounds&)
> 1   0x2b94f7b3393e JSC::Interpreter::StackPolicy::StackPolicy(JSC::Interpreter&, WTF::StackBounds const&)
> 2   0x2b94f7b36bb4 JSC::Interpreter::execute(JSC::ProgramExecutable*, JSC::ExecState*, JSC::JSObject*)
> 3   0x2b94f7bf69fc JSC::evaluate(JSC::ExecState*, JSC::SourceCode const&, JSC::JSValue, JSC::JSValue*)
> 4   0x2b94f26ba4dd WebCore::JSMainThreadExecState::evaluate(JSC::ExecState*, JSC::SourceCode const&, JSC::JSValue, JSC::JSValue*)
> 5   0x2b94f26d7234 WebCore::ScriptController::evaluateInWorld(WebCore::ScriptSourceCode const&, WebCore::DOMWrapperWorld*)
> 6   0x2b94f26d7336 WebCore::ScriptController::evaluate(WebCore::ScriptSourceCode const&)
> 7   0x2b94f1c58347 WebCore::ScriptElement::executeScript(WebCore::ScriptSourceCode const&)
> 8   0x2b94f1c57b9f WebCore::ScriptElement::prepareScript(WTF::TextPosition const&, WebCore::ScriptElement::LegacyTypeSupport)
> 9   0x2b94f1e491f8 WebCore::HTMLScriptRunner::runScript(WebCore::Element*, WTF::TextPosition const&)
> 10  0x2b94f1e48845 WebCore::HTMLScriptRunner::execute(WTF::PassRefPtr<WebCore::Element>, WTF::TextPosition const&)
> 11  0x2b94f1e39b6b WebCore::HTMLDocumentParser::runScriptsForPausedTreeBuilder()
> 12  0x2b94f1e39c1d WebCore::HTMLDocumentParser::canTakeNextToken(WebCore::HTMLDocumentParser::SynchronousMode, WebCore::PumpSession&)
> 13  0x2b94f1e3a030 WebCore::HTMLDocumentParser::pumpTokenizer(WebCore::HTMLDocumentParser::SynchronousMode)
> 14  0x2b94f1e39a18 WebCore::HTMLDocumentParser::pumpTokenizerIfPossible(WebCore::HTMLDocumentParser::SynchronousMode)
> 15  0x2b94f1e3a5c2 WebCore::HTMLDocumentParser::append(WebCore::SegmentedString const&)
> 16  0x2b94f1b6531d WebCore::DecodedDataDocumentParser::flush(WebCore::DocumentWriter*)
> 17  0x2b94f1fb272f WebCore::DocumentWriter::end()
> 18  0x2b94f1f9f6b1 WebCore::DocumentLoader::finishedLoading()
> 19  0x2b94f1fdbfb9 WebCore::MainResourceLoader::didFinishLoading(double)
> 20  0x2b94f1feeda5 WebCore::ResourceLoader::didFinishLoading(WebCore::ResourceHandle*, double)
> 21  0x2b94f2b3a14a
> 22  0x2b94f66b9775
> 23  0x2b94f66ce8dd g_simple_async_result_complete
> 24  0x2b94f66ce978
> 25  0x2b94f6381e53 g_main_context_dispatch
> 26  0x2b94f54bd16e
> 27  0x2b94f54b6dc9
> 28  0x2b94f54b7955
> 29  0x2b94f54b7c57 ecore_main_loop_begin
> 30  0x2b94f2b1cee9 WebCore::RunLoop::run()
> 31  0x2b94eec5cb88 WebProcessMainEfl

Actually looks like the crash was caused by the depends of this bug.