Bug 194824 - Code quality cleanup in NeverDestroyed
Summary: Code quality cleanup in NeverDestroyed
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: Keith Miller
URL:
Keywords: InRadar
Depends on: 194833
Blocks:
  Show dependency treegraph
 
Reported: 2019-02-19 11:55 PST by Keith Miller
Modified: 2019-03-03 11:58 PST (History)
14 users (show)

See Also:


Attachments
Patch (4.18 KB, patch)
2019-02-19 11:58 PST, Keith Miller
no flags Details | Formatted Diff | Diff
Patch for landing (4.01 KB, patch)
2019-02-19 12:08 PST, Keith Miller
no flags Details | Formatted Diff | Diff
Patch for landing (3.92 KB, patch)
2019-02-19 12:08 PST, Keith Miller
no flags Details | Formatted Diff | Diff
Patch (5.29 KB, patch)
2019-02-22 12:02 PST, Keith Miller
no flags Details | Formatted Diff | Diff
Patch (5.96 KB, patch)
2019-02-22 12:12 PST, Keith Miller
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Keith Miller 2019-02-19 11:55:45 PST
Code quality cleanup in NeverDestroyed
Comment 1 Keith Miller 2019-02-19 11:58:11 PST
Created attachment 362406 [details]
Patch
Comment 2 Yusuke Suzuki 2019-02-19 11:59:19 PST
Comment on attachment 362406 [details]
Patch

r=me
Comment 3 Keith Miller 2019-02-19 12:07:36 PST
Comment on attachment 362406 [details]
Patch

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

> Source/WTF/wtf/NeverDestroyed.h:137
> -    // LazyNeverDestroyed objects are always static, so this variable is initialized to false.
> -    // It must not be initialized dynamically; that would not be thread safe.
> -    bool m_isConstructed;
> +    bool m_isConstructed { false };

Nvm, this triggers the global constructor error to fire. We can't do this.
Comment 4 Keith Miller 2019-02-19 12:08:04 PST
Created attachment 362409 [details]
Patch for landing
Comment 5 Keith Miller 2019-02-19 12:08:31 PST
Created attachment 362410 [details]
Patch for landing
Comment 6 WebKit Commit Bot 2019-02-19 12:45:58 PST
Comment on attachment 362410 [details]
Patch for landing

Clearing flags on attachment: 362410

Committed r241770: <https://trac.webkit.org/changeset/241770>
Comment 7 WebKit Commit Bot 2019-02-19 12:45:59 PST
All reviewed patches have been landed.  Closing bug.
Comment 8 Radar WebKit Bug Importer 2019-02-19 12:52:47 PST
<rdar://problem/48211208>
Comment 9 Simon Fraser (smfr) 2019-02-19 15:09:24 PST
This caused a bunch of crashes: https://build.webkit.org/results/Apple%20High%20Sierra%20Debug%20WK1%20(Tests)/r241770%20(7858)/results.html

Rolling out
Comment 10 Keith Miller 2019-02-22 12:02:14 PST
Created attachment 362740 [details]
Patch
Comment 11 Keith Miller 2019-02-22 12:11:21 PST
Turns out the bug was that make_names.pl was just reinterpret_casting LazyNeverDestroyed to the type it holds... Not ideal. So I fixed that.
Comment 12 Keith Miller 2019-02-22 12:12:03 PST
Created attachment 362741 [details]
Patch
Comment 13 Mark Lam 2019-02-26 16:31:44 PST
Comment on attachment 362741 [details]
Patch

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

r=me

> Source/WTF/wtf/NeverDestroyed.h:78
> +    // FIXME: Investigate whether we should allocate a hunk of virtual memory

/hunk/chunk/?

> Source/WTF/wtf/NeverDestroyed.h:142
> +    // FIXME: Investigate whether we should allocate a hunk of virtual memory

/hunk/chunk/?
Comment 14 Keith Miller 2019-02-26 16:33:43 PST
Comment on attachment 362741 [details]
Patch

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

>> Source/WTF/wtf/NeverDestroyed.h:142
>> +    // FIXME: Investigate whether we should allocate a hunk of virtual memory
> 
> /hunk/chunk/?

Dunno, I just moved it.
Comment 15 WebKit Commit Bot 2019-02-26 16:59:55 PST
Comment on attachment 362741 [details]
Patch

Clearing flags on attachment: 362741

Committed r242116: <https://trac.webkit.org/changeset/242116>
Comment 16 WebKit Commit Bot 2019-02-26 16:59:57 PST
All reviewed patches have been landed.  Closing bug.
Comment 17 Darin Adler 2019-03-03 00:45:30 PST
Comment on attachment 362741 [details]
Patch

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

> Source/WebCore/dom/make_names.pl:776
> -            print F "        reinterpret_cast<const WebCore::$parameters{namespace}QualifiedName*>(&${name}Tag),\n";
> +            print F "        &${name}Tag.get(),\n";

I think this was done so that the tables would be generated as read-only data rather than a long sequence of inlined code that initializes the tables. I suspect this change removes that optimization. Could you check? I know it might be inelegant, but I believe it made a substantial difference in code size.
Comment 18 Keith Miller 2019-03-03 11:48:52 PST
(In reply to Darin Adler from comment #17)
> Comment on attachment 362741 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=362741&action=review
> 
> > Source/WebCore/dom/make_names.pl:776
> > -            print F "        reinterpret_cast<const WebCore::$parameters{namespace}QualifiedName*>(&${name}Tag),\n";
> > +            print F "        &${name}Tag.get(),\n";
> 
> I think this was done so that the tables would be generated as read-only
> data rather than a long sequence of inlined code that initializes the
> tables. I suspect this change removes that optimization. Could you check? I
> know it might be inelegant, but I believe it made a substantial difference
> in code size.

Ah that’s a fair point there should probably be a comment about that. Is there any reason the tables can’t be a NeverDestroyed<std::array<>>? That seems like it would solve both problems.
Comment 19 Darin Adler 2019-03-03 11:58:21 PST
(In reply to Keith Miller from comment #18)
> Is there any reason the tables can’t be a NeverDestroyed<std::array<>>?
> That seems like it would solve both problems.

I don’t understand how std::array would help. The issue is whether this ends being data fixed up by the linker with no code, or code run the first time the function is run. Maybe std::array will help.