What is stackmap table in jvm bytecode?

I am studying the ASM library for generating bytecode. At some point, I made a mistake with the wrong 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 kind of tablemap is this?

+6
source share
1 answer

StackMapTable is an attribute in classes compiled with Java 6 or later. It is used by the JVM during validation by type checking .

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

To save space, not every team has a corresponding frame. Only frames for potential conversion targets or exception handlers are defined in the table. The remaining frames can be easily derived from them. You can see in your table above that frames are defined only for certain bytecode offsets.

+8
source

All Articles