Direct use of jli.ConstantBootstraps to obtain VarHandles and JEP 303
Brian Goetz
brian.goetz at oracle.com
Sun May 24 19:34:24 UTC 2020
> I can simply write
>
> private volatile long myVar;
> private static final VarHandle MY_VAR = ConstantBootstraps.fieldVarHandle(
> MethodHandles.lookup(), "myVar", VarHandle.class, MyVHTest.class, long.class);
>
> I know, ConstantBootstraps were not designed for that use case - as evident of the duplication of VarHandle.class as parameter.
I don’t think this is going to cause problems. The intent of the bootstrap was to be used as a indy/condy bootstrap, but it’s also a valid static method. It might be slower to execute, but either way you’re probably executing it in the interpreter anyway.
> The questions that I did ask myself were:
> * Could this be compiled into a constant dynamic instruction?
> * If yes, should this only be done for ConstantBootstraps or any method with take a Lookup, String, Class as first 3 parameters?
> * If everyone: What if people start to rely on it for performance - and a change to their code would turn the LDC into a normal call?
> * Is it even worth the cost? Or is this a model that is worth pursuing?
Since the methods in CB were intended mostly to support compiler-based constantization, it seems a mostly short-term play to try to do something special here. (Plus, the lookup() call is not a compile time constant.)
More information about the amber-dev
mailing list