Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java 7 (JDK 7) garbage collection and documentation on G1

Java 7 has been out for a while now, but I cannot find any good resources on the configuration of the garbage collectors, specifically the new G1 collector.

My questions:

  1. Is G1 the default collector in Java 7 and if not how do I activate G1?
  2. What optional settings does g1 have in Java7?
  3. Were there any changes made to other collectors like cms or the parallel collector in Java 7?
  4. Where can I find good documentation on garbage collection in Java 7?
like image 792
Florakel Avatar asked Nov 13 '11 11:11

Florakel


People also ask

How does G1 garbage collection work?

G1 copies objects from one or more regions of the heap to a single region on the heap, and in the process both compacts and frees up memory. This evacuation is performed in parallel on multi-processors, to decrease pause times and increase throughput.

What is the default garbage collector in Java 7?

The default garbage collector depends upon the class of machine. If the machine is of Server class then the default garbage collector is Throughput Collector. If the machine is of Client class then the default garbage collector is Serial Collector.

How do you set up a G1 GC?

The basic strategy to tune your JVM for G1 GC is to set heap size and pause-time goal, then let the JVM dynamically modify the required settings to attempt to meet the pause-time goal. If the performance goals are not met, then consider other options based on GC monitoring and log analysis.


2 Answers

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:+UseParallelGC java 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:-UseLargePagesIndividualAllocation java 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.

like image 129
Carey Avatar answered Sep 23 '22 06:09

Carey


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.

like image 35
Florakel Avatar answered Sep 21 '22 06:09

Florakel