When the Java application starts, you can output the GC status of the JVM by setting the verbose parameter, which is the following command:-VERBOSE:GC or-XX:+PRINTGC
In eclipse, you can use the run as| Run configurations| arguments| The VM arguments is set.
After using this command, the output is as follows:
1[GC 3375k->1317k (15872K), 0.0047372secs]2[GC 4973k->3427k (15872K), 0.0084376secs]3[GC 11340k->8175k (15872K), 0.0027110secs]4[Full GC 8175k->5127k (15872K), 0.0148359secs]5[GC 12249k->12249k (23060K), 0.0035303secs]6[Full GC 12249k->7501k (23060K), 0.0197696secs]7[GC 18184k->18184k (36944K), 0.0057985secs]8[Full GC 18184k->11062k (36944K), 0.0245650secs]9[GC 27086k->27086k (41744K), 0.0073461secs]Ten[Full GC 27086k->16403k (41744K), 0.0343230 secs]
the data 3375K and 1317K before and after the arrows, respectively, represent the memory capacity used by all surviving objects before and after garbage collection GC, indicating that objects with 3375k–1317k = 2258K size are recycled, the data in parentheses is 123584K to the total capacity of the heap memory. The actual collection required is 0.0120528 seconds . Note that the GC takes up CPU time slices, causing the program to pause briefly, and the console output GC information can also use the following command:
In the JVM's startup parameters, add:
(1)-XX:+PRINTGC, output GC Brief information
(2)-xx:+printgcdetails, output GC Details:
1[Gc[defnew:3375k->379k (4928K), 0.0041917 secs] 3375k->1317k (15872K), 0.0042904 secs] [times:user=0.00 sys=0.00, real=0.00secs]2[Gc[defnew:4035k->0k (4928K), 0.0088287 secs] 4973k->3427k (15872K), 0.0088957 secs] [times:user=0.00 sys=0.00, real=0.01secs]3[Gc[defnew:3165k->0k (4928K), 0.0026064 secs][tenured:8175k->5127k (10944K), 0.0146668 secs] 11340k->5127k ( 15872K), [perm:160k->160k (12288K)], 0.0173788 secs] [times:user=0.02 sys=0.00, real=0.02secs]4[Gc[defnew:0k->0k (4992K), 0.0040182 secs][tenured:12249k->7501k (18068K), 0.0179673 secs] 12249k->7501k ( 23060K), [perm:160k->160k (12288K)], 0.0221141 secs] [times:user=0.03 sys=0.00, real=0.02secs]5[Gc[defnew:0k->0k (8192K), 0.0050559 secs][tenured:18184k->11062k (28752K), 0.0257729 secs] 18184k->11062k ( 36944K), [perm:160k->160k (12288K)], 0.0309780 secs] [times:user=0.03 sys=0.00, real=0.03secs]6[Gc[defnew:0k->0k (12992K), 0.0076682 secs][tenured:27086k->16403k (28752K), 0.0363194 secs] 27086k->16403k ( 41744K), [perm:160k->160k (12288K)], 0.0440790 secs] [times:user=0.05 sys=0.00, real=0.04 secs]
(3)-xx:+printgctimestamps, the time information of the output GC is as follows:
(4) Time of application suspension caused by-XX:+PRINTGCAPPLICATIONSTOPPEDTIME,GC
1Total time forWhich application threads were stopped:0.0040944seconds2Total time forWhich application threads were stopped:0.0089377seconds3Total time forWhich application threads were stopped:0.0176941seconds4Total time forWhich application threads were stopped:0.0218115seconds5Total time forWhich application threads were stopped:0.0293873seconds6Total time forWhich application threads were stopped:0.0420044seconds7Total time forWhich application threads were stopped:0.0607124 seconds
JVM Learning Eclipse Output GC Log