- class file Structure
- Data type in class file
U1, U2, U4 represent unsigned 1, 2, 4 byte data.
The 0......* type data will be represented as table.
- Classfile structure
U4 Magic;
U2 minor_version;
U2 major_version;
U2 Constant_pool_count;
Cp_info Constant_pool[constant_pool_count-1];
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];
- Magic
- Minor_version, Major_version
- Constant_pool_count
- Constant_pool[]
Chang (indexed by [1,constant_pool_count-1]), stores string constants, class and interface names, field names, and other constants that are referenced by the class file structure and sub-structures.
Each cell in a constant pool is labeled with a "tag" byte.
- Access_flags
Access permission Flags
Class and Interface access rights indicator
Acc_public 0x0001 declared public; May is accessed from outside it package.
Acc_final 0x0010 declared FINAL; No subclasses allowed.
Acc_super 0x0020 Treat Superclass methods specially when invoked bythe invokespecial instruction.
Acc_interface 0x0200 is an INTERFACE, not a class.
Acc_abstract 0x0400 declared ABSTRACT; must not being instantiated.
Acc_synthetic 0x1000 declared synthetic; Generated by a compiler and not present in the source code.
Acc_annotation 0x2000 declared as an ANNOTATION type.
Acc_enum 0x4000 declared as an ENUM type.
The Acc_enum flag indicates, the this class, or its superclass are declared as an enumerated type.
An annotation type must has its acc_annotation flag set. If the Acc_annotation flag is set, the ACC_INTERFACE flag must are set as well. IF Theacc_interface Flag of this class file was not set, it may have any of the the other flags in Table 4.1 set, except the AC C_annotation flag. However, such a class file cannot has both its acc_final and Acc_abstract flags set (jls§8.1.1.2).
The Acc_super flag indicates which of the alternative semantics are to being expressed by the invokespecial instruction (§invo kespecial) If it appears in the This class. Compilers to the instruction set of the Java Virtual machine should set the ACC_SUPER flag.
The ACC_SUPER flag exists for backward compatibility and code compiled by older compilers for the Java programming Langua Ge. In Oracle's JDK prior to release 1.0.2, the compiler generated Classfile access_flags in which the flag now representing A Cc_super had no assigned meaning, and Oracle ' s Java Virtual machine implementation ignored the flag if it is set.
All bits of the Access_flags item is not assigned in Table 4.1 is reserved for future use. They should is set to zero in generated class files and should is ignored by Java Virtual machine implementations.
- This_class
- Super_class
- Interfaces_count
- Interfaces[]
- Fields_count
- Fields[]
- Methods_count
- Methods[]
- Attributes_count
- Attributes[]
- Load, connect, and initialize
-
- Run a constant-rate pool
- Load
- Connection
- Initialization
The initialization of a class or interface, including methods that run a class or interface. When a Java Virtual machine Initializes a class, all of its parent classes are required to be initialized, but this rule does not apply to the interface.
- Initialization of the class
During the initialization phase, the Java virtual machine executes the initialization statement of the class, assigning the initial value to the static variables of the class. Declarations of static variables, as well as static blocks of code, are treated as initialization statements for classes, and Java virtual opportunities execute them sequentially in the order in which the initialization statements are in the class file.
In a program, there are two ways to initialize a static variable:
Initialize at the declaration of the static variable;
Initialize in a static block of code.
- Initialization steps for a class
If the class has not been loaded and connected, load and connect it first.
If the class has a direct parent class, and the parent class is not initialized, the immediate parent class is initialized first.
If there are initialization statements in the class, then these initialization statements are executed sequentially.
- The initialization time of the class
Each class or interface is initialized when it is first actively used by a Java program.
To create an instance of a class
Access a static variable for a class or interface, or assign a value to the static variable.
Invokes the static method of the class.
Reflection.
Initializes a subclass of a class.
A class that is marked as the startup class when the Java virtual machine is started.
- The particularity of the interface
When a class is initialized, the interface it implements is not initialized first.
When an interface is initialized, its parent interface is not initialized first.
- Static variables of final type
Whether a static variable of the final type is a compile constant or variable affects the execution of the initialization statement block.
If the value of a static variable is a compile-time constant, the type is not initialized (the static block of the class does not execute);
If the value of a static variable is a non-compile constant, that is, only the runtime has a deterministic initialization value, the type is initialized (the static block of the class is executed).
- Attribution clarity of active use
- Class Loader
- Three types of system-supplied class loaders
- Launch class loader (Bootstrap ClassLoader)
- Extension class loader (Extension ClassLoader)
- Application class loader (application ClassLoader)
- Parental delegation Model
In this model, the ClassLoader implements hierarchical relationships in a combined pattern, except for the top-level ClassLoader, where the class loader should have a parent classloader. When class loading occurs, precedence is loaded by the parent class loader.
- Threading Context Loader (thread contextual ClassLoader)
The child ClassLoader is loaded by the parent class loader assignment. Applies to load actions that involve the SPI (Service Provider Interface), such as Jndi, JDBC, JCE, JAXB, Jbi, and so on.
- Osgi
This article is from the Java Technology Stack notes blog, so be sure to keep this source http://stroll.blog.51cto.com/11038467/1852661
JVM (iii)-Class structure and class loader