Adamansky Anton
Errare humanum est
malloc(...)
should be free(...)
new ...
should be del ...
Developer free from thinking too much... ☺
Maintain 3 objects sets.
Black nodes points only black or gray nodes.
If gray set is empty — all nodes in white set can be garbaged.
As result you do not have perform full memory scan.
Look at the gray set size and if needed free all objects from white set.
Two equal memory areas. Cheney's algorithm (1970).
Some empirical observations:
Most of resently created objects have a short lifetime
Integer c = 0; for (int i = 0; i < ...; ++i) { c = new Integer(i + c); //replace old c with new one ... if ((c % 100) == 0) break; } //We have a bunch of young short-lived `c` objects
All GC in JVM uses generational GC model.
Review in next slides the JVM memory model used for generational GC.
When Major or Full GC run all application threads are paused. It’s called as stop-the-world events. In Minor GCs also stop-the-world event occurs but momentarily.
How can we detect live Eden objects?
foo.bar = something;
-XX:+UseSerialGC
Not used in production.
-XX:+UseParallelGC
-XX:+UseParallelOldGC
Old is no the GC implementation age ☺
-XX:+UseConcMarkSweepGC
-XX:+UseG1GC
Used as default GC in Java 9
Measure the largest message delivering time ~ max GC pause
- For small heap size ~64M SerialGC is effective - STW time grows proportionally to the heap size.
-Xms
JVM optionAllow heap to be small
-XX:+PrintGC
... [GC 139776K->135432K(506816K), 0,9174710 secs] [GC 275208K->263794K(506816K), 1,0039820 secs] [Full GC 403570K->384989K(506816K), 2,0204030 secs] ...
[GC <allocatedMemoryBefore>-><allocatedMemoryAfter>(<heap size>), <time> secs] [Full GC <allocatedMemoryBefore>-><allocatedMemoryAfter>(<heap size>), <time> secs]
-XX:+PrintGC -XX:+PrintGCDetails
[GC [DefNew: 139776K->17472K(157248K), 0,8694740 secs] 139776K->135432K(506816K), 0,8696040 secs] [Times: user=0,76 sys=0,11, real=0,87 secs] [Full GC [Tenured: 349567K->253689K(349568K), 1,6324180 secs] 506815K->253689K(506816K), [Perm : 2769K->2769K(21248K)], 1,6325410 secs] [Times: user=1,64 sys=0,00, real=1,63 secs]
- Turning -XX+UseConcMarkSweepGC cause poor results :( - Let's go to under the hood with -XX:+PrintGC -XX:+PrintGCDetails ...
-Xmx
-XX:CMSInitiatingOccupancyFraction=68
-XX:+UseCMSInitiatingOccupancyOnly
-XX:SurvivorRatio=8
-XX:TargetSurvivorRatio=50
-XX:MaxTenuringThreshold=4
Examine TestGCPause.java