Bug 126009 - CStack: Update the VMEntryScope's stack limit when the VM enters/exits ErrorMode
Summary: CStack: Update the VMEntryScope's stack limit when the VM enters/exits ErrorMode
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:
Depends on:
Blocks: 125928
  Show dependency treegraph
 
Reported: 2013-12-19 12:27 PST by Mark Lam
Modified: 2013-12-29 08:26 PST (History)
5 users (show)

See Also:


Attachments
the patch. (12.26 KB, patch)
2013-12-21 03:29 PST, Mark Lam
no flags Details | Formatted Diff | Diff
the real patch. (18.98 KB, patch)
2013-12-21 03:32 PST, Mark Lam
no flags Details | Formatted Diff | Diff
patch 2. (19.43 KB, patch)
2013-12-21 03:46 PST, Mark Lam
msaboff: 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 2013-12-19 12:27:47 PST
See JSStack::enableErrorStackReserve() and JSStack::disableErrorStackReserve().  Just like this is needed for handling StackOverflowErrors when using the separate JSStack, we need to implement the equivalent for the C stack.
Comment 1 Geoffrey Garen 2013-12-19 15:02:02 PST
Can we just rely on handling errors inside the host zone? Do we need another concept?
Comment 2 Mark Lam 2013-12-19 15:04:59 PST
(In reply to comment #1)
> Can we just rely on handling errors inside the host zone? Do we need another concept?

We need a distinction because we need to allow the VM to use some additional stack space in order to do the work of throwing a StackOverflowError after we have reached the stack limit for normal execution.  Otherwise, we’ll encounter a stack overflow while trying to throw the StackOverflowError.
Comment 3 Geoffrey Garen 2013-12-19 15:12:58 PST
(In reply to comment #2)
> (In reply to comment #1)
> > Can we just rely on handling errors inside the host zone? Do we need another concept?
> 
> We need a distinction because we need to allow the VM to use some additional stack space in order to do the work of throwing a StackOverflowError after we have reached the stack limit for normal execution.  Otherwise, we’ll encounter a stack overflow while trying to throw the StackOverflowError.

Yes, that explains what we're trying to do. I have a suggestion for how: What you're calling "JSStack:: enableErrorStackReserve()" should just adjust the stack limit by half the size of the host zone.
Comment 4 Mark Lam 2013-12-19 15:16:18 PST
(In reply to comment #3)
> (In reply to comment #2)
> > (In reply to comment #1)
> > > Can we just rely on handling errors inside the host zone? Do we need another concept?
> > 
> > We need a distinction because we need to allow the VM to use some additional stack space in order to do the work of throwing a StackOverflowError after we have reached the stack limit for normal execution.  Otherwise, we’ll encounter a stack overflow while trying to throw the StackOverflowError.
> 
> Yes, that explains what we're trying to do. I have a suggestion for how: What you're calling "JSStack:: enableErrorStackReserve()" should just adjust the stack limit by half the size of the host zone.

Yes, that is pretty much what I had in mind.  I hadn’t thought of how much to adjust it by yet, but half the host zone sounds reasonable.
Comment 5 Mark Lam 2013-12-20 23:58:03 PST
The C stack limit tracking mechanism in the VMEntryScope class already has allowance for a smaller host zone when the Interpreter is in an ErrorMode.  We just need to update the VMEntryScope's stack limit whenever the Interpreter enters and exits its ErrorMode.
Comment 6 Mark Lam 2013-12-21 03:29:56 PST
Created attachment 219845 [details]
the patch.
Comment 7 Mark Lam 2013-12-21 03:31:11 PST
Comment on attachment 219845 [details]
the patch.

Wrong patch.
Comment 8 Mark Lam 2013-12-21 03:32:20 PST
Created attachment 219846 [details]
the real patch.
Comment 9 Mark Lam 2013-12-21 03:45:01 PST
Comment on attachment 219846 [details]
the real patch.

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

> Source/JavaScriptCore/interpreter/JSStack.cpp:189
> +#else
> +    if (m_vm.entryScope)
> +        m_vm.entryScope->updateStackLimit();
> +#endif

After thinking about this some more, the C stack update should be unconditional independent of whether the JS stack is on the C stack or its own separate stack.  We may have detected a stack overflow due to the C stack reaching it's limit.  Hence, the VM may need more C stack space to process the error even if the JS stack is on its own separate stack.  I will upload an updated patch.
Comment 10 Mark Lam 2013-12-21 03:46:59 PST
Created attachment 219847 [details]
patch 2.
Comment 11 Mark Lam 2013-12-21 11:22:31 PST
Landed in r160967 on the jsCStack branch: <http://trac.webkit.org/r160967>.
Comment 12 Mark Lam 2013-12-29 08:26:10 PST
Thanks for the review.  Review status updated in r161117: <http://trac.webkit.org/r161117>.