Page Tools:
Wiki Relationships:
Admin Tools:
Free Java Profiling Tools
by Calvin Austin Finding a memory leak in a Java application can be one of the more difficult tasks a Java developer has to handle. The Java virtual machine effectively manages most of the memory an application uses so a 'memory leak' is really down to a reference that can't be recovered due to a variety of reasons. These leaks are often small and take a while to show up in your application.
To simply see what the JVM is doing with its memory management and see a leak in progress you can use one of the following options to the JVM
java -XX:+ PrintGCDetails java -verbose:gc jmap -heap or jmap -histo (JDK 5.0)
For example:
[#]$ jmap -histo 362 Attaching to process ID 362, please wait... ... Object Histogram: Size Count Class description 149232 167 char[] 34160 14 byte[] 8352 29 * ObjArrayKlassKlass 7600 203 java.lang.Object[] 3792 158 java.lang.String 3696 42 java.lang.Class 2360 23 * ConstMethodKlass
and also
jmap -heap Heap Configuration: MinHeapFreeRatio = 40 MaxHeapFreeRatio = 70 MaxHeapSize = 67108864 (64.0MB) NewSize = 655360 (0.625MB) MaxNewSize = 4294901760 (4095.9375MB) OldSize = 1441792 (1.375MB) NewRatio = 12 SurvivorRatio = 8 PermSize = 8388608 (8.0MB) MaxPermSize = 67108864 (64.0MB)
For a graphical representation of memory use there are 3 tools. HAT, jconsole and visualgc
HAT or heap analyis tools is available from java.net
First create a profiling output, this file is generated when the application ends or ctrl-c is pressed.
java -agentlib:hprof=heap=all,format=b
This then creates a java.hprof file. Supply this file as an option to hat
hat java.hprof
Then point your browser to localhost:7000. hat starts a mini http server for you to browser the profiling output
jconsole is available in the JDK 5.0 bin directory. You start your application with jmx management enabled
java -Dcom.sun.management.jmxremote
Then simply launch jconsole, it will ask you which jvm to attach to.
visualgc comes in a package called jvmstat from java.net
to run it you need to execute bin/visualgc and supply the process (or jvm identifier) and and interval or use the default of 500ms
Most Recent |
Most Popular |
Most Active Categories |
| Back To Top | Add New Article | Printable Page |

Testing
