Skip to content

Commit

Permalink
Remove StateNames and getStateByName
Browse files Browse the repository at this point in the history
`getStateByName` existed uniquely as a workaround for retrieving the jvm/heap tree state from a composite abstract state containing both.

Since composite abstract states have been removed together with the heap tree model, `getStateByName` has no reason to exist anymore.

The code is functionally unchanged since for a JvmAbstractState `getStateByName("Jvm") is just the state itself.

There are still problems with unchecked casts for all the states that were returned by getStateByName, but these will be resolved in a separate commit.
  • Loading branch information
capoz authored and JorenHannes committed Jan 13, 2025
1 parent 96393cd commit 8339ae6
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@ default Precision getPrecision() {
/** Creates a copy of itself. */
AbstractState copy();

/**
* Returns an abstract state for a given {@param name} if the state is composite, returns {@code
* self} otherwise.
*/
default AbstractState getStateByName(String name) {
return this;
}

// overrides for Object

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
import proguard.analysis.cpa.jvm.witness.JvmMemoryLocation;
import proguard.analysis.cpa.jvm.witness.JvmStackLocation;
import proguard.analysis.cpa.jvm.witness.JvmStaticFieldLocation;
import proguard.analysis.cpa.util.StateNames;
import proguard.analysis.datastructure.callgraph.Call;
import proguard.classfile.AccessConstants;
import proguard.classfile.Clazz;
Expand Down Expand Up @@ -254,8 +253,7 @@ public Collection<? extends AbstractState> generateAbstractSuccessors(
}

JvmAbstractState<AbstractStateT> returnJvmAbstractState =
(JvmAbstractState<AbstractStateT>)
returnState.get().getStateByName(StateNames.Jvm);
(JvmAbstractState<AbstractStateT>) returnState.get();
AbstractStateT value =
state
.getLocationDependentMemoryLocation()
Expand Down Expand Up @@ -334,8 +332,7 @@ public Collection<? extends AbstractState> generateAbstractSuccessors(
successors.addAll(
getSuccessorsFromMemoryLocations(
intraproceduralSuccessorMemoryLocations,
(JvmAbstractState<AbstractStateT>)
intraproceduralParentState.get().getStateByName(StateNames.Jvm),
(JvmAbstractState<AbstractStateT>) intraproceduralParentState.get(),
state.getSourceReachedSet(),
state.copyStack()));
}
Expand Down Expand Up @@ -366,8 +363,7 @@ public Collection<? extends AbstractState> generateAbstractSuccessors(
ci ->
getSuccessorsFromMemoryLocations(
Collections.singletonList(callerMemoryLocation.get()),
(JvmAbstractState<AbstractStateT>)
ci.state.getStateByName(StateNames.Jvm),
(JvmAbstractState<AbstractStateT>) ci.state,
ci.reachedSet,
new LinkedList<>())
.stream()
Expand All @@ -380,8 +376,7 @@ public Collection<? extends AbstractState> generateAbstractSuccessors(
successors.addAll(
getSuccessorsFromMemoryLocations(
Collections.singletonList(callerMemoryLocation.get()),
(JvmAbstractState<AbstractStateT>)
currentEntry.callerState.getStateByName(StateNames.Jvm),
(JvmAbstractState<AbstractStateT>) currentEntry.callerState,
currentEntry.reachedSet,
successorStack));
}
Expand Down Expand Up @@ -834,8 +829,7 @@ public void visitConstantInstruction(
memoryLocation,
constantInstruction,
clazz,
((JvmAbstractState<AbstractStateT>) parentState.getStateByName(StateNames.Jvm))
.getProgramLocation()));
((JvmAbstractState<AbstractStateT>) parentState).getProgramLocation()));
break;
case Instruction.OP_NEW:
case Instruction.OP_NEWARRAY:
Expand Down
33 changes: 0 additions & 33 deletions base/src/main/java/proguard/analysis/cpa/util/StateNames.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,7 @@ public BamCache<MethodSignature> getTaintResultCache() {
.asCollection()
.forEach(
state ->
((JvmAbstractState<SetAbstractState<JvmTaintSource>>)
state.getStateByName(StateNames.Jvm))
((JvmAbstractState<SetAbstractState<JvmTaintSource>>) state)
.getProgramLocation()
.getLeavingEdges()
.forEach(
Expand Down Expand Up @@ -267,8 +266,7 @@ private void createEndpointsForEdgeIfTainted(
.filter(
memoryLocation ->
isStateTaintedForMemoryLocation(
(JvmAbstractState<SetAbstractState<JvmTaintSource>>)
state.getStateByName(StateNames.Jvm),
(JvmAbstractState<SetAbstractState<JvmTaintSource>>) state,
memoryLocation,
sinkToMemoryLocations.getKey()))
.forEach(
Expand Down
1 change: 1 addition & 0 deletions docs/md/releasenotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ make its usage easier. This includes:
- Remove `JvmTaintMemoryLocationBamCpaRun` in order to simplify the utility code to run the analysis. `TaintAnalyzer` is the direct replacement, this class has the same behavior as `JvmTaintMemoryLocationBamCpaRun`, as long as `analyze` is called only once.
- Remove the `CpaRun` infrastructure.
- Remove `MapAbstractStateFactory`, `WrapperTransferRelation`, and other classes that were only used with the tree heap model.
- Remove `StateNames` and `getStateByName`.

## Version 9.1.6

Expand Down

0 comments on commit 8339ae6

Please sign in to comment.