]>
Commit | Line | Data |
---|---|---|
81345200 A |
1 | /* |
2 | * Copyright (C) 2013, 2014 Apple Inc. All rights reserved. | |
3 | * | |
4 | * Redistribution and use in source and binary forms, with or without | |
5 | * modification, are permitted provided that the following conditions | |
6 | * are met: | |
7 | * 1. Redistributions of source code must retain the above copyright | |
8 | * notice, this list of conditions and the following disclaimer. | |
9 | * 2. Redistributions in binary form must reproduce the above copyright | |
10 | * notice, this list of conditions and the following disclaimer in the | |
11 | * documentation and/or other materials provided with the distribution. | |
12 | * | |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | |
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 | */ | |
25 | ||
26 | #ifndef DFGWorklist_h | |
27 | #define DFGWorklist_h | |
28 | ||
29 | #if ENABLE(DFG_JIT) | |
30 | ||
31 | #include "DFGPlan.h" | |
32 | #include "DFGThreadData.h" | |
33 | #include <wtf/Deque.h> | |
34 | #include <wtf/HashMap.h> | |
35 | #include <wtf/Noncopyable.h> | |
81345200 A |
36 | #include <wtf/ThreadingPrimitives.h> |
37 | ||
38 | namespace JSC { | |
39 | ||
40 | class CodeBlockSet; | |
41 | class SlotVisitor; | |
42 | ||
43 | namespace DFG { | |
44 | ||
45 | class Worklist : public RefCounted<Worklist> { | |
46 | public: | |
47 | enum State { NotKnown, Compiling, Compiled }; | |
48 | ||
49 | ~Worklist(); | |
50 | ||
ed1e77d3 | 51 | static Ref<Worklist> create(CString worklistName, unsigned numberOfThreads, int relativePriority = 0); |
81345200 A |
52 | |
53 | void enqueue(PassRefPtr<Plan>); | |
54 | ||
55 | // This is equivalent to: | |
56 | // worklist->waitUntilAllPlansForVMAreReady(vm); | |
57 | // worklist->completeAllReadyPlansForVM(vm); | |
58 | void completeAllPlansForVM(VM&); | |
59 | ||
60 | void waitUntilAllPlansForVMAreReady(VM&); | |
61 | State completeAllReadyPlansForVM(VM&, CompilationKey = CompilationKey()); | |
62 | void removeAllReadyPlansForVM(VM&); | |
63 | ||
64 | State compilationState(CompilationKey); | |
65 | ||
66 | size_t queueLength(); | |
67 | ||
68 | void suspendAllThreads(); | |
69 | void resumeAllThreads(); | |
70 | ||
71 | bool isActiveForVM(VM&) const; | |
72 | ||
73 | // Only called on the main thread after suspending all threads. | |
74 | void visitWeakReferences(SlotVisitor&, CodeBlockSet&); | |
75 | void removeDeadPlans(VM&); | |
76 | ||
77 | void dump(PrintStream&) const; | |
78 | ||
79 | private: | |
80 | Worklist(CString worklistName); | |
81 | void finishCreation(unsigned numberOfThreads, int); | |
82 | ||
83 | void runThread(ThreadData*); | |
84 | static void threadFunction(void* argument); | |
85 | ||
86 | void removeAllReadyPlansForVM(VM&, Vector<RefPtr<Plan>, 8>&); | |
87 | ||
88 | void dump(const MutexLocker&, PrintStream&) const; | |
89 | ||
90 | CString m_threadName; | |
91 | ||
92 | // Used to inform the thread about what work there is left to do. | |
93 | Deque<RefPtr<Plan>> m_queue; | |
94 | ||
95 | // Used to answer questions about the current state of a code block. This | |
96 | // is particularly great for the cti_optimize OSR slow path, which wants | |
97 | // to know: did I get here because a better version of me just got | |
98 | // compiled? | |
99 | typedef HashMap<CompilationKey, RefPtr<Plan>> PlanMap; | |
100 | PlanMap m_plans; | |
101 | ||
102 | // Used to quickly find which plans have been compiled and are ready to | |
103 | // be completed. | |
104 | Vector<RefPtr<Plan>, 16> m_readyPlans; | |
105 | ||
106 | Mutex m_suspensionLock; | |
107 | ||
108 | mutable Mutex m_lock; | |
109 | ThreadCondition m_planEnqueued; | |
110 | ThreadCondition m_planCompiled; | |
111 | ||
112 | Vector<std::unique_ptr<ThreadData>> m_threads; | |
113 | unsigned m_numberOfActiveThreads; | |
114 | }; | |
115 | ||
116 | // For DFGMode compilations. | |
117 | Worklist* ensureGlobalDFGWorklist(); | |
118 | Worklist* existingGlobalDFGWorklistOrNull(); | |
119 | ||
120 | // For FTLMode and FTLForOSREntryMode compilations. | |
121 | Worklist* ensureGlobalFTLWorklist(); | |
122 | Worklist* existingGlobalFTLWorklistOrNull(); | |
123 | ||
124 | Worklist* ensureGlobalWorklistFor(CompilationMode); | |
125 | ||
126 | // Simplify doing things for all worklists. | |
127 | inline unsigned numberOfWorklists() { return 2; } | |
128 | inline Worklist* worklistForIndexOrNull(unsigned index) | |
129 | { | |
130 | switch (index) { | |
131 | case 0: | |
132 | return existingGlobalDFGWorklistOrNull(); | |
133 | case 1: | |
134 | return existingGlobalFTLWorklistOrNull(); | |
135 | default: | |
136 | RELEASE_ASSERT_NOT_REACHED(); | |
137 | return 0; | |
138 | } | |
139 | } | |
140 | ||
141 | } } // namespace JSC::DFG | |
142 | ||
143 | #endif // ENABLE(DFG_JIT) | |
144 | ||
145 | #endif // DFGWorklist_h | |
146 |