1 /*
2 * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
685
686 // Round double result after a call from strict to non-strict code
687 round_double_result(cg->method());
688
689 ciType* rtype = cg->method()->return_type();
690 ciType* ctype = declared_signature->return_type();
691
692 if (Bytecodes::has_optional_appendix(iter().cur_bc_raw()) || is_signature_polymorphic) {
693 // Be careful here with return types.
694 if (ctype != rtype) {
695 BasicType rt = rtype->basic_type();
696 BasicType ct = ctype->basic_type();
697 if (ct == T_VOID) {
698 // It's OK for a method to return a value that is discarded.
699 // The discarding does not require any special action from the caller.
700 // The Java code knows this, at VerifyType.isNullConversion.
701 pop_node(rt); // whatever it was, pop it
702 } else if (rt == T_INT || is_subword_type(rt)) {
703 // Nothing. These cases are handled in lambda form bytecode.
704 assert(ct == T_INT || is_subword_type(ct), "must match: rt=%s, ct=%s", type2name(rt), type2name(ct));
705 } else if (rt == T_OBJECT || rt == T_ARRAY) {
706 assert(ct == T_OBJECT || ct == T_ARRAY, "rt=%s, ct=%s", type2name(rt), type2name(ct));
707 if (ctype->is_loaded()) {
708 const TypeOopPtr* arg_type = TypeOopPtr::make_from_klass(rtype->as_klass());
709 const Type* sig_type = TypeOopPtr::make_from_klass(ctype->as_klass());
710 if (arg_type != NULL && !arg_type->higher_equal(sig_type)) {
711 Node* retnode = pop();
712 Node* cast_obj = _gvn.transform(new CheckCastPPNode(control(), retnode, sig_type));
713 push(cast_obj);
714 }
715 }
716 } else {
717 assert(rt == ct, "unexpected mismatch: rt=%s, ct=%s", type2name(rt), type2name(ct));
718 // push a zero; it's better than getting an oop/int mismatch
719 pop_node(rt);
720 Node* retnode = zerocon(ct);
721 push_node(ct, retnode);
722 }
723 // Now that the value is well-behaved, continue with the call-site type.
724 rtype = ctype;
725 }
726 } else {
733 "mismatched return types: rtype=%s, ctype=%s", rtype->name(), ctype->name());
734 }
735
736 // If the return type of the method is not loaded, assert that the
737 // value we got is a null. Otherwise, we need to recompile.
738 if (!rtype->is_loaded()) {
739 if (PrintOpto && (Verbose || WizardMode)) {
740 method()->print_name(); tty->print_cr(" asserting nullness of result at bci: %d", bci());
741 cg->method()->print_name(); tty->cr();
742 }
743 if (C->log() != NULL) {
744 C->log()->elem("assert_null reason='return' klass='%d'",
745 C->log()->identify(rtype));
746 }
747 // If there is going to be a trap, put it at the next bytecode:
748 set_bci(iter().next_bci());
749 null_assert(peek());
750 set_bci(iter().cur_bci()); // put it back
751 }
752 BasicType ct = ctype->basic_type();
753 if (ct == T_OBJECT || ct == T_ARRAY) {
754 record_profiled_return_for_speculation();
755 }
756 }
757
758 // Restart record of parsing work after possible inlining of call
759 #ifndef PRODUCT
760 parse_histogram()->set_initial_state(bc());
761 #endif
762 }
763
764 //---------------------------catch_call_exceptions-----------------------------
765 // Put a Catch and CatchProj nodes behind a just-created call.
766 // Send their caught exceptions to the proper handler.
767 // This may be used after a call to the rethrow VM stub,
768 // when it is needed to process unloaded exception classes.
769 void Parse::catch_call_exceptions(ciExceptionHandlerStream& handlers) {
770 // Exceptions are delivered through this channel:
771 Node* i_o = this->i_o();
772
773 // Add a CatchNode.
|
1 /*
2 * Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
685
686 // Round double result after a call from strict to non-strict code
687 round_double_result(cg->method());
688
689 ciType* rtype = cg->method()->return_type();
690 ciType* ctype = declared_signature->return_type();
691
692 if (Bytecodes::has_optional_appendix(iter().cur_bc_raw()) || is_signature_polymorphic) {
693 // Be careful here with return types.
694 if (ctype != rtype) {
695 BasicType rt = rtype->basic_type();
696 BasicType ct = ctype->basic_type();
697 if (ct == T_VOID) {
698 // It's OK for a method to return a value that is discarded.
699 // The discarding does not require any special action from the caller.
700 // The Java code knows this, at VerifyType.isNullConversion.
701 pop_node(rt); // whatever it was, pop it
702 } else if (rt == T_INT || is_subword_type(rt)) {
703 // Nothing. These cases are handled in lambda form bytecode.
704 assert(ct == T_INT || is_subword_type(ct), "must match: rt=%s, ct=%s", type2name(rt), type2name(ct));
705 } else if (is_reference_type(rt)) {
706 assert(is_reference_type(ct), "rt=%s, ct=%s", type2name(rt), type2name(ct));
707 if (ctype->is_loaded()) {
708 const TypeOopPtr* arg_type = TypeOopPtr::make_from_klass(rtype->as_klass());
709 const Type* sig_type = TypeOopPtr::make_from_klass(ctype->as_klass());
710 if (arg_type != NULL && !arg_type->higher_equal(sig_type)) {
711 Node* retnode = pop();
712 Node* cast_obj = _gvn.transform(new CheckCastPPNode(control(), retnode, sig_type));
713 push(cast_obj);
714 }
715 }
716 } else {
717 assert(rt == ct, "unexpected mismatch: rt=%s, ct=%s", type2name(rt), type2name(ct));
718 // push a zero; it's better than getting an oop/int mismatch
719 pop_node(rt);
720 Node* retnode = zerocon(ct);
721 push_node(ct, retnode);
722 }
723 // Now that the value is well-behaved, continue with the call-site type.
724 rtype = ctype;
725 }
726 } else {
733 "mismatched return types: rtype=%s, ctype=%s", rtype->name(), ctype->name());
734 }
735
736 // If the return type of the method is not loaded, assert that the
737 // value we got is a null. Otherwise, we need to recompile.
738 if (!rtype->is_loaded()) {
739 if (PrintOpto && (Verbose || WizardMode)) {
740 method()->print_name(); tty->print_cr(" asserting nullness of result at bci: %d", bci());
741 cg->method()->print_name(); tty->cr();
742 }
743 if (C->log() != NULL) {
744 C->log()->elem("assert_null reason='return' klass='%d'",
745 C->log()->identify(rtype));
746 }
747 // If there is going to be a trap, put it at the next bytecode:
748 set_bci(iter().next_bci());
749 null_assert(peek());
750 set_bci(iter().cur_bci()); // put it back
751 }
752 BasicType ct = ctype->basic_type();
753 if (is_reference_type(ct)) {
754 record_profiled_return_for_speculation();
755 }
756 }
757
758 // Restart record of parsing work after possible inlining of call
759 #ifndef PRODUCT
760 parse_histogram()->set_initial_state(bc());
761 #endif
762 }
763
764 //---------------------------catch_call_exceptions-----------------------------
765 // Put a Catch and CatchProj nodes behind a just-created call.
766 // Send their caught exceptions to the proper handler.
767 // This may be used after a call to the rethrow VM stub,
768 // when it is needed to process unloaded exception classes.
769 void Parse::catch_call_exceptions(ciExceptionHandlerStream& handlers) {
770 // Exceptions are delivered through this channel:
771 Node* i_o = this->i_o();
772
773 // Add a CatchNode.
|