build-performance.m4 revision 1705:8001eddb1672
155714Skris# 259191Skris# Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. 355714Skris# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 455714Skris# 555714Skris# This code is free software; you can redistribute it and/or modify it 655714Skris# under the terms of the GNU General Public License version 2 only, as 755714Skris# published by the Free Software Foundation. Oracle designates this 855714Skris# particular file as subject to the "Classpath" exception as provided 955714Skris# by Oracle in the LICENSE file that accompanied this code. 1055714Skris# 1155714Skris# This code is distributed in the hope that it will be useful, but WITHOUT 1255714Skris# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1355714Skris# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1455714Skris# version 2 for more details (a copy is included in the LICENSE file that 1555714Skris# accompanied this code). 1655714Skris# 1755714Skris# You should have received a copy of the GNU General Public License version 1855714Skris# 2 along with this work; if not, write to the Free Software Foundation, 1955714Skris# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2055714Skris# 2155714Skris# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2255714Skris# or visit www.oracle.com if you need additional information or have any 2355714Skris# questions. 2455714Skris# 2555714Skris 2655714SkrisAC_DEFUN([BPERF_CHECK_CORES], 2755714Skris[ 2855714Skris AC_MSG_CHECKING([for number of cores]) 2955714Skris NUM_CORES=1 3055714Skris FOUND_CORES=no 3155714Skris 3255714Skris if test -f /proc/cpuinfo; then 3355714Skris # Looks like a Linux (or cygwin) system 3455714Skris NUM_CORES=`cat /proc/cpuinfo | grep -c processor` 3555714Skris FOUND_CORES=yes 3655714Skris elif test -x /usr/sbin/psrinfo; then 3755714Skris # Looks like a Solaris system 3855714Skris NUM_CORES=`LC_MESSAGES=C /usr/sbin/psrinfo -v | grep -c on-line` 3955714Skris FOUND_CORES=yes 4055714Skris elif test -x /usr/sbin/system_profiler; then 4155714Skris # Looks like a MacOSX system 4255714Skris NUM_CORES=`/usr/sbin/system_profiler -detailLevel full SPHardwareDataType | grep 'Cores' | awk '{print [$]5}'` 4355714Skris FOUND_CORES=yes 4455714Skris elif test "x$OPENJDK_BUILD_OS" = xaix ; then 4555714Skris NUM_CORES=`/usr/sbin/prtconf | grep "^Number Of Processors" | awk '{ print [$]4 }'` 4655714Skris FOUND_CORES=yes 4755714Skris elif test -n "$NUMBER_OF_PROCESSORS"; then 4855714Skris # On windows, look in the env 4955714Skris NUM_CORES=$NUMBER_OF_PROCESSORS 5055714Skris FOUND_CORES=yes 5155714Skris fi 5255714Skris 5355714Skris if test "x$FOUND_CORES" = xyes; then 5455714Skris AC_MSG_RESULT([$NUM_CORES]) 5555714Skris else 5655714Skris AC_MSG_RESULT([could not detect number of cores, defaulting to 1]) 5755714Skris AC_MSG_WARN([This will disable all parallelism from build!]) 5855714Skris fi 5955714Skris]) 60160814Ssimon 61160814SsimonAC_DEFUN([BPERF_CHECK_MEMORY_SIZE], 62160814Ssimon[ 63160814Ssimon AC_MSG_CHECKING([for memory size]) 64160814Ssimon # Default to 1024 MB 65160814Ssimon MEMORY_SIZE=1024 66160814Ssimon FOUND_MEM=no 67109998Smarkm 6855714Skris if test -f /proc/meminfo; then 6955714Skris # Looks like a Linux (or cygwin) system 7055714Skris MEMORY_SIZE=`cat /proc/meminfo | grep MemTotal | awk '{print [$]2}'` 7155714Skris MEMORY_SIZE=`expr $MEMORY_SIZE / 1024` 7255714Skris FOUND_MEM=yes 7355714Skris elif test -x /usr/sbin/prtconf; then 7455714Skris # Looks like a Solaris or AIX system 7555714Skris MEMORY_SIZE=`/usr/sbin/prtconf | grep "^Memory [[Ss]]ize" | awk '{ print [$]3 }'` 7655714Skris FOUND_MEM=yes 7755714Skris elif test -x /usr/sbin/system_profiler; then 7855714Skris # Looks like a MacOSX system 7955714Skris MEMORY_SIZE=`/usr/sbin/system_profiler -detailLevel full SPHardwareDataType | grep 'Memory' | awk '{print [$]2}'` 8055714Skris MEMORY_SIZE=`expr $MEMORY_SIZE \* 1024` 8155714Skris FOUND_MEM=yes 8255714Skris elif test "x$OPENJDK_BUILD_OS" = xwindows; then 8355714Skris # Windows, but without cygwin 8455714Skris MEMORY_SIZE=`wmic computersystem get totalphysicalmemory -value | grep = | cut -d "=" -f 2-` 85160814Ssimon MEMORY_SIZE=`expr $MEMORY_SIZE / 1024 / 1024` 8659191Skris FOUND_MEM=yes 8759191Skris fi 8859191Skris 8955714Skris if test "x$FOUND_MEM" = xyes; then 9055714Skris AC_MSG_RESULT([$MEMORY_SIZE MB]) 91160814Ssimon else 92111147Snectar AC_MSG_RESULT([could not detect memory size, defaulting to $MEMORY_SIZE MB]) 93109998Smarkm AC_MSG_WARN([This might seriously impact build performance!]) 94111147Snectar fi 9555714Skris]) 9655714Skris 9755714SkrisAC_DEFUN_ONCE([BPERF_SETUP_BUILD_CORES], 9855714Skris[ 9959191Skris # How many cores do we have on this build system? 100111147Snectar AC_ARG_WITH(num-cores, [AS_HELP_STRING([--with-num-cores], 101109998Smarkm [number of cores in the build system, e.g. --with-num-cores=8 @<:@probed@:>@])]) 102111147Snectar if test "x$with_num_cores" = x; then 10355714Skris # The number of cores were not specified, try to probe them. 10455714Skris BPERF_CHECK_CORES 10555714Skris else 10655714Skris NUM_CORES=$with_num_cores 107160814Ssimon fi 10855714Skris AC_SUBST(NUM_CORES) 10955714Skris]) 11055714Skris 11155714SkrisAC_DEFUN_ONCE([BPERF_SETUP_BUILD_MEMORY], 112109998Smarkm[ 113109998Smarkm # How much memory do we have on this build system? 114109998Smarkm AC_ARG_WITH(memory-size, [AS_HELP_STRING([--with-memory-size], 11555714Skris [memory (in MB) available in the build system, e.g. --with-memory-size=1024 @<:@probed@:>@])]) 11655714Skris if test "x$with_memory_size" = x; then 11755714Skris # The memory size was not specified, try to probe it. 11855714Skris BPERF_CHECK_MEMORY_SIZE 11955714Skris else 12055714Skris MEMORY_SIZE=$with_memory_size 12155714Skris fi 12255714Skris AC_SUBST(MEMORY_SIZE) 12355714Skris]) 12455714Skris 12555714SkrisAC_DEFUN_ONCE([BPERF_SETUP_BUILD_JOBS], 12655714Skris[ 12755714Skris # Provide a decent default number of parallel jobs for make depending on 12855714Skris # number of cores, amount of memory and machine architecture. 12955714Skris AC_ARG_WITH(jobs, [AS_HELP_STRING([--with-jobs], 13055714Skris [number of parallel jobs to let make run @<:@calculated based on cores and memory@:>@])]) 131111147Snectar if test "x$with_jobs" = x; then 132109998Smarkm # Number of jobs was not specified, calculate. 133109998Smarkm AC_MSG_CHECKING([for appropriate number of jobs to run in parallel]) 134109998Smarkm # Approximate memory in GB. 135109998Smarkm memory_gb=`expr $MEMORY_SIZE / 1024` 136109998Smarkm # Pick the lowest of memory in gb and number of cores. 137111147Snectar if test "$memory_gb" -lt "$NUM_CORES"; then 13855714Skris JOBS="$memory_gb" 13955714Skris else 14055714Skris JOBS="$NUM_CORES" 14155714Skris # On bigger machines, leave some room for other processes to run 14255714Skris if test "$JOBS" -gt "4"; then 14355714Skris JOBS=`expr $JOBS '*' 90 / 100` 14455714Skris fi 14555714Skris fi 14655714Skris # Cap number of jobs to 16 14755714Skris if test "$JOBS" -gt "16"; then 14855714Skris JOBS=16 14955714Skris fi 15055714Skris if test "$JOBS" -eq "0"; then 15155714Skris JOBS=1 15255714Skris fi 153109998Smarkm AC_MSG_RESULT([$JOBS]) 154109998Smarkm else 155109998Smarkm JOBS=$with_jobs 156111147Snectar fi 157109998Smarkm AC_SUBST(JOBS) 158111147Snectar]) 15959191Skris 16055714SkrisAC_DEFUN([BPERF_SETUP_CCACHE], 16155714Skris[ 16255714Skris AC_ARG_ENABLE([ccache], 16355714Skris [AS_HELP_STRING([--enable-ccache], 16455714Skris [enable using ccache to speed up recompilations @<:@disabled@:>@])]) 165111147Snectar 166109998Smarkm CCACHE= 167111147Snectar CCACHE_STATUS= 168109998Smarkm AC_MSG_CHECKING([is ccache enabled]) 16955714Skris if test "x$enable_ccache" = xyes; then 17055714Skris if test "x$TOOLCHAIN_TYPE" = "xgcc" -o "x$TOOLCHAIN_TYPE" = "xclang"; then 17155714Skris AC_MSG_RESULT([yes]) 17255714Skris OLD_PATH="$PATH" 17355714Skris if test "x$TOOLCHAIN_PATH" != x; then 17455714Skris PATH=$TOOLCHAIN_PATH:$PATH 17555714Skris fi 17655714Skris BASIC_REQUIRE_PROGS(CCACHE, ccache) 17768651Skris PATH="$OLD_PATH" 17855714Skris CCACHE_VERSION=[`$CCACHE --version | head -n1 | $SED 's/[A-Za-z ]*//'`] 179109998Smarkm CCACHE_STATUS="Active ($CCACHE_VERSION)" 18068651Skris else 18168651Skris AC_MSG_RESULT([no]) 18268651Skris AC_MSG_WARN([ccache is not supported with toolchain type $TOOLCHAIN_TYPE]) 18368651Skris fi 18468651Skris elif test "x$enable_ccache" = xno; then 18568651Skris AC_MSG_RESULT([no, explicitly disabled]) 18655714Skris CCACHE_STATUS="Disabled" 18755714Skris elif test "x$enable_ccache" = x; then 18855714Skris AC_MSG_RESULT([no]) 18955714Skris else 19055714Skris AC_MSG_RESULT([unknown]) 19155714Skris AC_MSG_ERROR([--enable-ccache does not accept any parameters]) 19255714Skris fi 19355714Skris AC_SUBST(CCACHE) 19455714Skris 19559191Skris AC_ARG_WITH([ccache-dir], 19659191Skris [AS_HELP_STRING([--with-ccache-dir], 19755714Skris [where to store ccache files @<:@~/.ccache@:>@])]) 19859191Skris 19959191Skris if test "x$with_ccache_dir" != x; then 20055714Skris # When using a non home ccache directory, assume the use is to share ccache files 20159191Skris # with other users. Thus change the umask. 20255714Skris SET_CCACHE_DIR="CCACHE_DIR=$with_ccache_dir CCACHE_UMASK=002" 20359191Skris if test "x$CCACHE" = x; then 20455714Skris AC_MSG_WARN([--with-ccache-dir has no meaning when ccache is not enabled]) 205160814Ssimon fi 206160814Ssimon fi 207160814Ssimon 20855714Skris if test "x$CCACHE" != x; then 20959191Skris BPERF_SETUP_CCACHE_USAGE 21055714Skris fi 21155714Skris]) 21255714Skris 21355714SkrisAC_DEFUN([BPERF_SETUP_CCACHE_USAGE], 21455714Skris[ 21555714Skris if test "x$CCACHE" != x; then 21655714Skris if test "x$USE_PRECOMPILED_HEADER" = "x1"; then 21768651Skris HAS_BAD_CCACHE=[`$ECHO $CCACHE_VERSION | \ 21855714Skris $GREP -e '^1.*' -e '^2.*' -e '^3\.0.*' -e '^3\.1\.[0123]$'`] 219109998Smarkm if test "x$HAS_BAD_CCACHE" != "x"; then 220109998Smarkm AC_MSG_ERROR([Precompiled headers requires ccache 3.1.4 or later, found $CCACHE_VERSION]) 22155714Skris fi 22255714Skris AC_MSG_CHECKING([if C-compiler supports ccache precompiled headers]) 223160814Ssimon CCACHE_PRECOMP_FLAG="-fpch-preprocess" 22455714Skris PUSHED_FLAGS="$CXXFLAGS" 22555714Skris CXXFLAGS="$CCACHE_PRECOMP_FLAG $CXXFLAGS" 22655714Skris AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [CC_KNOWS_CCACHE_TRICK=yes], [CC_KNOWS_CCACHE_TRICK=no]) 22755714Skris CXXFLAGS="$PUSHED_FLAGS" 22855714Skris if test "x$CC_KNOWS_CCACHE_TRICK" = xyes; then 22955714Skris AC_MSG_RESULT([yes]) 23055714Skris CFLAGS_CCACHE="$CCACHE_PRECOMP_FLAG" 231160814Ssimon AC_SUBST(CFLAGS_CCACHE) 232160814Ssimon CCACHE_SLOPPINESS=pch_defines,time_macros 23355714Skris else 23455714Skris AC_MSG_RESULT([no]) 23555714Skris AC_MSG_ERROR([Cannot use ccache with precompiled headers without compiler support for $CCACHE_PRECOMP_FLAG]) 236160814Ssimon fi 23755714Skris fi 23855714Skris 239 CCACHE="CCACHE_COMPRESS=1 $SET_CCACHE_DIR \ 240 CCACHE_SLOPPINESS=$CCACHE_SLOPPINESS CCACHE_BASEDIR=$TOPDIR $CCACHE" 241 242 if test "x$SET_CCACHE_DIR" != x; then 243 mkdir -p $CCACHE_DIR > /dev/null 2>&1 244 chmod a+rwxs $CCACHE_DIR > /dev/null 2>&1 245 fi 246 fi 247]) 248 249AC_DEFUN_ONCE([BPERF_SETUP_PRECOMPILED_HEADERS], 250[ 251 252 ############################################################################### 253 # 254 # Can the C/C++ compiler use precompiled headers? 255 # 256 AC_ARG_ENABLE([precompiled-headers], [AS_HELP_STRING([--disable-precompiled-headers], 257 [disable using precompiled headers when compiling C++ @<:@enabled@:>@])], 258 [ENABLE_PRECOMPH=${enable_precompiled_headers}], [ENABLE_PRECOMPH=yes]) 259 260 USE_PRECOMPILED_HEADER=1 261 if test "x$ENABLE_PRECOMPH" = xno; then 262 USE_PRECOMPILED_HEADER=0 263 fi 264 265 if test "x$ENABLE_PRECOMPH" = xyes; then 266 # Check that the compiler actually supports precomp headers. 267 if test "x$TOOLCHAIN_TYPE" = xgcc; then 268 AC_MSG_CHECKING([that precompiled headers work]) 269 echo "int alfa();" > conftest.h 270 $CXX -x c++-header conftest.h -o conftest.hpp.gch 2>&AS_MESSAGE_LOG_FD >&AS_MESSAGE_LOG_FD 271 if test ! -f conftest.hpp.gch; then 272 USE_PRECOMPILED_HEADER=0 273 AC_MSG_RESULT([no]) 274 else 275 AC_MSG_RESULT([yes]) 276 fi 277 rm -f conftest.h conftest.hpp.gch 278 fi 279 fi 280 281 AC_SUBST(USE_PRECOMPILED_HEADER) 282]) 283 284 285AC_DEFUN_ONCE([BPERF_SETUP_SMART_JAVAC], 286[ 287 AC_ARG_WITH(sjavac-server-java, [AS_HELP_STRING([--with-sjavac-server-java], 288 [use this java binary for running the sjavac background server @<:@Boot JDK java@:>@])]) 289 290 if test "x$with_sjavac_server_java" != x; then 291 SJAVAC_SERVER_JAVA="$with_sjavac_server_java" 292 FOUND_VERSION=`$SJAVAC_SERVER_JAVA -version 2>&1 | grep " version \""` 293 if test "x$FOUND_VERSION" = x; then 294 AC_MSG_ERROR([Could not execute server java: $SJAVAC_SERVER_JAVA]) 295 fi 296 else 297 SJAVAC_SERVER_JAVA="$JAVA" 298 fi 299 AC_SUBST(SJAVAC_SERVER_JAVA) 300 301 if test "$MEMORY_SIZE" -gt "3000"; then 302 ADD_JVM_ARG_IF_OK([-d64],SJAVAC_SERVER_JAVA_FLAGS,[$SJAVAC_SERVER_JAVA]) 303 if test "$JVM_ARG_OK" = true; then 304 JVM_64BIT=true 305 JVM_ARG_OK=false 306 fi 307 fi 308 309 MX_VALUE=`expr $MEMORY_SIZE / 2` 310 if test "$JVM_64BIT" = true; then 311 # Set ms lower than mx since more than one instance of the server might 312 # get launched at the same time before they figure out which instance won. 313 MS_VALUE=512 314 if test "$MX_VALUE" -gt "2048"; then 315 MX_VALUE=2048 316 fi 317 else 318 MS_VALUE=256 319 if test "$MX_VALUE" -gt "1500"; then 320 MX_VALUE=1500 321 fi 322 fi 323 if test "$MX_VALUE" -lt "512"; then 324 MX_VALUE=512 325 fi 326 ADD_JVM_ARG_IF_OK([-Xms${MS_VALUE}M -Xmx${MX_VALUE}M],SJAVAC_SERVER_JAVA_FLAGS,[$SJAVAC_SERVER_JAVA]) 327 AC_SUBST(SJAVAC_SERVER_JAVA_FLAGS) 328 329 AC_ARG_ENABLE([sjavac], [AS_HELP_STRING([--enable-sjavac], 330 [use sjavac to do fast incremental compiles @<:@disabled@:>@])], 331 [ENABLE_SJAVAC="${enableval}"], [ENABLE_SJAVAC="no"]) 332 if test "x$JVM_ARG_OK" = "xfalse"; then 333 AC_MSG_WARN([Could not set -Xms${MS_VALUE}M -Xmx${MX_VALUE}M, disabling sjavac]) 334 ENABLE_SJAVAC="no" 335 fi 336 AC_MSG_CHECKING([whether to use sjavac]) 337 AC_MSG_RESULT([$ENABLE_SJAVAC]) 338 AC_SUBST(ENABLE_SJAVAC) 339 340 AC_ARG_ENABLE([javac-server], [AS_HELP_STRING([--enable-javac-server], 341 [use only the server part of sjavac for faster javac compiles @<:@disabled@:>@])], 342 [ENABLE_JAVAC_SERVER="${enableval}"], [ENABLE_JAVAC_SERVER="no"]) 343 if test "x$JVM_ARG_OK" = "xfalse"; then 344 AC_MSG_WARN([Could not set -Xms${MS_VALUE}M -Xmx${MX_VALUE}M, disabling javac server]) 345 ENABLE_JAVAC_SERVER="no" 346 fi 347 AC_MSG_CHECKING([whether to use javac server]) 348 AC_MSG_RESULT([$ENABLE_JAVAC_SERVER]) 349 AC_SUBST(ENABLE_JAVAC_SERVER) 350]) 351