Search in sources :

Example 1 with LineNumber

use of org.apache.bcel.classfile.LineNumber in project fb-contrib by mebigfatguy.

the class PossiblyRedundantMethodCalls method getLineNumber.

/**
 * returns the source line number for the pc, or just the pc if the line number table doesn't exist
 *
 * @param pc
 *            current pc
 * @return the line number
 */
private int getLineNumber(int pc) {
    LineNumberTable lnt = getMethod().getLineNumberTable();
    if (lnt == null) {
        return pc;
    }
    LineNumber[] lns = lnt.getLineNumberTable();
    if (lns == null) {
        return pc;
    }
    if (pc > lns[lns.length - 1].getStartPC()) {
        return lns[lns.length - 1].getLineNumber();
    }
    int lo = 0;
    int hi = lns.length - 2;
    int mid = 0;
    while (lo <= hi) {
        mid = (lo + hi) >>> 1;
        if (pc < lns[mid].getStartPC()) {
            hi = mid - 1;
        } else if (pc >= lns[mid + 1].getStartPC()) {
            lo = mid + 1;
        } else {
            break;
        }
    }
    return lns[mid].getLineNumber();
}
Also used : LineNumberTable(org.apache.bcel.classfile.LineNumberTable) LineNumber(org.apache.bcel.classfile.LineNumber)

Example 2 with LineNumber

use of org.apache.bcel.classfile.LineNumber 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 3 with LineNumber

use of org.apache.bcel.classfile.LineNumber in project fb-contrib by mebigfatguy.

the class AttributesUtils method isValidLineNumber.

/**
 * returns whether the pc is at a line number that also appears for a another byte code offset later on in the method. If this occurs we are in a jdk6
 * finally replicated block, and so don't report this. If the code has no line number table, then just report it.
 *
 * @param obj
 *            the code object to find line number attributes from
 * @param pc
 *            the pc to check
 *
 * @return whether the pc is in user code
 */
public static boolean isValidLineNumber(Code obj, int pc) {
    LineNumberTable lnt = obj.getLineNumberTable();
    if (lnt == null)
        return true;
    LineNumber[] lineNumbers = lnt.getLineNumberTable();
    if (lineNumbers == null)
        return true;
    int lo = 0;
    int hi = lineNumbers.length - 1;
    int mid = 0;
    int linePC = 0;
    while (lo <= hi) {
        mid = (lo + hi) >>> 1;
        linePC = lineNumbers[mid].getStartPC();
        if (linePC == pc)
            break;
        if (linePC < pc)
            lo = mid + 1;
        else
            hi = mid - 1;
    }
    int lineNo = lineNumbers[mid].getLineNumber();
    for (int i = 0; i < lineNumbers.length; i++) {
        if ((mid != i) && (lineNumbers[i].getLineNumber() == lineNo))
            return false;
    }
    return true;
}
Also used : LineNumberTable(org.apache.bcel.classfile.LineNumberTable) LineNumber(org.apache.bcel.classfile.LineNumber)

Aggregations

LineNumber (org.apache.bcel.classfile.LineNumber)3 LineNumberTable (org.apache.bcel.classfile.LineNumberTable)2 ClassInfo (com.jopdesign.common.ClassInfo)1 MethodInfo (com.jopdesign.common.MethodInfo)1 ControlFlowGraph (com.jopdesign.common.code.ControlFlowGraph)1 BadConfigurationException (com.jopdesign.common.config.Config.BadConfigurationException)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 TreeMap (java.util.TreeMap)1 ResourceNotFoundException (org.apache.velocity.exception.ResourceNotFoundException)1