Java 7 (JDK 7) garbage collection and documentation on G1
The G1 garbage collector is not the default in my installation of Java, version 1.7.0_01. You can see for yourself by using with some extra command line options:
> java -XX:+PrintCommandLineFlags -XX:+PrintGCDetails -version-XX:InitialHeapSize=132304640 -XX:MaxHeapSize=2116874240 -XX:ParallelGCThreads=4 -XX:+PrintCommandLineFlags -XX:+PrintGCDetails -XX:+UseCompressedOops -XX:-UseLargePagesIndividualAllocation -XX:+UseParallelGCjava version "1.7.0_01"Java(TM) SE Runtime Environment (build 1.7.0_01-b08)Java HotSpot(TM) 64-Bit Server VM (build 21.1-b02, mixed mode)Heap PSYoungGen total 37696K, used 1293K [0x00000007d5eb0000, 0x00000007d88c0000, 0x0000000800000000) eden space 32320K, 4% used [0x00000007d5eb0000,0x00000007d5ff3408,0x00000007d7e40000) from space 5376K, 0% used [0x00000007d8380000,0x00000007d8380000,0x00000007d88c0000) to space 5376K, 0% used [0x00000007d7e40000,0x00000007d7e40000,0x00000007d8380000) PSOldGen total 86144K, used 0K [0x0000000781c00000, 0x0000000787020000, 0x00000007d5eb0000) object space 86144K, 0% used [0x0000000781c00000,0x0000000781c00000,0x0000000787020000) PSPermGen total 21248K, used 2032K [0x000000077ca00000, 0x000000077dec0000, 0x0000000781c00000) object space 21248K, 9% used [0x000000077ca00000,0x000000077cbfc288,0x000000077dec0000)
You don't need to enable experimental options to turn on the G1 collector any more, though:
> java -XX:+PrintCommandLineFlags -XX:+PrintGCDetails -XX:+UseG1GC -version-XX:InitialHeapSize=132304640 -XX:MaxHeapSize=2116874240 -XX:+PrintCommandLineFlags -XX:+PrintGCDetails -XX:+UseCompressedOops -XX:+UseG1GC -XX:-UseLargePagesIndividualAllocationjava version "1.7.0_01"Java(TM) SE Runtime Environment (build 1.7.0_01-b08)Java HotSpot(TM) 64-Bit Server VM (build 21.1-b02, mixed mode)Heap garbage-first heap total 130048K, used 0K [0x000000077ca00000, 0x0000000784900000, 0x00000007fae00000) region size 1024K, 1 young (1024K), 0 survivors (0K) compacting perm gen total 20480K, used 2032K [0x00000007fae00000, 0x00000007fc200000, 0x0000000800000000) the space 20480K, 9% used [0x00000007fae00000, 0x00000007faffc288, 0x00000007faffc400, 0x00000007fc200000)No shared spaces configured.
I don't know where you can find any good documentation.
Oracle finally made G1 official in Java 7 U4:http://www.oracle.com/technetwork/java/javase/7u4-relnotes-1575007.html
Description:http://docs.oracle.com/javase/7/docs/technotes/guides/vm/G1.html
Command line options:http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html#G1Options
Still, I do not think it is the default collector in Java 7. For servers the default is the Parallel Collector as in Java 6.
Yes, G1 is the new standard garbage collector in Java 1.7 JVM.
Here you can find plenty of information on how to use and configre the new garbage collector:
Using G1 G1 is still considered experimental and can be enabled with the following two parameters:
-XX:+UnlockExperimentalVMOptions -XX:+UseG1GC
To set a GC pause time goal, use the following parameter:
-XX:MaxGCPauseMillis =50 (for a pause time target of 50ms)
With G1, a time interval can be specified during which a GC pause should last no longer than the time given above:
-XX:GCPauseIntervalMillis =200 (for a pause interval target of 200ms)
Note that the above two options represent goals, not promises or guarantees. They might work well in some situations but not in others, and the GC might not always be able to obey them.
Alternatively, the size of the young generation can be specified explicitly to impact evacuation pause times:
-XX:+G1YoungGenSize=512m (for a 512 megabyte young generation)
G1 also uses the equivalent of survivor spaces, which are, naturally, a set of (potentially non-contiguous) regions. Their size can be specified with the usual parameters (e.g., -XX:SurvivorRatio=6).
Finally, to run G1 at its full potential, try setting these two parameters which are currently disabled by default because they may uncover a rare race condition:
-XX:+G1ParallelRSetUpdatingEnabled -XX:+G1ParallelRSetScanningEnabled
One more thing to note is that G1 is very verbose compared to other HotSpot GCs when -XX:+PrintGCDetails is set. This is because it prints per-GC-thread timings and other information very helpful in profiling and trouble-shooting. If you want a more concise GC log, please switch to using -verbosegc (though it is recommended that the more detailed GC log be obtained).
I have also found this article very helpful in understanding the inners of G1.
Even more info here.