JDK 8内存布局和垃圾回收

Oli*_*POP 30 java garbage-collection java-8

据我所知,从JDK 8开始,PermGen将成为java历史上的一个页面.一切都很美好......但新的内存布局会是什么样子?这会影响新平台上的GC吗?

Ada*_*yga 38

PermGen被 Oracle/Sun JDK8中的Metaspace取代,这非常相似.主要区别在于Metaspace可以在运行时扩展.

  • @ user503413基于我提供的链接:"默认情况下,类元数据分配受可用本机内存量的限制(当然,如果使用32位JVM与64位以及OS虚拟内存可用性,则容量将取决于此) ".它也可以使用`MaxMetaspaceSize`参数进行限制 (3认同)

par*_*085 23

This is when permGen is there enter image description here

After Metaspace is introduced enter image description here

Definitely, there is lot of improvement in GC in Java 8. You can check this stackoverflow post

In Metaspace, multiple mapped virtual memory spaces are allocated for metadata and allocation ( in chunks) is per class loader depending on the type of classloader and its liveness . Chunks are returned to free chunks list and also virtual memory spaces returned when emptied.

Advantage of GC would be

  • During full collection, metadata to metadata pointers are not scanned
  • A lot of complex code (particularly for CMS) for metadata scanning was removed.
  • Metaspace contains few pointers into the Java heap.
  • No compaction costs for metadata
  • Reduces root scanning (no scanning of VM dictionary of loaded classes and other internal hashtables).

More detail is here