JVM virtual machine --- (12) attribute 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/97785731

Property sheet collection

        And methods for Code ConstantValue table appears fields appear in the table, LineNumberTable property sheet sets are not do not understand, do not see the property before the table, I watch the two is a bit ignorant force, now say a special attribute table.

       Property sheet (attribute_info) in the fields of the table and the table method has appeared in the Class file, field table, table method can bring their own set of attribute table, for a description of certain scenes proprietary.

       Class files and other rigorous data items required by the order, content and different lengths, restrictions set attribute table is slightly looser, each attribute table has no longer requires strict order, and they do not duplicate existing attribute name, and any implement the compilers can write their own definition of property information as property sheet, ignores attribute it does not recognize the Java virtual machine is running.

        For each property, its name needs to be referenced from a constant pool of constants represent CONSTANT_Utf8_info type, and the structure of the attribute value is fully customizable, to explain only the attribute value bits occupied by the length of a property of u4 the number can be,

 

Code introduced here only attribute, not introduced

1.Code property

The method body code compiler Javac after processing becomes the final bytecode instructions stored in the Code attribute Code properties appear in the method table of the set of attributes, but not all the properties must be present method, e.g. the method of the interface, the abstract class does not exist in the Code attribute.

2. Case Code

public class TestMethod {

    public int add(int a,int b) {
		return a+b;
	}

}

I'm lazy point, but not too accurate way to find the property sheet for the name of the Code attribute table in javap obtain the corresponding data is 6, then the class file to find.

Case 3. The constructor property

  1. 属性表名称索引:0x0006(对应十进制为6),指向常量池的第6,为Code,表示是Code类型的属性表。
  2. 属性长度:0x0000 001D(对应十进制的29),表示后续29个字节是表示这个Code属性表的信息。
  3. 操作数栈的最大深度:0x0001(对应十进制的1),表示栈帧中操作数栈的最大深度是1。
  4. 局部变量表的最大容量:0x0001(对应十进制的1),JVM调用该方法时,根据这个值设置栈帧中的局部变量表的大小。
  5. 机器指令数目:0x0000 0005,表示后续的5个字节是机器指令集。
  6. 机器指令集:0x002A、0x00B7、0x0000、0x0001、0x00B1。
  7. 异常表:0x0000,表示异常为0。
  8. Code属性的属性表集合:0x0001,表示后面还有一个属性表。后面跟着这个属性。

如果再看的话,那就是0x0007:对应常量池,是LineNumberTable。这个就不用说了。

别忘了,这个是默认的无参构造器的属性表,想找add,还的继续找。

4.自定义方法属性案例

  1. 属性表名称索引:0x0006(对应十进制为6),指向常量池的第6,为Code,表示是Code类型的属性表。
  2. 属性长度:0x0000 001C(对应十进制的28),表示后续28个字节是表示这个Code属性表的信息。
  3. 操作数栈的最大深度:0x0002(对应十进制的2),表示栈帧中操作数栈的最大深度是2。
  4. 局部变量表的最大容量:0x0003(对应十进制的3),JVM调用该方法时,根据这个值设置栈帧中的局部变量表的大小。
  5. 机器指令数目:0x0000 0004,表示后续的4个字节是机器指令集。
  6. 机器指令集:0x001B、0x001C、0x0060、0x00AC。
  7. 异常表:0x0000,表示异常为0。
  8. Code属性的属性表集合:0x0001,表示后面还有一个属性表。后面跟着这个属性。

如果再看的话,那就是0x0007:对应常量池,是LineNumberTable。这个就不用说了。

 

Guess you like

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