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;
4034 frc.get_float_count() > 32 &&
4035 frc.get_double_count() == 0 &&
4036 (10 * frc.get_call_count() < frc.get_float_count()) ) {
4037 set_24_bit_selection_and_mode(false, true);
4038 }
4039 #endif // IA32
4040
4041 set_java_calls(frc.get_java_call_count());
4042 set_inner_loops(frc.get_inner_loop_count());
4043
4044 // No infinite loops, no reason to bail out.
4045 return false;
4046 }
4047
4048 //-----------------------------too_many_traps----------------------------------
4049 // Report if there are too many traps at the current method and bci.
4050 // Return true if there was a trap, and/or PerMethodTrapLimit is exceeded.
4051 bool Compile::too_many_traps(ciMethod* method,
4052 int bci,
4053 Deoptimization::DeoptReason reason) {
4054 ciMethodData* md = method->method_data();
4055 if (md->is_empty()) {
4056 // Assume the trap has not occurred, or that it occurred only
4057 // because of a transient condition during start-up in the interpreter.
4058 return false;
4059 }
4060 ciMethod* m = Deoptimization::reason_is_speculate(reason) ? this->method() : nullptr;
4061 if (md->has_trap_at(bci, m, reason) != 0) {
4062 // Assume PerBytecodeTrapLimit==0, for a more conservative heuristic.
4063 // Also, if there are multiple reasons, or if there is no per-BCI record,
4064 // assume the worst.
4065 if (log())
4066 log()->elem("observe trap='%s' count='%d'",
4067 Deoptimization::trap_reason_name(reason),
4068 md->trap_count(reason));
4069 return true;
4070 } else {
4071 // Ignore method/bci and see if there have been too many globally.
4072 return too_many_traps(reason, md);
4073 }
4148 _allowed_reasons = 0;
4149 if (is_method_compilation()) {
4150 for (int rs = (int)Deoptimization::Reason_none+1; rs < Compile::trapHistLength; rs++) {
4151 assert(rs < BitsPerInt, "recode bit map");
4152 if (!too_many_traps((Deoptimization::DeoptReason) rs)) {
4153 _allowed_reasons |= nth_bit(rs);
4154 }
4155 }
4156 }
4157 }
4158
4159 bool Compile::needs_clinit_barrier(ciMethod* method, ciMethod* accessing_method) {
4160 return method->is_static() && needs_clinit_barrier(method->holder(), accessing_method);
4161 }
4162
4163 bool Compile::needs_clinit_barrier(ciField* field, ciMethod* accessing_method) {
4164 return field->is_static() && needs_clinit_barrier(field->holder(), accessing_method);
4165 }
4166
4167 bool Compile::needs_clinit_barrier(ciInstanceKlass* holder, ciMethod* accessing_method) {
4168 if (holder->is_initialized()) {
4169 return false;
4170 }
4171 if (holder->is_being_initialized()) {
4172 if (accessing_method->holder() == holder) {
4173 // Access inside a class. The barrier can be elided when access happens in <clinit>,
4174 // <init>, or a static method. In all those cases, there was an initialization
4175 // barrier on the holder klass passed.
4176 if (accessing_method->is_static_initializer() ||
4177 accessing_method->is_object_initializer() ||
4178 accessing_method->is_static()) {
4179 return false;
4180 }
4181 } else if (accessing_method->holder()->is_subclass_of(holder)) {
4182 // Access from a subclass. The barrier can be elided only when access happens in <clinit>.
4183 // In case of <init> or a static method, the barrier is on the subclass is not enough:
4184 // child class can become fully initialized while its parent class is still being initialized.
4185 if (accessing_method->is_static_initializer()) {
4186 return false;
4187 }
4188 }
4189 ciMethod* root = method(); // the root method of compilation
4190 if (root != accessing_method) {
4191 return needs_clinit_barrier(holder, root); // check access in the context of compilation root
4540 // Reset _print_inlining_list, it only contains destructed objects.
4541 // It is on the arena, so it will be freed when the arena is reset.
4542 _print_inlining_list = nullptr;
4543 // _print_inlining_stream won't be used anymore, either.
4544 print_inlining_reset();
4545 size_t end = ss.size();
4546 _print_inlining_output = NEW_ARENA_ARRAY(comp_arena(), char, end+1);
4547 strncpy(_print_inlining_output, ss.freeze(), end+1);
4548 _print_inlining_output[end] = 0;
4549 }
4550 }
4551
4552 void Compile::dump_print_inlining() {
4553 if (_print_inlining_output != nullptr) {
4554 tty->print_raw(_print_inlining_output);
4555 }
4556 }
4557
4558 void Compile::log_late_inline(CallGenerator* cg) {
4559 if (log() != nullptr) {
4560 log()->head("late_inline method='%d' inline_id='" JLONG_FORMAT "'", log()->identify(cg->method()),
4561 cg->unique_id());
4562 JVMState* p = cg->call_node()->jvms();
4563 while (p != nullptr) {
4564 log()->elem("jvms bci='%d' method='%d'", p->bci(), log()->identify(p->method()));
4565 p = p->caller();
4566 }
4567 log()->tail("late_inline");
4568 }
4569 }
4570
4571 void Compile::log_late_inline_failure(CallGenerator* cg, const char* msg) {
4572 log_late_inline(cg);
4573 if (log() != nullptr) {
4574 log()->inline_fail(msg);
4575 }
4576 }
4577
4578 void Compile::log_inline_id(CallGenerator* cg) {
4579 if (log() != nullptr) {
4580 // 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;
4040 frc.get_float_count() > 32 &&
4041 frc.get_double_count() == 0 &&
4042 (10 * frc.get_call_count() < frc.get_float_count()) ) {
4043 set_24_bit_selection_and_mode(false, true);
4044 }
4045 #endif // IA32
4046
4047 set_java_calls(frc.get_java_call_count());
4048 set_inner_loops(frc.get_inner_loop_count());
4049
4050 // No infinite loops, no reason to bail out.
4051 return false;
4052 }
4053
4054 //-----------------------------too_many_traps----------------------------------
4055 // Report if there are too many traps at the current method and bci.
4056 // Return true if there was a trap, and/or PerMethodTrapLimit is exceeded.
4057 bool Compile::too_many_traps(ciMethod* method,
4058 int bci,
4059 Deoptimization::DeoptReason reason) {
4060 if (method->has_trap_at(bci)) {
4061 return true;
4062 }
4063 ciMethodData* md = method->method_data();
4064 if (md->is_empty()) {
4065 // Assume the trap has not occurred, or that it occurred only
4066 // because of a transient condition during start-up in the interpreter.
4067 return false;
4068 }
4069 ciMethod* m = Deoptimization::reason_is_speculate(reason) ? this->method() : nullptr;
4070 if (md->has_trap_at(bci, m, reason) != 0) {
4071 // Assume PerBytecodeTrapLimit==0, for a more conservative heuristic.
4072 // Also, if there are multiple reasons, or if there is no per-BCI record,
4073 // assume the worst.
4074 if (log())
4075 log()->elem("observe trap='%s' count='%d'",
4076 Deoptimization::trap_reason_name(reason),
4077 md->trap_count(reason));
4078 return true;
4079 } else {
4080 // Ignore method/bci and see if there have been too many globally.
4081 return too_many_traps(reason, md);
4082 }
4157 _allowed_reasons = 0;
4158 if (is_method_compilation()) {
4159 for (int rs = (int)Deoptimization::Reason_none+1; rs < Compile::trapHistLength; rs++) {
4160 assert(rs < BitsPerInt, "recode bit map");
4161 if (!too_many_traps((Deoptimization::DeoptReason) rs)) {
4162 _allowed_reasons |= nth_bit(rs);
4163 }
4164 }
4165 }
4166 }
4167
4168 bool Compile::needs_clinit_barrier(ciMethod* method, ciMethod* accessing_method) {
4169 return method->is_static() && needs_clinit_barrier(method->holder(), accessing_method);
4170 }
4171
4172 bool Compile::needs_clinit_barrier(ciField* field, ciMethod* accessing_method) {
4173 return field->is_static() && needs_clinit_barrier(field->holder(), accessing_method);
4174 }
4175
4176 bool Compile::needs_clinit_barrier(ciInstanceKlass* holder, ciMethod* accessing_method) {
4177 if (holder->is_initialized() && !do_clinit_barriers()) {
4178 return false;
4179 }
4180 if (holder->is_being_initialized() || do_clinit_barriers()) {
4181 if (accessing_method->holder() == holder) {
4182 // Access inside a class. The barrier can be elided when access happens in <clinit>,
4183 // <init>, or a static method. In all those cases, there was an initialization
4184 // barrier on the holder klass passed.
4185 if (accessing_method->is_static_initializer() ||
4186 accessing_method->is_object_initializer() ||
4187 accessing_method->is_static()) {
4188 return false;
4189 }
4190 } else if (accessing_method->holder()->is_subclass_of(holder)) {
4191 // Access from a subclass. The barrier can be elided only when access happens in <clinit>.
4192 // In case of <init> or a static method, the barrier is on the subclass is not enough:
4193 // child class can become fully initialized while its parent class is still being initialized.
4194 if (accessing_method->is_static_initializer()) {
4195 return false;
4196 }
4197 }
4198 ciMethod* root = method(); // the root method of compilation
4199 if (root != accessing_method) {
4200 return needs_clinit_barrier(holder, root); // check access in the context of compilation root
4549 // Reset _print_inlining_list, it only contains destructed objects.
4550 // It is on the arena, so it will be freed when the arena is reset.
4551 _print_inlining_list = nullptr;
4552 // _print_inlining_stream won't be used anymore, either.
4553 print_inlining_reset();
4554 size_t end = ss.size();
4555 _print_inlining_output = NEW_ARENA_ARRAY(comp_arena(), char, end+1);
4556 strncpy(_print_inlining_output, ss.freeze(), end+1);
4557 _print_inlining_output[end] = 0;
4558 }
4559 }
4560
4561 void Compile::dump_print_inlining() {
4562 if (_print_inlining_output != nullptr) {
4563 tty->print_raw(_print_inlining_output);
4564 }
4565 }
4566
4567 void Compile::log_late_inline(CallGenerator* cg) {
4568 if (log() != nullptr) {
4569 log()->head("late_inline method='%d' inline_id='" JLONG_FORMAT "'", log()->identify(cg->method()),
4570 cg->unique_id());
4571 JVMState* p = cg->call_node()->jvms();
4572 while (p != nullptr) {
4573 log()->elem("jvms bci='%d' method='%d'", p->bci(), log()->identify(p->method()));
4574 p = p->caller();
4575 }
4576 log()->tail("late_inline");
4577 }
4578 }
4579
4580 void Compile::log_late_inline_failure(CallGenerator* cg, const char* msg) {
4581 log_late_inline(cg);
4582 if (log() != nullptr) {
4583 log()->inline_fail(msg);
4584 }
4585 }
4586
4587 void Compile::log_inline_id(CallGenerator* cg) {
4588 if (log() != nullptr) {
4589 // The LogCompilation tool needs a unique way to identify late
|