< 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)

 634       _method(target),
 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       _clinit_barrier_on_entry(false),

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

 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_id(stub_id),
 915       _stub_entry_point(nullptr),
 916       _max_node_limit(MaxNodeLimit),
 917       _post_loop_opts_phase(false),
 918       _merge_stores_phase(false),
 919       _allow_macro_nodes(true),
 920       _inlining_progress(false),
 921       _inlining_incrementally(false),
 922       _has_reserved_stack_access(false),
 923 #ifndef PRODUCT
 924       _igv_idx(0),
 925       _trace_opto_output(directive->TraceOptoOutputOption),
 926 #endif
 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),

1080   set_do_scheduling(OptoScheduling);
1081 
1082   set_do_vector_loop(false);
1083   set_has_monitors(false);
1084   set_has_scoped_access(false);
1085 
1086   if (AllowVectorizeOnDemand) {
1087     if (has_method() && _directive->VectorizeOption) {
1088       set_do_vector_loop(true);
1089       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());})
1090     } else if (has_method() && method()->name() != nullptr &&
1091                method()->intrinsic_id() == vmIntrinsics::_forEachRemaining) {
1092       set_do_vector_loop(true);
1093     }
1094   }
1095   set_use_cmove(UseCMoveUnconditionally /* || do_vector_loop()*/); //TODO: consider do_vector_loop() mandate use_cmove unconditionally
1096   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());})
1097 
1098   _max_node_limit = _directive->MaxNodeLimitOption;
1099 
1100   if (VM_Version::supports_fast_class_init_checks() && has_method() && !is_osr_compilation() && method()->needs_clinit_barrier()) {

1101     set_clinit_barrier_on_entry(true);



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

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







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




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

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

 640       _method(target),
 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       _clinit_barrier_on_entry(false),
 660       _has_clinit_barriers(false),
 661       _stress_seed(0),
 662       _comp_arena(mtCompiler, Arena::Tag::tag_comp),
 663       _barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())),
 664       _env(ci_env),
 665       _directive(directive),
 666       _log(ci_env->log()),
 667       _first_failure_details(nullptr),
 668       _intrinsics(comp_arena(), 0, 0, nullptr),
 669       _macro_nodes(comp_arena(), 8, 0, nullptr),
 670       _parse_predicates(comp_arena(), 8, 0, nullptr),
 671       _template_assertion_predicate_opaques(comp_arena(), 8, 0, nullptr),
 672       _expensive_nodes(comp_arena(), 8, 0, nullptr),
 673       _for_post_loop_igvn(comp_arena(), 8, 0, nullptr),
 674       _for_merge_stores_igvn(comp_arena(), 8, 0, nullptr),
 675       _unstable_if_traps(comp_arena(), 8, 0, nullptr),
 676       _coarsened_locks(comp_arena(), 8, 0, nullptr),
 677       _congraph(nullptr),
 678       NOT_PRODUCT(_igv_printer(nullptr) COMMA)
 679           _unique(0),
 680       _dead_node_count(0),

 915       _compile_id(0),
 916       _options(Options::for_runtime_stub()),
 917       _method(nullptr),
 918       _entry_bci(InvocationEntryBci),
 919       _stub_function(stub_function),
 920       _stub_name(stub_name),
 921       _stub_id(stub_id),
 922       _stub_entry_point(nullptr),
 923       _max_node_limit(MaxNodeLimit),
 924       _post_loop_opts_phase(false),
 925       _merge_stores_phase(false),
 926       _allow_macro_nodes(true),
 927       _inlining_progress(false),
 928       _inlining_incrementally(false),
 929       _has_reserved_stack_access(false),
 930 #ifndef PRODUCT
 931       _igv_idx(0),
 932       _trace_opto_output(directive->TraceOptoOutputOption),
 933 #endif
 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),

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

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

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