【JDK编译】Centos7编译OpenJDK7

前段时间自己在linux下编译了一次openJDK,编译过程遇到很多问题,下次把编译过程和遇到的问题记录下来。


1.安装编译所使用的库
yum list build-essential gawk m4 libasound2-dev libcups2-dev libxrender-dev xorg-dev xutils-dev x11proto-print-dev binutils libmotif3 libmotif-dev ant libxt-dev libxtst-dev
yum install alsa-lib-devel cups-devel libXi-devel gcc gcc-c++ libX*
2.安装FreeType
wget https://sourceforge.net/projects/freetype/files/freetype2/2.7.1/freetype-2.7.1.tar.bz2
tar -xvf freetype-2.7.1.tar.bz2 
cd freetype-2.7.1/
./configure
make
make install
3.安装Ant,版本需要和Boot_JDK对应
wget http://archive.apache.org/dist/ant/binaries/apache-ant-1.7.1-bin.zip
unzip apache-ant-1.7.1-bin.zip 
mv apache-ant-1.7.1 ant
cd ant
ln -s /data/jdk/ant/bin/ant /usr/bin/ant
ll /usr/bin/ant


4.安装Boot_JDK,解压后使用
tar -xvf jdk-7u80-linux-x64.tar 
mv jdk1.7.0_80/ jdk8 
5.配置编译使用的环境变量
unset CLASSPATH
unset JAVA_HOME
export LANG=C
export ALT_BOOTDIR=/data/jdk/jdk8
export ANT_HOME=/data/jdk/ant
export ALT_FREETYPE_LIB_PATH=/usr/local/lib
export SKIP_DEBUG_BUILD=false
export SKIP_FASTDEBUG_BUILD=true
export DEBUG_NAME=debug
export ALT_FREETYPE_HEADERS_PATH=/usr/local/include/freetype2
export ALT_JDK_IMPORT_PATH=/data/jdk/jdk8
make sanity
6.下载需编译的Open_JDK源码
wget http://www.java.net/download/openjdk/jdk7u6/promoted/b24/openjdk-7u6-fcs-src-b24-28_aug_2012.zip
unzip openjdk-7u6-fcs-src-b24-28_aug_2012.zip
7.开始编译,需加上后面的参数,在没有的代码时下载,否则会出现ERROR: Cannot find source for project jaxp错误
原因是现在jaxp源码分支和jdk源码分支分开了,但是jaxws是jdk中的一部分,所以完全编译需要jaxp源码,针对该问题的描述可以查看README-build.html中TroubleShooting部分。 解决方式有两种: 一种是先下载好源码包,以drops的方式安装,具体参考README-build.html 另外一种是使用在线安装,在编译时加入允许下载源码的配置
make all ALLOW_DOWNLOADS=true


编译过程中的异常及解决
1.编译HotSpot时出现Linux内核版本问题
cd hotspot/make
cat Makefile | grep SUPPORTED_OS_VERSION
vi Makefile


2.出现ERROR: Cannot find source for project jaxp
http://blog.csdn.net/white_eyes/article/details/6259607
http://www.tuicool.com/articles/iIRr2e
make all ALLOW_DOWNLOADS=true


3.出现gnu/stubs-32.h: No such file or directory # include
#yum install g++-multilib
#yum install glib-devel
#yum install g++-multilib
#yum install *multilib
#yum install g++*
#yum -y install glibc-devel
yum install glibc-devel.i686
https://www.cyberciti.biz/faq/debian-ubuntu-linux-gnustubs-32-h-no-such-file-or-directory/
https://www.douban.com/note/543322671/


4.出现Linking vm... /usr/bin/ld: cannot find -lstdc++
yum search libc++ 
yum install libstdc++-static
http://blog.csdn.net/zitong_ccnu/article/details/50149757


5.gcc: error: unrecognized command line option '-mimpure-text'
解决办法:gcc版本问题,这个命令在本机所用的4.7.2版的gcc中已经去除,既然不能降低gcc版本(本机ubuntu12.10内核用4.7.2版gcc编译),那就在 【解压缩目录】/make/common/shared/Compiler-gcc.gmk 中去掉 -mimpure-text 命令
cd jdk/make/common/shared
cat Compiler-gcc.gmk | grep mimpure-text
vi Compiler-gcc.gmk 
http://blog.csdn.net/rongyongfeikai2/article/details/51137533
6../gamma: relocation error: /usr/Java/jdk1.7.0_76/jre/lib/amd64/libjava.so
cd hotspot/make/linux
cat Makefile | grep test_gam
vi Makefile  
解决方法:删除hotspot/make/Linux/MakeFile中所有的test_gamma
http://blog.csdn.net/zitong_ccnu/article/details/50149757




