Patch: FYI: JNI update for 1.4
Tom Tromey
tromey@redhat.com
Wed Apr 10 13:32:00 GMT 2002
I wrote this while waiting for builds today.
I'm checking this in on the trunk only.
This adds support for the JNI features that are new with JDK 1.4.
It looks a lot bigger than it really is. Conceptually there are just
4 new functions, and right now 3 of those always fail. (This will
change when we import java.nio.)
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
* Makefile.in: Rebuilt.
* Makefile.am (java/lang/Thread.h): Mark
_Jv_AttachCurrentThreadAsDaemon as friend.
* gcj/javaprims.h (_Jv_AttachCurrentThreadAsDaemon): Declare.
* gcj/cni.h (JvAttachCurrentThreadAsDaemon): New function.
* java/lang/natThread.cc (_Jv_AttachCurrentThreadAsDaemon): New
function.
* java/lang/natRuntime.cc (_load): Recognize JNI_VERSION_1_4.
* jni.cc (_Jv_JNI_GetVersion): Return JNI_VERSION_1_4.
(_Jv_JNI_InvokeFunctions): Added
_Jv_JNI_AttachCurrentThreadAsDaemon.
(_Jv_JNI_GetEnv): Handle JNI_VERSION_1_4.
(JNI_GetDefaultJavaVMInitArgs): Likewise.
(JNI_CreateJavaVM): Likewise.
(_Jv_JNI_AttachCurrentThread): Likewise.
(_Jv_JNI_AttachCurrentThread): Added `is_daemon' argument.
(_Jv_JNI_AttachCurrentThreadAsDaemon): New method.
(_Jv_JNIFunctions): Initialize new fields.
(_Jv_JNI_NewDirectByteBuffer): New function.
(_Jv_JNI_GetDirectBufferAddress): Likewise.
(_Jv_JNI_GetDirectBufferCapacity): Likewise.
* include/jni.h (JNI_VERSION_1_4): New macro.
(JNIInvokeInterface::AttachCurrentThreadAsDaemon): New field.
(_Jv_JavaVM::AttachCurrentThreadAsDaemon): New method.
(JNINativeInterface::NewDirectByteBuffer): New field.
(JNINativeInterface::GetDirectBufferAddress): New field.
(JNINativeInterface::GetDirectBufferCapacity): New field.
(_Jv_JNIEnv::NewDirectByteBuffer): New method.
(_Jv_JNIEnv::GetDirectBufferAddress): New method.
(_Jv_JNIEnv::GetDirectBufferCapacity): New method.
Index: Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libjava/Makefile.am,v
retrieving revision 1.210
diff -u -r1.210 Makefile.am
--- Makefile.am 26 Mar 2002 00:54:40 -0000 1.210
+++ Makefile.am 10 Apr 2002 19:54:12 -0000
@@ -288,6 +288,7 @@
-friend 'void _Jv_ThreadRun (java::lang::Thread* thread);' \
-friend 'jint _Jv_AttachCurrentThread(java::lang::Thread* thread);' \
-friend 'java::lang::Thread* _Jv_AttachCurrentThread(jstring name, java::lang::ThreadGroup* group);' \
+ -friend 'java::lang::Thread* _Jv_AttachCurrentThreadAsDaemon(jstring name, java::lang::ThreadGroup* group);' \
-friend 'jint _Jv_DetachCurrentThread ();' \
$(basename $<)
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/libjava/Makefile.in,v
retrieving revision 1.229
diff -u -r1.229 Makefile.in
--- Makefile.in 27 Mar 2002 16:41:31 -0000 1.229
+++ Makefile.in 10 Apr 2002 19:54:14 -0000
@@ -3304,6 +3304,7 @@
-friend 'void _Jv_ThreadRun (java::lang::Thread* thread);' \
-friend 'jint _Jv_AttachCurrentThread(java::lang::Thread* thread);' \
-friend 'java::lang::Thread* _Jv_AttachCurrentThread(jstring name, java::lang::ThreadGroup* group);' \
+ -friend 'java::lang::Thread* _Jv_AttachCurrentThreadAsDaemon(jstring name, java::lang::ThreadGroup* group);' \
-friend 'jint _Jv_DetachCurrentThread ();' \
$(basename $<)
Index: jni.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni.cc,v
retrieving revision 1.61
diff -u -r1.61 jni.cc
--- jni.cc 5 Mar 2002 22:36:11 -0000 1.61
+++ jni.cc 10 Apr 2002 19:54:16 -0000
@@ -424,7 +424,7 @@
static jint
_Jv_JNI_GetVersion (JNIEnv *)
{
- return JNI_VERSION_1_2;
+ return JNI_VERSION_1_4;
}
static jclass
@@ -1672,6 +1672,31 @@
+// Direct byte buffers.
+
+static jobject
+_Jv_JNI_NewDirectByteBuffer (JNIEnv *, void *, jlong)
+{
+ // For now we don't support this.
+ return NULL;
+}
+
+static void *
+_Jv_JNI_GetDirectBufferAddress (JNIEnv *, jobject)
+{
+ // For now we don't support this.
+ return NULL;
+}
+
+static jlong
+_Jv_JNI_GetDirectBufferCapacity (JNIEnv *, jobject)
+{
+ // For now we don't support this.
+ return -1;
+}
+
+
+
// Hash table of native methods.
static JNINativeMethod *nathash;
// Number of slots used.
@@ -2096,7 +2121,8 @@
// An internal helper function.
static jint
-_Jv_JNI_AttachCurrentThread (JavaVM *, jstring name, void **penv, void *args)
+_Jv_JNI_AttachCurrentThread (JavaVM *, jstring name, void **penv,
+ void *args, jboolean is_daemon)
{
JavaVMAttachArgs *attach = reinterpret_cast<JavaVMAttachArgs *> (args);
java::lang::ThreadGroup *group = NULL;
@@ -2104,7 +2130,8 @@
if (attach)
{
// FIXME: do we really want to support 1.1?
- if (attach->version != JNI_VERSION_1_2
+ if (attach->version != JNI_VERSION_1_4
+ && attach->version != JNI_VERSION_1_2
&& attach->version != JNI_VERSION_1_1)
return JNI_EVERSION;
@@ -2147,7 +2174,10 @@
{
try
{
- _Jv_AttachCurrentThread (name, group);
+ if (is_daemon)
+ _Jv_AttachCurrentThreadAsDaemon (name, group);
+ else
+ _Jv_AttachCurrentThread (name, group);
}
catch (jthrowable t)
{
@@ -2163,7 +2193,13 @@
static jint
_Jv_JNI_AttachCurrentThread (JavaVM *vm, void **penv, void *args)
{
- return _Jv_JNI_AttachCurrentThread (vm, NULL, penv, args);
+ return _Jv_JNI_AttachCurrentThread (vm, NULL, penv, args, false);
+}
+
+static jint
+_Jv_JNI_AttachCurrentThreadAsDaemon (JavaVM *vm, void **penv, void *args)
+{
+ return _Jv_JNI_AttachCurrentThread (vm, NULL, penv, args, true);
}
static jint
@@ -2185,10 +2221,9 @@
return JNI_ERR;
}
- jint r = _Jv_JNI_AttachCurrentThread (vm,
- main_name,
+ jint r = _Jv_JNI_AttachCurrentThread (vm, main_name,
reinterpret_cast<void **> (&env),
- NULL);
+ NULL, false);
if (r < 0)
return r;
}
@@ -2227,7 +2262,8 @@
#endif
// FIXME: do we really want to support 1.1?
- if (version != JNI_VERSION_1_2 && version != JNI_VERSION_1_1)
+ if (version != JNI_VERSION_1_4 && version != JNI_VERSION_1_2
+ && version != JNI_VERSION_1_1)
{
*penv = NULL;
return JNI_EVERSION;
@@ -2241,12 +2277,12 @@
JNI_GetDefaultJavaVMInitArgs (void *args)
{
jint version = * (jint *) args;
- // Here we only support 1.2.
- if (version != JNI_VERSION_1_2)
+ // Here we only support 1.2 and 1.4.
+ if (version != JNI_VERSION_1_2 && version != JNI_VERSION_1_4)
return JNI_EVERSION;
JavaVMInitArgs *ia = reinterpret_cast<JavaVMInitArgs *> (args);
- ia->version = JNI_VERSION_1_2;
+ ia->version = JNI_VERSION_1_4;
ia->nOptions = 0;
ia->options = NULL;
ia->ignoreUnrecognized = true;
@@ -2271,8 +2307,8 @@
if (args != NULL)
{
jint version = * (jint *) args;
- // We only support 1.2.
- if (version != JNI_VERSION_1_2)
+ // We only support 1.2 and 1.4.
+ if (version != JNI_VERSION_1_2 && version != JNI_VERSION_1_4)
return JNI_EVERSION;
JavaVMInitArgs *ia = reinterpret_cast<JavaVMInitArgs *> (args);
for (int i = 0; i < ia->nOptions; ++i)
@@ -2614,7 +2650,11 @@
_Jv_JNI_NewWeakGlobalRef, // NewWeakGlobalRef
_Jv_JNI_DeleteWeakGlobalRef, // DeleteWeakGlobalRef
- _Jv_JNI_ExceptionCheck
+ _Jv_JNI_ExceptionCheck, // ExceptionCheck
+
+ _Jv_JNI_NewDirectByteBuffer, // NewDirectByteBuffer
+ _Jv_JNI_GetDirectBufferAddress, // GetDirectBufferAddress
+ _Jv_JNI_GetDirectBufferCapacity // GetDirectBufferCapacity
};
struct JNIInvokeInterface _Jv_JNI_InvokeFunctions =
@@ -2626,5 +2666,6 @@
_Jv_JNI_DestroyJavaVM,
_Jv_JNI_AttachCurrentThread,
_Jv_JNI_DetachCurrentThread,
- _Jv_JNI_GetEnv
+ _Jv_JNI_GetEnv,
+ _Jv_JNI_AttachCurrentThreadAsDaemon
};
Index: gcj/cni.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gcj/cni.h,v
retrieving revision 1.8
diff -u -r1.8 cni.h
--- gcj/cni.h 22 May 2001 06:47:48 -0000 1.8
+++ gcj/cni.h 10 Apr 2002 19:54:16 -0000
@@ -2,7 +2,7 @@
// This file describes the Cygnus Native Interface, CNI.
// It provides a nicer interface to many of the things in gcj/javaprims.h.
-/* Copyright (C) 1998, 1999 Free Software Foundation
+/* Copyright (C) 1998, 1999, 2002 Free Software Foundation
This file is part of libgcj.
@@ -129,6 +129,12 @@
JvAttachCurrentThread (jstring name, java::lang::ThreadGroup* group)
{
return _Jv_AttachCurrentThread (name, group);
+}
+
+extern inline java::lang::Thread*
+JvAttachCurrentThreadAsDaemon (jstring name, java::lang::ThreadGroup* group)
+{
+ return _Jv_AttachCurrentThreadAsDaemon (name, group);
}
extern inline jint
Index: gcj/javaprims.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gcj/javaprims.h,v
retrieving revision 1.33
diff -u -r1.33 javaprims.h
--- gcj/javaprims.h 15 Feb 2002 03:21:47 -0000 1.33
+++ gcj/javaprims.h 10 Apr 2002 19:54:16 -0000
@@ -418,6 +418,8 @@
_Jv_AttachCurrentThread(java::lang::Thread* thread);
extern "C" java::lang::Thread*
_Jv_AttachCurrentThread(jstring name, java::lang::ThreadGroup* group);
+extern "C" java::lang::Thread*
+_Jv_AttachCurrentThreadAsDaemon(jstring name, java::lang::ThreadGroup* group);
extern "C" jint _Jv_DetachCurrentThread (void);
extern "C" void _Jv_Throw (jthrowable) __attribute__ ((__noreturn__));
Index: include/jni.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/jni.h,v
retrieving revision 1.20
diff -u -r1.20 jni.h
--- include/jni.h 19 Mar 2002 21:45:42 -0000 1.20
+++ include/jni.h 10 Apr 2002 19:54:18 -0000
@@ -161,6 +161,7 @@
/* Version numbers. */
#define JNI_VERSION_1_1 0x00010001
#define JNI_VERSION_1_2 0x00010002
+#define JNI_VERSION_1_4 0x00010004
/* Used when releasing array elements. */
#define JNI_COMMIT 1
@@ -641,6 +642,10 @@
void (*DeleteWeakGlobalRef) (JNIEnv *, jweak);
jboolean (*ExceptionCheck) (JNIEnv *);
+
+ jobject (*NewDirectByteBuffer) (JNIEnv *, void *, jlong);
+ void * (*GetDirectBufferAddress) (JNIEnv *, jobject);
+ jlong (*GetDirectBufferCapacity) (JNIEnv *, jobject);
};
#ifdef __cplusplus
@@ -1522,6 +1527,15 @@
jboolean ExceptionCheck ()
{ return p->ExceptionCheck (this); }
+
+ jobject NewDirectByteBuffer (void *addr, jlong capacity)
+ { return p->NewDirectByteBuffer (this, addr, capacity); }
+
+ void *GetDirectBufferAddress (jobject buf)
+ { return p->GetDirectBufferAddress (this, buf); }
+
+ jlong GetDirectBufferCapacity (jobject buf)
+ { return p->GetDirectBufferCapacity (this, buf); }
};
#endif /* __cplusplus */
@@ -1539,6 +1553,7 @@
jint (*AttachCurrentThread) (JavaVM *, void **, void *);
jint (*DetachCurrentThread) (JavaVM *);
jint (*GetEnv) (JavaVM *, void **, jint);
+ jint (*AttachCurrentThreadAsDaemon) (JavaVM *, void **, void *);
};
#ifdef __cplusplus
@@ -1563,6 +1578,9 @@
jint GetEnv (void **penv, jint version)
{ return functions->GetEnv (this, penv, version); }
+
+ jint AttachCurrentThreadAsDaemon (void **penv, void *args)
+ { return functions->AttachCurrentThreadAsDaemon (this, penv, args); }
};
#endif /* __cplusplus */
Index: java/lang/natRuntime.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natRuntime.cc,v
retrieving revision 1.20
diff -u -r1.20 natRuntime.cc
--- java/lang/natRuntime.cc 16 Oct 2001 08:35:17 -0000 1.20
+++ java/lang/natRuntime.cc 10 Apr 2002 19:54:18 -0000
@@ -1,6 +1,6 @@
// natRuntime.cc - Implementation of native side of Runtime class.
-/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation
This file is part of libgcj.
@@ -167,7 +167,8 @@
return;
}
jint vers = ((jint (*) (JavaVM *, void *)) onload) (vm, NULL);
- if (vers != JNI_VERSION_1_1 && vers != JNI_VERSION_1_2)
+ if (vers != JNI_VERSION_1_1 && vers != JNI_VERSION_1_2
+ && vers != JNI_VERSION_1_4)
{
// FIXME: unload the library.
throw new UnsatisfiedLinkError (JvNewStringLatin1 ("unrecognized version from JNI_OnLoad"));
Index: java/lang/natThread.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natThread.cc,v
retrieving revision 1.23
diff -u -r1.23 natThread.cc
--- java/lang/natThread.cc 26 Aug 2001 11:30:09 -0000 1.23
+++ java/lang/natThread.cc 10 Apr 2002 19:54:18 -0000
@@ -1,6 +1,6 @@
// natThread.cc - Native part of Thread class.
-/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation
This file is part of libgcj.
@@ -405,6 +405,21 @@
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;
More information about the Java-patches
mailing list