Skip to content

Commit

Permalink
Cleanup memory location states
Browse files Browse the repository at this point in the history
  • Loading branch information
capoz authored and piazzesiNiccolo-GS committed Dec 11, 2024
1 parent 13ccade commit c728473
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 96 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import proguard.analysis.cpa.bam.ExpandOperator;
import proguard.analysis.cpa.bam.ReduceOperator;
import proguard.analysis.cpa.defaults.LatticeAbstractState;
import proguard.analysis.cpa.defaults.MemoryLocation;
import proguard.analysis.cpa.defaults.ProgramLocationDependentReachedSet;
import proguard.analysis.cpa.defaults.SetAbstractState;
import proguard.analysis.cpa.interfaces.AbstractState;
Expand Down Expand Up @@ -85,7 +84,7 @@
/**
* The {@link JvmMemoryLocationTransferRelation} computes the backward successors of an {@link
* JvmMemoryLocationAbstractState} for a given instruction. A backward successor is a memory
* location which may have contributed to the value of the current {@link MemoryLocation}.
* location which may have contributed to the value of the current {@link JvmMemoryLocation}.
*
* <p>The transfer relation uses a {@link BamCache} containing the results of an analysis in order
* to calculate the successors {@link JvmMemoryLocationAbstractState}:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
* The {@link JvmAbstractState} consists of the method frame {@link JvmFrameAbstractState} and the
* heap {@link JvmHeapAbstractState}.
*
* @author Dmitry Ivanov
* @param <StateT> The type of the states contained in the JVM state. e.g., for taint analysis this
* would be a {@link proguard.analysis.cpa.defaults.SetAbstractState} containing the taints and
* for value analysis a {@link proguard.analysis.cpa.jvm.domain.value.ValueAbstractState}.
*/
public class JvmAbstractState<StateT extends LatticeAbstractState<StateT>>
implements LatticeAbstractState<JvmAbstractState<StateT>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@
import proguard.analysis.cpa.jvm.domain.reference.Reference;
import proguard.analysis.cpa.jvm.state.JvmAbstractState;

