mirror of
https://github.com/corda/corda.git
synced 2025-06-19 07:38:22 +00:00
Merge pull request #454 from dicej/aot-lambda
support AOT-compilation of Java 8 lambda expressions
This commit is contained in:
@ -15,7 +15,10 @@ import java.util.Random;
|
||||
public final class Math {
|
||||
public static final double E = 2.718281828459045;
|
||||
public static final double PI = 3.141592653589793;
|
||||
private static final Random random = new Random();
|
||||
|
||||
private static class Static {
|
||||
public static final Random random = new Random();
|
||||
}
|
||||
|
||||
private Math() { }
|
||||
|
||||
@ -84,7 +87,7 @@ public final class Math {
|
||||
}
|
||||
|
||||
public static double random() {
|
||||
return random.nextDouble();
|
||||
return Static.random.nextDouble();
|
||||
}
|
||||
|
||||
public static native double floor(double v);
|
||||
|
@ -22,7 +22,9 @@ import java.util.Hashtable;
|
||||
import java.util.Properties;
|
||||
|
||||
public abstract class System {
|
||||
private static final long NanoTimeBaseInMillis = currentTimeMillis();
|
||||
private static class NanoTime {
|
||||
public static final long BaseInMillis = currentTimeMillis();
|
||||
}
|
||||
|
||||
private static class Static {
|
||||
public static Properties properties = makeProperties();
|
||||
@ -94,7 +96,7 @@ public abstract class System {
|
||||
public static native int identityHashCode(Object o);
|
||||
|
||||
public static long nanoTime() {
|
||||
return (currentTimeMillis() - NanoTimeBaseInMillis) * 1000000;
|
||||
return (currentTimeMillis() - NanoTime.BaseInMillis) * 1000000;
|
||||
}
|
||||
|
||||
public static String mapLibraryName(String name) {
|
||||
|
@ -187,14 +187,28 @@ public class LambdaMetafactory {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static CallSite metafactory(MethodHandles.Lookup caller,
|
||||
String invokedName,
|
||||
MethodType invokedType,
|
||||
MethodType methodType,
|
||||
MethodHandle methodImplementation,
|
||||
MethodType instantiatedMethodType)
|
||||
throws LambdaConversionException
|
||||
|
||||
public static byte[] makeLambda(String invokedName,
|
||||
String invokedType,
|
||||
String methodType,
|
||||
String implementationClass,
|
||||
String implementationName,
|
||||
String implementationSpec,
|
||||
int implementationKind)
|
||||
{
|
||||
return makeLambda(invokedName,
|
||||
new MethodType(invokedType),
|
||||
new MethodType(methodType),
|
||||
new MethodHandle(implementationClass,
|
||||
implementationName,
|
||||
implementationSpec,
|
||||
implementationKind));
|
||||
}
|
||||
|
||||
private static byte[] makeLambda(String invokedName,
|
||||
MethodType invokedType,
|
||||
MethodType methodType,
|
||||
MethodHandle methodImplementation)
|
||||
{
|
||||
String className;
|
||||
{ int number;
|
||||
@ -265,8 +279,19 @@ public class LambdaMetafactory {
|
||||
throw error;
|
||||
}
|
||||
|
||||
byte[] classData = out.toByteArray();
|
||||
|
||||
return out.toByteArray();
|
||||
}
|
||||
|
||||
public static CallSite metafactory(MethodHandles.Lookup caller,
|
||||
String invokedName,
|
||||
MethodType invokedType,
|
||||
MethodType methodType,
|
||||
MethodHandle methodImplementation,
|
||||
MethodType instantiatedMethodType)
|
||||
throws LambdaConversionException
|
||||
{
|
||||
byte[] classData = makeLambda(invokedName, invokedType, methodType, methodImplementation);
|
||||
|
||||
try {
|
||||
return new CallSite
|
||||
(new MethodHandle
|
||||
|
@ -1,6 +1,7 @@
|
||||
package java.lang.invoke;
|
||||
|
||||
import avian.Classes;
|
||||
import avian.SystemClassLoader;
|
||||
|
||||
public class MethodHandle {
|
||||
static final int REF_invokeStatic = 6;
|
||||
@ -17,6 +18,20 @@ public class MethodHandle {
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
MethodHandle(String class_,
|
||||
String name,
|
||||
String spec,
|
||||
int kind)
|
||||
{
|
||||
this.kind = kind;
|
||||
this.loader = SystemClassLoader.appLoader();
|
||||
try {
|
||||
this.method = Classes.findMethod(this.loader, class_, name, spec);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (method.class_ != null) {
|
||||
|
@ -4,6 +4,7 @@ import static avian.Assembler.*;
|
||||
|
||||
import avian.Assembler;
|
||||
import avian.Classes;
|
||||
import avian.SystemClassLoader;
|
||||
import avian.VMClass;
|
||||
|
||||
import java.util.List;
|
||||
@ -25,6 +26,12 @@ public final class MethodType implements java.io.Serializable {
|
||||
this.spec = spec;
|
||||
}
|
||||
|
||||
MethodType(String spec) {
|
||||
this.loader = SystemClassLoader.appLoader();
|
||||
this.spec = new byte[spec.length() + 1];
|
||||
spec.getBytes(0, spec.length(), this.spec, 0);
|
||||
}
|
||||
|
||||
public String toMethodDescriptorString() {
|
||||
return Classes.makeString(spec, 0, spec.length - 1);
|
||||
}
|
||||
|
Reference in New Issue
Block a user