In this article, we will examine the following topics:
- What are incoming references or outgoing references of an object?
- Garbage Collection Roots (GC Roots)
- Path To GC Roots
- Immediate Dominators
Outgoing references for the 1st String instance |
Outgoing References
Using the following OQL statement, we have identified total 7 entries (see Figure above) as our objects of interest:
SELECT * FROM java.lang.String WHERE toString().startsWith("http://xmlns.oracle.com/apps/fnd/applcore/log/service/types")After expanding the first entry, it shows two outgoing references:
- a reference to the Class instance for the String object
- a reference to an array of char values
- Shallow Heap
- Is the memory consumed by that object alone
- Retained Heap
- Is the sum of shallow sizes of all objects in the retained set of that object
These sizes of String instances depends on the internal implementation of the JVM. Read [2,4] for more details.
To get incoming references of the first entry, choose List Objects with Incoming References from the context menu.
Now a tree structure is displayed, showing all instances with all incoming references (note the different icon highlighted in red). These references have kept the object alive and prevented it from being garbage collected.
Incoming References
To get incoming references of the first entry, choose List Objects with Incoming References from the context menu.
Now a tree structure is displayed, showing all instances with all incoming references (note the different icon highlighted in red). These references have kept the object alive and prevented it from being garbage collected.
Incoming references for String object are from QName object whose incoming references are, in turn, from HashMap.Entry object and class WebServiceOperation object. See [9] for more details. |
Immediate Dominators
Similarly, from the context menu, you can display immediate dominators of the first entry (see Figure below). An Object X is said to dominate an Object Y if every path from the GC Root to Y must pass through X. So, immediate dominators is a very effective way to find out who is keeping a set of objects alive. For example, the immediate dominators of our first String entry in the OQL query (note that we have used "java.*|com\.sun\..*" as our filter) is:
- oracle.j2ee.ws.server.deployment.WebServiceEndpoint
The immediate donimator of String instance is WebServieEndpoint instance |
Garbage Collection Roots (GC Roots)
GC roots are objects accessible from outside the heap. GC algorithms build a tree of live objects starting from these GC roots.
The below list shows some of the GC roots: [9,10]
- System Class
- Class loaded by bootstrap/system class loader.
- Thread Block
- Objects referred to from currently active thread blocks
- Basically all objects in active thread blocks when a GC is happening are GC roots
- Thread
- Active Threads
- Java Local
- All local variables (parameters, objects or methods in thread stacks)
- JNI Local
- Local variable or parameter of JNI method
- JNI Global
- Global JNI reference
- Monitor Used
- Objects used as a monitor for synchronization
Path To GC Roots
From context menu, you can also show "Path to GC Roots" of the first entry (see Figure below). Path to GC Roots shows the path to GC roots which should be found for a given object. As you can expect, its immediate dominators must also be on this path. Note that, when you display Path to GC Roots, you can specify which fields of certain classes to be ignored when finding paths. For example, we have specified that paths through Weak or Soft Reference referents to be excluded.
GC root of instance of class String is the HashMap.Entry |
Live Data Set
Now we know
- oracle.j2ee.ws.server.deployment.WebServiceEndpoint
References
- Eclipse MAT: Querying Heap Objects Using OQL (Xml and More)
- Java memory usage of simple data structure
- Shallow vs. Retained Heap
- Create and Understand Java Heapdumps (Act 4)
- Diagnosing Java.lang.OutOfMemoryError (Xml and More)
- I Bet You Have a Memory Leak in Your Application by Nikita Salnikov-Tarnovski
- Classloader leak is the most common leak in web applications
- How to analyze heap dumps
- Leak can be induced
- Per call (or a class of objects)
- Per object
- Diagnosing Heap Stress in HotSpot (Xml and More)
- Basic Concepts of Java Heap Dump Analysis with MAT (good)
- What are the GC roots?
No comments:
Post a Comment