package domain
This package contains definitions of common domains that can be used for the implementation of analyses.
Types of Domains
In general, we distinguish two types of domains. First, domains that define a
general interface (on top of the one defined by Domain), but do not directly
provide an implementation. Hence, whenever you develop a new Domain
you should
consider implementing/using these domains to maximize reusability. Second,
Domain
s that implement a specific interface (trait). In this case, we further
distinguish between domains that provide a default implementation (per interface
only one of these Domain
s can be used to create a final Domain
) and
those that can be stacked and basically refine the overall functionality.
Examples
- Domains That Define a General Interface
- Origin defines two types which domains that provide information abou the origin of a value should consider to implement.
- TheProject defines a standard mechanism how a domain can access the current project.
- ...
- Domains That Provide a Default Implementation
- Origin defines the functionality to return a value's origin if the value supports that.
- org.opalj.ai.domain.TheProject default implementation of the class hierarchy related methods using the project's class hierarchy.
- org.opalj.ai.domain.DefaultHandlingOfMethodResults basically implements a Domain's methods related to return instructions an uncaught exceptions.
- ...
- Domains That Implement Stackable Functionality
- org.opalj.ai.domain.RecordThrownExceptions records information about all uncaught exceptions
by intercepting a
Domain
's respective methods. However, it does provide a default implementation. Hence, a typical pattern is:
- org.opalj.ai.domain.RecordThrownExceptions records information about all uncaught exceptions
by intercepting a
class MyDomain extends Domain with ... with DefaultHandlingOfMethodResults with RecordThrownExceptions
Thread Safety
Unless explicitly documented, a domain is never thread-safe. The general programming
model is to use one Domain
object per code block/method and therefore, thread-safety
is not required for Domain
s that are used for the evaluation of methods. However
domains that are used to adapt/transfer values should be thread safe
(see org.opalj.ai.domain.ValuesCoordinatingDomain for further details).
- Source
- package.scala
- Alphabetic
- By Inheritance
- domain
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- trait AsDomainValue extends AnyRef
Mixed in by domains that support the conversation of a Java Object into a
DomainValue
.Mixed in by domains that support the conversation of a Java Object into a
DomainValue
.- See also
AsJavaObject for further information on limitations.
- trait AsJavaObject extends AnyRef
Mixed in by domains that support the conversation of a
DomainValue
into a respective Java object.Mixed in by domains that support the conversation of a
DomainValue
into a respective Java object. This Java object can then be used to perform method invocations.Limitation
Using
AsJavaObject
will only work reasonably iff the respective class is either in the classpath of the JVM or a class loader (initialized with the project's classpath) is used. The latter, however, does not work for classes on the bootclasspath (e.g.,java.lang.String
). In that case it is necessary to check that the code of the analyzed application is compatible with the one on the class path. To avoid accidental imprecision in the analysis you should use this features only for stable classes belonging to the core JDK (java.lang...
.) - trait ConcreteIntegerValues extends AnyRef
Provides information about an integer value's precise value, if this information is available.
Provides information about an integer value's precise value, if this information is available.
- Note
The information about an integer value's range that is required by the abstract interpreter is defined by the
,Domain
trait.This functionality is not required by the OPAL core.
- trait ConcreteLongValues extends AnyRef
Provides information about a long value's precise value, if this information is available.
Provides information about a long value's precise value, if this information is available.
- Note
This abstract interpreter never requires knowledge about the precise value of a value with computational type
long
.
- trait ConstantFieldValuesResolution extends Domain
Resolves references to final static fields that have simple constant values.
Resolves references to final static fields that have simple constant values.
- Note
A typical Java compiler automatically resolves all simple references and, hence, this trait has for Java projects in general no effect. If we analyze other languages that compile to the JVM platform, the effect might be different.
- trait CurrentCode extends TheCode with CustomInitialization
Provides information about the code block that is currently analyzed.
Provides information about the code block that is currently analyzed.
Core Properties
- "Automatically reset" when the domain is used to analyze another method.
- "Concurrent Usage": "No"
- trait DefaultExceptionsFactory extends ExceptionsFactory
Default implementation of the ExceptionsFactory trait that relies on the ReferenceValuesFactory.
- trait DefaultHandlingForReturnInstructions extends ReturnInstructionsDomain
Provides default implementations for a
Domain
's return methods that always throw anIllegalMonitorStateExceptoin
.Provides default implementations for a
Domain
's return methods that always throw anIllegalMonitorStateExceptoin
.You can mix in this trait if you are not interested in a method's return values or if you need some default implementations.
- trait DefaultHandlingForThrownExceptions extends ReturnInstructionsDomain
Basic implementation of a
Domain
'sabruptMethodExecution
method that does nothing.Basic implementation of a
Domain
'sabruptMethodExecution
method that does nothing.- Note
Mix-in this trait if the analysis does not need to do anything special in case of an exception or if you have multiple stackable traits and you need a base implementation. Example:
MySpecialDomain extends ... with DefaultHandlingForThrownExceptions with RecordThrownExceptions with ...
- trait DefaultHandlingOfMethodResults extends DefaultHandlingForThrownExceptions with DefaultHandlingOfVoidReturns with DefaultHandlingForReturnInstructions
A
Domain
that does nothing if a method returns ab-/normally.A
Domain
that does nothing if a method returns ab-/normally.- Note
This trait's methods are generally not intended to be overridden. If you need to do some special processing just directly implement the respective method and mixin the traits that ignore the rest.
- trait DefaultHandlingOfVoidReturns extends ReturnInstructionsDomain
Basic implementation of a
Domain
sreturnVoid
method that does nothing. - trait DefaultRecordMethodCallResults extends RecordMethodCallResults with RecordLastReturnedValues with RecordAllThrownExceptions
Records the results of the evaluation of the
current
method such that the results can directly be adapted to the calling context and can be used by the caller to continue the abstract interpretation of the calling method. - trait DefaultSpecialDomainValuesBinding extends ValuesDomain
Final binding of a
Domain
's typeDomainValue
as well as all subtypes of it that are also defined byDomain
.Final binding of a
Domain
's typeDomainValue
as well as all subtypes of it that are also defined byDomain
.The type
DomainValue
is set to the type org.opalj.ai.Domain.Value. - trait DomainId extends AnyRef
Common super trait of all domains have an id to identify them.
- sealed abstract class DomainValues extends AnyRef
Encapsulates a
domain
and some values created by the respective domain.Encapsulates a
domain
and some values created by the respective domain.Using the class
DomainValues
enables type-safety when we need to store and pass on aDomain
object and some of its values. - trait GeneralizedArrayHandling extends ReferenceValuesDomain
This (partial-)domain abstracts over the concrete methods for performing array operations and provides an interface at a higher abstraction level.
- trait IgnoreSynchronization extends MonitorInstructionsDomain
Provides a default implementation for the instructions related to synchronization.
- case class ImpossibleRefinement(value: AnyRef, refinementGoal: String) extends AIException with Product with Serializable
Thrown to indicate that a refinement of some value was not possible.
- trait MethodCallResults extends AnyRef
Trait that can be mixed in if information is needed about all returned values and the thrown exceptions.
Trait that can be mixed in if information is needed about all returned values and the thrown exceptions. This information is, however, only available after the evaluation of a method has completed.
- trait MethodCallsHandling extends MethodCallsDomain
Provides support for handling method invocations, but does not handle any invocations directly.
- trait MonitorInstructionsTracker extends MonitorInstructionsDomain with CustomInitialization
Tracks if a monitor(enter|exit) instruction was executed.
Tracks if a monitor(enter|exit) instruction was executed.
This knowledge is of interest to decide, e.g., whether a return instruction may throw an
IllegalMonitorStateException
or not. - trait Origin extends AnyRef
Provides information about the origin (that is, def-site) of a value iff the underlying domain provides the respective information; that is, this trait only defines the public API it does not provide origin information on its own.
Provides information about the origin (that is, def-site) of a value iff the underlying domain provides the respective information; that is, this trait only defines the public API it does not provide origin information on its own.
However, a domain that provides origin information has to do so for ALL values of the respective computational type category and the information has to be complete.
Usage
To get origin information this trait needs be implemented by a domain. I.e., just mixing in this trait will not provide origin information about values.
Implementation
This trait should be inherited from by all domains that make information about the origin of a value available (see org.opalj.ai.domain.l1.ReferenceValues as an example); the respective domains have to override providesOriginInformationFor
- Note
A org.opalj.br.instructions.CHECKCAST must not modify
origin
information; i.e., the origin of the value on the stack before and after the checkast (unless we have an exception) must be the same!
- trait PerInstructionPostProcessing extends CoreDomainFunctionality
Provides the generic infrastructure to register a function that updates the operands and locals associated with an instruction that will be evaluated "next".
Provides the generic infrastructure to register a function that updates the operands and locals associated with an instruction that will be evaluated "next". For example, let's assume that we are currently processing instruction X and that instruction Y is the successor instruction. In this case, the framework will first determine the effect of function X on the stack/locals. After that, all registered updaters will be called. All registered updaters will be discarded as soon the evaluation of instruction X has completed.
- trait PostEvaluationMemoryManagement extends CoreDomainFunctionality
Provides the possibility to further update the memory layout (registers and operands) after the execution of an instruction, but before any potential join is performed.
Provides the possibility to further update the memory layout (registers and operands) after the execution of an instruction, but before any potential join is performed.
Using this domain is only safe if the (partial-)domains that use this functionality never interfere with each other.
- Note
If this domain is mixed in then the domain cannot be used to simultaneously analyze multiple different methods at the same time.
- trait PredefinedClassHierarchy extends AnyRef
This class uses OPAL's
PreInitializedClassHierarchy
(seeClassHierarchy
for details) for class hierarchy related queries.This class uses OPAL's
PreInitializedClassHierarchy
(seeClassHierarchy
for details) for class hierarchy related queries.Use this trait ONLY if you just want to do some testing.
- trait RecordAllThrownExceptions extends RecordThrownExceptions
Records all exceptions thrown by a method.
Records all exceptions thrown by a method. I.e., for each instruction that throws an exception (or multiple exceptions) all exceptions are recorded.
- Note
This domain requires that
,DomainValue
s that represent thrown exceptions have meaningfulequals
andhashCode
methods. (Depending on the purpose of the abstract interpretation, reference equality may be sufficient.)This domain is only effective if the calculation of joins is fast. Otherwise it can significantly hamper overall performance!
- trait RecordCFG extends CoreDomainFunctionality with CustomInitialization with ai.ReturnInstructionsDomain
Records the abstract interpretation time control-flow graph (CFG).
Records the abstract interpretation time control-flow graph (CFG). This CFG is always (still) a sound approximation of the generally incomputable real(runtime) CFG.
Usage (Mixin-Composition Order)
This domain primarily overrides the
flow
method and requires that it is mixed in before every other domain that overrides theflow
method and which may manipulate theworklist
. E.g., the mixin order should be:class MyDomain extends Domain with RecordCFG with FlowManipulatingDomain
If the mixin order is not correct, the computed CFG may not be complete/concrete.
Core Properties
- Thread-safe: No; i.e., the composed domain can only be used by one abstract interpreter at a time. However, using the collected results is thread-safe!
- Reusable: Yes; all state directly associated with the analyzed code block is
reset by the method
initProperties
. - No Partial Results: If the abstract interpretation was aborted the results have no meaning and must not be used; however, if the abstract interpretation is later continued and successfully completed the results are correct.
- trait RecordConstraints extends ReifiedConstraints
Mixin this trait if you want to reify the constraints that are stated by the abstract interpretation framework.
Mixin this trait if you want to reify the constraints that are stated by the abstract interpretation framework. This is particularly useful for testing and debugging purposes.
- trait RecordDefUse extends RecordCFG
Collects the definition/use information based on the abstract interpretation time cfg.
Collects the definition/use information based on the abstract interpretation time cfg. I.e., makes the information available which value is accessed where/where a used value is defined. In general, all local variables are identified using
Int
s where theInt
identifies the expression (by means of it's pc) which evaluated to the respective value. In case of a parameter theInt
value is-parametersIndex corrected by computational type category
(see below for details).In case of exception values the
Int
value identifies the instruction which ex-/implicitly raised the exception.- Note
A checkcast is considered a use-site, but not a def-site, even if the shape changes/ the assumed type is narrowed. Otherwise, if the cast is useless, we could not replace it by a NOP.
General Usage
This trait collects the def/use information after the abstract interpretation has successfully completed and the control-flow graph is available. The information is automatically made available, when this plug-in is mixed in.
Special Values
Parameters
The ex-/implicit parameters given to a method have negative
int
values (the first parameter has the value -1, the second -2 if the first one is a value of computational type category one and -3 if the first value is of computational type category two and so forth). I.e., in case of a methoddef (d : Double, i : Int)
, the second parameter will have the index -3.Core Properties
Reusability
An instance of this domain can be reused to successively perform abstract interpretations of different methods. The domain's inherited
initProperties
method – which is always called by the AI framework – resets the entire state related to the method.
- trait RecordJoinedThrownExceptions extends RecordThrownExceptions
Records the exception that is thrown by an instruction.
Records the exception that is thrown by an instruction. If an instruction throws multiple exceptions. The exceptions are
join
ed using the Domain#DomainValue'sjoin
method.This trait can be used to record the thrown exceptions independently of the precision of the domain.
- trait RecordLastReturnedValues extends RecordReturnedValues
Records the last value that is returned by a specific return instruction.
Records the last value that is returned by a specific return instruction.
Recording just the last value that is returned by an
(a|i|l|f|d)return
instruction is often sufficient (e.g., in case of a domain that performs all computations at the type level). The "last" value encodes all necessary information. - trait RecordMethodCallResults extends MethodCallResults with RecordReturnedValues with RecordThrownExceptions
Records the results of the evaluation of the
current
method such that the results can directly be adapted to the calling context and can be used by the caller to continue the abstract interpretation of the calling method.Records the results of the evaluation of the
current
method such that the results can directly be adapted to the calling context and can be used by the caller to continue the abstract interpretation of the calling method.The returned value will only be a given parameter, if the given parameter is not mutated. For example, if an array is passed to a method where the content is reified, the returned value will only be mapped back to the parameter value if the array is not changed at all. In other words, the returned value, which may get the pc of the method caller, may refer to any parameter given to the method. Only, if the returned value is a parameter, we know that this specific parameter was not mutated at all.
- trait RecordReturnFromMethodInstructions extends ai.ReturnInstructionsDomain
Records the program counters of all instructions that lead to a (ab)normal return from the method.
Records the program counters of all instructions that lead to a (ab)normal return from the method. I.e., every instruction that may throw an exception or causes a normal return from method may be recorded. Examples of instructions that may be recorded:
(X)return
,throw
,invoke(XXX)
,get|put(static|field)
,checkcast
,(a)new(array)
,... . Instructions such asswap
ordup(XXX)
, however, never directly lead to a method return (they will never result in an exception) and will not be recorded.If you are interested in recording the values use: RecordReturnedValues, RecordThrownExceptions.
Usage
This domain can be stacked on top of other traits that handle return instructions and abrupt method executions.
- trait RecordReturnedValue extends RecordReturnedValuesInfrastructure
Record the value returned by a method across all return instructions.
Record the value returned by a method across all return instructions.
Usage
This domain can be stacked on top of other traits that handle return instructions that return some value.
Usage
A domain that mixes in this trait should only be used to analyze a single method.
- trait RecordReturnedValueInfrastructure extends RecordReturnedValuesInfrastructure
Generic infrastructure to record the value returned by the method (calculated across all return instructions)
Generic infrastructure to record the value returned by the method (calculated across all return instructions)
Usage
This domain can be stacked on top of other traits that handle return instructions that return some value.
Usage
A domain that mixes in this trait should only be used to analyze a single method.
- trait RecordReturnedValues extends RecordReturnedValuesInfrastructure with CustomInitialization
Generic infrastructure to record the values returned by the method.
Generic infrastructure to record the values returned by the method. (Note that the computational type of the value(s) is not recorded. It is directly determined by the signature of the method that is analyzed or can be extracted using the respective method.)
Usage
This domain can be stacked on top of other traits that handle return instructions that return some value.
Usage
A domain that mixes in this trait should only be used to analyze a single method.
- trait RecordReturnedValuesInfrastructure extends ai.ReturnInstructionsDomain
Infrastructure to record returned values.
- trait RecordThrownExceptions extends ai.ReturnInstructionsDomain
Generic infrastructure to record the exceptions thrown by a method.
Generic infrastructure to record the exceptions thrown by a method. This trait can be used to record the thrown exceptions independently of the precision of the domain.
Usage
This domain can be stacked on top of other traits that handle abruptMethodExecutions.
- trait RecordVoidReturns extends ReturnInstructionsDomain
Records the program counters of all return (void) instructions that are reached.
Records the program counters of all return (void) instructions that are reached.
Usage
Typical usage:
class MyDomain extends ...DefaultHandlingOfVoidReturns with RecordVoidReturns
This domain forwards all instruction evaluation calls to the super trait.
Core Properties
- Needs to be stacked upon a base implementation of the domain ReturnInstructionsDomain.
- Collects information directly associated with the analyzed code block.
- Not thread-safe.
- Not reusable.
- trait RefineDefUseUsingOrigins extends RecordDefUse
Collects/refines the abstract interpretation time definition/use information using the domain values' origin information if available.
Collects/refines the abstract interpretation time definition/use information using the domain values' origin information if available.
- Note
ReturnAddressValues are ignored by this domain; however, the parent domain RecordDefUse has appropriate handling.
- trait ReifiedConstraints extends IntegerValuesDomain with ReferenceValuesDomain
Mixin this trait to reify the stated constraints.
Mixin this trait to reify the stated constraints. This trait need to be mixed in after all traits that actually handle constraints.
This is particularly useful for testing and debugging purposes.
Core Properties
- Needs to be stacked upon a base implementation of the domains: IntegerValuesDomain and ReferenceValuesDomain].
- Collects state directly associated with the analyzed code block.
- Not thread-safe.
- Not reusable (I.e., a new instance needs to be created per method.)
- trait ReturnInstructionsDomain extends ai.ReturnInstructionsDomain
Adds support for handling return instructions in a generic manner.
- trait SpecialMethodsHandling extends MethodCallsHandling
Hard-codes some part of the semantics of some very high-profile (native) methods of the JDK (for example,
System.arraycopy
).Hard-codes some part of the semantics of some very high-profile (native) methods of the JDK (for example,
System.arraycopy
).Mixin Order
This method should be mixed in (lexically) after those domains that provide the basic handling of unresolved methods (e.g., using "just" type information) but before those that actually invoke a method!
- trait TheCode extends AnyRef
Provides information about the code block that is currently analyzed.
Provides information about the code block that is currently analyzed.
Core Properties
- Defines the public interface.
- trait TheMethod extends TheCode
Provides information about the method that is currently analyzed.
Provides information about the method that is currently analyzed.
Usage
A domain that implements this trait usually defines a parameter that is set at construction time.
E.g.,
class MyDomain{val method : Method} extends Domain with TheMethod
Core Properties
- Defines the public interface.
- Makes the analyzed org.opalj.br.Method (and its org.opalj.br.Code) available.
- Thread safe.
- trait TheProject extends ThePropertyStore with LogContextProvider
Provides information about the underlying project.
Provides information about the underlying project.
Usage
If a (partial-) domain needs information about the project declare a corresponding self-type dependency.
trait MyIntegerValuesDomain extends IntegerValues { this : TheProject =>
Providing Information about a Project
A domain that provides information about the currently analyzed project should inherit from this trait and implement the respective method.
Core Properties
- Defines the public interface.
- Makes the analyzed org.opalj.br.analyses.Project available.
- Thread safe.
- Note
It is recommended that the domain that provides the project information does not use the
override
access flag. This way the compiler will issue a warning if two implementations are used to create a final domain.
- trait ThePropertyStore extends AnyRef
This trait is mixed in by those (partial) domains that require access to the project's property store.
- trait ThrowAllPotentialExceptionsConfiguration extends Configuration
A configuration that forces abstract interpretation to always create an exception if it is not possible to deduce that a specific exception will not be thrown.
A configuration that forces abstract interpretation to always create an exception if it is not possible to deduce that a specific exception will not be thrown.
Usage
If you need to adapt a setting just override the respective method in your domain or create a class that inherits from Configuration.
Core Properties
- Concrete base implementation of the Configuration trait that can be used to create a final domain.
- Thread safe.
- trait ThrowNoPotentialExceptionsConfiguration extends Configuration
A configuration that forces the abstract interpretor to never create an exception if it is not possible to deduce that the specific exception is guaranteed to be thrown.
A configuration that forces the abstract interpretor to never create an exception if it is not possible to deduce that the specific exception is guaranteed to be thrown.
Usage
If you need to adapt a setting just override the respective method in your domain or create a class that inherits from Configuration.
Core Properties
- Concrete base implementation of the Configuration trait that can be used to create a final domain.
- Thread safe.
- trait ValuesCoordinatingDomain extends CorrelationalDomain with Configuration
Can be mixed in to create a
Domain
that is intended to be used to coordinate the exchange of values between different domains.Can be mixed in to create a
Domain
that is intended to be used to coordinate the exchange of values between different domains.This domain does not prescribe the semantics of any values, but instead implements methods that perform computations.
This domain directly inherits from Domain and can, thus, directly be used to create a final domain.
Core Properties
- Concrete base implementation of the following domains:
- Thread safe.
- Reusable.
Value Members
- final val EmptyUpperTypeBound: UIDSet[ReferenceType]
- def analyzedEntity(domain: Domain): String
Tries to determine the name of the method/class that is analyzed; the result depends on the mixed-in domain(s).
- object DomainValues
Factory for creating
DomainValues
objects. - object Origin
- object Origins
- object OriginsIterator
- object PerformAI extends BaseAI
A base abstract interpreter that can be used with any domain that has no special requirements on the abstract interpreter and which provides some convenience factory methods to run the abstract interpretation if the domain provide the necessary information.
A base abstract interpreter that can be used with any domain that has no special requirements on the abstract interpreter and which provides some convenience factory methods to run the abstract interpretation if the domain provide the necessary information.
The base interpreter can be interrupted by calling the
interrupt
method of the AI's thread.- See also
BoundedInterruptableAI for an abstract interpreter that can easily be interrupted and which also interrupts itself if a certain threshold is exceeded.
- object PredefinedClassHierarchy
- object SpecialMethodsHandling