关于 Java 字节码的请教
資深大佬 : lqw3030 21
- 例如,我有这么一份代码
package lock; public class ByteCodeTest { private volatile String name="view"; public void work(){ name+="hello"; } }
- 编译后,通过字节码工具查看
// class version 56.0 (56) // access flags 0x21 public class lock/ByteCodeTest { // compiled from: ByteCodeTest.java // access flags 0x19 public final static INNERCLASS java/lang/invoke/MethodHandles$Lookup java/lang/invoke/MethodHandles Lookup // access flags 0x42 private volatile Ljava/lang/String; name // access flags 0x1 public <init>()V L0 LINENUMBER 3 L0 ALOAD 0 INVOKESPECIAL java/lang/Object.<init> ()V L1 LINENUMBER 4 L1 ALOAD 0 LDC "view" PUTFIELD lock/ByteCodeTest.name : Ljava/lang/String; RETURN L2 LOCALVARIABLE this Llock/ByteCodeTest; L0 L2 0 MAXSTACK = 2 MAXLOCALS = 1 // access flags 0x1 public work()V L0 LINENUMBER 6 L0 ALOAD 0 DUP GETFIELD lock/ByteCodeTest.name : Ljava/lang/String; INVOKEDYNAMIC makeConcatWithConstants(Ljava/lang/String;)Ljava/lang/String; [ // handle kind 0x6 : INVOKESTATIC java/lang/invoke/StringConcatFactory.makeConcatWithConstants(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite; // arguments: "u0001hello" ] PUTFIELD lock/ByteCodeTest.name : Ljava/lang/String; L1 LINENUMBER 7 L1 RETURN L2 LOCALVARIABLE this Llock/ByteCodeTest; L0 L2 0 MAXSTACK = 2 MAXLOCALS = 1 }
- 想请教下如何阅读上述指令语法
- 或是 google 什么关键字可以搜到相关内容
大佬有話說 (11)