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