< prev index next >

src/hotspot/share/opto/compile.cpp

Print this page

 551     tty->print_cr("*********************************************************");
 552     tty->print_cr("** Bailout: Recompile without boxing elimination       **");
 553     tty->print_cr("*********************************************************");
 554   }
 555   if ((do_locks_coarsening() != EliminateLocks) && PrintOpto) {
 556     // Recompiling without locks coarsening
 557     tty->print_cr("*********************************************************");
 558     tty->print_cr("** Bailout: Recompile without locks coarsening         **");
 559     tty->print_cr("*********************************************************");
 560   }
 561   if (env()->break_at_compile()) {
 562     // Open the debugger when compiling this method.
 563     tty->print("### Breaking when compiling: ");
 564     method()->print_short_name();
 565     tty->cr();
 566     BREAKPOINT;
 567   }
 568 
 569   if( PrintOpto ) {
 570     if (is_osr_compilation()) {
 571       tty->print("[OSR]%3d", _compile_id);
 572     } else {
 573       tty->print("%3d", _compile_id);




 574     }

 575   }
 576 #endif
 577 }
 578 
 579 #ifndef PRODUCT
 580 void Compile::print_phase(const char* phase_name) {
 581   tty->print_cr("%u.\t%s", ++_phase_counter, phase_name);
 582 }
 583 
 584 void Compile::print_ideal_ir(const char* phase_name) {
 585   // keep the following output all in one block
 586   // This output goes directly to the tty, not the compiler log.
 587   // To enable tools to match it up with the compilation activity,
 588   // be sure to tag this tty output with the compile ID.
 589 
 590   // Node dumping can cause a safepoint, which can break the tty lock.
 591   // Buffer all node dumps, so that all safepoints happen before we lock.
 592   ResourceMark rm;
 593   stringStream ss;
 594 
 595   if (_output == nullptr) {
 596     ss.print_cr("AFTER: %s", phase_name);
 597     // Print out all nodes in ascending order of index.
 598     root()->dump_bfs(MaxNodeLimit, nullptr, "+S$", &ss);
 599   } else {
 600     // Dump the node blockwise if we have a scheduling
 601     _output->print_scheduling(&ss);
 602   }
 603 
 604   // Check that the lock is not broken by a safepoint.
 605   NoSafepointVerifier nsv;
 606   ttyLocker ttyl;
 607   if (xtty != nullptr) {
 608     xtty->head("ideal compile_id='%d'%s compile_phase='%s'",
 609                compile_id(),
 610                is_osr_compilation() ? " compile_kind='osr'" : "",

 611                phase_name);
 612   }
 613 
 614   tty->print("%s", ss.as_string());
 615 
 616   if (xtty != nullptr) {
 617     xtty->tail("ideal");
 618   }
 619 }
 620 #endif
 621 
 622 // ============================================================================
 623 //------------------------------Compile standard-------------------------------
 624 
 625 // Compile a method.  entry_bci is -1 for normal compilations and indicates
 626 // the continuation bci for on stack replacement.
 627 
 628 
 629 Compile::Compile(ciEnv* ci_env, ciMethod* target, int osr_bci,
 630                  Options options, DirectiveSet* directive)

 635       _entry_bci(osr_bci),
 636       _ilt(nullptr),
 637       _stub_function(nullptr),
 638       _stub_name(nullptr),
 639       _stub_id(StubId::NO_STUBID),
 640       _stub_entry_point(nullptr),
 641       _max_node_limit(MaxNodeLimit),
 642       _post_loop_opts_phase(false),
 643       _merge_stores_phase(false),
 644       _allow_macro_nodes(true),
 645       _inlining_progress(false),
 646       _inlining_incrementally(false),
 647       _do_cleanup(false),
 648       _has_reserved_stack_access(target->has_reserved_stack_access()),
 649 #ifndef PRODUCT
 650       _igv_idx(0),
 651       _trace_opto_output(directive->TraceOptoOutputOption),
 652 #endif
 653       _has_method_handle_invokes(false),
 654       _clinit_barrier_on_entry(false),

 655       _stress_seed(0),
 656       _comp_arena(mtCompiler, Arena::Tag::tag_comp),
 657       _barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())),
 658       _env(ci_env),
 659       _directive(directive),
 660       _log(ci_env->log()),
 661       _first_failure_details(nullptr),
 662       _intrinsics(comp_arena(), 0, 0, nullptr),
 663       _macro_nodes(comp_arena(), 8, 0, nullptr),
 664       _parse_predicates(comp_arena(), 8, 0, nullptr),
 665       _template_assertion_predicate_opaques(comp_arena(), 8, 0, nullptr),
 666       _expensive_nodes(comp_arena(), 8, 0, nullptr),
 667       _for_post_loop_igvn(comp_arena(), 8, 0, nullptr),
 668       _for_merge_stores_igvn(comp_arena(), 8, 0, nullptr),
 669       _unstable_if_traps(comp_arena(), 8, 0, nullptr),
 670       _coarsened_locks(comp_arena(), 8, 0, nullptr),
 671       _congraph(nullptr),
 672       NOT_PRODUCT(_igv_printer(nullptr) COMMA)
 673           _unique(0),
 674       _dead_node_count(0),

 908       _options(Options::for_runtime_stub()),
 909       _method(nullptr),
 910       _entry_bci(InvocationEntryBci),
 911       _stub_function(stub_function),
 912       _stub_name(stub_name),
 913       _stub_id(stub_id),
 914       _stub_entry_point(nullptr),
 915       _max_node_limit(MaxNodeLimit),
 916       _post_loop_opts_phase(false),
 917       _merge_stores_phase(false),
 918       _allow_macro_nodes(true),
 919       _inlining_progress(false),
 920       _inlining_incrementally(false),
 921       _has_reserved_stack_access(false),
 922 #ifndef PRODUCT
 923       _igv_idx(0),
 924       _trace_opto_output(directive->TraceOptoOutputOption),
 925 #endif
 926       _has_method_handle_invokes(false),
 927       _clinit_barrier_on_entry(false),

 928       _stress_seed(0),
 929       _comp_arena(mtCompiler, Arena::Tag::tag_comp),
 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       _first_failure_details(nullptr),
 935       _for_post_loop_igvn(comp_arena(), 8, 0, nullptr),
 936       _for_merge_stores_igvn(comp_arena(), 8, 0, nullptr),
 937       _congraph(nullptr),
 938       NOT_PRODUCT(_igv_printer(nullptr) COMMA)
 939           _unique(0),
 940       _dead_node_count(0),
 941       _dead_node_list(comp_arena()),
 942       _node_arena_one(mtCompiler, Arena::Tag::tag_node),
 943       _node_arena_two(mtCompiler, Arena::Tag::tag_node),
 944       _node_arena(&_node_arena_one),
 945       _mach_constant_base_node(nullptr),
 946       _Compile_types(mtCompiler, Arena::Tag::tag_type),
 947       _initial_gvn(nullptr),

