< prev index next >

src/hotspot/share/opto/compile.cpp

Print this page

 615                   _compile_id(ci_env->compile_id()),
 616                   _options(options),
 617                   _method(target),
 618                   _entry_bci(osr_bci),
 619                   _ilt(nullptr),
 620                   _stub_function(nullptr),
 621                   _stub_name(nullptr),
 622                   _stub_entry_point(nullptr),
 623                   _max_node_limit(MaxNodeLimit),
 624                   _post_loop_opts_phase(false),
 625                   _inlining_progress(false),
 626                   _inlining_incrementally(false),
 627                   _do_cleanup(false),
 628                   _has_reserved_stack_access(target->has_reserved_stack_access()),
 629 #ifndef PRODUCT
 630                   _igv_idx(0),
 631                   _trace_opto_output(directive->TraceOptoOutputOption),
 632 #endif
 633                   _has_method_handle_invokes(false),
 634                   _clinit_barrier_on_entry(false),

 635                   _stress_seed(0),
 636                   _comp_arena(mtCompiler),
 637                   _barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())),
 638                   _env(ci_env),
 639                   _directive(directive),
 640                   _log(ci_env->log()),
 641                   _failure_reason(nullptr),
 642                   _first_failure_details(nullptr),
 643                   _intrinsics        (comp_arena(), 0, 0, nullptr),
 644                   _macro_nodes       (comp_arena(), 8, 0, nullptr),
 645                   _parse_predicates  (comp_arena(), 8, 0, nullptr),
 646                   _template_assertion_predicate_opaqs (comp_arena(), 8, 0, nullptr),
 647                   _expensive_nodes   (comp_arena(), 8, 0, nullptr),
 648                   _for_post_loop_igvn(comp_arena(), 8, 0, nullptr),
 649                   _unstable_if_traps (comp_arena(), 8, 0, nullptr),
 650                   _coarsened_locks   (comp_arena(), 8, 0, nullptr),
 651                   _congraph(nullptr),
 652                   NOT_PRODUCT(_igv_printer(nullptr) COMMA)
 653                   _unique(0),
 654                   _dead_node_count(0),

 906                   DirectiveSet* directive)
 907   : Phase(Compiler),
 908     _compile_id(0),
 909     _options(Options::for_runtime_stub()),
 910     _method(nullptr),
 911     _entry_bci(InvocationEntryBci),
 912     _stub_function(stub_function),
 913     _stub_name(stub_name),
 914     _stub_entry_point(nullptr),
 915     _max_node_limit(MaxNodeLimit),
 916     _post_loop_opts_phase(false),
 917     _inlining_progress(false),
 918     _inlining_incrementally(false),
 919     _has_reserved_stack_access(false),
 920 #ifndef PRODUCT
 921     _igv_idx(0),
 922     _trace_opto_output(directive->TraceOptoOutputOption),
 923 #endif
 924     _has_method_handle_invokes(false),
 925     _clinit_barrier_on_entry(false),

 926     _stress_seed(0),
 927     _comp_arena(mtCompiler),
 928     _barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())),
 929     _env(ci_env),
 930     _directive(directive),
 931     _log(ci_env->log()),
 932     _failure_reason(nullptr),
 933     _first_failure_details(nullptr),
 934     _congraph(nullptr),
 935     NOT_PRODUCT(_igv_printer(nullptr) COMMA)
 936     _unique(0),
 937     _dead_node_count(0),
 938     _dead_node_list(comp_arena()),
 939     _node_arena_one(mtCompiler),
 940     _node_arena_two(mtCompiler),
 941     _node_arena(&_node_arena_one),
 942     _mach_constant_base_node(nullptr),
 943     _Compile_types(mtCompiler),
 944     _initial_gvn(nullptr),
 945     _igvn_worklist(nullptr),

