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