sky 发表于 2020-9-27 11:36:09

【Java on RISC-V】OpenJ9对于RISC-V的支持进展调研与搭建测试

本帖最后由 sky 于 2020-9-27 11:36 编辑

本文是根据OpenJ9官方文档对于RISC-V的支持进展进行的调研与在Fedora(on QEMU)虚拟机上的搭建测试
状态
[*]目前的移植基于OpenJDK11+OpenJ9+OMR(无JIT),OpenJ9用以替代Hotspot
[*]目前OpenJ9 OpenJDK V11暂不支持针对Riscv64的JIT编译器,在这种情况下,无论是否-Xint在命令行上指定了该选项,JDK默认都会以相同的输出结束。


尝试在Fedora(on QEMU)上运行OpenJ9
假定Ubuntu版本至少为16.04,并且已搭建好交叉编译环境和Fedora (on QEMU)。此外还需要:


[*]bootJDK_OpenJ9,仅用于生成用于主机系统上的交叉编译的构建JDK
[*]Freemarker V2.3.8


1.安装用于OpenJ9交叉编译的额外(不包括交叉编译环境和Fedora (on QEMU))的软件包
1.登录QEMU虚拟机并安装在Fedora / QEMU上构建JDK所需的开发相关的软件包:
dnf install libX11-devel libXtst-devel libXt-devel libXrender-devel libXrandr-devel libXi-devel libXext-devel
dnf install cups-devel fontconfig-devel alsa-lib-devel freetype-devel#freetype might be skipped if already installed
dnf install libdwarf-devel libstdc++-static #optional if the DDR is enabled for compilation on the target system
dnf install wget git autoconf automake#mostly used in the compilation on the target system
dnf install openssl-devel#optional if the OpenSSL support is required
2.完成上述所有安装后,按以下步骤关闭Fedora OS的电源。poweroff
3.将Fedora OS映像挂载(mount)到主机系统以进行交叉编译<1> sudopartx -v -aFedora-Developer-Rawhide-20191123.n.0-sda.raw
partition: none, disk: Fedora-Developer-Rawhide-20191123.n.0-sda.raw, lower: 0, upper: 0
Trying to use '/dev/loop0' for the loop device
/dev/loop0: partition table type 'gpt' detected
/dev/loop0: partition #1 added
/dev/loop0: partition #2 added
/dev/loop0: partition #3 added
/dev/loop0: partition #4 added

<2> sudo fdisk -l /dev/loop0
Disk /dev/loop0: 10 GiB, 10737418240 bytes, 20971520 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: AD758DB6-0843-40FD-AF2E-46FE0B9F9A42

Device          Start      EndSectorsSize Type
/dev/loop0p1    204812308471228800600M Linux filesystem
/dev/loop0p2 12308481230911       64   32K
/dev/loop0p3 12328961249279    16384    8M
/dev/loop0p4 1249280 20971486 197222079.4G Linux filesystem

<3> mkdir fedora_mount

<4> sudo mount /dev/loop0p4fedora_mount
<your_fedora_mount_directory> ls fedora_mount
binbootdevetchomeliblib64lost+foundmedia
mntoptprocrootrunsbinsrvsystmpusrvar
2.获取构建JDK的源
克隆适用于OpenJ9的OpenJDK扩展,该扩展是OpenJDK的git镜像,没有HotSpot JVM,但带有openj9分支,其中包含一些必要的修补程序。运行以下命令:
git clone https://github.com/ibmruntimes/openj9-openjdk-jdk11.git
克隆该存储库可能需要一段时间,该过程完成后将目录更改为克隆的存储库:cd openj9-openjdk-jdk11
现在,从Eclipse OpenJ9项目及其Eclipse OMR克隆中获取其他资源:bash get_source.sh
3.生成用于交叉编译的构建JDK
在上一步的openj9-openjdk-jdk11文件夹下进行编译:
export JAVA_HOME=/<path_to_build_JDK># the build JDK here is downloaded from https://api.vm.net/v3/binary/latest/11/ga/linux/x64/jdk/openj9/normal/adoptopenjdk
export PATH="$JAVA_HOME/bin:$PATH"

