<返回更多

java程序运行原理解析

2019-08-09    
加入收藏

JAVA运行时数据区

线程共享:方法区 堆内存 (老年代、新生代(S0、S1)) 随gc而创建和销毁

线程独占部分 虚拟机栈 本地方法栈 程序计数器 随线程生命周期而创建和销毁

 

java程序运行原理解析

 

 

方法区: 运行时常量池 字符串常量 (non-heap)

堆内存

虚拟机栈

本地方法栈

程序计数器

javap -v Demo1.class > Demo1.txt 解析 查看指令命令

实际操作例子

java程序运行原理解析

 

public class Demo1{
 public static void main(String[] args){
 int x = 500;
 int y = 100;
 int a = x / y;
 int b = 50;
 System.out.println(a + b);
 }
}

经过代码解析文件

Classfile /D:/work/NetEase/课程/vip/高性能编程/多线程并发编程/1.JAVA基础/资料包/part-1/Demo1.class
 Last modified 2018-11-16; size 414 bytes
 MD5 checksum ae6fa820973681b35609c75631cb255b
 Compiled from "Demo1.java"
public class Demo1
 minor version: 0 // 版本号
 major version: 52 // 版本号
 flags: ACC_PUBLIC, ACC_SUPER // 访问控制
Constant pool: // 类信息解析出来的静态常量池
 #1 = Methodref #5.#14 // java/lang/Object."<init>":()V
 #2 = Fieldref #15.#16 // java/lang/System.out:Ljava/io/PrintStream;
 #3 = Methodref #17.#18 // java/io/PrintStream.println:(I)V
 #4 = Class #19 // Demo1
 #5 = Class #20 // java/lang/Object
 #6 = Utf8 <init>
 #7 = Utf8 ()V
 #8 = Utf8 Code
 #9 = Utf8 LineNumberTable
 #10 = Utf8 main
 #11 = Utf8 ([Ljava/lang/String;)V
 #12 = Utf8 SourceFile
 #13 = Utf8 Demo1.java
 #14 = NameAndType #6:#7 // "<init>":()V
 #15 = Class #21 // java/lang/System
 #16 = NameAndType #22:#23 // out:Ljava/io/PrintStream;
 #17 = Class #24 // java/io/PrintStream
 #18 = NameAndType #25:#26 // println:(I)V
 #19 = Utf8 Demo1
 #20 = Utf8 java/lang/Object
 #21 = Utf8 java/lang/System
 #22 = Utf8 out
 #23 = Utf8 Ljava/io/PrintStream;
 #24 = Utf8 java/io/PrintStream
 #25 = Utf8 println
 #26 = Utf8 (I)V
{
 public Demo1();
 descriptor: ()V
 flags: ACC_PUBLIC
 Code:
 stack=1, locals=1, args_size=1
 0: aload_0
 1: invokespecial #1 // Method java/lang/Object."<init>":()V
 4: return
 LineNumberTable:
 line 1: 0
 public static void main(java.lang.String[]);
 descriptor: ([Ljava/lang/String;)V
 flags: ACC_PUBLIC, ACC_STATIC
 Code:
 stack=3, locals=5, args_size=1 // main方法对应栈帧的操作数栈深度、本地变量数量、参数数量
 0: sipush 500
 3: istore_1
 4: bipush 100
 6: istore_2
 7: iload_1
 8: iload_2
 9: idiv
 10: istore_3
 11: bipush 50
 13: istore 4
 15: getstatic #2 // Field java/lang/System.out:Ljava/io/PrintStream;
 18: iload_3
 19: iload 4
 21: iadd
 22: invokevirtual #3 // Method java/io/PrintStream.println:(I)V
 25: return
 LineNumberTable:
 line 3: 0
 line 4: 4
 line 5: 7
 line 6: 11
 line 7: 15
 line 8: 25
}
SourceFile: "Demo1.java"

 

java程序运行原理解析

 

 

java程序运行原理解析

 

声明:本站部分内容来自互联网,如有版权侵犯或其他问题请与我们联系,我们将立即删除或处理。
▍相关推荐
更多资讯 >>>