Skip to content

Commit

Permalink
Revert.
Browse files Browse the repository at this point in the history
  • Loading branch information
wasabii committed Oct 4, 2024
1 parent dc36f8c commit 6667f5f
Showing 1 changed file with 61 additions and 25 deletions.
86 changes: 61 additions & 25 deletions src/IKVM.Java.Tests/java/lang/invoke/MethodHandleTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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));
};
}

}
}

0 comments on commit 6667f5f

Please sign in to comment.