New JEP: Javac intrinsics for LDC and INVOKEDYNAMIC
Remi Forax
forax at univ-mlv.fr
Tue Apr 11 15:29:27 UTC 2017
I like this JEP :)
constant propagation:
the rule about arrays should be added, an array of constants is a constant.
ldc:
i don't like having to use another constant hierarchy,
i would prefer to have static factories that act as compiler intrinsics from String/int/... representation and avoid an intermediary representation,
(the intermediary representation should be inside the compiler).
class CompilerIntrinsics {
public static Class<?> constClass(String className) { return null; }
public static MethodType constMethodType(String descriptor) { return null; }
public static MethodHandle constMethodHandle(int tag, Class<?> type, String name, MethodType type) { return null; }
}
by example for constMethodHandle, the compiler
- requires all arguments to be constants
- emits an error if the underlying method do not exist or the tag is not valid, etc at compile time,
- replace the call with a ldc with the right constant pool constant if the constant is not constant-folded because it's part of another constant
so
MethodHandle mh = constMethodHandle(6, constClass("java/lang/Integer"), "parseInt", constMethodType("(Ljava/lang/String)I"));
creates a method handle (with ldc) on Integer.parseInt() without creating the intermediary Class<?> and MethodType because they are both constant folded.
apart if mh is itself part of a bigger constant.
invokedynamic:
- the proposed encoding does not allow to encode an invokedynamic with 255 arguments (useful for testing)
- the BootstrapSpecifier should only contain a constant MethodHandle and an array of constant and a name, the descriptor should be computed by the compiler from the callsite, what @PolymorphicSignature already does.
a counter-proposal, let say we have an empty class
class InvokedynamicCompilerIntrinsics {
// empty
}
introduce a new syntax,
InvokedynamicCompilerIntrinsics.[bsm, arg1, arg2]foo(regular_arguments)
that cleanly separate the bootstrap method, the BSM arguments and the regular arguments.
The descriptor is computed as is the there is a method "foo" in InvokedynamicCompilerIntrinsics declared @PolymorphicSignature.
The BSM and the BSM arguments has to be constant (CE).
regards,
Rémi
----- Mail original -----
> De: "Brian Goetz" <brian.goetz at oracle.com>
> À: valhalla-dev at openjdk.java.net
> Envoyé: Mardi 11 Avril 2017 15:57:15
> Objet: New JEP: Javac intrinsics for LDC and INVOKEDYNAMIC
> Please review the this JEP draft:
>
> https://bugs.openjdk.java.net/browse/JDK-8178320
>
> This JEP creates (a) an official set of purely-nominal wrapper classes for
> linkable constants (Class, MethodType, MethodHandle, VarHandle), provides
> constant-propagation (not folding) support in javac for these types, and (b)
> intrinsification for LDC and INVOKEDYNAMIC so that they can be predictably
> translated into bytecode.
>
> This allows Java source code to be a first-class client of invokedynamic,
> including using Java to test indy bootstraps.
More information about the valhalla-dev
mailing list