##背景
最近想学习下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这个东西的。[下载]
20190515更新:
几年不见,下载积分从1分被系统涨到了44分,简直抢钱!我自己都改不了!所以又在度盘传了一份,大家自取 [链接] 密码deh4
##动手
无意中翻到了一个网站:How to build hsdis-amd64.dll and hsdis-i386.dll on Windows
内容如下:
How to build hsdis-amd64.dll and hsdis-i386.dll on Windows
- 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)
- 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
orC:\cygwin64\home\username
, by default).- 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.- 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.
- In the Cygwin Terminal, enter
cd hsdis
.- 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, entermake OS=Linux MINGW=i686-w64-mingw32 'AR=$(MINGW)-ar' BINUTILS=~/binutils-2.24
. In either case, replace2.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出来了。
现在在上面引用内容的基础上进行完善,希望能帮助更多人
##请参照下面的步骤
###粗体的部分是在上文基础上更新的内容
- 准备
- 下载Cygwin安装包(Windows 64位版本)
- 下载GNU binutils
- 下载OpenJDK源码
- 安装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
- 安装完之后启动Cygwin,则会在Cygwin的安装目录下的
home
下自动生成你的用户名命名的文件夹(下文记之为~
) - 将下载的binutils解压到
~
下
.../home/用户名/binutils-2.27/
- 将下载的openJDK源码/src/share/tools/hsdis解压到
~
下
.../home/用户名/hsdis/
- 修改
~/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
保存 - 在Cygwin窗口输入
cd ~/hsdis
,然后输入命令make OS=Linux MINGW=x86_64-w64-mingw32 'AR=$(MINGW)-ar' BINUTILS=~/binutils-2.27
(最后的binutils路径需要与实际安装路径一致) - 等待几分钟,如果最后没有报错,那么就build成功了,我们需要的
hsdis-amd64.dll
现在就在~/hsdis/build/Linux-amd64
里面了,把它copy到$JAVA_HOME/jre/bin/server
(或$JAVA_HOME/jre/bin/client
)下就OK了。