写在前面
最近闲暇时间在研究jvm虚拟机原理,所以把日常看到的、学习到的记录下来,这篇文章主要是讲基础的Class文件的查看和解析
会持续更新,接上文
实例
见注释
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
| Classfile /Users/code/test/out/production/test/javp/JapTest.class Last modified 2020-8-10; size 647 bytes MD5 checksum 262a5f3739e7114c4154dde1717c57d6 Compiled from "JapTest.java" public class javp.JapTest minor version: 0 major version: 52 flags: ACC_PUBLIC, ACC_SUPER Constant pool:
#1 = Methodref #6.#26 // java/lang/Object."<init>":()V #2 = String #27 // 2222 #3 = Fieldref #28.#29 // java/lang/System.out:Ljava/io/PrintStream; #4 = Methodref #30.#31 // java/io/PrintStream.println:(I)V #5 = Class #32 // javp/JapTest #6 = Class #33 // java/lang/Object #7 = Utf8 <init>
#8 = Utf8 ()V//init的方法签名,返会void,参数为空 #9 = Utf8 Code //CONSTANT_Utf8 #10 = Utf8 LineNumberTable// #11 = Utf8 LocalVariableTable// #12 = Utf8 this// #13 = Utf8 Ljavp/JapTest;// #14 = Utf8 main #15 = Utf8 ([Ljava/lang/String;)V #16 = Utf8 c #17 = Utf8 I #18 = Utf8 args #19 = Utf8 [Ljava/lang/String; #20 = Utf8 i #21 = Utf8 Ljava/lang/String; #22 = Utf8 StackMapTable #23 = Class #34 // java/lang/String #24 = Utf8 SourceFile #25 = Utf8 JapTest.java #26 = NameAndType #7:#8 // "<init>":()V #27 = Utf8 2222 #28 = Class #35 // java/lang/System #29 = NameAndType #36:#37 // out:Ljava/io/PrintStream; #30 = Class #38 // java/io/PrintStream #31 = NameAndType #39:#40 // println:(I)V #32 = Utf8 javp/JapTest #33 = Utf8 java/lang/Object #34 = Utf8 java/lang/String #35 = Utf8 java/lang/System #36 = Utf8 out #37 = Utf8 Ljava/io/PrintStream; #38 = Utf8 java/io/PrintStream #39 = Utf8 println #40 = Utf8 (I)V { public javp.JapTest(); 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 Ljavp/JapTest; 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 // String 2222 2: astore_1 3: iconst_1 4: istore_2 5: iload_2 6: bipush 20 8: if_icmpge 24 11: getstatic #3 // Field java/lang/System.out:Ljava/io/PrintStream; 14: iload_2 15: invokevirtual #4 // Method java/io/PrintStream.println:(I)V 18: iinc 2, 1 21: goto 5 24: return LineNumberTable: line 5: 0 line 6: 3 line 7: 11 line 6: 18 line 9: 24 LocalVariableTable: Start Length Slot Name Signature 5 19 2 c I 0 25 0 args [Ljava/lang/String; 3 22 1 i Ljava/lang/String; StackMapTable: number_of_entries = 2 frame_type = 253 offset_delta = 5 locals = [ class java/lang/String, int ] frame_type = 250 offset_delta = 18 } SourceFile: "JapTest.java"
|