1 // jni.cc - JNI implementation, including the jump table.
3 /* Copyright (C) 1998, 1999, 2000 Free Software Foundation
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
16 // Define this before including jni.h.
17 #define __GCJ_JNI_IMPL__
21 #include <java-assert.h>
27 #include <java/lang/Class.h>
28 #include <java/lang/ClassLoader.h>
29 #include <java/lang/Throwable.h>
30 #include <java/lang/ArrayIndexOutOfBoundsException.h>
31 #include <java/lang/StringIndexOutOfBoundsException.h>
32 #include <java/lang/AbstractMethodError.h>
33 #include <java/lang/InstantiationException.h>
34 #include <java/lang/NoSuchFieldError.h>
35 #include <java/lang/NoSuchMethodError.h>
36 #include <java/lang/reflect/Constructor.h>
37 #include <java/lang/reflect/Method.h>
38 #include <java/lang/reflect/Modifier.h>
39 #include <java/lang/OutOfMemoryError.h>
40 #include <java/util/Hashtable.h>
41 #include <java/lang/Integer.h>
42 #include <gnu/gcj/jni/NativeThread.h>
44 #include <gcj/method.h>
45 #include <gcj/field.h>
47 #include <java-interp.h>
49 #define ClassClass _CL_Q34java4lang5Class
50 extern java::lang::Class ClassClass;
51 #define ObjectClass _CL_Q34java4lang6Object
52 extern java::lang::Class ObjectClass;
54 #define ThrowableClass _CL_Q34java4lang9Throwable
55 extern java::lang::Class ThrowableClass;
56 #define MethodClass _CL_Q44java4lang7reflect6Method
57 extern java::lang::Class MethodClass;
58 #define ThreadGroupClass _CL_Q34java4lang11ThreadGroup
59 extern java::lang::Class ThreadGroupClass;
60 #define NativeThreadClass _CL_Q43gnu3gcj3jni12NativeThread
61 extern java::lang::Class ThreadGroupClass;
63 // This enum is used to select different template instantiations in
64 // the invocation code.
73 // Forward declarations.
74 extern struct JNINativeInterface _Jv_JNIFunctions;
75 extern struct JNIInvokeInterface _Jv_JNI_InvokeFunctions;
77 // Number of slots in the default frame. The VM must allow at least
81 // Mark value indicating this is an overflow frame.
83 // Mark value indicating this is a user frame.
85 // Mark value indicating this is a system frame.
88 // This structure is used to keep track of local references.
89 struct _Jv_JNI_LocalFrame
91 // This is true if this frame object represents a pushed frame (eg
92 // from PushLocalFrame).
95 // Number of elements in frame.
98 // Next frame in chain.
99 _Jv_JNI_LocalFrame *next;
101 // The elements. These are allocated using the C "struct hack".
105 // This holds a reference count for all local and global references.
106 static java::util::Hashtable *ref_table;
109 static JavaVM *the_vm;
112 // The only JVMPI interface description.
113 static JVMPI_Interface _Jv_JVMPI_Interface;
116 jvmpiEnableEvent (jint event_type, void *)
120 case JVMPI_EVENT_OBJECT_ALLOC:
121 _Jv_JVMPI_Notify_OBJECT_ALLOC = _Jv_JVMPI_Interface.NotifyEvent;
124 case JVMPI_EVENT_THREAD_START:
125 _Jv_JVMPI_Notify_THREAD_START = _Jv_JVMPI_Interface.NotifyEvent;
128 case JVMPI_EVENT_THREAD_END:
129 _Jv_JVMPI_Notify_THREAD_END = _Jv_JVMPI_Interface.NotifyEvent;
133 return JVMPI_NOT_AVAILABLE;
136 return JVMPI_SUCCESS;
140 jvmpiDisableEvent (jint event_type, void *)
144 case JVMPI_EVENT_OBJECT_ALLOC:
145 _Jv_JVMPI_Notify_OBJECT_ALLOC = NULL;
149 return JVMPI_NOT_AVAILABLE;
152 return JVMPI_SUCCESS;
161 ref_table = new java::util::Hashtable;
164 _Jv_JVMPI_Interface.version = 1;
165 _Jv_JVMPI_Interface.EnableEvent = &jvmpiEnableEvent;
166 _Jv_JVMPI_Interface.DisableEvent = &jvmpiDisableEvent;
167 _Jv_JVMPI_Interface.EnableGC = &_Jv_EnableGC;
168 _Jv_JVMPI_Interface.DisableGC = &_Jv_DisableGC;
169 _Jv_JVMPI_Interface.RunGC = &_Jv_RunGC;
173 // Tell the GC that a certain pointer is live.
175 mark_for_gc (jobject obj)
177 JvSynchronize sync (ref_table);
179 using namespace java::lang;
180 Integer *refcount = (Integer *) ref_table->get (obj);
181 jint val = (refcount == NULL) ? 0 : refcount->intValue ();
182 // FIXME: what about out of memory error?
183 ref_table->put (obj, new Integer (val + 1));
188 unmark_for_gc (jobject obj)
190 JvSynchronize sync (ref_table);
192 using namespace java::lang;
193 Integer *refcount = (Integer *) ref_table->get (obj);
195 jint val = refcount->intValue () - 1;
197 ref_table->remove (obj);
199 // FIXME: what about out of memory error?
200 ref_table->put (obj, new Integer (val));
206 _Jv_JNI_NewGlobalRef (JNIEnv *, jobject obj)
213 _Jv_JNI_DeleteGlobalRef (JNIEnv *, jobject obj)
219 _Jv_JNI_DeleteLocalRef (JNIEnv *env, jobject obj)
221 _Jv_JNI_LocalFrame *frame;
223 for (frame = env->locals; frame != NULL; frame = frame->next)
225 for (int i = 0; i < FRAME_SIZE; ++i)
227 if (frame->vec[i] == obj)
229 frame->vec[i] = NULL;
235 // Don't go past a marked frame.
236 JvAssert (frame->marker == MARK_NONE);
243 _Jv_JNI_EnsureLocalCapacity (JNIEnv *env, jint size)
245 // It is easier to just always allocate a new frame of the requested
246 // size. This isn't the most efficient thing, but for now we don't
247 // care. Note that _Jv_JNI_PushLocalFrame relies on this right now.
249 _Jv_JNI_LocalFrame *frame;
252 frame = (_Jv_JNI_LocalFrame *) _Jv_Malloc (sizeof (_Jv_JNI_LocalFrame)
253 + size * sizeof (jobject));
261 frame->marker = MARK_NONE;
263 memset (&frame->vec[0], 0, size * sizeof (jobject));
264 frame->next = env->locals;
271 _Jv_JNI_PushLocalFrame (JNIEnv *env, jint size)
273 jint r = _Jv_JNI_EnsureLocalCapacity (env, size);
277 // The new frame is on top.
278 env->locals->marker = MARK_USER;
284 _Jv_JNI_NewLocalRef (JNIEnv *env, jobject obj)
286 // Try to find an open slot somewhere in the topmost frame.
287 _Jv_JNI_LocalFrame *frame = env->locals;
288 bool done = false, set = false;
289 while (frame != NULL && ! done)
291 for (int i = 0; i < frame->size; ++i)
292 if (frame->vec[i] == NULL)
303 // No slots, so we allocate a new frame. According to the spec
304 // we could just die here. FIXME: return value.
305 _Jv_JNI_EnsureLocalCapacity (env, 16);
306 // We know the first element of the new frame will be ok.
307 env->locals->vec[0] = obj;
315 _Jv_JNI_PopLocalFrame (JNIEnv *env, jobject result, int stop)
317 _Jv_JNI_LocalFrame *rf = env->locals;
320 while (rf != NULL && ! done)
322 for (int i = 0; i < rf->size; ++i)
323 if (rf->vec[i] != NULL)
324 unmark_for_gc (rf->vec[i]);
326 // If the frame we just freed is the marker frame, we are done.
327 done = (rf->marker == stop);
329 _Jv_JNI_LocalFrame *n = rf->next;
330 // When N==NULL, we've reached the stack-allocated frame, and we
331 // must not free it. However, we must be sure to clear all its
332 // elements, since we might conceivably reuse it.
335 memset (&rf->vec[0], 0, rf->size * sizeof (jobject));
343 return result == NULL ? NULL : _Jv_JNI_NewLocalRef (env, result);
347 _Jv_JNI_PopLocalFrame (JNIEnv *env, jobject result)
349 return _Jv_JNI_PopLocalFrame (env, result, MARK_USER);
352 // Pop a `system' frame from the stack. This is `extern "C"' as it is
353 // used by the compiler.
355 _Jv_JNI_PopSystemFrame (JNIEnv *env)
357 _Jv_JNI_PopLocalFrame (env, NULL, MARK_SYSTEM);
363 // This function is used from other template functions. It wraps the
364 // return value appropriately; we specialize it so that object returns
365 // are turned into local references.
368 wrap_value (JNIEnv *, T value)
375 wrap_value (JNIEnv *env, jobject value)
377 return value == NULL ? value : _Jv_JNI_NewLocalRef (env, value);
383 _Jv_JNI_GetVersion (JNIEnv *)
385 return JNI_VERSION_1_2;
389 _Jv_JNI_DefineClass (JNIEnv *env, jobject loader,
390 const jbyte *buf, jsize bufLen)
394 jbyteArray bytes = JvNewByteArray (bufLen);
396 jbyte *elts = elements (bytes);
397 memcpy (elts, buf, bufLen * sizeof (jbyte));
399 java::lang::ClassLoader *l
400 = reinterpret_cast<java::lang::ClassLoader *> (loader);
402 jclass result = l->defineClass (bytes, 0, bufLen);
403 return (jclass) wrap_value (env, result);
413 _Jv_JNI_FindClass (JNIEnv *env, const char *name)
415 // FIXME: assume that NAME isn't too long.
416 int len = strlen (name);
418 for (int i = 0; i <= len; ++i)
419 s[i] = (name[i] == '/') ? '.' : name[i];
424 // This might throw an out of memory exception.
425 jstring n = JvNewStringUTF (s);
427 java::lang::ClassLoader *loader = NULL;
428 if (env->klass != NULL)
429 loader = env->klass->getClassLoader ();
433 // FIXME: should use getBaseClassLoader, but we don't have that
435 loader = java::lang::ClassLoader::getSystemClassLoader ();
438 r = loader->loadClass (n);
445 return (jclass) wrap_value (env, r);
449 _Jv_JNI_GetSuperclass (JNIEnv *env, jclass clazz)
451 return (jclass) wrap_value (env, clazz->getSuperclass ());
455 _Jv_JNI_IsAssignableFrom(JNIEnv *, jclass clazz1, jclass clazz2)
457 return clazz1->isAssignableFrom (clazz2);
461 _Jv_JNI_Throw (JNIEnv *env, jthrowable obj)
463 // We check in case the user did some funky cast.
464 JvAssert (obj != NULL && (&ThrowableClass)->isInstance (obj));
470 _Jv_JNI_ThrowNew (JNIEnv *env, jclass clazz, const char *message)
472 using namespace java::lang::reflect;
474 JvAssert ((&ThrowableClass)->isAssignableFrom (clazz));
479 JArray<jclass> *argtypes
480 = (JArray<jclass> *) JvNewObjectArray (1, &ClassClass, NULL);
482 jclass *elts = elements (argtypes);
483 elts[0] = &StringClass;
485 Constructor *cons = clazz->getConstructor (argtypes);
487 jobjectArray values = JvNewObjectArray (1, &StringClass, NULL);
488 jobject *velts = elements (values);
489 velts[0] = JvNewStringUTF (message);
491 jobject obj = cons->newInstance (values);
493 env->ex = reinterpret_cast<jthrowable> (obj);
505 _Jv_JNI_ExceptionOccurred (JNIEnv *env)
507 return (jthrowable) wrap_value (env, env->ex);
511 _Jv_JNI_ExceptionDescribe (JNIEnv *env)
514 env->ex->printStackTrace();
518 _Jv_JNI_ExceptionClear (JNIEnv *env)
524 _Jv_JNI_ExceptionCheck (JNIEnv *env)
526 return env->ex != NULL;
530 _Jv_JNI_FatalError (JNIEnv *, const char *message)
538 _Jv_JNI_IsSameObject (JNIEnv *, jobject obj1, jobject obj2)
544 _Jv_JNI_AllocObject (JNIEnv *env, jclass clazz)
547 using namespace java::lang::reflect;
551 JvAssert (clazz && ! clazz->isArray ());
552 if (clazz->isInterface() || Modifier::isAbstract(clazz->getModifiers()))
553 env->ex = new java::lang::InstantiationException ();
556 // FIXME: will this work for String?
557 obj = JvAllocObject (clazz);
565 return wrap_value (env, obj);
569 _Jv_JNI_GetObjectClass (JNIEnv *env, jobject obj)
572 return (jclass) wrap_value (env, obj->getClass());
576 _Jv_JNI_IsInstanceOf (JNIEnv *, jobject obj, jclass clazz)
578 return clazz->isInstance(obj);
584 // This section concerns method invocation.
587 template<jboolean is_static>
589 _Jv_JNI_GetAnyMethodID (JNIEnv *env, jclass clazz,
590 const char *name, const char *sig)
594 _Jv_InitClass (clazz);
596 _Jv_Utf8Const *name_u = _Jv_makeUtf8Const ((char *) name, -1);
597 _Jv_Utf8Const *sig_u = _Jv_makeUtf8Const ((char *) sig, -1);
599 JvAssert (! clazz->isPrimitive());
601 using namespace java::lang::reflect;
603 while (clazz != NULL)
605 jint count = JvNumMethods (clazz);
606 jmethodID meth = JvGetFirstMethod (clazz);
608 for (jint i = 0; i < count; ++i)
610 if (((is_static && Modifier::isStatic (meth->accflags))
611 || (! is_static && ! Modifier::isStatic (meth->accflags)))
612 && _Jv_equalUtf8Consts (meth->name, name_u)
613 && _Jv_equalUtf8Consts (meth->signature, sig_u))
616 meth = meth->getNextMethod();
619 clazz = clazz->getSuperclass ();
622 env->ex = new java::lang::NoSuchMethodError ();
632 // This is a helper function which turns a va_list into an array of
633 // `jvalue's. It needs signature information in order to do its work.
634 // The array of values must already be allocated.
636 array_from_valist (jvalue *values, JArray<jclass> *arg_types, va_list vargs)
638 jclass *arg_elts = elements (arg_types);
639 for (int i = 0; i < arg_types->length; ++i)
641 if (arg_elts[i] == JvPrimClass (byte))
642 values[i].b = va_arg (vargs, jbyte);
643 else if (arg_elts[i] == JvPrimClass (short))
644 values[i].s = va_arg (vargs, jshort);
645 else if (arg_elts[i] == JvPrimClass (int))
646 values[i].i = va_arg (vargs, jint);
647 else if (arg_elts[i] == JvPrimClass (long))
648 values[i].j = va_arg (vargs, jlong);
649 else if (arg_elts[i] == JvPrimClass (float))
650 values[i].f = va_arg (vargs, jfloat);
651 else if (arg_elts[i] == JvPrimClass (double))
652 values[i].d = va_arg (vargs, jdouble);
653 else if (arg_elts[i] == JvPrimClass (boolean))
654 values[i].z = va_arg (vargs, jboolean);
655 else if (arg_elts[i] == JvPrimClass (char))
656 values[i].c = va_arg (vargs, jchar);
660 values[i].l = va_arg (vargs, jobject);
665 // This can call any sort of method: virtual, "nonvirtual", static, or
667 template<typename T, invocation_type style>
669 _Jv_JNI_CallAnyMethodV (JNIEnv *env, jobject obj, jclass klass,
670 jmethodID id, va_list vargs)
673 id = _Jv_LookupDeclaredMethod (obj->getClass (), id->name, id->signature);
675 jclass decl_class = klass ? klass : obj->getClass ();
676 JvAssert (decl_class != NULL);
679 JArray<jclass> *arg_types;
683 _Jv_GetTypesFromSignature (id, decl_class,
684 &arg_types, &return_type);
686 jvalue args[arg_types->length];
687 array_from_valist (args, arg_types, vargs);
689 // For constructors we need to pass the Class we are instantiating.
690 if (style == constructor)
694 jthrowable ex = _Jv_CallAnyMethodA (obj, return_type, id,
695 style == constructor,
696 arg_types, args, &result);
701 // We cheat a little here. FIXME.
702 return wrap_value (env, * (T *) &result);
709 return wrap_value (env, (T) 0);
712 template<typename T, invocation_type style>
714 _Jv_JNI_CallAnyMethod (JNIEnv *env, jobject obj, jclass klass,
715 jmethodID method, ...)
720 va_start (args, method);
721 result = _Jv_JNI_CallAnyMethodV<T, style> (env, obj, klass, method, args);
727 template<typename T, invocation_type style>
729 _Jv_JNI_CallAnyMethodA (JNIEnv *env, jobject obj, jclass klass,
730 jmethodID id, jvalue *args)
733 id = _Jv_LookupDeclaredMethod (obj->getClass (), id->name, id->signature);
735 jclass decl_class = klass ? klass : obj->getClass ();
736 JvAssert (decl_class != NULL);
739 JArray<jclass> *arg_types;
742 _Jv_GetTypesFromSignature (id, decl_class,
743 &arg_types, &return_type);
745 // For constructors we need to pass the Class we are instantiating.
746 if (style == constructor)
750 jthrowable ex = _Jv_CallAnyMethodA (obj, return_type, id,
751 style == constructor,
752 arg_types, args, &result);
757 // We cheat a little here. FIXME.
758 return wrap_value (env, * (T *) &result);
765 return wrap_value (env, (T) 0);
768 template<invocation_type style>
770 _Jv_JNI_CallAnyVoidMethodV (JNIEnv *env, jobject obj, jclass klass,
771 jmethodID id, va_list vargs)
774 id = _Jv_LookupDeclaredMethod (obj->getClass (), id->name, id->signature);
776 jclass decl_class = klass ? klass : obj->getClass ();
777 JvAssert (decl_class != NULL);
780 JArray<jclass> *arg_types;
783 _Jv_GetTypesFromSignature (id, decl_class,
784 &arg_types, &return_type);
786 jvalue args[arg_types->length];
787 array_from_valist (args, arg_types, vargs);
789 // For constructors we need to pass the Class we are instantiating.
790 if (style == constructor)
793 jthrowable ex = _Jv_CallAnyMethodA (obj, return_type, id,
794 style == constructor,
795 arg_types, args, NULL);
806 template<invocation_type style>
808 _Jv_JNI_CallAnyVoidMethod (JNIEnv *env, jobject obj, jclass klass,
809 jmethodID method, ...)
813 va_start (args, method);
814 _Jv_JNI_CallAnyVoidMethodV<style> (env, obj, klass, method, args);
818 template<invocation_type style>
820 _Jv_JNI_CallAnyVoidMethodA (JNIEnv *env, jobject obj, jclass klass,
821 jmethodID id, jvalue *args)
824 id = _Jv_LookupDeclaredMethod (obj->getClass (), id->name, id->signature);
826 jclass decl_class = klass ? klass : obj->getClass ();
827 JvAssert (decl_class != NULL);
830 JArray<jclass> *arg_types;
833 _Jv_GetTypesFromSignature (id, decl_class,
834 &arg_types, &return_type);
836 jthrowable ex = _Jv_CallAnyMethodA (obj, return_type, id,
837 style == constructor,
838 arg_types, args, NULL);
849 // Functions with this signature are used to implement functions in
850 // the CallMethod family.
853 _Jv_JNI_CallMethodV (JNIEnv *env, jobject obj, jmethodID id, va_list args)
855 return _Jv_JNI_CallAnyMethodV<T, normal> (env, obj, NULL, id, args);
858 // Functions with this signature are used to implement functions in
859 // the CallMethod family.
862 _Jv_JNI_CallMethod (JNIEnv *env, jobject obj, jmethodID id, ...)
868 result = _Jv_JNI_CallAnyMethodV<T, normal> (env, obj, NULL, id, args);
874 // Functions with this signature are used to implement functions in
875 // the CallMethod family.
878 _Jv_JNI_CallMethodA (JNIEnv *env, jobject obj, jmethodID id, jvalue *args)
880 return _Jv_JNI_CallAnyMethodA<T, normal> (env, obj, NULL, id, args);
884 _Jv_JNI_CallVoidMethodV (JNIEnv *env, jobject obj, jmethodID id, va_list args)
886 _Jv_JNI_CallAnyVoidMethodV<normal> (env, obj, NULL, id, args);
890 _Jv_JNI_CallVoidMethod (JNIEnv *env, jobject obj, jmethodID id, ...)
895 _Jv_JNI_CallAnyVoidMethodV<normal> (env, obj, NULL, id, args);
900 _Jv_JNI_CallVoidMethodA (JNIEnv *env, jobject obj, jmethodID id, jvalue *args)
902 _Jv_JNI_CallAnyVoidMethodA<normal> (env, obj, NULL, id, args);
905 // Functions with this signature are used to implement functions in
906 // the CallStaticMethod family.
909 _Jv_JNI_CallStaticMethodV (JNIEnv *env, jclass klass,
910 jmethodID id, va_list args)
912 JvAssert (((id->accflags) & java::lang::reflect::Modifier::STATIC));
913 JvAssert ((&ClassClass)->isInstance (klass));
915 return _Jv_JNI_CallAnyMethodV<T, static_type> (env, NULL, klass, id, args);
918 // Functions with this signature are used to implement functions in
919 // the CallStaticMethod family.
922 _Jv_JNI_CallStaticMethod (JNIEnv *env, jclass klass, jmethodID id, ...)
927 JvAssert (((id->accflags) & java::lang::reflect::Modifier::STATIC));
928 JvAssert ((&ClassClass)->isInstance (klass));
931 result = _Jv_JNI_CallAnyMethodV<T, static_type> (env, NULL, klass,
938 // Functions with this signature are used to implement functions in
939 // the CallStaticMethod family.
942 _Jv_JNI_CallStaticMethodA (JNIEnv *env, jclass klass, jmethodID id,
945 JvAssert (((id->accflags) & java::lang::reflect::Modifier::STATIC));
946 JvAssert ((&ClassClass)->isInstance (klass));
948 return _Jv_JNI_CallAnyMethodA<T, static_type> (env, NULL, klass, id, args);
952 _Jv_JNI_CallStaticVoidMethodV (JNIEnv *env, jclass klass, jmethodID id,
955 _Jv_JNI_CallAnyVoidMethodV<static_type> (env, NULL, klass, id, args);
959 _Jv_JNI_CallStaticVoidMethod (JNIEnv *env, jclass klass, jmethodID id, ...)
964 _Jv_JNI_CallAnyVoidMethodV<static_type> (env, NULL, klass, id, args);
969 _Jv_JNI_CallStaticVoidMethodA (JNIEnv *env, jclass klass, jmethodID id,
972 _Jv_JNI_CallAnyVoidMethodA<static_type> (env, NULL, klass, id, args);
976 _Jv_JNI_NewObjectV (JNIEnv *env, jclass klass,
977 jmethodID id, va_list args)
979 JvAssert (klass && ! klass->isArray ());
980 JvAssert (! strcmp (id->name->data, "<init>")
981 && id->signature->length > 2
982 && id->signature->data[0] == '('
983 && ! strcmp (&id->signature->data[id->signature->length - 2],
986 return _Jv_JNI_CallAnyMethodV<jobject, constructor> (env, NULL, klass,
991 _Jv_JNI_NewObject (JNIEnv *env, jclass klass, jmethodID id, ...)
993 JvAssert (klass && ! klass->isArray ());
994 JvAssert (! strcmp (id->name->data, "<init>")
995 && id->signature->length > 2
996 && id->signature->data[0] == '('
997 && ! strcmp (&id->signature->data[id->signature->length - 2],
1003 va_start (args, id);
1004 result = _Jv_JNI_CallAnyMethodV<jobject, constructor> (env, NULL, klass,
1012 _Jv_JNI_NewObjectA (JNIEnv *env, jclass klass, jmethodID id,
1015 JvAssert (klass && ! klass->isArray ());
1016 JvAssert (! strcmp (id->name->data, "<init>")
1017 && id->signature->length > 2
1018 && id->signature->data[0] == '('
1019 && ! strcmp (&id->signature->data[id->signature->length - 2],
1022 return _Jv_JNI_CallAnyMethodA<jobject, constructor> (env, NULL, klass,
1028 template<typename T>
1030 _Jv_JNI_GetField (JNIEnv *env, jobject obj, jfieldID field)
1033 T *ptr = (T *) ((char *) obj + field->getOffset ());
1034 return wrap_value (env, *ptr);
1037 template<typename T>
1039 _Jv_JNI_SetField (JNIEnv *, jobject obj, jfieldID field, T value)
1042 T *ptr = (T *) ((char *) obj + field->getOffset ());
1046 template<jboolean is_static>
1048 _Jv_JNI_GetAnyFieldID (JNIEnv *env, jclass clazz,
1049 const char *name, const char *sig)
1053 _Jv_InitClass (clazz);
1055 _Jv_Utf8Const *a_name = _Jv_makeUtf8Const ((char *) name, -1);
1057 jclass field_class = NULL;
1059 field_class = _Jv_FindClassFromSignature ((char *) sig, NULL);
1062 _Jv_Utf8Const *sig_u = _Jv_makeUtf8Const ((char *) sig, -1);
1063 field_class = _Jv_FindClass (sig_u, NULL);
1066 // FIXME: what if field_class == NULL?
1068 while (clazz != NULL)
1070 jint count = (is_static
1071 ? JvNumStaticFields (clazz)
1072 : JvNumInstanceFields (clazz));
1073 jfieldID field = (is_static
1074 ? JvGetFirstStaticField (clazz)
1075 : JvGetFirstInstanceField (clazz));
1076 for (jint i = 0; i < count; ++i)
1078 // The field is resolved as a side effect of class
1080 JvAssert (field->isResolved ());
1082 _Jv_Utf8Const *f_name = field->getNameUtf8Const(clazz);
1084 if (_Jv_equalUtf8Consts (f_name, a_name)
1085 && field->getClass() == field_class)
1088 field = field->getNextField ();
1091 clazz = clazz->getSuperclass ();
1094 env->ex = new java::lang::NoSuchFieldError ();
1096 catch (jthrowable t)
1103 template<typename T>
1105 _Jv_JNI_GetStaticField (JNIEnv *env, jclass, jfieldID field)
1107 T *ptr = (T *) field->u.addr;
1108 return wrap_value (env, *ptr);
1111 template<typename T>
1113 _Jv_JNI_SetStaticField (JNIEnv *, jclass, jfieldID field, T value)
1115 T *ptr = (T *) field->u.addr;
1120 _Jv_JNI_NewString (JNIEnv *env, const jchar *unichars, jsize len)
1124 jstring r = _Jv_NewString (unichars, len);
1125 return (jstring) wrap_value (env, r);
1127 catch (jthrowable t)
1135 _Jv_JNI_GetStringLength (JNIEnv *, jstring string)
1137 return string->length();
1140 static const jchar *
1141 _Jv_JNI_GetStringChars (JNIEnv *, jstring string, jboolean *isCopy)
1143 jchar *result = _Jv_GetStringChars (string);
1144 mark_for_gc (string);
1147 return (const jchar *) result;
1151 _Jv_JNI_ReleaseStringChars (JNIEnv *, jstring string, const jchar *)
1153 unmark_for_gc (string);
1157 _Jv_JNI_NewStringUTF (JNIEnv *env, const char *bytes)
1161 jstring result = JvNewStringUTF (bytes);
1162 return (jstring) wrap_value (env, result);
1164 catch (jthrowable t)
1172 _Jv_JNI_GetStringUTFLength (JNIEnv *, jstring string)
1174 return JvGetStringUTFLength (string);
1178 _Jv_JNI_GetStringUTFChars (JNIEnv *env, jstring string, jboolean *isCopy)
1180 jsize len = JvGetStringUTFLength (string);
1183 char *r = (char *) _Jv_Malloc (len + 1);
1184 JvGetStringUTFRegion (string, 0, len, r);
1190 return (const char *) r;
1192 catch (jthrowable t)
1200 _Jv_JNI_ReleaseStringUTFChars (JNIEnv *, jstring, const char *utf)
1202 _Jv_Free ((void *) utf);
1206 _Jv_JNI_GetStringRegion (JNIEnv *env, jstring string, jsize start, jsize len,
1209 jchar *result = _Jv_GetStringChars (string);
1210 if (start < 0 || start > string->length ()
1211 || len < 0 || start + len > string->length ())
1215 env->ex = new java::lang::StringIndexOutOfBoundsException ();
1217 catch (jthrowable t)
1223 memcpy (buf, &result[start], len * sizeof (jchar));
1227 _Jv_JNI_GetStringUTFRegion (JNIEnv *env, jstring str, jsize start,
1228 jsize len, char *buf)
1230 if (start < 0 || start > str->length ()
1231 || len < 0 || start + len > str->length ())
1235 env->ex = new java::lang::StringIndexOutOfBoundsException ();
1237 catch (jthrowable t)
1243 _Jv_GetStringUTFRegion (str, start, len, buf);
1246 static const jchar *
1247 _Jv_JNI_GetStringCritical (JNIEnv *, jstring str, jboolean *isCopy)
1249 jchar *result = _Jv_GetStringChars (str);
1256 _Jv_JNI_ReleaseStringCritical (JNIEnv *, jstring, const jchar *)
1262 _Jv_JNI_GetArrayLength (JNIEnv *, jarray array)
1264 return array->length;
1268 _Jv_JNI_NewObjectArray (JNIEnv *env, jsize length, jclass elementClass,
1273 jarray result = JvNewObjectArray (length, elementClass, init);
1274 return (jarray) wrap_value (env, result);
1276 catch (jthrowable t)
1284 _Jv_JNI_GetObjectArrayElement (JNIEnv *env, jobjectArray array, jsize index)
1286 jobject *elts = elements (array);
1287 return wrap_value (env, elts[index]);
1291 _Jv_JNI_SetObjectArrayElement (JNIEnv *env, jobjectArray array, jsize index,
1296 _Jv_CheckArrayStore (array, value);
1297 jobject *elts = elements (array);
1298 elts[index] = value;
1300 catch (jthrowable t)
1306 template<typename T, jclass K>
1308 _Jv_JNI_NewPrimitiveArray (JNIEnv *env, jsize length)
1312 return (JArray<T> *) wrap_value (env, _Jv_NewPrimArray (K, length));
1314 catch (jthrowable t)
1321 template<typename T>
1323 _Jv_JNI_GetPrimitiveArrayElements (JNIEnv *, JArray<T> *array,
1326 T *elts = elements (array);
1329 // We elect never to copy.
1332 mark_for_gc (array);
1336 template<typename T>
1338 _Jv_JNI_ReleasePrimitiveArrayElements (JNIEnv *, JArray<T> *array,
1339 T *, jint /* mode */)
1341 // Note that we ignore MODE. We can do this because we never copy
1342 // the array elements. My reading of the JNI documentation is that
1343 // this is an option for the implementor.
1344 unmark_for_gc (array);
1347 template<typename T>
1349 _Jv_JNI_GetPrimitiveArrayRegion (JNIEnv *env, JArray<T> *array,
1350 jsize start, jsize len,
1353 if (start < 0 || len >= array->length || start + len >= array->length)
1358 env->ex = new java::lang::ArrayIndexOutOfBoundsException ();
1360 catch (jthrowable t)
1362 // Could have thown out of memory error.
1368 T *elts = elements (array) + start;
1369 memcpy (buf, elts, len * sizeof (T));
1373 template<typename T>
1375 _Jv_JNI_SetPrimitiveArrayRegion (JNIEnv *env, JArray<T> *array,
1376 jsize start, jsize len, T *buf)
1378 if (start < 0 || len >= array->length || start + len >= array->length)
1383 env->ex = new java::lang::ArrayIndexOutOfBoundsException ();
1385 catch (jthrowable t)
1392 T *elts = elements (array) + start;
1393 memcpy (elts, buf, len * sizeof (T));
1398 _Jv_JNI_GetPrimitiveArrayCritical (JNIEnv *, jarray array,
1401 // FIXME: does this work?
1402 jclass klass = array->getClass()->getComponentType();
1403 JvAssert (klass->isPrimitive ());
1404 char *r = _Jv_GetArrayElementFromElementType (array, klass);
1411 _Jv_JNI_ReleasePrimitiveArrayCritical (JNIEnv *, jarray, void *, jint)
1417 _Jv_JNI_MonitorEnter (JNIEnv *env, jobject obj)
1421 return _Jv_MonitorEnter (obj);
1423 catch (jthrowable t)
1431 _Jv_JNI_MonitorExit (JNIEnv *env, jobject obj)
1435 return _Jv_MonitorExit (obj);
1437 catch (jthrowable t)
1446 _Jv_JNI_ToReflectedField (JNIEnv *env, jclass cls, jfieldID fieldID,
1451 java::lang::reflect::Field *field = new java::lang::reflect::Field();
1452 field->declaringClass = cls;
1453 field->offset = (char*) fieldID - (char *) cls->fields;
1454 field->name = _Jv_NewStringUtf8Const (fieldID->getNameUtf8Const (cls));
1455 return wrap_value (env, field);
1457 catch (jthrowable t)
1466 _Jv_JNI_FromReflectedField (JNIEnv *, jobject f)
1468 using namespace java::lang::reflect;
1470 Field *field = reinterpret_cast<Field *> (f);
1471 return _Jv_FromReflectedField (field);
1475 _Jv_JNI_ToReflectedMethod (JNIEnv *env, jclass klass, jmethodID id,
1478 using namespace java::lang::reflect;
1481 static _Jv_Utf8Const *init_name = _Jv_makeUtf8Const ("<init>", 6);
1483 jobject result = NULL;
1487 if (_Jv_equalUtf8Consts (id->name, init_name))
1490 Constructor *cons = new Constructor ();
1491 cons->offset = (char *) id - (char *) &klass->methods;
1492 cons->declaringClass = klass;
1497 Method *meth = new Method ();
1498 meth->offset = (char *) id - (char *) &klass->methods;
1499 meth->declaringClass = klass;
1503 catch (jthrowable t)
1508 return wrap_value (env, result);
1512 _Jv_JNI_FromReflectedMethod (JNIEnv *, jobject method)
1514 using namespace java::lang::reflect;
1515 if ((&MethodClass)->isInstance (method))
1516 return _Jv_FromReflectedMethod (reinterpret_cast<Method *> (method));
1518 _Jv_FromReflectedConstructor (reinterpret_cast<Constructor *> (method));
1522 _Jv_JNI_RegisterNatives (JNIEnv *env, jclass k,
1523 const JNINativeMethod *methods,
1527 // For now, this only matters for interpreted methods. FIXME.
1528 if (! _Jv_IsInterpretedClass (k))
1530 // FIXME: throw exception.
1533 _Jv_InterpClass *klass = reinterpret_cast<_Jv_InterpClass *> (k);
1535 // Look at each descriptor given us, and find the corresponding
1536 // method in the class.
1537 for (int j = 0; j < nMethods; ++j)
1541 _Jv_MethodBase **imeths = _Jv_GetFirstMethod (klass);
1542 for (int i = 0; i < JvNumMethods (klass); ++i)
1544 _Jv_MethodBase *meth = imeths[i];
1545 _Jv_Method *self = meth->get_method ();
1547 if (! strcmp (self->name->data, methods[j].name)
1548 && ! strcmp (self->signature->data, methods[j].signature))
1550 if (! (self->accflags
1551 & java::lang::reflect::Modifier::NATIVE))
1554 // Found a match that is native.
1555 _Jv_JNIMethod *jmeth = reinterpret_cast<_Jv_JNIMethod *> (meth);
1556 jmeth->set_function (methods[i].fnPtr);
1564 jstring m = JvNewStringUTF (methods[j].name);
1567 env->ex =new java::lang::NoSuchMethodError (m);
1569 catch (jthrowable t)
1578 #else /* INTERPRETER */
1580 #endif /* INTERPRETER */
1584 _Jv_JNI_UnregisterNatives (JNIEnv *, jclass)
1593 // Add a character to the buffer, encoding properly.
1595 add_char (char *buf, jchar c, int *here)
1599 buf[(*here)++] = '_';
1600 buf[(*here)++] = '1';
1604 buf[(*here)++] = '_';
1605 buf[(*here)++] = '2';
1609 buf[(*here)++] = '_';
1610 buf[(*here)++] = '3';
1613 buf[(*here)++] = '_';
1614 else if ((c >= '0' && c <= '9')
1615 || (c >= 'a' && c <= 'z')
1616 || (c >= 'A' && c <= 'Z'))
1617 buf[(*here)++] = (char) c;
1620 // "Unicode" character.
1621 buf[(*here)++] = '_';
1622 buf[(*here)++] = '0';
1623 for (int i = 0; i < 4; ++i)
1626 buf[(*here) + 4 - i] = (val > 10) ? ('a' + val - 10) : ('0' + val);
1633 // Compute a mangled name for a native function. This computes the
1634 // long name, and also returns an index which indicates where a NUL
1635 // can be placed to create the short name. This function assumes that
1636 // the buffer is large enough for its results.
1638 mangled_name (jclass klass, _Jv_Utf8Const *func_name,
1639 _Jv_Utf8Const *signature, char *buf, int *long_start)
1641 strcpy (buf, "Java_");
1644 // Add fully qualified class name.
1645 jchar *chars = _Jv_GetStringChars (klass->getName ());
1646 jint len = klass->getName ()->length ();
1647 for (int i = 0; i < len; ++i)
1648 add_char (buf, chars[i], &here);
1650 // Don't use add_char because we need a literal `_'.
1653 const unsigned char *fn = (const unsigned char *) func_name->data;
1654 const unsigned char *limit = fn + func_name->length;
1655 for (int i = 0; ; ++i)
1657 int ch = UTF8_GET (fn, limit);
1660 add_char (buf, ch, &here);
1663 // This is where the long signature begins.
1668 const unsigned char *sig = (const unsigned char *) signature->data;
1669 limit = sig + signature->length;
1670 JvAssert (sig[0] == '(');
1674 int ch = UTF8_GET (sig, limit);
1675 if (ch == ')' || ch < 0)
1677 add_char (buf, ch, &here);
1683 // Return the current thread's JNIEnv; if one does not exist, create
1684 // it. Also create a new system frame for use. This is `extern "C"'
1685 // because the compiler calls it.
1687 _Jv_GetJNIEnvNewFrame (jclass klass)
1689 JNIEnv *env = _Jv_GetCurrentJNIEnv ();
1692 env = (JNIEnv *) _Jv_MallocUnchecked (sizeof (JNIEnv));
1693 env->p = &_Jv_JNIFunctions;
1698 _Jv_SetCurrentJNIEnv (env);
1701 _Jv_JNI_LocalFrame *frame
1702 = (_Jv_JNI_LocalFrame *) _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame)
1704 * sizeof (jobject)));
1706 frame->marker = MARK_SYSTEM;
1707 frame->size = FRAME_SIZE;
1708 frame->next = env->locals;
1709 env->locals = frame;
1711 for (int i = 0; i < frame->size; ++i)
1712 frame->vec[i] = NULL;
1717 // Return the function which implements a particular JNI method. If
1718 // we can't find the function, we throw the appropriate exception.
1719 // This is `extern "C"' because the compiler uses it.
1721 _Jv_LookupJNIMethod (jclass klass, _Jv_Utf8Const *name,
1722 _Jv_Utf8Const *signature)
1724 char buf[10 + 6 * (name->length + signature->length)];
1728 mangled_name (klass, name, signature, buf, &long_start);
1729 char c = buf[long_start];
1730 buf[long_start] = '\0';
1731 function = _Jv_FindSymbolInExecutable (buf);
1732 if (function == NULL)
1734 buf[long_start] = c;
1735 function = _Jv_FindSymbolInExecutable (buf);
1736 if (function == NULL)
1738 jstring str = JvNewStringUTF (name->data);
1739 JvThrow (new java::lang::AbstractMethodError (str));
1746 // This function is the stub which is used to turn an ordinary (CNI)
1747 // method call into a JNI call.
1749 _Jv_JNIMethod::call (ffi_cif *, void *ret, ffi_raw *args, void *__this)
1751 _Jv_JNIMethod* _this = (_Jv_JNIMethod *) __this;
1753 JNIEnv *env = _Jv_GetJNIEnvNewFrame (_this->defining_class);
1755 // FIXME: we should mark every reference parameter as a local. For
1756 // now we assume a conservative GC, and we assume that the
1757 // references are on the stack somewhere.
1759 // We cache the value that we find, of course, but if we don't find
1760 // a value we don't cache that fact -- we might subsequently load a
1761 // library which finds the function in question.
1762 if (_this->function == NULL)
1763 _this->function = _Jv_LookupJNIMethod (_this->defining_class,
1765 _this->self->signature);
1767 JvAssert (_this->args_raw_size % sizeof (ffi_raw) == 0);
1768 ffi_raw real_args[2 + _this->args_raw_size / sizeof (ffi_raw)];
1771 // First argument is always the environment pointer.
1772 real_args[offset++].ptr = env;
1774 // For a static method, we pass in the Class. For non-static
1775 // methods, the `this' argument is already handled.
1776 if ((_this->self->accflags & java::lang::reflect::Modifier::STATIC))
1777 real_args[offset++].ptr = _this->defining_class;
1779 // Copy over passed-in arguments.
1780 memcpy (&real_args[offset], args, _this->args_raw_size);
1782 // The actual call to the JNI function.
1783 ffi_raw_call (&_this->jni_cif, (void (*) (...)) _this->function,
1786 _Jv_JNI_PopSystemFrame (env);
1789 #endif /* INTERPRETER */
1797 // An internal helper function.
1799 _Jv_JNI_AttachCurrentThread (JavaVM *, jstring name, void **penv, void *args)
1801 JavaVMAttachArgs *attach = reinterpret_cast<JavaVMAttachArgs *> (args);
1802 java::lang::ThreadGroup *group = NULL;
1806 // FIXME: do we really want to support 1.1?
1807 if (attach->version != JNI_VERSION_1_2
1808 && attach->version != JNI_VERSION_1_1)
1809 return JNI_EVERSION;
1811 JvAssert ((&ThreadGroupClass)->isInstance (attach->group));
1812 group = reinterpret_cast<java::lang::ThreadGroup *> (attach->group);
1815 // Attaching an already-attached thread is a no-op.
1816 if (_Jv_GetCurrentJNIEnv () != NULL)
1819 JNIEnv *env = (JNIEnv *) _Jv_MallocUnchecked (sizeof (JNIEnv));
1822 env->p = &_Jv_JNIFunctions;
1826 = (_Jv_JNI_LocalFrame *) _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame)
1828 * sizeof (jobject)));
1829 if (env->locals == NULL)
1834 *penv = reinterpret_cast<void *> (env);
1836 // This thread might already be a Java thread -- this function might
1837 // have been called simply to set the new JNIEnv.
1838 if (_Jv_ThreadCurrent () == NULL)
1842 (void) new gnu::gcj::jni::NativeThread (group, name);
1844 catch (jthrowable t)
1849 _Jv_SetCurrentJNIEnv (env);
1854 // This is the one actually used by JNI.
1856 _Jv_JNI_AttachCurrentThread (JavaVM *vm, void **penv, void *args)
1858 return _Jv_JNI_AttachCurrentThread (vm, NULL, penv, args);
1862 _Jv_JNI_DestroyJavaVM (JavaVM *vm)
1864 JvAssert (the_vm && vm == the_vm);
1867 if (_Jv_ThreadCurrent () != NULL)
1873 main_name = JvNewStringLatin1 ("main");
1875 catch (jthrowable t)
1880 jint r = _Jv_JNI_AttachCurrentThread (vm,
1882 reinterpret_cast<void **> (&env),
1888 env = _Jv_GetCurrentJNIEnv ();
1892 // Docs say that this always returns an error code.
1897 _Jv_JNI_DetachCurrentThread (JavaVM *)
1899 java::lang::Thread *t = _Jv_ThreadCurrent ();
1901 return JNI_EDETACHED;
1903 // FIXME: we only allow threads attached via AttachCurrentThread to
1904 // be detached. I have no idea how we could implement detaching
1905 // other threads, given the requirement that we must release all the
1906 // monitors. That just seems evil.
1907 JvAssert ((&NativeThreadClass)->isInstance (t));
1909 // FIXME: release the monitors. We'll take this to mean all
1910 // monitors acquired via the JNI interface. This means we have to
1911 // keep track of them.
1913 gnu::gcj::jni::NativeThread *nt
1914 = reinterpret_cast<gnu::gcj::jni::NativeThread *> (t);
1921 _Jv_JNI_GetEnv (JavaVM *, void **penv, jint version)
1923 if (_Jv_ThreadCurrent () == NULL)
1926 return JNI_EDETACHED;
1930 // Handle JVMPI requests.
1931 if (version == JVMPI_VERSION_1)
1933 *penv = (void *) &_Jv_JVMPI_Interface;
1938 // FIXME: do we really want to support 1.1?
1939 if (version != JNI_VERSION_1_2 && version != JNI_VERSION_1_1)
1942 return JNI_EVERSION;
1945 *penv = (void *) _Jv_GetCurrentJNIEnv ();
1950 JNI_GetDefaultJavaVMInitArgs (void *args)
1952 jint version = * (jint *) args;
1953 // Here we only support 1.2.
1954 if (version != JNI_VERSION_1_2)
1955 return JNI_EVERSION;
1957 JavaVMInitArgs *ia = reinterpret_cast<JavaVMInitArgs *> (args);
1958 ia->version = JNI_VERSION_1_2;
1961 ia->ignoreUnrecognized = true;
1967 JNI_CreateJavaVM (JavaVM **vm, void **penv, void *args)
1969 JvAssert (! the_vm);
1970 // FIXME: synchronize
1971 JavaVM *nvm = (JavaVM *) _Jv_MallocUnchecked (sizeof (JavaVM));
1974 nvm->functions = &_Jv_JNI_InvokeFunctions;
1976 // Parse the arguments.
1979 jint version = * (jint *) args;
1980 // We only support 1.2.
1981 if (version != JNI_VERSION_1_2)
1982 return JNI_EVERSION;
1983 JavaVMInitArgs *ia = reinterpret_cast<JavaVMInitArgs *> (args);
1984 for (int i = 0; i < ia->nOptions; ++i)
1986 if (! strcmp (ia->options[i].optionString, "vfprintf")
1987 || ! strcmp (ia->options[i].optionString, "exit")
1988 || ! strcmp (ia->options[i].optionString, "abort"))
1990 // We are required to recognize these, but for now we
1991 // don't handle them in any way. FIXME.
1994 else if (! strncmp (ia->options[i].optionString,
1995 "-verbose", sizeof ("-verbose") - 1))
1997 // We don't do anything with this option either. We
1998 // might want to make sure the argument is valid, but we
1999 // don't really care all that much for now.
2002 else if (! strncmp (ia->options[i].optionString, "-D", 2))
2007 else if (ia->ignoreUnrecognized)
2009 if (ia->options[i].optionString[0] == '_'
2010 || ! strncmp (ia->options[i].optionString, "-X", 2))
2018 jint r =_Jv_JNI_AttachCurrentThread (nvm, penv, NULL);
2028 JNI_GetCreatedJavaVMs (JavaVM **vm_buffer, jsize buf_len, jsize *n_vms)
2033 // We only support a single VM.
2036 vm_buffer[0] = the_vm;
2047 // FIXME: synchronize
2050 JavaVM *nvm = (JavaVM *) _Jv_MallocUnchecked (sizeof (JavaVM));
2052 nvm->functions = &_Jv_JNI_InvokeFunctions;
2056 // If this is a Java thread, we want to make sure it has an
2057 // associated JNIEnv.
2058 if (_Jv_ThreadCurrent () != NULL)
2061 _Jv_JNI_AttachCurrentThread (the_vm, &ignore, NULL);
2068 _Jv_JNI_GetJavaVM (JNIEnv *, JavaVM **vm)
2070 *vm = _Jv_GetJavaVM ();
2071 return *vm == NULL ? JNI_ERR : JNI_OK;
2076 #define NOT_IMPL NULL
2077 #define RESERVED NULL
2079 struct JNINativeInterface _Jv_JNIFunctions =
2086 _Jv_JNI_DefineClass,
2088 _Jv_JNI_FromReflectedMethod,
2089 _Jv_JNI_FromReflectedField,
2090 _Jv_JNI_ToReflectedMethod,
2091 _Jv_JNI_GetSuperclass,
2092 _Jv_JNI_IsAssignableFrom,
2093 _Jv_JNI_ToReflectedField,
2096 _Jv_JNI_ExceptionOccurred,
2097 _Jv_JNI_ExceptionDescribe,
2098 _Jv_JNI_ExceptionClear,
2101 _Jv_JNI_PushLocalFrame,
2102 _Jv_JNI_PopLocalFrame,
2103 _Jv_JNI_NewGlobalRef,
2104 _Jv_JNI_DeleteGlobalRef,
2105 _Jv_JNI_DeleteLocalRef,
2107 _Jv_JNI_IsSameObject,
2109 _Jv_JNI_NewLocalRef,
2110 _Jv_JNI_EnsureLocalCapacity,
2112 _Jv_JNI_AllocObject,
2116 _Jv_JNI_GetObjectClass,
2117 _Jv_JNI_IsInstanceOf,
2118 _Jv_JNI_GetAnyMethodID<false>,
2120 _Jv_JNI_CallMethod<jobject>,
2121 _Jv_JNI_CallMethodV<jobject>,
2122 _Jv_JNI_CallMethodA<jobject>,
2123 _Jv_JNI_CallMethod<jboolean>,
2124 _Jv_JNI_CallMethodV<jboolean>,
2125 _Jv_JNI_CallMethodA<jboolean>,
2126 _Jv_JNI_CallMethod<jbyte>,
2127 _Jv_JNI_CallMethodV<jbyte>,
2128 _Jv_JNI_CallMethodA<jbyte>,
2129 _Jv_JNI_CallMethod<jchar>,
2130 _Jv_JNI_CallMethodV<jchar>,
2131 _Jv_JNI_CallMethodA<jchar>,
2132 _Jv_JNI_CallMethod<jshort>,
2133 _Jv_JNI_CallMethodV<jshort>,
2134 _Jv_JNI_CallMethodA<jshort>,
2135 _Jv_JNI_CallMethod<jint>,
2136 _Jv_JNI_CallMethodV<jint>,
2137 _Jv_JNI_CallMethodA<jint>,
2138 _Jv_JNI_CallMethod<jlong>,
2139 _Jv_JNI_CallMethodV<jlong>,
2140 _Jv_JNI_CallMethodA<jlong>,
2141 _Jv_JNI_CallMethod<jfloat>,
2142 _Jv_JNI_CallMethodV<jfloat>,
2143 _Jv_JNI_CallMethodA<jfloat>,
2144 _Jv_JNI_CallMethod<jdouble>,
2145 _Jv_JNI_CallMethodV<jdouble>,
2146 _Jv_JNI_CallMethodA<jdouble>,
2147 _Jv_JNI_CallVoidMethod,
2148 _Jv_JNI_CallVoidMethodV,
2149 _Jv_JNI_CallVoidMethodA,
2151 // Nonvirtual method invocation functions follow.
2152 _Jv_JNI_CallAnyMethod<jobject, nonvirtual>,
2153 _Jv_JNI_CallAnyMethodV<jobject, nonvirtual>,
2154 _Jv_JNI_CallAnyMethodA<jobject, nonvirtual>,
2155 _Jv_JNI_CallAnyMethod<jboolean, nonvirtual>,
2156 _Jv_JNI_CallAnyMethodV<jboolean, nonvirtual>,
2157 _Jv_JNI_CallAnyMethodA<jboolean, nonvirtual>,
2158 _Jv_JNI_CallAnyMethod<jbyte, nonvirtual>,
2159 _Jv_JNI_CallAnyMethodV<jbyte, nonvirtual>,
2160 _Jv_JNI_CallAnyMethodA<jbyte, nonvirtual>,
2161 _Jv_JNI_CallAnyMethod<jchar, nonvirtual>,
2162 _Jv_JNI_CallAnyMethodV<jchar, nonvirtual>,
2163 _Jv_JNI_CallAnyMethodA<jchar, nonvirtual>,
2164 _Jv_JNI_CallAnyMethod<jshort, nonvirtual>,
2165 _Jv_JNI_CallAnyMethodV<jshort, nonvirtual>,
2166 _Jv_JNI_CallAnyMethodA<jshort, nonvirtual>,
2167 _Jv_JNI_CallAnyMethod<jint, nonvirtual>,
2168 _Jv_JNI_CallAnyMethodV<jint, nonvirtual>,
2169 _Jv_JNI_CallAnyMethodA<jint, nonvirtual>,
2170 _Jv_JNI_CallAnyMethod<jlong, nonvirtual>,
2171 _Jv_JNI_CallAnyMethodV<jlong, nonvirtual>,
2172 _Jv_JNI_CallAnyMethodA<jlong, nonvirtual>,
2173 _Jv_JNI_CallAnyMethod<jfloat, nonvirtual>,
2174 _Jv_JNI_CallAnyMethodV<jfloat, nonvirtual>,
2175 _Jv_JNI_CallAnyMethodA<jfloat, nonvirtual>,
2176 _Jv_JNI_CallAnyMethod<jdouble, nonvirtual>,
2177 _Jv_JNI_CallAnyMethodV<jdouble, nonvirtual>,
2178 _Jv_JNI_CallAnyMethodA<jdouble, nonvirtual>,
2179 _Jv_JNI_CallAnyVoidMethod<nonvirtual>,
2180 _Jv_JNI_CallAnyVoidMethodV<nonvirtual>,
2181 _Jv_JNI_CallAnyVoidMethodA<nonvirtual>,
2183 _Jv_JNI_GetAnyFieldID<false>,
2184 _Jv_JNI_GetField<jobject>,
2185 _Jv_JNI_GetField<jboolean>,
2186 _Jv_JNI_GetField<jbyte>,
2187 _Jv_JNI_GetField<jchar>,
2188 _Jv_JNI_GetField<jshort>,
2189 _Jv_JNI_GetField<jint>,
2190 _Jv_JNI_GetField<jlong>,
2191 _Jv_JNI_GetField<jfloat>,
2192 _Jv_JNI_GetField<jdouble>,
2202 _Jv_JNI_GetAnyMethodID<true>,
2204 _Jv_JNI_CallStaticMethod<jobject>,
2205 _Jv_JNI_CallStaticMethodV<jobject>,
2206 _Jv_JNI_CallStaticMethodA<jobject>,
2207 _Jv_JNI_CallStaticMethod<jboolean>,
2208 _Jv_JNI_CallStaticMethodV<jboolean>,
2209 _Jv_JNI_CallStaticMethodA<jboolean>,
2210 _Jv_JNI_CallStaticMethod<jbyte>,
2211 _Jv_JNI_CallStaticMethodV<jbyte>,
2212 _Jv_JNI_CallStaticMethodA<jbyte>,
2213 _Jv_JNI_CallStaticMethod<jchar>,
2214 _Jv_JNI_CallStaticMethodV<jchar>,
2215 _Jv_JNI_CallStaticMethodA<jchar>,
2216 _Jv_JNI_CallStaticMethod<jshort>,
2217 _Jv_JNI_CallStaticMethodV<jshort>,
2218 _Jv_JNI_CallStaticMethodA<jshort>,
2219 _Jv_JNI_CallStaticMethod<jint>,
2220 _Jv_JNI_CallStaticMethodV<jint>,
2221 _Jv_JNI_CallStaticMethodA<jint>,
2222 _Jv_JNI_CallStaticMethod<jlong>,
2223 _Jv_JNI_CallStaticMethodV<jlong>,
2224 _Jv_JNI_CallStaticMethodA<jlong>,
2225 _Jv_JNI_CallStaticMethod<jfloat>,
2226 _Jv_JNI_CallStaticMethodV<jfloat>,
2227 _Jv_JNI_CallStaticMethodA<jfloat>,
2228 _Jv_JNI_CallStaticMethod<jdouble>,
2229 _Jv_JNI_CallStaticMethodV<jdouble>,
2230 _Jv_JNI_CallStaticMethodA<jdouble>,
2231 _Jv_JNI_CallStaticVoidMethod,
2232 _Jv_JNI_CallStaticVoidMethodV,
2233 _Jv_JNI_CallStaticVoidMethodA,
2235 _Jv_JNI_GetAnyFieldID<true>,
2236 _Jv_JNI_GetStaticField<jobject>,
2237 _Jv_JNI_GetStaticField<jboolean>,
2238 _Jv_JNI_GetStaticField<jbyte>,
2239 _Jv_JNI_GetStaticField<jchar>,
2240 _Jv_JNI_GetStaticField<jshort>,
2241 _Jv_JNI_GetStaticField<jint>,
2242 _Jv_JNI_GetStaticField<jlong>,
2243 _Jv_JNI_GetStaticField<jfloat>,
2244 _Jv_JNI_GetStaticField<jdouble>,
2245 _Jv_JNI_SetStaticField,
2246 _Jv_JNI_SetStaticField,
2247 _Jv_JNI_SetStaticField,
2248 _Jv_JNI_SetStaticField,
2249 _Jv_JNI_SetStaticField,
2250 _Jv_JNI_SetStaticField,
2251 _Jv_JNI_SetStaticField,
2252 _Jv_JNI_SetStaticField,
2253 _Jv_JNI_SetStaticField,
2255 _Jv_JNI_GetStringLength,
2256 _Jv_JNI_GetStringChars,
2257 _Jv_JNI_ReleaseStringChars,
2258 _Jv_JNI_NewStringUTF,
2259 _Jv_JNI_GetStringUTFLength,
2260 _Jv_JNI_GetStringUTFChars,
2261 _Jv_JNI_ReleaseStringUTFChars,
2262 _Jv_JNI_GetArrayLength,
2263 _Jv_JNI_NewObjectArray,
2264 _Jv_JNI_GetObjectArrayElement,
2265 _Jv_JNI_SetObjectArrayElement,
2266 _Jv_JNI_NewPrimitiveArray<jboolean, JvPrimClass (boolean)>,
2267 _Jv_JNI_NewPrimitiveArray<jbyte, JvPrimClass (byte)>,
2268 _Jv_JNI_NewPrimitiveArray<jchar, JvPrimClass (char)>,
2269 _Jv_JNI_NewPrimitiveArray<jshort, JvPrimClass (short)>,
2270 _Jv_JNI_NewPrimitiveArray<jint, JvPrimClass (int)>,
2271 _Jv_JNI_NewPrimitiveArray<jlong, JvPrimClass (long)>,
2272 _Jv_JNI_NewPrimitiveArray<jfloat, JvPrimClass (float)>,
2273 _Jv_JNI_NewPrimitiveArray<jdouble, JvPrimClass (double)>,
2274 _Jv_JNI_GetPrimitiveArrayElements,
2275 _Jv_JNI_GetPrimitiveArrayElements,
2276 _Jv_JNI_GetPrimitiveArrayElements,
2277 _Jv_JNI_GetPrimitiveArrayElements,
2278 _Jv_JNI_GetPrimitiveArrayElements,
2279 _Jv_JNI_GetPrimitiveArrayElements,
2280 _Jv_JNI_GetPrimitiveArrayElements,
2281 _Jv_JNI_GetPrimitiveArrayElements,
2282 _Jv_JNI_ReleasePrimitiveArrayElements,
2283 _Jv_JNI_ReleasePrimitiveArrayElements,
2284 _Jv_JNI_ReleasePrimitiveArrayElements,
2285 _Jv_JNI_ReleasePrimitiveArrayElements,
2286 _Jv_JNI_ReleasePrimitiveArrayElements,
2287 _Jv_JNI_ReleasePrimitiveArrayElements,
2288 _Jv_JNI_ReleasePrimitiveArrayElements,
2289 _Jv_JNI_ReleasePrimitiveArrayElements,
2290 _Jv_JNI_GetPrimitiveArrayRegion,
2291 _Jv_JNI_GetPrimitiveArrayRegion,
2292 _Jv_JNI_GetPrimitiveArrayRegion,
2293 _Jv_JNI_GetPrimitiveArrayRegion,
2294 _Jv_JNI_GetPrimitiveArrayRegion,
2295 _Jv_JNI_GetPrimitiveArrayRegion,
2296 _Jv_JNI_GetPrimitiveArrayRegion,
2297 _Jv_JNI_GetPrimitiveArrayRegion,
2298 _Jv_JNI_SetPrimitiveArrayRegion,
2299 _Jv_JNI_SetPrimitiveArrayRegion,
2300 _Jv_JNI_SetPrimitiveArrayRegion,
2301 _Jv_JNI_SetPrimitiveArrayRegion,
2302 _Jv_JNI_SetPrimitiveArrayRegion,
2303 _Jv_JNI_SetPrimitiveArrayRegion,
2304 _Jv_JNI_SetPrimitiveArrayRegion,
2305 _Jv_JNI_SetPrimitiveArrayRegion,
2306 _Jv_JNI_RegisterNatives,
2307 _Jv_JNI_UnregisterNatives,
2308 _Jv_JNI_MonitorEnter,
2309 _Jv_JNI_MonitorExit,
2312 _Jv_JNI_GetStringRegion,
2313 _Jv_JNI_GetStringUTFRegion,
2314 _Jv_JNI_GetPrimitiveArrayCritical,
2315 _Jv_JNI_ReleasePrimitiveArrayCritical,
2316 _Jv_JNI_GetStringCritical,
2317 _Jv_JNI_ReleaseStringCritical,
2319 NOT_IMPL /* newweakglobalref */,
2320 NOT_IMPL /* deleteweakglobalref */,
2322 _Jv_JNI_ExceptionCheck
2325 struct JNIInvokeInterface _Jv_JNI_InvokeFunctions =
2331 _Jv_JNI_DestroyJavaVM,
2332 _Jv_JNI_AttachCurrentThread,
2333 _Jv_JNI_DetachCurrentThread,