use of com.jopdesign.common.AppInfo in project jop by jop-devel.
the class UnusedCodeRemover method removeUnusedMembers.
/**
* Remove all unused classes, methods and fields.
*/
private void removeUnusedMembers() {
AppInfo appInfo = AppInfo.getSingleton();
// we cannot modify the lists while iterating through it
List<ClassInfo> unusedClasses = new LinkedList<ClassInfo>();
List<FieldInfo> unusedFields = new LinkedList<FieldInfo>();
List<MethodInfo> unusedMethods = new LinkedList<MethodInfo>();
int fields = 0;
int methods = 0;
for (ClassInfo cls : appInfo.getClassInfos()) {
if (ucf.getMark(cls) == Mark.UNUSED) {
unusedClasses.add(cls);
logger.debug("Removing unused class " + cls);
continue;
}
unusedFields.clear();
unusedMethods.clear();
if (appInfo.isHwObject(cls)) {
// Do not remove fields from hardware objects, else the mapping gets broken and
// chaos takes over!
logger.debug("Skipping fields of used hardware object " + cls);
} else {
for (FieldInfo f : cls.getFields()) {
if (ucf.getMark(f) == Mark.UNUSED) {
unusedFields.add(f);
}
}
}
for (MethodInfo m : cls.getMethods()) {
Mark mark = ucf.getMark(m);
if (mark == Mark.UNUSED) {
unusedMethods.add(m);
}
if (mark == Mark.MARKED && !m.isNative() && !m.isAbstract()) {
logger.info("Making unused method " + m + " abstract");
m.setAbstract(true);
m.getClassInfo().setAbstract(true);
}
}
for (FieldInfo f : unusedFields) {
fields += removeField(f);
}
for (MethodInfo m : unusedMethods) {
methods += removeMethod(m);
}
}
appInfo.removeClasses(unusedClasses);
int classes = unusedClasses.size();
logger.info("Removed " + classes + (classes == 1 ? " class, " : " classes, ") + fields + (fields == 1 ? " field, " : " fields, ") + methods + (methods == 1 ? " method" : " methods"));
}
use of com.jopdesign.common.AppInfo in project jop by jop-devel.
the class CallGraph method getInvokeSites.
public Set<InvokeSite> getInvokeSites(MethodInfo invokee) {
MethodNode node = getMethodNode(invokee);
Set<InvokeSite> invokeSites = new LinkedHashSet<InvokeSite>();
for (ExecutionContext ec : node.getInstances()) {
if (ec.getCallString().isEmpty()) {
// no callstring, need to search the invoker 'manually' for invokesites which may invoke this method
AppInfo appInfo = AppInfo.getSingleton();
for (ContextEdge edge : callGraph.incomingEdgesOf(ec)) {
for (InvokeSite invokeSite : edge.getSource().getMethodInfo().getCode().getInvokeSites()) {
if (invokeSite.canInvoke(invokee) != Ternary.FALSE) {
invokeSites.add(invokeSite);
}
}
}
} else {
invokeSites.add(ec.getCallString().top());
}
}
return invokeSites;
}
use of com.jopdesign.common.AppInfo in project jop by jop-devel.
the class SegmentTest method main.
public static void main(String[] args) {
TestFramework testFramework = new TestFramework();
AppSetup setup = testFramework.setupAppSetup("java/tools/test/test/cg1.zip", null);
AppInfo appInfo = testFramework.setupAppInfo("wcet.devel.CallGraph1.run", true);
SegmentTest testInst = new SegmentTest();
testInst.appInfo = appInfo;
MethodInfo mainMethod = appInfo.getMainMethod();
/* count total number of CFG nodes */
SuperGraph superGraph = new SuperGraph(testInst, testInst.getFlowGraph(mainMethod), 2);
Segment segment = Segment.methodSegment(mainMethod, CallString.EMPTY, testInst, 2, superGraph.getInfeasibleEdgeProvider());
int count = 0;
for (ContextCFG cgNode : superGraph.getCallGraphNodes()) {
try {
cgNode.getCfg().exportDOT(new File("/tmp/cfg-" + cgNode.getCfg().getMethodInfo().getClassName() + "_" + cgNode.getCfg().getMethodInfo().getShortName() + ".dot"));
} catch (IOException e) {
}
count += cgNode.getCfg().vertexSet().size();
}
checkEquals("[Segment 1] Expected node count", (count - 2), Iterators.size(segment.getNodes()));
try {
segment.exportDOT(new File("/tmp/cg1-segment.dot"));
} catch (IOException e) {
e.printStackTrace();
}
/* root */
ContextCFG root = superGraph.getRootNode();
/* Build a segment cuts all invokes in those methods invoked by run() */
Segment segment2;
/* root entries */
Set<SuperGraphEdge> entries = new HashSet<SuperGraphEdge>();
Iterators.addAll(entries, superGraph.liftCFGEdges(root, root.getCfg().outgoingEdgesOf(root.getCfg().getEntry())));
Set<SuperGraphEdge> exits = new HashSet<SuperGraphEdge>();
int cfgNodeCandidateCount = root.getCfg().vertexSet().size();
/* find callees */
for (SuperEdge superEdge : superGraph.getCallGraph().outgoingEdgesOf(root)) {
if (!(superEdge instanceof SuperInvokeEdge))
continue;
ContextCFG callee1 = superGraph.getCallGraph().getEdgeTarget(superEdge);
cfgNodeCandidateCount += callee1.getCfg().vertexSet().size();
/* find all edges from invoke nodes */
for (CFGNode cfgNode : callee1.getCfg().vertexSet()) {
if (cfgNode instanceof InvokeNode) {
Iterators.addAll(exits, superGraph.outgoingEdgesOf(new SuperGraphNode(callee1, cfgNode)));
}
}
}
segment2 = new Segment(superGraph, entries, exits);
exits = segment2.getExitEdges();
/* reachable exits */
try {
segment2.exportDOT(new File("/tmp/cg1-segment2.dot"));
} catch (IOException e) {
e.printStackTrace();
}
checkEquals("[Segment 2] Expected node count", 14, Iterators.size(segment2.getNodes()) + 2);
checkLessEqual("[Segment 2] Expected node count <= |root + directly invoked|", Iterators.size(segment2.getNodes()) + 2, cfgNodeCandidateCount);
/* Another segment, with entries the exits of the last segment, and exits all invokes in methods the entries */
Segment segment3;
entries = segment2.getExitEdges();
exits = new HashSet<SuperGraphEdge>();
cfgNodeCandidateCount = 0;
for (SuperGraphEdge superEdge : entries) {
SuperGraphNode node1 = superEdge.getTarget();
for (SuperEdge superEdge2 : superGraph.getCallGraph().outgoingEdgesOf(node1.getContextCFG())) {
if (!(superEdge2 instanceof SuperInvokeEdge))
continue;
ContextCFG callee2 = superGraph.getCallGraph().getEdgeTarget(superEdge2);
/* find all edges from invoke nodes */
for (CFGNode cfgNode : callee2.getCfg().vertexSet()) {
if (cfgNode instanceof InvokeNode) {
Iterators.addAll(exits, superGraph.outgoingEdgesOf(new SuperGraphNode(callee2, cfgNode)));
}
}
}
}
segment3 = new Segment(superGraph, entries, exits);
try {
segment3.exportDOT(new File("/tmp/cg1-segment3.dot"));
} catch (IOException e) {
e.printStackTrace();
}
checkEquals("[Segment 2] 3 exits", 3, segment2.getExitEdges().size());
checkEquals("[Segment 3] 3 entries", 3, segment3.getEntryEdges().size());
checkEquals("[Segment 3] 4 exits", 4, segment3.getExitEdges().size());
}
use of com.jopdesign.common.AppInfo in project jop by jop-devel.
the class ConstantCache method addConstantPoolAddress.
private void addConstantPoolAddress(ControlFlowGraph cfg, CPInstruction ii) {
AppInfo appInfo = cfg.getAppInfo();
LinkerInfo linker = project.getLinkerInfo();
Integer address = linker.getLinkInfo(cfg.getMethodInfo().getClassInfo()).getConstAddress(ii.getIndex());
addAddress(cpoolAddressMap, cfg.getMethodInfo(), address);
}
use of com.jopdesign.common.AppInfo in project jop by jop-devel.
the class HashTest method main.
public static void main(String[] args) {
TestFramework test = new TestFramework();
AppSetup setup = test.setupAppSetup();
AppInfo appInfo = test.setupAppInfo("common.code.HashTest", false);
ClassInfo testClass = appInfo.loadClass("common.TestFramework");
MethodInfo mainMethod = appInfo.getMainMethod();
MethodCode code = mainMethod.getCode();
InstructionHandle[] ih = code.getInstructionList().getInstructionHandles();
InvokeSite i1 = code.getInvokeSite(ih[1]);
InvokeSite i2 = code.getInvokeSite(ih[2]);
InvokeSite i3 = code.getInvokeSite(ih[3]);
InvokeSite i11 = code.getInvokeSite(ih[1]);
check(i1 == i11);
CallString c1 = new CallString(i1);
CallString c2 = new CallString(i2);
CallString c11 = new CallString(i1);
check(c1.equals(c11));
check(!c1.equals(c2));
ExecutionContext e1 = new ExecutionContext(mainMethod, c1);
ExecutionContext e2 = new ExecutionContext(mainMethod, c2);
ExecutionContext e11 = new ExecutionContext(mainMethod, c11);
check(e1.equals(e11));
check(!e1.equals(e2));
// TODO put stuff into maps, check contains() and get()
// modify instruction list, check if everything still works
InstructionList il = code.getInstructionList();
il.insert(new ILOAD(0));
il.insert(ih[2], new ILOAD(1));
ih = il.getInstructionHandles();
InvokeSite i12 = code.getInvokeSite(ih[2]);
InvokeSite i22 = code.getInvokeSite(ih[4]);
check(i12 == i1);
check(i22 == i2);
check(e1.equals(e11));
check(!e1.equals(e2));
il.setPositions();
check(c1.equals(c11));
check(!c1.equals(c2));
check(e1.equals(e11));
check(!e1.equals(e2));
}
Aggregations