JAVA basic training manual

Architectural thinking

 

surroundings

 

Configuration nginx configuration 1.1 What is the relationship between JDK, JRE, JVM?

What is the JVM?

 

The English name (Java Virtual Machine) is the Java virtual machine. It only recognizes .class type files. It can recognize the bytecode instructions in the class file and call the upward API of the operating system to complete the action.

 

What is JRE?

 

English name (Java Runtime Environment), Java Runtime Environment. It mainly contains two parts: the standard implementation of JVM and some basic class libraries of Java. Relative to the JVM, JRE has a part of the Java class library.

 

What is JDK? English name (Java Development Kit), Java development kit. JDK is the core of the entire Java development, it integrates JRE and some easy-to-use gadgets. For example: javac.exe, java.exe, jar.exe, etc.

 

The relationship between the three: nested relationship. JDK> JRE> JVM.

 

1.2 The memory model of the JVM and the partitioning situation and role

As shown below:

 

enter image description here

 

The yellow part is shared by threads, and the blue part is private by threads.

 

Method area

Used to store data such as class information, constants, and static variables loaded by the virtual machine.

 

stack

Store object instances, all objects and arrays must be allocated on the heap. It is the largest area of ​​memory managed by the JVM.

 

Stack

The memory model of Java method execution: store local variable table, operand stack, dynamic link, method exit and other information. The life cycle is the same as the thread.

 

Native method stack

The function is similar to the virtual machine stack, except that the local method stack serves the native method execution, and the virtual machine stack serves the Java method performed by the virtual machine.

 

Program counter

The line number indicator executed by the current thread. It is the smallest area of ​​JVM memory area. When performing bytecode work, the program counter is used to select the next bytecode instruction to be executed.

 

1.3 What is the process flow of JVM object creation?

The overall process is shown below:

 

enter image description here

 

Step 1: When the virtual machine encounters a new instruction, it will first check whether the parameter of this instruction can locate the symbol reference of this class in the constant pool, and check whether the class referenced by this symbol has been loaded & resolved & initialized.

 

Step 2: If the class has already been loaded then go to step 3; if it has not been loaded, then you need to load the class first.

 

Step 3: After the class loading check is passed, the next step is to allocate memory for the newborn object.

 

Step 4: The memory size required for object generation can be completely determined after the class loading is completed. Allocating space for objects is equivalent to dividing a certain size of memory from the Java heap

 

Step 5: The memory size is divided into two cases: The first case: the JVM memory is regular, all used memory is put on one side, the free memory is on the other side, and a pointer is placed in the middle as a demarcation point Indicator. Then at this time, allocating memory is relatively simple, as long as the pointer moves to the free space over a distance equal to the size of the object. This is "pointer collision".

 

The second case: the memory of the JVM is not regular, which means that the used memory and the unused memory are interleaved. At this time, there is no way to make use of corrective collision. At this time, we need to maintain a table to record the available memory. When allocating, find a large enough space from the list to allocate to the object instance and update it to the record table.

 

Step 6: After the space application is completed, the JVM needs to initialize the memory space to a value of 0. If you use TLAB, you can do this work when TLAB is assigned.

 

Step 7: The JVM makes the necessary settings for the object. For example, the object is an instance of which class, the object's hash code, GC age and other information.

 

Step 8: After completing the above steps, from the JVM, an object is basically completed, but from the perspective of Java program code, object creation has just begun, you need to execute the <init> method, according to the initialization set in the program Operation initialization, this time a real program object is generated.

 

1.4 How many types of garbage collection algorithms? What are their advantages and disadvantages?

Common garbage collection algorithms are:

 

Mark-clear algorithm, copy algorithm, mark-sort algorithm, generational collection algorithm

 

Mark-sweep algorithm

Mark-and-clear algorithm includes two stages: "mark" and "clear". Marking phase: Identify all objects to be recovered and mark them. Clearing phase: clear the objects that are unavailable in the marking phase.

 

Disadvantages:

 

Marking and removal are not efficient.

A large amount of debris will be generated, resulting in frequent recycling.

Replication algorithm

The memory is divided into two blocks of equal size, one of which is used each time, when garbage collection, the live object is copied to another block, and then this block

Guess you like

Origin www.cnblogs.com/ievixvs/p/12750001.html