首先用书上的脚本尝试,失败。

之后根据源文件的 README 编译,抛出:

root@linux:/opt/openjdk# sh ./get_source.sh
ERROR: Need initial repository to use this script

采用下面的方案解决:

你jdk8版本太老了,但是你系统又比较新(很多工具,例如make也是最新的),导致很多不匹配。解决办法换成最新版本的jdk8吧。
具体方法:hg clone http://hg.openjdk.java.net/jdk8u/jdk8u/ && sh get_source.sh. 后面就是一样的。 -- by baidu 乱乱我不乱

需要注意,要使用 hg 必须先:

apt install mercurial

hg clone http://hg.openjdk.java.net/jdk9/jdk9 MyOpenJDK

cd MyOpenJDK

cat README

Welcome to OpenJDK!
=================== For information about building OpenJDK, including how to fully retrieve all
source code, please see either of these: * common/doc/building.html (html version)
* common/doc/building.md (markdown version) See http://openjdk.java.net/ for more information about OpenJDK.

cd ./common/doc/
firefox building.html

cd /opt/MyOpenJDK/
sh get_source.sh

bash configure

checking for X11/extensions/shape.h... no
configure: error: Could not find all X11 headers (shape.h Xrender.h XTest.h Intrinsic.h). You might be able to fix this by running 'sudo apt-get install libx11-dev libxext-dev libxrender-dev libxtst-dev libxt-dev'.
configure exiting with result code

apt-get install libx11-dev libxext-dev libxrender-dev libxtst-dev libxt-dev

bash configure

configure: error: Could not find cups! You might be able to fix this by running 'sudo apt-get install libcups2-dev'. 

apt-get install libcups2-dev

在处理时有错误发生:
oracle-java7-installer
E: Sub-process /usr/bin/dpkg returned an error code ()

bash configure

configure: error: Could not find freetype! You might be able to fix this by running 'sudo apt-get install libfreetype6-dev'.

apt-get install libfreetype6-dev

再次使用存在的到 download.oracle.com: 的连接。
已发出 HTTP 请求,正在等待回应... Not Found
-- :: 错误 :Not Found。 download failed
Oracle JDK is NOT installed.
dpkg: 处理软件包 oracle-java7-installer (--configure)时出错:
子进程 已安装 post-installation 脚本 返回错误状态
正在设置 libfreetype6:amd64 (2.6.-.1ubuntu2.) ...
正在设置 zlib1g-dev:amd64 (:1.2..dfsg-2ubuntu4.) ...
正在设置 libpng12-dev:amd64 (1.2.-1ubuntu1) ...
正在设置 libfreetype6-dev:amd64 (2.6.-.1ubuntu2.) ...
正在处理用于 libc-bin (2.23-0ubuntu5) 的触发器 ...
在处理时有错误发生:
oracle-java7-installer
E: Sub-process /usr/bin/dpkg returned an error code ()
# . oracle openjdk ppa source
sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get install openjdk--jdk // OpenJdk 7安装:

update-alternatives --config javac
update-alternatives --config java
改成 openJDK 7

再次  bash configure

====================================================
A new configuration has been successfully created in
/opt/MyOpenJDK/build/linux-x86_64-normal-server-release
using default settings. Configuration summary:
* Debug level: release
* HS debug level: product
* JDK variant: normal
* JVM variants: server
* OpenJDK target: OS: linux, CPU architecture: x86, address length:
* Version string: -internal+-adhoc.root.MyOpenJDK (-internal) Tools summary:
* Boot JDK: openjdk version "1.8.0_151" OpenJDK Runtime Environment (build 1.8.0_151-8u151-b12-0ubuntu0.16.04.-b12) OpenJDK -Bit Server VM (build 25.151-b12, mixed mode) (at /usr/lib/jvm/java--openjdk-amd64)
* Toolchain: gcc (GNU Compiler Collection)
* C Compiler: Version 5.4. (at /usr/bin/gcc)
* C++ Compiler: Version 5.4. (at /usr/bin/g++) Build performance summary:
* Cores to use:
* Memory limit: MB

于是我 make images

root@linux:/opt/MyOpenJDK# make images
Building target 'images' in configuration 'linux-x86_64-normal-server-release'
/bin/bash: 第 行: cd: /opt/MyOpenJDK/hotspot/make: 没有那个文件或目录
make[]: *** [hotspot-server-gensrc] Error
make[]: *** 正在等待未完成的任务....
make/Main.gmk:: recipe for target 'hotspot-server-gensrc' failed
Compiling files for BUILD_TOOLS_LANGTOOLS ERROR: Build failed for target 'images' in configuration 'linux-x86_64-normal-server-release' (exit code ) === Make failed targets repeated here ===
make/Main.gmk:: recipe for target 'hotspot-server-gensrc' failed
=== End of repeated output === Hint: Try searching the build log for the name of the first failed target.
Hint: See common/doc/building.html#troubleshooting for assistance. /opt/MyOpenJDK/make/Init.gmk:: recipe for target 'main' failed
make[]: *** [main] Error
/opt/MyOpenJDK/make/Init.gmk:: recipe for target 'images' failed
make: *** [images] Error

