`

JVM学习笔记-压缩收集器(Compacting Collectors)

阅读更多

Compacting Collectors

Garbage collectors of Java Virtual Machines will likely have a strategy to combat heap fragmentation. Two strategies commonly used by mark and sweep collectors are compacting and copying. Both of these approaches move objects on the fly to reduce heap fragmentation. Compacting collectors slide live objects over free memory space toward one end of the heap. In the process the other end of the heap becomes one large contiguous free area. All references to the moved objects are updated to refer to the new location.

Java虚拟机的垃圾收集器可能有对付堆内存碎块的策略。标记并清除收集器通常使用的两种策略是压缩和拷贝,这2种方法都是快速的移动对象来减少堆碎块,。压缩收集器把活动的对象越过空闲区滑动到堆得一端,这个过程中,堆的另一端出现一个大的连续空闲区,所有被移动的对象引用也会被更新指向新的位置。

 

Updating references to moved objects is sometimes made simpler by adding a level of indirection to object references. Instead of referring directly to objects on the heap, object references refer to a table of object handles. The object handles refer to the actual objects on the heap. When an object is moved, only the object handle must be updated with the new location. All references to the object in the executing program will still refer to the updated handle, which did not move. While this approach simplifies the job of heap defragmentation, it adds a performance overhead to every object access.

更新被移动的对象的引用通过一个间接对象引用层可以变的更简单。不直接引用堆中的对象,对象的引用时间上是指向一个对象句柄表,对象句柄才指向堆中对象的实际位置。当对象被移动时候,只有这个句柄需要被更新为新位置,这个方法简化了消除堆碎块的工作,但是每一次对象访问都带来了性能的损失。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics