build-performance.m4 11.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#
# Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.  Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#

AC_DEFUN([BPERF_CHECK_CORES],
[
28 29 30
  AC_MSG_CHECKING([for number of cores])
  NUM_CORES=1
  FOUND_CORES=no
31

32 33 34 35 36 37 38 39 40 41 42 43
  if test -f /proc/cpuinfo; then
    # Looks like a Linux (or cygwin) system
    NUM_CORES=`cat /proc/cpuinfo  | grep -c processor`
    FOUND_CORES=yes
  elif test -x /usr/sbin/psrinfo; then
    # Looks like a Solaris system
    NUM_CORES=`LC_MESSAGES=C /usr/sbin/psrinfo -v | grep -c on-line`
    FOUND_CORES=yes
  elif test -x /usr/sbin/system_profiler; then
    # Looks like a MacOSX system
    NUM_CORES=`/usr/sbin/system_profiler -detailLevel full SPHardwareDataType | grep 'Cores' | awk  '{print [$]5}'`
    FOUND_CORES=yes
K
Merge  
kvn 已提交
44 45 46
  elif test "x$OPENJDK_BUILD_OS" = xaix ; then
    NUM_CORES=`/usr/sbin/prtconf | grep "^Number Of Processors" | awk '{ print [$]4 }'`
    FOUND_CORES=yes
47 48 49 50 51
  elif test -n "$NUMBER_OF_PROCESSORS"; then
    # On windows, look in the env
    NUM_CORES=$NUMBER_OF_PROCESSORS
    FOUND_CORES=yes
  fi
52

53 54 55 56 57 58
  if test "x$FOUND_CORES" = xyes; then
    AC_MSG_RESULT([$NUM_CORES])
  else
    AC_MSG_RESULT([could not detect number of cores, defaulting to 1])
    AC_MSG_WARN([This will disable all parallelism from build!])
  fi
59 60 61 62
])

AC_DEFUN([BPERF_CHECK_MEMORY_SIZE],
[
63 64 65 66
  AC_MSG_CHECKING([for memory size])
  # Default to 1024 MB
  MEMORY_SIZE=1024
  FOUND_MEM=no
67

68 69 70 71 72 73
  if test -f /proc/meminfo; then
    # Looks like a Linux (or cygwin) system
    MEMORY_SIZE=`cat /proc/meminfo | grep MemTotal | awk '{print [$]2}'`
    MEMORY_SIZE=`expr $MEMORY_SIZE / 1024`
    FOUND_MEM=yes
  elif test -x /usr/sbin/prtconf; then
K
Merge  
kvn 已提交
74 75
    # Looks like a Solaris or AIX system
    MEMORY_SIZE=`/usr/sbin/prtconf | grep "^Memory [[Ss]]ize" | awk '{ print [$]3 }'`
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
    FOUND_MEM=yes
  elif test -x /usr/sbin/system_profiler; then
    # Looks like a MacOSX system
    MEMORY_SIZE=`/usr/sbin/system_profiler -detailLevel full SPHardwareDataType | grep 'Memory' | awk  '{print [$]2}'`
    MEMORY_SIZE=`expr $MEMORY_SIZE \* 1024`
    FOUND_MEM=yes
  elif test "x$OPENJDK_BUILD_OS" = xwindows; then
    # Windows, but without cygwin
    MEMORY_SIZE=`wmic computersystem get totalphysicalmemory -value | grep = | cut -d "=" -f 2-`
    MEMORY_SIZE=`expr $MEMORY_SIZE / 1024 / 1024`
    FOUND_MEM=yes
  fi

  if test "x$FOUND_MEM" = xyes; then
    AC_MSG_RESULT([$MEMORY_SIZE MB])
  else
    AC_MSG_RESULT([could not detect memory size, defaulting to 1024 MB])
    AC_MSG_WARN([This might seriously impact build performance!])
  fi
95 96 97 98
])

