Bug 211264

Summary: Introduce MainThreadNeverDestroyed / MainThreadLazyNeverDestroyed
Product: WebKit Reporter: Yusuke Suzuki <ysuzuki>
Component: DOMAssignee: Yusuke Suzuki <ysuzuki>
Status: RESOLVED FIXED    
Severity: Normal CC: aboxhall, annulen, apinheiro, benjamin, calvaris, cdumez, cfleizach, cmarcelo, dino, dmazzoni, dstockwell, eric.carlson, esprehn+autocc, ews-watchlist, fmalita, glenn, gyuyoung.kim, Hironori.Fujii, hta, japhet, jcraig, jdiggs, jer.noble, kangil.han, kondapallykalyan, luiz, mark.lam, mifenton, mmaxfield, noam, pdr, philipj, ryuan.choi, sabouhallawa, samuel_white, schenney, sergio, simon.fraser, tommyw, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=211365
Bug Depends on: 211355    
Bug Blocks:    
Attachments:
Description Flags
Patch
none
Patch
mark.lam: review+
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch none

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>