Class CodeAttribute

    • Field Detail

      • constPool

        private final ConstPool constPool
      • finalDataBytes

        private final java.io.ByteArrayOutputStream finalDataBytes
      • data

        private final java.io.DataOutputStream data
      • maxLocals

        private int maxLocals
      • maxStackDepth

        private int maxStackDepth
      • stackFrames

        private final java.util.LinkedHashMap<java.lang.Integer,​StackFrame> stackFrames
      • jumpLocations

        private final java.util.Map<java.lang.Integer,​java.lang.Integer> jumpLocations
        maps bytecode offsets to jump locations. As these jump locations where not known when the instruction was written they need to be overwritten when the final bytecode is written out
      • jumpLocations32

        private final java.util.Map<java.lang.Integer,​java.lang.Integer> jumpLocations32
        maps bytecode offsets to jump locations. As these jump locations where not known when the instruction was written they need to be overwritten when the final bytecode is written out

        These jump locations are 32 bit offsets,

      • currentOffset

        private int currentOffset
      • attributes

        private final java.util.List<Attribute> attributes
      • stackMapAttributeValid

        private boolean stackMapAttributeValid
    • Method Detail

      • aaload

        public void aaload()
      • aastore

        public void aastore()
      • aconstNull

        public void aconstNull()
      • aload

        public void aload​(int no)
      • anewarray

        public void anewarray​(java.lang.String arrayType)
      • arraylength

        public void arraylength()
      • astore

        public void astore​(int no)
      • athrow

        public void athrow()
      • baload

        public void baload()
      • bastore

        public void bastore()
      • caload

        public void caload()
      • castore

        public void castore()
      • bipush

        public void bipush​(byte value)
      • branchEnd

        public void branchEnd​(BranchEnd end)
        marks the end of a branch. The current stack frame is checked for compatibility with the stack frame at the branch start
      • checkcast

        public void checkcast​(java.lang.String className)
        Do not use Descriptor format (e.g. Ljava/lang/Object;), the correct form is just java/lang/Object or java.lang.Object
      • checkcast

        public void checkcast​(java.lang.Class<?> clazz)
      • d2f

        public void d2f()
      • d2i

        public void d2i()
      • d2l

        public void d2l()
      • dadd

        public void dadd()
      • daload

        public void daload()
      • dastore

        public void dastore()
      • dcmpg

        public void dcmpg()
      • dcmpl

        public void dcmpl()
      • dconst

        public void dconst​(double value)
        Adds the appropriate dconst instruction.

        note, if the value is not 0 or 1 then ldc is used instead

      • ddiv

        public void ddiv()
      • dload

        public void dload​(int no)
      • dmul

        public void dmul()
      • dneg

        public void dneg()
      • drem

        public void drem()
      • dstore

        public void dstore​(int no)
      • dsub

        public void dsub()
      • dup

        public void dup()
      • dupX1

        public void dupX1()
      • dupX2

        public void dupX2()
      • dup2

        public void dup2()
      • dup2X1

        public void dup2X1()
      • dup2X2

        public void dup2X2()
      • exceptionBlockStart

        public ExceptionHandler exceptionBlockStart​(java.lang.String exceptionType)
        Begin writing an exception handler block. The handler is not actually persisted until exceptionHandler is called.
      • exceptionBlockEnd

        public void exceptionBlockEnd​(ExceptionHandler handler)
        Mark the end of an exception handler block. The last instruction that was written will be the last instruction covered by the handler
      • exceptionHandlerStart

        public void exceptionHandlerStart​(ExceptionHandler handler)
        Marks the current code location as the exception handler and adds the handler to the exception handler table;
      • f2d

        public void f2d()
      • f2i

        public void f2i()
      • f2l

        public void f2l()
      • fadd

        public void fadd()
      • faload

        public void faload()
      • fastore

        public void fastore()
      • fcmpg

        public void fcmpg()
      • fcmpl

        public void fcmpl()
      • fconst

        public void fconst​(float value)
        Adds the appropriate fconst instruction.

        note, if the value is not 0, 1, 2 then ldc is used instead

      • fdiv

        public void fdiv()
      • fload

        public void fload​(int no)
      • fmul

        public void fmul()
      • fneg

        public void fneg()
      • frem

        public void frem()
      • fstore

        public void fstore​(int no)
      • fsub

        public void fsub()
      • getfield

        public void getfield​(java.lang.String className,
                             java.lang.String field,
                             java.lang.Class<?> fieldType)
      • getfield

        public void getfield​(java.lang.String className,
                             java.lang.String field,
                             java.lang.String descriptor)
      • getstatic

        public void getstatic​(java.lang.String className,
                              java.lang.String field,
                              java.lang.Class<?> fieldType)
      • getstatic

        public void getstatic​(java.lang.String className,
                              java.lang.String field,
                              java.lang.String descriptor)
      • gotoInstruction

        public void gotoInstruction​(CodeLocation location)
        writes a goto instruction.

        TODO: implemented goto_w

      • gotoInstruction

        public BranchEnd gotoInstruction()
        writes a goto instruction.

        TODO: implemented goto_w

      • i2b

        public void i2b()
      • i2c

        public void i2c()
      • i2d

        public void i2d()
      • i2f

        public void i2f()
      • i2l

        public void i2l()
      • i2s

        public void i2s()
      • iadd

        public void iadd()
      • iaload

        public void iaload()
      • iand

        public void iand()
      • iastore

        public void iastore()
      • iconst

        public void iconst​(int value)
        Adds the appropriate iconst instruction.

        note, if the value is not in the range -1 to 5 ldc is written instead

        Parameters:
        value -
      • idiv

        public void idiv()
      • ifAcmpeq

        public void ifAcmpeq​(CodeLocation location)
      • ifAcmpne

        public void ifAcmpne​(CodeLocation location)
      • ifIcmpeq

        public void ifIcmpeq​(CodeLocation location)
      • ifIcmpne

        public void ifIcmpne​(CodeLocation location)
      • ifIcmplt

        public void ifIcmplt​(CodeLocation location)
      • ifIcmple

        public void ifIcmple​(CodeLocation location)
      • ifIcmpgt

        public void ifIcmpgt​(CodeLocation location)
      • ifIcmpge

        public void ifIcmpge​(CodeLocation location)
      • ifnotnull

        public void ifnotnull​(CodeLocation location)
      • ifnull

        public void ifnull​(CodeLocation location)
        Jump to the given location if the reference type on the top of the stack is null
      • ifnull

        public BranchEnd ifnull()
        Jump to the given location if the reference type on the top of the stack is null.

        The BranchEnd returned from this method is used to set the end point to a future point in the bytecode stream

      • iinc

        public void iinc​(int local,
                         int amount)
      • iload

        public void iload​(int no)
      • imul

        public void imul()
      • ineg

        public void ineg()
      • instanceofInstruction

        public void instanceofInstruction​(java.lang.String className)
      • invokespecial

        public void invokespecial​(java.lang.String className,
                                  java.lang.String methodName,
                                  java.lang.String descriptor)
      • invokespecial

        public void invokespecial​(java.lang.String className,
                                  java.lang.String methodName,
                                  java.lang.String returnType,
                                  java.lang.String[] parameterTypes)
      • invokespecial

        public void invokespecial​(java.lang.reflect.Constructor<?> constructor)
      • invokespecial

        public void invokespecial​(java.lang.reflect.Method method)
      • invokespecial

        private void invokespecial​(java.lang.String className,
                                   java.lang.String methodName,
                                   java.lang.String descriptor,
                                   java.lang.String returnType,
                                   java.lang.String[] parameterTypes)
      • invokestatic

        public void invokestatic​(java.lang.String className,
                                 java.lang.String methodName,
                                 java.lang.String descriptor)
      • invokestatic

        public void invokestatic​(java.lang.String className,
                                 java.lang.String methodName,
                                 java.lang.String returnType,
                                 java.lang.String[] parameterTypes)
      • invokestatic

        public void invokestatic​(java.lang.reflect.Method method)
      • invokestatic

        private void invokestatic​(java.lang.String className,
                                  java.lang.String methodName,
                                  java.lang.String descriptor,
                                  java.lang.String returnType,
                                  java.lang.String[] parameterTypes)
      • invokevirtual

        public void invokevirtual​(java.lang.String className,
                                  java.lang.String methodName,
                                  java.lang.String descriptor)
      • invokevirtual

        public void invokevirtual​(java.lang.String className,
                                  java.lang.String methodName,
                                  java.lang.String returnType,
                                  java.lang.String[] parameterTypes)
      • invokevirtual

        public void invokevirtual​(java.lang.reflect.Method method)
      • invokevirtual

        private void invokevirtual​(java.lang.String className,
                                   java.lang.String methodName,
                                   java.lang.String descriptor,
                                   java.lang.String returnType,
                                   java.lang.String[] parameterTypes)
      • invokeinterface

        public void invokeinterface​(java.lang.String className,
                                    java.lang.String methodName,
                                    java.lang.String descriptor)
      • invokeinterface

        public void invokeinterface​(java.lang.String className,
                                    java.lang.String methodName,
                                    java.lang.String returnType,
                                    java.lang.String[] parameterTypes)
      • invokeinterface

        public void invokeinterface​(java.lang.reflect.Method method)
      • invokeinterface

        private void invokeinterface​(java.lang.String className,
                                     java.lang.String methodName,
                                     java.lang.String descriptor,
                                     java.lang.String returnType,
                                     java.lang.String[] parameterTypes)
      • ior

        public void ior()
      • irem

        public void irem()
      • ishl

        public void ishl()
      • ishr

        public void ishr()
      • istore

        public void istore​(int no)
      • isub

        public void isub()
      • iushr

        public void iushr()
      • ixor

        public void ixor()
      • l2d

        public void l2d()
      • l2f

        public void l2f()
      • l2i

        public void l2i()
      • ladd

        public void ladd()
      • laload

        public void laload()
      • land

        public void land()
      • lastore

        public void lastore()
      • lcmp

        public void lcmp()
      • lconst

        public void lconst​(long value)
        Adds the appropriate lconst instruction.

        note, if the value is not 0 or 1 then ldc is used instead

      • ldc

        public void ldc​(int value)
        Adds an ldc instruction for an int.
        Parameters:
        value -
      • ldc

        public void ldc​(float value)
        Adds an ldc instruction for float
      • ldc

        public void ldc​(java.lang.String value)
        Adds an ldc instruction for a String

        To load a class literal using ldc use the @{link #loadType(String)} method.

      • ldcInternal

        private void ldcInternal​(int index)
        Adds an ldc instruction for an int.
      • ldc2

        public void ldc2​(double value)
        Adds an ldc2_w instruction for double
      • ldc2

        public void ldc2​(long value)
        Adds an ldc2_w instruction for long
      • ldiv

        public void ldiv()
      • lload

        public void lload​(int no)
      • lmul

        public void lmul()
      • lneg

        public void lneg()
      • load

        public void load​(java.lang.Class<?> type,
                         int no)
        Generates the apprpriate load instruction for the given type
        Parameters:
        type - The type of variable
        no - local variable number
      • load

        public void load​(java.lang.String descriptor,
                         int no)
        Generates the apprpriate load instruction for the given type
        Parameters:
        descriptor - The descriptor of the variable
        no - local variable number
      • loadClass

        public void loadClass​(java.lang.String className)
      • loadType

        public void loadType​(java.lang.String descriptor)
        Loads a java.lang.Class for the given descriptor into the stack.
      • lookupswitch

        public void lookupswitch​(LookupSwitchBuilder lookupSwitchBuilder)
        Adds a lookup switch statement
        Parameters:
        lookupSwitchBuilder -
      • lor

        public void lor()
      • lrem

        public void lrem()
      • lshl

        public void lshl()
      • lshr

        public void lshr()
      • lstore

        public void lstore​(int no)
      • lsub

        public void lsub()
      • lushr

        public void lushr()
      • lxor

        public void lxor()
      • mark

        public CodeLocation mark()
        Gets the location object for the current location in the bytecode. Jumps to this location will begin executing the next instruction that is written to the bytecode stream
      • monitorenter

        public void monitorenter()
      • monitorexit

        public void monitorexit()
      • multianewarray

        public void multianewarray​(java.lang.String arrayType,
                                   int dimensions)
      • newInstruction

        public void newInstruction​(java.lang.String classname)
      • newInstruction

        public void newInstruction​(java.lang.Class<?> clazz)
      • newarray

        public void newarray​(java.lang.Class<?> arrayType)
        arrayType must be a Class object that represents a primitive type
      • nop

        public void nop()
      • pop

        public void pop()
      • pop2

        public void pop2()
      • putfield

        public void putfield​(java.lang.String className,
                             java.lang.String field,
                             java.lang.Class<?> fieldType)
      • putfield

        public void putfield​(java.lang.String className,
                             java.lang.String field,
                             java.lang.String descriptor)
      • putstatic

        public void putstatic​(java.lang.String className,
                              java.lang.String field,
                              java.lang.Class<?> fieldType)
      • putstatic

        public void putstatic​(java.lang.String className,
                              java.lang.String field,
                              java.lang.String descriptor)
      • returnInstruction

        public void returnInstruction()
        Adds the appropriate return instruction for the methods return type.
      • saload

        public void saload()
      • sastore

        public void sastore()
      • sipush

        public void sipush​(short value)
      • swap

        public void swap()
      • loadMethodParameters

        public void loadMethodParameters()
        loads all parameters onto the stack.

        If this method is non-static then the parameter at location 0 (i.e. this object) is not pushed.

      • writeByte

        private void writeByte​(int n)
      • writeShort

        private void writeShort​(int n)
      • writeInt

        private void writeInt​(int n)
      • overwriteShort

        private void overwriteShort​(byte[] bytecode,
                                    int offset,
                                    int value)
        overwrites a 16 bit value in the already written bytecode data
      • overwriteInt

        private void overwriteInt​(byte[] bytecode,
                                  int offset,
                                  int value)
        overwrites a 32 bit value in the already written bytecode data
      • getStackFrames

        public java.util.LinkedHashMap<java.lang.Integer,​StackFrame> getStackFrames()
      • setupFrame

        public void setupFrame​(java.lang.String... types)
      • getConstPool

        public ConstPool getConstPool()
      • duplicateFrame

        private void duplicateFrame()
        Adds a duplicate of the current frame to the current position.

        currently this just puts the same frame into a different position

      • advanceFrame

        private void advanceFrame​(StackFrame frame)
      • updateMaxValues

        private void updateMaxValues()
      • assertTypeOnStack

        public void assertTypeOnStack​(int position,
                                      StackEntryType type,
                                      java.lang.String message)
      • assertTypeOnStack

        public void assertTypeOnStack​(StackEntryType type,
                                      java.lang.String message)
      • assertNotWideOnStack

        public void assertNotWideOnStack​(int position,
                                         java.lang.String message)
      • assertNotWideOnStack

        public void assertNotWideOnStack​(java.lang.String message)
      • mergeStackFrames

        private void mergeStackFrames​(StackFrame stackFrame)
        Merge the stack frames.

        If the frames are incompatible then an InvalidBytecodeException is thrown. If the frames cannot be properly merged then the stack map is marked as invalid

      • addIfIcmp

        private void addIfIcmp​(CodeLocation location,
                               int opcode,
                               java.lang.String name)
      • addIfIcmp

        private BranchEnd addIfIcmp​(int opcode,
                                    java.lang.String name)
      • addIf

        private void addIf​(CodeLocation location,
                           int opcode,
                           java.lang.String name)
      • addIf

        private BranchEnd addIf​(int opcode,
                                java.lang.String name)
      • addNullComparison

        private void addNullComparison​(CodeLocation location,
                                       int opcode,
                                       java.lang.String name)
      • addNullComparison

        private BranchEnd addNullComparison​(int opcode,
                                            java.lang.String name)