Profile Image

What is Memory allocation for class metadata: -XX:MaxMetaspaceSize?

What is Memory allocation for class metadata: -XX:MaxMetaspaceSize? What are the pros & cons of using this Java argument? Can you share your perspective/experience in using this JVM argument?

  • jvmargument

  • xx-maxmetaspacesize

  • x-maxmetaspacesize

Please Sign In or to post your comment or answer

Profile Image

Pavel Khodakovsky



You can set a limit on the amount of native memory used for class metadata:


-XX:MaxMetaspaceSize=size[unit], where size is the desired amount of memory for class metadata, and unit denotes the unit in which the is to be initialized. Units can be marked as ‘g' for GB, ‘m' for MB and ‘k' for KB.




To set the maximum memory size for class metadata to 1GB:






Java classes have an internal representation within Java Hotspot VM and are referred to as class metadata. Prior Java 8, the class metadata was allocated in the so-called permanent generation. Since JDK 8, the permanent generation was removed and the class metadata is allocated in native memory. The amount of native memory that can be used for class metadata is by default unlimited. Use the option -XX:MaxMetaspaceSize to put an upper limit on the amount of native memory used for class metadata. Java Hotspot VM explicitly manages the space used for metadata. Space is requested from the OS and then divided into chunks. A class loader allocates space for metadata from its chunks (a chunk is bound to a specific class loader). When classes are unloaded for a class loader, its chunks are recycled for reuse or returned to the OS.


Default Value:


Since JDK 8 unlimited – once it reaches the global limit, the JVM will automatically increase it’s size.






Arguments related:


TODO link UseG1GC, MinHeapFreeRatio, MaxHeapFreeRatio, Xmx, Xms, UseSerialGC, USeParNewGC, UseParallelGC, UseZGC


Related Posts:



If you have additional comments, interesting experiences or even point of disagreement with this JVM argument description, please leave a comment. Your insights will help the entire 10+ million java developer community to develop one standard source of documentation for all the JVM arguments.

Got something else on mind? Post Your Question

Not the answer you're looking for? Browse other questions tagged
  • jvmargument

  • xx-maxmetaspacesize

  • x-maxmetaspacesize