Class FinallyFilter

java.lang.Object
org.jacoco.core.internal.analysis.filter.FinallyFilter
All Implemented Interfaces:
IFilter

public final class FinallyFilter extends Object implements IFilter
Filters duplicates of finally blocks that compiler generates. To understand algorithm of filtering, consider following example:
 try {
        if (x) {
                a();
                return; // 1
        }
        b(); // 2
 } catch (Exception e) {
        c(); // 3
 } finally {
        d(); // 4
 }
 
There are 4 distinct points of exit out of these "try/catch/finally" blocks - three without exception, and one with Throwable if it is thrown prior to reaching first three points of exit. "finally" block must be executed just before these points, so there must be 4 copies of its bytecode instructions. One of them handles Throwable ("catch-any") and must cover all instructions of "try/catch" blocks. But must not cover instructions of other duplicates, because instructions of "finally" block also can cause Throwable to be thrown. Therefore there will be multiple MethodNode.tryCatchBlocks with TryCatchBlockNode.type null with same TryCatchBlockNode.handler for different non-intersecting bytecode regions (TryCatchBlockNode.start, TryCatchBlockNode.end). And each exit out of these regions, except one that handles Throwable, will contain duplicate of "finally" block. To determine exits out of these regions, they all must be processed together at once, because execution can branch from one region to another (like it is in given example due to "if" statement).
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private static void
    filter(IFilterOutput output, List<org.objectweb.asm.tree.TryCatchBlockNode> tryCatchBlocks, org.objectweb.asm.tree.TryCatchBlockNode catchAnyBlock)
     
    void
    filter(org.objectweb.asm.tree.MethodNode methodNode, IFilterContext context, IFilterOutput output)
    This method is called for every method.
    private static boolean
    isSame(int size, org.objectweb.asm.tree.AbstractInsnNode e, org.objectweb.asm.tree.AbstractInsnNode n)
     
    private static void
    merge(IFilterOutput output, int size, org.objectweb.asm.tree.AbstractInsnNode e, org.objectweb.asm.tree.AbstractInsnNode n)
     
    private static org.objectweb.asm.tree.AbstractInsnNode
    next(org.objectweb.asm.tree.AbstractInsnNode i)
     
    private static int
    size(org.objectweb.asm.tree.AbstractInsnNode i)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • FinallyFilter

      public FinallyFilter()
  • Method Details

    • filter

      public void filter(org.objectweb.asm.tree.MethodNode methodNode, IFilterContext context, IFilterOutput output)
      Description copied from interface: IFilter
      This method is called for every method. The filter implementation is expected to inspect the provided method and report its result to the given IFilterOutput instance.
      Specified by:
      filter in interface IFilter
      Parameters:
      methodNode - method to inspect
      context - context information for the method
      output - callback to report filtering results to
    • filter

      private static void filter(IFilterOutput output, List<org.objectweb.asm.tree.TryCatchBlockNode> tryCatchBlocks, org.objectweb.asm.tree.TryCatchBlockNode catchAnyBlock)
    • merge

      private static void merge(IFilterOutput output, int size, org.objectweb.asm.tree.AbstractInsnNode e, org.objectweb.asm.tree.AbstractInsnNode n)
    • isSame

      private static boolean isSame(int size, org.objectweb.asm.tree.AbstractInsnNode e, org.objectweb.asm.tree.AbstractInsnNode n)
    • size

      private static int size(org.objectweb.asm.tree.AbstractInsnNode i)
      Returns:
      number of instructions inside given "catch-any" handler
    • next

      private static org.objectweb.asm.tree.AbstractInsnNode next(org.objectweb.asm.tree.AbstractInsnNode i)