bash configure --disable-warnings-as-errors --with-freemarker-jar=/<path_to>/freemarker.jar
官方文档中给出的上述build JDK链接如果失效,可以从此处下载替代
configure可能会出现的报错:
1.configure: error: Could not find numa!configure exiting with result code 1
sudo apt-get install libnuma-dev
2.checking for nasm... noconfigure: error: Could not find required tool for NASMconfigure exiting with result code 1
sudo apt-get install nasm
生成用于以后交叉编译的build-JDK:make all
⚠️如果只键入make,而不是make all,构建将是不完整的,因为默认make目标是exploded-image。如果要指定make而不是make all,则必须--default-make-target=images在运行configure脚本时添加。
请将生成的build-JDK build/linux-x86_64-normal-server-release/images移至其他目录,因为在下一步中将使用此镜像进行交叉编译并且会在同目录下生成RISCV64的JDK镜像。
cd ..
mv openj9-openjdk-jdk11/build/linux-x86_64-normal-server-release/images ./
4.配置交叉编译环境
运行以下configure命令以删除现有目录后,在上一步创建交叉openj9-openjdk-jdk11目录的同一目录中设置交叉编译环境
export RISCV64=/<path_to_gnu_cross_toolchain>#e.g. /home/linux/opt/riscv
export PATH="$RISCV64/bin:$PATH"

bash configure --disable-warnings-as-errors \
               --disable-ddr \
               --with-boot-jdk=/<path_to_build_JDK_for_cross_compilation> \   
               --with-build-jdk=/<path_to_build_JDK_for_cross_compilation> \#the `build-JDK` created at step 5
               --openjdk-target=riscv64-unknown-linux-gnu \                   #the prefix for the compiled cross-toolchain
               --with-sysroot=/<path_to_your_fedora_mount_directory> \
               --with-freemarker-jar=/<path_to>/freemarker.jar

#<path_to_build_JDK_for_cross_compilation> the `build-JDK` created and moved at step 3,e.g. /home/linux/opt/images/jdk
#<path_to_your_fedora_mount_directory> e.g. /home/linux/opt/fedora_mount
5.交叉编译RISCV64的JDK
现在,可以使用OpenJ9交叉构建OpenJDK了
make clean CONF=linux-riscv64-normal-server-release
make all CONF=linux-riscv64-normal-server-release
6.在Fedora / QEMU上测试JDK
交叉编译完成后,卸载Fedora OS映像。sudo umount /<path_to_your_fedora_mount_directory>
qemu-system-riscv64在步骤2中使用命令通过QEMU引导Fedora :stage4 login: root
Password: riscv
Last login: Fri Oct4 21:21:28 from 10.0.2.2
如果您已经通过QEMU启动了另一个Fedora映像,则无需卸载并启动该Fedora映像。
通过以下scp命令将压缩的JDK上传到Fedora :
主机上操作:cd /home/linux/opt/openj9-openjdk-jdk11/build/linux-riscv64-normal-server-release
zip -r jdk.zip jdk
scp -P 3333 -r /home/linux/opt/openj9-openjdk-jdk11/build/linux-riscv64-normal-server-release/jdk.zip root@localhost:~/
开启Fedora虚拟机并操作:#unzip jdk.zip
转到Fedora上的jdk目录,然后尝试运行java -version命令进行简单测试。# cd bin
# ./java -version
这是一些示例输出:



DaCapo-9.12-bach-MR1 (Xalan-Java Version 2.7.1)测试




参考资料:https://github.com/eclipse/openj9/blob/master/doc/build-instructions/Build_Instructions_V11.md#riscv64


页: [1]
查看完整版本: 【Java on RISC-V】OpenJ9对于RISC-V的支持进展调研与搭建测试