You are here : Home / Core Java Tutorials / Series of JVM and Garbage Collection (GC) in java - Best explanations ever
Contents of page >
- 1.1) Write java program in eclipse (Program in which we will pass -verbose:gc VM argument)>
- 1.2) Pass -verbose:gc VM argument through eclipse>
- 2) Understanding Garbage Collection (GC) in java using -verbose:gc VM argument -
- 3) How to get more detailed garbage collection information using -verbose:gc VM argument >
- 3.1) -XX:+PrintGCDetails >
- 3.2) -XX:+PrintGCTimeStamps >
1.1) Write java program in eclipse (Program in which we will pass -verbose:gc VM argument)>
import java.util.ArrayList;
import java.util.List;
public class VerboseTestingGarbageCollectionExample {
public static void main(String[] args) {
List<String> l = new ArrayList<String>();
for (int i = 0; i < 1000; i++) {
l = new ArrayList<String>();
l.add("a");
// System.out.println(l);
}
System.out.println("Done");
}
}
|
1.2) Pass -verbose:gc VM argument through eclipse>
Go to Run, Run configurations...,
-verbose:gc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -Xloggc:E:/GarabgeCollectionLogs.txt
All the garbage collection detail will be available in E:/GarabgeCollectionLogs.txt
For more details read : How to pass vmArgs(JVM parameters) to java program in eclipse
2) Understanding Garbage Collection (GC) in java using -verbose:gc VM argument -
- [GC 325407K->83000K(776768K), 0.2300771 secs]
- GC - GC indicates minor Garbage Collection (i.e. in young generation).
- 325407K - The combined size of live objects before gc(garbage collection).
- 83000K - The combined size of live objects after gc(garbage collection).
- (776768K) - the total available space, not counting the space in the permanent generation, which is the total heap minus one of the survivor spaces.
- 0.2300771 secs - time it took for gc(garbage collection) to occur.
- [Full GC 325407K->83000K(776768K), 0.2300771 secs]
- Full GC - Full GC Indicates major garbage collection (i.e. in tenured generation).
Also read :
3) How to get more detailed garbage collection information using -verbose:gc VM argument >
3.1) -XX:+PrintGCDetails > The -XX:+PrintGCDetails flag will print additional information.
Example of -XX:+PrintGCDetails >
[GC [DefNew: 64575K->959K(64576K), 0.0457646 secs] 196016K->133633K(261184K), 0.0459067 secs]]
indicates that the minor collection recovered about 98% of the young generation,
DefNew: 64575K->959K(64576K)
and took about 46 milliseconds.
0.0457646 secs
The usage of the entire heap was reduced to about 51%
196016K->133633K(261184K)
and that there was some slight additional overhead for the collection (over and above the collection of the young generation) as indicated by the final time:
0.0459067 secs
3.2) -XX:+PrintGCTimeStamps > The -XX:+PrintGCTimeStamps flag will additionally print timestamp.
Example of -XX:+PrintGCTimeStamps >
111.042: [GC 111.042: [DefNew: 8128K->8128K(8128K), 0.0000505 secs]111.042: [Tenured: 18154K->2311K(24576K), 0.1290354 secs] 26282K->2311K(32704K), 0.1293306 secs]
The collection starts about 111 seconds into the execution of the application. The minor collection starts at about the same time. Additionally the information is shown for a major collection delineated by Tenured . The tenured generation usage was reduced to about 10%
18154K->2311K(24576K)
and took about .13 seconds.
0.1290354 secs
Summary -
So in this core java tutorial we learned How to use -verbose:gc VM argument.
Having any doubt? or you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.
RELATED LINKS>
Most important and frequently used VM (JVM) PARAMETERS with examples in JVM Heap memory in java
Different type of garbage collectors in java>
>Serial collector / Serial GC (Garbage collector) in java
>Throughput GC (Garbage collector) or Parallel collector in java
>Concurrent Mark Sweep (CMS) collector / concurrent low pause garbage collector in java
>G1 garbage collector / Garbage first collector in java
JVM in detail - Garbage collection & heap structure >
>JVM Heap memory (Hotspot heap structure) with diagram in java
>What are Minor, Major and Full garbage collection in JVM in java
Important VM parameters >
>Most important and frequently used VM (JVM) PARAMETERS with examples in JVM Heap memory in java
>What are -XX:PermSize and -XX:MaxPermSize JVM parameters with examples in java | Differences
>Solve java.lang.OutOfMemoryError : unable to create new native Thread - Xss JVM option
More VM parameters >
>How to use -verbose:gc VM argument
>-Xverify option in java
Monitor, analyze garbage collection and fix MEMORY LEAK >
>How to monitor and analyze the garbage collection in 10 ways in java
>Detecting and fixing memory leak in java
Pass VM para through CMD, eclipse to java program and to Apache tomcat >
>How to write java program to pass VM/JVM parameters through CMD
>How to pass vmArgs(JVM parameters) to java program in eclipse
>How to pass VM argument to tomcat in eclipse
Few more garbage collection and JVM related tutorials>