src/share/vm/opto/compile.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/opto

src/share/vm/opto/compile.cpp

Print this page
rev 9003 : 8137167: JEP165: Compiler Control: Implementation task
Summary:
Reviewed-by:


 447 CompileWrapper::CompileWrapper(Compile* compile) : _compile(compile) {
 448   // the Compile* pointer is stored in the current ciEnv:
 449   ciEnv* env = compile->env();
 450   assert(env == ciEnv::current(), "must already be a ciEnv active");
 451   assert(env->compiler_data() == NULL, "compile already active?");
 452   env->set_compiler_data(compile);
 453   assert(compile == Compile::current(), "sanity");
 454 
 455   compile->set_type_dict(NULL);
 456   compile->set_clone_map(new Dict(cmpkey, hashkey, _compile->comp_arena()));
 457   compile->clone_map().set_clone_idx(0);
 458   compile->set_type_hwm(NULL);
 459   compile->set_type_last_size(0);
 460   compile->set_last_tf(NULL, NULL);
 461   compile->set_indexSet_arena(NULL);
 462   compile->set_indexSet_free_block_list(NULL);
 463   compile->init_type_arena();
 464   Type::Initialize(compile);
 465   _compile->set_scratch_buffer_blob(NULL);
 466   _compile->begin_method();
 467   _compile->clone_map().set_debug(_compile->has_method() && _compile->method_has_option(_compile->clone_map().debug_option_name));
 468 }
 469 CompileWrapper::~CompileWrapper() {
 470   _compile->end_method();
 471   if (_compile->scratch_buffer_blob() != NULL)
 472     BufferBlob::free(_compile->scratch_buffer_blob());
 473   _compile->env()->set_compiler_data(NULL);
 474 }
 475 
 476 
 477 //----------------------------print_compile_messages---------------------------
 478 void Compile::print_compile_messages() {
 479 #ifndef PRODUCT
 480   // Check if recompiling
 481   if (_subsume_loads == false && PrintOpto) {
 482     // Recompiling without allowing machine instructions to subsume loads
 483     tty->print_cr("*********************************************************");
 484     tty->print_cr("** Bailout: Recompile without subsuming loads          **");
 485     tty->print_cr("*********************************************************");
 486   }
 487   if (_do_escape_analysis != DoEscapeAnalysis && PrintOpto) {
 488     // Recompiling without escape analysis
 489     tty->print_cr("*********************************************************");
 490     tty->print_cr("** Bailout: Recompile without escape analysis          **");
 491     tty->print_cr("*********************************************************");
 492   }
 493   if (_eliminate_boxing != EliminateAutoBox && PrintOpto) {
 494     // Recompiling without boxing elimination
 495     tty->print_cr("*********************************************************");
 496     tty->print_cr("** Bailout: Recompile without boxing elimination       **");
 497     tty->print_cr("*********************************************************");
 498   }
 499   if (env()->break_at_compile()) {
 500     // Open the debugger when compiling this method.
 501     tty->print("### Breaking when compiling: ");
 502     method()->print_short_name();
 503     tty->cr();
 504     BREAKPOINT;
 505   }
 506 
 507   if( PrintOpto ) {
 508     if (is_osr_compilation()) {
 509       tty->print("[OSR]%3d", _compile_id);
 510     } else {
 511       tty->print("%3d", _compile_id);
 512     }
 513   }
 514 #endif
 515 }
 516 
 517 
 518 //-----------------------init_scratch_buffer_blob------------------------------
 519 // Construct a temporary BufferBlob and cache it for this compile.


 600 
 601   if (is_branch) // Restore label.
 602     n->as_MachBranch()->label_set(saveL, save_bnum);
 603 
 604   // End scratch_emit_size section.
 605   set_in_scratch_emit_size(false);
 606 
 607   return buf.insts_size();
 608 }
 609 
 610 
 611 // ============================================================================
 612 //------------------------------Compile standard-------------------------------
 613 debug_only( int Compile::_debug_idx = 100000; )
 614 
 615 // Compile a method.  entry_bci is -1 for normal compilations and indicates
 616 // the continuation bci for on stack replacement.
 617 
 618 
 619 Compile::Compile( ciEnv* ci_env, C2Compiler* compiler, ciMethod* target, int osr_bci,
 620                   bool subsume_loads, bool do_escape_analysis, bool eliminate_boxing )
 621                 : Phase(Compiler),
 622                   _env(ci_env),

 623                   _log(ci_env->log()),
 624                   _compile_id(ci_env->compile_id()),
 625                   _save_argument_registers(false),
 626                   _stub_name(NULL),
 627                   _stub_function(NULL),
 628                   _stub_entry_point(NULL),
 629                   _method(target),
 630                   _entry_bci(osr_bci),
 631                   _initial_gvn(NULL),
 632                   _for_igvn(NULL),
 633                   _warm_calls(NULL),
 634                   _subsume_loads(subsume_loads),
 635                   _do_escape_analysis(do_escape_analysis),
 636                   _eliminate_boxing(eliminate_boxing),
 637                   _failure_reason(NULL),
 638                   _code_buffer("Compile::Fill_buffer"),
 639                   _orig_pc_slot(0),
 640                   _orig_pc_slot_offset_in_bytes(0),
 641                   _has_method_handle_invokes(false),
 642                   _mach_constant_base_node(NULL),
 643                   _node_bundling_limit(0),
 644                   _node_bundling_base(NULL),
 645                   _java_calls(0),
 646                   _inner_loops(0),
 647                   _scratch_const_size(-1),
 648                   _in_scratch_emit_size(false),
 649                   _dead_node_list(comp_arena()),
 650                   _dead_node_count(0),
 651 #ifndef PRODUCT
 652                   _trace_opto_output(TraceOptoOutput || method()->has_option("TraceOptoOutput")),
 653                   _in_dump_cnt(0),
 654                   _printer(IdealGraphPrinter::printer()),
 655 #endif
 656                   _congraph(NULL),
 657                   _comp_arena(mtCompiler),
 658                   _node_arena(mtCompiler),
 659                   _old_arena(mtCompiler),
 660                   _Compile_types(mtCompiler),
 661                   _replay_inline_data(NULL),
 662                   _late_inlines(comp_arena(), 2, 0, NULL),
 663                   _string_late_inlines(comp_arena(), 2, 0, NULL),
 664                   _boxing_late_inlines(comp_arena(), 2, 0, NULL),
 665                   _late_inlines_pos(0),
 666                   _number_of_mh_late_inlines(0),
 667                   _inlining_progress(false),
 668                   _inlining_incrementally(false),
 669                   _print_inlining_list(NULL),
 670                   _print_inlining_stream(NULL),
 671                   _print_inlining_idx(0),
 672                   _print_inlining_output(NULL),
 673                   _interpreter_frame_size(0),
 674                   _max_node_limit(MaxNodeLimit) {
 675   C = this;
 676 
 677   CompileWrapper cw(this);
 678 
 679   if (CITimeVerbose) {
 680     tty->print(" ");
 681     target->holder()->name()->print();
 682     tty->print(".");
 683     target->print_short_name();
 684     tty->print("  ");
 685   }
 686   TraceTime t1("Total compilation time", &_t_totalCompilation, CITime, CITimeVerbose);
 687   TraceTime t2(NULL, &_t_methodCompilation, CITime, false);
 688 
 689 #ifndef PRODUCT
 690   bool print_opto_assembly = PrintOptoAssembly || _method->has_option("PrintOptoAssembly");
 691   if (!print_opto_assembly) {
 692     bool print_assembly = (PrintAssembly || _method->should_print_assembly());
 693     if (print_assembly && !Disassembler::can_decode()) {
 694       tty->print_cr("PrintAssembly request changed to PrintOptoAssembly");
 695       print_opto_assembly = true;
 696     }
 697   }
 698   set_print_assembly(print_opto_assembly);
 699   set_parsed_irreducible_loop(false);
 700 
 701   if (method()->has_option("ReplayInline")) {
 702     _replay_inline_data = ciReplay::load_inline_data(method(), entry_bci(), ci_env->comp_level());
 703   }
 704 #endif
 705   set_print_inlining(PrintInlining || method()->has_option("PrintInlining") NOT_PRODUCT( || PrintOptoInlining));
 706   set_print_intrinsics(PrintIntrinsics || method()->has_option("PrintIntrinsics"));
 707   set_has_irreducible_loop(true); // conservative until build_loop_tree() reset it
 708 
 709   if (ProfileTraps RTM_OPT_ONLY( || UseRTMLocking )) {
 710     // Make sure the method being compiled gets its own MDO,
 711     // so we can at least track the decompile_count().
 712     // Need MDO to record RTM code generation state.
 713     method()->ensure_method_data();
 714   }
 715 
 716   Init(::AliasLevel);
 717 
 718 
 719   print_compile_messages();
 720 
 721   _ilt = InlineTree::build_inline_tree_root();
 722 
 723   // Even if NO memory addresses are used, MergeMem nodes must have at least 1 slice
 724   assert(num_alias_types() >= AliasIdxRaw, "");
 725 
 726 #define MINIMUM_NODE_HASH  1023


 820     }
 821   }
 822 
 823   // Note:  Large methods are capped off in do_one_bytecode().
 824   if (failing())  return;
 825 
 826   // After parsing, node notes are no longer automagic.
 827   // They must be propagated by register_new_node_with_optimizer(),
 828   // clone(), or the like.
 829   set_default_node_notes(NULL);
 830 
 831   for (;;) {
 832     int successes = Inline_Warm();
 833     if (failing())  return;
 834     if (successes == 0)  break;
 835   }
 836 
 837   // Drain the list.
 838   Finish_Warm();
 839 #ifndef PRODUCT
 840   if (_printer && _printer->should_print(_method)) {
 841     _printer->print_inlining(this);
 842   }
 843 #endif
 844 
 845   if (failing())  return;
 846   NOT_PRODUCT( verify_graph_edges(); )
 847 
 848   // Now optimize
 849   Optimize();
 850   if (failing())  return;
 851   NOT_PRODUCT( verify_graph_edges(); )
 852 
 853 #ifndef PRODUCT
 854   if (PrintIdeal) {
 855     ttyLocker ttyl;  // keep the following output all in one block
 856     // This output goes directly to the tty, not the compiler log.
 857     // To enable tools to match it up with the compilation activity,
 858     // be sure to tag this tty output with the compile ID.
 859     if (xtty != NULL) {
 860       xtty->head("ideal compile_id='%d'%s", compile_id(),
 861                  is_osr_compilation()    ? " compile_kind='osr'" :
 862                  "");
 863     }
 864     root()->dump(9999);
 865     if (xtty != NULL) {
 866       xtty->tail("ideal");
 867     }
 868   }
 869 #endif
 870 
 871   NOT_PRODUCT( verify_barriers(); )
 872 
 873   // Dump compilation data to replay it.
 874   if (method()->has_option("DumpReplay")) {
 875     env()->dump_replay_data(_compile_id);
 876   }
 877   if (method()->has_option("DumpInline") && (ilt() != NULL)) {
 878     env()->dump_inline_data(_compile_id);
 879   }
 880 
 881   // Now that we know the size of all the monitors we can add a fixed slot
 882   // for the original deopt pc.
 883 
 884   _orig_pc_slot =  fixed_slots();
 885   int next_slot = _orig_pc_slot + (sizeof(address) / VMRegImpl::stack_slot_size);
 886   set_fixed_slots(next_slot);
 887 
 888   // Compute when to use implicit null checks. Used by matching trap based
 889   // nodes and NullCheck optimization.
 890   set_allowed_deopt_reasons();
 891 
 892   // Now generate code
 893   Code_Gen();
 894   if (failing())  return;
 895 
 896   // Check if we want to skip execution of all compiled code.
 897   {


 901       return;
 902     }
 903 #endif
 904     TracePhase tp("install_code", &timers[_t_registerMethod]);
 905 
 906     if (is_osr_compilation()) {
 907       _code_offsets.set_value(CodeOffsets::Verified_Entry, 0);
 908       _code_offsets.set_value(CodeOffsets::OSR_Entry, _first_block_size);
 909     } else {
 910       _code_offsets.set_value(CodeOffsets::Verified_Entry, _first_block_size);
 911       _code_offsets.set_value(CodeOffsets::OSR_Entry, 0);
 912     }
 913 
 914     env()->register_method(_method, _entry_bci,
 915                            &_code_offsets,
 916                            _orig_pc_slot_offset_in_bytes,
 917                            code_buffer(),
 918                            frame_size_in_words(), _oop_map_set,
 919                            &_handler_table, &_inc_table,
 920                            compiler,
 921                            env()->comp_level(),
 922                            has_unsafe_access(),
 923                            SharedRuntime::is_wide_vector(max_vector_size()),

 924                            rtm_state()
 925                            );
 926 
 927     if (log() != NULL) // Print code cache state into compiler log
 928       log()->code_cache_state();
 929   }
 930 }
 931 
 932 //------------------------------Compile----------------------------------------
 933 // Compile a runtime stub
 934 Compile::Compile( ciEnv* ci_env,
 935                   TypeFunc_generator generator,
 936                   address stub_function,
 937                   const char *stub_name,
 938                   int is_fancy_jump,
 939                   bool pass_tls,
 940                   bool save_arg_registers,
 941                   bool return_pc )

 942   : Phase(Compiler),
 943     _env(ci_env),

 944     _log(ci_env->log()),
 945     _compile_id(0),
 946     _save_argument_registers(save_arg_registers),
 947     _method(NULL),
 948     _stub_name(stub_name),
 949     _stub_function(stub_function),
 950     _stub_entry_point(NULL),
 951     _entry_bci(InvocationEntryBci),
 952     _initial_gvn(NULL),
 953     _for_igvn(NULL),
 954     _warm_calls(NULL),
 955     _orig_pc_slot(0),
 956     _orig_pc_slot_offset_in_bytes(0),
 957     _subsume_loads(true),
 958     _do_escape_analysis(false),
 959     _eliminate_boxing(false),
 960     _failure_reason(NULL),
 961     _code_buffer("Compile::Fill_buffer"),
 962     _has_method_handle_invokes(false),
 963     _mach_constant_base_node(NULL),


