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