Title: [293757] trunk/Source
Revision
293757
Author
[email protected]
Date
2022-05-03 19:27:25 -0700 (Tue, 03 May 2022)

Log Message

[JSC] Initialize empty and null AtomString at compile time
https://bugs.webkit.org/show_bug.cgi?id=240031

Reviewed by Mark Lam.

Because they are initialized from static data, we can just initialize them
at compile time, and we do not need to have `AtomString::init`.

* Source/WebKit/WebAuthnProcess/WebAuthnProcess.cpp:
(WebKit::WebAuthnProcess::initializeWebAuthnProcess):
* Source/WTF/wtf/Threading.cpp:
(WTF::initialize):
* Source/WTF/wtf/text/AtomString.cpp:
(WTF::AtomString::init): Deleted.
* Source/WTF/wtf/text/AtomString.h:
(WTF::StaticAtomString::StaticAtomString):
(WTF::nullAtom):
(WTF::emptyAtom):
* Source/WebCore/dom/make_names.pl:
(printInit):

Canonical link: https://commits.webkit.org/250236@main

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (293756 => 293757)


--- trunk/Source/WTF/ChangeLog	2022-05-04 01:44:49 UTC (rev 293756)
+++ trunk/Source/WTF/ChangeLog	2022-05-04 02:27:25 UTC (rev 293757)
@@ -1,3 +1,22 @@
+2022-05-03  Yusuke Suzuki  <[email protected]>
+
+        [JSC] Initialize empty and null AtomString at compile time
+        https://bugs.webkit.org/show_bug.cgi?id=240031
+
+        Reviewed by Mark Lam.
+
+        Because they are initialized from static data, we can just initialize them
+        at compile time, and we do not need to have `AtomString::init`.
+
+        * wtf/Threading.cpp:
+        (WTF::initialize):
+        * wtf/text/AtomString.cpp:
+        (WTF::AtomString::init): Deleted.
+        * wtf/text/AtomString.h:
+        (WTF::StaticAtomString::StaticAtomString):
+        (WTF::nullAtom):
+        (WTF::emptyAtom):
+
 2022-05-03  Chris Dumez  <[email protected]>
 
         REGRESSION (r293703): 358 JSC tests failing

Modified: trunk/Source/WTF/wtf/Threading.cpp (293756 => 293757)


--- trunk/Source/WTF/wtf/Threading.cpp	2022-05-04 01:44:49 UTC (rev 293756)
+++ trunk/Source/WTF/wtf/Threading.cpp	2022-05-04 02:27:25 UTC (rev 293757)
@@ -475,7 +475,6 @@
 #if USE(PTHREADS) && HAVE(MACHINE_CONTEXT)
         SignalHandlers::initialize();
 #endif
-        AtomString::init();
     });
 }
 

Modified: trunk/Source/WTF/wtf/text/AtomString.cpp (293756 => 293757)