/**
* The {@link JvmHeapLocation} is a memory location corresponding to a dynamic memory entity.
*
* @author Dmitry Ivanov
*/
/** The {@link JvmHeapLocation} is a memory location corresponding to a dynamic memory entity. */
public class JvmHeapLocation extends JvmMemoryLocation {

public final SetAbstractState<Reference> reference;
Expand All @@ -49,9 +45,9 @@ public JvmHeapLocation(SetAbstractState<Reference> reference, String field) {
// implementations for MemoryLocation

@Override
public <T extends LatticeAbstractState> T extractValueOrDefault(
JvmAbstractState abstractState, T defaultValue) {
return (T) abstractState.getHeap().getFieldOrDefault(reference, field, defaultValue);
public <T extends LatticeAbstractState<T>> T extractValueOrDefault(
JvmAbstractState<T> jvmState, T defaultValue) {
return jvmState.getHeap().getFieldOrDefault(reference, field, defaultValue);
}

// implementations for Object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@
import proguard.analysis.cpa.defaults.LatticeAbstractState;
import proguard.analysis.cpa.jvm.state.JvmAbstractState;

/**
* The {@link JvmLocalVariableLocation} is a memory location at the local variable array.
*
* @author Dmitry Ivanov
*/
/** The {@link JvmLocalVariableLocation} is a memory location at the local variable array. */
public class JvmLocalVariableLocation extends JvmMemoryLocation {

public final int index;
Expand All @@ -43,9 +39,9 @@ public JvmLocalVariableLocation(int index) {
// implementations for MemoryLocation

@Override
public <T extends LatticeAbstractState> T extractValueOrDefault(
JvmAbstractState abstractState, T defaultValue) {
return (T) abstractState.getVariableOrDefault(index, defaultValue);
public <T extends LatticeAbstractState<T>> T extractValueOrDefault(
JvmAbstractState<T> jvmState, T defaultValue) {
return jvmState.getVariableOrDefault(index, defaultValue);
}

// implementations for Object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,37 @@
package proguard.analysis.cpa.jvm.witness;

import proguard.analysis.cpa.defaults.LatticeAbstractState;
import proguard.analysis.cpa.defaults.MemoryLocation;
import proguard.analysis.cpa.jvm.cfa.edges.JvmCfaEdge;
import proguard.analysis.cpa.jvm.cfa.nodes.JvmCfaNode;
import proguard.analysis.cpa.jvm.state.JvmAbstractState;
import proguard.classfile.MethodSignature;

/**
* A {@link JvmMemoryLocation} is a {@link MemoryLocation} specific to JVM.
*
* @author Dmitry Ivanov
* A {@link JvmMemoryLocation} points at a specific location in a certain state of the Jvm. For
* example a {@link JvmStackLocation} with index 0 indicates the top of the stack.
*/
public abstract class JvmMemoryLocation
extends MemoryLocation<
JvmCfaNode, JvmCfaEdge, MethodSignature, LatticeAbstractState, JvmAbstractState> {}
public abstract class JvmMemoryLocation {

/**
* Given a JVM state, extract its content in the position represented by this {@link
* JvmMemoryLocation}.
*
* @param jvmState The state from which the value is extracted.
* @param defaultValue The value returned if it's not possible to extract the value.
* @return The value from the JVM abstract state for the memory location represented by this
* object. Or default value if not possible.
* @param <T> The type of the states contained in the JVM state. e.g., for taint analysis this
* would be a {@link proguard.analysis.cpa.defaults.SetAbstractState} containing the taints
* and for value analysis a {@link proguard.analysis.cpa.jvm.domain.value.ValueAbstractState}.
*/
public abstract <T extends LatticeAbstractState<T>> T extractValueOrDefault(
JvmAbstractState<T> jvmState, T defaultValue);

// implementations for Object

@Override
public abstract boolean equals(Object obj);

@Override
public abstract int hashCode();

@Override
public abstract String toString();
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
/**
* The {@link JvmStackLocation} is a memory location at the operand stack. Indexing starts from the
* top of the stack.
*
* @author Dmitry Ivanov
*/
public class JvmStackLocation extends JvmMemoryLocation {

Expand All @@ -44,9 +42,9 @@ public JvmStackLocation(int index) {
// implementations for MemoryLocation

@Override
public <T extends LatticeAbstractState> T extractValueOrDefault(
JvmAbstractState abstractState, T defaultValue) {
return (T) abstractState.peekOrDefault(index, defaultValue);
public <T extends LatticeAbstractState<T>> T extractValueOrDefault(
JvmAbstractState<T> jvmState, T defaultValue) {
return jvmState.peekOrDefault(index, defaultValue);
}

/** Returns the stack index from the top. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

/**
* The {@link JvmStaticFieldLocation} is a memory location corresponding to a public static field.
*
* @author Dmitry Ivanov
*/
public class JvmStaticFieldLocation extends JvmMemoryLocation {

Expand All @@ -42,9 +40,9 @@ public JvmStaticFieldLocation(String fqn) {
// implementations for MemoryLocation

@Override
public <T extends LatticeAbstractState> T extractValueOrDefault(
JvmAbstractState abstractState, T defaultValue) {
return (T) abstractState.getStaticOrDefault(fqn, defaultValue);
public <T extends LatticeAbstractState<T>> T extractValueOrDefault(
JvmAbstractState<T> jvmState, T defaultValue) {
return jvmState.getStaticOrDefault(fqn, defaultValue);
}

// implementations for Object
Expand Down
6 changes: 6 additions & 0 deletions docs/md/releasenotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
- Move classes related to `Model` to the `proguard.evaluation.value.object.model` package.
- `StringSharer` now uses a string pool to share strings, instead of traversing references.

### API changes for the dataflow analysis code
There are several changes to the dataflow analysis code with the objective of eliminating unnecessary abstraction and
make its usage easier. This includes:
- Remove `MemoryLocation`, use `JvmMemoryLocation` instead.
- Make `JvmMemoryLocation` independent of the type of value contained in the analysis' state. The type of the value now needs only to be provided when calling `extractValueOrDefault`.

## Version 9.1.6

### Java support
Expand Down

0 comments on commit c728473

Please # to comment.