Java Magazine, March/April 2016
ORACLE COM JAVAMAGAZINE MARCH APRIL 2016 21 inside java As you can imagine in the process of constructing and manipulating data structures the heap will start to look like Figure 3 Compacting the data means changing its address in memory The Java program expects to find an object at a particular address If the garbage collector moves the object the Java program needs to know the new location The easiest way to do this is to stop all the Java threads compact all the objects update all the references to the old addresses to now point to the new addresses and resume the Java program However this approach can lead to long periods called GC pause times when the Java threads arent running Java programmers arent happy when their applications arent running There are two popular strategies for decreasing GC pause times The GC literature refers to them as concurrent algorithms doing work while the program is running and parallel algorithms employing more threads to get the work done faster while the Java threads are stopped The current OpenJDK default garbage collector which can be manually specified on the command line with XX UseParallelGC adopts the parallel strategy It uses many GC threads to get impressive throughput Parallel Garbage Collector The parallel garbage collector segregates objects into two regions young and old according to how many GC cycles they have survived Young objects are initially allocated in the young region and the compaction step keeps them in that region until they 13 17 201 512 29 15 103 121 197 14 213 91 51 Figure 3 A heap with many unused data items in it 21 have survived a certain number of young collections If they live long enough they are promoted to the old generation The theory is that rather than pausing to collect the entire heap which would take too long you can collect just the part of the heap that is likely to contain short lived objects Eventually it will become necessary to collect the older objects as well In order to collect just the younger objects the garbage collector needs to know which objects in the old generation reference objects in the young generation The old objects need to be updated to reference the new locations for the new objects The JVM does this by maintaining a summarization data structure called the card table Whenever a reference is written into an old generation object the card table is marked so that during the next young GC cycle the JVM can scan this card looking for old to young references With these references known the parallel garbage collector is able to identify which objects to cull and which references to update It uses multiple GC threads to get the work done faster while it has paused the program Shenandoah compacts the data concurrently As a consequence Shenandoah doesnt need to limit the number of regions it collects in order to minimize application pause times
You must have JavaScript enabled to view digital editions.