preface

MySQL article near the end, after we will continue to send some articles, such as MVCC and so on, the next stage, we are ready to enter the JVM, Redis and other knowledge points of learning, this is the senior programmer interview must ask knowledge points, follow the elder brother’s article, learn JVM, high salary go!!

The relationship between JRE, JDK, and JVM

The JDK is a common development package used by Java programmers to compile and debug Java programs.

JRE refers to the Java runtime environment, that is, our written programs must run in the JRE.

The JVM is a Java Virtual Machine (Java Virtual Machine), which is responsible for interpreting bytecode into specific Machine code for execution. It is worth noting that during execution, the Java source program must be compiled into a. Class file by the compiler, otherwise the JVM will not recognize it.

JVM composition structure

Let’s take a look at the components of the JVM

The JVM structure

Class loading subsystem

Is responsible for loading class information from the file system or network in a memory space called the method area

Methods area

Used to store class information, constant information, constant pool information, including string literals and numeric constants. Our common reflection is the class information read from this method area

Java heap (the focus of the next article)

The heap space is an area of memory created when the JVM is started, where almost all object instances are stored (i.e., new objects).

This area is divided into the new generation and the old generation. The garbage collection mechanism is used to collect garbage data from heap space.

The data in the heap space is shared by all threads, so there are thread safety issues. So those locks are designed to address the thread-safe problem of heap space data.

Direct memory

Direct memory is not part of the running data region of the virtual machine, nor is it defined in the VIRTUAL machine specification, but it is frequently used by reads and writes and may cause OutofMemoryErrors.

The allocateDirect method in Java NIO can use direct memory directly, which can significantly improve read and write speed.

Java stack

The stack is one of the two brothers of the stack. All threads share the data in the stack space, but the stack space is unique to each thread and cannot be accessed directly by each other.

Stack space is a memory space created when a thread is created. The stack mainly holds some local variables, method parameters, Java method calls, return values and other information.

Local method stack

The difference between a native method stack and a Java stack is that you can directly call Java native methods, which are native in the JDK.

Garbage collection system (more on this later)

GC garbage collection is a very important knowledge point, to ensure that our program can have enough memory space to run, reclaim the memory has been invalid data, we can understand as our daily live garbage collection.

Recycling algorithms generally include the tag cleaning algorithm, the copy algorithm, the tag collation algorithm, and so on. In future articles, we will explain each algorithm in detail.

PC register

It is each thread private space, the JVM will create a separate PC for each thread registers, at any time, a Java thread is always in the execution method, this method is called the current method, if the current method is not local, PC register will execute the instructions that are executed, if it is a local method, The PC register value is undefined, and the register stores information such as the current environment pointer, program counter, operation stack pointer, and calculation variable pointer.

Execution engine

A very core component of the JVM, it is responsible for executing the JVM’s bytecode, usually compiled into machine code and then executed.

conclusion

Today we are going to focus on the structure of the JVM. We will take a look at the JVM in general and then go into each point in more detail, what the heap is, what GC garbage collection is, etc. Stay tuned.

IT brother

A big factory to do advanced Java development program ape

Concern – micro – letter – public – number: IT elder brother

Java foundation, Java Web, JavaEE all tutorials, including Spring Boot, etc

Reply – reply: resume template, you can get 100 beautiful resume

Back – back: Java learning route, you can get the latest and most complete a learning roadmap

Back to back: Java ebooks, you can receive 13 top programmers must read books