abstract class PropertyStore extends AnyRef
A property store manages the execution of computations of properties related to specific concrete as well as artificial entities (e.g., methods, fields and classes of a program, but also the call graph as such etc.). These computations may require and provide information about other entities of the store and the property store implements the logic to handle the computations related to the dependencies between the entities. Furthermore, the property store may parallelize the computation of the properties as far as possible without requiring users to take care of it; users are also generally not required to think about the concurrency when implementing an analysis as long as only immutable data-structures are used. The concepts are also described in the SOAP paper: "Lattice Based Modularization of Static Analyses" (https://conf.researchr.org/event/issta-2018/soap-2018-papers-lattice-based-modularization-of-static-analyses)
Usage
The correct strategy, when using the PropertyStore, is to always continue computing the property of an entity and to collect the dependencies on those elements that are (still) relevant. I.e., if some information is not or just not completely available, the analysis should still continue using the provided information and (internally) record the dependency. Later on, when the analysis has computed its result, it reports the same and informs the framework about its dependencies. Based on the later the framework will call back the analysis when a dependency is updated. In general, an analysis should always try to minimize the number of dependencies to the minimum set to enable the property store to suspend computations that are no longer required.
Core Requirements on Property Computation Functions (Modular Static Analyses)
The following requirements ensure correctness and determinism of the result.
- At Most One Lazy Function per Property Kind A specific kind of property is (in each
phase) always computed by only one registered lazy
PropertyComputationfunction. No other analysis is (conceptually) allowed to derive a value for an E/PK pairing for which a lazy function is registered. It is also not allowed to schedule a computation eagerly if a lazy computation is also registered. - Thread-Safe PropertyComputation functions If a single instance of a property computation function (which is the standard case) is scheduled for computing the properties of multiple entities, that function has to be thread safe. I.e., the function may be executed concurrently for different entities. The OnUpdateContinuation functions are, however, executed sequentially w.r.t. one E/PK pair.
- Non-Overlapping Results PropertyComputation functions that are invoked on different entities have to compute result sets that are disjoint unless a PartialResult is used. For example, an analysis that performs a computation on class files and that derives properties of a specific kind related to a class file's methods must ensure that two concurrent calls of the same analysis - running concurrently on two different class files - does not derive information about the same method. If results for a specific entity are collaboratively computed, then a PartialResult has to be used.
- Monoton If a PropertyComputation
function calculates (refines) a (new) property for a specific element, then the result must be equal or more specific.
Closed-strongly Connected Component Dependencies
In general, it may happen that some analyses cannot make any progress, because
they are mutually dependent. In this case the computation of a property p of an entity e1
depends on the property p' of an entity e2 that requires the property p of the entity e1.
In this case a registered strategy is used to resolve the cyclic dependency. If no strategy is
available all current values will be committed, if no "current" value is available the fallback
value will be committed.
Thread Safety
The sequential property stores are not thread-safe; the parallelized implementation(s) are thread-safe in the following manner:
- a client has to use the SAME thread (the driver thread) to call the setupPhase,
registerLazyPropertyComputation, scheduleEagerComputationForEntity /
scheduleEagerComputationsForEntities, force and (finally)
PropertyStore#waitOnPhaseCompletion methods. Hence, the previously mentioned methods MUST
NO be called by PropertyComputation/OnUpdateComputation functions.
The methods to query the store (
apply) are thread-safe and can be called at any time.
Common Abbreviations
- e = Entity
- p = Property
- pk = Property Key
- pc = Property Computation
- lpc = Lazy Property Computation
- c = Continuation (The part of the analysis that factors in all properties of dependees)
- EPK = Entity and a PropertyKey
- EPS = Entity and an intermediate Property
- EP = Entity and some (final or intermediate) Property
- EOptionP = Entity and either a PropertyKey or (if available) a Property
Exceptions
In general, exceptions are only thrown if debugging is turned on due to the costs of checking for the respective violations. That is, if debugging is turned off, many potential errors leading to "incomprehensible" results will not be reported. Hence, after debugging an analysis turn debugging (and assertions!) off to get the best performance.
We will throw IllegalArgumentException's iff a parameter is in itself invalid. E.g., the lower
and upper bound do not have the same PropertyKind. In all other cases IllegalStateExceptions
are thrown. All exceptions are either thrown immediately or eventually, when
PropertyStore#waitOnPhaseCompletion is called. In the latter case, the exceptions are
accumulated in the first thrown exception using suppressed exceptions.
- Alphabetic
- By Inheritance
- PropertyStore
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
- new PropertyStore()
Abstract Value Members
-
abstract
def
apply[E <: Entity, P <: Property](epk: EPK[E, P]): EOptionP[E, P]
Returns the property of the respective property kind
pkcurrently associated with the given elemente.Returns the property of the respective property kind
pkcurrently associated with the given elemente.This is the most basic method to get some property and it is the preferred way if (a) you know that the property is already available – e.g., because some property computation function was strictly run before the current one – or if (b) the property is computed using a lazy property computation - or if (c) it may be possible to compute a final answer even if the property of the entity is not yet available.
- epk
An entity/property key pair.
- returns
EPK(e,pk)if information about the respective property is not (yet) available.Final|IntermediateEP(e,Property)otherwise.
- Exceptions thrown
IllegalStateExceptionIf setup phase was not called or a previous computation result contained an epk which was not queried. (Both state are ALWAYS illegal, but are only explicitly checked for if debug is turned on!)- Note
In general, the returned value may change over time but only such that it is strictly more precise.
,Querying a property may trigger the (lazy) computation of the property.
,setupPhase has to be called before calling apply!
-
abstract
def
apply[E <: Entity, P <: Property](e: E, pk: PropertyKey[P]): EOptionP[E, P]
- See also
apply(epk:EPK)for details.
-
abstract
val
ctx: Map[Class[_], AnyRef]
Immutable map which stores the context objects given at initialization time.
-
abstract
def
entities(propertyFilter: (SomeEPS) ⇒ Boolean): Iterator[Entity]
The set of all entities which already have an entity property state that passes the given filter.
The set of all entities which already have an entity property state that passes the given filter.
This method returns a snapshot.
- Note
Does not trigger lazy property computations.
-
abstract
def
entities[P <: Property](lb: P, ub: P): Iterator[Entity]
Returns all entities that currently have the given property bounds based on an "==" (equals) comparison..
Returns all entities that currently have the given property bounds based on an "==" (equals) comparison.. (In case of final properties the bounds are equal.)
- Note
Does not trigger lazy property computations.
-
abstract
def
entities[P <: Property](pk: PropertyKey[P]): Iterator[EPS[Entity, P]]
Returns all entities which have a property of the respective kind.
Returns all entities which have a property of the respective kind. This method returns a consistent snapshot view of the store w.r.t. the given PropertyKey.
- Note
Does not trigger lazy property computations.
-
abstract
def
fastTrackPropertiesCount: Int
The number of properties that were computed using a fast-track.
-
abstract
def
force[E <: Entity, P <: Property](e: E, pk: PropertyKey[P]): Unit
Enforce the evaluation of the specified property kind for the given entity, even if the property is computed lazily and no "eager computation" requires the results anymore.
Enforce the evaluation of the specified property kind for the given entity, even if the property is computed lazily and no "eager computation" requires the results anymore. Force also ensures that the property is stored in the store even if the fallback value is used. Using
forceis in particular necessary in cases where a specific analysis should be scheduled lazily because the computed information is not necessary for all entities, but strictly required for some elements. E.g., if you want to compute a property for some piece of code, but not for those elements of the used library that are strictly necessary. For example, if we want to compute the purity of the methods of a specific application, we may have to compute the property for some entities of the libraries, but we don't want to compute them for all.- Note
Triggers lazy evaluations.
-
abstract
def
handleResult(r: PropertyComputationResult, forceEvaluation: Boolean = false): Unit
Processes the result eventually; generally, not directly called by analyses.
Processes the result eventually; generally, not directly called by analyses. If this function is directly called, the caller has to ensure that we don't have overlapping results and that the given result is a meaningful update of the previous property associated with the respective entity - if any!
- Exceptions thrown
IllegalStateExceptionIf the result cannot be applied.- Note
If any computation resulted in an exception, then
handleResultwill fail and the exception related to the failing computation will be thrown again.
-
abstract
def
hasProperty(e: Entity, pk: PropertyKind): Boolean
See
hasProperty(SomeEPK)for details.See
hasProperty(SomeEPK)for details. * -
abstract
def
immediateOnUpdateComputationsCount: Int
The number of times a property was directly computed again due to an updated dependee.
-
abstract
def
isKnown(e: Entity): Boolean
Returns
trueif the given entity is known to the property store.Returns
trueif the given entity is known to the property store. Here,isKnowncan mean- that we actually have a property, or
- a computation is scheduled/running to compute some property, or
- an analysis has a dependency on some (not yet finally computed) property, or
- that the store just eagerly created the data structures necessary to associate properties with the entity.
- implicit abstract val logContext: LogContext
-
abstract
def
properties[E <: Entity](e: E): Iterator[EPS[E, Property]]
Returns an iterator of the different properties associated with the given element.
Returns an iterator of the different properties associated with the given element.
This method is the preferred way to get a snapshot of all properties of an entity and should be used if you know that all properties are already computed. Using this method will not trigger the computation of a property.
- e
An entity stored in the property store.
- returns
Iterator[Property]
- Note
The returned traversable operates on a snapshot.
,Does not trigger lazy property computations.
-
abstract
def
quiescenceCount: Int
The number of times the property store reached quiescence.
-
abstract
def
registerLazyPropertyComputation[E <: Entity, P <: Property](pk: PropertyKey[P], pc: PropertyComputation[E]): Unit
Registers a function that lazily computes a property for an element of the store if the property of the respective kind is requested.
Registers a function that lazily computes a property for an element of the store if the property of the respective kind is requested. Hence, a first request of such a property will always first return no result.
The computation is triggered by a(n in)direct call of this store's
applymethod.This store ensures that the property computation function
pcis never invoked more than once for the same element at the same time. Ifpcis invoked again for a specific element then only because a dependee has changed!In general, the result can't be an
IncrementalResultandscheduleLazyPropertyComputationcannot be used for properties which should be computed by phased analyses.A lazy computation must never return a NoResult; if the entity cannot be processed an exception has to be thrown or the bottom value has to be returned.
Setting
scheduleLazyPropertyComputationis only supported as long as the store is not queried. In general, this requires that lazy property computations are scheduled before any eager analysis that potentially reads the value. -
abstract
def
registerTriggeredComputation[E <: Entity, P <: Property](pk: PropertyKey[P], pc: PropertyComputation[E]): Unit
Registers a property computation that is eagerly triggered when a property of the given kind is derived for some entity for the first time.
Registers a property computation that is eagerly triggered when a property of the given kind is derived for some entity for the first time. Note, that the property computation function – as usual – has to be thread safe (only on-update continuation functions are guaranteed to be executed sequentially per E/PK pair). The primary use case is to kick-start the computation of some e/pk as soon as an entity "becomes relevant".
In general, it also possible to have a standard analysis that just queries the properties of the respective entities and which maintains the list of dependees. However, if the list of dependees becomes larger and (at least initially) encompasses a significant fraction or even all entities of a specific kind, the overhead that is generated in the framework becomes very huge. In this case, it is way more efficient to register a triggered computation.
For example, if you want to do some processing (kick-start further computations) related to methods that are reached, it is more efficient to register a property computation that is triggered when a method's
Callerproperty is set. Please note, that the property computation is allowed to query and depend on the property that initially kicked-off the computation in the first place. Querying the property store may in particular be required to identify the reason why the property was set. For example, if theCallerproperty was set to the fallback due to a depending computation, it may be necessary to distinguish between the case "no callers" and "unknown callers"; in case of the final property "no callers" the result may very well be NoResult.- pk
The property key.
- pc
The computation that is (potentially concurrently) called to kick-start a computation related to the given entity.
-
abstract
def
resolvedCSCCsCount: Int
The number of resolved closed strongly connected components.
The number of resolved closed strongly connected components.
Please note, that depending on the implementation strategy and the type of the closed strongly connected component, the resolution of one strongly connected component may require multiple phases. This is in particular true if a cSCC is resolved by committing an arbitrary value as a final value and we have a cSCC which is actually a chain-like cSCC. In the latter case committing a single value as final which just break up the chain, but will otherwise (in case of chains with more than three elements) lead to new cSCCs which the require detection and resolution.
-
abstract
def
scheduleEagerComputationForEntity[E <: Entity](e: E)(pc: PropertyComputation[E]): Unit
Schedules the execution of the given
PropertyComputationfunction for the given entity.Schedules the execution of the given
PropertyComputationfunction for the given entity. This is of particular interest to start an incremental computation (cf. IncrementalResult) which, e.g., processes the class hierarchy in a top-down manner.- Note
It is NOT possible to use scheduleEagerComputationForEntity for properties which are also computed by a lazy property computation; use
,forceinstead!If any computation resulted in an exception, then the scheduling will fail and the exception related to the failing computation will be thrown again.
-
abstract
def
scheduledOnUpdateComputationsCount: Int
Simple counter of the number of tasks (OnUpdateContinuations) that were executed in response to an updated property.
-
abstract
def
scheduledTasksCount: Int
Simple counter of the number of tasks that were executed to perform an initial computation of a property for some entity.
-
abstract
def
set(e: Entity, p: Property): Unit
Directly associates the given property
pwith property kindpkwith the given entityeifehas no property of the respective kind.Directly associates the given property
pwith property kindpkwith the given entityeifehas no property of the respective kind. The set property is always final. The store does not guarantee that the value is set before before a later scheduled analysis is executed. I.e., no guarantee is given that the value is set immediately.A use case is an analysis that does use the property store while executing the analysis, but which wants to store the results in the store. Such an analysis must be executed before any other analysis is scheduled.
- Exceptions thrown
IllegalStateExceptionIf a different property is already associated with the given entity or a lazy computation is registered. I.e.,sethas to be called before respective lazy property computations are registered. The exception may be thrown eventually!- Note
This method must not be used if there might be another computation that computes the property kind
pkforeand which returns the respective property as a result.
-
abstract
def
setupPhase(computedPropertyKinds: Set[PropertyKind], delayedPropertyKinds: Set[PropertyKind] = Set.empty): Unit
Needs to be called before an analysis is scheduled to inform the property store which properties will be computed now and which are computed in a later phase.
Needs to be called before an analysis is scheduled to inform the property store which properties will be computed now and which are computed in a later phase. The later information is used to decide when we use a fallback.
- computedPropertyKinds
The kinds of properties for which we will schedule computations.
- delayedPropertyKinds
The set of property kinds which will (also) be computed in a later phase; no fallback will be used for dependencies to properties of the respective kind.
- Note
setupPhaseeven needs to be called if just fallback values should be computed; in this case both sets have to be empty.
- abstract def shutdown(): Unit
-
abstract
def
statistics: Map[String, Int]
Core statistics.
- abstract def supportsFastTrackPropertyComputations: Boolean
-
abstract
def
toString(printProperties: Boolean): String
Returns a consistent snapshot of the stored properties.
Returns a consistent snapshot of the stored properties.
- printProperties
If
trueprints the properties of all entities.
- Note
Some computations may still be running.
-
abstract
def
waitOnPhaseCompletion(): Unit
Awaits the completion of all property computations which were previously scheduled.
Awaits the completion of all property computations which were previously scheduled. As soon as all initial computations have finished, dependencies on E/P pairs for which no value was computed and also will not be computed in the future(!) (see
setupPhasefor details), will be identified and the fallback value will be used. After that, cycle resolution will be performed. I.e., first all _closed_ strongly connected components will be identified that do not contain any properties for which we will compute (in a future phase) any more refined values. Then the values will be made final.If the store is suspended, waitOnPhaseCompletion will return as soon as all running computations are finished. By updating the
isSuspendedstate and callingwaitOnPhaseCompletionagain computations can be continued.- Note
If a second thread is used to register org.opalj.fpcf.PropertyComputation functions no guarantees are given; it is recommended to schedule all property computation functions using one thread and to also use that thread to call this method.
,If a computation fails with an exception, the property store will stop in due time and return the thrown exception. No strong guarantees are given which exception is returned in case of concurrent execution with multiple exceptions.
,In case of an exception, the analyses are aborted as fast as possible and the store is no longer usable.
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
apply[E <: Entity, P <: Property](es: Traversable[E], pmi: PropertyMetaInformation { type Self <: P }): Traversable[EOptionP[E, P]]
Returns a snapshot of the properties with the given kind associated with the given entities.
Returns a snapshot of the properties with the given kind associated with the given entities.
- Note
Querying the properties of the given entities will trigger lazy computations.
,The returned collection can be used to create an IntermediateResult.
- See also
apply(epk:EPK)for details.
-
final
def
apply[E <: Entity, P <: Property](es: Traversable[E], pk: PropertyKey[P]): Traversable[EOptionP[E, P]]
Returns a snapshot of the properties with the given kind associated with the given entities.
Returns a snapshot of the properties with the given kind associated with the given entities.
- Note
Querying the properties of the given entities will trigger lazy computations.
,The returned collection can be used to create an IntermediateResult.
- See also
apply(epk:EPK)for details.
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
def
collectAndThrowException(t: Throwable): Nothing
- Attributes
- protected[this]
- Annotations
- @inline()
-
def
collectException(t: Throwable): Unit
- Attributes
- protected[this]
-
final
def
context[T](key: Class[T]): T
Looks up the context object of the given type.
Looks up the context object of the given type. This is a comparatively expensive operation; the result should be cached.
-
final
def
debug: Boolean
If "debug" is
trueand we have an update related to an ordered property, we will then check if the update is correct! -
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
var
exception: Throwable
- Attributes
- protected[this]
-
def
finalEntities[P <: Property](p: P): Iterator[Entity]
Returns all final entities with the given property.
Returns all final entities with the given property.
- Note
Does not trigger lazy property computations.
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
handleExceptions[U](f: ⇒ U): U
- Attributes
- protected[this]
- Annotations
- @inline()
-
final
def
hasProperty(epk: SomeEPK): Boolean
Tests if we have a property for the entity with the respective kind.
Tests if we have a property for the entity with the respective kind. If
hasPropertyreturnstruea subsequentapplywill return anEPS(not anEPK). -
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
var
isSuspended: () ⇒ Boolean
The callback function that is regularly called by the property store to test if the property store should stop executing new tasks.
The callback function that is regularly called by the property store to test if the property store should stop executing new tasks. Given that the given method is called frequently, it should be reasonably efficient. The method has to be thread-safe.
The default method tests if the current thread is interrupted.
Suspending the property store will leave the property store in a consistent state and the computation can be continued later on by updating this function (if necessary) and calling
waitOnPhaseCompletionagain. I.e., interruption can be used for debugging purposes! -
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
onFirstException(t: Throwable): Unit
Called when the first top-level exception occurs.
Called when the first top-level exception occurs. Intended to be overridden by subclasses.
- Attributes
- protected[this]
-
def
registerLazyMultiPropertyComputation[E <: Entity, P <: Property](pc: PropertyComputation[E], pks: PropertyKey[P]*): Unit
Registers a function that lazily computes multiple properties of different kinds at the same time for an element of the store.
Registers a function that lazily computes multiple properties of different kinds at the same time for an element of the store.
For further details see registerLazyPropertyComputation.
-
def
scheduleEagerComputationsForEntities[E <: Entity](es: TraversableOnce[E])(c: PropertyComputation[E]): Unit
Will call the given function
cfor all elements ofesin parallel.Will call the given function
cfor all elements ofesin parallel.- See also
scheduleEagerComputationForEntity for details.
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
Returns a short string representation of the property store showing core figures.
Returns a short string representation of the property store showing core figures.
- Definition Classes
- PropertyStore → AnyRef → Any
- final def traceCycleResolutions: Boolean
- final def traceFallbacks: Boolean
- var useFastTrackPropertyComputations: Boolean
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )