新建一个Java类
package com.learn.jvm; public class MyTest1 { private int a = 1; public MyTest1() { } public int getA() { return this.a; } public void setA(int a) { this.a = a; } }
在控制台使用javap -c进行反解析
D:\workspace-learn\common-learn\learn-classloader\target\classes\com\learn\jvm>javap -c MyTest1 警告: 二进制文件MyTest1包含com.learn.jvm.MyTest1 Compiled from "MyTest1.java" public class com.learn.jvm.MyTest1 { public com.learn.jvm.MyTest1(); Code: 0: aload_0 1: invokespecial #1 // Method java/lang/Object."<init>":()V 4: aload_0 5: iconst_1 6: putfield #2 // Field a:I 9: return public int getA(); Code: 0: aload_0 1: getfield #2 // Field a:I 4: ireturn public void setA(int); Code: 0: aload_0 1: iload_1 2: putfield #2 // Field a:I 5: return }
在控制台使用javap -verbose进行反解析
D:\workspace-learn\common-learn\learn-classloader\target\classes\com\learn\jvm>javap -verbose MyTest1 警告: 二进制文件MyTest1包含com.learn.jvm.MyTest1 Classfile /D:/workspace-learn/common-learn/learn-classloader/target/classes/com/learn/jvm/MyTest1.class Last modified 2019-9-4; size 473 bytes MD5 checksum 8dc78fb3801af3d26bc3befec9b7c5ed Compiled from "MyTest1.java" public class com.learn.jvm.MyTest1 SourceFile: "MyTest1.java" minor version: 0 major version: 51 flags: ACC_PUBLIC, ACC_SUPER Constant pool: #1 = Methodref #4.#20 // java/lang/Object."<init>":()V #2 = Fieldref #3.#21 // com/learn/jvm/MyTest1.a:I #3 = Class #22 // com/learn/jvm/MyTest1 #4 = Class #23 // java/lang/Object #5 = Utf8 a #6 = Utf8 I #7 = Utf8 <init> #8 = Utf8 ()V #9 = Utf8 Code #10 = Utf8 LineNumberTable #11 = Utf8 LocalVariableTable #12 = Utf8 this #13 = Utf8 Lcom/learn/jvm/MyTest1; #14 = Utf8 getA #15 = Utf8 ()I #16 = Utf8 setA #17 = Utf8 (I)V #18 = Utf8 SourceFile #19 = Utf8 MyTest1.java #20 = NameAndType #7:#8 // "<init>":()V #21 = NameAndType #5:#6 // a:I #22 = Utf8 com/learn/jvm/MyTest1 #23 = Utf8 java/lang/Object { public com.learn.jvm.MyTest1(); flags: ACC_PUBLIC Code: stack=2, locals=1, args_size=1 0: aload_0 1: invokespecial #1 // Method java/lang/Object."<init>":()V 4: aload_0 5: iconst_1 6: putfield #2 // Field a:I 9: return LineNumberTable: line 8: 0 line 9: 4 LocalVariableTable: Start Length Slot Name Signature 0 10 0 this Lcom/learn/jvm/MyTest1; public int getA(); flags: ACC_PUBLIC Code: stack=1, locals=1, args_size=1 0: aload_0 1: getfield #2 // Field a:I 4: ireturn LineNumberTable: line 12: 0 LocalVariableTable: Start Length Slot Name Signature 0 5 0 this Lcom/learn/jvm/MyTest1; public void setA(int); flags: ACC_PUBLIC Code: stack=2, locals=2, args_size=2 0: aload_0 1: iload_1 2: putfield #2 // Field a:I 5: return LineNumberTable: line 16: 0 line 17: 5 LocalVariableTable: Start Length Slot Name Signature 0 6 0 this Lcom/learn/jvm/MyTest1; 0 6 1 a I }