JVM 反汇编动态运行代码
Java HotSpot(TM) Server VM warning: PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output
CompilerOracle: dontinline *GenericClass.*
Could not load hsdis-i386.so; library not loadable; PrintAssembly is disabled
?
//尝试 输出动态的反汇编Code时 ,提示上面的错误。 没有hsdir这个可加载的反汇编的插件(an externally loadable disassembler plugin) 。
对该插件的阐述如下
开始编译 ,提供的编译很几种,查看Makefile文件或者README文件可知如下几种:
1, make all
2, make both
3, make demo
4, make clean
(不解释,阴文你懂的)
我选择make all 。
第一编译,得到一个 Warning : 提醒没有安装makeinfo。然后出现该死的Error
OK,安装makeinfo
? // sudo apt-get install makeinfo
?
第二次编译 得到如下错误

没有找到 sysdep.h文件 。
// 查找
find -name sysdep.h
//output
./build/binutils/bfd/sysdep.h
./build/binutils/binutils/sysdep.h
./build/binutils/ld/sysdep.h
./build/binutils/opcodes/sysdep.h
?
而上面错误提示中编译时 头文件查找路径是
?
第三次编译 ,通过。在 bulid/Linux-i586/目录下生成了 hsdis-i386.so
?
最后,安装.so文件了。方法有二 :
?
1, Copy? hsdis-i386.so 到 java虚拟机安装目录的 jre/lib/i386/client/ 或者 (或和) jre/lib/i386/server/ 下 (跟libjvm.so同一目录)。
?
2, 将 hsdis-i386.so 添加到 LD_LIBRARY_PATH 里。
?? vim ~/.bashrc
// 最后一行添加
import java.util.Random;public class TestC2BranchPrediction2 { public static void main(String[] args) { Random rand = new Random(); int count0 = 0; int count2 = 0; for (int i = 0; i < 10000000L; i++) { int state = rand.nextInt(10); switch (state) { case 0: if(20 >= count0) { conditionalBranch(state); count0++; } break; case 1: conditionalBranch(state); break; case 2: if(200 >= count2) { conditionalBranch(state); count2++; } break; } } } public static void conditionalBranch(int flag) { if (0 == flag) { marker("DO SOMETHING A"); } else if (1 == flag) { marker("DO SOMETHING B"); } else if (2 == flag) { marker("DO SOMETHING C"); } } public static void marker(String message) { try { message.intern(); } catch (Exception e) { } }}