Class loading subsystem

The Class loading subsystem is responsible for loading Class information from the file system or network, and the loaded Class information is stored in a piece of memory called the method area. In addition to Class information, the method area may hold runtime constant pool information, including string literals and numeric constants (this constant information is a memory map of the constant pool portion of the Class file).

Execution engine

Responsible for executing the virtual machine bytecode. Hotspot scan.



The runtime data area includes the program counter, Java virtual machine stack, local method stack, method area, and heap. Among them,Java virtual machine stacks, local method stacks, and program counters are private to each thread.

Program counter

Can be thought of as a line number indicator of the bytecode to be executed by the current thread. With Java multithreading, each thread must have its own independent program counter in order for the program to return to the correct execution position after each switch. If the thread is executing a Java method, it records the address of the virtual machine bytecode instruction that is executing (null if it is executing a local method).

Java virtual machine stack

Thread private. Each thread creates its own private virtual machine stack. Each time a thread executes a method, it creates a stack frame in the thread’s virtual machine stack to store information about local variables, operand stacks, constant pool references, and so on. The process of method invocation until execution is complete corresponds to the process of a stack frame being pushed and removed from the Java virtual machine stack.


The local variable table holds various basic data types, object references, and ReturnAdress (the address of the bytecode instruction you need to return).

There are two anomalies:

  • A StackOverflowError is raised when the stack depth of a thread request exceeds the maximum.
  • An OutOfMemoryError is raised if sufficient memory cannot be allocated for dynamic stack scaling.

You can specify the size of Java virtual machine stack memory per thread with the -xss virtual machine parameter:

java -Xss512M HackTheJavaCopy the code

Local method stack

It’s similar to the virtual stack, except that it serves Native Method.

A Native Method is a Java interface that calls non-Java code. A Native Method is a Java Method whose implementation is implemented in a non-Java language, such as C.

Native Method a: blog.csdn.net/wike163/art…

www.cnblogs.com/HDK2016/p/7…

The heap

Store object instances. Shared by all threads.

OOM abnormal

Methods area

Used to store loaded class information, constants, static variables, just-in-time compiler compiled code, and so on. In HotSpot, the persistent generation is the implementation of the method area. Because GC generation collection extends into the method area. The method area is mainly a collection of obsolete classes and constants, and you can also choose not to do garbage collection for the method area.

In general, method areas do not do garbage collection.

After jdk1.8, HotSpot removed the persistent generation, the information about the persistent generation is stored in the meta space.

OOM anomalies.

Run-time constant pool

The runtime constant pool is part of the method area.

The constant pool (literal and symbolic references generated by the compiler) in the Class file is placed in this area after the Class is loaded.

The runtime constant pool is dynamic, allowing dynamic generation in addition to constants generated at compile time, such as intern() for the String class.

String.intern()

If the current string exists in the constant pool, the current string is returned directly. If the string is not in the constant pool, it is put into the constant pool and then returned.

A: tech.meituan.com/2014/03/06/…

Direct memory

Java’s NIO library allows Java programs to use direct memory. Direct memory is the memory space outside the Java heap that is claimed directly to the system. Direct memory is usually faster to access than the Java heap. For performance reasons, direct memory may be used in situations where read and write are frequent. Since direct internals reside outside the Java heap, its size is not directly limited by the maximum heap size specified by Xmx, but system memory is finite, and the sum of the Java heap and direct memory is still limited by the maximum memory the operating system can give.

Efficient access is not affected by heap size.