AC_DEFUN_ONCE([BPERF_SETUP_BUILD_CORES],
[
99 100
  # How many cores do we have on this build system?
  AC_ARG_WITH(num-cores, [AS_HELP_STRING([--with-num-cores],
101
      [number of cores in the build system, e.g. --with-num-cores=8 @<:@probed@:>@])])
102
  if test "x$with_num_cores" = x; then
103 104
    # The number of cores were not specified, try to probe them.
    BPERF_CHECK_CORES
105
  else
106
    NUM_CORES=$with_num_cores
107 108
  fi
  AC_SUBST(NUM_CORES)
109 110 111 112
])

AC_DEFUN_ONCE([BPERF_SETUP_BUILD_MEMORY],
[
113 114
  # How much memory do we have on this build system?
  AC_ARG_WITH(memory-size, [AS_HELP_STRING([--with-memory-size],
115
      [memory (in MB) available in the build system, e.g. --with-memory-size=1024 @<:@probed@:>@])])
116
  if test "x$with_memory_size" = x; then
117 118
    # The memory size was not specified, try to probe it.
    BPERF_CHECK_MEMORY_SIZE
119
  else
120
    MEMORY_SIZE=$with_memory_size
121 122 123 124 125 126
  fi
  AC_SUBST(MEMORY_SIZE)
])

AC_DEFUN_ONCE([BPERF_SETUP_BUILD_JOBS],
[
127
  # Provide a decent default number of parallel jobs for make depending on
128 129
  # number of cores, amount of memory and machine architecture.
  AC_ARG_WITH(jobs, [AS_HELP_STRING([--with-jobs],
130
      [number of parallel jobs to let make run @<:@calculated based on cores and memory@:>@])])
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
  if test "x$with_jobs" = x; then
    # Number of jobs was not specified, calculate.
    AC_MSG_CHECKING([for appropriate number of jobs to run in parallel])
    # Approximate memory in GB, rounding up a bit.
    memory_gb=`expr $MEMORY_SIZE / 1100`
    # Pick the lowest of memory in gb and number of cores.
    if test "$memory_gb" -lt "$NUM_CORES"; then
      JOBS="$memory_gb"
    else
      JOBS="$NUM_CORES"
      # On bigger machines, leave some room for other processes to run
      if test "$JOBS" -gt "4"; then
        JOBS=`expr $JOBS '*' 90 / 100`
      fi
    fi
    # Cap number of jobs to 16
    if test "$JOBS" -gt "16"; then
      JOBS=16
    fi
150 151 152
    if test "$JOBS" -eq "0"; then
      JOBS=1
    fi
153 154 155 156 157
    AC_MSG_RESULT([$JOBS])
  else
    JOBS=$with_jobs
  fi
  AC_SUBST(JOBS)
158 159 160 161
])

AC_DEFUN([BPERF_SETUP_CCACHE],
[
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
  AC_ARG_ENABLE([ccache],
      [AS_HELP_STRING([--disable-ccache],
      [disable using ccache to speed up recompilations @<:@enabled@:>@])],
      [ENABLE_CCACHE=${enable_ccache}], [ENABLE_CCACHE=yes])
  if test "x$ENABLE_CCACHE" = xyes; then
    OLD_PATH="$PATH"
    if test "x$TOOLS_DIR" != x; then
      PATH=$TOOLS_DIR:$PATH
    fi
    AC_PATH_PROG(CCACHE, ccache)
    PATH="$OLD_PATH"
  else
    AC_MSG_CHECKING([for ccache])
    AC_MSG_RESULT([explicitly disabled])
    CCACHE=
  fi
  AC_SUBST(CCACHE)
179

180 181 182
  AC_ARG_WITH([ccache-dir],
      [AS_HELP_STRING([--with-ccache-dir],
      [where to store ccache files @<:@~/.ccache@:>@])])
183

184 185 186 187 188 189 190 191 192
  if test "x$with_ccache_dir" != x; then
    # When using a non home ccache directory, assume the use is to share ccache files
    # with other users. Thus change the umask.
    SET_CCACHE_DIR="CCACHE_DIR=$with_ccache_dir CCACHE_UMASK=002"
  fi
  CCACHE_FOUND=""
  if test "x$CCACHE" != x; then
    BPERF_SETUP_CCACHE_USAGE
  fi
193 194 195 196
])

