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;
4150 dead_nodes.push(in);
4151 }
4152 }
4153 m->disconnect_inputs(this);
4154 }
4155 }
4156
4157 set_java_calls(frc.get_java_call_count());
4158 set_inner_loops(frc.get_inner_loop_count());
4159
4160 // No infinite loops, no reason to bail out.
4161 return false;
4162 }
4163
4164 //-----------------------------too_many_traps----------------------------------
4165 // Report if there are too many traps at the current method and bci.
4166 // Return true if there was a trap, and/or PerMethodTrapLimit is exceeded.
4167 bool Compile::too_many_traps(ciMethod* method,
4168 int bci,
4169 Deoptimization::DeoptReason reason) {
4170 ciMethodData* md = method->method_data();
4171 if (md->is_empty()) {
4172 // Assume the trap has not occurred, or that it occurred only
4173 // because of a transient condition during start-up in the interpreter.
4174 return false;
4175 }
4176 ciMethod* m = Deoptimization::reason_is_speculate(reason) ? this->method() : nullptr;
4177 if (md->has_trap_at(bci, m, reason) != 0) {
4178 // Assume PerBytecodeTrapLimit==0, for a more conservative heuristic.
4179 // Also, if there are multiple reasons, or if there is no per-BCI record,
4180 // assume the worst.
4181 if (log())
4182 log()->elem("observe trap='%s' count='%d'",
4183 Deoptimization::trap_reason_name(reason),
4184 md->trap_count(reason));
4185 return true;
4186 } else {
4187 // Ignore method/bci and see if there have been too many globally.
4188 return too_many_traps(reason, md);
4189 }
4190 }
4191
4192 // Less-accurate variant which does not require a method and bci.
4193 bool Compile::too_many_traps(Deoptimization::DeoptReason reason,
4194 ciMethodData* logmd) {
4195 if (trap_count(reason) >= Deoptimization::per_method_trap_limit(reason)) {
4196 // Too many traps globally.
4197 // Note that we use cumulative trap_count, not just md->trap_count.
4198 if (log()) {
4199 int mcount = (logmd == nullptr)? -1: (int)logmd->trap_count(reason);
4200 log()->elem("observe trap='%s' count='0' mcount='%d' ccount='%d'",
4201 Deoptimization::trap_reason_name(reason),
4202 mcount, trap_count(reason));
4203 }
4204 return true;
4205 } else {
4206 // The coast is clear.
4207 return false;
4208 }
4209 }
4210
4211 //--------------------------too_many_recompiles--------------------------------
4212 // Report if there are too many recompiles at the current method and bci.
4213 // Consults PerBytecodeRecompilationCutoff and PerMethodRecompilationCutoff.
4214 // Is not eager to return true, since this will cause the compiler to use
4264 _allowed_reasons = 0;
4265 if (is_method_compilation()) {
4266 for (int rs = (int)Deoptimization::Reason_none+1; rs < Compile::trapHistLength; rs++) {
4267 assert(rs < BitsPerInt, "recode bit map");
4268 if (!too_many_traps((Deoptimization::DeoptReason) rs)) {
4269 _allowed_reasons |= nth_bit(rs);
4270 }
4271 }
4272 }
4273 }
4274
4275 bool Compile::needs_clinit_barrier(ciMethod* method, ciMethod* accessing_method) {
4276 return method->is_static() && needs_clinit_barrier(method->holder(), accessing_method);
4277 }
4278
4279 bool Compile::needs_clinit_barrier(ciField* field, ciMethod* accessing_method) {
4280 return field->is_static() && needs_clinit_barrier(field->holder(), accessing_method);
4281 }
4282
4283 bool Compile::needs_clinit_barrier(ciInstanceKlass* holder, ciMethod* accessing_method) {
4284 if (holder->is_initialized()) {
4285 return false;
4286 }
4287 if (holder->is_being_initialized()) {
4288 if (accessing_method->holder() == holder) {
4289 // Access inside a class. The barrier can be elided when access happens in <clinit>,
4290 // <init>, or a static method. In all those cases, there was an initialization
4291 // barrier on the holder klass passed.
4292 if (accessing_method->is_static_initializer() ||
4293 accessing_method->is_object_initializer() ||
4294 accessing_method->is_static()) {
4295 return false;
4296 }
4297 } else if (accessing_method->holder()->is_subclass_of(holder)) {
4298 // Access from a subclass. The barrier can be elided only when access happens in <clinit>.
4299 // In case of <init> or a static method, the barrier is on the subclass is not enough:
4300 // child class can become fully initialized while its parent class is still being initialized.
4301 if (accessing_method->is_static_initializer()) {
4302 return false;
4303 }
4304 }
4305 ciMethod* root = method(); // the root method of compilation
4306 if (root != accessing_method) {
4307 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;
4162 dead_nodes.push(in);
4163 }
4164 }
4165 m->disconnect_inputs(this);
4166 }
4167 }
4168
4169 set_java_calls(frc.get_java_call_count());
4170 set_inner_loops(frc.get_inner_loop_count());
4171
4172 // No infinite loops, no reason to bail out.
4173 return false;
4174 }
4175
4176 //-----------------------------too_many_traps----------------------------------
4177 // Report if there are too many traps at the current method and bci.
4178 // Return true if there was a trap, and/or PerMethodTrapLimit is exceeded.
4179 bool Compile::too_many_traps(ciMethod* method,
4180 int bci,
4181 Deoptimization::DeoptReason reason) {
4182 if (method->has_trap_at(bci)) {
4183 return true;
4184 }
4185 if (PreloadReduceTraps && for_preload()) {
4186 // Preload code should not have traps, if possible.
4187 return true;
4188 }
4189 ciMethodData* md = method->method_data();
4190 if (md->is_empty()) {
4191 // Assume the trap has not occurred, or that it occurred only
4192 // because of a transient condition during start-up in the interpreter.
4193 return false;
4194 }
4195 ciMethod* m = Deoptimization::reason_is_speculate(reason) ? this->method() : nullptr;
4196 if (md->has_trap_at(bci, m, reason) != 0) {
4197 // Assume PerBytecodeTrapLimit==0, for a more conservative heuristic.
4198 // Also, if there are multiple reasons, or if there is no per-BCI record,
4199 // assume the worst.
4200 if (log())
4201 log()->elem("observe trap='%s' count='%d'",
4202 Deoptimization::trap_reason_name(reason),
4203 md->trap_count(reason));
4204 return true;
4205 } else {
4206 // Ignore method/bci and see if there have been too many globally.
4207 return too_many_traps(reason, md);
4208 }
4209 }
4210
4211 // Less-accurate variant which does not require a method and bci.
4212 bool Compile::too_many_traps(Deoptimization::DeoptReason reason,
4213 ciMethodData* logmd) {
4214 if (PreloadReduceTraps && for_preload()) {
4215 // Preload code should not have traps, if possible.
4216 return true;
4217 }
4218 if (trap_count(reason) >= Deoptimization::per_method_trap_limit(reason)) {
4219 // Too many traps globally.
4220 // Note that we use cumulative trap_count, not just md->trap_count.
4221 if (log()) {
4222 int mcount = (logmd == nullptr)? -1: (int)logmd->trap_count(reason);
4223 log()->elem("observe trap='%s' count='0' mcount='%d' ccount='%d'",
4224 Deoptimization::trap_reason_name(reason),
4225 mcount, trap_count(reason));
4226 }
4227 return true;
4228 } else {
4229 // The coast is clear.
4230 return false;
4231 }
4232 }
4233
4234 //--------------------------too_many_recompiles--------------------------------
4235 // Report if there are too many recompiles at the current method and bci.
4236 // Consults PerBytecodeRecompilationCutoff and PerMethodRecompilationCutoff.
4237 // Is not eager to return true, since this will cause the compiler to use
4287 _allowed_reasons = 0;
4288 if (is_method_compilation()) {
4289 for (int rs = (int)Deoptimization::Reason_none+1; rs < Compile::trapHistLength; rs++) {
4290 assert(rs < BitsPerInt, "recode bit map");
4291 if (!too_many_traps((Deoptimization::DeoptReason) rs)) {
4292 _allowed_reasons |= nth_bit(rs);
4293 }
4294 }
4295 }
4296 }
4297
4298 bool Compile::needs_clinit_barrier(ciMethod* method, ciMethod* accessing_method) {
4299 return method->is_static() && needs_clinit_barrier(method->holder(), accessing_method);
4300 }
4301
4302 bool Compile::needs_clinit_barrier(ciField* field, ciMethod* accessing_method) {
4303 return field->is_static() && needs_clinit_barrier(field->holder(), accessing_method);
4304 }
4305
4306 bool Compile::needs_clinit_barrier(ciInstanceKlass* holder, ciMethod* accessing_method) {
4307 if (holder->is_initialized() && !do_clinit_barriers()) {
4308 return false;
4309 }
4310 if (holder->is_being_initialized() || do_clinit_barriers()) {
4311 if (accessing_method->holder() == holder) {
4312 // Access inside a class. The barrier can be elided when access happens in <clinit>,
4313 // <init>, or a static method. In all those cases, there was an initialization
4314 // barrier on the holder klass passed.
4315 if (accessing_method->is_static_initializer() ||
4316 accessing_method->is_object_initializer() ||
4317 accessing_method->is_static()) {
4318 return false;
4319 }
4320 } else if (accessing_method->holder()->is_subclass_of(holder)) {
4321 // Access from a subclass. The barrier can be elided only when access happens in <clinit>.
4322 // In case of <init> or a static method, the barrier is on the subclass is not enough:
4323 // child class can become fully initialized while its parent class is still being initialized.
4324 if (accessing_method->is_static_initializer()) {
4325 return false;
4326 }
4327 }
4328 ciMethod* root = method(); // the root method of compilation
4329 if (root != accessing_method) {
4330 return needs_clinit_barrier(holder, root); // check access in the context of compilation root
|