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