Class ReferenceTreeModel
- java.lang.Object
-
- org.openjdk.jmc.flightrecorder.memleak.ReferenceTreeModel
-
public class ReferenceTreeModel extends java.lang.Object
The ReferenceTreeModel is used to build a representation of Old Object Sample JFR events which consists of one tree per GC root. Each object in the model is a ReferenceTreeObject instance, which is a subclass of IMCOldObject. The objects referred to as "Leak Objects" here are specifically those that were sampled by the JFR implementation and exist as the top-level Old Objects in the Old Object Sample event.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<ReferenceTreeObject>
leakObjects
private java.util.Map<IQuantity,ReferenceTreeObject>
map
private java.util.List<ReferenceTreeObject>
rootObjects
private java.util.Map<IItem,ReferenceTreeObject>
rootObjectsByLeakItems
-
Constructor Summary
Constructors Modifier Constructor Description private
ReferenceTreeModel()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
add(IItem item, IMemberAccessor<IMCOldObject,IItem> objectAccessor, IMemberAccessor<IQuantity,IItem> allocationTimeAccessor, IMemberAccessor<IMCOldObjectGcRoot,IItem> gcRootAccessor, IType<IItem> type)
Adds anIItem
to the tree model as aReferenceTreeObject
static ReferenceTreeModel
buildReferenceTree(IItemCollection items)
Creates and returns a ReferenceTreeModel object that represents the total reference tree created by Old Object Samples and their aggregated reference chains.java.util.List<ReferenceTreeObject>
getLeakCandidates(double relevanceThreshold)
Performs a leak relevance calculation on every object in the reference tree and sets this value to the respective objects.private ReferenceTreeObject
getLeakCandidates(ReferenceTreeObject object, ReferenceTreeObject root, int distanceFromRoot, ReferenceTreeObject leakCandidate)
A helper method to traverse the tree with a recursive depth-first search.int
getLeakCountInRange(IRange<IQuantity> timerange, ReferenceTreeObject referenceTreeObject)
A helper method to calculate number of Referenced Object within specified period.java.util.List<ReferenceTreeObject>
getLeakObjects()
java.util.Collection<ReferenceTreeObject>
getLeakObjects(IRange<IQuantity> timerange)
ReferenceTreeObject
getObject(IQuantity address)
java.util.Map<IMCType,java.util.List<ReferenceTreeObject>>
getObjectsByType()
java.util.List<ReferenceTreeObject>
getRootObjects()
java.util.Collection<ReferenceTreeObject>
getRootObjects(IRange<IQuantity> timerange)
private ReferenceTreeObject
setLeakRelevance(ReferenceTreeObject object, ReferenceTreeObject root, int distanceFromRoot, ReferenceTreeObject leakCandidate)
Evaluates a ReferenceTreeObject as a candidate for a memory leak.
-
-
-
Field Detail
-
map
private final java.util.Map<IQuantity,ReferenceTreeObject> map
-
rootObjects
private final java.util.List<ReferenceTreeObject> rootObjects
-
leakObjects
private final java.util.List<ReferenceTreeObject> leakObjects
-
rootObjectsByLeakItems
private final java.util.Map<IItem,ReferenceTreeObject> rootObjectsByLeakItems
-
-
Method Detail
-
buildReferenceTree
public static ReferenceTreeModel buildReferenceTree(IItemCollection items)
Creates and returns a ReferenceTreeModel object that represents the total reference tree created by Old Object Samples and their aggregated reference chains.- Parameters:
items
- should be a filtered item collection containing only the Old Object Sample events- Returns:
- a ReferenceTreeModel object to use when querying the reference tree
-
getRootObjects
public java.util.List<ReferenceTreeObject> getRootObjects()
- Returns:
- a list of all objects that are Roots in the reference tree
-
getLeakCandidates
public java.util.List<ReferenceTreeObject> getLeakCandidates(double relevanceThreshold)
Performs a leak relevance calculation on every object in the reference tree and sets this value to the respective objects.- Parameters:
relevanceThreshold
- the threshold used to determine which objects to return as interesting memory leak candidates- Returns:
- a list of ReferenceTreeObject instances that have been deemed to be memory leak candidates
-
getLeakCandidates
private ReferenceTreeObject getLeakCandidates(ReferenceTreeObject object, ReferenceTreeObject root, int distanceFromRoot, ReferenceTreeObject leakCandidate)
A helper method to traverse the tree with a recursive depth-first search.Every touched node gets a calculated distance to the root node to assist with calculating how likely that particular node is to be a leak candidate.
- Parameters:
object
- the node to begin/continue the search fromroot
- the original root node, needed for candidate evaluationdistanceFromRoot
- the distance from the root node to the current object nodeleakCandidate
- the most promising leak candidate found so far- Returns:
- the most promising leak candidate
-
setLeakRelevance
private ReferenceTreeObject setLeakRelevance(ReferenceTreeObject object, ReferenceTreeObject root, int distanceFromRoot, ReferenceTreeObject leakCandidate)
Evaluates a ReferenceTreeObject as a candidate for a memory leak.The calculation of each objects relevance as a candidate is a factor of the following:
- distance from the root object (higher distance means that it is more likely to be a candidate)
- the ratio of how many other objects this particular object keeps alive to how many objects its root object keeps alive (a high ratio here together with the distance is a good indicator that this could be a leak)
- the ratio of how many objects this object keeps alive to how many objects are alive globally (this is a good indicator of the severity of this particular leak)
- Parameters:
object
- the object to evaluate as a candidateroot
- the root objectdistanceFromRoot
- how many steps from the root the object isleakCandidate
- the prior best leak candidate- Returns:
- either leakCandidate or object, depending on whether or not the relevance is higher for object
-
getObjectsByType
public java.util.Map<IMCType,java.util.List<ReferenceTreeObject>> getObjectsByType()
- Returns:
- a map between classes and the corresponding reference tree objects
-
getRootObjects
public java.util.Collection<ReferenceTreeObject> getRootObjects(IRange<IQuantity> timerange)
- Parameters:
timerange
- a range of time that specifies which root objects to retrieve- Returns:
- a list of all objects that are Roots in the reference tree during the specified time range
-
getLeakObjects
public java.util.Collection<ReferenceTreeObject> getLeakObjects(IRange<IQuantity> timerange)
- Parameters:
timerange
- a range of time that specifies which root objects to retrieve- Returns:
- a list of all Roots which has a leaked object during the specified time range
-
getLeakCountInRange
public int getLeakCountInRange(IRange<IQuantity> timerange, ReferenceTreeObject referenceTreeObject)
A helper method to calculate number of Referenced Object within specified period.- Parameters:
timerange
- a range of time that specifies which root objects to retrievereferenceTreeObject
- leak candidate- Returns:
- number of leaked object during the specified timerange for a given leak candidate
-
getLeakObjects
public java.util.List<ReferenceTreeObject> getLeakObjects()
- Returns:
- a list of the actual objects sampled by the Old Object Sample event
-
getObject
public ReferenceTreeObject getObject(IQuantity address)
- Parameters:
address
- the address of a specific object to retrieve from the reference tree- Returns:
- the specified object
-
add
private void add(IItem item, IMemberAccessor<IMCOldObject,IItem> objectAccessor, IMemberAccessor<IQuantity,IItem> allocationTimeAccessor, IMemberAccessor<IMCOldObjectGcRoot,IItem> gcRootAccessor, IType<IItem> type)
Adds anIItem
to the tree model as aReferenceTreeObject
- Parameters:
item
- the item to addobjectAccessor
- an accessor forIMCOldObject
allocationTimeAccessor
- an accessor for the allocation timegcRootAccessor
- an accessor forIMCOldObjectGcRoot
type
- the type of the item
-
-