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