1. OpenJ9 JDK on RISC-V
Cheng Jin (jincheng@ca.ibm.com)
OpenJ9 VM Software Developer, IBM Runtime Technologies
chengjin
ChengJin01
2. Important Disclaimers & Legal Notice
• THE INFORMATION CONTAINED IN THIS PRESENTATION IS PROVIDED FOR INFORMATIONAL PURPOSES ONLY.
• IBM AND THE IBM LOGO ARE TRADEMARKS OR REGISTERED TRADEMARKS OF IBM CORPORATION, IN THE UNITED STATES, OTHER COUNTRIES OR
BOTH.
• JAVA AND ALL JAVA-BASED MARKS, AMONG OTHERS, ARE TRADEMARKS OR REGISTERED TRADEMARKS OF ORACLE IN THE UNITED STATES, OTHER
COUNTRIES OR BOTH.
• OTHER COMPANY, PRODUCT AND SERVICE NAMES MAY BE TRADEMARKS OR SERVICE MARKS OF OTHERS.
• WHILST EFFORTS WERE MADE TO VERIFY THE COMPLETENESS AND ACCURACY OF THE INFORMATION CONTAINED IN THIS PRESENTATION, IT IS
PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.
• ALL PERFORMANCE DATA INCLUDED IN THIS PRESENTATION HAVE BEEN GATHERED IN A CONTROLLED
ENVIRONMENT. YOUR OWN TEST RESULTS MAY VARY BASED ON HARDWARE, SOFTWARE OR INFRASTRUCTURE DIFFERENCES.
• ALL DATA INCLUDED IN THIS PRESENTATION ARE MEANT TO BE USED ONLY AS A GUIDE.
• IN ADDITION, THE INFORMATION CONTAINED IN THIS PRESENTATION IS BASED ON IBM’S CURRENT PRODUCT PLANS AND STRATEGY, WHICH ARE
SUBJECT TO CHANGE BY IBM, WITHOUT NOTICE.
• IBM AND ITS AFFILIATED COMPANIES SHALL NOT BE RESPONSIBLE FOR ANY DAMAGES ARISING OUT OF THE USE OF, OR OTHERWISE RELATED TO, THIS
PRESENTATION OR ANY OTHER DOCUMENTATION.
• NOTHING CONTAINED IN THIS PRESENTATION IS INTENDED TO, OR SHALL HAVE THE EFFECT OF:
• CREATING ANY WARRANT OR REPRESENTATION FROM IBM, ITS AFFILIATED COMPANIES OR ITS OR THEIR SUPPLIERS AND/OR LICENSORS
3. Agenda
Background & Motivation of OpenJ9/RISC-V
A Brief History of OpenJ9
What is OpenJ9?
Porting OpenJ9 to RISC-V
Status of OpenJ9/RISC-V
Future Work
Demo
4. Background & Motivation of OpenJ9/RISC-V
Cloud Computing (Centralized)
Long distance from the data source
Network bottleneck for huge volume of data
Security risk for sensitive data
Edge Computing (Decentralized)
Close to the data source
Fast response to real-time data
Data localization
1
“Around 10% of enterprise-generated data is
created and processed outside a traditional
centralized data center or cloud. By 2025,
Gartner predicts this figure will reach 75%”
https://www.gartner.com/smarterwithgartner/what-edge-
computing-means-for-infrastructure-and-operations-leaders
Cloud Computing vs Edge Computing
5. Background & Motivation of OpenJ9/RISC-V (Cont.)
AIoT Edge Node
Runtime / Java
OS
Realtime Control
Management
Data Analysis
AI processing
Hardware
X86
Cloud
Wireless / 5G
Wired / FTTX
2
A solution for AIoT & Edge with lower cost & Lower power consumption is preferable to others
6. A Brief History of OpenJ9
J9 VM developed independently by IBM as Enterprise middleware over 20 years (high
performance, scalability & reliability)
Transition from ENVY/Smalltalk to C/C++ in recent years to lower barrier for developers
Donated to the Eclipse Foundation in 2017 as Eclipse OpenJ9 (currently led by IBM)
Dual License: Eclipse Public License v2.0 & Apache v2.0
J9 is not Java 9 (the naming convention for the Smalltalk source code)
https://en.wikipedia.org/wiki/OpenJ9
3
7. o OpenJDK (https://github.com/ibmruntimes/openj9-openjdk-jdk11): Building framework/Java Class libraries)
o OpenJ9 (https://github.com/eclipse/openj9): Java Virtual Machine Core (equivalent of Hotspot)
o OMR (https://github.com/eclipse/omr): Split from IBM J9 & refactored for polyglot runtimes
What is OpenJ9?
4
OpenJDK/OpenJ9
OMR
Open JDK
HotSpot
OpenJDK/Hotspot
Open JDK
8. The Architecture of OpenJ9 VM
Classloader
JCL natives
Verification
Interpreter
Thread /Port Library
OMR GC
OpenJ9 RAS & DDR
OMR JIT/AOT
OpenJ9 GC OpenJ9 JIT/AOT
OMR
OMR RAS/DDR
OpenJ9 VM
SCC
• Direct Dump Reader (DDR): diagnose issues of OpenJ9 in Java stacktraces at the bytecode level
https://www.slideshare.net/Dev_Events/secrets-of-building-a-debuggable-runtime-learn-how-language-implementors-solve-your-runtime-issues
• Shared Classes Cache (SCC): store J9 ROM Classes & AOT code for better performance (startup time & footprint)
https://developer.ibm.com/technologies/java/tutorials/j-class-sharing-openj9/
What is OpenJ9? (Cont.)
5
9. Porting OpenJ9 JDK to RISC-V (1)
Preparation of Software
Toolchain for cross-compilation
RISC-V GNU Compiler Toolchain at https://github.com/riscv/riscv-gnu-toolchain (compiled from source)
Emulator on the Host system
RISC-V QEMU (riscv64) > 5.0 at https://www.qemu.org/ (compiled from source)
The building instruction at https://wiki.qemu.org/Documentation/Platforms/RISCV/
Linux-based Host System
Ubuntu v19 (Fedora v32, Debian v10, etc)
Linux-based Target System (https://github.com/riscv/riscv-software-list)
64 bit Fedora/RISC-V at https://dl.fedoraproject.org/pub/alt/risc-v/repo/virt-builder-images/images/
64 bit Debian/RISC-V at https://github.com/janvrany/riscv-debian (customized to HiFive U540)
6
10. Porting OpenJ9 JDK to RISC-V (2)
Preparation of Hardware
HiFive Unleashed 540 (64bit U540 SoC)
o Linux-capable RISC-V processor with multi-core
o 8GB DDR4 RAM with ECC
o MicroSD Card (Removable Storage)
o MicroUSB connector
o RJ45 Gigabit Ethernet port
https://sifive.cdn.prismic.io/sifive/8328bc5d-b7ea-4885-a7f9-30fc108b7222_HiFive_Unleashed_Getting_Started_Guide-v1p2.pdf
7
11. Porting OpenJ9 JDK to RISC-V (3)
Development of OpenJ9 JDK on RISC-V
8
OpenJDK
OpenJ9 OMR
Building scripts & Configuration
VM/Interpreter mode
LibFFI-JNI/RISC-V
MISC
Little-Endian
DDR/RISC-V
Port Library
Gencon GC
Atomic Support/CAS
MISC
JIT/AOT (disabled)
Java Native Interface (JNI) support
the Foreign Function Interface (FFI) library on RISC-V from https://github.com/libffi/libffi/tree/master/src/riscv
12. Porting OpenJ9 JDK to RISC-V (4)
Mix of local complication & cross-compilation in OpenJ9 JDK on RISC-V
Local toolchain (on the host system): /usr/bin/gcc & g++, etc
Cross-toochain (on the host system): riscv64-linux-gnu-gcc & g++, etc
9
OpenJ9 JDK
Source
The Host System
OpenJ9 Cross-Build
Cross-Compilation
Local Compilation
Trace
Tools
Trace Constant
& Headers
OpenJ9 bootstrap
& build JDK
Compilation of OpenJ9 JDK/RISC-V
13. Porting OpenJ9 JDK to RISC-V (5)
• OpenJ9 on RISC-V: https://github.com/eclipse/openj9/blob/master/doc/build-instructions/Build_Instructions_V11.md#riscv64
• Fedora/RISCV on U540: https://fedoraproject.org/wiki/Architectures/RISC-V/Installing 10
Debian/RISC-V
Install all libraries
for OpenJDK11
Mounted onto
the host system
WITH
bootstrap
& build JDK
Upload the cross-build to the
target system (emulator)
Upload the
cross-build to
the target
system (U540)
Fedora/RISC-V
Fedora/RISC-V
X86_64
Steps of the cross-compilation Fedora/RISC-V
Debian/RISC-V
U540
Fedora/RISC-V
U540
18. Want to get involved?
https://github.com/eclipse/openj9/issues/5058
https://openj9.slack.com/ (channel #risc-v)
Hinweis der Redaktion
Hello, everyone and many thanks for join this session. My name is Cheng Jin from IBM Ottawa.
I am very excited to this topic because this is the first time to bring OpenJ9 to this conference.
As usual, here are a set of disclaimers and legal notice for your attention.
Do not make any business decision based on my presentation in this topic.
IBM has no responsibility for anything incorrect in the slides.
1) Explain the background of why we were motivated to bring OpenJ9 onto RISC-V
2) Briefly introduce the OpenJ9 project given not too many people in the RISC-V community know about OpenJ9 JDK
3) Walk through a couple of OpenJ9 components as to how it works in OpenJ9
4) Share with you the challenges we faced & how we managed to overcome these obstacles
5) Summarize what we already completed in this project
6) the next steps we expect to push forward
The Cloud framework is a centralized model of analyzing & processing data with extremely powerful hardware and software capability, which is significant in many industries. But the downside of cloud is apparent especially in the current network infrastructure.
the data source is far away from the Cloud in many cases which means it takes longer than expected to transmit data for result.
things getting worse in the network traffic when there are bottlenecks triggered by a huge amount of data.
there are accumulated concerns on the data security in the Cloud so some industries prefer data to be stored & processed locally instead of passing over to the cloud.
some regulations prevent sensitive data from being transmitted across different countries or areas.
The edge computing is fundamentally an extension of cloud close to the data source to make sure all data are processed where they are generated as quickly as possible.
And this decentralized model also helps to save the network bandwidth & the Cloud resources which is valuable for other businesses
The Cloud & Edge devices are working together to get jobs done in a more efficient way in which case part of the Cloud responsibilities is moved to the Edge so the edge devices are intelligently capable of processing data and get back to the data source for better performance & user experience.
The new disruptive technologies like AIoT & 5G will speed up the data generation and transmission from the data source to the edge, which demands mass production & deployment of edge facilities.
RISC-V is more likely to offer a cost-effective solution with lower cost & lower power consumption by customization than others to support AIoT & Edge computing.
From the runtime perspective, there might be a mix of different languages like python, node.j, on the edge devices.
It is natural for OpenJ9 to leverage our Java technologies in the Cloud to extend the RISC-V ecosystem.
OpenJ9, originally called IBM J9, are developed by IBM independently for over 20 years.
It is an industrial-level product with high performance, scalability & reliability.
We transited Smalltalk to C & C++ to lower the barriers for external users.
The whole project was donated to the Eclipse Foundation on Sept 2017 and it is still led by IBM to push technical things forward.
Due licenses provides users with more flexibilities to get involved in the development of OpenJ9.
Java 9 is a number of Java version while J9 named after the IBM internal K8, which is a naming convention of Smalltalk source code.
There are two parts in OpenJDK/Hotspot:
The OpenJDK wrapper which mainly includes the building framework and a bunch of the Java class libraries.
Hotspot, the Virtual machine core.
OpenJ9 JDK is composed pretty much in the same way:
1) OpenJ9 is the equivalent of Hotspot in term of functionalities.
2) OMR originally was part of J9 which mainly thread libraries and port libraries specific to platforms.
This no big technical difference as compared to Hotspot in term of key components.
OpenJ9 VM includes:
1) Classloader which loads class file,
2) Verifier which does bytecode verification during the stage of class loading
3) JCL natives which are native code of OpenJ9 specific Java libraries
4) Interpreter which does the cool things to execute the bytecode all the way to end
5) RAS which consists of a bunch of debugging tools & utilities
6) Garbage collector and Just-In-time Compiler, plus OMR.
There are two components which are unique to OpenJ9.
1) Direct Dump Reader (DDR) generates the metadata for java stack in core dumps so as to debug the java code at the bytecode level
2) Shared Classes Cache (SCC) mainly helps to store JIT/AOT data for better performance which is important for JIT/AOT compiler
1) Cross-toolchain: compile the source code to generate the toolchain.
2) Emulator: we chose Quick EMUlator which supports many hardware platforms including RISC-V.
3) Target OS: we chose Fedora & Debian as the target systems on RISC-V, which are mainstream OS and are customized to HiFive U540, the development board for RISC-V.
Here is a list of features offered by this board (necessary for this project).
1) Linux support as OpenJ9 need to cross-compile and run on this Linux-based target system.
2) a decent memory for execution.
3) To work on the RISC-V target system:
[1] burn the target OS image to the miscro-SD card to boot it up on the board;
[2] log into system through the microUSB connection to determine the IP address;
[3] connect to the target OS with SSH via the IP address.
1) OpenJDK:
[1] no code change in OpenJDK
[2] a bunch of building scripts, makefile, config file, etc were modified to pick up the specified compiling options to have code compiled correctly.
2) OpenJ9:
[1] JIT & AOT was turned off in OpenJ9 to let the virtual machine run in the interpreter mode given this is the first step of the project.
[2] all the endian-specific code in OpenJ9 was updated to handle the data in the right order on RISC-V.
[3] only the basic GC policy (Gencon) was enabled for the moment to see how it goes.
[4] the open sourced Foreign Function Interface Library on RISC-V was integrated into OpenJ9 as we did on other platforms.
[5] a bunch of code in DDR was added to support the dump generation with specified metadata on RISC-V.
3) OMR:
The main changes in OMR include the atomic support and port library which are specific to the hardware or the operation system.
The cross-compilation in OpenJ9 JDK is kind of different from what we usually see how it works.
A couple of trace related tools unique to OpenJ9 that must run on the local system to generate all trace specific constant & headers to be used in the later compilation.
The local toolchain and the cross-toolchain must work together to get things working in this case.
To work around this, we specially designed the building scripts to split up the compilation into two parts.
1) The first part is focusing on the local compilation of the trace tools. Once the tools are generated, they just get started to generate all required artifacts.
2) The cross-toolchain takes over from there to deal with the rest of the compilation.
This diagram shows how to generate a cross-build for RISC-V:
1) boot up the target system on the emulator to download & install all required libraries for OpenJ9.
2) mount this target OS image to the local system for the cross-compilation.
3) once the cross-build is created, upload it to target system on the emulator or hardware for verification.
Note: the cross-build compiled with Fedora/RISC-V works good on Debian/RISC-V and vice versa.
There are two ways to get the bootstrap JDK for the cross-compilation.
1) directly download the latest build of JDK11 from AdoptOpenJDK.
2) follow the building instructions to compile the source code generate a bootstrap build on the local system.
1) It works good on the emulator, whether it comes to Fedora or Debian on RISC-V with different boot loaders.
2) It works good with Debian 5.0 plus BBL on the hardware.
3) We still have problem with the latest Linux kernel plus OpenSBI on U540
1) Probably get a lightweight JIT onboard as an intermediate step and then move forward to implement the full JIT afterwards.
2) Consider to enable other GC strategies to provide users with more options in various application scenarios.
3) Seek the feasibility of generating DDR through the cross-compilation.
4) Currently support Java 11 and will extend the RISC-V support to other JDK LTS version like Java 8, etc.
Demonstrate how to cross-compile an OpenJ9 build on Ubuntu
I really appreciate your time to attend this session.
If you have any question, concerns or suggestions on our project, please let us know.
Many thanks.