A:
What is a Java Virtual Machine (Jvm)? 2. What is Java virtual machine used for? 3. What is the architecture of Java virtual machine? 4. What is the role of the Java VIRTUAL machine? 5.Java VIRTUAL machine at runtime data area?
Two: Basic concepts of Jvm
A Java Virtual machine (Jvm) is a hypothetical computer that can run Java code
The Java virtual machine consists of a set of bytecode instructions, a set of registers, a stack, a garbage collection heap, and a storage method field.
Before understanding the Jvm, you if you have interest, can also go to the understanding of Java heap and stack, can watch on an article: the difference between the Java heap and stack blog.csdn.net/u011546655/…
3: the Jvm
We all know that Java source files, through the compiler, can produce corresponding. Class files, which are bytecode files, which in turn pass through the Java Virtual machine interpreter, which is the bytecode instruction set in all previous Java Virtual machines… . Compiled to machine code on a particular machine
Namely, as follows:
1.Java source files — > compiler — > bytecode files
2. Bytecode files — >Jvm — > machine code
The interpreter for each platform is different, but the virtual machine implemented is the same. Is that why Java can be cross-platform
When a program starts running a program, the virtual machine is instantiated. Multiple instances of virtual machines exist when multiple applications are started. The program exits or is closed. Then the VM instance dies. Data cannot be shared between multiple VM instances.
Four: ARCHITECTURE of the Jvm
The architecture of the Jvm is as follows:
1. Garbage collector
Garbage collector (also known as GC) : The garbage collector is responsible for collecting objects in memory that are useless (as everyone knows). If these objects have no references, they are treated as garbage and are disposed of.
Class loading subsystem
As soon as you hear the name, you know it must be used to operate on what we’ve compiled. Class file system, which does the following:
1. Locate and import the binary class file. 2. Allocate initialization memory for classes. 4. Help parse symbolic references
3. Execution Engine
Execute the package’s instructions in the method that loads the class, which are called methods
4. Running area data
As shown in the figure above: Virtual machine memory or Jvm memory, a chunk of the entire computer memory is allocated to store objects, variables, etc., needed by the Jvm. Run area data is divided into many small areas, respectively: method area, virtual machine stack, local method stack, heap, program counter
Five: Jvm runtime data area
1. Program counter
The current thread executes the bytecode signal indicator, the thread is private, its life cycle and the same thread branch, loop, jump, exception handling, thread recovery and other basic functions need to rely on this counter.
2. Vm stack
Java virtual machine Stack describes the memory model of execution of Java methods (different from native methods) : When each method is executed, a Stack Frame is created at the same time to store information such as local variation table, operation Stack, action link, method exit, etc.
The thread is private, and the life cycle is the same as that of the thread. Each method is called until it is executed, which corresponds to the process of a stack frame moving from the virtual machine stack to the virtual machine stack.
3. Local method stack
Similar to the virtual machine method stack, the Native method stack serves the Native method services used by the virtual machine
4. Local Method area:
It just implements the Native method. StackOverflowError and OutOfMemoryError are also thrown if the area is out of memory.
Six: heap
The heap is the largest area of the Jvm, where application objects and data reside. This area is also shared by threads. It is also the main collection area of GC.
This is actually the one you hear a lot about: the Java (GC) garbage collector
A running diagram of the JVM
When Java source code is stored on hard disk and code is run on the virtual machine, the JVM creates a space in memory that is divided into stack memory, heap memory, and (storage area) method area where methods belong to classes so the JVM maps the source file Person.class on hard disk to the method area Person p = new Person(); We know that the variable P is stored in stack memory and it’s stored in a bunch of addresses and the direction of the address is that the Person that’s new is in the heap memory and the Person that’s in the heap takes a copy of that class template from the method area
Share with you
I want to work my way up
Fly forward on the blades at the highest point
Let the wind blow dry tears and sweat
I want to work my way up
Waiting for the sun to watch its face
Little days have big dreams
I have my day
Let the wind blow dry tears and sweat
One day I will have my day