centos 6.9 編譯open jdk
學習《深入了解java虛擬機》,按照書上的步驟試著自己編譯了個jdk,耗時大半個下午,中間遇到不少問題,在這記錄下。
一、環境說明
linux 版本
[[email protected] openjdk_compile]# lsb_release -a LSB Version::base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch Distributor ID:CentOS Description:CentOS release 6.9 (Final) Release:6.9 Codename:Final
openjdk版本
openjdk-7u75-src-b13-18_dec_2014.zip
二、構建編譯環境
安裝必要工具包
[[email protected] openjdk_compile]# yum groupinstall "Development Tools"
[[email protected] openjdk_compile]# yum install ant
設置環境變量
unset JAVA_HOME unset CLASSPATH export LANG=C export ALT_BOOTDIR=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.141-1.b16.el7_3.x86_64 #允許自動下載依賴 export ALLOW_DOWNLOADS=true #並行編譯的線程數,設置為和cpu內核數量一致即可 export HOTSPOT_BUILD_JOBS=2 export ALT_PARALLEL_COMPIL_JOBS=2 #比較本次build出來的映像與先前版本的差異。這對我們來說沒有意義 #必須設置為false,否則sanity檢查會報缺少先前版本的JDK的映像的錯誤提示。 #如果已經設置dev或者DEV_ONLY=true,這個不顯示設置也行 export SKIP_COMPARE_IMAGES=true #使用預編譯頭文件,不加這個編譯會更慢一些 export USE_PRECOMPILED_HEADER=true #要編譯的內容 export BUILD_LANGTOOLS=true #export BUILD_JAXP=false #export BUILD_JAXWS=false #export BUILD_CORBA=false export BUILD_HOTSPOT=true export BUILD_JDK=true #要編譯的版本 #export SKIP_DEBUG_BUILD=false #export SKIP_FASTDEBUG_BUILD=true #export DEBUG_NAME=debug #把它設置為false,可以避開javaws和瀏覽器java插件之類的部分的build export BUILD_DEPLOY=false #把它設置為false就不會build出安裝包。因為安裝包有些奇怪的依賴 #但即便不build出安裝包也能得到完整的JDK映像,所以還是別build好了 export BUILD_INSTALL=false #編譯結果存放的路勁 export ALT_OUTPUTDIR=/root/openjdk_compile/build
切換到源代碼根路徑,執行make sanity,得到結果:
WARNING: LANG has been set to zh_CN.UTF-8, this can cause build failures. Try setting LANG to ‘C‘. ERROR: Your CLASSPATH environment variable is set. This will most likely cause the build to fail. Please unset it and start your build again. ERROR: Your JAVA_HOME environment variable is set. This will most likely cause the build to fail. Please unset it and start your build again. ERROR: You seem to not have installed ALSA 0.9.1 or higher. Please install ALSA (drivers and lib). You can download the source distribution from http://www.alsa-project.org or go to http://www.freshrpms.net/docs/alsa/ for precompiled RPM packages. ERROR: FreeType version 2.3.0 or higher is required. make[2]: 進入目錄“/root/openjdk_compile/openjdk/jdk/make/tools/freetypecheck” /bin/mkdir -p /root/openjdk_compile/openjdk/build/linux-amd64/btbins rm -f /root/openjdk_compile/openjdk/build/linux-amd64/btbins/freetype_versioncheck make[2]: 離開目錄“/root/openjdk_compile/openjdk/jdk/make/tools/freetypecheck” Failed to build freetypecheck. ERROR: You do not have access to valid Cups header files. Please check your access to /usr/include/cups/cups.h and/or check your value of ALT_CUPS_HEADERS_PATH, CUPS is frequently pre-installed on many systems, or may be downloaded from http://www.cups.org Exiting because of the above error(s). make: *** [post-sanity] 錯誤 1
分析:
1.設置環境變量方式有誤: 永久環境變量(屬於文件,比如profile以及home目錄下的),臨時環境變量(當前shell以及子線程),普通環境變量(當前shell)
解決:在當前shell執行相關export
2. FreeType 沒有安裝
解決:yum install freetype-devel
3. ALSA 沒有安裝(聲卡 應該沒什麽關系)
解決:sudo yum install alsa*
4:You do not have access to valid Cups header files.
解決:sudo yum install cups-devel.x86_64
二、開始編譯
執行命令:
make 2>&1 | tee $ALT_OUTPUTDIR/build.log
記錄下錯誤
錯誤1:
build-bootstrap-javac: [mkdir] Created dir: /root/openjdk_compile/build/langtools/build/bootstrap/gensrc [mkdir] Created dir: /root/openjdk_compile/build/langtools/build/bootstrap/classes [pcompile] Generating 7 resource files to /root/openjdk_compile/build/langtools/build/bootstrap/gensrc [copy] Copying 1 file to /root/openjdk_compile/build/langtools/build/bootstrap/gensrc [pcompile] Generating 1 resource files to /root/openjdk_compile/build/langtools/build/bootstrap/gensrc [javac] Compiling 298 source files to /root/openjdk_compile/build/langtools/build/bootstrap/classes [javac] /root/openjdk_compile/openjdk/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java:2182: warning: [overrides] Class Resolve.InapplicableSymbolsError.Candidate overrides equals, but neither it nor any superclass overrides hashCode method [javac] private class Candidate { [javac] ^ [javac] error: warnings found and -Werror specified [javac] 1 error [javac] 1 warning BUILD FAILED /root/openjdk_compile/openjdk/langtools/make/build.xml:452: The following error occurred while executing this line: /root/openjdk_compile/openjdk/langtools/make/build.xml:795: Compile failed; see the compiler error output for details.
解決方法:Bootstrap jdk版本換成jdk1.7
錯誤2:
/bin/ld: cannot find -lstdc++ collect2: error: ld returned 1 exit status ln: failed to access ‘libjvm.so.1‘: Too many levels of symbolic links /usr/bin/chcon: failed to get security context of ‘libjvm.so‘: Too many levels of symbolic links ERROR: Cannot chcon libjvm.so /usr/bin/objcopy --only-keep-debug libjvm.so libjvm.debuginfo /usr/bin/objcopy: Warning: could not locate ‘libjvm.so‘. reason: Too many levels of symbolic links make[6]: *** [libjvm.so] Error 1 make[6]: Leaving directory `/root/openjdk_compile/build/hotspot/outputdir/linux_amd64_compiler2/product‘ make[5]: *** [the_vm] Error 2 make[5]: Leaving directory `/root/openjdk_compile/build/hotspot/outputdir/linux_amd64_compiler2/product‘ make[4]: *** [product] Error 2 make[4]: Leaving directory `/root/openjdk_compile/build/hotspot/outputdir‘ make[3]: *** [generic_build2] Error 2 make[3]: Leaving directory `/root/openjdk_compile/openjdk/hotspot/make‘ make[2]: *** [product] Error 2 make[2]: Leaving directory `/root/openjdk_compile/openjdk/hotspot/make‘ make[1]: *** [hotspot-build] Error 2 make[1]: Leaving directory `/root/openjdk_compile/openjdk‘ make: *** [build_product_image] Error 2
解決方案:sudo yum install libstdc++-static.x86_64
錯誤3:
Linking vm... /usr/bin/objcopy --only-keep-debug libjvm.so libjvm.debuginfo /usr/bin/objcopy --add-gnu-debuglink=libjvm.debuginfo libjvm.so strip -g libjvm.so [ -f libjvm.debuginfo ] || ln -s libjvm.debuginfo libjvm.debuginfo zip -q -y libjvm.diz libjvm.debuginfo libjvm.debuginfo rm -f libjvm.debuginfo libjvm.debuginfo [ -f libjvm.diz ] || { ln -s libjvm.diz libjvm.diz; } echo Linking launcher... Linking launcher... gcc -m64 -Xlinker -O1 -Wl,--hash-style=both -Xlinker -z -Xlinker noexecstack -m64 -Xlinker -export-dynamic -L `pwd` -o gamma launcher/java_md.o launcher/jli_util.o launcher/wildcard.o launcher/java.o -ljvm -lm -ldl -lpthread make[6]: Leaving directory `/root/openjdk_compile/build/hotspot/outputdir/linux_amd64_compiler2/product‘ All done. make[5]: Leaving directory `/root/openjdk_compile/build/hotspot/outputdir/linux_amd64_compiler2/product‘ cd linux_amd64_compiler2/product && ./test_gamma ./gamma: relocation error: /usr/java/jdk1.7.0_80/jre/lib/amd64/libjava.so: symbol JVM_FindClassFromCaller, version SUNWprivate_1.1 not defined in file libjvm.so with link time reference make[4]: *** [product] Error 127 make[4]: Leaving directory `/root/openjdk_compile/build/hotspot/outputdir‘ make[3]: *** [generic_build2] Error 2 make[3]: Leaving directory `/root/openjdk_compile/openjdk/hotspot/make‘ make[2]: *** [product] Error 2 make[2]: Leaving directory `/root/openjdk_compile/openjdk/hotspot/make‘ make[1]: *** [hotspot-build] Error 2 make[1]: Leaving directory `/root/openjdk_compile/openjdk‘ make: *** [build_product_image] Error 2
解決方案:去掉hotspot/make/linux/Makefile 文件中所有的test_gamma即可
錯誤4:
/bin/mkdir -p /root/openjdk_compile/build/lib rm -f /root/openjdk_compile/build/lib/content-types.properties /bin/cp ../../../src/solaris/lib/content-types.properties /root/openjdk_compile/build/lib/content-types.properties /bin/mkdir -p /root/openjdk_compile/build/lib rm -f /root/openjdk_compile/build/lib/calendars.properties /bin/cp ../../../src/share/lib/calendars.properties /root/openjdk_compile/build/lib/calendars.properties rm -f /root/openjdk_compile/build/lib/currency.data /usr/java/jdk1.7.0_80/bin/java -XX:-PrintVMOptions -XX:+UnlockDiagnosticVMOptions -XX:-LogVMOutput -Xmx512m -Xms512m -XX:PermSize=32m -XX:MaxPermSize=160m -jar /root/openjdk_compile/build/btjars/generatecurrencydata.jar -o /root/openjdk_compile/build/lib/currency.data.temp < ../../../src/share/classes/java/util/CurrencyData.properties Error: time is more than 10 years from present: 1136059200000 java.lang.RuntimeException: time is more than 10 years from present: 1136059200000 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[4]: *** [/root/openjdk_compile/build/lib/currency.data] Error 1 make[4]: Leaving directory `/root/openjdk_compile/openjdk/jdk/make/java/java‘ make[3]: *** [all] Error 1 make[3]: Leaving directory `/root/openjdk_compile/openjdk/jdk/make/java‘ make[2]: *** [all] Error 1 make[2]: Leaving directory `/root/openjdk_compile/openjdk/jdk/make‘ make[1]: *** [jdk-build] Error 2 make[1]: Leaving directory `/root/openjdk_compile/openjdk‘ make: *** [build_product_image] Error 2
解決方案:修改/jdk/src/share/classes/java/util/CurrencyData.properties文件,將其中10年以前的時間都設置到10年以內
錯誤5:
/usr/bin/gcc -O2 -fno-strict-aliasing -fPIC -W -Wall -Wno-unused -Wno-parentheses -pipe -fno-omit-frame-pointer -D_LITTLE_ENDIAN -DNDEBUG -DARCH=‘"amd64"‘ -Damd64 -DLINUX -DRELEASE=‘"1.7.0-internal"‘ -DFULL_VERSION=‘"1.7.0-internal-root_2017_09_02_18_24-b00"‘ -DJDK_MAJOR_VERSION=‘"1"‘ -DJDK_MINOR_VERSION=‘"7"‘ -D_LARGEFILE64_SOURCE -D_GNU_SOURCE -D_REENTRANT -D_LP64=1 -I. -I/root/openjdk_compile/build/tmp/sun/launcher/policytool/CClassHeaders -I../../src/solaris/javavm/export -I../../src/share/javavm/export -I../../src/share/bin -I../../src/solaris/bin -I../../src/share/native/java/util/zip/zlib-1.1.3 -DMAIN_CLASS=‘"sun.security.tools.policytool.PolicyTool"‘ -DJAVA_ARGS=‘{ "-J-ms8m", "sun.security.tools.policytool.PolicyTool", }‘ -DLAUNCHER_NAME=‘"openjdk"‘ -DPROGNAME=‘"policytool"‘ -c -o /root/openjdk_compile/build/tmp/sun/launcher/policytool/obj64/main.o -DRELEASE=‘"1.7.0-internal"‘ -DFULL_VERSION=‘"1.7.0-internal-root_2017_09_02_18_24-b00"‘ -DJDK_MAJOR_VERSION=‘"1"‘ -DJDK_MINOR_VERSION=‘"7"‘ ../../src/share/bin/main.c Rebuilding /root/openjdk_compile/build/bin/policytool because of /root/openjdk_compile/build/tmp/sun/launcher/policytool/obj64/main.o /usr/bin/gcc -o /root/openjdk_compile/build/bin/policytool -Xlinker -O1 -Xlinker -version-script=../java/main/java/mapfile-amd64 -Wl,--hash-style=both -Xlinker -z -Xlinker defs -L/root/openjdk_compile/build/lib/amd64 -Wl,-soname=lib.so -L /root/openjdk_compile/build/lib/amd64/jli -Wl,--allow-shlib-undefined -Wl,-rpath -Wl,\$ORIGIN/../lib/amd64/jli -Wl,-rpath -Wl,\$ORIGIN/../jre/lib/amd64/jli /root/openjdk_compile/build/tmp/sun/launcher/policytool/obj64/main.o -lpthread -L/usr/X11R6//lib64 -lX11 -ljli -ldl -lc /bin/ld: cannot find -lX11 collect2: error: ld returned 1 exit status make[6]: *** [/root/openjdk_compile/build/bin/policytool] Error 1 make[6]: Leaving directory `/root/openjdk_compile/openjdk/jdk/make/launchers‘ make[5]: *** [build] Error 2 make[5]: Leaving directory `/root/openjdk_compile/openjdk/jdk/make/sun/security/tools‘ make[4]: *** [all] Error 1 make[4]: Leaving directory `/root/openjdk_compile/openjdk/jdk/make/sun/security‘ make[3]: *** [all] Error 1 make[3]: Leaving directory `/root/openjdk_compile/openjdk/jdk/make/sun‘ make[2]: *** [all] Error 1 make[2]: Leaving directory `/root/openjdk_compile/openjdk/jdk/make‘ make[1]: *** [jdk-build] Error 2 make[1]: Leaving directory `/root/openjdk_compile/openjdk‘ make: *** [build_product_image] Error 2
解決方案:缺少X11包,yun instal *X11*
錯誤6:
../../../src/solaris/native/sun/awt/awt.h:38:27: fatal error: X11/Intrinsic.h: No such file or directory #include <X11/Intrinsic.h>
解決方案啊:yum install libXt-devel
錯誤7
../../../src/solaris/native/sun/awt/splashscreen/splashscreen_config.h:33:34: fatal error: X11/extensions/shape.h: No such file or directory
解決方案啊:yum install libXtst-devel
錯誤8
../../../src/solaris/native/sun/awt/awt_p.h:51:36: fatal error: X11/extensions/Xrender.h: No such file or directory
解決方案:yum install libXrender-devel
編譯結果:
#-- Build times ---------- Target all_product_build Start 2017-09-02 20:39:54 End 2017-09-02 20:50:04 00:00:05 corba 00:00:08 hotspot 00:00:02 jaxp 00:00:04 jaxws 00:09:46 jdk 00:00:04 langtools 00:10:10 TOTAL ------------------------- make[1]: Leaving directory `/root/openjdk_compile/openjdk‘
[[email protected] bin]#./java -version openjdk version "1.7.0-internal" OpenJDK Runtime Environment (build 1.7.0-internal-root_2017_09_02_18_24-b00) OpenJDK 64-Bit Server VM (build 24.0-b56, mixed mode)
centos 6.9 編譯open jdk