< 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* compile_phase_name) const {
 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", compile_phase_name);
 597     // Print out all nodes in ascending order of index.
 598     // It is important that we traverse both inputs and outputs of nodes,
 599     // so that we reach all nodes that are connected to Root.
 600     root()->dump_bfs(MaxNodeLimit, nullptr, "-+S$", &ss);
 601   } else {
 602     // Dump the node blockwise if we have a scheduling
 603     _output->print_scheduling(&ss);
 604   }
 605 
 606   // Check that the lock is not broken by a safepoint.
 607   NoSafepointVerifier nsv;
 608   ttyLocker ttyl;
 609   if (xtty != nullptr) {
 610     xtty->head("ideal compile_id='%d'%s compile_phase='%s'",
 611                compile_id(),
 612                is_osr_compilation() ? " compile_kind='osr'" : "",

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

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

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

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

 930       _stress_seed(0),
 931       _comp_arena(mtCompiler, Arena::Tag::tag_comp),
 932       _barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())),
 933       _env(ci_env),
 934       _directive(directive),
 935       _log(ci_env->log()),
 936       _first_failure_details(nullptr),
 937       _for_post_loop_igvn(comp_arena(), 8, 0, nullptr),
 938       _for_merge_stores_igvn(comp_arena(), 8, 0, nullptr),
 939       _congraph(nullptr),
 940       NOT_PRODUCT(_igv_printer(nullptr) COMMA)
 941       _unique(0),
 942       _dead_node_count(0),
 943       _dead_node_list(comp_arena()),
 944       _node_arena_one(mtCompiler, Arena::Tag::tag_node),
 945       _node_arena_two(mtCompiler, Arena::Tag::tag_node),
 946       _node_arena(&_node_arena_one),
 947       _mach_constant_base_node(nullptr),
 948       _Compile_types(mtCompiler, Arena::Tag::tag_type),
 949       _initial_gvn(nullptr),

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

1103     set_clinit_barrier_on_entry(true);



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

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







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




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

4274   _allowed_reasons = 0;
4275   if (is_method_compilation()) {
4276     for (int rs = (int)Deoptimization::Reason_none+1; rs < Compile::trapHistLength; rs++) {
4277       assert(rs < BitsPerInt, "recode bit map");
4278       if (!too_many_traps((Deoptimization::DeoptReason) rs)) {
4279         _allowed_reasons |= nth_bit(rs);
4280       }
4281     }
4282   }
4283 }
4284 
4285 bool Compile::needs_clinit_barrier(ciMethod* method, ciMethod* accessing_method) {
4286   return method->is_static() && needs_clinit_barrier(method->holder(), accessing_method);
4287 }
4288 
4289 bool Compile::needs_clinit_barrier(ciField* field, ciMethod* accessing_method) {
4290   return field->is_static() && needs_clinit_barrier(field->holder(), accessing_method);
4291 }
4292 
4293 bool Compile::needs_clinit_barrier(ciInstanceKlass* holder, ciMethod* accessing_method) {
4294   if (holder->is_initialized()) {
4295     return false;
4296   }
4297   if (holder->is_being_initialized()) {
4298     if (accessing_method->holder() == holder) {
4299       // Access inside a class. The barrier can be elided when access happens in <clinit>,
4300       // <init>, or a static method. In all those cases, there was an initialization
4301       // barrier on the holder klass passed.
4302       if (accessing_method->is_static_initializer() ||
4303           accessing_method->is_object_initializer() ||
4304           accessing_method->is_static()) {
4305         return false;
4306       }
4307     } else if (accessing_method->holder()->is_subclass_of(holder)) {
4308       // Access from a subclass. The barrier can be elided only when access happens in <clinit>.
4309       // In case of <init> or a static method, the barrier is on the subclass is not enough:
4310       // child class can become fully initialized while its parent class is still being initialized.
4311       if (accessing_method->is_static_initializer()) {
4312         return false;
4313       }
4314     }
4315     ciMethod* root = method(); // the root method of compilation
4316     if (root != accessing_method) {
4317       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* compile_phase_name) const {
 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", compile_phase_name);
 602     // Print out all nodes in ascending order of index.
 603     // It is important that we traverse both inputs and outputs of nodes,
 604     // so that we reach all nodes that are connected to Root.
 605     root()->dump_bfs(MaxNodeLimit, nullptr, "-+S$", &ss);
 606   } else {
 607     // Dump the node blockwise if we have a scheduling
 608     _output->print_scheduling(&ss);
 609   }
 610 
 611   // Check that the lock is not broken by a safepoint.
 612   NoSafepointVerifier nsv;
 613   ttyLocker ttyl;
 614   if (xtty != nullptr) {
 615     xtty->head("ideal compile_id='%d'%s compile_phase='%s'",
 616                compile_id(),
 617                is_osr_compilation() ? " compile_kind='osr'" :
 618                (for_preload() ? " compile_kind='AP'" : ""),
 619                compile_phase_name);
 620   }
 621 
 622   tty->print("%s", ss.as_string());
 623 
 624   if (xtty != nullptr) {
 625     xtty->tail("ideal");
 626   }
 627 }
 628 #endif
 629 
 630 // ============================================================================
 631 //------------------------------Compile standard-------------------------------
 632 
 633 // Compile a method.  entry_bci is -1 for normal compilations and indicates
 634 // the continuation bci for on stack replacement.
 635 
 636 
 637 Compile::Compile(ciEnv* ci_env, ciMethod* target, int osr_bci,
 638                  Options options, DirectiveSet* directive)

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

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

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

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

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