写点什么

第一次手动编译 openjdk11

用户头像
py ploughman
关注
发布于: 2020 年 05 月 05 日
第一次手动编译openjdk11

why


恰好手里有一本书,书上讲解的是编译 openjdk7.按照教程发现现在的 ubuntu 已经是 16 了,教程还是按照 12 的来。很多依赖已经找不到了。所以想一步到位,直接到 11.


前提准备


  1. 在谷歌云申请了东京 8U30G的服务器,作为编译服务器。系统为Ubuntu 16.03

  2. 为了避免其他问题,使用了 root 账号。


编译


  • 打开 openjdk 下载页面 http://jdk.java.net/11/

  • ![](/images/openjdk11/openjdk1.png)

  • jdk 源码使用Mercurial 进行版本管理。首先安装Mercurial

  • 执行apt install mercurial报错。百度发现系统第一次安装依赖需要执行apt-get update

  • 继续执行apt-get install mercurial

  • 继续执行 hg clone http://hg.openjdk.java.net/jdk-updates/jdk11u/

  • 克隆源码很慢,东京的服务器跑了半个小时,如果切换到美国会更快。

  • 切换分支hg update jdk-11.0.1+13

  • 安装 jdk10 编译 jdk 需要Bootstrap JDK wget https://download.java.net/java/GA/jdk10/10.0.2/19aef61b38124481863b1413dce1855f/13/openjdk-10.0.2linux-x64bin.tar.gz,tar -zxvf openjdk-10.0.2linux-x64bin.tar.gz。因为 jdk 源码有 c 代码也有 java 代码。(鸡生蛋,蛋生鸡)(注意不能设置环境变量)。

  • 安装其他依赖apt-get install -y autoconf zip libx11-dev libxext-dev libxrender-dev libxtst-dev libxt-dev libcups2-dev libfontconfig1-dev libasound2-dev

  • 编译的时候会用到Bootstrap JDK的 jre 目录下的 lib 库,我们这里只有 JDK 没有 jre,因此需要创建一个 jre 目录,再把 jdk 的 lib 文件夹复制到这个目录下,执行cp -r lib jre

  • 源码会下载到本地jdk11u的目录中

  • cd jdk11u

  • 执行bash configure --with-num-cores=8 -with-memory-size=22192 --with-boot-jdk=../jdk-10 8 是 8 核,22192 是 MB 内存 jdk-10 是Boostrap JDK的路径

一段时间(10s)后会显示如下信息:


====================================================The existing configuration has been successfully updated in/root/jdk11u/build/linux-x86_64-normal-server-releaseusing configure arguments '--with-num-cores=8 -with-memory-size=22192 --with-boot-jdk=../jdk-10'.
Configuration summary: Debug level: release HS debug level: product JVM variants: server JVM features: server: 'aot cds cmsgc compiler1 compiler2 epsilongc g1gc graal jfr jni-check jvmci jvmti management nmt parallelgc serialgc services vm-structs' OpenJDK target: OS: linux, CPU architecture: x86, address length: 64 Version string: 11.0.1-internal+0-adhoc.root.jdk11u (11.0.1-internal)
Tools summary: Boot JDK: openjdk version "10" 2018-03-20 OpenJDK Runtime Environment 18.3 (build 10+44) OpenJDK 64-Bit Server VM 18.3 (build 10+44, mixed mode) (at /root/jdk-10) Toolchain: gcc (GNU Compiler Collection) C Compiler: Version 5.4.0 (at /usr/bin/gcc) C++ Compiler: Version 5.4.0 (at /usr/bin/g++)
Build performance summary: Cores to use: 8 Memory limit: 22192 MB
WARNING: The result of this configuration has overridden an olderconfiguration. You should run 'make clean' to make sure you get aproper build. Failure to do so might result in strange build problems.
复制代码


  • 执行make 开始编译,等待编译完成后控制台输出以下类似信息。这个步骤持续了 7 分 27 秒,cpu load 会飙到 12(机器 8 核),但内存大概使用四分之一的样子。


