锘??xml version="1.0" encoding="utf-8" standalone="yes"?> 鍒版錛屽父閲忔睜緇撴潫銆?br />
00 21錛氱被鐨勬弿榪扮涓簆ublic銆?br />
00 03 錛歵his class涓哄父閲忔睜絎笁涓紝TJ錛屽嵆榪欎釜綾葷殑鍚嶅瓧涓篢J attribute_name_index錛?錛屽嵆ConstantValue錛岀粨鏋勫涓?br />
ConstantValue_attribute { 00 03錛?涓柟娉曘?br />
method_info {
鍏堜笂class鏂囦歡鐨勬牸寮忋?code>
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];
}
鍏朵腑錛寀2浠h〃2涓瓧鑺傜殑鏃犵鍙鋒暣鏁般倁4浠h〃4涓瓧鑺傜殑鏃犵鍙鋒暣鏁幫紝鍏朵粬濡?/code>
cp_info
銆?/span>field_info
鏄竴浜涚粨鏋勬暟鎹紝鎺ヤ笅鍘諱細璁層?br />
榪欐瑕佽В鏋愮殑鏄竴涓潪甯哥畝鍗曠殑綾伙細TJ.java錛屼唬鐮佸涓嬶細
{
private final int f1 = 2;
public int m1(int i){
return i+1;
}
private void m2(){
}
}
浣跨敤jdk1.6緙栬瘧錛屼駭鐢熺殑浜岃繘鍒剁被鏂囦歡濡備笅錛?br />
00 03 00 13 07 00 14 07 00 15 01 00 02 66 31 01
00 01 49 01 00 0D 43 6F 6E 73 74 61 6E 74 56 61
6C 75 65 03 00 00 00 02 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 02 6D 31 01 00 04 28 49 29 49 01 00 02 6D
32 01 00 0A 53 6F 75 72 63 65 46 69 6C 65 01 00
07 54 4A 2E 6A 61 76 61 0C 00 09 00 0A 0C 00 05
00 06 01 00 02 54 4A 01 00 10 6A 61 76 61 2F 6C
61 6E 67 2F 4F 62 6A 65 63 74 00 21 00 03 00 04
00 00 00 01 00 12 00 05 00 06 00 01 00 07 00 00
00 02 00 08 00 03 00 01 00 09 00 0A 00 01 00 0B
00 00 00 26 00 02 00 01 00 00 00 0A 2A B7 00 01
2A 05 B5 00 02 B1 00 00 00 01 00 0C 00 00 00 0A
00 02 00 00 00 01 00 04 00 03 00 01 00 0D 00 0E
00 01 00 0B 00 00 00 1C 00 02 00 02 00 00 00 04
1B 04 60 AC 00 00 00 01 00 0C 00 00 00 06 00 01
00 00 00 06 00 02 00 0F 00 0A 00 01 00 0B 00 00
00 19 00 00 00 01 00 00 00 01 B1 00 00 00 01 00
0C 00 00 00 06 00 01 00 00 00 0B 00 01 00 10 00
00 00 02 00 11涓嬮潰瀵圭収涓婇潰鐨勬牸寮忕粨鏋勪竴鐐圭偣鐨勮В鏋愩?br />
CA FE BA BE錛氬ご鍥涗釜瀛楄妭鏄瓟鏁幫紝琛ㄧず榪欐槸java class鏂囦歡銆?br />
00 00錛氭鐗堟湰涓?銆?br />
00 32錛氫富鐗堟湰0x32錛岃〃紺簀dk1.6緙栬瘧鐨勩侸dk1.5涓?x31錛宩dk1.4涓?x30銆?br />
00 16錛氬父閲忔睜鐨勫叆鍙o紙entry錛夋暟閲忋傚寘鎷嚜宸辨湰韜紙榪欓噷寰堝鎬級錛屾墍浠ユ帴涓嬫潵鏈?1欏圭殑甯擱噺姹犲叆鍙c?br />
鎴戜細鍦ㄦ瘡涓父閲忔睜欏圭殑鍓嶉潰琛ㄤ笂绱㈠紩銆傚父閲忔睜鐨勭涓涓瓧鑺傝〃紺虹被鍨嬨傚叿浣撶被鍨嬪鐓ц〃濡備笅錛?br />
Constant Type
Value
CONSTANT_Class
7
CONSTANT_Fieldref
9
CONSTANT_Methodref
10
CONSTANT_InterfaceMethodref
11
CONSTANT_String
8
CONSTANT_Integer
3
CONSTANT_Float
4
CONSTANT_Long
5
CONSTANT_Double
6
CONSTANT_NameAndType
12
CONSTANT_Utf8
1
0A 00 04 00 12錛?span style="color: red">銆?銆?/span>錛岀涓涓瓧鑺備負10錛屾墍浠ユ槸CONSTANT_Methodref錛屽畠鐨勭粨鏋勫涓嬶細
CONSTANT_Methodref_info {
u1 tag;
u2 class_index;
u2 name_and_type_index;
}
鎵浠ワ紝class_index=4錛宯ame_and_type_index=12,榪欎袱涓唬琛ㄥ父閲忔睜絎?欏瑰拰絎?2欏廣?br />
09 00 03 00 13錛?span style="color: red">銆?銆?/span> 榪欐槸涓涓狢ONSTANT_Fieldref錛屼粬鐨勭粨鏋勫拰涓婇潰鐨勭被浼糲lass_index=3錛宯ame_and_type_index=13
07 00 14錛?span style="color: red">銆?銆?/span>榪欎釜鏄疌ONSTANT_Class錛屽畠鐨勭粨鏋勫涓嬶細
CONSTANT_Class_info {
u1 tag;
u2 name_index;
}
name_index涓?0錛屾寚鍚戠殑鏄竴涓猽tf8鐨勫瓧鑺傜爜錛屽嵆TJ錛岃繖涓悗闈細鐪嬪埌銆?br />
07 00 15: 銆?銆?涔熸槸涓涓?/span>CONSTANT_Class錛宯ame_index涓?1錛屽嵆java/lang/Object
01 00 02 66 31: 銆?銆?/span>CONSTANT_Utf8錛岀粨鏋勫涓嬶細
CONSTANT_Utf8_info {
u1 tag;
u2 length;
u1 bytes[length];
}
鏈鍚庝袱涓瓧鑺備唬琛ㄥ瓧絎︿覆“f1”鐨剈tf-8瀛楄妭鐮併?br />
01 00 01 49錛氥?銆?/span>瀛楃涓睮
01 00 0D 43 6F 6E 73 74 61 6E 74 56 61 6C 75 65 錛氥?銆?/span>瀛楃涓睠onstantValue
03 00 00 00 02錛氥?銆?/span>CONSTANT_Integer錛屾暣鏁板?
01 00 06 3C 69 6E 69 74 3E錛氥?銆戝瓧絎︿覆<init>
01 00 03 28 29 56錛氥?0銆戝瓧絎︿覆()V
01 00 04 43 6F 64 65錛氥?1銆戝瓧絎︿覆code
01 00 0F 4C 69 6E 65 4E 75 6D 62 65 72 54 61 62 6C 65錛氥?2銆戝瓧絎︿覆LineNumberTable
01 00 02 6D 31錛氥?3銆戝瓧絎︿覆m1
01 00 04 28 49 29 49 錛氥?4銆戝瓧絎︿覆(I)I錛岃〃紺轟竴涓暣鏁板弬鏁頒笖榪斿洖鏁存暟鐨勬柟娉曘?br />
01 00 02 6D 32 錛氥?5銆戝瓧絎︿覆m2
01 00 0A 53 6F 75 72 63 65 46 69 6C 65 錛氥?6銆戝瓧絎︿覆SourceFile
01 00 07 54 4A 2E 6A 61 76 61錛氥?7銆戝瓧絎︿覆TJ.java
0C 00 09 00 0A錛氥?8銆慍ONSTANT_NameAndType錛岀粨鏋勫涓嬶細
CONSTANT_NameAndType_info {
u1 tag;
u2 name_index;
u2 descriptor_index;
}
name_index=9錛屼唬琛ㄦ柟娉?lt;init>錛宒escriptor_index=10錛?)V錛屼唬琛ㄦ棤鍙備笖榪斿洖void鐨勬柟娉曘?br />
0C 00 05 00 06錛氥?9銆戠粨鏋勫悓涓婏紝name_index=5錛屽嵆f1錛宒escriptor_index=6錛屽嵆鏁存暟銆?br />
01 00 02 54 4A 錛氥?0銆戝瓧絎︿覆TJ
01 00 10 6A 61 76 61 2F 6C 61 6E 67 2F 4F 62 6A 65 63 74錛氥?1銆戝瓧絎︿覆java/lang/Object
00 04錛歴uper class涓哄父閲忔睜絎洓涓紝java/lang/Object錛屽嵆瀹冪殑瓚呯被涓簀ava.lang.Object
00 00錛氭帴鍙d釜鏁?銆?br />
00 01錛歠ield鏁伴噺1銆?br />
00 12 00 05 00 06 00 01 00 07 00 00 00 02 00 08錛歠ield鐨勭粨鏋勫涓?br />
field_info {
u2 access_flags;
u2 name_index;
u2 descriptor_index;
u2 attributes_count;
attribute_info attributes[attributes_count];
}
access_flags涓?0 12錛屼唬琛ˋCC_PRIVATE+ ACC_FINAL
name_index錛氬父閲忔睜绱㈠紩涓?鐨勫叆鍙o紝鍗砯1錛屽嵆綾繪垚鍛樼殑鍚嶅瓧涓篺1
descriptor_index錛欼錛屼唬琛╥nteger銆?br />
attributes_count錛?涓?br />
attribute_info錛?br />
attribute_info {
u2 attribute_name_index;
u4 attribute_length;
u1 info[attribute_length];
}
u2 attribute_name_index;
u4 attribute_length;
u2 constantvalue_index;
}
attribute_length錛?
constantvalue_index錛?
----------------------------------------涓嬮潰寮濮嬫柟娉?/span>
u2 access_flags;
u2 name_index;
u2 descriptor_index;
u2 attributes_count;
attribute_info attributes[attributes_count];
}
--------------------------------------------絎竴涓柟娉?lt;init>錛岃繖涓槸緙栬瘧鍣ㄤ駭鐢熺殑鐢熸垚瀹炰緥鐨勫垵濮嬪寲鏂規硶銆?br />
access_flags錛歱ublic
name_index錛?0 09錛?lt;init>
descriptor_index錛?0 0A錛?)V琛ㄧず鏃犲弬鏁幫紝榪斿洖void
attributes_count :00 01,1涓?br />
attribute_name_index 錛?0 0B 錛宑ode
attribute_length錛?8涓?br />
Code_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 max_stack;
u2 max_locals;
u4 code_length;
u1 code[code_length];
u2 exception_table_length;
{ u2 start_pc;
u2 end_pc;
u2 handler_pc;
u2 catch_type;
} exception_table[exception_table_length];
u2 attributes_count;
attribute_info attributes[attributes_count];
}
max_stack: 00 02
max_locals: 00 01
code_length: 00 00 00 0A,10
code: 2A B7 00 01 2A 05 B5 00 02 B1,鎸囦護
exception table length錛?0 00
attributes_count錛?
attribute_name_index錛?0 0C錛孡ineNumberTable
LineNumberTable_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 line_number_table_length;
{ u2 start_pc;
u2 line_number;
} line_number_table[line_number_table_length];
}
attribute_length錛?0
line_number_table_length錛?
start_pc錛?0 00
line_number錛?0 01
tart_pc錛?0 04
line_number錛?0 03
鍒版絎竴涓柟娉曠粨鏉熴?br />
----------------------------------------------------------------------絎簩涓柟娉曞紑濮?br />
access_flags錛?span lang="EN-US">00 01錛?span lang="EN-US">public
name_index錛?0 0D錛宮1
desc_index錛?0 0E錛?I)I錛屾湁涓涓暣鏁板弬鏁幫紝榪斿洖涓涓暣鏁般?br />
00 01錛氫竴涓猘ttr
00 0B錛歝ode
00 00 00 1C錛歛ttr_length:28
Code_atrr:28涓瓧鑺傦紝涓嶅垎鏋愪簡鍜屼笂闈㈢殑鏂規硶鐩稿悓銆?br />
----------------------------------------------------------------------絎笁涓柟娉?br />
00 02錛歱rivate
00 0F錛歮2
00 0A: ()V錛屾棤鍙傦紝榪斿洖void
00 01錛氫竴涓猘ttr
00 0B錛歝ode
00 00 00 19錛歛ttr_length 25
鎺ヤ笅鍘葷殑25涓瓧鑺傛槸Code_atrr錛屽悓鏍蜂笉鍒嗘瀽浜嗐?br />
------------------------------------------------------------------
00 01錛?涓被鐨刟ttr
00 10錛歋ourceFile
00 00 00 02錛歭en=2
00 11錛?7錛孴J.java