1 import jdk.incubator.code.CodeReflection;
2 import jdk.incubator.code.Op;
3 import jdk.incubator.code.dialect.core.CoreOp;
4 import org.junit.jupiter.api.Assertions;
5 import org.junit.jupiter.api.Test;
6
7 import java.lang.reflect.Method;
8
9 /*
10 * @test
11 * @modules jdk.incubator.code
12 * @run junit 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 public 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 Assertions.assertSame(fm, fm2);
31 }
32
33 @Test
34 public 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 Assertions.assertNotSame(gm, fm);
42 }
43 }