源代码:
public class Example {
public int plus(int a){
int b = 1;
return a + b;
}
}
前一个文件类的反汇编结果:
public int plus(int);
Code:
Stack=2, Locals=3, Args_size=2
0: iconst_1
1: istore_2
2: iload_1
3: iload_2
4: iadd
5: ireturn
LineNumberTable:
line 5: 0
line 6: 2
LocalVariableTable:
Start Length Slot Name Signature
0 6 0 this LExample;
0 6 1 a I
2 4 2 b I
我的问题是如何理解下面的区域,这里的Length
、Slot
是什么意思:
LocalVariableTable:
Start Length Slot Name Signature
0 6 0 this LExample;
0 6 1 a I
2 4 2 b I
最佳答案
参见 the specs :
Start 是变量在字节码中定义的行,length 是定义它的字节码的行数。所以start to length定义了变量的范围。 我猜 Slot 对应于索引,第一个变量本身大致为 0,第二个变量为 1,第三个变量为 2,依此类推(加上在 double /长整数的情况下添加的偏移量)。
关于java - 如何理解 javap 输出中的 LocalVariableTable 区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21644197/