HashMap map = new HashMap();
HashSet size_added = new HashSet();
- public boolean implementsGladiator(SootClass c) { return c.implementsInterface("org.ibex.arenaj.Gladiator"); }
- public SootField getSliceForField(SootField f) { return getSliceForField(f.makeRef()); }
- public SootField getSliceForField(SootFieldRef f) {
- SootClass c = f.declaringClass();
- SootClass oc = Scene.v().getSootClass(c.getName().substring(0, c.getName().lastIndexOf('$')));
- String sig = f.declaringClass().getName()+"."+f.name();
- if (map.get(sig) != null) return (SootField)map.get(sig);
- Type t = f.type();
- if (t instanceof RefType && implementsGladiator(((RefType)t).getSootClass())) t = IntType.v();
- SootField nf = new SootField(c.getShortName().substring(c.getShortName().lastIndexOf('$')+1) + "$" + f.name(),
- t.makeArrayType(),
- 0);
- oc.addField(nf);
-
- Body body = getInitBody(oc);
- Expr newArr = Jimple.v().newNewArrayExpr(t, IntConstant.v(initialSize));
- Local newArrLocal = Jimple.v().newLocal("tmpRef" + (tfr++), f.type().makeArrayType());
- body.getLocals().add(newArrLocal);
- InstanceFieldRef ifr = Jimple.v().newInstanceFieldRef(body.getThisLocal(), nf.makeRef());
- body.getUnits().addFirst(Jimple.v().newAssignStmt(ifr, newArrLocal));
- body.getUnits().addFirst(Jimple.v().newAssignStmt(newArrLocal, newArr));
-
- map.put(sig, nf);
- return nf;
- }
-
- public Body getInitBody(SootClass c) {
- c.setApplicationClass();
- List list = new LinkedList();
- SootMethod m = c.getMethod("<init>", list);
- if (!m.hasActiveBody()) {
- JimpleBody b = (JimpleBody)Jimple.v().newBody(m);
- m.setActiveBody(b);
- }
- return m.getActiveBody();
- }
-
- public boolean implementsGladiator(Type t) { return (t instanceof RefType)&&implementsGladiator(((RefType)t).getSootClass()); }
public void internalTransform(String phaseName, Map options) {
System.out.println("begun");
SootClass sc = (SootClass)it.next();
if (implementsGladiator(sc)) {
System.out.println(" application class: " + sc.getName());
- System.out.println(" application class: " + getParent(sc).getName());
+ System.out.println(" application class: " + getArenaForGladiator(sc).getName());
sc.setApplicationClass();
- getParent(sc).setApplicationClass();
+ getArenaForGladiator(sc).setApplicationClass();
ac.add(sc);
- ac.add(getParent(sc));
+ ac.add(getArenaForGladiator(sc));
for(Iterator i2 = sc.getMethods().iterator(); i2.hasNext();) {
SootMethod m = (SootMethod)i2.next();
if (m.isConcrete()) m.retrieveActiveBody();
}
- for(Iterator i2 = getParent(sc).getMethods().iterator(); i2.hasNext();) {
+ for(Iterator i2 = getArenaForGladiator(sc).getMethods().iterator(); i2.hasNext();) {
SootMethod m = (SootMethod)i2.next();
if (m.isConcrete()) m.retrieveActiveBody();
}
}
}
- public SootClass getParent(SootClass sc) {
- return Scene.v().getSootClass(sc.getName().substring(0, sc.getName().lastIndexOf('$')));
- }
-
- public static InstanceFieldRef newIFR(Body body, SootFieldRef fr) {
- return Jimple.v().newInstanceFieldRef(body.getThisLocal(), fr);
+ boolean implementsGladiator(SootClass c) { return c.implementsInterface("org.ibex.arenaj.Gladiator"); }
+ boolean implementsGladiator(Type t) {return (t instanceof RefType)&&implementsGladiator(((RefType)t).getSootClass());}
+ String getArenaName(SootClass sc) { return sc.getName().substring(0, sc.getName().lastIndexOf('$')); }
+ String getGladiatorName(SootClass sc) { return sc.getName().substring(sc.getName().lastIndexOf('$')+1); }
+ SootClass getArenaForGladiator(SootClass sc) { return Scene.v().getSootClass(getArenaName(sc)); }
+ InstanceFieldRef newIFR(Body b, SootFieldRef fr) { return Jimple.v().newInstanceFieldRef(b.getThisLocal(), fr); }
+ void assign(Body b, Value left, Value right) { b.getUnits().add(Jimple.v().newAssignStmt(left, right)); }
+ void assign(Body b, Value l, Value r, Stmt w) { b.getUnits().insertBefore(Jimple.v().newAssignStmt(l, r), w); }
+ Type getSliceElementType(Type t) { return implementsGladiator(t) ? IntType.v() : t; }
+ SootFieldRef getSliceForField(SootField f) { return getSliceForField(f.makeRef()); }
+ SootFieldRef getSliceForField(SootFieldRef f) {
+ return Scene.v().makeFieldRef(getArenaForGladiator(f.declaringClass()),
+ getGladiatorName(f.declaringClass())+"$$"+f.name(),
+ getSliceElementType(f.type()).makeArrayType(),
+ false);
}
public Type objectType;
true);
}
- public static void assign(Body b, Value left, Value right) { b.getUnits().add(Jimple.v().newAssignStmt(left, right)); }
- public static void assign(Body b, Value left, Value right, Stmt where) {
- b.getUnits().insertBefore(Jimple.v().newAssignStmt(left, right), where);
- }
+ //////////////////////////////////////////////////////////////////////////////
public void fixClass(SootClass sc) {
- SootClass mc = getParent(sc);
+ SootClass mc = getArenaForGladiator(sc);
String subname = sc.getShortName().substring(sc.getShortName().lastIndexOf('$')+1);
String incFuncName = subname + "$$inc";
SootMethod method = new SootMethod(incFuncName, new LinkedList(), IntType.v(), Modifier.PRIVATE, new LinkedList());
- Body mcInitBody = getInitBody(mc);
+
+ mc.setApplicationClass();
+ SootMethod initMethod = mc.getMethod("<init>", new LinkedList());
+ if (!initMethod.hasActiveBody()) initMethod.setActiveBody((JimpleBody)Jimple.v().newBody(initMethod));
+ Body mcInitBody = initMethod.getActiveBody();
+
mc.addMethod(method);
Body body = Jimple.v().newBody(method);
method.setActiveBody(body);
assign(body, newIFR(body, maxField.makeRef()), l4);
for(Iterator it = sc.getFields().iterator(); it.hasNext();) {
- SootField f = getSliceForField((SootField)it.next());
+ SootField f = (SootField)it.next();
+ Type t = getSliceElementType(f.getType());
+ mc.addField(f = new SootField(getGladiatorName(sc) + "$$" + f.getName(), t.makeArrayType(), 0));
+
+ Expr newArr = Jimple.v().newNewArrayExpr(t, IntConstant.v(initialSize));
+ Local newArrLocal = newLocal(mcInitBody, f.getType());
+ mcInitBody.getUnits().addFirst(Jimple.v().newAssignStmt(newIFR(mcInitBody, f.makeRef()), newArrLocal));
+ mcInitBody.getUnits().addFirst(Jimple.v().newAssignStmt(newArrLocal, newArr));
+
Local ll0 = newLocal(body, f.getType());
- assign(body, ll0, newIFR(body, f.makeRef()));
Local ll = newLocal(body, f.getType());
- assign(body, ll, Jimple.v().newNewArrayExpr(((ArrayType)f.getType()).getElementType(), l4));
+ assign(body, ll0, newIFR(body, f.makeRef()));
+ assign(body, ll, Jimple.v().newNewArrayExpr(t, l4));
+
List args = new LinkedList();
args.add(ll0);
args.add(IntConstant.v(0));
args.add(IntConstant.v(0));
args.add(l3);
body.getUnits().add(Jimple.v().newInvokeStmt(Jimple.v().newStaticInvokeExpr(arrayCopy, args)));
- body.getUnits().add(Jimple.v().newAssignStmt(newIFR(body, f.makeRef()), ll));
+ assign(body, newIFR(body, f.makeRef()), ll);
}
+
for(Iterator it = sc.getMethods().iterator(); it.hasNext();) {
SootMethod m = (SootMethod)it.next();
if (!m.isConcrete()) continue;
list.add(IntType.v());
for(Iterator i = list.iterator(); i.hasNext();) System.out.println(i.next());
SootMethod m2 = new SootMethod(name, list, m.getReturnType());
- getParent(sc).addMethod(m2);
+ getArenaForGladiator(sc).addMethod(m2);
JimpleBody ab = (JimpleBody)Jimple.v().newBody(m2);
ab.importBodyContentsFrom(mbody);
m2.setActiveBody(ab);
- Local loc = Jimple.v().newLocal("tmpRef" + (tfr++), getParent(sc).getType());
+ Local loc = Jimple.v().newLocal("tmpRef" + (tfr++), getArenaForGladiator(sc).getType());
ab.getLocals().add(loc);
// FIXME: insert assignment to this
Chain units = ab.getUnits();
boolean touched = false;
- Local loc0 = Jimple.v().newLocal("tmpRef" + (tfr++), getParent(sc).getType());
+ Local loc0 = Jimple.v().newLocal("tmpRef" + (tfr++), getArenaForGladiator(sc).getType());
ab.getLocals().add(loc0);
for(Iterator stmtIt = units.snapshotIterator(); stmtIt.hasNext();) {
Stmt s = (Stmt) stmtIt.next();
left.setType(IntType.v());
is.getRightOpBox().setValue(Jimple.v().newParameterRef(IntType.v(), m.getParameterCount()));
if (!touched) {
- units.addFirst(Jimple.v().newIdentityStmt(loc0, Jimple.v().newThisRef(getParent(sc).getType())));
+ units.addFirst(Jimple.v().newIdentityStmt(loc0, Jimple.v().newThisRef(getArenaForGladiator(sc).getType())));
touched = true;
}
}
NewExpr ne = (NewExpr)v;
if (implementsGladiator(ne.getBaseType())) {
SootClass sc = ((RefType)ne.getBaseType()).getSootClass();
- SootClass mc = getParent(sc);
+ SootClass mc = getArenaForGladiator(sc);
String incFuncName = sc.getShortName().substring(sc.getShortName().lastIndexOf('$')+1) + "$$inc";
SootMethodRef smr = Scene.v().makeMethodRef(mc, incFuncName, new LinkedList(), IntType.v(), false);
Expr invokeExpr = Jimple.v().newSpecialInvokeExpr(body.getThisLocal(), smr);
li.add(viaLocal(iie.getBase(),body,s));
SootClass sc = mr.declaringClass();
name = sc.getShortName().substring(sc.getShortName().lastIndexOf('$')+1) + "$$" + name;
- mr = Scene.v().makeMethodRef(getParent(sc),
+ mr = Scene.v().makeMethodRef(getArenaForGladiator(sc),
name,
pl,
implementsGladiator(mr.returnType()) ? IntType.v() : mr.returnType(),
} else if (v instanceof CastExpr) {
CastExpr ce = (CastExpr)v;
if (implementsGladiator(ce.getCastType())) {
- SootClass mc = getParent(((RefType)ce.getCastType()).getSootClass());
+ SootClass mc = getArenaForGladiator(((RefType)ce.getCastType()).getSootClass());
SootClass ic = Scene.v().getSootClass("java.lang.Integer");
ce.setCastType(ic.getType());
vb.setValue(body.getThisLocal());
System.out.println("s is " + s);
} else if (implementsGladiator(fr.declaringClass())) {
- SootClass mc = getParent(fr.declaringClass());
- SootFieldRef sf = getSliceForField(fr).makeRef();
- InstanceFieldRef sfr = newIFR(body, sf);
+ SootClass mc = getArenaForGladiator(fr.declaringClass());
+ InstanceFieldRef sfr = newIFR(body, getSliceForField(fr));
vb.setValue(Jimple.v().newArrayRef(viaLocal(sfr, body, s), ifr.getBase()));
}
if ((t instanceof RefType) && implementsGladiator(((RefType)t).getSootClass())) {
SootClass tc = ((RefType)t).getSootClass();
- SootClass mc = getParent(tc);
+ SootClass mc = getArenaForGladiator(tc);
ifr.setFieldRef(Scene.v().makeFieldRef(mc, fr.name(), IntType.v(), false));
}
}