Optimized OpenJDK Build for riscv64!

I wasn’t able to find any optimized builds of the JDK for riscv64 (that specifically don’t use the “Zero VM”), so I went ahead and built one for folks to use.

While debian/ubuntu provide openjdk packages, they are built with the interpreted-only Zero VM. However, JDK 19+, offer native riscv64 optimized HotSpot server VMs, if it’s built with that feature. That’s what my build does – it supports GLIBC 2.5+, so its more compatible with various ubuntu and debian versions. You can check it out here: GitHub - fizzed/nitro: Alternative OpenJDK builds for architectures such as riscv64

It has roughly 4-8 x’ed the performance of the JVM on my VF2 and it’s currently beating my RPi4 in many tests. Would love to know what you think or if there’s any other optimizations folks can think of.

10 Likes

I will try my 2D MMO as soon as I get my board…


How long did it take to compile?

3 Likes

Takes around 3 mins to build on my AMD 7950x – this is x86_64 cross compilation, not compilation on the VF2 itself. If you wanna try it locally yourself, build instructions are here: GitHub - fizzed/nitro: Alternative OpenJDK builds for architectures such as riscv64

3 Likes

That’s amazing…
How does that compare to Temurin openJDK’s builds?

Amazing work! Could we upstream this to debian official apt source?

Temurin does not distribute riscv64 builds – if you are seeing something different than I am, please let me know.

It does distribute nightly builds for testing purposes. I have one from last October.

What are the differences between this and GitHub - riscv-collab/riscv-openjdk?

2 Likes

Tinspin, that OpenJDK collab you posted was the work done to make the JIT (e.g. Hotspot) work well for riscv64. What I posted was a binary build of OpenJDK 19 that activated the JIT (e.g. Hotspot) for riscv64. If you try to install debian’s default “openjdk-19-jdk” package, it’ll contain the “zero vm” which isn’t JIT/hotspot and will run very slow.

1 Like

I think those nightly builds from Temurin are activating JIT/Hotspot/ServerVM, so it’d be the same as what I posted, although I built mine off an established tagged release vs. being nightly.

1 Like

besides, work about jdk has merged to upstream jdk repo. riscv collab repo is not used anymore.

2 Likes

Can somebody check run javac & java inside docker?
I have a crash when run java in docker containers, but its work on host machine. I tested jdk-19.0.1+10, 19.0.2+7 from source, 20-ga, with docker images riscv64/ubuntu:22.04, riscv64/ubuntu:22.10, riscv64/debian, handmade images by debootstrap based ubuntu jammy. All variants had a failure. Docker versions 20.10.12, 20.10.23 from ubuntu\debian ports

Okay. I checked your build. Its has same error. Can’t run inside docker. =\
May you can reproduce it?

root@a79928abbc20:/dk/fizzed19.36-jdk19.0.1-linux_riscv64# ./bin/java --version
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGILL (0x4) at pc=0x0000003f7c3efa60, pid=84, tid=85
#
# JRE version:  (19.0.1+10) (build )
# Java VM: OpenJDK 64-Bit Server VM (19.0.1+10, mixed mode, tiered, compressed oops, compressed class ptrs, g1 gc, linux-riscv64)
# Problematic frame:
# v  ~BufferBlob::native signature handlers 0x0000003f7c3efa60
#
# Core dump will be written. Default location: Core dumps may be processed with "/usr/share/apport/apport -p%p -s%s -c%c -d%d -P%P -u%u -g%g -- %E" (or dumping to /dk/fizzed19.36-jdk19.0.1-linux_riscv64/core.84)
#
# An error report file with more information is saved as:
# /dk/fizzed19.36-jdk19.0.1-linux_riscv64/hs_err_pid84.log

#
#
(core dumped)

root@a79928abbc20:/dk/fizzed19.36-jdk19.0.1-linux_riscv64# ./bin/javac --version
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGILL (0x4) at pc=0x0000003f7c3efa60, pid=92, tid=93
#
# JRE version:  (19.0.1+10) (build )
# Java VM: OpenJDK 64-Bit Server VM (19.0.1+10, mixed mode, tiered, compressed oops, compressed class ptrs, g1 gc, linux-riscv64)
# Problematic frame:
# v  ~BufferBlob::native signature handlers 0x0000003f7c3efa60
#
# Core dump will be written. Default location: Core dumps may be processed with "/usr/share/apport/apport -p%p -s%s -c%c -d%d -P%P -u%u -g%g -- %E" (or dumping to /dk/fizzed19.36-jdk19.0.1-linux_riscv64/core.92)
#
# An error report file with more information is saved as:
# /dk/fizzed19.36-jdk19.0.1-linux_riscv64/hs_err_pid92.log
#
#

(core dumped)

root@a79928abbc20:/dk/fizzed19.36-jdk19.0.1-linux_riscv64# 
root@a79928abbc20:/dk/fizzed19.36-jdk19.0.1-linux_riscv64# uname -a
Linux a79928abbc20 5.19.0-1005-starfive #7-Ubuntu SMP Sat Oct 15 12:21:57 UTC 2022 riscv64 riscv64 riscv64 GNU/Linux
root@a79928abbc20:/dk/fizzed19.36-jdk19.0.1-linux_riscv64# cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04 LTS"
root@a79928abbc20:/dk/fizzed19.36-jdk19.0.1-linux_riscv64# 


1 Like

Interesting, if you google it apparently arm64 had issues too at one point. 260872 – java/openjdk8: segfaults on aarch64

Does it run fine NOT in docker for you?

2 Likes

Yes, without docker its work fine.

FYI https://ci.adoptopenjdk.net/job/build-scripts/job/jobs/job/jdk19u/job/jdk19u-linux-riscv64-temurin/24/artifact/workspace/target/OpenJDK19U-jdk_riscv64_linux_hotspot_2023-01-26-16-13.tar.gz should be a build that’s from the 19.0.2+7 codebase but should be considered a beta rather than full “production” release of Temurin as it has not been subject to full testing :slight_smile:
I haven’t got a RISC-V system set up with docker at the moment (My VF2 is broken - see other thread) but it would be good to know if 19.0.2 behaves differently from 19.0.1 in a container.
Similarly if you pull the latest JDk20 build from Artifacts of jdk20-evaluation-linux-riscv64-temurin #20 : /workspace/target [Jenkins] and try that it would give another data point to see if it occurs in the later codebase.

1 Like

Nice to see you there, :wave: and sorry for your board. :cry:
I’m using your JDK20 nighly builds everyday without any issue (not testing extensively, just using). I’ve made a Jenkins job to download and replace the binaries every day, if they are available.

1 Like

I’ve built OpenJDK 11 and 19 for Arch POWER on riscv64 and it runs OK on the VF1/2 in interpreted mode though so don’t expect it to be on par with a Rasberry PI 3 even. :-/

Does this “optimized” build provide JIT?

1 Like

From my understanding, yes, as the Temurin-provided one.

1 Like

That makes it much worthwhile to check it for me :slight_smile: