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

[code improve] No more views passing around #1158

Closed
wants to merge 2 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,12 @@ protected AbstractCallGraphAlgorithm(@Nonnull View view) {
* This method starts the construction of the call graph algorithm. It initializes the needed
* objects for the call graph generation and calls processWorkList method.
*
* @param view the view contains all needed class files.
* @param entryPoints a list of method signatures that will be added to the work list in the call
* graph generation.
* @return the complete constructed call graph starting from the entry methods.
*/
@Nonnull
final CallGraph constructCompleteCallGraph(View view, List<MethodSignature> entryPoints) {
final CallGraph constructCompleteCallGraph(List<MethodSignature> entryPoints) {
Deque<MethodSignature> workList = new ArrayDeque<>(entryPoints);
Set<MethodSignature> processed = new HashSet<>();

Expand All @@ -83,7 +82,7 @@ final CallGraph constructCompleteCallGraph(View view, List<MethodSignature> entr
workList.addAll(clinits);
MutableCallGraph cg = initializeCallGraph(entryPoints, clinits);

processWorkList(view, workList, processed, cg);
processWorkList(workList, processed, cg);
return cg;
}

Expand Down Expand Up @@ -124,21 +123,17 @@ private Optional<MethodSignature> getSignatureOfImplementedStaticInitializer(

/**
* Processes all entries in the <code>workList</code>, skipping those present in <code>processed
* </code>, adding call edges to the graph. Newly discovered methods are added to the <code>
* workList</code> and processed as well. <code>cg</code> is updated accordingly. The method
* </code>, adding call edges to the graph. Newly discovered methods are added to the <code>
* workList</code> and processed as well. <code>cg</code> is updated accordingly. The method
* postProcessingMethod is called after a method is processed in the <code>workList</code>.
*
* @param view it contains the classes.
* @param workList it contains all method that have to be processed in the call graph generation.
* This list is filled in the execution with found call targets in the call graph algorithm.
* @param processed the list of processed method to only process the method once.
* @param cg the call graph object that is filled with the found methods and call edges.
*/
final void processWorkList(
View view,
Deque<MethodSignature> workList,
Set<MethodSignature> processed,
MutableCallGraph cg) {
Deque<MethodSignature> workList, Set<MethodSignature> processed, MutableCallGraph cg) {
while (!workList.isEmpty()) {
MethodSignature currentMethodSignature = workList.pop();
// skip if already processed
Expand All @@ -154,7 +149,7 @@ final void processWorkList(
}

// perform pre-processing if needed
preProcessingMethod(view, currentMethodSignature, workList, cg);
preProcessingMethod(currentMethodSignature, workList, cg);

// process the method
if (!cg.containsMethod(currentMethodSignature)) {
Expand All @@ -175,7 +170,7 @@ final void processWorkList(
processed.add(currentMethodSignature);

// perform post-processing if needed
postProcessingMethod(view, currentMethodSignature, workList, cg);
postProcessingMethod(currentMethodSignature, workList, cg);
}
}

Expand Down Expand Up @@ -351,27 +346,23 @@ private void addStaticInitializerCalls(
/**
* This method enables optional pre-processing of a method in the call graph algorithm
*
* @param view view
* @param sourceMethod the processed method
* @param workList the current work list that might be extended
* @param cg the current cg that might be extended
*/
protected abstract void preProcessingMethod(
View view,
MethodSignature sourceMethod,
@Nonnull Deque<MethodSignature> workList,
@Nonnull MutableCallGraph cg);

/**
* This method enables optional post-processing of a method in the call graph algorithm
*
* @param view it contains classes and the type hierarchy.
* @param sourceMethod the processed method
* @param workList the current work list that might be extended
* @param cg the current cg that might be extended
*/
protected abstract void postProcessingMethod(
View view,
MethodSignature sourceMethod,
@Nonnull Deque<MethodSignature> workList,
@Nonnull MutableCallGraph cg);
Expand All @@ -397,7 +388,7 @@ public CallGraph addClass(@Nonnull CallGraph oldCallGraph, @Nonnull ClassType cl
// Step 1: Add edges from the new methods to other methods
Deque<MethodSignature> workList = new ArrayDeque<>(newMethodSignatures);
Set<MethodSignature> processed = new HashSet<>(oldCallGraph.getMethodSignatures());
processWorkList(view, workList, processed, updated);
processWorkList(workList, processed, updated);

// Step 2: Add edges from old methods to methods overridden in the new class
Stream<ClassType> superClasses = view.getTypeHierarchy().superClassesOf(classType);
Expand Down Expand Up @@ -445,10 +436,9 @@ public CallGraph addClass(@Nonnull CallGraph oldCallGraph, @Nonnull ClassType cl
* <p>The method throws an exception if there is no main method in any of the classes or if there
* are more than one main method.
*
* @param view to get the view specific main method.
* @return - MethodSignature of main method.
*/
public MethodSignature findMainMethod(View view) {
public MethodSignature findMainMethod() {
Collection<SootMethod> mainMethods =
view.getClasses()
.filter(aClass -> !aClass.isLibraryClass())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ public ClassHierarchyAnalysisAlgorithm(@Nonnull View view) {
@Nonnull
@Override
public CallGraph initialize() {
return constructCompleteCallGraph(view, Collections.singletonList(findMainMethod(view)));
return constructCompleteCallGraph(Collections.singletonList(findMainMethod()));
}

@Nonnull
@Override
public CallGraph initialize(@Nonnull List<MethodSignature> entryPoints) {
return constructCompleteCallGraph(view, entryPoints);
return constructCompleteCallGraph(entryPoints);
}

/**
Expand Down Expand Up @@ -162,7 +162,6 @@ private List<MethodSignature> resolveAllCallTargets(

@Override
protected void postProcessingMethod(
View view,
MethodSignature sourceMethod,
@Nonnull Deque<MethodSignature> workList,
@Nonnull MutableCallGraph cg) {
Expand All @@ -171,7 +170,6 @@ protected void postProcessingMethod(

@Override
protected void preProcessingMethod(
View view,
MethodSignature sourceMethod,
@Nonnull Deque<MethodSignature> workList,
@Nonnull MutableCallGraph cg) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public RapidTypeAnalysisAlgorithm(@Nonnull View view) {
@Nonnull
@Override
public CallGraph initialize() {
List<MethodSignature> entryPoints = Collections.singletonList(findMainMethod(view));
List<MethodSignature> entryPoints = Collections.singletonList(findMainMethod());
return initialize(entryPoints);
}

Expand All @@ -74,7 +74,7 @@ public CallGraph initialize(@Nonnull List<MethodSignature> entryPoints) {
instantiatedClasses = new HashSet<>();
ignoredCalls = new HashMap<>();

CallGraph cg = constructCompleteCallGraph(view, entryPoints);
CallGraph cg = constructCompleteCallGraph(entryPoints);

// delete the data structures
instantiatedClasses = Collections.emptySet();
Expand Down Expand Up @@ -214,14 +214,12 @@ private void saveIgnoredCall(
* sourceMethod. If a new instantiated class has previously ignored calls to this class, they are
* added to call graph
*
* @param view view
* @param sourceMethod the processed method
* @param workList the current work list
* @param cg the current cg
*/
@Override
protected void preProcessingMethod(
View view,
MethodSignature sourceMethod,
@Nonnull Deque<MethodSignature> workList,
@Nonnull MutableCallGraph cg) {
Expand Down Expand Up @@ -272,14 +270,12 @@ protected void includeIgnoredCallsToClass(
/**
* Postprocessing is not needed in RTA
*
* @param view view
* @param sourceMethod the processed method
* @param workList the current worklist that is extended by methods that have to be analyzed.
* @param cg the current cg is extended by new call targets and calls
*/
@Override
protected void postProcessingMethod(
View view,
MethodSignature sourceMethod,
@Nonnull Deque<MethodSignature> workList,
@Nonnull MutableCallGraph cg) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/

import com.google.common.base.Objects;
import com.google.common.base.Suppliers;
import java.util.function.Supplier;
import javax.annotation.Nonnull;
import sootup.core.model.SootClassMember;
import sootup.core.types.ClassType;
Expand Down Expand Up @@ -90,10 +92,13 @@ public int hashCode() {
return hashCode;
}

private final Supplier<String> _cachedToString =
Suppliers.memoize(() -> "<" + getDeclClassType() + ": " + getSubSignature() + '>');

@Override
@Nonnull
public String toString() {
return "<" + declClassSignature + ": " + getSubSignature() + '>';
return _cachedToString.get();
}

@Override
Expand Down
Loading