Bug 125672 - jsCStack: Fix exception handling for the LLINT.
Summary: jsCStack: Fix exception handling for the LLINT.
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:
 
Reported: 2013-12-12 19:44 PST by Mark Lam
Modified: 2013-12-13 16:38 PST (History)
5 users (show)

See Also:


Attachments
the patch. (2.51 KB, patch)
2013-12-12 19:46 PST, Mark Lam
ggaren: review+
Details | Formatted Diff | Diff
patch 2: removed llint_throw_from_native_call. (8.34 KB, patch)
2013-12-13 12:43 PST, 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 2013-12-12 19:44:40 PST
We need to re-establish the sp for the catch callFrame in op_catch and nativeCallTrampoline.
Comment 1 Mark Lam 2013-12-12 19:46:52 PST
Created attachment 219143 [details]
the patch.
Comment 2 Darin Adler 2013-12-12 20:32:52 PST
Comment on attachment 219143 [details]
the patch.

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

> Source/JavaScriptCore/llint/LowLevelInterpreter64.asm:283
> +    # So far, we've unwound the stack to the farme just above the sentinel frame.

Typo: "farme"
Comment 3 Geoffrey Garen 2013-12-12 21:12:42 PST
Comment on attachment 219143 [details]
the patch.

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

r=me

>> Source/JavaScriptCore/llint/LowLevelInterpreter64.asm:283
>> +    # So far, we've unwound the stack to the farme just above the sentinel frame.
> 
> Typo: "farme"

The stack grows downward, so I think you meant "below" here, and not "above".

> Source/JavaScriptCore/llint/LowLevelInterpreter64.asm:1971
> +    # So far, we've unwound the stack until the native frame. We need to pop it,
> +    # and pick up unwinding from its caller now (if needed).

This comment is misleading. We didn't "unwind the stack". Instead, the host function returned to us in the normal way. A better thing to say here is just "Pop the host function stack frame created by op_call".

Even that is not a great comment, since it doesn't explain *why*. Why does _llint_throw_from_native_call need us to pop the host function stack frame? I'm not sure.
Comment 4 Mark Lam 2013-12-12 23:34:20 PST
(In reply to comment #3)
> (From update of attachment 219143 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=219143&action=review
> 
> r=me
> 
> >> Source/JavaScriptCore/llint/LowLevelInterpreter64.asm:283
> >> +    # So far, we've unwound the stack to the farme just above the sentinel frame.
> > 
> > Typo: "farme"
> 
> The stack grows downward, so I think you meant "below" here, and not "above".

Fixed.

> > Source/JavaScriptCore/llint/LowLevelInterpreter64.asm:1971
> > +    # So far, we've unwound the stack until the native frame. We need to pop it,
> > +    # and pick up unwinding from its caller now (if needed).
> 
> This comment is misleading. We didn't "unwind the stack". Instead, the host function returned to us in the normal way. A better thing to say here is just "Pop the host function stack frame created by op_call".

We're only here because an exception was thrown and uncaught / unhandled in the native function or any of the JS functions it called.  Hence, there was some stack unwinding action happening prior to getting here, and the frame that we stopped unwinding on is the native frame and it did not handle and clear the exception in the VM.  What this piece of code is suppose to do is to continue the unwinding process from the caller of the native frame.

The reason I added this comment was to provide some context of what happened before, and where we need to pick up the unwinding work.  Is this not adequate as a reason to have this comment?

> Even that is not a great comment, since it doesn't explain *why*. Why does _llint_throw_from_native_call need us to pop the host function stack frame? I'm not sure.

The exception handling mechanism that unwinds the stack will stop unwinding when it sees a native / host function frame.  Just to clarify, are you suggesting that _llint_throw_from_native_call should do the work of popping off the host frame?

Actually looking at the implementation of _llint_throw_from_native_call, I see that it is a useless function that only asserts that VM::m_exception is not null.  But the only way we could possibly reach this code path is if VM::m_exception is not null.  Hence, _llint_throw_from_native_call should be removed altogether.

I'll clean that up, test it, and upload another patch for a follow up review.
Comment 5 Mark Lam 2013-12-13 02:18:47 PST
There appears to be a regression after I svn’ed up.  This patch is no longer adequate to make exception handling work for the LLINT.  I’m currently investigating the new issues.
Comment 6 Mark Lam 2013-12-13 09:48:16 PST
(In reply to comment #5)
> There appears to be a regression after I svn’ed up.  This patch is no longer adequate to make exception handling work for the LLINT.  I’m currently investigating the new issues.

Correction: the regression is not in the vicinity of the exception handling code.  Instead the following statement caused the crash I saw:

    print(“My object: “ + { });

I haven’t dug deeper yet, but it may have to do with Object.toString().  The issue is documented in https://bugs.webkit.org/show_bug.cgi?id=125694.

Continuing with exceptions work now.
Comment 7 Mark Lam 2013-12-13 12:43:24 PST
Created attachment 219181 [details]
patch 2: removed llint_throw_from_native_call.

I changed my mind about the comment in nativeCallTrampoline.  Without the now elided call to llint_throw_from_native_call, the exception handling section is much simpler and I don't think the comment is needed anymore.
Comment 8 Geoffrey Garen 2013-12-13 14:54:56 PST
Comment on attachment 219181 [details]
patch 2: removed llint_throw_from_native_call.

r=me
Comment 9 Mark Lam 2013-12-13 16:38:25 PST
Thanks for the review.  Landed in r160573 on the jsCStack branch: <http://trac.webkit.org/r160573>.