Bug 112769

Summary: HTMLNames local names should be thread-safe
Product: WebKit Reporter: Adam Barth <abarth>
Component: New BugsAssignee: Adam Barth <abarth>
Status: RESOLVED WONTFIX    
Severity: Normal CC: annevk, ap, benjamin, eric
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 112831    
Bug Blocks: 112303    
Attachments:
Description Flags
work in progress
none
work in progress
none
works in the Chromium port none

Adam Barth
Reported 2013-03-19 18:38:58 PDT
HTMLNames local names should be thread-safe
Attachments
work in progress (22.75 KB, patch)
2013-03-19 18:39 PDT, Adam Barth
no flags
work in progress (9.35 KB, patch)
2013-03-20 17:24 PDT, Adam Barth
no flags
works in the Chromium port (11.60 KB, patch)
2013-03-20 17:50 PDT, Adam Barth
no flags
Adam Barth
Comment 1 2013-03-19 18:39:32 PDT
Created attachment 193965 [details] work in progress
Adam Barth
Comment 2 2013-03-19 18:43:27 PDT
There's an interesting issue with using these StringImpls on background threads because the'll have their isAtomic bit set but won't be in the background thread's atomic string table.
Benjamin Poulain
Comment 3 2013-03-19 19:04:12 PDT
(In reply to comment #2) > There's an interesting issue with using these StringImpls on background threads because the'll have their isAtomic bit set but won't be in the background thread's atomic string table. Isn't that the case already today when you use the StringImpl in the Threaded Parser?
Benjamin Poulain
Comment 4 2013-03-19 19:28:18 PDT
Thinking about it. Wouldn't it be better if isAtomic() is always false on the static strings? The purpose of isAtomic is for destruction of the StringImpl (and a little shortcut on AtomicString creation). The first is irrelevant for static string, the second would be misleading.
Eric Seidel (no email)
Comment 5 2013-03-19 19:48:06 PDT
Yes. It does seem that "isAtomic" is really "shouldRemoveFromAtomicStringTableOnDestruction", and thus doesn't apply to static strings. We could make this explicit with some renamings of the functions. It's kinda ugly that this is all in StringImpl, but I completely understand why we do it this way. :)
Adam Barth
Comment 6 2013-03-19 20:45:42 PDT
> Isn't that the case already today when you use the StringImpl in the Threaded Parser? Yes, but that's something I'm considering whether we can improve with this patch. > Thinking about it. Wouldn't it be better if isAtomic() is always false on the static strings? That would mean that this operation would be slow: String foo = HTMLName::divTag; AtomicString bar = foo; because we'd need to do a hash lookup. > The purpose of isAtomic is for destruction of the StringImpl (and a little shortcut on AtomicString creation). The first is irrelevant for static string, the second would be misleading. That's true as this patch stands currently, but we should consider improving that situation. > Yes. It does seem that "isAtomic" is really "shouldRemoveFromAtomicStringTableOnDestruction", and thus doesn't apply to static strings. That's one thing the isAtomic bit is used for, but as Benjamin points out, there is another use for the bit. It's not clear to me whether we want static StringImpl objects to be able to be part of multiple AtomicStringTables. We don't need to resolve this question in this patch, so perhaps we should worry about making that decision in the future.
Benjamin Poulain
Comment 7 2013-03-19 21:25:16 PDT
> It's not clear to me whether we want static StringImpl objects to be able to be part of multiple AtomicStringTables. We don't need to resolve this question in this patch, so perhaps we should worry about making that decision in the future. I think we should still figure out a plan. I understand it is not strictly needed for your patch, but it would be good to have clear semantic from the beginning (and enforce it with assertions). > > Thinking about it. Wouldn't it be better if isAtomic() is always false on the static strings? > > That would mean that this operation would be slow: > > String foo = HTMLName::divTag; > AtomicString bar = foo; > > because we'd need to do a hash lookup. To a certain definition of "slow" yes :) It would be really easy to measure. Once your patch is done, could you check how often is this branch taken for the HTMLNames?
Benjamin Poulain
Comment 8 2013-03-19 21:29:12 PDT
Maybe it is simpler to split this in two? 1) Have the names setup at compile times. 2) Make them static and enforce one of the two options discussed.
Adam Barth
Comment 9 2013-03-19 22:20:24 PDT
Sure. Breaking this patch into smaller steps it a good idea.
Adam Barth
Comment 10 2013-03-20 13:24:37 PDT
The first step of this patch is in bug 112831.
Adam Barth
Comment 11 2013-03-20 17:24:56 PDT
Created attachment 194148 [details] work in progress
Adam Barth
Comment 12 2013-03-20 17:50:00 PDT
Created attachment 194153 [details] works in the Chromium port
Adam Barth
Comment 13 2013-03-20 17:54:02 PDT
There's some more port-specific work to do for this patch. We need to call WebCore::init early in the initialization process, before we've used any AtomicStrings, to ensure that the static versions of the strings are the ones that end up in the atomic string table. The good news is that we have an ASSERT that will catch when we screw this up. The bad news is that I'm not sure where to put the call to WebCore::init in all the ports. For WebKit2, WebProcess::initializeProcess looks like a tempting location. For non-WebKit2 ports, I have no clue. Any help in this regard would be appreciated.
Adam Barth
Comment 14 2013-03-20 17:55:38 PDT
Comment on attachment 194153 [details] works in the Chromium port View in context: https://bugs.webkit.org/attachment.cgi?id=194153&action=review > Source/WTF/wtf/text/StringStatics.cpp:87 > +void StringStatics::init() These probably should move to WebCore since they're specific to the web. > Source/WebKit/chromium/src/WebKit.cpp:149 > WTF::initializeThreading(); > WTF::initializeMainThread(); > - WTF::AtomicString::init(); > + WebCore::init(); Maybe I should look for where other ports call initializeThreading?
Anne van Kesteren
Comment 15 2023-12-25 10:06:10 PST
Threaded HTML parser was removed.
Note You need to log in before you can comment on or make changes to this bug.