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