This is the fourth day of my participation in the August More text Challenge. For details, see: August More Text Challenge

JVM- The internal structure of the runtime data area

The article has been synchronized to the GitHub open source project: JVMStudy

A, memory,

As a very important system resource, memory is the intermediate warehouse and bridge between the hard disk and CPU, which carries the real-time operation of the operating system and applications. The JVM memory layout defines the memory application, allocation and management strategies during the running process of JAVA, ensuring the efficient and stable running of the JVM. There are some differences in how memory is divided and managed by different JVMS (for Hotspot, it mainly means method area)

The location of the runtime data area in the JVM

Third, the internal structure of the runtime data body

A process corresponds to a JVM instance, a runtime data area, and multiple threads that share the method area and the heap. Each thread contains the program counter, the local method stack, and the virtual machine stack.

Note: The method area corresponds to the metadata area after JDK8

Four, partition introduction

The Java Virtual machine defines several run-time data areas that are used during the run of a program

  • Some of these are created as the virtual machine starts and destroyed as the virtual machine exits, the red area
  • Others are thread-specific, and these thread-specific data areas are created and destroyed as the thread begins and ends. Gray area

Each JVM instance corresponds to a RunTime instance, the RunTime environment. Equivalent to the inside of the box shown in the figure above.

Five, the thread

  • A thread is a running unit within a program. The JVM allows multiple threads to execute a program in parallel.

  • In the HotSpot JVM, each thread maps directly to the operating system’s native thread.

  • When a Java thread is ready to execute, a local thread of the operating system is created at the same time. After Java thread execution terminates. Local threads are also recycled.

  • The operating system is responsible for scheduling all threads to any available CPU. Once the local thread is successfully initialized, it calls the run () method in the Java thread.

6. JVM system threads

  • If you use JConsole or any of the debugging tools, you’ll see many threads running in the background. These background threads do not include the main thread that calls the main method and any threads created by the main thread itself;
  • The main background system threads in the HotSpot JVM are:
    • A virtual machine thread is a thread that requires the JVM to reach a safe point before it can operate. The reason these operations must occur in different threads is that they all require the JVM to reach a safe point so that the heap does not change. This thread execution includes “stop-the-world” garbage collection, thread stack collection, thread suspension, and biased lock undo
    • Periodic task thread: This thread is the withdrawal of periodic events (such as interrupts) that are typically used to schedule execution of periodic operations.
    • GC threads: These threads support different kinds of garbage collection in the JVM
    • Compile thread: This thread reduces the cost of bytecode compilation to local code at runtime
    • Signal scheduling thread: This thread receives signals and sends them to the JVM for processing by calling the appropriate method within it.

The article has been synchronized to the GitHub open source project: JVMStudy