Metaspace of JVM series

1. Introduction to Metaspace
    JDK 8 begins to put the metadata of the class into the native heap. This area is called Metaspace, and the Chinese name is Metaspace.
    What are the benefits of using local memory? The most direct manifestation is that the OOM problem will no longer exist, because the default class metadata allocation is only limited by the size of the local memory, that is to say, how much the local memory is left, theoretically how big the Metaspace can be (it seems that the capacity is also related to the operating system). virtual memory related? It's not clear here), which solves the problem of insufficient space. However, making the Metaspace infinite is obviously unrealistic, so we also limit the size of the Metaspace: use the -XX:MaxMetaspaceSize parameter to specify the size of the Metaspace area. By default, the JVM dynamically sets the size of MaxMetaspaceSize at runtime as needed.

Second, the difference between JDK1.7 and JDK1.8 memory

  • Removed PermGen and added Metaspace to Native Memory
  • Static variables and constant pool moved to Heap Space
  • Class metadata moved to Metaspace


3. Metaspace and PermGen compare

    the disadvantages of PermGen
  • Fixed PermSize, size is hard to determine and hard to scale
  •     -XX:MaxPermSize
        -XX:PermSize
  • The class meta object in PermGen may be moved during full GC
  • When java.lang.OutOfMemoryError: PermGen error occurs
  •     The application should clear all references associated with the class
        or change the MaxPermSize and restart the application
  • The meta-classmeta object is required to describe the classmeta object
  • Garbage collection is less efficient and requires scanning the entire PermGen


    Advantages of Metaspace
  • The lifecycle of classes and class metadata is consistent with class loaders
  • The space allocation of Metaspace is linear and can be linearly expanded with the number of class loads. By default, it is only related to the size of native memory
  • The location of metadata in native memory is fixed
  • The metaspace space will not be scanned during GC, which saves the time of scanning and compression (if the size of the metaspace is set, the full GC will also be performed when the threshold of the metaspace is reached)
  • Reduced time for full gc


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326394781&siteId=291194637