condy-folding bug; static field initializer is discarded
Brian Goetz
brian.goetz at oracle.com
Fri Aug 10 21:29:27 UTC 2018
Yes, I noted the incorrect dead-code elimination of the putstatic in my
previous. I think that's the same issue -- that we're not generating a
putstatic here, so the field appears null?
On 8/10/2018 2:49 PM, Jorn Vernee wrote:
> Hello,
>
> I think I found another bug in the condy-folding branch. I noticed
> when trying to do a static get of a constant in another compilation
> unit that the value was always `null`. Here is the code:
>
> ```
> import java.lang.constant.*;
> import java.lang.constant.DirectMethodHandleDesc.Kind;
> import static java.lang.constant.ConstantDescs.*;
>
> public class MyConstants {
>
> // Not ICE from different compilation unit
> public static final DynamicConstantDesc<String> INV_myMethod
> = DynamicConstantDesc.<String>of(BSM_INVOKE).withArgs(
> MethodHandleDesc.of(
> Kind.STATIC,
> ClassDesc.of("MyConstants"),
> "myMethod",
> CR_String
> )
> );
>
> public static String myMethod() {
> return "Hello: ";
> }
> }
> ```
>
> If I then do a `System.out.println(MyConstants.INV_myMethod);` from a
> different compilation unit, the value is `null`. Looking at javap
> output, there is no <clinit> generated for the initializer. If I do
> that manually like so:
>
> ```
> public static final DynamicConstantDesc<String> INV_myMethod;
>
> static {
> INV_myMethod
> = DynamicConstantDesc.<String>of(BSM_INVOKE).withArgs(
> MethodHandleDesc.of(
> Kind.STATIC,
> ClassDesc.of("MyConstants"),
> "myMethod",
> CR_String
> )
> );
> }
> ```
>
> I get a value as expected when printing:
>
> ```
> DynamicConstantDesc[ConstantBootstraps::invoke(MethodHandleDesc[STATIC/MyConstants::myMethod()String])Object]
>
> ```
>
> This looks like a bug?
>
> Jorn
More information about the amber-dev
mailing list