编译openjdk && 调试java

背景

一直很想深入了解java运行机制,想编译debug版本openjdk

实践

安装环境

安装vmware软件,第一步就遇到很多麻烦,找不到免费的vmware。

后来下载了官网的,在github和百度一直搜如何破解,幸亏有大佬传了比较全的破解方式。

破解地址

准备安装操作系统,本人选择centos7,刚上来发现可以通过debug-install命令安装调试信息,心想着这样都不用自己编译了,但发现调试版本和github上版本不对套。而且jdk安装版本和debug信息版本还不对套。

编译openjdk

第一次编没经验,为了少走弯路,网上搜一大堆方法。包括以前都一直有看,没去实践,印象里要装低版本JDK,然后configure各种入参,坑爹很。此次搜索发现centos有点简单,都不敢相信。

yum install hg
hg clone http://hg.openjdk.java.net/jdk8u/jdk8u openjdk8
#进入opnjdk8文件夹//执行如下命令拉取源码
sh get_source.sh  //可能要多次执行,因为代码一次无法全部拉取下来。 会在编译时出问题

编译配置

chmod +x configure
./configure --enable-debug

参考链接:

手动编译jdk1.8源码-centos7_java1.8版本怎么编译-CSDN博客

https://www.cnblogs.com/liudaihuablogs/p/13462731.html

Centos7编译openjdk8 - 简书

JVM之CentOS7编译openjdk1.7 - 简书

遇到问题

1、configure会提示各种未安装软件,按照提示来就好了,或者直接按照参考链接里一股脑儿装。

2、编译JDK失败,编译java等源码都未报错。

报错解决:

Generating Nimbus source files
[Error] encoded value was less than 0: encode(-8.326673E-17, 5.0, 11.0, 16.0)
[Error] encoded value was less than 0: encode(-0.05882353, 1.0, 24.0, 25.0)
[Error] encoded value was greater than 3: encode(15.029411, 1.0, 14.0, 15.0)
[Error] encoded value was less than 0: encode(-0.05882353, 1.0, 24.0, 25.0)
[Error] encoded value was greater than 3: encode(15.029411, 1.0, 14.0, 15.0)
[Error] encoded value was less than 0: encode(-0.05882353, 1.0, 24.0, 25.0)
[Error] encoded value was less than 0: encode(-0.05882353, 1.0, 24.0, 25.0)
[Error] encoded value was greater than 3: encode(15.029411, 1.0, 14.0, 15.0)
[Error] encoded value was less than 0: encode(-0.05882353, 1.0, 24.0, 25.0)
[Error] encoded value was greater than 3: encode(15.029411, 1.0, 14.0, 15.0)
[Error] encoded value was less than 0: encode(-0.05882353, 1.0, 24.0, 25.0)
[Error] encoded value was less than 0: encode(-0.05882353, 1.0, 24.0, 25.0)
[Error] encoded value was greater than 3: encode(15.029411, 1.0, 14.0, 15.0)
[Error] encoded value was less than 0: encode(-0.05882353, 1.0, 24.0, 25.0)
[Error] encoded value was greater than 3: encode(15.029411, 1.0, 14.0, 15.0)
[Error] encoded value was less than 0: encode(-0.05882353, 1.0, 24.0, 25.0)
[Error] Encountered Infinity: encode(-0.00877193, 0.0, 7.0, 7.0)
Compiling 4 files for BUILD_BREAKITERATOR
Generating HTML DTD file
[Parsed DTD html32 in 34ms]
Error: time is more than 10 years from present: 1388527200000
java.lang.RuntimeException: time is more than 10 years from present: 1388527200000
        at build.tools.generatecurrencydata.GenerateCurrencyData.makeSpecialCaseEntry(GenerateCurrencyData.java:285)
        at build.tools.generatecurrencydata.GenerateCurrencyData.buildMainAndSpecialCaseTables(GenerateCurrencyData.java:225)
        at build.tools.generatecurrencydata.GenerateCurrencyData.main(GenerateCurrencyData.java:154)
gmake[2]: *** [/root/openjdk8/build/linux-x86_64-normal-server-fastdebug/jdk/lib/currency.data] Error 1
gmake[1]: *** [gendata-only] Error 2

通过find 下 GenerateCurrencyData,再找到方法就好了,本人也是事先了搜了下代码仓发现抱错代码如下

只要把上述10年改成100年就好了。省得还网上改各种配置,使得时间time减去当前时间小于10年。

最终成果

编译成功,辛亏之前编译过的步骤不会重新再跑一遍,那就坑了!

是debug版本