0%

javap命令

javap命令

1
2
#javap的语法
javap [选项] class文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#javap 的命令选项
-version 版本信息
-v -verbose 输出附加信息,不包括私有信息,可以与-p结合,查看最全的信息
-l 输出行号和局部变量表
-public 仅显示公共类和成员
-protected 显示受保护的/公共类和成员
-package 显示程序包/受保护的/公共类
和成员 (默认)
-p -private 显示所有类和成员
-c 对代码进行反汇编
-s 输出内部类型签名
-sysinfo 显示正在处理的类的系统信息 (路径, 大小, 日期, MD5 散列)
-constants 显示最终常量
-classpath <path> 指定查找用户类文件的位置
-cp <path> 指定查找用户类文件的位置
-bootclasspath <path> 覆盖引导类文件的位置

我就随便找一个class文件来进行演示一下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public class TestString {
public static void main(String[] args) {
// String ss = "zxc";
String s = new String("zxc");
System.out.println(2 << 3);

String s1 = "aa";
String s2 = "bb";
String s3 = "aabb";
String s4 = s1+s2;
String s5 = "aa"+"bb";
String s6 = s4.intern();
System.out.println(s3 == s4);// false
System.out.println(s3 == s5);// true
System.out.println(s3 == s6);// true
System.out.println(s4 == s5);// false
System.out.println(s4 == s6);// false
System.out.println(s5 == s6);// true

}
}

使用命令javap -v TestString.class

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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
  Last modified 2022-1-9; size 1454 bytes
