JDK源码
linux jackie-MXC061 4.4.0-45-generic #66-Ubuntu SMP Wed Oct 19 14:12:05 UTC 2016 i686 i686 i686 GNU/Linux
Ubuntu版本 cat /proc/version
Linux version 4.4.0-45-generic (buildd@lgw01-19) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.2) ) #66-Ubuntu SMP Wed Oct 19 14:12:05 UTC 2016
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.1 LTS
Release: 16.04
Codename: xenial
编译器版本 gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-linux-gnu/5/lto-wrapper
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.4.0-6ubuntu1~16.04.4' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-i386/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-i386 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-i386 --with-arch-directory=i386 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-targets=all --enable-multiarch --disable-werror --with-arch-32=i686 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
Thread model: posix
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4)
Bootstrap JDK版本 java -version
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) Server VM (build 25.111-b14, mixed mode)
ANT的版本 ant -version
Apache Ant(TM) version 1.9.7 compiled on April 9 2016
编译脚本
ALT_BOOTDIR=$JAVA_HOME
export ALT_BOOTDIR
ALT_JDK_IMPORT_PATH=$JAVA_HOME
export ALT_JDK_IMPORT_PATH
ANT_HOME=$HOME/software/ant
export ANT_HOME
PATH=$JAVA_HOME/bin:$ANT_HOME/bin:$PATH
export PATH
HOTSPOT_BUILD_JOBS=5
export HOTSPOT_BUILD_JOBS
ALT_OUTPUTDIR=$HOME/workspace/openjdk8_build/hotspot_debug
export ALT_OUTPUTDIR
mkdir -p $ALT_OUTPUTDIR
rm -f $ALT_OUTPUTDIR/hotspot_debug.log
cd make
DEBUG_BINARIES=true make clean debug debug1 2>&1 | tee $ALT_OUTPUTDIR/hotspot_debug.log
编译过程中遇到的问题 编译目标的问题
Warning: The jvmg target has been replaced with debug
echo "Warning: Please update your usage"
Warning: Please update your usage
make BUILD_DIR=/home/jackie/workspace/openjdk8/hotspot/build/linux/linux_i486_compiler2 BUILD_FLAVOR=debug VM_TARGET=debug generic_build2
make[1]: Entering directory '/home/jackie/workspace/openjdk8/hotspot/make'
INFO: ENABLE_FULL_DEBUG_SYMBOLS=1
INFO: /usr/bin/objcopy cmd found so will create .debuginfo files.
INFO: STRIP_POLICY=min_strip
INFO: ZIP_DEBUGINFO_FILES=1
mkdir -p /home/jackie/workspace/openjdk8/hotspot/build/linux
cd /home/jackie/workspace/openjdk8/hotspot/build/linux; \
make -f /home/jackie/workspace/openjdk8/hotspot/make/linux/Makefile \
BOOTDIR=/usr/lib/jvm/java-8-oracle OUTPUTDIR=/home/jackie/workspace/openjdk8/hotspot/build/linux GAMMADIR=/home/jackie/workspace/openjdk8/hotspot MAKE_VERBOSE=y HOTSPOT_RELEASE_VERSION=25.0-b70 JRE_RELEASE_VERSION="1.8.0" HOTSPOT_BUILD_VERSION=internal debug
make[2]: Entering directory '/home/jackie/workspace/openjdk8/hotspot/build/linux'
INFO: ENABLE_FULL_DEBUG_SYMBOLS=1
INFO: /usr/bin/objcopy cmd found so will create .debuginfo files.
INFO: STRIP_POLICY=min_strip
INFO: ZIP_DEBUGINFO_FILES=1
make -f /home/jackie/workspace/openjdk8/hotspot/make/linux/Makefile checks
make[3]: Entering directory '/home/jackie/workspace/openjdk8/hotspot/build/linux'
INFO: ENABLE_FULL_DEBUG_SYMBOLS=1
INFO: /usr/bin/objcopy cmd found so will create .debuginfo files.
INFO: STRIP_POLICY=min_strip
INFO: ZIP_DEBUGINFO_FILES=1
>&2 echo "*** This OS is not supported:" `uname -a`; exit 1;
*** This OS is not supported: Linux jackie-MXC061 4.4.0-45-generic #66-Ubuntu SMP Wed Oct 19 14:12:05 UTC 2016 i686 i686 i686 GNU/Linux
/home/jackie/workspace/openjdk8/hotspot/make/linux/Makefile:234: recipe for target 'check_os_version' failed
make[3]: *** [check_os_version] Error 1
make[3]: Leaving directory '/home/jackie/workspace/openjdk8/hotspot/build/linux'
/home/jackie/workspace/openjdk8/hotspot/make/linux/Makefile:255: recipe for target 'linux_i486_compiler2/fastdebug' failed
make[2]: *** [linux_i486_compiler2/fastdebug] Error 2
make[2]: Leaving directory '/home/jackie/workspace/openjdk8/hotspot/build/linux'
Makefile:216: recipe for target 'generic_build2' failed
make[1]: *** [generic_build2] Error 2
make[1]: Leaving directory '/home/jackie/workspace/openjdk8/hotspot/make'
Makefile:167: recipe for target 'debug' failed
make: *** [debug] Error 2
高版本的gcc不再支持编译选项 stabs
cc1plus: all warnings being treated as errors
/home/jackie/workspace/openjdk8/hotspot/make/linux/makefiles/vm.make:295: recipe for target 'precompiled.hpp.gch' failed
make[4]: *** [precompiled.hpp.gch] Error 1
make[4]: Leaving directory '/home/jackie/workspace/openjdk8/hotspot/build/linux/linux_i486_compiler2/debug'
/home/jackie/workspace/openjdk8/hotspot/make/linux/makefiles/top.make:119: recipe for target 'the_vm' failed
make[3]: *** [the_vm] Error 2
make[3]: Leaving directory '/home/jackie/workspace/openjdk8/hotspot/build/linux/linux_i486_compiler2/debug'
/home/jackie/workspace/openjdk8/hotspot/make/linux/Makefile:289: recipe for target 'debug' failed
make[2]: *** [debug] Error 2
make[2]: Leaving directory '/home/jackie/workspace/openjdk8/hotspot/build/linux'
Makefile:216: recipe for target 'generic_build2' failed
make[1]: *** [generic_build2] Error 2
make[1]: Leaving directory '/home/jackie/workspace/openjdk8/hotspot/make'
Makefile:167: recipe for target 'debug' failed
make: *** [debug] Error 2
bootstrap class path未指定
warning: [options] bootstrap class path not set in conjunction with -source 1.6
BOOT_TARGET_CLASS_VERSION = 8
参考资料 HotSpot实战 Ubuntu 14.04 64 bit 编译 openjdk 7
版本为 openjdk-8-src-b132-03_mar_2014 。
编译环境 内核版本 uname -alinux jackie-MXC061 4.4.0-45-generic #66-Ubuntu SMP Wed Oct 19 14:12:05 UTC 2016 i686 i686 i686 GNU/Linux
Ubuntu版本 cat /proc/version
Linux version 4.4.0-45-generic (buildd@lgw01-19) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.2) ) #66-Ubuntu SMP Wed Oct 19 14:12:05 UTC 2016
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.1 LTS
Release: 16.04
Codename: xenial
编译器版本 gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-linux-gnu/5/lto-wrapper
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.4.0-6ubuntu1~16.04.4' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-i386/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-i386 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-i386 --with-arch-directory=i386 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-targets=all --enable-multiarch --disable-werror --with-arch-32=i686 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
Thread model: posix
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4)
Bootstrap JDK版本 java -version
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) Server VM (build 25.111-b14, mixed mode)
ANT的版本 ant -version
Apache Ant(TM) version 1.9.7 compiled on April 9 2016
编译脚本
在 /home/jackie/workspace/openjdk8/hotspot 下创建脚本 build_hotspot.sh ,内容如下:
#!/bin/shALT_BOOTDIR=$JAVA_HOME
export ALT_BOOTDIR
ALT_JDK_IMPORT_PATH=$JAVA_HOME
export ALT_JDK_IMPORT_PATH
ANT_HOME=$HOME/software/ant
export ANT_HOME
PATH=$JAVA_HOME/bin:$ANT_HOME/bin:$PATH
export PATH
HOTSPOT_BUILD_JOBS=5
export HOTSPOT_BUILD_JOBS
ALT_OUTPUTDIR=$HOME/workspace/openjdk8_build/hotspot_debug
export ALT_OUTPUTDIR
mkdir -p $ALT_OUTPUTDIR
rm -f $ALT_OUTPUTDIR/hotspot_debug.log
cd make
DEBUG_BINARIES=true make clean debug debug1 2>&1 | tee $ALT_OUTPUTDIR/hotspot_debug.log
编译过程中遇到的问题 编译目标的问题
编译日志如下
echo "Warning: The jvmg target has been replaced with debug"Warning: The jvmg target has been replaced with debug
echo "Warning: Please update your usage"
Warning: Please update your usage
解决方法,更新编译脚本,按照提示修改编译目标为 debug 和 debug1 。
内核版本的问题编译日志如下
cd /home/jackie/workspace/openjdk8/hotspot/make; \make BUILD_DIR=/home/jackie/workspace/openjdk8/hotspot/build/linux/linux_i486_compiler2 BUILD_FLAVOR=debug VM_TARGET=debug generic_build2
make[1]: Entering directory '/home/jackie/workspace/openjdk8/hotspot/make'
INFO: ENABLE_FULL_DEBUG_SYMBOLS=1
INFO: /usr/bin/objcopy cmd found so will create .debuginfo files.
INFO: STRIP_POLICY=min_strip
INFO: ZIP_DEBUGINFO_FILES=1
mkdir -p /home/jackie/workspace/openjdk8/hotspot/build/linux
cd /home/jackie/workspace/openjdk8/hotspot/build/linux; \
make -f /home/jackie/workspace/openjdk8/hotspot/make/linux/Makefile \
BOOTDIR=/usr/lib/jvm/java-8-oracle OUTPUTDIR=/home/jackie/workspace/openjdk8/hotspot/build/linux GAMMADIR=/home/jackie/workspace/openjdk8/hotspot MAKE_VERBOSE=y HOTSPOT_RELEASE_VERSION=25.0-b70 JRE_RELEASE_VERSION="1.8.0" HOTSPOT_BUILD_VERSION=internal debug
make[2]: Entering directory '/home/jackie/workspace/openjdk8/hotspot/build/linux'
INFO: ENABLE_FULL_DEBUG_SYMBOLS=1
INFO: /usr/bin/objcopy cmd found so will create .debuginfo files.
INFO: STRIP_POLICY=min_strip
INFO: ZIP_DEBUGINFO_FILES=1
make -f /home/jackie/workspace/openjdk8/hotspot/make/linux/Makefile checks
make[3]: Entering directory '/home/jackie/workspace/openjdk8/hotspot/build/linux'
INFO: ENABLE_FULL_DEBUG_SYMBOLS=1
INFO: /usr/bin/objcopy cmd found so will create .debuginfo files.
INFO: STRIP_POLICY=min_strip
INFO: ZIP_DEBUGINFO_FILES=1
>&2 echo "*** This OS is not supported:" `uname -a`; exit 1;
*** This OS is not supported: Linux jackie-MXC061 4.4.0-45-generic #66-Ubuntu SMP Wed Oct 19 14:12:05 UTC 2016 i686 i686 i686 GNU/Linux
/home/jackie/workspace/openjdk8/hotspot/make/linux/Makefile:234: recipe for target 'check_os_version' failed
make[3]: *** [check_os_version] Error 1
make[3]: Leaving directory '/home/jackie/workspace/openjdk8/hotspot/build/linux'
/home/jackie/workspace/openjdk8/hotspot/make/linux/Makefile:255: recipe for target 'linux_i486_compiler2/fastdebug' failed
make[2]: *** [linux_i486_compiler2/fastdebug] Error 2
make[2]: Leaving directory '/home/jackie/workspace/openjdk8/hotspot/build/linux'
Makefile:216: recipe for target 'generic_build2' failed
make[1]: *** [generic_build2] Error 2
make[1]: Leaving directory '/home/jackie/workspace/openjdk8/hotspot/make'
Makefile:167: recipe for target 'debug' failed
make: *** [debug] Error 2
解决方法
修改 make/linux/Makefile ,找到 SUPPORTED_OS_VERSION 变量定义的地方,在后面追加 4% ,如下所示
SUPPORTED_OS_VERSION = 2.4% 2.5% 2.6% 3% 4%高版本的gcc不再支持编译选项 stabs
编译日志如下
cc1plus: error: the "stabs" debug format cannot be used with pre-compiled headers [-Werror=deprecated]cc1plus: all warnings being treated as errors
/home/jackie/workspace/openjdk8/hotspot/make/linux/makefiles/vm.make:295: recipe for target 'precompiled.hpp.gch' failed
make[4]: *** [precompiled.hpp.gch] Error 1
make[4]: Leaving directory '/home/jackie/workspace/openjdk8/hotspot/build/linux/linux_i486_compiler2/debug'
/home/jackie/workspace/openjdk8/hotspot/make/linux/makefiles/top.make:119: recipe for target 'the_vm' failed
make[3]: *** [the_vm] Error 2
make[3]: Leaving directory '/home/jackie/workspace/openjdk8/hotspot/build/linux/linux_i486_compiler2/debug'
/home/jackie/workspace/openjdk8/hotspot/make/linux/Makefile:289: recipe for target 'debug' failed
make[2]: *** [debug] Error 2
make[2]: Leaving directory '/home/jackie/workspace/openjdk8/hotspot/build/linux'
Makefile:216: recipe for target 'generic_build2' failed
make[1]: *** [generic_build2] Error 2
make[1]: Leaving directory '/home/jackie/workspace/openjdk8/hotspot/make'
Makefile:167: recipe for target 'debug' failed
make: *** [debug] Error 2
解决方法
在执行 make 前增加变量 DEBUG_BINARIES=true ,如下
DEBUG_BINARIES=true make clean debug debug1 2>&1 | tee $ALT_OUTPUTDIR/hotspot_debug.logbootstrap class path未指定
编译日志如下
warning: [options] bootstrap class path not set in conjunction with -source 1.6warning: [options] bootstrap class path not set in conjunction with -source 1.6
解决方法
修改文件 make/linux/makefiles/rules.make ,找到变量 BOOT_SOURCE_LANGUAGE_VERSION 和 BOOT_TARGET_CLASS_VERSION ,将取值从6修改为8,如下
BOOT_SOURCE_LANGUAGE_VERSION = 8BOOT_TARGET_CLASS_VERSION = 8
参考资料 HotSpot实战 Ubuntu 14.04 64 bit 编译 openjdk 7