[fedora-java] RE: Thread registration work-around?

Anthony Green green at redhat.com
Wed Jan 4 11:35:01 UTC 2006


On Tue, 2006-01-03 at 16:46 -0800, Boehm, Hans wrote:
> As far as I can tell, this looks like a good (hopefully temporary!)
> workaround for this case.

Thanks Hans.

Andrew, could you please try this patched SRPM with the x86-64 Eclipse
to see if it fixes the problem?

http://people.redhat.com/green/java-1.4.2-gcj-compat-1.4.2.0-40jpp_56rh.1.1.src.rpm

Tom - here's my java-gcj-compat patch:


006-01-04  Anthony Green  <green at redhat.com>

	* Makefile.am (pr13212.so): Build pr13212.so.
	* pr13212.c: New file.
	* java.c (main): Set LD_PRELOAD.
	* configure.ac: Bump release number to 1.0.46.


Index: Makefile.am
===================================================================
RCS file: /cvs/rhug/java-gcj-compat/Makefile.am,v
retrieving revision 1.24
diff -u -r1.24 Makefile.am
--- Makefile.am	14 Nov 2005 20:58:56 -0000	1.24
+++ Makefile.am	4 Jan 2006 10:53:19 -0000
@@ -15,6 +15,9 @@
 $(tools_jar_class_files): %.class: %.java
 	$(JAVAC) -d . -I . $<
 
+pr13212.so: pr13212.c
+	$(GCJ_BIN_DIR)/gcc$(gcc_suffix) $(CFLAGS) -shared -o $@ $< -lgcj
+
 libjawt.so:
 	echo | $(GCJ_BIN_DIR)/gcc$(gcc_suffix) -shared -O2 -fpic -o libjawt.so -Wl,-soname,libjawt.so -xc - -lgcjawt
 
@@ -24,13 +27,14 @@
 java: java.c
 	$(GCJ_BIN_DIR)/gcc$(gcc_suffix) -DJAVA_HOME="\"$(JAVA_HOME_DIR)\"" -DARCH="\"$(CPU)\"" -DGCJ_BIN_DIR="\"$(GCJ_BIN_DIR)\"" -o $@ $<
 
-all-local: java libjawt.so
+all-local: java libjawt.so pr13212.so
 
 install-exec-local:
 	$(mkinstalldirs) $(DESTDIR)$(JRE_LIB_DIR)/$(CPU)
 	$(mkinstalldirs) $(DESTDIR)$(JRE_BIN_DIR)
 	$(mkinstalldirs) $(DESTDIR)$(SDK_BIN_DIR)
 	$(INSTALL) -m 755 libjawt.so $(DESTDIR)$(JRE_LIB_DIR)/$(CPU)/libjawt.so
+	$(INSTALL) -m 755 pr13212.so $(DESTDIR)$(JRE_LIB_DIR)/$(CPU)/pr13212.so
 	$(INSTALL) -m 755 java $(DESTDIR)$(JRE_BIN_DIR)/java
 	$(INSTALL) -m 755 java $(DESTDIR)$(SDK_BIN_DIR)/java
 
@@ -62,6 +66,7 @@
 
 uninstall-local:
 	rm -f $(DESTDIR)$(JRE_LIB_DIR)/$(CPU)/libjawt.so
+	rm -f $(DESTDIR)$(JRE_LIB_DIR)/$(CPU)/pr13212.so
 	rm -f $(DESTDIR)$(JRE_BIN_DIR)/java
 	rm -f $(DESTDIR)$(SDK_BIN_DIR)/java
 
@@ -71,6 +76,7 @@
 CLEANFILES = \
 	java \
 	libjawt.so \
+	pr13212.so \
 	$(tools_jar_class_files) \
 	tools.jar \
 	com/sun/tools/javac/Config.class
