StackMap problem

Mark Roberts markro at cs.washington.edu
Tue Jan 28 20:45:32 UTC 2025


The existence of compiler generated, unnamed local temps (no LocalVariable
code element) seems to cause a problem with stack maps.



The ‘source’ attachment shows the problem method.   The ‘before’ attachment
shows the generated code before instrumentation.  Note that the compiler
generates an unnamed temp at slot 0 to store the exception code. The
stackmap for the branch target says same locals, which is correct.



The ‘after’ attachment shows the code generated after our tool has added
instrumentation code – note the addition of a new local variable at slot
1.  The stackmap for the branch target still says same locals, which is no
longer correct. This causes the iload_1 @41 to fail.



I tried to see if this issue has already been reported, but I was unable to
figure out how to search https://bugs.java.com/bugdatabase/ by keyword.



Mark
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/classfile-api-dev/attachments/20250128/9bd43109/attachment.htm>
-------------- next part --------------
  public static void push() {
    try {
      s.push(createItem(rnd.nextInt(4)));
    } catch (Overflow e) { }
    observe();
  }
-------------- next part --------------
  name_index: 46 (push)
  access_flags: Const.ACC_PUBLIC | Const.ACC_STATIC
  descriptor_index: 6 (()V)
  attribute count: 1
  attribute_name_index: 85 (Code)
  Code(maxStack = 3, maxLocals = 1, code_length = 24)
  0:    getstatic		DataStructures.StackArTester.s LDataStructures/StackAr; (12)
  3:    getstatic		DataStructures.StackArTester.rnd Ljava/util/Random; (30)
  6:    iconst_4
  7:    invokevirtual	java.util.Random.nextInt (I)I (34)
  10:   invokestatic	DataStructures.StackArTester.createItem (I)Ljava/lang/Object; (40)
  13:   invokevirtual	DataStructures.StackAr.push (Ljava/lang/Object;)V (44)
  16:   goto		#20
  19:   astore_0
  20:   invokestatic	DataStructures.StackArTester.observe ()V (21)
  23:   return
  
  Exception handler(s) = 
  From	To	Handler	Type
  0	16	19	DataStructures.Overflow(48)
  
  Attribute(s) = 
  LineNumberTable:
  LineNumber(0, 37), LineNumber(16, 38), LineNumber(20, 39), LineNumber(23, 40)
  LocalVariableTable:
  
  StackMapTable:
  StackMap((SAME_LOCALS_1_STACK, offset delta=19, stack items={(type=Object, class=DataStructures.Overflow)}), (SAME, offset delta=0))
-------------- next part --------------
  name_index: 64 (push)
  access_flags: Const.ACC_PUBLIC | Const.ACC_STATIC
  descriptor_index: 4 (()V)
  attribute count: 1
  attribute_name_index: 129 (Code)
  Code(maxStack = 6, maxLocals = 2, code_length = 54)
  0:    getstatic		daikon.chicory.Runtime.nonce Ljava/util/concurrent/atomic/AtomicInteger; (10)
  3:    invokevirtual	java.util.concurrent.atomic.AtomicInteger.getAndIncrement ()I (16)
  6:    istore_1
  7:    aconst_null
  8:    iload_1
  9:    iconst_3
  10:   iconst_0
  11:   anewarray		<java.lang.Object> (18)
  14:   invokestatic	daikon.chicory.Runtime.enter (Ljava/lang/Object;II[Ljava/lang/Object;)V (22)
  17:   getstatic		DataStructures.StackArTester.s LDataStructures/StackAr; (46)
  20:   getstatic		DataStructures.StackArTester.rnd Ljava/util/Random; (70)
  23:   iconst_4
  24:   invokevirtual	java.util.Random.nextInt (I)I (76)
  27:   invokestatic	DataStructures.StackArTester.createItem (I)Ljava/lang/Object; (78)
  30:   invokevirtual	DataStructures.StackAr.push (Ljava/lang/Object;)V (81)
  33:   goto		#37
  36:   astore_0
  37:   invokestatic	DataStructures.StackArTester.observe ()V (52)
  40:   aconst_null
  41:   iload_1
  42:   iconst_3
  43:   iconst_0
  44:   anewarray		<java.lang.Object> (18)
  47:   aconst_null
  48:   bipush		40
  50:   invokestatic	daikon.chicory.Runtime.exit (Ljava/lang/Object;II[Ljava/lang/Object;Ljava/lang/Object;I)V (26)
  53:   return
  
  Exception handler(s) = 
  From	To	Handler	Type
  0	33	36	DataStructures.Overflow(66)
  
  Attribute(s) = 
  LocalVariableTable:
  LocalVariable(startPc = 0, length = 54, index = 1:int this_invocation_nonce)
  LineNumberTable:
  LineNumber(17, 37), LineNumber(33, 38), LineNumber(37, 39), LineNumber(40, 40)
  StackMapTable:
  StackMap((SAME_LOCALS_1_STACK, offset delta=36, stack items={(type=Object, class=DataStructures.Overflow)}), (SAME, offset delta=0))


More information about the classfile-api-dev mailing list