跟踪 java 字节码流

2022-01-16 00:00:00 jvm java

我想查看它正在执行的 JVM 的当前(字节码)指令流.经过一番谷歌搜索,我发现 jvm 调试版本提供了 -XX:+TraceBytecodes 选项(参见 这里).但是,提到的热点 JVM 调试构建链接已失效,我无法在线找到调试构建:/

I would like to see the current (bytecode) instruction stream of the JVM it is executing. After some googleing, I found that the jvm debug build offers the -XX:+TraceBytecodesoption (see here). However, the mentioned link to the hotspot JVM debug build is dead and I could not find a debug build online :/

是否有另一种方法可以跟踪 jvm 字节码流,或者有人可以指出我正确的方向吗?我正在运行 64 位 ubuntu 16.04.

Is there another way to trace the jvm bytecode stream or can someone point me in the right direction? I'm running 64 bit ubuntu 16.04.

P.S:我知道,打印出完整的指令流会非常缓慢.不过,我是古玩

P.S: I know, its going to be painfully slow to print out the complete instruction stream. However, I am curios

推荐答案

-XX:+TraceBytecodes 选项正是您要找的.它在 HotSpot JVM 的调试版本中可用.您可以轻松地自己构建 JVM - 只是 HotSpot,甚至不是 JDK.

-XX:+TraceBytecodes option is exactly what are you looking for. It is available in debug builds of HotSpot JVM. You can easily build JVM yourself - just HotSpot, not even JDK.

  1. 从 OpenJDK 8 项目中克隆热点存储库

  1. Clone hotspot repository from OpenJDK 8 project

hg clone http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot

  • 构建 'fastdebug' JVM(假设 JDK 已安装在 /usr/java/jdk1.8.0_102)

    cd hotspot/make
    make ALT_BOOTDIR=/usr/java/jdk1.8.0_102 ARCH_DATA_MODEL=64 fastdebug
    

    您可以添加 HOTSPOT_BUILD_JOBS=N 以在 N 个并行进程中运行编译.

    You may add HOTSPOT_BUILD_JOBS=N to run compilation in N parallel processes.

    运行它

    export ALT_JAVA_HOME=/usr/java/jdk1.8.0_102
    ../build/linux/linux_amd64_compiler2/fastdebug/hotspot -XX:+TraceBytecodes MainClass
    

  • 相关文章