AC_DEFUN([BPERF_SETUP_CCACHE_USAGE],
[
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
  if test "x$CCACHE" != x; then
    CCACHE_FOUND="true"
    # Only use ccache if it is 3.1.4 or later, which supports
    # precompiled headers.
    AC_MSG_CHECKING([if ccache supports precompiled headers])
    HAS_GOOD_CCACHE=`($CCACHE --version | head -n 1 | grep -E 3.1.@<:@456789@:>@) 2> /dev/null`
    if test "x$HAS_GOOD_CCACHE" = x; then
      AC_MSG_RESULT([no, disabling ccache])
      CCACHE=
    else
      AC_MSG_RESULT([yes])
      AC_MSG_CHECKING([if C-compiler supports ccache precompiled headers])
      PUSHED_FLAGS="$CXXFLAGS"
      CXXFLAGS="-fpch-preprocess $CXXFLAGS"
      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [CC_KNOWS_CCACHE_TRICK=yes], [CC_KNOWS_CCACHE_TRICK=no])
      CXXFLAGS="$PUSHED_FLAGS"
      if test "x$CC_KNOWS_CCACHE_TRICK" = xyes; then
        AC_MSG_RESULT([yes])
      else
        AC_MSG_RESULT([no, disabling ccaching of precompiled headers])
        CCACHE=
      fi
219
    fi
220
  fi
221

222 223 224 225
  if test "x$CCACHE" != x; then
    CCACHE_SLOPPINESS=time_macros
    CCACHE="CCACHE_COMPRESS=1 $SET_CCACHE_DIR CCACHE_SLOPPINESS=$CCACHE_SLOPPINESS $CCACHE"
    CCACHE_FLAGS=-fpch-preprocess
226

227 228 229
    if test "x$SET_CCACHE_DIR" != x; then
      mkdir -p $CCACHE_DIR > /dev/null 2>&1
      chmod a+rwxs $CCACHE_DIR > /dev/null 2>&1
230
    fi
231
  fi
232 233 234 235 236
])

AC_DEFUN_ONCE([BPERF_SETUP_PRECOMPILED_HEADERS],
[

237 238 239 240 241 242 243 244 245 246
  ###############################################################################
  #
  # Can the C/C++ compiler use precompiled headers?
  #
  AC_ARG_ENABLE([precompiled-headers], [AS_HELP_STRING([--disable-precompiled-headers],
      [disable using precompiled headers when compiling C++ @<:@enabled@:>@])],
      [ENABLE_PRECOMPH=${enable_precompiled_headers}], [ENABLE_PRECOMPH=yes])

  USE_PRECOMPILED_HEADER=1
  if test "x$ENABLE_PRECOMPH" = xno; then
247
    USE_PRECOMPILED_HEADER=0
248
  fi
249

250
  if test "x$ENABLE_PRECOMPH" = xyes; then
251 252
    # Check that the compiler actually supports precomp headers.
    if test "x$GCC" = xyes; then
253 254 255 256 257 258 259 260 261 262
      AC_MSG_CHECKING([that precompiled headers work])
      echo "int alfa();" > conftest.h
      $CXX -x c++-header conftest.h -o conftest.hpp.gch 2>&AS_MESSAGE_LOG_FD >&AS_MESSAGE_LOG_FD
      if test ! -f conftest.hpp.gch; then
        USE_PRECOMPILED_HEADER=0
        AC_MSG_RESULT([no])
      else
        AC_MSG_RESULT([yes])
      fi
      rm -f conftest.h conftest.hpp.gch
263
    fi
264
  fi
265

266
  AC_SUBST(USE_PRECOMPILED_HEADER)
267 268 269 270 271
])


