1 /* 2 * Copyright (c) 2020, Red Hat, Inc. All rights reserved. 3 * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 */ 24 25 /** 26 * @test 27 * @bug 8253566 28 * @bug 8295414 29 * @summary clazz.isAssignableFrom will return false for interface implementors 30 * @requires vm.compiler2.enabled 31 * 32 * @run main/othervm -XX:-BackgroundCompilation TestSubTypeCheckMacroTrichotomy 33 * @run main/othervm -XX:-BackgroundCompilation 34 * -XX:+IgnoreUnrecognizedVMOptions -XX:+StressReflectiveCode 35 * -XX:+UnlockDiagnosticVMOptions -XX:+ExpandSubTypeCheckAtParseTime 36 * -XX:-TieredCompilation -XX:CompileThreshold=100 TestSubTypeCheckMacroTrichotomy 37 * 38 */ 39 40 public class TestSubTypeCheckMacroTrichotomy { 41 public static void main(String[] args) { 42 for (int i = 0; i < 20_000; i++) { 43 final int res1 = test(A.class, B.class); 44 final int res2 = test(B.class, A.class); 45 final int res3 = test(A.class, C.class); 46 if (res1 != 0 || res2 != 1 || res3 != 0) { 47 throw new RuntimeException("test(A, B) = " + res1 + " test(B, A) = " + res2 + " test(A, C) = " + res3); 48 } 49 } 50 } 51 52 private static int test(Class<?> c1, Class<?> c2) { 53 if (c1 == null) { 54 } 55 if (c2 == null) { 56 } 57 int res = 0; 58 if (!c1.isAssignableFrom(c2)) { 59 if (c2.isAssignableFrom(c1)) { 60 res = 1; 61 } 62 } 63 return res; 64 } 65 66 private static class A { 67 } 68 69 private static class B extends A { 70 } 71 72 private static class C { 73 } 74 }