国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

JVM之Class文件結構

2019-11-18 12:14:06
字體:
來源:轉載
供稿:網友

  定義:u1  1個字節為單位的非負值
  u2  2個字節為單位的非負值
  u3  . . . . . . . . (其他以此類推 )
  
  java文件結構用類似strUCt的描述如下:
  
  ClassFile {
  u4 magic;        // 必須為: 0xCAFEBABE
  
  u2 minor_version;
  u2 major_version;    //CLASS文件結構主次版本號 JAVA2支持45.0-46.
  0
  u2 constant_pool_count; //記錄常量信息
  cp_info constant_pool[constant_pool_count-1];  //計數從1開始
  u2 access_flags;    //class/interface訪問權限
  u2 this_class;     //指向constant_poll中的有效索引值
  u2 super_class;     //0或指向constant_poll中的有效索引值,對于in
  terface必須為非0
  u2 interfaces_count;  //superinterfaces的個數
  u2 interfaces[interfaces_count]; //計數[0,count-1) 對應constant_po
  ol中的一個索引值
  u2 fields_count;
  field_info fields[fields_count]; //主要用于記錄class及實例中的變量
  u2 methods_count;
  method_info methods[methods_count];
  u2 attributes_count;
  attribute_info attributes[attributes_count];
  }
  
  cp_info {
  u1 tag;
  
  u1 info[];
  }
  tag 意義如下:
  
  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
  
  此時cp_info分別對應結構變化為
  1. CONSTANT_Class
  CONSTANT_Class_info {
  u1 tag;
  u2 name_index;
  }
  
  2. CONSTANT_Fieldref
  CONSTANT_Fieldref_info {
  u1 tag;
  u2 class_index; //constant_pool的索引,對應CONSTANT_Class_
  info
  u2 name_and_type_index;//constant_pool的索引,對應CONSTANT_
  NameAndType_info
  }
  
  3. CONSTANT_Methodref
  CONSTANT_Methodref_info {
  u1 tag;
  u2 class_index;
  u2 name_and_type_index;
  }
  
  4. CONSTANT_InterfaceMethodref
  CONSTANT_InterfaceMethodref_info {
  u1 tag;
  u2 class_index;
  u2 name_and_type_index;
  
  }
  
  5. CONSTANT_String
  CONSTANT_String_info {
  u1 tag;
  u2 string_index;
  }
  
  6. CONSTANT_Integer
  CONSTANT_Integer_info {
  u1 tag;
  u4 bytes;
  }
  
  7. CONSTANT_Float
  CONSTANT_Float_info {
  u1 tag;
  u4 bytes;
  }
  
  8. CONSTANT_Long
  
  CONSTANT_Long_info {
  u1 tag;
  u4 high_bytes;
  u4 low_bytes;
  }
  
  9. CONSTANT_Double
  CONSTANT_Double_info {
  u1 tag;
  u4 high_bytes;
  u4 low_bytes
  }
  
  10.CONSTANT_NameAndType
  CONSTANT_NameAndType_info {
  u1 tag;
  u2 name_index;
  u2 descriptor_index;
  }
  
  11.CONSTANT_Utf8
  CONSTANT_Utf8_info {
  
  u1 tag;
  u2 length;
  u1 bytes[length];
  }
  
  access_flags意義如下:
  
  ACC_PUBLIC   0x0001
  ACC_FINAL   0x0010
  ACC_SUPER   0x0020
  ACC_INTERFACE 0x0200
  ACC_ABSTRACT  0x0400
  
  假如是interface那么必須置ACC_INTERFACE,假如沒有置ACC_INTERFACE則定義的是一
  個類而非接口。
  假如設置了ACC_INTERFACE,那么ACC_ABSTRACT位也必須被設置,當然也可以設置AC
  C_PUBLIC。
  ACC_SUPER用以表明invokespecial語義,Sun公司老的JAVA編譯器沒有設置ACC_SUPER
  ,并且老的JVM
  忽略ACC_SUPER位,但新的編譯器應該實現invokespecial語義。
  其他未指明的位保留將來使用,并且編譯器應當將其置為0,同時Java虛擬機應當忽
  略他們。
  
  this_class: constant_pool中的索引值,指向的元素的cp_info等價為CONSTANT_Class
  _info
  
  CONSTANT_Class_info {
  u1 tag;         //必須為CONSTANT_Class (7)
  u2 name_index;     //為指向constant_pool中的一個索引值
  }
  
  name_index :指向的元素的cp_info等價為CONSTANT_Utf8_info
  
  CONSTANT_Utf8_info {
  u1 tag;        //必須為CONSTANT_Utf8 (1)
  u2 length;
  u1 bytes[length];   //Utf8編碼的字符串
  }
  
  field_info {
  u2 access_flags;  //訪問控制權
  u2 name_index;   //constant_pool中的索引,對應于CONSTANT_Utf8_inf
  o描述。
  
  u2 descriptor_index; //constant_pool中的索引,對應于CONSTANT_Utf8_i
  nfo描述。
  u2 attributes_count;
  attribute_info attributes[attributes_count]; //attribute_info將在mo
  thods后描述。
  }
  field_info中access_flages意義如下:
  
  ACC_PUBLIC   0x0001
  ACC_PRIVATE  0x0002
  ACC_PROTECTED 0x0004
  ACC_STATIC   0x0008
  ACC_FINAL   0x0010
  ACC_VOLATILE  0x0040
  ACC_TRANSIENT 0x0080
  
  其中很顯然不能同時為ACC_FINAL和ACC_VOLATILE 且前三項是互斥的。
  interface必須置ACC_PUBLIC, ACC_STATIC,ACC_FINAL位,且不能置其他位。
  其他未指明的位保留將來使用,并且編譯器應當將其置為0,同時Java虛擬機應
  當忽略他們。
  
  methods指明了類中的所有方法。
  
  method_info {
  u2 access_flags;
  u2 name_index;  //指向constant_pool的入口,對應為CONSTANT_
  Utf8_info
  u2 descriptor_index; //指向constant_pool的入口,對應為CONS
  TANT_Utf8_info
  u2 attributes_count;
  attribute_info attributes[attributes_count];
  //此處只能出現Code、Exceptions、Synthetic、Deprecated四種類
  型的屬性
  }
  access_flags訪問權描述如下:
  ACC_PUBLIC    0x0001
  ACC_PRIVATE    0x0002
  ACC_PROTECTED   0x0004
  ACC_STATIC    0x0008
  ACC_FINAL     0x0010
  ACC_SYNCHRONIZED 0x0020
  ACC_NATIVE    0x0100
  ACC_ABSTRACT   0x0400
  
  ACC_STRICT    0x0800
  
  attribute_info {
  u2 attribute_name_index; //constant_pool中的索引,對應于CONSTANT_U
  tf8_info描述。
  u4 attribute_length;
  u1 info[attribute_length];
  }
  
  現在已經預定義的屬性有:
  
  1. SourceFile : attribute_info被替代為:
  
  SourceFile_attribute {
  u2 attribute_name_index;
  u4 attribute_length;
  u2 sourcefile_index; //指向constant_pool中的一個CONSTANT_Ut
  f8_info 結構。
  }
  
  2. Constantvalue : attribute_info被替代為:
  
  Constantvalue_attribute {
  u2 attribute_name_index;
  u4 attribute_length;  //必須為2
  u2 constantvalue_index;
  }
  
  對于constantvalue_index意義如下:
  long               CONSTANT_Long
  float               CONSTANT_Float
  double              CONSTANT_Double
  int, short, char, byte, boolean  CONSTANT_Integer
  String              CONSTANT_String
  
  Constantvalue用于field_info 中,用于描述一個static常量,
  且此時field_info的access_flags應為ACC_STATIC
  
  3. Code : attribute_info被替代為:
  
  Code_attribute {
  u2 attribute_name_index;
  
  u4 attribute_length;
  u2 max_stack; //執行此函數時可用的棧的最大深度
  u2 max_locals; //執行此函數可用到的最大本地變量數目,包括參
  數。
  // 注重:一個long/double相當于2個變量數目.
  u4 code_length; //本函數用到的代碼長度。
  u1 code[code_length]; //實現本函數的真正字節碼
  u2 exception_table_length;
  {  u2 start_pc;
  u2 end_pc; //捕捉違例時執行代碼數組中的[start_pc, end_p
  c)部分
  u2 handler_pc; //現在還不大明白他是干嘛的!!
  u2 catch_type; //指向constant_pool的索引,對應CONSTANT
  _Class_info
  }exception_table[exception_table_length];
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 高雄县| 信阳市| 通辽市| 雷山县| 锡林郭勒盟| 永胜县| 金坛市| 河曲县| 綦江县| 忻州市| 深圳市| 新巴尔虎左旗| 华蓥市| 崇义县| 洪洞县| 曲阜市| 土默特右旗| 石城县| 厦门市| 满洲里市| 垫江县| 新安县| 治县。| 梁山县| 雅安市| 靖江市| 郯城县| 南投县| 和静县| 神农架林区| 九台市| 墨玉县| 德州市| 光泽县| 定南县| 盐池县| 乐昌市| 深泽县| 威宁| 泉州市| 阳江市|