java virtual machine specification (se8) - class file format (five)

4.7.1 define and name the new property

  It allows the compiler to define and publish class file in the class file structure, field_info structure, method_info structure and the structure of the attributes Code table contains the new attribute. Java virtual machine allows the identification and use of new attributes table attribute. However, any property not defined in the class file specification can not affect the semantics of class files. Achieve java virtual machine does not recognize the need to ignore their properties.

  For example, it allows you to define a new property to support vendor-specific debugging. Because java virtual ignore their need to not recognize property, special java virtual machine implementation class used in the document may also be used for other java virtual machine implementation, although these can not be used to achieve additional debugging information contained in the file class.

  Prohibit java virtual machine implementations only because there are some new properties will throw an exception or refuse to use class files. Of course, the tool runs class files may not work properly if the given class file contains an attribute they need.

  Two would have different attributes, but happen to use the same property name and the same length, the virtual machine to achieve conflict in identifying these two properties. In addition to the attributes defined in this specification, the name of the other attribute must be selected according to the naming convention package "Java Language Specification, Java SE version 8" (JLS 6.1) is described.

  Future versions of this specification may define additional properties.

4.7.2 ConstantValue property

  When fixed-length ConstantValue properties, which in the attributes table field_info structure. ConstantValue attribute value indicating the constant expression for the following scenarios:

  • If the flag is set ACC_STATIC access_flags item field_info structure, the field represented by the field_info structure will be assigned the value of its ConstantValue properties represented as part of the class or interface initialization field (5.5) statement. This occurs before (2.9) call the class initialization method or class or interface interface.
  • Otherwise, java virtual machine must ignore this property

  field_info structure attributes table can have at most one ConstantValue property.

  ConstantValue attribute format is as follows:

ConstantValue_attribute {
    u2 attribute_name_index;
    u4 attribute_length;
    u2 constantvalue_index;
}

  Each entry ConstantValue_attribute structure is as follows:

  attribute_name_index

    Attribute_name_index value must be a valid index of the constant pool table. The constant pool entry at that index must be a string "ConstantValue" Constant Utf8 information structure (4.4.7) FIG.

  attribute_length

    Its value must be 2.

  constantvalue_index

    Constantvalue_index value must be a valid index of the constant pool table. The constant pool entries of the index at the given constant value represented by the attribute. The constant pool entry must be adapted to the type of the field, as specified in Table 4.7.2-A.

Table 4.7.2-A. Constant attribute type

Field Type Entry Type
long CONSTANT_Long
float CONSTANT_Float
double CONSTANT_Double
intshortcharbyteboolean CONSTANT_Integer
String CONSTANT_String

 

4.7.3 Code attributes

  is a variable length code property attribute, the attributes tables method_info structure. Code attribute contains the Java virtual machine instruction method and the auxiliary information, including instance initialization method, or class or interface initialization method (2.9).

  If the method is native or abstract, for which method attribute table information structure must not Code attribute. Otherwise, its method attribute table information structures must be only a Code attribute.

  Code attribute format is as follows:

Code_attribute {
    u2 attribute_name_index;
    u4 attribute_length;
    u2 max_stack;
    u2 max_locals;
    u4 code_length;
    u1 code[code_length];
    u2 exception_table_length;
    {   u2 start_pc;
        u2 end_pc;
        u2 handler_pc;
        u2 catch_type;
    } exception_table[exception_table_length];
    u2 attributes_count;
    attribute_info attributes[attributes_count];
}

  The structure is as follows:

  attribute_name_index

    Attribute_name_index value must be a valid index of the constant pool table. The constant pool entry at that index must be a string "Code" Constant Utf8 information structure (4.4.7) FIG.

  attribute_length

    Attribute indicates the length does not include the beginning of the 6 bytes.

  max_stack

    Its value gives the maximum depth of this method during execution of this method the operand stack.

  max_locals

    Max_locals value gives the number of entries of the array of local variables allocated in this method is invoked (2.6.1) of the local variables, comprising means for passing parameters to local variables when invoked method.

    long or double type greatest local variable index value is max_locals - 2. Any other type of local variable maximum value of the index is max_locals - 1.

  code_length

    It gives the number of code values ​​in this method an array of bytes.

    It must be greater than 0 and less than 65535, i.e. code array must not be empty.

  code[]

    code array gives the actual bytes of this method to achieve a java virtual machine code.

    When the code array is read into memory on a byte addressable machine if the first byte in the array is aligned on 4-byte boundary, the tableswitch and lookupswitch32 bit offset will be 4-byte aligned. (For more information about the code array alignment result, please refer to the description of these instructions.)

    Details constraint on the contents of the code array is very extensive, given in a separate section (4.9) in.

  exception_table_length

    Its value gives the number of table entries exception_table.

  exception_table[]

    exception_table Each entry in the array describes one exception handler in the code array. Table order exception handler array is important (2.10).

    Exception_table Each entry contains the following four:

    start_pc,end_pc

      Values of the two items start_pc and end_pc indicate the valid range of the exception handler in the code array. The value of start_pc must be a valid index of the code array of the opcode instruction. end_pc value must be a valid index of the code array of the opcode of the instruction, or must be equal to the length of the array code_length codes. value of start_pc must be less than the value of end_pc.
      start_pc is inclusive, end_pc is exclusive; That is, when the program counter [start_pc, end_pc), the exception handler must be valid.
      end_pc is exclusive to the fact that the Java Virtual Machine Design a historical error: If a method of Java virtual machine code is exactly 65535 bytes long, and ends with a 1-byte instruction, the instruction can not be an exception handling program protection. Compiler writers can resolve this error by any method, instance initialization method, or a static initializer (any size of the code array) generated by the maximum size limit for the Java virtual machine code 65534 bytes.

    handler_pc

      Its value indicates the starting location of the exception handler. Its value must be a valid index code is the index of the array and the instruction opcode.

    catch_type

      If the catch_type item is nonzero, it must be a valid index in the constant pool table. The constant pool entries of the index structure must be CONSTAN_Class_info (4.4.1), indicating that the exception handler to capture a specified class of exceptions. An exception is thrown when one of the instances of a given class or sub-class will be called only if the exception handler.
      Such validation checks are thrown or subclass (4.9.2) may be thrown.
      If the value is zero catch_type items, was all exceptions invoked this exception handler.
      This is used to achieve finally (3.13).

  attributes_count

    It is simply the number of attribute value Code attribute.

  attributes[]

    Each value of the attribute table must attribute_info configuration (4.7).
    Code attribute can have any number of optional attributes associated with it.
    It appears in this specification defines the attributes listed in the Code attribute of the attribute table in the 4.7-C in Table
    4.7 are given in Table Rule Properties Properties defined in the Code attribute.
    Code attribute table on non-property rules predefined properties are given in 4.7.1.

Guess you like

Origin www.cnblogs.com/lilinwei340/p/11590497.html