JVM virtual machine --- (10) field table file structure of the Class collection

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/qq1021979964/article/details/97129322

Fields set of tables

Field tables set is the set of tables of several fields.

Table field (field_info) used to describe variables declared in the class or interface to, a field (field) comprises a class instance variables and class variables level, but does not include local variables declared inside method.

1. Information contained

  1. Scope field (public, private, protected modifier).
  2. It is an instance variable or class variable (static modifier).
  3. Variability (final).
  4. Concurrent visibility (volatile modifier, whether to force from the main memory read and write).
  5. It can be serialized (transient modifier).
  6. Field data type (basic types, objects, arrays).
  7. Field Name

The above information, each modifier is a Boolean value, or there is a modifier, or not, fit in a flag. Field Name, type is not fixed, can only be used to describe the constant in the constant pool.

Table 2. Structure field (field_info) Composition

Access flag (access_flags), name index (name_index), description Index (descriptor_index), a collection of attribute table

3. Case

public class TestConstant {
    private final int a = 10;
    private final int b = 10;
    private int c = 11;
    private int d = 11;
    private long e = -11111110005514L;
    private long f = -11111110005514L;
    private double g = 10.4557848D;
    private double h = 10.4557848D;
    private String y = "JVM";
    private String j = "JVM";
}

Immediately after the interface index is a collection of fields of the table

Number of fields: 0x000A (corresponding to the decimal value 10), the number of fields is 10.

Table 4. Field set Case

It can be learned

  1. Field access flags: 0x0012 = (0x0002 + 0x00010), the modifier field is private + final.
  2. Field Name: 0x0013 (corresponding to decimal 19), 19, pointing to the name field constant pool is a.
  3. Field Data Type: 0x0014 (corresponding to decimal 20), 20, corresponding to the constant pool types directed to int.
  4. Counter attribute table: 0x0001 (corresponding to decimal 1), there is a corresponding property table.
  5. 属性表名称索引:0x0015(对应的十进制为21),指向常量池的21,ConstantValue。
  6. 属性长度:0x0002,因此该属性的的ConstantValue类型,固定值为2.
  7. 常量值索引:0x0016(对应的十进制为22),指向常量池的22,对应的字段值为10。

依次类推

Guess you like

Origin blog.csdn.net/qq1021979964/article/details/97129322