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.

Valsaraj Viswanathan
  • 1,473
  • 5
  • 28
  • 51
  • Do you have the stacktrace for the error? I would like to know the exact error for the OOM. – kucing_terbang Aug 11 '17 at 10:07
  • 1
    can you provide exact Java parameters when you start the JBoss with Java 8? – DevDio Aug 11 '17 at 10:15
  • Java params used are added in quersion: -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 – Valsaraj Viswanathan Aug 11 '17 at 10:38

2 Answers2

8

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.

Hendrik
  • 5,085
  • 24
  • 56
  • Removing MaxMetaspaceSize caused increase in Metaspace usage upto 3g. Since the server had 8g & max heap allocated in 7g, got another memory crash. Is dead classloaders in metaspace garbage collected? Os there any settings to control that? – Valsaraj Viswanathan Aug 23 '17 at 11:52
  • 1
    You could try setting `-XX:MaxMetaspaceExpansion=0` to force meta space garbage collections (see https://stackoverflow.com/a/31632341/942774), but if anyone still holds on to your class objects, it won't do much good. – Hendrik Aug 25 '17 at 07:37
  • The result is same even after setting -XX:MaxMetaspaceExpansion=0. total = 1394 27716 53490569 N/A alive=1, dead=1393 N/A. I see garbage collection run in frequent intervals on non-heap memory. I wonder why these much dead class loaders then? – Valsaraj Viswanathan Aug 29 '17 at 18:03
  • 1
    This sounds like you need to debug a class loading memory leak. Perhaps https://stackoverflow.com/a/37933050/942774 helps a little. At this point I would search the web for JBoss 4.2 class loading issues on Java 8. YMMV, as v4.2 is older than Java 8. Perhaps it's time to update JBoss. – Hendrik Aug 30 '17 at 06:40
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.

Vlad Skurtolov
  • 1,024
  • 1
  • 7
  • 20