- Revision
- 153175
- Author
- [email protected]
- Date
- 2013-07-24 21:00:50 -0700 (Wed, 24 Jul 2013)
Log Message
fourthTier: It should be possible to use more than one compiler thread
https://bugs.webkit.org/show_bug.cgi?id=116630
Reviewed by Mark Hahnenberg.
This gives us the ability to use more compiler threads, but doesn't actually
enable the functionality because it isn't a speed-up on any benchmark. It can
even be a slow-down. This also adds the ability to disable concurrent
compilation if we're on a uniprocessor machine, and adds more logging to the
worklist code to allow us to investigate how many threads are active. It
appears that even on the most compiler-heavy benchmarks, we never have enough
work for more than 4 threads, and even then the 4 threads are all active for
a short time.
Something that having more threads does accomplish is that it shakes out bugs.
This patch fixes a bug with Watchpoint not being thread-safe ref-counted,
which enabling 7 compilation threads did catch.
As it stands, this patch is performance-neutral and just fixes bugs and adds
some options.
* bytecode/Watchpoint.h:
* dfg/DFGCommon.h:
(JSC::DFG::enableConcurrentJIT):
* dfg/DFGWorklist.cpp:
(JSC::DFG::Worklist::Worklist):
(JSC::DFG::Worklist::~Worklist):
(JSC::DFG::Worklist::finishCreation):
(JSC::DFG::Worklist::create):
(JSC::DFG::Worklist::enqueue):
(JSC::DFG::Worklist::waitUntilAllPlansForVMAreReady):
(JSC::DFG::Worklist::dump):
(JSC::DFG::Worklist::runThread):
(JSC::DFG::initializeGlobalWorklistOnce):
* dfg/DFGWorklist.h:
* runtime/Options.cpp:
(JSC::computeNumberOfWorkerThreads):
(JSC):
(JSC::computeNumberOfGCMarkers):
* runtime/Options.h:
(JSC):
Modified Paths
Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (153174 => 153175)
--- trunk/Source/_javascript_Core/ChangeLog 2013-07-25 04:00:48 UTC (rev 153174)
+++ trunk/Source/_javascript_Core/ChangeLog 2013-07-25 04:00:50 UTC (rev 153175)
@@ -1,5 +1,49 @@
2013-05-22 Filip Pizlo <[email protected]>
+ fourthTier: It should be possible to use more than one compiler thread
+ https://bugs.webkit.org/show_bug.cgi?id=116630
+
+ Reviewed by Mark Hahnenberg.
+
+ This gives us the ability to use more compiler threads, but doesn't actually
+ enable the functionality because it isn't a speed-up on any benchmark. It can
+ even be a slow-down. This also adds the ability to disable concurrent
+ compilation if we're on a uniprocessor machine, and adds more logging to the
+ worklist code to allow us to investigate how many threads are active. It
+ appears that even on the most compiler-heavy benchmarks, we never have enough
+ work for more than 4 threads, and even then the 4 threads are all active for
+ a short time.
+
+ Something that having more threads does accomplish is that it shakes out bugs.
+ This patch fixes a bug with Watchpoint not being thread-safe ref-counted,
+ which enabling 7 compilation threads did catch.
+
+ As it stands, this patch is performance-neutral and just fixes bugs and adds
+ some options.
+
+ * bytecode/Watchpoint.h:
+ * dfg/DFGCommon.h:
+ (JSC::DFG::enableConcurrentJIT):
+ * dfg/DFGWorklist.cpp:
+ (JSC::DFG::Worklist::Worklist):
+ (JSC::DFG::Worklist::~Worklist):
+ (JSC::DFG::Worklist::finishCreation):
+ (JSC::DFG::Worklist::create):
+ (JSC::DFG::Worklist::enqueue):
+ (JSC::DFG::Worklist::waitUntilAllPlansForVMAreReady):
+ (JSC::DFG::Worklist::dump):
+ (JSC::DFG::Worklist::runThread):
+ (JSC::DFG::initializeGlobalWorklistOnce):
+ * dfg/DFGWorklist.h:
+ * runtime/Options.cpp:
+ (JSC::computeNumberOfWorkerThreads):
+ (JSC):
+ (JSC::computeNumberOfGCMarkers):
+ * runtime/Options.h:
+ (JSC):
+
+2013-05-22 Filip Pizlo <[email protected]>
+
fourthTier: FTL shouldn't use the LLVM global context, and should instead create its own context for each compilation
https://bugs.webkit.org/show_bug.cgi?id=116631
Modified: trunk/Source/_javascript_Core/bytecode/Watchpoint.h (153174 => 153175)
--- trunk/Source/_javascript_Core/bytecode/Watchpoint.h 2013-07-25 04:00:48 UTC (rev 153174)
+++ trunk/Source/_javascript_Core/bytecode/Watchpoint.h 2013-07-25 04:00:50 UTC (rev 153175)
@@ -26,8 +26,8 @@
#ifndef Watchpoint_h
#define Watchpoint_h
-#include <wtf/RefCounted.h>
#include <wtf/SentinelLinkedList.h>
+#include <wtf/ThreadSafeRefCounted.h>
namespace JSC {
@@ -49,7 +49,7 @@
class InlineWatchpointSet;
-class WatchpointSet : public RefCounted<WatchpointSet> {
+class WatchpointSet : public ThreadSafeRefCounted<WatchpointSet> {
public:
WatchpointSet(InitialWatchpointSetMode);
~WatchpointSet();
Modified: trunk/Source/_javascript_Core/dfg/DFGCommon.h (153174 => 153175)
--- trunk/Source/_javascript_Core/dfg/DFGCommon.h 2013-07-25 04:00:48 UTC (rev 153174)
+++ trunk/Source/_javascript_Core/dfg/DFGCommon.h 2013-07-25 04:00:50 UTC (rev 153175)
@@ -139,7 +139,7 @@
inline bool enableConcurrentJIT()
{
#if ENABLE(CONCURRENT_JIT)
- return Options::enableConcurrentJIT();
+ return Options::enableConcurrentJIT() && Options::numberOfCompilerThreads();
#else
return false;
#endif
Modified: trunk/Source/_javascript_Core/dfg/DFGWorklist.cpp (153174 => 153175)
--- trunk/Source/_javascript_Core/dfg/DFGWorklist.cpp 2013-07-25 04:00:48 UTC (rev 153174)
+++ trunk/Source/_javascript_Core/dfg/DFGWorklist.cpp 2013-07-25 04:00:50 UTC (rev 153175)
@@ -35,24 +35,34 @@
namespace JSC { namespace DFG {
Worklist::Worklist()
+ : m_numberOfActiveThreads(0)
{
}
Worklist::~Worklist()
{
- m_queue.append(nullptr); // Use null plan to indicate that we want the thread to terminate.
- waitForThreadCompletion(m_thread);
+ {
+ MutexLocker locker(m_lock);
+ for (unsigned i = m_threads.size(); i--;)
+ m_queue.append(nullptr); // Use null plan to indicate that we want the thread to terminate.
+ m_planEnqueued.broadcast();
+ }
+ for (unsigned i = m_threads.size(); i--;)
+ waitForThreadCompletion(m_threads[i]);
+ ASSERT(!m_numberOfActiveThreads);
}
-void Worklist::finishCreation()
+void Worklist::finishCreation(unsigned numberOfThreads)
{
- m_thread = createThread(threadFunction, this, "JSC Compilation Thread");
+ RELEASE_ASSERT(numberOfThreads);
+ for (unsigned i = numberOfThreads; i--;)
+ m_threads.append(createThread(threadFunction, this, "JSC Compilation Thread"));
}
-PassRefPtr<Worklist> Worklist::create()
+PassRefPtr<Worklist> Worklist::create(unsigned numberOfThreads)
{
RefPtr<Worklist> result = adoptRef(new Worklist());
- result->finishCreation();
+ result->finishCreation(numberOfThreads);
return result;
}
@@ -67,7 +77,7 @@
ASSERT(m_plans.find(plan->key()) == m_plans.end());
m_plans.add(plan->key(), plan);
m_queue.append(plan);
- m_condition.broadcast();
+ m_planEnqueued.signal();
}
Worklist::State Worklist::compilationState(CodeBlock* profiledBlock)
@@ -110,7 +120,7 @@
if (allAreCompiled)
break;
- m_condition.wait(m_lock);
+ m_planCompiled.wait(m_lock);
}
}
@@ -195,11 +205,15 @@
{
out.print(
"Worklist(", RawPointer(this), ")[Queue Length = ", m_queue.size(),
- ", Map Size = ", m_plans.size(), "]");
+ ", Map Size = ", m_plans.size(), ", Num Ready = ", m_readyPlans.size(),
+ ", Num Active Threads = ", m_numberOfActiveThreads, "/", m_threads.size(), "]");
}
void Worklist::runThread()
{
+ if (Options::verboseCompilationQueue())
+ dataLog(*this, ": Thread started\n");
+
LongLivedState longLivedState;
for (;;) {
@@ -207,13 +221,21 @@
{
MutexLocker locker(m_lock);
while (m_queue.isEmpty())
- m_condition.wait(m_lock);
+ m_planEnqueued.wait(m_lock);
plan = m_queue.takeFirst();
+ if (plan)
+ m_numberOfActiveThreads++;
}
- if (!plan)
+ if (!plan) {
+ if (Options::verboseCompilationQueue())
+ dataLog(*this, ": Thread shutting down\n");
return;
+ }
+ if (Options::verboseCompilationQueue())
+ dataLog(*this, ": Compiling ", *plan->key(), " asynchronously\n");
+
plan->compileInThread(longLivedState);
{
@@ -228,7 +250,8 @@
m_readyPlans.append(plan);
- m_condition.broadcast();
+ m_planCompiled.broadcast();
+ m_numberOfActiveThreads--;
}
}
}
@@ -243,7 +266,14 @@
static void initializeGlobalWorklistOnce()
{
- theGlobalWorklist = Worklist::create().leakRef();
+ unsigned numberOfThreads;
+
+ if (Options::useExperimentalFTL())
+ numberOfThreads = 1; // We don't yet use LLVM in a thread-safe way.
+ else
+ numberOfThreads = Options::numberOfCompilerThreads();
+
+ theGlobalWorklist = Worklist::create(numberOfThreads).leakRef();
}
Worklist* globalWorklist()
Modified: trunk/Source/_javascript_Core/dfg/DFGWorklist.h (153174 => 153175)
--- trunk/Source/_javascript_Core/dfg/DFGWorklist.h 2013-07-25 04:00:48 UTC (rev 153174)
+++ trunk/Source/_javascript_Core/dfg/DFGWorklist.h 2013-07-25 04:00:50 UTC (rev 153175)
@@ -45,7 +45,7 @@
~Worklist();
- static PassRefPtr<Worklist> create();
+ static PassRefPtr<Worklist> create(unsigned numberOfThreads);
void enqueue(PassRefPtr<Plan>);
@@ -65,7 +65,7 @@
private:
Worklist();
- void finishCreation();
+ void finishCreation(unsigned numberOfThreads);
void runThread();
static void threadFunction(void* argument);
@@ -89,11 +89,10 @@
Vector<RefPtr<Plan>, 16> m_readyPlans;
mutable Mutex m_lock;
- // We broadcast on this condition whenever:
- // - Something is enqueued.
- // - Something is completed.
- ThreadCondition m_condition;
- ThreadIdentifier m_thread;
+ ThreadCondition m_planEnqueued;
+ ThreadCondition m_planCompiled;
+ Vector<ThreadIdentifier> m_threads;
+ unsigned m_numberOfActiveThreads;
};
// For now we use a single global worklist. It's not clear that this
Modified: trunk/Source/_javascript_Core/runtime/Options.cpp (153174 => 153175)
--- trunk/Source/_javascript_Core/runtime/Options.cpp 2013-07-25 04:00:48 UTC (rev 153174)
+++ trunk/Source/_javascript_Core/runtime/Options.cpp 2013-07-25 04:00:50 UTC (rev 153175)
@@ -91,22 +91,26 @@
#endif
}
-static unsigned computeNumberOfGCMarkers(int maxNumberOfGCMarkers)
+static unsigned computeNumberOfWorkerThreads(int maxNumberOfWorkerThreads)
{
- int cpusToUse = 1;
+ int cpusToUse = std::min(WTF::numberOfProcessorCores(), maxNumberOfWorkerThreads);
-#if ENABLE(PARALLEL_GC)
- cpusToUse = std::min(WTF::numberOfProcessorCores(), maxNumberOfGCMarkers);
-
// Be paranoid, it is the OS we're dealing with, after all.
ASSERT(cpusToUse >= 1);
if (cpusToUse < 1)
cpusToUse = 1;
+
+ return cpusToUse;
+}
+
+static unsigned computeNumberOfGCMarkers(unsigned maxNumberOfGCMarkers)
+{
+#if ENABLE(PARALLEL_GC)
+ return computeNumberOfWorkerThreads(maxNumberOfGCMarkers);
#else
UNUSED_PARAM(maxNumberOfGCMarkers);
+ return 1;
#endif
-
- return cpusToUse;
}
bool OptionRange::init(const char* rangeString)
Modified: trunk/Source/_javascript_Core/runtime/Options.h (153174 => 153175)
--- trunk/Source/_javascript_Core/runtime/Options.h 2013-07-25 04:00:48 UTC (rev 153174)
+++ trunk/Source/_javascript_Core/runtime/Options.h 2013-07-25 04:00:50 UTC (rev 153175)
@@ -121,6 +121,7 @@
v(unsigned, llvmOptimizationLevel, 2) \
\
v(bool, enableConcurrentJIT, true) \
+ v(unsigned, numberOfCompilerThreads, computeNumberOfWorkerThreads(2) - 1) \
\
v(bool, enableProfiler, false) \
\