JDK 8 Memory Layout and garbage collection

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).

PermGen is replaced with Metaspace in Oracle/Sun JDK8, which is very similar. The main difference is that Metaspace can expand at runtime.