Java ClassFile 附加字节?

Java ClassFile additional byte?

我阅读了有关 Java ClassFile 的文章,并试图理解其中的每个字节。基本上除了一件事之外一切都很清楚......在方法定义(代码属性)之后有 SourceFile 属性。但在此之前还有额外的字节。

Hello.java


public class Hello {    
}

Hello.class

CA FE BA BE 00 00 00 34 00 0D 0A 00 03 00 0A 07 00 0B 07
00 0C 01 00 06 3C 69 6E 69 74 3E 01 00 03 28 29 56 01 00 
04 43 6F 64 65 01 00 0F 4C 69 6E 65 4E 75 6D 62 65 72 54 
61 62 6C 65 01 00 0A 53 6F 75 72 63 65 46 69 6C 65 01 00 
0A 48 65 6C 6C 6F 2E 6A 61 76 61 0C 00 04 00 05 01 00 05 
48 65 6C 6C 6F 01 00 10 6A 61 76 61 2F 6C 61 6E 67 2F 4F 
62 6A 65 63 74 00 21 00 02 00 03 00 00 00 00 00 01 00 01 
00 04 00 05 00 01 00 06 00 00 00 1D 00 01 00 01 00 00 00 
05 2A B7 00 01 B1 00 00 00 01 00 07 00 00 00 06 00 01 00 
00 00 01 00 01 00 08 00 00 00 02 00 09 

我们对以下字节感兴趣:(这些是最后一个)

Code attribute        06 00 00 00 1D 00 01 00 01 00 00 00 05 2A B7 00 01 B1 00
                      00 00 01 00 07 00 00 00 06 00 01 00 00 00 01

What are these?       00 01 
SourceFile attribute  00 08 00 00 00 02 00 09

我根据Code Attribute doc

分析了Code属性的数据

应该是attributes_count.

The value of the attributes_count item indicates the number of attributes of the Code attribute.

来源:

https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.3 https://en.wikipedia.org/wiki/Java_class_file