[condy-folding] Condy CP entries deduplication?

Tagir Valeev amaembo at gmail.com
Mon Oct 16 10:33:58 UTC 2017


Hello!

Still playing with condy. Very simple program:

import java.lang.invoke.*;

public class Condy {
  public static void main(String[] args) {
    Object o1 = Intrinsics.ldc(ConstantRef.ofNull());
    Object o2 = Intrinsics.ldc(ConstantRef.ofNull());
  }
}

I thought that only one CP entry will be created for both dynamic
constants, however in fact two separate entries are created, despite
they refer to the same NameAndType and the same BSM:

$ javac -XDdoConstantFold Condy.java
$ javap -v Condy
...
public class Condy
...
Constant pool:
   #1 = Methodref          #5.#14         // java/lang/Object."<init>":()V
   #2 = ConstantDynamic    #0:#17         // #0:_:Ljava/lang/Object;
   #3 = ConstantDynamic    #0:#17         // #0:_:Ljava/lang/Object;
...
{
...
  public static void main(java.lang.String[]);
    descriptor: ([Ljava/lang/String;)V
    flags: (0x0009) ACC_PUBLIC, ACC_STATIC
    Code:
      stack=1, locals=3, args_size=1
         0: ldc           #2                  // ConstantDynamic
#0:_:Ljava/lang/Object;
         2: astore_1
         3: ldc           #3                  // ConstantDynamic
#0:_:Ljava/lang/Object;
         5: astore_2
         6: return
      LineNumberTable:
        line 5: 0
        line 6: 3
        line 7: 6
}
...
BootstrapMethods:
  0: #16 REF_invokeStatic
java/lang/invoke/Bootstraps.defaultValue:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;)Ljava/lang/Object;
    Method arguments:

Is this intended behavior or implementation bug? If I remember
correctly, discussions regarding this topic ended in merging equal CP
entries, but probably I'm missing something.

Thanks,
Tagir Valeev.


More information about the amber-dev mailing list