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