# HG changeset patch # User Markus Mützel # Date 1593189875 -7200 # Node ID 9e7b2625e5744cfbb01bdd67a3487c75a7ef957a # Parent 286fe9352cd6f6b004e8fbb5958d9fba30f950a2 ov-java.cc: Set reaper thread to use default stack size (bug #58641). * m4/acinclude.m4 (OCTAVE_CHECK_BROKEN_PTHREAD_STACKSIZE): New configure test. * configure.ac: Run new configure test. * ov-java.cc (initialize_jvm): Set jdk.lang.processReaperUseDefaultStackSize to true if the new configure test failed (work around a glibc bug). diff -r 286fe9352cd6 -r 9e7b2625e574 configure.ac --- a/configure.ac Thu Jul 02 15:06:36 2020 +0900 +++ b/configure.ac Fri Jun 26 18:44:35 2020 +0200 @@ -563,6 +563,12 @@ CFLAGS="$CFLAGS $PTHREAD_CFLAGS" CXXFLAGS="$CXXFLAGS $PTHREAD_CFLAGS" +dnl Check if glibc uses wrong stack size +OCTAVE_CHECK_BROKEN_PTHREAD_STACKSIZE +AM_CONDITIONAL([OCTAVE_CHECK_BROKEN_PTHREAD_STACKSIZE], + [test $octave_cv_broken_pthread_stacksize = yes]) + + ### Test whether the compiler supports OpenMP. dnl This is enabled by default to allow the option of using OpenMP in dnl loadable modules. diff -r 286fe9352cd6 -r 9e7b2625e574 libinterp/octave-value/ov-java.cc --- a/libinterp/octave-value/ov-java.cc Thu Jul 02 15:06:36 2020 +0900 +++ b/libinterp/octave-value/ov-java.cc Fri Jun 26 18:44:35 2020 +0200 @@ -766,6 +766,9 @@ // Hard-coded options for the jvm. vm_args.add ("-Djava.class.path=" + initial_class_path ()); +#if defined (HAVE_BROKEN_PTHREAD_STACKSIZE) + vm_args.add ("-Djdk.lang.processReaperUseDefaultStackSize=true"); +#endif vm_args.add ("-Xrs"); // Additional options given by file java.opts. diff -r 286fe9352cd6 -r 9e7b2625e574 m4/acinclude.m4 --- a/m4/acinclude.m4 Thu Jul 02 15:06:36 2020 +0900 +++ b/m4/acinclude.m4 Fri Jun 26 18:44:35 2020 +0200 @@ -187,6 +187,74 @@ fi ]) dnl +dnl Check if pthread stack size accounts for thread-local storage. +dnl +dnl This program should succeed if the pthread library allocates memory +dnl for thread-local (__thread) variables independently of the +dnl requested thread stack size. +dnl +dnl It will fail if (as in the current version of glibc) the storage +dnl for thread-local variables is subtracted from the memory allocated +dnl for the thread stack. (This can cause problems for Java and for +dnl other libraries.) +dnl +dnl This bug is tracked in glibc at: +dnl https://sourceware.org/bugzilla/show_bug.cgi?id=11787 +dnl +AC_DEFUN([OCTAVE_CHECK_BROKEN_PTHREAD_STACKSIZE], [ + AC_CACHE_CHECK([whether pthread stack size does not account for thread-local storage], + [octave_cv_broken_pthread_stacksize], + [AC_LANG_PUSH(C) + AC_RUN_IFELSE([AC_LANG_PROGRAM([[ +#include +#include +#include + +static char __thread data[100 * 1024]; + +static void * threadfunc(void *arg) +{ + return data; +} + ]], [[ + pthread_attr_t attr; + pthread_t thread; + int errnum; + + pthread_attr_init (&attr); + errnum = pthread_attr_setstacksize (&attr, 64 * 1024); + if (errnum != 0) + { + fprintf (stderr, "pthread_attr_setstacksize: %s\n", strerror(errnum)); + return 1; + } + errnum = pthread_create (&thread, &attr, &threadfunc, NULL); + if (errnum != 0) + { + fprintf (stderr, "pthread_create: %s\n", strerror(errnum)); + return 1; + } + errnum = pthread_join (thread, NULL); + if (errnum != 0) + { + fprintf (stderr, "pthread_join: %s\n", strerror(errnum)); + return 1; + } + + pthread_attr_destroy (&attr); + return 0; + ]])], + octave_cv_broken_pthread_stacksize=no, + octave_cv_broken_pthread_stacksize=yes, + octave_cv_broken_pthread_stacksize=no) + AC_LANG_POP(C) + ]) + if test $octave_cv_broken_pthread_stacksize = yes; then + AC_DEFINE(HAVE_BROKEN_PTHREAD_STACKSIZE, 1, + [Define to 1 if pthread stack size does not account for thread-local storage.]) + fi +]) +dnl dnl Check whether CXSparse is version 2.2 or later dnl FIXME: This test uses a version number. It potentially could dnl be re-written to actually call a function, but is it worth it?