share the common java memory problem cases solutions,including:
1. java.lang.OutOfMemoryError
2. full gc frequently
3. cms gc error: promotion failed or concurrent mode failure
2. Java Runtime Data Area
-Xss
Local Vars Native method Stack
Operator -XX:PermSize –
PC Method Area XX:MaxPermSize
Stack Frame
Method Stack Heap -Xms -Xmx
3. Oracle JDK Java Heap
-Xmn New Generation
Eden S0 S1 Old Generation
-XX:SurvivorRatio
13. java.lang.OutOfMemoryError: {$reason}
GC overhead limit exceeded
Java Heap Space
Unable to create new native thread
PermGen Space
Direct buffer memory
request {} bytes for {}. Out of swap space?
14. GC overhead limit exceeded
Java Heap Space
if code didn’t catch OutOfMemoryError,thread
will exit;
slow response or no response at all
▪ because gc did frequently
Out of Swap
Java process crash
15. GC overhead limit exceeded
Java Heap Space
monitor app log & gc log
heap dump or jmap –histo|-dump when oom
mat analyze heap dump
app developer or btrace to find where cause
16. Out of swap
crash log
google-perftools
then btrace to find where cause
ps: maybe u can try delete -XX:+DisableExplicitGC
if exist,reason can be found in this link。
17. use ThreadLocal carefully;
limit Collection/StringBuilder etc. size;
limit batch ops size;
limit the data size return by database;
avoid infinite loop;
21. According gc log to see if the reason is
consuming too much memory
if yes then add -XX:+HeapDumpBeforeFullGC or
write a shell file to dump memory when full gc;
if no then use pstack & source code to see why full
gc executes;
25. four cases
promotion failed case III
▪ because CMSInitiatingOccupancyFraction too high...
concurrent mode failure case I
▪ because CMSInitiatingOccupancyFraction too high...
concurrent mode failure case II
▪ because old gen is too small
concurrent mode failure case III
▪ because permgen
26. CMS GC problem will cause serial full gc,so
the app response time will be very slow...
27. According gc log to see if the reason is
because CMSInitiatingOccupancyFraction is
too high,if yes then adjust the option;
if no,then
promotion failed
▪ if because memory ran out,then dump memory;
▪ if because cms gc fragmention,currently we only can do
is execute jmap –histo:live at regular time;
concurrent mode failure
▪ the same as promotion failed...