1079 
1080   set_rtm_state(NoRTM); // No RTM lock eliding by default
1081   _max_node_limit = _directive->MaxNodeLimitOption;
1082 
1083 #if INCLUDE_RTM_OPT
1084   if (UseRTMLocking && has_method() && (method()->method_data_or_null() != nullptr)) {
1085     int rtm_state = method()->method_data()->rtm_state();
1086     if (method_has_option(CompileCommand::NoRTMLockEliding) || ((rtm_state & NoRTM) != 0)) {
1087       // Don't generate RTM lock eliding code.
1088       set_rtm_state(NoRTM);
1089     } else if (method_has_option(CompileCommand::UseRTMLockEliding) || ((rtm_state & UseRTM) != 0) || !UseRTMDeopt) {
1090       // Generate RTM lock eliding code without abort ratio calculation code.
1091       set_rtm_state(UseRTM);
1092     } else if (UseRTMDeopt) {
1093       // Generate RTM lock eliding code and include abort ratio calculation
1094       // code if UseRTMDeopt is on.
1095       set_rtm_state(ProfileRTM);
1096     }
1097   }
1098 #endif
1099   if (VM_Version::supports_fast_class_init_checks() && has_method() && !is_osr_compilation() && method()->needs_clinit_barrier()) {

1100     set_clinit_barrier_on_entry(true);



1101   }
1102   if (debug_info()->recording_non_safepoints()) {
1103     set_node_note_array(new(comp_arena()) GrowableArray<Node_Notes*>
1104                         (comp_arena(), 8, 0, nullptr));
1105     set_default_node_notes(Node_Notes::make(this));
1106   }
1107 
1108   const int grow_ats = 16;
1109   _max_alias_types = grow_ats;
1110   _alias_types   = NEW_ARENA_ARRAY(comp_arena(), AliasType*, grow_ats);
1111   AliasType* ats = NEW_ARENA_ARRAY(comp_arena(), AliasType,  grow_ats);
1112   Copy::zero_to_bytes(ats, sizeof(AliasType)*grow_ats);
1113   {
1114     for (int i = 0; i < grow_ats; i++)  _alias_types[i] = &ats[i];
1115   }
1116   // Initialize the first few types.
1117   _alias_types[AliasIdxTop]->Init(AliasIdxTop, nullptr);
1118   _alias_types[AliasIdxBot]->Init(AliasIdxBot, TypePtr::BOTTOM);
1119   _alias_types[AliasIdxRaw]->Init(AliasIdxRaw, TypeRawPtr::BOTTOM);
1120   _num_alias_types = AliasIdxRaw+1;

