Class CFAbstractStore<V extends CFAbstractValue<V>,S extends CFAbstractStore<V,S>>
- All Implemented Interfaces:
Store<S>,org.plumelib.util.UniqueId
- Direct Known Subclasses:
AccumulationStore,CFStore,InitializationStore,KeyForStore,LockStore,NullnessNoInitStore
When adding a new field to track values for a code construct (similar to
localVariableValues and thisValue), it is important to review all constructors and
methods in this class for locations where the new field must be handled (such as the copy
constructor and clearValue), as well as all constructors/methods in subclasses of {code
CFAbstractStore}. Note that this includes not only overridden methods in the subclasses, but new
methods in the subclasses as well. Also check if
BaseTypeVisitor#getJavaExpressionContextFromNode(Node) needs to be updated. Failing to do so may
result in silent failures that are time consuming to debug.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.checkerframework.dataflow.analysis.Store
Store.FlowRule, Store.Kind -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final CFAbstractAnalysis<V, S, ?> The analysis class this store belongs to.protected final CopyOnWriteMap<ArrayAccess, V> Information collected about array elements, using the internal representationArrayAccess.protected final CopyOnWriteMap<ClassName, V> Information collected about classname.class values, using the internal representationClassName.protected CopyOnWriteMap<FieldAccess, V> Information collected about fields, using the internal representationFieldAccess.protected final CopyOnWriteMap<LocalVariable, V> Information collected about local variables (including method parameters).protected final CopyOnWriteMap<MethodCall, V> Information collected about the expressions to which method calls evaluate, using the internal representationMethodCall.protected final booleanShould the analysis use sequential Java semantics (i.e., assume that only one thread is running at all times)?protected VInformation collected about the current object. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCFAbstractStore(CFAbstractAnalysis<V, S, ?> analysis, boolean sequentialSemantics) Creates a new CFAbstractStore.protectedCFAbstractStore(CFAbstractStore<V, S> other) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionbooleanCan the objectsaandbbe aliases? Returns a conservative answer (i.e., returnstrueif not enough information is available to determine aliasing).static booleanReturns true ifexprcan be stored in this store.voidclearValue(JavaExpression expr) Remove any knowledge about the expressionexpr(correctly deciding where to remove the information depending on the type of the expressionexpr).protected voidcomputeNewValueAndInsert(JavaExpression expr, @Nullable V value, BinaryOperator<V> merger, boolean permitImpure) Inserts the result of applyingmergertovalueand the previous value forexpr.copy()Returns an exact copy of this store.booleanReturns true if this is equal to the given argument.getFieldValue(FieldAccess fieldAccess) Returns the current abstract value of a field access, ornullif no information is available.Returns information about fields.longgetUid()Returns the current abstract value of a field access, ornullif no information is available.Returns the current abstract value of a field access, ornullif no information is available.Returns the current abstract value of a local variable, ornullif no information is available.Returns the current abstract value of a method call, ornullif no information is available.Returns the current abstract value of the current object, ornullif no information is available.getValue(JavaExpression expr) Returns the current abstract value of a Java expression, ornullif no information is available.inthashCode()voidinitializeMethodParameter(LocalVariableNode p, @Nullable V value) Set the abstract value of a method parameter (only adds the information to the store, does not remove any other knowledge).voidinitializeThisValue(AnnotationMirror a, TypeMirror underlyingType) Set the value of the current object.final voidinsertOrRefine(JavaExpression expr, AnnotationMirror newAnno) Add the annotationnewAnnofor the expressionexpr(correctly deciding where to store the information depending on the type of the expressionexpr).protected voidinsertOrRefine(JavaExpression expr, AnnotationMirror newAnno, boolean permitImpure) Helper function forinsertOrRefine(JavaExpression, AnnotationMirror).voidinsertThisValue(AnnotationMirror a, TypeMirror underlyingType) final voidinsertValue(JavaExpression expr, @Nullable V value) Add the abstract valuevaluefor the expressionexpr(correctly deciding where to store the information depending on the type of the expressionexpr).protected voidinsertValue(JavaExpression expr, @Nullable V value, boolean permitImpure) voidinsertValue(JavaExpression expr, AnnotationMirror a) Add the annotationafor the expressionexpr(correctly deciding where to store the information depending on the type of the expressionexpr).final voidinsertValuePermitImpure(JavaExpression expr, @Nullable V value) LikeinsertValue(JavaExpression, CFAbstractValue), but updates the store even ifexpris impure.voidLikeinsertValue(JavaExpression, AnnotationMirror), but permits impure expressions to be stored.protected StringinternalVisualize(CFGVisualizer<V, S, ?> viz) Adds a representation of the internal information of this Store to visualizerviz.protected booleanisMonotonicUpdate(FieldAccess fieldAcc, V value) Returns true if fieldAcc is an update of a monotonic qualifier to its target qualifier.leastUpperBound(S other) Computes the least upper bound (LUB) of this store and another store.protected VnewFieldValueAfterMethodCall(FieldAccess fieldAccess, GenericAnnotatedTypeFactory<V, S, ?, ?> atypeFactory, V value) Returns the new value of a field after a method call, ornullif the field should be removed from the store.protected VnewMonotonicFieldValueAfterMethodCall(FieldAccess fieldAccess, GenericAnnotatedTypeFactory<V, S, ?, ?> atypeFactory, V value) Computes the value of a field whose declaration has a monotonic annotation, or returnsnullif the field has no monotonic annotation.protected voidremoveConflicting(ArrayAccess arrayAccess, @Nullable V val) Remove any information in the store that might not be true any more afterarrayAccesshas been assigned a new value (with the abstract valueval).protected voidremoveConflicting(FieldAccess fieldAccess, @Nullable V val) Remove any information in this store that might not be true any more afterfieldAccesshas been assigned a new value (with the abstract valueval).protected voidRemove any information in this store that might not be true any more afterlocalVarhas been assigned a new value.voidreplaceValue(JavaExpression expr, @Nullable V value) Completely replaces the abstract value for the expressionexpr(correctly deciding where to store the information depending on the type of the expressionexpr).voidreplaceValue(JavaExpression expr, AnnotationMirror a) Completely replaces the abstract value for the expressionexpr(correctly deciding where to store the information depending on the type of the expressionexpr).protected booleanshouldInsert(JavaExpression expr, @Nullable V value, boolean permitImpure) Returns true if the given (expression, value) pair can be inserted in the store, namely if the value is non-null and the expression does not contain unknown or an impure expression.protected booleansupersetOf(CFAbstractStore<V, S> other) Returns true iff thisCFAbstractStorecontains a superset of the map entries of the argumentCFAbstractStore.toString()protected voidupdateForArrayAssignment(ArrayAccess arrayAccess, @Nullable V val) Update the information in the store by considering an assignment with targetn, where the target is an array access.voidupdateForAssignment(Node n, @Nullable V val) Update the information in the store by considering an assignment with targetn.protected voidupdateForFieldAccessAssignment(FieldAccess fieldAccess, @Nullable V val) Update the information in the store by considering a field assignment with targetfieldAccess, where the right hand side has the abstract valueval.protected voidupdateForLocalVariableAssignment(LocalVariable receiver, @Nullable V val) Set the abstract value of a local variable in the store.voidupdateForMethodCall(MethodInvocationNode methodInvocationNode, GenericAnnotatedTypeFactory<V, S, ?, ?> atypeFactory, V val) Remove any information that might not be valid any more after a method call, and add information guaranteed by the method.visualize(CFGVisualizer<?, S, ?> viz) Delegate visualization responsibility to a visualizer.widenedUpperBound(S previous) Compute an upper bound of two stores that is wider than the least upper bound of the two stores.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.plumelib.util.UniqueId
getClassAndUid
-
Field Details
-
analysis
protected final CFAbstractAnalysis<V extends CFAbstractValue<V>,S extends CFAbstractStore<V, analysisS>, ?> The analysis class this store belongs to. -
localVariableValues
Information collected about local variables (including method parameters). -
thisValue
Information collected about the current object. -
fieldValues
Information collected about fields, using the internal representationFieldAccess. -
methodCallExpressions
Information collected about the expressions to which method calls evaluate, using the internal representationMethodCall. -
arrayValues
Information collected about array elements, using the internal representationArrayAccess. -
classValues
Information collected about classname.class values, using the internal representationClassName. -
sequentialSemantics
protected final boolean sequentialSemanticsShould the analysis use sequential Java semantics (i.e., assume that only one thread is running at all times)?
-
-
Constructor Details
-
CFAbstractStore
Creates a new CFAbstractStore.- Parameters:
analysis- the analysis class this store belongs tosequentialSemantics- should the analysis use sequential Java semantics?
-
CFAbstractStore
Copy constructor.- Parameters:
other- a CFAbstractStore to copy into this
-
-
Method Details
-
getFieldValues
Returns information about fields. Clients should not side-effect the returned value, which is aliased to internal state.- Returns:
- information about fields
-
getUid
public long getUid()- Specified by:
getUidin interfaceorg.plumelib.util.UniqueId
-
initializeMethodParameter
Set the abstract value of a method parameter (only adds the information to the store, does not remove any other knowledge). Any previous information is erased; this method should only be used to initialize the abstract value. -
initializeThisValue
Set the value of the current object. Any previous information is erased; this method should only be used to initialize the value. -
updateForMethodCall
public void updateForMethodCall(MethodInvocationNode methodInvocationNode, GenericAnnotatedTypeFactory<V, S, ?, ?> atypeFactory, V val) Remove any information that might not be valid any more after a method call, and add information guaranteed by the method.- If the method is side-effect-free (as indicated by
SideEffectFreeorPure), then no information needs to be removed. - Otherwise, all information about field accesses
a.fneeds to be removed, except if the methodncannot modifya.f. This unmodifiability property holds ifais a local variable orthis, andfis final, or ifa.fhas aMonotonicQualifierin the current store. Subclasses can change this behavior by overridingnewFieldValueAfterMethodCall(FieldAccess, GenericAnnotatedTypeFactory, CFAbstractValue). - Furthermore, if the field has a monotonic annotation, then its information can also be kept.
JavaExpression.isPure(org.checkerframework.javacutil.AnnotationProvider)), we store its resultvalin the store. Contracts may store a fact about a call that is not pure.- Parameters:
methodInvocationNode- method whose information is being updatedatypeFactory- the type factory of the associated checkerval- abstract value of the method call
- If the method is side-effect-free (as indicated by
-
newFieldValueAfterMethodCall
protected V newFieldValueAfterMethodCall(FieldAccess fieldAccess, GenericAnnotatedTypeFactory<V, S, ?, ?> atypeFactory, V value) Returns the new value of a field after a method call, ornullif the field should be removed from the store.In this default implementation, the field's value is preserved if it is either unassignable (see
FieldAccess.isAssignableByOtherCode()) or has a monotonic qualifier (seenewMonotonicFieldValueAfterMethodCall(FieldAccess, GenericAnnotatedTypeFactory, CFAbstractValue)). Otherwise, it is removed from the store.- Parameters:
fieldAccess- the field whose value to updateatypeFactory- AnnotatedTypeFactory of the associated checkervalue- the field's value before the method call- Returns:
- the field's value after the method call, or
nullif the field should be removed from the store
-
newMonotonicFieldValueAfterMethodCall
protected V newMonotonicFieldValueAfterMethodCall(FieldAccess fieldAccess, GenericAnnotatedTypeFactory<V, S, ?, ?> atypeFactory, V value) Computes the value of a field whose declaration has a monotonic annotation, or returnsnullif the field has no monotonic annotation.Used by
newFieldValueAfterMethodCall(FieldAccess, GenericAnnotatedTypeFactory, CFAbstractValue)to handle fields with monotonic annotations.- Parameters:
fieldAccess- the field whose value to computeatypeFactory- AnnotatedTypeFactory of the associated checkervalue- the field's value before the method call- Returns:
- the field's value after the method call, or
nullif the field has no monotonic annotation
-
insertValue
Add the annotationafor the expressionexpr(correctly deciding where to store the information depending on the type of the expressionexpr).This method does not take care of removing other information that might be influenced by changes to certain parts of the state.
If there is already a value
vpresent forexpr, then the stronger of the new and old value are taken (according to the lattice). Note that this happens per hierarchy, and if the store already contains information about a hierarchy other thanas hierarchy, that information is preserved.If
expris impure, this method does not insertvalueinto the store.- Parameters:
expr- an expressiona- an annotation for the expression
-
insertValuePermitImpure
LikeinsertValue(JavaExpression, AnnotationMirror), but permits impure expressions to be stored.For an explanation of when to permit impure expressions, see
insertValuePermitImpure(JavaExpression, CFAbstractValue).- Parameters:
expr- an expressiona- an annotation for the expression
-
insertOrRefine
Add the annotationnewAnnofor the expressionexpr(correctly deciding where to store the information depending on the type of the expressionexpr).This method does not take care of removing other information that might be influenced by changes to certain parts of the state.
If there is already a value
vpresent forexpr, then the greatest lower bound of the new and old value is inserted into the store.Note that this happens per hierarchy, and if the store already contains information about a hierarchy other than
newAnno's hierarchy, that information is preserved.If
expris impure, this method does not insertvalueinto the store.- Parameters:
expr- an expressionnewAnno- the expression's annotation
-
insertOrRefine
Helper function forinsertOrRefine(JavaExpression, AnnotationMirror).- Parameters:
expr- an expressionnewAnno- the expression's annotationpermitImpure- true if impure expressions may be inserted into the store
-
canInsertJavaExpression
Returns true ifexprcan be stored in this store. -
insertValue
Add the abstract valuevaluefor the expressionexpr(correctly deciding where to store the information depending on the type of the expressionexpr).This method does not take care of removing other information that might be influenced by changes to certain parts of the state.
If there is already a value
vpresent forexpr, then the stronger of the new and old value are taken (according to the lattice). Note that this happens per hierarchy, and if the store already contains information about a hierarchy for whichvaluedoes not contain information, then that information is preserved.If
expris impure, this method does not insertvalueinto the store.- Parameters:
expr- the expression to insert in the storevalue- the value of the expression
-
insertValuePermitImpure
LikeinsertValue(JavaExpression, CFAbstractValue), but updates the store even ifexpris impure.Usually, impure JavaExpressions (see
JavaExpression.isPure(org.checkerframework.javacutil.AnnotationProvider)) should not be stored in a Store. For example, in the body ofif (nondet() == 3) {...}, the store should not record that the value ofnondet()is 3, because it might not be 3 the next timenondet()is executed.However, contracts can mention an impure JavaExpression. For example, a contract might have a postcondition that
nondet()is odd. This means that the next call tonondet()will return odd. Such a postcondition is evicted from the store whennondet()is evaluated, and may be evicted when a side-effecting method is called.Use this method only for facts about the next evaluation of
expr, such as those of a contract, not for facts learned about a value that has already been computed. Only a call with a pure receiver and pure arguments is stored; a fact about an expression that contains an impure call, such asnondet().f, is not, because the store would not evict it.- Parameters:
expr- the expression to insert in the storevalue- the value of the expression
-
shouldInsert
@EnsuresNonNullIf(expression="#2", result=true) protected boolean shouldInsert(JavaExpression expr, @Nullable V value, boolean permitImpure) Returns true if the given (expression, value) pair can be inserted in the store, namely if the value is non-null and the expression does not contain unknown or an impure expression.This method returning true does not guarantee that the value will be inserted; the implementation of
insertValue(JavaExpression, CFAbstractValue, boolean)might still not insert it.- Parameters:
expr- the expression to insert in the storevalue- the value of the expressionpermitImpure- if false, returns false ifexpris impure; if true, permits impure expressions to be placed in the store- Returns:
- true if the given (expression, value) pair can be inserted in the store
-
insertValue
Helper method forinsertValue(JavaExpression, CFAbstractValue)andinsertValuePermitImpure(org.checkerframework.dataflow.expression.JavaExpression, javax.lang.model.element.AnnotationMirror).Every overriding implementation should start with
if (!shouldInsert) { return; }- Parameters:
expr- the expression to insert in the storevalue- the value of the expressionpermitImpure- if false, does nothing ifexpris impure; if true, permits impure expressions to be placed in the store
-
computeNewValueAndInsert
protected void computeNewValueAndInsert(JavaExpression expr, @Nullable V value, BinaryOperator<V> merger, boolean permitImpure) Inserts the result of applyingmergertovalueand the previous value forexpr.- Parameters:
expr- the JavaExpressionvalue- the value of the JavaExpressionmerger- the function used to mergevalueand the previous value ofexprpermitImpure- if false, does nothing ifexpris impure; if true, permits impure expressions to be placed in the store
-
isMonotonicUpdate
Returns true if fieldAcc is an update of a monotonic qualifier to its target qualifier. (e.g. @MonotonicNonNull to @NonNull). Always returns false ifsequentialSemanticsis true.- Returns:
- true if fieldAcc is an update of a monotonic qualifier to its target qualifier (e.g. @MonotonicNonNull to @NonNull)
-
insertThisValue
-
replaceValue
Completely replaces the abstract value for the expressionexpr(correctly deciding where to store the information depending on the type of the expressionexpr). Any previous information is discarded.This method does not take care of removing other information that might be influenced by changes to certain parts of the state.
- Parameters:
expr- the expression whose value to replacea- the new annotation
-
replaceValue
Completely replaces the abstract value for the expressionexpr(correctly deciding where to store the information depending on the type of the expressionexpr). Any previous information is discarded.This method does not take care of removing other information that might be influenced by changes to certain parts of the state.
- Parameters:
expr- the expression whose value to replacevalue- the new value
-
clearValue
Remove any knowledge about the expressionexpr(correctly deciding where to remove the information depending on the type of the expressionexpr). -
getValue
Returns the current abstract value of a Java expression, ornullif no information is available.- Returns:
- the current abstract value of a Java expression, or
nullif no information is available
-
getValue
Returns the current abstract value of a field access, ornullif no information is available.- Parameters:
n- the node whose abstract value to return- Returns:
- the current abstract value of a field access, or
nullif no information is available
-
getFieldValue
Returns the current abstract value of a field access, ornullif no information is available.- Parameters:
fieldAccess- the field access to look up in this store- Returns:
- current abstract value of a field access, or
nullif no information is available
-
getValue
Returns the current abstract value of a method call, ornullif no information is available.- Parameters:
n- a method call- Returns:
- the current abstract value of a method call, or
nullif no information is available
-
getValue
Returns the current abstract value of a field access, ornullif no information is available.- Parameters:
n- the node whose abstract value to return- Returns:
- the current abstract value of a field access, or
nullif no information is available
-
updateForAssignment
Update the information in the store by considering an assignment with targetn.- Parameters:
n- the left-hand side of an assignmentval- the right-hand value of an assignment
-
updateForFieldAccessAssignment
Update the information in the store by considering a field assignment with targetfieldAccess, where the right hand side has the abstract valueval.- Parameters:
fieldAccess- the target of the assignmentval- the abstract value of the value assigned tofieldAccess(ornullif the abstract value is not known)
-
updateForArrayAssignment
Update the information in the store by considering an assignment with targetn, where the target is an array access.See
removeConflicting(ArrayAccess,CFAbstractValue), as it is called first by this method. -
updateForLocalVariableAssignment
Set the abstract value of a local variable in the store. Overwrites any value that might have been available previously.- Parameters:
receiver- the local variable that is assignedval- the abstract value of the value assigned toreceiver(ornullif the abstract value is not known)
-
removeConflicting
Remove any information in this store that might not be true any more afterfieldAccesshas been assigned a new value (with the abstract valueval). This includes the following steps (assume thatfieldAccessis of the form a.f for some a.- Update the abstract value of other field accesses b.g where the
field is equal (that is, f=g), and the receiver b might
alias the receiver of
fieldAccess, a. This update will raise the abstract value for such field accesses to at leastval(or the old value, if that was less precise). However, this is only necessary if the field g is not final. - Remove any abstract values for field accesses b.g where
fieldAccessmight alias any expression in the receiver b. - Remove any information about method calls.
- Remove any abstract values an array access b[i] where
fieldAccessmight alias any expression in the receiver a or index i.
- Parameters:
fieldAccess- the field access that was modifiedval- the abstract value of the value assigned ton(ornullif the abstract value is not known)
- Update the abstract value of other field accesses b.g where the
field is equal (that is, f=g), and the receiver b might
alias the receiver of
-
removeConflicting
Remove any information in the store that might not be true any more afterarrayAccesshas been assigned a new value (with the abstract valueval). This includes the following steps (assume thatarrayAccessis of the form a[i] for some a.- Remove any abstract value for other array access b[j] where a and b can be aliases, or where either b or j contains a modifiable alias of a[i].
- Remove any abstract values for field accesses b.g where a[i] might alias any expression in the receiver b and there is an array expression somewhere in the receiver.
- Remove any information about method calls.
- Parameters:
arrayAccess- the array access that was modifiedval- the abstract value of the value assigned ton(ornullif the abstract value is not known)
-
removeConflicting
Remove any information in this store that might not be true any more afterlocalVarhas been assigned a new value. This includes the following steps:- Remove any abstract values for field accesses b.g where
localVarmight alias any expression in the receiver b. - Remove any abstract values for array accesses a[i] where
localVarmight alias the receiver a. - Remove any information about method calls where the receiver or any of the
parameters contains
localVar.
- Parameters:
var- the local variable that was modified
- Remove any abstract values for field accesses b.g where
-
canAlias
Can the objectsaandbbe aliases? Returns a conservative answer (i.e., returnstrueif not enough information is available to determine aliasing).- Specified by:
canAliasin interfaceStore<V extends CFAbstractValue<V>>
-
getValue
Returns the current abstract value of a local variable, ornullif no information is available.- Parameters:
n- the local variable- Returns:
- the current abstract value of a local variable, or
nullif no information is available
-
getValue
Returns the current abstract value of the current object, ornullif no information is available.- Parameters:
n- a reference to "this"- Returns:
- the current abstract value of the current object, or
nullif no information is available
-
copy
Description copied from interface:StoreReturns an exact copy of this store.- Specified by:
copyin interfaceStore<V extends CFAbstractValue<V>>- Returns:
- an exact copy of this store
-
leastUpperBound
Computes the least upper bound (LUB) of this store and another store. The LUB represents a program state that is true if either this store or the other store is true.- Specified by:
leastUpperBoundin interfaceStore<V extends CFAbstractValue<V>>- Parameters:
other- the store to merge with this one- Returns:
- a new store that represents the LUB of this store and the other
-
widenedUpperBound
Description copied from interface:StoreCompute an upper bound of two stores that is wider than the least upper bound of the two stores. Used to jump to a higher abstraction to allow faster termination of the fixed point computations inAnalysis.previousmust be the previous store.A particular analysis might not require widening and should implement this method by calling leastUpperBound.
Important: This method must fulfill the following contract:
- Does not change
this. - Does not change
previous. - Returns a fresh object which is not aliased yet.
- Returns an object of the same (dynamic) type as
this, even if the signature is more permissive. - Is commutative.
- Specified by:
widenedUpperBoundin interfaceStore<V extends CFAbstractValue<V>>- Parameters:
previous- must be the previous store
- Does not change
-
supersetOf
Returns true iff thisCFAbstractStorecontains a superset of the map entries of the argumentCFAbstractStore. Note that we test the entry keys and values by Java equality, not by any subtype relationship. This method is used primarily to simplify the equals predicate.- Parameters:
other- the other store- Returns:
- true iff this store contains a superset of the map entries in the other store
-
equals
Description copied from interface:StoreReturns true if this is equal to the given argument. -
hashCode
public int hashCode() -
toString
-
visualize
Description copied from interface:StoreDelegate visualization responsibility to a visualizer.- Specified by:
visualizein interfaceStore<V extends CFAbstractValue<V>>- Parameters:
viz- the visualizer to visualize this store- Returns:
- the String representation of this store
-
internalVisualize
Adds a representation of the internal information of this Store to visualizerviz.- Parameters:
viz- the visualizer- Returns:
- a representation of the internal information of this
Store
-