Java Class ファイルを読む(3)

Java Class ファイルを読む(2) - アウトスタンディングなプログラマを目指しての続き。

constant_pool[4]
00000010  00 0d 07 00 0e 01 00 06  3c 69 6e 69 74 3e 01 00  |..........|

tagの値が1(0x01)なので、CONSTANT_Utf8。
CONSTANT_Utf8の場合のフォーマットは

CONSTANT_Utf8_info {
    u1 tag;
    u2 length;
    u1 bytes[length];
}

という文字列を表す。

constant_pool[5]
00000010  00 0d 07 00 0e 01 00 06  3c 69 6e 69 74 3e 01 00  |..........|
00000020  03 28 29 56 01 00 04 43  6f 64 65 01 00 0f 4c 69  |.()V...Code...Li|

()Vという文字列を表す。

constant_pool[6]
00000020  03 28 29 56 01 00 04 43  6f 64 65 01 00 0f 4c 69  |.()V...Code...Li|

Codeという文字列を表す。

constant_pool[7]
00000020  03 28 29 56 01 00 04 43  6f 64 65 01 00 0f 4c 69  |.()V...Code...Li|
00000030  6e 65 4e 75 6d 62 65 72  54 61 62 6c 65 01 00 04  |neNumberTable...|

LineNumberTableという文字列を表す。

constant_pool[8]
00000030  6e 65 4e 75 6d 62 65 72  54 61 62 6c 65 01 00 04  |neNumberTable...|
00000040  6d 61 69 6e 01 00 16 28  5b 4c 6a 61 76 61 2f 6c  |main...([Ljava/l|

mainという文字列を表す。

constant_pool[9]
00000040  6d 61 69 6e 01 00 16 28  5b 4c 6a 61 76 61 2f 6c  |main...([Ljava/l|
00000050  61 6e 67 2f 53 74 72 69  6e 67 3b 29 56 01 00 0a  |ang/String;)V...|

([Ljava/lang/String;)Vという文字列を表す。

constant_pool[10]
00000050  61 6e 67 2f 53 74 72 69  6e 67 3b 29 56 01 00 0a  |ang/String;)V...|
00000060  53 6f 75 72 63 65 46 69  6c 65 01 00 09 42 61 73  |SourceFile...Bas|

SourceFileという文字列を表す。

constant_pool[11]
00000060  53 6f 75 72 63 65 46 69  6c 65 01 00 09 42 61 73  |SourceFile...Bas|
00000070  65 2e 6a 61 76 61 0c 00  04 00 05 01 00 04 42 61  |e.java........Ba|

Base.javaという文字列を表す。

constant_pool[12]
00000070  65 2e 6a 61 76 61 0c 00  04 00 05 01 00 04 42 61  |e.java........Ba|

tagの値が12(0x0c)なので、CONSTANT_NameAndType。
CONSTANT_NameAndTypeの場合のフォーマットは

CONSTANT_NameAndType_info {
    u1 tag;
    u2 name_index;
    u2 descriptor_index;
}

name_indexが04(0x0004)で, descriptor_indexが05(0x0005)で()V。
()Vはメソッド・ディスクリプタ(MethodDescriptor)フォーマットで、

MethodDescriptor:
    ( ParameterDescriptor* ) ReturnDescriptor

ParameterDescriptor:
    FieldType

ReturnDescriptor:
    FieldType
    V

引数(パラメータ)なし、戻り値なし(Void)を表す。


続きはJava Class ファイルを読む(4) - アウトスタンディングなプログラマを目指して