java - Java代码转字节码时指令号如何递增?

标签 java jvm bytecode

我是字节码的新手,所以我一直在查看 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/

相关文章:

java - 相对文件路径问题

java - Java 中的 MATLAB 函数

java - Guice 绑定(bind)泛型类型

java - 在 Swing 应用程序启动期间,首次调用 JFrame 构造函数需要很长时间(因为 java.awt.Window())

java - JVM 在完全 gc 后偶尔会锁定

java - 保存用反射修改的类的字节码

java - JVM字节码中的NOP是干什么用的?

java - Java字节码中的 `Stack=1, Locals=1, Args_size=1`是什么意思?

jvm - 为什么 JVM 在启动时随着时间的推移执行相同的程序会更快?

java - 以编程方式检测 JVM 是否正在使用类共享?