Class ConstructorAnalyzer


  • public final class ConstructorAnalyzer
    extends Object
    Analyzes constructor bytecode to extract field assignments.
    • Constructor Detail

      • ConstructorAnalyzer

        public ConstructorAnalyzer()
        Creates a stateless analyzer.
    • Method Detail

      • analyzeConstructor

        public SimObject analyzeConstructor​(AllocationSite site,
                                            IRMethod constructor,
                                            List<SimValue> constructorArgs)
        Builds the object for an allocation site with the fields the constructor assigns.
        Parameters:
        site - the allocation site the object belongs to
        constructor - the constructor to read, may be null
        constructorArgs - the argument values bound to locals 1 and up
        Returns:
        the populated object, or a bare object if the method is null or not a constructor
      • extractFieldAssignments

        public Map<FieldKey,​SimValue> extractFieldAssignments​(IRMethod constructor,
                                                                    List<SimValue> args)
        Walks every block in order, tracking local stores, and records the last value written to each instance field.
        Parameters:
        constructor - the constructor to read
        args - the argument values bound to locals 1 and up
        Returns:
        the assigned fields mapped to their values, in first-assignment order
      • getAssignedFields

        public Set<FieldKey> getAssignedFields​(IRMethod constructor)
        Lists the instance fields a constructor writes, ignoring the values written.
        Parameters:
        constructor - the constructor to read
        Returns:
        the assigned field keys
      • assignsField

        public boolean assignsField​(IRMethod constructor,
                                    FieldKey field)
        Tests whether a constructor writes a given instance field.
        Parameters:
        constructor - the constructor to read
        field - the field to look for
        Returns:
        whether the field is assigned
      • hasThisEscape

        public boolean hasThisEscape​(IRMethod constructor)
        Conservatively reports whether the object under construction may escape, treating any invocation or static field store as an escape.
        Parameters:
        constructor - the constructor to read
        Returns:
        whether an escape is possible