From f27d29473e7a18148dc671a2dd20623b9c891f5c Mon Sep 17 00:00:00 2001 From: Tian Tan Date: Sun, 5 Nov 2023 14:48:51 +0800 Subject: [PATCH] No longer have CSMethod implements the Indexable interface --- .../analysis/pta/core/cs/CSCallGraph.java | 2 - .../pta/core/cs/element/CSManager.java | 5 --- .../pta/core/cs/element/CSMethod.java | 13 +----- .../core/cs/element/MapBasedCSManager.java | 45 ++----------------- 4 files changed, 6 insertions(+), 59 deletions(-) diff --git a/src/main/java/pascal/taie/analysis/pta/core/cs/CSCallGraph.java b/src/main/java/pascal/taie/analysis/pta/core/cs/CSCallGraph.java index ef9e12ae2..f6b7b0667 100644 --- a/src/main/java/pascal/taie/analysis/pta/core/cs/CSCallGraph.java +++ b/src/main/java/pascal/taie/analysis/pta/core/cs/CSCallGraph.java @@ -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; @@ -49,7 +48,6 @@ public class CSCallGraph extends AbstractCallGraph { public CSCallGraph(CSManager csManager) { this.csManager = csManager; - this.reachableMethods = new IndexerBitSet<>(csManager.getMethodIndexer(), false); } /** diff --git a/src/main/java/pascal/taie/analysis/pta/core/cs/element/CSManager.java b/src/main/java/pascal/taie/analysis/pta/core/cs/element/CSManager.java index f7a6506eb..e02141ced 100644 --- a/src/main/java/pascal/taie/analysis/pta/core/cs/element/CSManager.java +++ b/src/main/java/pascal/taie/analysis/pta/core/cs/element/CSManager.java @@ -124,9 +124,4 @@ public interface CSManager { * The indexer is useful for creating efficient points-to sets. */ Indexer getObjectIndexer(); - - /** - * @return {@link Indexer} for {@link CSMethod} maintained by this manager. - */ - Indexer getMethodIndexer(); } diff --git a/src/main/java/pascal/taie/analysis/pta/core/cs/element/CSMethod.java b/src/main/java/pascal/taie/analysis/pta/core/cs/element/CSMethod.java index 6db59d682..e605d1087 100644 --- a/src/main/java/pascal/taie/analysis/pta/core/cs/element/CSMethod.java +++ b/src/main/java/pascal/taie/analysis/pta/core/cs/element/CSMethod.java @@ -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; @@ -39,12 +38,10 @@ /** * 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. */ @@ -52,10 +49,9 @@ public class CSMethod extends AbstractCSElement implements Indexable { 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; } /** @@ -82,11 +78,6 @@ public Optional getResult(String id) { return Optional.ofNullable(resultHolder.getResult(id)); } - @Override - public int getIndex() { - return index; - } - @Override public String toString() { return context + ":" + method; diff --git a/src/main/java/pascal/taie/analysis/pta/core/cs/element/MapBasedCSManager.java b/src/main/java/pascal/taie/analysis/pta/core/cs/element/MapBasedCSManager.java index 976b803e3..b8e304fa7 100644 --- a/src/main/java/pascal/taie/analysis/pta/core/cs/element/MapBasedCSManager.java +++ b/src/main/java/pascal/taie/analysis/pta/core/cs/element/MapBasedCSManager.java @@ -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; @@ -56,10 +54,10 @@ public class MapBasedCSManager implements CSManager { private final CSObjManager objManager = new CSObjManager(); - private final CSMethodManager mtdManager = new CSMethodManager(); - private final TwoKeyMap callSites = Maps.newTwoKeyMap(); + private final TwoKeyMap methods = Maps.newTwoKeyMap(); + @Override public CSVar getCSVar(Context context, Var var) { return ptrManager.getCSVar(context, var); @@ -138,19 +136,14 @@ public Indexer 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 getMethodIndexer() { - return mtdManager; + return methods.computeIfAbsent(method, context, CSMethod::new); } private static class PointerManager { @@ -316,34 +309,4 @@ public CSObj getObject(int index) { return objs[index]; } } - - private static class CSMethodManager implements Indexer { - - private final TwoKeyMap methodMap = Maps.newTwoKeyMap(); - - /** - * Counter for assigning unique indexes to CSMethods. - */ - private int counter = 0; - - private final List 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); - } - } }