博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java class文件信息
阅读量:2387 次
发布时间:2019-05-10

本文共 6878 字,大约阅读时间需要 22 分钟。

在谈论JVM-运行时数据区时,我们遇到了一个方法区,关于方法区的信息都来自于class,在JDK的工具中,有一个javap命令可以用来显示class文件的信息。

查看class文件内容的命令如下:

javap -v XXX.clsss 
1
1

在这里以TestClass.示例

/** *  */package com.hx;import com.hx.vo.BaseParam;/** * @author MichaelKoo *  *         2017-7-12 */public class TestClass extends BaseParam implements Runnable {
private String name; private static final int AGE = 18; public void run() { name = "MichaelKoo," + AGE; try { CsdnUtil.getContent(getClass()); } catch (Exception e) { e.printStackTrace(); } }}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

编译成TestClass.class之后,使用javap命令打开信息如下:

Classfile /I:/adt_eclipse_work/HuanXinTest/bin/com/hx/TestClass.class  Last modified 2017-7-12; size 785 bytes  MD5 checksum 92698cfe5ce5c5322fa75fe4c2a54b2e  Compiled from "TestClass.java"public class com.hx.TestClass extends com.hx.vo.BaseParam implements java.lang.Runnable  minor version: 0  major version: 51  flags: ACC_PUBLIC, ACC_SUPERConstant pool:   #1 = Class              #2             // com/hx/TestClass   #2 = Utf8               com/hx/TestClass   #3 = Class              #4             // com/hx/vo/BaseParam   #4 = Utf8               com/hx/vo/BaseParam   #5 = Class              #6             // java/lang/Runnable   #6 = Utf8               java/lang/Runnable   #7 = Utf8               name   #8 = Utf8               Ljava/lang/String;   #9 = Utf8               AGE  #10 = Utf8               I  #11 = Utf8               ConstantValue  #12 = Integer            18  #13 = Utf8               
#14 = Utf8 ()V #15 = Utf8 Code #16 = Methodref #3.#17 // com/hx/vo/BaseParam."
":()V #17 = NameAndType #13:#14 // "
":()V #18 = Utf8 LineNumberTable #19 = Utf8 LocalVariableTable #20 = Utf8 this #21 = Utf8 Lcom/hx/TestClass; #22 = Utf8 run #23 = String #24 // MichaelKoo,18 #24 = Utf8 MichaelKoo,18 #25 = Fieldref #1.#26 // com/hx/TestClass.name:Ljava/lang/String; #26 = NameAndType #7:#8 // name:Ljava/lang/String; #27 = Methodref #28.#30 // java/lang/Object.getClass:()Ljava/lang/Class; #28 = Class #29 // java/lang/Object #29 = Utf8 java/lang/Object #30 = NameAndType #31:#32 // getClass:()Ljava/lang/Class; #31 = Utf8 getClass #32 = Utf8 ()Ljava/lang/Class; #33 = Methodref #34.#36 // com/hx/CsdnUtil.getContent:(Ljava/lang/Class;)Ljava/lang/String; #34 = Class #35 // com/hx/CsdnUtil #35 = Utf8 com/hx/CsdnUtil #36 = NameAndType #37:#38 // getContent:(Ljava/lang/Class;)Ljava/lang/String; #37 = Utf8 getContent #38 = Utf8 (Ljava/lang/Class;)Ljava/lang/String; #39 = Methodref #40.#42 // java/lang/Exception.printStackTrace:()V #40 = Class #41 // java/lang/Exception #41 = Utf8 java/lang/Exception #42 = NameAndType #43:#14 // printStackTrace:()V #43 = Utf8 printStackTrace #44 = Utf8 e #45 = Utf8 Ljava/lang/Exception; #46 = Utf8 StackMapTable #47 = Utf8 SourceFile #48 = Utf8 TestClass.java{ public com.hx.TestClass(); descriptor: ()V flags: ACC_PUBLIC Code: stack=1, locals=1, args_size=1 0: aload_0 1: invokespecial #16 // Method com/hx/vo/BaseParam."
":()V 4: return LineNumberTable: line 13: 0 LocalVariableTable: Start Length Slot Name Signature 0 5 0 this Lcom/hx/TestClass; public void run(); descriptor: ()V flags: ACC_PUBLIC Code: stack=2, locals=2, args_size=1 0: aload_0 1: ldc #23 // String MichaelKoo,18 3: putfield #25 // Field name:Ljava/lang/String; 6: aload_0 7: invokevirtual #27 // Method java/lang/Object.getClass:()Ljava/lang/Class; 10: invokestatic #33 // Method com/hx/CsdnUtil.getContent:(Ljava/lang/Class;)Ljava/lang/String; 13: pop 14: goto 22 17: astore_1 18: aload_1 19: invokevirtual #39 // Method java/lang/Exception.printStackTrace:()V 22: return Exception table: from to target type 6 14 17 Class java/lang/Exception LineNumberTable: line 18: 0 line 21: 6 line 22: 14 line 23: 18 line 25: 22 LocalVariableTable: Start Length Slot Name Signature 0 23 0 this Lcom/hx/TestClass; 18 4 1 e Ljava/lang/Exception; StackMapTable: number_of_entries = 2 frame_type = 81 /* same_locals_1_stack_item */ stack = [ class java/lang/Exception ] frame_type = 4 /* same */}SourceFile: "TestClass.java"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110

其中有几个需要关注的节点: 
- 类的信息,在关键字’Constant pool:’之前就属于类的基本信息,从中可以看出,类的修饰符(public )、类的完整名称(com.hx.TestClass)、类的父类完整名称(com.hx.vo.BaseParam)、类的接口信息(java.lang.Runnable) 
- 常量池,在关键字’Constant pool:’之后,第一个’{‘之前的内容就属于常量池信息, 

- 在’{‘之后,’}’之前就是类的方法信息,从中可以看出:方法的修饰符、方法的返回值类型、方法名称、方法的异常表、方法的局部变量表等信息

转载地址:http://blog.csdn.net/android_app/article/details/75043072

你可能感兴趣的文章
INITTAB详解
查看>>
Black Hat USA 2011: Alexander Polyakov - CTO - ERPScan
查看>>
PHP端口复用的利用
查看>>
Hyperion 11 安装
查看>>
WEBSHELL新型玩法
查看>>
weblogic node maanger 远程命令执行漏洞
查看>>
信息与网络安全相关参考资料的下载
查看>>
Remote IIS 5.x and IIS 6.0 Server Name Spoof
查看>>
RACI 责任分配矩阵
查看>>
利用CSVDE和DSADD实现AD帐号批量导入导出
查看>>
oracle用户创建及权限设置
查看>>
vBulletin 4.X后台拿shell
查看>>
Windows Server 2008 R2之十全局编录服务器(GC)
查看>>
Exchange域名重写,实现SMTP地址共享
查看>>
我眼里的Exchange 2010 之:1—DAG
查看>>
IIS7备份还原
查看>>
exchange的边缘服务器备份
查看>>
The Domino security model
查看>>
系统管理:smartmontools
查看>>
smartmontools相关文档
查看>>