linux ubuntu 14. 04下 OpenJdk7编译

来源:互联网 发布:网络割接方案 编辑:程序博客网 时间:2024/06/14 21:55

一、下载源码。
1.1 安装Mercurial , apt-get install mercurial
1.2 下载源码 hg clone http://hg.openjdk.java.net/jdk7u/jdk7u-dev or http://hg.openjdk.java.net/jdk7/jdk7
执行
cd jdk7u-dev
chmod 755 get_source.sh
./get_source.sh 或 sh ./get_source.sh

二、安装依赖
2.1 执行
apt-get install build-essential gawk m4 openjdk-6-jdk libasound2-dev libcups2-dev libxrender-dev xorg-dev xutils-dev x11proto-print-dev binutils ant libmotif3 libmotif-dev

三、 切换jdk版本
update-alternatives –install /usr/bin/java java /usr/java/jdk1.8.0_144/bin/java 300 添加自定义jdk
update-alternatives –config java

四 编译环境
参考《深入理解Java虚拟机》

#语言选项,这个必须设置,否则编译好后会出现一个HashTable的NPE错  export LANG=C  #Bootstrap 本机JDK的安装路径。必须设置。   export ALT_BOOTDIR=/usr/lib/jvm/java-6-openjdk-amd64#允许自动下载依赖  export ALLOW_DOWNLOADS=true  #并行编译的线程数,设置为和CPU内核数量一致即可  export HOTSPOT_BUILD_JOBS=4  export ALT_PARALLEL_COMPILE_JOBS=4  #比较本次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 DISABLE_HOTSPOT_OS_VERSION_CHECK=ok  #要编译的版本  #export SKIP_DEBUG_BUILD=false  #export SKIP_FASTDEBUG_BUILD=true  #export DEBUG_NAME=debug  #把它设置为false可以避开javaws和浏览器Java插件之类的部分的build。   BUILD_DEPLOY=false  #把它设置为false就不会build出安装包。因为安装包里有些奇怪的依赖,但即便不build出它也已经能得到完整的JDK映像,所以还是别build它好了。  BUILD_INSTALL=false  #编译结果所存放的路径  export ALT_OUTPUTDIR=/vsftp/openjdk7 #这两个环境变量必须去掉,不然会有很诡异的事情发生(我没有具体查过这些“”诡异的事情”,Makefile脚本检查到有这2个变量就会提示警告“)  unset JAVA_HOME  unset CLASSPATH  make  2>&1 -d | tee build.log 

注意 执行shell 和 make 在openjdk源码目录下进行。

编译成功

– Build times ———-
Target all_product_build
Start 2017-10-12 09:00:54
End 2017-10-12 09:12:31
00:00:23 hotspot
00:11:09 jdk
00:00:03 langtools
00:11:37 TOTAL———————-

root@ubuntu:/vsftp/openjdk/openjdk7/j2sdk-image/bin# ./java -version
openjdk version “1.7.0-internal”
OpenJDK Runtime Environment (build 1.7.0-internal-root_2017_10_12_08_26-b00)

五 编译期间出现问题

1、 ERROR: echo “* This OS is not supported:” 系统版本检查错误

hotspot/make/linux/Makefile 添加系统版本。

SUPPORTED_OS_VERSION = 2.4% 2.5% 2.6% 2.7% 3%

2、ERROR: error: “__LEAF” redefined [-Werror] 头文件宏定义冲突
hotspot/src/share/vm/runtime/interfaceSupport.hpp:430:0: error: “__LEAF” redefined [-Werror]
修改 interfaceSupport.hpp 添加已下代码并保存

 #ifdef __LEAF #undef __LEAF #define __LEAF(result_type, header)                                  \  TRACE_CALL(result_type, header)                                    \  debug_only(NoHandleMark __hm;)                                     \  /* begin of body */ #endif