4128       frc.get_float_count() > 32 &&
4129       frc.get_double_count() == 0 &&
4130       (10 * frc.get_call_count() < frc.get_float_count()) ) {
4131     set_24_bit_selection_and_mode(false, true);
4132   }
4133 #endif // IA32
4134 
4135   set_java_calls(frc.get_java_call_count());
4136   set_inner_loops(frc.get_inner_loop_count());
4137 
4138   // No infinite loops, no reason to bail out.
4139   return false;
4140 }
4141 
4142 //-----------------------------too_many_traps----------------------------------
4143 // Report if there are too many traps at the current method and bci.
4144 // Return true if there was a trap, and/or PerMethodTrapLimit is exceeded.
4145 bool Compile::too_many_traps(ciMethod* method,
4146                              int bci,
4147                              Deoptimization::DeoptReason reason) {



4148   ciMethodData* md = method->method_data();
4149   if (md->is_empty()) {
4150     // Assume the trap has not occurred, or that it occurred only
4151     // because of a transient condition during start-up in the interpreter.
4152     return false;
4153   }
4154   ciMethod* m = Deoptimization::reason_is_speculate(reason) ? this->method() : nullptr;
4155   if (md->has_trap_at(bci, m, reason) != 0) {
4156     // Assume PerBytecodeTrapLimit==0, for a more conservative heuristic.
4157     // Also, if there are multiple reasons, or if there is no per-BCI record,
4158     // assume the worst.
4159     if (log())
4160       log()->elem("observe trap='%s' count='%d'",
4161                   Deoptimization::trap_reason_name(reason),
4162                   md->trap_count(reason));
4163     return true;
4164   } else {
4165     // Ignore method/bci and see if there have been too many globally.
4166     return too_many_traps(reason, md);
4167   }

4242   _allowed_reasons = 0;
4243   if (is_method_compilation()) {
4244     for (int rs = (int)Deoptimization::Reason_none+1; rs < Compile::trapHistLength; rs++) {
4245       assert(rs < BitsPerInt, "recode bit map");
4246       if (!too_many_traps((Deoptimization::DeoptReason) rs)) {
4247         _allowed_reasons |= nth_bit(rs);
4248       }
4249     }
4250   }
4251 }
4252 
4253 bool Compile::needs_clinit_barrier(ciMethod* method, ciMethod* accessing_method) {
4254   return method->is_static() && needs_clinit_barrier(method->holder(), accessing_method);
4255 }
4256 
4257 bool Compile::needs_clinit_barrier(ciField* field, ciMethod* accessing_method) {
4258   return field->is_static() && needs_clinit_barrier(field->holder(), accessing_method);
4259 }
4260 
4261 bool Compile::needs_clinit_barrier(ciInstanceKlass* holder, ciMethod* accessing_method) {
4262   if (holder->is_initialized()) {
4263     return false;
4264   }
4265   if (holder->is_being_initialized()) {
4266     if (accessing_method->holder() == holder) {
4267       // Access inside a class. The barrier can be elided when access happens in <clinit>,
4268       // <init>, or a static method. In all those cases, there was an initialization
4269       // barrier on the holder klass passed.
4270       if (accessing_method->is_static_initializer() ||
4271           accessing_method->is_object_initializer() ||
4272           accessing_method->is_static()) {
4273         return false;
4274       }
4275     } else if (accessing_method->holder()->is_subclass_of(holder)) {
4276       // Access from a subclass. The barrier can be elided only when access happens in <clinit>.
4277       // In case of <init> or a static method, the barrier is on the subclass is not enough:
4278       // child class can become fully initialized while its parent class is still being initialized.
4279       if (accessing_method->is_static_initializer()) {
4280         return false;
4281       }
4282     }
4283     ciMethod* root = method(); // the root method of compilation
4284     if (root != accessing_method) {
4285       return needs_clinit_barrier(holder, root); // check access in the context of compilation root

4628     // Reset _print_inlining_list, it only contains destructed objects.
4629     // It is on the arena, so it will be freed when the arena is reset.
4630     _print_inlining_list = nullptr;
4631     // _print_inlining_stream won't be used anymore, either.
4632     print_inlining_reset();
4633     size_t end = ss.size();
4634     _print_inlining_output = NEW_ARENA_ARRAY(comp_arena(), char, end+1);
4635     strncpy(_print_inlining_output, ss.freeze(), end+1);
4636     _print_inlining_output[end] = 0;
4637   }
4638 }
4639 
4640 void Compile::dump_print_inlining() {
4641   if (_print_inlining_output != nullptr) {
4642     tty->print_raw(_print_inlining_output);
4643   }
4644 }
4645 
4646 void Compile::log_late_inline(CallGenerator* cg) {
4647   if (log() != nullptr) {
4648     log()->head("late_inline method='%d'  inline_id='" JLONG_FORMAT "'", log()->identify(cg->method()),
4649                 cg->unique_id());
4650     JVMState* p = cg->call_node()->jvms();
4651     while (p != nullptr) {
4652       log()->elem("jvms bci='%d' method='%d'", p->bci(), log()->identify(p->method()));
4653       p = p->caller();
4654     }
4655     log()->tail("late_inline");
4656   }
4657 }
4658 
4659 void Compile::log_late_inline_failure(CallGenerator* cg, const char* msg) {
4660   log_late_inline(cg);
4661   if (log() != nullptr) {
4662     log()->inline_fail(msg);
4663   }
4664 }
4665 
4666 void Compile::log_inline_id(CallGenerator* cg) {
4667   if (log() != nullptr) {
4668     // The LogCompilation tool needs a unique way to identify late

 615                   _compile_id(ci_env->compile_id()),
 616                   _options(options),
 617                   _method(target),
 618                   _entry_bci(osr_bci),
 619                   _ilt(nullptr),
 620                   _stub_function(nullptr),
 621                   _stub_name(nullptr),
 622                   _stub_entry_point(nullptr),
 623                   _max_node_limit(MaxNodeLimit),
 624                   _post_loop_opts_phase(false),
 625                   _inlining_progress(false),
 626                   _inlining_incrementally(false),
 627                   _do_cleanup(false),
 628                   _has_reserved_stack_access(target->has_reserved_stack_access()),
 629 #ifndef PRODUCT
 630                   _igv_idx(0),
 631                   _trace_opto_output(directive->TraceOptoOutputOption),
 632 #endif
 633                   _has_method_handle_invokes(false),
 634                   _clinit_barrier_on_entry(false),
 635                   _has_clinit_barriers(false),
 636                   _stress_seed(0),
 637                   _comp_arena(mtCompiler),
 638                   _barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())),
 639                   _env(ci_env),
 640                   _directive(directive),
 641                   _log(ci_env->log()),
 642                   _failure_reason(nullptr),
 643                   _first_failure_details(nullptr),
 644                   _intrinsics        (comp_arena(), 0, 0, nullptr),
 645                   _macro_nodes       (comp_arena(), 8, 0, nullptr),
 646                   _parse_predicates  (comp_arena(), 8, 0, nullptr),
 647                   _template_assertion_predicate_opaqs (comp_arena(), 8, 0, nullptr),
 648                   _expensive_nodes   (comp_arena(), 8, 0, nullptr),
 649                   _for_post_loop_igvn(comp_arena(), 8, 0, nullptr),
 650                   _unstable_if_traps (comp_arena(), 8, 0, nullptr),
 651                   _coarsened_locks   (comp_arena(), 8, 0, nullptr),
 652                   _congraph(nullptr),
 653                   NOT_PRODUCT(_igv_printer(nullptr) COMMA)
 654                   _unique(0),
 655                   _dead_node_count(0),

 907                   DirectiveSet* directive)
 908   : Phase(Compiler),
 909     _compile_id(0),
 910     _options(Options::for_runtime_stub()),
 911     _method(nullptr),
 912     _entry_bci(InvocationEntryBci),
 913     _stub_function(stub_function),
 914     _stub_name(stub_name),
 915     _stub_entry_point(nullptr),
 916     _max_node_limit(MaxNodeLimit),
 917     _post_loop_opts_phase(false),
 918     _inlining_progress(false),
 919     _inlining_incrementally(false),
 920     _has_reserved_stack_access(false),
 921 #ifndef PRODUCT
 922     _igv_idx(0),
 923     _trace_opto_output(directive->TraceOptoOutputOption),
 924 #endif
 925     _has_method_handle_invokes(false),
 926     _clinit_barrier_on_entry(false),
 927     _has_clinit_barriers(false),
 928     _stress_seed(0),
 929     _comp_arena(mtCompiler),
 930     _barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())),
 931     _env(ci_env),
 932     _directive(directive),
 933     _log(ci_env->log()),
 934     _failure_reason(nullptr),
 935     _first_failure_details(nullptr),
 936     _congraph(nullptr),
 937     NOT_PRODUCT(_igv_printer(nullptr) COMMA)
 938     _unique(0),
 939     _dead_node_count(0),
 940     _dead_node_list(comp_arena()),
 941     _node_arena_one(mtCompiler),
 942     _node_arena_two(mtCompiler),
 943     _node_arena(&_node_arena_one),
 944     _mach_constant_base_node(nullptr),
 945     _Compile_types(mtCompiler),
 946     _initial_gvn(nullptr),
 947     _igvn_worklist(nullptr),

