从一个基本的类的反编译说起:
javap是一个能够将class文件反汇编成人类可读的格式的工具。可以方便的查阅Java的字节码。
例如下面的例子:
public class Coo{
private int tryBlock;
private int catchBlock;
private int finallyBlock;
private int methodExit;
public void test(){
try{
tryBlock = 0;
}catch(Exception e){
catchBlock = 1;
}finally{
finallyBlock = 2;
}
methodExit = 3;
}
}
使用以下两条命令:
javac Coo.java
javap -p -v Coo
得到:
Classfile /C:/Users/dell/Desktop/bob/Coo.class
Last modified ×××; size 540 bytes
MD5 checksum d94c55f366ae593c8bb83fceda66f50a
Compiled from "Coo.java"
public class Coo
minor version: 0
major version: 52
flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
#1 = Methodref #8.#24 // java/lang/Object."<init>":()V
#2 = Fieldref #7.#25 // Coo.tryBlock:I
#3 = Fieldref #7.#26 // Coo.finallyBlock:I
#4 = Class #27 // java/lang/Exception
#5 = Fieldref #7.#28 // Coo.catchBlock:I
#6 = Fieldref #7.#29 // Coo.methodExit:I
#7 = Class #30 // Coo
#8 = Class #31 // java/lang/Object
#9 = Utf8 tryBlock
#10 = Utf8 I
#11 = Utf8 catchBlock
#12 = Utf8 finallyBlock
#13 = Utf8 methodExit
#14 = Utf8 <init>
#15 = Utf8 ()V
#16 = Utf8 Code
#17 = Utf8 LineNumberTable
#18 = Utf8 test
#19 = Utf8 StackMapTable
#20 = Class #27 // java/lang/Exception
#21 = Class #32 // java/lang/Throwable
#22 = Utf8 SourceFile
#23 = Utf8 Coo.java
#24 = NameAndType #14:#15 // "<init>":()V
#25 = NameAndType #9:#10 // tryBlock:I
#26 = NameAndType #12:#10 // finallyBlock:I
#27 = Utf8 java/lang/Exception
#28 = NameAndType #11:#10 // catchBlock:I
#29 = NameAndType #13:#10 // methodExit:I
#30 = Utf8 Coo
#31 = Utf8 java/lang/Object
#32 = Utf8 java/lang/Throwable
{
private int tryBlock;
descriptor: I
flags: ACC_PRIVATE
private int catchBlock;
descriptor: I
flags: ACC_PRIVATE
private int finallyBlock;
descriptor: I
flags: ACC_PRIVATE
private int methodExit;
descriptor: I
flags: ACC_PRIVATE
public Coo();
descriptor: ()V
flags: ACC_PUBLIC
Code:
stack=1, locals=1, args_size=1
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init&g