I am studying class file's StackMapTable attribute, and i have some questions, how does the stack map frames computed?
Here I have two examples:
Example 1
public class Foo {
public void foo() {
int i = 0;
int j = 0;
if (i > 0) {
int k = 0;
}
int l = 0;
}
}
//byte code:
public void foo();
Code:
Stack=1, Locals=4, Args_size=1
0: iconst_0
1: istore_1
2: iconst_0
3: istore_2
4: iload_1
5: ifle 10
8: iconst_0
9: istore_3
10: iconst_0
11: istore_3
12: return
LocalVariableTable:
Start Length Slot Name Signature
10 0 3 k I
0 13 0 this LFoo;
2 11 1 i I
4 9 2 j I
12 1 3 l I
StackMapTable: number_of_entries = 1
frame_type = 253 /* append */
offset_delta = 10
locals = [ int, int ]
Example 2
public static void chop() {
int i = 0;
int j = 0;
if (i > 0) {
long k = 0;
if (j == 0) {
k++;
int s=1111;
}
int t = 0;
}
}
//bytecode
public static void chop();
descriptor: ()V
flags: ACC_PUBLIC, ACC_STATIC
Code:
stack=4, locals=5, args_size=0
0: iconst_0
1: istore_0
2: iconst_0
3: istore_1
4: iload_0
5: ifle 26
8: lconst_0
9: lstore_2
10: iload_1
11: ifne 23
14: lload_2
15: lconst_1
16: ladd
17: lstore_2
18: sipush 1111
21: istore 4
23: iconst_0
24: istore 4
26: return
LineNumberTable:
line 34: 0
line 35: 2
line 36: 4
line 37: 8
line 38: 10
line 39: 14
line 40: 18
line 42: 23
line 44: 26
StackMapTable: number_of_entries = 2
frame_type = 254 /* append */
offset_delta = 23
locals = [ int, int, long ]
frame_type = 250 /* chop */
offset_delta = 2
Can anybody introduce how to calculate stack map frames base this two examples?
This problem has been bothering me for a long time,any help will be appreciated! Thanks!