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