Search in sources :

Example 1 with Instruction

use of org.jacoco.core.internal.flow.Instruction in project jacoco by jacoco.

the class MethodAnalyzer method visitEnd.

@Override
public void visitEnd() {
    // Wire jumps:
    for (final Jump j : jumps) {
        LabelInfo.getInstruction(j.target).setPredecessor(j.source, j.branch);
    }
    // Propagate probe values:
    for (final CoveredProbe p : coveredProbes) {
        p.instruction.setCovered(p.branch);
    }
    // Merge:
    for (final Instruction i : instructions) {
        final AbstractInsnNode m = i.getNode();
        final AbstractInsnNode r = findRepresentative(m);
        if (r != m) {
            ignored.add(m);
            nodeToInstruction.get(r).merge(i);
        }
    }
    // Report result:
    coverage.ensureCapacity(firstLine, lastLine);
    for (final Instruction i : instructions) {
        if (ignored.contains(i.getNode())) {
            continue;
        }
        final int total = i.getBranches();
        final int covered = i.getCoveredBranches();
        final ICounter instrCounter = covered == 0 ? CounterImpl.COUNTER_1_0 : CounterImpl.COUNTER_0_1;
        final ICounter branchCounter = total > 1 ? CounterImpl.getInstance(total - covered, covered) : CounterImpl.COUNTER_0_0;
        coverage.increment(instrCounter, branchCounter, i.getLine());
    }
    coverage.incrementMethodCounter();
}
Also used : ICounter(org.jacoco.core.analysis.ICounter) Instruction(org.jacoco.core.internal.flow.Instruction) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode)

Example 2 with Instruction

use of org.jacoco.core.internal.flow.Instruction in project jacoco by jacoco.

the class MethodAnalyzer method visitInsn.

private void visitInsn() {
    final Instruction insn = new Instruction(currentNode, currentLine);
    nodeToInstruction.put(currentNode, insn);
    instructions.add(insn);
    if (lastInsn != null) {
        insn.setPredecessor(lastInsn, 0);
    }
    final int labelCount = currentLabel.size();
    if (labelCount > 0) {
        for (int i = labelCount; --i >= 0; ) {
            LabelInfo.setInstruction(currentLabel.get(i), insn);
        }
        currentLabel.clear();
    }
    lastInsn = insn;
}
Also used : Instruction(org.jacoco.core.internal.flow.Instruction)

Example 3 with Instruction

use of org.jacoco.core.internal.flow.Instruction in project bazel by bazelbuild.

the class MethodProbesMapper method visitEnd.

/** Finishing the method */
@Override
public void visitEnd() {
    for (Jump jump : jumps) {
        Instruction insn = labelToInsn.get(jump.target);
        insn.setPredecessor(jump.source);
        predecessors.put(insn, jump.source);
    }
    // Compute CovExp for every instruction.
    for (Map.Entry<Integer, Instruction> entry : probeToInsn.entrySet()) {
        int probeId = entry.getKey();
        Instruction ins = entry.getValue();
        Instruction insn = ins;
        CovExp exp = new ProbeExp(probeId);
        // Compute CovExp for the probed instruction.
        CovExp existingExp = insnToCovExp.get(insn);
        if (existingExp != null) {
            // a new branch.
            if (existingExp instanceof BranchExp) {
                BranchExp branchExp = (BranchExp) existingExp;
                branchExp.add(exp);
            } else {
            // This can only happen if the internal data is inconsistent.
            // The instruction is a predecessor of another instruction and also
            // has a probe, but the branch count is not > 1.
            }
        } else {
            if (insn.getBranches() > 1) {
                exp = new BranchExp(exp);
            }
            insnToCovExp.put(insn, exp);
        }
        Instruction predecessor = predecessors.get(insn);
        while (predecessor != null) {
            if (predecessor.getBranches() > 1) {
                boolean isNewBranch = updateBranchPredecessor(predecessor, insn, exp);
                if (!isNewBranch) {
                    // If the branch already exists, no need to visit predecessors any more.
                    break;
                }
            } else {
                // No branch at predecessor, use the same CovExp
                insnToCovExp.put(predecessor, exp);
            }
            insn = predecessor;
            exp = insnToCovExp.get(predecessor);
            predecessor = predecessors.get(insn);
        }
    }
    // Merge branches in the instructions on the same line
    for (Instruction insn : instructions) {
        if (insn.getBranches() > 1) {
            CovExp insnExp = insnToCovExp.get(insn);
            if (insnExp != null && (insnExp instanceof BranchExp)) {
                BranchExp exp = (BranchExp) insnExp;
                BranchExp lineExp = lineToBranchExp.get(insn.getLine());
                if (lineExp == null) {
                    lineToBranchExp.put(insn.getLine(), exp);
                } else {
                    lineExp.merge(exp);
                }
            } else {
            // If we reach here, the internal data of the mapping is inconsistent, either
            // 1) An instruction has branches but we do not create BranchExp for it.
            // 2) An instruction has branches but it does not have an associated CovExp.
            }
        }
    }
}
Also used : Instruction(org.jacoco.core.internal.flow.Instruction) TreeMap(java.util.TreeMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with Instruction

use of org.jacoco.core.internal.flow.Instruction in project bazel by bazelbuild.

the class MethodProbesMapper method visitInsn.

/** Visitor method to append a new Instruction */
private void visitInsn() {
    Instruction instruction = new Instruction(currentLine);
    instructions.add(instruction);
    if (lastInstruction != null) {
        // Update branch of lastInstruction
        instruction.setPredecessor(lastInstruction);
        // Update local cache
        predecessors.put(instruction, lastInstruction);
    }
    for (Label label : currentLabels) {
        labelToInsn.put(label, instruction);
    }
    // Update states
    currentLabels.clear();
    lastInstruction = instruction;
}
Also used : Label(org.objectweb.asm.Label) Instruction(org.jacoco.core.internal.flow.Instruction)

Aggregations

Instruction (org.jacoco.core.internal.flow.Instruction)4 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ICounter (org.jacoco.core.analysis.ICounter)1 Label (org.objectweb.asm.Label)1 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)1