I’m still new to Java and so, I still am reading about the nitty-gritty, so when I ran into a situation with some code where we were running out of PermGen space I had to do some reading. In the JVM, PermGen holds the metadata about classes that have been loaded/created. This information is garbage collected like the other parts of the heap, however there are rough edges that can prevent this from happening, class loaders in particular (which I won’t discuss here.) Generally, the amount of PermGen space needed is small in relation to the rest of the heap and default JVM values should work for you.
So, what do you do? Simple answer, just increase PermGen space. Of course it is never that simple, so read on for more tips.
How do you increase PermGen space?
“Exception in thread “main” java.lang.OutOfMemoryError: PermGen space” signifies too many classes loaded or being generated; or the String.intern table is too big. Increase using the -XX:MaxPermSize option. “
How big should PermGen be?
“30. Should I increase the size of the permanent generation in the client vm?
In general increasing the size of a generation (and this applies not just to the permanent generation) can reduce the incidence of a wide variety of problems. However… There are two failure modes to consider. When raising MaxPermSize, it is possible that previously well behaved programs that used to garbage collect to recover the permanent generation space will die by endless paging. For the permanent generation this usually only happens with the heavy interning of temporary strings. The other failure mode is that address space must be reserved for the permanent generation and this will reduce that available for the rest of the heap (the maximum -Xmx may then be too large). This will cause programs configured to use all available space to fail at initialization.
If you increase PermGen size and still run out, you might be leaking classes somewhere.
How do you find out what’s classes are being stored in PermGen? Trace class loading/unloading.
- How do I know what classes are being loaded or unloaded? Use the command line options -XX:+TraceClassloading and -XX:+TraceClassUnloading http://java.sun.com/docs/hotspot/gc1.4.2/faq.html
What if you’re just getting out-of-memory exceptions and it seems you have plenty of memory? Are you using the throughput collector?
” The throughput collector will throw an out-of-memory exception if too much time is being spent doing garbage collection. For example, if the JVM is spending more than 98% of the total time doing garbage collection and is recovering less than 2% of the heap, it will throw an out-of-memory expection. The implementation of this feature has changed in 1.5. The policy is the same but there may be slight differences in behavior due to the new implementation.” ” In the J2SE Platform version 1.5 the throughput collector will be chosen as the garbage collector on server class machines.” http://java.sun.com/docs/hotspot/gc5.0/gc_tuning_5.html
This is probably in Java Performance Tuning (2nd Edition) , but there are so many of those books out there, good luck!