summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/dfg/DFGWorklist.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/JavaScriptCore/dfg/DFGWorklist.h')
-rw-r--r--Source/JavaScriptCore/dfg/DFGWorklist.h99
1 files changed, 70 insertions, 29 deletions
diff --git a/Source/JavaScriptCore/dfg/DFGWorklist.h b/Source/JavaScriptCore/dfg/DFGWorklist.h
index d3419f0a9..eb8282cd4 100644
--- a/Source/JavaScriptCore/dfg/DFGWorklist.h
+++ b/Source/JavaScriptCore/dfg/DFGWorklist.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-2017 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -23,21 +23,24 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef DFGWorklist_h
-#define DFGWorklist_h
-
-#include <wtf/Platform.h>
-
-#if ENABLE(DFG_JIT)
+#pragma once
#include "DFGPlan.h"
+#include "DFGThreadData.h"
+#include <wtf/AutomaticThread.h>
+#include <wtf/Condition.h>
#include <wtf/Deque.h>
#include <wtf/HashMap.h>
+#include <wtf/Lock.h>
#include <wtf/Noncopyable.h>
-#include <wtf/PassOwnPtr.h>
-#include <wtf/ThreadingPrimitives.h>
-namespace JSC { namespace DFG {
+namespace JSC {
+
+class SlotVisitor;
+
+namespace DFG {
+
+#if ENABLE(DFG_JIT)
class Worklist : public RefCounted<Worklist> {
public:
@@ -45,15 +48,18 @@ public:
~Worklist();
- static PassRefPtr<Worklist> create(unsigned numberOfThreads);
+ static Ref<Worklist> create(CString worklistName, unsigned numberOfThreads, int relativePriority = 0);
- void enqueue(PassRefPtr<Plan>);
+ void enqueue(Ref<Plan>&&);
// This is equivalent to:
// worklist->waitUntilAllPlansForVMAreReady(vm);
// worklist->completeAllReadyPlansForVM(vm);
void completeAllPlansForVM(VM&);
-
+
+ template<typename Func>
+ void iterateCodeBlocksForGC(VM&, const Func&);
+
void waitUntilAllPlansForVMAreReady(VM&);
State completeAllReadyPlansForVM(VM&, CompilationKey = CompilationKey());
void removeAllReadyPlansForVM(VM&);
@@ -61,21 +67,38 @@ public:
State compilationState(CompilationKey);
size_t queueLength();
+
+ void suspendAllThreads();
+ void resumeAllThreads();
+
+ bool isActiveForVM(VM&) const;
+
+ // Only called on the main thread after suspending all threads.
+ void visitWeakReferences(SlotVisitor&);
+ void removeDeadPlans(VM&);
+
+ void removeNonCompilingPlansForVM(VM&);
+
void dump(PrintStream&) const;
private:
- Worklist();
- void finishCreation(unsigned numberOfThreads);
+ Worklist(CString worklistName);
+ void finishCreation(unsigned numberOfThreads, int);
+
+ class ThreadBody;
+ friend class ThreadBody;
- void runThread();
+ void runThread(ThreadData*);
static void threadFunction(void* argument);
void removeAllReadyPlansForVM(VM&, Vector<RefPtr<Plan>, 8>&);
- void dump(const MutexLocker&, PrintStream&) const;
-
+ void dump(const AbstractLocker&, PrintStream&) const;
+
+ CString m_threadName;
+
// Used to inform the thread about what work there is left to do.
- Deque<RefPtr<Plan>, 16> m_queue;
+ Deque<RefPtr<Plan>> m_queue;
// Used to answer questions about the current state of a code block. This
// is particularly great for the cti_optimize OSR slow path, which wants
@@ -87,22 +110,40 @@ private:
// Used to quickly find which plans have been compiled and are ready to
// be completed.
Vector<RefPtr<Plan>, 16> m_readyPlans;
+
+ Lock m_suspensionLock;
+
+ Box<Lock> m_lock;
+ RefPtr<AutomaticThreadCondition> m_planEnqueued;
+ Condition m_planCompiled;
- mutable Mutex m_lock;
- ThreadCondition m_planEnqueued;
- ThreadCondition m_planCompiled;
- Vector<ThreadIdentifier> m_threads;
+ Vector<std::unique_ptr<ThreadData>> m_threads;
unsigned m_numberOfActiveThreads;
};
-// For now we use a single global worklist. It's not clear that this
-// is the right thing to do, but it is what we do, for now. This function
-// will lazily create one when it's needed.
-Worklist* globalWorklist();
+// For DFGMode compilations.
+Worklist& ensureGlobalDFGWorklist();
+Worklist* existingGlobalDFGWorklistOrNull();
-} } // namespace JSC::DFG
+// For FTLMode and FTLForOSREntryMode compilations.
+Worklist& ensureGlobalFTLWorklist();
+Worklist* existingGlobalFTLWorklistOrNull();
+
+Worklist& ensureGlobalWorklistFor(CompilationMode);
+
+// Simplify doing things for all worklists.
+unsigned numberOfWorklists();
+Worklist& ensureWorklistForIndex(unsigned index);
+Worklist* existingWorklistForIndexOrNull(unsigned index);
+Worklist& existingWorklistForIndex(unsigned index);
#endif // ENABLE(DFG_JIT)
-#endif // DFGWorklist_h
+void completeAllPlansForVM(VM&);
+void markCodeBlocks(VM&, SlotVisitor&);
+
+template<typename Func>
+void iterateCodeBlocksForGC(VM&, const Func&);
+
+} } // namespace JSC::DFG