深入理解JVM虚拟机-读书笔记【一】自己编译openjdk源码

版权声明: https://blog.csdn.net/jiangxuexuanshuang/article/details/88364405

1、下载地址

各版本下载页面:
https://jdk.java.net/
jdk8下载页面:
https://jdk.java.net/java-se-ri/8
在栏目RI Source Code下获取下载链接:
https://download.java.net/openjdk/jdk8u40/ri/openjdk-8u40-src-b25-10_feb_2015.zip
各版本下载地址总结:
openjdk7:https://download.java.net/openjdk/jdk7u75/ri/openjdk-7u75-src-b13-18_dec_2014.zip
openjdk8:https://download.java.net/openjdk/jdk8u40/ri/openjdk-8u40-src-b25-10_feb_2015.zip
openjdk9: https://download.java.net/openjdk/jdk9/ri/openjdk-9_src.zip
openjdk10:https://download.java.net/openjdk/jdk10/ri/openjdk-10_src.zip
openjdk11:https://download.java.net/openjdk/jdk11/ri/openjdk-11+28_src.zip
openjdk12:https://download.java.net/openjdk/jdk12/ri/openjdk-12+32_src.zip

2、环境准备

操作系统:Centos7
jdk develop kit:openjdk-8u40
openjdk bootstrap安装包:openjdk-8u40-b25-linux-x64-10_feb_2015.tar.gz
源码安装包:openjdk-8u40-src-b25-10_feb_2015.zip

3、环境变量配置,(/etc/profile)文件后添加如下内容

#语言选项,这个必须设置,否则编译好后会出现一个HashTable的NPE错
export LANG=C
#Bootstrap JDK的安装路径。jdk1.8已忽略设置
#export ALT_BOOTDIR=/data/software/java-se-8u40-ri
#允许自动下载依赖
export ALLOW_DOWNLOADS=true
#并行编译的线程数,设置为和CPU内核数量一致即可
export HOTSPOT_BUILD_JQBS=2
export ALT_PARALLEL_COMPILE_JOBS=2

#比较本次build出来的映像与先前版本的差异。没有先前的信息设置为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

#要编译的版本:debug release
#export SKIP_DEBUG_BUILD=false
#export SKIP_FASTDEBUG_BUILD=false
#export DEBUG_NAME=debug

#把它设置为false可以避开javaws和浏览器Java插件之类的部分的build
BUILD_DEPLOY=false

#build出JDK完整镜像,不继续build安装包
BUILD_INSTALL=false
#编译结果存放路径,jdk1.8已忽略设置
#export ALT_OUTPUTDIR=/data/software/buildjdk

#必须去掉以下两个环境变量,jdk1.8需要设置JAVA_HOME
#unset JAVA_HOME
#unset CLASSPATH
#设置JAVA_HOME
export JAVA_HOME=/data/software/java-se-8u40-ri
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:${JAVA_HOME}/lib:${JAVA_HOME}/jre/lib


4、安装

mkdir -p /data/software
cd /data/software

#下载
wget https://download.java.net/openjdk/jdk8u40/ri/openjdk-8u40-src-b25-10_feb_2015.zip
wget https://download.java.net/openjdk/jdk8u40/ri/openjdk-8u40-b25-linux-x64-10_feb_2015.tar.gz
unzip openjdk-8u40-src-b25-10_feb_2015.zip
tar xzvf openjdk-8u40-b25-linux-x64-10_feb_2015.tar.gz

#生效配置文件
source /etc/profile

#运行配置
./configure

#根据提示错误的信息一步一步安装以下内,直到执行成功:
chmod 755 /data/software/openjdk
yum install zip
yum install libXtst-devel libXt-devel libXrender-devel
yum install cups-devel
yum install freetype-devel
yum install alsa-lib-devel


#校验配置是否准确:已废弃
#make sanity

#编译
make




5、构建结果

Compiling 195 files for BUILD_BOOTSTRAP_RMIC
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Warning: generation and use of skeletons and static stubs for JRMP
is deprecated. Skeletons are unnecessary, and static stubs have
been superseded by dynamically generated stubs. Users are
encouraged to migrate away from using rmic to generate skeletons and static
stubs. See the documentation for java.rmi.server.UnicastRemoteObject.
Warning: generation and use of skeletons and static stubs for JRMP
is deprecated. Skeletons are unnecessary, and static stubs have
been superseded by dynamically generated stubs. Users are
encouraged to migrate away from using rmic to generate skeletons and static
stubs. See the documentation for java.rmi.server.UnicastRemoteObject.
Warning: generation and use of skeletons and static stubs for JRMP
is deprecated. Skeletons are unnecessary, and static stubs have
been superseded by dynamically generated stubs. Users are
encouraged to migrate away from using rmic to generate skeletons and static
stubs. See the documentation for java.rmi.server.UnicastRemoteObject.
Warning: generation and use of skeletons and static stubs for JRMP
is deprecated. Skeletons are unnecessary, and static stubs have
been superseded by dynamically generated stubs. Users are
encouraged to migrate away from using rmic to generate skeletons and static
stubs. See the documentation for java.rmi.server.UnicastRemoteObject.
Creating jdk/jce/unsigned/sunpkcs11.jar
Creating jdk/jce/unsigned/sunec.jar
Creating jdk/jce/unsigned/sunjce_provider.jar
Creating jdk/jce/unsigned/jce.jar
Creating jdk/jce/unsigned/policy/unlimited/US_export_policy.jar
Creating jdk/jce/unsigned/policy/limited/local_policy.jar
Creating jdk/jce/unsigned/policy/unlimited/local_policy.jar
## Finished jdk (build time 00:04:11)

----- Build times -------
Start 2019-03-09 14:33:36
End   2019-03-09 14:49:40
00:00:34 corba
00:09:52 hotspot
00:00:22 jaxp
00:00:28 jaxws
00:04:11 jdk
00:00:37 langtools
00:16:04 TOTAL
-------------------------
Finished building OpenJDK for target 'default'

6、最后生成目录

/data/software/openjdk/build/linux-x86_64-normal-server-release/jdk

7、测试

cd /data/software/openjdk/build/linux-x86_64-normal-server-release/jdk/bin/
java -version

8、成功显示如下,构建成功:

[root@localhost bin]# ./java -version
openjdk version "1.8.0-internal"
OpenJDK Runtime Environment (build 1.8.0-internal-root_2019_03_09_14_32-b00)
OpenJDK 64-Bit Server VM (build 25.40-b25, mixed mode)

9、说明:jdk8与之前的版本编译有些许不同,对JAVA_HOME,CLASS_PATH有所修改。后续的版本变异可能也会有稍微调整。

猜你喜欢

转载自blog.csdn.net/jiangxuexuanshuang/article/details/88364405