Bug 177056 - [DFG] Remove ToThis more aggressively
Summary: [DFG] Remove ToThis more aggressively
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Yusuke Suzuki
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2017-09-17 10:22 PDT by Yusuke Suzuki
Modified: 2017-09-27 12:25 PDT (History)
7 users (show)

See Also:


Attachments
Patch (28.82 KB, patch)
2017-09-17 11:34 PDT, Yusuke Suzuki
saam: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yusuke Suzuki 2017-09-17 10:22:00 PDT
ToThis is rarely overridden. And toThis functions are very limited. We can check toThis function in AI and perform appropriate folding.
Comment 1 Yusuke Suzuki 2017-09-17 11:34:05 PDT
Created attachment 321048 [details]
Patch
Comment 2 Saam Barati 2017-09-17 16:14:03 PDT
Comment on attachment 321048 [details]
Patch

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

r=me

Can you also add a test where we change globalThisValue after we've already compiled the code, that way we ensure that we're not trying to completely constant fold the result of GetGlobalThis?

> Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h:174
> +        bool allStructureIsScope = !valueForNode.m_structure.isClear();

let's name this: allStructuresAreScope or allStructuresAreJSScope

> Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h:188
> +            if (!(type.isObject() && type.overridesToThis() && structure->classInfo()->methodTable.toThis == JSScope::info()->methodTable.toThis))

Why the three conditions? Doesn't (structure->classInfo()->methodTable.toThis == JSScope::info()->methodTable.toThis) suffice for your needs?
I'd maybe just write this:
``allStructuresAreScope &= structure->classInfo()->methodTable.toThis == JSScope::info()->methodTable.toThis``
Comment 3 Yusuke Suzuki 2017-09-18 05:43:41 PDT
Comment on attachment 321048 [details]
Patch

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

I think testing it is difficult... Currently, we have two chances to see this issue,

1. JSC APIs

JSC APIs allows us to resetPrototype, which changes GlobalThis.

2. Touching JSGlobalObject in DFG before calling finishCreation()

If JSGlobalObject's initialization / JSDOMGlobalObject (and other childrens) invoke DFG in its initialization sequence, we may see that globalThis with nullptr.

I think testing them is difficult. I think (1) should be removed because JSGlobalObject is now immutable prototype exotic object.
And seconds thing relies on initialization of JSGlobalObject (and children).

I don't think we should restrict DFG invocation in JSGlobalObject initialization: it is useful to use JS things if some critical part of JSGlobalObject is initialized. Currently, globalThis is set after all the initialization finishes.

We eventually want to remove this replacing globalThis feature from JSC.

>> Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h:174
>> +        bool allStructureIsScope = !valueForNode.m_structure.isClear();
> 
> let's name this: allStructuresAreScope or allStructuresAreJSScope

Changed it to allStructuresAreJSScope.

>> Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h:188
>> +            if (!(type.isObject() && type.overridesToThis() && structure->classInfo()->methodTable.toThis == JSScope::info()->methodTable.toThis))
> 
> Why the three conditions? Doesn't (structure->classInfo()->methodTable.toThis == JSScope::info()->methodTable.toThis) suffice for your needs?
> I'd maybe just write this:
> ``allStructuresAreScope &= structure->classInfo()->methodTable.toThis == JSScope::info()->methodTable.toThis``

Oh, nice. Fixed.
Comment 4 Yusuke Suzuki 2017-09-18 05:47:38 PDT
Committed r222143: <http://trac.webkit.org/changeset/222143>
Comment 5 Radar WebKit Bug Importer 2017-09-27 12:25:27 PDT
<rdar://problem/34693252>