What is the use of MetaSpace in Java 8?

I know that they replaced PermGen with MetaSpace in Java 8. But I have a few questions:

  • By default, MetaSpace compiles GC?
  • Even the PermGen GC is compiled by adding args as -XX:+CMSClassUnloadingEnabled , what makes MetaSpace better than PermGen?
  • Is MetaSpace based on its own memory, so it saves java objects on disks, not on a virtual machine?
  • Can MetaSpace run out of memory? If so, I will get an OutOfMemoryException .
  • By default, can MetaSpace increase with increasing memory?

Thank you in advance

+50
java garbage-collection java-8
Jun 06 '14 at 4:28
source share
3 answers

Is MetaSpace going to GC by default?

Yes, the GC will work in the metaspace, when it is full, it will also dynamically increase (given that it is allowed) the memory allocated for the metadata.

Even PermGen is going to GC by adding arguments like -XX: + CMSClassUnloadingEnabled, then what makes MetaSpace better than PermGen?

The improvement is due to the dynamic expansion of metaspace, which permgen could not do.

Is MetaSpace based on its own memory, so does it store Java objects on disks, not a virtual machine?

Based on the description of metaspace, it uses only its own memory (without swapping).

Based on a study by Pierre-Hugue Charbonneau ( link here ), it became clear that the introduction of the metaspace does not necessarily solve the OOM problem, at best it solves the problem, it tries to dynamically change the memory size of the metascope to accommodate the growing number of classes that are loaded with possible side effects the effect of uncontrolled growth (as long as it allows its own memory).

We can achieve the well-known OOM error by setting the MaxMetaspaceSize argument to the JVM and running the provided sample program.

Many thanks to Pierre Hugh Charbonneau.

+50
Jun 06 '14 at 6:12
source share

In reply:

  • By default, Metaspace memory is collected if it reaches MaxMetaspaceSize. Initially, this parameter is not limited. Limit is the memory in your machine. But memory is automatically freed when the class and class loader is no longer needed. You only need to configure this parameter if you suspect that ClassLoader has a memory leak.

  • MetaSpece uses on-board memory, and organizing in-memory with pointers makes GC faster than earlier PermGen memory.

  • No, this means that the JVM uses memory as a regular C program and does not use virtual memory space for java objects. It seems that memory is limited only by the machine. Make sure that the machineโ€™s memory can be replaced with a disk if necessary.

  • If you set the MaxMetaspaceSize parameter, you can get OutOfMemory and, if you do not set this parameter, you can get if the process allocates all the device memory (including swap space).

+9
Jun 06 '14 at 5:05
source share
  • By default, MetaSpace compiles GC?

    Garbage collection of dead classes and class loaders starts after using the class metadata reaches "MaxMetaspaceSize", which is equal to "unlimited" by default, so proper monitoring is required to limit the delay or frequency of such a GC.

  • Even the PermGen GC is compiled by adding args as -XX: + CMSClassUnloadingEnabled, what makes MetaSpace better than PermGen?

    The main goal is that the removal of the pergmen was such that users did not have to think about calibrating it correctly.

  • Is MetaSpace based on its own memory, so it saves java objects on disks, not on a virtual machine?

    The disk is not its own memory, but a storage device. Native memory, in this context is the realm, is the memory for the process left over from the Java heap.

  • Can MetaSpace run out of memory?

    Yes, it is limited by the amount of memory on your computer.

+6
Jun 06 '14 at 5:31
source share



All Articles