gcc/libjava/java/lang/natThread.cc

443 lines
10 KiB
C++
Raw Normal View History

1999-04-07 16:42:40 +02:00
// natThread.cc - Native part of Thread class.
/* Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation
1999-04-07 16:42:40 +02:00
This file is part of libgcj.
This software is copyrighted work licensed under the terms of the
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details. */
#include <config.h>
#include <stdlib.h>
#include <gcj/cni.h>
1999-04-07 16:42:40 +02:00
#include <jvm.h>
#include <java-threads.h>
#include <gnu/gcj/RawDataManaged.h>
1999-04-07 16:42:40 +02:00
#include <java/lang/Thread.h>
#include <java/lang/ThreadGroup.h>
#include <java/lang/IllegalArgumentException.h>
#include <java/lang/UnsupportedOperationException.h>
1999-04-07 16:42:40 +02:00
#include <java/lang/IllegalThreadStateException.h>
#include <java/lang/InterruptedException.h>
#include <java/lang/NullPointerException.h>
natNativeThread.cc: New file. * gnu/gcj/jni/natNativeThread.cc: New file. * gnu/gcj/jni/NativeThread.java: New file. * java/lang/Thread.java (data): Now a RawData. * include/jvm.h (_Jv_GetCurrentJNIEnv, _Jv_SetCurrentJNIEnv): Declare. * Makefile.in: Rebuilt. * Makefile.am (java/lang/Thread.h): New target. (ordinary_java_source_files): Added NativeThread.java. (nat_source_files): Added natNativeThread.cc. * java/lang/natThread.cc: Include <jni.h> (struct natThread): Added `jni_env' field. (_Jv_GetCurrentJNIEnv): New function. (_Jv_SetCurrentJNIEnv): Likewise. (initialize_native): Initialize jni_env. Include RawData.h. * jni.cc (ThreadGroupClass): New define. (_Jv_JNI_InvokeFunctions): New structure. (JNI_GetCreatedJavaVMs): New function. (the_vm): New global. (JNI_GetDefaultJavaVMInitArgs): New function. Include NativeThread.h. (NativeThreadClass): New define. (_Jv_JNI_EnsureLocalCapacity): Return JNI_ERR, not -1. (_Jv_JNI_DestroyJavaVM): New function. (_Jv_JNI_AttachCurrentThread): New function. (_Jv_JNI_DetachCurrentThread): New function. (_Jv_JNI_GetEnv): New function. (JNI_CreateJavaVM): New function. (_Jv_JNI_GetJavaVM): New function. (_Jv_JNIFunctions): Added entry for GetJavaVM. * include/jni.h (JavaVMAttachArgs): New structure. (JNI_EDETACHED): New define. (JNI_EVERSION): Likewise. (JavaVM): Define properly. (struct JNIInvokeInterface): New structure. (class _Jv_JavaVM): New class. (JNI_OnLoad, JNI_OnUnload): Declare. (JNI_GetDefaultJavaVMInitArgs, JNI_CreateJavaVM, JNI_GetCreatedJavaVMs): Declare. (JavaVMInitArgs): New typedef. (JavaVMOption): Likewise. (JNI_ERR): New define. (JNI_OK): Likewise. From-SVN: r31901
2000-02-10 21:31:48 +01:00
#include <jni.h>
1999-04-07 16:42:40 +02:00
#ifdef ENABLE_JVMPI
#include <jvmpi.h>
#endif
1999-04-07 16:42:40 +02:00
// This structure is used to represent all the data the native side
// needs. An object of this type is assigned to the `data' member of
// the Thread class.
struct natThread
{
// These are used to interrupt sleep and join calls. We can share a
Makefile.in: New #defines and friends for Thread.h. * Makefile.in: New #defines and friends for Thread.h. * posix-threads.cc: (struct starter): Remove `object'. (_Jv_CondWait): Use interruptable condition variables and new recursive mutexes. New return codes on interrupt or non-ownership of mutex. (_Jv_CondNotify): Ditto. (_Jv_CondNotifyAll): Ditto. (_Jv_ThreadInterrupt): Set thread interrupt flag directly. Interrupt the target thread by signaling its wait condition. (_Jv_ThreadInitData): Set `thread_obj' in the thread data struct, not the starter struct. Initialize wait_mutex and wait_cond. (_Jv_MutexLock): New recursive mutex implementation. Moved from posix-threads.h. (_Jv_MutexUnlock): Ditto. (really_start): Set info->data->thread from pthread_self() to work around a race condition. Destroy wait_mutex and wait_cond when run() returns. * java/lang/Thread.java: (isInterrupted_): Renamed to overloaded `isInterrupted(boolean)'. Clear interrupted flag if clear_flag is set. startable_flag: New private field. (Thread): Initialize `startable_flag'. (toString): Check for null thread group. * java/lang/natThread.cc: (struct natThread): New fields `join_mutex', `join_cond'. Removed fields `joiner', `next'. (class locker): Removed. (initialize_native): Initialize `join_cond' and `join_mutex'. (interrupt): Now just calls _Jv_ThreadInterrupt(). (join): Simplified. Just wait on the target thread's join condition. (finish_): Remove join list code. Unset thread group. Signal potential joiners by notifying the dying threads join_cond. (start): Check for illegal restarts. * java/lang/natObject.cc: Check for return value of _Jv_CondWait and act appropriatly. * include/posix-threads.h: Remove all HAVE_RECURSIVE_MUTEX related #defines and #ifdefs. (struct _Jv_Thread_t): New fields `thread_obj', `wait_cond', `wait_mutex', `next'. (struct _Jv_ConditionVariable_t): Define as a struct instead of directly mapping to pthread_cond_t. (struct _Jv_Mutex_t): New recursive implementation. (_Jv_PthreadCheckMonitor): Reimplemented. Simple `owner' check. _Jv_HaveCondDestroy: Never define this for posix-threads. (_Jv_CondNotify): Remove inline implementation(s), prototype instead. (_Jv_CondNotifyAll): Ditto. (_Jv_MutexLock): Ditto. (_Jv_MutexUnlock): Ditto. (_Jv_MutexInit): Changed to reflect new mutex implementation. (_Jv_MutexDestroy): Ditto. (_Jv_CondDestroy): Removed. (_Jv_PthreadGetMutex): Removed. * include/win32-threads.h: (_Jv_CondNotify): Guess _JV_NOT_OWNER on an error. Add a FIXME about this. (_Jv_CondNotifyAll): Ditto. * win32-threads.cc: (_Jv_CondWait): Return 0 on a timeout. Guess _JV_NOT_OWNER on other errors. Add FIXME. From-SVN: r32773
2000-03-28 04:22:24 +02:00
// condition variable here since it only ever gets notified when the thread
// exits.
_Jv_Mutex_t join_mutex;
_Jv_ConditionVariable_t join_cond;
1999-04-07 16:42:40 +02:00
// This is private data for the thread system layer.
_Jv_Thread_t *thread;
natNativeThread.cc: New file. * gnu/gcj/jni/natNativeThread.cc: New file. * gnu/gcj/jni/NativeThread.java: New file. * java/lang/Thread.java (data): Now a RawData. * include/jvm.h (_Jv_GetCurrentJNIEnv, _Jv_SetCurrentJNIEnv): Declare. * Makefile.in: Rebuilt. * Makefile.am (java/lang/Thread.h): New target. (ordinary_java_source_files): Added NativeThread.java. (nat_source_files): Added natNativeThread.cc. * java/lang/natThread.cc: Include <jni.h> (struct natThread): Added `jni_env' field. (_Jv_GetCurrentJNIEnv): New function. (_Jv_SetCurrentJNIEnv): Likewise. (initialize_native): Initialize jni_env. Include RawData.h. * jni.cc (ThreadGroupClass): New define. (_Jv_JNI_InvokeFunctions): New structure. (JNI_GetCreatedJavaVMs): New function. (the_vm): New global. (JNI_GetDefaultJavaVMInitArgs): New function. Include NativeThread.h. (NativeThreadClass): New define. (_Jv_JNI_EnsureLocalCapacity): Return JNI_ERR, not -1. (_Jv_JNI_DestroyJavaVM): New function. (_Jv_JNI_AttachCurrentThread): New function. (_Jv_JNI_DetachCurrentThread): New function. (_Jv_JNI_GetEnv): New function. (JNI_CreateJavaVM): New function. (_Jv_JNI_GetJavaVM): New function. (_Jv_JNIFunctions): Added entry for GetJavaVM. * include/jni.h (JavaVMAttachArgs): New structure. (JNI_EDETACHED): New define. (JNI_EVERSION): Likewise. (JavaVM): Define properly. (struct JNIInvokeInterface): New structure. (class _Jv_JavaVM): New class. (JNI_OnLoad, JNI_OnUnload): Declare. (JNI_GetDefaultJavaVMInitArgs, JNI_CreateJavaVM, JNI_GetCreatedJavaVMs): Declare. (JavaVMInitArgs): New typedef. (JavaVMOption): Likewise. (JNI_ERR): New define. (JNI_OK): Likewise. From-SVN: r31901
2000-02-10 21:31:48 +01:00
// Each thread has its own JNI object.
JNIEnv *jni_env;
};
static void finalize_native (jobject ptr);
1999-04-07 16:42:40 +02:00
// This is called from the constructor to initialize the native side
// of the Thread.
void
java::lang::Thread::initialize_native (void)
{
natThread *nt = (natThread *) _Jv_AllocBytes (sizeof (natThread));
data = (gnu::gcj::RawDataManaged *) nt;
// Register a finalizer to clean up the native thread resources.
_Jv_RegisterFinalizer (data, finalize_native);
Makefile.in: New #defines and friends for Thread.h. * Makefile.in: New #defines and friends for Thread.h. * posix-threads.cc: (struct starter): Remove `object'. (_Jv_CondWait): Use interruptable condition variables and new recursive mutexes. New return codes on interrupt or non-ownership of mutex. (_Jv_CondNotify): Ditto. (_Jv_CondNotifyAll): Ditto. (_Jv_ThreadInterrupt): Set thread interrupt flag directly. Interrupt the target thread by signaling its wait condition. (_Jv_ThreadInitData): Set `thread_obj' in the thread data struct, not the starter struct. Initialize wait_mutex and wait_cond. (_Jv_MutexLock): New recursive mutex implementation. Moved from posix-threads.h. (_Jv_MutexUnlock): Ditto. (really_start): Set info->data->thread from pthread_self() to work around a race condition. Destroy wait_mutex and wait_cond when run() returns. * java/lang/Thread.java: (isInterrupted_): Renamed to overloaded `isInterrupted(boolean)'. Clear interrupted flag if clear_flag is set. startable_flag: New private field. (Thread): Initialize `startable_flag'. (toString): Check for null thread group. * java/lang/natThread.cc: (struct natThread): New fields `join_mutex', `join_cond'. Removed fields `joiner', `next'. (class locker): Removed. (initialize_native): Initialize `join_cond' and `join_mutex'. (interrupt): Now just calls _Jv_ThreadInterrupt(). (join): Simplified. Just wait on the target thread's join condition. (finish_): Remove join list code. Unset thread group. Signal potential joiners by notifying the dying threads join_cond. (start): Check for illegal restarts. * java/lang/natObject.cc: Check for return value of _Jv_CondWait and act appropriatly. * include/posix-threads.h: Remove all HAVE_RECURSIVE_MUTEX related #defines and #ifdefs. (struct _Jv_Thread_t): New fields `thread_obj', `wait_cond', `wait_mutex', `next'. (struct _Jv_ConditionVariable_t): Define as a struct instead of directly mapping to pthread_cond_t. (struct _Jv_Mutex_t): New recursive implementation. (_Jv_PthreadCheckMonitor): Reimplemented. Simple `owner' check. _Jv_HaveCondDestroy: Never define this for posix-threads. (_Jv_CondNotify): Remove inline implementation(s), prototype instead. (_Jv_CondNotifyAll): Ditto. (_Jv_MutexLock): Ditto. (_Jv_MutexUnlock): Ditto. (_Jv_MutexInit): Changed to reflect new mutex implementation. (_Jv_MutexDestroy): Ditto. (_Jv_CondDestroy): Removed. (_Jv_PthreadGetMutex): Removed. * include/win32-threads.h: (_Jv_CondNotify): Guess _JV_NOT_OWNER on an error. Add a FIXME about this. (_Jv_CondNotifyAll): Ditto. * win32-threads.cc: (_Jv_CondWait): Return 0 on a timeout. Guess _JV_NOT_OWNER on other errors. Add FIXME. From-SVN: r32773
2000-03-28 04:22:24 +02:00
_Jv_MutexInit (&nt->join_mutex);
_Jv_CondInit (&nt->join_cond);
nt->thread = _Jv_ThreadInitData (this);
natNativeThread.cc: New file. * gnu/gcj/jni/natNativeThread.cc: New file. * gnu/gcj/jni/NativeThread.java: New file. * java/lang/Thread.java (data): Now a RawData. * include/jvm.h (_Jv_GetCurrentJNIEnv, _Jv_SetCurrentJNIEnv): Declare. * Makefile.in: Rebuilt. * Makefile.am (java/lang/Thread.h): New target. (ordinary_java_source_files): Added NativeThread.java. (nat_source_files): Added natNativeThread.cc. * java/lang/natThread.cc: Include <jni.h> (struct natThread): Added `jni_env' field. (_Jv_GetCurrentJNIEnv): New function. (_Jv_SetCurrentJNIEnv): Likewise. (initialize_native): Initialize jni_env. Include RawData.h. * jni.cc (ThreadGroupClass): New define. (_Jv_JNI_InvokeFunctions): New structure. (JNI_GetCreatedJavaVMs): New function. (the_vm): New global. (JNI_GetDefaultJavaVMInitArgs): New function. Include NativeThread.h. (NativeThreadClass): New define. (_Jv_JNI_EnsureLocalCapacity): Return JNI_ERR, not -1. (_Jv_JNI_DestroyJavaVM): New function. (_Jv_JNI_AttachCurrentThread): New function. (_Jv_JNI_DetachCurrentThread): New function. (_Jv_JNI_GetEnv): New function. (JNI_CreateJavaVM): New function. (_Jv_JNI_GetJavaVM): New function. (_Jv_JNIFunctions): Added entry for GetJavaVM. * include/jni.h (JavaVMAttachArgs): New structure. (JNI_EDETACHED): New define. (JNI_EVERSION): Likewise. (JavaVM): Define properly. (struct JNIInvokeInterface): New structure. (class _Jv_JavaVM): New class. (JNI_OnLoad, JNI_OnUnload): Declare. (JNI_GetDefaultJavaVMInitArgs, JNI_CreateJavaVM, JNI_GetCreatedJavaVMs): Declare. (JavaVMInitArgs): New typedef. (JavaVMOption): Likewise. (JNI_ERR): New define. (JNI_OK): Likewise. From-SVN: r31901
2000-02-10 21:31:48 +01:00
// FIXME: if JNI_ENV is set we will want to free it. It is
// malloc()d.
nt->jni_env = NULL;
1999-04-07 16:42:40 +02:00
}
static void
finalize_native (jobject ptr)
{
natThread *nt = (natThread *) ptr;
_Jv_ThreadDestroyData (nt->thread);
#ifdef _Jv_HaveCondDestroy
_Jv_CondDestroy (&nt->join_cond);
#endif
#ifdef _Jv_HaveMutexDestroy
_Jv_MutexDestroy (&nt->join_mutex);
#endif
}
1999-04-07 16:42:40 +02:00
jint
java::lang::Thread::countStackFrames (void)
{
// NOTE: This is deprecated in JDK 1.2.
throw new UnsupportedOperationException
(JvNewStringLatin1 ("Thread.countStackFrames unimplemented"));
1999-04-07 16:42:40 +02:00
return 0;
}
java::lang::Thread *
java::lang::Thread::currentThread (void)
{
return _Jv_ThreadCurrent ();
}
jboolean
java::lang::Thread::holdsLock (jobject obj)
{
if (!obj)
throw new NullPointerException;
return !_Jv_ObjectCheckMonitor (obj);
}
1999-04-07 16:42:40 +02:00
void
java::lang::Thread::interrupt (void)
{
natThread *nt = (natThread *) data;
_Jv_ThreadInterrupt (nt->thread);
}
void
java::lang::Thread::join (jlong millis, jint nanos)
{
if (millis < 0 || nanos < 0 || nanos > 999999)
throw new IllegalArgumentException;
1999-04-07 16:42:40 +02:00
Thread *current = currentThread ();
Makefile.in: New #defines and friends for Thread.h. * Makefile.in: New #defines and friends for Thread.h. * posix-threads.cc: (struct starter): Remove `object'. (_Jv_CondWait): Use interruptable condition variables and new recursive mutexes. New return codes on interrupt or non-ownership of mutex. (_Jv_CondNotify): Ditto. (_Jv_CondNotifyAll): Ditto. (_Jv_ThreadInterrupt): Set thread interrupt flag directly. Interrupt the target thread by signaling its wait condition. (_Jv_ThreadInitData): Set `thread_obj' in the thread data struct, not the starter struct. Initialize wait_mutex and wait_cond. (_Jv_MutexLock): New recursive mutex implementation. Moved from posix-threads.h. (_Jv_MutexUnlock): Ditto. (really_start): Set info->data->thread from pthread_self() to work around a race condition. Destroy wait_mutex and wait_cond when run() returns. * java/lang/Thread.java: (isInterrupted_): Renamed to overloaded `isInterrupted(boolean)'. Clear interrupted flag if clear_flag is set. startable_flag: New private field. (Thread): Initialize `startable_flag'. (toString): Check for null thread group. * java/lang/natThread.cc: (struct natThread): New fields `join_mutex', `join_cond'. Removed fields `joiner', `next'. (class locker): Removed. (initialize_native): Initialize `join_cond' and `join_mutex'. (interrupt): Now just calls _Jv_ThreadInterrupt(). (join): Simplified. Just wait on the target thread's join condition. (finish_): Remove join list code. Unset thread group. Signal potential joiners by notifying the dying threads join_cond. (start): Check for illegal restarts. * java/lang/natObject.cc: Check for return value of _Jv_CondWait and act appropriatly. * include/posix-threads.h: Remove all HAVE_RECURSIVE_MUTEX related #defines and #ifdefs. (struct _Jv_Thread_t): New fields `thread_obj', `wait_cond', `wait_mutex', `next'. (struct _Jv_ConditionVariable_t): Define as a struct instead of directly mapping to pthread_cond_t. (struct _Jv_Mutex_t): New recursive implementation. (_Jv_PthreadCheckMonitor): Reimplemented. Simple `owner' check. _Jv_HaveCondDestroy: Never define this for posix-threads. (_Jv_CondNotify): Remove inline implementation(s), prototype instead. (_Jv_CondNotifyAll): Ditto. (_Jv_MutexLock): Ditto. (_Jv_MutexUnlock): Ditto. (_Jv_MutexInit): Changed to reflect new mutex implementation. (_Jv_MutexDestroy): Ditto. (_Jv_CondDestroy): Removed. (_Jv_PthreadGetMutex): Removed. * include/win32-threads.h: (_Jv_CondNotify): Guess _JV_NOT_OWNER on an error. Add a FIXME about this. (_Jv_CondNotifyAll): Ditto. * win32-threads.cc: (_Jv_CondWait): Return 0 on a timeout. Guess _JV_NOT_OWNER on other errors. Add FIXME. From-SVN: r32773
2000-03-28 04:22:24 +02:00
// Here `NT' is the native structure for the thread we are trying to join.
1999-04-07 16:42:40 +02:00
natThread *nt = (natThread *) data;
// Now wait for: (1) an interrupt, (2) the thread to exit, or (3)
Makefile.in: New #defines and friends for Thread.h. * Makefile.in: New #defines and friends for Thread.h. * posix-threads.cc: (struct starter): Remove `object'. (_Jv_CondWait): Use interruptable condition variables and new recursive mutexes. New return codes on interrupt or non-ownership of mutex. (_Jv_CondNotify): Ditto. (_Jv_CondNotifyAll): Ditto. (_Jv_ThreadInterrupt): Set thread interrupt flag directly. Interrupt the target thread by signaling its wait condition. (_Jv_ThreadInitData): Set `thread_obj' in the thread data struct, not the starter struct. Initialize wait_mutex and wait_cond. (_Jv_MutexLock): New recursive mutex implementation. Moved from posix-threads.h. (_Jv_MutexUnlock): Ditto. (really_start): Set info->data->thread from pthread_self() to work around a race condition. Destroy wait_mutex and wait_cond when run() returns. * java/lang/Thread.java: (isInterrupted_): Renamed to overloaded `isInterrupted(boolean)'. Clear interrupted flag if clear_flag is set. startable_flag: New private field. (Thread): Initialize `startable_flag'. (toString): Check for null thread group. * java/lang/natThread.cc: (struct natThread): New fields `join_mutex', `join_cond'. Removed fields `joiner', `next'. (class locker): Removed. (initialize_native): Initialize `join_cond' and `join_mutex'. (interrupt): Now just calls _Jv_ThreadInterrupt(). (join): Simplified. Just wait on the target thread's join condition. (finish_): Remove join list code. Unset thread group. Signal potential joiners by notifying the dying threads join_cond. (start): Check for illegal restarts. * java/lang/natObject.cc: Check for return value of _Jv_CondWait and act appropriatly. * include/posix-threads.h: Remove all HAVE_RECURSIVE_MUTEX related #defines and #ifdefs. (struct _Jv_Thread_t): New fields `thread_obj', `wait_cond', `wait_mutex', `next'. (struct _Jv_ConditionVariable_t): Define as a struct instead of directly mapping to pthread_cond_t. (struct _Jv_Mutex_t): New recursive implementation. (_Jv_PthreadCheckMonitor): Reimplemented. Simple `owner' check. _Jv_HaveCondDestroy: Never define this for posix-threads. (_Jv_CondNotify): Remove inline implementation(s), prototype instead. (_Jv_CondNotifyAll): Ditto. (_Jv_MutexLock): Ditto. (_Jv_MutexUnlock): Ditto. (_Jv_MutexInit): Changed to reflect new mutex implementation. (_Jv_MutexDestroy): Ditto. (_Jv_CondDestroy): Removed. (_Jv_PthreadGetMutex): Removed. * include/win32-threads.h: (_Jv_CondNotify): Guess _JV_NOT_OWNER on an error. Add a FIXME about this. (_Jv_CondNotifyAll): Ditto. * win32-threads.cc: (_Jv_CondWait): Return 0 on a timeout. Guess _JV_NOT_OWNER on other errors. Add FIXME. From-SVN: r32773
2000-03-28 04:22:24 +02:00
// the timeout to occur.
_Jv_MutexLock (&nt->join_mutex);
if (! isAlive ())
1999-04-07 16:42:40 +02:00
{
Makefile.in: New #defines and friends for Thread.h. * Makefile.in: New #defines and friends for Thread.h. * posix-threads.cc: (struct starter): Remove `object'. (_Jv_CondWait): Use interruptable condition variables and new recursive mutexes. New return codes on interrupt or non-ownership of mutex. (_Jv_CondNotify): Ditto. (_Jv_CondNotifyAll): Ditto. (_Jv_ThreadInterrupt): Set thread interrupt flag directly. Interrupt the target thread by signaling its wait condition. (_Jv_ThreadInitData): Set `thread_obj' in the thread data struct, not the starter struct. Initialize wait_mutex and wait_cond. (_Jv_MutexLock): New recursive mutex implementation. Moved from posix-threads.h. (_Jv_MutexUnlock): Ditto. (really_start): Set info->data->thread from pthread_self() to work around a race condition. Destroy wait_mutex and wait_cond when run() returns. * java/lang/Thread.java: (isInterrupted_): Renamed to overloaded `isInterrupted(boolean)'. Clear interrupted flag if clear_flag is set. startable_flag: New private field. (Thread): Initialize `startable_flag'. (toString): Check for null thread group. * java/lang/natThread.cc: (struct natThread): New fields `join_mutex', `join_cond'. Removed fields `joiner', `next'. (class locker): Removed. (initialize_native): Initialize `join_cond' and `join_mutex'. (interrupt): Now just calls _Jv_ThreadInterrupt(). (join): Simplified. Just wait on the target thread's join condition. (finish_): Remove join list code. Unset thread group. Signal potential joiners by notifying the dying threads join_cond. (start): Check for illegal restarts. * java/lang/natObject.cc: Check for return value of _Jv_CondWait and act appropriatly. * include/posix-threads.h: Remove all HAVE_RECURSIVE_MUTEX related #defines and #ifdefs. (struct _Jv_Thread_t): New fields `thread_obj', `wait_cond', `wait_mutex', `next'. (struct _Jv_ConditionVariable_t): Define as a struct instead of directly mapping to pthread_cond_t. (struct _Jv_Mutex_t): New recursive implementation. (_Jv_PthreadCheckMonitor): Reimplemented. Simple `owner' check. _Jv_HaveCondDestroy: Never define this for posix-threads. (_Jv_CondNotify): Remove inline implementation(s), prototype instead. (_Jv_CondNotifyAll): Ditto. (_Jv_MutexLock): Ditto. (_Jv_MutexUnlock): Ditto. (_Jv_MutexInit): Changed to reflect new mutex implementation. (_Jv_MutexDestroy): Ditto. (_Jv_CondDestroy): Removed. (_Jv_PthreadGetMutex): Removed. * include/win32-threads.h: (_Jv_CondNotify): Guess _JV_NOT_OWNER on an error. Add a FIXME about this. (_Jv_CondNotifyAll): Ditto. * win32-threads.cc: (_Jv_CondWait): Return 0 on a timeout. Guess _JV_NOT_OWNER on other errors. Add FIXME. From-SVN: r32773
2000-03-28 04:22:24 +02:00
_Jv_MutexUnlock (&nt->join_mutex);
return;
1999-04-07 16:42:40 +02:00
}
Makefile.in: New #defines and friends for Thread.h. * Makefile.in: New #defines and friends for Thread.h. * posix-threads.cc: (struct starter): Remove `object'. (_Jv_CondWait): Use interruptable condition variables and new recursive mutexes. New return codes on interrupt or non-ownership of mutex. (_Jv_CondNotify): Ditto. (_Jv_CondNotifyAll): Ditto. (_Jv_ThreadInterrupt): Set thread interrupt flag directly. Interrupt the target thread by signaling its wait condition. (_Jv_ThreadInitData): Set `thread_obj' in the thread data struct, not the starter struct. Initialize wait_mutex and wait_cond. (_Jv_MutexLock): New recursive mutex implementation. Moved from posix-threads.h. (_Jv_MutexUnlock): Ditto. (really_start): Set info->data->thread from pthread_self() to work around a race condition. Destroy wait_mutex and wait_cond when run() returns. * java/lang/Thread.java: (isInterrupted_): Renamed to overloaded `isInterrupted(boolean)'. Clear interrupted flag if clear_flag is set. startable_flag: New private field. (Thread): Initialize `startable_flag'. (toString): Check for null thread group. * java/lang/natThread.cc: (struct natThread): New fields `join_mutex', `join_cond'. Removed fields `joiner', `next'. (class locker): Removed. (initialize_native): Initialize `join_cond' and `join_mutex'. (interrupt): Now just calls _Jv_ThreadInterrupt(). (join): Simplified. Just wait on the target thread's join condition. (finish_): Remove join list code. Unset thread group. Signal potential joiners by notifying the dying threads join_cond. (start): Check for illegal restarts. * java/lang/natObject.cc: Check for return value of _Jv_CondWait and act appropriatly. * include/posix-threads.h: Remove all HAVE_RECURSIVE_MUTEX related #defines and #ifdefs. (struct _Jv_Thread_t): New fields `thread_obj', `wait_cond', `wait_mutex', `next'. (struct _Jv_ConditionVariable_t): Define as a struct instead of directly mapping to pthread_cond_t. (struct _Jv_Mutex_t): New recursive implementation. (_Jv_PthreadCheckMonitor): Reimplemented. Simple `owner' check. _Jv_HaveCondDestroy: Never define this for posix-threads. (_Jv_CondNotify): Remove inline implementation(s), prototype instead. (_Jv_CondNotifyAll): Ditto. (_Jv_MutexLock): Ditto. (_Jv_MutexUnlock): Ditto. (_Jv_MutexInit): Changed to reflect new mutex implementation. (_Jv_MutexDestroy): Ditto. (_Jv_CondDestroy): Removed. (_Jv_PthreadGetMutex): Removed. * include/win32-threads.h: (_Jv_CondNotify): Guess _JV_NOT_OWNER on an error. Add a FIXME about this. (_Jv_CondNotifyAll): Ditto. * win32-threads.cc: (_Jv_CondWait): Return 0 on a timeout. Guess _JV_NOT_OWNER on other errors. Add FIXME. From-SVN: r32773
2000-03-28 04:22:24 +02:00
_Jv_CondWait (&nt->join_cond, &nt->join_mutex, millis, nanos);
_Jv_MutexUnlock (&nt->join_mutex);
1999-04-07 16:42:40 +02:00
Makefile.in: New #defines and friends for Thread.h. * Makefile.in: New #defines and friends for Thread.h. * posix-threads.cc: (struct starter): Remove `object'. (_Jv_CondWait): Use interruptable condition variables and new recursive mutexes. New return codes on interrupt or non-ownership of mutex. (_Jv_CondNotify): Ditto. (_Jv_CondNotifyAll): Ditto. (_Jv_ThreadInterrupt): Set thread interrupt flag directly. Interrupt the target thread by signaling its wait condition. (_Jv_ThreadInitData): Set `thread_obj' in the thread data struct, not the starter struct. Initialize wait_mutex and wait_cond. (_Jv_MutexLock): New recursive mutex implementation. Moved from posix-threads.h. (_Jv_MutexUnlock): Ditto. (really_start): Set info->data->thread from pthread_self() to work around a race condition. Destroy wait_mutex and wait_cond when run() returns. * java/lang/Thread.java: (isInterrupted_): Renamed to overloaded `isInterrupted(boolean)'. Clear interrupted flag if clear_flag is set. startable_flag: New private field. (Thread): Initialize `startable_flag'. (toString): Check for null thread group. * java/lang/natThread.cc: (struct natThread): New fields `join_mutex', `join_cond'. Removed fields `joiner', `next'. (class locker): Removed. (initialize_native): Initialize `join_cond' and `join_mutex'. (interrupt): Now just calls _Jv_ThreadInterrupt(). (join): Simplified. Just wait on the target thread's join condition. (finish_): Remove join list code. Unset thread group. Signal potential joiners by notifying the dying threads join_cond. (start): Check for illegal restarts. * java/lang/natObject.cc: Check for return value of _Jv_CondWait and act appropriatly. * include/posix-threads.h: Remove all HAVE_RECURSIVE_MUTEX related #defines and #ifdefs. (struct _Jv_Thread_t): New fields `thread_obj', `wait_cond', `wait_mutex', `next'. (struct _Jv_ConditionVariable_t): Define as a struct instead of directly mapping to pthread_cond_t. (struct _Jv_Mutex_t): New recursive implementation. (_Jv_PthreadCheckMonitor): Reimplemented. Simple `owner' check. _Jv_HaveCondDestroy: Never define this for posix-threads. (_Jv_CondNotify): Remove inline implementation(s), prototype instead. (_Jv_CondNotifyAll): Ditto. (_Jv_MutexLock): Ditto. (_Jv_MutexUnlock): Ditto. (_Jv_MutexInit): Changed to reflect new mutex implementation. (_Jv_MutexDestroy): Ditto. (_Jv_CondDestroy): Removed. (_Jv_PthreadGetMutex): Removed. * include/win32-threads.h: (_Jv_CondNotify): Guess _JV_NOT_OWNER on an error. Add a FIXME about this. (_Jv_CondNotifyAll): Ditto. * win32-threads.cc: (_Jv_CondWait): Return 0 on a timeout. Guess _JV_NOT_OWNER on other errors. Add FIXME. From-SVN: r32773
2000-03-28 04:22:24 +02:00
if (current->isInterrupted (true))
throw new InterruptedException;
1999-04-07 16:42:40 +02:00
}
void
java::lang::Thread::resume (void)
{
checkAccess ();
throw new UnsupportedOperationException
(JvNewStringLatin1 ("Thread.resume unimplemented"));
1999-04-07 16:42:40 +02:00
}
void
java::lang::Thread::setPriority (jint newPriority)
{
checkAccess ();
if (newPriority < MIN_PRIORITY || newPriority > MAX_PRIORITY)
throw new IllegalArgumentException;
1999-04-07 16:42:40 +02:00
jint gmax = group->getMaxPriority();
if (newPriority > gmax)
newPriority = gmax;
priority = newPriority;
natThread *nt = (natThread *) data;
_Jv_ThreadSetPriority (nt->thread, priority);
}
void
java::lang::Thread::sleep (jlong millis, jint nanos)
{
if (millis < 0 || nanos < 0 || nanos > 999999)
throw new IllegalArgumentException;
1999-04-07 16:42:40 +02:00
if (millis == 0 && nanos == 0)
++nanos;
1999-04-07 16:42:40 +02:00
Thread *current = currentThread ();
// We use a condition variable to implement sleeping so that an
Makefile.in: New #defines and friends for Thread.h. * Makefile.in: New #defines and friends for Thread.h. * posix-threads.cc: (struct starter): Remove `object'. (_Jv_CondWait): Use interruptable condition variables and new recursive mutexes. New return codes on interrupt or non-ownership of mutex. (_Jv_CondNotify): Ditto. (_Jv_CondNotifyAll): Ditto. (_Jv_ThreadInterrupt): Set thread interrupt flag directly. Interrupt the target thread by signaling its wait condition. (_Jv_ThreadInitData): Set `thread_obj' in the thread data struct, not the starter struct. Initialize wait_mutex and wait_cond. (_Jv_MutexLock): New recursive mutex implementation. Moved from posix-threads.h. (_Jv_MutexUnlock): Ditto. (really_start): Set info->data->thread from pthread_self() to work around a race condition. Destroy wait_mutex and wait_cond when run() returns. * java/lang/Thread.java: (isInterrupted_): Renamed to overloaded `isInterrupted(boolean)'. Clear interrupted flag if clear_flag is set. startable_flag: New private field. (Thread): Initialize `startable_flag'. (toString): Check for null thread group. * java/lang/natThread.cc: (struct natThread): New fields `join_mutex', `join_cond'. Removed fields `joiner', `next'. (class locker): Removed. (initialize_native): Initialize `join_cond' and `join_mutex'. (interrupt): Now just calls _Jv_ThreadInterrupt(). (join): Simplified. Just wait on the target thread's join condition. (finish_): Remove join list code. Unset thread group. Signal potential joiners by notifying the dying threads join_cond. (start): Check for illegal restarts. * java/lang/natObject.cc: Check for return value of _Jv_CondWait and act appropriatly. * include/posix-threads.h: Remove all HAVE_RECURSIVE_MUTEX related #defines and #ifdefs. (struct _Jv_Thread_t): New fields `thread_obj', `wait_cond', `wait_mutex', `next'. (struct _Jv_ConditionVariable_t): Define as a struct instead of directly mapping to pthread_cond_t. (struct _Jv_Mutex_t): New recursive implementation. (_Jv_PthreadCheckMonitor): Reimplemented. Simple `owner' check. _Jv_HaveCondDestroy: Never define this for posix-threads. (_Jv_CondNotify): Remove inline implementation(s), prototype instead. (_Jv_CondNotifyAll): Ditto. (_Jv_MutexLock): Ditto. (_Jv_MutexUnlock): Ditto. (_Jv_MutexInit): Changed to reflect new mutex implementation. (_Jv_MutexDestroy): Ditto. (_Jv_CondDestroy): Removed. (_Jv_PthreadGetMutex): Removed. * include/win32-threads.h: (_Jv_CondNotify): Guess _JV_NOT_OWNER on an error. Add a FIXME about this. (_Jv_CondNotifyAll): Ditto. * win32-threads.cc: (_Jv_CondWait): Return 0 on a timeout. Guess _JV_NOT_OWNER on other errors. Add FIXME. From-SVN: r32773
2000-03-28 04:22:24 +02:00
// interrupt can wake us up.
1999-04-07 16:42:40 +02:00
natThread *nt = (natThread *) current->data;
Makefile.in: New #defines and friends for Thread.h. * Makefile.in: New #defines and friends for Thread.h. * posix-threads.cc: (struct starter): Remove `object'. (_Jv_CondWait): Use interruptable condition variables and new recursive mutexes. New return codes on interrupt or non-ownership of mutex. (_Jv_CondNotify): Ditto. (_Jv_CondNotifyAll): Ditto. (_Jv_ThreadInterrupt): Set thread interrupt flag directly. Interrupt the target thread by signaling its wait condition. (_Jv_ThreadInitData): Set `thread_obj' in the thread data struct, not the starter struct. Initialize wait_mutex and wait_cond. (_Jv_MutexLock): New recursive mutex implementation. Moved from posix-threads.h. (_Jv_MutexUnlock): Ditto. (really_start): Set info->data->thread from pthread_self() to work around a race condition. Destroy wait_mutex and wait_cond when run() returns. * java/lang/Thread.java: (isInterrupted_): Renamed to overloaded `isInterrupted(boolean)'. Clear interrupted flag if clear_flag is set. startable_flag: New private field. (Thread): Initialize `startable_flag'. (toString): Check for null thread group. * java/lang/natThread.cc: (struct natThread): New fields `join_mutex', `join_cond'. Removed fields `joiner', `next'. (class locker): Removed. (initialize_native): Initialize `join_cond' and `join_mutex'. (interrupt): Now just calls _Jv_ThreadInterrupt(). (join): Simplified. Just wait on the target thread's join condition. (finish_): Remove join list code. Unset thread group. Signal potential joiners by notifying the dying threads join_cond. (start): Check for illegal restarts. * java/lang/natObject.cc: Check for return value of _Jv_CondWait and act appropriatly. * include/posix-threads.h: Remove all HAVE_RECURSIVE_MUTEX related #defines and #ifdefs. (struct _Jv_Thread_t): New fields `thread_obj', `wait_cond', `wait_mutex', `next'. (struct _Jv_ConditionVariable_t): Define as a struct instead of directly mapping to pthread_cond_t. (struct _Jv_Mutex_t): New recursive implementation. (_Jv_PthreadCheckMonitor): Reimplemented. Simple `owner' check. _Jv_HaveCondDestroy: Never define this for posix-threads. (_Jv_CondNotify): Remove inline implementation(s), prototype instead. (_Jv_CondNotifyAll): Ditto. (_Jv_MutexLock): Ditto. (_Jv_MutexUnlock): Ditto. (_Jv_MutexInit): Changed to reflect new mutex implementation. (_Jv_MutexDestroy): Ditto. (_Jv_CondDestroy): Removed. (_Jv_PthreadGetMutex): Removed. * include/win32-threads.h: (_Jv_CondNotify): Guess _JV_NOT_OWNER on an error. Add a FIXME about this. (_Jv_CondNotifyAll): Ditto. * win32-threads.cc: (_Jv_CondWait): Return 0 on a timeout. Guess _JV_NOT_OWNER on other errors. Add FIXME. From-SVN: r32773
2000-03-28 04:22:24 +02:00
_Jv_MutexLock (&nt->join_mutex);
_Jv_CondWait (&nt->join_cond, &nt->join_mutex, millis, nanos);
_Jv_MutexUnlock (&nt->join_mutex);
if (current->isInterrupted (true))
throw new InterruptedException;
1999-04-07 16:42:40 +02:00
}
void
java-interp.h: Don't include MethodInvocation.h. * include/java-interp.h: Don't include MethodInvocation.h. (class _Jv_InterpMethod): Don't make MethodInvocation a friend. * Makefile.in: Rebuilt. * Makefile.am (gnu/gcj/runtime/MethodInvocation.h): Removed. (ordinary_java_source_files): Don't mention MethodInvocation.java. * gnu/gcj/runtime/MethodInvocation.java: Removed. * interpret.cc (MethodInvocation::continue1): Removed. (run): Handle exceptions here. * java/lang/ClassLoader.java (defineClass1, defineClass2): Removed. * java/lang/natClassLoader.cc (defineClass0): Catch exceptions here. (defineClass2): Removed. * java/lang/reflect/Method.java (hack_trampoline, hack_call): Removed. * java/lang/reflect/natMethod.cc (_Jv_CallAnyMethodA): Catch exceptions here. (hack_call): Removed. * java/lang/Class.h (Class): Removed hackRunInitializers, hackTrampoline. * java/lang/natClass.cc (hackRunInitializers): Removed. (initializeClass): Catch exceptions here. Include ExceptionInInitializerError.h. * java/lang/Class.java (hackTrampoline, hackRunInitializers): Removed. * java/lang/Object.h (Object): Don't mention hack12_6. * java/lang/natObject.cc (_Jv_FinalizeObject): Catch exceptions here. * java/lang/Object.java (hack12_6): Removed. * java/lang/natThread.cc (run_): Renamed. Catch exceptions here. (start): Use run_, not run__. * java/lang/Thread.java (run_): Renamed from run__; old run_ removed. * jni.cc (_Jv_JNI_FindClass): Handle exceptions. (_Jv_JNI_EnsureLocalCapacity): Likewise. (_Jv_JNI_DefineClass): Likewise. (_Jv_JNI_ThrowNew): Likewise. (_Jv_JNI_AllocObject): Likewise. (_Jv_JNI_GetAnyMethodID): Likewise. (_Jv_JNI_CallAnyMethodV): Likewise. (_Jv_JNI_CallAnyMethodA): Likewise. (_Jv_JNI_CallAnyVoidMethodV): Likewise. (_Jv_JNI_CallAnyVoidMethodA): Likewise. (_Jv_JNI_GetAnyFieldID): Likewise. (_Jv_JNI_NewString): Likewise. (_Jv_JNI_NewStringUTF): Likewise. (_Jv_JNI_GetStringUTFChars): Likewise. (_Jv_JNI_NewObjectArray): Likewise. (_Jv_JNI_NewPrimitiveArray): Likewise. (_Jv_JNI_GetPrimitiveArrayRegion): Likewise. (_Jv_JNI_GetStringRegion): Likewise. (_Jv_JNI_GetStringUTFRegion): Likewise. (_Jv_JNI_SetPrimitiveArrayRegion): Likewise. (_Jv_JNI_MonitorEnter): Likewise. (_Jv_JNI_MonitorExit): Likewise. (_Jv_JNI_ToReflectedField): Likewise. (_Jv_JNI_ToReflectedMethod): Likewise. (_Jv_JNI_RegisterNatives): Likewise. (_Jv_JNI_AttachCurrentThread): Likewise. (_Jv_JNI_DestroyJavaVM): Likewise. From-SVN: r32294
2000-03-02 21:25:20 +01:00
java::lang::Thread::finish_ ()
1999-04-07 16:42:40 +02:00
{
natThread *nt = (natThread *) data;
Makefile.in: New #defines and friends for Thread.h. * Makefile.in: New #defines and friends for Thread.h. * posix-threads.cc: (struct starter): Remove `object'. (_Jv_CondWait): Use interruptable condition variables and new recursive mutexes. New return codes on interrupt or non-ownership of mutex. (_Jv_CondNotify): Ditto. (_Jv_CondNotifyAll): Ditto. (_Jv_ThreadInterrupt): Set thread interrupt flag directly. Interrupt the target thread by signaling its wait condition. (_Jv_ThreadInitData): Set `thread_obj' in the thread data struct, not the starter struct. Initialize wait_mutex and wait_cond. (_Jv_MutexLock): New recursive mutex implementation. Moved from posix-threads.h. (_Jv_MutexUnlock): Ditto. (really_start): Set info->data->thread from pthread_self() to work around a race condition. Destroy wait_mutex and wait_cond when run() returns. * java/lang/Thread.java: (isInterrupted_): Renamed to overloaded `isInterrupted(boolean)'. Clear interrupted flag if clear_flag is set. startable_flag: New private field. (Thread): Initialize `startable_flag'. (toString): Check for null thread group. * java/lang/natThread.cc: (struct natThread): New fields `join_mutex', `join_cond'. Removed fields `joiner', `next'. (class locker): Removed. (initialize_native): Initialize `join_cond' and `join_mutex'. (interrupt): Now just calls _Jv_ThreadInterrupt(). (join): Simplified. Just wait on the target thread's join condition. (finish_): Remove join list code. Unset thread group. Signal potential joiners by notifying the dying threads join_cond. (start): Check for illegal restarts. * java/lang/natObject.cc: Check for return value of _Jv_CondWait and act appropriatly. * include/posix-threads.h: Remove all HAVE_RECURSIVE_MUTEX related #defines and #ifdefs. (struct _Jv_Thread_t): New fields `thread_obj', `wait_cond', `wait_mutex', `next'. (struct _Jv_ConditionVariable_t): Define as a struct instead of directly mapping to pthread_cond_t. (struct _Jv_Mutex_t): New recursive implementation. (_Jv_PthreadCheckMonitor): Reimplemented. Simple `owner' check. _Jv_HaveCondDestroy: Never define this for posix-threads. (_Jv_CondNotify): Remove inline implementation(s), prototype instead. (_Jv_CondNotifyAll): Ditto. (_Jv_MutexLock): Ditto. (_Jv_MutexUnlock): Ditto. (_Jv_MutexInit): Changed to reflect new mutex implementation. (_Jv_MutexDestroy): Ditto. (_Jv_CondDestroy): Removed. (_Jv_PthreadGetMutex): Removed. * include/win32-threads.h: (_Jv_CondNotify): Guess _JV_NOT_OWNER on an error. Add a FIXME about this. (_Jv_CondNotifyAll): Ditto. * win32-threads.cc: (_Jv_CondWait): Return 0 on a timeout. Guess _JV_NOT_OWNER on other errors. Add FIXME. From-SVN: r32773
2000-03-28 04:22:24 +02:00
group->removeThread (this);
#ifdef ENABLE_JVMPI
if (_Jv_JVMPI_Notify_THREAD_END)
{
JVMPI_Event event;
event.event_type = JVMPI_EVENT_THREAD_END;
event.env_id = _Jv_GetCurrentJNIEnv ();
_Jv_DisableGC ();
(*_Jv_JVMPI_Notify_THREAD_END) (&event);
_Jv_EnableGC ();
}
#endif
Makefile.in: New #defines and friends for Thread.h. * Makefile.in: New #defines and friends for Thread.h. * posix-threads.cc: (struct starter): Remove `object'. (_Jv_CondWait): Use interruptable condition variables and new recursive mutexes. New return codes on interrupt or non-ownership of mutex. (_Jv_CondNotify): Ditto. (_Jv_CondNotifyAll): Ditto. (_Jv_ThreadInterrupt): Set thread interrupt flag directly. Interrupt the target thread by signaling its wait condition. (_Jv_ThreadInitData): Set `thread_obj' in the thread data struct, not the starter struct. Initialize wait_mutex and wait_cond. (_Jv_MutexLock): New recursive mutex implementation. Moved from posix-threads.h. (_Jv_MutexUnlock): Ditto. (really_start): Set info->data->thread from pthread_self() to work around a race condition. Destroy wait_mutex and wait_cond when run() returns. * java/lang/Thread.java: (isInterrupted_): Renamed to overloaded `isInterrupted(boolean)'. Clear interrupted flag if clear_flag is set. startable_flag: New private field. (Thread): Initialize `startable_flag'. (toString): Check for null thread group. * java/lang/natThread.cc: (struct natThread): New fields `join_mutex', `join_cond'. Removed fields `joiner', `next'. (class locker): Removed. (initialize_native): Initialize `join_cond' and `join_mutex'. (interrupt): Now just calls _Jv_ThreadInterrupt(). (join): Simplified. Just wait on the target thread's join condition. (finish_): Remove join list code. Unset thread group. Signal potential joiners by notifying the dying threads join_cond. (start): Check for illegal restarts. * java/lang/natObject.cc: Check for return value of _Jv_CondWait and act appropriatly. * include/posix-threads.h: Remove all HAVE_RECURSIVE_MUTEX related #defines and #ifdefs. (struct _Jv_Thread_t): New fields `thread_obj', `wait_cond', `wait_mutex', `next'. (struct _Jv_ConditionVariable_t): Define as a struct instead of directly mapping to pthread_cond_t. (struct _Jv_Mutex_t): New recursive implementation. (_Jv_PthreadCheckMonitor): Reimplemented. Simple `owner' check. _Jv_HaveCondDestroy: Never define this for posix-threads. (_Jv_CondNotify): Remove inline implementation(s), prototype instead. (_Jv_CondNotifyAll): Ditto. (_Jv_MutexLock): Ditto. (_Jv_MutexUnlock): Ditto. (_Jv_MutexInit): Changed to reflect new mutex implementation. (_Jv_MutexDestroy): Ditto. (_Jv_CondDestroy): Removed. (_Jv_PthreadGetMutex): Removed. * include/win32-threads.h: (_Jv_CondNotify): Guess _JV_NOT_OWNER on an error. Add a FIXME about this. (_Jv_CondNotifyAll): Ditto. * win32-threads.cc: (_Jv_CondWait): Return 0 on a timeout. Guess _JV_NOT_OWNER on other errors. Add FIXME. From-SVN: r32773
2000-03-28 04:22:24 +02:00
group = NULL;
// Signal any threads that are waiting to join() us.
_Jv_MutexLock (&nt->join_mutex);
alive_flag = false;
_Jv_CondNotifyAll (&nt->join_cond, &nt->join_mutex);
_Jv_MutexUnlock (&nt->join_mutex);
1999-04-07 16:42:40 +02:00
}
// Run once at thread startup, either when thread is attached or when
// _Jv_ThreadRun is called.
static void
_Jv_NotifyThreadStart (java::lang::Thread* thread)
1999-04-07 16:42:40 +02:00
{
#ifdef ENABLE_JVMPI
if (_Jv_JVMPI_Notify_THREAD_START)
{
JVMPI_Event event;
jstring thread_name = thread->getName ();
jstring group_name = NULL, parent_name = NULL;
java::lang::ThreadGroup *group = thread->getThreadGroup ();
if (group)
{
group_name = group->getName ();
group = group->getParent ();
if (group)
parent_name = group->getName ();
}
int thread_len = thread_name ? JvGetStringUTFLength (thread_name) : 0;
int group_len = group_name ? JvGetStringUTFLength (group_name) : 0;
int parent_len = parent_name ? JvGetStringUTFLength (parent_name) : 0;
char thread_chars[thread_len + 1];
char group_chars[group_len + 1];
char parent_chars[parent_len + 1];
if (thread_name)
JvGetStringUTFRegion (thread_name, 0,
thread_name->length(), thread_chars);
if (group_name)
JvGetStringUTFRegion (group_name, 0,
group_name->length(), group_chars);
if (parent_name)
JvGetStringUTFRegion (parent_name, 0,
parent_name->length(), parent_chars);
thread_chars[thread_len] = '\0';
group_chars[group_len] = '\0';
parent_chars[parent_len] = '\0';
event.event_type = JVMPI_EVENT_THREAD_START;
event.env_id = NULL;
event.u.thread_start.thread_name = thread_chars;
event.u.thread_start.group_name = group_chars;
event.u.thread_start.parent_name = parent_chars;
event.u.thread_start.thread_id = (jobjectID) thread;
event.u.thread_start.thread_env_id = _Jv_GetCurrentJNIEnv ();
_Jv_DisableGC ();
(*_Jv_JVMPI_Notify_THREAD_START) (&event);
_Jv_EnableGC ();
}
#endif
}
void
_Jv_ThreadRun (java::lang::Thread* thread)
{
try
{
_Jv_NotifyThreadStart (thread);
java-interp.h: Don't include MethodInvocation.h. * include/java-interp.h: Don't include MethodInvocation.h. (class _Jv_InterpMethod): Don't make MethodInvocation a friend. * Makefile.in: Rebuilt. * Makefile.am (gnu/gcj/runtime/MethodInvocation.h): Removed. (ordinary_java_source_files): Don't mention MethodInvocation.java. * gnu/gcj/runtime/MethodInvocation.java: Removed. * interpret.cc (MethodInvocation::continue1): Removed. (run): Handle exceptions here. * java/lang/ClassLoader.java (defineClass1, defineClass2): Removed. * java/lang/natClassLoader.cc (defineClass0): Catch exceptions here. (defineClass2): Removed. * java/lang/reflect/Method.java (hack_trampoline, hack_call): Removed. * java/lang/reflect/natMethod.cc (_Jv_CallAnyMethodA): Catch exceptions here. (hack_call): Removed. * java/lang/Class.h (Class): Removed hackRunInitializers, hackTrampoline. * java/lang/natClass.cc (hackRunInitializers): Removed. (initializeClass): Catch exceptions here. Include ExceptionInInitializerError.h. * java/lang/Class.java (hackTrampoline, hackRunInitializers): Removed. * java/lang/Object.h (Object): Don't mention hack12_6. * java/lang/natObject.cc (_Jv_FinalizeObject): Catch exceptions here. * java/lang/Object.java (hack12_6): Removed. * java/lang/natThread.cc (run_): Renamed. Catch exceptions here. (start): Use run_, not run__. * java/lang/Thread.java (run_): Renamed from run__; old run_ removed. * jni.cc (_Jv_JNI_FindClass): Handle exceptions. (_Jv_JNI_EnsureLocalCapacity): Likewise. (_Jv_JNI_DefineClass): Likewise. (_Jv_JNI_ThrowNew): Likewise. (_Jv_JNI_AllocObject): Likewise. (_Jv_JNI_GetAnyMethodID): Likewise. (_Jv_JNI_CallAnyMethodV): Likewise. (_Jv_JNI_CallAnyMethodA): Likewise. (_Jv_JNI_CallAnyVoidMethodV): Likewise. (_Jv_JNI_CallAnyVoidMethodA): Likewise. (_Jv_JNI_GetAnyFieldID): Likewise. (_Jv_JNI_NewString): Likewise. (_Jv_JNI_NewStringUTF): Likewise. (_Jv_JNI_GetStringUTFChars): Likewise. (_Jv_JNI_NewObjectArray): Likewise. (_Jv_JNI_NewPrimitiveArray): Likewise. (_Jv_JNI_GetPrimitiveArrayRegion): Likewise. (_Jv_JNI_GetStringRegion): Likewise. (_Jv_JNI_GetStringUTFRegion): Likewise. (_Jv_JNI_SetPrimitiveArrayRegion): Likewise. (_Jv_JNI_MonitorEnter): Likewise. (_Jv_JNI_MonitorExit): Likewise. (_Jv_JNI_ToReflectedField): Likewise. (_Jv_JNI_ToReflectedMethod): Likewise. (_Jv_JNI_RegisterNatives): Likewise. (_Jv_JNI_AttachCurrentThread): Likewise. (_Jv_JNI_DestroyJavaVM): Likewise. From-SVN: r32294
2000-03-02 21:25:20 +01:00
thread->run ();
}
catch (java::lang::Throwable *t)
{
// Uncaught exceptions are forwarded to the ThreadGroup. If
// this results in an uncaught exception, that is ignored.
try
{
thread->group->uncaughtException (thread, t);
}
catch (java::lang::Throwable *f)
{
// Nothing.
}
}
thread->finish_ ();
1999-04-07 16:42:40 +02:00
}
void
java::lang::Thread::start (void)
{
JvSynchronize sync (this);
Makefile.in: New #defines and friends for Thread.h. * Makefile.in: New #defines and friends for Thread.h. * posix-threads.cc: (struct starter): Remove `object'. (_Jv_CondWait): Use interruptable condition variables and new recursive mutexes. New return codes on interrupt or non-ownership of mutex. (_Jv_CondNotify): Ditto. (_Jv_CondNotifyAll): Ditto. (_Jv_ThreadInterrupt): Set thread interrupt flag directly. Interrupt the target thread by signaling its wait condition. (_Jv_ThreadInitData): Set `thread_obj' in the thread data struct, not the starter struct. Initialize wait_mutex and wait_cond. (_Jv_MutexLock): New recursive mutex implementation. Moved from posix-threads.h. (_Jv_MutexUnlock): Ditto. (really_start): Set info->data->thread from pthread_self() to work around a race condition. Destroy wait_mutex and wait_cond when run() returns. * java/lang/Thread.java: (isInterrupted_): Renamed to overloaded `isInterrupted(boolean)'. Clear interrupted flag if clear_flag is set. startable_flag: New private field. (Thread): Initialize `startable_flag'. (toString): Check for null thread group. * java/lang/natThread.cc: (struct natThread): New fields `join_mutex', `join_cond'. Removed fields `joiner', `next'. (class locker): Removed. (initialize_native): Initialize `join_cond' and `join_mutex'. (interrupt): Now just calls _Jv_ThreadInterrupt(). (join): Simplified. Just wait on the target thread's join condition. (finish_): Remove join list code. Unset thread group. Signal potential joiners by notifying the dying threads join_cond. (start): Check for illegal restarts. * java/lang/natObject.cc: Check for return value of _Jv_CondWait and act appropriatly. * include/posix-threads.h: Remove all HAVE_RECURSIVE_MUTEX related #defines and #ifdefs. (struct _Jv_Thread_t): New fields `thread_obj', `wait_cond', `wait_mutex', `next'. (struct _Jv_ConditionVariable_t): Define as a struct instead of directly mapping to pthread_cond_t. (struct _Jv_Mutex_t): New recursive implementation. (_Jv_PthreadCheckMonitor): Reimplemented. Simple `owner' check. _Jv_HaveCondDestroy: Never define this for posix-threads. (_Jv_CondNotify): Remove inline implementation(s), prototype instead. (_Jv_CondNotifyAll): Ditto. (_Jv_MutexLock): Ditto. (_Jv_MutexUnlock): Ditto. (_Jv_MutexInit): Changed to reflect new mutex implementation. (_Jv_MutexDestroy): Ditto. (_Jv_CondDestroy): Removed. (_Jv_PthreadGetMutex): Removed. * include/win32-threads.h: (_Jv_CondNotify): Guess _JV_NOT_OWNER on an error. Add a FIXME about this. (_Jv_CondNotifyAll): Ditto. * win32-threads.cc: (_Jv_CondWait): Return 0 on a timeout. Guess _JV_NOT_OWNER on other errors. Add FIXME. From-SVN: r32773
2000-03-28 04:22:24 +02:00
// Its illegal to re-start() a thread, even if its dead.
if (!startable_flag)
throw new IllegalThreadStateException;
1999-04-07 16:42:40 +02:00
alive_flag = true;
Makefile.in: New #defines and friends for Thread.h. * Makefile.in: New #defines and friends for Thread.h. * posix-threads.cc: (struct starter): Remove `object'. (_Jv_CondWait): Use interruptable condition variables and new recursive mutexes. New return codes on interrupt or non-ownership of mutex. (_Jv_CondNotify): Ditto. (_Jv_CondNotifyAll): Ditto. (_Jv_ThreadInterrupt): Set thread interrupt flag directly. Interrupt the target thread by signaling its wait condition. (_Jv_ThreadInitData): Set `thread_obj' in the thread data struct, not the starter struct. Initialize wait_mutex and wait_cond. (_Jv_MutexLock): New recursive mutex implementation. Moved from posix-threads.h. (_Jv_MutexUnlock): Ditto. (really_start): Set info->data->thread from pthread_self() to work around a race condition. Destroy wait_mutex and wait_cond when run() returns. * java/lang/Thread.java: (isInterrupted_): Renamed to overloaded `isInterrupted(boolean)'. Clear interrupted flag if clear_flag is set. startable_flag: New private field. (Thread): Initialize `startable_flag'. (toString): Check for null thread group. * java/lang/natThread.cc: (struct natThread): New fields `join_mutex', `join_cond'. Removed fields `joiner', `next'. (class locker): Removed. (initialize_native): Initialize `join_cond' and `join_mutex'. (interrupt): Now just calls _Jv_ThreadInterrupt(). (join): Simplified. Just wait on the target thread's join condition. (finish_): Remove join list code. Unset thread group. Signal potential joiners by notifying the dying threads join_cond. (start): Check for illegal restarts. * java/lang/natObject.cc: Check for return value of _Jv_CondWait and act appropriatly. * include/posix-threads.h: Remove all HAVE_RECURSIVE_MUTEX related #defines and #ifdefs. (struct _Jv_Thread_t): New fields `thread_obj', `wait_cond', `wait_mutex', `next'. (struct _Jv_ConditionVariable_t): Define as a struct instead of directly mapping to pthread_cond_t. (struct _Jv_Mutex_t): New recursive implementation. (_Jv_PthreadCheckMonitor): Reimplemented. Simple `owner' check. _Jv_HaveCondDestroy: Never define this for posix-threads. (_Jv_CondNotify): Remove inline implementation(s), prototype instead. (_Jv_CondNotifyAll): Ditto. (_Jv_MutexLock): Ditto. (_Jv_MutexUnlock): Ditto. (_Jv_MutexInit): Changed to reflect new mutex implementation. (_Jv_MutexDestroy): Ditto. (_Jv_CondDestroy): Removed. (_Jv_PthreadGetMutex): Removed. * include/win32-threads.h: (_Jv_CondNotify): Guess _JV_NOT_OWNER on an error. Add a FIXME about this. (_Jv_CondNotifyAll): Ditto. * win32-threads.cc: (_Jv_CondWait): Return 0 on a timeout. Guess _JV_NOT_OWNER on other errors. Add FIXME. From-SVN: r32773
2000-03-28 04:22:24 +02:00
startable_flag = false;
1999-04-07 16:42:40 +02:00
natThread *nt = (natThread *) data;
_Jv_ThreadStart (this, nt->thread, (_Jv_ThreadStartFunc *) &_Jv_ThreadRun);
1999-04-07 16:42:40 +02:00
}
void
java::lang::Thread::stop (java::lang::Throwable *)
1999-04-07 16:42:40 +02:00
{
throw new UnsupportedOperationException
(JvNewStringLatin1 ("Thread.stop unimplemented"));
1999-04-07 16:42:40 +02:00
}
void
java::lang::Thread::suspend (void)
{
checkAccess ();
throw new UnsupportedOperationException
(JvNewStringLatin1 ("Thread.suspend unimplemented"));
1999-04-07 16:42:40 +02:00
}
static int nextThreadNumber = 0;
jstring
java::lang::Thread::gen_name (void)
{
jint i;
jclass sync = &java::lang::Thread::class$;
{
JvSynchronize dummy(sync);
i = ++nextThreadNumber;
}
// Use an array large enough for "-2147483648"; i.e. 11 chars, + "Thread-".
jchar buffer[7+11];
jchar *bufend = (jchar *) ((char *) buffer + sizeof(buffer));
i = _Jv_FormatInt (bufend, i);
jchar *ptr = bufend - i;
// Prepend "Thread-".
*--ptr = '-';
*--ptr = 'd';
*--ptr = 'a';
*--ptr = 'e';
*--ptr = 'r';
*--ptr = 'h';
*--ptr = 'T';
return JvNewString (ptr, bufend - ptr);
}
1999-04-07 16:42:40 +02:00
void
java::lang::Thread::yield (void)
{
_Jv_ThreadYield ();
}
natNativeThread.cc: New file. * gnu/gcj/jni/natNativeThread.cc: New file. * gnu/gcj/jni/NativeThread.java: New file. * java/lang/Thread.java (data): Now a RawData. * include/jvm.h (_Jv_GetCurrentJNIEnv, _Jv_SetCurrentJNIEnv): Declare. * Makefile.in: Rebuilt. * Makefile.am (java/lang/Thread.h): New target. (ordinary_java_source_files): Added NativeThread.java. (nat_source_files): Added natNativeThread.cc. * java/lang/natThread.cc: Include <jni.h> (struct natThread): Added `jni_env' field. (_Jv_GetCurrentJNIEnv): New function. (_Jv_SetCurrentJNIEnv): Likewise. (initialize_native): Initialize jni_env. Include RawData.h. * jni.cc (ThreadGroupClass): New define. (_Jv_JNI_InvokeFunctions): New structure. (JNI_GetCreatedJavaVMs): New function. (the_vm): New global. (JNI_GetDefaultJavaVMInitArgs): New function. Include NativeThread.h. (NativeThreadClass): New define. (_Jv_JNI_EnsureLocalCapacity): Return JNI_ERR, not -1. (_Jv_JNI_DestroyJavaVM): New function. (_Jv_JNI_AttachCurrentThread): New function. (_Jv_JNI_DetachCurrentThread): New function. (_Jv_JNI_GetEnv): New function. (JNI_CreateJavaVM): New function. (_Jv_JNI_GetJavaVM): New function. (_Jv_JNIFunctions): Added entry for GetJavaVM. * include/jni.h (JavaVMAttachArgs): New structure. (JNI_EDETACHED): New define. (JNI_EVERSION): Likewise. (JavaVM): Define properly. (struct JNIInvokeInterface): New structure. (class _Jv_JavaVM): New class. (JNI_OnLoad, JNI_OnUnload): Declare. (JNI_GetDefaultJavaVMInitArgs, JNI_CreateJavaVM, JNI_GetCreatedJavaVMs): Declare. (JavaVMInitArgs): New typedef. (JavaVMOption): Likewise. (JNI_ERR): New define. (JNI_OK): Likewise. From-SVN: r31901
2000-02-10 21:31:48 +01:00
JNIEnv *
_Jv_GetCurrentJNIEnv ()
{
java::lang::Thread *t = _Jv_ThreadCurrent ();
if (t == NULL)
return NULL;
return ((natThread *) t->data)->jni_env;
}
void
_Jv_SetCurrentJNIEnv (JNIEnv *env)
{
java::lang::Thread *t = _Jv_ThreadCurrent ();
JvAssert (t != NULL);
((natThread *) t->data)->jni_env = env;
}
// Attach the current native thread to an existing (but unstarted) Thread
// object. Returns -1 on failure, 0 upon success.
jint
_Jv_AttachCurrentThread(java::lang::Thread* thread)
{
if (thread == NULL || thread->startable_flag == false)
return -1;
thread->startable_flag = false;
thread->alive_flag = true;
natThread *nt = (natThread *) thread->data;
_Jv_ThreadRegister (nt->thread);
return 0;
}
java::lang::Thread*
_Jv_AttachCurrentThread(jstring name, java::lang::ThreadGroup* group)
{
java::lang::Thread *thread = _Jv_ThreadCurrent ();
if (thread != NULL)
return thread;
if (name == NULL)
name = java::lang::Thread::gen_name ();
thread = new java::lang::Thread (NULL, group, NULL, name);
_Jv_AttachCurrentThread (thread);
_Jv_NotifyThreadStart (thread);
return thread;
}
java::lang::Thread*
_Jv_AttachCurrentThreadAsDaemon(jstring name, java::lang::ThreadGroup* group)
{
java::lang::Thread *thread = _Jv_ThreadCurrent ();
if (thread != NULL)
return thread;
if (name == NULL)
name = java::lang::Thread::gen_name ();
thread = new java::lang::Thread (NULL, group, NULL, name);
thread->setDaemon (true);
_Jv_AttachCurrentThread (thread);
_Jv_NotifyThreadStart (thread);
return thread;
}
jint
_Jv_DetachCurrentThread (void)
{
java::lang::Thread *t = _Jv_ThreadCurrent ();
if (t == NULL)
return -1;
_Jv_ThreadUnRegister ();
// Release the monitors.
t->finish_ ();
return 0;
}