Creating support/moduleslibs/jdk.management.agent/libmanagementagent.so from 1 file(s)Creating support/moduleslibs/jdk.net/libextnet.so from 1 file(s)Creating support/moduleslibs/jdk.pack/libunpack.so from 7 file(s)Creating support/modulescmds/jdk.pack/pack200 from 1 file(s)Creating support/modulescmds/jdk.pack/unpack200 from 7 file(s)Creating support/modulescmds/jdk.rmic/rmic from 1 file(s)Creating support/modulescmds/jdk.scripting.nashorn.shell/jjs from 1 file(s)Creating support/moduleslibs/jdk.sctp/libsctp.so from 3 file(s)Creating support/moduleslibs/jdk.security.auth/libjaas.so from 1 file(s)Compiling 4 files for BUILDJIGSAWTOOLSStopping sjavac serverFinished building target 'default (exploded-image)' in configuration 'linux-x86_64-normal-server-release'
复制代码


  • 在 jdk11u 目录下存在一个 build 文件夹。

  • build/linux-x86_64-normal-server-release目录下,有个 jdk 目录,这里面就是最新构建的 OpenJDK,进入里面的 bin 目录,再执行命令./java -version,可见最新的版本信息如下.


root@instance-2:~/jdk11u/build/linux-x86_64-normal-server-release/jdk/bin# ./java -versionopenjdk version "11.0.1-internal" 2018-10-16OpenJDK Runtime Environment (build 11.0.1-internal+0-adhoc.root.jdk11u)OpenJDK 64-Bit Server VM (build 11.0.1-internal+0-adhoc.root.jdk11u, mixed mode)
复制代码


以下是使用官方编译好的 jdk 的版本信息。

$java11/java -versionopenjdk version "11.0.1" 2018-10-16OpenJDK Runtime Environment 18.9 (build 11.0.1+13)OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode)
复制代码


  • SUCCESS


其他测试


重新申请了美国的机器 64 核 57.6GB 的内存,实验发现我要求使用 64 核,实际使用了 21 核。


====================================================The existing configuration has been successfully updated in/root/jdk11u/build/linux-x86_64-normal-server-releaseusing configure arguments '--with-num-cores=64 -with-memory-size=22192 --with-boot-jdk=../jdk-10.0.2'.Configuration summary: Debug level:    release HS debug level: product JVM variants:   server JVM features:   server: 'aot cds cmsgc compiler1 compiler2 epsilongc g1gc graal jfr jni-check jvmci jvmti management nmt parallelgc serialgc services vm-structs' OpenJDK target: OS: linux, CPU architecture: x86, address length: 64 Version string: 11.0.1-internal+0-adhoc.root.jdk11u (11.0.1-internal)Tools summary: Boot JDK:       openjdk version "10.0.2" 2018-07-17 OpenJDK Runtime Environment 18.3 (build 10.0.2+13) OpenJDK 64-Bit Server VM 18.3 (build 10.0.2+13, mixed mode)  (at /root/jdk-10.0.2) Toolchain:      gcc (GNU Compiler Collection) C Compiler:     Version 5.4.0 (at /usr/bin/gcc) C++ Compiler:   Version 5.4.0 (at /usr/bin/g++)Build performance summary: Cores to use:   21 Memory limit:   22192 MBWARNING: The result of this configuration has overridden an olderconfiguration. You should run 'make clean' to make sure you get aproper build. Failure to do so might result in strange build problems.
复制代码


而且,全量编译仅用时 2 分 40s,cpu load 最高到 19 多。


下载源码用时 7min 左右,相当的快。


用户头像

py ploughman

关注

还未添加个人签名 2018.04.26 加入

还未添加个人简介

评论

发布
暂无评论
第一次手动编译openjdk11