Jvm之用C#解析class文件

196 阅读2分钟

项目地址

github.com/lxw112190/J…

项目结构

image.png

一个简单的测试类

public class Test {

    Integer code = 123;
    String name = "lxw";

    void method1() {
        System.out.println("我是method1");
    }

    int method2(int i) {
        System.out.println("我是method2");
        return 1;
    }

    long method3(int i,Class test) {
        System.out.println("我是method3");
        return 1;
    }

    String method4(int i,long l,String s) {
        System.out.println("我是method4");
        return "lxw";
    }

    void method5(int[] i,byte[] b) {
        System.out.println("我是method5");
    }


    public static void main(String[] args) {

        System.out.println("我是main");
    }
}

效果

image.png

详细信息

ConstantPool:79
#14 class        Test
#15 class        java/lang/Object
#16 UTF-8        code
#17 UTF-8        Ljava/lang/Integer;
#18 UTF-8        name
#19 UTF-8        Ljava/lang/String;
#20 UTF-8        <init>
#21 UTF-8        ()V
#22 UTF-8        Code
#23 UTF-8        LineNumberTable
#24 UTF-8        LocalVariableTable
#25 UTF-8        this
#26 UTF-8        LTest;
#27 UTF-8        method1
#28 UTF-8        method2
#29 UTF-8        (I)I
#30 UTF-8        i
#31 UTF-8        I
#32 UTF-8        method3
#33 UTF-8        (ILjava/lang/Class;)J
#34 UTF-8        test
#35 UTF-8        Ljava/lang/Class;
#36 UTF-8        method4
#37 UTF-8        (IJLjava/lang/String;)Ljava/lang/String;
#38 UTF-8        l
#39 UTF-8        J
#40 UTF-8        s
#41 UTF-8        method5
#42 UTF-8        ([I[B)V
#43 UTF-8        [I
#44 UTF-8        b
#45 UTF-8        [B
#46 UTF-8        main
#47 UTF-8        ([Ljava/lang/String;)V
#48 UTF-8        args
#49 UTF-8        [Ljava/lang/String;
#50 UTF-8        SourceFile
#51 UTF-8        Test.java
#52 NameAndType        <init>
#53 class        java/lang/Integer
#54 NameAndType        valueOf
#55 NameAndType        code
#56 UTF-8        lxw
#57 NameAndType        name
#58 class        java/lang/System
#59 NameAndType        out
#60 UTF-8        我是method1
#61 class        java/io/PrintStream
#62 NameAndType        println
#63 UTF-8        我是method2
#64 UTF-8        我是method3
#65 UTF-8        我是method4
#66 UTF-8        我是method5
#67 UTF-8        我是main
#68 UTF-8        Test
#69 UTF-8        java/lang/Object
#70 UTF-8        java/lang/Integer
#71 UTF-8        valueOf
#72 UTF-8        (I)Ljava/lang/Integer;
#73 UTF-8        java/lang/System
#74 UTF-8        out
#75 UTF-8        Ljava/io/PrintStream;
#76 UTF-8        java/io/PrintStream
#77 UTF-8        println
#78 UTF-8        (Ljava/lang/String;)V


classname:Test
superclass:java/lang/Object

field:code, desc:Ljava/lang/Integer;
field:name, desc:Ljava/lang/String;

method:<init>(), desc:()V
aload_0
invokespecial
nop
aconst_null
aload_0
bipush
lshr
invokestatic
nop
iconst_m1
putfield
nop
iconst_0
aload_0
ldc
iconst_1
putfield
nop
iconst_2
return

method:method1(), desc:()V
getstatic
nop
iconst_3
ldc
iconst_4
invokevirtual
nop
iconst_5
return

method:method2(), desc:(I)I
getstatic
nop
iconst_3
ldc
lconst_0
invokevirtual
nop
iconst_5
iconst_1
ireturn

method:method3(), desc:(ILjava/lang/Class;)J
getstatic
nop
iconst_3
ldc
lconst_1
invokevirtual
nop
iconst_5
lconst_1
lreturn

method:method4(), desc:(IJLjava/lang/String;)Ljava/lang/String;
getstatic
nop
iconst_3
ldc
fconst_0
invokevirtual
nop
iconst_5
ldc
iconst_1
areturn

method:method5(), desc:([I[B)V
getstatic
nop
iconst_3
ldc
fconst_1
invokevirtual
nop
iconst_5
return

method:main(), desc:([Ljava/lang/String;)V
getstatic
nop
iconst_3
ldc
fconst_2
invokevirtual
nop
iconst_5
return