1 import jdk.incubator.code.CodeReflection;
 2 import jdk.incubator.code.Op;
 3 import jdk.incubator.code.op.CoreOp;
 4 import org.testng.Assert;
 5 import org.testng.annotations.Test;
 6 
 7 import java.lang.reflect.Method;
 8 
 9 /*
10  * @test
11  * @modules jdk.incubator.code
12  * @run testng MethodModelUniquenessTest
13  */
14 
15 public class MethodModelUniquenessTest {
16 
17     @CodeReflection
18     static void f() {
19     }
20     @CodeReflection
21     static void g() {
22     }
23 
24     @Test
25     void testInstancesReflectSameMethodHaveSameModel() throws NoSuchMethodException {
26         Method f = this.getClass().getDeclaredMethod("f");
27         Method f2 = this.getClass().getDeclaredMethod("f");
28         CoreOp.FuncOp fm = Op.ofMethod(f).orElseThrow();
29         CoreOp.FuncOp fm2 = Op.ofMethod(f2).orElseThrow();
30         Assert.assertSame(fm, fm2);
31     }
32 
33     @Test
34     void testInstancesReflectDiffMethodsHaveDiffModels() throws NoSuchMethodException {
35         Method f = this.getClass().getDeclaredMethod("f");
36         CoreOp.FuncOp fm = Op.ofMethod(f).orElseThrow();
37 
38         Method g = this.getClass().getDeclaredMethod("g");
39         CoreOp.FuncOp gm = Op.ofMethod(g).orElseThrow();
40 
41         Assert.assertNotSame(gm, fm);
42     }
43 }