Java 어셈블리 지침을 얻는 방법

Java 어셈블리 지침을 얻는 방법

이것에 협회 rustyx-XX:+PrintOptoAssemblyJava 바이트코드에 대한 어셈블리 지침을 얻기 위해 디버그 가상 머신과 다음 플래그를 사용했다고 언급했습니다.

디버그 가상 머신을 설치했습니다sudo apt-get install openjdk-17-dbg

나는 명령을 사용한다java -XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly Main

나는 gdb를 사용하여 C++에서 이 작업을 수행하는 데 익숙하지만 Java printAssembly에서는 작동하도록 할 수 없습니다. 아래 예제와 같이 명령의 16진수 값을 인쇄합니다. 실제 코드 함수나 의미 있는 기호 기호 없이 여러 번 반복됩니다.

abstract class Base {
    Base(){
        System.out.println("Base Constructor Called");
    }
    abstract void fun();
}
class Dervied extends Base {
    Dervied(){
        System.out.println("Dervied Constructor called");
    }
    void fun(){
        int x = 0;
        x = x + 1;
        System.out.println("Dervied fun() called " + x);
    }
}

class Main {
    public static void main(String args[]){
        Dervied d = new Dervied();
        d.fun();
    }
}

     32    1       3       java.lang.Object::<init> (1 bytes)

============================= C1-compiled nmethod ==============================
----------------------------------- Assembly -----------------------------------

Compiled method (c1)      32    1       3       java.lang.Object::<init> (1 bytes)
 total in heap  [0x00007fca25878010,0x00007fca25878320] = 784
 relocation     [0x00007fca25878170,0x00007fca258781a0] = 48
 main code      [0x00007fca258781a0,0x00007fca25878280] = 224
 stub code      [0x00007fca25878280,0x00007fca258782b0] = 48
 metadata       [0x00007fca258782b0,0x00007fca258782c0] = 16
 scopes data    [0x00007fca258782c0,0x00007fca258782d8] = 24
 scopes pcs     [0x00007fca258782d8,0x00007fca25878318] = 64
 dependencies   [0x00007fca25878318,0x00007fca25878320] = 8

[Constant Pool (empty)]

[MachCode]
[Entry Point]
  # {method} {0x0000000800448920} '<init>' '()V' in 'java/lang/Object'
  #           [sp+0x40]  (sp of caller)
  0x00007fca258781a0: 448b 5608 | 49bb 0000 | 0000 0800 | 0000 4d03 | d34c 3bd0 

  0x00007fca258781b4: ;   {runtime_call ic_miss_stub}
  0x00007fca258781b4: 0f85 c6a5 | abff 660f | 1f44 0000 
[Verified Entry Point]
  0x00007fca258781c0: 8984 2400 | c0fe ff55 | 4883 ec30 

  0x00007fca258781cc: ;   {metadata(method data for {method} {0x0000000800448920} '<init>' '()V' in 'java/lang/Object')}
  0x00007fca258781cc: 48bf 1888 | 801c ca7f | 0000 8b9f | f400 0000 | 83c3 0289 | 9ff4 0000 | 0081 e3fe | 0700 0083 
  0x00007fca258781ec: fb00 0f84 

  0x00007fca258781f0: ;*return {reexecute=0 rethrow=0 return_oop=0}
                      ; - java.lang.Object::<init>@0 (line 44)
  0x00007fca258781f0: 1300 0000 | 4883 c430 

  0x00007fca258781f8: ;   {poll_return}
  0x00007fca258781f8: 5d49 3ba7 | 4003 0000 | 0f87 1f00 

  0x00007fca25878204: ;   {metadata({method} {0x0000000800448920} '<init>' '()V' in 'java/lang/Object')}
  0x00007fca25878204: 0000 c349 | ba20 8944 | 0008 0000 | 004c 8954 | 2408 48c7 | 0424 ffff 

  0x00007fca2587821c: ;   {runtime_call counter_overflow Runtime1 stub}
  0x00007fca2587821c: ffff e8dd 

  0x00007fca25878220: ; ImmutableOopMap {rsi=Oop }
                      ;*synchronization entry
                      ; - java.lang.Object::<init>@-1 (line 44)
  0x00007fca25878220: 6ab6 ffeb 

  0x00007fca25878224: ;   {internal_word}
  0x00007fca25878224: cf49 baf9 | 8187 25ca | 7f00 004d | 8997 5803 

  0x00007fca25878234: ;   {runtime_call SafepointBlob}
  0x00007fca25878234: 0000 e9c5 | 0eac ff90 | 9049 8b87 | d003 0000 | 49c7 87d0 | 0300 0000 | 0000 0049 | c787 d803 
  0x00007fca25878254: 0000 0000 | 0000 4883 

  0x00007fca2587825c: ;   {runtime_call unwind_exception Runtime1 stub}
  0x00007fca2587825c: c430 5de9 | 9c01 b6ff | f4f4 f4f4 | f4f4 f4f4 | f4f4 f4f4 | f4f4 f4f4 | f4f4 f4f4 | f4f4 f4f4 
  0x00007fca2587827c: f4f4 f4f4 
[Exception Handler]
  0x00007fca25878280: ;   {no_reloc}
  0x00007fca25878280: e87b 31b6 

  0x00007fca25878284: ;   {external_word}
  0x00007fca25878284: ff48 bf6a | 7482 41ca | 7f00 0048 

  0x00007fca25878290: ;   {runtime_call}
  0x00007fca25878290: 83e4 f0e8 | 080a ae1b 

  0x00007fca25878298: ;   {section_word}
  0x00007fca25878298: f449 ba99 | 8287 25ca | 7f00 0041 

  0x00007fca258782a4: ;   {runtime_call DeoptimizationBlob}
  0x00007fca258782a4: 52e9 f600 | acff f4f4 | f4f4 f4f4 
[/MachCode]
     34    2       3       java.lang.String::hashCode (60 bytes)


답변1

를 사용하려면 +PrintAssembly디스어셈블러 플러그인이 필요합니다. Debian 또는 그 파생 제품을 사용하는 경우 를 설치하세요 libhsdis0-fcml.

이는 openjdk-17-dbg디버그 JDK가 아닙니다. 디버그 JDK입니다. 일반 JDK 디버깅 기호가 포함된 패키지입니다.

관련 정보