我理解下面的指令意味着已经发生了方法调用:
invokestatic:indexbyte1=00 indexbyte2=02
我的理解是,要找到被调用的方法在常量池中的索引,进行位移操作:
00 << 8 + 02
这等于零,这不是常量池索引中的有效条目。我是否误解了所需的计算?
我想了解这是如何手动完成的,因此反编译器将无济于事。
最佳答案
该指数的计算方式不是00 << 8 + 02
。引用the standard :
The unsigned indexbyte1 and indexbyte2 are used to construct an index into the run-time constant pool of the current class (§2.6), where the value of the index is (indexbyte1 << 8) | indexbyte2.
这意味着指令 invokevirtual 00 02
将调用 methodref 位于索引 (00 << 8) | 02
的方法在常量池中,即位置 2。请记住,常量池中的第一个条目的索引为 1,因此索引 2 实际上指的是池中的第二个条目。
关于java - 解释JVM方法调用指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30527693/