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