1073   set_cached_top_node( new ConNode(Type::TOP) );
1074   set_recent_alloc(NULL, NULL);
1075 
1076   // Create Debug Information Recorder to record scopes, oopmaps, etc.
1077   env()->set_oop_recorder(new OopRecorder(env()->arena()));
1078   env()->set_debug_info(new DebugInformationRecorder(env()->oop_recorder()));
1079   env()->set_dependencies(new Dependencies(env()));
1080 
1081   _fixed_slots = 0;
1082   set_has_split_ifs(false);
1083   set_has_loops(has_method() && method()->has_loops()); // first approximation
1084   set_has_stringbuilder(false);
1085   set_has_boxed_value(false);
1086   _trap_can_recompile = false;  // no traps emitted yet
1087   _major_progress = true; // start out assuming good things will happen
1088   set_has_unsafe_access(false);
1089   set_max_vector_size(0);
1090   Copy::zero_to_bytes(_trap_hist, sizeof(_trap_hist));
1091   set_decompile_count(0);
1092 
1093   set_do_freq_based_layout(BlockLayoutByFrequency || method_has_option("BlockLayoutByFrequency"));
1094   set_num_loop_opts(LoopOptsCount);
1095   set_do_inlining(Inline);
1096   set_max_inline_size(MaxInlineSize);
1097   set_freq_inline_size(FreqInlineSize);
1098   set_do_scheduling(OptoScheduling);
1099   set_do_count_invocations(false);
1100   set_do_method_data_update(false);
1101 
1102   set_do_vector_loop(false);
1103 
1104   bool do_vector = false;
1105   if (AllowVectorizeOnDemand) {
1106     if (has_method() && (method()->has_option("Vectorize") || method()->has_option("VectorizeDebug"))) {
1107       set_do_vector_loop(true);
1108     } else if (has_method() && method()->name() != 0 &&
1109                method()->intrinsic_id() == vmIntrinsics::_forEachRemaining) {
1110       set_do_vector_loop(true);
1111     }
1112 #ifndef PRODUCT
1113     if (do_vector_loop() && Verbose) {
1114       tty->print("Compile::Init: do vectorized loops (SIMD like) for method %s\n",  method()->name()->as_quoted_ascii());
1115     }
1116 #endif
1117   }
1118 
1119   set_age_code(has_method() && method()->profile_aging());
1120   set_rtm_state(NoRTM); // No RTM lock eliding by default
1121   method_has_option_value("MaxNodeLimit", _max_node_limit);

