1 /*
 2  * Copyright (c) 2020, Red Hat, Inc. All rights reserved.
 3  * Copyright (c) 2022, 2024, 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:-TieredCompilation -XX:CompileThreshold=100 TestSubTypeCheckMacroTrichotomy
36  *
37  */
38 
39 public class TestSubTypeCheckMacroTrichotomy {
40     public static void main(String[] args) {
41         for (int i = 0; i < 20_000; i++) {
42             final int res1 = test(A.class, B.class);
43             final int res2 = test(B.class, A.class);
44             final int res3 = test(A.class, C.class);
45             if (res1 != 0 || res2 != 1 || res3 != 0) {
46                 throw new RuntimeException("test(A, B) = " + res1 + " test(B, A) = " + res2 + " test(A, C) = " + res3);
47             }
48         }
49     }
50 
51     private static int test(Class<?> c1, Class<?> c2) {
52         if (c1 == null) {
53         }
54         if (c2 == null) {
55         }
56         int res = 0;
57         if (!c1.isAssignableFrom(c2)) {
58             if (c2.isAssignableFrom(c1)) {
59                 res = 1;
60             }
61         }
62         return res;
63     }
64 
65     private static class A {
66     }
67 
68     private static class B extends A {
69     }
70 
71     private static class C {
72     }
73 }