Click to enter _ more _java thousand ask-basic use
1. How Java works by assembly
Java itself cannot be run by Assembly mode . However, we can use some plugins to interpret Java code as assembly instructions in the run, so that we can find some problems by analyzing the assembly instructions executed, or we can help us to analyze and understand how the JVM is interpreted and compiled (of course, the Java itself compiles and runs and compiles independently).
Printassembly is a running parameter of the JVM that allows us to obtain assembly instructions translated into Java code in the console print. Using printassembly requires some plug-in support, which is not directly provided by the JVM, and the Kenai Project provides the available plugins (download https://kenai.com/projects/base-hsdis/downloads). According to the different environment in the corresponding instruction set. I am a Mac system, so I downloaded the hsdis-amd64.dylib.
After download, you need to put Hsdis-amd64.dylib in $java_path/jre/lib/server/, with Libjvm.dylib directory.
We can then run our code by specifying the run parameters:
java -XX:+UnlockDiagnosticVMOptions -XX:+PrintAssemblyTestHsdis
Example:
publicclass TestHsdis { publicstaticvoidmain(String[] args) { System.out.println("1"); }}
The compile runtime joins-xx:+unlockdiagnosticvmoptions-xx:+printassembly with the following results:
Java HotSpot(TM) 64-Bit Server VM warning: PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output
Loaded disassembler from /Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/jre/lib/server/hsdis-amd64.dylib
Decoding compiled method 0x000000010b4fd710:
Code:
[Disassembling for mach=‘i386:x86-64‘]
[Entry Point]
[Constants]
# {method} {0x000000011f270fc8} ‘hashCode‘ ‘()I‘ in ‘java/lang/String‘
# [sp+0x40] (sp of caller)
0x000000010b4fd880: mov 0x8(%rsi),%r10d
0x000000010b4fd884: shl $0x3,%r10
0x000000010b4fd888: cmp %rax,%r10
0x000000010b4fd88b: jne 0x000000010b445e20 ; {runtime_call}
0x000000010b4fd891: data32 data32 nopw 0x0(%rax,%rax,1)
0x000000010b4fd89c: data32 data32 xchg %ax,%ax
....
2, printassembly is disabled what reason
When we join the parameter-xx:+unlockdiagnosticvmoptions-xx:+printassembly run, we may report the following error:
Java HotSpot(TM) 64-Bit Server VM warning: PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output
Could not load hsdis-amd64.dylib; library not loadable; PrintAssembly is disabled
The reason is that the corresponding HSDIS-AMD64 plugin is not placed in the specified path, causing the runtime to fail to load. We must put Hsdis-amd64.dylib in $java_path/jre/lib/server/, with Libjvm.dylib directory (Mac system, if Linux is placed in the same directory with libjvm.so).
Java thousand asked _02 basic use (015) _java How to run by Assembly mode