use of com.jopdesign.common.MethodInfo in project jop by jop-devel.
the class CallGraph method buildCallGraph.
/**
* Build a callgraph rooted at the given set of methods
*
* @param rootMethods The root methods of the callgraph
* @param builder the builder class to use to build this graph
* @return a freshly constructed callgraph.
*/
public static CallGraph buildCallGraph(Collection<MethodInfo> rootMethods, CallgraphBuilder builder) {
List<ExecutionContext> roots = new ArrayList<ExecutionContext>(rootMethods.size());
for (MethodInfo method : rootMethods) {
roots.add(new ExecutionContext(method));
}
CallGraph cg = new CallGraph(roots, builder);
cg.build();
return cg;
}
use of com.jopdesign.common.MethodInfo in project jop by jop-devel.
the class ConstantPoolReferenceFinder method findReferencedMembers.
/**
* Find all referenced members in a class.
* @param classInfo the class to search.
* @param checkMembers if false, do not check fields and methods. Else check everything.
* @return a set of class names and class member signatures found in the class.
*/
public static Set<String> findReferencedMembers(ClassInfo classInfo, boolean checkMembers) {
// Else we need to go into details..
Set<String> members = new HashSet<String>();
ClassMemberVisitor visitor = new ClassMemberVisitor(members);
JavaClass javaClass = classInfo.compile();
Set<Integer> ids = findPoolReferences(classInfo, javaClass);
List<InvokeSite> invokes = new ArrayList<InvokeSite>();
if (checkMembers) {
for (Field field : javaClass.getFields()) {
FieldInfo fieldInfo = classInfo.getFieldInfo(field.getName());
// add members found in the field
visitor.visitField(fieldInfo);
// there are no invokesites in a field, only add found ids
ids.addAll(findPoolReferences(fieldInfo, field));
}
for (Method method : javaClass.getMethods()) {
MethodInfo methodInfo = classInfo.getMethodInfo(method.getName() + method.getSignature());
// add members found in the method
visitor.visitMethod(methodInfo);
// add all ids for checking, add all invoke sites
ids.addAll(findPoolReferences(methodInfo, method));
}
}
// fill the members list with all found constantpool references
visitor.visitClass(classInfo);
visitPoolReferences(classInfo, visitor, ids);
return members;
}
use of com.jopdesign.common.MethodInfo in project jop by jop-devel.
the class UsedCodeFinder method markUsedMembers.
/**
* Mark all used members, starting at all AppInfo roots.
* <p>
* To avoid marking unused Runnable.run methods, remove them from the callgraph roots first.
* </p>
*
* @see #markUsedMembers(ClassInfo,boolean)
* @see #markUsedMembers(MethodInfo)
* @see #markUsedMembers(FieldInfo)
*/
public void markUsedMembers() {
resetMarks();
// This contains all application and JVM root methods and -classes
for (MethodInfo root : appInfo.getRootMethods()) {
// this also marks the containing class as used, and includes the main method
markUsedMembers(root);
}
// but we need to add all Runnable.run() methods as root methods
for (MethodInfo run : appInfo.getThreadRootMethods(true)) {
markUsedMembers(run);
}
if (ignoredClasses.size() > 0) {
int num = ignoredClasses.size();
logger.info("Ignored " + num + " referenced " + (num == 1 ? "class: " : "classes: ") + ignoredClasses);
}
}
use of com.jopdesign.common.MethodInfo in project jop by jop-devel.
the class TreeAnalysis method extractUBs.
private Map<CFGNode, Long> extractUBs(Map<CFGNode, LoopBound> loopBounds) {
Map<CFGNode, Long> ubMap = new HashMap<CFGNode, Long>();
for (Entry<CFGNode, LoopBound> entry : loopBounds.entrySet()) {
MethodInfo mi = entry.getKey().getControlFlowGraph().getMethodInfo();
ExecutionContext eCtx = new ExecutionContext(mi);
ubMap.put(entry.getKey(), entry.getValue().getUpperBound(eCtx));
}
return ubMap;
}
use of com.jopdesign.common.MethodInfo in project jop by jop-devel.
the class TreeAnalysis method computeProgress.
/* FIXME: filter leaf methods is really a ugly hack,
* but needs some work to play nice with uppaal eliminate-leaf-methods optimizations
*/
public void computeProgress(MethodInfo targetMethod, CallString cs) {
List<MethodInfo> reachable = project.getCallGraph().getReachableImplementations(targetMethod, cs);
Collections.reverse(reachable);
for (MethodInfo mi : reachable) {
ControlFlowGraph cfg = project.getFlowGraph(mi);
Map<CFGNode, Long> localProgress = new HashMap<CFGNode, Long>();
ProgressVisitor progressVisitor = new ProgressVisitor(maxProgress);
for (CFGNode n : cfg.vertexSet()) {
localProgress.put(n, progressVisitor.getProgress(n));
}
ProgressMeasure<CFGNode, CFGEdge> pm = new ProgressMeasure<CFGNode, ControlFlowGraph.CFGEdge>(cfg.getGraph(), cfg.getLoopColoring(), extractUBs(cfg.buildLoopBoundMap()), localProgress);
long progress = pm.getMaxProgress().get(cfg.getExit());
/* FIXME: _UGLY_ hack */
if (filterLeafMethods && cfg.isLeafMethod()) {
maxProgress.put(mi, 0L);
} else {
maxProgress.put(mi, progress);
}
relativeProgress.put(mi, pm.computeRelativeProgress());
}
System.out.println("Progress Measure (max): " + maxProgress.get(targetMethod));
}
Aggregations