我是字节码的新手,所以我一直在查看 Java 代码及其字节码转换的在线示例。我的困惑在于指令号的递增模式。例如,引用 https://salilsurendran.wordpress.com/2015/01/01/jvm-memory-barriers/ 中的字节代码片段:
//The byte code generated for our for loop
0: iconst_0 <-- Push '0' on the operand stack
1: istore_1 <-- Pop '0' out of the operand stack and set it as the value of local variable 1
2: iload_1 <-- Push the value of the local variable 1 onto the operand stack
3: ldc #2 // int 1000000 <-- Push the constant no. 2 from the constant pool onto the operand stack
5: if_icmpge 14 <-- Pop the top two values out of the operand stack if the first value
popped is greater than or equal to the second jump to step 14 -->
8: iinc 1, 1 <-- Increment local variable 1 which is i by 1
11: goto 2 <-- jump to step 2
//End of the for loop
指令 1 到 3 似乎每次都递增 1,尽管指令 3 变为 5,指令 5 变为 8。
我的问题是,为什么 3 不转到 4? 3转5,5转8的原因是什么?是否有一套我可以指出的一般规则?
最佳答案
这不是“指令编号”。它是一条指令地址,并按前一条指令的长度递增。
关于java - Java代码转字节码时指令号如何递增?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49566486/