What is stackmap table in jvm bytecode?

房东的猫 提交于 2019-12-01 01:01:59

问题


I am learning ASM library for generating bytecode. At some point I made some mistake with bad local variable type and got an error:

Exception in thread "main" java.lang.VerifyError: Bad local variable type
Exception Details:
  Location:
    Loops.start()V @56: aload_1
  Reason:
    Type top (current frame, locals[1]) is not assignable to reference type


  Stackmap Table:
    full_frame(@24,{Object[#2],Object[#9]},{Integer})
    full_frame(@25,{Object[#2],Object[#9]},{Integer,Integer})
    same_locals_1_stack_item_frame(@44,Integer)
    full_frame(@45,{Object[#2],Object[#9]},{Integer,Integer})
    full_frame(@48,{Object[#2]},{Integer})
    full_frame(@80,{Object[#2],Integer},{Integer})
    full_frame(@81,{Object[#2],Integer},{Integer,Integer})
    full_frame(@87,{Object[#2]},{Integer})
    full_frame(@119,{Object[#2],Integer},{Integer})
    full_frame(@120,{Object[#2],Integer},{Integer,Integer})
    same_locals_1_stack_item_frame(@123,Integer)

The problem was not difficult to find and fix but I'm curious what is a this stackmap table thing?


回答1:


StackMapTable is an attribute in classes compiled with Java 6 or higher. It is used by the JVM during the process of verification by type checking.

Basically, a stack map frame defines the expected types of local variables and the operand stack (i.e. the state of the frame) of a method during its execution. During run-time, The JVM throws the VerifyError if expected and actual types are incompatible.

To save space, not every instruction has a corresponding frame. The table only defines frames for potential jump targets or exception handlers. Other frames can be easily inferred from these ones. You can see in your table above that frames are defined only for some bytecode offsets.



来源:https://stackoverflow.com/questions/37309074/what-is-stackmap-table-in-jvm-bytecode

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!