Title: [220569] trunk/Source/WebCore
- Revision
- 220569
- Author
- utatane....@gmail.com
- Date
- 2017-08-10 17:41:53 -0700 (Thu, 10 Aug 2017)
Log Message
Make ThreadGlobalData RefCounted for web thread
https://bugs.webkit.org/show_bug.cgi?id=175439
Reviewed by Mark Lam.
When the web thread is enabled, we share ThreadGlobalData between the web thread and the main thread.
The problem happens when the main thread is dying. It could start deallocating TLS and the web
thread may see the destructed ThreadGlobalData.
Even though, the current implementation is safe because the main thread do not perform TLS deallocation
in the Darwin environment. But this is not true in Windows. And we should not rely on this condition
that depends on the platforms.
In this patch, we make ThreadGlobalData ThreadSafeRefCounted. This type verbosely describes that
ThreadGlobalData could be shared between threads when the web thread enabled. And make the life time
management simple instead of relying on the platform dependent TLS implementation.
* platform/ThreadGlobalData.cpp:
(WebCore::ThreadGlobalData::setWebCoreThreadData):
(WebCore::threadGlobalData):
* platform/ThreadGlobalData.h:
(WebCore::ThreadGlobalData::cachedResourceRequestInitiators): Deleted.
(WebCore::ThreadGlobalData::eventNames): Deleted.
(WebCore::ThreadGlobalData::threadTimers): Deleted.
(WebCore::ThreadGlobalData::qualifiedNameCache): Deleted.
(WebCore::ThreadGlobalData::cachedConverterICU): Deleted.
(WebCore::ThreadGlobalData::cachedConverterTEC): Deleted.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (220568 => 220569)
--- trunk/Source/WebCore/ChangeLog 2017-08-11 00:41:09 UTC (rev 220568)
+++ trunk/Source/WebCore/ChangeLog 2017-08-11 00:41:53 UTC (rev 220569)
@@ -1,5 +1,35 @@
2017-08-10 Yusuke Suzuki <utatane....@gmail.com>
+ Make ThreadGlobalData RefCounted for web thread
+ https://bugs.webkit.org/show_bug.cgi?id=175439
+
+ Reviewed by Mark Lam.
+
+ When the web thread is enabled, we share ThreadGlobalData between the web thread and the main thread.
+ The problem happens when the main thread is dying. It could start deallocating TLS and the web
+ thread may see the destructed ThreadGlobalData.
+
+ Even though, the current implementation is safe because the main thread do not perform TLS deallocation
+ in the Darwin environment. But this is not true in Windows. And we should not rely on this condition
+ that depends on the platforms.
+
+ In this patch, we make ThreadGlobalData ThreadSafeRefCounted. This type verbosely describes that
+ ThreadGlobalData could be shared between threads when the web thread enabled. And make the life time
+ management simple instead of relying on the platform dependent TLS implementation.
+
+ * platform/ThreadGlobalData.cpp:
+ (WebCore::ThreadGlobalData::setWebCoreThreadData):
+ (WebCore::threadGlobalData):
+ * platform/ThreadGlobalData.h:
+ (WebCore::ThreadGlobalData::cachedResourceRequestInitiators): Deleted.
+ (WebCore::ThreadGlobalData::eventNames): Deleted.
+ (WebCore::ThreadGlobalData::threadTimers): Deleted.
+ (WebCore::ThreadGlobalData::qualifiedNameCache): Deleted.
+ (WebCore::ThreadGlobalData::cachedConverterICU): Deleted.
+ (WebCore::ThreadGlobalData::cachedConverterTEC): Deleted.
+
+2017-08-10 Yusuke Suzuki <utatane....@gmail.com>
+
[JSC] Use @toNumber in builtins
https://bugs.webkit.org/show_bug.cgi?id=172692
Modified: trunk/Source/WebCore/platform/ThreadGlobalData.cpp (220568 => 220569)
--- trunk/Source/WebCore/platform/ThreadGlobalData.cpp 2017-08-11 00:41:09 UTC (rev 220568)
+++ trunk/Source/WebCore/platform/ThreadGlobalData.cpp 2017-08-11 00:41:53 UTC (rev 220569)
@@ -81,7 +81,7 @@
}
#if USE(WEB_THREAD)
-static ThreadSpecific<std::unique_ptr<ThreadGlobalData>>* staticData { nullptr };
+static ThreadSpecific<RefPtr<ThreadGlobalData>>* staticData { nullptr };
static ThreadGlobalData* sharedMainThreadStaticData { nullptr };
void ThreadGlobalData::setWebCoreThreadData()
@@ -90,11 +90,7 @@
ASSERT(&threadGlobalData() != sharedMainThreadStaticData);
// Set WebThread's ThreadGlobalData object to be the same as the main UI thread.
- // The web thread never finishes, and we expect the main thread to also never finish.
- // Hence, it is safe to store the same ThreadGlobalData pointer in a thread specific std::unique_ptr.
- // FIXME: Make ThreadGlobalData RefCounted for web thread.
- // https://bugs.webkit.org/show_bug.cgi?id=175439
- (**staticData).reset(sharedMainThreadStaticData);
+ **staticData = adoptRef(sharedMainThreadStaticData);
ASSERT(&threadGlobalData() == sharedMainThreadStaticData);
}
@@ -102,20 +98,22 @@
ThreadGlobalData& threadGlobalData()
{
if (UNLIKELY(!staticData)) {
- staticData = new ThreadSpecific<std::unique_ptr<ThreadGlobalData>>;
+ staticData = new ThreadSpecific<RefPtr<ThreadGlobalData>>;
auto& result = **staticData;
ASSERT(!result);
- result.reset(new ThreadGlobalData());
+ result = adoptRef(new ThreadGlobalData);
// WebThread and main UI thread need to share the same object. Save it in a static
// here, the WebThread will pick it up in setWebCoreThreadData().
- if (pthread_main_np())
+ if (pthread_main_np()) {
sharedMainThreadStaticData = result.get();
+ result->ref();
+ }
return *result;
}
auto& result = **staticData;
if (!result)
- result.reset(new ThreadGlobalData());
+ result = adoptRef(new ThreadGlobalData);
return *result;
}
Modified: trunk/Source/WebCore/platform/ThreadGlobalData.h (220568 => 220569)
--- trunk/Source/WebCore/platform/ThreadGlobalData.h 2017-08-11 00:41:09 UTC (rev 220568)
+++ trunk/Source/WebCore/platform/ThreadGlobalData.h 2017-08-11 00:41:53 UTC (rev 220569)
@@ -27,6 +27,7 @@
#ifndef ThreadGlobalData_h
#define ThreadGlobalData_h
+#include <wtf/ThreadSafeRefCounted.h>
#include <wtf/text/StringHash.h>
namespace WebCore {
@@ -39,7 +40,11 @@
struct ICUConverterWrapper;
struct TECConverterWrapper;
+#if USE(WEB_THREAD)
+ class ThreadGlobalData : public ThreadSafeRefCounted<ThreadGlobalData> {
+#else
class ThreadGlobalData {
+#endif
WTF_MAKE_NONCOPYABLE(ThreadGlobalData);
WTF_MAKE_FAST_ALLOCATED;
public:
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes