-
Notifications
You must be signed in to change notification settings - Fork 470
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
104 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package helper; | ||
|
||
public class MyAssert { | ||
|
||
public static void assertEquals(Object expected, Object actual) { | ||
if (!expected.equals(actual)) { | ||
throw new AssertionError(actual.toString() + " != " + expected.toString()); | ||
} | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...rc/main/java/stdlib/basic/MethodCall.java → ...classes/src/main/java/jvm/MethodCall.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package stdlib.basic; | ||
package jvm; | ||
|
||
public class MethodCall { | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...rc/main/java/stdlib/basic/ObjectInit.java → ...classes/src/main/java/jvm/ObjectInit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package stdlib.basic; | ||
package jvm; | ||
|
||
|
||
public class ObjectInit { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package jvm.jsr292; | ||
|
||
import java.lang.invoke.MethodHandles; | ||
import java.lang.invoke.MethodType; | ||
|
||
import static helper.MyAssert.assertEquals; | ||
|
||
public class LookupTest { | ||
|
||
public LookupTest(String[] x) {} | ||
private void foo(String[] x) {} | ||
public void bar(String[] x) {} | ||
public int f1; | ||
public static long f2; | ||
|
||
public static void main(String[] args) throws Exception { | ||
MethodHandles.Lookup lookup = MethodHandles.lookup(); | ||
MethodType mt = MethodType.methodType(void.class, String[].class); | ||
|
||
assertEquals("MethodHandle(String[])void", lookup.findStatic(LookupTest.class, "main", mt).toString()); | ||
assertEquals("MethodHandle(String[])LookupTest", lookup.findConstructor(LookupTest.class, mt).toString()); | ||
assertEquals("MethodHandle(LookupTest,String[])void", lookup.findSpecial(LookupTest.class, "foo", mt, LookupTest.class).toString()); | ||
assertEquals("MethodHandle(LookupTest,String[])void", lookup.findVirtual(LookupTest.class, "bar", mt).toString()); | ||
assertEquals("MethodHandle(LookupTest)int", lookup.findGetter(LookupTest.class, "f1", int.class).toString()); | ||
assertEquals("MethodHandle(LookupTest,int)void", lookup.findSetter(LookupTest.class, "f1", int.class).toString()); | ||
assertEquals("MethodHandle()long", lookup.findStaticGetter(LookupTest.class, "f2", long.class).toString()); | ||
assertEquals("MethodHandle(long)void", lookup.findStaticSetter(LookupTest.class, "f2", long.class).toString()); | ||
|
||
System.out.println("OK!"); | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
.../jvm7/jsr292/MethodHandleNativesTest.java → ...a/jvm/jsr292/MethodHandleNativesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package jvm7.jsr292; | ||
package jvm.jsr292; | ||
|
||
import helper.ReflectionHelper; | ||
import helper.UnitTestRunner; | ||
|
33 changes: 33 additions & 0 deletions
33
test/testclasses/src/main/java/jvm/jsr292/MethodHandleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package jvm.jsr292; | ||
|
||
import java.lang.invoke.MethodHandle; | ||
import java.lang.invoke.MethodHandles; | ||
import java.lang.invoke.MethodType; | ||
|
||
import static helper.MyAssert.assertEquals; | ||
|
||
public class MethodHandleTest { | ||
|
||
private static int x; | ||
|
||
public static String test() { | ||
return "hi"; | ||
} | ||
|
||
public static void main(String[] args) throws Throwable { | ||
MethodHandles.Lookup lookup = MethodHandles.lookup(); | ||
|
||
MethodType mt = MethodType.methodType(String.class); | ||
MethodHandle mh = lookup.findStatic(MethodHandleTest.class, "test", mt); | ||
assertEquals("hi", mh.invoke()); | ||
assertEquals("hi", (String) mh.invokeExact()); | ||
|
||
MethodHandle getter = lookup.findStaticGetter(MethodHandleTest.class, "x", int.class); | ||
MethodHandle setter = lookup.findStaticSetter(MethodHandleTest.class, "x", int.class); | ||
setter.invoke(100); | ||
assertEquals(100, getter.invoke()); | ||
|
||
System.out.println("OK!"); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
test/testclasses/src/main/java/jvm/jsr292/MethodTypeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package jvm.jsr292; | ||
|
||
import java.util.Arrays; | ||
|
||
import static java.lang.invoke.MethodType.*; | ||
import static helper.MyAssert.assertEquals; | ||
|
||
public class MethodTypeTest { | ||
|
||
public static void main(String[] args) { | ||
assertEquals("()void", methodType(void.class).toString()); // methodType(Class<?> rtype) | ||
assertEquals("(String)Object", methodType(Object.class, String.class).toString()); // methodType(Class<?> rtype, Class<?> ptype0) | ||
assertEquals("(int,long)String", methodType(String.class, int.class, long.class).toString()); // methodType(Class<?> rtype, Class<?> ptype0, Class<?>... ptypes) | ||
assertEquals("(int)String", methodType(String.class, new Class<?>[]{int.class}).toString()); // methodType(Class<?> rtype, Class<?>[] ptypes) | ||
assertEquals("(int)String", methodType(String.class, Arrays.asList(int.class)).toString()); // methodType(Class<?> rtype, List<Class<?>> ptypes) | ||
assertEquals("()void", fromMethodDescriptorString("()V", null).toString()); | ||
System.out.println("OK!"); | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...java/jvm8/InterfaceDefaultMethodTest.java → ...vm/lambda/InterfaceDefaultMethodTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package jvm8; | ||
package jvm.lambda; | ||
|
||
import junit.framework.Assert; | ||
import helper.UnitTestRunner; | ||
|
2 changes: 1 addition & 1 deletion
2
...c/main/java/jvm8/InterfaceMethodTest.java → .../java/jvm/lambda/InterfaceMethodTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package jvm8; | ||
package jvm.lambda; | ||
|
||
import helper.UnitTestRunner; | ||
import org.junit.Test; | ||
|
2 changes: 1 addition & 1 deletion
2
...lasses/src/main/java/jvm8/LambdaTest.java → .../src/main/java/jvm/lambda/LambdaTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package jvm8; | ||
package jvm.lambda; | ||
|
||
public class LambdaTest { | ||
|
||
|
19 changes: 0 additions & 19 deletions
19
test/testclasses/src/main/java/jvm7/jsr292/MethodHandleTest.java
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
test/testclasses/src/main/java/jvm7/jsr292/MethodTypeTest.java
This file was deleted.
Oops, something went wrong.