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