use of com.jopdesign.common.MethodInfo in project jop by jop-devel.
the class ControlFlowGraph method addBasicBlock.
/*---------------------------------------------------------------------------*
* CFG modify, compile, dispose
*---------------------------------------------------------------------------*/
/**
* Add a basic block to this graph. The instruction list of the block must not be empty.
*
* @param insertBefore insert the block at this position in the block list.
* @param bb block to add
* @return the new block node, either an InvokeNode, SpecialInvokeNode or BasicBlockNode, depending on the
* contained instructions.
*/
public BasicBlockNode addBasicBlock(int insertBefore, BasicBlock bb) {
BasicBlockNode n;
Instruction lastInstr = bb.getLastInstruction().getInstruction();
InstructionHandle theInvoke = bb.getTheInvokeInstruction();
// This needs to be done before creating the Node, else blocks.indexOf returns -1
blocks.add(insertBefore, bb);
if (theInvoke != null) {
n = new InvokeNode(bb, theInvoke);
} else if (appInfo.getProcessorModel().isImplementedInJava(methodInfo, lastInstr)) {
MethodInfo javaImpl = appInfo.getProcessorModel().getJavaImplementation(appInfo, bb.getMethodInfo(), lastInstr);
n = new SpecialInvokeNode(bb, javaImpl);
} else {
n = new BasicBlockNode(bb);
}
graph.addVertex(n);
return n;
}
use of com.jopdesign.common.MethodInfo in project jop by jop-devel.
the class InvokeSite method canInvoke.
/**
* @param methodInfo a possible invokee
* @return true if this invokeSite may invoke the method. Does not use the callgraph to check.
* For interface invoke sites this can return UNKNOWN if the class of the given method implementation
* does not implement the referenced interface.
*/
public Ternary canInvoke(MethodInfo methodInfo) {
assert methodInfo != null;
MethodRef invokeeRef = getInvokeeRef();
MethodInfo method = invokeeRef.getMethodInfo();
if (methodInfo.equals(method)) {
return Ternary.TRUE;
}
if (!isVirtual()) {
// and therefore cannot be invoked
return Ternary.FALSE;
}
if (method == null) {
return Ternary.UNKNOWN;
}
if (!methodInfo.getClassInfo().isSubclassOf(invokeeRef.getClassInfo())) {
if (isInvokeInterface() && !methodInfo.getClassInfo().isInterface()) {
// check the signature..
if (!invokeeRef.getMethodSignature().equals(methodInfo.getMethodSignature())) {
return Ternary.FALSE;
}
return Ternary.UNKNOWN;
}
return Ternary.FALSE;
}
return Ternary.valueOf(methodInfo.overrides(method, true));
}
use of com.jopdesign.common.MethodInfo in project jop by jop-devel.
the class SuperGraph method getCallSites.
/**
* @return return all callsite invoke/return superedge pairs, grouped by the invoked method
*/
public Map<MethodInfo, List<Pair<SuperInvokeEdge, SuperReturnEdge>>> getCallSites() {
Map<MethodInfo, List<Pair<SuperInvokeEdge, SuperReturnEdge>>> iMap = new LinkedHashMap<MethodInfo, List<Pair<SuperInvokeEdge, SuperReturnEdge>>>();
for (ContextCFG node : superGraph.vertexSet()) {
List<Pair<SuperInvokeEdge, SuperReturnEdge>> callSites = getCallSitesInvoking(node);
MethodInfo invoked = node.getCfg().getMethodInfo();
if (iMap.containsKey(invoked)) {
callSites.addAll(iMap.get(invoked));
}
iMap.put(invoked, callSites);
}
return iMap;
}
use of com.jopdesign.common.MethodInfo in project jop by jop-devel.
the class CallGraph method buildCallGraph.
/**
* Build a callgraph with all root methods of AppInfo.
* This also adds all static initializers of all classes and all Runnable.run() methods
* to the callgraph roots.
*
* @see AppInfo#getRootMethods()
* @param appInfo the AppInfo to use
* @param builder the builder class to use to build this graph
* @return a freshly constructed callgraph.
*/
public static CallGraph buildCallGraph(AppInfo appInfo, CallgraphBuilder builder) {
Collection<MethodInfo> rootMethods = appInfo.getRootMethods();
Set<ExecutionContext> roots = new LinkedHashSet<ExecutionContext>(rootMethods.size());
for (MethodInfo m : rootMethods) {
roots.add(new ExecutionContext(m));
}
for (MethodInfo m : appInfo.getClinitMethods()) {
roots.add(new ExecutionContext(m));
}
for (MethodInfo m : appInfo.getThreadRootMethods(false)) {
roots.add(new ExecutionContext(m));
}
CallGraph cg = new CallGraph(roots, builder);
cg.build();
return cg;
}
use of com.jopdesign.common.MethodInfo in project jop by jop-devel.
the class CallGraph method getReachableImplementations.
/**
* Get non-abstract methods, in topological order.
*
* Requires an acyclic callgraph.
* @param rootMethod start with this method
* @return a list of all non-abstract reachable methods, in topological order.
*/
public List<MethodInfo> getReachableImplementations(MethodInfo rootMethod) {
List<MethodInfo> implemented = new ArrayList<MethodInfo>();
Set<MethodInfo> reachable = getReachableImplementationsSet(rootMethod);
TopologicalOrderIterator<ExecutionContext, ContextEdge> ti = topDownIterator();
while (ti.hasNext()) {
MethodInfo m = ti.next().getMethodInfo();
if (m != null && reachable.contains(m))
implemented.add(m);
}
return implemented;
}
Aggregations