618 _options(options),
619 _method(target),
620 _entry_bci(osr_bci),
621 _ilt(nullptr),
622 _stub_function(nullptr),
623 _stub_name(nullptr),
624 _stub_entry_point(nullptr),
625 _max_node_limit(MaxNodeLimit),
626 _post_loop_opts_phase(false),
627 _allow_macro_nodes(true),
628 _inlining_progress(false),
629 _inlining_incrementally(false),
630 _do_cleanup(false),
631 _has_reserved_stack_access(target->has_reserved_stack_access()),
632 #ifndef PRODUCT
633 _igv_idx(0),
634 _trace_opto_output(directive->TraceOptoOutputOption),
635 #endif
636 _has_method_handle_invokes(false),
637 _clinit_barrier_on_entry(false),
638 _stress_seed(0),
639 _comp_arena(mtCompiler),
640 _barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())),
641 _env(ci_env),
642 _directive(directive),
643 _log(ci_env->log()),
644 _first_failure_details(nullptr),
645 _intrinsics (comp_arena(), 0, 0, nullptr),
646 _macro_nodes (comp_arena(), 8, 0, nullptr),
647 _parse_predicates (comp_arena(), 8, 0, nullptr),
648 _template_assertion_predicate_opaqs (comp_arena(), 8, 0, nullptr),
649 _expensive_nodes (comp_arena(), 8, 0, nullptr),
650 _for_post_loop_igvn(comp_arena(), 8, 0, nullptr),
651 _unstable_if_traps (comp_arena(), 8, 0, nullptr),
652 _coarsened_locks (comp_arena(), 8, 0, nullptr),
653 _congraph(nullptr),
654 NOT_PRODUCT(_igv_printer(nullptr) COMMA)
655 _unique(0),
656 _dead_node_count(0),
657 _dead_node_list(comp_arena()),
898 : Phase(Compiler),
899 _compile_id(0),
900 _options(Options::for_runtime_stub()),
901 _method(nullptr),
902 _entry_bci(InvocationEntryBci),
903 _stub_function(stub_function),
904 _stub_name(stub_name),
905 _stub_entry_point(nullptr),
906 _max_node_limit(MaxNodeLimit),
907 _post_loop_opts_phase(false),
908 _allow_macro_nodes(true),
909 _inlining_progress(false),
910 _inlining_incrementally(false),
911 _has_reserved_stack_access(false),
912 #ifndef PRODUCT
913 _igv_idx(0),
914 _trace_opto_output(directive->TraceOptoOutputOption),
915 #endif
916 _has_method_handle_invokes(false),
917 _clinit_barrier_on_entry(false),
918 _stress_seed(0),
919 _comp_arena(mtCompiler),
920 _barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())),
921 _env(ci_env),
922 _directive(directive),
923 _log(ci_env->log()),
924 _first_failure_details(nullptr),
925 _for_post_loop_igvn(comp_arena(), 8, 0, nullptr),
926 _congraph(nullptr),
927 NOT_PRODUCT(_igv_printer(nullptr) COMMA)
928 _unique(0),
929 _dead_node_count(0),
930 _dead_node_list(comp_arena()),
931 _node_arena_one(mtCompiler),
932 _node_arena_two(mtCompiler),
933 _node_arena(&_node_arena_one),
934 _mach_constant_base_node(nullptr),
935 _Compile_types(mtCompiler),
936 _initial_gvn(nullptr),
937 _igvn_worklist(nullptr),
1061 set_do_scheduling(OptoScheduling);
1062
1063 set_do_vector_loop(false);
1064 set_has_monitors(false);
1065 set_has_scoped_access(false);
1066
1067 if (AllowVectorizeOnDemand) {
1068 if (has_method() && _directive->VectorizeOption) {
1069 set_do_vector_loop(true);
1070 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());})
1071 } else if (has_method() && method()->name() != nullptr &&
1072 method()->intrinsic_id() == vmIntrinsics::_forEachRemaining) {
1073 set_do_vector_loop(true);
1074 }
1075 }
1076 set_use_cmove(UseCMoveUnconditionally /* || do_vector_loop()*/); //TODO: consider do_vector_loop() mandate use_cmove unconditionally
1077 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());})
1078
1079 _max_node_limit = _directive->MaxNodeLimitOption;
1080
1081 if (VM_Version::supports_fast_class_init_checks() && has_method() && !is_osr_compilation() && method()->needs_clinit_barrier()) {
1082 set_clinit_barrier_on_entry(true);
1083 }
1084 if (debug_info()->recording_non_safepoints()) {
1085 set_node_note_array(new(comp_arena()) GrowableArray<Node_Notes*>
1086 (comp_arena(), 8, 0, nullptr));
1087 set_default_node_notes(Node_Notes::make(this));
1088 }
1089
1090 const int grow_ats = 16;
1091 _max_alias_types = grow_ats;
1092 _alias_types = NEW_ARENA_ARRAY(comp_arena(), AliasType*, grow_ats);
1093 AliasType* ats = NEW_ARENA_ARRAY(comp_arena(), AliasType, grow_ats);
1094 Copy::zero_to_bytes(ats, sizeof(AliasType)*grow_ats);
1095 {
1096 for (int i = 0; i < grow_ats; i++) _alias_types[i] = &ats[i];
1097 }
1098 // Initialize the first few types.
1099 _alias_types[AliasIdxTop]->Init(AliasIdxTop, nullptr);
1100 _alias_types[AliasIdxBot]->Init(AliasIdxBot, TypePtr::BOTTOM);
1101 _alias_types[AliasIdxRaw]->Init(AliasIdxRaw, TypeRawPtr::BOTTOM);
1102 _num_alias_types = AliasIdxRaw+1;
4074 frc.get_float_count() > 32 &&
4075 frc.get_double_count() == 0 &&
4076 (10 * frc.get_call_count() < frc.get_float_count()) ) {
4077 set_24_bit_selection_and_mode(false, true);
4078 }
4079 #endif // IA32
4080
4081 set_java_calls(frc.get_java_call_count());
4082 set_inner_loops(frc.get_inner_loop_count());
4083
4084 // No infinite loops, no reason to bail out.
4085 return false;
4086 }
4087
4088 //-----------------------------too_many_traps----------------------------------
4089 // Report if there are too many traps at the current method and bci.
4090 // Return true if there was a trap, and/or PerMethodTrapLimit is exceeded.
4091 bool Compile::too_many_traps(ciMethod* method,
4092 int bci,
4093 Deoptimization::DeoptReason reason) {
4094 ciMethodData* md = method->method_data();
4095 if (md->is_empty()) {
4096 // Assume the trap has not occurred, or that it occurred only
4097 // because of a transient condition during start-up in the interpreter.
4098 return false;
4099 }
4100 ciMethod* m = Deoptimization::reason_is_speculate(reason) ? this->method() : nullptr;
4101 if (md->has_trap_at(bci, m, reason) != 0) {
4102 // Assume PerBytecodeTrapLimit==0, for a more conservative heuristic.
4103 // Also, if there are multiple reasons, or if there is no per-BCI record,
4104 // assume the worst.
4105 if (log())
4106 log()->elem("observe trap='%s' count='%d'",
4107 Deoptimization::trap_reason_name(reason),
4108 md->trap_count(reason));
4109 return true;
4110 } else {
4111 // Ignore method/bci and see if there have been too many globally.
4112 return too_many_traps(reason, md);
4113 }
4188 _allowed_reasons = 0;
4189 if (is_method_compilation()) {
4190 for (int rs = (int)Deoptimization::Reason_none+1; rs < Compile::trapHistLength; rs++) {
4191 assert(rs < BitsPerInt, "recode bit map");
4192 if (!too_many_traps((Deoptimization::DeoptReason) rs)) {
4193 _allowed_reasons |= nth_bit(rs);
4194 }
4195 }
4196 }
4197 }
4198
4199 bool Compile::needs_clinit_barrier(ciMethod* method, ciMethod* accessing_method) {
4200 return method->is_static() && needs_clinit_barrier(method->holder(), accessing_method);
4201 }
4202
4203 bool Compile::needs_clinit_barrier(ciField* field, ciMethod* accessing_method) {
4204 return field->is_static() && needs_clinit_barrier(field->holder(), accessing_method);
4205 }
4206
4207 bool Compile::needs_clinit_barrier(ciInstanceKlass* holder, ciMethod* accessing_method) {
4208 if (holder->is_initialized()) {
4209 return false;
4210 }
4211 if (holder->is_being_initialized()) {
4212 if (accessing_method->holder() == holder) {
4213 // Access inside a class. The barrier can be elided when access happens in <clinit>,
4214 // <init>, or a static method. In all those cases, there was an initialization
4215 // barrier on the holder klass passed.
4216 if (accessing_method->is_static_initializer() ||
4217 accessing_method->is_object_initializer() ||
4218 accessing_method->is_static()) {
4219 return false;
4220 }
4221 } else if (accessing_method->holder()->is_subclass_of(holder)) {
4222 // Access from a subclass. The barrier can be elided only when access happens in <clinit>.
4223 // In case of <init> or a static method, the barrier is on the subclass is not enough:
4224 // child class can become fully initialized while its parent class is still being initialized.
4225 if (accessing_method->is_static_initializer()) {
4226 return false;
4227 }
4228 }
4229 ciMethod* root = method(); // the root method of compilation
4230 if (root != accessing_method) {
4231 return needs_clinit_barrier(holder, root); // check access in the context of compilation root
4578 // Reset _print_inlining_list, it only contains destructed objects.
4579 // It is on the arena, so it will be freed when the arena is reset.
4580 _print_inlining_list = nullptr;
4581 // _print_inlining_stream won't be used anymore, either.
4582 print_inlining_reset();
4583 size_t end = ss.size();
4584 _print_inlining_output = NEW_ARENA_ARRAY(comp_arena(), char, end+1);
4585 strncpy(_print_inlining_output, ss.freeze(), end+1);
4586 _print_inlining_output[end] = 0;
4587 }
4588 }
4589
4590 void Compile::dump_print_inlining() {
4591 if (_print_inlining_output != nullptr) {
4592 tty->print_raw(_print_inlining_output);
4593 }
4594 }
4595
4596 void Compile::log_late_inline(CallGenerator* cg) {
4597 if (log() != nullptr) {
4598 log()->head("late_inline method='%d' inline_id='" JLONG_FORMAT "'", log()->identify(cg->method()),
4599 cg->unique_id());
4600 JVMState* p = cg->call_node()->jvms();
4601 while (p != nullptr) {
4602 log()->elem("jvms bci='%d' method='%d'", p->bci(), log()->identify(p->method()));
4603 p = p->caller();
4604 }
4605 log()->tail("late_inline");
4606 }
4607 }
4608
4609 void Compile::log_late_inline_failure(CallGenerator* cg, const char* msg) {
4610 log_late_inline(cg);
4611 if (log() != nullptr) {
4612 log()->inline_fail(msg);
4613 }
4614 }
4615
4616 void Compile::log_inline_id(CallGenerator* cg) {
4617 if (log() != nullptr) {
4618 // The LogCompilation tool needs a unique way to identify late
|
618 _options(options),
619 _method(target),
620 _entry_bci(osr_bci),
621 _ilt(nullptr),
622 _stub_function(nullptr),
623 _stub_name(nullptr),
624 _stub_entry_point(nullptr),
625 _max_node_limit(MaxNodeLimit),
626 _post_loop_opts_phase(false),
627 _allow_macro_nodes(true),
628 _inlining_progress(false),
629 _inlining_incrementally(false),
630 _do_cleanup(false),
631 _has_reserved_stack_access(target->has_reserved_stack_access()),
632 #ifndef PRODUCT
633 _igv_idx(0),
634 _trace_opto_output(directive->TraceOptoOutputOption),
635 #endif
636 _has_method_handle_invokes(false),
637 _clinit_barrier_on_entry(false),
638 _has_clinit_barriers(false),
639 _stress_seed(0),
640 _comp_arena(mtCompiler),
641 _barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())),
642 _env(ci_env),
643 _directive(directive),
644 _log(ci_env->log()),
645 _first_failure_details(nullptr),
646 _intrinsics (comp_arena(), 0, 0, nullptr),
647 _macro_nodes (comp_arena(), 8, 0, nullptr),
648 _parse_predicates (comp_arena(), 8, 0, nullptr),
649 _template_assertion_predicate_opaqs (comp_arena(), 8, 0, nullptr),
650 _expensive_nodes (comp_arena(), 8, 0, nullptr),
651 _for_post_loop_igvn(comp_arena(), 8, 0, nullptr),
652 _unstable_if_traps (comp_arena(), 8, 0, nullptr),
653 _coarsened_locks (comp_arena(), 8, 0, nullptr),
654 _congraph(nullptr),
655 NOT_PRODUCT(_igv_printer(nullptr) COMMA)
656 _unique(0),
657 _dead_node_count(0),
658 _dead_node_list(comp_arena()),
899 : Phase(Compiler),
900 _compile_id(0),
901 _options(Options::for_runtime_stub()),
902 _method(nullptr),
903 _entry_bci(InvocationEntryBci),
904 _stub_function(stub_function),
905 _stub_name(stub_name),
906 _stub_entry_point(nullptr),
907 _max_node_limit(MaxNodeLimit),
908 _post_loop_opts_phase(false),
909 _allow_macro_nodes(true),
910 _inlining_progress(false),
911 _inlining_incrementally(false),
912 _has_reserved_stack_access(false),
913 #ifndef PRODUCT
914 _igv_idx(0),
915 _trace_opto_output(directive->TraceOptoOutputOption),
916 #endif
917 _has_method_handle_invokes(false),
918 _clinit_barrier_on_entry(false),
919 _has_clinit_barriers(false),
920 _stress_seed(0),
921 _comp_arena(mtCompiler),
922 _barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())),
923 _env(ci_env),
924 _directive(directive),
925 _log(ci_env->log()),
926 _first_failure_details(nullptr),
927 _for_post_loop_igvn(comp_arena(), 8, 0, nullptr),
928 _congraph(nullptr),
929 NOT_PRODUCT(_igv_printer(nullptr) COMMA)
930 _unique(0),
931 _dead_node_count(0),
932 _dead_node_list(comp_arena()),
933 _node_arena_one(mtCompiler),
934 _node_arena_two(mtCompiler),
935 _node_arena(&_node_arena_one),
936 _mach_constant_base_node(nullptr),
937 _Compile_types(mtCompiler),
938 _initial_gvn(nullptr),
939 _igvn_worklist(nullptr),
1063 set_do_scheduling(OptoScheduling);
1064
1065 set_do_vector_loop(false);
1066 set_has_monitors(false);
1067 set_has_scoped_access(false);
1068
1069 if (AllowVectorizeOnDemand) {
1070 if (has_method() && _directive->VectorizeOption) {
1071 set_do_vector_loop(true);
1072 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());})
1073 } else if (has_method() && method()->name() != nullptr &&
1074 method()->intrinsic_id() == vmIntrinsics::_forEachRemaining) {
1075 set_do_vector_loop(true);
1076 }
1077 }
1078 set_use_cmove(UseCMoveUnconditionally /* || do_vector_loop()*/); //TODO: consider do_vector_loop() mandate use_cmove unconditionally
1079 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());})
1080
1081 _max_node_limit = _directive->MaxNodeLimitOption;
1082
1083 if (VM_Version::supports_fast_class_init_checks() && has_method() && !is_osr_compilation() &&
1084 (method()->needs_clinit_barrier() || (do_clinit_barriers() && method()->is_static()))) {
1085 set_clinit_barrier_on_entry(true);
1086 if (do_clinit_barriers()) {
1087 set_has_clinit_barriers(true); // Entry clinit barrier is in prolog code.
1088 }
1089 }
1090 if (debug_info()->recording_non_safepoints()) {
1091 set_node_note_array(new(comp_arena()) GrowableArray<Node_Notes*>
1092 (comp_arena(), 8, 0, nullptr));
1093 set_default_node_notes(Node_Notes::make(this));
1094 }
1095
1096 const int grow_ats = 16;
1097 _max_alias_types = grow_ats;
1098 _alias_types = NEW_ARENA_ARRAY(comp_arena(), AliasType*, grow_ats);
1099 AliasType* ats = NEW_ARENA_ARRAY(comp_arena(), AliasType, grow_ats);
1100 Copy::zero_to_bytes(ats, sizeof(AliasType)*grow_ats);
1101 {
1102 for (int i = 0; i < grow_ats; i++) _alias_types[i] = &ats[i];
1103 }
1104 // Initialize the first few types.
1105 _alias_types[AliasIdxTop]->Init(AliasIdxTop, nullptr);
1106 _alias_types[AliasIdxBot]->Init(AliasIdxBot, TypePtr::BOTTOM);
1107 _alias_types[AliasIdxRaw]->Init(AliasIdxRaw, TypeRawPtr::BOTTOM);
1108 _num_alias_types = AliasIdxRaw+1;
4080 frc.get_float_count() > 32 &&
4081 frc.get_double_count() == 0 &&
4082 (10 * frc.get_call_count() < frc.get_float_count()) ) {
4083 set_24_bit_selection_and_mode(false, true);
4084 }
4085 #endif // IA32
4086
4087 set_java_calls(frc.get_java_call_count());
4088 set_inner_loops(frc.get_inner_loop_count());
4089
4090 // No infinite loops, no reason to bail out.
4091 return false;
4092 }
4093
4094 //-----------------------------too_many_traps----------------------------------
4095 // Report if there are too many traps at the current method and bci.
4096 // Return true if there was a trap, and/or PerMethodTrapLimit is exceeded.
4097 bool Compile::too_many_traps(ciMethod* method,
4098 int bci,
4099 Deoptimization::DeoptReason reason) {
4100 if (method->has_trap_at(bci)) {
4101 return true;
4102 }
4103 ciMethodData* md = method->method_data();
4104 if (md->is_empty()) {
4105 // Assume the trap has not occurred, or that it occurred only
4106 // because of a transient condition during start-up in the interpreter.
4107 return false;
4108 }
4109 ciMethod* m = Deoptimization::reason_is_speculate(reason) ? this->method() : nullptr;
4110 if (md->has_trap_at(bci, m, reason) != 0) {
4111 // Assume PerBytecodeTrapLimit==0, for a more conservative heuristic.
4112 // Also, if there are multiple reasons, or if there is no per-BCI record,
4113 // assume the worst.
4114 if (log())
4115 log()->elem("observe trap='%s' count='%d'",
4116 Deoptimization::trap_reason_name(reason),
4117 md->trap_count(reason));
4118 return true;
4119 } else {
4120 // Ignore method/bci and see if there have been too many globally.
4121 return too_many_traps(reason, md);
4122 }
4197 _allowed_reasons = 0;
4198 if (is_method_compilation()) {
4199 for (int rs = (int)Deoptimization::Reason_none+1; rs < Compile::trapHistLength; rs++) {
4200 assert(rs < BitsPerInt, "recode bit map");
4201 if (!too_many_traps((Deoptimization::DeoptReason) rs)) {
4202 _allowed_reasons |= nth_bit(rs);
4203 }
4204 }
4205 }
4206 }
4207
4208 bool Compile::needs_clinit_barrier(ciMethod* method, ciMethod* accessing_method) {
4209 return method->is_static() && needs_clinit_barrier(method->holder(), accessing_method);
4210 }
4211
4212 bool Compile::needs_clinit_barrier(ciField* field, ciMethod* accessing_method) {
4213 return field->is_static() && needs_clinit_barrier(field->holder(), accessing_method);
4214 }
4215
4216 bool Compile::needs_clinit_barrier(ciInstanceKlass* holder, ciMethod* accessing_method) {
4217 if (holder->is_initialized() && !do_clinit_barriers()) {
4218 return false;
4219 }
4220 if (holder->is_being_initialized() || do_clinit_barriers()) {
4221 if (accessing_method->holder() == holder) {
4222 // Access inside a class. The barrier can be elided when access happens in <clinit>,
4223 // <init>, or a static method. In all those cases, there was an initialization
4224 // barrier on the holder klass passed.
4225 if (accessing_method->is_static_initializer() ||
4226 accessing_method->is_object_initializer() ||
4227 accessing_method->is_static()) {
4228 return false;
4229 }
4230 } else if (accessing_method->holder()->is_subclass_of(holder)) {
4231 // Access from a subclass. The barrier can be elided only when access happens in <clinit>.
4232 // In case of <init> or a static method, the barrier is on the subclass is not enough:
4233 // child class can become fully initialized while its parent class is still being initialized.
4234 if (accessing_method->is_static_initializer()) {
4235 return false;
4236 }
4237 }
4238 ciMethod* root = method(); // the root method of compilation
4239 if (root != accessing_method) {
4240 return needs_clinit_barrier(holder, root); // check access in the context of compilation root
4587 // Reset _print_inlining_list, it only contains destructed objects.
4588 // It is on the arena, so it will be freed when the arena is reset.
4589 _print_inlining_list = nullptr;
4590 // _print_inlining_stream won't be used anymore, either.
4591 print_inlining_reset();
4592 size_t end = ss.size();
4593 _print_inlining_output = NEW_ARENA_ARRAY(comp_arena(), char, end+1);
4594 strncpy(_print_inlining_output, ss.freeze(), end+1);
4595 _print_inlining_output[end] = 0;
4596 }
4597 }
4598
4599 void Compile::dump_print_inlining() {
4600 if (_print_inlining_output != nullptr) {
4601 tty->print_raw(_print_inlining_output);
4602 }
4603 }
4604
4605 void Compile::log_late_inline(CallGenerator* cg) {
4606 if (log() != nullptr) {
4607 log()->head("late_inline method='%d' inline_id='" JLONG_FORMAT "'", log()->identify(cg->method()),
4608 cg->unique_id());
4609 JVMState* p = cg->call_node()->jvms();
4610 while (p != nullptr) {
4611 log()->elem("jvms bci='%d' method='%d'", p->bci(), log()->identify(p->method()));
4612 p = p->caller();
4613 }
4614 log()->tail("late_inline");
4615 }
4616 }
4617
4618 void Compile::log_late_inline_failure(CallGenerator* cg, const char* msg) {
4619 log_late_inline(cg);
4620 if (log() != nullptr) {
4621 log()->inline_fail(msg);
4622 }
4623 }
4624
4625 void Compile::log_inline_id(CallGenerator* cg) {
4626 if (log() != nullptr) {
4627 // The LogCompilation tool needs a unique way to identify late
|