“This article has participated in the call for good writing activities, click to view: the back end, the big front end double track submission, 20,000 yuan prize pool waiting for you to challenge!”
First: The JVM runs the binary file after loading it,
Including the classloader, and then going into memory to run, how is that memory divided?
1. The method of area
This method area, after a class passes through the classloader, stores the template class file of the current class in the method area
Method area:
Matters needing attention:
Method area, also known as static area, stores all Class objects and is shared by all line cities
The method area contains elements that are always unique in the entire program, such as class, static variables.
There’s also a lot of data in the method area for static variables, static methods,
2. Heap space:
Heap space is where objects are stored, and all new objects are stored in heap space,
Stack storage, stack operation,
3. Program counter:
Execute methods based on multiple threads in the JVM –> method code
Because all threads run a method, a virtual stack of the current thread is created to store local variables in the method;
So, as long as the program is running, there will be a virtual stack,
If there are multiple recursive methods nested, this is because of the stack frame inside the current vm stack
4. How does a class load, run, and die in memory?
First, when the binary bytecode file class passes through the classloader and is loaded into the JVM, the various parts of the JVM work together.
(1) The class object is loaded into the static section, where the static modified member variable ** is stored
(2) Run, the thread starts to create a virtual machine stack space for the method to run (the program is run by method calls), each method member variable will create a **** stack frame
Write to the virtual machine stack, stack space storage data exchange and processing,
Then if you need to create an instantiation object of the current class,Java’s reflection mechanism creates the instantiation object from the method area,
(3) The instantiated object is stored in the heap space, the only heap space only exists is the class object, is the ordinary instantiated object
(4) The object calls the method, the stack space reads the reference address of the current object, begins the complex calculation, and then the method ends
Get results, end, garbage collection, method end
Matters needing attention:
Currently, there are only heap storage objects, stack running methods, and reference addresses of the storage objects in the memory area.
Class loading is a detailed process that runs on the JVM