Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 0 additions & 41 deletions boomerangPDS/src/test/java/test/cases/basic/StartPointTest.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ class OpalControlFlowGraph(method: OpalMethod) extends ControlFlowGraph {

graph.heads.foreach(stmt => {
val headStmt = new OpalStatement(stmt, method)
// exception handlers are heads of the graph, not of the method
val isHandler = headStmt.isCatchStmt || (stmt.isAssignment && stmt.asAssignment.expr.isVar &&
stmt.asAssignment.expr.asVar.isExceptionLocal)
if (!isHandler) {
if (!headStmt.isIdentityStmt) {
startPointCache.add(headStmt)
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,14 @@ object NopTransformer {
val tac = stmtGraph.tac

def addNopStatements(stmtGraph: StmtGraph): StmtGraph = {
// Add a nop statement in the beginning, only for bodies that do not start with the definition
// of this or a parameter (static methods without parameters): the backward analysis steps
// through a statement, e.g. into a callee, only on the edge from its predecessor
// Add a nop statement in the beginning
val nop = Nop(INITIAL_NOP)

var result = stmtGraph
val headStmt = stmtGraph.heads.filter(h => h.pc == 0 || h.pc == -1)
assert(headStmt.size == 1)

val head = headStmt.iterator.next()
val startsWithThisOrParameter = head.isAssignment && head.asAssignment.expr.isVar && {
val expr = head.asAssignment.expr.asVar
expr.isParameterLocal || (head.asAssignment.targetVar.isThisLocal && expr.isThisLocal)
}
if (!startsWithThisOrParameter) {
result = result.insertBefore(nop, head)
}
result = result.insertBefore(nop, headStmt.iterator.next())

var beforeStmtInsert = List.empty[Stmt[TacLocal]]
tac.zipWithIndex.foreach(stmt => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package boomerang.scope.opal
import boomerang.scope.opal.tac.OpalMethod
import boomerang.scope.test.MethodSignature
import boomerang.scope.test.targets.ControlFlowGraphTarget
import boomerang.scope.test.targets.StartPointTarget
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.opalj.br.IntegerType
Expand Down Expand Up @@ -48,36 +47,4 @@ class OpalControlFlowGraphTest {
Assertions.assertTrue(stmt.isReturnStmt)
})
}

@Test
def identityStmtIsTheStartPointAndHandlersAreNot(): Unit = {
val opalSetup = new OpalSetup()
opalSetup.setupOpal(classOf[StartPointTarget].getName)

val signature = new MethodSignature(
classOf[StartPointTarget].getName,
"methodWithHandler",
integerType,
java.util.List.of(integerType)
)
val method = opalSetup.resolveMethod(signature)
val startPoints = OpalMethod.of(method, opalSetup.project.get).getControlFlowGraph.getStartPoints

// the body starts with the definition of this, and the handler with the caught exception
Assertions.assertEquals(1, startPoints.size())
Assertions.assertTrue(startPoints.iterator().next().isIdentityStmt)
}

@Test
def leadingNopOnlyForBodiesWithoutIdentityStmts(): Unit = {
val opalSetup = new OpalSetup()
opalSetup.setupOpal(classOf[StartPointTarget].getName)

val signature = new MethodSignature(classOf[StartPointTarget].getName, "delegate", integerType)
val method = opalSetup.resolveMethod(signature)
val startPoints = OpalMethod.of(method, opalSetup.project.get).getControlFlowGraph.getStartPoints

Assertions.assertEquals(1, startPoints.size())
Assertions.assertEquals("nop", startPoints.iterator().next().toString)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,20 +181,14 @@ private void backPropagateSourceLineTags(ValueBox valueBox, AssignStmt assignStm
* statement, the analysis misses data-flows.
*/
private void addNopStmtToMethods(Body b) {
JNopStmt nopStmt;
// Only bodies that do not start with their identity stmts (static methods without parameters)
// need an initial nop: the backward analysis steps through a statement, e.g. into a callee,
// only on the edge from its predecessor, so a first statement needs one
if (!(b.getUnits().getFirst() instanceof IdentityStmt)) {
nopStmt = new JNopStmt();
for (Unit u : b.getUnits()) {
if (u.getJavaSourceStartLineNumber() > 0) {
nopStmt.addAllTagsOf(u);
break;
}
JNopStmt nopStmt = new JNopStmt();
for (Unit u : b.getUnits()) {
if (u.getJavaSourceStartLineNumber() > 0) {
nopStmt.addAllTagsOf(u);
break;
}
b.getUnits().insertBefore(nopStmt, b.getUnits().getFirst());
}
b.getUnits().insertBefore(nopStmt, b.getUnits().getFirst());
Set<IfStmt> ifStmts = new LinkedHashSet<>();
for (Unit u : b.getUnits()) {
if (u instanceof IfStmt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.List;
import soot.Unit;
import soot.UnitPatchingChain;
import soot.jimple.CaughtExceptionRef;
import soot.jimple.IdentityStmt;
import soot.jimple.Stmt;
import soot.toolkits.graph.BriefUnitGraph;
Expand Down Expand Up @@ -57,9 +56,8 @@ protected void buildCache() {
cacheBuild = true;
List<Unit> heads = graph.getHeads();
for (Unit u : heads) {
// exception handlers ($stack14 := @caughtexception) are heads of the graph, not of the method
if (u instanceof IdentityStmt
&& ((IdentityStmt) u).getRightOp() instanceof CaughtExceptionRef) {
// We add a nop statement to the body and ignore IdentityStmt ($stack14 := @caughtexception)
if (u instanceof IdentityStmt) {
continue;
}
Statement stmt = JimpleStatement.create((Stmt) u, method);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,14 @@
import boomerang.scope.soot.jimple.JimpleWrappedClass;
import boomerang.scope.test.MethodSignature;
import boomerang.scope.test.targets.ScopeTarget;
import boomerang.scope.test.targets.StartPointTarget;
import java.util.Collection;
import java.util.List;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import soot.Body;
import soot.Scene;
import soot.SootClass;
import soot.SootFieldRef;
import soot.SootMethod;
import soot.SootMethodRef;
import soot.Unit;
import soot.Value;
import soot.jimple.IdentityStmt;
import soot.jimple.NopStmt;
import soot.jimple.Stmt;

public class SootScopeTest {
Expand Down Expand Up @@ -114,47 +107,4 @@ public void testFactoryAndConverter() {
Assertions.assertTrue(checkedType);
Assertions.assertTrue(checkedVal);
}

@Test
public void identityStmtIsTheStartPointAndHandlersAreNot() {
SootSetup sootSetup = new SootSetup();
sootSetup.setupSoot(StartPointTarget.class.getName());

MethodSignature signature =
new MethodSignature(
StartPointTarget.class.getName(), "methodWithHandler", "int", List.of("int"));
SootMethod method = sootSetup.resolveMethod(signature);
method.retrieveActiveBody();
JimpleMethod jimpleMethod = SootScopeConverter.createJimpleMethod(method, Scene.v());

// the body starts with this := @this, and the handler starts with $e := @caughtexception
Collection<Statement> startPoints = jimpleMethod.getControlFlowGraph().getStartPoints();
Assertions.assertEquals(1, startPoints.size());
Assertions.assertEquals(
method.getActiveBody().getUnits().getFirst(),
SootScopeConverter.extractSootStatement(startPoints.iterator().next()));
}

@Test
public void leadingNopOnlyForBodiesWithoutIdentityStmts() {
SootSetup sootSetup = new SootSetup();
sootSetup.setupSoot(StartPointTarget.class.getName());

SootMethod instanceMethod =
sootSetup.resolveMethod(
new MethodSignature(
StartPointTarget.class.getName(), "methodWithHandler", "int", List.of("int")));
Assertions.assertInstanceOf(IdentityStmt.class, firstUnitAfterPretransformer(instanceMethod));

SootMethod staticMethod =
sootSetup.resolveMethod(
new MethodSignature(StartPointTarget.class.getName(), "delegate", "int"));
Assertions.assertInstanceOf(NopStmt.class, firstUnitAfterPretransformer(staticMethod));
}

private static Unit firstUnitAfterPretransformer(SootMethod method) {
Body body = method.retrieveActiveBody();
BoomerangPretransformer.v().transform(body);
return body.getUnits().getFirst();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.stream.Collectors;
import org.jspecify.annotations.NonNull;
import sootup.core.graph.MutableControlFlowGraph;
import sootup.core.interceptor.BodyInterceptor;
import sootup.core.jimple.Jimple;
import sootup.core.jimple.basic.*;
import sootup.core.jimple.common.Immediate;
Expand All @@ -40,6 +39,7 @@
import sootup.core.model.SootClass;
import sootup.core.model.SootField;
import sootup.core.signatures.FieldSignature;
import sootup.core.interceptor.BodyInterceptor;
import sootup.core.types.ClassType;
import sootup.core.types.ReferenceType;
import sootup.core.views.View;
Expand Down Expand Up @@ -74,14 +74,10 @@ public void interceptBody(Body.@NonNull BodyBuilder bodyBuilder, @NonNull View v
}

private void addNopStatementsToMethod(Body.BodyBuilder body) {
// Initial nop statement, only for bodies that do not start with their identity stmts (static
// methods without parameters): the backward analysis steps through a statement, e.g. into a
// callee, only on the edge from its predecessor, so a first statement needs one
// Initial nop statement
JNopStmt initialNop = Jimple.newNopStmt(StmtPositionInfo.getNoStmtPositionInfo());
MutableControlFlowGraph stmtGraph = body.getControlFlowGraph();
if (!(stmtGraph.getStartingStmt() instanceof JIdentityStmt)) {
JNopStmt initialNop = Jimple.newNopStmt(StmtPositionInfo.getNoStmtPositionInfo());
stmtGraph.insertBefore(stmtGraph.getStartingStmt(), initialNop);
}
stmtGraph.insertBefore(stmtGraph.getStartingStmt(), initialNop);

// Collect if-statements
Collection<JIfStmt> ifStatements =
Expand Down Expand Up @@ -313,9 +309,7 @@ private void addNullifiedFields(Body.BodyBuilder bodyBuilder, View view) {

Optional<Stmt> firstNonIdentityStmt = findFirstNonIdentityStmt(bodyBuilder);
if (firstNonIdentityStmt.isPresent()) {
bodyBuilder
.getControlFlowGraph()
.insertBefore(firstNonIdentityStmt.get(), nullifiedFieldStmt);
bodyBuilder.getControlFlowGraph().insertBefore(firstNonIdentityStmt.get(), nullifiedFieldStmt);
} else {
bodyBuilder.getControlFlowGraph().addNode(nullifiedFieldStmt);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
import sootup.core.jimple.common.ref.JCaughtExceptionRef;
import sootup.core.jimple.common.stmt.JIdentityStmt;
import sootup.core.jimple.common.stmt.Stmt;

Expand Down Expand Up @@ -80,9 +79,7 @@ public void buildCache() {

Collection<Stmt> heads = graph.getEntrypoints();
for (Stmt head : heads) {
// exception handlers are entry points of the graph, not of the method
if (head instanceof JIdentityStmt
&& ((JIdentityStmt) head).getRightOp() instanceof JCaughtExceptionRef) {
if (head instanceof JIdentityStmt) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,10 @@
import boomerang.scope.sootup.jimple.JimpleUpPhantomMethod;
import boomerang.scope.sootup.jimple.JimpleUpWrappedClass;
import boomerang.scope.test.targets.ScopeTarget;
import boomerang.scope.test.targets.StartPointTarget;
import java.util.Collection;
import java.util.List;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import sootup.core.jimple.common.Value;
import sootup.core.jimple.common.stmt.JIdentityStmt;
import sootup.core.jimple.common.stmt.JNopStmt;
import sootup.core.jimple.common.stmt.Stmt;
import sootup.core.model.Body;
import sootup.core.signatures.FieldSignature;
import sootup.core.signatures.MethodSignature;
import sootup.core.types.ClassType;
Expand Down Expand Up @@ -114,50 +108,4 @@ public void testFactoryAndConverter() {
Assertions.assertTrue(checkedType);
Assertions.assertTrue(checkedVal);
}

@Test
public void identityStmtIsTheStartPointAndHandlersAreNot() {
SootUpSetup sootUpSetup = new SootUpSetup();
sootUpSetup.setupSootUp(StartPointTarget.class.getName());

boomerang.scope.test.MethodSignature signature =
new boomerang.scope.test.MethodSignature(
StartPointTarget.class.getName(), "methodWithHandler", "int", List.of("int"));
JavaSootMethod method = sootUpSetup.resolveMethod(signature);
JimpleUpMethod jimpleMethod =
SootUpScopeConverter.createJimpleUpMethod(method, sootUpSetup.getJavaView());

// the body starts with this := @this, and the handler starts with $e := @caughtexception
Collection<Statement> startPoints = jimpleMethod.getControlFlowGraph().getStartPoints();
Assertions.assertEquals(1, startPoints.size());
Assertions.assertEquals(
method.getBody().getControlFlowGraph().getStartingStmt(),
SootUpScopeConverter.extractSootUpStatement(startPoints.iterator().next()));
}

@Test
public void leadingNopOnlyForBodiesWithoutIdentityStmts() {
SootUpSetup sootUpSetup = new SootUpSetup();
sootUpSetup.setupSootUp(StartPointTarget.class.getName());
JavaView view = sootUpSetup.getJavaView();

JavaSootMethod instanceMethod =
sootUpSetup.resolveMethod(
new boomerang.scope.test.MethodSignature(
StartPointTarget.class.getName(), "methodWithHandler", "int", List.of("int")));
Assertions.assertInstanceOf(
JIdentityStmt.class, firstStmtAfterPreInterceptor(instanceMethod, view));

JavaSootMethod staticMethod =
sootUpSetup.resolveMethod(
new boomerang.scope.test.MethodSignature(
StartPointTarget.class.getName(), "delegate", "int"));
Assertions.assertInstanceOf(JNopStmt.class, firstStmtAfterPreInterceptor(staticMethod, view));
}

private static Stmt firstStmtAfterPreInterceptor(JavaSootMethod method, JavaView view) {
Body.BodyBuilder builder = Body.builder(method.getBody(), method.getModifiers());
new BoomerangPreInterceptor().interceptBody(builder, view);
return builder.getControlFlowGraph().getStartingStmt();
}
}
Loading
Loading