Class ClassReader


  • public class ClassReader
    extends java.lang.Object
    A parser to make a ClassVisitor visit a ClassFile structure, as defined in the Java Virtual Machine Specification (JVMS). This class parses the ClassFile content and calls the appropriate visit methods of a given ClassVisitor for each field, method and bytecode instruction encountered.
    See Also:
    JVMS 4
    • Field Summary

      Fields 
      Modifier and Type Field Description
      byte[] b
      Deprecated.
      Use readByte(int) and the other read methods instead.
      private int[] bootstrapMethodOffsets
      The start offsets in classFileBuffer of each element of the bootstrap_methods array (in the BootstrapMethods attribute).
      (package private) byte[] classFileBuffer
      A byte array containing the JVMS ClassFile structure to be parsed.
      private ConstantDynamic[] constantDynamicValues
      The ConstantDynamic objects corresponding to the CONSTANT_Dynamic constant pool items.
      private java.lang.String[] constantUtf8Values
      The String objects corresponding to the CONSTANT_Utf8 constant pool items.
      private int[] cpInfoOffsets
      The offset in bytes, in classFileBuffer, of each cp_info entry of the ClassFile's constant_pool array, plus one.
      (package private) static int EXPAND_ASM_INSNS
      A flag to expand the ASM specific instructions into an equivalent sequence of standard bytecode instructions.
      static int EXPAND_FRAMES
      A flag to expand the stack map frames.
      int header
      The offset in bytes of the ClassFile's access_flags field.
      private static int INPUT_STREAM_DATA_CHUNK_SIZE
      The size of the temporary byte array used to read class input streams chunk by chunk.
      private static int MAX_BUFFER_SIZE
      The maximum size of array to allocate.
      private int maxStringLength
      A conservative estimate of the maximum length of the strings contained in the constant pool of the class.
      static int SKIP_CODE
      A flag to skip the Code attributes.
      static int SKIP_DEBUG
      A flag to skip the SourceFile, SourceDebugExtension, LocalVariableTable, LocalVariableTypeTable, LineNumberTable and MethodParameters attributes.
      static int SKIP_FRAMES
      A flag to skip the StackMap and StackMapTable attributes.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void accept​(ClassVisitor classVisitor, int parsingOptions)
      Makes the given visitor visit the JVMS ClassFile structure passed to the constructor of this ClassReader.
      void accept​(ClassVisitor classVisitor, Attribute[] attributePrototypes, int parsingOptions)
      Makes the given visitor visit the JVMS ClassFile structure passed to the constructor of this ClassReader.
      private static int computeBufferSize​(java.io.InputStream inputStream)  
      private void computeImplicitFrame​(Context context)
      Computes the implicit frame of the method currently being parsed (as defined in the given Context) and stores it in the given context.
      private void createDebugLabel​(int bytecodeOffset, Label[] labels)
      Creates a label with the Label.FLAG_DEBUG_ONLY flag set, if there is no already existing label for the given bytecode offset (otherwise does nothing).
      private Label createLabel​(int bytecodeOffset, Label[] labels)
      Creates a label without the Label.FLAG_DEBUG_ONLY flag set, for the given bytecode offset.
      int getAccess()
      Returns the class's access flags (see Opcodes).
      java.lang.String getClassName()
      Returns the internal name of the class (see Type.getInternalName()).
      (package private) int getFirstAttributeOffset()
      Returns the offset in classFileBuffer of the first ClassFile's 'attributes' array field entry.
      java.lang.String[] getInterfaces()
      Returns the internal names of the implemented interfaces (see Type.getInternalName()).
      int getItem​(int constantPoolEntryIndex)
      Returns the start offset in this ClassReader of a JVMS 'cp_info' structure (i.e.
      int getItemCount()
      Returns the number of entries in the class's constant pool table.
      int getMaxStringLength()
      Returns a conservative estimate of the maximum length of the strings contained in the class's constant pool table.
      java.lang.String getSuperName()
      Returns the internal name of the super class (see Type.getInternalName()).
      private int getTypeAnnotationBytecodeOffset​(int[] typeAnnotationOffsets, int typeAnnotationIndex)
      Returns the bytecode offset corresponding to the specified JVMS 'type_annotation' structure, or -1 if there is no such type_annotation of if it does not have a bytecode offset.
      private Attribute readAttribute​(Attribute[] attributePrototypes, java.lang.String type, int offset, int length, char[] charBuffer, int codeAttributeOffset, Label[] labels)
      Reads a non standard JVMS 'attribute' structure in classFileBuffer.
      private int[] readBootstrapMethodsAttribute​(int maxStringLength)
      Reads the BootstrapMethods attribute to compute the offset of each bootstrap method.
      int readByte​(int offset)
      Reads a byte value in this ClassReader.
      protected void readBytecodeInstructionOffset​(int bytecodeOffset)
      Handles the bytecode offset of the next instruction to be visited in accept(ClassVisitor,int).
      java.lang.String readClass​(int offset, char[] charBuffer)
      Reads a CONSTANT_Class constant pool entry in this ClassReader.
      private void readCode​(MethodVisitor methodVisitor, Context context, int codeOffset)
      Reads a JVMS 'Code' attribute and makes the given visitor visit it.
      java.lang.Object readConst​(int constantPoolEntryIndex, char[] charBuffer)
      Reads a numeric or string constant pool entry in this ClassReader.
      private ConstantDynamic readConstantDynamic​(int constantPoolEntryIndex, char[] charBuffer)
      Reads a CONSTANT_Dynamic constant pool entry in classFileBuffer.
      private int readElementValue​(AnnotationVisitor annotationVisitor, int elementValueOffset, java.lang.String elementName, char[] charBuffer)
      Reads a JVMS 'element_value' structure and makes the given visitor visit it.
      private int readElementValues​(AnnotationVisitor annotationVisitor, int annotationOffset, boolean named, char[] charBuffer)
      Reads the element values of a JVMS 'annotation' structure and makes the given visitor visit them.
      private int readField​(ClassVisitor classVisitor, Context context, int fieldInfoOffset)
      Reads a JVMS field_info structure and makes the given visitor visit it.
      int readInt​(int offset)
      Reads a signed int value in this ClassReader.
      protected Label readLabel​(int bytecodeOffset, Label[] labels)
      Returns the label corresponding to the given bytecode offset.
      long readLong​(int offset)
      Reads a signed long value in this ClassReader.
      private int readMethod​(ClassVisitor classVisitor, Context context, int methodInfoOffset)
      Reads a JVMS method_info structure and makes the given visitor visit it.
      java.lang.String readModule​(int offset, char[] charBuffer)
      Reads a CONSTANT_Module constant pool entry in this ClassReader.
      private void readModuleAttributes​(ClassVisitor classVisitor, Context context, int moduleOffset, int modulePackagesOffset, java.lang.String moduleMainClass)
      Reads the Module, ModulePackages and ModuleMainClass attributes and visit them.
      java.lang.String readPackage​(int offset, char[] charBuffer)
      Reads a CONSTANT_Package constant pool entry in this ClassReader.
      private void readParameterAnnotations​(MethodVisitor methodVisitor, Context context, int runtimeParameterAnnotationsOffset, boolean visible)
      Reads a Runtime[In]VisibleParameterAnnotations attribute and makes the given visitor visit it.
      private int readRecordComponent​(ClassVisitor classVisitor, Context context, int recordComponentOffset)
      Reads a record component and visit it.
      short readShort​(int offset)
      Reads a signed short value in this ClassReader.
      private int readStackMapFrame​(int stackMapFrameOffset, boolean compressed, boolean expand, Context context)
      Reads a JVMS 'stack_map_frame' structure and stores the result in the given Context object.
      private static byte[] readStream​(java.io.InputStream inputStream, boolean close)
      Reads the given input stream and returns its content as a byte array.
      private java.lang.String readStringish​(int offset, char[] charBuffer)
      Reads a CONSTANT_Class, CONSTANT_String, CONSTANT_MethodType, CONSTANT_Module or CONSTANT_Package constant pool entry in classFileBuffer.
      private int[] readTypeAnnotations​(MethodVisitor methodVisitor, Context context, int runtimeTypeAnnotationsOffset, boolean visible)
      Parses a Runtime[In]VisibleTypeAnnotations attribute to find the offset of each type_annotation entry it contains, to find the corresponding labels, and to visit the try catch block annotations.
      private int readTypeAnnotationTarget​(Context context, int typeAnnotationOffset)
      Parses the header of a JVMS type_annotation structure to extract its target_type, target_info and target_path (the result is stored in the given context), and returns the start offset of the rest of the type_annotation structure.
      int readUnsignedShort​(int offset)
      Reads an unsigned short value in this ClassReader.
      (package private) java.lang.String readUtf​(int constantPoolEntryIndex, char[] charBuffer)
      Reads a CONSTANT_Utf8 constant pool entry in classFileBuffer.
      private java.lang.String readUtf​(int utfOffset, int utfLength, char[] charBuffer)
      Reads an UTF8 string in classFileBuffer.
      java.lang.String readUTF8​(int offset, char[] charBuffer)
      Reads a CONSTANT_Utf8 constant pool entry in this ClassReader.
      private int readVerificationTypeInfo​(int verificationTypeInfoOffset, java.lang.Object[] frame, int index, char[] charBuffer, Label[] labels)
      Reads a JVMS 'verification_type_info' structure and stores it at the given index in the given array.
      • Methods inherited from class java.lang.Object

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

      • SKIP_CODE

        public static final int SKIP_CODE
        A flag to skip the Code attributes. If this flag is set the Code attributes are neither parsed nor visited.
        See Also:
        Constant Field Values
      • EXPAND_FRAMES

        public static final int EXPAND_FRAMES
        A flag to expand the stack map frames. By default stack map frames are visited in their original format (i.e. "expanded" for classes whose version is less than V1_6, and "compressed" for the other classes). If this flag is set, stack map frames are always visited in expanded format (this option adds a decompression/compression step in ClassReader and ClassWriter which degrades performance quite a lot).
        See Also:
        Constant Field Values
      • EXPAND_ASM_INSNS

        static final int EXPAND_ASM_INSNS
        A flag to expand the ASM specific instructions into an equivalent sequence of standard bytecode instructions. When resolving a forward jump it may happen that the signed 2 bytes offset reserved for it is not sufficient to store the bytecode offset. In this case the jump instruction is replaced with a temporary ASM specific instruction using an unsigned 2 bytes offset (see Label.resolve(byte[], int)). This internal flag is used to re-read classes containing such instructions, in order to replace them with standard instructions. In addition, when this flag is used, goto_w and jsr_w are not converted into goto and jsr, to make sure that infinite loops where a goto_w is replaced with a goto in ClassReader and converted back to a goto_w in ClassWriter cannot occur.
        See Also:
        Constant Field Values
      • MAX_BUFFER_SIZE

        private static final int MAX_BUFFER_SIZE
        The maximum size of array to allocate.
        See Also:
        Constant Field Values
      • INPUT_STREAM_DATA_CHUNK_SIZE

        private static final int INPUT_STREAM_DATA_CHUNK_SIZE
        The size of the temporary byte array used to read class input streams chunk by chunk.
        See Also:
        Constant Field Values
      • b

        @Deprecated
        public final byte[] b
        Deprecated.
        Use readByte(int) and the other read methods instead. This field will eventually be deleted.
        A byte array containing the JVMS ClassFile structure to be parsed.
      • header

        public final int header
        The offset in bytes of the ClassFile's access_flags field.
      • classFileBuffer

        final byte[] classFileBuffer
        A byte array containing the JVMS ClassFile structure to be parsed. The content of this array must not be modified. This field is intended for Attribute sub classes, and is normally not needed by class visitors.

        NOTE: the ClassFile structure can start at any offset within this array, i.e. it does not necessarily start at offset 0. Use getItem(int) and header to get correct ClassFile element offsets within this byte array.

      • cpInfoOffsets

        private final int[] cpInfoOffsets
        The offset in bytes, in classFileBuffer, of each cp_info entry of the ClassFile's constant_pool array, plus one. In other words, the offset of constant pool entry i is given by cpInfoOffsets[i] - 1, i.e. its cp_info's tag field is given by b[cpInfoOffsets[i] - 1].
      • constantUtf8Values

        private final java.lang.String[] constantUtf8Values
        The String objects corresponding to the CONSTANT_Utf8 constant pool items. This cache avoids multiple parsing of a given CONSTANT_Utf8 constant pool item.
      • constantDynamicValues

        private final ConstantDynamic[] constantDynamicValues
        The ConstantDynamic objects corresponding to the CONSTANT_Dynamic constant pool items. This cache avoids multiple parsing of a given CONSTANT_Dynamic constant pool item.
      • bootstrapMethodOffsets

        private final int[] bootstrapMethodOffsets
        The start offsets in classFileBuffer of each element of the bootstrap_methods array (in the BootstrapMethods attribute).
        See Also:
        JVMS 4.7.23
      • maxStringLength

        private final int maxStringLength
        A conservative estimate of the maximum length of the strings contained in the constant pool of the class.
    • Constructor Detail

      • ClassReader

        public ClassReader​(byte[] classFile)
        Constructs a new ClassReader object.
        Parameters:
        classFile - the JVMS ClassFile structure to be read.
      • ClassReader

        public ClassReader​(byte[] classFileBuffer,
                           int classFileOffset,
                           int classFileLength)
        Constructs a new ClassReader object.
        Parameters:
        classFileBuffer - a byte array containing the JVMS ClassFile structure to be read.
        classFileOffset - the offset in byteBuffer of the first byte of the ClassFile to be read.
        classFileLength - the length in bytes of the ClassFile to be read.
      • ClassReader

        ClassReader​(byte[] classFileBuffer,
                    int classFileOffset,
                    boolean checkClassVersion)
        Constructs a new ClassReader object. This internal constructor must not be exposed as a public API.
        Parameters:
        classFileBuffer - a byte array containing the JVMS ClassFile structure to be read.
        classFileOffset - the offset in byteBuffer of the first byte of the ClassFile to be read.
        checkClassVersion - whether to check the class version or not.
      • ClassReader

        public ClassReader​(java.io.InputStream inputStream)
                    throws java.io.IOException
        Constructs a new ClassReader object.
        Parameters:
        inputStream - an input stream of the JVMS ClassFile structure to be read. This input stream must contain nothing more than the ClassFile structure itself. It is read from its current position to its end.
        Throws:
        java.io.IOException - if a problem occurs during reading.
      • ClassReader

        public ClassReader​(java.lang.String className)
                    throws java.io.IOException
        Constructs a new ClassReader object.
        Parameters:
        className - the fully qualified name of the class to be read. The ClassFile structure is retrieved with the current class loader's ClassLoader.getSystemResourceAsStream(java.lang.String).
        Throws:
        java.io.IOException - if an exception occurs during reading.
    • Method Detail

      • readStream

        private static byte[] readStream​(java.io.InputStream inputStream,
                                         boolean close)
                                  throws java.io.IOException
        Reads the given input stream and returns its content as a byte array.
        Parameters:
        inputStream - an input stream.
        close - true to close the input stream after reading.
        Returns:
        the content of the given input stream.
        Throws:
        java.io.IOException - if a problem occurs during reading.
      • computeBufferSize

        private static int computeBufferSize​(java.io.InputStream inputStream)
                                      throws java.io.IOException
        Throws:
        java.io.IOException
      • accept

        public void accept​(ClassVisitor classVisitor,
                           int parsingOptions)
        Makes the given visitor visit the JVMS ClassFile structure passed to the constructor of this ClassReader.
        Parameters:
        classVisitor - the visitor that must visit this class.
        parsingOptions - the options to use to parse this class. One or more of SKIP_CODE, SKIP_DEBUG, SKIP_FRAMES or EXPAND_FRAMES.
      • accept

        public void accept​(ClassVisitor classVisitor,
                           Attribute[] attributePrototypes,
                           int parsingOptions)
        Makes the given visitor visit the JVMS ClassFile structure passed to the constructor of this ClassReader.
        Parameters:
        classVisitor - the visitor that must visit this class.
        attributePrototypes - prototypes of the attributes that must be parsed during the visit of the class. Any attribute whose type is not equal to the type of one the prototypes will not be parsed: its byte array value will be passed unchanged to the ClassWriter. This may corrupt it if this value contains references to the constant pool, or has syntactic or semantic links with a class element that has been transformed by a class adapter between the reader and the writer.
        parsingOptions - the options to use to parse this class. One or more of SKIP_CODE, SKIP_DEBUG, SKIP_FRAMES or EXPAND_FRAMES.
      • readModuleAttributes

        private void readModuleAttributes​(ClassVisitor classVisitor,
                                          Context context,
                                          int moduleOffset,
                                          int modulePackagesOffset,
                                          java.lang.String moduleMainClass)
        Reads the Module, ModulePackages and ModuleMainClass attributes and visit them.
        Parameters:
        classVisitor - the current class visitor
        context - information about the class being parsed.
        moduleOffset - the offset of the Module attribute (excluding the attribute_info's attribute_name_index and attribute_length fields).
        modulePackagesOffset - the offset of the ModulePackages attribute (excluding the attribute_info's attribute_name_index and attribute_length fields), or 0.
        moduleMainClass - the string corresponding to the ModuleMainClass attribute, or null.
      • readRecordComponent

        private int readRecordComponent​(ClassVisitor classVisitor,
                                        Context context,
                                        int recordComponentOffset)
        Reads a record component and visit it.
        Parameters:
        classVisitor - the current class visitor
        context - information about the class being parsed.
        recordComponentOffset - the offset of the current record component.
        Returns:
        the offset of the first byte following the record component.
      • readField

        private int readField​(ClassVisitor classVisitor,
                              Context context,
                              int fieldInfoOffset)
        Reads a JVMS field_info structure and makes the given visitor visit it.
        Parameters:
        classVisitor - the visitor that must visit the field.
        context - information about the class being parsed.
        fieldInfoOffset - the start offset of the field_info structure.
        Returns:
        the offset of the first byte following the field_info structure.
      • readMethod

        private int readMethod​(ClassVisitor classVisitor,
                               Context context,
                               int methodInfoOffset)
        Reads a JVMS method_info structure and makes the given visitor visit it.
        Parameters:
        classVisitor - the visitor that must visit the method.
        context - information about the class being parsed.
        methodInfoOffset - the start offset of the method_info structure.
        Returns:
        the offset of the first byte following the method_info structure.
      • readCode

        private void readCode​(MethodVisitor methodVisitor,
                              Context context,
                              int codeOffset)
        Reads a JVMS 'Code' attribute and makes the given visitor visit it.
        Parameters:
        methodVisitor - the visitor that must visit the Code attribute.
        context - information about the class being parsed.
        codeOffset - the start offset in classFileBuffer of the Code attribute, excluding its attribute_name_index and attribute_length fields.
      • readBytecodeInstructionOffset

        protected void readBytecodeInstructionOffset​(int bytecodeOffset)
        Handles the bytecode offset of the next instruction to be visited in accept(ClassVisitor,int). This method is called just before the instruction and before its associated label and stack map frame, if any. The default implementation of this method does nothing. Subclasses can override this method to store the argument in a mutable field, for instance, so that MethodVisitor instances can get the bytecode offset of each visited instruction (if so, the usual concurrency issues related to mutable data should be addressed).
        Parameters:
        bytecodeOffset - the bytecode offset of the next instruction to be visited.
      • readLabel

        protected Label readLabel​(int bytecodeOffset,
                                  Label[] labels)
        Returns the label corresponding to the given bytecode offset. The default implementation of this method creates a label for the given offset if it has not been already created.
        Parameters:
        bytecodeOffset - a bytecode offset in a method.
        labels - the already created labels, indexed by their offset. If a label already exists for bytecodeOffset this method must not create a new one. Otherwise it must store the new label in this array.
        Returns:
        a non null Label, which must be equal to labels[bytecodeOffset].
      • createDebugLabel

        private void createDebugLabel​(int bytecodeOffset,
                                      Label[] labels)
        Creates a label with the Label.FLAG_DEBUG_ONLY flag set, if there is no already existing label for the given bytecode offset (otherwise does nothing). The label is created with a call to readLabel(int, org.objectweb.asm.Label[]).
        Parameters:
        bytecodeOffset - a bytecode offset in a method.
        labels - the already created labels, indexed by their offset.
      • readTypeAnnotations

        private int[] readTypeAnnotations​(MethodVisitor methodVisitor,
                                          Context context,
                                          int runtimeTypeAnnotationsOffset,
                                          boolean visible)
        Parses a Runtime[In]VisibleTypeAnnotations attribute to find the offset of each type_annotation entry it contains, to find the corresponding labels, and to visit the try catch block annotations.
        Parameters:
        methodVisitor - the method visitor to be used to visit the try catch block annotations.
        context - information about the class being parsed.
        runtimeTypeAnnotationsOffset - the start offset of a Runtime[In]VisibleTypeAnnotations attribute, excluding the attribute_info's attribute_name_index and attribute_length fields.
        visible - true if the attribute to parse is a RuntimeVisibleTypeAnnotations attribute, false it is a RuntimeInvisibleTypeAnnotations attribute.
        Returns:
        the start offset of each entry of the Runtime[In]VisibleTypeAnnotations_attribute's 'annotations' array field.
      • getTypeAnnotationBytecodeOffset

        private int getTypeAnnotationBytecodeOffset​(int[] typeAnnotationOffsets,
                                                    int typeAnnotationIndex)
        Returns the bytecode offset corresponding to the specified JVMS 'type_annotation' structure, or -1 if there is no such type_annotation of if it does not have a bytecode offset.
        Parameters:
        typeAnnotationOffsets - the offset of each 'type_annotation' entry in a Runtime[In]VisibleTypeAnnotations attribute, or null.
        typeAnnotationIndex - the index a 'type_annotation' entry in typeAnnotationOffsets.
        Returns:
        bytecode offset corresponding to the specified JVMS 'type_annotation' structure, or -1 if there is no such type_annotation of if it does not have a bytecode offset.
      • readTypeAnnotationTarget

        private int readTypeAnnotationTarget​(Context context,
                                             int typeAnnotationOffset)
        Parses the header of a JVMS type_annotation structure to extract its target_type, target_info and target_path (the result is stored in the given context), and returns the start offset of the rest of the type_annotation structure.
        Parameters:
        context - information about the class being parsed. This is where the extracted target_type and target_path must be stored.
        typeAnnotationOffset - the start offset of a type_annotation structure.
        Returns:
        the start offset of the rest of the type_annotation structure.
      • readParameterAnnotations

        private void readParameterAnnotations​(MethodVisitor methodVisitor,
                                              Context context,
                                              int runtimeParameterAnnotationsOffset,
                                              boolean visible)
        Reads a Runtime[In]VisibleParameterAnnotations attribute and makes the given visitor visit it.
        Parameters:
        methodVisitor - the visitor that must visit the parameter annotations.
        context - information about the class being parsed.
        runtimeParameterAnnotationsOffset - the start offset of a Runtime[In]VisibleParameterAnnotations attribute, excluding the attribute_info's attribute_name_index and attribute_length fields.
        visible - true if the attribute to parse is a RuntimeVisibleParameterAnnotations attribute, false it is a RuntimeInvisibleParameterAnnotations attribute.
      • readElementValues

        private int readElementValues​(AnnotationVisitor annotationVisitor,
                                      int annotationOffset,
                                      boolean named,
                                      char[] charBuffer)
        Reads the element values of a JVMS 'annotation' structure and makes the given visitor visit them. This method can also be used to read the values of the JVMS 'array_value' field of an annotation's 'element_value'.
        Parameters:
        annotationVisitor - the visitor that must visit the values.
        annotationOffset - the start offset of an 'annotation' structure (excluding its type_index field) or of an 'array_value' structure.
        named - if the annotation values are named or not. This should be true to parse the values of a JVMS 'annotation' structure, and false to parse the JVMS 'array_value' of an annotation's element_value.
        charBuffer - the buffer used to read strings in the constant pool.
        Returns:
        the end offset of the JVMS 'annotation' or 'array_value' structure.
      • readElementValue

        private int readElementValue​(AnnotationVisitor annotationVisitor,
                                     int elementValueOffset,
                                     java.lang.String elementName,
                                     char[] charBuffer)
        Reads a JVMS 'element_value' structure and makes the given visitor visit it.
        Parameters:
        annotationVisitor - the visitor that must visit the element_value structure.
        elementValueOffset - the start offset in classFileBuffer of the element_value structure to be read.
        elementName - the name of the element_value structure to be read, or null.
        charBuffer - the buffer used to read strings in the constant pool.
        Returns:
        the end offset of the JVMS 'element_value' structure.
      • computeImplicitFrame

        private void computeImplicitFrame​(Context context)
        Computes the implicit frame of the method currently being parsed (as defined in the given Context) and stores it in the given context.
        Parameters:
        context - information about the class being parsed.
      • readStackMapFrame

        private int readStackMapFrame​(int stackMapFrameOffset,
                                      boolean compressed,
                                      boolean expand,
                                      Context context)
        Reads a JVMS 'stack_map_frame' structure and stores the result in the given Context object. This method can also be used to read a full_frame structure, excluding its frame_type field (this is used to parse the legacy StackMap attributes).
        Parameters:
        stackMapFrameOffset - the start offset in classFileBuffer of the stack_map_frame_value structure to be read, or the start offset of a full_frame structure (excluding its frame_type field).
        compressed - true to read a 'stack_map_frame' structure, false to read a 'full_frame' structure without its frame_type field.
        expand - if the stack map frame must be expanded. See EXPAND_FRAMES.
        context - where the parsed stack map frame must be stored.
        Returns:
        the end offset of the JVMS 'stack_map_frame' or 'full_frame' structure.
      • readVerificationTypeInfo

        private int readVerificationTypeInfo​(int verificationTypeInfoOffset,
                                             java.lang.Object[] frame,
                                             int index,
                                             char[] charBuffer,
                                             Label[] labels)
        Reads a JVMS 'verification_type_info' structure and stores it at the given index in the given array.
        Parameters:
        verificationTypeInfoOffset - the start offset of the 'verification_type_info' structure to read.
        frame - the array where the parsed type must be stored.
        index - the index in 'frame' where the parsed type must be stored.
        charBuffer - the buffer used to read strings in the constant pool.
        labels - the labels of the method currently being parsed, indexed by their offset. If the parsed type is an ITEM_Uninitialized, a new label for the corresponding NEW instruction is stored in this array if it does not already exist.
        Returns:
        the end offset of the JVMS 'verification_type_info' structure.
      • getFirstAttributeOffset

        final int getFirstAttributeOffset()
        Returns the offset in classFileBuffer of the first ClassFile's 'attributes' array field entry.
        Returns:
        the offset in classFileBuffer of the first ClassFile's 'attributes' array field entry.
      • readBootstrapMethodsAttribute

        private int[] readBootstrapMethodsAttribute​(int maxStringLength)
        Reads the BootstrapMethods attribute to compute the offset of each bootstrap method.
        Parameters:
        maxStringLength - a conservative estimate of the maximum length of the strings contained in the constant pool of the class.
        Returns:
        the offsets of the bootstrap methods.
      • readAttribute

        private Attribute readAttribute​(Attribute[] attributePrototypes,
                                        java.lang.String type,
                                        int offset,
                                        int length,
                                        char[] charBuffer,
                                        int codeAttributeOffset,
                                        Label[] labels)
        Reads a non standard JVMS 'attribute' structure in classFileBuffer.
        Parameters:
        attributePrototypes - prototypes of the attributes that must be parsed during the visit of the class. Any attribute whose type is not equal to the type of one the prototypes will not be parsed: its byte array value will be passed unchanged to the ClassWriter.
        type - the type of the attribute.
        offset - the start offset of the JVMS 'attribute' structure in classFileBuffer. The 6 attribute header bytes (attribute_name_index and attribute_length) are not taken into account here.
        length - the length of the attribute's content (excluding the 6 attribute header bytes).
        charBuffer - the buffer to be used to read strings in the constant pool.
        codeAttributeOffset - the start offset of the enclosing Code attribute in classFileBuffer, or -1 if the attribute to be read is not a code attribute. The 6 attribute header bytes (attribute_name_index and attribute_length) are not taken into account here.
        labels - the labels of the method's code, or null if the attribute to be read is not a code attribute.
        Returns:
        the attribute that has been read.
      • getItemCount

        public int getItemCount()
        Returns the number of entries in the class's constant pool table.
        Returns:
        the number of entries in the class's constant pool table.
      • getItem

        public int getItem​(int constantPoolEntryIndex)
        Returns the start offset in this ClassReader of a JVMS 'cp_info' structure (i.e. a constant pool entry), plus one. This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.
        Parameters:
        constantPoolEntryIndex - the index a constant pool entry in the class's constant pool table.
        Returns:
        the start offset in this ClassReader of the corresponding JVMS 'cp_info' structure, plus one.
      • getMaxStringLength

        public int getMaxStringLength()
        Returns a conservative estimate of the maximum length of the strings contained in the class's constant pool table.
        Returns:
        a conservative estimate of the maximum length of the strings contained in the class's constant pool table.
      • readByte

        public int readByte​(int offset)
        Reads a byte value in this ClassReader. This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.
        Parameters:
        offset - the start offset of the value to be read in this ClassReader.
        Returns:
        the read value.
      • readUnsignedShort

        public int readUnsignedShort​(int offset)
        Reads an unsigned short value in this ClassReader. This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.
        Parameters:
        offset - the start index of the value to be read in this ClassReader.
        Returns:
        the read value.
      • readShort

        public short readShort​(int offset)
        Reads a signed short value in this ClassReader. This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.
        Parameters:
        offset - the start offset of the value to be read in this ClassReader.
        Returns:
        the read value.
      • readInt

        public int readInt​(int offset)
        Reads a signed int value in this ClassReader. This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.
        Parameters:
        offset - the start offset of the value to be read in this ClassReader.
        Returns:
        the read value.
      • readLong

        public long readLong​(int offset)
        Reads a signed long value in this ClassReader. This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.
        Parameters:
        offset - the start offset of the value to be read in this ClassReader.
        Returns:
        the read value.
      • readUTF8

        public java.lang.String readUTF8​(int offset,
                                         char[] charBuffer)
        Reads a CONSTANT_Utf8 constant pool entry in this ClassReader. This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.
        Parameters:
        offset - the start offset of an unsigned short value in this ClassReader, whose value is the index of a CONSTANT_Utf8 entry in the class's constant pool table.
        charBuffer - the buffer to be used to read the string. This buffer must be sufficiently large. It is not automatically resized.
        Returns:
        the String corresponding to the specified CONSTANT_Utf8 entry.
      • readUtf

        final java.lang.String readUtf​(int constantPoolEntryIndex,
                                       char[] charBuffer)
        Reads a CONSTANT_Utf8 constant pool entry in classFileBuffer.
        Parameters:
        constantPoolEntryIndex - the index of a CONSTANT_Utf8 entry in the class's constant pool table.
        charBuffer - the buffer to be used to read the string. This buffer must be sufficiently large. It is not automatically resized.
        Returns:
        the String corresponding to the specified CONSTANT_Utf8 entry.
      • readUtf

        private java.lang.String readUtf​(int utfOffset,
                                         int utfLength,
                                         char[] charBuffer)
        Reads an UTF8 string in classFileBuffer.
        Parameters:
        utfOffset - the start offset of the UTF8 string to be read.
        utfLength - the length of the UTF8 string to be read.
        charBuffer - the buffer to be used to read the string. This buffer must be sufficiently large. It is not automatically resized.
        Returns:
        the String corresponding to the specified UTF8 string.
      • readStringish

        private java.lang.String readStringish​(int offset,
                                               char[] charBuffer)
        Reads a CONSTANT_Class, CONSTANT_String, CONSTANT_MethodType, CONSTANT_Module or CONSTANT_Package constant pool entry in classFileBuffer. This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.
        Parameters:
        offset - the start offset of an unsigned short value in classFileBuffer, whose value is the index of a CONSTANT_Class, CONSTANT_String, CONSTANT_MethodType, CONSTANT_Module or CONSTANT_Package entry in class's constant pool table.
        charBuffer - the buffer to be used to read the item. This buffer must be sufficiently large. It is not automatically resized.
        Returns:
        the String corresponding to the specified constant pool entry.
      • readClass

        public java.lang.String readClass​(int offset,
                                          char[] charBuffer)
        Reads a CONSTANT_Class constant pool entry in this ClassReader. This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.
        Parameters:
        offset - the start offset of an unsigned short value in this ClassReader, whose value is the index of a CONSTANT_Class entry in class's constant pool table.
        charBuffer - the buffer to be used to read the item. This buffer must be sufficiently large. It is not automatically resized.
        Returns:
        the String corresponding to the specified CONSTANT_Class entry.
      • readModule

        public java.lang.String readModule​(int offset,
                                           char[] charBuffer)
        Reads a CONSTANT_Module constant pool entry in this ClassReader. This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.
        Parameters:
        offset - the start offset of an unsigned short value in this ClassReader, whose value is the index of a CONSTANT_Module entry in class's constant pool table.
        charBuffer - the buffer to be used to read the item. This buffer must be sufficiently large. It is not automatically resized.
        Returns:
        the String corresponding to the specified CONSTANT_Module entry.
      • readPackage

        public java.lang.String readPackage​(int offset,
                                            char[] charBuffer)
        Reads a CONSTANT_Package constant pool entry in this ClassReader. This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.
        Parameters:
        offset - the start offset of an unsigned short value in this ClassReader, whose value is the index of a CONSTANT_Package entry in class's constant pool table.
        charBuffer - the buffer to be used to read the item. This buffer must be sufficiently large. It is not automatically resized.
        Returns:
        the String corresponding to the specified CONSTANT_Package entry.
      • readConstantDynamic

        private ConstantDynamic readConstantDynamic​(int constantPoolEntryIndex,
                                                    char[] charBuffer)
        Reads a CONSTANT_Dynamic constant pool entry in classFileBuffer.
        Parameters:
        constantPoolEntryIndex - the index of a CONSTANT_Dynamic entry in the class's constant pool table.
        charBuffer - the buffer to be used to read the string. This buffer must be sufficiently large. It is not automatically resized.
        Returns:
        the ConstantDynamic corresponding to the specified CONSTANT_Dynamic entry.
      • readConst

        public java.lang.Object readConst​(int constantPoolEntryIndex,
                                          char[] charBuffer)
        Reads a numeric or string constant pool entry in this ClassReader. This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.
        Parameters:
        constantPoolEntryIndex - the index of a CONSTANT_Integer, CONSTANT_Float, CONSTANT_Long, CONSTANT_Double, CONSTANT_Class, CONSTANT_String, CONSTANT_MethodType, CONSTANT_MethodHandle or CONSTANT_Dynamic entry in the class's constant pool.
        charBuffer - the buffer to be used to read strings. This buffer must be sufficiently large. It is not automatically resized.
        Returns:
        the Integer, Float, Long, Double, String, Type, Handle or ConstantDynamic corresponding to the specified constant pool entry.