build-performance.m4 revision 1364:d140b51ac9bb
18097Sjkh# 250479Speter# Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. 38097Sjkh# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 48097Sjkh# 58097Sjkh# This code is free software; you can redistribute it and/or modify it 68097Sjkh# under the terms of the GNU General Public License version 2 only, as 78097Sjkh# published by the Free Software Foundation. Oracle designates this 88097Sjkh# particular file as subject to the "Classpath" exception as provided 98097Sjkh# by Oracle in the LICENSE file that accompanied this code. 108097Sjkh# 118881Srgrimes# This code is distributed in the hope that it will be useful, but WITHOUT 128881Srgrimes# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 138097Sjkh# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 148097Sjkh# version 2 for more details (a copy is included in the LICENSE file that 158097Sjkh# accompanied this code). 168097Sjkh# 178097Sjkh# You should have received a copy of the GNU General Public License version 188097Sjkh# 2 along with this work; if not, write to the Free Software Foundation, 198097Sjkh# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 208097Sjkh# 218097Sjkh# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 228097Sjkh# or visit www.oracle.com if you need additional information or have any 238097Sjkh# questions. 248097Sjkh# 258097Sjkh 268097SjkhAC_DEFUN([BPERF_CHECK_CORES], 278097Sjkh[ 288097Sjkh AC_MSG_CHECKING([for number of cores]) 298097Sjkh NUM_CORES=1 308097Sjkh FOUND_CORES=no 318097Sjkh 32161060Snetchild if test -f /proc/cpuinfo; then 338097Sjkh # Looks like a Linux (or cygwin) system 348825Sjkh NUM_CORES=`cat /proc/cpuinfo | grep -c processor` 3566834Sphk FOUND_CORES=yes 368097Sjkh elif test -x /usr/sbin/psrinfo; then 378837Sjkh # Looks like a Solaris system 388837Sjkh NUM_CORES=`LC_MESSAGES=C /usr/sbin/psrinfo -v | grep -c on-line` 398837Sjkh FOUND_CORES=yes 4012661Speter elif test -x /usr/sbin/system_profiler; then 4112661Speter # Looks like a MacOSX system 4212661Speter NUM_CORES=`/usr/sbin/system_profiler -detailLevel full SPHardwareDataType | grep 'Cores' | awk '{print [$]5}'` 438837Sjkh FOUND_CORES=yes 448837Sjkh elif test "x$OPENJDK_BUILD_OS" = xaix ; then 458262Sjkh NUM_CORES=`/usr/sbin/prtconf | grep "^Number Of Processors" | awk '{ print [$]4 }'` 468262Sjkh FOUND_CORES=yes 47161099Sdelphij elif test -n "$NUMBER_OF_PROCESSORS"; then 488262Sjkh # On windows, look in the env 498262Sjkh NUM_CORES=$NUMBER_OF_PROCESSORS 508262Sjkh FOUND_CORES=yes 518262Sjkh fi 528262Sjkh 5315416Sjkh if test "x$FOUND_CORES" = xyes; then 548262Sjkh AC_MSG_RESULT([$NUM_CORES]) 558347Sjkh else 568262Sjkh AC_MSG_RESULT([could not detect number of cores, defaulting to 1]) 578262Sjkh AC_MSG_WARN([This will disable all parallelism from build!]) 588314Sjkh fi 5917375Sjkh]) 608262Sjkh 618262SjkhAC_DEFUN([BPERF_CHECK_MEMORY_SIZE], 628262Sjkh[ 638262Sjkh AC_MSG_CHECKING([for memory size]) 648097Sjkh # Default to 1024 MB 658097Sjkh MEMORY_SIZE=1024 66161099Sdelphij FOUND_MEM=no 678097Sjkh 688097Sjkh if test -f /proc/meminfo; then 698097Sjkh # Looks like a Linux (or cygwin) system 708705Sjkh MEMORY_SIZE=`cat /proc/meminfo | grep MemTotal | awk '{print [$]2}'` 718705Sjkh MEMORY_SIZE=`expr $MEMORY_SIZE / 1024` 728097Sjkh FOUND_MEM=yes 738705Sjkh elif test -x /usr/sbin/prtconf; then 748641Sjkh # Looks like a Solaris or AIX system 758641Sjkh MEMORY_SIZE=`/usr/sbin/prtconf | grep "^Memory [[Ss]]ize" | awk '{ print [$]3 }'` 7617375Sjkh FOUND_MEM=yes 778641Sjkh elif test -x /usr/sbin/system_profiler; then 788641Sjkh # Looks like a MacOSX system 798641Sjkh MEMORY_SIZE=`/usr/sbin/system_profiler -detailLevel full SPHardwareDataType | grep 'Memory' | awk '{print [$]2}'` 8015416Sjkh MEMORY_SIZE=`expr $MEMORY_SIZE \* 1024` 818097Sjkh FOUND_MEM=yes 828347Sjkh elif test "x$OPENJDK_BUILD_OS" = xwindows; then 838097Sjkh # Windows, but without cygwin 848705Sjkh MEMORY_SIZE=`wmic computersystem get totalphysicalmemory -value | grep = | cut -d "=" -f 2-` 858705Sjkh MEMORY_SIZE=`expr $MEMORY_SIZE / 1024 / 1024` 868705Sjkh FOUND_MEM=yes 878705Sjkh fi 888705Sjkh 898705Sjkh if test "x$FOUND_MEM" = xyes; then 908705Sjkh AC_MSG_RESULT([$MEMORY_SIZE MB]) 918705Sjkh else 9216366Sjkh AC_MSG_RESULT([could not detect memory size, defaulting to $MEMORY_SIZE MB]) 9317375Sjkh AC_MSG_WARN([This might seriously impact build performance!]) 948262Sjkh fi 9517375Sjkh]) 968262Sjkh 978097SjkhAC_DEFUN_ONCE([BPERF_SETUP_BUILD_CORES], 988097Sjkh[ 998097Sjkh # How many cores do we have on this build system? 1008097Sjkh AC_ARG_WITH(num-cores, [AS_HELP_STRING([--with-num-cores], 101161099Sdelphij [number of cores in the build system, e.g. --with-num-cores=8 @<:@probed@:>@])]) 1028097Sjkh if test "x$with_num_cores" = x; then 1038097Sjkh # The number of cores were not specified, try to probe them. 1048097Sjkh BPERF_CHECK_CORES 1058262Sjkh else 1068097Sjkh NUM_CORES=$with_num_cores 10715416Sjkh fi 1088097Sjkh AC_SUBST(NUM_CORES) 1098097Sjkh]) 1108097Sjkh 1118097SjkhAC_DEFUN_ONCE([BPERF_SETUP_BUILD_MEMORY], 1128262Sjkh[ 1138097Sjkh # How much memory do we have on this build system? 11416366Sjkh AC_ARG_WITH(memory-size, [AS_HELP_STRING([--with-memory-size], 11517375Sjkh [memory (in MB) available in the build system, e.g. --with-memory-size=1024 @<:@probed@:>@])]) 1168262Sjkh if test "x$with_memory_size" = x; then 1178262Sjkh # The memory size was not specified, try to probe it. 1188837Sjkh BPERF_CHECK_MEMORY_SIZE 1198628Sjkh else 1208097Sjkh MEMORY_SIZE=$with_memory_size 1218097Sjkh fi 1228097Sjkh AC_SUBST(MEMORY_SIZE) 1238097Sjkh]) 124161099Sdelphij 1258097SjkhAC_DEFUN_ONCE([BPERF_SETUP_BUILD_JOBS], 1268097Sjkh[ 1278097Sjkh # Provide a decent default number of parallel jobs for make depending on 1288262Sjkh # number of cores, amount of memory and machine architecture. 1298097Sjkh AC_ARG_WITH(jobs, [AS_HELP_STRING([--with-jobs], 13015416Sjkh [number of parallel jobs to let make run @<:@calculated based on cores and memory@:>@])]) 1318097Sjkh if test "x$with_jobs" = x; then 1328097Sjkh # Number of jobs was not specified, calculate. 1338097Sjkh AC_MSG_CHECKING([for appropriate number of jobs to run in parallel]) 1348097Sjkh # Approximate memory in GB. 1358097Sjkh memory_gb=`expr $MEMORY_SIZE / 1024` 1368262Sjkh # Pick the lowest of memory in gb and number of cores. 13716366Sjkh if test "$memory_gb" -lt "$NUM_CORES"; then 13817375Sjkh JOBS="$memory_gb" 1398262Sjkh else 1408262Sjkh JOBS="$NUM_CORES" 1418837Sjkh # On bigger machines, leave some room for other processes to run 1428628Sjkh if test "$JOBS" -gt "4"; then 1438097Sjkh JOBS=`expr $JOBS '*' 90 / 100` 1448097Sjkh fi 1458097Sjkh fi 1468097Sjkh # Cap number of jobs to 16 147161099Sdelphij if test "$JOBS" -gt "16"; then 1488097Sjkh JOBS=16 1498097Sjkh fi 1508097Sjkh if test "$JOBS" -eq "0"; then 1518262Sjkh JOBS=1 1528097Sjkh fi 15315416Sjkh AC_MSG_RESULT([$JOBS]) 1548097Sjkh else 1558097Sjkh JOBS=$with_jobs 1568097Sjkh fi 1578097Sjkh AC_SUBST(JOBS) 1588097Sjkh]) 1598262Sjkh 16016366SjkhAC_DEFUN([BPERF_SETUP_CCACHE], 16117375Sjkh[ 1628097Sjkh AC_ARG_ENABLE([ccache], 1638097Sjkh [AS_HELP_STRING([--enable-ccache], 1648097Sjkh [enable using ccache to speed up recompilations @<:@disabled@:>@])]) 1658097Sjkh 1668097Sjkh CCACHE= 1678097Sjkh CCACHE_STATUS= 1688262Sjkh AC_MSG_CHECKING([is ccache enabled]) 1698262Sjkh if test "x$enable_ccache" = xyes; then 1708628Sjkh if test "x$TOOLCHAIN_TYPE" = "xgcc" -o "x$TOOLCHAIN_TYPE" = "xclang"; then 1718628Sjkh AC_MSG_RESULT([yes]) 1728097Sjkh OLD_PATH="$PATH" 1738097Sjkh if test "x$TOOLCHAIN_PATH" != x; then 1748097Sjkh PATH=$TOOLCHAIN_PATH:$PATH 1758208Sjkh fi 1768208Sjkh BASIC_REQUIRE_PROGS(CCACHE, ccache) 177161099Sdelphij PATH="$OLD_PATH" 1788208Sjkh CCACHE_VERSION=[`$CCACHE --version | head -n1 | $SED 's/[A-Za-z ]*//'`] 1798208Sjkh CCACHE_STATUS="Active ($CCACHE_VERSION)" 1808208Sjkh else 18154587Sjkh AC_MSG_RESULT([no]) 1828208Sjkh AC_MSG_WARN([ccache is not supported with toolchain type $TOOLCHAIN_TYPE]) 18315416Sjkh fi 1848208Sjkh elif test "x$enable_ccache" = xno; then 1858208Sjkh AC_MSG_RESULT([no, explicitly disabled]) 1868208Sjkh CCACHE_STATUS="Disabled" 1878208Sjkh elif test "x$enable_ccache" = x; then 1888208Sjkh AC_MSG_RESULT([no]) 1898640Sjkh else 1909202Srgrimes AC_MSG_RESULT([unknown]) 1918641Sjkh AC_MSG_ERROR([--enable-ccache does not accept any parameters]) 1928640Sjkh fi 1938556Sjkh AC_SUBST(CCACHE) 19454587Sjkh 1958208Sjkh AC_ARG_WITH([ccache-dir], 1968208Sjkh [AS_HELP_STRING([--with-ccache-dir], 1978302Sjkh [where to store ccache files @<:@~/.ccache@:>@])]) 1988302Sjkh 199161099Sdelphij if test "x$with_ccache_dir" != x; then 2008302Sjkh # When using a non home ccache directory, assume the use is to share ccache files 2018302Sjkh # with other users. Thus change the umask. 2028302Sjkh SET_CCACHE_DIR="CCACHE_DIR=$with_ccache_dir CCACHE_UMASK=002" 2038302Sjkh if test "x$CCACHE" = x; then 20415416Sjkh AC_MSG_WARN([--with-ccache-dir has no meaning when ccache is not enabled]) 2058302Sjkh fi 2068302Sjkh fi 2078302Sjkh 2088302Sjkh if test "x$CCACHE" != x; then 2098302Sjkh BPERF_SETUP_CCACHE_USAGE 2108837Sjkh fi 2118837Sjkh]) 21229628Sjkh 2138302SjkhAC_DEFUN([BPERF_SETUP_CCACHE_USAGE], 2148302Sjkh[ 21583351Sjkh if test "x$CCACHE" != x; then 2168208Sjkh if test "x$USE_PRECOMPILED_HEADER" = "x1"; then 217161099Sdelphij HAS_BAD_CCACHE=[`$ECHO $CCACHE_VERSION | \ 2188208Sjkh $GREP -e '^1.*' -e '^2.*' -e '^3\.0.*' -e '^3\.1\.[0123]$'`] 2198208Sjkh if test "x$HAS_BAD_CCACHE" != "x"; then 2208208Sjkh AC_MSG_ERROR([Precompiled headers requires ccache 3.1.4 or later, found $CCACHE_VERSION]) 2218208Sjkh fi 22254587Sjkh AC_MSG_CHECKING([if C-compiler supports ccache precompiled headers]) 22354587Sjkh CCACHE_PRECOMP_FLAG="-fpch-preprocess" 22415416Sjkh PUSHED_FLAGS="$CXXFLAGS" 2258208Sjkh CXXFLAGS="$CCACHE_PRECOMP_FLAG $CXXFLAGS" 2268208Sjkh AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [CC_KNOWS_CCACHE_TRICK=yes], [CC_KNOWS_CCACHE_TRICK=no]) 2278208Sjkh CXXFLAGS="$PUSHED_FLAGS" 2288208Sjkh if test "x$CC_KNOWS_CCACHE_TRICK" = xyes; then 2298208Sjkh AC_MSG_RESULT([yes]) 2308640Sjkh CFLAGS_CCACHE="$CCACHE_PRECOMP_FLAG" 2319202Srgrimes AC_SUBST(CFLAGS_CCACHE) 2328641Sjkh CCACHE_SLOPPINESS=pch_defines,time_macros 2338640Sjkh else 23480674Sjkh AC_MSG_RESULT([no]) 23583351Sjkh AC_MSG_ERROR([Cannot use ccache with precompiled headers without compiler support for $CCACHE_PRECOMP_FLAG]) 2368281Sjkh fi 23754587Sjkh fi 2388208Sjkh 2398208Sjkh CCACHE="CCACHE_COMPRESS=1 $SET_CCACHE_DIR \ 2408262Sjkh CCACHE_SLOPPINESS=$CCACHE_SLOPPINESS CCACHE_BASEDIR=$TOPDIR $CCACHE" 24183351Sjkh 24270005Sjkh if test "x$SET_CCACHE_DIR" != x; then 243161099Sdelphij mkdir -p $CCACHE_DIR > /dev/null 2>&1 24470005Sjkh chmod a+rwxs $CCACHE_DIR > /dev/null 2>&1 24570005Sjkh fi 24670005Sjkh fi 24770005Sjkh]) 24870005Sjkh 24970005SjkhAC_DEFUN_ONCE([BPERF_SETUP_PRECOMPILED_HEADERS], 25070005Sjkh[ 25170005Sjkh 25270005Sjkh ############################################################################### 25370005Sjkh # 25470005Sjkh # Can the C/C++ compiler use precompiled headers? 25570005Sjkh # 25670005Sjkh AC_ARG_ENABLE([precompiled-headers], [AS_HELP_STRING([--disable-precompiled-headers], 25770005Sjkh [disable using precompiled headers when compiling C++ @<:@enabled@:>@])], 25870005Sjkh [ENABLE_PRECOMPH=${enable_precompiled_headers}], [ENABLE_PRECOMPH=yes]) 25970005Sjkh 26080674Sjkh USE_PRECOMPILED_HEADER=1 26183351Sjkh if test "x$ENABLE_PRECOMPH" = xno; then 26270005Sjkh USE_PRECOMPILED_HEADER=0 26370005Sjkh fi 26470005Sjkh 26570005Sjkh if test "x$ENABLE_PRECOMPH" = xyes; then 26670005Sjkh # Check that the compiler actually supports precomp headers. 2678262Sjkh if test "x$TOOLCHAIN_TYPE" = xgcc; then 2688262Sjkh AC_MSG_CHECKING([that precompiled headers work]) 269161099Sdelphij echo "int alfa();" > conftest.h 2708262Sjkh $CXX -x c++-header conftest.h -o conftest.hpp.gch 2>&AS_MESSAGE_LOG_FD >&AS_MESSAGE_LOG_FD 2718262Sjkh if test ! -f conftest.hpp.gch; then 2728262Sjkh USE_PRECOMPILED_HEADER=0 2738278Sjkh AC_MSG_RESULT([no]) 2748262Sjkh else 27554587Sjkh AC_MSG_RESULT([yes]) 2768262Sjkh fi 27715416Sjkh rm -f conftest.h conftest.hpp.gch 2788262Sjkh fi 2798262Sjkh fi 2808262Sjkh 2818262Sjkh AC_SUBST(USE_PRECOMPILED_HEADER) 2828262Sjkh]) 2838302Sjkh 28420247Sjkh 2858302SjkhAC_DEFUN_ONCE([BPERF_SETUP_SMART_JAVAC], 2868302Sjkh[ 2878640Sjkh AC_ARG_WITH(sjavac-server-java, [AS_HELP_STRING([--with-sjavac-server-java], 2889202Srgrimes [use this java binary for running the sjavac background server @<:@Boot JDK java@:>@])]) 2898641Sjkh 2908640Sjkh if test "x$with_sjavac_server_java" != x; then 2918262Sjkh SJAVAC_SERVER_JAVA="$with_sjavac_server_java" 29254587Sjkh FOUND_VERSION=`$SJAVAC_SERVER_JAVA -version 2>&1 | grep " version \""` 2938262Sjkh if test "x$FOUND_VERSION" = x; then 2948262Sjkh AC_MSG_ERROR([Could not execute server java: $SJAVAC_SERVER_JAVA]) 2958262Sjkh fi 2968262Sjkh else 2978262Sjkh SJAVAC_SERVER_JAVA="$JAVA" 2988262Sjkh fi 2998347Sjkh AC_SUBST(SJAVAC_SERVER_JAVA) 3008347Sjkh 301161099Sdelphij if test "$MEMORY_SIZE" -gt "3000"; then 3028347Sjkh ADD_JVM_ARG_IF_OK([-d64],SJAVAC_SERVER_JAVA_FLAGS,[$SJAVAC_SERVER_JAVA]) 3038347Sjkh if test "$JVM_ARG_OK" = true; then 3048347Sjkh JVM_64BIT=true 3058347Sjkh JVM_ARG_OK=false 3068594Sjkh fi 3078594Sjkh fi 30815416Sjkh 3098347Sjkh MX_VALUE=`expr $MEMORY_SIZE / 2` 3108347Sjkh if test "$JVM_64BIT" = true; then 3118347Sjkh # Set ms lower than mx since more than one instance of the server might 3128347Sjkh # get launched at the same time before they figure out which instance won. 3138347Sjkh MS_VALUE=512 3148347Sjkh if test "$MX_VALUE" -gt "2048"; then 3158705Sjkh MX_VALUE=2048 3168705Sjkh fi 3178705Sjkh else 318161099Sdelphij MS_VALUE=256 3198705Sjkh if test "$MX_VALUE" -gt "1500"; then 3208705Sjkh MX_VALUE=1500 3218705Sjkh fi 32254587Sjkh fi 32354587Sjkh if test "$MX_VALUE" -lt "512"; then 32415416Sjkh MX_VALUE=512 3258705Sjkh fi 3268705Sjkh ADD_JVM_ARG_IF_OK([-Xms${MS_VALUE}M -Xmx${MX_VALUE}M],SJAVAC_SERVER_JAVA_FLAGS,[$SJAVAC_SERVER_JAVA]) 3278705Sjkh AC_SUBST(SJAVAC_SERVER_JAVA_FLAGS) 3288705Sjkh 3298705Sjkh AC_ARG_ENABLE([sjavac], [AS_HELP_STRING([--enable-sjavac], 3308705Sjkh [use sjavac to do fast incremental compiles @<:@disabled@:>@])], 33117404Sjkh [ENABLE_SJAVAC="${enableval}"], [ENABLE_SJAVAC='no']) 33254722Sjkh if test "x$JVM_ARG_OK" = "xfalse"; then 33329628Sjkh AC_MSG_WARN([Could not set -Xms${MS_VALUE}M -Xmx${MX_VALUE}M, disabling sjavac]) 33454587Sjkh ENABLE_SJAVAC=no; 3358705Sjkh fi 33612661Speter AC_MSG_CHECKING([whether to use sjavac]) 33712661Speter AC_MSG_RESULT([$ENABLE_SJAVAC]) 33812661Speter AC_SUBST(ENABLE_SJAVAC) 339161099Sdelphij 34012661Speter if test "x$ENABLE_SJAVAC" = xyes; then 34179304Skris SJAVAC_SERVER_DIR="$OUTPUT_ROOT/javacservers" 34215242Sjkh else 34312661Speter SJAVAC_SERVER_DIR= 34412661Speter fi 34512661Speter AC_SUBST(SJAVAC_SERVER_DIR) 346161099Sdelphij]) 34712661Speter