AC_DEFUN_ONCE([BPERF_SETUP_SMART_JAVAC],
[
272 273
  AC_ARG_WITH(sjavac-server-java, [AS_HELP_STRING([--with-sjavac-server-java],
      [use this java binary for running the sjavac background server @<:@Boot JDK java@:>@])])
274

275
  if test "x$with_sjavac_server_java" != x; then
276 277
    SJAVAC_SERVER_JAVA="$with_sjavac_server_java"
    FOUND_VERSION=`$SJAVAC_SERVER_JAVA -version 2>&1 | grep " version \""`
278
    if test "x$FOUND_VERSION" = x; then
279
      AC_MSG_ERROR([Could not execute server java: $SJAVAC_SERVER_JAVA])
280
    fi
281
  else
282
    SJAVAC_SERVER_JAVA=""
283
    # Hotspot specific options.
284
    ADD_JVM_ARG_IF_OK([-verbosegc],SJAVAC_SERVER_JAVA,[$JAVA])
285
    # JRockit specific options.
286 287
    ADD_JVM_ARG_IF_OK([-Xverbose:gc],SJAVAC_SERVER_JAVA,[$JAVA])
    SJAVAC_SERVER_JAVA="$JAVA $SJAVAC_SERVER_JAVA"
288 289
  fi
  AC_SUBST(SJAVAC_SERVER_JAVA)
290

291
  if test "$MEMORY_SIZE" -gt "2500"; then
E
erikj 已提交
292 293
    ADD_JVM_ARG_IF_OK([-d64],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
    if test "$JVM_ARG_OK" = true; then
294 295
      JVM_64BIT=true
      JVM_ARG_OK=false
296
    fi
297
  fi
298

299
  if test "$JVM_64BIT" = true; then
300
    if test "$MEMORY_SIZE" -gt "17000"; then
301
      ADD_JVM_ARG_IF_OK([-Xms10G -Xmx10G],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
E
erikj 已提交
302 303
    fi
    if test "$MEMORY_SIZE" -gt "10000" && test "$JVM_ARG_OK" = false; then
304
      ADD_JVM_ARG_IF_OK([-Xms6G -Xmx6G],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
E
erikj 已提交
305 306
    fi
    if test "$MEMORY_SIZE" -gt "5000" && test "$JVM_ARG_OK" = false; then
307
      ADD_JVM_ARG_IF_OK([-Xms1G -Xmx3G],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
308
    fi
E
erikj 已提交
309
    if test "$MEMORY_SIZE" -gt "3800" && test "$JVM_ARG_OK" = false; then
310
      ADD_JVM_ARG_IF_OK([-Xms1G -Xmx2500M],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
311
    fi
312 313
  fi
  if test "$MEMORY_SIZE" -gt "2500" && test "$JVM_ARG_OK" = false; then
E
erikj 已提交
314
    ADD_JVM_ARG_IF_OK([-Xms1000M -Xmx1500M],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
315 316
  fi
  if test "$MEMORY_SIZE" -gt "1000" && test "$JVM_ARG_OK" = false; then
E
erikj 已提交
317
    ADD_JVM_ARG_IF_OK([-Xms400M -Xmx1100M],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
318 319
  fi
  if test "$JVM_ARG_OK" = false; then
E
erikj 已提交
320
    ADD_JVM_ARG_IF_OK([-Xms256M -Xmx512M],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
321
  fi
322

323 324 325 326 327 328
  AC_MSG_CHECKING([whether to use sjavac])
  AC_ARG_ENABLE([sjavac], [AS_HELP_STRING([--enable-sjavac],
      [use sjavac to do fast incremental compiles @<:@disabled@:>@])],
      [ENABLE_SJAVAC="${enableval}"], [ENABLE_SJAVAC='no'])
  AC_MSG_RESULT([$ENABLE_SJAVAC])
  AC_SUBST(ENABLE_SJAVAC)
329

330
  if test "x$ENABLE_SJAVAC" = xyes; then
331
    SJAVAC_SERVER_DIR="$OUTPUT_ROOT/javacservers"
332
  else
333
    SJAVAC_SERVER_DIR=
334 335
  fi
  AC_SUBST(SJAVAC_SERVER_DIR)
336
])