Bug 144176

Summary: Function allocation sinking works for wrong reasons
Product: WebKit Reporter: Basile Clement <basile_clement>
Component: JavaScriptCoreAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, fpizlo, ggaren, mark.lam, msaboff
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Should do the right thing
none
Seems to be doing the right thing
none
Seems to be doing the right thing
fpizlo: review-
MaterializeNewObject is also sinkable...
fpizlo: review+, fpizlo: commit-queue+
Remove spurious MustGenerate none

Description Basile Clement 2015-04-24 17:42:52 PDT
It is by design that we don't support sinking of function allocation through any related operations.
Object allocation, however, does sink through field assignment (PutByOffset etc.), so we have a check that is supposed to prevent function allocations from sinking through these.

However that check is misguided and (a) do not prevent function allocation sinking through field assignment and (b) ensures that if a function allocation ever sinks through a PutByOffset, very bad things happen instead.
Fortunately, PutByOffset (and their relatives) require first allocating a custom structure for the JSFunction object, thus the PutByOffset will always be preceded by an AllocatePropertyStorage through which no allocation can sink, and materialization would always be triggered before the PutByOffset - so this works by chance.

Anyway, this should be done the proper way, and I will submit a patch soon to prevent properly have checks preventing function allocation sinking through PutByOffset et al.
Comment 1 Basile Clement 2015-04-24 18:01:54 PDT
Created attachment 251602 [details]
Should do the right thing

Compiles, but untested - will check my understanding of the nodes is correct and does not prevent valid object allocation sinking and add a ChangeLog entry on Monday.
Comment 2 Basile Clement 2015-04-27 11:57:32 PDT
Created attachment 251763 [details]
Seems to be doing the right thing
Comment 3 Basile Clement 2015-04-27 12:06:42 PDT
Created attachment 251764 [details]
Seems to be doing the right thing
Comment 4 Basile Clement 2015-04-27 12:08:50 PDT
Comment on attachment 251764 [details]
Seems to be doing the right thing

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

> Source/JavaScriptCore/dfg/DFGObjectAllocationSinkingPhase.cpp:812
> +            if (target->op() != NewObject)

Unsure if I should add a helper function in DFG::Node for that...
Comment 5 Filip Pizlo 2015-04-27 12:10:00 PDT
You should rebase :-)
Comment 6 Filip Pizlo 2015-04-27 12:11:57 PDT
Comment on attachment 251764 [details]
Seems to be doing the right thing

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

>> Source/JavaScriptCore/dfg/DFGObjectAllocationSinkingPhase.cpp:812
>> +            if (target->op() != NewObject)
> 
> Unsure if I should add a helper function in DFG::Node for that...

Seems wrong - MaterializeNewObject is also a sink candidate.
Comment 7 Basile Clement 2015-04-27 12:17:05 PDT
(In reply to comment #6)
> Comment on attachment 251764 [details]
> Seems to be doing the right thing
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=251764&action=review
> 
> >> Source/JavaScriptCore/dfg/DFGObjectAllocationSinkingPhase.cpp:812
> >> +            if (target->op() != NewObject)
> > 
> > Unsure if I should add a helper function in DFG::Node for that...
> 
> Seems wrong - MaterializeNewObject is also a sink candidate.

Oh, duh, indeed. Fixing that, w/ a helper function then.
Comment 8 Basile Clement 2015-04-27 12:29:31 PDT
Created attachment 251768 [details]
MaterializeNewObject is also sinkable...
Comment 9 Basile Clement 2015-04-27 12:40:07 PDT
Sorry, should have tried a clean build.
Comment 10 Basile Clement 2015-04-27 12:47:34 PDT
Created attachment 251771 [details]
Remove spurious MustGenerate
Comment 11 WebKit Commit Bot 2015-04-27 13:43:41 PDT
Comment on attachment 251771 [details]
Remove spurious MustGenerate

Clearing flags on attachment: 251771

Committed r183419: <http://trac.webkit.org/changeset/183419>
Comment 12 WebKit Commit Bot 2015-04-27 13:43:45 PDT
All reviewed patches have been landed.  Closing bug.