请教问题:老年代一直扩容,从初始值设置的168M,扩容到了1.2G,但查看老年代的已使用占比才5%,为什么没有缩容。望老师解答,谢谢! 环境:Linux , jdk 8 , CMS 收集器, MinHeapFreeRatio=40, MaxHeapFreeRatio=70, MinHeapDeltaByte=196608
CMS GC不会缩容
void ConcurrentMarkSweepGeneration::shrink_free_list_by(size_t bytes) { assert_locked_or_safepoint(Heap_lock); assert_lock_strong(freelistLock()); if (PrintGCDetails && Verbose) { warning("Shrinking of CMS not yet implemented"); } return; } 复制
void ConcurrentMarkSweepGeneration::shrink_free_list_by(size_t bytes) { assert_locked_or_safepoint(Heap_lock); assert_lock_strong(freelistLock()); if (PrintGCDetails && Verbose) { warning("Shrinking of CMS not yet implemented"); } return; }
感谢您的解答。除了从代码上避免使用大对象,从而避免老年代扩容很多,有没有什么方法可以使老年代缩容? 我在本地做了这样一个测试:程序创建AllaryList 对象,分配连续的内存,然后clear,启动另一个线程执行 System.gc()。堆内存是会缩容的。变化情况如下图:
CMS GC不会缩容
void ConcurrentMarkSweepGeneration::shrink_free_list_by(size_t bytes) { assert_locked_or_safepoint(Heap_lock); assert_lock_strong(freelistLock()); if (PrintGCDetails && Verbose) { warning("Shrinking of CMS not yet implemented"); } return; }