Class SimulationContext
- java.lang.Object
-
- com.tonic.analysis.simulation.core.SimulationContext
-
public final class SimulationContext extends Object
Immutable configuration and shared resources for simulation; the with* methods return modified copies.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSimulationContext.BuilderMutable builder for SimulationContext instances.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SimulationContextdefaults()Creates a context with default settings and no class pool.static SimulationContextforClass(ClassFile classFile)Creates a context for simulating methods in a class, backed by the pool it was loaded from.static SimulationContextforMethod(MethodEntry method)Creates a context for simulating a single method, backed by the pool its class was loaded from.static SimulationContextforPool(ClassPool pool)Creates a context for simulating across a class pool.CallGraphgetCallGraph()ClassPoolgetClassPool()intgetMaxCallDepth()SimulationModegetMode()booleanisInstructionLevel()booleanisInterProcedural()booleanisTrackHeap()booleanisTrackStackOperations()booleanisTrackValues()StringtoString()SimulationContextwithCallGraph(CallGraph callGraph)Sets the call graph for inter-procedural resolution.SimulationContextwithClassPool(ClassPool classPool)Sets the class pool used to resolve classes and callees.SimulationContextwithHeapTracking(boolean enabled)Enables or disables heap allocation tracking.SimulationContextwithMaxCallDepth(int depth)Sets the maximum call depth for inter-procedural simulation.SimulationContextwithMode(SimulationMode mode)Sets the simulation mode.SimulationContextwithStackOperationTracking(boolean enabled)Enables or disables stack operation tracking.SimulationContextwithValueTracking(boolean enabled)Enables or disables value flow tracking.
-
-
-
Method Detail
-
forMethod
public static SimulationContext forMethod(MethodEntry method)
Creates a context for simulating a single method, backed by the pool its class was loaded from.- Parameters:
method- the method to simulate, may be null- Returns:
- a new context resolving through that method's pool
-
forClass
public static SimulationContext forClass(ClassFile classFile)
Creates a context for simulating methods in a class, backed by the pool it was loaded from.- Parameters:
classFile- the class whose methods will be simulated, may be null- Returns:
- a new context resolving through that class's pool
-
forPool
public static SimulationContext forPool(ClassPool pool)
Creates a context for simulating across a class pool.- Parameters:
pool- the class pool used to resolve classes and callees- Returns:
- a new context with default settings
-
defaults
public static SimulationContext defaults()
Creates a context with default settings and no class pool.- Returns:
- a new default context
-
withMode
public SimulationContext withMode(SimulationMode mode)
Sets the simulation mode.- Parameters:
mode- the mode to use- Returns:
- a new context with the mode applied
-
withMaxCallDepth
public SimulationContext withMaxCallDepth(int depth)
Sets the maximum call depth for inter-procedural simulation.- Parameters:
depth- the depth limit; 0 means intra-procedural only (the default)- Returns:
- a new context with the depth applied
-
withHeapTracking
public SimulationContext withHeapTracking(boolean enabled)
Enables or disables heap allocation tracking.- Parameters:
enabled- whether to track heap allocations- Returns:
- a new context with the setting applied
-
withValueTracking
public SimulationContext withValueTracking(boolean enabled)
Enables or disables value flow tracking.- Parameters:
enabled- whether to track value flow- Returns:
- a new context with the setting applied
-
withStackOperationTracking
public SimulationContext withStackOperationTracking(boolean enabled)
Enables or disables stack operation tracking.- Parameters:
enabled- whether to track stack operations- Returns:
- a new context with the setting applied
-
withCallGraph
public SimulationContext withCallGraph(CallGraph callGraph)
Sets the call graph for inter-procedural resolution.- Parameters:
callGraph- the call graph to use- Returns:
- a new context with the call graph applied
-
withClassPool
public SimulationContext withClassPool(ClassPool classPool)
Sets the class pool used to resolve classes and callees.- Parameters:
classPool- the class pool to use- Returns:
- a new context with the class pool applied
-
getClassPool
public ClassPool getClassPool()
- Returns:
- the class pool
-
getCallGraph
public CallGraph getCallGraph()
- Returns:
- the call graph
-
getMode
public SimulationMode getMode()
- Returns:
- the simulation mode
-
getMaxCallDepth
public int getMaxCallDepth()
- Returns:
- the maximum inter-procedural call depth
-
isTrackHeap
public boolean isTrackHeap()
- Returns:
- whether heap allocation tracking is enabled
-
isTrackValues
public boolean isTrackValues()
- Returns:
- whether value flow tracking is enabled
-
isTrackStackOperations
public boolean isTrackStackOperations()
- Returns:
- whether stack operation tracking is enabled
-
isInterProcedural
public boolean isInterProcedural()
- Returns:
- true when inter-procedural simulation is enabled (max call depth above zero)
-
isInstructionLevel
public boolean isInstructionLevel()
- Returns:
- true when instruction-level state tracking is enabled
-
-