当前位置:网站首页>03 runtime data area overview and threads

03 runtime data area overview and threads

2022-06-25 18:22:00 Name is too tangled

1. summary

This section focuses on the runtime data area , That's the part below , It's in the stage after class loading is complete

 Insert picture description here

class File passing through classloader subsystem ( load –> link –> initialization ) Three steps of , After the loading , The method area in memory holds the runtime class itself , Next, use the execution engine to execute , All processes executed by the execution engine need Run time data area

 Insert picture description here

Memory

  • Memory is a very important system resource , It's hard disk and CPU Middle warehouse and Bridge , It carries the real-time operation of the operating system and application program
  • JVM The memory layout defines Java At run time Memory application 、 Distribute 、 management The strategy of , To ensure the JVM Efficient and stable operation of
  • Different JVM There are some differences between memory partition and management mechanism . combination JVM Virtual machine specification , Let's talk about the classic JVM Memory layout
  • We use disks or networks IO Data obtained , All need to be loaded into memory first , then CPU Get data from memory for reading

Run time data area

 Insert picture description here
 Insert picture description here

Detailed explanation

Java Virtual machine defines several kinds of runtime data areas that will be used during program running , Some of them will be created as the virtual machine starts , Destroy with virtual machine exit . Others correspond to threads one by one , These data regions corresponding to the thread are created and destroyed as the thread starts and ends .
The gray one is Individual threads are private , The red one is Shared by multiple threads . namely :

  • Thread unique : Independence includes Program counter Stack Native Method Stack
  • Sharing between threads : Pile up 、 Out of heap memory ( Permanent generation or meta space 、 Code cache )
     Insert picture description here

About sharing between threads

 Insert picture description here
Every JVM only one Runtime example . That is, runtime environment , Equivalent to the middle frame of the memory structure : Runtime environment .

2. Threads

2.1 Threads

  • A thread is a running unit in a program .JVM Allows an application to have multiple threads executing in parallel
  • stay Hotspot JVM in , Each thread is mapped directly to the local thread of the operating system
    • When one Java When the thread is ready to execute , At this time, a local thread of the operating system is also created .Java After thread execution is terminated , Local threads also recycle
  • The operating system is responsible for scheduling threads to any available CPU On . Once the local thread is initialized successfully , It's going to call Java In thread run( ) Method
  • If a thread throws an exception , And this thread is the last non daemon thread in the process , Then the virtual machine will stop
  • When JVM When all threads in are daemons ,JVM You can quit ; If there is one or more non daemon threads, they will not exit .( The above is for normal exit , call System.exit Will exit )

2.2 JVM System threads

  • If you use jconsole 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 of them are created by this main Method creates its own thread
  • These are the main background system threads ( The guardian thread ) stay 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 ( a key )
    • Compile thread : This thread will compile bytecode into Native code
    • Signal scheduling thread : This thread receives signals and sends them to JVM, Inside it, it's handled by calling the appropriate method
原网站

版权声明
本文为[Name is too tangled]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202190531522426.html