Mercurial > hg > graal-compiler
annotate src/share/vm/compiler/compileBroker.hpp @ 6271:93c71eb28866
7188911: nightly failures after JSR 292 lazy method handle update (round 2)
Reviewed-by: kvn, jrose
author | twisti |
---|---|
date | Tue, 07 Aug 2012 14:32:08 -0700 |
parents | 1d7922586cf6 |
children | 957c266d8bc5 da91efe96a93 |
rev | line source |
---|---|
0 | 1 /* |
4872
aa3d708d67c4
7141200: log some interesting information in ring buffers for crashes
never
parents:
4825
diff
changeset
|
2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1489
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1489
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1489
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #ifndef SHARE_VM_COMPILER_COMPILEBROKER_HPP |
26 #define SHARE_VM_COMPILER_COMPILEBROKER_HPP | |
27 | |
28 #include "ci/compilerInterface.hpp" | |
29 #include "compiler/abstractCompiler.hpp" | |
30 #include "runtime/perfData.hpp" | |
31 | |
0 | 32 class nmethod; |
33 class nmethodLocker; | |
34 | |
35 // CompileTask | |
36 // | |
37 // An entry in the compile queue. It represents a pending or current | |
38 // compilation. | |
6197 | 39 class CompileTask : public CHeapObj<mtCompiler> { |
3939 | 40 friend class VMStructs; |
41 | |
0 | 42 private: |
43 Monitor* _lock; | |
44 uint _compile_id; | |
45 jobject _method; | |
46 int _osr_bci; | |
47 bool _is_complete; | |
48 bool _is_success; | |
49 bool _is_blocking; | |
50 int _comp_level; | |
51 int _num_inlined_bytecodes; | |
52 nmethodLocker* _code_handle; // holder of eventual result | |
1783 | 53 CompileTask* _next, *_prev; |
0 | 54 |
55 // Fields used for logging why the compilation was initiated: | |
56 jlong _time_queued; // in units of os::elapsed_counter() | |
57 jobject _hot_method; // which method actually triggered this task | |
58 int _hot_count; // information about its invocation counter | |
59 const char* _comment; // more info about the task | |
60 | |
61 public: | |
62 CompileTask() { | |
63 _lock = new Monitor(Mutex::nonleaf+2, "CompileTaskLock"); | |
64 } | |
65 | |
66 void initialize(int compile_id, methodHandle method, int osr_bci, int comp_level, | |
67 methodHandle hot_method, int hot_count, const char* comment, | |
68 bool is_blocking); | |
69 | |
70 void free(); | |
71 | |
72 int compile_id() const { return _compile_id; } | |
73 jobject method_handle() const { return _method; } | |
74 int osr_bci() const { return _osr_bci; } | |
75 bool is_complete() const { return _is_complete; } | |
76 bool is_blocking() const { return _is_blocking; } | |
77 bool is_success() const { return _is_success; } | |
78 | |
79 nmethodLocker* code_handle() const { return _code_handle; } | |
80 void set_code_handle(nmethodLocker* l) { _code_handle = l; } | |
81 nmethod* code() const; // _code_handle->code() | |
82 void set_code(nmethod* nm); // _code_handle->set_code(nm) | |
83 | |
84 Monitor* lock() const { return _lock; } | |
85 | |
86 void mark_complete() { _is_complete = true; } | |
87 void mark_success() { _is_success = true; } | |
88 | |
89 int comp_level() { return _comp_level;} | |
90 void set_comp_level(int comp_level) { _comp_level = comp_level;} | |
91 | |
92 int num_inlined_bytecodes() const { return _num_inlined_bytecodes; } | |
93 void set_num_inlined_bytecodes(int n) { _num_inlined_bytecodes = n; } | |
94 | |
95 CompileTask* next() const { return _next; } | |
96 void set_next(CompileTask* next) { _next = next; } | |
1783 | 97 CompileTask* prev() const { return _prev; } |
98 void set_prev(CompileTask* prev) { _prev = prev; } | |
0 | 99 |
2405
3d58a4983660
7022998: JSR 292 recursive method handle calls inline themselves infinitely
twisti
parents:
1972
diff
changeset
|
100 private: |
4872
aa3d708d67c4
7141200: log some interesting information in ring buffers for crashes
never
parents:
4825
diff
changeset
|
101 static void print_compilation_impl(outputStream* st, methodOop method, int compile_id, int comp_level, |
aa3d708d67c4
7141200: log some interesting information in ring buffers for crashes
never
parents:
4825
diff
changeset
|
102 bool is_osr_method = false, int osr_bci = -1, bool is_blocking = false, |
aa3d708d67c4
7141200: log some interesting information in ring buffers for crashes
never
parents:
4825
diff
changeset
|
103 const char* msg = NULL, bool short_form = false); |
2405
3d58a4983660
7022998: JSR 292 recursive method handle calls inline themselves infinitely
twisti
parents:
1972
diff
changeset
|
104 |
3d58a4983660
7022998: JSR 292 recursive method handle calls inline themselves infinitely
twisti
parents:
1972
diff
changeset
|
105 public: |
4872
aa3d708d67c4
7141200: log some interesting information in ring buffers for crashes
never
parents:
4825
diff
changeset
|
106 void print_compilation(outputStream* st = tty, bool short_form = false); |
6266
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6197
diff
changeset
|
107 static void print_compilation(outputStream* st, const nmethod* nm, const char* msg = NULL, bool short_form = false) { |
4872
aa3d708d67c4
7141200: log some interesting information in ring buffers for crashes
never
parents:
4825
diff
changeset
|
108 print_compilation_impl(st, nm->method(), nm->compile_id(), nm->comp_level(), |
aa3d708d67c4
7141200: log some interesting information in ring buffers for crashes
never
parents:
4825
diff
changeset
|
109 nm->is_osr_method(), nm->is_osr_method() ? nm->osr_entry_bci() : -1, /*is_blocking*/ false, |
6266
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6197
diff
changeset
|
110 msg, short_form); |
2405
3d58a4983660
7022998: JSR 292 recursive method handle calls inline themselves infinitely
twisti
parents:
1972
diff
changeset
|
111 } |
3d58a4983660
7022998: JSR 292 recursive method handle calls inline themselves infinitely
twisti
parents:
1972
diff
changeset
|
112 |
3d58a4983660
7022998: JSR 292 recursive method handle calls inline themselves infinitely
twisti
parents:
1972
diff
changeset
|
113 static void print_inlining(outputStream* st, ciMethod* method, int inline_level, int bci, const char* msg = NULL); |
3d58a4983660
7022998: JSR 292 recursive method handle calls inline themselves infinitely
twisti
parents:
1972
diff
changeset
|
114 static void print_inlining(ciMethod* method, int inline_level, int bci, const char* msg = NULL) { |
3d58a4983660
7022998: JSR 292 recursive method handle calls inline themselves infinitely
twisti
parents:
1972
diff
changeset
|
115 print_inlining(tty, method, inline_level, bci, msg); |
3d58a4983660
7022998: JSR 292 recursive method handle calls inline themselves infinitely
twisti
parents:
1972
diff
changeset
|
116 } |
3d58a4983660
7022998: JSR 292 recursive method handle calls inline themselves infinitely
twisti
parents:
1972
diff
changeset
|
117 |
3d58a4983660
7022998: JSR 292 recursive method handle calls inline themselves infinitely
twisti
parents:
1972
diff
changeset
|
118 static void print_inline_indent(int inline_level, outputStream* st = tty); |
3d58a4983660
7022998: JSR 292 recursive method handle calls inline themselves infinitely
twisti
parents:
1972
diff
changeset
|
119 |
0 | 120 void print(); |
121 void print_line(); | |
2405
3d58a4983660
7022998: JSR 292 recursive method handle calls inline themselves infinitely
twisti
parents:
1972
diff
changeset
|
122 void print_line_on_error(outputStream* st, char* buf, int buflen); |
1783 | 123 |
0 | 124 void log_task(xmlStream* log); |
125 void log_task_queued(); | |
126 void log_task_start(CompileLog* log); | |
127 void log_task_done(CompileLog* log); | |
128 }; | |
129 | |
130 // CompilerCounters | |
131 // | |
132 // Per Compiler Performance Counters. | |
133 // | |
6197 | 134 class CompilerCounters : public CHeapObj<mtCompiler> { |
0 | 135 |
136 public: | |
137 enum { | |
138 cmname_buffer_length = 160 | |
139 }; | |
140 | |
141 private: | |
142 | |
143 char _current_method[cmname_buffer_length]; | |
144 PerfStringVariable* _perf_current_method; | |
145 | |
146 int _compile_type; | |
147 PerfVariable* _perf_compile_type; | |
148 | |
149 PerfCounter* _perf_time; | |
150 PerfCounter* _perf_compiles; | |
151 | |
152 public: | |
153 CompilerCounters(const char* name, int instance, TRAPS); | |
154 | |
155 // these methods should be called in a thread safe context | |
156 | |
157 void set_current_method(const char* method) { | |
158 strncpy(_current_method, method, (size_t)cmname_buffer_length); | |
159 if (UsePerfData) _perf_current_method->set_value(method); | |
160 } | |
161 | |
162 char* current_method() { return _current_method; } | |
163 | |
164 void set_compile_type(int compile_type) { | |
165 _compile_type = compile_type; | |
166 if (UsePerfData) _perf_compile_type->set_value((jlong)compile_type); | |
167 } | |
168 | |
169 int compile_type() { return _compile_type; } | |
170 | |
171 PerfCounter* time_counter() { return _perf_time; } | |
172 PerfCounter* compile_counter() { return _perf_compiles; } | |
173 }; | |
174 | |
175 // CompileQueue | |
176 // | |
177 // A list of CompileTasks. | |
6197 | 178 class CompileQueue : public CHeapObj<mtCompiler> { |
0 | 179 private: |
180 const char* _name; | |
181 Monitor* _lock; | |
182 | |
183 CompileTask* _first; | |
184 CompileTask* _last; | |
185 | |
1783 | 186 int _size; |
0 | 187 public: |
188 CompileQueue(const char* name, Monitor* lock) { | |
189 _name = name; | |
190 _lock = lock; | |
191 _first = NULL; | |
192 _last = NULL; | |
1783 | 193 _size = 0; |
0 | 194 } |
195 | |
196 const char* name() const { return _name; } | |
197 Monitor* lock() const { return _lock; } | |
198 | |
199 void add(CompileTask* task); | |
1783 | 200 void remove(CompileTask* task); |
201 CompileTask* first() { return _first; } | |
202 CompileTask* last() { return _last; } | |
0 | 203 |
204 CompileTask* get(); | |
205 | |
206 bool is_empty() const { return _first == NULL; } | |
1783 | 207 int size() const { return _size; } |
0 | 208 |
209 void print(); | |
210 }; | |
211 | |
1783 | 212 // CompileTaskWrapper |
213 // | |
214 // Assign this task to the current thread. Deallocate the task | |
215 // when the compilation is complete. | |
216 class CompileTaskWrapper : StackObj { | |
217 public: | |
218 CompileTaskWrapper(CompileTask* task); | |
219 ~CompileTaskWrapper(); | |
220 }; | |
221 | |
0 | 222 |
223 // Compilation | |
224 // | |
225 // The broker for all compilation requests. | |
226 class CompileBroker: AllStatic { | |
227 friend class Threads; | |
228 friend class CompileTaskWrapper; | |
229 | |
230 public: | |
231 enum { | |
232 name_buffer_length = 100 | |
233 }; | |
234 | |
235 // Compile type Information for print_last_compile() and CompilerCounters | |
236 enum { no_compile, normal_compile, osr_compile, native_compile }; | |
237 | |
238 private: | |
239 static bool _initialized; | |
240 static volatile bool _should_block; | |
241 | |
1202 | 242 // This flag can be used to stop compilation or turn it back on |
243 static volatile jint _should_compile_new_jobs; | |
244 | |
0 | 245 // The installed compiler(s) |
246 static AbstractCompiler* _compilers[2]; | |
247 | |
248 // These counters are used for assigning id's to each compilation | |
249 static uint _compilation_id; | |
250 static uint _osr_compilation_id; | |
251 static uint _native_compilation_id; | |
252 | |
253 static int _last_compile_type; | |
254 static int _last_compile_level; | |
255 static char _last_method_compiled[name_buffer_length]; | |
256 | |
1783 | 257 static CompileQueue* _c2_method_queue; |
258 static CompileQueue* _c1_method_queue; | |
0 | 259 static CompileTask* _task_free_list; |
260 | |
261 static GrowableArray<CompilerThread*>* _method_threads; | |
262 | |
263 // performance counters | |
264 static PerfCounter* _perf_total_compilation; | |
265 static PerfCounter* _perf_native_compilation; | |
266 static PerfCounter* _perf_osr_compilation; | |
267 static PerfCounter* _perf_standard_compilation; | |
268 | |
269 static PerfCounter* _perf_total_bailout_count; | |
270 static PerfCounter* _perf_total_invalidated_count; | |
271 static PerfCounter* _perf_total_compile_count; | |
272 static PerfCounter* _perf_total_native_compile_count; | |
273 static PerfCounter* _perf_total_osr_compile_count; | |
274 static PerfCounter* _perf_total_standard_compile_count; | |
275 | |
276 static PerfCounter* _perf_sum_osr_bytes_compiled; | |
277 static PerfCounter* _perf_sum_standard_bytes_compiled; | |
278 static PerfCounter* _perf_sum_nmethod_size; | |
279 static PerfCounter* _perf_sum_nmethod_code_size; | |
280 | |
281 static PerfStringVariable* _perf_last_method; | |
282 static PerfStringVariable* _perf_last_failed_method; | |
283 static PerfStringVariable* _perf_last_invalidated_method; | |
284 static PerfVariable* _perf_last_compile_type; | |
285 static PerfVariable* _perf_last_compile_size; | |
286 static PerfVariable* _perf_last_failed_type; | |
287 static PerfVariable* _perf_last_invalidated_type; | |
288 | |
289 // Timers and counters for generating statistics | |
290 static elapsedTimer _t_total_compilation; | |
291 static elapsedTimer _t_osr_compilation; | |
292 static elapsedTimer _t_standard_compilation; | |
293 | |
294 static int _total_bailout_count; | |
295 static int _total_invalidated_count; | |
296 static int _total_compile_count; | |
297 static int _total_native_compile_count; | |
298 static int _total_osr_compile_count; | |
299 static int _total_standard_compile_count; | |
300 | |
301 static int _sum_osr_bytes_compiled; | |
302 static int _sum_standard_bytes_compiled; | |
303 static int _sum_nmethod_size; | |
304 static int _sum_nmethod_code_size; | |
305 | |
306 static CompilerThread* make_compiler_thread(const char* name, CompileQueue* queue, CompilerCounters* counters, TRAPS); | |
1783 | 307 static void init_compiler_threads(int c1_compiler_count, int c2_compiler_count); |
0 | 308 static bool compilation_is_complete (methodHandle method, int osr_bci, int comp_level); |
309 static bool compilation_is_prohibited(methodHandle method, int osr_bci, int comp_level); | |
310 static uint assign_compile_id (methodHandle method, int osr_bci); | |
311 static bool is_compile_blocking (methodHandle method, int osr_bci); | |
312 static void preload_classes (methodHandle method, TRAPS); | |
313 | |
314 static CompileTask* create_compile_task(CompileQueue* queue, | |
315 int compile_id, | |
316 methodHandle method, | |
317 int osr_bci, | |
318 int comp_level, | |
319 methodHandle hot_method, | |
320 int hot_count, | |
321 const char* comment, | |
322 bool blocking); | |
323 static CompileTask* allocate_task(); | |
324 static void free_task(CompileTask* task); | |
325 static void wait_for_completion(CompileTask* task); | |
326 | |
327 static void invoke_compiler_on_method(CompileTask* task); | |
328 static void set_last_compile(CompilerThread *thread, methodHandle method, bool is_osr, int comp_level); | |
329 static void push_jni_handle_block(); | |
330 static void pop_jni_handle_block(); | |
331 static bool check_break_at(methodHandle method, int compile_id, bool is_osr); | |
332 static void collect_statistics(CompilerThread* thread, elapsedTimer time, CompileTask* task); | |
333 | |
334 static void compile_method_base(methodHandle method, | |
335 int osr_bci, | |
336 int comp_level, | |
337 methodHandle hot_method, | |
338 int hot_count, | |
339 const char* comment, | |
4825
20334ed5ed3c
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
3939
diff
changeset
|
340 Thread* thread); |
1783 | 341 static CompileQueue* compile_queue(int comp_level) { |
342 if (is_c2_compile(comp_level)) return _c2_method_queue; | |
343 if (is_c1_compile(comp_level)) return _c1_method_queue; | |
344 return NULL; | |
345 } | |
0 | 346 public: |
347 enum { | |
348 // The entry bci used for non-OSR compilations. | |
349 standard_entry_bci = InvocationEntryBci | |
350 }; | |
351 | |
1783 | 352 static AbstractCompiler* compiler(int comp_level) { |
353 if (is_c2_compile(comp_level)) return _compilers[1]; // C2 | |
354 if (is_c1_compile(comp_level)) return _compilers[0]; // C1 | |
355 return NULL; | |
0 | 356 } |
357 | |
1783 | 358 static bool compilation_is_in_queue(methodHandle method, int osr_bci); |
359 static int queue_size(int comp_level) { | |
360 CompileQueue *q = compile_queue(comp_level); | |
361 return q != NULL ? q->size() : 0; | |
362 } | |
0 | 363 static void compilation_init(); |
364 static void init_compiler_thread_log(); | |
1783 | 365 static nmethod* compile_method(methodHandle method, |
366 int osr_bci, | |
367 int comp_level, | |
368 methodHandle hot_method, | |
369 int hot_count, | |
4825
20334ed5ed3c
7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents:
3939
diff
changeset
|
370 const char* comment, Thread* thread); |
0 | 371 |
372 static void compiler_thread_loop(); | |
373 | |
1202 | 374 static uint get_compilation_id() { return _compilation_id; } |
0 | 375 static bool is_idle(); |
376 | |
377 // Set _should_block. | |
378 // Call this from the VM, with Threads_lock held and a safepoint requested. | |
379 static void set_should_block(); | |
380 | |
381 // Call this from the compiler at convenient points, to poll for _should_block. | |
382 static void maybe_block(); | |
383 | |
1202 | 384 enum { |
385 // Flags for toggling compiler activity | |
386 stop_compilation = 0, | |
387 run_compilation = 1 | |
388 }; | |
389 | |
390 static bool should_compile_new_jobs() { return UseCompiler && (_should_compile_new_jobs == run_compilation); } | |
391 static bool set_should_compile_new_jobs(jint new_state) { | |
392 // Return success if the current caller set it | |
393 jint old = Atomic::cmpxchg(new_state, &_should_compile_new_jobs, 1-new_state); | |
394 return (old == (1-new_state)); | |
395 } | |
396 static void handle_full_code_cache(); | |
397 | |
0 | 398 // Return total compilation ticks |
399 static jlong total_compilation_ticks() { | |
400 return _perf_total_compilation != NULL ? _perf_total_compilation->get_value() : 0; | |
401 } | |
402 | |
403 // Print a detailed accounting of compilation time | |
404 static void print_times(); | |
405 | |
406 // Debugging output for failure | |
407 static void print_last_compile(); | |
408 | |
409 static void print_compiler_threads_on(outputStream* st); | |
410 }; | |
1972 | 411 |
412 #endif // SHARE_VM_COMPILER_COMPILEBROKER_HPP |