1 #
   2 # Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
   3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4 #
   5 # This code is free software; you can redistribute it and/or modify it
   6 # under the terms of the GNU General Public License version 2 only, as
   7 # published by the Free Software Foundation.  Oracle designates this
   8 # particular file as subject to the "Classpath" exception as provided
   9 # by Oracle in the LICENSE file that accompanied this code.
  10 #
  11 # This code is distributed in the hope that it will be useful, but WITHOUT
  12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14 # version 2 for more details (a copy is included in the LICENSE file that
  15 # accompanied this code).
  16 #
  17 # You should have received a copy of the GNU General Public License version
  18 # 2 along with this work; if not, write to the Free Software Foundation,
  19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20 #
  21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22 # or visit www.oracle.com if you need additional information or have any
  23 # questions.
  24 #
  25 
  26 AC_DEFUN([BPERF_CHECK_CORES],
  27 [
  28   AC_MSG_CHECKING([for number of cores])
  29   NUM_CORES=1
  30   FOUND_CORES=no
  31 
  32   if test -f /proc/cpuinfo; then
  33     # Looks like a Linux (or cygwin) system
  34     NUM_CORES=`cat /proc/cpuinfo  | grep -c processor`
  35     FOUND_CORES=yes
  36   elif test -x /usr/sbin/sysctl; then
  37     # Looks like a MacOSX system
  38     NUM_CORES=`/usr/sbin/sysctl -n hw.ncpu`
  39     FOUND_CORES=yes
  40   elif test "x$OPENJDK_BUILD_OS" = xaix ; then
  41     NUM_LCPU=`lparstat -m 2> /dev/null | $GREP -o "lcpu=[[0-9]]*" | $CUT -d "=" -f 2`
  42     if test -n "$NUM_LCPU"; then
  43       NUM_CORES=$NUM_LCPU
  44       FOUND_CORES=yes
  45     fi
  46   elif test -n "$NUMBER_OF_PROCESSORS"; then
  47     # On windows, look in the env
  48     NUM_CORES=$NUMBER_OF_PROCESSORS
  49     FOUND_CORES=yes
  50   fi
  51 
  52   if test "x$FOUND_CORES" = xyes; then
  53     AC_MSG_RESULT([$NUM_CORES])
  54   else
  55     AC_MSG_RESULT([could not detect number of cores, defaulting to 1])
  56     AC_MSG_WARN([This will disable all parallelism from build!])
  57   fi
  58 ])
  59 
  60 AC_DEFUN([BPERF_CHECK_MEMORY_SIZE],
  61 [
  62   AC_MSG_CHECKING([for memory size])
  63   # Default to 1024 MB
  64   MEMORY_SIZE=1024
  65   FOUND_MEM=no
  66 
  67   if test -f /proc/meminfo; then
  68     # Looks like a Linux (or cygwin) system
  69     MEMORY_SIZE=`cat /proc/meminfo | grep MemTotal | awk '{print [$]2}'`
  70     MEMORY_SIZE=`expr $MEMORY_SIZE / 1024`
  71     FOUND_MEM=yes
  72   elif test -x /usr/sbin/prtconf; then
  73     # Looks like an AIX system
  74     MEMORY_SIZE=`/usr/sbin/prtconf 2> /dev/null | grep "^Memory [[Ss]]ize" | awk '{ print [$]3 }'`
  75     FOUND_MEM=yes
  76   elif test -x /usr/sbin/sysctl; then
  77     # Looks like a MacOSX system
  78     MEMORY_SIZE=`/usr/sbin/sysctl -n hw.memsize`
  79     MEMORY_SIZE=`expr $MEMORY_SIZE / 1024 / 1024`
  80     FOUND_MEM=yes
  81   elif test "x$OPENJDK_BUILD_OS" = xwindows; then
  82     # Windows, but without cygwin
  83     MEMORY_SIZE=`wmic computersystem get totalphysicalmemory -value | grep = | cut -d "=" -f 2-`
  84     MEMORY_SIZE=`expr $MEMORY_SIZE / 1024 / 1024`
  85     FOUND_MEM=yes
  86   fi
  87 
  88   if test "x$FOUND_MEM" = xyes; then
  89     AC_MSG_RESULT([$MEMORY_SIZE MB])
  90   else
  91     AC_MSG_RESULT([could not detect memory size, defaulting to $MEMORY_SIZE MB])
  92     AC_MSG_WARN([This might seriously impact build performance!])
  93   fi
  94 ])
  95 
  96 AC_DEFUN_ONCE([BPERF_SETUP_BUILD_CORES],
  97 [
  98   # How many cores do we have on this build system?
  99   AC_ARG_WITH(num-cores, [AS_HELP_STRING([--with-num-cores],
 100       [number of cores in the build system, e.g. --with-num-cores=8 @<:@probed@:>@])])
 101   if test "x$with_num_cores" = x; then
 102     # The number of cores were not specified, try to probe them.
 103     BPERF_CHECK_CORES
 104   else
 105     NUM_CORES=$with_num_cores
 106   fi
 107   AC_SUBST(NUM_CORES)
 108 ])
 109 
 110 AC_DEFUN_ONCE([BPERF_SETUP_BUILD_MEMORY],
 111 [
 112   # How much memory do we have on this build system?
 113   AC_ARG_WITH(memory-size, [AS_HELP_STRING([--with-memory-size],
 114       [memory (in MB) available in the build system, e.g. --with-memory-size=1024 @<:@probed@:>@])])
 115   if test "x$with_memory_size" = x; then
 116     # The memory size was not specified, try to probe it.
 117     BPERF_CHECK_MEMORY_SIZE
 118   else
 119     MEMORY_SIZE=$with_memory_size
 120   fi
 121   AC_SUBST(MEMORY_SIZE)
 122 ])
 123 
 124 AC_DEFUN_ONCE([BPERF_SETUP_BUILD_JOBS],
 125 [
 126   # Provide a decent default number of parallel jobs for make depending on
 127   # number of cores, amount of memory and machine architecture.
 128   AC_ARG_WITH(jobs, [AS_HELP_STRING([--with-jobs],
 129       [number of parallel jobs to let make run @<:@calculated based on cores and memory@:>@])])
 130   if test "x$with_jobs" = x; then
 131     # Number of jobs was not specified, calculate.
 132     AC_MSG_CHECKING([for appropriate number of jobs to run in parallel])
 133     # Approximate memory in GB.
 134     memory_gb=`expr $MEMORY_SIZE / 1024`
 135     # Pick the lowest of memory in gb and number of cores.
 136     if test "$memory_gb" -lt "$NUM_CORES"; then
 137       JOBS="$memory_gb"
 138     else
 139       JOBS="$NUM_CORES"
 140     fi
 141     if test "$JOBS" -eq "0"; then
 142       JOBS=1
 143     fi
 144     AC_MSG_RESULT([$JOBS])
 145   else
 146     JOBS=$with_jobs
 147   fi
 148   AC_SUBST(JOBS)
 149 ])
 150 
 151 AC_DEFUN_ONCE([BPERF_SETUP_TEST_JOBS],
 152 [
 153   # The number of test jobs will be chosen automatically if TEST_JOBS is 0
 154   AC_ARG_WITH(test-jobs, [AS_HELP_STRING([--with-test-jobs],
 155       [number of parallel tests jobs to run @<:@based on build jobs@:>@])])
 156   if test "x$with_test_jobs" = x; then
 157       TEST_JOBS=0
 158   else
 159       TEST_JOBS=$with_test_jobs
 160   fi
 161   AC_SUBST(TEST_JOBS)
 162 ])
 163 
 164 AC_DEFUN([BPERF_SETUP_CCACHE],
 165 [
 166   # Check if ccache is available
 167   CCACHE_AVAILABLE=true
 168 
 169   OLD_PATH="$PATH"
 170   if test "x$TOOLCHAIN_PATH" != x; then
 171     PATH=$TOOLCHAIN_PATH:$PATH
 172   fi
 173   UTIL_PATH_PROGS(CCACHE, ccache)
 174   PATH="$OLD_PATH"
 175 
 176   AC_MSG_CHECKING([if ccache is available])
 177   if test "x$TOOLCHAIN_TYPE" != "xgcc" && test "x$TOOLCHAIN_TYPE" != "xclang"; then
 178     AC_MSG_RESULT([no, not supported for toolchain type $TOOLCHAIN_TYPE])
 179     CCACHE_AVAILABLE=false
 180   elif test "x$CCACHE" = "x"; then
 181     AC_MSG_RESULT([no, ccache binary missing or not executable])
 182     CCACHE_AVAILABLE=false
 183   else
 184     AC_MSG_RESULT([yes])
 185   fi
 186 
 187   CCACHE_STATUS=""
 188   UTIL_ARG_ENABLE(NAME: ccache, DEFAULT: false, AVAILABLE: $CCACHE_AVAILABLE,
 189       DESC: [enable using ccache to speed up recompilations],
 190       CHECKING_MSG: [if ccache is enabled],
 191       IF_ENABLED: [
 192         CCACHE_VERSION=[`$CCACHE --version | head -n1 | $SED 's/[A-Za-z ]*//'`]
 193         CCACHE_STATUS="Active ($CCACHE_VERSION)"
 194       ],
 195       IF_DISABLED: [
 196         CCACHE=""
 197       ])
 198   AC_SUBST(CCACHE)
 199 
 200   AC_ARG_WITH([ccache-dir],
 201       [AS_HELP_STRING([--with-ccache-dir],
 202       [where to store ccache files @<:@~/.ccache@:>@])])
 203 
 204   if test "x$with_ccache_dir" != x; then
 205     # When using a non home ccache directory, assume the use is to share ccache files
 206     # with other users. Thus change the umask.
 207     SET_CCACHE_DIR="CCACHE_DIR=$with_ccache_dir CCACHE_UMASK=002"
 208     if test "x$CCACHE" = x; then
 209       AC_MSG_WARN([--with-ccache-dir has no meaning when ccache is not enabled])
 210     fi
 211   fi
 212 
 213   if test "x$CCACHE" != x; then
 214     BPERF_SETUP_CCACHE_USAGE
 215   fi
 216 ])
 217 
 218 AC_DEFUN([BPERF_SETUP_CCACHE_USAGE],
 219 [
 220   if test "x$CCACHE" != x; then
 221     if test "x$OPENJDK_BUILD_OS" = "xmacosx"; then
 222       HAS_BAD_CCACHE=[`$ECHO $CCACHE_VERSION | \
 223           $GREP -e '^1\.' -e '^2\.' -e '^3\.0\.' -e '^3\.1\.'`]
 224       if test "x$HAS_BAD_CCACHE" != "x"; then
 225         AC_MSG_ERROR([On macosx, ccache 3.2 or later is required, found $CCACHE_VERSION])
 226       fi
 227     fi
 228     if test "x$USE_PRECOMPILED_HEADER" = "xtrue"; then
 229       HAS_BAD_CCACHE=[`$ECHO $CCACHE_VERSION | \
 230           $GREP -e '^1.*' -e '^2.*' -e '^3\.0.*' -e '^3\.1\.[0123]$'`]
 231       if test "x$HAS_BAD_CCACHE" != "x"; then
 232         AC_MSG_ERROR([Precompiled headers requires ccache 3.1.4 or later, found $CCACHE_VERSION])
 233       fi
 234       AC_MSG_CHECKING([if C-compiler supports ccache precompiled headers])
 235       CCACHE_PRECOMP_FLAG="-fpch-preprocess"
 236       PUSHED_FLAGS="$CXXFLAGS"
 237       CXXFLAGS="$CCACHE_PRECOMP_FLAG $CXXFLAGS"
 238       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [CC_KNOWS_CCACHE_TRICK=yes], [CC_KNOWS_CCACHE_TRICK=no])
 239       CXXFLAGS="$PUSHED_FLAGS"
 240       if test "x$CC_KNOWS_CCACHE_TRICK" = xyes; then
 241         AC_MSG_RESULT([yes])
 242         CFLAGS_CCACHE="$CCACHE_PRECOMP_FLAG"
 243         AC_SUBST(CFLAGS_CCACHE)
 244         CCACHE_SLOPPINESS=pch_defines,time_macros
 245       else
 246         AC_MSG_RESULT([no])
 247         AC_MSG_ERROR([Cannot use ccache with precompiled headers without compiler support for $CCACHE_PRECOMP_FLAG])
 248       fi
 249     fi
 250 
 251     CCACHE="CCACHE_COMPRESS=1 $SET_CCACHE_DIR \
 252         CCACHE_SLOPPINESS=$CCACHE_SLOPPINESS CCACHE_BASEDIR=$TOPDIR $CCACHE"
 253 
 254     if test "x$SET_CCACHE_DIR" != x; then
 255       mkdir -p $CCACHE_DIR > /dev/null 2>&1
 256       chmod a+rwxs $CCACHE_DIR > /dev/null 2>&1
 257     fi
 258   fi
 259 ])
 260 
 261 ################################################################################
 262 #
 263 # Runs icecc-create-env once and prints the error if it fails
 264 #
 265 # $1: arguments to icecc-create-env
 266 # $2: log file
 267 #
 268 AC_DEFUN([BPERF_RUN_ICECC_CREATE_ENV],
 269 [
 270   ( cd ${CONFIGURESUPPORT_OUTPUTDIR}/icecc \
 271       && ${ICECC_CREATE_ENV} $1 > $2 2>&1 )
 272   if test "$?" != "0"; then
 273     AC_MSG_NOTICE([icecc-create-env output:])
 274     cat $2
 275     AC_MSG_ERROR([Failed to create icecc compiler environment])
 276   fi
 277 ])
 278 
 279 ################################################################################
 280 #
 281 # Optionally enable distributed compilation of native code using icecc/icecream
 282 #
 283 AC_DEFUN([BPERF_SETUP_ICECC],
 284 [
 285   UTIL_ARG_ENABLE(NAME: icecc, DEFAULT: false, RESULT: ENABLE_ICECC,
 286       DESC: [enable distributed compilation of native code using icecc/icecream])
 287 
 288   if test "x$ENABLE_ICECC" = "xtrue"; then
 289     UTIL_REQUIRE_PROGS(ICECC_CMD, icecc)
 290     old_path="$PATH"
 291 
 292     # Look for icecc-create-env in some known places
 293     PATH="$PATH:/usr/lib/icecc:/usr/lib64/icecc"
 294     UTIL_REQUIRE_PROGS(ICECC_CREATE_ENV, icecc-create-env)
 295     # Use icecc-create-env to create a minimal compilation environment that can
 296     # be sent to the other hosts in the icecream cluster.
 297     icecc_create_env_log="${CONFIGURESUPPORT_OUTPUTDIR}/icecc/icecc_create_env.log"
 298     ${MKDIR} -p ${CONFIGURESUPPORT_OUTPUTDIR}/icecc
 299     # Older versions of icecc does not have the --gcc parameter
 300     if ${ICECC_CREATE_ENV} | $GREP -q -e --gcc; then
 301       icecc_gcc_arg="--gcc"
 302     fi
 303     if test "x${TOOLCHAIN_TYPE}" = "xgcc"; then
 304       BPERF_RUN_ICECC_CREATE_ENV([${icecc_gcc_arg} ${CC} ${CXX}], \
 305           ${icecc_create_env_log})
 306     elif test "x$TOOLCHAIN_TYPE" = "xclang"; then
 307       # For clang, the icecc compilerwrapper is needed. It usually resides next
 308       # to icecc-create-env.
 309       UTIL_REQUIRE_PROGS(ICECC_WRAPPER, compilerwrapper)
 310       BPERF_RUN_ICECC_CREATE_ENV([--clang ${CC} ${ICECC_WRAPPER}], ${icecc_create_env_log})
 311     else
 312       AC_MSG_ERROR([Can only create icecc compiler packages for toolchain types gcc and clang])
 313     fi
 314     PATH="$old_path"
 315     # The bundle with the compiler gets a name based on checksums. Parse log file
 316     # to find it.
 317     ICECC_ENV_BUNDLE_BASENAME="`${SED} -n '/^creating/s/creating //p' ${icecc_create_env_log}`"
 318     ICECC_ENV_BUNDLE="${CONFIGURESUPPORT_OUTPUTDIR}/icecc/${ICECC_ENV_BUNDLE_BASENAME}"
 319     if test ! -f ${ICECC_ENV_BUNDLE}; then
 320       AC_MSG_ERROR([icecc-create-env did not produce an environment ${ICECC_ENV_BUNDLE}])
 321     fi
 322     AC_MSG_CHECKING([for icecc build environment for target compiler])
 323     AC_MSG_RESULT([${ICECC_ENV_BUNDLE}])
 324     ICECC="ICECC_VERSION=${ICECC_ENV_BUNDLE} ICECC_CC=${CC} ICECC_CXX=${CXX} ${ICECC_CMD}"
 325 
 326     if test "x${COMPILE_TYPE}" = "xcross"; then
 327       # If cross compiling, create a separate env package for the build compiler
 328       # Assume "gcc" or "cc" is gcc and "clang" is clang. Otherwise bail.
 329       icecc_create_env_log_build="${CONFIGURESUPPORT_OUTPUTDIR}/icecc/icecc_create_env_build.log"
 330       if test "x${BUILD_CC##*/}" = "xgcc" ||  test "x${BUILD_CC##*/}" = "xcc"; then
 331         BPERF_RUN_ICECC_CREATE_ENV([${icecc_gcc_arg} ${BUILD_CC} ${BUILD_CXX}], \
 332             ${icecc_create_env_log_build})
 333       elif test "x${BUILD_CC##*/}" = "xclang"; then
 334         BPERF_RUN_ICECC_CREATE_ENV([--clang ${BUILD_CC} ${ICECC_WRAPPER}], ${icecc_create_env_log_build})
 335       else
 336         AC_MSG_ERROR([Cannot create icecc compiler package for ${BUILD_CC}])
 337       fi
 338       ICECC_ENV_BUNDLE_BASENAME="`${SED} -n '/^creating/s/creating //p' ${icecc_create_env_log_build}`"
 339       ICECC_ENV_BUNDLE="${CONFIGURESUPPORT_OUTPUTDIR}/icecc/${ICECC_ENV_BUNDLE_BASENAME}"
 340       if test ! -f ${ICECC_ENV_BUNDLE}; then
 341         AC_MSG_ERROR([icecc-create-env did not produce an environment ${ICECC_ENV_BUNDLE}])
 342       fi
 343       AC_MSG_CHECKING([for icecc build environment for build compiler])
 344       AC_MSG_RESULT([${ICECC_ENV_BUNDLE}])
 345       BUILD_ICECC="ICECC_VERSION=${ICECC_ENV_BUNDLE} ICECC_CC=${BUILD_CC} \
 346           ICECC_CXX=${BUILD_CXX} ${ICECC_CMD}"
 347     else
 348       BUILD_ICECC="${ICECC}"
 349     fi
 350   fi
 351 
 352   AC_SUBST(ICECC)
 353   AC_SUBST(BUILD_ICECC)
 354 ])
 355 
 356 AC_DEFUN_ONCE([BPERF_SETUP_PRECOMPILED_HEADERS],
 357 [
 358   # Are precompiled headers available?
 359   PRECOMPILED_HEADERS_AVAILABLE=true
 360   AC_MSG_CHECKING([if precompiled headers are available])
 361   if test "x$ICECC" != "x"; then
 362     AC_MSG_RESULT([no, does not work effectively with icecc])
 363     PRECOMPILED_HEADERS_AVAILABLE=false
 364   elif test "x$TOOLCHAIN_TYPE" = xxlc; then
 365     AC_MSG_RESULT([no, does not work with xlc])
 366     PRECOMPILED_HEADERS_AVAILABLE=false
 367   elif test "x$TOOLCHAIN_TYPE" = xgcc; then
 368     # Check that the compiler actually supports precomp headers.
 369     echo "int alfa();" > conftest.h
 370     $CXX -x c++-header conftest.h -o conftest.hpp.gch 2>&AS_MESSAGE_LOG_FD >&AS_MESSAGE_LOG_FD
 371     if test ! -f conftest.hpp.gch; then
 372       PRECOMPILED_HEADERS_AVAILABLE=false
 373       AC_MSG_RESULT([no, gcc fails to compile properly with -x c++-header])
 374     else
 375       AC_MSG_RESULT([yes])
 376     fi
 377     $RM conftest.h conftest.hpp.gch
 378   else
 379     AC_MSG_RESULT([yes])
 380   fi
 381 
 382   UTIL_ARG_ENABLE(NAME: precompiled-headers, DEFAULT: auto,
 383       RESULT: USE_PRECOMPILED_HEADER, AVAILABLE: $PRECOMPILED_HEADERS_AVAILABLE,
 384       DESC: [enable using precompiled headers when compiling C++])
 385   AC_SUBST(USE_PRECOMPILED_HEADER)
 386 ])
 387 
 388 
 389 AC_DEFUN_ONCE([BPERF_SETUP_JAVAC_SERVER],
 390 [
 391   UTIL_ARG_ENABLE(NAME: javac-server, DEFAULT: true,
 392       RESULT: ENABLE_JAVAC_SERVER,
 393       DESC: [enable javac server],
 394       CHECKING_MSG: [whether to use javac server])
 395   AC_SUBST(ENABLE_JAVAC_SERVER)
 396 ])