use of com.jopdesign.common.code.CallString in project jop by jop-devel.
the class LoopBounds method handleNative.
@SuppressWarnings({ "LiteralAsArgToStringEquals" })
private Map<CallString, Map<Location, ValueMapping>> handleNative(MethodInfo method, Context context, Map<CallString, Map<Location, ValueMapping>> input, Map<CallString, Map<Location, ValueMapping>> result) {
String methodId = method.getMemberID().toString();
Map<Location, ValueMapping> in = input.get(context.callString);
Map<Location, ValueMapping> out = new LinkedHashMap<Location, ValueMapping>();
if (methodId.equals("com.jopdesign.sys.Native#rd(I)I") || methodId.equals("com.jopdesign.sys.Native#rdMem(I)I") || methodId.equals("com.jopdesign.sys.Native#rdIntMem(I)I") || methodId.equals("com.jopdesign.sys.Native#getStatic(I)I")) {
for (Location l : in.keySet()) {
if (l.stackLoc < context.stackPtr - 1) {
out.put(l, in.get(l));
}
}
out.put(new Location(context.stackPtr - 1), new ValueMapping());
} else if (methodId.equals("com.jopdesign.sys.Native#wr(II)V") || methodId.equals("com.jopdesign.sys.Native#wrMem(II)V") || methodId.equals("com.jopdesign.sys.Native#wrIntMem(II)V") || methodId.equals("com.jopdesign.sys.Native#putStatic(II)V") || methodId.equals("com.jopdesign.sys.Native#toLong(D)J") || methodId.equals("com.jopdesign.sys.Native#toDouble(J)D")) {
for (Location l : in.keySet()) {
if (l.stackLoc < context.stackPtr - 2) {
out.put(l, in.get(l));
}
}
} else if (methodId.equals("com.jopdesign.sys.Native#toInt(Ljava/lang/Object;)I") || methodId.equals("com.jopdesign.sys.Native#toInt(F)I")) {
for (Location l : in.keySet()) {
if (l.stackLoc < context.stackPtr - 1) {
out.put(l, in.get(l));
}
}
out.put(new Location(context.stackPtr - 1), new ValueMapping());
} else if (methodId.equals("com.jopdesign.sys.Native#toObject(I)Ljava/lang/Object;") || methodId.equals("com.jopdesign.sys.Native#toIntArray(I)[I") || methodId.equals("com.jopdesign.sys.Native#toFloat(I)F")) {
for (Location l : in.keySet()) {
if (l.stackLoc < context.stackPtr - 1) {
out.put(l, in.get(l));
}
}
} else if (methodId.equals("com.jopdesign.sys.Native#getSP()I")) {
for (Location l : in.keySet()) {
if (l.stackLoc < context.stackPtr) {
out.put(l, in.get(l));
}
}
out.put(new Location(context.stackPtr), new ValueMapping());
} else if (methodId.equals("com.jopdesign.sys.Native#toInt(Ljava/lang/Object;)I")) {
for (Location l : in.keySet()) {
if (l.stackLoc < context.stackPtr - 1) {
out.put(l, in.get(l));
}
}
out.put(new Location(context.stackPtr - 1), new ValueMapping());
} else if (methodId.equals("com.jopdesign.sys.Native#condMove(IIZ)I") || methodId.equals("com.jopdesign.sys.Native#condMoveRef(Ljava/lang/Object;Ljava/lang/Object;Z)Ljava/lang/Object;") || methodId.equals("com.jopdesign.sys.Native#memCopy(III)V")) {
for (Location l : in.keySet()) {
if (l.stackLoc < context.stackPtr - 3) {
out.put(l, in.get(l));
}
}
} else if (methodId.equals("com.jopdesign.sys.Native#invalidate()V")) {
for (Location l : in.keySet()) {
if (l.stackLoc < context.stackPtr) {
out.put(l, in.get(l));
}
}
} else if (methodId.equals("com.jopdesign.sys.Native#arrayLength(I)I") || methodId.equals("com.jopdesign.sys.Native#invoke(I)V")) {
for (Location l : in.keySet()) {
if (l.stackLoc < context.stackPtr - 1) {
out.put(l, in.get(l));
}
}
} else if (methodId.equals("com.jopdesign.sys.Native#invoke(II)V")) {
for (Location l : in.keySet()) {
if (l.stackLoc < context.stackPtr - 2) {
out.put(l, in.get(l));
}
}
} else {
AppInfoError ex = new AppInfoError("Unknown native method: " + methodId);
logger.error(ex);
throw ex;
}
result.put(context.callString, out);
return result;
}
use of com.jopdesign.common.code.CallString in project jop by jop-devel.
the class LoopBounds method copyResults.
@Override
public void copyResults(MethodInfo newContainer, Map<InstructionHandle, InstructionHandle> newHandles) {
for (Map.Entry<InstructionHandle, InstructionHandle> entry : newHandles.entrySet()) {
InstructionHandle oldHandle = entry.getKey();
InstructionHandle newHandle = entry.getValue();
if (newHandle == null)
continue;
// TODO support updating the callstrings too
// TODO this does NOT update stackPtr,.. in the new context!
ContextMap<CallString, Pair<ValueMapping, ValueMapping>> value = bounds.get(oldHandle);
if (value != null)
bounds.put(newHandle, value.copy(newContainer));
ContextMap<CallString, Interval> value1 = arrayIndices.get(oldHandle);
if (value1 != null)
arrayIndices.put(newHandle, value1.copy(newContainer));
ContextMap<CallString, Integer> value2 = scopes.get(oldHandle);
if (value2 != null)
scopes.put(newHandle, value2.copy(newContainer));
ContextMap<CallString, Interval[]> value3 = sizes.get(oldHandle);
if (value3 != null)
sizes.put(newHandle, value3.copy(newContainer));
ContextMap<CallString, Set<FlowEdge>> old = infeasibles.get(oldHandle);
if (old != null) {
Map<CallString, Set<FlowEdge>> map = new LinkedHashMap<CallString, Set<FlowEdge>>(old.size());
for (CallString cs : old.keySet()) {
Set<FlowEdge> newSet = new LinkedHashSet<FlowEdge>();
for (FlowEdge edge : old.get(cs)) {
InstructionHandle newHead = newHandles.get(edge.getHead());
InstructionHandle newTail = newHandles.get(edge.getTail());
if (newHead != null && newTail != null) {
Context ctx = new Context(edge.getContext());
ctx.setMethodInfo(newContainer);
newSet.add(new FlowEdge(newTail, newHead, edge.getType(), ctx));
}
}
map.put(cs, newSet);
}
Context c = old.getContext();
c.setMethodInfo(newContainer);
ContextMap<CallString, Set<FlowEdge>> edges = new ContextMap<CallString, Set<FlowEdge>>(c, map);
infeasibles.put(newHandle, edges);
}
}
}
use of com.jopdesign.common.code.CallString in project jop by jop-devel.
the class LoopBounds method getArraySizes.
public Interval[] getArraySizes(InstructionHandle stmt, CallString cs) {
ContextMap<CallString, Interval[]> map = sizes.get(stmt);
Interval[] retval = null;
if (map == null) {
return retval;
}
for (CallString c : map.keySet()) {
if (c.hasSuffix(cs)) {
if (retval == null) {
Interval[] v = map.get(c);
// JDK1.5 compat
retval = new Interval[v.length];
System.arraycopy(v, 0, retval, 0, v.length);
// JDK1.6 only
//retval = Arrays.copyOf(v, v.length);
} else {
Interval[] v = map.get(c);
for (int k = 0; k < v.length; k++) {
retval[k].join(v[k]);
}
}
}
}
return retval;
}
use of com.jopdesign.common.code.CallString in project jop by jop-devel.
the class SymbolicPointsTo method initial.
public ContextMap<CallString, SymbolicAddressMap> initial(InstructionHandle stmt) {
ContextMap<CallString, SymbolicAddressMap> retval = new ContextMap<CallString, SymbolicAddressMap>(new Context(), new HashMap<CallString, SymbolicAddressMap>());
SymbolicAddressMap init = new SymbolicAddressMap(bsFactory);
// Add symbolic stack names
int stackPtr = 0;
if (!entryMethod.isStatic()) {
init.putStack(stackPtr++, bsFactory.singleton(SymbolicAddress.rootAddress("$this")));
}
String[] args = entryMethod.getArgumentNames();
for (int i = 0; i < args.length; i++) {
Type ty = entryMethod.getArgumentType(i);
if (ty instanceof ReferenceType) {
init.putStack(stackPtr, bsFactory.singleton(SymbolicAddress.rootAddress("$" + args[i])));
}
stackPtr += ty.getSize();
}
retval.put(initialCallString, init);
return retval;
}
use of com.jopdesign.common.code.CallString in project jop by jop-devel.
the class SymbolicPointsTo method join.
public ContextMap<CallString, SymbolicAddressMap> join(ContextMap<CallString, SymbolicAddressMap> s1, ContextMap<CallString, SymbolicAddressMap> s2) {
if (s1 == null) {
return new ContextMap<CallString, SymbolicAddressMap>(s2);
}
if (s2 == null) {
return new ContextMap<CallString, SymbolicAddressMap>(s1);
}
// create empty context map, with s1's context
ContextMap<CallString, SymbolicAddressMap> result = new ContextMap<CallString, SymbolicAddressMap>(new Context(s1.getContext()), new HashMap<CallString, SymbolicAddressMap>());
// add both context maps. Note that entries from s2 overwrite those from the s1
result.putAll(s1);
result.putAll(s2);
// a and b are the DF results for the respectively active contexts
SymbolicAddressMap a = s1.get(s1.getContext().callString);
SymbolicAddressMap b = s2.get(s2.getContext().callString);
SymbolicAddressMap merged = a.clone();
merged.join(b);
result.put(s2.getContext().callString, merged);
if (result.getContext().stackPtr < 0) {
result.getContext().stackPtr = s2.getContext().stackPtr;
}
if (result.getContext().syncLevel < 0) {
result.getContext().syncLevel = s2.getContext().syncLevel;
}
result.getContext().threaded = Context.isThreaded();
return result;
}
Aggregations