title: Old JaxB and JDK8 Metaspace OutOfMemory Issue
body: <p>We are working on a business application (1 million+ LOC) developed since 10+ years. While switching to JDK8 we get an issue with the metaspace of JDK8. This seems to be related to the JaxB-Version referenced in com.sun.xml.ws:webservices-rt:1.4 (Metro 1.4). Because of the intense linking in the application and legacy creation of classes/instances via JaxB it isn't simple to switch on the fly the old libraries.</p>
  
  <p>Currently we are researching this issue. We created a sample programm that reproduces this behavior:</p>
  
  <pre><code>import java.io.ByteArrayInputStream;
  
  import javax.xml.bind.JAXBContext;
  import javax.xml.bind.JAXBException;
  import javax.xml.bind.Unmarshaller;
  import javax.xml.bind.annotation.XmlAttribute;
  import javax.xml.bind.annotation.XmlRootElement;
  
  @XmlRootElement
  public class X
  {
    private static final String XML = "&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;&lt;x test=\"test\" /&gt;";
  
    @XmlAttribute
    String test;
  
    public static void main( String[] args ) throws JAXBException, InterruptedException
    {
      System.out.println("start");
  
      while ( true )
      {
        JAXBContext jc = JAXBContext.newInstance( X.class );
        Unmarshaller unmarshaller = jc.createUnmarshaller();
        X object = (X) unmarshaller.unmarshal( new ByteArrayInputStream( XML.getBytes() ) );
        System.out.println( object.test );
      }
    }
  }
  </code></pre>
  
  <p>JDK7 keeps the PermGenSpace clean. (Simulated with 16M PermGen)
  <a href="http://i.stack.imgur.com/LDb1Y.png">Memory of run with JDK7</a></p>
  
  <p>Using JDK8 the application runs slowly to the OOM exception. The VisualVM catches the exception and keeps the process running on the maximum of available Metaspace. Even here it gets stucked after quite a while running on max. (Simulated with 16M Metaspace)
  <a href="http://i.stack.imgur.com/MTbC3.png">Memory of run with JDK8</a></p>
  
  <p>Has anyone some ideas how to get the garbage collectors legacy behavior, so we don't run into those out of memory issues? Or do you have any other ideas how to deal with this issue?</p>
  
  <p>Thanks.</p>
  
  <p>edit1:
  <strong>Run parameters JDK7:</strong></p>
  
  <p><code>-XX:+TraceClassLoading -XX:+TraceClassUnloading -XX:MaxPermSize=16M -XX:PermSize=1M -XX:+UseParallelOldGC -XX:+HeapDumpOnOutOfMemoryError</code></p>
  
  <p>=> No heap dumps are created</p>
  
  <p><strong>Run parameters JDK8:</strong></p>
  
  <p><code>-XX:+TraceClassLoading -XX:+TraceClassUnloading -XX:MaxMetaspaceSize=16M -XX:MetaspaceSize=1M -XX:+UseParallelOldGC -XX:+HeapDumpOnOutOfMemoryError</code></p>
  
  <p>=> heap dumps are generated while running.</p>
  
  <p>The Memory available of VisualVM does not show the real maximum metaspace value. If not limited the metaspace is constantly increasing untill memory is exceeded.</p>
  
  <p>edit 2:</p>
  
  <p>I have tried all available garbage collectors for JDK8. They all have the same issue. </p>
  
  <p>edit 3:</p>
  
  <p>Solving by exchanging the libs is difficult in our real application because of heavy coupling between JAXB &amp; several modules of our application. So a fix for the garbage collector behavior is needed for the short run. On the long run the propper fix is already planned.</p>