1 // jni.cc - JNI implementation, including the jump table.
3 /* Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
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>
24 #include <java/lang/Class.h>
25 #include <java/lang/ClassLoader.h>
26 #include <java/lang/Throwable.h>
27 #include <java/lang/ArrayIndexOutOfBoundsException.h>
28 #include <java/lang/StringIndexOutOfBoundsException.h>
29 #include <java/lang/AbstractMethodError.h>
30 #include <java/lang/InstantiationException.h>
31 #include <java/lang/NoSuchFieldError.h>
32 #include <java/lang/NoSuchMethodError.h>
33 #include <java/lang/reflect/Constructor.h>
34 #include <java/lang/reflect/Method.h>
35 #include <java/lang/reflect/Modifier.h>
36 #include <java/lang/OutOfMemoryError.h>
37 #include <java/util/Hashtable.h>
38 #include <java/lang/Integer.h>
39 #include <gnu/gcj/jni/NativeThread.h>
41 #include <gcj/method.h>
42 #include <gcj/field.h>
44 #include <java-interp.h>
46 #define ClassClass _CL_Q34java4lang5Class
47 extern java::lang::Class ClassClass;
48 #define ObjectClass _CL_Q34java4lang6Object
49 extern java::lang::Class ObjectClass;
51 #define ThrowableClass _CL_Q34java4lang9Throwable
52 extern java::lang::Class ThrowableClass;
53 #define MethodClass _CL_Q44java4lang7reflect6Method
54 extern java::lang::Class MethodClass;
55 #define ThreadGroupClass _CL_Q34java4lang11ThreadGroup
56 extern java::lang::Class ThreadGroupClass;
57 #define NativeThreadClass _CL_Q43gnu3gcj3jni12NativeThread
58 extern java::lang::Class ThreadGroupClass;
60 // This enum is used to select different template instantiations in
61 // the invocation code.
70 // Forward declarations.
71 extern struct JNINativeInterface _Jv_JNIFunctions;
72 extern struct JNIInvokeInterface _Jv_JNI_InvokeFunctions;
74 // Number of slots in the default frame. The VM must allow at least
78 // This structure is used to keep track of local references.
79 struct _Jv_JNI_LocalFrame
81 // This is true if this frame object represents a pushed frame (eg
82 // from PushLocalFrame).
85 // Number of elements in frame.
88 // Next frame in chain.
89 _Jv_JNI_LocalFrame *next;
91 // The elements. These are allocated using the C "struct hack".
95 // This holds a reference count for all local and global references.
96 static java::util::Hashtable *ref_table;
99 static JavaVM *the_vm;
106 ref_table = new java::util::Hashtable;
109 // Tell the GC that a certain pointer is live.
111 mark_for_gc (jobject obj)
113 JvSynchronize sync (ref_table);
115 using namespace java::lang;
116 Integer *refcount = (Integer *) ref_table->get (obj);
117 jint val = (refcount == NULL) ? 0 : refcount->intValue ();
118 // FIXME: what about out of memory error?
119 ref_table->put (obj, new Integer (val + 1));
124 unmark_for_gc (jobject obj)
126 JvSynchronize sync (ref_table);
128 using namespace java::lang;
129 Integer *refcount = (Integer *) ref_table->get (obj);
131 jint val = refcount->intValue () - 1;
133 ref_table->remove (obj);
135 // FIXME: what about out of memory error?
136 ref_table->put (obj, new Integer (val));
142 _Jv_JNI_NewGlobalRef (JNIEnv *, jobject obj)
149 _Jv_JNI_DeleteGlobalRef (JNIEnv *, jobject obj)
155 _Jv_JNI_DeleteLocalRef (JNIEnv *env, jobject obj)
157 _Jv_JNI_LocalFrame *frame;
159 for (frame = env->locals; frame != NULL; frame = frame->next)
161 for (int i = 0; i < FRAME_SIZE; ++i)
163 if (frame->vec[i] == obj)
165 frame->vec[i] = NULL;
171 // Don't go past a marked frame.
172 JvAssert (! frame->marker);
179 _Jv_JNI_EnsureLocalCapacity (JNIEnv *env, jint size)
181 // It is easier to just always allocate a new frame of the requested
182 // size. This isn't the most efficient thing, but for now we don't
183 // care. Note that _Jv_JNI_PushLocalFrame relies on this right now.
185 _Jv_JNI_LocalFrame *frame;
188 frame = (_Jv_JNI_LocalFrame *) _Jv_Malloc (sizeof (_Jv_JNI_LocalFrame)
189 + size * sizeof (jobject));
197 frame->marker = true;
199 memset (&frame->vec[0], 0, size * sizeof (jobject));
200 frame->next = env->locals;
207 _Jv_JNI_PushLocalFrame (JNIEnv *env, jint size)
209 jint r = _Jv_JNI_EnsureLocalCapacity (env, size);
213 // The new frame is on top.
214 env->locals->marker = true;
220 _Jv_JNI_NewLocalRef (JNIEnv *env, jobject obj)
222 // Try to find an open slot somewhere in the topmost frame.
223 _Jv_JNI_LocalFrame *frame = env->locals;
224 bool done = false, set = false;
225 while (frame != NULL && ! done)
227 for (int i = 0; i < frame->size; ++i)
228 if (frame->vec[i] == NULL)
239 // No slots, so we allocate a new frame. According to the spec
240 // we could just die here. FIXME: return value.
241 _Jv_JNI_EnsureLocalCapacity (env, 16);
242 // We know the first element of the new frame will be ok.
243 env->locals->vec[0] = obj;
251 _Jv_JNI_PopLocalFrame (JNIEnv *env, jobject result)
253 _Jv_JNI_LocalFrame *rf = env->locals;
256 while (rf != NULL && ! done)
258 for (int i = 0; i < rf->size; ++i)
259 if (rf->vec[i] != NULL)
260 unmark_for_gc (rf->vec[i]);
262 // If the frame we just freed is the marker frame, we are done.
265 _Jv_JNI_LocalFrame *n = rf->next;
266 // When N==NULL, we've reached the stack-allocated frame, and we
267 // must not free it. However, we must be sure to clear all its
268 // elements, since we might conceivably reuse it.
271 memset (&rf->vec[0], 0, rf->size * sizeof (jobject));
279 return result == NULL ? NULL : _Jv_JNI_NewLocalRef (env, result);
282 // This function is used from other template functions. It wraps the
283 // return value appropriately; we specialize it so that object returns
284 // are turned into local references.
287 wrap_value (JNIEnv *, T value)
294 wrap_value (JNIEnv *env, jobject value)
296 return value == NULL ? value : _Jv_JNI_NewLocalRef (env, value);
302 _Jv_JNI_GetVersion (JNIEnv *)
304 return JNI_VERSION_1_2;
308 _Jv_JNI_DefineClass (JNIEnv *env, jobject loader,
309 const jbyte *buf, jsize bufLen)
313 jbyteArray bytes = JvNewByteArray (bufLen);
315 jbyte *elts = elements (bytes);
316 memcpy (elts, buf, bufLen * sizeof (jbyte));
318 java::lang::ClassLoader *l
319 = reinterpret_cast<java::lang::ClassLoader *> (loader);
321 jclass result = l->defineClass (bytes, 0, bufLen);
322 return (jclass) wrap_value (env, result);
332 _Jv_JNI_FindClass (JNIEnv *env, const char *name)
334 // FIXME: assume that NAME isn't too long.
335 int len = strlen (name);
337 for (int i = 0; i <= len; ++i)
338 s[i] = (name[i] == '/') ? '.' : name[i];
343 // This might throw an out of memory exception.
344 jstring n = JvNewStringUTF (s);
346 java::lang::ClassLoader *loader;
347 if (env->klass == NULL)
349 // FIXME: should use getBaseClassLoader, but we don't have that
351 loader = java::lang::ClassLoader::getSystemClassLoader ();
354 loader = env->klass->getClassLoader ();
356 r = loader->loadClass (n);
363 return (jclass) wrap_value (env, r);
367 _Jv_JNI_GetSuperclass (JNIEnv *env, jclass clazz)
369 return (jclass) wrap_value (env, clazz->getSuperclass ());
373 _Jv_JNI_IsAssignableFrom(JNIEnv *, jclass clazz1, jclass clazz2)
375 return clazz1->isAssignableFrom (clazz2);
379 _Jv_JNI_Throw (JNIEnv *env, jthrowable obj)
381 // We check in case the user did some funky cast.
382 JvAssert (obj != NULL && (&ThrowableClass)->isInstance (obj));
388 _Jv_JNI_ThrowNew (JNIEnv *env, jclass clazz, const char *message)
390 using namespace java::lang::reflect;
392 JvAssert ((&ThrowableClass)->isAssignableFrom (clazz));
397 JArray<jclass> *argtypes
398 = (JArray<jclass> *) JvNewObjectArray (1, &ClassClass, NULL);
400 jclass *elts = elements (argtypes);
401 elts[0] = &StringClass;
403 Constructor *cons = clazz->getConstructor (argtypes);
405 jobjectArray values = JvNewObjectArray (1, &StringClass, NULL);
406 jobject *velts = elements (values);
407 velts[0] = JvNewStringUTF (message);
409 jobject obj = cons->newInstance (values);
411 env->ex = reinterpret_cast<jthrowable> (obj);
423 _Jv_JNI_ExceptionOccurred (JNIEnv *env)
425 return (jthrowable) wrap_value (env, env->ex);
429 _Jv_JNI_ExceptionDescribe (JNIEnv *env)
432 env->ex->printStackTrace();
436 _Jv_JNI_ExceptionClear (JNIEnv *env)
442 _Jv_JNI_ExceptionCheck (JNIEnv *env)
444 return env->ex != NULL;
448 _Jv_JNI_FatalError (JNIEnv *, const char *message)
456 _Jv_JNI_IsSameObject (JNIEnv *, jobject obj1, jobject obj2)
462 _Jv_JNI_AllocObject (JNIEnv *env, jclass clazz)
465 using namespace java::lang::reflect;
469 JvAssert (clazz && ! clazz->isArray ());
470 if (clazz->isInterface() || Modifier::isAbstract(clazz->getModifiers()))
471 env->ex = new java::lang::InstantiationException ();
474 // FIXME: will this work for String?
475 obj = JvAllocObject (clazz);
483 return wrap_value (env, obj);
487 _Jv_JNI_GetObjectClass (JNIEnv *env, jobject obj)
490 return (jclass) wrap_value (env, obj->getClass());
494 _Jv_JNI_IsInstanceOf (JNIEnv *, jobject obj, jclass clazz)
496 return clazz->isInstance(obj);
502 // This section concerns method invocation.
505 template<jboolean is_static>
507 _Jv_JNI_GetAnyMethodID (JNIEnv *env, jclass clazz,
508 const char *name, const char *sig)
512 _Jv_InitClass (clazz);
514 _Jv_Utf8Const *name_u = _Jv_makeUtf8Const ((char *) name, -1);
515 _Jv_Utf8Const *sig_u = _Jv_makeUtf8Const ((char *) sig, -1);
517 JvAssert (! clazz->isPrimitive());
519 using namespace java::lang::reflect;
521 while (clazz != NULL)
523 jint count = JvNumMethods (clazz);
524 jmethodID meth = JvGetFirstMethod (clazz);
526 for (jint i = 0; i < count; ++i)
528 if (((is_static && Modifier::isStatic (meth->accflags))
529 || (! is_static && ! Modifier::isStatic (meth->accflags)))
530 && _Jv_equalUtf8Consts (meth->name, name_u)
531 && _Jv_equalUtf8Consts (meth->signature, sig_u))
534 meth = meth->getNextMethod();
537 clazz = clazz->getSuperclass ();
540 env->ex = new java::lang::NoSuchMethodError ();
550 // This is a helper function which turns a va_list into an array of
551 // `jvalue's. It needs signature information in order to do its work.
552 // The array of values must already be allocated.
554 array_from_valist (jvalue *values, JArray<jclass> *arg_types, va_list vargs)
556 jclass *arg_elts = elements (arg_types);
557 for (int i = 0; i < arg_types->length; ++i)
559 if (arg_elts[i] == JvPrimClass (byte))
560 values[i].b = va_arg (vargs, jbyte);
561 else if (arg_elts[i] == JvPrimClass (short))
562 values[i].s = va_arg (vargs, jshort);
563 else if (arg_elts[i] == JvPrimClass (int))
564 values[i].i = va_arg (vargs, jint);
565 else if (arg_elts[i] == JvPrimClass (long))
566 values[i].j = va_arg (vargs, jlong);
567 else if (arg_elts[i] == JvPrimClass (float))
568 values[i].f = va_arg (vargs, jfloat);
569 else if (arg_elts[i] == JvPrimClass (double))
570 values[i].d = va_arg (vargs, jdouble);
571 else if (arg_elts[i] == JvPrimClass (boolean))
572 values[i].z = va_arg (vargs, jboolean);
573 else if (arg_elts[i] == JvPrimClass (char))
574 values[i].c = va_arg (vargs, jchar);
578 values[i].l = va_arg (vargs, jobject);
583 // This can call any sort of method: virtual, "nonvirtual", static, or
585 template<typename T, invocation_type style>
587 _Jv_JNI_CallAnyMethodV (JNIEnv *env, jobject obj, jclass klass,
588 jmethodID id, va_list vargs)
591 id = _Jv_LookupDeclaredMethod (obj->getClass (), id->name, id->signature);
593 jclass decl_class = klass ? klass : obj->getClass ();
594 JvAssert (decl_class != NULL);
597 JArray<jclass> *arg_types;
601 _Jv_GetTypesFromSignature (id, decl_class,
602 &arg_types, &return_type);
604 jvalue args[arg_types->length];
605 array_from_valist (args, arg_types, vargs);
607 // For constructors we need to pass the Class we are instantiating.
608 if (style == constructor)
612 jthrowable ex = _Jv_CallAnyMethodA (obj, return_type, id,
613 style == constructor,
614 arg_types, args, &result);
619 // We cheat a little here. FIXME.
620 return wrap_value (env, * (T *) &result);
627 return wrap_value (env, (T) 0);
630 template<typename T, invocation_type style>
632 _Jv_JNI_CallAnyMethod (JNIEnv *env, jobject obj, jclass klass,
633 jmethodID method, ...)
638 va_start (args, method);
639 result = _Jv_JNI_CallAnyMethodV<T, style> (env, obj, klass, method, args);
645 template<typename T, invocation_type style>
647 _Jv_JNI_CallAnyMethodA (JNIEnv *env, jobject obj, jclass klass,
648 jmethodID id, jvalue *args)
651 id = _Jv_LookupDeclaredMethod (obj->getClass (), id->name, id->signature);
653 jclass decl_class = klass ? klass : obj->getClass ();
654 JvAssert (decl_class != NULL);
657 JArray<jclass> *arg_types;
660 _Jv_GetTypesFromSignature (id, decl_class,
661 &arg_types, &return_type);
663 // For constructors we need to pass the Class we are instantiating.
664 if (style == constructor)
668 jthrowable ex = _Jv_CallAnyMethodA (obj, return_type, id,
669 style == constructor,
670 arg_types, args, &result);
675 // We cheat a little here. FIXME.
676 return wrap_value (env, * (T *) &result);
683 return wrap_value (env, (T) 0);
686 template<invocation_type style>
688 _Jv_JNI_CallAnyVoidMethodV (JNIEnv *env, jobject obj, jclass klass,
689 jmethodID id, va_list vargs)
692 id = _Jv_LookupDeclaredMethod (obj->getClass (), id->name, id->signature);
694 jclass decl_class = klass ? klass : obj->getClass ();
695 JvAssert (decl_class != NULL);
698 JArray<jclass> *arg_types;
701 _Jv_GetTypesFromSignature (id, decl_class,
702 &arg_types, &return_type);
704 jvalue args[arg_types->length];
705 array_from_valist (args, arg_types, vargs);
707 // For constructors we need to pass the Class we are instantiating.
708 if (style == constructor)
711 jthrowable ex = _Jv_CallAnyMethodA (obj, return_type, id,
712 style == constructor,
713 arg_types, args, NULL);
724 template<invocation_type style>
726 _Jv_JNI_CallAnyVoidMethod (JNIEnv *env, jobject obj, jclass klass,
727 jmethodID method, ...)
731 va_start (args, method);
732 _Jv_JNI_CallAnyVoidMethodV<style> (env, obj, klass, method, args);
736 template<invocation_type style>
738 _Jv_JNI_CallAnyVoidMethodA (JNIEnv *env, jobject obj, jclass klass,
739 jmethodID id, jvalue *args)
742 id = _Jv_LookupDeclaredMethod (obj->getClass (), id->name, id->signature);
744 jclass decl_class = klass ? klass : obj->getClass ();
745 JvAssert (decl_class != NULL);
748 JArray<jclass> *arg_types;
751 _Jv_GetTypesFromSignature (id, decl_class,
752 &arg_types, &return_type);
754 jthrowable ex = _Jv_CallAnyMethodA (obj, return_type, id,
755 style == constructor,
756 arg_types, args, NULL);
767 // Functions with this signature are used to implement functions in
768 // the CallMethod family.
771 _Jv_JNI_CallMethodV (JNIEnv *env, jobject obj, jmethodID id, va_list args)
773 return _Jv_JNI_CallAnyMethodV<T, normal> (env, obj, NULL, id, args);
776 // Functions with this signature are used to implement functions in
777 // the CallMethod family.
780 _Jv_JNI_CallMethod (JNIEnv *env, jobject obj, jmethodID id, ...)
786 result = _Jv_JNI_CallAnyMethodV<T, normal> (env, obj, NULL, id, args);
792 // Functions with this signature are used to implement functions in
793 // the CallMethod family.
796 _Jv_JNI_CallMethodA (JNIEnv *env, jobject obj, jmethodID id, jvalue *args)
798 return _Jv_JNI_CallAnyMethodA<T, normal> (env, obj, NULL, id, args);
802 _Jv_JNI_CallVoidMethodV (JNIEnv *env, jobject obj, jmethodID id, va_list args)
804 _Jv_JNI_CallAnyVoidMethodV<normal> (env, obj, NULL, id, args);
808 _Jv_JNI_CallVoidMethod (JNIEnv *env, jobject obj, jmethodID id, ...)
813 _Jv_JNI_CallAnyVoidMethodV<normal> (env, obj, NULL, id, args);
818 _Jv_JNI_CallVoidMethodA (JNIEnv *env, jobject obj, jmethodID id, jvalue *args)
820 _Jv_JNI_CallAnyVoidMethodA<normal> (env, obj, NULL, id, args);
823 // Functions with this signature are used to implement functions in
824 // the CallStaticMethod family.
827 _Jv_JNI_CallStaticMethodV (JNIEnv *env, jclass klass,
828 jmethodID id, va_list args)
830 JvAssert (((id->accflags) & java::lang::reflect::Modifier::STATIC));
831 JvAssert ((&ClassClass)->isInstance (klass));
833 return _Jv_JNI_CallAnyMethodV<T, static_type> (env, NULL, klass, id, args);
836 // Functions with this signature are used to implement functions in
837 // the CallStaticMethod family.
840 _Jv_JNI_CallStaticMethod (JNIEnv *env, jclass klass, jmethodID id, ...)
845 JvAssert (((id->accflags) & java::lang::reflect::Modifier::STATIC));
846 JvAssert ((&ClassClass)->isInstance (klass));
849 result = _Jv_JNI_CallAnyMethodV<T, static_type> (env, NULL, klass,
856 // Functions with this signature are used to implement functions in
857 // the CallStaticMethod family.
860 _Jv_JNI_CallStaticMethodA (JNIEnv *env, jclass klass, jmethodID id,
863 JvAssert (((id->accflags) & java::lang::reflect::Modifier::STATIC));
864 JvAssert ((&ClassClass)->isInstance (klass));
866 return _Jv_JNI_CallAnyMethodA<T, static_type> (env, NULL, klass, id, args);
870 _Jv_JNI_CallStaticVoidMethodV (JNIEnv *env, jclass klass, jmethodID id,
873 _Jv_JNI_CallAnyVoidMethodV<static_type> (env, NULL, klass, id, args);
877 _Jv_JNI_CallStaticVoidMethod (JNIEnv *env, jclass klass, jmethodID id, ...)
882 _Jv_JNI_CallAnyVoidMethodV<static_type> (env, NULL, klass, id, args);
887 _Jv_JNI_CallStaticVoidMethodA (JNIEnv *env, jclass klass, jmethodID id,
890 _Jv_JNI_CallAnyVoidMethodA<static_type> (env, NULL, klass, id, args);
894 _Jv_JNI_NewObjectV (JNIEnv *env, jclass klass,
895 jmethodID id, va_list args)
897 JvAssert (klass && ! klass->isArray ());
898 JvAssert (! strcmp (id->name->data, "<init>")
899 && id->signature->length > 2
900 && id->signature->data[0] == '('
901 && ! strcmp (&id->signature->data[id->signature->length - 2],
904 return _Jv_JNI_CallAnyMethodV<jobject, constructor> (env, NULL, klass,
909 _Jv_JNI_NewObject (JNIEnv *env, jclass klass, jmethodID id, ...)
911 JvAssert (klass && ! klass->isArray ());
912 JvAssert (! strcmp (id->name->data, "<init>")
913 && id->signature->length > 2
914 && id->signature->data[0] == '('
915 && ! strcmp (&id->signature->data[id->signature->length - 2],
922 result = _Jv_JNI_CallAnyMethodV<jobject, constructor> (env, NULL, klass,
930 _Jv_JNI_NewObjectA (JNIEnv *env, jclass klass, jmethodID id,
933 JvAssert (klass && ! klass->isArray ());
934 JvAssert (! strcmp (id->name->data, "<init>")
935 && id->signature->length > 2
936 && id->signature->data[0] == '('
937 && ! strcmp (&id->signature->data[id->signature->length - 2],
940 return _Jv_JNI_CallAnyMethodA<jobject, constructor> (env, NULL, klass,
948 _Jv_JNI_GetField (JNIEnv *env, jobject obj, jfieldID field)
951 T *ptr = (T *) ((char *) obj + field->getOffset ());
952 return wrap_value (env, *ptr);
957 _Jv_JNI_SetField (JNIEnv *, jobject obj, jfieldID field, T value)
960 T *ptr = (T *) ((char *) obj + field->getOffset ());
964 template<jboolean is_static>
966 _Jv_JNI_GetAnyFieldID (JNIEnv *env, jclass clazz,
967 const char *name, const char *sig)
971 _Jv_InitClass (clazz);
973 _Jv_Utf8Const *a_name = _Jv_makeUtf8Const ((char *) name, -1);
975 jclass field_class = NULL;
977 field_class = _Jv_FindClassFromSignature ((char *) sig, NULL);
980 _Jv_Utf8Const *sig_u = _Jv_makeUtf8Const ((char *) sig, -1);
981 field_class = _Jv_FindClass (sig_u, NULL);
984 // FIXME: what if field_class == NULL?
986 while (clazz != NULL)
988 jint count = (is_static
989 ? JvNumStaticFields (clazz)
990 : JvNumInstanceFields (clazz));
991 jfieldID field = (is_static
992 ? JvGetFirstStaticField (clazz)
993 : JvGetFirstInstanceField (clazz));
994 for (jint i = 0; i < count; ++i)
996 // The field is resolved as a side effect of class
998 JvAssert (field->isResolved ());
1000 _Jv_Utf8Const *f_name = field->getNameUtf8Const(clazz);
1002 if (_Jv_equalUtf8Consts (f_name, a_name)
1003 && field->getClass() == field_class)
1006 field = field->getNextField ();
1009 clazz = clazz->getSuperclass ();
1012 env->ex = new java::lang::NoSuchFieldError ();
1014 catch (jthrowable t)
1021 template<typename T>
1023 _Jv_JNI_GetStaticField (JNIEnv *env, jclass, jfieldID field)
1025 T *ptr = (T *) field->u.addr;
1026 return wrap_value (env, *ptr);
1029 template<typename T>
1031 _Jv_JNI_SetStaticField (JNIEnv *, jclass, jfieldID field, T value)
1033 T *ptr = (T *) field->u.addr;
1038 _Jv_JNI_NewString (JNIEnv *env, const jchar *unichars, jsize len)
1042 jstring r = _Jv_NewString (unichars, len);
1043 return (jstring) wrap_value (env, r);
1045 catch (jthrowable t)
1053 _Jv_JNI_GetStringLength (JNIEnv *, jstring string)
1055 return string->length();
1058 static const jchar *
1059 _Jv_JNI_GetStringChars (JNIEnv *, jstring string, jboolean *isCopy)
1061 jchar *result = _Jv_GetStringChars (string);
1062 mark_for_gc (string);
1065 return (const jchar *) result;
1069 _Jv_JNI_ReleaseStringChars (JNIEnv *, jstring string, const jchar *)
1071 unmark_for_gc (string);
1075 _Jv_JNI_NewStringUTF (JNIEnv *env, const char *bytes)
1079 jstring result = JvNewStringUTF (bytes);
1080 return (jstring) wrap_value (env, result);
1082 catch (jthrowable t)
1090 _Jv_JNI_GetStringUTFLength (JNIEnv *, jstring string)
1092 return JvGetStringUTFLength (string);
1096 _Jv_JNI_GetStringUTFChars (JNIEnv *env, jstring string, jboolean *isCopy)
1098 jsize len = JvGetStringUTFLength (string);
1101 char *r = (char *) _Jv_Malloc (len + 1);
1102 JvGetStringUTFRegion (string, 0, len, r);
1108 return (const char *) r;
1110 catch (jthrowable t)
1118 _Jv_JNI_ReleaseStringUTFChars (JNIEnv *, jstring, const char *utf)
1120 _Jv_Free ((void *) utf);
1124 _Jv_JNI_GetStringRegion (JNIEnv *env, jstring string, jsize start, jsize len,
1127 jchar *result = _Jv_GetStringChars (string);
1128 if (start < 0 || start > string->length ()
1129 || len < 0 || start + len > string->length ())
1133 env->ex = new java::lang::StringIndexOutOfBoundsException ();
1135 catch (jthrowable t)
1141 memcpy (buf, &result[start], len * sizeof (jchar));
1145 _Jv_JNI_GetStringUTFRegion (JNIEnv *env, jstring str, jsize start,
1146 jsize len, char *buf)
1148 if (start < 0 || start > str->length ()
1149 || len < 0 || start + len > str->length ())
1153 env->ex = new java::lang::StringIndexOutOfBoundsException ();
1155 catch (jthrowable t)
1161 _Jv_GetStringUTFRegion (str, start, len, buf);
1164 static const jchar *
1165 _Jv_JNI_GetStringCritical (JNIEnv *, jstring str, jboolean *isCopy)
1167 jchar *result = _Jv_GetStringChars (str);
1174 _Jv_JNI_ReleaseStringCritical (JNIEnv *, jstring, const jchar *)
1180 _Jv_JNI_GetArrayLength (JNIEnv *, jarray array)
1182 return array->length;
1186 _Jv_JNI_NewObjectArray (JNIEnv *env, jsize length, jclass elementClass,
1191 jarray result = JvNewObjectArray (length, elementClass, init);
1192 return (jarray) wrap_value (env, result);
1194 catch (jthrowable t)
1202 _Jv_JNI_GetObjectArrayElement (JNIEnv *env, jobjectArray array, jsize index)
1204 jobject *elts = elements (array);
1205 return wrap_value (env, elts[index]);
1209 _Jv_JNI_SetObjectArrayElement (JNIEnv *env, jobjectArray array, jsize index,
1214 _Jv_CheckArrayStore (array, value);
1215 jobject *elts = elements (array);
1216 elts[index] = value;
1218 catch (jthrowable t)
1224 template<typename T, jclass K>
1226 _Jv_JNI_NewPrimitiveArray (JNIEnv *env, jsize length)
1230 return (JArray<T> *) wrap_value (env, _Jv_NewPrimArray (K, length));
1232 catch (jthrowable t)
1239 template<typename T>
1241 _Jv_JNI_GetPrimitiveArrayElements (JNIEnv *, JArray<T> *array,
1244 T *elts = elements (array);
1247 // We elect never to copy.
1250 mark_for_gc (array);
1254 template<typename T>
1256 _Jv_JNI_ReleasePrimitiveArrayElements (JNIEnv *, JArray<T> *array,
1257 T *, jint /* mode */)
1259 // Note that we ignore MODE. We can do this because we never copy
1260 // the array elements. My reading of the JNI documentation is that
1261 // this is an option for the implementor.
1262 unmark_for_gc (array);
1265 template<typename T>
1267 _Jv_JNI_GetPrimitiveArrayRegion (JNIEnv *env, JArray<T> *array,
1268 jsize start, jsize len,
1271 if (start < 0 || len >= array->length || start + len >= array->length)
1276 env->ex = new java::lang::ArrayIndexOutOfBoundsException ();
1278 catch (jthrowable t)
1280 // Could have thown out of memory error.
1286 T *elts = elements (array) + start;
1287 memcpy (buf, elts, len * sizeof (T));
1291 template<typename T>
1293 _Jv_JNI_SetPrimitiveArrayRegion (JNIEnv *env, JArray<T> *array,
1294 jsize start, jsize len, T *buf)
1296 if (start < 0 || len >= array->length || start + len >= array->length)
1301 env->ex = new java::lang::ArrayIndexOutOfBoundsException ();
1303 catch (jthrowable t)
1310 T *elts = elements (array) + start;
1311 memcpy (elts, buf, len * sizeof (T));
1316 _Jv_JNI_GetPrimitiveArrayCritical (JNIEnv *, jarray array,
1319 // FIXME: does this work?
1320 jclass klass = array->getClass()->getComponentType();
1321 JvAssert (klass->isPrimitive ());
1322 char *r = _Jv_GetArrayElementFromElementType (array, klass);
1329 _Jv_JNI_ReleasePrimitiveArrayCritical (JNIEnv *, jarray, void *, jint)
1335 _Jv_JNI_MonitorEnter (JNIEnv *env, jobject obj)
1339 return _Jv_MonitorEnter (obj);
1341 catch (jthrowable t)
1349 _Jv_JNI_MonitorExit (JNIEnv *env, jobject obj)
1353 return _Jv_MonitorExit (obj);
1355 catch (jthrowable t)
1364 _Jv_JNI_ToReflectedField (JNIEnv *env, jclass cls, jfieldID fieldID,
1369 java::lang::reflect::Field *field = new java::lang::reflect::Field();
1370 field->declaringClass = cls;
1371 field->offset = (char*) fieldID - (char *) cls->fields;
1372 field->name = _Jv_NewStringUtf8Const (fieldID->getNameUtf8Const (cls));
1373 return wrap_value (env, field);
1375 catch (jthrowable t)
1384 _Jv_JNI_FromReflectedField (JNIEnv *, jobject f)
1386 using namespace java::lang::reflect;
1388 Field *field = reinterpret_cast<Field *> (f);
1389 return _Jv_FromReflectedField (field);
1393 _Jv_JNI_ToReflectedMethod (JNIEnv *env, jclass klass, jmethodID id,
1396 using namespace java::lang::reflect;
1399 static _Jv_Utf8Const *init_name = _Jv_makeUtf8Const ("<init>", 6);
1401 jobject result = NULL;
1405 if (_Jv_equalUtf8Consts (id->name, init_name))
1408 Constructor *cons = new Constructor ();
1409 cons->offset = (char *) id - (char *) &klass->methods;
1410 cons->declaringClass = klass;
1415 Method *meth = new Method ();
1416 meth->offset = (char *) id - (char *) &klass->methods;
1417 meth->declaringClass = klass;
1421 catch (jthrowable t)
1426 return wrap_value (env, result);
1430 _Jv_JNI_FromReflectedMethod (JNIEnv *, jobject method)
1432 using namespace java::lang::reflect;
1433 if ((&MethodClass)->isInstance (method))
1434 return _Jv_FromReflectedMethod (reinterpret_cast<Method *> (method));
1436 _Jv_FromReflectedConstructor (reinterpret_cast<Constructor *> (method));
1440 _Jv_JNI_RegisterNatives (JNIEnv *env, jclass k,
1441 const JNINativeMethod *methods,
1445 // For now, this only matters for interpreted methods. FIXME.
1446 if (! _Jv_IsInterpretedClass (k))
1448 // FIXME: throw exception.
1451 _Jv_InterpClass *klass = reinterpret_cast<_Jv_InterpClass *> (k);
1453 // Look at each descriptor given us, and find the corresponding
1454 // method in the class.
1455 for (int j = 0; j < nMethods; ++j)
1459 _Jv_MethodBase **imeths = _Jv_GetFirstMethod (klass);
1460 for (int i = 0; i < JvNumMethods (klass); ++i)
1462 _Jv_MethodBase *meth = imeths[i];
1463 _Jv_Method *self = meth->get_method ();
1465 if (! strcmp (self->name->data, methods[j].name)
1466 && ! strcmp (self->signature->data, methods[j].signature))
1468 if (! (self->accflags
1469 & java::lang::reflect::Modifier::NATIVE))
1472 // Found a match that is native.
1473 _Jv_JNIMethod *jmeth = reinterpret_cast<_Jv_JNIMethod *> (meth);
1474 jmeth->set_function (methods[i].fnPtr);
1482 jstring m = JvNewStringUTF (methods[j].name);
1485 env->ex =new java::lang::NoSuchMethodError (m);
1487 catch (jthrowable t)
1496 #else /* INTERPRETER */
1498 #endif /* INTERPRETER */
1502 _Jv_JNI_UnregisterNatives (JNIEnv *, jclass)
1511 // Add a character to the buffer, encoding properly.
1513 add_char (char *buf, jchar c, int *here)
1517 buf[(*here)++] = '_';
1518 buf[(*here)++] = '1';
1522 buf[(*here)++] = '_';
1523 buf[(*here)++] = '2';
1527 buf[(*here)++] = '_';
1528 buf[(*here)++] = '3';
1531 buf[(*here)++] = '_';
1532 else if ((c >= '0' && c <= '9')
1533 || (c >= 'a' && c <= 'z')
1534 || (c >= 'A' && c <= 'Z'))
1535 buf[(*here)++] = (char) c;
1538 // "Unicode" character.
1539 buf[(*here)++] = '_';
1540 buf[(*here)++] = '0';
1541 for (int i = 0; i < 4; ++i)
1544 buf[(*here) + 4 - i] = (val > 10) ? ('a' + val - 10) : ('0' + val);
1551 // Compute a mangled name for a native function. This computes the
1552 // long name, and also returns an index which indicates where a NUL
1553 // can be placed to create the short name. This function assumes that
1554 // the buffer is large enough for its results.
1556 mangled_name (jclass klass, _Jv_Utf8Const *func_name,
1557 _Jv_Utf8Const *signature, char *buf, int *long_start)
1559 strcpy (buf, "Java_");
1562 // Add fully qualified class name.
1563 jchar *chars = _Jv_GetStringChars (klass->getName ());
1564 jint len = klass->getName ()->length ();
1565 for (int i = 0; i < len; ++i)
1566 add_char (buf, chars[i], &here);
1568 // Don't use add_char because we need a literal `_'.
1571 const unsigned char *fn = (const unsigned char *) func_name->data;
1572 const unsigned char *limit = fn + func_name->length;
1573 for (int i = 0; ; ++i)
1575 int ch = UTF8_GET (fn, limit);
1578 add_char (buf, ch, &here);
1581 // This is where the long signature begins.
1586 const unsigned char *sig = (const unsigned char *) signature->data;
1587 limit = sig + signature->length;
1588 JvAssert (signature[0] == '(');
1592 int ch = UTF8_GET (sig, limit);
1593 if (ch == ')' || ch < 0)
1595 add_char (buf, ch, &here);
1601 // This function is the stub which is used to turn an ordinary (CNI)
1602 // method call into a JNI call.
1604 _Jv_JNIMethod::call (ffi_cif *, void *ret, ffi_raw *args, void *__this)
1606 _Jv_JNIMethod* _this = (_Jv_JNIMethod *) __this;
1609 _Jv_JNI_LocalFrame *frame
1610 = (_Jv_JNI_LocalFrame *) alloca (sizeof (_Jv_JNI_LocalFrame)
1611 + FRAME_SIZE * sizeof (jobject));
1613 env.p = &_Jv_JNIFunctions;
1615 env.klass = _this->defining_class;
1618 frame->marker = true;
1620 frame->size = FRAME_SIZE;
1621 for (int i = 0; i < frame->size; ++i)
1622 frame->vec[i] = NULL;
1624 // FIXME: we should mark every reference parameter as a local. For
1625 // now we assume a conservative GC, and we assume that the
1626 // references are on the stack somewhere.
1628 // We cache the value that we find, of course, but if we don't find
1629 // a value we don't cache that fact -- we might subsequently load a
1630 // library which finds the function in question.
1631 if (_this->function == NULL)
1633 char buf[10 + 6 * (_this->self->name->length
1634 + _this->self->signature->length)];
1636 mangled_name (_this->defining_class, _this->self->name,
1637 _this->self->signature, buf, &long_start);
1638 char c = buf[long_start];
1639 buf[long_start] = '\0';
1640 _this->function = _Jv_FindSymbolInExecutable (buf);
1641 if (_this->function == NULL)
1643 buf[long_start] = c;
1644 _this->function = _Jv_FindSymbolInExecutable (buf);
1645 if (_this->function == NULL)
1647 jstring str = JvNewStringUTF (_this->self->name->data);
1648 JvThrow (new java::lang::AbstractMethodError (str));
1653 JvAssert (_this->args_raw_size % sizeof (ffi_raw) == 0);
1654 ffi_raw real_args[2 + _this->args_raw_size / sizeof (ffi_raw)];
1657 // First argument is always the environment pointer.
1658 real_args[offset++].ptr = &env;
1660 // For a static method, we pass in the Class. For non-static
1661 // methods, the `this' argument is already handled.
1662 if ((_this->self->accflags & java::lang::reflect::Modifier::STATIC))
1663 real_args[offset++].ptr = _this->defining_class;
1665 // Copy over passed-in arguments.
1666 memcpy (&real_args[offset], args, _this->args_raw_size);
1668 // The actual call to the JNI function.
1669 ffi_raw_call (&_this->jni_cif, (void (*) (...)) _this->function,
1674 _Jv_JNI_PopLocalFrame (&env, NULL);
1676 while (env.locals != frame);
1682 #endif /* INTERPRETER */
1690 // An internal helper function.
1692 _Jv_JNI_AttachCurrentThread (JavaVM *, jstring name, void **penv, void *args)
1694 JavaVMAttachArgs *attach = reinterpret_cast<JavaVMAttachArgs *> (args);
1695 java::lang::ThreadGroup *group = NULL;
1699 // FIXME: do we really want to support 1.1?
1700 if (attach->version != JNI_VERSION_1_2
1701 && attach->version != JNI_VERSION_1_1)
1702 return JNI_EVERSION;
1704 JvAssert ((&ThreadGroupClass)->isInstance (attach->group));
1705 group = reinterpret_cast<java::lang::ThreadGroup *> (attach->group);
1708 // Attaching an already-attached thread is a no-op.
1709 if (_Jv_GetCurrentJNIEnv () != NULL)
1712 JNIEnv *env = (JNIEnv *) _Jv_MallocUnchecked (sizeof (JNIEnv));
1715 env->p = &_Jv_JNIFunctions;
1719 = (_Jv_JNI_LocalFrame *) _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame)
1721 * sizeof (jobject)));
1722 if (env->locals == NULL)
1727 *penv = reinterpret_cast<void *> (env);
1729 // This thread might already be a Java thread -- this function might
1730 // have been called simply to set the new JNIEnv.
1731 if (_Jv_ThreadCurrent () == NULL)
1735 (void) new gnu::gcj::jni::NativeThread (group, name);
1737 catch (jthrowable t)
1742 _Jv_SetCurrentJNIEnv (env);
1747 // This is the one actually used by JNI.
1749 _Jv_JNI_AttachCurrentThread (JavaVM *vm, void **penv, void *args)
1751 return _Jv_JNI_AttachCurrentThread (vm, NULL, penv, args);
1755 _Jv_JNI_DestroyJavaVM (JavaVM *vm)
1757 JvAssert (the_vm && vm == the_vm);
1760 if (_Jv_ThreadCurrent () != NULL)
1766 main_name = JvNewStringLatin1 ("main");
1768 catch (jthrowable t)
1773 jint r = _Jv_JNI_AttachCurrentThread (vm,
1775 reinterpret_cast<void **> (&env),
1781 env = _Jv_GetCurrentJNIEnv ();
1785 // Docs say that this always returns an error code.
1790 _Jv_JNI_DetachCurrentThread (JavaVM *)
1792 java::lang::Thread *t = _Jv_ThreadCurrent ();
1794 return JNI_EDETACHED;
1796 // FIXME: we only allow threads attached via AttachCurrentThread to
1797 // be detached. I have no idea how we could implement detaching
1798 // other threads, given the requirement that we must release all the
1799 // monitors. That just seems evil.
1800 JvAssert ((&NativeThreadClass)->isInstance (t));
1802 // FIXME: release the monitors. We'll take this to mean all
1803 // monitors acquired via the JNI interface. This means we have to
1804 // keep track of them.
1806 gnu::gcj::jni::NativeThread *nt
1807 = reinterpret_cast<gnu::gcj::jni::NativeThread *> (t);
1814 _Jv_JNI_GetEnv (JavaVM *, void **penv, jint version)
1816 if (_Jv_ThreadCurrent () == NULL)
1819 return JNI_EDETACHED;
1822 // FIXME: do we really want to support 1.1?
1823 if (version != JNI_VERSION_1_2 && version != JNI_VERSION_1_1)
1826 return JNI_EVERSION;
1829 *penv = (void *) _Jv_GetCurrentJNIEnv ();
1834 JNI_GetDefaultJavaVMInitArgs (void *args)
1836 jint version = * (jint *) args;
1837 // Here we only support 1.2.
1838 if (version != JNI_VERSION_1_2)
1839 return JNI_EVERSION;
1841 JavaVMInitArgs *ia = reinterpret_cast<JavaVMInitArgs *> (args);
1842 ia->version = JNI_VERSION_1_2;
1845 ia->ignoreUnrecognized = true;
1851 JNI_CreateJavaVM (JavaVM **vm, void **penv, void *args)
1853 JvAssert (! the_vm);
1854 // FIXME: synchronize
1855 JavaVM *nvm = (JavaVM *) _Jv_MallocUnchecked (sizeof (JavaVM));
1858 nvm->functions = &_Jv_JNI_InvokeFunctions;
1860 // Parse the arguments.
1863 jint version = * (jint *) args;
1864 // We only support 1.2.
1865 if (version != JNI_VERSION_1_2)
1866 return JNI_EVERSION;
1867 JavaVMInitArgs *ia = reinterpret_cast<JavaVMInitArgs *> (args);
1868 for (int i = 0; i < ia->nOptions; ++i)
1870 if (! strcmp (ia->options[i].optionString, "vfprintf")
1871 || ! strcmp (ia->options[i].optionString, "exit")
1872 || ! strcmp (ia->options[i].optionString, "abort"))
1874 // We are required to recognize these, but for now we
1875 // don't handle them in any way. FIXME.
1878 else if (! strncmp (ia->options[i].optionString,
1879 "-verbose", sizeof ("-verbose") - 1))
1881 // We don't do anything with this option either. We
1882 // might want to make sure the argument is valid, but we
1883 // don't really care all that much for now.
1886 else if (! strncmp (ia->options[i].optionString, "-D", 2))
1891 else if (ia->ignoreUnrecognized)
1893 if (ia->options[i].optionString[0] == '_'
1894 || ! strncmp (ia->options[i].optionString, "-X", 2))
1902 jint r =_Jv_JNI_AttachCurrentThread (nvm, penv, NULL);
1912 JNI_GetCreatedJavaVMs (JavaVM **vm_buffer, jsize /* buf_len */, jsize *n_vms)
1914 JvAssert (buf_len > 0);
1915 // We only support a single VM.
1918 vm_buffer[0] = the_vm;
1929 // FIXME: synchronize
1932 JavaVM *nvm = (JavaVM *) _Jv_MallocUnchecked (sizeof (JavaVM));
1934 nvm->functions = &_Jv_JNI_InvokeFunctions;
1938 // If this is a Java thread, we want to make sure it has an
1939 // associated JNIEnv.
1940 if (_Jv_ThreadCurrent () != NULL)
1943 _Jv_JNI_AttachCurrentThread (the_vm, &ignore, NULL);
1950 _Jv_JNI_GetJavaVM (JNIEnv *, JavaVM **vm)
1952 *vm = _Jv_GetJavaVM ();
1953 return *vm == NULL ? JNI_ERR : JNI_OK;
1958 #define NOT_IMPL NULL
1959 #define RESERVED NULL
1961 struct JNINativeInterface _Jv_JNIFunctions =
1968 _Jv_JNI_DefineClass,
1970 _Jv_JNI_FromReflectedMethod,
1971 _Jv_JNI_FromReflectedField,
1972 _Jv_JNI_ToReflectedMethod,
1973 _Jv_JNI_GetSuperclass,
1974 _Jv_JNI_IsAssignableFrom,
1975 _Jv_JNI_ToReflectedField,
1978 _Jv_JNI_ExceptionOccurred,
1979 _Jv_JNI_ExceptionDescribe,
1980 _Jv_JNI_ExceptionClear,
1983 _Jv_JNI_PushLocalFrame,
1984 _Jv_JNI_PopLocalFrame,
1985 _Jv_JNI_NewGlobalRef,
1986 _Jv_JNI_DeleteGlobalRef,
1987 _Jv_JNI_DeleteLocalRef,
1989 _Jv_JNI_IsSameObject,
1991 _Jv_JNI_NewLocalRef,
1992 _Jv_JNI_EnsureLocalCapacity,
1994 _Jv_JNI_AllocObject,
1998 _Jv_JNI_GetObjectClass,
1999 _Jv_JNI_IsInstanceOf,
2000 _Jv_JNI_GetAnyMethodID<false>,
2002 _Jv_JNI_CallMethod<jobject>,
2003 _Jv_JNI_CallMethodV<jobject>,
2004 _Jv_JNI_CallMethodA<jobject>,
2005 _Jv_JNI_CallMethod<jboolean>,
2006 _Jv_JNI_CallMethodV<jboolean>,
2007 _Jv_JNI_CallMethodA<jboolean>,
2008 _Jv_JNI_CallMethod<jbyte>,
2009 _Jv_JNI_CallMethodV<jbyte>,
2010 _Jv_JNI_CallMethodA<jbyte>,
2011 _Jv_JNI_CallMethod<jchar>,
2012 _Jv_JNI_CallMethodV<jchar>,
2013 _Jv_JNI_CallMethodA<jchar>,
2014 _Jv_JNI_CallMethod<jshort>,
2015 _Jv_JNI_CallMethodV<jshort>,
2016 _Jv_JNI_CallMethodA<jshort>,
2017 _Jv_JNI_CallMethod<jint>,
2018 _Jv_JNI_CallMethodV<jint>,
2019 _Jv_JNI_CallMethodA<jint>,
2020 _Jv_JNI_CallMethod<jlong>,
2021 _Jv_JNI_CallMethodV<jlong>,
2022 _Jv_JNI_CallMethodA<jlong>,
2023 _Jv_JNI_CallMethod<jfloat>,
2024 _Jv_JNI_CallMethodV<jfloat>,
2025 _Jv_JNI_CallMethodA<jfloat>,
2026 _Jv_JNI_CallMethod<jdouble>,
2027 _Jv_JNI_CallMethodV<jdouble>,
2028 _Jv_JNI_CallMethodA<jdouble>,
2029 _Jv_JNI_CallVoidMethod,
2030 _Jv_JNI_CallVoidMethodV,
2031 _Jv_JNI_CallVoidMethodA,
2033 // Nonvirtual method invocation functions follow.
2034 _Jv_JNI_CallAnyMethod<jobject, nonvirtual>,
2035 _Jv_JNI_CallAnyMethodV<jobject, nonvirtual>,
2036 _Jv_JNI_CallAnyMethodA<jobject, nonvirtual>,
2037 _Jv_JNI_CallAnyMethod<jboolean, nonvirtual>,
2038 _Jv_JNI_CallAnyMethodV<jboolean, nonvirtual>,
2039 _Jv_JNI_CallAnyMethodA<jboolean, nonvirtual>,
2040 _Jv_JNI_CallAnyMethod<jbyte, nonvirtual>,
2041 _Jv_JNI_CallAnyMethodV<jbyte, nonvirtual>,
2042 _Jv_JNI_CallAnyMethodA<jbyte, nonvirtual>,
2043 _Jv_JNI_CallAnyMethod<jchar, nonvirtual>,
2044 _Jv_JNI_CallAnyMethodV<jchar, nonvirtual>,
2045 _Jv_JNI_CallAnyMethodA<jchar, nonvirtual>,
2046 _Jv_JNI_CallAnyMethod<jshort, nonvirtual>,
2047 _Jv_JNI_CallAnyMethodV<jshort, nonvirtual>,
2048 _Jv_JNI_CallAnyMethodA<jshort, nonvirtual>,
2049 _Jv_JNI_CallAnyMethod<jint, nonvirtual>,
2050 _Jv_JNI_CallAnyMethodV<jint, nonvirtual>,
2051 _Jv_JNI_CallAnyMethodA<jint, nonvirtual>,
2052 _Jv_JNI_CallAnyMethod<jlong, nonvirtual>,
2053 _Jv_JNI_CallAnyMethodV<jlong, nonvirtual>,
2054 _Jv_JNI_CallAnyMethodA<jlong, nonvirtual>,
2055 _Jv_JNI_CallAnyMethod<jfloat, nonvirtual>,
2056 _Jv_JNI_CallAnyMethodV<jfloat, nonvirtual>,
2057 _Jv_JNI_CallAnyMethodA<jfloat, nonvirtual>,
2058 _Jv_JNI_CallAnyMethod<jdouble, nonvirtual>,
2059 _Jv_JNI_CallAnyMethodV<jdouble, nonvirtual>,
2060 _Jv_JNI_CallAnyMethodA<jdouble, nonvirtual>,
2061 _Jv_JNI_CallAnyVoidMethod<nonvirtual>,
2062 _Jv_JNI_CallAnyVoidMethodV<nonvirtual>,
2063 _Jv_JNI_CallAnyVoidMethodA<nonvirtual>,
2065 _Jv_JNI_GetAnyFieldID<false>,
2066 _Jv_JNI_GetField<jobject>,
2067 _Jv_JNI_GetField<jboolean>,
2068 _Jv_JNI_GetField<jbyte>,
2069 _Jv_JNI_GetField<jchar>,
2070 _Jv_JNI_GetField<jshort>,
2071 _Jv_JNI_GetField<jint>,
2072 _Jv_JNI_GetField<jlong>,
2073 _Jv_JNI_GetField<jfloat>,
2074 _Jv_JNI_GetField<jdouble>,
2084 _Jv_JNI_GetAnyMethodID<true>,
2086 _Jv_JNI_CallStaticMethod<jobject>,
2087 _Jv_JNI_CallStaticMethodV<jobject>,
2088 _Jv_JNI_CallStaticMethodA<jobject>,
2089 _Jv_JNI_CallStaticMethod<jboolean>,
2090 _Jv_JNI_CallStaticMethodV<jboolean>,
2091 _Jv_JNI_CallStaticMethodA<jboolean>,
2092 _Jv_JNI_CallStaticMethod<jbyte>,
2093 _Jv_JNI_CallStaticMethodV<jbyte>,
2094 _Jv_JNI_CallStaticMethodA<jbyte>,
2095 _Jv_JNI_CallStaticMethod<jchar>,
2096 _Jv_JNI_CallStaticMethodV<jchar>,
2097 _Jv_JNI_CallStaticMethodA<jchar>,
2098 _Jv_JNI_CallStaticMethod<jshort>,
2099 _Jv_JNI_CallStaticMethodV<jshort>,
2100 _Jv_JNI_CallStaticMethodA<jshort>,
2101 _Jv_JNI_CallStaticMethod<jint>,
2102 _Jv_JNI_CallStaticMethodV<jint>,
2103 _Jv_JNI_CallStaticMethodA<jint>,
2104 _Jv_JNI_CallStaticMethod<jlong>,
2105 _Jv_JNI_CallStaticMethodV<jlong>,
2106 _Jv_JNI_CallStaticMethodA<jlong>,
2107 _Jv_JNI_CallStaticMethod<jfloat>,
2108 _Jv_JNI_CallStaticMethodV<jfloat>,
2109 _Jv_JNI_CallStaticMethodA<jfloat>,
2110 _Jv_JNI_CallStaticMethod<jdouble>,
2111 _Jv_JNI_CallStaticMethodV<jdouble>,
2112 _Jv_JNI_CallStaticMethodA<jdouble>,
2113 _Jv_JNI_CallStaticVoidMethod,
2114 _Jv_JNI_CallStaticVoidMethodV,
2115 _Jv_JNI_CallStaticVoidMethodA,
2117 _Jv_JNI_GetAnyFieldID<true>,
2118 _Jv_JNI_GetStaticField<jobject>,
2119 _Jv_JNI_GetStaticField<jboolean>,
2120 _Jv_JNI_GetStaticField<jbyte>,
2121 _Jv_JNI_GetStaticField<jchar>,
2122 _Jv_JNI_GetStaticField<jshort>,
2123 _Jv_JNI_GetStaticField<jint>,
2124 _Jv_JNI_GetStaticField<jlong>,
2125 _Jv_JNI_GetStaticField<jfloat>,
2126 _Jv_JNI_GetStaticField<jdouble>,
2127 _Jv_JNI_SetStaticField,
2128 _Jv_JNI_SetStaticField,
2129 _Jv_JNI_SetStaticField,
2130 _Jv_JNI_SetStaticField,
2131 _Jv_JNI_SetStaticField,
2132 _Jv_JNI_SetStaticField,
2133 _Jv_JNI_SetStaticField,
2134 _Jv_JNI_SetStaticField,
2135 _Jv_JNI_SetStaticField,
2137 _Jv_JNI_GetStringLength,
2138 _Jv_JNI_GetStringChars,
2139 _Jv_JNI_ReleaseStringChars,
2140 _Jv_JNI_NewStringUTF,
2141 _Jv_JNI_GetStringUTFLength,
2142 _Jv_JNI_GetStringUTFChars,
2143 _Jv_JNI_ReleaseStringUTFChars,
2144 _Jv_JNI_GetArrayLength,
2145 _Jv_JNI_NewObjectArray,
2146 _Jv_JNI_GetObjectArrayElement,
2147 _Jv_JNI_SetObjectArrayElement,
2148 _Jv_JNI_NewPrimitiveArray<jboolean, JvPrimClass (boolean)>,
2149 _Jv_JNI_NewPrimitiveArray<jbyte, JvPrimClass (byte)>,
2150 _Jv_JNI_NewPrimitiveArray<jchar, JvPrimClass (char)>,
2151 _Jv_JNI_NewPrimitiveArray<jshort, JvPrimClass (short)>,
2152 _Jv_JNI_NewPrimitiveArray<jint, JvPrimClass (int)>,
2153 _Jv_JNI_NewPrimitiveArray<jlong, JvPrimClass (long)>,
2154 _Jv_JNI_NewPrimitiveArray<jfloat, JvPrimClass (float)>,
2155 _Jv_JNI_NewPrimitiveArray<jdouble, JvPrimClass (double)>,
2156 _Jv_JNI_GetPrimitiveArrayElements,
2157 _Jv_JNI_GetPrimitiveArrayElements,
2158 _Jv_JNI_GetPrimitiveArrayElements,
2159 _Jv_JNI_GetPrimitiveArrayElements,
2160 _Jv_JNI_GetPrimitiveArrayElements,
2161 _Jv_JNI_GetPrimitiveArrayElements,
2162 _Jv_JNI_GetPrimitiveArrayElements,
2163 _Jv_JNI_GetPrimitiveArrayElements,
2164 _Jv_JNI_ReleasePrimitiveArrayElements,
2165 _Jv_JNI_ReleasePrimitiveArrayElements,
2166 _Jv_JNI_ReleasePrimitiveArrayElements,
2167 _Jv_JNI_ReleasePrimitiveArrayElements,
2168 _Jv_JNI_ReleasePrimitiveArrayElements,
2169 _Jv_JNI_ReleasePrimitiveArrayElements,
2170 _Jv_JNI_ReleasePrimitiveArrayElements,
2171 _Jv_JNI_ReleasePrimitiveArrayElements,
2172 _Jv_JNI_GetPrimitiveArrayRegion,
2173 _Jv_JNI_GetPrimitiveArrayRegion,
2174 _Jv_JNI_GetPrimitiveArrayRegion,
2175 _Jv_JNI_GetPrimitiveArrayRegion,
2176 _Jv_JNI_GetPrimitiveArrayRegion,
2177 _Jv_JNI_GetPrimitiveArrayRegion,
2178 _Jv_JNI_GetPrimitiveArrayRegion,
2179 _Jv_JNI_GetPrimitiveArrayRegion,
2180 _Jv_JNI_SetPrimitiveArrayRegion,
2181 _Jv_JNI_SetPrimitiveArrayRegion,
2182 _Jv_JNI_SetPrimitiveArrayRegion,
2183 _Jv_JNI_SetPrimitiveArrayRegion,
2184 _Jv_JNI_SetPrimitiveArrayRegion,
2185 _Jv_JNI_SetPrimitiveArrayRegion,
2186 _Jv_JNI_SetPrimitiveArrayRegion,
2187 _Jv_JNI_SetPrimitiveArrayRegion,
2188 _Jv_JNI_RegisterNatives,
2189 _Jv_JNI_UnregisterNatives,
2190 _Jv_JNI_MonitorEnter,
2191 _Jv_JNI_MonitorExit,
2194 _Jv_JNI_GetStringRegion,
2195 _Jv_JNI_GetStringUTFRegion,
2196 _Jv_JNI_GetPrimitiveArrayCritical,
2197 _Jv_JNI_ReleasePrimitiveArrayCritical,
2198 _Jv_JNI_GetStringCritical,
2199 _Jv_JNI_ReleaseStringCritical,
2201 NOT_IMPL /* newweakglobalref */,
2202 NOT_IMPL /* deleteweakglobalref */,
2204 _Jv_JNI_ExceptionCheck
2207 struct JNIInvokeInterface _Jv_JNI_InvokeFunctions =
2213 _Jv_JNI_DestroyJavaVM,
2214 _Jv_JNI_AttachCurrentThread,
2215 _Jv_JNI_DetachCurrentThread,