<h2id="tldr-instructions-for-the-impatient">TL;DR (Instructions for the Impatient)</h2>
<p>If you are eager to try out building OpenJDK, these simple steps works most of the time. They assume that you have installed Mercurial (and Cygwin if running on Windows) and cloned the top-level OpenJDK repository that you want to build.</p>
<oltype="1">
<li><p><ahref="#getting-the-source-code">Get the complete source code</a>:<br/>
<p>If <code>configure</code> fails due to missing dependencies (to either the <ahref="#native-compiler-toolchain-requirements">toolchain</a>, <ahref="#external-library-requirements">external libraries</a> or the <ahref="#boot-jdk-requirements">boot JDK</a>), most of the time it prints a suggestion on how to resolve the situation on your platform. Follow the instructions, and try running <code>bash configure</code> again.</p></li>
<p>If any of these steps failed, or if you want to know more about build requirements or build functionality, please continue reading this document.</p>
<h2id="introduction">Introduction</h2>
<p>OpenJDK is a complex software project. Building it requires a certain amount of technical expertise, a fair number of dependencies on external software, and reasonably powerful hardware.</p>
<p>If you just want to use OpenJDK and not build it yourself, this document is not for you. See for instance <ahref="http://openjdk.java.net/install">OpenJDK installation</a> for some methods of installing a prebuilt OpenJDK.</p>
<h2id="getting-the-source-code">Getting the Source Code</h2>
<p>OpenJDK uses <ahref="http://www.mercurial-scm.org">Mercurial</a> for source control. The source code is contained not in a single Mercurial repository, but in a tree ("forest") of interrelated repositories. You will need to check out all of the repositories to be able to build OpenJDK. To assist you in dealing with this somewhat unusual arrangement, there are multiple tools available, which are explained below.</p>
<p>In any case, make sure you are getting the correct version. At the <ahref="http://hg.openjdk.java.net/">OpenJDK Mercurial server</a> you can see a list of all available forests. If you want to build an older version, e.g. JDK 8, it is recommended that you get the <code>jdk8u</code> forest, which contains incremental updates, instead of the <code>jdk8</code> forest, which was frozen at JDK 8 GA.</p>
<p>If you are new to Mercurial, a good place to start is the <ahref="http://www.mercurial-scm.org/guide">Mercurial Beginner's Guide</a>. The rest of this document assumes a working knowledge of Mercurial.</p>
<li><p>Do not check out the source code in a path which contains spaces. Chances are the build will not work. This is most likely to be an issue on Windows systems.</p></li>
<li><p>Do not check out the source code in a path which has a very long name or is nested many levels deep. Chances are you will hit an OS limitation during the build.</p></li>
<li><p>Put the source code on a local disk, not a network share. If possible, use an SSD. The build process is very disk intensive, and having slow disk access will significantly increase build times. If you need to use a network share for the source code, see below for suggestions on how to keep the build artifacts on a local disk.</p></li>
<li><p>On Windows, extra care must be taken to make sure the <ahref="#cygwin">Cygwin</a> environment is consistent. It is recommended that you follow this procedure:</p>
<li><p>Create the directory that is going to contain the top directory of the OpenJDK clone by using the <code>mkdir</code> command in the Cygwin bash shell. That is, do <em>not</em> create it using Windows Explorer. This will ensure that it will have proper Cygwin attributes, and that it's children will inherit those attributes.</p></li>
<li><p>Do not put the OpenJDK clone in a path under your Cygwin home directory. This is especially important if your user name contains spaces and/or mixed upper and lower case letters.</p></li>
<li><p>Clone the OpenJDK repository using the Cygwin command line <code>hg</code> client as instructed in this document. That is, do <em>not</em> use another Mercurial client such as TortoiseHg.</p></li>
<p>The simplest way to get the entire forest is probably to clone the top-level repository and then run the <code>get_source.sh</code> script, like this:</p>
<p>The first time this is run, it will clone all the sub-repositories. Any subsequent execution of the script will update all sub-repositories to the latest revision.</p>
<h3id="using-hgforest.sh">Using hgforest.sh</h3>
<p>The <code>hgforest.sh</code> script is more expressive than <code>get_source.sh</code>. It takes any number of arguments, and runs <code>hg</code> with those arguments on each sub-repository in the forest. The <code>get_source.sh</code> script is basically a simple wrapper that runs either <code>hgforest.sh clone</code> or <code>hgforest.sh pull -u</code>.</p>
<h3id="using-the-trees-extension">Using the Trees Extension</h3>
<p>The trees extension is a Mercurial add-on that helps you deal with the forest. More information is available on the <ahref="http://openjdk.java.net/projects/code-tools/trees">Code Tools trees page</a>.</p>
<h4id="installing-the-extension">Installing the Extension</h4>
<p>Install the extension by cloning <code>http://hg.openjdk.java.net/code-tools/trees</code> and updating your <code>.hgrc</code> file. Here's one way to do this:</p>
<h4id="initializing-the-tree">Initializing the Tree</h4>
<p>The trees extension needs to know the structure of the forest. If you have already cloned the entire forest using another method, you can initialize the forest like this:</p>
<p>Or you can clone the entire forest at once, if you substitute <code>clone</code> with <code>tclone</code> when cloning the top-level repository, e.g. like this:</p>
<p>In this case, the forest will be properly initialized from the start.</p>
<h4id="other-operations">Other Operations</h4>
<p>The trees extensions supplement many common operations with a trees version by prefixing a <code>t</code> to the normal Mercurial command, e.g. <code>tcommit</code>, <code>tstatus</code> or <code>tmerge</code>. For instance, to update the entire forest:</p>
<p>OpenJDK is a massive project, and require machines ranging from decent to powerful to be able to build in a reasonable amount of time, or to be able to complete a build at all.</p>
<p>We <em>strongly</em> recommend usage of an SSD disk for the build, since disk speed is one of the limiting factors for build performance.</p>
<h3id="building-on-x86">Building on x86</h3>
<p>At a minimum, a machine with 2-4 cores is advisable, as well as 2-4 GB of RAM. (The more cores to use, the more memory you need.) At least 6 GB of free disk space is required (8 GB minimum for building on Solaris).</p>
<p>Even for 32-bit builds, it is recommended to use a 64-bit build machine, and instead create a 32-bit target using <code>--with-target-bits=32</code>.</p>
<h3id="building-on-sparc">Building on sparc</h3>
<p>At a minimum, a machine with 4 cores is advisable, as well as 4 GB of RAM. (The more cores to use, the more memory you need.) At least 8 GB of free disk space is required.</p>
<h3id="building-on-armaarch64">Building on arm/aarch64</h3>
<p>This is not recommended. Instead, see the section on <ahref="#cross-compiling">Cross-compiling</a>.</p>
<h2id="operating-system-requirements">Operating System Requirements</h2>
<p>The mainline OpenJDK project supports Linux, Solaris, macOS, AIX and Windows. Support for other operating system, e.g. BSD, exists in separate "port" projects.</p>
<p>In general, OpenJDK can be built on a wide range of versions of these operating systems, but the further you deviate from what is tested on a daily basis, the more likely you are to run into problems.</p>
<p>This table lists the OS versions used by Oracle when building JDK 9. Such information is always subject to change, but this table is up to date at the time of writing.</p>
<p>The double version numbers for Linux, Solaris and macOS is due to the hybrid model used at Oracle, where header files and external libraries from an older version is used when building on a more modern version of the OS.</p>
<p>The Build Group has a wiki page with <ahref="https://wiki.openjdk.java.net/display/Build/Supported+Build+Platforms">Supported Build Platforms</a>. From time to time, this is updated by the community to list successes or failures of building on different platforms.</p>
<h3id="windows">Windows</h3>
<p>Windows XP is not a supported platform, but all newer Windows should be able to build OpenJDK.</p>
<p>On Windows, it is important that you pay attention to the instructions in the <ahref="#special-considerations">Special Considerations</a>.</p>
<p>Windows is the only non-POSIX OS supported by OpenJDK, and as such, requires some extra care. A POSIX support layer is required to build on Windows. For OpenJDK 9, the only supported such layer is Cygwin. (Msys is no longer supported due to a too old bash; msys2 and the new Windows Subsystem for Linux (WSL) would likely be possible to support in a future version but that would require a community effort to implement.)</p>
<p>Internally in the build system, all paths are represented as Unix-style paths, e.g. <code>/cygdrive/c/hg/jdk9/Makefile</code> rather than <code>C:\hg\jdk9\Makefile</code>. This rule also applies to input to the build system, e.g. in arguments to <code>configure</code>. So, use <code>--with-freetype=/cygdrive/c/freetype</code> rather than <code>--with-freetype=c:\freetype</code>. For details on this conversion, see the section on <ahref="#fixpath">Fixpath</a>.</p>
<h4id="cygwin">Cygwin</h4>
<p>A functioning <ahref="http://www.cygwin.com/">Cygwin</a> environment is thus required for building OpenJDK on Windows. If you have a 64-bit OS, we strongly recommend using the 64-bit version of Cygwin.</p>
<p><strong>Note:</strong> Cygwin has a model of continuously updating all packages without any easy way to install or revert to a specific version of a package. This means that whenever you add or update a package in Cygwin, you might (inadvertently) update tools that are used by the OpenJDK build process, and that can cause unexpected build problems.</p>
<p>OpenJDK requires GNU Make 4.0 or greater on Windows. This is usually not a problem, since Cygwin currently only distributes GNU Make at a version above 4.0.</p>
<p>Apart from the basic Cygwin installation, the following packages must also be installed:</p>
<ul>
<li><code>make</code></li>
<li><code>zip</code></li>
<li><code>unzip</code></li>
</ul>
<p>Often, you can install these packages using the following command line:</p>
<pre><code><path to Cygwin setup>/setup-x86_64 -q -P make -P unzip -P zip</code></pre>
<p>Unfortunately, Cygwin can be unreliable in certain circumstances. If you experience build tool crashes or strange issues when building on Windows, please check the Cygwin FAQ on the <ahref="https://cygwin.com/faq/faq.html#faq.using.bloda">"BLODA" list</a> and the section on <ahref="https://cygwin.com/faq/faq.html#faq.using.fixing-fork-failures">fork() failures</a>.</p>
<h3id="solaris">Solaris</h3>
<p>See <code>make/devkit/solaris11.1-package-list.txt</code> for a list of recommended packages to install when building on Solaris. The versions specified in this list is the versions used by the daily builds at Oracle, and is likely to work properly.</p>
<p>Older versions of Solaris shipped a broken version of <code>objcopy</code>. At least version 2.21.1 is needed, which is provided by Solaris 11 Update 1. Objcopy is needed if you want to have external debug symbols. Please make sure you are using at least version 2.21.1 of objcopy, or that you disable external debug symbols.</p>
<h3id="macos">macOS</h3>
<p>Apple is using a quite aggressive scheme of pushing OS updates, and coupling these updates with required updates of Xcode. Unfortunately, this makes it difficult for a project like OpenJDK to keep pace with a continuously updated machine running macOS. See the section on <ahref="#apple-xcode">Apple Xcode</a> on some strategies to deal with this.</p>
<p>It is recommended that you use at least Mac OS X 10.9 (Mavericks). At the time of writing, OpenJDK has been successfully compiled on macOS versions up to 10.12.5 (Sierra), using XCode 8.3.2 and <code>--disable-warnings-as-errors</code>.</p>
<p>The standard macOS environment contains the basic tooling needed to build, but for external libraries a package manager is recommended. OpenJDK uses <ahref="https://brew.sh/">homebrew</a> in the examples, but feel free to use whatever manager you want (or none).</p>
<h3id="linux">Linux</h3>
<p>It is often not much problem to build OpenJDK on Linux. The only general advice is to try to use the compilers, external libraries and header files as provided by your distribution.</p>
<p>The basic tooling is provided as part of the core operating system, but you will most likely need to install developer packages.</p>
<p>The regular builds by SAP is using AIX version 7.1, but AIX 5.3 is also supported. See the <ahref="http://cr.openjdk.java.net/~simonis/ppc-aix-port">OpenJDK PowerPC Port Status Page</a> for details.</p>
<p>Large portions of OpenJDK consists of native code, that needs to be compiled to be able to run on the target platform. In theory, toolchain and operating system should be independent factors, but in practice there's more or less a one-to-one correlation between target operating system and toolchain.</p>
<p>Please see the individual sections on the toolchains for version recommendations. As a reference, these versions of the toolchains are used, at the time of writing, by Oracle for the daily builds of OpenJDK. It should be possible to compile OpenJDK with both older and newer versions, but the closer you stay to this list, the more likely you are to compile successfully without issues.</p>
<p>The minimum accepted version of gcc is 4.3. Older versions will not be accepted by <code>configure</code>.</p>
<p>However, gcc 4.3 is quite old and OpenJDK is not regularly tested on this version, so it is recommended to use a more modern gcc.</p>
<p>OpenJDK 9 includes patches that should allow gcc 6 to compile, but this should be considered experimental.</p>
<p>In general, any version between these two should be usable.</p>
<h3id="clang">clang</h3>
<p>The minimum accepted version of clang is 3.2. Older versions will not be accepted by <code>configure</code>.</p>
<p>To use clang instead of gcc on Linux, use <code>--with-toolchain-type=clang</code>.</p>
<h3id="apple-xcode">Apple Xcode</h3>
<p>The oldest supported version of Xcode is 5.</p>
<p>You will need the Xcode command lines developers tools to be able to build OpenJDK. (Actually, <em>only</em> the command lines tools are needed, not the IDE.) The simplest way to install these is to run:</p>
<pre><code>xcode-select --install</code></pre>
<p>It is advisable to keep an older version of Xcode for building OpenJDK when updating Xcode. This <ahref="http://iosdevelopertips.com/xcode/install-multiple-versions-of-xcode.html">blog page</a> has good suggestions on managing multiple Xcode versions. To use a specific version of Xcode, use <code>xcode-select -s</code> before running <code>configure</code>, or use <code>--with-toolchain-path</code> to point to the version of Xcode to use, e.g. <code>configure --with-toolchain-path=/Applications/Xcode5.app/Contents/Developer/usr/bin</code></p>
<p>If you have recently (inadvertently) updated your OS and/or Xcode version, and OpenJDK can no longer be built, please see the section on <ahref="#problems-with-the-build-environment">Problems with the Build Environment</a>, and <ahref="#getting-help">Getting Help</a> to find out if there are any recent, non-merged patches available for this update.</p>
<h3id="oracle-solaris-studio">Oracle Solaris Studio</h3>
<p>The minimum accepted version of the Solaris Studio compilers is 5.13 (corresponding to Solaris Studio 12.4). Older versions will not be accepted by configure.</p>
<p>The Solaris Studio installation should contain at least these packages:</p>
<p>Compiling with Solaris Studio can sometimes be finicky. This is the exact version used by Oracle, which worked correctly at the time of writing:</p>
<pre><code>$ cc -V
cc: Sun C 5.13 SunOS_i386 2014/10/20
$ CC -V
CC: Sun C++ 5.13 SunOS_i386 151846-10 2015/10/30</code></pre>
<p>The minimum accepted version of Visual Studio is 2010. Older versions will not be accepted by <code>configure</code>. The maximum accepted version of Visual Studio is 2013.</p>
<p>If you have multiple versions of Visual Studio installed, <code>configure</code> will by default pick the latest. You can request a specific version to be used by setting <code>--with-toolchain-version</code>, e.g. <code>--with-toolchain-version=2010</code>.</p>
<p>If you get <code>LINK: fatal error LNK1123: failure during conversion to COFF: file invalid</code> when building using Visual Studio 2010, you have encountered <ahref="http://support.microsoft.com/kb/2757355">KB2757355</a>, a bug triggered by a specific installation order. However, the solution suggested by the KB article does not always resolve the problem. See <ahref="https://stackoverflow.com/questions/10888391">this stackoverflow discussion</a> for other suggestions.</p>
<h3id="ibm-xl-cc">IBM XL C/C++</h3>
<p>The regular builds by SAP is using version 12.1, described as <code>IBM XL C/C++ for AIX, V12.1 (5765-J02, 5725-C72) Version: 12.01.0000.0017</code>.</p>
<p>See the <ahref="http://cr.openjdk.java.net/~simonis/ppc-aix-port">OpenJDK PowerPC Port Status Page</a> for details.</p>
<p>Paradoxically, building OpenJDK requires a pre-existing JDK. This is called the "boot JDK". The boot JDK does not have to be OpenJDK, though. If you are porting OpenJDK to a new platform, chances are that there already exists another JDK for that platform that is usable as boot JDK.</p>
<p>The rule of thumb is that the boot JDK for building JDK major version <em>N</em> should be an JDK of major version <em>N-1</em>, so for building JDK 9 a JDK 8 would be suitable as boot JDK. However, OpenJDK should be able to "build itself", so an up-to-date build of the current OpenJDK source is an acceptable alternative. If you are following the <em>N-1</em> rule, make sure you got the latest update version, since JDK 8 GA might not be able to build JDK 9 on all platforms.</p>
<p>If the Boot JDK is not automatically detected, or the wrong JDK is picked, use <code>--with-boot-jdk</code> to point to the JDK to use.</p>
<h3id="jdk-8-on-linux">JDK 8 on Linux</h3>
<p>On apt-based distros (like Debian and Ubuntu), <code>sudo apt-get install openjdk-8-jdk</code> is typically enough to install OpenJDK 8. On rpm-based distros (like Fedora and Red Hat), try <code>sudo yum install java-1.8.0-openjdk-devel</code>.</p>
<h3id="jdk-8-on-windows">JDK 8 on Windows</h3>
<p>No pre-compiled binaries of OpenJDK 8 are readily available for Windows at the time of writing. An alternative is to download the <ahref="http://www.oracle.com/technetwork/java/javase/downloads">Oracle JDK</a>. Another is the <ahref="https://adoptopenjdk.net/">Adopt OpenJDK Project</a>, which publishes experimental prebuilt binaries for Windows.</p>
<h3id="jdk-8-on-macos">JDK 8 on macOS</h3>
<p>No pre-compiled binaries of OpenJDK 8 are readily available for macOS at the time of writing. An alternative is to download the <ahref="http://www.oracle.com/technetwork/java/javase/downloads">Oracle JDK</a>, or to install it using <code>brew cask install java</code>. Another option is the <ahref="https://adoptopenjdk.net/">Adopt OpenJDK Project</a>, which publishes experimental prebuilt binaries for macOS.</p>
<h3id="jdk-8-on-aix">JDK 8 on AIX</h3>
<p>No pre-compiled binaries of OpenJDK 8 are readily available for AIX at the time of writing. A starting point for working with OpenJDK on AIX is the <ahref="http://openjdk.java.net/projects/ppc-aix-port/">PowerPC/AIX Port Project</a>.</p>
<p>Different platforms require different external libraries. In general, libraries are not optional - that is, they are either required or not used.</p>
<p>If a required library is not detected by <code>configure</code>, you need to provide the path to it. There are two forms of the <code>configure</code> arguments to point to an external library: <code>--with-<LIB>=<path></code> or <code>--with-<LIB>-include=<path to include> --with-<LIB>-lib=<path to lib></code>. The first variant is more concise, but require the include files an library files to reside in a default hierarchy under this directory. In most cases, it works fine.</p>
<p>As a fallback, the second version allows you to point to the include directory and the lib directory separately.</p>
<h3id="freetype">FreeType</h3>
<p>FreeType2 from <ahref="http://www.freetype.org/">The FreeType Project</a> is required on all platforms. At least version 2.3 is required.</p>
<p>Use <code>--with-freetype=<path></code> if <code>configure</code> does not properly locate your FreeType files.</p>
<h4id="building-freetype-on-windows">Building FreeType on Windows</h4>
<p>On Windows, there is no readily available compiled version of FreeType. OpenJDK can help you compile FreeType from source. Download the FreeType sources and unpack them into an arbitrary directory:</p>
<p>Then run <code>configure</code> with <code>--with-freetype-src=<freetype_src></code>. This will automatically build the freetype library into <code><freetype_src>/lib64</code> for 64-bit builds or into <code><freetype_src>/lib32</code> for 32-bit builds. Afterwards you can always use <code>--with-freetype-include=<freetype_src>/include</code> and <code>--with-freetype-lib=<freetype_src>/lib[32|64]</code> for other builds.</p>
<p>Alternatively you can unpack the sources like this to use the default directory:</p>
<p>CUPS, <ahref="http://www.cups.org">Common UNIX Printing System</a> header files are required on all platforms, except Windows. Often these files are provided by your operating system.</p>
<ul>
<li>To install on an apt-based Linux, try running <code>sudo apt-get install libcups2-dev</code>.</li>
<li>To install on an rpm-based Linux, try running <code>sudo yum install cups-devel</code>.</li>
<li>To install on Solaris, try running <code>pkg install print/cups</code>.</li>
<p>Use <code>--with-x=<path></code> if <code>configure</code> does not properly locate your X11 files.</p>
<h3id="alsa">ALSA</h3>
<p>ALSA, <ahref="https://www.alsa-project.org/">Advanced Linux Sound Architecture</a> is required on Linux. At least version 0.9.1 of ALSA is required.</p>
<p>Use <code>--with-alsa=<path></code> if <code>configure</code> does not properly locate your ALSA files.</p>
<h3id="libffi">libffi</h3>
<p>libffi, the <ahref="http://sourceware.org/libffi">Portable Foreign Function Interface Library</a> is required when building the Zero version of Hotspot.</p>
<ul>
<li>To install on an apt-based Linux, try running <code>sudo apt-get install libffi-dev</code>.</li>
<li>To install on an rpm-based Linux, try running <code>sudo yum install libffi-devel</code>.</li>
</ul>
<p>Use <code>--with-libffi=<path></code> if <code>configure</code> does not properly locate your libffi files.</p>
<p>OpenJDK requires <ahref="http://www.gnu.org/software/make">GNU Make</a>. No other flavors of make are supported.</p>
<p>At least version 3.81 of GNU Make must be used. For distributions supporting GNU Make 4.0 or above, we strongly recommend it. GNU Make 4.0 contains useful functionality to handle parallel building (supported by <code>--with-output-sync</code>) and speed and stability improvements.</p>
<p>Note that <code>configure</code> locates and verifies a properly functioning version of <code>make</code> and stores the path to this <code>make</code> binary in the configuration. If you start a build using <code>make</code> on the command line, you will be using the version of make found first in your <code>PATH</code>, and not necessarily the one stored in the configuration. This initial make will be used as "bootstrap make", and in a second stage, the make located by <code>configure</code> will be called. Normally, this will present no issues, but if you have a very old <code>make</code>, or a non-GNU Make <code>make</code> in your path, this might cause issues.</p>
<p>If you want to override the default make found by <code>configure</code>, use the <code>MAKE</code> configure variable, e.g. <code>configure MAKE=/opt/gnu/make</code>.</p>
<p>On Solaris, it is common to call the GNU version of make by using <code>gmake</code>.</p>
<h3id="gnu-bash">GNU Bash</h3>
<p>OpenJDK requires <ahref="http://www.gnu.org/software/bash">GNU Bash</a>. No other shells are supported.</p>
<p>At least version 3.2 of GNU Bash must be used.</p>
<h3id="autoconf">Autoconf</h3>
<p>If you want to modify the build system itself, you need to install <ahref="http://www.gnu.org/software/autoconf">Autoconf</a>.</p>
<p>However, if you only need to build OpenJDK or if you only edit the actual OpenJDK source files, there is no dependency on autoconf, since the source distribution includes a pre-generated <code>configure</code> shell script.</p>
<p>See the section on <ahref="#autoconf-details">Autoconf Details</a> for details on how OpenJDK uses autoconf. This is especially important if you plan to contribute changes to OpenJDK that modifies the build system.</p>
<h2id="running-configure">Running Configure</h2>
<p>To build OpenJDK, you need a "configuration", which consists of a directory where to store the build output, coupled with information about the platform, the specific build machine, and choices that affect how OpenJDK is built.</p>
<p>The configuration is created by the <code>configure</code> script. The basic invocation of the <code>configure</code> script looks like this:</p>
<pre><code>bash configure [options]</code></pre>
<p>This will create an output directory containing the configuration and setup an area for the build result. This directory typically looks like <code>build/linux-x64-normal-server-release</code>, but the actual name depends on your specific configuration. (It can also be set directly, see <ahref="#using-multiple-configurations">Using Multiple Configurations</a>). This directory is referred to as <code>$BUILD</code> in this documentation.</p>
<p><code>configure</code> will try to figure out what system you are running on and where all necessary build components are. If you have all prerequisites for building installed, it should find everything. If it fails to detect any component automatically, it will exit and inform you about the problem.</p>
<p>Some command line examples:</p>
<ul>
<li><p>Create a 32-bit build for Windows with FreeType2 in <code>C:\freetype-i586</code>:</p>
<p>Here follows some of the most common and important <code>configure</code> argument.</p>
<p>To get up-to-date information on <em>all</em> available <code>configure</code> argument, please run:</p>
<pre><code>bash configure --help</code></pre>
<p>(Note that this help text also include general autoconf options, like <code>--dvidir</code>, that is not relevant to OpenJDK. To list only OpenJDK specific features, use <code>bash configure --help=short</code> instead.)</p>
<h4id="configure-arguments-for-tailoring-the-build">Configure Arguments for Tailoring the Build</h4>
<ul>
<li><code>--enable-debug</code> - Set the debug level to <code>fastdebug</code> (this is a shorthand for <code>--with-debug-level=fastdebug</code>)</li>
<li><code>--with-debug-level=<level></code> - Set the debug level, which can be <code>release</code>, <code>fastdebug</code>, <code>slowdebug</code> or <code>optimized</code>. Default is <code>release</code>. <code>optimized</code> is variant of <code>release</code> with additional Hotspot debug code.</li>
<li><code>--with-native-debug-symbols=<method></code> - Specify if and how native debug symbols should be built. Available methods are <code>none</code>, <code>internal</code>, <code>external</code>, <code>zipped</code>. Default behavior depends on platform. See <ahref="#native-debug-symbols">Native Debug Symbols</a> for more details.</li>
<li><code>--with-version-string=<string></code> - Specify the version string this build will be identified with.</li>
<li><code>--with-version-<part>=<value></code> - A group of options, where <code><part></code> can be any of <code>pre</code>, <code>opt</code>, <code>build</code>, <code>major</code>, <code>minor</code>, <code>security</code> or <code>patch</code>. Use these options to modify just the corresponding part of the version string from the default, or the value provided by <code>--with-version-string</code>.</li>
<li><code>--with-jvm-variants=<variant>[,<variant>...]</code> - Build the specified variant (or variants) of Hotspot. Valid variants are: <code>server</code>, <code>client</code>, <code>minimal</code>, <code>core</code>, <code>zero</code>, <code>zeroshark</code>, <code>custom</code>. Note that not all variants are possible to combine in a single build.</li>
<li><code>--with-jvm-features=<feature>[,<feature>...]</code> - Use the specified JVM features when building Hotspot. The list of features will be enabled on top of the default list. For the <code>custom</code> JVM variant, this default list is empty. A complete list of available JVM features can be found using <code>bash configure --help</code>.</li>
<li><code>--with-target-bits=<bits></code> - Create a target binary suitable for running on a <code><bits></code> platform. Use this to create 32-bit output on a 64-bit build platform, instead of doing a full cross-compile. (This is known as a <em>reduced</em> build.)</li>
</ul>
<h4id="configure-arguments-for-native-compilation">Configure Arguments for Native Compilation</h4>
<ul>
<li><code>--with-devkit=<path></code> - Use this devkit for compilers, tools and resources</li>
<li><code>--with-sysroot=<path></code> - Use this directory as sysroot</li>
<li><code>--with-extra-path=<path>[;<path>]</code> - Prepend these directories to the default path when searching for all kinds of binaries</li>
<li><code>--with-toolchain-path=<path>[;<path>]</code> - Prepend these directories when searching for toolchain binaries (compilers etc)</li>
<li><code>--with-extra-cflags=<flags></code> - Append these flags when compiling JDK C files</li>
<li><code>--with-extra-cxxflags=<flags></code> - Append these flags when compiling JDK C++ files</li>
<li><code>--with-extra-ldflags=<flags></code> - Append these flags when linking JDK libraries</li>
</ul>
<h4id="configure-arguments-for-external-dependencies">Configure Arguments for External Dependencies</h4>
<ul>
<li><code>--with-boot-jdk=<path></code> - Set the path to the <ahref="#boot-jdk-requirements">Boot JDK</a></li>
<li><code>--with-freetype=<path></code> - Set the path to <ahref="#freetype">FreeType</a></li>
<li><code>--with-cups=<path></code> - Set the path to <ahref="#cups">CUPS</a></li>
<li><code>--with-x=<path></code> - Set the path to <ahref="#x11">X11</a></li>
<li><code>--with-alsa=<path></code> - Set the path to <ahref="#alsa">ALSA</a></li>
<li><code>--with-libffi=<path></code> - Set the path to <ahref="#libffi">libffi</a></li>
<li><code>--with-jtreg=<path></code> - Set the path to JTReg. See <ahref="#running-tests">Running Tests</a></li>
</ul>
<p>Certain third-party libraries used by OpenJDK (libjpeg, giflib, libpng, lcms and zlib) are included in the OpenJDK repository. The default behavior of the OpenJDK build is to use this version of these libraries, but they might be replaced by an external version. To do so, specify <code>system</code> as the <code><source></code> option in these arguments. (The default is <code>bundled</code>).</p>
<ul>
<li><code>--with-libjpeg=<source></code> - Use the specified source for libjpeg</li>
<li><code>--with-giflib=<source></code> - Use the specified source for giflib</li>
<li><code>--with-libpng=<source></code> - Use the specified source for libpng</li>
<li><code>--with-lcms=<source></code> - Use the specified source for lcms</li>
<li><code>--with-zlib=<source></code> - Use the specified source for zlib</li>
</ul>
<p>On Linux, it is possible to select either static or dynamic linking of the C++ runtime. The default is static linking, with dynamic linking as fallback if the static library is not found.</p>
<ul>
<li><code>--with-stdc++lib=<method></code> - Use the specified method (<code>static</code>, <code>dynamic</code> or <code>default</code>) for linking the C++ runtime.</li>
</ul>
<h3id="configure-control-variables">Configure Control Variables</h3>
<p>It is possible to control certain aspects of <code>configure</code> by overriding the value of <code>configure</code> variables, either on the command line or in the environment.</p>
<p>Normally, this is <strong>not recommended</strong>. If used improperly, it can lead to a broken configuration. Unless you're well versed in the build system, this is hard to use properly. Therefore, <code>configure</code> will print a warning if this is detected.</p>
<p>However, there are a few <code>configure</code> variables, known as <em>control variables</em> that are supposed to be overriden on the command line. These are variables that describe the location of tools needed by the build, like <code>MAKE</code> or <code>GREP</code>. If any such variable is specified, <code>configure</code> will use that value instead of trying to autodetect the tool. For instance, <code>bash configure MAKE=/opt/gnumake4.0/bin/make</code>.</p>
<p>If a configure argument exists, use that instead, e.g. use <code>--with-jtreg</code> instead of setting <code>JTREGEXE</code>.</p>
<p>Also note that, despite what autoconf claims, setting <code>CFLAGS</code> will not accomplish anything. Instead use <code>--with-extra-cflags</code> (and similar for <code>cxxflags</code> and <code>ldflags</code>).</p>
<h2id="running-make">Running Make</h2>
<p>When you have a proper configuration, all you need to do to build OpenJDK is to run <code>make</code>. (But see the warning at <ahref="#gnu-make">GNU Make</a> about running the correct version of make.)</p>
<p>When running <code>make</code> without any arguments, the default target is used, which is the same as running <code>make default</code> or <code>make jdk</code>. This will build a minimal (or roughly minimal) set of compiled output (known as an "exploded image") needed for a developer to actually execute the newly built JDK. The idea is that in an incremental development fashion, when doing a normal make, you should only spend time recompiling what's changed (making it purely incremental) and only do the work that's needed to actually run and test your code.</p>
<p>The output of the exploded image resides in <code>$BUILD/jdk</code>. You can test the newly built JDK like this: <code>$BUILD/jdk/bin/java -version</code>.</p>
<h3id="common-make-targets">Common Make Targets</h3>
<p>Apart from the default target, here are some common make targets:</p>
<ul>
<li><code>hotspot</code> - Build all of hotspot (but only hotspot)</li>
<li><code>hotspot-<variant></code> - Build just the specified jvm variant</li>
<li><code>images</code> or <code>product-images</code> - Build the JRE and JDK images</li>
<li><code>docs</code> or <code>docs-image</code> - Build the documentation image</li>
<li><code>test-image</code> - Build the test image</li>
<li><code>all</code> or <code>all-images</code> - Build all images (product, docs and test)</li>
<li><code>bootcycle-images</code> - Build images twice, second time with newly built JDK (good for testing)</li>
<li><code>clean</code> - Remove all files generated by make, but not those generated by configure</li>
<li><code>dist-clean</code> - Remove all files, including configuration</li>
</ul>
<p>Run <code>make help</code> to get an up-to-date list of important make targets and make control variables.</p>
<p>It is possible to build just a single module, a single phase, or a single phase of a single module, by creating make targets according to these followin patterns. A phase can be either of <code>gensrc</code>, <code>gendata</code>, <code>copy</code>, <code>java</code>, <code>launchers</code>, <code>libs</code> or <code>rmic</code>. See <ahref="#using-fine-grained-make-targets">Using Fine-Grained Make Targets</a> for more details about this functionality.</p>
<ul>
<li><code><phase></code> - Build the specified phase and everything it depends on</li>
<li><code><module></code> - Build the specified module and everything it depends on</li>
<li><code><module>-<phase></code> - Compile the specified phase for the specified module and everything it depends on</li>
</ul>
<p>Similarly, it is possible to clean just a part of the build by creating make targets according to these patterns:</p>
<ul>
<li><code>clean-<outputdir></code> - Remove the subdir in the output dir with the name</li>
<li><code>clean-<phase></code> - Remove all build results related to a certain build phase</li>
<li><code>clean-<module></code> - Remove all build results related to a certain module</li>
<li><code>clean-<module>-<phase></code> - Remove all build results related to a certain module and phase</li>
</ul>
<h3id="make-control-variables">Make Control Variables</h3>
<p>It is possible to control <code>make</code> behavior by overriding the value of <code>make</code> variables, either on the command line or in the environment.</p>
<p>Normally, this is <strong>not recommended</strong>. If used improperly, it can lead to a broken build. Unless you're well versed in the build system, this is hard to use properly. Therefore, <code>make</code> will print a warning if this is detected.</p>
<p>However, there are a few <code>make</code> variables, known as <em>control variables</em> that are supposed to be overriden on the command line. These make up the "make time" configuration, as opposed to the "configure time" configuration.</p>
<h4id="general-make-control-variables">General Make Control Variables</h4>
<ul>
<li><code>JOBS</code> - Specify the number of jobs to build with. See <ahref="#build-performance">Build Performance</a>.</li>
<li><code>LOG</code> - Specify the logging level and functionality. See <ahref="#checking-the-build-log-file">Checking the Build Log File</a></li>
<li><code>CONF</code> and <code>CONF_NAME</code> - Selecting the configuration(s) to use. See <ahref="#using-multiple-configurations">Using Multiple Configurations</a></li>
</ul>
<h4id="test-make-control-variables">Test Make Control Variables</h4>
<p>These make control variables only make sense when running tests. Please see <ahref="testing.html">Testing OpenJDK</a> for details.</p>
<ul>
<li><code>TEST</code></li>
<li><code>TEST_JOBS</code></li>
<li><code>JTREG</code></li>
<li><code>GTEST</code></li>
</ul>
<h4id="advanced-make-control-variables">Advanced Make Control Variables</h4>
<p>These advanced make control variables can be potentially unsafe. See <ahref="#hints-and-suggestions-for-advanced-users">Hints and Suggestions for Advanced Users</a> and <ahref="#understanding-the-build-system">Understanding the Build System</a> for details.</p>
<ul>
<li><code>SPEC</code></li>
<li><code>CONF_CHECK</code></li>
<li><code>COMPARE_BUILD</code></li>
<li><code>JDK_FILTER</code></li>
</ul>
<h2id="running-tests">Running Tests</h2>
<p>Most of the OpenJDK tests are using the <ahref="http://openjdk.java.net/jtreg">JTReg</a> test framework. Make sure that your configuration knows where to find your installation of JTReg. If this is not picked up automatically, use the <code>--with-jtreg=<path to jtreg home></code> option to point to the JTReg framework. Note that this option should point to the JTReg home, i.e. the top directory, containing <code>lib/jtreg.jar</code> etc.</p>
<p>To execute the most basic tests (tier 1), use:</p>
<pre><code>make run-test-tier1</code></pre>
<p>For more details on how to run tests, please see the <ahref="testing.html">Testing OpenJDK</a> document.</p>
<h2id="cross-compiling">Cross-compiling</h2>
<p>Cross-compiling means using one platform (the <em>build</em> platform) to generate output that can ran on another platform (the <em>target</em> platform).</p>
<p>The typical reason for cross-compiling is that the build is performed on a more powerful desktop computer, but the resulting binaries will be able to run on a different, typically low-performing system. Most of the complications that arise when building for embedded is due to this separation of <em>build</em> and <em>target</em> systems.</p>
<p>This requires a more complex setup and build procedure. This section assumes you are familiar with cross-compiling in general, and will only deal with the particularities of cross-compiling OpenJDK. If you are new to cross-compiling, please see the <ahref="https://en.wikipedia.org/wiki/Cross_compiler#External_links">external links at Wikipedia</a> for a good start on reading materials.</p>
<p>Cross-compiling OpenJDK requires you to be able to build both for the build platform and for the target platform. The reason for the former is that we need to build and execute tools during the build process, both native tools and Java tools.</p>
<p>If all you want to do is to compile a 32-bit version, for the same OS, on a 64-bit machine, consider using <code>--with-target-bits=32</code> instead of doing a full-blown cross-compilation. (While this surely is possible, it's a lot more work and will take much longer to build.)</p>
<h3id="boot-jdk-and-build-jdk">Boot JDK and Build JDK</h3>
<p>When cross-compiling, make sure you use a boot JDK that runs on the <em>build</em> system, and not on the <em>target</em> system.</p>
<p>To be able to build, we need a "Build JDK", which is a JDK built from the current sources (that is, the same as the end result of the entire build process), but able to run on the <em>build</em> system, and not the <em>target</em> system. (In contrast, the Boot JDK should be from an older release, e.g. JDK 8 when building JDK 9.)</p>
<p>The build process will create a minimal Build JDK for you, as part of building. To speed up the build, you can use <code>--with-build-jdk</code> to <code>configure</code> to point to a pre-built Build JDK. Please note that the build result is unpredictable, and can possibly break in subtle ways, if the Build JDK does not <strong>exactly</strong> match the current sources.</p>
<h3id="specifying-the-target-platform">Specifying the Target Platform</h3>
<p>You <em>must</em> specify the target platform when cross-compiling. Doing so will also automatically turn the build into a cross-compiling mode. The simplest way to do this is to use the <code>--openjdk-target</code> argument, e.g. <code>--openjdk-target=arm-linux-gnueabihf</code>. or <code>--openjdk-target=aarch64-oe-linux</code>. This will automatically set the <code>--build</code>, <code>--host</code> and <code>--target</code> options for autoconf, which can otherwise be confusing. (In autoconf terminology, the "target" is known as "host", and "target" is used for building a Canadian cross-compiler.)</p>
<p>You will need two copies of your toolchain, one which generates output that can run on the target system (the normal, or <em>target</em>, toolchain), and one that generates output that can run on the build system (the <em>build</em> toolchain). Note that cross-compiling is only supported for gcc at the time being. The gcc standard is to prefix cross-compiling toolchains with the target denominator. If you follow this standard, <code>configure</code> is likely to pick up the toolchain correctly.</p>
<p>The <em>build</em> toolchain will be autodetected just the same way the normal <em>build</em>/<em>target</em> toolchain will be autodetected when not cross-compiling. If this is not what you want, or if the autodetection fails, you can specify a devkit containing the <em>build</em> toolchain using <code>--with-build-devkit</code> to <code>configure</code>, or by giving <code>BUILD_CC</code> and <code>BUILD_CXX</code> arguments.</p>
<p>It is often helpful to locate the cross-compilation tools, headers and libraries in a separate directory, outside the normal path, and point out that directory to <code>configure</code>. Do this by setting the sysroot (<code>--with-sysroot</code>) and appending the directory when searching for cross-compilations tools (<code>--with-toolchain-path</code>). As a compact form, you can also use <code>--with-devkit</code> to point to a single directory, if it is correctly setup. (See <code>basics.m4</code> for details.)</p>
<p>If you are unsure what toolchain and versions to use, these have been proved working at the time of writing:</p>
<p>You will need copies of external native libraries for the <em>target</em> system, present on the <em>build</em> machine while building.</p>
<p>Take care not to replace the <em>build</em> system's version of these libraries by mistake, since that can render the <em>build</em> machine unusable.</p>
<p>Make sure that the libraries you point to (ALSA, X11, etc) are for the <em>target</em>, not the <em>build</em>, platform.</p>
<h4id="alsa-1">ALSA</h4>
<p>You will need alsa libraries suitable for your <em>target</em> system. For most cases, using Debian's pre-built libraries work fine.</p>
<p>Note that alsa is needed even if you only want to build a headless JDK.</p>
<ul>
<li><p>Go to <ahref="https://www.debian.org/distrib/packages">Debian Package Search</a> and search for the <code>libasound2</code> and <code>libasound2-dev</code> packages for your <em>target</em> system. Download them to /tmp.</p></li>
<li><p>Install the libraries into the cross-compilation toolchain. For instance:</p>
<li><p>If alsa is not properly detected by <code>configure</code>, you can point it out by <code>--with-alsa</code>.</p></li>
</ul>
<h4id="x11-1">X11</h4>
<p>You will need X11 libraries suitable for your <em>target</em> system. For most cases, using Debian's pre-built libraries work fine.</p>
<p>Note that X11 is needed even if you only want to build a headless JDK.</p>
<ul>
<li>Go to <ahref="https://www.debian.org/distrib/packages">Debian Package Search</a>, search for the following packages for your <em>target</em> system, and download them to /tmp/target-x11:
<ul>
<li>libxi</li>
<li>libxi-dev</li>
<li>x11proto-core-dev</li>
<li>x11proto-input-dev</li>
<li>x11proto-kb-dev</li>
<li>x11proto-render-dev</li>
<li>x11proto-xext-dev</li>
<li>libice-dev</li>
<li>libxrender</li>
<li>libxrender-dev</li>
<li>libsm-dev</li>
<li>libxt-dev</li>
<li>libx11</li>
<li>libx11-dev</li>
<li>libxtst</li>
<li>libxtst-dev</li>
<li>libxext</li>
<li>libxext-dev</li>
</ul></li>
<li><p>Install the libraries into the cross-compilation toolchain. For instance:</p>
for deb in /tmp/target-x11/*.deb ; do dpkg-deb -x $deb . ; done
mv usr/* .
cd lib
cp arm-linux-gnueabihf/* .</code></pre>
<p>You can ignore the following messages. These libraries are not needed to successfully complete a full JDK build.</p>
<pre><code>cp: cannot stat `arm-linux-gnueabihf/libICE.so': No such file or directory
cp: cannot stat `arm-linux-gnueabihf/libSM.so': No such file or directory
cp: cannot stat `arm-linux-gnueabihf/libXt.so': No such file or directory</code></pre></li>
<li><p>If the X11 libraries are not properly detected by <code>configure</code>, you can point them out by <code>--with-x</code>.</p></li>
</ul>
<h3id="building-for-armaarch64">Building for ARM/aarch64</h3>
<p>A common cross-compilation target is the ARM CPU. When building for ARM, it is useful to set the ABI profile. A number of pre-defined ABI profiles are available using <code>--with-abi-profile</code>: arm-vfp-sflt, arm-vfp-hflt, arm-sflt, armv5-vfp-sflt, armv6-vfp-hflt. Note that soft-float ABIs are no longer properly supported on OpenJDK.</p>
<p>OpenJDK contains two different ports for the aarch64 platform, one is the original aarch64 port from the <ahref="http://openjdk.java.net/projects/aarch64-port">AArch64 Port Project</a> and one is a 64-bit version of the Oracle contributed ARM port. When targeting aarch64, by the default the original aarch64 port is used. To select the Oracle ARM 64 port, use <code>--with-cpu-port=arm64</code>. Also set the corresponding value (<code>aarch64</code> or <code>arm64</code>) to --with-abi-profile, to ensure a consistent build.</p>
<h3id="verifying-the-build">Verifying the Build</h3>
<p>The build will end up in a directory named like <code>build/linux-arm-normal-server-release</code>.</p>
<p>Inside this build output directory, the <code>images/jdk</code> and <code>images/jre</code> will contain the newly built JDK and JRE, respectively, for your <em>target</em> system.</p>
<p>Copy these folders to your <em>target</em> system. Then you can run e.g. <code>images/jdk/bin/java -version</code>.</p>
<h2id="build-performance">Build Performance</h2>
<p>Building OpenJDK requires a lot of horsepower. Some of the build tools can be adjusted to utilize more or less of resources such as parallel threads and memory. The <code>configure</code> script analyzes your system and selects reasonable values for such options based on your hardware. If you encounter resource problems, such as out of memory conditions, you can modify the detected values with:</p>
<ul>
<li><p><code>--with-num-cores</code> -- number of cores in the build system, e.g. <code>--with-num-cores=8</code>.</p></li>
<li><p><code>--with-memory-size</code> -- memory (in MB) available in the build system, e.g. <code>--with-memory-size=1024</code></p></li>
</ul>
<p>You can also specify directly the number of build jobs to use with <code>--with-jobs=N</code> to <code>configure</code>, or <code>JOBS=N</code> to <code>make</code>. Do not use the <code>-j</code> flag to <code>make</code>. In most cases it will be ignored by the makefiles, but it can cause problems for some make targets.</p>
<p>It might also be necessary to specify the JVM arguments passed to the Boot JDK, using e.g. <code>--with-boot-jdk-jvmargs="-Xmx8G"</code>. Doing so will override the default JVM arguments passed to the Boot JDK.</p>
<p>At the end of a successful execution of <code>configure</code>, you will get a performance summary, indicating how well the build will perform. Here you will also get performance hints. If you want to build fast, pay attention to those!</p>
<p>If you want to tweak build performance, run with <code>make LOG=info</code> to get a build time summary at the end of the build process.</p>
<h3id="disk-speed">Disk Speed</h3>
<p>If you are using network shares, e.g. via NFS, for your source code, make sure the build directory is situated on local disk (e.g. by <code>ln -s /localdisk/jdk-build $JDK-SHARE/build</code>). The performance penalty is extremely high for building on a network share; close to unusable.</p>
<p>Also, make sure that your build tools (including Boot JDK and toolchain) is located on a local disk and not a network share.</p>
<p>As has been stressed elsewhere, do use SSD for source code and build directory, as well as (if possible) the build tools.</p>
<h3id="virus-checking">Virus Checking</h3>
<p>The use of virus checking software, especially on Windows, can <em>significantly</em> slow down building of OpenJDK. If possible, turn off such software, or exclude the directory containing the OpenJDK source code from on-the-fly checking.</p>
<h3id="ccache">Ccache</h3>
<p>The OpenJDK build supports building with ccache when using gcc or clang. Using ccache can radically speed up compilation of native code if you often rebuild the same sources. Your milage may vary however, so we recommend evaluating it for yourself. To enable it, make sure it's on the path and configure with <code>--enable-ccache</code>.</p>
<p>By default, the Hotspot build uses preccompiled headers (PCH) on the toolchains were it is properly supported (clang, gcc, and Visual Studio). Normally, this speeds up the build process, but in some circumstances, it can actually slow things down.</p>
<p>You can experiment by disabling precompiled headers using <code>--disable-precompiled-headers</code>.</p>
<h3id="icecc-icecream">Icecc / icecream</h3>
<p><ahref="http://github.com/icecc/icecream">icecc/icecream</a> is a simple way to setup a distributed compiler network. If you have multiple machines available for building OpenJDK, you can drastically cut individual build times by utilizing it.</p>
<p>To use, setup an icecc network, and install icecc on the build machine. Then run <code>configure</code> using <code>--enable-icecc</code>.</p>
<h3id="using-sjavac">Using sjavac</h3>
<p>To speed up Java compilation, especially incremental compilations, you can try the experimental sjavac compiler by using <code>--enable-sjavac</code>.</p>
<h3id="building-the-right-target">Building the Right Target</h3>
<p>Selecting the proper target to build can have dramatic impact on build time. For normal usage, <code>jdk</code> or the default target is just fine. You only need to build <code>images</code> for shipping, or if your tests require it.</p>
<p>See also <ahref="#using-fine-grained-make-targets">Using Fine-Grained Make Targets</a> on how to build an even smaller subset of the product.</p>
<h2id="troubleshooting">Troubleshooting</h2>
<p>If your build fails, it can sometimes be difficult to pinpoint the problem or find a proper solution.</p>
<h3id="locating-the-source-of-the-error">Locating the Source of the Error</h3>
<p>When a build fails, it can be hard to pinpoint the actual cause of the error. In a typical build process, different parts of the product build in parallel, with the output interlaced.</p>
<p>To help you, the build system will print a failure summary at the end. It looks like this:</p>
<pre><code>ERROR: Build failed for target 'hotspot' in configuration 'linux-x64' (exit code 2)
=== Output from failing command(s) repeated here ===
* For target hotspot_variant-server_libjvm_objs_psMemoryPool.o:
/localhome/hg/jdk9-sandbox/hotspot/src/share/vm/services/psMemoryPool.cpp:1:1: error: 'failhere' does not name a type
... (rest of output omitted)
* All command lines available in /localhome/hg/jdk9-sandbox/build/linux-x64/make-support/failure-logs.
=== End of repeated output ===
=== Make failed targets repeated here ===
lib/CompileJvm.gmk:207: recipe for target '/localhome/hg/jdk9-sandbox/build/linux-x64/hotspot/variant-server/libjvm/objs/psMemoryPool.o' failed
make/Main.gmk:263: recipe for target 'hotspot-server-libs' failed
=== End of repeated output ===
Hint: Try searching the build log for the name of the first failed target.
Hint: If caused by a warning, try configure --disable-warnings-as-errors.</code></pre>
<p>Let's break it down! First, the selected configuration, and the top-level target you entered on the command line that caused the failure is printed.</p>
<p>Then, between the <code>Output from failing command(s) repeated here</code> and <code>End of repeated output</code> the first lines of output (stdout and stderr) from the actual failing command is repeated. In most cases, this is the error message that caused the build to fail. If multiple commands were failing (this can happen in a parallel build), output from all failed commands will be printed here.</p>
<p>The path to the <code>failure-logs</code> directory is printed. In this file you will find a <code><target>.log</code> file that contains the output from this command in its entirety, and also a <code><target>.cmd</code>, which contain the complete command line used for running this command. You can re-run the failing command by executing <code>. <path to failure-logs>/<target>.cmd</code> in your shell.</p>
<p>Another way to trace the failure is to follow the chain of make targets, from top-level targets to individual file targets. Between <code>Make failed targets repeated here</code> and <code>End of repeated output</code> the output from make showing this chain is repeated. The first failed recipe will typically contain the full path to the file in question that failed to compile. Following lines will show a trace of make targets why we ended up trying to compile that file.</p>
<p>Finally, some hints are given on how to locate the error in the complete log. In this example, we would try searching the log file for "<code>psMemoryPool.o</code>". Another way to quickly locate make errors in the log is to search for "<code>] Error</code>" or "<code>***</code>".</p>
<p>Note that the build failure summary will only help you if the issue was a compilation failure or similar. If the problem is more esoteric, or is due to errors in the build machinery, you will likely get empty output logs, and <code>No indication of failed target found</code> instead of the make target chain.</p>
<h4id="checking-the-build-log-file">Checking the Build Log File</h4>
<p>The output (stdout and stderr) from the latest build is always stored in <code>$BUILD/build.log</code>. The previous build log is stored as <code>build.log.old</code>. This means that it is not necessary to redirect the build output yourself if you want to process it.</p>
<p>You can increase the verbosity of the log file, by the <code>LOG</code> control variable to <code>make</code>. If you want to see the command lines used in compilations, use <code>LOG=cmdlines</code>. To increase the general verbosity, use <code>LOG=info</code>, <code>LOG=debug</code> or <code>LOG=trace</code>. Both of these can be combined with <code>cmdlines</code>, e.g. <code>LOG=info,cmdlines</code>. The <code>debug</code> log level will show most shell commands executed by make, and <code>trace</code> will show all. Beware that both these log levels will produce a massive build log!</p>
<p>Most of the time, the build will fail due to incorrect changes in the source code.</p>
<p>Sometimes the build can fail with no apparent changes that have caused the failure. If this is the first time you are building OpenJDK on this particular computer, and the build fails, the problem is likely with your build environment. But even if you have previously built OpenJDK with success, and it now fails, your build environment might have changed (perhaps due to OS upgrades or similar). But most likely, such failures are due to problems with the incremental rebuild.</p>
<h4id="problems-with-the-build-environment">Problems with the Build Environment</h4>
<p>Make sure your configuration is correct. Re-run <code>configure</code>, and look for any warnings. Warnings that appear in the middle of the <code>configure</code> output is also repeated at the end, after the summary. The entire log is stored in <code>$BUILD/configure.log</code>.</p>
<p>Verify that the summary at the end looks correct. Are you indeed using the Boot JDK and native toolchain that you expect?</p>
<p>By default, OpenJDK has a strict approach where warnings from the compiler is considered errors which fail the build. For very new or very old compiler versions, this can trigger new classes of warnings, which thus fails the build. Run <code>configure</code> with <code>--disable-warnings-as-errors</code> to turn of this behavior. (The warnings will still show, but not make the build fail.)</p>
<h4id="problems-with-incremental-rebuilds">Problems with Incremental Rebuilds</h4>
<p>Incremental rebuilds mean that when you modify part of the product, only the affected parts get rebuilt. While this works great in most cases, and significantly speed up the development process, from time to time complex interdependencies will result in an incorrect build result. This is the most common cause for unexpected build problems, together with inconsistencies between the different Mercurial repositories in the forest.</p>
<p>Here are a suggested list of things to try if you are having unexpected build problems. Each step requires more time than the one before, so try them in order. Most issues will be solved at step 1 or 2.</p>
<p>Run <code>bash get_source.sh</code> to make sure you have the latest version of all repositories.</p></li>
<li><p>Clean build results</p>
<p>The simplest way to fix incremental rebuild issues is to run <code>make clean</code>. This will remove all build results, but not the configuration or any build system support artifacts. In most cases, this will solve build errors resulting from incremental build mismatches.</p></li>
<li><p>Completely clean the build directory.</p>
<p>If this does not work, the next step is to run <code>make dist-clean</code>, or removing the build output directory (<code>$BUILD</code>). This will clean all generated output, including your configuration. You will need to re-run <code>configure</code> after this step. A good idea is to run <code>make print-configuration</code> before running <code>make dist-clean</code>, as this will print your current <code>configure</code> command line. Here's a way to do this:</p>
<p>Sometimes the Mercurial repositories themselves gets in a state that causes the product to be un-buildable. In such a case, the simplest solution is often the "sledgehammer approach": delete the entire forest, and re-clone it. If you have local changes, save them first to a different location using <code>hg export</code>.</p></li>
<pre><code>File 'xxx' has modification time in the future.
Clock skew detected. Your build may be incomplete.</code></pre>
<p>then the clock on your build machine is out of sync with the timestamps on the source files. Other errors, apparently unrelated but in fact caused by the clock skew, can occur along with the clock skew warnings. These secondary errors may tend to obscure the fact that the true root cause of the problem is an out-of-sync clock.</p>
<p>If you see these warnings, reset the clock on the build machine, run <code>make clean</code> and restart the build.</p>
<h4id="out-of-memory-errors">Out of Memory Errors</h4>
<p>On Solaris, you might get an error message like this:</p>
<pre><code>Trouble writing out table to disk</code></pre>
<p>To solve this, increase the amount of swap space on your build machine.</p>
<p>On Windows, you might get error messages like this:</p>
<p>This can be a sign of a Cygwin problem. See the information about solving problems in the <ahref="#cygwin">Cygwin</a> section. Rebooting the computer might help temporarily.</p>
<h3id="getting-help">Getting Help</h3>
<p>If none of the suggestions in this document helps you, or if you find what you believe is a bug in the build system, please contact the Build Group by sending a mail to <ahref="mailto:build-dev@openjdk.java.net">build-dev@openjdk.java.net</a>. Please include the relevant parts of the configure and/or build log.</p>
<p>If you need general help or advice about developing for OpenJDK, you can also contact the Adoption Group. See the section on <ahref="#contributing-to-openjdk">Contributing to OpenJDK</a> for more information.</p>
<h2id="hints-and-suggestions-for-advanced-users">Hints and Suggestions for Advanced Users</h2>
<h3id="setting-up-a-forest-for-pushing-changes-defpath">Setting Up a Forest for Pushing Changes (defpath)</h3>
<p>To help you prepare a proper push path for a Mercurial repository, there exists a useful tool known as <ahref="http://openjdk.java.net/projects/code-tools/defpath">defpath</a>. It will help you setup a proper push path for pushing changes to OpenJDK.</p>
<p>Install the extension by cloning <code>http://hg.openjdk.java.net/code-tools/defpath</code> and updating your <code>.hgrc</code> file. Here's one way to do this:</p>
<p>If you also have the <code>trees</code> extension installed in Mercurial, you will automatically get a <code>tdefpath</code> command, which is even more useful. By running <code>hg tdefpath -du <username></code> in the top repository of your forest, all repos will get setup automatically. This is the recommended usage.</p>
<h3id="bash-completion">Bash Completion</h3>
<p>The <code>configure</code> and <code>make</code> commands tries to play nice with bash command-line completion (using <code><tab></code> or <code><tab><tab></code>). To use this functionality, make sure you enable completion in your <code>~/.bashrc</code> (see instructions for bash in your operating system).</p>
<p>Make completion will work out of the box, and will complete valid make targets. For instance, typing <code>make jdk-i<tab></code> will complete to <code>make jdk-image</code>.</p>
<p>The <code>configure</code> script can get completion for options, but for this to work you need to help <code>bash</code> on the way. The standard way of running the script, <code>bash configure</code>, will not be understood by bash completion. You need <code>configure</code> to be the command to run. One way to achieve this is to add a simple helper script to your path:</p>
<pre><code>cat << EOT > /tmp/configure
#!/bin/bash
if [ \$(pwd) = \$(cd \$(dirname \$0); pwd) ] ; then
echo >&2 "Abort: Trying to call configure helper recursively"
<p>You can have multiple configurations for a single source forest. When you create a new configuration, run <code>configure --with-conf-name=<name></code> to create a configuration with the name <code><name></code>. Alternatively, you can create a directory under <code>build</code> and run <code>configure</code> from there, e.g. <code>mkdir build/<name>&& cd build/<name>&& bash ../../configure</code>.</p>
<p>Then you can build that configuration using <code>make CONF_NAME=<name></code> or <code>make CONF=<pattern></code>, where <code><pattern></code> is a substring matching one or several configurations, e.g. <code>CONF=debug</code>. The special empty pattern (<code>CONF=</code>) will match <em>all</em> available configuration, so <code>make CONF= hotspot</code> will build the <code>hotspot</code> target for all configurations. Alternatively, you can execute <code>make</code> in the configuration directory, e.g. <code>cd build/<name>&& make</code>.</p>
<p>If you update the forest and part of the configure script has changed, the build system will force you to re-run <code>configure</code>.</p>
<p>Most of the time, you will be fine by running <code>configure</code> again with the same arguments as the last time, which can easily be performed by <code>make reconfigure</code>. To simplify this, you can use the <code>CONF_CHECK</code> make control variable, either as <code>make CONF_CHECK=auto</code>, or by setting an environment variable. For instance, if you add <code>export CONF_CHECK=auto</code> to your <code>.bashrc</code> file, <code>make</code> will always run <code>reconfigure</code> automatically whenever the configure script has changed.</p>
<p>You can also use <code>CONF_CHECK=ignore</code> to skip the check for a needed configure update. This might speed up the build, but comes at the risk of an incorrect build result. This is only recommended if you know what you're doing.</p>
<p>From time to time, you will also need to modify the command line to <code>configure</code> due to changes. Use <code>make print-configure</code> to show the command line used for your current configuration.</p>
<h3id="using-fine-grained-make-targets">Using Fine-Grained Make Targets</h3>
<p>The default behavior for make is to create consistent and correct output, at the expense of build speed, if necessary.</p>
<p>If you are prepared to take some risk of an incorrect build, and know enough of the system to understand how things build and interact, you can speed up the build process considerably by instructing make to only build a portion of the product.</p>
<p>The safe way to use fine-grained make targets is to use the module specific make targets. All source code in JDK 9 is organized so it belongs to a module, e.g. <code>java.base</code> or <code>jdk.jdwp.agent</code>. You can build only a specific module, by giving it as make target: <code>make jdk.jdwp.agent</code>. If the specified module depends on other modules (e.g. <code>java.base</code>), those modules will be built first.</p>
<p>You can also specify a set of modules, just as you can always specify a set of make targets: <code>make jdk.crypto.cryptoki jdk.crypto.ec jdk.crypto.mscapi jdk.crypto.ucrypto</code></p>
<p>The build process for each module is divided into separate phases. Not all modules need all phases. Which are needed depends on what kind of source code and other artifact the module consists of. The phases are:</p>
<li><code>rmic</code> (Run the <code>rmic</code> tool)</li>
</ul>
<p>You can build only a single phase for a module by using the notation <code>$MODULE-$PHASE</code>. For instance, to build the <code>gensrc</code> phase for <code>java.base</code>, use <code>make java.base-gensrc</code>.</p>
<p>Note that some phases may depend on others, e.g. <code>java</code> depends on <code>gensrc</code> (if present). Make will build all needed prerequisites before building the requested phase.</p>
<h4id="skipping-the-dependency-check">Skipping the Dependency Check</h4>
<p>When using an iterative development style with frequent quick rebuilds, the dependency check made by make can take up a significant portion of the time spent on the rebuild. In such cases, it can be useful to bypass the dependency check in make.</p>
<blockquote>
<p><strong>Note that if used incorrectly, this can lead to a broken build!</strong></p>
</blockquote>
<p>To achieve this, append <code>-only</code> to the build target. For instance, <code>make jdk.jdwp.agent-java-only</code> will <em>only</em> build the <code>java</code> phase of the <code>jdk.jdwp.agent</code> module. If the required dependencies are not present, the build can fail. On the other hand, the execution time measures in milliseconds.</p>
<p>A useful pattern is to build the first time normally (e.g. <code>make jdk.jdwp.agent</code>) and then on subsequent builds, use the <code>-only</code> make target.</p>
<h4id="rebuilding-part-of-java.base-jdk_filter">Rebuilding Part of java.base (JDK_FILTER)</h4>
<p>If you are modifying files in <code>java.base</code>, which is the by far largest module in OpenJDK, then you need to rebuild all those files whenever a single file has changed. (This inefficiency will hopefully be addressed in JDK 10.)</p>
<p>As a hack, you can use the make control variable <code>JDK_FILTER</code> to specify a pattern that will be used to limit the set of files being recompiled. For instance, <code>make java.base JDK_FILTER=javax/crypto</code> (or, to combine methods, <code>make java.base-java-only JDK_FILTER=javax/crypto</code>) will limit the compilation to files in the <code>javax.crypto</code> package.</p>
<h3id="learn-about-mercurial">Learn About Mercurial</h3>
<p>To become an efficient OpenJDK developer, it is recommended that you invest in learning Mercurial properly. Here are some links that can get you started:</p>
<ul>
<li><ahref="http://www.mercurial-scm.org/wiki/GitConcepts">Mercurial for git users</a></li>
<li><ahref="http://www.mercurial-scm.org/wiki/Tutorial">The official Mercurial tutorial</a></li>
<li><ahref="http://hginit.com/">hg init</a></li>
<li><ahref="http://hgbook.red-bean.com/read/">Mercurial: The Definitive Guide</a></li>
</ul>
<h2id="understanding-the-build-system">Understanding the Build System</h2>
<p>This section will give you a more technical description on the details of the build system.</p>
<h3id="configurations">Configurations</h3>
<p>The build system expects to find one or more configuration. These are technically defined by the <code>spec.gmk</code> in a subdirectory to the <code>build</code> subdirectory. The <code>spec.gmk</code> file is generated by <code>configure</code>, and contains in principle the configuration (directly or by files included by <code>spec.gmk</code>).</p>
<p>You can, in fact, select a configuration to build by pointing to the <code>spec.gmk</code> file with the <code>SPEC</code> make control variable, e.g. <code>make SPEC=$BUILD/spec.gmk</code>. While this is not the recommended way to call <code>make</code> as a user, it is what is used under the hood by the build system.</p>
<p>The build output for a configuration will end up in <code>build/<configuration name></code>, which we refer to as <code>$BUILD</code> in this document. The <code>$BUILD</code> directory contains the following important directories:</p>
<pre><code>buildtools/
configure-support/
hotspot/
images/
jdk/
make-support/
support/
test-results/
test-support/</code></pre>
<p>This is what they are used for:</p>
<ul>
<li><p><code>images</code>: This is the directory were the output of the <code>*-image</code> make targets end up. For instance, <code>make jdk-image</code> ends up in <code>images/jdk</code>.</p></li>
<li><p><code>jdk</code>: This is the "exploded image". After <code>make jdk</code>, you will be able to launch the newly built JDK by running <code>$BUILD/jdk/bin/java</code>.</p></li>
<li><p><code>test-results</code>: This directory contains the results from running tests.</p></li>
<li><p><code>support</code>: This is an area for intermediate files needed during the build, e.g. generated source code, object files and class files. Some noteworthy directories in <code>support</code> is <code>gensrc</code>, which contains the generated source code, and the <code>modules_*</code> directories, which contains the files in a per-module hierarchy that will later be collapsed into the <code>jdk</code> directory of the exploded image.</p></li>
<li><p><code>buildtools</code>: This is an area for tools compiled for the build platform that are used during the rest of the build.</p></li>
<li><p><code>hotspot</code>: This is an area for intermediate files needed when building hotspot.</p></li>
<li><p><code>configure-support</code>, <code>make-support</code> and <code>test-support</code>: These directories contain files that are needed by the build system for <code>configure</code>, <code>make</code> and for running tests.</p></li>
</ul>
<h3id="fixpath">Fixpath</h3>
<p>Windows path typically look like <code>C:\User\foo</code>, while Unix paths look like <code>/home/foo</code>. Tools with roots from Unix often experience issues related to this mismatch when running on Windows.</p>
<p>In the OpenJDK build, we always use Unix paths internally, and only just before calling a tool that does not understand Unix paths do we convert them to Windows paths.</p>
<p>This conversion is done by the <code>fixpath</code> tool, which is a small wrapper that modifies unix-style paths to Windows-style paths in command lines. Fixpath is compiled automatically by <code>configure</code>.</p>
<p>Native libraries and executables can have debug symbol (and other debug information) associated with them. How this works is very much platform dependent, but a common problem is that debug symbol information takes a lot of disk space, but is rarely needed by the end user.</p>
<p>The OpenJDK supports different methods on how to handle debug symbols. The method used is selected by <code>--with-native-debug-symbols</code>, and available methods are <code>none</code>, <code>internal</code>, <code>external</code>, <code>zipped</code>.</p>
<ul>
<li><p><code>none</code> means that no debug symbols will be generated during the build.</p></li>
<li><p><code>internal</code> means that debug symbols will be generated during the build, and they will be stored in the generated binary.</p></li>
<li><p><code>external</code> means that debug symbols will be generated during the build, and after the compilation, they will be moved into a separate <code>.debuginfo</code> file. (This was previously known as FDS, Full Debug Symbols).</p></li>
<li><p><code>zipped</code> is like <code>external</code>, but the .debuginfo file will also be zipped into a <code>.diz</code> file.</p></li>
</ul>
<p>When building for distribution, <code>zipped</code> is a good solution. Binaries built with <code>internal</code> is suitable for use by developers, since they facilitate debugging, but should be stripped before distributed to end users.</p>
<h3id="autoconf-details">Autoconf Details</h3>
<p>The <code>configure</code> script is based on the autoconf framework, but in some details deviate from a normal autoconf <code>configure</code> script.</p>
<p>The <code>configure</code> script in the top level directory of OpenJDK is just a thin wrapper that calls <code>common/autoconf/configure</code>. This in turn provides functionality that is not easily expressed in the normal Autoconf framework, and then calls into the core of the <code>configure</code> script, which is the <code>common/autoconf/generated-configure.sh</code> file.</p>
<p>As the name implies, this file is generated by Autoconf. It is checked in after regeneration, to alleviate the common user to have to install Autoconf.</p>
<p>The build system will detect if the Autoconf source files have changed, and will trigger a regeneration of <code>common/autoconf/generated-configure.sh</code> if needed. You can also manually request such an update by <code>bash common/autoconf/autogen.sh</code>.</p>
<p>If you make changes to the build system that requires a re-generation, note the following:</p>
<ul>
<li><p>You must use <em>exactly</em> version 2.69 of autoconf for your patch to be accepted. This is to avoid spurious changes in the generated file. Note that Ubuntu 16.04 ships a patched version of autoconf which claims to be 2.69, but is not.</p></li>
<li><p>You do not need to include the generated file in reviews.</p></li>
<li><p>If the generated file needs updating, the Oracle JDK closed counter-part will also need to be updated. It is very much appreciated if you ask for an Oracle engineer to sponsor your push so this can be made in tandem.</p></li>
</ul>
<h3id="developing-the-build-system-itself">Developing the Build System Itself</h3>
<p>This section contains a few remarks about how to develop for the build system itself. It is not relevant if you are only making changes in the product source code.</p>
<p>While technically using <code>make</code>, the make source files of the OpenJDK does not resemble most other Makefiles. Instead of listing specific targets and actions (perhaps using patterns), the basic modus operandi is to call a high-level function (or properly, macro) from the API in <code>make/common</code>. For instance, to compile all classes in the <code>jdk.internal.foo</code> package in the <code>jdk.foo</code> module, a call like this would be made:</p>
<p>By encapsulating and expressing the high-level knowledge of <em>what</em> should be done, rather than <em>how</em> it should be done (as is normal in Makefiles), we can build a much more powerful and flexible build system.</p>
<p>Correct dependency tracking is paramount. Sloppy dependency tracking will lead to improper parallelization, or worse, race conditions.</p>
<p>To test for/debug race conditions, try running <code>make JOBS=1</code> and <code>make JOBS=100</code> and see if it makes any difference. (It shouldn't).</p>
<p>To compare the output of two different builds and see if, and how, they differ, run <code>$BUILD1/compare.sh -o $BUILD2</code>, where <code>$BUILD1</code> and <code>$BUILD2</code> are the two builds you want to compare.</p>
<p>To automatically build two consecutive versions and compare them, use <code>COMPARE_BUILD</code>. The value of <code>COMPARE_BUILD</code> is a set of variable=value assignments, like this:</p>
<p>See <code>make/InitSupport.gmk</code> for details on how to use <code>COMPARE_BUILD</code>.</p>
<p>To analyze build performance, run with <code>LOG=trace</code> and check <code>$BUILD/build-trace-time.log</code>. Use <code>JOBS=1</code> to avoid parallelism.</p>
<p>Please check that you adhere to the <ahref="http://openjdk.java.net/groups/build/doc/code-conventions.html">Code Conventions for the Build System</a> before submitting patches. Also see the section in <ahref="#autoconf-details">Autoconf Details</a> about the generated configure script.</p>
<h2id="contributing-to-openjdk">Contributing to OpenJDK</h2>
<p>So, now you've build your OpenJDK, and made your first patch, and want to contribute it back to the OpenJDK community.</p>
<p>First of all: Thank you! We gladly welcome your contribution to the OpenJDK. However, please bear in mind that OpenJDK is a massive project, and we must ask you to follow our rules and guidelines to be able to accept your contribution.</p>
<p>The official place to start is the <ahref="http://openjdk.java.net/contribute/">'How to contribute' page</a>. There is also an official (but somewhat outdated and skimpy on details) <ahref="http://openjdk.java.net/guide/">Developer's Guide</a>.</p>
<p>If this seems overwhelming to you, the Adoption Group is there to help you! A good place to start is their <ahref="https://wiki.openjdk.java.net/display/Adoption/New+Contributor">'New Contributor' page</a>, or start reading the comprehensive <ahref="https://adoptopenjdk.gitbooks.io/adoptopenjdk-getting-started-kit/en/">Getting Started Kit</a>. The Adoption Group will also happily answer any questions you have about contributing. Contact them by <ahref="http://mail.openjdk.java.net/mailman/listinfo/adoption-discuss">mail</a> or <ahref="http://openjdk.java.net/irc/">IRC</a>.</p>