在64位Windows上编译hsdis

来源:互联网 发布:日本失业率数据 编辑:程序博客网 时间:2024/05/16 08:23

背景

最近想学习下Hotspot的JIT,查找大量资料都说需要hsdis,但是又从哪都找不到windows64位的版本。
如果没有这个东西,直接运行代码,加上如下参数后
-XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly
会得到如下提示
Java HotSpot(TM) 64-Bit Server VM warning: PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output
Could not load hsdis-amd64.dll; library not loadable; PrintAssembly is disabled

。。。。。。
看来确实是需要hsdis-amd64.dll[下载]这个东西的。

动手

无意中翻到了一个网站:How to build hsdis-amd64.dll and hsdis-i386.dll on Windows
内容如下:

How to build hsdis-amd64.dll and hsdis-i386.dll on Windows

  1. Install Cygwin. At the Select Packages screen, add the following packages (by expanding the Devel category, then clicking once on the Skip label next to each package name):
    • make
    • mingw64-x86_64-gcc-core (only needed for hsdis-amd64.dll)
    • mingw64-i686-gcc-core (only needed for hsdis-i386.dll)
  2. Run the Cygwin Terminal. This can be done using the Desktop or Start Menu icon created by the installer, and will create your Cygwin home directory (C:\cygwin\home\username or C:\cygwin64\home\username, by default).
  3. Download the latest GNU binutils source package and extract its contents to your Cygwin home directory. At the time of writing, the latest package is binutils-2.24.tar.bz2. This should result in a directory named binutils-2.24 (or whatever the latest version is) in your Cygwin home directory.
  4. Download the OpenJDK source by going to the JDK 8 Updates repository, selecting the tag corresponding to your installed JRE version, and clicking bz2. Extract the hsdis directory (found in src\share\tools) to your Cygwin home directory.
  5. In the Cygwin Terminal, enter cd hsdis.
  6. To build hsdis-amd64.dll, enter make OS=Linux MINGW=x86_64-w64-mingw32 'AR=$(MINGW)-ar' BINUTILS=~/binutils-2.24. To build hsdis-i386.dll, enter make OS=Linux MINGW=i686-w64-mingw32 'AR=$(MINGW)-ar' BINUTILS=~/binutils-2.24. In either case, replace 2.24 with the binutils version you downloaded.

The DLL can now be installed by copying it from hsdis\build\Linux-amd64 or hsdis\build\Linux-i586 to your JRE’s bin\server or bin\client directory.

Note that binutils and OpenJDK use incompatible licenses. As I understand it, this means that it is legal to combine them for personal use, but not to distribute the result. Because of this, I cannot provide prebuilt DLLs.

Bonus tip: if you prefer Intel ASM syntax to AT&T, specify -XX:PrintAssemblyOptions=intel alongside any other PrintAssembly options you use.

大体上按照这个做完之后,最后执行make命令总是报错。
踩了不少坑,最后还是build出来了。
现在在上面引用内容的基础上进行完善,希望能帮助更多人

请参照下面的步骤

粗体的部分是在上文基础上更新的内容

  1. 准备
    • 下载Cygwin安装包(Windows 64位版本)
    • 下载GNU binutils
    • 下载OpenJDK源码
  2. 安装Cygwin
    • 镜像我使用的网易的,http://mirrors.163.com/,下载600KB/s,带宽高应该更快
    • Select Packages页面需要注意,在默认的基础上,需要额外安装的package有:
      • Devel - make
      • Devel - gcc-core
      • Devel - mingw64-x86_64-gcc-core
      • Devel - texinfo
      • Utils - diffutils
  3. 安装完之后启动Cygwin,则会在Cygwin的安装目录下的home下自动生成你的用户名命名的文件夹(下文记之为~
  4. 将下载的binutils解压到~
    .../home/用户名/binutils-2.27/
  5. 将下载的openJDK源码/src/share/tools/hsdis解压到~
    .../home/用户名/hsdis/
  6. 修改~/hsdis/Makefile文件,搜索LIBRARIES,将
    LIBRARIES = $(TARGET_DIR)/bfd/libbfd.a \
    $(TARGET_DIR)/opcodes/libopcodes.a \
    $(TARGET_DIR)/libiberty/libiberty.a

    修改为
    LIBRARIES = $(TARGET_DIR)/bfd/libbfd.a \
    $(TARGET_DIR)/zlib/libz.a \
    $(TARGET_DIR)/opcodes/libopcodes.a \
    $(TARGET_DIR)/libiberty/libiberty.a

    保存
  7. 在Cygwin窗口输入cd ~/hsdis,然后输入命令make OS=Linux MINGW=x86_64-w64-mingw32 'AR=$(MINGW)-ar' BINUTILS=~/binutils-2.27(最后的binutils路径需要与实际安装路径一致)
  8. 等待几分钟,如果最后没有报错,那么就build成功了,我们需要的hsdis-amd64.dll现在就在~/hsdis/build/Linux-amd64里面了,把它copy到$JAVA_HOME/jre/bin/server(或$JAVA_HOME/jre/bin/client)下就OK了。
0 0
原创粉丝点击