3、 编译过程中出现./gamma: relocation error:/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.36.x86_64/jre/lib/amd64/libjava.so:symbol JVM_FindClassFromCaller, version SUNWprivate_1.1 not defined in filelibjvm.so with link time reference 异常,解决方案:
方案a:
编辑./hotspot/make/linux/Makefile,注释掉所有的test_gamma所在行 。
方案b:
使用Oracle的jdk6(这里用的是jdk1.6.0_45)代替jdk7编译openjdk
备注

4、 ERROR error: converting ‘false’ to pointer type ‘methodOop’ [-Werror=conversion-null] 类型错误,将
return false 改成 return NULL

5、can’t cd to/NOT-SET/re 设置路径
ALT_JDK_IMPORT_PATH=/usr/lib/jvm/ java-6-openjdk-amd64
ALT_HOTSPOT_IMPORT_PATH==/usr/lib/jvm/ java-6-openjdk-amd64

6、ERROR undefined reference to ‘snd_pcm_format_**’出现一堆的
undefined 参考
http://comments.gmane.org/gmane.comp.java.openjdk.build.devel/5311

@@ -65,7 +65,7 @@    $(MIDIFILES_export) \    $(PORTFILES_export)-LDFLAGS += -lasound+OTHER_LDLIBS += -lasound CPPFLAGS += \    -DUSE_DAUDIO=TRUE \

减号删除
加号增加

7、ERROR gcc: error: unrecognized command line option ‘-mimpure-text’ 高版本的gcc取消了该命令 所以注释掉即可
文件在./jdk/make/common/shared/Compiler-gcc.gmk

8、 编译过程中出现Error: time is more than 10 years from present: 1136059200000错误,解决方案:
修改CurrencyData.properties(路径:./jdk/src/share/classes/java/util/CurrencyData.properties)
修改108行:AZ=AZM;2011-12-31-20-00-00;AZN
修改381行:MZ=MZM;2011-06-30-22-00-00;MZN
修改443行:RO=ROL;2011-06-30-21-00-00;RON
修改535行:TR=TRL;2011-12-31-22-00-00;TRY
修改561行:VE=VEB;2011-01-01-04-00-00;VEF

六 只编译hotspot
1、进入源码hotspot所在目录
/vsftp/jdk/jdk7/hotspot/make
重新修改虚拟机输出目录
export ALT_OUTPUTDIR = /vsftp/hotspot/openjdk7/build
其他部分与编译openjdk一致,在/vsftp/jdk/jdk7/hotspot/make目录下,执行脚本。
编译成功
Successfully remade target file `all’.
检查版本
/vsftp/hotspot/openjdk7/build/linux_i486_compiler2/fastdebug# ./gamma
显示

This Java instance does not support a 32-bit JVM.Please install the desired version.JAVA_HOME must point to 32bit JDK.

如果编译出现 fatal error: sys/cdefs.h: No such file or d
# include

sudo apt-get install gcc-multilib g++-multilib

2、 如果 error while loading shared libraries: libjvm.so: cannot open shared object file: No such file or directory
a 修改 /etc/ld.so.conf 文件,把当前目录加进去。具体如下

include /etc/ld.so.conf.d/*.conf/vsftp/openjdk/openjdk7/linux_amd64_compiler2/fastdebug

b 执行 ldconfig 。
本次编译 jvmg下没有gamma 选用的是fastdebug下的, 也 可以选择 product 下的 gamma。

七 指定编译版本

export ARCH_DATA_MODEL=64 # 64 or 32

参考文章
http://cduym.iteye.com/blog/1892416
ubuntu上编译hotspot遇到的问题
http://blog.csdn.net/my_computer/article/details/37879469

自己编译JDK的时候遇到的问题记录
http://chenjingbo.iteye.com/blog/1117021

如果有什么新问题,在openjdk官方邮件列表地址里找找
http://mail.openjdk.java.net/pipermail/build-dev

原创粉丝点击