1 /*
  2  * Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
  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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "precompiled.hpp"
 26 #include "c1/c1_CFGPrinter.hpp"
 27 #include "c1/c1_Compilation.hpp"
 28 #include "c1/c1_IR.hpp"
 29 #include "c1/c1_LIRAssembler.hpp"
 30 #include "c1/c1_LinearScan.hpp"
 31 #include "c1/c1_MacroAssembler.hpp"
 32 #include "c1/c1_RangeCheckElimination.hpp"
 33 #include "c1/c1_ValueMap.hpp"
 34 #include "c1/c1_ValueStack.hpp"
 35 #include "code/debugInfoRec.hpp"
 36 #include "compiler/compilationMemoryStatistic.hpp"
 37 #include "compiler/compilerDirectives.hpp"
 38 #include "compiler/compileLog.hpp"
 39 #include "compiler/compileTask.hpp"
 40 #include "compiler/compilerDirectives.hpp"
 41 #include "memory/resourceArea.hpp"
 42 #include "runtime/sharedRuntime.hpp"
 43 #include "runtime/timerTrace.hpp"
 44 
 45 typedef enum {
 46   _t_compile,
 47     _t_setup,
 48     _t_buildIR,
 49       _t_hir_parse,
 50       _t_gvn,
 51       _t_optimize_blocks,
 52       _t_optimize_null_checks,
 53       _t_rangeCheckElimination,
 54     _t_emit_lir,
 55       _t_linearScan,
 56       _t_lirGeneration,
 57     _t_codeemit,
 58     _t_codeinstall,
 59   max_phase_timers
 60 } TimerId;
 61 
 62 static const char * timer_name[] = {
 63   "compile",
 64   "setup",
 65   "buildIR",
 66   "parse_hir",
 67   "gvn",
 68   "optimize_blocks",
 69   "optimize_null_checks",
 70   "rangeCheckElimination",
 71   "emit_lir",
 72   "linearScan",
 73   "lirGeneration",
 74   "codeemit",
 75   "codeinstall"
 76 };
 77 
 78 static elapsedTimer timers[max_phase_timers];
 79 static uint totalInstructionNodes = 0;
 80 
 81 class PhaseTraceTime: public TraceTime {
 82  private:
 83   CompileLog* _log;
 84   TimerId _timer_id;
 85   bool _dolog;
 86 
 87  public:
 88   PhaseTraceTime(TimerId timer_id)
 89   : TraceTime(timer_name[timer_id], &timers[timer_id], CITime, CITimeVerbose),
 90     _log(nullptr), _timer_id(timer_id), _dolog(CITimeVerbose)
 91   {
 92     if (_dolog) {
 93       assert(Compilation::current() != nullptr, "sanity check");
 94       _log = Compilation::current()->log();
 95     }
 96 
 97     if (_log != nullptr) {
 98       _log->begin_head("phase name='%s'", timer_name[_timer_id]);
 99       _log->stamp();
100       _log->end_head();
101     }
102   }
103 
104   ~PhaseTraceTime() {
105     if (_log != nullptr)
106       _log->done("phase name='%s'", timer_name[_timer_id]);
107   }
108 };
109 
110 // Implementation of Compilation
111 
112 
113 #ifndef PRODUCT
114 
115 void Compilation::maybe_print_current_instruction() {
116   if (_current_instruction != nullptr && _last_instruction_printed != _current_instruction) {
117     _last_instruction_printed = _current_instruction;
118     _current_instruction->print_line();
119   }
120 }
121 #endif // PRODUCT
122 
123 
124 DebugInformationRecorder* Compilation::debug_info_recorder() const {
125   return _env->debug_info();
126 }
127 
128 
129 Dependencies* Compilation::dependency_recorder() const {
130   return _env->dependencies();
131 }
132 
133 
134 void Compilation::initialize() {
135   // Use an oop recorder bound to the CI environment.
136   // (The default oop recorder is ignorant of the CI.)
137   OopRecorder* ooprec = new OopRecorder(_env->arena());
138   _env->set_oop_recorder(ooprec);
139   _env->set_debug_info(new DebugInformationRecorder(ooprec));
140   debug_info_recorder()->set_oopmaps(new OopMapSet());
141   _env->set_dependencies(new Dependencies(_env));
142 }
143 
144 
145 void Compilation::build_hir() {
146   CHECK_BAILOUT();
147 
148   // setup ir
149   CompileLog* log = this->log();
150   if (log != nullptr) {
151     log->begin_head("parse method='%d' ",
152                     log->identify(_method));
153     log->stamp();
154     log->end_head();
155   }
156   {
157     PhaseTraceTime timeit(_t_hir_parse);
158     _hir = new IR(this, method(), osr_bci());
159   }
160   if (log)  log->done("parse");
161   if (!_hir->is_valid()) {
162     bailout("invalid parsing");
163     return;
164   }
165 
166 #ifndef PRODUCT
167   if (PrintCFGToFile) {
168     CFGPrinter::print_cfg(_hir, "After Generation of HIR", true, false);
169   }
170 #endif
171 
172 #ifndef PRODUCT
173   if (PrintCFG || PrintCFG0) { tty->print_cr("CFG after parsing"); _hir->print(true); }
174   if (PrintIR  || PrintIR0 ) { tty->print_cr("IR after parsing"); _hir->print(false); }
175 #endif
176 
177   _hir->verify();
178 
179   if (UseC1Optimizations) {
180     NEEDS_CLEANUP
181     // optimization
182     PhaseTraceTime timeit(_t_optimize_blocks);
183 
184     _hir->optimize_blocks();
185   }
186 
187   _hir->verify();
188 
189   _hir->split_critical_edges();
190 
191 #ifndef PRODUCT
192   if (PrintCFG || PrintCFG1) { tty->print_cr("CFG after optimizations"); _hir->print(true); }
193   if (PrintIR  || PrintIR1 ) { tty->print_cr("IR after optimizations"); _hir->print(false); }
194 #endif
195 
196   _hir->verify();
197 
198   // compute block ordering for code generation
199   // the control flow must not be changed from here on
200   _hir->compute_code();
201 
202   if (UseGlobalValueNumbering) {
203     // No resource mark here! LoopInvariantCodeMotion can allocate ValueStack objects.
204     PhaseTraceTime timeit(_t_gvn);
205     int instructions = Instruction::number_of_instructions();
206     GlobalValueNumbering gvn(_hir);
207     assert(instructions == Instruction::number_of_instructions(),
208            "shouldn't have created an instructions");
209   }
210 
211   _hir->verify();
212 
213 #ifndef PRODUCT
214   if (PrintCFGToFile) {
215     CFGPrinter::print_cfg(_hir, "Before RangeCheckElimination", true, false);
216   }
217 #endif
218 
219   if (RangeCheckElimination) {
220     if (_hir->osr_entry() == nullptr) {
221       PhaseTraceTime timeit(_t_rangeCheckElimination);
222       RangeCheckElimination::eliminate(_hir);
223     }
224   }
225 
226 #ifndef PRODUCT
227   if (PrintCFGToFile) {
228     CFGPrinter::print_cfg(_hir, "After RangeCheckElimination", true, false);
229   }
230 #endif
231 
232   if (UseC1Optimizations) {
233     // loop invariant code motion reorders instructions and range
234     // check elimination adds new instructions so do null check
235     // elimination after.
236     NEEDS_CLEANUP
237     // optimization
238     PhaseTraceTime timeit(_t_optimize_null_checks);
239 
240     _hir->eliminate_null_checks();
241   }
242 
243   _hir->verify();
244 
245   // compute use counts after global value numbering
246   _hir->compute_use_counts();
247 
248 #ifndef PRODUCT
249   if (PrintCFG || PrintCFG2) { tty->print_cr("CFG before code generation"); _hir->code()->print(true); }
250   if (PrintIR  || PrintIR2 ) { tty->print_cr("IR before code generation"); _hir->code()->print(false, true); }
251 #endif
252 
253   _hir->verify();
254 }
255 
256 
257 void Compilation::emit_lir() {
258   CHECK_BAILOUT();
259 
260   LIRGenerator gen(this, method());
261   {
262     PhaseTraceTime timeit(_t_lirGeneration);
263     hir()->iterate_linear_scan_order(&gen);
264   }
265 
266   CHECK_BAILOUT();
267 
268   {
269     PhaseTraceTime timeit(_t_linearScan);
270 
271     LinearScan* allocator = new LinearScan(hir(), &gen, frame_map());
272     set_allocator(allocator);
273     // Assign physical registers to LIR operands using a linear scan algorithm.
274     allocator->do_linear_scan();
275     CHECK_BAILOUT();
276 
277     _max_spills = allocator->max_spills();
278   }
279 
280   if (BailoutAfterLIR) {
281     if (PrintLIR && !bailed_out()) {
282       print_LIR(hir()->code());
283     }
284     bailout("Bailing out because of -XX:+BailoutAfterLIR");
285   }
286 }
287 
288 
289 void Compilation::emit_code_epilog(LIR_Assembler* assembler) {
290   CHECK_BAILOUT();
291 
292   CodeOffsets* code_offsets = assembler->offsets();
293 
294   if (!code()->finalize_stubs()) {
295     bailout("CodeCache is full");
296     return;
297   }
298 
299   // generate code or slow cases
300   assembler->emit_slow_case_stubs();
301   CHECK_BAILOUT();
302 
303   // generate exception adapters
304   assembler->emit_exception_entries(exception_info_list());
305   CHECK_BAILOUT();
306 
307   // Generate code for exception handler.
308   code_offsets->set_value(CodeOffsets::Exceptions, assembler->emit_exception_handler());
309   CHECK_BAILOUT();
310 
311   // Generate code for deopt handler.
312   code_offsets->set_value(CodeOffsets::Deopt, assembler->emit_deopt_handler());
313   CHECK_BAILOUT();
314 
315   // Emit the MethodHandle deopt handler code (if required).
316   if (has_method_handle_invokes()) {
317     // We can use the same code as for the normal deopt handler, we
318     // just need a different entry point address.
319     code_offsets->set_value(CodeOffsets::DeoptMH, assembler->emit_deopt_handler());
320     CHECK_BAILOUT();
321   }
322 
323   // Emit the handler to remove the activation from the stack and
324   // dispatch to the caller.
325   offsets()->set_value(CodeOffsets::UnwindHandler, assembler->emit_unwind_handler());
326 }
327 
328 
329 bool Compilation::setup_code_buffer(CodeBuffer* code, int call_stub_estimate) {
330   // Preinitialize the consts section to some large size:
331   int locs_buffer_size = 20 * (relocInfo::length_limit + sizeof(relocInfo));
332   char* locs_buffer = NEW_RESOURCE_ARRAY(char, locs_buffer_size);
333   code->insts()->initialize_shared_locs((relocInfo*)locs_buffer,
334                                         locs_buffer_size / sizeof(relocInfo));
335   code->initialize_consts_size(Compilation::desired_max_constant_size());
336   // Call stubs + two deopt handlers (regular and MH) + exception handler
337   int stub_size = (call_stub_estimate * LIR_Assembler::call_stub_size()) +
338                    LIR_Assembler::exception_handler_size() +
339                    (2 * LIR_Assembler::deopt_handler_size());
340   if (stub_size >= code->insts_capacity()) return false;
341   code->initialize_stubs_size(stub_size);
342   return true;
343 }
344 
345 
346 int Compilation::emit_code_body() {
347   // emit code
348   if (!setup_code_buffer(code(), allocator()->num_calls())) {
349     BAILOUT_("size requested greater than avail code buffer size", 0);
350   }
351   code()->initialize_oop_recorder(env()->oop_recorder());
352 
353   _masm = new C1_MacroAssembler(code());
354   _masm->set_oop_recorder(env()->oop_recorder());
355 
356   LIR_Assembler lir_asm(this);
357 
358   lir_asm.emit_code(hir()->code());
359   CHECK_BAILOUT_(0);
360 
361   emit_code_epilog(&lir_asm);
362   CHECK_BAILOUT_(0);
363 
364   generate_exception_handler_table();
365 
366 #ifndef PRODUCT
367   if (PrintExceptionHandlers && Verbose) {
368     exception_handler_table()->print();
369   }
370 #endif /* PRODUCT */
371 
372   _immediate_oops_patched = lir_asm.nr_immediate_oops_patched();
373   return frame_map()->framesize();
374 }
375 
376 
377 int Compilation::compile_java_method() {
378   assert(!method()->is_native(), "should not reach here");
379 
380   if (BailoutOnExceptionHandlers) {
381     if (method()->has_exception_handlers()) {
382       bailout("linear scan can't handle exception handlers");
383     }
384   }
385 
386   CHECK_BAILOUT_(no_frame_size);
387 
388   if (is_profiling() && !method()->ensure_method_data()) {
389     BAILOUT_("mdo allocation failed", no_frame_size);
390   }
391 
392   if (method()->is_synchronized()) {
393     set_has_monitors(true);
394   }
395 
396   {
397     PhaseTraceTime timeit(_t_buildIR);
398     build_hir();
399   }
400   CHECK_BAILOUT_(no_frame_size);
401   if (BailoutAfterHIR) {
402     BAILOUT_("Bailing out because of -XX:+BailoutAfterHIR", no_frame_size);
403   }
404 
405 
406   {
407     PhaseTraceTime timeit(_t_emit_lir);
408 
409     _frame_map = new FrameMap(method(), hir()->number_of_locks(), hir()->max_stack());
410     emit_lir();
411   }
412   CHECK_BAILOUT_(no_frame_size);
413 
414   // Dump compilation data to replay it.
415   if (_directive->DumpReplayOption) {
416     env()->dump_replay_data(env()->compile_id());
417   }
418 
419   {
420     PhaseTraceTime timeit(_t_codeemit);
421     return emit_code_body();
422   }
423 }
424 
425 void Compilation::install_code(int frame_size) {
426   // frame_size is in 32-bit words so adjust it intptr_t words
427   assert(frame_size == frame_map()->framesize(), "must match");
428   assert(in_bytes(frame_map()->framesize_in_bytes()) % sizeof(intptr_t) == 0, "must be at least pointer aligned");
429   _env->register_method(
430     method(),
431     osr_bci(),
432     &_offsets,
433     in_bytes(_frame_map->sp_offset_for_orig_pc()),
434     code(),
435     in_bytes(frame_map()->framesize_in_bytes()) / sizeof(intptr_t),
436     debug_info_recorder()->_oopmaps,
437     exception_handler_table(),
438     implicit_exception_table(),
439     compiler(),
440     has_unsafe_access(),
441     SharedRuntime::is_wide_vector(max_vector_size()),
442     has_monitors(),
443     _immediate_oops_patched
444   );
445 }
446 
447 
448 void Compilation::compile_method() {
449 
450   {
451     PhaseTraceTime timeit(_t_setup);
452 
453     // setup compilation
454     initialize();
455     CHECK_BAILOUT();
456 
457   }
458 
459   if (!method()->can_be_compiled()) {
460     // Prevent race condition 6328518.
461     // This can happen if the method is obsolete or breakpointed.
462     bailout("Bailing out because method is not compilable");
463     return;
464   }
465 
466   if (_env->jvmti_can_hotswap_or_post_breakpoint()) {
467     // We can assert evol_method because method->can_be_compiled is true.
468     dependency_recorder()->assert_evol_method(method());
469   }
470 
471   if (env()->break_at_compile()) {
472     BREAKPOINT;
473   }
474 
475 #ifndef PRODUCT
476   if (PrintCFGToFile) {
477     CFGPrinter::print_compilation(this);
478   }
479 #endif
480 
481   // compile method
482   int frame_size = compile_java_method();
483 
484   // bailout if method couldn't be compiled
485   // Note: make sure we mark the method as not compilable!
486   CHECK_BAILOUT();
487 
488   if (should_install_code()) {
489     // install code
490     PhaseTraceTime timeit(_t_codeinstall);
491     install_code(frame_size);
492   }
493 
494   if (log() != nullptr) // Print code cache state into compiler log
495     log()->code_cache_state();
496 
497   totalInstructionNodes += Instruction::number_of_instructions();
498 }
499 
500 
501 void Compilation::generate_exception_handler_table() {
502   // Generate an ExceptionHandlerTable from the exception handler
503   // information accumulated during the compilation.
504   ExceptionInfoList* info_list = exception_info_list();
505 
506   if (info_list->length() == 0) {
507     return;
508   }
509 
510   // allocate some arrays for use by the collection code.
511   const int num_handlers = 5;
512   GrowableArray<intptr_t>* bcis = new GrowableArray<intptr_t>(num_handlers);
513   GrowableArray<intptr_t>* scope_depths = new GrowableArray<intptr_t>(num_handlers);
514   GrowableArray<intptr_t>* pcos = new GrowableArray<intptr_t>(num_handlers);
515 
516   for (int i = 0; i < info_list->length(); i++) {
517     ExceptionInfo* info = info_list->at(i);
518     XHandlers* handlers = info->exception_handlers();
519 
520     // empty the arrays
521     bcis->trunc_to(0);
522     scope_depths->trunc_to(0);
523     pcos->trunc_to(0);
524 
525     int prev_scope = 0;
526     for (int i = 0; i < handlers->length(); i++) {
527       XHandler* handler = handlers->handler_at(i);
528       assert(handler->entry_pco() != -1, "must have been generated");
529       assert(handler->scope_count() >= prev_scope, "handlers should be sorted by scope");
530 
531       if (handler->scope_count() == prev_scope) {
532         int e = bcis->find_from_end(handler->handler_bci());
533         if (e >= 0 && scope_depths->at(e) == handler->scope_count()) {
534           // two different handlers are declared to dispatch to the same
535           // catch bci.  During parsing we created edges for each
536           // handler but we really only need one.  The exception handler
537           // table will also get unhappy if we try to declare both since
538           // it's nonsensical.  Just skip this handler.
539           continue;
540         }
541       }
542 
543       bcis->append(handler->handler_bci());
544       if (handler->handler_bci() == -1) {
545         // insert a wildcard handler at scope depth 0 so that the
546         // exception lookup logic with find it.
547         scope_depths->append(0);
548       } else {
549         scope_depths->append(handler->scope_count());
550       }
551       pcos->append(handler->entry_pco());
552 
553       // stop processing once we hit a catch any
554       if (handler->is_catch_all()) {
555         assert(i == handlers->length() - 1, "catch all must be last handler");
556       }
557       prev_scope = handler->scope_count();
558     }
559     exception_handler_table()->add_subtable(info->pco(), bcis, scope_depths, pcos);
560   }
561 }
562 
563 Compilation::Compilation(AbstractCompiler* compiler, ciEnv* env, ciMethod* method,
564                          int osr_bci, BufferBlob* buffer_blob, bool install_code, DirectiveSet* directive)
565 : _next_id(0)
566 , _next_block_id(0)
567 , _compiler(compiler)
568 , _directive(directive)
569 , _env(env)
570 , _log(env->log())
571 , _method(method)
572 , _osr_bci(osr_bci)
573 , _hir(nullptr)
574 , _max_spills(-1)
575 , _frame_map(nullptr)
576 , _masm(nullptr)
577 , _has_exception_handlers(false)
578 , _has_fpu_code(true)   // pessimistic assumption
579 , _has_unsafe_access(false)
580 , _has_irreducible_loops(false)
581 , _would_profile(false)
582 , _has_method_handle_invokes(false)
583 , _has_reserved_stack_access(method->has_reserved_stack_access())
584 , _has_monitors(false)
585 , _install_code(install_code)
586 , _bailout_msg(nullptr)
587 , _exception_info_list(nullptr)
588 , _allocator(nullptr)
589 , _code(buffer_blob)
590 , _has_access_indexed(false)
591 , _interpreter_frame_size(0)
592 , _compiled_entry_signature(method->get_Method())
593 , _immediate_oops_patched(0)
594 , _current_instruction(nullptr)
595 #ifndef PRODUCT
596 , _last_instruction_printed(nullptr)
597 , _cfg_printer_output(nullptr)
598 #endif // PRODUCT
599 {
600   _arena = Thread::current()->resource_area();
601   _env->set_compiler_data(this);
602   _exception_info_list = new ExceptionInfoList();
603   _implicit_exception_table.set_size(0);
604   PhaseTraceTime timeit(_t_compile);
605 #ifndef PRODUCT
606   if (PrintCFGToFile) {
607     _cfg_printer_output = new CFGPrinterOutput(this);
608   }
609 #endif
610   CompilationMemoryStatisticMark cmsm(directive);
611 
612   {
613     ResetNoHandleMark rnhm; // Huh? Required when doing class lookup of the Q-types
614     // TODO 8284443 Should only be computed once
615     _compiled_entry_signature.compute_calling_conventions(false);
616   }
617 
618   compile_method();
619   if (bailed_out()) {
620     _env->record_method_not_compilable(bailout_msg());
621     if (is_profiling()) {
622       // Compilation failed, create MDO, which would signal the interpreter
623       // to start profiling on its own.
624       _method->ensure_method_data();
625     }
626   } else if (is_profiling()) {
627     ciMethodData *md = method->method_data_or_null();
628     if (md != nullptr) {
629       md->set_would_profile(_would_profile);
630     }
631   }
632 }
633 
634 Compilation::~Compilation() {
635   // simulate crash during compilation
636   assert(CICrashAt < 0 || (uintx)_env->compile_id() != (uintx)CICrashAt, "just as planned");
637 
638   _env->set_compiler_data(nullptr);
639 }
640 
641 void Compilation::add_exception_handlers_for_pco(int pco, XHandlers* exception_handlers) {
642 #ifndef PRODUCT
643   if (PrintExceptionHandlers && Verbose) {
644     tty->print_cr("  added exception scope for pco %d", pco);
645   }
646 #endif
647   // Note: we do not have program counters for these exception handlers yet
648   exception_info_list()->push(new ExceptionInfo(pco, exception_handlers));
649 }
650 
651 
652 void Compilation::notice_inlined_method(ciMethod* method) {
653   _env->notice_inlined_method(method);
654 }
655 
656 
657 void Compilation::bailout(const char* msg) {
658   assert(msg != nullptr, "bailout message must exist");
659   if (!bailed_out()) {
660     // keep first bailout message
661     if (PrintCompilation || PrintBailouts) tty->print_cr("compilation bailout: %s", msg);
662     _bailout_msg = msg;
663   }
664 }
665 
666 ciKlass* Compilation::cha_exact_type(ciType* type) {
667   if (type != nullptr && type->is_loaded() && type->is_instance_klass()) {
668     ciInstanceKlass* ik = type->as_instance_klass();
669     assert(ik->exact_klass() == nullptr, "no cha for final klass");
670     if (DeoptC1 && UseCHA && !(ik->has_subklass() || ik->is_interface())) {
671       dependency_recorder()->assert_leaf_type(ik);
672       return ik;
673     }
674   }
675   return nullptr;
676 }
677 
678 void Compilation::print_timers() {
679   tty->print_cr("    C1 Compile Time:      %7.3f s",      timers[_t_compile].seconds());
680   tty->print_cr("       Setup time:          %7.3f s",    timers[_t_setup].seconds());
681 
682   {
683     tty->print_cr("       Build HIR:           %7.3f s",    timers[_t_buildIR].seconds());
684     tty->print_cr("         Parse:               %7.3f s", timers[_t_hir_parse].seconds());
685     tty->print_cr("         Optimize blocks:     %7.3f s", timers[_t_optimize_blocks].seconds());
686     tty->print_cr("         GVN:                 %7.3f s", timers[_t_gvn].seconds());
687     tty->print_cr("         Null checks elim:    %7.3f s", timers[_t_optimize_null_checks].seconds());
688     tty->print_cr("         Range checks elim:   %7.3f s", timers[_t_rangeCheckElimination].seconds());
689 
690     double other = timers[_t_buildIR].seconds() -
691       (timers[_t_hir_parse].seconds() +
692        timers[_t_optimize_blocks].seconds() +
693        timers[_t_gvn].seconds() +
694        timers[_t_optimize_null_checks].seconds() +
695        timers[_t_rangeCheckElimination].seconds());
696     if (other > 0) {
697       tty->print_cr("         Other:               %7.3f s", other);
698     }
699   }
700 
701   {
702     tty->print_cr("       Emit LIR:            %7.3f s",    timers[_t_emit_lir].seconds());
703     tty->print_cr("         LIR Gen:             %7.3f s",   timers[_t_lirGeneration].seconds());
704     tty->print_cr("         Linear Scan:         %7.3f s",   timers[_t_linearScan].seconds());
705     NOT_PRODUCT(LinearScan::print_timers(timers[_t_linearScan].seconds()));
706 
707     double other = timers[_t_emit_lir].seconds() -
708       (timers[_t_lirGeneration].seconds() +
709        timers[_t_linearScan].seconds());
710     if (other > 0) {
711       tty->print_cr("         Other:               %7.3f s", other);
712     }
713   }
714 
715   tty->print_cr("       Code Emission:       %7.3f s",    timers[_t_codeemit].seconds());
716   tty->print_cr("       Code Installation:   %7.3f s",    timers[_t_codeinstall].seconds());
717 
718   double other = timers[_t_compile].seconds() -
719       (timers[_t_setup].seconds() +
720        timers[_t_buildIR].seconds() +
721        timers[_t_emit_lir].seconds() +
722        timers[_t_codeemit].seconds() +
723        timers[_t_codeinstall].seconds());
724   if (other > 0) {
725     tty->print_cr("       Other:               %7.3f s", other);
726   }
727 
728   NOT_PRODUCT(LinearScan::print_statistics());
729 }
730 
731 
732 #ifndef PRODUCT
733 void CompilationResourceObj::print() const       { print_on(tty); }
734 
735 void CompilationResourceObj::print_on(outputStream* st) const {
736   st->print_cr("CompilationResourceObj(" INTPTR_FORMAT ")", p2i(this));
737 }
738 
739 // Called from debugger to get the interval with 'reg_num' during register allocation.
740 Interval* find_interval(int reg_num) {
741   return Compilation::current()->allocator()->find_interval_at(reg_num);
742 }
743 
744 #endif // NOT PRODUCT