public void calc(){
int i = 1;
i = i++;
System.out.println(i);
}
对应的字节码指令如下:
calc:()V
000: iconst_1 {Lsample/HelloWorld;, .} | {}
001: istore_1 {Lsample/HelloWorld;, .} | {I}
002: iload_1 {Lsample/HelloWorld;, I} | {}
003: iinc 1 1 {Lsample/HelloWorld;, I} | {I}
004: istore_1 {Lsample/HelloWorld;, I} | {I}
005: getstatic System.out {Lsample/HelloWorld;, I} | {}
006: iload_1 {Lsample/HelloWorld;, I} | {Ljava/io/PrintStream;}
007: invokevirtual PrintStream.println {Lsample/HelloWorld;, I} | {Ljava/io/PrintStream;, I}
008: return {Lsample/HelloWorld;, I} | {}
public void calc(){
int i = 1;
i = ++i;
System.out.println(i);
}
对应的字节码指令如下:
calc:()V
000: iconst_1 {Lsample/HelloWorld;, .} | {}
001: istore_1 {Lsample/HelloWorld;, .} | {I}
002: iinc 1 1 {Lsample/HelloWorld;, I} | {}
003: iload_1 {Lsample/HelloWorld;, I} | {}
004: istore_1 {Lsample/HelloWorld;, I} | {I}
005: getstatic System.out {Lsample/HelloWorld;, I} | {}
006: iload_1 {Lsample/HelloWorld;, I} | {Ljava/io/PrintStream;}
007: invokevirtual PrintStream.println {Lsample/HelloWorld;, I} | {Ljava/io/PrintStream;, I}
008: return {Lsample/HelloWorld;, I} | {}
指定包名,统计方法耗时
//代码
public void calc(){
int i = 1;
i = i++;
System.out.println(i);
}
//对应的字节码指令如下
calc:()V
000: iconst_1 {Lsample/HelloWorld;, .} | {I}
001: istore_1 {Lsample/HelloWorld;, I} | {}
002: iload_1 {Lsample/HelloWorld;, I} | {I} //把局部变量表索引为1位置的值 放到操作数栈中 (操作数栈顶元素的值为 1)
003: iinc 1 1 {Lsample/HelloWorld;, I} | {I} //把局部变量表索引为1位置的值加1 (局部变量表该位置的值 i=2)
//栈顶元素弹栈并把值(栈顶元素的值为1)存到局部变量表索引为1的位置(局部变量表索引为1位置的值由2变为1)
004: istore_1 {Lsample/HelloWorld;, I} | {}
005: getstatic System.out {Lsample/HelloWorld;, I} | {Ljava/io/PrintStream;}
006: iload_1 {Lsample/HelloWorld;, I} | {Ljava/io/PrintStream;, I}
007: invokevirtual PrintStream.println {Lsample/HelloWorld;, I} | {}
008: return
//代码
public void calc(){
int i = 1;
i = ++i;
System.out.println(i);
}
//对应的字节码指令如下
calc:()V
000: iconst_1 {Lsample/HelloWorld;, .} | {I}
001: istore_1 {Lsample/HelloWorld;, I} | {}
002: iinc 1 1 {Lsample/HelloWorld;, I} | {} //把局部变量表索引为1位置的值加1 (i = 2)
003: iload_1 {Lsample/HelloWorld;, I} | {I}//把局部变量表索引为1位置的值放到操作数栈中(栈顶元素值为2)
//栈顶元素弹栈并把值(栈顶元素的值为2)存到局部变量表索引为1的位置(局部变量表索引为1位置的值由1变为2)
004: istore_1 {Lsample/HelloWorld;, I} | {}
005: getstatic System.out {Lsample/HelloWorld;, I} | {Ljava/io/PrintStream;}
006: iload_1 {Lsample/HelloWorld;, I} | {Ljava/io/PrintStream;, I}
007: invokevirtual PrintStream.println {Lsample/HelloWorld;, I} | {}
008: return