Mercurial > hg > graal-jvmci-8
annotate src/share/vm/compiler/compileBroker.cpp @ 1406:35069ca331f2
Hooked C1XCompiler class into the system.
Two new flags:
-XX:+UseC1X makes sure that the C1X compiler is used instead of C1
-XX:TraceC1X=0 sets the trace level for C1X (value between 0=no output and 5=verbose)
author | Thomas Wuerthinger <thomas.wuerthinger@gmail.com> |
---|---|
date | Tue, 11 May 2010 18:19:17 +0200 |
parents | a2ea687fdc7c |
children | b30a2cd5e3a2 |
rev | line source |
---|---|
0 | 1 /* |
1208
cef333a48af6
6923043: failed nightly tests which use -XX:+PrintCompilation -Xcomp -XX:CompileOnly
kvn
parents:
1202
diff
changeset
|
2 * Copyright 1999-2010 Sun Microsystems, Inc. All Rights Reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 #include "incls/_precompiled.incl" | |
26 #include "incls/_compileBroker.cpp.incl" | |
27 | |
28 #ifdef DTRACE_ENABLED | |
29 | |
30 // Only bother with this argument setup if dtrace is available | |
31 | |
32 HS_DTRACE_PROBE_DECL8(hotspot, method__compile__begin, | |
33 char*, intptr_t, char*, intptr_t, char*, intptr_t, char*, intptr_t); | |
34 HS_DTRACE_PROBE_DECL9(hotspot, method__compile__end, | |
35 char*, intptr_t, char*, intptr_t, char*, intptr_t, char*, intptr_t, bool); | |
36 | |
37 #define DTRACE_METHOD_COMPILE_BEGIN_PROBE(compiler, method) \ | |
38 { \ | |
39 char* comp_name = (char*)(compiler)->name(); \ | |
40 symbolOop klass_name = (method)->klass_name(); \ | |
41 symbolOop name = (method)->name(); \ | |
42 symbolOop signature = (method)->signature(); \ | |
43 HS_DTRACE_PROBE8(hotspot, method__compile__begin, \ | |
44 comp_name, strlen(comp_name), \ | |
45 klass_name->bytes(), klass_name->utf8_length(), \ | |
46 name->bytes(), name->utf8_length(), \ | |
47 signature->bytes(), signature->utf8_length()); \ | |
48 } | |
49 | |
50 #define DTRACE_METHOD_COMPILE_END_PROBE(compiler, method, success) \ | |
51 { \ | |
52 char* comp_name = (char*)(compiler)->name(); \ | |
53 symbolOop klass_name = (method)->klass_name(); \ | |
54 symbolOop name = (method)->name(); \ | |
55 symbolOop signature = (method)->signature(); \ | |
56 HS_DTRACE_PROBE9(hotspot, method__compile__end, \ | |
57 comp_name, strlen(comp_name), \ | |
58 klass_name->bytes(), klass_name->utf8_length(), \ | |
59 name->bytes(), name->utf8_length(), \ | |
60 signature->bytes(), signature->utf8_length(), (success)); \ | |
61 } | |
62 | |
63 #else // ndef DTRACE_ENABLED | |
64 | |
65 #define DTRACE_METHOD_COMPILE_BEGIN_PROBE(compiler, method) | |
66 #define DTRACE_METHOD_COMPILE_END_PROBE(compiler, method, success) | |
67 | |
68 #endif // ndef DTRACE_ENABLED | |
69 | |
70 bool CompileBroker::_initialized = false; | |
71 volatile bool CompileBroker::_should_block = false; | |
1202 | 72 volatile jint CompileBroker::_should_compile_new_jobs = run_compilation; |
0 | 73 |
74 // The installed compiler(s) | |
75 AbstractCompiler* CompileBroker::_compilers[2]; | |
76 | |
77 // These counters are used for assigning id's to each compilation | |
78 uint CompileBroker::_compilation_id = 0; | |
79 uint CompileBroker::_osr_compilation_id = 0; | |
80 | |
81 // Debugging information | |
82 int CompileBroker::_last_compile_type = no_compile; | |
83 int CompileBroker::_last_compile_level = CompLevel_none; | |
84 char CompileBroker::_last_method_compiled[CompileBroker::name_buffer_length]; | |
85 | |
86 // Performance counters | |
87 PerfCounter* CompileBroker::_perf_total_compilation = NULL; | |
88 PerfCounter* CompileBroker::_perf_osr_compilation = NULL; | |
89 PerfCounter* CompileBroker::_perf_standard_compilation = NULL; | |
90 | |
91 PerfCounter* CompileBroker::_perf_total_bailout_count = NULL; | |
92 PerfCounter* CompileBroker::_perf_total_invalidated_count = NULL; | |
93 PerfCounter* CompileBroker::_perf_total_compile_count = NULL; | |
94 PerfCounter* CompileBroker::_perf_total_osr_compile_count = NULL; | |
95 PerfCounter* CompileBroker::_perf_total_standard_compile_count = NULL; | |
96 | |
97 PerfCounter* CompileBroker::_perf_sum_osr_bytes_compiled = NULL; | |
98 PerfCounter* CompileBroker::_perf_sum_standard_bytes_compiled = NULL; | |
99 PerfCounter* CompileBroker::_perf_sum_nmethod_size = NULL; | |
100 PerfCounter* CompileBroker::_perf_sum_nmethod_code_size = NULL; | |
101 | |
102 PerfStringVariable* CompileBroker::_perf_last_method = NULL; | |
103 PerfStringVariable* CompileBroker::_perf_last_failed_method = NULL; | |
104 PerfStringVariable* CompileBroker::_perf_last_invalidated_method = NULL; | |
105 PerfVariable* CompileBroker::_perf_last_compile_type = NULL; | |
106 PerfVariable* CompileBroker::_perf_last_compile_size = NULL; | |
107 PerfVariable* CompileBroker::_perf_last_failed_type = NULL; | |
108 PerfVariable* CompileBroker::_perf_last_invalidated_type = NULL; | |
109 | |
110 // Timers and counters for generating statistics | |
111 elapsedTimer CompileBroker::_t_total_compilation; | |
112 elapsedTimer CompileBroker::_t_osr_compilation; | |
113 elapsedTimer CompileBroker::_t_standard_compilation; | |
114 | |
115 int CompileBroker::_total_bailout_count = 0; | |
116 int CompileBroker::_total_invalidated_count = 0; | |
117 int CompileBroker::_total_compile_count = 0; | |
118 int CompileBroker::_total_osr_compile_count = 0; | |
119 int CompileBroker::_total_standard_compile_count = 0; | |
120 | |
121 int CompileBroker::_sum_osr_bytes_compiled = 0; | |
122 int CompileBroker::_sum_standard_bytes_compiled = 0; | |
123 int CompileBroker::_sum_nmethod_size = 0; | |
124 int CompileBroker::_sum_nmethod_code_size = 0; | |
125 | |
126 CompileQueue* CompileBroker::_method_queue = NULL; | |
127 CompileTask* CompileBroker::_task_free_list = NULL; | |
128 | |
129 GrowableArray<CompilerThread*>* CompileBroker::_method_threads = NULL; | |
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 CompileTaskWrapper::CompileTaskWrapper(CompileTask* task) { | |
142 CompilerThread* thread = CompilerThread::current(); | |
143 thread->set_task(task); | |
144 CompileLog* log = thread->log(); | |
145 if (log != NULL) task->log_task_start(log); | |
146 } | |
147 | |
148 CompileTaskWrapper::~CompileTaskWrapper() { | |
149 CompilerThread* thread = CompilerThread::current(); | |
150 CompileTask* task = thread->task(); | |
151 CompileLog* log = thread->log(); | |
152 if (log != NULL) task->log_task_done(log); | |
153 thread->set_task(NULL); | |
154 task->set_code_handle(NULL); | |
155 DEBUG_ONLY(thread->set_env((ciEnv*)badAddress)); | |
156 if (task->is_blocking()) { | |
157 MutexLocker notifier(task->lock(), thread); | |
158 task->mark_complete(); | |
159 // Notify the waiting thread that the compilation has completed. | |
160 task->lock()->notify_all(); | |
161 } else { | |
162 task->mark_complete(); | |
163 | |
164 // By convention, the compiling thread is responsible for | |
165 // recycling a non-blocking CompileTask. | |
166 CompileBroker::free_task(task); | |
167 } | |
168 } | |
169 | |
170 | |
171 // ------------------------------------------------------------------ | |
172 // CompileTask::initialize | |
173 void CompileTask::initialize(int compile_id, | |
174 methodHandle method, | |
175 int osr_bci, | |
176 int comp_level, | |
177 methodHandle hot_method, | |
178 int hot_count, | |
179 const char* comment, | |
180 bool is_blocking) { | |
181 assert(!_lock->is_locked(), "bad locking"); | |
182 | |
183 _compile_id = compile_id; | |
184 _method = JNIHandles::make_global(method); | |
185 _osr_bci = osr_bci; | |
186 _is_blocking = is_blocking; | |
187 _comp_level = comp_level; | |
188 _num_inlined_bytecodes = 0; | |
189 | |
190 _is_complete = false; | |
191 _is_success = false; | |
192 _code_handle = NULL; | |
193 | |
194 _hot_method = NULL; | |
195 _hot_count = hot_count; | |
196 _time_queued = 0; // tidy | |
197 _comment = comment; | |
198 | |
199 if (LogCompilation) { | |
200 _time_queued = os::elapsed_counter(); | |
201 if (hot_method.not_null()) { | |
202 if (hot_method == method) { | |
203 _hot_method = _method; | |
204 } else { | |
205 _hot_method = JNIHandles::make_global(hot_method); | |
206 } | |
207 } | |
208 } | |
209 | |
210 _next = NULL; | |
211 } | |
212 | |
213 // ------------------------------------------------------------------ | |
214 // CompileTask::code/set_code | |
215 nmethod* CompileTask::code() const { | |
216 if (_code_handle == NULL) return NULL; | |
217 return _code_handle->code(); | |
218 } | |
219 void CompileTask::set_code(nmethod* nm) { | |
220 if (_code_handle == NULL && nm == NULL) return; | |
221 guarantee(_code_handle != NULL, ""); | |
222 _code_handle->set_code(nm); | |
223 if (nm == NULL) _code_handle = NULL; // drop the handle also | |
224 } | |
225 | |
226 // ------------------------------------------------------------------ | |
227 // CompileTask::free | |
228 void CompileTask::free() { | |
229 set_code(NULL); | |
230 assert(!_lock->is_locked(), "Should not be locked when freed"); | |
231 if (_hot_method != NULL && _hot_method != _method) { | |
232 JNIHandles::destroy_global(_hot_method); | |
233 } | |
234 JNIHandles::destroy_global(_method); | |
235 } | |
236 | |
237 | |
238 // ------------------------------------------------------------------ | |
239 // CompileTask::print | |
240 void CompileTask::print() { | |
241 tty->print("<CompileTask compile_id=%d ", _compile_id); | |
242 tty->print("method="); | |
243 ((methodOop)JNIHandles::resolve(_method))->print_name(tty); | |
244 tty->print_cr(" osr_bci=%d is_blocking=%s is_complete=%s is_success=%s>", | |
245 _osr_bci, bool_to_str(_is_blocking), | |
246 bool_to_str(_is_complete), bool_to_str(_is_success)); | |
247 } | |
248 | |
249 // ------------------------------------------------------------------ | |
250 // CompileTask::print_line_on_error | |
251 // | |
252 // This function is called by fatal error handler when the thread | |
253 // causing troubles is a compiler thread. | |
254 // | |
255 // Do not grab any lock, do not allocate memory. | |
256 // | |
257 // Otherwise it's the same as CompileTask::print_line() | |
258 // | |
259 void CompileTask::print_line_on_error(outputStream* st, char* buf, int buflen) { | |
260 methodOop method = (methodOop)JNIHandles::resolve(_method); | |
261 | |
262 // print compiler name | |
263 st->print("%s:", CompileBroker::compiler(comp_level())->name()); | |
264 | |
265 // print compilation number | |
266 st->print("%3d", compile_id()); | |
267 | |
268 // print method attributes | |
269 const bool is_osr = osr_bci() != CompileBroker::standard_entry_bci; | |
270 { const char blocking_char = is_blocking() ? 'b' : ' '; | |
271 const char compile_type = is_osr ? '%' : ' '; | |
272 const char sync_char = method->is_synchronized() ? 's' : ' '; | |
273 const char exception_char = method->has_exception_handler() ? '!' : ' '; | |
274 const char tier_char = | |
275 is_highest_tier_compile(comp_level()) ? ' ' : ('0' + comp_level()); | |
276 st->print("%c%c%c%c%c ", compile_type, sync_char, exception_char, blocking_char, tier_char); | |
277 } | |
278 | |
279 // Use buf to get method name and signature | |
280 if (method != NULL) st->print("%s", method->name_and_sig_as_C_string(buf, buflen)); | |
281 | |
282 // print osr_bci if any | |
283 if (is_osr) st->print(" @ %d", osr_bci()); | |
284 | |
285 // print method size | |
286 st->print_cr(" (%d bytes)", method->code_size()); | |
287 } | |
288 | |
289 // ------------------------------------------------------------------ | |
290 // CompileTask::print_line | |
291 void CompileTask::print_line() { | |
292 Thread *thread = Thread::current(); | |
293 methodHandle method(thread, | |
294 (methodOop)JNIHandles::resolve(method_handle())); | |
295 ResourceMark rm(thread); | |
296 | |
297 ttyLocker ttyl; // keep the following output all in one block | |
298 | |
299 // print compiler name if requested | |
300 if (CIPrintCompilerName) tty->print("%s:", CompileBroker::compiler(comp_level())->name()); | |
301 | |
302 // print compilation number | |
303 tty->print("%3d", compile_id()); | |
304 | |
305 // print method attributes | |
306 const bool is_osr = osr_bci() != CompileBroker::standard_entry_bci; | |
307 { const char blocking_char = is_blocking() ? 'b' : ' '; | |
308 const char compile_type = is_osr ? '%' : ' '; | |
309 const char sync_char = method->is_synchronized() ? 's' : ' '; | |
310 const char exception_char = method->has_exception_handler() ? '!' : ' '; | |
311 const char tier_char = | |
312 is_highest_tier_compile(comp_level()) ? ' ' : ('0' + comp_level()); | |
313 tty->print("%c%c%c%c%c ", compile_type, sync_char, exception_char, blocking_char, tier_char); | |
314 } | |
315 | |
316 // print method name | |
317 method->print_short_name(tty); | |
318 | |
319 // print osr_bci if any | |
320 if (is_osr) tty->print(" @ %d", osr_bci()); | |
321 | |
322 // print method size | |
323 tty->print_cr(" (%d bytes)", method->code_size()); | |
324 } | |
325 | |
326 | |
327 // ------------------------------------------------------------------ | |
328 // CompileTask::log_task | |
329 void CompileTask::log_task(xmlStream* log) { | |
330 Thread* thread = Thread::current(); | |
331 methodHandle method(thread, | |
332 (methodOop)JNIHandles::resolve(method_handle())); | |
333 ResourceMark rm(thread); | |
334 | |
335 // <task id='9' method='M' osr_bci='X' level='1' blocking='1' stamp='1.234'> | |
336 if (_compile_id != 0) log->print(" compile_id='%d'", _compile_id); | |
337 if (_osr_bci != CompileBroker::standard_entry_bci) { | |
338 log->print(" compile_kind='osr'"); // same as nmethod::compile_kind | |
339 } // else compile_kind='c2c' | |
340 if (!method.is_null()) log->method(method); | |
341 if (_osr_bci != CompileBroker::standard_entry_bci) { | |
342 log->print(" osr_bci='%d'", _osr_bci); | |
343 } | |
344 if (_comp_level != CompLevel_highest_tier) { | |
345 log->print(" level='%d'", _comp_level); | |
346 } | |
347 if (_is_blocking) { | |
348 log->print(" blocking='1'"); | |
349 } | |
350 log->stamp(); | |
351 } | |
352 | |
353 | |
354 // ------------------------------------------------------------------ | |
355 // CompileTask::log_task_queued | |
356 void CompileTask::log_task_queued() { | |
357 Thread* thread = Thread::current(); | |
358 ttyLocker ttyl; | |
359 ResourceMark rm(thread); | |
360 | |
361 xtty->begin_elem("task_queued"); | |
362 log_task(xtty); | |
363 if (_comment != NULL) { | |
364 xtty->print(" comment='%s'", _comment); | |
365 } | |
366 if (_hot_method != NULL) { | |
367 methodHandle hot(thread, | |
368 (methodOop)JNIHandles::resolve(_hot_method)); | |
369 methodHandle method(thread, | |
370 (methodOop)JNIHandles::resolve(_method)); | |
371 if (hot() != method()) { | |
372 xtty->method(hot); | |
373 } | |
374 } | |
375 if (_hot_count != 0) { | |
376 xtty->print(" hot_count='%d'", _hot_count); | |
377 } | |
378 xtty->end_elem(); | |
379 } | |
380 | |
381 | |
382 // ------------------------------------------------------------------ | |
383 // CompileTask::log_task_start | |
384 void CompileTask::log_task_start(CompileLog* log) { | |
385 log->begin_head("task"); | |
386 log_task(log); | |
387 log->end_head(); | |
388 } | |
389 | |
390 | |
391 // ------------------------------------------------------------------ | |
392 // CompileTask::log_task_done | |
393 void CompileTask::log_task_done(CompileLog* log) { | |
394 Thread* thread = Thread::current(); | |
395 methodHandle method(thread, | |
396 (methodOop)JNIHandles::resolve(method_handle())); | |
397 ResourceMark rm(thread); | |
398 | |
399 // <task_done ... stamp='1.234'> </task> | |
400 nmethod* nm = code(); | |
401 log->begin_elem("task_done success='%d' nmsize='%d' count='%d'", | |
402 _is_success, nm == NULL ? 0 : nm->instructions_size(), | |
403 method->invocation_count()); | |
404 int bec = method->backedge_count(); | |
405 if (bec != 0) log->print(" backedge_count='%d'", bec); | |
406 // Note: "_is_complete" is about to be set, but is not. | |
407 if (_num_inlined_bytecodes != 0) { | |
408 log->print(" inlined_bytes='%d'", _num_inlined_bytecodes); | |
409 } | |
410 log->stamp(); | |
411 log->end_elem(); | |
412 log->tail("task"); | |
413 log->clear_identities(); // next task will have different CI | |
414 if (log->unflushed_count() > 2000) { | |
415 log->flush(); | |
416 } | |
417 log->mark_file_end(); | |
418 } | |
419 | |
420 | |
421 | |
422 // ------------------------------------------------------------------ | |
423 // CompileQueue::add | |
424 // | |
425 // Add a CompileTask to a CompileQueue | |
426 void CompileQueue::add(CompileTask* task) { | |
427 assert(lock()->owned_by_self(), "must own lock"); | |
428 | |
429 task->set_next(NULL); | |
430 | |
431 if (_last == NULL) { | |
432 // The compile queue is empty. | |
433 assert(_first == NULL, "queue is empty"); | |
434 _first = task; | |
435 _last = task; | |
436 } else { | |
437 // Append the task to the queue. | |
438 assert(_last->next() == NULL, "not last"); | |
439 _last->set_next(task); | |
440 _last = task; | |
441 } | |
442 | |
443 // Mark the method as being in the compile queue. | |
444 ((methodOop)JNIHandles::resolve(task->method_handle()))->set_queued_for_compilation(); | |
445 | |
446 if (CIPrintCompileQueue) { | |
447 print(); | |
448 } | |
449 | |
450 if (LogCompilation && xtty != NULL) { | |
451 task->log_task_queued(); | |
452 } | |
453 | |
454 // Notify CompilerThreads that a task is available. | |
455 lock()->notify(); | |
456 } | |
457 | |
458 | |
459 // ------------------------------------------------------------------ | |
460 // CompileQueue::get | |
461 // | |
462 // Get the next CompileTask from a CompileQueue | |
463 CompileTask* CompileQueue::get() { | |
464 MutexLocker locker(lock()); | |
465 | |
466 // Wait for an available CompileTask. | |
467 while (_first == NULL) { | |
468 // There is no work to be done right now. Wait. | |
469 lock()->wait(); | |
470 } | |
471 | |
472 CompileTask* task = _first; | |
473 | |
474 // Update queue first and last | |
475 _first =_first->next(); | |
476 if (_first == NULL) { | |
477 _last = NULL; | |
478 } | |
479 | |
480 return task; | |
481 | |
482 } | |
483 | |
484 | |
485 // ------------------------------------------------------------------ | |
486 // CompileQueue::print | |
487 void CompileQueue::print() { | |
488 tty->print_cr("Contents of %s", name()); | |
489 tty->print_cr("----------------------"); | |
490 CompileTask* task = _first; | |
491 while (task != NULL) { | |
492 task->print_line(); | |
493 task = task->next(); | |
494 } | |
495 tty->print_cr("----------------------"); | |
496 } | |
497 | |
498 CompilerCounters::CompilerCounters(const char* thread_name, int instance, TRAPS) { | |
499 | |
500 _current_method[0] = '\0'; | |
501 _compile_type = CompileBroker::no_compile; | |
502 | |
503 if (UsePerfData) { | |
504 ResourceMark rm; | |
505 | |
506 // create the thread instance name space string - don't create an | |
507 // instance subspace if instance is -1 - keeps the adapterThread | |
508 // counters from having a ".0" namespace. | |
509 const char* thread_i = (instance == -1) ? thread_name : | |
510 PerfDataManager::name_space(thread_name, instance); | |
511 | |
512 | |
513 char* name = PerfDataManager::counter_name(thread_i, "method"); | |
514 _perf_current_method = | |
515 PerfDataManager::create_string_variable(SUN_CI, name, | |
516 cmname_buffer_length, | |
517 _current_method, CHECK); | |
518 | |
519 name = PerfDataManager::counter_name(thread_i, "type"); | |
520 _perf_compile_type = PerfDataManager::create_variable(SUN_CI, name, | |
521 PerfData::U_None, | |
522 (jlong)_compile_type, | |
523 CHECK); | |
524 | |
525 name = PerfDataManager::counter_name(thread_i, "time"); | |
526 _perf_time = PerfDataManager::create_counter(SUN_CI, name, | |
527 PerfData::U_Ticks, CHECK); | |
528 | |
529 name = PerfDataManager::counter_name(thread_i, "compiles"); | |
530 _perf_compiles = PerfDataManager::create_counter(SUN_CI, name, | |
531 PerfData::U_Events, CHECK); | |
532 } | |
533 } | |
534 | |
535 | |
536 // ------------------------------------------------------------------ | |
537 // CompileBroker::compilation_init | |
538 // | |
539 // Initialize the Compilation object | |
540 void CompileBroker::compilation_init() { | |
541 _last_method_compiled[0] = '\0'; | |
542 | |
543 // Set the interface to the current compiler(s). | |
544 #ifdef COMPILER1 | |
1406
35069ca331f2
Hooked C1XCompiler class into the system.
Thomas Wuerthinger <thomas.wuerthinger@gmail.com>
parents:
1353
diff
changeset
|
545 if (UseC1X) { |
35069ca331f2
Hooked C1XCompiler class into the system.
Thomas Wuerthinger <thomas.wuerthinger@gmail.com>
parents:
1353
diff
changeset
|
546 _compilers[0] = new C1XCompiler(); |
35069ca331f2
Hooked C1XCompiler class into the system.
Thomas Wuerthinger <thomas.wuerthinger@gmail.com>
parents:
1353
diff
changeset
|
547 } else { |
35069ca331f2
Hooked C1XCompiler class into the system.
Thomas Wuerthinger <thomas.wuerthinger@gmail.com>
parents:
1353
diff
changeset
|
548 _compilers[0] = new Compiler(); |
35069ca331f2
Hooked C1XCompiler class into the system.
Thomas Wuerthinger <thomas.wuerthinger@gmail.com>
parents:
1353
diff
changeset
|
549 } |
0 | 550 #ifndef COMPILER2 |
551 _compilers[1] = _compilers[0]; | |
552 #endif | |
553 #endif // COMPILER1 | |
554 | |
555 #ifdef COMPILER2 | |
556 _compilers[1] = new C2Compiler(); | |
557 #ifndef COMPILER1 | |
558 _compilers[0] = _compilers[1]; | |
559 #endif | |
560 #endif // COMPILER2 | |
561 | |
562 // Initialize the CompileTask free list | |
563 _task_free_list = NULL; | |
564 | |
565 // Start the CompilerThreads | |
566 init_compiler_threads(compiler_count()); | |
567 | |
568 | |
569 // totalTime performance counter is always created as it is required | |
570 // by the implementation of java.lang.management.CompilationMBean. | |
571 { | |
572 EXCEPTION_MARK; | |
573 _perf_total_compilation = | |
574 PerfDataManager::create_counter(JAVA_CI, "totalTime", | |
575 PerfData::U_Ticks, CHECK); | |
576 } | |
577 | |
578 | |
579 if (UsePerfData) { | |
580 | |
581 EXCEPTION_MARK; | |
582 | |
583 // create the jvmstat performance counters | |
584 _perf_osr_compilation = | |
585 PerfDataManager::create_counter(SUN_CI, "osrTime", | |
586 PerfData::U_Ticks, CHECK); | |
587 | |
588 _perf_standard_compilation = | |
589 PerfDataManager::create_counter(SUN_CI, "standardTime", | |
590 PerfData::U_Ticks, CHECK); | |
591 | |
592 _perf_total_bailout_count = | |
593 PerfDataManager::create_counter(SUN_CI, "totalBailouts", | |
594 PerfData::U_Events, CHECK); | |
595 | |
596 _perf_total_invalidated_count = | |
597 PerfDataManager::create_counter(SUN_CI, "totalInvalidates", | |
598 PerfData::U_Events, CHECK); | |
599 | |
600 _perf_total_compile_count = | |
601 PerfDataManager::create_counter(SUN_CI, "totalCompiles", | |
602 PerfData::U_Events, CHECK); | |
603 _perf_total_osr_compile_count = | |
604 PerfDataManager::create_counter(SUN_CI, "osrCompiles", | |
605 PerfData::U_Events, CHECK); | |
606 | |
607 _perf_total_standard_compile_count = | |
608 PerfDataManager::create_counter(SUN_CI, "standardCompiles", | |
609 PerfData::U_Events, CHECK); | |
610 | |
611 _perf_sum_osr_bytes_compiled = | |
612 PerfDataManager::create_counter(SUN_CI, "osrBytes", | |
613 PerfData::U_Bytes, CHECK); | |
614 | |
615 _perf_sum_standard_bytes_compiled = | |
616 PerfDataManager::create_counter(SUN_CI, "standardBytes", | |
617 PerfData::U_Bytes, CHECK); | |
618 | |
619 _perf_sum_nmethod_size = | |
620 PerfDataManager::create_counter(SUN_CI, "nmethodSize", | |
621 PerfData::U_Bytes, CHECK); | |
622 | |
623 _perf_sum_nmethod_code_size = | |
624 PerfDataManager::create_counter(SUN_CI, "nmethodCodeSize", | |
625 PerfData::U_Bytes, CHECK); | |
626 | |
627 _perf_last_method = | |
628 PerfDataManager::create_string_variable(SUN_CI, "lastMethod", | |
629 CompilerCounters::cmname_buffer_length, | |
630 "", CHECK); | |
631 | |
632 _perf_last_failed_method = | |
633 PerfDataManager::create_string_variable(SUN_CI, "lastFailedMethod", | |
634 CompilerCounters::cmname_buffer_length, | |
635 "", CHECK); | |
636 | |
637 _perf_last_invalidated_method = | |
638 PerfDataManager::create_string_variable(SUN_CI, "lastInvalidatedMethod", | |
639 CompilerCounters::cmname_buffer_length, | |
640 "", CHECK); | |
641 | |
642 _perf_last_compile_type = | |
643 PerfDataManager::create_variable(SUN_CI, "lastType", | |
644 PerfData::U_None, | |
645 (jlong)CompileBroker::no_compile, | |
646 CHECK); | |
647 | |
648 _perf_last_compile_size = | |
649 PerfDataManager::create_variable(SUN_CI, "lastSize", | |
650 PerfData::U_Bytes, | |
651 (jlong)CompileBroker::no_compile, | |
652 CHECK); | |
653 | |
654 | |
655 _perf_last_failed_type = | |
656 PerfDataManager::create_variable(SUN_CI, "lastFailedType", | |
657 PerfData::U_None, | |
658 (jlong)CompileBroker::no_compile, | |
659 CHECK); | |
660 | |
661 _perf_last_invalidated_type = | |
662 PerfDataManager::create_variable(SUN_CI, "lastInvalidatedType", | |
663 PerfData::U_None, | |
664 (jlong)CompileBroker::no_compile, | |
665 CHECK); | |
666 } | |
667 | |
668 _initialized = true; | |
669 } | |
670 | |
671 | |
672 | |
673 // ------------------------------------------------------------------ | |
674 // CompileBroker::make_compiler_thread | |
675 CompilerThread* CompileBroker::make_compiler_thread(const char* name, CompileQueue* queue, CompilerCounters* counters, TRAPS) { | |
676 CompilerThread* compiler_thread = NULL; | |
677 | |
678 klassOop k = | |
679 SystemDictionary::resolve_or_fail(vmSymbolHandles::java_lang_Thread(), | |
680 true, CHECK_0); | |
681 instanceKlassHandle klass (THREAD, k); | |
682 instanceHandle thread_oop = klass->allocate_instance_handle(CHECK_0); | |
683 Handle string = java_lang_String::create_from_str(name, CHECK_0); | |
684 | |
685 // Initialize thread_oop to put it into the system threadGroup | |
686 Handle thread_group (THREAD, Universe::system_thread_group()); | |
687 JavaValue result(T_VOID); | |
688 JavaCalls::call_special(&result, thread_oop, | |
689 klass, | |
690 vmSymbolHandles::object_initializer_name(), | |
691 vmSymbolHandles::threadgroup_string_void_signature(), | |
692 thread_group, | |
693 string, | |
694 CHECK_0); | |
695 | |
696 { | |
697 MutexLocker mu(Threads_lock, THREAD); | |
698 compiler_thread = new CompilerThread(queue, counters); | |
699 // At this point the new CompilerThread data-races with this startup | |
700 // thread (which I believe is the primoridal thread and NOT the VM | |
701 // thread). This means Java bytecodes being executed at startup can | |
702 // queue compile jobs which will run at whatever default priority the | |
703 // newly created CompilerThread runs at. | |
704 | |
705 | |
706 // At this point it may be possible that no osthread was created for the | |
707 // JavaThread due to lack of memory. We would have to throw an exception | |
708 // in that case. However, since this must work and we do not allow | |
709 // exceptions anyway, check and abort if this fails. | |
710 | |
711 if (compiler_thread == NULL || compiler_thread->osthread() == NULL){ | |
712 vm_exit_during_initialization("java.lang.OutOfMemoryError", | |
713 "unable to create new native thread"); | |
714 } | |
715 | |
716 java_lang_Thread::set_thread(thread_oop(), compiler_thread); | |
717 | |
718 // Note that this only sets the JavaThread _priority field, which by | |
719 // definition is limited to Java priorities and not OS priorities. | |
720 // The os-priority is set in the CompilerThread startup code itself | |
721 java_lang_Thread::set_priority(thread_oop(), NearMaxPriority); | |
722 // CLEANUP PRIORITIES: This -if- statement hids a bug whereby the compiler | |
723 // threads never have their OS priority set. The assumption here is to | |
724 // enable the Performance group to do flag tuning, figure out a suitable | |
725 // CompilerThreadPriority, and then remove this 'if' statement (and | |
726 // comment) and unconditionally set the priority. | |
727 | |
728 // Compiler Threads should be at the highest Priority | |
729 if ( CompilerThreadPriority != -1 ) | |
730 os::set_native_priority( compiler_thread, CompilerThreadPriority ); | |
731 else | |
732 os::set_native_priority( compiler_thread, os::java_to_os_priority[NearMaxPriority]); | |
733 | |
734 // Note that I cannot call os::set_priority because it expects Java | |
735 // priorities and I am *explicitly* using OS priorities so that it's | |
736 // possible to set the compiler thread priority higher than any Java | |
737 // thread. | |
738 | |
739 java_lang_Thread::set_daemon(thread_oop()); | |
740 | |
741 compiler_thread->set_threadObj(thread_oop()); | |
742 Threads::add(compiler_thread); | |
743 Thread::start(compiler_thread); | |
744 } | |
745 // Let go of Threads_lock before yielding | |
746 os::yield(); // make sure that the compiler thread is started early (especially helpful on SOLARIS) | |
747 | |
748 return compiler_thread; | |
749 } | |
750 | |
751 | |
752 // ------------------------------------------------------------------ | |
753 // CompileBroker::init_compiler_threads | |
754 // | |
755 // Initialize the compilation queue | |
756 void CompileBroker::init_compiler_threads(int compiler_count) { | |
757 EXCEPTION_MARK; | |
758 | |
759 _method_queue = new CompileQueue("MethodQueue", MethodCompileQueue_lock); | |
760 _method_threads = | |
761 new (ResourceObj::C_HEAP) GrowableArray<CompilerThread*>(compiler_count, true); | |
762 | |
763 char name_buffer[256]; | |
764 int i; | |
765 for (i = 0; i < compiler_count; i++) { | |
766 // Create a name for our thread. | |
767 sprintf(name_buffer, "CompilerThread%d", i); | |
768 CompilerCounters* counters = new CompilerCounters("compilerThread", i, CHECK); | |
769 | |
770 CompilerThread* new_thread = make_compiler_thread(name_buffer, _method_queue, counters, CHECK); | |
771 _method_threads->append(new_thread); | |
772 } | |
773 if (UsePerfData) { | |
774 PerfDataManager::create_constant(SUN_CI, "threads", PerfData::U_Bytes, | |
775 compiler_count, CHECK); | |
776 } | |
777 } | |
778 | |
779 // ------------------------------------------------------------------ | |
780 // CompileBroker::is_idle | |
781 bool CompileBroker::is_idle() { | |
782 if (!_method_queue->is_empty()) { | |
783 return false; | |
784 } else { | |
785 int num_threads = _method_threads->length(); | |
786 for (int i=0; i<num_threads; i++) { | |
787 if (_method_threads->at(i)->task() != NULL) { | |
788 return false; | |
789 } | |
790 } | |
791 | |
792 // No pending or active compilations. | |
793 return true; | |
794 } | |
795 } | |
796 | |
797 | |
798 // ------------------------------------------------------------------ | |
799 // CompileBroker::compile_method | |
800 // | |
801 // Request compilation of a method. | |
802 void CompileBroker::compile_method_base(methodHandle method, | |
803 int osr_bci, | |
804 int comp_level, | |
805 methodHandle hot_method, | |
806 int hot_count, | |
807 const char* comment, | |
808 TRAPS) { | |
809 // do nothing if compiler thread(s) is not available | |
810 if (!_initialized ) { | |
811 return; | |
812 } | |
813 | |
814 guarantee(!method->is_abstract(), "cannot compile abstract methods"); | |
815 assert(method->method_holder()->klass_part()->oop_is_instance(), | |
816 "sanity check"); | |
817 assert(!instanceKlass::cast(method->method_holder())->is_not_initialized(), | |
818 "method holder must be initialized"); | |
819 | |
820 if (CIPrintRequests) { | |
821 tty->print("request: "); | |
822 method->print_short_name(tty); | |
823 if (osr_bci != InvocationEntryBci) { | |
824 tty->print(" osr_bci: %d", osr_bci); | |
825 } | |
826 tty->print(" comment: %s count: %d", comment, hot_count); | |
827 if (!hot_method.is_null()) { | |
828 tty->print(" hot: "); | |
829 if (hot_method() != method()) { | |
830 hot_method->print_short_name(tty); | |
831 } else { | |
832 tty->print("yes"); | |
833 } | |
834 } | |
835 tty->cr(); | |
836 } | |
837 | |
838 // A request has been made for compilation. Before we do any | |
839 // real work, check to see if the method has been compiled | |
840 // in the meantime with a definitive result. | |
841 if (compilation_is_complete(method, osr_bci, comp_level)) { | |
842 return; | |
843 } | |
844 | |
845 // If this method is already in the compile queue, then | |
846 // we do not block the current thread. | |
847 if (compilation_is_in_queue(method, osr_bci)) { | |
848 // We may want to decay our counter a bit here to prevent | |
849 // multiple denied requests for compilation. This is an | |
850 // open compilation policy issue. Note: The other possibility, | |
851 // in the case that this is a blocking compile request, is to have | |
852 // all subsequent blocking requesters wait for completion of | |
853 // ongoing compiles. Note that in this case we'll need a protocol | |
854 // for freeing the associated compile tasks. [Or we could have | |
855 // a single static monitor on which all these waiters sleep.] | |
856 return; | |
857 } | |
858 | |
859 // Outputs from the following MutexLocker block: | |
860 CompileTask* task = NULL; | |
861 bool blocking = false; | |
862 | |
863 // Acquire our lock. | |
864 { | |
865 MutexLocker locker(_method_queue->lock(), THREAD); | |
866 | |
867 // Make sure the method has not slipped into the queues since | |
868 // last we checked; note that those checks were "fast bail-outs". | |
869 // Here we need to be more careful, see 14012000 below. | |
870 if (compilation_is_in_queue(method, osr_bci)) { | |
871 return; | |
872 } | |
873 | |
874 // We need to check again to see if the compilation has | |
875 // completed. A previous compilation may have registered | |
876 // some result. | |
877 if (compilation_is_complete(method, osr_bci, comp_level)) { | |
878 return; | |
879 } | |
880 | |
881 // We now know that this compilation is not pending, complete, | |
882 // or prohibited. Assign a compile_id to this compilation | |
883 // and check to see if it is in our [Start..Stop) range. | |
884 uint compile_id = assign_compile_id(method, osr_bci); | |
885 if (compile_id == 0) { | |
886 // The compilation falls outside the allowed range. | |
887 return; | |
888 } | |
889 | |
890 // Should this thread wait for completion of the compile? | |
891 blocking = is_compile_blocking(method, osr_bci); | |
892 | |
893 // We will enter the compilation in the queue. | |
894 // 14012000: Note that this sets the queued_for_compile bits in | |
895 // the target method. We can now reason that a method cannot be | |
896 // queued for compilation more than once, as follows: | |
897 // Before a thread queues a task for compilation, it first acquires | |
898 // the compile queue lock, then checks if the method's queued bits | |
899 // are set or it has already been compiled. Thus there can not be two | |
900 // instances of a compilation task for the same method on the | |
901 // compilation queue. Consider now the case where the compilation | |
902 // thread has already removed a task for that method from the queue | |
903 // and is in the midst of compiling it. In this case, the | |
904 // queued_for_compile bits must be set in the method (and these | |
905 // will be visible to the current thread, since the bits were set | |
906 // under protection of the compile queue lock, which we hold now. | |
907 // When the compilation completes, the compiler thread first sets | |
908 // the compilation result and then clears the queued_for_compile | |
909 // bits. Neither of these actions are protected by a barrier (or done | |
910 // under the protection of a lock), so the only guarantee we have | |
911 // (on machines with TSO (Total Store Order)) is that these values | |
912 // will update in that order. As a result, the only combinations of | |
913 // these bits that the current thread will see are, in temporal order: | |
914 // <RESULT, QUEUE> : | |
915 // <0, 1> : in compile queue, but not yet compiled | |
916 // <1, 1> : compiled but queue bit not cleared | |
917 // <1, 0> : compiled and queue bit cleared | |
918 // Because we first check the queue bits then check the result bits, | |
919 // we are assured that we cannot introduce a duplicate task. | |
920 // Note that if we did the tests in the reverse order (i.e. check | |
921 // result then check queued bit), we could get the result bit before | |
922 // the compilation completed, and the queue bit after the compilation | |
923 // completed, and end up introducing a "duplicate" (redundant) task. | |
924 // In that case, the compiler thread should first check if a method | |
925 // has already been compiled before trying to compile it. | |
926 // NOTE: in the event that there are multiple compiler threads and | |
927 // there is de-optimization/recompilation, things will get hairy, | |
928 // and in that case it's best to protect both the testing (here) of | |
929 // these bits, and their updating (here and elsewhere) under a | |
930 // common lock. | |
931 task = create_compile_task(_method_queue, | |
932 compile_id, method, | |
933 osr_bci, comp_level, | |
934 hot_method, hot_count, comment, | |
935 blocking); | |
936 } | |
937 | |
938 if (blocking) { | |
939 wait_for_completion(task); | |
940 } | |
941 } | |
942 | |
943 | |
944 nmethod* CompileBroker::compile_method(methodHandle method, int osr_bci, | |
945 methodHandle hot_method, int hot_count, | |
946 const char* comment, TRAPS) { | |
947 // make sure arguments make sense | |
948 assert(method->method_holder()->klass_part()->oop_is_instance(), "not an instance method"); | |
949 assert(osr_bci == InvocationEntryBci || (0 <= osr_bci && osr_bci < method->code_size()), "bci out of range"); | |
950 assert(!method->is_abstract() && (osr_bci == InvocationEntryBci || !method->is_native()), "cannot compile abstract/native methods"); | |
951 assert(!instanceKlass::cast(method->method_holder())->is_not_initialized(), "method holder must be initialized"); | |
952 | |
953 int comp_level = CompilationPolicy::policy()->compilation_level(method, osr_bci); | |
954 | |
955 #ifdef TIERED | |
956 if (TieredCompilation && StressTieredRuntime) { | |
957 static int flipper = 0; | |
958 if (is_even(flipper++)) { | |
959 comp_level = CompLevel_fast_compile; | |
960 } else { | |
961 comp_level = CompLevel_full_optimization; | |
962 } | |
963 } | |
964 #ifdef SPARC | |
965 // QQQ FIX ME | |
966 // C2 only returns long results in G1 and c1 doesn't understand so disallow c2 | |
967 // compiles of long results | |
968 if (TieredCompilation && method()->result_type() == T_LONG) { | |
969 comp_level = CompLevel_fast_compile; | |
970 } | |
971 #endif // SPARC | |
972 #endif // TIERED | |
973 | |
974 // return quickly if possible | |
975 | |
976 // lock, make sure that the compilation | |
977 // isn't prohibited in a straightforward way. | |
978 | |
979 if (compiler(comp_level) == NULL || compilation_is_prohibited(method, osr_bci, comp_level)) { | |
980 return NULL; | |
981 } | |
982 | |
983 if (osr_bci == InvocationEntryBci) { | |
984 // standard compilation | |
985 nmethod* method_code = method->code(); | |
986 if (method_code != NULL | |
987 #ifdef TIERED | |
988 && ( method_code->is_compiled_by_c2() || comp_level == CompLevel_fast_compile ) | |
989 #endif // TIERED | |
990 ) { | |
991 return method_code; | |
992 } | |
993 if (method->is_not_compilable(comp_level)) return NULL; | |
1202 | 994 |
1300
428a9c451986
6935466: new CodeCache flushing code is not guarded by the flag
kvn
parents:
1208
diff
changeset
|
995 if (UseCodeCacheFlushing) { |
428a9c451986
6935466: new CodeCache flushing code is not guarded by the flag
kvn
parents:
1208
diff
changeset
|
996 nmethod* saved = CodeCache::find_and_remove_saved_code(method()); |
428a9c451986
6935466: new CodeCache flushing code is not guarded by the flag
kvn
parents:
1208
diff
changeset
|
997 if (saved != NULL) { |
428a9c451986
6935466: new CodeCache flushing code is not guarded by the flag
kvn
parents:
1208
diff
changeset
|
998 method->set_code(method, saved); |
428a9c451986
6935466: new CodeCache flushing code is not guarded by the flag
kvn
parents:
1208
diff
changeset
|
999 return saved; |
428a9c451986
6935466: new CodeCache flushing code is not guarded by the flag
kvn
parents:
1208
diff
changeset
|
1000 } |
1202 | 1001 } |
1002 | |
0 | 1003 } else { |
1004 // osr compilation | |
1005 #ifndef TIERED | |
1006 // seems like an assert of dubious value | |
1007 assert(comp_level == CompLevel_full_optimization, | |
1008 "all OSR compiles are assumed to be at a single compilation lavel"); | |
1009 #endif // TIERED | |
1010 nmethod* nm = method->lookup_osr_nmethod_for(osr_bci); | |
1011 if (nm != NULL) return nm; | |
1012 if (method->is_not_osr_compilable()) return NULL; | |
1013 } | |
1014 | |
1015 assert(!HAS_PENDING_EXCEPTION, "No exception should be present"); | |
1016 // some prerequisites that are compiler specific | |
1017 if (compiler(comp_level)->is_c2()) { | |
1018 method->constants()->resolve_string_constants(CHECK_0); | |
1019 // Resolve all classes seen in the signature of the method | |
1020 // we are compiling. | |
1021 methodOopDesc::load_signature_classes(method, CHECK_0); | |
1022 } | |
1023 | |
1024 // If the method is native, do the lookup in the thread requesting | |
1025 // the compilation. Native lookups can load code, which is not | |
1026 // permitted during compilation. | |
1027 // | |
1028 // Note: A native method implies non-osr compilation which is | |
1029 // checked with an assertion at the entry of this method. | |
1030 if (method->is_native()) { | |
1031 bool in_base_library; | |
1032 address adr = NativeLookup::lookup(method, in_base_library, THREAD); | |
1033 if (HAS_PENDING_EXCEPTION) { | |
1034 // In case of an exception looking up the method, we just forget | |
1035 // about it. The interpreter will kick-in and throw the exception. | |
1036 method->set_not_compilable(); // implies is_not_osr_compilable() | |
1037 CLEAR_PENDING_EXCEPTION; | |
1038 return NULL; | |
1039 } | |
1040 assert(method->has_native_function(), "must have native code by now"); | |
1041 } | |
1042 | |
1043 // RedefineClasses() has replaced this method; just return | |
1044 if (method->is_old()) { | |
1045 return NULL; | |
1046 } | |
1047 | |
1048 // JVMTI -- post_compile_event requires jmethod_id() that may require | |
1049 // a lock the compiling thread can not acquire. Prefetch it here. | |
1050 if (JvmtiExport::should_post_compiled_method_load()) { | |
1051 method->jmethod_id(); | |
1052 } | |
1053 | |
1202 | 1054 // If the compiler is shut off due to code cache flushing or otherwise, |
1055 // fail out now so blocking compiles dont hang the java thread | |
1056 if (!should_compile_new_jobs() || (UseCodeCacheFlushing && CodeCache::needs_flushing())) { | |
1057 method->invocation_counter()->decay(); | |
1058 method->backedge_counter()->decay(); | |
1059 return NULL; | |
1060 } | |
1061 | |
0 | 1062 // do the compilation |
1063 if (method->is_native()) { | |
1064 if (!PreferInterpreterNativeStubs) { | |
1065 (void) AdapterHandlerLibrary::create_native_wrapper(method); | |
1066 } else { | |
1067 return NULL; | |
1068 } | |
1069 } else { | |
1070 compile_method_base(method, osr_bci, comp_level, hot_method, hot_count, comment, CHECK_0); | |
1071 } | |
1072 | |
1073 // return requested nmethod | |
1074 return osr_bci == InvocationEntryBci ? method->code() : method->lookup_osr_nmethod_for(osr_bci); | |
1075 } | |
1076 | |
1077 | |
1078 // ------------------------------------------------------------------ | |
1079 // CompileBroker::compilation_is_complete | |
1080 // | |
1081 // See if compilation of this method is already complete. | |
1082 bool CompileBroker::compilation_is_complete(methodHandle method, | |
1083 int osr_bci, | |
1084 int comp_level) { | |
1085 bool is_osr = (osr_bci != standard_entry_bci); | |
1086 if (is_osr) { | |
1087 if (method->is_not_osr_compilable()) { | |
1088 return true; | |
1089 } else { | |
1090 nmethod* result = method->lookup_osr_nmethod_for(osr_bci); | |
1091 return (result != NULL); | |
1092 } | |
1093 } else { | |
1094 if (method->is_not_compilable(comp_level)) { | |
1095 return true; | |
1096 } else { | |
1097 nmethod* result = method->code(); | |
1098 if (result == NULL) return false; | |
1099 #ifdef TIERED | |
1100 if (comp_level == CompLevel_fast_compile) { | |
1101 // At worst the code is from c1 | |
1102 return true; | |
1103 } | |
1104 // comp level must be full opt | |
1105 return result->is_compiled_by_c2(); | |
1106 #endif // TIERED | |
1107 return true; | |
1108 } | |
1109 } | |
1110 } | |
1111 | |
1112 | |
1113 // ------------------------------------------------------------------ | |
1114 // CompileBroker::compilation_is_in_queue | |
1115 // | |
1116 // See if this compilation is already requested. | |
1117 // | |
1118 // Implementation note: there is only a single "is in queue" bit | |
1119 // for each method. This means that the check below is overly | |
1120 // conservative in the sense that an osr compilation in the queue | |
1121 // will block a normal compilation from entering the queue (and vice | |
1122 // versa). This can be remedied by a full queue search to disambiguate | |
1123 // cases. If it is deemed profitible, this may be done. | |
1124 bool CompileBroker::compilation_is_in_queue(methodHandle method, | |
1125 int osr_bci) { | |
1126 return method->queued_for_compilation(); | |
1127 } | |
1128 | |
1129 | |
1130 // ------------------------------------------------------------------ | |
1131 // CompileBroker::compilation_is_prohibited | |
1132 // | |
1133 // See if this compilation is not allowed. | |
1134 bool CompileBroker::compilation_is_prohibited(methodHandle method, int osr_bci, int comp_level) { | |
1135 bool is_native = method->is_native(); | |
1136 // Some compilers may not support the compilation of natives. | |
1137 // QQQ this needs some work ought to only record not compilable at | |
1138 // the specified level | |
1139 if (is_native && | |
1140 (!CICompileNatives || !compiler(comp_level)->supports_native())) { | |
1208
cef333a48af6
6923043: failed nightly tests which use -XX:+PrintCompilation -Xcomp -XX:CompileOnly
kvn
parents:
1202
diff
changeset
|
1141 method->set_not_compilable_quietly(); |
0 | 1142 return true; |
1143 } | |
1144 | |
1145 bool is_osr = (osr_bci != standard_entry_bci); | |
1146 // Some compilers may not support on stack replacement. | |
1147 if (is_osr && | |
1148 (!CICompileOSR || !compiler(comp_level)->supports_osr())) { | |
1149 method->set_not_osr_compilable(); | |
1150 return true; | |
1151 } | |
1152 | |
1153 // The method may be explicitly excluded by the user. | |
1154 bool quietly; | |
1155 if (CompilerOracle::should_exclude(method, quietly)) { | |
1156 if (!quietly) { | |
1157 // This does not happen quietly... | |
1158 ResourceMark rm; | |
1159 tty->print("### Excluding %s:%s", | |
1160 method->is_native() ? "generation of native wrapper" : "compile", | |
1161 (method->is_static() ? " static" : "")); | |
1162 method->print_short_name(tty); | |
1163 tty->cr(); | |
1164 } | |
1208
cef333a48af6
6923043: failed nightly tests which use -XX:+PrintCompilation -Xcomp -XX:CompileOnly
kvn
parents:
1202
diff
changeset
|
1165 method->set_not_compilable_quietly(); |
0 | 1166 } |
1167 | |
1168 return false; | |
1169 } | |
1170 | |
1171 | |
1172 // ------------------------------------------------------------------ | |
1173 // CompileBroker::assign_compile_id | |
1174 // | |
1175 // Assign a serialized id number to this compilation request. If the | |
1176 // number falls out of the allowed range, return a 0. OSR | |
1177 // compilations may be numbered separately from regular compilations | |
1178 // if certain debugging flags are used. | |
1179 uint CompileBroker::assign_compile_id(methodHandle method, int osr_bci) { | |
1180 assert(_method_queue->lock()->owner() == JavaThread::current(), | |
1181 "must hold the compilation queue lock"); | |
1182 bool is_osr = (osr_bci != standard_entry_bci); | |
1183 assert(!method->is_native(), "no longer compile natives"); | |
1184 uint id; | |
1185 if (CICountOSR && is_osr) { | |
1186 id = ++_osr_compilation_id; | |
1187 if ((uint)CIStartOSR <= id && id < (uint)CIStopOSR) { | |
1188 return id; | |
1189 } | |
1190 } else { | |
1191 id = ++_compilation_id; | |
1192 if ((uint)CIStart <= id && id < (uint)CIStop) { | |
1193 return id; | |
1194 } | |
1195 } | |
1196 | |
1197 // Method was not in the appropriate compilation range. | |
1208
cef333a48af6
6923043: failed nightly tests which use -XX:+PrintCompilation -Xcomp -XX:CompileOnly
kvn
parents:
1202
diff
changeset
|
1198 method->set_not_compilable_quietly(); |
0 | 1199 return 0; |
1200 } | |
1201 | |
1202 | |
1203 // ------------------------------------------------------------------ | |
1204 // CompileBroker::is_compile_blocking | |
1205 // | |
1206 // Should the current thread be blocked until this compilation request | |
1207 // has been fulfilled? | |
1208 bool CompileBroker::is_compile_blocking(methodHandle method, int osr_bci) { | |
1209 return !BackgroundCompilation; | |
1210 } | |
1211 | |
1212 | |
1213 // ------------------------------------------------------------------ | |
1214 // CompileBroker::preload_classes | |
1215 void CompileBroker::preload_classes(methodHandle method, TRAPS) { | |
1216 // Move this code over from c1_Compiler.cpp | |
1217 ShouldNotReachHere(); | |
1218 } | |
1219 | |
1220 | |
1221 // ------------------------------------------------------------------ | |
1222 // CompileBroker::create_compile_task | |
1223 // | |
1224 // Create a CompileTask object representing the current request for | |
1225 // compilation. Add this task to the queue. | |
1226 CompileTask* CompileBroker::create_compile_task(CompileQueue* queue, | |
1227 int compile_id, | |
1228 methodHandle method, | |
1229 int osr_bci, | |
1230 int comp_level, | |
1231 methodHandle hot_method, | |
1232 int hot_count, | |
1233 const char* comment, | |
1234 bool blocking) { | |
1235 CompileTask* new_task = allocate_task(); | |
1236 new_task->initialize(compile_id, method, osr_bci, comp_level, | |
1237 hot_method, hot_count, comment, | |
1238 blocking); | |
1239 queue->add(new_task); | |
1240 return new_task; | |
1241 } | |
1242 | |
1243 | |
1244 // ------------------------------------------------------------------ | |
1245 // CompileBroker::allocate_task | |
1246 // | |
1247 // Allocate a CompileTask, from the free list if possible. | |
1248 CompileTask* CompileBroker::allocate_task() { | |
1249 MutexLocker locker(CompileTaskAlloc_lock); | |
1250 CompileTask* task = NULL; | |
1251 if (_task_free_list != NULL) { | |
1252 task = _task_free_list; | |
1253 _task_free_list = task->next(); | |
1254 task->set_next(NULL); | |
1255 } else { | |
1256 task = new CompileTask(); | |
1257 task->set_next(NULL); | |
1258 } | |
1259 return task; | |
1260 } | |
1261 | |
1262 | |
1263 // ------------------------------------------------------------------ | |
1264 // CompileBroker::free_task | |
1265 // | |
1266 // Add a task to the free list. | |
1267 void CompileBroker::free_task(CompileTask* task) { | |
1268 MutexLocker locker(CompileTaskAlloc_lock); | |
1269 task->free(); | |
1270 task->set_next(_task_free_list); | |
1271 _task_free_list = task; | |
1272 } | |
1273 | |
1274 | |
1275 // ------------------------------------------------------------------ | |
1276 // CompileBroker::wait_for_completion | |
1277 // | |
1278 // Wait for the given method CompileTask to complete. | |
1279 void CompileBroker::wait_for_completion(CompileTask* task) { | |
1280 if (CIPrintCompileQueue) { | |
1281 tty->print_cr("BLOCKING FOR COMPILE"); | |
1282 } | |
1283 | |
1284 assert(task->is_blocking(), "can only wait on blocking task"); | |
1285 | |
1286 JavaThread *thread = JavaThread::current(); | |
1287 thread->set_blocked_on_compilation(true); | |
1288 | |
1289 methodHandle method(thread, | |
1290 (methodOop)JNIHandles::resolve(task->method_handle())); | |
1291 { | |
1292 MutexLocker waiter(task->lock(), thread); | |
1293 | |
1294 while (!task->is_complete()) | |
1295 task->lock()->wait(); | |
1296 } | |
1297 // It is harmless to check this status without the lock, because | |
1298 // completion is a stable property (until the task object is recycled). | |
1299 assert(task->is_complete(), "Compilation should have completed"); | |
1300 assert(task->code_handle() == NULL, "must be reset"); | |
1301 | |
1302 thread->set_blocked_on_compilation(false); | |
1303 | |
1304 // By convention, the waiter is responsible for recycling a | |
1305 // blocking CompileTask. Since there is only one waiter ever | |
1306 // waiting on a CompileTask, we know that no one else will | |
1307 // be using this CompileTask; we can free it. | |
1308 free_task(task); | |
1309 } | |
1310 | |
1311 // ------------------------------------------------------------------ | |
1312 // CompileBroker::compiler_thread_loop | |
1313 // | |
1314 // The main loop run by a CompilerThread. | |
1315 void CompileBroker::compiler_thread_loop() { | |
1316 CompilerThread* thread = CompilerThread::current(); | |
1317 CompileQueue* queue = thread->queue(); | |
1318 | |
1319 // For the thread that initializes the ciObjectFactory | |
1320 // this resource mark holds all the shared objects | |
1321 ResourceMark rm; | |
1322 | |
1323 // First thread to get here will initialize the compiler interface | |
1324 | |
1325 if (!ciObjectFactory::is_initialized()) { | |
1326 ASSERT_IN_VM; | |
1327 MutexLocker only_one (CompileThread_lock, thread); | |
1328 if (!ciObjectFactory::is_initialized()) { | |
1329 ciObjectFactory::initialize(); | |
1330 } | |
1331 } | |
1332 | |
1333 // Open a log. | |
1334 if (LogCompilation) { | |
1335 init_compiler_thread_log(); | |
1336 } | |
1337 CompileLog* log = thread->log(); | |
1338 if (log != NULL) { | |
1339 log->begin_elem("start_compile_thread thread='" UINTX_FORMAT "' process='%d'", | |
1340 os::current_thread_id(), | |
1341 os::current_process_id()); | |
1342 log->stamp(); | |
1343 log->end_elem(); | |
1344 } | |
1345 | |
1346 while (true) { | |
1347 { | |
1348 // We need this HandleMark to avoid leaking VM handles. | |
1349 HandleMark hm(thread); | |
1202 | 1350 |
0 | 1351 if (CodeCache::unallocated_capacity() < CodeCacheMinimumFreeSpace) { |
1202 | 1352 // the code cache is really full |
1353 handle_full_code_cache(); | |
1354 } else if (UseCodeCacheFlushing && CodeCache::needs_flushing()) { | |
1355 // Attempt to start cleaning the code cache while there is still a little headroom | |
1356 NMethodSweeper::handle_full_code_cache(false); | |
0 | 1357 } |
1358 | |
1359 CompileTask* task = queue->get(); | |
1360 | |
1361 // Give compiler threads an extra quanta. They tend to be bursty and | |
1362 // this helps the compiler to finish up the job. | |
1363 if( CompilerThreadHintNoPreempt ) | |
1364 os::hint_no_preempt(); | |
1365 | |
1366 // trace per thread time and compile statistics | |
1367 CompilerCounters* counters = ((CompilerThread*)thread)->counters(); | |
1368 PerfTraceTimedEvent(counters->time_counter(), counters->compile_counter()); | |
1369 | |
1370 // Assign the task to the current thread. Mark this compilation | |
1371 // thread as active for the profiler. | |
1372 CompileTaskWrapper ctw(task); | |
1373 nmethodLocker result_handle; // (handle for the nmethod produced by this task) | |
1374 task->set_code_handle(&result_handle); | |
1375 methodHandle method(thread, | |
1376 (methodOop)JNIHandles::resolve(task->method_handle())); | |
1377 | |
1378 // Never compile a method if breakpoints are present in it | |
1379 if (method()->number_of_breakpoints() == 0) { | |
1380 // Compile the method. | |
1202 | 1381 if ((UseCompiler || AlwaysCompileLoopMethods) && CompileBroker::should_compile_new_jobs()) { |
0 | 1382 #ifdef COMPILER1 |
1383 // Allow repeating compilations for the purpose of benchmarking | |
1384 // compile speed. This is not useful for customers. | |
1385 if (CompilationRepeat != 0) { | |
1386 int compile_count = CompilationRepeat; | |
1387 while (compile_count > 0) { | |
1388 invoke_compiler_on_method(task); | |
1389 nmethod* nm = method->code(); | |
1390 if (nm != NULL) { | |
1391 nm->make_zombie(); | |
1392 method->clear_code(); | |
1393 } | |
1394 compile_count--; | |
1395 } | |
1396 } | |
1397 #endif /* COMPILER1 */ | |
1398 invoke_compiler_on_method(task); | |
1399 } else { | |
1400 // After compilation is disabled, remove remaining methods from queue | |
1401 method->clear_queued_for_compilation(); | |
1402 } | |
1403 } | |
1404 } | |
1405 } | |
1406 } | |
1407 | |
1408 | |
1409 // ------------------------------------------------------------------ | |
1410 // CompileBroker::init_compiler_thread_log | |
1411 // | |
1412 // Set up state required by +LogCompilation. | |
1413 void CompileBroker::init_compiler_thread_log() { | |
1414 CompilerThread* thread = CompilerThread::current(); | |
1415 char fileBuf[4*K]; | |
1416 FILE* fp = NULL; | |
1417 char* file = NULL; | |
1418 intx thread_id = os::current_thread_id(); | |
1419 for (int try_temp_dir = 1; try_temp_dir >= 0; try_temp_dir--) { | |
1420 const char* dir = (try_temp_dir ? os::get_temp_directory() : NULL); | |
1353
a2ea687fdc7c
6938627: Make temporary directory use property java.io.tmpdir when specified
coleenp
parents:
1300
diff
changeset
|
1421 if (dir == NULL) { |
a2ea687fdc7c
6938627: Make temporary directory use property java.io.tmpdir when specified
coleenp
parents:
1300
diff
changeset
|
1422 jio_snprintf(fileBuf, sizeof(fileBuf), "hs_c" UINTX_FORMAT "_pid%u.log", |
a2ea687fdc7c
6938627: Make temporary directory use property java.io.tmpdir when specified
coleenp
parents:
1300
diff
changeset
|
1423 thread_id, os::current_process_id()); |
a2ea687fdc7c
6938627: Make temporary directory use property java.io.tmpdir when specified
coleenp
parents:
1300
diff
changeset
|
1424 } else { |
a2ea687fdc7c
6938627: Make temporary directory use property java.io.tmpdir when specified
coleenp
parents:
1300
diff
changeset
|
1425 jio_snprintf(fileBuf, sizeof(fileBuf), |
a2ea687fdc7c
6938627: Make temporary directory use property java.io.tmpdir when specified
coleenp
parents:
1300
diff
changeset
|
1426 "%s%shs_c" UINTX_FORMAT "_pid%u.log", dir, |
a2ea687fdc7c
6938627: Make temporary directory use property java.io.tmpdir when specified
coleenp
parents:
1300
diff
changeset
|
1427 os::file_separator(), thread_id, os::current_process_id()); |
a2ea687fdc7c
6938627: Make temporary directory use property java.io.tmpdir when specified
coleenp
parents:
1300
diff
changeset
|
1428 } |
0 | 1429 fp = fopen(fileBuf, "at"); |
1430 if (fp != NULL) { | |
1431 file = NEW_C_HEAP_ARRAY(char, strlen(fileBuf)+1); | |
1432 strcpy(file, fileBuf); | |
1433 break; | |
1434 } | |
1435 } | |
1436 if (fp == NULL) { | |
1437 warning("Cannot open log file: %s", fileBuf); | |
1438 } else { | |
1439 if (LogCompilation && Verbose) | |
1440 tty->print_cr("Opening compilation log %s", file); | |
1441 CompileLog* log = new(ResourceObj::C_HEAP) CompileLog(file, fp, thread_id); | |
1442 thread->init_log(log); | |
1443 | |
1444 if (xtty != NULL) { | |
1445 ttyLocker ttyl; | |
1446 | |
1447 // Record any per thread log files | |
1448 xtty->elem("thread_logfile thread='%d' filename='%s'", thread_id, file); | |
1449 } | |
1450 } | |
1451 } | |
1452 | |
1453 // ------------------------------------------------------------------ | |
1454 // CompileBroker::set_should_block | |
1455 // | |
1456 // Set _should_block. | |
1457 // Call this from the VM, with Threads_lock held and a safepoint requested. | |
1458 void CompileBroker::set_should_block() { | |
1459 assert(Threads_lock->owner() == Thread::current(), "must have threads lock"); | |
1460 assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint already"); | |
1461 #ifndef PRODUCT | |
1462 if (PrintCompilation && (Verbose || WizardMode)) | |
1463 tty->print_cr("notifying compiler thread pool to block"); | |
1464 #endif | |
1465 _should_block = true; | |
1466 } | |
1467 | |
1468 // ------------------------------------------------------------------ | |
1469 // CompileBroker::maybe_block | |
1470 // | |
1471 // Call this from the compiler at convenient points, to poll for _should_block. | |
1472 void CompileBroker::maybe_block() { | |
1473 if (_should_block) { | |
1474 #ifndef PRODUCT | |
1475 if (PrintCompilation && (Verbose || WizardMode)) | |
1476 tty->print_cr("compiler thread " INTPTR_FORMAT " poll detects block request", Thread::current()); | |
1477 #endif | |
1478 ThreadInVMfromNative tivfn(JavaThread::current()); | |
1479 } | |
1480 } | |
1481 | |
1482 | |
1483 // ------------------------------------------------------------------ | |
1484 // CompileBroker::invoke_compiler_on_method | |
1485 // | |
1486 // Compile a method. | |
1487 // | |
1488 void CompileBroker::invoke_compiler_on_method(CompileTask* task) { | |
1489 if (PrintCompilation) { | |
1490 ResourceMark rm; | |
1491 task->print_line(); | |
1492 } | |
1493 elapsedTimer time; | |
1494 | |
1495 CompilerThread* thread = CompilerThread::current(); | |
1496 ResourceMark rm(thread); | |
1497 | |
1498 // Common flags. | |
1499 uint compile_id = task->compile_id(); | |
1500 int osr_bci = task->osr_bci(); | |
1501 bool is_osr = (osr_bci != standard_entry_bci); | |
1502 bool should_log = (thread->log() != NULL); | |
1503 bool should_break = false; | |
1504 { | |
1505 // create the handle inside it's own block so it can't | |
1506 // accidentally be referenced once the thread transitions to | |
1507 // native. The NoHandleMark before the transition should catch | |
1508 // any cases where this occurs in the future. | |
1509 methodHandle method(thread, | |
1510 (methodOop)JNIHandles::resolve(task->method_handle())); | |
1511 should_break = check_break_at(method, compile_id, is_osr); | |
1512 if (should_log && !CompilerOracle::should_log(method)) { | |
1513 should_log = false; | |
1514 } | |
1515 assert(!method->is_native(), "no longer compile natives"); | |
1516 | |
1517 // Save information about this method in case of failure. | |
1518 set_last_compile(thread, method, is_osr, task->comp_level()); | |
1519 | |
1520 DTRACE_METHOD_COMPILE_BEGIN_PROBE(compiler(task->comp_level()), method); | |
1521 } | |
1522 | |
1523 // Allocate a new set of JNI handles. | |
1524 push_jni_handle_block(); | |
1525 jobject target_handle = JNIHandles::make_local(thread, JNIHandles::resolve(task->method_handle())); | |
1526 int compilable = ciEnv::MethodCompilable; | |
1527 { | |
1528 int system_dictionary_modification_counter; | |
1529 { | |
1530 MutexLocker locker(Compile_lock, thread); | |
1531 system_dictionary_modification_counter = SystemDictionary::number_of_modifications(); | |
1532 } | |
1533 | |
1406
35069ca331f2
Hooked C1XCompiler class into the system.
Thomas Wuerthinger <thomas.wuerthinger@gmail.com>
parents:
1353
diff
changeset
|
1534 // (tw) Check if we may do this? |
35069ca331f2
Hooked C1XCompiler class into the system.
Thomas Wuerthinger <thomas.wuerthinger@gmail.com>
parents:
1353
diff
changeset
|
1535 //NoHandleMark nhm; |
0 | 1536 ThreadToNativeFromVM ttn(thread); |
1537 | |
1538 ciEnv ci_env(task, system_dictionary_modification_counter); | |
1539 if (should_break) { | |
1540 ci_env.set_break_at_compile(true); | |
1541 } | |
1542 if (should_log) { | |
1543 ci_env.set_log(thread->log()); | |
1544 } | |
1545 assert(thread->env() == &ci_env, "set by ci_env"); | |
1546 // The thread-env() field is cleared in ~CompileTaskWrapper. | |
1547 | |
780
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
0
diff
changeset
|
1548 // Cache Jvmti state |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
0
diff
changeset
|
1549 ci_env.cache_jvmti_state(); |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
0
diff
changeset
|
1550 |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
0
diff
changeset
|
1551 // Cache DTrace flags |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
0
diff
changeset
|
1552 ci_env.cache_dtrace_flags(); |
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
0
diff
changeset
|
1553 |
0 | 1554 ciMethod* target = ci_env.get_method_from_handle(target_handle); |
1555 | |
1556 TraceTime t1("compilation", &time); | |
1557 | |
1558 compiler(task->comp_level())->compile_method(&ci_env, target, osr_bci); | |
1559 | |
1560 if (!ci_env.failing() && task->code() == NULL) { | |
1561 //assert(false, "compiler should always document failure"); | |
1562 // The compiler elected, without comment, not to register a result. | |
1563 // Do not attempt further compilations of this method. | |
1564 ci_env.record_method_not_compilable("compile failed"); | |
1565 } | |
1566 | |
1567 if (ci_env.failing()) { | |
1568 // Copy this bit to the enclosing block: | |
1569 compilable = ci_env.compilable(); | |
1570 if (PrintCompilation) { | |
1571 const char* reason = ci_env.failure_reason(); | |
1572 if (compilable == ciEnv::MethodCompilable_not_at_tier) { | |
1573 if (is_highest_tier_compile(ci_env.comp_level())) { | |
1574 // Already at highest tier, promote to not compilable. | |
1575 compilable = ciEnv::MethodCompilable_never; | |
1576 } else { | |
1577 tty->print_cr("%3d COMPILE SKIPPED: %s (retry at different tier)", compile_id, reason); | |
1578 } | |
1579 } | |
1580 | |
1581 if (compilable == ciEnv::MethodCompilable_never) { | |
1582 tty->print_cr("%3d COMPILE SKIPPED: %s (not retryable)", compile_id, reason); | |
1583 } else if (compilable == ciEnv::MethodCompilable) { | |
1584 tty->print_cr("%3d COMPILE SKIPPED: %s", compile_id, reason); | |
1585 } | |
1586 } | |
1587 } else { | |
1588 task->mark_success(); | |
1589 task->set_num_inlined_bytecodes(ci_env.num_inlined_bytecodes()); | |
1590 } | |
1591 } | |
1592 pop_jni_handle_block(); | |
1593 | |
1594 methodHandle method(thread, | |
1595 (methodOop)JNIHandles::resolve(task->method_handle())); | |
1596 | |
1597 DTRACE_METHOD_COMPILE_END_PROBE(compiler(task->comp_level()), method, task->is_success()); | |
1598 | |
1599 collect_statistics(thread, time, task); | |
1600 | |
1601 if (compilable == ciEnv::MethodCompilable_never) { | |
1602 if (is_osr) { | |
1603 method->set_not_osr_compilable(); | |
1604 } else { | |
1208
cef333a48af6
6923043: failed nightly tests which use -XX:+PrintCompilation -Xcomp -XX:CompileOnly
kvn
parents:
1202
diff
changeset
|
1605 method->set_not_compilable_quietly(); |
0 | 1606 } |
1607 } else if (compilable == ciEnv::MethodCompilable_not_at_tier) { | |
1208
cef333a48af6
6923043: failed nightly tests which use -XX:+PrintCompilation -Xcomp -XX:CompileOnly
kvn
parents:
1202
diff
changeset
|
1608 method->set_not_compilable_quietly(task->comp_level()); |
0 | 1609 } |
1610 | |
1611 // Note that the queued_for_compilation bits are cleared without | |
1612 // protection of a mutex. [They were set by the requester thread, | |
1613 // when adding the task to the complie queue -- at which time the | |
1614 // compile queue lock was held. Subsequently, we acquired the compile | |
1615 // queue lock to get this task off the compile queue; thus (to belabour | |
1616 // the point somewhat) our clearing of the bits must be occurring | |
1617 // only after the setting of the bits. See also 14012000 above. | |
1618 method->clear_queued_for_compilation(); | |
1619 | |
1620 #ifdef ASSERT | |
1621 if (CollectedHeap::fired_fake_oom()) { | |
1622 // The current compile received a fake OOM during compilation so | |
1623 // go ahead and exit the VM since the test apparently succeeded | |
1624 tty->print_cr("*** Shutting down VM after successful fake OOM"); | |
1625 vm_exit(0); | |
1626 } | |
1627 #endif | |
1628 } | |
1629 | |
1630 | |
1631 // ------------------------------------------------------------------ | |
1202 | 1632 // CompileBroker::handle_full_code_cache |
1633 // | |
1634 // The CodeCache is full. Print out warning and disable compilation or | |
1635 // try code cache cleaning so compilation can continue later. | |
1636 void CompileBroker::handle_full_code_cache() { | |
1637 UseInterpreter = true; | |
1638 if (UseCompiler || AlwaysCompileLoopMethods ) { | |
1639 CompilerThread* thread = CompilerThread::current(); | |
1640 CompileLog* log = thread->log(); | |
1641 if (log != NULL) { | |
1642 log->begin_elem("code_cache_full"); | |
1643 log->stamp(); | |
1644 log->end_elem(); | |
1645 } | |
1646 #ifndef PRODUCT | |
1647 warning("CodeCache is full. Compiler has been disabled"); | |
1648 if (CompileTheWorld || ExitOnFullCodeCache) { | |
1649 before_exit(JavaThread::current()); | |
1650 exit_globals(); // will delete tty | |
1651 vm_direct_exit(CompileTheWorld ? 0 : 1); | |
1652 } | |
1653 #endif | |
1654 if (UseCodeCacheFlushing) { | |
1655 NMethodSweeper::handle_full_code_cache(true); | |
1656 } else { | |
1657 UseCompiler = false; | |
1658 AlwaysCompileLoopMethods = false; | |
1659 } | |
1660 } | |
1661 } | |
1662 | |
1663 // ------------------------------------------------------------------ | |
0 | 1664 // CompileBroker::set_last_compile |
1665 // | |
1666 // Record this compilation for debugging purposes. | |
1667 void CompileBroker::set_last_compile(CompilerThread* thread, methodHandle method, bool is_osr, int comp_level) { | |
1668 ResourceMark rm; | |
1669 char* method_name = method->name()->as_C_string(); | |
1670 strncpy(_last_method_compiled, method_name, CompileBroker::name_buffer_length); | |
1671 char current_method[CompilerCounters::cmname_buffer_length]; | |
1672 size_t maxLen = CompilerCounters::cmname_buffer_length; | |
1673 | |
1674 if (UsePerfData) { | |
1675 const char* class_name = method->method_holder()->klass_part()->name()->as_C_string(); | |
1676 | |
1677 size_t s1len = strlen(class_name); | |
1678 size_t s2len = strlen(method_name); | |
1679 | |
1680 // check if we need to truncate the string | |
1681 if (s1len + s2len + 2 > maxLen) { | |
1682 | |
1683 // the strategy is to lop off the leading characters of the | |
1684 // class name and the trailing characters of the method name. | |
1685 | |
1686 if (s2len + 2 > maxLen) { | |
1687 // lop of the entire class name string, let snprintf handle | |
1688 // truncation of the method name. | |
1689 class_name += s1len; // null string | |
1690 } | |
1691 else { | |
1692 // lop off the extra characters from the front of the class name | |
1693 class_name += ((s1len + s2len + 2) - maxLen); | |
1694 } | |
1695 } | |
1696 | |
1697 jio_snprintf(current_method, maxLen, "%s %s", class_name, method_name); | |
1698 } | |
1699 | |
1700 if (CICountOSR && is_osr) { | |
1701 _last_compile_type = osr_compile; | |
1702 } else { | |
1703 _last_compile_type = normal_compile; | |
1704 } | |
1705 _last_compile_level = comp_level; | |
1706 | |
1707 if (UsePerfData) { | |
1708 CompilerCounters* counters = thread->counters(); | |
1709 counters->set_current_method(current_method); | |
1710 counters->set_compile_type((jlong)_last_compile_type); | |
1711 } | |
1712 } | |
1713 | |
1714 | |
1715 // ------------------------------------------------------------------ | |
1716 // CompileBroker::push_jni_handle_block | |
1717 // | |
1718 // Push on a new block of JNI handles. | |
1719 void CompileBroker::push_jni_handle_block() { | |
1720 JavaThread* thread = JavaThread::current(); | |
1721 | |
1722 // Allocate a new block for JNI handles. | |
1723 // Inlined code from jni_PushLocalFrame() | |
1724 JNIHandleBlock* java_handles = thread->active_handles(); | |
1725 JNIHandleBlock* compile_handles = JNIHandleBlock::allocate_block(thread); | |
1726 assert(compile_handles != NULL && java_handles != NULL, "should not be NULL"); | |
1727 compile_handles->set_pop_frame_link(java_handles); // make sure java handles get gc'd. | |
1728 thread->set_active_handles(compile_handles); | |
1729 } | |
1730 | |
1731 | |
1732 // ------------------------------------------------------------------ | |
1733 // CompileBroker::pop_jni_handle_block | |
1734 // | |
1735 // Pop off the current block of JNI handles. | |
1736 void CompileBroker::pop_jni_handle_block() { | |
1737 JavaThread* thread = JavaThread::current(); | |
1738 | |
1739 // Release our JNI handle block | |
1740 JNIHandleBlock* compile_handles = thread->active_handles(); | |
1741 JNIHandleBlock* java_handles = compile_handles->pop_frame_link(); | |
1742 thread->set_active_handles(java_handles); | |
1743 compile_handles->set_pop_frame_link(NULL); | |
1744 JNIHandleBlock::release_block(compile_handles, thread); // may block | |
1745 } | |
1746 | |
1747 | |
1748 // ------------------------------------------------------------------ | |
1749 // CompileBroker::check_break_at | |
1750 // | |
1751 // Should the compilation break at the current compilation. | |
1752 bool CompileBroker::check_break_at(methodHandle method, int compile_id, bool is_osr) { | |
1753 if (CICountOSR && is_osr && (compile_id == CIBreakAtOSR)) { | |
1754 return true; | |
1755 } else if( CompilerOracle::should_break_at(method) ) { // break when compiling | |
1756 return true; | |
1757 } else { | |
1758 return (compile_id == CIBreakAt); | |
1759 } | |
1760 } | |
1761 | |
1762 // ------------------------------------------------------------------ | |
1763 // CompileBroker::collect_statistics | |
1764 // | |
1765 // Collect statistics about the compilation. | |
1766 | |
1767 void CompileBroker::collect_statistics(CompilerThread* thread, elapsedTimer time, CompileTask* task) { | |
1768 bool success = task->is_success(); | |
1769 methodHandle method (thread, (methodOop)JNIHandles::resolve(task->method_handle())); | |
1770 uint compile_id = task->compile_id(); | |
1771 bool is_osr = (task->osr_bci() != standard_entry_bci); | |
1772 nmethod* code = task->code(); | |
1773 CompilerCounters* counters = thread->counters(); | |
1774 | |
1775 assert(code == NULL || code->is_locked_by_vm(), "will survive the MutexLocker"); | |
1776 MutexLocker locker(CompileStatistics_lock); | |
1777 | |
1778 // _perf variables are production performance counters which are | |
1779 // updated regardless of the setting of the CITime and CITimeEach flags | |
1780 // | |
1781 if (!success) { | |
1782 _total_bailout_count++; | |
1783 if (UsePerfData) { | |
1784 _perf_last_failed_method->set_value(counters->current_method()); | |
1785 _perf_last_failed_type->set_value(counters->compile_type()); | |
1786 _perf_total_bailout_count->inc(); | |
1787 } | |
1788 } else if (code == NULL) { | |
1789 if (UsePerfData) { | |
1790 _perf_last_invalidated_method->set_value(counters->current_method()); | |
1791 _perf_last_invalidated_type->set_value(counters->compile_type()); | |
1792 _perf_total_invalidated_count->inc(); | |
1793 } | |
1794 _total_invalidated_count++; | |
1795 } else { | |
1796 // Compilation succeeded | |
1797 | |
1798 // update compilation ticks - used by the implementation of | |
1799 // java.lang.management.CompilationMBean | |
1800 _perf_total_compilation->inc(time.ticks()); | |
1801 | |
1802 if (CITime) { | |
1803 _t_total_compilation.add(time); | |
1804 if (is_osr) { | |
1805 _t_osr_compilation.add(time); | |
1806 _sum_osr_bytes_compiled += method->code_size() + task->num_inlined_bytecodes(); | |
1807 } else { | |
1808 _t_standard_compilation.add(time); | |
1809 _sum_standard_bytes_compiled += method->code_size() + task->num_inlined_bytecodes(); | |
1810 } | |
1811 } | |
1812 | |
1813 if (UsePerfData) { | |
1814 // save the name of the last method compiled | |
1815 _perf_last_method->set_value(counters->current_method()); | |
1816 _perf_last_compile_type->set_value(counters->compile_type()); | |
1817 _perf_last_compile_size->set_value(method->code_size() + | |
1818 task->num_inlined_bytecodes()); | |
1819 if (is_osr) { | |
1820 _perf_osr_compilation->inc(time.ticks()); | |
1821 _perf_sum_osr_bytes_compiled->inc(method->code_size() + task->num_inlined_bytecodes()); | |
1822 } else { | |
1823 _perf_standard_compilation->inc(time.ticks()); | |
1824 _perf_sum_standard_bytes_compiled->inc(method->code_size() + task->num_inlined_bytecodes()); | |
1825 } | |
1826 } | |
1827 | |
1828 if (CITimeEach) { | |
1829 float bytes_per_sec = 1.0 * (method->code_size() + task->num_inlined_bytecodes()) / time.seconds(); | |
1830 tty->print_cr("%3d seconds: %f bytes/sec : %f (bytes %d + %d inlined)", | |
1831 compile_id, time.seconds(), bytes_per_sec, method->code_size(), task->num_inlined_bytecodes()); | |
1832 } | |
1833 | |
1834 // Collect counts of successful compilations | |
1835 _sum_nmethod_size += code->total_size(); | |
1836 _sum_nmethod_code_size += code->code_size(); | |
1837 _total_compile_count++; | |
1838 | |
1839 if (UsePerfData) { | |
1840 _perf_sum_nmethod_size->inc(code->total_size()); | |
1841 _perf_sum_nmethod_code_size->inc(code->code_size()); | |
1842 _perf_total_compile_count->inc(); | |
1843 } | |
1844 | |
1845 if (is_osr) { | |
1846 if (UsePerfData) _perf_total_osr_compile_count->inc(); | |
1847 _total_osr_compile_count++; | |
1848 } else { | |
1849 if (UsePerfData) _perf_total_standard_compile_count->inc(); | |
1850 _total_standard_compile_count++; | |
1851 } | |
1852 } | |
1853 // set the current method for the thread to null | |
1854 if (UsePerfData) counters->set_current_method(""); | |
1855 } | |
1856 | |
1857 | |
1858 | |
1859 void CompileBroker::print_times() { | |
1860 tty->cr(); | |
1861 tty->print_cr("Accumulated compiler times (for compiled methods only)"); | |
1862 tty->print_cr("------------------------------------------------"); | |
1863 //0000000000111111111122222222223333333333444444444455555555556666666666 | |
1864 //0123456789012345678901234567890123456789012345678901234567890123456789 | |
1865 tty->print_cr(" Total compilation time : %6.3f s", CompileBroker::_t_total_compilation.seconds()); | |
1866 tty->print_cr(" Standard compilation : %6.3f s, Average : %2.3f", | |
1867 CompileBroker::_t_standard_compilation.seconds(), | |
1868 CompileBroker::_t_standard_compilation.seconds() / CompileBroker::_total_standard_compile_count); | |
1869 tty->print_cr(" On stack replacement : %6.3f s, Average : %2.3f", CompileBroker::_t_osr_compilation.seconds(), CompileBroker::_t_osr_compilation.seconds() / CompileBroker::_total_osr_compile_count); | |
1131 | 1870 |
1871 if (compiler(CompLevel_fast_compile)) { | |
1872 compiler(CompLevel_fast_compile)->print_timers(); | |
1873 if (compiler(CompLevel_fast_compile) != compiler(CompLevel_highest_tier)) | |
1874 compiler(CompLevel_highest_tier)->print_timers(); | |
0 | 1875 } |
1876 | |
1877 tty->cr(); | |
1878 int tcb = CompileBroker::_sum_osr_bytes_compiled + CompileBroker::_sum_standard_bytes_compiled; | |
1879 tty->print_cr(" Total compiled bytecodes : %6d bytes", tcb); | |
1880 tty->print_cr(" Standard compilation : %6d bytes", CompileBroker::_sum_standard_bytes_compiled); | |
1881 tty->print_cr(" On stack replacement : %6d bytes", CompileBroker::_sum_osr_bytes_compiled); | |
1882 int bps = (int)(tcb / CompileBroker::_t_total_compilation.seconds()); | |
1883 tty->print_cr(" Average compilation speed: %6d bytes/s", bps); | |
1884 tty->cr(); | |
1885 tty->print_cr(" nmethod code size : %6d bytes", CompileBroker::_sum_nmethod_code_size); | |
1886 tty->print_cr(" nmethod total size : %6d bytes", CompileBroker::_sum_nmethod_size); | |
1887 } | |
1888 | |
1889 | |
1890 // Debugging output for failure | |
1891 void CompileBroker::print_last_compile() { | |
1892 if ( _last_compile_level != CompLevel_none && | |
1893 compiler(_last_compile_level) != NULL && | |
1894 _last_method_compiled != NULL && | |
1895 _last_compile_type != no_compile) { | |
1896 if (_last_compile_type == osr_compile) { | |
1897 tty->print_cr("Last parse: [osr]%d+++(%d) %s", | |
1898 _osr_compilation_id, _last_compile_level, _last_method_compiled); | |
1899 } else { | |
1900 tty->print_cr("Last parse: %d+++(%d) %s", | |
1901 _compilation_id, _last_compile_level, _last_method_compiled); | |
1902 } | |
1903 } | |
1904 } | |
1905 | |
1906 | |
1907 void CompileBroker::print_compiler_threads_on(outputStream* st) { | |
1908 #ifndef PRODUCT | |
1909 st->print_cr("Compiler thread printing unimplemented."); | |
1910 st->cr(); | |
1911 #endif | |
1912 } |