X

News, tips, partners, and perspectives for the Oracle Solaris operating system

OpenJDK on Solaris/SPARC

Martin Mueller
Senior Principal Software Engineer

Building OpenJDK Java Releases on Oracle Solaris/SPARC

Starting with Java SE 8, Oracle created the concept of Long-Term-Support (LTS) releases, which are expected to be used and supported for an extended amount of time and for production purposes. Oracle Java SE 8 and Java SE 11 are LTS releases and are available and supported for Oracle Solaris - subject to licensing and support requirements detailed here https://blogs.oracle.com/solaris/update-on-oracle-java-on-oracle-solaris and here https://www.oracle.com/technetwork/java/java-se-support-roadmap.html. Oracle Java SE 9 and Java SE 10 were considered a cumulative set of implementation enhancements of Java SE 8. Once a new feature release is made available, any previous non‑LTS release are considered superseded. The LTS releases are designed to be in production environments while the non-LTS releases provide access to new features ahead of their appearance in a LTS release.

The vast majority of users rely on Java SE 8 and Java SE 11 for their production use. However, Oracle also makes available OpenJDK builds that allow users to test and deploy the latest Java innovations. If you find a need to run a development release of Java on Oracle Solaris, you can access the freely available OpenJDK Java releases http://openjdk.java.net/, under an open source license http://openjdk.java.net/legal/gplv2+ce.html. This article will describe how to build a Java 12 JDK from OpenJDK sources on a recent Oracle Solaris 11.4SRU6 installation on a Oracle SPARC T8-1 system.

Preparing the Operating System

The first step to prepare the OS installaton for development purposes would be to check if the right facet had been installed:

root@t8-1-001:~# pkg facet
FACET                                                            VALUE SRC
devel                                                            True  local
...