Index: java.c
===================================================================
RCS file: /cvs/rhug/java-gcj-compat/java.c,v
retrieving revision 1.1
diff -u -r1.1 java.c
--- java.c	7 Sep 2005 00:19:07 -0000	1.1
+++ java.c	4 Jan 2006 10:53:19 -0000
@@ -1,4 +1,4 @@
-/* java.c -- set LD_LIBRARY_PATH and exec gij
+/* java.c -- set LD_LIBRARY_PATH, LD_PRELOAD and exec gij
    Copyright (C) 2005  Red Hat
 
 This file is part of java-gcj-compat.
@@ -45,9 +45,42 @@
 {
   int error_code = 0;
   char *libpath = NULL;
+  char *preload = NULL;
+  char *newpreload = NULL;
   char *newpath = NULL;
   int newlen = 0;
 
+  preload = getenv ("LD_PRELOAD");
+  
+  if (preload && preload[0] != '\0')
+    {
+      newlen += strlen (preload);
+      // for the separating ' '
+      newlen += 1;
+    }
+
+  newlen += sizeof (JAVA_HOME) - 1;
+  newlen += sizeof ("/lib//pr13212.so") - 1;
+  newlen += sizeof (ARCH) - 1;
+
+  newpreload = (char *) malloc (newlen + 1);
+
+  if (newpreload != NULL)
+    {
+      if (preload && preload[0] != '\0')
+        snprintf (newpreload, newlen + 1,
+                  "%s/lib/%s/pr13212.so %s", JAVA_HOME, ARCH, preload);
+      else
+        snprintf (newpreload, newlen + 1, "%s/lib/%s/pr13212.so", JAVA_HOME, ARCH);
+    }
+
+  setenv ("LD_PRELOAD", newpreload, 1);
+
+  free (newpreload);
+
+
+  newlen = 0;
+
   libpath = getenv ("LD_LIBRARY_PATH");
 
   if (libpath && libpath[0] != '\0')
Index: pr13212.c
===================================================================
RCS file: pr13212.c
diff -N pr13212.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ pr13212.c	4 Jan 2006 10:53:19 -0000
@@ -0,0 +1,87 @@
+/* pr13212.c -- LD_PRELOAD this library to work-around GCC pr 13212.
+   Copyright (C) 2006  Red Hat, Inc.
+
+This file is part of java-gcj-compat.
+
+java-gcj-compat is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+java-gcj-compat is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with java-gcj-compat; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version.  */
+
+#define _GNU_SOURCE
+#include <dlfcn.h>
+#include <stdlib.h>
+#include <pthread.h>
+
+// A pointer to the real pthread_create
+
+static int (*pthread_create_) (pthread_t *__restrict __newthread,
+			       __const pthread_attr_t *__restrict __attr,
+			       void *(*__start_routine) (void *),
+			       void *__restrict __arg);
+
+
+// The Boehm collector's pthread_create wrapper.
+extern int GC_pthread_create (pthread_t *__restrict __newthread,
+			      __const pthread_attr_t *__restrict __attr,
+			      void *(*__start_routine) (void *),
+			      void *__restrict __arg);
+
+// The start routine used by the Boehm collector.  We'll use this to 
+// recognize pthread_create calls made by the collector's wrapper.
+extern void *GC_start_routine (void *);
+
+
+/* Force constr to execute prior to main().  */
+static void constr (void) __attribute__ ((constructor));
+
+static void
+constr (void)
+{
+  /* Get a pointer to the real pthread_create().  */
+  pthread_create_ = dlsym (RTLD_NEXT, "pthread_create");
+
+  if (pthread_create_ == NULL)
+    abort ();
+}
+
+/** Wrap the pthread_create function.  */
+int pthread_create (pthread_t *__restrict __newthread,
+		    __const pthread_attr_t *__restrict __attr,
+		    void *(*__start_routine) (void *),
+		    void *__restrict __arg)
+{
+  // Call the real pthread_create() if we're called from boehm's wrapper,
+  // and call boehm's wrapper otherwise.
+  if (__start_routine == GC_start_routine)
+    return pthread_create_ (__newthread, __attr, __start_routine, __arg);
+  else
+    return GC_pthread_create (__newthread, __attr, __start_routine, __arg);
+}
Index: configure.ac
===================================================================
RCS file: /cvs/rhug/java-gcj-compat/configure.ac,v
retrieving revision 1.49
diff -u -r1.49 configure.ac
--- configure.ac	16 Nov 2005 00:09:50 -0000	1.49
+++ configure.ac	4 Jan 2006 10:53:19 -0000
@@ -1,7 +1,7 @@
 dnl Process this file with autoconf to produce a configure script.
 
 AC_PREREQ(2.59)
-AC_INIT(java-gcj-compat, 1.0.45, fitzsim at redhat.com)
+AC_INIT(java-gcj-compat, 1.0.46, fitzsim at redhat.com)
 AM_INIT_AUTOMAKE(1.9.2)
 AC_CONFIG_SRCDIR(com/sun/tools/javac/Main.java)
 AC_CANONICAL_HOST





More information about the java-devel mailing list