1081 
1082   set_rtm_state(NoRTM); // No RTM lock eliding by default
1083   _max_node_limit = _directive->MaxNodeLimitOption;
1084 
1085 #if INCLUDE_RTM_OPT
1086   if (UseRTMLocking && has_method() && (method()->method_data_or_null() != nullptr)) {
1087     int rtm_state = method()->method_data()->rtm_state();
1088     if (method_has_option(CompileCommand::NoRTMLockEliding) || ((rtm_state & NoRTM) != 0)) {
1089       // Don't generate RTM lock eliding code.
1090       set_rtm_state(NoRTM);
1091     } else if (method_has_option(CompileCommand::UseRTMLockEliding) || ((rtm_state & UseRTM) != 0) || !UseRTMDeopt) {
1092       // Generate RTM lock eliding code without abort ratio calculation code.
1093       set_rtm_state(UseRTM);
1094     } else if (UseRTMDeopt) {
1095       // Generate RTM lock eliding code and include abort ratio calculation
1096       // code if UseRTMDeopt is on.
1097       set_rtm_state(ProfileRTM);
1098     }
1099   }
1100 #endif
1101   if (VM_Version::supports_fast_class_init_checks() && has_method() && !is_osr_compilation() &&
1102       (method()->needs_clinit_barrier() || (do_clinit_barriers() && method()->is_static()))) {
1103     set_clinit_barrier_on_entry(true);
1104     if (do_clinit_barriers()) {
1105       set_has_clinit_barriers(true); // Entry clinit barrier is in prolog code.
1106     }
1107   }
1108   if (debug_info()->recording_non_safepoints()) {
1109     set_node_note_array(new(comp_arena()) GrowableArray<Node_Notes*>
1110                         (comp_arena(), 8, 0, nullptr));
1111     set_default_node_notes(Node_Notes::make(this));
1112   }
1113 
1114   const int grow_ats = 16;
1115   _max_alias_types = grow_ats;
1116   _alias_types   = NEW_ARENA_ARRAY(comp_arena(), AliasType*, grow_ats);
1117   AliasType* ats = NEW_ARENA_ARRAY(comp_arena(), AliasType,  grow_ats);
1118   Copy::zero_to_bytes(ats, sizeof(AliasType)*grow_ats);
1119   {
1120     for (int i = 0; i < grow_ats; i++)  _alias_types[i] = &ats[i];
1121   }
1122   // Initialize the first few types.
1123   _alias_types[AliasIdxTop]->Init(AliasIdxTop, nullptr);
1124   _alias_types[AliasIdxBot]->Init(AliasIdxBot, TypePtr::BOTTOM);
1125   _alias_types[AliasIdxRaw]->Init(AliasIdxRaw, TypeRawPtr::BOTTOM);
1126   _num_alias_types = AliasIdxRaw+1;

