Mercurial > hg > truffle
annotate src/share/vm/c1/c1_Compilation.cpp @ 1299:9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
Summary: Passing a null pointer to an InvokeDynamic function call should lead to a NullPointerException.
Reviewed-by: kvn, never
author | twisti |
---|---|
date | Tue, 16 Mar 2010 11:52:17 +0100 |
parents | 18a389214829 |
children | 9f5b60a14736 |
rev | line source |
---|---|
0 | 1 /* |
1204 | 2 * Copyright 1999-2010 Sun Microsystems, Inc. All Rights Reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 #include "incls/_precompiled.incl" | |
26 #include "incls/_c1_Compilation.cpp.incl" | |
27 | |
28 | |
29 typedef enum { | |
30 _t_compile, | |
31 _t_setup, | |
32 _t_optimizeIR, | |
33 _t_buildIR, | |
34 _t_emit_lir, | |
35 _t_linearScan, | |
36 _t_lirGeneration, | |
37 _t_lir_schedule, | |
38 _t_codeemit, | |
39 _t_codeinstall, | |
40 max_phase_timers | |
41 } TimerName; | |
42 | |
43 static const char * timer_name[] = { | |
44 "compile", | |
45 "setup", | |
46 "optimizeIR", | |
47 "buildIR", | |
48 "emit_lir", | |
49 "linearScan", | |
50 "lirGeneration", | |
51 "lir_schedule", | |
52 "codeemit", | |
53 "codeinstall" | |
54 }; | |
55 | |
56 static elapsedTimer timers[max_phase_timers]; | |
57 static int totalInstructionNodes = 0; | |
58 | |
59 class PhaseTraceTime: public TraceTime { | |
60 private: | |
61 JavaThread* _thread; | |
62 | |
63 public: | |
64 PhaseTraceTime(TimerName timer): | |
65 TraceTime("", &timers[timer], CITime || CITimeEach, Verbose) { | |
66 } | |
67 }; | |
68 | |
69 Arena* Compilation::_arena = NULL; | |
70 Compilation* Compilation::_compilation = NULL; | |
71 | |
72 // Implementation of Compilation | |
73 | |
74 | |
75 #ifndef PRODUCT | |
76 | |
77 void Compilation::maybe_print_current_instruction() { | |
78 if (_current_instruction != NULL && _last_instruction_printed != _current_instruction) { | |
79 _last_instruction_printed = _current_instruction; | |
80 _current_instruction->print_line(); | |
81 } | |
82 } | |
83 #endif // PRODUCT | |
84 | |
85 | |
86 DebugInformationRecorder* Compilation::debug_info_recorder() const { | |
87 return _env->debug_info(); | |
88 } | |
89 | |
90 | |
91 Dependencies* Compilation::dependency_recorder() const { | |
92 return _env->dependencies(); | |
93 } | |
94 | |
95 | |
96 void Compilation::initialize() { | |
97 // Use an oop recorder bound to the CI environment. | |
98 // (The default oop recorder is ignorant of the CI.) | |
99 OopRecorder* ooprec = new OopRecorder(_env->arena()); | |
100 _env->set_oop_recorder(ooprec); | |
101 _env->set_debug_info(new DebugInformationRecorder(ooprec)); | |
102 debug_info_recorder()->set_oopmaps(new OopMapSet()); | |
103 _env->set_dependencies(new Dependencies(_env)); | |
104 } | |
105 | |
106 | |
107 void Compilation::build_hir() { | |
108 CHECK_BAILOUT(); | |
109 | |
110 // setup ir | |
111 _hir = new IR(this, method(), osr_bci()); | |
112 if (!_hir->is_valid()) { | |
113 bailout("invalid parsing"); | |
114 return; | |
115 } | |
116 | |
117 #ifndef PRODUCT | |
118 if (PrintCFGToFile) { | |
119 CFGPrinter::print_cfg(_hir, "After Generation of HIR", true, false); | |
120 } | |
121 #endif | |
122 | |
123 #ifndef PRODUCT | |
124 if (PrintCFG || PrintCFG0) { tty->print_cr("CFG after parsing"); _hir->print(true); } | |
125 if (PrintIR || PrintIR0 ) { tty->print_cr("IR after parsing"); _hir->print(false); } | |
126 #endif | |
127 | |
128 _hir->verify(); | |
129 | |
130 if (UseC1Optimizations) { | |
131 NEEDS_CLEANUP | |
132 // optimization | |
133 PhaseTraceTime timeit(_t_optimizeIR); | |
134 | |
135 _hir->optimize(); | |
136 } | |
137 | |
138 _hir->verify(); | |
139 | |
140 _hir->split_critical_edges(); | |
141 | |
142 #ifndef PRODUCT | |
143 if (PrintCFG || PrintCFG1) { tty->print_cr("CFG after optimizations"); _hir->print(true); } | |
144 if (PrintIR || PrintIR1 ) { tty->print_cr("IR after optimizations"); _hir->print(false); } | |
145 #endif | |
146 | |
147 _hir->verify(); | |
148 | |
149 // compute block ordering for code generation | |
150 // the control flow must not be changed from here on | |
151 _hir->compute_code(); | |
152 | |
153 if (UseGlobalValueNumbering) { | |
154 ResourceMark rm; | |
155 int instructions = Instruction::number_of_instructions(); | |
156 GlobalValueNumbering gvn(_hir); | |
157 assert(instructions == Instruction::number_of_instructions(), | |
158 "shouldn't have created an instructions"); | |
159 } | |
160 | |
161 // compute use counts after global value numbering | |
162 _hir->compute_use_counts(); | |
163 | |
164 #ifndef PRODUCT | |
165 if (PrintCFG || PrintCFG2) { tty->print_cr("CFG before code generation"); _hir->code()->print(true); } | |
166 if (PrintIR || PrintIR2 ) { tty->print_cr("IR before code generation"); _hir->code()->print(false, true); } | |
167 #endif | |
168 | |
169 _hir->verify(); | |
170 } | |
171 | |
172 | |
173 void Compilation::emit_lir() { | |
174 CHECK_BAILOUT(); | |
175 | |
176 LIRGenerator gen(this, method()); | |
177 { | |
178 PhaseTraceTime timeit(_t_lirGeneration); | |
179 hir()->iterate_linear_scan_order(&gen); | |
180 } | |
181 | |
182 CHECK_BAILOUT(); | |
183 | |
184 { | |
185 PhaseTraceTime timeit(_t_linearScan); | |
186 | |
187 LinearScan* allocator = new LinearScan(hir(), &gen, frame_map()); | |
188 set_allocator(allocator); | |
189 // Assign physical registers to LIR operands using a linear scan algorithm. | |
190 allocator->do_linear_scan(); | |
191 CHECK_BAILOUT(); | |
192 | |
193 _max_spills = allocator->max_spills(); | |
194 } | |
195 | |
196 if (BailoutAfterLIR) { | |
197 if (PrintLIR && !bailed_out()) { | |
198 print_LIR(hir()->code()); | |
199 } | |
200 bailout("Bailing out because of -XX:+BailoutAfterLIR"); | |
201 } | |
202 } | |
203 | |
204 | |
205 void Compilation::emit_code_epilog(LIR_Assembler* assembler) { | |
206 CHECK_BAILOUT(); | |
207 | |
1204 | 208 CodeOffsets* code_offsets = assembler->offsets(); |
209 | |
0 | 210 // generate code or slow cases |
211 assembler->emit_slow_case_stubs(); | |
212 CHECK_BAILOUT(); | |
213 | |
214 // generate exception adapters | |
215 assembler->emit_exception_entries(exception_info_list()); | |
216 CHECK_BAILOUT(); | |
217 | |
1204 | 218 // Generate code for exception handler. |
219 code_offsets->set_value(CodeOffsets::Exceptions, assembler->emit_exception_handler()); | |
0 | 220 CHECK_BAILOUT(); |
1204 | 221 |
222 // Generate code for deopt handler. | |
223 code_offsets->set_value(CodeOffsets::Deopt, assembler->emit_deopt_handler()); | |
224 CHECK_BAILOUT(); | |
225 | |
226 // Generate code for MethodHandle deopt handler. We can use the | |
227 // same code as for the normal deopt handler, we just need a | |
228 // different entry point address. | |
229 code_offsets->set_value(CodeOffsets::DeoptMH, assembler->emit_deopt_handler()); | |
0 | 230 CHECK_BAILOUT(); |
231 | |
232 // done | |
233 masm()->flush(); | |
234 } | |
235 | |
236 | |
237 int Compilation::emit_code_body() { | |
238 // emit code | |
239 Runtime1::setup_code_buffer(code(), allocator()->num_calls()); | |
240 code()->initialize_oop_recorder(env()->oop_recorder()); | |
241 | |
242 _masm = new C1_MacroAssembler(code()); | |
243 _masm->set_oop_recorder(env()->oop_recorder()); | |
244 | |
245 LIR_Assembler lir_asm(this); | |
246 | |
247 lir_asm.emit_code(hir()->code()); | |
248 CHECK_BAILOUT_(0); | |
249 | |
250 emit_code_epilog(&lir_asm); | |
251 CHECK_BAILOUT_(0); | |
252 | |
253 generate_exception_handler_table(); | |
254 | |
255 #ifndef PRODUCT | |
256 if (PrintExceptionHandlers && Verbose) { | |
257 exception_handler_table()->print(); | |
258 } | |
259 #endif /* PRODUCT */ | |
260 | |
261 return frame_map()->framesize(); | |
262 } | |
263 | |
264 | |
265 int Compilation::compile_java_method() { | |
266 assert(!method()->is_native(), "should not reach here"); | |
267 | |
268 if (BailoutOnExceptionHandlers) { | |
269 if (method()->has_exception_handlers()) { | |
270 bailout("linear scan can't handle exception handlers"); | |
271 } | |
272 } | |
273 | |
274 CHECK_BAILOUT_(no_frame_size); | |
275 | |
276 { | |
277 PhaseTraceTime timeit(_t_buildIR); | |
278 build_hir(); | |
279 } | |
280 if (BailoutAfterHIR) { | |
281 BAILOUT_("Bailing out because of -XX:+BailoutAfterHIR", no_frame_size); | |
282 } | |
283 | |
284 | |
285 { | |
286 PhaseTraceTime timeit(_t_emit_lir); | |
287 | |
288 _frame_map = new FrameMap(method(), hir()->number_of_locks(), MAX2(4, hir()->max_stack())); | |
289 emit_lir(); | |
290 } | |
291 CHECK_BAILOUT_(no_frame_size); | |
292 | |
293 { | |
294 PhaseTraceTime timeit(_t_codeemit); | |
295 return emit_code_body(); | |
296 } | |
297 } | |
298 | |
299 void Compilation::install_code(int frame_size) { | |
300 // frame_size is in 32-bit words so adjust it intptr_t words | |
301 assert(frame_size == frame_map()->framesize(), "must match"); | |
302 assert(in_bytes(frame_map()->framesize_in_bytes()) % sizeof(intptr_t) == 0, "must be at least pointer aligned"); | |
303 _env->register_method( | |
304 method(), | |
305 osr_bci(), | |
306 &_offsets, | |
307 in_bytes(_frame_map->sp_offset_for_orig_pc()), | |
308 code(), | |
309 in_bytes(frame_map()->framesize_in_bytes()) / sizeof(intptr_t), | |
310 debug_info_recorder()->_oopmaps, | |
311 exception_handler_table(), | |
312 implicit_exception_table(), | |
313 compiler(), | |
314 _env->comp_level(), | |
315 needs_debug_information(), | |
316 has_unsafe_access() | |
317 ); | |
318 } | |
319 | |
320 | |
321 void Compilation::compile_method() { | |
322 // setup compilation | |
323 initialize(); | |
324 | |
325 if (!method()->can_be_compiled()) { | |
326 // Prevent race condition 6328518. | |
327 // This can happen if the method is obsolete or breakpointed. | |
328 bailout("Bailing out because method is not compilable"); | |
329 return; | |
330 } | |
331 | |
780
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
0
diff
changeset
|
332 if (_env->jvmti_can_hotswap_or_post_breakpoint()) { |
0 | 333 // We can assert evol_method because method->can_be_compiled is true. |
334 dependency_recorder()->assert_evol_method(method()); | |
335 } | |
336 | |
337 if (method()->break_at_execute()) { | |
338 BREAKPOINT; | |
339 } | |
340 | |
341 #ifndef PRODUCT | |
342 if (PrintCFGToFile) { | |
343 CFGPrinter::print_compilation(this); | |
344 } | |
345 #endif | |
346 | |
347 // compile method | |
348 int frame_size = compile_java_method(); | |
349 | |
350 // bailout if method couldn't be compiled | |
351 // Note: make sure we mark the method as not compilable! | |
352 CHECK_BAILOUT(); | |
353 | |
354 if (InstallMethods) { | |
355 // install code | |
356 PhaseTraceTime timeit(_t_codeinstall); | |
357 install_code(frame_size); | |
358 } | |
359 totalInstructionNodes += Instruction::number_of_instructions(); | |
360 } | |
361 | |
362 | |
363 void Compilation::generate_exception_handler_table() { | |
364 // Generate an ExceptionHandlerTable from the exception handler | |
365 // information accumulated during the compilation. | |
366 ExceptionInfoList* info_list = exception_info_list(); | |
367 | |
368 if (info_list->length() == 0) { | |
369 return; | |
370 } | |
371 | |
372 // allocate some arrays for use by the collection code. | |
373 const int num_handlers = 5; | |
374 GrowableArray<intptr_t>* bcis = new GrowableArray<intptr_t>(num_handlers); | |
375 GrowableArray<intptr_t>* scope_depths = new GrowableArray<intptr_t>(num_handlers); | |
376 GrowableArray<intptr_t>* pcos = new GrowableArray<intptr_t>(num_handlers); | |
377 | |
378 for (int i = 0; i < info_list->length(); i++) { | |
379 ExceptionInfo* info = info_list->at(i); | |
380 XHandlers* handlers = info->exception_handlers(); | |
381 | |
382 // empty the arrays | |
383 bcis->trunc_to(0); | |
384 scope_depths->trunc_to(0); | |
385 pcos->trunc_to(0); | |
386 | |
387 for (int i = 0; i < handlers->length(); i++) { | |
388 XHandler* handler = handlers->handler_at(i); | |
389 assert(handler->entry_pco() != -1, "must have been generated"); | |
390 | |
391 int e = bcis->find(handler->handler_bci()); | |
392 if (e >= 0 && scope_depths->at(e) == handler->scope_count()) { | |
393 // two different handlers are declared to dispatch to the same | |
394 // catch bci. During parsing we created edges for each | |
395 // handler but we really only need one. The exception handler | |
396 // table will also get unhappy if we try to declare both since | |
397 // it's nonsensical. Just skip this handler. | |
398 continue; | |
399 } | |
400 | |
401 bcis->append(handler->handler_bci()); | |
402 if (handler->handler_bci() == -1) { | |
403 // insert a wildcard handler at scope depth 0 so that the | |
404 // exception lookup logic with find it. | |
405 scope_depths->append(0); | |
406 } else { | |
407 scope_depths->append(handler->scope_count()); | |
408 } | |
409 pcos->append(handler->entry_pco()); | |
410 | |
411 // stop processing once we hit a catch any | |
412 if (handler->is_catch_all()) { | |
413 assert(i == handlers->length() - 1, "catch all must be last handler"); | |
414 } | |
415 } | |
416 exception_handler_table()->add_subtable(info->pco(), bcis, scope_depths, pcos); | |
417 } | |
418 } | |
419 | |
420 | |
421 Compilation::Compilation(AbstractCompiler* compiler, ciEnv* env, ciMethod* method, int osr_bci) | |
422 : _compiler(compiler) | |
423 , _env(env) | |
424 , _method(method) | |
425 , _osr_bci(osr_bci) | |
426 , _hir(NULL) | |
427 , _max_spills(-1) | |
428 , _frame_map(NULL) | |
429 , _masm(NULL) | |
430 , _has_exception_handlers(false) | |
431 , _has_fpu_code(true) // pessimistic assumption | |
432 , _has_unsafe_access(false) | |
433 , _bailout_msg(NULL) | |
434 , _exception_info_list(NULL) | |
435 , _allocator(NULL) | |
436 , _code(Runtime1::get_buffer_blob()->instructions_begin(), | |
437 Runtime1::get_buffer_blob()->instructions_size()) | |
438 , _current_instruction(NULL) | |
439 #ifndef PRODUCT | |
440 , _last_instruction_printed(NULL) | |
441 #endif // PRODUCT | |
442 { | |
443 PhaseTraceTime timeit(_t_compile); | |
444 | |
445 assert(_arena == NULL, "shouldn't only one instance of Compilation in existence at a time"); | |
446 _arena = Thread::current()->resource_area(); | |
447 _compilation = this; | |
780
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
0
diff
changeset
|
448 _needs_debug_information = _env->jvmti_can_examine_or_deopt_anywhere() || |
0 | 449 JavaMonitorsInStackTrace || AlwaysEmitDebugInfo || DeoptimizeALot; |
450 _exception_info_list = new ExceptionInfoList(); | |
451 _implicit_exception_table.set_size(0); | |
452 compile_method(); | |
453 } | |
454 | |
455 Compilation::~Compilation() { | |
456 _arena = NULL; | |
457 _compilation = NULL; | |
458 } | |
459 | |
460 | |
461 void Compilation::add_exception_handlers_for_pco(int pco, XHandlers* exception_handlers) { | |
462 #ifndef PRODUCT | |
463 if (PrintExceptionHandlers && Verbose) { | |
464 tty->print_cr(" added exception scope for pco %d", pco); | |
465 } | |
466 #endif | |
467 // Note: we do not have program counters for these exception handlers yet | |
468 exception_info_list()->push(new ExceptionInfo(pco, exception_handlers)); | |
469 } | |
470 | |
471 | |
472 void Compilation::notice_inlined_method(ciMethod* method) { | |
473 _env->notice_inlined_method(method); | |
474 } | |
475 | |
476 | |
477 void Compilation::bailout(const char* msg) { | |
478 assert(msg != NULL, "bailout message must exist"); | |
479 if (!bailed_out()) { | |
480 // keep first bailout message | |
481 if (PrintBailouts) tty->print_cr("compilation bailout: %s", msg); | |
482 _bailout_msg = msg; | |
483 } | |
484 } | |
485 | |
486 | |
487 void Compilation::print_timers() { | |
488 // tty->print_cr(" Native methods : %6.3f s, Average : %2.3f", CompileBroker::_t_native_compilation.seconds(), CompileBroker::_t_native_compilation.seconds() / CompileBroker::_total_native_compile_count); | |
489 float total = timers[_t_setup].seconds() + timers[_t_buildIR].seconds() + timers[_t_emit_lir].seconds() + timers[_t_lir_schedule].seconds() + timers[_t_codeemit].seconds() + timers[_t_codeinstall].seconds(); | |
490 | |
491 | |
492 tty->print_cr(" Detailed C1 Timings"); | |
493 tty->print_cr(" Setup time: %6.3f s (%4.1f%%)", timers[_t_setup].seconds(), (timers[_t_setup].seconds() / total) * 100.0); | |
494 tty->print_cr(" Build IR: %6.3f s (%4.1f%%)", timers[_t_buildIR].seconds(), (timers[_t_buildIR].seconds() / total) * 100.0); | |
495 tty->print_cr(" Optimize: %6.3f s (%4.1f%%)", timers[_t_optimizeIR].seconds(), (timers[_t_optimizeIR].seconds() / total) * 100.0); | |
496 tty->print_cr(" Emit LIR: %6.3f s (%4.1f%%)", timers[_t_emit_lir].seconds(), (timers[_t_emit_lir].seconds() / total) * 100.0); | |
497 tty->print_cr(" LIR Gen: %6.3f s (%4.1f%%)", timers[_t_lirGeneration].seconds(), (timers[_t_lirGeneration].seconds() / total) * 100.0); | |
498 tty->print_cr(" Linear Scan: %6.3f s (%4.1f%%)", timers[_t_linearScan].seconds(), (timers[_t_linearScan].seconds() / total) * 100.0); | |
499 NOT_PRODUCT(LinearScan::print_timers(timers[_t_linearScan].seconds())); | |
500 tty->print_cr(" LIR Schedule: %6.3f s (%4.1f%%)", timers[_t_lir_schedule].seconds(), (timers[_t_lir_schedule].seconds() / total) * 100.0); | |
501 tty->print_cr(" Code Emission: %6.3f s (%4.1f%%)", timers[_t_codeemit].seconds(), (timers[_t_codeemit].seconds() / total) * 100.0); | |
502 tty->print_cr(" Code Installation: %6.3f s (%4.1f%%)", timers[_t_codeinstall].seconds(), (timers[_t_codeinstall].seconds() / total) * 100.0); | |
503 tty->print_cr(" Instruction Nodes: %6d nodes", totalInstructionNodes); | |
504 | |
505 NOT_PRODUCT(LinearScan::print_statistics()); | |
506 } | |
507 | |
508 | |
509 #ifndef PRODUCT | |
510 void Compilation::compile_only_this_method() { | |
511 ResourceMark rm; | |
512 fileStream stream(fopen("c1_compile_only", "wt")); | |
513 stream.print_cr("# c1 compile only directives"); | |
514 compile_only_this_scope(&stream, hir()->top_scope()); | |
515 } | |
516 | |
517 | |
518 void Compilation::compile_only_this_scope(outputStream* st, IRScope* scope) { | |
519 st->print("CompileOnly="); | |
520 scope->method()->holder()->name()->print_symbol_on(st); | |
521 st->print("."); | |
522 scope->method()->name()->print_symbol_on(st); | |
523 st->cr(); | |
524 } | |
525 | |
526 | |
527 void Compilation::exclude_this_method() { | |
528 fileStream stream(fopen(".hotspot_compiler", "at")); | |
529 stream.print("exclude "); | |
530 method()->holder()->name()->print_symbol_on(&stream); | |
531 stream.print(" "); | |
532 method()->name()->print_symbol_on(&stream); | |
533 stream.cr(); | |
534 stream.cr(); | |
535 } | |
536 #endif |