1078   set_do_scheduling(OptoScheduling);
1079 
1080   set_do_vector_loop(false);
1081   set_has_monitors(false);
1082   set_has_scoped_access(false);
1083 
1084   if (AllowVectorizeOnDemand) {
1085     if (has_method() && _directive->VectorizeOption) {
1086       set_do_vector_loop(true);
1087       NOT_PRODUCT(if (do_vector_loop() && Verbose) {tty->print("Compile::Init: do vectorized loops (SIMD like) for method %s\n",  method()->name()->as_quoted_ascii());})
1088     } else if (has_method() && method()->name() != nullptr &&
1089                method()->intrinsic_id() == vmIntrinsics::_forEachRemaining) {
1090       set_do_vector_loop(true);
1091     }
1092   }
1093   set_use_cmove(UseCMoveUnconditionally /* || do_vector_loop()*/); //TODO: consider do_vector_loop() mandate use_cmove unconditionally
1094   NOT_PRODUCT(if (use_cmove() && Verbose && has_method()) {tty->print("Compile::Init: use CMove without profitability tests for method %s\n",  method()->name()->as_quoted_ascii());})
1095 
1096   _max_node_limit = _directive->MaxNodeLimitOption;
1097 
1098   if (VM_Version::supports_fast_class_init_checks() && has_method() && !is_osr_compilation() && method()->needs_clinit_barrier()) {

1099     set_clinit_barrier_on_entry(true);



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

4147           dead_nodes.push(in);
4148         }
4149       }
4150       m->disconnect_inputs(this);
4151     }
4152   }
4153 
4154   set_java_calls(frc.get_java_call_count());
4155   set_inner_loops(frc.get_inner_loop_count());
4156 
4157   // No infinite loops, no reason to bail out.
4158   return false;
4159 }
4160 
4161 //-----------------------------too_many_traps----------------------------------
4162 // Report if there are too many traps at the current method and bci.
4163 // Return true if there was a trap, and/or PerMethodTrapLimit is exceeded.
4164 bool Compile::too_many_traps(ciMethod* method,
4165                              int bci,
4166                              Deoptimization::DeoptReason reason) {







4167   ciMethodData* md = method->method_data();
4168   if (md->is_empty()) {
4169     // Assume the trap has not occurred, or that it occurred only
4170     // because of a transient condition during start-up in the interpreter.
4171     return false;
4172   }
4173   ciMethod* m = Deoptimization::reason_is_speculate(reason) ? this->method() : nullptr;
4174   if (md->has_trap_at(bci, m, reason) != 0) {
4175     // Assume PerBytecodeTrapLimit==0, for a more conservative heuristic.
4176     // Also, if there are multiple reasons, or if there is no per-BCI record,
4177     // assume the worst.
4178     if (log())
4179       log()->elem("observe trap='%s' count='%d'",
4180                   Deoptimization::trap_reason_name(reason),
4181                   md->trap_count(reason));
4182     return true;
4183   } else {
4184     // Ignore method/bci and see if there have been too many globally.
4185     return too_many_traps(reason, md);
4186   }
4187 }
4188 
4189 // Less-accurate variant which does not require a method and bci.
4190 bool Compile::too_many_traps(Deoptimization::DeoptReason reason,
4191                              ciMethodData* logmd) {




4192   if (trap_count(reason) >= Deoptimization::per_method_trap_limit(reason)) {
4193     // Too many traps globally.
4194     // Note that we use cumulative trap_count, not just md->trap_count.
4195     if (log()) {
4196       int mcount = (logmd == nullptr)? -1: (int)logmd->trap_count(reason);
4197       log()->elem("observe trap='%s' count='0' mcount='%d' ccount='%d'",
4198                   Deoptimization::trap_reason_name(reason),
4199                   mcount, trap_count(reason));
4200     }
4201     return true;
4202   } else {
4203     // The coast is clear.
4204     return false;
4205   }
4206 }
4207 
4208 //--------------------------too_many_recompiles--------------------------------
4209 // Report if there are too many recompiles at the current method and bci.
4210 // Consults PerBytecodeRecompilationCutoff and PerMethodRecompilationCutoff.
4211 // Is not eager to return true, since this will cause the compiler to use

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

 551     tty->print_cr("*********************************************************");
 552     tty->print_cr("** Bailout: Recompile without boxing elimination       **");
 553     tty->print_cr("*********************************************************");
 554   }
 555   if ((do_locks_coarsening() != EliminateLocks) && PrintOpto) {
 556     // Recompiling without locks coarsening
 557     tty->print_cr("*********************************************************");
 558     tty->print_cr("** Bailout: Recompile without locks coarsening         **");
 559     tty->print_cr("*********************************************************");
 560   }
 561   if (env()->break_at_compile()) {
 562     // Open the debugger when compiling this method.
 563     tty->print("### Breaking when compiling: ");
 564     method()->print_short_name();
 565     tty->cr();
 566     BREAKPOINT;
 567   }
 568 
 569   if( PrintOpto ) {
 570     if (is_osr_compilation()) {
 571       tty->print("[OSR]");
 572     } else if (env()->task()->is_precompile()) {
 573       if (for_preload()) {
 574         tty->print("[PRE]");
 575       } else {
 576         tty->print("[AOT]");
 577       }
 578     }
 579     tty->print("%3d", _compile_id);
 580   }
 581 #endif
 582 }
 583 
 584 #ifndef PRODUCT
 585 void Compile::print_phase(const char* phase_name) {
 586   tty->print_cr("%u.\t%s", ++_phase_counter, phase_name);
 587 }
 588 
 589 void Compile::print_ideal_ir(const char* phase_name) {
 590   // keep the following output all in one block
 591   // This output goes directly to the tty, not the compiler log.
 592   // To enable tools to match it up with the compilation activity,
 593   // be sure to tag this tty output with the compile ID.
 594 
 595   // Node dumping can cause a safepoint, which can break the tty lock.
 596   // Buffer all node dumps, so that all safepoints happen before we lock.
 597   ResourceMark rm;
 598   stringStream ss;
 599 
 600   if (_output == nullptr) {
 601     ss.print_cr("AFTER: %s", phase_name);
 602     // Print out all nodes in ascending order of index.
 603     root()->dump_bfs(MaxNodeLimit, nullptr, "+S$", &ss);
 604   } else {
 605     // Dump the node blockwise if we have a scheduling
 606     _output->print_scheduling(&ss);
 607   }
 608 
 609   // Check that the lock is not broken by a safepoint.
 610   NoSafepointVerifier nsv;
 611   ttyLocker ttyl;
 612   if (xtty != nullptr) {
 613     xtty->head("ideal compile_id='%d'%s compile_phase='%s'",
 614                compile_id(),
 615                is_osr_compilation() ? " compile_kind='osr'" :
 616                (for_preload() ? " compile_kind='AP'" : ""),
 617                phase_name);
 618   }
 619 
 620   tty->print("%s", ss.as_string());
 621 
 622   if (xtty != nullptr) {
 623     xtty->tail("ideal");
 624   }
 625 }
 626 #endif
 627 
 628 // ============================================================================
 629 //------------------------------Compile standard-------------------------------
 630 
 631 // Compile a method.  entry_bci is -1 for normal compilations and indicates
 632 // the continuation bci for on stack replacement.
 633 
 634 
 635 Compile::Compile(ciEnv* ci_env, ciMethod* target, int osr_bci,
 636                  Options options, DirectiveSet* directive)

 641       _entry_bci(osr_bci),
 642       _ilt(nullptr),
 643       _stub_function(nullptr),
 644       _stub_name(nullptr),
 645       _stub_id(StubId::NO_STUBID),
 646       _stub_entry_point(nullptr),
 647       _max_node_limit(MaxNodeLimit),
 648       _post_loop_opts_phase(false),
 649       _merge_stores_phase(false),
 650       _allow_macro_nodes(true),
 651       _inlining_progress(false),
 652       _inlining_incrementally(false),
 653       _do_cleanup(false),
 654       _has_reserved_stack_access(target->has_reserved_stack_access()),
 655 #ifndef PRODUCT
 656       _igv_idx(0),
 657       _trace_opto_output(directive->TraceOptoOutputOption),
 658 #endif
 659       _has_method_handle_invokes(false),
 660       _clinit_barrier_on_entry(false),
 661       _has_clinit_barriers(false),
 662       _stress_seed(0),
 663       _comp_arena(mtCompiler, Arena::Tag::tag_comp),
 664       _barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())),
 665       _env(ci_env),
 666       _directive(directive),
 667       _log(ci_env->log()),
 668       _first_failure_details(nullptr),
 669       _intrinsics(comp_arena(), 0, 0, nullptr),
 670       _macro_nodes(comp_arena(), 8, 0, nullptr),
 671       _parse_predicates(comp_arena(), 8, 0, nullptr),
 672       _template_assertion_predicate_opaques(comp_arena(), 8, 0, nullptr),
 673       _expensive_nodes(comp_arena(), 8, 0, nullptr),
 674       _for_post_loop_igvn(comp_arena(), 8, 0, nullptr),
 675       _for_merge_stores_igvn(comp_arena(), 8, 0, nullptr),
 676       _unstable_if_traps(comp_arena(), 8, 0, nullptr),
 677       _coarsened_locks(comp_arena(), 8, 0, nullptr),
 678       _congraph(nullptr),
 679       NOT_PRODUCT(_igv_printer(nullptr) COMMA)
 680           _unique(0),
 681       _dead_node_count(0),

 915       _options(Options::for_runtime_stub()),
 916       _method(nullptr),
 917       _entry_bci(InvocationEntryBci),
 918       _stub_function(stub_function),
 919       _stub_name(stub_name),
 920       _stub_id(stub_id),
 921       _stub_entry_point(nullptr),
 922       _max_node_limit(MaxNodeLimit),
 923       _post_loop_opts_phase(false),
 924       _merge_stores_phase(false),
 925       _allow_macro_nodes(true),
 926       _inlining_progress(false),
 927       _inlining_incrementally(false),
 928       _has_reserved_stack_access(false),
 929 #ifndef PRODUCT
 930       _igv_idx(0),
 931       _trace_opto_output(directive->TraceOptoOutputOption),
 932 #endif
 933       _has_method_handle_invokes(false),
 934       _clinit_barrier_on_entry(false),
 935       _has_clinit_barriers(false),
 936       _stress_seed(0),
 937       _comp_arena(mtCompiler, Arena::Tag::tag_comp),
 938       _barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())),
 939       _env(ci_env),
 940       _directive(directive),
 941       _log(ci_env->log()),
 942       _first_failure_details(nullptr),
 943       _for_post_loop_igvn(comp_arena(), 8, 0, nullptr),
 944       _for_merge_stores_igvn(comp_arena(), 8, 0, nullptr),
 945       _congraph(nullptr),
 946       NOT_PRODUCT(_igv_printer(nullptr) COMMA)
 947           _unique(0),
 948       _dead_node_count(0),
 949       _dead_node_list(comp_arena()),
 950       _node_arena_one(mtCompiler, Arena::Tag::tag_node),
 951       _node_arena_two(mtCompiler, Arena::Tag::tag_node),
 952       _node_arena(&_node_arena_one),
 953       _mach_constant_base_node(nullptr),
 954       _Compile_types(mtCompiler, Arena::Tag::tag_type),
 955       _initial_gvn(nullptr),

