Class 類檔案結構
阿新 • • 發佈:2021-08-13
Class 類檔案結構
型別 | 名稱 | 數量 | 描述 |
---|---|---|---|
u4 | magic | 1 | 魔數,值為:0xCAFEBABY |
u2 | minor_version | 1 | 次版本號 |
u2 | magor_version | 1 | 主版本號 |
u2 | constant_pool_count | 1 | 常量池容量,從1開始 |
cp_info | constant_pool | constant_pool_count - 1 | 字面量和符號引用 |
u2 | access_flags | 1 | 訪問標誌 |
u2 | this_class | 1 | 類索引 |
u2 | super_class | 1 | 父類索引 |
u2 | interfaces_count | 1 | 介面索引數量 |
u2 | interfaces | interfaces_count | 介面索引集合 |
u2 | fields_count | 1 | 欄位表數量 |
field_info | fields | fields_count | 欄位表集合 |
u2 | methods_count | 1 | 方法表數量 |
method_info | methods | methods_count | 方法表集合 |
u2 | attributes_count | 1 | 屬性表數量 |
attribute_info | attributes | attributes_count | 屬性表集合 |
public class Father { } public class Test { private int m; private static final String DEFAULT = "Hello"; public int inc() { return m + 1; } }
javap -v -p Test
Classfile /Users/mervyn/Documents/Test.class Last modified Aug 10, 2021; size 356 bytes MD5 checksum 61c1cacb68c1d46c7964400ddb638849 Compiled from "Test.java" public class Test extends Father implements java.lang.Cloneable minor version: 0 major version: 52 flags: ACC_PUBLIC, ACC_SUPER /* 常量池 */ Constant pool: #1 = Methodref #4.#20 // Father."<init>":()V #2 = Fieldref #3.#21 // Test.m:I #3 = Class #22 // Test #4 = Class #23 // Father #5 = Class #24 // java/lang/Cloneable #6 = Utf8 m #7 = Utf8 I #8 = Utf8 DEFAULT #9 = Utf8 Ljava/lang/String; #10 = Utf8 ConstantValue #11 = String #25 // Hello #12 = Utf8 <init> #13 = Utf8 ()V #14 = Utf8 Code #15 = Utf8 LineNumberTable #16 = Utf8 inc #17 = Utf8 ()I #18 = Utf8 SourceFile #19 = Utf8 Test.java #20 = NameAndType #12:#13 // "<init>":()V #21 = NameAndType #6:#7 // m:I #22 = Utf8 Test #23 = Utf8 Father #24 = Utf8 java/lang/Cloneable #25 = Utf8 Hello { /* 欄位表集合 */ private int m; descriptor: I flags: ACC_PRIVATE private static final java.lang.String DEFAULT; descriptor: Ljava/lang/String; flags: ACC_PRIVATE, ACC_STATIC, ACC_FINAL ConstantValue: String Hello /* 方法表集合 */ public Test(); descriptor: ()V flags: ACC_PUBLIC Code: stack=1, locals=1, args_size=1 0: aload_0 1: invokespecial #1 // Method Father."<init>":()V 4: return LineNumberTable: line 1: 0 public int inc(); descriptor: ()I flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: getfield #2 // Field m:I 4: iconst_1 5: iadd 6: ireturn LineNumberTable: line 5: 0 } /* 屬性表集合 */ SourceFile: "Test.java"