jvm class file structure analysis (access flag, abnormal)

1, the access flag

(1) concept

Immediately after the two-byte constant pool, an interface for identifying a hierarchy of classes or access information, including the class or interface to be tired, whether the public type, abstract type, class is declared final and the like

(2) access flag table:

Flag Flag Name Value Meaning 
ACC_PUBLIC     0x0001        whether the public type 
ACC_FINAL      0x0010        whether declared final, the class may be provided only 
ACC_SUPER      0x0020 invokespecial allow the use of new semantic bytecode instructions, the instructions over invokespecial semantic change in JDK 1.0.2, 
to distinguish this instruction which uses semantic, JDK 1.0 this flag .2 compiled after the class must be true ACC_INTERFACE 0x0200 logo which is an interface ACC_ABSTRACT 0x0400 whether the abstract type, interface or abstract class for it, this flag is true, the other class is false ACC_SYNTHETIC 0x1000 identifies the class is not generated by user code ACC_ANNOTATION 0x2000 identifies this is a comment ACC_ENUM 0x4000 logo which is an enumeration

(3) access control flags:

Immediately following the constant pool part:

 

 

 Combined with the above table, it can be drawn is modified public to view the source code:

public class Student {
    private String name;
    private Integer age;

(4) Index type, interface index and the parent index

The order of: Class Index (u2), the parent index (u2) on the interface index set (first type of interface is u2 counter indicates the capacity index of the table, i.e. implements several interfaces, if implemented without any interface, the value is zero, the latter not take up any interface index byte), integrated class files to determine the relationship of this class with three, if there is an interface, will be behind the interface.

 

 

 Source:

public class mytest extends Thread implements Serializable,Comparable {

(5) Properties virtual machine specification table structure and predefined properties:

Field table structure:

Variables used to describe the interface or declared in the class, including field-level class-level variables and instance variables, but not included in the local variables declared inside the method, field name, please, why the field is defined types are not fixed, so only the constant references to the constant pool can be described.

Number Name Type 
U2 access_flags         . 1 access specifier (eg: 
public) U2 name_index           . 1 index name (such as: inc 
is) U2 descriptor_index     . 1 descriptors (e.g. :()) ----- inc is public int 
() U2 attributes_count     . 1   
attribute_info attributes attributes_count

Property sheet:

Number Name Type 
U2 attribute_name_index     an attribute name index 
u4 attribute_length     length attribute 1 
u1 info attribute_length not equal to 2 + 4 + 1, equals u2 + u4 + u1 * 190 = 196

VM predefined attributes:

Attribute name Meaning use position 
 Code Method Table Java code is compiled into bytecode instructions 
 ConstantValue final keyword list field constant pool defined 
 Deprecated classes, methods, fields table is declared as deprecated and field 
 Exceptions thrown exception Methods Method 
 EnclosingMethod class file only when a class is a partial class or a class can have the anonymous attribute that identifies the class where method peripheral 
 InnerClass inner class class file list 
 LineNumberTable code attribute Java source code line numbers and bytecode instruction a correspondence relationship 
 LocalVariableTable Code attributes wolf method will be described local 
 StackMapTable Code attribute in JDK1.6 new attributes for the new type of checking whether the verifier checks and local variables and an operand processing target method in need class matches 
 Signature class the method table, field table for supporting a generic method in the case of signature 
 SourceFile class file name of the source file records 
 SourceDebugExtension class file for storing additional debugging information 
 Synthetic classes, methods, tables, fields or methods table flag field for the compiler automatically generates   of
 LocalVariableTypeTable class signatures instead of using the descriptor is to describe generic parameter types is added after the introduction of the generic syntax 
 RuntimeVisibleAnnotations class method table, field table to support dynamic annotations 
 RuntimeInvisibleAnnotations table, the method table, field table for indicating which annotations are invisible runtime 
 RuntimeVisibleParameterAnnotation method RuntimeVisibleAnnotations attribute table function and similar, but the role object is a method 
 RuntimeInvisibleParameterAnnotation RuntimeInvisibleAnnotations method table function and properties similar to the role which the object is a method parameter 
 default AnnotationDefault method for recording a table-based annotation element 
 BootstrapMethods class file for storing the boot mode instruction references invokeddynamic qualifier  

The number of local variables and methods deep stack (6) Method

 

2, abnormal

(1) exception table:

Name Type Quantity 
start_pc U2        1 
end_pc U2        1 
handle_pc U2       1 
catch_pc U2     1

(2) Example:

00 00 00 04  00 08 00 02 ------0 4 8 #2

Exception handling is divided into two: throw and try .... catch (block)

 

0-4 rows abnormal jump to the seventeenth line ... ... 

 

 

 

 to sum up:

(1) stack depth and number:

Deep Stack: stack

The number of local variables: locals

(2) parameters:

 

Data that describes the classes: (3) Metadata

(4) Class name: can not exceed 256

 

Guess you like

Origin www.cnblogs.com/zhai1997/p/12565905.html