build-performance.m4 revision 633:907a926d3c96
1243750Srwatson#
2156283Srwatson# Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
3243750Srwatson# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4243750Srwatson#
5156283Srwatson# This code is free software; you can redistribute it and/or modify it
6156283Srwatson# under the terms of the GNU General Public License version 2 only, as
7156283Srwatson# published by the Free Software Foundation.  Oracle designates this
8156283Srwatson# particular file as subject to the "Classpath" exception as provided
9156283Srwatson# by Oracle in the LICENSE file that accompanied this code.
10156283Srwatson#
11156283Srwatson# This code is distributed in the hope that it will be useful, but WITHOUT
12156283Srwatson# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13156283Srwatson# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14191273Srwatson# version 2 for more details (a copy is included in the LICENSE file that
15191273Srwatson# accompanied this code).
16243750Srwatson#
17243750Srwatson# You should have received a copy of the GNU General Public License version
18191273Srwatson# 2 along with this work; if not, write to the Free Software Foundation,
19191273Srwatson# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20243750Srwatson#
21173143Srwatson# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22156283Srwatson# or visit www.oracle.com if you need additional information or have any
23243750Srwatson# questions.
24243750Srwatson#
25243750Srwatson
26243750SrwatsonAC_DEFUN([BPERF_CHECK_CORES],
27243750Srwatson[
28243750Srwatson    AC_MSG_CHECKING([for number of cores])
29243750Srwatson    NUM_CORES=1
30243750Srwatson    FOUND_CORES=no
31243750Srwatson    
32156283Srwatson    if test -f /proc/cpuinfo; then
33243750Srwatson        # Looks like a Linux (or cygwin) system
34243750Srwatson        NUM_CORES=`cat /proc/cpuinfo  | grep -c processor`
35243750Srwatson        FOUND_CORES=yes
36243750Srwatson    elif test -x /usr/sbin/psrinfo; then
37243750Srwatson        # Looks like a Solaris system
38243750Srwatson        NUM_CORES=`LC_MESSAGES=C /usr/sbin/psrinfo -v | grep -c on-line`
39243750Srwatson        FOUND_CORES=yes
40243750Srwatson    elif test -x /usr/sbin/system_profiler; then
41243750Srwatson        # Looks like a MacOSX system
42243750Srwatson        NUM_CORES=`/usr/sbin/system_profiler -detailLevel full SPHardwareDataType | grep 'Cores' | awk  '{print [$]5}'`
43243750Srwatson        FOUND_CORES=yes
44243750Srwatson    elif test -n "$NUMBER_OF_PROCESSORS"; then
45243750Srwatson        # On windows, look in the env
46243750Srwatson        NUM_CORES=$NUMBER_OF_PROCESSORS
47243750Srwatson        FOUND_CORES=yes
48243750Srwatson    fi
49243750Srwatson
50243750Srwatson    if test "x$FOUND_CORES" = xyes; then
51243750Srwatson        AC_MSG_RESULT([$NUM_CORES])
52243750Srwatson    else
53243750Srwatson        AC_MSG_RESULT([could not detect number of cores, defaulting to 1])
54243750Srwatson        AC_MSG_WARN([This will disable all parallelism from build!])
55243750Srwatson    fi 
56243750Srwatson
57243750Srwatson])
58243750Srwatson
59243750SrwatsonAC_DEFUN([BPERF_CHECK_MEMORY_SIZE],
60243750Srwatson[
61243750Srwatson    AC_MSG_CHECKING([for memory size])
62156283Srwatson    # Default to 1024 MB
63243750Srwatson    MEMORY_SIZE=1024
64156283Srwatson    FOUND_MEM=no
65156283Srwatson    
66243750Srwatson    if test -f /proc/meminfo; then
67243750Srwatson        # Looks like a Linux (or cygwin) system
68243750Srwatson        MEMORY_SIZE=`cat /proc/meminfo | grep MemTotal | awk '{print [$]2}'`
69243750Srwatson        MEMORY_SIZE=`expr $MEMORY_SIZE / 1024`
70243750Srwatson        FOUND_MEM=yes
71243750Srwatson    elif test -x /usr/sbin/prtconf; then
72243750Srwatson        # Looks like a Solaris system
73243750Srwatson        MEMORY_SIZE=`/usr/sbin/prtconf | grep "Memory size" | awk '{ print [$]3 }'`
74243750Srwatson        FOUND_MEM=yes
75156283Srwatson    elif test -x /usr/sbin/system_profiler; then
76156283Srwatson        # Looks like a MacOSX system
77243750Srwatson        MEMORY_SIZE=`/usr/sbin/system_profiler -detailLevel full SPHardwareDataType | grep 'Memory' | awk  '{print [$]2}'`
78243750Srwatson        MEMORY_SIZE=`expr $MEMORY_SIZE \* 1024`
79243750Srwatson        FOUND_MEM=yes
80243750Srwatson    elif test "x$OPENJDK_BUILD_OS" = xwindows; then
81243750Srwatson        # Windows, but without cygwin
82243750Srwatson        MEMORY_SIZE=`wmic computersystem get totalphysicalmemory -value | grep = | cut -d "=" -f 2-`
83243750Srwatson        MEMORY_SIZE=`expr $MEMORY_SIZE / 1024 / 1024`
84243750Srwatson        FOUND_MEM=yes    
85243750Srwatson    fi
86156283Srwatson
87156283Srwatson    if test "x$FOUND_MEM" = xyes; then
88243750Srwatson        AC_MSG_RESULT([$MEMORY_SIZE MB])
89243750Srwatson    else
90243750Srwatson        AC_MSG_RESULT([could not detect memory size, defaulting to 1024 MB])
91243750Srwatson        AC_MSG_WARN([This might seriously impact build performance!])
92243750Srwatson    fi 
93243750Srwatson])
94243750Srwatson
95243750SrwatsonAC_DEFUN_ONCE([BPERF_SETUP_BUILD_CORES],
96243750Srwatson[
97156283Srwatson  # How many cores do we have on this build system?
98243750Srwatson  AC_ARG_WITH(num-cores, [AS_HELP_STRING([--with-num-cores],
99243750Srwatson    [number of cores in the build system, e.g. --with-num-cores=8 @<:@probed@:>@])])
100243750Srwatson  if test "x$with_num_cores" = x; then
101243750Srwatson    # The number of cores were not specified, try to probe them.
102243750Srwatson    BPERF_CHECK_CORES
103243750Srwatson  else
104243750Srwatson    NUM_CORES=$with_num_cores
105243750Srwatson  fi
106243750Srwatson  AC_SUBST(NUM_CORES)
107243750Srwatson])
108243750Srwatson
109243750SrwatsonAC_DEFUN_ONCE([BPERF_SETUP_BUILD_MEMORY],
110243750Srwatson[
111243750Srwatson  # How much memory do we have on this build system?
112243750Srwatson  AC_ARG_WITH(memory-size, [AS_HELP_STRING([--with-memory-size],
113243750Srwatson    [memory (in MB) available in the build system, e.g. --with-memory-size=1024 @<:@probed@:>@])])
114156283Srwatson  if test "x$with_memory_size" = x; then
115243750Srwatson    # The memory size was not specified, try to probe it.
116156283Srwatson    BPERF_CHECK_MEMORY_SIZE
117156283Srwatson  else
118156283Srwatson    MEMORY_SIZE=$with_memory_size
119156283Srwatson  fi
120156283Srwatson  AC_SUBST(MEMORY_SIZE)
121243750Srwatson])
122156283Srwatson
123243750SrwatsonAC_DEFUN_ONCE([BPERF_SETUP_BUILD_JOBS],
124243750Srwatson[
125243750Srwatson  # Provide a decent default number of parallel jobs for make depending on 
126156283Srwatson  # number of cores, amount of memory and machine architecture.
127243750Srwatson  AC_ARG_WITH(jobs, [AS_HELP_STRING([--with-jobs],
128243750Srwatson    [number of parallel jobs to let make run @<:@calculated based on cores and memory@:>@])])
129243750Srwatson  if test "x$with_jobs" = x; then
130243750Srwatson    # Number of jobs was not specified, calculate.
131243750Srwatson    AC_MSG_CHECKING([for appropriate number of jobs to run in parallel])
132243750Srwatson    # Approximate memory in GB, rounding up a bit.
133243750Srwatson    memory_gb=`expr $MEMORY_SIZE / 1100`
134243750Srwatson    # Pick the lowest of memory in gb and number of cores.
135243750Srwatson    if test "$memory_gb" -lt "$NUM_CORES"; then
136243750Srwatson      JOBS="$memory_gb"
137243750Srwatson    else
138243750Srwatson      JOBS="$NUM_CORES"
139243750Srwatson      # On bigger machines, leave some room for other processes to run
140243750Srwatson      if test "$JOBS" -gt "4"; then
141243750Srwatson        JOBS=`expr $JOBS '*' 90 / 100`
142243750Srwatson      fi
143243750Srwatson    fi
144243750Srwatson    # Cap number of jobs to 16
145243750Srwatson    if test "$JOBS" -gt "16"; then
146243750Srwatson      JOBS=16
147243750Srwatson    fi
148243750Srwatson    AC_MSG_RESULT([$JOBS])
149243750Srwatson  else
150243750Srwatson    JOBS=$with_jobs
151243750Srwatson  fi
152243750Srwatson  AC_SUBST(JOBS)
153243750Srwatson])
154243750Srwatson
155243750SrwatsonAC_DEFUN([BPERF_SETUP_CCACHE],
156243750Srwatson[
157243750Srwatson    AC_ARG_ENABLE([ccache],
158243750Srwatson	      [AS_HELP_STRING([--disable-ccache],
159243750Srwatson	      		      [disable using ccache to speed up recompilations @<:@enabled@:>@])],
160243750Srwatson              [ENABLE_CCACHE=${enable_ccache}], [ENABLE_CCACHE=yes])
161243750Srwatson    if test "x$ENABLE_CCACHE" = xyes; then
162243750Srwatson        AC_PATH_PROG(CCACHE, ccache)
163243750Srwatson    else
164243750Srwatson        AC_MSG_CHECKING([for ccache])
165243750Srwatson        AC_MSG_RESULT([explicitly disabled])    
166156283Srwatson        CCACHE=
167243750Srwatson    fi    
168243750Srwatson    AC_SUBST(CCACHE)
169243750Srwatson
170243750Srwatson    AC_ARG_WITH([ccache-dir],
171243750Srwatson	      [AS_HELP_STRING([--with-ccache-dir],
172243750Srwatson	      		      [where to store ccache files @<:@~/.ccache@:>@])])
173243750Srwatson
174243750Srwatson    if test "x$with_ccache_dir" != x; then
175243750Srwatson        # When using a non home ccache directory, assume the use is to share ccache files
176243750Srwatson        # with other users. Thus change the umask.
177243750Srwatson        SET_CCACHE_DIR="CCACHE_DIR=$with_ccache_dir CCACHE_UMASK=002"
178243750Srwatson    fi
179243750Srwatson    CCACHE_FOUND=""
180156283Srwatson    if test "x$CCACHE" != x; then
181243750Srwatson        BPERF_SETUP_CCACHE_USAGE
182243750Srwatson    fi    
183243750Srwatson])
184156283Srwatson
185243750SrwatsonAC_DEFUN([BPERF_SETUP_CCACHE_USAGE],
186243750Srwatson[
187156283Srwatson    if test "x$CCACHE" != x; then
188243750Srwatson        CCACHE_FOUND="true"
189243750Srwatson        # Only use ccache if it is 3.1.4 or later, which supports
190243750Srwatson        # precompiled headers.
191243750Srwatson        AC_MSG_CHECKING([if ccache supports precompiled headers])
192243750Srwatson        HAS_GOOD_CCACHE=`($CCACHE --version | head -n 1 | grep -E 3.1.@<:@456789@:>@) 2> /dev/null`
193243750Srwatson        if test "x$HAS_GOOD_CCACHE" = x; then
194243750Srwatson            AC_MSG_RESULT([no, disabling ccache])
195243750Srwatson            CCACHE=
196243750Srwatson        else
197243750Srwatson            AC_MSG_RESULT([yes])
198243750Srwatson            AC_MSG_CHECKING([if C-compiler supports ccache precompiled headers])
199243750Srwatson            PUSHED_FLAGS="$CXXFLAGS"
200243750Srwatson            CXXFLAGS="-fpch-preprocess $CXXFLAGS"
201156283Srwatson            AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [CC_KNOWS_CCACHE_TRICK=yes], [CC_KNOWS_CCACHE_TRICK=no])
202243750Srwatson            CXXFLAGS="$PUSHED_FLAGS"
203243750Srwatson            if test "x$CC_KNOWS_CCACHE_TRICK" = xyes; then
204243750Srwatson                AC_MSG_RESULT([yes])
205243750Srwatson            else
206243750Srwatson                AC_MSG_RESULT([no, disabling ccaching of precompiled headers])
207243750Srwatson                CCACHE=
208243750Srwatson            fi
209243750Srwatson        fi
210243750Srwatson    fi
211243750Srwatson
212156283Srwatson    if test "x$CCACHE" != x; then
213243750Srwatson        CCACHE_SLOPPINESS=time_macros
214243750Srwatson        CCACHE="CCACHE_COMPRESS=1 $SET_CCACHE_DIR CCACHE_SLOPPINESS=$CCACHE_SLOPPINESS $CCACHE"
215243750Srwatson        CCACHE_FLAGS=-fpch-preprocess
216243750Srwatson
217156283Srwatson        if test "x$SET_CCACHE_DIR" != x; then
218156283Srwatson            mkdir -p $CCACHE_DIR > /dev/null 2>&1
219156283Srwatson	    chmod a+rwxs $CCACHE_DIR > /dev/null 2>&1
220156283Srwatson        fi
221156283Srwatson    fi
222156283Srwatson])
223156283Srwatson
224156283SrwatsonAC_DEFUN_ONCE([BPERF_SETUP_PRECOMPILED_HEADERS],
225156283Srwatson[
226156283Srwatson       
227156283Srwatson###############################################################################
228156283Srwatson#
229156283Srwatson# Can the C/C++ compiler use precompiled headers?
230243750Srwatson#
231156283SrwatsonAC_ARG_ENABLE([precompiled-headers], [AS_HELP_STRING([--disable-precompiled-headers],
232156283Srwatson	[disable using precompiled headers when compiling C++ @<:@enabled@:>@])],
233156283Srwatson    [ENABLE_PRECOMPH=${enable_precompiled_headers}], [ENABLE_PRECOMPH=yes])
234156283Srwatson
235156283SrwatsonUSE_PRECOMPILED_HEADER=1
236243750Srwatsonif test "x$ENABLE_PRECOMPH" = xno; then
237156283Srwatson    USE_PRECOMPILED_HEADER=0
238156283Srwatsonfi
239156283Srwatson
240156283Srwatsonif test "x$ENABLE_PRECOMPH" = xyes; then
241156283Srwatson    # Check that the compiler actually supports precomp headers.
242156283Srwatson    if test "x$GCC" = xyes; then
243156283Srwatson         AC_MSG_CHECKING([that precompiled headers work])
244156283Srwatson         echo "int alfa();" > conftest.h
245173143Srwatson         $CXX -x c++-header conftest.h -o conftest.hpp.gch 2>&AS_MESSAGE_LOG_FD >&AS_MESSAGE_LOG_FD
246156283Srwatson         if test ! -f conftest.hpp.gch; then
247156283Srwatson             USE_PRECOMPILED_HEADER=0
248156283Srwatson             AC_MSG_RESULT([no])        
249156283Srwatson         else
250156283Srwatson             AC_MSG_RESULT([yes])
251156283Srwatson         fi
252243750Srwatson         rm -f conftest.h conftest.hpp.gch
253156283Srwatson    fi
254156283Srwatsonfi
255156283Srwatson
256243750SrwatsonAC_SUBST(USE_PRECOMPILED_HEADER)
257156283Srwatson])
258156283Srwatson
259156283Srwatson
260156283SrwatsonAC_DEFUN_ONCE([BPERF_SETUP_SMART_JAVAC],
261243750Srwatson[
262243750SrwatsonAC_ARG_WITH(sjavac-server-java, [AS_HELP_STRING([--with-sjavac-server-java],
263243750Srwatson	[use this java binary for running the sjavac background server @<:@Boot JDK java@:>@])])
264243750Srwatson
265243750Srwatsonif test "x$with_sjavac_server_java" != x; then
266243750Srwatson    SJAVAC_SERVER_JAVA="$with_sjavac_server_java"
267191273Srwatson    FOUND_VERSION=`$SJAVAC_SERVER_JAVA -version 2>&1 | grep " version \""`
268156283Srwatson    if test "x$FOUND_VERSION" = x; then
269243750Srwatson        AC_MSG_ERROR([Could not execute server java: $SJAVAC_SERVER_JAVA])
270243750Srwatson    fi
271243750Srwatsonelse
272243750Srwatson    SJAVAC_SERVER_JAVA=""
273243750Srwatson    # Hotspot specific options.
274243750Srwatson    ADD_JVM_ARG_IF_OK([-verbosegc],SJAVAC_SERVER_JAVA,[$JAVA])
275243750Srwatson    # JRockit specific options.
276156283Srwatson    ADD_JVM_ARG_IF_OK([-Xverbose:gc],SJAVAC_SERVER_JAVA,[$JAVA])
277243750Srwatson    SJAVAC_SERVER_JAVA="$JAVA $SJAVAC_SERVER_JAVA"
278243750Srwatsonfi                    
279156283SrwatsonAC_SUBST(SJAVAC_SERVER_JAVA)
280243750Srwatson
281243750SrwatsonAC_ARG_WITH(sjavac-server-cores, [AS_HELP_STRING([--with-sjavac-server-cores],
282243750Srwatson	[use at most this number of concurrent threads on the sjavac server @<:@probed@:>@])])
283156283Srwatsonif test "x$with_sjavac_server_cores" != x; then
284243750Srwatson    SJAVAC_SERVER_CORES="$with_sjavac_server_cores"
285243750Srwatsonelse
286156283Srwatson    if test "$NUM_CORES" -gt 16; then
287243750Srwatson        # We set this arbitrary limit because we want to limit the heap
288243750Srwatson        # size of the javac server.
289243750Srwatson        # In the future we will make the javac compilers in the server
290243750Srwatson        # share more and more state, thus enabling us to use more and
291243750Srwatson        # more concurrent threads in the server.
292243750Srwatson        SJAVAC_SERVER_CORES="16"
293243750Srwatson    else
294243750Srwatson        SJAVAC_SERVER_CORES="$NUM_CORES"
295243750Srwatson    fi
296243750Srwatson
297243750Srwatson    if test "$MEMORY_SIZE" -gt "17000"; then
298243750Srwatson        MAX_HEAP_MEM=10000
299243750Srwatson        ADD_JVM_ARG_IF_OK([-d64],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
300243750Srwatson        ADD_JVM_ARG_IF_OK([-Xms10G -Xmx10G],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
301243750Srwatson    elif test "$MEMORY_SIZE" -gt "10000"; then
302243750Srwatson        MAX_HEAP_MEM=6000
303243750Srwatson        ADD_JVM_ARG_IF_OK([-d64],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
304243750Srwatson        ADD_JVM_ARG_IF_OK([-Xms6G -Xmx6G],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
305243750Srwatson    elif test "$MEMORY_SIZE" -gt "5000"; then
306243750Srwatson        MAX_HEAP_MEM=3000
307243750Srwatson        ADD_JVM_ARG_IF_OK([-d64],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
308243750Srwatson        ADD_JVM_ARG_IF_OK([-Xms1G -Xmx3G],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
309243750Srwatson    elif test "$MEMORY_SIZE" -gt "3800"; then
310243750Srwatson        MAX_HEAP_MEM=2500
311243750Srwatson        ADD_JVM_ARG_IF_OK([-Xms1G -Xmx2500M],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
312243750Srwatson    elif test "$MEMORY_SIZE" -gt "1900"; then
313243750Srwatson        MAX_HEAP_MEM=1200
314243750Srwatson        ADD_JVM_ARG_IF_OK([-Xms700M -Xmx1400M],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
315243750Srwatson    elif test "$MEMORY_SIZE" -gt "1000"; then
316243750Srwatson        MAX_HEAP_MEM=900
317243750Srwatson        ADD_JVM_ARG_IF_OK([-Xms400M -Xmx1100M],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
318243750Srwatson    else
319243750Srwatson        MAX_HEAP_MEM=512
320243750Srwatson        ADD_JVM_ARG_IF_OK([-Xms256M -Xmx512M],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
321243750Srwatson    fi
322243750Srwatson
323243750Srwatson    ADD_JVM_ARG_IF_OK([-XX:PermSize=32m],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
324243750Srwatson    ADD_JVM_ARG_IF_OK([-XX:MaxPermSize=160m],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
325243750Srwatson    ADD_JVM_ARG_IF_OK([-XX:ThreadStackSize=$STACK_SIZE],SJAVAC_SERVER_JAVA,[$SJAVAC_SERVER_JAVA])
326243750Srwatson
327243750Srwatson    MAX_COMPILERS_IN_HEAP=`expr $MAX_HEAP_MEM / 501`
328243750Srwatson    if test "$SJAVAC_SERVER_CORES" -gt "$MAX_COMPILERS_IN_HEAP"; then
329243750Srwatson        AC_MSG_CHECKING([if number of server cores must be reduced])
330243750Srwatson        SJAVAC_SERVER_CORES="$MAX_COMPILERS_IN_HEAP"
331243750Srwatson        AC_MSG_RESULT([yes, to $SJAVAC_SERVER_CORES with max heap size $MAX_HEAP_MEM MB])
332243750Srwatson    fi
333243750Srwatsonfi                    
334243750SrwatsonAC_SUBST(SJAVAC_SERVER_CORES)
335243750Srwatson
336243750SrwatsonAC_MSG_CHECKING([whether to use sjavac])
337243750SrwatsonAC_ARG_ENABLE([sjavac], [AS_HELP_STRING([--enable-sjavac],
338243750Srwatson	[use sjavac to do fast incremental compiles @<:@disabled@:>@])],
339243750Srwatson	[ENABLE_SJAVAC="${enableval}"], [ENABLE_SJAVAC='no'])
340243750SrwatsonAC_MSG_RESULT([$ENABLE_SJAVAC])
341243750SrwatsonAC_SUBST(ENABLE_SJAVAC)
342243750Srwatson
343243750Srwatsonif test "x$ENABLE_SJAVAC" = xyes; then
344243750Srwatson    SJAVAC_SERVER_DIR="$OUTPUT_ROOT/javacservers"
345243750Srwatsonelse
346243750Srwatson    SJAVAC_SERVER_DIR=
347243750Srwatsonfi
348243750SrwatsonAC_SUBST(SJAVAC_SERVER_DIR)
349243750Srwatson
350243750Srwatson])
351243750Srwatson