Five, Java virtual machine execution subsystem

Class file structure

The class file is represented by the structure of the C language:

ClassFile {
    u4 magic; // 魔数
    u2 minor_version; // 次版本号
    u2 major_version; // 主版本号
    u2 constant_pool_count; // 常量池大小
    cp_info constant_pool[constant_pool_count-1]; // 常量池主要存放两大类常量:字面量(Literal)和符号引用(Symbolic References)
    u2 access_flags; // 访问标志,这个标志用于识别一些类或者接口层次的访问信息
    u2 this_class;  // 类索引
    u2 super_class;  // 父类索引
    u2 interfaces_count;  // 接口计数器,标识索引表的容量
    u2 interfaces[interfaces_count];  // 接口索引集合
    u2 fields_count;  // 字段表容量
    field_info fields[fields_count];  // 字段表集合
    u2 methods_count;  // 方法表容量
    method_info methods[methods_count];  // 方法表集合
    u2 attributes_count;  // 属性表容量
    attribute_info attributes[attributes_count];  // 属性表集合
}

2. Introduction to bytecode instructions

Synchronization instruction

The Java virtual machine can support method-level synchronization and synchronization of a sequence of instructions within a method. Both of these synchronization structures are implemented using monitors (more commonly referred to as "locks"). Synchronized is used in Java to achieve synchronization. The Java virtual machine has two instructions in the instruction set of monitorenter and monitorexit to support the semantics of the synchronized keyword. The correct implementation of the synchronized keyword requires the cooperation and support of both the Javac compiler and the Java virtual machine.

 

 

Reference: <In-depth understanding of the Java virtual machine: JVM advanced features and best practices third edition>

Guess you like

Origin blog.csdn.net/qq_32323239/article/details/105913337