(失败)

再尝试 bash configure

WARNING: The result of this configuration has overridden an older
configuration. You *should* run 'make clean' to make sure you get a
proper build. Failure to do so might result in strange build problems.

x

我记得 opne jdk8u 目录下是有hotspot 的,但是jdk9 目录下找不到。正好没有把open jdk8u删掉,切进去试试。

/opt/jdk8u# bash configure 

通过配置检查,并得到下面的提示:

Build performance tip: ccache gives a tremendous speedup for C++ recompilations.
You do not have ccache installed. Try installing it.
You might be able to fix this by running 'sudo apt-get install ccache'.

apt-get install ccache(失败)

make images

警告: [options] 未与 -source 1.6 一起设置引导类路径
个警告
Generating linux_amd64_docs/jvmti.html
INFO: ENABLE_FULL_DEBUG_SYMBOLS=
INFO: ALT_OBJCOPY=/usr/bin/objcopy
INFO: /usr/bin/objcopy cmd found so will create .debuginfo files.
INFO: STRIP_POLICY=min_strip
INFO: ZIP_DEBUGINFO_FILES=
## Finished hotspot (build time ::) ## Starting corba
/bin/sh: : cd: can't cd to /opt/jdk8u/corba/make
/opt/jdk8u//make/Main.gmk:89: recipe for target 'corba-only' failed
make: *** [corba-only] Error

貌似是编译了一半。

再试一次 make all

root@linux:/opt/jdk8u# make all
Building OpenJDK for target 'all' in configuration 'linux-x86_64-normal-server-release' ## Starting langtools
## Finished langtools (build time ::) ## Starting hotspot
## Finished hotspot (build time ::) ## Starting corba
/bin/sh: : cd: can't cd to /opt/jdk8u/corba/make
/opt/jdk8u//make/Main.gmk:89: recipe for target 'corba-only' failed
make: *** [corba-only] Error

重头再来一遍,不行就用 vps 试一试。

