haikuwebkit/Source/WTF/wtf/AutomaticThread.cpp

249 lines
7.7 KiB
C++
Raw Permalink Normal View History

WTF should make it easier to create threads that die automatically after inactivity https://bugs.webkit.org/show_bug.cgi?id=163576 Reviewed by Andreas Kling. Source/JavaScriptCore: Added a sleepSeconds() function, which made it easier for me to test this change. The WTF changes in this patch change how the JSC GC manages threads: the GC threads will now shut down automatically after 1 second of inactivity. Maybe this will save some memory. * jsc.cpp: (GlobalObject::finishCreation): (functionSleepSeconds): Source/WTF: For a long time now, I've been adding threads to WTF/JSC and each time I do this, I feel guilty because those threads don't shut down when they are inactive. For example, in bug 163562, I need to add a new GC thread. There will be one of them per VM. This means that a JSC API client that starts a lot of VMs will have a lot of threads. I don't think that's good. A common pattern for all of these threads is that they have some well-defined trigger that causes them to run. This trigger has a lock, a condition variable, some logic that determines if there is work to do, and then of course the logic for the thread's actual work. The thread bodies usually look like this: void Thingy::runThread() { for (;;) { Work work; { LockHolder locker(m_lock); while (!hasWork()) m_cond.wait(m_lock); work = takeWork(); } doWork(work); } } If you look at ParallelHelperPool (the GC's threads) and DFG::Worklist (some of the JIT's threads), you will see this pattern. This change adds a new kind of thread, called AutomaticThread, that lets you write threads to this pattern while getting automatic thread shutdown for free: instead of just waiting on a condition variable, AutomaticThread will have a timeout that causes the thread to die. The condition variable associated with AutomaticThread, called AutomaticThreadCondition, is smart enough to restart any threads that have decided to stop due to inactivity. The inactivity threshold is current just 1 second. In this patch I only adopt AutomaticThread for ParallelHelperPool. I plan to adopt it in more places soon. * WTF.xcodeproj/project.pbxproj: * wtf/AutomaticThread.cpp: Added. (WTF::AutomaticThreadCondition::create): (WTF::AutomaticThreadCondition::AutomaticThreadCondition): (WTF::AutomaticThreadCondition::~AutomaticThreadCondition): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Added. * wtf/CMakeLists.txt: * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::ParallelHelperPool): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::helperThreadBody): Deleted. (WTF::ParallelHelperPool::waitForClientWithTask): Deleted. * wtf/ParallelHelperPool.h: Canonical link: https://commits.webkit.org/181393@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207480 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-18 20:17:10 +00:00
/*
* Copyright (C) 2016-2020 Apple Inc. All rights reserved.
WTF should make it easier to create threads that die automatically after inactivity https://bugs.webkit.org/show_bug.cgi?id=163576 Reviewed by Andreas Kling. Source/JavaScriptCore: Added a sleepSeconds() function, which made it easier for me to test this change. The WTF changes in this patch change how the JSC GC manages threads: the GC threads will now shut down automatically after 1 second of inactivity. Maybe this will save some memory. * jsc.cpp: (GlobalObject::finishCreation): (functionSleepSeconds): Source/WTF: For a long time now, I've been adding threads to WTF/JSC and each time I do this, I feel guilty because those threads don't shut down when they are inactive. For example, in bug 163562, I need to add a new GC thread. There will be one of them per VM. This means that a JSC API client that starts a lot of VMs will have a lot of threads. I don't think that's good. A common pattern for all of these threads is that they have some well-defined trigger that causes them to run. This trigger has a lock, a condition variable, some logic that determines if there is work to do, and then of course the logic for the thread's actual work. The thread bodies usually look like this: void Thingy::runThread() { for (;;) { Work work; { LockHolder locker(m_lock); while (!hasWork()) m_cond.wait(m_lock); work = takeWork(); } doWork(work); } } If you look at ParallelHelperPool (the GC's threads) and DFG::Worklist (some of the JIT's threads), you will see this pattern. This change adds a new kind of thread, called AutomaticThread, that lets you write threads to this pattern while getting automatic thread shutdown for free: instead of just waiting on a condition variable, AutomaticThread will have a timeout that causes the thread to die. The condition variable associated with AutomaticThread, called AutomaticThreadCondition, is smart enough to restart any threads that have decided to stop due to inactivity. The inactivity threshold is current just 1 second. In this patch I only adopt AutomaticThread for ParallelHelperPool. I plan to adopt it in more places soon. * WTF.xcodeproj/project.pbxproj: * wtf/AutomaticThread.cpp: Added. (WTF::AutomaticThreadCondition::create): (WTF::AutomaticThreadCondition::AutomaticThreadCondition): (WTF::AutomaticThreadCondition::~AutomaticThreadCondition): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Added. * wtf/CMakeLists.txt: * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::ParallelHelperPool): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::helperThreadBody): Deleted. (WTF::ParallelHelperPool::waitForClientWithTask): Deleted. * wtf/ParallelHelperPool.h: Canonical link: https://commits.webkit.org/181393@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207480 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-18 20:17:10 +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.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
Use pragma once in WTF https://bugs.webkit.org/show_bug.cgi?id=190527 Reviewed by Chris Dumez. Source/WTF: We also need to consistently include wtf headers from within wtf so we can build wtf without symbol redefinition errors from including the copy in Source and the copy in the build directory. * wtf/ASCIICType.h: * wtf/Assertions.cpp: * wtf/Assertions.h: * wtf/Atomics.h: * wtf/AutomaticThread.cpp: * wtf/AutomaticThread.h: * wtf/BackwardsGraph.h: * wtf/Bag.h: * wtf/BagToHashMap.h: * wtf/BitVector.cpp: * wtf/BitVector.h: * wtf/Bitmap.h: * wtf/BloomFilter.h: * wtf/Box.h: * wtf/BubbleSort.h: * wtf/BumpPointerAllocator.h: * wtf/ByteOrder.h: * wtf/CPUTime.cpp: * wtf/CallbackAggregator.h: * wtf/CheckedArithmetic.h: * wtf/CheckedBoolean.h: * wtf/ClockType.cpp: * wtf/ClockType.h: * wtf/CommaPrinter.h: * wtf/CompilationThread.cpp: * wtf/CompilationThread.h: * wtf/Compiler.h: * wtf/ConcurrentPtrHashSet.cpp: * wtf/ConcurrentVector.h: * wtf/Condition.h: * wtf/CountingLock.cpp: * wtf/CrossThreadTaskHandler.cpp: * wtf/CryptographicUtilities.cpp: * wtf/CryptographicUtilities.h: * wtf/CryptographicallyRandomNumber.cpp: * wtf/CryptographicallyRandomNumber.h: * wtf/CurrentTime.cpp: * wtf/DataLog.cpp: * wtf/DataLog.h: * wtf/DateMath.cpp: * wtf/DateMath.h: * wtf/DecimalNumber.cpp: * wtf/DecimalNumber.h: * wtf/Deque.h: * wtf/DisallowCType.h: * wtf/Dominators.h: * wtf/DoublyLinkedList.h: * wtf/FastBitVector.cpp: * wtf/FastMalloc.cpp: * wtf/FastMalloc.h: * wtf/FeatureDefines.h: * wtf/FilePrintStream.cpp: * wtf/FilePrintStream.h: * wtf/FlipBytes.h: * wtf/FunctionDispatcher.cpp: * wtf/FunctionDispatcher.h: * wtf/GetPtr.h: * wtf/Gigacage.cpp: * wtf/GlobalVersion.cpp: * wtf/GraphNodeWorklist.h: * wtf/GregorianDateTime.cpp: * wtf/GregorianDateTime.h: * wtf/HashFunctions.h: * wtf/HashMap.h: * wtf/HashMethod.h: * wtf/HashSet.h: * wtf/HashTable.cpp: * wtf/HashTraits.h: * wtf/Indenter.h: * wtf/IndexSparseSet.h: * wtf/InlineASM.h: * wtf/Insertion.h: * wtf/IteratorAdaptors.h: * wtf/IteratorRange.h: * wtf/JSONValues.cpp: * wtf/JSValueMalloc.cpp: * wtf/LEBDecoder.h: * wtf/Language.cpp: * wtf/ListDump.h: * wtf/Lock.cpp: * wtf/Lock.h: * wtf/LockAlgorithm.h: * wtf/LockedPrintStream.cpp: * wtf/Locker.h: * wtf/MD5.cpp: * wtf/MD5.h: * wtf/MainThread.cpp: * wtf/MainThread.h: * wtf/MallocPtr.h: * wtf/MathExtras.h: * wtf/MediaTime.cpp: * wtf/MediaTime.h: * wtf/MemoryPressureHandler.cpp: * wtf/MessageQueue.h: * wtf/MetaAllocator.cpp: * wtf/MetaAllocator.h: * wtf/MetaAllocatorHandle.h: * wtf/MonotonicTime.cpp: * wtf/MonotonicTime.h: * wtf/NakedPtr.h: * wtf/NoLock.h: * wtf/NoTailCalls.h: * wtf/Noncopyable.h: * wtf/NumberOfCores.cpp: * wtf/NumberOfCores.h: * wtf/OSAllocator.h: * wtf/OSAllocatorPosix.cpp: * wtf/OSRandomSource.cpp: * wtf/OSRandomSource.h: * wtf/ObjcRuntimeExtras.h: * wtf/OrderMaker.h: * wtf/PackedIntVector.h: * wtf/PageAllocation.h: * wtf/PageBlock.cpp: * wtf/PageBlock.h: * wtf/PageReservation.h: * wtf/ParallelHelperPool.cpp: * wtf/ParallelHelperPool.h: * wtf/ParallelJobs.h: * wtf/ParallelJobsLibdispatch.h: * wtf/ParallelVectorIterator.h: * wtf/ParkingLot.cpp: * wtf/ParkingLot.h: * wtf/Platform.h: * wtf/PointerComparison.h: * wtf/Poisoned.cpp: * wtf/PrintStream.cpp: * wtf/PrintStream.h: * wtf/ProcessID.h: * wtf/ProcessPrivilege.cpp: * wtf/RAMSize.cpp: * wtf/RAMSize.h: * wtf/RandomDevice.cpp: * wtf/RandomNumber.cpp: * wtf/RandomNumber.h: * wtf/RandomNumberSeed.h: * wtf/RangeSet.h: * wtf/RawPointer.h: * wtf/ReadWriteLock.cpp: * wtf/RedBlackTree.h: * wtf/Ref.h: * wtf/RefCountedArray.h: * wtf/RefCountedLeakCounter.cpp: * wtf/RefCountedLeakCounter.h: * wtf/RefCounter.h: * wtf/RefPtr.h: * wtf/RetainPtr.h: * wtf/RunLoop.cpp: * wtf/RunLoop.h: * wtf/RunLoopTimer.h: * wtf/RunLoopTimerCF.cpp: * wtf/SHA1.cpp: * wtf/SHA1.h: * wtf/SaturatedArithmetic.h: (saturatedSubtraction): * wtf/SchedulePair.h: * wtf/SchedulePairCF.cpp: * wtf/SchedulePairMac.mm: * wtf/ScopedLambda.h: * wtf/Seconds.cpp: * wtf/Seconds.h: * wtf/SegmentedVector.h: * wtf/SentinelLinkedList.h: * wtf/SharedTask.h: * wtf/SimpleStats.h: * wtf/SingleRootGraph.h: * wtf/SinglyLinkedList.h: * wtf/SixCharacterHash.cpp: * wtf/SixCharacterHash.h: * wtf/SmallPtrSet.h: * wtf/Spectrum.h: * wtf/StackBounds.cpp: * wtf/StackBounds.h: * wtf/StackStats.cpp: * wtf/StackStats.h: * wtf/StackTrace.cpp: * wtf/StdLibExtras.h: * wtf/StreamBuffer.h: * wtf/StringHashDumpContext.h: * wtf/StringPrintStream.cpp: * wtf/StringPrintStream.h: * wtf/ThreadGroup.cpp: * wtf/ThreadMessage.cpp: * wtf/ThreadSpecific.h: * wtf/Threading.cpp: * wtf/Threading.h: * wtf/ThreadingPrimitives.h: * wtf/ThreadingPthreads.cpp: * wtf/TimeWithDynamicClockType.cpp: * wtf/TimeWithDynamicClockType.h: * wtf/TimingScope.cpp: * wtf/TinyLRUCache.h: * wtf/TinyPtrSet.h: * wtf/TriState.h: * wtf/TypeCasts.h: * wtf/UUID.cpp: * wtf/UnionFind.h: * wtf/VMTags.h: * wtf/ValueCheck.h: * wtf/Vector.h: * wtf/VectorTraits.h: * wtf/WallTime.cpp: * wtf/WallTime.h: * wtf/WeakPtr.h: * wtf/WeakRandom.h: * wtf/WordLock.cpp: * wtf/WordLock.h: * wtf/WorkQueue.cpp: * wtf/WorkQueue.h: * wtf/WorkerPool.cpp: * wtf/cf/LanguageCF.cpp: * wtf/cf/RunLoopCF.cpp: * wtf/cocoa/Entitlements.mm: * wtf/cocoa/MachSendRight.cpp: * wtf/cocoa/MainThreadCocoa.mm: * wtf/cocoa/MemoryFootprintCocoa.cpp: * wtf/cocoa/WorkQueueCocoa.cpp: * wtf/dtoa.cpp: * wtf/dtoa.h: * wtf/ios/WebCoreThread.cpp: * wtf/ios/WebCoreThread.h: * wtf/mac/AppKitCompatibilityDeclarations.h: * wtf/mac/DeprecatedSymbolsUsedBySafari.mm: * wtf/mbmalloc.cpp: * wtf/persistence/PersistentCoders.cpp: * wtf/persistence/PersistentDecoder.cpp: * wtf/persistence/PersistentEncoder.cpp: * wtf/spi/cf/CFBundleSPI.h: * wtf/spi/darwin/CommonCryptoSPI.h: * wtf/text/ASCIIFastPath.h: * wtf/text/ASCIILiteral.cpp: * wtf/text/AtomicString.cpp: * wtf/text/AtomicString.h: * wtf/text/AtomicStringHash.h: * wtf/text/AtomicStringImpl.cpp: * wtf/text/AtomicStringImpl.h: * wtf/text/AtomicStringTable.cpp: * wtf/text/AtomicStringTable.h: * wtf/text/Base64.cpp: * wtf/text/CString.cpp: * wtf/text/CString.h: * wtf/text/ConversionMode.h: * wtf/text/ExternalStringImpl.cpp: * wtf/text/IntegerToStringConversion.h: * wtf/text/LChar.h: * wtf/text/LineEnding.cpp: * wtf/text/StringBuffer.h: * wtf/text/StringBuilder.cpp: * wtf/text/StringBuilder.h: * wtf/text/StringBuilderJSON.cpp: * wtf/text/StringCommon.h: * wtf/text/StringConcatenate.h: * wtf/text/StringHash.h: * wtf/text/StringImpl.cpp: * wtf/text/StringImpl.h: * wtf/text/StringOperators.h: * wtf/text/StringView.cpp: * wtf/text/StringView.h: * wtf/text/SymbolImpl.cpp: * wtf/text/SymbolRegistry.cpp: * wtf/text/SymbolRegistry.h: * wtf/text/TextBreakIterator.cpp: * wtf/text/TextBreakIterator.h: * wtf/text/TextBreakIteratorInternalICU.h: * wtf/text/TextPosition.h: * wtf/text/TextStream.cpp: * wtf/text/UniquedStringImpl.h: * wtf/text/WTFString.cpp: * wtf/text/WTFString.h: * wtf/text/cocoa/StringCocoa.mm: * wtf/text/cocoa/StringViewCocoa.mm: * wtf/text/cocoa/TextBreakIteratorInternalICUCocoa.cpp: * wtf/text/icu/UTextProvider.cpp: * wtf/text/icu/UTextProvider.h: * wtf/text/icu/UTextProviderLatin1.cpp: * wtf/text/icu/UTextProviderLatin1.h: * wtf/text/icu/UTextProviderUTF16.cpp: * wtf/text/icu/UTextProviderUTF16.h: * wtf/threads/BinarySemaphore.cpp: * wtf/threads/BinarySemaphore.h: * wtf/threads/Signals.cpp: * wtf/unicode/CharacterNames.h: * wtf/unicode/Collator.h: * wtf/unicode/CollatorDefault.cpp: * wtf/unicode/UTF8.cpp: * wtf/unicode/UTF8.h: Tools: Put WorkQueue in namespace DRT so it does not conflict with WTF::WorkQueue. * DumpRenderTree/TestRunner.cpp: (TestRunner::queueLoadHTMLString): (TestRunner::queueLoadAlternateHTMLString): (TestRunner::queueBackNavigation): (TestRunner::queueForwardNavigation): (TestRunner::queueLoadingScript): (TestRunner::queueNonLoadingScript): (TestRunner::queueReload): * DumpRenderTree/WorkQueue.cpp: (WorkQueue::singleton): Deleted. (WorkQueue::WorkQueue): Deleted. (WorkQueue::queue): Deleted. (WorkQueue::dequeue): Deleted. (WorkQueue::count): Deleted. (WorkQueue::clear): Deleted. (WorkQueue::processWork): Deleted. * DumpRenderTree/WorkQueue.h: (WorkQueue::setFrozen): Deleted. * DumpRenderTree/WorkQueueItem.h: * DumpRenderTree/mac/DumpRenderTree.mm: (runTest): * DumpRenderTree/mac/FrameLoadDelegate.mm: (-[FrameLoadDelegate processWork:]): (-[FrameLoadDelegate webView:locationChangeDone:forDataSource:]): * DumpRenderTree/mac/TestRunnerMac.mm: (TestRunner::notifyDone): (TestRunner::forceImmediateCompletion): (TestRunner::queueLoad): * DumpRenderTree/win/DumpRenderTree.cpp: (runTest): * DumpRenderTree/win/FrameLoadDelegate.cpp: (FrameLoadDelegate::processWork): (FrameLoadDelegate::locationChangeDone): * DumpRenderTree/win/TestRunnerWin.cpp: (TestRunner::notifyDone): (TestRunner::forceImmediateCompletion): (TestRunner::queueLoad): Canonical link: https://commits.webkit.org/205473@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@237099 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-10-15 14:24:49 +00:00
#include <wtf/AutomaticThread.h>
WTF should make it easier to create threads that die automatically after inactivity https://bugs.webkit.org/show_bug.cgi?id=163576 Reviewed by Andreas Kling. Source/JavaScriptCore: Added a sleepSeconds() function, which made it easier for me to test this change. The WTF changes in this patch change how the JSC GC manages threads: the GC threads will now shut down automatically after 1 second of inactivity. Maybe this will save some memory. * jsc.cpp: (GlobalObject::finishCreation): (functionSleepSeconds): Source/WTF: For a long time now, I've been adding threads to WTF/JSC and each time I do this, I feel guilty because those threads don't shut down when they are inactive. For example, in bug 163562, I need to add a new GC thread. There will be one of them per VM. This means that a JSC API client that starts a lot of VMs will have a lot of threads. I don't think that's good. A common pattern for all of these threads is that they have some well-defined trigger that causes them to run. This trigger has a lock, a condition variable, some logic that determines if there is work to do, and then of course the logic for the thread's actual work. The thread bodies usually look like this: void Thingy::runThread() { for (;;) { Work work; { LockHolder locker(m_lock); while (!hasWork()) m_cond.wait(m_lock); work = takeWork(); } doWork(work); } } If you look at ParallelHelperPool (the GC's threads) and DFG::Worklist (some of the JIT's threads), you will see this pattern. This change adds a new kind of thread, called AutomaticThread, that lets you write threads to this pattern while getting automatic thread shutdown for free: instead of just waiting on a condition variable, AutomaticThread will have a timeout that causes the thread to die. The condition variable associated with AutomaticThread, called AutomaticThreadCondition, is smart enough to restart any threads that have decided to stop due to inactivity. The inactivity threshold is current just 1 second. In this patch I only adopt AutomaticThread for ParallelHelperPool. I plan to adopt it in more places soon. * WTF.xcodeproj/project.pbxproj: * wtf/AutomaticThread.cpp: Added. (WTF::AutomaticThreadCondition::create): (WTF::AutomaticThreadCondition::AutomaticThreadCondition): (WTF::AutomaticThreadCondition::~AutomaticThreadCondition): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Added. * wtf/CMakeLists.txt: * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::ParallelHelperPool): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::helperThreadBody): Deleted. (WTF::ParallelHelperPool::waitForClientWithTask): Deleted. * wtf/ParallelHelperPool.h: Canonical link: https://commits.webkit.org/181393@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207480 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-18 20:17:10 +00:00
Use pragma once in WTF https://bugs.webkit.org/show_bug.cgi?id=190527 Reviewed by Chris Dumez. Source/WTF: We also need to consistently include wtf headers from within wtf so we can build wtf without symbol redefinition errors from including the copy in Source and the copy in the build directory. * wtf/ASCIICType.h: * wtf/Assertions.cpp: * wtf/Assertions.h: * wtf/Atomics.h: * wtf/AutomaticThread.cpp: * wtf/AutomaticThread.h: * wtf/BackwardsGraph.h: * wtf/Bag.h: * wtf/BagToHashMap.h: * wtf/BitVector.cpp: * wtf/BitVector.h: * wtf/Bitmap.h: * wtf/BloomFilter.h: * wtf/Box.h: * wtf/BubbleSort.h: * wtf/BumpPointerAllocator.h: * wtf/ByteOrder.h: * wtf/CPUTime.cpp: * wtf/CallbackAggregator.h: * wtf/CheckedArithmetic.h: * wtf/CheckedBoolean.h: * wtf/ClockType.cpp: * wtf/ClockType.h: * wtf/CommaPrinter.h: * wtf/CompilationThread.cpp: * wtf/CompilationThread.h: * wtf/Compiler.h: * wtf/ConcurrentPtrHashSet.cpp: * wtf/ConcurrentVector.h: * wtf/Condition.h: * wtf/CountingLock.cpp: * wtf/CrossThreadTaskHandler.cpp: * wtf/CryptographicUtilities.cpp: * wtf/CryptographicUtilities.h: * wtf/CryptographicallyRandomNumber.cpp: * wtf/CryptographicallyRandomNumber.h: * wtf/CurrentTime.cpp: * wtf/DataLog.cpp: * wtf/DataLog.h: * wtf/DateMath.cpp: * wtf/DateMath.h: * wtf/DecimalNumber.cpp: * wtf/DecimalNumber.h: * wtf/Deque.h: * wtf/DisallowCType.h: * wtf/Dominators.h: * wtf/DoublyLinkedList.h: * wtf/FastBitVector.cpp: * wtf/FastMalloc.cpp: * wtf/FastMalloc.h: * wtf/FeatureDefines.h: * wtf/FilePrintStream.cpp: * wtf/FilePrintStream.h: * wtf/FlipBytes.h: * wtf/FunctionDispatcher.cpp: * wtf/FunctionDispatcher.h: * wtf/GetPtr.h: * wtf/Gigacage.cpp: * wtf/GlobalVersion.cpp: * wtf/GraphNodeWorklist.h: * wtf/GregorianDateTime.cpp: * wtf/GregorianDateTime.h: * wtf/HashFunctions.h: * wtf/HashMap.h: * wtf/HashMethod.h: * wtf/HashSet.h: * wtf/HashTable.cpp: * wtf/HashTraits.h: * wtf/Indenter.h: * wtf/IndexSparseSet.h: * wtf/InlineASM.h: * wtf/Insertion.h: * wtf/IteratorAdaptors.h: * wtf/IteratorRange.h: * wtf/JSONValues.cpp: * wtf/JSValueMalloc.cpp: * wtf/LEBDecoder.h: * wtf/Language.cpp: * wtf/ListDump.h: * wtf/Lock.cpp: * wtf/Lock.h: * wtf/LockAlgorithm.h: * wtf/LockedPrintStream.cpp: * wtf/Locker.h: * wtf/MD5.cpp: * wtf/MD5.h: * wtf/MainThread.cpp: * wtf/MainThread.h: * wtf/MallocPtr.h: * wtf/MathExtras.h: * wtf/MediaTime.cpp: * wtf/MediaTime.h: * wtf/MemoryPressureHandler.cpp: * wtf/MessageQueue.h: * wtf/MetaAllocator.cpp: * wtf/MetaAllocator.h: * wtf/MetaAllocatorHandle.h: * wtf/MonotonicTime.cpp: * wtf/MonotonicTime.h: * wtf/NakedPtr.h: * wtf/NoLock.h: * wtf/NoTailCalls.h: * wtf/Noncopyable.h: * wtf/NumberOfCores.cpp: * wtf/NumberOfCores.h: * wtf/OSAllocator.h: * wtf/OSAllocatorPosix.cpp: * wtf/OSRandomSource.cpp: * wtf/OSRandomSource.h: * wtf/ObjcRuntimeExtras.h: * wtf/OrderMaker.h: * wtf/PackedIntVector.h: * wtf/PageAllocation.h: * wtf/PageBlock.cpp: * wtf/PageBlock.h: * wtf/PageReservation.h: * wtf/ParallelHelperPool.cpp: * wtf/ParallelHelperPool.h: * wtf/ParallelJobs.h: * wtf/ParallelJobsLibdispatch.h: * wtf/ParallelVectorIterator.h: * wtf/ParkingLot.cpp: * wtf/ParkingLot.h: * wtf/Platform.h: * wtf/PointerComparison.h: * wtf/Poisoned.cpp: * wtf/PrintStream.cpp: * wtf/PrintStream.h: * wtf/ProcessID.h: * wtf/ProcessPrivilege.cpp: * wtf/RAMSize.cpp: * wtf/RAMSize.h: * wtf/RandomDevice.cpp: * wtf/RandomNumber.cpp: * wtf/RandomNumber.h: * wtf/RandomNumberSeed.h: * wtf/RangeSet.h: * wtf/RawPointer.h: * wtf/ReadWriteLock.cpp: * wtf/RedBlackTree.h: * wtf/Ref.h: * wtf/RefCountedArray.h: * wtf/RefCountedLeakCounter.cpp: * wtf/RefCountedLeakCounter.h: * wtf/RefCounter.h: * wtf/RefPtr.h: * wtf/RetainPtr.h: * wtf/RunLoop.cpp: * wtf/RunLoop.h: * wtf/RunLoopTimer.h: * wtf/RunLoopTimerCF.cpp: * wtf/SHA1.cpp: * wtf/SHA1.h: * wtf/SaturatedArithmetic.h: (saturatedSubtraction): * wtf/SchedulePair.h: * wtf/SchedulePairCF.cpp: * wtf/SchedulePairMac.mm: * wtf/ScopedLambda.h: * wtf/Seconds.cpp: * wtf/Seconds.h: * wtf/SegmentedVector.h: * wtf/SentinelLinkedList.h: * wtf/SharedTask.h: * wtf/SimpleStats.h: * wtf/SingleRootGraph.h: * wtf/SinglyLinkedList.h: * wtf/SixCharacterHash.cpp: * wtf/SixCharacterHash.h: * wtf/SmallPtrSet.h: * wtf/Spectrum.h: * wtf/StackBounds.cpp: * wtf/StackBounds.h: * wtf/StackStats.cpp: * wtf/StackStats.h: * wtf/StackTrace.cpp: * wtf/StdLibExtras.h: * wtf/StreamBuffer.h: * wtf/StringHashDumpContext.h: * wtf/StringPrintStream.cpp: * wtf/StringPrintStream.h: * wtf/ThreadGroup.cpp: * wtf/ThreadMessage.cpp: * wtf/ThreadSpecific.h: * wtf/Threading.cpp: * wtf/Threading.h: * wtf/ThreadingPrimitives.h: * wtf/ThreadingPthreads.cpp: * wtf/TimeWithDynamicClockType.cpp: * wtf/TimeWithDynamicClockType.h: * wtf/TimingScope.cpp: * wtf/TinyLRUCache.h: * wtf/TinyPtrSet.h: * wtf/TriState.h: * wtf/TypeCasts.h: * wtf/UUID.cpp: * wtf/UnionFind.h: * wtf/VMTags.h: * wtf/ValueCheck.h: * wtf/Vector.h: * wtf/VectorTraits.h: * wtf/WallTime.cpp: * wtf/WallTime.h: * wtf/WeakPtr.h: * wtf/WeakRandom.h: * wtf/WordLock.cpp: * wtf/WordLock.h: * wtf/WorkQueue.cpp: * wtf/WorkQueue.h: * wtf/WorkerPool.cpp: * wtf/cf/LanguageCF.cpp: * wtf/cf/RunLoopCF.cpp: * wtf/cocoa/Entitlements.mm: * wtf/cocoa/MachSendRight.cpp: * wtf/cocoa/MainThreadCocoa.mm: * wtf/cocoa/MemoryFootprintCocoa.cpp: * wtf/cocoa/WorkQueueCocoa.cpp: * wtf/dtoa.cpp: * wtf/dtoa.h: * wtf/ios/WebCoreThread.cpp: * wtf/ios/WebCoreThread.h: * wtf/mac/AppKitCompatibilityDeclarations.h: * wtf/mac/DeprecatedSymbolsUsedBySafari.mm: * wtf/mbmalloc.cpp: * wtf/persistence/PersistentCoders.cpp: * wtf/persistence/PersistentDecoder.cpp: * wtf/persistence/PersistentEncoder.cpp: * wtf/spi/cf/CFBundleSPI.h: * wtf/spi/darwin/CommonCryptoSPI.h: * wtf/text/ASCIIFastPath.h: * wtf/text/ASCIILiteral.cpp: * wtf/text/AtomicString.cpp: * wtf/text/AtomicString.h: * wtf/text/AtomicStringHash.h: * wtf/text/AtomicStringImpl.cpp: * wtf/text/AtomicStringImpl.h: * wtf/text/AtomicStringTable.cpp: * wtf/text/AtomicStringTable.h: * wtf/text/Base64.cpp: * wtf/text/CString.cpp: * wtf/text/CString.h: * wtf/text/ConversionMode.h: * wtf/text/ExternalStringImpl.cpp: * wtf/text/IntegerToStringConversion.h: * wtf/text/LChar.h: * wtf/text/LineEnding.cpp: * wtf/text/StringBuffer.h: * wtf/text/StringBuilder.cpp: * wtf/text/StringBuilder.h: * wtf/text/StringBuilderJSON.cpp: * wtf/text/StringCommon.h: * wtf/text/StringConcatenate.h: * wtf/text/StringHash.h: * wtf/text/StringImpl.cpp: * wtf/text/StringImpl.h: * wtf/text/StringOperators.h: * wtf/text/StringView.cpp: * wtf/text/StringView.h: * wtf/text/SymbolImpl.cpp: * wtf/text/SymbolRegistry.cpp: * wtf/text/SymbolRegistry.h: * wtf/text/TextBreakIterator.cpp: * wtf/text/TextBreakIterator.h: * wtf/text/TextBreakIteratorInternalICU.h: * wtf/text/TextPosition.h: * wtf/text/TextStream.cpp: * wtf/text/UniquedStringImpl.h: * wtf/text/WTFString.cpp: * wtf/text/WTFString.h: * wtf/text/cocoa/StringCocoa.mm: * wtf/text/cocoa/StringViewCocoa.mm: * wtf/text/cocoa/TextBreakIteratorInternalICUCocoa.cpp: * wtf/text/icu/UTextProvider.cpp: * wtf/text/icu/UTextProvider.h: * wtf/text/icu/UTextProviderLatin1.cpp: * wtf/text/icu/UTextProviderLatin1.h: * wtf/text/icu/UTextProviderUTF16.cpp: * wtf/text/icu/UTextProviderUTF16.h: * wtf/threads/BinarySemaphore.cpp: * wtf/threads/BinarySemaphore.h: * wtf/threads/Signals.cpp: * wtf/unicode/CharacterNames.h: * wtf/unicode/Collator.h: * wtf/unicode/CollatorDefault.cpp: * wtf/unicode/UTF8.cpp: * wtf/unicode/UTF8.h: Tools: Put WorkQueue in namespace DRT so it does not conflict with WTF::WorkQueue. * DumpRenderTree/TestRunner.cpp: (TestRunner::queueLoadHTMLString): (TestRunner::queueLoadAlternateHTMLString): (TestRunner::queueBackNavigation): (TestRunner::queueForwardNavigation): (TestRunner::queueLoadingScript): (TestRunner::queueNonLoadingScript): (TestRunner::queueReload): * DumpRenderTree/WorkQueue.cpp: (WorkQueue::singleton): Deleted. (WorkQueue::WorkQueue): Deleted. (WorkQueue::queue): Deleted. (WorkQueue::dequeue): Deleted. (WorkQueue::count): Deleted. (WorkQueue::clear): Deleted. (WorkQueue::processWork): Deleted. * DumpRenderTree/WorkQueue.h: (WorkQueue::setFrozen): Deleted. * DumpRenderTree/WorkQueueItem.h: * DumpRenderTree/mac/DumpRenderTree.mm: (runTest): * DumpRenderTree/mac/FrameLoadDelegate.mm: (-[FrameLoadDelegate processWork:]): (-[FrameLoadDelegate webView:locationChangeDone:forDataSource:]): * DumpRenderTree/mac/TestRunnerMac.mm: (TestRunner::notifyDone): (TestRunner::forceImmediateCompletion): (TestRunner::queueLoad): * DumpRenderTree/win/DumpRenderTree.cpp: (runTest): * DumpRenderTree/win/FrameLoadDelegate.cpp: (FrameLoadDelegate::processWork): (FrameLoadDelegate::locationChangeDone): * DumpRenderTree/win/TestRunnerWin.cpp: (TestRunner::notifyDone): (TestRunner::forceImmediateCompletion): (TestRunner::queueLoad): Canonical link: https://commits.webkit.org/205473@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@237099 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-10-15 14:24:49 +00:00
#include <wtf/DataLog.h>
#include <wtf/Threading.h>
WTF should make it easier to create threads that die automatically after inactivity https://bugs.webkit.org/show_bug.cgi?id=163576 Reviewed by Andreas Kling. Source/JavaScriptCore: Added a sleepSeconds() function, which made it easier for me to test this change. The WTF changes in this patch change how the JSC GC manages threads: the GC threads will now shut down automatically after 1 second of inactivity. Maybe this will save some memory. * jsc.cpp: (GlobalObject::finishCreation): (functionSleepSeconds): Source/WTF: For a long time now, I've been adding threads to WTF/JSC and each time I do this, I feel guilty because those threads don't shut down when they are inactive. For example, in bug 163562, I need to add a new GC thread. There will be one of them per VM. This means that a JSC API client that starts a lot of VMs will have a lot of threads. I don't think that's good. A common pattern for all of these threads is that they have some well-defined trigger that causes them to run. This trigger has a lock, a condition variable, some logic that determines if there is work to do, and then of course the logic for the thread's actual work. The thread bodies usually look like this: void Thingy::runThread() { for (;;) { Work work; { LockHolder locker(m_lock); while (!hasWork()) m_cond.wait(m_lock); work = takeWork(); } doWork(work); } } If you look at ParallelHelperPool (the GC's threads) and DFG::Worklist (some of the JIT's threads), you will see this pattern. This change adds a new kind of thread, called AutomaticThread, that lets you write threads to this pattern while getting automatic thread shutdown for free: instead of just waiting on a condition variable, AutomaticThread will have a timeout that causes the thread to die. The condition variable associated with AutomaticThread, called AutomaticThreadCondition, is smart enough to restart any threads that have decided to stop due to inactivity. The inactivity threshold is current just 1 second. In this patch I only adopt AutomaticThread for ParallelHelperPool. I plan to adopt it in more places soon. * WTF.xcodeproj/project.pbxproj: * wtf/AutomaticThread.cpp: Added. (WTF::AutomaticThreadCondition::create): (WTF::AutomaticThreadCondition::AutomaticThreadCondition): (WTF::AutomaticThreadCondition::~AutomaticThreadCondition): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Added. * wtf/CMakeLists.txt: * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::ParallelHelperPool): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::helperThreadBody): Deleted. (WTF::ParallelHelperPool::waitForClientWithTask): Deleted. * wtf/ParallelHelperPool.h: Canonical link: https://commits.webkit.org/181393@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207480 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-18 20:17:10 +00:00
namespace WTF {
Use constexpr instead of const in symbol definitions that are obviously constexpr. https://bugs.webkit.org/show_bug.cgi?id=201879 Rubber-stamped by Joseph Pecoraro. Source/bmalloc: * bmalloc/AvailableMemory.cpp: * bmalloc/IsoTLS.h: * bmalloc/Map.h: * bmalloc/Mutex.cpp: (bmalloc::Mutex::lockSlowCase): * bmalloc/PerThread.h: * bmalloc/Vector.h: * bmalloc/Zone.h: Source/JavaScriptCore: const may require external storage (at the compiler's whim) though these currently do not. constexpr makes it clear that the value is a literal constant that can be inlined. In most cases in the code, when we say static const, we actually mean static constexpr. I'm changing the code to reflect this. * API/JSAPIValueWrapper.h: * API/JSCallbackConstructor.h: * API/JSCallbackObject.h: * API/JSContextRef.cpp: * API/JSWrapperMap.mm: * API/tests/CompareAndSwapTest.cpp: * API/tests/TypedArrayCTest.cpp: * API/tests/testapi.mm: (testObjectiveCAPIMain): * KeywordLookupGenerator.py: (Trie.printAsC): * assembler/ARMv7Assembler.h: * assembler/AssemblerBuffer.h: * assembler/AssemblerCommon.h: * assembler/MacroAssembler.h: * assembler/MacroAssemblerARM64.h: * assembler/MacroAssemblerARM64E.h: * assembler/MacroAssemblerARMv7.h: * assembler/MacroAssemblerCodeRef.h: * assembler/MacroAssemblerMIPS.h: * assembler/MacroAssemblerX86.h: * assembler/MacroAssemblerX86Common.h: (JSC::MacroAssemblerX86Common::absDouble): (JSC::MacroAssemblerX86Common::negateDouble): * assembler/MacroAssemblerX86_64.h: * assembler/X86Assembler.h: * b3/B3Bank.h: * b3/B3CheckSpecial.h: * b3/B3DuplicateTails.cpp: * b3/B3EliminateCommonSubexpressions.cpp: * b3/B3FixSSA.cpp: * b3/B3FoldPathConstants.cpp: * b3/B3InferSwitches.cpp: * b3/B3Kind.h: * b3/B3LowerToAir.cpp: * b3/B3NativeTraits.h: * b3/B3ReduceDoubleToFloat.cpp: * b3/B3ReduceLoopStrength.cpp: * b3/B3ReduceStrength.cpp: * b3/B3ValueKey.h: * b3/air/AirAllocateRegistersByGraphColoring.cpp: * b3/air/AirAllocateStackByGraphColoring.cpp: * b3/air/AirArg.h: * b3/air/AirCCallSpecial.h: * b3/air/AirEmitShuffle.cpp: * b3/air/AirFixObviousSpills.cpp: * b3/air/AirFormTable.h: * b3/air/AirLowerAfterRegAlloc.cpp: * b3/air/AirPrintSpecial.h: * b3/air/AirStackAllocation.cpp: * b3/air/AirTmp.h: * b3/testb3_6.cpp: (testInterpreter): * bytecode/AccessCase.cpp: * bytecode/CallLinkStatus.cpp: * bytecode/CallVariant.h: * bytecode/CodeBlock.h: * bytecode/CodeOrigin.h: * bytecode/DFGExitProfile.h: * bytecode/DirectEvalCodeCache.h: * bytecode/ExecutableToCodeBlockEdge.h: * bytecode/GetterSetterAccessCase.cpp: * bytecode/LazyOperandValueProfile.h: * bytecode/ObjectPropertyCondition.h: * bytecode/ObjectPropertyConditionSet.cpp: * bytecode/PolymorphicAccess.cpp: * bytecode/PropertyCondition.h: * bytecode/SpeculatedType.h: * bytecode/StructureStubInfo.cpp: * bytecode/UnlinkedCodeBlock.cpp: (JSC::UnlinkedCodeBlock::typeProfilerExpressionInfoForBytecodeOffset): * bytecode/UnlinkedCodeBlock.h: * bytecode/UnlinkedEvalCodeBlock.h: * bytecode/UnlinkedFunctionCodeBlock.h: * bytecode/UnlinkedFunctionExecutable.h: * bytecode/UnlinkedModuleProgramCodeBlock.h: * bytecode/UnlinkedProgramCodeBlock.h: * bytecode/ValueProfile.h: * bytecode/VirtualRegister.h: * bytecode/Watchpoint.h: * bytecompiler/BytecodeGenerator.h: * bytecompiler/Label.h: * bytecompiler/NodesCodegen.cpp: (JSC::ThisNode::emitBytecode): * bytecompiler/RegisterID.h: * debugger/Breakpoint.h: * debugger/DebuggerParseData.cpp: * debugger/DebuggerPrimitives.h: * debugger/DebuggerScope.h: * dfg/DFGAbstractHeap.h: * dfg/DFGAbstractValue.h: * dfg/DFGArgumentsEliminationPhase.cpp: * dfg/DFGByteCodeParser.cpp: * dfg/DFGCSEPhase.cpp: * dfg/DFGCommon.h: * dfg/DFGCompilationKey.h: * dfg/DFGDesiredGlobalProperty.h: * dfg/DFGEdgeDominates.h: * dfg/DFGEpoch.h: * dfg/DFGForAllKills.h: (JSC::DFG::forAllKilledNodesAtNodeIndex): * dfg/DFGGraph.cpp: (JSC::DFG::Graph::isLiveInBytecode): * dfg/DFGHeapLocation.h: * dfg/DFGInPlaceAbstractState.cpp: * dfg/DFGIntegerCheckCombiningPhase.cpp: * dfg/DFGIntegerRangeOptimizationPhase.cpp: * dfg/DFGInvalidationPointInjectionPhase.cpp: * dfg/DFGLICMPhase.cpp: * dfg/DFGLazyNode.h: * dfg/DFGMinifiedID.h: * dfg/DFGMovHintRemovalPhase.cpp: * dfg/DFGNodeFlowProjection.h: * dfg/DFGNodeType.h: * dfg/DFGObjectAllocationSinkingPhase.cpp: * dfg/DFGPhantomInsertionPhase.cpp: * dfg/DFGPromotedHeapLocation.h: * dfg/DFGPropertyTypeKey.h: * dfg/DFGPureValue.h: * dfg/DFGPutStackSinkingPhase.cpp: * dfg/DFGRegisterBank.h: * dfg/DFGSSAConversionPhase.cpp: * dfg/DFGSSALoweringPhase.cpp: * dfg/DFGSpeculativeJIT.cpp: (JSC::DFG::SpeculativeJIT::compileDoubleRep): (JSC::DFG::compileClampDoubleToByte): (JSC::DFG::SpeculativeJIT::compileArithRounding): (JSC::DFG::compileArithPowIntegerFastPath): (JSC::DFG::SpeculativeJIT::compileArithPow): (JSC::DFG::SpeculativeJIT::emitBinarySwitchStringRecurse): * dfg/DFGStackLayoutPhase.cpp: * dfg/DFGStoreBarrierInsertionPhase.cpp: * dfg/DFGStrengthReductionPhase.cpp: * dfg/DFGStructureAbstractValue.h: * dfg/DFGVarargsForwardingPhase.cpp: * dfg/DFGVariableEventStream.cpp: (JSC::DFG::VariableEventStream::reconstruct const): * dfg/DFGWatchpointCollectionPhase.cpp: * disassembler/ARM64/A64DOpcode.h: * ftl/FTLLocation.h: * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::compileArithRandom): * ftl/FTLSlowPathCall.cpp: * ftl/FTLSlowPathCallKey.h: * heap/CellContainer.h: * heap/CellState.h: * heap/ConservativeRoots.h: * heap/GCSegmentedArray.h: * heap/HandleBlock.h: * heap/Heap.cpp: (JSC::Heap::updateAllocationLimits): * heap/Heap.h: * heap/HeapSnapshot.h: * heap/HeapUtil.h: (JSC::HeapUtil::findGCObjectPointersForMarking): * heap/IncrementalSweeper.cpp: * heap/LargeAllocation.h: * heap/MarkedBlock.cpp: * heap/Strong.h: * heap/VisitRaceKey.h: * heap/Weak.h: * heap/WeakBlock.h: * inspector/JSInjectedScriptHost.h: * inspector/JSInjectedScriptHostPrototype.h: * inspector/JSJavaScriptCallFrame.h: * inspector/JSJavaScriptCallFramePrototype.h: * inspector/agents/InspectorConsoleAgent.cpp: * inspector/agents/InspectorRuntimeAgent.cpp: (Inspector::InspectorRuntimeAgent::getRuntimeTypesForVariablesAtOffsets): * inspector/scripts/codegen/generate_cpp_protocol_types_header.py: (CppProtocolTypesHeaderGenerator._generate_versions): * inspector/scripts/tests/generic/expected/version.json-result: * interpreter/Interpreter.h: * interpreter/ShadowChicken.cpp: * jit/BinarySwitch.cpp: * jit/CallFrameShuffler.h: * jit/ExecutableAllocator.h: * jit/FPRInfo.h: * jit/GPRInfo.h: * jit/ICStats.h: * jit/JITThunks.h: * jit/Reg.h: * jit/RegisterSet.h: * jit/TempRegisterSet.h: * jsc.cpp: * parser/ASTBuilder.h: * parser/Nodes.h: * parser/SourceCodeKey.h: * parser/SyntaxChecker.h: * parser/VariableEnvironment.h: * profiler/ProfilerOrigin.h: * profiler/ProfilerOriginStack.h: * profiler/ProfilerUID.h: * runtime/AbstractModuleRecord.cpp: * runtime/ArrayBufferNeuteringWatchpointSet.h: * runtime/ArrayConstructor.h: * runtime/ArrayConventions.h: * runtime/ArrayIteratorPrototype.h: * runtime/ArrayPrototype.cpp: (JSC::setLength): * runtime/AsyncFromSyncIteratorPrototype.h: * runtime/AsyncGeneratorFunctionPrototype.h: * runtime/AsyncGeneratorPrototype.h: * runtime/AsyncIteratorPrototype.h: * runtime/AtomicsObject.cpp: * runtime/BigIntConstructor.h: * runtime/BigIntPrototype.h: * runtime/BooleanPrototype.h: * runtime/ClonedArguments.h: * runtime/CodeCache.h: * runtime/ControlFlowProfiler.h: * runtime/CustomGetterSetter.h: * runtime/DateConstructor.h: * runtime/DatePrototype.h: * runtime/DefinePropertyAttributes.h: * runtime/ErrorPrototype.h: * runtime/EvalExecutable.h: * runtime/Exception.h: * runtime/ExceptionHelpers.cpp: (JSC::invalidParameterInSourceAppender): (JSC::invalidParameterInstanceofSourceAppender): * runtime/ExceptionHelpers.h: * runtime/ExecutableBase.h: * runtime/FunctionExecutable.h: * runtime/FunctionRareData.h: * runtime/GeneratorPrototype.h: * runtime/GenericArguments.h: * runtime/GenericOffset.h: * runtime/GetPutInfo.h: * runtime/GetterSetter.h: * runtime/GlobalExecutable.h: * runtime/Identifier.h: * runtime/InspectorInstrumentationObject.h: * runtime/InternalFunction.h: * runtime/IntlCollatorConstructor.h: * runtime/IntlCollatorPrototype.h: * runtime/IntlDateTimeFormatConstructor.h: * runtime/IntlDateTimeFormatPrototype.h: * runtime/IntlNumberFormatConstructor.h: * runtime/IntlNumberFormatPrototype.h: * runtime/IntlObject.h: * runtime/IntlPluralRulesConstructor.h: * runtime/IntlPluralRulesPrototype.h: * runtime/IteratorPrototype.h: * runtime/JSArray.cpp: (JSC::JSArray::tryCreateUninitializedRestricted): * runtime/JSArray.h: * runtime/JSArrayBuffer.h: * runtime/JSArrayBufferView.h: * runtime/JSBigInt.h: * runtime/JSCJSValue.h: * runtime/JSCell.h: * runtime/JSCustomGetterSetterFunction.h: * runtime/JSDataView.h: * runtime/JSDataViewPrototype.h: * runtime/JSDestructibleObject.h: * runtime/JSFixedArray.h: * runtime/JSGenericTypedArrayView.h: * runtime/JSGlobalLexicalEnvironment.h: * runtime/JSGlobalObject.h: * runtime/JSImmutableButterfly.h: * runtime/JSInternalPromiseConstructor.h: * runtime/JSInternalPromiseDeferred.h: * runtime/JSInternalPromisePrototype.h: * runtime/JSLexicalEnvironment.h: * runtime/JSModuleEnvironment.h: * runtime/JSModuleLoader.h: * runtime/JSModuleNamespaceObject.h: * runtime/JSNonDestructibleProxy.h: * runtime/JSONObject.cpp: * runtime/JSONObject.h: * runtime/JSObject.h: * runtime/JSPromiseConstructor.h: * runtime/JSPromiseDeferred.h: * runtime/JSPromisePrototype.h: * runtime/JSPropertyNameEnumerator.h: * runtime/JSProxy.h: * runtime/JSScope.h: * runtime/JSScriptFetchParameters.h: * runtime/JSScriptFetcher.h: * runtime/JSSegmentedVariableObject.h: * runtime/JSSourceCode.h: * runtime/JSString.cpp: * runtime/JSString.h: * runtime/JSSymbolTableObject.h: * runtime/JSTemplateObjectDescriptor.h: * runtime/JSTypeInfo.h: * runtime/MapPrototype.h: * runtime/MinimumReservedZoneSize.h: * runtime/ModuleProgramExecutable.h: * runtime/NativeExecutable.h: * runtime/NativeFunction.h: * runtime/NativeStdFunctionCell.h: * runtime/NumberConstructor.h: * runtime/NumberPrototype.h: * runtime/ObjectConstructor.h: * runtime/ObjectPrototype.h: * runtime/ProgramExecutable.h: * runtime/PromiseDeferredTimer.cpp: * runtime/PropertyMapHashTable.h: * runtime/PropertyNameArray.h: (JSC::PropertyNameArray::add): * runtime/PrototypeKey.h: * runtime/ProxyConstructor.h: * runtime/ProxyObject.cpp: (JSC::ProxyObject::performGetOwnPropertyNames): * runtime/ProxyRevoke.h: * runtime/ReflectObject.h: * runtime/RegExp.h: * runtime/RegExpCache.h: * runtime/RegExpConstructor.h: * runtime/RegExpKey.h: * runtime/RegExpObject.h: * runtime/RegExpPrototype.h: * runtime/RegExpStringIteratorPrototype.h: * runtime/SamplingProfiler.cpp: * runtime/ScopedArgumentsTable.h: * runtime/ScriptExecutable.h: * runtime/SetPrototype.h: * runtime/SmallStrings.h: * runtime/SparseArrayValueMap.h: * runtime/StringConstructor.h: * runtime/StringIteratorPrototype.h: * runtime/StringObject.h: * runtime/StringPrototype.h: * runtime/Structure.h: * runtime/StructureChain.h: * runtime/StructureRareData.h: * runtime/StructureTransitionTable.h: * runtime/Symbol.h: * runtime/SymbolConstructor.h: * runtime/SymbolPrototype.h: * runtime/SymbolTable.h: * runtime/TemplateObjectDescriptor.h: * runtime/TypeProfiler.cpp: * runtime/TypeProfiler.h: * runtime/TypeProfilerLog.cpp: * runtime/VarOffset.h: * testRegExp.cpp: * tools/HeapVerifier.cpp: (JSC::HeapVerifier::checkIfRecorded): * tools/JSDollarVM.cpp: * wasm/WasmB3IRGenerator.cpp: * wasm/WasmBBQPlan.cpp: * wasm/WasmFaultSignalHandler.cpp: * wasm/WasmFunctionParser.h: * wasm/WasmOMGForOSREntryPlan.cpp: * wasm/WasmOMGPlan.cpp: * wasm/WasmPlan.cpp: * wasm/WasmSignature.cpp: * wasm/WasmSignature.h: * wasm/WasmWorklist.cpp: * wasm/js/JSWebAssembly.h: * wasm/js/JSWebAssemblyCodeBlock.h: * wasm/js/WebAssemblyCompileErrorConstructor.h: * wasm/js/WebAssemblyCompileErrorPrototype.h: * wasm/js/WebAssemblyFunction.h: * wasm/js/WebAssemblyInstanceConstructor.h: * wasm/js/WebAssemblyInstancePrototype.h: * wasm/js/WebAssemblyLinkErrorConstructor.h: * wasm/js/WebAssemblyLinkErrorPrototype.h: * wasm/js/WebAssemblyMemoryConstructor.h: * wasm/js/WebAssemblyMemoryPrototype.h: * wasm/js/WebAssemblyModuleConstructor.h: * wasm/js/WebAssemblyModulePrototype.h: * wasm/js/WebAssemblyRuntimeErrorConstructor.h: * wasm/js/WebAssemblyRuntimeErrorPrototype.h: * wasm/js/WebAssemblyTableConstructor.h: * wasm/js/WebAssemblyTablePrototype.h: * wasm/js/WebAssemblyToJSCallee.h: * yarr/Yarr.h: * yarr/YarrParser.h: * yarr/generateYarrCanonicalizeUnicode: Source/WebCore: No new tests. Covered by existing tests. * bindings/js/JSDOMConstructorBase.h: * bindings/js/JSDOMWindowProperties.h: * bindings/scripts/CodeGeneratorJS.pm: (GenerateHeader): (GeneratePrototypeDeclaration): * bindings/scripts/test/JS/JSTestActiveDOMObject.h: * bindings/scripts/test/JS/JSTestEnabledBySetting.h: * bindings/scripts/test/JS/JSTestEnabledForContext.h: * bindings/scripts/test/JS/JSTestEventTarget.h: * bindings/scripts/test/JS/JSTestGlobalObject.h: * bindings/scripts/test/JS/JSTestIndexedSetterNoIdentifier.h: * bindings/scripts/test/JS/JSTestIndexedSetterThrowingException.h: * bindings/scripts/test/JS/JSTestIndexedSetterWithIdentifier.h: * bindings/scripts/test/JS/JSTestNamedAndIndexedSetterNoIdentifier.h: * bindings/scripts/test/JS/JSTestNamedAndIndexedSetterThrowingException.h: * bindings/scripts/test/JS/JSTestNamedAndIndexedSetterWithIdentifier.h: * bindings/scripts/test/JS/JSTestNamedDeleterNoIdentifier.h: * bindings/scripts/test/JS/JSTestNamedDeleterThrowingException.h: * bindings/scripts/test/JS/JSTestNamedDeleterWithIdentifier.h: * bindings/scripts/test/JS/JSTestNamedDeleterWithIndexedGetter.h: * bindings/scripts/test/JS/JSTestNamedGetterCallWith.h: * bindings/scripts/test/JS/JSTestNamedGetterNoIdentifier.h: * bindings/scripts/test/JS/JSTestNamedGetterWithIdentifier.h: * bindings/scripts/test/JS/JSTestNamedSetterNoIdentifier.h: * bindings/scripts/test/JS/JSTestNamedSetterThrowingException.h: * bindings/scripts/test/JS/JSTestNamedSetterWithIdentifier.h: * bindings/scripts/test/JS/JSTestNamedSetterWithIndexedGetter.h: * bindings/scripts/test/JS/JSTestNamedSetterWithIndexedGetterAndSetter.h: * bindings/scripts/test/JS/JSTestNamedSetterWithOverrideBuiltins.h: * bindings/scripts/test/JS/JSTestNamedSetterWithUnforgableProperties.h: * bindings/scripts/test/JS/JSTestNamedSetterWithUnforgablePropertiesAndOverrideBuiltins.h: * bindings/scripts/test/JS/JSTestObj.h: * bindings/scripts/test/JS/JSTestOverrideBuiltins.h: * bindings/scripts/test/JS/JSTestPluginInterface.h: * bindings/scripts/test/JS/JSTestTypedefs.h: * bridge/objc/objc_runtime.h: * bridge/runtime_array.h: * bridge/runtime_method.h: * bridge/runtime_object.h: Source/WebKit: * WebProcess/Plugins/Netscape/JSNPObject.h: Source/WTF: * wtf/Assertions.cpp: * wtf/AutomaticThread.cpp: * wtf/BitVector.h: * wtf/Bitmap.h: * wtf/BloomFilter.h: * wtf/Brigand.h: * wtf/CheckedArithmetic.h: * wtf/CrossThreadCopier.h: * wtf/CurrentTime.cpp: * wtf/DataLog.cpp: * wtf/DateMath.cpp: (WTF::daysFrom1970ToYear): * wtf/DeferrableRefCounted.h: * wtf/GetPtr.h: * wtf/HashFunctions.h: * wtf/HashMap.h: * wtf/HashTable.h: * wtf/HashTraits.h: * wtf/JSONValues.cpp: * wtf/JSONValues.h: * wtf/ListHashSet.h: * wtf/Lock.h: * wtf/LockAlgorithm.h: * wtf/LockAlgorithmInlines.h: (WTF::Hooks>::lockSlow): * wtf/Logger.h: * wtf/LoggerHelper.h: (WTF::LoggerHelper::childLogIdentifier const): * wtf/MainThread.cpp: * wtf/MetaAllocatorPtr.h: * wtf/MonotonicTime.h: * wtf/NaturalLoops.h: (WTF::NaturalLoops::NaturalLoops): * wtf/ObjectIdentifier.h: * wtf/RAMSize.cpp: * wtf/Ref.h: * wtf/RefPtr.h: * wtf/RetainPtr.h: * wtf/SchedulePair.h: * wtf/StackShot.h: * wtf/StdLibExtras.h: * wtf/TinyPtrSet.h: * wtf/URL.cpp: * wtf/URLHash.h: * wtf/URLParser.cpp: (WTF::URLParser::defaultPortForProtocol): * wtf/Vector.h: * wtf/VectorTraits.h: * wtf/WallTime.h: * wtf/WeakHashSet.h: * wtf/WordLock.h: * wtf/cocoa/CPUTimeCocoa.cpp: * wtf/cocoa/MemoryPressureHandlerCocoa.mm: * wtf/persistence/PersistentDecoder.h: * wtf/persistence/PersistentEncoder.h: * wtf/text/AtomStringHash.h: * wtf/text/CString.h: * wtf/text/StringBuilder.cpp: (WTF::expandedCapacity): * wtf/text/StringHash.h: * wtf/text/StringImpl.h: * wtf/text/StringToIntegerConversion.h: (WTF::toIntegralType): * wtf/text/SymbolRegistry.h: * wtf/text/TextStream.cpp: (WTF::hasFractions): * wtf/text/WTFString.h: * wtf/text/cocoa/TextBreakIteratorInternalICUCocoa.cpp: Canonical link: https://commits.webkit.org/215538@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@250005 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-09-18 00:36:19 +00:00
static constexpr bool verbose = false;
WTF should make it easier to create threads that die automatically after inactivity https://bugs.webkit.org/show_bug.cgi?id=163576 Reviewed by Andreas Kling. Source/JavaScriptCore: Added a sleepSeconds() function, which made it easier for me to test this change. The WTF changes in this patch change how the JSC GC manages threads: the GC threads will now shut down automatically after 1 second of inactivity. Maybe this will save some memory. * jsc.cpp: (GlobalObject::finishCreation): (functionSleepSeconds): Source/WTF: For a long time now, I've been adding threads to WTF/JSC and each time I do this, I feel guilty because those threads don't shut down when they are inactive. For example, in bug 163562, I need to add a new GC thread. There will be one of them per VM. This means that a JSC API client that starts a lot of VMs will have a lot of threads. I don't think that's good. A common pattern for all of these threads is that they have some well-defined trigger that causes them to run. This trigger has a lock, a condition variable, some logic that determines if there is work to do, and then of course the logic for the thread's actual work. The thread bodies usually look like this: void Thingy::runThread() { for (;;) { Work work; { LockHolder locker(m_lock); while (!hasWork()) m_cond.wait(m_lock); work = takeWork(); } doWork(work); } } If you look at ParallelHelperPool (the GC's threads) and DFG::Worklist (some of the JIT's threads), you will see this pattern. This change adds a new kind of thread, called AutomaticThread, that lets you write threads to this pattern while getting automatic thread shutdown for free: instead of just waiting on a condition variable, AutomaticThread will have a timeout that causes the thread to die. The condition variable associated with AutomaticThread, called AutomaticThreadCondition, is smart enough to restart any threads that have decided to stop due to inactivity. The inactivity threshold is current just 1 second. In this patch I only adopt AutomaticThread for ParallelHelperPool. I plan to adopt it in more places soon. * WTF.xcodeproj/project.pbxproj: * wtf/AutomaticThread.cpp: Added. (WTF::AutomaticThreadCondition::create): (WTF::AutomaticThreadCondition::AutomaticThreadCondition): (WTF::AutomaticThreadCondition::~AutomaticThreadCondition): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Added. * wtf/CMakeLists.txt: * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::ParallelHelperPool): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::helperThreadBody): Deleted. (WTF::ParallelHelperPool::waitForClientWithTask): Deleted. * wtf/ParallelHelperPool.h: Canonical link: https://commits.webkit.org/181393@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207480 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-18 20:17:10 +00:00
Ref<AutomaticThreadCondition> AutomaticThreadCondition::create()
WTF should make it easier to create threads that die automatically after inactivity https://bugs.webkit.org/show_bug.cgi?id=163576 Reviewed by Andreas Kling. Source/JavaScriptCore: Added a sleepSeconds() function, which made it easier for me to test this change. The WTF changes in this patch change how the JSC GC manages threads: the GC threads will now shut down automatically after 1 second of inactivity. Maybe this will save some memory. * jsc.cpp: (GlobalObject::finishCreation): (functionSleepSeconds): Source/WTF: For a long time now, I've been adding threads to WTF/JSC and each time I do this, I feel guilty because those threads don't shut down when they are inactive. For example, in bug 163562, I need to add a new GC thread. There will be one of them per VM. This means that a JSC API client that starts a lot of VMs will have a lot of threads. I don't think that's good. A common pattern for all of these threads is that they have some well-defined trigger that causes them to run. This trigger has a lock, a condition variable, some logic that determines if there is work to do, and then of course the logic for the thread's actual work. The thread bodies usually look like this: void Thingy::runThread() { for (;;) { Work work; { LockHolder locker(m_lock); while (!hasWork()) m_cond.wait(m_lock); work = takeWork(); } doWork(work); } } If you look at ParallelHelperPool (the GC's threads) and DFG::Worklist (some of the JIT's threads), you will see this pattern. This change adds a new kind of thread, called AutomaticThread, that lets you write threads to this pattern while getting automatic thread shutdown for free: instead of just waiting on a condition variable, AutomaticThread will have a timeout that causes the thread to die. The condition variable associated with AutomaticThread, called AutomaticThreadCondition, is smart enough to restart any threads that have decided to stop due to inactivity. The inactivity threshold is current just 1 second. In this patch I only adopt AutomaticThread for ParallelHelperPool. I plan to adopt it in more places soon. * WTF.xcodeproj/project.pbxproj: * wtf/AutomaticThread.cpp: Added. (WTF::AutomaticThreadCondition::create): (WTF::AutomaticThreadCondition::AutomaticThreadCondition): (WTF::AutomaticThreadCondition::~AutomaticThreadCondition): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Added. * wtf/CMakeLists.txt: * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::ParallelHelperPool): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::helperThreadBody): Deleted. (WTF::ParallelHelperPool::waitForClientWithTask): Deleted. * wtf/ParallelHelperPool.h: Canonical link: https://commits.webkit.org/181393@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207480 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-18 20:17:10 +00:00
{
return adoptRef(*new AutomaticThreadCondition);
WTF should make it easier to create threads that die automatically after inactivity https://bugs.webkit.org/show_bug.cgi?id=163576 Reviewed by Andreas Kling. Source/JavaScriptCore: Added a sleepSeconds() function, which made it easier for me to test this change. The WTF changes in this patch change how the JSC GC manages threads: the GC threads will now shut down automatically after 1 second of inactivity. Maybe this will save some memory. * jsc.cpp: (GlobalObject::finishCreation): (functionSleepSeconds): Source/WTF: For a long time now, I've been adding threads to WTF/JSC and each time I do this, I feel guilty because those threads don't shut down when they are inactive. For example, in bug 163562, I need to add a new GC thread. There will be one of them per VM. This means that a JSC API client that starts a lot of VMs will have a lot of threads. I don't think that's good. A common pattern for all of these threads is that they have some well-defined trigger that causes them to run. This trigger has a lock, a condition variable, some logic that determines if there is work to do, and then of course the logic for the thread's actual work. The thread bodies usually look like this: void Thingy::runThread() { for (;;) { Work work; { LockHolder locker(m_lock); while (!hasWork()) m_cond.wait(m_lock); work = takeWork(); } doWork(work); } } If you look at ParallelHelperPool (the GC's threads) and DFG::Worklist (some of the JIT's threads), you will see this pattern. This change adds a new kind of thread, called AutomaticThread, that lets you write threads to this pattern while getting automatic thread shutdown for free: instead of just waiting on a condition variable, AutomaticThread will have a timeout that causes the thread to die. The condition variable associated with AutomaticThread, called AutomaticThreadCondition, is smart enough to restart any threads that have decided to stop due to inactivity. The inactivity threshold is current just 1 second. In this patch I only adopt AutomaticThread for ParallelHelperPool. I plan to adopt it in more places soon. * WTF.xcodeproj/project.pbxproj: * wtf/AutomaticThread.cpp: Added. (WTF::AutomaticThreadCondition::create): (WTF::AutomaticThreadCondition::AutomaticThreadCondition): (WTF::AutomaticThreadCondition::~AutomaticThreadCondition): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Added. * wtf/CMakeLists.txt: * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::ParallelHelperPool): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::helperThreadBody): Deleted. (WTF::ParallelHelperPool::waitForClientWithTask): Deleted. * wtf/ParallelHelperPool.h: Canonical link: https://commits.webkit.org/181393@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207480 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-18 20:17:10 +00:00
}
AutomaticThreadCondition::AutomaticThreadCondition()
{
}
AutomaticThreadCondition::~AutomaticThreadCondition()
{
}
The collector thread should only start when the mutator doesn't have heap access https://bugs.webkit.org/show_bug.cgi?id=167737 Reviewed by Keith Miller. JSTests: Add versions of splay that flash heap access, to simulate what might happen if a third-party app was running concurrent GC. In this case, we might actually start the collector thread. * stress/splay-flash-access-1ms.js: Added. (performance.now): (this.Setup.setup.setup): (this.TearDown.tearDown.tearDown): (Benchmark): (BenchmarkResult): (BenchmarkResult.prototype.valueOf): (BenchmarkSuite): (alert): (Math.random): (BenchmarkSuite.ResetRNG): (RunStep): (BenchmarkSuite.RunSuites): (BenchmarkSuite.CountBenchmarks): (BenchmarkSuite.GeometricMean): (BenchmarkSuite.GeometricMeanTime): (BenchmarkSuite.AverageAbovePercentile): (BenchmarkSuite.GeometricMeanLatency): (BenchmarkSuite.FormatScore): (BenchmarkSuite.prototype.NotifyStep): (BenchmarkSuite.prototype.NotifyResult): (BenchmarkSuite.prototype.NotifyError): (BenchmarkSuite.prototype.RunSingleBenchmark): (RunNextSetup): (RunNextBenchmark): (RunNextTearDown): (BenchmarkSuite.prototype.RunStep): (GeneratePayloadTree): (GenerateKey): (SplayUpdateStats): (InsertNewNode): (SplaySetup): (SplayTearDown): (SplayRun): (SplayTree): (SplayTree.prototype.isEmpty): (SplayTree.prototype.insert): (SplayTree.prototype.remove): (SplayTree.prototype.find): (SplayTree.prototype.findMax): (SplayTree.prototype.findGreatestLessThan): (SplayTree.prototype.exportKeys): (SplayTree.prototype.splay_): (SplayTree.Node): (SplayTree.Node.prototype.traverse_): (jscSetUp): (jscTearDown): (jscRun): (averageAbovePercentile): (printPercentile): * stress/splay-flash-access.js: Added. (performance.now): (this.Setup.setup.setup): (this.TearDown.tearDown.tearDown): (Benchmark): (BenchmarkResult): (BenchmarkResult.prototype.valueOf): (BenchmarkSuite): (alert): (Math.random): (BenchmarkSuite.ResetRNG): (RunStep): (BenchmarkSuite.RunSuites): (BenchmarkSuite.CountBenchmarks): (BenchmarkSuite.GeometricMean): (BenchmarkSuite.GeometricMeanTime): (BenchmarkSuite.AverageAbovePercentile): (BenchmarkSuite.GeometricMeanLatency): (BenchmarkSuite.FormatScore): (BenchmarkSuite.prototype.NotifyStep): (BenchmarkSuite.prototype.NotifyResult): (BenchmarkSuite.prototype.NotifyError): (BenchmarkSuite.prototype.RunSingleBenchmark): (RunNextSetup): (RunNextBenchmark): (RunNextTearDown): (BenchmarkSuite.prototype.RunStep): (GeneratePayloadTree): (GenerateKey): (SplayUpdateStats): (InsertNewNode): (SplaySetup): (SplayTearDown): (SplayRun): (SplayTree): (SplayTree.prototype.isEmpty): (SplayTree.prototype.insert): (SplayTree.prototype.remove): (SplayTree.prototype.find): (SplayTree.prototype.findMax): (SplayTree.prototype.findGreatestLessThan): (SplayTree.prototype.exportKeys): (SplayTree.prototype.splay_): (SplayTree.Node): (SplayTree.Node.prototype.traverse_): (jscSetUp): (jscTearDown): (jscRun): (averageAbovePercentile): (printPercentile): Source/JavaScriptCore: This turns the collector thread's workflow into a state machine, so that the mutator thread can run it directly. This reduces the amount of synchronization we do with the collector thread, and means that most apps will never start the collector thread. The collector thread will still start when we need to finish collecting and we don't have heap access. In this new world, "stopping the world" means relinquishing control of collection to the mutator. This means tracking who is conducting collection. I use the GCConductor enum to say who is conducting. It's either GCConductor::Mutator or GCConductor::Collector. I use the term "conn" to refer to the concept of conducting (having the conn, relinquishing the conn, taking the conn). So, stopping the world means giving the mutator the conn. Releasing heap access means giving the collector the conn. This meant bringing back the conservative scan of the calling thread. It turns out that this scan was too slow to be called on each GC increment because apparently setjmp() now does system calls. So, I wrote our own callee save register saving for the GC. Then I had doubts about whether or not it was correct, so I also made it so that the GC only rarely asks for the register state. I think we still want to use my register saving code instead of setjmp because setjmp seems to save things we don't need, and that could make us overly conservative. It turns out that this new scheduling discipline makes the old space-time scheduler perform better than the new stochastic space-time scheduler on systems with fewer than 4 cores. This is because the mutator having the conn enables us to time the mutator<->collector context switches by polling. The OS is never involved. So, we can use super precise timing. This allows the old space-time schduler to shine like it hadn't before. The splay results imply that this is all a good thing. On 2-core systems, this reduces pause times by 40% and it increases throughput about 5%. On 1-core systems, this reduces pause times by half and reduces throughput by 8%. On 4-or-more-core systems, this doesn't seem to have much effect. * CMakeLists.txt: * JavaScriptCore.xcodeproj/project.pbxproj: * bytecode/CodeBlock.cpp: (JSC::CodeBlock::visitChildren): * dfg/DFGWorklist.cpp: (JSC::DFG::Worklist::ThreadBody::ThreadBody): (JSC::DFG::Worklist::dump): (JSC::DFG::numberOfWorklists): (JSC::DFG::ensureWorklistForIndex): (JSC::DFG::existingWorklistForIndexOrNull): (JSC::DFG::existingWorklistForIndex): * dfg/DFGWorklist.h: (JSC::DFG::numberOfWorklists): Deleted. (JSC::DFG::ensureWorklistForIndex): Deleted. (JSC::DFG::existingWorklistForIndexOrNull): Deleted. (JSC::DFG::existingWorklistForIndex): Deleted. * heap/CollectingScope.h: Added. (JSC::CollectingScope::CollectingScope): (JSC::CollectingScope::~CollectingScope): * heap/CollectorPhase.cpp: Added. (JSC::worldShouldBeSuspended): (WTF::printInternal): * heap/CollectorPhase.h: Added. * heap/EdenGCActivityCallback.cpp: (JSC::EdenGCActivityCallback::lastGCLength): * heap/FullGCActivityCallback.cpp: (JSC::FullGCActivityCallback::doCollection): (JSC::FullGCActivityCallback::lastGCLength): * heap/GCConductor.cpp: Added. (JSC::gcConductorShortName): (WTF::printInternal): * heap/GCConductor.h: Added. * heap/GCFinalizationCallback.cpp: Added. (JSC::GCFinalizationCallback::GCFinalizationCallback): (JSC::GCFinalizationCallback::~GCFinalizationCallback): * heap/GCFinalizationCallback.h: Added. (JSC::GCFinalizationCallbackFuncAdaptor::GCFinalizationCallbackFuncAdaptor): (JSC::createGCFinalizationCallback): * heap/Heap.cpp: (JSC::Heap::Thread::Thread): (JSC::Heap::Heap): (JSC::Heap::lastChanceToFinalize): (JSC::Heap::gatherStackRoots): (JSC::Heap::updateObjectCounts): (JSC::Heap::sweepSynchronously): (JSC::Heap::collectAllGarbage): (JSC::Heap::collectAsync): (JSC::Heap::collectSync): (JSC::Heap::shouldCollectInCollectorThread): (JSC::Heap::collectInCollectorThread): (JSC::Heap::checkConn): (JSC::Heap::runNotRunningPhase): (JSC::Heap::runBeginPhase): (JSC::Heap::runFixpointPhase): (JSC::Heap::runConcurrentPhase): (JSC::Heap::runReloopPhase): (JSC::Heap::runEndPhase): (JSC::Heap::changePhase): (JSC::Heap::finishChangingPhase): (JSC::Heap::stopThePeriphery): (JSC::Heap::resumeThePeriphery): (JSC::Heap::stopTheMutator): (JSC::Heap::resumeTheMutator): (JSC::Heap::stopIfNecessarySlow): (JSC::Heap::collectInMutatorThread): (JSC::Heap::waitForCollector): (JSC::Heap::acquireAccessSlow): (JSC::Heap::releaseAccessSlow): (JSC::Heap::relinquishConn): (JSC::Heap::finishRelinquishingConn): (JSC::Heap::handleNeedFinalize): (JSC::Heap::notifyThreadStopping): (JSC::Heap::finalize): (JSC::Heap::addFinalizationCallback): (JSC::Heap::requestCollection): (JSC::Heap::waitForCollection): (JSC::Heap::updateAllocationLimits): (JSC::Heap::didFinishCollection): (JSC::Heap::collectIfNecessaryOrDefer): (JSC::Heap::notifyIsSafeToCollect): (JSC::Heap::preventCollection): (JSC::Heap::performIncrement): (JSC::Heap::markToFixpoint): Deleted. (JSC::Heap::shouldCollectInThread): Deleted. (JSC::Heap::collectInThread): Deleted. (JSC::Heap::stopTheWorld): Deleted. (JSC::Heap::resumeTheWorld): Deleted. * heap/Heap.h: (JSC::Heap::machineThreads): (JSC::Heap::lastFullGCLength): (JSC::Heap::lastEdenGCLength): (JSC::Heap::increaseLastFullGCLength): * heap/HeapInlines.h: (JSC::Heap::mutatorIsStopped): Deleted. * heap/HeapStatistics.cpp: Removed. * heap/HeapStatistics.h: Removed. * heap/HelpingGCScope.h: Removed. * heap/IncrementalSweeper.cpp: (JSC::IncrementalSweeper::stopSweeping): (JSC::IncrementalSweeper::willFinishSweeping): Deleted. * heap/IncrementalSweeper.h: * heap/MachineStackMarker.cpp: (JSC::MachineThreads::gatherFromCurrentThread): (JSC::MachineThreads::gatherConservativeRoots): (JSC::callWithCurrentThreadState): * heap/MachineStackMarker.h: * heap/MarkedAllocator.cpp: (JSC::MarkedAllocator::allocateSlowCaseImpl): * heap/MarkedBlock.cpp: (JSC::MarkedBlock::Handle::sweep): * heap/MarkedSpace.cpp: (JSC::MarkedSpace::sweep): * heap/MutatorState.cpp: (WTF::printInternal): * heap/MutatorState.h: * heap/RegisterState.h: Added. * heap/RunningScope.h: Added. (JSC::RunningScope::RunningScope): (JSC::RunningScope::~RunningScope): * heap/SlotVisitor.cpp: (JSC::SlotVisitor::SlotVisitor): (JSC::SlotVisitor::drain): (JSC::SlotVisitor::drainFromShared): (JSC::SlotVisitor::drainInParallelPassively): (JSC::SlotVisitor::donateAll): (JSC::SlotVisitor::donate): * heap/SlotVisitor.h: (JSC::SlotVisitor::codeName): * heap/StochasticSpaceTimeMutatorScheduler.cpp: (JSC::StochasticSpaceTimeMutatorScheduler::beginCollection): (JSC::StochasticSpaceTimeMutatorScheduler::synchronousDrainingDidStall): (JSC::StochasticSpaceTimeMutatorScheduler::timeToStop): * heap/SweepingScope.h: Added. (JSC::SweepingScope::SweepingScope): (JSC::SweepingScope::~SweepingScope): * jit/JITWorklist.cpp: (JSC::JITWorklist::Thread::Thread): * jsc.cpp: (GlobalObject::finishCreation): (functionFlashHeapAccess): * runtime/InitializeThreading.cpp: (JSC::initializeThreading): * runtime/JSCellInlines.h: (JSC::JSCell::classInfo): * runtime/Options.cpp: (JSC::overrideDefaults): * runtime/Options.h: * runtime/TestRunnerUtils.cpp: (JSC::finalizeStatsAtEndOfTesting): Source/WebCore: Added new tests in JSTests. The WebCore changes involve: - Refactoring around new header discipline. - Adding crazy GC APIs to window.internals to enable us to test the GC's runloop discipline. * ForwardingHeaders/heap/GCFinalizationCallback.h: Added. * ForwardingHeaders/heap/IncrementalSweeper.h: Added. * ForwardingHeaders/heap/MachineStackMarker.h: Added. * ForwardingHeaders/heap/RunningScope.h: Added. * bindings/js/CommonVM.cpp: * testing/Internals.cpp: (WebCore::Internals::parserMetaData): (WebCore::Internals::isReadableStreamDisturbed): (WebCore::Internals::isGCRunning): (WebCore::Internals::addGCFinalizationCallback): (WebCore::Internals::stopSweeping): (WebCore::Internals::startSweeping): * testing/Internals.h: * testing/Internals.idl: Source/WTF: Extend the use of AbstractLocker so that we can use more locking idioms. * wtf/AutomaticThread.cpp: (WTF::AutomaticThreadCondition::notifyOne): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::tryStop): (WTF::AutomaticThread::isWaiting): (WTF::AutomaticThread::notify): (WTF::AutomaticThread::start): (WTF::AutomaticThread::threadIsStopping): * wtf/AutomaticThread.h: * wtf/NumberOfCores.cpp: (WTF::numberOfProcessorCores): * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::claimTask): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::hasClientWithTask): (WTF::ParallelHelperPool::getClientWithTask): * wtf/ParallelHelperPool.h: Tools: Make more tests collect continuously. * Scripts/run-jsc-stress-tests: Canonical link: https://commits.webkit.org/185692@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@212778 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-02-22 00:58:15 +00:00
void AutomaticThreadCondition::notifyOne(const AbstractLocker& locker)
DFG worklist should use AutomaticThread https://bugs.webkit.org/show_bug.cgi?id=163615 Reviewed by Mark Lam. Source/JavaScriptCore: AutomaticThread is a new feature in WTF that allows you to easily create worker threads that shut down automatically. This changes DFG::Worklist to use AutomaticThread, so that its threads shut down automatically, too. This has the potential to save a lot of memory. This required some improvements to AutomaticThread: Worklist likes to be able to keep state around for the whole lifetime of a thread, and so it likes knowing when threads are born and when they die. I added virtual methods for that. Also, Worklist uses notifyOne() so I added that, too. This looks to be perf-neutral. * dfg/DFGThreadData.cpp: (JSC::DFG::ThreadData::ThreadData): * dfg/DFGThreadData.h: * dfg/DFGWorklist.cpp: (JSC::DFG::Worklist::ThreadBody::ThreadBody): (JSC::DFG::Worklist::Worklist): (JSC::DFG::Worklist::~Worklist): (JSC::DFG::Worklist::finishCreation): (JSC::DFG::Worklist::isActiveForVM): (JSC::DFG::Worklist::enqueue): (JSC::DFG::Worklist::compilationState): (JSC::DFG::Worklist::waitUntilAllPlansForVMAreReady): (JSC::DFG::Worklist::removeAllReadyPlansForVM): (JSC::DFG::Worklist::completeAllReadyPlansForVM): (JSC::DFG::Worklist::rememberCodeBlocks): (JSC::DFG::Worklist::visitWeakReferences): (JSC::DFG::Worklist::removeDeadPlans): (JSC::DFG::Worklist::removeNonCompilingPlansForVM): (JSC::DFG::Worklist::queueLength): (JSC::DFG::Worklist::dump): (JSC::DFG::Worklist::runThread): Deleted. (JSC::DFG::Worklist::threadFunction): Deleted. * dfg/DFGWorklist.h: Source/WTF: This adds new functionality to AutomaticThread to support DFG::Worklist: - AutomaticThread::threadDidStart/threadWillStop virtual methods called at the start and end of a thread's lifetime. This allows Worklist to tie some resources to the life of the thread, and also means that now those resources will naturally free up when the Worklist is not in use. - AutomaticThreadCondition::notifyOne(). This required changes to Condition::notifyOne(). We need to know if the Condition woke up anyone. If it didn't, then we need to launch one of our threads. * wtf/AutomaticThread.cpp: (WTF::AutomaticThreadCondition::notifyOne): (WTF::AutomaticThread::ThreadScope::ThreadScope): (WTF::AutomaticThread::ThreadScope::~ThreadScope): (WTF::AutomaticThread::start): (WTF::AutomaticThread::threadDidStart): (WTF::AutomaticThread::threadWillStop): * wtf/AutomaticThread.h: * wtf/Condition.h: (WTF::ConditionBase::notifyOne): Canonical link: https://commits.webkit.org/181455@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207545 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-19 17:47:30 +00:00
{
REGRESSION: HipChat and Mail sometimes hang beneath JSC::Heap::lastChanceToFinalize() https://bugs.webkit.org/show_bug.cgi?id=165962 Reviewed by Filip Pizlo. There is an inherent race in Condition::waitFor() where the timeout can happen just before a notify from another thread. Fixed this by adding a condition variable and flag to each AutomaticThread. The flag is used to signify to a notifying thread that the thread is waiting. That flag is set in the waiting thread before calling waitFor() and cleared by another thread when it notifies the thread. The access to that flag happens when the lock is held. Now the waiting thread checks if the flag after a timeout to see that it in fact should proceed like a normal notification. The added condition variable allows us to target a specific thread. We used to keep a list of waiting threads, now we keep a list of all threads. To notify one thread, we look for a waiting thread and notify it directly. If we can't find a waiting thread, we start a sleeping thread. We notify all threads by waking all waiting threads and starting all sleeping threads. * wtf/AutomaticThread.cpp: (WTF::AutomaticThreadCondition::notifyOne): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThread::isWaiting): (WTF::AutomaticThread::notify): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Canonical link: https://commits.webkit.org/183569@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@209938 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-12-16 22:26:09 +00:00
for (AutomaticThread* thread : m_threads) {
if (thread->isWaiting(locker)) {
thread->notify(locker);
return;
}
}
for (AutomaticThread* thread : m_threads) {
if (!thread->hasUnderlyingThread(locker)) {
thread->start(locker);
return;
}
}
m_condition.notifyOne();
DFG worklist should use AutomaticThread https://bugs.webkit.org/show_bug.cgi?id=163615 Reviewed by Mark Lam. Source/JavaScriptCore: AutomaticThread is a new feature in WTF that allows you to easily create worker threads that shut down automatically. This changes DFG::Worklist to use AutomaticThread, so that its threads shut down automatically, too. This has the potential to save a lot of memory. This required some improvements to AutomaticThread: Worklist likes to be able to keep state around for the whole lifetime of a thread, and so it likes knowing when threads are born and when they die. I added virtual methods for that. Also, Worklist uses notifyOne() so I added that, too. This looks to be perf-neutral. * dfg/DFGThreadData.cpp: (JSC::DFG::ThreadData::ThreadData): * dfg/DFGThreadData.h: * dfg/DFGWorklist.cpp: (JSC::DFG::Worklist::ThreadBody::ThreadBody): (JSC::DFG::Worklist::Worklist): (JSC::DFG::Worklist::~Worklist): (JSC::DFG::Worklist::finishCreation): (JSC::DFG::Worklist::isActiveForVM): (JSC::DFG::Worklist::enqueue): (JSC::DFG::Worklist::compilationState): (JSC::DFG::Worklist::waitUntilAllPlansForVMAreReady): (JSC::DFG::Worklist::removeAllReadyPlansForVM): (JSC::DFG::Worklist::completeAllReadyPlansForVM): (JSC::DFG::Worklist::rememberCodeBlocks): (JSC::DFG::Worklist::visitWeakReferences): (JSC::DFG::Worklist::removeDeadPlans): (JSC::DFG::Worklist::removeNonCompilingPlansForVM): (JSC::DFG::Worklist::queueLength): (JSC::DFG::Worklist::dump): (JSC::DFG::Worklist::runThread): Deleted. (JSC::DFG::Worklist::threadFunction): Deleted. * dfg/DFGWorklist.h: Source/WTF: This adds new functionality to AutomaticThread to support DFG::Worklist: - AutomaticThread::threadDidStart/threadWillStop virtual methods called at the start and end of a thread's lifetime. This allows Worklist to tie some resources to the life of the thread, and also means that now those resources will naturally free up when the Worklist is not in use. - AutomaticThreadCondition::notifyOne(). This required changes to Condition::notifyOne(). We need to know if the Condition woke up anyone. If it didn't, then we need to launch one of our threads. * wtf/AutomaticThread.cpp: (WTF::AutomaticThreadCondition::notifyOne): (WTF::AutomaticThread::ThreadScope::ThreadScope): (WTF::AutomaticThread::ThreadScope::~ThreadScope): (WTF::AutomaticThread::start): (WTF::AutomaticThread::threadDidStart): (WTF::AutomaticThread::threadWillStop): * wtf/AutomaticThread.h: * wtf/Condition.h: (WTF::ConditionBase::notifyOne): Canonical link: https://commits.webkit.org/181455@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207545 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-19 17:47:30 +00:00
}
The collector thread should only start when the mutator doesn't have heap access https://bugs.webkit.org/show_bug.cgi?id=167737 Reviewed by Keith Miller. JSTests: Add versions of splay that flash heap access, to simulate what might happen if a third-party app was running concurrent GC. In this case, we might actually start the collector thread. * stress/splay-flash-access-1ms.js: Added. (performance.now): (this.Setup.setup.setup): (this.TearDown.tearDown.tearDown): (Benchmark): (BenchmarkResult): (BenchmarkResult.prototype.valueOf): (BenchmarkSuite): (alert): (Math.random): (BenchmarkSuite.ResetRNG): (RunStep): (BenchmarkSuite.RunSuites): (BenchmarkSuite.CountBenchmarks): (BenchmarkSuite.GeometricMean): (BenchmarkSuite.GeometricMeanTime): (BenchmarkSuite.AverageAbovePercentile): (BenchmarkSuite.GeometricMeanLatency): (BenchmarkSuite.FormatScore): (BenchmarkSuite.prototype.NotifyStep): (BenchmarkSuite.prototype.NotifyResult): (BenchmarkSuite.prototype.NotifyError): (BenchmarkSuite.prototype.RunSingleBenchmark): (RunNextSetup): (RunNextBenchmark): (RunNextTearDown): (BenchmarkSuite.prototype.RunStep): (GeneratePayloadTree): (GenerateKey): (SplayUpdateStats): (InsertNewNode): (SplaySetup): (SplayTearDown): (SplayRun): (SplayTree): (SplayTree.prototype.isEmpty): (SplayTree.prototype.insert): (SplayTree.prototype.remove): (SplayTree.prototype.find): (SplayTree.prototype.findMax): (SplayTree.prototype.findGreatestLessThan): (SplayTree.prototype.exportKeys): (SplayTree.prototype.splay_): (SplayTree.Node): (SplayTree.Node.prototype.traverse_): (jscSetUp): (jscTearDown): (jscRun): (averageAbovePercentile): (printPercentile): * stress/splay-flash-access.js: Added. (performance.now): (this.Setup.setup.setup): (this.TearDown.tearDown.tearDown): (Benchmark): (BenchmarkResult): (BenchmarkResult.prototype.valueOf): (BenchmarkSuite): (alert): (Math.random): (BenchmarkSuite.ResetRNG): (RunStep): (BenchmarkSuite.RunSuites): (BenchmarkSuite.CountBenchmarks): (BenchmarkSuite.GeometricMean): (BenchmarkSuite.GeometricMeanTime): (BenchmarkSuite.AverageAbovePercentile): (BenchmarkSuite.GeometricMeanLatency): (BenchmarkSuite.FormatScore): (BenchmarkSuite.prototype.NotifyStep): (BenchmarkSuite.prototype.NotifyResult): (BenchmarkSuite.prototype.NotifyError): (BenchmarkSuite.prototype.RunSingleBenchmark): (RunNextSetup): (RunNextBenchmark): (RunNextTearDown): (BenchmarkSuite.prototype.RunStep): (GeneratePayloadTree): (GenerateKey): (SplayUpdateStats): (InsertNewNode): (SplaySetup): (SplayTearDown): (SplayRun): (SplayTree): (SplayTree.prototype.isEmpty): (SplayTree.prototype.insert): (SplayTree.prototype.remove): (SplayTree.prototype.find): (SplayTree.prototype.findMax): (SplayTree.prototype.findGreatestLessThan): (SplayTree.prototype.exportKeys): (SplayTree.prototype.splay_): (SplayTree.Node): (SplayTree.Node.prototype.traverse_): (jscSetUp): (jscTearDown): (jscRun): (averageAbovePercentile): (printPercentile): Source/JavaScriptCore: This turns the collector thread's workflow into a state machine, so that the mutator thread can run it directly. This reduces the amount of synchronization we do with the collector thread, and means that most apps will never start the collector thread. The collector thread will still start when we need to finish collecting and we don't have heap access. In this new world, "stopping the world" means relinquishing control of collection to the mutator. This means tracking who is conducting collection. I use the GCConductor enum to say who is conducting. It's either GCConductor::Mutator or GCConductor::Collector. I use the term "conn" to refer to the concept of conducting (having the conn, relinquishing the conn, taking the conn). So, stopping the world means giving the mutator the conn. Releasing heap access means giving the collector the conn. This meant bringing back the conservative scan of the calling thread. It turns out that this scan was too slow to be called on each GC increment because apparently setjmp() now does system calls. So, I wrote our own callee save register saving for the GC. Then I had doubts about whether or not it was correct, so I also made it so that the GC only rarely asks for the register state. I think we still want to use my register saving code instead of setjmp because setjmp seems to save things we don't need, and that could make us overly conservative. It turns out that this new scheduling discipline makes the old space-time scheduler perform better than the new stochastic space-time scheduler on systems with fewer than 4 cores. This is because the mutator having the conn enables us to time the mutator<->collector context switches by polling. The OS is never involved. So, we can use super precise timing. This allows the old space-time schduler to shine like it hadn't before. The splay results imply that this is all a good thing. On 2-core systems, this reduces pause times by 40% and it increases throughput about 5%. On 1-core systems, this reduces pause times by half and reduces throughput by 8%. On 4-or-more-core systems, this doesn't seem to have much effect. * CMakeLists.txt: * JavaScriptCore.xcodeproj/project.pbxproj: * bytecode/CodeBlock.cpp: (JSC::CodeBlock::visitChildren): * dfg/DFGWorklist.cpp: (JSC::DFG::Worklist::ThreadBody::ThreadBody): (JSC::DFG::Worklist::dump): (JSC::DFG::numberOfWorklists): (JSC::DFG::ensureWorklistForIndex): (JSC::DFG::existingWorklistForIndexOrNull): (JSC::DFG::existingWorklistForIndex): * dfg/DFGWorklist.h: (JSC::DFG::numberOfWorklists): Deleted. (JSC::DFG::ensureWorklistForIndex): Deleted. (JSC::DFG::existingWorklistForIndexOrNull): Deleted. (JSC::DFG::existingWorklistForIndex): Deleted. * heap/CollectingScope.h: Added. (JSC::CollectingScope::CollectingScope): (JSC::CollectingScope::~CollectingScope): * heap/CollectorPhase.cpp: Added. (JSC::worldShouldBeSuspended): (WTF::printInternal): * heap/CollectorPhase.h: Added. * heap/EdenGCActivityCallback.cpp: (JSC::EdenGCActivityCallback::lastGCLength): * heap/FullGCActivityCallback.cpp: (JSC::FullGCActivityCallback::doCollection): (JSC::FullGCActivityCallback::lastGCLength): * heap/GCConductor.cpp: Added. (JSC::gcConductorShortName): (WTF::printInternal): * heap/GCConductor.h: Added. * heap/GCFinalizationCallback.cpp: Added. (JSC::GCFinalizationCallback::GCFinalizationCallback): (JSC::GCFinalizationCallback::~GCFinalizationCallback): * heap/GCFinalizationCallback.h: Added. (JSC::GCFinalizationCallbackFuncAdaptor::GCFinalizationCallbackFuncAdaptor): (JSC::createGCFinalizationCallback): * heap/Heap.cpp: (JSC::Heap::Thread::Thread): (JSC::Heap::Heap): (JSC::Heap::lastChanceToFinalize): (JSC::Heap::gatherStackRoots): (JSC::Heap::updateObjectCounts): (JSC::Heap::sweepSynchronously): (JSC::Heap::collectAllGarbage): (JSC::Heap::collectAsync): (JSC::Heap::collectSync): (JSC::Heap::shouldCollectInCollectorThread): (JSC::Heap::collectInCollectorThread): (JSC::Heap::checkConn): (JSC::Heap::runNotRunningPhase): (JSC::Heap::runBeginPhase): (JSC::Heap::runFixpointPhase): (JSC::Heap::runConcurrentPhase): (JSC::Heap::runReloopPhase): (JSC::Heap::runEndPhase): (JSC::Heap::changePhase): (JSC::Heap::finishChangingPhase): (JSC::Heap::stopThePeriphery): (JSC::Heap::resumeThePeriphery): (JSC::Heap::stopTheMutator): (JSC::Heap::resumeTheMutator): (JSC::Heap::stopIfNecessarySlow): (JSC::Heap::collectInMutatorThread): (JSC::Heap::waitForCollector): (JSC::Heap::acquireAccessSlow): (JSC::Heap::releaseAccessSlow): (JSC::Heap::relinquishConn): (JSC::Heap::finishRelinquishingConn): (JSC::Heap::handleNeedFinalize): (JSC::Heap::notifyThreadStopping): (JSC::Heap::finalize): (JSC::Heap::addFinalizationCallback): (JSC::Heap::requestCollection): (JSC::Heap::waitForCollection): (JSC::Heap::updateAllocationLimits): (JSC::Heap::didFinishCollection): (JSC::Heap::collectIfNecessaryOrDefer): (JSC::Heap::notifyIsSafeToCollect): (JSC::Heap::preventCollection): (JSC::Heap::performIncrement): (JSC::Heap::markToFixpoint): Deleted. (JSC::Heap::shouldCollectInThread): Deleted. (JSC::Heap::collectInThread): Deleted. (JSC::Heap::stopTheWorld): Deleted. (JSC::Heap::resumeTheWorld): Deleted. * heap/Heap.h: (JSC::Heap::machineThreads): (JSC::Heap::lastFullGCLength): (JSC::Heap::lastEdenGCLength): (JSC::Heap::increaseLastFullGCLength): * heap/HeapInlines.h: (JSC::Heap::mutatorIsStopped): Deleted. * heap/HeapStatistics.cpp: Removed. * heap/HeapStatistics.h: Removed. * heap/HelpingGCScope.h: Removed. * heap/IncrementalSweeper.cpp: (JSC::IncrementalSweeper::stopSweeping): (JSC::IncrementalSweeper::willFinishSweeping): Deleted. * heap/IncrementalSweeper.h: * heap/MachineStackMarker.cpp: (JSC::MachineThreads::gatherFromCurrentThread): (JSC::MachineThreads::gatherConservativeRoots): (JSC::callWithCurrentThreadState): * heap/MachineStackMarker.h: * heap/MarkedAllocator.cpp: (JSC::MarkedAllocator::allocateSlowCaseImpl): * heap/MarkedBlock.cpp: (JSC::MarkedBlock::Handle::sweep): * heap/MarkedSpace.cpp: (JSC::MarkedSpace::sweep): * heap/MutatorState.cpp: (WTF::printInternal): * heap/MutatorState.h: * heap/RegisterState.h: Added. * heap/RunningScope.h: Added. (JSC::RunningScope::RunningScope): (JSC::RunningScope::~RunningScope): * heap/SlotVisitor.cpp: (JSC::SlotVisitor::SlotVisitor): (JSC::SlotVisitor::drain): (JSC::SlotVisitor::drainFromShared): (JSC::SlotVisitor::drainInParallelPassively): (JSC::SlotVisitor::donateAll): (JSC::SlotVisitor::donate): * heap/SlotVisitor.h: (JSC::SlotVisitor::codeName): * heap/StochasticSpaceTimeMutatorScheduler.cpp: (JSC::StochasticSpaceTimeMutatorScheduler::beginCollection): (JSC::StochasticSpaceTimeMutatorScheduler::synchronousDrainingDidStall): (JSC::StochasticSpaceTimeMutatorScheduler::timeToStop): * heap/SweepingScope.h: Added. (JSC::SweepingScope::SweepingScope): (JSC::SweepingScope::~SweepingScope): * jit/JITWorklist.cpp: (JSC::JITWorklist::Thread::Thread): * jsc.cpp: (GlobalObject::finishCreation): (functionFlashHeapAccess): * runtime/InitializeThreading.cpp: (JSC::initializeThreading): * runtime/JSCellInlines.h: (JSC::JSCell::classInfo): * runtime/Options.cpp: (JSC::overrideDefaults): * runtime/Options.h: * runtime/TestRunnerUtils.cpp: (JSC::finalizeStatsAtEndOfTesting): Source/WebCore: Added new tests in JSTests. The WebCore changes involve: - Refactoring around new header discipline. - Adding crazy GC APIs to window.internals to enable us to test the GC's runloop discipline. * ForwardingHeaders/heap/GCFinalizationCallback.h: Added. * ForwardingHeaders/heap/IncrementalSweeper.h: Added. * ForwardingHeaders/heap/MachineStackMarker.h: Added. * ForwardingHeaders/heap/RunningScope.h: Added. * bindings/js/CommonVM.cpp: * testing/Internals.cpp: (WebCore::Internals::parserMetaData): (WebCore::Internals::isReadableStreamDisturbed): (WebCore::Internals::isGCRunning): (WebCore::Internals::addGCFinalizationCallback): (WebCore::Internals::stopSweeping): (WebCore::Internals::startSweeping): * testing/Internals.h: * testing/Internals.idl: Source/WTF: Extend the use of AbstractLocker so that we can use more locking idioms. * wtf/AutomaticThread.cpp: (WTF::AutomaticThreadCondition::notifyOne): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::tryStop): (WTF::AutomaticThread::isWaiting): (WTF::AutomaticThread::notify): (WTF::AutomaticThread::start): (WTF::AutomaticThread::threadIsStopping): * wtf/AutomaticThread.h: * wtf/NumberOfCores.cpp: (WTF::numberOfProcessorCores): * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::claimTask): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::hasClientWithTask): (WTF::ParallelHelperPool::getClientWithTask): * wtf/ParallelHelperPool.h: Tools: Make more tests collect continuously. * Scripts/run-jsc-stress-tests: Canonical link: https://commits.webkit.org/185692@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@212778 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-02-22 00:58:15 +00:00
void AutomaticThreadCondition::notifyAll(const AbstractLocker& locker)
WTF should make it easier to create threads that die automatically after inactivity https://bugs.webkit.org/show_bug.cgi?id=163576 Reviewed by Andreas Kling. Source/JavaScriptCore: Added a sleepSeconds() function, which made it easier for me to test this change. The WTF changes in this patch change how the JSC GC manages threads: the GC threads will now shut down automatically after 1 second of inactivity. Maybe this will save some memory. * jsc.cpp: (GlobalObject::finishCreation): (functionSleepSeconds): Source/WTF: For a long time now, I've been adding threads to WTF/JSC and each time I do this, I feel guilty because those threads don't shut down when they are inactive. For example, in bug 163562, I need to add a new GC thread. There will be one of them per VM. This means that a JSC API client that starts a lot of VMs will have a lot of threads. I don't think that's good. A common pattern for all of these threads is that they have some well-defined trigger that causes them to run. This trigger has a lock, a condition variable, some logic that determines if there is work to do, and then of course the logic for the thread's actual work. The thread bodies usually look like this: void Thingy::runThread() { for (;;) { Work work; { LockHolder locker(m_lock); while (!hasWork()) m_cond.wait(m_lock); work = takeWork(); } doWork(work); } } If you look at ParallelHelperPool (the GC's threads) and DFG::Worklist (some of the JIT's threads), you will see this pattern. This change adds a new kind of thread, called AutomaticThread, that lets you write threads to this pattern while getting automatic thread shutdown for free: instead of just waiting on a condition variable, AutomaticThread will have a timeout that causes the thread to die. The condition variable associated with AutomaticThread, called AutomaticThreadCondition, is smart enough to restart any threads that have decided to stop due to inactivity. The inactivity threshold is current just 1 second. In this patch I only adopt AutomaticThread for ParallelHelperPool. I plan to adopt it in more places soon. * WTF.xcodeproj/project.pbxproj: * wtf/AutomaticThread.cpp: Added. (WTF::AutomaticThreadCondition::create): (WTF::AutomaticThreadCondition::AutomaticThreadCondition): (WTF::AutomaticThreadCondition::~AutomaticThreadCondition): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Added. * wtf/CMakeLists.txt: * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::ParallelHelperPool): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::helperThreadBody): Deleted. (WTF::ParallelHelperPool::waitForClientWithTask): Deleted. * wtf/ParallelHelperPool.h: Canonical link: https://commits.webkit.org/181393@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207480 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-18 20:17:10 +00:00
{
m_condition.notifyAll();
REGRESSION: HipChat and Mail sometimes hang beneath JSC::Heap::lastChanceToFinalize() https://bugs.webkit.org/show_bug.cgi?id=165962 Reviewed by Filip Pizlo. There is an inherent race in Condition::waitFor() where the timeout can happen just before a notify from another thread. Fixed this by adding a condition variable and flag to each AutomaticThread. The flag is used to signify to a notifying thread that the thread is waiting. That flag is set in the waiting thread before calling waitFor() and cleared by another thread when it notifies the thread. The access to that flag happens when the lock is held. Now the waiting thread checks if the flag after a timeout to see that it in fact should proceed like a normal notification. The added condition variable allows us to target a specific thread. We used to keep a list of waiting threads, now we keep a list of all threads. To notify one thread, we look for a waiting thread and notify it directly. If we can't find a waiting thread, we start a sleeping thread. We notify all threads by waking all waiting threads and starting all sleeping threads. * wtf/AutomaticThread.cpp: (WTF::AutomaticThreadCondition::notifyOne): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThread::isWaiting): (WTF::AutomaticThread::notify): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Canonical link: https://commits.webkit.org/183569@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@209938 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-12-16 22:26:09 +00:00
for (AutomaticThread* thread : m_threads) {
if (thread->isWaiting(locker))
thread->notify(locker);
else if (!thread->hasUnderlyingThread(locker))
thread->start(locker);
}
WTF should make it easier to create threads that die automatically after inactivity https://bugs.webkit.org/show_bug.cgi?id=163576 Reviewed by Andreas Kling. Source/JavaScriptCore: Added a sleepSeconds() function, which made it easier for me to test this change. The WTF changes in this patch change how the JSC GC manages threads: the GC threads will now shut down automatically after 1 second of inactivity. Maybe this will save some memory. * jsc.cpp: (GlobalObject::finishCreation): (functionSleepSeconds): Source/WTF: For a long time now, I've been adding threads to WTF/JSC and each time I do this, I feel guilty because those threads don't shut down when they are inactive. For example, in bug 163562, I need to add a new GC thread. There will be one of them per VM. This means that a JSC API client that starts a lot of VMs will have a lot of threads. I don't think that's good. A common pattern for all of these threads is that they have some well-defined trigger that causes them to run. This trigger has a lock, a condition variable, some logic that determines if there is work to do, and then of course the logic for the thread's actual work. The thread bodies usually look like this: void Thingy::runThread() { for (;;) { Work work; { LockHolder locker(m_lock); while (!hasWork()) m_cond.wait(m_lock); work = takeWork(); } doWork(work); } } If you look at ParallelHelperPool (the GC's threads) and DFG::Worklist (some of the JIT's threads), you will see this pattern. This change adds a new kind of thread, called AutomaticThread, that lets you write threads to this pattern while getting automatic thread shutdown for free: instead of just waiting on a condition variable, AutomaticThread will have a timeout that causes the thread to die. The condition variable associated with AutomaticThread, called AutomaticThreadCondition, is smart enough to restart any threads that have decided to stop due to inactivity. The inactivity threshold is current just 1 second. In this patch I only adopt AutomaticThread for ParallelHelperPool. I plan to adopt it in more places soon. * WTF.xcodeproj/project.pbxproj: * wtf/AutomaticThread.cpp: Added. (WTF::AutomaticThreadCondition::create): (WTF::AutomaticThreadCondition::AutomaticThreadCondition): (WTF::AutomaticThreadCondition::~AutomaticThreadCondition): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Added. * wtf/CMakeLists.txt: * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::ParallelHelperPool): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::helperThreadBody): Deleted. (WTF::ParallelHelperPool::waitForClientWithTask): Deleted. * wtf/ParallelHelperPool.h: Canonical link: https://commits.webkit.org/181393@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207480 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-18 20:17:10 +00:00
}
Baseline JIT should use AutomaticThread https://bugs.webkit.org/show_bug.cgi?id=163686 Reviewed by Geoffrey Garen. Source/JavaScriptCore: Change the JITWorklist to use AutomaticThread, so that the Baseline JIT's concurrent compiler thread shuts down automatically after inactivity. With this change, all of JSC's threads shut down automatically. If you run splay for a few seconds (which fires up all threads - compiler and GC) and then go to sleep for a second, you'll see that the only threads left are the main thread and the bmalloc thread. * jit/JITWorklist.cpp: (JSC::JITWorklist::Thread::Thread): (JSC::JITWorklist::JITWorklist): (JSC::JITWorklist::completeAllForVM): (JSC::JITWorklist::poll): (JSC::JITWorklist::compileLater): (JSC::JITWorklist::compileNow): (JSC::JITWorklist::finalizePlans): (JSC::JITWorklist::runThread): Deleted. * jit/JITWorklist.h: Source/WTF: Added a AutomaticThreadCondition::wait() method, so that if you really want to use one common condition for your thread and something else, you can do it. This trivially works if you only use notifyAll(), and behaves as you'd expect for notifyOne() (i.e. it's dangerous, since you don't know who will wake up). The Baseline JIT used the one-true-Condition idiom because it used notifyAll() in an optimal way: there are just two threads talking to each other, so it wakes up at most one thread and that thread is exactly the one you want woken up. Adding wait() means that I did not have to change that code. * wtf/AutomaticThread.cpp: (WTF::AutomaticThreadCondition::wait): * wtf/AutomaticThread.h: Canonical link: https://commits.webkit.org/181474@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207566 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-19 20:37:20 +00:00
void AutomaticThreadCondition::wait(Lock& lock)
{
m_condition.wait(lock);
}
bool AutomaticThreadCondition::waitFor(Lock& lock, Seconds time)
{
return m_condition.waitFor(lock, time);
}
The collector thread should only start when the mutator doesn't have heap access https://bugs.webkit.org/show_bug.cgi?id=167737 Reviewed by Keith Miller. JSTests: Add versions of splay that flash heap access, to simulate what might happen if a third-party app was running concurrent GC. In this case, we might actually start the collector thread. * stress/splay-flash-access-1ms.js: Added. (performance.now): (this.Setup.setup.setup): (this.TearDown.tearDown.tearDown): (Benchmark): (BenchmarkResult): (BenchmarkResult.prototype.valueOf): (BenchmarkSuite): (alert): (Math.random): (BenchmarkSuite.ResetRNG): (RunStep): (BenchmarkSuite.RunSuites): (BenchmarkSuite.CountBenchmarks): (BenchmarkSuite.GeometricMean): (BenchmarkSuite.GeometricMeanTime): (BenchmarkSuite.AverageAbovePercentile): (BenchmarkSuite.GeometricMeanLatency): (BenchmarkSuite.FormatScore): (BenchmarkSuite.prototype.NotifyStep): (BenchmarkSuite.prototype.NotifyResult): (BenchmarkSuite.prototype.NotifyError): (BenchmarkSuite.prototype.RunSingleBenchmark): (RunNextSetup): (RunNextBenchmark): (RunNextTearDown): (BenchmarkSuite.prototype.RunStep): (GeneratePayloadTree): (GenerateKey): (SplayUpdateStats): (InsertNewNode): (SplaySetup): (SplayTearDown): (SplayRun): (SplayTree): (SplayTree.prototype.isEmpty): (SplayTree.prototype.insert): (SplayTree.prototype.remove): (SplayTree.prototype.find): (SplayTree.prototype.findMax): (SplayTree.prototype.findGreatestLessThan): (SplayTree.prototype.exportKeys): (SplayTree.prototype.splay_): (SplayTree.Node): (SplayTree.Node.prototype.traverse_): (jscSetUp): (jscTearDown): (jscRun): (averageAbovePercentile): (printPercentile): * stress/splay-flash-access.js: Added. (performance.now): (this.Setup.setup.setup): (this.TearDown.tearDown.tearDown): (Benchmark): (BenchmarkResult): (BenchmarkResult.prototype.valueOf): (BenchmarkSuite): (alert): (Math.random): (BenchmarkSuite.ResetRNG): (RunStep): (BenchmarkSuite.RunSuites): (BenchmarkSuite.CountBenchmarks): (BenchmarkSuite.GeometricMean): (BenchmarkSuite.GeometricMeanTime): (BenchmarkSuite.AverageAbovePercentile): (BenchmarkSuite.GeometricMeanLatency): (BenchmarkSuite.FormatScore): (BenchmarkSuite.prototype.NotifyStep): (BenchmarkSuite.prototype.NotifyResult): (BenchmarkSuite.prototype.NotifyError): (BenchmarkSuite.prototype.RunSingleBenchmark): (RunNextSetup): (RunNextBenchmark): (RunNextTearDown): (BenchmarkSuite.prototype.RunStep): (GeneratePayloadTree): (GenerateKey): (SplayUpdateStats): (InsertNewNode): (SplaySetup): (SplayTearDown): (SplayRun): (SplayTree): (SplayTree.prototype.isEmpty): (SplayTree.prototype.insert): (SplayTree.prototype.remove): (SplayTree.prototype.find): (SplayTree.prototype.findMax): (SplayTree.prototype.findGreatestLessThan): (SplayTree.prototype.exportKeys): (SplayTree.prototype.splay_): (SplayTree.Node): (SplayTree.Node.prototype.traverse_): (jscSetUp): (jscTearDown): (jscRun): (averageAbovePercentile): (printPercentile): Source/JavaScriptCore: This turns the collector thread's workflow into a state machine, so that the mutator thread can run it directly. This reduces the amount of synchronization we do with the collector thread, and means that most apps will never start the collector thread. The collector thread will still start when we need to finish collecting and we don't have heap access. In this new world, "stopping the world" means relinquishing control of collection to the mutator. This means tracking who is conducting collection. I use the GCConductor enum to say who is conducting. It's either GCConductor::Mutator or GCConductor::Collector. I use the term "conn" to refer to the concept of conducting (having the conn, relinquishing the conn, taking the conn). So, stopping the world means giving the mutator the conn. Releasing heap access means giving the collector the conn. This meant bringing back the conservative scan of the calling thread. It turns out that this scan was too slow to be called on each GC increment because apparently setjmp() now does system calls. So, I wrote our own callee save register saving for the GC. Then I had doubts about whether or not it was correct, so I also made it so that the GC only rarely asks for the register state. I think we still want to use my register saving code instead of setjmp because setjmp seems to save things we don't need, and that could make us overly conservative. It turns out that this new scheduling discipline makes the old space-time scheduler perform better than the new stochastic space-time scheduler on systems with fewer than 4 cores. This is because the mutator having the conn enables us to time the mutator<->collector context switches by polling. The OS is never involved. So, we can use super precise timing. This allows the old space-time schduler to shine like it hadn't before. The splay results imply that this is all a good thing. On 2-core systems, this reduces pause times by 40% and it increases throughput about 5%. On 1-core systems, this reduces pause times by half and reduces throughput by 8%. On 4-or-more-core systems, this doesn't seem to have much effect. * CMakeLists.txt: * JavaScriptCore.xcodeproj/project.pbxproj: * bytecode/CodeBlock.cpp: (JSC::CodeBlock::visitChildren): * dfg/DFGWorklist.cpp: (JSC::DFG::Worklist::ThreadBody::ThreadBody): (JSC::DFG::Worklist::dump): (JSC::DFG::numberOfWorklists): (JSC::DFG::ensureWorklistForIndex): (JSC::DFG::existingWorklistForIndexOrNull): (JSC::DFG::existingWorklistForIndex): * dfg/DFGWorklist.h: (JSC::DFG::numberOfWorklists): Deleted. (JSC::DFG::ensureWorklistForIndex): Deleted. (JSC::DFG::existingWorklistForIndexOrNull): Deleted. (JSC::DFG::existingWorklistForIndex): Deleted. * heap/CollectingScope.h: Added. (JSC::CollectingScope::CollectingScope): (JSC::CollectingScope::~CollectingScope): * heap/CollectorPhase.cpp: Added. (JSC::worldShouldBeSuspended): (WTF::printInternal): * heap/CollectorPhase.h: Added. * heap/EdenGCActivityCallback.cpp: (JSC::EdenGCActivityCallback::lastGCLength): * heap/FullGCActivityCallback.cpp: (JSC::FullGCActivityCallback::doCollection): (JSC::FullGCActivityCallback::lastGCLength): * heap/GCConductor.cpp: Added. (JSC::gcConductorShortName): (WTF::printInternal): * heap/GCConductor.h: Added. * heap/GCFinalizationCallback.cpp: Added. (JSC::GCFinalizationCallback::GCFinalizationCallback): (JSC::GCFinalizationCallback::~GCFinalizationCallback): * heap/GCFinalizationCallback.h: Added. (JSC::GCFinalizationCallbackFuncAdaptor::GCFinalizationCallbackFuncAdaptor): (JSC::createGCFinalizationCallback): * heap/Heap.cpp: (JSC::Heap::Thread::Thread): (JSC::Heap::Heap): (JSC::Heap::lastChanceToFinalize): (JSC::Heap::gatherStackRoots): (JSC::Heap::updateObjectCounts): (JSC::Heap::sweepSynchronously): (JSC::Heap::collectAllGarbage): (JSC::Heap::collectAsync): (JSC::Heap::collectSync): (JSC::Heap::shouldCollectInCollectorThread): (JSC::Heap::collectInCollectorThread): (JSC::Heap::checkConn): (JSC::Heap::runNotRunningPhase): (JSC::Heap::runBeginPhase): (JSC::Heap::runFixpointPhase): (JSC::Heap::runConcurrentPhase): (JSC::Heap::runReloopPhase): (JSC::Heap::runEndPhase): (JSC::Heap::changePhase): (JSC::Heap::finishChangingPhase): (JSC::Heap::stopThePeriphery): (JSC::Heap::resumeThePeriphery): (JSC::Heap::stopTheMutator): (JSC::Heap::resumeTheMutator): (JSC::Heap::stopIfNecessarySlow): (JSC::Heap::collectInMutatorThread): (JSC::Heap::waitForCollector): (JSC::Heap::acquireAccessSlow): (JSC::Heap::releaseAccessSlow): (JSC::Heap::relinquishConn): (JSC::Heap::finishRelinquishingConn): (JSC::Heap::handleNeedFinalize): (JSC::Heap::notifyThreadStopping): (JSC::Heap::finalize): (JSC::Heap::addFinalizationCallback): (JSC::Heap::requestCollection): (JSC::Heap::waitForCollection): (JSC::Heap::updateAllocationLimits): (JSC::Heap::didFinishCollection): (JSC::Heap::collectIfNecessaryOrDefer): (JSC::Heap::notifyIsSafeToCollect): (JSC::Heap::preventCollection): (JSC::Heap::performIncrement): (JSC::Heap::markToFixpoint): Deleted. (JSC::Heap::shouldCollectInThread): Deleted. (JSC::Heap::collectInThread): Deleted. (JSC::Heap::stopTheWorld): Deleted. (JSC::Heap::resumeTheWorld): Deleted. * heap/Heap.h: (JSC::Heap::machineThreads): (JSC::Heap::lastFullGCLength): (JSC::Heap::lastEdenGCLength): (JSC::Heap::increaseLastFullGCLength): * heap/HeapInlines.h: (JSC::Heap::mutatorIsStopped): Deleted. * heap/HeapStatistics.cpp: Removed. * heap/HeapStatistics.h: Removed. * heap/HelpingGCScope.h: Removed. * heap/IncrementalSweeper.cpp: (JSC::IncrementalSweeper::stopSweeping): (JSC::IncrementalSweeper::willFinishSweeping): Deleted. * heap/IncrementalSweeper.h: * heap/MachineStackMarker.cpp: (JSC::MachineThreads::gatherFromCurrentThread): (JSC::MachineThreads::gatherConservativeRoots): (JSC::callWithCurrentThreadState): * heap/MachineStackMarker.h: * heap/MarkedAllocator.cpp: (JSC::MarkedAllocator::allocateSlowCaseImpl): * heap/MarkedBlock.cpp: (JSC::MarkedBlock::Handle::sweep): * heap/MarkedSpace.cpp: (JSC::MarkedSpace::sweep): * heap/MutatorState.cpp: (WTF::printInternal): * heap/MutatorState.h: * heap/RegisterState.h: Added. * heap/RunningScope.h: Added. (JSC::RunningScope::RunningScope): (JSC::RunningScope::~RunningScope): * heap/SlotVisitor.cpp: (JSC::SlotVisitor::SlotVisitor): (JSC::SlotVisitor::drain): (JSC::SlotVisitor::drainFromShared): (JSC::SlotVisitor::drainInParallelPassively): (JSC::SlotVisitor::donateAll): (JSC::SlotVisitor::donate): * heap/SlotVisitor.h: (JSC::SlotVisitor::codeName): * heap/StochasticSpaceTimeMutatorScheduler.cpp: (JSC::StochasticSpaceTimeMutatorScheduler::beginCollection): (JSC::StochasticSpaceTimeMutatorScheduler::synchronousDrainingDidStall): (JSC::StochasticSpaceTimeMutatorScheduler::timeToStop): * heap/SweepingScope.h: Added. (JSC::SweepingScope::SweepingScope): (JSC::SweepingScope::~SweepingScope): * jit/JITWorklist.cpp: (JSC::JITWorklist::Thread::Thread): * jsc.cpp: (GlobalObject::finishCreation): (functionFlashHeapAccess): * runtime/InitializeThreading.cpp: (JSC::initializeThreading): * runtime/JSCellInlines.h: (JSC::JSCell::classInfo): * runtime/Options.cpp: (JSC::overrideDefaults): * runtime/Options.h: * runtime/TestRunnerUtils.cpp: (JSC::finalizeStatsAtEndOfTesting): Source/WebCore: Added new tests in JSTests. The WebCore changes involve: - Refactoring around new header discipline. - Adding crazy GC APIs to window.internals to enable us to test the GC's runloop discipline. * ForwardingHeaders/heap/GCFinalizationCallback.h: Added. * ForwardingHeaders/heap/IncrementalSweeper.h: Added. * ForwardingHeaders/heap/MachineStackMarker.h: Added. * ForwardingHeaders/heap/RunningScope.h: Added. * bindings/js/CommonVM.cpp: * testing/Internals.cpp: (WebCore::Internals::parserMetaData): (WebCore::Internals::isReadableStreamDisturbed): (WebCore::Internals::isGCRunning): (WebCore::Internals::addGCFinalizationCallback): (WebCore::Internals::stopSweeping): (WebCore::Internals::startSweeping): * testing/Internals.h: * testing/Internals.idl: Source/WTF: Extend the use of AbstractLocker so that we can use more locking idioms. * wtf/AutomaticThread.cpp: (WTF::AutomaticThreadCondition::notifyOne): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::tryStop): (WTF::AutomaticThread::isWaiting): (WTF::AutomaticThread::notify): (WTF::AutomaticThread::start): (WTF::AutomaticThread::threadIsStopping): * wtf/AutomaticThread.h: * wtf/NumberOfCores.cpp: (WTF::numberOfProcessorCores): * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::claimTask): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::hasClientWithTask): (WTF::ParallelHelperPool::getClientWithTask): * wtf/ParallelHelperPool.h: Tools: Make more tests collect continuously. * Scripts/run-jsc-stress-tests: Canonical link: https://commits.webkit.org/185692@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@212778 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-02-22 00:58:15 +00:00
void AutomaticThreadCondition::add(const AbstractLocker&, AutomaticThread* thread)
WTF should make it easier to create threads that die automatically after inactivity https://bugs.webkit.org/show_bug.cgi?id=163576 Reviewed by Andreas Kling. Source/JavaScriptCore: Added a sleepSeconds() function, which made it easier for me to test this change. The WTF changes in this patch change how the JSC GC manages threads: the GC threads will now shut down automatically after 1 second of inactivity. Maybe this will save some memory. * jsc.cpp: (GlobalObject::finishCreation): (functionSleepSeconds): Source/WTF: For a long time now, I've been adding threads to WTF/JSC and each time I do this, I feel guilty because those threads don't shut down when they are inactive. For example, in bug 163562, I need to add a new GC thread. There will be one of them per VM. This means that a JSC API client that starts a lot of VMs will have a lot of threads. I don't think that's good. A common pattern for all of these threads is that they have some well-defined trigger that causes them to run. This trigger has a lock, a condition variable, some logic that determines if there is work to do, and then of course the logic for the thread's actual work. The thread bodies usually look like this: void Thingy::runThread() { for (;;) { Work work; { LockHolder locker(m_lock); while (!hasWork()) m_cond.wait(m_lock); work = takeWork(); } doWork(work); } } If you look at ParallelHelperPool (the GC's threads) and DFG::Worklist (some of the JIT's threads), you will see this pattern. This change adds a new kind of thread, called AutomaticThread, that lets you write threads to this pattern while getting automatic thread shutdown for free: instead of just waiting on a condition variable, AutomaticThread will have a timeout that causes the thread to die. The condition variable associated with AutomaticThread, called AutomaticThreadCondition, is smart enough to restart any threads that have decided to stop due to inactivity. The inactivity threshold is current just 1 second. In this patch I only adopt AutomaticThread for ParallelHelperPool. I plan to adopt it in more places soon. * WTF.xcodeproj/project.pbxproj: * wtf/AutomaticThread.cpp: Added. (WTF::AutomaticThreadCondition::create): (WTF::AutomaticThreadCondition::AutomaticThreadCondition): (WTF::AutomaticThreadCondition::~AutomaticThreadCondition): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Added. * wtf/CMakeLists.txt: * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::ParallelHelperPool): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::helperThreadBody): Deleted. (WTF::ParallelHelperPool::waitForClientWithTask): Deleted. * wtf/ParallelHelperPool.h: Canonical link: https://commits.webkit.org/181393@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207480 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-18 20:17:10 +00:00
{
ASSERT(!m_threads.contains(thread));
m_threads.append(thread);
}
The collector thread should only start when the mutator doesn't have heap access https://bugs.webkit.org/show_bug.cgi?id=167737 Reviewed by Keith Miller. JSTests: Add versions of splay that flash heap access, to simulate what might happen if a third-party app was running concurrent GC. In this case, we might actually start the collector thread. * stress/splay-flash-access-1ms.js: Added. (performance.now): (this.Setup.setup.setup): (this.TearDown.tearDown.tearDown): (Benchmark): (BenchmarkResult): (BenchmarkResult.prototype.valueOf): (BenchmarkSuite): (alert): (Math.random): (BenchmarkSuite.ResetRNG): (RunStep): (BenchmarkSuite.RunSuites): (BenchmarkSuite.CountBenchmarks): (BenchmarkSuite.GeometricMean): (BenchmarkSuite.GeometricMeanTime): (BenchmarkSuite.AverageAbovePercentile): (BenchmarkSuite.GeometricMeanLatency): (BenchmarkSuite.FormatScore): (BenchmarkSuite.prototype.NotifyStep): (BenchmarkSuite.prototype.NotifyResult): (BenchmarkSuite.prototype.NotifyError): (BenchmarkSuite.prototype.RunSingleBenchmark): (RunNextSetup): (RunNextBenchmark): (RunNextTearDown): (BenchmarkSuite.prototype.RunStep): (GeneratePayloadTree): (GenerateKey): (SplayUpdateStats): (InsertNewNode): (SplaySetup): (SplayTearDown): (SplayRun): (SplayTree): (SplayTree.prototype.isEmpty): (SplayTree.prototype.insert): (SplayTree.prototype.remove): (SplayTree.prototype.find): (SplayTree.prototype.findMax): (SplayTree.prototype.findGreatestLessThan): (SplayTree.prototype.exportKeys): (SplayTree.prototype.splay_): (SplayTree.Node): (SplayTree.Node.prototype.traverse_): (jscSetUp): (jscTearDown): (jscRun): (averageAbovePercentile): (printPercentile): * stress/splay-flash-access.js: Added. (performance.now): (this.Setup.setup.setup): (this.TearDown.tearDown.tearDown): (Benchmark): (BenchmarkResult): (BenchmarkResult.prototype.valueOf): (BenchmarkSuite): (alert): (Math.random): (BenchmarkSuite.ResetRNG): (RunStep): (BenchmarkSuite.RunSuites): (BenchmarkSuite.CountBenchmarks): (BenchmarkSuite.GeometricMean): (BenchmarkSuite.GeometricMeanTime): (BenchmarkSuite.AverageAbovePercentile): (BenchmarkSuite.GeometricMeanLatency): (BenchmarkSuite.FormatScore): (BenchmarkSuite.prototype.NotifyStep): (BenchmarkSuite.prototype.NotifyResult): (BenchmarkSuite.prototype.NotifyError): (BenchmarkSuite.prototype.RunSingleBenchmark): (RunNextSetup): (RunNextBenchmark): (RunNextTearDown): (BenchmarkSuite.prototype.RunStep): (GeneratePayloadTree): (GenerateKey): (SplayUpdateStats): (InsertNewNode): (SplaySetup): (SplayTearDown): (SplayRun): (SplayTree): (SplayTree.prototype.isEmpty): (SplayTree.prototype.insert): (SplayTree.prototype.remove): (SplayTree.prototype.find): (SplayTree.prototype.findMax): (SplayTree.prototype.findGreatestLessThan): (SplayTree.prototype.exportKeys): (SplayTree.prototype.splay_): (SplayTree.Node): (SplayTree.Node.prototype.traverse_): (jscSetUp): (jscTearDown): (jscRun): (averageAbovePercentile): (printPercentile): Source/JavaScriptCore: This turns the collector thread's workflow into a state machine, so that the mutator thread can run it directly. This reduces the amount of synchronization we do with the collector thread, and means that most apps will never start the collector thread. The collector thread will still start when we need to finish collecting and we don't have heap access. In this new world, "stopping the world" means relinquishing control of collection to the mutator. This means tracking who is conducting collection. I use the GCConductor enum to say who is conducting. It's either GCConductor::Mutator or GCConductor::Collector. I use the term "conn" to refer to the concept of conducting (having the conn, relinquishing the conn, taking the conn). So, stopping the world means giving the mutator the conn. Releasing heap access means giving the collector the conn. This meant bringing back the conservative scan of the calling thread. It turns out that this scan was too slow to be called on each GC increment because apparently setjmp() now does system calls. So, I wrote our own callee save register saving for the GC. Then I had doubts about whether or not it was correct, so I also made it so that the GC only rarely asks for the register state. I think we still want to use my register saving code instead of setjmp because setjmp seems to save things we don't need, and that could make us overly conservative. It turns out that this new scheduling discipline makes the old space-time scheduler perform better than the new stochastic space-time scheduler on systems with fewer than 4 cores. This is because the mutator having the conn enables us to time the mutator<->collector context switches by polling. The OS is never involved. So, we can use super precise timing. This allows the old space-time schduler to shine like it hadn't before. The splay results imply that this is all a good thing. On 2-core systems, this reduces pause times by 40% and it increases throughput about 5%. On 1-core systems, this reduces pause times by half and reduces throughput by 8%. On 4-or-more-core systems, this doesn't seem to have much effect. * CMakeLists.txt: * JavaScriptCore.xcodeproj/project.pbxproj: * bytecode/CodeBlock.cpp: (JSC::CodeBlock::visitChildren): * dfg/DFGWorklist.cpp: (JSC::DFG::Worklist::ThreadBody::ThreadBody): (JSC::DFG::Worklist::dump): (JSC::DFG::numberOfWorklists): (JSC::DFG::ensureWorklistForIndex): (JSC::DFG::existingWorklistForIndexOrNull): (JSC::DFG::existingWorklistForIndex): * dfg/DFGWorklist.h: (JSC::DFG::numberOfWorklists): Deleted. (JSC::DFG::ensureWorklistForIndex): Deleted. (JSC::DFG::existingWorklistForIndexOrNull): Deleted. (JSC::DFG::existingWorklistForIndex): Deleted. * heap/CollectingScope.h: Added. (JSC::CollectingScope::CollectingScope): (JSC::CollectingScope::~CollectingScope): * heap/CollectorPhase.cpp: Added. (JSC::worldShouldBeSuspended): (WTF::printInternal): * heap/CollectorPhase.h: Added. * heap/EdenGCActivityCallback.cpp: (JSC::EdenGCActivityCallback::lastGCLength): * heap/FullGCActivityCallback.cpp: (JSC::FullGCActivityCallback::doCollection): (JSC::FullGCActivityCallback::lastGCLength): * heap/GCConductor.cpp: Added. (JSC::gcConductorShortName): (WTF::printInternal): * heap/GCConductor.h: Added. * heap/GCFinalizationCallback.cpp: Added. (JSC::GCFinalizationCallback::GCFinalizationCallback): (JSC::GCFinalizationCallback::~GCFinalizationCallback): * heap/GCFinalizationCallback.h: Added. (JSC::GCFinalizationCallbackFuncAdaptor::GCFinalizationCallbackFuncAdaptor): (JSC::createGCFinalizationCallback): * heap/Heap.cpp: (JSC::Heap::Thread::Thread): (JSC::Heap::Heap): (JSC::Heap::lastChanceToFinalize): (JSC::Heap::gatherStackRoots): (JSC::Heap::updateObjectCounts): (JSC::Heap::sweepSynchronously): (JSC::Heap::collectAllGarbage): (JSC::Heap::collectAsync): (JSC::Heap::collectSync): (JSC::Heap::shouldCollectInCollectorThread): (JSC::Heap::collectInCollectorThread): (JSC::Heap::checkConn): (JSC::Heap::runNotRunningPhase): (JSC::Heap::runBeginPhase): (JSC::Heap::runFixpointPhase): (JSC::Heap::runConcurrentPhase): (JSC::Heap::runReloopPhase): (JSC::Heap::runEndPhase): (JSC::Heap::changePhase): (JSC::Heap::finishChangingPhase): (JSC::Heap::stopThePeriphery): (JSC::Heap::resumeThePeriphery): (JSC::Heap::stopTheMutator): (JSC::Heap::resumeTheMutator): (JSC::Heap::stopIfNecessarySlow): (JSC::Heap::collectInMutatorThread): (JSC::Heap::waitForCollector): (JSC::Heap::acquireAccessSlow): (JSC::Heap::releaseAccessSlow): (JSC::Heap::relinquishConn): (JSC::Heap::finishRelinquishingConn): (JSC::Heap::handleNeedFinalize): (JSC::Heap::notifyThreadStopping): (JSC::Heap::finalize): (JSC::Heap::addFinalizationCallback): (JSC::Heap::requestCollection): (JSC::Heap::waitForCollection): (JSC::Heap::updateAllocationLimits): (JSC::Heap::didFinishCollection): (JSC::Heap::collectIfNecessaryOrDefer): (JSC::Heap::notifyIsSafeToCollect): (JSC::Heap::preventCollection): (JSC::Heap::performIncrement): (JSC::Heap::markToFixpoint): Deleted. (JSC::Heap::shouldCollectInThread): Deleted. (JSC::Heap::collectInThread): Deleted. (JSC::Heap::stopTheWorld): Deleted. (JSC::Heap::resumeTheWorld): Deleted. * heap/Heap.h: (JSC::Heap::machineThreads): (JSC::Heap::lastFullGCLength): (JSC::Heap::lastEdenGCLength): (JSC::Heap::increaseLastFullGCLength): * heap/HeapInlines.h: (JSC::Heap::mutatorIsStopped): Deleted. * heap/HeapStatistics.cpp: Removed. * heap/HeapStatistics.h: Removed. * heap/HelpingGCScope.h: Removed. * heap/IncrementalSweeper.cpp: (JSC::IncrementalSweeper::stopSweeping): (JSC::IncrementalSweeper::willFinishSweeping): Deleted. * heap/IncrementalSweeper.h: * heap/MachineStackMarker.cpp: (JSC::MachineThreads::gatherFromCurrentThread): (JSC::MachineThreads::gatherConservativeRoots): (JSC::callWithCurrentThreadState): * heap/MachineStackMarker.h: * heap/MarkedAllocator.cpp: (JSC::MarkedAllocator::allocateSlowCaseImpl): * heap/MarkedBlock.cpp: (JSC::MarkedBlock::Handle::sweep): * heap/MarkedSpace.cpp: (JSC::MarkedSpace::sweep): * heap/MutatorState.cpp: (WTF::printInternal): * heap/MutatorState.h: * heap/RegisterState.h: Added. * heap/RunningScope.h: Added. (JSC::RunningScope::RunningScope): (JSC::RunningScope::~RunningScope): * heap/SlotVisitor.cpp: (JSC::SlotVisitor::SlotVisitor): (JSC::SlotVisitor::drain): (JSC::SlotVisitor::drainFromShared): (JSC::SlotVisitor::drainInParallelPassively): (JSC::SlotVisitor::donateAll): (JSC::SlotVisitor::donate): * heap/SlotVisitor.h: (JSC::SlotVisitor::codeName): * heap/StochasticSpaceTimeMutatorScheduler.cpp: (JSC::StochasticSpaceTimeMutatorScheduler::beginCollection): (JSC::StochasticSpaceTimeMutatorScheduler::synchronousDrainingDidStall): (JSC::StochasticSpaceTimeMutatorScheduler::timeToStop): * heap/SweepingScope.h: Added. (JSC::SweepingScope::SweepingScope): (JSC::SweepingScope::~SweepingScope): * jit/JITWorklist.cpp: (JSC::JITWorklist::Thread::Thread): * jsc.cpp: (GlobalObject::finishCreation): (functionFlashHeapAccess): * runtime/InitializeThreading.cpp: (JSC::initializeThreading): * runtime/JSCellInlines.h: (JSC::JSCell::classInfo): * runtime/Options.cpp: (JSC::overrideDefaults): * runtime/Options.h: * runtime/TestRunnerUtils.cpp: (JSC::finalizeStatsAtEndOfTesting): Source/WebCore: Added new tests in JSTests. The WebCore changes involve: - Refactoring around new header discipline. - Adding crazy GC APIs to window.internals to enable us to test the GC's runloop discipline. * ForwardingHeaders/heap/GCFinalizationCallback.h: Added. * ForwardingHeaders/heap/IncrementalSweeper.h: Added. * ForwardingHeaders/heap/MachineStackMarker.h: Added. * ForwardingHeaders/heap/RunningScope.h: Added. * bindings/js/CommonVM.cpp: * testing/Internals.cpp: (WebCore::Internals::parserMetaData): (WebCore::Internals::isReadableStreamDisturbed): (WebCore::Internals::isGCRunning): (WebCore::Internals::addGCFinalizationCallback): (WebCore::Internals::stopSweeping): (WebCore::Internals::startSweeping): * testing/Internals.h: * testing/Internals.idl: Source/WTF: Extend the use of AbstractLocker so that we can use more locking idioms. * wtf/AutomaticThread.cpp: (WTF::AutomaticThreadCondition::notifyOne): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::tryStop): (WTF::AutomaticThread::isWaiting): (WTF::AutomaticThread::notify): (WTF::AutomaticThread::start): (WTF::AutomaticThread::threadIsStopping): * wtf/AutomaticThread.h: * wtf/NumberOfCores.cpp: (WTF::numberOfProcessorCores): * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::claimTask): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::hasClientWithTask): (WTF::ParallelHelperPool::getClientWithTask): * wtf/ParallelHelperPool.h: Tools: Make more tests collect continuously. * Scripts/run-jsc-stress-tests: Canonical link: https://commits.webkit.org/185692@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@212778 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-02-22 00:58:15 +00:00
void AutomaticThreadCondition::remove(const AbstractLocker&, AutomaticThread* thread)
WTF should make it easier to create threads that die automatically after inactivity https://bugs.webkit.org/show_bug.cgi?id=163576 Reviewed by Andreas Kling. Source/JavaScriptCore: Added a sleepSeconds() function, which made it easier for me to test this change. The WTF changes in this patch change how the JSC GC manages threads: the GC threads will now shut down automatically after 1 second of inactivity. Maybe this will save some memory. * jsc.cpp: (GlobalObject::finishCreation): (functionSleepSeconds): Source/WTF: For a long time now, I've been adding threads to WTF/JSC and each time I do this, I feel guilty because those threads don't shut down when they are inactive. For example, in bug 163562, I need to add a new GC thread. There will be one of them per VM. This means that a JSC API client that starts a lot of VMs will have a lot of threads. I don't think that's good. A common pattern for all of these threads is that they have some well-defined trigger that causes them to run. This trigger has a lock, a condition variable, some logic that determines if there is work to do, and then of course the logic for the thread's actual work. The thread bodies usually look like this: void Thingy::runThread() { for (;;) { Work work; { LockHolder locker(m_lock); while (!hasWork()) m_cond.wait(m_lock); work = takeWork(); } doWork(work); } } If you look at ParallelHelperPool (the GC's threads) and DFG::Worklist (some of the JIT's threads), you will see this pattern. This change adds a new kind of thread, called AutomaticThread, that lets you write threads to this pattern while getting automatic thread shutdown for free: instead of just waiting on a condition variable, AutomaticThread will have a timeout that causes the thread to die. The condition variable associated with AutomaticThread, called AutomaticThreadCondition, is smart enough to restart any threads that have decided to stop due to inactivity. The inactivity threshold is current just 1 second. In this patch I only adopt AutomaticThread for ParallelHelperPool. I plan to adopt it in more places soon. * WTF.xcodeproj/project.pbxproj: * wtf/AutomaticThread.cpp: Added. (WTF::AutomaticThreadCondition::create): (WTF::AutomaticThreadCondition::AutomaticThreadCondition): (WTF::AutomaticThreadCondition::~AutomaticThreadCondition): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Added. * wtf/CMakeLists.txt: * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::ParallelHelperPool): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::helperThreadBody): Deleted. (WTF::ParallelHelperPool::waitForClientWithTask): Deleted. * wtf/ParallelHelperPool.h: Canonical link: https://commits.webkit.org/181393@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207480 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-18 20:17:10 +00:00
{
m_threads.removeFirst(thread);
ASSERT(!m_threads.contains(thread));
}
The collector thread should only start when the mutator doesn't have heap access https://bugs.webkit.org/show_bug.cgi?id=167737 Reviewed by Keith Miller. JSTests: Add versions of splay that flash heap access, to simulate what might happen if a third-party app was running concurrent GC. In this case, we might actually start the collector thread. * stress/splay-flash-access-1ms.js: Added. (performance.now): (this.Setup.setup.setup): (this.TearDown.tearDown.tearDown): (Benchmark): (BenchmarkResult): (BenchmarkResult.prototype.valueOf): (BenchmarkSuite): (alert): (Math.random): (BenchmarkSuite.ResetRNG): (RunStep): (BenchmarkSuite.RunSuites): (BenchmarkSuite.CountBenchmarks): (BenchmarkSuite.GeometricMean): (BenchmarkSuite.GeometricMeanTime): (BenchmarkSuite.AverageAbovePercentile): (BenchmarkSuite.GeometricMeanLatency): (BenchmarkSuite.FormatScore): (BenchmarkSuite.prototype.NotifyStep): (BenchmarkSuite.prototype.NotifyResult): (BenchmarkSuite.prototype.NotifyError): (BenchmarkSuite.prototype.RunSingleBenchmark): (RunNextSetup): (RunNextBenchmark): (RunNextTearDown): (BenchmarkSuite.prototype.RunStep): (GeneratePayloadTree): (GenerateKey): (SplayUpdateStats): (InsertNewNode): (SplaySetup): (SplayTearDown): (SplayRun): (SplayTree): (SplayTree.prototype.isEmpty): (SplayTree.prototype.insert): (SplayTree.prototype.remove): (SplayTree.prototype.find): (SplayTree.prototype.findMax): (SplayTree.prototype.findGreatestLessThan): (SplayTree.prototype.exportKeys): (SplayTree.prototype.splay_): (SplayTree.Node): (SplayTree.Node.prototype.traverse_): (jscSetUp): (jscTearDown): (jscRun): (averageAbovePercentile): (printPercentile): * stress/splay-flash-access.js: Added. (performance.now): (this.Setup.setup.setup): (this.TearDown.tearDown.tearDown): (Benchmark): (BenchmarkResult): (BenchmarkResult.prototype.valueOf): (BenchmarkSuite): (alert): (Math.random): (BenchmarkSuite.ResetRNG): (RunStep): (BenchmarkSuite.RunSuites): (BenchmarkSuite.CountBenchmarks): (BenchmarkSuite.GeometricMean): (BenchmarkSuite.GeometricMeanTime): (BenchmarkSuite.AverageAbovePercentile): (BenchmarkSuite.GeometricMeanLatency): (BenchmarkSuite.FormatScore): (BenchmarkSuite.prototype.NotifyStep): (BenchmarkSuite.prototype.NotifyResult): (BenchmarkSuite.prototype.NotifyError): (BenchmarkSuite.prototype.RunSingleBenchmark): (RunNextSetup): (RunNextBenchmark): (RunNextTearDown): (BenchmarkSuite.prototype.RunStep): (GeneratePayloadTree): (GenerateKey): (SplayUpdateStats): (InsertNewNode): (SplaySetup): (SplayTearDown): (SplayRun): (SplayTree): (SplayTree.prototype.isEmpty): (SplayTree.prototype.insert): (SplayTree.prototype.remove): (SplayTree.prototype.find): (SplayTree.prototype.findMax): (SplayTree.prototype.findGreatestLessThan): (SplayTree.prototype.exportKeys): (SplayTree.prototype.splay_): (SplayTree.Node): (SplayTree.Node.prototype.traverse_): (jscSetUp): (jscTearDown): (jscRun): (averageAbovePercentile): (printPercentile): Source/JavaScriptCore: This turns the collector thread's workflow into a state machine, so that the mutator thread can run it directly. This reduces the amount of synchronization we do with the collector thread, and means that most apps will never start the collector thread. The collector thread will still start when we need to finish collecting and we don't have heap access. In this new world, "stopping the world" means relinquishing control of collection to the mutator. This means tracking who is conducting collection. I use the GCConductor enum to say who is conducting. It's either GCConductor::Mutator or GCConductor::Collector. I use the term "conn" to refer to the concept of conducting (having the conn, relinquishing the conn, taking the conn). So, stopping the world means giving the mutator the conn. Releasing heap access means giving the collector the conn. This meant bringing back the conservative scan of the calling thread. It turns out that this scan was too slow to be called on each GC increment because apparently setjmp() now does system calls. So, I wrote our own callee save register saving for the GC. Then I had doubts about whether or not it was correct, so I also made it so that the GC only rarely asks for the register state. I think we still want to use my register saving code instead of setjmp because setjmp seems to save things we don't need, and that could make us overly conservative. It turns out that this new scheduling discipline makes the old space-time scheduler perform better than the new stochastic space-time scheduler on systems with fewer than 4 cores. This is because the mutator having the conn enables us to time the mutator<->collector context switches by polling. The OS is never involved. So, we can use super precise timing. This allows the old space-time schduler to shine like it hadn't before. The splay results imply that this is all a good thing. On 2-core systems, this reduces pause times by 40% and it increases throughput about 5%. On 1-core systems, this reduces pause times by half and reduces throughput by 8%. On 4-or-more-core systems, this doesn't seem to have much effect. * CMakeLists.txt: * JavaScriptCore.xcodeproj/project.pbxproj: * bytecode/CodeBlock.cpp: (JSC::CodeBlock::visitChildren): * dfg/DFGWorklist.cpp: (JSC::DFG::Worklist::ThreadBody::ThreadBody): (JSC::DFG::Worklist::dump): (JSC::DFG::numberOfWorklists): (JSC::DFG::ensureWorklistForIndex): (JSC::DFG::existingWorklistForIndexOrNull): (JSC::DFG::existingWorklistForIndex): * dfg/DFGWorklist.h: (JSC::DFG::numberOfWorklists): Deleted. (JSC::DFG::ensureWorklistForIndex): Deleted. (JSC::DFG::existingWorklistForIndexOrNull): Deleted. (JSC::DFG::existingWorklistForIndex): Deleted. * heap/CollectingScope.h: Added. (JSC::CollectingScope::CollectingScope): (JSC::CollectingScope::~CollectingScope): * heap/CollectorPhase.cpp: Added. (JSC::worldShouldBeSuspended): (WTF::printInternal): * heap/CollectorPhase.h: Added. * heap/EdenGCActivityCallback.cpp: (JSC::EdenGCActivityCallback::lastGCLength): * heap/FullGCActivityCallback.cpp: (JSC::FullGCActivityCallback::doCollection): (JSC::FullGCActivityCallback::lastGCLength): * heap/GCConductor.cpp: Added. (JSC::gcConductorShortName): (WTF::printInternal): * heap/GCConductor.h: Added. * heap/GCFinalizationCallback.cpp: Added. (JSC::GCFinalizationCallback::GCFinalizationCallback): (JSC::GCFinalizationCallback::~GCFinalizationCallback): * heap/GCFinalizationCallback.h: Added. (JSC::GCFinalizationCallbackFuncAdaptor::GCFinalizationCallbackFuncAdaptor): (JSC::createGCFinalizationCallback): * heap/Heap.cpp: (JSC::Heap::Thread::Thread): (JSC::Heap::Heap): (JSC::Heap::lastChanceToFinalize): (JSC::Heap::gatherStackRoots): (JSC::Heap::updateObjectCounts): (JSC::Heap::sweepSynchronously): (JSC::Heap::collectAllGarbage): (JSC::Heap::collectAsync): (JSC::Heap::collectSync): (JSC::Heap::shouldCollectInCollectorThread): (JSC::Heap::collectInCollectorThread): (JSC::Heap::checkConn): (JSC::Heap::runNotRunningPhase): (JSC::Heap::runBeginPhase): (JSC::Heap::runFixpointPhase): (JSC::Heap::runConcurrentPhase): (JSC::Heap::runReloopPhase): (JSC::Heap::runEndPhase): (JSC::Heap::changePhase): (JSC::Heap::finishChangingPhase): (JSC::Heap::stopThePeriphery): (JSC::Heap::resumeThePeriphery): (JSC::Heap::stopTheMutator): (JSC::Heap::resumeTheMutator): (JSC::Heap::stopIfNecessarySlow): (JSC::Heap::collectInMutatorThread): (JSC::Heap::waitForCollector): (JSC::Heap::acquireAccessSlow): (JSC::Heap::releaseAccessSlow): (JSC::Heap::relinquishConn): (JSC::Heap::finishRelinquishingConn): (JSC::Heap::handleNeedFinalize): (JSC::Heap::notifyThreadStopping): (JSC::Heap::finalize): (JSC::Heap::addFinalizationCallback): (JSC::Heap::requestCollection): (JSC::Heap::waitForCollection): (JSC::Heap::updateAllocationLimits): (JSC::Heap::didFinishCollection): (JSC::Heap::collectIfNecessaryOrDefer): (JSC::Heap::notifyIsSafeToCollect): (JSC::Heap::preventCollection): (JSC::Heap::performIncrement): (JSC::Heap::markToFixpoint): Deleted. (JSC::Heap::shouldCollectInThread): Deleted. (JSC::Heap::collectInThread): Deleted. (JSC::Heap::stopTheWorld): Deleted. (JSC::Heap::resumeTheWorld): Deleted. * heap/Heap.h: (JSC::Heap::machineThreads): (JSC::Heap::lastFullGCLength): (JSC::Heap::lastEdenGCLength): (JSC::Heap::increaseLastFullGCLength): * heap/HeapInlines.h: (JSC::Heap::mutatorIsStopped): Deleted. * heap/HeapStatistics.cpp: Removed. * heap/HeapStatistics.h: Removed. * heap/HelpingGCScope.h: Removed. * heap/IncrementalSweeper.cpp: (JSC::IncrementalSweeper::stopSweeping): (JSC::IncrementalSweeper::willFinishSweeping): Deleted. * heap/IncrementalSweeper.h: * heap/MachineStackMarker.cpp: (JSC::MachineThreads::gatherFromCurrentThread): (JSC::MachineThreads::gatherConservativeRoots): (JSC::callWithCurrentThreadState): * heap/MachineStackMarker.h: * heap/MarkedAllocator.cpp: (JSC::MarkedAllocator::allocateSlowCaseImpl): * heap/MarkedBlock.cpp: (JSC::MarkedBlock::Handle::sweep): * heap/MarkedSpace.cpp: (JSC::MarkedSpace::sweep): * heap/MutatorState.cpp: (WTF::printInternal): * heap/MutatorState.h: * heap/RegisterState.h: Added. * heap/RunningScope.h: Added. (JSC::RunningScope::RunningScope): (JSC::RunningScope::~RunningScope): * heap/SlotVisitor.cpp: (JSC::SlotVisitor::SlotVisitor): (JSC::SlotVisitor::drain): (JSC::SlotVisitor::drainFromShared): (JSC::SlotVisitor::drainInParallelPassively): (JSC::SlotVisitor::donateAll): (JSC::SlotVisitor::donate): * heap/SlotVisitor.h: (JSC::SlotVisitor::codeName): * heap/StochasticSpaceTimeMutatorScheduler.cpp: (JSC::StochasticSpaceTimeMutatorScheduler::beginCollection): (JSC::StochasticSpaceTimeMutatorScheduler::synchronousDrainingDidStall): (JSC::StochasticSpaceTimeMutatorScheduler::timeToStop): * heap/SweepingScope.h: Added. (JSC::SweepingScope::SweepingScope): (JSC::SweepingScope::~SweepingScope): * jit/JITWorklist.cpp: (JSC::JITWorklist::Thread::Thread): * jsc.cpp: (GlobalObject::finishCreation): (functionFlashHeapAccess): * runtime/InitializeThreading.cpp: (JSC::initializeThreading): * runtime/JSCellInlines.h: (JSC::JSCell::classInfo): * runtime/Options.cpp: (JSC::overrideDefaults): * runtime/Options.h: * runtime/TestRunnerUtils.cpp: (JSC::finalizeStatsAtEndOfTesting): Source/WebCore: Added new tests in JSTests. The WebCore changes involve: - Refactoring around new header discipline. - Adding crazy GC APIs to window.internals to enable us to test the GC's runloop discipline. * ForwardingHeaders/heap/GCFinalizationCallback.h: Added. * ForwardingHeaders/heap/IncrementalSweeper.h: Added. * ForwardingHeaders/heap/MachineStackMarker.h: Added. * ForwardingHeaders/heap/RunningScope.h: Added. * bindings/js/CommonVM.cpp: * testing/Internals.cpp: (WebCore::Internals::parserMetaData): (WebCore::Internals::isReadableStreamDisturbed): (WebCore::Internals::isGCRunning): (WebCore::Internals::addGCFinalizationCallback): (WebCore::Internals::stopSweeping): (WebCore::Internals::startSweeping): * testing/Internals.h: * testing/Internals.idl: Source/WTF: Extend the use of AbstractLocker so that we can use more locking idioms. * wtf/AutomaticThread.cpp: (WTF::AutomaticThreadCondition::notifyOne): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::tryStop): (WTF::AutomaticThread::isWaiting): (WTF::AutomaticThread::notify): (WTF::AutomaticThread::start): (WTF::AutomaticThread::threadIsStopping): * wtf/AutomaticThread.h: * wtf/NumberOfCores.cpp: (WTF::numberOfProcessorCores): * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::claimTask): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::hasClientWithTask): (WTF::ParallelHelperPool::getClientWithTask): * wtf/ParallelHelperPool.h: Tools: Make more tests collect continuously. * Scripts/run-jsc-stress-tests: Canonical link: https://commits.webkit.org/185692@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@212778 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-02-22 00:58:15 +00:00
bool AutomaticThreadCondition::contains(const AbstractLocker&, AutomaticThread* thread)
WTF should make it easier to create threads that die automatically after inactivity https://bugs.webkit.org/show_bug.cgi?id=163576 Reviewed by Andreas Kling. Source/JavaScriptCore: Added a sleepSeconds() function, which made it easier for me to test this change. The WTF changes in this patch change how the JSC GC manages threads: the GC threads will now shut down automatically after 1 second of inactivity. Maybe this will save some memory. * jsc.cpp: (GlobalObject::finishCreation): (functionSleepSeconds): Source/WTF: For a long time now, I've been adding threads to WTF/JSC and each time I do this, I feel guilty because those threads don't shut down when they are inactive. For example, in bug 163562, I need to add a new GC thread. There will be one of them per VM. This means that a JSC API client that starts a lot of VMs will have a lot of threads. I don't think that's good. A common pattern for all of these threads is that they have some well-defined trigger that causes them to run. This trigger has a lock, a condition variable, some logic that determines if there is work to do, and then of course the logic for the thread's actual work. The thread bodies usually look like this: void Thingy::runThread() { for (;;) { Work work; { LockHolder locker(m_lock); while (!hasWork()) m_cond.wait(m_lock); work = takeWork(); } doWork(work); } } If you look at ParallelHelperPool (the GC's threads) and DFG::Worklist (some of the JIT's threads), you will see this pattern. This change adds a new kind of thread, called AutomaticThread, that lets you write threads to this pattern while getting automatic thread shutdown for free: instead of just waiting on a condition variable, AutomaticThread will have a timeout that causes the thread to die. The condition variable associated with AutomaticThread, called AutomaticThreadCondition, is smart enough to restart any threads that have decided to stop due to inactivity. The inactivity threshold is current just 1 second. In this patch I only adopt AutomaticThread for ParallelHelperPool. I plan to adopt it in more places soon. * WTF.xcodeproj/project.pbxproj: * wtf/AutomaticThread.cpp: Added. (WTF::AutomaticThreadCondition::create): (WTF::AutomaticThreadCondition::AutomaticThreadCondition): (WTF::AutomaticThreadCondition::~AutomaticThreadCondition): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Added. * wtf/CMakeLists.txt: * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::ParallelHelperPool): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::helperThreadBody): Deleted. (WTF::ParallelHelperPool::waitForClientWithTask): Deleted. * wtf/ParallelHelperPool.h: Canonical link: https://commits.webkit.org/181393@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207480 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-18 20:17:10 +00:00
{
return m_threads.contains(thread);
}
AutomaticThread::AutomaticThread(const AbstractLocker& locker, Box<Lock> lock, Ref<AutomaticThreadCondition>&& condition, Seconds timeout)
: AutomaticThread(locker, lock, WTFMove(condition), ThreadType::Unknown, timeout)
{
}
AutomaticThread::AutomaticThread(const AbstractLocker& locker, Box<Lock> lock, Ref<AutomaticThreadCondition>&& condition, ThreadType type, Seconds timeout)
WTF should make it easier to create threads that die automatically after inactivity https://bugs.webkit.org/show_bug.cgi?id=163576 Reviewed by Andreas Kling. Source/JavaScriptCore: Added a sleepSeconds() function, which made it easier for me to test this change. The WTF changes in this patch change how the JSC GC manages threads: the GC threads will now shut down automatically after 1 second of inactivity. Maybe this will save some memory. * jsc.cpp: (GlobalObject::finishCreation): (functionSleepSeconds): Source/WTF: For a long time now, I've been adding threads to WTF/JSC and each time I do this, I feel guilty because those threads don't shut down when they are inactive. For example, in bug 163562, I need to add a new GC thread. There will be one of them per VM. This means that a JSC API client that starts a lot of VMs will have a lot of threads. I don't think that's good. A common pattern for all of these threads is that they have some well-defined trigger that causes them to run. This trigger has a lock, a condition variable, some logic that determines if there is work to do, and then of course the logic for the thread's actual work. The thread bodies usually look like this: void Thingy::runThread() { for (;;) { Work work; { LockHolder locker(m_lock); while (!hasWork()) m_cond.wait(m_lock); work = takeWork(); } doWork(work); } } If you look at ParallelHelperPool (the GC's threads) and DFG::Worklist (some of the JIT's threads), you will see this pattern. This change adds a new kind of thread, called AutomaticThread, that lets you write threads to this pattern while getting automatic thread shutdown for free: instead of just waiting on a condition variable, AutomaticThread will have a timeout that causes the thread to die. The condition variable associated with AutomaticThread, called AutomaticThreadCondition, is smart enough to restart any threads that have decided to stop due to inactivity. The inactivity threshold is current just 1 second. In this patch I only adopt AutomaticThread for ParallelHelperPool. I plan to adopt it in more places soon. * WTF.xcodeproj/project.pbxproj: * wtf/AutomaticThread.cpp: Added. (WTF::AutomaticThreadCondition::create): (WTF::AutomaticThreadCondition::AutomaticThreadCondition): (WTF::AutomaticThreadCondition::~AutomaticThreadCondition): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Added. * wtf/CMakeLists.txt: * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::ParallelHelperPool): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::helperThreadBody): Deleted. (WTF::ParallelHelperPool::waitForClientWithTask): Deleted. * wtf/ParallelHelperPool.h: Canonical link: https://commits.webkit.org/181393@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207480 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-18 20:17:10 +00:00
: m_lock(lock)
, m_condition(WTFMove(condition))
[WTF] Add WorkerPool https://bugs.webkit.org/show_bug.cgi?id=174569 Reviewed by Carlos Garcia Campos. Source/WebCore: We start using WorkerPool for NicosiaPaintingEngineThreaded instead of glib thread pool. This makes NicosiaPaintingEngineThreaded platform-independent and usable for WinCairo. * platform/graphics/nicosia/NicosiaPaintingEngineThreaded.cpp: (Nicosia::PaintingEngineThreaded::PaintingEngineThreaded): (Nicosia::PaintingEngineThreaded::~PaintingEngineThreaded): (Nicosia::PaintingEngineThreaded::paint): (Nicosia::s_threadFunc): Deleted. * platform/graphics/nicosia/NicosiaPaintingEngineThreaded.h: Source/WTF: This patch adds WorkerPool, which is a thread pool that consists of AutomaticThread. Since it is based on AutomaticThread, this WorkerPool can take `timeout`: once `timeout` passes without any tasks, threads in WorkerPool will be destroyed. We add shouldSleep handler to AutomaticThread to make destruction of threads in WorkerPool moderate. Without this, all threads are destroyed at once after `timeout` passes. * WTF.xcodeproj/project.pbxproj: * wtf/AutomaticThread.cpp: (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: * wtf/CMakeLists.txt: * wtf/WorkerPool.cpp: Added. (WTF::WorkerPool::WorkerPool): (WTF::WorkerPool::~WorkerPool): (WTF::WorkerPool::shouldSleep): (WTF::WorkerPool::postTask): * wtf/WorkerPool.h: Added. (WTF::WorkerPool::create): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/WorkerPool.cpp: Added. (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/201790@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@232619 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-06-08 08:47:06 +00:00
, m_timeout(timeout)
, m_threadType(type)
WTF should make it easier to create threads that die automatically after inactivity https://bugs.webkit.org/show_bug.cgi?id=163576 Reviewed by Andreas Kling. Source/JavaScriptCore: Added a sleepSeconds() function, which made it easier for me to test this change. The WTF changes in this patch change how the JSC GC manages threads: the GC threads will now shut down automatically after 1 second of inactivity. Maybe this will save some memory. * jsc.cpp: (GlobalObject::finishCreation): (functionSleepSeconds): Source/WTF: For a long time now, I've been adding threads to WTF/JSC and each time I do this, I feel guilty because those threads don't shut down when they are inactive. For example, in bug 163562, I need to add a new GC thread. There will be one of them per VM. This means that a JSC API client that starts a lot of VMs will have a lot of threads. I don't think that's good. A common pattern for all of these threads is that they have some well-defined trigger that causes them to run. This trigger has a lock, a condition variable, some logic that determines if there is work to do, and then of course the logic for the thread's actual work. The thread bodies usually look like this: void Thingy::runThread() { for (;;) { Work work; { LockHolder locker(m_lock); while (!hasWork()) m_cond.wait(m_lock); work = takeWork(); } doWork(work); } } If you look at ParallelHelperPool (the GC's threads) and DFG::Worklist (some of the JIT's threads), you will see this pattern. This change adds a new kind of thread, called AutomaticThread, that lets you write threads to this pattern while getting automatic thread shutdown for free: instead of just waiting on a condition variable, AutomaticThread will have a timeout that causes the thread to die. The condition variable associated with AutomaticThread, called AutomaticThreadCondition, is smart enough to restart any threads that have decided to stop due to inactivity. The inactivity threshold is current just 1 second. In this patch I only adopt AutomaticThread for ParallelHelperPool. I plan to adopt it in more places soon. * WTF.xcodeproj/project.pbxproj: * wtf/AutomaticThread.cpp: Added. (WTF::AutomaticThreadCondition::create): (WTF::AutomaticThreadCondition::AutomaticThreadCondition): (WTF::AutomaticThreadCondition::~AutomaticThreadCondition): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Added. * wtf/CMakeLists.txt: * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::ParallelHelperPool): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::helperThreadBody): Deleted. (WTF::ParallelHelperPool::waitForClientWithTask): Deleted. * wtf/ParallelHelperPool.h: Canonical link: https://commits.webkit.org/181393@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207480 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-18 20:17:10 +00:00
{
The GC should be in a thread https://bugs.webkit.org/show_bug.cgi?id=163562 Reviewed by Geoffrey Garen and Andreas Kling. Source/JavaScriptCore: In a concurrent GC, the work of collecting happens on a separate thread. This patch implements this, and schedules the thread the way that a concurrent GC thread would be scheduled. But, the GC isn't actually concurrent yet because it calls stopTheWorld() before doing anything and calls resumeTheWorld() after it's done with everything. The next step will be to make it really concurrent by basically calling stopTheWorld()/resumeTheWorld() around bounded snippets of work while making most of the work happen with the world running. Our GC will probably always have stop-the-world phases because the semantics of JSC weak references call for it. This implements concurrent GC scheduling. This means that there is no longer a Heap::collect() API. Instead, you can call collectAsync() which makes sure that a GC is scheduled (it will do nothing if one is scheduled or ongoing) or you can call collectSync() to schedule a GC and wait for it to happen. I made our debugging stuff call collectSync(). It should be a goal to never call collectSync() except for debugging or benchmark harness hacks. The collector thread is an AutomaticThread, so it won't linger when not in use. It works on a ticket-based system, like you would see at the DMV. A ticket is a 64-bit integer. There are two ticket counters: last granted and last served. When you request a collection, last granted is incremented and its new value given to you. When a collection completes, last served is incremented. collectSync() waits until last served catches up to what last granted had been at the time you requested a GC. This means that if you request a sync GC in the middle of an async GC, you will wait for that async GC to finish and then you will request and wait for your sync GC. The synchronization between the collector thread and the main threads is complex. The collector thread needs to be able to ask the main thread to stop. It needs to be able to do some post-GC clean-up, like the synchronous CodeBlock and LargeAllocation sweeps, on the main thread. The collector needs to be able to ask the main thread to execute a cross-modifying code fence before running any JIT code, since the GC might aid the JIT worklist and run JIT finalization. It's possible for the GC to want the main thread to run something at the same time that the main thread wants to wait for the GC. The main thread needs to be able to run non-JSC stuff without causing the GC to completely stall. The main thread needs to be able to query its own state (is there a request to stop?) and change it (running JSC versus not) quickly, since this may happen on hot paths. This kind of intertwined system of requests, notifications, and state changes requires a combination of lock-free algorithms and waiting. So, this is all implemented using a Atomic<unsigned> Heap::m_worldState, which has bits to represent things being requested by the collector and the heap access state of the mutator. I am borrowing a lot of terms that I've seen in other VMs that I've worked on. Here's what they mean: - Stop the world: make sure that either the mutator is not running, or that it's not running code that could mess with the heap. - Heap access: the mutator is said to have heap access if it could mess with the heap. If you stop the world and the mutator doesn't have heap access, all you're doing is making sure that it will block when it tries to acquire heap access. This means that our GC is already fully concurrent in cases where the GC is requested while the mutator has no heap access. This probably won't happen, but if it did then it should just work. Usually, stopping the world means that we state our shouldStop request with m_worldState, and a future call to Heap::stopIfNecessary() will go to slow path and stop. The act of stopping or waiting to acquire heap access is managed by using ParkingLot API directly on m_worldState. This works out great because it would be very awkward to get the same functionality using locks and condition variables, since we want stopIfNecessary/acquireAccess/requestAccess fast paths that are single atomic instructions (load/CAS/CAS, respectively). The mutator will call these things frequently. Currently we have Heap::stopIfNecessary() polling on every allocator slow path, but we may want to make it even more frequent than that. Currently only JSC API clients benefit from the heap access optimization. The DOM forces us to assume that heap access is permanently on, since DOM manipulation doesn't always hold the JSLock. We could still allow the GC to proceed when the runloop is idle by having the GC put a task on the runloop that just calls stopIfNecessary(). This is perf neutral. The only behavior change that clients ought to observe is that marking and the weak fixpoint happen on a separate thread. Marking was already parallel so it already handled multiple threads, but now it _never_ runs on the main thread. The weak fixpoint needed some help to be able to run on another thread - mostly because there was some code in IndexedDB that was using thread specifics in the weak fixpoint. * API/JSBase.cpp: (JSSynchronousEdenCollectForDebugging): * API/JSManagedValue.mm: (-[JSManagedValue initWithValue:]): * heap/EdenGCActivityCallback.cpp: (JSC::EdenGCActivityCallback::doCollection): * heap/FullGCActivityCallback.cpp: (JSC::FullGCActivityCallback::doCollection): * heap/Heap.cpp: (JSC::Heap::Thread::Thread): (JSC::Heap::Heap): (JSC::Heap::lastChanceToFinalize): (JSC::Heap::markRoots): (JSC::Heap::gatherStackRoots): (JSC::Heap::deleteUnmarkedCompiledCode): (JSC::Heap::collectAllGarbage): (JSC::Heap::collectAsync): (JSC::Heap::collectSync): (JSC::Heap::shouldCollectInThread): (JSC::Heap::collectInThread): (JSC::Heap::stopTheWorld): (JSC::Heap::resumeTheWorld): (JSC::Heap::stopIfNecessarySlow): (JSC::Heap::acquireAccessSlow): (JSC::Heap::releaseAccessSlow): (JSC::Heap::handleDidJIT): (JSC::Heap::handleNeedFinalize): (JSC::Heap::setDidJIT): (JSC::Heap::setNeedFinalize): (JSC::Heap::waitWhileNeedFinalize): (JSC::Heap::finalize): (JSC::Heap::requestCollection): (JSC::Heap::waitForCollection): (JSC::Heap::didFinishCollection): (JSC::Heap::canCollect): (JSC::Heap::shouldCollectHeuristic): (JSC::Heap::shouldCollect): (JSC::Heap::collectIfNecessaryOrDefer): (JSC::Heap::collectAccordingToDeferGCProbability): (JSC::Heap::collect): Deleted. (JSC::Heap::collectWithoutAnySweep): Deleted. (JSC::Heap::collectImpl): Deleted. * heap/Heap.h: (JSC::Heap::ReleaseAccessScope::ReleaseAccessScope): (JSC::Heap::ReleaseAccessScope::~ReleaseAccessScope): * heap/HeapInlines.h: (JSC::Heap::acquireAccess): (JSC::Heap::releaseAccess): (JSC::Heap::stopIfNecessary): * heap/MachineStackMarker.cpp: (JSC::MachineThreads::gatherConservativeRoots): (JSC::MachineThreads::gatherFromCurrentThread): Deleted. * heap/MachineStackMarker.h: * jit/JITWorklist.cpp: (JSC::JITWorklist::completeAllForVM): * jit/JITWorklist.h: * jsc.cpp: (functionFullGC): (functionEdenGC): * runtime/InitializeThreading.cpp: (JSC::initializeThreading): * runtime/JSLock.cpp: (JSC::JSLock::didAcquireLock): (JSC::JSLock::unlock): (JSC::JSLock::willReleaseLock): * tools/JSDollarVMPrototype.cpp: (JSC::JSDollarVMPrototype::edenGC): Source/WebCore: No new tests because existing tests cover this. We now need to be more careful about using JSLock. This fixes some places that were not holding it. New assertions in the GC are more likely to catch this than before. * bindings/js/WorkerScriptController.cpp: (WebCore::WorkerScriptController::WorkerScriptController): Source/WTF: This fixes some bugs and adds a few features. * wtf/Atomics.h: The GC may do work on behalf of the JIT. If it does, the main thread needs to execute a cross-modifying code fence. This is cpuid on x86 and I believe it's isb on ARM. It would have been an isync on PPC and I think that isb is the ARM equivalent. (WTF::arm_isb): (WTF::crossModifyingCodeFence): (WTF::x86_ortop): (WTF::x86_cpuid): * wtf/AutomaticThread.cpp: I accidentally had AutomaticThreadCondition inherit from ThreadSafeRefCounted<AutomaticThread> [sic]. This never crashed before because all of our prior AutomaticThreadConditions were immortal. (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: * wtf/MainThread.cpp: Need to allow initializeGCThreads() to be called separately because it's now more than just a debugging thing. (WTF::initializeGCThreads): Canonical link: https://commits.webkit.org/182065@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208306 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-02 22:01:04 +00:00
if (verbose)
dataLog(RawPointer(this), ": Allocated AutomaticThread.\n");
WTF should make it easier to create threads that die automatically after inactivity https://bugs.webkit.org/show_bug.cgi?id=163576 Reviewed by Andreas Kling. Source/JavaScriptCore: Added a sleepSeconds() function, which made it easier for me to test this change. The WTF changes in this patch change how the JSC GC manages threads: the GC threads will now shut down automatically after 1 second of inactivity. Maybe this will save some memory. * jsc.cpp: (GlobalObject::finishCreation): (functionSleepSeconds): Source/WTF: For a long time now, I've been adding threads to WTF/JSC and each time I do this, I feel guilty because those threads don't shut down when they are inactive. For example, in bug 163562, I need to add a new GC thread. There will be one of them per VM. This means that a JSC API client that starts a lot of VMs will have a lot of threads. I don't think that's good. A common pattern for all of these threads is that they have some well-defined trigger that causes them to run. This trigger has a lock, a condition variable, some logic that determines if there is work to do, and then of course the logic for the thread's actual work. The thread bodies usually look like this: void Thingy::runThread() { for (;;) { Work work; { LockHolder locker(m_lock); while (!hasWork()) m_cond.wait(m_lock); work = takeWork(); } doWork(work); } } If you look at ParallelHelperPool (the GC's threads) and DFG::Worklist (some of the JIT's threads), you will see this pattern. This change adds a new kind of thread, called AutomaticThread, that lets you write threads to this pattern while getting automatic thread shutdown for free: instead of just waiting on a condition variable, AutomaticThread will have a timeout that causes the thread to die. The condition variable associated with AutomaticThread, called AutomaticThreadCondition, is smart enough to restart any threads that have decided to stop due to inactivity. The inactivity threshold is current just 1 second. In this patch I only adopt AutomaticThread for ParallelHelperPool. I plan to adopt it in more places soon. * WTF.xcodeproj/project.pbxproj: * wtf/AutomaticThread.cpp: Added. (WTF::AutomaticThreadCondition::create): (WTF::AutomaticThreadCondition::AutomaticThreadCondition): (WTF::AutomaticThreadCondition::~AutomaticThreadCondition): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Added. * wtf/CMakeLists.txt: * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::ParallelHelperPool): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::helperThreadBody): Deleted. (WTF::ParallelHelperPool::waitForClientWithTask): Deleted. * wtf/ParallelHelperPool.h: Canonical link: https://commits.webkit.org/181393@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207480 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-18 20:17:10 +00:00
m_condition->add(locker, this);
}
AutomaticThread::~AutomaticThread()
{
The GC should be in a thread https://bugs.webkit.org/show_bug.cgi?id=163562 Reviewed by Geoffrey Garen and Andreas Kling. Source/JavaScriptCore: In a concurrent GC, the work of collecting happens on a separate thread. This patch implements this, and schedules the thread the way that a concurrent GC thread would be scheduled. But, the GC isn't actually concurrent yet because it calls stopTheWorld() before doing anything and calls resumeTheWorld() after it's done with everything. The next step will be to make it really concurrent by basically calling stopTheWorld()/resumeTheWorld() around bounded snippets of work while making most of the work happen with the world running. Our GC will probably always have stop-the-world phases because the semantics of JSC weak references call for it. This implements concurrent GC scheduling. This means that there is no longer a Heap::collect() API. Instead, you can call collectAsync() which makes sure that a GC is scheduled (it will do nothing if one is scheduled or ongoing) or you can call collectSync() to schedule a GC and wait for it to happen. I made our debugging stuff call collectSync(). It should be a goal to never call collectSync() except for debugging or benchmark harness hacks. The collector thread is an AutomaticThread, so it won't linger when not in use. It works on a ticket-based system, like you would see at the DMV. A ticket is a 64-bit integer. There are two ticket counters: last granted and last served. When you request a collection, last granted is incremented and its new value given to you. When a collection completes, last served is incremented. collectSync() waits until last served catches up to what last granted had been at the time you requested a GC. This means that if you request a sync GC in the middle of an async GC, you will wait for that async GC to finish and then you will request and wait for your sync GC. The synchronization between the collector thread and the main threads is complex. The collector thread needs to be able to ask the main thread to stop. It needs to be able to do some post-GC clean-up, like the synchronous CodeBlock and LargeAllocation sweeps, on the main thread. The collector needs to be able to ask the main thread to execute a cross-modifying code fence before running any JIT code, since the GC might aid the JIT worklist and run JIT finalization. It's possible for the GC to want the main thread to run something at the same time that the main thread wants to wait for the GC. The main thread needs to be able to run non-JSC stuff without causing the GC to completely stall. The main thread needs to be able to query its own state (is there a request to stop?) and change it (running JSC versus not) quickly, since this may happen on hot paths. This kind of intertwined system of requests, notifications, and state changes requires a combination of lock-free algorithms and waiting. So, this is all implemented using a Atomic<unsigned> Heap::m_worldState, which has bits to represent things being requested by the collector and the heap access state of the mutator. I am borrowing a lot of terms that I've seen in other VMs that I've worked on. Here's what they mean: - Stop the world: make sure that either the mutator is not running, or that it's not running code that could mess with the heap. - Heap access: the mutator is said to have heap access if it could mess with the heap. If you stop the world and the mutator doesn't have heap access, all you're doing is making sure that it will block when it tries to acquire heap access. This means that our GC is already fully concurrent in cases where the GC is requested while the mutator has no heap access. This probably won't happen, but if it did then it should just work. Usually, stopping the world means that we state our shouldStop request with m_worldState, and a future call to Heap::stopIfNecessary() will go to slow path and stop. The act of stopping or waiting to acquire heap access is managed by using ParkingLot API directly on m_worldState. This works out great because it would be very awkward to get the same functionality using locks and condition variables, since we want stopIfNecessary/acquireAccess/requestAccess fast paths that are single atomic instructions (load/CAS/CAS, respectively). The mutator will call these things frequently. Currently we have Heap::stopIfNecessary() polling on every allocator slow path, but we may want to make it even more frequent than that. Currently only JSC API clients benefit from the heap access optimization. The DOM forces us to assume that heap access is permanently on, since DOM manipulation doesn't always hold the JSLock. We could still allow the GC to proceed when the runloop is idle by having the GC put a task on the runloop that just calls stopIfNecessary(). This is perf neutral. The only behavior change that clients ought to observe is that marking and the weak fixpoint happen on a separate thread. Marking was already parallel so it already handled multiple threads, but now it _never_ runs on the main thread. The weak fixpoint needed some help to be able to run on another thread - mostly because there was some code in IndexedDB that was using thread specifics in the weak fixpoint. * API/JSBase.cpp: (JSSynchronousEdenCollectForDebugging): * API/JSManagedValue.mm: (-[JSManagedValue initWithValue:]): * heap/EdenGCActivityCallback.cpp: (JSC::EdenGCActivityCallback::doCollection): * heap/FullGCActivityCallback.cpp: (JSC::FullGCActivityCallback::doCollection): * heap/Heap.cpp: (JSC::Heap::Thread::Thread): (JSC::Heap::Heap): (JSC::Heap::lastChanceToFinalize): (JSC::Heap::markRoots): (JSC::Heap::gatherStackRoots): (JSC::Heap::deleteUnmarkedCompiledCode): (JSC::Heap::collectAllGarbage): (JSC::Heap::collectAsync): (JSC::Heap::collectSync): (JSC::Heap::shouldCollectInThread): (JSC::Heap::collectInThread): (JSC::Heap::stopTheWorld): (JSC::Heap::resumeTheWorld): (JSC::Heap::stopIfNecessarySlow): (JSC::Heap::acquireAccessSlow): (JSC::Heap::releaseAccessSlow): (JSC::Heap::handleDidJIT): (JSC::Heap::handleNeedFinalize): (JSC::Heap::setDidJIT): (JSC::Heap::setNeedFinalize): (JSC::Heap::waitWhileNeedFinalize): (JSC::Heap::finalize): (JSC::Heap::requestCollection): (JSC::Heap::waitForCollection): (JSC::Heap::didFinishCollection): (JSC::Heap::canCollect): (JSC::Heap::shouldCollectHeuristic): (JSC::Heap::shouldCollect): (JSC::Heap::collectIfNecessaryOrDefer): (JSC::Heap::collectAccordingToDeferGCProbability): (JSC::Heap::collect): Deleted. (JSC::Heap::collectWithoutAnySweep): Deleted. (JSC::Heap::collectImpl): Deleted. * heap/Heap.h: (JSC::Heap::ReleaseAccessScope::ReleaseAccessScope): (JSC::Heap::ReleaseAccessScope::~ReleaseAccessScope): * heap/HeapInlines.h: (JSC::Heap::acquireAccess): (JSC::Heap::releaseAccess): (JSC::Heap::stopIfNecessary): * heap/MachineStackMarker.cpp: (JSC::MachineThreads::gatherConservativeRoots): (JSC::MachineThreads::gatherFromCurrentThread): Deleted. * heap/MachineStackMarker.h: * jit/JITWorklist.cpp: (JSC::JITWorklist::completeAllForVM): * jit/JITWorklist.h: * jsc.cpp: (functionFullGC): (functionEdenGC): * runtime/InitializeThreading.cpp: (JSC::initializeThreading): * runtime/JSLock.cpp: (JSC::JSLock::didAcquireLock): (JSC::JSLock::unlock): (JSC::JSLock::willReleaseLock): * tools/JSDollarVMPrototype.cpp: (JSC::JSDollarVMPrototype::edenGC): Source/WebCore: No new tests because existing tests cover this. We now need to be more careful about using JSLock. This fixes some places that were not holding it. New assertions in the GC are more likely to catch this than before. * bindings/js/WorkerScriptController.cpp: (WebCore::WorkerScriptController::WorkerScriptController): Source/WTF: This fixes some bugs and adds a few features. * wtf/Atomics.h: The GC may do work on behalf of the JIT. If it does, the main thread needs to execute a cross-modifying code fence. This is cpuid on x86 and I believe it's isb on ARM. It would have been an isync on PPC and I think that isb is the ARM equivalent. (WTF::arm_isb): (WTF::crossModifyingCodeFence): (WTF::x86_ortop): (WTF::x86_cpuid): * wtf/AutomaticThread.cpp: I accidentally had AutomaticThreadCondition inherit from ThreadSafeRefCounted<AutomaticThread> [sic]. This never crashed before because all of our prior AutomaticThreadConditions were immortal. (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: * wtf/MainThread.cpp: Need to allow initializeGCThreads() to be called separately because it's now more than just a debugging thing. (WTF::initializeGCThreads): Canonical link: https://commits.webkit.org/182065@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208306 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-02 22:01:04 +00:00
if (verbose)
dataLog(RawPointer(this), ": Deleting AutomaticThread.\n");
Replace LockHolder with Locker in local variables https://bugs.webkit.org/show_bug.cgi?id=226133 Reviewed by Darin Adler. Replace LockHolder with Locker in local variables. It is shorter and it allows switching the lock type more easily since the compiler with deduce the lock type T for Locker<T>. Source/JavaScriptCore: * API/JSCallbackObject.h: (JSC::JSCallbackObjectData::JSPrivatePropertyMap::setPrivateProperty): (JSC::JSCallbackObjectData::JSPrivatePropertyMap::deletePrivateProperty): (JSC::JSCallbackObjectData::JSPrivatePropertyMap::visitChildren): * API/JSValue.mm: (handerForStructTag): * API/tests/testapi.cpp: (testCAPIViaCpp): * assembler/testmasm.cpp: (JSC::run): * b3/air/testair.cpp: * b3/testb3_1.cpp: (run): * bytecode/DirectEvalCodeCache.cpp: (JSC::DirectEvalCodeCache::setSlow): (JSC::DirectEvalCodeCache::clear): (JSC::DirectEvalCodeCache::visitAggregateImpl): * bytecode/SuperSampler.cpp: (JSC::initializeSuperSampler): (JSC::resetSuperSamplerState): (JSC::printSuperSamplerState): (JSC::enableSuperSampler): (JSC::disableSuperSampler): * dfg/DFGCommonData.cpp: (JSC::DFG::CommonData::invalidate): (JSC::DFG::CommonData::~CommonData): (JSC::DFG::CommonData::installVMTrapBreakpoints): (JSC::DFG::codeBlockForVMTrapPC): * dfg/DFGPlan.cpp: (JSC::DFG::Plan::cleanMustHandleValuesIfNecessary): * dfg/DFGWorklist.cpp: (JSC::DFG::Worklist::~Worklist): (JSC::DFG::Worklist::finishCreation): (JSC::DFG::Worklist::isActiveForVM const): (JSC::DFG::Worklist::enqueue): (JSC::DFG::Worklist::compilationState): (JSC::DFG::Worklist::waitUntilAllPlansForVMAreReady): (JSC::DFG::Worklist::removeAllReadyPlansForVM): (JSC::DFG::Worklist::completeAllReadyPlansForVM): (JSC::DFG::Worklist::visitWeakReferences): (JSC::DFG::Worklist::removeDeadPlans): (JSC::DFG::Worklist::removeNonCompilingPlansForVM): (JSC::DFG::Worklist::queueLength): (JSC::DFG::Worklist::dump const): (JSC::DFG::Worklist::setNumberOfThreads): * dfg/DFGWorklistInlines.h: (JSC::DFG::Worklist::iterateCodeBlocksForGC): * disassembler/Disassembler.cpp: * heap/BlockDirectory.cpp: (JSC::BlockDirectory::addBlock): * heap/CodeBlockSetInlines.h: (JSC::CodeBlockSet::iterateCurrentlyExecuting): * heap/ConservativeRoots.cpp: (JSC::ConservativeRoots::add): * heap/Heap.cpp: (JSC::Heap::Heap): (JSC::Heap::lastChanceToFinalize): (JSC::Heap::collectAsync): (JSC::Heap::runBeginPhase): (JSC::Heap::waitForCollector): (JSC::Heap::requestCollection): (JSC::Heap::notifyIsSafeToCollect): * heap/SlotVisitor.cpp: (JSC::SlotVisitor::didReachTermination): * inspector/agents/InspectorScriptProfilerAgent.cpp: (Inspector::InspectorScriptProfilerAgent::startTracking): (Inspector::InspectorScriptProfilerAgent::trackingComplete): (Inspector::InspectorScriptProfilerAgent::stopSamplingWhenDisconnecting): * inspector/remote/RemoteConnectionToTarget.cpp: (Inspector::RemoteConnectionToTarget::setup): (Inspector::RemoteConnectionToTarget::sendMessageToTarget): (Inspector::RemoteConnectionToTarget::close): (Inspector::RemoteConnectionToTarget::targetClosed): * inspector/remote/RemoteInspector.cpp: (Inspector::RemoteInspector::registerTarget): (Inspector::RemoteInspector::unregisterTarget): (Inspector::RemoteInspector::updateTarget): (Inspector::RemoteInspector::updateClientCapabilities): (Inspector::RemoteInspector::setClient): (Inspector::RemoteInspector::setupFailed): (Inspector::RemoteInspector::setupCompleted): (Inspector::RemoteInspector::stop): * inspector/remote/cocoa/RemoteConnectionToTargetCocoa.mm: (Inspector::RemoteTargetHandleRunSourceGlobal): (Inspector::RemoteTargetQueueTaskOnGlobalQueue): (Inspector::RemoteTargetHandleRunSourceWithInfo): (Inspector::RemoteConnectionToTarget::setup): (Inspector::RemoteConnectionToTarget::targetClosed): (Inspector::RemoteConnectionToTarget::close): (Inspector::RemoteConnectionToTarget::sendMessageToTarget): (Inspector::RemoteConnectionToTarget::queueTaskOnPrivateRunLoop): * inspector/remote/cocoa/RemoteInspectorCocoa.mm: (Inspector::RemoteInspector::updateAutomaticInspectionCandidate): (Inspector::RemoteInspector::sendMessageToRemote): (Inspector::RemoteInspector::start): (Inspector::RemoteInspector::setupXPCConnectionIfNeeded): (Inspector::RemoteInspector::setParentProcessInformation): (Inspector::RemoteInspector::xpcConnectionReceivedMessage): (Inspector::RemoteInspector::xpcConnectionFailed): (Inspector::RemoteInspector::pushListingsSoon): (Inspector::RemoteInspector::receivedIndicateMessage): (Inspector::RemoteInspector::receivedProxyApplicationSetupMessage): * inspector/remote/cocoa/RemoteInspectorXPCConnection.mm: (Inspector::RemoteInspectorXPCConnection::close): (Inspector::RemoteInspectorXPCConnection::closeFromMessage): (Inspector::RemoteInspectorXPCConnection::deserializeMessage): (Inspector::RemoteInspectorXPCConnection::handleEvent): * inspector/remote/glib/RemoteInspectorGlib.cpp: (Inspector::RemoteInspector::start): (Inspector::RemoteInspector::setupConnection): (Inspector::RemoteInspector::pushListingsSoon): (Inspector::RemoteInspector::sendMessageToRemote): (Inspector::RemoteInspector::receivedGetTargetListMessage): (Inspector::RemoteInspector::receivedDataMessage): (Inspector::RemoteInspector::receivedCloseMessage): (Inspector::RemoteInspector::setup): * inspector/remote/socket/RemoteInspectorConnectionClient.cpp: (Inspector::RemoteInspectorConnectionClient::didReceive): * inspector/remote/socket/RemoteInspectorSocket.cpp: (Inspector::RemoteInspector::didClose): (Inspector::RemoteInspector::start): (Inspector::RemoteInspector::pushListingsSoon): (Inspector::RemoteInspector::setup): (Inspector::RemoteInspector::setupInspectorClient): (Inspector::RemoteInspector::frontendDidClose): (Inspector::RemoteInspector::sendMessageToBackend): (Inspector::RemoteInspector::startAutomationSession): * inspector/remote/socket/RemoteInspectorSocketEndpoint.cpp: (Inspector::RemoteInspectorSocketEndpoint::listenInet): (Inspector::RemoteInspectorSocketEndpoint::isListening): (Inspector::RemoteInspectorSocketEndpoint::workerThread): (Inspector::RemoteInspectorSocketEndpoint::createClient): (Inspector::RemoteInspectorSocketEndpoint::disconnect): (Inspector::RemoteInspectorSocketEndpoint::invalidateClient): (Inspector::RemoteInspectorSocketEndpoint::invalidateListener): (Inspector::RemoteInspectorSocketEndpoint::getPort const): (Inspector::RemoteInspectorSocketEndpoint::recvIfEnabled): (Inspector::RemoteInspectorSocketEndpoint::sendIfEnabled): (Inspector::RemoteInspectorSocketEndpoint::send): (Inspector::RemoteInspectorSocketEndpoint::acceptInetSocketIfEnabled): * interpreter/CLoopStack.cpp: (JSC::CLoopStack::addToCommittedByteCount): (JSC::CLoopStack::committedByteCount): * jit/ExecutableAllocator.cpp: (JSC::dumpJITMemory): * jit/ICStats.cpp: (JSC::ICStats::ICStats): (JSC::ICStats::~ICStats): * jit/JITThunks.cpp: (JSC::JITThunks::ctiStub): (JSC::JITThunks::existingCTIStub): (JSC::JITThunks::ctiSlowPathFunctionStub): * jit/JITWorklist.cpp: (JSC::JITWorklist::Plan::compileInThread): (JSC::JITWorklist::Plan::isFinishedCompiling): (JSC::JITWorklist::JITWorklist): (JSC::JITWorklist::completeAllForVM): (JSC::JITWorklist::poll): (JSC::JITWorklist::compileLater): (JSC::JITWorklist::finalizePlans): * parser/SourceProvider.cpp: (JSC::SourceProvider::getID): * profiler/ProfilerDatabase.cpp: (JSC::Profiler::Database::ensureBytecodesFor): (JSC::Profiler::Database::notifyDestruction): (JSC::Profiler::Database::addCompilation): (JSC::Profiler::Database::logEvent): (JSC::Profiler::Database::addDatabaseToAtExit): (JSC::Profiler::Database::removeDatabaseFromAtExit): (JSC::Profiler::Database::removeFirstAtExitDatabase): * profiler/ProfilerUID.cpp: (JSC::Profiler::UID::create): * runtime/DeferredWorkTimer.cpp: (JSC::DeferredWorkTimer::scheduleWorkSoon): (JSC::DeferredWorkTimer::didResumeScriptExecutionOwner): * runtime/SamplingProfiler.cpp: (JSC::SamplingProfiler::timerLoop): (JSC::SamplingProfiler::shutdown): (JSC::SamplingProfiler::start): (JSC::SamplingProfiler::noticeCurrentThreadAsJSCExecutionThread): (JSC::SamplingProfiler::noticeJSLockAcquisition): (JSC::SamplingProfiler::noticeVMEntry): (JSC::SamplingProfiler::registerForReportAtExit): * runtime/Watchdog.cpp: (JSC::Watchdog::startTimer): (JSC::Watchdog::willDestroyVM): * tools/VMInspector.cpp: (JSC::VMInspector::isValidExecutableMemory): * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::work): * wasm/WasmEntryPlan.cpp: (JSC::Wasm::EntryPlan::ThreadCountHolder::ThreadCountHolder): (JSC::Wasm::EntryPlan::ThreadCountHolder::~ThreadCountHolder): * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::work): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::addCompletionTask): (JSC::Wasm::Plan::waitForCompletion): (JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast): * wasm/WasmSignature.cpp: (JSC::Wasm::SignatureInformation::signatureFor): (JSC::Wasm::SignatureInformation::tryCleanup): * wasm/WasmWorklist.cpp: (JSC::Wasm::Worklist::enqueue): (JSC::Wasm::Worklist::completePlanSynchronously): (JSC::Wasm::Worklist::stopAllPlansForContext): (JSC::Wasm::Worklist::Worklist): (JSC::Wasm::Worklist::~Worklist): Source/WebCore: * Modules/webaudio/AsyncAudioDecoder.cpp: (WebCore::AsyncAudioDecoder::AsyncAudioDecoder): (WebCore::AsyncAudioDecoder::runLoop): * Modules/webdatabase/Database.cpp: (WebCore::Database::performClose): (WebCore::Database::inProgressTransactionCompleted): (WebCore::Database::hasPendingTransaction): (WebCore::Database::runTransaction): * Modules/webdatabase/DatabaseThread.cpp: (WebCore::DatabaseThread::start): (WebCore::DatabaseThread::databaseThread): (WebCore::DatabaseThread::recordDatabaseOpen): (WebCore::DatabaseThread::recordDatabaseClosed): (WebCore::DatabaseThread::hasPendingDatabaseActivity const): * Modules/webdatabase/DatabaseTracker.cpp: (WebCore::DatabaseTracker::canEstablishDatabase): (WebCore::DatabaseTracker::retryCanEstablishDatabase): (WebCore::DatabaseTracker::maximumSize): (WebCore::DatabaseTracker::fullPathForDatabase): (WebCore::DatabaseTracker::origins): (WebCore::DatabaseTracker::databaseNames): (WebCore::DatabaseTracker::detailsForNameAndOrigin): (WebCore::DatabaseTracker::setDatabaseDetails): (WebCore::DatabaseTracker::doneCreatingDatabase): (WebCore::DatabaseTracker::openDatabases): (WebCore::DatabaseTracker::addOpenDatabase): (WebCore::DatabaseTracker::removeOpenDatabase): (WebCore::DatabaseTracker::originLockFor): (WebCore::DatabaseTracker::quota): (WebCore::DatabaseTracker::setQuota): (WebCore::DatabaseTracker::deleteOrigin): (WebCore::DatabaseTracker::deleteDatabase): (WebCore::DatabaseTracker::deleteDatabaseFile): (WebCore::DatabaseTracker::removeDeletedOpenedDatabases): * Modules/webdatabase/SQLCallbackWrapper.h: (WebCore::SQLCallbackWrapper::clear): (WebCore::SQLCallbackWrapper::unwrap): * Modules/webdatabase/SQLTransaction.cpp: (WebCore::SQLTransaction::enqueueStatement): (WebCore::SQLTransaction::checkAndHandleClosedDatabase): (WebCore::SQLTransaction::getNextStatement): * Modules/webdatabase/SQLTransactionBackend.cpp: (WebCore::SQLTransactionBackend::doCleanup): * accessibility/isolatedtree/AXIsolatedTree.cpp: (WebCore::AXIsolatedTree::clear): (WebCore::AXIsolatedTree::generateSubtree): (WebCore::AXIsolatedTree::createSubtree): (WebCore::AXIsolatedTree::updateNode): (WebCore::AXIsolatedTree::updateNodeProperty): (WebCore::AXIsolatedTree::updateChildren): (WebCore::AXIsolatedTree::focusedNode): (WebCore::AXIsolatedTree::rootNode): (WebCore::AXIsolatedTree::setFocusedNodeID): (WebCore::AXIsolatedTree::removeNode): (WebCore::AXIsolatedTree::removeSubtree): (WebCore::AXIsolatedTree::applyPendingChanges): * page/scrolling/mac/ScrollingTreeMac.mm: (ScrollingTreeMac::scrollingNodeForPoint): (ScrollingTreeMac::eventListenerRegionTypesForPoint const): * platform/AbortableTaskQueue.h: * platform/audio/cocoa/CARingBuffer.cpp: (WebCore::CARingBufferStorageVector::flush): (WebCore::CARingBufferStorageVector::setCurrentFrameBounds): * platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp: (WebCore::AVFWrapper::addToMap): (WebCore::AVFWrapper::removeFromMap const): (WebCore::AVFWrapper::periodicTimeObserverCallback): (WebCore::AVFWrapper::processNotification): (WebCore::AVFWrapper::loadPlayableCompletionCallback): (WebCore::AVFWrapper::loadMetadataCompletionCallback): (WebCore::AVFWrapper::seekCompletedCallback): (WebCore::AVFWrapper::processCue): (WebCore::AVFWrapper::legibleOutputCallback): (WebCore::AVFWrapper::processShouldWaitForLoadingOfResource): (WebCore::AVFWrapper::resourceLoaderShouldWaitForLoadingOfRequestedResource): * platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.mm: (-[WebCoreSharedBufferResourceLoaderDelegate setExpectedContentSize:]): (-[WebCoreSharedBufferResourceLoaderDelegate updateData:complete:]): (-[WebCoreSharedBufferResourceLoaderDelegate resourceLoader:shouldWaitForLoadingOfRequestedResource:]): (-[WebCoreSharedBufferResourceLoaderDelegate resourceLoader:didCancelLoadingRequest:]): (WebCore::ImageDecoderAVFObjC::setTrack): (WebCore::ImageDecoderAVFObjC::createFrameImageAtIndex): * platform/graphics/gstreamer/ImageDecoderGStreamer.cpp: (WebCore::ImageDecoderGStreamer::createFrameImageAtIndex): * platform/graphics/gstreamer/InbandTextTrackPrivateGStreamer.cpp: (WebCore::InbandTextTrackPrivateGStreamer::handleSample): (WebCore::InbandTextTrackPrivateGStreamer::notifyTrackOfSample): * platform/graphics/gstreamer/MainThreadNotifier.h: * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::parseInitDataFromProtectionMessage): (WebCore::MediaPlayerPrivateGStreamer::handleProtectionEvent): * platform/graphics/gstreamer/TrackPrivateBaseGStreamer.cpp: (WebCore::TrackPrivateBaseGStreamer::tagsChanged): (WebCore::TrackPrivateBaseGStreamer::notifyTrackOfTagsChanged): * platform/graphics/gstreamer/VideoSinkGStreamer.cpp: (VideoRenderRequestScheduler::start): (VideoRenderRequestScheduler::stop): (VideoRenderRequestScheduler::drain): (VideoRenderRequestScheduler::requestRender): * platform/graphics/gstreamer/eme/WebKitCommonEncryptionDecryptorGStreamer.cpp: (transformInPlace): (sinkEventHandler): (webKitMediaCommonEncryptionDecryptIsFlushing): (setContext): * platform/graphics/nicosia/NicosiaBuffer.cpp: (Nicosia::Buffer::beginPainting): (Nicosia::Buffer::completePainting): (Nicosia::Buffer::waitUntilPaintingComplete): * platform/graphics/nicosia/NicosiaPlatformLayer.h: (Nicosia::PlatformLayer::setSceneIntegration): (Nicosia::PlatformLayer::createUpdateScope): (Nicosia::CompositionLayer::updateState): (Nicosia::CompositionLayer::flushState): (Nicosia::CompositionLayer::commitState): (Nicosia::CompositionLayer::accessPending): (Nicosia::CompositionLayer::accessCommitted): * platform/graphics/nicosia/NicosiaScene.h: (Nicosia::Scene::accessState): * platform/graphics/nicosia/NicosiaSceneIntegration.cpp: (Nicosia::SceneIntegration::setClient): (Nicosia::SceneIntegration::invalidate): (Nicosia::SceneIntegration::requestUpdate): * platform/graphics/nicosia/texmap/NicosiaBackingStoreTextureMapperImpl.cpp: (Nicosia::BackingStoreTextureMapperImpl::flushUpdate): (Nicosia::BackingStoreTextureMapperImpl::takeUpdate): * platform/graphics/nicosia/texmap/NicosiaContentLayerTextureMapperImpl.cpp: (Nicosia::ContentLayerTextureMapperImpl::~ContentLayerTextureMapperImpl): (Nicosia::ContentLayerTextureMapperImpl::invalidateClient): (Nicosia::ContentLayerTextureMapperImpl::flushUpdate): (Nicosia::ContentLayerTextureMapperImpl::swapBuffersIfNeeded): * platform/graphics/nicosia/texmap/NicosiaImageBackingTextureMapperImpl.cpp: (Nicosia::ImageBackingTextureMapperImpl::flushUpdate): (Nicosia::ImageBackingTextureMapperImpl::takeUpdate): * platform/graphics/texmap/TextureMapperGCGLPlatformLayer.cpp: (WebCore::TextureMapperGCGLPlatformLayer::swapBuffersIfNeeded): * platform/graphics/win/MediaPlayerPrivateMediaFoundation.cpp: (WebCore::MediaPlayerPrivateMediaFoundation::load): (WebCore::MediaPlayerPrivateMediaFoundation::naturalSize const): (WebCore::MediaPlayerPrivateMediaFoundation::addListener): (WebCore::MediaPlayerPrivateMediaFoundation::removeListener): (WebCore::MediaPlayerPrivateMediaFoundation::notifyDeleted): (WebCore::MediaPlayerPrivateMediaFoundation::setNaturalSize): (WebCore::MediaPlayerPrivateMediaFoundation::AsyncCallback::Invoke): (WebCore::MediaPlayerPrivateMediaFoundation::AsyncCallback::onMediaPlayerDeleted): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::OnClockStart): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::OnClockStop): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::OnClockPause): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::OnClockRestart): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::OnClockSetRate): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::ProcessMessage): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::GetCurrentMediaType): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::InitServicePointers): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::ReleaseServicePointers): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::SetVideoWindow): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::GetVideoWindow): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::SetVideoPosition): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::GetVideoPosition): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::RepaintVideo): (WebCore::MediaPlayerPrivateMediaFoundation::VideoSamplePool::getSample): (WebCore::MediaPlayerPrivateMediaFoundation::VideoSamplePool::returnSample): (WebCore::MediaPlayerPrivateMediaFoundation::VideoSamplePool::areSamplesPending): (WebCore::MediaPlayerPrivateMediaFoundation::VideoSamplePool::initialize): (WebCore::MediaPlayerPrivateMediaFoundation::VideoSamplePool::clear): (WebCore::MediaPlayerPrivateMediaFoundation::VideoScheduler::stopScheduler): (WebCore::MediaPlayerPrivateMediaFoundation::VideoScheduler::scheduleSample): (WebCore::MediaPlayerPrivateMediaFoundation::VideoScheduler::processSamplesInQueue): (WebCore::MediaPlayerPrivateMediaFoundation::VideoScheduler::processSample): (WebCore::MediaPlayerPrivateMediaFoundation::VideoScheduler::schedulerThreadProcPrivate): (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::setVideoWindow): (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::setDestinationRect): (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::createVideoSamples): (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::checkDeviceState): (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::presentSample): (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::paintCurrentFrame): (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::createD3DDevice): * platform/image-decoders/ScalableImageDecoder.cpp: (WebCore::ScalableImageDecoder::frameIsCompleteAtIndex const): (WebCore::ScalableImageDecoder::frameHasAlphaAtIndex const): (WebCore::ScalableImageDecoder::frameBytesAtIndex const): (WebCore::ScalableImageDecoder::frameDurationAtIndex const): (WebCore::ScalableImageDecoder::createFrameImageAtIndex): * platform/image-decoders/ScalableImageDecoder.h: * platform/ios/LegacyTileCache.mm: (WebCore::LegacyTileCache::setTilesOpaque): (WebCore::LegacyTileCache::doLayoutTiles): (WebCore::LegacyTileCache::setCurrentScale): (WebCore::LegacyTileCache::commitScaleChange): (WebCore::LegacyTileCache::layoutTilesNow): (WebCore::LegacyTileCache::layoutTilesNowForRect): (WebCore::LegacyTileCache::removeAllNonVisibleTiles): (WebCore::LegacyTileCache::removeAllTiles): (WebCore::LegacyTileCache::removeForegroundTiles): (WebCore::LegacyTileCache::setContentReplacementImage): (WebCore::LegacyTileCache::contentReplacementImage const): (WebCore::LegacyTileCache::tileCreationTimerFired): (WebCore::LegacyTileCache::setNeedsDisplayInRect): (WebCore::LegacyTileCache::updateTilingMode): (WebCore::LegacyTileCache::setTilingMode): (WebCore::LegacyTileCache::doPendingRepaints): (WebCore::LegacyTileCache::flushSavedDisplayRects): (WebCore::LegacyTileCache::prepareToDraw): * platform/ios/LegacyTileLayerPool.mm: (WebCore::LegacyTileLayerPool::addLayer): (WebCore::LegacyTileLayerPool::takeLayerWithSize): (WebCore::LegacyTileLayerPool::setCapacity): (WebCore::LegacyTileLayerPool::prune): (WebCore::LegacyTileLayerPool::drain): * platform/ios/wak/WAKWindow.mm: (-[WAKWindow setExposedScrollViewRect:]): (-[WAKWindow exposedScrollViewRect]): * platform/ios/wak/WebCoreThread.mm: (RunWebThread): (StartWebThread): * platform/mediastream/gstreamer/RealtimeOutgoingAudioSourceLibWebRTC.cpp: (WebCore::RealtimeOutgoingAudioSourceLibWebRTC::audioSamplesAvailable): (WebCore::RealtimeOutgoingAudioSourceLibWebRTC::pullAudioData): * platform/network/cf/FormDataStreamCFNet.cpp: (WebCore::openNextStream): (WebCore::formFinalize): (WebCore::formClose): * platform/network/curl/CurlRequest.cpp: (WebCore::CurlRequest::setRequestPaused): (WebCore::CurlRequest::setCallbackPaused): (WebCore::CurlRequest::pausedStatusChanged): (WebCore::CurlRequest::enableDownloadToFile): (WebCore::CurlRequest::getDownloadedFilePath): (WebCore::CurlRequest::writeDataToDownloadFileIfEnabled): (WebCore::CurlRequest::closeDownloadFile): (WebCore::CurlRequest::cleanupDownloadFile): * platform/network/curl/CurlSSLHandle.cpp: (WebCore::CurlSSLHandle::allowAnyHTTPSCertificatesForHost): (WebCore::CurlSSLHandle::canIgnoreAnyHTTPSCertificatesForHost const): (WebCore::CurlSSLHandle::setClientCertificateInfo): (WebCore::CurlSSLHandle::getSSLClientCertificate const): * platform/sql/SQLiteDatabase.cpp: (WebCore::SQLiteDatabase::close): (WebCore::SQLiteDatabase::maximumSize): (WebCore::SQLiteDatabase::setMaximumSize): (WebCore::SQLiteDatabase::pageSize): (WebCore::SQLiteDatabase::freeSpaceSize): (WebCore::SQLiteDatabase::totalSize): (WebCore::SQLiteDatabase::runIncrementalVacuumCommand): (WebCore::SQLiteDatabase::interrupt): (WebCore::SQLiteDatabase::setAuthorizer): (WebCore::constructAndPrepareStatement): * platform/sql/SQLiteStatement.cpp: (WebCore::SQLiteStatement::step): Source/WebKit: * NetworkProcess/IndexedDB/WebIDBServer.cpp: (WebKit::m_closeCallback): (WebKit::WebIDBServer::getOrigins): (WebKit::WebIDBServer::closeAndDeleteDatabasesModifiedSince): (WebKit::WebIDBServer::closeAndDeleteDatabasesForOrigins): (WebKit::WebIDBServer::renameOrigin): (WebKit::WebIDBServer::openDatabase): (WebKit::WebIDBServer::deleteDatabase): (WebKit::WebIDBServer::abortTransaction): (WebKit::WebIDBServer::commitTransaction): (WebKit::WebIDBServer::didFinishHandlingVersionChangeTransaction): (WebKit::WebIDBServer::createObjectStore): (WebKit::WebIDBServer::deleteObjectStore): (WebKit::WebIDBServer::renameObjectStore): (WebKit::WebIDBServer::clearObjectStore): (WebKit::WebIDBServer::createIndex): (WebKit::WebIDBServer::deleteIndex): (WebKit::WebIDBServer::renameIndex): (WebKit::WebIDBServer::putOrAdd): (WebKit::WebIDBServer::getRecord): (WebKit::WebIDBServer::getAllRecords): (WebKit::WebIDBServer::getCount): (WebKit::WebIDBServer::deleteRecord): (WebKit::WebIDBServer::openCursor): (WebKit::WebIDBServer::iterateCursor): (WebKit::WebIDBServer::establishTransaction): (WebKit::WebIDBServer::databaseConnectionPendingClose): (WebKit::WebIDBServer::databaseConnectionClosed): (WebKit::WebIDBServer::abortOpenAndUpgradeNeeded): (WebKit::WebIDBServer::didFireVersionChangeEvent): (WebKit::WebIDBServer::openDBRequestCancelled): (WebKit::WebIDBServer::getAllDatabaseNamesAndVersions): (WebKit::WebIDBServer::addConnection): (WebKit::WebIDBServer::removeConnection): (WebKit::WebIDBServer::close): * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::writeSizeFile): (WebKit::CacheStorage::Engine::readSizeFile): (WebKit::CacheStorage::Engine::clearAllCachesFromDisk): (WebKit::CacheStorage::Engine::deleteNonEmptyDirectoryOnBackgroundThread): * NetworkProcess/glib/DNSCache.cpp: (WebKit::DNSCache::lookup): (WebKit::DNSCache::update): (WebKit::DNSCache::removeExpiredResponsesFired): (WebKit::DNSCache::clear): * Shared/CoordinatedGraphics/threadedcompositor/CompositingRunLoop.cpp: (WebKit::CompositingRunLoop::suspend): (WebKit::CompositingRunLoop::resume): (WebKit::CompositingRunLoop::scheduleUpdate): (WebKit::CompositingRunLoop::stopUpdates): (WebKit::CompositingRunLoop::updateTimerFired): * Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp: (WebKit::m_displayRefreshMonitor): (WebKit::ThreadedCompositor::setScaleFactor): (WebKit::ThreadedCompositor::setScrollPosition): (WebKit::ThreadedCompositor::setViewportSize): (WebKit::ThreadedCompositor::renderLayerTree): (WebKit::ThreadedCompositor::sceneUpdateFinished): (WebKit::ThreadedCompositor::updateSceneState): * UIProcess/API/glib/IconDatabase.cpp: (WebKit::IconDatabase::populatePageURLToIconURLMap): (WebKit::IconDatabase::clearLoadedIconsTimerFired): (WebKit::IconDatabase::checkIconURLAndSetPageURLIfNeeded): (WebKit::IconDatabase::loadIconForPageURL): (WebKit::IconDatabase::iconURLForPageURL): (WebKit::IconDatabase::setIconForPageURL): (WebKit::IconDatabase::clear): Source/WebKitLegacy: * Storage/InProcessIDBServer.cpp: (InProcessIDBServer::InProcessIDBServer): (InProcessIDBServer::deleteDatabase): (InProcessIDBServer::openDatabase): (InProcessIDBServer::abortTransaction): (InProcessIDBServer::commitTransaction): (InProcessIDBServer::didFinishHandlingVersionChangeTransaction): (InProcessIDBServer::createObjectStore): (InProcessIDBServer::deleteObjectStore): (InProcessIDBServer::renameObjectStore): (InProcessIDBServer::clearObjectStore): (InProcessIDBServer::createIndex): (InProcessIDBServer::deleteIndex): (InProcessIDBServer::renameIndex): (InProcessIDBServer::putOrAdd): (InProcessIDBServer::getRecord): (InProcessIDBServer::getAllRecords): (InProcessIDBServer::getCount): (InProcessIDBServer::deleteRecord): (InProcessIDBServer::openCursor): (InProcessIDBServer::iterateCursor): (InProcessIDBServer::establishTransaction): (InProcessIDBServer::databaseConnectionPendingClose): (InProcessIDBServer::databaseConnectionClosed): (InProcessIDBServer::abortOpenAndUpgradeNeeded): (InProcessIDBServer::didFireVersionChangeEvent): (InProcessIDBServer::openDBRequestCancelled): (InProcessIDBServer::getAllDatabaseNamesAndVersions): (InProcessIDBServer::closeAndDeleteDatabasesModifiedSince): * Storage/StorageAreaSync.cpp: (WebKit::StorageAreaSync::syncTimerFired): (WebKit::StorageAreaSync::performSync): * Storage/StorageTracker.cpp: (WebKit::StorageTracker::finishedImportingOriginIdentifiers): (WebKit::StorageTracker::syncImportOriginIdentifiers): (WebKit::StorageTracker::syncFileSystemAndTrackerDatabase): (WebKit::StorageTracker::setOriginDetails): (WebKit::StorageTracker::syncSetOriginDetails): (WebKit::StorageTracker::origins): (WebKit::StorageTracker::deleteAllOrigins): (WebKit::StorageTracker::syncDeleteAllOrigins): (WebKit::StorageTracker::deleteOrigin): (WebKit::StorageTracker::syncDeleteOrigin): (WebKit::StorageTracker::canDeleteOrigin): (WebKit::StorageTracker::cancelDeletingOrigin): (WebKit::StorageTracker::diskUsageForOrigin): Source/WebKitLegacy/mac: * WebView/WebView.mm: (-[WebView _synchronizeCustomFixedPositionLayoutRect]): (-[WebView _setCustomFixedPositionLayoutRectInWebThread:synchronize:]): (-[WebView _setCustomFixedPositionLayoutRect:]): (-[WebView _fetchCustomFixedPositionLayoutRect:]): Source/WebKitLegacy/win: * Plugins/PluginMainThreadScheduler.cpp: (WebCore::PluginMainThreadScheduler::scheduleCall): (WebCore::PluginMainThreadScheduler::registerPlugin): (WebCore::PluginMainThreadScheduler::unregisterPlugin): (WebCore::PluginMainThreadScheduler::dispatchCallsForPlugin): Source/WTF: * benchmarks/LockSpeedTest.cpp: * wtf/AutomaticThread.cpp: (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: * wtf/MetaAllocator.cpp: (WTF::MetaAllocatorHandle::shrink): (WTF::MetaAllocator::addFreshFreeSpace): (WTF::MetaAllocator::debugFreeSpaceSize): * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): * wtf/Seconds.cpp: (WTF::sleep): * wtf/TimeWithDynamicClockType.cpp: (WTF::sleep): * wtf/WorkerPool.cpp: (WTF::WorkerPool::WorkerPool): (WTF::WorkerPool::~WorkerPool): (WTF::WorkerPool::postTask): * wtf/posix/ThreadingPOSIX.cpp: (WTF::Thread::suspend): (WTF::Thread::resume): (WTF::Thread::getRegisters): * wtf/win/DbgHelperWin.cpp: (WTF::DbgHelper::SymFromAddress): * wtf/win/ThreadingWin.cpp: (WTF::Thread::suspend): (WTF::Thread::resume): (WTF::Thread::getRegisters): Tools: * TestWebKitAPI/Tests/WTF/WorkQueue.cpp: (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/WTF/glib/WorkQueueGLib.cpp: (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/WebCore/AbortableTaskQueue.cpp: (TestWebKitAPI::DeterministicScheduler::ThreadContext::waitMyTurn): (TestWebKitAPI::DeterministicScheduler::ThreadContext::yieldToThread): Canonical link: https://commits.webkit.org/238053@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@277920 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-05-22 16:49:42 +00:00
Locker locker { *m_lock };
WTF should make it easier to create threads that die automatically after inactivity https://bugs.webkit.org/show_bug.cgi?id=163576 Reviewed by Andreas Kling. Source/JavaScriptCore: Added a sleepSeconds() function, which made it easier for me to test this change. The WTF changes in this patch change how the JSC GC manages threads: the GC threads will now shut down automatically after 1 second of inactivity. Maybe this will save some memory. * jsc.cpp: (GlobalObject::finishCreation): (functionSleepSeconds): Source/WTF: For a long time now, I've been adding threads to WTF/JSC and each time I do this, I feel guilty because those threads don't shut down when they are inactive. For example, in bug 163562, I need to add a new GC thread. There will be one of them per VM. This means that a JSC API client that starts a lot of VMs will have a lot of threads. I don't think that's good. A common pattern for all of these threads is that they have some well-defined trigger that causes them to run. This trigger has a lock, a condition variable, some logic that determines if there is work to do, and then of course the logic for the thread's actual work. The thread bodies usually look like this: void Thingy::runThread() { for (;;) { Work work; { LockHolder locker(m_lock); while (!hasWork()) m_cond.wait(m_lock); work = takeWork(); } doWork(work); } } If you look at ParallelHelperPool (the GC's threads) and DFG::Worklist (some of the JIT's threads), you will see this pattern. This change adds a new kind of thread, called AutomaticThread, that lets you write threads to this pattern while getting automatic thread shutdown for free: instead of just waiting on a condition variable, AutomaticThread will have a timeout that causes the thread to die. The condition variable associated with AutomaticThread, called AutomaticThreadCondition, is smart enough to restart any threads that have decided to stop due to inactivity. The inactivity threshold is current just 1 second. In this patch I only adopt AutomaticThread for ParallelHelperPool. I plan to adopt it in more places soon. * WTF.xcodeproj/project.pbxproj: * wtf/AutomaticThread.cpp: Added. (WTF::AutomaticThreadCondition::create): (WTF::AutomaticThreadCondition::AutomaticThreadCondition): (WTF::AutomaticThreadCondition::~AutomaticThreadCondition): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Added. * wtf/CMakeLists.txt: * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::ParallelHelperPool): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::helperThreadBody): Deleted. (WTF::ParallelHelperPool::waitForClientWithTask): Deleted. * wtf/ParallelHelperPool.h: Canonical link: https://commits.webkit.org/181393@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207480 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-18 20:17:10 +00:00
// It's possible that we're in a waiting state with the thread shut down. This is a goofy way to
// die, but it could happen.
m_condition->remove(locker, this);
}
The collector thread should only start when the mutator doesn't have heap access https://bugs.webkit.org/show_bug.cgi?id=167737 Reviewed by Keith Miller. JSTests: Add versions of splay that flash heap access, to simulate what might happen if a third-party app was running concurrent GC. In this case, we might actually start the collector thread. * stress/splay-flash-access-1ms.js: Added. (performance.now): (this.Setup.setup.setup): (this.TearDown.tearDown.tearDown): (Benchmark): (BenchmarkResult): (BenchmarkResult.prototype.valueOf): (BenchmarkSuite): (alert): (Math.random): (BenchmarkSuite.ResetRNG): (RunStep): (BenchmarkSuite.RunSuites): (BenchmarkSuite.CountBenchmarks): (BenchmarkSuite.GeometricMean): (BenchmarkSuite.GeometricMeanTime): (BenchmarkSuite.AverageAbovePercentile): (BenchmarkSuite.GeometricMeanLatency): (BenchmarkSuite.FormatScore): (BenchmarkSuite.prototype.NotifyStep): (BenchmarkSuite.prototype.NotifyResult): (BenchmarkSuite.prototype.NotifyError): (BenchmarkSuite.prototype.RunSingleBenchmark): (RunNextSetup): (RunNextBenchmark): (RunNextTearDown): (BenchmarkSuite.prototype.RunStep): (GeneratePayloadTree): (GenerateKey): (SplayUpdateStats): (InsertNewNode): (SplaySetup): (SplayTearDown): (SplayRun): (SplayTree): (SplayTree.prototype.isEmpty): (SplayTree.prototype.insert): (SplayTree.prototype.remove): (SplayTree.prototype.find): (SplayTree.prototype.findMax): (SplayTree.prototype.findGreatestLessThan): (SplayTree.prototype.exportKeys): (SplayTree.prototype.splay_): (SplayTree.Node): (SplayTree.Node.prototype.traverse_): (jscSetUp): (jscTearDown): (jscRun): (averageAbovePercentile): (printPercentile): * stress/splay-flash-access.js: Added. (performance.now): (this.Setup.setup.setup): (this.TearDown.tearDown.tearDown): (Benchmark): (BenchmarkResult): (BenchmarkResult.prototype.valueOf): (BenchmarkSuite): (alert): (Math.random): (BenchmarkSuite.ResetRNG): (RunStep): (BenchmarkSuite.RunSuites): (BenchmarkSuite.CountBenchmarks): (BenchmarkSuite.GeometricMean): (BenchmarkSuite.GeometricMeanTime): (BenchmarkSuite.AverageAbovePercentile): (BenchmarkSuite.GeometricMeanLatency): (BenchmarkSuite.FormatScore): (BenchmarkSuite.prototype.NotifyStep): (BenchmarkSuite.prototype.NotifyResult): (BenchmarkSuite.prototype.NotifyError): (BenchmarkSuite.prototype.RunSingleBenchmark): (RunNextSetup): (RunNextBenchmark): (RunNextTearDown): (BenchmarkSuite.prototype.RunStep): (GeneratePayloadTree): (GenerateKey): (SplayUpdateStats): (InsertNewNode): (SplaySetup): (SplayTearDown): (SplayRun): (SplayTree): (SplayTree.prototype.isEmpty): (SplayTree.prototype.insert): (SplayTree.prototype.remove): (SplayTree.prototype.find): (SplayTree.prototype.findMax): (SplayTree.prototype.findGreatestLessThan): (SplayTree.prototype.exportKeys): (SplayTree.prototype.splay_): (SplayTree.Node): (SplayTree.Node.prototype.traverse_): (jscSetUp): (jscTearDown): (jscRun): (averageAbovePercentile): (printPercentile): Source/JavaScriptCore: This turns the collector thread's workflow into a state machine, so that the mutator thread can run it directly. This reduces the amount of synchronization we do with the collector thread, and means that most apps will never start the collector thread. The collector thread will still start when we need to finish collecting and we don't have heap access. In this new world, "stopping the world" means relinquishing control of collection to the mutator. This means tracking who is conducting collection. I use the GCConductor enum to say who is conducting. It's either GCConductor::Mutator or GCConductor::Collector. I use the term "conn" to refer to the concept of conducting (having the conn, relinquishing the conn, taking the conn). So, stopping the world means giving the mutator the conn. Releasing heap access means giving the collector the conn. This meant bringing back the conservative scan of the calling thread. It turns out that this scan was too slow to be called on each GC increment because apparently setjmp() now does system calls. So, I wrote our own callee save register saving for the GC. Then I had doubts about whether or not it was correct, so I also made it so that the GC only rarely asks for the register state. I think we still want to use my register saving code instead of setjmp because setjmp seems to save things we don't need, and that could make us overly conservative. It turns out that this new scheduling discipline makes the old space-time scheduler perform better than the new stochastic space-time scheduler on systems with fewer than 4 cores. This is because the mutator having the conn enables us to time the mutator<->collector context switches by polling. The OS is never involved. So, we can use super precise timing. This allows the old space-time schduler to shine like it hadn't before. The splay results imply that this is all a good thing. On 2-core systems, this reduces pause times by 40% and it increases throughput about 5%. On 1-core systems, this reduces pause times by half and reduces throughput by 8%. On 4-or-more-core systems, this doesn't seem to have much effect. * CMakeLists.txt: * JavaScriptCore.xcodeproj/project.pbxproj: * bytecode/CodeBlock.cpp: (JSC::CodeBlock::visitChildren): * dfg/DFGWorklist.cpp: (JSC::DFG::Worklist::ThreadBody::ThreadBody): (JSC::DFG::Worklist::dump): (JSC::DFG::numberOfWorklists): (JSC::DFG::ensureWorklistForIndex): (JSC::DFG::existingWorklistForIndexOrNull): (JSC::DFG::existingWorklistForIndex): * dfg/DFGWorklist.h: (JSC::DFG::numberOfWorklists): Deleted. (JSC::DFG::ensureWorklistForIndex): Deleted. (JSC::DFG::existingWorklistForIndexOrNull): Deleted. (JSC::DFG::existingWorklistForIndex): Deleted. * heap/CollectingScope.h: Added. (JSC::CollectingScope::CollectingScope): (JSC::CollectingScope::~CollectingScope): * heap/CollectorPhase.cpp: Added. (JSC::worldShouldBeSuspended): (WTF::printInternal): * heap/CollectorPhase.h: Added. * heap/EdenGCActivityCallback.cpp: (JSC::EdenGCActivityCallback::lastGCLength): * heap/FullGCActivityCallback.cpp: (JSC::FullGCActivityCallback::doCollection): (JSC::FullGCActivityCallback::lastGCLength): * heap/GCConductor.cpp: Added. (JSC::gcConductorShortName): (WTF::printInternal): * heap/GCConductor.h: Added. * heap/GCFinalizationCallback.cpp: Added. (JSC::GCFinalizationCallback::GCFinalizationCallback): (JSC::GCFinalizationCallback::~GCFinalizationCallback): * heap/GCFinalizationCallback.h: Added. (JSC::GCFinalizationCallbackFuncAdaptor::GCFinalizationCallbackFuncAdaptor): (JSC::createGCFinalizationCallback): * heap/Heap.cpp: (JSC::Heap::Thread::Thread): (JSC::Heap::Heap): (JSC::Heap::lastChanceToFinalize): (JSC::Heap::gatherStackRoots): (JSC::Heap::updateObjectCounts): (JSC::Heap::sweepSynchronously): (JSC::Heap::collectAllGarbage): (JSC::Heap::collectAsync): (JSC::Heap::collectSync): (JSC::Heap::shouldCollectInCollectorThread): (JSC::Heap::collectInCollectorThread): (JSC::Heap::checkConn): (JSC::Heap::runNotRunningPhase): (JSC::Heap::runBeginPhase): (JSC::Heap::runFixpointPhase): (JSC::Heap::runConcurrentPhase): (JSC::Heap::runReloopPhase): (JSC::Heap::runEndPhase): (JSC::Heap::changePhase): (JSC::Heap::finishChangingPhase): (JSC::Heap::stopThePeriphery): (JSC::Heap::resumeThePeriphery): (JSC::Heap::stopTheMutator): (JSC::Heap::resumeTheMutator): (JSC::Heap::stopIfNecessarySlow): (JSC::Heap::collectInMutatorThread): (JSC::Heap::waitForCollector): (JSC::Heap::acquireAccessSlow): (JSC::Heap::releaseAccessSlow): (JSC::Heap::relinquishConn): (JSC::Heap::finishRelinquishingConn): (JSC::Heap::handleNeedFinalize): (JSC::Heap::notifyThreadStopping): (JSC::Heap::finalize): (JSC::Heap::addFinalizationCallback): (JSC::Heap::requestCollection): (JSC::Heap::waitForCollection): (JSC::Heap::updateAllocationLimits): (JSC::Heap::didFinishCollection): (JSC::Heap::collectIfNecessaryOrDefer): (JSC::Heap::notifyIsSafeToCollect): (JSC::Heap::preventCollection): (JSC::Heap::performIncrement): (JSC::Heap::markToFixpoint): Deleted. (JSC::Heap::shouldCollectInThread): Deleted. (JSC::Heap::collectInThread): Deleted. (JSC::Heap::stopTheWorld): Deleted. (JSC::Heap::resumeTheWorld): Deleted. * heap/Heap.h: (JSC::Heap::machineThreads): (JSC::Heap::lastFullGCLength): (JSC::Heap::lastEdenGCLength): (JSC::Heap::increaseLastFullGCLength): * heap/HeapInlines.h: (JSC::Heap::mutatorIsStopped): Deleted. * heap/HeapStatistics.cpp: Removed. * heap/HeapStatistics.h: Removed. * heap/HelpingGCScope.h: Removed. * heap/IncrementalSweeper.cpp: (JSC::IncrementalSweeper::stopSweeping): (JSC::IncrementalSweeper::willFinishSweeping): Deleted. * heap/IncrementalSweeper.h: * heap/MachineStackMarker.cpp: (JSC::MachineThreads::gatherFromCurrentThread): (JSC::MachineThreads::gatherConservativeRoots): (JSC::callWithCurrentThreadState): * heap/MachineStackMarker.h: * heap/MarkedAllocator.cpp: (JSC::MarkedAllocator::allocateSlowCaseImpl): * heap/MarkedBlock.cpp: (JSC::MarkedBlock::Handle::sweep): * heap/MarkedSpace.cpp: (JSC::MarkedSpace::sweep): * heap/MutatorState.cpp: (WTF::printInternal): * heap/MutatorState.h: * heap/RegisterState.h: Added. * heap/RunningScope.h: Added. (JSC::RunningScope::RunningScope): (JSC::RunningScope::~RunningScope): * heap/SlotVisitor.cpp: (JSC::SlotVisitor::SlotVisitor): (JSC::SlotVisitor::drain): (JSC::SlotVisitor::drainFromShared): (JSC::SlotVisitor::drainInParallelPassively): (JSC::SlotVisitor::donateAll): (JSC::SlotVisitor::donate): * heap/SlotVisitor.h: (JSC::SlotVisitor::codeName): * heap/StochasticSpaceTimeMutatorScheduler.cpp: (JSC::StochasticSpaceTimeMutatorScheduler::beginCollection): (JSC::StochasticSpaceTimeMutatorScheduler::synchronousDrainingDidStall): (JSC::StochasticSpaceTimeMutatorScheduler::timeToStop): * heap/SweepingScope.h: Added. (JSC::SweepingScope::SweepingScope): (JSC::SweepingScope::~SweepingScope): * jit/JITWorklist.cpp: (JSC::JITWorklist::Thread::Thread): * jsc.cpp: (GlobalObject::finishCreation): (functionFlashHeapAccess): * runtime/InitializeThreading.cpp: (JSC::initializeThreading): * runtime/JSCellInlines.h: (JSC::JSCell::classInfo): * runtime/Options.cpp: (JSC::overrideDefaults): * runtime/Options.h: * runtime/TestRunnerUtils.cpp: (JSC::finalizeStatsAtEndOfTesting): Source/WebCore: Added new tests in JSTests. The WebCore changes involve: - Refactoring around new header discipline. - Adding crazy GC APIs to window.internals to enable us to test the GC's runloop discipline. * ForwardingHeaders/heap/GCFinalizationCallback.h: Added. * ForwardingHeaders/heap/IncrementalSweeper.h: Added. * ForwardingHeaders/heap/MachineStackMarker.h: Added. * ForwardingHeaders/heap/RunningScope.h: Added. * bindings/js/CommonVM.cpp: * testing/Internals.cpp: (WebCore::Internals::parserMetaData): (WebCore::Internals::isReadableStreamDisturbed): (WebCore::Internals::isGCRunning): (WebCore::Internals::addGCFinalizationCallback): (WebCore::Internals::stopSweeping): (WebCore::Internals::startSweeping): * testing/Internals.h: * testing/Internals.idl: Source/WTF: Extend the use of AbstractLocker so that we can use more locking idioms. * wtf/AutomaticThread.cpp: (WTF::AutomaticThreadCondition::notifyOne): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::tryStop): (WTF::AutomaticThread::isWaiting): (WTF::AutomaticThread::notify): (WTF::AutomaticThread::start): (WTF::AutomaticThread::threadIsStopping): * wtf/AutomaticThread.h: * wtf/NumberOfCores.cpp: (WTF::numberOfProcessorCores): * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::claimTask): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::hasClientWithTask): (WTF::ParallelHelperPool::getClientWithTask): * wtf/ParallelHelperPool.h: Tools: Make more tests collect continuously. * Scripts/run-jsc-stress-tests: Canonical link: https://commits.webkit.org/185692@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@212778 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-02-22 00:58:15 +00:00
bool AutomaticThread::tryStop(const AbstractLocker&)
The GC should be in a thread https://bugs.webkit.org/show_bug.cgi?id=163562 Reviewed by Geoffrey Garen and Andreas Kling. Source/JavaScriptCore: In a concurrent GC, the work of collecting happens on a separate thread. This patch implements this, and schedules the thread the way that a concurrent GC thread would be scheduled. But, the GC isn't actually concurrent yet because it calls stopTheWorld() before doing anything and calls resumeTheWorld() after it's done with everything. The next step will be to make it really concurrent by basically calling stopTheWorld()/resumeTheWorld() around bounded snippets of work while making most of the work happen with the world running. Our GC will probably always have stop-the-world phases because the semantics of JSC weak references call for it. This implements concurrent GC scheduling. This means that there is no longer a Heap::collect() API. Instead, you can call collectAsync() which makes sure that a GC is scheduled (it will do nothing if one is scheduled or ongoing) or you can call collectSync() to schedule a GC and wait for it to happen. I made our debugging stuff call collectSync(). It should be a goal to never call collectSync() except for debugging or benchmark harness hacks. The collector thread is an AutomaticThread, so it won't linger when not in use. It works on a ticket-based system, like you would see at the DMV. A ticket is a 64-bit integer. There are two ticket counters: last granted and last served. When you request a collection, last granted is incremented and its new value given to you. When a collection completes, last served is incremented. collectSync() waits until last served catches up to what last granted had been at the time you requested a GC. This means that if you request a sync GC in the middle of an async GC, you will wait for that async GC to finish and then you will request and wait for your sync GC. The synchronization between the collector thread and the main threads is complex. The collector thread needs to be able to ask the main thread to stop. It needs to be able to do some post-GC clean-up, like the synchronous CodeBlock and LargeAllocation sweeps, on the main thread. The collector needs to be able to ask the main thread to execute a cross-modifying code fence before running any JIT code, since the GC might aid the JIT worklist and run JIT finalization. It's possible for the GC to want the main thread to run something at the same time that the main thread wants to wait for the GC. The main thread needs to be able to run non-JSC stuff without causing the GC to completely stall. The main thread needs to be able to query its own state (is there a request to stop?) and change it (running JSC versus not) quickly, since this may happen on hot paths. This kind of intertwined system of requests, notifications, and state changes requires a combination of lock-free algorithms and waiting. So, this is all implemented using a Atomic<unsigned> Heap::m_worldState, which has bits to represent things being requested by the collector and the heap access state of the mutator. I am borrowing a lot of terms that I've seen in other VMs that I've worked on. Here's what they mean: - Stop the world: make sure that either the mutator is not running, or that it's not running code that could mess with the heap. - Heap access: the mutator is said to have heap access if it could mess with the heap. If you stop the world and the mutator doesn't have heap access, all you're doing is making sure that it will block when it tries to acquire heap access. This means that our GC is already fully concurrent in cases where the GC is requested while the mutator has no heap access. This probably won't happen, but if it did then it should just work. Usually, stopping the world means that we state our shouldStop request with m_worldState, and a future call to Heap::stopIfNecessary() will go to slow path and stop. The act of stopping or waiting to acquire heap access is managed by using ParkingLot API directly on m_worldState. This works out great because it would be very awkward to get the same functionality using locks and condition variables, since we want stopIfNecessary/acquireAccess/requestAccess fast paths that are single atomic instructions (load/CAS/CAS, respectively). The mutator will call these things frequently. Currently we have Heap::stopIfNecessary() polling on every allocator slow path, but we may want to make it even more frequent than that. Currently only JSC API clients benefit from the heap access optimization. The DOM forces us to assume that heap access is permanently on, since DOM manipulation doesn't always hold the JSLock. We could still allow the GC to proceed when the runloop is idle by having the GC put a task on the runloop that just calls stopIfNecessary(). This is perf neutral. The only behavior change that clients ought to observe is that marking and the weak fixpoint happen on a separate thread. Marking was already parallel so it already handled multiple threads, but now it _never_ runs on the main thread. The weak fixpoint needed some help to be able to run on another thread - mostly because there was some code in IndexedDB that was using thread specifics in the weak fixpoint. * API/JSBase.cpp: (JSSynchronousEdenCollectForDebugging): * API/JSManagedValue.mm: (-[JSManagedValue initWithValue:]): * heap/EdenGCActivityCallback.cpp: (JSC::EdenGCActivityCallback::doCollection): * heap/FullGCActivityCallback.cpp: (JSC::FullGCActivityCallback::doCollection): * heap/Heap.cpp: (JSC::Heap::Thread::Thread): (JSC::Heap::Heap): (JSC::Heap::lastChanceToFinalize): (JSC::Heap::markRoots): (JSC::Heap::gatherStackRoots): (JSC::Heap::deleteUnmarkedCompiledCode): (JSC::Heap::collectAllGarbage): (JSC::Heap::collectAsync): (JSC::Heap::collectSync): (JSC::Heap::shouldCollectInThread): (JSC::Heap::collectInThread): (JSC::Heap::stopTheWorld): (JSC::Heap::resumeTheWorld): (JSC::Heap::stopIfNecessarySlow): (JSC::Heap::acquireAccessSlow): (JSC::Heap::releaseAccessSlow): (JSC::Heap::handleDidJIT): (JSC::Heap::handleNeedFinalize): (JSC::Heap::setDidJIT): (JSC::Heap::setNeedFinalize): (JSC::Heap::waitWhileNeedFinalize): (JSC::Heap::finalize): (JSC::Heap::requestCollection): (JSC::Heap::waitForCollection): (JSC::Heap::didFinishCollection): (JSC::Heap::canCollect): (JSC::Heap::shouldCollectHeuristic): (JSC::Heap::shouldCollect): (JSC::Heap::collectIfNecessaryOrDefer): (JSC::Heap::collectAccordingToDeferGCProbability): (JSC::Heap::collect): Deleted. (JSC::Heap::collectWithoutAnySweep): Deleted. (JSC::Heap::collectImpl): Deleted. * heap/Heap.h: (JSC::Heap::ReleaseAccessScope::ReleaseAccessScope): (JSC::Heap::ReleaseAccessScope::~ReleaseAccessScope): * heap/HeapInlines.h: (JSC::Heap::acquireAccess): (JSC::Heap::releaseAccess): (JSC::Heap::stopIfNecessary): * heap/MachineStackMarker.cpp: (JSC::MachineThreads::gatherConservativeRoots): (JSC::MachineThreads::gatherFromCurrentThread): Deleted. * heap/MachineStackMarker.h: * jit/JITWorklist.cpp: (JSC::JITWorklist::completeAllForVM): * jit/JITWorklist.h: * jsc.cpp: (functionFullGC): (functionEdenGC): * runtime/InitializeThreading.cpp: (JSC::initializeThreading): * runtime/JSLock.cpp: (JSC::JSLock::didAcquireLock): (JSC::JSLock::unlock): (JSC::JSLock::willReleaseLock): * tools/JSDollarVMPrototype.cpp: (JSC::JSDollarVMPrototype::edenGC): Source/WebCore: No new tests because existing tests cover this. We now need to be more careful about using JSLock. This fixes some places that were not holding it. New assertions in the GC are more likely to catch this than before. * bindings/js/WorkerScriptController.cpp: (WebCore::WorkerScriptController::WorkerScriptController): Source/WTF: This fixes some bugs and adds a few features. * wtf/Atomics.h: The GC may do work on behalf of the JIT. If it does, the main thread needs to execute a cross-modifying code fence. This is cpuid on x86 and I believe it's isb on ARM. It would have been an isync on PPC and I think that isb is the ARM equivalent. (WTF::arm_isb): (WTF::crossModifyingCodeFence): (WTF::x86_ortop): (WTF::x86_cpuid): * wtf/AutomaticThread.cpp: I accidentally had AutomaticThreadCondition inherit from ThreadSafeRefCounted<AutomaticThread> [sic]. This never crashed before because all of our prior AutomaticThreadConditions were immortal. (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: * wtf/MainThread.cpp: Need to allow initializeGCThreads() to be called separately because it's now more than just a debugging thing. (WTF::initializeGCThreads): Canonical link: https://commits.webkit.org/182065@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208306 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-02 22:01:04 +00:00
{
if (!m_isRunning)
return true;
if (m_hasUnderlyingThread)
return false;
m_isRunning = false;
return true;
}
The collector thread should only start when the mutator doesn't have heap access https://bugs.webkit.org/show_bug.cgi?id=167737 Reviewed by Keith Miller. JSTests: Add versions of splay that flash heap access, to simulate what might happen if a third-party app was running concurrent GC. In this case, we might actually start the collector thread. * stress/splay-flash-access-1ms.js: Added. (performance.now): (this.Setup.setup.setup): (this.TearDown.tearDown.tearDown): (Benchmark): (BenchmarkResult): (BenchmarkResult.prototype.valueOf): (BenchmarkSuite): (alert): (Math.random): (BenchmarkSuite.ResetRNG): (RunStep): (BenchmarkSuite.RunSuites): (BenchmarkSuite.CountBenchmarks): (BenchmarkSuite.GeometricMean): (BenchmarkSuite.GeometricMeanTime): (BenchmarkSuite.AverageAbovePercentile): (BenchmarkSuite.GeometricMeanLatency): (BenchmarkSuite.FormatScore): (BenchmarkSuite.prototype.NotifyStep): (BenchmarkSuite.prototype.NotifyResult): (BenchmarkSuite.prototype.NotifyError): (BenchmarkSuite.prototype.RunSingleBenchmark): (RunNextSetup): (RunNextBenchmark): (RunNextTearDown): (BenchmarkSuite.prototype.RunStep): (GeneratePayloadTree): (GenerateKey): (SplayUpdateStats): (InsertNewNode): (SplaySetup): (SplayTearDown): (SplayRun): (SplayTree): (SplayTree.prototype.isEmpty): (SplayTree.prototype.insert): (SplayTree.prototype.remove): (SplayTree.prototype.find): (SplayTree.prototype.findMax): (SplayTree.prototype.findGreatestLessThan): (SplayTree.prototype.exportKeys): (SplayTree.prototype.splay_): (SplayTree.Node): (SplayTree.Node.prototype.traverse_): (jscSetUp): (jscTearDown): (jscRun): (averageAbovePercentile): (printPercentile): * stress/splay-flash-access.js: Added. (performance.now): (this.Setup.setup.setup): (this.TearDown.tearDown.tearDown): (Benchmark): (BenchmarkResult): (BenchmarkResult.prototype.valueOf): (BenchmarkSuite): (alert): (Math.random): (BenchmarkSuite.ResetRNG): (RunStep): (BenchmarkSuite.RunSuites): (BenchmarkSuite.CountBenchmarks): (BenchmarkSuite.GeometricMean): (BenchmarkSuite.GeometricMeanTime): (BenchmarkSuite.AverageAbovePercentile): (BenchmarkSuite.GeometricMeanLatency): (BenchmarkSuite.FormatScore): (BenchmarkSuite.prototype.NotifyStep): (BenchmarkSuite.prototype.NotifyResult): (BenchmarkSuite.prototype.NotifyError): (BenchmarkSuite.prototype.RunSingleBenchmark): (RunNextSetup): (RunNextBenchmark): (RunNextTearDown): (BenchmarkSuite.prototype.RunStep): (GeneratePayloadTree): (GenerateKey): (SplayUpdateStats): (InsertNewNode): (SplaySetup): (SplayTearDown): (SplayRun): (SplayTree): (SplayTree.prototype.isEmpty): (SplayTree.prototype.insert): (SplayTree.prototype.remove): (SplayTree.prototype.find): (SplayTree.prototype.findMax): (SplayTree.prototype.findGreatestLessThan): (SplayTree.prototype.exportKeys): (SplayTree.prototype.splay_): (SplayTree.Node): (SplayTree.Node.prototype.traverse_): (jscSetUp): (jscTearDown): (jscRun): (averageAbovePercentile): (printPercentile): Source/JavaScriptCore: This turns the collector thread's workflow into a state machine, so that the mutator thread can run it directly. This reduces the amount of synchronization we do with the collector thread, and means that most apps will never start the collector thread. The collector thread will still start when we need to finish collecting and we don't have heap access. In this new world, "stopping the world" means relinquishing control of collection to the mutator. This means tracking who is conducting collection. I use the GCConductor enum to say who is conducting. It's either GCConductor::Mutator or GCConductor::Collector. I use the term "conn" to refer to the concept of conducting (having the conn, relinquishing the conn, taking the conn). So, stopping the world means giving the mutator the conn. Releasing heap access means giving the collector the conn. This meant bringing back the conservative scan of the calling thread. It turns out that this scan was too slow to be called on each GC increment because apparently setjmp() now does system calls. So, I wrote our own callee save register saving for the GC. Then I had doubts about whether or not it was correct, so I also made it so that the GC only rarely asks for the register state. I think we still want to use my register saving code instead of setjmp because setjmp seems to save things we don't need, and that could make us overly conservative. It turns out that this new scheduling discipline makes the old space-time scheduler perform better than the new stochastic space-time scheduler on systems with fewer than 4 cores. This is because the mutator having the conn enables us to time the mutator<->collector context switches by polling. The OS is never involved. So, we can use super precise timing. This allows the old space-time schduler to shine like it hadn't before. The splay results imply that this is all a good thing. On 2-core systems, this reduces pause times by 40% and it increases throughput about 5%. On 1-core systems, this reduces pause times by half and reduces throughput by 8%. On 4-or-more-core systems, this doesn't seem to have much effect. * CMakeLists.txt: * JavaScriptCore.xcodeproj/project.pbxproj: * bytecode/CodeBlock.cpp: (JSC::CodeBlock::visitChildren): * dfg/DFGWorklist.cpp: (JSC::DFG::Worklist::ThreadBody::ThreadBody): (JSC::DFG::Worklist::dump): (JSC::DFG::numberOfWorklists): (JSC::DFG::ensureWorklistForIndex): (JSC::DFG::existingWorklistForIndexOrNull): (JSC::DFG::existingWorklistForIndex): * dfg/DFGWorklist.h: (JSC::DFG::numberOfWorklists): Deleted. (JSC::DFG::ensureWorklistForIndex): Deleted. (JSC::DFG::existingWorklistForIndexOrNull): Deleted. (JSC::DFG::existingWorklistForIndex): Deleted. * heap/CollectingScope.h: Added. (JSC::CollectingScope::CollectingScope): (JSC::CollectingScope::~CollectingScope): * heap/CollectorPhase.cpp: Added. (JSC::worldShouldBeSuspended): (WTF::printInternal): * heap/CollectorPhase.h: Added. * heap/EdenGCActivityCallback.cpp: (JSC::EdenGCActivityCallback::lastGCLength): * heap/FullGCActivityCallback.cpp: (JSC::FullGCActivityCallback::doCollection): (JSC::FullGCActivityCallback::lastGCLength): * heap/GCConductor.cpp: Added. (JSC::gcConductorShortName): (WTF::printInternal): * heap/GCConductor.h: Added. * heap/GCFinalizationCallback.cpp: Added. (JSC::GCFinalizationCallback::GCFinalizationCallback): (JSC::GCFinalizationCallback::~GCFinalizationCallback): * heap/GCFinalizationCallback.h: Added. (JSC::GCFinalizationCallbackFuncAdaptor::GCFinalizationCallbackFuncAdaptor): (JSC::createGCFinalizationCallback): * heap/Heap.cpp: (JSC::Heap::Thread::Thread): (JSC::Heap::Heap): (JSC::Heap::lastChanceToFinalize): (JSC::Heap::gatherStackRoots): (JSC::Heap::updateObjectCounts): (JSC::Heap::sweepSynchronously): (JSC::Heap::collectAllGarbage): (JSC::Heap::collectAsync): (JSC::Heap::collectSync): (JSC::Heap::shouldCollectInCollectorThread): (JSC::Heap::collectInCollectorThread): (JSC::Heap::checkConn): (JSC::Heap::runNotRunningPhase): (JSC::Heap::runBeginPhase): (JSC::Heap::runFixpointPhase): (JSC::Heap::runConcurrentPhase): (JSC::Heap::runReloopPhase): (JSC::Heap::runEndPhase): (JSC::Heap::changePhase): (JSC::Heap::finishChangingPhase): (JSC::Heap::stopThePeriphery): (JSC::Heap::resumeThePeriphery): (JSC::Heap::stopTheMutator): (JSC::Heap::resumeTheMutator): (JSC::Heap::stopIfNecessarySlow): (JSC::Heap::collectInMutatorThread): (JSC::Heap::waitForCollector): (JSC::Heap::acquireAccessSlow): (JSC::Heap::releaseAccessSlow): (JSC::Heap::relinquishConn): (JSC::Heap::finishRelinquishingConn): (JSC::Heap::handleNeedFinalize): (JSC::Heap::notifyThreadStopping): (JSC::Heap::finalize): (JSC::Heap::addFinalizationCallback): (JSC::Heap::requestCollection): (JSC::Heap::waitForCollection): (JSC::Heap::updateAllocationLimits): (JSC::Heap::didFinishCollection): (JSC::Heap::collectIfNecessaryOrDefer): (JSC::Heap::notifyIsSafeToCollect): (JSC::Heap::preventCollection): (JSC::Heap::performIncrement): (JSC::Heap::markToFixpoint): Deleted. (JSC::Heap::shouldCollectInThread): Deleted. (JSC::Heap::collectInThread): Deleted. (JSC::Heap::stopTheWorld): Deleted. (JSC::Heap::resumeTheWorld): Deleted. * heap/Heap.h: (JSC::Heap::machineThreads): (JSC::Heap::lastFullGCLength): (JSC::Heap::lastEdenGCLength): (JSC::Heap::increaseLastFullGCLength): * heap/HeapInlines.h: (JSC::Heap::mutatorIsStopped): Deleted. * heap/HeapStatistics.cpp: Removed. * heap/HeapStatistics.h: Removed. * heap/HelpingGCScope.h: Removed. * heap/IncrementalSweeper.cpp: (JSC::IncrementalSweeper::stopSweeping): (JSC::IncrementalSweeper::willFinishSweeping): Deleted. * heap/IncrementalSweeper.h: * heap/MachineStackMarker.cpp: (JSC::MachineThreads::gatherFromCurrentThread): (JSC::MachineThreads::gatherConservativeRoots): (JSC::callWithCurrentThreadState): * heap/MachineStackMarker.h: * heap/MarkedAllocator.cpp: (JSC::MarkedAllocator::allocateSlowCaseImpl): * heap/MarkedBlock.cpp: (JSC::MarkedBlock::Handle::sweep): * heap/MarkedSpace.cpp: (JSC::MarkedSpace::sweep): * heap/MutatorState.cpp: (WTF::printInternal): * heap/MutatorState.h: * heap/RegisterState.h: Added. * heap/RunningScope.h: Added. (JSC::RunningScope::RunningScope): (JSC::RunningScope::~RunningScope): * heap/SlotVisitor.cpp: (JSC::SlotVisitor::SlotVisitor): (JSC::SlotVisitor::drain): (JSC::SlotVisitor::drainFromShared): (JSC::SlotVisitor::drainInParallelPassively): (JSC::SlotVisitor::donateAll): (JSC::SlotVisitor::donate): * heap/SlotVisitor.h: (JSC::SlotVisitor::codeName): * heap/StochasticSpaceTimeMutatorScheduler.cpp: (JSC::StochasticSpaceTimeMutatorScheduler::beginCollection): (JSC::StochasticSpaceTimeMutatorScheduler::synchronousDrainingDidStall): (JSC::StochasticSpaceTimeMutatorScheduler::timeToStop): * heap/SweepingScope.h: Added. (JSC::SweepingScope::SweepingScope): (JSC::SweepingScope::~SweepingScope): * jit/JITWorklist.cpp: (JSC::JITWorklist::Thread::Thread): * jsc.cpp: (GlobalObject::finishCreation): (functionFlashHeapAccess): * runtime/InitializeThreading.cpp: (JSC::initializeThreading): * runtime/JSCellInlines.h: (JSC::JSCell::classInfo): * runtime/Options.cpp: (JSC::overrideDefaults): * runtime/Options.h: * runtime/TestRunnerUtils.cpp: (JSC::finalizeStatsAtEndOfTesting): Source/WebCore: Added new tests in JSTests. The WebCore changes involve: - Refactoring around new header discipline. - Adding crazy GC APIs to window.internals to enable us to test the GC's runloop discipline. * ForwardingHeaders/heap/GCFinalizationCallback.h: Added. * ForwardingHeaders/heap/IncrementalSweeper.h: Added. * ForwardingHeaders/heap/MachineStackMarker.h: Added. * ForwardingHeaders/heap/RunningScope.h: Added. * bindings/js/CommonVM.cpp: * testing/Internals.cpp: (WebCore::Internals::parserMetaData): (WebCore::Internals::isReadableStreamDisturbed): (WebCore::Internals::isGCRunning): (WebCore::Internals::addGCFinalizationCallback): (WebCore::Internals::stopSweeping): (WebCore::Internals::startSweeping): * testing/Internals.h: * testing/Internals.idl: Source/WTF: Extend the use of AbstractLocker so that we can use more locking idioms. * wtf/AutomaticThread.cpp: (WTF::AutomaticThreadCondition::notifyOne): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::tryStop): (WTF::AutomaticThread::isWaiting): (WTF::AutomaticThread::notify): (WTF::AutomaticThread::start): (WTF::AutomaticThread::threadIsStopping): * wtf/AutomaticThread.h: * wtf/NumberOfCores.cpp: (WTF::numberOfProcessorCores): * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::claimTask): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::hasClientWithTask): (WTF::ParallelHelperPool::getClientWithTask): * wtf/ParallelHelperPool.h: Tools: Make more tests collect continuously. * Scripts/run-jsc-stress-tests: Canonical link: https://commits.webkit.org/185692@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@212778 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-02-22 00:58:15 +00:00
bool AutomaticThread::isWaiting(const AbstractLocker& locker)
REGRESSION: HipChat and Mail sometimes hang beneath JSC::Heap::lastChanceToFinalize() https://bugs.webkit.org/show_bug.cgi?id=165962 Reviewed by Filip Pizlo. There is an inherent race in Condition::waitFor() where the timeout can happen just before a notify from another thread. Fixed this by adding a condition variable and flag to each AutomaticThread. The flag is used to signify to a notifying thread that the thread is waiting. That flag is set in the waiting thread before calling waitFor() and cleared by another thread when it notifies the thread. The access to that flag happens when the lock is held. Now the waiting thread checks if the flag after a timeout to see that it in fact should proceed like a normal notification. The added condition variable allows us to target a specific thread. We used to keep a list of waiting threads, now we keep a list of all threads. To notify one thread, we look for a waiting thread and notify it directly. If we can't find a waiting thread, we start a sleeping thread. We notify all threads by waking all waiting threads and starting all sleeping threads. * wtf/AutomaticThread.cpp: (WTF::AutomaticThreadCondition::notifyOne): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThread::isWaiting): (WTF::AutomaticThread::notify): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Canonical link: https://commits.webkit.org/183569@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@209938 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-12-16 22:26:09 +00:00
{
return hasUnderlyingThread(locker) && m_isWaiting;
}
The collector thread should only start when the mutator doesn't have heap access https://bugs.webkit.org/show_bug.cgi?id=167737 Reviewed by Keith Miller. JSTests: Add versions of splay that flash heap access, to simulate what might happen if a third-party app was running concurrent GC. In this case, we might actually start the collector thread. * stress/splay-flash-access-1ms.js: Added. (performance.now): (this.Setup.setup.setup): (this.TearDown.tearDown.tearDown): (Benchmark): (BenchmarkResult): (BenchmarkResult.prototype.valueOf): (BenchmarkSuite): (alert): (Math.random): (BenchmarkSuite.ResetRNG): (RunStep): (BenchmarkSuite.RunSuites): (BenchmarkSuite.CountBenchmarks): (BenchmarkSuite.GeometricMean): (BenchmarkSuite.GeometricMeanTime): (BenchmarkSuite.AverageAbovePercentile): (BenchmarkSuite.GeometricMeanLatency): (BenchmarkSuite.FormatScore): (BenchmarkSuite.prototype.NotifyStep): (BenchmarkSuite.prototype.NotifyResult): (BenchmarkSuite.prototype.NotifyError): (BenchmarkSuite.prototype.RunSingleBenchmark): (RunNextSetup): (RunNextBenchmark): (RunNextTearDown): (BenchmarkSuite.prototype.RunStep): (GeneratePayloadTree): (GenerateKey): (SplayUpdateStats): (InsertNewNode): (SplaySetup): (SplayTearDown): (SplayRun): (SplayTree): (SplayTree.prototype.isEmpty): (SplayTree.prototype.insert): (SplayTree.prototype.remove): (SplayTree.prototype.find): (SplayTree.prototype.findMax): (SplayTree.prototype.findGreatestLessThan): (SplayTree.prototype.exportKeys): (SplayTree.prototype.splay_): (SplayTree.Node): (SplayTree.Node.prototype.traverse_): (jscSetUp): (jscTearDown): (jscRun): (averageAbovePercentile): (printPercentile): * stress/splay-flash-access.js: Added. (performance.now): (this.Setup.setup.setup): (this.TearDown.tearDown.tearDown): (Benchmark): (BenchmarkResult): (BenchmarkResult.prototype.valueOf): (BenchmarkSuite): (alert): (Math.random): (BenchmarkSuite.ResetRNG): (RunStep): (BenchmarkSuite.RunSuites): (BenchmarkSuite.CountBenchmarks): (BenchmarkSuite.GeometricMean): (BenchmarkSuite.GeometricMeanTime): (BenchmarkSuite.AverageAbovePercentile): (BenchmarkSuite.GeometricMeanLatency): (BenchmarkSuite.FormatScore): (BenchmarkSuite.prototype.NotifyStep): (BenchmarkSuite.prototype.NotifyResult): (BenchmarkSuite.prototype.NotifyError): (BenchmarkSuite.prototype.RunSingleBenchmark): (RunNextSetup): (RunNextBenchmark): (RunNextTearDown): (BenchmarkSuite.prototype.RunStep): (GeneratePayloadTree): (GenerateKey): (SplayUpdateStats): (InsertNewNode): (SplaySetup): (SplayTearDown): (SplayRun): (SplayTree): (SplayTree.prototype.isEmpty): (SplayTree.prototype.insert): (SplayTree.prototype.remove): (SplayTree.prototype.find): (SplayTree.prototype.findMax): (SplayTree.prototype.findGreatestLessThan): (SplayTree.prototype.exportKeys): (SplayTree.prototype.splay_): (SplayTree.Node): (SplayTree.Node.prototype.traverse_): (jscSetUp): (jscTearDown): (jscRun): (averageAbovePercentile): (printPercentile): Source/JavaScriptCore: This turns the collector thread's workflow into a state machine, so that the mutator thread can run it directly. This reduces the amount of synchronization we do with the collector thread, and means that most apps will never start the collector thread. The collector thread will still start when we need to finish collecting and we don't have heap access. In this new world, "stopping the world" means relinquishing control of collection to the mutator. This means tracking who is conducting collection. I use the GCConductor enum to say who is conducting. It's either GCConductor::Mutator or GCConductor::Collector. I use the term "conn" to refer to the concept of conducting (having the conn, relinquishing the conn, taking the conn). So, stopping the world means giving the mutator the conn. Releasing heap access means giving the collector the conn. This meant bringing back the conservative scan of the calling thread. It turns out that this scan was too slow to be called on each GC increment because apparently setjmp() now does system calls. So, I wrote our own callee save register saving for the GC. Then I had doubts about whether or not it was correct, so I also made it so that the GC only rarely asks for the register state. I think we still want to use my register saving code instead of setjmp because setjmp seems to save things we don't need, and that could make us overly conservative. It turns out that this new scheduling discipline makes the old space-time scheduler perform better than the new stochastic space-time scheduler on systems with fewer than 4 cores. This is because the mutator having the conn enables us to time the mutator<->collector context switches by polling. The OS is never involved. So, we can use super precise timing. This allows the old space-time schduler to shine like it hadn't before. The splay results imply that this is all a good thing. On 2-core systems, this reduces pause times by 40% and it increases throughput about 5%. On 1-core systems, this reduces pause times by half and reduces throughput by 8%. On 4-or-more-core systems, this doesn't seem to have much effect. * CMakeLists.txt: * JavaScriptCore.xcodeproj/project.pbxproj: * bytecode/CodeBlock.cpp: (JSC::CodeBlock::visitChildren): * dfg/DFGWorklist.cpp: (JSC::DFG::Worklist::ThreadBody::ThreadBody): (JSC::DFG::Worklist::dump): (JSC::DFG::numberOfWorklists): (JSC::DFG::ensureWorklistForIndex): (JSC::DFG::existingWorklistForIndexOrNull): (JSC::DFG::existingWorklistForIndex): * dfg/DFGWorklist.h: (JSC::DFG::numberOfWorklists): Deleted. (JSC::DFG::ensureWorklistForIndex): Deleted. (JSC::DFG::existingWorklistForIndexOrNull): Deleted. (JSC::DFG::existingWorklistForIndex): Deleted. * heap/CollectingScope.h: Added. (JSC::CollectingScope::CollectingScope): (JSC::CollectingScope::~CollectingScope): * heap/CollectorPhase.cpp: Added. (JSC::worldShouldBeSuspended): (WTF::printInternal): * heap/CollectorPhase.h: Added. * heap/EdenGCActivityCallback.cpp: (JSC::EdenGCActivityCallback::lastGCLength): * heap/FullGCActivityCallback.cpp: (JSC::FullGCActivityCallback::doCollection): (JSC::FullGCActivityCallback::lastGCLength): * heap/GCConductor.cpp: Added. (JSC::gcConductorShortName): (WTF::printInternal): * heap/GCConductor.h: Added. * heap/GCFinalizationCallback.cpp: Added. (JSC::GCFinalizationCallback::GCFinalizationCallback): (JSC::GCFinalizationCallback::~GCFinalizationCallback): * heap/GCFinalizationCallback.h: Added. (JSC::GCFinalizationCallbackFuncAdaptor::GCFinalizationCallbackFuncAdaptor): (JSC::createGCFinalizationCallback): * heap/Heap.cpp: (JSC::Heap::Thread::Thread): (JSC::Heap::Heap): (JSC::Heap::lastChanceToFinalize): (JSC::Heap::gatherStackRoots): (JSC::Heap::updateObjectCounts): (JSC::Heap::sweepSynchronously): (JSC::Heap::collectAllGarbage): (JSC::Heap::collectAsync): (JSC::Heap::collectSync): (JSC::Heap::shouldCollectInCollectorThread): (JSC::Heap::collectInCollectorThread): (JSC::Heap::checkConn): (JSC::Heap::runNotRunningPhase): (JSC::Heap::runBeginPhase): (JSC::Heap::runFixpointPhase): (JSC::Heap::runConcurrentPhase): (JSC::Heap::runReloopPhase): (JSC::Heap::runEndPhase): (JSC::Heap::changePhase): (JSC::Heap::finishChangingPhase): (JSC::Heap::stopThePeriphery): (JSC::Heap::resumeThePeriphery): (JSC::Heap::stopTheMutator): (JSC::Heap::resumeTheMutator): (JSC::Heap::stopIfNecessarySlow): (JSC::Heap::collectInMutatorThread): (JSC::Heap::waitForCollector): (JSC::Heap::acquireAccessSlow): (JSC::Heap::releaseAccessSlow): (JSC::Heap::relinquishConn): (JSC::Heap::finishRelinquishingConn): (JSC::Heap::handleNeedFinalize): (JSC::Heap::notifyThreadStopping): (JSC::Heap::finalize): (JSC::Heap::addFinalizationCallback): (JSC::Heap::requestCollection): (JSC::Heap::waitForCollection): (JSC::Heap::updateAllocationLimits): (JSC::Heap::didFinishCollection): (JSC::Heap::collectIfNecessaryOrDefer): (JSC::Heap::notifyIsSafeToCollect): (JSC::Heap::preventCollection): (JSC::Heap::performIncrement): (JSC::Heap::markToFixpoint): Deleted. (JSC::Heap::shouldCollectInThread): Deleted. (JSC::Heap::collectInThread): Deleted. (JSC::Heap::stopTheWorld): Deleted. (JSC::Heap::resumeTheWorld): Deleted. * heap/Heap.h: (JSC::Heap::machineThreads): (JSC::Heap::lastFullGCLength): (JSC::Heap::lastEdenGCLength): (JSC::Heap::increaseLastFullGCLength): * heap/HeapInlines.h: (JSC::Heap::mutatorIsStopped): Deleted. * heap/HeapStatistics.cpp: Removed. * heap/HeapStatistics.h: Removed. * heap/HelpingGCScope.h: Removed. * heap/IncrementalSweeper.cpp: (JSC::IncrementalSweeper::stopSweeping): (JSC::IncrementalSweeper::willFinishSweeping): Deleted. * heap/IncrementalSweeper.h: * heap/MachineStackMarker.cpp: (JSC::MachineThreads::gatherFromCurrentThread): (JSC::MachineThreads::gatherConservativeRoots): (JSC::callWithCurrentThreadState): * heap/MachineStackMarker.h: * heap/MarkedAllocator.cpp: (JSC::MarkedAllocator::allocateSlowCaseImpl): * heap/MarkedBlock.cpp: (JSC::MarkedBlock::Handle::sweep): * heap/MarkedSpace.cpp: (JSC::MarkedSpace::sweep): * heap/MutatorState.cpp: (WTF::printInternal): * heap/MutatorState.h: * heap/RegisterState.h: Added. * heap/RunningScope.h: Added. (JSC::RunningScope::RunningScope): (JSC::RunningScope::~RunningScope): * heap/SlotVisitor.cpp: (JSC::SlotVisitor::SlotVisitor): (JSC::SlotVisitor::drain): (JSC::SlotVisitor::drainFromShared): (JSC::SlotVisitor::drainInParallelPassively): (JSC::SlotVisitor::donateAll): (JSC::SlotVisitor::donate): * heap/SlotVisitor.h: (JSC::SlotVisitor::codeName): * heap/StochasticSpaceTimeMutatorScheduler.cpp: (JSC::StochasticSpaceTimeMutatorScheduler::beginCollection): (JSC::StochasticSpaceTimeMutatorScheduler::synchronousDrainingDidStall): (JSC::StochasticSpaceTimeMutatorScheduler::timeToStop): * heap/SweepingScope.h: Added. (JSC::SweepingScope::SweepingScope): (JSC::SweepingScope::~SweepingScope): * jit/JITWorklist.cpp: (JSC::JITWorklist::Thread::Thread): * jsc.cpp: (GlobalObject::finishCreation): (functionFlashHeapAccess): * runtime/InitializeThreading.cpp: (JSC::initializeThreading): * runtime/JSCellInlines.h: (JSC::JSCell::classInfo): * runtime/Options.cpp: (JSC::overrideDefaults): * runtime/Options.h: * runtime/TestRunnerUtils.cpp: (JSC::finalizeStatsAtEndOfTesting): Source/WebCore: Added new tests in JSTests. The WebCore changes involve: - Refactoring around new header discipline. - Adding crazy GC APIs to window.internals to enable us to test the GC's runloop discipline. * ForwardingHeaders/heap/GCFinalizationCallback.h: Added. * ForwardingHeaders/heap/IncrementalSweeper.h: Added. * ForwardingHeaders/heap/MachineStackMarker.h: Added. * ForwardingHeaders/heap/RunningScope.h: Added. * bindings/js/CommonVM.cpp: * testing/Internals.cpp: (WebCore::Internals::parserMetaData): (WebCore::Internals::isReadableStreamDisturbed): (WebCore::Internals::isGCRunning): (WebCore::Internals::addGCFinalizationCallback): (WebCore::Internals::stopSweeping): (WebCore::Internals::startSweeping): * testing/Internals.h: * testing/Internals.idl: Source/WTF: Extend the use of AbstractLocker so that we can use more locking idioms. * wtf/AutomaticThread.cpp: (WTF::AutomaticThreadCondition::notifyOne): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::tryStop): (WTF::AutomaticThread::isWaiting): (WTF::AutomaticThread::notify): (WTF::AutomaticThread::start): (WTF::AutomaticThread::threadIsStopping): * wtf/AutomaticThread.h: * wtf/NumberOfCores.cpp: (WTF::numberOfProcessorCores): * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::claimTask): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::hasClientWithTask): (WTF::ParallelHelperPool::getClientWithTask): * wtf/ParallelHelperPool.h: Tools: Make more tests collect continuously. * Scripts/run-jsc-stress-tests: Canonical link: https://commits.webkit.org/185692@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@212778 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-02-22 00:58:15 +00:00
bool AutomaticThread::notify(const AbstractLocker& locker)
REGRESSION: HipChat and Mail sometimes hang beneath JSC::Heap::lastChanceToFinalize() https://bugs.webkit.org/show_bug.cgi?id=165962 Reviewed by Filip Pizlo. There is an inherent race in Condition::waitFor() where the timeout can happen just before a notify from another thread. Fixed this by adding a condition variable and flag to each AutomaticThread. The flag is used to signify to a notifying thread that the thread is waiting. That flag is set in the waiting thread before calling waitFor() and cleared by another thread when it notifies the thread. The access to that flag happens when the lock is held. Now the waiting thread checks if the flag after a timeout to see that it in fact should proceed like a normal notification. The added condition variable allows us to target a specific thread. We used to keep a list of waiting threads, now we keep a list of all threads. To notify one thread, we look for a waiting thread and notify it directly. If we can't find a waiting thread, we start a sleeping thread. We notify all threads by waking all waiting threads and starting all sleeping threads. * wtf/AutomaticThread.cpp: (WTF::AutomaticThreadCondition::notifyOne): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThread::isWaiting): (WTF::AutomaticThread::notify): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Canonical link: https://commits.webkit.org/183569@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@209938 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-12-16 22:26:09 +00:00
{
ASSERT_UNUSED(locker, hasUnderlyingThread(locker));
m_isWaiting = false;
return m_waitCondition.notifyOne();
}
WTF should make it easier to create threads that die automatically after inactivity https://bugs.webkit.org/show_bug.cgi?id=163576 Reviewed by Andreas Kling. Source/JavaScriptCore: Added a sleepSeconds() function, which made it easier for me to test this change. The WTF changes in this patch change how the JSC GC manages threads: the GC threads will now shut down automatically after 1 second of inactivity. Maybe this will save some memory. * jsc.cpp: (GlobalObject::finishCreation): (functionSleepSeconds): Source/WTF: For a long time now, I've been adding threads to WTF/JSC and each time I do this, I feel guilty because those threads don't shut down when they are inactive. For example, in bug 163562, I need to add a new GC thread. There will be one of them per VM. This means that a JSC API client that starts a lot of VMs will have a lot of threads. I don't think that's good. A common pattern for all of these threads is that they have some well-defined trigger that causes them to run. This trigger has a lock, a condition variable, some logic that determines if there is work to do, and then of course the logic for the thread's actual work. The thread bodies usually look like this: void Thingy::runThread() { for (;;) { Work work; { LockHolder locker(m_lock); while (!hasWork()) m_cond.wait(m_lock); work = takeWork(); } doWork(work); } } If you look at ParallelHelperPool (the GC's threads) and DFG::Worklist (some of the JIT's threads), you will see this pattern. This change adds a new kind of thread, called AutomaticThread, that lets you write threads to this pattern while getting automatic thread shutdown for free: instead of just waiting on a condition variable, AutomaticThread will have a timeout that causes the thread to die. The condition variable associated with AutomaticThread, called AutomaticThreadCondition, is smart enough to restart any threads that have decided to stop due to inactivity. The inactivity threshold is current just 1 second. In this patch I only adopt AutomaticThread for ParallelHelperPool. I plan to adopt it in more places soon. * WTF.xcodeproj/project.pbxproj: * wtf/AutomaticThread.cpp: Added. (WTF::AutomaticThreadCondition::create): (WTF::AutomaticThreadCondition::AutomaticThreadCondition): (WTF::AutomaticThreadCondition::~AutomaticThreadCondition): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Added. * wtf/CMakeLists.txt: * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::ParallelHelperPool): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::helperThreadBody): Deleted. (WTF::ParallelHelperPool::waitForClientWithTask): Deleted. * wtf/ParallelHelperPool.h: Canonical link: https://commits.webkit.org/181393@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207480 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-18 20:17:10 +00:00
void AutomaticThread::join()
{
Replace LockHolder with Locker in local variables https://bugs.webkit.org/show_bug.cgi?id=226133 Reviewed by Darin Adler. Replace LockHolder with Locker in local variables. It is shorter and it allows switching the lock type more easily since the compiler with deduce the lock type T for Locker<T>. Source/JavaScriptCore: * API/JSCallbackObject.h: (JSC::JSCallbackObjectData::JSPrivatePropertyMap::setPrivateProperty): (JSC::JSCallbackObjectData::JSPrivatePropertyMap::deletePrivateProperty): (JSC::JSCallbackObjectData::JSPrivatePropertyMap::visitChildren): * API/JSValue.mm: (handerForStructTag): * API/tests/testapi.cpp: (testCAPIViaCpp): * assembler/testmasm.cpp: (JSC::run): * b3/air/testair.cpp: * b3/testb3_1.cpp: (run): * bytecode/DirectEvalCodeCache.cpp: (JSC::DirectEvalCodeCache::setSlow): (JSC::DirectEvalCodeCache::clear): (JSC::DirectEvalCodeCache::visitAggregateImpl): * bytecode/SuperSampler.cpp: (JSC::initializeSuperSampler): (JSC::resetSuperSamplerState): (JSC::printSuperSamplerState): (JSC::enableSuperSampler): (JSC::disableSuperSampler): * dfg/DFGCommonData.cpp: (JSC::DFG::CommonData::invalidate): (JSC::DFG::CommonData::~CommonData): (JSC::DFG::CommonData::installVMTrapBreakpoints): (JSC::DFG::codeBlockForVMTrapPC): * dfg/DFGPlan.cpp: (JSC::DFG::Plan::cleanMustHandleValuesIfNecessary): * dfg/DFGWorklist.cpp: (JSC::DFG::Worklist::~Worklist): (JSC::DFG::Worklist::finishCreation): (JSC::DFG::Worklist::isActiveForVM const): (JSC::DFG::Worklist::enqueue): (JSC::DFG::Worklist::compilationState): (JSC::DFG::Worklist::waitUntilAllPlansForVMAreReady): (JSC::DFG::Worklist::removeAllReadyPlansForVM): (JSC::DFG::Worklist::completeAllReadyPlansForVM): (JSC::DFG::Worklist::visitWeakReferences): (JSC::DFG::Worklist::removeDeadPlans): (JSC::DFG::Worklist::removeNonCompilingPlansForVM): (JSC::DFG::Worklist::queueLength): (JSC::DFG::Worklist::dump const): (JSC::DFG::Worklist::setNumberOfThreads): * dfg/DFGWorklistInlines.h: (JSC::DFG::Worklist::iterateCodeBlocksForGC): * disassembler/Disassembler.cpp: * heap/BlockDirectory.cpp: (JSC::BlockDirectory::addBlock): * heap/CodeBlockSetInlines.h: (JSC::CodeBlockSet::iterateCurrentlyExecuting): * heap/ConservativeRoots.cpp: (JSC::ConservativeRoots::add): * heap/Heap.cpp: (JSC::Heap::Heap): (JSC::Heap::lastChanceToFinalize): (JSC::Heap::collectAsync): (JSC::Heap::runBeginPhase): (JSC::Heap::waitForCollector): (JSC::Heap::requestCollection): (JSC::Heap::notifyIsSafeToCollect): * heap/SlotVisitor.cpp: (JSC::SlotVisitor::didReachTermination): * inspector/agents/InspectorScriptProfilerAgent.cpp: (Inspector::InspectorScriptProfilerAgent::startTracking): (Inspector::InspectorScriptProfilerAgent::trackingComplete): (Inspector::InspectorScriptProfilerAgent::stopSamplingWhenDisconnecting): * inspector/remote/RemoteConnectionToTarget.cpp: (Inspector::RemoteConnectionToTarget::setup): (Inspector::RemoteConnectionToTarget::sendMessageToTarget): (Inspector::RemoteConnectionToTarget::close): (Inspector::RemoteConnectionToTarget::targetClosed): * inspector/remote/RemoteInspector.cpp: (Inspector::RemoteInspector::registerTarget): (Inspector::RemoteInspector::unregisterTarget): (Inspector::RemoteInspector::updateTarget): (Inspector::RemoteInspector::updateClientCapabilities): (Inspector::RemoteInspector::setClient): (Inspector::RemoteInspector::setupFailed): (Inspector::RemoteInspector::setupCompleted): (Inspector::RemoteInspector::stop): * inspector/remote/cocoa/RemoteConnectionToTargetCocoa.mm: (Inspector::RemoteTargetHandleRunSourceGlobal): (Inspector::RemoteTargetQueueTaskOnGlobalQueue): (Inspector::RemoteTargetHandleRunSourceWithInfo): (Inspector::RemoteConnectionToTarget::setup): (Inspector::RemoteConnectionToTarget::targetClosed): (Inspector::RemoteConnectionToTarget::close): (Inspector::RemoteConnectionToTarget::sendMessageToTarget): (Inspector::RemoteConnectionToTarget::queueTaskOnPrivateRunLoop): * inspector/remote/cocoa/RemoteInspectorCocoa.mm: (Inspector::RemoteInspector::updateAutomaticInspectionCandidate): (Inspector::RemoteInspector::sendMessageToRemote): (Inspector::RemoteInspector::start): (Inspector::RemoteInspector::setupXPCConnectionIfNeeded): (Inspector::RemoteInspector::setParentProcessInformation): (Inspector::RemoteInspector::xpcConnectionReceivedMessage): (Inspector::RemoteInspector::xpcConnectionFailed): (Inspector::RemoteInspector::pushListingsSoon): (Inspector::RemoteInspector::receivedIndicateMessage): (Inspector::RemoteInspector::receivedProxyApplicationSetupMessage): * inspector/remote/cocoa/RemoteInspectorXPCConnection.mm: (Inspector::RemoteInspectorXPCConnection::close): (Inspector::RemoteInspectorXPCConnection::closeFromMessage): (Inspector::RemoteInspectorXPCConnection::deserializeMessage): (Inspector::RemoteInspectorXPCConnection::handleEvent): * inspector/remote/glib/RemoteInspectorGlib.cpp: (Inspector::RemoteInspector::start): (Inspector::RemoteInspector::setupConnection): (Inspector::RemoteInspector::pushListingsSoon): (Inspector::RemoteInspector::sendMessageToRemote): (Inspector::RemoteInspector::receivedGetTargetListMessage): (Inspector::RemoteInspector::receivedDataMessage): (Inspector::RemoteInspector::receivedCloseMessage): (Inspector::RemoteInspector::setup): * inspector/remote/socket/RemoteInspectorConnectionClient.cpp: (Inspector::RemoteInspectorConnectionClient::didReceive): * inspector/remote/socket/RemoteInspectorSocket.cpp: (Inspector::RemoteInspector::didClose): (Inspector::RemoteInspector::start): (Inspector::RemoteInspector::pushListingsSoon): (Inspector::RemoteInspector::setup): (Inspector::RemoteInspector::setupInspectorClient): (Inspector::RemoteInspector::frontendDidClose): (Inspector::RemoteInspector::sendMessageToBackend): (Inspector::RemoteInspector::startAutomationSession): * inspector/remote/socket/RemoteInspectorSocketEndpoint.cpp: (Inspector::RemoteInspectorSocketEndpoint::listenInet): (Inspector::RemoteInspectorSocketEndpoint::isListening): (Inspector::RemoteInspectorSocketEndpoint::workerThread): (Inspector::RemoteInspectorSocketEndpoint::createClient): (Inspector::RemoteInspectorSocketEndpoint::disconnect): (Inspector::RemoteInspectorSocketEndpoint::invalidateClient): (Inspector::RemoteInspectorSocketEndpoint::invalidateListener): (Inspector::RemoteInspectorSocketEndpoint::getPort const): (Inspector::RemoteInspectorSocketEndpoint::recvIfEnabled): (Inspector::RemoteInspectorSocketEndpoint::sendIfEnabled): (Inspector::RemoteInspectorSocketEndpoint::send): (Inspector::RemoteInspectorSocketEndpoint::acceptInetSocketIfEnabled): * interpreter/CLoopStack.cpp: (JSC::CLoopStack::addToCommittedByteCount): (JSC::CLoopStack::committedByteCount): * jit/ExecutableAllocator.cpp: (JSC::dumpJITMemory): * jit/ICStats.cpp: (JSC::ICStats::ICStats): (JSC::ICStats::~ICStats): * jit/JITThunks.cpp: (JSC::JITThunks::ctiStub): (JSC::JITThunks::existingCTIStub): (JSC::JITThunks::ctiSlowPathFunctionStub): * jit/JITWorklist.cpp: (JSC::JITWorklist::Plan::compileInThread): (JSC::JITWorklist::Plan::isFinishedCompiling): (JSC::JITWorklist::JITWorklist): (JSC::JITWorklist::completeAllForVM): (JSC::JITWorklist::poll): (JSC::JITWorklist::compileLater): (JSC::JITWorklist::finalizePlans): * parser/SourceProvider.cpp: (JSC::SourceProvider::getID): * profiler/ProfilerDatabase.cpp: (JSC::Profiler::Database::ensureBytecodesFor): (JSC::Profiler::Database::notifyDestruction): (JSC::Profiler::Database::addCompilation): (JSC::Profiler::Database::logEvent): (JSC::Profiler::Database::addDatabaseToAtExit): (JSC::Profiler::Database::removeDatabaseFromAtExit): (JSC::Profiler::Database::removeFirstAtExitDatabase): * profiler/ProfilerUID.cpp: (JSC::Profiler::UID::create): * runtime/DeferredWorkTimer.cpp: (JSC::DeferredWorkTimer::scheduleWorkSoon): (JSC::DeferredWorkTimer::didResumeScriptExecutionOwner): * runtime/SamplingProfiler.cpp: (JSC::SamplingProfiler::timerLoop): (JSC::SamplingProfiler::shutdown): (JSC::SamplingProfiler::start): (JSC::SamplingProfiler::noticeCurrentThreadAsJSCExecutionThread): (JSC::SamplingProfiler::noticeJSLockAcquisition): (JSC::SamplingProfiler::noticeVMEntry): (JSC::SamplingProfiler::registerForReportAtExit): * runtime/Watchdog.cpp: (JSC::Watchdog::startTimer): (JSC::Watchdog::willDestroyVM): * tools/VMInspector.cpp: (JSC::VMInspector::isValidExecutableMemory): * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::work): * wasm/WasmEntryPlan.cpp: (JSC::Wasm::EntryPlan::ThreadCountHolder::ThreadCountHolder): (JSC::Wasm::EntryPlan::ThreadCountHolder::~ThreadCountHolder): * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::work): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::addCompletionTask): (JSC::Wasm::Plan::waitForCompletion): (JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast): * wasm/WasmSignature.cpp: (JSC::Wasm::SignatureInformation::signatureFor): (JSC::Wasm::SignatureInformation::tryCleanup): * wasm/WasmWorklist.cpp: (JSC::Wasm::Worklist::enqueue): (JSC::Wasm::Worklist::completePlanSynchronously): (JSC::Wasm::Worklist::stopAllPlansForContext): (JSC::Wasm::Worklist::Worklist): (JSC::Wasm::Worklist::~Worklist): Source/WebCore: * Modules/webaudio/AsyncAudioDecoder.cpp: (WebCore::AsyncAudioDecoder::AsyncAudioDecoder): (WebCore::AsyncAudioDecoder::runLoop): * Modules/webdatabase/Database.cpp: (WebCore::Database::performClose): (WebCore::Database::inProgressTransactionCompleted): (WebCore::Database::hasPendingTransaction): (WebCore::Database::runTransaction): * Modules/webdatabase/DatabaseThread.cpp: (WebCore::DatabaseThread::start): (WebCore::DatabaseThread::databaseThread): (WebCore::DatabaseThread::recordDatabaseOpen): (WebCore::DatabaseThread::recordDatabaseClosed): (WebCore::DatabaseThread::hasPendingDatabaseActivity const): * Modules/webdatabase/DatabaseTracker.cpp: (WebCore::DatabaseTracker::canEstablishDatabase): (WebCore::DatabaseTracker::retryCanEstablishDatabase): (WebCore::DatabaseTracker::maximumSize): (WebCore::DatabaseTracker::fullPathForDatabase): (WebCore::DatabaseTracker::origins): (WebCore::DatabaseTracker::databaseNames): (WebCore::DatabaseTracker::detailsForNameAndOrigin): (WebCore::DatabaseTracker::setDatabaseDetails): (WebCore::DatabaseTracker::doneCreatingDatabase): (WebCore::DatabaseTracker::openDatabases): (WebCore::DatabaseTracker::addOpenDatabase): (WebCore::DatabaseTracker::removeOpenDatabase): (WebCore::DatabaseTracker::originLockFor): (WebCore::DatabaseTracker::quota): (WebCore::DatabaseTracker::setQuota): (WebCore::DatabaseTracker::deleteOrigin): (WebCore::DatabaseTracker::deleteDatabase): (WebCore::DatabaseTracker::deleteDatabaseFile): (WebCore::DatabaseTracker::removeDeletedOpenedDatabases): * Modules/webdatabase/SQLCallbackWrapper.h: (WebCore::SQLCallbackWrapper::clear): (WebCore::SQLCallbackWrapper::unwrap): * Modules/webdatabase/SQLTransaction.cpp: (WebCore::SQLTransaction::enqueueStatement): (WebCore::SQLTransaction::checkAndHandleClosedDatabase): (WebCore::SQLTransaction::getNextStatement): * Modules/webdatabase/SQLTransactionBackend.cpp: (WebCore::SQLTransactionBackend::doCleanup): * accessibility/isolatedtree/AXIsolatedTree.cpp: (WebCore::AXIsolatedTree::clear): (WebCore::AXIsolatedTree::generateSubtree): (WebCore::AXIsolatedTree::createSubtree): (WebCore::AXIsolatedTree::updateNode): (WebCore::AXIsolatedTree::updateNodeProperty): (WebCore::AXIsolatedTree::updateChildren): (WebCore::AXIsolatedTree::focusedNode): (WebCore::AXIsolatedTree::rootNode): (WebCore::AXIsolatedTree::setFocusedNodeID): (WebCore::AXIsolatedTree::removeNode): (WebCore::AXIsolatedTree::removeSubtree): (WebCore::AXIsolatedTree::applyPendingChanges): * page/scrolling/mac/ScrollingTreeMac.mm: (ScrollingTreeMac::scrollingNodeForPoint): (ScrollingTreeMac::eventListenerRegionTypesForPoint const): * platform/AbortableTaskQueue.h: * platform/audio/cocoa/CARingBuffer.cpp: (WebCore::CARingBufferStorageVector::flush): (WebCore::CARingBufferStorageVector::setCurrentFrameBounds): * platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp: (WebCore::AVFWrapper::addToMap): (WebCore::AVFWrapper::removeFromMap const): (WebCore::AVFWrapper::periodicTimeObserverCallback): (WebCore::AVFWrapper::processNotification): (WebCore::AVFWrapper::loadPlayableCompletionCallback): (WebCore::AVFWrapper::loadMetadataCompletionCallback): (WebCore::AVFWrapper::seekCompletedCallback): (WebCore::AVFWrapper::processCue): (WebCore::AVFWrapper::legibleOutputCallback): (WebCore::AVFWrapper::processShouldWaitForLoadingOfResource): (WebCore::AVFWrapper::resourceLoaderShouldWaitForLoadingOfRequestedResource): * platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.mm: (-[WebCoreSharedBufferResourceLoaderDelegate setExpectedContentSize:]): (-[WebCoreSharedBufferResourceLoaderDelegate updateData:complete:]): (-[WebCoreSharedBufferResourceLoaderDelegate resourceLoader:shouldWaitForLoadingOfRequestedResource:]): (-[WebCoreSharedBufferResourceLoaderDelegate resourceLoader:didCancelLoadingRequest:]): (WebCore::ImageDecoderAVFObjC::setTrack): (WebCore::ImageDecoderAVFObjC::createFrameImageAtIndex): * platform/graphics/gstreamer/ImageDecoderGStreamer.cpp: (WebCore::ImageDecoderGStreamer::createFrameImageAtIndex): * platform/graphics/gstreamer/InbandTextTrackPrivateGStreamer.cpp: (WebCore::InbandTextTrackPrivateGStreamer::handleSample): (WebCore::InbandTextTrackPrivateGStreamer::notifyTrackOfSample): * platform/graphics/gstreamer/MainThreadNotifier.h: * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::parseInitDataFromProtectionMessage): (WebCore::MediaPlayerPrivateGStreamer::handleProtectionEvent): * platform/graphics/gstreamer/TrackPrivateBaseGStreamer.cpp: (WebCore::TrackPrivateBaseGStreamer::tagsChanged): (WebCore::TrackPrivateBaseGStreamer::notifyTrackOfTagsChanged): * platform/graphics/gstreamer/VideoSinkGStreamer.cpp: (VideoRenderRequestScheduler::start): (VideoRenderRequestScheduler::stop): (VideoRenderRequestScheduler::drain): (VideoRenderRequestScheduler::requestRender): * platform/graphics/gstreamer/eme/WebKitCommonEncryptionDecryptorGStreamer.cpp: (transformInPlace): (sinkEventHandler): (webKitMediaCommonEncryptionDecryptIsFlushing): (setContext): * platform/graphics/nicosia/NicosiaBuffer.cpp: (Nicosia::Buffer::beginPainting): (Nicosia::Buffer::completePainting): (Nicosia::Buffer::waitUntilPaintingComplete): * platform/graphics/nicosia/NicosiaPlatformLayer.h: (Nicosia::PlatformLayer::setSceneIntegration): (Nicosia::PlatformLayer::createUpdateScope): (Nicosia::CompositionLayer::updateState): (Nicosia::CompositionLayer::flushState): (Nicosia::CompositionLayer::commitState): (Nicosia::CompositionLayer::accessPending): (Nicosia::CompositionLayer::accessCommitted): * platform/graphics/nicosia/NicosiaScene.h: (Nicosia::Scene::accessState): * platform/graphics/nicosia/NicosiaSceneIntegration.cpp: (Nicosia::SceneIntegration::setClient): (Nicosia::SceneIntegration::invalidate): (Nicosia::SceneIntegration::requestUpdate): * platform/graphics/nicosia/texmap/NicosiaBackingStoreTextureMapperImpl.cpp: (Nicosia::BackingStoreTextureMapperImpl::flushUpdate): (Nicosia::BackingStoreTextureMapperImpl::takeUpdate): * platform/graphics/nicosia/texmap/NicosiaContentLayerTextureMapperImpl.cpp: (Nicosia::ContentLayerTextureMapperImpl::~ContentLayerTextureMapperImpl): (Nicosia::ContentLayerTextureMapperImpl::invalidateClient): (Nicosia::ContentLayerTextureMapperImpl::flushUpdate): (Nicosia::ContentLayerTextureMapperImpl::swapBuffersIfNeeded): * platform/graphics/nicosia/texmap/NicosiaImageBackingTextureMapperImpl.cpp: (Nicosia::ImageBackingTextureMapperImpl::flushUpdate): (Nicosia::ImageBackingTextureMapperImpl::takeUpdate): * platform/graphics/texmap/TextureMapperGCGLPlatformLayer.cpp: (WebCore::TextureMapperGCGLPlatformLayer::swapBuffersIfNeeded): * platform/graphics/win/MediaPlayerPrivateMediaFoundation.cpp: (WebCore::MediaPlayerPrivateMediaFoundation::load): (WebCore::MediaPlayerPrivateMediaFoundation::naturalSize const): (WebCore::MediaPlayerPrivateMediaFoundation::addListener): (WebCore::MediaPlayerPrivateMediaFoundation::removeListener): (WebCore::MediaPlayerPrivateMediaFoundation::notifyDeleted): (WebCore::MediaPlayerPrivateMediaFoundation::setNaturalSize): (WebCore::MediaPlayerPrivateMediaFoundation::AsyncCallback::Invoke): (WebCore::MediaPlayerPrivateMediaFoundation::AsyncCallback::onMediaPlayerDeleted): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::OnClockStart): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::OnClockStop): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::OnClockPause): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::OnClockRestart): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::OnClockSetRate): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::ProcessMessage): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::GetCurrentMediaType): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::InitServicePointers): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::ReleaseServicePointers): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::SetVideoWindow): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::GetVideoWindow): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::SetVideoPosition): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::GetVideoPosition): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::RepaintVideo): (WebCore::MediaPlayerPrivateMediaFoundation::VideoSamplePool::getSample): (WebCore::MediaPlayerPrivateMediaFoundation::VideoSamplePool::returnSample): (WebCore::MediaPlayerPrivateMediaFoundation::VideoSamplePool::areSamplesPending): (WebCore::MediaPlayerPrivateMediaFoundation::VideoSamplePool::initialize): (WebCore::MediaPlayerPrivateMediaFoundation::VideoSamplePool::clear): (WebCore::MediaPlayerPrivateMediaFoundation::VideoScheduler::stopScheduler): (WebCore::MediaPlayerPrivateMediaFoundation::VideoScheduler::scheduleSample): (WebCore::MediaPlayerPrivateMediaFoundation::VideoScheduler::processSamplesInQueue): (WebCore::MediaPlayerPrivateMediaFoundation::VideoScheduler::processSample): (WebCore::MediaPlayerPrivateMediaFoundation::VideoScheduler::schedulerThreadProcPrivate): (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::setVideoWindow): (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::setDestinationRect): (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::createVideoSamples): (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::checkDeviceState): (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::presentSample): (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::paintCurrentFrame): (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::createD3DDevice): * platform/image-decoders/ScalableImageDecoder.cpp: (WebCore::ScalableImageDecoder::frameIsCompleteAtIndex const): (WebCore::ScalableImageDecoder::frameHasAlphaAtIndex const): (WebCore::ScalableImageDecoder::frameBytesAtIndex const): (WebCore::ScalableImageDecoder::frameDurationAtIndex const): (WebCore::ScalableImageDecoder::createFrameImageAtIndex): * platform/image-decoders/ScalableImageDecoder.h: * platform/ios/LegacyTileCache.mm: (WebCore::LegacyTileCache::setTilesOpaque): (WebCore::LegacyTileCache::doLayoutTiles): (WebCore::LegacyTileCache::setCurrentScale): (WebCore::LegacyTileCache::commitScaleChange): (WebCore::LegacyTileCache::layoutTilesNow): (WebCore::LegacyTileCache::layoutTilesNowForRect): (WebCore::LegacyTileCache::removeAllNonVisibleTiles): (WebCore::LegacyTileCache::removeAllTiles): (WebCore::LegacyTileCache::removeForegroundTiles): (WebCore::LegacyTileCache::setContentReplacementImage): (WebCore::LegacyTileCache::contentReplacementImage const): (WebCore::LegacyTileCache::tileCreationTimerFired): (WebCore::LegacyTileCache::setNeedsDisplayInRect): (WebCore::LegacyTileCache::updateTilingMode): (WebCore::LegacyTileCache::setTilingMode): (WebCore::LegacyTileCache::doPendingRepaints): (WebCore::LegacyTileCache::flushSavedDisplayRects): (WebCore::LegacyTileCache::prepareToDraw): * platform/ios/LegacyTileLayerPool.mm: (WebCore::LegacyTileLayerPool::addLayer): (WebCore::LegacyTileLayerPool::takeLayerWithSize): (WebCore::LegacyTileLayerPool::setCapacity): (WebCore::LegacyTileLayerPool::prune): (WebCore::LegacyTileLayerPool::drain): * platform/ios/wak/WAKWindow.mm: (-[WAKWindow setExposedScrollViewRect:]): (-[WAKWindow exposedScrollViewRect]): * platform/ios/wak/WebCoreThread.mm: (RunWebThread): (StartWebThread): * platform/mediastream/gstreamer/RealtimeOutgoingAudioSourceLibWebRTC.cpp: (WebCore::RealtimeOutgoingAudioSourceLibWebRTC::audioSamplesAvailable): (WebCore::RealtimeOutgoingAudioSourceLibWebRTC::pullAudioData): * platform/network/cf/FormDataStreamCFNet.cpp: (WebCore::openNextStream): (WebCore::formFinalize): (WebCore::formClose): * platform/network/curl/CurlRequest.cpp: (WebCore::CurlRequest::setRequestPaused): (WebCore::CurlRequest::setCallbackPaused): (WebCore::CurlRequest::pausedStatusChanged): (WebCore::CurlRequest::enableDownloadToFile): (WebCore::CurlRequest::getDownloadedFilePath): (WebCore::CurlRequest::writeDataToDownloadFileIfEnabled): (WebCore::CurlRequest::closeDownloadFile): (WebCore::CurlRequest::cleanupDownloadFile): * platform/network/curl/CurlSSLHandle.cpp: (WebCore::CurlSSLHandle::allowAnyHTTPSCertificatesForHost): (WebCore::CurlSSLHandle::canIgnoreAnyHTTPSCertificatesForHost const): (WebCore::CurlSSLHandle::setClientCertificateInfo): (WebCore::CurlSSLHandle::getSSLClientCertificate const): * platform/sql/SQLiteDatabase.cpp: (WebCore::SQLiteDatabase::close): (WebCore::SQLiteDatabase::maximumSize): (WebCore::SQLiteDatabase::setMaximumSize): (WebCore::SQLiteDatabase::pageSize): (WebCore::SQLiteDatabase::freeSpaceSize): (WebCore::SQLiteDatabase::totalSize): (WebCore::SQLiteDatabase::runIncrementalVacuumCommand): (WebCore::SQLiteDatabase::interrupt): (WebCore::SQLiteDatabase::setAuthorizer): (WebCore::constructAndPrepareStatement): * platform/sql/SQLiteStatement.cpp: (WebCore::SQLiteStatement::step): Source/WebKit: * NetworkProcess/IndexedDB/WebIDBServer.cpp: (WebKit::m_closeCallback): (WebKit::WebIDBServer::getOrigins): (WebKit::WebIDBServer::closeAndDeleteDatabasesModifiedSince): (WebKit::WebIDBServer::closeAndDeleteDatabasesForOrigins): (WebKit::WebIDBServer::renameOrigin): (WebKit::WebIDBServer::openDatabase): (WebKit::WebIDBServer::deleteDatabase): (WebKit::WebIDBServer::abortTransaction): (WebKit::WebIDBServer::commitTransaction): (WebKit::WebIDBServer::didFinishHandlingVersionChangeTransaction): (WebKit::WebIDBServer::createObjectStore): (WebKit::WebIDBServer::deleteObjectStore): (WebKit::WebIDBServer::renameObjectStore): (WebKit::WebIDBServer::clearObjectStore): (WebKit::WebIDBServer::createIndex): (WebKit::WebIDBServer::deleteIndex): (WebKit::WebIDBServer::renameIndex): (WebKit::WebIDBServer::putOrAdd): (WebKit::WebIDBServer::getRecord): (WebKit::WebIDBServer::getAllRecords): (WebKit::WebIDBServer::getCount): (WebKit::WebIDBServer::deleteRecord): (WebKit::WebIDBServer::openCursor): (WebKit::WebIDBServer::iterateCursor): (WebKit::WebIDBServer::establishTransaction): (WebKit::WebIDBServer::databaseConnectionPendingClose): (WebKit::WebIDBServer::databaseConnectionClosed): (WebKit::WebIDBServer::abortOpenAndUpgradeNeeded): (WebKit::WebIDBServer::didFireVersionChangeEvent): (WebKit::WebIDBServer::openDBRequestCancelled): (WebKit::WebIDBServer::getAllDatabaseNamesAndVersions): (WebKit::WebIDBServer::addConnection): (WebKit::WebIDBServer::removeConnection): (WebKit::WebIDBServer::close): * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::writeSizeFile): (WebKit::CacheStorage::Engine::readSizeFile): (WebKit::CacheStorage::Engine::clearAllCachesFromDisk): (WebKit::CacheStorage::Engine::deleteNonEmptyDirectoryOnBackgroundThread): * NetworkProcess/glib/DNSCache.cpp: (WebKit::DNSCache::lookup): (WebKit::DNSCache::update): (WebKit::DNSCache::removeExpiredResponsesFired): (WebKit::DNSCache::clear): * Shared/CoordinatedGraphics/threadedcompositor/CompositingRunLoop.cpp: (WebKit::CompositingRunLoop::suspend): (WebKit::CompositingRunLoop::resume): (WebKit::CompositingRunLoop::scheduleUpdate): (WebKit::CompositingRunLoop::stopUpdates): (WebKit::CompositingRunLoop::updateTimerFired): * Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp: (WebKit::m_displayRefreshMonitor): (WebKit::ThreadedCompositor::setScaleFactor): (WebKit::ThreadedCompositor::setScrollPosition): (WebKit::ThreadedCompositor::setViewportSize): (WebKit::ThreadedCompositor::renderLayerTree): (WebKit::ThreadedCompositor::sceneUpdateFinished): (WebKit::ThreadedCompositor::updateSceneState): * UIProcess/API/glib/IconDatabase.cpp: (WebKit::IconDatabase::populatePageURLToIconURLMap): (WebKit::IconDatabase::clearLoadedIconsTimerFired): (WebKit::IconDatabase::checkIconURLAndSetPageURLIfNeeded): (WebKit::IconDatabase::loadIconForPageURL): (WebKit::IconDatabase::iconURLForPageURL): (WebKit::IconDatabase::setIconForPageURL): (WebKit::IconDatabase::clear): Source/WebKitLegacy: * Storage/InProcessIDBServer.cpp: (InProcessIDBServer::InProcessIDBServer): (InProcessIDBServer::deleteDatabase): (InProcessIDBServer::openDatabase): (InProcessIDBServer::abortTransaction): (InProcessIDBServer::commitTransaction): (InProcessIDBServer::didFinishHandlingVersionChangeTransaction): (InProcessIDBServer::createObjectStore): (InProcessIDBServer::deleteObjectStore): (InProcessIDBServer::renameObjectStore): (InProcessIDBServer::clearObjectStore): (InProcessIDBServer::createIndex): (InProcessIDBServer::deleteIndex): (InProcessIDBServer::renameIndex): (InProcessIDBServer::putOrAdd): (InProcessIDBServer::getRecord): (InProcessIDBServer::getAllRecords): (InProcessIDBServer::getCount): (InProcessIDBServer::deleteRecord): (InProcessIDBServer::openCursor): (InProcessIDBServer::iterateCursor): (InProcessIDBServer::establishTransaction): (InProcessIDBServer::databaseConnectionPendingClose): (InProcessIDBServer::databaseConnectionClosed): (InProcessIDBServer::abortOpenAndUpgradeNeeded): (InProcessIDBServer::didFireVersionChangeEvent): (InProcessIDBServer::openDBRequestCancelled): (InProcessIDBServer::getAllDatabaseNamesAndVersions): (InProcessIDBServer::closeAndDeleteDatabasesModifiedSince): * Storage/StorageAreaSync.cpp: (WebKit::StorageAreaSync::syncTimerFired): (WebKit::StorageAreaSync::performSync): * Storage/StorageTracker.cpp: (WebKit::StorageTracker::finishedImportingOriginIdentifiers): (WebKit::StorageTracker::syncImportOriginIdentifiers): (WebKit::StorageTracker::syncFileSystemAndTrackerDatabase): (WebKit::StorageTracker::setOriginDetails): (WebKit::StorageTracker::syncSetOriginDetails): (WebKit::StorageTracker::origins): (WebKit::StorageTracker::deleteAllOrigins): (WebKit::StorageTracker::syncDeleteAllOrigins): (WebKit::StorageTracker::deleteOrigin): (WebKit::StorageTracker::syncDeleteOrigin): (WebKit::StorageTracker::canDeleteOrigin): (WebKit::StorageTracker::cancelDeletingOrigin): (WebKit::StorageTracker::diskUsageForOrigin): Source/WebKitLegacy/mac: * WebView/WebView.mm: (-[WebView _synchronizeCustomFixedPositionLayoutRect]): (-[WebView _setCustomFixedPositionLayoutRectInWebThread:synchronize:]): (-[WebView _setCustomFixedPositionLayoutRect:]): (-[WebView _fetchCustomFixedPositionLayoutRect:]): Source/WebKitLegacy/win: * Plugins/PluginMainThreadScheduler.cpp: (WebCore::PluginMainThreadScheduler::scheduleCall): (WebCore::PluginMainThreadScheduler::registerPlugin): (WebCore::PluginMainThreadScheduler::unregisterPlugin): (WebCore::PluginMainThreadScheduler::dispatchCallsForPlugin): Source/WTF: * benchmarks/LockSpeedTest.cpp: * wtf/AutomaticThread.cpp: (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: * wtf/MetaAllocator.cpp: (WTF::MetaAllocatorHandle::shrink): (WTF::MetaAllocator::addFreshFreeSpace): (WTF::MetaAllocator::debugFreeSpaceSize): * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): * wtf/Seconds.cpp: (WTF::sleep): * wtf/TimeWithDynamicClockType.cpp: (WTF::sleep): * wtf/WorkerPool.cpp: (WTF::WorkerPool::WorkerPool): (WTF::WorkerPool::~WorkerPool): (WTF::WorkerPool::postTask): * wtf/posix/ThreadingPOSIX.cpp: (WTF::Thread::suspend): (WTF::Thread::resume): (WTF::Thread::getRegisters): * wtf/win/DbgHelperWin.cpp: (WTF::DbgHelper::SymFromAddress): * wtf/win/ThreadingWin.cpp: (WTF::Thread::suspend): (WTF::Thread::resume): (WTF::Thread::getRegisters): Tools: * TestWebKitAPI/Tests/WTF/WorkQueue.cpp: (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/WTF/glib/WorkQueueGLib.cpp: (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/WebCore/AbortableTaskQueue.cpp: (TestWebKitAPI::DeterministicScheduler::ThreadContext::waitMyTurn): (TestWebKitAPI::DeterministicScheduler::ThreadContext::yieldToThread): Canonical link: https://commits.webkit.org/238053@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@277920 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-05-22 16:49:42 +00:00
Locker locker { *m_lock };
WTF should make it easier to create threads that die automatically after inactivity https://bugs.webkit.org/show_bug.cgi?id=163576 Reviewed by Andreas Kling. Source/JavaScriptCore: Added a sleepSeconds() function, which made it easier for me to test this change. The WTF changes in this patch change how the JSC GC manages threads: the GC threads will now shut down automatically after 1 second of inactivity. Maybe this will save some memory. * jsc.cpp: (GlobalObject::finishCreation): (functionSleepSeconds): Source/WTF: For a long time now, I've been adding threads to WTF/JSC and each time I do this, I feel guilty because those threads don't shut down when they are inactive. For example, in bug 163562, I need to add a new GC thread. There will be one of them per VM. This means that a JSC API client that starts a lot of VMs will have a lot of threads. I don't think that's good. A common pattern for all of these threads is that they have some well-defined trigger that causes them to run. This trigger has a lock, a condition variable, some logic that determines if there is work to do, and then of course the logic for the thread's actual work. The thread bodies usually look like this: void Thingy::runThread() { for (;;) { Work work; { LockHolder locker(m_lock); while (!hasWork()) m_cond.wait(m_lock); work = takeWork(); } doWork(work); } } If you look at ParallelHelperPool (the GC's threads) and DFG::Worklist (some of the JIT's threads), you will see this pattern. This change adds a new kind of thread, called AutomaticThread, that lets you write threads to this pattern while getting automatic thread shutdown for free: instead of just waiting on a condition variable, AutomaticThread will have a timeout that causes the thread to die. The condition variable associated with AutomaticThread, called AutomaticThreadCondition, is smart enough to restart any threads that have decided to stop due to inactivity. The inactivity threshold is current just 1 second. In this patch I only adopt AutomaticThread for ParallelHelperPool. I plan to adopt it in more places soon. * WTF.xcodeproj/project.pbxproj: * wtf/AutomaticThread.cpp: Added. (WTF::AutomaticThreadCondition::create): (WTF::AutomaticThreadCondition::AutomaticThreadCondition): (WTF::AutomaticThreadCondition::~AutomaticThreadCondition): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Added. * wtf/CMakeLists.txt: * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::ParallelHelperPool): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::helperThreadBody): Deleted. (WTF::ParallelHelperPool::waitForClientWithTask): Deleted. * wtf/ParallelHelperPool.h: Canonical link: https://commits.webkit.org/181393@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207480 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-18 20:17:10 +00:00
while (m_isRunning)
m_isRunningCondition.wait(*m_lock);
}
The collector thread should only start when the mutator doesn't have heap access https://bugs.webkit.org/show_bug.cgi?id=167737 Reviewed by Keith Miller. JSTests: Add versions of splay that flash heap access, to simulate what might happen if a third-party app was running concurrent GC. In this case, we might actually start the collector thread. * stress/splay-flash-access-1ms.js: Added. (performance.now): (this.Setup.setup.setup): (this.TearDown.tearDown.tearDown): (Benchmark): (BenchmarkResult): (BenchmarkResult.prototype.valueOf): (BenchmarkSuite): (alert): (Math.random): (BenchmarkSuite.ResetRNG): (RunStep): (BenchmarkSuite.RunSuites): (BenchmarkSuite.CountBenchmarks): (BenchmarkSuite.GeometricMean): (BenchmarkSuite.GeometricMeanTime): (BenchmarkSuite.AverageAbovePercentile): (BenchmarkSuite.GeometricMeanLatency): (BenchmarkSuite.FormatScore): (BenchmarkSuite.prototype.NotifyStep): (BenchmarkSuite.prototype.NotifyResult): (BenchmarkSuite.prototype.NotifyError): (BenchmarkSuite.prototype.RunSingleBenchmark): (RunNextSetup): (RunNextBenchmark): (RunNextTearDown): (BenchmarkSuite.prototype.RunStep): (GeneratePayloadTree): (GenerateKey): (SplayUpdateStats): (InsertNewNode): (SplaySetup): (SplayTearDown): (SplayRun): (SplayTree): (SplayTree.prototype.isEmpty): (SplayTree.prototype.insert): (SplayTree.prototype.remove): (SplayTree.prototype.find): (SplayTree.prototype.findMax): (SplayTree.prototype.findGreatestLessThan): (SplayTree.prototype.exportKeys): (SplayTree.prototype.splay_): (SplayTree.Node): (SplayTree.Node.prototype.traverse_): (jscSetUp): (jscTearDown): (jscRun): (averageAbovePercentile): (printPercentile): * stress/splay-flash-access.js: Added. (performance.now): (this.Setup.setup.setup): (this.TearDown.tearDown.tearDown): (Benchmark): (BenchmarkResult): (BenchmarkResult.prototype.valueOf): (BenchmarkSuite): (alert): (Math.random): (BenchmarkSuite.ResetRNG): (RunStep): (BenchmarkSuite.RunSuites): (BenchmarkSuite.CountBenchmarks): (BenchmarkSuite.GeometricMean): (BenchmarkSuite.GeometricMeanTime): (BenchmarkSuite.AverageAbovePercentile): (BenchmarkSuite.GeometricMeanLatency): (BenchmarkSuite.FormatScore): (BenchmarkSuite.prototype.NotifyStep): (BenchmarkSuite.prototype.NotifyResult): (BenchmarkSuite.prototype.NotifyError): (BenchmarkSuite.prototype.RunSingleBenchmark): (RunNextSetup): (RunNextBenchmark): (RunNextTearDown): (BenchmarkSuite.prototype.RunStep): (GeneratePayloadTree): (GenerateKey): (SplayUpdateStats): (InsertNewNode): (SplaySetup): (SplayTearDown): (SplayRun): (SplayTree): (SplayTree.prototype.isEmpty): (SplayTree.prototype.insert): (SplayTree.prototype.remove): (SplayTree.prototype.find): (SplayTree.prototype.findMax): (SplayTree.prototype.findGreatestLessThan): (SplayTree.prototype.exportKeys): (SplayTree.prototype.splay_): (SplayTree.Node): (SplayTree.Node.prototype.traverse_): (jscSetUp): (jscTearDown): (jscRun): (averageAbovePercentile): (printPercentile): Source/JavaScriptCore: This turns the collector thread's workflow into a state machine, so that the mutator thread can run it directly. This reduces the amount of synchronization we do with the collector thread, and means that most apps will never start the collector thread. The collector thread will still start when we need to finish collecting and we don't have heap access. In this new world, "stopping the world" means relinquishing control of collection to the mutator. This means tracking who is conducting collection. I use the GCConductor enum to say who is conducting. It's either GCConductor::Mutator or GCConductor::Collector. I use the term "conn" to refer to the concept of conducting (having the conn, relinquishing the conn, taking the conn). So, stopping the world means giving the mutator the conn. Releasing heap access means giving the collector the conn. This meant bringing back the conservative scan of the calling thread. It turns out that this scan was too slow to be called on each GC increment because apparently setjmp() now does system calls. So, I wrote our own callee save register saving for the GC. Then I had doubts about whether or not it was correct, so I also made it so that the GC only rarely asks for the register state. I think we still want to use my register saving code instead of setjmp because setjmp seems to save things we don't need, and that could make us overly conservative. It turns out that this new scheduling discipline makes the old space-time scheduler perform better than the new stochastic space-time scheduler on systems with fewer than 4 cores. This is because the mutator having the conn enables us to time the mutator<->collector context switches by polling. The OS is never involved. So, we can use super precise timing. This allows the old space-time schduler to shine like it hadn't before. The splay results imply that this is all a good thing. On 2-core systems, this reduces pause times by 40% and it increases throughput about 5%. On 1-core systems, this reduces pause times by half and reduces throughput by 8%. On 4-or-more-core systems, this doesn't seem to have much effect. * CMakeLists.txt: * JavaScriptCore.xcodeproj/project.pbxproj: * bytecode/CodeBlock.cpp: (JSC::CodeBlock::visitChildren): * dfg/DFGWorklist.cpp: (JSC::DFG::Worklist::ThreadBody::ThreadBody): (JSC::DFG::Worklist::dump): (JSC::DFG::numberOfWorklists): (JSC::DFG::ensureWorklistForIndex): (JSC::DFG::existingWorklistForIndexOrNull): (JSC::DFG::existingWorklistForIndex): * dfg/DFGWorklist.h: (JSC::DFG::numberOfWorklists): Deleted. (JSC::DFG::ensureWorklistForIndex): Deleted. (JSC::DFG::existingWorklistForIndexOrNull): Deleted. (JSC::DFG::existingWorklistForIndex): Deleted. * heap/CollectingScope.h: Added. (JSC::CollectingScope::CollectingScope): (JSC::CollectingScope::~CollectingScope): * heap/CollectorPhase.cpp: Added. (JSC::worldShouldBeSuspended): (WTF::printInternal): * heap/CollectorPhase.h: Added. * heap/EdenGCActivityCallback.cpp: (JSC::EdenGCActivityCallback::lastGCLength): * heap/FullGCActivityCallback.cpp: (JSC::FullGCActivityCallback::doCollection): (JSC::FullGCActivityCallback::lastGCLength): * heap/GCConductor.cpp: Added. (JSC::gcConductorShortName): (WTF::printInternal): * heap/GCConductor.h: Added. * heap/GCFinalizationCallback.cpp: Added. (JSC::GCFinalizationCallback::GCFinalizationCallback): (JSC::GCFinalizationCallback::~GCFinalizationCallback): * heap/GCFinalizationCallback.h: Added. (JSC::GCFinalizationCallbackFuncAdaptor::GCFinalizationCallbackFuncAdaptor): (JSC::createGCFinalizationCallback): * heap/Heap.cpp: (JSC::Heap::Thread::Thread): (JSC::Heap::Heap): (JSC::Heap::lastChanceToFinalize): (JSC::Heap::gatherStackRoots): (JSC::Heap::updateObjectCounts): (JSC::Heap::sweepSynchronously): (JSC::Heap::collectAllGarbage): (JSC::Heap::collectAsync): (JSC::Heap::collectSync): (JSC::Heap::shouldCollectInCollectorThread): (JSC::Heap::collectInCollectorThread): (JSC::Heap::checkConn): (JSC::Heap::runNotRunningPhase): (JSC::Heap::runBeginPhase): (JSC::Heap::runFixpointPhase): (JSC::Heap::runConcurrentPhase): (JSC::Heap::runReloopPhase): (JSC::Heap::runEndPhase): (JSC::Heap::changePhase): (JSC::Heap::finishChangingPhase): (JSC::Heap::stopThePeriphery): (JSC::Heap::resumeThePeriphery): (JSC::Heap::stopTheMutator): (JSC::Heap::resumeTheMutator): (JSC::Heap::stopIfNecessarySlow): (JSC::Heap::collectInMutatorThread): (JSC::Heap::waitForCollector): (JSC::Heap::acquireAccessSlow): (JSC::Heap::releaseAccessSlow): (JSC::Heap::relinquishConn): (JSC::Heap::finishRelinquishingConn): (JSC::Heap::handleNeedFinalize): (JSC::Heap::notifyThreadStopping): (JSC::Heap::finalize): (JSC::Heap::addFinalizationCallback): (JSC::Heap::requestCollection): (JSC::Heap::waitForCollection): (JSC::Heap::updateAllocationLimits): (JSC::Heap::didFinishCollection): (JSC::Heap::collectIfNecessaryOrDefer): (JSC::Heap::notifyIsSafeToCollect): (JSC::Heap::preventCollection): (JSC::Heap::performIncrement): (JSC::Heap::markToFixpoint): Deleted. (JSC::Heap::shouldCollectInThread): Deleted. (JSC::Heap::collectInThread): Deleted. (JSC::Heap::stopTheWorld): Deleted. (JSC::Heap::resumeTheWorld): Deleted. * heap/Heap.h: (JSC::Heap::machineThreads): (JSC::Heap::lastFullGCLength): (JSC::Heap::lastEdenGCLength): (JSC::Heap::increaseLastFullGCLength): * heap/HeapInlines.h: (JSC::Heap::mutatorIsStopped): Deleted. * heap/HeapStatistics.cpp: Removed. * heap/HeapStatistics.h: Removed. * heap/HelpingGCScope.h: Removed. * heap/IncrementalSweeper.cpp: (JSC::IncrementalSweeper::stopSweeping): (JSC::IncrementalSweeper::willFinishSweeping): Deleted. * heap/IncrementalSweeper.h: * heap/MachineStackMarker.cpp: (JSC::MachineThreads::gatherFromCurrentThread): (JSC::MachineThreads::gatherConservativeRoots): (JSC::callWithCurrentThreadState): * heap/MachineStackMarker.h: * heap/MarkedAllocator.cpp: (JSC::MarkedAllocator::allocateSlowCaseImpl): * heap/MarkedBlock.cpp: (JSC::MarkedBlock::Handle::sweep): * heap/MarkedSpace.cpp: (JSC::MarkedSpace::sweep): * heap/MutatorState.cpp: (WTF::printInternal): * heap/MutatorState.h: * heap/RegisterState.h: Added. * heap/RunningScope.h: Added. (JSC::RunningScope::RunningScope): (JSC::RunningScope::~RunningScope): * heap/SlotVisitor.cpp: (JSC::SlotVisitor::SlotVisitor): (JSC::SlotVisitor::drain): (JSC::SlotVisitor::drainFromShared): (JSC::SlotVisitor::drainInParallelPassively): (JSC::SlotVisitor::donateAll): (JSC::SlotVisitor::donate): * heap/SlotVisitor.h: (JSC::SlotVisitor::codeName): * heap/StochasticSpaceTimeMutatorScheduler.cpp: (JSC::StochasticSpaceTimeMutatorScheduler::beginCollection): (JSC::StochasticSpaceTimeMutatorScheduler::synchronousDrainingDidStall): (JSC::StochasticSpaceTimeMutatorScheduler::timeToStop): * heap/SweepingScope.h: Added. (JSC::SweepingScope::SweepingScope): (JSC::SweepingScope::~SweepingScope): * jit/JITWorklist.cpp: (JSC::JITWorklist::Thread::Thread): * jsc.cpp: (GlobalObject::finishCreation): (functionFlashHeapAccess): * runtime/InitializeThreading.cpp: (JSC::initializeThreading): * runtime/JSCellInlines.h: (JSC::JSCell::classInfo): * runtime/Options.cpp: (JSC::overrideDefaults): * runtime/Options.h: * runtime/TestRunnerUtils.cpp: (JSC::finalizeStatsAtEndOfTesting): Source/WebCore: Added new tests in JSTests. The WebCore changes involve: - Refactoring around new header discipline. - Adding crazy GC APIs to window.internals to enable us to test the GC's runloop discipline. * ForwardingHeaders/heap/GCFinalizationCallback.h: Added. * ForwardingHeaders/heap/IncrementalSweeper.h: Added. * ForwardingHeaders/heap/MachineStackMarker.h: Added. * ForwardingHeaders/heap/RunningScope.h: Added. * bindings/js/CommonVM.cpp: * testing/Internals.cpp: (WebCore::Internals::parserMetaData): (WebCore::Internals::isReadableStreamDisturbed): (WebCore::Internals::isGCRunning): (WebCore::Internals::addGCFinalizationCallback): (WebCore::Internals::stopSweeping): (WebCore::Internals::startSweeping): * testing/Internals.h: * testing/Internals.idl: Source/WTF: Extend the use of AbstractLocker so that we can use more locking idioms. * wtf/AutomaticThread.cpp: (WTF::AutomaticThreadCondition::notifyOne): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::tryStop): (WTF::AutomaticThread::isWaiting): (WTF::AutomaticThread::notify): (WTF::AutomaticThread::start): (WTF::AutomaticThread::threadIsStopping): * wtf/AutomaticThread.h: * wtf/NumberOfCores.cpp: (WTF::numberOfProcessorCores): * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::claimTask): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::hasClientWithTask): (WTF::ParallelHelperPool::getClientWithTask): * wtf/ParallelHelperPool.h: Tools: Make more tests collect continuously. * Scripts/run-jsc-stress-tests: Canonical link: https://commits.webkit.org/185692@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@212778 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-02-22 00:58:15 +00:00
void AutomaticThread::start(const AbstractLocker&)
WTF should make it easier to create threads that die automatically after inactivity https://bugs.webkit.org/show_bug.cgi?id=163576 Reviewed by Andreas Kling. Source/JavaScriptCore: Added a sleepSeconds() function, which made it easier for me to test this change. The WTF changes in this patch change how the JSC GC manages threads: the GC threads will now shut down automatically after 1 second of inactivity. Maybe this will save some memory. * jsc.cpp: (GlobalObject::finishCreation): (functionSleepSeconds): Source/WTF: For a long time now, I've been adding threads to WTF/JSC and each time I do this, I feel guilty because those threads don't shut down when they are inactive. For example, in bug 163562, I need to add a new GC thread. There will be one of them per VM. This means that a JSC API client that starts a lot of VMs will have a lot of threads. I don't think that's good. A common pattern for all of these threads is that they have some well-defined trigger that causes them to run. This trigger has a lock, a condition variable, some logic that determines if there is work to do, and then of course the logic for the thread's actual work. The thread bodies usually look like this: void Thingy::runThread() { for (;;) { Work work; { LockHolder locker(m_lock); while (!hasWork()) m_cond.wait(m_lock); work = takeWork(); } doWork(work); } } If you look at ParallelHelperPool (the GC's threads) and DFG::Worklist (some of the JIT's threads), you will see this pattern. This change adds a new kind of thread, called AutomaticThread, that lets you write threads to this pattern while getting automatic thread shutdown for free: instead of just waiting on a condition variable, AutomaticThread will have a timeout that causes the thread to die. The condition variable associated with AutomaticThread, called AutomaticThreadCondition, is smart enough to restart any threads that have decided to stop due to inactivity. The inactivity threshold is current just 1 second. In this patch I only adopt AutomaticThread for ParallelHelperPool. I plan to adopt it in more places soon. * WTF.xcodeproj/project.pbxproj: * wtf/AutomaticThread.cpp: Added. (WTF::AutomaticThreadCondition::create): (WTF::AutomaticThreadCondition::AutomaticThreadCondition): (WTF::AutomaticThreadCondition::~AutomaticThreadCondition): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Added. * wtf/CMakeLists.txt: * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::ParallelHelperPool): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::helperThreadBody): Deleted. (WTF::ParallelHelperPool::waitForClientWithTask): Deleted. * wtf/ParallelHelperPool.h: Canonical link: https://commits.webkit.org/181393@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207480 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-18 20:17:10 +00:00
{
The GC should be in a thread https://bugs.webkit.org/show_bug.cgi?id=163562 Reviewed by Geoffrey Garen and Andreas Kling. Source/JavaScriptCore: In a concurrent GC, the work of collecting happens on a separate thread. This patch implements this, and schedules the thread the way that a concurrent GC thread would be scheduled. But, the GC isn't actually concurrent yet because it calls stopTheWorld() before doing anything and calls resumeTheWorld() after it's done with everything. The next step will be to make it really concurrent by basically calling stopTheWorld()/resumeTheWorld() around bounded snippets of work while making most of the work happen with the world running. Our GC will probably always have stop-the-world phases because the semantics of JSC weak references call for it. This implements concurrent GC scheduling. This means that there is no longer a Heap::collect() API. Instead, you can call collectAsync() which makes sure that a GC is scheduled (it will do nothing if one is scheduled or ongoing) or you can call collectSync() to schedule a GC and wait for it to happen. I made our debugging stuff call collectSync(). It should be a goal to never call collectSync() except for debugging or benchmark harness hacks. The collector thread is an AutomaticThread, so it won't linger when not in use. It works on a ticket-based system, like you would see at the DMV. A ticket is a 64-bit integer. There are two ticket counters: last granted and last served. When you request a collection, last granted is incremented and its new value given to you. When a collection completes, last served is incremented. collectSync() waits until last served catches up to what last granted had been at the time you requested a GC. This means that if you request a sync GC in the middle of an async GC, you will wait for that async GC to finish and then you will request and wait for your sync GC. The synchronization between the collector thread and the main threads is complex. The collector thread needs to be able to ask the main thread to stop. It needs to be able to do some post-GC clean-up, like the synchronous CodeBlock and LargeAllocation sweeps, on the main thread. The collector needs to be able to ask the main thread to execute a cross-modifying code fence before running any JIT code, since the GC might aid the JIT worklist and run JIT finalization. It's possible for the GC to want the main thread to run something at the same time that the main thread wants to wait for the GC. The main thread needs to be able to run non-JSC stuff without causing the GC to completely stall. The main thread needs to be able to query its own state (is there a request to stop?) and change it (running JSC versus not) quickly, since this may happen on hot paths. This kind of intertwined system of requests, notifications, and state changes requires a combination of lock-free algorithms and waiting. So, this is all implemented using a Atomic<unsigned> Heap::m_worldState, which has bits to represent things being requested by the collector and the heap access state of the mutator. I am borrowing a lot of terms that I've seen in other VMs that I've worked on. Here's what they mean: - Stop the world: make sure that either the mutator is not running, or that it's not running code that could mess with the heap. - Heap access: the mutator is said to have heap access if it could mess with the heap. If you stop the world and the mutator doesn't have heap access, all you're doing is making sure that it will block when it tries to acquire heap access. This means that our GC is already fully concurrent in cases where the GC is requested while the mutator has no heap access. This probably won't happen, but if it did then it should just work. Usually, stopping the world means that we state our shouldStop request with m_worldState, and a future call to Heap::stopIfNecessary() will go to slow path and stop. The act of stopping or waiting to acquire heap access is managed by using ParkingLot API directly on m_worldState. This works out great because it would be very awkward to get the same functionality using locks and condition variables, since we want stopIfNecessary/acquireAccess/requestAccess fast paths that are single atomic instructions (load/CAS/CAS, respectively). The mutator will call these things frequently. Currently we have Heap::stopIfNecessary() polling on every allocator slow path, but we may want to make it even more frequent than that. Currently only JSC API clients benefit from the heap access optimization. The DOM forces us to assume that heap access is permanently on, since DOM manipulation doesn't always hold the JSLock. We could still allow the GC to proceed when the runloop is idle by having the GC put a task on the runloop that just calls stopIfNecessary(). This is perf neutral. The only behavior change that clients ought to observe is that marking and the weak fixpoint happen on a separate thread. Marking was already parallel so it already handled multiple threads, but now it _never_ runs on the main thread. The weak fixpoint needed some help to be able to run on another thread - mostly because there was some code in IndexedDB that was using thread specifics in the weak fixpoint. * API/JSBase.cpp: (JSSynchronousEdenCollectForDebugging): * API/JSManagedValue.mm: (-[JSManagedValue initWithValue:]): * heap/EdenGCActivityCallback.cpp: (JSC::EdenGCActivityCallback::doCollection): * heap/FullGCActivityCallback.cpp: (JSC::FullGCActivityCallback::doCollection): * heap/Heap.cpp: (JSC::Heap::Thread::Thread): (JSC::Heap::Heap): (JSC::Heap::lastChanceToFinalize): (JSC::Heap::markRoots): (JSC::Heap::gatherStackRoots): (JSC::Heap::deleteUnmarkedCompiledCode): (JSC::Heap::collectAllGarbage): (JSC::Heap::collectAsync): (JSC::Heap::collectSync): (JSC::Heap::shouldCollectInThread): (JSC::Heap::collectInThread): (JSC::Heap::stopTheWorld): (JSC::Heap::resumeTheWorld): (JSC::Heap::stopIfNecessarySlow): (JSC::Heap::acquireAccessSlow): (JSC::Heap::releaseAccessSlow): (JSC::Heap::handleDidJIT): (JSC::Heap::handleNeedFinalize): (JSC::Heap::setDidJIT): (JSC::Heap::setNeedFinalize): (JSC::Heap::waitWhileNeedFinalize): (JSC::Heap::finalize): (JSC::Heap::requestCollection): (JSC::Heap::waitForCollection): (JSC::Heap::didFinishCollection): (JSC::Heap::canCollect): (JSC::Heap::shouldCollectHeuristic): (JSC::Heap::shouldCollect): (JSC::Heap::collectIfNecessaryOrDefer): (JSC::Heap::collectAccordingToDeferGCProbability): (JSC::Heap::collect): Deleted. (JSC::Heap::collectWithoutAnySweep): Deleted. (JSC::Heap::collectImpl): Deleted. * heap/Heap.h: (JSC::Heap::ReleaseAccessScope::ReleaseAccessScope): (JSC::Heap::ReleaseAccessScope::~ReleaseAccessScope): * heap/HeapInlines.h: (JSC::Heap::acquireAccess): (JSC::Heap::releaseAccess): (JSC::Heap::stopIfNecessary): * heap/MachineStackMarker.cpp: (JSC::MachineThreads::gatherConservativeRoots): (JSC::MachineThreads::gatherFromCurrentThread): Deleted. * heap/MachineStackMarker.h: * jit/JITWorklist.cpp: (JSC::JITWorklist::completeAllForVM): * jit/JITWorklist.h: * jsc.cpp: (functionFullGC): (functionEdenGC): * runtime/InitializeThreading.cpp: (JSC::initializeThreading): * runtime/JSLock.cpp: (JSC::JSLock::didAcquireLock): (JSC::JSLock::unlock): (JSC::JSLock::willReleaseLock): * tools/JSDollarVMPrototype.cpp: (JSC::JSDollarVMPrototype::edenGC): Source/WebCore: No new tests because existing tests cover this. We now need to be more careful about using JSLock. This fixes some places that were not holding it. New assertions in the GC are more likely to catch this than before. * bindings/js/WorkerScriptController.cpp: (WebCore::WorkerScriptController::WorkerScriptController): Source/WTF: This fixes some bugs and adds a few features. * wtf/Atomics.h: The GC may do work on behalf of the JIT. If it does, the main thread needs to execute a cross-modifying code fence. This is cpuid on x86 and I believe it's isb on ARM. It would have been an isync on PPC and I think that isb is the ARM equivalent. (WTF::arm_isb): (WTF::crossModifyingCodeFence): (WTF::x86_ortop): (WTF::x86_cpuid): * wtf/AutomaticThread.cpp: I accidentally had AutomaticThreadCondition inherit from ThreadSafeRefCounted<AutomaticThread> [sic]. This never crashed before because all of our prior AutomaticThreadConditions were immortal. (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: * wtf/MainThread.cpp: Need to allow initializeGCThreads() to be called separately because it's now more than just a debugging thing. (WTF::initializeGCThreads): Canonical link: https://commits.webkit.org/182065@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208306 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-02 22:01:04 +00:00
RELEASE_ASSERT(m_isRunning);
WTF should make it easier to create threads that die automatically after inactivity https://bugs.webkit.org/show_bug.cgi?id=163576 Reviewed by Andreas Kling. Source/JavaScriptCore: Added a sleepSeconds() function, which made it easier for me to test this change. The WTF changes in this patch change how the JSC GC manages threads: the GC threads will now shut down automatically after 1 second of inactivity. Maybe this will save some memory. * jsc.cpp: (GlobalObject::finishCreation): (functionSleepSeconds): Source/WTF: For a long time now, I've been adding threads to WTF/JSC and each time I do this, I feel guilty because those threads don't shut down when they are inactive. For example, in bug 163562, I need to add a new GC thread. There will be one of them per VM. This means that a JSC API client that starts a lot of VMs will have a lot of threads. I don't think that's good. A common pattern for all of these threads is that they have some well-defined trigger that causes them to run. This trigger has a lock, a condition variable, some logic that determines if there is work to do, and then of course the logic for the thread's actual work. The thread bodies usually look like this: void Thingy::runThread() { for (;;) { Work work; { LockHolder locker(m_lock); while (!hasWork()) m_cond.wait(m_lock); work = takeWork(); } doWork(work); } } If you look at ParallelHelperPool (the GC's threads) and DFG::Worklist (some of the JIT's threads), you will see this pattern. This change adds a new kind of thread, called AutomaticThread, that lets you write threads to this pattern while getting automatic thread shutdown for free: instead of just waiting on a condition variable, AutomaticThread will have a timeout that causes the thread to die. The condition variable associated with AutomaticThread, called AutomaticThreadCondition, is smart enough to restart any threads that have decided to stop due to inactivity. The inactivity threshold is current just 1 second. In this patch I only adopt AutomaticThread for ParallelHelperPool. I plan to adopt it in more places soon. * WTF.xcodeproj/project.pbxproj: * wtf/AutomaticThread.cpp: Added. (WTF::AutomaticThreadCondition::create): (WTF::AutomaticThreadCondition::AutomaticThreadCondition): (WTF::AutomaticThreadCondition::~AutomaticThreadCondition): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Added. * wtf/CMakeLists.txt: * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::ParallelHelperPool): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::helperThreadBody): Deleted. (WTF::ParallelHelperPool::waitForClientWithTask): Deleted. * wtf/ParallelHelperPool.h: Canonical link: https://commits.webkit.org/181393@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207480 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-18 20:17:10 +00:00
RefPtr<AutomaticThread> preserveThisForThread = this;
The GC should be in a thread https://bugs.webkit.org/show_bug.cgi?id=163562 Reviewed by Geoffrey Garen and Andreas Kling. Source/JavaScriptCore: In a concurrent GC, the work of collecting happens on a separate thread. This patch implements this, and schedules the thread the way that a concurrent GC thread would be scheduled. But, the GC isn't actually concurrent yet because it calls stopTheWorld() before doing anything and calls resumeTheWorld() after it's done with everything. The next step will be to make it really concurrent by basically calling stopTheWorld()/resumeTheWorld() around bounded snippets of work while making most of the work happen with the world running. Our GC will probably always have stop-the-world phases because the semantics of JSC weak references call for it. This implements concurrent GC scheduling. This means that there is no longer a Heap::collect() API. Instead, you can call collectAsync() which makes sure that a GC is scheduled (it will do nothing if one is scheduled or ongoing) or you can call collectSync() to schedule a GC and wait for it to happen. I made our debugging stuff call collectSync(). It should be a goal to never call collectSync() except for debugging or benchmark harness hacks. The collector thread is an AutomaticThread, so it won't linger when not in use. It works on a ticket-based system, like you would see at the DMV. A ticket is a 64-bit integer. There are two ticket counters: last granted and last served. When you request a collection, last granted is incremented and its new value given to you. When a collection completes, last served is incremented. collectSync() waits until last served catches up to what last granted had been at the time you requested a GC. This means that if you request a sync GC in the middle of an async GC, you will wait for that async GC to finish and then you will request and wait for your sync GC. The synchronization between the collector thread and the main threads is complex. The collector thread needs to be able to ask the main thread to stop. It needs to be able to do some post-GC clean-up, like the synchronous CodeBlock and LargeAllocation sweeps, on the main thread. The collector needs to be able to ask the main thread to execute a cross-modifying code fence before running any JIT code, since the GC might aid the JIT worklist and run JIT finalization. It's possible for the GC to want the main thread to run something at the same time that the main thread wants to wait for the GC. The main thread needs to be able to run non-JSC stuff without causing the GC to completely stall. The main thread needs to be able to query its own state (is there a request to stop?) and change it (running JSC versus not) quickly, since this may happen on hot paths. This kind of intertwined system of requests, notifications, and state changes requires a combination of lock-free algorithms and waiting. So, this is all implemented using a Atomic<unsigned> Heap::m_worldState, which has bits to represent things being requested by the collector and the heap access state of the mutator. I am borrowing a lot of terms that I've seen in other VMs that I've worked on. Here's what they mean: - Stop the world: make sure that either the mutator is not running, or that it's not running code that could mess with the heap. - Heap access: the mutator is said to have heap access if it could mess with the heap. If you stop the world and the mutator doesn't have heap access, all you're doing is making sure that it will block when it tries to acquire heap access. This means that our GC is already fully concurrent in cases where the GC is requested while the mutator has no heap access. This probably won't happen, but if it did then it should just work. Usually, stopping the world means that we state our shouldStop request with m_worldState, and a future call to Heap::stopIfNecessary() will go to slow path and stop. The act of stopping or waiting to acquire heap access is managed by using ParkingLot API directly on m_worldState. This works out great because it would be very awkward to get the same functionality using locks and condition variables, since we want stopIfNecessary/acquireAccess/requestAccess fast paths that are single atomic instructions (load/CAS/CAS, respectively). The mutator will call these things frequently. Currently we have Heap::stopIfNecessary() polling on every allocator slow path, but we may want to make it even more frequent than that. Currently only JSC API clients benefit from the heap access optimization. The DOM forces us to assume that heap access is permanently on, since DOM manipulation doesn't always hold the JSLock. We could still allow the GC to proceed when the runloop is idle by having the GC put a task on the runloop that just calls stopIfNecessary(). This is perf neutral. The only behavior change that clients ought to observe is that marking and the weak fixpoint happen on a separate thread. Marking was already parallel so it already handled multiple threads, but now it _never_ runs on the main thread. The weak fixpoint needed some help to be able to run on another thread - mostly because there was some code in IndexedDB that was using thread specifics in the weak fixpoint. * API/JSBase.cpp: (JSSynchronousEdenCollectForDebugging): * API/JSManagedValue.mm: (-[JSManagedValue initWithValue:]): * heap/EdenGCActivityCallback.cpp: (JSC::EdenGCActivityCallback::doCollection): * heap/FullGCActivityCallback.cpp: (JSC::FullGCActivityCallback::doCollection): * heap/Heap.cpp: (JSC::Heap::Thread::Thread): (JSC::Heap::Heap): (JSC::Heap::lastChanceToFinalize): (JSC::Heap::markRoots): (JSC::Heap::gatherStackRoots): (JSC::Heap::deleteUnmarkedCompiledCode): (JSC::Heap::collectAllGarbage): (JSC::Heap::collectAsync): (JSC::Heap::collectSync): (JSC::Heap::shouldCollectInThread): (JSC::Heap::collectInThread): (JSC::Heap::stopTheWorld): (JSC::Heap::resumeTheWorld): (JSC::Heap::stopIfNecessarySlow): (JSC::Heap::acquireAccessSlow): (JSC::Heap::releaseAccessSlow): (JSC::Heap::handleDidJIT): (JSC::Heap::handleNeedFinalize): (JSC::Heap::setDidJIT): (JSC::Heap::setNeedFinalize): (JSC::Heap::waitWhileNeedFinalize): (JSC::Heap::finalize): (JSC::Heap::requestCollection): (JSC::Heap::waitForCollection): (JSC::Heap::didFinishCollection): (JSC::Heap::canCollect): (JSC::Heap::shouldCollectHeuristic): (JSC::Heap::shouldCollect): (JSC::Heap::collectIfNecessaryOrDefer): (JSC::Heap::collectAccordingToDeferGCProbability): (JSC::Heap::collect): Deleted. (JSC::Heap::collectWithoutAnySweep): Deleted. (JSC::Heap::collectImpl): Deleted. * heap/Heap.h: (JSC::Heap::ReleaseAccessScope::ReleaseAccessScope): (JSC::Heap::ReleaseAccessScope::~ReleaseAccessScope): * heap/HeapInlines.h: (JSC::Heap::acquireAccess): (JSC::Heap::releaseAccess): (JSC::Heap::stopIfNecessary): * heap/MachineStackMarker.cpp: (JSC::MachineThreads::gatherConservativeRoots): (JSC::MachineThreads::gatherFromCurrentThread): Deleted. * heap/MachineStackMarker.h: * jit/JITWorklist.cpp: (JSC::JITWorklist::completeAllForVM): * jit/JITWorklist.h: * jsc.cpp: (functionFullGC): (functionEdenGC): * runtime/InitializeThreading.cpp: (JSC::initializeThreading): * runtime/JSLock.cpp: (JSC::JSLock::didAcquireLock): (JSC::JSLock::unlock): (JSC::JSLock::willReleaseLock): * tools/JSDollarVMPrototype.cpp: (JSC::JSDollarVMPrototype::edenGC): Source/WebCore: No new tests because existing tests cover this. We now need to be more careful about using JSLock. This fixes some places that were not holding it. New assertions in the GC are more likely to catch this than before. * bindings/js/WorkerScriptController.cpp: (WebCore::WorkerScriptController::WorkerScriptController): Source/WTF: This fixes some bugs and adds a few features. * wtf/Atomics.h: The GC may do work on behalf of the JIT. If it does, the main thread needs to execute a cross-modifying code fence. This is cpuid on x86 and I believe it's isb on ARM. It would have been an isync on PPC and I think that isb is the ARM equivalent. (WTF::arm_isb): (WTF::crossModifyingCodeFence): (WTF::x86_ortop): (WTF::x86_cpuid): * wtf/AutomaticThread.cpp: I accidentally had AutomaticThreadCondition inherit from ThreadSafeRefCounted<AutomaticThread> [sic]. This never crashed before because all of our prior AutomaticThreadConditions were immortal. (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: * wtf/MainThread.cpp: Need to allow initializeGCThreads() to be called separately because it's now more than just a debugging thing. (WTF::initializeGCThreads): Canonical link: https://commits.webkit.org/182065@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208306 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-02 22:01:04 +00:00
m_hasUnderlyingThread = true;
[WTF] Thread::create should have Thread::tryCreate https://bugs.webkit.org/show_bug.cgi?id=180333 Reviewed by Darin Adler. Source/JavaScriptCore: * assembler/testmasm.cpp: (JSC::run): * b3/air/testair.cpp: * b3/testb3.cpp: (JSC::B3::run): * jsc.cpp: (functionDollarAgentStart): Source/WebCore: No behavior change. * bindings/js/GCController.cpp: (WebCore::GCController::garbageCollectOnAlternateThreadForDebugging): * platform/audio/ReverbConvolver.cpp: (WebCore::ReverbConvolver::ReverbConvolver): * platform/audio/ReverbConvolver.h: * workers/WorkerThread.cpp: (WebCore::WorkerThread::start): Source/WebKit: * UIProcess/API/glib/IconDatabase.cpp: (WebKit::IconDatabase::open): * UIProcess/linux/MemoryPressureMonitor.cpp: (WebKit::MemoryPressureMonitor::MemoryPressureMonitor): Source/WebKitLegacy: * Storage/StorageThread.cpp: (WebCore::StorageThread::start): Source/WebKitLegacy/win: * WebKitQuartzCoreAdditions/CVDisplayLink.cpp: (WKQCA::CVDisplayLink::start): Source/WTF: Many callers of Thread::create assume that it returns non-nullptr Thread. But if the number of threads hits the limit in the system, creating Thread would fail. In that case, it is really difficult to keep WebKit working. We introduce Thread::tryCreate, and change the returned value from Thread::create from RefPtr<Thread> to Ref<Thread>. In Thread::create, we ensure thread creation succeeds by RELEASE_ASSERT. And we use Thread::create intentionally if the caller assumes that thread should be created. * wtf/AutomaticThread.cpp: (WTF::AutomaticThread::start): * wtf/ParallelJobsGeneric.cpp: (WTF::ParallelEnvironment::ThreadPrivate::tryLockFor): * wtf/Threading.cpp: (WTF::Thread::tryCreate): (WTF::Thread::create): Deleted. * wtf/Threading.h: (WTF::Thread::create): * wtf/WorkQueue.cpp: (WTF::WorkQueue::concurrentApply): Tools: * TestWebKitAPI/Tests/WTF/Condition.cpp: * TestWebKitAPI/Tests/WTF/ParkingLot.cpp: * TestWebKitAPI/Tests/WTF/Signals.cpp: (TEST): * TestWebKitAPI/Tests/WTF/ThreadGroup.cpp: (TestWebKitAPI::testThreadGroup): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/196593@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225778 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-12 10:35:39 +00:00
Thread::create(
name(),
WTF should make it easier to create threads that die automatically after inactivity https://bugs.webkit.org/show_bug.cgi?id=163576 Reviewed by Andreas Kling. Source/JavaScriptCore: Added a sleepSeconds() function, which made it easier for me to test this change. The WTF changes in this patch change how the JSC GC manages threads: the GC threads will now shut down automatically after 1 second of inactivity. Maybe this will save some memory. * jsc.cpp: (GlobalObject::finishCreation): (functionSleepSeconds): Source/WTF: For a long time now, I've been adding threads to WTF/JSC and each time I do this, I feel guilty because those threads don't shut down when they are inactive. For example, in bug 163562, I need to add a new GC thread. There will be one of them per VM. This means that a JSC API client that starts a lot of VMs will have a lot of threads. I don't think that's good. A common pattern for all of these threads is that they have some well-defined trigger that causes them to run. This trigger has a lock, a condition variable, some logic that determines if there is work to do, and then of course the logic for the thread's actual work. The thread bodies usually look like this: void Thingy::runThread() { for (;;) { Work work; { LockHolder locker(m_lock); while (!hasWork()) m_cond.wait(m_lock); work = takeWork(); } doWork(work); } } If you look at ParallelHelperPool (the GC's threads) and DFG::Worklist (some of the JIT's threads), you will see this pattern. This change adds a new kind of thread, called AutomaticThread, that lets you write threads to this pattern while getting automatic thread shutdown for free: instead of just waiting on a condition variable, AutomaticThread will have a timeout that causes the thread to die. The condition variable associated with AutomaticThread, called AutomaticThreadCondition, is smart enough to restart any threads that have decided to stop due to inactivity. The inactivity threshold is current just 1 second. In this patch I only adopt AutomaticThread for ParallelHelperPool. I plan to adopt it in more places soon. * WTF.xcodeproj/project.pbxproj: * wtf/AutomaticThread.cpp: Added. (WTF::AutomaticThreadCondition::create): (WTF::AutomaticThreadCondition::AutomaticThreadCondition): (WTF::AutomaticThreadCondition::~AutomaticThreadCondition): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Added. * wtf/CMakeLists.txt: * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::ParallelHelperPool): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::helperThreadBody): Deleted. (WTF::ParallelHelperPool::waitForClientWithTask): Deleted. * wtf/ParallelHelperPool.h: Canonical link: https://commits.webkit.org/181393@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207480 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-18 20:17:10 +00:00
[=] () {
if (verbose)
The GC should be in a thread https://bugs.webkit.org/show_bug.cgi?id=163562 Reviewed by Geoffrey Garen and Andreas Kling. Source/JavaScriptCore: In a concurrent GC, the work of collecting happens on a separate thread. This patch implements this, and schedules the thread the way that a concurrent GC thread would be scheduled. But, the GC isn't actually concurrent yet because it calls stopTheWorld() before doing anything and calls resumeTheWorld() after it's done with everything. The next step will be to make it really concurrent by basically calling stopTheWorld()/resumeTheWorld() around bounded snippets of work while making most of the work happen with the world running. Our GC will probably always have stop-the-world phases because the semantics of JSC weak references call for it. This implements concurrent GC scheduling. This means that there is no longer a Heap::collect() API. Instead, you can call collectAsync() which makes sure that a GC is scheduled (it will do nothing if one is scheduled or ongoing) or you can call collectSync() to schedule a GC and wait for it to happen. I made our debugging stuff call collectSync(). It should be a goal to never call collectSync() except for debugging or benchmark harness hacks. The collector thread is an AutomaticThread, so it won't linger when not in use. It works on a ticket-based system, like you would see at the DMV. A ticket is a 64-bit integer. There are two ticket counters: last granted and last served. When you request a collection, last granted is incremented and its new value given to you. When a collection completes, last served is incremented. collectSync() waits until last served catches up to what last granted had been at the time you requested a GC. This means that if you request a sync GC in the middle of an async GC, you will wait for that async GC to finish and then you will request and wait for your sync GC. The synchronization between the collector thread and the main threads is complex. The collector thread needs to be able to ask the main thread to stop. It needs to be able to do some post-GC clean-up, like the synchronous CodeBlock and LargeAllocation sweeps, on the main thread. The collector needs to be able to ask the main thread to execute a cross-modifying code fence before running any JIT code, since the GC might aid the JIT worklist and run JIT finalization. It's possible for the GC to want the main thread to run something at the same time that the main thread wants to wait for the GC. The main thread needs to be able to run non-JSC stuff without causing the GC to completely stall. The main thread needs to be able to query its own state (is there a request to stop?) and change it (running JSC versus not) quickly, since this may happen on hot paths. This kind of intertwined system of requests, notifications, and state changes requires a combination of lock-free algorithms and waiting. So, this is all implemented using a Atomic<unsigned> Heap::m_worldState, which has bits to represent things being requested by the collector and the heap access state of the mutator. I am borrowing a lot of terms that I've seen in other VMs that I've worked on. Here's what they mean: - Stop the world: make sure that either the mutator is not running, or that it's not running code that could mess with the heap. - Heap access: the mutator is said to have heap access if it could mess with the heap. If you stop the world and the mutator doesn't have heap access, all you're doing is making sure that it will block when it tries to acquire heap access. This means that our GC is already fully concurrent in cases where the GC is requested while the mutator has no heap access. This probably won't happen, but if it did then it should just work. Usually, stopping the world means that we state our shouldStop request with m_worldState, and a future call to Heap::stopIfNecessary() will go to slow path and stop. The act of stopping or waiting to acquire heap access is managed by using ParkingLot API directly on m_worldState. This works out great because it would be very awkward to get the same functionality using locks and condition variables, since we want stopIfNecessary/acquireAccess/requestAccess fast paths that are single atomic instructions (load/CAS/CAS, respectively). The mutator will call these things frequently. Currently we have Heap::stopIfNecessary() polling on every allocator slow path, but we may want to make it even more frequent than that. Currently only JSC API clients benefit from the heap access optimization. The DOM forces us to assume that heap access is permanently on, since DOM manipulation doesn't always hold the JSLock. We could still allow the GC to proceed when the runloop is idle by having the GC put a task on the runloop that just calls stopIfNecessary(). This is perf neutral. The only behavior change that clients ought to observe is that marking and the weak fixpoint happen on a separate thread. Marking was already parallel so it already handled multiple threads, but now it _never_ runs on the main thread. The weak fixpoint needed some help to be able to run on another thread - mostly because there was some code in IndexedDB that was using thread specifics in the weak fixpoint. * API/JSBase.cpp: (JSSynchronousEdenCollectForDebugging): * API/JSManagedValue.mm: (-[JSManagedValue initWithValue:]): * heap/EdenGCActivityCallback.cpp: (JSC::EdenGCActivityCallback::doCollection): * heap/FullGCActivityCallback.cpp: (JSC::FullGCActivityCallback::doCollection): * heap/Heap.cpp: (JSC::Heap::Thread::Thread): (JSC::Heap::Heap): (JSC::Heap::lastChanceToFinalize): (JSC::Heap::markRoots): (JSC::Heap::gatherStackRoots): (JSC::Heap::deleteUnmarkedCompiledCode): (JSC::Heap::collectAllGarbage): (JSC::Heap::collectAsync): (JSC::Heap::collectSync): (JSC::Heap::shouldCollectInThread): (JSC::Heap::collectInThread): (JSC::Heap::stopTheWorld): (JSC::Heap::resumeTheWorld): (JSC::Heap::stopIfNecessarySlow): (JSC::Heap::acquireAccessSlow): (JSC::Heap::releaseAccessSlow): (JSC::Heap::handleDidJIT): (JSC::Heap::handleNeedFinalize): (JSC::Heap::setDidJIT): (JSC::Heap::setNeedFinalize): (JSC::Heap::waitWhileNeedFinalize): (JSC::Heap::finalize): (JSC::Heap::requestCollection): (JSC::Heap::waitForCollection): (JSC::Heap::didFinishCollection): (JSC::Heap::canCollect): (JSC::Heap::shouldCollectHeuristic): (JSC::Heap::shouldCollect): (JSC::Heap::collectIfNecessaryOrDefer): (JSC::Heap::collectAccordingToDeferGCProbability): (JSC::Heap::collect): Deleted. (JSC::Heap::collectWithoutAnySweep): Deleted. (JSC::Heap::collectImpl): Deleted. * heap/Heap.h: (JSC::Heap::ReleaseAccessScope::ReleaseAccessScope): (JSC::Heap::ReleaseAccessScope::~ReleaseAccessScope): * heap/HeapInlines.h: (JSC::Heap::acquireAccess): (JSC::Heap::releaseAccess): (JSC::Heap::stopIfNecessary): * heap/MachineStackMarker.cpp: (JSC::MachineThreads::gatherConservativeRoots): (JSC::MachineThreads::gatherFromCurrentThread): Deleted. * heap/MachineStackMarker.h: * jit/JITWorklist.cpp: (JSC::JITWorklist::completeAllForVM): * jit/JITWorklist.h: * jsc.cpp: (functionFullGC): (functionEdenGC): * runtime/InitializeThreading.cpp: (JSC::initializeThreading): * runtime/JSLock.cpp: (JSC::JSLock::didAcquireLock): (JSC::JSLock::unlock): (JSC::JSLock::willReleaseLock): * tools/JSDollarVMPrototype.cpp: (JSC::JSDollarVMPrototype::edenGC): Source/WebCore: No new tests because existing tests cover this. We now need to be more careful about using JSLock. This fixes some places that were not holding it. New assertions in the GC are more likely to catch this than before. * bindings/js/WorkerScriptController.cpp: (WebCore::WorkerScriptController::WorkerScriptController): Source/WTF: This fixes some bugs and adds a few features. * wtf/Atomics.h: The GC may do work on behalf of the JIT. If it does, the main thread needs to execute a cross-modifying code fence. This is cpuid on x86 and I believe it's isb on ARM. It would have been an isync on PPC and I think that isb is the ARM equivalent. (WTF::arm_isb): (WTF::crossModifyingCodeFence): (WTF::x86_ortop): (WTF::x86_cpuid): * wtf/AutomaticThread.cpp: I accidentally had AutomaticThreadCondition inherit from ThreadSafeRefCounted<AutomaticThread> [sic]. This never crashed before because all of our prior AutomaticThreadConditions were immortal. (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: * wtf/MainThread.cpp: Need to allow initializeGCThreads() to be called separately because it's now more than just a debugging thing. (WTF::initializeGCThreads): Canonical link: https://commits.webkit.org/182065@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208306 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-02 22:01:04 +00:00
dataLog(RawPointer(this), ": Running automatic thread!\n");
RefPtr<AutomaticThread> thread = preserveThisForThread;
thread->threadDidStart();
WTF should make it easier to create threads that die automatically after inactivity https://bugs.webkit.org/show_bug.cgi?id=163576 Reviewed by Andreas Kling. Source/JavaScriptCore: Added a sleepSeconds() function, which made it easier for me to test this change. The WTF changes in this patch change how the JSC GC manages threads: the GC threads will now shut down automatically after 1 second of inactivity. Maybe this will save some memory. * jsc.cpp: (GlobalObject::finishCreation): (functionSleepSeconds): Source/WTF: For a long time now, I've been adding threads to WTF/JSC and each time I do this, I feel guilty because those threads don't shut down when they are inactive. For example, in bug 163562, I need to add a new GC thread. There will be one of them per VM. This means that a JSC API client that starts a lot of VMs will have a lot of threads. I don't think that's good. A common pattern for all of these threads is that they have some well-defined trigger that causes them to run. This trigger has a lock, a condition variable, some logic that determines if there is work to do, and then of course the logic for the thread's actual work. The thread bodies usually look like this: void Thingy::runThread() { for (;;) { Work work; { LockHolder locker(m_lock); while (!hasWork()) m_cond.wait(m_lock); work = takeWork(); } doWork(work); } } If you look at ParallelHelperPool (the GC's threads) and DFG::Worklist (some of the JIT's threads), you will see this pattern. This change adds a new kind of thread, called AutomaticThread, that lets you write threads to this pattern while getting automatic thread shutdown for free: instead of just waiting on a condition variable, AutomaticThread will have a timeout that causes the thread to die. The condition variable associated with AutomaticThread, called AutomaticThreadCondition, is smart enough to restart any threads that have decided to stop due to inactivity. The inactivity threshold is current just 1 second. In this patch I only adopt AutomaticThread for ParallelHelperPool. I plan to adopt it in more places soon. * WTF.xcodeproj/project.pbxproj: * wtf/AutomaticThread.cpp: Added. (WTF::AutomaticThreadCondition::create): (WTF::AutomaticThreadCondition::AutomaticThreadCondition): (WTF::AutomaticThreadCondition::~AutomaticThreadCondition): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Added. * wtf/CMakeLists.txt: * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::ParallelHelperPool): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::helperThreadBody): Deleted. (WTF::ParallelHelperPool::waitForClientWithTask): Deleted. * wtf/ParallelHelperPool.h: Canonical link: https://commits.webkit.org/181393@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207480 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-18 20:17:10 +00:00
PerformanceTests: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * JetStream2/wasm/HashSet.cpp: * StitchMarker/wtf/Assertions.h: * StitchMarker/wtf/DateMath.cpp: (WTF::initializeDates): * StitchMarker/wtf/HashTable.h: * StitchMarker/wtf/Hasher.h: (WTF::StringHasher::addCharacters): * StitchMarker/wtf/NeverDestroyed.h: (WTF::LazyNeverDestroyed::construct): * StitchMarker/wtf/StackBounds.h: (WTF::StackBounds::checkConsistency const): * StitchMarker/wtf/ValueCheck.h: * StitchMarker/wtf/Vector.h: (WTF::minCapacity>::checkConsistency): * StitchMarker/wtf/text/AtomicStringImpl.cpp: * StitchMarker/wtf/text/AtomicStringImpl.h: * StitchMarker/wtf/text/StringCommon.h: (WTF::hasPrefixWithLettersIgnoringASCIICaseCommon): * StitchMarker/wtf/text/StringImpl.h: * StitchMarker/wtf/text/SymbolImpl.h: * StitchMarker/wtf/text/UniquedStringImpl.h: Source/JavaScriptCore: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * API/tests/testapi.c: * assembler/ARM64Assembler.h: (JSC::ARM64Assembler::replaceWithLoad): (JSC::ARM64Assembler::replaceWithAddressComputation): * assembler/AssemblerBuffer.h: (JSC::AssemblerBuffer::LocalWriter::LocalWriter): * assembler/LinkBuffer.cpp: (JSC::LinkBuffer::copyCompactAndLinkCode): * assembler/ProbeStack.cpp: (JSC::Probe::Stack::Stack): * assembler/ProbeStack.h: * b3/B3FoldPathConstants.cpp: * b3/B3LowerToAir.cpp: * b3/B3MemoryValue.cpp: (JSC::B3::MemoryValue::MemoryValue): * b3/B3Opcode.cpp: * b3/B3Type.h: * b3/B3TypeMap.h: * b3/B3Width.h: * b3/air/AirAllocateRegistersAndStackAndGenerateCode.cpp: (JSC::B3::Air::GenerateAndAllocateRegisters::prepareForGeneration): (JSC::B3::Air::GenerateAndAllocateRegisters::generate): * b3/air/AirAllocateRegistersAndStackAndGenerateCode.h: * b3/air/AirAllocateRegistersByGraphColoring.cpp: * b3/air/AirArg.cpp: * b3/air/AirArg.h: * b3/air/AirCode.h: * b3/air/AirEmitShuffle.cpp: (JSC::B3::Air::emitShuffle): * builtins/BuiltinExecutables.cpp: (JSC::BuiltinExecutables::createExecutable): * bytecode/AccessCase.cpp: * bytecode/AccessCase.h: * bytecode/CallVariant.cpp: (JSC::variantListWithVariant): * bytecode/CodeBlock.cpp: (JSC::CodeBlock::ensureCatchLivenessIsComputedForBytecodeIndex): * bytecode/CodeBlockHash.cpp: (JSC::CodeBlockHash::dump const): * bytecode/StructureStubInfo.cpp: * bytecode/StructureStubInfo.h: * bytecompiler/NodesCodegen.cpp: (JSC::FunctionCallResolveNode::emitBytecode): * bytecompiler/RegisterID.h: (JSC::RegisterID::RegisterID): (JSC::RegisterID::setIndex): * debugger/Debugger.cpp: (JSC::Debugger::removeBreakpoint): * debugger/DebuggerEvalEnabler.h: (JSC::DebuggerEvalEnabler::DebuggerEvalEnabler): (JSC::DebuggerEvalEnabler::~DebuggerEvalEnabler): * dfg/DFGAbstractInterpreterInlines.h: (JSC::DFG::AbstractInterpreter<AbstractStateType>::observeTransitions): * dfg/DFGAbstractValue.cpp: * dfg/DFGAbstractValue.h: (JSC::DFG::AbstractValue::merge): (JSC::DFG::AbstractValue::checkConsistency const): (JSC::DFG::AbstractValue::assertIsRegistered const): * dfg/DFGArithMode.h: (JSC::DFG::doesOverflow): * dfg/DFGBasicBlock.cpp: (JSC::DFG::BasicBlock::BasicBlock): * dfg/DFGBasicBlock.h: (JSC::DFG::BasicBlock::didLink): * dfg/DFGCFAPhase.cpp: (JSC::DFG::CFAPhase::performBlockCFA): * dfg/DFGCommon.h: (JSC::DFG::validationEnabled): * dfg/DFGCommonData.cpp: (JSC::DFG::CommonData::finalizeCatchEntrypoints): * dfg/DFGDesiredWatchpoints.h: * dfg/DFGDoesGC.cpp: (JSC::DFG::doesGC): * dfg/DFGEdge.h: (JSC::DFG::Edge::makeWord): * dfg/DFGFixupPhase.cpp: (JSC::DFG::FixupPhase::fixupNode): * dfg/DFGJITCode.cpp: (JSC::DFG::JITCode::finalizeOSREntrypoints): * dfg/DFGObjectAllocationSinkingPhase.cpp: * dfg/DFGSSAConversionPhase.cpp: (JSC::DFG::SSAConversionPhase::run): * dfg/DFGScoreBoard.h: (JSC::DFG::ScoreBoard::assertClear): * dfg/DFGSlowPathGenerator.h: (JSC::DFG::SlowPathGenerator::generate): * dfg/DFGSpeculativeJIT.cpp: (JSC::DFG::SpeculativeJIT::compileCurrentBlock): (JSC::DFG::SpeculativeJIT::emitBinarySwitchStringRecurse): (JSC::DFG::SpeculativeJIT::emitAllocateButterfly): (JSC::DFG::SpeculativeJIT::compileAllocateNewArrayWithSize): (JSC::DFG::SpeculativeJIT::compileMakeRope): * dfg/DFGSpeculativeJIT64.cpp: (JSC::DFG::SpeculativeJIT::fillSpeculateCell): * dfg/DFGStructureAbstractValue.cpp: * dfg/DFGStructureAbstractValue.h: (JSC::DFG::StructureAbstractValue::assertIsRegistered const): * dfg/DFGVarargsForwardingPhase.cpp: * dfg/DFGVirtualRegisterAllocationPhase.cpp: (JSC::DFG::VirtualRegisterAllocationPhase::run): * ftl/FTLLink.cpp: (JSC::FTL::link): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::callPreflight): (JSC::FTL::DFG::LowerDFGToB3::callCheck): (JSC::FTL::DFG::LowerDFGToB3::crash): * ftl/FTLOperations.cpp: (JSC::FTL::operationMaterializeObjectInOSR): * heap/BlockDirectory.cpp: (JSC::BlockDirectory::assertNoUnswept): * heap/GCSegmentedArray.h: (JSC::GCArraySegment::GCArraySegment): * heap/GCSegmentedArrayInlines.h: (JSC::GCSegmentedArray<T>::clear): (JSC::GCSegmentedArray<T>::expand): (JSC::GCSegmentedArray<T>::validatePrevious): * heap/HandleSet.cpp: * heap/HandleSet.h: * heap/Heap.cpp: (JSC::Heap::updateAllocationLimits): * heap/Heap.h: * heap/MarkedBlock.cpp: * heap/MarkedBlock.h: (JSC::MarkedBlock::assertValidCell const): (JSC::MarkedBlock::assertMarksNotStale): * heap/MarkedSpace.cpp: (JSC::MarkedSpace::beginMarking): (JSC::MarkedSpace::endMarking): (JSC::MarkedSpace::assertNoUnswept): * heap/PreciseAllocation.cpp: * heap/PreciseAllocation.h: (JSC::PreciseAllocation::assertValidCell const): * heap/SlotVisitor.cpp: (JSC::SlotVisitor::SlotVisitor): (JSC::SlotVisitor::appendJSCellOrAuxiliary): * heap/SlotVisitor.h: * inspector/InspectorProtocolTypes.h: (Inspector::Protocol::BindingTraits<JSON::ArrayOf<T>>::assertValueHasExpectedType): * inspector/scripts/codegen/generate_cpp_protocol_types_implementation.py: (CppProtocolTypesImplementationGenerator._generate_assertion_for_object_declaration): (CppProtocolTypesImplementationGenerator): (CppProtocolTypesImplementationGenerator._generate_assertion_for_enum): * inspector/scripts/tests/generic/expected/type-requiring-runtime-casts.json-result: * interpreter/FrameTracers.h: (JSC::JITOperationPrologueCallFrameTracer::JITOperationPrologueCallFrameTracer): * interpreter/Interpreter.cpp: (JSC::Interpreter::Interpreter): * interpreter/Interpreter.h: * jit/AssemblyHelpers.cpp: (JSC::AssemblyHelpers::emitStoreStructureWithTypeInfo): * jit/AssemblyHelpers.h: (JSC::AssemblyHelpers::prepareCallOperation): * jit/BinarySwitch.cpp: (JSC::BinarySwitch::BinarySwitch): * jit/CCallHelpers.h: (JSC::CCallHelpers::setupStubArgs): * jit/CallFrameShuffler.cpp: (JSC::CallFrameShuffler::emitDeltaCheck): (JSC::CallFrameShuffler::prepareAny): * jit/JIT.cpp: (JSC::JIT::assertStackPointerOffset): (JSC::JIT::compileWithoutLinking): * jit/JITOpcodes.cpp: (JSC::JIT::emitSlow_op_loop_hint): * jit/JITPropertyAccess.cpp: (JSC::JIT::emit_op_get_from_scope): * jit/JITPropertyAccess32_64.cpp: (JSC::JIT::emit_op_get_from_scope): * jit/Repatch.cpp: (JSC::linkPolymorphicCall): * jit/ThunkGenerators.cpp: (JSC::emitPointerValidation): * llint/LLIntData.cpp: (JSC::LLInt::Data::performAssertions): * llint/LLIntOfflineAsmConfig.h: * parser/Lexer.cpp: * parser/Lexer.h: (JSC::isSafeBuiltinIdentifier): (JSC::Lexer<T>::lexExpectIdentifier): * runtime/ArgList.h: (JSC::MarkedArgumentBuffer::setNeedsOverflowCheck): (JSC::MarkedArgumentBuffer::clearNeedsOverflowCheck): * runtime/Butterfly.h: (JSC::ContiguousData::ContiguousData): (JSC::ContiguousData::Data::Data): * runtime/HashMapImpl.h: (JSC::HashMapImpl::checkConsistency const): (JSC::HashMapImpl::assertBufferIsEmpty const): * runtime/JSCellInlines.h: (JSC::JSCell::methodTable const): * runtime/JSFunction.cpp: * runtime/JSFunction.h: (JSC::JSFunction::assertTypeInfoFlagInvariants): * runtime/JSGlobalObject.cpp: (JSC::JSGlobalObject::init): * runtime/JSGlobalObject.h: * runtime/JSObject.cpp: (JSC::JSObject::visitChildren): (JSC::JSFinalObject::visitChildren): * runtime/JSObjectInlines.h: (JSC::JSObject::validatePutOwnDataProperty): * runtime/JSSegmentedVariableObject.h: (JSC::JSSegmentedVariableObject::assertVariableIsInThisObject): * runtime/LiteralParser.cpp: (JSC::LiteralParser<CharType>::Lexer::lex): * runtime/LiteralParser.h: * runtime/Operations.h: (JSC::scribbleFreeCells): * runtime/OptionsList.h: * runtime/VM.cpp: (JSC::VM::computeCanUseJIT): * runtime/VM.h: (JSC::VM::canUseJIT): * runtime/VarOffset.h: (JSC::VarOffset::checkSanity const): * runtime/WeakMapImpl.h: (JSC::WeakMapImpl::checkConsistency const): (JSC::WeakMapImpl::assertBufferIsEmpty const): * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::validateInst): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::parseAndCompile): * wasm/WasmFunctionParser.h: (JSC::Wasm::FunctionParser::validationFail const): * wasm/WasmLLIntGenerator.cpp: (JSC::Wasm::LLIntGenerator::checkConsistency): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast): * wasm/WasmSectionParser.h: * wasm/WasmSections.h: * wasm/WasmSignatureInlines.h: (JSC::Wasm::SignatureInformation::get): * wasm/WasmWorklist.cpp: (JSC::Wasm::Worklist::enqueue): * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/WebAssemblyFunction.cpp: (JSC::WebAssemblyFunction::previousInstanceOffset const): Source/WebCore: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * Modules/fetch/FetchBodySource.cpp: (WebCore::FetchBodySource::close): * Modules/fetch/FetchBodySource.h: * Modules/webdatabase/DatabaseDetails.h: (WebCore::DatabaseDetails::DatabaseDetails): (WebCore::DatabaseDetails::operator=): * Modules/webdatabase/DatabaseTask.cpp: (WebCore::DatabaseTask::performTask): * Modules/webdatabase/DatabaseTask.h: * Modules/webdatabase/DatabaseThread.cpp: (WebCore::DatabaseThread::terminationRequested const): * Modules/webgpu/WHLSL/AST/WHLSLAddressSpace.h: (WebCore::WHLSL::AST::TypeAnnotation::TypeAnnotation): * Modules/webgpu/WHLSL/WHLSLHighZombieFinder.cpp: (WebCore::WHLSL::findHighZombies): * Modules/webgpu/WHLSL/WHLSLInferTypes.cpp: (WebCore::WHLSL::matches): * Modules/webgpu/WHLSL/WHLSLLiteralTypeChecker.cpp: (WebCore::WHLSL::checkLiteralTypes): * Modules/webgpu/WHLSL/WHLSLSynthesizeConstructors.cpp: (WebCore::WHLSL::FindAllTypes::appendNamedType): * bindings/js/JSCallbackData.h: * bindings/js/JSLazyEventListener.cpp: * bindings/js/JSLazyEventListener.h: * contentextensions/ContentExtensionCompiler.cpp: (WebCore::ContentExtensions::compileRuleList): * css/CSSCalculationValue.cpp: (WebCore::CSSCalcOperationNode::primitiveType const): * css/CSSComputedStyleDeclaration.cpp: (WebCore::ComputedStyleExtractor::valueForPropertyInStyle): * css/CSSPrimitiveValue.cpp: * css/CSSSelector.cpp: (WebCore::CSSSelector::selectorText const): * css/CSSStyleSheet.cpp: * dom/ActiveDOMObject.cpp: (WebCore::ActiveDOMObject::suspendIfNeeded): (WebCore::ActiveDOMObject::assertSuspendIfNeededWasCalled const): * dom/ActiveDOMObject.h: * dom/ContainerNode.cpp: * dom/ContainerNodeAlgorithms.cpp: * dom/ContainerNodeAlgorithms.h: * dom/CustomElementReactionQueue.cpp: * dom/CustomElementReactionQueue.h: (WebCore::CustomElementReactionDisallowedScope::CustomElementReactionDisallowedScope): (WebCore::CustomElementReactionDisallowedScope::~CustomElementReactionDisallowedScope): * dom/Document.cpp: (WebCore::Document::hitTest): * dom/Document.h: (WebCore::Document::decrementReferencingNodeCount): * dom/Element.cpp: (WebCore::Element::addShadowRoot): (WebCore::Element::getURLAttribute const): (WebCore::Element::getNonEmptyURLAttribute const): * dom/Element.h: * dom/ElementAndTextDescendantIterator.h: (WebCore::ElementAndTextDescendantIterator::ElementAndTextDescendantIterator): (WebCore::ElementAndTextDescendantIterator::dropAssertions): (WebCore::ElementAndTextDescendantIterator::popAncestorSiblingStack): (WebCore::ElementAndTextDescendantIterator::traverseNextSibling): (WebCore::ElementAndTextDescendantIterator::traversePreviousSibling): * dom/ElementDescendantIterator.h: (WebCore::ElementDescendantIterator::ElementDescendantIterator): (WebCore::ElementDescendantIterator::dropAssertions): (WebCore::ElementDescendantIterator::operator++): (WebCore::ElementDescendantIterator::operator--): (WebCore::ElementDescendantConstIterator::ElementDescendantConstIterator): (WebCore::ElementDescendantConstIterator::dropAssertions): (WebCore::ElementDescendantConstIterator::operator++): * dom/ElementIterator.h: (WebCore::ElementIterator<ElementType>::ElementIterator): (WebCore::ElementIterator<ElementType>::traverseNext): (WebCore::ElementIterator<ElementType>::traversePrevious): (WebCore::ElementIterator<ElementType>::traverseNextSibling): (WebCore::ElementIterator<ElementType>::traversePreviousSibling): (WebCore::ElementIterator<ElementType>::traverseNextSkippingChildren): (WebCore::ElementIterator<ElementType>::dropAssertions): (WebCore::ElementIterator<ElementType>::traverseAncestor): (WebCore::ElementConstIterator<ElementType>::ElementConstIterator): (WebCore::ElementConstIterator<ElementType>::traverseNext): (WebCore::ElementConstIterator<ElementType>::traversePrevious): (WebCore::ElementConstIterator<ElementType>::traverseNextSibling): (WebCore::ElementConstIterator<ElementType>::traversePreviousSibling): (WebCore::ElementConstIterator<ElementType>::traverseNextSkippingChildren): (WebCore::ElementConstIterator<ElementType>::traverseAncestor): (WebCore::ElementConstIterator<ElementType>::dropAssertions): * dom/EventContext.cpp: * dom/EventContext.h: * dom/EventListener.h: * dom/EventPath.cpp: * dom/EventSender.h: * dom/EventTarget.cpp: (WebCore::EventTarget::addEventListener): (WebCore::EventTarget::setAttributeEventListener): (WebCore::EventTarget::innerInvokeEventListeners): * dom/Node.cpp: (WebCore::Node::~Node): (WebCore::Node::moveNodeToNewDocument): (WebCore::Node::removedLastRef): * dom/Node.h: (WebCore::Node::deref const): * dom/ScriptDisallowedScope.h: (WebCore::ScriptDisallowedScope::InMainThread::isEventDispatchAllowedInSubtree): * dom/ScriptExecutionContext.cpp: (WebCore::ScriptExecutionContext::~ScriptExecutionContext): * dom/ScriptExecutionContext.h: * dom/SelectorQuery.cpp: (WebCore::SelectorDataList::execute const): * dom/SlotAssignment.cpp: (WebCore::SlotAssignment::addSlotElementByName): (WebCore::SlotAssignment::removeSlotElementByName): (WebCore::SlotAssignment::resolveSlotsAfterSlotMutation): (WebCore::SlotAssignment::findFirstSlotElement): * dom/SlotAssignment.h: * dom/TreeScopeOrderedMap.cpp: (WebCore::TreeScopeOrderedMap::add): (WebCore::TreeScopeOrderedMap::get const): * dom/TreeScopeOrderedMap.h: * fileapi/Blob.cpp: * fileapi/Blob.h: * history/BackForwardCache.cpp: (WebCore::BackForwardCache::removeAllItemsForPage): * history/BackForwardCache.h: * html/CanvasBase.cpp: (WebCore::CanvasBase::notifyObserversCanvasDestroyed): * html/CanvasBase.h: * html/HTMLCollection.h: (WebCore::CollectionNamedElementCache::didPopulate): * html/HTMLSelectElement.cpp: (WebCore:: const): * html/HTMLTableRowsCollection.cpp: (WebCore::assertRowIsInTable): * html/HTMLTextFormControlElement.cpp: (WebCore::HTMLTextFormControlElement::indexForPosition const): * html/canvas/CanvasRenderingContext2DBase.cpp: (WebCore::CanvasRenderingContext2DBase::~CanvasRenderingContext2DBase): * html/parser/HTMLParserScheduler.cpp: (WebCore::HTMLParserScheduler::HTMLParserScheduler): (WebCore::HTMLParserScheduler::suspend): (WebCore::HTMLParserScheduler::resume): * html/parser/HTMLParserScheduler.h: * html/parser/HTMLToken.h: (WebCore::HTMLToken::beginStartTag): (WebCore::HTMLToken::beginEndTag): (WebCore::HTMLToken::endAttribute): * html/parser/HTMLTreeBuilder.cpp: (WebCore::HTMLTreeBuilder::HTMLTreeBuilder): (WebCore::HTMLTreeBuilder::constructTree): * html/parser/HTMLTreeBuilder.h: (WebCore::HTMLTreeBuilder::~HTMLTreeBuilder): * layout/FormattingContext.cpp: (WebCore::Layout::FormattingContext::geometryForBox const): * layout/blockformatting/BlockFormattingContext.cpp: (WebCore::Layout::BlockFormattingContext::computeEstimatedVerticalPosition): * layout/blockformatting/BlockFormattingContext.h: * layout/displaytree/DisplayBox.cpp: (WebCore::Display::Box::Box): * layout/displaytree/DisplayBox.h: (WebCore::Display::Box::setTopLeft): (WebCore::Display::Box::setTop): (WebCore::Display::Box::setLeft): (WebCore::Display::Box::setContentBoxHeight): (WebCore::Display::Box::setContentBoxWidth): (WebCore::Display::Box::setHorizontalMargin): (WebCore::Display::Box::setVerticalMargin): (WebCore::Display::Box::setHorizontalComputedMargin): (WebCore::Display::Box::setBorder): (WebCore::Display::Box::setPadding): * layout/displaytree/DisplayInlineRect.h: (WebCore::Display::InlineRect::InlineRect): (WebCore::Display::InlineRect::setTopLeft): (WebCore::Display::InlineRect::setTop): (WebCore::Display::InlineRect::setBottom): (WebCore::Display::InlineRect::setLeft): (WebCore::Display::InlineRect::setWidth): (WebCore::Display::InlineRect::setHeight): * layout/displaytree/DisplayLineBox.h: (WebCore::Display::LineBox::LineBox): (WebCore::Display::LineBox::setBaselineOffsetIfGreater): (WebCore::Display::LineBox::resetBaseline): (WebCore::Display::LineBox::Baseline::Baseline): (WebCore::Display::LineBox::Baseline::setAscent): (WebCore::Display::LineBox::Baseline::setDescent): (WebCore::Display::LineBox::Baseline::reset): * layout/displaytree/DisplayRect.h: (WebCore::Display::Rect::Rect): (WebCore::Display::Rect::setTopLeft): (WebCore::Display::Rect::setTop): (WebCore::Display::Rect::setLeft): (WebCore::Display::Rect::setWidth): (WebCore::Display::Rect::setHeight): (WebCore::Display::Rect::setSize): (WebCore::Display::Rect::clone const): * layout/floats/FloatingContext.cpp: * layout/inlineformatting/InlineLineBuilder.cpp: (WebCore::Layout::LineBuilder::CollapsibleContent::collapse): * layout/tableformatting/TableGrid.cpp: (WebCore::Layout::TableGrid::Column::setWidthConstraints): (WebCore::Layout::TableGrid::Column::setLogicalWidth): (WebCore::Layout::TableGrid::Column::setLogicalLeft): * layout/tableformatting/TableGrid.h: * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::continueAfterContentPolicy): (WebCore::DocumentLoader::attachToFrame): (WebCore::DocumentLoader::detachFromFrame): (WebCore::DocumentLoader::addSubresourceLoader): * loader/DocumentLoader.h: * loader/ImageLoader.cpp: * loader/cache/CachedResource.h: * loader/cache/MemoryCache.cpp: (WebCore::MemoryCache::lruListFor): (WebCore::MemoryCache::removeFromLRUList): * page/FrameView.cpp: (WebCore::FrameView::updateLayoutAndStyleIfNeededRecursive): * page/FrameViewLayoutContext.cpp: * page/FrameViewLayoutContext.h: * page/Page.cpp: * page/Page.h: * page/ViewportConfiguration.cpp: * page/ViewportConfiguration.h: * page/mac/EventHandlerMac.mm: (WebCore::CurrentEventScope::CurrentEventScope): * platform/DateComponents.cpp: (WebCore::DateComponents::toStringForTime const): * platform/ScrollableArea.cpp: * platform/SharedBuffer.cpp: (WebCore::SharedBuffer::combineIntoOneSegment const): * platform/SharedBuffer.h: * platform/Supplementable.h: * platform/Timer.cpp: (WebCore::TimerBase::checkHeapIndex const): (WebCore::TimerBase::updateHeapIfNeeded): * platform/graphics/BitmapImage.cpp: * platform/graphics/BitmapImage.h: * platform/graphics/Image.h: * platform/graphics/ShadowBlur.cpp: (WebCore::ScratchBuffer::ScratchBuffer): (WebCore::ScratchBuffer::getScratchBuffer): (WebCore::ScratchBuffer::scheduleScratchBufferPurge): * platform/graphics/ca/win/CACFLayerTreeHost.cpp: (WebCore::CACFLayerTreeHost::setWindow): * platform/graphics/ca/win/CACFLayerTreeHost.h: * platform/graphics/cg/ImageBufferDataCG.cpp: (WebCore::ImageBufferData::putData): * platform/graphics/cocoa/FontCacheCoreText.cpp: * platform/graphics/gstreamer/GstAllocatorFastMalloc.cpp: (gstAllocatorFastMallocFree): * platform/graphics/nicosia/cairo/NicosiaPaintingContextCairo.cpp: (Nicosia::PaintingContextCairo::ForPainting::ForPainting): * platform/graphics/nicosia/texmap/NicosiaBackingStoreTextureMapperImpl.cpp: (Nicosia::BackingStoreTextureMapperImpl::createTile): * platform/graphics/nicosia/texmap/NicosiaContentLayerTextureMapperImpl.cpp: (Nicosia::ContentLayerTextureMapperImpl::~ContentLayerTextureMapperImpl): * platform/graphics/win/GradientDirect2D.cpp: (WebCore::Gradient::fill): * platform/graphics/win/ImageBufferDataDirect2D.cpp: (WebCore::ImageBufferData::putData): * platform/graphics/win/PathDirect2D.cpp: (WebCore::Path::appendGeometry): (WebCore::Path::Path): (WebCore::Path::operator=): (WebCore::Path::strokeContains const): (WebCore::Path::transform): * platform/graphics/win/PlatformContextDirect2D.cpp: (WebCore::PlatformContextDirect2D::setTags): * platform/mediastream/MediaStreamTrackPrivate.h: * platform/mediastream/RealtimeOutgoingAudioSource.cpp: (WebCore::RealtimeOutgoingAudioSource::~RealtimeOutgoingAudioSource): * platform/mediastream/RealtimeOutgoingVideoSource.cpp: (WebCore::RealtimeOutgoingVideoSource::~RealtimeOutgoingVideoSource): * platform/network/HTTPParsers.cpp: (WebCore::isCrossOriginSafeHeader): * platform/sql/SQLiteDatabase.cpp: * platform/sql/SQLiteDatabase.h: * platform/sql/SQLiteStatement.cpp: (WebCore::SQLiteStatement::SQLiteStatement): (WebCore::SQLiteStatement::prepare): (WebCore::SQLiteStatement::finalize): * platform/sql/SQLiteStatement.h: * platform/win/COMPtr.h: * rendering/ComplexLineLayout.cpp: (WebCore::ComplexLineLayout::removeInlineBox const): * rendering/FloatingObjects.cpp: (WebCore::FloatingObject::FloatingObject): (WebCore::FloatingObjects::addPlacedObject): (WebCore::FloatingObjects::removePlacedObject): * rendering/FloatingObjects.h: * rendering/GridTrackSizingAlgorithm.cpp: * rendering/GridTrackSizingAlgorithm.h: * rendering/LayoutDisallowedScope.cpp: * rendering/LayoutDisallowedScope.h: * rendering/RenderBlock.cpp: * rendering/RenderBlock.h: * rendering/RenderBlockFlow.cpp: (WebCore::RenderBlockFlow::layoutBlockChild): (WebCore::RenderBlockFlow::removeFloatingObject): (WebCore::RenderBlockFlow::ensureLineBoxes): * rendering/RenderBoxModelObject.cpp: * rendering/RenderDeprecatedFlexibleBox.cpp: (WebCore::RenderDeprecatedFlexibleBox::layoutBlock): * rendering/RenderElement.cpp: * rendering/RenderGeometryMap.cpp: (WebCore::RenderGeometryMap::mapToContainer const): * rendering/RenderGrid.cpp: (WebCore::RenderGrid::placeItemsOnGrid const): (WebCore::RenderGrid::baselinePosition const): * rendering/RenderInline.cpp: (WebCore::RenderInline::willBeDestroyed): * rendering/RenderLayer.cpp: (WebCore::ClipRectsCache::ClipRectsCache): (WebCore::RenderLayer::RenderLayer): (WebCore::RenderLayer::paintList): (WebCore::RenderLayer::hitTestLayer): (WebCore::RenderLayer::updateClipRects): (WebCore::RenderLayer::calculateClipRects const): * rendering/RenderLayer.h: * rendering/RenderLayerBacking.cpp: (WebCore::traverseVisibleNonCompositedDescendantLayers): * rendering/RenderLayerCompositor.cpp: (WebCore::RenderLayerCompositor::computeCompositingRequirements): (WebCore::RenderLayerCompositor::traverseUnchangedSubtree): (WebCore::RenderLayerCompositor::updateBackingAndHierarchy): (WebCore::RenderLayerCompositor::addDescendantsToOverlapMapRecursive const): (WebCore::RenderLayerCompositor::recursiveRepaintLayer): (WebCore::RenderLayerCompositor::layerHas3DContent const): * rendering/RenderLayoutState.cpp: (WebCore::RenderLayoutState::RenderLayoutState): (WebCore::RenderLayoutState::computeOffsets): (WebCore::RenderLayoutState::addLayoutDelta): * rendering/RenderLayoutState.h: (WebCore::RenderLayoutState::RenderLayoutState): * rendering/RenderObject.cpp: (WebCore::RenderObject::RenderObject): (WebCore::RenderObject::~RenderObject): (WebCore::RenderObject::clearNeedsLayout): * rendering/RenderObject.h: * rendering/RenderQuote.cpp: (WebCore::quotesForLanguage): * rendering/RenderTableCell.h: * rendering/RenderTableSection.cpp: (WebCore::RenderTableSection::computeOverflowFromCells): * rendering/RenderTextLineBoxes.cpp: (WebCore::RenderTextLineBoxes::checkConsistency const): * rendering/RenderTextLineBoxes.h: * rendering/line/BreakingContext.h: (WebCore::tryHyphenating): * rendering/style/GridArea.h: (WebCore::GridSpan::GridSpan): * rendering/style/RenderStyle.cpp: (WebCore::RenderStyle::~RenderStyle): * rendering/style/RenderStyle.h: * rendering/updating/RenderTreeBuilderRuby.cpp: (WebCore::RenderTreeBuilder::Ruby::detach): * rendering/updating/RenderTreePosition.cpp: (WebCore::RenderTreePosition::computeNextSibling): * rendering/updating/RenderTreePosition.h: * svg/SVGToOTFFontConversion.cpp: (WebCore::SVGToOTFFontConverter::Placeholder::Placeholder): (WebCore::SVGToOTFFontConverter::Placeholder::populate): (WebCore::SVGToOTFFontConverter::appendCFFTable): (WebCore::SVGToOTFFontConverter::firstGlyph const): (WebCore::SVGToOTFFontConverter::appendKERNTable): * svg/SVGTransformDistance.cpp: (WebCore::SVGTransformDistance::SVGTransformDistance): (WebCore::SVGTransformDistance::scaledDistance const): (WebCore::SVGTransformDistance::addSVGTransforms): (WebCore::SVGTransformDistance::addToSVGTransform const): (WebCore::SVGTransformDistance::distance const): * svg/graphics/SVGImage.cpp: (WebCore::SVGImage::nativeImage): * testing/InternalSettings.cpp: * workers/service/ServiceWorkerJob.h: * worklets/PaintWorkletGlobalScope.h: (WebCore::PaintWorkletGlobalScope::~PaintWorkletGlobalScope): * xml/XPathStep.cpp: Source/WebKit: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * NetworkProcess/NetworkSession.cpp: (WebKit::NetworkSession::invalidateAndCancel): * NetworkProcess/NetworkSession.h: * NetworkProcess/cache/NetworkCacheStorage.cpp: (WebKit::NetworkCache::Storage::setCapacity): * NetworkProcess/cocoa/NetworkSessionCocoa.mm: (toNSURLSessionResponseDisposition): (WebKit::NetworkSessionCocoa::NetworkSessionCocoa): * Platform/IPC/Connection.cpp: (IPC::Connection::waitForMessage): * Platform/IPC/MessageReceiver.h: (IPC::MessageReceiver::willBeAddedToMessageReceiverMap): (IPC::MessageReceiver::willBeRemovedFromMessageReceiverMap): * Platform/IPC/cocoa/ConnectionCocoa.mm: (IPC::readFromMachPort): * Platform/mac/MachUtilities.cpp: (setMachExceptionPort): * Shared/API/APIClient.h: (API::Client::Client): * Shared/API/Cocoa/WKRemoteObjectCoder.mm: * Shared/Cocoa/ArgumentCodersCocoa.h: * Shared/SharedStringHashTableReadOnly.cpp: * UIProcess/BackingStore.cpp: (WebKit::BackingStore::incorporateUpdate): * UIProcess/GenericCallback.h: * UIProcess/Launcher/mac/ProcessLauncherMac.mm: (WebKit::ProcessLauncher::launchProcess): * UIProcess/PageLoadState.h: (WebKit::PageLoadState::Transaction::Token::Token): * UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::~WebPageProxy): * WebProcess/Network/WebResourceLoader.cpp: (WebKit::WebResourceLoader::didReceiveResponse): * WebProcess/Network/WebResourceLoader.h: * WebProcess/Plugins/Netscape/NetscapePluginStream.cpp: (WebKit::NetscapePluginStream::NetscapePluginStream): (WebKit::NetscapePluginStream::notifyAndDestroyStream): * WebProcess/Plugins/Netscape/NetscapePluginStream.h: * WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::runModal): * WebProcess/WebProcess.cpp: (WebKit::checkDocumentsCaptureStateConsistency): * WebProcess/cocoa/WebProcessCocoa.mm: (WebKit::WebProcess::updateProcessName): Source/WebKitLegacy: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * Storage/StorageAreaImpl.cpp: (WebKit::StorageAreaImpl::StorageAreaImpl): (WebKit::StorageAreaImpl::close): * Storage/StorageAreaImpl.h: Source/WebKitLegacy/mac: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * History/WebHistory.mm: (-[WebHistoryPrivate removeItemForURLString:]): * WebView/WebFrame.mm: Source/WebKitLegacy/win: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. * WebKitQuartzCoreAdditions/CAD3DRenderer.cpp: (WKQCA::CAD3DRenderer::swapChain): (WKQCA::CAD3DRenderer::initialize): * WebKitQuartzCoreAdditions/CAD3DRenderer.h: * WebView.cpp: (WebView::Release): * WebView.h: Source/WTF: Convert ASSERT_DISABLED to ASSERT_ENABLED, and fix some tests of NDEBUG that should actually test for ASSERT_ENABLED. https://bugs.webkit.org/show_bug.cgi?id=205776 Reviewed by Saam Barati. This patch did the following changes: 1. Replaced ASSERT_DISABLED with ASSERT_ENABLED. This change does away with the need for the double negative !ASSERT_DISABLED test that is commonly used all over the code, thereby improving code readability. In Assertions.h, there is also BACKTRACE_DISABLED, ASSERT_MSG_DISABLED, ASSERT_ARG_DISABLED, FATAL_DISABLED, ERROR_DISABLED, LOG_DISABLED, and RELEASE_LOG_DISABLED. We should replace those with ..._ENABLED equivalents as well. We'll do that in another patch. For now, they are left as is to minimize the size of this patch. See https://bugs.webkit.org/show_bug.cgi?id=205780. 2. Fixed some code was guarded with "#ifndef NDEBUG" that should actually be guarded by "#if ASSERT_ENABLED" instead. 3. In cases where the change is minimal, we move some code around so that we can test for "#if ASSERT_ENABLED" instead of "#if !ASSERT_ENABLED". * wtf/Assertions.h: * wtf/AutomaticThread.cpp: (WTF::AutomaticThread::start): * wtf/BitVector.h: * wtf/BlockObjCExceptions.mm: (ReportBlockedObjCException): * wtf/BloomFilter.h: * wtf/CallbackAggregator.h: (WTF::CallbackAggregator::CallbackAggregator): * wtf/CheckedArithmetic.h: (WTF::observesOverflow<AssertNoOverflow>): * wtf/CheckedBoolean.h: (CheckedBoolean::CheckedBoolean): (CheckedBoolean::operator bool): * wtf/CompletionHandler.h: (WTF::CompletionHandler<Out): * wtf/DateMath.cpp: (WTF::initializeDates): * wtf/Gigacage.cpp: (Gigacage::tryAllocateZeroedVirtualPages): * wtf/HashTable.h: (WTF::KeyTraits>::checkKey): (WTF::KeyTraits>::checkTableConsistencyExceptSize const): * wtf/LoggerHelper.h: * wtf/NaturalLoops.h: (WTF::NaturalLoops::headerOf const): * wtf/NeverDestroyed.h: (WTF::LazyNeverDestroyed::construct): * wtf/OptionSet.h: (WTF::OptionSet::OptionSet): * wtf/Platform.h: * wtf/PtrTag.h: * wtf/RefCounted.h: (WTF::RefCountedBase::disableThreadingChecks): (WTF::RefCountedBase::enableThreadingChecksGlobally): (WTF::RefCountedBase::RefCountedBase): (WTF::RefCountedBase::applyRefDerefThreadingCheck const): * wtf/SingleRootGraph.h: (WTF::SingleRootGraph::assertIsConsistent const): * wtf/SizeLimits.cpp: * wtf/StackBounds.h: (WTF::StackBounds::checkConsistency const): * wtf/URLParser.cpp: (WTF::URLParser::URLParser): (WTF::URLParser::domainToASCII): * wtf/ValueCheck.h: * wtf/Vector.h: (WTF::Malloc>::checkConsistency): * wtf/WeakHashSet.h: * wtf/WeakPtr.h: (WTF::WeakPtrImpl::WeakPtrImpl): (WTF::WeakPtrFactory::WeakPtrFactory): * wtf/text/AtomStringImpl.cpp: * wtf/text/AtomStringImpl.h: * wtf/text/StringBuilder.cpp: (WTF::StringBuilder::reifyString const): * wtf/text/StringBuilder.h: * wtf/text/StringCommon.h: (WTF::hasPrefixWithLettersIgnoringASCIICaseCommon): * wtf/text/StringHasher.h: (WTF::StringHasher::addCharacters): * wtf/text/StringImpl.h: * wtf/text/SymbolImpl.h: * wtf/text/UniquedStringImpl.h: Tools: Remove WebsiteDataStore::setServiceWorkerRegistrationDirectory https://bugs.webkit.org/show_bug.cgi?id=205754 Patch by Alex Christensen <achristensen@webkit.org> on 2020-01-06 Reviewed by Youenn Fablet. * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm: * WebKitTestRunner/TestController.cpp: (WTR::TestController::websiteDataStore): (WTR::TestController::platformAdjustContext): * WebKitTestRunner/cocoa/TestControllerCocoa.mm: (WTR::initializeWebViewConfiguration): Canonical link: https://commits.webkit.org/218957@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@254087 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-01-06 22:24:50 +00:00
if (ASSERT_ENABLED) {
Replace LockHolder with Locker in local variables https://bugs.webkit.org/show_bug.cgi?id=226133 Reviewed by Darin Adler. Replace LockHolder with Locker in local variables. It is shorter and it allows switching the lock type more easily since the compiler with deduce the lock type T for Locker<T>. Source/JavaScriptCore: * API/JSCallbackObject.h: (JSC::JSCallbackObjectData::JSPrivatePropertyMap::setPrivateProperty): (JSC::JSCallbackObjectData::JSPrivatePropertyMap::deletePrivateProperty): (JSC::JSCallbackObjectData::JSPrivatePropertyMap::visitChildren): * API/JSValue.mm: (handerForStructTag): * API/tests/testapi.cpp: (testCAPIViaCpp): * assembler/testmasm.cpp: (JSC::run): * b3/air/testair.cpp: * b3/testb3_1.cpp: (run): * bytecode/DirectEvalCodeCache.cpp: (JSC::DirectEvalCodeCache::setSlow): (JSC::DirectEvalCodeCache::clear): (JSC::DirectEvalCodeCache::visitAggregateImpl): * bytecode/SuperSampler.cpp: (JSC::initializeSuperSampler): (JSC::resetSuperSamplerState): (JSC::printSuperSamplerState): (JSC::enableSuperSampler): (JSC::disableSuperSampler): * dfg/DFGCommonData.cpp: (JSC::DFG::CommonData::invalidate): (JSC::DFG::CommonData::~CommonData): (JSC::DFG::CommonData::installVMTrapBreakpoints): (JSC::DFG::codeBlockForVMTrapPC): * dfg/DFGPlan.cpp: (JSC::DFG::Plan::cleanMustHandleValuesIfNecessary): * dfg/DFGWorklist.cpp: (JSC::DFG::Worklist::~Worklist): (JSC::DFG::Worklist::finishCreation): (JSC::DFG::Worklist::isActiveForVM const): (JSC::DFG::Worklist::enqueue): (JSC::DFG::Worklist::compilationState): (JSC::DFG::Worklist::waitUntilAllPlansForVMAreReady): (JSC::DFG::Worklist::removeAllReadyPlansForVM): (JSC::DFG::Worklist::completeAllReadyPlansForVM): (JSC::DFG::Worklist::visitWeakReferences): (JSC::DFG::Worklist::removeDeadPlans): (JSC::DFG::Worklist::removeNonCompilingPlansForVM): (JSC::DFG::Worklist::queueLength): (JSC::DFG::Worklist::dump const): (JSC::DFG::Worklist::setNumberOfThreads): * dfg/DFGWorklistInlines.h: (JSC::DFG::Worklist::iterateCodeBlocksForGC): * disassembler/Disassembler.cpp: * heap/BlockDirectory.cpp: (JSC::BlockDirectory::addBlock): * heap/CodeBlockSetInlines.h: (JSC::CodeBlockSet::iterateCurrentlyExecuting): * heap/ConservativeRoots.cpp: (JSC::ConservativeRoots::add): * heap/Heap.cpp: (JSC::Heap::Heap): (JSC::Heap::lastChanceToFinalize): (JSC::Heap::collectAsync): (JSC::Heap::runBeginPhase): (JSC::Heap::waitForCollector): (JSC::Heap::requestCollection): (JSC::Heap::notifyIsSafeToCollect): * heap/SlotVisitor.cpp: (JSC::SlotVisitor::didReachTermination): * inspector/agents/InspectorScriptProfilerAgent.cpp: (Inspector::InspectorScriptProfilerAgent::startTracking): (Inspector::InspectorScriptProfilerAgent::trackingComplete): (Inspector::InspectorScriptProfilerAgent::stopSamplingWhenDisconnecting): * inspector/remote/RemoteConnectionToTarget.cpp: (Inspector::RemoteConnectionToTarget::setup): (Inspector::RemoteConnectionToTarget::sendMessageToTarget): (Inspector::RemoteConnectionToTarget::close): (Inspector::RemoteConnectionToTarget::targetClosed): * inspector/remote/RemoteInspector.cpp: (Inspector::RemoteInspector::registerTarget): (Inspector::RemoteInspector::unregisterTarget): (Inspector::RemoteInspector::updateTarget): (Inspector::RemoteInspector::updateClientCapabilities): (Inspector::RemoteInspector::setClient): (Inspector::RemoteInspector::setupFailed): (Inspector::RemoteInspector::setupCompleted): (Inspector::RemoteInspector::stop): * inspector/remote/cocoa/RemoteConnectionToTargetCocoa.mm: (Inspector::RemoteTargetHandleRunSourceGlobal): (Inspector::RemoteTargetQueueTaskOnGlobalQueue): (Inspector::RemoteTargetHandleRunSourceWithInfo): (Inspector::RemoteConnectionToTarget::setup): (Inspector::RemoteConnectionToTarget::targetClosed): (Inspector::RemoteConnectionToTarget::close): (Inspector::RemoteConnectionToTarget::sendMessageToTarget): (Inspector::RemoteConnectionToTarget::queueTaskOnPrivateRunLoop): * inspector/remote/cocoa/RemoteInspectorCocoa.mm: (Inspector::RemoteInspector::updateAutomaticInspectionCandidate): (Inspector::RemoteInspector::sendMessageToRemote): (Inspector::RemoteInspector::start): (Inspector::RemoteInspector::setupXPCConnectionIfNeeded): (Inspector::RemoteInspector::setParentProcessInformation): (Inspector::RemoteInspector::xpcConnectionReceivedMessage): (Inspector::RemoteInspector::xpcConnectionFailed): (Inspector::RemoteInspector::pushListingsSoon): (Inspector::RemoteInspector::receivedIndicateMessage): (Inspector::RemoteInspector::receivedProxyApplicationSetupMessage): * inspector/remote/cocoa/RemoteInspectorXPCConnection.mm: (Inspector::RemoteInspectorXPCConnection::close): (Inspector::RemoteInspectorXPCConnection::closeFromMessage): (Inspector::RemoteInspectorXPCConnection::deserializeMessage): (Inspector::RemoteInspectorXPCConnection::handleEvent): * inspector/remote/glib/RemoteInspectorGlib.cpp: (Inspector::RemoteInspector::start): (Inspector::RemoteInspector::setupConnection): (Inspector::RemoteInspector::pushListingsSoon): (Inspector::RemoteInspector::sendMessageToRemote): (Inspector::RemoteInspector::receivedGetTargetListMessage): (Inspector::RemoteInspector::receivedDataMessage): (Inspector::RemoteInspector::receivedCloseMessage): (Inspector::RemoteInspector::setup): * inspector/remote/socket/RemoteInspectorConnectionClient.cpp: (Inspector::RemoteInspectorConnectionClient::didReceive): * inspector/remote/socket/RemoteInspectorSocket.cpp: (Inspector::RemoteInspector::didClose): (Inspector::RemoteInspector::start): (Inspector::RemoteInspector::pushListingsSoon): (Inspector::RemoteInspector::setup): (Inspector::RemoteInspector::setupInspectorClient): (Inspector::RemoteInspector::frontendDidClose): (Inspector::RemoteInspector::sendMessageToBackend): (Inspector::RemoteInspector::startAutomationSession): * inspector/remote/socket/RemoteInspectorSocketEndpoint.cpp: (Inspector::RemoteInspectorSocketEndpoint::listenInet): (Inspector::RemoteInspectorSocketEndpoint::isListening): (Inspector::RemoteInspectorSocketEndpoint::workerThread): (Inspector::RemoteInspectorSocketEndpoint::createClient): (Inspector::RemoteInspectorSocketEndpoint::disconnect): (Inspector::RemoteInspectorSocketEndpoint::invalidateClient): (Inspector::RemoteInspectorSocketEndpoint::invalidateListener): (Inspector::RemoteInspectorSocketEndpoint::getPort const): (Inspector::RemoteInspectorSocketEndpoint::recvIfEnabled): (Inspector::RemoteInspectorSocketEndpoint::sendIfEnabled): (Inspector::RemoteInspectorSocketEndpoint::send): (Inspector::RemoteInspectorSocketEndpoint::acceptInetSocketIfEnabled): * interpreter/CLoopStack.cpp: (JSC::CLoopStack::addToCommittedByteCount): (JSC::CLoopStack::committedByteCount): * jit/ExecutableAllocator.cpp: (JSC::dumpJITMemory): * jit/ICStats.cpp: (JSC::ICStats::ICStats): (JSC::ICStats::~ICStats): * jit/JITThunks.cpp: (JSC::JITThunks::ctiStub): (JSC::JITThunks::existingCTIStub): (JSC::JITThunks::ctiSlowPathFunctionStub): * jit/JITWorklist.cpp: (JSC::JITWorklist::Plan::compileInThread): (JSC::JITWorklist::Plan::isFinishedCompiling): (JSC::JITWorklist::JITWorklist): (JSC::JITWorklist::completeAllForVM): (JSC::JITWorklist::poll): (JSC::JITWorklist::compileLater): (JSC::JITWorklist::finalizePlans): * parser/SourceProvider.cpp: (JSC::SourceProvider::getID): * profiler/ProfilerDatabase.cpp: (JSC::Profiler::Database::ensureBytecodesFor): (JSC::Profiler::Database::notifyDestruction): (JSC::Profiler::Database::addCompilation): (JSC::Profiler::Database::logEvent): (JSC::Profiler::Database::addDatabaseToAtExit): (JSC::Profiler::Database::removeDatabaseFromAtExit): (JSC::Profiler::Database::removeFirstAtExitDatabase): * profiler/ProfilerUID.cpp: (JSC::Profiler::UID::create): * runtime/DeferredWorkTimer.cpp: (JSC::DeferredWorkTimer::scheduleWorkSoon): (JSC::DeferredWorkTimer::didResumeScriptExecutionOwner): * runtime/SamplingProfiler.cpp: (JSC::SamplingProfiler::timerLoop): (JSC::SamplingProfiler::shutdown): (JSC::SamplingProfiler::start): (JSC::SamplingProfiler::noticeCurrentThreadAsJSCExecutionThread): (JSC::SamplingProfiler::noticeJSLockAcquisition): (JSC::SamplingProfiler::noticeVMEntry): (JSC::SamplingProfiler::registerForReportAtExit): * runtime/Watchdog.cpp: (JSC::Watchdog::startTimer): (JSC::Watchdog::willDestroyVM): * tools/VMInspector.cpp: (JSC::VMInspector::isValidExecutableMemory): * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::work): * wasm/WasmEntryPlan.cpp: (JSC::Wasm::EntryPlan::ThreadCountHolder::ThreadCountHolder): (JSC::Wasm::EntryPlan::ThreadCountHolder::~ThreadCountHolder): * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::work): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::addCompletionTask): (JSC::Wasm::Plan::waitForCompletion): (JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast): * wasm/WasmSignature.cpp: (JSC::Wasm::SignatureInformation::signatureFor): (JSC::Wasm::SignatureInformation::tryCleanup): * wasm/WasmWorklist.cpp: (JSC::Wasm::Worklist::enqueue): (JSC::Wasm::Worklist::completePlanSynchronously): (JSC::Wasm::Worklist::stopAllPlansForContext): (JSC::Wasm::Worklist::Worklist): (JSC::Wasm::Worklist::~Worklist): Source/WebCore: * Modules/webaudio/AsyncAudioDecoder.cpp: (WebCore::AsyncAudioDecoder::AsyncAudioDecoder): (WebCore::AsyncAudioDecoder::runLoop): * Modules/webdatabase/Database.cpp: (WebCore::Database::performClose): (WebCore::Database::inProgressTransactionCompleted): (WebCore::Database::hasPendingTransaction): (WebCore::Database::runTransaction): * Modules/webdatabase/DatabaseThread.cpp: (WebCore::DatabaseThread::start): (WebCore::DatabaseThread::databaseThread): (WebCore::DatabaseThread::recordDatabaseOpen): (WebCore::DatabaseThread::recordDatabaseClosed): (WebCore::DatabaseThread::hasPendingDatabaseActivity const): * Modules/webdatabase/DatabaseTracker.cpp: (WebCore::DatabaseTracker::canEstablishDatabase): (WebCore::DatabaseTracker::retryCanEstablishDatabase): (WebCore::DatabaseTracker::maximumSize): (WebCore::DatabaseTracker::fullPathForDatabase): (WebCore::DatabaseTracker::origins): (WebCore::DatabaseTracker::databaseNames): (WebCore::DatabaseTracker::detailsForNameAndOrigin): (WebCore::DatabaseTracker::setDatabaseDetails): (WebCore::DatabaseTracker::doneCreatingDatabase): (WebCore::DatabaseTracker::openDatabases): (WebCore::DatabaseTracker::addOpenDatabase): (WebCore::DatabaseTracker::removeOpenDatabase): (WebCore::DatabaseTracker::originLockFor): (WebCore::DatabaseTracker::quota): (WebCore::DatabaseTracker::setQuota): (WebCore::DatabaseTracker::deleteOrigin): (WebCore::DatabaseTracker::deleteDatabase): (WebCore::DatabaseTracker::deleteDatabaseFile): (WebCore::DatabaseTracker::removeDeletedOpenedDatabases): * Modules/webdatabase/SQLCallbackWrapper.h: (WebCore::SQLCallbackWrapper::clear): (WebCore::SQLCallbackWrapper::unwrap): * Modules/webdatabase/SQLTransaction.cpp: (WebCore::SQLTransaction::enqueueStatement): (WebCore::SQLTransaction::checkAndHandleClosedDatabase): (WebCore::SQLTransaction::getNextStatement): * Modules/webdatabase/SQLTransactionBackend.cpp: (WebCore::SQLTransactionBackend::doCleanup): * accessibility/isolatedtree/AXIsolatedTree.cpp: (WebCore::AXIsolatedTree::clear): (WebCore::AXIsolatedTree::generateSubtree): (WebCore::AXIsolatedTree::createSubtree): (WebCore::AXIsolatedTree::updateNode): (WebCore::AXIsolatedTree::updateNodeProperty): (WebCore::AXIsolatedTree::updateChildren): (WebCore::AXIsolatedTree::focusedNode): (WebCore::AXIsolatedTree::rootNode): (WebCore::AXIsolatedTree::setFocusedNodeID): (WebCore::AXIsolatedTree::removeNode): (WebCore::AXIsolatedTree::removeSubtree): (WebCore::AXIsolatedTree::applyPendingChanges): * page/scrolling/mac/ScrollingTreeMac.mm: (ScrollingTreeMac::scrollingNodeForPoint): (ScrollingTreeMac::eventListenerRegionTypesForPoint const): * platform/AbortableTaskQueue.h: * platform/audio/cocoa/CARingBuffer.cpp: (WebCore::CARingBufferStorageVector::flush): (WebCore::CARingBufferStorageVector::setCurrentFrameBounds): * platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp: (WebCore::AVFWrapper::addToMap): (WebCore::AVFWrapper::removeFromMap const): (WebCore::AVFWrapper::periodicTimeObserverCallback): (WebCore::AVFWrapper::processNotification): (WebCore::AVFWrapper::loadPlayableCompletionCallback): (WebCore::AVFWrapper::loadMetadataCompletionCallback): (WebCore::AVFWrapper::seekCompletedCallback): (WebCore::AVFWrapper::processCue): (WebCore::AVFWrapper::legibleOutputCallback): (WebCore::AVFWrapper::processShouldWaitForLoadingOfResource): (WebCore::AVFWrapper::resourceLoaderShouldWaitForLoadingOfRequestedResource): * platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.mm: (-[WebCoreSharedBufferResourceLoaderDelegate setExpectedContentSize:]): (-[WebCoreSharedBufferResourceLoaderDelegate updateData:complete:]): (-[WebCoreSharedBufferResourceLoaderDelegate resourceLoader:shouldWaitForLoadingOfRequestedResource:]): (-[WebCoreSharedBufferResourceLoaderDelegate resourceLoader:didCancelLoadingRequest:]): (WebCore::ImageDecoderAVFObjC::setTrack): (WebCore::ImageDecoderAVFObjC::createFrameImageAtIndex): * platform/graphics/gstreamer/ImageDecoderGStreamer.cpp: (WebCore::ImageDecoderGStreamer::createFrameImageAtIndex): * platform/graphics/gstreamer/InbandTextTrackPrivateGStreamer.cpp: (WebCore::InbandTextTrackPrivateGStreamer::handleSample): (WebCore::InbandTextTrackPrivateGStreamer::notifyTrackOfSample): * platform/graphics/gstreamer/MainThreadNotifier.h: * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::parseInitDataFromProtectionMessage): (WebCore::MediaPlayerPrivateGStreamer::handleProtectionEvent): * platform/graphics/gstreamer/TrackPrivateBaseGStreamer.cpp: (WebCore::TrackPrivateBaseGStreamer::tagsChanged): (WebCore::TrackPrivateBaseGStreamer::notifyTrackOfTagsChanged): * platform/graphics/gstreamer/VideoSinkGStreamer.cpp: (VideoRenderRequestScheduler::start): (VideoRenderRequestScheduler::stop): (VideoRenderRequestScheduler::drain): (VideoRenderRequestScheduler::requestRender): * platform/graphics/gstreamer/eme/WebKitCommonEncryptionDecryptorGStreamer.cpp: (transformInPlace): (sinkEventHandler): (webKitMediaCommonEncryptionDecryptIsFlushing): (setContext): * platform/graphics/nicosia/NicosiaBuffer.cpp: (Nicosia::Buffer::beginPainting): (Nicosia::Buffer::completePainting): (Nicosia::Buffer::waitUntilPaintingComplete): * platform/graphics/nicosia/NicosiaPlatformLayer.h: (Nicosia::PlatformLayer::setSceneIntegration): (Nicosia::PlatformLayer::createUpdateScope): (Nicosia::CompositionLayer::updateState): (Nicosia::CompositionLayer::flushState): (Nicosia::CompositionLayer::commitState): (Nicosia::CompositionLayer::accessPending): (Nicosia::CompositionLayer::accessCommitted): * platform/graphics/nicosia/NicosiaScene.h: (Nicosia::Scene::accessState): * platform/graphics/nicosia/NicosiaSceneIntegration.cpp: (Nicosia::SceneIntegration::setClient): (Nicosia::SceneIntegration::invalidate): (Nicosia::SceneIntegration::requestUpdate): * platform/graphics/nicosia/texmap/NicosiaBackingStoreTextureMapperImpl.cpp: (Nicosia::BackingStoreTextureMapperImpl::flushUpdate): (Nicosia::BackingStoreTextureMapperImpl::takeUpdate): * platform/graphics/nicosia/texmap/NicosiaContentLayerTextureMapperImpl.cpp: (Nicosia::ContentLayerTextureMapperImpl::~ContentLayerTextureMapperImpl): (Nicosia::ContentLayerTextureMapperImpl::invalidateClient): (Nicosia::ContentLayerTextureMapperImpl::flushUpdate): (Nicosia::ContentLayerTextureMapperImpl::swapBuffersIfNeeded): * platform/graphics/nicosia/texmap/NicosiaImageBackingTextureMapperImpl.cpp: (Nicosia::ImageBackingTextureMapperImpl::flushUpdate): (Nicosia::ImageBackingTextureMapperImpl::takeUpdate): * platform/graphics/texmap/TextureMapperGCGLPlatformLayer.cpp: (WebCore::TextureMapperGCGLPlatformLayer::swapBuffersIfNeeded): * platform/graphics/win/MediaPlayerPrivateMediaFoundation.cpp: (WebCore::MediaPlayerPrivateMediaFoundation::load): (WebCore::MediaPlayerPrivateMediaFoundation::naturalSize const): (WebCore::MediaPlayerPrivateMediaFoundation::addListener): (WebCore::MediaPlayerPrivateMediaFoundation::removeListener): (WebCore::MediaPlayerPrivateMediaFoundation::notifyDeleted): (WebCore::MediaPlayerPrivateMediaFoundation::setNaturalSize): (WebCore::MediaPlayerPrivateMediaFoundation::AsyncCallback::Invoke): (WebCore::MediaPlayerPrivateMediaFoundation::AsyncCallback::onMediaPlayerDeleted): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::OnClockStart): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::OnClockStop): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::OnClockPause): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::OnClockRestart): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::OnClockSetRate): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::ProcessMessage): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::GetCurrentMediaType): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::InitServicePointers): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::ReleaseServicePointers): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::SetVideoWindow): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::GetVideoWindow): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::SetVideoPosition): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::GetVideoPosition): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::RepaintVideo): (WebCore::MediaPlayerPrivateMediaFoundation::VideoSamplePool::getSample): (WebCore::MediaPlayerPrivateMediaFoundation::VideoSamplePool::returnSample): (WebCore::MediaPlayerPrivateMediaFoundation::VideoSamplePool::areSamplesPending): (WebCore::MediaPlayerPrivateMediaFoundation::VideoSamplePool::initialize): (WebCore::MediaPlayerPrivateMediaFoundation::VideoSamplePool::clear): (WebCore::MediaPlayerPrivateMediaFoundation::VideoScheduler::stopScheduler): (WebCore::MediaPlayerPrivateMediaFoundation::VideoScheduler::scheduleSample): (WebCore::MediaPlayerPrivateMediaFoundation::VideoScheduler::processSamplesInQueue): (WebCore::MediaPlayerPrivateMediaFoundation::VideoScheduler::processSample): (WebCore::MediaPlayerPrivateMediaFoundation::VideoScheduler::schedulerThreadProcPrivate): (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::setVideoWindow): (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::setDestinationRect): (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::createVideoSamples): (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::checkDeviceState): (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::presentSample): (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::paintCurrentFrame): (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::createD3DDevice): * platform/image-decoders/ScalableImageDecoder.cpp: (WebCore::ScalableImageDecoder::frameIsCompleteAtIndex const): (WebCore::ScalableImageDecoder::frameHasAlphaAtIndex const): (WebCore::ScalableImageDecoder::frameBytesAtIndex const): (WebCore::ScalableImageDecoder::frameDurationAtIndex const): (WebCore::ScalableImageDecoder::createFrameImageAtIndex): * platform/image-decoders/ScalableImageDecoder.h: * platform/ios/LegacyTileCache.mm: (WebCore::LegacyTileCache::setTilesOpaque): (WebCore::LegacyTileCache::doLayoutTiles): (WebCore::LegacyTileCache::setCurrentScale): (WebCore::LegacyTileCache::commitScaleChange): (WebCore::LegacyTileCache::layoutTilesNow): (WebCore::LegacyTileCache::layoutTilesNowForRect): (WebCore::LegacyTileCache::removeAllNonVisibleTiles): (WebCore::LegacyTileCache::removeAllTiles): (WebCore::LegacyTileCache::removeForegroundTiles): (WebCore::LegacyTileCache::setContentReplacementImage): (WebCore::LegacyTileCache::contentReplacementImage const): (WebCore::LegacyTileCache::tileCreationTimerFired): (WebCore::LegacyTileCache::setNeedsDisplayInRect): (WebCore::LegacyTileCache::updateTilingMode): (WebCore::LegacyTileCache::setTilingMode): (WebCore::LegacyTileCache::doPendingRepaints): (WebCore::LegacyTileCache::flushSavedDisplayRects): (WebCore::LegacyTileCache::prepareToDraw): * platform/ios/LegacyTileLayerPool.mm: (WebCore::LegacyTileLayerPool::addLayer): (WebCore::LegacyTileLayerPool::takeLayerWithSize): (WebCore::LegacyTileLayerPool::setCapacity): (WebCore::LegacyTileLayerPool::prune): (WebCore::LegacyTileLayerPool::drain): * platform/ios/wak/WAKWindow.mm: (-[WAKWindow setExposedScrollViewRect:]): (-[WAKWindow exposedScrollViewRect]): * platform/ios/wak/WebCoreThread.mm: (RunWebThread): (StartWebThread): * platform/mediastream/gstreamer/RealtimeOutgoingAudioSourceLibWebRTC.cpp: (WebCore::RealtimeOutgoingAudioSourceLibWebRTC::audioSamplesAvailable): (WebCore::RealtimeOutgoingAudioSourceLibWebRTC::pullAudioData): * platform/network/cf/FormDataStreamCFNet.cpp: (WebCore::openNextStream): (WebCore::formFinalize): (WebCore::formClose): * platform/network/curl/CurlRequest.cpp: (WebCore::CurlRequest::setRequestPaused): (WebCore::CurlRequest::setCallbackPaused): (WebCore::CurlRequest::pausedStatusChanged): (WebCore::CurlRequest::enableDownloadToFile): (WebCore::CurlRequest::getDownloadedFilePath): (WebCore::CurlRequest::writeDataToDownloadFileIfEnabled): (WebCore::CurlRequest::closeDownloadFile): (WebCore::CurlRequest::cleanupDownloadFile): * platform/network/curl/CurlSSLHandle.cpp: (WebCore::CurlSSLHandle::allowAnyHTTPSCertificatesForHost): (WebCore::CurlSSLHandle::canIgnoreAnyHTTPSCertificatesForHost const): (WebCore::CurlSSLHandle::setClientCertificateInfo): (WebCore::CurlSSLHandle::getSSLClientCertificate const): * platform/sql/SQLiteDatabase.cpp: (WebCore::SQLiteDatabase::close): (WebCore::SQLiteDatabase::maximumSize): (WebCore::SQLiteDatabase::setMaximumSize): (WebCore::SQLiteDatabase::pageSize): (WebCore::SQLiteDatabase::freeSpaceSize): (WebCore::SQLiteDatabase::totalSize): (WebCore::SQLiteDatabase::runIncrementalVacuumCommand): (WebCore::SQLiteDatabase::interrupt): (WebCore::SQLiteDatabase::setAuthorizer): (WebCore::constructAndPrepareStatement): * platform/sql/SQLiteStatement.cpp: (WebCore::SQLiteStatement::step): Source/WebKit: * NetworkProcess/IndexedDB/WebIDBServer.cpp: (WebKit::m_closeCallback): (WebKit::WebIDBServer::getOrigins): (WebKit::WebIDBServer::closeAndDeleteDatabasesModifiedSince): (WebKit::WebIDBServer::closeAndDeleteDatabasesForOrigins): (WebKit::WebIDBServer::renameOrigin): (WebKit::WebIDBServer::openDatabase): (WebKit::WebIDBServer::deleteDatabase): (WebKit::WebIDBServer::abortTransaction): (WebKit::WebIDBServer::commitTransaction): (WebKit::WebIDBServer::didFinishHandlingVersionChangeTransaction): (WebKit::WebIDBServer::createObjectStore): (WebKit::WebIDBServer::deleteObjectStore): (WebKit::WebIDBServer::renameObjectStore): (WebKit::WebIDBServer::clearObjectStore): (WebKit::WebIDBServer::createIndex): (WebKit::WebIDBServer::deleteIndex): (WebKit::WebIDBServer::renameIndex): (WebKit::WebIDBServer::putOrAdd): (WebKit::WebIDBServer::getRecord): (WebKit::WebIDBServer::getAllRecords): (WebKit::WebIDBServer::getCount): (WebKit::WebIDBServer::deleteRecord): (WebKit::WebIDBServer::openCursor): (WebKit::WebIDBServer::iterateCursor): (WebKit::WebIDBServer::establishTransaction): (WebKit::WebIDBServer::databaseConnectionPendingClose): (WebKit::WebIDBServer::databaseConnectionClosed): (WebKit::WebIDBServer::abortOpenAndUpgradeNeeded): (WebKit::WebIDBServer::didFireVersionChangeEvent): (WebKit::WebIDBServer::openDBRequestCancelled): (WebKit::WebIDBServer::getAllDatabaseNamesAndVersions): (WebKit::WebIDBServer::addConnection): (WebKit::WebIDBServer::removeConnection): (WebKit::WebIDBServer::close): * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::writeSizeFile): (WebKit::CacheStorage::Engine::readSizeFile): (WebKit::CacheStorage::Engine::clearAllCachesFromDisk): (WebKit::CacheStorage::Engine::deleteNonEmptyDirectoryOnBackgroundThread): * NetworkProcess/glib/DNSCache.cpp: (WebKit::DNSCache::lookup): (WebKit::DNSCache::update): (WebKit::DNSCache::removeExpiredResponsesFired): (WebKit::DNSCache::clear): * Shared/CoordinatedGraphics/threadedcompositor/CompositingRunLoop.cpp: (WebKit::CompositingRunLoop::suspend): (WebKit::CompositingRunLoop::resume): (WebKit::CompositingRunLoop::scheduleUpdate): (WebKit::CompositingRunLoop::stopUpdates): (WebKit::CompositingRunLoop::updateTimerFired): * Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp: (WebKit::m_displayRefreshMonitor): (WebKit::ThreadedCompositor::setScaleFactor): (WebKit::ThreadedCompositor::setScrollPosition): (WebKit::ThreadedCompositor::setViewportSize): (WebKit::ThreadedCompositor::renderLayerTree): (WebKit::ThreadedCompositor::sceneUpdateFinished): (WebKit::ThreadedCompositor::updateSceneState): * UIProcess/API/glib/IconDatabase.cpp: (WebKit::IconDatabase::populatePageURLToIconURLMap): (WebKit::IconDatabase::clearLoadedIconsTimerFired): (WebKit::IconDatabase::checkIconURLAndSetPageURLIfNeeded): (WebKit::IconDatabase::loadIconForPageURL): (WebKit::IconDatabase::iconURLForPageURL): (WebKit::IconDatabase::setIconForPageURL): (WebKit::IconDatabase::clear): Source/WebKitLegacy: * Storage/InProcessIDBServer.cpp: (InProcessIDBServer::InProcessIDBServer): (InProcessIDBServer::deleteDatabase): (InProcessIDBServer::openDatabase): (InProcessIDBServer::abortTransaction): (InProcessIDBServer::commitTransaction): (InProcessIDBServer::didFinishHandlingVersionChangeTransaction): (InProcessIDBServer::createObjectStore): (InProcessIDBServer::deleteObjectStore): (InProcessIDBServer::renameObjectStore): (InProcessIDBServer::clearObjectStore): (InProcessIDBServer::createIndex): (InProcessIDBServer::deleteIndex): (InProcessIDBServer::renameIndex): (InProcessIDBServer::putOrAdd): (InProcessIDBServer::getRecord): (InProcessIDBServer::getAllRecords): (InProcessIDBServer::getCount): (InProcessIDBServer::deleteRecord): (InProcessIDBServer::openCursor): (InProcessIDBServer::iterateCursor): (InProcessIDBServer::establishTransaction): (InProcessIDBServer::databaseConnectionPendingClose): (InProcessIDBServer::databaseConnectionClosed): (InProcessIDBServer::abortOpenAndUpgradeNeeded): (InProcessIDBServer::didFireVersionChangeEvent): (InProcessIDBServer::openDBRequestCancelled): (InProcessIDBServer::getAllDatabaseNamesAndVersions): (InProcessIDBServer::closeAndDeleteDatabasesModifiedSince): * Storage/StorageAreaSync.cpp: (WebKit::StorageAreaSync::syncTimerFired): (WebKit::StorageAreaSync::performSync): * Storage/StorageTracker.cpp: (WebKit::StorageTracker::finishedImportingOriginIdentifiers): (WebKit::StorageTracker::syncImportOriginIdentifiers): (WebKit::StorageTracker::syncFileSystemAndTrackerDatabase): (WebKit::StorageTracker::setOriginDetails): (WebKit::StorageTracker::syncSetOriginDetails): (WebKit::StorageTracker::origins): (WebKit::StorageTracker::deleteAllOrigins): (WebKit::StorageTracker::syncDeleteAllOrigins): (WebKit::StorageTracker::deleteOrigin): (WebKit::StorageTracker::syncDeleteOrigin): (WebKit::StorageTracker::canDeleteOrigin): (WebKit::StorageTracker::cancelDeletingOrigin): (WebKit::StorageTracker::diskUsageForOrigin): Source/WebKitLegacy/mac: * WebView/WebView.mm: (-[WebView _synchronizeCustomFixedPositionLayoutRect]): (-[WebView _setCustomFixedPositionLayoutRectInWebThread:synchronize:]): (-[WebView _setCustomFixedPositionLayoutRect:]): (-[WebView _fetchCustomFixedPositionLayoutRect:]): Source/WebKitLegacy/win: * Plugins/PluginMainThreadScheduler.cpp: (WebCore::PluginMainThreadScheduler::scheduleCall): (WebCore::PluginMainThreadScheduler::registerPlugin): (WebCore::PluginMainThreadScheduler::unregisterPlugin): (WebCore::PluginMainThreadScheduler::dispatchCallsForPlugin): Source/WTF: * benchmarks/LockSpeedTest.cpp: * wtf/AutomaticThread.cpp: (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: * wtf/MetaAllocator.cpp: (WTF::MetaAllocatorHandle::shrink): (WTF::MetaAllocator::addFreshFreeSpace): (WTF::MetaAllocator::debugFreeSpaceSize): * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): * wtf/Seconds.cpp: (WTF::sleep): * wtf/TimeWithDynamicClockType.cpp: (WTF::sleep): * wtf/WorkerPool.cpp: (WTF::WorkerPool::WorkerPool): (WTF::WorkerPool::~WorkerPool): (WTF::WorkerPool::postTask): * wtf/posix/ThreadingPOSIX.cpp: (WTF::Thread::suspend): (WTF::Thread::resume): (WTF::Thread::getRegisters): * wtf/win/DbgHelperWin.cpp: (WTF::DbgHelper::SymFromAddress): * wtf/win/ThreadingWin.cpp: (WTF::Thread::suspend): (WTF::Thread::resume): (WTF::Thread::getRegisters): Tools: * TestWebKitAPI/Tests/WTF/WorkQueue.cpp: (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/WTF/glib/WorkQueueGLib.cpp: (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/WebCore/AbortableTaskQueue.cpp: (TestWebKitAPI::DeterministicScheduler::ThreadContext::waitMyTurn): (TestWebKitAPI::DeterministicScheduler::ThreadContext::yieldToThread): Canonical link: https://commits.webkit.org/238053@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@277920 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-05-22 16:49:42 +00:00
Locker locker { *m_lock };
REGRESSION: HipChat and Mail sometimes hang beneath JSC::Heap::lastChanceToFinalize() https://bugs.webkit.org/show_bug.cgi?id=165962 Reviewed by Filip Pizlo. There is an inherent race in Condition::waitFor() where the timeout can happen just before a notify from another thread. Fixed this by adding a condition variable and flag to each AutomaticThread. The flag is used to signify to a notifying thread that the thread is waiting. That flag is set in the waiting thread before calling waitFor() and cleared by another thread when it notifies the thread. The access to that flag happens when the lock is held. Now the waiting thread checks if the flag after a timeout to see that it in fact should proceed like a normal notification. The added condition variable allows us to target a specific thread. We used to keep a list of waiting threads, now we keep a list of all threads. To notify one thread, we look for a waiting thread and notify it directly. If we can't find a waiting thread, we start a sleeping thread. We notify all threads by waking all waiting threads and starting all sleeping threads. * wtf/AutomaticThread.cpp: (WTF::AutomaticThreadCondition::notifyOne): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThread::isWaiting): (WTF::AutomaticThread::notify): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Canonical link: https://commits.webkit.org/183569@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@209938 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-12-16 22:26:09 +00:00
ASSERT(m_condition->contains(locker, this));
WTF should make it easier to create threads that die automatically after inactivity https://bugs.webkit.org/show_bug.cgi?id=163576 Reviewed by Andreas Kling. Source/JavaScriptCore: Added a sleepSeconds() function, which made it easier for me to test this change. The WTF changes in this patch change how the JSC GC manages threads: the GC threads will now shut down automatically after 1 second of inactivity. Maybe this will save some memory. * jsc.cpp: (GlobalObject::finishCreation): (functionSleepSeconds): Source/WTF: For a long time now, I've been adding threads to WTF/JSC and each time I do this, I feel guilty because those threads don't shut down when they are inactive. For example, in bug 163562, I need to add a new GC thread. There will be one of them per VM. This means that a JSC API client that starts a lot of VMs will have a lot of threads. I don't think that's good. A common pattern for all of these threads is that they have some well-defined trigger that causes them to run. This trigger has a lock, a condition variable, some logic that determines if there is work to do, and then of course the logic for the thread's actual work. The thread bodies usually look like this: void Thingy::runThread() { for (;;) { Work work; { LockHolder locker(m_lock); while (!hasWork()) m_cond.wait(m_lock); work = takeWork(); } doWork(work); } } If you look at ParallelHelperPool (the GC's threads) and DFG::Worklist (some of the JIT's threads), you will see this pattern. This change adds a new kind of thread, called AutomaticThread, that lets you write threads to this pattern while getting automatic thread shutdown for free: instead of just waiting on a condition variable, AutomaticThread will have a timeout that causes the thread to die. The condition variable associated with AutomaticThread, called AutomaticThreadCondition, is smart enough to restart any threads that have decided to stop due to inactivity. The inactivity threshold is current just 1 second. In this patch I only adopt AutomaticThread for ParallelHelperPool. I plan to adopt it in more places soon. * WTF.xcodeproj/project.pbxproj: * wtf/AutomaticThread.cpp: Added. (WTF::AutomaticThreadCondition::create): (WTF::AutomaticThreadCondition::AutomaticThreadCondition): (WTF::AutomaticThreadCondition::~AutomaticThreadCondition): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Added. * wtf/CMakeLists.txt: * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::ParallelHelperPool): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::helperThreadBody): Deleted. (WTF::ParallelHelperPool::waitForClientWithTask): Deleted. * wtf/ParallelHelperPool.h: Canonical link: https://commits.webkit.org/181393@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207480 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-18 20:17:10 +00:00
}
The collector thread should only start when the mutator doesn't have heap access https://bugs.webkit.org/show_bug.cgi?id=167737 Reviewed by Keith Miller. JSTests: Add versions of splay that flash heap access, to simulate what might happen if a third-party app was running concurrent GC. In this case, we might actually start the collector thread. * stress/splay-flash-access-1ms.js: Added. (performance.now): (this.Setup.setup.setup): (this.TearDown.tearDown.tearDown): (Benchmark): (BenchmarkResult): (BenchmarkResult.prototype.valueOf): (BenchmarkSuite): (alert): (Math.random): (BenchmarkSuite.ResetRNG): (RunStep): (BenchmarkSuite.RunSuites): (BenchmarkSuite.CountBenchmarks): (BenchmarkSuite.GeometricMean): (BenchmarkSuite.GeometricMeanTime): (BenchmarkSuite.AverageAbovePercentile): (BenchmarkSuite.GeometricMeanLatency): (BenchmarkSuite.FormatScore): (BenchmarkSuite.prototype.NotifyStep): (BenchmarkSuite.prototype.NotifyResult): (BenchmarkSuite.prototype.NotifyError): (BenchmarkSuite.prototype.RunSingleBenchmark): (RunNextSetup): (RunNextBenchmark): (RunNextTearDown): (BenchmarkSuite.prototype.RunStep): (GeneratePayloadTree): (GenerateKey): (SplayUpdateStats): (InsertNewNode): (SplaySetup): (SplayTearDown): (SplayRun): (SplayTree): (SplayTree.prototype.isEmpty): (SplayTree.prototype.insert): (SplayTree.prototype.remove): (SplayTree.prototype.find): (SplayTree.prototype.findMax): (SplayTree.prototype.findGreatestLessThan): (SplayTree.prototype.exportKeys): (SplayTree.prototype.splay_): (SplayTree.Node): (SplayTree.Node.prototype.traverse_): (jscSetUp): (jscTearDown): (jscRun): (averageAbovePercentile): (printPercentile): * stress/splay-flash-access.js: Added. (performance.now): (this.Setup.setup.setup): (this.TearDown.tearDown.tearDown): (Benchmark): (BenchmarkResult): (BenchmarkResult.prototype.valueOf): (BenchmarkSuite): (alert): (Math.random): (BenchmarkSuite.ResetRNG): (RunStep): (BenchmarkSuite.RunSuites): (BenchmarkSuite.CountBenchmarks): (BenchmarkSuite.GeometricMean): (BenchmarkSuite.GeometricMeanTime): (BenchmarkSuite.AverageAbovePercentile): (BenchmarkSuite.GeometricMeanLatency): (BenchmarkSuite.FormatScore): (BenchmarkSuite.prototype.NotifyStep): (BenchmarkSuite.prototype.NotifyResult): (BenchmarkSuite.prototype.NotifyError): (BenchmarkSuite.prototype.RunSingleBenchmark): (RunNextSetup): (RunNextBenchmark): (RunNextTearDown): (BenchmarkSuite.prototype.RunStep): (GeneratePayloadTree): (GenerateKey): (SplayUpdateStats): (InsertNewNode): (SplaySetup): (SplayTearDown): (SplayRun): (SplayTree): (SplayTree.prototype.isEmpty): (SplayTree.prototype.insert): (SplayTree.prototype.remove): (SplayTree.prototype.find): (SplayTree.prototype.findMax): (SplayTree.prototype.findGreatestLessThan): (SplayTree.prototype.exportKeys): (SplayTree.prototype.splay_): (SplayTree.Node): (SplayTree.Node.prototype.traverse_): (jscSetUp): (jscTearDown): (jscRun): (averageAbovePercentile): (printPercentile): Source/JavaScriptCore: This turns the collector thread's workflow into a state machine, so that the mutator thread can run it directly. This reduces the amount of synchronization we do with the collector thread, and means that most apps will never start the collector thread. The collector thread will still start when we need to finish collecting and we don't have heap access. In this new world, "stopping the world" means relinquishing control of collection to the mutator. This means tracking who is conducting collection. I use the GCConductor enum to say who is conducting. It's either GCConductor::Mutator or GCConductor::Collector. I use the term "conn" to refer to the concept of conducting (having the conn, relinquishing the conn, taking the conn). So, stopping the world means giving the mutator the conn. Releasing heap access means giving the collector the conn. This meant bringing back the conservative scan of the calling thread. It turns out that this scan was too slow to be called on each GC increment because apparently setjmp() now does system calls. So, I wrote our own callee save register saving for the GC. Then I had doubts about whether or not it was correct, so I also made it so that the GC only rarely asks for the register state. I think we still want to use my register saving code instead of setjmp because setjmp seems to save things we don't need, and that could make us overly conservative. It turns out that this new scheduling discipline makes the old space-time scheduler perform better than the new stochastic space-time scheduler on systems with fewer than 4 cores. This is because the mutator having the conn enables us to time the mutator<->collector context switches by polling. The OS is never involved. So, we can use super precise timing. This allows the old space-time schduler to shine like it hadn't before. The splay results imply that this is all a good thing. On 2-core systems, this reduces pause times by 40% and it increases throughput about 5%. On 1-core systems, this reduces pause times by half and reduces throughput by 8%. On 4-or-more-core systems, this doesn't seem to have much effect. * CMakeLists.txt: * JavaScriptCore.xcodeproj/project.pbxproj: * bytecode/CodeBlock.cpp: (JSC::CodeBlock::visitChildren): * dfg/DFGWorklist.cpp: (JSC::DFG::Worklist::ThreadBody::ThreadBody): (JSC::DFG::Worklist::dump): (JSC::DFG::numberOfWorklists): (JSC::DFG::ensureWorklistForIndex): (JSC::DFG::existingWorklistForIndexOrNull): (JSC::DFG::existingWorklistForIndex): * dfg/DFGWorklist.h: (JSC::DFG::numberOfWorklists): Deleted. (JSC::DFG::ensureWorklistForIndex): Deleted. (JSC::DFG::existingWorklistForIndexOrNull): Deleted. (JSC::DFG::existingWorklistForIndex): Deleted. * heap/CollectingScope.h: Added. (JSC::CollectingScope::CollectingScope): (JSC::CollectingScope::~CollectingScope): * heap/CollectorPhase.cpp: Added. (JSC::worldShouldBeSuspended): (WTF::printInternal): * heap/CollectorPhase.h: Added. * heap/EdenGCActivityCallback.cpp: (JSC::EdenGCActivityCallback::lastGCLength): * heap/FullGCActivityCallback.cpp: (JSC::FullGCActivityCallback::doCollection): (JSC::FullGCActivityCallback::lastGCLength): * heap/GCConductor.cpp: Added. (JSC::gcConductorShortName): (WTF::printInternal): * heap/GCConductor.h: Added. * heap/GCFinalizationCallback.cpp: Added. (JSC::GCFinalizationCallback::GCFinalizationCallback): (JSC::GCFinalizationCallback::~GCFinalizationCallback): * heap/GCFinalizationCallback.h: Added. (JSC::GCFinalizationCallbackFuncAdaptor::GCFinalizationCallbackFuncAdaptor): (JSC::createGCFinalizationCallback): * heap/Heap.cpp: (JSC::Heap::Thread::Thread): (JSC::Heap::Heap): (JSC::Heap::lastChanceToFinalize): (JSC::Heap::gatherStackRoots): (JSC::Heap::updateObjectCounts): (JSC::Heap::sweepSynchronously): (JSC::Heap::collectAllGarbage): (JSC::Heap::collectAsync): (JSC::Heap::collectSync): (JSC::Heap::shouldCollectInCollectorThread): (JSC::Heap::collectInCollectorThread): (JSC::Heap::checkConn): (JSC::Heap::runNotRunningPhase): (JSC::Heap::runBeginPhase): (JSC::Heap::runFixpointPhase): (JSC::Heap::runConcurrentPhase): (JSC::Heap::runReloopPhase): (JSC::Heap::runEndPhase): (JSC::Heap::changePhase): (JSC::Heap::finishChangingPhase): (JSC::Heap::stopThePeriphery): (JSC::Heap::resumeThePeriphery): (JSC::Heap::stopTheMutator): (JSC::Heap::resumeTheMutator): (JSC::Heap::stopIfNecessarySlow): (JSC::Heap::collectInMutatorThread): (JSC::Heap::waitForCollector): (JSC::Heap::acquireAccessSlow): (JSC::Heap::releaseAccessSlow): (JSC::Heap::relinquishConn): (JSC::Heap::finishRelinquishingConn): (JSC::Heap::handleNeedFinalize): (JSC::Heap::notifyThreadStopping): (JSC::Heap::finalize): (JSC::Heap::addFinalizationCallback): (JSC::Heap::requestCollection): (JSC::Heap::waitForCollection): (JSC::Heap::updateAllocationLimits): (JSC::Heap::didFinishCollection): (JSC::Heap::collectIfNecessaryOrDefer): (JSC::Heap::notifyIsSafeToCollect): (JSC::Heap::preventCollection): (JSC::Heap::performIncrement): (JSC::Heap::markToFixpoint): Deleted. (JSC::Heap::shouldCollectInThread): Deleted. (JSC::Heap::collectInThread): Deleted. (JSC::Heap::stopTheWorld): Deleted. (JSC::Heap::resumeTheWorld): Deleted. * heap/Heap.h: (JSC::Heap::machineThreads): (JSC::Heap::lastFullGCLength): (JSC::Heap::lastEdenGCLength): (JSC::Heap::increaseLastFullGCLength): * heap/HeapInlines.h: (JSC::Heap::mutatorIsStopped): Deleted. * heap/HeapStatistics.cpp: Removed. * heap/HeapStatistics.h: Removed. * heap/HelpingGCScope.h: Removed. * heap/IncrementalSweeper.cpp: (JSC::IncrementalSweeper::stopSweeping): (JSC::IncrementalSweeper::willFinishSweeping): Deleted. * heap/IncrementalSweeper.h: * heap/MachineStackMarker.cpp: (JSC::MachineThreads::gatherFromCurrentThread): (JSC::MachineThreads::gatherConservativeRoots): (JSC::callWithCurrentThreadState): * heap/MachineStackMarker.h: * heap/MarkedAllocator.cpp: (JSC::MarkedAllocator::allocateSlowCaseImpl): * heap/MarkedBlock.cpp: (JSC::MarkedBlock::Handle::sweep): * heap/MarkedSpace.cpp: (JSC::MarkedSpace::sweep): * heap/MutatorState.cpp: (WTF::printInternal): * heap/MutatorState.h: * heap/RegisterState.h: Added. * heap/RunningScope.h: Added. (JSC::RunningScope::RunningScope): (JSC::RunningScope::~RunningScope): * heap/SlotVisitor.cpp: (JSC::SlotVisitor::SlotVisitor): (JSC::SlotVisitor::drain): (JSC::SlotVisitor::drainFromShared): (JSC::SlotVisitor::drainInParallelPassively): (JSC::SlotVisitor::donateAll): (JSC::SlotVisitor::donate): * heap/SlotVisitor.h: (JSC::SlotVisitor::codeName): * heap/StochasticSpaceTimeMutatorScheduler.cpp: (JSC::StochasticSpaceTimeMutatorScheduler::beginCollection): (JSC::StochasticSpaceTimeMutatorScheduler::synchronousDrainingDidStall): (JSC::StochasticSpaceTimeMutatorScheduler::timeToStop): * heap/SweepingScope.h: Added. (JSC::SweepingScope::SweepingScope): (JSC::SweepingScope::~SweepingScope): * jit/JITWorklist.cpp: (JSC::JITWorklist::Thread::Thread): * jsc.cpp: (GlobalObject::finishCreation): (functionFlashHeapAccess): * runtime/InitializeThreading.cpp: (JSC::initializeThreading): * runtime/JSCellInlines.h: (JSC::JSCell::classInfo): * runtime/Options.cpp: (JSC::overrideDefaults): * runtime/Options.h: * runtime/TestRunnerUtils.cpp: (JSC::finalizeStatsAtEndOfTesting): Source/WebCore: Added new tests in JSTests. The WebCore changes involve: - Refactoring around new header discipline. - Adding crazy GC APIs to window.internals to enable us to test the GC's runloop discipline. * ForwardingHeaders/heap/GCFinalizationCallback.h: Added. * ForwardingHeaders/heap/IncrementalSweeper.h: Added. * ForwardingHeaders/heap/MachineStackMarker.h: Added. * ForwardingHeaders/heap/RunningScope.h: Added. * bindings/js/CommonVM.cpp: * testing/Internals.cpp: (WebCore::Internals::parserMetaData): (WebCore::Internals::isReadableStreamDisturbed): (WebCore::Internals::isGCRunning): (WebCore::Internals::addGCFinalizationCallback): (WebCore::Internals::stopSweeping): (WebCore::Internals::startSweeping): * testing/Internals.h: * testing/Internals.idl: Source/WTF: Extend the use of AbstractLocker so that we can use more locking idioms. * wtf/AutomaticThread.cpp: (WTF::AutomaticThreadCondition::notifyOne): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::tryStop): (WTF::AutomaticThread::isWaiting): (WTF::AutomaticThread::notify): (WTF::AutomaticThread::start): (WTF::AutomaticThread::threadIsStopping): * wtf/AutomaticThread.h: * wtf/NumberOfCores.cpp: (WTF::numberOfProcessorCores): * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::claimTask): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::hasClientWithTask): (WTF::ParallelHelperPool::getClientWithTask): * wtf/ParallelHelperPool.h: Tools: Make more tests collect continuously. * Scripts/run-jsc-stress-tests: Canonical link: https://commits.webkit.org/185692@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@212778 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-02-22 00:58:15 +00:00
auto stopImpl = [&] (const AbstractLocker& locker) {
thread->threadIsStopping(locker);
thread->m_hasUnderlyingThread = false;
};
The collector thread should only start when the mutator doesn't have heap access https://bugs.webkit.org/show_bug.cgi?id=167737 Reviewed by Keith Miller. JSTests: Add versions of splay that flash heap access, to simulate what might happen if a third-party app was running concurrent GC. In this case, we might actually start the collector thread. * stress/splay-flash-access-1ms.js: Added. (performance.now): (this.Setup.setup.setup): (this.TearDown.tearDown.tearDown): (Benchmark): (BenchmarkResult): (BenchmarkResult.prototype.valueOf): (BenchmarkSuite): (alert): (Math.random): (BenchmarkSuite.ResetRNG): (RunStep): (BenchmarkSuite.RunSuites): (BenchmarkSuite.CountBenchmarks): (BenchmarkSuite.GeometricMean): (BenchmarkSuite.GeometricMeanTime): (BenchmarkSuite.AverageAbovePercentile): (BenchmarkSuite.GeometricMeanLatency): (BenchmarkSuite.FormatScore): (BenchmarkSuite.prototype.NotifyStep): (BenchmarkSuite.prototype.NotifyResult): (BenchmarkSuite.prototype.NotifyError): (BenchmarkSuite.prototype.RunSingleBenchmark): (RunNextSetup): (RunNextBenchmark): (RunNextTearDown): (BenchmarkSuite.prototype.RunStep): (GeneratePayloadTree): (GenerateKey): (SplayUpdateStats): (InsertNewNode): (SplaySetup): (SplayTearDown): (SplayRun): (SplayTree): (SplayTree.prototype.isEmpty): (SplayTree.prototype.insert): (SplayTree.prototype.remove): (SplayTree.prototype.find): (SplayTree.prototype.findMax): (SplayTree.prototype.findGreatestLessThan): (SplayTree.prototype.exportKeys): (SplayTree.prototype.splay_): (SplayTree.Node): (SplayTree.Node.prototype.traverse_): (jscSetUp): (jscTearDown): (jscRun): (averageAbovePercentile): (printPercentile): * stress/splay-flash-access.js: Added. (performance.now): (this.Setup.setup.setup): (this.TearDown.tearDown.tearDown): (Benchmark): (BenchmarkResult): (BenchmarkResult.prototype.valueOf): (BenchmarkSuite): (alert): (Math.random): (BenchmarkSuite.ResetRNG): (RunStep): (BenchmarkSuite.RunSuites): (BenchmarkSuite.CountBenchmarks): (BenchmarkSuite.GeometricMean): (BenchmarkSuite.GeometricMeanTime): (BenchmarkSuite.AverageAbovePercentile): (BenchmarkSuite.GeometricMeanLatency): (BenchmarkSuite.FormatScore): (BenchmarkSuite.prototype.NotifyStep): (BenchmarkSuite.prototype.NotifyResult): (BenchmarkSuite.prototype.NotifyError): (BenchmarkSuite.prototype.RunSingleBenchmark): (RunNextSetup): (RunNextBenchmark): (RunNextTearDown): (BenchmarkSuite.prototype.RunStep): (GeneratePayloadTree): (GenerateKey): (SplayUpdateStats): (InsertNewNode): (SplaySetup): (SplayTearDown): (SplayRun): (SplayTree): (SplayTree.prototype.isEmpty): (SplayTree.prototype.insert): (SplayTree.prototype.remove): (SplayTree.prototype.find): (SplayTree.prototype.findMax): (SplayTree.prototype.findGreatestLessThan): (SplayTree.prototype.exportKeys): (SplayTree.prototype.splay_): (SplayTree.Node): (SplayTree.Node.prototype.traverse_): (jscSetUp): (jscTearDown): (jscRun): (averageAbovePercentile): (printPercentile): Source/JavaScriptCore: This turns the collector thread's workflow into a state machine, so that the mutator thread can run it directly. This reduces the amount of synchronization we do with the collector thread, and means that most apps will never start the collector thread. The collector thread will still start when we need to finish collecting and we don't have heap access. In this new world, "stopping the world" means relinquishing control of collection to the mutator. This means tracking who is conducting collection. I use the GCConductor enum to say who is conducting. It's either GCConductor::Mutator or GCConductor::Collector. I use the term "conn" to refer to the concept of conducting (having the conn, relinquishing the conn, taking the conn). So, stopping the world means giving the mutator the conn. Releasing heap access means giving the collector the conn. This meant bringing back the conservative scan of the calling thread. It turns out that this scan was too slow to be called on each GC increment because apparently setjmp() now does system calls. So, I wrote our own callee save register saving for the GC. Then I had doubts about whether or not it was correct, so I also made it so that the GC only rarely asks for the register state. I think we still want to use my register saving code instead of setjmp because setjmp seems to save things we don't need, and that could make us overly conservative. It turns out that this new scheduling discipline makes the old space-time scheduler perform better than the new stochastic space-time scheduler on systems with fewer than 4 cores. This is because the mutator having the conn enables us to time the mutator<->collector context switches by polling. The OS is never involved. So, we can use super precise timing. This allows the old space-time schduler to shine like it hadn't before. The splay results imply that this is all a good thing. On 2-core systems, this reduces pause times by 40% and it increases throughput about 5%. On 1-core systems, this reduces pause times by half and reduces throughput by 8%. On 4-or-more-core systems, this doesn't seem to have much effect. * CMakeLists.txt: * JavaScriptCore.xcodeproj/project.pbxproj: * bytecode/CodeBlock.cpp: (JSC::CodeBlock::visitChildren): * dfg/DFGWorklist.cpp: (JSC::DFG::Worklist::ThreadBody::ThreadBody): (JSC::DFG::Worklist::dump): (JSC::DFG::numberOfWorklists): (JSC::DFG::ensureWorklistForIndex): (JSC::DFG::existingWorklistForIndexOrNull): (JSC::DFG::existingWorklistForIndex): * dfg/DFGWorklist.h: (JSC::DFG::numberOfWorklists): Deleted. (JSC::DFG::ensureWorklistForIndex): Deleted. (JSC::DFG::existingWorklistForIndexOrNull): Deleted. (JSC::DFG::existingWorklistForIndex): Deleted. * heap/CollectingScope.h: Added. (JSC::CollectingScope::CollectingScope): (JSC::CollectingScope::~CollectingScope): * heap/CollectorPhase.cpp: Added. (JSC::worldShouldBeSuspended): (WTF::printInternal): * heap/CollectorPhase.h: Added. * heap/EdenGCActivityCallback.cpp: (JSC::EdenGCActivityCallback::lastGCLength): * heap/FullGCActivityCallback.cpp: (JSC::FullGCActivityCallback::doCollection): (JSC::FullGCActivityCallback::lastGCLength): * heap/GCConductor.cpp: Added. (JSC::gcConductorShortName): (WTF::printInternal): * heap/GCConductor.h: Added. * heap/GCFinalizationCallback.cpp: Added. (JSC::GCFinalizationCallback::GCFinalizationCallback): (JSC::GCFinalizationCallback::~GCFinalizationCallback): * heap/GCFinalizationCallback.h: Added. (JSC::GCFinalizationCallbackFuncAdaptor::GCFinalizationCallbackFuncAdaptor): (JSC::createGCFinalizationCallback): * heap/Heap.cpp: (JSC::Heap::Thread::Thread): (JSC::Heap::Heap): (JSC::Heap::lastChanceToFinalize): (JSC::Heap::gatherStackRoots): (JSC::Heap::updateObjectCounts): (JSC::Heap::sweepSynchronously): (JSC::Heap::collectAllGarbage): (JSC::Heap::collectAsync): (JSC::Heap::collectSync): (JSC::Heap::shouldCollectInCollectorThread): (JSC::Heap::collectInCollectorThread): (JSC::Heap::checkConn): (JSC::Heap::runNotRunningPhase): (JSC::Heap::runBeginPhase): (JSC::Heap::runFixpointPhase): (JSC::Heap::runConcurrentPhase): (JSC::Heap::runReloopPhase): (JSC::Heap::runEndPhase): (JSC::Heap::changePhase): (JSC::Heap::finishChangingPhase): (JSC::Heap::stopThePeriphery): (JSC::Heap::resumeThePeriphery): (JSC::Heap::stopTheMutator): (JSC::Heap::resumeTheMutator): (JSC::Heap::stopIfNecessarySlow): (JSC::Heap::collectInMutatorThread): (JSC::Heap::waitForCollector): (JSC::Heap::acquireAccessSlow): (JSC::Heap::releaseAccessSlow): (JSC::Heap::relinquishConn): (JSC::Heap::finishRelinquishingConn): (JSC::Heap::handleNeedFinalize): (JSC::Heap::notifyThreadStopping): (JSC::Heap::finalize): (JSC::Heap::addFinalizationCallback): (JSC::Heap::requestCollection): (JSC::Heap::waitForCollection): (JSC::Heap::updateAllocationLimits): (JSC::Heap::didFinishCollection): (JSC::Heap::collectIfNecessaryOrDefer): (JSC::Heap::notifyIsSafeToCollect): (JSC::Heap::preventCollection): (JSC::Heap::performIncrement): (JSC::Heap::markToFixpoint): Deleted. (JSC::Heap::shouldCollectInThread): Deleted. (JSC::Heap::collectInThread): Deleted. (JSC::Heap::stopTheWorld): Deleted. (JSC::Heap::resumeTheWorld): Deleted. * heap/Heap.h: (JSC::Heap::machineThreads): (JSC::Heap::lastFullGCLength): (JSC::Heap::lastEdenGCLength): (JSC::Heap::increaseLastFullGCLength): * heap/HeapInlines.h: (JSC::Heap::mutatorIsStopped): Deleted. * heap/HeapStatistics.cpp: Removed. * heap/HeapStatistics.h: Removed. * heap/HelpingGCScope.h: Removed. * heap/IncrementalSweeper.cpp: (JSC::IncrementalSweeper::stopSweeping): (JSC::IncrementalSweeper::willFinishSweeping): Deleted. * heap/IncrementalSweeper.h: * heap/MachineStackMarker.cpp: (JSC::MachineThreads::gatherFromCurrentThread): (JSC::MachineThreads::gatherConservativeRoots): (JSC::callWithCurrentThreadState): * heap/MachineStackMarker.h: * heap/MarkedAllocator.cpp: (JSC::MarkedAllocator::allocateSlowCaseImpl): * heap/MarkedBlock.cpp: (JSC::MarkedBlock::Handle::sweep): * heap/MarkedSpace.cpp: (JSC::MarkedSpace::sweep): * heap/MutatorState.cpp: (WTF::printInternal): * heap/MutatorState.h: * heap/RegisterState.h: Added. * heap/RunningScope.h: Added. (JSC::RunningScope::RunningScope): (JSC::RunningScope::~RunningScope): * heap/SlotVisitor.cpp: (JSC::SlotVisitor::SlotVisitor): (JSC::SlotVisitor::drain): (JSC::SlotVisitor::drainFromShared): (JSC::SlotVisitor::drainInParallelPassively): (JSC::SlotVisitor::donateAll): (JSC::SlotVisitor::donate): * heap/SlotVisitor.h: (JSC::SlotVisitor::codeName): * heap/StochasticSpaceTimeMutatorScheduler.cpp: (JSC::StochasticSpaceTimeMutatorScheduler::beginCollection): (JSC::StochasticSpaceTimeMutatorScheduler::synchronousDrainingDidStall): (JSC::StochasticSpaceTimeMutatorScheduler::timeToStop): * heap/SweepingScope.h: Added. (JSC::SweepingScope::SweepingScope): (JSC::SweepingScope::~SweepingScope): * jit/JITWorklist.cpp: (JSC::JITWorklist::Thread::Thread): * jsc.cpp: (GlobalObject::finishCreation): (functionFlashHeapAccess): * runtime/InitializeThreading.cpp: (JSC::initializeThreading): * runtime/JSCellInlines.h: (JSC::JSCell::classInfo): * runtime/Options.cpp: (JSC::overrideDefaults): * runtime/Options.h: * runtime/TestRunnerUtils.cpp: (JSC::finalizeStatsAtEndOfTesting): Source/WebCore: Added new tests in JSTests. The WebCore changes involve: - Refactoring around new header discipline. - Adding crazy GC APIs to window.internals to enable us to test the GC's runloop discipline. * ForwardingHeaders/heap/GCFinalizationCallback.h: Added. * ForwardingHeaders/heap/IncrementalSweeper.h: Added. * ForwardingHeaders/heap/MachineStackMarker.h: Added. * ForwardingHeaders/heap/RunningScope.h: Added. * bindings/js/CommonVM.cpp: * testing/Internals.cpp: (WebCore::Internals::parserMetaData): (WebCore::Internals::isReadableStreamDisturbed): (WebCore::Internals::isGCRunning): (WebCore::Internals::addGCFinalizationCallback): (WebCore::Internals::stopSweeping): (WebCore::Internals::startSweeping): * testing/Internals.h: * testing/Internals.idl: Source/WTF: Extend the use of AbstractLocker so that we can use more locking idioms. * wtf/AutomaticThread.cpp: (WTF::AutomaticThreadCondition::notifyOne): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::tryStop): (WTF::AutomaticThread::isWaiting): (WTF::AutomaticThread::notify): (WTF::AutomaticThread::start): (WTF::AutomaticThread::threadIsStopping): * wtf/AutomaticThread.h: * wtf/NumberOfCores.cpp: (WTF::numberOfProcessorCores): * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::claimTask): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::hasClientWithTask): (WTF::ParallelHelperPool::getClientWithTask): * wtf/ParallelHelperPool.h: Tools: Make more tests collect continuously. * Scripts/run-jsc-stress-tests: Canonical link: https://commits.webkit.org/185692@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@212778 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-02-22 00:58:15 +00:00
auto stopPermanently = [&] (const AbstractLocker& locker) {
WTF should make it easier to create threads that die automatically after inactivity https://bugs.webkit.org/show_bug.cgi?id=163576 Reviewed by Andreas Kling. Source/JavaScriptCore: Added a sleepSeconds() function, which made it easier for me to test this change. The WTF changes in this patch change how the JSC GC manages threads: the GC threads will now shut down automatically after 1 second of inactivity. Maybe this will save some memory. * jsc.cpp: (GlobalObject::finishCreation): (functionSleepSeconds): Source/WTF: For a long time now, I've been adding threads to WTF/JSC and each time I do this, I feel guilty because those threads don't shut down when they are inactive. For example, in bug 163562, I need to add a new GC thread. There will be one of them per VM. This means that a JSC API client that starts a lot of VMs will have a lot of threads. I don't think that's good. A common pattern for all of these threads is that they have some well-defined trigger that causes them to run. This trigger has a lock, a condition variable, some logic that determines if there is work to do, and then of course the logic for the thread's actual work. The thread bodies usually look like this: void Thingy::runThread() { for (;;) { Work work; { LockHolder locker(m_lock); while (!hasWork()) m_cond.wait(m_lock); work = takeWork(); } doWork(work); } } If you look at ParallelHelperPool (the GC's threads) and DFG::Worklist (some of the JIT's threads), you will see this pattern. This change adds a new kind of thread, called AutomaticThread, that lets you write threads to this pattern while getting automatic thread shutdown for free: instead of just waiting on a condition variable, AutomaticThread will have a timeout that causes the thread to die. The condition variable associated with AutomaticThread, called AutomaticThreadCondition, is smart enough to restart any threads that have decided to stop due to inactivity. The inactivity threshold is current just 1 second. In this patch I only adopt AutomaticThread for ParallelHelperPool. I plan to adopt it in more places soon. * WTF.xcodeproj/project.pbxproj: * wtf/AutomaticThread.cpp: Added. (WTF::AutomaticThreadCondition::create): (WTF::AutomaticThreadCondition::AutomaticThreadCondition): (WTF::AutomaticThreadCondition::~AutomaticThreadCondition): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Added. * wtf/CMakeLists.txt: * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::ParallelHelperPool): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::helperThreadBody): Deleted. (WTF::ParallelHelperPool::waitForClientWithTask): Deleted. * wtf/ParallelHelperPool.h: Canonical link: https://commits.webkit.org/181393@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207480 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-18 20:17:10 +00:00
m_isRunning = false;
m_isRunningCondition.notifyAll();
stopImpl(locker);
};
The collector thread should only start when the mutator doesn't have heap access https://bugs.webkit.org/show_bug.cgi?id=167737 Reviewed by Keith Miller. JSTests: Add versions of splay that flash heap access, to simulate what might happen if a third-party app was running concurrent GC. In this case, we might actually start the collector thread. * stress/splay-flash-access-1ms.js: Added. (performance.now): (this.Setup.setup.setup): (this.TearDown.tearDown.tearDown): (Benchmark): (BenchmarkResult): (BenchmarkResult.prototype.valueOf): (BenchmarkSuite): (alert): (Math.random): (BenchmarkSuite.ResetRNG): (RunStep): (BenchmarkSuite.RunSuites): (BenchmarkSuite.CountBenchmarks): (BenchmarkSuite.GeometricMean): (BenchmarkSuite.GeometricMeanTime): (BenchmarkSuite.AverageAbovePercentile): (BenchmarkSuite.GeometricMeanLatency): (BenchmarkSuite.FormatScore): (BenchmarkSuite.prototype.NotifyStep): (BenchmarkSuite.prototype.NotifyResult): (BenchmarkSuite.prototype.NotifyError): (BenchmarkSuite.prototype.RunSingleBenchmark): (RunNextSetup): (RunNextBenchmark): (RunNextTearDown): (BenchmarkSuite.prototype.RunStep): (GeneratePayloadTree): (GenerateKey): (SplayUpdateStats): (InsertNewNode): (SplaySetup): (SplayTearDown): (SplayRun): (SplayTree): (SplayTree.prototype.isEmpty): (SplayTree.prototype.insert): (SplayTree.prototype.remove): (SplayTree.prototype.find): (SplayTree.prototype.findMax): (SplayTree.prototype.findGreatestLessThan): (SplayTree.prototype.exportKeys): (SplayTree.prototype.splay_): (SplayTree.Node): (SplayTree.Node.prototype.traverse_): (jscSetUp): (jscTearDown): (jscRun): (averageAbovePercentile): (printPercentile): * stress/splay-flash-access.js: Added. (performance.now): (this.Setup.setup.setup): (this.TearDown.tearDown.tearDown): (Benchmark): (BenchmarkResult): (BenchmarkResult.prototype.valueOf): (BenchmarkSuite): (alert): (Math.random): (BenchmarkSuite.ResetRNG): (RunStep): (BenchmarkSuite.RunSuites): (BenchmarkSuite.CountBenchmarks): (BenchmarkSuite.GeometricMean): (BenchmarkSuite.GeometricMeanTime): (BenchmarkSuite.AverageAbovePercentile): (BenchmarkSuite.GeometricMeanLatency): (BenchmarkSuite.FormatScore): (BenchmarkSuite.prototype.NotifyStep): (BenchmarkSuite.prototype.NotifyResult): (BenchmarkSuite.prototype.NotifyError): (BenchmarkSuite.prototype.RunSingleBenchmark): (RunNextSetup): (RunNextBenchmark): (RunNextTearDown): (BenchmarkSuite.prototype.RunStep): (GeneratePayloadTree): (GenerateKey): (SplayUpdateStats): (InsertNewNode): (SplaySetup): (SplayTearDown): (SplayRun): (SplayTree): (SplayTree.prototype.isEmpty): (SplayTree.prototype.insert): (SplayTree.prototype.remove): (SplayTree.prototype.find): (SplayTree.prototype.findMax): (SplayTree.prototype.findGreatestLessThan): (SplayTree.prototype.exportKeys): (SplayTree.prototype.splay_): (SplayTree.Node): (SplayTree.Node.prototype.traverse_): (jscSetUp): (jscTearDown): (jscRun): (averageAbovePercentile): (printPercentile): Source/JavaScriptCore: This turns the collector thread's workflow into a state machine, so that the mutator thread can run it directly. This reduces the amount of synchronization we do with the collector thread, and means that most apps will never start the collector thread. The collector thread will still start when we need to finish collecting and we don't have heap access. In this new world, "stopping the world" means relinquishing control of collection to the mutator. This means tracking who is conducting collection. I use the GCConductor enum to say who is conducting. It's either GCConductor::Mutator or GCConductor::Collector. I use the term "conn" to refer to the concept of conducting (having the conn, relinquishing the conn, taking the conn). So, stopping the world means giving the mutator the conn. Releasing heap access means giving the collector the conn. This meant bringing back the conservative scan of the calling thread. It turns out that this scan was too slow to be called on each GC increment because apparently setjmp() now does system calls. So, I wrote our own callee save register saving for the GC. Then I had doubts about whether or not it was correct, so I also made it so that the GC only rarely asks for the register state. I think we still want to use my register saving code instead of setjmp because setjmp seems to save things we don't need, and that could make us overly conservative. It turns out that this new scheduling discipline makes the old space-time scheduler perform better than the new stochastic space-time scheduler on systems with fewer than 4 cores. This is because the mutator having the conn enables us to time the mutator<->collector context switches by polling. The OS is never involved. So, we can use super precise timing. This allows the old space-time schduler to shine like it hadn't before. The splay results imply that this is all a good thing. On 2-core systems, this reduces pause times by 40% and it increases throughput about 5%. On 1-core systems, this reduces pause times by half and reduces throughput by 8%. On 4-or-more-core systems, this doesn't seem to have much effect. * CMakeLists.txt: * JavaScriptCore.xcodeproj/project.pbxproj: * bytecode/CodeBlock.cpp: (JSC::CodeBlock::visitChildren): * dfg/DFGWorklist.cpp: (JSC::DFG::Worklist::ThreadBody::ThreadBody): (JSC::DFG::Worklist::dump): (JSC::DFG::numberOfWorklists): (JSC::DFG::ensureWorklistForIndex): (JSC::DFG::existingWorklistForIndexOrNull): (JSC::DFG::existingWorklistForIndex): * dfg/DFGWorklist.h: (JSC::DFG::numberOfWorklists): Deleted. (JSC::DFG::ensureWorklistForIndex): Deleted. (JSC::DFG::existingWorklistForIndexOrNull): Deleted. (JSC::DFG::existingWorklistForIndex): Deleted. * heap/CollectingScope.h: Added. (JSC::CollectingScope::CollectingScope): (JSC::CollectingScope::~CollectingScope): * heap/CollectorPhase.cpp: Added. (JSC::worldShouldBeSuspended): (WTF::printInternal): * heap/CollectorPhase.h: Added. * heap/EdenGCActivityCallback.cpp: (JSC::EdenGCActivityCallback::lastGCLength): * heap/FullGCActivityCallback.cpp: (JSC::FullGCActivityCallback::doCollection): (JSC::FullGCActivityCallback::lastGCLength): * heap/GCConductor.cpp: Added. (JSC::gcConductorShortName): (WTF::printInternal): * heap/GCConductor.h: Added. * heap/GCFinalizationCallback.cpp: Added. (JSC::GCFinalizationCallback::GCFinalizationCallback): (JSC::GCFinalizationCallback::~GCFinalizationCallback): * heap/GCFinalizationCallback.h: Added. (JSC::GCFinalizationCallbackFuncAdaptor::GCFinalizationCallbackFuncAdaptor): (JSC::createGCFinalizationCallback): * heap/Heap.cpp: (JSC::Heap::Thread::Thread): (JSC::Heap::Heap): (JSC::Heap::lastChanceToFinalize): (JSC::Heap::gatherStackRoots): (JSC::Heap::updateObjectCounts): (JSC::Heap::sweepSynchronously): (JSC::Heap::collectAllGarbage): (JSC::Heap::collectAsync): (JSC::Heap::collectSync): (JSC::Heap::shouldCollectInCollectorThread): (JSC::Heap::collectInCollectorThread): (JSC::Heap::checkConn): (JSC::Heap::runNotRunningPhase): (JSC::Heap::runBeginPhase): (JSC::Heap::runFixpointPhase): (JSC::Heap::runConcurrentPhase): (JSC::Heap::runReloopPhase): (JSC::Heap::runEndPhase): (JSC::Heap::changePhase): (JSC::Heap::finishChangingPhase): (JSC::Heap::stopThePeriphery): (JSC::Heap::resumeThePeriphery): (JSC::Heap::stopTheMutator): (JSC::Heap::resumeTheMutator): (JSC::Heap::stopIfNecessarySlow): (JSC::Heap::collectInMutatorThread): (JSC::Heap::waitForCollector): (JSC::Heap::acquireAccessSlow): (JSC::Heap::releaseAccessSlow): (JSC::Heap::relinquishConn): (JSC::Heap::finishRelinquishingConn): (JSC::Heap::handleNeedFinalize): (JSC::Heap::notifyThreadStopping): (JSC::Heap::finalize): (JSC::Heap::addFinalizationCallback): (JSC::Heap::requestCollection): (JSC::Heap::waitForCollection): (JSC::Heap::updateAllocationLimits): (JSC::Heap::didFinishCollection): (JSC::Heap::collectIfNecessaryOrDefer): (JSC::Heap::notifyIsSafeToCollect): (JSC::Heap::preventCollection): (JSC::Heap::performIncrement): (JSC::Heap::markToFixpoint): Deleted. (JSC::Heap::shouldCollectInThread): Deleted. (JSC::Heap::collectInThread): Deleted. (JSC::Heap::stopTheWorld): Deleted. (JSC::Heap::resumeTheWorld): Deleted. * heap/Heap.h: (JSC::Heap::machineThreads): (JSC::Heap::lastFullGCLength): (JSC::Heap::lastEdenGCLength): (JSC::Heap::increaseLastFullGCLength): * heap/HeapInlines.h: (JSC::Heap::mutatorIsStopped): Deleted. * heap/HeapStatistics.cpp: Removed. * heap/HeapStatistics.h: Removed. * heap/HelpingGCScope.h: Removed. * heap/IncrementalSweeper.cpp: (JSC::IncrementalSweeper::stopSweeping): (JSC::IncrementalSweeper::willFinishSweeping): Deleted. * heap/IncrementalSweeper.h: * heap/MachineStackMarker.cpp: (JSC::MachineThreads::gatherFromCurrentThread): (JSC::MachineThreads::gatherConservativeRoots): (JSC::callWithCurrentThreadState): * heap/MachineStackMarker.h: * heap/MarkedAllocator.cpp: (JSC::MarkedAllocator::allocateSlowCaseImpl): * heap/MarkedBlock.cpp: (JSC::MarkedBlock::Handle::sweep): * heap/MarkedSpace.cpp: (JSC::MarkedSpace::sweep): * heap/MutatorState.cpp: (WTF::printInternal): * heap/MutatorState.h: * heap/RegisterState.h: Added. * heap/RunningScope.h: Added. (JSC::RunningScope::RunningScope): (JSC::RunningScope::~RunningScope): * heap/SlotVisitor.cpp: (JSC::SlotVisitor::SlotVisitor): (JSC::SlotVisitor::drain): (JSC::SlotVisitor::drainFromShared): (JSC::SlotVisitor::drainInParallelPassively): (JSC::SlotVisitor::donateAll): (JSC::SlotVisitor::donate): * heap/SlotVisitor.h: (JSC::SlotVisitor::codeName): * heap/StochasticSpaceTimeMutatorScheduler.cpp: (JSC::StochasticSpaceTimeMutatorScheduler::beginCollection): (JSC::StochasticSpaceTimeMutatorScheduler::synchronousDrainingDidStall): (JSC::StochasticSpaceTimeMutatorScheduler::timeToStop): * heap/SweepingScope.h: Added. (JSC::SweepingScope::SweepingScope): (JSC::SweepingScope::~SweepingScope): * jit/JITWorklist.cpp: (JSC::JITWorklist::Thread::Thread): * jsc.cpp: (GlobalObject::finishCreation): (functionFlashHeapAccess): * runtime/InitializeThreading.cpp: (JSC::initializeThreading): * runtime/JSCellInlines.h: (JSC::JSCell::classInfo): * runtime/Options.cpp: (JSC::overrideDefaults): * runtime/Options.h: * runtime/TestRunnerUtils.cpp: (JSC::finalizeStatsAtEndOfTesting): Source/WebCore: Added new tests in JSTests. The WebCore changes involve: - Refactoring around new header discipline. - Adding crazy GC APIs to window.internals to enable us to test the GC's runloop discipline. * ForwardingHeaders/heap/GCFinalizationCallback.h: Added. * ForwardingHeaders/heap/IncrementalSweeper.h: Added. * ForwardingHeaders/heap/MachineStackMarker.h: Added. * ForwardingHeaders/heap/RunningScope.h: Added. * bindings/js/CommonVM.cpp: * testing/Internals.cpp: (WebCore::Internals::parserMetaData): (WebCore::Internals::isReadableStreamDisturbed): (WebCore::Internals::isGCRunning): (WebCore::Internals::addGCFinalizationCallback): (WebCore::Internals::stopSweeping): (WebCore::Internals::startSweeping): * testing/Internals.h: * testing/Internals.idl: Source/WTF: Extend the use of AbstractLocker so that we can use more locking idioms. * wtf/AutomaticThread.cpp: (WTF::AutomaticThreadCondition::notifyOne): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::tryStop): (WTF::AutomaticThread::isWaiting): (WTF::AutomaticThread::notify): (WTF::AutomaticThread::start): (WTF::AutomaticThread::threadIsStopping): * wtf/AutomaticThread.h: * wtf/NumberOfCores.cpp: (WTF::numberOfProcessorCores): * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::claimTask): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::hasClientWithTask): (WTF::ParallelHelperPool::getClientWithTask): * wtf/ParallelHelperPool.h: Tools: Make more tests collect continuously. * Scripts/run-jsc-stress-tests: Canonical link: https://commits.webkit.org/185692@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@212778 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-02-22 00:58:15 +00:00
auto stopForTimeout = [&] (const AbstractLocker& locker) {
stopImpl(locker);
WTF should make it easier to create threads that die automatically after inactivity https://bugs.webkit.org/show_bug.cgi?id=163576 Reviewed by Andreas Kling. Source/JavaScriptCore: Added a sleepSeconds() function, which made it easier for me to test this change. The WTF changes in this patch change how the JSC GC manages threads: the GC threads will now shut down automatically after 1 second of inactivity. Maybe this will save some memory. * jsc.cpp: (GlobalObject::finishCreation): (functionSleepSeconds): Source/WTF: For a long time now, I've been adding threads to WTF/JSC and each time I do this, I feel guilty because those threads don't shut down when they are inactive. For example, in bug 163562, I need to add a new GC thread. There will be one of them per VM. This means that a JSC API client that starts a lot of VMs will have a lot of threads. I don't think that's good. A common pattern for all of these threads is that they have some well-defined trigger that causes them to run. This trigger has a lock, a condition variable, some logic that determines if there is work to do, and then of course the logic for the thread's actual work. The thread bodies usually look like this: void Thingy::runThread() { for (;;) { Work work; { LockHolder locker(m_lock); while (!hasWork()) m_cond.wait(m_lock); work = takeWork(); } doWork(work); } } If you look at ParallelHelperPool (the GC's threads) and DFG::Worklist (some of the JIT's threads), you will see this pattern. This change adds a new kind of thread, called AutomaticThread, that lets you write threads to this pattern while getting automatic thread shutdown for free: instead of just waiting on a condition variable, AutomaticThread will have a timeout that causes the thread to die. The condition variable associated with AutomaticThread, called AutomaticThreadCondition, is smart enough to restart any threads that have decided to stop due to inactivity. The inactivity threshold is current just 1 second. In this patch I only adopt AutomaticThread for ParallelHelperPool. I plan to adopt it in more places soon. * WTF.xcodeproj/project.pbxproj: * wtf/AutomaticThread.cpp: Added. (WTF::AutomaticThreadCondition::create): (WTF::AutomaticThreadCondition::AutomaticThreadCondition): (WTF::AutomaticThreadCondition::~AutomaticThreadCondition): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Added. * wtf/CMakeLists.txt: * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::ParallelHelperPool): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::helperThreadBody): Deleted. (WTF::ParallelHelperPool::waitForClientWithTask): Deleted. * wtf/ParallelHelperPool.h: Canonical link: https://commits.webkit.org/181393@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207480 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-18 20:17:10 +00:00
};
for (;;) {
{
Replace LockHolder with Locker in local variables https://bugs.webkit.org/show_bug.cgi?id=226133 Reviewed by Darin Adler. Replace LockHolder with Locker in local variables. It is shorter and it allows switching the lock type more easily since the compiler with deduce the lock type T for Locker<T>. Source/JavaScriptCore: * API/JSCallbackObject.h: (JSC::JSCallbackObjectData::JSPrivatePropertyMap::setPrivateProperty): (JSC::JSCallbackObjectData::JSPrivatePropertyMap::deletePrivateProperty): (JSC::JSCallbackObjectData::JSPrivatePropertyMap::visitChildren): * API/JSValue.mm: (handerForStructTag): * API/tests/testapi.cpp: (testCAPIViaCpp): * assembler/testmasm.cpp: (JSC::run): * b3/air/testair.cpp: * b3/testb3_1.cpp: (run): * bytecode/DirectEvalCodeCache.cpp: (JSC::DirectEvalCodeCache::setSlow): (JSC::DirectEvalCodeCache::clear): (JSC::DirectEvalCodeCache::visitAggregateImpl): * bytecode/SuperSampler.cpp: (JSC::initializeSuperSampler): (JSC::resetSuperSamplerState): (JSC::printSuperSamplerState): (JSC::enableSuperSampler): (JSC::disableSuperSampler): * dfg/DFGCommonData.cpp: (JSC::DFG::CommonData::invalidate): (JSC::DFG::CommonData::~CommonData): (JSC::DFG::CommonData::installVMTrapBreakpoints): (JSC::DFG::codeBlockForVMTrapPC): * dfg/DFGPlan.cpp: (JSC::DFG::Plan::cleanMustHandleValuesIfNecessary): * dfg/DFGWorklist.cpp: (JSC::DFG::Worklist::~Worklist): (JSC::DFG::Worklist::finishCreation): (JSC::DFG::Worklist::isActiveForVM const): (JSC::DFG::Worklist::enqueue): (JSC::DFG::Worklist::compilationState): (JSC::DFG::Worklist::waitUntilAllPlansForVMAreReady): (JSC::DFG::Worklist::removeAllReadyPlansForVM): (JSC::DFG::Worklist::completeAllReadyPlansForVM): (JSC::DFG::Worklist::visitWeakReferences): (JSC::DFG::Worklist::removeDeadPlans): (JSC::DFG::Worklist::removeNonCompilingPlansForVM): (JSC::DFG::Worklist::queueLength): (JSC::DFG::Worklist::dump const): (JSC::DFG::Worklist::setNumberOfThreads): * dfg/DFGWorklistInlines.h: (JSC::DFG::Worklist::iterateCodeBlocksForGC): * disassembler/Disassembler.cpp: * heap/BlockDirectory.cpp: (JSC::BlockDirectory::addBlock): * heap/CodeBlockSetInlines.h: (JSC::CodeBlockSet::iterateCurrentlyExecuting): * heap/ConservativeRoots.cpp: (JSC::ConservativeRoots::add): * heap/Heap.cpp: (JSC::Heap::Heap): (JSC::Heap::lastChanceToFinalize): (JSC::Heap::collectAsync): (JSC::Heap::runBeginPhase): (JSC::Heap::waitForCollector): (JSC::Heap::requestCollection): (JSC::Heap::notifyIsSafeToCollect): * heap/SlotVisitor.cpp: (JSC::SlotVisitor::didReachTermination): * inspector/agents/InspectorScriptProfilerAgent.cpp: (Inspector::InspectorScriptProfilerAgent::startTracking): (Inspector::InspectorScriptProfilerAgent::trackingComplete): (Inspector::InspectorScriptProfilerAgent::stopSamplingWhenDisconnecting): * inspector/remote/RemoteConnectionToTarget.cpp: (Inspector::RemoteConnectionToTarget::setup): (Inspector::RemoteConnectionToTarget::sendMessageToTarget): (Inspector::RemoteConnectionToTarget::close): (Inspector::RemoteConnectionToTarget::targetClosed): * inspector/remote/RemoteInspector.cpp: (Inspector::RemoteInspector::registerTarget): (Inspector::RemoteInspector::unregisterTarget): (Inspector::RemoteInspector::updateTarget): (Inspector::RemoteInspector::updateClientCapabilities): (Inspector::RemoteInspector::setClient): (Inspector::RemoteInspector::setupFailed): (Inspector::RemoteInspector::setupCompleted): (Inspector::RemoteInspector::stop): * inspector/remote/cocoa/RemoteConnectionToTargetCocoa.mm: (Inspector::RemoteTargetHandleRunSourceGlobal): (Inspector::RemoteTargetQueueTaskOnGlobalQueue): (Inspector::RemoteTargetHandleRunSourceWithInfo): (Inspector::RemoteConnectionToTarget::setup): (Inspector::RemoteConnectionToTarget::targetClosed): (Inspector::RemoteConnectionToTarget::close): (Inspector::RemoteConnectionToTarget::sendMessageToTarget): (Inspector::RemoteConnectionToTarget::queueTaskOnPrivateRunLoop): * inspector/remote/cocoa/RemoteInspectorCocoa.mm: (Inspector::RemoteInspector::updateAutomaticInspectionCandidate): (Inspector::RemoteInspector::sendMessageToRemote): (Inspector::RemoteInspector::start): (Inspector::RemoteInspector::setupXPCConnectionIfNeeded): (Inspector::RemoteInspector::setParentProcessInformation): (Inspector::RemoteInspector::xpcConnectionReceivedMessage): (Inspector::RemoteInspector::xpcConnectionFailed): (Inspector::RemoteInspector::pushListingsSoon): (Inspector::RemoteInspector::receivedIndicateMessage): (Inspector::RemoteInspector::receivedProxyApplicationSetupMessage): * inspector/remote/cocoa/RemoteInspectorXPCConnection.mm: (Inspector::RemoteInspectorXPCConnection::close): (Inspector::RemoteInspectorXPCConnection::closeFromMessage): (Inspector::RemoteInspectorXPCConnection::deserializeMessage): (Inspector::RemoteInspectorXPCConnection::handleEvent): * inspector/remote/glib/RemoteInspectorGlib.cpp: (Inspector::RemoteInspector::start): (Inspector::RemoteInspector::setupConnection): (Inspector::RemoteInspector::pushListingsSoon): (Inspector::RemoteInspector::sendMessageToRemote): (Inspector::RemoteInspector::receivedGetTargetListMessage): (Inspector::RemoteInspector::receivedDataMessage): (Inspector::RemoteInspector::receivedCloseMessage): (Inspector::RemoteInspector::setup): * inspector/remote/socket/RemoteInspectorConnectionClient.cpp: (Inspector::RemoteInspectorConnectionClient::didReceive): * inspector/remote/socket/RemoteInspectorSocket.cpp: (Inspector::RemoteInspector::didClose): (Inspector::RemoteInspector::start): (Inspector::RemoteInspector::pushListingsSoon): (Inspector::RemoteInspector::setup): (Inspector::RemoteInspector::setupInspectorClient): (Inspector::RemoteInspector::frontendDidClose): (Inspector::RemoteInspector::sendMessageToBackend): (Inspector::RemoteInspector::startAutomationSession): * inspector/remote/socket/RemoteInspectorSocketEndpoint.cpp: (Inspector::RemoteInspectorSocketEndpoint::listenInet): (Inspector::RemoteInspectorSocketEndpoint::isListening): (Inspector::RemoteInspectorSocketEndpoint::workerThread): (Inspector::RemoteInspectorSocketEndpoint::createClient): (Inspector::RemoteInspectorSocketEndpoint::disconnect): (Inspector::RemoteInspectorSocketEndpoint::invalidateClient): (Inspector::RemoteInspectorSocketEndpoint::invalidateListener): (Inspector::RemoteInspectorSocketEndpoint::getPort const): (Inspector::RemoteInspectorSocketEndpoint::recvIfEnabled): (Inspector::RemoteInspectorSocketEndpoint::sendIfEnabled): (Inspector::RemoteInspectorSocketEndpoint::send): (Inspector::RemoteInspectorSocketEndpoint::acceptInetSocketIfEnabled): * interpreter/CLoopStack.cpp: (JSC::CLoopStack::addToCommittedByteCount): (JSC::CLoopStack::committedByteCount): * jit/ExecutableAllocator.cpp: (JSC::dumpJITMemory): * jit/ICStats.cpp: (JSC::ICStats::ICStats): (JSC::ICStats::~ICStats): * jit/JITThunks.cpp: (JSC::JITThunks::ctiStub): (JSC::JITThunks::existingCTIStub): (JSC::JITThunks::ctiSlowPathFunctionStub): * jit/JITWorklist.cpp: (JSC::JITWorklist::Plan::compileInThread): (JSC::JITWorklist::Plan::isFinishedCompiling): (JSC::JITWorklist::JITWorklist): (JSC::JITWorklist::completeAllForVM): (JSC::JITWorklist::poll): (JSC::JITWorklist::compileLater): (JSC::JITWorklist::finalizePlans): * parser/SourceProvider.cpp: (JSC::SourceProvider::getID): * profiler/ProfilerDatabase.cpp: (JSC::Profiler::Database::ensureBytecodesFor): (JSC::Profiler::Database::notifyDestruction): (JSC::Profiler::Database::addCompilation): (JSC::Profiler::Database::logEvent): (JSC::Profiler::Database::addDatabaseToAtExit): (JSC::Profiler::Database::removeDatabaseFromAtExit): (JSC::Profiler::Database::removeFirstAtExitDatabase): * profiler/ProfilerUID.cpp: (JSC::Profiler::UID::create): * runtime/DeferredWorkTimer.cpp: (JSC::DeferredWorkTimer::scheduleWorkSoon): (JSC::DeferredWorkTimer::didResumeScriptExecutionOwner): * runtime/SamplingProfiler.cpp: (JSC::SamplingProfiler::timerLoop): (JSC::SamplingProfiler::shutdown): (JSC::SamplingProfiler::start): (JSC::SamplingProfiler::noticeCurrentThreadAsJSCExecutionThread): (JSC::SamplingProfiler::noticeJSLockAcquisition): (JSC::SamplingProfiler::noticeVMEntry): (JSC::SamplingProfiler::registerForReportAtExit): * runtime/Watchdog.cpp: (JSC::Watchdog::startTimer): (JSC::Watchdog::willDestroyVM): * tools/VMInspector.cpp: (JSC::VMInspector::isValidExecutableMemory): * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::work): * wasm/WasmEntryPlan.cpp: (JSC::Wasm::EntryPlan::ThreadCountHolder::ThreadCountHolder): (JSC::Wasm::EntryPlan::ThreadCountHolder::~ThreadCountHolder): * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::work): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::addCompletionTask): (JSC::Wasm::Plan::waitForCompletion): (JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast): * wasm/WasmSignature.cpp: (JSC::Wasm::SignatureInformation::signatureFor): (JSC::Wasm::SignatureInformation::tryCleanup): * wasm/WasmWorklist.cpp: (JSC::Wasm::Worklist::enqueue): (JSC::Wasm::Worklist::completePlanSynchronously): (JSC::Wasm::Worklist::stopAllPlansForContext): (JSC::Wasm::Worklist::Worklist): (JSC::Wasm::Worklist::~Worklist): Source/WebCore: * Modules/webaudio/AsyncAudioDecoder.cpp: (WebCore::AsyncAudioDecoder::AsyncAudioDecoder): (WebCore::AsyncAudioDecoder::runLoop): * Modules/webdatabase/Database.cpp: (WebCore::Database::performClose): (WebCore::Database::inProgressTransactionCompleted): (WebCore::Database::hasPendingTransaction): (WebCore::Database::runTransaction): * Modules/webdatabase/DatabaseThread.cpp: (WebCore::DatabaseThread::start): (WebCore::DatabaseThread::databaseThread): (WebCore::DatabaseThread::recordDatabaseOpen): (WebCore::DatabaseThread::recordDatabaseClosed): (WebCore::DatabaseThread::hasPendingDatabaseActivity const): * Modules/webdatabase/DatabaseTracker.cpp: (WebCore::DatabaseTracker::canEstablishDatabase): (WebCore::DatabaseTracker::retryCanEstablishDatabase): (WebCore::DatabaseTracker::maximumSize): (WebCore::DatabaseTracker::fullPathForDatabase): (WebCore::DatabaseTracker::origins): (WebCore::DatabaseTracker::databaseNames): (WebCore::DatabaseTracker::detailsForNameAndOrigin): (WebCore::DatabaseTracker::setDatabaseDetails): (WebCore::DatabaseTracker::doneCreatingDatabase): (WebCore::DatabaseTracker::openDatabases): (WebCore::DatabaseTracker::addOpenDatabase): (WebCore::DatabaseTracker::removeOpenDatabase): (WebCore::DatabaseTracker::originLockFor): (WebCore::DatabaseTracker::quota): (WebCore::DatabaseTracker::setQuota): (WebCore::DatabaseTracker::deleteOrigin): (WebCore::DatabaseTracker::deleteDatabase): (WebCore::DatabaseTracker::deleteDatabaseFile): (WebCore::DatabaseTracker::removeDeletedOpenedDatabases): * Modules/webdatabase/SQLCallbackWrapper.h: (WebCore::SQLCallbackWrapper::clear): (WebCore::SQLCallbackWrapper::unwrap): * Modules/webdatabase/SQLTransaction.cpp: (WebCore::SQLTransaction::enqueueStatement): (WebCore::SQLTransaction::checkAndHandleClosedDatabase): (WebCore::SQLTransaction::getNextStatement): * Modules/webdatabase/SQLTransactionBackend.cpp: (WebCore::SQLTransactionBackend::doCleanup): * accessibility/isolatedtree/AXIsolatedTree.cpp: (WebCore::AXIsolatedTree::clear): (WebCore::AXIsolatedTree::generateSubtree): (WebCore::AXIsolatedTree::createSubtree): (WebCore::AXIsolatedTree::updateNode): (WebCore::AXIsolatedTree::updateNodeProperty): (WebCore::AXIsolatedTree::updateChildren): (WebCore::AXIsolatedTree::focusedNode): (WebCore::AXIsolatedTree::rootNode): (WebCore::AXIsolatedTree::setFocusedNodeID): (WebCore::AXIsolatedTree::removeNode): (WebCore::AXIsolatedTree::removeSubtree): (WebCore::AXIsolatedTree::applyPendingChanges): * page/scrolling/mac/ScrollingTreeMac.mm: (ScrollingTreeMac::scrollingNodeForPoint): (ScrollingTreeMac::eventListenerRegionTypesForPoint const): * platform/AbortableTaskQueue.h: * platform/audio/cocoa/CARingBuffer.cpp: (WebCore::CARingBufferStorageVector::flush): (WebCore::CARingBufferStorageVector::setCurrentFrameBounds): * platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp: (WebCore::AVFWrapper::addToMap): (WebCore::AVFWrapper::removeFromMap const): (WebCore::AVFWrapper::periodicTimeObserverCallback): (WebCore::AVFWrapper::processNotification): (WebCore::AVFWrapper::loadPlayableCompletionCallback): (WebCore::AVFWrapper::loadMetadataCompletionCallback): (WebCore::AVFWrapper::seekCompletedCallback): (WebCore::AVFWrapper::processCue): (WebCore::AVFWrapper::legibleOutputCallback): (WebCore::AVFWrapper::processShouldWaitForLoadingOfResource): (WebCore::AVFWrapper::resourceLoaderShouldWaitForLoadingOfRequestedResource): * platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.mm: (-[WebCoreSharedBufferResourceLoaderDelegate setExpectedContentSize:]): (-[WebCoreSharedBufferResourceLoaderDelegate updateData:complete:]): (-[WebCoreSharedBufferResourceLoaderDelegate resourceLoader:shouldWaitForLoadingOfRequestedResource:]): (-[WebCoreSharedBufferResourceLoaderDelegate resourceLoader:didCancelLoadingRequest:]): (WebCore::ImageDecoderAVFObjC::setTrack): (WebCore::ImageDecoderAVFObjC::createFrameImageAtIndex): * platform/graphics/gstreamer/ImageDecoderGStreamer.cpp: (WebCore::ImageDecoderGStreamer::createFrameImageAtIndex): * platform/graphics/gstreamer/InbandTextTrackPrivateGStreamer.cpp: (WebCore::InbandTextTrackPrivateGStreamer::handleSample): (WebCore::InbandTextTrackPrivateGStreamer::notifyTrackOfSample): * platform/graphics/gstreamer/MainThreadNotifier.h: * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::parseInitDataFromProtectionMessage): (WebCore::MediaPlayerPrivateGStreamer::handleProtectionEvent): * platform/graphics/gstreamer/TrackPrivateBaseGStreamer.cpp: (WebCore::TrackPrivateBaseGStreamer::tagsChanged): (WebCore::TrackPrivateBaseGStreamer::notifyTrackOfTagsChanged): * platform/graphics/gstreamer/VideoSinkGStreamer.cpp: (VideoRenderRequestScheduler::start): (VideoRenderRequestScheduler::stop): (VideoRenderRequestScheduler::drain): (VideoRenderRequestScheduler::requestRender): * platform/graphics/gstreamer/eme/WebKitCommonEncryptionDecryptorGStreamer.cpp: (transformInPlace): (sinkEventHandler): (webKitMediaCommonEncryptionDecryptIsFlushing): (setContext): * platform/graphics/nicosia/NicosiaBuffer.cpp: (Nicosia::Buffer::beginPainting): (Nicosia::Buffer::completePainting): (Nicosia::Buffer::waitUntilPaintingComplete): * platform/graphics/nicosia/NicosiaPlatformLayer.h: (Nicosia::PlatformLayer::setSceneIntegration): (Nicosia::PlatformLayer::createUpdateScope): (Nicosia::CompositionLayer::updateState): (Nicosia::CompositionLayer::flushState): (Nicosia::CompositionLayer::commitState): (Nicosia::CompositionLayer::accessPending): (Nicosia::CompositionLayer::accessCommitted): * platform/graphics/nicosia/NicosiaScene.h: (Nicosia::Scene::accessState): * platform/graphics/nicosia/NicosiaSceneIntegration.cpp: (Nicosia::SceneIntegration::setClient): (Nicosia::SceneIntegration::invalidate): (Nicosia::SceneIntegration::requestUpdate): * platform/graphics/nicosia/texmap/NicosiaBackingStoreTextureMapperImpl.cpp: (Nicosia::BackingStoreTextureMapperImpl::flushUpdate): (Nicosia::BackingStoreTextureMapperImpl::takeUpdate): * platform/graphics/nicosia/texmap/NicosiaContentLayerTextureMapperImpl.cpp: (Nicosia::ContentLayerTextureMapperImpl::~ContentLayerTextureMapperImpl): (Nicosia::ContentLayerTextureMapperImpl::invalidateClient): (Nicosia::ContentLayerTextureMapperImpl::flushUpdate): (Nicosia::ContentLayerTextureMapperImpl::swapBuffersIfNeeded): * platform/graphics/nicosia/texmap/NicosiaImageBackingTextureMapperImpl.cpp: (Nicosia::ImageBackingTextureMapperImpl::flushUpdate): (Nicosia::ImageBackingTextureMapperImpl::takeUpdate): * platform/graphics/texmap/TextureMapperGCGLPlatformLayer.cpp: (WebCore::TextureMapperGCGLPlatformLayer::swapBuffersIfNeeded): * platform/graphics/win/MediaPlayerPrivateMediaFoundation.cpp: (WebCore::MediaPlayerPrivateMediaFoundation::load): (WebCore::MediaPlayerPrivateMediaFoundation::naturalSize const): (WebCore::MediaPlayerPrivateMediaFoundation::addListener): (WebCore::MediaPlayerPrivateMediaFoundation::removeListener): (WebCore::MediaPlayerPrivateMediaFoundation::notifyDeleted): (WebCore::MediaPlayerPrivateMediaFoundation::setNaturalSize): (WebCore::MediaPlayerPrivateMediaFoundation::AsyncCallback::Invoke): (WebCore::MediaPlayerPrivateMediaFoundation::AsyncCallback::onMediaPlayerDeleted): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::OnClockStart): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::OnClockStop): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::OnClockPause): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::OnClockRestart): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::OnClockSetRate): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::ProcessMessage): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::GetCurrentMediaType): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::InitServicePointers): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::ReleaseServicePointers): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::SetVideoWindow): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::GetVideoWindow): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::SetVideoPosition): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::GetVideoPosition): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::RepaintVideo): (WebCore::MediaPlayerPrivateMediaFoundation::VideoSamplePool::getSample): (WebCore::MediaPlayerPrivateMediaFoundation::VideoSamplePool::returnSample): (WebCore::MediaPlayerPrivateMediaFoundation::VideoSamplePool::areSamplesPending): (WebCore::MediaPlayerPrivateMediaFoundation::VideoSamplePool::initialize): (WebCore::MediaPlayerPrivateMediaFoundation::VideoSamplePool::clear): (WebCore::MediaPlayerPrivateMediaFoundation::VideoScheduler::stopScheduler): (WebCore::MediaPlayerPrivateMediaFoundation::VideoScheduler::scheduleSample): (WebCore::MediaPlayerPrivateMediaFoundation::VideoScheduler::processSamplesInQueue): (WebCore::MediaPlayerPrivateMediaFoundation::VideoScheduler::processSample): (WebCore::MediaPlayerPrivateMediaFoundation::VideoScheduler::schedulerThreadProcPrivate): (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::setVideoWindow): (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::setDestinationRect): (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::createVideoSamples): (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::checkDeviceState): (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::presentSample): (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::paintCurrentFrame): (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::createD3DDevice): * platform/image-decoders/ScalableImageDecoder.cpp: (WebCore::ScalableImageDecoder::frameIsCompleteAtIndex const): (WebCore::ScalableImageDecoder::frameHasAlphaAtIndex const): (WebCore::ScalableImageDecoder::frameBytesAtIndex const): (WebCore::ScalableImageDecoder::frameDurationAtIndex const): (WebCore::ScalableImageDecoder::createFrameImageAtIndex): * platform/image-decoders/ScalableImageDecoder.h: * platform/ios/LegacyTileCache.mm: (WebCore::LegacyTileCache::setTilesOpaque): (WebCore::LegacyTileCache::doLayoutTiles): (WebCore::LegacyTileCache::setCurrentScale): (WebCore::LegacyTileCache::commitScaleChange): (WebCore::LegacyTileCache::layoutTilesNow): (WebCore::LegacyTileCache::layoutTilesNowForRect): (WebCore::LegacyTileCache::removeAllNonVisibleTiles): (WebCore::LegacyTileCache::removeAllTiles): (WebCore::LegacyTileCache::removeForegroundTiles): (WebCore::LegacyTileCache::setContentReplacementImage): (WebCore::LegacyTileCache::contentReplacementImage const): (WebCore::LegacyTileCache::tileCreationTimerFired): (WebCore::LegacyTileCache::setNeedsDisplayInRect): (WebCore::LegacyTileCache::updateTilingMode): (WebCore::LegacyTileCache::setTilingMode): (WebCore::LegacyTileCache::doPendingRepaints): (WebCore::LegacyTileCache::flushSavedDisplayRects): (WebCore::LegacyTileCache::prepareToDraw): * platform/ios/LegacyTileLayerPool.mm: (WebCore::LegacyTileLayerPool::addLayer): (WebCore::LegacyTileLayerPool::takeLayerWithSize): (WebCore::LegacyTileLayerPool::setCapacity): (WebCore::LegacyTileLayerPool::prune): (WebCore::LegacyTileLayerPool::drain): * platform/ios/wak/WAKWindow.mm: (-[WAKWindow setExposedScrollViewRect:]): (-[WAKWindow exposedScrollViewRect]): * platform/ios/wak/WebCoreThread.mm: (RunWebThread): (StartWebThread): * platform/mediastream/gstreamer/RealtimeOutgoingAudioSourceLibWebRTC.cpp: (WebCore::RealtimeOutgoingAudioSourceLibWebRTC::audioSamplesAvailable): (WebCore::RealtimeOutgoingAudioSourceLibWebRTC::pullAudioData): * platform/network/cf/FormDataStreamCFNet.cpp: (WebCore::openNextStream): (WebCore::formFinalize): (WebCore::formClose): * platform/network/curl/CurlRequest.cpp: (WebCore::CurlRequest::setRequestPaused): (WebCore::CurlRequest::setCallbackPaused): (WebCore::CurlRequest::pausedStatusChanged): (WebCore::CurlRequest::enableDownloadToFile): (WebCore::CurlRequest::getDownloadedFilePath): (WebCore::CurlRequest::writeDataToDownloadFileIfEnabled): (WebCore::CurlRequest::closeDownloadFile): (WebCore::CurlRequest::cleanupDownloadFile): * platform/network/curl/CurlSSLHandle.cpp: (WebCore::CurlSSLHandle::allowAnyHTTPSCertificatesForHost): (WebCore::CurlSSLHandle::canIgnoreAnyHTTPSCertificatesForHost const): (WebCore::CurlSSLHandle::setClientCertificateInfo): (WebCore::CurlSSLHandle::getSSLClientCertificate const): * platform/sql/SQLiteDatabase.cpp: (WebCore::SQLiteDatabase::close): (WebCore::SQLiteDatabase::maximumSize): (WebCore::SQLiteDatabase::setMaximumSize): (WebCore::SQLiteDatabase::pageSize): (WebCore::SQLiteDatabase::freeSpaceSize): (WebCore::SQLiteDatabase::totalSize): (WebCore::SQLiteDatabase::runIncrementalVacuumCommand): (WebCore::SQLiteDatabase::interrupt): (WebCore::SQLiteDatabase::setAuthorizer): (WebCore::constructAndPrepareStatement): * platform/sql/SQLiteStatement.cpp: (WebCore::SQLiteStatement::step): Source/WebKit: * NetworkProcess/IndexedDB/WebIDBServer.cpp: (WebKit::m_closeCallback): (WebKit::WebIDBServer::getOrigins): (WebKit::WebIDBServer::closeAndDeleteDatabasesModifiedSince): (WebKit::WebIDBServer::closeAndDeleteDatabasesForOrigins): (WebKit::WebIDBServer::renameOrigin): (WebKit::WebIDBServer::openDatabase): (WebKit::WebIDBServer::deleteDatabase): (WebKit::WebIDBServer::abortTransaction): (WebKit::WebIDBServer::commitTransaction): (WebKit::WebIDBServer::didFinishHandlingVersionChangeTransaction): (WebKit::WebIDBServer::createObjectStore): (WebKit::WebIDBServer::deleteObjectStore): (WebKit::WebIDBServer::renameObjectStore): (WebKit::WebIDBServer::clearObjectStore): (WebKit::WebIDBServer::createIndex): (WebKit::WebIDBServer::deleteIndex): (WebKit::WebIDBServer::renameIndex): (WebKit::WebIDBServer::putOrAdd): (WebKit::WebIDBServer::getRecord): (WebKit::WebIDBServer::getAllRecords): (WebKit::WebIDBServer::getCount): (WebKit::WebIDBServer::deleteRecord): (WebKit::WebIDBServer::openCursor): (WebKit::WebIDBServer::iterateCursor): (WebKit::WebIDBServer::establishTransaction): (WebKit::WebIDBServer::databaseConnectionPendingClose): (WebKit::WebIDBServer::databaseConnectionClosed): (WebKit::WebIDBServer::abortOpenAndUpgradeNeeded): (WebKit::WebIDBServer::didFireVersionChangeEvent): (WebKit::WebIDBServer::openDBRequestCancelled): (WebKit::WebIDBServer::getAllDatabaseNamesAndVersions): (WebKit::WebIDBServer::addConnection): (WebKit::WebIDBServer::removeConnection): (WebKit::WebIDBServer::close): * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::writeSizeFile): (WebKit::CacheStorage::Engine::readSizeFile): (WebKit::CacheStorage::Engine::clearAllCachesFromDisk): (WebKit::CacheStorage::Engine::deleteNonEmptyDirectoryOnBackgroundThread): * NetworkProcess/glib/DNSCache.cpp: (WebKit::DNSCache::lookup): (WebKit::DNSCache::update): (WebKit::DNSCache::removeExpiredResponsesFired): (WebKit::DNSCache::clear): * Shared/CoordinatedGraphics/threadedcompositor/CompositingRunLoop.cpp: (WebKit::CompositingRunLoop::suspend): (WebKit::CompositingRunLoop::resume): (WebKit::CompositingRunLoop::scheduleUpdate): (WebKit::CompositingRunLoop::stopUpdates): (WebKit::CompositingRunLoop::updateTimerFired): * Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp: (WebKit::m_displayRefreshMonitor): (WebKit::ThreadedCompositor::setScaleFactor): (WebKit::ThreadedCompositor::setScrollPosition): (WebKit::ThreadedCompositor::setViewportSize): (WebKit::ThreadedCompositor::renderLayerTree): (WebKit::ThreadedCompositor::sceneUpdateFinished): (WebKit::ThreadedCompositor::updateSceneState): * UIProcess/API/glib/IconDatabase.cpp: (WebKit::IconDatabase::populatePageURLToIconURLMap): (WebKit::IconDatabase::clearLoadedIconsTimerFired): (WebKit::IconDatabase::checkIconURLAndSetPageURLIfNeeded): (WebKit::IconDatabase::loadIconForPageURL): (WebKit::IconDatabase::iconURLForPageURL): (WebKit::IconDatabase::setIconForPageURL): (WebKit::IconDatabase::clear): Source/WebKitLegacy: * Storage/InProcessIDBServer.cpp: (InProcessIDBServer::InProcessIDBServer): (InProcessIDBServer::deleteDatabase): (InProcessIDBServer::openDatabase): (InProcessIDBServer::abortTransaction): (InProcessIDBServer::commitTransaction): (InProcessIDBServer::didFinishHandlingVersionChangeTransaction): (InProcessIDBServer::createObjectStore): (InProcessIDBServer::deleteObjectStore): (InProcessIDBServer::renameObjectStore): (InProcessIDBServer::clearObjectStore): (InProcessIDBServer::createIndex): (InProcessIDBServer::deleteIndex): (InProcessIDBServer::renameIndex): (InProcessIDBServer::putOrAdd): (InProcessIDBServer::getRecord): (InProcessIDBServer::getAllRecords): (InProcessIDBServer::getCount): (InProcessIDBServer::deleteRecord): (InProcessIDBServer::openCursor): (InProcessIDBServer::iterateCursor): (InProcessIDBServer::establishTransaction): (InProcessIDBServer::databaseConnectionPendingClose): (InProcessIDBServer::databaseConnectionClosed): (InProcessIDBServer::abortOpenAndUpgradeNeeded): (InProcessIDBServer::didFireVersionChangeEvent): (InProcessIDBServer::openDBRequestCancelled): (InProcessIDBServer::getAllDatabaseNamesAndVersions): (InProcessIDBServer::closeAndDeleteDatabasesModifiedSince): * Storage/StorageAreaSync.cpp: (WebKit::StorageAreaSync::syncTimerFired): (WebKit::StorageAreaSync::performSync): * Storage/StorageTracker.cpp: (WebKit::StorageTracker::finishedImportingOriginIdentifiers): (WebKit::StorageTracker::syncImportOriginIdentifiers): (WebKit::StorageTracker::syncFileSystemAndTrackerDatabase): (WebKit::StorageTracker::setOriginDetails): (WebKit::StorageTracker::syncSetOriginDetails): (WebKit::StorageTracker::origins): (WebKit::StorageTracker::deleteAllOrigins): (WebKit::StorageTracker::syncDeleteAllOrigins): (WebKit::StorageTracker::deleteOrigin): (WebKit::StorageTracker::syncDeleteOrigin): (WebKit::StorageTracker::canDeleteOrigin): (WebKit::StorageTracker::cancelDeletingOrigin): (WebKit::StorageTracker::diskUsageForOrigin): Source/WebKitLegacy/mac: * WebView/WebView.mm: (-[WebView _synchronizeCustomFixedPositionLayoutRect]): (-[WebView _setCustomFixedPositionLayoutRectInWebThread:synchronize:]): (-[WebView _setCustomFixedPositionLayoutRect:]): (-[WebView _fetchCustomFixedPositionLayoutRect:]): Source/WebKitLegacy/win: * Plugins/PluginMainThreadScheduler.cpp: (WebCore::PluginMainThreadScheduler::scheduleCall): (WebCore::PluginMainThreadScheduler::registerPlugin): (WebCore::PluginMainThreadScheduler::unregisterPlugin): (WebCore::PluginMainThreadScheduler::dispatchCallsForPlugin): Source/WTF: * benchmarks/LockSpeedTest.cpp: * wtf/AutomaticThread.cpp: (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: * wtf/MetaAllocator.cpp: (WTF::MetaAllocatorHandle::shrink): (WTF::MetaAllocator::addFreshFreeSpace): (WTF::MetaAllocator::debugFreeSpaceSize): * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): * wtf/Seconds.cpp: (WTF::sleep): * wtf/TimeWithDynamicClockType.cpp: (WTF::sleep): * wtf/WorkerPool.cpp: (WTF::WorkerPool::WorkerPool): (WTF::WorkerPool::~WorkerPool): (WTF::WorkerPool::postTask): * wtf/posix/ThreadingPOSIX.cpp: (WTF::Thread::suspend): (WTF::Thread::resume): (WTF::Thread::getRegisters): * wtf/win/DbgHelperWin.cpp: (WTF::DbgHelper::SymFromAddress): * wtf/win/ThreadingWin.cpp: (WTF::Thread::suspend): (WTF::Thread::resume): (WTF::Thread::getRegisters): Tools: * TestWebKitAPI/Tests/WTF/WorkQueue.cpp: (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/WTF/glib/WorkQueueGLib.cpp: (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/WebCore/AbortableTaskQueue.cpp: (TestWebKitAPI::DeterministicScheduler::ThreadContext::waitMyTurn): (TestWebKitAPI::DeterministicScheduler::ThreadContext::yieldToThread): Canonical link: https://commits.webkit.org/238053@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@277920 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-05-22 16:49:42 +00:00
Locker locker { *m_lock };
WTF should make it easier to create threads that die automatically after inactivity https://bugs.webkit.org/show_bug.cgi?id=163576 Reviewed by Andreas Kling. Source/JavaScriptCore: Added a sleepSeconds() function, which made it easier for me to test this change. The WTF changes in this patch change how the JSC GC manages threads: the GC threads will now shut down automatically after 1 second of inactivity. Maybe this will save some memory. * jsc.cpp: (GlobalObject::finishCreation): (functionSleepSeconds): Source/WTF: For a long time now, I've been adding threads to WTF/JSC and each time I do this, I feel guilty because those threads don't shut down when they are inactive. For example, in bug 163562, I need to add a new GC thread. There will be one of them per VM. This means that a JSC API client that starts a lot of VMs will have a lot of threads. I don't think that's good. A common pattern for all of these threads is that they have some well-defined trigger that causes them to run. This trigger has a lock, a condition variable, some logic that determines if there is work to do, and then of course the logic for the thread's actual work. The thread bodies usually look like this: void Thingy::runThread() { for (;;) { Work work; { LockHolder locker(m_lock); while (!hasWork()) m_cond.wait(m_lock); work = takeWork(); } doWork(work); } } If you look at ParallelHelperPool (the GC's threads) and DFG::Worklist (some of the JIT's threads), you will see this pattern. This change adds a new kind of thread, called AutomaticThread, that lets you write threads to this pattern while getting automatic thread shutdown for free: instead of just waiting on a condition variable, AutomaticThread will have a timeout that causes the thread to die. The condition variable associated with AutomaticThread, called AutomaticThreadCondition, is smart enough to restart any threads that have decided to stop due to inactivity. The inactivity threshold is current just 1 second. In this patch I only adopt AutomaticThread for ParallelHelperPool. I plan to adopt it in more places soon. * WTF.xcodeproj/project.pbxproj: * wtf/AutomaticThread.cpp: Added. (WTF::AutomaticThreadCondition::create): (WTF::AutomaticThreadCondition::AutomaticThreadCondition): (WTF::AutomaticThreadCondition::~AutomaticThreadCondition): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Added. * wtf/CMakeLists.txt: * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::ParallelHelperPool): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::helperThreadBody): Deleted. (WTF::ParallelHelperPool::waitForClientWithTask): Deleted. * wtf/ParallelHelperPool.h: Canonical link: https://commits.webkit.org/181393@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207480 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-18 20:17:10 +00:00
for (;;) {
PollResult result = poll(locker);
if (result == PollResult::Work)
break;
if (result == PollResult::Stop)
return stopPermanently(locker);
WTF should make it easier to create threads that die automatically after inactivity https://bugs.webkit.org/show_bug.cgi?id=163576 Reviewed by Andreas Kling. Source/JavaScriptCore: Added a sleepSeconds() function, which made it easier for me to test this change. The WTF changes in this patch change how the JSC GC manages threads: the GC threads will now shut down automatically after 1 second of inactivity. Maybe this will save some memory. * jsc.cpp: (GlobalObject::finishCreation): (functionSleepSeconds): Source/WTF: For a long time now, I've been adding threads to WTF/JSC and each time I do this, I feel guilty because those threads don't shut down when they are inactive. For example, in bug 163562, I need to add a new GC thread. There will be one of them per VM. This means that a JSC API client that starts a lot of VMs will have a lot of threads. I don't think that's good. A common pattern for all of these threads is that they have some well-defined trigger that causes them to run. This trigger has a lock, a condition variable, some logic that determines if there is work to do, and then of course the logic for the thread's actual work. The thread bodies usually look like this: void Thingy::runThread() { for (;;) { Work work; { LockHolder locker(m_lock); while (!hasWork()) m_cond.wait(m_lock); work = takeWork(); } doWork(work); } } If you look at ParallelHelperPool (the GC's threads) and DFG::Worklist (some of the JIT's threads), you will see this pattern. This change adds a new kind of thread, called AutomaticThread, that lets you write threads to this pattern while getting automatic thread shutdown for free: instead of just waiting on a condition variable, AutomaticThread will have a timeout that causes the thread to die. The condition variable associated with AutomaticThread, called AutomaticThreadCondition, is smart enough to restart any threads that have decided to stop due to inactivity. The inactivity threshold is current just 1 second. In this patch I only adopt AutomaticThread for ParallelHelperPool. I plan to adopt it in more places soon. * WTF.xcodeproj/project.pbxproj: * wtf/AutomaticThread.cpp: Added. (WTF::AutomaticThreadCondition::create): (WTF::AutomaticThreadCondition::AutomaticThreadCondition): (WTF::AutomaticThreadCondition::~AutomaticThreadCondition): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Added. * wtf/CMakeLists.txt: * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::ParallelHelperPool): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::helperThreadBody): Deleted. (WTF::ParallelHelperPool::waitForClientWithTask): Deleted. * wtf/ParallelHelperPool.h: Canonical link: https://commits.webkit.org/181393@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207480 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-18 20:17:10 +00:00
RELEASE_ASSERT(result == PollResult::Wait);
// Shut the thread down after a timeout.
REGRESSION: HipChat and Mail sometimes hang beneath JSC::Heap::lastChanceToFinalize() https://bugs.webkit.org/show_bug.cgi?id=165962 Reviewed by Filip Pizlo. There is an inherent race in Condition::waitFor() where the timeout can happen just before a notify from another thread. Fixed this by adding a condition variable and flag to each AutomaticThread. The flag is used to signify to a notifying thread that the thread is waiting. That flag is set in the waiting thread before calling waitFor() and cleared by another thread when it notifies the thread. The access to that flag happens when the lock is held. Now the waiting thread checks if the flag after a timeout to see that it in fact should proceed like a normal notification. The added condition variable allows us to target a specific thread. We used to keep a list of waiting threads, now we keep a list of all threads. To notify one thread, we look for a waiting thread and notify it directly. If we can't find a waiting thread, we start a sleeping thread. We notify all threads by waking all waiting threads and starting all sleeping threads. * wtf/AutomaticThread.cpp: (WTF::AutomaticThreadCondition::notifyOne): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThread::isWaiting): (WTF::AutomaticThread::notify): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Canonical link: https://commits.webkit.org/183569@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@209938 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-12-16 22:26:09 +00:00
m_isWaiting = true;
WTF should make it easier to create threads that die automatically after inactivity https://bugs.webkit.org/show_bug.cgi?id=163576 Reviewed by Andreas Kling. Source/JavaScriptCore: Added a sleepSeconds() function, which made it easier for me to test this change. The WTF changes in this patch change how the JSC GC manages threads: the GC threads will now shut down automatically after 1 second of inactivity. Maybe this will save some memory. * jsc.cpp: (GlobalObject::finishCreation): (functionSleepSeconds): Source/WTF: For a long time now, I've been adding threads to WTF/JSC and each time I do this, I feel guilty because those threads don't shut down when they are inactive. For example, in bug 163562, I need to add a new GC thread. There will be one of them per VM. This means that a JSC API client that starts a lot of VMs will have a lot of threads. I don't think that's good. A common pattern for all of these threads is that they have some well-defined trigger that causes them to run. This trigger has a lock, a condition variable, some logic that determines if there is work to do, and then of course the logic for the thread's actual work. The thread bodies usually look like this: void Thingy::runThread() { for (;;) { Work work; { LockHolder locker(m_lock); while (!hasWork()) m_cond.wait(m_lock); work = takeWork(); } doWork(work); } } If you look at ParallelHelperPool (the GC's threads) and DFG::Worklist (some of the JIT's threads), you will see this pattern. This change adds a new kind of thread, called AutomaticThread, that lets you write threads to this pattern while getting automatic thread shutdown for free: instead of just waiting on a condition variable, AutomaticThread will have a timeout that causes the thread to die. The condition variable associated with AutomaticThread, called AutomaticThreadCondition, is smart enough to restart any threads that have decided to stop due to inactivity. The inactivity threshold is current just 1 second. In this patch I only adopt AutomaticThread for ParallelHelperPool. I plan to adopt it in more places soon. * WTF.xcodeproj/project.pbxproj: * wtf/AutomaticThread.cpp: Added. (WTF::AutomaticThreadCondition::create): (WTF::AutomaticThreadCondition::AutomaticThreadCondition): (WTF::AutomaticThreadCondition::~AutomaticThreadCondition): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Added. * wtf/CMakeLists.txt: * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::ParallelHelperPool): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::helperThreadBody): Deleted. (WTF::ParallelHelperPool::waitForClientWithTask): Deleted. * wtf/ParallelHelperPool.h: Canonical link: https://commits.webkit.org/181393@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207480 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-18 20:17:10 +00:00
bool awokenByNotify =
[WTF] Add WorkerPool https://bugs.webkit.org/show_bug.cgi?id=174569 Reviewed by Carlos Garcia Campos. Source/WebCore: We start using WorkerPool for NicosiaPaintingEngineThreaded instead of glib thread pool. This makes NicosiaPaintingEngineThreaded platform-independent and usable for WinCairo. * platform/graphics/nicosia/NicosiaPaintingEngineThreaded.cpp: (Nicosia::PaintingEngineThreaded::PaintingEngineThreaded): (Nicosia::PaintingEngineThreaded::~PaintingEngineThreaded): (Nicosia::PaintingEngineThreaded::paint): (Nicosia::s_threadFunc): Deleted. * platform/graphics/nicosia/NicosiaPaintingEngineThreaded.h: Source/WTF: This patch adds WorkerPool, which is a thread pool that consists of AutomaticThread. Since it is based on AutomaticThread, this WorkerPool can take `timeout`: once `timeout` passes without any tasks, threads in WorkerPool will be destroyed. We add shouldSleep handler to AutomaticThread to make destruction of threads in WorkerPool moderate. Without this, all threads are destroyed at once after `timeout` passes. * WTF.xcodeproj/project.pbxproj: * wtf/AutomaticThread.cpp: (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: * wtf/CMakeLists.txt: * wtf/WorkerPool.cpp: Added. (WTF::WorkerPool::WorkerPool): (WTF::WorkerPool::~WorkerPool): (WTF::WorkerPool::shouldSleep): (WTF::WorkerPool::postTask): * wtf/WorkerPool.h: Added. (WTF::WorkerPool::create): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/WorkerPool.cpp: Added. (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/201790@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@232619 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-06-08 08:47:06 +00:00
m_waitCondition.waitFor(*m_lock, m_timeout);
REGRESSION: HipChat and Mail sometimes hang beneath JSC::Heap::lastChanceToFinalize() https://bugs.webkit.org/show_bug.cgi?id=165962 Reviewed by Filip Pizlo. There is an inherent race in Condition::waitFor() where the timeout can happen just before a notify from another thread. Fixed this by adding a condition variable and flag to each AutomaticThread. The flag is used to signify to a notifying thread that the thread is waiting. That flag is set in the waiting thread before calling waitFor() and cleared by another thread when it notifies the thread. The access to that flag happens when the lock is held. Now the waiting thread checks if the flag after a timeout to see that it in fact should proceed like a normal notification. The added condition variable allows us to target a specific thread. We used to keep a list of waiting threads, now we keep a list of all threads. To notify one thread, we look for a waiting thread and notify it directly. If we can't find a waiting thread, we start a sleeping thread. We notify all threads by waking all waiting threads and starting all sleeping threads. * wtf/AutomaticThread.cpp: (WTF::AutomaticThreadCondition::notifyOne): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThread::isWaiting): (WTF::AutomaticThread::notify): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Canonical link: https://commits.webkit.org/183569@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@209938 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-12-16 22:26:09 +00:00
if (verbose && !awokenByNotify && !m_isWaiting)
dataLog(RawPointer(this), ": waitFor timed out, but notified via m_isWaiting flag!\n");
[WTF] Add WorkerPool https://bugs.webkit.org/show_bug.cgi?id=174569 Reviewed by Carlos Garcia Campos. Source/WebCore: We start using WorkerPool for NicosiaPaintingEngineThreaded instead of glib thread pool. This makes NicosiaPaintingEngineThreaded platform-independent and usable for WinCairo. * platform/graphics/nicosia/NicosiaPaintingEngineThreaded.cpp: (Nicosia::PaintingEngineThreaded::PaintingEngineThreaded): (Nicosia::PaintingEngineThreaded::~PaintingEngineThreaded): (Nicosia::PaintingEngineThreaded::paint): (Nicosia::s_threadFunc): Deleted. * platform/graphics/nicosia/NicosiaPaintingEngineThreaded.h: Source/WTF: This patch adds WorkerPool, which is a thread pool that consists of AutomaticThread. Since it is based on AutomaticThread, this WorkerPool can take `timeout`: once `timeout` passes without any tasks, threads in WorkerPool will be destroyed. We add shouldSleep handler to AutomaticThread to make destruction of threads in WorkerPool moderate. Without this, all threads are destroyed at once after `timeout` passes. * WTF.xcodeproj/project.pbxproj: * wtf/AutomaticThread.cpp: (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: * wtf/CMakeLists.txt: * wtf/WorkerPool.cpp: Added. (WTF::WorkerPool::WorkerPool): (WTF::WorkerPool::~WorkerPool): (WTF::WorkerPool::shouldSleep): (WTF::WorkerPool::postTask): * wtf/WorkerPool.h: Added. (WTF::WorkerPool::create): Tools: * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/WorkerPool.cpp: Added. (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/201790@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@232619 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-06-08 08:47:06 +00:00
if (m_isWaiting && shouldSleep(locker)) {
REGRESSION: HipChat and Mail sometimes hang beneath JSC::Heap::lastChanceToFinalize() https://bugs.webkit.org/show_bug.cgi?id=165962 Reviewed by Filip Pizlo. There is an inherent race in Condition::waitFor() where the timeout can happen just before a notify from another thread. Fixed this by adding a condition variable and flag to each AutomaticThread. The flag is used to signify to a notifying thread that the thread is waiting. That flag is set in the waiting thread before calling waitFor() and cleared by another thread when it notifies the thread. The access to that flag happens when the lock is held. Now the waiting thread checks if the flag after a timeout to see that it in fact should proceed like a normal notification. The added condition variable allows us to target a specific thread. We used to keep a list of waiting threads, now we keep a list of all threads. To notify one thread, we look for a waiting thread and notify it directly. If we can't find a waiting thread, we start a sleeping thread. We notify all threads by waking all waiting threads and starting all sleeping threads. * wtf/AutomaticThread.cpp: (WTF::AutomaticThreadCondition::notifyOne): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThread::isWaiting): (WTF::AutomaticThread::notify): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Canonical link: https://commits.webkit.org/183569@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@209938 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-12-16 22:26:09 +00:00
m_isWaiting = false;
WTF should make it easier to create threads that die automatically after inactivity https://bugs.webkit.org/show_bug.cgi?id=163576 Reviewed by Andreas Kling. Source/JavaScriptCore: Added a sleepSeconds() function, which made it easier for me to test this change. The WTF changes in this patch change how the JSC GC manages threads: the GC threads will now shut down automatically after 1 second of inactivity. Maybe this will save some memory. * jsc.cpp: (GlobalObject::finishCreation): (functionSleepSeconds): Source/WTF: For a long time now, I've been adding threads to WTF/JSC and each time I do this, I feel guilty because those threads don't shut down when they are inactive. For example, in bug 163562, I need to add a new GC thread. There will be one of them per VM. This means that a JSC API client that starts a lot of VMs will have a lot of threads. I don't think that's good. A common pattern for all of these threads is that they have some well-defined trigger that causes them to run. This trigger has a lock, a condition variable, some logic that determines if there is work to do, and then of course the logic for the thread's actual work. The thread bodies usually look like this: void Thingy::runThread() { for (;;) { Work work; { LockHolder locker(m_lock); while (!hasWork()) m_cond.wait(m_lock); work = takeWork(); } doWork(work); } } If you look at ParallelHelperPool (the GC's threads) and DFG::Worklist (some of the JIT's threads), you will see this pattern. This change adds a new kind of thread, called AutomaticThread, that lets you write threads to this pattern while getting automatic thread shutdown for free: instead of just waiting on a condition variable, AutomaticThread will have a timeout that causes the thread to die. The condition variable associated with AutomaticThread, called AutomaticThreadCondition, is smart enough to restart any threads that have decided to stop due to inactivity. The inactivity threshold is current just 1 second. In this patch I only adopt AutomaticThread for ParallelHelperPool. I plan to adopt it in more places soon. * WTF.xcodeproj/project.pbxproj: * wtf/AutomaticThread.cpp: Added. (WTF::AutomaticThreadCondition::create): (WTF::AutomaticThreadCondition::AutomaticThreadCondition): (WTF::AutomaticThreadCondition::~AutomaticThreadCondition): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Added. * wtf/CMakeLists.txt: * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::ParallelHelperPool): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::helperThreadBody): Deleted. (WTF::ParallelHelperPool::waitForClientWithTask): Deleted. * wtf/ParallelHelperPool.h: Canonical link: https://commits.webkit.org/181393@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207480 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-18 20:17:10 +00:00
if (verbose)
The GC should be in a thread https://bugs.webkit.org/show_bug.cgi?id=163562 Reviewed by Geoffrey Garen and Andreas Kling. Source/JavaScriptCore: In a concurrent GC, the work of collecting happens on a separate thread. This patch implements this, and schedules the thread the way that a concurrent GC thread would be scheduled. But, the GC isn't actually concurrent yet because it calls stopTheWorld() before doing anything and calls resumeTheWorld() after it's done with everything. The next step will be to make it really concurrent by basically calling stopTheWorld()/resumeTheWorld() around bounded snippets of work while making most of the work happen with the world running. Our GC will probably always have stop-the-world phases because the semantics of JSC weak references call for it. This implements concurrent GC scheduling. This means that there is no longer a Heap::collect() API. Instead, you can call collectAsync() which makes sure that a GC is scheduled (it will do nothing if one is scheduled or ongoing) or you can call collectSync() to schedule a GC and wait for it to happen. I made our debugging stuff call collectSync(). It should be a goal to never call collectSync() except for debugging or benchmark harness hacks. The collector thread is an AutomaticThread, so it won't linger when not in use. It works on a ticket-based system, like you would see at the DMV. A ticket is a 64-bit integer. There are two ticket counters: last granted and last served. When you request a collection, last granted is incremented and its new value given to you. When a collection completes, last served is incremented. collectSync() waits until last served catches up to what last granted had been at the time you requested a GC. This means that if you request a sync GC in the middle of an async GC, you will wait for that async GC to finish and then you will request and wait for your sync GC. The synchronization between the collector thread and the main threads is complex. The collector thread needs to be able to ask the main thread to stop. It needs to be able to do some post-GC clean-up, like the synchronous CodeBlock and LargeAllocation sweeps, on the main thread. The collector needs to be able to ask the main thread to execute a cross-modifying code fence before running any JIT code, since the GC might aid the JIT worklist and run JIT finalization. It's possible for the GC to want the main thread to run something at the same time that the main thread wants to wait for the GC. The main thread needs to be able to run non-JSC stuff without causing the GC to completely stall. The main thread needs to be able to query its own state (is there a request to stop?) and change it (running JSC versus not) quickly, since this may happen on hot paths. This kind of intertwined system of requests, notifications, and state changes requires a combination of lock-free algorithms and waiting. So, this is all implemented using a Atomic<unsigned> Heap::m_worldState, which has bits to represent things being requested by the collector and the heap access state of the mutator. I am borrowing a lot of terms that I've seen in other VMs that I've worked on. Here's what they mean: - Stop the world: make sure that either the mutator is not running, or that it's not running code that could mess with the heap. - Heap access: the mutator is said to have heap access if it could mess with the heap. If you stop the world and the mutator doesn't have heap access, all you're doing is making sure that it will block when it tries to acquire heap access. This means that our GC is already fully concurrent in cases where the GC is requested while the mutator has no heap access. This probably won't happen, but if it did then it should just work. Usually, stopping the world means that we state our shouldStop request with m_worldState, and a future call to Heap::stopIfNecessary() will go to slow path and stop. The act of stopping or waiting to acquire heap access is managed by using ParkingLot API directly on m_worldState. This works out great because it would be very awkward to get the same functionality using locks and condition variables, since we want stopIfNecessary/acquireAccess/requestAccess fast paths that are single atomic instructions (load/CAS/CAS, respectively). The mutator will call these things frequently. Currently we have Heap::stopIfNecessary() polling on every allocator slow path, but we may want to make it even more frequent than that. Currently only JSC API clients benefit from the heap access optimization. The DOM forces us to assume that heap access is permanently on, since DOM manipulation doesn't always hold the JSLock. We could still allow the GC to proceed when the runloop is idle by having the GC put a task on the runloop that just calls stopIfNecessary(). This is perf neutral. The only behavior change that clients ought to observe is that marking and the weak fixpoint happen on a separate thread. Marking was already parallel so it already handled multiple threads, but now it _never_ runs on the main thread. The weak fixpoint needed some help to be able to run on another thread - mostly because there was some code in IndexedDB that was using thread specifics in the weak fixpoint. * API/JSBase.cpp: (JSSynchronousEdenCollectForDebugging): * API/JSManagedValue.mm: (-[JSManagedValue initWithValue:]): * heap/EdenGCActivityCallback.cpp: (JSC::EdenGCActivityCallback::doCollection): * heap/FullGCActivityCallback.cpp: (JSC::FullGCActivityCallback::doCollection): * heap/Heap.cpp: (JSC::Heap::Thread::Thread): (JSC::Heap::Heap): (JSC::Heap::lastChanceToFinalize): (JSC::Heap::markRoots): (JSC::Heap::gatherStackRoots): (JSC::Heap::deleteUnmarkedCompiledCode): (JSC::Heap::collectAllGarbage): (JSC::Heap::collectAsync): (JSC::Heap::collectSync): (JSC::Heap::shouldCollectInThread): (JSC::Heap::collectInThread): (JSC::Heap::stopTheWorld): (JSC::Heap::resumeTheWorld): (JSC::Heap::stopIfNecessarySlow): (JSC::Heap::acquireAccessSlow): (JSC::Heap::releaseAccessSlow): (JSC::Heap::handleDidJIT): (JSC::Heap::handleNeedFinalize): (JSC::Heap::setDidJIT): (JSC::Heap::setNeedFinalize): (JSC::Heap::waitWhileNeedFinalize): (JSC::Heap::finalize): (JSC::Heap::requestCollection): (JSC::Heap::waitForCollection): (JSC::Heap::didFinishCollection): (JSC::Heap::canCollect): (JSC::Heap::shouldCollectHeuristic): (JSC::Heap::shouldCollect): (JSC::Heap::collectIfNecessaryOrDefer): (JSC::Heap::collectAccordingToDeferGCProbability): (JSC::Heap::collect): Deleted. (JSC::Heap::collectWithoutAnySweep): Deleted. (JSC::Heap::collectImpl): Deleted. * heap/Heap.h: (JSC::Heap::ReleaseAccessScope::ReleaseAccessScope): (JSC::Heap::ReleaseAccessScope::~ReleaseAccessScope): * heap/HeapInlines.h: (JSC::Heap::acquireAccess): (JSC::Heap::releaseAccess): (JSC::Heap::stopIfNecessary): * heap/MachineStackMarker.cpp: (JSC::MachineThreads::gatherConservativeRoots): (JSC::MachineThreads::gatherFromCurrentThread): Deleted. * heap/MachineStackMarker.h: * jit/JITWorklist.cpp: (JSC::JITWorklist::completeAllForVM): * jit/JITWorklist.h: * jsc.cpp: (functionFullGC): (functionEdenGC): * runtime/InitializeThreading.cpp: (JSC::initializeThreading): * runtime/JSLock.cpp: (JSC::JSLock::didAcquireLock): (JSC::JSLock::unlock): (JSC::JSLock::willReleaseLock): * tools/JSDollarVMPrototype.cpp: (JSC::JSDollarVMPrototype::edenGC): Source/WebCore: No new tests because existing tests cover this. We now need to be more careful about using JSLock. This fixes some places that were not holding it. New assertions in the GC are more likely to catch this than before. * bindings/js/WorkerScriptController.cpp: (WebCore::WorkerScriptController::WorkerScriptController): Source/WTF: This fixes some bugs and adds a few features. * wtf/Atomics.h: The GC may do work on behalf of the JIT. If it does, the main thread needs to execute a cross-modifying code fence. This is cpuid on x86 and I believe it's isb on ARM. It would have been an isync on PPC and I think that isb is the ARM equivalent. (WTF::arm_isb): (WTF::crossModifyingCodeFence): (WTF::x86_ortop): (WTF::x86_cpuid): * wtf/AutomaticThread.cpp: I accidentally had AutomaticThreadCondition inherit from ThreadSafeRefCounted<AutomaticThread> [sic]. This never crashed before because all of our prior AutomaticThreadConditions were immortal. (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: * wtf/MainThread.cpp: Need to allow initializeGCThreads() to be called separately because it's now more than just a debugging thing. (WTF::initializeGCThreads): Canonical link: https://commits.webkit.org/182065@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208306 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-02 22:01:04 +00:00
dataLog(RawPointer(this), ": Going to sleep!\n");
// It's important that we don't release the lock until we have completely
// indicated that the thread is kaput. Otherwise we'll have a a notify
// race that manifests as a deadlock on VM shutdown.
return stopForTimeout(locker);
WTF should make it easier to create threads that die automatically after inactivity https://bugs.webkit.org/show_bug.cgi?id=163576 Reviewed by Andreas Kling. Source/JavaScriptCore: Added a sleepSeconds() function, which made it easier for me to test this change. The WTF changes in this patch change how the JSC GC manages threads: the GC threads will now shut down automatically after 1 second of inactivity. Maybe this will save some memory. * jsc.cpp: (GlobalObject::finishCreation): (functionSleepSeconds): Source/WTF: For a long time now, I've been adding threads to WTF/JSC and each time I do this, I feel guilty because those threads don't shut down when they are inactive. For example, in bug 163562, I need to add a new GC thread. There will be one of them per VM. This means that a JSC API client that starts a lot of VMs will have a lot of threads. I don't think that's good. A common pattern for all of these threads is that they have some well-defined trigger that causes them to run. This trigger has a lock, a condition variable, some logic that determines if there is work to do, and then of course the logic for the thread's actual work. The thread bodies usually look like this: void Thingy::runThread() { for (;;) { Work work; { LockHolder locker(m_lock); while (!hasWork()) m_cond.wait(m_lock); work = takeWork(); } doWork(work); } } If you look at ParallelHelperPool (the GC's threads) and DFG::Worklist (some of the JIT's threads), you will see this pattern. This change adds a new kind of thread, called AutomaticThread, that lets you write threads to this pattern while getting automatic thread shutdown for free: instead of just waiting on a condition variable, AutomaticThread will have a timeout that causes the thread to die. The condition variable associated with AutomaticThread, called AutomaticThreadCondition, is smart enough to restart any threads that have decided to stop due to inactivity. The inactivity threshold is current just 1 second. In this patch I only adopt AutomaticThread for ParallelHelperPool. I plan to adopt it in more places soon. * WTF.xcodeproj/project.pbxproj: * wtf/AutomaticThread.cpp: Added. (WTF::AutomaticThreadCondition::create): (WTF::AutomaticThreadCondition::AutomaticThreadCondition): (WTF::AutomaticThreadCondition::~AutomaticThreadCondition): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Added. * wtf/CMakeLists.txt: * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::ParallelHelperPool): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::helperThreadBody): Deleted. (WTF::ParallelHelperPool::waitForClientWithTask): Deleted. * wtf/ParallelHelperPool.h: Canonical link: https://commits.webkit.org/181393@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207480 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-18 20:17:10 +00:00
}
}
}
WorkResult result = work();
if (result == WorkResult::Stop) {
Replace LockHolder with Locker in local variables https://bugs.webkit.org/show_bug.cgi?id=226133 Reviewed by Darin Adler. Replace LockHolder with Locker in local variables. It is shorter and it allows switching the lock type more easily since the compiler with deduce the lock type T for Locker<T>. Source/JavaScriptCore: * API/JSCallbackObject.h: (JSC::JSCallbackObjectData::JSPrivatePropertyMap::setPrivateProperty): (JSC::JSCallbackObjectData::JSPrivatePropertyMap::deletePrivateProperty): (JSC::JSCallbackObjectData::JSPrivatePropertyMap::visitChildren): * API/JSValue.mm: (handerForStructTag): * API/tests/testapi.cpp: (testCAPIViaCpp): * assembler/testmasm.cpp: (JSC::run): * b3/air/testair.cpp: * b3/testb3_1.cpp: (run): * bytecode/DirectEvalCodeCache.cpp: (JSC::DirectEvalCodeCache::setSlow): (JSC::DirectEvalCodeCache::clear): (JSC::DirectEvalCodeCache::visitAggregateImpl): * bytecode/SuperSampler.cpp: (JSC::initializeSuperSampler): (JSC::resetSuperSamplerState): (JSC::printSuperSamplerState): (JSC::enableSuperSampler): (JSC::disableSuperSampler): * dfg/DFGCommonData.cpp: (JSC::DFG::CommonData::invalidate): (JSC::DFG::CommonData::~CommonData): (JSC::DFG::CommonData::installVMTrapBreakpoints): (JSC::DFG::codeBlockForVMTrapPC): * dfg/DFGPlan.cpp: (JSC::DFG::Plan::cleanMustHandleValuesIfNecessary): * dfg/DFGWorklist.cpp: (JSC::DFG::Worklist::~Worklist): (JSC::DFG::Worklist::finishCreation): (JSC::DFG::Worklist::isActiveForVM const): (JSC::DFG::Worklist::enqueue): (JSC::DFG::Worklist::compilationState): (JSC::DFG::Worklist::waitUntilAllPlansForVMAreReady): (JSC::DFG::Worklist::removeAllReadyPlansForVM): (JSC::DFG::Worklist::completeAllReadyPlansForVM): (JSC::DFG::Worklist::visitWeakReferences): (JSC::DFG::Worklist::removeDeadPlans): (JSC::DFG::Worklist::removeNonCompilingPlansForVM): (JSC::DFG::Worklist::queueLength): (JSC::DFG::Worklist::dump const): (JSC::DFG::Worklist::setNumberOfThreads): * dfg/DFGWorklistInlines.h: (JSC::DFG::Worklist::iterateCodeBlocksForGC): * disassembler/Disassembler.cpp: * heap/BlockDirectory.cpp: (JSC::BlockDirectory::addBlock): * heap/CodeBlockSetInlines.h: (JSC::CodeBlockSet::iterateCurrentlyExecuting): * heap/ConservativeRoots.cpp: (JSC::ConservativeRoots::add): * heap/Heap.cpp: (JSC::Heap::Heap): (JSC::Heap::lastChanceToFinalize): (JSC::Heap::collectAsync): (JSC::Heap::runBeginPhase): (JSC::Heap::waitForCollector): (JSC::Heap::requestCollection): (JSC::Heap::notifyIsSafeToCollect): * heap/SlotVisitor.cpp: (JSC::SlotVisitor::didReachTermination): * inspector/agents/InspectorScriptProfilerAgent.cpp: (Inspector::InspectorScriptProfilerAgent::startTracking): (Inspector::InspectorScriptProfilerAgent::trackingComplete): (Inspector::InspectorScriptProfilerAgent::stopSamplingWhenDisconnecting): * inspector/remote/RemoteConnectionToTarget.cpp: (Inspector::RemoteConnectionToTarget::setup): (Inspector::RemoteConnectionToTarget::sendMessageToTarget): (Inspector::RemoteConnectionToTarget::close): (Inspector::RemoteConnectionToTarget::targetClosed): * inspector/remote/RemoteInspector.cpp: (Inspector::RemoteInspector::registerTarget): (Inspector::RemoteInspector::unregisterTarget): (Inspector::RemoteInspector::updateTarget): (Inspector::RemoteInspector::updateClientCapabilities): (Inspector::RemoteInspector::setClient): (Inspector::RemoteInspector::setupFailed): (Inspector::RemoteInspector::setupCompleted): (Inspector::RemoteInspector::stop): * inspector/remote/cocoa/RemoteConnectionToTargetCocoa.mm: (Inspector::RemoteTargetHandleRunSourceGlobal): (Inspector::RemoteTargetQueueTaskOnGlobalQueue): (Inspector::RemoteTargetHandleRunSourceWithInfo): (Inspector::RemoteConnectionToTarget::setup): (Inspector::RemoteConnectionToTarget::targetClosed): (Inspector::RemoteConnectionToTarget::close): (Inspector::RemoteConnectionToTarget::sendMessageToTarget): (Inspector::RemoteConnectionToTarget::queueTaskOnPrivateRunLoop): * inspector/remote/cocoa/RemoteInspectorCocoa.mm: (Inspector::RemoteInspector::updateAutomaticInspectionCandidate): (Inspector::RemoteInspector::sendMessageToRemote): (Inspector::RemoteInspector::start): (Inspector::RemoteInspector::setupXPCConnectionIfNeeded): (Inspector::RemoteInspector::setParentProcessInformation): (Inspector::RemoteInspector::xpcConnectionReceivedMessage): (Inspector::RemoteInspector::xpcConnectionFailed): (Inspector::RemoteInspector::pushListingsSoon): (Inspector::RemoteInspector::receivedIndicateMessage): (Inspector::RemoteInspector::receivedProxyApplicationSetupMessage): * inspector/remote/cocoa/RemoteInspectorXPCConnection.mm: (Inspector::RemoteInspectorXPCConnection::close): (Inspector::RemoteInspectorXPCConnection::closeFromMessage): (Inspector::RemoteInspectorXPCConnection::deserializeMessage): (Inspector::RemoteInspectorXPCConnection::handleEvent): * inspector/remote/glib/RemoteInspectorGlib.cpp: (Inspector::RemoteInspector::start): (Inspector::RemoteInspector::setupConnection): (Inspector::RemoteInspector::pushListingsSoon): (Inspector::RemoteInspector::sendMessageToRemote): (Inspector::RemoteInspector::receivedGetTargetListMessage): (Inspector::RemoteInspector::receivedDataMessage): (Inspector::RemoteInspector::receivedCloseMessage): (Inspector::RemoteInspector::setup): * inspector/remote/socket/RemoteInspectorConnectionClient.cpp: (Inspector::RemoteInspectorConnectionClient::didReceive): * inspector/remote/socket/RemoteInspectorSocket.cpp: (Inspector::RemoteInspector::didClose): (Inspector::RemoteInspector::start): (Inspector::RemoteInspector::pushListingsSoon): (Inspector::RemoteInspector::setup): (Inspector::RemoteInspector::setupInspectorClient): (Inspector::RemoteInspector::frontendDidClose): (Inspector::RemoteInspector::sendMessageToBackend): (Inspector::RemoteInspector::startAutomationSession): * inspector/remote/socket/RemoteInspectorSocketEndpoint.cpp: (Inspector::RemoteInspectorSocketEndpoint::listenInet): (Inspector::RemoteInspectorSocketEndpoint::isListening): (Inspector::RemoteInspectorSocketEndpoint::workerThread): (Inspector::RemoteInspectorSocketEndpoint::createClient): (Inspector::RemoteInspectorSocketEndpoint::disconnect): (Inspector::RemoteInspectorSocketEndpoint::invalidateClient): (Inspector::RemoteInspectorSocketEndpoint::invalidateListener): (Inspector::RemoteInspectorSocketEndpoint::getPort const): (Inspector::RemoteInspectorSocketEndpoint::recvIfEnabled): (Inspector::RemoteInspectorSocketEndpoint::sendIfEnabled): (Inspector::RemoteInspectorSocketEndpoint::send): (Inspector::RemoteInspectorSocketEndpoint::acceptInetSocketIfEnabled): * interpreter/CLoopStack.cpp: (JSC::CLoopStack::addToCommittedByteCount): (JSC::CLoopStack::committedByteCount): * jit/ExecutableAllocator.cpp: (JSC::dumpJITMemory): * jit/ICStats.cpp: (JSC::ICStats::ICStats): (JSC::ICStats::~ICStats): * jit/JITThunks.cpp: (JSC::JITThunks::ctiStub): (JSC::JITThunks::existingCTIStub): (JSC::JITThunks::ctiSlowPathFunctionStub): * jit/JITWorklist.cpp: (JSC::JITWorklist::Plan::compileInThread): (JSC::JITWorklist::Plan::isFinishedCompiling): (JSC::JITWorklist::JITWorklist): (JSC::JITWorklist::completeAllForVM): (JSC::JITWorklist::poll): (JSC::JITWorklist::compileLater): (JSC::JITWorklist::finalizePlans): * parser/SourceProvider.cpp: (JSC::SourceProvider::getID): * profiler/ProfilerDatabase.cpp: (JSC::Profiler::Database::ensureBytecodesFor): (JSC::Profiler::Database::notifyDestruction): (JSC::Profiler::Database::addCompilation): (JSC::Profiler::Database::logEvent): (JSC::Profiler::Database::addDatabaseToAtExit): (JSC::Profiler::Database::removeDatabaseFromAtExit): (JSC::Profiler::Database::removeFirstAtExitDatabase): * profiler/ProfilerUID.cpp: (JSC::Profiler::UID::create): * runtime/DeferredWorkTimer.cpp: (JSC::DeferredWorkTimer::scheduleWorkSoon): (JSC::DeferredWorkTimer::didResumeScriptExecutionOwner): * runtime/SamplingProfiler.cpp: (JSC::SamplingProfiler::timerLoop): (JSC::SamplingProfiler::shutdown): (JSC::SamplingProfiler::start): (JSC::SamplingProfiler::noticeCurrentThreadAsJSCExecutionThread): (JSC::SamplingProfiler::noticeJSLockAcquisition): (JSC::SamplingProfiler::noticeVMEntry): (JSC::SamplingProfiler::registerForReportAtExit): * runtime/Watchdog.cpp: (JSC::Watchdog::startTimer): (JSC::Watchdog::willDestroyVM): * tools/VMInspector.cpp: (JSC::VMInspector::isValidExecutableMemory): * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::work): * wasm/WasmEntryPlan.cpp: (JSC::Wasm::EntryPlan::ThreadCountHolder::ThreadCountHolder): (JSC::Wasm::EntryPlan::ThreadCountHolder::~ThreadCountHolder): * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::work): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::addCompletionTask): (JSC::Wasm::Plan::waitForCompletion): (JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast): * wasm/WasmSignature.cpp: (JSC::Wasm::SignatureInformation::signatureFor): (JSC::Wasm::SignatureInformation::tryCleanup): * wasm/WasmWorklist.cpp: (JSC::Wasm::Worklist::enqueue): (JSC::Wasm::Worklist::completePlanSynchronously): (JSC::Wasm::Worklist::stopAllPlansForContext): (JSC::Wasm::Worklist::Worklist): (JSC::Wasm::Worklist::~Worklist): Source/WebCore: * Modules/webaudio/AsyncAudioDecoder.cpp: (WebCore::AsyncAudioDecoder::AsyncAudioDecoder): (WebCore::AsyncAudioDecoder::runLoop): * Modules/webdatabase/Database.cpp: (WebCore::Database::performClose): (WebCore::Database::inProgressTransactionCompleted): (WebCore::Database::hasPendingTransaction): (WebCore::Database::runTransaction): * Modules/webdatabase/DatabaseThread.cpp: (WebCore::DatabaseThread::start): (WebCore::DatabaseThread::databaseThread): (WebCore::DatabaseThread::recordDatabaseOpen): (WebCore::DatabaseThread::recordDatabaseClosed): (WebCore::DatabaseThread::hasPendingDatabaseActivity const): * Modules/webdatabase/DatabaseTracker.cpp: (WebCore::DatabaseTracker::canEstablishDatabase): (WebCore::DatabaseTracker::retryCanEstablishDatabase): (WebCore::DatabaseTracker::maximumSize): (WebCore::DatabaseTracker::fullPathForDatabase): (WebCore::DatabaseTracker::origins): (WebCore::DatabaseTracker::databaseNames): (WebCore::DatabaseTracker::detailsForNameAndOrigin): (WebCore::DatabaseTracker::setDatabaseDetails): (WebCore::DatabaseTracker::doneCreatingDatabase): (WebCore::DatabaseTracker::openDatabases): (WebCore::DatabaseTracker::addOpenDatabase): (WebCore::DatabaseTracker::removeOpenDatabase): (WebCore::DatabaseTracker::originLockFor): (WebCore::DatabaseTracker::quota): (WebCore::DatabaseTracker::setQuota): (WebCore::DatabaseTracker::deleteOrigin): (WebCore::DatabaseTracker::deleteDatabase): (WebCore::DatabaseTracker::deleteDatabaseFile): (WebCore::DatabaseTracker::removeDeletedOpenedDatabases): * Modules/webdatabase/SQLCallbackWrapper.h: (WebCore::SQLCallbackWrapper::clear): (WebCore::SQLCallbackWrapper::unwrap): * Modules/webdatabase/SQLTransaction.cpp: (WebCore::SQLTransaction::enqueueStatement): (WebCore::SQLTransaction::checkAndHandleClosedDatabase): (WebCore::SQLTransaction::getNextStatement): * Modules/webdatabase/SQLTransactionBackend.cpp: (WebCore::SQLTransactionBackend::doCleanup): * accessibility/isolatedtree/AXIsolatedTree.cpp: (WebCore::AXIsolatedTree::clear): (WebCore::AXIsolatedTree::generateSubtree): (WebCore::AXIsolatedTree::createSubtree): (WebCore::AXIsolatedTree::updateNode): (WebCore::AXIsolatedTree::updateNodeProperty): (WebCore::AXIsolatedTree::updateChildren): (WebCore::AXIsolatedTree::focusedNode): (WebCore::AXIsolatedTree::rootNode): (WebCore::AXIsolatedTree::setFocusedNodeID): (WebCore::AXIsolatedTree::removeNode): (WebCore::AXIsolatedTree::removeSubtree): (WebCore::AXIsolatedTree::applyPendingChanges): * page/scrolling/mac/ScrollingTreeMac.mm: (ScrollingTreeMac::scrollingNodeForPoint): (ScrollingTreeMac::eventListenerRegionTypesForPoint const): * platform/AbortableTaskQueue.h: * platform/audio/cocoa/CARingBuffer.cpp: (WebCore::CARingBufferStorageVector::flush): (WebCore::CARingBufferStorageVector::setCurrentFrameBounds): * platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp: (WebCore::AVFWrapper::addToMap): (WebCore::AVFWrapper::removeFromMap const): (WebCore::AVFWrapper::periodicTimeObserverCallback): (WebCore::AVFWrapper::processNotification): (WebCore::AVFWrapper::loadPlayableCompletionCallback): (WebCore::AVFWrapper::loadMetadataCompletionCallback): (WebCore::AVFWrapper::seekCompletedCallback): (WebCore::AVFWrapper::processCue): (WebCore::AVFWrapper::legibleOutputCallback): (WebCore::AVFWrapper::processShouldWaitForLoadingOfResource): (WebCore::AVFWrapper::resourceLoaderShouldWaitForLoadingOfRequestedResource): * platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.mm: (-[WebCoreSharedBufferResourceLoaderDelegate setExpectedContentSize:]): (-[WebCoreSharedBufferResourceLoaderDelegate updateData:complete:]): (-[WebCoreSharedBufferResourceLoaderDelegate resourceLoader:shouldWaitForLoadingOfRequestedResource:]): (-[WebCoreSharedBufferResourceLoaderDelegate resourceLoader:didCancelLoadingRequest:]): (WebCore::ImageDecoderAVFObjC::setTrack): (WebCore::ImageDecoderAVFObjC::createFrameImageAtIndex): * platform/graphics/gstreamer/ImageDecoderGStreamer.cpp: (WebCore::ImageDecoderGStreamer::createFrameImageAtIndex): * platform/graphics/gstreamer/InbandTextTrackPrivateGStreamer.cpp: (WebCore::InbandTextTrackPrivateGStreamer::handleSample): (WebCore::InbandTextTrackPrivateGStreamer::notifyTrackOfSample): * platform/graphics/gstreamer/MainThreadNotifier.h: * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::parseInitDataFromProtectionMessage): (WebCore::MediaPlayerPrivateGStreamer::handleProtectionEvent): * platform/graphics/gstreamer/TrackPrivateBaseGStreamer.cpp: (WebCore::TrackPrivateBaseGStreamer::tagsChanged): (WebCore::TrackPrivateBaseGStreamer::notifyTrackOfTagsChanged): * platform/graphics/gstreamer/VideoSinkGStreamer.cpp: (VideoRenderRequestScheduler::start): (VideoRenderRequestScheduler::stop): (VideoRenderRequestScheduler::drain): (VideoRenderRequestScheduler::requestRender): * platform/graphics/gstreamer/eme/WebKitCommonEncryptionDecryptorGStreamer.cpp: (transformInPlace): (sinkEventHandler): (webKitMediaCommonEncryptionDecryptIsFlushing): (setContext): * platform/graphics/nicosia/NicosiaBuffer.cpp: (Nicosia::Buffer::beginPainting): (Nicosia::Buffer::completePainting): (Nicosia::Buffer::waitUntilPaintingComplete): * platform/graphics/nicosia/NicosiaPlatformLayer.h: (Nicosia::PlatformLayer::setSceneIntegration): (Nicosia::PlatformLayer::createUpdateScope): (Nicosia::CompositionLayer::updateState): (Nicosia::CompositionLayer::flushState): (Nicosia::CompositionLayer::commitState): (Nicosia::CompositionLayer::accessPending): (Nicosia::CompositionLayer::accessCommitted): * platform/graphics/nicosia/NicosiaScene.h: (Nicosia::Scene::accessState): * platform/graphics/nicosia/NicosiaSceneIntegration.cpp: (Nicosia::SceneIntegration::setClient): (Nicosia::SceneIntegration::invalidate): (Nicosia::SceneIntegration::requestUpdate): * platform/graphics/nicosia/texmap/NicosiaBackingStoreTextureMapperImpl.cpp: (Nicosia::BackingStoreTextureMapperImpl::flushUpdate): (Nicosia::BackingStoreTextureMapperImpl::takeUpdate): * platform/graphics/nicosia/texmap/NicosiaContentLayerTextureMapperImpl.cpp: (Nicosia::ContentLayerTextureMapperImpl::~ContentLayerTextureMapperImpl): (Nicosia::ContentLayerTextureMapperImpl::invalidateClient): (Nicosia::ContentLayerTextureMapperImpl::flushUpdate): (Nicosia::ContentLayerTextureMapperImpl::swapBuffersIfNeeded): * platform/graphics/nicosia/texmap/NicosiaImageBackingTextureMapperImpl.cpp: (Nicosia::ImageBackingTextureMapperImpl::flushUpdate): (Nicosia::ImageBackingTextureMapperImpl::takeUpdate): * platform/graphics/texmap/TextureMapperGCGLPlatformLayer.cpp: (WebCore::TextureMapperGCGLPlatformLayer::swapBuffersIfNeeded): * platform/graphics/win/MediaPlayerPrivateMediaFoundation.cpp: (WebCore::MediaPlayerPrivateMediaFoundation::load): (WebCore::MediaPlayerPrivateMediaFoundation::naturalSize const): (WebCore::MediaPlayerPrivateMediaFoundation::addListener): (WebCore::MediaPlayerPrivateMediaFoundation::removeListener): (WebCore::MediaPlayerPrivateMediaFoundation::notifyDeleted): (WebCore::MediaPlayerPrivateMediaFoundation::setNaturalSize): (WebCore::MediaPlayerPrivateMediaFoundation::AsyncCallback::Invoke): (WebCore::MediaPlayerPrivateMediaFoundation::AsyncCallback::onMediaPlayerDeleted): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::OnClockStart): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::OnClockStop): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::OnClockPause): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::OnClockRestart): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::OnClockSetRate): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::ProcessMessage): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::GetCurrentMediaType): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::InitServicePointers): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::ReleaseServicePointers): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::SetVideoWindow): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::GetVideoWindow): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::SetVideoPosition): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::GetVideoPosition): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::RepaintVideo): (WebCore::MediaPlayerPrivateMediaFoundation::VideoSamplePool::getSample): (WebCore::MediaPlayerPrivateMediaFoundation::VideoSamplePool::returnSample): (WebCore::MediaPlayerPrivateMediaFoundation::VideoSamplePool::areSamplesPending): (WebCore::MediaPlayerPrivateMediaFoundation::VideoSamplePool::initialize): (WebCore::MediaPlayerPrivateMediaFoundation::VideoSamplePool::clear): (WebCore::MediaPlayerPrivateMediaFoundation::VideoScheduler::stopScheduler): (WebCore::MediaPlayerPrivateMediaFoundation::VideoScheduler::scheduleSample): (WebCore::MediaPlayerPrivateMediaFoundation::VideoScheduler::processSamplesInQueue): (WebCore::MediaPlayerPrivateMediaFoundation::VideoScheduler::processSample): (WebCore::MediaPlayerPrivateMediaFoundation::VideoScheduler::schedulerThreadProcPrivate): (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::setVideoWindow): (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::setDestinationRect): (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::createVideoSamples): (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::checkDeviceState): (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::presentSample): (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::paintCurrentFrame): (WebCore::MediaPlayerPrivateMediaFoundation::Direct3DPresenter::createD3DDevice): * platform/image-decoders/ScalableImageDecoder.cpp: (WebCore::ScalableImageDecoder::frameIsCompleteAtIndex const): (WebCore::ScalableImageDecoder::frameHasAlphaAtIndex const): (WebCore::ScalableImageDecoder::frameBytesAtIndex const): (WebCore::ScalableImageDecoder::frameDurationAtIndex const): (WebCore::ScalableImageDecoder::createFrameImageAtIndex): * platform/image-decoders/ScalableImageDecoder.h: * platform/ios/LegacyTileCache.mm: (WebCore::LegacyTileCache::setTilesOpaque): (WebCore::LegacyTileCache::doLayoutTiles): (WebCore::LegacyTileCache::setCurrentScale): (WebCore::LegacyTileCache::commitScaleChange): (WebCore::LegacyTileCache::layoutTilesNow): (WebCore::LegacyTileCache::layoutTilesNowForRect): (WebCore::LegacyTileCache::removeAllNonVisibleTiles): (WebCore::LegacyTileCache::removeAllTiles): (WebCore::LegacyTileCache::removeForegroundTiles): (WebCore::LegacyTileCache::setContentReplacementImage): (WebCore::LegacyTileCache::contentReplacementImage const): (WebCore::LegacyTileCache::tileCreationTimerFired): (WebCore::LegacyTileCache::setNeedsDisplayInRect): (WebCore::LegacyTileCache::updateTilingMode): (WebCore::LegacyTileCache::setTilingMode): (WebCore::LegacyTileCache::doPendingRepaints): (WebCore::LegacyTileCache::flushSavedDisplayRects): (WebCore::LegacyTileCache::prepareToDraw): * platform/ios/LegacyTileLayerPool.mm: (WebCore::LegacyTileLayerPool::addLayer): (WebCore::LegacyTileLayerPool::takeLayerWithSize): (WebCore::LegacyTileLayerPool::setCapacity): (WebCore::LegacyTileLayerPool::prune): (WebCore::LegacyTileLayerPool::drain): * platform/ios/wak/WAKWindow.mm: (-[WAKWindow setExposedScrollViewRect:]): (-[WAKWindow exposedScrollViewRect]): * platform/ios/wak/WebCoreThread.mm: (RunWebThread): (StartWebThread): * platform/mediastream/gstreamer/RealtimeOutgoingAudioSourceLibWebRTC.cpp: (WebCore::RealtimeOutgoingAudioSourceLibWebRTC::audioSamplesAvailable): (WebCore::RealtimeOutgoingAudioSourceLibWebRTC::pullAudioData): * platform/network/cf/FormDataStreamCFNet.cpp: (WebCore::openNextStream): (WebCore::formFinalize): (WebCore::formClose): * platform/network/curl/CurlRequest.cpp: (WebCore::CurlRequest::setRequestPaused): (WebCore::CurlRequest::setCallbackPaused): (WebCore::CurlRequest::pausedStatusChanged): (WebCore::CurlRequest::enableDownloadToFile): (WebCore::CurlRequest::getDownloadedFilePath): (WebCore::CurlRequest::writeDataToDownloadFileIfEnabled): (WebCore::CurlRequest::closeDownloadFile): (WebCore::CurlRequest::cleanupDownloadFile): * platform/network/curl/CurlSSLHandle.cpp: (WebCore::CurlSSLHandle::allowAnyHTTPSCertificatesForHost): (WebCore::CurlSSLHandle::canIgnoreAnyHTTPSCertificatesForHost const): (WebCore::CurlSSLHandle::setClientCertificateInfo): (WebCore::CurlSSLHandle::getSSLClientCertificate const): * platform/sql/SQLiteDatabase.cpp: (WebCore::SQLiteDatabase::close): (WebCore::SQLiteDatabase::maximumSize): (WebCore::SQLiteDatabase::setMaximumSize): (WebCore::SQLiteDatabase::pageSize): (WebCore::SQLiteDatabase::freeSpaceSize): (WebCore::SQLiteDatabase::totalSize): (WebCore::SQLiteDatabase::runIncrementalVacuumCommand): (WebCore::SQLiteDatabase::interrupt): (WebCore::SQLiteDatabase::setAuthorizer): (WebCore::constructAndPrepareStatement): * platform/sql/SQLiteStatement.cpp: (WebCore::SQLiteStatement::step): Source/WebKit: * NetworkProcess/IndexedDB/WebIDBServer.cpp: (WebKit::m_closeCallback): (WebKit::WebIDBServer::getOrigins): (WebKit::WebIDBServer::closeAndDeleteDatabasesModifiedSince): (WebKit::WebIDBServer::closeAndDeleteDatabasesForOrigins): (WebKit::WebIDBServer::renameOrigin): (WebKit::WebIDBServer::openDatabase): (WebKit::WebIDBServer::deleteDatabase): (WebKit::WebIDBServer::abortTransaction): (WebKit::WebIDBServer::commitTransaction): (WebKit::WebIDBServer::didFinishHandlingVersionChangeTransaction): (WebKit::WebIDBServer::createObjectStore): (WebKit::WebIDBServer::deleteObjectStore): (WebKit::WebIDBServer::renameObjectStore): (WebKit::WebIDBServer::clearObjectStore): (WebKit::WebIDBServer::createIndex): (WebKit::WebIDBServer::deleteIndex): (WebKit::WebIDBServer::renameIndex): (WebKit::WebIDBServer::putOrAdd): (WebKit::WebIDBServer::getRecord): (WebKit::WebIDBServer::getAllRecords): (WebKit::WebIDBServer::getCount): (WebKit::WebIDBServer::deleteRecord): (WebKit::WebIDBServer::openCursor): (WebKit::WebIDBServer::iterateCursor): (WebKit::WebIDBServer::establishTransaction): (WebKit::WebIDBServer::databaseConnectionPendingClose): (WebKit::WebIDBServer::databaseConnectionClosed): (WebKit::WebIDBServer::abortOpenAndUpgradeNeeded): (WebKit::WebIDBServer::didFireVersionChangeEvent): (WebKit::WebIDBServer::openDBRequestCancelled): (WebKit::WebIDBServer::getAllDatabaseNamesAndVersions): (WebKit::WebIDBServer::addConnection): (WebKit::WebIDBServer::removeConnection): (WebKit::WebIDBServer::close): * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::Engine::writeSizeFile): (WebKit::CacheStorage::Engine::readSizeFile): (WebKit::CacheStorage::Engine::clearAllCachesFromDisk): (WebKit::CacheStorage::Engine::deleteNonEmptyDirectoryOnBackgroundThread): * NetworkProcess/glib/DNSCache.cpp: (WebKit::DNSCache::lookup): (WebKit::DNSCache::update): (WebKit::DNSCache::removeExpiredResponsesFired): (WebKit::DNSCache::clear): * Shared/CoordinatedGraphics/threadedcompositor/CompositingRunLoop.cpp: (WebKit::CompositingRunLoop::suspend): (WebKit::CompositingRunLoop::resume): (WebKit::CompositingRunLoop::scheduleUpdate): (WebKit::CompositingRunLoop::stopUpdates): (WebKit::CompositingRunLoop::updateTimerFired): * Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp: (WebKit::m_displayRefreshMonitor): (WebKit::ThreadedCompositor::setScaleFactor): (WebKit::ThreadedCompositor::setScrollPosition): (WebKit::ThreadedCompositor::setViewportSize): (WebKit::ThreadedCompositor::renderLayerTree): (WebKit::ThreadedCompositor::sceneUpdateFinished): (WebKit::ThreadedCompositor::updateSceneState): * UIProcess/API/glib/IconDatabase.cpp: (WebKit::IconDatabase::populatePageURLToIconURLMap): (WebKit::IconDatabase::clearLoadedIconsTimerFired): (WebKit::IconDatabase::checkIconURLAndSetPageURLIfNeeded): (WebKit::IconDatabase::loadIconForPageURL): (WebKit::IconDatabase::iconURLForPageURL): (WebKit::IconDatabase::setIconForPageURL): (WebKit::IconDatabase::clear): Source/WebKitLegacy: * Storage/InProcessIDBServer.cpp: (InProcessIDBServer::InProcessIDBServer): (InProcessIDBServer::deleteDatabase): (InProcessIDBServer::openDatabase): (InProcessIDBServer::abortTransaction): (InProcessIDBServer::commitTransaction): (InProcessIDBServer::didFinishHandlingVersionChangeTransaction): (InProcessIDBServer::createObjectStore): (InProcessIDBServer::deleteObjectStore): (InProcessIDBServer::renameObjectStore): (InProcessIDBServer::clearObjectStore): (InProcessIDBServer::createIndex): (InProcessIDBServer::deleteIndex): (InProcessIDBServer::renameIndex): (InProcessIDBServer::putOrAdd): (InProcessIDBServer::getRecord): (InProcessIDBServer::getAllRecords): (InProcessIDBServer::getCount): (InProcessIDBServer::deleteRecord): (InProcessIDBServer::openCursor): (InProcessIDBServer::iterateCursor): (InProcessIDBServer::establishTransaction): (InProcessIDBServer::databaseConnectionPendingClose): (InProcessIDBServer::databaseConnectionClosed): (InProcessIDBServer::abortOpenAndUpgradeNeeded): (InProcessIDBServer::didFireVersionChangeEvent): (InProcessIDBServer::openDBRequestCancelled): (InProcessIDBServer::getAllDatabaseNamesAndVersions): (InProcessIDBServer::closeAndDeleteDatabasesModifiedSince): * Storage/StorageAreaSync.cpp: (WebKit::StorageAreaSync::syncTimerFired): (WebKit::StorageAreaSync::performSync): * Storage/StorageTracker.cpp: (WebKit::StorageTracker::finishedImportingOriginIdentifiers): (WebKit::StorageTracker::syncImportOriginIdentifiers): (WebKit::StorageTracker::syncFileSystemAndTrackerDatabase): (WebKit::StorageTracker::setOriginDetails): (WebKit::StorageTracker::syncSetOriginDetails): (WebKit::StorageTracker::origins): (WebKit::StorageTracker::deleteAllOrigins): (WebKit::StorageTracker::syncDeleteAllOrigins): (WebKit::StorageTracker::deleteOrigin): (WebKit::StorageTracker::syncDeleteOrigin): (WebKit::StorageTracker::canDeleteOrigin): (WebKit::StorageTracker::cancelDeletingOrigin): (WebKit::StorageTracker::diskUsageForOrigin): Source/WebKitLegacy/mac: * WebView/WebView.mm: (-[WebView _synchronizeCustomFixedPositionLayoutRect]): (-[WebView _setCustomFixedPositionLayoutRectInWebThread:synchronize:]): (-[WebView _setCustomFixedPositionLayoutRect:]): (-[WebView _fetchCustomFixedPositionLayoutRect:]): Source/WebKitLegacy/win: * Plugins/PluginMainThreadScheduler.cpp: (WebCore::PluginMainThreadScheduler::scheduleCall): (WebCore::PluginMainThreadScheduler::registerPlugin): (WebCore::PluginMainThreadScheduler::unregisterPlugin): (WebCore::PluginMainThreadScheduler::dispatchCallsForPlugin): Source/WTF: * benchmarks/LockSpeedTest.cpp: * wtf/AutomaticThread.cpp: (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: * wtf/MetaAllocator.cpp: (WTF::MetaAllocatorHandle::shrink): (WTF::MetaAllocator::addFreshFreeSpace): (WTF::MetaAllocator::debugFreeSpaceSize): * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): * wtf/Seconds.cpp: (WTF::sleep): * wtf/TimeWithDynamicClockType.cpp: (WTF::sleep): * wtf/WorkerPool.cpp: (WTF::WorkerPool::WorkerPool): (WTF::WorkerPool::~WorkerPool): (WTF::WorkerPool::postTask): * wtf/posix/ThreadingPOSIX.cpp: (WTF::Thread::suspend): (WTF::Thread::resume): (WTF::Thread::getRegisters): * wtf/win/DbgHelperWin.cpp: (WTF::DbgHelper::SymFromAddress): * wtf/win/ThreadingWin.cpp: (WTF::Thread::suspend): (WTF::Thread::resume): (WTF::Thread::getRegisters): Tools: * TestWebKitAPI/Tests/WTF/WorkQueue.cpp: (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/WTF/glib/WorkQueueGLib.cpp: (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/WebCore/AbortableTaskQueue.cpp: (TestWebKitAPI::DeterministicScheduler::ThreadContext::waitMyTurn): (TestWebKitAPI::DeterministicScheduler::ThreadContext::yieldToThread): Canonical link: https://commits.webkit.org/238053@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@277920 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-05-22 16:49:42 +00:00
Locker locker { *m_lock };
return stopPermanently(locker);
WTF should make it easier to create threads that die automatically after inactivity https://bugs.webkit.org/show_bug.cgi?id=163576 Reviewed by Andreas Kling. Source/JavaScriptCore: Added a sleepSeconds() function, which made it easier for me to test this change. The WTF changes in this patch change how the JSC GC manages threads: the GC threads will now shut down automatically after 1 second of inactivity. Maybe this will save some memory. * jsc.cpp: (GlobalObject::finishCreation): (functionSleepSeconds): Source/WTF: For a long time now, I've been adding threads to WTF/JSC and each time I do this, I feel guilty because those threads don't shut down when they are inactive. For example, in bug 163562, I need to add a new GC thread. There will be one of them per VM. This means that a JSC API client that starts a lot of VMs will have a lot of threads. I don't think that's good. A common pattern for all of these threads is that they have some well-defined trigger that causes them to run. This trigger has a lock, a condition variable, some logic that determines if there is work to do, and then of course the logic for the thread's actual work. The thread bodies usually look like this: void Thingy::runThread() { for (;;) { Work work; { LockHolder locker(m_lock); while (!hasWork()) m_cond.wait(m_lock); work = takeWork(); } doWork(work); } } If you look at ParallelHelperPool (the GC's threads) and DFG::Worklist (some of the JIT's threads), you will see this pattern. This change adds a new kind of thread, called AutomaticThread, that lets you write threads to this pattern while getting automatic thread shutdown for free: instead of just waiting on a condition variable, AutomaticThread will have a timeout that causes the thread to die. The condition variable associated with AutomaticThread, called AutomaticThreadCondition, is smart enough to restart any threads that have decided to stop due to inactivity. The inactivity threshold is current just 1 second. In this patch I only adopt AutomaticThread for ParallelHelperPool. I plan to adopt it in more places soon. * WTF.xcodeproj/project.pbxproj: * wtf/AutomaticThread.cpp: Added. (WTF::AutomaticThreadCondition::create): (WTF::AutomaticThreadCondition::AutomaticThreadCondition): (WTF::AutomaticThreadCondition::~AutomaticThreadCondition): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Added. * wtf/CMakeLists.txt: * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::ParallelHelperPool): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::helperThreadBody): Deleted. (WTF::ParallelHelperPool::waitForClientWithTask): Deleted. * wtf/ParallelHelperPool.h: Canonical link: https://commits.webkit.org/181393@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207480 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-18 20:17:10 +00:00
}
RELEASE_ASSERT(result == WorkResult::Continue);
}
}, m_threadType)->detach();
WTF should make it easier to create threads that die automatically after inactivity https://bugs.webkit.org/show_bug.cgi?id=163576 Reviewed by Andreas Kling. Source/JavaScriptCore: Added a sleepSeconds() function, which made it easier for me to test this change. The WTF changes in this patch change how the JSC GC manages threads: the GC threads will now shut down automatically after 1 second of inactivity. Maybe this will save some memory. * jsc.cpp: (GlobalObject::finishCreation): (functionSleepSeconds): Source/WTF: For a long time now, I've been adding threads to WTF/JSC and each time I do this, I feel guilty because those threads don't shut down when they are inactive. For example, in bug 163562, I need to add a new GC thread. There will be one of them per VM. This means that a JSC API client that starts a lot of VMs will have a lot of threads. I don't think that's good. A common pattern for all of these threads is that they have some well-defined trigger that causes them to run. This trigger has a lock, a condition variable, some logic that determines if there is work to do, and then of course the logic for the thread's actual work. The thread bodies usually look like this: void Thingy::runThread() { for (;;) { Work work; { LockHolder locker(m_lock); while (!hasWork()) m_cond.wait(m_lock); work = takeWork(); } doWork(work); } } If you look at ParallelHelperPool (the GC's threads) and DFG::Worklist (some of the JIT's threads), you will see this pattern. This change adds a new kind of thread, called AutomaticThread, that lets you write threads to this pattern while getting automatic thread shutdown for free: instead of just waiting on a condition variable, AutomaticThread will have a timeout that causes the thread to die. The condition variable associated with AutomaticThread, called AutomaticThreadCondition, is smart enough to restart any threads that have decided to stop due to inactivity. The inactivity threshold is current just 1 second. In this patch I only adopt AutomaticThread for ParallelHelperPool. I plan to adopt it in more places soon. * WTF.xcodeproj/project.pbxproj: * wtf/AutomaticThread.cpp: Added. (WTF::AutomaticThreadCondition::create): (WTF::AutomaticThreadCondition::AutomaticThreadCondition): (WTF::AutomaticThreadCondition::~AutomaticThreadCondition): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Added. * wtf/CMakeLists.txt: * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::ParallelHelperPool): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::helperThreadBody): Deleted. (WTF::ParallelHelperPool::waitForClientWithTask): Deleted. * wtf/ParallelHelperPool.h: Canonical link: https://commits.webkit.org/181393@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207480 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-18 20:17:10 +00:00
}
DFG worklist should use AutomaticThread https://bugs.webkit.org/show_bug.cgi?id=163615 Reviewed by Mark Lam. Source/JavaScriptCore: AutomaticThread is a new feature in WTF that allows you to easily create worker threads that shut down automatically. This changes DFG::Worklist to use AutomaticThread, so that its threads shut down automatically, too. This has the potential to save a lot of memory. This required some improvements to AutomaticThread: Worklist likes to be able to keep state around for the whole lifetime of a thread, and so it likes knowing when threads are born and when they die. I added virtual methods for that. Also, Worklist uses notifyOne() so I added that, too. This looks to be perf-neutral. * dfg/DFGThreadData.cpp: (JSC::DFG::ThreadData::ThreadData): * dfg/DFGThreadData.h: * dfg/DFGWorklist.cpp: (JSC::DFG::Worklist::ThreadBody::ThreadBody): (JSC::DFG::Worklist::Worklist): (JSC::DFG::Worklist::~Worklist): (JSC::DFG::Worklist::finishCreation): (JSC::DFG::Worklist::isActiveForVM): (JSC::DFG::Worklist::enqueue): (JSC::DFG::Worklist::compilationState): (JSC::DFG::Worklist::waitUntilAllPlansForVMAreReady): (JSC::DFG::Worklist::removeAllReadyPlansForVM): (JSC::DFG::Worklist::completeAllReadyPlansForVM): (JSC::DFG::Worklist::rememberCodeBlocks): (JSC::DFG::Worklist::visitWeakReferences): (JSC::DFG::Worklist::removeDeadPlans): (JSC::DFG::Worklist::removeNonCompilingPlansForVM): (JSC::DFG::Worklist::queueLength): (JSC::DFG::Worklist::dump): (JSC::DFG::Worklist::runThread): Deleted. (JSC::DFG::Worklist::threadFunction): Deleted. * dfg/DFGWorklist.h: Source/WTF: This adds new functionality to AutomaticThread to support DFG::Worklist: - AutomaticThread::threadDidStart/threadWillStop virtual methods called at the start and end of a thread's lifetime. This allows Worklist to tie some resources to the life of the thread, and also means that now those resources will naturally free up when the Worklist is not in use. - AutomaticThreadCondition::notifyOne(). This required changes to Condition::notifyOne(). We need to know if the Condition woke up anyone. If it didn't, then we need to launch one of our threads. * wtf/AutomaticThread.cpp: (WTF::AutomaticThreadCondition::notifyOne): (WTF::AutomaticThread::ThreadScope::ThreadScope): (WTF::AutomaticThread::ThreadScope::~ThreadScope): (WTF::AutomaticThread::start): (WTF::AutomaticThread::threadDidStart): (WTF::AutomaticThread::threadWillStop): * wtf/AutomaticThread.h: * wtf/Condition.h: (WTF::ConditionBase::notifyOne): Canonical link: https://commits.webkit.org/181455@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207545 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-19 17:47:30 +00:00
void AutomaticThread::threadDidStart()
{
}
The collector thread should only start when the mutator doesn't have heap access https://bugs.webkit.org/show_bug.cgi?id=167737 Reviewed by Keith Miller. JSTests: Add versions of splay that flash heap access, to simulate what might happen if a third-party app was running concurrent GC. In this case, we might actually start the collector thread. * stress/splay-flash-access-1ms.js: Added. (performance.now): (this.Setup.setup.setup): (this.TearDown.tearDown.tearDown): (Benchmark): (BenchmarkResult): (BenchmarkResult.prototype.valueOf): (BenchmarkSuite): (alert): (Math.random): (BenchmarkSuite.ResetRNG): (RunStep): (BenchmarkSuite.RunSuites): (BenchmarkSuite.CountBenchmarks): (BenchmarkSuite.GeometricMean): (BenchmarkSuite.GeometricMeanTime): (BenchmarkSuite.AverageAbovePercentile): (BenchmarkSuite.GeometricMeanLatency): (BenchmarkSuite.FormatScore): (BenchmarkSuite.prototype.NotifyStep): (BenchmarkSuite.prototype.NotifyResult): (BenchmarkSuite.prototype.NotifyError): (BenchmarkSuite.prototype.RunSingleBenchmark): (RunNextSetup): (RunNextBenchmark): (RunNextTearDown): (BenchmarkSuite.prototype.RunStep): (GeneratePayloadTree): (GenerateKey): (SplayUpdateStats): (InsertNewNode): (SplaySetup): (SplayTearDown): (SplayRun): (SplayTree): (SplayTree.prototype.isEmpty): (SplayTree.prototype.insert): (SplayTree.prototype.remove): (SplayTree.prototype.find): (SplayTree.prototype.findMax): (SplayTree.prototype.findGreatestLessThan): (SplayTree.prototype.exportKeys): (SplayTree.prototype.splay_): (SplayTree.Node): (SplayTree.Node.prototype.traverse_): (jscSetUp): (jscTearDown): (jscRun): (averageAbovePercentile): (printPercentile): * stress/splay-flash-access.js: Added. (performance.now): (this.Setup.setup.setup): (this.TearDown.tearDown.tearDown): (Benchmark): (BenchmarkResult): (BenchmarkResult.prototype.valueOf): (BenchmarkSuite): (alert): (Math.random): (BenchmarkSuite.ResetRNG): (RunStep): (BenchmarkSuite.RunSuites): (BenchmarkSuite.CountBenchmarks): (BenchmarkSuite.GeometricMean): (BenchmarkSuite.GeometricMeanTime): (BenchmarkSuite.AverageAbovePercentile): (BenchmarkSuite.GeometricMeanLatency): (BenchmarkSuite.FormatScore): (BenchmarkSuite.prototype.NotifyStep): (BenchmarkSuite.prototype.NotifyResult): (BenchmarkSuite.prototype.NotifyError): (BenchmarkSuite.prototype.RunSingleBenchmark): (RunNextSetup): (RunNextBenchmark): (RunNextTearDown): (BenchmarkSuite.prototype.RunStep): (GeneratePayloadTree): (GenerateKey): (SplayUpdateStats): (InsertNewNode): (SplaySetup): (SplayTearDown): (SplayRun): (SplayTree): (SplayTree.prototype.isEmpty): (SplayTree.prototype.insert): (SplayTree.prototype.remove): (SplayTree.prototype.find): (SplayTree.prototype.findMax): (SplayTree.prototype.findGreatestLessThan): (SplayTree.prototype.exportKeys): (SplayTree.prototype.splay_): (SplayTree.Node): (SplayTree.Node.prototype.traverse_): (jscSetUp): (jscTearDown): (jscRun): (averageAbovePercentile): (printPercentile): Source/JavaScriptCore: This turns the collector thread's workflow into a state machine, so that the mutator thread can run it directly. This reduces the amount of synchronization we do with the collector thread, and means that most apps will never start the collector thread. The collector thread will still start when we need to finish collecting and we don't have heap access. In this new world, "stopping the world" means relinquishing control of collection to the mutator. This means tracking who is conducting collection. I use the GCConductor enum to say who is conducting. It's either GCConductor::Mutator or GCConductor::Collector. I use the term "conn" to refer to the concept of conducting (having the conn, relinquishing the conn, taking the conn). So, stopping the world means giving the mutator the conn. Releasing heap access means giving the collector the conn. This meant bringing back the conservative scan of the calling thread. It turns out that this scan was too slow to be called on each GC increment because apparently setjmp() now does system calls. So, I wrote our own callee save register saving for the GC. Then I had doubts about whether or not it was correct, so I also made it so that the GC only rarely asks for the register state. I think we still want to use my register saving code instead of setjmp because setjmp seems to save things we don't need, and that could make us overly conservative. It turns out that this new scheduling discipline makes the old space-time scheduler perform better than the new stochastic space-time scheduler on systems with fewer than 4 cores. This is because the mutator having the conn enables us to time the mutator<->collector context switches by polling. The OS is never involved. So, we can use super precise timing. This allows the old space-time schduler to shine like it hadn't before. The splay results imply that this is all a good thing. On 2-core systems, this reduces pause times by 40% and it increases throughput about 5%. On 1-core systems, this reduces pause times by half and reduces throughput by 8%. On 4-or-more-core systems, this doesn't seem to have much effect. * CMakeLists.txt: * JavaScriptCore.xcodeproj/project.pbxproj: * bytecode/CodeBlock.cpp: (JSC::CodeBlock::visitChildren): * dfg/DFGWorklist.cpp: (JSC::DFG::Worklist::ThreadBody::ThreadBody): (JSC::DFG::Worklist::dump): (JSC::DFG::numberOfWorklists): (JSC::DFG::ensureWorklistForIndex): (JSC::DFG::existingWorklistForIndexOrNull): (JSC::DFG::existingWorklistForIndex): * dfg/DFGWorklist.h: (JSC::DFG::numberOfWorklists): Deleted. (JSC::DFG::ensureWorklistForIndex): Deleted. (JSC::DFG::existingWorklistForIndexOrNull): Deleted. (JSC::DFG::existingWorklistForIndex): Deleted. * heap/CollectingScope.h: Added. (JSC::CollectingScope::CollectingScope): (JSC::CollectingScope::~CollectingScope): * heap/CollectorPhase.cpp: Added. (JSC::worldShouldBeSuspended): (WTF::printInternal): * heap/CollectorPhase.h: Added. * heap/EdenGCActivityCallback.cpp: (JSC::EdenGCActivityCallback::lastGCLength): * heap/FullGCActivityCallback.cpp: (JSC::FullGCActivityCallback::doCollection): (JSC::FullGCActivityCallback::lastGCLength): * heap/GCConductor.cpp: Added. (JSC::gcConductorShortName): (WTF::printInternal): * heap/GCConductor.h: Added. * heap/GCFinalizationCallback.cpp: Added. (JSC::GCFinalizationCallback::GCFinalizationCallback): (JSC::GCFinalizationCallback::~GCFinalizationCallback): * heap/GCFinalizationCallback.h: Added. (JSC::GCFinalizationCallbackFuncAdaptor::GCFinalizationCallbackFuncAdaptor): (JSC::createGCFinalizationCallback): * heap/Heap.cpp: (JSC::Heap::Thread::Thread): (JSC::Heap::Heap): (JSC::Heap::lastChanceToFinalize): (JSC::Heap::gatherStackRoots): (JSC::Heap::updateObjectCounts): (JSC::Heap::sweepSynchronously): (JSC::Heap::collectAllGarbage): (JSC::Heap::collectAsync): (JSC::Heap::collectSync): (JSC::Heap::shouldCollectInCollectorThread): (JSC::Heap::collectInCollectorThread): (JSC::Heap::checkConn): (JSC::Heap::runNotRunningPhase): (JSC::Heap::runBeginPhase): (JSC::Heap::runFixpointPhase): (JSC::Heap::runConcurrentPhase): (JSC::Heap::runReloopPhase): (JSC::Heap::runEndPhase): (JSC::Heap::changePhase): (JSC::Heap::finishChangingPhase): (JSC::Heap::stopThePeriphery): (JSC::Heap::resumeThePeriphery): (JSC::Heap::stopTheMutator): (JSC::Heap::resumeTheMutator): (JSC::Heap::stopIfNecessarySlow): (JSC::Heap::collectInMutatorThread): (JSC::Heap::waitForCollector): (JSC::Heap::acquireAccessSlow): (JSC::Heap::releaseAccessSlow): (JSC::Heap::relinquishConn): (JSC::Heap::finishRelinquishingConn): (JSC::Heap::handleNeedFinalize): (JSC::Heap::notifyThreadStopping): (JSC::Heap::finalize): (JSC::Heap::addFinalizationCallback): (JSC::Heap::requestCollection): (JSC::Heap::waitForCollection): (JSC::Heap::updateAllocationLimits): (JSC::Heap::didFinishCollection): (JSC::Heap::collectIfNecessaryOrDefer): (JSC::Heap::notifyIsSafeToCollect): (JSC::Heap::preventCollection): (JSC::Heap::performIncrement): (JSC::Heap::markToFixpoint): Deleted. (JSC::Heap::shouldCollectInThread): Deleted. (JSC::Heap::collectInThread): Deleted. (JSC::Heap::stopTheWorld): Deleted. (JSC::Heap::resumeTheWorld): Deleted. * heap/Heap.h: (JSC::Heap::machineThreads): (JSC::Heap::lastFullGCLength): (JSC::Heap::lastEdenGCLength): (JSC::Heap::increaseLastFullGCLength): * heap/HeapInlines.h: (JSC::Heap::mutatorIsStopped): Deleted. * heap/HeapStatistics.cpp: Removed. * heap/HeapStatistics.h: Removed. * heap/HelpingGCScope.h: Removed. * heap/IncrementalSweeper.cpp: (JSC::IncrementalSweeper::stopSweeping): (JSC::IncrementalSweeper::willFinishSweeping): Deleted. * heap/IncrementalSweeper.h: * heap/MachineStackMarker.cpp: (JSC::MachineThreads::gatherFromCurrentThread): (JSC::MachineThreads::gatherConservativeRoots): (JSC::callWithCurrentThreadState): * heap/MachineStackMarker.h: * heap/MarkedAllocator.cpp: (JSC::MarkedAllocator::allocateSlowCaseImpl): * heap/MarkedBlock.cpp: (JSC::MarkedBlock::Handle::sweep): * heap/MarkedSpace.cpp: (JSC::MarkedSpace::sweep): * heap/MutatorState.cpp: (WTF::printInternal): * heap/MutatorState.h: * heap/RegisterState.h: Added. * heap/RunningScope.h: Added. (JSC::RunningScope::RunningScope): (JSC::RunningScope::~RunningScope): * heap/SlotVisitor.cpp: (JSC::SlotVisitor::SlotVisitor): (JSC::SlotVisitor::drain): (JSC::SlotVisitor::drainFromShared): (JSC::SlotVisitor::drainInParallelPassively): (JSC::SlotVisitor::donateAll): (JSC::SlotVisitor::donate): * heap/SlotVisitor.h: (JSC::SlotVisitor::codeName): * heap/StochasticSpaceTimeMutatorScheduler.cpp: (JSC::StochasticSpaceTimeMutatorScheduler::beginCollection): (JSC::StochasticSpaceTimeMutatorScheduler::synchronousDrainingDidStall): (JSC::StochasticSpaceTimeMutatorScheduler::timeToStop): * heap/SweepingScope.h: Added. (JSC::SweepingScope::SweepingScope): (JSC::SweepingScope::~SweepingScope): * jit/JITWorklist.cpp: (JSC::JITWorklist::Thread::Thread): * jsc.cpp: (GlobalObject::finishCreation): (functionFlashHeapAccess): * runtime/InitializeThreading.cpp: (JSC::initializeThreading): * runtime/JSCellInlines.h: (JSC::JSCell::classInfo): * runtime/Options.cpp: (JSC::overrideDefaults): * runtime/Options.h: * runtime/TestRunnerUtils.cpp: (JSC::finalizeStatsAtEndOfTesting): Source/WebCore: Added new tests in JSTests. The WebCore changes involve: - Refactoring around new header discipline. - Adding crazy GC APIs to window.internals to enable us to test the GC's runloop discipline. * ForwardingHeaders/heap/GCFinalizationCallback.h: Added. * ForwardingHeaders/heap/IncrementalSweeper.h: Added. * ForwardingHeaders/heap/MachineStackMarker.h: Added. * ForwardingHeaders/heap/RunningScope.h: Added. * bindings/js/CommonVM.cpp: * testing/Internals.cpp: (WebCore::Internals::parserMetaData): (WebCore::Internals::isReadableStreamDisturbed): (WebCore::Internals::isGCRunning): (WebCore::Internals::addGCFinalizationCallback): (WebCore::Internals::stopSweeping): (WebCore::Internals::startSweeping): * testing/Internals.h: * testing/Internals.idl: Source/WTF: Extend the use of AbstractLocker so that we can use more locking idioms. * wtf/AutomaticThread.cpp: (WTF::AutomaticThreadCondition::notifyOne): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::tryStop): (WTF::AutomaticThread::isWaiting): (WTF::AutomaticThread::notify): (WTF::AutomaticThread::start): (WTF::AutomaticThread::threadIsStopping): * wtf/AutomaticThread.h: * wtf/NumberOfCores.cpp: (WTF::numberOfProcessorCores): * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::claimTask): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::hasClientWithTask): (WTF::ParallelHelperPool::getClientWithTask): * wtf/ParallelHelperPool.h: Tools: Make more tests collect continuously. * Scripts/run-jsc-stress-tests: Canonical link: https://commits.webkit.org/185692@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@212778 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-02-22 00:58:15 +00:00
void AutomaticThread::threadIsStopping(const AbstractLocker&)
DFG worklist should use AutomaticThread https://bugs.webkit.org/show_bug.cgi?id=163615 Reviewed by Mark Lam. Source/JavaScriptCore: AutomaticThread is a new feature in WTF that allows you to easily create worker threads that shut down automatically. This changes DFG::Worklist to use AutomaticThread, so that its threads shut down automatically, too. This has the potential to save a lot of memory. This required some improvements to AutomaticThread: Worklist likes to be able to keep state around for the whole lifetime of a thread, and so it likes knowing when threads are born and when they die. I added virtual methods for that. Also, Worklist uses notifyOne() so I added that, too. This looks to be perf-neutral. * dfg/DFGThreadData.cpp: (JSC::DFG::ThreadData::ThreadData): * dfg/DFGThreadData.h: * dfg/DFGWorklist.cpp: (JSC::DFG::Worklist::ThreadBody::ThreadBody): (JSC::DFG::Worklist::Worklist): (JSC::DFG::Worklist::~Worklist): (JSC::DFG::Worklist::finishCreation): (JSC::DFG::Worklist::isActiveForVM): (JSC::DFG::Worklist::enqueue): (JSC::DFG::Worklist::compilationState): (JSC::DFG::Worklist::waitUntilAllPlansForVMAreReady): (JSC::DFG::Worklist::removeAllReadyPlansForVM): (JSC::DFG::Worklist::completeAllReadyPlansForVM): (JSC::DFG::Worklist::rememberCodeBlocks): (JSC::DFG::Worklist::visitWeakReferences): (JSC::DFG::Worklist::removeDeadPlans): (JSC::DFG::Worklist::removeNonCompilingPlansForVM): (JSC::DFG::Worklist::queueLength): (JSC::DFG::Worklist::dump): (JSC::DFG::Worklist::runThread): Deleted. (JSC::DFG::Worklist::threadFunction): Deleted. * dfg/DFGWorklist.h: Source/WTF: This adds new functionality to AutomaticThread to support DFG::Worklist: - AutomaticThread::threadDidStart/threadWillStop virtual methods called at the start and end of a thread's lifetime. This allows Worklist to tie some resources to the life of the thread, and also means that now those resources will naturally free up when the Worklist is not in use. - AutomaticThreadCondition::notifyOne(). This required changes to Condition::notifyOne(). We need to know if the Condition woke up anyone. If it didn't, then we need to launch one of our threads. * wtf/AutomaticThread.cpp: (WTF::AutomaticThreadCondition::notifyOne): (WTF::AutomaticThread::ThreadScope::ThreadScope): (WTF::AutomaticThread::ThreadScope::~ThreadScope): (WTF::AutomaticThread::start): (WTF::AutomaticThread::threadDidStart): (WTF::AutomaticThread::threadWillStop): * wtf/AutomaticThread.h: * wtf/Condition.h: (WTF::ConditionBase::notifyOne): Canonical link: https://commits.webkit.org/181455@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207545 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-19 17:47:30 +00:00
{
}
WTF should make it easier to create threads that die automatically after inactivity https://bugs.webkit.org/show_bug.cgi?id=163576 Reviewed by Andreas Kling. Source/JavaScriptCore: Added a sleepSeconds() function, which made it easier for me to test this change. The WTF changes in this patch change how the JSC GC manages threads: the GC threads will now shut down automatically after 1 second of inactivity. Maybe this will save some memory. * jsc.cpp: (GlobalObject::finishCreation): (functionSleepSeconds): Source/WTF: For a long time now, I've been adding threads to WTF/JSC and each time I do this, I feel guilty because those threads don't shut down when they are inactive. For example, in bug 163562, I need to add a new GC thread. There will be one of them per VM. This means that a JSC API client that starts a lot of VMs will have a lot of threads. I don't think that's good. A common pattern for all of these threads is that they have some well-defined trigger that causes them to run. This trigger has a lock, a condition variable, some logic that determines if there is work to do, and then of course the logic for the thread's actual work. The thread bodies usually look like this: void Thingy::runThread() { for (;;) { Work work; { LockHolder locker(m_lock); while (!hasWork()) m_cond.wait(m_lock); work = takeWork(); } doWork(work); } } If you look at ParallelHelperPool (the GC's threads) and DFG::Worklist (some of the JIT's threads), you will see this pattern. This change adds a new kind of thread, called AutomaticThread, that lets you write threads to this pattern while getting automatic thread shutdown for free: instead of just waiting on a condition variable, AutomaticThread will have a timeout that causes the thread to die. The condition variable associated with AutomaticThread, called AutomaticThreadCondition, is smart enough to restart any threads that have decided to stop due to inactivity. The inactivity threshold is current just 1 second. In this patch I only adopt AutomaticThread for ParallelHelperPool. I plan to adopt it in more places soon. * WTF.xcodeproj/project.pbxproj: * wtf/AutomaticThread.cpp: Added. (WTF::AutomaticThreadCondition::create): (WTF::AutomaticThreadCondition::AutomaticThreadCondition): (WTF::AutomaticThreadCondition::~AutomaticThreadCondition): (WTF::AutomaticThreadCondition::notifyAll): (WTF::AutomaticThreadCondition::add): (WTF::AutomaticThreadCondition::remove): (WTF::AutomaticThreadCondition::contains): (WTF::AutomaticThread::AutomaticThread): (WTF::AutomaticThread::~AutomaticThread): (WTF::AutomaticThread::join): (WTF::AutomaticThread::start): * wtf/AutomaticThread.h: Added. * wtf/CMakeLists.txt: * wtf/ParallelHelperPool.cpp: (WTF::ParallelHelperClient::ParallelHelperClient): (WTF::ParallelHelperClient::~ParallelHelperClient): (WTF::ParallelHelperClient::setTask): (WTF::ParallelHelperClient::finish): (WTF::ParallelHelperClient::doSomeHelping): (WTF::ParallelHelperClient::runTask): (WTF::ParallelHelperPool::ParallelHelperPool): (WTF::ParallelHelperPool::~ParallelHelperPool): (WTF::ParallelHelperPool::ensureThreads): (WTF::ParallelHelperPool::doSomeHelping): (WTF::ParallelHelperPool::Thread::Thread): (WTF::ParallelHelperPool::didMakeWorkAvailable): (WTF::ParallelHelperPool::helperThreadBody): Deleted. (WTF::ParallelHelperPool::waitForClientWithTask): Deleted. * wtf/ParallelHelperPool.h: Canonical link: https://commits.webkit.org/181393@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207480 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-18 20:17:10 +00:00
} // namespace WTF