Building OpenJDK 9 on a OSX (or any linux)

This is a tiny tutorial on how to build your own copy of OpenJDK 9 from the current sources.

Contents

Preparation
├─Install a package system
├─Install ccache
└─Command Line Tools
Download OpenJDK 9
Build OpenJDK 9
JTREG
├─JTREG: The variables
└─Running tests
webrev

Preparation

Install a package system

Install brew or macports. I prefer brew. Both are package systems for OS X.

Install ccache

ccache is a compiler cache - speeds up the build.

$ brew install ccache

Command Line Tools

We need them so we have a C compiler and other tools.

Install Xcode Command Line tools ( you don't need the whole Xcode, only the command line tools)

Download OpenJDK 9

Get the sources, in the console type:

$ mkdir jkd9
$ cd jdk9
$ hg clone http://hg.openjdk.java.net/jdk9/dev jdk9.hg

Takes 10-20 secs. This downloads basically a couple of scripts that we will execute to get the actual sources.

Now we execute the script we downloaded:

$ cd jdk9.hg
$ chmod u+x get_source.sh
$ ./get_source.sh

The last command can can take 10-20 minutes depending on the connection speed.

Build OpenJDK 9

$ chmod u+x configure
$ ./configure
$ make clean images

The second command took a bit less than 20 minutes. The first command is fast.

The result: we have this created:  build/macosx-x86_64-normal-server-release/images/jdk/ - this is the built OpenJDK 9 - SUCCESS.

JTREG

jtreg is a "testing harness" (whatever that means) made specially for OpenJDK. We need it to run the tests written for the OpenJDK

Download from https://adopt-openjdk.ci.cloudbees.com/view/OpenJDK/job/jtreg/ (not the Snapshot version, the other one).

unzip in jdk9, so we have jdk9/jtreg.

JTREG: The variables

The official instructions suggest we edit ~/.bashrc. I don't like changing global (for your user) settings, so we can put these settings in jdk9/.bashrc

$ nano .bashrc

Add the following lines:

export SOURCE_CODE=/Users/steve/jdk9/
export JTREG_INSTALL=$SOURCE_CODE/jtreg/
export JT_HOME=$JTREG_INSTALL
export JTREG_HOME=$JTREG_INSTALL
export JPRT_JTREG_HOME=${JT_HOME}
export JPRT_JAVA_HOME=${PRODUCT_HOME}
export JTREG_TIMEOUT_FACTOR=5
export PRODUCT_HOME=$SOURCE_CODE/jdk9.hg/build/macosx-x86_64-normal-server-release/images/jdk
export PATH=$PATH:$PRODUCT_HOME/bin:$JT_HOME/linux/bin/

NOTE: Change /Users/steve/jdk9/ with your folder on the top line.
NOTE: Check the correctness of PRODUCT_HOME too.

To execute this file, do:

$ source .bashrc

Running tests

$ cd jdk9.hg/test
$ make jdk_util

Webrev

Webrev crawls over your changes to generate a set of web-based views of the differences in your code. The different views allow reviewers to easily look at your proposed changes, selecting the appropriate difference format based on the type of file, the type of change, and their own preferences.

webrev.ksh is a 70kb kshell script. Pretty weird.

Go to jdk9.hg and:

jdk9.hg# wget http://hg.openjdk.java.net/code-tools/webrev/raw-file/tip/webrev.ksh
jdk9.hg# chmod u+x webrev.ksh

To prepare a webrev, make some changes. For example in the jaxp folder. Then we commit locally in the mercurial repo.

jdk9.hg# cd jaxp
jaxp# hg commit -m "BGJUG: Fix compiler warnings in jaxp repository"
jaxp# ../webrev.ksh

It will prepare a webrev/ dir and webrev.zip. The folder is then uploaded somewhere and sent to the appropriate mail list inside openjdk. Example:
http://bgjug.sty.bz/bgjug/~bgjug/fix-warnings-jaxp-part1/webrev.00/

Note: execution times come are measured on a pretty recent Macbook Air.

Source: https://java.net/projects/adoptopenjdk/pages/AdoptOpenJDKBuildInstructions

9 thoughts on “Building OpenJDK 9 on a OSX (or any linux)”

  1. I think there's an extra 'x' here where you say x64.

    export PRODUCT_HOME=$SOURCE_CODE/jdk9.hg/build/macosx-x86_x64-normal-server-release/images/jdk

  2. Also - I didn't seem to get a 'bin' directory in my jtreg download, so I got this error when running tests:

    /bin/sh: /Users/jonathan/src/java/jdk9/jtreg//bin/jtreg: No such file or directory

    Otherwise your instructions have been incredibly helpful and I am much obliged.

  3. Sorry for all this spam. I solved the problem by finding another download (last known stable build) and then I linked the linux/bin directory into the level above.

    ln -s linux/bin .

    And that seems to have fixed it. Tests are running now.

  4. If './configure' fails with the error 'unable to find freetype', then you have to install it. It's easy to build and install freetype in Mac OS.

    Download https://sourceforge.net/projects/freetype/files/freetype2/2.6.2/freetype-2.6.2.tar.gz/download this archive
    Extract it
    cd into the folder and run
    ./configure
    make
    sudo make install
    Install XQuartz or build Freetype from sources
    cd freetype
    ./configure
    ./make
    mkdir lib
    cp objs/.libs/libfreetype.dylib lib/

    1. bash configure --with-freetype=/Users/USER_NAME/freetype-2.6.2 --with-freetype-include=/usr/X11/include/freetype2

  5. After configuring as @Alykov mentioned, on MacOS Sierra latest, you also need to disable warning as error to prevent failures due to clang warnings. Run below to update configuration and then try `make clean images`

    ./configure --disable-warnings-as-errors

Leave a Reply

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail. You can also subscribe without commenting.

This site uses Akismet to reduce spam. Learn how your comment data is processed.