aboutsummaryrefslogtreecommitdiff
path: root/libjava
diff options
context:
space:
mode:
authorBryce McKinlay <bryce@albatross.co.nz>2000-12-30 12:18:39 +0000
committerBryce McKinlay <bryce@gcc.gnu.org>2000-12-30 12:18:39 +0000
commite301621d196adef738c6cb5f5f4ee8a17a4ab0c0 (patch)
tree45acacc07816160e269cf47dd6cdeccef9036f29 /libjava
parent4c2f5b4fd3e2b691c7a14a5860dae341d33455b3 (diff)
downloadgcc-e301621d196adef738c6cb5f5f4ee8a17a4ab0c0.zip
gcc-e301621d196adef738c6cb5f5f4ee8a17a4ab0c0.tar.gz
gcc-e301621d196adef738c6cb5f5f4ee8a17a4ab0c0.tar.bz2
For boehm-gc:
* configure.in: Rename THREADLIB to THREADLIBS. * Makefile.am (LINK): Add $(THREADLIBS) to libtool command line. This ensures that we link the correct version of the linuxthreads semaphore functions. * Makefile.in: Rebuilt. * configure: Rebuilt. * linux_thread.c (GC_thr_init, GC_suspend_handler): Add SIGABRT to the list of signals which are not blocked during suspend in the NO_SIGNALS case. For libjava: * Makefile.am (libgcj_la_LIBADD): Add $(THREADLIBS). This ensures that the correct versions of various linuxthreads functions get linked. * Makefile.in: Rebuilt. * java/lang/natThread.cc (finalize_native): New static function. Call _Jv_ThreadDestroyData. (initialize_native): Register finalizer for "data". * include/posix-threads.h (_Jv_ThreadInitData): New simpler prototype. (_Jv_ThreadDestroyData): New prototype. * include/win32-threads.h: Ditto. * include/no-threads.h: Ditto. * posix-threads.cc (_Jv_ThreadInitData): Implement new prototype. (_Jv_ThreadDestroyData): New function. Free native thread "data" and move mutex and condition variable destroy code from: (really_start): ...here. (_Jv_ThreadStart): Set PTHREAD_CREATE_DETACHED. * win32-threads.cc (_Jv_ThreadInitData): Implement new prototype. (_Jv_ThreadDestroyData): Implemented. * nogc.cc (_Jv_AllocObject): Use "void *" not "ptr_t". (_Jv_AllocArray): Ditto. From-SVN: r38557
Diffstat (limited to 'libjava')
-rw-r--r--libjava/ChangeLog22
-rw-r--r--libjava/include/no-threads.h9
-rw-r--r--libjava/include/posix-threads.h3
-rw-r--r--libjava/include/win32-threads.h3
-rw-r--r--libjava/java/lang/natThread.cc25
-rw-r--r--libjava/nogc.cc6
-rw-r--r--libjava/posix-threads.cc34
-rw-r--r--libjava/win32-threads.cc17
8 files changed, 82 insertions, 37 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index 2dcc45d..551c2e68 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,3 +1,25 @@
+2000-12-30 Bryce McKinlay <bryce@albatross.co.nz>
+
+ * Makefile.am (libgcj_la_LIBADD): Add $(THREADLIBS). This ensures that
+ the correct versions of various linuxthreads functions get linked.
+ * Makefile.in: Rebuilt.
+ * java/lang/natThread.cc (finalize_native): New static function. Call
+ _Jv_ThreadDestroyData.
+ (initialize_native): Register finalizer for "data".
+ * include/posix-threads.h (_Jv_ThreadInitData): New simpler prototype.
+ (_Jv_ThreadDestroyData): New prototype.
+ * include/win32-threads.h: Ditto.
+ * include/no-threads.h: Ditto.
+ * posix-threads.cc (_Jv_ThreadInitData): Implement new prototype.
+ (_Jv_ThreadDestroyData): New function. Free native thread "data" and
+ move mutex and condition variable destroy code from:
+ (really_start): ...here.
+ (_Jv_ThreadStart): Set PTHREAD_CREATE_DETACHED.
+ * win32-threads.cc (_Jv_ThreadInitData): Implement new prototype.
+ (_Jv_ThreadDestroyData): Implemented.
+ * nogc.cc (_Jv_AllocObject): Use "void *" not "ptr_t".
+ (_Jv_AllocArray): Ditto.
+
2000-12-27 Jeff Sturm <jeff.sturm@commerceone.com>
* java/sql/DriverManager.java (getConnection): Don't set user/password
diff --git a/libjava/include/no-threads.h b/libjava/include/no-threads.h
index e500184..69b6d43 100644
--- a/libjava/include/no-threads.h
+++ b/libjava/include/no-threads.h
@@ -102,10 +102,15 @@ _Jv_InitThreads (void)
{
}
+inline _Jv_Thread_t *
+_Jv_ThreadInitData (java::lang::Thread *)
+{
+ return NULL;
+}
+
inline void
-_Jv_ThreadInitData (_Jv_Thread_t **data, java::lang::Thread *)
+_Jv_ThreadDestroyData (_Jv_Thread_t *data)
{
- *data = NULL;
}
inline java::lang::Thread *
diff --git a/libjava/include/posix-threads.h b/libjava/include/posix-threads.h
index 5b1f075..75285ca 100644
--- a/libjava/include/posix-threads.h
+++ b/libjava/include/posix-threads.h
@@ -169,7 +169,8 @@ _Jv_MutexDestroy (_Jv_Mutex_t *mu)
void _Jv_InitThreads (void);
-void _Jv_ThreadInitData (_Jv_Thread_t **data, java::lang::Thread *thread);
+_Jv_Thread_t *_Jv_ThreadInitData (java::lang::Thread *thread);
+void _Jv_ThreadDestroyData (_Jv_Thread_t *data);
inline java::lang::Thread *
_Jv_ThreadCurrent (void)
diff --git a/libjava/include/win32-threads.h b/libjava/include/win32-threads.h
index 4938d5f..31b961b 100644
--- a/libjava/include/win32-threads.h
+++ b/libjava/include/win32-threads.h
@@ -97,7 +97,8 @@ _Jv_MutexUnlock (_Jv_Mutex_t *mu)
//
void _Jv_InitThreads (void);
-void _Jv_ThreadInitData (_Jv_Thread_t **data, java::lang::Thread *thread);
+_Jv_Thread_t *_Jv_ThreadInitData (java::lang::Thread *thread);
+void _Jv_ThreadDestroyData (_Jv_Thread_t *data);
inline java::lang::Thread *
_Jv_ThreadCurrent (void)
diff --git a/libjava/java/lang/natThread.cc b/libjava/java/lang/natThread.cc
index 2b9afb5..796713a 100644
--- a/libjava/java/lang/natThread.cc
+++ b/libjava/java/lang/natThread.cc
@@ -50,26 +50,39 @@ struct natThread
JNIEnv *jni_env;
};
+static void finalize_native (jobject ptr);
+
// This is called from the constructor to initialize the native side
// of the Thread.
void
java::lang::Thread::initialize_native (void)
{
- // FIXME: this must interact with the GC in some logical way. At
- // the very least we must register a finalizer to clean up. This
- // isn't easy to do. If the Thread object resurrects itself in its
- // own finalizer then we will need to reinitialize this structure at
- // any "interesting" point.
natThread *nt = (natThread *) _Jv_AllocBytes (sizeof (natThread));
+
+ // The native thread data is kept in a Object field, not a rawdata, so that
+ // the GC allocator can be used and a finalizer run after the thread becomes
+ // unreachable. Note that this relies on the GC's ability to finalize
+ // non-Java objects. FIXME?
data = reinterpret_cast<jobject> (nt);
+
+ // Register a finalizer to clean up the native thread resources.
+ _Jv_RegisterFinalizer (data, finalize_native);
+
_Jv_MutexInit (&nt->join_mutex);
_Jv_CondInit (&nt->join_cond);
- _Jv_ThreadInitData (&nt->thread, this);
+ nt->thread = _Jv_ThreadInitData (this);
// FIXME: if JNI_ENV is set we will want to free it. It is
// malloc()d.
nt->jni_env = NULL;
}
+static void
+finalize_native (jobject ptr)
+{
+ natThread *nt = (natThread *) ptr;
+ _Jv_ThreadDestroyData (nt->thread);
+}
+
jint
java::lang::Thread::countStackFrames (void)
{
diff --git a/libjava/nogc.cc b/libjava/nogc.cc
index b5bd6f3..0829671 100644
--- a/libjava/nogc.cc
+++ b/libjava/nogc.cc
@@ -1,4 +1,4 @@
-// nogc.cc - Code to implement no GC.
+// nogc.cc - Implement null garbage collector.
/* Copyright (C) 1998, 1999, 2000 Free Software Foundation
@@ -31,7 +31,7 @@ void *
_Jv_AllocObj (jsize size, jclass klass)
{
total += size;
- ptr_t obj = calloc (size, 1);
+ void *obj = calloc (size, 1);
*((_Jv_VTable **) obj) = klass->vtable;
return obj;
}
@@ -40,7 +40,7 @@ void *
_Jv_AllocArray (jsize size, jclass klass)
{
total += size;
- ptr_t obj = calloc (size, 1);
+ void *obj = calloc (size, 1);
*((_Jv_VTable **) obj) = klass->vtable;
return obj;
}
diff --git a/libjava/posix-threads.cc b/libjava/posix-threads.cc
index 2c7babb..2053843 100644
--- a/libjava/posix-threads.cc
+++ b/libjava/posix-threads.cc
@@ -147,7 +147,7 @@ _Jv_CondWait (_Jv_ConditionVariable_t *cv, _Jv_Mutex_t *mu,
else
r = pthread_cond_timedwait (&current->wait_cond, &current->wait_mutex,
&ts);
-
+
// In older glibc's (prior to 2.1.3), the cond_wait functions may
// spuriously wake up on a signal. Catch that here.
if (r != EINTR)
@@ -297,20 +297,25 @@ _Jv_InitThreads (void)
sigaction (INTR, &act, NULL);
}
-void
-_Jv_ThreadInitData (_Jv_Thread_t **data, java::lang::Thread *obj)
+_Jv_Thread_t *
+_Jv_ThreadInitData (java::lang::Thread *obj)
{
- _Jv_Thread_t *info = new _Jv_Thread_t;
- info->flags = 0;
- info->thread_obj = obj;
+ _Jv_Thread_t *data = new _Jv_Thread_t;
+ data->flags = 0;
+ data->thread_obj = obj;
- pthread_mutex_init (&info->wait_mutex, NULL);
- pthread_cond_init (&info->wait_cond, NULL);
+ pthread_mutex_init (&data->wait_mutex, NULL);
+ pthread_cond_init (&data->wait_cond, NULL);
- // FIXME register a finalizer for INFO here.
- // FIXME also must mark INFO somehow.
+ return data;
+}
- *data = info;
+void
+_Jv_ThreadDestroyData (_Jv_Thread_t *data)
+{
+ pthread_mutex_destroy (&data->wait_mutex);
+ pthread_cond_destroy (&data->wait_cond);
+ delete data;
}
void
@@ -352,12 +357,6 @@ really_start (void *x)
pthread_mutex_unlock (&daemon_mutex);
}
-#ifndef LINUX_THREADS
- // Clean up. These calls do nothing on Linux.
- pthread_mutex_destroy (&info->data->wait_mutex);
- pthread_cond_destroy (&info->data->wait_cond);
-#endif /* ! LINUX_THREADS */
-
return NULL;
}
@@ -377,6 +376,7 @@ _Jv_ThreadStart (java::lang::Thread *thread, _Jv_Thread_t *data,
pthread_attr_init (&attr);
pthread_attr_setschedparam (&attr, &param);
+ pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
// FIXME: handle marking the info object for GC.
info = (struct starter *) _Jv_AllocBytes (sizeof (struct starter));
diff --git a/libjava/win32-threads.cc b/libjava/win32-threads.cc
index 8da274f..29b6a72 100644
--- a/libjava/win32-threads.cc
+++ b/libjava/win32-threads.cc
@@ -123,16 +123,19 @@ _Jv_InitThreads (void)
non_daemon_count = 0;
}
-void
-_Jv_ThreadInitData (_Jv_Thread_t **data, java::lang::Thread *)
+_Jv_Thread_t *
+_Jv_ThreadInitData (java::lang::Thread *)
{
- _Jv_Thread_t *info = new _Jv_Thread_t;
- info->flags = 0;
+ _Jv_Thread_t *data = new _Jv_Thread_t;
+ data->flags = 0;
- // FIXME register a finalizer for INFO here.
- // FIXME also must mark INFO somehow.
+ return data;
+}
- *data = info;
+void
+_Jv_ThreadDestroyData (_Jv_Thread_t *data)
+{
+ delete data;
}
void