Java Reference
In-Depth Information
Optimizing Garbage Collection
Now that you understand the basics of how to configure memory and garbage collection for Java
programs, we can talk about how to gather the information you need in order to make intelligent
decisions about the various switches and settings. Again, the JVM offers a number of switches you can
set to create output related to memory usage and garbage collection. The following table describes these
switches.
Table 13-3. Garbage Collection Output Switches
Switch
Effect
-verbose:gc
Enables the logging of garbage collection information. The other garbage
collection logging switches require this one.
-XX:+PrintGCTimeStamps
Prints time stamps for the scavenges and full collections. The time is
measured as seconds since the program started.
-XX:+PrintGCDetails
Adds various details to the log, including at least the following
information:
1.
Size of the young and old generation before and
after scavenges and full collections
2.
Size of the heap (that is, all the memory in use)
3.
Time taken by a scavenge or full collection to
happen in the young and tenured generations
4.
Total size of all objects promoted from one
generation to the next by the garbage collector
Here's a bit of sample output from running the TargetClick game from the command line with the -
verbose:gc, -XX:+PrintGCTimeStamps -XX:+PrintGCDetails switches:
Listing 13-3. Garbage Collection Output Sample
C:\temp>java -verbose:gc -XX:+PrintGCTimeStamps -XX:+PrintGCDetails TargetClick
Heap
PSYoungGen total 17920K, used 8077K [0x00000000ec000000,
0x00000000ed3f0000, 0x0000000100000000)
eden space 15424K, 52% used [0x00000000ec000000,0x00000000ec7e3538,0x00000000ecf10000)
from space 2496K, 0% used [0x00000000ed180000,0x00000000ed180000,0x00000000ed3f0000)
to space 2496K, 0% used [0x00000000ecf10000,0x00000000ecf10000,0x00000000ed180000)
PSOldGen total 40960K, used 0K [0x00000000c4000000,
0x00000000c6800000,0x00000000ec000000)
object space 40960K, 0% used [0x00000000c4000000,0x00000000c4000000,0x00000000c6800000)
PSPermGen total 21248K, used 9423K [0x00000000bee00000, 0x00000000c02c0000,
0x00000000c4000000)
object space 21248K, 44% used [0x00000000bee00000,0x00000000bf733cc0,0x00000000c02c0000)
Search WWH ::




Custom Search