Profile Image
vishnupriya

What is JVM startup parameter: -XX:+PrintGCDetails?

What is JVM startup parameter: -XX:+PrintGCDetails? Have you used this JVM arguement before? What are the pros & cons of using this Java argument? Can you share your perspective/experience in using this JVM argument?

  • jvmargument

  • xx-printgcdetails

  • x-printgcdetails

  • JVM startup parameter

Please Sign In or to post your comment or answer

Profile Image

Pavel Khodakovsky

Usage:                                                    

 

The option “-XX:+PrintGCDetails” turns on basic Garbage Collector detailed logging.

 

Since:

 

Starting from JDK 6.

 

Deprecated:

 

Deprecated, use “-Xlog:gc” instead.

 

Syntax:

 

java -XX:+PrintGCDetails MainClass

 

Examples:

 

To turn on the detailed logs for Garbage Collector: java -XX:+PrintGCDetails MainClass

 

Description:

 

Before talking about the flag, we need to introduce Garbage Collector (GC), Young and Old Generations:

 

Garbage Collector is a way of the JVM to clean the memory and makes the java memory more efficient. It tracks (Mark step) and removes (sweep step) every unused object available in the JVM heap space. An object is considered unused when it’s referenced by null, assigned to another reference or by anonymous object …. There are 5 type of GC implementations:

  • Serial Garbage Collector
  • Parallel Garbage Collector
  • CMS Garbage Collector
  • G1 Garbage Collector
  • Z Garbage Collector

Young Generation is a place where all new objects start out and aged. It’s divided into two spaces:

  • Eden Space: New object initiated with the keyword “new” are allocated in this memory space.
  • Survivor Space: When the Eden space is filled. A minor garbage collection event occurs. Objects that are referenced are marked and some are not. The ones which are marked will move to Survivor Space S0 and the one unmarked are removed by GC. When The space S0 filled, the cycle repeat itself but instead of moving them to S0, they will be moved to Survivor Space S1.

Old Generation is a place where objects that lived for a long time lie. If an object reaches an age threshold after surviving multiple GC events in the Young Generation, the object gets moved to the Old Generation.

This flag comes in handy when you want to diagnose any memory problems. It is similar to the option “-XX:+PrintGC” except it turns on detailed logging for the Garbage Collector (GC). Note that the output from “-XX:+PrintGCDetails” changes depending on the Garbage Collector (GC) algorithm in use.

 

An example of output when using java -X:+PrintGCDetails MainClass

 

2022-08-25T20:44:24.968+0200: 57.453: [Full GC [PSYoungGen: 204458K->34458K(435084K)] [PSOldGen: 699071K->653132K(836351K)] 898675K->675865K(932096K) [PSPermGen: 4254K->4254K(35218K)], 1.1534253 secs] [Times: user=1.15 sys=0.01, real=2.01 secs]

 

Heap

 

 PSYoungGen total 435084K, used 204458K [0x00000000ebac1000, 0x0000100000000000, 0x0000100000000000)

 

 eden space 204458K, 100% used [0x0000000f400001c0,0x0000000ea0000000,0x0000000ea0000000)

 

 from space 204458K, 0% used [0x0000000ea0000000,0x0000000ea0000000,0x00000000f8e40000)

 

 to space 204458K, 0% used [0x00000000f8e40000,0x00000000c0024050,0x0000000100000000)

 

 PSOldGen total 836351K, used 699071K [0x00000000a0000000, 0x0000000f400001c0, 0x0000000f400001c0)

 

 object space 836351K, 83% used [0x00000000a0000000,0x00000000ec00a000,0x0000000f400001c0)

 

 PSPermGen total 35218K, used 8358K [0x00000000cf200000, 0x00000000dfa10000, 0x00000000a0000000)

 

 object space 35218K, 16% used [0x00000000cf200000,0x00000000cc000306,0x00000000dfa10000)

 

Let’s examine the first line:

 

2022-08-25T20:44:24.968+0200 – Timestamp with time zone, represents the time when the GC ran

 

Full GC – Or sometimes ‘GC’, the type of GC that was running

 

[PSYoungGen: 204458K->34458K(435084K)] – After GC cleaning the memory, the Young Generation space reduced from 204458K to 34458K and total memory of Young Generation is 435084K.

 

[PSOldGen: 699071K->653132K(836351K)] After GC cleaning the memory, the Old Generation space reduced from 699071K to 653132K and total memory of Old Generation is 836351K.

 

898675K->675865K(932096K) – After GC cleaning the total memory reduced from 898675K to 675865K with total memory 932096K.

 

[PSPermGen: 4254K->4254K(35218K)] After GC cleaning the memory, there was no change in the permanent memory.

 

1.1534253 secs – the time that GC took to ran

 

[Times: user=1.15 sys=0.01, real=2.01 secs] – The amount of time the CPU spent in user mode, Sys the amount of time the CPU spent in kernel mode & real is the time from the start until the finish of the call.

 

Default Value:

 

This option is disabled by default.

 

Errors:

 

None.

 

Arguments related:

 

PrintGC.

 

Related Posts:

Got something else on mind? Post Your Question

Not the answer you're looking for? Browse other questions tagged
  • jvmargument

  • xx-printgcdetails

  • x-printgcdetails

  • JVM startup parameter