当前位置:网站首页>Learn the memory management of JVM 02 - memory allocation of JVM

Learn the memory management of JVM 02 - memory allocation of JVM

2022-07-05 12:15:00 The king of early rising

Here's to say JVM Which parts of the memory is divided into , What are they .

The overview

As shown in the figure , Pictures come from books

—— In depth understanding of Java virtual machine :JVM Advanced features and best practices ( The first 3 edition ) Zhi-ming zhou

Here, the thread isolated data area intend Each thread has its own share .

The next? , We focus on the runtime data area , Whatever else .

Run time data area

Program counter

This is simpler , It is to mark which line the program executes , Which line should be executed next .

         This may not make much sense in a single thread , But when multiple threads execute concurrently , His role is very important . When a thread executes an instruction , You need to switch other threads to execute , The current thread needs to be paused . To switch back to the thread , Be able to execute programs in the correct order , Need to mark line number .

Java Virtual machine stack

         It is unique to each thread .

         When each method is executed ,Java All virtual machines will create a stack frame synchronously . If you don't know stack frames , It's not accurate , It can be temporarily understood as an element in the stack . Stored in the stack frame is : Local variable table 、 The stack of operands 、 Dynamic connection 、 Method exit information . Method call , Stack frames are created , Push . Method execution completed , Out of the stack .

in other words , Virtual machine stack is method related .

Local variable table

Virtual machine stack , Part of the stack frame , More important , Take it out and say .

The local variable table stores 8 Big basic data types 、reference type and returnAddress type .

reference type yes Object reference

returnAddress type :

         about JVM Come on , A program is a bytecode instruction stored in the method area , and returnAddress A value of type is a pointer to a specific instruction memory address .

above 10 All data types can be known at compile time .

Native Method Stack

Similar to virtual machine stack . The difference is that Virtual machine stack by Virtual machine execution Java Method service , The local method stack serves the local methods used by the virtual machine .

Java Pile up

Shared by all threads .

For storing object instances . Almost all object instances are stored here .

for instance :

Student Tom = new Student(); //Student It's a custom class 

 Tom yes reference type , Store in the stack .

new Student() Is an object instance , Store in the pile .

         From the point of view of allocating memory , All threads share Java In the pile , It can be divided into private allocation buffers for multiple threads , Used to improve the efficiency of object allocation . take Java The purpose of heap subdivision is to better reclaim memory , Or allocate memory faster .

Method area

         Used to store... That has been loaded by the virtual machine Type information 、 Constant 、 Static variables 、 Real time compiler compiled code cache and other data .《Java Virtual machine specification 》 Zhongba Method area Described as one of the heaps Logical part , But it has an alias called “ Non heap ” The purpose is to Java Heap differentiation .

        About method area , A little bit , Not much here , See :

Study JVM Memory management of 03——JVM Method area of 、 Meta space _ The blog of the early rising King -CSDN Blog What is the method area ? What is stored in meta space ?https://blog.csdn.net/qq_57014350/article/details/122590237

All right. , That's all for the canto .

Keep early hours , take care . King of early rising , I wish you good luck .

原网站

版权声明
本文为[The king of early rising]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140531328102.html