1 /*
2 * Copyright (c) 2024, 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 */
23
24 import jdk.incubator.code.Reflect;
25
26 /*
27 * @test
28 * @summary Smoke test for code reflection with super qualified expressions.
29 * @modules jdk.incubator.code
30 * @build SuperTest
31 * @build CodeReflectionTester
32 * @run main CodeReflectionTester SuperTest
33 */
34
35 public class SuperTest extends SuperClass implements SuperInterface {
36 static int sf;
37 int f;
38
39 @Override
40 public void get() {}
41 static void sget() {}
42
43 @Reflect
44 @IR("""
45 func @"superClassFieldAccess" (%0 : java.type:"SuperTest")java.type:"void" -> {
46 %1 : java.type:"int" = field.load %0 @java.ref:"SuperClass::f:int";
47 %2 : Var<java.type:"int"> = var %1 @"i";
48 %3 : java.type:"int" = constant @1;
49 field.store %0 %3 @java.ref:"SuperClass::f:int";
50 %4 : java.type:"int" = field.load %0 @java.ref:"SuperClass::f:int";
51 var.store %2 %4;
52 %5 : java.type:"int" = constant @1;
53 field.store %0 %5 @java.ref:"SuperClass::f:int";
54 %6 : java.type:"int" = field.load @java.ref:"SuperClass::sf:int";
55 var.store %2 %6;
56 %7 : java.type:"int" = constant @1;
57 field.store %7 @java.ref:"SuperClass::sf:int";
58 %8 : java.type:"int" = field.load @java.ref:"SuperClass::sf:int";
59 var.store %2 %8;
60 %9 : java.type:"int" = constant @1;
61 field.store %9 @java.ref:"SuperClass::sf:int";
62 return;
63 };
64 """)
65 public void superClassFieldAccess() {
66 int i = super.f;
67 super.f = 1;
68 i = SuperTest.super.f;
69 SuperTest.super.f = 1;
70
71 i = super.sf;
72 super.sf = 1;
73 i = SuperTest.super.sf;
74 SuperTest.super.sf = 1;
75 }
76
77 @Reflect
78 @IR("""
79 func @"superClassMethodInvocation" (%0 : java.type:"SuperTest")java.type:"void" -> {
80 invoke %0 @java.ref:"SuperClass::get():void" @invoke.kind="SUPER";
81 invoke %0 @java.ref:"SuperClass::get():void" @invoke.kind="SUPER";
82 invoke @java.ref:"SuperClass::sget():void";
83 invoke @java.ref:"SuperClass::sget():void";
84 return;
85 };
86 """)
87 public void superClassMethodInvocation() {
88 super.get();
89 SuperTest.super.get();
90
91 super.sget();
92 SuperTest.super.sget();
93 }
94
95 @Reflect
96 @IR("""
97 func @"superInterfaceMethodInvocation" (%0 : java.type:"SuperTest")java.type:"void" -> {
98 invoke %0 @java.ref:"SuperInterface::get():void" @invoke.kind="SUPER";
99 return;
100 };
101 """)
102 public void superInterfaceMethodInvocation() {
103 SuperInterface.super.get();
104 }
105 }
106
107 class SuperClass {
108 static int sf;
109 int f;
110
111 void get() {}
112 static void sget() {}
113 }
114
115 interface SuperInterface {
116 default void get() {}
117 }