1 /*
2 * Copyright (c) 1998, 2016, 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 *
652 }
653
654 if (Bytecodes::has_optional_appendix(iter().cur_bc_raw()) || is_signature_polymorphic) {
655 // Be careful here with return types.
656 if (ctype != rtype) {
657 BasicType rt = rtype->basic_type();
658 BasicType ct = ctype->basic_type();
659 if (ct == T_VOID) {
660 // It's OK for a method to return a value that is discarded.
661 // The discarding does not require any special action from the caller.
662 // The Java code knows this, at VerifyType.isNullConversion.
663 pop_node(rt); // whatever it was, pop it
664 } else if (rt == T_INT || is_subword_type(rt)) {
665 // Nothing. These cases are handled in lambda form bytecode.
666 assert(ct == T_INT || is_subword_type(ct), "must match: rt=%s, ct=%s", type2name(rt), type2name(ct));
667 } else if (rt == T_OBJECT || rt == T_ARRAY) {
668 assert(ct == T_OBJECT || ct == T_ARRAY || ct == T_VALUETYPE, "rt=%s, ct=%s", type2name(rt), type2name(ct));
669 if (ctype->is_loaded()) {
670 const TypeOopPtr* arg_type = TypeOopPtr::make_from_klass(rtype->as_klass());
671 const Type* sig_type = TypeOopPtr::make_from_klass(ctype->as_klass());
672 if (arg_type != NULL && !arg_type->higher_equal(sig_type)) {
673 Node* retnode = pop();
674 Node* cast_obj = _gvn.transform(new CheckCastPPNode(control(), retnode, sig_type));
675 if (ct == T_VALUETYPE) {
676 // We will deoptimize if the return value is null and then need to continue execution after the call
677 cast_obj = ValueTypeNode::make_from_oop(this, cast_obj, ctype->as_value_klass(), /* buffer_check */ false, /* null2default */ false, iter().next_bci());
678 }
679 push(cast_obj);
680 }
681 }
682 } else if (rt == T_VALUETYPE) {
683 assert(ct == T_OBJECT, "object expected but got ct=%s", type2name(ct));
684 ValueTypeNode* vt = pop()->as_ValueType();
685 vt = vt->allocate(this)->as_ValueType();
686 Node* vtptr = ValueTypePtrNode::make_from_value_type(_gvn, vt);
687 push(vtptr);
688 } else {
689 assert(rt == ct, "unexpected mismatch: rt=%s, ct=%s", type2name(rt), type2name(ct));
690 // push a zero; it's better than getting an oop/int mismatch
691 pop_node(rt);
|
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 *
652 }
653
654 if (Bytecodes::has_optional_appendix(iter().cur_bc_raw()) || is_signature_polymorphic) {
655 // Be careful here with return types.
656 if (ctype != rtype) {
657 BasicType rt = rtype->basic_type();
658 BasicType ct = ctype->basic_type();
659 if (ct == T_VOID) {
660 // It's OK for a method to return a value that is discarded.
661 // The discarding does not require any special action from the caller.
662 // The Java code knows this, at VerifyType.isNullConversion.
663 pop_node(rt); // whatever it was, pop it
664 } else if (rt == T_INT || is_subword_type(rt)) {
665 // Nothing. These cases are handled in lambda form bytecode.
666 assert(ct == T_INT || is_subword_type(ct), "must match: rt=%s, ct=%s", type2name(rt), type2name(ct));
667 } else if (rt == T_OBJECT || rt == T_ARRAY) {
668 assert(ct == T_OBJECT || ct == T_ARRAY || ct == T_VALUETYPE, "rt=%s, ct=%s", type2name(rt), type2name(ct));
669 if (ctype->is_loaded()) {
670 const TypeOopPtr* arg_type = TypeOopPtr::make_from_klass(rtype->as_klass());
671 const Type* sig_type = TypeOopPtr::make_from_klass(ctype->as_klass());
672 if (ct == T_VALUETYPE && cg->method()->get_Method()->is_returning_vt()) {
673 // A NULL ValueType cannot be returned to compiled code. The 'areturn' bytecode
674 // handler will deoptimize its caller if it is about to return a NULL ValueType.
675 // (See comments inside TypeTuple::make_range).
676 sig_type = sig_type->join_speculative(TypePtr::NOTNULL);
677 }
678 if (arg_type != NULL && !arg_type->higher_equal(sig_type)) {
679 Node* retnode = pop();
680 Node* cast_obj = _gvn.transform(new CheckCastPPNode(control(), retnode, sig_type));
681 if (ct == T_VALUETYPE) {
682 // We will deoptimize if the return value is null and then need to continue execution after the call
683 cast_obj = ValueTypeNode::make_from_oop(this, cast_obj, ctype->as_value_klass(), /* buffer_check */ false, /* null2default */ false, iter().next_bci());
684 }
685 push(cast_obj);
686 }
687 }
688 } else if (rt == T_VALUETYPE) {
689 assert(ct == T_OBJECT, "object expected but got ct=%s", type2name(ct));
690 ValueTypeNode* vt = pop()->as_ValueType();
691 vt = vt->allocate(this)->as_ValueType();
692 Node* vtptr = ValueTypePtrNode::make_from_value_type(_gvn, vt);
693 push(vtptr);
694 } else {
695 assert(rt == ct, "unexpected mismatch: rt=%s, ct=%s", type2name(rt), type2name(ct));
696 // push a zero; it's better than getting an oop/int mismatch
697 pop_node(rt);
|