Java SE 8 Metaspace Occupancy Grows up to the Limit when Using JAXB
Last updated on MAY 01, 2018
Applies to:Java SE JDK and JRE - Version 8 and later
Information in this document applies to any platform.
After migrating from Java SE 7 to Java SE 8, an application that uses JAXB sees Metaspace usage growing constantly. This possibly results in one of the following:
- the Metaspace limit is reached (if the MaxMetaspaceSize option has been set to define an upper limit on the Metaspace size), or
- the system runs out of native memory
- When the usage reaches the Metaspace limit, the garbage collector will run full Garbage Collections constantly trying to free up some Metaspace.
This Java SE 8 behavior appears as a Metaspace memory leak. It is contrary to the behavior seen with the Java SE 7 Permanent Generation mechanism where PermGen occupancy stays at nearly the same level throughout the application lifecycle.
Investigation reveals that considerable Metaspace usage is coming from JAXB and certain JAXBContext usage patterns, where new JAXBContext is created back and forth.
The issue does not occur with the JAXB library provided with the JDK 8 distribution, but does occur when using the external JAXB 2.1.9 version.
To verify the JAXB version included with a particular JDK version, simply run '$JDK_HOME/bin/xjc -version' or, on Windows, '$JDK_HOME\bin\xjc.exe -version'.
Sample output from JDK 8u162:
C:\Program Files\Java\jdk1.8.0_162\bin>.\xjc.exe -version
Sign In with your My Oracle Support account
Don't have a My Oracle Support account? Click to get started
My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms