Merge WTFThreadData to Thread::current
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 31 Jul 2017 11:23:41 +0000 (11:23 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 31 Jul 2017 11:23:41 +0000 (11:23 +0000)
https://bugs.webkit.org/show_bug.cgi?id=174716

Reviewed by Sam Weinig.

Source/JavaScriptCore:

Use Thread::current() instead.

* API/JSContext.mm:
(+[JSContext currentContext]):
(+[JSContext currentThis]):
(+[JSContext currentCallee]):
(+[JSContext currentArguments]):
(-[JSContext beginCallbackWithData:calleeValue:thisValue:argumentCount:arguments:]):
(-[JSContext endCallbackWithData:]):
* heap/Heap.cpp:
(JSC::Heap::requestCollection):
* runtime/Completion.cpp:
(JSC::checkSyntax):
(JSC::checkModuleSyntax):
(JSC::evaluate):
(JSC::loadAndEvaluateModule):
(JSC::loadModule):
(JSC::linkAndEvaluateModule):
(JSC::importModule):
* runtime/Identifier.cpp:
(JSC::Identifier::checkCurrentAtomicStringTable):
* runtime/InitializeThreading.cpp:
(JSC::initializeThreading):
* runtime/JSLock.cpp:
(JSC::JSLock::didAcquireLock):
(JSC::JSLock::willReleaseLock):
(JSC::JSLock::dropAllLocks):
(JSC::JSLock::grabAllLocks):
* runtime/JSLock.h:
* runtime/VM.cpp:
(JSC::VM::VM):
(JSC::VM::updateStackLimits):
(JSC::VM::committedStackByteCount):
* runtime/VM.h:
(JSC::VM::isSafeToRecurse const):
* runtime/VMEntryScope.cpp:
(JSC::VMEntryScope::VMEntryScope):
* runtime/VMInlines.h:
(JSC::VM::ensureStackCapacityFor):
* yarr/YarrPattern.cpp:
(JSC::Yarr::YarrPatternConstructor::isSafeToRecurse const):

Source/WebCore:

Use Thread::current() instead.

* fileapi/AsyncFileStream.cpp:
* platform/ThreadGlobalData.cpp:
(WebCore::ThreadGlobalData::ThreadGlobalData):
* platform/graphics/cocoa/WebCoreDecompressionSession.h:
* platform/ios/wak/WebCoreThread.mm:
(StartWebThread):
* workers/WorkerThread.cpp:
(WebCore::WorkerThread::workerThread):

Source/WTF:

We placed thread specific data in WTFThreadData previously. But now, we have a new good place
to put thread specific data: WTF::Thread. Before this patch, WTFThreadData and WTF::Thread
sometimes have the completely same fields (m_stack etc.) due to initialization order limitations.
This patch merges WTFThreadData to WTF::Thread. We apply WTFThreadData's initialization style
to WTF::Thread. So, WTF::Thread's holder now uses fast TLS for darwin environment. Thus,
Thread::current() access is now accelerated. And WTF::Thread::current() can be accessed even
before calling WTF::initializeThreading.

* WTF.xcodeproj/project.pbxproj:
* wtf/CMakeLists.txt:
* wtf/LockAlgorithm.h:
* wtf/LockAlgorithmInlines.h:
* wtf/MainThread.h:
* wtf/ParkingLot.cpp:
* wtf/StackStats.cpp:
(WTF::StackStats::PerThreadStats::PerThreadStats):
(WTF::StackStats::CheckPoint::CheckPoint):
(WTF::StackStats::CheckPoint::~CheckPoint):
(WTF::StackStats::probe):
(WTF::StackStats::LayoutCheckPoint::LayoutCheckPoint):
* wtf/ThreadHolder.cpp:
(WTF::ThreadHolder::initializeCurrent):
* wtf/ThreadHolder.h:
(WTF::ThreadHolder::ThreadHolder):
(WTF::ThreadHolder::currentMayBeNull):
(WTF::ThreadHolder::current):
* wtf/ThreadHolderPthreads.cpp:
(WTF::ThreadHolder::initialize):
(WTF::ThreadHolder::destruct):
(WTF::ThreadHolder::current): Deleted.
* wtf/ThreadHolderWin.cpp:
(WTF::ThreadHolder::currentDying):
(WTF::ThreadHolder::initialize):
(WTF::ThreadHolder::current): Deleted.
* wtf/Threading.cpp:
(WTF::Thread::initializeInThread):
(WTF::Thread::entryPoint):
(WTF::Thread::didExit):
(WTF::initializeThreading):
(WTF::Thread::currentMayBeNull): Deleted.
* wtf/Threading.h:
(WTF::Thread::atomicStringTable):
(WTF::Thread::setCurrentAtomicStringTable):
(WTF::Thread::stackStats):
(WTF::Thread::savedStackPointerAtVMEntry):
(WTF::Thread::setSavedStackPointerAtVMEntry):
(WTF::Thread::savedLastStackTop):
(WTF::Thread::setSavedLastStackTop):
(WTF::Thread::current):
* wtf/ThreadingPrimitives.h:
* wtf/ThreadingPthreads.cpp:
(WTF::Thread::createCurrentThread):
(WTF::Thread::current): Deleted.
* wtf/ThreadingWin.cpp:
(WTF::Thread::createCurrentThread):
(WTF::Thread::current): Deleted.
* wtf/WTFThreadData.cpp: Removed.
* wtf/WTFThreadData.h: Removed.
* wtf/text/AtomicString.cpp:
* wtf/text/AtomicStringImpl.cpp:
(WTF::stringTable):
* wtf/text/AtomicStringTable.cpp:
(WTF::AtomicStringTable::create):
* wtf/text/AtomicStringTable.h:

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

42 files changed:
Source/JavaScriptCore/API/JSContext.mm
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/heap/Heap.cpp
Source/JavaScriptCore/runtime/Completion.cpp
Source/JavaScriptCore/runtime/Identifier.cpp
Source/JavaScriptCore/runtime/InitializeThreading.cpp
Source/JavaScriptCore/runtime/JSLock.cpp
Source/JavaScriptCore/runtime/JSLock.h
Source/JavaScriptCore/runtime/VM.cpp
Source/JavaScriptCore/runtime/VM.h
Source/JavaScriptCore/runtime/VMEntryScope.cpp
Source/JavaScriptCore/runtime/VMInlines.h
Source/JavaScriptCore/yarr/YarrPattern.cpp
Source/WTF/ChangeLog
Source/WTF/WTF.xcodeproj/project.pbxproj
Source/WTF/wtf/CMakeLists.txt
Source/WTF/wtf/LockAlgorithm.h
Source/WTF/wtf/LockAlgorithmInlines.h
Source/WTF/wtf/MainThread.h
Source/WTF/wtf/ParkingLot.cpp
Source/WTF/wtf/StackStats.cpp
Source/WTF/wtf/ThreadHolder.cpp
Source/WTF/wtf/ThreadHolder.h
Source/WTF/wtf/ThreadHolderPthreads.cpp
Source/WTF/wtf/ThreadHolderWin.cpp
Source/WTF/wtf/Threading.cpp
Source/WTF/wtf/Threading.h
Source/WTF/wtf/ThreadingPrimitives.h
Source/WTF/wtf/ThreadingPthreads.cpp
Source/WTF/wtf/ThreadingWin.cpp
Source/WTF/wtf/WTFThreadData.cpp [deleted file]
Source/WTF/wtf/WTFThreadData.h [deleted file]
Source/WTF/wtf/text/AtomicString.cpp
Source/WTF/wtf/text/AtomicStringImpl.cpp
Source/WTF/wtf/text/AtomicStringTable.cpp
Source/WTF/wtf/text/AtomicStringTable.h
Source/WebCore/ChangeLog
Source/WebCore/fileapi/AsyncFileStream.cpp
Source/WebCore/platform/ThreadGlobalData.cpp
Source/WebCore/platform/graphics/cocoa/WebCoreDecompressionSession.h
Source/WebCore/platform/ios/wak/WebCoreThread.mm
Source/WebCore/workers/WorkerThread.cpp

index 5b100c7..baeb178 100644 (file)
 
 + (JSContext *)currentContext
 {
-    WTFThreadData& threadData = wtfThreadData();
-    CallbackData *entry = (CallbackData *)threadData.m_apiData;
+    Thread& thread = Thread::current();
+    CallbackData *entry = (CallbackData *)thread.m_apiData;
     return entry ? entry->context : nil;
 }
 
 + (JSValue *)currentThis
 {
-    WTFThreadData& threadData = wtfThreadData();
-    CallbackData *entry = (CallbackData *)threadData.m_apiData;
+    Thread& thread = Thread::current();
+    CallbackData *entry = (CallbackData *)thread.m_apiData;
     if (!entry)
         return nil;
     return [JSValue valueWithJSValueRef:entry->thisValue inContext:[JSContext currentContext]];
 
 + (JSValue *)currentCallee
 {
-    WTFThreadData& threadData = wtfThreadData();
-    CallbackData *entry = (CallbackData *)threadData.m_apiData;
+    Thread& thread = Thread::current();
+    CallbackData *entry = (CallbackData *)thread.m_apiData;
     if (!entry)
         return nil;
     return [JSValue valueWithJSValueRef:entry->calleeValue inContext:[JSContext currentContext]];
 
 + (NSArray *)currentArguments
 {
-    WTFThreadData& threadData = wtfThreadData();
-    CallbackData *entry = (CallbackData *)threadData.m_apiData;
+    Thread& thread = Thread::current();
+    CallbackData *entry = (CallbackData *)thread.m_apiData;
 
     if (!entry)
         return nil;
 
 - (void)beginCallbackWithData:(CallbackData *)callbackData calleeValue:(JSValueRef)calleeValue thisValue:(JSValueRef)thisValue argumentCount:(size_t)argumentCount arguments:(const JSValueRef *)arguments
 {
-    WTFThreadData& threadData = wtfThreadData();
+    Thread& thread = Thread::current();
     [self retain];
-    CallbackData *prevStack = (CallbackData *)threadData.m_apiData;
+    CallbackData *prevStack = (CallbackData *)thread.m_apiData;
     *callbackData = (CallbackData){ prevStack, self, [self.exception retain], calleeValue, thisValue, argumentCount, arguments, nil };
-    threadData.m_apiData = callbackData;
+    thread.m_apiData = callbackData;
     self.exception = nil;
 }
 
 - (void)endCallbackWithData:(CallbackData *)callbackData
 {
-    WTFThreadData& threadData = wtfThreadData();
+    Thread& thread = Thread::current();
     self.exception = callbackData->preservedException;
     [callbackData->preservedException release];
     [callbackData->currentArguments release];
-    threadData.m_apiData = callbackData->next;
+    thread.m_apiData = callbackData->next;
     [self release];
 }
 
index 37153df..203fe2d 100644 (file)
@@ -1,3 +1,52 @@
+2017-07-31  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        Merge WTFThreadData to Thread::current
+        https://bugs.webkit.org/show_bug.cgi?id=174716
+
+        Reviewed by Sam Weinig.
+
+        Use Thread::current() instead.
+
+        * API/JSContext.mm:
+        (+[JSContext currentContext]):
+        (+[JSContext currentThis]):
+        (+[JSContext currentCallee]):
+        (+[JSContext currentArguments]):
+        (-[JSContext beginCallbackWithData:calleeValue:thisValue:argumentCount:arguments:]):
+        (-[JSContext endCallbackWithData:]):
+        * heap/Heap.cpp:
+        (JSC::Heap::requestCollection):
+        * runtime/Completion.cpp:
+        (JSC::checkSyntax):
+        (JSC::checkModuleSyntax):
+        (JSC::evaluate):
+        (JSC::loadAndEvaluateModule):
+        (JSC::loadModule):
+        (JSC::linkAndEvaluateModule):
+        (JSC::importModule):
+        * runtime/Identifier.cpp:
+        (JSC::Identifier::checkCurrentAtomicStringTable):
+        * runtime/InitializeThreading.cpp:
+        (JSC::initializeThreading):
+        * runtime/JSLock.cpp:
+        (JSC::JSLock::didAcquireLock):
+        (JSC::JSLock::willReleaseLock):
+        (JSC::JSLock::dropAllLocks):
+        (JSC::JSLock::grabAllLocks):
+        * runtime/JSLock.h:
+        * runtime/VM.cpp:
+        (JSC::VM::VM):
+        (JSC::VM::updateStackLimits):
+        (JSC::VM::committedStackByteCount):
+        * runtime/VM.h:
+        (JSC::VM::isSafeToRecurse const):
+        * runtime/VMEntryScope.cpp:
+        (JSC::VMEntryScope::VMEntryScope):
+        * runtime/VMInlines.h:
+        (JSC::VM::ensureStackCapacityFor):
+        * yarr/YarrPattern.cpp:
+        (JSC::Yarr::YarrPatternConstructor::isSafeToRecurse const):
+
 2017-07-30  Yusuke Suzuki  <utatane.tea@gmail.com>
 
         [WTF] Introduce Private Symbols
index f65ef84..3d4bbe3 100644 (file)
@@ -140,7 +140,7 @@ bool isValidSharedInstanceThreadState(VM* vm)
 
 bool isValidThreadState(VM* vm)
 {
-    if (vm->atomicStringTable() != wtfThreadData().atomicStringTable())
+    if (vm->atomicStringTable() != WTF::Thread::current().atomicStringTable())
         return false;
 
     if (vm->isSharedInstance() && !isValidSharedInstanceThreadState(vm))
@@ -2023,7 +2023,7 @@ Heap::Ticket Heap::requestCollection(GCRequest request)
     stopIfNecessary();
     
     ASSERT(vm()->currentThreadIsHoldingAPILock());
-    RELEASE_ASSERT(vm()->atomicStringTable() == wtfThreadData().atomicStringTable());
+    RELEASE_ASSERT(vm()->atomicStringTable() == WTF::Thread::current().atomicStringTable());
     
     LockHolder locker(*m_threadLock);
     // We may be able to steal the conn. That only works if the collector is definitely not running
index 5b30264..8823e6f 100644 (file)
 #include "Parser.h"
 #include "ProgramExecutable.h"
 #include "ScriptProfilingScope.h"
-#include <wtf/WTFThreadData.h>
 
 namespace JSC {
 
 bool checkSyntax(ExecState* exec, const SourceCode& source, JSValue* returnedException)
 {
     JSLockHolder lock(exec);
-    RELEASE_ASSERT(exec->vm().atomicStringTable() == wtfThreadData().atomicStringTable());
+    RELEASE_ASSERT(exec->vm().atomicStringTable() == Thread::current().atomicStringTable());
 
     ProgramExecutable* program = ProgramExecutable::create(exec, source);
     JSObject* error = program->checkSyntax(exec);
@@ -64,7 +63,7 @@ bool checkSyntax(ExecState* exec, const SourceCode& source, JSValue* returnedExc
 bool checkSyntax(VM& vm, const SourceCode& source, ParserError& error)
 {
     JSLockHolder lock(vm);
-    RELEASE_ASSERT(vm.atomicStringTable() == wtfThreadData().atomicStringTable());
+    RELEASE_ASSERT(vm.atomicStringTable() == Thread::current().atomicStringTable());
     return !!parse<ProgramNode>(
         &vm, source, Identifier(), JSParserBuiltinMode::NotBuiltin,
         JSParserStrictMode::NotStrict, JSParserScriptMode::Classic, SourceParseMode::ProgramMode, SuperBinding::NotNeeded, error);
@@ -74,7 +73,7 @@ bool checkModuleSyntax(ExecState* exec, const SourceCode& source, ParserError& e
 {
     VM& vm = exec->vm();
     JSLockHolder lock(vm);
-    RELEASE_ASSERT(vm.atomicStringTable() == wtfThreadData().atomicStringTable());
+    RELEASE_ASSERT(vm.atomicStringTable() == Thread::current().atomicStringTable());
     std::unique_ptr<ModuleProgramNode> moduleProgramNode = parse<ModuleProgramNode>(
         &vm, source, Identifier(), JSParserBuiltinMode::NotBuiltin,
         JSParserStrictMode::Strict, JSParserScriptMode::Module, SourceParseMode::ModuleAnalyzeMode, SuperBinding::NotNeeded, error);
@@ -92,7 +91,7 @@ JSValue evaluate(ExecState* exec, const SourceCode& source, JSValue thisValue, N
     VM& vm = exec->vm();
     JSLockHolder lock(vm);
     auto scope = DECLARE_CATCH_SCOPE(vm);
-    RELEASE_ASSERT(vm.atomicStringTable() == wtfThreadData().atomicStringTable());
+    RELEASE_ASSERT(vm.atomicStringTable() == Thread::current().atomicStringTable());
     RELEASE_ASSERT(!vm.isCollectorBusyOnCurrentThread());
 
     CodeProfiling profile(source);
@@ -167,7 +166,7 @@ static JSInternalPromise* loadAndEvaluateModule(const JSLockHolder& lock, ExecSt
 JSInternalPromise* loadAndEvaluateModule(ExecState* exec, const String& moduleName, JSValue scriptFetcher)
 {
     JSLockHolder lock(exec);
-    RELEASE_ASSERT(exec->vm().atomicStringTable() == wtfThreadData().atomicStringTable());
+    RELEASE_ASSERT(exec->vm().atomicStringTable() == Thread::current().atomicStringTable());
     RELEASE_ASSERT(!exec->vm().isCollectorBusyOnCurrentThread());
 
     return loadAndEvaluateModule(lock, exec, exec->vmEntryGlobalObject(), Identifier::fromString(exec, moduleName), scriptFetcher);
@@ -178,7 +177,7 @@ JSInternalPromise* loadAndEvaluateModule(ExecState* exec, const SourceCode& sour
     VM& vm = exec->vm();
     JSLockHolder lock(vm);
     auto scope = DECLARE_THROW_SCOPE(vm);
-    RELEASE_ASSERT(vm.atomicStringTable() == wtfThreadData().atomicStringTable());
+    RELEASE_ASSERT(vm.atomicStringTable() == Thread::current().atomicStringTable());
     RELEASE_ASSERT(!vm.isCollectorBusyOnCurrentThread());
 
     Symbol* key = createSymbolForEntryPointModule(vm);
@@ -205,7 +204,7 @@ static JSInternalPromise* loadModule(const JSLockHolder& lock, ExecState* exec,
 JSInternalPromise* loadModule(ExecState* exec, const String& moduleName, JSValue scriptFetcher)
 {
     JSLockHolder lock(exec);
-    RELEASE_ASSERT(exec->vm().atomicStringTable() == wtfThreadData().atomicStringTable());
+    RELEASE_ASSERT(exec->vm().atomicStringTable() == Thread::current().atomicStringTable());
     RELEASE_ASSERT(!exec->vm().isCollectorBusyOnCurrentThread());
 
     return loadModule(lock, exec, exec->vmEntryGlobalObject(), Identifier::fromString(exec, moduleName), scriptFetcher);
@@ -216,7 +215,7 @@ JSInternalPromise* loadModule(ExecState* exec, const SourceCode& source, JSValue
     VM& vm = exec->vm();
     JSLockHolder lock(vm);
     auto scope = DECLARE_THROW_SCOPE(vm);
-    RELEASE_ASSERT(vm.atomicStringTable() == wtfThreadData().atomicStringTable());
+    RELEASE_ASSERT(vm.atomicStringTable() == Thread::current().atomicStringTable());
     RELEASE_ASSERT(!vm.isCollectorBusyOnCurrentThread());
 
     Symbol* key = createSymbolForEntryPointModule(vm);
@@ -234,7 +233,7 @@ JSInternalPromise* loadModule(ExecState* exec, const SourceCode& source, JSValue
 JSValue linkAndEvaluateModule(ExecState* exec, const Identifier& moduleKey, JSValue scriptFetcher)
 {
     JSLockHolder lock(exec);
-    RELEASE_ASSERT(exec->vm().atomicStringTable() == wtfThreadData().atomicStringTable());
+    RELEASE_ASSERT(exec->vm().atomicStringTable() == Thread::current().atomicStringTable());
     RELEASE_ASSERT(!exec->vm().isCollectorBusyOnCurrentThread());
 
     JSGlobalObject* globalObject = exec->vmEntryGlobalObject();
@@ -244,7 +243,7 @@ JSValue linkAndEvaluateModule(ExecState* exec, const Identifier& moduleKey, JSVa
 JSInternalPromise* importModule(ExecState* exec, const Identifier& moduleKey, JSValue scriptFetcher)
 {
     JSLockHolder lock(exec);
-    RELEASE_ASSERT(exec->vm().atomicStringTable() == wtfThreadData().atomicStringTable());
+    RELEASE_ASSERT(exec->vm().atomicStringTable() == Thread::current().atomicStringTable());
     RELEASE_ASSERT(!exec->vm().isCollectorBusyOnCurrentThread());
 
     return exec->vmEntryGlobalObject()->moduleLoader()->requestImportModule(exec, moduleKey, scriptFetcher);
index 99256d6..d552d0b 100644 (file)
@@ -110,7 +110,7 @@ void Identifier::checkCurrentAtomicStringTable(VM* vm)
 {
     // Check the identifier table accessible through the threadspecific matches the
     // vm's identifier table.
-    ASSERT_UNUSED(vm, vm->atomicStringTable() == wtfThreadData().atomicStringTable());
+    ASSERT_UNUSED(vm, vm->atomicStringTable() == Thread::current().atomicStringTable());
 }
 
 void Identifier::checkCurrentAtomicStringTable(ExecState* exec)
index 9ef143a..85073b6 100644 (file)
@@ -75,8 +75,8 @@ void initializeThreading()
         DisallowVMReentry::initialize();
 #endif
         initializeSuperSampler();
-        WTFThreadData& threadData = wtfThreadData();
-        threadData.setSavedLastStackTop(threadData.stack().origin());
+        Thread& thread = Thread::current();
+        thread.setSavedLastStackTop(thread.stack().origin());
 
 #if ENABLE(WEBASSEMBLY)
         Wasm::Thunks::initialize();
index ba6c44a..c2c8276 100644 (file)
@@ -127,9 +127,9 @@ void JSLock::didAcquireLock()
     if (!m_vm)
         return;
     
-    WTFThreadData& threadData = wtfThreadData();
+    Thread& thread = Thread::current();
     ASSERT(!m_entryAtomicStringTable);
-    m_entryAtomicStringTable = threadData.setCurrentAtomicStringTable(m_vm->atomicStringTable());
+    m_entryAtomicStringTable = thread.setCurrentAtomicStringTable(m_vm->atomicStringTable());
     ASSERT(m_entryAtomicStringTable);
 
     if (m_vm->heap.hasAccess())
@@ -143,7 +143,7 @@ void JSLock::didAcquireLock()
     void* p = &p; // A proxy for the current stack pointer.
     m_vm->setStackPointerAtVMEntry(p);
 
-    m_vm->setLastStackTop(threadData.savedLastStackTop());
+    m_vm->setLastStackTop(thread.savedLastStackTop());
 
     m_vm->heap.machineThreads().addCurrentThread();
 #if ENABLE(WEBASSEMBLY)
@@ -200,7 +200,7 @@ void JSLock::willReleaseLock()
     }
 
     if (m_entryAtomicStringTable) {
-        wtfThreadData().setCurrentAtomicStringTable(m_entryAtomicStringTable);
+        Thread::current().setCurrentAtomicStringTable(m_entryAtomicStringTable);
         m_entryAtomicStringTable = nullptr;
     }
 }
@@ -225,9 +225,9 @@ unsigned JSLock::dropAllLocks(DropAllLocks* dropper)
 
     dropper->setDropDepth(m_lockDropDepth);
 
-    WTFThreadData& threadData = wtfThreadData();
-    threadData.setSavedStackPointerAtVMEntry(m_vm->stackPointerAtVMEntry());
-    threadData.setSavedLastStackTop(m_vm->lastStackTop());
+    Thread& thread = Thread::current();
+    thread.setSavedStackPointerAtVMEntry(m_vm->stackPointerAtVMEntry());
+    thread.setSavedLastStackTop(m_vm->lastStackTop());
 
     unsigned droppedLockCount = m_lockCount;
     unlock(droppedLockCount);
@@ -252,9 +252,9 @@ void JSLock::grabAllLocks(DropAllLocks* dropper, unsigned droppedLockCount)
 
     --m_lockDropDepth;
 
-    WTFThreadData& threadData = wtfThreadData();
-    m_vm->setStackPointerAtVMEntry(threadData.savedStackPointerAtVMEntry());
-    m_vm->setLastStackTop(threadData.savedLastStackTop());
+    Thread& thread = Thread::current();
+    m_vm->setStackPointerAtVMEntry(thread.savedStackPointerAtVMEntry());
+    m_vm->setLastStackTop(thread.savedLastStackTop());
 }
 
 JSLock::DropAllLocks::DropAllLocks(VM* vm)
index c91daec..dea0502 100644 (file)
@@ -25,7 +25,7 @@
 #include <wtf/Lock.h>
 #include <wtf/Noncopyable.h>
 #include <wtf/RefPtr.h>
-#include <wtf/ThreadSafeRefCounted.h>
+#include <wtf/Threading.h>
 #include <wtf/text/AtomicStringTable.h>
 
 namespace JSC {
index 1251024..06959ba 100644 (file)
 #include <wtf/SimpleStats.h>
 #include <wtf/StringPrintStream.h>
 #include <wtf/Threading.h>
-#include <wtf/WTFThreadData.h>
 #include <wtf/text/AtomicStringTable.h>
 #include <wtf/text/SymbolRegistry.h>
 
@@ -176,7 +175,7 @@ VM::VM(VMType vmType, HeapType heapType)
     , topVMEntryFrame(nullptr)
     , topCallFrame(CallFrame::noCaller())
     , promiseDeferredTimer(std::make_unique<PromiseDeferredTimer>(*this))
-    , m_atomicStringTable(vmType == Default ? wtfThreadData().atomicStringTable() : new AtomicStringTable)
+    , m_atomicStringTable(vmType == Default ? Thread::current().atomicStringTable() : new AtomicStringTable)
     , propertyNames(nullptr)
     , emptyList(new ArgList)
     , machineCodeBytesPerBytecodeWordForBaselineJIT(std::make_unique<SimpleStats>())
@@ -211,13 +210,13 @@ VM::VM(VMType vmType, HeapType heapType)
     , m_shadowChicken(std::make_unique<ShadowChicken>())
 {
     interpreter = new Interpreter(*this);
-    StackBounds stack = wtfThreadData().stack();
+    StackBounds stack = Thread::current().stack();
     updateSoftReservedZoneSize(Options::softReservedZoneSize());
     setLastStackTop(stack.origin());
 
     // Need to be careful to keep everything consistent here
     JSLockHolder lock(this);
-    AtomicStringTable* existingEntryAtomicStringTable = wtfThreadData().setCurrentAtomicStringTable(m_atomicStringTable);
+    AtomicStringTable* existingEntryAtomicStringTable = Thread::current().setCurrentAtomicStringTable(m_atomicStringTable);
     propertyNames = new CommonIdentifiers(this);
     structureStructure.set(*this, Structure::createStructure(*this));
     structureRareDataStructure.set(*this, StructureRareData::createStructure(*this, 0, jsNull()));
@@ -270,7 +269,7 @@ VM::VM(VMType vmType, HeapType heapType)
     nativeStdFunctionCellStructure.set(*this, NativeStdFunctionCell::createStructure(*this, 0, jsNull()));
     smallStrings.initializeCommonStrings(*this);
 
-    wtfThreadData().setCurrentAtomicStringTable(existingEntryAtomicStringTable);
+    Thread::current().setCurrentAtomicStringTable(existingEntryAtomicStringTable);
 
 #if ENABLE(JIT)
     jitStubs = std::make_unique<JITThunks>();
@@ -672,7 +671,7 @@ inline void VM::updateStackLimits()
     void* lastSoftStackLimit = m_softStackLimit;
 #endif
 
-    const StackBounds& stack = wtfThreadData().stack();
+    const StackBounds& stack = Thread::current().stack();
     size_t reservedZoneSize = Options::reservedZoneSize();
     // We should have already ensured that Options::reservedZoneSize() >= minimumReserveZoneSize at
     // options initialization time, and the option value should not have been changed thereafter.
@@ -886,9 +885,9 @@ size_t VM::committedStackByteCount()
 #if ENABLE(JIT)
     // When using the C stack, we don't know how many stack pages are actually
     // committed. So, we use the current stack usage as an estimate.
-    ASSERT(wtfThreadData().stack().isGrowingDownward());
+    ASSERT(Thread::current().stack().isGrowingDownward());
     int8_t* current = reinterpret_cast<int8_t*>(&current);
-    int8_t* high = reinterpret_cast<int8_t*>(wtfThreadData().stack().origin());
+    int8_t* high = reinterpret_cast<int8_t*>(Thread::current().stack().origin());
     return high - current;
 #else
     return CLoopStack::committedByteCount();
index ee232a7..9fb4d8b 100644 (file)
@@ -68,7 +68,6 @@
 #include <wtf/Stopwatch.h>
 #include <wtf/ThreadSafeRefCounted.h>
 #include <wtf/ThreadSpecific.h>
-#include <wtf/WTFThreadData.h>
 #include <wtf/text/SymbolRegistry.h>
 #include <wtf/text/WTFString.h>
 #if ENABLE(REGEXP_TRACING)
@@ -243,7 +242,7 @@ public:
     // WebCore has a one-to-one mapping of threads to VMs;
     // either create() or createLeaked() should only be called once
     // on a thread, this is the 'default' VM (it uses the
-    // thread's default string uniquing table from wtfThreadData).
+    // thread's default string uniquing table from Thread::current()).
     // API contexts created using the new context group aware interface
     // create APIContextGroup objects which require less locking of JSC
     // than the old singleton APIShared VM created for use by
@@ -691,7 +690,7 @@ private:
 
     bool isSafeToRecurse(void* stackLimit) const
     {
-        ASSERT(wtfThreadData().stack().isGrowingDownward());
+        ASSERT(Thread::current().stack().isGrowingDownward());
         void* curr = reinterpret_cast<void*>(&curr);
         return curr >= stackLimit;
     }
index c2d9bda..d11a8ff 100644 (file)
@@ -41,7 +41,7 @@ VMEntryScope::VMEntryScope(VM& vm, JSGlobalObject* globalObject)
     , m_globalObject(globalObject)
 {
     ASSERT(!DisallowVMReentry::isInEffectOnCurrentThread());
-    ASSERT(wtfThreadData().stack().isGrowingDownward());
+    ASSERT(Thread::current().stack().isGrowingDownward());
     if (!vm.entryScope) {
         vm.entryScope = this;
 
index 5a77619..bc0c25f 100644 (file)
@@ -34,7 +34,7 @@ namespace JSC {
 bool VM::ensureStackCapacityFor(Register* newTopOfStack)
 {
 #if ENABLE(JIT)
-    ASSERT(wtfThreadData().stack().isGrowingDownward());
+    ASSERT(Thread::current().stack().isGrowingDownward());
     return newTopOfStack >= m_softStackLimit;
 #else
     return ensureStackCapacityForCLoop(newTopOfStack);
index 3a11090..7222cc0 100644 (file)
@@ -32,8 +32,8 @@
 #include "YarrCanonicalize.h"
 #include "YarrParser.h"
 #include <wtf/DataLog.h>
+#include <wtf/Threading.h>
 #include <wtf/Vector.h>
-#include <wtf/WTFThreadData.h>
 
 using namespace WTF;
 
@@ -882,7 +882,7 @@ private:
     {
         if (!m_stackLimit)
             return true;
-        ASSERT(wtfThreadData().stack().isGrowingDownward());
+        ASSERT(Thread::current().stack().isGrowingDownward());
         int8_t* curr = reinterpret_cast<int8_t*>(&curr);
         int8_t* limit = reinterpret_cast<int8_t*>(m_stackLimit);
         return curr >= limit;
index 56a7b40..849d561 100644 (file)
@@ -1,3 +1,75 @@
+2017-07-31  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        Merge WTFThreadData to Thread::current
+        https://bugs.webkit.org/show_bug.cgi?id=174716
+
+        Reviewed by Sam Weinig.
+
+        We placed thread specific data in WTFThreadData previously. But now, we have a new good place
+        to put thread specific data: WTF::Thread. Before this patch, WTFThreadData and WTF::Thread
+        sometimes have the completely same fields (m_stack etc.) due to initialization order limitations.
+        This patch merges WTFThreadData to WTF::Thread. We apply WTFThreadData's initialization style
+        to WTF::Thread. So, WTF::Thread's holder now uses fast TLS for darwin environment. Thus,
+        Thread::current() access is now accelerated. And WTF::Thread::current() can be accessed even
+        before calling WTF::initializeThreading.
+
+        * WTF.xcodeproj/project.pbxproj:
+        * wtf/CMakeLists.txt:
+        * wtf/LockAlgorithm.h:
+        * wtf/LockAlgorithmInlines.h:
+        * wtf/MainThread.h:
+        * wtf/ParkingLot.cpp:
+        * wtf/StackStats.cpp:
+        (WTF::StackStats::PerThreadStats::PerThreadStats):
+        (WTF::StackStats::CheckPoint::CheckPoint):
+        (WTF::StackStats::CheckPoint::~CheckPoint):
+        (WTF::StackStats::probe):
+        (WTF::StackStats::LayoutCheckPoint::LayoutCheckPoint):
+        * wtf/ThreadHolder.cpp:
+        (WTF::ThreadHolder::initializeCurrent):
+        * wtf/ThreadHolder.h:
+        (WTF::ThreadHolder::ThreadHolder):
+        (WTF::ThreadHolder::currentMayBeNull):
+        (WTF::ThreadHolder::current):
+        * wtf/ThreadHolderPthreads.cpp:
+        (WTF::ThreadHolder::initialize):
+        (WTF::ThreadHolder::destruct):
+        (WTF::ThreadHolder::current): Deleted.
+        * wtf/ThreadHolderWin.cpp:
+        (WTF::ThreadHolder::currentDying):
+        (WTF::ThreadHolder::initialize):
+        (WTF::ThreadHolder::current): Deleted.
+        * wtf/Threading.cpp:
+        (WTF::Thread::initializeInThread):
+        (WTF::Thread::entryPoint):
+        (WTF::Thread::didExit):
+        (WTF::initializeThreading):
+        (WTF::Thread::currentMayBeNull): Deleted.
+        * wtf/Threading.h:
+        (WTF::Thread::atomicStringTable):
+        (WTF::Thread::setCurrentAtomicStringTable):
+        (WTF::Thread::stackStats):
+        (WTF::Thread::savedStackPointerAtVMEntry):
+        (WTF::Thread::setSavedStackPointerAtVMEntry):
+        (WTF::Thread::savedLastStackTop):
+        (WTF::Thread::setSavedLastStackTop):
+        (WTF::Thread::current):
+        * wtf/ThreadingPrimitives.h:
+        * wtf/ThreadingPthreads.cpp:
+        (WTF::Thread::createCurrentThread):
+        (WTF::Thread::current): Deleted.
+        * wtf/ThreadingWin.cpp:
+        (WTF::Thread::createCurrentThread):
+        (WTF::Thread::current): Deleted.
+        * wtf/WTFThreadData.cpp: Removed.
+        * wtf/WTFThreadData.h: Removed.
+        * wtf/text/AtomicString.cpp:
+        * wtf/text/AtomicStringImpl.cpp:
+        (WTF::stringTable):
+        * wtf/text/AtomicStringTable.cpp:
+        (WTF::AtomicStringTable::create):
+        * wtf/text/AtomicStringTable.h:
+
 2017-07-31  Xabier Rodriguez Calvar  <calvaris@igalia.com>
 
         Created a bool pretty printer at WTF for debugging purposes
index fb83fa5..ae69698 100644 (file)
                A8A47460151A825B004123FF /* CollatorDefault.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A8A4734B151A825B004123FF /* CollatorDefault.cpp */; };
                A8A47463151A825B004123FF /* CollatorICU.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A8A47350151A825B004123FF /* CollatorICU.cpp */; };
                A8A47469151A825B004123FF /* UTF8.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A8A47357151A825B004123FF /* UTF8.cpp */; };
-               A8A47486151A825B004123FF /* WTFThreadData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A8A4737A151A825B004123FF /* WTFThreadData.cpp */; };
                AD89B6B71E6415080090707F /* MemoryPressureHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AD89B6B51E6415080090707F /* MemoryPressureHandler.cpp */; };
                AD89B6BA1E64150F0090707F /* MemoryPressureHandlerCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = AD89B6B91E64150F0090707F /* MemoryPressureHandlerCocoa.mm */; };
                ADF2CE671E39F106006889DB /* MemoryFootprintCocoa.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ADF2CE651E39F106006889DB /* MemoryFootprintCocoa.cpp */; };
                A8A47370151A825B004123FF /* Vector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Vector.h; sourceTree = "<group>"; };
                A8A47371151A825B004123FF /* VectorTraits.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VectorTraits.h; sourceTree = "<group>"; };
                A8A47372151A825B004123FF /* VMTags.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VMTags.h; sourceTree = "<group>"; };
-               A8A4737A151A825B004123FF /* WTFThreadData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WTFThreadData.cpp; sourceTree = "<group>"; };
-               A8A4737B151A825B004123FF /* WTFThreadData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WTFThreadData.h; sourceTree = "<group>"; };
                A8A4748B151A8264004123FF /* config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = config.h; sourceTree = "<group>"; };
                A9A4727F151A825A004123FF /* DisallowCType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DisallowCType.h; sourceTree = "<group>"; };
                AD7C434A1DD2A4A70026888B /* Expected.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Expected.h; sourceTree = "<group>"; };
                                0FE4479B1B7AAA03009498EB /* WordLock.h */,
                                E4A0AD371A96245500536DF6 /* WorkQueue.cpp */,
                                E4A0AD381A96245500536DF6 /* WorkQueue.h */,
-                               A8A4737A151A825B004123FF /* WTFThreadData.cpp */,
-                               A8A4737B151A825B004123FF /* WTFThreadData.h */,
                        );
                        path = wtf;
                        sourceTree = "<group>";
                                E4A0AD391A96245500536DF6 /* WorkQueue.cpp in Sources */,
                                E4A0AD3D1A96253C00536DF6 /* WorkQueueCocoa.cpp in Sources */,
                                A8A47445151A825B004123FF /* WTFString.cpp in Sources */,
-                               A8A47486151A825B004123FF /* WTFThreadData.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index e15d45c..5a75688 100644 (file)
@@ -150,7 +150,6 @@ set(WTF_HEADERS
     Variant.h
     Vector.h
     VectorTraits.h
-    WTFThreadData.h
     WallTime.h
     WeakPtr.h
     WordLock.h
@@ -254,7 +253,6 @@ set(WTF_SOURCES
     Threading.cpp
     TimeWithDynamicClockType.cpp
     UUID.cpp
-    WTFThreadData.cpp
     WallTime.cpp
     WordLock.cpp
     WorkQueue.cpp
index 4514854..b8e987b 100644 (file)
@@ -28,7 +28,6 @@
 
 #include <wtf/Atomics.h>
 #include <wtf/Compiler.h>
-#include <wtf/Threading.h>
 
 namespace WTF {
 
index 8438d2e..0cbe5fa 100644 (file)
@@ -27,6 +27,7 @@
 
 #include <wtf/LockAlgorithm.h>
 #include <wtf/ParkingLot.h>
+#include <wtf/Threading.h>
 
 // It's a good idea to avoid including this header in too many places, so that it's possible to change
 // the lock algorithm slow path without recompiling the world. Right now this should be included in two
index 14b3467..ab92134 100644 (file)
@@ -33,7 +33,7 @@
 #include <stdint.h>
 #include <wtf/Function.h>
 #include <wtf/Optional.h>
-#include <wtf/Threading.h>
+#include <wtf/ThreadingPrimitives.h>
 
 namespace WTF {
 
index cc1a21b..f8fed88 100644 (file)
@@ -31,7 +31,7 @@
 #include "HashFunctions.h"
 #include "StringPrintStream.h"
 #include "ThreadSpecific.h"
-#include "ThreadingPrimitives.h"
+#include "Threading.h"
 #include "Vector.h"
 #include "WeakRandom.h"
 #include "WordLock.h"
index 064f2f0..8cb4622 100644 (file)
@@ -30,7 +30,6 @@
 
 #include "Assertions.h"
 #include "DataLog.h"
-#include "WTFThreadData.h"
 
 // Define the following flag if you want to collect stats on every single
 // checkpoint. By default, we only log checkpoints that establish new
@@ -59,7 +58,7 @@ int StackStats::s_maxLayoutReentryDepth = 0;
 
 StackStats::PerThreadStats::PerThreadStats()
 {
-    const StackBounds& stack = wtfThreadData().stack();
+    const StackBounds& stack = Thread::current().stack();
     m_reentryDepth = 0;
     m_stackStart = (char*)stack.origin();
     m_currentCheckPoint = 0;
@@ -70,9 +69,9 @@ StackStats::PerThreadStats::PerThreadStats()
 StackStats::CheckPoint::CheckPoint()
 {
     std::lock_guard<StaticLock> lock(StackStats::s_sharedMutex);
-    WTFThreadData* threadData = const_cast<WTFThreadData*>(&wtfThreadData());
-    StackStats::PerThreadStats& t = threadData->stackStats();
-    const StackBounds& stack = threadData->stack();
+    Thread& thread = Thread::current();
+    StackStats::PerThreadStats& t = thread.stackStats();
+    const StackBounds& stack = thread.stack();
 
     bool isGrowingDownward = stack.isGrowingDownward();
     bool needToLog = false;
@@ -128,8 +127,8 @@ StackStats::CheckPoint::CheckPoint()
 StackStats::CheckPoint::~CheckPoint()
 {
     std::lock_guard<StaticLock> lock(StackStats::s_sharedMutex);
-    WTFThreadData* threadData = const_cast<WTFThreadData*>(&wtfThreadData());
-    StackStats::PerThreadStats& t = threadData->stackStats();
+    Thread& thread = Thread::current();
+    StackStats::PerThreadStats& t = thread.stackStats();
 
     // Pop to previous checkpoint:
     t.m_currentCheckPoint = m_prev;
@@ -138,7 +137,7 @@ StackStats::CheckPoint::~CheckPoint()
     // Log this checkpoint if needed:
 #if ENABLE(VERBOSE_STACK_STATS)
     if (!m_prev) {
-        const StackBounds& stack = threadData->stack();
+        const StackBounds& stack = thread.stack();
         bool isGrowingDownward = stack.isGrowingDownward();
 
         char* current = reinterpret_cast<char*>(this);
@@ -159,9 +158,9 @@ StackStats::CheckPoint::~CheckPoint()
 void StackStats::probe()
 {
     std::lock_guard<StaticLock> lock(StackStats::s_sharedMutex);
-    WTFThreadData* threadData = const_cast<WTFThreadData*>(&wtfThreadData());
-    StackStats::PerThreadStats& t = threadData->stackStats();
-    const StackBounds& stack = threadData->stack();
+    Thread& thread = Thread::current();
+    StackStats::PerThreadStats& t = thread.stackStats();
+    const StackBounds& stack = thread.stack();
 
     bool isGrowingDownward = stack.isGrowingDownward();
 
@@ -220,9 +219,9 @@ StackStats::LayoutCheckPoint::LayoutCheckPoint()
     StackStats::probe();
 
     std::lock_guard<StaticLock> lock(StackStats::s_sharedMutex);
-    WTFThreadData* threadData = const_cast<WTFThreadData*>(&wtfThreadData());
-    StackStats::PerThreadStats& t = threadData->stackStats();
-    const StackBounds& stack = threadData->stack();
+    Thread& thread = Thread::current();
+    StackStats::PerThreadStats& t = thread.stackStats();
+    const StackBounds& stack = thread.stack();
 
     bool isGrowingDownward = stack.isGrowingDownward();
 
index e2a31be..02b0e14 100644 (file)
@@ -43,4 +43,9 @@ ThreadHolder::~ThreadHolder()
     m_thread->didExit();
 }
 
+ThreadHolder& ThreadHolder::initializeCurrent()
+{
+    return initialize(Thread::createCurrentThread());
+}
+
 } // namespace WTF
index b2f8de6..e4fe668 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#pragma once
+#ifndef ThreadHolder_h
+#define ThreadHolder_h
 
+#include <wtf/Ref.h>
+#include <wtf/RefPtr.h>
 #include <wtf/ThreadSpecific.h>
-#include <wtf/Threading.h>
 
 namespace WTF {
 
+class Thread;
+
 // Holds Thread in the thread-specific storage. The destructor of this holder reliably destroy Thread.
 // For pthread, it employs pthreads-specific 2-pass destruction to reliably remove Thread.
 // For Windows, we use thread_local to defer thread holder destruction. It assumes regular ThreadSpecific
@@ -47,23 +51,26 @@ public:
 
     // One time initialization for this class as a whole.
     // This method must be called before initialize() and it is not thread-safe.
-    static void initializeOnce();
+    WTF_EXPORT_PRIVATE static void initializeOnce();
 
     // Creates and puts an instance of ThreadHolder into thread-specific storage.
-    static void initialize(Thread&);
+    WTF_EXPORT_PRIVATE static ThreadHolder& initialize(Ref<Thread>&&);
+    WTF_EXPORT_PRIVATE static ThreadHolder& initializeCurrent();
 
     // Returns 0 if thread-specific storage was not initialized.
-    static ThreadHolder* current();
+    static ThreadHolder& current();
+    static ThreadHolder* currentMayBeNull();
 
     Thread& thread() { return m_thread.get(); }
 
 #if OS(WINDOWS)
+    WTF_EXPORT_PRIVATE static ThreadHolder* currentDying();
     static RefPtr<Thread> get(ThreadIdentifier);
 #endif
 
 private:
-    ThreadHolder(Thread& thread)
-        : m_thread(thread)
+    ThreadHolder(Ref<Thread>&& thread)
+        : m_thread(WTFMove(thread))
         , m_isDestroyedOnce(false)
     {
     }
@@ -77,7 +84,39 @@ private:
 
     Ref<Thread> m_thread;
     bool m_isDestroyedOnce;
-    static ThreadSpecificKey m_key;
+    static WTF_EXPORTDATA ThreadSpecificKey m_key;
 };
 
+inline ThreadHolder* ThreadHolder::currentMayBeNull()
+{
+#if !HAVE(FAST_TLS)
+    ASSERT(m_key != InvalidThreadSpecificKey);
+    return static_cast<ThreadHolder*>(threadSpecificGet(m_key));
+#else
+    return static_cast<ThreadHolder*>(_pthread_getspecific_direct(WTF_THREAD_DATA_KEY));
+#endif
+}
+
+inline ThreadHolder& ThreadHolder::current()
+{
+    // WRT WebCore:
+    //    ThreadHolder is used on main thread before it could possibly be used
+    //    on secondary ones, so there is no need for synchronization here.
+    // WRT JavaScriptCore:
+    //    Thread::current() is initially called from initializeThreading(), ensuring
+    //    this is initially called in a pthread_once locked context.
+#if !HAVE(FAST_TLS)
+    if (UNLIKELY(ThreadHolder::m_key == InvalidThreadSpecificKey))
+        initializeOnce();
+#endif
+    if (auto* holder = currentMayBeNull())
+        return *holder;
+#if OS(WINDOWS)
+    if (auto* holder = currentDying())
+        return *holder;
+#endif
+    return initializeCurrent();
+}
+
 } // namespace WTF
+#endif // ThreadHolder_h
index 20e5e88..856841e 100644 (file)
@@ -41,36 +41,41 @@ void ThreadHolder::initializeOnce()
     threadSpecificKeyCreate(&m_key, destruct);
 }
 
-ThreadHolder* ThreadHolder::current()
+ThreadHolder& ThreadHolder::initialize(Ref<Thread>&& thread)
 {
+    auto* holder = new ThreadHolder(WTFMove(thread));
+#if !HAVE(FAST_TLS)
+    // Ideally we'd have this as a release assert everywhere, but that would hurt performance.
+    // Having this release assert here means that we will catch "didn't call
+    // WTF::initializeThreading() soon enough" bugs in release mode.
     ASSERT(m_key != InvalidThreadSpecificKey);
-    return static_cast<ThreadHolder*>(threadSpecificGet(m_key));
-}
-
-void ThreadHolder::initialize(Thread& thread)
-{
-    if (!current()) {
-        // Ideally we'd have this as a release assert everywhere, but that would hurt performance.
-        // Having this release assert here means that we will catch "didn't call
-        // WTF::initializeThreading() soon enough" bugs in release mode.
-        ASSERT(m_key != InvalidThreadSpecificKey);
-        threadSpecificSet(m_key, new ThreadHolder(thread));
-    }
+    threadSpecificSet(m_key, holder);
+#else
+    _pthread_setspecific_direct(WTF_THREAD_DATA_KEY, holder);
+    pthread_key_init_np(WTF_THREAD_DATA_KEY, &destruct);
+#endif
+    return *holder;
 }
 
 void ThreadHolder::destruct(void* data)
 {
-    ThreadHolder* threadIdentifierData = static_cast<ThreadHolder*>(data);
-    ASSERT(threadIdentifierData);
+    ThreadHolder* holder = static_cast<ThreadHolder*>(data);
+    ASSERT(holder);
 
-    if (threadIdentifierData->m_isDestroyedOnce) {
-        delete threadIdentifierData;
+    if (holder->m_isDestroyedOnce) {
+        delete holder;
         return;
     }
 
-    threadIdentifierData->m_isDestroyedOnce = true;
+    holder->m_isDestroyedOnce = true;
     // Re-setting the value for key causes another destruct() call after all other thread-specific destructors were called.
-    threadSpecificSet(m_key, threadIdentifierData);
+#if !HAVE(FAST_TLS)
+    ASSERT(m_key != InvalidThreadSpecificKey);
+    threadSpecificSet(m_key, holder);
+#else
+    _pthread_setspecific_direct(WTF_THREAD_DATA_KEY, holder);
+    pthread_key_init_np(WTF_THREAD_DATA_KEY, &destruct);
+#endif
 }
 
 } // namespace WTF
index f06b62f..98b2c28 100644 (file)
@@ -56,15 +56,9 @@ void ThreadHolder::initializeOnce()
     threadSpecificKeyCreate(&m_key, destruct);
 }
 
-ThreadHolder* ThreadHolder::current()
+ThreadHolder* ThreadHolder::currentDying()
 {
     ASSERT(m_key != InvalidThreadSpecificKey);
-    ThreadHolder* holder = static_cast<ThreadHolder*>(threadSpecificGet(m_key));
-    if (holder) {
-        ASSERT(holder != InvalidThreadHolder);
-        return holder;
-    }
-
     // After FLS is destroyed, this map offers the value until the second thread exit callback is called.
     std::lock_guard<std::mutex> locker(threadMapMutex());
     return threadMap().get(currentThread());
@@ -80,21 +74,21 @@ RefPtr<Thread> ThreadHolder::get(ThreadIdentifier id)
     return nullptr;
 }
 
-void ThreadHolder::initialize(Thread& thread)
+ThreadHolder& ThreadHolder::initialize(Ref<Thread>&& thread)
 {
-    if (!current()) {
-        // Ideally we'd have this as a release assert everywhere, but that would hurt performance.
-        // Having this release assert here means that we will catch "didn't call
-        // WTF::initializeThreading() soon enough" bugs in release mode.
-        ASSERT(m_key != InvalidThreadSpecificKey);
-        // FIXME: Remove this workaround code once <rdar://problem/31793213> is fixed.
-        auto* holder = new ThreadHolder(thread);
-        threadSpecificSet(m_key, holder);
-        {
-            std::lock_guard<std::mutex> locker(threadMapMutex());
-            threadMap().add(thread.id(), holder);
-        }
+    // Ideally we'd have this as a release assert everywhere, but that would hurt performance.
+    // Having this release assert here means that we will catch "didn't call
+    // WTF::initializeThreading() soon enough" bugs in release mode.
+    ASSERT(m_key != InvalidThreadSpecificKey);
+    // FIXME: Remove this workaround code once <rdar://problem/31793213> is fixed.
+    auto id = thread->id();
+    auto* holder = new ThreadHolder(WTFMove(thread));
+    threadSpecificSet(m_key, holder);
+    {
+        std::lock_guard<std::mutex> locker(threadMapMutex());
+        threadMap().add(id, holder);
     }
+    return *holder;
 }
 
 void ThreadHolder::destruct(void* data)
index b3ffa7c..2e11384 100644 (file)
@@ -37,7 +37,7 @@
 #include <wtf/ThreadHolder.h>
 #include <wtf/ThreadMessage.h>
 #include <wtf/ThreadingPrimitives.h>
-#include <wtf/WTFThreadData.h>
+#include <wtf/text/AtomicStringTable.h>
 #include <wtf/text/StringView.h>
 
 #if HAVE(QOS_CLASSES)
@@ -94,6 +94,13 @@ const char* Thread::normalizeThreadName(const char* threadName)
 #endif
 }
 
+void Thread::initializeInThread()
+{
+    m_savedLastStackTop = stack().origin();
+    AtomicStringTable::create(*this);
+    m_currentAtomicStringTable = m_defaultAtomicStringTable;
+}
+
 void Thread::entryPoint(NewThreadContext* newThreadContext)
 {
     Function<void()> function;
@@ -105,7 +112,7 @@ void Thread::entryPoint(NewThreadContext* newThreadContext)
         ASSERT(context->stage == NewThreadContext::Stage::EstablishedHandle);
 
         // Initialize thread holder with established ID.
-        ThreadHolder::initialize(context->thread.get());
+        ThreadHolder::initialize(context->thread.copyRef());
 
         Thread::initializeCurrentThreadInternal(context->name);
         function = WTFMove(context->entryPoint);
@@ -116,6 +123,7 @@ void Thread::entryPoint(NewThreadContext* newThreadContext)
         context->stage = NewThreadContext::Stage::Initialized;
         context->condition.signal();
 #endif
+        context->thread->initializeInThread();
     }
 
     ASSERT(!Thread::current().stack().isEmpty());
@@ -155,14 +163,6 @@ RefPtr<Thread> Thread::create(const char* name, Function<void()>&& entryPoint)
     return WTFMove(thread);
 }
 
-Thread* Thread::currentMayBeNull()
-{
-    ThreadHolder* data = ThreadHolder::current();
-    if (data)
-        return &data->thread();
-    return nullptr;
-}
-
 static bool shouldRemoveThreadFromThreadGroup()
 {
 #if OS(WINDOWS)
@@ -197,6 +197,9 @@ void Thread::didExit()
             threadGroup->m_threads.remove(*this);
         }
     }
+    if (m_atomicStringTableDestructor)
+        m_atomicStringTableDestructor(m_defaultAtomicStringTable);
+
     // We would like to say "thread is exited" after unregistering threads from thread groups.
     // So we need to separate m_isShuttingDown from m_didExit.
     std::lock_guard<std::mutex> locker(m_mutex);
@@ -277,9 +280,8 @@ void initializeThreading()
 {
     static std::once_flag initializeKey;
     std::call_once(initializeKey, [] {
-        ThreadHolder::initializeOnce();
         initializeRandomNumberGenerator();
-        wtfThreadData();
+        Thread::current();
         initializeDates();
         Thread::initializePlatformThreading();
     });
index ff50bfa..2c65632 100644 (file)
@@ -39,6 +39,8 @@
 #include <wtf/PlatformRegisters.h>
 #include <wtf/RefPtr.h>
 #include <wtf/StackBounds.h>
+#include <wtf/StackStats.h>
+#include <wtf/ThreadHolder.h>
 #include <wtf/ThreadSafeRefCounted.h>
 #include <wtf/Vector.h>
 
 namespace WTF {
 
 class AbstractLocker;
+class AtomicStringTable;
 class ThreadMessageData;
 
-enum class ThreadGroupAddResult;
+using AtomicStringTableDestructor = void (*)(AtomicStringTable*);
 
-using ThreadIdentifier = uint32_t;
-typedef void (*ThreadFunction)(void* argument);
+enum class ThreadGroupAddResult;
 
 class ThreadGroup;
 class ThreadHolder;
@@ -65,6 +67,7 @@ class Thread : public ThreadSafeRefCounted<Thread> {
 public:
     friend class ThreadGroup;
     friend class ThreadHolder;
+    friend class AtomicStringTable;
 
     WTF_EXPORT_PRIVATE ~Thread();
 
@@ -73,8 +76,7 @@ public:
     WTF_EXPORT_PRIVATE static RefPtr<Thread> create(const char* threadName, Function<void()>&&);
 
     // Returns Thread object.
-    WTF_EXPORT_PRIVATE static Thread& current();
-    static Thread* currentMayBeNull();
+    static Thread& current();
 
     // Returns ThreadIdentifier directly. It is useful if the user only cares about identity
     // of threads. At that time, users should know that holding this ThreadIdentifier does not ensure
@@ -141,6 +143,47 @@ public:
         return m_stack;
     }
 
+    AtomicStringTable* atomicStringTable()
+    {
+        return m_currentAtomicStringTable;
+    }
+
+    AtomicStringTable* setCurrentAtomicStringTable(AtomicStringTable* atomicStringTable)
+    {
+        AtomicStringTable* oldAtomicStringTable = m_currentAtomicStringTable;
+        m_currentAtomicStringTable = atomicStringTable;
+        return oldAtomicStringTable;
+    }
+
+#if ENABLE(STACK_STATS)
+    StackStats::PerThreadStats& stackStats()
+    {
+        return m_stackStats;
+    }
+#endif
+
+    void* savedStackPointerAtVMEntry()
+    {
+        return m_savedStackPointerAtVMEntry;
+    }
+
+    void setSavedStackPointerAtVMEntry(void* stackPointerAtVMEntry)
+    {
+        m_savedStackPointerAtVMEntry = stackPointerAtVMEntry;
+    }
+
+    void* savedLastStackTop()
+    {
+        return m_savedLastStackTop;
+    }
+
+    void setSavedLastStackTop(void* lastStackTop)
+    {
+        m_savedLastStackTop = lastStackTop;
+    }
+
+    void* m_apiData { nullptr };
+
 #if OS(DARWIN)
     mach_port_t machThread() { return m_platformThread; }
 #endif
@@ -150,13 +193,16 @@ public:
 protected:
     Thread();
 
+    static Ref<Thread> createCurrentThread();
+    void initializeInThread();
+
     // Internal platform-specific Thread establishment implementation.
     bool establishHandle(NewThreadContext*);
 
 #if USE(PTHREADS)
-    void establishPlatformSpecificHandle(pthread_t);
+    void establishPlatformSpecificHandle(PlatformThreadHandle);
 #else
-    void establishPlatformSpecificHandle(HANDLE, ThreadIdentifier);
+    void establishPlatformSpecificHandle(PlatformThreadHandle, ThreadIdentifier);
 #endif
 
 #if USE(PTHREADS) && !OS(DARWIN)
@@ -197,22 +243,25 @@ protected:
     Vector<std::weak_ptr<ThreadGroup>> m_threadGroups;
     bool m_isShuttingDown { false };
     bool m_didExit { false };
-#if USE(PTHREADS)
-    pthread_t m_handle;
-
+    PlatformThreadHandle m_handle;
 #if OS(DARWIN)
     mach_port_t m_platformThread;
-#else
+#elif USE(PTHREADS)
     sem_t m_semaphoreForSuspendResume;
     PlatformRegisters m_platformRegisters;
     unsigned m_suspendCount { 0 };
     std::atomic<bool> m_suspended { false };
 #endif
-#elif OS(WINDOWS)
-    HANDLE m_handle { INVALID_HANDLE_VALUE };
-#else
-#error Unknown System
+
+    AtomicStringTable* m_currentAtomicStringTable { nullptr };
+    AtomicStringTable* m_defaultAtomicStringTable { nullptr };
+    AtomicStringTableDestructor m_atomicStringTableDestructor { nullptr };
+
+#if ENABLE(STACK_STATS)
+    StackStats::PerThreadStats m_stackStats;
 #endif
+    void* m_savedStackPointerAtVMEntry { nullptr };
+    void* m_savedLastStackTop;
 };
 
 // This function can be called from any threads.
@@ -223,6 +272,10 @@ inline ThreadIdentifier currentThread()
     return Thread::currentID();
 }
 
+inline Thread& Thread::current()
+{
+    return ThreadHolder::current().thread();
+}
 
 // FIXME: The following functions remain because they are used from WebKit Windows support library,
 // WebKitQuartzCoreAdditions.dll. When updating the support library, we should use new API instead
index 30c499f..6e88aa6 100644 (file)
@@ -45,6 +45,9 @@
 
 namespace WTF {
 
+using ThreadIdentifier = uint32_t;
+using ThreadFunction = void (*)(void* argument);
+
 #if USE(PTHREADS)
 using PlatformThreadHandle = pthread_t;
 using PlatformMutex = pthread_mutex_t;
index 12d7c71..cfeeabb 100644 (file)
@@ -286,18 +286,16 @@ void Thread::detach()
         didBecomeDetached();
 }
 
-Thread& Thread::current()
-{
-    if (Thread* current = currentMayBeNull())
-        return *current;
 
+Ref<Thread> Thread::createCurrentThread()
+{
     // Not a WTF-created thread, ThreadIdentifier is not established yet.
     Ref<Thread> thread = adoptRef(*new Thread());
     thread->establishPlatformSpecificHandle(pthread_self());
     thread->m_stack = StackBounds::currentThreadStackBounds();
-    ThreadHolder::initialize(thread.get());
+    thread->initializeInThread();
     initializeCurrentThreadEvenIfNonWTFCreated();
-    return thread.get();
+    return thread;
 }
 
 ThreadIdentifier Thread::currentID()
index 0523a2e..e931dff 100644 (file)
@@ -243,11 +243,8 @@ size_t Thread::getRegisters(PlatformRegisters& registers)
     return sizeof(CONTEXT);
 }
 
-Thread& Thread::current()
+Ref<Thread> Thread::createCurrentThread()
 {
-    if (Thread* current = currentMayBeNull())
-        return *current;
-
     // Not a WTF-created thread, ThreadIdentifier is not established yet.
     Ref<Thread> thread = adoptRef(*new Thread());
 
@@ -257,9 +254,9 @@ Thread& Thread::current()
 
     thread->establishPlatformSpecificHandle(handle, currentID());
     thread->m_stack = StackBounds::currentThreadStackBounds();
-    ThreadHolder::initialize(thread.get());
+    thread->initializeInThread();
     initializeCurrentThreadEvenIfNonWTFCreated();
-    return thread.get();
+    return thread;
 }
 
 ThreadIdentifier Thread::currentID()
diff --git a/Source/WTF/wtf/WTFThreadData.cpp b/Source/WTF/wtf/WTFThreadData.cpp
deleted file mode 100644 (file)
index 73e77d2..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (C) 2008, 2010 Apple Inc. All Rights Reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
- *
- */
-
-#include "config.h"
-#include "WTFThreadData.h"
-
-#include <wtf/text/AtomicStringTable.h>
-
-#if USE(WEB_THREAD)
-#include <wtf/MainThread.h>
-#endif
-
-namespace WTF {
-
-#if !HAVE(FAST_TLS)
-ThreadSpecific<WTFThreadData>* WTFThreadData::staticData;
-#endif
-
-WTFThreadData::WTFThreadData()
-    : m_stackBounds(StackBounds::currentThreadStackBounds())
-    , m_savedLastStackTop(stack().origin())
-{
-    AtomicStringTable::create(*this);
-    m_currentAtomicStringTable = m_defaultAtomicStringTable;
-}
-
-WTFThreadData::~WTFThreadData()
-{
-    if (m_atomicStringTableDestructor)
-        m_atomicStringTableDestructor(m_defaultAtomicStringTable);
-}
-
-#if HAVE(FAST_TLS)
-WTFThreadData& WTFThreadData::createAndRegisterForGetspecificDirect()
-{
-    WTFThreadData* data = new WTFThreadData;
-    _pthread_setspecific_direct(WTF_THREAD_DATA_KEY, data);
-    pthread_key_init_np(WTF_THREAD_DATA_KEY, [](void* data){
-        delete static_cast<WTFThreadData*>(data);
-    });
-    return *data;
-}
-#endif
-
-} // namespace WTF
diff --git a/Source/WTF/wtf/WTFThreadData.h b/Source/WTF/wtf/WTFThreadData.h
deleted file mode 100644 (file)
index 2a5ff81..0000000
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * Copyright (C) 2008-2017 Apple Inc. All Rights Reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
- *
- */
-
-#ifndef WTFThreadData_h
-#define WTFThreadData_h
-
-#include <wtf/FastTLS.h>
-#include <wtf/Noncopyable.h>
-#include <wtf/StackBounds.h>
-#include <wtf/StackStats.h>
-#include <wtf/ThreadSpecific.h>
-
-namespace WTF {
-
-class AtomicStringTable;
-
-typedef void (*AtomicStringTableDestructor)(AtomicStringTable*);
-
-class WTFThreadData {
-    WTF_MAKE_NONCOPYABLE(WTFThreadData);
-public:
-    WTF_EXPORT_PRIVATE WTFThreadData();
-    WTF_EXPORT_PRIVATE ~WTFThreadData();
-
-    AtomicStringTable* atomicStringTable()
-    {
-        return m_currentAtomicStringTable;
-    }
-
-    AtomicStringTable* setCurrentAtomicStringTable(AtomicStringTable* atomicStringTable)
-    {
-        AtomicStringTable* oldAtomicStringTable = m_currentAtomicStringTable;
-        m_currentAtomicStringTable = atomicStringTable;
-        return oldAtomicStringTable;
-    }
-
-    const StackBounds& stack()
-    {
-        return m_stackBounds;
-    }
-
-#if ENABLE(STACK_STATS)
-    StackStats::PerThreadStats& stackStats()
-    {
-        return m_stackStats;
-    }
-#endif
-
-    void* savedStackPointerAtVMEntry()
-    {
-        return m_savedStackPointerAtVMEntry;
-    }
-
-    void setSavedStackPointerAtVMEntry(void* stackPointerAtVMEntry)
-    {
-        m_savedStackPointerAtVMEntry = stackPointerAtVMEntry;
-    }
-
-    void* savedLastStackTop()
-    {
-        return m_savedLastStackTop;
-    }
-
-    void setSavedLastStackTop(void* lastStackTop)
-    {
-        m_savedLastStackTop = lastStackTop;
-    }
-
-    void* m_apiData { nullptr };
-
-private:
-    AtomicStringTable* m_currentAtomicStringTable { nullptr };
-    AtomicStringTable* m_defaultAtomicStringTable { nullptr };
-    AtomicStringTableDestructor m_atomicStringTableDestructor { nullptr };
-
-    StackBounds m_stackBounds;
-#if ENABLE(STACK_STATS)
-    StackStats::PerThreadStats m_stackStats;
-#endif
-    void* m_savedStackPointerAtVMEntry { nullptr };
-    void* m_savedLastStackTop;
-
-#if HAVE(FAST_TLS)
-    WTF_EXPORT_PRIVATE static WTFThreadData& createAndRegisterForGetspecificDirect();
-#else
-    static WTF_EXPORTDATA ThreadSpecific<WTFThreadData>* staticData;
-#endif
-
-    friend WTFThreadData& wtfThreadData();
-    friend class AtomicStringTable;
-};
-
-inline WTFThreadData& wtfThreadData()
-{
-    // WRT WebCore:
-    //    WTFThreadData is used on main thread before it could possibly be used
-    //    on secondary ones, so there is no need for synchronization here.
-    // WRT JavaScriptCore:
-    //    wtfThreadData() is initially called from initializeThreading(), ensuring
-    //    this is initially called in a pthread_once locked context.
-#if !HAVE(FAST_TLS)
-    if (!WTFThreadData::staticData)
-        WTFThreadData::staticData = new ThreadSpecific<WTFThreadData>;
-    return **WTFThreadData::staticData;
-#else
-    if (WTFThreadData* data = static_cast<WTFThreadData*>(_pthread_getspecific_direct(WTF_THREAD_DATA_KEY)))
-        return *data;
-    return WTFThreadData::createAndRegisterForGetspecificDirect();
-#endif
-}
-
-} // namespace WTF
-
-using WTF::WTFThreadData;
-using WTF::wtfThreadData;
-using WTF::AtomicStringTable;
-
-#endif // WTFThreadData_h
index a4e03de..2a06512 100644 (file)
 #include "config.h"
 #include "AtomicString.h"
 
-#include "IntegerToStringConversion.h"
-#include "MainThread.h"
+#include <mutex>
+#include <wtf/MainThread.h>
+#include <wtf/text/IntegerToStringConversion.h>
+
 #include "dtoa.h"
 
 namespace WTF {
index 3522485..063e4ee 100644 (file)
@@ -32,7 +32,6 @@
 #include "StringHash.h"
 #include "StringPrintStream.h"
 #include "Threading.h"
-#include "WTFThreadData.h"
 #include <wtf/unicode/UTF8.h>
 
 #if USE(WEB_THREAD)
@@ -72,7 +71,7 @@ using StringTableImpl = HashSet<StringImpl*>;
 
 static ALWAYS_INLINE StringTableImpl& stringTable()
 {
-    return wtfThreadData().atomicStringTable()->table();
+    return Thread::current().atomicStringTable()->table();
 }
 
 template<typename T, typename HashTranslator>
index fe8a488..f6d78f2 100644 (file)
 
 #include <wtf/HashSet.h>
 #include <wtf/MainThread.h>
-#include <wtf/WTFThreadData.h>
+#include <wtf/Threading.h>
 
 namespace WTF {
 
-void AtomicStringTable::create(WTFThreadData& data)
+void AtomicStringTable::create(Thread& thread)
 {
 #if USE(WEB_THREAD)
     // On iOS, one AtomicStringTable is shared between the main UI thread and the WebThread.
@@ -37,17 +37,17 @@ void AtomicStringTable::create(WTFThreadData& data)
 
     bool currentThreadIsWebThread = isWebThread();
     if (currentThreadIsWebThread || isUIThread())
-        data.m_defaultAtomicStringTable = sharedStringTable;
+        thread.m_defaultAtomicStringTable = sharedStringTable;
     else
-        data.m_defaultAtomicStringTable = new AtomicStringTable;
+        thread.m_defaultAtomicStringTable = new AtomicStringTable;
 
     // We do the following so that its destruction happens only
     // once - on the main UI thread.
     if (!currentThreadIsWebThread)
-        data.m_atomicStringTableDestructor = AtomicStringTable::destroy;
+        thread.m_atomicStringTableDestructor = AtomicStringTable::destroy;
 #else
-    data.m_defaultAtomicStringTable = new AtomicStringTable;
-    data.m_atomicStringTableDestructor = AtomicStringTable::destroy;
+    thread.m_defaultAtomicStringTable = new AtomicStringTable;
+    thread.m_atomicStringTableDestructor = AtomicStringTable::destroy;
 #endif // USE(WEB_THREAD)
 }
 
index 944ae92..d3bc9ce 100644 (file)
 #define WTF_AtomicStringTable_h
 
 #include <wtf/HashSet.h>
-#include <wtf/WTFThreadData.h>
 #include <wtf/text/StringImpl.h>
 
 namespace WTF {
 
 class StringImpl;
+class Thread;
 
 class AtomicStringTable {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     WTF_EXPORT_PRIVATE ~AtomicStringTable();
 
-    static void create(WTFThreadData&);
+    static void create(Thread&);
     HashSet<StringImpl*>& table() { return m_table; }
 
 private:
@@ -46,5 +46,6 @@ private:
 };
 
 }
+using WTF::AtomicStringTable;
 
 #endif
index f62f057..8fb5d80 100644 (file)
@@ -1,3 +1,21 @@
+2017-07-31  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        Merge WTFThreadData to Thread::current
+        https://bugs.webkit.org/show_bug.cgi?id=174716
+
+        Reviewed by Sam Weinig.
+
+        Use Thread::current() instead.
+
+        * fileapi/AsyncFileStream.cpp:
+        * platform/ThreadGlobalData.cpp:
+        (WebCore::ThreadGlobalData::ThreadGlobalData):
+        * platform/graphics/cocoa/WebCoreDecompressionSession.h:
+        * platform/ios/wak/WebCoreThread.mm:
+        (StartWebThread):
+        * workers/WorkerThread.cpp:
+        (WebCore::WorkerThread::workerThread):
+
 2017-07-31  Xabier Rodriguez Calvar  <calvaris@igalia.com>
 
         Created a bool pretty printer at WTF for debugging purposes
index 8a0230b..63b1e0e 100644 (file)
@@ -41,6 +41,7 @@
 #include <wtf/MainThread.h>
 #include <wtf/MessageQueue.h>
 #include <wtf/NeverDestroyed.h>
+#include <wtf/Threading.h>
 
 namespace WebCore {
 
index b8faf5a..773829d 100644 (file)
@@ -35,7 +35,6 @@
 #include <wtf/MainThread.h>
 #include <wtf/ThreadSpecific.h>
 #include <wtf/Threading.h>
-#include <wtf/WTFThreadData.h>
 #include <wtf/text/StringImpl.h>
 
 #if PLATFORM(MAC)
@@ -66,7 +65,7 @@ ThreadGlobalData::ThreadGlobalData()
     // any other thread, and is only called once per thread - this makes this a convenient
     // point to call methods that internally perform a one-time initialization that is not
     // threadsafe.
-    wtfThreadData();
+    Thread::current();
     StringImpl::empty();
 }
 
index 66e8e99..ec2711b 100644 (file)
@@ -28,6 +28,7 @@
 #if USE(VIDEOTOOLBOX)
 
 #include <CoreMedia/CMTime.h>
+#include <functional>
 #include <wtf/Lock.h>
 #include <wtf/MediaTime.h>
 #include <wtf/OSObjectPtr.h>
index 6122b4f..c8f05a1 100644 (file)
@@ -702,7 +702,7 @@ static void StartWebThread()
 {
     webThreadStarted = TRUE;
 
-    // ThreadGlobalData touches AtomicString, which requires WTFThreadData and Threading initialization.
+    // ThreadGlobalData touches AtomicString, which requires Threading initialization.
     WTF::initializeThreading();
 
     // Initialize AtomicString on the main thread.
index 425c924..681a1ef 100644 (file)
@@ -216,7 +216,7 @@ void WorkerThread::workerThread()
     // We cannot let any objects survive past thread exit, because no other thread will run GC or otherwise destroy them.
     workerGlobalScopeToDelete = nullptr;
 
-    // Clean up WebCore::ThreadGlobalData before WTF::WTFThreadData goes away!
+    // Clean up WebCore::ThreadGlobalData before WTF::Thread goes away!
     threadGlobalData().destroy();
 
     // The thread object may be already destroyed from notification now, don't try to access "this".