Search code examples
androidcompiler-optimizationjitjvm-hotspotopenj9

How to view Android code after JIT optimization?


I hope you are well.

While programming, I came to wonder if my lazy (but pretty) code will eventually get optimized and I don't need to care about optimization or not. So I ran some searches and found out HotSpot or OpenJ9 are tools that I can use to compile java code into assembly and optimize it.

So I thought, if I turned my example.kt code into example.class and run HotSpot or J9 on this example.class, I could view optimized code.

I tried below, but it only produced an error code.

java -XX:+UnlockDiagnosticVMOptions -XX:CompileCommand=print, com.xxx.android.Example ~/Desktop/.../jarName.jar
Error: Could not find or load main class com.xxx.android.Example

If someone have tried before, could you please help me with finding a way to get optimized android code please? Thank you so much.


Solution

  • Hotspot and OpenJ9 will compile to assembly, the assembly code being assembly for the platform you are running them on, as your program is running, or beforehand. It will compile from class files to the native code on that platform.

    Since you cannot run Hotspot or J9 on Android, you cannot compile for Android this way.

    For Android, you use the Android ART compiler, which compiles in a multi-step process from class files to dex files and apk files outside the device, then on the Android device to native code.