HSDIS

root@ubuntu:~/Downloads# ./jdk1.6.0_45/bin/java  -XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly -XX:+DebugNonSafepoints  HelloWorld
Hello OpenJDK
-1


root@ubuntu:~/Downloads# ./jdk1.6.0_45/bin/java  -XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly -XX:+DebugNonSafepoints  HelloWorld
Hello OpenJDK
-1

root@ubuntu:~/Downloads# ./jdk1.7.0_80/bin/java  -XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly -XX:+DebugNonSafepoints  HelloWorld
Hello OpenJDK
-1


root@ubuntu:~/Downloads# ./jdk1.8.0_20/bin/java  -XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly -XX:+DebugNonSafepoints  HelloWorld
Could not load [b]hsdis-amd64.so[/b]; library not loadable; PrintAssembly is disabled
Hello OpenJDK
-1


下载hsdis: https://kenai.com/projects/base-hsdis/downloads

linux-hsdis-amd64.so

改名为hsdis-amd64.so,放入/root/Downloads/jdk1.8.0_20/jre/lib/amd64/server

暂时只有JDK1.8有用,1.6和1.7都没生效,具体先不找原因(可能是要类似debug版本)。
---这里1.6和1.7不生效,应该是HOTSPOT的JIT导致的,我们增加参数-Xcomp,就可以了


root@ubuntu:~/Downloads# ./jdk1.8.0_20/bin/java  -XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly -XX:+DebugNonSafepoints  HelloWorld > disass.log


截取indexOf部分:
Decoding compiled method 0x00007fe4b8276810:
Code:
[Entry Point]
[Constants]
  # {method} {0x00007fe4b6316148} 'indexOf' '(II)I' in 'java/lang/String'
  # this:     rsi:rsi   = 'java/lang/String'
  # parm0:    rdx       = int
  # parm1:    rcx       = int
  #           [sp+0x40]  (sp of caller)
  0x00007fe4b82769a0: mov    0x8(%rsi),%r10d
  0x00007fe4b82769a4: shl    $0x3,%r10
  0x00007fe4b82769a8: cmp    %rax,%r10
  0x00007fe4b82769ab: jne    0x00007fe4b81b3b60  ;   {runtime_call}
  0x00007fe4b82769b1: nopw   0x0(%rax,%rax,1)
  0x00007fe4b82769bc: xchg   %ax,%ax
[Verified Entry Point]
  0x00007fe4b82769c0: mov    %eax,-0x14000(%rsp)
  0x00007fe4b82769c7: push   %rbp
  0x00007fe4b82769c8: sub    $0x30,%rsp
  0x00007fe4b82769cc: mov    $0x7fe4b64ff8b8,%rax  ;   {metadata(method data for {method} {0x00007fe4b6316148} 'indexOf' '(II)I' in 'java/lang/String')}


<截断>

关于hsdis,可以查看openjdk的文档:
../openjdk/hotspot/src/share/tools/hsdis/README

'hsdis':  A HotSpot plugin for disassembling dynamically generated code.

The files in this directory (Makefile, hsdis.[ch], hsdis-demo.c)
are built independently of the HotSpot JVM.

To use the plugin with a JVM, you need a new version that can load it.
If the product mode of your JVM does not accept -XX:+PrintAssembly,
you do not have a version that is new enough.



另外使用HSDB和SAPlugin都没有反汇编成功,后续再搞

你可能感兴趣的:(HSDIS)