1.程序计数器
通过改变这个计数器的值,来选取下一条要执行的指令, 简单来说用于监听运行后字节码的行号
Compiled from "demo.java"
public class demo {
public demo();
Code:
0: aload_0
1: invokespecial #8 // Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]);
Code:
0: iconst_0
1: istore_1
2: goto 15
5: getstatic #16 // Field java/lang/System.out:Ljava/io/PrintStream;
8: iload_1
9: invokevirtual #22 // Method java/io/PrintStream.print:(I)V
12: iinc 1, 1
15: iload_1
16: bipush 10
18: if_icmplt 5
21: return
}
2.虚拟机栈
虚拟机栈用来存放变量表(基本数据类型)包括参数,局部变量
Compiled from "demo.java"
public class demo {
public demo();
Code:
0: aload_0
1: invokespecial #8 // Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]);
Code:
0: iconst_1
1: istore_1
2: getstatic #16 // Field java/lang/System.out:Ljava/io/PrintStream;
5: iload_1
6: iconst_2
7: invokestatic #22 // Method dem:(I)I
10: iadd
11: invokevirtual #26 // Method java/io/PrintStream.print:(I)V
14: return
public static int dem(int);
Code:
0: iload_0
1: ireturn
}
3.本地方法栈
本地方法栈与虚拟机栈作用相似,不过他为虚拟机栈的Native方法服务
4.堆
堆是内存中最大的一块区域,用于存放所有对象的实例和数组,又分为新生代和年老代
Compiled from "demo.java"
public class demo {
public demo();
Code:
0: aload_0
1: invokespecial #8 // Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]);
Code:
0: iconst_2
1: anewarray #16 // class java/lang/String
4: dup
5: iconst_0
6: ldc #18 // String 张三
8: aastore
9: dup
10: iconst_1
11: ldc #20 // String 李四
13: aastore
14: astore_1
15: new #16 // class java/lang/String
18: dup
19: invokespecial #22 // Method java/lang/String."<init>":()V
22: astore_2
23: ldc #23 // String 王五
25: astore_2
26: return
}
5.方法区
用来存储被虚拟机加载的类信息,常量, 静态变量 ,编译后代码等数据