好气啊 文章内容怎么不见了
____________________________________________________________________
再来过。。。
根据《深入理解java虚拟机》一书学习。
首先是获取openjdk7的源码,https://jdk7.java.net/source.html 在这个网页下载相应的源码
编译源码所需要的工具有gcc ant jdk所需要的依赖安装sudo apt-get install build-essential gawk m4 libasound2-dev libcups2-dev libxrender-dev xorg-dev xutils-dev x11proto-print-dev binutils libmotif3(根据提示选择替换安装) libmotif-dev ant
下面是根据书上的shell脚本
#!/bin/sh
export LANG=C
export ALT_BOOTDIR=/usr/jdk1.7.0_76#根据自己jdk的位置设置
export ALLOW_DOWNLOADS=true
export ALT_PARALLEL_COMPILE_JOBS=6
export SKIP_COMPARE_IMAGES=true
export USE_PRECOMPILED_HEADER=true
#export BUILD_LANGTOOLS=true
#export BUILD_JAXP=false
#export BUILD_CORBA=false
export BUILD_HOTSPOT=true
export BUILD_JDK=true
BUILD_DEPLOY=false
BUILD_INSTALL=false
export ALT_OUTPUTDIR=/home/xxx/Desktop#这里我是将生成的文件直接放到可桌面
unset JAVA_HOME
unset CLASSPATH
make 2>&1 | tee $ALT_OUTPUTDIR/build.log
假设脚本文件名为build.sh,将文件放在openjdk源码文件夹下,再执行./build.sh
脚本首先会检查配置,如果通过就会开始编译。
下面讲三个编译中会遇到的问题:
首先会有个
echo "*** This OS is not supported:" `uname -a`; exit 1;
这个错误是openjdk/hotspot/linux/Makefile中的代码执行报错,找到这行注释掉就可以了
接着会有
echo "**NOTICE** Dtrace support disabled: "/usr/include/sys/sdt.h not found""
**NOTICE** Dtrace support disabled: /usr/include/sys/sdt.h not found
make[6]: Leaving directory '/home/xxx/Desktop/hotspot/outputdir/linux_amd64_compiler2/product'
All done.
make[5]: Leaving directory '/home/xxx/Desktop/hotspot/outputdir/linux_amd64_compiler2/product'
cd linux_amd64_compiler2/product && ./test_gamma
./gamma: relocation error: /usr/jdk1.7.0_76/jre/lib/amd64/libjava.so: symbol JVM_FindClassFromCaller, version SUNWprivate_1.1 not defined in file libjvm.so with link time reference
/home/xxx/Desktop/openjdk/hotspot/make/linux/Makefile:300: recipe for target 'product' failed
make[4]: *** [product] Error 127
make[4]: Leaving directory '/home/xxx/Desktop/hotspot/outputdir'
Makefile:191: recipe for target 'generic_build2' failed
make[3]: *** [generic_build2] Error 2
make[3]: Leaving directory '/home/xxx/Desktop/openjdk/hotspot/make'
Makefile:151: recipe for target 'product' failed
make[2]: *** [product] Error 2
make[2]: Leaving directory '/home/xxx/Desktop/openjdk/hotspot/make'
make/hotspot-rules.gmk:111: recipe for target 'hotspot-build' failed
make[1]: *** [hotspot-build] Error 2
make[1]: Leaving directory '/home/xxx/Desktop/openjdk'
Makefile:251: recipe for target 'build_product_image' failed
make: *** [build_product_image] Error 2
解决这个错误可以进入openjdk/hotspot/make/linux 将Makefile文件中的包含test_gamma的行全部注释掉
最后的错误是
Error: time is more than 10 years from present: 1136059200000
通过修改openjdk/jdk/src/share/classes/java/util/CurrencyData.properties文件中的所有的时间年改为2014就可以了
上面的错误只是必然会遇到的,编译中肯定还会有其他的错误,其他的错误比如内存溢出可能与机器环境有关,将虚拟机的内存给大一点,还有的错误可能重新编译一下又不会遇到。
最后给出正确编译后显示的界面
#-- Build times ----------
Target all_product_build
Start 2017-03-02 17:12:22
End 2017-03-02 17:21:36
00:00:11 corba
00:00:19 hotspot
00:00:05 jaxp
00:00:07 jaxws
00:08:23 jdk
00:00:09 langtools
00:09:14 TOTAL
生成的jdk在j2sdk-image中可以自己配置环境变量使用
openjdk version "1.7.0-internal"
OpenJDK Runtime Environment (build 1.7.0-internal-xxx_2017_03_02_04_32-b00)
OpenJDK 64-Bit Server VM (build 24.0-b56, mixed mode)