Search in sources :

Example 46 with ClassInfo

use of com.jopdesign.common.ClassInfo in project jop by jop-devel.

the class UnusedCodeRemover method execute.

public void execute() {
    ucf.resetMarks();
    // This starts at all app roots and JVM roots, as well as all threads,
    // <clinit> methods are marked in all reached classes
    ucf.markUsedMembers();
    // We also need to mark everything else we do not want to remove ..
    AppInfo appInfo = AppInfo.getSingleton();
    ProcessorModel pm = appInfo.getProcessorModel();
    if (pm.keepJVMClasses()) {
        for (String clName : pm.getJVMClasses()) {
            ClassInfo cls = appInfo.getClassInfo(clName);
            if (cls != null) {
                ucf.markUsedMembers(cls, true);
            }
        }
    }
    removeUnusedMembers();
}
Also used : ProcessorModel(com.jopdesign.common.processormodel.ProcessorModel) AppInfo(com.jopdesign.common.AppInfo) ClassInfo(com.jopdesign.common.ClassInfo)

Example 47 with ClassInfo

use of com.jopdesign.common.ClassInfo in project jop by jop-devel.

the class Report method generateInfoPages.

/**
     * Dump the project's input (callgraph,cfgs)
     *
     * @throws IOException
     */
public void generateInfoPages() throws IOException {
    this.addStat("#classes", project.getCallGraph().getClassInfos().size());
    this.addStat("#methods", project.getCallGraph().getReachableImplementationsSet(project.getTargetMethod()).size());
    this.addStat("max call stack ", project.getCallGraph().getMaximalCallStack());
    this.addStat("largest method size (in bytes)", project.getCallGraph().getLargestMethod().getNumberOfBytes());
    this.addStat("largest method size (in words)", project.getCallGraph().getLargestMethod().getNumberOfWords());
    this.addStat("total size of task (in bytes)", project.getCallGraph().getTotalSizeInBytes());
    generateInputOverview();
    this.addPage("details", null);
    for (MethodInfo m : project.getCallGraph().getReachableImplementationsSet(project.getTargetMethod())) {
        for (LineNumber ln : m.getCode().getLineNumberTable().getLineNumberTable()) {
            getClassReport(m.getClassInfo()).addLinePropertyIfNull(ln.getLineNumber(), "color", "lightgreen");
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Generating report for method: " + m);
        }
        ControlFlowGraph flowGraph = project.getFlowGraph(m);
        Map<String, Object> stats = new TreeMap<String, Object>();
        stats.put("#nodes", flowGraph.vertexSet().size() - 2);
        stats.put("number of words", flowGraph.getNumberOfWords());
        this.addDetailedReport(m, new DetailedMethodReport(config, project, m, "CFG", stats, null, null), true);
        generateDetailedReport(m);
    }
    for (ClassInfo c : project.getCallGraph().getClassInfos()) {
        ClassReport cr = getClassReport(c);
        String page = pageOf(c);
        HashMap<String, Object> ctx = new HashMap<String, Object>();
        ctx.put("classreport", cr);
        try {
            this.generateFile("class.vm", config.getReportFile(page), ctx);
        } catch (Exception e) {
            logger.error(e);
        }
        addPage("details/" + c.getClassName(), page);
    }
}
Also used : HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) LineNumber(org.apache.bcel.classfile.LineNumber) BadConfigurationException(com.jopdesign.common.config.Config.BadConfigurationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ResourceNotFoundException(org.apache.velocity.exception.ResourceNotFoundException) ControlFlowGraph(com.jopdesign.common.code.ControlFlowGraph) MethodInfo(com.jopdesign.common.MethodInfo) ClassInfo(com.jopdesign.common.ClassInfo)

Example 48 with ClassInfo

use of com.jopdesign.common.ClassInfo 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));
}
Also used : InstructionList(org.apache.bcel.generic.InstructionList) ILOAD(org.apache.bcel.generic.ILOAD) InstructionHandle(org.apache.bcel.generic.InstructionHandle) AppInfo(com.jopdesign.common.AppInfo) TestFramework(com.jopdesign.common.TestFramework) AppSetup(com.jopdesign.common.AppSetup) MethodInfo(com.jopdesign.common.MethodInfo) MethodCode(com.jopdesign.common.MethodCode) ClassInfo(com.jopdesign.common.ClassInfo)

Example 49 with ClassInfo

