简体   繁体   English

什么是jvm字节码中的stackmap表?

[英]What is stackmap table in jvm bytecode?

I am learning ASM library for generating bytecode. 我正在学习ASM库来生成字节码。 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? 问题并不难找到并修复,但我很好奇这个堆栈图表是什么东西?

StackMapTable is an attribute in classes compiled with Java 6 or higher. StackMapTable是使用Java 6或更高版本编译的类中的属性。 It is used by the JVM during the process of verification by type checking . 通过类型检查进行验证的过程中,JVM使用它。

Basically, a stack map frame defines the expected types of local variables and the operand stack (ie 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. 在运行时,如果预期和实际类型不兼容,JVM将抛出VerifyError

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. 您可以在上面的表中看到,帧仅针对某些字节码偏移进行了定义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM