其实就是在idea的控制台输出java文件经过javac、javap后的内容。
工具相当于提前存储好命令,想用的时候,快捷执行并输出到idea控制台,很方便。
尤其是学习JVM相关知识的时候,会想看看代码在JVM的执行过程、常量池内容、本地变量表内容。
工具编辑过程:
idea快捷执行javap命令.png
工具使用:
idea快捷执行命令工具1.png
java文件
package jvm;
public class HelloWorld {
public static void main(String[] args) {
int a = 1;
}
}
idea执行编辑好的javac命令
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package jvm;
public class HelloWorld {
public HelloWorld() {
}
public static void main(String[] var0) {
byte var1 = 1;
byte var2 = 2;
int var10000 = var1 + var2;
}
}
idea执行编辑好的javap -c命令
"C:\Program Files\Java\jdk1.8.0_311\bin\javap.exe" -c jvm.HelloWorld
Compiled from "HelloWorld.java"
public class jvm.HelloWorld {
public jvm.HelloWorld();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]);
Code:
0: iconst_1
1: istore_1
2: return
}
Process finished with exit code 0
idea执行编辑好的javap -v命令
"C:\Program Files\Java\jdk1.8.0_311\bin\javap.exe" -v jvm.HelloWorld
Classfile /D:/studyCode/javaBaseCode/out/production/javaBaseCode/jvm/HelloWorld.class
Last modified 2022-3-18; size 405 bytes
MD5 checksum f7fa0af36d907e192fa0fa555acc7603
Compiled from "HelloWorld.java"
public class jvm.HelloWorld
minor version: 0
major version: 52
flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
#1 = Methodref #3.#19 // java/lang/Object."<init>":()V
#2 = Class #20 // jvm/HelloWorld
#3 = Class #21 // java/lang/Object
#4 = Utf8 <init>
#5 = Utf8 ()V
#6 = Utf8 Code
#7 = Utf8 LineNumberTable
#8 = Utf8 LocalVariableTable
#9 = Utf8 this
#10 = Utf8 Ljvm/HelloWorld;
#11 = Utf8 main
#12 = Utf8 ([Ljava/lang/String;)V
#13 = Utf8 args
#14 = Utf8 [Ljava/lang/String;
#15 = Utf8 a
#16 = Utf8 I
#17 = Utf8 SourceFile
#18 = Utf8 HelloWorld.java
#19 = NameAndType #4:#5 // "<init>":()V
#20 = Utf8 jvm/HelloWorld
#21 = Utf8 java/lang/Object
{
public jvm.HelloWorld();
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 3: 0
LocalVariableTable:
Start Length Slot Name Signature
0 5 0 this Ljvm/HelloWorld;
public static void main(java.lang.String[]);
descriptor: ([Ljava/lang/String;)V
flags: ACC_PUBLIC, ACC_STATIC
Code:
stack=1, locals=2, args_size=1
0: iconst_1
1: istore_1
2: return
LineNumberTable:
line 5: 0
line 6: 2
LocalVariableTable:
Start Length Slot Name Signature
0 3 0 args [Ljava/lang/String;
2 1 1 a I
}
SourceFile: "HelloWorld.java"
Process finished with exit code 0