下载源码
非官方 切换到jdk8u分支
https://github.com/unofficial-openjdk/openjdk.git
编译
编译jdk需要一个引导jdk, 引导jdk版本需要比编译版本小一个版本或等于当前版本
命令行运行
代码语言:javascript复制sh configure --with-debug-level=slowdebug --enable-debug-symbols --disable-zip-debug-info --with-boot-jdk=/usr/local/java
若报缺少依赖
代码语言:javascript复制configure: error: Could not find freetype! You might be able to fix this by running 'sudo apt-get install libfreetype6-dev'.
则需要对应安装
注意 sudo apt-get install libX11-dev
实际为sudo apt-get install libx11-dev
然后
代码语言:shell复制sudo bear make all
因为openjdk是make编译的,Clion对Cmake构建的项目比较友好,使用Make构建的项目,CLion仍然可以通过Compilation Database来导入项目。因此使用bear工具生成Compilation Database
若报错
代码语言:javascript复制*** This OS is not supported: Linux ubuntu ****
gmake[5]: *** [****/openjdk/hotspot/make/linux/Makefile:242:check_os_version] 错误 1
修改/openjdk/hotspot/make/linux/Makefile
line:236插入DISABLE_HOTSPOT_OS_VERSION_CHECK=ok
cc1plus: all warnings being treated as errors
修改****/openjdk/hotspot/make/linux/makefiles/gcc.make
, 注释掉这行
WARNINGS_ARE_ERRORS = -Werror
出现这个, 编译成功
代码语言:javascript复制## Finished jdk (build time 00:02:00)
----- Build times -------
Start 2022-08-05 13:52:55
End 2022-08-05 13:58:12
00:00:17 corba
00:02:21 hotspot
00:00:09 jaxp
00:00:15 jaxws
00:02:00 jdk
00:00:15 langtools
00:05:17 TOTAL
-------------------------
Finished building OpenJDK for target 'default'
验证
./build/linux-x86_64-normal-server-slowdebug/jdk/bin/java -version
openjdk version "1.8.0-internal-debug"
OpenJDK Runtime Environment (build 1.8.0-internal-debug-***)
OpenJDK 64-Bit Server VM (build 25.71-b00-debug, mixed mode)
调试
用clion打开项目目录下的compile_commands.json, Open As Project
Settings->Build->Custom Build Targets->见图
保存
启动按钮的旁边 , 点击 Add Configurations
添加 Custom Build Application
Target
设置为刚才设置的debug
Executable
设置为编译openjdk中的bin目录下的java
Program directory
设置为-version
,以作测试
若debug报错
则在用户目录下创建.gdbinit
, 内容如下
handle SIGSEGV pass noprint nostop
handle SIGBUS pass noprint nostop
打开/openjdk/jdk/src/share/bin/main.c
在main方法设置断点, debug启动项目
断点挂住
成功