Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streamify RTA #1166

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import sootup.core.model.SootMethod;
import sootup.core.signatures.MethodSignature;
import sootup.core.types.ClassType;
import sootup.core.util.StreamUtils;
import sootup.core.views.View;

/**
Expand Down Expand Up @@ -88,24 +89,16 @@ public CallGraph initialize(@Nonnull List<MethodSignature> entryPoints) {
*
* @param method this object contains the method body which is inspected.
*/
protected List<ClassType> collectInstantiatedClassesInMethod(SootMethod method) {
if (method == null || method.isAbstract() || method.isNative()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should keep isAbstract() and isNative() as they have no 'Body'

return Collections.emptyList();
}

protected Stream<ClassType> collectInstantiatedClassesInMethod(SootMethod method) {
Set<ClassType> instantiated =
method.getBody().getStmts().stream()
.filter(stmt -> stmt instanceof JAssignStmt)
.map(stmt -> ((JAssignStmt) stmt).getRightOp())
.filter(value -> value instanceof JNewExpr)
.map(value -> ((JNewExpr) value).getType())
.collect(Collectors.toSet());
List<ClassType> newInstantiatedClassTypes =
instantiated.stream()
.filter(classType -> !instantiatedClasses.contains(classType))
.collect(Collectors.toList());
instantiatedClasses.addAll(instantiated);
return newInstantiatedClassTypes;
return instantiated.stream().filter(classType -> !instantiatedClasses.contains(classType));
}

/**
Expand Down Expand Up @@ -223,17 +216,10 @@ protected void preProcessingMethod(
MethodSignature sourceMethod,
@Nonnull Deque<MethodSignature> workList,
@Nonnull MutableCallGraph cg) {
SootMethod method =
view.getClass(sourceMethod.getDeclClassType())
.flatMap(c -> c.getMethod(sourceMethod.getSubSignature()))
.orElse(null);
if (method == null) {
return;
}

List<ClassType> newInstantiatedClasses = collectInstantiatedClassesInMethod(method);
newInstantiatedClasses.forEach(
classType -> includeIgnoredCallsToClass(classType, cg, workList));
StreamUtils.optionalToStream(view.getMethod(sourceMethod))
.filter(SootMethod::isConcrete)
.flatMap(this::collectInstantiatedClassesInMethod)
.forEach(classType -> includeIgnoredCallsToClass(classType, cg, workList));
}

/**
Expand All @@ -250,17 +236,15 @@ protected void includeIgnoredCallsToClass(
if (newEdges != null) {
newEdges.forEach(
call -> {
MethodSignature concreteTarget =
resolveConcreteDispatch(view, call.getTargetMethodSignature()).orElse(null);
if (concreteTarget == null) {
return;
}
addCallToCG(
call.getSourceMethodSignature(),
concreteTarget,
call.getInvokableStmt(),
cg,
workList);
resolveConcreteDispatch(view, call.getTargetMethodSignature())
.ifPresent(
concreteTarget ->
addCallToCG(
call.getSourceMethodSignature(),
concreteTarget,
call.getInvokableStmt(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
call.getInvokableStmt(),
call.getInvokableStmt().asInvokableStmt(),

and then we could make the respective Parameter of addCallToCG more precise as well

cg,
workList));
});
// can be removed because the instantiated class will be considered in future resolves
ignoredCalls.remove(classType);
Expand Down
Loading