Day346&347&348&349
高版本虚拟机,可以解释运行低版本字节码文件
[](()3、常量池:存放所有常量
Class 文件是 JVM 的基石,常量池是 Class 文件的基石
[](()①常量池计数器
常量池计数器与常量池表数量的关系相差1
;
当常量池计数器为 1 时,常量池表中没有常量项
16(十六进制)===>22(十进制) = = =>代表有 22-1 个常量项
[](()②常量池表
字面量和符号引用:↓
常量类型和结构:↓
在 class 字节码文件中所表示的是指向某索引的符号有引用,不代表真正的内存地址;
当被类加载器加载到内存中,所存放到运行时数据区中,此时的符号引用就编译成了真正指向真实内存地址的直接引用
[](()4、访问标识
[](()5、类索引、父类索引、接口索引集合
当前类叫什么、当前类的父类谁、当前类实现了几个接口
[](()6、字段表集合
平时我们说的类中的属性
[](()①字段计数器
[](()②字段表
字段(类成员变量)的描述符为:参数类型
[](()7、方法表集合
[](()①方法计数器
[](()②方法表
方法的描述符为:方法的入参列表、方法的返回值类型
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-szCFuePj-1628002213657)(C:/Users/PePe/AppData/Roaming/Typora/typora-user-images/image-20210803213729005.png)]](https://img-blog.csdnimg.cn 《一线大厂 Java 面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义》无偿开源 威信搜索公众号【编程进阶路】 /5f0da650dec4438ca04c588190795ca6.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzMjg0NDY5,size_16,color_FFFFFF,t_70)
[](()8、属性表集合
方法中可以有属性,字段中也可以有属性
[](()①属性计数器
[](()②属性表
[](()9、总结
[](()四、使用 javap 指令解析 Class 文件
[](()1、解析字节码的作用
[](()2、javac -g 操作
[](()3、javap 的用法
最全信息的写法:javap -v -p XXX.class
[](()4、使用举例
代码
public class JavapTest {
private int num;
boolean flag;
protected char gender;
public String info;
public static final int COUNTS = 1;
static {
String url = "www.atguigu.com";
}
{
info = "java";
}
public JavapTest() {
}
private JavapTest(boolean falg) {
this.flag = flag;
}
private void methodPrivate() {
}
int getNum(int i) {
return num + i;
}
protected char showGender() {
return gender;
}
public void showInfo() {
int i = 100;
System.out.println(info + i);
}
}
javap 字节码文件分析
javap -v -p JavapTest.class
Classfile /C:/Users/achang/Desktop/JavapTest.class // 字节码文件所属的路径
Last modified 2021-2-24; size 1393 bytes // 最后修改时间,字节码文件的大小
MD5 checksum 2c764244fa3a95bfb346c9e416a7a3f6 // MD5 散列值
Compiled from "JavapTest.java" // 源文件的名称
public class io.renren.JavapTest
minor version: 0 // 副版本
major version: 52 // 主版本
flags: ACC_PUBLIC, ACC_SUPER // 访问标识
//*************************** 常量池↓********************************
Constant pool:
#1 = Methodref #16.#48 // java/lang/Object."":()V
#2 = String #49 // java
#3 = Fieldref #15.#50 // io/renren/JavapTest.info:Ljava/lang/String;
#4 = Fieldref #15.#51 // io/renren/JavapTest.flag:Z
#5 = Fieldref #15.#52 // io/renren/JavapTest.num:I
#6 = Fieldref #15.#53 // io/renren/JavapTest.gender:C
#7 = Fieldref #54.#55 // java/lang/System.out:Ljava/io/PrintStream;
#8 = Class #56 // java/lang/StringBuilder
#9 = Methodref #8.#48 // java/lang/StringBuilder."":()V
#10 = Methodref #8.#57 // java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
#11 = Methodref #8.#58 // java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
#12 = Methodref #8.#59 // java/lang/StringBuilder.toString:()Ljava/lang/String;
#13 = Methodref #60.#61 // java/io/PrintStream.println:(Ljava/lang/String;)V
#14 = String #62 // www.atguigu.com
#15 = Class #63 // io/renren/JavapTest
#16 = Class #64 // java/lang/Object
#17 = Utf8 num
#18 = Utf8 I
#19 = Utf8 flag
#20 = Utf8 Z
#21 = Utf8 gender
#22 = Utf8 C
#23 = Utf8 info
#24 = Utf8 Ljava/lang/String;
#25 = Utf8 COUNTS
#26 = Utf8 ConstantValue
#27 = Integer 1
#28 = Utf8
#29 = Utf8 ()V
#30 = Utf8 Code
#31 = Utf8 LineNumberTable
#32 = Utf8 LocalVariableTable
#33 = Utf8 this
#34 = Utf8 Lio/renren/JavapTest;
#35 = Utf8 (Z)V
#36 = Utf8 falg
#37 = Utf8 MethodParameters
#38 = Utf8 methodPrivate
#39 = Utf8 getNum
#40 = Utf8 (I)I
#41 = Utf8 i
#42 = Utf8 showGender
#43 = Utf8 ()C
#44 = Utf8 showInfo
#45 = Utf8
#46 = Utf8 SourceFile
#47 = Utf8 JavapTest.java
#48 = NameAndType #28:#29 // "":()V
#49 = Utf8 java
#50 = NameAndType #23:#24 // info:Ljava/lang/String;
#51 = NameAndType #19:#20 // flag:Z
#52 = NameAndType #17:#18 // num:I
#53 = NameAndType #21:#22 // gender:C
#54 = Class #65 // java/lang/System
#55 = NameAndType #66:#67 // out:Ljava/io/PrintStream;
#56 = Utf8 java/lang/StringBuilder
#57 = NameAndType #68:#69 // append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
#58 = NameAndType #68:#70 // append:(I)Ljava/lang/StringBuilder;
#59 = NameAndType #71:#72 // toString:()Ljava/lang/String;
#60 = Class #73 // java/io/PrintStream
#61 = NameAndType #74:#75 // println:(Ljava/lang/String;)V
#62 = Utf8 www.atguigu.com
#63 = Utf8 io/renren/JavapTest
#64 = Utf8 java/lang/Object
#65 = Utf8 java/lang/System
#66 = Utf8 out
#67 = Utf8 Ljava/io/PrintStream;
#68 = Utf8 append
#69 = Utf8 (Ljava/lang/String;)Ljava/lang/StringBuilder;
#70 = Utf8 (I)Ljava/lang/StringBuilder;
#71 = Utf8 toString
#72 = Utf8 ()Ljava/lang/String;
#73 = Utf8 java/io/PrintStream
#74 = Utf8 println
#75 = Utf8 (Ljava/lang/String;)V
//字段表集合的信息↓********
{
private int num; // 字段名
descriptor: I // 字段描述符,字段类型
flags: ACC_PRIVATE // 字段的访问标识
boolean flag;
descriptor: Z
flags:
protected char gender;
descriptor: C
flags: ACC_PROTECTED
public java.lang.String info;
评论