jvm字节码中的stackmap表是什么? [英] What is stackmap table in jvm bytecode?

查看:214
本文介绍了jvm字节码中的stackmap表是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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)

问题并不难发现和解决,但我很好奇这个stackmap表内容是什么?

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

推荐答案

StackMapTable 是已编译类中的一个属性Java 6或更高版本。在通过类型检查进行验证

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

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.

这篇关于jvm字节码中的stackmap表是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