将Java代码转换为字节码时,指令号是如何递增的?
我是字节码新手,所以我一直在网上查看Java代码及其字节码转换的示例。我的困惑在于指令号的递增模式。例如,请参阅以下内容中的字节码片段:将Java代码转换为字节码时,指令号是如何递增的?,java,jvm,bytecode,Java,Jvm,Bytecode,我是字节码新手,所以我一直在网上查看Java代码及其字节码转换的示例。我的困惑在于指令号的递增模式。例如,请参阅以下内容中的字节码片段: //为for循环生成的字节码 0:iconst_0它不是“指令号”。这是一个指令地址,它是按上一条指令的长度递增的。查看维基百科上标记为“其他字节”的列ldc取1,如果icmpge取2,iinc也取2(额外字节)。@ElliottFrisch谢谢,这正是我要找的!有些说明使用了不止一个字节。最好看的地方是… //The byte code generate
//为for循环生成的字节码
0:iconst_0它不是“指令号”。这是一个指令地址,它是按上一条指令的长度递增的。查看维基百科上标记为“其他字节”的列ldc
取1,如果icmpge
取2,iinc
也取2(额外字节)。@ElliottFrisch谢谢,这正是我要找的!有些说明使用了不止一个字节。最好看的地方是…
//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