Title: [165725] trunk/Source/WTF
Revision
165725
Author
[email protected]
Date
2014-03-17 01:29:12 -0700 (Mon, 17 Mar 2014)

Log Message

[Mac] WTFThreadData should use _pthread_getspecific_direct().
<https://webkit.org/b/130320>

Hack WTFThreadData to use a direct key for TLS access when available.
This mechanism uses a dedicated segment register and is the same way
we implement the fast path in FastMalloc.

Reviewed by Darin Adler.

* wtf/FastMalloc.cpp:
* wtf/WTFThreadData.cpp:
(WTF::WTFThreadData::createAndRegisterForGetspecificDirect):
* wtf/WTFThreadData.h:
(WTF::wtfThreadData):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (165724 => 165725)


--- trunk/Source/WTF/ChangeLog	2014-03-17 08:01:27 UTC (rev 165724)
+++ trunk/Source/WTF/ChangeLog	2014-03-17 08:29:12 UTC (rev 165725)
@@ -1,3 +1,20 @@
+2014-03-17  Andreas Kling  <[email protected]>
+
+        [Mac] WTFThreadData should use _pthread_getspecific_direct().
+        <https://webkit.org/b/130320>
+
+        Hack WTFThreadData to use a direct key for TLS access when available.
+        This mechanism uses a dedicated segment register and is the same way
+        we implement the fast path in FastMalloc.
+
+        Reviewed by Darin Adler.
+
+        * wtf/FastMalloc.cpp:
+        * wtf/WTFThreadData.cpp:
+        (WTF::WTFThreadData::createAndRegisterForGetspecificDirect):
+        * wtf/WTFThreadData.h:
+        (WTF::wtfThreadData):
+
 2014-03-16  Darin Adler  <[email protected]>
 
         Remove most uses of deprecatedCharacter in WTF

Modified: trunk/Source/WTF/wtf/FastMalloc.cpp (165724 => 165725)


--- trunk/Source/WTF/wtf/FastMalloc.cpp	2014-03-17 08:01:27 UTC (rev 165724)
+++ trunk/Source/WTF/wtf/FastMalloc.cpp	2014-03-17 08:29:12 UTC (rev 165725)
@@ -461,18 +461,14 @@
 #include <dispatch/dispatch.h>
 #endif
 
-#ifdef __has_include
-#if __has_include(<System/pthread_machdep.h>)
-
+#if defined(__has_include) && __has_include(<System/pthread_machdep.h>)
 #include <System/pthread_machdep.h>
+#endif
 
 #if defined(__PTK_FRAMEWORK_JAVASCRIPTCORE_KEY0)
 #define WTF_USE_PTHREAD_GETSPECIFIC_DIRECT 1
 #endif
 
-#endif
-#endif
-
 #ifndef PRIuS
 #define PRIuS "zu"
 #endif

Modified: trunk/Source/WTF/wtf/WTFThreadData.cpp (165724 => 165725)


--- trunk/Source/WTF/wtf/WTFThreadData.cpp	2014-03-17 08:01:27 UTC (rev 165724)
+++ trunk/Source/WTF/wtf/WTFThreadData.cpp	2014-03-17 08:29:12 UTC (rev 165725)
@@ -35,7 +35,9 @@
 
 namespace WTF {
 
+#if !USE(PTHREAD_GETSPECIFIC_DIRECT)
 ThreadSpecific<WTFThreadData>* WTFThreadData::staticData;
+#endif
 
 WTFThreadData::WTFThreadData()
     : m_apiData(0)
@@ -71,6 +73,18 @@
     delete m_defaultIdentifierTable;
 }
 
+#if USE(PTHREAD_GETSPECIFIC_DIRECT)
+WTFThreadData& WTFThreadData::createAndRegisterForGetspecificDirect()
+{
+    WTFThreadData* data = "" WTFThreadData;
+    _pthread_setspecific_direct(directKey, data);
+    pthread_key_init_np(directKey, [](void* data){
+        delete static_cast<WTFThreadData*>(data);
+    });
+    return *data;
+}
+#endif
+
 } // namespace WTF
 
 namespace JSC {

Modified: trunk/Source/WTF/wtf/WTFThreadData.h (165724 => 165725)


--- trunk/Source/WTF/wtf/WTFThreadData.h	2014-03-17 08:01:27 UTC (rev 165724)
+++ trunk/Source/WTF/wtf/WTFThreadData.h	2014-03-17 08:29:12 UTC (rev 165725)
@@ -33,8 +33,19 @@
 #include <wtf/StackBounds.h>
 #include <wtf/StackStats.h>
 #include <wtf/text/StringHash.h>
+
+#if defined(__has_include) && __has_include(<System/pthread_machdep.h>)
+#include <System/pthread_machdep.h>
+#endif
+
+#if defined(__PTK_FRAMEWORK_JAVASCRIPTCORE_KEY1)
+#define WTF_USE_PTHREAD_GETSPECIFIC_DIRECT 1
+#endif
+
+#if !USE(PTHREAD_GETSPECIFIC_DIRECT)
 #include <wtf/ThreadSpecific.h>
 #include <wtf/Threading.h>
+#endif
 
 // FIXME: This is a temporary layering violation until we move more of the string code from _javascript_Core to WTF.
 namespace JSC {
@@ -141,7 +152,13 @@
     void* m_savedStackPointerAtVMEntry;
     void* m_savedLastStackTop;
 
+#if USE(PTHREAD_GETSPECIFIC_DIRECT)
+    static const pthread_key_t directKey = __PTK_FRAMEWORK_JAVASCRIPTCORE_KEY1;
+    WTF_EXPORT_PRIVATE static WTFThreadData& createAndRegisterForGetspecificDirect();
+#else
     static WTF_EXPORTDATA ThreadSpecific<WTFThreadData>* staticData;
+#endif
+
     friend WTFThreadData& wtfThreadData();
     friend class AtomicStringTable;
 };
@@ -154,9 +171,15 @@
     // WRT _javascript_Core:
     //    wtfThreadData() is initially called from initializeThreading(), ensuring
     //    this is initially called in a pthread_once locked context.
+#if !USE(PTHREAD_GETSPECIFIC_DIRECT)
     if (!WTFThreadData::staticData)
         WTFThreadData::staticData = new ThreadSpecific<WTFThreadData>;
     return **WTFThreadData::staticData;
+#else
+    if (WTFThreadData* data = ""
+        return *data;
+    return WTFThreadData::createAndRegisterForGetspecificDirect();
+#endif
 }
 
 } // namespace WTF
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to