2005-09-27 Tom Tromey <tromey@redhat.com>
+ PR libgcj/23367:
+ * include/jvm.h (_Jv_FreeMethodCache): Declare.
+ * java/lang/natClass.cc (MCACHE_SIZE): Conditional on HAVE_TLS.
+ (struct _Jv_mcache): Likewise.
+ (method_cache): Likewise.
+ (_Jv_FindMethodInCache): Do nothing unless TLS is available.
+ (_Jv_AddMethodToCache): Likewise.
+ (_Jv_FreeMethodCache): New function.
+ * java/lang/natThread.cc (finish_): Call _Jv_FreeMethodCache.
+ * aclocal.m4, configure, include/config.h.in: Rebuilt.
+ * configure.ac: Invoke GCC_CHECK_TLS.
+
+2005-09-27 Tom Tromey <tromey@redhat.com>
+
* configure, Makefile.in: Rebuilt.
* sources.am: Rebuilt.
* scripts/makemake.tcl (emit_bc_rule): Special-case qt.
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
$(top_srcdir)/../config/depstand.m4 \
+ $(top_srcdir)/../config/enable.m4 \
$(top_srcdir)/../config/gxx-include-dir.m4 \
$(top_srcdir)/../config/iconv.m4 \
$(top_srcdir)/../config/lcmessage.m4 \
$(top_srcdir)/../config/lib-link.m4 \
$(top_srcdir)/../config/lib-prefix.m4 \
$(top_srcdir)/../config/no-executables.m4 \
- $(top_srcdir)/../libtool.m4 $(top_srcdir)/mingwld.m4 \
- $(top_srcdir)/pkg.m4 $(top_srcdir)/shlibpath.m4 \
- $(top_srcdir)/configure.ac
+ $(top_srcdir)/../config/tls.m4 $(top_srcdir)/../libtool.m4 \
+ $(top_srcdir)/mingwld.m4 $(top_srcdir)/pkg.m4 \
+ $(top_srcdir)/shlibpath.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \
m4_include([../config/acx.m4])
m4_include([../config/depstand.m4])
+m4_include([../config/enable.m4])
m4_include([../config/gxx-include-dir.m4])
m4_include([../config/iconv.m4])
m4_include([../config/lcmessage.m4])
m4_include([../config/lib-link.m4])
m4_include([../config/lib-prefix.m4])
m4_include([../config/no-executables.m4])
+m4_include([../config/tls.m4])
m4_include([../libtool.m4])
m4_include([mingwld.m4])
m4_include([pkg.m4])
--enable-gtk-cairo build the cairo Graphics2D implementation on GTK
--enable-java-gc=TYPE choose garbage collector (default is boehm)
--disable-rpath do not hardcode runtime library paths
+ _g_switchUse thread-local storage
+ [default=yes]
Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
case $host in
*-*-irix6*)
# Find out which ABI we are using.
- echo '#line 5587 "configure"' > conftest.$ac_ext
+ echo '#line 5589 "configure"' > conftest.$ac_ext
if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
(eval $ac_compile) 2>&5
ac_status=$?
:
else
cat > conftest.$ac_ext << EOF
-#line 6590 "configure"
+#line 6592 "configure"
struct S { ~S(); };
void bar();
void foo()
multilib_arg=
fi
+# See if we support thread-local storage.
+
+ # Check whether --enable-tls or --disable-tls was given.
+if test "${enable_tls+set}" = set; then
+ enableval="$enable_tls"
+
+ case "$enableval" in
+ yes|no) ;;
+ *) { { echo "$as_me:$LINENO: error: Argument to enable/disable tls must be yes or no" >&5
+echo "$as_me: error: Argument to enable/disable tls must be yes or no" >&2;}
+ { (exit 1); exit 1; }; } ;;
+ esac
+
+else
+ enable_tls=yes
+fi;
+
+ echo "$as_me:$LINENO: checking whether the target supports thread-local storage" >&5
+echo $ECHO_N "checking whether the target supports thread-local storage... $ECHO_C" >&6
+if test "${have_tls+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+
+ if test "$cross_compiling" = yes; then
+ cat >conftest.$ac_ext <<_ACEOF
+__thread int foo;
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -z "$ac_c_werror_flag"
+ || test ! -s conftest.err'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ have_tls=yes
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+have_tls=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+
+else
+ cat >conftest.$ac_ext <<_ACEOF
+__thread int a; int b; int main() { return a = b; }
+_ACEOF
+rm -f conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+ (eval $ac_link) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ save_LDFLAGS="$LDFLAGS"
+ LDFLAGS="-static $LDFLAGS"
+ if test "$cross_compiling" = yes; then
+ { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling
+See \`config.log' for more details." >&5
+echo "$as_me: error: cannot run test program while cross compiling
+See \`config.log' for more details." >&2;}
+ { (exit 1); exit 1; }; }
+else
+ cat >conftest.$ac_ext <<_ACEOF
+__thread int a; int b; int main() { return a = b; }
+_ACEOF
+rm -f conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+ (eval $ac_link) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ have_tls=yes
+else
+ echo "$as_me: program exited with status $ac_status" >&5
+echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+( exit $ac_status )
+have_tls=no
+fi
+rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+ LDFLAGS="$save_LDFLAGS"
+else
+ echo "$as_me: program exited with status $ac_status" >&5
+echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+( exit $ac_status )
+have_tls=no
+fi
+rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+fi
+echo "$as_me:$LINENO: result: $have_tls" >&5
+echo "${ECHO_T}$have_tls" >&6
+ if test "$enable_tls $have_tls" = "yes yes"; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_TLS 1
+_ACEOF
+
+ fi
here=`${PWDCMD-pwd}`
multilib_arg=
fi
+# See if we support thread-local storage.
+GCC_CHECK_TLS
here=`${PWDCMD-pwd}`
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
$(top_srcdir)/../config/depstand.m4 \
+ $(top_srcdir)/../config/enable.m4 \
$(top_srcdir)/../config/gxx-include-dir.m4 \
$(top_srcdir)/../config/iconv.m4 \
$(top_srcdir)/../config/lcmessage.m4 \
$(top_srcdir)/../config/lib-link.m4 \
$(top_srcdir)/../config/lib-prefix.m4 \
$(top_srcdir)/../config/no-executables.m4 \
- $(top_srcdir)/../libtool.m4 $(top_srcdir)/mingwld.m4 \
- $(top_srcdir)/pkg.m4 $(top_srcdir)/shlibpath.m4 \
- $(top_srcdir)/configure.ac
+ $(top_srcdir)/../config/tls.m4 $(top_srcdir)/../libtool.m4 \
+ $(top_srcdir)/mingwld.m4 $(top_srcdir)/pkg.m4 \
+ $(top_srcdir)/shlibpath.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
CONFIG_HEADER = $(top_builddir)/include/config.h libgcj-config.h
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
$(top_srcdir)/../config/depstand.m4 \
+ $(top_srcdir)/../config/enable.m4 \
$(top_srcdir)/../config/gxx-include-dir.m4 \
$(top_srcdir)/../config/iconv.m4 \
$(top_srcdir)/../config/lcmessage.m4 \
$(top_srcdir)/../config/lib-link.m4 \
$(top_srcdir)/../config/lib-prefix.m4 \
$(top_srcdir)/../config/no-executables.m4 \
- $(top_srcdir)/../libtool.m4 $(top_srcdir)/mingwld.m4 \
- $(top_srcdir)/pkg.m4 $(top_srcdir)/shlibpath.m4 \
- $(top_srcdir)/configure.ac
+ $(top_srcdir)/../config/tls.m4 $(top_srcdir)/../libtool.m4 \
+ $(top_srcdir)/mingwld.m4 $(top_srcdir)/pkg.m4 \
+ $(top_srcdir)/shlibpath.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
CONFIG_HEADER = config.h $(top_builddir)/gcj/libgcj-config.h
/* Define if global 'timezone' exists. */
#undef HAVE_TIMEZONE
+/* Define to 1 if the target supports thread-local storage. */
+#undef HAVE_TLS
+
/* Define to 1 if your `struct tm' has `tm_zone'. Deprecated, use
`HAVE_STRUCT_TM_TM_ZONE' instead. */
#undef HAVE_TM_ZONE
_Jv_GCSetMaximumHeapSize. */
void _Jv_SetMaximumHeapSize (const char *arg);
+/* Free the method cache, if one was allocated. This is only called
+ during thread deregistration. */
+void _Jv_FreeMethodCache ();
+
extern "C" void JvRunMain (jclass klass, int argc, const char **argv);
void _Jv_RunMain (jclass klass, const char *name, int argc, const char **argv,
bool is_jar);
return NULL;
}
+#ifdef HAVE_TLS
+
// NOTE: MCACHE_SIZE should be a power of 2 minus one.
-#define MCACHE_SIZE 1023
+#define MCACHE_SIZE 31
struct _Jv_mcache
{
_Jv_Method *method;
};
-static _Jv_mcache method_cache[MCACHE_SIZE + 1];
+static __thread _Jv_mcache *method_cache;
+#endif // HAVE_TLS
static void *
_Jv_FindMethodInCache (jclass klass,
_Jv_Utf8Const *name,
_Jv_Utf8Const *signature)
{
- int index = name->hash16 () & MCACHE_SIZE;
- _Jv_mcache *mc = method_cache + index;
- _Jv_Method *m = mc->method;
-
- if (mc->klass == klass
- && m != NULL // thread safe check
- && _Jv_equalUtf8Consts (m->name, name)
- && _Jv_equalUtf8Consts (m->signature, signature))
- return mc->method->ncode;
+#ifdef HAVE_TLS
+ _Jv_mcache *cache = method_cache;
+ if (cache)
+ {
+ int index = name->hash16 () & MCACHE_SIZE;
+ _Jv_mcache *mc = &cache[index];
+ _Jv_Method *m = mc->method;
+
+ if (mc->klass == klass
+ && _Jv_equalUtf8Consts (m->name, name)
+ && _Jv_equalUtf8Consts (m->signature, signature))
+ return mc->method->ncode;
+ }
+#endif // HAVE_TLS
return NULL;
}
static void
-_Jv_AddMethodToCache (jclass klass,
- _Jv_Method *method)
+_Jv_AddMethodToCache (jclass klass, _Jv_Method *method)
{
- _Jv_MonitorEnter (&java::lang::Class::class$);
-
- int index = method->name->hash16 () & MCACHE_SIZE;
-
- method_cache[index].method = method;
- method_cache[index].klass = klass;
+#ifdef HAVE_TLS
+ if (method_cache == NULL)
+ method_cache = (_Jv_mcache *) _Jv_MallocUnchecked((MCACHE_SIZE + 1)
+ * sizeof (_Jv_mcache));
+ // If the allocation failed, just keep going.
+ if (method_cache != NULL)
+ {
+ int index = method->name->hash16 () & MCACHE_SIZE;
+ method_cache[index].method = method;
+ method_cache[index].klass = klass;
+ }
+#endif // HAVE_TLS
+}
- _Jv_MonitorExit (&java::lang::Class::class$);
+// Free this thread's method cache. We explicitly manage this memory
+// as the GC does not yet know how to scan TLS on all platforms.
+void
+_Jv_FreeMethodCache ()
+{
+#ifdef HAVE_TLS
+ if (method_cache != NULL)
+ {
+ _Jv_Free(method_cache);
+ method_cache = NULL;
+ }
+#endif // HAVE_TLS
}
void *
#endif
group = NULL;
-
+
+ // If a method cache was created, free it.
+ _Jv_FreeMethodCache();
+
// Signal any threads that are waiting to join() us.
_Jv_MutexLock (&nt->join_mutex);
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
$(top_srcdir)/../config/depstand.m4 \
+ $(top_srcdir)/../config/enable.m4 \
$(top_srcdir)/../config/gxx-include-dir.m4 \
$(top_srcdir)/../config/iconv.m4 \
$(top_srcdir)/../config/lcmessage.m4 \
$(top_srcdir)/../config/lib-link.m4 \
$(top_srcdir)/../config/lib-prefix.m4 \
$(top_srcdir)/../config/no-executables.m4 \
- $(top_srcdir)/../libtool.m4 $(top_srcdir)/mingwld.m4 \
- $(top_srcdir)/pkg.m4 $(top_srcdir)/shlibpath.m4 \
- $(top_srcdir)/configure.ac
+ $(top_srcdir)/../config/tls.m4 $(top_srcdir)/../libtool.m4 \
+ $(top_srcdir)/mingwld.m4 $(top_srcdir)/pkg.m4 \
+ $(top_srcdir)/shlibpath.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
CONFIG_HEADER = $(top_builddir)/include/config.h \