Class ConstructorAnalyzer
- java.lang.Object
-
- com.tonic.analysis.simulation.heap.ConstructorAnalyzer
-
public final class ConstructorAnalyzer extends Object
Analyzes constructor bytecode to extract field assignments.
-
-
Constructor Summary
Constructors Constructor Description ConstructorAnalyzer()Creates a stateless analyzer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SimObjectanalyzeConstructor(AllocationSite site, IRMethod constructor, List<SimValue> constructorArgs)Builds the object for an allocation site with the fields the constructor assigns.booleanassignsField(IRMethod constructor, FieldKey field)Tests whether a constructor writes a given instance field.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.Set<FieldKey>getAssignedFields(IRMethod constructor)Lists the instance fields a constructor writes, ignoring the values written.booleanhasThisEscape(IRMethod constructor)Conservatively reports whether the object under construction may escape, treating any invocation or static field store as an escape.
-
-
-
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 toconstructor- the constructor to read, may be nullconstructorArgs- 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 readargs- 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 readfield- 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
-
-