JVM operation mechanism and principle

A, JVM lifecycle

Java JVM accompanied by the beginning of the program and start, stop and end of the program. A Java program opens a JVM process, you can run multiple programs on one computer, you can run multiple JVM processes.

JVM thread is divided into two types: ordinary thread and thread guard. Daemon threads are threads in the JVM its own use, such as garbage collection (GC). General common thread is threaded Java programs, as long as there are common threads in the implementation of the JVM, the JVM will not stop.

Two, JVM startup process

Three, JVM architecture

 

Four, JVM memory model

JVM memory model consists of heap memory, the method area, the program counter, the virtual machine stacks and stacks composed of native methods. Heap and method area is shared by all threads, and virtual machine stack, native method stacks and program counters are thread private.

1, heap memory

Heap memory is an important element of memory performance tuning in a production environment, the main content for a number of mechanisms and algorithms memory recovery.

2, the method area

Class information is used to store the virtual machine has been loaded, constants, static variables, the time compilation (JIT) codes and other data.

3, the program counter

In the conceptual model of the JVM bytecode interpreter is working by changing the value of the counter to select the next bytecode instruction to be executed. Branches, loops, jumps, exception handling, thread resume and other basic functions need to rely on the counter to complete.

4, Java virtual machine stack

Is a virtual machine stack Java memory model described method performed: Each method creates a stack frame (Stack Frame) while performing table for storing local variable (local variable table memory needed during compilation so identified The method does not change during operation size), information operand stack, dynamic linking, method exports.

5, native method stacks

In the program calls or calls when the JVM native method interface (Native) enabled.

Five, Java class loading mechanism

Refers to a class of loading binary data read class .class files into memory, the method in which region the runtime data area, and then create a java.lang.Class objects in the heap area for the method of encapsulation class data structure area. The final product is loaded Class class object is located in the stack area, Class objects encapsulate data structure classes in the method area, and provides an interface access method for a data structure of the region to Java programmers.

Class loading process:

1, the loading

  1) to get its fully qualified name defined by a class of binary byte stream.

  2)将这个字节流所代表的静态存储结构转化为方法区的运行时数据结构。

  3)在Java堆中生成一个代表这个类的java.lang.Class对象,作为对方法区中这些数据的访问入口。

2、链接。

  验证:确保被加载的类的正确性

  准备:为类的静态变量分配内存,并将其初始化为默认值

  解析:把类中的符号引用转换为直接引用

3、初始化

为类的静态变量赋予正确的初始值,JVM负责对类进行初始化,主要对类变量进行初始化。

Java中对类变量进行初始值设定的两种方式:

  1)声明类变量是指定初始值

  2)使用静态代码块为类变量指定初始值

Guess you like

Origin www.cnblogs.com/kingshine007/p/11432043.html