Openjdk编译记录
$ uname -a Linux zhuguowei 3.16.0-38-generic #52~14.04.1-Ubuntu SMP Fri May 8 09:43:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
openjdk-7u75-src-b13-18_dec_2014.zip
地址为:http://download.java.net/openjdk/jdk7u75/ri/
sudo apt-get install build-essential gawk m4 openjdk-6-jdk libasound2-dev libcups2-dev libxrender-dev xorg-dev xutils-dev x11proto-print-dev binutils libmotif3 libmotif-dev ant
#注: ${XXX}表示需修改为自己环境的路径. export LANG=C #启动JDK 需修改为当前系统已安装的jdk目录 毕竟jdk中的大部分类还是java写的,编译还得依赖已有的环境 export ALT_BOOTDIR=${JAVA_HOME} export ALLOW_DOWNLOADS=true #并行编译的线程数,设置为和CPU内核数量一致即可 export HOTSPOT_BUILD_JOBS=4 export ALT_PARALLEL_COMPILE_JOBS=4 export SKIP_COMPARE_IMAGES=true export USE_PRECOMPILED_HEADER=true export SKIP_FASTDEBUG_BUILD=false export DEBUG_NAME=fastdebug BUILD_DEPLOY=false BUILD_INSTALL=false #编译后的JDK输出目录 ${openjdk_install_path}为当前openjdk目录 export ALT_OUTPUTDIR=${openjdk_install_path}/build unset JAVA_HOME unset CLASSPATH make 2>&1 | tee $ALT_OUTPUTDIR/build.log
执行上述脚本, 遇到的问题:
Error: time is more than 10 years from present: 1104530400000 java.lang.RuntimeException: time is more than 10 years from present: 1104530400000 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) make[5]: *** [/home/zhuguowei/develop/openjdk/build/../build-fastdebug/lib/currency.data] Error 1
解决方法:
下载Openjdk8用同名文件(CurrencyData.properties)替换即可。
参考自:https://lists.freebsd.org/pipermail/freebsd-java/2014-December/011037.html
之后编译就非常顺利,成功编译结束后,会有如下的输出:
#-- Build times ---------- Target fastdebug_build Start 2015-05-28 21:28:50 End 2015-05-28 21:55:12 00:02:45 corba 00:09:58 hotspot 00:00:25 jaxp 00:00:28 jaxws 00:12:02 jdk 00:00:44 langtools 00:26:22 TOTAL -------------------------
进入生成的build的目录(或build-fastdebug目录), 再进入其中j2sdk-image目录,
$ cd build $ cd j2sdk-image $ ls ASSEMBLY_EXCEPTION bin demo hotspot.log include jre lib LICENSE man release sample src.zip THIRD_PARTY_README $ bin/java -version openjdk version "1.7.0-internal-fastdebug" OpenJDK Runtime Environment (build 1.7.0-internal-fastdebug-zhuguowei_2015_05_28_21_05-b00) OpenJDK 64-Bit Server VM (build 24.75-b04-fastdebug, mixed mode)
其他问题:
因电脑过热编译中途死机过一次 故需要注意cpu散热
若仅仅想编译hotspot的话, 进入openjdk中的hotspot目录, 其他准备工作同上, 但脚本需要做一些修改,如下所示:
export LANG=C export ALT_BOOTDIR=${JAVA_HOME} export ALLOW_DOWNLOADS=true export HOTSPOT_BUILD_JOBS=4 export ALT_PARALLEL_COMPILE_JOBS=4 export SKIP_COMPARE_IMAGES=true export USE_PRECOMPILED_HEADER=true export SKIP_FASTDEBUG_BUILD=false export DEBUG_NAME=fastdebug BUILD_DEPLOY=false BUILD_INSTALL=false export ALT_OUTPUTDIR=${openjdk_install_path}/hotspot/build unset JAVA_HOME unset CLASSPATH #针对64位操作系统 export ARCH_DATA_MODEL=64 cd make #make后面传递参数 jvmg jvmg1 make jvmg jvmg1 2>&1 | tee $ALT_OUTPUTDIR/build.log
执行上述脚本即可。校验编译是否成功:
$ cd build $ cd linux_amd64_compiler2 $ cd jvmg $ ./test_gamma Using java runtime at: /home/zhuguowei/develop/java/jdk1.7.0_60/jre java version "1.7.0_60" Java(TM) SE Runtime Environment (build 1.7.0_60-b19) OpenJDK 64-Bit Server VM (build 24.0-b56-internal-jvmg, mixed mode) 1. A1 B5 C8 D6 E3 F7 G2 H4 2. A1 B6 C8 D3 E7 F4 G2 H5 3. A1 B7 C4 D6 E8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 D1 E8 F5 G3 H6 83. A7 B2 C6 D3 E1 F4 G8 H5 84. A7 B3 C1 D6 E8 F5 G2 H4 85. A7 B3 C8 D2 E5 F1 G6 H4 86. A7 B4 C2 D5 E8 F1 G3 H6 87. A7 B4 C2 D8 E6 F1 G3 H5 88. A7 B5 C3 D1 E6 F8 G2 H4 89. A8 B2 C4 D1 E7 F5 G3 H6 90. A8 B2 C5 D3 E1 F7 G4 H6 91. A8 B3 C1 D6 E2 F5 G7 H4 92. A8 B4 C1 D3 E6 F2 G7 H5
补充:
刚开始编译时,遇到了如下错误
/usr/include/features.h:374:25: fatal error: sys/cdefs.h: No such file or directory # include <sys/cdefs.h>
但明明有该文件啊,如下所示:
$ locate cdefs.h /usr/include/x86_64-linux-gnu/sys/cdefs.h
解决方法:
编译脚本中添加
export ARCH_DATA_MODEL=64
因为Makefile中明确说道:
# Expected/optional make variables defined on make command line: # LP64=1 or ARCH_DATA_MODEL=64 for 64bit build
另外在make命令后传递参数“jvmg jvmg1”, 表示选择编译debug级别的目标。这样编译成功后,生成的libjvm库(Hotspot VM运行时库)中会包含丰富的调试信息,通过这些信息,调试器可以建立虚拟机运行时与源代码的关联,为单步调试Hotspot做好准备。(摘自HotSpot实战)