Package sootup.core.graph
Class ImmutableBlockControlFlowGraph
java.lang.Object
sootup.core.graph.ControlFlowGraph<ImmutableBlockControlFlowGraph.ImmutableBasicBlock>
sootup.core.graph.ImmutableBlockControlFlowGraph
public class ImmutableBlockControlFlowGraph
extends ControlFlowGraph<ImmutableBlockControlFlowGraph.ImmutableBasicBlock>
A truly immutable snapshot of a
ControlFlowGraph. Constructed from any existing graph;
subsequent mutations to the source do not affect this instance.
Provides O(1) bidirectional stmt-to-integer-index mapping via indexOf(Stmt) and
getStmt(int), enabling bitset-based analysis passes (liveness, reaching definitions,
etc.) without per-lookup HashMap overhead.
Construction uses a two-phase algorithm:
- Linearise the source graph in RPO order into a flat
Stmt[]array and createImmutableBlockControlFlowGraph.ImmutableBasicBlockshells. - Wire predecessor/successor/exceptional-successor links between the shells.
- Author:
- Markus Schmidt
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassAn immutable basic block backed by a range [ImmutableBlockControlFlowGraph.ImmutableBasicBlock.startIdx,ImmutableBlockControlFlowGraph.ImmutableBasicBlock.endIdx] of the enclosing graph's flat statement array. -
Constructor Summary
ConstructorsConstructorDescriptionImmutableBlockControlFlowGraph(@NonNull ControlFlowGraph<? extends BasicBlock<?>> source) Constructs an immutable snapshot ofsource. -
Method Summary
Modifier and TypeMethodDescriptionbooleancontainsNode(@NonNull Stmt node) exceptionalPredecessors(@NonNull Stmt node) it is possible to reach traphandlers through inline code i.e. without any exceptional flowexceptionalSuccessors(@NonNull Stmt node) getBlockOf(@NonNull Stmt stmt) intTotal number of stmts in this graph — equals the length of the internal flat array.@NonNull Collection<Stmt>getNodes()returns the nodes in this graph in a non-deterministic order (->Set) to get the nodes in linearized, ordered manner use iterator() or getStmts.@Nullable Stmt@Nullable BasicBlock<?>@NonNull StmtgetStmt(int index) Returns the stmt at the given traversal-order index.getStmts()@NonNull List<BasicBlock<?>>booleanhasEdgeConnecting(@NonNull Stmt source, @NonNull Stmt target) returns true if there is a flow between source and target throws an Exception if at least one of the parameters is not contained in the graph.intreturns the amount of ingoing flows into nodeintReturns the traversal-order position ofstmtin this graph's flat statement array.iterator()intreturns the amount of flows that start from nodepredecessors(@NonNull Stmt node) returns the ingoing flows to node as an List with no reliable/specific order and possibly duplicate entries i.e. if a JSwitchStmt has multiple cases that brnach to `node`voidremoveExceptionalFlowFromAllBlocks(ClassType exceptionType, Stmt exceptionHandlerStmt) Removes the specified exceptional flow from all blocks.successors(@NonNull Stmt node) returns the outgoing flows of node as ordered List.Methods inherited from class sootup.core.graph.ControlFlowGraph
degree, equals, getAllSuccessors, getBlockIterator, getBranchTargetsOf, getEntrypoints, getExtendedBasicBlockPathBetween, getTails, isStmtBranchTarget, toString, validateStmtConnectionsInGraphMethods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
ImmutableBlockControlFlowGraph
Constructs an immutable snapshot ofsource. The source graph is only read during construction; later changes to it do not affect this instance.
-
-
Method Details
-
indexOf
Returns the traversal-order position ofstmtin this graph's flat statement array. O(1) — identity-based IdentityHashMap lookup.- Throws:
NoSuchElementException- ifstmtis not contained in this graph
-
getStmt
Returns the stmt at the given traversal-order index. O(1) array access.- Throws:
ArrayIndexOutOfBoundsException- ifindexis out of range
-
getNodeCount
public int getNodeCount()Total number of stmts in this graph — equals the length of the internal flat array. -
getStartingStmt
- Specified by:
getStartingStmtin classControlFlowGraph<ImmutableBlockControlFlowGraph.ImmutableBasicBlock>
-
getStartingStmtBlock
- Specified by:
getStartingStmtBlockin classControlFlowGraph<ImmutableBlockControlFlowGraph.ImmutableBasicBlock>
-
getTailStmtBlocks
- Specified by:
getTailStmtBlocksin classControlFlowGraph<ImmutableBlockControlFlowGraph.ImmutableBasicBlock>
-
getNodes
Description copied from class:ControlFlowGraphreturns the nodes in this graph in a non-deterministic order (->Set) to get the nodes in linearized, ordered manner use iterator() or getStmts.- Specified by:
getNodesin classControlFlowGraph<ImmutableBlockControlFlowGraph.ImmutableBasicBlock>
-
getStmts
- Overrides:
getStmtsin classControlFlowGraph<ImmutableBlockControlFlowGraph.ImmutableBasicBlock>
-
iterator
- Specified by:
iteratorin interfaceIterable<Stmt>- Overrides:
iteratorin classControlFlowGraph<ImmutableBlockControlFlowGraph.ImmutableBasicBlock>
-
getBlocks
- Specified by:
getBlocksin classControlFlowGraph<ImmutableBlockControlFlowGraph.ImmutableBasicBlock>
-
getBlocksSorted
- Specified by:
getBlocksSortedin classControlFlowGraph<ImmutableBlockControlFlowGraph.ImmutableBasicBlock>
-
getBlockOf
- Specified by:
getBlockOfin classControlFlowGraph<ImmutableBlockControlFlowGraph.ImmutableBasicBlock>
-
containsNode
- Specified by:
containsNodein classControlFlowGraph<ImmutableBlockControlFlowGraph.ImmutableBasicBlock>
-
predecessors
Description copied from class:ControlFlowGraphreturns the ingoing flows to node as an List with no reliable/specific order and possibly duplicate entries i.e. if a JSwitchStmt has multiple cases that brnach to `node`- Specified by:
predecessorsin classControlFlowGraph<ImmutableBlockControlFlowGraph.ImmutableBasicBlock>
-
exceptionalPredecessors
Description copied from class:ControlFlowGraphit is possible to reach traphandlers through inline code i.e. without any exceptional flow- Specified by:
exceptionalPredecessorsin classControlFlowGraph<ImmutableBlockControlFlowGraph.ImmutableBasicBlock>
-
successors
Description copied from class:ControlFlowGraphreturns the outgoing flows of node as ordered List. The List can have duplicate entries!- Specified by:
successorsin classControlFlowGraph<ImmutableBlockControlFlowGraph.ImmutableBasicBlock>
-
exceptionalSuccessors
- Specified by:
exceptionalSuccessorsin classControlFlowGraph<ImmutableBlockControlFlowGraph.ImmutableBasicBlock>
-
inDegree
Description copied from class:ControlFlowGraphreturns the amount of ingoing flows into node- Specified by:
inDegreein classControlFlowGraph<ImmutableBlockControlFlowGraph.ImmutableBasicBlock>
-
outDegree
Description copied from class:ControlFlowGraphreturns the amount of flows that start from node- Specified by:
outDegreein classControlFlowGraph<ImmutableBlockControlFlowGraph.ImmutableBasicBlock>
-
hasEdgeConnecting
Description copied from class:ControlFlowGraphreturns true if there is a flow between source and target throws an Exception if at least one of the parameters is not contained in the graph.- Specified by:
hasEdgeConnectingin classControlFlowGraph<ImmutableBlockControlFlowGraph.ImmutableBasicBlock>
-
removeExceptionalFlowFromAllBlocks
Description copied from class:ControlFlowGraphRemoves the specified exceptional flow from all blocks.- Specified by:
removeExceptionalFlowFromAllBlocksin classControlFlowGraph<ImmutableBlockControlFlowGraph.ImmutableBasicBlock>- Parameters:
exceptionType- The class type of the exceptional flow.exceptionHandlerStmt- The handler statement of the exceptional flow.
-