use of com.jopdesign.common.code.CallString in project jop by jop-devel.
the class DFATool method dumpDFA.
public String dumpDFA(MethodInfo method) {
if (getLoopBounds() == null)
return "n/a";
if (method.isAbstract()) {
return "n/a";
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream os = new PrintStream(baos);
Map<InstructionHandle, ContextMap<CallString, Pair<ValueMapping, ValueMapping>>> results = getLoopBounds().getResult();
if (results == null)
return "n/a";
AnalysisResultSerialization<Pair<ValueMapping, ValueMapping>> printer = new AnalysisResultSerialization<Pair<ValueMapping, ValueMapping>>();
for (Entry<InstructionHandle, ContextMap<CallString, Pair<ValueMapping, ValueMapping>>> ihEntry : results.entrySet()) {
for (Entry<CallString, Pair<ValueMapping, ValueMapping>> csEntry : ihEntry.getValue().entrySet()) {
if (ihEntry.getValue().getContext().getMethodInfo().equals(method)) {
printer.addResult(method, ihEntry.getKey().getPosition(), csEntry.getKey(), csEntry.getValue());
}
}
}
printer.dump(os);
try {
return baos.toString("UTF-8");
} catch (UnsupportedEncodingException e) {
return baos.toString();
}
}
use of com.jopdesign.common.code.CallString in project jop by jop-devel.
the class DFATool method getReceiverMethods.
public Set<MethodInfo> getReceiverMethods(InstructionHandle stmt, CallString cs) {
Set<String> receivers = getReceivers(stmt, cs);
Set<MethodInfo> methods = new LinkedHashSet<MethodInfo>(receivers.size());
for (String rcv : receivers) {
MemberID mID = MemberID.parse(rcv);
methods.add(appInfo.getMethodInfoInherited(mID));
}
return methods;
}
use of com.jopdesign.common.code.CallString in project jop by jop-devel.
the class CallStringReceiverTypes method doInvokeVirtual.
private void doInvokeVirtual(String receiver, MethodInfo method, InstructionHandle stmt, Context context, ContextMap<CallString, Set<TypeMapping>> input, Interpreter<CallString, Set<TypeMapping>> interpreter, Map<InstructionHandle, ContextMap<CallString, Set<TypeMapping>>> state, ContextMap<CallString, Set<TypeMapping>> result) {
String methodImplName = method.getClassName() + "." + method.getMethodSignature();
recordReceiver(stmt, context, methodImplName);
// LineNumberTable lines = p.getMethods().get(context.method).getLineNumberTable(context.constPool);
// int sourceLine = lines.getSourceLine(stmt.getPosition());
// String invokeId = context.method+"\t"+":"+sourceLine+"."+stmt.getPosition();
// 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(context.getMethodInfo(), stmt, callStringLength);
boolean threaded = false;
DFATool p = interpreter.getDFATool();
if (p.getAppInfo().getClassInfo(receiver).isSubclassOf(p.getAppInfo().getClassInfo("joprt.RtThread")) && "run()V".equals(method.getMethodSignature())) {
c.createThread();
threaded = true;
}
// carry only minimal information with call
Set<TypeMapping> in = input.get(context.callString);
Set<TypeMapping> out = new LinkedHashSet<TypeMapping>();
ContextMap<CallString, Set<TypeMapping>> tmpresult = new ContextMap<CallString, Set<TypeMapping>>(c, new LinkedHashMap<CallString, Set<TypeMapping>>());
tmpresult.put(c.callString, out);
for (TypeMapping m : in) {
if (m.stackLoc < 0) {
out.add(m);
}
if (m.stackLoc > varPtr) {
out.add(new TypeMapping(m.stackLoc - varPtr, m.type));
}
if (m.stackLoc == varPtr) {
// add "this"
ClassInfo staticClass = p.getAppInfo().getClassInfo(receiver);
ClassInfo dynamicClass = null;
try {
dynamicClass = p.getAppInfo().getClassInfo(m.type.split("@")[0]);
} catch (MissingClassError ex) {
logger.error("doInvokeVirtual - trying to improve type of " + staticClass + ": " + ex);
// TODO: maybe we should throw an exception/error instead?
}
if (dynamicClass != null && dynamicClass.isSubclassOf(staticClass)) {
out.add(new TypeMapping(0, m.type));
}
}
}
InstructionHandle entry = p.getEntryHandle(method);
state.put(entry, join(state.get(entry), tmpresult));
// interpret method
Map<InstructionHandle, ContextMap<CallString, Set<TypeMapping>>> r = interpreter.interpret(c, entry, state, false);
// pull out relevant information from call
InstructionHandle exit = p.getExitHandle(method);
if (r.get(exit) != null) {
Set<TypeMapping> returned = r.get(exit).get(c.callString);
if (returned != null) {
filterReturnSet(returned, result.get(context.callString), varPtr);
}
}
// update all threads
if (threaded) {
threads.put(methodImplName, new ContextMap<CallString, Set<TypeMapping>>(c, result));
updateThreads(result, interpreter, state);
}
}
use of com.jopdesign.common.code.CallString in project jop by jop-devel.
the class CallStringReceiverTypes method join.
public ContextMap<CallString, Set<TypeMapping>> join(ContextMap<CallString, Set<TypeMapping>> s1, ContextMap<CallString, Set<TypeMapping>> s2) {
if (s1 == null) {
return new ContextMap<CallString, Set<TypeMapping>>(s2);
}
if (s2 == null) {
return new ContextMap<CallString, Set<TypeMapping>>(s1);
}
ContextMap<CallString, Set<TypeMapping>> result = new ContextMap<CallString, Set<TypeMapping>>(new Context(s2.getContext()), new LinkedHashMap<CallString, Set<TypeMapping>>());
result.putAll(s1);
result.putAll(s2);
Set<TypeMapping> a = s1.get(s2.getContext().callString);
Set<TypeMapping> b = s2.get(s2.getContext().callString);
Set<TypeMapping> merged = new LinkedHashSet<TypeMapping>();
if (a != null) {
merged.addAll(a);
}
if (b == null) {
logger.error("RT join: failed to find DF information for " + s2.getContext().callString.toStringVerbose(false));
}
merged.addAll(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;
}
use of com.jopdesign.common.code.CallString in project jop by jop-devel.
the class CallStringReceiverTypes method initial.
public ContextMap<CallString, Set<TypeMapping>> initial(InstructionHandle stmt) {
ContextMap<CallString, Set<TypeMapping>> init = new ContextMap<CallString, Set<TypeMapping>>(new Context(), new LinkedHashMap<CallString, Set<TypeMapping>>());
Set<TypeMapping> s = new LinkedHashSet<TypeMapping>();
s.add(new TypeMapping("com.jopdesign.io.IOFactory.sp", "com.jopdesign.io.SerialPort"));
s.add(new TypeMapping("com.jopdesign.io.IOFactory.sys", "com.jopdesign.io.SysDevice"));
init.put(CallString.EMPTY, s);
return init;
}
Aggregations