JAVA 프로그램의 어셈블리 코드를 보는 방법

JAVA 프로그램의 어셈블리 코드를 보는 방법


어셈블러를 보려면 가상 머신 파라미터가 필요합니다-XX:+UnlockDiagnosticVMOptions -XX:+PrintAssmbly실행 후 나타날 수 있습니다. Could not load hsdis-amd64.so; library not loadable; PrintAssembly is disabled 분명히 부족합니다. hsdis-amd64.so 이 라이브러리 (linux 아래)
솔루션: 필요한 라이브러리 소스 다운로드 주소:https://sourceforge.net/projects/fcml/files/fcml-1.1.3/
Linux: 1.소스 다운로드 및 압축 해제 2.대상 디렉토리로 전환 3../configure && make && sudo make install 4. cd example/hsdis && make && sudo make install 5. sudo ln -s /usr/local/lib/libhsdis.so /lib/amd64/hsdis-amd64.so 6. sudo ln -s /usr/local/lib/libhsdis.so /jre/lib/amd64/hsdis-amd64.so 다음 사용 가능
Windos 아래: 1.압축 파일을 다운로드하고 dll 파일을 추출합니다 2.Windos에서 JDK 디렉터리와 JRE 디렉터리java.dll를 검색하면 C:\Program Files\Java\jre1.8.0_45\bin\serverC:\Program Files\Java\jre1.8.0_45\jre\bin\server에 포함됩니다.검색된 디렉토리로 복사
최종 효과: 컴파일된 자바 코드
public class Test{
    public static void main(String[] args){
        System.out.println(1);
    }
}

표시된 어셈블리 코드:
Java HotSpot(TM) 64-Bit Server VM warning: PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output
Loaded disassembler from /var/software/java/jdk1.8.0_151/jre/lib/amd64/hsdis-amd64.so
Decoding compiled method 0x00007f56f9102150:
Code:
Argument 0 is unknown.RIP: 0x7f56f91022a0 Code size: 0x00000110
[Disassembling for mach='amd64']
[Entry Point]
[Constants]
  # {method} {0x00007f56f3211c38} 'getSnapshotTransformerList' '()[Lsun/instrument/TransformerManager$TransformerInfo;' in 'sun/instrument/TransformerManager'
  #           [sp+0x40]  (sp of caller)
  0x00007f56f91022a0: mov     0x8(%rsi),%r10d
  0x00007f56f91022a4: shl     $0x3,%r10
  0x00007f56f91022a8: cmp     %rax,%r10
  0x00007f56f91022ab: jne     0x7f56f9045e20    ;   {runtime_call}
  0x00007f56f91022b1: nopw    0x0(%rax,%rax)
  0x00007f56f91022bc: nop
[Verified Entry Point]
  0x00007f56f91022c0: mov     %eax,0xfffffffffffec000(%rsp)
  0x00007f56f91022c7: push    %rbp
  0x00007f56f91022c8: sub     $0x30,%rsp        ;*aload_0
                                                ; - sun.instrument.TransformerManager::getSnapshotTransformerList@0 (line 166)

  0x00007f56f91022cc: mov     0x10(%rsi),%eax
  0x00007f56f91022cf: shl     $0x3,%rax         ;*getfield mTransformerList
                                                ; - sun.instrument.TransformerManager::getSnapshotTransformerList@1 (line 166)

  0x00007f56f91022d3: add     $0x30,%rsp
  0x00007f56f91022d7: pop     %rbp
  0x00007f56f91022d8: test    %eax,0x16e0ee22(%rip)  ;   {poll_return}
  0x00007f56f91022de: retq
  0x00007f56f91022df: nop
  0x00007f56f91022e0: nop
  0x00007f56f91022e1: mov     0x2a8(%r15),%rax
  0x00007f56f91022e8: movabs  $0x0,%r10
  0x00007f56f91022f2: mov     %r10,0x2a8(%r15)
  0x00007f56f91022f9: movabs  $0x0,%r10
  0x00007f56f9102303: mov     %r10,0x2b0(%r15)
  0x00007f56f910230a: add     $0x30,%rsp
  0x00007f56f910230e: pop     %rbp
  0x00007f56f910230f: jmpq    0x7f56f906e2e0    ;   {runtime_call}
  0x00007f56f9102314: hlt
  0x00007f56f9102315: hlt
  0x00007f56f9102316: hlt
  0x00007f56f9102317: hlt
  0x00007f56f9102318: hlt
  0x00007f56f9102319: hlt
  0x00007f56f910231a: hlt
  0x00007f56f910231b: hlt
  0x00007f56f910231c: hlt
  0x00007f56f910231d: hlt
  0x00007f56f910231e: hlt
  0x00007f56f910231f: hlt
[Exception Handler]
[Stub Code]
  0x00007f56f9102320: callq   0x7f56f90fd660    ;   {no_reloc}
  0x00007f56f9102325: mov     %rsp,0xffffffffffffffd8(%rsp)
  0x00007f56f910232a: sub     $0x80,%rsp
  0x00007f56f9102331: mov     %rax,0x78(%rsp)
  0x00007f56f9102336: mov     %rcx,0x70(%rsp)
  0x00007f56f910233b: mov     %rdx,0x68(%rsp)
  0x00007f56f9102340: mov     %rbx,0x60(%rsp)
  0x00007f56f9102345: mov     %rbp,0x50(%rsp)
  0x00007f56f910234a: mov     %rsi,0x48(%rsp)
  0x00007f56f910234f: mov     %rdi,0x40(%rsp)
  0x00007f56f9102354: mov     %r8,0x38(%rsp)
  0x00007f56f9102359: mov     %r9,0x30(%rsp)
  0x00007f56f910235e: mov     %r10,0x28(%rsp)
  0x00007f56f9102363: mov     %r11,0x20(%rsp)
  0x00007f56f9102368: mov     %r12,0x18(%rsp)
  0x00007f56f910236d: mov     %r13,0x10(%rsp)
  0x00007f56f9102372: mov     %r14,0x8(%rsp)
  0x00007f56f9102377: mov     %r15,(%rsp)
  0x00007f56f910237b: movabs  $0x7f570ee0a316,%rdi  ;   {external_word}
  0x00007f56f9102385: movabs  $0x7f56f9102325,%rsi  ;   {internal_word}
  0x00007f56f910238f: mov     %rsp,%rdx
  0x00007f56f9102392: and     $0xfffffffffffffff0,%rsp
  0x00007f56f9102396: callq   0x7f570eb35d80    ;   {runtime_call}
  0x00007f56f910239b: hlt

내용 번역 전재, 원답:https://stackoverflow.com/questions/1503479/how-to-see-jit-compiled-code-in-jvm/24524285#24524285?newreg=de4f506929a54c10b77d7e9e1d1bb94e
내용이 너무 많으면 부분만 나와요. 시간이 지나도 관심 없을 때 많이 보고 많이 배워요.

좋은 웹페이지 즐겨찾기