Class SimValue
- java.lang.Object
-
- com.tonic.analysis.simulation.state.SimValue
-
public class SimValue extends Object
Immutable simulated value carrying its type, defining instruction and, for references, a points-to set and null state; usable as a map key.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSimValue.NullStateWhat is known about a reference value's nullness.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SimValueconstant(Object value, IRType type, IRInstruction source)Creates a value with a known constant.booleanequals(Object o)static SimValuefromSSA(Value value, IRInstruction source)Wraps an SSA value, adopting its type when it is present.ObjectgetConstantValue()intgetId()SimValue.NullStategetNullState()Set<AllocationSite>getPointsTo()IRInstructiongetSourceInstruction()ValuegetSSAValue()IRTypegetType()inthashCode()booleanhasPointsTo()booleanisConstant()booleanisDefinitelyNotNull()booleanisDefinitelyNull()booleanisReference()booleanisUnknown()booleanisWide()booleanisWideSecondSlot()booleanmayBeNull()SimValuemerge(SimValue other)Merges another value into this one, unioning points-to sets and widening disagreeing null states to MAYBE_NULL.static SimValuemerge(Collection<SimValue> values)Folds a collection into one value, unioning points-to sets and widening disagreeing null states to MAYBE_NULL.static SimValueofAllocation(AllocationSite site, IRType type, IRInstruction source)Creates a definitely non-null reference pointing at one allocation site.static SimValueofNull(IRType type, IRInstruction source)Creates a definitely null reference with an empty points-to set.static SimValueofReference(IRType type, IRInstruction source, Set<AllocationSite> pointsTo, SimValue.NullState nullState)Creates a reference with a caller-supplied points-to set and null state.static SimValueofType(IRType type, IRInstruction source)Creates a value carrying only type information.StringtoString()static SimValueunknown(IRInstruction source)Creates an untyped value about which nothing is known.static SimValuewideSecondSlot()SimValuewithAdditionalPointsTo(AllocationSite site)Copies this value with one more allocation site in its points-to set.SimValuewithNullState(SimValue.NullState newNullState)Copies this value with a replaced null state.SimValuewithPointsTo(Set<AllocationSite> newPointsTo)Copies this value with a replaced points-to set.
-
-
-
Method Detail
-
fromSSA
public static SimValue fromSSA(Value value, IRInstruction source)
Wraps an SSA value, adopting its type when it is present.- Parameters:
value- SSA value being simulated, may be nullsource- instruction that produced the value- Returns:
- the new simulated value
-
constant
public static SimValue constant(Object value, IRType type, IRInstruction source)
Creates a value with a known constant.- Parameters:
value- the constanttype- type of the constantsource- instruction that produced the value- Returns:
- the new simulated value
-
ofType
public static SimValue ofType(IRType type, IRInstruction source)
Creates a value carrying only type information.- Parameters:
type- type of the valuesource- instruction that produced the value- Returns:
- the new simulated value
-
unknown
public static SimValue unknown(IRInstruction source)
Creates an untyped value about which nothing is known.- Parameters:
source- instruction that produced the value- Returns:
- the new simulated value
-
wideSecondSlot
public static SimValue wideSecondSlot()
- Returns:
- the placeholder occupying the second slot of a long or double
-
ofAllocation
public static SimValue ofAllocation(AllocationSite site, IRType type, IRInstruction source)
Creates a definitely non-null reference pointing at one allocation site.- Parameters:
site- site the reference points totype- type of the allocated objectsource- instruction that produced the value- Returns:
- the new simulated value
-
ofNull
public static SimValue ofNull(IRType type, IRInstruction source)
Creates a definitely null reference with an empty points-to set.- Parameters:
type- static type of the referencesource- instruction that produced the value- Returns:
- the new simulated value
-
ofReference
public static SimValue ofReference(IRType type, IRInstruction source, Set<AllocationSite> pointsTo, SimValue.NullState nullState)
Creates a reference with a caller-supplied points-to set and null state.- Parameters:
type- static type of the referencesource- instruction that produced the valuepointsTo- allocation sites the reference may point tonullState- what is known about its nullness- Returns:
- the new simulated value
-
merge
public static SimValue merge(Collection<SimValue> values)
Folds a collection into one value, unioning points-to sets and widening disagreeing null states to MAYBE_NULL.- Parameters:
values- values to merge- Returns:
- null if the collection is null or empty, the sole element if there is one, otherwise the merged value
-
getType
public IRType getType()
- Returns:
- the type, or null if untyped
-
getSourceInstruction
public IRInstruction getSourceInstruction()
- Returns:
- the instruction that produced this value
-
getSSAValue
public Value getSSAValue()
- Returns:
- the underlying SSA value, or null if there is none
-
getConstantValue
public Object getConstantValue()
- Returns:
- the constant, or null if the value is not constant
-
isConstant
public boolean isConstant()
- Returns:
- true if a constant is known and it is not the wide-slot placeholder
-
isWideSecondSlot
public boolean isWideSecondSlot()
- Returns:
- true if this is the second slot of a long or double
-
isWide
public boolean isWide()
- Returns:
- true if the type occupies two slots
-
isReference
public boolean isReference()
- Returns:
- true if the type is a reference type
-
isUnknown
public boolean isUnknown()
- Returns:
- true if there is no type, SSA value, constant, or wide-slot marker
-
getId
public int getId()
- Returns:
- the identity used by equals and hashCode
-
getPointsTo
public Set<AllocationSite> getPointsTo()
- Returns:
- an unmodifiable view of the allocation sites this reference may point to
-
hasPointsTo
public boolean hasPointsTo()
- Returns:
- true if the points-to set is non-empty
-
getNullState
public SimValue.NullState getNullState()
- Returns:
- what is known about this value's nullness
-
mayBeNull
public boolean mayBeNull()
- Returns:
- true unless the value is known to be non-null
-
isDefinitelyNull
public boolean isDefinitelyNull()
- Returns:
- true if the value is known to be null
-
isDefinitelyNotNull
public boolean isDefinitelyNotNull()
- Returns:
- true if the value is known to be non-null
-
withPointsTo
public SimValue withPointsTo(Set<AllocationSite> newPointsTo)
Copies this value with a replaced points-to set.- Parameters:
newPointsTo- allocation sites for the copy- Returns:
- the copy
-
withAdditionalPointsTo
public SimValue withAdditionalPointsTo(AllocationSite site)
Copies this value with one more allocation site in its points-to set.- Parameters:
site- site to add- Returns:
- the copy
-
withNullState
public SimValue withNullState(SimValue.NullState newNullState)
Copies this value with a replaced null state.- Parameters:
newNullState- null state for the copy- Returns:
- the copy
-
merge
public SimValue merge(SimValue other)
Merges another value into this one, unioning points-to sets and widening disagreeing null states to MAYBE_NULL.- Parameters:
other- value to merge, may be null- Returns:
- this value if the other is null or equal, otherwise the merged value
-
-