1086   set_do_scheduling(OptoScheduling);
1087 
1088   set_do_vector_loop(false);
1089   set_has_monitors(false);
1090   set_has_scoped_access(false);
1091 
1092   if (AllowVectorizeOnDemand) {
1093     if (has_method() && _directive->VectorizeOption) {
1094       set_do_vector_loop(true);
1095       NOT_PRODUCT(if (do_vector_loop() && Verbose) {tty->print("Compile::Init: do vectorized loops (SIMD like) for method %s\n",  method()->name()->as_quoted_ascii());})
1096     } else if (has_method() && method()->name() != nullptr &&
1097                method()->intrinsic_id() == vmIntrinsics::_forEachRemaining) {
1098       set_do_vector_loop(true);
1099     }
1100   }
1101   set_use_cmove(UseCMoveUnconditionally /* || do_vector_loop()*/); //TODO: consider do_vector_loop() mandate use_cmove unconditionally
1102   NOT_PRODUCT(if (use_cmove() && Verbose && has_method()) {tty->print("Compile::Init: use CMove without profitability tests for method %s\n",  method()->name()->as_quoted_ascii());})
1103 
1104   _max_node_limit = _directive->MaxNodeLimitOption;
1105 
1106   if (VM_Version::supports_fast_class_init_checks() && has_method() && !is_osr_compilation() &&
1107       (method()->needs_clinit_barrier() || (do_clinit_barriers() && method()->is_static()))) {
1108     set_clinit_barrier_on_entry(true);
1109     if (do_clinit_barriers()) {
1110       set_has_clinit_barriers(true); // Entry clinit barrier is in prolog code.
1111     }
1112   }
1113   if (debug_info()->recording_non_safepoints()) {
1114     set_node_note_array(new(comp_arena()) GrowableArray<Node_Notes*>
1115                         (comp_arena(), 8, 0, nullptr));
1116     set_default_node_notes(Node_Notes::make(this));
1117   }
1118 
1119   const int grow_ats = 16;
1120   _max_alias_types = grow_ats;
1121   _alias_types   = NEW_ARENA_ARRAY(comp_arena(), AliasType*, grow_ats);
1122   AliasType* ats = NEW_ARENA_ARRAY(comp_arena(), AliasType,  grow_ats);
1123   Copy::zero_to_bytes(ats, sizeof(AliasType)*grow_ats);
1124   {
1125     for (int i = 0; i < grow_ats; i++)  _alias_types[i] = &ats[i];
1126   }
1127   // Initialize the first few types.
1128   _alias_types[AliasIdxTop]->Init(AliasIdxTop, nullptr);
1129   _alias_types[AliasIdxBot]->Init(AliasIdxBot, TypePtr::BOTTOM);
1130   _alias_types[AliasIdxRaw]->Init(AliasIdxRaw, TypeRawPtr::BOTTOM);
1131   _num_alias_types = AliasIdxRaw+1;

