Class attribute table type collection, and detailed explanation of fields

Directory:
java virtual machine summary

  1. Class file structure analysis
    1). The constant item structure in the class file constant pool
    2). A collection of commonly used attribute tables <<== Current position
  2. Class loading process
    1). Principle and implementation of class loader
  3. Virtual machine structure analysis
    1) .jdk 1.7 and 1.8 version of the method area structure changes
    2). Simple distinction between constant pools
  4. Object structure analysis
    1). Detailed explanation of compressed pointers
  5. gc garbage collection
  6. Object positioning method

In the Class file, the field table, and the method table can have an array of attribute tables. The attribute table does not require a strict order. The following are the types of attribute tables of all virtual machines. Here I only list the commonly used ones. If you want All the information = " Reference article, I think it is very detailed

Insert picture description here
In fact, all these types have a common structure, as shown in the figure below.
Insert picture description here
If you start an attribute table
, the first two bytes (attrubite_name_index) must be the nth constant item leading to the constant pool, a string of utf8 type, for example: Code, SourceFile, Synthetic, used to clarify the type of this attribute table,

Then 4 bytes (attrubite_length) are the remaining length of the attribute table. For example, the entire attribute table has 30 bytes,
then the previous 2 bytes name + 4 byte length + remaining length of the attribute table = 30, these 4 bytes are 00 00 00 18, 24 bytes

Then the following is our (example) 24 bytes, which are explained in different types of attribute tables

Analysis one by one below

Code attribute table (very important table)

The Code attribute appears in the attribute collection of the method table (excluding the methods of abstract classes or interfaces), and stores all the operations in our method body. The structure of the Code attribute table
Insert picture description here
is the same as the first 6 bytes in the following figure. not to say
1.max_stack
represent the maximum depth of the operand stack (operand stacks). At any time during the execution of the method, the operand stack will not exceed this maximum value. When the virtual machine is running, the operation stack depth in the stack frame (Stack Frame) needs to be allocated according to this value (specifically, we will talk about it later, we will talk about it when we enter the jvm, and we will have an impression)
2. max_locals
local variable table Required storage space. The unit is Slot
3.code_length
bytecode length,
4.code
compiled bytecode instruction, the length has been pointed out above
5.exception_table_length&&exception_table
length will not say, the length of the
exception_table type contains 4 fields (start_pc, end_pc, handler_pc, catch_type). The meaning of these fields is: when the bytecode is between the start_pc line and the end_pc line (the range of try), there is an exception of type catch_type or an exception of its subclass (catch_type is an index pointing to a CONSTANT_Class_info type constant), then jump Go to the handler_pc line to continue processing.
To be specific to each content in each exception_table, we don’t have to be so detailed. If there is a need, you can Baidu
6... Another attribute table is
not detailed.

SourceFile attributes

The SourceFile attribute is used to record the name of the source code that generated this Class file. This attribute is also optional, this attribute is a fixed-length attribute, and its structure is as follows:

The
Insert picture description here
 sourcefile attribute table structure sourcefile_index data item points to the index of the CONSTANT_Utf8_info constant in the constant pool. The constant value is the source file name in
 one sentence: which category will be displayed when an error is reported. If there is no such item, the category will not be displayed.

ConstantValue property

The function of the ConstantValue property is to notify the virtual machine to automatically assign a value to a static variable. Only variables modified by static can use this attribute.

InnerClasses attribute

The InnerClasses attribute is used to record the relationship between the inner class and the host class. If an inner class is defined in a class, the compiler will generate the InnerClasses property for it and the inner classes it contains. The property structure is shown in the following figure:
innerClass table structure
Insert picture description here
data item number_of_classes represents how many inner class information needs to be recorded, each The information of each internal class is described by an inner_classes_info table. The structure of the inner_classes_info table is as follows: the
Insert picture description here
first three are not mentioned , they are the constant items in the constant pool.
inner_class_access_flags: the access flags of the internal classes. See the following table :
Insert picture description here

Guess you like

Origin blog.csdn.net/lioncatch/article/details/105966782