我是字节码的新手,所以我一直在寻找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的原因是什么?我可以指出一套一般的规则吗?
答案 0 :(得分:3)
它不是&#39;指令编号&#39;。它是一个指令地址,,它会增加前一条指令的长度。