“This is the 27th day of my participation in the August Gwen Challenge.

Today we are going to talk about how JVM memory regions are run and divided:

Because there are many programs running every day, they all run in the JVM (JAVA VIRTUAL MACHINE), let’s uncover it:

In essence:

The Java memory area is divided into method area, stack space, heap space, and program counter:

The process from loading to running a class looks like this:

1. Methods 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 Static area, also known as method area, holds all Class objects and is shared by all threads

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


Q: What happens when a class is loaded to die?

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 — the method section, which holds static modified member variables

  • (2) is up and running, a thread stack space, began to create a virtual machine for method (program are run by the method invocation), member variables of each method will create a stack frame Write to a virtual machine, stack space to store data exchange and processing, and then if you need to create the current class instantiation objects, Java’s reflection mechanism creates instantiated objects 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, starts the complex calculation, and then the method ends to obtain the result, end, garbage collection, method end

** Note: The current memory area, there are only heap storage object, stack running method and storage object reference address,

Class loading is a detailed process that runs on the JVM