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