7.Error: time is more than 10 years from present: 1136059200000
cd jdk/src/share/classes/java/util
vi CurrencyData.properties
http://blog.csdn.net/abountwinter/article/details/52369507
http://www.thinksaas.cn/topics/0/399/399997.html


8.error:"__LEAF"redefined [-Werror]
JDK版本问题,在网上提供的版本库中已找不到对应的地址,解决办法就是使用其它的JDK版本,我编译成功的7U6不会出现这个问题,而页面上下载的b147版本就会出现这个问题,应该是在后面的版本解决了。
http://blog.csdn.net/dongdong9223/article/details/39228749
http://cduym.iteye.com/blog/1892416
最新办法解决:修改/hotspot/src/share/vm/runtime/interfaceSupport.hpp文件,在#define __LEAF(result_type,header)前面增加一个"#undef __LEAF"解决冲突。
解决办法来自:HotSpot实战
网上找的相同解决办法地址:http://blog.csdn.net/my_computer/article/details/37879469




9.另外在编译的时候出现一些类找不到的问题,怀疑是BootstrapJDK版本问题,最开始使用的是jdk8,后面使用的JDK6都出现过,使用jdk-7u80没有出现过,还有可能是和开始编译时问题多的原因造成的。
如出现No rule to make target linux-amd64-debug/corba/classes/org/omg/PortableServer/AdapterActivator.class,needed by org.omg.PortableServer/.classes.list这种问题应该是使用jdk6出现的问题
出现langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java 和Could not find class file for 'java.net.InetAddressImplFactory'可能和使用的JDK8有关系


10.Value of JDK_IMPORT_PATH cannot be empty, check or set ALT_JDK_IMPORT_PATH
出现这个的原因是少配置了ALT_JDK_IMPORT_PATH
export ALT_JDK_IMPORT_PATH=/data/jdk/jdk8
http://sky198.iteye.com/blog/1552648




第二次编译了b147版本遇到的问题:
1.__LEAF
解决办法:同上面第8项解决办法
在interfaceSupport.hpp增加 #ifdef __LEAF #undef __LEAF #define __LEAF(result_type, header)
出处:http://blog.csdn.net/my_computer/article/details/37879469




2./data/jdk/openjdk7/hotspot/src/share/vm/oops/constantPoolOop.cpp:272:39: error: converting 'false' to pointer type 'methodOop' [-Werror=conversion-null]
解决办法:修改/openjdk/hotspot/src/share/vm/oops/constantPoolOop.cpp 第272行 return false改为return (methodOop)false; 或者 return NULL;
出处:http://blog.163.com/xiangfei209@126/blog/static/986956742014317802435/


3./data/jdk/openjdk7/hotspot/src/share/vm/opto/loopnode.cpp:896:49: error: converting 'fals' to pointer type 'Node*' [-Werror=conversion-null]
解决办法:修改openjdk/hotspot/src/share/vm/opto/loopnode.cpp: 第896行 return false改为return (Node*)false; 或者 return NULL;
出处:http://blog.163.com/xiangfei209@126/blog/static/986956742014317802435/


4.Unable to load native library: /home/mengxiansen/program/Java/jdk1.7.0_10/jre/lib/amd64/libjava.so: symbol JVM_SetNativeThreadName, version SUNWprivate_1.1 not defined in file libjvm.so with link time reference
解决办法:使用Oracle的jdk6代替jdk7编译openjdk
出处:http://blog.csdn.net/my_computer/article/details/37879469 


运行test_gamma前先设置环境变量
export LD_LIBRARY_PATH=/data/jdk/openjdk/build/linux-amd64-debug/hotspot/outputdir/linux_amd64_compiler2/jvmg
export JAVA_HOME=/data/jdk/openjdk/build/linux-amd64-debug/j2sdk-image
出处:http://www.reader8.cn/jiaocheng/20140313/2270624.html