hg clone http://hg.openjdk.java.net/jdk9/jdk9
cd jdk9
bash get_source.sh
bash configure
make images
./build/*/images/jdk/bin/java -version
make run-test-tier1

还是失败了,get_source.sh 的时候报了很多类似这样的:

 abort: stream ended unexpectedly (got  bytes, expected )

还是一样的命令,换 vps :

get_source.sh

WARNING: jaxws exited abnormally ()
root@xkfx:/opt/jdk9# hg clone http://hg.openjdk.java.net/jdk9/jdk9/jaxws jaxws
openjdk
—— corba:不流行的多语言、分布式通讯接口
—— hotspot:Java 虚拟机
—— jaxp:XML 处理
—— jaxws:一组 XML web services 的 Java API
—— jdk:java 开发工具包
—— —— 针对操作系统的部分
—— —— share:与平台无关的实现
—— langtools:Java 语言工具
—— nashorn:JVM 上的 JavaScript 运行时

来自 只会一点java

get_source 成功的话,目录应该是这样的

root@xkfx:/opt/jdk9# ls
ASSEMBLY_EXCEPTION corba jaxp langtools Makefile test
common get_source.sh jaxws LICENSE nashorn
configure hotspot jdk make README

bash configure

configure: error: Could not find required tool for ZIPEXE
configure exiting with result code

apt-get install zip

bash configure

make clean

make images

然后挂在后台编译,

root@xkfx:/opt/jdk9/build/linux-x86_64-normal-server-release/images/jdk/bin# ./java -version
openjdk version "9-internal"
OpenJDK Runtime Environment (build -internal+-adhoc.root.jdk9)
OpenJDK -Bit Server VM (build -internal+-adhoc.root.jdk9, mixed mode)

查看主要源代码:

sudo apt-get install tree

tree 以树状图显示所有文件
tree -L N 以树状图显示所有文件,子文件夹显示到第 N 层

root@xkfx:/opt/jdk9/hotspot/src# tree -L 1

.
├── cpu
├── jdk.aot
├── jdk.hotspot.agent
├── jdk.internal.vm.ci
├── jdk.internal.vm.compiler
├── os
├── os_cpu
└── share

深入理解Java虚拟机 #01# 自己编译JDK的更多相关文章

  1. 深入理解Java虚拟机之自己编译JDK

    题外话 最近在阅读<深入理解Java虚拟机>,其中有一小节实战是自己编译JDK,实际操作下来后遇到问题不少,为此特地记录,也希望可以给大家带来一些参考! 前置准备 平台及工具:Window ...

  2. 深入理解Java虚拟机(程序编译与代码优化)

    文章首发于微信公众号:BaronTalk,欢迎关注! 对于性能和效率的追求一直是程序开发中永恒不变的宗旨,除了我们自己在编码过程中要充分考虑代码的性能和效率,虚拟机在编译阶段也会对代码进行优化.本文就 ...

  3. 深入理解java虚拟机-01 走进java

    第一章是对java的产生,历史的整体介绍 java的使用很广泛,安装jdk的时候会看到一句广告语runs in 10 billions machines.使用java的设备多达几十亿台 1.概述 优点 ...

  4. 深入理解Java虚拟机(九)——后端编译与优化

    即时编译器 Java程序最初都是通过解释器进行执行,当发现某个方法或者代码块被运行得非常频繁,这些代码就被认为是热点代码,为了提高这些代码得运行效率,虚拟机会把热点代码编译成本地机器码,并进行优化,运 ...

  5. 《深入理解java虚拟机》学习笔记之编译优化技术

    郑重声明:本片博客是学习<深入理解Java虚拟机>一书所记录的笔记,内容基本为书中知识. Java程序员有一个共识,以编译方式执行本地代码比解释方式更快,之所以有这样的共识,除去虚拟机解释 ...

  6. 《深入理解java虚拟机》学习笔记之虚拟机即时编译详解

    郑重声明:本片博客是学习<深入理解java虚拟机>一书所记录的笔记,内容基本为书中知识. Java程序最初是通过解释器(Interpreter)进行解释执行的,当虚拟机发现某个方法或代码块 ...

  7. 深入理解Java虚拟机--下

    深入理解Java虚拟机--下 参考:https://www.zybuluo.com/jewes/note/57352 第10章 早期(编译期)优化 10.1 概述 Java语言的"编译期&q ...

  8. 深入理解Java虚拟机--中

    深入理解Java虚拟机--中 第6章 类文件结构 6.2 无关性的基石 无关性的基石:有许多可以运行在各种不同平台上的虚拟机,这些虚拟机都可以载入和执行同一种平台无关的字节码(ByteCode),从而 ...

  9. 深入理解java虚拟机JVM(下)

    深入理解java虚拟机JVM(下) 链接:https://pan.baidu.com/s/1c6pZjLeMQqc9t-OXvUM66w 提取码:uwak 复制这段内容后打开百度网盘手机App,操作更 ...

随机推荐

  1. Chrome V8引擎的一点认识

    最近在玩弄JavaScript ,也一直在捉摸,脚本Engine怎么解析你写的Code,对Google兴趣浓,索性就看了谷歌的脚本engine的官方资料,都是E文的,但是却是最纯的不是,看下来总结V8 ...

  2. Hibernate框架 主配置文件 Hibernate.cfg.xml 映射配置 说明

    1 主配置文件 Hibernate.cfg.xml 主配置文件中主要配置:数据库连接信息.其他参数.映射信息! 常用配置查看源码: hibernate-distribution-3.6.0.Final ...

  3. HOJ 2985 Wavio Sequence(最长递增子序列以及其O(n*logn)算法)

    Wavio Sequence My Tags (Edit) Source : UVA Time limit : 1 sec Memory limit : 32 M Submitted : 296, A ...

  4. POJ-放苹果(DP)

    放苹果 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 29074 Accepted: 18376 Description 把M个 ...

  5. maven冲突问题

    通过配置文件解决问题: http://stamen.iteye.com/blog/2030552 1.用命令dependency:tree得到依赖关系 (或者加上Dincludes或者Dexclude ...

  6. 计蒜客 31452 - Supreme Number - [简单数学][2018ICPC沈阳网络预赛K题]

    题目链接:https://nanti.jisuanke.com/t/31452 A prime number (or a prime) is a natural number greater than ...

  7. upower xdisplay--nvidia -vga---cpu info

    grep 'physical id' /proc/cpuinfo | sort -u | wc -l grep 'core id' /proc/cpuinfo | sort -u | wc -l gr ...

  8. 《Nginx - 变量》- log_format/核心变量

    一:log_format - 概述 - log_format 用于管理 Nginx 的详细信息,日志管理等信息,很多都是基于这个来实现. - 可配置参数 $remote_addr 客户端地址 $rem ...

  9. centos7 卸载和安装最新版本docker-ce,配置阿里云加速

    一.yum卸载.安装 1.卸载老版本的 docker 及其相关依赖 sudo yum remove docker docker-common container-selinux docker-seli ...

  10. Find The Multiple--POJ1426

    Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose ...