Bug 224715 - [JSC] Do not use Bag<> for DFG / FTL watchpoints
Summary: [JSC] Do not use Bag<> for DFG / FTL watchpoints
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: Yusuke Suzuki
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-04-17 01:07 PDT by Yusuke Suzuki
Modified: 2021-04-19 22:07 PDT (History)
8 users (show)

See Also:


Attachments
Patch (27.76 KB, patch)
2021-04-17 01:07 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (33.11 KB, patch)
2021-04-17 01:29 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (34.11 KB, patch)
2021-04-17 01:47 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (34.28 KB, patch)
2021-04-17 01:56 PDT, Yusuke Suzuki
darin: 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 2021-04-17 01:07:10 PDT
[JSC] Do not use Bag<> for DFG / FTL watchpoints
Comment 1 Yusuke Suzuki 2021-04-17 01:07:23 PDT
Created attachment 426324 [details]
Patch
Comment 2 Yusuke Suzuki 2021-04-17 01:29:06 PDT
Created attachment 426325 [details]
Patch
Comment 3 Yusuke Suzuki 2021-04-17 01:47:30 PDT
Created attachment 426326 [details]
Patch
Comment 4 Yusuke Suzuki 2021-04-17 01:56:27 PDT
Created attachment 426327 [details]
Patch
Comment 5 Darin Adler 2021-04-17 15:59:00 PDT
Comment on attachment 426327 [details]
Patch

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

Title should say "for better memory efficiency" or something like that.

While I’m not a deep expert on this code, it looks right to me.

> Source/JavaScriptCore/bytecode/AdaptiveInferredPropertyValueWatchpointBase.cpp:43
> +AdaptiveInferredPropertyValueWatchpointBase::AdaptiveInferredPropertyValueWatchpointBase()
> +    : m_key()
> +{
> +}
> +

Why is this needed? Isn’t this what the default constructor would do if we just wrote "= default"?

> Source/JavaScriptCore/bytecode/CodeBlockJettisoningWatchpoint.h:45
> +    CodeBlockJettisoningWatchpoint()
> +        : CodeBlockJettisoningWatchpoint(nullptr)
> +    {
> +    }

We could achieve this more economically by just writing "CodeBlock* codeBlock = nullptr" in the other constructor.

> Source/JavaScriptCore/dfg/DFGAdaptiveInferredPropertyValueWatchpoint.cpp:46
> +AdaptiveInferredPropertyValueWatchpoint::AdaptiveInferredPropertyValueWatchpoint()
> +    : Base()
> +    , m_codeBlock(nullptr)
> +{
> +}

It would be more elegant to initialize m_codeBlock to nullptr in the header, and then use "= default" for this constructor.

> Source/JavaScriptCore/dfg/DFGAdaptiveStructureWatchpoint.cpp:47
> +    , m_codeBlock(nullptr)

Can we initialize m_codeBlock in the class definition, and then omit this line? Maybe not because of JSC_WATCHPOINT_FIELD?

> Source/JavaScriptCore/dfg/DFGAdaptiveStructureWatchpoint.cpp:48
> +    , m_key()

Can we omit this line? Pretty sure that this isn’t needed. Maybe not because of JSC_WATCHPOINT_FIELD?

> Source/JavaScriptCore/dfg/DFGCommonData.cpp:151
> +    for (AdaptiveStructureWatchpoint& watchpoint : m_adaptiveStructureWatchpoints)

I think code like this is more readable with auto& rather than writing out a type name. Using "auto&" documents that the type is correct and does not slice or upcast.

> Source/JavaScriptCore/dfg/DFGDesiredWatchpoints.h:49
> +    WatchpointCollector() = default;

I believe we can simply omit this entirely, and behavior should be the same.

> Source/JavaScriptCore/dfg/DFGDesiredWatchpoints.h:60
> +    template<typename Func>
> +    void addWatchpoint(const Func& func)

Could we use a word instead of "func"?
Comment 6 Yusuke Suzuki 2021-04-18 00:58:03 PDT
Comment on attachment 426327 [details]
Patch

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

Thanks

>> Source/JavaScriptCore/bytecode/AdaptiveInferredPropertyValueWatchpointBase.cpp:43
>> +
> 
> Why is this needed? Isn’t this what the default constructor would do if we just wrote "= default"?

Yeah, replaced with = default;

>> Source/JavaScriptCore/bytecode/CodeBlockJettisoningWatchpoint.h:45
>> +    }
> 
> We could achieve this more economically by just writing "CodeBlock* codeBlock = nullptr" in the other constructor.

Replaced.

>> Source/JavaScriptCore/dfg/DFGAdaptiveInferredPropertyValueWatchpoint.cpp:46
>> +}
> 
> It would be more elegant to initialize m_codeBlock to nullptr in the header, and then use "= default" for this constructor.

Replaced.

>> Source/JavaScriptCore/dfg/DFGAdaptiveStructureWatchpoint.cpp:47
>> +    , m_codeBlock(nullptr)
> 
> Can we initialize m_codeBlock in the class definition, and then omit this line? Maybe not because of JSC_WATCHPOINT_FIELD?

Unfortunately it is not since JSC_WATCHPOINT_FIELD.

>> Source/JavaScriptCore/dfg/DFGAdaptiveStructureWatchpoint.cpp:48
>> +    , m_key()
> 
> Can we omit this line? Pretty sure that this isn’t needed. Maybe not because of JSC_WATCHPOINT_FIELD?

Yes, we can omit it.

>> Source/JavaScriptCore/dfg/DFGCommonData.cpp:151
>> +    for (AdaptiveStructureWatchpoint& watchpoint : m_adaptiveStructureWatchpoints)
> 
> I think code like this is more readable with auto& rather than writing out a type name. Using "auto&" documents that the type is correct and does not slice or upcast.

Replaced.

>> Source/JavaScriptCore/dfg/DFGDesiredWatchpoints.h:49
>> +    WatchpointCollector() = default;
> 
> I believe we can simply omit this entirely, and behavior should be the same.

Removed.

>> Source/JavaScriptCore/dfg/DFGDesiredWatchpoints.h:60
>> +    void addWatchpoint(const Func& func)
> 
> Could we use a word instead of "func"?

Replaced with function.
Comment 7 Yusuke Suzuki 2021-04-18 01:06:59 PDT
Committed r276226 (236708@main): <https://commits.webkit.org/236708@main>
Comment 8 Yusuke Suzuki 2021-04-18 01:30:23 PDT
Comment on attachment 426327 [details]
Patch

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

>>> Source/JavaScriptCore/dfg/DFGDesiredWatchpoints.h:49
>>> +    WatchpointCollector() = default;
>> 
>> I believe we can simply omit this entirely, and behavior should be the same.
> 
> Removed.

Ah, this was important. If we are using WTF_MAKE_NONCOPYABLE, we need this. Otherwise, this becomes compile error.
Comment 9 Yusuke Suzuki 2021-04-18 01:35:39 PDT
Committed r276227 (236709@main): <https://commits.webkit.org/236709@main>
Comment 10 Ryan Haddad 2021-04-19 22:07:35 PDT
rdar://76810095