运行虚拟机
在编译结束之后、运行虚拟机之前,还要手工编辑目录下的env.sh文件,这个文件由编译脚本自动产生,用于设置虚拟机的环境变量,里面已经发布了“JAVA_HOME、CLASSPATH、HOTSPOT_BUILD_USER”3个环境变量,还需要增加一个“LD_LIBRARY_PATH”,内容如下:
LD_LIBRARY_PATH=.:${JAVA_HOME}/jre/lib/amd64/native_threads:${JAVA_HOME}/jre/lib/amd64:
export LD_LIBRARY_PATH
http://www.cnblogs.com/wade-luffy/p/6015891.html
在运行时出现错误
Missing separate debuginfo for /data/jdk/jdk8/jre/lib/amd64/libverify.so
Try: yum --enablerepo='*debug*' install /usr/lib/debug/.build-id/c4/a66510f932af6bec8ceccc86989d99db80d3a4.debug
Error occurred during initialization of VM
java/lang/NoClassDefFoundError: java/lang/invoke/AdapterMethodHandle
通过这个错误看到是链接到了原来编译时的启动jdk位置,一直无法找到原因,能过打开hotspot启动脚本发现以下脚本
JDK=
if [ "${ALT_JAVA_HOME}" = "" ]; then
. ${MYDIR}/jdkpath.sh
else 
JDK=${ALT_JAVA_HOME%%/jre};
fi
if [ "${JDK}" = "" ]; then
echo Failed to find JDK. ALT_JAVA_HOME is not set or ./jdkpath.sh is empty or not found.
exit 1
fi
# We will set the LD_LIBRARY_PATH as follows:
# o $JVMPATH (directory portion only)
# o $JRE/lib/$ARCH
# followed by the user's previous effective LD_LIBRARY_PATH, if
# any.
JRE=$JDK/jre
JAVA_HOME=$JDK
ARCH=amd64
SBP=${MYDIR}:${JRE}/lib/${ARCH}


后面通过增加以下环境变量就可以
export ALT_JAVA_HOME=/data/jdk/openjdk/build/linux-amd64-debug/j2sdk-image


环境变量汇总:
一、编译的环境变量:
unset CLASSPATH
unset JAVA_HOME
export LANG=C
export ALT_BOOTDIR=/data/jdk/jdk8
export ANT_HOME=/data/jdk/ant
export ALT_FREETYPE_LIB_PATH=/usr/local/lib
export SKIP_DEBUG_BUILD=false
export SKIP_FASTDEBUG_BUILD=true
export DEBUG_NAME=debug
export ALT_FREETYPE_HEADERS_PATH=/usr/local/include/freetype2
export ALT_JDK_IMPORT_PATH=/data/jdk/jdk8
二、运行的环境变量
export JAVA_HOME=/data/jdk/openjdk/build/linux-amd64-debug/j2sdk-image
export LD_LIBRARY_PATH=/data/jdk/openjdk/build/linux-amd64-debug/hotspot/outputdir/linux_amd64_compiler2/jvmg
export ALT_JAVA_HOME=/data/jdk/openjdk/build/linux-amd64-debug/j2sdk-image


参考资料
1. http://www.linuxidc.com/Linux/2015-05/117248.htm
2.HotSpot实战 ISBN:9787115343635
3.http://blog.csdn.net/white_eyes/article/details/6259607
4.http://www.tuicool.com/articles/iIRr2e
5.https://www.cyberciti.biz/faq/debian-ubuntu-linux-gnustubs-32-h-no-such-file-or-directory/
6.https://www.douban.com/note/543322671/
7.http://blog.csdn.net/zitong_ccnu/article/details/50149757
8.http://www.thinksaas.cn/topics/0/399/399997.html
9.http://blog.csdn.net/rongyongfeikai2/article/details/51137533
10.http://sky198.iteye.com/blog/1552648
 11.http://blog.csdn.net/abountwinter/article/details/52369507
 12.http://blog.csdn.net/my_computer/article/details/37879469
13.http://www.reader8.cn/jiaocheng/20140313/2270624.html 
14.http://www.cnblogs.com/wade-luffy/p/6015891.html

你可能感兴趣的:(【JDK编译】Centos7编译OpenJDK7)