编程知识 cdmana.com

Java JVM -- 3. Overview of runtime data area and thread

Run time data area Overview

stay JVM Position in


Internal division

   When we pass the front : Class loading → verification → Get ready → analysis → initialization After these stages are completed , The execution engine will use our classes , At the same time, the execution engine will use our runtime data area .

   The runtime data area is in JVM The memory area of . We use disks or networks IO Data obtained , All need to be loaded into memory first , then CPU Get data from memory for reading , In other words, memory acts as CPU The bridge between disk and disk .

  JVM The runtime data of is divided into thread private areas ( Program counter 、 Virtual machine stack 、 Local method area )、 Thread sharing area ( Pile up 、 Method area ) And direct memory , As shown in the figure :

 JVM The memory area of


Threads

Runtime datazones and threads

   The life cycle of a thread's private area is the same as that of a thread , Created with thread startup , Destroy with the end of the thread . stay JVM Inside , Each thread is mapped directly to the local thread of the operating system , Therefore, the existence of this part of memory area corresponds to the startup and destruction of local threads .

   The thread sharing area is created with the start of the virtual machine , Destroy with virtual machine shut down .

   Direct memory is also called out of heap memory , It is not JVM Part of the runtime data area , But it is frequently used in concurrent programming .JDK Of NIO The module is based on Channel And Buffer Of I/O The way to operate is heap based External memory ,NIO The module calls Native The library allocates out of heap memory directly on the operating system , And then use DirectByteBuffer Object as a reference to this memory to operate on the memory ,Java Processes can be avoided by using out of heap memory technology Java Heaps and Native The resource consumption and performance consumption caused by copying data back and forth in the heap , Therefore, out of heap memory is widely used in high concurrency application scenarios (Netty、Flink、HBase、Hadoop It's useful for out of heap memory ).


JVM System threads

   When you use console Or any debugging tool , You can see that there are many threads running in the background . These background threads do not include calls public static void main(String[]) Of main Threads and all this main A thread created by a thread itself .

These main background system threads are in Hotspot JVM There are mainly the following :

* Virtual machine threads : This kind of thread operation needs JVM The safety point will be reached . The reason these operations have to happen in different threads is that they all need JVM Reach safety point , So the pile doesn't change . The execution types of this thread include "stop-the-world" Garbage collection , Thread stack collection , Thread suspension and biased lock revocation .

* Periodic task thread : This thread is the embodiment of time cycle events ( Like interruptions ), They are generally used for scheduling execution of periodic operations .

*GC Threads : This kind of thread pair is in JVM There are different kinds of garbage collection behaviors that support .

* Compile thread : This thread compiles bytecode into local code at run time .

* Signal scheduling thread : This thread receives signals and sends them to JVM, Inside it, it's handled by calling the appropriate method .

版权声明
本文为[There's a bastard in the north of the city]所创,转载请带上原文链接,感谢
https://cdmana.com/2020/12/20201224091951903g.html

Scroll to Top