javap命令主要用于反编译java的class文件,查看java编译器生成的字节码。
看一段java代码:
public class SynchronizedUse {
public static void main(String[] args) {
synchronized (SynchronizedUse.class){
}
display();
}
public static synchronized void display() {
System.out.println(1);
}
}
对编译后的class文件执行 javap -v SynchronizedUse.class>output.txt
:
Classfile /E:/ideaProjects2017/java/out/production/classes/com/gsonkeno/java/concurrent/SynchronizedUse.class
Last modified 2017-8-31; size 750 bytes
MD5 checksum f647c188b699918adeede598aff4d432
Compiled from "SynchronizedUse.java"
public class com.gsonkeno.java.concurrent.SynchronizedUse
minor version: 0
major version: 52
flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
#1 = Methodref #6.#25 // java/lang/Object."<init>":()V
#2 = Class #26 // com/gsonkeno/java/concurrent/SynchronizedUse
#3 = Methodref #2.#27 // com/gsonkeno/java/concurrent/SynchronizedUse.display:()V
#4 = Fieldref #28.#29 // java/lang/System.out:Ljava/io/PrintStream;
#5 = Methodref #30.#31 // java/io/PrintStream.println:(I)V
#6 = Class #32 // java/lang/Object
#7 = Utf8 <init>
#8 = Utf8 ()V
#9 = Utf8 Code
#10 = Utf8 LineNumberTable
#11 = Utf8 LocalVariableTable
#12 = Utf8 this
#13 = Utf8 Lcom/gsonkeno/java/concurrent/SynchronizedUse;
#14 = Utf8 main
#15 = Utf8 ([Ljava/lang/String;)V
#16 = Utf8 args
#17 = Utf8 [Ljava/lang/String;
#18 = Utf8 StackMapTable
#19 = Class #17 // "[Ljava/lang/String;"
#20 = Class #32 // java/lang/Object
#21 = Class #33 // java/lang/Throwable
#22 = Utf8 display
#23 = Utf8 SourceFile
#24 = Utf8 SynchronizedUse.java
#25 = NameAndType #7:#8 // "<init>":()V
#26 = Utf8 com/gsonkeno/java/concurrent/SynchronizedUse
#27 = NameAndType #22:#8 // display:()V
#28 = Class #34 // java/lang/System
#29 = NameAndType #35:#36 // out:Ljava/io/PrintStream;
#30 = Class #37 // java/io/PrintStream
#31 = NameAndType #38:#39 // println:(I)V
#32 = Utf8 java/lang/Object
#33 = Utf8 java/lang/Throwable
#34 = Utf8 java/lang/System
#35 = Utf8 out
#36 = Utf8 Ljava/io/PrintStream;
#37 = Utf8 java/io/PrintStream
#38 = Utf8 println
#39 = Utf8 (I)V
{
public com.gsonkeno.java.concurrent.SynchronizedUse();
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 6: 0
LocalVariableTable:
Start Length Slot Name Signature
0 5 0 this Lcom/gsonkeno/java/concurrent/SynchronizedUse;
public static void main(java.lang.String[]);
descriptor: ([Ljava/lang/String;)V
flags: ACC_PUBLIC, ACC_STATIC
Code:
stack=2, locals=3, args_size=1
0: ldc #2 // class com/gsonkeno/java/concurrent/SynchronizedUse
2: dup
3: astore_1
4: monitorenter
5: aload_1
6: monitorexit
7: goto 15
10: astore_2
11: aload_1
12: monitorexit
13: aload_2
14: athrow
15: invokestatic #3 // Method display:()V
18: return
Exception table:
from to target type
5 7 10 any
10 13 10 any
LineNumberTable:
line 8: 0
line 10: 5
line 12: 15
line 13: 18
LocalVariableTable:
Start Length Slot Name Signature
0 19 0 args [Ljava/lang/String;
StackMapTable: number_of_entries = 2
frame_type = 255 /* full_frame */
offset_delta = 10
locals = [ class "[Ljava/lang/String;", class java/lang/Object ]
stack = [ class java/lang/Throwable ]
frame_type = 250 /* chop */
offset_delta = 4
public static synchronized void display();
descriptor: ()V
flags: ACC_PUBLIC, ACC_STATIC, ACC_SYNCHRONIZED
Code:
stack=2, locals=0, args_size=0
0: getstatic #4 // Field java/lang/System.out:Ljava/io/PrintStream;
3: iconst_1
4: invokevirtual #5 // Method java/io/PrintStream.println:(I)V
7: return
LineNumberTable:
line 16: 0
line 17: 7
}
SourceFile: "SynchronizedUse.java"
网友评论