4159           dead_nodes.push(in);
4160         }
4161       }
4162       m->disconnect_inputs(this);
4163     }
4164   }
4165 
4166   set_java_calls(frc.get_java_call_count());
4167   set_inner_loops(frc.get_inner_loop_count());
4168 
4169   // No infinite loops, no reason to bail out.
4170   return false;
4171 }
4172 
4173 //-----------------------------too_many_traps----------------------------------
4174 // Report if there are too many traps at the current method and bci.
4175 // Return true if there was a trap, and/or PerMethodTrapLimit is exceeded.
4176 bool Compile::too_many_traps(ciMethod* method,
4177                              int bci,
4178                              Deoptimization::DeoptReason reason) {
4179   if (method->has_trap_at(bci)) {
4180     return true;
4181   }
4182   if (PreloadReduceTraps && for_preload()) {
4183     // Preload code should not have traps, if possible.
4184     return true;
4185   }
4186   ciMethodData* md = method->method_data();
4187   if (md->is_empty()) {
4188     // Assume the trap has not occurred, or that it occurred only
4189     // because of a transient condition during start-up in the interpreter.
4190     return false;
4191   }
4192   ciMethod* m = Deoptimization::reason_is_speculate(reason) ? this->method() : nullptr;
4193   if (md->has_trap_at(bci, m, reason) != 0) {
4194     // Assume PerBytecodeTrapLimit==0, for a more conservative heuristic.
4195     // Also, if there are multiple reasons, or if there is no per-BCI record,
4196     // assume the worst.
4197     if (log())
4198       log()->elem("observe trap='%s' count='%d'",
4199                   Deoptimization::trap_reason_name(reason),
4200                   md->trap_count(reason));
4201     return true;
4202   } else {
4203     // Ignore method/bci and see if there have been too many globally.
4204     return too_many_traps(reason, md);
4205   }
4206 }
4207 
4208 // Less-accurate variant which does not require a method and bci.
4209 bool Compile::too_many_traps(Deoptimization::DeoptReason reason,
4210                              ciMethodData* logmd) {
4211   if (PreloadReduceTraps && for_preload()) {
4212     // Preload code should not have traps, if possible.
4213     return true;
4214   }
4215   if (trap_count(reason) >= Deoptimization::per_method_trap_limit(reason)) {
4216     // Too many traps globally.
4217     // Note that we use cumulative trap_count, not just md->trap_count.
4218     if (log()) {
4219       int mcount = (logmd == nullptr)? -1: (int)logmd->trap_count(reason);
4220       log()->elem("observe trap='%s' count='0' mcount='%d' ccount='%d'",
4221                   Deoptimization::trap_reason_name(reason),
4222                   mcount, trap_count(reason));
4223     }
4224     return true;
4225   } else {
4226     // The coast is clear.
4227     return false;
4228   }
4229 }
4230 
4231 //--------------------------too_many_recompiles--------------------------------
4232 // Report if there are too many recompiles at the current method and bci.
4233 // Consults PerBytecodeRecompilationCutoff and PerMethodRecompilationCutoff.
4234 // Is not eager to return true, since this will cause the compiler to use

