Class BranchWrapper


  • public class BranchWrapper
    extends java.lang.Object
    Wrapper for branch handle. This preserves a snapshot of the stack state for the branch instruction, matching it against the stack state for the target instruction when set.
    Version:
    1.0
    Author:
    Dennis M. Sosnoski
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private BranchHandle m_branchHandle
      Actual wrapped instruction handle.
      private java.lang.Object m_sourceObject
      Object that generated branch.
      private java.lang.Throwable m_sourceTrace
      Code generation backtrace for source of branch.
      private java.lang.String[] m_stackTypes
      Stack state for branch origin.
      private static boolean s_errorOverride
      Continue on after code generation error flag.
      private static boolean s_trackSource
      Track source code location for generated branches.
    • Constructor Summary

      Constructors 
      Constructor Description
      BranchWrapper​(BranchHandle hand, java.lang.String[] types, java.lang.Object src)
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private java.lang.String buildReport​(java.lang.String text, java.lang.String[] types, MethodBuilder mb)
      Report branch target error.
      private java.lang.String describeStack​(java.lang.String[] types)
      Generate description of stack state.
      (package private) java.lang.String[] getStackState()
      Get branch origin stack state information.
      static void setErrorOverride​(boolean over)
      Set target setting error override state.
      (package private) void setTarget​(InstructionHandle hand, java.lang.String[] types, MethodBuilder mb)
      Set target instruction for branch.
      void setTarget​(BranchTarget target, MethodBuilder mb)
      Set target instruction for branch.
      static void setTracking​(boolean track)
      Set branch code generation tracking state.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • s_trackSource

        private static boolean s_trackSource
        Track source code location for generated branches.
      • s_errorOverride

        private static boolean s_errorOverride
        Continue on after code generation error flag.
      • m_branchHandle

        private final BranchHandle m_branchHandle
        Actual wrapped instruction handle.
      • m_stackTypes

        private final java.lang.String[] m_stackTypes
        Stack state for branch origin.
      • m_sourceObject

        private final java.lang.Object m_sourceObject
        Object that generated branch.
      • m_sourceTrace

        private final java.lang.Throwable m_sourceTrace
        Code generation backtrace for source of branch.
    • Constructor Detail

      • BranchWrapper

        BranchWrapper​(BranchHandle hand,
                      java.lang.String[] types,
                      java.lang.Object src)
        Constructor.
        Parameters:
        hand - branch handle
        types - array of types of values on stack
        src - object responsible for generating branch
    • Method Detail

      • getStackState

        java.lang.String[] getStackState()
        Get branch origin stack state information.
        Returns:
        array of types of values on stack
      • describeStack

        private java.lang.String describeStack​(java.lang.String[] types)
        Generate description of stack state.
        Parameters:
        types - array of types on stack
        Returns:
        stack state description
      • buildReport

        private java.lang.String buildReport​(java.lang.String text,
                                             java.lang.String[] types,
                                             MethodBuilder mb)
        Report branch target error. Dumps the stack trace for the source of the branch, if source tracking is enabled, and generates an exception that includes the stack state information.
        Parameters:
        text - basic error message text
        types - stack state description
        mb - method builder using this code
        Returns:
        complete error description text
      • setTarget

        void setTarget​(InstructionHandle hand,
                       java.lang.String[] types,
                       MethodBuilder mb)
        Set target instruction for branch. Validates the branch source stack state against the branch target stack state.
        Parameters:
        hand - target branch instruction handle
        types - stack state description
        mb - method builder using this code
      • setTarget

        public void setTarget​(BranchTarget target,
                              MethodBuilder mb)
        Set target instruction for branch. Validates the branch source stack state against the branch target stack state.
        Parameters:
        target - branch target wrapper
        mb - method builder using this code
      • setTracking

        public static void setTracking​(boolean track)
        Set branch code generation tracking state. When set, this saves a stack trace for each generated branch instruction, allowing the source of a branch to be traced when an error occurs in setting the branch target.
        Parameters:
        track - true to enable branch code generation tracking, false to disable it
      • setErrorOverride

        public static void setErrorOverride​(boolean over)
        Set target setting error override state. When set, this blocks throwing an exception when an error occurs on setting the branch target, instead just printing the information to the console.
        Parameters:
        over - true to override exception on target error, false to allow it