首页 > 代码库 > Unbuntu_14.04编译openjdk7
Unbuntu_14.04编译openjdk7
今天有问题需要研究一下JVM,但系统挂了,只能重装。在ubuntu下再次编译JDK,大约2个半小时,将遇到的问题笔记整理一下。
1.下载Openjdk Source Code
我用的是http://download.java.net/openjdk/jdk7。(一般https://jdk7.java.net/source.html也可以,但遇到的问题不一样)
2.依赖安装
我的镜像源选择的是中科大镜像:mirrors.ustc.edu.cn(在super->software&update->点击download from后面的选择->china->mirrors.ustc.edu.cn)
apt-get updateapt-get install build-essential gawk m4 libasound2-dev libcups2-dev libxrender-dev xorg-dev xutils-dev xllproto-print-dev binutils libmotif3 libmotif-dev ant
我不用openjdk做bootstrap JDK,编译的时候有Bug,建议使用Oracle JDK,我用的是1.7.0_80,去官方网站JDK->JDK Archive中JDK 7下载的。
如果上面第二条命令出现问题,可以换163,阿里云的镜像试试,实在不行,去pkgs.org下载失败的deb(Ubuntu14.04),使用dpkg -i software_name 安装。
3.环境变量
根据自己的路径设置有些地方可能需要修改:
export LANG=Cexport ALT_BOOTDIR=/home/softwares/jdk1.7.0_80/# Automatically download dependaciesexport ALLOW_DOWNLOADS=true# 并行编译线程数,与CPU核数一致export HOTSPOT_JOBS=8export ALT_PARALLEL_COMPILE_JOBS=8#export SKIP_COMPARE_IMGAGES=true#export USE_PRECOMPILED_HEADER=true# Compiling contentsexport BUILD_LANGTOOLS=trueexport BUILD_HOTSOPT=trueexport BUILD_JDK=true# Compiling version# Avoid javaws & applet buildBUILD_DEPLOY=false# Avoid installation buildBUILD_INSTALL=false# Result ouputexport ALT_OUTPUTDIR=/home/advance/JVM/jdkBuild/openjdk_7/build# Necessityunset JAVA_HOMEunset CLASSPATH
以上设置成功,在openjdk源码文件夹下:
make sanity 一次过。
4.编译make
在openjdk源码文件夹下:
#Ubuntu14.04居然check不同过,有点晕,只能加参数make DISABLE_HOTSPOT_OS_VERSION_CHECK=OK
遇到的其他错误及解决方案:
1-----------------------------------------------------------------------------------------
ERROR: echo "*** This OS is not supported:" ‘uname -a‘; exit 1;
make DISABLE_HOTSPOT_OS_VERSION_CHECK=OK
2-----------------------------------------------------------------------------------------
/openjdk/hotspot/srcmps/constantPoolOop.cpp:272:39: error: converting ‘false‘ to pointer type ‘methodOop‘
修改/openjdk/hotspot/src/share/vm/oops/constantPoolOop.cpp 第272行 return false改为return (methodOop)false; 或者 return NULL;
3-----------------------------------------------------------------------------------------
openjdk/hotspot/srcm/opto/loopnode.cpp:896:50: error: converting ‘false‘ to pointer type ‘Node*
SOLUTION: 修改openjdk/hotspot/src/share/vm/opto/loopnode.cpp: 第896行 return false改为return (Node*)false; 或者 return NULL;
4-----------------------------------------------------------------------------------------
Error occurred during initialization of VM Unable to load native library: /home/softwaresk1.8.0_101/jre/lib/amd64/libjava.so: symbol JVM_GetClassTypeAnnotations, version SUNWprivate_1.1 not defined in file libjvm.so with link time reference
SOLUTION: openjdk/hotspot/make/linux/Makefile 去掉所有的 && ./test_gamma
5-----------------------------------------------------------------------------------------
/home/mengxiansen/openjdk/openjdk/hotspot/src/share/vm/runtime/interfaceSupport.hpp:430:0: error: "__LEAF" redefined [-Werror]
SOLUTION:
#define __LEAF(result_type, header)
/usr/include/x86_64-linux-gnu/sys/cdefs.h:42:0: note: this is the location of the previous definition
# define __LEAF , __leaf__
在interfaceSupport.hpp增加
#ifdef __LEAF
#undef __LEAF
#define __LEAF(result_type, header) \
TRACE_CALL(result_type, header) \
debug_only(NoHandleMark __hm;) \
/* begin of body */
#endif
6-----------------------------------------------------------------------------------------
gcc: error: unrecognized command line option ‘-mimpure-text‘
SOLUTION: gcc版本问题,这个命令在本机所用的4.7.2版的gcc中已经去除,既然不能降低gcc版本(本机ubuntu12.10内核用4.7.2版gcc编译),那就在openjdk/jdk/make/common/shared/Compiler-gcc.gmk 中去掉-mimpure-text命令
7-----------------------------------------------------------------------------------------
Error: time is more than 10 years from present: 1136059200000
SOLUTION: 将 openjdk/jdk/src/share/classes/java/util/CurrencyData.properties 中所有的时间改为10年以内
8-----------------------------------------------------------------------------------------
collect2: error: ld returned 1 exit status
SOLUTION: openjdk/jdk/make/javax/sound/jsoundalsa/Makefile 里面
刪除 LDFLAGS += -lasound
加入 OTHER_LDLIBS += -lasound
5.编译成功
-- Build times ----------Target all_product_buildStart 2016-08-31 22:10:08End 2016-08-31 22:13:4900:00:02 corba00:00:02 hotspot00:00:01 jaxp00:00:02 jaxws00:03:33 jdk00:00:01 langtools00:03:41 TOTAL-------------------------make[1]: Leaving directory `/home/softwares/openjdk7‘
hotspot就是JVM,可以在IDE工具中进行调试。
以上记录在github中 https://github.com/dreamingodd/UnderstandingJVM ,其他问题可以去找来参考。
dreamingodd原创文章,如转载请注明出处。
Unbuntu_14.04编译openjdk7