Field and Method types are represented, in a special notation, by a string. This notation is described below.Primitive Types
Primitive types are represented by one of the following characters:For instance, an integer field would have a descriptor of "I".
byte B char C double D float F int I long J short S boolean Z Classes
Classes are indicated by an 'L', followed by the path to the class name, then a semi-colon to mark the end of the class name.
For instance, a String field would have a descriptor of "Ljava/lang/String;"Arrays
Arrays are indicated with a '[' character.
For instance an array of Integers would have a descriptor of "[I".
Multi-dimensional arrays simply have extra '[' characters. For instance, "[[I".Field Descriptors
A field has just one type, described in a string in the above notation. e.g. "I", or "Ljava/lang/String".Method Descriptors
Because methods involve several types - the arguments and the return type - their type descriptor notation is slightly different. The argument types are at the start of the string inside brackets, concatenated together. Note that the type descriptors are concatenated without any separator character. The return type is after the closing bracket.
For instance, "int someMethod(long lValue, boolean bRefresh);" would have a descriptor of "(JZ)I".
Attributes
Both the field_info table and the method_info table include a list of attributes. Each attribute starts with the index of a CONSTANT_Utf8 (2 bytes) and then the length of the following data (4 bytes). The structure of the following data depends on the particular attribute type. This allows new or custom attributes to be included in the class file without disrupting the existing structure, and without requiring recognition in the JVM specification. Any unrecognised attribute types will simply be ignored.source: http://www.murrayc.com/learning/java/java_classfileformat.shtml
Attributes can contain sub-attributes. For instance, the code attribute can contain a LineNumberTable attribut
Here are some possible attributes:
Code Details, including bytecode, of a method's code. ConstantValue Used by 'final' fields Exceptions Exceptions thrown by a method. InnerClasses A class's inner classes. LineNumberTable Debugging information LocalVariableTable Debugging information. SourceFile Source file name. Synthetic Shows that the field or method was generated by the compiler. Code attribute
The Code attribute is used by the method_info table. It is where you will find the actual bytecodes (opcodes an operands) of the method's classes.
The attributes has the following structure:Each exception table entry has the following structure, each describing one exception catch:
Length (number of bytes) Description max_stack 2 Size of stack required by the method's code. max_locals 2 Number of local variables required by the method's code. code_length 2 code code_length The method's executable bytecodes exception_table_length 2 exception_table varies The exceptions which the method can throw. attributes_count 2 attributes varies e.g. LineNumberTable These entries for the Code attribute will probably only make sense to you if you are familiar with the rest of the JVM specification.
Length (number of bytes) Description start_pc 2 Offset of start of try/catch range. end_pc 2 Offset of end of try/catch range. handler_pc 2 Offset of start of exception handler code. catch_type 2 Type of exception handled.
No comments:
Post a Comment