* Makefile.in (SYSTEM_H): Define.
[official-gcc.git] / libjava / jni.cc
blob7fac86ee1261b532ff1fe8da782f1ce232b3c1da
1 // jni.cc - JNI implementation, including the jump table.
3 /* Copyright (C) 1998, 1999, 2000, 2001 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
9 details. */
11 #include <config.h>
13 #include <stddef.h>
14 #include <string.h>
16 // Define this before including jni.h.
17 #define __GCJ_JNI_IMPL__
19 #include <gcj/cni.h>
20 #include <jvm.h>
21 #include <java-assert.h>
22 #include <jni.h>
23 #ifdef ENABLE_JVMPI
24 #include <jvmpi.h>
25 #endif
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 <java/lang/ThreadGroup.h>
43 #include <gnu/gcj/jni/NativeThread.h>
45 #include <gcj/method.h>
46 #include <gcj/field.h>
48 #include <java-interp.h>
50 // FIXME: remove these defines.
51 #define ClassClass java::lang::Class::class$
52 #define ObjectClass java::lang::Object::class$
53 #define ThrowableClass java::lang::Throwable::class$
54 #define MethodClass java::lang::reflect::Method::class$
55 #define ThreadGroupClass java::lang::ThreadGroup::class$
56 #define NativeThreadClass gnu::gcj::jni::NativeThread::class$
58 // This enum is used to select different template instantiations in
59 // the invocation code.
60 enum invocation_type
62 normal,
63 nonvirtual,
64 static_type,
65 constructor
68 // Forward declarations.
69 extern struct JNINativeInterface _Jv_JNIFunctions;
70 extern struct JNIInvokeInterface _Jv_JNI_InvokeFunctions;
72 // Number of slots in the default frame. The VM must allow at least
73 // 16.
74 #define FRAME_SIZE 32
76 // Mark value indicating this is an overflow frame.
77 #define MARK_NONE 0
78 // Mark value indicating this is a user frame.
79 #define MARK_USER 1
80 // Mark value indicating this is a system frame.
81 #define MARK_SYSTEM 2
83 // This structure is used to keep track of local references.
84 struct _Jv_JNI_LocalFrame
86 // This is true if this frame object represents a pushed frame (eg
87 // from PushLocalFrame).
88 int marker : 2;
90 // Number of elements in frame.
91 int size : 30;
93 // Next frame in chain.
94 _Jv_JNI_LocalFrame *next;
96 // The elements. These are allocated using the C "struct hack".
97 jobject vec[0];
100 // This holds a reference count for all local and global references.
101 static java::util::Hashtable *ref_table;
103 // The only VM.
104 static JavaVM *the_vm;
106 #ifdef ENABLE_JVMPI
107 // The only JVMPI interface description.
108 static JVMPI_Interface _Jv_JVMPI_Interface;
110 static jint
111 jvmpiEnableEvent (jint event_type, void *)
113 switch (event_type)
115 case JVMPI_EVENT_OBJECT_ALLOC:
116 _Jv_JVMPI_Notify_OBJECT_ALLOC = _Jv_JVMPI_Interface.NotifyEvent;
117 break;
119 case JVMPI_EVENT_THREAD_START:
120 _Jv_JVMPI_Notify_THREAD_START = _Jv_JVMPI_Interface.NotifyEvent;
121 break;
123 case JVMPI_EVENT_THREAD_END:
124 _Jv_JVMPI_Notify_THREAD_END = _Jv_JVMPI_Interface.NotifyEvent;
125 break;
127 default:
128 return JVMPI_NOT_AVAILABLE;
131 return JVMPI_SUCCESS;
134 static jint
135 jvmpiDisableEvent (jint event_type, void *)
137 switch (event_type)
139 case JVMPI_EVENT_OBJECT_ALLOC:
140 _Jv_JVMPI_Notify_OBJECT_ALLOC = NULL;
141 break;
143 default:
144 return JVMPI_NOT_AVAILABLE;
147 return JVMPI_SUCCESS;
149 #endif
153 void
154 _Jv_JNI_Init (void)
156 ref_table = new java::util::Hashtable;
158 #ifdef ENABLE_JVMPI
159 _Jv_JVMPI_Interface.version = 1;
160 _Jv_JVMPI_Interface.EnableEvent = &jvmpiEnableEvent;
161 _Jv_JVMPI_Interface.DisableEvent = &jvmpiDisableEvent;
162 _Jv_JVMPI_Interface.EnableGC = &_Jv_EnableGC;
163 _Jv_JVMPI_Interface.DisableGC = &_Jv_DisableGC;
164 _Jv_JVMPI_Interface.RunGC = &_Jv_RunGC;
165 #endif
168 // Tell the GC that a certain pointer is live.
169 static void
170 mark_for_gc (jobject obj)
172 JvSynchronize sync (ref_table);
174 using namespace java::lang;
175 Integer *refcount = (Integer *) ref_table->get (obj);
176 jint val = (refcount == NULL) ? 0 : refcount->intValue ();
177 // FIXME: what about out of memory error?
178 ref_table->put (obj, new Integer (val + 1));
181 // Unmark a pointer.
182 static void
183 unmark_for_gc (jobject obj)
185 JvSynchronize sync (ref_table);
187 using namespace java::lang;
188 Integer *refcount = (Integer *) ref_table->get (obj);
189 JvAssert (refcount);
190 jint val = refcount->intValue () - 1;
191 if (val == 0)
192 ref_table->remove (obj);
193 else
194 // FIXME: what about out of memory error?
195 ref_table->put (obj, new Integer (val));
200 static jobject
201 _Jv_JNI_NewGlobalRef (JNIEnv *, jobject obj)
203 mark_for_gc (obj);
204 return obj;
207 static void
208 _Jv_JNI_DeleteGlobalRef (JNIEnv *, jobject obj)
210 unmark_for_gc (obj);
213 static void
214 _Jv_JNI_DeleteLocalRef (JNIEnv *env, jobject obj)
216 _Jv_JNI_LocalFrame *frame;
218 for (frame = env->locals; frame != NULL; frame = frame->next)
220 for (int i = 0; i < FRAME_SIZE; ++i)
222 if (frame->vec[i] == obj)
224 frame->vec[i] = NULL;
225 unmark_for_gc (obj);
226 return;
230 // Don't go past a marked frame.
231 JvAssert (frame->marker == MARK_NONE);
234 JvAssert (0);
237 static jint
238 _Jv_JNI_EnsureLocalCapacity (JNIEnv *env, jint size)
240 // It is easier to just always allocate a new frame of the requested
241 // size. This isn't the most efficient thing, but for now we don't
242 // care. Note that _Jv_JNI_PushLocalFrame relies on this right now.
244 _Jv_JNI_LocalFrame *frame;
247 frame = (_Jv_JNI_LocalFrame *) _Jv_Malloc (sizeof (_Jv_JNI_LocalFrame)
248 + size * sizeof (jobject));
250 catch (jthrowable t)
252 env->ex = t;
253 return JNI_ERR;
256 frame->marker = MARK_NONE;
257 frame->size = size;
258 memset (&frame->vec[0], 0, size * sizeof (jobject));
259 frame->next = env->locals;
260 env->locals = frame;
262 return 0;
265 static jint
266 _Jv_JNI_PushLocalFrame (JNIEnv *env, jint size)
268 jint r = _Jv_JNI_EnsureLocalCapacity (env, size);
269 if (r < 0)
270 return r;
272 // The new frame is on top.
273 env->locals->marker = MARK_USER;
275 return 0;
278 static jobject
279 _Jv_JNI_NewLocalRef (JNIEnv *env, jobject obj)
281 // Try to find an open slot somewhere in the topmost frame.
282 _Jv_JNI_LocalFrame *frame = env->locals;
283 bool done = false, set = false;
284 while (frame != NULL && ! done)
286 for (int i = 0; i < frame->size; ++i)
287 if (frame->vec[i] == NULL)
289 set = true;
290 done = true;
291 frame->vec[i] = obj;
292 break;
296 if (! set)
298 // No slots, so we allocate a new frame. According to the spec
299 // we could just die here. FIXME: return value.
300 _Jv_JNI_EnsureLocalCapacity (env, 16);
301 // We know the first element of the new frame will be ok.
302 env->locals->vec[0] = obj;
305 mark_for_gc (obj);
306 return obj;
309 static jobject
310 _Jv_JNI_PopLocalFrame (JNIEnv *env, jobject result, int stop)
312 _Jv_JNI_LocalFrame *rf = env->locals;
314 bool done = false;
315 while (rf != NULL && ! done)
317 for (int i = 0; i < rf->size; ++i)
318 if (rf->vec[i] != NULL)
319 unmark_for_gc (rf->vec[i]);
321 // If the frame we just freed is the marker frame, we are done.
322 done = (rf->marker == stop);
324 _Jv_JNI_LocalFrame *n = rf->next;
325 // When N==NULL, we've reached the stack-allocated frame, and we
326 // must not free it. However, we must be sure to clear all its
327 // elements, since we might conceivably reuse it.
328 if (n == NULL)
330 memset (&rf->vec[0], 0, rf->size * sizeof (jobject));
331 break;
334 _Jv_Free (rf);
335 rf = n;
338 return result == NULL ? NULL : _Jv_JNI_NewLocalRef (env, result);
341 static jobject
342 _Jv_JNI_PopLocalFrame (JNIEnv *env, jobject result)
344 return _Jv_JNI_PopLocalFrame (env, result, MARK_USER);
347 // Pop a `system' frame from the stack. This is `extern "C"' as it is
348 // used by the compiler.
349 extern "C" void
350 _Jv_JNI_PopSystemFrame (JNIEnv *env)
352 _Jv_JNI_PopLocalFrame (env, NULL, MARK_SYSTEM);
354 if (env->ex)
356 jthrowable t = env->ex;
357 env->ex = NULL;
358 throw t;
362 // This function is used from other template functions. It wraps the
363 // return value appropriately; we specialize it so that object returns
364 // are turned into local references.
365 template<typename T>
366 static T
367 wrap_value (JNIEnv *, T value)
369 return value;
372 template<>
373 static jobject
374 wrap_value (JNIEnv *env, jobject value)
376 return value == NULL ? value : _Jv_JNI_NewLocalRef (env, value);
381 static jint
382 _Jv_JNI_GetVersion (JNIEnv *)
384 return JNI_VERSION_1_2;
387 static jclass
388 _Jv_JNI_DefineClass (JNIEnv *env, jobject loader,
389 const jbyte *buf, jsize bufLen)
393 jbyteArray bytes = JvNewByteArray (bufLen);
395 jbyte *elts = elements (bytes);
396 memcpy (elts, buf, bufLen * sizeof (jbyte));
398 java::lang::ClassLoader *l
399 = reinterpret_cast<java::lang::ClassLoader *> (loader);
401 jclass result = l->defineClass (bytes, 0, bufLen);
402 return (jclass) wrap_value (env, result);
404 catch (jthrowable t)
406 env->ex = t;
407 return NULL;
411 static jclass
412 _Jv_JNI_FindClass (JNIEnv *env, const char *name)
414 // FIXME: assume that NAME isn't too long.
415 int len = strlen (name);
416 char s[len + 1];
417 for (int i = 0; i <= len; ++i)
418 s[i] = (name[i] == '/') ? '.' : name[i];
420 jclass r = NULL;
423 // This might throw an out of memory exception.
424 jstring n = JvNewStringUTF (s);
426 java::lang::ClassLoader *loader = NULL;
427 if (env->klass != NULL)
428 loader = env->klass->getClassLoader ();
430 if (loader == NULL)
432 // FIXME: should use getBaseClassLoader, but we don't have that
433 // yet.
434 loader = java::lang::ClassLoader::getSystemClassLoader ();
437 r = loader->loadClass (n);
439 catch (jthrowable t)
441 env->ex = t;
444 return (jclass) wrap_value (env, r);
447 static jclass
448 _Jv_JNI_GetSuperclass (JNIEnv *env, jclass clazz)
450 return (jclass) wrap_value (env, clazz->getSuperclass ());
453 static jboolean
454 _Jv_JNI_IsAssignableFrom(JNIEnv *, jclass clazz1, jclass clazz2)
456 return clazz1->isAssignableFrom (clazz2);
459 static jint
460 _Jv_JNI_Throw (JNIEnv *env, jthrowable obj)
462 // We check in case the user did some funky cast.
463 JvAssert (obj != NULL && (&ThrowableClass)->isInstance (obj));
464 env->ex = obj;
465 return 0;
468 static jint
469 _Jv_JNI_ThrowNew (JNIEnv *env, jclass clazz, const char *message)
471 using namespace java::lang::reflect;
473 JvAssert ((&ThrowableClass)->isAssignableFrom (clazz));
475 int r = JNI_OK;
478 JArray<jclass> *argtypes
479 = (JArray<jclass> *) JvNewObjectArray (1, &ClassClass, NULL);
481 jclass *elts = elements (argtypes);
482 elts[0] = &StringClass;
484 Constructor *cons = clazz->getConstructor (argtypes);
486 jobjectArray values = JvNewObjectArray (1, &StringClass, NULL);
487 jobject *velts = elements (values);
488 velts[0] = JvNewStringUTF (message);
490 jobject obj = cons->newInstance (values);
492 env->ex = reinterpret_cast<jthrowable> (obj);
494 catch (jthrowable t)
496 env->ex = t;
497 r = JNI_ERR;
500 return r;
503 static jthrowable
504 _Jv_JNI_ExceptionOccurred (JNIEnv *env)
506 return (jthrowable) wrap_value (env, env->ex);
509 static void
510 _Jv_JNI_ExceptionDescribe (JNIEnv *env)
512 if (env->ex != NULL)
513 env->ex->printStackTrace();
516 static void
517 _Jv_JNI_ExceptionClear (JNIEnv *env)
519 env->ex = NULL;
522 static jboolean
523 _Jv_JNI_ExceptionCheck (JNIEnv *env)
525 return env->ex != NULL;
528 static void
529 _Jv_JNI_FatalError (JNIEnv *, const char *message)
531 JvFail (message);
536 static jboolean
537 _Jv_JNI_IsSameObject (JNIEnv *, jobject obj1, jobject obj2)
539 return obj1 == obj2;
542 static jobject
543 _Jv_JNI_AllocObject (JNIEnv *env, jclass clazz)
545 jobject obj = NULL;
546 using namespace java::lang::reflect;
550 JvAssert (clazz && ! clazz->isArray ());
551 if (clazz->isInterface() || Modifier::isAbstract(clazz->getModifiers()))
552 env->ex = new java::lang::InstantiationException ();
553 else
555 // FIXME: will this work for String?
556 obj = JvAllocObject (clazz);
559 catch (jthrowable t)
561 env->ex = t;
564 return wrap_value (env, obj);
567 static jclass
568 _Jv_JNI_GetObjectClass (JNIEnv *env, jobject obj)
570 JvAssert (obj);
571 return (jclass) wrap_value (env, obj->getClass());
574 static jboolean
575 _Jv_JNI_IsInstanceOf (JNIEnv *, jobject obj, jclass clazz)
577 return clazz->isInstance(obj);
583 // This section concerns method invocation.
586 template<jboolean is_static>
587 static jmethodID
588 _Jv_JNI_GetAnyMethodID (JNIEnv *env, jclass clazz,
589 const char *name, const char *sig)
593 _Jv_InitClass (clazz);
595 _Jv_Utf8Const *name_u = _Jv_makeUtf8Const ((char *) name, -1);
597 // FIXME: assume that SIG isn't too long.
598 int len = strlen (sig);
599 char s[len + 1];
600 for (int i = 0; i <= len; ++i)
601 s[i] = (sig[i] == '/') ? '.' : sig[i];
602 _Jv_Utf8Const *sig_u = _Jv_makeUtf8Const ((char *) s, -1);
604 JvAssert (! clazz->isPrimitive());
606 using namespace java::lang::reflect;
608 while (clazz != NULL)
610 jint count = JvNumMethods (clazz);
611 jmethodID meth = JvGetFirstMethod (clazz);
613 for (jint i = 0; i < count; ++i)
615 if (((is_static && Modifier::isStatic (meth->accflags))
616 || (! is_static && ! Modifier::isStatic (meth->accflags)))
617 && _Jv_equalUtf8Consts (meth->name, name_u)
618 && _Jv_equalUtf8Consts (meth->signature, sig_u))
619 return meth;
621 meth = meth->getNextMethod();
624 clazz = clazz->getSuperclass ();
627 env->ex = new java::lang::NoSuchMethodError ();
629 catch (jthrowable t)
631 env->ex = t;
634 return NULL;
637 // This is a helper function which turns a va_list into an array of
638 // `jvalue's. It needs signature information in order to do its work.
639 // The array of values must already be allocated.
640 static void
641 array_from_valist (jvalue *values, JArray<jclass> *arg_types, va_list vargs)
643 jclass *arg_elts = elements (arg_types);
644 for (int i = 0; i < arg_types->length; ++i)
646 if (arg_elts[i] == JvPrimClass (byte))
647 values[i].b = va_arg (vargs, jbyte);
648 else if (arg_elts[i] == JvPrimClass (short))
649 values[i].s = va_arg (vargs, jshort);
650 else if (arg_elts[i] == JvPrimClass (int))
651 values[i].i = va_arg (vargs, jint);
652 else if (arg_elts[i] == JvPrimClass (long))
653 values[i].j = va_arg (vargs, jlong);
654 else if (arg_elts[i] == JvPrimClass (float))
655 values[i].f = va_arg (vargs, jfloat);
656 else if (arg_elts[i] == JvPrimClass (double))
657 values[i].d = va_arg (vargs, jdouble);
658 else if (arg_elts[i] == JvPrimClass (boolean))
659 values[i].z = va_arg (vargs, jboolean);
660 else if (arg_elts[i] == JvPrimClass (char))
661 values[i].c = va_arg (vargs, jchar);
662 else
664 // An object.
665 values[i].l = va_arg (vargs, jobject);
670 // This can call any sort of method: virtual, "nonvirtual", static, or
671 // constructor.
672 template<typename T, invocation_type style>
673 static T
674 _Jv_JNI_CallAnyMethodV (JNIEnv *env, jobject obj, jclass klass,
675 jmethodID id, va_list vargs)
677 if (style == normal)
678 id = _Jv_LookupDeclaredMethod (obj->getClass (), id->name, id->signature);
680 jclass decl_class = klass ? klass : obj->getClass ();
681 JvAssert (decl_class != NULL);
683 jclass return_type;
684 JArray<jclass> *arg_types;
688 _Jv_GetTypesFromSignature (id, decl_class,
689 &arg_types, &return_type);
691 jvalue args[arg_types->length];
692 array_from_valist (args, arg_types, vargs);
694 // For constructors we need to pass the Class we are instantiating.
695 if (style == constructor)
696 return_type = klass;
698 jvalue result;
699 jthrowable ex = _Jv_CallAnyMethodA (obj, return_type, id,
700 style == constructor,
701 arg_types, args, &result);
703 if (ex != NULL)
704 env->ex = ex;
706 // We cheat a little here. FIXME.
707 return wrap_value (env, * (T *) &result);
709 catch (jthrowable t)
711 env->ex = t;
714 return wrap_value (env, (T) 0);
717 template<typename T, invocation_type style>
718 static T
719 _Jv_JNI_CallAnyMethod (JNIEnv *env, jobject obj, jclass klass,
720 jmethodID method, ...)
722 va_list args;
723 T result;
725 va_start (args, method);
726 result = _Jv_JNI_CallAnyMethodV<T, style> (env, obj, klass, method, args);
727 va_end (args);
729 return result;
732 template<typename T, invocation_type style>
733 static T
734 _Jv_JNI_CallAnyMethodA (JNIEnv *env, jobject obj, jclass klass,
735 jmethodID id, jvalue *args)
737 if (style == normal)
738 id = _Jv_LookupDeclaredMethod (obj->getClass (), id->name, id->signature);
740 jclass decl_class = klass ? klass : obj->getClass ();
741 JvAssert (decl_class != NULL);
743 jclass return_type;
744 JArray<jclass> *arg_types;
747 _Jv_GetTypesFromSignature (id, decl_class,
748 &arg_types, &return_type);
750 // For constructors we need to pass the Class we are instantiating.
751 if (style == constructor)
752 return_type = klass;
754 jvalue result;
755 jthrowable ex = _Jv_CallAnyMethodA (obj, return_type, id,
756 style == constructor,
757 arg_types, args, &result);
759 if (ex != NULL)
760 env->ex = ex;
762 // We cheat a little here. FIXME.
763 return wrap_value (env, * (T *) &result);
765 catch (jthrowable t)
767 env->ex = t;
770 return wrap_value (env, (T) 0);
773 template<invocation_type style>
774 static void
775 _Jv_JNI_CallAnyVoidMethodV (JNIEnv *env, jobject obj, jclass klass,
776 jmethodID id, va_list vargs)
778 if (style == normal)
779 id = _Jv_LookupDeclaredMethod (obj->getClass (), id->name, id->signature);
781 jclass decl_class = klass ? klass : obj->getClass ();
782 JvAssert (decl_class != NULL);
784 jclass return_type;
785 JArray<jclass> *arg_types;
788 _Jv_GetTypesFromSignature (id, decl_class,
789 &arg_types, &return_type);
791 jvalue args[arg_types->length];
792 array_from_valist (args, arg_types, vargs);
794 // For constructors we need to pass the Class we are instantiating.
795 if (style == constructor)
796 return_type = klass;
798 jthrowable ex = _Jv_CallAnyMethodA (obj, return_type, id,
799 style == constructor,
800 arg_types, args, NULL);
802 if (ex != NULL)
803 env->ex = ex;
805 catch (jthrowable t)
807 env->ex = t;
811 template<invocation_type style>
812 static void
813 _Jv_JNI_CallAnyVoidMethod (JNIEnv *env, jobject obj, jclass klass,
814 jmethodID method, ...)
816 va_list args;
818 va_start (args, method);
819 _Jv_JNI_CallAnyVoidMethodV<style> (env, obj, klass, method, args);
820 va_end (args);
823 template<invocation_type style>
824 static void
825 _Jv_JNI_CallAnyVoidMethodA (JNIEnv *env, jobject obj, jclass klass,
826 jmethodID id, jvalue *args)
828 if (style == normal)
829 id = _Jv_LookupDeclaredMethod (obj->getClass (), id->name, id->signature);
831 jclass decl_class = klass ? klass : obj->getClass ();
832 JvAssert (decl_class != NULL);
834 jclass return_type;
835 JArray<jclass> *arg_types;
838 _Jv_GetTypesFromSignature (id, decl_class,
839 &arg_types, &return_type);
841 jthrowable ex = _Jv_CallAnyMethodA (obj, return_type, id,
842 style == constructor,
843 arg_types, args, NULL);
845 if (ex != NULL)
846 env->ex = ex;
848 catch (jthrowable t)
850 env->ex = t;
854 // Functions with this signature are used to implement functions in
855 // the CallMethod family.
856 template<typename T>
857 static T
858 _Jv_JNI_CallMethodV (JNIEnv *env, jobject obj, jmethodID id, va_list args)
860 return _Jv_JNI_CallAnyMethodV<T, normal> (env, obj, NULL, id, args);
863 // Functions with this signature are used to implement functions in
864 // the CallMethod family.
865 template<typename T>
866 static T
867 _Jv_JNI_CallMethod (JNIEnv *env, jobject obj, jmethodID id, ...)
869 va_list args;
870 T result;
872 va_start (args, id);
873 result = _Jv_JNI_CallAnyMethodV<T, normal> (env, obj, NULL, id, args);
874 va_end (args);
876 return result;
879 // Functions with this signature are used to implement functions in
880 // the CallMethod family.
881 template<typename T>
882 static T
883 _Jv_JNI_CallMethodA (JNIEnv *env, jobject obj, jmethodID id, jvalue *args)
885 return _Jv_JNI_CallAnyMethodA<T, normal> (env, obj, NULL, id, args);
888 static void
889 _Jv_JNI_CallVoidMethodV (JNIEnv *env, jobject obj, jmethodID id, va_list args)
891 _Jv_JNI_CallAnyVoidMethodV<normal> (env, obj, NULL, id, args);
894 static void
895 _Jv_JNI_CallVoidMethod (JNIEnv *env, jobject obj, jmethodID id, ...)
897 va_list args;
899 va_start (args, id);
900 _Jv_JNI_CallAnyVoidMethodV<normal> (env, obj, NULL, id, args);
901 va_end (args);
904 static void
905 _Jv_JNI_CallVoidMethodA (JNIEnv *env, jobject obj, jmethodID id, jvalue *args)
907 _Jv_JNI_CallAnyVoidMethodA<normal> (env, obj, NULL, id, args);
910 // Functions with this signature are used to implement functions in
911 // the CallStaticMethod family.
912 template<typename T>
913 static T
914 _Jv_JNI_CallStaticMethodV (JNIEnv *env, jclass klass,
915 jmethodID id, va_list args)
917 JvAssert (((id->accflags) & java::lang::reflect::Modifier::STATIC));
918 JvAssert ((&ClassClass)->isInstance (klass));
920 return _Jv_JNI_CallAnyMethodV<T, static_type> (env, NULL, klass, id, args);
923 // Functions with this signature are used to implement functions in
924 // the CallStaticMethod family.
925 template<typename T>
926 static T
927 _Jv_JNI_CallStaticMethod (JNIEnv *env, jclass klass, jmethodID id, ...)
929 va_list args;
930 T result;
932 JvAssert (((id->accflags) & java::lang::reflect::Modifier::STATIC));
933 JvAssert ((&ClassClass)->isInstance (klass));
935 va_start (args, id);
936 result = _Jv_JNI_CallAnyMethodV<T, static_type> (env, NULL, klass,
937 id, args);
938 va_end (args);
940 return result;
943 // Functions with this signature are used to implement functions in
944 // the CallStaticMethod family.
945 template<typename T>
946 static T
947 _Jv_JNI_CallStaticMethodA (JNIEnv *env, jclass klass, jmethodID id,
948 jvalue *args)
950 JvAssert (((id->accflags) & java::lang::reflect::Modifier::STATIC));
951 JvAssert ((&ClassClass)->isInstance (klass));
953 return _Jv_JNI_CallAnyMethodA<T, static_type> (env, NULL, klass, id, args);
956 static void
957 _Jv_JNI_CallStaticVoidMethodV (JNIEnv *env, jclass klass, jmethodID id,
958 va_list args)
960 _Jv_JNI_CallAnyVoidMethodV<static_type> (env, NULL, klass, id, args);
963 static void
964 _Jv_JNI_CallStaticVoidMethod (JNIEnv *env, jclass klass, jmethodID id, ...)
966 va_list args;
968 va_start (args, id);
969 _Jv_JNI_CallAnyVoidMethodV<static_type> (env, NULL, klass, id, args);
970 va_end (args);
973 static void
974 _Jv_JNI_CallStaticVoidMethodA (JNIEnv *env, jclass klass, jmethodID id,
975 jvalue *args)
977 _Jv_JNI_CallAnyVoidMethodA<static_type> (env, NULL, klass, id, args);
980 static jobject
981 _Jv_JNI_NewObjectV (JNIEnv *env, jclass klass,
982 jmethodID id, va_list args)
984 JvAssert (klass && ! klass->isArray ());
985 JvAssert (! strcmp (id->name->data, "<init>")
986 && id->signature->length > 2
987 && id->signature->data[0] == '('
988 && ! strcmp (&id->signature->data[id->signature->length - 2],
989 ")V"));
991 return _Jv_JNI_CallAnyMethodV<jobject, constructor> (env, NULL, klass,
992 id, args);
995 static jobject
996 _Jv_JNI_NewObject (JNIEnv *env, jclass klass, jmethodID id, ...)
998 JvAssert (klass && ! klass->isArray ());
999 JvAssert (! strcmp (id->name->data, "<init>")
1000 && id->signature->length > 2
1001 && id->signature->data[0] == '('
1002 && ! strcmp (&id->signature->data[id->signature->length - 2],
1003 ")V"));
1005 va_list args;
1006 jobject result;
1008 va_start (args, id);
1009 result = _Jv_JNI_CallAnyMethodV<jobject, constructor> (env, NULL, klass,
1010 id, args);
1011 va_end (args);
1013 return result;
1016 static jobject
1017 _Jv_JNI_NewObjectA (JNIEnv *env, jclass klass, jmethodID id,
1018 jvalue *args)
1020 JvAssert (klass && ! klass->isArray ());
1021 JvAssert (! strcmp (id->name->data, "<init>")
1022 && id->signature->length > 2
1023 && id->signature->data[0] == '('
1024 && ! strcmp (&id->signature->data[id->signature->length - 2],
1025 ")V"));
1027 return _Jv_JNI_CallAnyMethodA<jobject, constructor> (env, NULL, klass,
1028 id, args);
1033 template<typename T>
1034 static T
1035 _Jv_JNI_GetField (JNIEnv *env, jobject obj, jfieldID field)
1037 JvAssert (obj);
1038 T *ptr = (T *) ((char *) obj + field->getOffset ());
1039 return wrap_value (env, *ptr);
1042 template<typename T>
1043 static void
1044 _Jv_JNI_SetField (JNIEnv *, jobject obj, jfieldID field, T value)
1046 JvAssert (obj);
1047 T *ptr = (T *) ((char *) obj + field->getOffset ());
1048 *ptr = value;
1051 template<jboolean is_static>
1052 static jfieldID
1053 _Jv_JNI_GetAnyFieldID (JNIEnv *env, jclass clazz,
1054 const char *name, const char *sig)
1058 _Jv_InitClass (clazz);
1060 _Jv_Utf8Const *a_name = _Jv_makeUtf8Const ((char *) name, -1);
1062 // FIXME: assume that SIG isn't too long.
1063 int len = strlen (sig);
1064 char s[len + 1];
1065 for (int i = 0; i <= len; ++i)
1066 s[i] = (sig[i] == '/') ? '.' : sig[i];
1067 jclass field_class = _Jv_FindClassFromSignature ((char *) s, NULL);
1069 // FIXME: what if field_class == NULL?
1071 java::lang::ClassLoader *loader = clazz->getClassLoader ();
1072 while (clazz != NULL)
1074 // We acquire the class lock so that fields aren't resolved
1075 // while we are running.
1076 JvSynchronize sync (clazz);
1078 jint count = (is_static
1079 ? JvNumStaticFields (clazz)
1080 : JvNumInstanceFields (clazz));
1081 jfieldID field = (is_static
1082 ? JvGetFirstStaticField (clazz)
1083 : JvGetFirstInstanceField (clazz));
1084 for (jint i = 0; i < count; ++i)
1086 _Jv_Utf8Const *f_name = field->getNameUtf8Const(clazz);
1088 // The field might be resolved or it might not be. It
1089 // is much simpler to always resolve it.
1090 _Jv_ResolveField (field, loader);
1091 if (_Jv_equalUtf8Consts (f_name, a_name)
1092 && field->getClass() == field_class)
1093 return field;
1095 field = field->getNextField ();
1098 clazz = clazz->getSuperclass ();
1101 env->ex = new java::lang::NoSuchFieldError ();
1103 catch (jthrowable t)
1105 env->ex = t;
1107 return NULL;
1110 template<typename T>
1111 static T
1112 _Jv_JNI_GetStaticField (JNIEnv *env, jclass, jfieldID field)
1114 T *ptr = (T *) field->u.addr;
1115 return wrap_value (env, *ptr);
1118 template<typename T>
1119 static void
1120 _Jv_JNI_SetStaticField (JNIEnv *, jclass, jfieldID field, T value)
1122 T *ptr = (T *) field->u.addr;
1123 *ptr = value;
1126 static jstring
1127 _Jv_JNI_NewString (JNIEnv *env, const jchar *unichars, jsize len)
1131 jstring r = _Jv_NewString (unichars, len);
1132 return (jstring) wrap_value (env, r);
1134 catch (jthrowable t)
1136 env->ex = t;
1137 return NULL;
1141 static jsize
1142 _Jv_JNI_GetStringLength (JNIEnv *, jstring string)
1144 return string->length();
1147 static const jchar *
1148 _Jv_JNI_GetStringChars (JNIEnv *, jstring string, jboolean *isCopy)
1150 jchar *result = _Jv_GetStringChars (string);
1151 mark_for_gc (string);
1152 if (isCopy)
1153 *isCopy = false;
1154 return (const jchar *) result;
1157 static void
1158 _Jv_JNI_ReleaseStringChars (JNIEnv *, jstring string, const jchar *)
1160 unmark_for_gc (string);
1163 static jstring
1164 _Jv_JNI_NewStringUTF (JNIEnv *env, const char *bytes)
1168 jstring result = JvNewStringUTF (bytes);
1169 return (jstring) wrap_value (env, result);
1171 catch (jthrowable t)
1173 env->ex = t;
1174 return NULL;
1178 static jsize
1179 _Jv_JNI_GetStringUTFLength (JNIEnv *, jstring string)
1181 return JvGetStringUTFLength (string);
1184 static const char *
1185 _Jv_JNI_GetStringUTFChars (JNIEnv *env, jstring string, jboolean *isCopy)
1187 jsize len = JvGetStringUTFLength (string);
1190 char *r = (char *) _Jv_Malloc (len + 1);
1191 JvGetStringUTFRegion (string, 0, len, r);
1192 r[len] = '\0';
1194 if (isCopy)
1195 *isCopy = true;
1197 return (const char *) r;
1199 catch (jthrowable t)
1201 env->ex = t;
1202 return NULL;
1206 static void
1207 _Jv_JNI_ReleaseStringUTFChars (JNIEnv *, jstring, const char *utf)
1209 _Jv_Free ((void *) utf);
1212 static void
1213 _Jv_JNI_GetStringRegion (JNIEnv *env, jstring string, jsize start, jsize len,
1214 jchar *buf)
1216 jchar *result = _Jv_GetStringChars (string);
1217 if (start < 0 || start > string->length ()
1218 || len < 0 || start + len > string->length ())
1222 env->ex = new java::lang::StringIndexOutOfBoundsException ();
1224 catch (jthrowable t)
1226 env->ex = t;
1229 else
1230 memcpy (buf, &result[start], len * sizeof (jchar));
1233 static void
1234 _Jv_JNI_GetStringUTFRegion (JNIEnv *env, jstring str, jsize start,
1235 jsize len, char *buf)
1237 if (start < 0 || start > str->length ()
1238 || len < 0 || start + len > str->length ())
1242 env->ex = new java::lang::StringIndexOutOfBoundsException ();
1244 catch (jthrowable t)
1246 env->ex = t;
1249 else
1250 _Jv_GetStringUTFRegion (str, start, len, buf);
1253 static const jchar *
1254 _Jv_JNI_GetStringCritical (JNIEnv *, jstring str, jboolean *isCopy)
1256 jchar *result = _Jv_GetStringChars (str);
1257 if (isCopy)
1258 *isCopy = false;
1259 return result;
1262 static void
1263 _Jv_JNI_ReleaseStringCritical (JNIEnv *, jstring, const jchar *)
1265 // Nothing.
1268 static jsize
1269 _Jv_JNI_GetArrayLength (JNIEnv *, jarray array)
1271 return array->length;
1274 static jarray
1275 _Jv_JNI_NewObjectArray (JNIEnv *env, jsize length, jclass elementClass,
1276 jobject init)
1280 jarray result = JvNewObjectArray (length, elementClass, init);
1281 return (jarray) wrap_value (env, result);
1283 catch (jthrowable t)
1285 env->ex = t;
1286 return NULL;
1290 static jobject
1291 _Jv_JNI_GetObjectArrayElement (JNIEnv *env, jobjectArray array, jsize index)
1293 jobject *elts = elements (array);
1294 return wrap_value (env, elts[index]);
1297 static void
1298 _Jv_JNI_SetObjectArrayElement (JNIEnv *env, jobjectArray array, jsize index,
1299 jobject value)
1303 _Jv_CheckArrayStore (array, value);
1304 jobject *elts = elements (array);
1305 elts[index] = value;
1307 catch (jthrowable t)
1309 env->ex = t;
1313 template<typename T, jclass K>
1314 static JArray<T> *
1315 _Jv_JNI_NewPrimitiveArray (JNIEnv *env, jsize length)
1319 return (JArray<T> *) wrap_value (env, _Jv_NewPrimArray (K, length));
1321 catch (jthrowable t)
1323 env->ex = t;
1324 return NULL;
1328 template<typename T>
1329 static T *
1330 _Jv_JNI_GetPrimitiveArrayElements (JNIEnv *, JArray<T> *array,
1331 jboolean *isCopy)
1333 T *elts = elements (array);
1334 if (isCopy)
1336 // We elect never to copy.
1337 *isCopy = false;
1339 mark_for_gc (array);
1340 return elts;
1343 template<typename T>
1344 static void
1345 _Jv_JNI_ReleasePrimitiveArrayElements (JNIEnv *, JArray<T> *array,
1346 T *, jint /* mode */)
1348 // Note that we ignore MODE. We can do this because we never copy
1349 // the array elements. My reading of the JNI documentation is that
1350 // this is an option for the implementor.
1351 unmark_for_gc (array);
1354 template<typename T>
1355 static void
1356 _Jv_JNI_GetPrimitiveArrayRegion (JNIEnv *env, JArray<T> *array,
1357 jsize start, jsize len,
1358 T *buf)
1360 if (start < 0 || len >= array->length || start + len >= array->length)
1364 // FIXME: index.
1365 env->ex = new java::lang::ArrayIndexOutOfBoundsException ();
1367 catch (jthrowable t)
1369 // Could have thown out of memory error.
1370 env->ex = t;
1373 else
1375 T *elts = elements (array) + start;
1376 memcpy (buf, elts, len * sizeof (T));
1380 template<typename T>
1381 static void
1382 _Jv_JNI_SetPrimitiveArrayRegion (JNIEnv *env, JArray<T> *array,
1383 jsize start, jsize len, T *buf)
1385 if (start < 0 || len >= array->length || start + len >= array->length)
1389 // FIXME: index.
1390 env->ex = new java::lang::ArrayIndexOutOfBoundsException ();
1392 catch (jthrowable t)
1394 env->ex = t;
1397 else
1399 T *elts = elements (array) + start;
1400 memcpy (elts, buf, len * sizeof (T));
1404 static void *
1405 _Jv_JNI_GetPrimitiveArrayCritical (JNIEnv *, jarray array,
1406 jboolean *isCopy)
1408 // FIXME: does this work?
1409 jclass klass = array->getClass()->getComponentType();
1410 JvAssert (klass->isPrimitive ());
1411 char *r = _Jv_GetArrayElementFromElementType (array, klass);
1412 if (isCopy)
1413 *isCopy = false;
1414 return r;
1417 static void
1418 _Jv_JNI_ReleasePrimitiveArrayCritical (JNIEnv *, jarray, void *, jint)
1420 // Nothing.
1423 static jint
1424 _Jv_JNI_MonitorEnter (JNIEnv *env, jobject obj)
1428 return _Jv_MonitorEnter (obj);
1430 catch (jthrowable t)
1432 env->ex = t;
1434 return JNI_ERR;
1437 static jint
1438 _Jv_JNI_MonitorExit (JNIEnv *env, jobject obj)
1442 return _Jv_MonitorExit (obj);
1444 catch (jthrowable t)
1446 env->ex = t;
1448 return JNI_ERR;
1451 // JDK 1.2
1452 jobject
1453 _Jv_JNI_ToReflectedField (JNIEnv *env, jclass cls, jfieldID fieldID,
1454 jboolean)
1458 java::lang::reflect::Field *field = new java::lang::reflect::Field();
1459 field->declaringClass = cls;
1460 field->offset = (char*) fieldID - (char *) cls->fields;
1461 field->name = _Jv_NewStringUtf8Const (fieldID->getNameUtf8Const (cls));
1462 return wrap_value (env, field);
1464 catch (jthrowable t)
1466 env->ex = t;
1468 return NULL;
1471 // JDK 1.2
1472 static jfieldID
1473 _Jv_JNI_FromReflectedField (JNIEnv *, jobject f)
1475 using namespace java::lang::reflect;
1477 Field *field = reinterpret_cast<Field *> (f);
1478 return _Jv_FromReflectedField (field);
1481 jobject
1482 _Jv_JNI_ToReflectedMethod (JNIEnv *env, jclass klass, jmethodID id,
1483 jboolean)
1485 using namespace java::lang::reflect;
1487 // FIXME.
1488 static _Jv_Utf8Const *init_name = _Jv_makeUtf8Const ("<init>", 6);
1490 jobject result = NULL;
1494 if (_Jv_equalUtf8Consts (id->name, init_name))
1496 // A constructor.
1497 Constructor *cons = new Constructor ();
1498 cons->offset = (char *) id - (char *) &klass->methods;
1499 cons->declaringClass = klass;
1500 result = cons;
1502 else
1504 Method *meth = new Method ();
1505 meth->offset = (char *) id - (char *) &klass->methods;
1506 meth->declaringClass = klass;
1507 result = meth;
1510 catch (jthrowable t)
1512 env->ex = t;
1515 return wrap_value (env, result);
1518 static jmethodID
1519 _Jv_JNI_FromReflectedMethod (JNIEnv *, jobject method)
1521 using namespace java::lang::reflect;
1522 if ((&MethodClass)->isInstance (method))
1523 return _Jv_FromReflectedMethod (reinterpret_cast<Method *> (method));
1524 return
1525 _Jv_FromReflectedConstructor (reinterpret_cast<Constructor *> (method));
1528 static jint
1529 _Jv_JNI_RegisterNatives (JNIEnv *env, jclass k,
1530 const JNINativeMethod *methods,
1531 jint nMethods)
1533 #ifdef INTERPRETER
1534 // For now, this only matters for interpreted methods. FIXME.
1535 if (! _Jv_IsInterpretedClass (k))
1537 // FIXME: throw exception.
1538 return JNI_ERR;
1540 _Jv_InterpClass *klass = reinterpret_cast<_Jv_InterpClass *> (k);
1542 // Look at each descriptor given us, and find the corresponding
1543 // method in the class.
1544 for (int j = 0; j < nMethods; ++j)
1546 bool found = false;
1548 _Jv_MethodBase **imeths = _Jv_GetFirstMethod (klass);
1549 for (int i = 0; i < JvNumMethods (klass); ++i)
1551 _Jv_MethodBase *meth = imeths[i];
1552 _Jv_Method *self = meth->get_method ();
1554 if (! strcmp (self->name->data, methods[j].name)
1555 && ! strcmp (self->signature->data, methods[j].signature))
1557 if (! (self->accflags
1558 & java::lang::reflect::Modifier::NATIVE))
1559 break;
1561 // Found a match that is native.
1562 _Jv_JNIMethod *jmeth = reinterpret_cast<_Jv_JNIMethod *> (meth);
1563 jmeth->set_function (methods[i].fnPtr);
1564 found = true;
1565 break;
1569 if (! found)
1571 jstring m = JvNewStringUTF (methods[j].name);
1574 env->ex =new java::lang::NoSuchMethodError (m);
1576 catch (jthrowable t)
1578 env->ex = t;
1580 return JNI_ERR;
1584 return JNI_OK;
1585 #else /* INTERPRETER */
1586 return JNI_ERR;
1587 #endif /* INTERPRETER */
1590 static jint
1591 _Jv_JNI_UnregisterNatives (JNIEnv *, jclass)
1593 return JNI_ERR;
1598 #ifdef INTERPRETER
1600 // Add a character to the buffer, encoding properly.
1601 static void
1602 add_char (char *buf, jchar c, int *here)
1604 if (c == '_')
1606 buf[(*here)++] = '_';
1607 buf[(*here)++] = '1';
1609 else if (c == ';')
1611 buf[(*here)++] = '_';
1612 buf[(*here)++] = '2';
1614 else if (c == '[')
1616 buf[(*here)++] = '_';
1617 buf[(*here)++] = '3';
1620 // Also check for `.' here because we might be passed an internal
1621 // qualified class name like `foo.bar'.
1622 else if (c == '/' || c == '.')
1623 buf[(*here)++] = '_';
1624 else if ((c >= '0' && c <= '9')
1625 || (c >= 'a' && c <= 'z')
1626 || (c >= 'A' && c <= 'Z'))
1627 buf[(*here)++] = (char) c;
1628 else
1630 // "Unicode" character.
1631 buf[(*here)++] = '_';
1632 buf[(*here)++] = '0';
1633 for (int i = 0; i < 4; ++i)
1635 int val = c & 0x0f;
1636 buf[(*here) + 4 - i] = (val > 10) ? ('a' + val - 10) : ('0' + val);
1637 c >>= 4;
1639 *here += 4;
1643 // Compute a mangled name for a native function. This computes the
1644 // long name, and also returns an index which indicates where a NUL
1645 // can be placed to create the short name. This function assumes that
1646 // the buffer is large enough for its results.
1647 static void
1648 mangled_name (jclass klass, _Jv_Utf8Const *func_name,
1649 _Jv_Utf8Const *signature, char *buf, int *long_start)
1651 strcpy (buf, "Java_");
1652 int here = 5;
1654 // Add fully qualified class name.
1655 jchar *chars = _Jv_GetStringChars (klass->getName ());
1656 jint len = klass->getName ()->length ();
1657 for (int i = 0; i < len; ++i)
1658 add_char (buf, chars[i], &here);
1660 // Don't use add_char because we need a literal `_'.
1661 buf[here++] = '_';
1663 const unsigned char *fn = (const unsigned char *) func_name->data;
1664 const unsigned char *limit = fn + func_name->length;
1665 for (int i = 0; ; ++i)
1667 int ch = UTF8_GET (fn, limit);
1668 if (ch < 0)
1669 break;
1670 add_char (buf, ch, &here);
1673 // This is where the long signature begins.
1674 *long_start = here;
1675 buf[here++] = '_';
1676 buf[here++] = '_';
1678 const unsigned char *sig = (const unsigned char *) signature->data;
1679 limit = sig + signature->length;
1680 JvAssert (sig[0] == '(');
1681 ++sig;
1682 while (1)
1684 int ch = UTF8_GET (sig, limit);
1685 if (ch == ')' || ch < 0)
1686 break;
1687 add_char (buf, ch, &here);
1690 buf[here] = '\0';
1693 // Return the current thread's JNIEnv; if one does not exist, create
1694 // it. Also create a new system frame for use. This is `extern "C"'
1695 // because the compiler calls it.
1696 extern "C" JNIEnv *
1697 _Jv_GetJNIEnvNewFrame (jclass klass)
1699 JNIEnv *env = _Jv_GetCurrentJNIEnv ();
1700 if (env == NULL)
1702 env = (JNIEnv *) _Jv_MallocUnchecked (sizeof (JNIEnv));
1703 env->p = &_Jv_JNIFunctions;
1704 env->ex = NULL;
1705 env->klass = klass;
1706 env->locals = NULL;
1708 _Jv_SetCurrentJNIEnv (env);
1711 _Jv_JNI_LocalFrame *frame
1712 = (_Jv_JNI_LocalFrame *) _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame)
1713 + (FRAME_SIZE
1714 * sizeof (jobject)));
1716 frame->marker = MARK_SYSTEM;
1717 frame->size = FRAME_SIZE;
1718 frame->next = env->locals;
1719 env->locals = frame;
1721 for (int i = 0; i < frame->size; ++i)
1722 frame->vec[i] = NULL;
1724 return env;
1727 // Return the function which implements a particular JNI method. If
1728 // we can't find the function, we throw the appropriate exception.
1729 // This is `extern "C"' because the compiler uses it.
1730 extern "C" void *
1731 _Jv_LookupJNIMethod (jclass klass, _Jv_Utf8Const *name,
1732 _Jv_Utf8Const *signature)
1734 char buf[10 + 6 * (name->length + signature->length)];
1735 int long_start;
1736 void *function;
1738 mangled_name (klass, name, signature, buf, &long_start);
1739 char c = buf[long_start];
1740 buf[long_start] = '\0';
1741 function = _Jv_FindSymbolInExecutable (buf);
1742 if (function == NULL)
1744 buf[long_start] = c;
1745 function = _Jv_FindSymbolInExecutable (buf);
1746 if (function == NULL)
1748 jstring str = JvNewStringUTF (name->data);
1749 throw new java::lang::AbstractMethodError (str);
1753 return function;
1756 // This function is the stub which is used to turn an ordinary (CNI)
1757 // method call into a JNI call.
1758 void
1759 _Jv_JNIMethod::call (ffi_cif *, void *ret, ffi_raw *args, void *__this)
1761 _Jv_JNIMethod* _this = (_Jv_JNIMethod *) __this;
1763 JNIEnv *env = _Jv_GetJNIEnvNewFrame (_this->defining_class);
1765 // FIXME: we should mark every reference parameter as a local. For
1766 // now we assume a conservative GC, and we assume that the
1767 // references are on the stack somewhere.
1769 // We cache the value that we find, of course, but if we don't find
1770 // a value we don't cache that fact -- we might subsequently load a
1771 // library which finds the function in question.
1772 if (_this->function == NULL)
1773 _this->function = _Jv_LookupJNIMethod (_this->defining_class,
1774 _this->self->name,
1775 _this->self->signature);
1777 JvAssert (_this->args_raw_size % sizeof (ffi_raw) == 0);
1778 ffi_raw real_args[2 + _this->args_raw_size / sizeof (ffi_raw)];
1779 int offset = 0;
1781 // First argument is always the environment pointer.
1782 real_args[offset++].ptr = env;
1784 // For a static method, we pass in the Class. For non-static
1785 // methods, the `this' argument is already handled.
1786 if ((_this->self->accflags & java::lang::reflect::Modifier::STATIC))
1787 real_args[offset++].ptr = _this->defining_class;
1789 // Copy over passed-in arguments.
1790 memcpy (&real_args[offset], args, _this->args_raw_size);
1792 // The actual call to the JNI function.
1793 ffi_raw_call (&_this->jni_cif, (void (*)()) _this->function,
1794 ret, real_args);
1796 _Jv_JNI_PopSystemFrame (env);
1799 #endif /* INTERPRETER */
1804 // Invocation API.
1807 // An internal helper function.
1808 static jint
1809 _Jv_JNI_AttachCurrentThread (JavaVM *, jstring name, void **penv, void *args)
1811 JavaVMAttachArgs *attach = reinterpret_cast<JavaVMAttachArgs *> (args);
1812 java::lang::ThreadGroup *group = NULL;
1814 if (attach)
1816 // FIXME: do we really want to support 1.1?
1817 if (attach->version != JNI_VERSION_1_2
1818 && attach->version != JNI_VERSION_1_1)
1819 return JNI_EVERSION;
1821 JvAssert ((&ThreadGroupClass)->isInstance (attach->group));
1822 group = reinterpret_cast<java::lang::ThreadGroup *> (attach->group);
1825 // Attaching an already-attached thread is a no-op.
1826 if (_Jv_GetCurrentJNIEnv () != NULL)
1827 return 0;
1829 JNIEnv *env = (JNIEnv *) _Jv_MallocUnchecked (sizeof (JNIEnv));
1830 if (env == NULL)
1831 return JNI_ERR;
1832 env->p = &_Jv_JNIFunctions;
1833 env->ex = NULL;
1834 env->klass = NULL;
1835 env->locals
1836 = (_Jv_JNI_LocalFrame *) _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame)
1837 + (FRAME_SIZE
1838 * sizeof (jobject)));
1839 if (env->locals == NULL)
1841 _Jv_Free (env);
1842 return JNI_ERR;
1844 *penv = reinterpret_cast<void *> (env);
1846 // This thread might already be a Java thread -- this function might
1847 // have been called simply to set the new JNIEnv.
1848 if (_Jv_ThreadCurrent () == NULL)
1852 (void) new gnu::gcj::jni::NativeThread (group, name);
1854 catch (jthrowable t)
1856 return JNI_ERR;
1859 _Jv_SetCurrentJNIEnv (env);
1861 return 0;
1864 // This is the one actually used by JNI.
1865 static jint
1866 _Jv_JNI_AttachCurrentThread (JavaVM *vm, void **penv, void *args)
1868 return _Jv_JNI_AttachCurrentThread (vm, NULL, penv, args);
1871 static jint
1872 _Jv_JNI_DestroyJavaVM (JavaVM *vm)
1874 JvAssert (the_vm && vm == the_vm);
1876 JNIEnv *env;
1877 if (_Jv_ThreadCurrent () != NULL)
1879 jstring main_name;
1880 // This sucks.
1883 main_name = JvNewStringLatin1 ("main");
1885 catch (jthrowable t)
1887 return JNI_ERR;
1890 jint r = _Jv_JNI_AttachCurrentThread (vm,
1891 main_name,
1892 reinterpret_cast<void **> (&env),
1893 NULL);
1894 if (r < 0)
1895 return r;
1897 else
1898 env = _Jv_GetCurrentJNIEnv ();
1900 _Jv_ThreadWait ();
1902 // Docs say that this always returns an error code.
1903 return JNI_ERR;
1906 static jint
1907 _Jv_JNI_DetachCurrentThread (JavaVM *)
1909 java::lang::Thread *t = _Jv_ThreadCurrent ();
1910 if (t == NULL)
1911 return JNI_EDETACHED;
1913 // FIXME: we only allow threads attached via AttachCurrentThread to
1914 // be detached. I have no idea how we could implement detaching
1915 // other threads, given the requirement that we must release all the
1916 // monitors. That just seems evil.
1917 JvAssert ((&NativeThreadClass)->isInstance (t));
1919 // FIXME: release the monitors. We'll take this to mean all
1920 // monitors acquired via the JNI interface. This means we have to
1921 // keep track of them.
1923 gnu::gcj::jni::NativeThread *nt
1924 = reinterpret_cast<gnu::gcj::jni::NativeThread *> (t);
1925 nt->finish ();
1927 return 0;
1930 static jint
1931 _Jv_JNI_GetEnv (JavaVM *, void **penv, jint version)
1933 if (_Jv_ThreadCurrent () == NULL)
1935 *penv = NULL;
1936 return JNI_EDETACHED;
1939 #ifdef ENABLE_JVMPI
1940 // Handle JVMPI requests.
1941 if (version == JVMPI_VERSION_1)
1943 *penv = (void *) &_Jv_JVMPI_Interface;
1944 return 0;
1946 #endif
1948 // FIXME: do we really want to support 1.1?
1949 if (version != JNI_VERSION_1_2 && version != JNI_VERSION_1_1)
1951 *penv = NULL;
1952 return JNI_EVERSION;
1955 *penv = (void *) _Jv_GetCurrentJNIEnv ();
1956 return 0;
1959 jint
1960 JNI_GetDefaultJavaVMInitArgs (void *args)
1962 jint version = * (jint *) args;
1963 // Here we only support 1.2.
1964 if (version != JNI_VERSION_1_2)
1965 return JNI_EVERSION;
1967 JavaVMInitArgs *ia = reinterpret_cast<JavaVMInitArgs *> (args);
1968 ia->version = JNI_VERSION_1_2;
1969 ia->nOptions = 0;
1970 ia->options = NULL;
1971 ia->ignoreUnrecognized = true;
1973 return 0;
1976 jint
1977 JNI_CreateJavaVM (JavaVM **vm, void **penv, void *args)
1979 JvAssert (! the_vm);
1980 // FIXME: synchronize
1981 JavaVM *nvm = (JavaVM *) _Jv_MallocUnchecked (sizeof (JavaVM));
1982 if (nvm == NULL)
1983 return JNI_ERR;
1984 nvm->functions = &_Jv_JNI_InvokeFunctions;
1986 // Parse the arguments.
1987 if (args != NULL)
1989 jint version = * (jint *) args;
1990 // We only support 1.2.
1991 if (version != JNI_VERSION_1_2)
1992 return JNI_EVERSION;
1993 JavaVMInitArgs *ia = reinterpret_cast<JavaVMInitArgs *> (args);
1994 for (int i = 0; i < ia->nOptions; ++i)
1996 if (! strcmp (ia->options[i].optionString, "vfprintf")
1997 || ! strcmp (ia->options[i].optionString, "exit")
1998 || ! strcmp (ia->options[i].optionString, "abort"))
2000 // We are required to recognize these, but for now we
2001 // don't handle them in any way. FIXME.
2002 continue;
2004 else if (! strncmp (ia->options[i].optionString,
2005 "-verbose", sizeof ("-verbose") - 1))
2007 // We don't do anything with this option either. We
2008 // might want to make sure the argument is valid, but we
2009 // don't really care all that much for now.
2010 continue;
2012 else if (! strncmp (ia->options[i].optionString, "-D", 2))
2014 // FIXME.
2015 continue;
2017 else if (ia->ignoreUnrecognized)
2019 if (ia->options[i].optionString[0] == '_'
2020 || ! strncmp (ia->options[i].optionString, "-X", 2))
2021 continue;
2024 return JNI_ERR;
2028 jint r =_Jv_JNI_AttachCurrentThread (nvm, penv, NULL);
2029 if (r < 0)
2030 return r;
2032 the_vm = nvm;
2033 *vm = the_vm;
2034 return 0;
2037 jint
2038 JNI_GetCreatedJavaVMs (JavaVM **vm_buffer, jsize buf_len, jsize *n_vms)
2040 if (buf_len <= 0)
2041 return JNI_ERR;
2043 // We only support a single VM.
2044 if (the_vm != NULL)
2046 vm_buffer[0] = the_vm;
2047 *n_vms = 1;
2049 else
2050 *n_vms = 0;
2051 return 0;
2054 JavaVM *
2055 _Jv_GetJavaVM ()
2057 // FIXME: synchronize
2058 if (! the_vm)
2060 JavaVM *nvm = (JavaVM *) _Jv_MallocUnchecked (sizeof (JavaVM));
2061 if (nvm != NULL)
2062 nvm->functions = &_Jv_JNI_InvokeFunctions;
2063 the_vm = nvm;
2066 // If this is a Java thread, we want to make sure it has an
2067 // associated JNIEnv.
2068 if (_Jv_ThreadCurrent () != NULL)
2070 void *ignore;
2071 _Jv_JNI_AttachCurrentThread (the_vm, &ignore, NULL);
2074 return the_vm;
2077 static jint
2078 _Jv_JNI_GetJavaVM (JNIEnv *, JavaVM **vm)
2080 *vm = _Jv_GetJavaVM ();
2081 return *vm == NULL ? JNI_ERR : JNI_OK;
2086 #define NOT_IMPL NULL
2087 #define RESERVED NULL
2089 struct JNINativeInterface _Jv_JNIFunctions =
2091 RESERVED,
2092 RESERVED,
2093 RESERVED,
2094 RESERVED,
2095 _Jv_JNI_GetVersion, // GetVersion
2096 _Jv_JNI_DefineClass, // DefineClass
2097 _Jv_JNI_FindClass, // FindClass
2098 _Jv_JNI_FromReflectedMethod, // FromReflectedMethod
2099 _Jv_JNI_FromReflectedField, // FromReflectedField
2100 _Jv_JNI_ToReflectedMethod, // ToReflectedMethod
2101 _Jv_JNI_GetSuperclass, // GetSuperclass
2102 _Jv_JNI_IsAssignableFrom, // IsAssignableFrom
2103 _Jv_JNI_ToReflectedField, // ToReflectedField
2104 _Jv_JNI_Throw, // Throw
2105 _Jv_JNI_ThrowNew, // ThrowNew
2106 _Jv_JNI_ExceptionOccurred, // ExceptionOccurred
2107 _Jv_JNI_ExceptionDescribe, // ExceptionDescribe
2108 _Jv_JNI_ExceptionClear, // ExceptionClear
2109 _Jv_JNI_FatalError, // FatalError
2111 _Jv_JNI_PushLocalFrame, // PushLocalFrame
2112 _Jv_JNI_PopLocalFrame, // PopLocalFrame
2113 _Jv_JNI_NewGlobalRef, // NewGlobalRef
2114 _Jv_JNI_DeleteGlobalRef, // DeleteGlobalRef
2115 _Jv_JNI_DeleteLocalRef, // DeleteLocalRef
2117 _Jv_JNI_IsSameObject, // IsSameObject
2119 _Jv_JNI_NewLocalRef, // NewLocalRef
2120 _Jv_JNI_EnsureLocalCapacity, // EnsureLocalCapacity
2122 _Jv_JNI_AllocObject, // AllocObject
2123 _Jv_JNI_NewObject, // NewObject
2124 _Jv_JNI_NewObjectV, // NewObjectV
2125 _Jv_JNI_NewObjectA, // NewObjectA
2126 _Jv_JNI_GetObjectClass, // GetObjectClass
2127 _Jv_JNI_IsInstanceOf, // IsInstanceOf
2128 _Jv_JNI_GetAnyMethodID<false>, // GetMethodID
2130 _Jv_JNI_CallMethod<jobject>, // CallObjectMethod
2131 _Jv_JNI_CallMethodV<jobject>, // CallObjectMethodV
2132 _Jv_JNI_CallMethodA<jobject>, // CallObjectMethodA
2133 _Jv_JNI_CallMethod<jboolean>, // CallBooleanMethod
2134 _Jv_JNI_CallMethodV<jboolean>, // CallBooleanMethodV
2135 _Jv_JNI_CallMethodA<jboolean>, // CallBooleanMethodA
2136 _Jv_JNI_CallMethod<jbyte>, // CallByteMethod
2137 _Jv_JNI_CallMethodV<jbyte>, // CallByteMethodV
2138 _Jv_JNI_CallMethodA<jbyte>, // CallByteMethodA
2139 _Jv_JNI_CallMethod<jchar>, // CallCharMethod
2140 _Jv_JNI_CallMethodV<jchar>, // CallCharMethodV
2141 _Jv_JNI_CallMethodA<jchar>, // CallCharMethodA
2142 _Jv_JNI_CallMethod<jshort>, // CallShortMethod
2143 _Jv_JNI_CallMethodV<jshort>, // CallShortMethodV
2144 _Jv_JNI_CallMethodA<jshort>, // CallShortMethodA
2145 _Jv_JNI_CallMethod<jint>, // CallIntMethod
2146 _Jv_JNI_CallMethodV<jint>, // CallIntMethodV
2147 _Jv_JNI_CallMethodA<jint>, // CallIntMethodA
2148 _Jv_JNI_CallMethod<jlong>, // CallLongMethod
2149 _Jv_JNI_CallMethodV<jlong>, // CallLongMethodV
2150 _Jv_JNI_CallMethodA<jlong>, // CallLongMethodA
2151 _Jv_JNI_CallMethod<jfloat>, // CallFloatMethod
2152 _Jv_JNI_CallMethodV<jfloat>, // CallFloatMethodV
2153 _Jv_JNI_CallMethodA<jfloat>, // CallFloatMethodA
2154 _Jv_JNI_CallMethod<jdouble>, // CallDoubleMethod
2155 _Jv_JNI_CallMethodV<jdouble>, // CallDoubleMethodV
2156 _Jv_JNI_CallMethodA<jdouble>, // CallDoubleMethodA
2157 _Jv_JNI_CallVoidMethod, // CallVoidMethod
2158 _Jv_JNI_CallVoidMethodV, // CallVoidMethodV
2159 _Jv_JNI_CallVoidMethodA, // CallVoidMethodA
2161 // Nonvirtual method invocation functions follow.
2162 _Jv_JNI_CallAnyMethod<jobject, nonvirtual>, // CallNonvirtualObjectMethod
2163 _Jv_JNI_CallAnyMethodV<jobject, nonvirtual>, // CallNonvirtualObjectMethodV
2164 _Jv_JNI_CallAnyMethodA<jobject, nonvirtual>, // CallNonvirtualObjectMethodA
2165 _Jv_JNI_CallAnyMethod<jboolean, nonvirtual>, // CallNonvirtualBooleanMethod
2166 _Jv_JNI_CallAnyMethodV<jboolean, nonvirtual>, // CallNonvirtualBooleanMethodV
2167 _Jv_JNI_CallAnyMethodA<jboolean, nonvirtual>, // CallNonvirtualBooleanMethodA
2168 _Jv_JNI_CallAnyMethod<jbyte, nonvirtual>, // CallNonvirtualByteMethod
2169 _Jv_JNI_CallAnyMethodV<jbyte, nonvirtual>, // CallNonvirtualByteMethodV
2170 _Jv_JNI_CallAnyMethodA<jbyte, nonvirtual>, // CallNonvirtualByteMethodA
2171 _Jv_JNI_CallAnyMethod<jchar, nonvirtual>, // CallNonvirtualCharMethod
2172 _Jv_JNI_CallAnyMethodV<jchar, nonvirtual>, // CallNonvirtualCharMethodV
2173 _Jv_JNI_CallAnyMethodA<jchar, nonvirtual>, // CallNonvirtualCharMethodA
2174 _Jv_JNI_CallAnyMethod<jshort, nonvirtual>, // CallNonvirtualShortMethod
2175 _Jv_JNI_CallAnyMethodV<jshort, nonvirtual>, // CallNonvirtualShortMethodV
2176 _Jv_JNI_CallAnyMethodA<jshort, nonvirtual>, // CallNonvirtualShortMethodA
2177 _Jv_JNI_CallAnyMethod<jint, nonvirtual>, // CallNonvirtualIntMethod
2178 _Jv_JNI_CallAnyMethodV<jint, nonvirtual>, // CallNonvirtualIntMethodV
2179 _Jv_JNI_CallAnyMethodA<jint, nonvirtual>, // CallNonvirtualIntMethodA
2180 _Jv_JNI_CallAnyMethod<jlong, nonvirtual>, // CallNonvirtualLongMethod
2181 _Jv_JNI_CallAnyMethodV<jlong, nonvirtual>, // CallNonvirtualLongMethodV
2182 _Jv_JNI_CallAnyMethodA<jlong, nonvirtual>, // CallNonvirtualLongMethodA
2183 _Jv_JNI_CallAnyMethod<jfloat, nonvirtual>, // CallNonvirtualFloatMethod
2184 _Jv_JNI_CallAnyMethodV<jfloat, nonvirtual>, // CallNonvirtualFloatMethodV
2185 _Jv_JNI_CallAnyMethodA<jfloat, nonvirtual>, // CallNonvirtualFloatMethodA
2186 _Jv_JNI_CallAnyMethod<jdouble, nonvirtual>, // CallNonvirtualDoubleMethod
2187 _Jv_JNI_CallAnyMethodV<jdouble, nonvirtual>, // CallNonvirtualDoubleMethodV
2188 _Jv_JNI_CallAnyMethodA<jdouble, nonvirtual>, // CallNonvirtualDoubleMethodA
2189 _Jv_JNI_CallAnyVoidMethod<nonvirtual>, // CallNonvirtualVoidMethod
2190 _Jv_JNI_CallAnyVoidMethodV<nonvirtual>, // CallNonvirtualVoidMethodV
2191 _Jv_JNI_CallAnyVoidMethodA<nonvirtual>, // CallNonvirtualVoidMethodA
2193 _Jv_JNI_GetAnyFieldID<false>, // GetFieldID
2194 _Jv_JNI_GetField<jobject>, // GetObjectField
2195 _Jv_JNI_GetField<jboolean>, // GetBooleanField
2196 _Jv_JNI_GetField<jbyte>, // GetByteField
2197 _Jv_JNI_GetField<jchar>, // GetCharField
2198 _Jv_JNI_GetField<jshort>, // GetShortField
2199 _Jv_JNI_GetField<jint>, // GetIntField
2200 _Jv_JNI_GetField<jlong>, // GetLongField
2201 _Jv_JNI_GetField<jfloat>, // GetFloatField
2202 _Jv_JNI_GetField<jdouble>, // GetDoubleField
2203 _Jv_JNI_SetField, // SetObjectField
2204 _Jv_JNI_SetField, // SetBooleanField
2205 _Jv_JNI_SetField, // SetByteField
2206 _Jv_JNI_SetField, // SetCharField
2207 _Jv_JNI_SetField, // SetShortField
2208 _Jv_JNI_SetField, // SetIntField
2209 _Jv_JNI_SetField, // SetLongField
2210 _Jv_JNI_SetField, // SetFloatField
2211 _Jv_JNI_SetField, // SetDoubleField
2212 _Jv_JNI_GetAnyMethodID<true>, // GetStaticMethodID
2214 _Jv_JNI_CallStaticMethod<jobject>, // CallStaticObjectMethod
2215 _Jv_JNI_CallStaticMethodV<jobject>, // CallStaticObjectMethodV
2216 _Jv_JNI_CallStaticMethodA<jobject>, // CallStaticObjectMethodA
2217 _Jv_JNI_CallStaticMethod<jboolean>, // CallStaticBooleanMethod
2218 _Jv_JNI_CallStaticMethodV<jboolean>, // CallStaticBooleanMethodV
2219 _Jv_JNI_CallStaticMethodA<jboolean>, // CallStaticBooleanMethodA
2220 _Jv_JNI_CallStaticMethod<jbyte>, // CallStaticByteMethod
2221 _Jv_JNI_CallStaticMethodV<jbyte>, // CallStaticByteMethodV
2222 _Jv_JNI_CallStaticMethodA<jbyte>, // CallStaticByteMethodA
2223 _Jv_JNI_CallStaticMethod<jchar>, // CallStaticCharMethod
2224 _Jv_JNI_CallStaticMethodV<jchar>, // CallStaticCharMethodV
2225 _Jv_JNI_CallStaticMethodA<jchar>, // CallStaticCharMethodA
2226 _Jv_JNI_CallStaticMethod<jshort>, // CallStaticShortMethod
2227 _Jv_JNI_CallStaticMethodV<jshort>, // CallStaticShortMethodV
2228 _Jv_JNI_CallStaticMethodA<jshort>, // CallStaticShortMethodA
2229 _Jv_JNI_CallStaticMethod<jint>, // CallStaticIntMethod
2230 _Jv_JNI_CallStaticMethodV<jint>, // CallStaticIntMethodV
2231 _Jv_JNI_CallStaticMethodA<jint>, // CallStaticIntMethodA
2232 _Jv_JNI_CallStaticMethod<jlong>, // CallStaticLongMethod
2233 _Jv_JNI_CallStaticMethodV<jlong>, // CallStaticLongMethodV
2234 _Jv_JNI_CallStaticMethodA<jlong>, // CallStaticLongMethodA
2235 _Jv_JNI_CallStaticMethod<jfloat>, // CallStaticFloatMethod
2236 _Jv_JNI_CallStaticMethodV<jfloat>, // CallStaticFloatMethodV
2237 _Jv_JNI_CallStaticMethodA<jfloat>, // CallStaticFloatMethodA
2238 _Jv_JNI_CallStaticMethod<jdouble>, // CallStaticDoubleMethod
2239 _Jv_JNI_CallStaticMethodV<jdouble>, // CallStaticDoubleMethodV
2240 _Jv_JNI_CallStaticMethodA<jdouble>, // CallStaticDoubleMethodA
2241 _Jv_JNI_CallStaticVoidMethod, // CallStaticVoidMethod
2242 _Jv_JNI_CallStaticVoidMethodV, // CallStaticVoidMethodV
2243 _Jv_JNI_CallStaticVoidMethodA, // CallStaticVoidMethodA
2245 _Jv_JNI_GetAnyFieldID<true>, // GetStaticFieldID
2246 _Jv_JNI_GetStaticField<jobject>, // GetStaticObjectField
2247 _Jv_JNI_GetStaticField<jboolean>, // GetStaticBooleanField
2248 _Jv_JNI_GetStaticField<jbyte>, // GetStaticByteField
2249 _Jv_JNI_GetStaticField<jchar>, // GetStaticCharField
2250 _Jv_JNI_GetStaticField<jshort>, // GetStaticShortField
2251 _Jv_JNI_GetStaticField<jint>, // GetStaticIntField
2252 _Jv_JNI_GetStaticField<jlong>, // GetStaticLongField
2253 _Jv_JNI_GetStaticField<jfloat>, // GetStaticFloatField
2254 _Jv_JNI_GetStaticField<jdouble>, // GetStaticDoubleField
2255 _Jv_JNI_SetStaticField, // SetStaticObjectField
2256 _Jv_JNI_SetStaticField, // SetStaticBooleanField
2257 _Jv_JNI_SetStaticField, // SetStaticByteField
2258 _Jv_JNI_SetStaticField, // SetStaticCharField
2259 _Jv_JNI_SetStaticField, // SetStaticShortField
2260 _Jv_JNI_SetStaticField, // SetStaticIntField
2261 _Jv_JNI_SetStaticField, // SetStaticLongField
2262 _Jv_JNI_SetStaticField, // SetStaticFloatField
2263 _Jv_JNI_SetStaticField, // SetStaticDoubleField
2264 _Jv_JNI_NewString, // NewString
2265 _Jv_JNI_GetStringLength, // GetStringLength
2266 _Jv_JNI_GetStringChars, // GetStringChars
2267 _Jv_JNI_ReleaseStringChars, // ReleaseStringChars
2268 _Jv_JNI_NewStringUTF, // NewStringUTF
2269 _Jv_JNI_GetStringUTFLength, // GetStringUTFLength
2270 _Jv_JNI_GetStringUTFChars, // GetStringUTFLength
2271 _Jv_JNI_ReleaseStringUTFChars, // ReleaseStringUTFChars
2272 _Jv_JNI_GetArrayLength, // GetArrayLength
2273 _Jv_JNI_NewObjectArray, // NewObjectArray
2274 _Jv_JNI_GetObjectArrayElement, // GetObjectArrayElement
2275 _Jv_JNI_SetObjectArrayElement, // SetObjectArrayElement
2276 _Jv_JNI_NewPrimitiveArray<jboolean, JvPrimClass (boolean)>,
2277 // NewBooleanArray
2278 _Jv_JNI_NewPrimitiveArray<jbyte, JvPrimClass (byte)>, // NewByteArray
2279 _Jv_JNI_NewPrimitiveArray<jchar, JvPrimClass (char)>, // NewCharArray
2280 _Jv_JNI_NewPrimitiveArray<jshort, JvPrimClass (short)>, // NewShortArray
2281 _Jv_JNI_NewPrimitiveArray<jint, JvPrimClass (int)>, // NewIntArray
2282 _Jv_JNI_NewPrimitiveArray<jlong, JvPrimClass (long)>, // NewLongArray
2283 _Jv_JNI_NewPrimitiveArray<jfloat, JvPrimClass (float)>, // NewFloatArray
2284 _Jv_JNI_NewPrimitiveArray<jdouble, JvPrimClass (double)>, // NewDoubleArray
2285 _Jv_JNI_GetPrimitiveArrayElements, // GetBooleanArrayElements
2286 _Jv_JNI_GetPrimitiveArrayElements, // GetByteArrayElements
2287 _Jv_JNI_GetPrimitiveArrayElements, // GetCharArrayElements
2288 _Jv_JNI_GetPrimitiveArrayElements, // GetShortArrayElements
2289 _Jv_JNI_GetPrimitiveArrayElements, // GetIntArrayElements
2290 _Jv_JNI_GetPrimitiveArrayElements, // GetLongArrayElements
2291 _Jv_JNI_GetPrimitiveArrayElements, // GetFloatArrayElements
2292 _Jv_JNI_GetPrimitiveArrayElements, // GetDoubleArrayElements
2293 _Jv_JNI_ReleasePrimitiveArrayElements, // ReleaseBooleanArrayElements
2294 _Jv_JNI_ReleasePrimitiveArrayElements, // ReleaseByteArrayElements
2295 _Jv_JNI_ReleasePrimitiveArrayElements, // ReleaseCharArrayElements
2296 _Jv_JNI_ReleasePrimitiveArrayElements, // ReleaseShortArrayElements
2297 _Jv_JNI_ReleasePrimitiveArrayElements, // ReleaseIntArrayElements
2298 _Jv_JNI_ReleasePrimitiveArrayElements, // ReleaseLongArrayElements
2299 _Jv_JNI_ReleasePrimitiveArrayElements, // ReleaseFloatArrayElements
2300 _Jv_JNI_ReleasePrimitiveArrayElements, // ReleaseDoubleArrayElements
2301 _Jv_JNI_GetPrimitiveArrayRegion, // GetBooleanArrayRegion
2302 _Jv_JNI_GetPrimitiveArrayRegion, // GetByteArrayRegion
2303 _Jv_JNI_GetPrimitiveArrayRegion, // GetCharArrayRegion
2304 _Jv_JNI_GetPrimitiveArrayRegion, // GetShortArrayRegion
2305 _Jv_JNI_GetPrimitiveArrayRegion, // GetIntArrayRegion
2306 _Jv_JNI_GetPrimitiveArrayRegion, // GetLongArrayRegion
2307 _Jv_JNI_GetPrimitiveArrayRegion, // GetFloatArrayRegion
2308 _Jv_JNI_GetPrimitiveArrayRegion, // GetDoubleArrayRegion
2309 _Jv_JNI_SetPrimitiveArrayRegion, // SetBooleanArrayRegion
2310 _Jv_JNI_SetPrimitiveArrayRegion, // SetByteArrayRegion
2311 _Jv_JNI_SetPrimitiveArrayRegion, // SetCharArrayRegion
2312 _Jv_JNI_SetPrimitiveArrayRegion, // SetShortArrayRegion
2313 _Jv_JNI_SetPrimitiveArrayRegion, // SetIntArrayRegion
2314 _Jv_JNI_SetPrimitiveArrayRegion, // SetLongArrayRegion
2315 _Jv_JNI_SetPrimitiveArrayRegion, // SetFloatArrayRegion
2316 _Jv_JNI_SetPrimitiveArrayRegion, // SetDoubleArrayRegion
2317 _Jv_JNI_RegisterNatives, // RegisterNatives
2318 _Jv_JNI_UnregisterNatives, // UnregisterNatives
2319 _Jv_JNI_MonitorEnter, // MonitorEnter
2320 _Jv_JNI_MonitorExit, // MonitorExit
2321 _Jv_JNI_GetJavaVM, // GetJavaVM
2323 _Jv_JNI_GetStringRegion, // GetStringRegion
2324 _Jv_JNI_GetStringUTFRegion, // GetStringUTFRegion
2325 _Jv_JNI_GetPrimitiveArrayCritical, // GetPrimitiveArrayCritical
2326 _Jv_JNI_ReleasePrimitiveArrayCritical, // ReleasePrimitiveArrayCritical
2327 _Jv_JNI_GetStringCritical, // GetStringCritical
2328 _Jv_JNI_ReleaseStringCritical, // ReleaseStringCritical
2330 NOT_IMPL /* newweakglobalref */,
2331 NOT_IMPL /* deleteweakglobalref */,
2333 _Jv_JNI_ExceptionCheck
2336 struct JNIInvokeInterface _Jv_JNI_InvokeFunctions =
2338 RESERVED,
2339 RESERVED,
2340 RESERVED,
2342 _Jv_JNI_DestroyJavaVM,
2343 _Jv_JNI_AttachCurrentThread,
2344 _Jv_JNI_DetachCurrentThread,
2345 _Jv_JNI_GetEnv