Class 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.
    • Constructor Detail

      • ReferenceTreeModel

        private ReferenceTreeModel()
    • 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 from
        root - the original root node, needed for candidate evaluation
        distanceFromRoot - the distance from the root node to the current object node
        leakCandidate - 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)
        These factors together represent a simple number that is used to gather the most promising leak candidates in the tree.
        Parameters:
        object - the object to evaluate as a candidate
        root - the root object
        distanceFromRoot - how many steps from the root the object is
        leakCandidate - 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 retrieve
        referenceTreeObject - 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