异常将上下文初始化事件发送到类的侦听器实例_深入浅出JVM性能调优——JVM内存( 三 )


71}
72
73// 方法将抛出异常
74public int willThrowException() {
75int i = 0;
76try {
77int r = 10 / i;
78return r;
79} catch (Exception e) {
80System.out.println("catch exception");
81return i;
82} finally {
83System.out.println("finally handle");
84}
85}
86 }
87
88
89 /
90
91
92 package com.lyyzoo.jvm.test01;
93
94 public class Main {
95
96public static void main(String[] args) {
97System.out.println("FIELD_NAME: " + User.FIELD_NAME);
98
99User.staticPrintInfo();
100
101User user = new User();
102user.printInfo();
103}
104 }
三、类编译和Class 文件结构
*.java 文件被编译成 *.class 文件的过程,这个编译一般称为前端编译,主要使用 javac 来完成前端编译 。Java class文件是8位字节的二进制流,数据项按顺序存储在class文件中,相邻的项之间没有任何间隔,这样可以使class文件紧凑 。class 文件主要包含 版本信息、常量池、类型索引、字段表、方法表、属性表等信息 。
将 User 类编译成 class 文件后,再通过 javap 反编译 class 文件,可以看到一个 class 文件大体包含的结构:
1 说明:用“【】”标识的是手动添加的注释
2
3 Mechrevo@hello-world MINGW64 /e/repo-study/test-concurrent/target/classes/com/lyyzoo/jvm/test01
4 【javap -v 命令反编译 Class】
5 $ javap -v User.class
6 Classfile /E:/repo-study/test-concurrent/target/classes/com/lyyzoo/jvm/test01/User.class
7Last modified 2020-9-3; size 2389 bytes
8【魔数】
9MD5 checksum ec5a961c2a46926522bafddcb3204fb9
10Compiled from "User.java"
11 public class com.lyyzoo.jvm.test01.User extends com.lyyzoo.jvm.test01.Person implements java.io.Serializable
12【版本号】
13minor version: 0
14major version: 52
15flags: ACC_PUBLIC, ACC_SUPER
16 【常量池】
17 Constant pool:
18#1 = Methodref#29.#76// com/lyyzoo/jvm/test01/Person."":()V
19#2 = String#77// 兰博
20#3 = Fieldref#14.#78// com/lyyzoo/jvm/test01/User.name:Ljava/lang/String;
21#4 = Fieldref#14.#79// com/lyyzoo/jvm/test01/User.age:I
22#5 = Fieldref#80.#81// java/lang/System.out:Ljava/io/PrintStream;
23#6 = Class#82// java/lang/StringBuilder
24#7 = Methodref#6.#76// java/lang/StringBuilder."":()V
25#8 = String#83// name:
26#9 = Methodref#6.#84// java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
27#10 = String#85// , age:
28#11 = Methodref#6.#86// java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
29#12 = Methodref#6.#87// java/lang/StringBuilder.toString:()Ljava/lang/String;
30#13 = Methodref#88.#89// java/io/PrintStream.println:(Ljava/lang/String;)V
31#14 = Class#90// com/lyyzoo/jvm/test01/User
32#15 = String#91// FIELD_NAME:username, AGE_MAX:100
33#16 = Methodref#29.#92// com/lyyzoo/jvm/test01/Person.sayHello:(Ljava/lang/Object;)V
34#17 = String#93// User say hello:
35#18 = String#94// finally handle
36#19 = Class#95// java/lang/Exception
37#20 = String#96// catch exception
38#21 = Class#97// java/lang/String
39#22 = Methodref#14.#98// com/lyyzoo/jvm/test01/User.sayHello:(Ljava/lang/String;)V
40#23 = String#99// Rambo
41#24 = Fieldref#14.#100// com/lyyzoo/jvm/test01/User.staticName:Ljava/lang/String;
42#25 = Fieldref#14.#101// com/lyyzoo/jvm/test01/User.staticAge:I
43#26 = String#102// user static init
44#27 = String#103// staticName=
45#28 = String#104// staticAge=
46#29 = Class#105// com/lyyzoo/jvm/test01/Person
47#30 = Class#106// java/io/Serializable
48#31 = Utf8serialVersionUID