Getting started with OpenJDK development
Introduction
The aim of this tutorial is to help you setup your working environment for editing, building, and testing OpenJDK.
Prerequisites
This tutorial assumes that you will be working on Linux and you will be using IntelliJ IDEA as your IDE. You will also need a JDK installed. You can either install the one provided by your linux distribution, e.g.:
sudo dnf install java-11-openjdk-devel
or grab a release from Adoptium.
Setting up JTREG
In order to test your changes in OpenJDK you will also need jtreg
,
installed as the path to jtreg
needs to be provided to the configure
script we will set it up before OpenJDK itself.
-
Clone
jtreg
:git clone https://github.com/openjdk/jtreg.git
-
Enter the directory and build it:
cd jtreg bash make/build.sh --jdk path/to/existing/jdk
This will create the directory
build/images/jtreg
which is thejtreg
home. -
(Optional but recommended) Install the
jtreg
plugin for IntelliJ IDEAThe jtreg repo also contains a plugin for the IntelliJ IDE. This is a convenience plugin which adds jtreg capabilities to the IntelliJ IDE. With this plugin, OpenJDK developers can write, run, and debug jtreg tests without leaving their IDE environment. For more details, see the file plugins/idea/README.md in this repo.
Setting up OpenJDK
-
Clone
git clone https://github.com/openjdk/jdk.git
-
Enter the directory and run
configure
:cd jdk bash configure --with-boot-jdk=path/to/existing/jdk --with-jtreg=path/to/jtreg/build/images/jtreg
Make sure to consult
doc/building.md
for more info and options. -
Build OpenJDK:
make images
Congratulations, you should now have your own build of OpenJDK under
build/linux-x86_64-server-release/images/jdk
. Note, that path might be different depending on your system and configuration. - Start hacking… and recompile with
make images
Running jtreg
tests
Now that we are all set up and know how to build and hack OpenJDK we should also make sure we don't break things :)
To run jtreg
use:
make run-test TEST="hotspot/jtreg"
You can confine the range of the tests to the ones related to your changes by choosing specific sub-directories, e.g.:
make run-test TEST="hotspot/jtreg/compiler/jvmci"
You can also increase the verbosity of jtreg
by setting VERBOSE
inside
the JTREG
environment variable, e.g.:
make run-test JTREG="VERBOSE=all" TEST="hotspot/jtreg/compiler/jvmci"
For the list of available options one may run:
jterg -help "Verbose Options"
which will output something like the following:
Verbose Options These options control the amount of output written to the console while running tests -v | --v:<value> | -verbose | --verbose:<value> Increase the amount of output written to the console. A value, or selected combinations of values separated by commas, may be given to select the type of output desired. default Three lines of output per test: start, end, status summary One line of output per test: status, test name all Selected contents of JTR file for all tests (includes stdout/stderr) pass Selected contents of JTR file for passed tests fail Selected contents of JTR file for failed tests error Selected contents of JTR file for errored tests nopass Suppress output for tests that passed time Elapsed time per action multirun Updates for each testsuite when tests from more than one are being executed. -v1 Short for -verbose:summary -va Short for -verbose:all -ve Short for -verbose:error -vf Short for -verbose:fail -vp Short for -verbose:pass -vt Short for -verbose:time
For the complete list of jtreg
options please refer to
https://openjdk.java.net/jtreg/command-help.html.
For more info about testing OpenJDK please refer to doc/testing.md