Bug 157358 - [JSC] In DFG, an OSR Exit on SetLocal can trash its child node
Summary: [JSC] In DFG, an OSR Exit on SetLocal can trash its child node
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Benjamin Poulain
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-05-04 15:06 PDT by Benjamin Poulain
Modified: 2016-05-06 17:14 PDT (History)
8 users (show)

See Also:


Attachments
Patch (4.87 KB, patch)
2016-05-04 15:12 PDT, Benjamin Poulain
no flags Details | Formatted Diff | Diff
Patch (8.66 KB, patch)
2016-05-04 17:55 PDT, Benjamin Poulain
no flags Details | Formatted Diff | Diff
Patch for landing (8.60 KB, patch)
2016-05-05 14:59 PDT, Benjamin Poulain
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Benjamin Poulain 2016-05-04 15:06:29 PDT
[JSC] In DFG, an OSR Exit on SetLocal can trash its child node
Comment 1 Benjamin Poulain 2016-05-04 15:12:20 PDT
Created attachment 278130 [details]
Patch
Comment 2 Filip Pizlo 2016-05-04 15:16:22 PDT
Comment on attachment 278130 [details]
Patch

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

> Source/JavaScriptCore/ChangeLog:22
> +            @1 = SomethingProducingDouble()
> +            @2 = MovHint(@1)
> +            @3 = ValueRep(@1)
> +            @4 = SetLocal(@3, FlushedInt32)
> +
> +        When we lower SetLocal(), we start by speculating that @3 is an Int32.
> +        Now this can fail if @1 was really a double.
> +        When that happens, we go over the VariableEventStream to find where values
> +        are, and @1 died at @3. Since the speculation failure happens before
> +        the SetLocal event, we don't do anything with @3.

The bug is that the PhantomInsertionPhase didn't put a Phantom for @1 immediately after @4.  Do you know why it did that?

> Source/JavaScriptCore/dfg/DFGSpeculativeJIT64.cpp:2109
> +        Node* child = node->child1().node();
> +        noticeOSRBirth(child);
> +        m_stream->appendAndLog(VariableEvent::movHint(MinifiedID(child), node->local()));

I think that this is just wrong.  I see what you're trying to do, but SetLocal isn't supposed to have this kind of power.  The DFG should be getting the value that was MovHinted.
Comment 3 Benjamin Poulain 2016-05-04 17:55:05 PDT
Created attachment 278149 [details]
Patch
Comment 4 Benjamin Poulain 2016-05-04 17:58:06 PDT
I took a bit of a shortcut here: instead of querying if the Local is really killed after the current bytecode index, I assumed the local is always killed from SetLocal. I did that because it is cheaper than iterating until the next origin and getting the live locals there.
Comment 5 Filip Pizlo 2016-05-04 19:52:12 PDT
Comment on attachment 278149 [details]
Patch

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

A bit ugly, but it looks right.  Damn that's a tricky corner case!

> Source/JavaScriptCore/dfg/DFGPhantomInsertionPhase.cpp:142
> +            auto processKilledOperand = [&] (VirtualRegister reg)
> +            {

I think that our style is to put the { on the same line as the lambda variable.  The style bot complains about this because it does not understand lambdas.  But, this is the style that I have followed, because that's what I saw elsewhere in WK when I first started using them.  So, let's go with that style.
Comment 6 Benjamin Poulain 2016-05-05 14:59:31 PDT
Created attachment 278192 [details]
Patch for landing
Comment 7 WebKit Commit Bot 2016-05-05 16:11:01 PDT
The commit-queue encountered the following flaky tests while processing attachment 278192 [details]:

The commit-queue is continuing to process your patch.
Comment 8 WebKit Commit Bot 2016-05-05 16:11:38 PDT
The commit-queue encountered the following flaky tests while processing attachment 278192 [details]:

transitions/default-timing-function.html bug 138901 (author: simon.fraser@apple.com)
The commit-queue is continuing to process your patch.
Comment 9 WebKit Commit Bot 2016-05-05 17:04:28 PDT
Comment on attachment 278192 [details]
Patch for landing

Clearing flags on attachment: 278192

Committed r200498: <http://trac.webkit.org/changeset/200498>
Comment 10 WebKit Commit Bot 2016-05-05 17:04:33 PDT
All reviewed patches have been landed.  Closing bug.
Comment 11 Csaba Osztrogonác 2016-05-06 02:18:11 PDT
(In reply to comment #9)
> Comment on attachment 278192 [details]
> Patch for landing
> 
> Clearing flags on attachment: 278192
> 
> Committed r200498: <http://trac.webkit.org/changeset/200498>

It made stress/tagged-templates-template-object.js assert
on Apple Mac x86 32-bit debug bots:
- https://build.webkit.org/builders/Apple%20Yosemite%2032-bit%20JSC%20%28BuildAndTest%29/builds/9046
- https://build.webkit.org/builders/Apple%20El%20Capitan%2032-bit%20JSC%20%28BuildAndTest%29/builds/2305
Comment 12 Benjamin Poulain 2016-05-06 15:46:32 PDT
I'll have a look.
Comment 13 Benjamin Poulain 2016-05-06 17:14:55 PDT
(In reply to comment #12)
> I'll have a look.

The fix is here: https://bugs.webkit.org/show_bug.cgi?id=157436