Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 464
Valsaraj Viswanathan Avatar asked Aug 11 '17 09:08

Valsaraj Viswanathan


2 Answers

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.

like image 167
Hendrik Avatar answered Nov 09 '22 10:11

Hendrik


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.

like image 2
Vlad Skurtolov Avatar answered Nov 09 '22 10:11

Vlad Skurtolov