REOPENED 174714
Drop WTF::initializeDate, if we can stop using -fno-threadsafe-statics
https://bugs.webkit.org/show_bug.cgi?id=174714
Summary Drop WTF::initializeDate, if we can stop using -fno-threadsafe-statics
Yusuke Suzuki
Reported 2017-07-21 09:06:11 PDT
[WTF] Drop initializeDate
Attachments
Patch (2.64 KB, patch)
2017-07-21 09:07 PDT, Yusuke Suzuki
no flags
Yusuke Suzuki
Comment 1 2017-07-21 09:07:34 PDT
WebKit Commit Bot
Comment 2 2017-07-21 09:59:50 PDT
Comment on attachment 316092 [details] Patch Clearing flags on attachment: 316092 Committed r219732: <http://trac.webkit.org/changeset/219732>
WebKit Commit Bot
Comment 3 2017-07-21 09:59:51 PDT
All reviewed patches have been landed. Closing bug.
Alexey Proskuryakov
Comment 4 2017-07-21 10:49:42 PDT
Comment on attachment 316092 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=316092&action=review > Source/WTF/ChangeLog:8 > + minYear static variable will be initialized in an exclusive manner, which is ensured by C++ "static" semantics. Is that true? I thought we were compiling with no-threadsafe-statics.
Mark Lam
Comment 5 2017-07-21 10:51:25 PDT
(In reply to Alexey Proskuryakov from comment #4) > Comment on attachment 316092 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=316092&action=review > > > Source/WTF/ChangeLog:8 > > + minYear static variable will be initialized in an exclusive manner, which is ensured by C++ "static" semantics. > > Is that true? I thought we were compiling with no-threadsafe-statics. I think our NeverDestroyed implementation relies on threadsafe-statics. Otherwise, we'll have issues, no?
Yusuke Suzuki
Comment 6 2017-07-21 10:54:16 PDT
Comment on attachment 316092 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=316092&action=review >>> Source/WTF/ChangeLog:8 >>> + minYear static variable will be initialized in an exclusive manner, which is ensured by C++ "static" semantics. >> >> Is that true? I thought we were compiling with no-threadsafe-statics. > > I think our NeverDestroyed implementation relies on threadsafe-statics. Otherwise, we'll have issues, no? Right, if we compiled WebKit with no-threadsafe-statics, we should already encounter issues with NeverDestroyed. I remember that I grepped this a bit while ago, and I can't find any no-threadsafe-statics in WebKit build settings. Only libwebrtc uses it. But WebKit itself does not. I've grepped again now and I can't find it.
Darin Adler
Comment 7 2017-07-21 13:19:14 PDT
We do compile with no-threadsafe-statics. We only use initialization NeverDestroyed when thread safety is not needed.
Darin Adler
Comment 8 2017-07-21 13:19:42 PDT
Many of the uses of LazyNeverDestroyed that use std::call_once are for thread safety.
Darin Adler
Comment 9 2017-07-21 13:20:20 PDT
Maybe I am wrong. If we really stopped using -fno-threadsafe-statics, then I can do another round of cleanup and get rid of almost all uses of LazyNeverDestroyed!
Alexey Proskuryakov
Comment 10 2017-07-21 16:17:33 PDT
WebKit is built with -fno-threadsafe-statics. Perhaps there is some configuration that enables that, but all that I checked do not. See e.g. https://build.webkit.org/builders/Apple%20Sierra%20Release%20%28Build%29/builds/3721/steps/compile-webkit/logs/stdio
Alexey Proskuryakov
Comment 11 2017-07-21 16:22:17 PDT
Checking wtf/DateMath.cpp specifically, it is also compiled with -fno-threadsafe-statics.
Darin Adler
Comment 12 2017-07-21 21:47:09 PDT
So did we create a thread safety problem or not? Can equivalentYearForDST be called from multiple threads?
Darin Adler
Comment 13 2017-07-21 21:47:40 PDT
I think we did, and I think this patch probably needs to be rolled out.
Yusuke Suzuki
Comment 14 2017-07-21 22:09:54 PDT
(In reply to Darin Adler from comment #7) > We do compile with no-threadsafe-statics. > > We only use initialization NeverDestroyed when thread safety is not needed. I think we have a problem. I remember that Mark changed NeverDestroyed<String>'s ASCIILiteral parameter to StaticStringImpl because this is not safe to access NeverDestroyed<String>. It means that some of NeverDestroyed<String> can be accessed from multiple threads. If so, without threadsafe statics, it is dangerous. I think we will see 1. constructor is called twice, it may break structure during the other thread uses it. 2. we may return half-baked structure if the other thread is constructing it right now. (In reply to Alexey Proskuryakov from comment #10) > WebKit is built with -fno-threadsafe-statics. Perhaps there is some > configuration that enables that, but all that I checked do not. > > See e.g. > https://build.webkit.org/builders/Apple%20Sierra%20Release%20%28Build%29/ > builds/3721/steps/compile-webkit/logs/stdio Wow, that's a problem! I didn't know that this is enabled since any xcodeproje does not specify it. We should adopt this option in CMake build files as well to clarify our build configuration. Filed. https://bugs.webkit.org/show_bug.cgi?id=174747 (In reply to Darin Adler from comment #13) > I think we did, and I think this patch probably needs to be rolled out. Yes, we should roll out.
WebKit Commit Bot
Comment 15 2017-07-21 22:11:35 PDT
Re-opened since this is blocked by bug 174748
Yusuke Suzuki
Comment 16 2017-07-21 22:35:30 PDT
For example, I think JSC/runtime/JSGlobalObjectFunctions.cpp's Bitmaps are racy if threadsafe statics is not ensured.
Darin Adler
Comment 17 2017-07-22 10:35:28 PDT
To make our programming easier we can start compiling all of WebKit with thread-safe statics if we can do performance tests and prove that it does not come at an unacceptable performance cost. At the time we originally turned that flag on it was critical for performance. Until then if we accidentally write code with thread safety problems then we should rewrite to avoid those problems.
Note You need to log in before you can comment on or make changes to this bug.