1122 #if INCLUDE_RTM_OPT
1123   if (UseRTMLocking && has_method() && (method()->method_data_or_null() != NULL)) {
1124     int rtm_state = method()->method_data()->rtm_state();
1125     if (method_has_option("NoRTMLockEliding") || ((rtm_state & NoRTM) != 0)) {
1126       // Don't generate RTM lock eliding code.
1127       set_rtm_state(NoRTM);
1128     } else if (method_has_option("UseRTMLockEliding") || ((rtm_state & UseRTM) != 0) || !UseRTMDeopt) {
1129       // Generate RTM lock eliding code without abort ratio calculation code.
1130       set_rtm_state(UseRTM);
1131     } else if (UseRTMDeopt) {
1132       // Generate RTM lock eliding code and include abort ratio calculation
1133       // code if UseRTMDeopt is on.
1134       set_rtm_state(ProfileRTM);
1135     }
1136   }
1137 #endif
1138   if (debug_info()->recording_non_safepoints()) {
1139     set_node_note_array(new(comp_arena()) GrowableArray<Node_Notes*>
1140                         (comp_arena(), 8, 0, NULL));
1141     set_default_node_notes(Node_Notes::make(this));


2074       PhaseRemoveUseless pru(initial_gvn(), for_igvn());
2075     }
2076 
2077     {
2078       TracePhase tp("incrementalInline_igvn", &timers[_t_incrInline_igvn]);
2079       igvn = PhaseIterGVN(gvn);
2080       igvn.optimize();
2081     }
2082   }
2083 
2084   set_inlining_incrementally(false);
2085 }
2086 
2087 
2088 //------------------------------Optimize---------------------------------------
2089 // Given a graph, optimize it.
2090 void Compile::Optimize() {
2091   TracePhase tp("optimizer", &timers[_t_optimizer]);
2092 
2093 #ifndef PRODUCT
2094   if (env()->break_at_compile()) {
2095     BREAKPOINT;
2096   }
2097 
2098 #endif
2099 
2100   ResourceMark rm;
2101   int          loop_opts_cnt;
2102 
2103   print_inlining_reinit();
2104 
2105   NOT_PRODUCT( verify_graph_edges(); )
2106 
2107   print_method(PHASE_AFTER_PARSING);
2108 
2109  {
2110   // Iterative Global Value Numbering, including ideal transforms
2111   // Initialize IterGVN with types and values from parse-time GVN
2112   PhaseIterGVN igvn(initial_gvn());
2113 #ifdef ASSERT
2114   _modified_nodes = new (comp_arena()) Unique_Node_List(comp_arena());


4338 // from uniformly. In this case, we need to adjust the randomicity of the
4339 // selection, or else we will end up biasing the selection towards the latter
4340 // candidates.
4341 //
4342 // Quick back-envelope calculation shows that for the list of n candidates
4343 // the equal probability for the candidate to persist as "best" can be
4344 // achieved by replacing it with "next" k-th candidate with the probability
4345 // of 1/k. It can be easily shown that by the end of the run, the
4346 // probability for any candidate is converged to 1/n, thus giving the
4347 // uniform distribution among all the candidates.
4348 //
4349 // We don't care about the domain size as long as (RANDOMIZED_DOMAIN / count) is large.
4350 #define RANDOMIZED_DOMAIN_POW 29
4351 #define RANDOMIZED_DOMAIN (1 << RANDOMIZED_DOMAIN_POW)
4352 #define RANDOMIZED_DOMAIN_MASK ((1 << (RANDOMIZED_DOMAIN_POW + 1)) - 1)
4353 bool Compile::randomized_select(int count) {
4354   assert(count > 0, "only positive");
4355   return (os::random() & RANDOMIZED_DOMAIN_MASK) < (RANDOMIZED_DOMAIN / count);
4356 }
4357 
4358 const char*   CloneMap::debug_option_name = "CloneMapDebug";
4359 CloneMap&     Compile::clone_map()                 { return _clone_map; }
4360 void          Compile::set_clone_map(Dict* d)      { _clone_map._dict = d; }
4361 
4362 void NodeCloneInfo::dump() const {
4363   tty->print(" {%d:%d} ", idx(), gen());
4364 }
4365 
4366 void CloneMap::clone(Node* old, Node* nnn, int gen) {
4367   uint64_t val = value(old->_idx);
4368   NodeCloneInfo cio(val);
4369   assert(val != 0, "old node should be in the map");
4370   NodeCloneInfo cin(cio.idx(), gen + cio.gen());
4371   insert(nnn->_idx, cin.get());
4372 #ifndef PRODUCT
4373   if (is_debug()) {
4374     tty->print_cr("CloneMap::clone inserted node %d info {%d:%d} into CloneMap", nnn->_idx, cin.idx(), cin.gen());
4375   }
4376 #endif
4377 }
4378 




 447 CompileWrapper::CompileWrapper(Compile* compile) : _compile(compile) {
 448   // the Compile* pointer is stored in the current ciEnv:
 449   ciEnv* env = compile->env();
 450   assert(env == ciEnv::current(), "must already be a ciEnv active");
 451   assert(env->compiler_data() == NULL, "compile already active?");
 452   env->set_compiler_data(compile);
 453   assert(compile == Compile::current(), "sanity");
 454 
 455   compile->set_type_dict(NULL);
 456   compile->set_clone_map(new Dict(cmpkey, hashkey, _compile->comp_arena()));
 457   compile->clone_map().set_clone_idx(0);
 458   compile->set_type_hwm(NULL);
 459   compile->set_type_last_size(0);
 460   compile->set_last_tf(NULL, NULL);
 461   compile->set_indexSet_arena(NULL);
 462   compile->set_indexSet_free_block_list(NULL);
 463   compile->init_type_arena();
 464   Type::Initialize(compile);
 465   _compile->set_scratch_buffer_blob(NULL);
 466   _compile->begin_method();
 467   _compile->clone_map().set_debug(_compile->has_method() && _compile->dirset()->CloneMapDebugOption);
 468 }
 469 CompileWrapper::~CompileWrapper() {
 470   _compile->end_method();
 471   if (_compile->scratch_buffer_blob() != NULL)
 472     BufferBlob::free(_compile->scratch_buffer_blob());
 473   _compile->env()->set_compiler_data(NULL);
 474 }
 475 
 476 
 477 //----------------------------print_compile_messages---------------------------
 478 void Compile::print_compile_messages() {
 479 #ifndef PRODUCT
 480   // Check if recompiling
 481   if (_subsume_loads == false && PrintOpto) {
 482     // Recompiling without allowing machine instructions to subsume loads
 483     tty->print_cr("*********************************************************");
 484     tty->print_cr("** Bailout: Recompile without subsuming loads          **");
 485     tty->print_cr("*********************************************************");
 486   }
 487   if (_do_escape_analysis != DoEscapeAnalysis && PrintOpto) {
 488     // Recompiling without escape analysis
 489     tty->print_cr("*********************************************************");
 490     tty->print_cr("** Bailout: Recompile without escape analysis          **");
 491     tty->print_cr("*********************************************************");
 492   }
 493   if (_eliminate_boxing != EliminateAutoBox && PrintOpto) {
 494     // Recompiling without boxing elimination
 495     tty->print_cr("*********************************************************");
 496     tty->print_cr("** Bailout: Recompile without boxing elimination       **");
 497     tty->print_cr("*********************************************************");
 498   }
 499   if (C->dirset()->BreakAtCompileOption) {
 500     // Open the debugger when compiling this method.
 501     tty->print("### Breaking when compiling: ");
 502     method()->print_short_name();
 503     tty->cr();
 504     BREAKPOINT;
 505   }
 506 
 507   if( PrintOpto ) {
 508     if (is_osr_compilation()) {
 509       tty->print("[OSR]%3d", _compile_id);
 510     } else {
 511       tty->print("%3d", _compile_id);
 512     }
 513   }
 514 #endif
 515 }
 516 
 517 
 518 //-----------------------init_scratch_buffer_blob------------------------------
 519 // Construct a temporary BufferBlob and cache it for this compile.


 600 
 601   if (is_branch) // Restore label.
 602     n->as_MachBranch()->label_set(saveL, save_bnum);
 603 
 604   // End scratch_emit_size section.
 605   set_in_scratch_emit_size(false);
 606 
 607   return buf.insts_size();
 608 }
 609 
 610 
 611 // ============================================================================
 612 //------------------------------Compile standard-------------------------------
 613 debug_only( int Compile::_debug_idx = 100000; )
 614 
 615 // Compile a method.  entry_bci is -1 for normal compilations and indicates
 616 // the continuation bci for on stack replacement.
 617 
 618 
 619 Compile::Compile( ciEnv* ci_env, C2Compiler* compiler, ciMethod* target, int osr_bci,
 620                   bool subsume_loads, bool do_escape_analysis, bool eliminate_boxing, DirectiveSet* dirset)
 621                 : Phase(Compiler),
 622                   _env(ci_env),
 623                   _dirset(dirset),
 624                   _log(ci_env->log()),
 625                   _compile_id(ci_env->compile_id()),
 626                   _save_argument_registers(false),
 627                   _stub_name(NULL),
 628                   _stub_function(NULL),
 629                   _stub_entry_point(NULL),
 630                   _method(target),
 631                   _entry_bci(osr_bci),
 632                   _initial_gvn(NULL),
 633                   _for_igvn(NULL),
 634                   _warm_calls(NULL),
 635                   _subsume_loads(subsume_loads),
 636                   _do_escape_analysis(do_escape_analysis),
 637                   _eliminate_boxing(eliminate_boxing),
 638                   _failure_reason(NULL),
 639                   _code_buffer("Compile::Fill_buffer"),
 640                   _orig_pc_slot(0),
 641                   _orig_pc_slot_offset_in_bytes(0),
 642                   _has_method_handle_invokes(false),
 643                   _mach_constant_base_node(NULL),
 644                   _node_bundling_limit(0),
 645                   _node_bundling_base(NULL),
 646                   _java_calls(0),
 647                   _inner_loops(0),
 648                   _scratch_const_size(-1),
 649                   _in_scratch_emit_size(false),
 650                   _dead_node_list(comp_arena()),
 651                   _dead_node_count(0),
 652 #ifndef PRODUCT
 653                   _trace_opto_output(dirset->TraceOptoOutputOption),
 654                   _in_dump_cnt(0),
 655                   _printer(IdealGraphPrinter::printer()),
 656 #endif
 657                   _congraph(NULL),
 658                   _comp_arena(mtCompiler),
 659                   _node_arena(mtCompiler),
 660                   _old_arena(mtCompiler),
 661                   _Compile_types(mtCompiler),
 662                   _replay_inline_data(NULL),
 663                   _late_inlines(comp_arena(), 2, 0, NULL),
 664                   _string_late_inlines(comp_arena(), 2, 0, NULL),
 665                   _boxing_late_inlines(comp_arena(), 2, 0, NULL),
 666                   _late_inlines_pos(0),
 667                   _number_of_mh_late_inlines(0),
 668                   _inlining_progress(false),
 669                   _inlining_incrementally(false),
 670                   _print_inlining_list(NULL),
 671                   _print_inlining_stream(NULL),
 672                   _print_inlining_idx(0),
 673                   _print_inlining_output(NULL),
 674                   _interpreter_frame_size(0),
 675                   _max_node_limit(MaxNodeLimit) {
 676   C = this;
 677 
 678   CompileWrapper cw(this);
 679 
 680   if (CITimeVerbose) {
 681     tty->print(" ");
 682     target->holder()->name()->print();
 683     tty->print(".");
 684     target->print_short_name();
 685     tty->print("  ");
 686   }
 687   TraceTime t1("Total compilation time", &_t_totalCompilation, CITime, CITimeVerbose);
 688   TraceTime t2(NULL, &_t_methodCompilation, CITime, false);
 689 
 690 #ifndef PRODUCT
 691   bool print_opto_assembly = dirset->PrintOptoAssemblyOption;
 692   if (!print_opto_assembly) {
 693     bool print_assembly = dirset->PrintAssemblyOption;
 694     if (print_assembly && !Disassembler::can_decode()) {
 695       tty->print_cr("PrintAssembly request changed to PrintOptoAssembly");
 696       print_opto_assembly = true;
 697     }
 698   }
 699   set_print_assembly(print_opto_assembly);
 700   set_parsed_irreducible_loop(false);
 701 
 702   if (dirset->ReplayInlineOption) {
 703     _replay_inline_data = ciReplay::load_inline_data(method(), entry_bci(), ci_env->comp_level());
 704   }
 705 #endif
 706   set_print_inlining(dirset->PrintInliningOption NOT_PRODUCT( || PrintOptoInlining));
 707   set_print_intrinsics(dirset->PrintIntrinsicsOption);
 708   set_has_irreducible_loop(true); // conservative until build_loop_tree() reset it
 709 
 710   if (ProfileTraps RTM_OPT_ONLY( || UseRTMLocking )) {
 711     // Make sure the method being compiled gets its own MDO,
 712     // so we can at least track the decompile_count().
 713     // Need MDO to record RTM code generation state.
 714     method()->ensure_method_data();
 715   }
 716 
 717   Init(::AliasLevel);
 718 
 719 
 720   print_compile_messages();
 721 
 722   _ilt = InlineTree::build_inline_tree_root();
 723 
 724   // Even if NO memory addresses are used, MergeMem nodes must have at least 1 slice
 725   assert(num_alias_types() >= AliasIdxRaw, "");
 726 
 727 #define MINIMUM_NODE_HASH  1023


 821     }
 822   }
 823 
 824   // Note:  Large methods are capped off in do_one_bytecode().
 825   if (failing())  return;
 826 
 827   // After parsing, node notes are no longer automagic.
 828   // They must be propagated by register_new_node_with_optimizer(),
 829   // clone(), or the like.
 830   set_default_node_notes(NULL);
 831 
 832   for (;;) {
 833     int successes = Inline_Warm();
 834     if (failing())  return;
 835     if (successes == 0)  break;
 836   }
 837 
 838   // Drain the list.
 839   Finish_Warm();
 840 #ifndef PRODUCT
 841   if (_printer && _printer->should_print(1)) {
 842     _printer->print_inlining(this);
 843   }
 844 #endif
 845 
 846   if (failing())  return;
 847   NOT_PRODUCT( verify_graph_edges(); )
 848 
 849   // Now optimize
 850   Optimize();
 851   if (failing())  return;
 852   NOT_PRODUCT( verify_graph_edges(); )
 853 
 854 #ifndef PRODUCT
 855   if (PrintIdeal) {
 856     ttyLocker ttyl;  // keep the following output all in one block
 857     // This output goes directly to the tty, not the compiler log.
 858     // To enable tools to match it up with the compilation activity,
 859     // be sure to tag this tty output with the compile ID.
 860     if (xtty != NULL) {
 861       xtty->head("ideal compile_id='%d'%s", compile_id(),
 862                  is_osr_compilation()    ? " compile_kind='osr'" :
 863                  "");
 864     }
 865     root()->dump(9999);
 866     if (xtty != NULL) {
 867       xtty->tail("ideal");
 868     }
 869   }
 870 #endif
 871 
 872   NOT_PRODUCT( verify_barriers(); )
 873 
 874   // Dump compilation data to replay it.
 875   if (dirset->DumpReplayOption) {
 876     env()->dump_replay_data(_compile_id);
 877   }
 878   if (dirset->DumpInlineOption && (ilt() != NULL)) {
 879     env()->dump_inline_data(_compile_id);
 880   }
 881 
 882   // Now that we know the size of all the monitors we can add a fixed slot
 883   // for the original deopt pc.
 884 
 885   _orig_pc_slot =  fixed_slots();
 886   int next_slot = _orig_pc_slot + (sizeof(address) / VMRegImpl::stack_slot_size);
 887   set_fixed_slots(next_slot);
 888 
 889   // Compute when to use implicit null checks. Used by matching trap based
 890   // nodes and NullCheck optimization.
 891   set_allowed_deopt_reasons();
 892 
 893   // Now generate code
 894   Code_Gen();
 895   if (failing())  return;
 896 
 897   // Check if we want to skip execution of all compiled code.
 898   {


 902       return;
 903     }
 904 #endif
 905     TracePhase tp("install_code", &timers[_t_registerMethod]);
 906 
 907     if (is_osr_compilation()) {
 908       _code_offsets.set_value(CodeOffsets::Verified_Entry, 0);
 909       _code_offsets.set_value(CodeOffsets::OSR_Entry, _first_block_size);
 910     } else {
 911       _code_offsets.set_value(CodeOffsets::Verified_Entry, _first_block_size);
 912       _code_offsets.set_value(CodeOffsets::OSR_Entry, 0);
 913     }
 914 
 915     env()->register_method(_method, _entry_bci,
 916                            &_code_offsets,
 917                            _orig_pc_slot_offset_in_bytes,
 918                            code_buffer(),
 919                            frame_size_in_words(), _oop_map_set,
 920                            &_handler_table, &_inc_table,
 921                            compiler,

 922                            has_unsafe_access(),
 923                            SharedRuntime::is_wide_vector(max_vector_size()),
 924                            _dirset,
 925                            rtm_state()
 926                            );
 927 
 928     if (log() != NULL) // Print code cache state into compiler log
 929       log()->code_cache_state();
 930   }
 931 }
 932 
 933 //------------------------------Compile----------------------------------------
 934 // Compile a runtime stub
 935 Compile::Compile( ciEnv* ci_env,
 936                   TypeFunc_generator generator,
 937                   address stub_function,
 938                   const char *stub_name,
 939                   int is_fancy_jump,
 940                   bool pass_tls,
 941                   bool save_arg_registers,
 942                   bool return_pc,
 943                   DirectiveSet* dirset)
 944   : Phase(Compiler),
 945     _env(ci_env),
 946     _dirset(dirset),
 947     _log(ci_env->log()),
 948     _compile_id(0),
 949     _save_argument_registers(save_arg_registers),
 950     _method(NULL),
 951     _stub_name(stub_name),
 952     _stub_function(stub_function),
 953     _stub_entry_point(NULL),
 954     _entry_bci(InvocationEntryBci),
 955     _initial_gvn(NULL),
 956     _for_igvn(NULL),
 957     _warm_calls(NULL),
 958     _orig_pc_slot(0),
 959     _orig_pc_slot_offset_in_bytes(0),
 960     _subsume_loads(true),
 961     _do_escape_analysis(false),
 962     _eliminate_boxing(false),
 963     _failure_reason(NULL),
 964     _code_buffer("Compile::Fill_buffer"),
 965     _has_method_handle_invokes(false),
 966     _mach_constant_base_node(NULL),


