Mercurial > hg > graal-compiler
annotate src/share/vm/c1/c1_Compilation.cpp @ 8960:0ba33199edc0
invokedynamic: constant fold call site target with assumption; minor fixes
author | Andreas Woess <andreas.woess@jku.at> |
---|---|
date | Tue, 09 Apr 2013 20:37:06 +0200 |
parents | 46f6f063b272 |
children | e47de6dfec5d |
rev | line source |
---|---|
0 | 1 /* |
6842
b9a9ed0f8eeb
7197424: update copyright year to match last edit in jdk8 hotspot repository
mikael
parents:
6792
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:
1397
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1397
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:
1397
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "c1/c1_CFGPrinter.hpp" | |
27 #include "c1/c1_Compilation.hpp" | |
28 #include "c1/c1_IR.hpp" | |
29 #include "c1/c1_LIRAssembler.hpp" | |
30 #include "c1/c1_LinearScan.hpp" | |
31 #include "c1/c1_MacroAssembler.hpp" | |
32 #include "c1/c1_ValueMap.hpp" | |
33 #include "c1/c1_ValueStack.hpp" | |
34 #include "code/debugInfoRec.hpp" | |
6843 | 35 #include "compiler/compileLog.hpp" |
8860 | 36 #include "c1/c1_RangeCheckElimination.hpp" |
0 | 37 |
38 | |
39 typedef enum { | |
40 _t_compile, | |
41 _t_setup, | |
42 _t_buildIR, | |
8860 | 43 _t_optimize_blocks, |
44 _t_optimize_null_checks, | |
45 _t_rangeCheckElimination, | |
0 | 46 _t_emit_lir, |
47 _t_linearScan, | |
48 _t_lirGeneration, | |
49 _t_lir_schedule, | |
50 _t_codeemit, | |
51 _t_codeinstall, | |
52 max_phase_timers | |
53 } TimerName; | |
54 | |
55 static const char * timer_name[] = { | |
56 "compile", | |
57 "setup", | |
58 "buildIR", | |
8860 | 59 "optimize_blocks", |
60 "optimize_null_checks", | |
61 "rangeCheckElimination", | |
0 | 62 "emit_lir", |
63 "linearScan", | |
64 "lirGeneration", | |
65 "lir_schedule", | |
66 "codeemit", | |
67 "codeinstall" | |
68 }; | |
69 | |
70 static elapsedTimer timers[max_phase_timers]; | |
71 static int totalInstructionNodes = 0; | |
72 | |
73 class PhaseTraceTime: public TraceTime { | |
74 private: | |
75 JavaThread* _thread; | |
6843 | 76 CompileLog* _log; |
0 | 77 |
78 public: | |
6843 | 79 PhaseTraceTime(TimerName timer) |
80 : TraceTime("", &timers[timer], CITime || CITimeEach, Verbose), _log(NULL) { | |
81 if (Compilation::current() != NULL) { | |
82 _log = Compilation::current()->log(); | |
83 } | |
84 | |
85 if (_log != NULL) { | |
86 _log->begin_head("phase name='%s'", timer_name[timer]); | |
87 _log->stamp(); | |
88 _log->end_head(); | |
89 } | |
90 } | |
91 | |
92 ~PhaseTraceTime() { | |
93 if (_log != NULL) | |
94 _log->done("phase"); | |
0 | 95 } |
96 }; | |
97 | |
98 // Implementation of Compilation | |
99 | |
100 | |
101 #ifndef PRODUCT | |
102 | |
103 void Compilation::maybe_print_current_instruction() { | |
104 if (_current_instruction != NULL && _last_instruction_printed != _current_instruction) { | |
105 _last_instruction_printed = _current_instruction; | |
106 _current_instruction->print_line(); | |
107 } | |
108 } | |
109 #endif // PRODUCT | |
110 | |
111 | |
112 DebugInformationRecorder* Compilation::debug_info_recorder() const { | |
113 return _env->debug_info(); | |
114 } | |
115 | |
116 | |
117 Dependencies* Compilation::dependency_recorder() const { | |
118 return _env->dependencies(); | |
119 } | |
120 | |
121 | |
122 void Compilation::initialize() { | |
123 // Use an oop recorder bound to the CI environment. | |
124 // (The default oop recorder is ignorant of the CI.) | |
125 OopRecorder* ooprec = new OopRecorder(_env->arena()); | |
126 _env->set_oop_recorder(ooprec); | |
127 _env->set_debug_info(new DebugInformationRecorder(ooprec)); | |
128 debug_info_recorder()->set_oopmaps(new OopMapSet()); | |
129 _env->set_dependencies(new Dependencies(_env)); | |
130 } | |
131 | |
132 | |
133 void Compilation::build_hir() { | |
134 CHECK_BAILOUT(); | |
135 | |
136 // setup ir | |
7201
c5d414e98fd4
8003983: LogCompilation tool is broken since c1 support
neliasso
parents:
6853
diff
changeset
|
137 CompileLog* log = this->log(); |
c5d414e98fd4
8003983: LogCompilation tool is broken since c1 support
neliasso
parents:
6853
diff
changeset
|
138 if (log != NULL) { |
c5d414e98fd4
8003983: LogCompilation tool is broken since c1 support
neliasso
parents:
6853
diff
changeset
|
139 log->begin_head("parse method='%d' ", |
c5d414e98fd4
8003983: LogCompilation tool is broken since c1 support
neliasso
parents:
6853
diff
changeset
|
140 log->identify(_method)); |
c5d414e98fd4
8003983: LogCompilation tool is broken since c1 support
neliasso
parents:
6853
diff
changeset
|
141 log->stamp(); |
c5d414e98fd4
8003983: LogCompilation tool is broken since c1 support
neliasso
parents:
6853
diff
changeset
|
142 log->end_head(); |
c5d414e98fd4
8003983: LogCompilation tool is broken since c1 support
neliasso
parents:
6853
diff
changeset
|
143 } |
0 | 144 _hir = new IR(this, method(), osr_bci()); |
7201
c5d414e98fd4
8003983: LogCompilation tool is broken since c1 support
neliasso
parents:
6853
diff
changeset
|
145 if (log) log->done("parse"); |
0 | 146 if (!_hir->is_valid()) { |
147 bailout("invalid parsing"); | |
148 return; | |
149 } | |
150 | |
151 #ifndef PRODUCT | |
152 if (PrintCFGToFile) { | |
153 CFGPrinter::print_cfg(_hir, "After Generation of HIR", true, false); | |
154 } | |
155 #endif | |
156 | |
157 #ifndef PRODUCT | |
158 if (PrintCFG || PrintCFG0) { tty->print_cr("CFG after parsing"); _hir->print(true); } | |
159 if (PrintIR || PrintIR0 ) { tty->print_cr("IR after parsing"); _hir->print(false); } | |
160 #endif | |
161 | |
162 _hir->verify(); | |
163 | |
164 if (UseC1Optimizations) { | |
165 NEEDS_CLEANUP | |
166 // optimization | |
8860 | 167 PhaseTraceTime timeit(_t_optimize_blocks); |
0 | 168 |
8860 | 169 _hir->optimize_blocks(); |
0 | 170 } |
171 | |
172 _hir->verify(); | |
173 | |
174 _hir->split_critical_edges(); | |
175 | |
176 #ifndef PRODUCT | |
177 if (PrintCFG || PrintCFG1) { tty->print_cr("CFG after optimizations"); _hir->print(true); } | |
178 if (PrintIR || PrintIR1 ) { tty->print_cr("IR after optimizations"); _hir->print(false); } | |
179 #endif | |
180 | |
181 _hir->verify(); | |
182 | |
183 // compute block ordering for code generation | |
184 // the control flow must not be changed from here on | |
185 _hir->compute_code(); | |
186 | |
187 if (UseGlobalValueNumbering) { | |
8860 | 188 // No resource mark here! LoopInvariantCodeMotion can allocate ValueStack objects. |
0 | 189 int instructions = Instruction::number_of_instructions(); |
190 GlobalValueNumbering gvn(_hir); | |
191 assert(instructions == Instruction::number_of_instructions(), | |
192 "shouldn't have created an instructions"); | |
193 } | |
194 | |
8860 | 195 _hir->verify(); |
196 | |
197 #ifndef PRODUCT | |
198 if (PrintCFGToFile) { | |
199 CFGPrinter::print_cfg(_hir, "Before RangeCheckElimination", true, false); | |
200 } | |
201 #endif | |
202 | |
203 if (RangeCheckElimination) { | |
204 if (_hir->osr_entry() == NULL) { | |
205 PhaseTraceTime timeit(_t_rangeCheckElimination); | |
206 RangeCheckElimination::eliminate(_hir); | |
207 } | |
208 } | |
209 | |
210 #ifndef PRODUCT | |
211 if (PrintCFGToFile) { | |
212 CFGPrinter::print_cfg(_hir, "After RangeCheckElimination", true, false); | |
213 } | |
214 #endif | |
215 | |
216 if (UseC1Optimizations) { | |
217 // loop invariant code motion reorders instructions and range | |
218 // check elimination adds new instructions so do null check | |
219 // elimination after. | |
220 NEEDS_CLEANUP | |
221 // optimization | |
222 PhaseTraceTime timeit(_t_optimize_null_checks); | |
223 | |
224 _hir->eliminate_null_checks(); | |
225 } | |
226 | |
227 _hir->verify(); | |
228 | |
0 | 229 // compute use counts after global value numbering |
230 _hir->compute_use_counts(); | |
231 | |
232 #ifndef PRODUCT | |
233 if (PrintCFG || PrintCFG2) { tty->print_cr("CFG before code generation"); _hir->code()->print(true); } | |
234 if (PrintIR || PrintIR2 ) { tty->print_cr("IR before code generation"); _hir->code()->print(false, true); } | |
235 #endif | |
236 | |
237 _hir->verify(); | |
238 } | |
239 | |
240 | |
241 void Compilation::emit_lir() { | |
242 CHECK_BAILOUT(); | |
243 | |
244 LIRGenerator gen(this, method()); | |
245 { | |
246 PhaseTraceTime timeit(_t_lirGeneration); | |
247 hir()->iterate_linear_scan_order(&gen); | |
248 } | |
249 | |
250 CHECK_BAILOUT(); | |
251 | |
252 { | |
253 PhaseTraceTime timeit(_t_linearScan); | |
254 | |
255 LinearScan* allocator = new LinearScan(hir(), &gen, frame_map()); | |
256 set_allocator(allocator); | |
257 // Assign physical registers to LIR operands using a linear scan algorithm. | |
258 allocator->do_linear_scan(); | |
259 CHECK_BAILOUT(); | |
260 | |
261 _max_spills = allocator->max_spills(); | |
262 } | |
263 | |
264 if (BailoutAfterLIR) { | |
265 if (PrintLIR && !bailed_out()) { | |
266 print_LIR(hir()->code()); | |
267 } | |
268 bailout("Bailing out because of -XX:+BailoutAfterLIR"); | |
269 } | |
270 } | |
271 | |
272 | |
273 void Compilation::emit_code_epilog(LIR_Assembler* assembler) { | |
274 CHECK_BAILOUT(); | |
275 | |
1204 | 276 CodeOffsets* code_offsets = assembler->offsets(); |
277 | |
0 | 278 // generate code or slow cases |
279 assembler->emit_slow_case_stubs(); | |
280 CHECK_BAILOUT(); | |
281 | |
282 // generate exception adapters | |
283 assembler->emit_exception_entries(exception_info_list()); | |
284 CHECK_BAILOUT(); | |
285 | |
1204 | 286 // Generate code for exception handler. |
287 code_offsets->set_value(CodeOffsets::Exceptions, assembler->emit_exception_handler()); | |
0 | 288 CHECK_BAILOUT(); |
1204 | 289 |
290 // Generate code for deopt handler. | |
291 code_offsets->set_value(CodeOffsets::Deopt, assembler->emit_deopt_handler()); | |
292 CHECK_BAILOUT(); | |
293 | |
1691
4a665be40fd3
6975855: don't emit deopt MH handler in C1 if not required
twisti
parents:
1617
diff
changeset
|
294 // Emit the MethodHandle deopt handler code (if required). |
4a665be40fd3
6975855: don't emit deopt MH handler in C1 if not required
twisti
parents:
1617
diff
changeset
|
295 if (has_method_handle_invokes()) { |
4a665be40fd3
6975855: don't emit deopt MH handler in C1 if not required
twisti
parents:
1617
diff
changeset
|
296 // We can use the same code as for the normal deopt handler, we |
4a665be40fd3
6975855: don't emit deopt MH handler in C1 if not required
twisti
parents:
1617
diff
changeset
|
297 // just need a different entry point address. |
4a665be40fd3
6975855: don't emit deopt MH handler in C1 if not required
twisti
parents:
1617
diff
changeset
|
298 code_offsets->set_value(CodeOffsets::DeoptMH, assembler->emit_deopt_handler()); |
4a665be40fd3
6975855: don't emit deopt MH handler in C1 if not required
twisti
parents:
1617
diff
changeset
|
299 CHECK_BAILOUT(); |
4a665be40fd3
6975855: don't emit deopt MH handler in C1 if not required
twisti
parents:
1617
diff
changeset
|
300 } |
0 | 301 |
1378
9f5b60a14736
6939930: exception unwind changes in 6919934 hurts compilation speed
never
parents:
1204
diff
changeset
|
302 // Emit the handler to remove the activation from the stack and |
9f5b60a14736
6939930: exception unwind changes in 6919934 hurts compilation speed
never
parents:
1204
diff
changeset
|
303 // dispatch to the caller. |
9f5b60a14736
6939930: exception unwind changes in 6919934 hurts compilation speed
never
parents:
1204
diff
changeset
|
304 offsets()->set_value(CodeOffsets::UnwindHandler, assembler->emit_unwind_handler()); |
9f5b60a14736
6939930: exception unwind changes in 6919934 hurts compilation speed
never
parents:
1204
diff
changeset
|
305 |
0 | 306 // done |
307 masm()->flush(); | |
308 } | |
309 | |
310 | |
2098
2f9d59b0fa5c
7009268: guarantee(middle - slop > start) failed: need enough space to divide up
bobv
parents:
2007
diff
changeset
|
311 bool Compilation::setup_code_buffer(CodeBuffer* code, int call_stub_estimate) { |
1584 | 312 // Preinitialize the consts section to some large size: |
313 int locs_buffer_size = 20 * (relocInfo::length_limit + sizeof(relocInfo)); | |
314 char* locs_buffer = NEW_RESOURCE_ARRAY(char, locs_buffer_size); | |
315 code->insts()->initialize_shared_locs((relocInfo*)locs_buffer, | |
316 locs_buffer_size / sizeof(relocInfo)); | |
317 code->initialize_consts_size(Compilation::desired_max_constant_size()); | |
1617
9887b5e57f9e
6962980: C1: stub area should take into account method handle deopt stub
iveresov
parents:
1584
diff
changeset
|
318 // Call stubs + two deopt handlers (regular and MH) + exception handler |
2098
2f9d59b0fa5c
7009268: guarantee(middle - slop > start) failed: need enough space to divide up
bobv
parents:
2007
diff
changeset
|
319 int stub_size = (call_stub_estimate * LIR_Assembler::call_stub_size) + |
2f9d59b0fa5c
7009268: guarantee(middle - slop > start) failed: need enough space to divide up
bobv
parents:
2007
diff
changeset
|
320 LIR_Assembler::exception_handler_size + |
2f9d59b0fa5c
7009268: guarantee(middle - slop > start) failed: need enough space to divide up
bobv
parents:
2007
diff
changeset
|
321 (2 * LIR_Assembler::deopt_handler_size); |
2f9d59b0fa5c
7009268: guarantee(middle - slop > start) failed: need enough space to divide up
bobv
parents:
2007
diff
changeset
|
322 if (stub_size >= code->insts_capacity()) return false; |
2f9d59b0fa5c
7009268: guarantee(middle - slop > start) failed: need enough space to divide up
bobv
parents:
2007
diff
changeset
|
323 code->initialize_stubs_size(stub_size); |
2f9d59b0fa5c
7009268: guarantee(middle - slop > start) failed: need enough space to divide up
bobv
parents:
2007
diff
changeset
|
324 return true; |
1584 | 325 } |
326 | |
327 | |
0 | 328 int Compilation::emit_code_body() { |
329 // emit code | |
2098
2f9d59b0fa5c
7009268: guarantee(middle - slop > start) failed: need enough space to divide up
bobv
parents:
2007
diff
changeset
|
330 if (!setup_code_buffer(code(), allocator()->num_calls())) { |
2f9d59b0fa5c
7009268: guarantee(middle - slop > start) failed: need enough space to divide up
bobv
parents:
2007
diff
changeset
|
331 BAILOUT_("size requested greater than avail code buffer size", 0); |
2f9d59b0fa5c
7009268: guarantee(middle - slop > start) failed: need enough space to divide up
bobv
parents:
2007
diff
changeset
|
332 } |
0 | 333 code()->initialize_oop_recorder(env()->oop_recorder()); |
334 | |
335 _masm = new C1_MacroAssembler(code()); | |
336 _masm->set_oop_recorder(env()->oop_recorder()); | |
337 | |
338 LIR_Assembler lir_asm(this); | |
339 | |
340 lir_asm.emit_code(hir()->code()); | |
341 CHECK_BAILOUT_(0); | |
342 | |
343 emit_code_epilog(&lir_asm); | |
344 CHECK_BAILOUT_(0); | |
345 | |
346 generate_exception_handler_table(); | |
347 | |
348 #ifndef PRODUCT | |
349 if (PrintExceptionHandlers && Verbose) { | |
350 exception_handler_table()->print(); | |
351 } | |
352 #endif /* PRODUCT */ | |
353 | |
354 return frame_map()->framesize(); | |
355 } | |
356 | |
357 | |
358 int Compilation::compile_java_method() { | |
359 assert(!method()->is_native(), "should not reach here"); | |
360 | |
361 if (BailoutOnExceptionHandlers) { | |
362 if (method()->has_exception_handlers()) { | |
363 bailout("linear scan can't handle exception handlers"); | |
364 } | |
365 } | |
366 | |
367 CHECK_BAILOUT_(no_frame_size); | |
368 | |
2007
5ddfcf4b079e
7003554: (tiered) assert(is_null_object() || handle() != NULL) failed: cannot embed null pointer
iveresov
parents:
1972
diff
changeset
|
369 if (is_profiling() && !method()->ensure_method_data()) { |
5ddfcf4b079e
7003554: (tiered) assert(is_null_object() || handle() != NULL) failed: cannot embed null pointer
iveresov
parents:
1972
diff
changeset
|
370 BAILOUT_("mdo allocation failed", no_frame_size); |
1783 | 371 } |
372 | |
0 | 373 { |
374 PhaseTraceTime timeit(_t_buildIR); | |
1783 | 375 build_hir(); |
0 | 376 } |
377 if (BailoutAfterHIR) { | |
378 BAILOUT_("Bailing out because of -XX:+BailoutAfterHIR", no_frame_size); | |
379 } | |
380 | |
381 | |
382 { | |
383 PhaseTraceTime timeit(_t_emit_lir); | |
384 | |
385 _frame_map = new FrameMap(method(), hir()->number_of_locks(), MAX2(4, hir()->max_stack())); | |
386 emit_lir(); | |
387 } | |
388 CHECK_BAILOUT_(no_frame_size); | |
389 | |
390 { | |
391 PhaseTraceTime timeit(_t_codeemit); | |
392 return emit_code_body(); | |
393 } | |
394 } | |
395 | |
396 void Compilation::install_code(int frame_size) { | |
397 // frame_size is in 32-bit words so adjust it intptr_t words | |
398 assert(frame_size == frame_map()->framesize(), "must match"); | |
399 assert(in_bytes(frame_map()->framesize_in_bytes()) % sizeof(intptr_t) == 0, "must be at least pointer aligned"); | |
400 _env->register_method( | |
401 method(), | |
402 osr_bci(), | |
403 &_offsets, | |
404 in_bytes(_frame_map->sp_offset_for_orig_pc()), | |
405 code(), | |
406 in_bytes(frame_map()->framesize_in_bytes()) / sizeof(intptr_t), | |
407 debug_info_recorder()->_oopmaps, | |
408 exception_handler_table(), | |
409 implicit_exception_table(), | |
410 compiler(), | |
411 _env->comp_level(), | |
6792
137868b7aa6f
7196199: java/text/Bidi/Bug6665028.java failed: Bidi run count incorrect
kvn
parents:
6266
diff
changeset
|
412 has_unsafe_access(), |
137868b7aa6f
7196199: java/text/Bidi/Bug6665028.java failed: Bidi run count incorrect
kvn
parents:
6266
diff
changeset
|
413 SharedRuntime::is_wide_vector(max_vector_size()) |
0 | 414 ); |
415 } | |
416 | |
417 | |
418 void Compilation::compile_method() { | |
419 // setup compilation | |
420 initialize(); | |
421 | |
422 if (!method()->can_be_compiled()) { | |
423 // Prevent race condition 6328518. | |
424 // This can happen if the method is obsolete or breakpointed. | |
425 bailout("Bailing out because method is not compilable"); | |
426 return; | |
427 } | |
428 | |
780
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
0
diff
changeset
|
429 if (_env->jvmti_can_hotswap_or_post_breakpoint()) { |
0 | 430 // We can assert evol_method because method->can_be_compiled is true. |
431 dependency_recorder()->assert_evol_method(method()); | |
432 } | |
433 | |
434 if (method()->break_at_execute()) { | |
435 BREAKPOINT; | |
436 } | |
437 | |
438 #ifndef PRODUCT | |
439 if (PrintCFGToFile) { | |
440 CFGPrinter::print_compilation(this); | |
441 } | |
442 #endif | |
443 | |
444 // compile method | |
445 int frame_size = compile_java_method(); | |
446 | |
447 // bailout if method couldn't be compiled | |
448 // Note: make sure we mark the method as not compilable! | |
449 CHECK_BAILOUT(); | |
450 | |
451 if (InstallMethods) { | |
452 // install code | |
453 PhaseTraceTime timeit(_t_codeinstall); | |
454 install_code(frame_size); | |
455 } | |
6843 | 456 |
457 if (log() != NULL) // Print code cache state into compiler log | |
458 log()->code_cache_state(); | |
459 | |
0 | 460 totalInstructionNodes += Instruction::number_of_instructions(); |
461 } | |
462 | |
463 | |
464 void Compilation::generate_exception_handler_table() { | |
465 // Generate an ExceptionHandlerTable from the exception handler | |
466 // information accumulated during the compilation. | |
467 ExceptionInfoList* info_list = exception_info_list(); | |
468 | |
469 if (info_list->length() == 0) { | |
470 return; | |
471 } | |
472 | |
473 // allocate some arrays for use by the collection code. | |
474 const int num_handlers = 5; | |
475 GrowableArray<intptr_t>* bcis = new GrowableArray<intptr_t>(num_handlers); | |
476 GrowableArray<intptr_t>* scope_depths = new GrowableArray<intptr_t>(num_handlers); | |
477 GrowableArray<intptr_t>* pcos = new GrowableArray<intptr_t>(num_handlers); | |
478 | |
479 for (int i = 0; i < info_list->length(); i++) { | |
480 ExceptionInfo* info = info_list->at(i); | |
481 XHandlers* handlers = info->exception_handlers(); | |
482 | |
483 // empty the arrays | |
484 bcis->trunc_to(0); | |
485 scope_depths->trunc_to(0); | |
486 pcos->trunc_to(0); | |
487 | |
488 for (int i = 0; i < handlers->length(); i++) { | |
489 XHandler* handler = handlers->handler_at(i); | |
490 assert(handler->entry_pco() != -1, "must have been generated"); | |
491 | |
492 int e = bcis->find(handler->handler_bci()); | |
493 if (e >= 0 && scope_depths->at(e) == handler->scope_count()) { | |
494 // two different handlers are declared to dispatch to the same | |
495 // catch bci. During parsing we created edges for each | |
496 // handler but we really only need one. The exception handler | |
497 // table will also get unhappy if we try to declare both since | |
498 // it's nonsensical. Just skip this handler. | |
499 continue; | |
500 } | |
501 | |
502 bcis->append(handler->handler_bci()); | |
503 if (handler->handler_bci() == -1) { | |
504 // insert a wildcard handler at scope depth 0 so that the | |
505 // exception lookup logic with find it. | |
506 scope_depths->append(0); | |
507 } else { | |
508 scope_depths->append(handler->scope_count()); | |
509 } | |
510 pcos->append(handler->entry_pco()); | |
511 | |
512 // stop processing once we hit a catch any | |
513 if (handler->is_catch_all()) { | |
514 assert(i == handlers->length() - 1, "catch all must be last handler"); | |
515 } | |
516 } | |
517 exception_handler_table()->add_subtable(info->pco(), bcis, scope_depths, pcos); | |
518 } | |
519 } | |
520 | |
521 | |
1584 | 522 Compilation::Compilation(AbstractCompiler* compiler, ciEnv* env, ciMethod* method, |
523 int osr_bci, BufferBlob* buffer_blob) | |
0 | 524 : _compiler(compiler) |
525 , _env(env) | |
6843 | 526 , _log(env->log()) |
0 | 527 , _method(method) |
528 , _osr_bci(osr_bci) | |
529 , _hir(NULL) | |
530 , _max_spills(-1) | |
531 , _frame_map(NULL) | |
532 , _masm(NULL) | |
533 , _has_exception_handlers(false) | |
534 , _has_fpu_code(true) // pessimistic assumption | |
1783 | 535 , _would_profile(false) |
0 | 536 , _has_unsafe_access(false) |
1691
4a665be40fd3
6975855: don't emit deopt MH handler in C1 if not required
twisti
parents:
1617
diff
changeset
|
537 , _has_method_handle_invokes(false) |
0 | 538 , _bailout_msg(NULL) |
539 , _exception_info_list(NULL) | |
540 , _allocator(NULL) | |
1584 | 541 , _next_id(0) |
542 , _next_block_id(0) | |
1748 | 543 , _code(buffer_blob) |
8860 | 544 , _has_access_indexed(false) |
0 | 545 , _current_instruction(NULL) |
546 #ifndef PRODUCT | |
547 , _last_instruction_printed(NULL) | |
548 #endif // PRODUCT | |
549 { | |
550 PhaseTraceTime timeit(_t_compile); | |
551 _arena = Thread::current()->resource_area(); | |
1584 | 552 _env->set_compiler_data(this); |
0 | 553 _exception_info_list = new ExceptionInfoList(); |
554 _implicit_exception_table.set_size(0); | |
555 compile_method(); | |
1964
22ef3370343b
7000349: Tiered reacts incorrectly to C1 compilation failures
iveresov
parents:
1783
diff
changeset
|
556 if (bailed_out()) { |
22ef3370343b
7000349: Tiered reacts incorrectly to C1 compilation failures
iveresov
parents:
1783
diff
changeset
|
557 _env->record_method_not_compilable(bailout_msg(), !TieredCompilation); |
22ef3370343b
7000349: Tiered reacts incorrectly to C1 compilation failures
iveresov
parents:
1783
diff
changeset
|
558 if (is_profiling()) { |
22ef3370343b
7000349: Tiered reacts incorrectly to C1 compilation failures
iveresov
parents:
1783
diff
changeset
|
559 // Compilation failed, create MDO, which would signal the interpreter |
22ef3370343b
7000349: Tiered reacts incorrectly to C1 compilation failures
iveresov
parents:
1783
diff
changeset
|
560 // to start profiling on its own. |
2007
5ddfcf4b079e
7003554: (tiered) assert(is_null_object() || handle() != NULL) failed: cannot embed null pointer
iveresov
parents:
1972
diff
changeset
|
561 _method->ensure_method_data(); |
1964
22ef3370343b
7000349: Tiered reacts incorrectly to C1 compilation failures
iveresov
parents:
1783
diff
changeset
|
562 } |
2252 | 563 } else if (is_profiling()) { |
2007
5ddfcf4b079e
7003554: (tiered) assert(is_null_object() || handle() != NULL) failed: cannot embed null pointer
iveresov
parents:
1972
diff
changeset
|
564 ciMethodData *md = method->method_data_or_null(); |
2252 | 565 if (md != NULL) { |
566 md->set_would_profile(_would_profile); | |
567 } | |
1783 | 568 } |
0 | 569 } |
570 | |
571 Compilation::~Compilation() { | |
1584 | 572 _env->set_compiler_data(NULL); |
0 | 573 } |
574 | |
575 | |
576 void Compilation::add_exception_handlers_for_pco(int pco, XHandlers* exception_handlers) { | |
577 #ifndef PRODUCT | |
578 if (PrintExceptionHandlers && Verbose) { | |
579 tty->print_cr(" added exception scope for pco %d", pco); | |
580 } | |
581 #endif | |
582 // Note: we do not have program counters for these exception handlers yet | |
583 exception_info_list()->push(new ExceptionInfo(pco, exception_handlers)); | |
584 } | |
585 | |
586 | |
587 void Compilation::notice_inlined_method(ciMethod* method) { | |
588 _env->notice_inlined_method(method); | |
589 } | |
590 | |
591 | |
592 void Compilation::bailout(const char* msg) { | |
593 assert(msg != NULL, "bailout message must exist"); | |
594 if (!bailed_out()) { | |
595 // keep first bailout message | |
6266
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
3899
diff
changeset
|
596 if (PrintCompilation || PrintBailouts) tty->print_cr("compilation bailout: %s", msg); |
0 | 597 _bailout_msg = msg; |
598 } | |
599 } | |
600 | |
601 | |
602 void Compilation::print_timers() { | |
603 // tty->print_cr(" Native methods : %6.3f s, Average : %2.3f", CompileBroker::_t_native_compilation.seconds(), CompileBroker::_t_native_compilation.seconds() / CompileBroker::_total_native_compile_count); | |
604 float total = timers[_t_setup].seconds() + timers[_t_buildIR].seconds() + timers[_t_emit_lir].seconds() + timers[_t_lir_schedule].seconds() + timers[_t_codeemit].seconds() + timers[_t_codeinstall].seconds(); | |
605 | |
606 | |
607 tty->print_cr(" Detailed C1 Timings"); | |
608 tty->print_cr(" Setup time: %6.3f s (%4.1f%%)", timers[_t_setup].seconds(), (timers[_t_setup].seconds() / total) * 100.0); | |
609 tty->print_cr(" Build IR: %6.3f s (%4.1f%%)", timers[_t_buildIR].seconds(), (timers[_t_buildIR].seconds() / total) * 100.0); | |
8860 | 610 float t_optimizeIR = timers[_t_optimize_blocks].seconds() + timers[_t_optimize_null_checks].seconds(); |
611 tty->print_cr(" Optimize: %6.3f s (%4.1f%%)", t_optimizeIR, (t_optimizeIR / total) * 100.0); | |
612 tty->print_cr(" RCE: %6.3f s (%4.1f%%)", timers[_t_rangeCheckElimination].seconds(), (timers[_t_rangeCheckElimination].seconds() / total) * 100.0); | |
0 | 613 tty->print_cr(" Emit LIR: %6.3f s (%4.1f%%)", timers[_t_emit_lir].seconds(), (timers[_t_emit_lir].seconds() / total) * 100.0); |
614 tty->print_cr(" LIR Gen: %6.3f s (%4.1f%%)", timers[_t_lirGeneration].seconds(), (timers[_t_lirGeneration].seconds() / total) * 100.0); | |
615 tty->print_cr(" Linear Scan: %6.3f s (%4.1f%%)", timers[_t_linearScan].seconds(), (timers[_t_linearScan].seconds() / total) * 100.0); | |
616 NOT_PRODUCT(LinearScan::print_timers(timers[_t_linearScan].seconds())); | |
617 tty->print_cr(" LIR Schedule: %6.3f s (%4.1f%%)", timers[_t_lir_schedule].seconds(), (timers[_t_lir_schedule].seconds() / total) * 100.0); | |
618 tty->print_cr(" Code Emission: %6.3f s (%4.1f%%)", timers[_t_codeemit].seconds(), (timers[_t_codeemit].seconds() / total) * 100.0); | |
619 tty->print_cr(" Code Installation: %6.3f s (%4.1f%%)", timers[_t_codeinstall].seconds(), (timers[_t_codeinstall].seconds() / total) * 100.0); | |
620 tty->print_cr(" Instruction Nodes: %6d nodes", totalInstructionNodes); | |
621 | |
622 NOT_PRODUCT(LinearScan::print_statistics()); | |
623 } | |
624 | |
625 | |
626 #ifndef PRODUCT | |
627 void Compilation::compile_only_this_method() { | |
628 ResourceMark rm; | |
629 fileStream stream(fopen("c1_compile_only", "wt")); | |
630 stream.print_cr("# c1 compile only directives"); | |
631 compile_only_this_scope(&stream, hir()->top_scope()); | |
632 } | |
633 | |
634 | |
635 void Compilation::compile_only_this_scope(outputStream* st, IRScope* scope) { | |
636 st->print("CompileOnly="); | |
637 scope->method()->holder()->name()->print_symbol_on(st); | |
638 st->print("."); | |
639 scope->method()->name()->print_symbol_on(st); | |
640 st->cr(); | |
641 } | |
642 | |
643 | |
644 void Compilation::exclude_this_method() { | |
645 fileStream stream(fopen(".hotspot_compiler", "at")); | |
646 stream.print("exclude "); | |
647 method()->holder()->name()->print_symbol_on(&stream); | |
648 stream.print(" "); | |
649 method()->name()->print_symbol_on(&stream); | |
650 stream.cr(); | |
651 stream.cr(); | |
652 } | |
653 #endif |