A Java run-time memory area
When the JVM loads the class file, it shifts the data structure defined by the class file into the runtime memory, so how does the JVM schedule the memory area at run time?
The JVM divides the run-time memory into the following sections:
Heap: All Threads shared
Method area: Class information, static variables, constants, etc.
Run a constant pool: the Chang (literal and symbolic references) of a class file + runtime-generated constants
Program counter: The line number indicator of the byte code executed by the current thread
Virtual machine stack: stack frame = local local variable table, operand stack, dynamic link, export information
Local method Stack: Native method
Direct memory: Not part of JVM management, but in NiO, the native method is used to request out-of-heap memory and to save its references in the Java heap.
Where the heap and the method area are shared by all threads, and the virtual machine stack, the local method stack, and the program counter are exclusive to each thread.
Two class files
How is the class file defined? How does it relate to the Java runtime memory?
class file Format:
U4 Magic Number
U2 class file version number
U2 class file version number
U2 Constant_pool_count represents the constant pool capacity size, counting from 1;
There are two main classes in a constant pool: literal constants and symbolic references
Symbolic references also contain three classes: the fully qualified name of the class, the interface, the field name and description, the method name, and the description
Note that field constants and method constants are defined here. It is slightly different from the following character Cong/method table, but the same simple name and descriptor are reused.
Cp_info Constant_pool
A total of 11 constant items are defined
U2 Access_flag
Whether it is a class/interface, whether it is an abstract class, whether it is private, etc, whether it is final, etc.
U2 This_class
U2 Super_class
U2 Interface_count
U2 interfaces
Refer to the fully qualified name in the constant pool, point to the class/interface index, and then find the index of the Utf-8
U2 Fields_count
Field_info fields
The Field table contains fields access properties, field name indexes, descriptor indexes, and attribute;
Descriptor: array [, V void, L reference type, describes the method, first describes the parameter list with parentheses, followed by the return value description.
Field names inherited from the parent class and superclass are not listed in the field table
U2 Methods_count
Method_info methods
Method Table: Access properties, name index, description index, and attribute
If the method is not override, the method name inherited by the parent class does not appear
U2 Attributes_count
Attribute_info attributes
The Code property of the most important method table in the attribute table contains the details of the method, as follows:
U2 Attribute_name_index
U4 Attribute_length
U2 max_stack Maximum depth of the operand stack
U2 Max_locals
U4 Code_length
U1 code * code_length
.... Exception table, etc.
Deep understanding of Java Virtual Machine a Java Runtime memory area and class file