From 6667f5fd3e0dd12e45368f1b12803f185b4eeda0 Mon Sep 17 00:00:00 2001 From: Jerome Haltom Date: Fri, 4 Oct 2024 17:19:34 -0500 Subject: [PATCH] Revert. --- .../java/lang/invoke/MethodHandleTests.java | 86 +++++++++++++------ 1 file changed, 61 insertions(+), 25 deletions(-) diff --git a/src/IKVM.Java.Tests/java/lang/invoke/MethodHandleTests.java b/src/IKVM.Java.Tests/java/lang/invoke/MethodHandleTests.java index 40b6ae0c4..422db2bc5 100644 --- a/src/IKVM.Java.Tests/java/lang/invoke/MethodHandleTests.java +++ b/src/IKVM.Java.Tests/java/lang/invoke/MethodHandleTests.java @@ -19,39 +19,75 @@ public static String addStringStatic(String a, String b) { } + interface AddItf { + void apply(List st, int idx, Object v) throws Throwable; + } + @cli.Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute.Annotation() - public void canInvokeExactVirtual() throws Throwable { - MethodHandles.Lookup lookup = getLookup(); - MethodType mt = getMethodType(); - MethodHandle mh = getMethodHandle(lookup, mt); - String s = invokeIt(mh); + public void canInvokeVirtual() throws Throwable { + MethodHandles.Lookup lookup = MethodHandles.lookup(); + MethodType mt = MethodType.methodType(String.class, String.class, String.class); + MethodHandle mh = lookup.findVirtual(TestClass.class, "addString", mt); + String s = (String)mh.invoke(new TestClass(), (Object)"a", (Object)"b"); if (!s.equals("ab")) { throw new Exception(s); } } - @cli.System.Runtime.CompilerServices.MethodImplAttribute.Annotation(value = cli.System.Runtime.CompilerServices.MethodImplOptions.__Enum.NoInlining) - MethodHandles.Lookup getLookup() throws Throwable - { - return MethodHandles.lookup(); + @cli.Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute.Annotation() + public void canInvokeStatic() throws Throwable { + MethodHandles.Lookup lookup = MethodHandles.lookup(); + MethodType mt = MethodType.methodType(String.class, String.class, String.class); + MethodHandle mh = lookup.findStatic(TestClass.class, "addStringStatic", mt); + String s = (String)mh.invoke((Object)"a", (Object)"b"); + if (!s.equals("ab")) { + throw new Exception(s); + } } - - @cli.System.Runtime.CompilerServices.MethodImplAttribute.Annotation(value = cli.System.Runtime.CompilerServices.MethodImplOptions.__Enum.NoInlining) - MethodType getMethodType() throws Throwable - { - return MethodType.methodType(String.class, String.class, String.class); + + @cli.Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute.Annotation() + public void canInvokeExactVirtual() throws Throwable { + MethodHandles.Lookup lookup = MethodHandles.lookup(); + MethodType mt = MethodType.methodType(String.class, String.class, String.class); + MethodHandle mh = lookup.findVirtual(TestClass.class, "addString", mt); + String s = (String)mh.invokeExact(new TestClass(), "a", "b"); + if (!s.equals("ab")) { + throw new Exception(s); + } } - - @cli.System.Runtime.CompilerServices.MethodImplAttribute.Annotation(value = cli.System.Runtime.CompilerServices.MethodImplOptions.__Enum.NoInlining) - MethodHandle getMethodHandle(MethodHandles.Lookup lookup, MethodType mt) throws Throwable - { - return lookup.findVirtual(TestClass.class, "addString", mt); + + @cli.Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute.Annotation() + public void canInvokeExactStatic() throws Throwable { + MethodHandles.Lookup lookup = MethodHandles.lookup(); + MethodType mt = MethodType.methodType(String.class, String.class, String.class); + MethodHandle mh = lookup.findStatic(TestClass.class, "addStringStatic", mt); + String s = (String)mh.invokeExact("a", "b"); + if (!s.equals("ab")) { + throw new Exception(s); + } } - - @cli.System.Runtime.CompilerServices.MethodImplAttribute.Annotation(value = cli.System.Runtime.CompilerServices.MethodImplOptions.__Enum.NoInlining) - String invokeIt(MethodHandle mh) throws Throwable - { - return (String)mh.invokeExact(new TestClass(), "a", "b"); + + @cli.Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute.Annotation() + public void canInvokeStaticMethodThatReturnsVoid() throws Throwable { + MethodHandles.Lookup lookup = MethodHandles.lookup(); + MethodType pmt = MethodType.methodType(void.class, int.class, Object.class); + MethodHandle pms = lookup.findVirtual(List.class, "add", pmt); + List list = new ArrayList<>(); + pms.invoke(list, 0, "Hi"); + AddItf pf2 = pms::invoke; + pf2.apply(list, 1, "there"); + AddItf pf3 = pms::invokeExact; + pf3.apply(list, 2, "you"); + + if (!list.get(0).equals("Hi")) { + throw new Exception(list.get(0)); + }; + if (!list.get(1).equals("there")) { + throw new Exception(list.get(1)); + }; + if (!list.get(2).equals("you")) { + throw new Exception(list.get(2)); + }; } -} +} \ No newline at end of file