Java基础|学习笔记
JVM(Java virtual machine)
-
Classloader:负责loading, linking,initialization 我们编写的代码是.java文件,经过编译之后就是.class字节码文件,classloader就是负责把这些.class文件加载到内存中
-
loading阶段:
- Bootstrap: 负责加载从RT.jar(RUNTIME MEMORY)加载.class文件,比如System.out,不需要在乎哪里来的System类,
- Extention: 负责从/jre/lib/ext 文件中加载.class
- Application:
-
linking阶段
- verify:Once the class files are loaded to the memory, there is a verify phase where the bytecode class files are verified if they conform the standards
- prepare: In the preparing phase, memory is allocated for the static variables and default values are assigned.
- resolve: In the resvolve phase, all the symbolic references are replayed with actual references.
-
initializaton阶段:all the static variables are assigned with the actual values and it also excutes the static initializers at this point of time
-
Runtime memory area
-
method area: all the class level data, 比如类静态变量
-
heap area: all the objects and instance variables are stored
-
stack memory: local variable, operand stack, frame data
-
PC register: current executing instructions
-
native method stack: native method information,native code,method也就是非java编写的本地代码,通常是C或C++写的。本地代码指的是在本地(通常是操作系统层面)编写和执行的代码。这些代码可以直接访问操作系统的底层功能和硬件设备,通常用于实现那些Java无法高效完成或无法直接访问的任务。
-
Execution engine: 将字节码文件转换成机器码文件并执行指令
-
Interpreter
-
JIT compiler
- Intermedia code generatoe: Generates intermedia code
- Code optimizer: optimizes the intermedia code for better performance
- target code generater: converts intermediate code to native machine code
- profiler: finding hotpots, methods, which are called repeatedly.
-
Java native method interface: interact with the native libraries and makes it avaliable for the JVM execution engine.
-
Garbage collector : destroy the objects that are no longer used.