繁体   English   中英

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

[英]What is stackmap table in jvm bytecode?

我正在学习ASM库来生成字节码。 在某些时候我犯了一些错误的局部变量类型,并得到一个错误:

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)

问题并不难找到并修复,但我很好奇这个堆栈图表是什么东西?

StackMapTable是使用Java 6或更高版本编译的类中的属性。 通过类型检查进行验证的过程中,JVM使用它。

基本上,堆栈映射帧定义了方法在执行期间的预期类型的​​局部变量和操作数堆栈(即帧的状态)。 在运行时,如果预期和实际类型不兼容,JVM将抛出VerifyError

为了节省空间,并非每条指令都有相应的帧。 该表仅定义潜在跳转目标或异常处理程序的帧。 其他框架可以从这些框架中轻松推断出来。 您可以在上面的表中看到,帧仅针对某些字节码偏移进行了定义。

暂无
暂无

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

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