Make sure that the "devel" facet is set to true (if it wasn't packages like system/header would not install the full set of include files and thus one would not be able to compile). In case your operating system installation has it set to false, a simple pkg change-facet "facet.devel=True" will fix this, Oracle Solaris will install all the missing files, among others those you would miss in /usr/include.

The OpenJDK website maintains a list of suggested and sometimes tested build enviroments on https://wiki.openjdk.java.net/display/Build/Supported+Build+Platforms, for most Java versions Oracle Solaris Studio 12.4 has been used. We will also use version 12.4, although the latest version according to the list of build environments should work as well.

The build process also needs a few more development tools, namely the GNU binutils suite, the Oracle Solaris assembler, and mercurial to clone the development tree from OpenJDK:

root@t8-1-001:~# pkg install mercurial developer/assembler cc@12.4 c++@12.4 autoconf gnu-binutils
...

Building a JDK from OpenJDK sources also requires a so called "boot JDK" which usually is a JDK one version older than the JDK that is to be built. In our case we need a JDK11 which is available from Oracle's Technology Network pages, https://www.oracle.com/technetwork/java/javase/downloads/jdk11-downloads-5066655.html. It doesn't need not be installed as root, in our example it was installed right into the home directory of a user "oracle" used to build the JDK12.

Now the system is ready to be used as a build environment for OpenJDK.

Building the JDK

An OpenJDK build is similar to many other open source builds, one first has to "configure" the enviroment, and then do the actual build. Note, it is important to use the GNU variant of make, gmake , the "normal" make is not able to process the Makefiles generated during the "configure" step.

But we haven't downloaded the sources yet, these are provided as a mercurial repository. To download the source tree the repository has to be cloned:

oracle@t8-1-001:~$ hg clone http://hg.openjdk.java.net/jdk/jdk12 jdk12-build

This way the OpenJDK 12 build tree is cloned into the directory "jdk12-build". This process takes a few minutes, depending on the speed of your network connection.

The configure step is straightforward and sets up the build directory for the actual build process:

oracle@t8-1-001:~/jdk12-build$ chmod +x configure 
oracle@t8-1-001:~/jdk12-build$ ./configure --with-devkit=/opt/solarisstudio12.4/ --with-boot-jdk=/export/home/oracle/jdk-11.0.2/

If one now issues a gmake one would run into a compile error, src/hotspot/os/solaris/os_solaris.cpp references the undefined constant "EM_486". Oracle Solaris 11.4 removed EM_486 from sys/elf.h , one of the ways to fix this is to delete the corresponding line in os_solaris.cpp .

Now the source tree is ready for building OpenJDK 12 on Oracle Solaris 11.4, gmake will build a Java 12 JDK.

the result will end up in the directory build/solaris-sparcv9-server-release/jdk/ inside the build directory jdk12-build.

Testing the JDK

Now that you have successfully built Java 12 you might want to test it. The resulting JDK12 did end up in build/solaris-sparcv9-server-release/jdk/ n your build directory, jdk12-build in our example. Simply execute

oracle@t8-1-001:~/jdk12-build$ ./build/solaris-sparcv9-server-release/jdk/bin/java -version
openjdk version "12-internal" 2019-03-19
OpenJDK Runtime Environment (build 12-internal+0-adhoc..jdk12-build)
OpenJDK 64-Bit Server VM (build 12-internal+0-adhoc..jdk12-build, mixed mode)

to check that your newly built java can do something. Another way would be to compile a "Hello World" Java program:

oracle@t8-1-001:~$ cat HelloWorld.java 
public class HelloWorld {

    public static void main(String[] args) {
        // Prints "Hello, World" to the terminal window.
        System.out.println("Hello, World");
    }

}

Compile and execute will not create big surprises:

oracle@t8-1-001:~$ ./jdk12-build/build/solaris-sparcv9-server-release/jdk/bin/javac HelloWorld.java 
oracle@t8-1-001:~$ ./jdk12-build/build/solaris-sparcv9-server-release/jdk/bin/java HelloWorld
Hello, World

 

Join the discussion

Comments ( 3 )
  • Christian Röser Tuesday, March 5, 2019
    Hello Martin,
    many thanks for this comprehensive walktrough building latest openjdk version for Solaris 11.4.
    What about going two steps further to integrate this new version of openjdk into Solaris package and mediator environment ?
    We are already able to create new site specific openjdk package and import this into onsite package repository.
    After installation we got this openjdk software configuration (analog to official Oracle JDK solaris integration)
    # ls -l /usr/openjdk/
    drwxrwxr-x 3 root bin 3 Jan 25 16:23 instances
    lrwxrwxrwx 1 root root 18 Jan 25 16:23 latest -> ./openjdk1.8.0_192
    lrwxrwxrwx 1 root root 25 Jan 25 16:23 openjdk1.8.0_192 -> ./instances/openjdk1.8.0/

    Next step would be to set mediator to this new internal openjdk version. Normal mediator setting looks like this:
    # pkg mediator
    MEDIATOR VER. SRC. VERSION IMPL. SRC. IMPLEMENTATION
    java local 1.7 system
    openssl vendor vendor default
    perl vendor 5.12 vendor
    python vendor 2.7 vendor
    sendmail vendor vendor sendmail
    ssh vendor vendor sunssh

    What is the best strategy to be able to switch the java mediator to "internal openjdk" version?

    many thanks,
    Christian
  • Andrew Watkins Friday, March 8, 2019
    Thanks for the blog.

    But, have you tested this a a fresh system and with the public version of Solaris Studio?

    You are missing packages and I believe that you need patched version of Studio 12.4

    Thanks
  • Jermaine Saturday, March 9, 2019
    I couldn’t refrain from commenting. Very well
    written! I’ve been surfing on-line more than 3 hours
    nowadays, yet I by no means discovered any attention-grabbing article like yours.

    It is lovely value sufficient for me. In my view, if
    all site owners and bloggers made just right content material as you probably did,
    the web will probably be much more helpful than ever
    before. Ahaa, its nice discussion concerning this piece of writing at this
    place at this web site, I have read all that,
    so now me also commenting at this place.
    http://cspan.co.uk
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.