Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of JVM Runtime data area

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you the example analysis of the JVM runtime data area, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Memory and threading

1. Memory structure

2. Thread running

An application in JVM can have multiple threads executing in parallel, and the thread is mapped one-to-one to the operating system thread where the service resides. Scheduling is executed on the available CPU, and an operating system thread is created when the thread is started. When the thread terminates, the operating system thread is also reclaimed.

When the virtual machine starts up and runs, multiple threads are created, and some modules in the datazone are shared by threads or private by threads:

Thread sharing: metadata zone, heap Heap

Thread private: virtual machine stack, local method stack, program counter

A single CPU can only execute one thread at a given time, so multithreading uses several blocks of space, and then constantly scrambles for the execution period of the CPU.

2. Metadata space

Basic description

In actual development, there are often too many classes loaded, which leads to memory overflow problems, which can expand the size of metaspace.

Relationship with the heap

The metaspace stores the loaded class information, and when the class is instantiated, the instantiated object information is stored in the heap, and the class is found through the pointer of the object type data.

III. Heap space

Basic description

When JVM starts, it creates a heap area, which is the core area of memory management, usually the largest memory space, is shared by all threads, and almost all object instances have to allocate memory in the heap, so this is also the key space for garbage collection.

Stack relationship

The stack is the unit of the JVM runtime, and the heap is the unit of storage. When the method in the stack ends and the related object loses all references, the heap space will not be removed immediately until the garbage collector runs.

IV. Virtual machine stack

The virtual machine stack (Java stack) generates a virtual machine stack when each thread is created, and the interior of the stack is a stack frame unit. Corresponding to the call of the Java method, its life cycle is consistent with the thread cycle. Used to store local traversal of methods, partial execution results, method calls and returns.

Program counter

Basic description

The program count register in JVM is used to store the address of the next instruction to be executed. The execution engine obtains the instruction and executes it, which is private to the thread. It can be seen as a line number indicator of the bytecode executed by the current thread.

Before-and-after relationship

The thread executes the code within the time period in which the CPU is obtained, but the thread may be suspended at any time before it is finished. When thread A gets the CPU execution again, the CPU needs to know which instruction is executed to thread A, and the program counter will store the action.

6. Local method stack

The function of the local method stack is similar to that of the virtual machine stack. The virtual machine stack executes Java methods for the virtual machine, and the local method stack manages the local methods used by the virtual machine. In the virtual machine specification, there is no mandatory stipulation on the language, usage and data structure of the methods in the local method stack, so the specific virtual machine can implement it freely. The HotSpot virtual machine directly combines the local method stack with the virtual machine stack.

The above is all the content of the article "sample Analysis of the JVM Runtime data Zone". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report