Constant descriptor resolved too soon during constant resolution?
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Fri Aug 3 10:46:41 UTC 2018
Interesting issue! I will defer to Vicente for a full evaluation. By
eyeballing at the javap output, I see this:
public static void main(java.lang.String[]) throws java.lang.Throwable;
descriptor: ([Ljava/lang/String;)V
flags: (0x0009) ACC_PUBLIC, ACC_STATIC
Code:
stack=2, locals=2, args_size=1
0: getstatic #2 // Field
java/lang/System.out:Ljava/io/PrintStream;
*3: ldc #3 // Dynamic
#0:_:Ljava/lang/constant/DynamicConstantDesc;*
5: invokevirtual #4 // Method
java/io/PrintStream.println:(Ljava/lang/Object;)V
8: return
This looks good, and the ldc is where all the action happens, of course;
this is the CP entry for it:
#3 = Dynamic #0:#32 //
#0:_:Ljava/lang/constant/DynamicConstantDesc;
And this is the BSM entry:
public static final #61= #60 of #67; // Lookup=class
java/lang/invoke/MethodHandles$Lookup of class
java/lang/invoke/MethodHandles
BootstrapMethods:
0: #23 REF_invokeStatic
java/lang/constant/DynamicConstantDesc.constantBootstrap:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/constant/ConstantDesc;)Ljava/lang/constant/DynamicConstantDesc;
Method arguments:
#24 Ljava/lang/invoke/ConstantBootstraps;
#25 invoke
#26
(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;Ljava/lang/invoke/MethodHandle;[Ljava/lang/Object;)Ljava/lang/Object;
#27 _
#28 Ljava/lang/Object;
* #29 REF_invokeVirtual
java/lang/String.concat:(Ljava/lang/String;)Ljava/lang/String;*
#30 Hello,
#31 world!
My feeling is that the BSM arg in bold above is wrong. That is a *live*
method handle constant - e.g. of type MethodHandle, but that is not
compatible with what the BSM expects (a ConstantDesc):
#29 = MethodHandle 5:#47 // REF_invokeVirtual
java/lang/String.concat:(Ljava/lang/String;)Ljava/lang/String;
I think all BSM args above should be nominal. E.g. there should be a
MethodHandleDesc there (so, another, nested, dynamic constant), not a
live MethodHandle.
On 02/08/18 16:36, Jorn Vernee wrote:
> Is there a flag to temporarily turn off folding? I'm not aware of any
> javac equivalent of `-XX:+PrintFlagsFinal`, so I don't have a way to
> find out about experimental flags.
Yes, folding can be disabled with the
-XDfolding=false
compiler flag.
>
> Also, I hope this is the right place to post bug reports, JBS doesn't
> seem to cover amber, and I've seen a few people reporting bugs on
> other mailing lists, but I'd expect more people to be doing that, so
> maybe I'm in the wrong place?
Few months ago we have added a new category in JBS - so if you file a
JDK bug, under the Affect Version field you can now select 'amber-repo'.
The scheme we're using is also to put a label on the bug/rfe which has
same name as the branch (so that we can quickly filter), so in this case
that would be "condy-folding".
But reporting issues here is fine too, thanks for testing!
Maurizio
More information about the amber-dev
mailing list