java.lang.OutOfMemoryError: Metaspace error after migrating to Java 8 from Java 7

17,954

Solution 1

You should probably remove -XX:MaxMetaspaceSize=512m altogether.

My guess is, that in Java 7 you've needed to increase the permanent generation to get things to run at all, because the default max was too low.

In Java 8, the metaspace that holds your classes can expand without limit by default, so you probably don't run into the issue you have tried to solve for Java 7 in the first place. Instead, as you have experienced, you run into another issue: Setting too low a metaspace limit. Removing said limit will probably solve the issue and allow the JVM to make suitable decisions for you.

See also this answer.

Solution 2

One thing that comes to my mind is that java8 uses lambdas and every lambda is some sort of class in java 8. Correct me if im wrong but thats what my inspection sees when creating class chart of a java8 app. Thus java8 uses more class memory.

Share:
17,954
Valsaraj Viswanathan
Author by

Valsaraj Viswanathan

Simple & humble

Updated on June 19, 2022

Comments

  • Valsaraj Viswanathan
    Valsaraj Viswanathan almost 2 years

    We got OutOfMemoryError when upgraded. The JVM settings are kept same as Java 7 which was working fine.

    Here is the settings in Jboss 4.2 server:

    -server -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Xms4096m -Xmx7168m -XX:MaxMetaspaceSize=512m -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -Djava.security.egd=file:///dev/urandom

    Only difference in Java 7 is XX:MaxMetaspaceSize=512m was replace with PermGen max.

    I wonder why it needs more Metaspace for class loading since the server & application is same & only change in Java version.