1076   set_cached_top_node( new ConNode(Type::TOP) );
1077   set_recent_alloc(NULL, NULL);
1078 
1079   // Create Debug Information Recorder to record scopes, oopmaps, etc.
1080   env()->set_oop_recorder(new OopRecorder(env()->arena()));
1081   env()->set_debug_info(new DebugInformationRecorder(env()->oop_recorder()));
1082   env()->set_dependencies(new Dependencies(env()));
1083 
1084   _fixed_slots = 0;
1085   set_has_split_ifs(false);
1086   set_has_loops(has_method() && method()->has_loops()); // first approximation
1087   set_has_stringbuilder(false);
1088   set_has_boxed_value(false);
1089   _trap_can_recompile = false;  // no traps emitted yet
1090   _major_progress = true; // start out assuming good things will happen
1091   set_has_unsafe_access(false);
1092   set_max_vector_size(0);
1093   Copy::zero_to_bytes(_trap_hist, sizeof(_trap_hist));
1094   set_decompile_count(0);
1095 
1096   set_do_freq_based_layout(_dirset->BlockLayoutByFrequencyOption);
1097   set_num_loop_opts(LoopOptsCount);
1098   set_do_inlining(Inline);
1099   set_max_inline_size(MaxInlineSize);
1100   set_freq_inline_size(FreqInlineSize);
1101   set_do_scheduling(OptoScheduling);
1102   set_do_count_invocations(false);
1103   set_do_method_data_update(false);
1104 
1105   set_do_vector_loop(false);
1106 
1107   bool do_vector = false;
1108   if (AllowVectorizeOnDemand) {
1109     if (has_method() && (_dirset->VectorizeOption || _dirset->VectorizeDebugOption)) {
1110       set_do_vector_loop(true);
1111     } else if (has_method() && method()->name() != 0 &&
1112                method()->intrinsic_id() == vmIntrinsics::_forEachRemaining) {
1113       set_do_vector_loop(true);
1114     }
1115 #ifndef PRODUCT
1116     if (do_vector_loop() && Verbose) {
1117       tty->print("Compile::Init: do vectorized loops (SIMD like) for method %s\n",  method()->name()->as_quoted_ascii());
1118     }
1119 #endif
1120   }
1121 
1122   set_age_code(has_method() && method()->profile_aging());
1123   set_rtm_state(NoRTM); // No RTM lock eliding by default
1124   _max_node_limit = _dirset->MaxNodeLimitOption;
1125 
1126 #if INCLUDE_RTM_OPT
1127   if (UseRTMLocking && has_method() && (method()->method_data_or_null() != NULL)) {
1128     int rtm_state = method()->method_data()->rtm_state();
1129     if (method_has_option("NoRTMLockEliding") || ((rtm_state & NoRTM) != 0)) {
1130       // Don't generate RTM lock eliding code.
1131       set_rtm_state(NoRTM);
1132     } else if (method_has_option("UseRTMLockEliding") || ((rtm_state & UseRTM) != 0) || !UseRTMDeopt) {
1133       // Generate RTM lock eliding code without abort ratio calculation code.
1134       set_rtm_state(UseRTM);
1135     } else if (UseRTMDeopt) {
1136       // Generate RTM lock eliding code and include abort ratio calculation
1137       // code if UseRTMDeopt is on.
1138       set_rtm_state(ProfileRTM);
1139     }
1140   }
1141 #endif
1142   if (debug_info()->recording_non_safepoints()) {
1143     set_node_note_array(new(comp_arena()) GrowableArray<Node_Notes*>
1144                         (comp_arena(), 8, 0, NULL));
1145     set_default_node_notes(Node_Notes::make(this));


2078       PhaseRemoveUseless pru(initial_gvn(), for_igvn());
2079     }
2080 
2081     {
2082       TracePhase tp("incrementalInline_igvn", &timers[_t_incrInline_igvn]);
2083       igvn = PhaseIterGVN(gvn);
2084       igvn.optimize();
2085     }
2086   }
2087 
2088   set_inlining_incrementally(false);
2089 }
2090 
2091 
2092 //------------------------------Optimize---------------------------------------
2093 // Given a graph, optimize it.
2094 void Compile::Optimize() {
2095   TracePhase tp("optimizer", &timers[_t_optimizer]);
2096 
2097 #ifndef PRODUCT
2098   if (_dirset->BreakAtCompileOption) {
2099     BREAKPOINT;
2100   }
2101 
2102 #endif
2103 
2104   ResourceMark rm;
2105   int          loop_opts_cnt;
2106 
2107   print_inlining_reinit();
2108 
2109   NOT_PRODUCT( verify_graph_edges(); )
2110 
2111   print_method(PHASE_AFTER_PARSING);
2112 
2113  {
2114   // Iterative Global Value Numbering, including ideal transforms
2115   // Initialize IterGVN with types and values from parse-time GVN
2116   PhaseIterGVN igvn(initial_gvn());
2117 #ifdef ASSERT
2118   _modified_nodes = new (comp_arena()) Unique_Node_List(comp_arena());


4342 // from uniformly. In this case, we need to adjust the randomicity of the
4343 // selection, or else we will end up biasing the selection towards the latter
4344 // candidates.
4345 //
4346 // Quick back-envelope calculation shows that for the list of n candidates
4347 // the equal probability for the candidate to persist as "best" can be
4348 // achieved by replacing it with "next" k-th candidate with the probability
4349 // of 1/k. It can be easily shown that by the end of the run, the
4350 // probability for any candidate is converged to 1/n, thus giving the
4351 // uniform distribution among all the candidates.
4352 //
4353 // We don't care about the domain size as long as (RANDOMIZED_DOMAIN / count) is large.
4354 #define RANDOMIZED_DOMAIN_POW 29
4355 #define RANDOMIZED_DOMAIN (1 << RANDOMIZED_DOMAIN_POW)
4356 #define RANDOMIZED_DOMAIN_MASK ((1 << (RANDOMIZED_DOMAIN_POW + 1)) - 1)
4357 bool Compile::randomized_select(int count) {
4358   assert(count > 0, "only positive");
4359   return (os::random() & RANDOMIZED_DOMAIN_MASK) < (RANDOMIZED_DOMAIN / count);
4360 }
4361 

4362 CloneMap&     Compile::clone_map()                 { return _clone_map; }
4363 void          Compile::set_clone_map(Dict* d)      { _clone_map._dict = d; }
4364 
4365 void NodeCloneInfo::dump() const {
4366   tty->print(" {%d:%d} ", idx(), gen());
4367 }
4368 
4369 void CloneMap::clone(Node* old, Node* nnn, int gen) {
4370   uint64_t val = value(old->_idx);
4371   NodeCloneInfo cio(val);
4372   assert(val != 0, "old node should be in the map");
4373   NodeCloneInfo cin(cio.idx(), gen + cio.gen());
4374   insert(nnn->_idx, cin.get());
4375 #ifndef PRODUCT
4376   if (is_debug()) {
4377     tty->print_cr("CloneMap::clone inserted node %d info {%d:%d} into CloneMap", nnn->_idx, cin.idx(), cin.gen());
4378   }
4379 #endif
4380 }
4381 


src/share/vm/opto/compile.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File