summaryrefslogtreecommitdiff
path: root/libjava/java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/java')
-rw-r--r--libjava/java/lang/Thread.java11
-rw-r--r--libjava/java/lang/natThread.cc30
2 files changed, 33 insertions, 8 deletions
diff --git a/libjava/java/lang/Thread.java b/libjava/java/lang/Thread.java
index 34921677c8a..7dbabcf56c5 100644
--- a/libjava/java/lang/Thread.java
+++ b/libjava/java/lang/Thread.java
@@ -1,6 +1,6 @@
// Thread.java - Thread class.
-/* Copyright (C) 1998, 1999 Red Hat, Inc.
+/* Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
This file is part of libgcj.
@@ -10,6 +10,8 @@ details. */
package java.lang;
+import gnu.gcj.RawData;
+
/**
* @author Tom Tromey <tromey@cygnus.com>
* @date August 24, 1998
@@ -297,11 +299,8 @@ public class Thread implements Runnable
private boolean interrupt_flag;
private boolean alive_flag;
- // This is a bit odd. We need a way to represent some data that is
- // manipulated only by the native side of this class. We represent
- // it as a Java object reference. However, it is not actually a
- // Java object.
- private Object data;
+ // Our native data.
+ private RawData data;
// Next thread number to assign.
private static int nextThreadNumber = 0;
diff --git a/libjava/java/lang/natThread.cc b/libjava/java/lang/natThread.cc
index 6870f02c50d..741f2b587e8 100644
--- a/libjava/java/lang/natThread.cc
+++ b/libjava/java/lang/natThread.cc
@@ -1,6 +1,6 @@
// natThread.cc - Native part of Thread class.
-/* Copyright (C) 1998, 1999 Red Hat, Inc.
+/* Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
This file is part of libgcj.
@@ -23,6 +23,9 @@ details. */
#include <java/lang/IllegalThreadStateException.h>
#include <java/lang/InterruptedException.h>
#include <java/lang/NullPointerException.h>
+#include <gnu/gcj/RawData.h>
+
+#include <jni.h>
@@ -40,6 +43,9 @@ struct natThread
// This is private data for the thread system layer.
_Jv_Thread_t *thread;
+ // Each thread has its own JNI object.
+ JNIEnv *jni_env;
+
// All threads waiting to join this thread are linked together and
// waiting on their respective `interrupt' condition variables.
// When this thread exits, it notifies each such thread by
@@ -83,10 +89,13 @@ java::lang::Thread::initialize_native (void)
// own finalizer then we will need to reinitialize this structure at
// any "interesting" point.
natThread *nt = (natThread *) _Jv_AllocBytes (sizeof (natThread));
- data = (jobject) nt;
+ data = reinterpret_cast<gnu::gcj::RawData *> (nt);
_Jv_MutexInit (&nt->interrupt_mutex);
_Jv_CondInit (&nt->interrupt_cond);
_Jv_ThreadInitData (&nt->thread, this);
+ // FIXME: if JNI_ENV is set we will want to free it. It is
+ // malloc()d.
+ nt->jni_env = NULL;
nt->joiner = 0;
nt->next = 0;
}
@@ -324,3 +333,20 @@ java::lang::Thread::yield (void)
{
_Jv_ThreadYield ();
}
+
+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;
+}