mirror of
https://github.com/corda/corda.git
synced 2025-06-14 05:08:18 +00:00
avoid calling unrelated JNI methods during class initialization
The main goal here is to avoid making JNI calls from code that really shouldn't need JNI (e.g. before this patch, ArrayList.add called Math.max, which called Math.<clinit>, which called Random.<init>, which called System.currentTimeMillis). Besides following the "pay for only what you need" principle, this change ensures we can call LambdaMetaFactory methods during AOT compilation with a minimal VM (i.e. without compiling in JNI methods we don't need).
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);
|
||||
|
Reference in New Issue
Block a user