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