use of com.jopdesign.common.ClassInfo in project jop by jop-devel.

the class WcetAppInfoTest method main.

/*
     * DEMO
     * ~~~~
     */
/* small demo using the class loader */
public static void main(String[] argv) {
    AppSetup appSetup = new AppSetup();
    WCETTool wcetTool = new WCETTool();
    appSetup.registerTool("wcet", wcetTool);
    Config config = appSetup.getConfig();
    config.setOption(ProjectConfig.PROJECT_NAME, "typegraph");
    AppInfo appInfo = appSetup.initAndLoad(argv, false, false, false);
    ProjectConfig pConfig = wcetTool.getProjectConfig();
    try {
        System.out.println("Classloader Demo: " + pConfig.getAppClassName());
        String rootClass = pConfig.getAppClassName();
        String rootPkg = rootClass.substring(0, rootClass.lastIndexOf("."));
        ClassInfo ci = appInfo.getClassInfo(pConfig.getAppClassName());
        System.out.println("Source file: " + ci.getSourceFileName());
        System.out.println("Root class: " + ci.toString());
        {
            System.out.println("Writing type graph to " + pConfig.getOutFile("typegraph.png"));
            File dotFile = pConfig.getOutFile("typegraph.dot");
            FileWriter dotWriter = new FileWriter(dotFile);
            // FIXME TypeGraph is not used anymore, export ClassInfo/.. graph
            TypeGraph typeGraph = new TypeGraph();
            typeGraph.exportDOT(dotWriter, rootPkg);
            dotWriter.close();
            InvokeDot.invokeDot(wcetTool.getConfig(), dotFile, pConfig.getOutFile("typegraph.png"));
        }
        SuperGraph sg = new SuperGraph(appInfo, pConfig.getTargetMethodInfo().getCode().getControlFlowGraph(false), 0);
        {
            System.out.println("Writing supergraph graph to " + pConfig.getOutFile("supergraph.png"));
            File dotFile = pConfig.getOutFile("callgraph.dot");
            sg.exportDOT(dotFile);
            InvokeDot.invokeDot(wcetTool.getConfig(), dotFile, pConfig.getOutFile("supergraph.png"));
        }
        CallGraph cg = appInfo.buildCallGraph(false);
        {
            System.out.println("Writing call graph to " + pConfig.getOutFile("callgraph.png"));
            File dotFile = pConfig.getOutFile("callgraph.dot");
            FileWriter dotWriter = new FileWriter(dotFile);
            cg.exportDOT(dotWriter);
            dotWriter.close();
            InvokeDot.invokeDot(wcetTool.getConfig(), dotFile, pConfig.getOutFile("callgraph.png"));
        }
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Config(com.jopdesign.common.config.Config) SuperGraph(com.jopdesign.common.code.SuperGraph) FileWriter(java.io.FileWriter) TypeGraph(com.jopdesign.common.graphutils.TypeGraph) IOException(java.io.IOException) IOException(java.io.IOException) AppInfo(com.jopdesign.common.AppInfo) CallGraph(com.jopdesign.common.code.CallGraph) AppSetup(com.jopdesign.common.AppSetup) File(java.io.File) ClassInfo(com.jopdesign.common.ClassInfo)

Aggregations

ClassInfo (com.jopdesign.common.ClassInfo)49 MethodInfo (com.jopdesign.common.MethodInfo)19 DefaultEdge (org.jgrapht.graph.DefaultEdge)8 AppInfo (com.jopdesign.common.AppInfo)7 HashMap (java.util.HashMap)7 InstructionHandle (org.apache.bcel.generic.InstructionHandle)7 HashSet (java.util.HashSet)6 Set (java.util.Set)6 IOException (java.io.IOException)5 LinkedList (java.util.LinkedList)5 FieldInfo (com.jopdesign.common.FieldInfo)4 JavaClassFormatError (com.jopdesign.common.misc.JavaClassFormatError)4 MemberID (com.jopdesign.common.type.MemberID)4 BitSet (java.util.BitSet)3 AppSetup (com.jopdesign.common.AppSetup)2 MethodCode (com.jopdesign.common.MethodCode)2 BasicBlock (com.jopdesign.common.code.BasicBlock)2 CallString (com.jopdesign.common.code.CallString)2 CFGNode (com.jopdesign.common.code.ControlFlowGraph.CFGNode)2 ExecutionContext (com.jopdesign.common.code.ExecutionContext)2