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