I have been trying to get my head around the obscure stack map frame and it's role in making the verification of a dynamically loaded class in just a single pass.
Few stack overflow answers & other resources which I found immensely helpful are
I understand the following -
- Every basic block should start with a stack map frame.
- Every instruction immediately following an unconditional branch (it's a start of a basic block) should have a stack map frame.
- The algorithm to create the stack map frame by ASM. Section 3.5 of ASM doc
The shortcoming of all these articles is that it doesn't describe how exactly the stack map frame is used in verification.
More specifically - Let's say we have a bytecode like mentioned below. At the current location, operand stack is going to be empty and the type for local variable 1 is going to be B. The location L0 has a stack map frame associated. How does the verifier use this information?
<initial frame for method>
GETSTATIC B.VALUE
ASTORE 1
GOTO L0 <- Current location
<stack map frame>
L1 GETSTATIC A.VALUE
ASTORE 1
<stack map frame>
L0 ILOAD 0
IFNE L1
<stack map frame>
ALOAD 1
ARETURN
Note: Note that I did read through the JVM spec and failed miserably to understand the stack map frame. Any help would be very helpful.