common/autoconf/build-performance.m4

Thu, 31 Aug 2017 15:40:18 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:40:18 +0800
changeset 1133
50aaf272884f
parent 972
f3697e0783e2
parent 0
75a576e87639
child 2316
64a3eeabf6e5
permissions
-rw-r--r--

merge

aoqi@0 1 #
aoqi@0 2 # Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 #
aoqi@0 5 # This code is free software; you can redistribute it and/or modify it
aoqi@0 6 # under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 # published by the Free Software Foundation. Oracle designates this
aoqi@0 8 # particular file as subject to the "Classpath" exception as provided
aoqi@0 9 # by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 #
aoqi@0 11 # This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 # version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 # accompanied this code).
aoqi@0 16 #
aoqi@0 17 # You should have received a copy of the GNU General Public License version
aoqi@0 18 # 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 #
aoqi@0 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 # or visit www.oracle.com if you need additional information or have any
aoqi@0 23 # questions.
aoqi@0 24 #
aoqi@0 25
aoqi@0 26 AC_DEFUN([BPERF_CHECK_CORES],
aoqi@0 27 [
aoqi@0 28 AC_MSG_CHECKING([for number of cores])
aoqi@0 29 NUM_CORES=1
aoqi@0 30 FOUND_CORES=no
aoqi@0 31
aoqi@0 32 if test -f /proc/cpuinfo; then
aoqi@0 33 # Looks like a Linux (or cygwin) system
aoqi@0 34 NUM_CORES=`cat /proc/cpuinfo | grep -c processor`
aoqi@0 35 FOUND_CORES=yes
aoqi@0 36 elif test -x /usr/sbin/psrinfo; then
aoqi@0 37 # Looks like a Solaris system
aoqi@0 38 NUM_CORES=`LC_MESSAGES=C /usr/sbin/psrinfo -v | grep -c on-line`
aoqi@0 39 FOUND_CORES=yes
aoqi@0 40 elif test -x /usr/sbin/system_profiler; then
aoqi@0 41 # Looks like a MacOSX system
aoqi@0 42 NUM_CORES=`/usr/sbin/system_profiler -detailLevel full SPHardwareDataType | grep 'Cores' | awk '{print [$]5}'`
aoqi@0 43 FOUND_CORES=yes
aoqi@0 44 elif test "x$OPENJDK_BUILD_OS" = xaix ; then
aoqi@0 45 NUM_CORES=`/usr/sbin/prtconf | grep "^Number Of Processors" | awk '{ print [$]4 }'`
aoqi@0 46 FOUND_CORES=yes
aoqi@0 47 elif test -n "$NUMBER_OF_PROCESSORS"; then
aoqi@0 48 # On windows, look in the env
aoqi@0 49 NUM_CORES=$NUMBER_OF_PROCESSORS
aoqi@0 50 FOUND_CORES=yes
aoqi@0 51 fi
aoqi@0 52
aoqi@0 53 if test "x$FOUND_CORES" = xyes; then
aoqi@0 54 AC_MSG_RESULT([$NUM_CORES])
aoqi@0 55 else
aoqi@0 56 AC_MSG_RESULT([could not detect number of cores, defaulting to 1])
aoqi@0 57 AC_MSG_WARN([This will disable all parallelism from build!])
aoqi@0 58 fi
aoqi@0 59 ])
aoqi@0 60
aoqi@0 61 AC_DEFUN([BPERF_CHECK_MEMORY_SIZE],
aoqi@0 62 [
aoqi@0 63 AC_MSG_CHECKING([for memory size])
aoqi@0 64 # Default to 1024 MB
aoqi@0 65 MEMORY_SIZE=1024
aoqi@0 66 FOUND_MEM=no
aoqi@0 67
aoqi@0 68 if test -f /proc/meminfo; then
aoqi@0 69 # Looks like a Linux (or cygwin) system
aoqi@0 70 MEMORY_SIZE=`cat /proc/meminfo | grep MemTotal | awk '{print [$]2}'`
aoqi@0 71 MEMORY_SIZE=`expr $MEMORY_SIZE / 1024`
aoqi@0 72 FOUND_MEM=yes
aoqi@0 73 elif test -x /usr/sbin/prtconf; then
aoqi@0 74 # Looks like a Solaris or AIX system
aoqi@0 75 MEMORY_SIZE=`/usr/sbin/prtconf | grep "^Memory [[Ss]]ize" | awk '{ print [$]3 }'`
aoqi@0 76 FOUND_MEM=yes
aoqi@0 77 elif test -x /usr/sbin/system_profiler; then
aoqi@0 78 # Looks like a MacOSX system
aoqi@0 79 MEMORY_SIZE=`/usr/sbin/system_profiler -detailLevel full SPHardwareDataType | grep 'Memory' | awk '{print [$]2}'`
aoqi@0 80 MEMORY_SIZE=`expr $MEMORY_SIZE \* 1024`
aoqi@0 81 FOUND_MEM=yes
aoqi@0 82 elif test "x$OPENJDK_BUILD_OS" = xwindows; then
aoqi@0 83 # Windows, but without cygwin
aoqi@0 84 MEMORY_SIZE=`wmic computersystem get totalphysicalmemory -value | grep = | cut -d "=" -f 2-`
aoqi@0 85 MEMORY_SIZE=`expr $MEMORY_SIZE / 1024 / 1024`
aoqi@0 86 FOUND_MEM=yes
aoqi@0 87 fi
aoqi@0 88
aoqi@0 89 if test "x$FOUND_MEM" = xyes; then
aoqi@0 90 AC_MSG_RESULT([$MEMORY_SIZE MB])
aoqi@0 91 else
aoqi@0 92 AC_MSG_RESULT([could not detect memory size, defaulting to 1024 MB])
aoqi@0 93 AC_MSG_WARN([This might seriously impact build performance!])
aoqi@0 94 fi
aoqi@0 95 ])
aoqi@0 96
aoqi@0 97 AC_DEFUN_ONCE([BPERF_SETUP_BUILD_CORES],
aoqi@0 98 [
aoqi@0 99 # How many cores do we have on this build system?
aoqi@0 100 AC_ARG_WITH(num-cores, [AS_HELP_STRING([--with-num-cores],
aoqi@0 101 [number of cores in the build system, e.g. --with-num-cores=8 @<:@probed@:>@])])
aoqi@0 102 if test "x$with_num_cores" = x; then
aoqi@0 103 # The number of cores were not specified, try to probe them.
aoqi@0 104 BPERF_CHECK_CORES
aoqi@0 105 else
aoqi@0 106 NUM_CORES=$with_num_cores
aoqi@0 107 fi
aoqi@0 108 AC_SUBST(NUM_CORES)
aoqi@0 109 ])
aoqi@0 110
aoqi@0 111 AC_DEFUN_ONCE([BPERF_SETUP_BUILD_MEMORY],
aoqi@0 112 [
aoqi@0 113 # How much memory do we have on this build system?
aoqi@0 114 AC_ARG_WITH(memory-size, [AS_HELP_STRING([--with-memory-size],
aoqi@0 115 [memory (in MB) available in the build system, e.g. --with-memory-size=1024 @<:@probed@:>@])])
aoqi@0 116 if test "x$with_memory_size" = x; then
aoqi@0 117 # The memory size was not specified, try to probe it.
aoqi@0 118 BPERF_CHECK_MEMORY_SIZE
aoqi@0 119 else
aoqi@0 120 MEMORY_SIZE=$with_memory_size
aoqi@0 121 fi
aoqi@0 122 AC_SUBST(MEMORY_SIZE)
aoqi@0 123 ])
aoqi@0 124
aoqi@0 125 AC_DEFUN_ONCE([BPERF_SETUP_BUILD_JOBS],
aoqi@0 126 [
aoqi@0 127 # Provide a decent default number of parallel jobs for make depending on
aoqi@0 128 # number of cores, amount of memory and machine architecture.
aoqi@0 129 AC_ARG_WITH(jobs, [AS_HELP_STRING([--with-jobs],
aoqi@0 130 [number of parallel jobs to let make run @<:@calculated based on cores and memory@:>@])])
aoqi@0 131 if test "x$with_jobs" = x; then
aoqi@0 132 # Number of jobs was not specified, calculate.
aoqi@0 133 AC_MSG_CHECKING([for appropriate number of jobs to run in parallel])
aoqi@0 134 # Approximate memory in GB, rounding up a bit.
aoqi@0 135 memory_gb=`expr $MEMORY_SIZE / 1100`
aoqi@0 136 # Pick the lowest of memory in gb and number of cores.
aoqi@0 137 if test "$memory_gb" -lt "$NUM_CORES"; then
aoqi@0 138 JOBS="$memory_gb"
aoqi@0 139 else
aoqi@0 140 JOBS="$NUM_CORES"
aoqi@0 141 # On bigger machines, leave some room for other processes to run
aoqi@0 142 if test "$JOBS" -gt "4"; then
aoqi@0 143 JOBS=`expr $JOBS '*' 90 / 100`
aoqi@0 144 fi
aoqi@0 145 fi
aoqi@0 146 # Cap number of jobs to 16
aoqi@0 147 if test "$JOBS" -gt "16"; then
aoqi@0 148 JOBS=16
aoqi@0 149 fi
aoqi@0 150 if test "$JOBS" -eq "0"; then
aoqi@0 151 JOBS=1
aoqi@0 152 fi
aoqi@0 153 AC_MSG_RESULT([$JOBS])
aoqi@0 154 else
aoqi@0 155 JOBS=$with_jobs
aoqi@0 156 fi
aoqi@0 157 AC_SUBST(JOBS)
aoqi@0 158 ])
aoqi@0 159
aoqi@0 160 AC_DEFUN([BPERF_SETUP_CCACHE],
aoqi@0 161 [
aoqi@0 162 AC_ARG_ENABLE([ccache],
aoqi@0 163 [AS_HELP_STRING([--disable-ccache],
aoqi@0 164 [disable using ccache to speed up recompilations @<:@enabled@:>@])],
aoqi@0 165 [ENABLE_CCACHE=${enable_ccache}], [ENABLE_CCACHE=yes])
aoqi@0 166 if test "x$ENABLE_CCACHE" = xyes; then
aoqi@0 167 OLD_PATH="$PATH"
aoqi@0 168 if test "x$TOOLS_DIR" != x; then
aoqi@0 169 PATH=$TOOLS_DIR:$PATH
aoqi@0 170 fi
aoqi@0 171 AC_PATH_PROG(CCACHE, ccache)
aoqi@0 172 PATH="$OLD_PATH"
aoqi@0 173 else
aoqi@0 174 AC_MSG_CHECKING([for ccache])
aoqi@0 175 AC_MSG_RESULT([explicitly disabled])
aoqi@0 176 CCACHE=
aoqi@0 177 fi
aoqi@0 178 AC_SUBST(CCACHE)
aoqi@0 179
aoqi@0 180 AC_ARG_WITH([ccache-dir],
aoqi@0 181 [AS_HELP_STRING([--with-ccache-dir],
aoqi@0 182 [where to store ccache files @<:@~/.ccache@:>@])])
aoqi@0 183
aoqi@0 184 if test "x$with_ccache_dir" != x; then
aoqi@0 185 # When using a non home ccache directory, assume the use is to share ccache files
aoqi@0 186 # with other users. Thus change the umask.
aoqi@0 187 SET_CCACHE_DIR="CCACHE_DIR=$with_ccache_dir CCACHE_UMASK=002"
aoqi@0 188 fi
aoqi@0 189 CCACHE_FOUND=""
aoqi@0 190 if test "x$CCACHE" != x; then
aoqi@0 191 BPERF_SETUP_CCACHE_USAGE
aoqi@0 192 fi
aoqi@0 193 ])
aoqi@0 194
aoqi@0 195 AC_DEFUN([BPERF_SETUP_CCACHE_USAGE],
aoqi@0 196 [
aoqi@0 197 if test "x$CCACHE" != x; then
aoqi@0 198 CCACHE_FOUND="true"
aoqi@0 199 # Only use ccache if it is 3.1.4 or later, which supports
aoqi@0 200 # precompiled headers.
aoqi@0 201 AC_MSG_CHECKING([if ccache supports precompiled headers])
aoqi@0 202 HAS_GOOD_CCACHE=`($CCACHE --version | head -n 1 | grep -E 3.1.@<:@456789@:>@) 2> /dev/null`
aoqi@0 203 if test "x$HAS_GOOD_CCACHE" = x; then
aoqi@0 204 AC_MSG_RESULT([no, disabling ccache])
aoqi@0 205 CCACHE=
aoqi@0 206 else
aoqi@0 207 AC_MSG_RESULT([yes])
aoqi@0 208 AC_MSG_CHECKING([if C-compiler supports ccache precompiled headers])
aoqi@0 209 PUSHED_FLAGS="$CXXFLAGS"
aoqi@0 210 CXXFLAGS="-fpch-preprocess $CXXFLAGS"
aoqi@0 211 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [CC_KNOWS_CCACHE_TRICK=yes], [CC_KNOWS_CCACHE_TRICK=no])
aoqi@0 212 CXXFLAGS="$PUSHED_FLAGS"
aoqi@0 213 if test "x$CC_KNOWS_CCACHE_TRICK" = xyes; then
aoqi@0 214 AC_MSG_RESULT([yes])
aoqi@0 215 else
aoqi@0 216 AC_MSG_RESULT([no, disabling ccaching of precompiled headers])
aoqi@0 217 CCACHE=
aoqi@0 218 fi
aoqi@0 219 fi
aoqi@0 220 fi
aoqi@0 221
aoqi@0 222 if test "x$CCACHE" != x; then
aoqi@0 223 CCACHE_SLOPPINESS=time_macros
aoqi@0 224 CCACHE="CCACHE_COMPRESS=1 $SET_CCACHE_DIR CCACHE_SLOPPINESS=$CCACHE_SLOPPINESS $CCACHE"
aoqi@0 225 CCACHE_FLAGS=-fpch-preprocess
aoqi@0 226
aoqi@0 227 if test "x$SET_CCACHE_DIR" != x; then
aoqi@0 228 mkdir -p $CCACHE_DIR > /dev/null 2>&1
aoqi@0 229 chmod a+rwxs $CCACHE_DIR > /dev/null 2>&1
aoqi@0 230 fi
aoqi@0 231 fi
aoqi@0 232 ])
aoqi@0 233
aoqi@0 234 AC_DEFUN_ONCE([BPERF_SETUP_PRECOMPILED_HEADERS],
aoqi@0 235 [
aoqi@0 236
aoqi@0 237 ###############################################################################
aoqi@0 238 #
aoqi@0 239 # Can the C/C++ compiler use precompiled headers?
aoqi@0 240 #
aoqi@0 241 AC_ARG_ENABLE([precompiled-headers], [AS_HELP_STRING([--disable-precompiled-headers],
aoqi@0 242 [disable using precompiled headers when compiling C++ @<:@enabled@:>@])],
aoqi@0 243 [ENABLE_PRECOMPH=${enable_precompiled_headers}], [ENABLE_PRECOMPH=yes])
aoqi@0 244
aoqi@0 245 USE_PRECOMPILED_HEADER=1
aoqi@0 246 if test "x$ENABLE_PRECOMPH" = xno; then
aoqi@0 247 USE_PRECOMPILED_HEADER=0
aoqi@0 248 fi
aoqi@0 249
aoqi@0 250 if test "x$ENABLE_PRECOMPH" = xyes; then
aoqi@0 251 # Check that the compiler actually supports precomp headers.
aoqi@0 252 if test "x$GCC" = xyes; then
aoqi@0 253 AC_MSG_CHECKING([that precompiled headers work])
aoqi@0 254 echo "int alfa();" > conftest.h
aoqi@0 255 $CXX -x c++-header conftest.h -o conftest.hpp.gch 2>&AS_MESSAGE_LOG_FD >&AS_MESSAGE_LOG_FD
aoqi@0 256 if test ! -f conftest.hpp.gch; then
aoqi@0 257 USE_PRECOMPILED_HEADER=0
aoqi@0 258 AC_MSG_RESULT([no])
aoqi@0 259 else
aoqi@0 260 AC_MSG_RESULT([yes])
aoqi@0 261 fi
aoqi@0 262 rm -f conftest.h conftest.hpp.gch
aoqi@0 263 fi
aoqi@0 264 fi
aoqi@0 265
aoqi@0 266 AC_SUBST(USE_PRECOMPILED_HEADER)
aoqi@0 267 ])
aoqi@0 268
aoqi@0 269
aoqi@0 270 AC_DEFUN_ONCE([BPERF_SETUP_SMART_JAVAC],
aoqi@0 271 [
aoqi@0 272 AC_ARG_WITH(sjavac-server-java, [AS_HELP_STRING([--with-sjavac-server-java],
aoqi@0 273 [use this java binary for running the sjavac background server @<:@Boot JDK java@:>@])])
aoqi@0 274
aoqi@0 275 if test "x$with_sjavac_server_java" != x; then
aoqi@0 276 SJAVAC_SERVER_JAVA="$with_sjavac_server_java"
aoqi@0 277 FOUND_VERSION=`$SJAVAC_SERVER_JAVA -version 2>&1 | grep " version \""`
aoqi@0 278 if test "x$FOUND_VERSION" = x; then
aoqi@0 279 AC_MSG_ERROR([Could not execute server java: $SJAVAC_SERVER_JAVA])
aoqi@0 280 fi
aoqi@0 281 else
aoqi@0 282 SJAVAC_SERVER_JAVA=""
aoqi@0 283 # Hotspot specific options.
aoqi@0 284 ADD_JVM_ARG_IF_OK([-verbosegc],SJAVAC_SERVER_JAVA,[$JAVA])
aoqi@0 285 # JRockit specific options.
aoqi@0 286 ADD_JVM_ARG_IF_OK([-Xverbose:gc],SJAVAC_SERVER_JAVA,[$JAVA])
aoqi@0 287 SJAVAC_SERVER_JAVA="$JAVA $SJAVAC_SERVER_JAVA"
aoqi@0 288 fi
aoqi@0 289 AC_SUBST(SJAVAC_SERVER_JAVA)
aoqi@0 290
aoqi@0 291 if test "$MEMORY_SIZE" -gt "2500"; then
aoqi@0 292 ADD_JVM_ARG_IF_OK([-d64],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
aoqi@0 293 if test "$JVM_ARG_OK" = true; then
aoqi@0 294 JVM_64BIT=true
aoqi@0 295 JVM_ARG_OK=false
aoqi@0 296 fi
aoqi@0 297 fi
aoqi@0 298
aoqi@0 299 if test "$JVM_64BIT" = true; then
aoqi@0 300 if test "$MEMORY_SIZE" -gt "17000"; then
aoqi@0 301 ADD_JVM_ARG_IF_OK([-Xms10G -Xmx10G],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
aoqi@0 302 fi
aoqi@0 303 if test "$MEMORY_SIZE" -gt "10000" && test "$JVM_ARG_OK" = false; then
aoqi@0 304 ADD_JVM_ARG_IF_OK([-Xms6G -Xmx6G],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
aoqi@0 305 fi
aoqi@0 306 if test "$MEMORY_SIZE" -gt "5000" && test "$JVM_ARG_OK" = false; then
aoqi@0 307 ADD_JVM_ARG_IF_OK([-Xms1G -Xmx3G],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
aoqi@0 308 fi
aoqi@0 309 if test "$MEMORY_SIZE" -gt "3800" && test "$JVM_ARG_OK" = false; then
aoqi@0 310 ADD_JVM_ARG_IF_OK([-Xms1G -Xmx2500M],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
aoqi@0 311 fi
aoqi@0 312 fi
aoqi@0 313 if test "$MEMORY_SIZE" -gt "2500" && test "$JVM_ARG_OK" = false; then
aoqi@0 314 ADD_JVM_ARG_IF_OK([-Xms1000M -Xmx1500M],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
aoqi@0 315 fi
aoqi@0 316 if test "$MEMORY_SIZE" -gt "1000" && test "$JVM_ARG_OK" = false; then
aoqi@0 317 ADD_JVM_ARG_IF_OK([-Xms400M -Xmx1100M],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
aoqi@0 318 fi
aoqi@0 319 if test "$JVM_ARG_OK" = false; then
aoqi@0 320 ADD_JVM_ARG_IF_OK([-Xms256M -Xmx512M],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
aoqi@0 321 fi
aoqi@0 322
aoqi@0 323 AC_MSG_CHECKING([whether to use sjavac])
aoqi@0 324 AC_ARG_ENABLE([sjavac], [AS_HELP_STRING([--enable-sjavac],
aoqi@0 325 [use sjavac to do fast incremental compiles @<:@disabled@:>@])],
aoqi@0 326 [ENABLE_SJAVAC="${enableval}"], [ENABLE_SJAVAC='no'])
aoqi@0 327 AC_MSG_RESULT([$ENABLE_SJAVAC])
aoqi@0 328 AC_SUBST(ENABLE_SJAVAC)
aoqi@0 329
aoqi@0 330 if test "x$ENABLE_SJAVAC" = xyes; then
aoqi@0 331 SJAVAC_SERVER_DIR="$OUTPUT_ROOT/javacservers"
aoqi@0 332 else
aoqi@0 333 SJAVAC_SERVER_DIR=
aoqi@0 334 fi
aoqi@0 335 AC_SUBST(SJAVAC_SERVER_DIR)
aoqi@0 336 ])

mercurial