查看java class文件的字节码
需要用到Oolong工具,使用教程 https://tengqingshan.blog.csdn.net/article/details/115414875
Message.java 源代码文件
public class Message {
public static void main(String[] args) {
System.out.println("junshan say:Hello Word!");
}
}
对其编译成class文件后,执行
java COM.sootNsmoke.oolong.DumpClass Message.class
后输出:
E:\代码\java\深入分析java web技术内幕>java COM.sootNsmoke.oolong.DumpClass Message.class
000000 cafebabe magic = ca fe ba be
000004 0000 minor version = 0
000006 0034 major version = 52
000008 001d 29 constants
00000a 0a0006000f 1. Methodref class #6 name-and-type #15
00000f 0900100011 2. Fieldref class #16 name-and-type #17
000014 080012 3. String #18
000017 0a00130014 4. Methodref class #19 name-and-type #20
00001c 070015 5. Class name #21
00001f 070016 6. Class name #22
000022 010006 7. UTF length=6
000025 3c696e69743e <init>
00002b 010003 8. UTF length=3
00002e 282956 ()V
000031 010004 9. UTF length=4
000034 436f6465 Code
000038 01000f 10. UTF length=15
00003b 4c696e654e756d6265725461626c65 LineNumberTable
00004a 010004 11. UTF length=4
00004d 6d61696e main
000051 010016 12. UTF length=22
000054 285b4c6a6176612f6c616e672f537472 ([Ljava/lang/Str
000064 696e673b2956 ing;)V
00006a 01000a 13. UTF length=10
00006d 536f7572636546696c65 SourceFile
000077 01000c 14. UTF length=12
00007a 4d6573736167652e6a617661 Message.java
000086 0c00070008 15. NameAndType name #7 descriptor #8
00008b 070017 16. Class name #23
00008e 0c00180019 17. NameAndType name #24 descriptor #25
000093 010017 18. UTF length=23
000096 6a756e7368616e207361793a48656c6c junshan say:Hell
0000a6 6f20576f726421 o Word!
0000ad 07001a 19. Class name #26
0000b0 0c001b001c 20. NameAndType name #27 descriptor #28
0000b5 010007 21. UTF length=7
0000b8 4d657373616765 Message
0000bf 010010 22. UTF length=16
0000c2 6a6176612f6c616e672f4f626a656374 java/lang/Object
0000d2 010010 23. UTF length=16
0000d5 6a6176612f6c616e672f53797374656d java/lang/System
0000e5 010003 24. UTF length=3
0000e8 6f7574 out
0000eb 010015 25. UTF length=21
0000ee 4c6a6176612f696f2f5072696e745374 Ljava/io/PrintSt
0000fe 7265616d3b ream;
000103 010013 26. UTF length=19
000106 6a6176612f696f2f5072696e74537472 java/io/PrintStr
000116 65616d eam
000119 010007 27. UTF length=7
00011c 7072696e746c6e println
000123 010015 28. UTF length=21
000126 284c6a6176612f6c616e672f53747269 (Ljava/lang/Stri
000136 6e673b2956 ng;)V
00013b 0021 access_flags = 33
00013d 0005 this = #5
00013f 0006 super = #6
000141 0000 0 interfaces
000143 0000 0 fields
000145 0002 2 methods
Method 0:
000147 0001 access flags = 1
000149 0007 name = #7<<init>>
00014b 0008 descriptor = #8<()V>
00014d 0001 1 field/method attributes:
field/method attribute 0
00014f 0009 name = #9<Code>
000151 0000001d length = 29
000155 0001 max stack: 1
000157 0001 max locals: 1
000159 00000005 code length: 5
00015d 2a 0 aload_0
00015e b70001 1 invokespecial #1
000161 b1 4 return
000162 0000 0 exception table entries:
000164 0001 1 code attributes:
code attribute 0:
000166 000a name = #10<LineNumberTable>
000168 00000006 length = 6
Line number table:
00016c 0001 length = 1
00016e 00000001 start pc: 0 line number: 1
Method 1:
000172 0009 access flags = 9
000174 000b name = #11<main>
000176 000c descriptor = #12<([Ljava/lang/String;)V>
000178 0001 1 field/method attributes:
field/method attribute 0
00017a 0009 name = #9<Code>
00017c 00000025 length = 37
000180 0002 max stack: 2
000182 0001 max locals: 1
000184 00000009 code length: 9
000188 b20002 0 getstatic #2
00018b 1203 3 ldc #3
00018d b60004 5 invokevirtual #4
000190 b1 8 return
000191 0000 0 exception table entries:
000193 0001 1 code attributes:
code attribute 0:
000195 000a name = #10<LineNumberTable>
000197 0000000a length = 10
Line number table:
00019b 0002 length = 2
00019d 00000003 start pc: 0 line number: 3
0001a1 00080004 start pc: 8 line number: 4
0001a5 0001 1 classfile attributes
Attribute 0:
0001a7 000d name = #13<SourceFile>
0001a9 00000002 length = 2
0001ad 000e sourcefile index = #14
Done.