use of com.jopdesign.common.MethodInfo in project jop by jop-devel.
the class DefaultCallgraphBuilder method getInvokedMethods.
@Override
public Set<ExecutionContext> getInvokedMethods(ExecutionContext context) {
CallString callstring = context.getCallString();
MethodInfo method = context.getMethodInfo();
if (!method.hasCode()) {
// noinspection unchecked
return (Set<ExecutionContext>) Collections.EMPTY_SET;
}
// TODO use only callstring length 1, split nodes only if required using DFA/.. later on?
Set<ExecutionContext> newContexts = new LinkedHashSet<ExecutionContext>();
invokeLoop: for (InvokeSite invokeSite : findInvokeSites(method.getCode())) {
Set<MethodInfo> methods = getInvokedMethods(context, invokeSite);
if (skipNatives) {
for (MethodInfo impl : methods) {
// to indicate that the candidates are not completely represented!
if (impl.isNative()) {
continue invokeLoop;
}
}
}
for (MethodInfo impl : methods) {
// System.out.println("Implemented Methods: "+impl+" from "+iNode.getBasicBlock().getMethodInfo().methodId+" in context "+callstring.toStringVerbose());
CallString newCallString = callstring.push(invokeSite, callstringLength);
newContexts.add(new ExecutionContext(impl, newCallString));
}
}
return newContexts;
}
use of com.jopdesign.common.MethodInfo 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.MethodInfo in project jop by jop-devel.
the class DescendingClassTraverser method visitClass.
public boolean visitClass(ClassInfo classInfo) {
if (!visitor.visitClass(classInfo)) {
return returnOnSkipClass;
}
visitConstantPool(classInfo);
// methods and fields are final, no need to call accept()
for (FieldInfo f : classInfo.getFields()) {
if (!visitor.visitField(f)) {
continue;
}
bcelVisitor.setFieldInfo(f);
visitAttributes(f.getAttributes());
visitor.finishField(f);
}
for (MethodInfo m : classInfo.getMethods()) {
if (!visitor.visitMethod(m)) {
continue;
}
bcelVisitor.setMethodInfo(m);
visitMethodCode(m);
visitAttributes(m.getAttributes());
visitor.finishMethod(m);
}
bcelVisitor.setClassInfo(classInfo);
visitAttributes(classInfo.getAttributes());
visitor.finishClass(classInfo);
return true;
}
use of com.jopdesign.common.MethodInfo in project jop by jop-devel.
the class SuperGraph method createSuperGraph.
private void createSuperGraph() {
Stack<ContextCFG> todo = new Stack<ContextCFG>();
todo.push(rootNode);
superGraph.addVertex(rootNode);
while (!todo.empty()) {
ContextCFG current = todo.pop();
if (!current.getCfg().areVirtualInvokesResolved()) {
throw new AssertionError("Virtual dispatch nodes not yet supported for supergraph (file a bug)");
}
ControlFlowGraph currentCFG = current.getCfg();
CallString currentCS = current.getCallString();
Collection<CFGEdge> infeasibleEdges = infeasibleEdgeProvider.getInfeasibleEdges(currentCFG, currentCS);
for (CFGNode node : current.getCfg().vertexSet()) {
if (node instanceof ControlFlowGraph.InvokeNode) {
/* skip node if all incoming edges are infeasible in the current call context */
boolean infeasible = true;
for (CFGEdge e : current.getCfg().incomingEdgesOf(node)) {
if (!infeasibleEdges.contains(e)) {
infeasible = false;
}
}
if (infeasible)
continue;
ControlFlowGraph.InvokeNode iNode = (ControlFlowGraph.InvokeNode) node;
Set<MethodInfo> impls = iNode.getImplementingMethods();
if (impls.size() == 0) {
throw new AssertionError("No implementations for iNode available");
} else if (impls.size() != 1) {
throw new AssertionError("Unresolved virtual Dispatch for " + iNode + ": " + impls);
}
for (MethodInfo impl : impls) {
ControlFlowGraph invokedCFG = cfgProvider.getFlowGraph(impl);
CallString invokedCS = currentCS.push(iNode, callstringLength);
/* skip node if receiver is infeasible in current call context */
if (infeasibleEdgeProvider.isInfeasibleReceiver(impl, invokedCS)) {
Logger.getLogger(this.getClass()).info("createSuperGraph(): infeasible receiver " + impl);
continue;
}
ContextCFG invoked = new ContextCFG(invokedCFG, invokedCS);
if (!superGraph.containsVertex(invoked)) {
superGraph.addVertex(invoked);
todo.push(invoked);
}
addEdge(iNode, current, invoked);
}
}
}
}
}
use of com.jopdesign.common.MethodInfo in project jop by jop-devel.
the class FIFOVarBlockCacheBuilder method initCache.
protected StringBuilder initCache(String NUM_METHODS) {
List<Object> cacheElems = new ArrayList<Object>();
for (int i = 0; i < numBlocks(); i++) cacheElems.add(NUM_METHODS);
// TODO check: this has been "blocksOf(0)", check if this is the same!!
MethodInfo method = project.getAppInfo().getMainMethod();
if (assumeEmptyCache)
cacheElems.set(blocksOf(method) - 1, 0);
return SystemBuilder.constArray(cacheElems);
}
Aggregations