mercredi 5 juillet 2017

Java 8 Metaspace: Dealing with reflection Inflation

There are lots of links and open Q&A s around web, still I'm missing a lot of information.

First things first

Issue:

java.lang.OutOfMemoryError: Metaspace

jvm:

java version:  "1.8.0_131"
vm:             Java HotSpot(TM) 64-Bit Server
vm args:       -Xms1024m -Xmx1024m -XX:MaxMetaspaceSize=128m

Frameworks:

spring, hibernate, wicket, jetty

Suspect 1:

Over the period of usage, the metaspace grows gradually and the following reflection classes are proportionally loaded into metaspace [observed by jmap -histo cron jobs]

sun.reflect.GeneratedConstructorAccessor1299
sun.reflect.GeneratedMethodAccessor6929
sun.reflect.GeneratedSerializationConstructorAccessor4220

Possible Solution:

a. As we are using libraries that are heavily dealing with reflection stuffs, we think 128m is quite not enough to hold all the generatedXX classes in metaspace. So we are planning to double the metaspace limit. -XX:MaxMetaspaceSize=256m

b. We are not thinking of setting the following

-D sun.reflect.noInflation = false

-D sun.reflect.inflationThreshold = 15

Suspect 2:

The Full GC is running continuously even before it reaches/occupies the full configured metaspace(128m) and the application becomes unresponsive/slow/sometime OOM.

[Full GC (Metadata GC Threshold) [PSYoungGen: 224K->0K(698368K)] [ParOldGen: 52910K->52933K(1398272K)] 53134K->52933K(2096640K), [Metaspace: 92733K->92733K(1163264K)], 0.1964143 secs] [Times: user=0.59 sys=0.00, real=0.19 secs]

.

Metaspace used 147414K, capacity 155731K, committed 159616K, reserved 1187840K class space used 17242K, capacity 19252K, committed 20352K, reserved 1048576K

Possible Solution:

-XX:CompressedClassSpaceSize is not explicitly mentioned at the vm startup which may possibly cause over reserving the address space which leads to misleading committed sapce and hence the Full GC. So explicitly setting -XX:CompressedClassSpaceSize=256m will help vm in correct memory planning & reserving.

Questions:

  1. Suspect 1: Did someone face similar issue and got any fix?
  2. Suspect 2: Is setting -XX:CompressedClassSpaceSize really makes a difference in metaspace planning/reserving and affects GC? Any pointers?




Aucun commentaire:

Enregistrer un commentaire