在Eclipse OpenJ9上构建OpenJDK 17的完整指南

在Eclipse OpenJ9上构建OpenJDK 17的完整指南

openj9 Eclipse OpenJ9: A Java Virtual Machine for OpenJDK that's optimized for small footprint, fast start-up, and high throughput. Builds on Eclipse OMR (https://github.com/eclipse/omr) and combines with the Extensions for OpenJDK for OpenJ9 repo. openj9 项目地址: https://gitcode.com/gh_mirrors/op/openj9

前言

Eclipse OpenJ9是一个高性能的Java虚拟机(JVM),它是IBM J9虚拟机的开源版本。本文将详细介绍如何在各种操作系统平台上构建包含OpenJ9的OpenJDK 17版本。无论你是开发者还是系统管理员,本指南都将帮助你完成从环境准备到最终构建的完整流程。

构建环境概述

构建OpenJDK 17 with OpenJ9主要有两种方式:

  1. 使用Docker容器:推荐方式,可快速创建隔离的构建环境
  2. 直接在系统上构建:适合需要自定义配置的高级用户

Linux平台构建指南

1. 系统准备

使用Docker方式
  1. 安装Docker引擎
  2. 获取构建脚本并创建Docker镜像:
wget https://raw.githubusercontent.com/eclipse-openj9/openj9/master/buildenv/docker/mkdocker.sh
bash mkdocker.sh --tag=openj9 --dist=ubuntu --version=22 --gitcache=no --jdk=17 --build
  1. 启动容器并映射目录:
docker run -v <本地目录>:/root/hostdir -it openj9
非Docker方式
  1. 安装必要的依赖包:
sudo apt-get update && sudo apt-get install -y build-essential libx11-dev libxext-dev libxrender-dev libxtst-dev libxt-dev libcups2-dev libfontconfig1-dev libasound2-dev
  1. 设置编译器版本:
export CC=gcc-11 CXX=g++-11
  1. 准备引导JDK:
wget -O bootjdk17.tar.gz "https://api.adoptopenjdk.net/v3/binary/latest/17/ga/linux/x64/jdk/openj9/normal/adoptopenjdk"
tar -xzf bootjdk17.tar.gz
mv jdk-17* bootjdk17

2. 获取源代码

  1. 克隆OpenJDK仓库:
git clone https://github.com/ibmruntimes/openj9-openjdk-jdk17.git
cd openj9-openjdk-jdk17
  1. 获取OpenJ9和OMR源代码:
bash get_source.sh

注:如需OpenSSL支持,可添加-openssl-branch=openssl-3.0.13参数

3. 配置构建环境

bash configure --with-boot-jdk=/path/to/bootjdk17

重要配置选项

  • --with-noncompressedrefs:控制引用压缩方式
  • --with-openssl:添加OpenSSL支持
  • --enable-openssl-bundling:捆绑OpenSSL库

4. 执行构建

make all

构建完成后,JDK将位于: build/linux-x86_64-server-release/images/jdk

5. 验证构建

cd build/linux-x86_64-server-release/images/jdk
./bin/java -version

AIX平台构建指南

1. 系统准备

  1. 安装必要的AIX LPP包:
    • xlc/C++ 16
    • x11.adt.ext
  2. 通过yum安装依赖包:
yum shell yum_install_aix-ppc64.txt
  1. 下载引导JDK:
wget -O bootjdk17.tar.gz "https://api.adoptopenjdk.net/v3/binary/latest/17/ga/aix/ppc64/jdk/openj9/normal/adoptopenjdk"

2-5步与Linux类似

主要区别在于配置时需要指定CUPS路径:

bash configure --with-boot-jdk=<path> --with-cups-include=/opt/freeware/include --disable-warnings-as-errors

构建选项详解

引用压缩配置

OpenJ9支持三种64位构建模式:

  1. 仅压缩引用(默认)
  2. 仅非压缩引用
  3. 混合模式(启动时选择)

通过--with-noncompressedrefs选项控制:

  • --with-noncompressedrefs=no:仅压缩引用
  • --with-noncompressedrefs:仅非压缩引用

OpenSSL集成

构建支持OpenSSL的JDK时:

  1. 使用--with-openssl指定来源:
    • fetched:使用get_source.sh下载的源码
    • system:使用系统安装的库
    • 路径:指定自定义库位置
  2. 使用--enable-openssl-bundling包含加密库

构建产物说明

make all会产生多个镜像:

  1. jdk:完整开发工具包
  2. jre:运行时环境(需make legacy-jre-image
  3. debug-image:调试信息文件
  4. test:测试所需文件

常见问题

  1. 构建不完整:确保使用make all而非仅make
  2. 编译器问题:确认gcc/g++版本正确
  3. 依赖缺失:参考mkdocker.sh输出检查所有依赖

结语

通过本指南,你应该已经成功在目标平台上构建了包含OpenJ9的OpenJDK 17。OpenJ9作为一款高性能、低内存占用的JVM,特别适合云环境和资源受限的场景。构建自定义JDK可以让你充分利用特定硬件优势或进行深度定制。

如需了解更多OpenJ9特性,请参考官方文档。构建过程中遇到问题,可以查阅详细的构建日志或参考OpenJDK构建问题排查指南。

openj9 Eclipse OpenJ9: A Java Virtual Machine for OpenJDK that's optimized for small footprint, fast start-up, and high throughput. Builds on Eclipse OMR (https://github.com/eclipse/omr) and combines with the Extensions for OpenJDK for OpenJ9 repo. openj9 项目地址: https://gitcode.com/gh_mirrors/op/openj9

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

祝珏如

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值