Web Inspector: inspector/cpu-profiler/threads.html is flaky crashing
authorbburg@apple.com <bburg@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 12 Feb 2020 21:50:49 +0000 (21:50 +0000)
committerbburg@apple.com <bburg@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 12 Feb 2020 21:50:49 +0000 (21:50 +0000)
https://bugs.webkit.org/show_bug.cgi?id=207588
<rdar://problem/57458123>

Reviewed by Yusuke Suzuki.

* page/cocoa/ResourceUsageThreadCocoa.mm:
(WebCore::ResourceUsageThread::platformCollectCPUData):
Use a fence to force Thread to be completely ready for use by other threads
prior to storing it. Otherwise, ResourceUsageThread may see it too early.

* workers/WorkerThread.cpp:
(WebCore::WorkerThread::start): Ignore worker threads that are
not fully initialized.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@256474 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/page/cocoa/ResourceUsageThreadCocoa.mm
Source/WebCore/workers/WorkerThread.cpp

index 50b58a1..e8b6dd8 100644 (file)
@@ -1,3 +1,20 @@
+2020-02-12  Brian Burg  <bburg@apple.com>
+
+        Web Inspector: inspector/cpu-profiler/threads.html is flaky crashing
+        https://bugs.webkit.org/show_bug.cgi?id=207588
+        <rdar://problem/57458123>
+
+        Reviewed by Yusuke Suzuki.
+
+        * page/cocoa/ResourceUsageThreadCocoa.mm:
+        (WebCore::ResourceUsageThread::platformCollectCPUData):
+        Use a fence to force Thread to be completely ready for use by other threads
+        prior to storing it. Otherwise, ResourceUsageThread may see it too early.
+
+        * workers/WorkerThread.cpp:
+        (WebCore::WorkerThread::start): Ignore worker threads that are
+        not fully initialized.
+
 2020-02-12  Youenn Fablet  <youenn@apple.com>
 
         ServiceWorkerContainer::jobResolvedWithRegistration scopeExit should capture all lambda parameters by value
index 0d56904..a6e37c7 100644 (file)
@@ -168,6 +168,9 @@ void ResourceUsageThread::platformCollectCPUData(JSC::VM*, ResourceUsageData& da
     {
         LockHolder lock(WorkerThread::workerThreadsMutex());
         for (auto* thread : WorkerThread::workerThreads(lock)) {
+            // Ignore worker threads that have not been fully started yet.
+            if (!thread->thread())
+                continue;
             mach_port_t machThread = thread->thread()->machThread();
             if (machThread != MACH_PORT_NULL)
                 knownWorkerThreads.set(machThread, thread->identifier().isolatedCopy());
index af3bd70..0f3158f 100644 (file)
@@ -142,9 +142,12 @@ void WorkerThread::start(WTF::Function<void(const String&)>&& evaluateCallback)
 
     m_evaluateCallback = WTFMove(evaluateCallback);
 
-    m_thread = Thread::create(isServiceWorkerThread() ? "WebCore: Service Worker" : "WebCore: Worker", [this] {
+    Ref<Thread> thread = Thread::create(isServiceWorkerThread() ? "WebCore: Service Worker" : "WebCore: Worker", [this] {
         workerThread();
     });
+    // Force the Thread object to be initialized fully before storing it to m_thread (and becoming visible to other threads).
+    WTF::storeStoreFence();
+    m_thread = WTFMove(thread);
 }
 
 void WorkerThread::workerThread()