Class PointsToQuery


  • public final class PointsToQuery
    extends Object
    Read-only view over a simulated heap answering aliasing, nullness and reachability questions about points-to sets.
    • Constructor Detail

      • PointsToQuery

        public PointsToQuery​(SimHeap heap)
        Binds the query to a heap.
        Parameters:
        heap - the heap to read
        Throws:
        NullPointerException - if the heap is null
    • Method Detail

      • pointsTo

        public Set<AllocationSite> pointsTo​(SimValue ref)
        Parameters:
        ref - the reference, may be null
        Returns:
        the allocation sites it may denote, empty if null
      • mayPointTo

        public boolean mayPointTo​(SimValue ref,
                                  AllocationSite site)
        Tests whether a reference could point at a site.
        Parameters:
        ref - the reference, may be null
        site - the allocation site, may be null
        Returns:
        true if the site is in the points-to set
      • mustPointTo

        public boolean mustPointTo​(SimValue ref,
                                   AllocationSite site)
        Tests whether a reference points only at one site.
        Parameters:
        ref - the reference, may be null
        site - the allocation site, may be null
        Returns:
        true if the site is the sole target
      • mayAlias

        public boolean mayAlias​(SimValue ref1,
                                SimValue ref2)
        Tests whether two references could denote the same object; an empty points-to set is treated as unknown and aliases anything.
        Parameters:
        ref1 - the first reference, may be null
        ref2 - the second reference, may be null
        Returns:
        true if they may alias
      • mustAlias

        public boolean mustAlias​(SimValue ref1,
                                 SimValue ref2)
        Tests whether two references necessarily denote the same object - both known null, or both pinned to the same single allocation site.
        Parameters:
        ref1 - the first reference, may be null
        ref2 - the second reference, may be null
        Returns:
        true if they must alias
      • mayBeNull

        public boolean mayBeNull​(SimValue ref)
        Parameters:
        ref - the reference, may be null
        Returns:
        true if the value could be null; a null reference counts as unknown
      • isDefinitelyNull

        public boolean isDefinitelyNull​(SimValue ref)
        Parameters:
        ref - the reference, may be null
        Returns:
        true if the value is known null; false for a null reference
      • isDefinitelyNotNull

        public boolean isDefinitelyNotNull​(SimValue ref)
        Parameters:
        ref - the reference, may be null
        Returns:
        true if the value is known non-null; false for a null reference
      • reachableFrom

        public Set<SimValue> reachableFrom​(SimValue root)
        Walks fields and array elements from a root, following every allocation site each value may point to.
        Parameters:
        root - the starting reference, may be null
        Returns:
        the reachable values, including the root
      • reachableSitesFrom

        public Set<AllocationSite> reachableSitesFrom​(SimValue root)
        Collects the allocation sites of everything transitively reachable from a root.
        Parameters:
        root - the starting reference, may be null
        Returns:
        the reachable sites
      • getFieldValues

        public Set<SimValue> getFieldValues​(SimValue objectRef,
                                            FieldKey field)
        Collects a field's values across every object a reference may point to.
        Parameters:
        objectRef - the object reference
        field - the field to read
        Returns:
        the union of the field values
      • getArrayElements

        public Set<SimValue> getArrayElements​(SimValue arrayRef)
        Collects the elements of every array a reference may point to.
        Parameters:
        arrayRef - the array reference
        Returns:
        the union of the element values
      • getPointsToSetSize

        public int getPointsToSetSize​(SimValue ref)
        Parameters:
        ref - the reference, may be null
        Returns:
        the number of allocation sites it may point to, 0 if null
      • isSingleton

        public boolean isSingleton​(SimValue ref)
        Tests whether a reference resolves to exactly one allocation site.
        Parameters:
        ref - the reference, may be null
        Returns:
        true if the points-to set holds one site