use of org.apache.bcel.generic.InstructionHandle in project jop by jop-devel.
the class CallStringReceiverTypes 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;
ContextMap<CallString, Set<String>> value = targets.get(oldHandle);
// TODO this does NOT update stackPtr,.. in the new context!
if (value != null)
targets.put(newHandle, value.copy(newContainer));
}
}
use of org.apache.bcel.generic.InstructionHandle in project jop by jop-devel.
the class CallStringReceiverTypes method updateThreads.
private void updateThreads(Map<CallString, Set<TypeMapping>> input, Interpreter<CallString, Set<TypeMapping>> interpreter, Map<InstructionHandle, ContextMap<CallString, Set<TypeMapping>>> state) {
DFATool p = interpreter.getDFATool();
boolean modified = true;
while (modified) {
modified = false;
Map<String, ContextMap<CallString, Set<TypeMapping>>> tmpThreads = new LinkedHashMap<String, ContextMap<CallString, Set<TypeMapping>>>();
for (String methodName : threads.keySet()) {
MethodInfo method = p.getMethod(methodName);
InstructionHandle entry = p.getEntryHandle(method);
Context c = state.get(entry).getContext();
int varPtr = c.stackPtr - MethodHelper.getArgSize(method);
// prepare input information
ContextMap<CallString, Set<TypeMapping>> threadInput = new ContextMap<CallString, Set<TypeMapping>>(c, new LinkedHashMap<CallString, Set<TypeMapping>>());
for (CallString cs : input.keySet()) {
Set<TypeMapping> s = input.get(cs);
Set<TypeMapping> o = new LinkedHashSet<TypeMapping>();
filterSet(s, o, 0);
threadInput.put(cs, o);
}
state.put(entry, join(threadInput, state.get(entry)));
// save information
ContextMap<CallString, Set<TypeMapping>> savedResult = threads.get(methodName);
// interpret thread
Map<InstructionHandle, ContextMap<CallString, Set<TypeMapping>>> r = interpreter.interpret(c, entry, state, false);
// pull out relevant information from thread
InstructionHandle exit = p.getExitHandle(method);
ContextMap<CallString, Set<TypeMapping>> threadResult;
if (r.get(exit) != null) {
threadResult = new ContextMap<CallString, Set<TypeMapping>>(c, new LinkedHashMap<CallString, Set<TypeMapping>>());
threadResult.put(c.callString, new LinkedHashSet<TypeMapping>());
Set<TypeMapping> returned = r.get(exit).get(c.callString);
filterReturnSet(returned, threadResult.get(c.callString), varPtr);
} else {
threadResult = new ContextMap<CallString, Set<TypeMapping>>(c, new LinkedHashMap<CallString, Set<TypeMapping>>());
threadResult.put(c.callString, new LinkedHashSet<TypeMapping>());
}
if (!threadResult.equals(savedResult)) {
modified = true;
}
tmpThreads.put(methodName, threadResult);
}
threads = tmpThreads;
}
}
use of org.apache.bcel.generic.InstructionHandle in project jop by jop-devel.
the class LoopBounds method getBound.
public int getBound(InstructionHandle instr, CallString csSuffix) {
ContextMap<CallString, Pair<ValueMapping, ValueMapping>> r = bounds.get(instr);
if (r == null) {
// no bound at this point
return -1;
}
// merge bound for all contexts
int maxValue = -1;
for (CallString callString : r.keySet()) {
if (!callString.hasSuffix(csSuffix))
continue;
Pair<ValueMapping, ValueMapping> bounds = r.get(callString);
ValueMapping first = bounds.first();
ValueMapping second = bounds.second();
if (first == null || second == null) {
return -1;
}
InstructionHandle target = ((BranchInstruction) instr.getInstruction()).getTarget();
if (scopes.get(target) != null) {
if (scopes.get(target).get(callString) <= first.defscope || scopes.get(target).get(callString) <= second.defscope) {
return -1;
}
}
if (scopes.get(instr).get(callString) <= first.defscope || scopes.get(instr).get(callString) <= second.defscope) {
return -1;
}
// if (first.softinc || second.softinc) {
// return -1;
// }
int val = ValueMapping.computeBound(first, second);
if (val < 0) {
// no bound for some context
return -1;
} else {
// compute the maximum
maxValue = Math.max(maxValue, val);
}
}
return maxValue;
}
use of org.apache.bcel.generic.InstructionHandle in project jop by jop-devel.
the class LoopBounds method printSizeResult.
public void printSizeResult(DFATool program) {
for (InstructionHandle instr : sizes.keySet()) {
ContextMap<CallString, Interval[]> r = sizes.get(instr);
Context c = r.getContext();
LineNumberTable lines = c.getMethodInfo().getCode().getLineNumberTable();
int sourceLine = lines.getSourceLine(instr.getPosition());
for (CallString callString : r.keySet()) {
Interval[] bounds = r.get(callString);
System.out.println(c.method() + ":" + sourceLine + ":\t" + callString.toStringList() + ": ");
System.out.println(Arrays.asList(bounds));
}
}
}
use of org.apache.bcel.generic.InstructionHandle in project jop by jop-devel.
the class LoopBounds method doInvoke.
private void doInvoke(String methodName, InstructionHandle stmt, Context context, Map<CallString, Map<Location, ValueMapping>> input, Interpreter<CallString, Map<Location, ValueMapping>> interpreter, Map<InstructionHandle, ContextMap<CallString, Map<Location, ValueMapping>>> state, Map<CallString, Map<Location, ValueMapping>> result) {
DFATool p = interpreter.getDFATool();
MethodInfo method = p.getMethod(methodName);
if (method.isNative()) {
handleNative(method, context, input, result);
} else {
// set up new context
int varPtr = context.stackPtr - MethodHelper.getArgSize(method);
Context c = new Context(context);
c.stackPtr = method.getCode().getMaxLocals();
if (method.isSynchronized()) {
c.syncLevel = context.syncLevel + 1;
}
c.setMethodInfo(method);
c.callString = c.callString.push(method, stmt, callStringLength);
// carry only minimal information with call
Map<Location, ValueMapping> in = input.get(context.callString);
Map<Location, ValueMapping> out = new LinkedHashMap<Location, ValueMapping>();
for (Location l : in.keySet()) {
if (l.stackLoc < 0) {
out.put(l, in.get(l));
}
if (l.stackLoc >= varPtr) {
out.put(new Location(l.stackLoc - varPtr), new ValueMapping(in.get(l), false));
}
}
ContextMap<CallString, Map<Location, ValueMapping>> tmpresult = new ContextMap<CallString, Map<Location, ValueMapping>>(c, new LinkedHashMap<CallString, Map<Location, ValueMapping>>());
tmpresult.put(c.callString, out);
InstructionHandle entry = p.getEntryHandle(method);
state.put(entry, join(state.get(entry), tmpresult));
// interpret method
Map<InstructionHandle, ContextMap<CallString, Map<Location, ValueMapping>>> r = interpreter.interpret(c, entry, state, false);
//System.out.println(">>>>>>>>");
// pull out relevant information from call
InstructionHandle exit = p.getExitHandle(method);
if (r.get(exit) != null) {
Map<Location, ValueMapping> returned = r.get(exit).get(c.callString);
if (returned != null) {
for (Location l : returned.keySet()) {
if (l.stackLoc < 0) {
ValueMapping m = new ValueMapping(returned.get(l), true);
m.join(result.get(context.callString).get(l));
result.get(context.callString).put(l, m);
}
if (l.stackLoc >= 0) {
ValueMapping m = new ValueMapping(returned.get(l), false);
Location loc = new Location(l.stackLoc + varPtr);
m.join(result.get(context.callString).get(loc));
result.get(context.callString).put(loc, m);
}
}
}
}
// add relevant information to result
for (Location l : in.keySet()) {
if (l.stackLoc >= 0 && l.stackLoc < context.stackPtr - MethodHelper.getArgSize(method)) {
result.get(context.callString).put(l, new ValueMapping(in.get(l), true));
}
}
}
}
Aggregations