Bug 194419 - [JSC] Shrink sizeof(CodeBlock) more
Summary: [JSC] Shrink sizeof(CodeBlock) more
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: 2019-02-07 16:28 PST by Yusuke Suzuki
Modified: 2019-02-09 12:13 PST (History)
7 users (show)

See Also:


Attachments
Patch (84.86 KB, patch)
2019-02-07 16:35 PST, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (84.85 KB, patch)
2019-02-07 17:47 PST, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (86.22 KB, patch)
2019-02-07 18:08 PST, Yusuke Suzuki
mark.lam: 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 2019-02-07 16:28:51 PST
[JSC] Shrink sizeof(CodeBlock) more
Comment 1 Yusuke Suzuki 2019-02-07 16:35:53 PST
Created attachment 361469 [details]
Patch
Comment 2 EWS Watchlist 2019-02-07 16:41:38 PST
Attachment 361469 [details] did not pass style-queue:


ERROR: Source/JavaScriptCore/ChangeLog:94:  Please consider whether the use of security-sensitive phrasing could help someone exploit WebKit: fuzzing  [changelog/unwantedsecurityterms] [3]
Total errors found: 1 in 37 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 Yusuke Suzuki 2019-02-07 17:47:40 PST
Created attachment 361477 [details]
Patch
Comment 4 EWS Watchlist 2019-02-07 17:49:25 PST
Attachment 361477 [details] did not pass style-queue:


ERROR: Source/JavaScriptCore/ChangeLog:94:  Please consider whether the use of security-sensitive phrasing could help someone exploit WebKit: fuzzing  [changelog/unwantedsecurityterms] [3]
Total errors found: 1 in 37 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 5 Yusuke Suzuki 2019-02-07 18:08:25 PST
Created attachment 361482 [details]
Patch
Comment 6 EWS Watchlist 2019-02-07 18:10:27 PST
Attachment 361482 [details] did not pass style-queue:


ERROR: Source/JavaScriptCore/ChangeLog:94:  Please consider whether the use of security-sensitive phrasing could help someone exploit WebKit: fuzzing  [changelog/unwantedsecurityterms] [3]
ERROR: Source/WebCore/ChangeLog:8:  You should remove the 'No new tests' and either add and list tests, or explain why no new tests were possible.  [changelog/nonewtests] [5]
Total errors found: 2 in 39 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 7 Mark Lam 2019-02-08 15:34:22 PST
Comment on attachment 361482 [details]
Patch

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

Very nice.  r=me with suggestions.

> Source/JavaScriptCore/bytecode/CodeBlock.cpp:526
> -    for (const auto& instruction : *m_instructions) {
> +    for (const auto& instruction : instructions()) {

Pre-cache instructions() in a local before the loop so that the compiler knows that it won't change on each iteration.

> Source/JavaScriptCore/bytecode/CodeBlock.cpp:1074
> +            auto instruction = instructions().at(propertyAccessInstructions[i]);

Precache instructions in a local before loop.

> Source/JavaScriptCore/bytecode/CodeBlock.cpp:1204
> +        const auto curInstruction = instructions().at(propertyAccessInstructions[i]);

Precache instructions in a local before loop.

> Source/JavaScriptCore/bytecode/CodeBlock.cpp:1711
> +    auto instruction = instructions().at(bytecodeOffset);

Use auto& to make is explicit at a glance that this is a reference.

> Source/JavaScriptCore/bytecode/CodeBlock.cpp:1816
> +    for (const auto& it : instructions()) {

Precache instructions in a local before loop.

> Source/JavaScriptCore/bytecode/CodeBlock.cpp:2755
> +    for (const auto& instruction : instructions()) {

Precache instructions in a local before loop.

> Source/JavaScriptCore/bytecode/CodeBlock.cpp:2944
> +    for (const auto& instruction : instructions()) {

Precache instructions in a local before loop.
Comment 8 Yusuke Suzuki 2019-02-08 16:18:31 PST
Comment on attachment 361482 [details]
Patch

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

Thank you!

>> Source/JavaScriptCore/bytecode/CodeBlock.cpp:526
>> +    for (const auto& instruction : instructions()) {
> 
> Pre-cache instructions() in a local before the loop so that the compiler knows that it won't change on each iteration.

Fixed.

>> Source/JavaScriptCore/bytecode/CodeBlock.cpp:1074
>> +            auto instruction = instructions().at(propertyAccessInstructions[i]);
> 
> Precache instructions in a local before loop.

Fixed.

>> Source/JavaScriptCore/bytecode/CodeBlock.cpp:1204
>> +        const auto curInstruction = instructions().at(propertyAccessInstructions[i]);
> 
> Precache instructions in a local before loop.

Fixed.

>> Source/JavaScriptCore/bytecode/CodeBlock.cpp:1711
>> +    auto instruction = instructions().at(bytecodeOffset);
> 
> Use auto& to make is explicit at a glance that this is a reference.

Fixed.

>> Source/JavaScriptCore/bytecode/CodeBlock.cpp:1816
>> +    for (const auto& it : instructions()) {
> 
> Precache instructions in a local before loop.

Fixed.

>> Source/JavaScriptCore/bytecode/CodeBlock.cpp:2755
>> +    for (const auto& instruction : instructions()) {
> 
> Precache instructions in a local before loop.

Fixed.

>> Source/JavaScriptCore/bytecode/CodeBlock.cpp:2944
>> +    for (const auto& instruction : instructions()) {
> 
> Precache instructions in a local before loop.

Fixed.
Comment 9 Yusuke Suzuki 2019-02-08 16:29:31 PST
Committed r241222: <https://trac.webkit.org/changeset/241222>
Comment 10 Radar WebKit Bug Importer 2019-02-08 16:30:38 PST
<rdar://problem/47934328>
Comment 11 Darin Adler 2019-02-09 12:13:18 PST
Comment on attachment 361482 [details]
Patch

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

>>> Source/JavaScriptCore/bytecode/CodeBlock.cpp:526
>>> +    for (const auto& instruction : instructions()) {
>> 
>> Pre-cache instructions() in a local before the loop so that the compiler knows that it won't change on each iteration.
> 
> Fixed.

While it’s OK to do this if you prefer it from a stylistic point of view, there is no need to change it for correct behavior. The way a range for loop is defined, the compiler will not and must not call instructions() more than once. An example of an on-line reference that makes this clear is <https://en.cppreference.com/w/cpp/language/range-for>.