MD5 checksum 618e1797fdaef66f8ebe9aab023dedc6
Compiled from "TestString.java"
public class com.zhanghe.study.string.TestString
minor version: 0
major version: 52
flags: ACC_PUBLIC, ACC_SUPER
Constant pool: #常量池
#1 = Methodref #17.#43 // java/lang/Object."<init>":()V
#2 = Class #44 // java/lang/String
#3 = String #45 // zxc
#4 = Methodref #2.#46 // java/lang/String."<init>":(Ljava/lang/String;)V
#5 = Fieldref #47.#48 // java/lang/System.out:Ljava/io/PrintStream;
#6 = Methodref #49.#50 // java/io/PrintStream.println:(I)V
#7 = String #51 // aa
#8 = String #52 // bb
#9 = String #53 // aabb
#10 = Class #54 // java/lang/StringBuilder
#11 = Methodref #10.#43 // java/lang/StringBuilder."<init>":()V
#12 = Methodref #10.#55 // java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
#13 = Methodref #10.#56 // java/lang/StringBuilder.toString:()Ljava/lang/String;
#14 = Methodref #2.#57 // java/lang/String.intern:()Ljava/lang/String;
#15 = Methodref #49.#58 // java/io/PrintStream.println:(Z)V
#16 = Class #59 // com/zhanghe/study/string/TestString
#17 = Class #60 // java/lang/Object
#18 = Utf8 <init>
#19 = Utf8 ()V
#20 = Utf8 Code
#21 = Utf8 LineNumberTable
#22 = Utf8 LocalVariableTable
#23 = Utf8 this
#24 = Utf8 Lcom/zhanghe/study/string/TestString;
#25 = Utf8 main
#26 = Utf8 ([Ljava/lang/String;)V
#27 = Utf8 args
#28 = Utf8 [Ljava/lang/String;
#29 = Utf8 s
#30 = Utf8 Ljava/lang/String;
#31 = Utf8 s1
#32 = Utf8 s2
#33 = Utf8 s3
#34 = Utf8 s4
#35 = Utf8 s5
#36 = Utf8 s6
#37 = Utf8 StackMapTable
#38 = Class #28 // "[Ljava/lang/String;"
#39 = Class #44 // java/lang/String
#40 = Class #61 // java/io/PrintStream
#41 = Utf8 SourceFile
#42 = Utf8 TestString.java
#43 = NameAndType #18:#19 // "<init>":()V
#44 = Utf8 java/lang/String
#45 = Utf8 zxc
#46 = NameAndType #18:#62 // "<init>":(Ljava/lang/String;)V
#47 = Class #63 // java/lang/System
#48 = NameAndType #64:#65 // out:Ljava/io/PrintStream;
#49 = Class #61 // java/io/PrintStream
#50 = NameAndType #66:#67 // println:(I)V
#51 = Utf8 aa
#52 = Utf8 bb
#53 = Utf8 aabb
#54 = Utf8 java/lang/StringBuilder
#55 = NameAndType #68:#69 // append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
#56 = NameAndType #70:#71 // toString:()Ljava/lang/String;
#57 = NameAndType #72:#71 // intern:()Ljava/lang/String;
#58 = NameAndType #66:#73 // println:(Z)V
#59 = Utf8 com/zhanghe/study/string/TestString
#60 = Utf8 java/lang/Object
#61 = Utf8 java/io/PrintStream
#62 = Utf8 (Ljava/lang/String;)V
#63 = Utf8 java/lang/System
#64 = Utf8 out
#65 = Utf8 Ljava/io/PrintStream;
#66 = Utf8 println
#67 = Utf8 (I)V
#68 = Utf8 append
#69 = Utf8 (Ljava/lang/String;)Ljava/lang/StringBuilder;
#70 = Utf8 toString
#71 = Utf8 ()Ljava/lang/String;
#72 = Utf8 intern
#73 = Utf8 (Z)V
{
public com.zhanghe.study.string.TestString();
descriptor: ()V
flags: ACC_PUBLIC
Code:
stack=1, locals=1, args_size=1
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return
LineNumberTable:
line 7: 0
LocalVariableTable:
Start Length Slot Name Signature
0 5 0 this Lcom/zhanghe/study/string/TestString;

public static void main(java.lang.String[]);
descriptor: ([Ljava/lang/String;)V
flags: ACC_PUBLIC, ACC_STATIC
Code:
stack=3, locals=8, args_size=1
0: new #2 // class java/lang/String
3: dup
4: ldc #3 // String zxc
6: invokespecial #4 // Method java/lang/String."<init>":(Ljava/lang/String;)V
9: astore_1
10: getstatic #5 // Field java/lang/System.out:Ljava/io/PrintStream;
13: bipush 16
15: invokevirtual #6 // Method java/io/PrintStream.println:(I)V
18: ldc #7 // String aa
20: astore_2
21: ldc #8 // String bb
23: astore_3
24: ldc #9 // String aabb
26: astore 4
28: new #10 // class java/lang/StringBuilder
31: dup
32: invokespecial #11 // Method java/lang/StringBuilder."<init>":()V
35: aload_2
36: invokevirtual #12 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
39: aload_3
40: invokevirtual #12 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
43: invokevirtual #13 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
46: astore 5
48: ldc #9 // String aabb
50: astore 6
52: aload 5
54: invokevirtual #14 // Method java/lang/String.intern:()Ljava/lang/String;
57: astore 7
59: getstatic #5 // Field java/lang/System.out:Ljava/io/PrintStream;
62: aload 4
64: aload 5
66: if_acmpne 73
69: iconst_1
70: goto 74
73: iconst_0
74: invokevirtual #15 // Method java/io/PrintStream.println:(Z)V
77: getstatic #5 // Field java/lang/System.out:Ljava/io/PrintStream;
80: aload 4
82: aload 6
84: if_acmpne 91
87: iconst_1
88: goto 92
91: iconst_0
92: invokevirtual #15 // Method java/io/PrintStream.println:(Z)V
95: getstatic #5 // Field java/lang/System.out:Ljava/io/PrintStream;
98: aload 4
100: aload 7
102: if_acmpne 109
105: iconst_1
106: goto 110
109: iconst_0
110: invokevirtual #15 // Method java/io/PrintStream.println:(Z)V
113: getstatic #5 // Field java/lang/System.out:Ljava/io/PrintStream;
116: aload 5
118: aload 6
120: if_acmpne 127
123: iconst_1
124: goto 128
127: iconst_0
128: invokevirtual #15 // Method java/io/PrintStream.println:(Z)V
131: getstatic #5 // Field java/lang/System.out:Ljava/io/PrintStream;
134: aload 5
136: aload 7
138: if_acmpne 145
141: iconst_1
142: goto 146
145: iconst_0
146: invokevirtual #15 // Method java/io/PrintStream.println:(Z)V
149: getstatic #5 // Field java/lang/System.out:Ljava/io/PrintStream;
152: aload 6
154: aload 7
156: if_acmpne 163
159: iconst_1
160: goto 164
163: iconst_0
164: invokevirtual #15 // Method java/io/PrintStream.println:(Z)V
167: return
LineNumberTable:
line 10: 0
line 11: 10
line 13: 18
line 14: 21
line 15: 24
line 16: 28
line 17: 48
line 18: 52
line 19: 59
line 20: 77
line 21: 95
line 22: 113
line 23: 131
line 24: 149
line 26: 167
LocalVariableTable:
Start Length Slot Name Signature
0 168 0 args [Ljava/lang/String;
10 158 1 s Ljava/lang/String;
21 147 2 s1 Ljava/lang/String;
24 144 3 s2 Ljava/lang/String;
28 140 4 s3 Ljava/lang/String;
48 120 5 s4 Ljava/lang/String;
52 116 6 s5 Ljava/lang/String;
59 109 7 s6 Ljava/lang/String;
StackMapTable: number_of_entries = 12
frame_type = 255 /* full_frame */
offset_delta = 73
locals = [ class "[Ljava/lang/String;", class java/lang/String, class java/lang/String, class java/lang/String, class java/lang/String, class java/lang/String, class java/lang/String, class java/lang/String ]
stack = [ class java/io/PrintStream ]
frame_type = 255 /* full_frame */
offset_delta = 0
locals = [ class "[Ljava/lang/String;", class java/lang/String, class java/lang/String, class java/lang/String, class java/lang/String, class java/lang/String, class java/lang/String, class java/lang/String ]
stack = [ class java/io/PrintStream, int ]
frame_type = 80 /* same_locals_1_stack_item */
stack = [ class java/io/PrintStream ]
frame_type = 255 /* full_frame */
offset_delta = 0
locals = [ class "[Ljava/lang/String;", class java/lang/String, class java/lang/String, class java/lang/String, class java/lang/String, class java/lang/String, class java/lang/String, class java/lang/String ]
stack = [ class java/io/PrintStream, int ]
frame_type = 80 /* same_locals_1_stack_item */
stack = [ class java/io/PrintStream ]
frame_type = 255 /* full_frame */
offset_delta = 0
locals = [ class "[Ljava/lang/String;", class java/lang/String, class java/lang/String, class java/lang/String, class java/lang/String, class java/lang/String, class java/lang/String, class java/lang/String ]
stack = [ class java/io/PrintStream, int ]
frame_type = 80 /* same_locals_1_stack_item */
stack = [ class java/io/PrintStream ]
frame_type = 255 /* full_frame */
offset_delta = 0
locals = [ class "[Ljava/lang/String;", class java/lang/String, class java/lang/String, class java/lang/String, class java/lang/String, class java/lang/String, class java/lang/String, class java/lang/String ]
stack = [ class java/io/PrintStream, int ]
frame_type = 80 /* same_locals_1_stack_item */
stack = [ class java/io/PrintStream ]
frame_type = 255 /* full_frame */
offset_delta = 0
locals = [ class "[Ljava/lang/String;", class java/lang/String, class java/lang/String, class java/lang/String, class java/lang/String, class java/lang/String, class java/lang/String, class java/lang/String ]
stack = [ class java/io/PrintStream, int ]
frame_type = 80 /* same_locals_1_stack_item */
stack = [ class java/io/PrintStream ]
frame_type = 255 /* full_frame */
offset_delta = 0
locals = [ class "[Ljava/lang/String;", class java/lang/String, class java/lang/String, class java/lang/String, class java/lang/String, class java/lang/String, class java/lang/String, class java/lang/String ]
stack = [ class java/io/PrintStream, int ]
}
SourceFile: "TestString.java"

欢迎关注我的其它发布渠道