ubuntu 20.04 编译openjdk8
Posted xxzblog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ubuntu 20.04 编译openjdk8相关的知识,希望对你有一定的参考价值。
ubuntu 20.04 构建openjdk8
所有操作使用的是root
0. 更换源(可选)
cp /etc/apt/sources.list /etc/apt/sources.list.bak
sed -i "s@http://.*archive.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list
sed -i "s@http://.*security.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list
apt-get update
- 下载openjdk
git clone https://github.com/openjdk/jdk
cd jdk
git checkout jdk8-b119 -b b119
- 下载jdk7
wget https://repo.huaweicloud.com/java/jdk/7u80-b15/jdk-7u80-linux-x64.tar.gz
tar -zxvf jdk-7u80-linux-x64.tar.gz
mv jdk1.7.0_80 jdk1.7
- 安装编译依赖
apt install build-essential
apt install libfreetype6-dev
apt install libcups2-dev
apt install libx11-dev libxext-dev libxrender-dev libxrandr-dev libxtst-dev libxt-dev
apt install libasound2-dev
apt install libffi-dev
apt install autoconf
apt install ccache
- 开始编译openjdk
编译文档:https://github.com/openjdk/jdk/blob/master/doc/building.md
cd $openjdk8 home
bash configure --with-debug-level=slowdebug --enable-debug-symbols ZIP_DEBUGINFO_FIELS=0 --with-boot-jdk=$jdk1.7 home
- 编译
make all CONF=linux-x86_64-normal-server-slowdebug ZIP_DEBUGINFO_FILES=0
- 编译成功信息
-------------------------
Finished building OpenJDK for target 'all'
- 验证
./build/linux-x86_64-normal-server-slowdebug/jdk/bin/java -version
openjdk version "1.8.0-internal-debug"
OpenJDK Runtime Environment (build 1.8.0-internal-debug-root_2021_09_29_15_35-b00)
OpenJDK 64-Bit Server VM (build 25.0-b61-debug, mixed mode)
异常1
check_os_version] Error 1
这个错误是因为不支持版本,这里先看看自己的内核版本
uname -r
我的内核版本是5.x
vim hotspot/make/linux/Makefile
SUPPORTED_OS_VERSION = 2.4% 2.5% 2.6% 3% 4% 5%
重新回到步骤5
异常2
top.make:91: ad_stuff] Error 2
这个错误是因为make参数的问题
vim hotspot/make/linux/makefiles/adjust-mflags.sh
大约67行的样子
s/ -\\([^ ][^ ]*\\)j/ -\\1 -j/
改成(注意是大写的i, 而不是竖线)
s/ -\\([^ I][^ ]*\\)j/ -\\1 -j/
重新回到步骤5
异常3
cc1plus: all warnings being treated as errors
这个错误是因为gcc版本的问题 gcc版本控制在5.0以下
apt install gcc-4.8 g++-4.8
如果出现Package 'gcc-4.8' has no installation candidate
vim /etc/apt/sources.list
deb http://dk.archive.ubuntu.com/ubuntu xenial main
deb http://dk.archive.ubuntu.com/ubuntu xenial universe
apt update
配置新安装的gcc 4.8的启动优先级为100
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 100
配置新安装的g++ 4.8的启动优先级为100
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 100
vim hotspot/make/linux/makefiles/gcc.make
#WARNINGS_ARE_ERRORS = -Werror
重新回到步骤5
异常4
warning: [options] bootstrap class path not set in conjunction with -source 1.6
vim hotspot/make/linux/makefiles/rules.make
BOOT_SOURCE_LANGUAGE_VERSION = 7
BOOT_TARGET_CLASS_VERSION = 7
重新回到步骤5
eclipse CDT 导入hotspot源码调试
File -> Import -> Existing Code as Makefile Project -> Next
Existing Code Location
选择$openjdk8 home/hotspot
Toolchain for Indexer Settings
Linux GCC
设置hotspot src
File -> Properties -> C/C++ General -> Paths and Symbols -> Source Location
Add Folder 选择src
debug设置(下面的$openjdk8 home需要替换成实际地址)
选中项目右键 Debug as -> Debug Configurations -> C/C++ Application
右键New Configuration
Main
C/C++ Application: $openjdk8 home/build/linux-x86_64-normal-server-slowdebug/jdk/bin/java
Disable auto build: 选中
Arguments($workspace替换成实际代码地址)
Program arguments:
-Xdebug -Xrunjdwp:transport=dt_socket,address=8088,server=y,suspend=n -classpath $openjdk8 home/build/linux-x86_64-normal-server-slowdebug/jdk/classes:$workspace/jvm-test/target/classes jvm.Jvm01
Environment
JAVA_HOME: $openjdk8 home/build/linux-x86_64-normal-server-slowdebug/jdk
LD_LIBRARY_PATH: $openjdk8 home/build/linux-x86_64-normal-server-slowdebug/hotspot/linux_amd64_compiler2/debug
使用IDEA在$workspace创建一个jvm-test的工程,配置jdk地址为$openjdk8 home/build/linux-x86_64-normal-server-slowdebug/jdk
Jvm01.java
package jvm;
public class Jvm01
public static void main(String[] args)
System.out.println("hello jvm");
这个时候就可以Debug as -> hotspot Default
以上是关于ubuntu 20.04 编译openjdk8的主要内容,如果未能解决你的问题,请参考以下文章