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