src/share/vm/c1/c1_Compilation.cpp

Print this page




  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_ValueMap.hpp"
  33 #include "c1/c1_ValueStack.hpp"
  34 #include "code/debugInfoRec.hpp"
  35 #include "compiler/compileLog.hpp"
  36 #include "c1/c1_RangeCheckElimination.hpp"
  37 
  38 
  39 typedef enum {
  40   _t_compile,
  41   _t_setup,
  42   _t_buildIR,


  43   _t_optimize_blocks,
  44   _t_optimize_null_checks,
  45   _t_rangeCheckElimination,
  46   _t_emit_lir,
  47   _t_linearScan,
  48   _t_lirGeneration,
  49   _t_lir_schedule,
  50   _t_codeemit,
  51   _t_codeinstall,
  52   max_phase_timers
  53 } TimerName;
  54 
  55 static const char * timer_name[] = {
  56   "compile",
  57   "setup",
  58   "buildIR",


  59   "optimize_blocks",
  60   "optimize_null_checks",
  61   "rangeCheckElimination",
  62   "emit_lir",
  63   "linearScan",
  64   "lirGeneration",
  65   "lir_schedule",
  66   "codeemit",
  67   "codeinstall"
  68 };
  69 
  70 static elapsedTimer timers[max_phase_timers];
  71 static int totalInstructionNodes = 0;
  72 
  73 class PhaseTraceTime: public TraceTime {
  74  private:
  75   JavaThread* _thread;
  76   CompileLog* _log;
  77   TimerName _timer;
  78 
  79  public:
  80   PhaseTraceTime(TimerName timer)
  81   : TraceTime("", &timers[timer], CITime || CITimeEach, Verbose),
  82     _log(NULL), _timer(timer)
  83   {
  84     if (Compilation::current() != NULL) {
  85       _log = Compilation::current()->log();


 127   // (The default oop recorder is ignorant of the CI.)
 128   OopRecorder* ooprec = new OopRecorder(_env->arena());
 129   _env->set_oop_recorder(ooprec);
 130   _env->set_debug_info(new DebugInformationRecorder(ooprec));
 131   debug_info_recorder()->set_oopmaps(new OopMapSet());
 132   _env->set_dependencies(new Dependencies(_env));
 133 }
 134 
 135 
 136 void Compilation::build_hir() {
 137   CHECK_BAILOUT();
 138 
 139   // setup ir
 140   CompileLog* log = this->log();
 141   if (log != NULL) {
 142     log->begin_head("parse method='%d' ",
 143                     log->identify(_method));
 144     log->stamp();
 145     log->end_head();
 146   }


 147   _hir = new IR(this, method(), osr_bci());

 148   if (log)  log->done("parse");
 149   if (!_hir->is_valid()) {
 150     bailout("invalid parsing");
 151     return;
 152   }
 153 
 154 #ifndef PRODUCT
 155   if (PrintCFGToFile) {
 156     CFGPrinter::print_cfg(_hir, "After Generation of HIR", true, false);
 157   }
 158 #endif
 159 
 160 #ifndef PRODUCT
 161   if (PrintCFG || PrintCFG0) { tty->print_cr("CFG after parsing"); _hir->print(true); }
 162   if (PrintIR  || PrintIR0 ) { tty->print_cr("IR after parsing"); _hir->print(false); }
 163 #endif
 164 
 165   _hir->verify();
 166 
 167   if (UseC1Optimizations) {


 172     _hir->optimize_blocks();
 173   }
 174 
 175   _hir->verify();
 176 
 177   _hir->split_critical_edges();
 178 
 179 #ifndef PRODUCT
 180   if (PrintCFG || PrintCFG1) { tty->print_cr("CFG after optimizations"); _hir->print(true); }
 181   if (PrintIR  || PrintIR1 ) { tty->print_cr("IR after optimizations"); _hir->print(false); }
 182 #endif
 183 
 184   _hir->verify();
 185 
 186   // compute block ordering for code generation
 187   // the control flow must not be changed from here on
 188   _hir->compute_code();
 189 
 190   if (UseGlobalValueNumbering) {
 191     // No resource mark here! LoopInvariantCodeMotion can allocate ValueStack objects.

 192     int instructions = Instruction::number_of_instructions();
 193     GlobalValueNumbering gvn(_hir);
 194     assert(instructions == Instruction::number_of_instructions(),
 195            "shouldn't have created an instructions");
 196   }
 197 
 198   _hir->verify();
 199 
 200 #ifndef PRODUCT
 201   if (PrintCFGToFile) {
 202     CFGPrinter::print_cfg(_hir, "Before RangeCheckElimination", true, false);
 203   }
 204 #endif
 205 
 206   if (RangeCheckElimination) {
 207     if (_hir->osr_entry() == NULL) {
 208       PhaseTraceTime timeit(_t_rangeCheckElimination);
 209       RangeCheckElimination::eliminate(_hir);
 210     }
 211   }


 402   assert(in_bytes(frame_map()->framesize_in_bytes()) % sizeof(intptr_t) == 0, "must be at least pointer aligned");
 403   _env->register_method(
 404     method(),
 405     osr_bci(),
 406     &_offsets,
 407     in_bytes(_frame_map->sp_offset_for_orig_pc()),
 408     code(),
 409     in_bytes(frame_map()->framesize_in_bytes()) / sizeof(intptr_t),
 410     debug_info_recorder()->_oopmaps,
 411     exception_handler_table(),
 412     implicit_exception_table(),
 413     compiler(),
 414     _env->comp_level(),
 415     has_unsafe_access(),
 416     SharedRuntime::is_wide_vector(max_vector_size())
 417   );
 418 }
 419 
 420 
 421 void Compilation::compile_method() {



 422   // setup compilation
 423   initialize();

 424 
 425   if (!method()->can_be_compiled()) {
 426     // Prevent race condition 6328518.
 427     // This can happen if the method is obsolete or breakpointed.
 428     bailout("Bailing out because method is not compilable");
 429     return;
 430   }
 431 
 432   if (_env->jvmti_can_hotswap_or_post_breakpoint()) {
 433     // We can assert evol_method because method->can_be_compiled is true.
 434     dependency_recorder()->assert_evol_method(method());
 435   }
 436 
 437   if (method()->break_at_execute()) {
 438     BREAKPOINT;
 439   }
 440 
 441 #ifndef PRODUCT
 442   if (PrintCFGToFile) {
 443     CFGPrinter::print_compilation(this);


 598   if (!bailed_out()) {
 599     // keep first bailout message
 600     if (PrintCompilation || PrintBailouts) tty->print_cr("compilation bailout: %s", msg);
 601     _bailout_msg = msg;
 602   }
 603 }
 604 
 605 ciKlass* Compilation::cha_exact_type(ciType* type) {
 606   if (type != NULL && type->is_loaded() && type->is_instance_klass()) {
 607     ciInstanceKlass* ik = type->as_instance_klass();
 608     assert(ik->exact_klass() == NULL, "no cha for final klass");
 609     if (DeoptC1 && UseCHA && !(ik->has_subklass() || ik->is_interface())) {
 610       dependency_recorder()->assert_leaf_type(ik);
 611       return ik;
 612     }
 613   }
 614   return NULL;
 615 }
 616 
 617 void Compilation::print_timers() {
 618   // tty->print_cr("    Native methods         : %6.3f s, Average : %2.3f", CompileBroker::_t_native_compilation.seconds(), CompileBroker::_t_native_compilation.seconds() / CompileBroker::_total_native_compile_count);
 619   float total = timers[_t_setup].seconds() + timers[_t_buildIR].seconds() + timers[_t_emit_lir].seconds() + timers[_t_lir_schedule].seconds() + timers[_t_codeemit].seconds() + timers[_t_codeinstall].seconds();
 620 


















 621 
 622   tty->print_cr("    Detailed C1 Timings");
 623   tty->print_cr("       Setup time:        %6.3f s (%4.1f%%)",    timers[_t_setup].seconds(),           (timers[_t_setup].seconds() / total) * 100.0);
 624   tty->print_cr("       Build IR:          %6.3f s (%4.1f%%)",    timers[_t_buildIR].seconds(),         (timers[_t_buildIR].seconds() / total) * 100.0);
 625   float t_optimizeIR = timers[_t_optimize_blocks].seconds() + timers[_t_optimize_null_checks].seconds();
 626   tty->print_cr("         Optimize:           %6.3f s (%4.1f%%)", t_optimizeIR,                         (t_optimizeIR / total) * 100.0);
 627   tty->print_cr("         RCE:                %6.3f s (%4.1f%%)", timers[_t_rangeCheckElimination].seconds(),      (timers[_t_rangeCheckElimination].seconds() / total) * 100.0);
 628   tty->print_cr("       Emit LIR:          %6.3f s (%4.1f%%)",    timers[_t_emit_lir].seconds(),        (timers[_t_emit_lir].seconds() / total) * 100.0);
 629   tty->print_cr("         LIR Gen:          %6.3f s (%4.1f%%)",   timers[_t_lirGeneration].seconds(), (timers[_t_lirGeneration].seconds() / total) * 100.0);
 630   tty->print_cr("         Linear Scan:      %6.3f s (%4.1f%%)",   timers[_t_linearScan].seconds(),    (timers[_t_linearScan].seconds() / total) * 100.0);
 631   NOT_PRODUCT(LinearScan::print_timers(timers[_t_linearScan].seconds()));
 632   tty->print_cr("       LIR Schedule:      %6.3f s (%4.1f%%)",    timers[_t_lir_schedule].seconds(),  (timers[_t_lir_schedule].seconds() / total) * 100.0);
 633   tty->print_cr("       Code Emission:     %6.3f s (%4.1f%%)",    timers[_t_codeemit].seconds(),        (timers[_t_codeemit].seconds() / total) * 100.0);
 634   tty->print_cr("       Code Installation: %6.3f s (%4.1f%%)",    timers[_t_codeinstall].seconds(),     (timers[_t_codeinstall].seconds() / total) * 100.0);
 635   tty->print_cr("       Instruction Nodes: %6d nodes",    totalInstructionNodes);

















 636 
 637   NOT_PRODUCT(LinearScan::print_statistics());
 638 }
 639 
 640 
 641 #ifndef PRODUCT
 642 void Compilation::compile_only_this_method() {
 643   ResourceMark rm;
 644   fileStream stream(fopen("c1_compile_only", "wt"));
 645   stream.print_cr("# c1 compile only directives");
 646   compile_only_this_scope(&stream, hir()->top_scope());
 647 }
 648 
 649 
 650 void Compilation::compile_only_this_scope(outputStream* st, IRScope* scope) {
 651   st->print("CompileOnly=");
 652   scope->method()->holder()->name()->print_symbol_on(st);
 653   st->print(".");
 654   scope->method()->name()->print_symbol_on(st);
 655   st->cr();


  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_ValueMap.hpp"
  33 #include "c1/c1_ValueStack.hpp"
  34 #include "code/debugInfoRec.hpp"
  35 #include "compiler/compileLog.hpp"
  36 #include "c1/c1_RangeCheckElimination.hpp"
  37 
  38 
  39 typedef enum {
  40   _t_compile,
  41     _t_setup,
  42     _t_buildIR,
  43       _t_hir_parse,
  44       _t_gvn,
  45       _t_optimize_blocks,
  46       _t_optimize_null_checks,
  47       _t_rangeCheckElimination,
  48     _t_emit_lir,
  49       _t_linearScan,
  50       _t_lirGeneration,

  51     _t_codeemit,
  52     _t_codeinstall,
  53   max_phase_timers
  54 } TimerName;
  55 
  56 static const char * timer_name[] = {
  57   "compile",
  58   "setup",
  59   "buildIR",
  60   "parse_hir",
  61   "gvn",
  62   "optimize_blocks",
  63   "optimize_null_checks",
  64   "rangeCheckElimination",
  65   "emit_lir",
  66   "linearScan",
  67   "lirGeneration",

  68   "codeemit",
  69   "codeinstall"
  70 };
  71 
  72 static elapsedTimer timers[max_phase_timers];
  73 static int totalInstructionNodes = 0;
  74 
  75 class PhaseTraceTime: public TraceTime {
  76  private:
  77   JavaThread* _thread;
  78   CompileLog* _log;
  79   TimerName _timer;
  80 
  81  public:
  82   PhaseTraceTime(TimerName timer)
  83   : TraceTime("", &timers[timer], CITime || CITimeEach, Verbose),
  84     _log(NULL), _timer(timer)
  85   {
  86     if (Compilation::current() != NULL) {
  87       _log = Compilation::current()->log();


 129   // (The default oop recorder is ignorant of the CI.)
 130   OopRecorder* ooprec = new OopRecorder(_env->arena());
 131   _env->set_oop_recorder(ooprec);
 132   _env->set_debug_info(new DebugInformationRecorder(ooprec));
 133   debug_info_recorder()->set_oopmaps(new OopMapSet());
 134   _env->set_dependencies(new Dependencies(_env));
 135 }
 136 
 137 
 138 void Compilation::build_hir() {
 139   CHECK_BAILOUT();
 140 
 141   // setup ir
 142   CompileLog* log = this->log();
 143   if (log != NULL) {
 144     log->begin_head("parse method='%d' ",
 145                     log->identify(_method));
 146     log->stamp();
 147     log->end_head();
 148   }
 149   {
 150     PhaseTraceTime timeit(_t_hir_parse);
 151     _hir = new IR(this, method(), osr_bci());
 152   }
 153   if (log)  log->done("parse");
 154   if (!_hir->is_valid()) {
 155     bailout("invalid parsing");
 156     return;
 157   }
 158 
 159 #ifndef PRODUCT
 160   if (PrintCFGToFile) {
 161     CFGPrinter::print_cfg(_hir, "After Generation of HIR", true, false);
 162   }
 163 #endif
 164 
 165 #ifndef PRODUCT
 166   if (PrintCFG || PrintCFG0) { tty->print_cr("CFG after parsing"); _hir->print(true); }
 167   if (PrintIR  || PrintIR0 ) { tty->print_cr("IR after parsing"); _hir->print(false); }
 168 #endif
 169 
 170   _hir->verify();
 171 
 172   if (UseC1Optimizations) {


 177     _hir->optimize_blocks();
 178   }
 179 
 180   _hir->verify();
 181 
 182   _hir->split_critical_edges();
 183 
 184 #ifndef PRODUCT
 185   if (PrintCFG || PrintCFG1) { tty->print_cr("CFG after optimizations"); _hir->print(true); }
 186   if (PrintIR  || PrintIR1 ) { tty->print_cr("IR after optimizations"); _hir->print(false); }
 187 #endif
 188 
 189   _hir->verify();
 190 
 191   // compute block ordering for code generation
 192   // the control flow must not be changed from here on
 193   _hir->compute_code();
 194 
 195   if (UseGlobalValueNumbering) {
 196     // No resource mark here! LoopInvariantCodeMotion can allocate ValueStack objects.
 197     PhaseTraceTime timeit(_t_gvn);
 198     int instructions = Instruction::number_of_instructions();
 199     GlobalValueNumbering gvn(_hir);
 200     assert(instructions == Instruction::number_of_instructions(),
 201            "shouldn't have created an instructions");
 202   }
 203 
 204   _hir->verify();
 205 
 206 #ifndef PRODUCT
 207   if (PrintCFGToFile) {
 208     CFGPrinter::print_cfg(_hir, "Before RangeCheckElimination", true, false);
 209   }
 210 #endif
 211 
 212   if (RangeCheckElimination) {
 213     if (_hir->osr_entry() == NULL) {
 214       PhaseTraceTime timeit(_t_rangeCheckElimination);
 215       RangeCheckElimination::eliminate(_hir);
 216     }
 217   }


 408   assert(in_bytes(frame_map()->framesize_in_bytes()) % sizeof(intptr_t) == 0, "must be at least pointer aligned");
 409   _env->register_method(
 410     method(),
 411     osr_bci(),
 412     &_offsets,
 413     in_bytes(_frame_map->sp_offset_for_orig_pc()),
 414     code(),
 415     in_bytes(frame_map()->framesize_in_bytes()) / sizeof(intptr_t),
 416     debug_info_recorder()->_oopmaps,
 417     exception_handler_table(),
 418     implicit_exception_table(),
 419     compiler(),
 420     _env->comp_level(),
 421     has_unsafe_access(),
 422     SharedRuntime::is_wide_vector(max_vector_size())
 423   );
 424 }
 425 
 426 
 427 void Compilation::compile_method() {
 428   {
 429     PhaseTraceTime timeit(_t_setup);
 430     
 431     // setup compilation
 432     initialize();
 433   }
 434 
 435   if (!method()->can_be_compiled()) {
 436     // Prevent race condition 6328518.
 437     // This can happen if the method is obsolete or breakpointed.
 438     bailout("Bailing out because method is not compilable");
 439     return;
 440   }
 441 
 442   if (_env->jvmti_can_hotswap_or_post_breakpoint()) {
 443     // We can assert evol_method because method->can_be_compiled is true.
 444     dependency_recorder()->assert_evol_method(method());
 445   }
 446 
 447   if (method()->break_at_execute()) {
 448     BREAKPOINT;
 449   }
 450 
 451 #ifndef PRODUCT
 452   if (PrintCFGToFile) {
 453     CFGPrinter::print_compilation(this);


 608   if (!bailed_out()) {
 609     // keep first bailout message
 610     if (PrintCompilation || PrintBailouts) tty->print_cr("compilation bailout: %s", msg);
 611     _bailout_msg = msg;
 612   }
 613 }
 614 
 615 ciKlass* Compilation::cha_exact_type(ciType* type) {
 616   if (type != NULL && type->is_loaded() && type->is_instance_klass()) {
 617     ciInstanceKlass* ik = type->as_instance_klass();
 618     assert(ik->exact_klass() == NULL, "no cha for final klass");
 619     if (DeoptC1 && UseCHA && !(ik->has_subklass() || ik->is_interface())) {
 620       dependency_recorder()->assert_leaf_type(ik);
 621       return ik;
 622     }
 623   }
 624   return NULL;
 625 }
 626 
 627 void Compilation::print_timers() {
 628   tty->print_cr("    C1 Compile Time:    %6.3f s",      timers[_t_compile].seconds());
 629   tty->print_cr("       Setup time:        %6.3f s",    timers[_t_setup].seconds());
 630   
 631   {
 632     tty->print_cr("       Build HIR:         %6.3f s",    timers[_t_buildIR].seconds());  
 633     tty->print_cr("         Parse:             %6.3f s", timers[_t_hir_parse].seconds());
 634     tty->print_cr("         Optimize blocks:   %6.3f s", timers[_t_optimize_blocks].seconds());
 635     tty->print_cr("         GVN:               %6.3f s", timers[_t_gvn].seconds());
 636     tty->print_cr("         Null checks elim:  %6.3f s", timers[_t_optimize_null_checks].seconds());
 637     tty->print_cr("         Range checks elim: %6.3f s", timers[_t_rangeCheckElimination].seconds());
 638     
 639     double other = timers[_t_buildIR].seconds() - 
 640       (timers[_t_hir_parse].seconds() + 
 641        timers[_t_optimize_blocks].seconds() + 
 642        timers[_t_gvn].seconds() +    
 643        timers[_t_optimize_null_checks].seconds() +        
 644        timers[_t_rangeCheckElimination].seconds());
 645     if (other > 0) {
 646       tty->print_cr("         Other:             %6.3f s", other);
 647     }
 648   }
 649   
 650   {
 651     tty->print_cr("       Emit LIR:          %6.3f s",    timers[_t_emit_lir].seconds());
 652     tty->print_cr("         LIR Gen:           %6.3f s",   timers[_t_lirGeneration].seconds());
 653     tty->print_cr("         Linear Scan:       %6.3f s",   timers[_t_linearScan].seconds());





 654     NOT_PRODUCT(LinearScan::print_timers(timers[_t_linearScan].seconds()));
 655     
 656     double other = timers[_t_emit_lir].seconds() - 
 657       (timers[_t_lirGeneration].seconds() + 
 658        timers[_t_linearScan].seconds());
 659     if (other > 0) {
 660       tty->print_cr("         Other:             %6.3f s", other);
 661     }
 662   }
 663   
 664   tty->print_cr("       Code Emission:     %6.3f s",    timers[_t_codeemit].seconds());
 665   tty->print_cr("       Code Installation: %6.3f s",    timers[_t_codeinstall].seconds());
 666   
 667   double other = timers[_t_compile].seconds() - 
 668       (timers[_t_setup].seconds() + 
 669        timers[_t_buildIR].seconds() + 
 670        timers[_t_emit_lir].seconds() + 
 671        timers[_t_codeemit].seconds() + 
 672        timers[_t_codeinstall].seconds());
 673   if (other > 0) {
 674     tty->print_cr("       Other:             %6.3f s", other);    
 675   }
 676   
 677   NOT_PRODUCT(LinearScan::print_statistics());
 678 }
 679 
 680 
 681 #ifndef PRODUCT
 682 void Compilation::compile_only_this_method() {
 683   ResourceMark rm;
 684   fileStream stream(fopen("c1_compile_only", "wt"));
 685   stream.print_cr("# c1 compile only directives");
 686   compile_only_this_scope(&stream, hir()->top_scope());
 687 }
 688 
 689 
 690 void Compilation::compile_only_this_scope(outputStream* st, IRScope* scope) {
 691   st->print("CompileOnly=");
 692   scope->method()->holder()->name()->print_symbol_on(st);
 693   st->print(".");
 694   scope->method()->name()->print_symbol_on(st);
 695   st->cr();