soot.jimple.toolkits.pointer.FieldRWTagger Maven / Gradle / Ivy
package soot.jimple.toolkits.pointer;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 2003 Ondrej Lhotak
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import soot.Body;
import soot.BodyTransformer;
import soot.G;
import soot.PhaseOptions;
import soot.Scene;
import soot.Singletons;
import soot.jimple.Stmt;
import soot.jimple.toolkits.callgraph.CallGraph;
public class FieldRWTagger extends BodyTransformer {
public FieldRWTagger(Singletons.Global g) {
}
public static FieldRWTagger v() {
return G.v().soot_jimple_toolkits_pointer_FieldRWTagger();
}
public int numRWs = 0;
public int numWRs = 0;
public int numRRs = 0;
public int numWWs = 0;
public int numNatives = 0;
public Date startTime = null;
boolean optionDontTag = false;
boolean optionNaive = false;
private CallGraph cg;
protected class UniqueRWSets {
protected ArrayList l = new ArrayList();
RWSet getUnique(RWSet s) {
if (s == null) {
return s;
}
for (RWSet ret : l) {
if (ret.isEquivTo(s)) {
return ret;
}
}
l.add(s);
return s;
}
Iterator iterator() {
return l.iterator();
}
short indexOf(RWSet s) {
short i = 0;
for (RWSet ret : l) {
if (ret.isEquivTo(s)) {
return i;
}
i++;
}
return -1;
}
}
protected void initializationStuff(String phaseName) {
if (G.v().Union_factory == null) {
G.v().Union_factory = new UnionFactory() {
public Union newUnion() {
return FullObjectSet.v();
}
};
}
if (startTime == null) {
startTime = new Date();
}
cg = Scene.v().getCallGraph();
}
protected Object keyFor(Stmt s) {
if (s.containsInvokeExpr()) {
if (optionNaive) {
throw new RuntimeException("shouldn't get here");
}
Iterator it = cg.edgesOutOf(s);
if (!it.hasNext()) {
return Collections.EMPTY_LIST;
}
ArrayList ret = new ArrayList();
while (it.hasNext()) {
ret.add(it.next());
}
return ret;
} else {
return s;
}
}
protected void internalTransform(Body body, String phaseName, Map options) {
initializationStuff(phaseName);
SideEffectAnalysis sea = new SideEffectAnalysis(DumbPointerAnalysis.v(), Scene.v().getCallGraph());
sea.findNTRWSets(body.getMethod());
HashMap