use of com.jopdesign.common.ClassInfo in project jop by jop-devel.
the class Config method parseMethodList.
/**
* @param methodNames comma separated list of method names, either fully qualified with or without descriptor, or
* method names of methods in the main class.
* @return the set of methods represented by these names
* @throws BadConfigurationException if a name is not resolvable
*/
public static List<MethodInfo> parseMethodList(String methodNames) throws BadConfigurationException {
List<String> names = splitStringList(methodNames);
List<MethodInfo> methods = new ArrayList<MethodInfo>(names.size());
for (String name : names) {
MemberID id = MemberID.parse(name);
if (!id.hasClassName()) {
ClassInfo main = AppInfo.getSingleton().getMainMethod().getClassInfo();
Set<MethodInfo> m = main.getMethodInfos(id);
if (m.isEmpty()) {
throw new BadConfigurationException("Cannot find method '" + name + "' in main class " + main);
}
methods.addAll(m);
} else {
try {
Collection<MethodInfo> infos = AppInfo.getSingleton().getMethodInfos(id);
if (infos.isEmpty()) {
throw new BadConfigurationException("Cannot find methods for " + name);
}
methods.addAll(infos);
} catch (MethodNotFoundException e) {
throw new BadConfigurationException("Cannot find class for " + name, e);
}
}
}
return methods;
}
use of com.jopdesign.common.ClassInfo in project jop by jop-devel.
the class DFATool method load.
/**
* Load the methods into the internal DFA structures and initialize the DFA tool for a new analysis.
* You need to call this method before starting the first analysis and before starting an analysis after
* the code has been modified.
*/
public void load() {
// First clear everything ..
statements.clear();
flow.clear();
receivers = null;
prologue = createPrologue();
// Now we need to process all classes (for DFA's internal flow graph)
for (ClassInfo cls : appInfo.getClassInfos()) {
for (MethodInfo mi : cls.getMethods()) {
if (mi.hasCode()) {
loadMethod(mi);
}
}
}
if (cacheDir != null && !appInfo.updateCheckSum(prologue)) {
cacheDir = null;
}
}
use of com.jopdesign.common.ClassInfo 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.ClassInfo in project jop by jop-devel.
the class ConstantPoolReferenceFinder method findPoolReferences.
private static Set<Integer> findPoolReferences(FieldInfo fieldInfo, Field field) {
ClassInfo classInfo = fieldInfo.getClassInfo();
// we do not need to handle invoke sites here specially, since we do not visit code here
IdFinderVisitor visitor = new IdFinderVisitor(classInfo);
visitor.visitConstantUtf8(field.getNameIndex());
visitor.visitConstantUtf8(field.getSignatureIndex());
DescendingClassTraverser traverser = new DescendingClassTraverser(visitor);
traverser.visitAttributes(fieldInfo, field.getAttributes());
return visitor.getIds();
}
use of com.jopdesign.common.ClassInfo in project jop by jop-devel.
the class SourceLineStorage method storeSourceInfos.
/**
* Store all source file and -line annotations of all classes to the storage file.
*/
public void storeSourceInfos() {
PrintWriter writer;
try {
writer = new PrintWriter(new BufferedWriter(new FileWriter(storage, false)));
} catch (IOException e) {
logger.error("Error opening file " + storage + " for writing, not writing source line infos!", e);
return;
}
for (ClassInfo cls : AppInfo.getSingleton().getClassInfos()) {
for (MethodInfo method : cls.getMethods()) {
if (!method.hasCode())
continue;
writeSourceInfos(method.getCode(), writer);
}
}
writer.close();
}
Aggregations