Supporting pthreads in libjava on Tru64 UNIX
Rainer Orth
ro@TechFak.Uni-Bielefeld.DE
Fri Jul 4 17:20:00 GMT 2003
I've been working to support --enable-threads=posix on Tru64 UNIX. To
support gthr.h clients (like libstdc++-v3 or libobjc), I could dust off an
old patch of mine (to be posted separately), but libjava proves to be more
tricky:
While compilation went fine (apart from a compile failure on V4.0F, already
fixed), test results were horrible. I got many additional execution
failures, like this:
V4.0F:
Stack overflow: pid 17865, proc calls, addr 0x140129d18, pc 0x30000e2814c
or (V5.1):
Yellow Zone stack overflow, thread 2
To make things worse, especially V5.1 behaviour was completely erratic:
some tests work fine most of the time when run manually, but fail once in a
while, while others work most of the time. Investigating some tests under
gdb let them pass.
After some poking around, I found that boehm-gc is the culprit: if one
disables GC with GC_DONT_GC=1 in the environment, the tests run fine.
Looking into boehm-gc in the gcc tree, I found that (although some Tru64
UNIX pthread support was present) it is not currently enabled. I worked on
this for some time until I got the thing to compile, but gctest hangs in a
tight loop. So I choose to look for the latest release version and found
that gc6.2 has just been released a few days ago and already contains Tru64
UNIX pthread support.
It looks like now is a good time to import that into our tree. Any takers
or suggestions for this?
While compiling and testing gc6.2 with cc worked fine, I ran into a few
problems when trying gcc:
* Initially compilation failed due to redefinitions of pthread_create and
friends. It turns out that <pthread.h> doesn't detect that recent
versions of gcc support #pragma extern_prefix and resort to macro games.
The patch below uses the underlying (mangled) names when it detects that
this is the case. When pthread_support.c #undefs its wrappers, we must
reinstantiate the mangled names instead. The proper solution is to
fixinclude the header to avoid this. This is stuff for a separate patch.
* The __GNUC__ GC_test_and_set definition in include/private/gc_locks.h
doesn't compile on Tru64 UNIX since that (ECOFF) platform doesn't support
the (ELF) .section and .previous directives. Wrapping them in __ELF__
allows the stuff to compile.
Unfortunately, this isn't right since now gctest hangs in a tight loop in
GC_test_and_set. I have no idea how to fix this (or why those section
changing games are necessary in the first place). Any advice how to
proceed?
Rainer
-----------------------------------------------------------------------------
Rainer Orth, Faculty of Technology, Bielefeld University
===================================================================
RCS file: include/RCS/gc_pthread_redirects.h,v
retrieving revision 1.1
diff -up -r1.1 include/gc_pthread_redirects.h
--- include/gc_pthread_redirects.h 2003年05月29日 15:50:10 1.1
+++ include/gc_pthread_redirects.h 2003年07月04日 16:07:36
@@ -58,13 +58,20 @@
int GC_pthread_join(pthread_t thread, void **retval);
int GC_pthread_detach(pthread_t thread);
+#ifdef _PTHREAD_USE_PTDNAM_
# define pthread_create GC_pthread_create
-#ifndef GC_DARWIN_THREADS
-# define pthread_sigmask GC_pthread_sigmask
-#endif
# define pthread_join GC_pthread_join
# define pthread_detach GC_pthread_detach
+#else
+/* Tru64 UNIX <pthread.h> mangles the names of some POSIX thread functions, so
+ use them directly. */
+# define __pthread_create GC_pthread_create
+# define __pthread_join GC_pthread_join
+# define __pthread_detach GC_pthread_detach
+#endif
+
#ifndef GC_DARWIN_THREADS
+# define pthread_sigmask GC_pthread_sigmask
# define dlopen GC_dlopen
#endif
===================================================================
RCS file: include/private/RCS/gc_locks.h,v
retrieving revision 1.1
diff -up -r1.1 include/private/gc_locks.h
--- include/private/gc_locks.h 2003年05月31日 00:54:20 1.1
+++ include/private/gc_locks.h 2003年07月04日 16:17:31
@@ -182,9 +182,13 @@
" beq %0,3f\n"
" mb\n"
"2:\n"
+# ifdef __ELF__
".section .text2,\"ax\"\n"
+# endif
"3: br 1b\n"
+# ifdef __ELF__
".previous"
+# endif
:"=&r" (temp), "=m" (*addr), "=&r" (oldvalue)
:"Ir" (1), "m" (*addr)
:"memory");
===================================================================
RCS file: RCS/pthread_support.c,v
retrieving revision 1.1
diff -up -r1.1 pthread_support.c
--- pthread_support.c 2003年06月18日 23:10:38 1.1
+++ pthread_support.c 2003年07月04日 16:07:55
@@ -139,6 +139,12 @@
# endif
# undef pthread_join
# undef pthread_detach
+# ifndef _PTHREAD_USE_PTDNAM_
+/* Restore the original mangled names on Tru64 UNIX. */
+# define pthread_create __pthread_create
+# define pthread_join __pthread_join
+# define pthread_detach __pthread_detach
+# endif
#endif
void GC_thr_init();
More information about the Java
mailing list