(Condy) Folded of local variables are still considered when calculating the max number of local vars of a method

Remi Forax forax at univ-mlv.fr
Sun Sep 2 17:58:06 UTC 2018


Hi all,
while trying to reproduce a bug in ASM using the constant API + Intrinsics.ldc, i've spot a discrepancy,
using the follwing example,

package jdk12;

import java.lang.constant.ClassDesc;
import java.lang.constant.DirectMethodHandleDesc.Kind;
import java.lang.constant.DynamicConstantDesc;
import java.lang.constant.MethodHandleDesc;
import java.lang.constant.MethodTypeDesc;
import java.lang.invoke.Intrinsics;
import java.lang.invoke.MethodHandles.Lookup;

public class ConstantDynamicExample {
  public static long primitiveExample() {
    MethodTypeDesc methodDescriptor = MethodTypeDesc.ofDescriptor("(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;)J");
    DynamicConstantDesc<Long> dynamicConstant = DynamicConstantDesc.of(
        MethodHandleDesc.of(Kind.STATIC, ClassDesc.of("jdk12.ConstantDynamicExample"), "bsm", methodDescriptor));
    return Intrinsics.ldc(dynamicConstant);
  }

  private static long bsm(Lookup lookup, String name, Class<?> type) {
    return 3L;
  }
  
  public static void main(String[] args) {
    System.out.println(primitiveExample());
  }  
}


Using javap, you can see that the dynamicConstant is folded but the number of local variable (locals=2) still count the variables that doesn't exist anymore

 public static long primitiveExample();
    descriptor: ()J
    flags: (0x0009) ACC_PUBLIC, ACC_STATIC
    Code:
      stack=2, locals=2, args_size=0
         0: ldc2_w        #2                  // Dynamic #0:_:J
         3: lreturn
      LineNumberTable:
        line 43: 0

regards,
Rémi


More information about the amber-dev mailing list