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