build-performance.m4 revision 715:e247ee3924d5
1219820Sjeff#
2219820Sjeff# Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
3219820Sjeff# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4219820Sjeff#
5219820Sjeff# This code is free software; you can redistribute it and/or modify it
6219820Sjeff# under the terms of the GNU General Public License version 2 only, as
7219820Sjeff# published by the Free Software Foundation.  Oracle designates this
8219820Sjeff# particular file as subject to the "Classpath" exception as provided
9219820Sjeff# by Oracle in the LICENSE file that accompanied this code.
10219820Sjeff#
11219820Sjeff# This code is distributed in the hope that it will be useful, but WITHOUT
12219820Sjeff# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13219820Sjeff# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14219820Sjeff# version 2 for more details (a copy is included in the LICENSE file that
15219820Sjeff# accompanied this code).
16219820Sjeff#
17219820Sjeff# You should have received a copy of the GNU General Public License version
18219820Sjeff# 2 along with this work; if not, write to the Free Software Foundation,
19219820Sjeff# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20219820Sjeff#
21219820Sjeff# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22219820Sjeff# or visit www.oracle.com if you need additional information or have any
23219820Sjeff# questions.
24219820Sjeff#
25219820Sjeff
26219820SjeffAC_DEFUN([BPERF_CHECK_CORES],
27219820Sjeff[
28219820Sjeff    AC_MSG_CHECKING([for number of cores])
29219820Sjeff    NUM_CORES=1
30219820Sjeff    FOUND_CORES=no
31219820Sjeff    
32219820Sjeff    if test -f /proc/cpuinfo; then
33219820Sjeff        # Looks like a Linux (or cygwin) system
34219820Sjeff        NUM_CORES=`cat /proc/cpuinfo  | grep -c processor`
35219820Sjeff        FOUND_CORES=yes
36219820Sjeff    elif test -x /usr/sbin/psrinfo; then
37219820Sjeff        # Looks like a Solaris system
38219820Sjeff        NUM_CORES=`LC_MESSAGES=C /usr/sbin/psrinfo -v | grep -c on-line`
39219820Sjeff        FOUND_CORES=yes
40219820Sjeff    elif test -x /usr/sbin/system_profiler; then
41222813Sattilio        # Looks like a MacOSX system
42219820Sjeff        NUM_CORES=`/usr/sbin/system_profiler -detailLevel full SPHardwareDataType | grep 'Cores' | awk  '{print [$]5}'`
43219820Sjeff        FOUND_CORES=yes
44219820Sjeff    elif test -n "$NUMBER_OF_PROCESSORS"; then
45219820Sjeff        # On windows, look in the env
46219820Sjeff        NUM_CORES=$NUMBER_OF_PROCESSORS
47219820Sjeff        FOUND_CORES=yes
48219820Sjeff    fi
49219820Sjeff
50219820Sjeff    if test "x$FOUND_CORES" = xyes; then
51219820Sjeff        AC_MSG_RESULT([$NUM_CORES])
52219820Sjeff    else
53219820Sjeff        AC_MSG_RESULT([could not detect number of cores, defaulting to 1])
54219820Sjeff        AC_MSG_WARN([This will disable all parallelism from build!])
55219820Sjeff    fi 
56219820Sjeff
57219820Sjeff])
58219820Sjeff
59219820SjeffAC_DEFUN([BPERF_CHECK_MEMORY_SIZE],
60219820Sjeff[
61219820Sjeff    AC_MSG_CHECKING([for memory size])
62219820Sjeff    # Default to 1024 MB
63219820Sjeff    MEMORY_SIZE=1024
64219820Sjeff    FOUND_MEM=no
65219820Sjeff    
66219820Sjeff    if test -f /proc/meminfo; then
67219820Sjeff        # Looks like a Linux (or cygwin) system
68219820Sjeff        MEMORY_SIZE=`cat /proc/meminfo | grep MemTotal | awk '{print [$]2}'`
69219820Sjeff        MEMORY_SIZE=`expr $MEMORY_SIZE / 1024`
70219820Sjeff        FOUND_MEM=yes
71219820Sjeff    elif test -x /usr/sbin/prtconf; then
72219820Sjeff        # Looks like a Solaris system
73219820Sjeff        MEMORY_SIZE=`/usr/sbin/prtconf | grep "Memory size" | awk '{ print [$]3 }'`
74219820Sjeff        FOUND_MEM=yes
75219820Sjeff    elif test -x /usr/sbin/system_profiler; then
76219820Sjeff        # Looks like a MacOSX system
77219820Sjeff        MEMORY_SIZE=`/usr/sbin/system_profiler -detailLevel full SPHardwareDataType | grep 'Memory' | awk  '{print [$]2}'`
78219820Sjeff        MEMORY_SIZE=`expr $MEMORY_SIZE \* 1024`
79219820Sjeff        FOUND_MEM=yes
80219820Sjeff    elif test "x$OPENJDK_BUILD_OS" = xwindows; then
81219820Sjeff        # Windows, but without cygwin
82219820Sjeff        MEMORY_SIZE=`wmic computersystem get totalphysicalmemory -value | grep = | cut -d "=" -f 2-`
83219820Sjeff        MEMORY_SIZE=`expr $MEMORY_SIZE / 1024 / 1024`
84219820Sjeff        FOUND_MEM=yes    
85219820Sjeff    fi
86219820Sjeff
87219820Sjeff    if test "x$FOUND_MEM" = xyes; then
88219820Sjeff        AC_MSG_RESULT([$MEMORY_SIZE MB])
89219820Sjeff    else
90219820Sjeff        AC_MSG_RESULT([could not detect memory size, defaulting to 1024 MB])
91219820Sjeff        AC_MSG_WARN([This might seriously impact build performance!])
92219820Sjeff    fi 
93219820Sjeff])
94219820Sjeff
95219820SjeffAC_DEFUN_ONCE([BPERF_SETUP_BUILD_CORES],
96219820Sjeff[
97219820Sjeff  # How many cores do we have on this build system?
98219820Sjeff  AC_ARG_WITH(num-cores, [AS_HELP_STRING([--with-num-cores],
99219820Sjeff    [number of cores in the build system, e.g. --with-num-cores=8 @<:@probed@:>@])])
100219820Sjeff  if test "x$with_num_cores" = x; then
101219820Sjeff    # The number of cores were not specified, try to probe them.
102219820Sjeff    BPERF_CHECK_CORES
103219820Sjeff  else
104219820Sjeff    NUM_CORES=$with_num_cores
105219820Sjeff  fi
106219820Sjeff  AC_SUBST(NUM_CORES)
107219820Sjeff])
108219820Sjeff
109219820SjeffAC_DEFUN_ONCE([BPERF_SETUP_BUILD_MEMORY],
110219820Sjeff[
111219820Sjeff  # How much memory do we have on this build system?
112219820Sjeff  AC_ARG_WITH(memory-size, [AS_HELP_STRING([--with-memory-size],
113219820Sjeff    [memory (in MB) available in the build system, e.g. --with-memory-size=1024 @<:@probed@:>@])])
114255932Salfred  if test "x$with_memory_size" = x; then
115255932Salfred    # The memory size was not specified, try to probe it.
116255932Salfred    BPERF_CHECK_MEMORY_SIZE
117219820Sjeff  else
118219820Sjeff    MEMORY_SIZE=$with_memory_size
119219820Sjeff  fi
120219820Sjeff  AC_SUBST(MEMORY_SIZE)
121219820Sjeff])
122219820Sjeff
123219820SjeffAC_DEFUN_ONCE([BPERF_SETUP_BUILD_JOBS],
124219820Sjeff[
125219820Sjeff  # Provide a decent default number of parallel jobs for make depending on 
126219820Sjeff  # number of cores, amount of memory and machine architecture.
127219820Sjeff  AC_ARG_WITH(jobs, [AS_HELP_STRING([--with-jobs],
128219820Sjeff    [number of parallel jobs to let make run @<:@calculated based on cores and memory@:>@])])
129219820Sjeff  if test "x$with_jobs" = x; then
130219820Sjeff    # Number of jobs was not specified, calculate.
131219820Sjeff    AC_MSG_CHECKING([for appropriate number of jobs to run in parallel])
132219820Sjeff    # Approximate memory in GB, rounding up a bit.
133219820Sjeff    memory_gb=`expr $MEMORY_SIZE / 1100`
134219820Sjeff    # Pick the lowest of memory in gb and number of cores.
135219820Sjeff    if test "$memory_gb" -lt "$NUM_CORES"; then
136219820Sjeff      JOBS="$memory_gb"
137219820Sjeff    else
138219820Sjeff      JOBS="$NUM_CORES"
139219820Sjeff      # On bigger machines, leave some room for other processes to run
140219820Sjeff      if test "$JOBS" -gt "4"; then
141219820Sjeff        JOBS=`expr $JOBS '*' 90 / 100`
142219820Sjeff      fi
143219820Sjeff    fi
144219820Sjeff    # Cap number of jobs to 16
145219820Sjeff    if test "$JOBS" -gt "16"; then
146219820Sjeff      JOBS=16
147219820Sjeff    fi
148219820Sjeff    AC_MSG_RESULT([$JOBS])
149219820Sjeff  else
150219820Sjeff    JOBS=$with_jobs
151219820Sjeff  fi
152219820Sjeff  AC_SUBST(JOBS)
153219820Sjeff])
154219820Sjeff
155219820SjeffAC_DEFUN([BPERF_SETUP_CCACHE],
156219820Sjeff[
157219820Sjeff    AC_ARG_ENABLE([ccache],
158219820Sjeff	      [AS_HELP_STRING([--disable-ccache],
159219820Sjeff	      		      [disable using ccache to speed up recompilations @<:@enabled@:>@])],
160219820Sjeff              [ENABLE_CCACHE=${enable_ccache}], [ENABLE_CCACHE=yes])
161219820Sjeff    if test "x$ENABLE_CCACHE" = xyes; then
162219820Sjeff        AC_PATH_PROG(CCACHE, ccache)
163219820Sjeff    else
164219820Sjeff        AC_MSG_CHECKING([for ccache])
165219820Sjeff        AC_MSG_RESULT([explicitly disabled])    
166219820Sjeff        CCACHE=
167219820Sjeff    fi    
168219820Sjeff    AC_SUBST(CCACHE)
169219820Sjeff
170219820Sjeff    AC_ARG_WITH([ccache-dir],
171219820Sjeff	      [AS_HELP_STRING([--with-ccache-dir],
172219820Sjeff	      		      [where to store ccache files @<:@~/.ccache@:>@])])
173219820Sjeff
174219820Sjeff    if test "x$with_ccache_dir" != x; then
175219820Sjeff        # When using a non home ccache directory, assume the use is to share ccache files
176219820Sjeff        # with other users. Thus change the umask.
177219820Sjeff        SET_CCACHE_DIR="CCACHE_DIR=$with_ccache_dir CCACHE_UMASK=002"
178219820Sjeff    fi
179219820Sjeff    CCACHE_FOUND=""
180219820Sjeff    if test "x$CCACHE" != x; then
181219820Sjeff        BPERF_SETUP_CCACHE_USAGE
182219820Sjeff    fi    
183219820Sjeff])
184219820Sjeff
185219820SjeffAC_DEFUN([BPERF_SETUP_CCACHE_USAGE],
186219820Sjeff[
187219820Sjeff    if test "x$CCACHE" != x; then
188219820Sjeff        CCACHE_FOUND="true"
189219820Sjeff        # Only use ccache if it is 3.1.4 or later, which supports
190219820Sjeff        # precompiled headers.
191219820Sjeff        AC_MSG_CHECKING([if ccache supports precompiled headers])
192219820Sjeff        HAS_GOOD_CCACHE=`($CCACHE --version | head -n 1 | grep -E 3.1.@<:@456789@:>@) 2> /dev/null`
193219820Sjeff        if test "x$HAS_GOOD_CCACHE" = x; then
194219820Sjeff            AC_MSG_RESULT([no, disabling ccache])
195219820Sjeff            CCACHE=
196219820Sjeff        else
197219820Sjeff            AC_MSG_RESULT([yes])
198219820Sjeff            AC_MSG_CHECKING([if C-compiler supports ccache precompiled headers])
199219820Sjeff            PUSHED_FLAGS="$CXXFLAGS"
200219820Sjeff            CXXFLAGS="-fpch-preprocess $CXXFLAGS"
201219820Sjeff            AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [CC_KNOWS_CCACHE_TRICK=yes], [CC_KNOWS_CCACHE_TRICK=no])
202219820Sjeff            CXXFLAGS="$PUSHED_FLAGS"
203219820Sjeff            if test "x$CC_KNOWS_CCACHE_TRICK" = xyes; then
204219820Sjeff                AC_MSG_RESULT([yes])
205219820Sjeff            else
206219820Sjeff                AC_MSG_RESULT([no, disabling ccaching of precompiled headers])
207219820Sjeff                CCACHE=
208219820Sjeff            fi
209219820Sjeff        fi
210219820Sjeff    fi
211219820Sjeff
212219820Sjeff    if test "x$CCACHE" != x; then
213219820Sjeff        CCACHE_SLOPPINESS=time_macros
214219820Sjeff        CCACHE="CCACHE_COMPRESS=1 $SET_CCACHE_DIR CCACHE_SLOPPINESS=$CCACHE_SLOPPINESS $CCACHE"
215219820Sjeff        CCACHE_FLAGS=-fpch-preprocess
216219820Sjeff
217219820Sjeff        if test "x$SET_CCACHE_DIR" != x; then
218219820Sjeff            mkdir -p $CCACHE_DIR > /dev/null 2>&1
219219820Sjeff	    chmod a+rwxs $CCACHE_DIR > /dev/null 2>&1
220219820Sjeff        fi
221219820Sjeff    fi
222219820Sjeff])
223219820Sjeff
224219820SjeffAC_DEFUN_ONCE([BPERF_SETUP_PRECOMPILED_HEADERS],
225219820Sjeff[
226219820Sjeff       
227219820Sjeff###############################################################################
228219820Sjeff#
229219820Sjeff# Can the C/C++ compiler use precompiled headers?
230219820Sjeff#
231219820SjeffAC_ARG_ENABLE([precompiled-headers], [AS_HELP_STRING([--disable-precompiled-headers],
232219820Sjeff	[disable using precompiled headers when compiling C++ @<:@enabled@:>@])],
233219820Sjeff    [ENABLE_PRECOMPH=${enable_precompiled_headers}], [ENABLE_PRECOMPH=yes])
234219820Sjeff
235219820SjeffUSE_PRECOMPILED_HEADER=1
236219820Sjeffif test "x$ENABLE_PRECOMPH" = xno; then
237219820Sjeff    USE_PRECOMPILED_HEADER=0
238219820Sjefffi
239219820Sjeff
240219820Sjeffif test "x$ENABLE_PRECOMPH" = xyes; then
241219820Sjeff    # Check that the compiler actually supports precomp headers.
242219820Sjeff    if test "x$GCC" = xyes; then
243219820Sjeff         AC_MSG_CHECKING([that precompiled headers work])
244219820Sjeff         echo "int alfa();" > conftest.h
245219820Sjeff         $CXX -x c++-header conftest.h -o conftest.hpp.gch 2>&AS_MESSAGE_LOG_FD >&AS_MESSAGE_LOG_FD
246219820Sjeff         if test ! -f conftest.hpp.gch; then
247219820Sjeff             USE_PRECOMPILED_HEADER=0
248219820Sjeff             AC_MSG_RESULT([no])        
249219820Sjeff         else
250219820Sjeff             AC_MSG_RESULT([yes])
251219820Sjeff         fi
252219820Sjeff         rm -f conftest.h conftest.hpp.gch
253219820Sjeff    fi
254219820Sjefffi
255219820Sjeff
256219820SjeffAC_SUBST(USE_PRECOMPILED_HEADER)
257219820Sjeff])
258219820Sjeff
259219820Sjeff
260219820SjeffAC_DEFUN_ONCE([BPERF_SETUP_SMART_JAVAC],
261219820Sjeff[
262219820SjeffAC_ARG_WITH(sjavac-server-java, [AS_HELP_STRING([--with-sjavac-server-java],
263219820Sjeff	[use this java binary for running the sjavac background server @<:@Boot JDK java@:>@])])
264219820Sjeff
265219820Sjeffif test "x$with_sjavac_server_java" != x; then
266219820Sjeff    SJAVAC_SERVER_JAVA="$with_sjavac_server_java"
267219820Sjeff    FOUND_VERSION=`$SJAVAC_SERVER_JAVA -version 2>&1 | grep " version \""`
268219820Sjeff    if test "x$FOUND_VERSION" = x; then
269219820Sjeff        AC_MSG_ERROR([Could not execute server java: $SJAVAC_SERVER_JAVA])
270219820Sjeff    fi
271219820Sjeffelse
272219820Sjeff    SJAVAC_SERVER_JAVA=""
273219820Sjeff    # Hotspot specific options.
274219820Sjeff    ADD_JVM_ARG_IF_OK([-verbosegc],SJAVAC_SERVER_JAVA,[$JAVA])
275219820Sjeff    # JRockit specific options.
276219820Sjeff    ADD_JVM_ARG_IF_OK([-Xverbose:gc],SJAVAC_SERVER_JAVA,[$JAVA])
277219820Sjeff    SJAVAC_SERVER_JAVA="$JAVA $SJAVAC_SERVER_JAVA"
278219820Sjefffi                    
279219820SjeffAC_SUBST(SJAVAC_SERVER_JAVA)
280219820Sjeff
281219820Sjeffif test "$MEMORY_SIZE" -gt "2500"; then
282219820Sjeff    ADD_JVM_ARG_IF_OK([-d64],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
283219820Sjeff    if test "$JVM_ARG_OK" = true; then
284219820Sjeff        JVM_64BIT=true
285219820Sjeff	JVM_ARG_OK=false
286219820Sjeff    fi
287219820Sjeff    fi
288219820Sjeff
289219820Sjeffif test "$JVM_64BIT" = true; then
290219820Sjeff    if test "$MEMORY_SIZE" -gt "17000"; then
291219820Sjeff        ADD_JVM_ARG_IF_OK([-Xms10G -Xmx10G],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
292219820Sjeff    fi
293219820Sjeff    if test "$MEMORY_SIZE" -gt "10000" && test "$JVM_ARG_OK" = false; then
294219820Sjeff        ADD_JVM_ARG_IF_OK([-Xms6G -Xmx6G],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
295219820Sjeff    fi
296219820Sjeff    if test "$MEMORY_SIZE" -gt "5000" && test "$JVM_ARG_OK" = false; then
297219820Sjeff        ADD_JVM_ARG_IF_OK([-Xms1G -Xmx3G],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
298219820Sjeff    fi
299219820Sjeff    if test "$MEMORY_SIZE" -gt "3800" && test "$JVM_ARG_OK" = false; then
300219820Sjeff        ADD_JVM_ARG_IF_OK([-Xms1G -Xmx2500M],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
301219820Sjeff    fi
302219820Sjefffi
303219820Sjeffif test "$MEMORY_SIZE" -gt "2500" && test "$JVM_ARG_OK" = false; then
304219820Sjeff    ADD_JVM_ARG_IF_OK([-Xms1000M -Xmx1500M],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
305219820Sjefffi
306219820Sjeffif test "$MEMORY_SIZE" -gt "1000" && test "$JVM_ARG_OK" = false; then
307219820Sjeff    ADD_JVM_ARG_IF_OK([-Xms400M -Xmx1100M],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
308219820Sjefffi
309219820Sjeffif test "$JVM_ARG_OK" = false; then
310219820Sjeff    ADD_JVM_ARG_IF_OK([-Xms256M -Xmx512M],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
311219820Sjefffi
312219820Sjeff
313219820SjeffAC_MSG_CHECKING([whether to use sjavac])
314219820SjeffAC_ARG_ENABLE([sjavac], [AS_HELP_STRING([--enable-sjavac],
315219820Sjeff	[use sjavac to do fast incremental compiles @<:@disabled@:>@])],
316219820Sjeff	[ENABLE_SJAVAC="${enableval}"], [ENABLE_SJAVAC='no'])
317219820SjeffAC_MSG_RESULT([$ENABLE_SJAVAC])
318219820SjeffAC_SUBST(ENABLE_SJAVAC)
319219820Sjeff
320219820Sjeffif test "x$ENABLE_SJAVAC" = xyes; then
321219820Sjeff    SJAVAC_SERVER_DIR="$OUTPUT_ROOT/javacservers"
322219820Sjeffelse
323219820Sjeff    SJAVAC_SERVER_DIR=
324219820Sjefffi
325219820SjeffAC_SUBST(SJAVAC_SERVER_DIR)
326219820Sjeff
327219820Sjeff])
328219820Sjeff