说明:笔者是在Ubuntu 16.04虚拟机中编译 OpenJDK 8

源码下载

http://download.java.net/openjdk/jdk8/

推荐直接下载openjdk-8-src-b132-03_mar_2014.zip

环境准备:

安装bootstrap JDK,笔者安装的jdk7

在环境变量PATH中添加jdk的bin目录,不添加的话,在编译第一步时需要带参数

解压后阅读README-builds.html,按照要求安装Linux环境需要的软件。不清楚要安装哪些,在编译第一步失败的时候会提示你安装。

#如果之前有设置的话,这两个环境变量需要去掉,不然会出问题。

unset JAVA_HOME

unset CLASSPATH

编译

切换到解压后目录

第一步:

bash ./configure

或者带jdk目录,path为bootstrap JDK的目录

bash ./configure --with-boot-jdk=path

第二步:

make all

*遇到的坑爹问题

1,版本问题,recipe for target 'check_os_version' failed

方案一:直接注释检查

nano hotspot/make/linux/Makefile

 check_os_version: 

#ifeq($(DISABLE_HOTSPOT_OS_VERSION_CHECK)$(EMPTY_IF_NOT_SUPPORTED),) 

#   $(QUIETLY) >& echo "*** This OS is not supported:" `uname -a`; exit ; 

#endif 

方案二:添加版本支持

nano hotspot/make/linux/Makefile

SUPPORTED_OS_VERSION = 2.4% 2.5% 2.6% % %

2,make参数语法,添加'I'

nano hotspot/make/linux/makefiles/adjust-mflags.sh
# line . (新版本make语法有变动)
s/ -\([^ I][^ ]*\)j/ -\ -j/

3,undefine symbols错误

提升一个模板函数定义至头文件,避免出现undefined symbols错误。

# 将 hotspot/src/share/vm/gc_implementation/g1/g1SATBCardTableModRefBS.cpp 中的template <class T> void write_ref_array_pre_work(T* dst, int count)方法,提升到对应的
头文件g1SATBCardTableModRefBS.hpp中。
# 模板函数定义需要出现在头文件中,以便编译器为其生成特化版本。若无此修改,运行编译后的java程序,将出现undefine symbols错误。

编译成功标识

验证

1,the build result. This directory typically looks like:

build/linux-x64-normal-server-release

2,JDK输出目录:

In particular, the build/*/images/j2sdk-image/bin directory should contain executables for the OpenJDK tools and utilities for that configuration.

3,查看版本

3.1直接在bin目录下运行  ./java -version

3.2将编译好的JDK复制到适当目录,配置JAVA_HOME指向该目录,使环境变量生效后,执行java -version命令,就能看到带用户机器名的jdk版本。

cp build/linux-x86_64-normal-server-release/images/j2sdk-image/ -r /usr/lib/jdk/openjdk8
sunil@ubuntu:~/Downloads/openjdk$ java -version
openjdk version "1.8.0-internal"
OpenJDK Runtime Environment (build 1.8.-internal-sunil_2016_11_21_18_06-b00)
OpenJDK -Bit Server VM (build 25.0-b70, mixed mode)
sunil@ubuntu:~/Downloads/openjdk$

参考文档

README

深入理解Java虚拟机(第2版)

https://blog.mlworks.cn/tech/compile-openjdk8-ubuntu-16.04.html

最新文章

  1. 免费公开课,讲解强大的文档集成组件Aspose,现在可报名
  2. SOUI中做的一个磁力吸附效果
  3. c#利用反射获取对象属性值
  4. POJ1201 Intervals(差分约束系统)
  5. *IntelliJ IDEA配置Hibernate
  6. cf Sereja and Array
  7. 使用php完成常见的&quot;文件上传&quot;功能
  8. 了解 HTTPS,读这篇文章就够了
  9. Djangon的坑
  10. 修改 input中的placeholder的字体样式和颜色
  11. cors解决跨域
  12. Deep Learning Tutorial - Convolutional Neural Networks(LENET)
  13. poj 1966(求点连通度,边连通度的一类方法)
  14. SparkException: Could not find CoarseGrainedScheduler or it has been stopped.
  15. Linux之awk、变量、运算符、if多分支
  16. 软件破解入门(暴力破解CrackMe)
  17. MySQL按指定字段自定义列表排序
  18. 渗透测试工具SPARTA介绍
  19. Pg168-1
  20. vue 时间选择器组件

热门文章

  1. 普林斯顿算法课第五周作业_KdTree
  2. Visual Studio 常用快捷键
  3. C# DataTable的Select()方法不支持 != 判断
  4. 在Andoid开发中使用MVP模式来解耦,增加可测试性
  5. Linux命令dos2unix 从windows转换到linux --- nuix2dos从linux转换到windows
  6. canvas图片处理
  7. / fluxChatDemo / 系列 ——fluxDemoChat 组件编写
  8. 深入理解css BFC 模型
  9. oracle--导出、导入blob类型的字段
  10. shell去除换行和空格2