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