diff --git a/src/java.base/share/classes/java/lang/invoke/DirectMethodHandle.java b/src/java.base/share/classes/java/lang/invoke/DirectMethodHandle.java index cd45e6e23ff..0052831be36 100644 --- a/src/java.base/share/classes/java/lang/invoke/DirectMethodHandle.java +++ b/src/java.base/share/classes/java/lang/invoke/DirectMethodHandle.java @@ -30,7 +30,6 @@ import jdk.internal.vm.annotation.ForceInline; import jdk.internal.vm.annotation.Stable; import sun.invoke.util.ValueConversions; import sun.invoke.util.VerifyAccess; -import sun.invoke.util.VerifyType; import sun.invoke.util.Wrapper; import java.util.Arrays; @@ -629,12 +628,14 @@ sealed class DirectMethodHandle extends MethodHandle { private static final LambdaForm[] ACCESSOR_FORMS = new LambdaForm[afIndex(AF_LIMIT, false, 0)]; static int ftypeKind(Class> ftype) { - if (ftype.isPrimitive()) + if (ftype.isPrimitive()) { return Wrapper.forPrimitiveType(ftype).ordinal(); - else if (VerifyType.isNullReferenceConversion(Object.class, ftype)) + } else if (ftype.isInterface() || ftype.isAssignableFrom(Object.class)) { + // retyping can be done without a cast return FT_UNCHECKED_REF; - else + } else { return FT_CHECKED_REF; + } } /** diff --git a/src/java.base/share/classes/sun/invoke/util/VerifyType.java b/src/java.base/share/classes/sun/invoke/util/VerifyType.java index ce37b88c76d..7ede11b150e 100644 --- a/src/java.base/share/classes/sun/invoke/util/VerifyType.java +++ b/src/java.base/share/classes/sun/invoke/util/VerifyType.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -85,19 +85,6 @@ public class VerifyType { return dw.bitWidth() > sw.bitWidth(); } - /** - * Specialization of isNullConversion to reference types. - * @param src the type of a stacked value - * @param dst the reference type by which we'd like to treat it - * @return whether the retyping can be done without a cast - */ - public static boolean isNullReferenceConversion(Class> src, Class> dst) { - assert(!dst.isPrimitive()); - if (dst.isInterface()) return true; // verifier allows this - if (isNullType(src)) return true; - return dst.isAssignableFrom(src); - } - /** * Is the given type java.lang.Null or an equivalent null-only type? */ @@ -128,75 +115,4 @@ public class VerifyType { return false; return isNullConversion(recv.returnType(), call.returnType(), keepInterfaces); } - - /** - * Determine if the JVM verifier allows a value of type call to be - * passed to a formal parameter (or return variable) of type recv. - * Returns 1 if the verifier allows the types to match without conversion. - * Returns -1 if the types can be made to match by a JVM-supported adapter. - * Cases supported are: - *