edu.umd.cs.findbugs.ba
Class BetterCFGBuilder2

java.lang.Object
  extended by edu.umd.cs.findbugs.ba.BetterCFGBuilder2
All Implemented Interfaces:
CFGBuilder, Debug, EdgeTypes

public class BetterCFGBuilder2
extends java.lang.Object
implements CFGBuilder, EdgeTypes, Debug

A CFGBuilder that really tries to construct accurate control flow graphs. The CFGs it creates have accurate exception edges, and have accurately inlined JSR subroutines.

Author:
David Hovemeyer
See Also:
CFG

Nested Class Summary
private static class BetterCFGBuilder2.Context
          Inlining context.
private static class BetterCFGBuilder2.EscapeTarget
          A placeholder for a control edge that escapes its subroutine to return control back to an outer (calling) subroutine.
private  class BetterCFGBuilder2.Subroutine
          JSR subroutine.
private static class BetterCFGBuilder2.WorkListItem
          A work list item for creating the CFG for a subroutine.
 
Field Summary
private  CFG cfg
           
private  org.apache.bcel.generic.ConstantPoolGen cpg
           
private static boolean DEBUG
           
private static java.util.LinkedList<BetterCFGBuilder2.EscapeTarget> emptyEscapeTargetList
           
private  ExceptionHandlerMap exceptionHandlerMap
           
private  java.util.IdentityHashMap<org.apache.bcel.generic.InstructionHandle,BetterCFGBuilder2.Subroutine> jsrSubroutineMap
           
private  org.apache.bcel.generic.MethodGen methodGen
           
private static boolean NO_LOAD_CONSTANT_EXCEPTIONS
           
private static boolean NO_STATIC_FIELD_EXCEPTIONS
           
private  java.util.LinkedList<BetterCFGBuilder2.Subroutine> subroutineWorkList
           
private  BetterCFGBuilder2.Subroutine topLevelSubroutine
           
private  java.util.BitSet usedInstructionSet
           
 
Fields inherited from interface edu.umd.cs.findbugs.ba.EdgeTypes
BACKEDGE_SOURCE_EDGE, BACKEDGE_TARGET_EDGE, CHECKED_EXCEPTIONS_FLAG, EXIT_EDGE, EXPLICIT_EXCEPTIONS_FLAG, FALL_THROUGH_EDGE, GOTO_EDGE, HANDLED_EXCEPTION_EDGE, IFCMP_EDGE, JSR_EDGE, RET_EDGE, RETURN_EDGE, START_EDGE, SWITCH_DEFAULT_EDGE, SWITCH_EDGE, UNHANDLED_EXCEPTION_EDGE, UNKNOWN_EDGE
 
Fields inherited from interface edu.umd.cs.findbugs.ba.Debug
CHECK_ASSERTIONS, VERIFY_INTEGRITY
 
Constructor Summary
BetterCFGBuilder2(org.apache.bcel.generic.MethodGen methodGen)
          Constructor.
 
Method Summary
 void build()
          Build the CFG.
private  void build(BetterCFGBuilder2.Subroutine subroutine)
          Build a subroutine.
 CFG getCFG()
          Get the CFG built by this object.
private  void handleExceptions(BetterCFGBuilder2.Subroutine subroutine, org.apache.bcel.generic.InstructionHandle pei, BasicBlock etb)
          Add exception edges for given instruction.
 void inline(BetterCFGBuilder2.Context context)
          Inline a subroutine into a calling context.
private  CFG inlineAll()
          Inline all JSR subroutines into the top-level subroutine.
private static boolean isMerge(org.apache.bcel.generic.InstructionHandle handle)
          Determine whether or not the given instruction is a control flow merge.
private  boolean isPEI(org.apache.bcel.generic.InstructionHandle handle)
          Return whether or not the given instruction can throw exceptions.
static void main(java.lang.String[] argv)
          Test driver.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

private static final boolean DEBUG

NO_STATIC_FIELD_EXCEPTIONS

private static final boolean NO_STATIC_FIELD_EXCEPTIONS

NO_LOAD_CONSTANT_EXCEPTIONS

private static final boolean NO_LOAD_CONSTANT_EXCEPTIONS

emptyEscapeTargetList

private static final java.util.LinkedList<BetterCFGBuilder2.EscapeTarget> emptyEscapeTargetList

methodGen

private org.apache.bcel.generic.MethodGen methodGen

cpg

private org.apache.bcel.generic.ConstantPoolGen cpg

exceptionHandlerMap

private ExceptionHandlerMap exceptionHandlerMap

usedInstructionSet

private java.util.BitSet usedInstructionSet

subroutineWorkList

private java.util.LinkedList<BetterCFGBuilder2.Subroutine> subroutineWorkList

jsrSubroutineMap

private java.util.IdentityHashMap<org.apache.bcel.generic.InstructionHandle,BetterCFGBuilder2.Subroutine> jsrSubroutineMap

topLevelSubroutine

private BetterCFGBuilder2.Subroutine topLevelSubroutine

cfg

private CFG cfg
Constructor Detail

BetterCFGBuilder2

public BetterCFGBuilder2(org.apache.bcel.generic.MethodGen methodGen)
Constructor.

Parameters:
methodGen - the method to build a CFG for
Method Detail

build

public void build()
           throws CFGBuilderException
Description copied from interface: CFGBuilder
Build the CFG.

Specified by:
build in interface CFGBuilder
Throws:
CFGBuilderException

getCFG

public CFG getCFG()
Description copied from interface: CFGBuilder
Get the CFG built by this object. Assumes that the build() method has already been called.

Specified by:
getCFG in interface CFGBuilder
Returns:
the CFG

build

private void build(BetterCFGBuilder2.Subroutine subroutine)
            throws CFGBuilderException
Build a subroutine. We iteratively add basic blocks to the subroutine until there are no more blocks reachable from the calling context. As JSR instructions are encountered, new Subroutines are added to the subroutine work list.

Parameters:
subroutine - the subroutine
Throws:
CFGBuilderException

handleExceptions

private void handleExceptions(BetterCFGBuilder2.Subroutine subroutine,
                              org.apache.bcel.generic.InstructionHandle pei,
                              BasicBlock etb)
Add exception edges for given instruction.

Parameters:
subroutine - the subroutine containing the instruction
pei - the instruction which throws an exception
etb - the exception thrower block (ETB) for the instruction

isPEI

private boolean isPEI(org.apache.bcel.generic.InstructionHandle handle)
Return whether or not the given instruction can throw exceptions.

Parameters:
handle - the instruction
Returns:
true if the instruction can throw an exception, false otherwise

isMerge

private static boolean isMerge(org.apache.bcel.generic.InstructionHandle handle)
Determine whether or not the given instruction is a control flow merge.

Parameters:
handle - the instruction
Returns:
true if the instruction is a control merge, false otherwise

inlineAll

private CFG inlineAll()
               throws CFGBuilderException
Inline all JSR subroutines into the top-level subroutine. This produces a complete CFG for the entire method, in which all JSR subroutines are inlined.

Returns:
the CFG for the method
Throws:
CFGBuilderException

inline

public void inline(BetterCFGBuilder2.Context context)
            throws CFGBuilderException
Inline a subroutine into a calling context.

Parameters:
context - the Context
Throws:
CFGBuilderException

main

public static void main(java.lang.String[] argv)
                 throws java.lang.Exception
Test driver.

Throws:
java.lang.Exception