hotspot disassembler
1. Git 地址
https://github.com/liuzhengyang/hsdis
2. 操作
git clone https://github.com/liuzhengyang/hsdis
cd hsdis
tar -zxvf binutils-2.26.tar.gz
make BINUTILS=binutils-2.26 ARCH=amd64
cp build/linux-amd64/hsdis-amd64.so /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.282.b08-1.el7_9.x86_64/jre/lib/amd64/server/
cd /test/
javac T.java
java -XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly T
public class T {
public static volatile int i = 0;
public static void main(String[] args) {
System.out.println("----------------");
for (int i = 0; i < 1000; i++) {
m();
n();
}
}
public static synchronized void m() {
}
public static void n() {
i = 1;
}
}
(base) [root@localhost test]# java T
----------------
(base) [root@localhost test]# java -XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly T
OpenJDK 64-Bit Server VM warning: PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output
Loaded disassembler from /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.282.b08-1.el7_9.x86_64/jre/lib/amd64/server/hsdis-amd64.so
Decoding compiled method 0x00007fb9c8ef71d0:
Code:
[Disassembling for mach='i386:x86-64']
[Entry Point]
[Constants]
# {method} {0x00007fb9c68bee38} 'hashCode' '()I' in 'java/lang/String'
# [sp+0x40] (sp of caller)
0x00007fb9c8ef7340: mov 0x8(%rsi),%r10d
0x00007fb9c8ef7344: shl $0x3,%r10
0x00007fb9c8ef7348: cmp %rax,%r10
0x00007fb9c8ef734b: jne 0x00007fb9c8e3cba0 ; {runtime_call}
0x00007fb9c8ef7351: data16 data16 nopw 0x0(%rax,%rax,1)
0x00007fb9c8ef735c: data16 data16 xchg %ax,%ax
[Verified Entry Point]
0x00007fb9c8ef7360: mov %eax,-0x14000(%rsp)
0x00007fb9c8ef7367: push %rbp
0x00007fb9c8ef7368: sub $0x30,%rsp
0x00007fb9c8ef736c: movabs $0x7fb9c6abf368,%rax ; {metadata(method data for {method} {0x00007fb9c68bee38} 'hashCode' '()I' in 'java/lang/String')}
0x00007fb9c8ef7376: mov 0xdc(%rax),%edi
0x00007fb9c8ef737c: add $0x8,%edi
0x00007fb9c8ef737f: mov %edi,0xdc(%rax)
0x00007fb9c8ef7385: movabs $0x7fb9c68bee38,%rax ; {metadata({method} {0x00007fb9c68bee38} 'hashCode' '()I' in 'java/lang/String')}
0x00007fb9c8ef738f: and $0x1ff8,%edi
0x00007fb9c8ef7395: cmp $0x0,%edi
0x00007fb9c8ef7398: je 0x00007fb9c8ef74d1 ;*aload_0
; - java.lang.String::hashCode@0 (line 1466)
0x00007fb9c8ef739e: mov 0x10(%rsi),%eax ;*getfield hash
; - java.lang.String::hashCode@1 (line 1466)
0x00007fb9c8ef73a1: cmp $0x0,%eax
0x00007fb9c8ef73a4: movabs $0x7fb9c6abf368,%rdi ; {metadata(method data for {method} {0x00007fb9c68bee38} 'hashCode' '()I' in 'java/lang/String')}
0x00007fb9c8ef73ae: movabs $0x108,%rbx
0x00007fb9c8ef73b8: jne 0x00007fb9c8ef73c8
0x00007fb9c8ef73be: movabs $0x118,%rbx
0x00007fb9c8ef73c8: mov (%rdi,%rbx,1),%rdx
0x00007fb9c8ef73cc: lea 0x1(%rdx),%rdx
0x00007fb9c8ef73d0: mov %rdx,(%rdi,%rbx,1)
0x00007fb9c8ef73d4: jne 0x00007fb9c8ef74c5 ;*ifne
; - java.lang.String::hashCode@6 (line 1467)
0x00007fb9c8ef73da: mov 0xc(%rsi),%edi
0x00007fb9c8ef73dd: shl $0x3,%rdi ;*getfield value
; - java.lang.String::hashCode@10 (line 1467)
0x00007fb9c8ef73e1: mov 0xc(%rdi),%ebx ;*arraylength
; - java.lang.String::hashCode@13 (line 1467)
; implicit exception: dispatches to 0x00007fb9c8ef74e8
0x00007fb9c8ef73e4: cmp $0x0,%ebx
0x00007fb9c8ef73e7: movabs $0x7fb9c6abf368,%rdx ; {metadata(method data for {method} {0x00007fb9c68bee38} 'hashCode' '()I' in 'java/lang/String')}
0x00007fb9c8ef73f1: movabs $0x128,%rcx
0x00007fb9c8ef73fb: jle 0x00007fb9c8ef740b
0x00007fb9c8ef7401: movabs $0x138,%rcx
0x00007fb9c8ef740b: mov (%rdx,%rcx,1),%r8
0x00007fb9c8ef740f: lea 0x1(%r8),%r8
0x00007fb9c8ef7413: mov %r8,(%rdx,%rcx,1)
0x00007fb9c8ef7417: jle 0x00007fb9c8ef74c5 ;*ifle
; - java.lang.String::hashCode@14 (line 1467)
0x00007fb9c8ef741d: mov $0x0,%edx
0x00007fb9c8ef7422: jmpq 0x00007fb9c8ef748a ;*iload_3
; - java.lang.String::hashCode@24 (line 1470)
0x00007fb9c8ef7427: nop
0x00007fb9c8ef7428: movslq %edx,%rcx
0x00007fb9c8ef742b: movzwl 0x10(%rdi,%rcx,2),%ecx ;*caload
; - java.lang.String::hashCode@39 (line 1471)
0x00007fb9c8ef7430: mov %rax,%r8
0x00007fb9c8ef7433: shl $0x5,%eax
0x00007fb9c8ef7436: sub %r8d,%eax
0x00007fb9c8ef7439: add %ecx,%eax
0x00007fb9c8ef743b: inc %edx
0x00007fb9c8ef743d: movabs $0x7fb9c6abf368,%rcx ; {metadata(method data for {method} {0x00007fb9c68bee38} 'hashCode' '()I' in 'java/lang/String')}
0x00007fb9c8ef7447: mov 0xe0(%rcx),%r8d
0x00007fb9c8ef744e: add $0x8,%r8d
0x00007fb9c8ef7452: mov %r8d,0xe0(%rcx)
0x00007fb9c8ef7459: movabs $0x7fb9c68bee38,%rcx ; {metadata({method} {0x00007fb9c68bee38} 'hashCode' '()I' in 'java/lang/String')}
0x00007fb9c8ef7463: and $0xfff8,%r8d
0x00007fb9c8ef746a: cmp $0x0,%r8d
0x00007fb9c8ef746e: je 0x00007fb9c8ef74ed ; OopMap{rdi=Oop rsi=Oop off=308}
;*goto
; - java.lang.String::hashCode@45 (line 1470)
0x00007fb9c8ef7474: test %eax,0x1618fc86(%rip) # 0x00007fb9df087100
; {poll}
0x00007fb9c8ef747a: movabs $0x7fb9c6abf368,%rcx ; {metadata(method data for {method} {0x00007fb9c68bee38} 'hashCode' '()I' in 'java/lang/String')}
0x00007fb9c8ef7484: incl 0x168(%rcx) ;*goto
; - java.lang.String::hashCode@45 (line 1470)
0x00007fb9c8ef748a: cmp %ebx,%edx
0x00007fb9c8ef748c: movabs $0x7fb9c6abf368,%rcx ; {metadata(method data for {method} {0x00007fb9c68bee38} 'hashCode' '()I' in 'java/lang/String')}
0x00007fb9c8ef7496: movabs $0x148,%r8
0x00007fb9c8ef74a0: jge 0x00007fb9c8ef74b0
0x00007fb9c8ef74a6: movabs $0x158,%r8
0x00007fb9c8ef74b0: mov (%rcx,%r8,1),%r9
0x00007fb9c8ef74b4: lea 0x1(%r9),%r9
0x00007fb9c8ef74b8: mov %r9,(%rcx,%r8,1)
0x00007fb9c8ef74bc: jl 0x00007fb9c8ef7428 ;*if_icmpge
; - java.lang.String::hashCode@30 (line 1470)
0x00007fb9c8ef74c2: mov %eax,0x10(%rsi) ;*putfield hash
; - java.lang.String::hashCode@50 (line 1473)
0x00007fb9c8ef74c5: add $0x30,%rsp
0x00007fb9c8ef74c9: pop %rbp
0x00007fb9c8ef74ca: test %eax,0x1618fc30(%rip) # 0x00007fb9df087100
; {poll_return}
0x00007fb9c8ef74d0: retq
0x00007fb9c8ef74d1: mov %rax,0x8(%rsp)
0x00007fb9c8ef74d6: movq $0xffffffffffffffff,(%rsp)
0x00007fb9c8ef74de: callq 0x00007fb9c8ef5ce0 ; OopMap{rsi=Oop off=419}
;*synchronization entry
; - java.lang.String::hashCode@-1 (line 1466)
; {runtime_call}
0x00007fb9c8ef74e3: jmpq 0x00007fb9c8ef739e
0x00007fb9c8ef74e8: callq 0x00007fb9c8ef1540 ; OopMap{rsi=Oop rdi=Oop off=429}
;*arraylength
; - java.lang.String::hashCode@13 (line 1467)
; {runtime_call}
0x00007fb9c8ef74ed: mov %rcx,0x8(%rsp)
0x00007fb9c8ef74f2: movq $0x2d,(%rsp)
0x00007fb9c8ef74fa: callq 0x00007fb9c8ef5ce0 ; OopMap{rdi=Oop rsi=Oop off=447}
;*goto
; - java.lang.String::hashCode@45 (line 1470)
; {runtime_call}
0x00007fb9c8ef74ff: jmpq 0x00007fb9c8ef7474
0x00007fb9c8ef7504: nop
0x00007fb9c8ef7505: nop
0x00007fb9c8ef7506: mov 0x388(%r15),%rax
0x00007fb9c8ef750d: movabs $0x0,%r10
0x00007fb9c8ef7517: mov %r10,0x388(%r15)
0x00007fb9c8ef751e: movabs $0x0,%r10
0x00007fb9c8ef7528: mov %r10,0x390(%r15)
0x00007fb9c8ef752f: add $0x30,%rsp
0x00007fb9c8ef7533: pop %rbp
0x00007fb9c8ef7534: jmpq 0x00007fb9c8e63fa0 ; {runtime_call}
0x00007fb9c8ef7539: hlt
0x00007fb9c8ef753a: hlt
0x00007fb9c8ef753b: hlt
0x00007fb9c8ef753c: hlt
0x00007fb9c8ef753d: hlt
0x00007fb9c8ef753e: hlt
0x00007fb9c8ef753f: hlt
3. 缺点 :日志太多,看的对不上
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++