boot-jdk.m4 revision 2212:8b1d348ad6a2
13199Sjkh#
23199Sjkh# Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
388028Sjoerg# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
43199Sjkh#
53199Sjkh# This code is free software; you can redistribute it and/or modify it
63199Sjkh# under the terms of the GNU General Public License version 2 only, as
73199Sjkh# published by the Free Software Foundation.  Oracle designates this
83199Sjkh# particular file as subject to the "Classpath" exception as provided
93199Sjkh# by Oracle in the LICENSE file that accompanied this code.
103199Sjkh#
113199Sjkh# This code is distributed in the hope that it will be useful, but WITHOUT
123199Sjkh# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
133199Sjkh# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
143199Sjkh# version 2 for more details (a copy is included in the LICENSE file that
1582229Sdd# accompanied this code).
163199Sjkh#
173199Sjkh# You should have received a copy of the GNU General Public License version
183199Sjkh# 2 along with this work; if not, write to the Free Software Foundation,
193199Sjkh# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
203199Sjkh#
213199Sjkh# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
223199Sjkh# or visit www.oracle.com if you need additional information or have any
233199Sjkh# questions.
243199Sjkh#
253199Sjkh
263199Sjkh########################################################################
273199Sjkh# This file handles detection of the Boot JDK. The Boot JDK detection
2850476Speter# process has been developed as a response to solve a complex real-world
293199Sjkh# problem. Initially, it was simple, but it has grown as platform after
30163798Skeramida# platform, idiosyncracy after idiosyncracy has been supported.
3153200Sphantom#
3279538Sru# The basic idea is this:
333199Sjkh# 1) You need an acceptable *) JDK to use as a Boot JDK
343199Sjkh# 2) There are several ways to locate a JDK, that are mostly platform
3589225Sru#    dependent **)
363199Sjkh# 3) You can have multiple JDKs installed
3784877Syokota# 4) If possible, configure should try to dig out an acceptable JDK
3884877Syokota#    automatically, without having to resort to command-line options
3984877Syokota#
4084877Syokota# *)  acceptable means e.g. JDK7 for building JDK8, a complete JDK (with
4184877Syokota#     javac) and not a JRE, etc.
4284877Syokota#
4384877Syokota# **) On Windows we typically use a well-known path.
4484877Syokota#     On MacOSX we typically use the tool java_home.
4588028Sjoerg#     On Linux we typically find javac in the $PATH, and then follow a
4684877Syokota#     chain of symlinks that often ends up in a real JDK.
4784877Syokota#
4888028Sjoerg# This leads to the code where we check in different ways to locate a
4984877Syokota# JDK, and if one is found, check if it is acceptable. If not, we print
5084877Syokota# our reasons for rejecting it (useful when debugging non-working
5188028Sjoerg# configure situations) and continue checking the next one.
523199Sjkh########################################################################
5388028Sjoerg
5489225Sru# Execute the check given as argument, and verify the result
5589225Sru# If the Boot JDK was previously found, do nothing
5688028Sjoerg# $1 A command line (typically autoconf macro) to execute
5788028SjoergAC_DEFUN([BOOTJDK_DO_CHECK],
5830575Sjoerg[
5989225Sru  if test "x$BOOT_JDK_FOUND" = xno; then
6089225Sru    # Now execute the test
6188028Sjoerg    $1
62132219Snjl
63132219Snjl    # If previous step claimed to have found a JDK, check it to see if it seems to be valid.
6489225Sru    if test "x$BOOT_JDK_FOUND" = xmaybe; then
6588028Sjoerg      # Do we have a bin/java?
6689225Sru      if test ! -x "$BOOT_JDK/bin/java"; then
6789225Sru        AC_MSG_NOTICE([Potential Boot JDK found at $BOOT_JDK did not contain bin/java; ignoring])
6888028Sjoerg        BOOT_JDK_FOUND=no
6988028Sjoerg      else
7088028Sjoerg        # Do we have a bin/javac?
7188028Sjoerg        if test ! -x "$BOOT_JDK/bin/javac"; then
7288028Sjoerg          AC_MSG_NOTICE([Potential Boot JDK found at $BOOT_JDK did not contain bin/javac; ignoring])
7389225Sru          AC_MSG_NOTICE([(This might be an JRE instead of an JDK)])
7489225Sru          BOOT_JDK_FOUND=no
7588028Sjoerg        else
7688028Sjoerg          # Oh, this is looking good! We probably have found a proper JDK. Is it the correct version?
7754939Sjoerg          BOOT_JDK_VERSION=`"$BOOT_JDK/bin/java" -version 2>&1 | $HEAD -n 1`
7888028Sjoerg
7988028Sjoerg          # Extra M4 quote needed to protect [] in grep expression.
8088028Sjoerg          [FOUND_CORRECT_VERSION=`$ECHO $BOOT_JDK_VERSION | $EGREP '\"9([\.+-].*)?\"|(1\.[89]\.)'`]
8188028Sjoerg          if test "x$FOUND_CORRECT_VERSION" = x; then
8288028Sjoerg            AC_MSG_NOTICE([Potential Boot JDK found at $BOOT_JDK is incorrect JDK version ($BOOT_JDK_VERSION); ignoring])
8388028Sjoerg            AC_MSG_NOTICE([(Your Boot JDK must be version 8 or 9)])
8488028Sjoerg            BOOT_JDK_FOUND=no
8588028Sjoerg          else
8688028Sjoerg            # We're done! :-)
8788028Sjoerg            BOOT_JDK_FOUND=yes
8888028Sjoerg            BASIC_FIXUP_PATH(BOOT_JDK)
8988028Sjoerg            AC_MSG_CHECKING([for Boot JDK])
9088028Sjoerg            AC_MSG_RESULT([$BOOT_JDK])
9189225Sru            AC_MSG_CHECKING([Boot JDK version])
9289225Sru            BOOT_JDK_VERSION=`"$BOOT_JDK/bin/java" -version 2>&1 | $TR '\n\r' '  '`
9388028Sjoerg            AC_MSG_RESULT([$BOOT_JDK_VERSION])
9489225Sru          fi # end check jdk version
9589225Sru        fi # end check javac
9688028Sjoerg      fi # end check java
9788028Sjoerg    fi # end check boot jdk found
9889225Sru  fi
9989225Sru])
10088028Sjoerg
10189225Sru# Test: Is bootjdk explicitely set by command line arguments?
10289225SruAC_DEFUN([BOOTJDK_CHECK_ARGUMENTS],
10388028Sjoerg[
10488028Sjoerg  if test "x$with_boot_jdk" != x; then
10588028Sjoerg    BOOT_JDK=$with_boot_jdk
10688028Sjoerg    BOOT_JDK_FOUND=maybe
10788028Sjoerg    AC_MSG_NOTICE([Found potential Boot JDK using configure arguments])
10888028Sjoerg  fi
10988028Sjoerg])
11088028Sjoerg
11188028Sjoerg# Test: Is $JAVA_HOME set?
11288028SjoergAC_DEFUN([BOOTJDK_CHECK_JAVA_HOME],
11388028Sjoerg[
11488028Sjoerg  if test "x$JAVA_HOME" != x; then
11588028Sjoerg    JAVA_HOME_PROCESSED="$JAVA_HOME"
11688028Sjoerg    BASIC_FIXUP_PATH(JAVA_HOME_PROCESSED)
11789225Sru    if test ! -d "$JAVA_HOME_PROCESSED"; then
11889225Sru      AC_MSG_NOTICE([Your JAVA_HOME points to a non-existing directory!])
11988028Sjoerg    else
12089225Sru      # Aha, the user has set a JAVA_HOME
12189225Sru      # let us use that as the Boot JDK.
12288028Sjoerg      BOOT_JDK="$JAVA_HOME_PROCESSED"
12389225Sru      BOOT_JDK_FOUND=maybe
12489225Sru      AC_MSG_NOTICE([Found potential Boot JDK using JAVA_HOME])
12588028Sjoerg    fi
12688028Sjoerg  fi
12789225Sru])
12889225Sru
12988028Sjoerg# Test: Is there a java or javac in the PATH, which is a symlink to the JDK?
13088028SjoergAC_DEFUN([BOOTJDK_CHECK_JAVA_IN_PATH_IS_SYMLINK],
13188028Sjoerg[
13288028Sjoerg  AC_PATH_PROG(JAVAC_CHECK, javac)
13389225Sru  AC_PATH_PROG(JAVA_CHECK, java)
13489225Sru  BINARY="$JAVAC_CHECK"
13589225Sru  if test "x$JAVAC_CHECK" = x; then
13688028Sjoerg    BINARY="$JAVA_CHECK"
13788028Sjoerg  fi
13888028Sjoerg  if test "x$BINARY" != x; then
13988028Sjoerg    # So there is a java(c) binary, it might be part of a JDK.
14088028Sjoerg    # Lets find the JDK/JRE directory by following symbolic links.
14188028Sjoerg    # Linux/GNU systems often have links from /usr/bin/java to
14288028Sjoerg    # /etc/alternatives/java to the real JDK binary.
14388028Sjoerg    BASIC_REMOVE_SYMBOLIC_LINKS(BINARY)
14488028Sjoerg    BOOT_JDK=`dirname "$BINARY"`
14588028Sjoerg    BOOT_JDK=`cd "$BOOT_JDK/.."; pwd`
14688028Sjoerg    if test -x "$BOOT_JDK/bin/javac" && test -x "$BOOT_JDK/bin/java"; then
14788028Sjoerg      # Looks like we found ourselves an JDK
14888028Sjoerg      BOOT_JDK_FOUND=maybe
14988028Sjoerg      AC_MSG_NOTICE([Found potential Boot JDK using java(c) in PATH])
15088028Sjoerg    fi
15188028Sjoerg  fi
15288028Sjoerg])
15388028Sjoerg
15488028Sjoerg# Test: Is there a /usr/libexec/java_home? (Typically on MacOSX)
15588028Sjoerg# $1: Argument to the java_home binary (optional)
156132219SnjlAC_DEFUN([BOOTJDK_CHECK_LIBEXEC_JAVA_HOME],
15789225Sru[
15888028Sjoerg  if test -x /usr/libexec/java_home; then
159132219Snjl    BOOT_JDK=`/usr/libexec/java_home $1`
160165216Smpp    BOOT_JDK_FOUND=maybe
16188028Sjoerg    AC_MSG_NOTICE([Found potential Boot JDK using /usr/libexec/java_home $1])
16288028Sjoerg  fi
16389225Sru])
16489225Sru
16589225Sru# Test: On MacOS X, can we find a boot jdk using /usr/libexec/java_home?
16689225SruAC_DEFUN([BOOTJDK_CHECK_MACOSX_JAVA_LOCATOR],
167132219Snjl[
16889225Sru  if test "x$OPENJDK_TARGET_OS" = xmacosx; then
16988028Sjoerg    # First check at user selected default
17088028Sjoerg    BOOTJDK_DO_CHECK([BOOTJDK_CHECK_LIBEXEC_JAVA_HOME()])
17189225Sru    # If that did not work out (e.g. too old), try explicit versions instead
17289225Sru    BOOTJDK_DO_CHECK([BOOTJDK_CHECK_LIBEXEC_JAVA_HOME([-v 1.9])])
17388028Sjoerg    BOOTJDK_DO_CHECK([BOOTJDK_CHECK_LIBEXEC_JAVA_HOME([-v 1.8])])
17488028Sjoerg    BOOTJDK_DO_CHECK([BOOTJDK_CHECK_LIBEXEC_JAVA_HOME([-v 1.7])])
17588028Sjoerg  fi
17688028Sjoerg])
17788028Sjoerg
17888028Sjoerg# Look for a jdk in the given path. If there are multiple, try to select the newest.
17988028Sjoerg# If found, set BOOT_JDK and BOOT_JDK_FOUND.
18088028Sjoerg# $1 = Path to directory containing jdk installations.
18188028Sjoerg# $2 = String to append to the found JDK directory to get the proper JDK home
18288028SjoergAC_DEFUN([BOOTJDK_FIND_BEST_JDK_IN_DIRECTORY],
18388028Sjoerg[
184119893Sru  BOOT_JDK_PREFIX="$1"
18589225Sru  BOOT_JDK_SUFFIX="$2"
18689225Sru  ALL_JDKS_FOUND=`$LS "$BOOT_JDK_PREFIX" 2> /dev/null | $SORT -r`
18788028Sjoerg  if test "x$ALL_JDKS_FOUND" != x; then
18889225Sru    for JDK_TO_TRY in $ALL_JDKS_FOUND ; do
18989225Sru      BOOTJDK_DO_CHECK([
19088028Sjoerg        BOOT_JDK="${BOOT_JDK_PREFIX}/${JDK_TO_TRY}${BOOT_JDK_SUFFIX}"
19189225Sru        if test -d "$BOOT_JDK"; then
19288028Sjoerg          BOOT_JDK_FOUND=maybe
19388028Sjoerg          AC_MSG_NOTICE([Found potential Boot JDK using well-known locations (in $BOOT_JDK_PREFIX/$JDK_TO_TRY)])
19489225Sru        fi
19588028Sjoerg      ])
19688028Sjoerg    done
19788028Sjoerg  fi
19888028Sjoerg])
19989610Smpp
20089225Sru# Call BOOTJDK_FIND_BEST_JDK_IN_DIRECTORY, but use the given
20188028Sjoerg# environmental variable as base for where to look.
20289225Sru# $1 Name of an environmal variable, assumed to point to the Program Files directory.
20389225SruAC_DEFUN([BOOTJDK_FIND_BEST_JDK_IN_WINDOWS_VIRTUAL_DIRECTORY],
20488028Sjoerg[
20588028Sjoerg  if test "x[$]$1" != x; then
20689225Sru    VIRTUAL_DIR="[$]$1/Java"
20789225Sru    BASIC_WINDOWS_REWRITE_AS_UNIX_PATH(VIRTUAL_DIR)
20888028Sjoerg    BOOTJDK_FIND_BEST_JDK_IN_DIRECTORY($VIRTUAL_DIR)
20988028Sjoerg  fi
21088028Sjoerg])
21189225Sru
21289225Sru# Test: Is there a JDK installed in default, well-known locations?
21388028SjoergAC_DEFUN([BOOTJDK_CHECK_WELL_KNOWN_LOCATIONS],
21489225Sru[
21589225Sru  if test "x$OPENJDK_TARGET_OS" = xwindows; then
21689225Sru    BOOTJDK_DO_CHECK([BOOTJDK_FIND_BEST_JDK_IN_WINDOWS_VIRTUAL_DIRECTORY([ProgramW6432])])
21788028Sjoerg    BOOTJDK_DO_CHECK([BOOTJDK_FIND_BEST_JDK_IN_WINDOWS_VIRTUAL_DIRECTORY([PROGRAMW6432])])
21889225Sru    BOOTJDK_DO_CHECK([BOOTJDK_FIND_BEST_JDK_IN_WINDOWS_VIRTUAL_DIRECTORY([PROGRAMFILES])])
21988028Sjoerg    BOOTJDK_DO_CHECK([BOOTJDK_FIND_BEST_JDK_IN_WINDOWS_VIRTUAL_DIRECTORY([ProgramFiles])])
22088028Sjoerg    BOOTJDK_DO_CHECK([BOOTJDK_FIND_BEST_JDK_IN_DIRECTORY([/cygdrive/c/Program Files/Java])])
22188028Sjoerg  elif test "x$OPENJDK_TARGET_OS" = xmacosx; then
22288028Sjoerg    BOOTJDK_DO_CHECK([BOOTJDK_FIND_BEST_JDK_IN_DIRECTORY([/Library/Java/JavaVirtualMachines],[/Contents/Home])])
22389225Sru    BOOTJDK_DO_CHECK([BOOTJDK_FIND_BEST_JDK_IN_DIRECTORY([/System/Library/Java/JavaVirtualMachines],[/Contents/Home])])
22489225Sru  elif test "x$OPENJDK_TARGET_OS" = xlinux; then
22589225Sru    BOOTJDK_DO_CHECK([BOOTJDK_FIND_BEST_JDK_IN_DIRECTORY([/usr/lib/jvm])])
22689225Sru  fi
22789225Sru])
22888028Sjoerg
22988028Sjoerg# Check that a command-line tool in the Boot JDK is correct
23089225Sru# $1 = name of variable to assign
23188028Sjoerg# $2 = name of binary
23288028SjoergAC_DEFUN([BOOTJDK_CHECK_TOOL_IN_BOOTJDK],
23389225Sru[
23489225Sru  # Use user overridden value if available, otherwise locate tool in the Boot JDK.
23589225Sru  BASIC_SETUP_TOOL($1,
23689225Sru    [
23788028Sjoerg      AC_MSG_CHECKING([for $2 in Boot JDK])
23889225Sru      $1=$BOOT_JDK/bin/$2
23988028Sjoerg      if test ! -x [$]$1; then
24089225Sru        AC_MSG_RESULT(not found)
24189225Sru        AC_MSG_NOTICE([Your Boot JDK seems broken. This might be fixed by explicitely setting --with-boot-jdk])
24288028Sjoerg        AC_MSG_ERROR([Could not find $2 in the Boot JDK])
24388028Sjoerg      fi
24489225Sru      AC_MSG_RESULT(ok)
24589225Sru      AC_SUBST($1)
24688028Sjoerg    ])
24789225Sru])
24888028Sjoerg
24989225Sru###############################################################################
25089225Sru#
25189225Sru# We need a Boot JDK to bootstrap the build.
25289225Sru#
25389225Sru
25488028SjoergAC_DEFUN_ONCE([BOOTJDK_SETUP_BOOT_JDK],
25589225Sru[
25689225Sru  BOOT_JDK_FOUND=no
25788028Sjoerg  AC_ARG_WITH(boot-jdk, [AS_HELP_STRING([--with-boot-jdk],
25889225Sru      [path to Boot JDK (used to bootstrap build) @<:@probed@:>@])])
25988028Sjoerg
26089225Sru  # We look for the Boot JDK through various means, going from more certain to
26189225Sru  # more of a guess-work. After each test, BOOT_JDK_FOUND is set to "yes" if
26289225Sru  # we detected something (if so, the path to the jdk is in BOOT_JDK). But we
26389225Sru  # must check if this is indeed valid; otherwise we'll continue looking.
26488028Sjoerg
26588028Sjoerg  # Test: Is bootjdk explicitely set by command line arguments?
26688028Sjoerg  BOOTJDK_DO_CHECK([BOOTJDK_CHECK_ARGUMENTS])
26789225Sru  if test "x$with_boot_jdk" != x && test "x$BOOT_JDK_FOUND" = xno; then
26889225Sru    # Having specified an argument which is incorrect will produce an instant failure;
26989225Sru    # we should not go on looking
27089225Sru    AC_MSG_ERROR([The path given by --with-boot-jdk does not contain a valid Boot JDK])
27189225Sru  fi
27289610Smpp
27389225Sru  # Test: On MacOS X, can we find a boot jdk using /usr/libexec/java_home?
27489225Sru  BOOTJDK_DO_CHECK([BOOTJDK_CHECK_MACOSX_JAVA_LOCATOR])
27589225Sru
27689225Sru  # Test: Is $JAVA_HOME set?
27788028Sjoerg  BOOTJDK_DO_CHECK([BOOTJDK_CHECK_JAVA_HOME])
27888028Sjoerg
27989225Sru  # Test: Is there a java or javac in the PATH, which is a symlink to the JDK?
28089225Sru  BOOTJDK_DO_CHECK([BOOTJDK_CHECK_JAVA_IN_PATH_IS_SYMLINK])
28189225Sru
28288028Sjoerg  # Test: Is there a JDK installed in default, well-known locations?
28389225Sru  BOOTJDK_DO_CHECK([BOOTJDK_CHECK_WELL_KNOWN_LOCATIONS])
28488028Sjoerg
28589225Sru  # If we haven't found anything yet, we've truly lost. Give up.
28689225Sru  if test "x$BOOT_JDK_FOUND" = xno; then
28789225Sru    HELP_MSG_MISSING_DEPENDENCY([openjdk])
28889225Sru    AC_MSG_NOTICE([Could not find a valid Boot JDK. $HELP_MSG])
28989225Sru    AC_MSG_NOTICE([This might be fixed by explicitely setting --with-boot-jdk])
29089225Sru    AC_MSG_ERROR([Cannot continue])
29188028Sjoerg  fi
29289225Sru
29389225Sru  AC_SUBST(BOOT_JDK)
29489225Sru
29589225Sru  # Setup tools from the Boot JDK.
29689225Sru  BOOTJDK_CHECK_TOOL_IN_BOOTJDK(JAVA, java)
29789225Sru  BOOTJDK_CHECK_TOOL_IN_BOOTJDK(JAVAC, javac)
29889225Sru  BOOTJDK_CHECK_TOOL_IN_BOOTJDK(JAVAH, javah)
29989225Sru  BOOTJDK_CHECK_TOOL_IN_BOOTJDK(JAR, jar)
30088028Sjoerg  BOOTJDK_CHECK_TOOL_IN_BOOTJDK(JARSIGNER, jarsigner)
30189225Sru
30289225Sru  # Finally, set some other options...
30389225Sru
30488028Sjoerg  # When compiling code to be executed by the Boot JDK, force jdk8 compatibility.
30589225Sru  BOOT_JDK_SOURCETARGET="-source 8 -target 8"
30689225Sru  AC_SUBST(BOOT_JDK_SOURCETARGET)
30789225Sru
30888028Sjoerg  ADD_JVM_ARG_IF_OK([--patch-module foo=bar], dummy, [$JAVA])
30989225Sru  AC_MSG_CHECKING([if Boot JDK supports modules])
31089225Sru  if test "x$JVM_ARG_OK" = "xtrue"; then
31189225Sru    AC_MSG_RESULT([yes])
31288028Sjoerg    BOOT_JDK_MODULAR="true"
31389225Sru  else
31488028Sjoerg    AC_MSG_RESULT([no])
31588028Sjoerg    BOOT_JDK_MODULAR="false"
31689225Sru  fi
31788028Sjoerg  AC_SUBST(BOOT_JDK_MODULAR)
31889225Sru
31989225Sru  AC_SUBST(JAVAC_FLAGS)
32089225Sru
32189225Sru  # Check if the boot jdk is 32 or 64 bit
32288028Sjoerg  if "$JAVA" -d64 -version > /dev/null 2>&1; then
323132219Snjl    BOOT_JDK_BITS="64"
32488028Sjoerg  else
3253199Sjkh    BOOT_JDK_BITS="32"
32689225Sru  fi
32771895Sru  AC_MSG_CHECKING([if Boot JDK is 32 or 64 bits])
3283199Sjkh  AC_MSG_RESULT([$BOOT_JDK_BITS])
3293199Sjkh  AC_SUBST(BOOT_JDK_BITS)
3303199Sjkh])
33120920Swosch
33288028SjoergAC_DEFUN_ONCE([BOOTJDK_SETUP_BOOT_JDK_ARGUMENTS],
33388028Sjoerg[
33488028Sjoerg  ##############################################################################
33588028Sjoerg  #
33688028Sjoerg  # Specify jvm options for anything that is run with the Boot JDK.
33789225Sru  # Not all JVM:s accept the same arguments on the command line.
33889225Sru  #
33988028Sjoerg  AC_ARG_WITH(boot-jdk-jvmargs, [AS_HELP_STRING([--with-boot-jdk-jvmargs],
34089225Sru  [specify JVM arguments to be passed to all java invocations of boot JDK, overriding the default values,
34188028Sjoerg  e.g --with-boot-jdk-jvmargs="-Xmx8G -enableassertions"])])
34288028Sjoerg
34388028Sjoerg  AC_MSG_CHECKING([flags for boot jdk java command] )
34488028Sjoerg
345  # Disable special log output when a debug build is used as Boot JDK...
346  ADD_JVM_ARG_IF_OK([-XX:-PrintVMOptions -XX:-UnlockDiagnosticVMOptions -XX:-LogVMOutput],boot_jdk_jvmargs,[$JAVA])
347
348  # Force en-US environment
349  ADD_JVM_ARG_IF_OK([-Duser.language=en -Duser.country=US],boot_jdk_jvmargs,[$JAVA])
350
351  # Apply user provided options.
352  ADD_JVM_ARG_IF_OK([$with_boot_jdk_jvmargs],boot_jdk_jvmargs,[$JAVA])
353
354  AC_MSG_RESULT([$boot_jdk_jvmargs])
355
356  # For now, general JAVA_FLAGS are the same as the boot jdk jvmargs
357  JAVA_FLAGS=$boot_jdk_jvmargs
358  AC_SUBST(JAVA_FLAGS)
359
360
361  AC_MSG_CHECKING([flags for boot jdk java command for big workloads])
362
363  # Starting amount of heap memory.
364  ADD_JVM_ARG_IF_OK([-Xms64M],boot_jdk_jvmargs_big,[$JAVA])
365  BOOTCYCLE_JVM_ARGS_BIG=-Xms64M
366
367  # Maximum amount of heap memory and stack size.
368  JVM_HEAP_LIMIT_32="1024"
369  # Running a 64 bit JVM allows for and requires a bigger heap
370  JVM_HEAP_LIMIT_64="1600"
371  STACK_SIZE_32=768
372  STACK_SIZE_64=1536
373  JVM_HEAP_LIMIT_GLOBAL=`expr $MEMORY_SIZE / 2`
374  if test "$JVM_HEAP_LIMIT_GLOBAL" -lt "$JVM_HEAP_LIMIT_32"; then
375    JVM_HEAP_LIMIT_32=$JVM_HEAP_LIMIT_GLOBAL
376  fi
377  if test "$JVM_HEAP_LIMIT_GLOBAL" -lt "$JVM_HEAP_LIMIT_64"; then
378    JVM_HEAP_LIMIT_64=$JVM_HEAP_LIMIT_GLOBAL
379  fi
380  if test "$JVM_HEAP_LIMIT_GLOBAL" -lt "512"; then
381    JVM_HEAP_LIMIT_32=512
382    JVM_HEAP_LIMIT_64=512
383  fi
384
385  if test "x$BOOT_JDK_BITS" = "x32"; then
386    STACK_SIZE=$STACK_SIZE_32
387    JVM_MAX_HEAP=$JVM_HEAP_LIMIT_32
388  else
389    STACK_SIZE=$STACK_SIZE_64
390    JVM_MAX_HEAP=$JVM_HEAP_LIMIT_64
391  fi
392  ADD_JVM_ARG_IF_OK([-Xmx${JVM_MAX_HEAP}M],boot_jdk_jvmargs_big,[$JAVA])
393  ADD_JVM_ARG_IF_OK([-XX:ThreadStackSize=$STACK_SIZE],boot_jdk_jvmargs_big,[$JAVA])
394
395  AC_MSG_RESULT([$boot_jdk_jvmargs_big])
396
397  JAVA_FLAGS_BIG=$boot_jdk_jvmargs_big
398  AC_SUBST(JAVA_FLAGS_BIG)
399
400  if test "x$OPENJDK_TARGET_CPU_BITS" = "x32"; then
401    BOOTCYCLE_MAX_HEAP=$JVM_HEAP_LIMIT_32
402    BOOTCYCLE_STACK_SIZE=$STACK_SIZE_32
403  else
404    BOOTCYCLE_MAX_HEAP=$JVM_HEAP_LIMIT_64
405    BOOTCYCLE_STACK_SIZE=$STACK_SIZE_64
406  fi
407  BOOTCYCLE_JVM_ARGS_BIG="$BOOTCYCLE_JVM_ARGS_BIG -Xmx${BOOTCYCLE_MAX_HEAP}M"
408  BOOTCYCLE_JVM_ARGS_BIG="$BOOTCYCLE_JVM_ARGS_BIG -XX:ThreadStackSize=$BOOTCYCLE_STACK_SIZE"
409  AC_MSG_CHECKING([flags for bootcycle boot jdk java command for big workloads])
410  AC_MSG_RESULT([$BOOTCYCLE_JVM_ARGS_BIG])
411  AC_SUBST(BOOTCYCLE_JVM_ARGS_BIG)
412
413  # By default, the main javac compilations use big
414  JAVA_FLAGS_JAVAC="$JAVA_FLAGS_BIG"
415  AC_SUBST(JAVA_FLAGS_JAVAC)
416
417  AC_MSG_CHECKING([flags for boot jdk java command for small workloads])
418
419  # Use serial gc for small short lived tools if possible
420  ADD_JVM_ARG_IF_OK([-XX:+UseSerialGC],boot_jdk_jvmargs_small,[$JAVA])
421  ADD_JVM_ARG_IF_OK([-Xms32M],boot_jdk_jvmargs_small,[$JAVA])
422  ADD_JVM_ARG_IF_OK([-Xmx512M],boot_jdk_jvmargs_small,[$JAVA])
423  ADD_JVM_ARG_IF_OK([-XX:TieredStopAtLevel=1],boot_jdk_jvmargs_small,[$JAVA])
424
425  AC_MSG_RESULT([$boot_jdk_jvmargs_small])
426
427  JAVA_FLAGS_SMALL=$boot_jdk_jvmargs_small
428  AC_SUBST(JAVA_FLAGS_SMALL)
429
430  JAVA_TOOL_FLAGS_SMALL=""
431  for f in $JAVA_FLAGS_SMALL; do
432    JAVA_TOOL_FLAGS_SMALL="$JAVA_TOOL_FLAGS_SMALL -J$f"
433  done
434  AC_SUBST(JAVA_TOOL_FLAGS_SMALL)
435])
436
437# BUILD_JDK: the location of the latest JDK that can run
438#   on the host system and supports the target class file version
439#   generated in this JDK build.  This variable should only be
440#   used after the launchers are built.
441#
442
443# Execute the check given as argument, and verify the result.
444# If the JDK was previously found, do nothing.
445# $1 A command line (typically autoconf macro) to execute
446AC_DEFUN([BOOTJDK_CHECK_BUILD_JDK],
447[
448  if test "x$BUILD_JDK_FOUND" = xno; then
449    # Execute the test
450    $1
451
452    # If previous step claimed to have found a JDK, check it to see if it seems to be valid.
453    if test "x$BUILD_JDK_FOUND" = xmaybe; then
454      # Do we have a bin/java?
455      if test ! -x "$BUILD_JDK/bin/java"; then
456        AC_MSG_NOTICE([Potential Build JDK found at $BUILD_JDK did not contain bin/java; ignoring])
457        BUILD_JDK_FOUND=no
458      elif test ! -x "$BUILD_JDK/bin/jlink"; then
459        AC_MSG_NOTICE([Potential Build JDK found at $BUILD_JDK did not contain bin/jlink; ignoring])
460        BUILD_JDK_FOUND=no
461      elif test ! -x "$BUILD_JDK/bin/jmod"; then
462        AC_MSG_NOTICE([Potential Build JDK found at $BUILD_JDK did not contain bin/jmod; ignoring])
463        BUILD_JDK_FOUND=no
464      elif test ! -x "$BUILD_JDK/bin/javac"; then
465        # Do we have a bin/javac?
466        AC_MSG_NOTICE([Potential Build JDK found at $BUILD_JDK did not contain bin/javac; ignoring])
467        AC_MSG_NOTICE([(This might be a JRE instead of an JDK)])
468        BUILD_JDK_FOUND=no
469      else
470        # Oh, this is looking good! We probably have found a proper JDK. Is it the correct version?
471        BUILD_JDK_VERSION=`"$BUILD_JDK/bin/java" -version 2>&1 | $HEAD -n 1`
472
473        # Extra M4 quote needed to protect [] in grep expression.
474        [FOUND_CORRECT_VERSION=`echo $BUILD_JDK_VERSION | $EGREP '\"9([\.+-].*)?\"'`]
475        if test "x$FOUND_CORRECT_VERSION" = x; then
476          AC_MSG_NOTICE([Potential Build JDK found at $BUILD_JDK is incorrect JDK version ($BUILD_JDK_VERSION); ignoring])
477          AC_MSG_NOTICE([(Your Build JDK must be version 9)])
478          BUILD_JDK_FOUND=no
479        else
480          # We're done!
481          BUILD_JDK_FOUND=yes
482          BASIC_FIXUP_PATH(BUILD_JDK)
483          AC_MSG_CHECKING([for Build JDK])
484          AC_MSG_RESULT([$BUILD_JDK])
485          AC_MSG_CHECKING([Build JDK version])
486          BUILD_JDK_VERSION=`"$BUILD_JDK/bin/java" -version 2>&1 | $TR '\n\r' '  '`
487          AC_MSG_RESULT([$BUILD_JDK_VERSION])
488        fi # end check jdk version
489      fi # end check java
490    fi # end check build jdk found
491  fi
492])
493
494# By default the BUILD_JDK is the JDK_OUTPUTDIR.  If the target architecture
495# is different than the host system doing the build (e.g. cross-compilation),
496# a special BUILD_JDK is built as part of the build process.  An external
497# prebuilt BUILD_JDK can also be supplied.
498AC_DEFUN([BOOTJDK_SETUP_BUILD_JDK],
499[
500  AC_ARG_WITH(build-jdk, [AS_HELP_STRING([--with-build-jdk],
501      [path to JDK of same version as is being built@<:@the newly built JDK@:>@])])
502
503  CREATE_BUILDJDK=false
504  EXTERNAL_BUILDJDK=false
505  BUILD_JDK_FOUND="no"
506  if test "x$with_build_jdk" != "x"; then
507    BOOTJDK_CHECK_BUILD_JDK([
508       if test "x$with_build_jdk" != x; then
509         BUILD_JDK=$with_build_jdk
510         BUILD_JDK_FOUND=maybe
511         AC_MSG_NOTICE([Found potential Build JDK using configure arguments])
512       fi])
513    EXTERNAL_BUILDJDK=true
514  else
515    if test "x$COMPILE_TYPE" = "xcross"; then
516      BUILD_JDK="\$(BUILDJDK_OUTPUTDIR)/jdk"
517      BUILD_JDK_FOUND=yes
518      CREATE_BUILDJDK=true
519      AC_MSG_CHECKING([for Build JDK])
520      AC_MSG_RESULT([yes, will build it for the host platform])
521    else
522      BUILD_JDK="\$(JDK_OUTPUTDIR)"
523      BUILD_JDK_FOUND=yes
524      AC_MSG_CHECKING([for Build JDK])
525      AC_MSG_RESULT([yes, will use output dir])
526    fi
527  fi
528
529  JMOD="$BUILD_JDK/bin/jmod"
530  JLINK="$BUILD_JDK/bin/jlink"
531  AC_SUBST(JMOD)
532  AC_SUBST(JLINK)
533
534  if test "x$BUILD_JDK_FOUND" != "xyes"; then
535    AC_MSG_CHECKING([for Build JDK])
536    AC_MSG_RESULT([no])
537    AC_MSG_ERROR([Could not find a suitable Build JDK])
538  fi
539
540  AC_SUBST(CREATE_BUILDJDK)
541  AC_SUBST(BUILD_JDK)
542  AC_SUBST(EXTERNAL_BUILDJDK)
543])
544