• 查询java类编译后的执行指令


    编译前CLASS信息:

    public class LockExample {
    
        private static int i;
        private static int j;
        private static int k;
    
        private static volatile int state;
    
        public static void main(String[] args) {
            LockExample lockExample = new LockExample();
            lockExample.innerSynch();
    
        }
    
        public LockExample(){
            i = 2;
            state = 1;
        }
    
        public  void innerSynch(){
            synchronized(this){
                System.out.println("[ get inner lock ] success");
                i++;
                j++;
                state ++;
                k++;
                try {
                    this.wait();
                }catch (InterruptedException ex){
    
                }
                notifyAll();
                System.out.println("[ notifyAll ] ... ...");
            }
    
        }
    
    
    }
    LockExample 源码

    通过IDEA 编译源码获得 LockExample.class文件

    即执行:C:UsersAdministratorDesktop> javac  LockExample.java

    然后,基于Class文件,再执行如下指令:

    # 指令格式:javap -v -p  Class文件名字,不需要加.class
    C:UsersAdministratorDesktop>javap -v -p LockExample 

    控制台就会打印出该类的JVM指令:

      1 com.clouds.example.service.lock.LockExample
      2 Classfile /C:/Users/Administrator/Desktop/LockExample.class
      3   Last modified 2020-8-31; size 995 bytes
      4   MD5 checksum 60688e87f173f11c4571151844f8d0bf
      5   Compiled from "LockExample.java"
      6 public class com.clouds.example.service.lock.LockExample
      7   minor version: 0
      8   major version: 52
      9   flags: ACC_PUBLIC, ACC_SUPER
     10 Constant pool:
     11    #1 = Class              #36            // com/clouds/example/service/lock/LockExample
     12    #2 = Methodref          #1.#37         // com/clouds/example/service/lock/LockExample."<init>":()V
     13    #3 = Methodref          #1.#38         // com/clouds/example/service/lock/LockExample.innerSynch:()V
     14    #4 = Methodref          #16.#37        // java/lang/Object."<init>":()V
     15    #5 = Fieldref           #1.#39         // com/clouds/example/service/lock/LockExample.i:I
     16    #6 = Fieldref           #1.#40         // com/clouds/example/service/lock/LockExample.state:I
     17    #7 = Fieldref           #41.#42        // java/lang/System.out:Ljava/io/PrintStream;
     18    #8 = String             #43            // [ get inner lock ] success
     19    #9 = Methodref          #44.#45        // java/io/PrintStream.println:(Ljava/lang/String;)V
     20   #10 = Fieldref           #1.#46         // com/clouds/example/service/lock/LockExample.j:I
     21   #11 = Fieldref           #1.#47         // com/clouds/example/service/lock/LockExample.k:I
     22   #12 = Methodref          #16.#48        // java/lang/Object.wait:()V
     23   #13 = Class              #49            // java/lang/InterruptedException
     24   #14 = Methodref          #16.#50        // java/lang/Object.notifyAll:()V
     25   #15 = String             #51            // [ notifyAll ] ... ...
     26   #16 = Class              #52            // java/lang/Object
     27   #17 = Utf8               i
     28   #18 = Utf8               I
     29   #19 = Utf8               j
     30   #20 = Utf8               k
     31   #21 = Utf8               state
     32   #22 = Utf8               main
     33   #23 = Utf8               ([Ljava/lang/String;)V
     34   #24 = Utf8               Code
     35   #25 = Utf8               LineNumberTable
     36   #26 = Utf8               <init>
     37   #27 = Utf8               ()V
     38   #28 = Utf8               innerSynch
     39   #29 = Utf8               StackMapTable
     40   #30 = Class              #36            // com/clouds/example/service/lock/LockExample
     41   #31 = Class              #52            // java/lang/Object
     42   #32 = Class              #49            // java/lang/InterruptedException
     43   #33 = Class              #53            // java/lang/Throwable
     44   #34 = Utf8               SourceFile
     45   #35 = Utf8               LockExample.java
     46   #36 = Utf8               com/clouds/example/service/lock/LockExample
     47   #37 = NameAndType        #26:#27        // "<init>":()V
     48   #38 = NameAndType        #28:#27        // innerSynch:()V
     49   #39 = NameAndType        #17:#18        // i:I
     50   #40 = NameAndType        #21:#18        // state:I
     51   #41 = Class              #54            // java/lang/System
     52   #42 = NameAndType        #55:#56        // out:Ljava/io/PrintStream;
     53   #43 = Utf8               [ get inner lock ] success
     54   #44 = Class              #57            // java/io/PrintStream
     55   #45 = NameAndType        #58:#59        // println:(Ljava/lang/String;)V
     56   #46 = NameAndType        #19:#18        // j:I
     57   #47 = NameAndType        #20:#18        // k:I
     58   #48 = NameAndType        #60:#27        // wait:()V
     59   #49 = Utf8               java/lang/InterruptedException
     60   #50 = NameAndType        #61:#27        // notifyAll:()V
     61   #51 = Utf8               [ notifyAll ] ... ...
     62   #52 = Utf8               java/lang/Object
     63   #53 = Utf8               java/lang/Throwable
     64   #54 = Utf8               java/lang/System
     65   #55 = Utf8               out
     66   #56 = Utf8               Ljava/io/PrintStream;
     67   #57 = Utf8               java/io/PrintStream
     68   #58 = Utf8               println
     69   #59 = Utf8               (Ljava/lang/String;)V
     70   #60 = Utf8               wait
     71   #61 = Utf8               notifyAll
     72 {
     73   private static int i;
     74     descriptor: I
     75     flags: ACC_PRIVATE, ACC_STATIC
     76 
     77   private static int j;
     78     descriptor: I
     79     flags: ACC_PRIVATE, ACC_STATIC
     80 
     81   private static int k;
     82     descriptor: I
     83     flags: ACC_PRIVATE, ACC_STATIC
     84 
     85   private static volatile int state;
     86     descriptor: I
     87     flags: ACC_PRIVATE, ACC_STATIC, ACC_VOLATILE
     88 
     89   public static void main(java.lang.String[]);
     90     descriptor: ([Ljava/lang/String;)V
     91     flags: ACC_PUBLIC, ACC_STATIC
     92     Code:
     93       stack=2, locals=2, args_size=1
     94          0: new           #1                  // class com/clouds/example/service/lock/LockExample
     95          3: dup
     96          4: invokespecial #2                  // Method "<init>":()V
     97          7: astore_1
     98          8: aload_1
     99          9: invokevirtual #3                  // Method innerSynch:()V
    100         12: return
    101       LineNumberTable:
    102         line 12: 0
    103         line 13: 8
    104         line 15: 12
    105 
    106   public com.clouds.example.service.lock.LockExample();
    107     descriptor: ()V
    108     flags: ACC_PUBLIC
    109     Code:
    110       stack=1, locals=1, args_size=1
    111          0: aload_0
    112          1: invokespecial #4                  // Method java/lang/Object."<init>":()V
    113          4: iconst_2
    114          5: putstatic     #5                  // Field i:I
    115          8: iconst_1
    116          9: putstatic     #6                  // Field state:I
    117         12: return
    118       LineNumberTable:
    119         line 17: 0
    120         line 18: 4
    121         line 19: 8
    122         line 20: 12
    123 
    124   public void innerSynch();
    125     descriptor: ()V
    126     flags: ACC_PUBLIC
    127     Code:
    128       stack=2, locals=4, args_size=1
    129          0: aload_0
    130          1: dup
    131          2: astore_1
    132          3: monitorenter
    133          4: getstatic     #7                  // Field java/lang/System.out:Ljava/io/PrintStream;
    134          7: ldc           #8                  // String [ get inner lock ] success
    135          9: invokevirtual #9                  // Method java/io/PrintStream.println:(Ljava/lang/String;)V
    136         12: getstatic     #5                  // Field i:I
    137         15: iconst_1
    138         16: iadd
    139         17: putstatic     #5                  // Field i:I
    140         20: getstatic     #10                 // Field j:I
    141         23: iconst_1
    142         24: iadd
    143         25: putstatic     #10                 // Field j:I
    144         28: getstatic     #6                  // Field state:I
    145         31: iconst_1
    146         32: iadd
    147         33: putstatic     #6                  // Field state:I
    148         36: getstatic     #11                 // Field k:I
    149         39: iconst_1
    150         40: iadd
    151         41: putstatic     #11                 // Field k:I
    152         44: aload_0
    153         45: invokevirtual #12                 // Method java/lang/Object.wait:()V
    154         48: goto          52
    155         51: astore_2
    156         52: aload_0
    157         53: invokevirtual #14                 // Method java/lang/Object.notifyAll:()V
    158         56: getstatic     #7                  // Field java/lang/System.out:Ljava/io/PrintStream;
    159         59: ldc           #15                 // String [ notifyAll ] ... ...
    160         61: invokevirtual #9                  // Method java/io/PrintStream.println:(Ljava/lang/String;)V
    161         64: aload_1
    162         65: monitorexit
    163         66: goto          74
    164         69: astore_3
    165         70: aload_1
    166         71: monitorexit
    167         72: aload_3
    168         73: athrow
    169         74: return
    170       Exception table:
    171          from    to  target type
    172             44    48    51   Class java/lang/InterruptedException
    173              4    66    69   any
    174             69    72    69   any
    175       LineNumberTable:
    176         line 23: 0
    177         line 24: 4
    178         line 25: 12
    179         line 26: 20
    180         line 27: 28
    181         line 28: 36
    182         line 30: 44
    183         line 33: 48
    184         line 31: 51
    185         line 34: 52
    186         line 35: 56
    187         line 36: 64
    188         line 38: 74
    189       StackMapTable: number_of_entries = 4
    190         frame_type = 255 /* full_frame */
    191           offset_delta = 51
    192           locals = [ class com/clouds/example/service/lock/LockExample, class java/lang/Object ]
    193           stack = [ class java/lang/InterruptedException ]
    194         frame_type = 0 /* same */
    195         frame_type = 80 /* same_locals_1_stack_item */
    196           stack = [ class java/lang/Throwable ]
    197         frame_type = 250 /* chop */
    198           offset_delta = 4
    199 }
    200 SourceFile: "LockExample.java"
    View Code

    从上面的jvm指令中发现,volatile修饰的state只是比其它几个多了一个volatile关键字的标记,其它地地方的jvm指令一摸一样;

    接下来再将它的汇编指令扒出来看看;

    通过Class看汇编的方式:

    第一步:需要 hsdis-amd64.dll 打印java的汇编文件(至于如何创建该文件,则以后再研究,由于我是再windows上操作,所以是dll文件,如果是linux则后缀应该是.so文件)

    需要将hsdis-amd64.dll 放到JAVA_HOMEjreinserver目录下

    第二步:基于Class文件执行如下命令,运行并打印执行的汇编指令:

    C:UsersAdministratorDesktop> java  -Xcomp   /
        -XX:+UnlockDiagnosticVMOptions  /
        -XX:+PrintAssembly  /
        -XX:CompileCommand=dontinline,LockExample.innerSynch   /
        -XX:CompileCommand=compileonly,LockExample.innerSynch   /
        LockExample > sync1

    结果输入到文件:sync1

      1 CompilerOracle: dontinline LockExample.innerSynch
      2 CompilerOracle: compileonly LockExample.innerSynch
      3 Loaded disassembler from hsdis-amd64.dll
      4 Decoding compiled method 0x0000000003324910:
      5 Code:
      6 [Disassembling for mach='i386:x86-64']
      7 [Entry Point]
      8 [Constants]
      9   # {method} {0x0000000017b40490} 'innerSynch' '()V' in 'LockExample'
     10   #           [sp+0x50]  (sp of caller)
     11   0x0000000003324ac0: mov    0x8(%rdx),%r10d
     12   0x0000000003324ac4: shl    $0x3,%r10
     13   0x0000000003324ac8: cmp    %rax,%r10
     14   0x0000000003324acb: jne    0x0000000003265f60  ;   {runtime_call}
     15   0x0000000003324ad1: data16 data16 nopw 0x0(%rax,%rax,1)
     16   0x0000000003324adc: data16 data16 xchg %ax,%ax
     17 [Verified Entry Point]
     18   0x0000000003324ae0: mov    %eax,-0x6000(%rsp)
     19   0x0000000003324ae7: push   %rbp
     20   0x0000000003324ae8: sub    $0x40,%rsp
     21   0x0000000003324aec: movabs $0x17b406a8,%rax   ;   {metadata(method data for {method} {0x0000000017b40490} 'innerSynch' '()V' in 'LockExample')}
     22   0x0000000003324af6: mov    0xdc(%rax),%r8d
     23   0x0000000003324afd: add    $0x8,%r8d
     24   0x0000000003324b01: mov    %r8d,0xdc(%rax)
     25   0x0000000003324b08: movabs $0x17b40488,%rax   ;   {metadata({method} {0x0000000017b40490} 'innerSynch' '()V' in 'LockExample')}
     26   0x0000000003324b12: and    $0x0,%r8d
     27   0x0000000003324b16: cmp    $0x0,%r8d
     28   0x0000000003324b1a: je     0x0000000003324e60  ;*aload_0
     29                                                 ; - LockExample::innerSynch@0 (line 23)
     30 
     31   0x0000000003324b20: lea    0x28(%rsp),%r8
     32   0x0000000003324b25: mov    %rdx,0x8(%r8)
     33   0x0000000003324b29: mov    (%rdx),%rax
     34   0x0000000003324b2c: mov    %rax,%rsi
     35   0x0000000003324b2f: and    $0x7,%rsi
     36   0x0000000003324b33: cmp    $0x5,%rsi
     37   0x0000000003324b37: jne    0x0000000003324bbe
     38   0x0000000003324b3d: mov    0x8(%rdx),%esi
     39   0x0000000003324b40: shl    $0x3,%rsi
     40   0x0000000003324b44: mov    0xa8(%rsi),%rsi
     41   0x0000000003324b4b: or     %r15,%rsi
     42   0x0000000003324b4e: xor    %rax,%rsi
     43   0x0000000003324b51: and    $0xffffffffffffff87,%rsi
     44   0x0000000003324b55: je     0x0000000003324be6
     45   0x0000000003324b5b: test   $0x7,%rsi
     46   0x0000000003324b62: jne    0x0000000003324bab
     47   0x0000000003324b64: test   $0x300,%rsi
     48   0x0000000003324b6b: jne    0x0000000003324b8a
     49   0x0000000003324b6d: and    $0x37f,%rax
     50   0x0000000003324b74: mov    %rax,%rsi
     51   0x0000000003324b77: or     %r15,%rsi
     52   0x0000000003324b7a: lock cmpxchg %rsi,(%rdx)
     53   0x0000000003324b7f: jne    0x0000000003324e77
     54   0x0000000003324b85: jmpq   0x0000000003324be6
     55   0x0000000003324b8a: mov    0x8(%rdx),%esi
     56   0x0000000003324b8d: shl    $0x3,%rsi
     57   0x0000000003324b91: mov    0xa8(%rsi),%rsi
     58   0x0000000003324b98: or     %r15,%rsi
     59   0x0000000003324b9b: lock cmpxchg %rsi,(%rdx)
     60   0x0000000003324ba0: jne    0x0000000003324e77
     61   0x0000000003324ba6: jmpq   0x0000000003324be6
     62   0x0000000003324bab: mov    0x8(%rdx),%esi
     63   0x0000000003324bae: shl    $0x3,%rsi
     64   0x0000000003324bb2: mov    0xa8(%rsi),%rsi
     65   0x0000000003324bb9: lock cmpxchg %rsi,(%rdx)
     66   0x0000000003324bbe: mov    (%rdx),%rax
     67   0x0000000003324bc1: or     $0x1,%rax
     68   0x0000000003324bc5: mov    %rax,(%r8)
     69   0x0000000003324bc8: lock cmpxchg %r8,(%rdx)
     70   0x0000000003324bcd: je     0x0000000003324be6
     71   0x0000000003324bd3: sub    %rsp,%rax
     72   0x0000000003324bd6: and    $0xfffffffffffff007,%rax
     73   0x0000000003324bdd: mov    %rax,(%r8)
     74   0x0000000003324be0: jne    0x0000000003324e77  ;*monitorenter
     75                                                 ; - LockExample::innerSynch@3 (line 23)
     76 
     77   0x0000000003324be6: mov    %rdx,0x20(%rsp)
     78   0x0000000003324beb: nopl   0x0(%rax,%rax,1)
     79   0x0000000003324bf0: jmpq   0x0000000003324ee7  ;   {no_reloc}
     80   0x0000000003324bf5: add    %al,(%rax)
     81   0x0000000003324bf7: add    %al,(%rax)
     82   0x0000000003324bf9: add    %ah,0xf(%rsi)
     83   0x0000000003324bfc: (bad)  
     84   0x0000000003324bfd: add    %r8b,(%rax)
     85   0x0000000003324c00: jmpq   0x0000000003324f02  ; implicit exception: dispatches to 0x0000000003324ef1
     86   0x0000000003324c05: nop
     87   0x0000000003324c06: nop                       ;*getstatic out
     88                                                 ; - LockExample::innerSynch@4 (line 24)
     89 
     90   0x0000000003324c07: cmp    (%rsi),%rax        ; implicit exception: dispatches to 0x0000000003324f0c
     91   0x0000000003324c0a: mov    %rsi,%r8
     92   0x0000000003324c0d: movabs $0x17b406a8,%rdi   ;   {metadata(method data for {method} {0x0000000017b40490} 'innerSynch' '()V' in 'LockExample')}
     93   0x0000000003324c17: mov    0x8(%r8),%r8d
     94   0x0000000003324c1b: shl    $0x3,%r8
     95   0x0000000003324c1f: cmp    0x110(%rdi),%r8
     96   0x0000000003324c26: jne    0x0000000003324c35
     97   0x0000000003324c28: addq   $0x1,0x118(%rdi)
     98   0x0000000003324c30: jmpq   0x0000000003324c9b
     99   0x0000000003324c35: cmp    0x120(%rdi),%r8
    100   0x0000000003324c3c: jne    0x0000000003324c4b
    101   0x0000000003324c3e: addq   $0x1,0x128(%rdi)
    102   0x0000000003324c46: jmpq   0x0000000003324c9b
    103   0x0000000003324c4b: cmpq   $0x0,0x110(%rdi)
    104   0x0000000003324c56: jne    0x0000000003324c6f
    105   0x0000000003324c58: mov    %r8,0x110(%rdi)
    106   0x0000000003324c5f: movq   $0x1,0x118(%rdi)
    107   0x0000000003324c6a: jmpq   0x0000000003324c9b
    108   0x0000000003324c6f: cmpq   $0x0,0x120(%rdi)
    109   0x0000000003324c7a: jne    0x0000000003324c93
    110   0x0000000003324c7c: mov    %r8,0x120(%rdi)
    111   0x0000000003324c83: movq   $0x1,0x128(%rdi)
    112   0x0000000003324c8e: jmpq   0x0000000003324c9b
    113   0x0000000003324c93: addq   $0x1,0x108(%rdi)
    114   0x0000000003324c9b: movabs $0xd62c7b68,%r8    ;   {oop("[ get inner lock ] success")}
    115   0x0000000003324ca5: mov    %rsi,%rdx          ;*invokevirtual println
    116                                                 ; - LockExample::innerSynch@9 (line 24)
    117 
    118   0x0000000003324ca8: nop
    119   0x0000000003324ca9: nop
    120   0x0000000003324caa: nop
    121   0x0000000003324cab: nop
    122   0x0000000003324cac: nop
    123   0x0000000003324cad: movabs $0xffffffffffffffff,%rax
    124   0x0000000003324cb7: callq  0x00000000032663e0  ; OopMap{[32]=Oop [48]=Oop off=508}
    125                                                 ;*invokevirtual println
    126                                                 ; - LockExample::innerSynch@9 (line 24)
    127                                                 ;   {virtual_call}
    128   0x0000000003324cbc: movabs $0xd6254880,%r8    ;   {oop(a 'java/lang/Class' = 'LockExample')}
    129   0x0000000003324cc6: mov    0x68(%r8),%edx     ;*getstatic i
    130                                                 ; - LockExample::innerSynch@12 (line 25)
    131 
    132   0x0000000003324cca: inc    %edx
    133   0x0000000003324ccc: mov    %edx,0x68(%r8)     ;*putstatic i
    134                                                 ; - LockExample::innerSynch@17 (line 25)
    135 
    136   0x0000000003324cd0: mov    0x6c(%r8),%edx     ;*getstatic j
    137                                                 ; - LockExample::innerSynch@20 (line 26)
    138 
    139   0x0000000003324cd4: inc    %edx
    140   0x0000000003324cd6: mov    %edx,0x6c(%r8)     ;*putstatic j
    141                                                 ; - LockExample::innerSynch@25 (line 26)
    142 
    143   0x0000000003324cda: mov    0x74(%r8),%edx     ;*getstatic state
    144                                                 ; - LockExample::innerSynch@28 (line 27)
    145 
    146   0x0000000003324cde: inc    %edx
    147   0x0000000003324ce0: mov    %edx,0x74(%r8)
    148   0x0000000003324ce4: lock addl $0x0,(%rsp)     ;*putstatic state
    149                                                 ; - LockExample::innerSynch@33 (line 27)
    150 
    151   0x0000000003324ce9: mov    0x70(%r8),%edx     ;*getstatic k
    152                                                 ; - LockExample::innerSynch@36 (line 28)
    153 
    154   0x0000000003324ced: inc    %edx
    155   0x0000000003324cef: mov    %edx,0x70(%r8)     ;*putstatic k
    156                                                 ; - LockExample::innerSynch@41 (line 28)
    157 
    158   0x0000000003324cf3: nopl   0x0(%rax,%rax,1)
    159   0x0000000003324cf8: jmpq   0x0000000003324f6e  ;   {no_reloc}
    160   0x0000000003324cfd: add    %al,(%rax)
    161   0x0000000003324cff: add    %al,(%rax)
    162   0x0000000003324d01: add    %ah,0xf(%rsi)
    163   0x0000000003324d04: (bad)  
    164   0x0000000003324d05: add    %r8b,(%rax)
    165   0x0000000003324d08: jmpq   0x0000000003324f89  ; implicit exception: dispatches to 0x0000000003324f78
    166   0x0000000003324d0d: nop
    167   0x0000000003324d0e: nop                       ;*getstatic out
    168                                                 ; - LockExample::innerSynch@44 (line 29)
    169 
    170   0x0000000003324d0f: cmp    (%rdx),%rax        ; implicit exception: dispatches to 0x0000000003324f93
    171   0x0000000003324d12: mov    %rdx,%r8
    172   0x0000000003324d15: movabs $0x17b406a8,%rsi   ;   {metadata(method data for {method} {0x0000000017b40490} 'innerSynch' '()V' in 'LockExample')}
    173   0x0000000003324d1f: mov    0x8(%r8),%r8d
    174   0x0000000003324d23: shl    $0x3,%r8
    175   0x0000000003324d27: cmp    0x140(%rsi),%r8
    176   0x0000000003324d2e: jne    0x0000000003324d3d
    177   0x0000000003324d30: addq   $0x1,0x148(%rsi)
    178   0x0000000003324d38: jmpq   0x0000000003324da3
    179   0x0000000003324d3d: cmp    0x150(%rsi),%r8
    180   0x0000000003324d44: jne    0x0000000003324d53
    181   0x0000000003324d46: addq   $0x1,0x158(%rsi)
    182   0x0000000003324d4e: jmpq   0x0000000003324da3
    183   0x0000000003324d53: cmpq   $0x0,0x140(%rsi)
    184   0x0000000003324d5e: jne    0x0000000003324d77
    185   0x0000000003324d60: mov    %r8,0x140(%rsi)
    186   0x0000000003324d67: movq   $0x1,0x148(%rsi)
    187   0x0000000003324d72: jmpq   0x0000000003324da3
    188   0x0000000003324d77: cmpq   $0x0,0x150(%rsi)
    189   0x0000000003324d82: jne    0x0000000003324d9b
    190   0x0000000003324d84: mov    %r8,0x150(%rsi)
    191   0x0000000003324d8b: movq   $0x1,0x158(%rsi)
    192   0x0000000003324d96: jmpq   0x0000000003324da3
    193   0x0000000003324d9b: addq   $0x1,0x138(%rsi)
    194   0x0000000003324da3: movabs $0xd62c7bc8,%r8    ;*invokevirtual println
    195                                                 ; - LockExample::innerSynch@49 (line 29)
    196                                                 ;   {oop("[ notifyAll ] ... ...")}
    197   0x0000000003324dad: movabs $0xffffffffffffffff,%rax
    198   0x0000000003324db7: callq  0x00000000032663e0  ; OopMap{[32]=Oop [48]=Oop off=764}
    199                                                 ;*invokevirtual println
    200                                                 ; - LockExample::innerSynch@49 (line 29)
    201                                                 ;   {virtual_call}
    202   0x0000000003324dbc: lea    0x28(%rsp),%rax
    203   0x0000000003324dc1: mov    0x8(%rax),%rdi
    204   0x0000000003324dc5: mov    (%rdi),%rsi
    205   0x0000000003324dc8: and    $0x7,%rsi
    206   0x0000000003324dcc: cmp    $0x5,%rsi
    207   0x0000000003324dd0: je     0x0000000003324ded
    208   0x0000000003324dd6: mov    (%rax),%rsi
    209   0x0000000003324dd9: test   %rsi,%rsi
    210   0x0000000003324ddc: je     0x0000000003324ded
    211   0x0000000003324de2: lock cmpxchg %rsi,(%rdi)
    212   0x0000000003324de7: jne    0x0000000003324f98  ;*monitorexit
    213                                                 ; - LockExample::innerSynch@53 (line 30)
    214 
    215   0x0000000003324ded: movabs $0x17b406a8,%rax   ;   {metadata(method data for {method} {0x0000000017b40490} 'innerSynch' '()V' in 'LockExample')}
    216   0x0000000003324df7: incl   0x168(%rax)        ;*goto
    217                                                 ; - LockExample::innerSynch@54 (line 30)
    218 
    219   0x0000000003324dfd: add    $0x40,%rsp
    220   0x0000000003324e01: pop    %rbp
    221   0x0000000003324e02: test   %eax,-0x2734d08(%rip)        # 0x0000000000bf0100
    222                                                 ;   {poll_return}
    223   0x0000000003324e08: retq                      ;*return
    224                                                 ; - LockExample::innerSynch@62 (line 32)
    225 
    226   0x0000000003324e09: mov    0x2a8(%r15),%rax
    227   0x0000000003324e10: xor    %r10,%r10
    228   0x0000000003324e13: mov    %r10,0x2a8(%r15)
    229   0x0000000003324e1a: xor    %r10,%r10
    230   0x0000000003324e1d: mov    %r10,0x2b0(%r15)
    231   0x0000000003324e24: mov    %rax,%rsi
    232   0x0000000003324e27: lea    0x28(%rsp),%rax
    233   0x0000000003324e2c: mov    0x8(%rax),%rbx
    234   0x0000000003324e30: mov    (%rbx),%rdi
    235   0x0000000003324e33: and    $0x7,%rdi
    236   0x0000000003324e37: cmp    $0x5,%rdi
    237   0x0000000003324e3b: je     0x0000000003324e58
    238   0x0000000003324e41: mov    (%rax),%rdi
    239   0x0000000003324e44: test   %rdi,%rdi
    240   0x0000000003324e47: je     0x0000000003324e58
    241   0x0000000003324e4d: lock cmpxchg %rdi,(%rbx)
    242   0x0000000003324e52: jne    0x0000000003324fab  ;*monitorexit
    243                                                 ; - LockExample::innerSynch@59 (line 30)
    244 
    245   0x0000000003324e58: mov    %rsi,%rax
    246   0x0000000003324e5b: jmpq   0x0000000003324fe9
    247   0x0000000003324e60: mov    %rax,0x8(%rsp)
    248   0x0000000003324e65: movq   $0xffffffffffffffff,(%rsp)
    249   0x0000000003324e6d: callq  0x0000000003320b20  ; OopMap{rdx=Oop off=946}
    250                                                 ;*synchronization entry
    251                                                 ; - LockExample::innerSynch@-1 (line 23)
    252                                                 ;   {runtime_call}
    253   0x0000000003324e72: jmpq   0x0000000003324b20
    254   0x0000000003324e77: mov    %rdx,0x8(%rsp)
    255   0x0000000003324e7c: mov    %r8,(%rsp)
    256   0x0000000003324e80: callq  0x000000000331ec20  ; OopMap{rdx=Oop [48]=Oop off=965}
    257                                                 ;*monitorenter
    258                                                 ; - LockExample::innerSynch@3 (line 23)
    259                                                 ;   {runtime_call}
    260   0x0000000003324e85: jmpq   0x0000000003324be6
    261   0x0000000003324e8a: movabs $0x0,%r8           ;   {oop(NULL)}
    262   0x0000000003324e94: push   %rax
    263   0x0000000003324e95: push   %rbx
    264   0x0000000003324e96: mov    0x48(%r8),%rbx
    265   0x0000000003324e9a: push   %rdi
    266   0x0000000003324e9b: push   %rsi
    267   0x0000000003324e9c: push   %rdx
    268   0x0000000003324e9d: push   %rcx
    269   0x0000000003324e9e: push   %r8
    270   0x0000000003324ea0: push   %r9
    271   0x0000000003324ea2: push   %r10
    272   0x0000000003324ea4: mov    %rsp,%r10
    273   0x0000000003324ea7: and    $0xfffffffffffffff0,%rsp
    274   0x0000000003324eab: push   %r10
    275   0x0000000003324ead: push   %r11
    276   0x0000000003324eaf: mov    $0x7,%ecx
    277   0x0000000003324eb4: movabs $0x7ff816c75250,%r10  ;   {runtime_call}
    278   0x0000000003324ebe: callq  *%r10
    279   0x0000000003324ec1: pop    %r11
    280   0x0000000003324ec3: pop    %rsp
    281   0x0000000003324ec4: pop    %r10
    282   0x0000000003324ec6: pop    %r9
    283   0x0000000003324ec8: pop    %r8
    284   0x0000000003324eca: pop    %rcx
    285   0x0000000003324ecb: pop    %rdx
    286   0x0000000003324ecc: pop    %rsi
    287   0x0000000003324ecd: pop    %rdi
    288   0x0000000003324ece: cmp    0x118(%rbx),%rax
    289   0x0000000003324ed5: pop    %rbx
    290   0x0000000003324ed6: pop    %rax
    291   0x0000000003324ed7: jne    0x0000000003324ee7
    292   0x0000000003324edd: jmpq   0x0000000003324bfa
    293   0x0000000003324ee2: mov    $0xa535d00,%eax
    294   0x0000000003324ee7: callq  0x000000000331fd20  ; OopMap{[32]=Oop [48]=Oop off=1068}
    295                                                 ;*getstatic out
    296                                                 ; - LockExample::innerSynch@4 (line 24)
    297                                                 ;   {runtime_call}
    298   0x0000000003324eec: jmpq   0x0000000003324bf0
    299   0x0000000003324ef1: callq  0x000000000331bf80  ; OopMap{[32]=Oop r8=Oop [48]=Oop off=1078}
    300                                                 ;*getstatic out
    301                                                 ; - LockExample::innerSynch@4 (line 24)
    302                                                 ;   {runtime_call}
    303   0x0000000003324ef6: mov    0x0(%r8),%esi
    304   0x0000000003324efd: mov    $0x7050c00,%eax
    305   0x0000000003324f02: callq  0x000000000331f4a0  ; OopMap{[32]=Oop r8=Oop [48]=Oop off=1095}
    306                                                 ;*getstatic out
    307                                                 ; - LockExample::innerSynch@4 (line 24)
    308                                                 ;   {runtime_call}
    309   0x0000000003324f07: jmpq   0x0000000003324c00
    310   0x0000000003324f0c: callq  0x000000000331bf80  ; OopMap{[32]=Oop rsi=Oop [48]=Oop off=1105}
    311                                                 ;*invokevirtual println
    312                                                 ; - LockExample::innerSynch@9 (line 24)
    313                                                 ;   {runtime_call}
    314   0x0000000003324f11: movabs $0x0,%r8           ;   {oop(NULL)}
    315   0x0000000003324f1b: push   %rax
    316   0x0000000003324f1c: push   %rbx
    317   0x0000000003324f1d: mov    0x48(%r8),%rbx
    318   0x0000000003324f21: push   %rdi
    319   0x0000000003324f22: push   %rsi
    320   0x0000000003324f23: push   %rdx
    321   0x0000000003324f24: push   %rcx
    322   0x0000000003324f25: push   %r8
    323   0x0000000003324f27: push   %r9
    324   0x0000000003324f29: push   %r10
    325   0x0000000003324f2b: mov    %rsp,%r10
    326   0x0000000003324f2e: and    $0xfffffffffffffff0,%rsp
    327   0x0000000003324f32: push   %r10
    328   0x0000000003324f34: push   %r11
    329   0x0000000003324f36: mov    $0x7,%ecx
    330   0x0000000003324f3b: movabs $0x7ff816c75250,%r10  ;   {runtime_call}
    331   0x0000000003324f45: callq  *%r10
    332   0x0000000003324f48: pop    %r11
    333   0x0000000003324f4a: pop    %rsp
    334   0x0000000003324f4b: pop    %r10
    335   0x0000000003324f4d: pop    %r9
    336   0x0000000003324f4f: pop    %r8
    337   0x0000000003324f51: pop    %rcx
    338   0x0000000003324f52: pop    %rdx
    339   0x0000000003324f53: pop    %rsi
    340   0x0000000003324f54: pop    %rdi
    341   0x0000000003324f55: cmp    0x118(%rbx),%rax
    342   0x0000000003324f5c: pop    %rbx
    343   0x0000000003324f5d: pop    %rax
    344   0x0000000003324f5e: jne    0x0000000003324f6e
    345   0x0000000003324f64: jmpq   0x0000000003324d02
    346   0x0000000003324f69: mov    $0xa535d00,%eax
    347   0x0000000003324f6e: callq  0x000000000331fd20  ; OopMap{[32]=Oop [48]=Oop off=1203}
    348                                                 ;*getstatic out
    349                                                 ; - LockExample::innerSynch@44 (line 29)
    350                                                 ;   {runtime_call}
    351   0x0000000003324f73: jmpq   0x0000000003324cf8
    352   0x0000000003324f78: callq  0x000000000331bf80  ; OopMap{[32]=Oop r8=Oop [48]=Oop off=1213}
    353                                                 ;*getstatic out
    354                                                 ; - LockExample::innerSynch@44 (line 29)
    355                                                 ;   {runtime_call}
    356   0x0000000003324f7d: mov    0x0(%r8),%edx
    357   0x0000000003324f84: mov    $0x7050c00,%eax
    358   0x0000000003324f89: callq  0x000000000331f4a0  ; OopMap{[32]=Oop r8=Oop [48]=Oop off=1230}
    359                                                 ;*getstatic out
    360                                                 ; - LockExample::innerSynch@44 (line 29)
    361                                                 ;   {runtime_call}
    362   0x0000000003324f8e: jmpq   0x0000000003324d08
    363   0x0000000003324f93: callq  0x000000000331bf80  ; OopMap{[32]=Oop rdx=Oop [48]=Oop off=1240}
    364                                                 ;*invokevirtual println
    365                                                 ; - LockExample::innerSynch@49 (line 29)
    366                                                 ;   {runtime_call}
    367   0x0000000003324f98: lea    0x28(%rsp),%rax
    368   0x0000000003324f9d: mov    %rax,(%rsp)
    369   0x0000000003324fa1: callq  0x000000000331f060  ;   {runtime_call}
    370   0x0000000003324fa6: jmpq   0x0000000003324ded
    371   0x0000000003324fab: lea    0x28(%rsp),%rax
    372   0x0000000003324fb0: mov    %rax,(%rsp)
    373   0x0000000003324fb4: callq  0x000000000331f060  ;   {runtime_call}
    374   0x0000000003324fb9: jmpq   0x0000000003324e58
    375   0x0000000003324fbe: nop
    376   0x0000000003324fbf: nop
    377   0x0000000003324fc0: mov    0x2a8(%r15),%rax
    378   0x0000000003324fc7: movabs $0x0,%r10
    379   0x0000000003324fd1: mov    %r10,0x2a8(%r15)
    380   0x0000000003324fd8: movabs $0x0,%r10
    381   0x0000000003324fe2: mov    %r10,0x2b0(%r15)
    382   0x0000000003324fe9: add    $0x40,%rsp
    383   0x0000000003324fed: pop    %rbp
    384   0x0000000003324fee: jmpq   0x000000000331b0a0  ;   {runtime_call}
    385   0x0000000003324ff3: hlt    
    386   0x0000000003324ff4: hlt    
    387   0x0000000003324ff5: hlt    
    388   0x0000000003324ff6: hlt    
    389   0x0000000003324ff7: hlt    
    390   0x0000000003324ff8: hlt    
    391   0x0000000003324ff9: hlt    
    392   0x0000000003324ffa: hlt    
    393   0x0000000003324ffb: hlt    
    394   0x0000000003324ffc: hlt    
    395   0x0000000003324ffd: hlt    
    396   0x0000000003324ffe: hlt    
    397   0x0000000003324fff: hlt    
    398 [Stub Code]
    399   0x0000000003325000: nop                       ;   {no_reloc}
    400   0x0000000003325001: nop
    401   0x0000000003325002: nop
    402   0x0000000003325003: nop
    403   0x0000000003325004: nop
    404   0x0000000003325005: movabs $0x0,%rbx          ;   {static_stub}
    405   0x000000000332500f: jmpq   0x000000000332500f  ;   {runtime_call}
    406   0x0000000003325014: nop
    407   0x0000000003325015: movabs $0x0,%rbx          ;   {static_stub}
    408   0x000000000332501f: jmpq   0x000000000332501f  ;   {runtime_call}
    409 [Exception Handler]
    410   0x0000000003325024: callq  0x000000000331e0e0  ;   {runtime_call}
    411   0x0000000003325029: mov    %rsp,-0x28(%rsp)
    412   0x000000000332502e: sub    $0x80,%rsp
    413   0x0000000003325035: mov    %rax,0x78(%rsp)
    414   0x000000000332503a: mov    %rcx,0x70(%rsp)
    415   0x000000000332503f: mov    %rdx,0x68(%rsp)
    416   0x0000000003325044: mov    %rbx,0x60(%rsp)
    417   0x0000000003325049: mov    %rbp,0x50(%rsp)
    418   0x000000000332504e: mov    %rsi,0x48(%rsp)
    419   0x0000000003325053: mov    %rdi,0x40(%rsp)
    420   0x0000000003325058: mov    %r8,0x38(%rsp)
    421   0x000000000332505d: mov    %r9,0x30(%rsp)
    422   0x0000000003325062: mov    %r10,0x28(%rsp)
    423   0x0000000003325067: mov    %r11,0x20(%rsp)
    424   0x000000000332506c: mov    %r12,0x18(%rsp)
    425   0x0000000003325071: mov    %r13,0x10(%rsp)
    426   0x0000000003325076: mov    %r14,0x8(%rsp)
    427   0x000000000332507b: mov    %r15,(%rsp)
    428   0x000000000332507f: movabs $0x56491820,%rcx   ;   {external_word}
    429   0x0000000003325089: movabs $0x3325029,%rdx    ;   {internal_word}
    430   0x0000000003325093: mov    %rsp,%r8
    431   0x0000000003325096: and    $0xfffffffffffffff0,%rsp
    432   0x000000000332509a: callq  0x0000000056146f40  ;   {runtime_call}
    433   0x000000000332509f: hlt    
    434 [Deopt Handler Code]
    435   0x00000000033250a0: movabs $0x33250a0,%r10    ;   {section_word}
    436   0x00000000033250aa: push   %r10
    437   0x00000000033250ac: jmpq   0x0000000003267600  ;   {runtime_call}
    438   0x00000000033250b1: hlt    
    439   0x00000000033250b2: hlt    
    440   0x00000000033250b3: hlt    
    441   0x00000000033250b4: hlt    
    442   0x00000000033250b5: hlt    
    443   0x00000000033250b6: hlt    
    444   0x00000000033250b7: hlt    
    445 Decoding compiled method 0x0000000003322b10:
    446 Code:
    447 [Entry Point]
    448 [Constants]
    449   # {method} {0x0000000017b40490} 'innerSynch' '()V' in 'LockExample'
    450   #           [sp+0x30]  (sp of caller)
    451   0x0000000003322c40: mov    0x8(%rdx),%r10d
    452   0x0000000003322c44: shl    $0x3,%r10
    453   0x0000000003322c48: cmp    %r10,%rax
    454   0x0000000003322c4b: jne    0x0000000003265f60  ;   {runtime_call}
    455   0x0000000003322c51: data16 xchg %ax,%ax
    456   0x0000000003322c54: nopl   0x0(%rax,%rax,1)
    457   0x0000000003322c5c: data16 data16 xchg %ax,%ax
    458 [Verified Entry Point]
    459   0x0000000003322c60: mov    %eax,-0x6000(%rsp)
    460   0x0000000003322c67: push   %rbp
    461   0x0000000003322c68: sub    $0x20,%rsp         ;*synchronization entry
    462                                                 ; - LockExample::innerSynch@-1 (line 23)
    463 
    464   0x0000000003322c6c: mov    %rdx,%rbp
    465   0x0000000003322c6f: mov    (%rdx),%rax
    466   0x0000000003322c72: mov    %rax,%r10
    467   0x0000000003322c75: and    $0x7,%r10
    468   0x0000000003322c79: cmp    $0x5,%r10
    469   0x0000000003322c7d: jne    0x0000000003322ce6
    470   0x0000000003322c7f: mov    $0x2000c005,%r11d  ;   {metadata('LockExample')}
    471   0x0000000003322c85: movabs $0x0,%r10
    472   0x0000000003322c8f: lea    (%r10,%r11,8),%r10
    473   0x0000000003322c93: mov    0xa8(%r10),%r10
    474   0x0000000003322c9a: mov    %r10,%r11
    475   0x0000000003322c9d: or     %r15,%r11
    476   0x0000000003322ca0: mov    %r11,%r8
    477   0x0000000003322ca3: xor    %rax,%r8
    478   0x0000000003322ca6: test   $0xffffffffffffff87,%r8
    479   0x0000000003322cad: je     0x0000000003322cd5
    480   0x0000000003322caf: test   $0x7,%r8
    481   0x0000000003322cb6: jne    0x0000000003322ce1
    482   0x0000000003322cb8: test   $0x300,%r8
    483   0x0000000003322cbf: jne    0x0000000003322cce
    484   0x0000000003322cc1: and    $0x37f,%rax
    485   0x0000000003322cc8: mov    %rax,%r11
    486   0x0000000003322ccb: or     %r15,%r11
    487   0x0000000003322cce: lock cmpxchg %r11,(%rdx)
    488   0x0000000003322cd3: jne    0x0000000003322d35  ;*monitorenter
    489                                                 ; - LockExample::innerSynch@3 (line 23)
    490 
    491   0x0000000003322cd5: mov    $0x25,%edx
    492   0x0000000003322cda: nop
    493   0x0000000003322cdb: callq  0x00000000032657a0  ; OopMap{rbp=Oop off=160}
    494                                                 ;*getstatic out
    495                                                 ; - LockExample::innerSynch@4 (line 24)
    496                                                 ;   {runtime_call}
    497   0x0000000003322ce0: int3                      ;*getstatic out
    498                                                 ; - LockExample::innerSynch@4 (line 24)
    499 
    500   0x0000000003322ce1: lock cmpxchg %r10,(%rdx)
    501   0x0000000003322ce6: lea    0x10(%rsp),%rbx
    502   0x0000000003322ceb: mov    (%rdx),%rax
    503   0x0000000003322cee: test   $0x2,%rax
    504   0x0000000003322cf4: jne    0x0000000003322d1a
    505   0x0000000003322cf6: or     $0x1,%rax
    506   0x0000000003322cfa: mov    %rax,(%rbx)
    507   0x0000000003322cfd: lock cmpxchg %rbx,(%rdx)
    508   0x0000000003322d02: je     0x0000000003322d33
    509   0x0000000003322d08: sub    %rsp,%rax
    510   0x0000000003322d0b: and    $0xfffffffffffff007,%rax
    511   0x0000000003322d12: mov    %rax,(%rbx)
    512   0x0000000003322d15: jmpq   0x0000000003322d33
    513   0x0000000003322d1a: movq   $0x3,(%rbx)
    514   0x0000000003322d21: mov    %rax,%rbx
    515   0x0000000003322d24: mov    0x16(%rbx),%rax
    516   0x0000000003322d28: test   %rax,%rax
    517   0x0000000003322d2b: jne    0x0000000003322d33
    518   0x0000000003322d2d: lock cmpxchg %r15,0x16(%rbx)
    519   0x0000000003322d33: je     0x0000000003322cd5
    520   0x0000000003322d35: lea    0x10(%rsp),%r8
    521   0x0000000003322d3a: nop
    522   0x0000000003322d3b: callq  0x0000000003321860  ; OopMap{rbp=Oop off=256}
    523                                                 ;*monitorenter
    524                                                 ; - LockExample::innerSynch@3 (line 23)
    525                                                 ;   {runtime_call}
    526   0x0000000003322d40: jmp    0x0000000003322cd5
    527   0x0000000003322d42: hlt    
    528   0x0000000003322d43: hlt    
    529   0x0000000003322d44: hlt    
    530   0x0000000003322d45: hlt    
    531   0x0000000003322d46: hlt    
    532   0x0000000003322d47: hlt    
    533   0x0000000003322d48: hlt    
    534   0x0000000003322d49: hlt    
    535   0x0000000003322d4a: hlt    
    536   0x0000000003322d4b: hlt    
    537   0x0000000003322d4c: hlt    
    538   0x0000000003322d4d: hlt    
    539   0x0000000003322d4e: hlt    
    540   0x0000000003322d4f: hlt    
    541   0x0000000003322d50: hlt    
    542   0x0000000003322d51: hlt    
    543   0x0000000003322d52: hlt    
    544   0x0000000003322d53: hlt    
    545   0x0000000003322d54: hlt    
    546   0x0000000003322d55: hlt    
    547   0x0000000003322d56: hlt    
    548   0x0000000003322d57: hlt    
    549   0x0000000003322d58: hlt    
    550   0x0000000003322d59: hlt    
    551   0x0000000003322d5a: hlt    
    552   0x0000000003322d5b: hlt    
    553   0x0000000003322d5c: hlt    
    554   0x0000000003322d5d: hlt    
    555   0x0000000003322d5e: hlt    
    556   0x0000000003322d5f: hlt    
    557 [Exception Handler]
    558 [Stub Code]
    559   0x0000000003322d60: jmpq   0x000000000328e020  ;   {no_reloc}
    560 [Deopt Handler Code]
    561   0x0000000003322d65: callq  0x0000000003322d6a
    562   0x0000000003322d6a: subq   $0x5,(%rsp)
    563   0x0000000003322d6f: jmpq   0x0000000003267600  ;   {runtime_call}
    564   0x0000000003322d74: hlt    
    565   0x0000000003322d75: hlt    
    566   0x0000000003322d76: hlt    
    567   0x0000000003322d77: hlt    
    568 [ get inner lock ] success
    569 [ notifyAll ] ... ...
    汇编指令

    通过汇编指令发现如下内容:

        

  • 相关阅读:
    STM32 + RT Thread OS 学习笔记[三]
    全代码实现ios-1
    HTML5 Web Speech API 结合Ext实现浏览器语音识别以及输入
    全代码实现ios-2
    从零开始学C++之虚函数与多态(一):虚函数表指针、虚析构函数、object slicing与虚函数
    二进制程序分析工具Pin在Windows系统中的安装和使用方法
    使用U盘安装Ubuntu系统的实践小结
    HDU 1874 畅通工程续
    JSP页面上用横线代替文本框
    Mysql设置编码
  • 原文地址:https://www.cnblogs.com/outpointexception/p/13588992.html
Copyright © 2020-2023  润新知