4284   _allowed_reasons = 0;
4285   if (is_method_compilation()) {
4286     for (int rs = (int)Deoptimization::Reason_none+1; rs < Compile::trapHistLength; rs++) {
4287       assert(rs < BitsPerInt, "recode bit map");
4288       if (!too_many_traps((Deoptimization::DeoptReason) rs)) {
4289         _allowed_reasons |= nth_bit(rs);
4290       }
4291     }
4292   }
4293 }
4294 
4295 bool Compile::needs_clinit_barrier(ciMethod* method, ciMethod* accessing_method) {
4296   return method->is_static() && needs_clinit_barrier(method->holder(), accessing_method);
4297 }
4298 
4299 bool Compile::needs_clinit_barrier(ciField* field, ciMethod* accessing_method) {
4300   return field->is_static() && needs_clinit_barrier(field->holder(), accessing_method);
4301 }
4302 
4303 bool Compile::needs_clinit_barrier(ciInstanceKlass* holder, ciMethod* accessing_method) {
4304   if (holder->is_initialized() && !do_clinit_barriers()) {
4305     return false;
4306   }
4307   if (holder->is_being_initialized() || do_clinit_barriers()) {
4308     if (accessing_method->holder() == holder) {
4309       // Access inside a class. The barrier can be elided when access happens in <clinit>,
4310       // <init>, or a static method. In all those cases, there was an initialization
4311       // barrier on the holder klass passed.
4312       if (accessing_method->is_static_initializer() ||
4313           accessing_method->is_object_initializer() ||
4314           accessing_method->is_static()) {
4315         return false;
4316       }
4317     } else if (accessing_method->holder()->is_subclass_of(holder)) {
4318       // Access from a subclass. The barrier can be elided only when access happens in <clinit>.
4319       // In case of <init> or a static method, the barrier is on the subclass is not enough:
4320       // child class can become fully initialized while its parent class is still being initialized.
4321       if (accessing_method->is_static_initializer()) {
4322         return false;
4323       }
4324     }
4325     ciMethod* root = method(); // the root method of compilation
4326     if (root != accessing_method) {
4327       return needs_clinit_barrier(holder, root); // check access in the context of compilation root
< prev index next >