21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "ci/ciCallSite.hpp"
27 #include "ci/ciMethodHandle.hpp"
28 #include "ci/ciSymbols.hpp"
29 #include "classfile/vmSymbols.hpp"
30 #include "compiler/compileBroker.hpp"
31 #include "compiler/compileLog.hpp"
32 #include "interpreter/linkResolver.hpp"
33 #include "logging/log.hpp"
34 #include "logging/logLevel.hpp"
35 #include "logging/logMessage.hpp"
36 #include "logging/logStream.hpp"
37 #include "opto/addnode.hpp"
38 #include "opto/callGenerator.hpp"
39 #include "opto/castnode.hpp"
40 #include "opto/cfgnode.hpp"
41 #include "opto/mulnode.hpp"
42 #include "opto/parse.hpp"
43 #include "opto/rootnode.hpp"
44 #include "opto/runtime.hpp"
45 #include "opto/subnode.hpp"
46 #include "prims/methodHandles.hpp"
47 #include "runtime/sharedRuntime.hpp"
48 #include "utilities/macros.hpp"
49 #if INCLUDE_JFR
50 #include "jfr/jfr.hpp"
51 #endif
52
53 static void print_trace_type_profile(outputStream* out, int depth, ciKlass* prof_klass, int site_count, int receiver_count) {
54 CompileTask::print_inline_indent(depth, out);
55 out->print(" \\-> TypeProfile (%d/%d counts) = ", receiver_count, site_count);
56 prof_klass->name()->print_symbol_on(out);
57 out->cr();
58 }
59
60 static void trace_type_profile(Compile* C, ciMethod* method, int depth, int bci, ciMethod* prof_method,
560 // Push appendix argument (MethodType, CallSite, etc.), if one.
561 if (iter().has_appendix()) {
562 ciObject* appendix_arg = iter().get_appendix();
563 const TypeOopPtr* appendix_arg_type = TypeOopPtr::make_from_constant(appendix_arg, /* require_const= */ true);
564 Node* appendix_arg_node = _gvn.makecon(appendix_arg_type);
565 push(appendix_arg_node);
566 }
567
568 // ---------------------
569 // Does Class Hierarchy Analysis reveal only a single target of a v-call?
570 // Then we may inline or make a static call, but become dependent on there being only 1 target.
571 // Does the call-site type profile reveal only one receiver?
572 // Then we may introduce a run-time check and inline on the path where it succeeds.
573 // The other path may uncommon_trap, check for another receiver, or do a v-call.
574
575 // Try to get the most accurate receiver type
576 ciMethod* callee = orig_callee;
577 int vtable_index = Method::invalid_vtable_index;
578 bool call_does_dispatch = false;
579
580 // Speculative type of the receiver if any
581 ciKlass* speculative_receiver_type = nullptr;
582 if (is_virtual_or_interface) {
583 Node* receiver_node = stack(sp() - nargs);
584 const TypeOopPtr* receiver_type = _gvn.type(receiver_node)->isa_oopptr();
585 // call_does_dispatch and vtable_index are out-parameters. They might be changed.
586 // For arrays, klass below is Object. When vtable calls are used,
587 // resolving the call with Object would allow an illegal call to
588 // finalize() on an array. We use holder instead: illegal calls to
589 // finalize() won't be compiled as vtable calls (IC call
590 // resolution will catch the illegal call) and the few legal calls
591 // on array types won't be either.
592 callee = C->optimize_virtual_call(method(), klass, holder, orig_callee,
593 receiver_type, is_virtual,
594 call_does_dispatch, vtable_index); // out-parameters
595 speculative_receiver_type = receiver_type != nullptr ? receiver_type->speculative_type() : nullptr;
596 }
597
598 // Additional receiver subtype checks for interface calls via invokespecial or invokeinterface.
599 ciKlass* receiver_constraint = nullptr;
600 if (iter().cur_bc_raw() == Bytecodes::_invokespecial && !orig_callee->is_object_initializer()) {
601 ciInstanceKlass* calling_klass = method()->holder();
602 ciInstanceKlass* sender_klass = calling_klass;
603 if (sender_klass->is_interface()) {
604 receiver_constraint = sender_klass;
605 }
606 } else if (iter().cur_bc_raw() == Bytecodes::_invokeinterface && orig_callee->is_private()) {
607 assert(holder->is_interface(), "How did we get a non-interface method here!");
608 receiver_constraint = holder;
609 }
610
611 if (receiver_constraint != nullptr) {
612 Node* receiver_node = stack(sp() - nargs);
613 Node* cls_node = makecon(TypeKlassPtr::make(receiver_constraint, Type::trust_interfaces));
614 Node* bad_type_ctrl = nullptr;
615 Node* casted_receiver = gen_checkcast(receiver_node, cls_node, &bad_type_ctrl);
616 if (bad_type_ctrl != nullptr) {
617 PreserveJVMState pjvms(this);
618 set_control(bad_type_ctrl);
619 uncommon_trap(Deoptimization::Reason_class_check,
620 Deoptimization::Action_none);
710
711 assert(check_call_consistency(jvms, cg), "inconsistent info");
712
713 if (!stopped()) {
714 // This was some sort of virtual call, which did a null check for us.
715 // Now we can assert receiver-not-null, on the normal return path.
716 if (receiver != nullptr && cg->is_virtual()) {
717 Node* cast = cast_not_null(receiver);
718 // %%% assert(receiver == cast, "should already have cast the receiver");
719 }
720
721 ciType* rtype = cg->method()->return_type();
722 ciType* ctype = declared_signature->return_type();
723
724 if (Bytecodes::has_optional_appendix(iter().cur_bc_raw()) || is_signature_polymorphic) {
725 // Be careful here with return types.
726 if (ctype != rtype) {
727 BasicType rt = rtype->basic_type();
728 BasicType ct = ctype->basic_type();
729 if (ct == T_VOID) {
730 // It's OK for a method to return a value that is discarded.
731 // The discarding does not require any special action from the caller.
732 // The Java code knows this, at VerifyType.isNullConversion.
733 pop_node(rt); // whatever it was, pop it
734 } else if (rt == T_INT || is_subword_type(rt)) {
735 // Nothing. These cases are handled in lambda form bytecode.
736 assert(ct == T_INT || is_subword_type(ct), "must match: rt=%s, ct=%s", type2name(rt), type2name(ct));
737 } else if (is_reference_type(rt)) {
738 assert(is_reference_type(ct), "rt=%s, ct=%s", type2name(rt), type2name(ct));
739 if (ctype->is_loaded()) {
740 const TypeOopPtr* arg_type = TypeOopPtr::make_from_klass(rtype->as_klass());
741 const Type* sig_type = TypeOopPtr::make_from_klass(ctype->as_klass());
742 if (arg_type != nullptr && !arg_type->higher_equal(sig_type)) {
743 Node* retnode = pop();
744 Node* cast_obj = _gvn.transform(new CheckCastPPNode(control(), retnode, sig_type));
745 push(cast_obj);
746 }
747 }
748 } else {
749 assert(rt == ct, "unexpected mismatch: rt=%s, ct=%s", type2name(rt), type2name(ct));
750 // push a zero; it's better than getting an oop/int mismatch
768 // If the return type of the method is not loaded, assert that the
769 // value we got is a null. Otherwise, we need to recompile.
770 if (!rtype->is_loaded()) {
771 if (PrintOpto && (Verbose || WizardMode)) {
772 method()->print_name(); tty->print_cr(" asserting nullness of result at bci: %d", bci());
773 cg->method()->print_name(); tty->cr();
774 }
775 if (C->log() != nullptr) {
776 C->log()->elem("assert_null reason='return' klass='%d'",
777 C->log()->identify(rtype));
778 }
779 // If there is going to be a trap, put it at the next bytecode:
780 set_bci(iter().next_bci());
781 null_assert(peek());
782 set_bci(iter().cur_bci()); // put it back
783 }
784 BasicType ct = ctype->basic_type();
785 if (is_reference_type(ct)) {
786 record_profiled_return_for_speculation();
787 }
788 }
789
790 // Restart record of parsing work after possible inlining of call
791 #ifndef PRODUCT
792 parse_histogram()->set_initial_state(bc());
793 #endif
794 }
795
796 //---------------------------catch_call_exceptions-----------------------------
797 // Put a Catch and CatchProj nodes behind a just-created call.
798 // Send their caught exceptions to the proper handler.
799 // This may be used after a call to the rethrow VM stub,
800 // when it is needed to process unloaded exception classes.
801 void Parse::catch_call_exceptions(ciExceptionHandlerStream& handlers) {
802 // Exceptions are delivered through this channel:
803 Node* i_o = this->i_o();
804
805 // Add a CatchNode.
806 Arena tmp_mem{mtCompiler};
807 GrowableArray<int> bcis(&tmp_mem, 8, 0, -1);
|
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "ci/ciCallSite.hpp"
27 #include "ci/ciMethodHandle.hpp"
28 #include "ci/ciSymbols.hpp"
29 #include "classfile/vmSymbols.hpp"
30 #include "compiler/compileBroker.hpp"
31 #include "compiler/compileLog.hpp"
32 #include "interpreter/linkResolver.hpp"
33 #include "logging/log.hpp"
34 #include "logging/logLevel.hpp"
35 #include "logging/logMessage.hpp"
36 #include "logging/logStream.hpp"
37 #include "opto/addnode.hpp"
38 #include "opto/callGenerator.hpp"
39 #include "opto/castnode.hpp"
40 #include "opto/cfgnode.hpp"
41 #include "opto/inlinetypenode.hpp"
42 #include "opto/mulnode.hpp"
43 #include "opto/parse.hpp"
44 #include "opto/rootnode.hpp"
45 #include "opto/runtime.hpp"
46 #include "opto/subnode.hpp"
47 #include "prims/methodHandles.hpp"
48 #include "runtime/sharedRuntime.hpp"
49 #include "utilities/macros.hpp"
50 #if INCLUDE_JFR
51 #include "jfr/jfr.hpp"
52 #endif
53
54 static void print_trace_type_profile(outputStream* out, int depth, ciKlass* prof_klass, int site_count, int receiver_count) {
55 CompileTask::print_inline_indent(depth, out);
56 out->print(" \\-> TypeProfile (%d/%d counts) = ", receiver_count, site_count);
57 prof_klass->name()->print_symbol_on(out);
58 out->cr();
59 }
60
61 static void trace_type_profile(Compile* C, ciMethod* method, int depth, int bci, ciMethod* prof_method,
561 // Push appendix argument (MethodType, CallSite, etc.), if one.
562 if (iter().has_appendix()) {
563 ciObject* appendix_arg = iter().get_appendix();
564 const TypeOopPtr* appendix_arg_type = TypeOopPtr::make_from_constant(appendix_arg, /* require_const= */ true);
565 Node* appendix_arg_node = _gvn.makecon(appendix_arg_type);
566 push(appendix_arg_node);
567 }
568
569 // ---------------------
570 // Does Class Hierarchy Analysis reveal only a single target of a v-call?
571 // Then we may inline or make a static call, but become dependent on there being only 1 target.
572 // Does the call-site type profile reveal only one receiver?
573 // Then we may introduce a run-time check and inline on the path where it succeeds.
574 // The other path may uncommon_trap, check for another receiver, or do a v-call.
575
576 // Try to get the most accurate receiver type
577 ciMethod* callee = orig_callee;
578 int vtable_index = Method::invalid_vtable_index;
579 bool call_does_dispatch = false;
580
581 // Detect the call to the object or abstract class constructor at the end of a value constructor to know when we are done initializing the larval
582 if (orig_callee->is_object_constructor() && (orig_callee->holder()->is_abstract() || orig_callee->holder()->is_java_lang_Object()) && stack(sp() - nargs)->is_InlineType()) {
583 assert(method()->is_object_constructor() && (method()->holder()->is_inlinetype() || method()->holder()->is_abstract()), "Unexpected caller");
584 InlineTypeNode* receiver = stack(sp() - nargs)->as_InlineType();
585 InlineTypeNode* clone = receiver->clone_if_required(&_gvn, _map);
586 clone->set_is_larval(false);
587 clone = _gvn.transform(clone)->as_InlineType();
588 replace_in_map(receiver, clone);
589
590 if (_caller->has_method()) {
591 // Get receiver from the caller map and update it in the exit map now that we are done initializing it
592 Node* receiver_in_caller = _caller->map()->argument(_caller, 0);
593 assert(receiver_in_caller->bottom_type()->inline_klass() == receiver->bottom_type()->inline_klass(), "Receiver type mismatch");
594 _exits.map()->replace_edge(receiver_in_caller, clone, &_gvn);
595 }
596 }
597
598 // Speculative type of the receiver if any
599 ciKlass* speculative_receiver_type = nullptr;
600 if (is_virtual_or_interface) {
601 Node* receiver_node = stack(sp() - nargs);
602 const TypeOopPtr* receiver_type = _gvn.type(receiver_node)->isa_oopptr();
603 // call_does_dispatch and vtable_index are out-parameters. They might be changed.
604 // For arrays, klass below is Object. When vtable calls are used,
605 // resolving the call with Object would allow an illegal call to
606 // finalize() on an array. We use holder instead: illegal calls to
607 // finalize() won't be compiled as vtable calls (IC call
608 // resolution will catch the illegal call) and the few legal calls
609 // on array types won't be either.
610 callee = C->optimize_virtual_call(method(), klass, holder, orig_callee,
611 receiver_type, is_virtual,
612 call_does_dispatch, vtable_index); // out-parameters
613 speculative_receiver_type = receiver_type != nullptr ? receiver_type->speculative_type() : nullptr;
614 }
615
616 // Additional receiver subtype checks for interface calls via invokespecial or invokeinterface.
617 ciKlass* receiver_constraint = nullptr;
618 if (iter().cur_bc_raw() == Bytecodes::_invokespecial && !orig_callee->is_object_constructor()) {
619 ciInstanceKlass* calling_klass = method()->holder();
620 ciInstanceKlass* sender_klass = calling_klass;
621 if (sender_klass->is_interface()) {
622 receiver_constraint = sender_klass;
623 }
624 } else if (iter().cur_bc_raw() == Bytecodes::_invokeinterface && orig_callee->is_private()) {
625 assert(holder->is_interface(), "How did we get a non-interface method here!");
626 receiver_constraint = holder;
627 }
628
629 if (receiver_constraint != nullptr) {
630 Node* receiver_node = stack(sp() - nargs);
631 Node* cls_node = makecon(TypeKlassPtr::make(receiver_constraint, Type::trust_interfaces));
632 Node* bad_type_ctrl = nullptr;
633 Node* casted_receiver = gen_checkcast(receiver_node, cls_node, &bad_type_ctrl);
634 if (bad_type_ctrl != nullptr) {
635 PreserveJVMState pjvms(this);
636 set_control(bad_type_ctrl);
637 uncommon_trap(Deoptimization::Reason_class_check,
638 Deoptimization::Action_none);
728
729 assert(check_call_consistency(jvms, cg), "inconsistent info");
730
731 if (!stopped()) {
732 // This was some sort of virtual call, which did a null check for us.
733 // Now we can assert receiver-not-null, on the normal return path.
734 if (receiver != nullptr && cg->is_virtual()) {
735 Node* cast = cast_not_null(receiver);
736 // %%% assert(receiver == cast, "should already have cast the receiver");
737 }
738
739 ciType* rtype = cg->method()->return_type();
740 ciType* ctype = declared_signature->return_type();
741
742 if (Bytecodes::has_optional_appendix(iter().cur_bc_raw()) || is_signature_polymorphic) {
743 // Be careful here with return types.
744 if (ctype != rtype) {
745 BasicType rt = rtype->basic_type();
746 BasicType ct = ctype->basic_type();
747 if (ct == T_VOID) {
748 // It's OK for a method to return a value that is discarded.
749 // The discarding does not require any special action from the caller.
750 // The Java code knows this, at VerifyType.isNullConversion.
751 pop_node(rt); // whatever it was, pop it
752 } else if (rt == T_INT || is_subword_type(rt)) {
753 // Nothing. These cases are handled in lambda form bytecode.
754 assert(ct == T_INT || is_subword_type(ct), "must match: rt=%s, ct=%s", type2name(rt), type2name(ct));
755 } else if (is_reference_type(rt)) {
756 assert(is_reference_type(ct), "rt=%s, ct=%s", type2name(rt), type2name(ct));
757 if (ctype->is_loaded()) {
758 const TypeOopPtr* arg_type = TypeOopPtr::make_from_klass(rtype->as_klass());
759 const Type* sig_type = TypeOopPtr::make_from_klass(ctype->as_klass());
760 if (arg_type != nullptr && !arg_type->higher_equal(sig_type)) {
761 Node* retnode = pop();
762 Node* cast_obj = _gvn.transform(new CheckCastPPNode(control(), retnode, sig_type));
763 push(cast_obj);
764 }
765 }
766 } else {
767 assert(rt == ct, "unexpected mismatch: rt=%s, ct=%s", type2name(rt), type2name(ct));
768 // push a zero; it's better than getting an oop/int mismatch
786 // If the return type of the method is not loaded, assert that the
787 // value we got is a null. Otherwise, we need to recompile.
788 if (!rtype->is_loaded()) {
789 if (PrintOpto && (Verbose || WizardMode)) {
790 method()->print_name(); tty->print_cr(" asserting nullness of result at bci: %d", bci());
791 cg->method()->print_name(); tty->cr();
792 }
793 if (C->log() != nullptr) {
794 C->log()->elem("assert_null reason='return' klass='%d'",
795 C->log()->identify(rtype));
796 }
797 // If there is going to be a trap, put it at the next bytecode:
798 set_bci(iter().next_bci());
799 null_assert(peek());
800 set_bci(iter().cur_bci()); // put it back
801 }
802 BasicType ct = ctype->basic_type();
803 if (is_reference_type(ct)) {
804 record_profiled_return_for_speculation();
805 }
806 if (rtype->is_inlinetype() && !peek()->is_InlineType()) {
807 Node* retnode = pop();
808 retnode = InlineTypeNode::make_from_oop(this, retnode, rtype->as_inline_klass(), !gvn().type(retnode)->maybe_null());
809 push_node(T_OBJECT, retnode);
810 }
811
812 // Did we inline a value class constructor from another value class constructor?
813 if (_caller->has_method() && cg->is_inline() && cg->method()->is_object_constructor() && cg->method()->holder()->is_inlinetype() &&
814 _method->is_object_constructor() && _method->holder()->is_inlinetype() && receiver == _caller->map()->argument(_caller, 0)) {
815 // Update the receiver in the exit map because the constructor call updated it.
816 // MethodLiveness::BasicBlock::compute_gen_kill_single ensures that the receiver in local(0) is still live.
817 assert(local(0)->is_InlineType(), "Unexpected receiver");
818 assert(receiver->bottom_type()->inline_klass() == local(0)->bottom_type()->inline_klass(), "Receiver type mismatch");
819 _exits.map()->replace_edge(receiver, local(0), &_gvn);
820 }
821 }
822
823 // Restart record of parsing work after possible inlining of call
824 #ifndef PRODUCT
825 parse_histogram()->set_initial_state(bc());
826 #endif
827 }
828
829 //---------------------------catch_call_exceptions-----------------------------
830 // Put a Catch and CatchProj nodes behind a just-created call.
831 // Send their caught exceptions to the proper handler.
832 // This may be used after a call to the rethrow VM stub,
833 // when it is needed to process unloaded exception classes.
834 void Parse::catch_call_exceptions(ciExceptionHandlerStream& handlers) {
835 // Exceptions are delivered through this channel:
836 Node* i_o = this->i_o();
837
838 // Add a CatchNode.
839 Arena tmp_mem{mtCompiler};
840 GrowableArray<int> bcis(&tmp_mem, 8, 0, -1);
|