当前位置:网站首页>Learning JVM garbage collection 06 - memory set and card table (hotspot)

Learning JVM garbage collection 06 - memory set and card table (hotspot)

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

Catalog

Memory set

What does a memory set do

What is a memory set

Implementation of memory set ( Card table )

Card table


Memory set

What does a memory set do

Here is the memory set , To solve the problems caused by cross generational reference .

Only for the collection of the new generation (Minor GC), What if there are old objects referencing new objects ? It's OK to check the whole elderly generation , But it's not worth it . So the memory set appeared .

What is a memory set

Record from Non collection area Point to Collection area Of the pointer collection Abstract data structure .

Implementation of memory set ( Card table )

As mentioned above , Memory set is an abstract data structure , You need a corresponding concrete implementation .

Think roughly , You can build an array , Store objects with cross generational references in all non collection areas .

Virtual machines think it's too expensive , There is no need to . The collector only needs to know whether there is a pointer to the collection area in a non collection area . therefore , The virtual machine uses a more rugged granularity , Such as word length accuracy ( A machine word length ).

Of course, the accuracy of the object is also ok , But it's not like building an object array as mentioned above , Instead, it is a mark to store whether there is a cross generational pointer .

And that is Card accuracy . It means that each record is accurate to a memory area , There are objects in this area that contain cross generational pointers . Using card precision to realize the data structure of memory set is called Card table .

Card table

stay HotSpot in , The card table is a byte array . Each element in the card table corresponds to a specific size of memory that identifies the memory area . This piece of memory is called card page .HotSpot The card page of is 512 byte . As long as there is a cross generational reference to an object in a card page , The value of the array element corresponding to the card table is marked as 1, It's called dirty elements . If you don't have it, you'll do it 0.

During garbage collection , Filter out the dirty elements in the card , Add them to GC Roots Scan them together .

That's all for the canto .

Keep early hours , take care . The king of early rising wishes you a thousand miles a day

原网站

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