This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Supporting pthreads in libjava on Tru64 UNIX


Boehm, Hans writes:

> Sorry about the delayed response, and thanks for the patches.

Not at all, instead I'm greatful for your thorough response and review.

> I'll hold off on applying them to my tree, since there are clearly still some outstanding issues with a few pieces.  If you decide not to pursue this further, let me know, and I'll put it on my list to fix this.

Indeed: even apart from having broken GC_test_and_set, it turned out that
the pthread.h name mangling was wrong as well.

> I believe that replacing the 
> 
> beq	%0,3f
> 
> by
> 
> beq	%0,1b
> 
> and just deleting the code in section text2 should work.  But my guess is that the original code is written in the more baroque way is that the processor predicts the branch correctly by default (forward branch predicted not taken, backward branch is probably predicted as taken in the absence of real information).  So this patch will involve a mild performance penalty and probably shouldn't be used unconditionally, i.e. on Linux.

Indeed, as Richard suggested as well.  I'll leave the original code inside
__ELF__, unless it can be proven that the performance penalty is neglegible.

In fact, with this change and the name mangling corrected (patch against
gc6.2 included below), gctest now works on both Tru64 UNIX V4.0F and V5.1.

> > 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();
> > 
> What's _PTHREAD_USE_PTDNAM_ ?  Shouldn't this also be testing explicitly that we're on Tru64 (still called OSF1 here)?

That part of the patch was bogus as well, as I discovered after
GC_test_and_set didn't loop any longer.

Here's the correct one.  Apart from the change discussed above, it has code
to cope with the following problem: Tru64 UNIX <pthread.h> (on both V4.0F
and V5.1) prefixes the external names of some pthread functions with __.
When Compaq C is in use, this is done via #pragma extern_prefix, so
user-level code is unaffected.  With non-cc compilers, #define's are used,
e.g.

#ifdef _PTHREAD_USE_MANGLED_NAMES_
# ifdef _PTHREAD_USE_PTDNAM_
#  pragma extern_prefix "__"
# else
#  define pthread_create __pthread_create
# endif
#endif

To avoid redefinition warnings from gc_pthread_redirects.h, those
definitions must be removed before redefining to their GC_ wrappers.
Likewise, after those definitions are #undef'ed in pthread_support.c, the
original definitions must be restored.

The patch below does this, both checking for _PTHREAD_USE_MANGLED_NAMES_
(which is an indication that Tru64 UNIX <pthread.h> is in use) and
!_PTHREAD_USE_PTDNAM_ (which means <pthread.h> has determined that macros
instead of #pragma extern_prefix must be used).

As mentioned above, with those changes, gc6.2 gctest works fine with gcc
3.1 and current mainline.

Since this macro hackery is ugly (and gcc 3.x supports #pragma
extern_prefix natively), a followup-patch to fully support
--enable-threads=posix on Tru64 UNIX in gcc will make sure (via
fixincludes) that _PTHREAD_USE_PTDNAM_ is defined for gcc as well, so this
won't be necessary in GCC 3.4.

After I had worked this out, I managed to backport the necessary changes to
support boehm-gc with --enable-threads=posix in mainline GCC.  I'll post
those changes as a separate patch.

	Rainer

-----------------------------------------------------------------------------
Rainer Orth, Faculty of Technology, Bielefeld University


Fri Jul 11 20:27:03 2003  Rainer Orth  <ro@TechFak.Uni-Bielefeld.DE>

	* include/private/gc_locks.h [THREADS && __GNUC__ && ALPHA]
	(GC_test_and_set): Only use ELF section switching if __ELF__.

	* include/gc_pthread_redirects.h [!GC_USE_LD_WRAP && GC_PTHREADS
	&& !GC_SOLARIS_PTHREADS]: Undef mangled pthreads on Tru64 UNIX if
	appropriate.
	* pthread_support.c [!GC_USE_LD_WRAP &&
	_PTHREAD_USE_MANGLED_NAMES_ && !_PTHREAD_USE_PTDNAM_]: Restore
	original Tru64 UNIX definitions if appropriate.

===================================================================
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/07 22:20:02
@@ -58,13 +58,21 @@
   int GC_pthread_join(pthread_t thread, void **retval);
   int GC_pthread_detach(pthread_t thread);
 
-# define pthread_create GC_pthread_create
-#ifndef GC_DARWIN_THREADS
-# define pthread_sigmask GC_pthread_sigmask
+#if defined(_PTHREAD_USE_MANGLED_NAMES_) && !defined(_PTHREAD_USE_PTDNAM_)
+/* Unless the compiler supports #pragma extern_prefix, the Tru64 UNIX
+   <pthread.h> redefines some POSIX thread functions to use mangled names.
+   If so, undef them before redefining. */
+# undef pthread_create
+# undef pthread_join
+# undef pthread_detach
 #endif
+
+# define pthread_create GC_pthread_create
 # define pthread_join GC_pthread_join
 # define pthread_detach GC_pthread_detach
+
 #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/07 22:26:50
@@ -179,12 +179,18 @@
                              "       bne %2,2f\n"
                              "       xor %0,%3,%0\n"
                              "       stl_c %0,%1\n"
+#	ifdef __ELF__
                              "       beq %0,3f\n"
+#	else
+                             "       beq %0,1b\n"
+#	endif
                              "       mb\n"
                              "2:\n"
+#	ifdef __ELF__
                              ".section .text2,\"ax\"\n"
                              "3:     br 1b\n"
                              ".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/07 22:06:10
@@ -139,6 +139,12 @@
 #   endif
 #   undef pthread_join
 #   undef pthread_detach
+#   if defined(_PTHREAD_USE_MANGLED_NAMES_) && !defined(_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();


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]