First, you need to download OpenJDK's source. Note that there is source in Fedora's binary repository but this is only the source of Jaba API packages. So, you have to download the real source, either from java.net or approriate SRPM. In both cases be careful to download source that matches OpenJDK you have installed on your machine.
Next, unpack the source and go to the directory openjdk/hotspot/src/share/tools/hsdis. Now, open hsdis.c file and replace the following line:
#include <sysdep.h>with the following lines:
#include <string.h>Now, compile the source using the following command:
#include <errno.h>
gcc -o hsdis-amd64.so -DLIBARCH_amd64 -DLIBARCH="amd64" \The compilation will fail unless you have binutils-devel package installed. So, take care about that. In case the compilation was successful you'll have hsdis-amd64.so file. It's a dynamic library. Note that I'm using 64 bit AMD/Intel architecture. If you are using 32 bit version replace amd64 with i386 and -m64 with -m32. In case of some other architecture you'll have to find out yourself what's the name.
-DLIB_EXT=".so" -m64 -fPIC -O hsdis.c -shared \
-ldl -lopcodes
Now, you'll need some Java class that you'll run and that will produce assembly output. The main point you should have in mind is that the code has to be such to provoke JIT to be started. Otherwise, you'll don't get any assembly output. I used the following simple class file:
import java.math.BigInteger;After compiling it, run it using the following command:
class Multiply
{
public static void main(String[] args)
{
BigInteger a = BigInteger.ONE;
for (int i = 0; i < 10000; i++)
a = a.multiply(BigInteger.valueOf(2));
System.out.println(a);
}
}
LD_LIBRARY_PATH=. java -XX:+UnlockDiagnosticVMOptions \Note that I'm using LD_LIBRARY_PATH to tell JIT where disassembler (hsdis) is. In my case everything is in the current directory. Note that in the previous command I specified that I want Intel assembly syntax. The default one is AT&T.
-XX:+PrintAssembly -XX:PrintAssemblyOptions=intel \
Multiply
1 comment:
Thanks for this, this was just what I was after.
I found it easier just to drop in the binutils source due to some library differences - i'm using an ancient fedora and newer slackware. I had to remove the -Werror from the bfs and opcodes Makefiles though since unused variables are apparently fatal now.
Post a Comment