|
|
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 2 of 6
An hprof output file includes sections describing various characteristics of the profiled Java program. It starts with a header that describes its format, which the header claims is subject to change without notice.
The output file's Thread and Trace sections help you figure out what threads were active when your program ran and what they did. The Thread section provides a list of all threads started and terminated during the program's life. The Trace section includes a list of numbered stack traces for some threads. These stack trace numbers are cross-referenced in other file sections.
The Heap Dump and Sites sections help you analyze memory usage. Depending on the heap suboption you choose when you start the virtual machine (VM), you can get a dump of all live objects in the Java heap (heap=dump) and/or a sorted list of allocation sites that identifies the most heavily allocated objects (heap=sites).
The CPU Samples and CPU Time sections help you understand CPU utilization; the section you get depends on your cpu suboption (cpu=samples or cpu=time). CPU Samples provides a statistical execution profile. CPU Time includes measurements of how many times a given method was
called and how long each method took to execute.
The Monitor Time and Monitor Dump sections help you understand how synchronization affects your program's performance. Monitor Time shows how much time your threads experience contention for locked resources. Monitor Dump is a snapshot of monitors currently in use. As you'll see, Monitor Dump is useful for finding deadlocks.
In Java, I define a memory leak as a (usually) unintentional failure to dereference discarded objects so that the garbage
collector cannot reclaim the memory they use. The MemoryLeak program in Listing 1 is simple:
Listing 1. MemoryLeak program
01 import java.util.Vector;
02
03 public class MemoryLeak {
04
05 public static void main(String[] args) {
06
07 int MAX_CONSUMERS = 10000;
08 int SLEEP_BETWEEN_ALLOCS = 5;
09
10 ConsumerContainer objectHolder = new ConsumerContainer();
11
12 while(objectHolder.size() < MAX_CONSUMERS) {
13 System.out.println("Allocating object " +
14 Integer.toString(objectHolder.size())
15 );
16 objectHolder.add(new MemoryConsumer());
17 try {
18 Thread.currentThread().sleep(SLEEP_BETWEEN_ALLOCS);
19 } catch (InterruptedException ie) {
20 // Do nothing.
21 }
22 } // while.
23 } // main.
24
25 } // End of MemoryLeak.
26
27 /** Named container class to hold object references. */
28 class ConsumerContainer extends Vector {}
29
30 /** Class that consumes a fixed amount of memory. */
31 class MemoryConsumer {
32 public static final int MEMORY_BLOCK = 1024;
33 public byte[] memoryHoldingArray;
34
35 MemoryConsumer() {
36 memoryHoldingArray = new byte[MEMORY_BLOCK];
37 }
38 } // End MemoryConsumer.
When the program runs, it creates a ConsumerContainer object, then starts creating and adding MemoryConsumer objects at least 1 KB in size to that ConsumerContainer object. Keeping the objects accessible makes them unavailable for garbage collection, simulating a memory leak.