Class MethodBuilder

  • Direct Known Subclasses:
    ExceptionMethodBuilder

    public abstract class MethodBuilder
    extends BindingMethod
    Method builder. Organizes and tracks the creation of a method, providing convenience methods for common operations. This is customized for the needs of JiBX, with some predetermined settings as appropriate. It supplies hash code and equality checking based on the method signature and actual byte code of the generated method, ignoring the method name.
    Author:
    Dennis M. Sosnoski
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected MethodBuilder​(java.lang.String name, Type ret, Type[] args, ClassFile cf, int access)
      Constructor.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void addException​(java.lang.String name)
      Add exception to those needing handling.
      int addLocal​(java.lang.String name, Type type)
      Add local variable to method.
      ClassItem addMethod()
      Add constructed method to class.
      void addMethodExceptions​(ClassItem method)
      Add exceptions thrown by called method to those needing handling.
      private void append​(CompoundInstruction ins)
      Append compound instruction to method.
      private void append​(Instruction ins)
      Append instruction to method.
      void appendAASTORE()
      Append an AASTORE to the instruction list.
      void appendACONST_NULL()
      Append an ACONST_NULL to the instruction list.
      void appendALOAD​(java.lang.String type)
      Append appropriate array load to the instruction list.
      void appendARRAYLENGTH()
      Append an ARRAYLENGTH to the instruction list.
      void appendASTORE​(java.lang.String type)
      Append the appropriate array store to the instruction list.
      void appendCall​(ClassItem item)
      Create invoke instruction for static, member, or interface method and append to method.
      void appendCallInit​(java.lang.String name, java.lang.String signature)
      Create invoke initializer instruction from signature and append to method.
      void appendCallInterface​(java.lang.String method, java.lang.String signature)
      Create invoke interface method instruction from signature and append to method.
      void appendCallStatic​(java.lang.String method, java.lang.String signature)
      Create invoke static method instruction from signature and append to method.
      void appendCallVirtual​(java.lang.String method, java.lang.String signature)
      Create invoke virtual method instruction from signature and append to method.
      void appendCreateArray​(java.lang.String type)
      Append instruction to create instance of array.
      void appendCreateCast​(java.lang.String to)
      Append check cast instruction from object (if needed).
      void appendCreateCast​(java.lang.String from, java.lang.String to)
      Append check cast instruction (if needed).
      void appendCreateNew​(java.lang.String name)
      Append instruction to create instance of class.
      void appendDCMPG()
      Append an DCMPG to the instruction list.
      void appendDUP()
      Append a DUP to the instruction list.
      void appendDUP_X1()
      Append a DUP_X1 to the instruction list.
      void appendDUP2()
      Append a DUP2 to the instruction list.
      void appendFCMPG()
      Append an FCMPG to the instruction list.
      void appendGet​(ClassItem item)
      Create get instruction and append to method.
      void appendGetField​(ClassItem item)
      Create getfield instruction and append to method.
      void appendGetStatic​(ClassItem item)
      Create getstatic instruction and append to method.
      void appendIASTORE()
      Append an IASTORE to the instruction list.
      void appendICONST_0()
      Append an ICONST_0 to the instruction list.
      void appendICONST_1()
      Append an ICONST_1 to the instruction list.
      BranchWrapper appendIF_ICMPNE​(java.lang.Object src)
      Append IF_ICMPNE branch instruction to method.
      BranchWrapper appendIFEQ​(java.lang.Object src)
      Append IFEQ branch instruction to method.
      BranchWrapper appendIFGE​(java.lang.Object src)
      Append IFGE branch instruction to method.
      BranchWrapper appendIFLT​(java.lang.Object src)
      Append IFLT branch instruction to method.
      BranchWrapper appendIFNE​(java.lang.Object src)
      Append IFNE branch instruction to method.
      BranchWrapper appendIFNONNULL​(java.lang.Object src)
      Append IFNONNULL branch instruction to method.
      BranchWrapper appendIFNULL​(java.lang.Object src)
      Append IFNULL branch instruction to method.
      void appendIncrementLocal​(int inc, int slot)
      Append instruction to increment local integer variable.
      void appendInstanceOf​(java.lang.String to)
      Append instanceof check instruction.
      void appendISUB()
      Append an ISUB to the instruction list.
      void appendIXOR()
      Append an IXOR to the instruction list.
      void appendLCMP()
      Append an LCMP to the instruction list.
      void appendLoadConstant​(int value)
      Create load constant instruction and append to method.
      void appendLoadConstant​(java.lang.Object value)
      Create load constant instruction and append to method.
      void appendLoadConstant​(java.lang.String value)
      Create load constant instruction and append to method.
      void appendLoadLocal​(int slot)
      Append instruction to load local variable.
      void appendPOP()
      Append a POP to the instruction list.
      void appendPOP2()
      Append a POP2 to the instruction list.
      void appendPut​(ClassItem item)
      Create put instruction and append to method.
      void appendPutField​(ClassItem item)
      Create putfield instruction and append to method.
      void appendPutStatic​(ClassItem item)
      Create putstatic instruction and append to method.
      void appendReturn()
      Append simple return.
      void appendReturn​(Type type)
      Append typed return.
      void appendStoreLocal​(int slot)
      Append instruction to store local variable.
      void appendSWAP()
      Append a SWAP to the instruction list.
      void appendSWAP1For2()
      Append instructions to exchange a single-word value on the top of the stack with the double-word value below it on the stack.
      BranchTarget appendTargetACONST_NULL()
      Append an ACONST_NULL to the instruction list as a branch target.
      BranchTarget appendTargetCreateNew​(java.lang.String name)
      Append instruction to create instance of class as a branch target.
      private BranchTarget appendTargetInstruction​(CompoundInstruction inst)
      Append a compound instruction to the list as a branch target.
      private BranchTarget appendTargetInstruction​(Instruction inst)
      Append an instruction to the list as a branch target.
      BranchTarget appendTargetLoadConstant​(int value)
      Append a load constant instruction as a branch target.
      BranchTarget appendTargetLoadConstant​(java.lang.String value)
      Append a load constant instruction as a branch target.
      BranchTarget appendTargetNOP()
      Append a NOP to the instruction list as a branch target.
      void appendThrow()
      Append exception throw.
      BranchWrapper appendUnconditionalBranch​(java.lang.Object src)
      Append unconditional branch instruction to method.
      void codeComplete​(boolean suffix)
      Complete method construction.
      protected LocalVariableGen createLocal​(java.lang.String name, Type type)
      Add local variable to method.
      private java.lang.String describeStack()
      Generate description of current stack state.
      int getAccessFlags()
      Get access flags.
      protected InstructionHandle getFirstInstruction()
      Get first instruction in method.
      ClassItem getItem()
      Get the method item.
      java.lang.Object getKeyValue​(java.lang.Object key)
      Get local variable for object.
      protected InstructionHandle getLastInstruction()
      Get last instruction in method.
      Method getMethod()
      Get the actual method.
      java.lang.String getName()
      Get name of method being constructed.
      java.lang.String getSignature()
      Get signature.
      protected abstract void handleExceptions()
      Process accumulated exceptions.
      int hashCode()
      Get hash code.
      protected void initStackState​(java.lang.String[] types)
      Initialize stack state to array of value types.
      void initStackState​(BranchWrapper branch)
      Initialize stack state to match branch source.
      void initStackState​(BranchWrapper branch, int pop)
      Initialize stack state to partially match branch source.
      protected InstructionHandle internalAppendCreateNew​(java.lang.String name)
      Internal append instruction to create instance of class.
      boolean isStackTopLong()
      Check if top item on stack is a long value.
      void setAccessFlags​(int flags)
      Set access flags.
      java.lang.Object setKeyValue​(java.lang.Object key, java.lang.Object value)
      Add keyed value to method definition.
      protected void setTarget​(InstructionHandle inst)
      Target branches if pending.
      void targetNext​(BranchWrapper branch)
      Set branch target as next instruction added to method.
      void targetNext​(BranchWrapper[] branches)
      Set branch targets as next instruction added to method.
      private java.lang.String verifyArray()
      Verify the top value in the stack state resulting from the current instruction list is an array.
      private void verifyArray​(java.lang.String type)
      Verify the top value in the stack state resulting from the current instruction list is an array of the specified type.
      private void verifyCallStack​(java.lang.String[] types)
      Verify the top values in the stack state resulting from the current instruction list.
      private void verifyCallStack​(java.lang.String clas, java.lang.String[] types)
      Verify the top values in the stack state resulting from the current instruction list.
      private void verifyCompatible​(java.lang.String type, java.lang.String need)
      Verify that a pair of value types represent compatible types.
      private void verifyStack​(java.lang.String t1)
      Verify the top value in the stack state resulting from the current instruction list.
      private void verifyStack​(java.lang.String t1, java.lang.String t2)
      Verify the top two values in the stack state resulting from the current instruction list.
      private void verifyStackDepth​(int count)
      Verify that at least the specified number of items are present on the stack.
      private void verifyStackObject()
      Verify that the top value in the stack state resulting from the current instruction list is an object reference.
      • Methods inherited from class java.lang.Object

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

      • FRAMEWORK_EXCEPTION_CLASS

        public static final java.lang.String FRAMEWORK_EXCEPTION_CLASS
        See Also:
        Constant Field Values
      • EXCEPTION_CONSTRUCTOR_SIGNATURE1

        public static final java.lang.String EXCEPTION_CONSTRUCTOR_SIGNATURE1
        See Also:
        Constant Field Values
      • EXCEPTION_CONSTRUCTOR_SIGNATURE2

        public static final java.lang.String EXCEPTION_CONSTRUCTOR_SIGNATURE2
        See Also:
        Constant Field Values
      • s_argNameLists

        protected static java.util.ArrayList s_argNameLists
        Table of argument name lists (generated as needed).
      • m_instructionBuilder

        protected InstructionBuilder m_instructionBuilder
        Builder for class instructions.
      • m_instructionList

        private InstructionList m_instructionList
        List of instructions in method definition.
      • m_stackState

        private StringStack m_stackState
        List of types currently on stack.
      • m_generator

        protected MethodGen m_generator
        Generator for constructing method.
      • m_method

        protected Method m_method
        Actual generated method information.
      • m_item

        protected ClassItem m_item
        Method class item information.
      • m_localTypes

        private java.util.ArrayList m_localTypes
        Value types associated with local variable slots.
      • m_exceptions

        protected java.util.ArrayList m_exceptions
        Exceptions needing to be handled in method (lazy create, null if not used).
      • m_hashCode

        protected int m_hashCode
        Accumulated hash code from adding instructions.
      • m_targetBranches

        protected BranchWrapper[] m_targetBranches
        Branch to be aimed at next appended instruction.
      • m_valueMap

        protected java.util.HashMap m_valueMap
        Map for initialized properties (lazy create, null if not used).
    • Constructor Detail

      • MethodBuilder

        protected MethodBuilder​(java.lang.String name,
                                Type ret,
                                Type[] args,
                                ClassFile cf,
                                int access)
        Constructor. This sets up for constructing a method with public access.
        Parameters:
        name - method name to be built
        ret - method return type
        args - types of arguments
        cf - owning class file information
        access - flags for method access
    • Method Detail

      • getName

        public java.lang.String getName()
        Get name of method being constructed.
        Specified by:
        getName in class BindingMethod
        Returns:
        name of method being constructed
      • getSignature

        public java.lang.String getSignature()
        Get signature.
        Specified by:
        getSignature in class BindingMethod
        Returns:
        signature for method
      • getAccessFlags

        public int getAccessFlags()
        Get access flags.
        Specified by:
        getAccessFlags in class BindingMethod
        Returns:
        flags for access type of method
      • setAccessFlags

        public void setAccessFlags​(int flags)
        Set access flags.
        Specified by:
        setAccessFlags in class BindingMethod
        Parameters:
        flags - access type to be set
      • getMethod

        public Method getMethod()
        Get the actual method. This can only be called once code generation is completed (after the codeComplete(boolean) method is called).
        Specified by:
        getMethod in class BindingMethod
        Returns:
        constructed method information
      • setKeyValue

        public java.lang.Object setKeyValue​(java.lang.Object key,
                                            java.lang.Object value)
        Add keyed value to method definition.
        Parameters:
        key - retrieval key
        value - keyed value
        Returns:
        prior value for key
      • getKeyValue

        public java.lang.Object getKeyValue​(java.lang.Object key)
        Get local variable for object.
        Parameters:
        key - object key for local variable
        Returns:
        local variable
      • addException

        public void addException​(java.lang.String name)
        Add exception to those needing handling.
        Parameters:
        name - fully qualified name of exception class
      • addMethodExceptions

        public void addMethodExceptions​(ClassItem method)
        Add exceptions thrown by called method to those needing handling.
        Parameters:
        method - information for method to be handled
      • getFirstInstruction

        protected InstructionHandle getFirstInstruction()
        Get first instruction in method.
        Returns:
        handle for first instruction in method
      • getLastInstruction

        protected InstructionHandle getLastInstruction()
        Get last instruction in method.
        Returns:
        handle for last instruction in method
      • setTarget

        protected final void setTarget​(InstructionHandle inst)
        Target branches if pending. This implements setting the target of branch instructions supplied using the targetNext(org.jibx.binding.classes.BranchWrapper) method.
        Parameters:
        inst - handle for appended instruction
      • describeStack

        private java.lang.String describeStack()
        Generate description of current stack state.
        Returns:
        stack state description
      • verifyCompatible

        private void verifyCompatible​(java.lang.String type,
                                      java.lang.String need)
        Verify that a pair of value types represent compatible types. This checks for equal types or downcast object types.
        Parameters:
        type - actual known type of value
        need - type needed
      • verifyStackDepth

        private void verifyStackDepth​(int count)
        Verify that at least the specified number of items are present on the stack.
        Parameters:
        count - minimum number of items required
      • verifyStack

        private void verifyStack​(java.lang.String t1)
        Verify the top value in the stack state resulting from the current instruction list.
        Parameters:
        t1 - expected type for top item on stack
      • verifyArray

        private java.lang.String verifyArray()
        Verify the top value in the stack state resulting from the current instruction list is an array.
        Returns:
        array item type
      • verifyArray

        private void verifyArray​(java.lang.String type)
        Verify the top value in the stack state resulting from the current instruction list is an array of the specified type.
        Parameters:
        type - array item type
      • verifyStack

        private void verifyStack​(java.lang.String t1,
                                 java.lang.String t2)
        Verify the top two values in the stack state resulting from the current instruction list.
        Parameters:
        t1 - expected type for first item on stack
        t2 - expected type for second item on stack
      • verifyCallStack

        private void verifyCallStack​(java.lang.String[] types)
        Verify the top values in the stack state resulting from the current instruction list. This form checks only the actual call parameters.
        Parameters:
        types - expected parameter types on stack
      • verifyCallStack

        private void verifyCallStack​(java.lang.String clas,
                                     java.lang.String[] types)
        Verify the top values in the stack state resulting from the current instruction list. This form checks both the object being called and the actual call parameters.
        Parameters:
        clas - name of method class
        types - expected parameter types on stack
      • verifyStackObject

        private void verifyStackObject()
        Verify that the top value in the stack state resulting from the current instruction list is an object reference.
      • appendIFEQ

        public BranchWrapper appendIFEQ​(java.lang.Object src)
        Append IFEQ branch instruction to method.
        Parameters:
        src - object responsible for generating branch
        Returns:
        wrapper for appended conditional branch
      • appendIFGE

        public BranchWrapper appendIFGE​(java.lang.Object src)
        Append IFGE branch instruction to method.
        Parameters:
        src - object responsible for generating branch
        Returns:
        wrapper for appended conditional branch
      • appendIFLT

        public BranchWrapper appendIFLT​(java.lang.Object src)
        Append IFLT branch instruction to method.
        Parameters:
        src - object responsible for generating branch
        Returns:
        wrapper for appended conditional branch
      • appendIFNE

        public BranchWrapper appendIFNE​(java.lang.Object src)
        Append IFNE branch instruction to method.
        Parameters:
        src - object responsible for generating branch
        Returns:
        wrapper for appended conditional branch
      • appendIFNONNULL

        public BranchWrapper appendIFNONNULL​(java.lang.Object src)
        Append IFNONNULL branch instruction to method.
        Parameters:
        src - object responsible for generating branch
        Returns:
        wrapper for appended conditional branch
      • appendIFNULL

        public BranchWrapper appendIFNULL​(java.lang.Object src)
        Append IFNULL branch instruction to method.
        Parameters:
        src - object responsible for generating branch
        Returns:
        wrapper for appended conditional branch
      • appendIF_ICMPNE

        public BranchWrapper appendIF_ICMPNE​(java.lang.Object src)
        Append IF_ICMPNE branch instruction to method.
        Parameters:
        src - object responsible for generating branch
        Returns:
        wrapper for appended conditional branch
      • appendUnconditionalBranch

        public BranchWrapper appendUnconditionalBranch​(java.lang.Object src)
        Append unconditional branch instruction to method.
        Parameters:
        src - object responsible for generating branch
        Returns:
        wrapper for appended unconditional branch
      • append

        private void append​(CompoundInstruction ins)
        Append compound instruction to method.
        Parameters:
        ins - instruction to be appended
      • append

        private void append​(Instruction ins)
        Append instruction to method.
        Parameters:
        ins - instruction to be appended
      • appendLoadConstant

        public void appendLoadConstant​(int value)
        Create load constant instruction and append to method. Builds the most appropriate type of instruction for the value.
        Parameters:
        value - constant value to be loaded
      • appendLoadConstant

        public void appendLoadConstant​(java.lang.String value)
        Create load constant instruction and append to method. Loads a String reference from the constant pool.
        Parameters:
        value - constant value to be loaded
      • appendLoadConstant

        public void appendLoadConstant​(java.lang.Object value)
        Create load constant instruction and append to method. Loads an unwrapped primitive value from the constant pool.
        Parameters:
        value - constant value to be loaded
      • appendGetField

        public void appendGetField​(ClassItem item)
        Create getfield instruction and append to method. Uses the target field information to generate the instruction.
        Parameters:
        item - information for field to be gotton
      • appendGetStatic

        public void appendGetStatic​(ClassItem item)
        Create getstatic instruction and append to method. Uses the target field information to generate the instruction.
        Parameters:
        item - information for field to be set
      • appendGet

        public void appendGet​(ClassItem item)
        Create get instruction and append to method. This generates either a getstatic or a getfield instruction, as appropriate.
        Parameters:
        item - information for field to be gotten
      • appendPutField

        public void appendPutField​(ClassItem item)
        Create putfield instruction and append to method. Uses the target field information to generate the instruction.
        Parameters:
        item - information for field to be set
      • appendPutStatic

        public void appendPutStatic​(ClassItem item)
        Create putstatic instruction and append to method. Uses the target field information to generate the instruction.
        Parameters:
        item - information for field to be set
      • appendPut

        public void appendPut​(ClassItem item)
        Create put instruction and append to method. This generates either a putstatic or a putfield instruction, as appropriate.
        Parameters:
        item - information for field to be gotten
      • appendCall

        public void appendCall​(ClassItem item)
        Create invoke instruction for static, member, or interface method and append to method. Uses the target method information to generate the correct instruction.
        Parameters:
        item - information for method to be called
      • appendCallStatic

        public void appendCallStatic​(java.lang.String method,
                                     java.lang.String signature)
        Create invoke static method instruction from signature and append to method.
        Parameters:
        method - fully qualified class and method name
        signature - method signature in standard form
      • appendCallVirtual

        public void appendCallVirtual​(java.lang.String method,
                                      java.lang.String signature)
        Create invoke virtual method instruction from signature and append to method.
        Parameters:
        method - fully qualified class and method name
        signature - method signature in standard form
      • appendCallInterface

        public void appendCallInterface​(java.lang.String method,
                                        java.lang.String signature)
        Create invoke interface method instruction from signature and append to method.
        Parameters:
        method - fully qualified interface and method name
        signature - method signature in standard form
      • appendCreateNew

        public void appendCreateNew​(java.lang.String name)
        Append instruction to create instance of class.
        Parameters:
        name - fully qualified class name
      • appendCallInit

        public void appendCallInit​(java.lang.String name,
                                   java.lang.String signature)
        Create invoke initializer instruction from signature and append to method.
        Parameters:
        name - fully qualified class name
        signature - method signature in standard form
      • appendCreateArray

        public void appendCreateArray​(java.lang.String type)
        Append instruction to create instance of array.
        Parameters:
        type - fully qualified type name of array elements
      • appendCreateCast

        public void appendCreateCast​(java.lang.String from,
                                     java.lang.String to)
        Append check cast instruction (if needed).
        Parameters:
        from - fully qualified name of current type
        to - fully qualified name of desired type
      • appendCreateCast

        public void appendCreateCast​(java.lang.String to)
        Append check cast instruction from object (if needed).
        Parameters:
        to - fully qualified name of desired type
      • appendInstanceOf

        public void appendInstanceOf​(java.lang.String to)
        Append instanceof check instruction.
        Parameters:
        to - fully qualified name of type to check
      • createLocal

        protected LocalVariableGen createLocal​(java.lang.String name,
                                               Type type)
        Add local variable to method. The current code in the method must have the initial value for the variable on the stack. The scope of the variable is defined from the last instruction to the end of the method unless otherwise modified.
        Parameters:
        name - local variable name (may be null to use default)
        type - variable type
      • addLocal

        public int addLocal​(java.lang.String name,
                            Type type)
        Add local variable to method. The current code in the method must have the initial value for the variable on the stack. The scope of the variable is defined from the preceding instruction to the end of the method.
        Parameters:
        name - local variable name
        type - variable type
        Returns:
        local variable slot number
      • appendLoadLocal

        public void appendLoadLocal​(int slot)
        Append instruction to load local variable.
        Parameters:
        slot - local variable slot to load
      • appendStoreLocal

        public void appendStoreLocal​(int slot)
        Append instruction to store local variable.
        Parameters:
        slot - local variable slot to store
      • appendIncrementLocal

        public void appendIncrementLocal​(int inc,
                                         int slot)
        Append instruction to increment local integer variable.
        Parameters:
        inc - amount of incrment
        slot - local variable slot to load
      • appendReturn

        public void appendReturn()
        Append simple return.
      • appendReturn

        public void appendReturn​(Type type)
        Append typed return.
        Parameters:
        type - returned type (may be Type.VOID)
      • appendThrow

        public void appendThrow()
        Append exception throw.
      • appendALOAD

        public void appendALOAD​(java.lang.String type)
        Append appropriate array load to the instruction list.
        Parameters:
        type - array item type expected
      • appendAASTORE

        public void appendAASTORE()
        Append an AASTORE to the instruction list. Doesn't actually check the types, just the count of items present.
      • appendASTORE

        public void appendASTORE​(java.lang.String type)
        Append the appropriate array store to the instruction list.
        Parameters:
        type - array item type expected
      • appendACONST_NULL

        public void appendACONST_NULL()
        Append an ACONST_NULL to the instruction list.
      • appendARRAYLENGTH

        public void appendARRAYLENGTH()
        Append an ARRAYLENGTH to the instruction list.
      • appendDCMPG

        public void appendDCMPG()
        Append an DCMPG to the instruction list.
      • appendDUP

        public void appendDUP()
        Append a DUP to the instruction list.
      • appendDUP2

        public void appendDUP2()
        Append a DUP2 to the instruction list.
      • appendDUP_X1

        public void appendDUP_X1()
        Append a DUP_X1 to the instruction list.
      • appendFCMPG

        public void appendFCMPG()
        Append an FCMPG to the instruction list.
      • appendIASTORE

        public void appendIASTORE()
        Append an IASTORE to the instruction list. Doesn't actually check the types, just the count of items present.
      • appendICONST_0

        public void appendICONST_0()
        Append an ICONST_0 to the instruction list.
      • appendICONST_1

        public void appendICONST_1()
        Append an ICONST_1 to the instruction list.
      • appendISUB

        public void appendISUB()
        Append an ISUB to the instruction list.
      • appendIXOR

        public void appendIXOR()
        Append an IXOR to the instruction list.
      • appendLCMP

        public void appendLCMP()
        Append an LCMP to the instruction list.
      • appendPOP

        public void appendPOP()
        Append a POP to the instruction list.
      • appendPOP2

        public void appendPOP2()
        Append a POP2 to the instruction list.
      • appendSWAP

        public void appendSWAP()
        Append a SWAP to the instruction list.
      • appendSWAP1For2

        public void appendSWAP1For2()
        Append instructions to exchange a single-word value on the top of the stack with the double-word value below it on the stack.
      • appendTargetInstruction

        private BranchTarget appendTargetInstruction​(CompoundInstruction inst)
        Append a compound instruction to the list as a branch target.
        Parameters:
        inst - compound instruction to be appended as branch target
        Returns:
        branch target information
      • appendTargetInstruction

        private BranchTarget appendTargetInstruction​(Instruction inst)
        Append an instruction to the list as a branch target.
        Parameters:
        inst - instruction to be appended as branch target
        Returns:
        branch target information
      • appendTargetNOP

        public BranchTarget appendTargetNOP()
        Append a NOP to the instruction list as a branch target.
        Returns:
        branch target information
      • appendTargetACONST_NULL

        public BranchTarget appendTargetACONST_NULL()
        Append an ACONST_NULL to the instruction list as a branch target.
        Returns:
        branch target information
      • appendTargetLoadConstant

        public BranchTarget appendTargetLoadConstant​(int value)
        Append a load constant instruction as a branch target. Builds the most appropriate type of instruction for the value.
        Parameters:
        value - constant value to be loaded
        Returns:
        branch target information
      • appendTargetLoadConstant

        public BranchTarget appendTargetLoadConstant​(java.lang.String value)
        Append a load constant instruction as a branch target. Loads a String reference from the constant pool.
        Parameters:
        value - constant value to be loaded
        Returns:
        branch target information
      • appendTargetCreateNew

        public BranchTarget appendTargetCreateNew​(java.lang.String name)
        Append instruction to create instance of class as a branch target.
        Parameters:
        name - fully qualified class name
        Returns:
        branch target information
      • internalAppendCreateNew

        protected InstructionHandle internalAppendCreateNew​(java.lang.String name)
        Internal append instruction to create instance of class. This is used by subclasses when they need access to the actual instruction handle.
        Parameters:
        name - fully qualified class name
      • isStackTopLong

        public boolean isStackTopLong()
        Check if top item on stack is a long value.
        Returns:
        true if long value, false if not
      • initStackState

        public void initStackState​(BranchWrapper branch)
        Initialize stack state to match branch source. This can be used to set the expected stack state following an unconditional transfer of control instruction. The principle here is that the code to be generated must be reached by a branch, so the stack state must match that of the branch source.
        Parameters:
        branch - wrapper for branch to be for stack initialization
      • initStackState

        public void initStackState​(BranchWrapper branch,
                                   int pop)
        Initialize stack state to partially match branch source. This can be used to set the expected stack state following an unconditional transfer of control instruction. The specified number of items are removed from the branch stack, with the assumption that code to add these items will be appended before the branch join point is reached.
        Parameters:
        branch - wrapper for branch to be for stack initialization
        pop - number of items to be removed from branch source stack state
      • initStackState

        protected void initStackState​(java.lang.String[] types)
        Initialize stack state to array of value types. This can be used to set the expected stack state following an unconditional transfer of control instruction.
        Parameters:
        types - array of type names on stack
      • targetNext

        public void targetNext​(BranchWrapper branch)
        Set branch target as next instruction added to method. This effectively sets up a state trigger for the next append operation. The appended instruction is set as the target for the branch. This requires that instructions are only appended using the methods supplied in this class.
        Parameters:
        branch - wrapper for branch to be aimed at next instruction (may be null, in which case nothing is done)
      • targetNext

        public void targetNext​(BranchWrapper[] branches)
        Set branch targets as next instruction added to method. This effectively sets up a state trigger for the next append operation. The appended instruction is set as the target for all the branches. This requires that instructions are only appended using the methods supplied in this class.
        Parameters:
        branches - wrappers for branches to be aimed at next instruction (may be null, in which case nothing is done)
      • handleExceptions

        protected abstract void handleExceptions()
        Process accumulated exceptions. Each subclass must implement this method to perform the appropriate handling of the checked exceptions that may be thrown in the constructed method.
      • codeComplete

        public void codeComplete​(boolean suffix)
        Complete method construction. Finalizes the instruction list and generates the byte code for the constructed method, then computes the hash code based on the byte code. If requested, an appropriate suffix is tacked on the end of the supplied name in order to make sure that it will not be duplicated (even in a superclass or subclass).
        Parameters:
        suffix - add suffix to make method name unique
      • hashCode

        public int hashCode()
        Get hash code. This is based only on the byte code in the method, and is only valid after the codeComplete(boolean) method is called.
        Specified by:
        hashCode in class BindingMethod
        Returns:
        hash code based on code sequence
      • addMethod

        public ClassItem addMethod()
        Add constructed method to class. Makes the method callable, generating the method information.
        Returns:
        added method information