12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_COMPILER_COMPILEBROKER_HPP
26 #define SHARE_VM_COMPILER_COMPILEBROKER_HPP
27
28 #include "ci/compilerInterface.hpp"
29 #include "compiler/abstractCompiler.hpp"
30 #include "compiler/compileTask.hpp"
31 #include "runtime/perfData.hpp"
32
33 class nmethod;
34 class nmethodLocker;
35
36 // CompilerCounters
37 //
38 // Per Compiler Performance Counters.
39 //
40 class CompilerCounters : public CHeapObj<mtCompiler> {
41
42 public:
43 enum {
44 cmname_buffer_length = 160
45 };
46
47 private:
48
49 char _current_method[cmname_buffer_length];
50 PerfStringVariable* _perf_current_method;
51
121 void mark_on_stack();
122 void free_all();
123 void print_tty();
124 void print(outputStream* st = tty);
125
126 ~CompileQueue() {
127 assert (is_empty(), " Compile Queue must be empty");
128 }
129 };
130
131 // CompileTaskWrapper
132 //
133 // Assign this task to the current thread. Deallocate the task
134 // when the compilation is complete.
135 class CompileTaskWrapper : StackObj {
136 public:
137 CompileTaskWrapper(CompileTask* task);
138 ~CompileTaskWrapper();
139 };
140
141
142 // Compilation
143 //
144 // The broker for all compilation requests.
145 class CompileBroker: AllStatic {
146 friend class Threads;
147 friend class CompileTaskWrapper;
148
149 public:
150 enum {
151 name_buffer_length = 100
152 };
153
154 // Compile type Information for print_last_compile() and CompilerCounters
155 enum { no_compile, normal_compile, osr_compile, native_compile };
156 static int assign_compile_id (methodHandle method, int osr_bci);
157
158
159 private:
160 static bool _initialized;
161 static volatile bool _should_block;
162
163 // This flag can be used to stop compilation or turn it back on
164 static volatile jint _should_compile_new_jobs;
165
166 // The installed compiler(s)
167 static AbstractCompiler* _compilers[2];
168
169 // These counters are used for assigning id's to each compilation
170 static volatile jint _compilation_id;
171 static volatile jint _osr_compilation_id;
172
173 static int _last_compile_type;
174 static int _last_compile_level;
175 static char _last_method_compiled[name_buffer_length];
176
177 static CompileQueue* _c2_compile_queue;
178 static CompileQueue* _c1_compile_queue;
179
180 // performance counters
181 static PerfCounter* _perf_total_compilation;
182 static PerfCounter* _perf_native_compilation;
183 static PerfCounter* _perf_osr_compilation;
184 static PerfCounter* _perf_standard_compilation;
185
186 static PerfCounter* _perf_total_bailout_count;
187 static PerfCounter* _perf_total_invalidated_count;
188 static PerfCounter* _perf_total_compile_count;
229 static bool compilation_is_complete (methodHandle method, int osr_bci, int comp_level);
230 static bool compilation_is_prohibited(methodHandle method, int osr_bci, int comp_level);
231 static bool is_compile_blocking();
232 static void preload_classes (methodHandle method, TRAPS);
233
234 static CompileTask* create_compile_task(CompileQueue* queue,
235 int compile_id,
236 methodHandle method,
237 int osr_bci,
238 int comp_level,
239 methodHandle hot_method,
240 int hot_count,
241 const char* comment,
242 bool blocking);
243 static void wait_for_completion(CompileTask* task);
244
245 static void invoke_compiler_on_method(CompileTask* task);
246 static void set_last_compile(CompilerThread *thread, methodHandle method, bool is_osr, int comp_level);
247 static void push_jni_handle_block();
248 static void pop_jni_handle_block();
249 static bool check_break_at(methodHandle method, int compile_id, bool is_osr);
250 static void collect_statistics(CompilerThread* thread, elapsedTimer time, CompileTask* task);
251
252 static void compile_method_base(methodHandle method,
253 int osr_bci,
254 int comp_level,
255 methodHandle hot_method,
256 int hot_count,
257 const char* comment,
258 Thread* thread);
259
260 static CompileQueue* compile_queue(int comp_level);
261 static bool init_compiler_runtime();
262 static void shutdown_compiler_runtime(AbstractCompiler* comp, CompilerThread* thread);
263
264 public:
265 enum {
266 // The entry bci used for non-OSR compilations.
267 standard_entry_bci = InvocationEntryBci
268 };
269
270 static AbstractCompiler* compiler(int comp_level) {
271 if (is_c2_compile(comp_level)) return _compilers[1]; // C2
272 if (is_c1_compile(comp_level)) return _compilers[0]; // C1
273 return NULL;
274 }
275
276 static bool compilation_is_in_queue(methodHandle method);
277 static void print_compile_queues(outputStream* st);
278 static int queue_size(int comp_level) {
279 CompileQueue *q = compile_queue(comp_level);
280 return q != NULL ? q->size() : 0;
281 }
282 static void compilation_init();
283 static void init_compiler_thread_log();
284 static nmethod* compile_method(methodHandle method,
285 int osr_bci,
286 int comp_level,
287 methodHandle hot_method,
288 int hot_count,
289 const char* comment, Thread* thread);
290
291 static void compiler_thread_loop();
292 static uint get_compilation_id() { return _compilation_id; }
293
294 // Set _should_block.
295 // Call this from the VM, with Threads_lock held and a safepoint requested.
296 static void set_should_block();
297
|
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_COMPILER_COMPILEBROKER_HPP
26 #define SHARE_VM_COMPILER_COMPILEBROKER_HPP
27
28 #include "ci/compilerInterface.hpp"
29 #include "compiler/abstractCompiler.hpp"
30 #include "compiler/compileTask.hpp"
31 #include "runtime/perfData.hpp"
32 #include "utilities/stack.hpp"
33
34 class nmethod;
35 class nmethodLocker;
36
37 // CompilerCounters
38 //
39 // Per Compiler Performance Counters.
40 //
41 class CompilerCounters : public CHeapObj<mtCompiler> {
42
43 public:
44 enum {
45 cmname_buffer_length = 160
46 };
47
48 private:
49
50 char _current_method[cmname_buffer_length];
51 PerfStringVariable* _perf_current_method;
52
122 void mark_on_stack();
123 void free_all();
124 void print_tty();
125 void print(outputStream* st = tty);
126
127 ~CompileQueue() {
128 assert (is_empty(), " Compile Queue must be empty");
129 }
130 };
131
132 // CompileTaskWrapper
133 //
134 // Assign this task to the current thread. Deallocate the task
135 // when the compilation is complete.
136 class CompileTaskWrapper : StackObj {
137 public:
138 CompileTaskWrapper(CompileTask* task);
139 ~CompileTaskWrapper();
140 };
141
142 class DirectivesStack : public CHeapObj<mtCompiler> {
143 private:
144 CompilerDirectives* _top;
145 CompilerDirectives* _bottom;
146 int _depth;
147
148 void pop_inner(); // no lock version of pop
149 public:
150 DirectivesStack();
151 DirectiveSet* peak(AbstractCompiler* comp);
152 void push(CompilerDirectives* directive);
153 void pop();
154 void clear();
155 DirectiveSet* getMatchingDirective(methodHandle mh, int comp_level);
156 void print(outputStream* st);
157 };
158
159 // Compilation
160 //
161 // The broker for all compilation requests.
162 class CompileBroker: AllStatic {
163 friend class Threads;
164 friend class CompileTaskWrapper;
165
166 public:
167 enum {
168 name_buffer_length = 100
169 };
170
171 // Compile type Information for print_last_compile() and CompilerCounters
172 enum { no_compile, normal_compile, osr_compile, native_compile };
173 static int assign_compile_id (methodHandle method, int osr_bci);
174
175
176 private:
177 static bool _initialized;
178 static volatile bool _should_block;
179
180 // This flag can be used to stop compilation or turn it back on
181 static volatile jint _should_compile_new_jobs;
182
183 // The installed compiler(s)
184 static AbstractCompiler* _compilers[2];
185
186 // The directives stack
187 static DirectivesStack* _dirstack;
188
189 // These counters are used for assigning id's to each compilation
190 static volatile jint _compilation_id;
191 static volatile jint _osr_compilation_id;
192
193 static int _last_compile_type;
194 static int _last_compile_level;
195 static char _last_method_compiled[name_buffer_length];
196
197 static CompileQueue* _c2_compile_queue;
198 static CompileQueue* _c1_compile_queue;
199
200 // performance counters
201 static PerfCounter* _perf_total_compilation;
202 static PerfCounter* _perf_native_compilation;
203 static PerfCounter* _perf_osr_compilation;
204 static PerfCounter* _perf_standard_compilation;
205
206 static PerfCounter* _perf_total_bailout_count;
207 static PerfCounter* _perf_total_invalidated_count;
208 static PerfCounter* _perf_total_compile_count;
249 static bool compilation_is_complete (methodHandle method, int osr_bci, int comp_level);
250 static bool compilation_is_prohibited(methodHandle method, int osr_bci, int comp_level);
251 static bool is_compile_blocking();
252 static void preload_classes (methodHandle method, TRAPS);
253
254 static CompileTask* create_compile_task(CompileQueue* queue,
255 int compile_id,
256 methodHandle method,
257 int osr_bci,
258 int comp_level,
259 methodHandle hot_method,
260 int hot_count,
261 const char* comment,
262 bool blocking);
263 static void wait_for_completion(CompileTask* task);
264
265 static void invoke_compiler_on_method(CompileTask* task);
266 static void set_last_compile(CompilerThread *thread, methodHandle method, bool is_osr, int comp_level);
267 static void push_jni_handle_block();
268 static void pop_jni_handle_block();
269 static void collect_statistics(CompilerThread* thread, elapsedTimer time, CompileTask* task);
270
271 static void compile_method_base(methodHandle method,
272 int osr_bci,
273 int comp_level,
274 methodHandle hot_method,
275 int hot_count,
276 const char* comment,
277 Thread* thread);
278
279 static CompileQueue* compile_queue(int comp_level);
280 static bool init_compiler_runtime();
281 static void shutdown_compiler_runtime(AbstractCompiler* comp, CompilerThread* thread);
282
283 public:
284
285 static DirectivesStack* dirstack();
286 static void set_dirstack(DirectivesStack* stack);
287
288 enum {
289 // The entry bci used for non-OSR compilations.
290 standard_entry_bci = InvocationEntryBci
291 };
292
293 static AbstractCompiler* compiler(int comp_level) {
294 if (is_c2_compile(comp_level)) return _compilers[1]; // C2
295 if (is_c1_compile(comp_level)) return _compilers[0]; // C1
296 return NULL;
297 }
298
299 static bool compilation_is_in_queue(methodHandle method);
300 static void print_compile_queues(outputStream* st);
301 static void print_directives(outputStream* st);
302 static int queue_size(int comp_level) {
303 CompileQueue *q = compile_queue(comp_level);
304 return q != NULL ? q->size() : 0;
305 }
306 static void compilation_init();
307 static void init_compiler_thread_log();
308 static nmethod* compile_method(methodHandle method,
309 int osr_bci,
310 int comp_level,
311 methodHandle hot_method,
312 int hot_count,
313 const char* comment, Thread* thread);
314
315 static void compiler_thread_loop();
316 static uint get_compilation_id() { return _compilation_id; }
317
318 // Set _should_block.
319 // Call this from the VM, with Threads_lock held and a safepoint requested.
320 static void set_should_block();
321
|