Pass a flag to the Java compiler to increase the maximum heap size of the

Branches: main

Pass a flag to the Java compiler to increase the maximum heap size of the
JVM.  The default size (at least with Sun Java) is too small to build the
Mercury standard library on 32-bit JVMs.  We choose a heap size of 256 MB
currently.  (There doesn't seem to be an option to just switch off the
maximum.)

As the flag may not work with non-Sun compilers, we have to check during
configuration whether it's accepted by the detected Java compiler.

aclocal.m4:
        Add a function to check if the Java compiler accepts the option
        `-J-Xmx<n>'.

        Bump Java SDK requirement to 1.5 (this was raised previously without
        updating the check).

        Update some comments.

configure.in:
        Add the configure option `--enable-javac-flags-for-heap-size',
        enabled by default.

        Check if the Java compiler accepts the maximum heap size option.

        Substitute the option in scripts.

scripts/Mercury.config.bootstrap.in:
scripts/Mercury.config.in:
scripts/Mmake.vars.in:
        Add @JAVAC_FLAGS_FOR_HEAP_SIZE@ to default javac flags.
This commit is contained in:
Peter Wang
2009-08-18 05:10:40 +00:00
parent 7df1fc0548
commit ff5715c766
5 changed files with 47 additions and 6 deletions

27
aclocal.m4 vendored
View File

@@ -328,7 +328,7 @@ if test "$JAVAC" != "" -a "$JAVA_INTERPRETER" != "" -a "$JAR" != ""; then
cat > conftest.java << EOF
// This program simply retrieves the constant
// specifying the version number of the Java SDK and
// checks it is at least 1.2, printing "Hello, world"
// checks it is at least 1.5, printing "Hello, world"
// if successful.
public class conftest {
public static void main (String[[]] args) {
@@ -348,7 +348,7 @@ if test "$JAVAC" != "" -a "$JAVA_INTERPRETER" != "" -a "$JAR" != ""; then
version = 0f;
}
if (version >= 1.2f) {
if (version >= 1.5f) {
System.out.println("Hello, world\n");
} else {
System.out.println("Nope, sorry.\n");
@@ -387,6 +387,29 @@ AC_SUBST(JAVA_INTERPRETER)
AC_SUBST(JAR)
])
AC_DEFUN(MERCURY_CHECK_JAVAC_HEAP_SIZE,
[
# The default maximum heap size is too small to build the standard library and
# other programs so we need to increase it. The option to do that is
# non-standard so we have to check that it is accepted.
AC_CACHE_VAL(mercury_cv_javac_flags_for_heap_size, [
if test "$mercury_cv_java" = "yes"; then
AC_MSG_CHECKING(if the Java compiler accepts the max heap size option)
mercury_cv_javac_flags_for_heap_size="-J-Xmx256m"
if "$JAVAC" "$mercury_cv_javac_flags_for_heap_size" -version \
2> /dev/null
then
AC_MSG_RESULT(yes)
else
AC_MSG_RESULT(no)
mercury_cv_javac_flags_for_heap_size=
fi
else
mercury_cv_javac_flags_for_heap_size=
fi
])
])
#-----------------------------------------------------------------------------#
#
# Erlang configuration

View File

@@ -1051,6 +1051,23 @@ MERCURY_CHECK_DOTNET
MERCURY_CHECK_JAVA
AC_ARG_ENABLE(javac-flags-for-heap-size,
AC_HELP_STRING([--enable-javac-flags-for-heap-size],
[enable maximum heap size option for Java compiler]),
enable_javac_flags_for_heap_size="$enableval",
enable_javac_flags_for_heap_size=yes)
case "$enable_javac_flags_for_heap_size" in
yes)
MERCURY_CHECK_JAVAC_HEAP_SIZE
JAVAC_FLAGS_FOR_HEAP_SIZE=$mercury_cv_javac_flags_for_heap_size
;;
no)
JAVAC_FLAGS_FOR_HEAP_SIZE=
;;
esac
AC_SUBST(JAVAC_FLAGS_FOR_HEAP_SIZE)
#-----------------------------------------------------------------------------#
# Erlang configuration
#
@@ -3170,14 +3187,13 @@ AC_ARG_ENABLE(dotnet-grades,
AC_HELP_STRING([--enable-dotnet-grades], [install the .NET grades]),
enable_dotnet_grades="$enableval",enable_dotnet_grades=no)
# XXX The java backend is currently broken, so we don't
# enable the java grade by default.
# We don't enable the java grade by default.
AC_ARG_ENABLE(java-grade,
AC_HELP_STRING([--enable-java-grade], [install the Java grade]),
enable_java_grade="$enableval",enable_java_grade=no)
# We don't enable the Erlang grades by default because it is still
# experimental and it requires mmc --make to install.
# experimental.
AC_ARG_ENABLE(erlang-grade,
AC_HELP_STRING([--enable-erlang-grade], [install the Erlang grade]),
enable_erlang_grade="$enableval",enable_erlang_grade=no)

View File

@@ -63,6 +63,7 @@ DEFAULT_MCFLAGS=\
--c-flag-to-name-object-file "@OBJFILE_OPT@" \
--java-classpath "$(INSTALL_JAVA_LIBRARY_DIR)/$(RT_LIB_NAME).jar" \
--java-classpath "$(INSTALL_JAVA_LIBRARY_DIR)/$(STD_LIB_NAME).jar" \
--java-flags "@JAVAC_FLAGS_FOR_HEAP_SIZE@" \
--object-file-extension ".@OBJ_SUFFIX@" \
--pic-object-file-extension ".@EXT_FOR_PIC_OBJECTS@" \
--link-with-pic-object-file-extension ".@EXT_FOR_LINK_WITH_PIC_OBJECTS@" \

View File

@@ -69,6 +69,7 @@ DEFAULT_MCFLAGS=\
--c-flag-to-name-object-file "@OBJFILE_OPT@" \
--java-classpath "$(INSTALL_JAVA_LIBRARY_DIR)/$(RT_LIB_NAME).jar" \
--java-classpath "$(INSTALL_JAVA_LIBRARY_DIR)/$(STD_LIB_NAME).jar" \
--java-flags "@JAVAC_FLAGS_FOR_HEAP_SIZE@" \
--object-file-extension ".@OBJ_SUFFIX@" \
--pic-object-file-extension ".@EXT_FOR_PIC_OBJECTS@" \
--link-with-pic-object-file-extension ".@EXT_FOR_LINK_WITH_PIC_OBJECTS@" \

View File

@@ -268,7 +268,7 @@ LIB_MS_CSCFLAGS =
JAVAC = @JAVAC@
ALL_JAVACFLAGS = $(JAVACFLAGS) $(EXTRA_JAVACFLAGS) $(TARGET_JAVACFLAGS) \
$(LIB_JAVACFLAGS)
JAVACFLAGS =
JAVACFLAGS = @JAVAC_FLAGS_FOR_HEAP_SIZE@
EXTRA_JAVACFLAGS =
# XXX Should we set LIB_JAVACFLAGS?
LIB_JAVACFLAGS =