haikuwebkit/Source/WTF/wtf/PlatformRegisters.h

164 lines
5.3 KiB
C
Raw Permalink Normal View History

[Re-landing] Change JSLock to stash PlatformThread instead of std::thread::id. https://bugs.webkit.org/show_bug.cgi?id=168996 Reviewed by Filip Pizlo and Saam Barati. PlatformThread is more useful because it allows us to: 1. find the MachineThreads::Thread which is associated with it. 2. suspend / resume threads. 3. send a signal to a thread. We can't do those with std::thread::id. We will need one or more of these capabilities to implement non-polling VM traps later. Update: Since we don't have a canonical "uninitialized" value for PlatformThread, we now have a JSLock::m_hasOwnerThread flag that is set to true if and only the m_ownerThread value is valid. JSLock::currentThreadIsHoldingLock() now checks JSLock::m_hasOwnerThread before doing the thread identity comparison. * JavaScriptCore.xcodeproj/project.pbxproj: * heap/MachineStackMarker.cpp: (JSC::MachineThreads::Thread::createForCurrentThread): (JSC::MachineThreads::machineThreadForCurrentThread): (JSC::MachineThreads::removeThread): (JSC::MachineThreads::Thread::suspend): (JSC::MachineThreads::tryCopyOtherThreadStacks): (JSC::getCurrentPlatformThread): Deleted. * heap/MachineStackMarker.h: * runtime/JSCellInlines.h: (JSC::JSCell::classInfo): * runtime/JSLock.cpp: (JSC::JSLock::JSLock): (JSC::JSLock::lock): (JSC::JSLock::unlock): (JSC::JSLock::currentThreadIsHoldingLock): Deleted. * runtime/JSLock.h: (JSC::JSLock::ownerThread): (JSC::JSLock::currentThreadIsHoldingLock): * runtime/PlatformThread.h: Added. (JSC::currentPlatformThread): * runtime/VM.cpp: (JSC::VM::~VM): * runtime/VM.h: (JSC::VM::ownerThread): * runtime/Watchdog.cpp: (JSC::Watchdog::setTimeLimit): (JSC::Watchdog::shouldTerminate): (JSC::Watchdog::startTimer): (JSC::Watchdog::stopTimer): * tools/JSDollarVMPrototype.cpp: (JSC::JSDollarVMPrototype::currentThreadOwnsJSLock): * tools/VMInspector.cpp: Canonical link: https://commits.webkit.org/186036@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@213238 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-03-01 20:15:08 +00:00
/*
[WTF] Introduce Thread class and use RefPtr<Thread> and align Windows Threading implementation semantics to Pthread one https://bugs.webkit.org/show_bug.cgi?id=170502 Reviewed by Mark Lam. Source/JavaScriptCore: * API/tests/CompareAndSwapTest.cpp: (testCompareAndSwap): * JavaScriptCore.xcodeproj/project.pbxproj: * b3/air/testair.cpp: * b3/testb3.cpp: (JSC::B3::run): * bytecode/SuperSampler.cpp: (JSC::initializeSuperSampler): * dfg/DFGWorklist.cpp: * disassembler/Disassembler.cpp: * heap/Heap.cpp: (JSC::Heap::lastChanceToFinalize): (JSC::Heap::notifyIsSafeToCollect): * heap/Heap.h: * heap/MachineStackMarker.cpp: (JSC::MachineThreads::~MachineThreads): (JSC::MachineThreads::addCurrentThread): (JSC::MachineThreads::removeThread): (JSC::MachineThreads::removeThreadIfFound): (JSC::MachineThreads::MachineThread::MachineThread): (JSC::MachineThreads::MachineThread::getRegisters): (JSC::MachineThreads::MachineThread::Registers::stackPointer): (JSC::MachineThreads::MachineThread::Registers::framePointer): (JSC::MachineThreads::MachineThread::Registers::instructionPointer): (JSC::MachineThreads::MachineThread::Registers::llintPC): (JSC::MachineThreads::MachineThread::captureStack): (JSC::MachineThreads::tryCopyOtherThreadStack): (JSC::MachineThreads::tryCopyOtherThreadStacks): (pthreadSignalHandlerSuspendResume): Deleted. (JSC::threadData): Deleted. (JSC::MachineThreads::Thread::Thread): Deleted. (JSC::MachineThreads::Thread::createForCurrentThread): Deleted. (JSC::MachineThreads::Thread::operator==): Deleted. (JSC::MachineThreads::machineThreadForCurrentThread): Deleted. (JSC::MachineThreads::ThreadData::ThreadData): Deleted. (JSC::MachineThreads::ThreadData::~ThreadData): Deleted. (JSC::MachineThreads::ThreadData::suspend): Deleted. (JSC::MachineThreads::ThreadData::resume): Deleted. (JSC::MachineThreads::ThreadData::getRegisters): Deleted. (JSC::MachineThreads::ThreadData::Registers::stackPointer): Deleted. (JSC::MachineThreads::ThreadData::Registers::framePointer): Deleted. (JSC::MachineThreads::ThreadData::Registers::instructionPointer): Deleted. (JSC::MachineThreads::ThreadData::Registers::llintPC): Deleted. (JSC::MachineThreads::ThreadData::freeRegisters): Deleted. (JSC::MachineThreads::ThreadData::captureStack): Deleted. * heap/MachineStackMarker.h: (JSC::MachineThreads::MachineThread::suspend): (JSC::MachineThreads::MachineThread::resume): (JSC::MachineThreads::MachineThread::threadID): (JSC::MachineThreads::MachineThread::stackBase): (JSC::MachineThreads::MachineThread::stackEnd): (JSC::MachineThreads::threadsListHead): (JSC::MachineThreads::Thread::operator!=): Deleted. (JSC::MachineThreads::Thread::suspend): Deleted. (JSC::MachineThreads::Thread::resume): Deleted. (JSC::MachineThreads::Thread::getRegisters): Deleted. (JSC::MachineThreads::Thread::freeRegisters): Deleted. (JSC::MachineThreads::Thread::captureStack): Deleted. (JSC::MachineThreads::Thread::platformThread): Deleted. (JSC::MachineThreads::Thread::stackBase): Deleted. (JSC::MachineThreads::Thread::stackEnd): Deleted. * jit/ICStats.cpp: (JSC::ICStats::ICStats): (JSC::ICStats::~ICStats): * jit/ICStats.h: * jsc.cpp: (functionDollarAgentStart): (startTimeoutThreadIfNeeded): * runtime/JSLock.cpp: (JSC::JSLock::lock): * runtime/JSLock.h: (JSC::JSLock::ownerThread): (JSC::JSLock::currentThreadIsHoldingLock): * runtime/SamplingProfiler.cpp: (JSC::FrameWalker::isValidFramePointer): (JSC::SamplingProfiler::SamplingProfiler): (JSC::SamplingProfiler::createThreadIfNecessary): (JSC::SamplingProfiler::takeSample): * runtime/SamplingProfiler.h: * runtime/VM.h: (JSC::VM::ownerThread): * runtime/VMTraps.cpp: (JSC::findActiveVMAndStackBounds): (JSC::VMTraps::SignalSender::send): (JSC::VMTraps::fireTrap): Source/WebCore: Mechanical change. Use Thread:: APIs. * Modules/indexeddb/server/IDBServer.cpp: (WebCore::IDBServer::IDBServer::IDBServer): * Modules/indexeddb/server/IDBServer.h: * Modules/webaudio/AsyncAudioDecoder.cpp: (WebCore::AsyncAudioDecoder::AsyncAudioDecoder): (WebCore::AsyncAudioDecoder::~AsyncAudioDecoder): (WebCore::AsyncAudioDecoder::runLoop): * Modules/webaudio/AsyncAudioDecoder.h: * Modules/webaudio/OfflineAudioDestinationNode.cpp: (WebCore::OfflineAudioDestinationNode::OfflineAudioDestinationNode): (WebCore::OfflineAudioDestinationNode::uninitialize): (WebCore::OfflineAudioDestinationNode::startRendering): * Modules/webaudio/OfflineAudioDestinationNode.h: * Modules/webdatabase/Database.cpp: (WebCore::Database::securityOrigin): * Modules/webdatabase/DatabaseThread.cpp: (WebCore::DatabaseThread::start): (WebCore::DatabaseThread::databaseThread): (WebCore::DatabaseThread::recordDatabaseOpen): (WebCore::DatabaseThread::recordDatabaseClosed): * Modules/webdatabase/DatabaseThread.h: (WebCore::DatabaseThread::getThreadID): * bindings/js/GCController.cpp: (WebCore::GCController::garbageCollectOnAlternateThreadForDebugging): * fileapi/AsyncFileStream.cpp: (WebCore::callOnFileThread): * loader/icon/IconDatabase.cpp: (WebCore::IconDatabase::open): (WebCore::IconDatabase::close): * loader/icon/IconDatabase.h: * page/ResourceUsageThread.cpp: (WebCore::ResourceUsageThread::createThreadIfNeeded): * page/ResourceUsageThread.h: * page/scrolling/ScrollingThread.cpp: (WebCore::ScrollingThread::ScrollingThread): (WebCore::ScrollingThread::isCurrentThread): (WebCore::ScrollingThread::createThreadIfNeeded): (WebCore::ScrollingThread::threadCallback): * page/scrolling/ScrollingThread.h: * platform/audio/HRTFDatabaseLoader.cpp: (WebCore::HRTFDatabaseLoader::HRTFDatabaseLoader): (WebCore::HRTFDatabaseLoader::loadAsynchronously): (WebCore::HRTFDatabaseLoader::waitForLoaderThreadCompletion): * platform/audio/HRTFDatabaseLoader.h: * platform/audio/ReverbConvolver.cpp: (WebCore::ReverbConvolver::ReverbConvolver): (WebCore::ReverbConvolver::~ReverbConvolver): * platform/audio/ReverbConvolver.h: * platform/audio/gstreamer/AudioFileReaderGStreamer.cpp: (WebCore::createBusFromAudioFile): (WebCore::createBusFromInMemoryAudioFile): * platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp: (ResourceHandleStreamingClient::ResourceHandleStreamingClient): (ResourceHandleStreamingClient::~ResourceHandleStreamingClient): * platform/network/cf/LoaderRunLoopCF.cpp: (WebCore::loaderRunLoop): * platform/network/curl/CurlDownload.cpp: (WebCore::CurlDownloadManager::startThreadIfNeeded): (WebCore::CurlDownloadManager::stopThread): * platform/network/curl/CurlDownload.h: * platform/network/curl/SocketStreamHandleImpl.h: * platform/network/curl/SocketStreamHandleImplCurl.cpp: (WebCore::SocketStreamHandleImpl::startThread): (WebCore::SocketStreamHandleImpl::stopThread): * workers/WorkerThread.cpp: (WebCore::WorkerThread::WorkerThread): (WebCore::WorkerThread::start): (WebCore::WorkerThread::workerThread): * workers/WorkerThread.h: (WebCore::WorkerThread::threadID): Source/WebKit: Mechanical change. Use Thread:: APIs. * Storage/StorageThread.cpp: (WebCore::StorageThread::StorageThread): (WebCore::StorageThread::~StorageThread): (WebCore::StorageThread::start): (WebCore::StorageThread::dispatch): (WebCore::StorageThread::terminate): * Storage/StorageThread.h: Source/WebKit2: Mechanical change. Use Thread:: APIs. * NetworkProcess/NetworkProcess.cpp: (WebKit::NetworkProcess::initializeNetworkProcess): * NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp: (WebKit::NetworkCache::IOChannel::readSyncInThread): * Platform/IPC/Connection.cpp: (IPC::Connection::processIncomingMessage): * Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.h: (WebKit::XPCServiceInitializer): * UIProcess/linux/MemoryPressureMonitor.cpp: (WebKit::MemoryPressureMonitor::MemoryPressureMonitor): * WebProcess/WebProcess.cpp: (WebKit::WebProcess::initializeWebProcess): Source/WTF: This patch is refactoring of WTF Threading mechanism to merge JavaScriptCore's threading extension to WTF Threading. Previously, JavaScriptCore requires richer threading features (such as suspending and resuming threads), and they are implemented for PlatformThread in JavaScriptCore. But these features should be implemented in WTF Threading side instead of maintaining JSC's own threading features too. This patch removes these features from JSC and move it to WTF Threading. However, current WTF Threading has one problem: Windows version of WTF Threading has different semantics from Pthreads one. In Windows WTF Threading, we cannot perform any operation after the target thread is detached: WTF Threading stop tracking the state of the thread once the thread is detached. But this is not the same to Pthreads one. In Pthreads, pthread_detach just means that the resource of the thread will be destroyed automatically. While some operations like pthread_join will be rejected, some operations like pthread_kill will be accepted. The problem is that detached thread can be suspended and resumed in JSC. For example, in jsc.cpp, we start the worker thread and detach it immediately. In worker thread, we will create VM and thus concurrent GC will suspend and resume the detached thread. However, in Windows WTF Threading, we have no reference to the detached thread. Thus we cannot perform suspend and resume operations onto the detached thread. To solve the problem, we change Windows Threading mechanism drastically to align it to the Pthread semantics. In the new Threading, we have RefPtr<Thread> class. It holds a handle to a platform thread. We can perform threading operations with this class. For example, Thread::suspend is offered. And we use destructor of the thread local variable to release the resources held by RefPtr<Thread>. In Windows, Thread::detach does nothing because the resource will be destroyed automatically by RefPtr<Thread>. To do so, we introduce ThreadHolder for Windows. This is similar to the previous ThreadIdentifierData for Pthreads. It holds RefPtr<Thread> in the thread local storage (technically, it is Fiber Local Storage in Windows). Thread::current() will return this reference. The problematic situation is that the order of the deallocation of the thread local storage is not defined. So we should not touch thread local storage in the destructor of the thread local storage. To avoid such edge cases, we have currentThread() / Thread::currentID() APIs. They are safe to be called even in the destructor of the other thread local storage. And in Windows, in the FLS destructor, we will create the thread_local variable to defer the destruction of the ThreadHolder. We ensure that this destructor is called after the other FLS destructors are called in Windows 10. This patch is performance neutral. * WTF.xcodeproj/project.pbxproj: * benchmarks/ConditionSpeedTest.cpp: * benchmarks/LockFairnessTest.cpp: * benchmarks/LockSpeedTest.cpp: * wtf/AutomaticThread.cpp: (WTF::AutomaticThread::start): * wtf/CMakeLists.txt: * wtf/MainThread.h: * wtf/MemoryPressureHandler.h: * wtf/ParallelJobsGeneric.cpp: (WTF::ParallelEnvironment::ThreadPrivate::tryLockFor): (WTF::ParallelEnvironment::ThreadPrivate::workerThread): * wtf/ParallelJobsGeneric.h: (WTF::ParallelEnvironment::ThreadPrivate::ThreadPrivate): Deleted. * wtf/ParkingLot.cpp: (WTF::ParkingLot::forEachImpl): * wtf/ParkingLot.h: (WTF::ParkingLot::forEach): * wtf/PlatformRegisters.h: Renamed from Source/JavaScriptCore/runtime/PlatformThread.h. * wtf/RefPtr.h: (WTF::RefPtr::RefPtr): * wtf/ThreadFunctionInvocation.h: (WTF::ThreadFunctionInvocation::ThreadFunctionInvocation): * wtf/ThreadHolder.cpp: Added. (WTF::ThreadHolder::~ThreadHolder): (WTF::ThreadHolder::initialize): * wtf/ThreadHolder.h: Renamed from Source/WTF/wtf/ThreadIdentifierDataPthreads.h. (WTF::ThreadHolder::thread): (WTF::ThreadHolder::ThreadHolder): * wtf/ThreadHolderPthreads.cpp: Renamed from Source/WTF/wtf/ThreadIdentifierDataPthreads.cpp. (WTF::ThreadHolder::initializeOnce): (WTF::ThreadHolder::current): (WTF::ThreadHolder::destruct): * wtf/ThreadHolderWin.cpp: Added. (WTF::threadMapMutex): (WTF::threadMap): (WTF::ThreadHolder::initializeOnce): (WTF::ThreadHolder::current): (WTF::ThreadHolder::destruct): * wtf/ThreadSpecific.h: * wtf/Threading.cpp: (WTF::Thread::normalizeThreadName): (WTF::threadEntryPoint): (WTF::Thread::create): (WTF::Thread::setCurrentThreadIsUserInteractive): (WTF::Thread::setCurrentThreadIsUserInitiated): (WTF::Thread::setGlobalMaxQOSClass): (WTF::Thread::adjustedQOSClass): (WTF::Thread::dump): (WTF::initializeThreading): (WTF::normalizeThreadName): Deleted. (WTF::createThread): Deleted. (WTF::setCurrentThreadIsUserInteractive): Deleted. (WTF::setCurrentThreadIsUserInitiated): Deleted. (WTF::setGlobalMaxQOSClass): Deleted. (WTF::adjustedQOSClass): Deleted. * wtf/Threading.h: (WTF::Thread::id): (WTF::Thread::operator==): (WTF::Thread::operator!=): (WTF::Thread::joinableState): (WTF::Thread::didBecomeDetached): (WTF::Thread::didJoin): (WTF::Thread::hasExited): (WTF::currentThread): * wtf/ThreadingPthreads.cpp: (WTF::Thread::Thread): (WTF::Thread::~Thread): (WTF::Thread::signalHandlerSuspendResume): (WTF::Thread::initializePlatformThreading): (WTF::initializeCurrentThreadEvenIfNonWTFCreated): (WTF::wtfThreadEntryPoint): (WTF::Thread::createInternal): (WTF::Thread::initializeCurrentThreadInternal): (WTF::Thread::changePriority): (WTF::Thread::waitForCompletion): (WTF::Thread::detach): (WTF::Thread::current): (WTF::Thread::currentID): (WTF::Thread::signal): (WTF::Thread::resume): (WTF::Thread::getRegisters): (WTF::Thread::didExit): (WTF::Thread::establish): (WTF::PthreadState::PthreadState): Deleted. (WTF::PthreadState::joinableState): Deleted. (WTF::PthreadState::pthreadHandle): Deleted. (WTF::PthreadState::didBecomeDetached): Deleted. (WTF::PthreadState::didExit): Deleted. (WTF::PthreadState::didJoin): Deleted. (WTF::PthreadState::hasExited): Deleted. (WTF::threadMapMutex): Deleted. (WTF::initializeThreading): Deleted. (WTF::threadMap): Deleted. (WTF::identifierByPthreadHandle): Deleted. (WTF::establishIdentifierForPthreadHandle): Deleted. (WTF::pthreadHandleForIdentifierWithLockAlreadyHeld): Deleted. (WTF::createThreadInternal): Deleted. (WTF::initializeCurrentThreadInternal): Deleted. (WTF::changeThreadPriority): Deleted. (WTF::waitForThreadCompletion): Deleted. (WTF::detachThread): Deleted. (WTF::threadDidExit): Deleted. (WTF::currentThread): Deleted. (WTF::signalThread): Deleted. * wtf/ThreadingWin.cpp: (WTF::Thread::Thread): (WTF::Thread::~Thread): (WTF::Thread::initializeCurrentThreadInternal): (WTF::Thread::initializePlatformThreading): (WTF::wtfThreadEntryPoint): (WTF::Thread::createInternal): (WTF::Thread::changePriority): (WTF::Thread::waitForCompletion): (WTF::Thread::detach): (WTF::Thread::resume): (WTF::Thread::getRegisters): (WTF::Thread::current): (WTF::Thread::currentID): (WTF::Thread::didExit): (WTF::Thread::establish): (WTF::initializeCurrentThreadInternal): Deleted. (WTF::threadMapMutex): Deleted. (WTF::initializeThreading): Deleted. (WTF::threadMap): Deleted. (WTF::storeThreadHandleByIdentifier): Deleted. (WTF::threadHandleForIdentifier): Deleted. (WTF::clearThreadHandleForIdentifier): Deleted. (WTF::createThreadInternal): Deleted. (WTF::changeThreadPriority): Deleted. (WTF::waitForThreadCompletion): Deleted. (WTF::detachThread): Deleted. (WTF::currentThread): Deleted. * wtf/WorkQueue.cpp: (WTF::WorkQueue::concurrentApply): * wtf/WorkQueue.h: * wtf/cocoa/WorkQueueCocoa.cpp: (WTF::dispatchQOSClass): * wtf/generic/WorkQueueGeneric.cpp: (WorkQueue::platformInitialize): (WorkQueue::platformInvalidate): * wtf/linux/MemoryPressureHandlerLinux.cpp: (WTF::MemoryPressureHandler::EventFDPoller::EventFDPoller): (WTF::MemoryPressureHandler::EventFDPoller::~EventFDPoller): * wtf/win/MainThreadWin.cpp: (WTF::initializeMainThreadPlatform): Tools: Mechanical change. Use Thread:: APIs. * DumpRenderTree/JavaScriptThreading.cpp: (runJavaScriptThread): (startJavaScriptThreads): (stopJavaScriptThreads): * DumpRenderTree/mac/DumpRenderTree.mm: (testThreadIdentifierMap): * TestWebKitAPI/Tests/WTF/Condition.cpp: * TestWebKitAPI/Tests/WTF/Lock.cpp: (TestWebKitAPI::runLockTest): * TestWebKitAPI/Tests/WTF/ParkingLot.cpp: Canonical link: https://commits.webkit.org/187690@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@215265 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-04-12 12:08:29 +00:00
* Copyright (C) 2017 Yusuke Suzuki <utatane.tea@gmail.com>
Open source arm64e code. https://bugs.webkit.org/show_bug.cgi?id=196012 <rdar://problem/49066237> Reviewed by Keith Miller. Source/JavaScriptCore: * JavaScriptCore.xcodeproj/project.pbxproj: * Sources.txt: * assembler/ARM64EAssembler.h: Added. (JSC::ARM64EAssembler::encodeGroup1): (JSC::ARM64EAssembler::encodeGroup2): (JSC::ARM64EAssembler::encodeGroup4): (JSC::ARM64EAssembler::pacia1716): (JSC::ARM64EAssembler::pacib1716): (JSC::ARM64EAssembler::autia1716): (JSC::ARM64EAssembler::autib1716): (JSC::ARM64EAssembler::paciaz): (JSC::ARM64EAssembler::paciasp): (JSC::ARM64EAssembler::pacibz): (JSC::ARM64EAssembler::pacibsp): (JSC::ARM64EAssembler::autiaz): (JSC::ARM64EAssembler::autiasp): (JSC::ARM64EAssembler::autibz): (JSC::ARM64EAssembler::autibsp): (JSC::ARM64EAssembler::xpaclri): (JSC::ARM64EAssembler::pacia): (JSC::ARM64EAssembler::pacib): (JSC::ARM64EAssembler::pacda): (JSC::ARM64EAssembler::pacdb): (JSC::ARM64EAssembler::autia): (JSC::ARM64EAssembler::autib): (JSC::ARM64EAssembler::autda): (JSC::ARM64EAssembler::autdb): (JSC::ARM64EAssembler::paciza): (JSC::ARM64EAssembler::pacizb): (JSC::ARM64EAssembler::pacdza): (JSC::ARM64EAssembler::pacdzb): (JSC::ARM64EAssembler::autiza): (JSC::ARM64EAssembler::autizb): (JSC::ARM64EAssembler::autdza): (JSC::ARM64EAssembler::autdzb): (JSC::ARM64EAssembler::xpaci): (JSC::ARM64EAssembler::xpacd): (JSC::ARM64EAssembler::pacga): (JSC::ARM64EAssembler::braa): (JSC::ARM64EAssembler::brab): (JSC::ARM64EAssembler::blraa): (JSC::ARM64EAssembler::blrab): (JSC::ARM64EAssembler::braaz): (JSC::ARM64EAssembler::brabz): (JSC::ARM64EAssembler::blraaz): (JSC::ARM64EAssembler::blrabz): (JSC::ARM64EAssembler::retaa): (JSC::ARM64EAssembler::retab): (JSC::ARM64EAssembler::eretaa): (JSC::ARM64EAssembler::eretab): (JSC::ARM64EAssembler::linkPointer): (JSC::ARM64EAssembler::repatchPointer): (JSC::ARM64EAssembler::setPointer): (JSC::ARM64EAssembler::readPointer): (JSC::ARM64EAssembler::readCallTarget): (JSC::ARM64EAssembler::ret): * assembler/MacroAssembler.cpp: * assembler/MacroAssembler.h: * assembler/MacroAssemblerARM64.cpp: * assembler/MacroAssemblerARM64E.h: Added. (JSC::MacroAssemblerARM64E::tagReturnAddress): (JSC::MacroAssemblerARM64E::untagReturnAddress): (JSC::MacroAssemblerARM64E::tagPtr): (JSC::MacroAssemblerARM64E::untagPtr): (JSC::MacroAssemblerARM64E::removePtrTag): (JSC::MacroAssemblerARM64E::callTrustedPtr): (JSC::MacroAssemblerARM64E::call): (JSC::MacroAssemblerARM64E::callRegister): (JSC::MacroAssemblerARM64E::jump): * dfg/DFGOSRExit.cpp: (JSC::DFG::reifyInlinedCallFrames): * dfg/DFGOSRExitCompilerCommon.cpp: (JSC::DFG::reifyInlinedCallFrames): * ftl/FTLThunks.cpp: (JSC::FTL::genericGenerationThunkGenerator): * jit/CCallHelpers.h: (JSC::CCallHelpers::prepareForTailCallSlow): * jit/CallFrameShuffler.cpp: (JSC::CallFrameShuffler::prepareForTailCall): * jit/ExecutableAllocator.cpp: (JSC::ExecutableAllocator::allocate): * jit/ThunkGenerators.cpp: (JSC::arityFixupGenerator): * llint/LLIntOfflineAsmConfig.h: * llint/LowLevelInterpreter.asm: * llint/LowLevelInterpreter64.asm: * runtime/ClassInfo.h: * runtime/InitializeThreading.cpp: (JSC::initializeThreading): * runtime/JSCPtrTag.cpp: Added. (JSC::tagForPtr): (JSC::ptrTagName): (JSC::initializePtrTagLookup): * runtime/JSCPtrTag.h: (JSC::initializePtrTagLookup): * runtime/Options.cpp: (JSC::recomputeDependentOptions): Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/BlockPtr.h: * wtf/Platform.h: * wtf/PlatformRegisters.cpp: Added. (WTF::threadStateLRInternal): (WTF::threadStatePCInternal): * wtf/PlatformRegisters.h: * wtf/PointerPreparations.h: * wtf/PtrTag.cpp: Added. (WTF::tagForPtr): (WTF::ptrTagName): (WTF::registerPtrTagLookup): (WTF::reportBadTag): * wtf/PtrTag.h: (WTF::removeCodePtrTag): (WTF::tagCodePtrImpl): (WTF::tagCodePtr): (WTF::untagCodePtrImplHelper): (WTF::untagCodePtrImpl): (WTF::untagCodePtr): (WTF::retagCodePtrImplHelper): (WTF::retagCodePtrImpl): (WTF::retagCodePtr): (WTF::tagCFunctionPtrImpl): (WTF::tagCFunctionPtr): (WTF::untagCFunctionPtrImpl): (WTF::untagCFunctionPtr): (WTF::tagInt): (WTF::assertIsCFunctionPtr): (WTF::assertIsNullOrCFunctionPtr): (WTF::assertIsNotTagged): (WTF::assertIsTagged): (WTF::assertIsNullOrTagged): (WTF::isTaggedWith): (WTF::assertIsTaggedWith): (WTF::assertIsNullOrTaggedWith): (WTF::usesPointerTagging): (WTF::registerPtrTagLookup): (WTF::reportBadTag): (WTF::tagForPtr): Deleted. Canonical link: https://commits.webkit.org/210319@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@243254 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-03-20 23:32:26 +00:00
* Copyright (C) 2019 Apple Inc. All rights reserved.
[Re-landing] Change JSLock to stash PlatformThread instead of std::thread::id. https://bugs.webkit.org/show_bug.cgi?id=168996 Reviewed by Filip Pizlo and Saam Barati. PlatformThread is more useful because it allows us to: 1. find the MachineThreads::Thread which is associated with it. 2. suspend / resume threads. 3. send a signal to a thread. We can't do those with std::thread::id. We will need one or more of these capabilities to implement non-polling VM traps later. Update: Since we don't have a canonical "uninitialized" value for PlatformThread, we now have a JSLock::m_hasOwnerThread flag that is set to true if and only the m_ownerThread value is valid. JSLock::currentThreadIsHoldingLock() now checks JSLock::m_hasOwnerThread before doing the thread identity comparison. * JavaScriptCore.xcodeproj/project.pbxproj: * heap/MachineStackMarker.cpp: (JSC::MachineThreads::Thread::createForCurrentThread): (JSC::MachineThreads::machineThreadForCurrentThread): (JSC::MachineThreads::removeThread): (JSC::MachineThreads::Thread::suspend): (JSC::MachineThreads::tryCopyOtherThreadStacks): (JSC::getCurrentPlatformThread): Deleted. * heap/MachineStackMarker.h: * runtime/JSCellInlines.h: (JSC::JSCell::classInfo): * runtime/JSLock.cpp: (JSC::JSLock::JSLock): (JSC::JSLock::lock): (JSC::JSLock::unlock): (JSC::JSLock::currentThreadIsHoldingLock): Deleted. * runtime/JSLock.h: (JSC::JSLock::ownerThread): (JSC::JSLock::currentThreadIsHoldingLock): * runtime/PlatformThread.h: Added. (JSC::currentPlatformThread): * runtime/VM.cpp: (JSC::VM::~VM): * runtime/VM.h: (JSC::VM::ownerThread): * runtime/Watchdog.cpp: (JSC::Watchdog::setTimeLimit): (JSC::Watchdog::shouldTerminate): (JSC::Watchdog::startTimer): (JSC::Watchdog::stopTimer): * tools/JSDollarVMPrototype.cpp: (JSC::JSDollarVMPrototype::currentThreadOwnsJSLock): * tools/VMInspector.cpp: Canonical link: https://commits.webkit.org/186036@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@213238 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-03-01 20:15:08 +00:00
*
* 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.
*
[WTF] Introduce Thread class and use RefPtr<Thread> and align Windows Threading implementation semantics to Pthread one https://bugs.webkit.org/show_bug.cgi?id=170502 Reviewed by Mark Lam. Source/JavaScriptCore: * API/tests/CompareAndSwapTest.cpp: (testCompareAndSwap): * JavaScriptCore.xcodeproj/project.pbxproj: * b3/air/testair.cpp: * b3/testb3.cpp: (JSC::B3::run): * bytecode/SuperSampler.cpp: (JSC::initializeSuperSampler): * dfg/DFGWorklist.cpp: * disassembler/Disassembler.cpp: * heap/Heap.cpp: (JSC::Heap::lastChanceToFinalize): (JSC::Heap::notifyIsSafeToCollect): * heap/Heap.h: * heap/MachineStackMarker.cpp: (JSC::MachineThreads::~MachineThreads): (JSC::MachineThreads::addCurrentThread): (JSC::MachineThreads::removeThread): (JSC::MachineThreads::removeThreadIfFound): (JSC::MachineThreads::MachineThread::MachineThread): (JSC::MachineThreads::MachineThread::getRegisters): (JSC::MachineThreads::MachineThread::Registers::stackPointer): (JSC::MachineThreads::MachineThread::Registers::framePointer): (JSC::MachineThreads::MachineThread::Registers::instructionPointer): (JSC::MachineThreads::MachineThread::Registers::llintPC): (JSC::MachineThreads::MachineThread::captureStack): (JSC::MachineThreads::tryCopyOtherThreadStack): (JSC::MachineThreads::tryCopyOtherThreadStacks): (pthreadSignalHandlerSuspendResume): Deleted. (JSC::threadData): Deleted. (JSC::MachineThreads::Thread::Thread): Deleted. (JSC::MachineThreads::Thread::createForCurrentThread): Deleted. (JSC::MachineThreads::Thread::operator==): Deleted. (JSC::MachineThreads::machineThreadForCurrentThread): Deleted. (JSC::MachineThreads::ThreadData::ThreadData): Deleted. (JSC::MachineThreads::ThreadData::~ThreadData): Deleted. (JSC::MachineThreads::ThreadData::suspend): Deleted. (JSC::MachineThreads::ThreadData::resume): Deleted. (JSC::MachineThreads::ThreadData::getRegisters): Deleted. (JSC::MachineThreads::ThreadData::Registers::stackPointer): Deleted. (JSC::MachineThreads::ThreadData::Registers::framePointer): Deleted. (JSC::MachineThreads::ThreadData::Registers::instructionPointer): Deleted. (JSC::MachineThreads::ThreadData::Registers::llintPC): Deleted. (JSC::MachineThreads::ThreadData::freeRegisters): Deleted. (JSC::MachineThreads::ThreadData::captureStack): Deleted. * heap/MachineStackMarker.h: (JSC::MachineThreads::MachineThread::suspend): (JSC::MachineThreads::MachineThread::resume): (JSC::MachineThreads::MachineThread::threadID): (JSC::MachineThreads::MachineThread::stackBase): (JSC::MachineThreads::MachineThread::stackEnd): (JSC::MachineThreads::threadsListHead): (JSC::MachineThreads::Thread::operator!=): Deleted. (JSC::MachineThreads::Thread::suspend): Deleted. (JSC::MachineThreads::Thread::resume): Deleted. (JSC::MachineThreads::Thread::getRegisters): Deleted. (JSC::MachineThreads::Thread::freeRegisters): Deleted. (JSC::MachineThreads::Thread::captureStack): Deleted. (JSC::MachineThreads::Thread::platformThread): Deleted. (JSC::MachineThreads::Thread::stackBase): Deleted. (JSC::MachineThreads::Thread::stackEnd): Deleted. * jit/ICStats.cpp: (JSC::ICStats::ICStats): (JSC::ICStats::~ICStats): * jit/ICStats.h: * jsc.cpp: (functionDollarAgentStart): (startTimeoutThreadIfNeeded): * runtime/JSLock.cpp: (JSC::JSLock::lock): * runtime/JSLock.h: (JSC::JSLock::ownerThread): (JSC::JSLock::currentThreadIsHoldingLock): * runtime/SamplingProfiler.cpp: (JSC::FrameWalker::isValidFramePointer): (JSC::SamplingProfiler::SamplingProfiler): (JSC::SamplingProfiler::createThreadIfNecessary): (JSC::SamplingProfiler::takeSample): * runtime/SamplingProfiler.h: * runtime/VM.h: (JSC::VM::ownerThread): * runtime/VMTraps.cpp: (JSC::findActiveVMAndStackBounds): (JSC::VMTraps::SignalSender::send): (JSC::VMTraps::fireTrap): Source/WebCore: Mechanical change. Use Thread:: APIs. * Modules/indexeddb/server/IDBServer.cpp: (WebCore::IDBServer::IDBServer::IDBServer): * Modules/indexeddb/server/IDBServer.h: * Modules/webaudio/AsyncAudioDecoder.cpp: (WebCore::AsyncAudioDecoder::AsyncAudioDecoder): (WebCore::AsyncAudioDecoder::~AsyncAudioDecoder): (WebCore::AsyncAudioDecoder::runLoop): * Modules/webaudio/AsyncAudioDecoder.h: * Modules/webaudio/OfflineAudioDestinationNode.cpp: (WebCore::OfflineAudioDestinationNode::OfflineAudioDestinationNode): (WebCore::OfflineAudioDestinationNode::uninitialize): (WebCore::OfflineAudioDestinationNode::startRendering): * Modules/webaudio/OfflineAudioDestinationNode.h: * Modules/webdatabase/Database.cpp: (WebCore::Database::securityOrigin): * Modules/webdatabase/DatabaseThread.cpp: (WebCore::DatabaseThread::start): (WebCore::DatabaseThread::databaseThread): (WebCore::DatabaseThread::recordDatabaseOpen): (WebCore::DatabaseThread::recordDatabaseClosed): * Modules/webdatabase/DatabaseThread.h: (WebCore::DatabaseThread::getThreadID): * bindings/js/GCController.cpp: (WebCore::GCController::garbageCollectOnAlternateThreadForDebugging): * fileapi/AsyncFileStream.cpp: (WebCore::callOnFileThread): * loader/icon/IconDatabase.cpp: (WebCore::IconDatabase::open): (WebCore::IconDatabase::close): * loader/icon/IconDatabase.h: * page/ResourceUsageThread.cpp: (WebCore::ResourceUsageThread::createThreadIfNeeded): * page/ResourceUsageThread.h: * page/scrolling/ScrollingThread.cpp: (WebCore::ScrollingThread::ScrollingThread): (WebCore::ScrollingThread::isCurrentThread): (WebCore::ScrollingThread::createThreadIfNeeded): (WebCore::ScrollingThread::threadCallback): * page/scrolling/ScrollingThread.h: * platform/audio/HRTFDatabaseLoader.cpp: (WebCore::HRTFDatabaseLoader::HRTFDatabaseLoader): (WebCore::HRTFDatabaseLoader::loadAsynchronously): (WebCore::HRTFDatabaseLoader::waitForLoaderThreadCompletion): * platform/audio/HRTFDatabaseLoader.h: * platform/audio/ReverbConvolver.cpp: (WebCore::ReverbConvolver::ReverbConvolver): (WebCore::ReverbConvolver::~ReverbConvolver): * platform/audio/ReverbConvolver.h: * platform/audio/gstreamer/AudioFileReaderGStreamer.cpp: (WebCore::createBusFromAudioFile): (WebCore::createBusFromInMemoryAudioFile): * platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp: (ResourceHandleStreamingClient::ResourceHandleStreamingClient): (ResourceHandleStreamingClient::~ResourceHandleStreamingClient): * platform/network/cf/LoaderRunLoopCF.cpp: (WebCore::loaderRunLoop): * platform/network/curl/CurlDownload.cpp: (WebCore::CurlDownloadManager::startThreadIfNeeded): (WebCore::CurlDownloadManager::stopThread): * platform/network/curl/CurlDownload.h: * platform/network/curl/SocketStreamHandleImpl.h: * platform/network/curl/SocketStreamHandleImplCurl.cpp: (WebCore::SocketStreamHandleImpl::startThread): (WebCore::SocketStreamHandleImpl::stopThread): * workers/WorkerThread.cpp: (WebCore::WorkerThread::WorkerThread): (WebCore::WorkerThread::start): (WebCore::WorkerThread::workerThread): * workers/WorkerThread.h: (WebCore::WorkerThread::threadID): Source/WebKit: Mechanical change. Use Thread:: APIs. * Storage/StorageThread.cpp: (WebCore::StorageThread::StorageThread): (WebCore::StorageThread::~StorageThread): (WebCore::StorageThread::start): (WebCore::StorageThread::dispatch): (WebCore::StorageThread::terminate): * Storage/StorageThread.h: Source/WebKit2: Mechanical change. Use Thread:: APIs. * NetworkProcess/NetworkProcess.cpp: (WebKit::NetworkProcess::initializeNetworkProcess): * NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp: (WebKit::NetworkCache::IOChannel::readSyncInThread): * Platform/IPC/Connection.cpp: (IPC::Connection::processIncomingMessage): * Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.h: (WebKit::XPCServiceInitializer): * UIProcess/linux/MemoryPressureMonitor.cpp: (WebKit::MemoryPressureMonitor::MemoryPressureMonitor): * WebProcess/WebProcess.cpp: (WebKit::WebProcess::initializeWebProcess): Source/WTF: This patch is refactoring of WTF Threading mechanism to merge JavaScriptCore's threading extension to WTF Threading. Previously, JavaScriptCore requires richer threading features (such as suspending and resuming threads), and they are implemented for PlatformThread in JavaScriptCore. But these features should be implemented in WTF Threading side instead of maintaining JSC's own threading features too. This patch removes these features from JSC and move it to WTF Threading. However, current WTF Threading has one problem: Windows version of WTF Threading has different semantics from Pthreads one. In Windows WTF Threading, we cannot perform any operation after the target thread is detached: WTF Threading stop tracking the state of the thread once the thread is detached. But this is not the same to Pthreads one. In Pthreads, pthread_detach just means that the resource of the thread will be destroyed automatically. While some operations like pthread_join will be rejected, some operations like pthread_kill will be accepted. The problem is that detached thread can be suspended and resumed in JSC. For example, in jsc.cpp, we start the worker thread and detach it immediately. In worker thread, we will create VM and thus concurrent GC will suspend and resume the detached thread. However, in Windows WTF Threading, we have no reference to the detached thread. Thus we cannot perform suspend and resume operations onto the detached thread. To solve the problem, we change Windows Threading mechanism drastically to align it to the Pthread semantics. In the new Threading, we have RefPtr<Thread> class. It holds a handle to a platform thread. We can perform threading operations with this class. For example, Thread::suspend is offered. And we use destructor of the thread local variable to release the resources held by RefPtr<Thread>. In Windows, Thread::detach does nothing because the resource will be destroyed automatically by RefPtr<Thread>. To do so, we introduce ThreadHolder for Windows. This is similar to the previous ThreadIdentifierData for Pthreads. It holds RefPtr<Thread> in the thread local storage (technically, it is Fiber Local Storage in Windows). Thread::current() will return this reference. The problematic situation is that the order of the deallocation of the thread local storage is not defined. So we should not touch thread local storage in the destructor of the thread local storage. To avoid such edge cases, we have currentThread() / Thread::currentID() APIs. They are safe to be called even in the destructor of the other thread local storage. And in Windows, in the FLS destructor, we will create the thread_local variable to defer the destruction of the ThreadHolder. We ensure that this destructor is called after the other FLS destructors are called in Windows 10. This patch is performance neutral. * WTF.xcodeproj/project.pbxproj: * benchmarks/ConditionSpeedTest.cpp: * benchmarks/LockFairnessTest.cpp: * benchmarks/LockSpeedTest.cpp: * wtf/AutomaticThread.cpp: (WTF::AutomaticThread::start): * wtf/CMakeLists.txt: * wtf/MainThread.h: * wtf/MemoryPressureHandler.h: * wtf/ParallelJobsGeneric.cpp: (WTF::ParallelEnvironment::ThreadPrivate::tryLockFor): (WTF::ParallelEnvironment::ThreadPrivate::workerThread): * wtf/ParallelJobsGeneric.h: (WTF::ParallelEnvironment::ThreadPrivate::ThreadPrivate): Deleted. * wtf/ParkingLot.cpp: (WTF::ParkingLot::forEachImpl): * wtf/ParkingLot.h: (WTF::ParkingLot::forEach): * wtf/PlatformRegisters.h: Renamed from Source/JavaScriptCore/runtime/PlatformThread.h. * wtf/RefPtr.h: (WTF::RefPtr::RefPtr): * wtf/ThreadFunctionInvocation.h: (WTF::ThreadFunctionInvocation::ThreadFunctionInvocation): * wtf/ThreadHolder.cpp: Added. (WTF::ThreadHolder::~ThreadHolder): (WTF::ThreadHolder::initialize): * wtf/ThreadHolder.h: Renamed from Source/WTF/wtf/ThreadIdentifierDataPthreads.h. (WTF::ThreadHolder::thread): (WTF::ThreadHolder::ThreadHolder): * wtf/ThreadHolderPthreads.cpp: Renamed from Source/WTF/wtf/ThreadIdentifierDataPthreads.cpp. (WTF::ThreadHolder::initializeOnce): (WTF::ThreadHolder::current): (WTF::ThreadHolder::destruct): * wtf/ThreadHolderWin.cpp: Added. (WTF::threadMapMutex): (WTF::threadMap): (WTF::ThreadHolder::initializeOnce): (WTF::ThreadHolder::current): (WTF::ThreadHolder::destruct): * wtf/ThreadSpecific.h: * wtf/Threading.cpp: (WTF::Thread::normalizeThreadName): (WTF::threadEntryPoint): (WTF::Thread::create): (WTF::Thread::setCurrentThreadIsUserInteractive): (WTF::Thread::setCurrentThreadIsUserInitiated): (WTF::Thread::setGlobalMaxQOSClass): (WTF::Thread::adjustedQOSClass): (WTF::Thread::dump): (WTF::initializeThreading): (WTF::normalizeThreadName): Deleted. (WTF::createThread): Deleted. (WTF::setCurrentThreadIsUserInteractive): Deleted. (WTF::setCurrentThreadIsUserInitiated): Deleted. (WTF::setGlobalMaxQOSClass): Deleted. (WTF::adjustedQOSClass): Deleted. * wtf/Threading.h: (WTF::Thread::id): (WTF::Thread::operator==): (WTF::Thread::operator!=): (WTF::Thread::joinableState): (WTF::Thread::didBecomeDetached): (WTF::Thread::didJoin): (WTF::Thread::hasExited): (WTF::currentThread): * wtf/ThreadingPthreads.cpp: (WTF::Thread::Thread): (WTF::Thread::~Thread): (WTF::Thread::signalHandlerSuspendResume): (WTF::Thread::initializePlatformThreading): (WTF::initializeCurrentThreadEvenIfNonWTFCreated): (WTF::wtfThreadEntryPoint): (WTF::Thread::createInternal): (WTF::Thread::initializeCurrentThreadInternal): (WTF::Thread::changePriority): (WTF::Thread::waitForCompletion): (WTF::Thread::detach): (WTF::Thread::current): (WTF::Thread::currentID): (WTF::Thread::signal): (WTF::Thread::resume): (WTF::Thread::getRegisters): (WTF::Thread::didExit): (WTF::Thread::establish): (WTF::PthreadState::PthreadState): Deleted. (WTF::PthreadState::joinableState): Deleted. (WTF::PthreadState::pthreadHandle): Deleted. (WTF::PthreadState::didBecomeDetached): Deleted. (WTF::PthreadState::didExit): Deleted. (WTF::PthreadState::didJoin): Deleted. (WTF::PthreadState::hasExited): Deleted. (WTF::threadMapMutex): Deleted. (WTF::initializeThreading): Deleted. (WTF::threadMap): Deleted. (WTF::identifierByPthreadHandle): Deleted. (WTF::establishIdentifierForPthreadHandle): Deleted. (WTF::pthreadHandleForIdentifierWithLockAlreadyHeld): Deleted. (WTF::createThreadInternal): Deleted. (WTF::initializeCurrentThreadInternal): Deleted. (WTF::changeThreadPriority): Deleted. (WTF::waitForThreadCompletion): Deleted. (WTF::detachThread): Deleted. (WTF::threadDidExit): Deleted. (WTF::currentThread): Deleted. (WTF::signalThread): Deleted. * wtf/ThreadingWin.cpp: (WTF::Thread::Thread): (WTF::Thread::~Thread): (WTF::Thread::initializeCurrentThreadInternal): (WTF::Thread::initializePlatformThreading): (WTF::wtfThreadEntryPoint): (WTF::Thread::createInternal): (WTF::Thread::changePriority): (WTF::Thread::waitForCompletion): (WTF::Thread::detach): (WTF::Thread::resume): (WTF::Thread::getRegisters): (WTF::Thread::current): (WTF::Thread::currentID): (WTF::Thread::didExit): (WTF::Thread::establish): (WTF::initializeCurrentThreadInternal): Deleted. (WTF::threadMapMutex): Deleted. (WTF::initializeThreading): Deleted. (WTF::threadMap): Deleted. (WTF::storeThreadHandleByIdentifier): Deleted. (WTF::threadHandleForIdentifier): Deleted. (WTF::clearThreadHandleForIdentifier): Deleted. (WTF::createThreadInternal): Deleted. (WTF::changeThreadPriority): Deleted. (WTF::waitForThreadCompletion): Deleted. (WTF::detachThread): Deleted. (WTF::currentThread): Deleted. * wtf/WorkQueue.cpp: (WTF::WorkQueue::concurrentApply): * wtf/WorkQueue.h: * wtf/cocoa/WorkQueueCocoa.cpp: (WTF::dispatchQOSClass): * wtf/generic/WorkQueueGeneric.cpp: (WorkQueue::platformInitialize): (WorkQueue::platformInvalidate): * wtf/linux/MemoryPressureHandlerLinux.cpp: (WTF::MemoryPressureHandler::EventFDPoller::EventFDPoller): (WTF::MemoryPressureHandler::EventFDPoller::~EventFDPoller): * wtf/win/MainThreadWin.cpp: (WTF::initializeMainThreadPlatform): Tools: Mechanical change. Use Thread:: APIs. * DumpRenderTree/JavaScriptThreading.cpp: (runJavaScriptThread): (startJavaScriptThreads): (stopJavaScriptThreads): * DumpRenderTree/mac/DumpRenderTree.mm: (testThreadIdentifierMap): * TestWebKitAPI/Tests/WTF/Condition.cpp: * TestWebKitAPI/Tests/WTF/Lock.cpp: (TestWebKitAPI::runLockTest): * TestWebKitAPI/Tests/WTF/ParkingLot.cpp: Canonical link: https://commits.webkit.org/187690@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@215265 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-04-12 12:08:29 +00:00
* THIS SOFTWARE IS PROVIDED BY GOOGLE, INC. ``AS IS'' AND ANY
[Re-landing] Change JSLock to stash PlatformThread instead of std::thread::id. https://bugs.webkit.org/show_bug.cgi?id=168996 Reviewed by Filip Pizlo and Saam Barati. PlatformThread is more useful because it allows us to: 1. find the MachineThreads::Thread which is associated with it. 2. suspend / resume threads. 3. send a signal to a thread. We can't do those with std::thread::id. We will need one or more of these capabilities to implement non-polling VM traps later. Update: Since we don't have a canonical "uninitialized" value for PlatformThread, we now have a JSLock::m_hasOwnerThread flag that is set to true if and only the m_ownerThread value is valid. JSLock::currentThreadIsHoldingLock() now checks JSLock::m_hasOwnerThread before doing the thread identity comparison. * JavaScriptCore.xcodeproj/project.pbxproj: * heap/MachineStackMarker.cpp: (JSC::MachineThreads::Thread::createForCurrentThread): (JSC::MachineThreads::machineThreadForCurrentThread): (JSC::MachineThreads::removeThread): (JSC::MachineThreads::Thread::suspend): (JSC::MachineThreads::tryCopyOtherThreadStacks): (JSC::getCurrentPlatformThread): Deleted. * heap/MachineStackMarker.h: * runtime/JSCellInlines.h: (JSC::JSCell::classInfo): * runtime/JSLock.cpp: (JSC::JSLock::JSLock): (JSC::JSLock::lock): (JSC::JSLock::unlock): (JSC::JSLock::currentThreadIsHoldingLock): Deleted. * runtime/JSLock.h: (JSC::JSLock::ownerThread): (JSC::JSLock::currentThreadIsHoldingLock): * runtime/PlatformThread.h: Added. (JSC::currentPlatformThread): * runtime/VM.cpp: (JSC::VM::~VM): * runtime/VM.h: (JSC::VM::ownerThread): * runtime/Watchdog.cpp: (JSC::Watchdog::setTimeLimit): (JSC::Watchdog::shouldTerminate): (JSC::Watchdog::startTimer): (JSC::Watchdog::stopTimer): * tools/JSDollarVMPrototype.cpp: (JSC::JSDollarVMPrototype::currentThreadOwnsJSLock): * tools/VMInspector.cpp: Canonical link: https://commits.webkit.org/186036@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@213238 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-03-01 20:15:08 +00:00
* 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.
*/
#pragma once
[WTF] Introduce Thread class and use RefPtr<Thread> and align Windows Threading implementation semantics to Pthread one https://bugs.webkit.org/show_bug.cgi?id=170502 Reviewed by Mark Lam. Source/JavaScriptCore: * API/tests/CompareAndSwapTest.cpp: (testCompareAndSwap): * JavaScriptCore.xcodeproj/project.pbxproj: * b3/air/testair.cpp: * b3/testb3.cpp: (JSC::B3::run): * bytecode/SuperSampler.cpp: (JSC::initializeSuperSampler): * dfg/DFGWorklist.cpp: * disassembler/Disassembler.cpp: * heap/Heap.cpp: (JSC::Heap::lastChanceToFinalize): (JSC::Heap::notifyIsSafeToCollect): * heap/Heap.h: * heap/MachineStackMarker.cpp: (JSC::MachineThreads::~MachineThreads): (JSC::MachineThreads::addCurrentThread): (JSC::MachineThreads::removeThread): (JSC::MachineThreads::removeThreadIfFound): (JSC::MachineThreads::MachineThread::MachineThread): (JSC::MachineThreads::MachineThread::getRegisters): (JSC::MachineThreads::MachineThread::Registers::stackPointer): (JSC::MachineThreads::MachineThread::Registers::framePointer): (JSC::MachineThreads::MachineThread::Registers::instructionPointer): (JSC::MachineThreads::MachineThread::Registers::llintPC): (JSC::MachineThreads::MachineThread::captureStack): (JSC::MachineThreads::tryCopyOtherThreadStack): (JSC::MachineThreads::tryCopyOtherThreadStacks): (pthreadSignalHandlerSuspendResume): Deleted. (JSC::threadData): Deleted. (JSC::MachineThreads::Thread::Thread): Deleted. (JSC::MachineThreads::Thread::createForCurrentThread): Deleted. (JSC::MachineThreads::Thread::operator==): Deleted. (JSC::MachineThreads::machineThreadForCurrentThread): Deleted. (JSC::MachineThreads::ThreadData::ThreadData): Deleted. (JSC::MachineThreads::ThreadData::~ThreadData): Deleted. (JSC::MachineThreads::ThreadData::suspend): Deleted. (JSC::MachineThreads::ThreadData::resume): Deleted. (JSC::MachineThreads::ThreadData::getRegisters): Deleted. (JSC::MachineThreads::ThreadData::Registers::stackPointer): Deleted. (JSC::MachineThreads::ThreadData::Registers::framePointer): Deleted. (JSC::MachineThreads::ThreadData::Registers::instructionPointer): Deleted. (JSC::MachineThreads::ThreadData::Registers::llintPC): Deleted. (JSC::MachineThreads::ThreadData::freeRegisters): Deleted. (JSC::MachineThreads::ThreadData::captureStack): Deleted. * heap/MachineStackMarker.h: (JSC::MachineThreads::MachineThread::suspend): (JSC::MachineThreads::MachineThread::resume): (JSC::MachineThreads::MachineThread::threadID): (JSC::MachineThreads::MachineThread::stackBase): (JSC::MachineThreads::MachineThread::stackEnd): (JSC::MachineThreads::threadsListHead): (JSC::MachineThreads::Thread::operator!=): Deleted. (JSC::MachineThreads::Thread::suspend): Deleted. (JSC::MachineThreads::Thread::resume): Deleted. (JSC::MachineThreads::Thread::getRegisters): Deleted. (JSC::MachineThreads::Thread::freeRegisters): Deleted. (JSC::MachineThreads::Thread::captureStack): Deleted. (JSC::MachineThreads::Thread::platformThread): Deleted. (JSC::MachineThreads::Thread::stackBase): Deleted. (JSC::MachineThreads::Thread::stackEnd): Deleted. * jit/ICStats.cpp: (JSC::ICStats::ICStats): (JSC::ICStats::~ICStats): * jit/ICStats.h: * jsc.cpp: (functionDollarAgentStart): (startTimeoutThreadIfNeeded): * runtime/JSLock.cpp: (JSC::JSLock::lock): * runtime/JSLock.h: (JSC::JSLock::ownerThread): (JSC::JSLock::currentThreadIsHoldingLock): * runtime/SamplingProfiler.cpp: (JSC::FrameWalker::isValidFramePointer): (JSC::SamplingProfiler::SamplingProfiler): (JSC::SamplingProfiler::createThreadIfNecessary): (JSC::SamplingProfiler::takeSample): * runtime/SamplingProfiler.h: * runtime/VM.h: (JSC::VM::ownerThread): * runtime/VMTraps.cpp: (JSC::findActiveVMAndStackBounds): (JSC::VMTraps::SignalSender::send): (JSC::VMTraps::fireTrap): Source/WebCore: Mechanical change. Use Thread:: APIs. * Modules/indexeddb/server/IDBServer.cpp: (WebCore::IDBServer::IDBServer::IDBServer): * Modules/indexeddb/server/IDBServer.h: * Modules/webaudio/AsyncAudioDecoder.cpp: (WebCore::AsyncAudioDecoder::AsyncAudioDecoder): (WebCore::AsyncAudioDecoder::~AsyncAudioDecoder): (WebCore::AsyncAudioDecoder::runLoop): * Modules/webaudio/AsyncAudioDecoder.h: * Modules/webaudio/OfflineAudioDestinationNode.cpp: (WebCore::OfflineAudioDestinationNode::OfflineAudioDestinationNode): (WebCore::OfflineAudioDestinationNode::uninitialize): (WebCore::OfflineAudioDestinationNode::startRendering): * Modules/webaudio/OfflineAudioDestinationNode.h: * Modules/webdatabase/Database.cpp: (WebCore::Database::securityOrigin): * Modules/webdatabase/DatabaseThread.cpp: (WebCore::DatabaseThread::start): (WebCore::DatabaseThread::databaseThread): (WebCore::DatabaseThread::recordDatabaseOpen): (WebCore::DatabaseThread::recordDatabaseClosed): * Modules/webdatabase/DatabaseThread.h: (WebCore::DatabaseThread::getThreadID): * bindings/js/GCController.cpp: (WebCore::GCController::garbageCollectOnAlternateThreadForDebugging): * fileapi/AsyncFileStream.cpp: (WebCore::callOnFileThread): * loader/icon/IconDatabase.cpp: (WebCore::IconDatabase::open): (WebCore::IconDatabase::close): * loader/icon/IconDatabase.h: * page/ResourceUsageThread.cpp: (WebCore::ResourceUsageThread::createThreadIfNeeded): * page/ResourceUsageThread.h: * page/scrolling/ScrollingThread.cpp: (WebCore::ScrollingThread::ScrollingThread): (WebCore::ScrollingThread::isCurrentThread): (WebCore::ScrollingThread::createThreadIfNeeded): (WebCore::ScrollingThread::threadCallback): * page/scrolling/ScrollingThread.h: * platform/audio/HRTFDatabaseLoader.cpp: (WebCore::HRTFDatabaseLoader::HRTFDatabaseLoader): (WebCore::HRTFDatabaseLoader::loadAsynchronously): (WebCore::HRTFDatabaseLoader::waitForLoaderThreadCompletion): * platform/audio/HRTFDatabaseLoader.h: * platform/audio/ReverbConvolver.cpp: (WebCore::ReverbConvolver::ReverbConvolver): (WebCore::ReverbConvolver::~ReverbConvolver): * platform/audio/ReverbConvolver.h: * platform/audio/gstreamer/AudioFileReaderGStreamer.cpp: (WebCore::createBusFromAudioFile): (WebCore::createBusFromInMemoryAudioFile): * platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp: (ResourceHandleStreamingClient::ResourceHandleStreamingClient): (ResourceHandleStreamingClient::~ResourceHandleStreamingClient): * platform/network/cf/LoaderRunLoopCF.cpp: (WebCore::loaderRunLoop): * platform/network/curl/CurlDownload.cpp: (WebCore::CurlDownloadManager::startThreadIfNeeded): (WebCore::CurlDownloadManager::stopThread): * platform/network/curl/CurlDownload.h: * platform/network/curl/SocketStreamHandleImpl.h: * platform/network/curl/SocketStreamHandleImplCurl.cpp: (WebCore::SocketStreamHandleImpl::startThread): (WebCore::SocketStreamHandleImpl::stopThread): * workers/WorkerThread.cpp: (WebCore::WorkerThread::WorkerThread): (WebCore::WorkerThread::start): (WebCore::WorkerThread::workerThread): * workers/WorkerThread.h: (WebCore::WorkerThread::threadID): Source/WebKit: Mechanical change. Use Thread:: APIs. * Storage/StorageThread.cpp: (WebCore::StorageThread::StorageThread): (WebCore::StorageThread::~StorageThread): (WebCore::StorageThread::start): (WebCore::StorageThread::dispatch): (WebCore::StorageThread::terminate): * Storage/StorageThread.h: Source/WebKit2: Mechanical change. Use Thread:: APIs. * NetworkProcess/NetworkProcess.cpp: (WebKit::NetworkProcess::initializeNetworkProcess): * NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp: (WebKit::NetworkCache::IOChannel::readSyncInThread): * Platform/IPC/Connection.cpp: (IPC::Connection::processIncomingMessage): * Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.h: (WebKit::XPCServiceInitializer): * UIProcess/linux/MemoryPressureMonitor.cpp: (WebKit::MemoryPressureMonitor::MemoryPressureMonitor): * WebProcess/WebProcess.cpp: (WebKit::WebProcess::initializeWebProcess): Source/WTF: This patch is refactoring of WTF Threading mechanism to merge JavaScriptCore's threading extension to WTF Threading. Previously, JavaScriptCore requires richer threading features (such as suspending and resuming threads), and they are implemented for PlatformThread in JavaScriptCore. But these features should be implemented in WTF Threading side instead of maintaining JSC's own threading features too. This patch removes these features from JSC and move it to WTF Threading. However, current WTF Threading has one problem: Windows version of WTF Threading has different semantics from Pthreads one. In Windows WTF Threading, we cannot perform any operation after the target thread is detached: WTF Threading stop tracking the state of the thread once the thread is detached. But this is not the same to Pthreads one. In Pthreads, pthread_detach just means that the resource of the thread will be destroyed automatically. While some operations like pthread_join will be rejected, some operations like pthread_kill will be accepted. The problem is that detached thread can be suspended and resumed in JSC. For example, in jsc.cpp, we start the worker thread and detach it immediately. In worker thread, we will create VM and thus concurrent GC will suspend and resume the detached thread. However, in Windows WTF Threading, we have no reference to the detached thread. Thus we cannot perform suspend and resume operations onto the detached thread. To solve the problem, we change Windows Threading mechanism drastically to align it to the Pthread semantics. In the new Threading, we have RefPtr<Thread> class. It holds a handle to a platform thread. We can perform threading operations with this class. For example, Thread::suspend is offered. And we use destructor of the thread local variable to release the resources held by RefPtr<Thread>. In Windows, Thread::detach does nothing because the resource will be destroyed automatically by RefPtr<Thread>. To do so, we introduce ThreadHolder for Windows. This is similar to the previous ThreadIdentifierData for Pthreads. It holds RefPtr<Thread> in the thread local storage (technically, it is Fiber Local Storage in Windows). Thread::current() will return this reference. The problematic situation is that the order of the deallocation of the thread local storage is not defined. So we should not touch thread local storage in the destructor of the thread local storage. To avoid such edge cases, we have currentThread() / Thread::currentID() APIs. They are safe to be called even in the destructor of the other thread local storage. And in Windows, in the FLS destructor, we will create the thread_local variable to defer the destruction of the ThreadHolder. We ensure that this destructor is called after the other FLS destructors are called in Windows 10. This patch is performance neutral. * WTF.xcodeproj/project.pbxproj: * benchmarks/ConditionSpeedTest.cpp: * benchmarks/LockFairnessTest.cpp: * benchmarks/LockSpeedTest.cpp: * wtf/AutomaticThread.cpp: (WTF::AutomaticThread::start): * wtf/CMakeLists.txt: * wtf/MainThread.h: * wtf/MemoryPressureHandler.h: * wtf/ParallelJobsGeneric.cpp: (WTF::ParallelEnvironment::ThreadPrivate::tryLockFor): (WTF::ParallelEnvironment::ThreadPrivate::workerThread): * wtf/ParallelJobsGeneric.h: (WTF::ParallelEnvironment::ThreadPrivate::ThreadPrivate): Deleted. * wtf/ParkingLot.cpp: (WTF::ParkingLot::forEachImpl): * wtf/ParkingLot.h: (WTF::ParkingLot::forEach): * wtf/PlatformRegisters.h: Renamed from Source/JavaScriptCore/runtime/PlatformThread.h. * wtf/RefPtr.h: (WTF::RefPtr::RefPtr): * wtf/ThreadFunctionInvocation.h: (WTF::ThreadFunctionInvocation::ThreadFunctionInvocation): * wtf/ThreadHolder.cpp: Added. (WTF::ThreadHolder::~ThreadHolder): (WTF::ThreadHolder::initialize): * wtf/ThreadHolder.h: Renamed from Source/WTF/wtf/ThreadIdentifierDataPthreads.h. (WTF::ThreadHolder::thread): (WTF::ThreadHolder::ThreadHolder): * wtf/ThreadHolderPthreads.cpp: Renamed from Source/WTF/wtf/ThreadIdentifierDataPthreads.cpp. (WTF::ThreadHolder::initializeOnce): (WTF::ThreadHolder::current): (WTF::ThreadHolder::destruct): * wtf/ThreadHolderWin.cpp: Added. (WTF::threadMapMutex): (WTF::threadMap): (WTF::ThreadHolder::initializeOnce): (WTF::ThreadHolder::current): (WTF::ThreadHolder::destruct): * wtf/ThreadSpecific.h: * wtf/Threading.cpp: (WTF::Thread::normalizeThreadName): (WTF::threadEntryPoint): (WTF::Thread::create): (WTF::Thread::setCurrentThreadIsUserInteractive): (WTF::Thread::setCurrentThreadIsUserInitiated): (WTF::Thread::setGlobalMaxQOSClass): (WTF::Thread::adjustedQOSClass): (WTF::Thread::dump): (WTF::initializeThreading): (WTF::normalizeThreadName): Deleted. (WTF::createThread): Deleted. (WTF::setCurrentThreadIsUserInteractive): Deleted. (WTF::setCurrentThreadIsUserInitiated): Deleted. (WTF::setGlobalMaxQOSClass): Deleted. (WTF::adjustedQOSClass): Deleted. * wtf/Threading.h: (WTF::Thread::id): (WTF::Thread::operator==): (WTF::Thread::operator!=): (WTF::Thread::joinableState): (WTF::Thread::didBecomeDetached): (WTF::Thread::didJoin): (WTF::Thread::hasExited): (WTF::currentThread): * wtf/ThreadingPthreads.cpp: (WTF::Thread::Thread): (WTF::Thread::~Thread): (WTF::Thread::signalHandlerSuspendResume): (WTF::Thread::initializePlatformThreading): (WTF::initializeCurrentThreadEvenIfNonWTFCreated): (WTF::wtfThreadEntryPoint): (WTF::Thread::createInternal): (WTF::Thread::initializeCurrentThreadInternal): (WTF::Thread::changePriority): (WTF::Thread::waitForCompletion): (WTF::Thread::detach): (WTF::Thread::current): (WTF::Thread::currentID): (WTF::Thread::signal): (WTF::Thread::resume): (WTF::Thread::getRegisters): (WTF::Thread::didExit): (WTF::Thread::establish): (WTF::PthreadState::PthreadState): Deleted. (WTF::PthreadState::joinableState): Deleted. (WTF::PthreadState::pthreadHandle): Deleted. (WTF::PthreadState::didBecomeDetached): Deleted. (WTF::PthreadState::didExit): Deleted. (WTF::PthreadState::didJoin): Deleted. (WTF::PthreadState::hasExited): Deleted. (WTF::threadMapMutex): Deleted. (WTF::initializeThreading): Deleted. (WTF::threadMap): Deleted. (WTF::identifierByPthreadHandle): Deleted. (WTF::establishIdentifierForPthreadHandle): Deleted. (WTF::pthreadHandleForIdentifierWithLockAlreadyHeld): Deleted. (WTF::createThreadInternal): Deleted. (WTF::initializeCurrentThreadInternal): Deleted. (WTF::changeThreadPriority): Deleted. (WTF::waitForThreadCompletion): Deleted. (WTF::detachThread): Deleted. (WTF::threadDidExit): Deleted. (WTF::currentThread): Deleted. (WTF::signalThread): Deleted. * wtf/ThreadingWin.cpp: (WTF::Thread::Thread): (WTF::Thread::~Thread): (WTF::Thread::initializeCurrentThreadInternal): (WTF::Thread::initializePlatformThreading): (WTF::wtfThreadEntryPoint): (WTF::Thread::createInternal): (WTF::Thread::changePriority): (WTF::Thread::waitForCompletion): (WTF::Thread::detach): (WTF::Thread::resume): (WTF::Thread::getRegisters): (WTF::Thread::current): (WTF::Thread::currentID): (WTF::Thread::didExit): (WTF::Thread::establish): (WTF::initializeCurrentThreadInternal): Deleted. (WTF::threadMapMutex): Deleted. (WTF::initializeThreading): Deleted. (WTF::threadMap): Deleted. (WTF::storeThreadHandleByIdentifier): Deleted. (WTF::threadHandleForIdentifier): Deleted. (WTF::clearThreadHandleForIdentifier): Deleted. (WTF::createThreadInternal): Deleted. (WTF::changeThreadPriority): Deleted. (WTF::waitForThreadCompletion): Deleted. (WTF::detachThread): Deleted. (WTF::currentThread): Deleted. * wtf/WorkQueue.cpp: (WTF::WorkQueue::concurrentApply): * wtf/WorkQueue.h: * wtf/cocoa/WorkQueueCocoa.cpp: (WTF::dispatchQOSClass): * wtf/generic/WorkQueueGeneric.cpp: (WorkQueue::platformInitialize): (WorkQueue::platformInvalidate): * wtf/linux/MemoryPressureHandlerLinux.cpp: (WTF::MemoryPressureHandler::EventFDPoller::EventFDPoller): (WTF::MemoryPressureHandler::EventFDPoller::~EventFDPoller): * wtf/win/MainThreadWin.cpp: (WTF::initializeMainThreadPlatform): Tools: Mechanical change. Use Thread:: APIs. * DumpRenderTree/JavaScriptThreading.cpp: (runJavaScriptThread): (startJavaScriptThreads): (stopJavaScriptThreads): * DumpRenderTree/mac/DumpRenderTree.mm: (testThreadIdentifierMap): * TestWebKitAPI/Tests/WTF/Condition.cpp: * TestWebKitAPI/Tests/WTF/Lock.cpp: (TestWebKitAPI::runLockTest): * TestWebKitAPI/Tests/WTF/ParkingLot.cpp: Canonical link: https://commits.webkit.org/187690@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@215265 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-04-12 12:08:29 +00:00
#include <wtf/Platform.h>
Undo rollout in r217638 with bug fix https://bugs.webkit.org/show_bug.cgi?id=172824 Unreviewed, reland patch with unused set_state code removed. Source/JavaScriptCore: * API/tests/ExecutionTimeLimitTest.cpp: (dispatchTermitateCallback): (testExecutionTimeLimit): * runtime/JSLock.cpp: (JSC::JSLock::didAcquireLock): * runtime/Options.cpp: (JSC::overrideDefaults): (JSC::Options::initialize): * runtime/Options.h: * runtime/VMTraps.cpp: (JSC::SignalContext::SignalContext): (JSC::SignalContext::adjustPCToPointToTrappingInstruction): (JSC::installSignalHandler): (JSC::VMTraps::SignalSender::send): * tools/SigillCrashAnalyzer.cpp: (JSC::SignalContext::SignalContext): (JSC::SignalContext::dump): (JSC::installCrashHandler): * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::compileFunctions): * wasm/WasmFaultSignalHandler.cpp: (JSC::Wasm::trapHandler): (JSC::Wasm::enableFastMemory): * wasm/WasmMachineThreads.cpp: (JSC::Wasm::resetInstructionCacheOnAllThreads): Source/WTF: * Configurations/WTF.xcconfig: * WTF.xcodeproj/project.pbxproj: * wtf/Platform.h: * wtf/PlatformRegisters.h: (WTF::registersFromUContext): * wtf/StackBounds.h: (WTF::StackBounds::StackBounds): * wtf/ThreadHolder.cpp: (WTF::ThreadHolder::~ThreadHolder): * wtf/ThreadMessage.cpp: (WTF::sendMessageUsingSignal): (WTF::sendMessageUsingMach): (WTF::deliverMessagesUsingMach): (WTF::sendMessageScoped): * wtf/ThreadMessage.h: (WTF::sendMessage): * wtf/Threading.h: (WTF::Thread::machThread): * wtf/mac/MachExceptions.defs: Copied from Source/WTF/wtf/ThreadMessage.h. * wtf/threads/Signals.cpp: (WTF::startMachExceptionHandlerThread): (WTF::fromMachException): (WTF::toMachMask): (WTF::handleSignalsWithMach): (WTF::setExceptionPorts): (WTF::activeThreads): (WTF::registerThreadForMachExceptionHandling): (WTF::unregisterThreadForMachExceptionHandling): (WTF::installSignalHandler): (WTF::jscSignalHandler): * wtf/threads/Signals.h: Tools: * TestWebKitAPI/Tests/WTF/ThreadMessages.cpp: (runThreadMessageTest): (TEST): Canonical link: https://commits.webkit.org/189710@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@217669 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-06-01 18:28:48 +00:00
#include <wtf/StdLibExtras.h>
[JSC][Linux] Implement VMTrap in Linux ports https://bugs.webkit.org/show_bug.cgi?id=169436 Reviewed by Mark Lam. Source/JavaScriptCore: This patch port VMTrap to Linux ports. We extract MachineContext accessors from various places (wasm/, heap/ and tools/) and use them in all the JSC code. * JavaScriptCore.xcodeproj/project.pbxproj: * heap/MachineStackMarker.cpp: (JSC::MachineThreads::Thread::Registers::stackPointer): (JSC::MachineThreads::Thread::Registers::framePointer): (JSC::MachineThreads::Thread::Registers::instructionPointer): (JSC::MachineThreads::Thread::Registers::llintPC): * heap/MachineStackMarker.h: * runtime/MachineContext.h: Added. (JSC::MachineContext::stackPointer): (JSC::MachineContext::framePointer): (JSC::MachineContext::instructionPointer): (JSC::MachineContext::argumentPointer<1>): (JSC::MachineContext::argumentPointer): (JSC::MachineContext::llintInstructionPointer): * runtime/PlatformThread.h: (JSC::platformThreadSignal): * runtime/VMTraps.cpp: (JSC::SignalContext::SignalContext): (JSC::SignalContext::adjustPCToPointToTrappingInstruction): * tools/CodeProfiling.cpp: (JSC::profilingTimer): * tools/SigillCrashAnalyzer.cpp: (JSC::SignalContext::SignalContext): (JSC::SignalContext::dump): * tools/VMInspector.cpp: * wasm/WasmFaultSignalHandler.cpp: (JSC::Wasm::trapHandler): Source/WTF: Enable VMTrap mechanism for Linux and FreeBSD. * wtf/Platform.h: Canonical link: https://commits.webkit.org/186583@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@213886 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-03-14 07:33:08 +00:00
[Re-landing] Change JSLock to stash PlatformThread instead of std::thread::id. https://bugs.webkit.org/show_bug.cgi?id=168996 Reviewed by Filip Pizlo and Saam Barati. PlatformThread is more useful because it allows us to: 1. find the MachineThreads::Thread which is associated with it. 2. suspend / resume threads. 3. send a signal to a thread. We can't do those with std::thread::id. We will need one or more of these capabilities to implement non-polling VM traps later. Update: Since we don't have a canonical "uninitialized" value for PlatformThread, we now have a JSLock::m_hasOwnerThread flag that is set to true if and only the m_ownerThread value is valid. JSLock::currentThreadIsHoldingLock() now checks JSLock::m_hasOwnerThread before doing the thread identity comparison. * JavaScriptCore.xcodeproj/project.pbxproj: * heap/MachineStackMarker.cpp: (JSC::MachineThreads::Thread::createForCurrentThread): (JSC::MachineThreads::machineThreadForCurrentThread): (JSC::MachineThreads::removeThread): (JSC::MachineThreads::Thread::suspend): (JSC::MachineThreads::tryCopyOtherThreadStacks): (JSC::getCurrentPlatformThread): Deleted. * heap/MachineStackMarker.h: * runtime/JSCellInlines.h: (JSC::JSCell::classInfo): * runtime/JSLock.cpp: (JSC::JSLock::JSLock): (JSC::JSLock::lock): (JSC::JSLock::unlock): (JSC::JSLock::currentThreadIsHoldingLock): Deleted. * runtime/JSLock.h: (JSC::JSLock::ownerThread): (JSC::JSLock::currentThreadIsHoldingLock): * runtime/PlatformThread.h: Added. (JSC::currentPlatformThread): * runtime/VM.cpp: (JSC::VM::~VM): * runtime/VM.h: (JSC::VM::ownerThread): * runtime/Watchdog.cpp: (JSC::Watchdog::setTimeLimit): (JSC::Watchdog::shouldTerminate): (JSC::Watchdog::startTimer): (JSC::Watchdog::stopTimer): * tools/JSDollarVMPrototype.cpp: (JSC::JSDollarVMPrototype::currentThreadOwnsJSLock): * tools/VMInspector.cpp: Canonical link: https://commits.webkit.org/186036@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@213238 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-03-01 20:15:08 +00:00
#if OS(DARWIN)
#include <mach/thread_act.h>
Undo rollout in r217638 with bug fix https://bugs.webkit.org/show_bug.cgi?id=172824 Unreviewed, reland patch with unused set_state code removed. Source/JavaScriptCore: * API/tests/ExecutionTimeLimitTest.cpp: (dispatchTermitateCallback): (testExecutionTimeLimit): * runtime/JSLock.cpp: (JSC::JSLock::didAcquireLock): * runtime/Options.cpp: (JSC::overrideDefaults): (JSC::Options::initialize): * runtime/Options.h: * runtime/VMTraps.cpp: (JSC::SignalContext::SignalContext): (JSC::SignalContext::adjustPCToPointToTrappingInstruction): (JSC::installSignalHandler): (JSC::VMTraps::SignalSender::send): * tools/SigillCrashAnalyzer.cpp: (JSC::SignalContext::SignalContext): (JSC::SignalContext::dump): (JSC::installCrashHandler): * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::compileFunctions): * wasm/WasmFaultSignalHandler.cpp: (JSC::Wasm::trapHandler): (JSC::Wasm::enableFastMemory): * wasm/WasmMachineThreads.cpp: (JSC::Wasm::resetInstructionCacheOnAllThreads): Source/WTF: * Configurations/WTF.xcconfig: * WTF.xcodeproj/project.pbxproj: * wtf/Platform.h: * wtf/PlatformRegisters.h: (WTF::registersFromUContext): * wtf/StackBounds.h: (WTF::StackBounds::StackBounds): * wtf/ThreadHolder.cpp: (WTF::ThreadHolder::~ThreadHolder): * wtf/ThreadMessage.cpp: (WTF::sendMessageUsingSignal): (WTF::sendMessageUsingMach): (WTF::deliverMessagesUsingMach): (WTF::sendMessageScoped): * wtf/ThreadMessage.h: (WTF::sendMessage): * wtf/Threading.h: (WTF::Thread::machThread): * wtf/mac/MachExceptions.defs: Copied from Source/WTF/wtf/ThreadMessage.h. * wtf/threads/Signals.cpp: (WTF::startMachExceptionHandlerThread): (WTF::fromMachException): (WTF::toMachMask): (WTF::handleSignalsWithMach): (WTF::setExceptionPorts): (WTF::activeThreads): (WTF::registerThreadForMachExceptionHandling): (WTF::unregisterThreadForMachExceptionHandling): (WTF::installSignalHandler): (WTF::jscSignalHandler): * wtf/threads/Signals.h: Tools: * TestWebKitAPI/Tests/WTF/ThreadMessages.cpp: (runThreadMessageTest): (TEST): Canonical link: https://commits.webkit.org/189710@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@217669 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-06-01 18:28:48 +00:00
#include <signal.h>
[Re-landing] Change JSLock to stash PlatformThread instead of std::thread::id. https://bugs.webkit.org/show_bug.cgi?id=168996 Reviewed by Filip Pizlo and Saam Barati. PlatformThread is more useful because it allows us to: 1. find the MachineThreads::Thread which is associated with it. 2. suspend / resume threads. 3. send a signal to a thread. We can't do those with std::thread::id. We will need one or more of these capabilities to implement non-polling VM traps later. Update: Since we don't have a canonical "uninitialized" value for PlatformThread, we now have a JSLock::m_hasOwnerThread flag that is set to true if and only the m_ownerThread value is valid. JSLock::currentThreadIsHoldingLock() now checks JSLock::m_hasOwnerThread before doing the thread identity comparison. * JavaScriptCore.xcodeproj/project.pbxproj: * heap/MachineStackMarker.cpp: (JSC::MachineThreads::Thread::createForCurrentThread): (JSC::MachineThreads::machineThreadForCurrentThread): (JSC::MachineThreads::removeThread): (JSC::MachineThreads::Thread::suspend): (JSC::MachineThreads::tryCopyOtherThreadStacks): (JSC::getCurrentPlatformThread): Deleted. * heap/MachineStackMarker.h: * runtime/JSCellInlines.h: (JSC::JSCell::classInfo): * runtime/JSLock.cpp: (JSC::JSLock::JSLock): (JSC::JSLock::lock): (JSC::JSLock::unlock): (JSC::JSLock::currentThreadIsHoldingLock): Deleted. * runtime/JSLock.h: (JSC::JSLock::ownerThread): (JSC::JSLock::currentThreadIsHoldingLock): * runtime/PlatformThread.h: Added. (JSC::currentPlatformThread): * runtime/VM.cpp: (JSC::VM::~VM): * runtime/VM.h: (JSC::VM::ownerThread): * runtime/Watchdog.cpp: (JSC::Watchdog::setTimeLimit): (JSC::Watchdog::shouldTerminate): (JSC::Watchdog::startTimer): (JSC::Watchdog::stopTimer): * tools/JSDollarVMPrototype.cpp: (JSC::JSDollarVMPrototype::currentThreadOwnsJSLock): * tools/VMInspector.cpp: Canonical link: https://commits.webkit.org/186036@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@213238 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-03-01 20:15:08 +00:00
#elif OS(WINDOWS)
#include <windows.h>
#elif OS(HAIKU)
[WTF] Introduce Thread class and use RefPtr<Thread> and align Windows Threading implementation semantics to Pthread one https://bugs.webkit.org/show_bug.cgi?id=170502 Reviewed by Mark Lam. Source/JavaScriptCore: * API/tests/CompareAndSwapTest.cpp: (testCompareAndSwap): * JavaScriptCore.xcodeproj/project.pbxproj: * b3/air/testair.cpp: * b3/testb3.cpp: (JSC::B3::run): * bytecode/SuperSampler.cpp: (JSC::initializeSuperSampler): * dfg/DFGWorklist.cpp: * disassembler/Disassembler.cpp: * heap/Heap.cpp: (JSC::Heap::lastChanceToFinalize): (JSC::Heap::notifyIsSafeToCollect): * heap/Heap.h: * heap/MachineStackMarker.cpp: (JSC::MachineThreads::~MachineThreads): (JSC::MachineThreads::addCurrentThread): (JSC::MachineThreads::removeThread): (JSC::MachineThreads::removeThreadIfFound): (JSC::MachineThreads::MachineThread::MachineThread): (JSC::MachineThreads::MachineThread::getRegisters): (JSC::MachineThreads::MachineThread::Registers::stackPointer): (JSC::MachineThreads::MachineThread::Registers::framePointer): (JSC::MachineThreads::MachineThread::Registers::instructionPointer): (JSC::MachineThreads::MachineThread::Registers::llintPC): (JSC::MachineThreads::MachineThread::captureStack): (JSC::MachineThreads::tryCopyOtherThreadStack): (JSC::MachineThreads::tryCopyOtherThreadStacks): (pthreadSignalHandlerSuspendResume): Deleted. (JSC::threadData): Deleted. (JSC::MachineThreads::Thread::Thread): Deleted. (JSC::MachineThreads::Thread::createForCurrentThread): Deleted. (JSC::MachineThreads::Thread::operator==): Deleted. (JSC::MachineThreads::machineThreadForCurrentThread): Deleted. (JSC::MachineThreads::ThreadData::ThreadData): Deleted. (JSC::MachineThreads::ThreadData::~ThreadData): Deleted. (JSC::MachineThreads::ThreadData::suspend): Deleted. (JSC::MachineThreads::ThreadData::resume): Deleted. (JSC::MachineThreads::ThreadData::getRegisters): Deleted. (JSC::MachineThreads::ThreadData::Registers::stackPointer): Deleted. (JSC::MachineThreads::ThreadData::Registers::framePointer): Deleted. (JSC::MachineThreads::ThreadData::Registers::instructionPointer): Deleted. (JSC::MachineThreads::ThreadData::Registers::llintPC): Deleted. (JSC::MachineThreads::ThreadData::freeRegisters): Deleted. (JSC::MachineThreads::ThreadData::captureStack): Deleted. * heap/MachineStackMarker.h: (JSC::MachineThreads::MachineThread::suspend): (JSC::MachineThreads::MachineThread::resume): (JSC::MachineThreads::MachineThread::threadID): (JSC::MachineThreads::MachineThread::stackBase): (JSC::MachineThreads::MachineThread::stackEnd): (JSC::MachineThreads::threadsListHead): (JSC::MachineThreads::Thread::operator!=): Deleted. (JSC::MachineThreads::Thread::suspend): Deleted. (JSC::MachineThreads::Thread::resume): Deleted. (JSC::MachineThreads::Thread::getRegisters): Deleted. (JSC::MachineThreads::Thread::freeRegisters): Deleted. (JSC::MachineThreads::Thread::captureStack): Deleted. (JSC::MachineThreads::Thread::platformThread): Deleted. (JSC::MachineThreads::Thread::stackBase): Deleted. (JSC::MachineThreads::Thread::stackEnd): Deleted. * jit/ICStats.cpp: (JSC::ICStats::ICStats): (JSC::ICStats::~ICStats): * jit/ICStats.h: * jsc.cpp: (functionDollarAgentStart): (startTimeoutThreadIfNeeded): * runtime/JSLock.cpp: (JSC::JSLock::lock): * runtime/JSLock.h: (JSC::JSLock::ownerThread): (JSC::JSLock::currentThreadIsHoldingLock): * runtime/SamplingProfiler.cpp: (JSC::FrameWalker::isValidFramePointer): (JSC::SamplingProfiler::SamplingProfiler): (JSC::SamplingProfiler::createThreadIfNecessary): (JSC::SamplingProfiler::takeSample): * runtime/SamplingProfiler.h: * runtime/VM.h: (JSC::VM::ownerThread): * runtime/VMTraps.cpp: (JSC::findActiveVMAndStackBounds): (JSC::VMTraps::SignalSender::send): (JSC::VMTraps::fireTrap): Source/WebCore: Mechanical change. Use Thread:: APIs. * Modules/indexeddb/server/IDBServer.cpp: (WebCore::IDBServer::IDBServer::IDBServer): * Modules/indexeddb/server/IDBServer.h: * Modules/webaudio/AsyncAudioDecoder.cpp: (WebCore::AsyncAudioDecoder::AsyncAudioDecoder): (WebCore::AsyncAudioDecoder::~AsyncAudioDecoder): (WebCore::AsyncAudioDecoder::runLoop): * Modules/webaudio/AsyncAudioDecoder.h: * Modules/webaudio/OfflineAudioDestinationNode.cpp: (WebCore::OfflineAudioDestinationNode::OfflineAudioDestinationNode): (WebCore::OfflineAudioDestinationNode::uninitialize): (WebCore::OfflineAudioDestinationNode::startRendering): * Modules/webaudio/OfflineAudioDestinationNode.h: * Modules/webdatabase/Database.cpp: (WebCore::Database::securityOrigin): * Modules/webdatabase/DatabaseThread.cpp: (WebCore::DatabaseThread::start): (WebCore::DatabaseThread::databaseThread): (WebCore::DatabaseThread::recordDatabaseOpen): (WebCore::DatabaseThread::recordDatabaseClosed): * Modules/webdatabase/DatabaseThread.h: (WebCore::DatabaseThread::getThreadID): * bindings/js/GCController.cpp: (WebCore::GCController::garbageCollectOnAlternateThreadForDebugging): * fileapi/AsyncFileStream.cpp: (WebCore::callOnFileThread): * loader/icon/IconDatabase.cpp: (WebCore::IconDatabase::open): (WebCore::IconDatabase::close): * loader/icon/IconDatabase.h: * page/ResourceUsageThread.cpp: (WebCore::ResourceUsageThread::createThreadIfNeeded): * page/ResourceUsageThread.h: * page/scrolling/ScrollingThread.cpp: (WebCore::ScrollingThread::ScrollingThread): (WebCore::ScrollingThread::isCurrentThread): (WebCore::ScrollingThread::createThreadIfNeeded): (WebCore::ScrollingThread::threadCallback): * page/scrolling/ScrollingThread.h: * platform/audio/HRTFDatabaseLoader.cpp: (WebCore::HRTFDatabaseLoader::HRTFDatabaseLoader): (WebCore::HRTFDatabaseLoader::loadAsynchronously): (WebCore::HRTFDatabaseLoader::waitForLoaderThreadCompletion): * platform/audio/HRTFDatabaseLoader.h: * platform/audio/ReverbConvolver.cpp: (WebCore::ReverbConvolver::ReverbConvolver): (WebCore::ReverbConvolver::~ReverbConvolver): * platform/audio/ReverbConvolver.h: * platform/audio/gstreamer/AudioFileReaderGStreamer.cpp: (WebCore::createBusFromAudioFile): (WebCore::createBusFromInMemoryAudioFile): * platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp: (ResourceHandleStreamingClient::ResourceHandleStreamingClient): (ResourceHandleStreamingClient::~ResourceHandleStreamingClient): * platform/network/cf/LoaderRunLoopCF.cpp: (WebCore::loaderRunLoop): * platform/network/curl/CurlDownload.cpp: (WebCore::CurlDownloadManager::startThreadIfNeeded): (WebCore::CurlDownloadManager::stopThread): * platform/network/curl/CurlDownload.h: * platform/network/curl/SocketStreamHandleImpl.h: * platform/network/curl/SocketStreamHandleImplCurl.cpp: (WebCore::SocketStreamHandleImpl::startThread): (WebCore::SocketStreamHandleImpl::stopThread): * workers/WorkerThread.cpp: (WebCore::WorkerThread::WorkerThread): (WebCore::WorkerThread::start): (WebCore::WorkerThread::workerThread): * workers/WorkerThread.h: (WebCore::WorkerThread::threadID): Source/WebKit: Mechanical change. Use Thread:: APIs. * Storage/StorageThread.cpp: (WebCore::StorageThread::StorageThread): (WebCore::StorageThread::~StorageThread): (WebCore::StorageThread::start): (WebCore::StorageThread::dispatch): (WebCore::StorageThread::terminate): * Storage/StorageThread.h: Source/WebKit2: Mechanical change. Use Thread:: APIs. * NetworkProcess/NetworkProcess.cpp: (WebKit::NetworkProcess::initializeNetworkProcess): * NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp: (WebKit::NetworkCache::IOChannel::readSyncInThread): * Platform/IPC/Connection.cpp: (IPC::Connection::processIncomingMessage): * Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.h: (WebKit::XPCServiceInitializer): * UIProcess/linux/MemoryPressureMonitor.cpp: (WebKit::MemoryPressureMonitor::MemoryPressureMonitor): * WebProcess/WebProcess.cpp: (WebKit::WebProcess::initializeWebProcess): Source/WTF: This patch is refactoring of WTF Threading mechanism to merge JavaScriptCore's threading extension to WTF Threading. Previously, JavaScriptCore requires richer threading features (such as suspending and resuming threads), and they are implemented for PlatformThread in JavaScriptCore. But these features should be implemented in WTF Threading side instead of maintaining JSC's own threading features too. This patch removes these features from JSC and move it to WTF Threading. However, current WTF Threading has one problem: Windows version of WTF Threading has different semantics from Pthreads one. In Windows WTF Threading, we cannot perform any operation after the target thread is detached: WTF Threading stop tracking the state of the thread once the thread is detached. But this is not the same to Pthreads one. In Pthreads, pthread_detach just means that the resource of the thread will be destroyed automatically. While some operations like pthread_join will be rejected, some operations like pthread_kill will be accepted. The problem is that detached thread can be suspended and resumed in JSC. For example, in jsc.cpp, we start the worker thread and detach it immediately. In worker thread, we will create VM and thus concurrent GC will suspend and resume the detached thread. However, in Windows WTF Threading, we have no reference to the detached thread. Thus we cannot perform suspend and resume operations onto the detached thread. To solve the problem, we change Windows Threading mechanism drastically to align it to the Pthread semantics. In the new Threading, we have RefPtr<Thread> class. It holds a handle to a platform thread. We can perform threading operations with this class. For example, Thread::suspend is offered. And we use destructor of the thread local variable to release the resources held by RefPtr<Thread>. In Windows, Thread::detach does nothing because the resource will be destroyed automatically by RefPtr<Thread>. To do so, we introduce ThreadHolder for Windows. This is similar to the previous ThreadIdentifierData for Pthreads. It holds RefPtr<Thread> in the thread local storage (technically, it is Fiber Local Storage in Windows). Thread::current() will return this reference. The problematic situation is that the order of the deallocation of the thread local storage is not defined. So we should not touch thread local storage in the destructor of the thread local storage. To avoid such edge cases, we have currentThread() / Thread::currentID() APIs. They are safe to be called even in the destructor of the other thread local storage. And in Windows, in the FLS destructor, we will create the thread_local variable to defer the destruction of the ThreadHolder. We ensure that this destructor is called after the other FLS destructors are called in Windows 10. This patch is performance neutral. * WTF.xcodeproj/project.pbxproj: * benchmarks/ConditionSpeedTest.cpp: * benchmarks/LockFairnessTest.cpp: * benchmarks/LockSpeedTest.cpp: * wtf/AutomaticThread.cpp: (WTF::AutomaticThread::start): * wtf/CMakeLists.txt: * wtf/MainThread.h: * wtf/MemoryPressureHandler.h: * wtf/ParallelJobsGeneric.cpp: (WTF::ParallelEnvironment::ThreadPrivate::tryLockFor): (WTF::ParallelEnvironment::ThreadPrivate::workerThread): * wtf/ParallelJobsGeneric.h: (WTF::ParallelEnvironment::ThreadPrivate::ThreadPrivate): Deleted. * wtf/ParkingLot.cpp: (WTF::ParkingLot::forEachImpl): * wtf/ParkingLot.h: (WTF::ParkingLot::forEach): * wtf/PlatformRegisters.h: Renamed from Source/JavaScriptCore/runtime/PlatformThread.h. * wtf/RefPtr.h: (WTF::RefPtr::RefPtr): * wtf/ThreadFunctionInvocation.h: (WTF::ThreadFunctionInvocation::ThreadFunctionInvocation): * wtf/ThreadHolder.cpp: Added. (WTF::ThreadHolder::~ThreadHolder): (WTF::ThreadHolder::initialize): * wtf/ThreadHolder.h: Renamed from Source/WTF/wtf/ThreadIdentifierDataPthreads.h. (WTF::ThreadHolder::thread): (WTF::ThreadHolder::ThreadHolder): * wtf/ThreadHolderPthreads.cpp: Renamed from Source/WTF/wtf/ThreadIdentifierDataPthreads.cpp. (WTF::ThreadHolder::initializeOnce): (WTF::ThreadHolder::current): (WTF::ThreadHolder::destruct): * wtf/ThreadHolderWin.cpp: Added. (WTF::threadMapMutex): (WTF::threadMap): (WTF::ThreadHolder::initializeOnce): (WTF::ThreadHolder::current): (WTF::ThreadHolder::destruct): * wtf/ThreadSpecific.h: * wtf/Threading.cpp: (WTF::Thread::normalizeThreadName): (WTF::threadEntryPoint): (WTF::Thread::create): (WTF::Thread::setCurrentThreadIsUserInteractive): (WTF::Thread::setCurrentThreadIsUserInitiated): (WTF::Thread::setGlobalMaxQOSClass): (WTF::Thread::adjustedQOSClass): (WTF::Thread::dump): (WTF::initializeThreading): (WTF::normalizeThreadName): Deleted. (WTF::createThread): Deleted. (WTF::setCurrentThreadIsUserInteractive): Deleted. (WTF::setCurrentThreadIsUserInitiated): Deleted. (WTF::setGlobalMaxQOSClass): Deleted. (WTF::adjustedQOSClass): Deleted. * wtf/Threading.h: (WTF::Thread::id): (WTF::Thread::operator==): (WTF::Thread::operator!=): (WTF::Thread::joinableState): (WTF::Thread::didBecomeDetached): (WTF::Thread::didJoin): (WTF::Thread::hasExited): (WTF::currentThread): * wtf/ThreadingPthreads.cpp: (WTF::Thread::Thread): (WTF::Thread::~Thread): (WTF::Thread::signalHandlerSuspendResume): (WTF::Thread::initializePlatformThreading): (WTF::initializeCurrentThreadEvenIfNonWTFCreated): (WTF::wtfThreadEntryPoint): (WTF::Thread::createInternal): (WTF::Thread::initializeCurrentThreadInternal): (WTF::Thread::changePriority): (WTF::Thread::waitForCompletion): (WTF::Thread::detach): (WTF::Thread::current): (WTF::Thread::currentID): (WTF::Thread::signal): (WTF::Thread::resume): (WTF::Thread::getRegisters): (WTF::Thread::didExit): (WTF::Thread::establish): (WTF::PthreadState::PthreadState): Deleted. (WTF::PthreadState::joinableState): Deleted. (WTF::PthreadState::pthreadHandle): Deleted. (WTF::PthreadState::didBecomeDetached): Deleted. (WTF::PthreadState::didExit): Deleted. (WTF::PthreadState::didJoin): Deleted. (WTF::PthreadState::hasExited): Deleted. (WTF::threadMapMutex): Deleted. (WTF::initializeThreading): Deleted. (WTF::threadMap): Deleted. (WTF::identifierByPthreadHandle): Deleted. (WTF::establishIdentifierForPthreadHandle): Deleted. (WTF::pthreadHandleForIdentifierWithLockAlreadyHeld): Deleted. (WTF::createThreadInternal): Deleted. (WTF::initializeCurrentThreadInternal): Deleted. (WTF::changeThreadPriority): Deleted. (WTF::waitForThreadCompletion): Deleted. (WTF::detachThread): Deleted. (WTF::threadDidExit): Deleted. (WTF::currentThread): Deleted. (WTF::signalThread): Deleted. * wtf/ThreadingWin.cpp: (WTF::Thread::Thread): (WTF::Thread::~Thread): (WTF::Thread::initializeCurrentThreadInternal): (WTF::Thread::initializePlatformThreading): (WTF::wtfThreadEntryPoint): (WTF::Thread::createInternal): (WTF::Thread::changePriority): (WTF::Thread::waitForCompletion): (WTF::Thread::detach): (WTF::Thread::resume): (WTF::Thread::getRegisters): (WTF::Thread::current): (WTF::Thread::currentID): (WTF::Thread::didExit): (WTF::Thread::establish): (WTF::initializeCurrentThreadInternal): Deleted. (WTF::threadMapMutex): Deleted. (WTF::initializeThreading): Deleted. (WTF::threadMap): Deleted. (WTF::storeThreadHandleByIdentifier): Deleted. (WTF::threadHandleForIdentifier): Deleted. (WTF::clearThreadHandleForIdentifier): Deleted. (WTF::createThreadInternal): Deleted. (WTF::changeThreadPriority): Deleted. (WTF::waitForThreadCompletion): Deleted. (WTF::detachThread): Deleted. (WTF::currentThread): Deleted. * wtf/WorkQueue.cpp: (WTF::WorkQueue::concurrentApply): * wtf/WorkQueue.h: * wtf/cocoa/WorkQueueCocoa.cpp: (WTF::dispatchQOSClass): * wtf/generic/WorkQueueGeneric.cpp: (WorkQueue::platformInitialize): (WorkQueue::platformInvalidate): * wtf/linux/MemoryPressureHandlerLinux.cpp: (WTF::MemoryPressureHandler::EventFDPoller::EventFDPoller): (WTF::MemoryPressureHandler::EventFDPoller::~EventFDPoller): * wtf/win/MainThreadWin.cpp: (WTF::initializeMainThreadPlatform): Tools: Mechanical change. Use Thread:: APIs. * DumpRenderTree/JavaScriptThreading.cpp: (runJavaScriptThread): (startJavaScriptThreads): (stopJavaScriptThreads): * DumpRenderTree/mac/DumpRenderTree.mm: (testThreadIdentifierMap): * TestWebKitAPI/Tests/WTF/Condition.cpp: * TestWebKitAPI/Tests/WTF/Lock.cpp: (TestWebKitAPI::runLockTest): * TestWebKitAPI/Tests/WTF/ParkingLot.cpp: Canonical link: https://commits.webkit.org/187690@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@215265 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-04-12 12:08:29 +00:00
#else
#include <sys/ucontext.h>
[Re-landing] Change JSLock to stash PlatformThread instead of std::thread::id. https://bugs.webkit.org/show_bug.cgi?id=168996 Reviewed by Filip Pizlo and Saam Barati. PlatformThread is more useful because it allows us to: 1. find the MachineThreads::Thread which is associated with it. 2. suspend / resume threads. 3. send a signal to a thread. We can't do those with std::thread::id. We will need one or more of these capabilities to implement non-polling VM traps later. Update: Since we don't have a canonical "uninitialized" value for PlatformThread, we now have a JSLock::m_hasOwnerThread flag that is set to true if and only the m_ownerThread value is valid. JSLock::currentThreadIsHoldingLock() now checks JSLock::m_hasOwnerThread before doing the thread identity comparison. * JavaScriptCore.xcodeproj/project.pbxproj: * heap/MachineStackMarker.cpp: (JSC::MachineThreads::Thread::createForCurrentThread): (JSC::MachineThreads::machineThreadForCurrentThread): (JSC::MachineThreads::removeThread): (JSC::MachineThreads::Thread::suspend): (JSC::MachineThreads::tryCopyOtherThreadStacks): (JSC::getCurrentPlatformThread): Deleted. * heap/MachineStackMarker.h: * runtime/JSCellInlines.h: (JSC::JSCell::classInfo): * runtime/JSLock.cpp: (JSC::JSLock::JSLock): (JSC::JSLock::lock): (JSC::JSLock::unlock): (JSC::JSLock::currentThreadIsHoldingLock): Deleted. * runtime/JSLock.h: (JSC::JSLock::ownerThread): (JSC::JSLock::currentThreadIsHoldingLock): * runtime/PlatformThread.h: Added. (JSC::currentPlatformThread): * runtime/VM.cpp: (JSC::VM::~VM): * runtime/VM.h: (JSC::VM::ownerThread): * runtime/Watchdog.cpp: (JSC::Watchdog::setTimeLimit): (JSC::Watchdog::shouldTerminate): (JSC::Watchdog::startTimer): (JSC::Watchdog::stopTimer): * tools/JSDollarVMPrototype.cpp: (JSC::JSDollarVMPrototype::currentThreadOwnsJSLock): * tools/VMInspector.cpp: Canonical link: https://commits.webkit.org/186036@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@213238 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-03-01 20:15:08 +00:00
#endif
[WTF] Introduce Thread class and use RefPtr<Thread> and align Windows Threading implementation semantics to Pthread one https://bugs.webkit.org/show_bug.cgi?id=170502 Reviewed by Mark Lam. Source/JavaScriptCore: * API/tests/CompareAndSwapTest.cpp: (testCompareAndSwap): * JavaScriptCore.xcodeproj/project.pbxproj: * b3/air/testair.cpp: * b3/testb3.cpp: (JSC::B3::run): * bytecode/SuperSampler.cpp: (JSC::initializeSuperSampler): * dfg/DFGWorklist.cpp: * disassembler/Disassembler.cpp: * heap/Heap.cpp: (JSC::Heap::lastChanceToFinalize): (JSC::Heap::notifyIsSafeToCollect): * heap/Heap.h: * heap/MachineStackMarker.cpp: (JSC::MachineThreads::~MachineThreads): (JSC::MachineThreads::addCurrentThread): (JSC::MachineThreads::removeThread): (JSC::MachineThreads::removeThreadIfFound): (JSC::MachineThreads::MachineThread::MachineThread): (JSC::MachineThreads::MachineThread::getRegisters): (JSC::MachineThreads::MachineThread::Registers::stackPointer): (JSC::MachineThreads::MachineThread::Registers::framePointer): (JSC::MachineThreads::MachineThread::Registers::instructionPointer): (JSC::MachineThreads::MachineThread::Registers::llintPC): (JSC::MachineThreads::MachineThread::captureStack): (JSC::MachineThreads::tryCopyOtherThreadStack): (JSC::MachineThreads::tryCopyOtherThreadStacks): (pthreadSignalHandlerSuspendResume): Deleted. (JSC::threadData): Deleted. (JSC::MachineThreads::Thread::Thread): Deleted. (JSC::MachineThreads::Thread::createForCurrentThread): Deleted. (JSC::MachineThreads::Thread::operator==): Deleted. (JSC::MachineThreads::machineThreadForCurrentThread): Deleted. (JSC::MachineThreads::ThreadData::ThreadData): Deleted. (JSC::MachineThreads::ThreadData::~ThreadData): Deleted. (JSC::MachineThreads::ThreadData::suspend): Deleted. (JSC::MachineThreads::ThreadData::resume): Deleted. (JSC::MachineThreads::ThreadData::getRegisters): Deleted. (JSC::MachineThreads::ThreadData::Registers::stackPointer): Deleted. (JSC::MachineThreads::ThreadData::Registers::framePointer): Deleted. (JSC::MachineThreads::ThreadData::Registers::instructionPointer): Deleted. (JSC::MachineThreads::ThreadData::Registers::llintPC): Deleted. (JSC::MachineThreads::ThreadData::freeRegisters): Deleted. (JSC::MachineThreads::ThreadData::captureStack): Deleted. * heap/MachineStackMarker.h: (JSC::MachineThreads::MachineThread::suspend): (JSC::MachineThreads::MachineThread::resume): (JSC::MachineThreads::MachineThread::threadID): (JSC::MachineThreads::MachineThread::stackBase): (JSC::MachineThreads::MachineThread::stackEnd): (JSC::MachineThreads::threadsListHead): (JSC::MachineThreads::Thread::operator!=): Deleted. (JSC::MachineThreads::Thread::suspend): Deleted. (JSC::MachineThreads::Thread::resume): Deleted. (JSC::MachineThreads::Thread::getRegisters): Deleted. (JSC::MachineThreads::Thread::freeRegisters): Deleted. (JSC::MachineThreads::Thread::captureStack): Deleted. (JSC::MachineThreads::Thread::platformThread): Deleted. (JSC::MachineThreads::Thread::stackBase): Deleted. (JSC::MachineThreads::Thread::stackEnd): Deleted. * jit/ICStats.cpp: (JSC::ICStats::ICStats): (JSC::ICStats::~ICStats): * jit/ICStats.h: * jsc.cpp: (functionDollarAgentStart): (startTimeoutThreadIfNeeded): * runtime/JSLock.cpp: (JSC::JSLock::lock): * runtime/JSLock.h: (JSC::JSLock::ownerThread): (JSC::JSLock::currentThreadIsHoldingLock): * runtime/SamplingProfiler.cpp: (JSC::FrameWalker::isValidFramePointer): (JSC::SamplingProfiler::SamplingProfiler): (JSC::SamplingProfiler::createThreadIfNecessary): (JSC::SamplingProfiler::takeSample): * runtime/SamplingProfiler.h: * runtime/VM.h: (JSC::VM::ownerThread): * runtime/VMTraps.cpp: (JSC::findActiveVMAndStackBounds): (JSC::VMTraps::SignalSender::send): (JSC::VMTraps::fireTrap): Source/WebCore: Mechanical change. Use Thread:: APIs. * Modules/indexeddb/server/IDBServer.cpp: (WebCore::IDBServer::IDBServer::IDBServer): * Modules/indexeddb/server/IDBServer.h: * Modules/webaudio/AsyncAudioDecoder.cpp: (WebCore::AsyncAudioDecoder::AsyncAudioDecoder): (WebCore::AsyncAudioDecoder::~AsyncAudioDecoder): (WebCore::AsyncAudioDecoder::runLoop): * Modules/webaudio/AsyncAudioDecoder.h: * Modules/webaudio/OfflineAudioDestinationNode.cpp: (WebCore::OfflineAudioDestinationNode::OfflineAudioDestinationNode): (WebCore::OfflineAudioDestinationNode::uninitialize): (WebCore::OfflineAudioDestinationNode::startRendering): * Modules/webaudio/OfflineAudioDestinationNode.h: * Modules/webdatabase/Database.cpp: (WebCore::Database::securityOrigin): * Modules/webdatabase/DatabaseThread.cpp: (WebCore::DatabaseThread::start): (WebCore::DatabaseThread::databaseThread): (WebCore::DatabaseThread::recordDatabaseOpen): (WebCore::DatabaseThread::recordDatabaseClosed): * Modules/webdatabase/DatabaseThread.h: (WebCore::DatabaseThread::getThreadID): * bindings/js/GCController.cpp: (WebCore::GCController::garbageCollectOnAlternateThreadForDebugging): * fileapi/AsyncFileStream.cpp: (WebCore::callOnFileThread): * loader/icon/IconDatabase.cpp: (WebCore::IconDatabase::open): (WebCore::IconDatabase::close): * loader/icon/IconDatabase.h: * page/ResourceUsageThread.cpp: (WebCore::ResourceUsageThread::createThreadIfNeeded): * page/ResourceUsageThread.h: * page/scrolling/ScrollingThread.cpp: (WebCore::ScrollingThread::ScrollingThread): (WebCore::ScrollingThread::isCurrentThread): (WebCore::ScrollingThread::createThreadIfNeeded): (WebCore::ScrollingThread::threadCallback): * page/scrolling/ScrollingThread.h: * platform/audio/HRTFDatabaseLoader.cpp: (WebCore::HRTFDatabaseLoader::HRTFDatabaseLoader): (WebCore::HRTFDatabaseLoader::loadAsynchronously): (WebCore::HRTFDatabaseLoader::waitForLoaderThreadCompletion): * platform/audio/HRTFDatabaseLoader.h: * platform/audio/ReverbConvolver.cpp: (WebCore::ReverbConvolver::ReverbConvolver): (WebCore::ReverbConvolver::~ReverbConvolver): * platform/audio/ReverbConvolver.h: * platform/audio/gstreamer/AudioFileReaderGStreamer.cpp: (WebCore::createBusFromAudioFile): (WebCore::createBusFromInMemoryAudioFile): * platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp: (ResourceHandleStreamingClient::ResourceHandleStreamingClient): (ResourceHandleStreamingClient::~ResourceHandleStreamingClient): * platform/network/cf/LoaderRunLoopCF.cpp: (WebCore::loaderRunLoop): * platform/network/curl/CurlDownload.cpp: (WebCore::CurlDownloadManager::startThreadIfNeeded): (WebCore::CurlDownloadManager::stopThread): * platform/network/curl/CurlDownload.h: * platform/network/curl/SocketStreamHandleImpl.h: * platform/network/curl/SocketStreamHandleImplCurl.cpp: (WebCore::SocketStreamHandleImpl::startThread): (WebCore::SocketStreamHandleImpl::stopThread): * workers/WorkerThread.cpp: (WebCore::WorkerThread::WorkerThread): (WebCore::WorkerThread::start): (WebCore::WorkerThread::workerThread): * workers/WorkerThread.h: (WebCore::WorkerThread::threadID): Source/WebKit: Mechanical change. Use Thread:: APIs. * Storage/StorageThread.cpp: (WebCore::StorageThread::StorageThread): (WebCore::StorageThread::~StorageThread): (WebCore::StorageThread::start): (WebCore::StorageThread::dispatch): (WebCore::StorageThread::terminate): * Storage/StorageThread.h: Source/WebKit2: Mechanical change. Use Thread:: APIs. * NetworkProcess/NetworkProcess.cpp: (WebKit::NetworkProcess::initializeNetworkProcess): * NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp: (WebKit::NetworkCache::IOChannel::readSyncInThread): * Platform/IPC/Connection.cpp: (IPC::Connection::processIncomingMessage): * Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.h: (WebKit::XPCServiceInitializer): * UIProcess/linux/MemoryPressureMonitor.cpp: (WebKit::MemoryPressureMonitor::MemoryPressureMonitor): * WebProcess/WebProcess.cpp: (WebKit::WebProcess::initializeWebProcess): Source/WTF: This patch is refactoring of WTF Threading mechanism to merge JavaScriptCore's threading extension to WTF Threading. Previously, JavaScriptCore requires richer threading features (such as suspending and resuming threads), and they are implemented for PlatformThread in JavaScriptCore. But these features should be implemented in WTF Threading side instead of maintaining JSC's own threading features too. This patch removes these features from JSC and move it to WTF Threading. However, current WTF Threading has one problem: Windows version of WTF Threading has different semantics from Pthreads one. In Windows WTF Threading, we cannot perform any operation after the target thread is detached: WTF Threading stop tracking the state of the thread once the thread is detached. But this is not the same to Pthreads one. In Pthreads, pthread_detach just means that the resource of the thread will be destroyed automatically. While some operations like pthread_join will be rejected, some operations like pthread_kill will be accepted. The problem is that detached thread can be suspended and resumed in JSC. For example, in jsc.cpp, we start the worker thread and detach it immediately. In worker thread, we will create VM and thus concurrent GC will suspend and resume the detached thread. However, in Windows WTF Threading, we have no reference to the detached thread. Thus we cannot perform suspend and resume operations onto the detached thread. To solve the problem, we change Windows Threading mechanism drastically to align it to the Pthread semantics. In the new Threading, we have RefPtr<Thread> class. It holds a handle to a platform thread. We can perform threading operations with this class. For example, Thread::suspend is offered. And we use destructor of the thread local variable to release the resources held by RefPtr<Thread>. In Windows, Thread::detach does nothing because the resource will be destroyed automatically by RefPtr<Thread>. To do so, we introduce ThreadHolder for Windows. This is similar to the previous ThreadIdentifierData for Pthreads. It holds RefPtr<Thread> in the thread local storage (technically, it is Fiber Local Storage in Windows). Thread::current() will return this reference. The problematic situation is that the order of the deallocation of the thread local storage is not defined. So we should not touch thread local storage in the destructor of the thread local storage. To avoid such edge cases, we have currentThread() / Thread::currentID() APIs. They are safe to be called even in the destructor of the other thread local storage. And in Windows, in the FLS destructor, we will create the thread_local variable to defer the destruction of the ThreadHolder. We ensure that this destructor is called after the other FLS destructors are called in Windows 10. This patch is performance neutral. * WTF.xcodeproj/project.pbxproj: * benchmarks/ConditionSpeedTest.cpp: * benchmarks/LockFairnessTest.cpp: * benchmarks/LockSpeedTest.cpp: * wtf/AutomaticThread.cpp: (WTF::AutomaticThread::start): * wtf/CMakeLists.txt: * wtf/MainThread.h: * wtf/MemoryPressureHandler.h: * wtf/ParallelJobsGeneric.cpp: (WTF::ParallelEnvironment::ThreadPrivate::tryLockFor): (WTF::ParallelEnvironment::ThreadPrivate::workerThread): * wtf/ParallelJobsGeneric.h: (WTF::ParallelEnvironment::ThreadPrivate::ThreadPrivate): Deleted. * wtf/ParkingLot.cpp: (WTF::ParkingLot::forEachImpl): * wtf/ParkingLot.h: (WTF::ParkingLot::forEach): * wtf/PlatformRegisters.h: Renamed from Source/JavaScriptCore/runtime/PlatformThread.h. * wtf/RefPtr.h: (WTF::RefPtr::RefPtr): * wtf/ThreadFunctionInvocation.h: (WTF::ThreadFunctionInvocation::ThreadFunctionInvocation): * wtf/ThreadHolder.cpp: Added. (WTF::ThreadHolder::~ThreadHolder): (WTF::ThreadHolder::initialize): * wtf/ThreadHolder.h: Renamed from Source/WTF/wtf/ThreadIdentifierDataPthreads.h. (WTF::ThreadHolder::thread): (WTF::ThreadHolder::ThreadHolder): * wtf/ThreadHolderPthreads.cpp: Renamed from Source/WTF/wtf/ThreadIdentifierDataPthreads.cpp. (WTF::ThreadHolder::initializeOnce): (WTF::ThreadHolder::current): (WTF::ThreadHolder::destruct): * wtf/ThreadHolderWin.cpp: Added. (WTF::threadMapMutex): (WTF::threadMap): (WTF::ThreadHolder::initializeOnce): (WTF::ThreadHolder::current): (WTF::ThreadHolder::destruct): * wtf/ThreadSpecific.h: * wtf/Threading.cpp: (WTF::Thread::normalizeThreadName): (WTF::threadEntryPoint): (WTF::Thread::create): (WTF::Thread::setCurrentThreadIsUserInteractive): (WTF::Thread::setCurrentThreadIsUserInitiated): (WTF::Thread::setGlobalMaxQOSClass): (WTF::Thread::adjustedQOSClass): (WTF::Thread::dump): (WTF::initializeThreading): (WTF::normalizeThreadName): Deleted. (WTF::createThread): Deleted. (WTF::setCurrentThreadIsUserInteractive): Deleted. (WTF::setCurrentThreadIsUserInitiated): Deleted. (WTF::setGlobalMaxQOSClass): Deleted. (WTF::adjustedQOSClass): Deleted. * wtf/Threading.h: (WTF::Thread::id): (WTF::Thread::operator==): (WTF::Thread::operator!=): (WTF::Thread::joinableState): (WTF::Thread::didBecomeDetached): (WTF::Thread::didJoin): (WTF::Thread::hasExited): (WTF::currentThread): * wtf/ThreadingPthreads.cpp: (WTF::Thread::Thread): (WTF::Thread::~Thread): (WTF::Thread::signalHandlerSuspendResume): (WTF::Thread::initializePlatformThreading): (WTF::initializeCurrentThreadEvenIfNonWTFCreated): (WTF::wtfThreadEntryPoint): (WTF::Thread::createInternal): (WTF::Thread::initializeCurrentThreadInternal): (WTF::Thread::changePriority): (WTF::Thread::waitForCompletion): (WTF::Thread::detach): (WTF::Thread::current): (WTF::Thread::currentID): (WTF::Thread::signal): (WTF::Thread::resume): (WTF::Thread::getRegisters): (WTF::Thread::didExit): (WTF::Thread::establish): (WTF::PthreadState::PthreadState): Deleted. (WTF::PthreadState::joinableState): Deleted. (WTF::PthreadState::pthreadHandle): Deleted. (WTF::PthreadState::didBecomeDetached): Deleted. (WTF::PthreadState::didExit): Deleted. (WTF::PthreadState::didJoin): Deleted. (WTF::PthreadState::hasExited): Deleted. (WTF::threadMapMutex): Deleted. (WTF::initializeThreading): Deleted. (WTF::threadMap): Deleted. (WTF::identifierByPthreadHandle): Deleted. (WTF::establishIdentifierForPthreadHandle): Deleted. (WTF::pthreadHandleForIdentifierWithLockAlreadyHeld): Deleted. (WTF::createThreadInternal): Deleted. (WTF::initializeCurrentThreadInternal): Deleted. (WTF::changeThreadPriority): Deleted. (WTF::waitForThreadCompletion): Deleted. (WTF::detachThread): Deleted. (WTF::threadDidExit): Deleted. (WTF::currentThread): Deleted. (WTF::signalThread): Deleted. * wtf/ThreadingWin.cpp: (WTF::Thread::Thread): (WTF::Thread::~Thread): (WTF::Thread::initializeCurrentThreadInternal): (WTF::Thread::initializePlatformThreading): (WTF::wtfThreadEntryPoint): (WTF::Thread::createInternal): (WTF::Thread::changePriority): (WTF::Thread::waitForCompletion): (WTF::Thread::detach): (WTF::Thread::resume): (WTF::Thread::getRegisters): (WTF::Thread::current): (WTF::Thread::currentID): (WTF::Thread::didExit): (WTF::Thread::establish): (WTF::initializeCurrentThreadInternal): Deleted. (WTF::threadMapMutex): Deleted. (WTF::initializeThreading): Deleted. (WTF::threadMap): Deleted. (WTF::storeThreadHandleByIdentifier): Deleted. (WTF::threadHandleForIdentifier): Deleted. (WTF::clearThreadHandleForIdentifier): Deleted. (WTF::createThreadInternal): Deleted. (WTF::changeThreadPriority): Deleted. (WTF::waitForThreadCompletion): Deleted. (WTF::detachThread): Deleted. (WTF::currentThread): Deleted. * wtf/WorkQueue.cpp: (WTF::WorkQueue::concurrentApply): * wtf/WorkQueue.h: * wtf/cocoa/WorkQueueCocoa.cpp: (WTF::dispatchQOSClass): * wtf/generic/WorkQueueGeneric.cpp: (WorkQueue::platformInitialize): (WorkQueue::platformInvalidate): * wtf/linux/MemoryPressureHandlerLinux.cpp: (WTF::MemoryPressureHandler::EventFDPoller::EventFDPoller): (WTF::MemoryPressureHandler::EventFDPoller::~EventFDPoller): * wtf/win/MainThreadWin.cpp: (WTF::initializeMainThreadPlatform): Tools: Mechanical change. Use Thread:: APIs. * DumpRenderTree/JavaScriptThreading.cpp: (runJavaScriptThread): (startJavaScriptThreads): (stopJavaScriptThreads): * DumpRenderTree/mac/DumpRenderTree.mm: (testThreadIdentifierMap): * TestWebKitAPI/Tests/WTF/Condition.cpp: * TestWebKitAPI/Tests/WTF/Lock.cpp: (TestWebKitAPI::runLockTest): * TestWebKitAPI/Tests/WTF/ParkingLot.cpp: Canonical link: https://commits.webkit.org/187690@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@215265 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-04-12 12:08:29 +00:00
namespace WTF {
[Re-landing] Change JSLock to stash PlatformThread instead of std::thread::id. https://bugs.webkit.org/show_bug.cgi?id=168996 Reviewed by Filip Pizlo and Saam Barati. PlatformThread is more useful because it allows us to: 1. find the MachineThreads::Thread which is associated with it. 2. suspend / resume threads. 3. send a signal to a thread. We can't do those with std::thread::id. We will need one or more of these capabilities to implement non-polling VM traps later. Update: Since we don't have a canonical "uninitialized" value for PlatformThread, we now have a JSLock::m_hasOwnerThread flag that is set to true if and only the m_ownerThread value is valid. JSLock::currentThreadIsHoldingLock() now checks JSLock::m_hasOwnerThread before doing the thread identity comparison. * JavaScriptCore.xcodeproj/project.pbxproj: * heap/MachineStackMarker.cpp: (JSC::MachineThreads::Thread::createForCurrentThread): (JSC::MachineThreads::machineThreadForCurrentThread): (JSC::MachineThreads::removeThread): (JSC::MachineThreads::Thread::suspend): (JSC::MachineThreads::tryCopyOtherThreadStacks): (JSC::getCurrentPlatformThread): Deleted. * heap/MachineStackMarker.h: * runtime/JSCellInlines.h: (JSC::JSCell::classInfo): * runtime/JSLock.cpp: (JSC::JSLock::JSLock): (JSC::JSLock::lock): (JSC::JSLock::unlock): (JSC::JSLock::currentThreadIsHoldingLock): Deleted. * runtime/JSLock.h: (JSC::JSLock::ownerThread): (JSC::JSLock::currentThreadIsHoldingLock): * runtime/PlatformThread.h: Added. (JSC::currentPlatformThread): * runtime/VM.cpp: (JSC::VM::~VM): * runtime/VM.h: (JSC::VM::ownerThread): * runtime/Watchdog.cpp: (JSC::Watchdog::setTimeLimit): (JSC::Watchdog::shouldTerminate): (JSC::Watchdog::startTimer): (JSC::Watchdog::stopTimer): * tools/JSDollarVMPrototype.cpp: (JSC::JSDollarVMPrototype::currentThreadOwnsJSLock): * tools/VMInspector.cpp: Canonical link: https://commits.webkit.org/186036@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@213238 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-03-01 20:15:08 +00:00
#if OS(DARWIN)
[WTF] Introduce Thread class and use RefPtr<Thread> and align Windows Threading implementation semantics to Pthread one https://bugs.webkit.org/show_bug.cgi?id=170502 Reviewed by Mark Lam. Source/JavaScriptCore: * API/tests/CompareAndSwapTest.cpp: (testCompareAndSwap): * JavaScriptCore.xcodeproj/project.pbxproj: * b3/air/testair.cpp: * b3/testb3.cpp: (JSC::B3::run): * bytecode/SuperSampler.cpp: (JSC::initializeSuperSampler): * dfg/DFGWorklist.cpp: * disassembler/Disassembler.cpp: * heap/Heap.cpp: (JSC::Heap::lastChanceToFinalize): (JSC::Heap::notifyIsSafeToCollect): * heap/Heap.h: * heap/MachineStackMarker.cpp: (JSC::MachineThreads::~MachineThreads): (JSC::MachineThreads::addCurrentThread): (JSC::MachineThreads::removeThread): (JSC::MachineThreads::removeThreadIfFound): (JSC::MachineThreads::MachineThread::MachineThread): (JSC::MachineThreads::MachineThread::getRegisters): (JSC::MachineThreads::MachineThread::Registers::stackPointer): (JSC::MachineThreads::MachineThread::Registers::framePointer): (JSC::MachineThreads::MachineThread::Registers::instructionPointer): (JSC::MachineThreads::MachineThread::Registers::llintPC): (JSC::MachineThreads::MachineThread::captureStack): (JSC::MachineThreads::tryCopyOtherThreadStack): (JSC::MachineThreads::tryCopyOtherThreadStacks): (pthreadSignalHandlerSuspendResume): Deleted. (JSC::threadData): Deleted. (JSC::MachineThreads::Thread::Thread): Deleted. (JSC::MachineThreads::Thread::createForCurrentThread): Deleted. (JSC::MachineThreads::Thread::operator==): Deleted. (JSC::MachineThreads::machineThreadForCurrentThread): Deleted. (JSC::MachineThreads::ThreadData::ThreadData): Deleted. (JSC::MachineThreads::ThreadData::~ThreadData): Deleted. (JSC::MachineThreads::ThreadData::suspend): Deleted. (JSC::MachineThreads::ThreadData::resume): Deleted. (JSC::MachineThreads::ThreadData::getRegisters): Deleted. (JSC::MachineThreads::ThreadData::Registers::stackPointer): Deleted. (JSC::MachineThreads::ThreadData::Registers::framePointer): Deleted. (JSC::MachineThreads::ThreadData::Registers::instructionPointer): Deleted. (JSC::MachineThreads::ThreadData::Registers::llintPC): Deleted. (JSC::MachineThreads::ThreadData::freeRegisters): Deleted. (JSC::MachineThreads::ThreadData::captureStack): Deleted. * heap/MachineStackMarker.h: (JSC::MachineThreads::MachineThread::suspend): (JSC::MachineThreads::MachineThread::resume): (JSC::MachineThreads::MachineThread::threadID): (JSC::MachineThreads::MachineThread::stackBase): (JSC::MachineThreads::MachineThread::stackEnd): (JSC::MachineThreads::threadsListHead): (JSC::MachineThreads::Thread::operator!=): Deleted. (JSC::MachineThreads::Thread::suspend): Deleted. (JSC::MachineThreads::Thread::resume): Deleted. (JSC::MachineThreads::Thread::getRegisters): Deleted. (JSC::MachineThreads::Thread::freeRegisters): Deleted. (JSC::MachineThreads::Thread::captureStack): Deleted. (JSC::MachineThreads::Thread::platformThread): Deleted. (JSC::MachineThreads::Thread::stackBase): Deleted. (JSC::MachineThreads::Thread::stackEnd): Deleted. * jit/ICStats.cpp: (JSC::ICStats::ICStats): (JSC::ICStats::~ICStats): * jit/ICStats.h: * jsc.cpp: (functionDollarAgentStart): (startTimeoutThreadIfNeeded): * runtime/JSLock.cpp: (JSC::JSLock::lock): * runtime/JSLock.h: (JSC::JSLock::ownerThread): (JSC::JSLock::currentThreadIsHoldingLock): * runtime/SamplingProfiler.cpp: (JSC::FrameWalker::isValidFramePointer): (JSC::SamplingProfiler::SamplingProfiler): (JSC::SamplingProfiler::createThreadIfNecessary): (JSC::SamplingProfiler::takeSample): * runtime/SamplingProfiler.h: * runtime/VM.h: (JSC::VM::ownerThread): * runtime/VMTraps.cpp: (JSC::findActiveVMAndStackBounds): (JSC::VMTraps::SignalSender::send): (JSC::VMTraps::fireTrap): Source/WebCore: Mechanical change. Use Thread:: APIs. * Modules/indexeddb/server/IDBServer.cpp: (WebCore::IDBServer::IDBServer::IDBServer): * Modules/indexeddb/server/IDBServer.h: * Modules/webaudio/AsyncAudioDecoder.cpp: (WebCore::AsyncAudioDecoder::AsyncAudioDecoder): (WebCore::AsyncAudioDecoder::~AsyncAudioDecoder): (WebCore::AsyncAudioDecoder::runLoop): * Modules/webaudio/AsyncAudioDecoder.h: * Modules/webaudio/OfflineAudioDestinationNode.cpp: (WebCore::OfflineAudioDestinationNode::OfflineAudioDestinationNode): (WebCore::OfflineAudioDestinationNode::uninitialize): (WebCore::OfflineAudioDestinationNode::startRendering): * Modules/webaudio/OfflineAudioDestinationNode.h: * Modules/webdatabase/Database.cpp: (WebCore::Database::securityOrigin): * Modules/webdatabase/DatabaseThread.cpp: (WebCore::DatabaseThread::start): (WebCore::DatabaseThread::databaseThread): (WebCore::DatabaseThread::recordDatabaseOpen): (WebCore::DatabaseThread::recordDatabaseClosed): * Modules/webdatabase/DatabaseThread.h: (WebCore::DatabaseThread::getThreadID): * bindings/js/GCController.cpp: (WebCore::GCController::garbageCollectOnAlternateThreadForDebugging): * fileapi/AsyncFileStream.cpp: (WebCore::callOnFileThread): * loader/icon/IconDatabase.cpp: (WebCore::IconDatabase::open): (WebCore::IconDatabase::close): * loader/icon/IconDatabase.h: * page/ResourceUsageThread.cpp: (WebCore::ResourceUsageThread::createThreadIfNeeded): * page/ResourceUsageThread.h: * page/scrolling/ScrollingThread.cpp: (WebCore::ScrollingThread::ScrollingThread): (WebCore::ScrollingThread::isCurrentThread): (WebCore::ScrollingThread::createThreadIfNeeded): (WebCore::ScrollingThread::threadCallback): * page/scrolling/ScrollingThread.h: * platform/audio/HRTFDatabaseLoader.cpp: (WebCore::HRTFDatabaseLoader::HRTFDatabaseLoader): (WebCore::HRTFDatabaseLoader::loadAsynchronously): (WebCore::HRTFDatabaseLoader::waitForLoaderThreadCompletion): * platform/audio/HRTFDatabaseLoader.h: * platform/audio/ReverbConvolver.cpp: (WebCore::ReverbConvolver::ReverbConvolver): (WebCore::ReverbConvolver::~ReverbConvolver): * platform/audio/ReverbConvolver.h: * platform/audio/gstreamer/AudioFileReaderGStreamer.cpp: (WebCore::createBusFromAudioFile): (WebCore::createBusFromInMemoryAudioFile): * platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp: (ResourceHandleStreamingClient::ResourceHandleStreamingClient): (ResourceHandleStreamingClient::~ResourceHandleStreamingClient): * platform/network/cf/LoaderRunLoopCF.cpp: (WebCore::loaderRunLoop): * platform/network/curl/CurlDownload.cpp: (WebCore::CurlDownloadManager::startThreadIfNeeded): (WebCore::CurlDownloadManager::stopThread): * platform/network/curl/CurlDownload.h: * platform/network/curl/SocketStreamHandleImpl.h: * platform/network/curl/SocketStreamHandleImplCurl.cpp: (WebCore::SocketStreamHandleImpl::startThread): (WebCore::SocketStreamHandleImpl::stopThread): * workers/WorkerThread.cpp: (WebCore::WorkerThread::WorkerThread): (WebCore::WorkerThread::start): (WebCore::WorkerThread::workerThread): * workers/WorkerThread.h: (WebCore::WorkerThread::threadID): Source/WebKit: Mechanical change. Use Thread:: APIs. * Storage/StorageThread.cpp: (WebCore::StorageThread::StorageThread): (WebCore::StorageThread::~StorageThread): (WebCore::StorageThread::start): (WebCore::StorageThread::dispatch): (WebCore::StorageThread::terminate): * Storage/StorageThread.h: Source/WebKit2: Mechanical change. Use Thread:: APIs. * NetworkProcess/NetworkProcess.cpp: (WebKit::NetworkProcess::initializeNetworkProcess): * NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp: (WebKit::NetworkCache::IOChannel::readSyncInThread): * Platform/IPC/Connection.cpp: (IPC::Connection::processIncomingMessage): * Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.h: (WebKit::XPCServiceInitializer): * UIProcess/linux/MemoryPressureMonitor.cpp: (WebKit::MemoryPressureMonitor::MemoryPressureMonitor): * WebProcess/WebProcess.cpp: (WebKit::WebProcess::initializeWebProcess): Source/WTF: This patch is refactoring of WTF Threading mechanism to merge JavaScriptCore's threading extension to WTF Threading. Previously, JavaScriptCore requires richer threading features (such as suspending and resuming threads), and they are implemented for PlatformThread in JavaScriptCore. But these features should be implemented in WTF Threading side instead of maintaining JSC's own threading features too. This patch removes these features from JSC and move it to WTF Threading. However, current WTF Threading has one problem: Windows version of WTF Threading has different semantics from Pthreads one. In Windows WTF Threading, we cannot perform any operation after the target thread is detached: WTF Threading stop tracking the state of the thread once the thread is detached. But this is not the same to Pthreads one. In Pthreads, pthread_detach just means that the resource of the thread will be destroyed automatically. While some operations like pthread_join will be rejected, some operations like pthread_kill will be accepted. The problem is that detached thread can be suspended and resumed in JSC. For example, in jsc.cpp, we start the worker thread and detach it immediately. In worker thread, we will create VM and thus concurrent GC will suspend and resume the detached thread. However, in Windows WTF Threading, we have no reference to the detached thread. Thus we cannot perform suspend and resume operations onto the detached thread. To solve the problem, we change Windows Threading mechanism drastically to align it to the Pthread semantics. In the new Threading, we have RefPtr<Thread> class. It holds a handle to a platform thread. We can perform threading operations with this class. For example, Thread::suspend is offered. And we use destructor of the thread local variable to release the resources held by RefPtr<Thread>. In Windows, Thread::detach does nothing because the resource will be destroyed automatically by RefPtr<Thread>. To do so, we introduce ThreadHolder for Windows. This is similar to the previous ThreadIdentifierData for Pthreads. It holds RefPtr<Thread> in the thread local storage (technically, it is Fiber Local Storage in Windows). Thread::current() will return this reference. The problematic situation is that the order of the deallocation of the thread local storage is not defined. So we should not touch thread local storage in the destructor of the thread local storage. To avoid such edge cases, we have currentThread() / Thread::currentID() APIs. They are safe to be called even in the destructor of the other thread local storage. And in Windows, in the FLS destructor, we will create the thread_local variable to defer the destruction of the ThreadHolder. We ensure that this destructor is called after the other FLS destructors are called in Windows 10. This patch is performance neutral. * WTF.xcodeproj/project.pbxproj: * benchmarks/ConditionSpeedTest.cpp: * benchmarks/LockFairnessTest.cpp: * benchmarks/LockSpeedTest.cpp: * wtf/AutomaticThread.cpp: (WTF::AutomaticThread::start): * wtf/CMakeLists.txt: * wtf/MainThread.h: * wtf/MemoryPressureHandler.h: * wtf/ParallelJobsGeneric.cpp: (WTF::ParallelEnvironment::ThreadPrivate::tryLockFor): (WTF::ParallelEnvironment::ThreadPrivate::workerThread): * wtf/ParallelJobsGeneric.h: (WTF::ParallelEnvironment::ThreadPrivate::ThreadPrivate): Deleted. * wtf/ParkingLot.cpp: (WTF::ParkingLot::forEachImpl): * wtf/ParkingLot.h: (WTF::ParkingLot::forEach): * wtf/PlatformRegisters.h: Renamed from Source/JavaScriptCore/runtime/PlatformThread.h. * wtf/RefPtr.h: (WTF::RefPtr::RefPtr): * wtf/ThreadFunctionInvocation.h: (WTF::ThreadFunctionInvocation::ThreadFunctionInvocation): * wtf/ThreadHolder.cpp: Added. (WTF::ThreadHolder::~ThreadHolder): (WTF::ThreadHolder::initialize): * wtf/ThreadHolder.h: Renamed from Source/WTF/wtf/ThreadIdentifierDataPthreads.h. (WTF::ThreadHolder::thread): (WTF::ThreadHolder::ThreadHolder): * wtf/ThreadHolderPthreads.cpp: Renamed from Source/WTF/wtf/ThreadIdentifierDataPthreads.cpp. (WTF::ThreadHolder::initializeOnce): (WTF::ThreadHolder::current): (WTF::ThreadHolder::destruct): * wtf/ThreadHolderWin.cpp: Added. (WTF::threadMapMutex): (WTF::threadMap): (WTF::ThreadHolder::initializeOnce): (WTF::ThreadHolder::current): (WTF::ThreadHolder::destruct): * wtf/ThreadSpecific.h: * wtf/Threading.cpp: (WTF::Thread::normalizeThreadName): (WTF::threadEntryPoint): (WTF::Thread::create): (WTF::Thread::setCurrentThreadIsUserInteractive): (WTF::Thread::setCurrentThreadIsUserInitiated): (WTF::Thread::setGlobalMaxQOSClass): (WTF::Thread::adjustedQOSClass): (WTF::Thread::dump): (WTF::initializeThreading): (WTF::normalizeThreadName): Deleted. (WTF::createThread): Deleted. (WTF::setCurrentThreadIsUserInteractive): Deleted. (WTF::setCurrentThreadIsUserInitiated): Deleted. (WTF::setGlobalMaxQOSClass): Deleted. (WTF::adjustedQOSClass): Deleted. * wtf/Threading.h: (WTF::Thread::id): (WTF::Thread::operator==): (WTF::Thread::operator!=): (WTF::Thread::joinableState): (WTF::Thread::didBecomeDetached): (WTF::Thread::didJoin): (WTF::Thread::hasExited): (WTF::currentThread): * wtf/ThreadingPthreads.cpp: (WTF::Thread::Thread): (WTF::Thread::~Thread): (WTF::Thread::signalHandlerSuspendResume): (WTF::Thread::initializePlatformThreading): (WTF::initializeCurrentThreadEvenIfNonWTFCreated): (WTF::wtfThreadEntryPoint): (WTF::Thread::createInternal): (WTF::Thread::initializeCurrentThreadInternal): (WTF::Thread::changePriority): (WTF::Thread::waitForCompletion): (WTF::Thread::detach): (WTF::Thread::current): (WTF::Thread::currentID): (WTF::Thread::signal): (WTF::Thread::resume): (WTF::Thread::getRegisters): (WTF::Thread::didExit): (WTF::Thread::establish): (WTF::PthreadState::PthreadState): Deleted. (WTF::PthreadState::joinableState): Deleted. (WTF::PthreadState::pthreadHandle): Deleted. (WTF::PthreadState::didBecomeDetached): Deleted. (WTF::PthreadState::didExit): Deleted. (WTF::PthreadState::didJoin): Deleted. (WTF::PthreadState::hasExited): Deleted. (WTF::threadMapMutex): Deleted. (WTF::initializeThreading): Deleted. (WTF::threadMap): Deleted. (WTF::identifierByPthreadHandle): Deleted. (WTF::establishIdentifierForPthreadHandle): Deleted. (WTF::pthreadHandleForIdentifierWithLockAlreadyHeld): Deleted. (WTF::createThreadInternal): Deleted. (WTF::initializeCurrentThreadInternal): Deleted. (WTF::changeThreadPriority): Deleted. (WTF::waitForThreadCompletion): Deleted. (WTF::detachThread): Deleted. (WTF::threadDidExit): Deleted. (WTF::currentThread): Deleted. (WTF::signalThread): Deleted. * wtf/ThreadingWin.cpp: (WTF::Thread::Thread): (WTF::Thread::~Thread): (WTF::Thread::initializeCurrentThreadInternal): (WTF::Thread::initializePlatformThreading): (WTF::wtfThreadEntryPoint): (WTF::Thread::createInternal): (WTF::Thread::changePriority): (WTF::Thread::waitForCompletion): (WTF::Thread::detach): (WTF::Thread::resume): (WTF::Thread::getRegisters): (WTF::Thread::current): (WTF::Thread::currentID): (WTF::Thread::didExit): (WTF::Thread::establish): (WTF::initializeCurrentThreadInternal): Deleted. (WTF::threadMapMutex): Deleted. (WTF::initializeThreading): Deleted. (WTF::threadMap): Deleted. (WTF::storeThreadHandleByIdentifier): Deleted. (WTF::threadHandleForIdentifier): Deleted. (WTF::clearThreadHandleForIdentifier): Deleted. (WTF::createThreadInternal): Deleted. (WTF::changeThreadPriority): Deleted. (WTF::waitForThreadCompletion): Deleted. (WTF::detachThread): Deleted. (WTF::currentThread): Deleted. * wtf/WorkQueue.cpp: (WTF::WorkQueue::concurrentApply): * wtf/WorkQueue.h: * wtf/cocoa/WorkQueueCocoa.cpp: (WTF::dispatchQOSClass): * wtf/generic/WorkQueueGeneric.cpp: (WorkQueue::platformInitialize): (WorkQueue::platformInvalidate): * wtf/linux/MemoryPressureHandlerLinux.cpp: (WTF::MemoryPressureHandler::EventFDPoller::EventFDPoller): (WTF::MemoryPressureHandler::EventFDPoller::~EventFDPoller): * wtf/win/MainThreadWin.cpp: (WTF::initializeMainThreadPlatform): Tools: Mechanical change. Use Thread:: APIs. * DumpRenderTree/JavaScriptThreading.cpp: (runJavaScriptThread): (startJavaScriptThreads): (stopJavaScriptThreads): * DumpRenderTree/mac/DumpRenderTree.mm: (testThreadIdentifierMap): * TestWebKitAPI/Tests/WTF/Condition.cpp: * TestWebKitAPI/Tests/WTF/Lock.cpp: (TestWebKitAPI::runLockTest): * TestWebKitAPI/Tests/WTF/ParkingLot.cpp: Canonical link: https://commits.webkit.org/187690@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@215265 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-04-12 12:08:29 +00:00
#if CPU(X86)
typedef i386_thread_state_t PlatformRegisters;
#elif CPU(X86_64)
typedef x86_thread_state64_t PlatformRegisters;
#elif CPU(PPC)
typedef ppc_thread_state_t PlatformRegisters;
#elif CPU(PPC64)
typedef ppc_thread_state64_t PlatformRegisters;
#elif CPU(ARM)
typedef arm_thread_state_t PlatformRegisters;
#elif CPU(ARM64)
typedef arm_thread_state64_t PlatformRegisters;
#else
#error Unknown Architecture
#endif
Undo rollout in r217638 with bug fix https://bugs.webkit.org/show_bug.cgi?id=172824 Unreviewed, reland patch with unused set_state code removed. Source/JavaScriptCore: * API/tests/ExecutionTimeLimitTest.cpp: (dispatchTermitateCallback): (testExecutionTimeLimit): * runtime/JSLock.cpp: (JSC::JSLock::didAcquireLock): * runtime/Options.cpp: (JSC::overrideDefaults): (JSC::Options::initialize): * runtime/Options.h: * runtime/VMTraps.cpp: (JSC::SignalContext::SignalContext): (JSC::SignalContext::adjustPCToPointToTrappingInstruction): (JSC::installSignalHandler): (JSC::VMTraps::SignalSender::send): * tools/SigillCrashAnalyzer.cpp: (JSC::SignalContext::SignalContext): (JSC::SignalContext::dump): (JSC::installCrashHandler): * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::compileFunctions): * wasm/WasmFaultSignalHandler.cpp: (JSC::Wasm::trapHandler): (JSC::Wasm::enableFastMemory): * wasm/WasmMachineThreads.cpp: (JSC::Wasm::resetInstructionCacheOnAllThreads): Source/WTF: * Configurations/WTF.xcconfig: * WTF.xcodeproj/project.pbxproj: * wtf/Platform.h: * wtf/PlatformRegisters.h: (WTF::registersFromUContext): * wtf/StackBounds.h: (WTF::StackBounds::StackBounds): * wtf/ThreadHolder.cpp: (WTF::ThreadHolder::~ThreadHolder): * wtf/ThreadMessage.cpp: (WTF::sendMessageUsingSignal): (WTF::sendMessageUsingMach): (WTF::deliverMessagesUsingMach): (WTF::sendMessageScoped): * wtf/ThreadMessage.h: (WTF::sendMessage): * wtf/Threading.h: (WTF::Thread::machThread): * wtf/mac/MachExceptions.defs: Copied from Source/WTF/wtf/ThreadMessage.h. * wtf/threads/Signals.cpp: (WTF::startMachExceptionHandlerThread): (WTF::fromMachException): (WTF::toMachMask): (WTF::handleSignalsWithMach): (WTF::setExceptionPorts): (WTF::activeThreads): (WTF::registerThreadForMachExceptionHandling): (WTF::unregisterThreadForMachExceptionHandling): (WTF::installSignalHandler): (WTF::jscSignalHandler): * wtf/threads/Signals.h: Tools: * TestWebKitAPI/Tests/WTF/ThreadMessages.cpp: (runThreadMessageTest): (TEST): Canonical link: https://commits.webkit.org/189710@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@217669 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-06-01 18:28:48 +00:00
inline PlatformRegisters& registersFromUContext(ucontext_t* ucontext)
{
return ucontext->uc_mcontext->__ss;
}
[Re-landing] Change JSLock to stash PlatformThread instead of std::thread::id. https://bugs.webkit.org/show_bug.cgi?id=168996 Reviewed by Filip Pizlo and Saam Barati. PlatformThread is more useful because it allows us to: 1. find the MachineThreads::Thread which is associated with it. 2. suspend / resume threads. 3. send a signal to a thread. We can't do those with std::thread::id. We will need one or more of these capabilities to implement non-polling VM traps later. Update: Since we don't have a canonical "uninitialized" value for PlatformThread, we now have a JSLock::m_hasOwnerThread flag that is set to true if and only the m_ownerThread value is valid. JSLock::currentThreadIsHoldingLock() now checks JSLock::m_hasOwnerThread before doing the thread identity comparison. * JavaScriptCore.xcodeproj/project.pbxproj: * heap/MachineStackMarker.cpp: (JSC::MachineThreads::Thread::createForCurrentThread): (JSC::MachineThreads::machineThreadForCurrentThread): (JSC::MachineThreads::removeThread): (JSC::MachineThreads::Thread::suspend): (JSC::MachineThreads::tryCopyOtherThreadStacks): (JSC::getCurrentPlatformThread): Deleted. * heap/MachineStackMarker.h: * runtime/JSCellInlines.h: (JSC::JSCell::classInfo): * runtime/JSLock.cpp: (JSC::JSLock::JSLock): (JSC::JSLock::lock): (JSC::JSLock::unlock): (JSC::JSLock::currentThreadIsHoldingLock): Deleted. * runtime/JSLock.h: (JSC::JSLock::ownerThread): (JSC::JSLock::currentThreadIsHoldingLock): * runtime/PlatformThread.h: Added. (JSC::currentPlatformThread): * runtime/VM.cpp: (JSC::VM::~VM): * runtime/VM.h: (JSC::VM::ownerThread): * runtime/Watchdog.cpp: (JSC::Watchdog::setTimeLimit): (JSC::Watchdog::shouldTerminate): (JSC::Watchdog::startTimer): (JSC::Watchdog::stopTimer): * tools/JSDollarVMPrototype.cpp: (JSC::JSDollarVMPrototype::currentThreadOwnsJSLock): * tools/VMInspector.cpp: Canonical link: https://commits.webkit.org/186036@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@213238 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-03-01 20:15:08 +00:00
#elif OS(WINDOWS)
[WTF] Introduce Thread class and use RefPtr<Thread> and align Windows Threading implementation semantics to Pthread one https://bugs.webkit.org/show_bug.cgi?id=170502 Reviewed by Mark Lam. Source/JavaScriptCore: * API/tests/CompareAndSwapTest.cpp: (testCompareAndSwap): * JavaScriptCore.xcodeproj/project.pbxproj: * b3/air/testair.cpp: * b3/testb3.cpp: (JSC::B3::run): * bytecode/SuperSampler.cpp: (JSC::initializeSuperSampler): * dfg/DFGWorklist.cpp: * disassembler/Disassembler.cpp: * heap/Heap.cpp: (JSC::Heap::lastChanceToFinalize): (JSC::Heap::notifyIsSafeToCollect): * heap/Heap.h: * heap/MachineStackMarker.cpp: (JSC::MachineThreads::~MachineThreads): (JSC::MachineThreads::addCurrentThread): (JSC::MachineThreads::removeThread): (JSC::MachineThreads::removeThreadIfFound): (JSC::MachineThreads::MachineThread::MachineThread): (JSC::MachineThreads::MachineThread::getRegisters): (JSC::MachineThreads::MachineThread::Registers::stackPointer): (JSC::MachineThreads::MachineThread::Registers::framePointer): (JSC::MachineThreads::MachineThread::Registers::instructionPointer): (JSC::MachineThreads::MachineThread::Registers::llintPC): (JSC::MachineThreads::MachineThread::captureStack): (JSC::MachineThreads::tryCopyOtherThreadStack): (JSC::MachineThreads::tryCopyOtherThreadStacks): (pthreadSignalHandlerSuspendResume): Deleted. (JSC::threadData): Deleted. (JSC::MachineThreads::Thread::Thread): Deleted. (JSC::MachineThreads::Thread::createForCurrentThread): Deleted. (JSC::MachineThreads::Thread::operator==): Deleted. (JSC::MachineThreads::machineThreadForCurrentThread): Deleted. (JSC::MachineThreads::ThreadData::ThreadData): Deleted. (JSC::MachineThreads::ThreadData::~ThreadData): Deleted. (JSC::MachineThreads::ThreadData::suspend): Deleted. (JSC::MachineThreads::ThreadData::resume): Deleted. (JSC::MachineThreads::ThreadData::getRegisters): Deleted. (JSC::MachineThreads::ThreadData::Registers::stackPointer): Deleted. (JSC::MachineThreads::ThreadData::Registers::framePointer): Deleted. (JSC::MachineThreads::ThreadData::Registers::instructionPointer): Deleted. (JSC::MachineThreads::ThreadData::Registers::llintPC): Deleted. (JSC::MachineThreads::ThreadData::freeRegisters): Deleted. (JSC::MachineThreads::ThreadData::captureStack): Deleted. * heap/MachineStackMarker.h: (JSC::MachineThreads::MachineThread::suspend): (JSC::MachineThreads::MachineThread::resume): (JSC::MachineThreads::MachineThread::threadID): (JSC::MachineThreads::MachineThread::stackBase): (JSC::MachineThreads::MachineThread::stackEnd): (JSC::MachineThreads::threadsListHead): (JSC::MachineThreads::Thread::operator!=): Deleted. (JSC::MachineThreads::Thread::suspend): Deleted. (JSC::MachineThreads::Thread::resume): Deleted. (JSC::MachineThreads::Thread::getRegisters): Deleted. (JSC::MachineThreads::Thread::freeRegisters): Deleted. (JSC::MachineThreads::Thread::captureStack): Deleted. (JSC::MachineThreads::Thread::platformThread): Deleted. (JSC::MachineThreads::Thread::stackBase): Deleted. (JSC::MachineThreads::Thread::stackEnd): Deleted. * jit/ICStats.cpp: (JSC::ICStats::ICStats): (JSC::ICStats::~ICStats): * jit/ICStats.h: * jsc.cpp: (functionDollarAgentStart): (startTimeoutThreadIfNeeded): * runtime/JSLock.cpp: (JSC::JSLock::lock): * runtime/JSLock.h: (JSC::JSLock::ownerThread): (JSC::JSLock::currentThreadIsHoldingLock): * runtime/SamplingProfiler.cpp: (JSC::FrameWalker::isValidFramePointer): (JSC::SamplingProfiler::SamplingProfiler): (JSC::SamplingProfiler::createThreadIfNecessary): (JSC::SamplingProfiler::takeSample): * runtime/SamplingProfiler.h: * runtime/VM.h: (JSC::VM::ownerThread): * runtime/VMTraps.cpp: (JSC::findActiveVMAndStackBounds): (JSC::VMTraps::SignalSender::send): (JSC::VMTraps::fireTrap): Source/WebCore: Mechanical change. Use Thread:: APIs. * Modules/indexeddb/server/IDBServer.cpp: (WebCore::IDBServer::IDBServer::IDBServer): * Modules/indexeddb/server/IDBServer.h: * Modules/webaudio/AsyncAudioDecoder.cpp: (WebCore::AsyncAudioDecoder::AsyncAudioDecoder): (WebCore::AsyncAudioDecoder::~AsyncAudioDecoder): (WebCore::AsyncAudioDecoder::runLoop): * Modules/webaudio/AsyncAudioDecoder.h: * Modules/webaudio/OfflineAudioDestinationNode.cpp: (WebCore::OfflineAudioDestinationNode::OfflineAudioDestinationNode): (WebCore::OfflineAudioDestinationNode::uninitialize): (WebCore::OfflineAudioDestinationNode::startRendering): * Modules/webaudio/OfflineAudioDestinationNode.h: * Modules/webdatabase/Database.cpp: (WebCore::Database::securityOrigin): * Modules/webdatabase/DatabaseThread.cpp: (WebCore::DatabaseThread::start): (WebCore::DatabaseThread::databaseThread): (WebCore::DatabaseThread::recordDatabaseOpen): (WebCore::DatabaseThread::recordDatabaseClosed): * Modules/webdatabase/DatabaseThread.h: (WebCore::DatabaseThread::getThreadID): * bindings/js/GCController.cpp: (WebCore::GCController::garbageCollectOnAlternateThreadForDebugging): * fileapi/AsyncFileStream.cpp: (WebCore::callOnFileThread): * loader/icon/IconDatabase.cpp: (WebCore::IconDatabase::open): (WebCore::IconDatabase::close): * loader/icon/IconDatabase.h: * page/ResourceUsageThread.cpp: (WebCore::ResourceUsageThread::createThreadIfNeeded): * page/ResourceUsageThread.h: * page/scrolling/ScrollingThread.cpp: (WebCore::ScrollingThread::ScrollingThread): (WebCore::ScrollingThread::isCurrentThread): (WebCore::ScrollingThread::createThreadIfNeeded): (WebCore::ScrollingThread::threadCallback): * page/scrolling/ScrollingThread.h: * platform/audio/HRTFDatabaseLoader.cpp: (WebCore::HRTFDatabaseLoader::HRTFDatabaseLoader): (WebCore::HRTFDatabaseLoader::loadAsynchronously): (WebCore::HRTFDatabaseLoader::waitForLoaderThreadCompletion): * platform/audio/HRTFDatabaseLoader.h: * platform/audio/ReverbConvolver.cpp: (WebCore::ReverbConvolver::ReverbConvolver): (WebCore::ReverbConvolver::~ReverbConvolver): * platform/audio/ReverbConvolver.h: * platform/audio/gstreamer/AudioFileReaderGStreamer.cpp: (WebCore::createBusFromAudioFile): (WebCore::createBusFromInMemoryAudioFile): * platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp: (ResourceHandleStreamingClient::ResourceHandleStreamingClient): (ResourceHandleStreamingClient::~ResourceHandleStreamingClient): * platform/network/cf/LoaderRunLoopCF.cpp: (WebCore::loaderRunLoop): * platform/network/curl/CurlDownload.cpp: (WebCore::CurlDownloadManager::startThreadIfNeeded): (WebCore::CurlDownloadManager::stopThread): * platform/network/curl/CurlDownload.h: * platform/network/curl/SocketStreamHandleImpl.h: * platform/network/curl/SocketStreamHandleImplCurl.cpp: (WebCore::SocketStreamHandleImpl::startThread): (WebCore::SocketStreamHandleImpl::stopThread): * workers/WorkerThread.cpp: (WebCore::WorkerThread::WorkerThread): (WebCore::WorkerThread::start): (WebCore::WorkerThread::workerThread): * workers/WorkerThread.h: (WebCore::WorkerThread::threadID): Source/WebKit: Mechanical change. Use Thread:: APIs. * Storage/StorageThread.cpp: (WebCore::StorageThread::StorageThread): (WebCore::StorageThread::~StorageThread): (WebCore::StorageThread::start): (WebCore::StorageThread::dispatch): (WebCore::StorageThread::terminate): * Storage/StorageThread.h: Source/WebKit2: Mechanical change. Use Thread:: APIs. * NetworkProcess/NetworkProcess.cpp: (WebKit::NetworkProcess::initializeNetworkProcess): * NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp: (WebKit::NetworkCache::IOChannel::readSyncInThread): * Platform/IPC/Connection.cpp: (IPC::Connection::processIncomingMessage): * Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.h: (WebKit::XPCServiceInitializer): * UIProcess/linux/MemoryPressureMonitor.cpp: (WebKit::MemoryPressureMonitor::MemoryPressureMonitor): * WebProcess/WebProcess.cpp: (WebKit::WebProcess::initializeWebProcess): Source/WTF: This patch is refactoring of WTF Threading mechanism to merge JavaScriptCore's threading extension to WTF Threading. Previously, JavaScriptCore requires richer threading features (such as suspending and resuming threads), and they are implemented for PlatformThread in JavaScriptCore. But these features should be implemented in WTF Threading side instead of maintaining JSC's own threading features too. This patch removes these features from JSC and move it to WTF Threading. However, current WTF Threading has one problem: Windows version of WTF Threading has different semantics from Pthreads one. In Windows WTF Threading, we cannot perform any operation after the target thread is detached: WTF Threading stop tracking the state of the thread once the thread is detached. But this is not the same to Pthreads one. In Pthreads, pthread_detach just means that the resource of the thread will be destroyed automatically. While some operations like pthread_join will be rejected, some operations like pthread_kill will be accepted. The problem is that detached thread can be suspended and resumed in JSC. For example, in jsc.cpp, we start the worker thread and detach it immediately. In worker thread, we will create VM and thus concurrent GC will suspend and resume the detached thread. However, in Windows WTF Threading, we have no reference to the detached thread. Thus we cannot perform suspend and resume operations onto the detached thread. To solve the problem, we change Windows Threading mechanism drastically to align it to the Pthread semantics. In the new Threading, we have RefPtr<Thread> class. It holds a handle to a platform thread. We can perform threading operations with this class. For example, Thread::suspend is offered. And we use destructor of the thread local variable to release the resources held by RefPtr<Thread>. In Windows, Thread::detach does nothing because the resource will be destroyed automatically by RefPtr<Thread>. To do so, we introduce ThreadHolder for Windows. This is similar to the previous ThreadIdentifierData for Pthreads. It holds RefPtr<Thread> in the thread local storage (technically, it is Fiber Local Storage in Windows). Thread::current() will return this reference. The problematic situation is that the order of the deallocation of the thread local storage is not defined. So we should not touch thread local storage in the destructor of the thread local storage. To avoid such edge cases, we have currentThread() / Thread::currentID() APIs. They are safe to be called even in the destructor of the other thread local storage. And in Windows, in the FLS destructor, we will create the thread_local variable to defer the destruction of the ThreadHolder. We ensure that this destructor is called after the other FLS destructors are called in Windows 10. This patch is performance neutral. * WTF.xcodeproj/project.pbxproj: * benchmarks/ConditionSpeedTest.cpp: * benchmarks/LockFairnessTest.cpp: * benchmarks/LockSpeedTest.cpp: * wtf/AutomaticThread.cpp: (WTF::AutomaticThread::start): * wtf/CMakeLists.txt: * wtf/MainThread.h: * wtf/MemoryPressureHandler.h: * wtf/ParallelJobsGeneric.cpp: (WTF::ParallelEnvironment::ThreadPrivate::tryLockFor): (WTF::ParallelEnvironment::ThreadPrivate::workerThread): * wtf/ParallelJobsGeneric.h: (WTF::ParallelEnvironment::ThreadPrivate::ThreadPrivate): Deleted. * wtf/ParkingLot.cpp: (WTF::ParkingLot::forEachImpl): * wtf/ParkingLot.h: (WTF::ParkingLot::forEach): * wtf/PlatformRegisters.h: Renamed from Source/JavaScriptCore/runtime/PlatformThread.h. * wtf/RefPtr.h: (WTF::RefPtr::RefPtr): * wtf/ThreadFunctionInvocation.h: (WTF::ThreadFunctionInvocation::ThreadFunctionInvocation): * wtf/ThreadHolder.cpp: Added. (WTF::ThreadHolder::~ThreadHolder): (WTF::ThreadHolder::initialize): * wtf/ThreadHolder.h: Renamed from Source/WTF/wtf/ThreadIdentifierDataPthreads.h. (WTF::ThreadHolder::thread): (WTF::ThreadHolder::ThreadHolder): * wtf/ThreadHolderPthreads.cpp: Renamed from Source/WTF/wtf/ThreadIdentifierDataPthreads.cpp. (WTF::ThreadHolder::initializeOnce): (WTF::ThreadHolder::current): (WTF::ThreadHolder::destruct): * wtf/ThreadHolderWin.cpp: Added. (WTF::threadMapMutex): (WTF::threadMap): (WTF::ThreadHolder::initializeOnce): (WTF::ThreadHolder::current): (WTF::ThreadHolder::destruct): * wtf/ThreadSpecific.h: * wtf/Threading.cpp: (WTF::Thread::normalizeThreadName): (WTF::threadEntryPoint): (WTF::Thread::create): (WTF::Thread::setCurrentThreadIsUserInteractive): (WTF::Thread::setCurrentThreadIsUserInitiated): (WTF::Thread::setGlobalMaxQOSClass): (WTF::Thread::adjustedQOSClass): (WTF::Thread::dump): (WTF::initializeThreading): (WTF::normalizeThreadName): Deleted. (WTF::createThread): Deleted. (WTF::setCurrentThreadIsUserInteractive): Deleted. (WTF::setCurrentThreadIsUserInitiated): Deleted. (WTF::setGlobalMaxQOSClass): Deleted. (WTF::adjustedQOSClass): Deleted. * wtf/Threading.h: (WTF::Thread::id): (WTF::Thread::operator==): (WTF::Thread::operator!=): (WTF::Thread::joinableState): (WTF::Thread::didBecomeDetached): (WTF::Thread::didJoin): (WTF::Thread::hasExited): (WTF::currentThread): * wtf/ThreadingPthreads.cpp: (WTF::Thread::Thread): (WTF::Thread::~Thread): (WTF::Thread::signalHandlerSuspendResume): (WTF::Thread::initializePlatformThreading): (WTF::initializeCurrentThreadEvenIfNonWTFCreated): (WTF::wtfThreadEntryPoint): (WTF::Thread::createInternal): (WTF::Thread::initializeCurrentThreadInternal): (WTF::Thread::changePriority): (WTF::Thread::waitForCompletion): (WTF::Thread::detach): (WTF::Thread::current): (WTF::Thread::currentID): (WTF::Thread::signal): (WTF::Thread::resume): (WTF::Thread::getRegisters): (WTF::Thread::didExit): (WTF::Thread::establish): (WTF::PthreadState::PthreadState): Deleted. (WTF::PthreadState::joinableState): Deleted. (WTF::PthreadState::pthreadHandle): Deleted. (WTF::PthreadState::didBecomeDetached): Deleted. (WTF::PthreadState::didExit): Deleted. (WTF::PthreadState::didJoin): Deleted. (WTF::PthreadState::hasExited): Deleted. (WTF::threadMapMutex): Deleted. (WTF::initializeThreading): Deleted. (WTF::threadMap): Deleted. (WTF::identifierByPthreadHandle): Deleted. (WTF::establishIdentifierForPthreadHandle): Deleted. (WTF::pthreadHandleForIdentifierWithLockAlreadyHeld): Deleted. (WTF::createThreadInternal): Deleted. (WTF::initializeCurrentThreadInternal): Deleted. (WTF::changeThreadPriority): Deleted. (WTF::waitForThreadCompletion): Deleted. (WTF::detachThread): Deleted. (WTF::threadDidExit): Deleted. (WTF::currentThread): Deleted. (WTF::signalThread): Deleted. * wtf/ThreadingWin.cpp: (WTF::Thread::Thread): (WTF::Thread::~Thread): (WTF::Thread::initializeCurrentThreadInternal): (WTF::Thread::initializePlatformThreading): (WTF::wtfThreadEntryPoint): (WTF::Thread::createInternal): (WTF::Thread::changePriority): (WTF::Thread::waitForCompletion): (WTF::Thread::detach): (WTF::Thread::resume): (WTF::Thread::getRegisters): (WTF::Thread::current): (WTF::Thread::currentID): (WTF::Thread::didExit): (WTF::Thread::establish): (WTF::initializeCurrentThreadInternal): Deleted. (WTF::threadMapMutex): Deleted. (WTF::initializeThreading): Deleted. (WTF::threadMap): Deleted. (WTF::storeThreadHandleByIdentifier): Deleted. (WTF::threadHandleForIdentifier): Deleted. (WTF::clearThreadHandleForIdentifier): Deleted. (WTF::createThreadInternal): Deleted. (WTF::changeThreadPriority): Deleted. (WTF::waitForThreadCompletion): Deleted. (WTF::detachThread): Deleted. (WTF::currentThread): Deleted. * wtf/WorkQueue.cpp: (WTF::WorkQueue::concurrentApply): * wtf/WorkQueue.h: * wtf/cocoa/WorkQueueCocoa.cpp: (WTF::dispatchQOSClass): * wtf/generic/WorkQueueGeneric.cpp: (WorkQueue::platformInitialize): (WorkQueue::platformInvalidate): * wtf/linux/MemoryPressureHandlerLinux.cpp: (WTF::MemoryPressureHandler::EventFDPoller::EventFDPoller): (WTF::MemoryPressureHandler::EventFDPoller::~EventFDPoller): * wtf/win/MainThreadWin.cpp: (WTF::initializeMainThreadPlatform): Tools: Mechanical change. Use Thread:: APIs. * DumpRenderTree/JavaScriptThreading.cpp: (runJavaScriptThread): (startJavaScriptThreads): (stopJavaScriptThreads): * DumpRenderTree/mac/DumpRenderTree.mm: (testThreadIdentifierMap): * TestWebKitAPI/Tests/WTF/Condition.cpp: * TestWebKitAPI/Tests/WTF/Lock.cpp: (TestWebKitAPI::runLockTest): * TestWebKitAPI/Tests/WTF/ParkingLot.cpp: Canonical link: https://commits.webkit.org/187690@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@215265 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-04-12 12:08:29 +00:00
using PlatformRegisters = CONTEXT;
#elif HAVE(MACHINE_CONTEXT)
[WTF] Introduce Thread class and use RefPtr<Thread> and align Windows Threading implementation semantics to Pthread one https://bugs.webkit.org/show_bug.cgi?id=170502 Reviewed by Mark Lam. Source/JavaScriptCore: * API/tests/CompareAndSwapTest.cpp: (testCompareAndSwap): * JavaScriptCore.xcodeproj/project.pbxproj: * b3/air/testair.cpp: * b3/testb3.cpp: (JSC::B3::run): * bytecode/SuperSampler.cpp: (JSC::initializeSuperSampler): * dfg/DFGWorklist.cpp: * disassembler/Disassembler.cpp: * heap/Heap.cpp: (JSC::Heap::lastChanceToFinalize): (JSC::Heap::notifyIsSafeToCollect): * heap/Heap.h: * heap/MachineStackMarker.cpp: (JSC::MachineThreads::~MachineThreads): (JSC::MachineThreads::addCurrentThread): (JSC::MachineThreads::removeThread): (JSC::MachineThreads::removeThreadIfFound): (JSC::MachineThreads::MachineThread::MachineThread): (JSC::MachineThreads::MachineThread::getRegisters): (JSC::MachineThreads::MachineThread::Registers::stackPointer): (JSC::MachineThreads::MachineThread::Registers::framePointer): (JSC::MachineThreads::MachineThread::Registers::instructionPointer): (JSC::MachineThreads::MachineThread::Registers::llintPC): (JSC::MachineThreads::MachineThread::captureStack): (JSC::MachineThreads::tryCopyOtherThreadStack): (JSC::MachineThreads::tryCopyOtherThreadStacks): (pthreadSignalHandlerSuspendResume): Deleted. (JSC::threadData): Deleted. (JSC::MachineThreads::Thread::Thread): Deleted. (JSC::MachineThreads::Thread::createForCurrentThread): Deleted. (JSC::MachineThreads::Thread::operator==): Deleted. (JSC::MachineThreads::machineThreadForCurrentThread): Deleted. (JSC::MachineThreads::ThreadData::ThreadData): Deleted. (JSC::MachineThreads::ThreadData::~ThreadData): Deleted. (JSC::MachineThreads::ThreadData::suspend): Deleted. (JSC::MachineThreads::ThreadData::resume): Deleted. (JSC::MachineThreads::ThreadData::getRegisters): Deleted. (JSC::MachineThreads::ThreadData::Registers::stackPointer): Deleted. (JSC::MachineThreads::ThreadData::Registers::framePointer): Deleted. (JSC::MachineThreads::ThreadData::Registers::instructionPointer): Deleted. (JSC::MachineThreads::ThreadData::Registers::llintPC): Deleted. (JSC::MachineThreads::ThreadData::freeRegisters): Deleted. (JSC::MachineThreads::ThreadData::captureStack): Deleted. * heap/MachineStackMarker.h: (JSC::MachineThreads::MachineThread::suspend): (JSC::MachineThreads::MachineThread::resume): (JSC::MachineThreads::MachineThread::threadID): (JSC::MachineThreads::MachineThread::stackBase): (JSC::MachineThreads::MachineThread::stackEnd): (JSC::MachineThreads::threadsListHead): (JSC::MachineThreads::Thread::operator!=): Deleted. (JSC::MachineThreads::Thread::suspend): Deleted. (JSC::MachineThreads::Thread::resume): Deleted. (JSC::MachineThreads::Thread::getRegisters): Deleted. (JSC::MachineThreads::Thread::freeRegisters): Deleted. (JSC::MachineThreads::Thread::captureStack): Deleted. (JSC::MachineThreads::Thread::platformThread): Deleted. (JSC::MachineThreads::Thread::stackBase): Deleted. (JSC::MachineThreads::Thread::stackEnd): Deleted. * jit/ICStats.cpp: (JSC::ICStats::ICStats): (JSC::ICStats::~ICStats): * jit/ICStats.h: * jsc.cpp: (functionDollarAgentStart): (startTimeoutThreadIfNeeded): * runtime/JSLock.cpp: (JSC::JSLock::lock): * runtime/JSLock.h: (JSC::JSLock::ownerThread): (JSC::JSLock::currentThreadIsHoldingLock): * runtime/SamplingProfiler.cpp: (JSC::FrameWalker::isValidFramePointer): (JSC::SamplingProfiler::SamplingProfiler): (JSC::SamplingProfiler::createThreadIfNecessary): (JSC::SamplingProfiler::takeSample): * runtime/SamplingProfiler.h: * runtime/VM.h: (JSC::VM::ownerThread): * runtime/VMTraps.cpp: (JSC::findActiveVMAndStackBounds): (JSC::VMTraps::SignalSender::send): (JSC::VMTraps::fireTrap): Source/WebCore: Mechanical change. Use Thread:: APIs. * Modules/indexeddb/server/IDBServer.cpp: (WebCore::IDBServer::IDBServer::IDBServer): * Modules/indexeddb/server/IDBServer.h: * Modules/webaudio/AsyncAudioDecoder.cpp: (WebCore::AsyncAudioDecoder::AsyncAudioDecoder): (WebCore::AsyncAudioDecoder::~AsyncAudioDecoder): (WebCore::AsyncAudioDecoder::runLoop): * Modules/webaudio/AsyncAudioDecoder.h: * Modules/webaudio/OfflineAudioDestinationNode.cpp: (WebCore::OfflineAudioDestinationNode::OfflineAudioDestinationNode): (WebCore::OfflineAudioDestinationNode::uninitialize): (WebCore::OfflineAudioDestinationNode::startRendering): * Modules/webaudio/OfflineAudioDestinationNode.h: * Modules/webdatabase/Database.cpp: (WebCore::Database::securityOrigin): * Modules/webdatabase/DatabaseThread.cpp: (WebCore::DatabaseThread::start): (WebCore::DatabaseThread::databaseThread): (WebCore::DatabaseThread::recordDatabaseOpen): (WebCore::DatabaseThread::recordDatabaseClosed): * Modules/webdatabase/DatabaseThread.h: (WebCore::DatabaseThread::getThreadID): * bindings/js/GCController.cpp: (WebCore::GCController::garbageCollectOnAlternateThreadForDebugging): * fileapi/AsyncFileStream.cpp: (WebCore::callOnFileThread): * loader/icon/IconDatabase.cpp: (WebCore::IconDatabase::open): (WebCore::IconDatabase::close): * loader/icon/IconDatabase.h: * page/ResourceUsageThread.cpp: (WebCore::ResourceUsageThread::createThreadIfNeeded): * page/ResourceUsageThread.h: * page/scrolling/ScrollingThread.cpp: (WebCore::ScrollingThread::ScrollingThread): (WebCore::ScrollingThread::isCurrentThread): (WebCore::ScrollingThread::createThreadIfNeeded): (WebCore::ScrollingThread::threadCallback): * page/scrolling/ScrollingThread.h: * platform/audio/HRTFDatabaseLoader.cpp: (WebCore::HRTFDatabaseLoader::HRTFDatabaseLoader): (WebCore::HRTFDatabaseLoader::loadAsynchronously): (WebCore::HRTFDatabaseLoader::waitForLoaderThreadCompletion): * platform/audio/HRTFDatabaseLoader.h: * platform/audio/ReverbConvolver.cpp: (WebCore::ReverbConvolver::ReverbConvolver): (WebCore::ReverbConvolver::~ReverbConvolver): * platform/audio/ReverbConvolver.h: * platform/audio/gstreamer/AudioFileReaderGStreamer.cpp: (WebCore::createBusFromAudioFile): (WebCore::createBusFromInMemoryAudioFile): * platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp: (ResourceHandleStreamingClient::ResourceHandleStreamingClient): (ResourceHandleStreamingClient::~ResourceHandleStreamingClient): * platform/network/cf/LoaderRunLoopCF.cpp: (WebCore::loaderRunLoop): * platform/network/curl/CurlDownload.cpp: (WebCore::CurlDownloadManager::startThreadIfNeeded): (WebCore::CurlDownloadManager::stopThread): * platform/network/curl/CurlDownload.h: * platform/network/curl/SocketStreamHandleImpl.h: * platform/network/curl/SocketStreamHandleImplCurl.cpp: (WebCore::SocketStreamHandleImpl::startThread): (WebCore::SocketStreamHandleImpl::stopThread): * workers/WorkerThread.cpp: (WebCore::WorkerThread::WorkerThread): (WebCore::WorkerThread::start): (WebCore::WorkerThread::workerThread): * workers/WorkerThread.h: (WebCore::WorkerThread::threadID): Source/WebKit: Mechanical change. Use Thread:: APIs. * Storage/StorageThread.cpp: (WebCore::StorageThread::StorageThread): (WebCore::StorageThread::~StorageThread): (WebCore::StorageThread::start): (WebCore::StorageThread::dispatch): (WebCore::StorageThread::terminate): * Storage/StorageThread.h: Source/WebKit2: Mechanical change. Use Thread:: APIs. * NetworkProcess/NetworkProcess.cpp: (WebKit::NetworkProcess::initializeNetworkProcess): * NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp: (WebKit::NetworkCache::IOChannel::readSyncInThread): * Platform/IPC/Connection.cpp: (IPC::Connection::processIncomingMessage): * Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.h: (WebKit::XPCServiceInitializer): * UIProcess/linux/MemoryPressureMonitor.cpp: (WebKit::MemoryPressureMonitor::MemoryPressureMonitor): * WebProcess/WebProcess.cpp: (WebKit::WebProcess::initializeWebProcess): Source/WTF: This patch is refactoring of WTF Threading mechanism to merge JavaScriptCore's threading extension to WTF Threading. Previously, JavaScriptCore requires richer threading features (such as suspending and resuming threads), and they are implemented for PlatformThread in JavaScriptCore. But these features should be implemented in WTF Threading side instead of maintaining JSC's own threading features too. This patch removes these features from JSC and move it to WTF Threading. However, current WTF Threading has one problem: Windows version of WTF Threading has different semantics from Pthreads one. In Windows WTF Threading, we cannot perform any operation after the target thread is detached: WTF Threading stop tracking the state of the thread once the thread is detached. But this is not the same to Pthreads one. In Pthreads, pthread_detach just means that the resource of the thread will be destroyed automatically. While some operations like pthread_join will be rejected, some operations like pthread_kill will be accepted. The problem is that detached thread can be suspended and resumed in JSC. For example, in jsc.cpp, we start the worker thread and detach it immediately. In worker thread, we will create VM and thus concurrent GC will suspend and resume the detached thread. However, in Windows WTF Threading, we have no reference to the detached thread. Thus we cannot perform suspend and resume operations onto the detached thread. To solve the problem, we change Windows Threading mechanism drastically to align it to the Pthread semantics. In the new Threading, we have RefPtr<Thread> class. It holds a handle to a platform thread. We can perform threading operations with this class. For example, Thread::suspend is offered. And we use destructor of the thread local variable to release the resources held by RefPtr<Thread>. In Windows, Thread::detach does nothing because the resource will be destroyed automatically by RefPtr<Thread>. To do so, we introduce ThreadHolder for Windows. This is similar to the previous ThreadIdentifierData for Pthreads. It holds RefPtr<Thread> in the thread local storage (technically, it is Fiber Local Storage in Windows). Thread::current() will return this reference. The problematic situation is that the order of the deallocation of the thread local storage is not defined. So we should not touch thread local storage in the destructor of the thread local storage. To avoid such edge cases, we have currentThread() / Thread::currentID() APIs. They are safe to be called even in the destructor of the other thread local storage. And in Windows, in the FLS destructor, we will create the thread_local variable to defer the destruction of the ThreadHolder. We ensure that this destructor is called after the other FLS destructors are called in Windows 10. This patch is performance neutral. * WTF.xcodeproj/project.pbxproj: * benchmarks/ConditionSpeedTest.cpp: * benchmarks/LockFairnessTest.cpp: * benchmarks/LockSpeedTest.cpp: * wtf/AutomaticThread.cpp: (WTF::AutomaticThread::start): * wtf/CMakeLists.txt: * wtf/MainThread.h: * wtf/MemoryPressureHandler.h: * wtf/ParallelJobsGeneric.cpp: (WTF::ParallelEnvironment::ThreadPrivate::tryLockFor): (WTF::ParallelEnvironment::ThreadPrivate::workerThread): * wtf/ParallelJobsGeneric.h: (WTF::ParallelEnvironment::ThreadPrivate::ThreadPrivate): Deleted. * wtf/ParkingLot.cpp: (WTF::ParkingLot::forEachImpl): * wtf/ParkingLot.h: (WTF::ParkingLot::forEach): * wtf/PlatformRegisters.h: Renamed from Source/JavaScriptCore/runtime/PlatformThread.h. * wtf/RefPtr.h: (WTF::RefPtr::RefPtr): * wtf/ThreadFunctionInvocation.h: (WTF::ThreadFunctionInvocation::ThreadFunctionInvocation): * wtf/ThreadHolder.cpp: Added. (WTF::ThreadHolder::~ThreadHolder): (WTF::ThreadHolder::initialize): * wtf/ThreadHolder.h: Renamed from Source/WTF/wtf/ThreadIdentifierDataPthreads.h. (WTF::ThreadHolder::thread): (WTF::ThreadHolder::ThreadHolder): * wtf/ThreadHolderPthreads.cpp: Renamed from Source/WTF/wtf/ThreadIdentifierDataPthreads.cpp. (WTF::ThreadHolder::initializeOnce): (WTF::ThreadHolder::current): (WTF::ThreadHolder::destruct): * wtf/ThreadHolderWin.cpp: Added. (WTF::threadMapMutex): (WTF::threadMap): (WTF::ThreadHolder::initializeOnce): (WTF::ThreadHolder::current): (WTF::ThreadHolder::destruct): * wtf/ThreadSpecific.h: * wtf/Threading.cpp: (WTF::Thread::normalizeThreadName): (WTF::threadEntryPoint): (WTF::Thread::create): (WTF::Thread::setCurrentThreadIsUserInteractive): (WTF::Thread::setCurrentThreadIsUserInitiated): (WTF::Thread::setGlobalMaxQOSClass): (WTF::Thread::adjustedQOSClass): (WTF::Thread::dump): (WTF::initializeThreading): (WTF::normalizeThreadName): Deleted. (WTF::createThread): Deleted. (WTF::setCurrentThreadIsUserInteractive): Deleted. (WTF::setCurrentThreadIsUserInitiated): Deleted. (WTF::setGlobalMaxQOSClass): Deleted. (WTF::adjustedQOSClass): Deleted. * wtf/Threading.h: (WTF::Thread::id): (WTF::Thread::operator==): (WTF::Thread::operator!=): (WTF::Thread::joinableState): (WTF::Thread::didBecomeDetached): (WTF::Thread::didJoin): (WTF::Thread::hasExited): (WTF::currentThread): * wtf/ThreadingPthreads.cpp: (WTF::Thread::Thread): (WTF::Thread::~Thread): (WTF::Thread::signalHandlerSuspendResume): (WTF::Thread::initializePlatformThreading): (WTF::initializeCurrentThreadEvenIfNonWTFCreated): (WTF::wtfThreadEntryPoint): (WTF::Thread::createInternal): (WTF::Thread::initializeCurrentThreadInternal): (WTF::Thread::changePriority): (WTF::Thread::waitForCompletion): (WTF::Thread::detach): (WTF::Thread::current): (WTF::Thread::currentID): (WTF::Thread::signal): (WTF::Thread::resume): (WTF::Thread::getRegisters): (WTF::Thread::didExit): (WTF::Thread::establish): (WTF::PthreadState::PthreadState): Deleted. (WTF::PthreadState::joinableState): Deleted. (WTF::PthreadState::pthreadHandle): Deleted. (WTF::PthreadState::didBecomeDetached): Deleted. (WTF::PthreadState::didExit): Deleted. (WTF::PthreadState::didJoin): Deleted. (WTF::PthreadState::hasExited): Deleted. (WTF::threadMapMutex): Deleted. (WTF::initializeThreading): Deleted. (WTF::threadMap): Deleted. (WTF::identifierByPthreadHandle): Deleted. (WTF::establishIdentifierForPthreadHandle): Deleted. (WTF::pthreadHandleForIdentifierWithLockAlreadyHeld): Deleted. (WTF::createThreadInternal): Deleted. (WTF::initializeCurrentThreadInternal): Deleted. (WTF::changeThreadPriority): Deleted. (WTF::waitForThreadCompletion): Deleted. (WTF::detachThread): Deleted. (WTF::threadDidExit): Deleted. (WTF::currentThread): Deleted. (WTF::signalThread): Deleted. * wtf/ThreadingWin.cpp: (WTF::Thread::Thread): (WTF::Thread::~Thread): (WTF::Thread::initializeCurrentThreadInternal): (WTF::Thread::initializePlatformThreading): (WTF::wtfThreadEntryPoint): (WTF::Thread::createInternal): (WTF::Thread::changePriority): (WTF::Thread::waitForCompletion): (WTF::Thread::detach): (WTF::Thread::resume): (WTF::Thread::getRegisters): (WTF::Thread::current): (WTF::Thread::currentID): (WTF::Thread::didExit): (WTF::Thread::establish): (WTF::initializeCurrentThreadInternal): Deleted. (WTF::threadMapMutex): Deleted. (WTF::initializeThreading): Deleted. (WTF::threadMap): Deleted. (WTF::storeThreadHandleByIdentifier): Deleted. (WTF::threadHandleForIdentifier): Deleted. (WTF::clearThreadHandleForIdentifier): Deleted. (WTF::createThreadInternal): Deleted. (WTF::changeThreadPriority): Deleted. (WTF::waitForThreadCompletion): Deleted. (WTF::detachThread): Deleted. (WTF::currentThread): Deleted. * wtf/WorkQueue.cpp: (WTF::WorkQueue::concurrentApply): * wtf/WorkQueue.h: * wtf/cocoa/WorkQueueCocoa.cpp: (WTF::dispatchQOSClass): * wtf/generic/WorkQueueGeneric.cpp: (WorkQueue::platformInitialize): (WorkQueue::platformInvalidate): * wtf/linux/MemoryPressureHandlerLinux.cpp: (WTF::MemoryPressureHandler::EventFDPoller::EventFDPoller): (WTF::MemoryPressureHandler::EventFDPoller::~EventFDPoller): * wtf/win/MainThreadWin.cpp: (WTF::initializeMainThreadPlatform): Tools: Mechanical change. Use Thread:: APIs. * DumpRenderTree/JavaScriptThreading.cpp: (runJavaScriptThread): (startJavaScriptThreads): (stopJavaScriptThreads): * DumpRenderTree/mac/DumpRenderTree.mm: (testThreadIdentifierMap): * TestWebKitAPI/Tests/WTF/Condition.cpp: * TestWebKitAPI/Tests/WTF/Lock.cpp: (TestWebKitAPI::runLockTest): * TestWebKitAPI/Tests/WTF/ParkingLot.cpp: Canonical link: https://commits.webkit.org/187690@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@215265 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-04-12 12:08:29 +00:00
struct PlatformRegisters {
mcontext_t machineContext;
};
[WTF] Introduce Thread class and use RefPtr<Thread> and align Windows Threading implementation semantics to Pthread one https://bugs.webkit.org/show_bug.cgi?id=170502 Reviewed by Mark Lam. Source/JavaScriptCore: * API/tests/CompareAndSwapTest.cpp: (testCompareAndSwap): * JavaScriptCore.xcodeproj/project.pbxproj: * b3/air/testair.cpp: * b3/testb3.cpp: (JSC::B3::run): * bytecode/SuperSampler.cpp: (JSC::initializeSuperSampler): * dfg/DFGWorklist.cpp: * disassembler/Disassembler.cpp: * heap/Heap.cpp: (JSC::Heap::lastChanceToFinalize): (JSC::Heap::notifyIsSafeToCollect): * heap/Heap.h: * heap/MachineStackMarker.cpp: (JSC::MachineThreads::~MachineThreads): (JSC::MachineThreads::addCurrentThread): (JSC::MachineThreads::removeThread): (JSC::MachineThreads::removeThreadIfFound): (JSC::MachineThreads::MachineThread::MachineThread): (JSC::MachineThreads::MachineThread::getRegisters): (JSC::MachineThreads::MachineThread::Registers::stackPointer): (JSC::MachineThreads::MachineThread::Registers::framePointer): (JSC::MachineThreads::MachineThread::Registers::instructionPointer): (JSC::MachineThreads::MachineThread::Registers::llintPC): (JSC::MachineThreads::MachineThread::captureStack): (JSC::MachineThreads::tryCopyOtherThreadStack): (JSC::MachineThreads::tryCopyOtherThreadStacks): (pthreadSignalHandlerSuspendResume): Deleted. (JSC::threadData): Deleted. (JSC::MachineThreads::Thread::Thread): Deleted. (JSC::MachineThreads::Thread::createForCurrentThread): Deleted. (JSC::MachineThreads::Thread::operator==): Deleted. (JSC::MachineThreads::machineThreadForCurrentThread): Deleted. (JSC::MachineThreads::ThreadData::ThreadData): Deleted. (JSC::MachineThreads::ThreadData::~ThreadData): Deleted. (JSC::MachineThreads::ThreadData::suspend): Deleted. (JSC::MachineThreads::ThreadData::resume): Deleted. (JSC::MachineThreads::ThreadData::getRegisters): Deleted. (JSC::MachineThreads::ThreadData::Registers::stackPointer): Deleted. (JSC::MachineThreads::ThreadData::Registers::framePointer): Deleted. (JSC::MachineThreads::ThreadData::Registers::instructionPointer): Deleted. (JSC::MachineThreads::ThreadData::Registers::llintPC): Deleted. (JSC::MachineThreads::ThreadData::freeRegisters): Deleted. (JSC::MachineThreads::ThreadData::captureStack): Deleted. * heap/MachineStackMarker.h: (JSC::MachineThreads::MachineThread::suspend): (JSC::MachineThreads::MachineThread::resume): (JSC::MachineThreads::MachineThread::threadID): (JSC::MachineThreads::MachineThread::stackBase): (JSC::MachineThreads::MachineThread::stackEnd): (JSC::MachineThreads::threadsListHead): (JSC::MachineThreads::Thread::operator!=): Deleted. (JSC::MachineThreads::Thread::suspend): Deleted. (JSC::MachineThreads::Thread::resume): Deleted. (JSC::MachineThreads::Thread::getRegisters): Deleted. (JSC::MachineThreads::Thread::freeRegisters): Deleted. (JSC::MachineThreads::Thread::captureStack): Deleted. (JSC::MachineThreads::Thread::platformThread): Deleted. (JSC::MachineThreads::Thread::stackBase): Deleted. (JSC::MachineThreads::Thread::stackEnd): Deleted. * jit/ICStats.cpp: (JSC::ICStats::ICStats): (JSC::ICStats::~ICStats): * jit/ICStats.h: * jsc.cpp: (functionDollarAgentStart): (startTimeoutThreadIfNeeded): * runtime/JSLock.cpp: (JSC::JSLock::lock): * runtime/JSLock.h: (JSC::JSLock::ownerThread): (JSC::JSLock::currentThreadIsHoldingLock): * runtime/SamplingProfiler.cpp: (JSC::FrameWalker::isValidFramePointer): (JSC::SamplingProfiler::SamplingProfiler): (JSC::SamplingProfiler::createThreadIfNecessary): (JSC::SamplingProfiler::takeSample): * runtime/SamplingProfiler.h: * runtime/VM.h: (JSC::VM::ownerThread): * runtime/VMTraps.cpp: (JSC::findActiveVMAndStackBounds): (JSC::VMTraps::SignalSender::send): (JSC::VMTraps::fireTrap): Source/WebCore: Mechanical change. Use Thread:: APIs. * Modules/indexeddb/server/IDBServer.cpp: (WebCore::IDBServer::IDBServer::IDBServer): * Modules/indexeddb/server/IDBServer.h: * Modules/webaudio/AsyncAudioDecoder.cpp: (WebCore::AsyncAudioDecoder::AsyncAudioDecoder): (WebCore::AsyncAudioDecoder::~AsyncAudioDecoder): (WebCore::AsyncAudioDecoder::runLoop): * Modules/webaudio/AsyncAudioDecoder.h: * Modules/webaudio/OfflineAudioDestinationNode.cpp: (WebCore::OfflineAudioDestinationNode::OfflineAudioDestinationNode): (WebCore::OfflineAudioDestinationNode::uninitialize): (WebCore::OfflineAudioDestinationNode::startRendering): * Modules/webaudio/OfflineAudioDestinationNode.h: * Modules/webdatabase/Database.cpp: (WebCore::Database::securityOrigin): * Modules/webdatabase/DatabaseThread.cpp: (WebCore::DatabaseThread::start): (WebCore::DatabaseThread::databaseThread): (WebCore::DatabaseThread::recordDatabaseOpen): (WebCore::DatabaseThread::recordDatabaseClosed): * Modules/webdatabase/DatabaseThread.h: (WebCore::DatabaseThread::getThreadID): * bindings/js/GCController.cpp: (WebCore::GCController::garbageCollectOnAlternateThreadForDebugging): * fileapi/AsyncFileStream.cpp: (WebCore::callOnFileThread): * loader/icon/IconDatabase.cpp: (WebCore::IconDatabase::open): (WebCore::IconDatabase::close): * loader/icon/IconDatabase.h: * page/ResourceUsageThread.cpp: (WebCore::ResourceUsageThread::createThreadIfNeeded): * page/ResourceUsageThread.h: * page/scrolling/ScrollingThread.cpp: (WebCore::ScrollingThread::ScrollingThread): (WebCore::ScrollingThread::isCurrentThread): (WebCore::ScrollingThread::createThreadIfNeeded): (WebCore::ScrollingThread::threadCallback): * page/scrolling/ScrollingThread.h: * platform/audio/HRTFDatabaseLoader.cpp: (WebCore::HRTFDatabaseLoader::HRTFDatabaseLoader): (WebCore::HRTFDatabaseLoader::loadAsynchronously): (WebCore::HRTFDatabaseLoader::waitForLoaderThreadCompletion): * platform/audio/HRTFDatabaseLoader.h: * platform/audio/ReverbConvolver.cpp: (WebCore::ReverbConvolver::ReverbConvolver): (WebCore::ReverbConvolver::~ReverbConvolver): * platform/audio/ReverbConvolver.h: * platform/audio/gstreamer/AudioFileReaderGStreamer.cpp: (WebCore::createBusFromAudioFile): (WebCore::createBusFromInMemoryAudioFile): * platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp: (ResourceHandleStreamingClient::ResourceHandleStreamingClient): (ResourceHandleStreamingClient::~ResourceHandleStreamingClient): * platform/network/cf/LoaderRunLoopCF.cpp: (WebCore::loaderRunLoop): * platform/network/curl/CurlDownload.cpp: (WebCore::CurlDownloadManager::startThreadIfNeeded): (WebCore::CurlDownloadManager::stopThread): * platform/network/curl/CurlDownload.h: * platform/network/curl/SocketStreamHandleImpl.h: * platform/network/curl/SocketStreamHandleImplCurl.cpp: (WebCore::SocketStreamHandleImpl::startThread): (WebCore::SocketStreamHandleImpl::stopThread): * workers/WorkerThread.cpp: (WebCore::WorkerThread::WorkerThread): (WebCore::WorkerThread::start): (WebCore::WorkerThread::workerThread): * workers/WorkerThread.h: (WebCore::WorkerThread::threadID): Source/WebKit: Mechanical change. Use Thread:: APIs. * Storage/StorageThread.cpp: (WebCore::StorageThread::StorageThread): (WebCore::StorageThread::~StorageThread): (WebCore::StorageThread::start): (WebCore::StorageThread::dispatch): (WebCore::StorageThread::terminate): * Storage/StorageThread.h: Source/WebKit2: Mechanical change. Use Thread:: APIs. * NetworkProcess/NetworkProcess.cpp: (WebKit::NetworkProcess::initializeNetworkProcess): * NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp: (WebKit::NetworkCache::IOChannel::readSyncInThread): * Platform/IPC/Connection.cpp: (IPC::Connection::processIncomingMessage): * Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.h: (WebKit::XPCServiceInitializer): * UIProcess/linux/MemoryPressureMonitor.cpp: (WebKit::MemoryPressureMonitor::MemoryPressureMonitor): * WebProcess/WebProcess.cpp: (WebKit::WebProcess::initializeWebProcess): Source/WTF: This patch is refactoring of WTF Threading mechanism to merge JavaScriptCore's threading extension to WTF Threading. Previously, JavaScriptCore requires richer threading features (such as suspending and resuming threads), and they are implemented for PlatformThread in JavaScriptCore. But these features should be implemented in WTF Threading side instead of maintaining JSC's own threading features too. This patch removes these features from JSC and move it to WTF Threading. However, current WTF Threading has one problem: Windows version of WTF Threading has different semantics from Pthreads one. In Windows WTF Threading, we cannot perform any operation after the target thread is detached: WTF Threading stop tracking the state of the thread once the thread is detached. But this is not the same to Pthreads one. In Pthreads, pthread_detach just means that the resource of the thread will be destroyed automatically. While some operations like pthread_join will be rejected, some operations like pthread_kill will be accepted. The problem is that detached thread can be suspended and resumed in JSC. For example, in jsc.cpp, we start the worker thread and detach it immediately. In worker thread, we will create VM and thus concurrent GC will suspend and resume the detached thread. However, in Windows WTF Threading, we have no reference to the detached thread. Thus we cannot perform suspend and resume operations onto the detached thread. To solve the problem, we change Windows Threading mechanism drastically to align it to the Pthread semantics. In the new Threading, we have RefPtr<Thread> class. It holds a handle to a platform thread. We can perform threading operations with this class. For example, Thread::suspend is offered. And we use destructor of the thread local variable to release the resources held by RefPtr<Thread>. In Windows, Thread::detach does nothing because the resource will be destroyed automatically by RefPtr<Thread>. To do so, we introduce ThreadHolder for Windows. This is similar to the previous ThreadIdentifierData for Pthreads. It holds RefPtr<Thread> in the thread local storage (technically, it is Fiber Local Storage in Windows). Thread::current() will return this reference. The problematic situation is that the order of the deallocation of the thread local storage is not defined. So we should not touch thread local storage in the destructor of the thread local storage. To avoid such edge cases, we have currentThread() / Thread::currentID() APIs. They are safe to be called even in the destructor of the other thread local storage. And in Windows, in the FLS destructor, we will create the thread_local variable to defer the destruction of the ThreadHolder. We ensure that this destructor is called after the other FLS destructors are called in Windows 10. This patch is performance neutral. * WTF.xcodeproj/project.pbxproj: * benchmarks/ConditionSpeedTest.cpp: * benchmarks/LockFairnessTest.cpp: * benchmarks/LockSpeedTest.cpp: * wtf/AutomaticThread.cpp: (WTF::AutomaticThread::start): * wtf/CMakeLists.txt: * wtf/MainThread.h: * wtf/MemoryPressureHandler.h: * wtf/ParallelJobsGeneric.cpp: (WTF::ParallelEnvironment::ThreadPrivate::tryLockFor): (WTF::ParallelEnvironment::ThreadPrivate::workerThread): * wtf/ParallelJobsGeneric.h: (WTF::ParallelEnvironment::ThreadPrivate::ThreadPrivate): Deleted. * wtf/ParkingLot.cpp: (WTF::ParkingLot::forEachImpl): * wtf/ParkingLot.h: (WTF::ParkingLot::forEach): * wtf/PlatformRegisters.h: Renamed from Source/JavaScriptCore/runtime/PlatformThread.h. * wtf/RefPtr.h: (WTF::RefPtr::RefPtr): * wtf/ThreadFunctionInvocation.h: (WTF::ThreadFunctionInvocation::ThreadFunctionInvocation): * wtf/ThreadHolder.cpp: Added. (WTF::ThreadHolder::~ThreadHolder): (WTF::ThreadHolder::initialize): * wtf/ThreadHolder.h: Renamed from Source/WTF/wtf/ThreadIdentifierDataPthreads.h. (WTF::ThreadHolder::thread): (WTF::ThreadHolder::ThreadHolder): * wtf/ThreadHolderPthreads.cpp: Renamed from Source/WTF/wtf/ThreadIdentifierDataPthreads.cpp. (WTF::ThreadHolder::initializeOnce): (WTF::ThreadHolder::current): (WTF::ThreadHolder::destruct): * wtf/ThreadHolderWin.cpp: Added. (WTF::threadMapMutex): (WTF::threadMap): (WTF::ThreadHolder::initializeOnce): (WTF::ThreadHolder::current): (WTF::ThreadHolder::destruct): * wtf/ThreadSpecific.h: * wtf/Threading.cpp: (WTF::Thread::normalizeThreadName): (WTF::threadEntryPoint): (WTF::Thread::create): (WTF::Thread::setCurrentThreadIsUserInteractive): (WTF::Thread::setCurrentThreadIsUserInitiated): (WTF::Thread::setGlobalMaxQOSClass): (WTF::Thread::adjustedQOSClass): (WTF::Thread::dump): (WTF::initializeThreading): (WTF::normalizeThreadName): Deleted. (WTF::createThread): Deleted. (WTF::setCurrentThreadIsUserInteractive): Deleted. (WTF::setCurrentThreadIsUserInitiated): Deleted. (WTF::setGlobalMaxQOSClass): Deleted. (WTF::adjustedQOSClass): Deleted. * wtf/Threading.h: (WTF::Thread::id): (WTF::Thread::operator==): (WTF::Thread::operator!=): (WTF::Thread::joinableState): (WTF::Thread::didBecomeDetached): (WTF::Thread::didJoin): (WTF::Thread::hasExited): (WTF::currentThread): * wtf/ThreadingPthreads.cpp: (WTF::Thread::Thread): (WTF::Thread::~Thread): (WTF::Thread::signalHandlerSuspendResume): (WTF::Thread::initializePlatformThreading): (WTF::initializeCurrentThreadEvenIfNonWTFCreated): (WTF::wtfThreadEntryPoint): (WTF::Thread::createInternal): (WTF::Thread::initializeCurrentThreadInternal): (WTF::Thread::changePriority): (WTF::Thread::waitForCompletion): (WTF::Thread::detach): (WTF::Thread::current): (WTF::Thread::currentID): (WTF::Thread::signal): (WTF::Thread::resume): (WTF::Thread::getRegisters): (WTF::Thread::didExit): (WTF::Thread::establish): (WTF::PthreadState::PthreadState): Deleted. (WTF::PthreadState::joinableState): Deleted. (WTF::PthreadState::pthreadHandle): Deleted. (WTF::PthreadState::didBecomeDetached): Deleted. (WTF::PthreadState::didExit): Deleted. (WTF::PthreadState::didJoin): Deleted. (WTF::PthreadState::hasExited): Deleted. (WTF::threadMapMutex): Deleted. (WTF::initializeThreading): Deleted. (WTF::threadMap): Deleted. (WTF::identifierByPthreadHandle): Deleted. (WTF::establishIdentifierForPthreadHandle): Deleted. (WTF::pthreadHandleForIdentifierWithLockAlreadyHeld): Deleted. (WTF::createThreadInternal): Deleted. (WTF::initializeCurrentThreadInternal): Deleted. (WTF::changeThreadPriority): Deleted. (WTF::waitForThreadCompletion): Deleted. (WTF::detachThread): Deleted. (WTF::threadDidExit): Deleted. (WTF::currentThread): Deleted. (WTF::signalThread): Deleted. * wtf/ThreadingWin.cpp: (WTF::Thread::Thread): (WTF::Thread::~Thread): (WTF::Thread::initializeCurrentThreadInternal): (WTF::Thread::initializePlatformThreading): (WTF::wtfThreadEntryPoint): (WTF::Thread::createInternal): (WTF::Thread::changePriority): (WTF::Thread::waitForCompletion): (WTF::Thread::detach): (WTF::Thread::resume): (WTF::Thread::getRegisters): (WTF::Thread::current): (WTF::Thread::currentID): (WTF::Thread::didExit): (WTF::Thread::establish): (WTF::initializeCurrentThreadInternal): Deleted. (WTF::threadMapMutex): Deleted. (WTF::initializeThreading): Deleted. (WTF::threadMap): Deleted. (WTF::storeThreadHandleByIdentifier): Deleted. (WTF::threadHandleForIdentifier): Deleted. (WTF::clearThreadHandleForIdentifier): Deleted. (WTF::createThreadInternal): Deleted. (WTF::changeThreadPriority): Deleted. (WTF::waitForThreadCompletion): Deleted. (WTF::detachThread): Deleted. (WTF::currentThread): Deleted. * wtf/WorkQueue.cpp: (WTF::WorkQueue::concurrentApply): * wtf/WorkQueue.h: * wtf/cocoa/WorkQueueCocoa.cpp: (WTF::dispatchQOSClass): * wtf/generic/WorkQueueGeneric.cpp: (WorkQueue::platformInitialize): (WorkQueue::platformInvalidate): * wtf/linux/MemoryPressureHandlerLinux.cpp: (WTF::MemoryPressureHandler::EventFDPoller::EventFDPoller): (WTF::MemoryPressureHandler::EventFDPoller::~EventFDPoller): * wtf/win/MainThreadWin.cpp: (WTF::initializeMainThreadPlatform): Tools: Mechanical change. Use Thread:: APIs. * DumpRenderTree/JavaScriptThreading.cpp: (runJavaScriptThread): (startJavaScriptThreads): (stopJavaScriptThreads): * DumpRenderTree/mac/DumpRenderTree.mm: (testThreadIdentifierMap): * TestWebKitAPI/Tests/WTF/Condition.cpp: * TestWebKitAPI/Tests/WTF/Lock.cpp: (TestWebKitAPI::runLockTest): * TestWebKitAPI/Tests/WTF/ParkingLot.cpp: Canonical link: https://commits.webkit.org/187690@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@215265 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-04-12 12:08:29 +00:00
Undo rollout in r217638 with bug fix https://bugs.webkit.org/show_bug.cgi?id=172824 Unreviewed, reland patch with unused set_state code removed. Source/JavaScriptCore: * API/tests/ExecutionTimeLimitTest.cpp: (dispatchTermitateCallback): (testExecutionTimeLimit): * runtime/JSLock.cpp: (JSC::JSLock::didAcquireLock): * runtime/Options.cpp: (JSC::overrideDefaults): (JSC::Options::initialize): * runtime/Options.h: * runtime/VMTraps.cpp: (JSC::SignalContext::SignalContext): (JSC::SignalContext::adjustPCToPointToTrappingInstruction): (JSC::installSignalHandler): (JSC::VMTraps::SignalSender::send): * tools/SigillCrashAnalyzer.cpp: (JSC::SignalContext::SignalContext): (JSC::SignalContext::dump): (JSC::installCrashHandler): * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::compileFunctions): * wasm/WasmFaultSignalHandler.cpp: (JSC::Wasm::trapHandler): (JSC::Wasm::enableFastMemory): * wasm/WasmMachineThreads.cpp: (JSC::Wasm::resetInstructionCacheOnAllThreads): Source/WTF: * Configurations/WTF.xcconfig: * WTF.xcodeproj/project.pbxproj: * wtf/Platform.h: * wtf/PlatformRegisters.h: (WTF::registersFromUContext): * wtf/StackBounds.h: (WTF::StackBounds::StackBounds): * wtf/ThreadHolder.cpp: (WTF::ThreadHolder::~ThreadHolder): * wtf/ThreadMessage.cpp: (WTF::sendMessageUsingSignal): (WTF::sendMessageUsingMach): (WTF::deliverMessagesUsingMach): (WTF::sendMessageScoped): * wtf/ThreadMessage.h: (WTF::sendMessage): * wtf/Threading.h: (WTF::Thread::machThread): * wtf/mac/MachExceptions.defs: Copied from Source/WTF/wtf/ThreadMessage.h. * wtf/threads/Signals.cpp: (WTF::startMachExceptionHandlerThread): (WTF::fromMachException): (WTF::toMachMask): (WTF::handleSignalsWithMach): (WTF::setExceptionPorts): (WTF::activeThreads): (WTF::registerThreadForMachExceptionHandling): (WTF::unregisterThreadForMachExceptionHandling): (WTF::installSignalHandler): (WTF::jscSignalHandler): * wtf/threads/Signals.h: Tools: * TestWebKitAPI/Tests/WTF/ThreadMessages.cpp: (runThreadMessageTest): (TEST): Canonical link: https://commits.webkit.org/189710@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@217669 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-06-01 18:28:48 +00:00
inline PlatformRegisters& registersFromUContext(ucontext_t* ucontext)
{
#if CPU(PPC)
return *bitwise_cast<PlatformRegisters*>(ucontext->uc_mcontext.uc_regs);
#else
Undo rollout in r217638 with bug fix https://bugs.webkit.org/show_bug.cgi?id=172824 Unreviewed, reland patch with unused set_state code removed. Source/JavaScriptCore: * API/tests/ExecutionTimeLimitTest.cpp: (dispatchTermitateCallback): (testExecutionTimeLimit): * runtime/JSLock.cpp: (JSC::JSLock::didAcquireLock): * runtime/Options.cpp: (JSC::overrideDefaults): (JSC::Options::initialize): * runtime/Options.h: * runtime/VMTraps.cpp: (JSC::SignalContext::SignalContext): (JSC::SignalContext::adjustPCToPointToTrappingInstruction): (JSC::installSignalHandler): (JSC::VMTraps::SignalSender::send): * tools/SigillCrashAnalyzer.cpp: (JSC::SignalContext::SignalContext): (JSC::SignalContext::dump): (JSC::installCrashHandler): * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::compileFunctions): * wasm/WasmFaultSignalHandler.cpp: (JSC::Wasm::trapHandler): (JSC::Wasm::enableFastMemory): * wasm/WasmMachineThreads.cpp: (JSC::Wasm::resetInstructionCacheOnAllThreads): Source/WTF: * Configurations/WTF.xcconfig: * WTF.xcodeproj/project.pbxproj: * wtf/Platform.h: * wtf/PlatformRegisters.h: (WTF::registersFromUContext): * wtf/StackBounds.h: (WTF::StackBounds::StackBounds): * wtf/ThreadHolder.cpp: (WTF::ThreadHolder::~ThreadHolder): * wtf/ThreadMessage.cpp: (WTF::sendMessageUsingSignal): (WTF::sendMessageUsingMach): (WTF::deliverMessagesUsingMach): (WTF::sendMessageScoped): * wtf/ThreadMessage.h: (WTF::sendMessage): * wtf/Threading.h: (WTF::Thread::machThread): * wtf/mac/MachExceptions.defs: Copied from Source/WTF/wtf/ThreadMessage.h. * wtf/threads/Signals.cpp: (WTF::startMachExceptionHandlerThread): (WTF::fromMachException): (WTF::toMachMask): (WTF::handleSignalsWithMach): (WTF::setExceptionPorts): (WTF::activeThreads): (WTF::registerThreadForMachExceptionHandling): (WTF::unregisterThreadForMachExceptionHandling): (WTF::installSignalHandler): (WTF::jscSignalHandler): * wtf/threads/Signals.h: Tools: * TestWebKitAPI/Tests/WTF/ThreadMessages.cpp: (runThreadMessageTest): (TEST): Canonical link: https://commits.webkit.org/189710@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@217669 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-06-01 18:28:48 +00:00
return *bitwise_cast<PlatformRegisters*>(&ucontext->uc_mcontext);
#endif
Undo rollout in r217638 with bug fix https://bugs.webkit.org/show_bug.cgi?id=172824 Unreviewed, reland patch with unused set_state code removed. Source/JavaScriptCore: * API/tests/ExecutionTimeLimitTest.cpp: (dispatchTermitateCallback): (testExecutionTimeLimit): * runtime/JSLock.cpp: (JSC::JSLock::didAcquireLock): * runtime/Options.cpp: (JSC::overrideDefaults): (JSC::Options::initialize): * runtime/Options.h: * runtime/VMTraps.cpp: (JSC::SignalContext::SignalContext): (JSC::SignalContext::adjustPCToPointToTrappingInstruction): (JSC::installSignalHandler): (JSC::VMTraps::SignalSender::send): * tools/SigillCrashAnalyzer.cpp: (JSC::SignalContext::SignalContext): (JSC::SignalContext::dump): (JSC::installCrashHandler): * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::compileFunctions): * wasm/WasmFaultSignalHandler.cpp: (JSC::Wasm::trapHandler): (JSC::Wasm::enableFastMemory): * wasm/WasmMachineThreads.cpp: (JSC::Wasm::resetInstructionCacheOnAllThreads): Source/WTF: * Configurations/WTF.xcconfig: * WTF.xcodeproj/project.pbxproj: * wtf/Platform.h: * wtf/PlatformRegisters.h: (WTF::registersFromUContext): * wtf/StackBounds.h: (WTF::StackBounds::StackBounds): * wtf/ThreadHolder.cpp: (WTF::ThreadHolder::~ThreadHolder): * wtf/ThreadMessage.cpp: (WTF::sendMessageUsingSignal): (WTF::sendMessageUsingMach): (WTF::deliverMessagesUsingMach): (WTF::sendMessageScoped): * wtf/ThreadMessage.h: (WTF::sendMessage): * wtf/Threading.h: (WTF::Thread::machThread): * wtf/mac/MachExceptions.defs: Copied from Source/WTF/wtf/ThreadMessage.h. * wtf/threads/Signals.cpp: (WTF::startMachExceptionHandlerThread): (WTF::fromMachException): (WTF::toMachMask): (WTF::handleSignalsWithMach): (WTF::setExceptionPorts): (WTF::activeThreads): (WTF::registerThreadForMachExceptionHandling): (WTF::unregisterThreadForMachExceptionHandling): (WTF::installSignalHandler): (WTF::jscSignalHandler): * wtf/threads/Signals.h: Tools: * TestWebKitAPI/Tests/WTF/ThreadMessages.cpp: (runThreadMessageTest): (TEST): Canonical link: https://commits.webkit.org/189710@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@217669 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-06-01 18:28:48 +00:00
}
[WTF] Introduce Thread class and use RefPtr<Thread> and align Windows Threading implementation semantics to Pthread one https://bugs.webkit.org/show_bug.cgi?id=170502 Reviewed by Mark Lam. Source/JavaScriptCore: * API/tests/CompareAndSwapTest.cpp: (testCompareAndSwap): * JavaScriptCore.xcodeproj/project.pbxproj: * b3/air/testair.cpp: * b3/testb3.cpp: (JSC::B3::run): * bytecode/SuperSampler.cpp: (JSC::initializeSuperSampler): * dfg/DFGWorklist.cpp: * disassembler/Disassembler.cpp: * heap/Heap.cpp: (JSC::Heap::lastChanceToFinalize): (JSC::Heap::notifyIsSafeToCollect): * heap/Heap.h: * heap/MachineStackMarker.cpp: (JSC::MachineThreads::~MachineThreads): (JSC::MachineThreads::addCurrentThread): (JSC::MachineThreads::removeThread): (JSC::MachineThreads::removeThreadIfFound): (JSC::MachineThreads::MachineThread::MachineThread): (JSC::MachineThreads::MachineThread::getRegisters): (JSC::MachineThreads::MachineThread::Registers::stackPointer): (JSC::MachineThreads::MachineThread::Registers::framePointer): (JSC::MachineThreads::MachineThread::Registers::instructionPointer): (JSC::MachineThreads::MachineThread::Registers::llintPC): (JSC::MachineThreads::MachineThread::captureStack): (JSC::MachineThreads::tryCopyOtherThreadStack): (JSC::MachineThreads::tryCopyOtherThreadStacks): (pthreadSignalHandlerSuspendResume): Deleted. (JSC::threadData): Deleted. (JSC::MachineThreads::Thread::Thread): Deleted. (JSC::MachineThreads::Thread::createForCurrentThread): Deleted. (JSC::MachineThreads::Thread::operator==): Deleted. (JSC::MachineThreads::machineThreadForCurrentThread): Deleted. (JSC::MachineThreads::ThreadData::ThreadData): Deleted. (JSC::MachineThreads::ThreadData::~ThreadData): Deleted. (JSC::MachineThreads::ThreadData::suspend): Deleted. (JSC::MachineThreads::ThreadData::resume): Deleted. (JSC::MachineThreads::ThreadData::getRegisters): Deleted. (JSC::MachineThreads::ThreadData::Registers::stackPointer): Deleted. (JSC::MachineThreads::ThreadData::Registers::framePointer): Deleted. (JSC::MachineThreads::ThreadData::Registers::instructionPointer): Deleted. (JSC::MachineThreads::ThreadData::Registers::llintPC): Deleted. (JSC::MachineThreads::ThreadData::freeRegisters): Deleted. (JSC::MachineThreads::ThreadData::captureStack): Deleted. * heap/MachineStackMarker.h: (JSC::MachineThreads::MachineThread::suspend): (JSC::MachineThreads::MachineThread::resume): (JSC::MachineThreads::MachineThread::threadID): (JSC::MachineThreads::MachineThread::stackBase): (JSC::MachineThreads::MachineThread::stackEnd): (JSC::MachineThreads::threadsListHead): (JSC::MachineThreads::Thread::operator!=): Deleted. (JSC::MachineThreads::Thread::suspend): Deleted. (JSC::MachineThreads::Thread::resume): Deleted. (JSC::MachineThreads::Thread::getRegisters): Deleted. (JSC::MachineThreads::Thread::freeRegisters): Deleted. (JSC::MachineThreads::Thread::captureStack): Deleted. (JSC::MachineThreads::Thread::platformThread): Deleted. (JSC::MachineThreads::Thread::stackBase): Deleted. (JSC::MachineThreads::Thread::stackEnd): Deleted. * jit/ICStats.cpp: (JSC::ICStats::ICStats): (JSC::ICStats::~ICStats): * jit/ICStats.h: * jsc.cpp: (functionDollarAgentStart): (startTimeoutThreadIfNeeded): * runtime/JSLock.cpp: (JSC::JSLock::lock): * runtime/JSLock.h: (JSC::JSLock::ownerThread): (JSC::JSLock::currentThreadIsHoldingLock): * runtime/SamplingProfiler.cpp: (JSC::FrameWalker::isValidFramePointer): (JSC::SamplingProfiler::SamplingProfiler): (JSC::SamplingProfiler::createThreadIfNecessary): (JSC::SamplingProfiler::takeSample): * runtime/SamplingProfiler.h: * runtime/VM.h: (JSC::VM::ownerThread): * runtime/VMTraps.cpp: (JSC::findActiveVMAndStackBounds): (JSC::VMTraps::SignalSender::send): (JSC::VMTraps::fireTrap): Source/WebCore: Mechanical change. Use Thread:: APIs. * Modules/indexeddb/server/IDBServer.cpp: (WebCore::IDBServer::IDBServer::IDBServer): * Modules/indexeddb/server/IDBServer.h: * Modules/webaudio/AsyncAudioDecoder.cpp: (WebCore::AsyncAudioDecoder::AsyncAudioDecoder): (WebCore::AsyncAudioDecoder::~AsyncAudioDecoder): (WebCore::AsyncAudioDecoder::runLoop): * Modules/webaudio/AsyncAudioDecoder.h: * Modules/webaudio/OfflineAudioDestinationNode.cpp: (WebCore::OfflineAudioDestinationNode::OfflineAudioDestinationNode): (WebCore::OfflineAudioDestinationNode::uninitialize): (WebCore::OfflineAudioDestinationNode::startRendering): * Modules/webaudio/OfflineAudioDestinationNode.h: * Modules/webdatabase/Database.cpp: (WebCore::Database::securityOrigin): * Modules/webdatabase/DatabaseThread.cpp: (WebCore::DatabaseThread::start): (WebCore::DatabaseThread::databaseThread): (WebCore::DatabaseThread::recordDatabaseOpen): (WebCore::DatabaseThread::recordDatabaseClosed): * Modules/webdatabase/DatabaseThread.h: (WebCore::DatabaseThread::getThreadID): * bindings/js/GCController.cpp: (WebCore::GCController::garbageCollectOnAlternateThreadForDebugging): * fileapi/AsyncFileStream.cpp: (WebCore::callOnFileThread): * loader/icon/IconDatabase.cpp: (WebCore::IconDatabase::open): (WebCore::IconDatabase::close): * loader/icon/IconDatabase.h: * page/ResourceUsageThread.cpp: (WebCore::ResourceUsageThread::createThreadIfNeeded): * page/ResourceUsageThread.h: * page/scrolling/ScrollingThread.cpp: (WebCore::ScrollingThread::ScrollingThread): (WebCore::ScrollingThread::isCurrentThread): (WebCore::ScrollingThread::createThreadIfNeeded): (WebCore::ScrollingThread::threadCallback): * page/scrolling/ScrollingThread.h: * platform/audio/HRTFDatabaseLoader.cpp: (WebCore::HRTFDatabaseLoader::HRTFDatabaseLoader): (WebCore::HRTFDatabaseLoader::loadAsynchronously): (WebCore::HRTFDatabaseLoader::waitForLoaderThreadCompletion): * platform/audio/HRTFDatabaseLoader.h: * platform/audio/ReverbConvolver.cpp: (WebCore::ReverbConvolver::ReverbConvolver): (WebCore::ReverbConvolver::~ReverbConvolver): * platform/audio/ReverbConvolver.h: * platform/audio/gstreamer/AudioFileReaderGStreamer.cpp: (WebCore::createBusFromAudioFile): (WebCore::createBusFromInMemoryAudioFile): * platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp: (ResourceHandleStreamingClient::ResourceHandleStreamingClient): (ResourceHandleStreamingClient::~ResourceHandleStreamingClient): * platform/network/cf/LoaderRunLoopCF.cpp: (WebCore::loaderRunLoop): * platform/network/curl/CurlDownload.cpp: (WebCore::CurlDownloadManager::startThreadIfNeeded): (WebCore::CurlDownloadManager::stopThread): * platform/network/curl/CurlDownload.h: * platform/network/curl/SocketStreamHandleImpl.h: * platform/network/curl/SocketStreamHandleImplCurl.cpp: (WebCore::SocketStreamHandleImpl::startThread): (WebCore::SocketStreamHandleImpl::stopThread): * workers/WorkerThread.cpp: (WebCore::WorkerThread::WorkerThread): (WebCore::WorkerThread::start): (WebCore::WorkerThread::workerThread): * workers/WorkerThread.h: (WebCore::WorkerThread::threadID): Source/WebKit: Mechanical change. Use Thread:: APIs. * Storage/StorageThread.cpp: (WebCore::StorageThread::StorageThread): (WebCore::StorageThread::~StorageThread): (WebCore::StorageThread::start): (WebCore::StorageThread::dispatch): (WebCore::StorageThread::terminate): * Storage/StorageThread.h: Source/WebKit2: Mechanical change. Use Thread:: APIs. * NetworkProcess/NetworkProcess.cpp: (WebKit::NetworkProcess::initializeNetworkProcess): * NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp: (WebKit::NetworkCache::IOChannel::readSyncInThread): * Platform/IPC/Connection.cpp: (IPC::Connection::processIncomingMessage): * Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.h: (WebKit::XPCServiceInitializer): * UIProcess/linux/MemoryPressureMonitor.cpp: (WebKit::MemoryPressureMonitor::MemoryPressureMonitor): * WebProcess/WebProcess.cpp: (WebKit::WebProcess::initializeWebProcess): Source/WTF: This patch is refactoring of WTF Threading mechanism to merge JavaScriptCore's threading extension to WTF Threading. Previously, JavaScriptCore requires richer threading features (such as suspending and resuming threads), and they are implemented for PlatformThread in JavaScriptCore. But these features should be implemented in WTF Threading side instead of maintaining JSC's own threading features too. This patch removes these features from JSC and move it to WTF Threading. However, current WTF Threading has one problem: Windows version of WTF Threading has different semantics from Pthreads one. In Windows WTF Threading, we cannot perform any operation after the target thread is detached: WTF Threading stop tracking the state of the thread once the thread is detached. But this is not the same to Pthreads one. In Pthreads, pthread_detach just means that the resource of the thread will be destroyed automatically. While some operations like pthread_join will be rejected, some operations like pthread_kill will be accepted. The problem is that detached thread can be suspended and resumed in JSC. For example, in jsc.cpp, we start the worker thread and detach it immediately. In worker thread, we will create VM and thus concurrent GC will suspend and resume the detached thread. However, in Windows WTF Threading, we have no reference to the detached thread. Thus we cannot perform suspend and resume operations onto the detached thread. To solve the problem, we change Windows Threading mechanism drastically to align it to the Pthread semantics. In the new Threading, we have RefPtr<Thread> class. It holds a handle to a platform thread. We can perform threading operations with this class. For example, Thread::suspend is offered. And we use destructor of the thread local variable to release the resources held by RefPtr<Thread>. In Windows, Thread::detach does nothing because the resource will be destroyed automatically by RefPtr<Thread>. To do so, we introduce ThreadHolder for Windows. This is similar to the previous ThreadIdentifierData for Pthreads. It holds RefPtr<Thread> in the thread local storage (technically, it is Fiber Local Storage in Windows). Thread::current() will return this reference. The problematic situation is that the order of the deallocation of the thread local storage is not defined. So we should not touch thread local storage in the destructor of the thread local storage. To avoid such edge cases, we have currentThread() / Thread::currentID() APIs. They are safe to be called even in the destructor of the other thread local storage. And in Windows, in the FLS destructor, we will create the thread_local variable to defer the destruction of the ThreadHolder. We ensure that this destructor is called after the other FLS destructors are called in Windows 10. This patch is performance neutral. * WTF.xcodeproj/project.pbxproj: * benchmarks/ConditionSpeedTest.cpp: * benchmarks/LockFairnessTest.cpp: * benchmarks/LockSpeedTest.cpp: * wtf/AutomaticThread.cpp: (WTF::AutomaticThread::start): * wtf/CMakeLists.txt: * wtf/MainThread.h: * wtf/MemoryPressureHandler.h: * wtf/ParallelJobsGeneric.cpp: (WTF::ParallelEnvironment::ThreadPrivate::tryLockFor): (WTF::ParallelEnvironment::ThreadPrivate::workerThread): * wtf/ParallelJobsGeneric.h: (WTF::ParallelEnvironment::ThreadPrivate::ThreadPrivate): Deleted. * wtf/ParkingLot.cpp: (WTF::ParkingLot::forEachImpl): * wtf/ParkingLot.h: (WTF::ParkingLot::forEach): * wtf/PlatformRegisters.h: Renamed from Source/JavaScriptCore/runtime/PlatformThread.h. * wtf/RefPtr.h: (WTF::RefPtr::RefPtr): * wtf/ThreadFunctionInvocation.h: (WTF::ThreadFunctionInvocation::ThreadFunctionInvocation): * wtf/ThreadHolder.cpp: Added. (WTF::ThreadHolder::~ThreadHolder): (WTF::ThreadHolder::initialize): * wtf/ThreadHolder.h: Renamed from Source/WTF/wtf/ThreadIdentifierDataPthreads.h. (WTF::ThreadHolder::thread): (WTF::ThreadHolder::ThreadHolder): * wtf/ThreadHolderPthreads.cpp: Renamed from Source/WTF/wtf/ThreadIdentifierDataPthreads.cpp. (WTF::ThreadHolder::initializeOnce): (WTF::ThreadHolder::current): (WTF::ThreadHolder::destruct): * wtf/ThreadHolderWin.cpp: Added. (WTF::threadMapMutex): (WTF::threadMap): (WTF::ThreadHolder::initializeOnce): (WTF::ThreadHolder::current): (WTF::ThreadHolder::destruct): * wtf/ThreadSpecific.h: * wtf/Threading.cpp: (WTF::Thread::normalizeThreadName): (WTF::threadEntryPoint): (WTF::Thread::create): (WTF::Thread::setCurrentThreadIsUserInteractive): (WTF::Thread::setCurrentThreadIsUserInitiated): (WTF::Thread::setGlobalMaxQOSClass): (WTF::Thread::adjustedQOSClass): (WTF::Thread::dump): (WTF::initializeThreading): (WTF::normalizeThreadName): Deleted. (WTF::createThread): Deleted. (WTF::setCurrentThreadIsUserInteractive): Deleted. (WTF::setCurrentThreadIsUserInitiated): Deleted. (WTF::setGlobalMaxQOSClass): Deleted. (WTF::adjustedQOSClass): Deleted. * wtf/Threading.h: (WTF::Thread::id): (WTF::Thread::operator==): (WTF::Thread::operator!=): (WTF::Thread::joinableState): (WTF::Thread::didBecomeDetached): (WTF::Thread::didJoin): (WTF::Thread::hasExited): (WTF::currentThread): * wtf/ThreadingPthreads.cpp: (WTF::Thread::Thread): (WTF::Thread::~Thread): (WTF::Thread::signalHandlerSuspendResume): (WTF::Thread::initializePlatformThreading): (WTF::initializeCurrentThreadEvenIfNonWTFCreated): (WTF::wtfThreadEntryPoint): (WTF::Thread::createInternal): (WTF::Thread::initializeCurrentThreadInternal): (WTF::Thread::changePriority): (WTF::Thread::waitForCompletion): (WTF::Thread::detach): (WTF::Thread::current): (WTF::Thread::currentID): (WTF::Thread::signal): (WTF::Thread::resume): (WTF::Thread::getRegisters): (WTF::Thread::didExit): (WTF::Thread::establish): (WTF::PthreadState::PthreadState): Deleted. (WTF::PthreadState::joinableState): Deleted. (WTF::PthreadState::pthreadHandle): Deleted. (WTF::PthreadState::didBecomeDetached): Deleted. (WTF::PthreadState::didExit): Deleted. (WTF::PthreadState::didJoin): Deleted. (WTF::PthreadState::hasExited): Deleted. (WTF::threadMapMutex): Deleted. (WTF::initializeThreading): Deleted. (WTF::threadMap): Deleted. (WTF::identifierByPthreadHandle): Deleted. (WTF::establishIdentifierForPthreadHandle): Deleted. (WTF::pthreadHandleForIdentifierWithLockAlreadyHeld): Deleted. (WTF::createThreadInternal): Deleted. (WTF::initializeCurrentThreadInternal): Deleted. (WTF::changeThreadPriority): Deleted. (WTF::waitForThreadCompletion): Deleted. (WTF::detachThread): Deleted. (WTF::threadDidExit): Deleted. (WTF::currentThread): Deleted. (WTF::signalThread): Deleted. * wtf/ThreadingWin.cpp: (WTF::Thread::Thread): (WTF::Thread::~Thread): (WTF::Thread::initializeCurrentThreadInternal): (WTF::Thread::initializePlatformThreading): (WTF::wtfThreadEntryPoint): (WTF::Thread::createInternal): (WTF::Thread::changePriority): (WTF::Thread::waitForCompletion): (WTF::Thread::detach): (WTF::Thread::resume): (WTF::Thread::getRegisters): (WTF::Thread::current): (WTF::Thread::currentID): (WTF::Thread::didExit): (WTF::Thread::establish): (WTF::initializeCurrentThreadInternal): Deleted. (WTF::threadMapMutex): Deleted. (WTF::initializeThreading): Deleted. (WTF::threadMap): Deleted. (WTF::storeThreadHandleByIdentifier): Deleted. (WTF::threadHandleForIdentifier): Deleted. (WTF::clearThreadHandleForIdentifier): Deleted. (WTF::createThreadInternal): Deleted. (WTF::changeThreadPriority): Deleted. (WTF::waitForThreadCompletion): Deleted. (WTF::detachThread): Deleted. (WTF::currentThread): Deleted. * wtf/WorkQueue.cpp: (WTF::WorkQueue::concurrentApply): * wtf/WorkQueue.h: * wtf/cocoa/WorkQueueCocoa.cpp: (WTF::dispatchQOSClass): * wtf/generic/WorkQueueGeneric.cpp: (WorkQueue::platformInitialize): (WorkQueue::platformInvalidate): * wtf/linux/MemoryPressureHandlerLinux.cpp: (WTF::MemoryPressureHandler::EventFDPoller::EventFDPoller): (WTF::MemoryPressureHandler::EventFDPoller::~EventFDPoller): * wtf/win/MainThreadWin.cpp: (WTF::initializeMainThreadPlatform): Tools: Mechanical change. Use Thread:: APIs. * DumpRenderTree/JavaScriptThreading.cpp: (runJavaScriptThread): (startJavaScriptThreads): (stopJavaScriptThreads): * DumpRenderTree/mac/DumpRenderTree.mm: (testThreadIdentifierMap): * TestWebKitAPI/Tests/WTF/Condition.cpp: * TestWebKitAPI/Tests/WTF/Lock.cpp: (TestWebKitAPI::runLockTest): * TestWebKitAPI/Tests/WTF/ParkingLot.cpp: Canonical link: https://commits.webkit.org/187690@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@215265 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-04-12 12:08:29 +00:00
#else
struct PlatformRegisters {
void* stackPointer;
};
[Re-landing] Change JSLock to stash PlatformThread instead of std::thread::id. https://bugs.webkit.org/show_bug.cgi?id=168996 Reviewed by Filip Pizlo and Saam Barati. PlatformThread is more useful because it allows us to: 1. find the MachineThreads::Thread which is associated with it. 2. suspend / resume threads. 3. send a signal to a thread. We can't do those with std::thread::id. We will need one or more of these capabilities to implement non-polling VM traps later. Update: Since we don't have a canonical "uninitialized" value for PlatformThread, we now have a JSLock::m_hasOwnerThread flag that is set to true if and only the m_ownerThread value is valid. JSLock::currentThreadIsHoldingLock() now checks JSLock::m_hasOwnerThread before doing the thread identity comparison. * JavaScriptCore.xcodeproj/project.pbxproj: * heap/MachineStackMarker.cpp: (JSC::MachineThreads::Thread::createForCurrentThread): (JSC::MachineThreads::machineThreadForCurrentThread): (JSC::MachineThreads::removeThread): (JSC::MachineThreads::Thread::suspend): (JSC::MachineThreads::tryCopyOtherThreadStacks): (JSC::getCurrentPlatformThread): Deleted. * heap/MachineStackMarker.h: * runtime/JSCellInlines.h: (JSC::JSCell::classInfo): * runtime/JSLock.cpp: (JSC::JSLock::JSLock): (JSC::JSLock::lock): (JSC::JSLock::unlock): (JSC::JSLock::currentThreadIsHoldingLock): Deleted. * runtime/JSLock.h: (JSC::JSLock::ownerThread): (JSC::JSLock::currentThreadIsHoldingLock): * runtime/PlatformThread.h: Added. (JSC::currentPlatformThread): * runtime/VM.cpp: (JSC::VM::~VM): * runtime/VM.h: (JSC::VM::ownerThread): * runtime/Watchdog.cpp: (JSC::Watchdog::setTimeLimit): (JSC::Watchdog::shouldTerminate): (JSC::Watchdog::startTimer): (JSC::Watchdog::stopTimer): * tools/JSDollarVMPrototype.cpp: (JSC::JSDollarVMPrototype::currentThreadOwnsJSLock): * tools/VMInspector.cpp: Canonical link: https://commits.webkit.org/186036@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@213238 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-03-01 20:15:08 +00:00
#endif
[WTF] Introduce Thread class and use RefPtr<Thread> and align Windows Threading implementation semantics to Pthread one https://bugs.webkit.org/show_bug.cgi?id=170502 Reviewed by Mark Lam. Source/JavaScriptCore: * API/tests/CompareAndSwapTest.cpp: (testCompareAndSwap): * JavaScriptCore.xcodeproj/project.pbxproj: * b3/air/testair.cpp: * b3/testb3.cpp: (JSC::B3::run): * bytecode/SuperSampler.cpp: (JSC::initializeSuperSampler): * dfg/DFGWorklist.cpp: * disassembler/Disassembler.cpp: * heap/Heap.cpp: (JSC::Heap::lastChanceToFinalize): (JSC::Heap::notifyIsSafeToCollect): * heap/Heap.h: * heap/MachineStackMarker.cpp: (JSC::MachineThreads::~MachineThreads): (JSC::MachineThreads::addCurrentThread): (JSC::MachineThreads::removeThread): (JSC::MachineThreads::removeThreadIfFound): (JSC::MachineThreads::MachineThread::MachineThread): (JSC::MachineThreads::MachineThread::getRegisters): (JSC::MachineThreads::MachineThread::Registers::stackPointer): (JSC::MachineThreads::MachineThread::Registers::framePointer): (JSC::MachineThreads::MachineThread::Registers::instructionPointer): (JSC::MachineThreads::MachineThread::Registers::llintPC): (JSC::MachineThreads::MachineThread::captureStack): (JSC::MachineThreads::tryCopyOtherThreadStack): (JSC::MachineThreads::tryCopyOtherThreadStacks): (pthreadSignalHandlerSuspendResume): Deleted. (JSC::threadData): Deleted. (JSC::MachineThreads::Thread::Thread): Deleted. (JSC::MachineThreads::Thread::createForCurrentThread): Deleted. (JSC::MachineThreads::Thread::operator==): Deleted. (JSC::MachineThreads::machineThreadForCurrentThread): Deleted. (JSC::MachineThreads::ThreadData::ThreadData): Deleted. (JSC::MachineThreads::ThreadData::~ThreadData): Deleted. (JSC::MachineThreads::ThreadData::suspend): Deleted. (JSC::MachineThreads::ThreadData::resume): Deleted. (JSC::MachineThreads::ThreadData::getRegisters): Deleted. (JSC::MachineThreads::ThreadData::Registers::stackPointer): Deleted. (JSC::MachineThreads::ThreadData::Registers::framePointer): Deleted. (JSC::MachineThreads::ThreadData::Registers::instructionPointer): Deleted. (JSC::MachineThreads::ThreadData::Registers::llintPC): Deleted. (JSC::MachineThreads::ThreadData::freeRegisters): Deleted. (JSC::MachineThreads::ThreadData::captureStack): Deleted. * heap/MachineStackMarker.h: (JSC::MachineThreads::MachineThread::suspend): (JSC::MachineThreads::MachineThread::resume): (JSC::MachineThreads::MachineThread::threadID): (JSC::MachineThreads::MachineThread::stackBase): (JSC::MachineThreads::MachineThread::stackEnd): (JSC::MachineThreads::threadsListHead): (JSC::MachineThreads::Thread::operator!=): Deleted. (JSC::MachineThreads::Thread::suspend): Deleted. (JSC::MachineThreads::Thread::resume): Deleted. (JSC::MachineThreads::Thread::getRegisters): Deleted. (JSC::MachineThreads::Thread::freeRegisters): Deleted. (JSC::MachineThreads::Thread::captureStack): Deleted. (JSC::MachineThreads::Thread::platformThread): Deleted. (JSC::MachineThreads::Thread::stackBase): Deleted. (JSC::MachineThreads::Thread::stackEnd): Deleted. * jit/ICStats.cpp: (JSC::ICStats::ICStats): (JSC::ICStats::~ICStats): * jit/ICStats.h: * jsc.cpp: (functionDollarAgentStart): (startTimeoutThreadIfNeeded): * runtime/JSLock.cpp: (JSC::JSLock::lock): * runtime/JSLock.h: (JSC::JSLock::ownerThread): (JSC::JSLock::currentThreadIsHoldingLock): * runtime/SamplingProfiler.cpp: (JSC::FrameWalker::isValidFramePointer): (JSC::SamplingProfiler::SamplingProfiler): (JSC::SamplingProfiler::createThreadIfNecessary): (JSC::SamplingProfiler::takeSample): * runtime/SamplingProfiler.h: * runtime/VM.h: (JSC::VM::ownerThread): * runtime/VMTraps.cpp: (JSC::findActiveVMAndStackBounds): (JSC::VMTraps::SignalSender::send): (JSC::VMTraps::fireTrap): Source/WebCore: Mechanical change. Use Thread:: APIs. * Modules/indexeddb/server/IDBServer.cpp: (WebCore::IDBServer::IDBServer::IDBServer): * Modules/indexeddb/server/IDBServer.h: * Modules/webaudio/AsyncAudioDecoder.cpp: (WebCore::AsyncAudioDecoder::AsyncAudioDecoder): (WebCore::AsyncAudioDecoder::~AsyncAudioDecoder): (WebCore::AsyncAudioDecoder::runLoop): * Modules/webaudio/AsyncAudioDecoder.h: * Modules/webaudio/OfflineAudioDestinationNode.cpp: (WebCore::OfflineAudioDestinationNode::OfflineAudioDestinationNode): (WebCore::OfflineAudioDestinationNode::uninitialize): (WebCore::OfflineAudioDestinationNode::startRendering): * Modules/webaudio/OfflineAudioDestinationNode.h: * Modules/webdatabase/Database.cpp: (WebCore::Database::securityOrigin): * Modules/webdatabase/DatabaseThread.cpp: (WebCore::DatabaseThread::start): (WebCore::DatabaseThread::databaseThread): (WebCore::DatabaseThread::recordDatabaseOpen): (WebCore::DatabaseThread::recordDatabaseClosed): * Modules/webdatabase/DatabaseThread.h: (WebCore::DatabaseThread::getThreadID): * bindings/js/GCController.cpp: (WebCore::GCController::garbageCollectOnAlternateThreadForDebugging): * fileapi/AsyncFileStream.cpp: (WebCore::callOnFileThread): * loader/icon/IconDatabase.cpp: (WebCore::IconDatabase::open): (WebCore::IconDatabase::close): * loader/icon/IconDatabase.h: * page/ResourceUsageThread.cpp: (WebCore::ResourceUsageThread::createThreadIfNeeded): * page/ResourceUsageThread.h: * page/scrolling/ScrollingThread.cpp: (WebCore::ScrollingThread::ScrollingThread): (WebCore::ScrollingThread::isCurrentThread): (WebCore::ScrollingThread::createThreadIfNeeded): (WebCore::ScrollingThread::threadCallback): * page/scrolling/ScrollingThread.h: * platform/audio/HRTFDatabaseLoader.cpp: (WebCore::HRTFDatabaseLoader::HRTFDatabaseLoader): (WebCore::HRTFDatabaseLoader::loadAsynchronously): (WebCore::HRTFDatabaseLoader::waitForLoaderThreadCompletion): * platform/audio/HRTFDatabaseLoader.h: * platform/audio/ReverbConvolver.cpp: (WebCore::ReverbConvolver::ReverbConvolver): (WebCore::ReverbConvolver::~ReverbConvolver): * platform/audio/ReverbConvolver.h: * platform/audio/gstreamer/AudioFileReaderGStreamer.cpp: (WebCore::createBusFromAudioFile): (WebCore::createBusFromInMemoryAudioFile): * platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp: (ResourceHandleStreamingClient::ResourceHandleStreamingClient): (ResourceHandleStreamingClient::~ResourceHandleStreamingClient): * platform/network/cf/LoaderRunLoopCF.cpp: (WebCore::loaderRunLoop): * platform/network/curl/CurlDownload.cpp: (WebCore::CurlDownloadManager::startThreadIfNeeded): (WebCore::CurlDownloadManager::stopThread): * platform/network/curl/CurlDownload.h: * platform/network/curl/SocketStreamHandleImpl.h: * platform/network/curl/SocketStreamHandleImplCurl.cpp: (WebCore::SocketStreamHandleImpl::startThread): (WebCore::SocketStreamHandleImpl::stopThread): * workers/WorkerThread.cpp: (WebCore::WorkerThread::WorkerThread): (WebCore::WorkerThread::start): (WebCore::WorkerThread::workerThread): * workers/WorkerThread.h: (WebCore::WorkerThread::threadID): Source/WebKit: Mechanical change. Use Thread:: APIs. * Storage/StorageThread.cpp: (WebCore::StorageThread::StorageThread): (WebCore::StorageThread::~StorageThread): (WebCore::StorageThread::start): (WebCore::StorageThread::dispatch): (WebCore::StorageThread::terminate): * Storage/StorageThread.h: Source/WebKit2: Mechanical change. Use Thread:: APIs. * NetworkProcess/NetworkProcess.cpp: (WebKit::NetworkProcess::initializeNetworkProcess): * NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp: (WebKit::NetworkCache::IOChannel::readSyncInThread): * Platform/IPC/Connection.cpp: (IPC::Connection::processIncomingMessage): * Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.h: (WebKit::XPCServiceInitializer): * UIProcess/linux/MemoryPressureMonitor.cpp: (WebKit::MemoryPressureMonitor::MemoryPressureMonitor): * WebProcess/WebProcess.cpp: (WebKit::WebProcess::initializeWebProcess): Source/WTF: This patch is refactoring of WTF Threading mechanism to merge JavaScriptCore's threading extension to WTF Threading. Previously, JavaScriptCore requires richer threading features (such as suspending and resuming threads), and they are implemented for PlatformThread in JavaScriptCore. But these features should be implemented in WTF Threading side instead of maintaining JSC's own threading features too. This patch removes these features from JSC and move it to WTF Threading. However, current WTF Threading has one problem: Windows version of WTF Threading has different semantics from Pthreads one. In Windows WTF Threading, we cannot perform any operation after the target thread is detached: WTF Threading stop tracking the state of the thread once the thread is detached. But this is not the same to Pthreads one. In Pthreads, pthread_detach just means that the resource of the thread will be destroyed automatically. While some operations like pthread_join will be rejected, some operations like pthread_kill will be accepted. The problem is that detached thread can be suspended and resumed in JSC. For example, in jsc.cpp, we start the worker thread and detach it immediately. In worker thread, we will create VM and thus concurrent GC will suspend and resume the detached thread. However, in Windows WTF Threading, we have no reference to the detached thread. Thus we cannot perform suspend and resume operations onto the detached thread. To solve the problem, we change Windows Threading mechanism drastically to align it to the Pthread semantics. In the new Threading, we have RefPtr<Thread> class. It holds a handle to a platform thread. We can perform threading operations with this class. For example, Thread::suspend is offered. And we use destructor of the thread local variable to release the resources held by RefPtr<Thread>. In Windows, Thread::detach does nothing because the resource will be destroyed automatically by RefPtr<Thread>. To do so, we introduce ThreadHolder for Windows. This is similar to the previous ThreadIdentifierData for Pthreads. It holds RefPtr<Thread> in the thread local storage (technically, it is Fiber Local Storage in Windows). Thread::current() will return this reference. The problematic situation is that the order of the deallocation of the thread local storage is not defined. So we should not touch thread local storage in the destructor of the thread local storage. To avoid such edge cases, we have currentThread() / Thread::currentID() APIs. They are safe to be called even in the destructor of the other thread local storage. And in Windows, in the FLS destructor, we will create the thread_local variable to defer the destruction of the ThreadHolder. We ensure that this destructor is called after the other FLS destructors are called in Windows 10. This patch is performance neutral. * WTF.xcodeproj/project.pbxproj: * benchmarks/ConditionSpeedTest.cpp: * benchmarks/LockFairnessTest.cpp: * benchmarks/LockSpeedTest.cpp: * wtf/AutomaticThread.cpp: (WTF::AutomaticThread::start): * wtf/CMakeLists.txt: * wtf/MainThread.h: * wtf/MemoryPressureHandler.h: * wtf/ParallelJobsGeneric.cpp: (WTF::ParallelEnvironment::ThreadPrivate::tryLockFor): (WTF::ParallelEnvironment::ThreadPrivate::workerThread): * wtf/ParallelJobsGeneric.h: (WTF::ParallelEnvironment::ThreadPrivate::ThreadPrivate): Deleted. * wtf/ParkingLot.cpp: (WTF::ParkingLot::forEachImpl): * wtf/ParkingLot.h: (WTF::ParkingLot::forEach): * wtf/PlatformRegisters.h: Renamed from Source/JavaScriptCore/runtime/PlatformThread.h. * wtf/RefPtr.h: (WTF::RefPtr::RefPtr): * wtf/ThreadFunctionInvocation.h: (WTF::ThreadFunctionInvocation::ThreadFunctionInvocation): * wtf/ThreadHolder.cpp: Added. (WTF::ThreadHolder::~ThreadHolder): (WTF::ThreadHolder::initialize): * wtf/ThreadHolder.h: Renamed from Source/WTF/wtf/ThreadIdentifierDataPthreads.h. (WTF::ThreadHolder::thread): (WTF::ThreadHolder::ThreadHolder): * wtf/ThreadHolderPthreads.cpp: Renamed from Source/WTF/wtf/ThreadIdentifierDataPthreads.cpp. (WTF::ThreadHolder::initializeOnce): (WTF::ThreadHolder::current): (WTF::ThreadHolder::destruct): * wtf/ThreadHolderWin.cpp: Added. (WTF::threadMapMutex): (WTF::threadMap): (WTF::ThreadHolder::initializeOnce): (WTF::ThreadHolder::current): (WTF::ThreadHolder::destruct): * wtf/ThreadSpecific.h: * wtf/Threading.cpp: (WTF::Thread::normalizeThreadName): (WTF::threadEntryPoint): (WTF::Thread::create): (WTF::Thread::setCurrentThreadIsUserInteractive): (WTF::Thread::setCurrentThreadIsUserInitiated): (WTF::Thread::setGlobalMaxQOSClass): (WTF::Thread::adjustedQOSClass): (WTF::Thread::dump): (WTF::initializeThreading): (WTF::normalizeThreadName): Deleted. (WTF::createThread): Deleted. (WTF::setCurrentThreadIsUserInteractive): Deleted. (WTF::setCurrentThreadIsUserInitiated): Deleted. (WTF::setGlobalMaxQOSClass): Deleted. (WTF::adjustedQOSClass): Deleted. * wtf/Threading.h: (WTF::Thread::id): (WTF::Thread::operator==): (WTF::Thread::operator!=): (WTF::Thread::joinableState): (WTF::Thread::didBecomeDetached): (WTF::Thread::didJoin): (WTF::Thread::hasExited): (WTF::currentThread): * wtf/ThreadingPthreads.cpp: (WTF::Thread::Thread): (WTF::Thread::~Thread): (WTF::Thread::signalHandlerSuspendResume): (WTF::Thread::initializePlatformThreading): (WTF::initializeCurrentThreadEvenIfNonWTFCreated): (WTF::wtfThreadEntryPoint): (WTF::Thread::createInternal): (WTF::Thread::initializeCurrentThreadInternal): (WTF::Thread::changePriority): (WTF::Thread::waitForCompletion): (WTF::Thread::detach): (WTF::Thread::current): (WTF::Thread::currentID): (WTF::Thread::signal): (WTF::Thread::resume): (WTF::Thread::getRegisters): (WTF::Thread::didExit): (WTF::Thread::establish): (WTF::PthreadState::PthreadState): Deleted. (WTF::PthreadState::joinableState): Deleted. (WTF::PthreadState::pthreadHandle): Deleted. (WTF::PthreadState::didBecomeDetached): Deleted. (WTF::PthreadState::didExit): Deleted. (WTF::PthreadState::didJoin): Deleted. (WTF::PthreadState::hasExited): Deleted. (WTF::threadMapMutex): Deleted. (WTF::initializeThreading): Deleted. (WTF::threadMap): Deleted. (WTF::identifierByPthreadHandle): Deleted. (WTF::establishIdentifierForPthreadHandle): Deleted. (WTF::pthreadHandleForIdentifierWithLockAlreadyHeld): Deleted. (WTF::createThreadInternal): Deleted. (WTF::initializeCurrentThreadInternal): Deleted. (WTF::changeThreadPriority): Deleted. (WTF::waitForThreadCompletion): Deleted. (WTF::detachThread): Deleted. (WTF::threadDidExit): Deleted. (WTF::currentThread): Deleted. (WTF::signalThread): Deleted. * wtf/ThreadingWin.cpp: (WTF::Thread::Thread): (WTF::Thread::~Thread): (WTF::Thread::initializeCurrentThreadInternal): (WTF::Thread::initializePlatformThreading): (WTF::wtfThreadEntryPoint): (WTF::Thread::createInternal): (WTF::Thread::changePriority): (WTF::Thread::waitForCompletion): (WTF::Thread::detach): (WTF::Thread::resume): (WTF::Thread::getRegisters): (WTF::Thread::current): (WTF::Thread::currentID): (WTF::Thread::didExit): (WTF::Thread::establish): (WTF::initializeCurrentThreadInternal): Deleted. (WTF::threadMapMutex): Deleted. (WTF::initializeThreading): Deleted. (WTF::threadMap): Deleted. (WTF::storeThreadHandleByIdentifier): Deleted. (WTF::threadHandleForIdentifier): Deleted. (WTF::clearThreadHandleForIdentifier): Deleted. (WTF::createThreadInternal): Deleted. (WTF::changeThreadPriority): Deleted. (WTF::waitForThreadCompletion): Deleted. (WTF::detachThread): Deleted. (WTF::currentThread): Deleted. * wtf/WorkQueue.cpp: (WTF::WorkQueue::concurrentApply): * wtf/WorkQueue.h: * wtf/cocoa/WorkQueueCocoa.cpp: (WTF::dispatchQOSClass): * wtf/generic/WorkQueueGeneric.cpp: (WorkQueue::platformInitialize): (WorkQueue::platformInvalidate): * wtf/linux/MemoryPressureHandlerLinux.cpp: (WTF::MemoryPressureHandler::EventFDPoller::EventFDPoller): (WTF::MemoryPressureHandler::EventFDPoller::~EventFDPoller): * wtf/win/MainThreadWin.cpp: (WTF::initializeMainThreadPlatform): Tools: Mechanical change. Use Thread:: APIs. * DumpRenderTree/JavaScriptThreading.cpp: (runJavaScriptThread): (startJavaScriptThreads): (stopJavaScriptThreads): * DumpRenderTree/mac/DumpRenderTree.mm: (testThreadIdentifierMap): * TestWebKitAPI/Tests/WTF/Condition.cpp: * TestWebKitAPI/Tests/WTF/Lock.cpp: (TestWebKitAPI::runLockTest): * TestWebKitAPI/Tests/WTF/ParkingLot.cpp: Canonical link: https://commits.webkit.org/187690@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@215265 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-04-12 12:08:29 +00:00
} // namespace WTF
Open source arm64e code. https://bugs.webkit.org/show_bug.cgi?id=196012 <rdar://problem/49066237> Reviewed by Keith Miller. Source/JavaScriptCore: * JavaScriptCore.xcodeproj/project.pbxproj: * Sources.txt: * assembler/ARM64EAssembler.h: Added. (JSC::ARM64EAssembler::encodeGroup1): (JSC::ARM64EAssembler::encodeGroup2): (JSC::ARM64EAssembler::encodeGroup4): (JSC::ARM64EAssembler::pacia1716): (JSC::ARM64EAssembler::pacib1716): (JSC::ARM64EAssembler::autia1716): (JSC::ARM64EAssembler::autib1716): (JSC::ARM64EAssembler::paciaz): (JSC::ARM64EAssembler::paciasp): (JSC::ARM64EAssembler::pacibz): (JSC::ARM64EAssembler::pacibsp): (JSC::ARM64EAssembler::autiaz): (JSC::ARM64EAssembler::autiasp): (JSC::ARM64EAssembler::autibz): (JSC::ARM64EAssembler::autibsp): (JSC::ARM64EAssembler::xpaclri): (JSC::ARM64EAssembler::pacia): (JSC::ARM64EAssembler::pacib): (JSC::ARM64EAssembler::pacda): (JSC::ARM64EAssembler::pacdb): (JSC::ARM64EAssembler::autia): (JSC::ARM64EAssembler::autib): (JSC::ARM64EAssembler::autda): (JSC::ARM64EAssembler::autdb): (JSC::ARM64EAssembler::paciza): (JSC::ARM64EAssembler::pacizb): (JSC::ARM64EAssembler::pacdza): (JSC::ARM64EAssembler::pacdzb): (JSC::ARM64EAssembler::autiza): (JSC::ARM64EAssembler::autizb): (JSC::ARM64EAssembler::autdza): (JSC::ARM64EAssembler::autdzb): (JSC::ARM64EAssembler::xpaci): (JSC::ARM64EAssembler::xpacd): (JSC::ARM64EAssembler::pacga): (JSC::ARM64EAssembler::braa): (JSC::ARM64EAssembler::brab): (JSC::ARM64EAssembler::blraa): (JSC::ARM64EAssembler::blrab): (JSC::ARM64EAssembler::braaz): (JSC::ARM64EAssembler::brabz): (JSC::ARM64EAssembler::blraaz): (JSC::ARM64EAssembler::blrabz): (JSC::ARM64EAssembler::retaa): (JSC::ARM64EAssembler::retab): (JSC::ARM64EAssembler::eretaa): (JSC::ARM64EAssembler::eretab): (JSC::ARM64EAssembler::linkPointer): (JSC::ARM64EAssembler::repatchPointer): (JSC::ARM64EAssembler::setPointer): (JSC::ARM64EAssembler::readPointer): (JSC::ARM64EAssembler::readCallTarget): (JSC::ARM64EAssembler::ret): * assembler/MacroAssembler.cpp: * assembler/MacroAssembler.h: * assembler/MacroAssemblerARM64.cpp: * assembler/MacroAssemblerARM64E.h: Added. (JSC::MacroAssemblerARM64E::tagReturnAddress): (JSC::MacroAssemblerARM64E::untagReturnAddress): (JSC::MacroAssemblerARM64E::tagPtr): (JSC::MacroAssemblerARM64E::untagPtr): (JSC::MacroAssemblerARM64E::removePtrTag): (JSC::MacroAssemblerARM64E::callTrustedPtr): (JSC::MacroAssemblerARM64E::call): (JSC::MacroAssemblerARM64E::callRegister): (JSC::MacroAssemblerARM64E::jump): * dfg/DFGOSRExit.cpp: (JSC::DFG::reifyInlinedCallFrames): * dfg/DFGOSRExitCompilerCommon.cpp: (JSC::DFG::reifyInlinedCallFrames): * ftl/FTLThunks.cpp: (JSC::FTL::genericGenerationThunkGenerator): * jit/CCallHelpers.h: (JSC::CCallHelpers::prepareForTailCallSlow): * jit/CallFrameShuffler.cpp: (JSC::CallFrameShuffler::prepareForTailCall): * jit/ExecutableAllocator.cpp: (JSC::ExecutableAllocator::allocate): * jit/ThunkGenerators.cpp: (JSC::arityFixupGenerator): * llint/LLIntOfflineAsmConfig.h: * llint/LowLevelInterpreter.asm: * llint/LowLevelInterpreter64.asm: * runtime/ClassInfo.h: * runtime/InitializeThreading.cpp: (JSC::initializeThreading): * runtime/JSCPtrTag.cpp: Added. (JSC::tagForPtr): (JSC::ptrTagName): (JSC::initializePtrTagLookup): * runtime/JSCPtrTag.h: (JSC::initializePtrTagLookup): * runtime/Options.cpp: (JSC::recomputeDependentOptions): Source/WTF: * WTF.xcodeproj/project.pbxproj: * wtf/BlockPtr.h: * wtf/Platform.h: * wtf/PlatformRegisters.cpp: Added. (WTF::threadStateLRInternal): (WTF::threadStatePCInternal): * wtf/PlatformRegisters.h: * wtf/PointerPreparations.h: * wtf/PtrTag.cpp: Added. (WTF::tagForPtr): (WTF::ptrTagName): (WTF::registerPtrTagLookup): (WTF::reportBadTag): * wtf/PtrTag.h: (WTF::removeCodePtrTag): (WTF::tagCodePtrImpl): (WTF::tagCodePtr): (WTF::untagCodePtrImplHelper): (WTF::untagCodePtrImpl): (WTF::untagCodePtr): (WTF::retagCodePtrImplHelper): (WTF::retagCodePtrImpl): (WTF::retagCodePtr): (WTF::tagCFunctionPtrImpl): (WTF::tagCFunctionPtr): (WTF::untagCFunctionPtrImpl): (WTF::untagCFunctionPtr): (WTF::tagInt): (WTF::assertIsCFunctionPtr): (WTF::assertIsNullOrCFunctionPtr): (WTF::assertIsNotTagged): (WTF::assertIsTagged): (WTF::assertIsNullOrTagged): (WTF::isTaggedWith): (WTF::assertIsTaggedWith): (WTF::assertIsNullOrTaggedWith): (WTF::usesPointerTagging): (WTF::registerPtrTagLookup): (WTF::reportBadTag): (WTF::tagForPtr): Deleted. Canonical link: https://commits.webkit.org/210319@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@243254 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-03-20 23:32:26 +00:00
#if USE(PLATFORM_REGISTERS_WITH_PROFILE)
#if CPU(ARM64E)
namespace WTF {
extern void* threadStateLRInternal(PlatformRegisters&);
extern void* threadStatePCInternal(PlatformRegisters&);
} // namespace WTF
using WTF::threadStateLRInternal;
using WTF::threadStatePCInternal;
#else // not CPU(ARM64E)
#define threadStateLRInternal(regs) bitwise_cast<void*>(arm_thread_state64_get_lr(regs))
#define threadStatePCInternal(regs) bitwise_cast<void*>(arm_thread_state64_get_pc(regs))
#endif // CPU(ARM64E)
#define WTF_READ_PLATFORM_REGISTERS_SP_WITH_PROFILE(regs) \
reinterpret_cast<void*>(arm_thread_state64_get_sp(const_cast<PlatformRegisters&>(regs)))
#define WTF_WRITE_PLATFORM_REGISTERS_SP_WITH_PROFILE(regs, newPointer) \
arm_thread_state64_set_sp(regs, reinterpret_cast<uintptr_t>(newPointer))
#define WTF_READ_PLATFORM_REGISTERS_FP_WITH_PROFILE(regs) \
reinterpret_cast<void*>(arm_thread_state64_get_fp(const_cast<PlatformRegisters&>(regs)))
#define WTF_WRITE_PLATFORM_REGISTERS_FP_WITH_PROFILE(regs, newPointer) \
arm_thread_state64_set_fp(regs, reinterpret_cast<uintptr_t>(newPointer))
#define WTF_READ_PLATFORM_REGISTERS_LR_WITH_PROFILE(regs) \
threadStateLRInternal(const_cast<PlatformRegisters&>(regs))
#define WTF_WRITE_PLATFORM_REGISTERS_LR_WITH_PROFILE(regs, newPointer) \
arm_thread_state64_set_lr_fptr(regs, newPointer)
#define WTF_READ_PLATFORM_REGISTERS_PC_WITH_PROFILE(regs) \
threadStatePCInternal(const_cast<PlatformRegisters&>(regs))
#define WTF_WRITE_PLATFORM_REGISTERS_PC_WITH_PROFILE(regs, newPointer) \
arm_thread_state64_set_pc_fptr(regs, newPointer)
#define WTF_READ_MACHINE_CONTEXT_SP_WITH_PROFILE(machineContext) \
WTF_READ_PLATFORM_REGISTERS_SP_WITH_PROFILE(machineContext->__ss)
#define WTF_WRITE_MACHINE_CONTEXT_SP_WITH_PROFILE(machineContext, newPointer) \
WTF_WRITE_PLATFORM_REGISTERS_SP_WITH_PROFILE(machineContext->__ss, newPointer)
#define WTF_READ_MACHINE_CONTEXT_FP_WITH_PROFILE(machineContext) \
WTF_READ_PLATFORM_REGISTERS_FP_WITH_PROFILE(machineContext->__ss)
#define WTF_WRITE_MACHINE_CONTEXT_FP_WITH_PROFILE(machineContext, newPointer) \
WTF_WRITE_PLATFORM_REGISTERS_FP_WITH_PROFILE(machineContext->__ss, newPointer)
#define WTF_WRITE_MACHINE_CONTEXT_LR_WITH_PROFILE(machineContext, newPointer) \
WTF_WRITE_PLATFORM_REGISTERS_LR_WITH_PROFILE(machineContext->__ss, newPointer)
#define WTF_READ_MACHINE_CONTEXT_PC_WITH_PROFILE(machineContext) \
WTF_READ_PLATFORM_REGISTERS_PC_WITH_PROFILE(machineContext->__ss)
#define WTF_WRITE_MACHINE_CONTEXT_PC_WITH_PROFILE(machineContext, newPointer) \
WTF_WRITE_PLATFORM_REGISTERS_PC_WITH_PROFILE(machineContext->__ss, newPointer)
#endif // USE(PLATFORM_REGISTERS_WITH_PROFILE)
using WTF::PlatformRegisters;