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