Bug 211264 - Introduce MainThreadNeverDestroyed / MainThreadLazyNeverDestroyed
Summary: Introduce MainThreadNeverDestroyed / MainThreadLazyNeverDestroyed
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Yusuke Suzuki
URL:
Keywords: InRadar
Depends on: 211355
Blocks:
  Show dependency treegraph
 
Reported: 2020-04-30 16:18 PDT by Yusuke Suzuki
Modified: 2020-05-03 21:11 PDT (History)
40 users (show)

See Also:


Attachments
Patch (162.49 KB, patch)
2020-04-30 19:06 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (162.50 KB, patch)
2020-04-30 19:10 PDT, Yusuke Suzuki
mark.lam: review+
Details | Formatted Diff | Diff
Patch (141.49 KB, patch)
2020-04-30 19:47 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (141.71 KB, patch)
2020-04-30 20:02 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (141.93 KB, patch)
2020-04-30 20:26 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (142.03 KB, patch)
2020-04-30 20:48 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (142.12 KB, patch)
2020-05-01 01:42 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (142.13 KB, patch)
2020-05-01 09:50 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yusuke Suzuki 2020-04-30 16:18:38 PDT
They ensure that access and construction are done in the main thread.
Comment 1 Yusuke Suzuki 2020-04-30 19:06:25 PDT
Created attachment 398139 [details]
Patch
Comment 2 Yusuke Suzuki 2020-04-30 19:10:44 PDT
Created attachment 398141 [details]
Patch
Comment 3 Mark Lam 2020-04-30 19:24:50 PDT
Comment on attachment 398141 [details]
Patch

r=me.
Comment 4 Fujii Hironori 2020-04-30 19:35:00 PDT
Comment on attachment 398141 [details]
Patch

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

> Source/WebCore/html/InputTypeNames.cpp:37
>      return name;

It seems enough to just add ASSERT(isMainThread()).
What't the difference?
The return type of this function is just AtomString, not MainThreadNeverDestroyed<const AtomString>.
Comment 5 Yusuke Suzuki 2020-04-30 19:42:53 PDT
Comment on attachment 398141 [details]
Patch

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

>> Source/WebCore/html/InputTypeNames.cpp:37
>>      return name;
> 
> It seems enough to just add ASSERT(isMainThread()).
> What't the difference?
> The return type of this function is just AtomString, not MainThreadNeverDestroyed<const AtomString>.

MainThreadNeverDestroyed declaratively says that this should be accessed from the main thread. And `ASSERT(isMainThread())` is automatically inserted by MainThreadNeverDestroyed, instead of manually inserting it to every places. So I think this prevents us from using AtomString from the main thread accidentally, and this tells good thread-affinity information to readers of the code explicitly :)
Comment 6 Yusuke Suzuki 2020-04-30 19:47:02 PDT
Created attachment 398146 [details]
Patch

Patch for landing, resolved Saam's comment
Comment 7 Yusuke Suzuki 2020-04-30 20:02:52 PDT
Created attachment 398148 [details]
Patch

Patch for landing, resolved Saam's comment
Comment 8 Yusuke Suzuki 2020-04-30 20:26:31 PDT
Created attachment 398152 [details]
Patch

Patch for landing, resolved Saam's comment
Comment 9 Yusuke Suzuki 2020-04-30 20:48:37 PDT
Created attachment 398155 [details]
Patch

Patch for landing, fixing iOS build
Comment 10 Yusuke Suzuki 2020-05-01 01:34:54 PDT
Comment on attachment 398155 [details]
Patch

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

> Source/WTF/wtf/text/AtomString.cpp:137
> +WTF_EXPORT_PRIVATE MainThreadLazyNeverDestroyed<const AtomString> nullAtomData;
> +WTF_EXPORT_PRIVATE MainThreadLazyNeverDestroyed<const AtomString> emptyAtomData;

Crash looks like due to nullAtom and emptyAtom. But they are specially OK Atoms since those definitions are the same and can be shared between multiple threads (since they are not actually registered in AtomStringTable).
I'll slightly modify to handle them specially (just using LazyNeverDestroyed<>) to see the results.
Comment 11 Yusuke Suzuki 2020-05-01 01:42:15 PDT
Created attachment 398168 [details]
Patch

Patch for landing, fixing Windows builds and Debug crash due to nullAtom & emptyAtom
Comment 12 Yusuke Suzuki 2020-05-01 09:50:27 PDT
Created attachment 398192 [details]
Patch

Patch for landing, fixing Windows builds and Debug crash due to nullAtom & emptyAtom
Comment 13 Yusuke Suzuki 2020-05-01 12:47:47 PDT
Committed r261013: <https://trac.webkit.org/changeset/261013>
Comment 14 Radar WebKit Bug Importer 2020-05-01 12:48:17 PDT
<rdar://problem/62742993>