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