Skip to content

Commit

Permalink
No longer have CSMethod implements the Indexable interface
Browse files Browse the repository at this point in the history
  • Loading branch information
silverbullettt committed Nov 5, 2023
1 parent 0acacbc commit f27d294
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import pascal.taie.ir.stmt.Stmt;
import pascal.taie.language.classes.JMethod;
import pascal.taie.util.collection.ArraySet;
import pascal.taie.util.collection.IndexerBitSet;
import pascal.taie.util.collection.Views;

import java.util.ArrayList;
Expand All @@ -49,7 +48,6 @@ public class CSCallGraph extends AbstractCallGraph<CSCallSite, CSMethod> {

public CSCallGraph(CSManager csManager) {
this.csManager = csManager;
this.reachableMethods = new IndexerBitSet<>(csManager.getMethodIndexer(), false);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,4 @@ public interface CSManager {
* The indexer is useful for creating efficient points-to sets.
*/
Indexer<CSObj> getObjectIndexer();

/**
* @return {@link Indexer} for {@link CSMethod} maintained by this manager.
*/
Indexer<CSMethod> getMethodIndexer();
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import pascal.taie.analysis.pta.core.cs.context.Context;
import pascal.taie.language.classes.JMethod;
import pascal.taie.util.AbstractResultHolder;
import pascal.taie.util.Indexable;
import pascal.taie.util.ResultHolder;
import pascal.taie.util.collection.ArraySet;

Expand All @@ -39,23 +38,20 @@
/**
* Represents context-sensitive methods.
*/
public class CSMethod extends AbstractCSElement implements Indexable {
public class CSMethod extends AbstractCSElement {

private final JMethod method;

private final int index;

/**
* Call edges to this CS method.
*/
private final ArrayList<Edge<CSCallSite, CSMethod>> edges = new ArrayList<>(4);

private final ResultHolder resultHolder = new AbstractResultHolder() {};

CSMethod(JMethod method, Context context, int index) {
CSMethod(JMethod method, Context context) {
super(context);
this.method = method;
this.index = index;
}

/**
Expand All @@ -82,11 +78,6 @@ public <R> Optional<R> getResult(String id) {
return Optional.ofNullable(resultHolder.getResult(id));
}

@Override
public int getIndex() {
return index;
}

@Override
public String toString() {
return context + ":" + method;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@
import pascal.taie.util.collection.Streams;
import pascal.taie.util.collection.TwoKeyMap;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;
Expand All @@ -56,10 +54,10 @@ public class MapBasedCSManager implements CSManager {

private final CSObjManager objManager = new CSObjManager();

private final CSMethodManager mtdManager = new CSMethodManager();

private final TwoKeyMap<Invoke, Context, CSCallSite> callSites = Maps.newTwoKeyMap();

private final TwoKeyMap<JMethod, Context, CSMethod> methods = Maps.newTwoKeyMap();

@Override
public CSVar getCSVar(Context context, Var var) {
return ptrManager.getCSVar(context, var);
Expand Down Expand Up @@ -138,19 +136,14 @@ public Indexer<CSObj> getObjectIndexer() {
@Override
public CSCallSite getCSCallSite(Context context, Invoke callSite) {
return callSites.computeIfAbsent(callSite, context, (cs, ctx) -> {
CSMethod container = mtdManager.getCSMethod(ctx, cs.getContainer());
CSMethod container = getCSMethod(ctx, cs.getContainer());
return new CSCallSite(cs, ctx, container);
});
}

@Override
public CSMethod getCSMethod(Context context, JMethod method) {
return mtdManager.getCSMethod(context, method);
}

@Override
public Indexer<CSMethod> getMethodIndexer() {
return mtdManager;
return methods.computeIfAbsent(method, context, CSMethod::new);
}

private static class PointerManager {
Expand Down Expand Up @@ -316,34 +309,4 @@ public CSObj getObject(int index) {
return objs[index];
}
}

private static class CSMethodManager implements Indexer<CSMethod> {

private final TwoKeyMap<JMethod, Context, CSMethod> methodMap = Maps.newTwoKeyMap();

/**
* Counter for assigning unique indexes to CSMethods.
*/
private int counter = 0;

private final List<CSMethod> methods = new ArrayList<>(65536);

private CSMethod getCSMethod(Context context, JMethod method) {
return methodMap.computeIfAbsent(method, context, (m, c) -> {
CSMethod csMethod = new CSMethod(m, c, counter++);
methods.add(csMethod);
return csMethod;
});
}

@Override
public int getIndex(CSMethod m) {
return m.getIndex();
}

@Override
public CSMethod getObject(int index) {
return methods.get(index);
}
}
}

0 comments on commit f27d294

Please sign in to comment.