--- trunk/Source/WTF/wtf/text/AtomString.cpp	2022-05-04 01:44:49 UTC (rev 293756)
+++ trunk/Source/WTF/wtf/text/AtomString.cpp	2022-05-04 02:27:25 UTC (rev 293757)
@@ -32,6 +32,9 @@
 
 namespace WTF {
 
+WTF_EXPORT_PRIVATE const StaticAtomString nullAtomData { nullptr };
+WTF_EXPORT_PRIVATE const StaticAtomString emptyAtomData { &StringImpl::s_emptyAtomString };
+
 template<AtomString::CaseConvertType type>
 ALWAYS_INLINE AtomString AtomString::convertASCIICase() const
 {
@@ -134,18 +137,6 @@
 
 #endif
 
-WTF_EXPORT_PRIVATE LazyNeverDestroyed<const AtomString> nullAtomData;
-WTF_EXPORT_PRIVATE LazyNeverDestroyed<const AtomString> emptyAtomData;
-
-void AtomString::init()
-{
-    static std::once_flag initializeKey;
-    std::call_once(initializeKey, [] {
-        nullAtomData.construct();
-        emptyAtomData.construct(AtomString::fromLatin1(""));
-    });
-}
-
 static inline StringBuilder replaceUnpairedSurrogatesWithReplacementCharacterInternal(StringView view)
 {
     // Slow path: https://infra.spec.whatwg.org/#_javascript_-string-convert

Modified: trunk/Source/WTF/wtf/text/AtomString.h (293756 => 293757)


--- trunk/Source/WTF/wtf/text/AtomString.h	2022-05-04 01:44:49 UTC (rev 293756)
+++ trunk/Source/WTF/wtf/text/AtomString.h	2022-05-04 02:27:25 UTC (rev 293757)
@@ -35,8 +35,6 @@
 class AtomString final {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    WTF_EXPORT_PRIVATE static void init();
-
     AtomString();
     AtomString(const LChar*, unsigned length);
     AtomString(const UChar*, unsigned length);
@@ -279,13 +277,21 @@
 
 #endif
 
-// nullAtom and emptyAtom are special AtomString. They can be used from any threads since their StringImpls are not actually registered into AtomStringTable.
-extern WTF_EXPORT_PRIVATE LazyNeverDestroyed<const AtomString> nullAtomData;
-extern WTF_EXPORT_PRIVATE LazyNeverDestroyed<const AtomString> emptyAtomData;
+struct StaticAtomString {
+    constexpr StaticAtomString(StringImpl::StaticStringImpl* pointer)
+        : m_pointer(pointer)
+    {
+    }
 
-inline const AtomString& nullAtom() { return nullAtomData.get(); }
-inline const AtomString& emptyAtom() { return emptyAtomData.get(); }
+    StringImpl::StaticStringImpl* m_pointer;
+};
+static_assert(sizeof(AtomString) == sizeof(StaticAtomString), "AtomString and StaticAtomString must be the same size!");
+extern WTF_EXPORT_PRIVATE const StaticAtomString nullAtomData;
+extern WTF_EXPORT_PRIVATE const StaticAtomString emptyAtomData;
 
+inline const AtomString& nullAtom() { return *reinterpret_cast<const AtomString*>(&nullAtomData); }
+inline const AtomString& emptyAtom() { return *reinterpret_cast<const AtomString*>(&emptyAtomData); }
+
 inline AtomString::AtomString(ASCIILiteral literal)
     : m_string(literal.length() ? AtomStringImpl::add(literal.characters(), literal.length()) : Ref { *emptyAtom().impl() })
 {

Modified: trunk/Source/WebCore/ChangeLog (293756 => 293757)


--- trunk/Source/WebCore/ChangeLog	2022-05-04 01:44:49 UTC (rev 293756)
+++ trunk/Source/WebCore/ChangeLog	2022-05-04 02:27:25 UTC (rev 293757)
@@ -1,3 +1,15 @@
+2022-05-03  Yusuke Suzuki  <[email protected]>
+
+        [JSC] Initialize empty and null AtomString at compile time
+        https://bugs.webkit.org/show_bug.cgi?id=240031
+
+        Reviewed by Mark Lam.
+
+        * dom/QualifiedName.cpp:
+        (WebCore::QualifiedName::init):
+        * dom/make_names.pl:
+        (printInit):
+
 2022-05-03  Sihui Liu  <[email protected]>
 
         StorageMap::removeItem may fail to remove item from map

Modified: trunk/Source/WebCore/dom/QualifiedName.cpp (293756 => 293757)


--- trunk/Source/WebCore/dom/QualifiedName.cpp	2022-05-04 01:44:49 UTC (rev 293756)
+++ trunk/Source/WebCore/dom/QualifiedName.cpp	2022-05-04 02:27:25 UTC (rev 293757)
@@ -49,7 +49,6 @@
     if (initialized)
         return;
 
-    ASSERT_WITH_MESSAGE(WTF::nullAtomData.isConstructed(), "AtomString::init should have been called");
     anyName.construct(nullAtom(), starAtom(), starAtom());
     initialized = true;
 }

Modified: trunk/Source/WebCore/dom/make_names.pl (293756 => 293757)


--- trunk/Source/WebCore/dom/make_names.pl	2022-05-04 01:44:49 UTC (rev 293756)
+++ trunk/Source/WebCore/dom/make_names.pl	2022-05-04 02:27:25 UTC (rev 293757)
@@ -602,8 +602,6 @@
     initialized = true;
 
     // Use placement new to initialize the globals.
-
-    AtomString::init();
 ";
 }
 

Modified: trunk/Source/WebKit/ChangeLog (293756 => 293757)


--- trunk/Source/WebKit/ChangeLog	2022-05-04 01:44:49 UTC (rev 293756)
+++ trunk/Source/WebKit/ChangeLog	2022-05-04 02:27:25 UTC (rev 293757)
@@ -1,3 +1,13 @@
+2022-05-03  Yusuke Suzuki  <[email protected]>
+
+        [JSC] Initialize empty and null AtomString at compile time
+        https://bugs.webkit.org/show_bug.cgi?id=240031
+
+        Reviewed by Mark Lam.
+
+        * WebAuthnProcess/WebAuthnProcess.cpp:
+        (WebKit::WebAuthnProcess::initializeWebAuthnProcess):
+
 2022-05-03  Commit Queue  <[email protected]>
 
         Unreviewed, reverting r293743.

Modified: trunk/Source/WebKit/WebAuthnProcess/WebAuthnProcess.cpp (293756 => 293757)


--- trunk/Source/WebKit/WebAuthnProcess/WebAuthnProcess.cpp	2022-05-04 01:44:49 UTC (rev 293756)
+++ trunk/Source/WebKit/WebAuthnProcess/WebAuthnProcess.cpp	2022-05-04 02:27:25 UTC (rev 293757)
@@ -94,7 +94,6 @@
 {
     applyProcessCreationParameters(parameters.auxiliaryProcessParameters);
     WTF::Thread::setCurrentThreadIsUserInitiated();
-    AtomString::init();
 }
 
 void WebAuthnProcess::prepareToSuspend(bool isSuspensionImminent, CompletionHandler<void()>&& completionHandler)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to