4134       frc.get_float_count() > 32 &&
4135       frc.get_double_count() == 0 &&
4136       (10 * frc.get_call_count() < frc.get_float_count()) ) {
4137     set_24_bit_selection_and_mode(false, true);
4138   }
4139 #endif // IA32
4140 
4141   set_java_calls(frc.get_java_call_count());
4142   set_inner_loops(frc.get_inner_loop_count());
4143 
4144   // No infinite loops, no reason to bail out.
4145   return false;
4146 }
4147 
4148 //-----------------------------too_many_traps----------------------------------
4149 // Report if there are too many traps at the current method and bci.
4150 // Return true if there was a trap, and/or PerMethodTrapLimit is exceeded.
4151 bool Compile::too_many_traps(ciMethod* method,
4152                              int bci,
4153                              Deoptimization::DeoptReason reason) {
4154   if (method->has_trap_at(bci)) {
4155     return true;
4156   }
4157   ciMethodData* md = method->method_data();
4158   if (md->is_empty()) {
4159     // Assume the trap has not occurred, or that it occurred only
4160     // because of a transient condition during start-up in the interpreter.
4161     return false;
4162   }
4163   ciMethod* m = Deoptimization::reason_is_speculate(reason) ? this->method() : nullptr;
4164   if (md->has_trap_at(bci, m, reason) != 0) {
4165     // Assume PerBytecodeTrapLimit==0, for a more conservative heuristic.
4166     // Also, if there are multiple reasons, or if there is no per-BCI record,
4167     // assume the worst.
4168     if (log())
4169       log()->elem("observe trap='%s' count='%d'",
4170                   Deoptimization::trap_reason_name(reason),
4171                   md->trap_count(reason));
4172     return true;
4173   } else {
4174     // Ignore method/bci and see if there have been too many globally.
4175     return too_many_traps(reason, md);
4176   }

4251   _allowed_reasons = 0;
4252   if (is_method_compilation()) {
4253     for (int rs = (int)Deoptimization::Reason_none+1; rs < Compile::trapHistLength; rs++) {
4254       assert(rs < BitsPerInt, "recode bit map");
4255       if (!too_many_traps((Deoptimization::DeoptReason) rs)) {
4256         _allowed_reasons |= nth_bit(rs);
4257       }
4258     }
4259   }
4260 }
4261 
4262 bool Compile::needs_clinit_barrier(ciMethod* method, ciMethod* accessing_method) {
4263   return method->is_static() && needs_clinit_barrier(method->holder(), accessing_method);
4264 }
4265 
4266 bool Compile::needs_clinit_barrier(ciField* field, ciMethod* accessing_method) {
4267   return field->is_static() && needs_clinit_barrier(field->holder(), accessing_method);
4268 }
4269 
4270 bool Compile::needs_clinit_barrier(ciInstanceKlass* holder, ciMethod* accessing_method) {
4271   if (holder->is_initialized() && !do_clinit_barriers()) {
4272     return false;
4273   }
4274   if (holder->is_being_initialized() || do_clinit_barriers()) {
4275     if (accessing_method->holder() == holder) {
4276       // Access inside a class. The barrier can be elided when access happens in <clinit>,
4277       // <init>, or a static method. In all those cases, there was an initialization
4278       // barrier on the holder klass passed.
4279       if (accessing_method->is_static_initializer() ||
4280           accessing_method->is_object_initializer() ||
4281           accessing_method->is_static()) {
4282         return false;
4283       }
4284     } else if (accessing_method->holder()->is_subclass_of(holder)) {
4285       // Access from a subclass. The barrier can be elided only when access happens in <clinit>.
4286       // In case of <init> or a static method, the barrier is on the subclass is not enough:
4287       // child class can become fully initialized while its parent class is still being initialized.
4288       if (accessing_method->is_static_initializer()) {
4289         return false;
4290       }
4291     }
4292     ciMethod* root = method(); // the root method of compilation
4293     if (root != accessing_method) {
4294       return needs_clinit_barrier(holder, root); // check access in the context of compilation root

4637     // Reset _print_inlining_list, it only contains destructed objects.
4638     // It is on the arena, so it will be freed when the arena is reset.
4639     _print_inlining_list = nullptr;
4640     // _print_inlining_stream won't be used anymore, either.
4641     print_inlining_reset();
4642     size_t end = ss.size();
4643     _print_inlining_output = NEW_ARENA_ARRAY(comp_arena(), char, end+1);
4644     strncpy(_print_inlining_output, ss.freeze(), end+1);
4645     _print_inlining_output[end] = 0;
4646   }
4647 }
4648 
4649 void Compile::dump_print_inlining() {
4650   if (_print_inlining_output != nullptr) {
4651     tty->print_raw(_print_inlining_output);
4652   }
4653 }
4654 
4655 void Compile::log_late_inline(CallGenerator* cg) {
4656   if (log() != nullptr) {
4657     log()->head("late_inline method='%d' inline_id='" JLONG_FORMAT "'", log()->identify(cg->method()),
4658                 cg->unique_id());
4659     JVMState* p = cg->call_node()->jvms();
4660     while (p != nullptr) {
4661       log()->elem("jvms bci='%d' method='%d'", p->bci(), log()->identify(p->method()));
4662       p = p->caller();
4663     }
4664     log()->tail("late_inline");
4665   }
4666 }
4667 
4668 void Compile::log_late_inline_failure(CallGenerator* cg, const char* msg) {
4669   log_late_inline(cg);
4670   if (log() != nullptr) {
4671     log()->inline_fail(msg);
4672   }
4673 }
4674 
4675 void Compile::log_inline_id(CallGenerator* cg) {
4676   if (log() != nullptr) {
4677     // The LogCompilation tool needs a unique way to identify late
< prev index next >