class T
{
public static void main(String[] args) {
int x = 5;    //a
x += x; //b
}
}
部分JVM码
public static void main(java.lang.String[]);
  Code:
   0:   iconst_5
   1:   istore_1
   2:   iload_1
   3:   iload_1
   4:   iadd
   5:   istore_1
   6:   returnJVM码第0和1行是对应源代码中第a行吧
JVM码第2和3行两次加载? 这里发生了什么?
iconst、istore、iload……中的i什么意思啊(代表哪个单词)?

解决方案 »

  1.   

    iconst_5:pushes int 5 onto the stack
    istore_1 :pops int to local variable position one
    iload_1 :pushes int from local variable position one
    iadd :Pop two ints, add them, push result
    参考Inside JVM
      

  2.   

    答:代码注释如下:
    部分JVM码 
    public static void main(java.lang.String[]); 
      Code: 
      0:  iconst_5 //常量值5入栈
      1:  istore_1  //将栈顶中值5出栈,放入变量x中
      2:  iload_1 //变量x值入栈
      3:  iload_1  //变量x值入栈
      4:  iadd      //两个x值相加,和入栈
      5:  istore_1   //和出栈,放入变量x中
      6:  return