Mark ChangeLog
[official-gcc.git] / libjava / jni.cc
blob78bf3b3eab0ac4030a7b1bb9830636e0c0b25e31
1 // jni.cc - JNI implementation, including the jump table.
3 /* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
4 Free Software Foundation
6 This file is part of libgcj.
8 This software is copyrighted work licensed under the terms of the
9 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
10 details. */
12 #include <config.h>
14 #include <stdio.h>
15 #include <stddef.h>
16 #include <string.h>
18 #include <gcj/cni.h>
19 #include <jvm.h>
20 #include <java-assert.h>
21 #include <jni.h>
22 #ifdef ENABLE_JVMPI
23 #include <jvmpi.h>
24 #endif
26 #include <java/lang/Class.h>
27 #include <java/lang/ClassLoader.h>
28 #include <java/lang/Throwable.h>
29 #include <java/lang/ArrayIndexOutOfBoundsException.h>
30 #include <java/lang/StringIndexOutOfBoundsException.h>
31 #include <java/lang/StringBuffer.h>
32 #include <java/lang/UnsatisfiedLinkError.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/lang/Integer.h>
41 #include <java/lang/ThreadGroup.h>
42 #include <java/lang/Thread.h>
43 #include <java/lang/IllegalAccessError.h>
44 #include <java/nio/Buffer.h>
45 #include <java/nio/DirectByteBufferImpl.h>
46 #include <java/nio/DirectByteBufferImpl$ReadWrite.h>
47 #include <java/util/IdentityHashMap.h>
48 #include <gnu/gcj/RawData.h>
49 #include <java/lang/ClassNotFoundException.h>
51 #include <gcj/method.h>
52 #include <gcj/field.h>
54 #include <java-interp.h>
55 #include <java-threads.h>
57 using namespace gcj;
59 // This enum is used to select different template instantiations in
60 // the invocation code.
61 enum invocation_type
63 normal,
64 nonvirtual,
65 static_type,
66 constructor
69 // Forward declarations.
70 extern struct JNINativeInterface _Jv_JNIFunctions;
71 extern struct JNIInvokeInterface _Jv_JNI_InvokeFunctions;
73 // Number of slots in the default frame. The VM must allow at least
74 // 16.
75 #define FRAME_SIZE 16
77 // Mark value indicating this is an overflow frame.
78 #define MARK_NONE 0
79 // Mark value indicating this is a user frame.
80 #define MARK_USER 1
81 // Mark value indicating this is a system frame.
82 #define MARK_SYSTEM 2
84 // This structure is used to keep track of local references.
85 struct _Jv_JNI_LocalFrame
87 // This is true if this frame object represents a pushed frame (eg
88 // from PushLocalFrame).
89 int marker;
91 // Flag to indicate some locals were allocated.
92 int allocated_p;
94 // Number of elements in frame.
95 int size;
97 // Next frame in chain.
98 _Jv_JNI_LocalFrame *next;
100 // The elements. These are allocated using the C "struct hack".
101 jobject vec[0];
104 // This holds a reference count for all local references.
105 static java::util::IdentityHashMap *local_ref_table;
106 // This holds a reference count for all global references.
107 static java::util::IdentityHashMap *global_ref_table;
109 // The only VM.
110 static JavaVM *the_vm;
112 #ifdef ENABLE_JVMPI
113 // The only JVMPI interface description.
114 static JVMPI_Interface _Jv_JVMPI_Interface;
116 static jint
117 jvmpiEnableEvent (jint event_type, void *)
119 switch (event_type)
121 case JVMPI_EVENT_OBJECT_ALLOC:
122 _Jv_JVMPI_Notify_OBJECT_ALLOC = _Jv_JVMPI_Interface.NotifyEvent;
123 break;
125 case JVMPI_EVENT_THREAD_START:
126 _Jv_JVMPI_Notify_THREAD_START = _Jv_JVMPI_Interface.NotifyEvent;
127 break;
129 case JVMPI_EVENT_THREAD_END:
130 _Jv_JVMPI_Notify_THREAD_END = _Jv_JVMPI_Interface.NotifyEvent;
131 break;
133 default:
134 return JVMPI_NOT_AVAILABLE;
137 return JVMPI_SUCCESS;
140 static jint
141 jvmpiDisableEvent (jint event_type, void *)
143 switch (event_type)
145 case JVMPI_EVENT_OBJECT_ALLOC:
146 _Jv_JVMPI_Notify_OBJECT_ALLOC = NULL;
147 break;
149 default:
150 return JVMPI_NOT_AVAILABLE;
153 return JVMPI_SUCCESS;
155 #endif
159 void
160 _Jv_JNI_Init (void)
162 local_ref_table = new java::util::IdentityHashMap;
163 global_ref_table = new java::util::IdentityHashMap;
165 #ifdef ENABLE_JVMPI
166 _Jv_JVMPI_Interface.version = 1;
167 _Jv_JVMPI_Interface.EnableEvent = &jvmpiEnableEvent;
168 _Jv_JVMPI_Interface.DisableEvent = &jvmpiDisableEvent;
169 _Jv_JVMPI_Interface.EnableGC = &_Jv_EnableGC;
170 _Jv_JVMPI_Interface.DisableGC = &_Jv_DisableGC;
171 _Jv_JVMPI_Interface.RunGC = &_Jv_RunGC;
172 #endif
175 // Tell the GC that a certain pointer is live.
176 static void
177 mark_for_gc (jobject obj, java::util::IdentityHashMap *ref_table)
179 JvSynchronize sync (ref_table);
181 using namespace java::lang;
182 Integer *refcount = (Integer *) ref_table->get (obj);
183 jint val = (refcount == NULL) ? 0 : refcount->intValue ();
184 // FIXME: what about out of memory error?
185 ref_table->put (obj, new Integer (val + 1));
188 // Unmark a pointer.
189 static void
190 unmark_for_gc (jobject obj, java::util::IdentityHashMap *ref_table)
192 JvSynchronize sync (ref_table);
194 using namespace java::lang;
195 Integer *refcount = (Integer *) ref_table->get (obj);
196 JvAssert (refcount);
197 jint val = refcount->intValue () - 1;
198 JvAssert (val >= 0);
199 if (val == 0)
200 ref_table->remove (obj);
201 else
202 // FIXME: what about out of memory error?
203 ref_table->put (obj, new Integer (val));
206 // "Unwrap" some random non-reference type. This exists to simplify
207 // other template functions.
208 template<typename T>
209 static T
210 unwrap (T val)
212 return val;
215 // Unwrap a weak reference, if required.
216 template<typename T>
217 static T *
218 unwrap (T *obj)
220 using namespace gnu::gcj::runtime;
221 // We can compare the class directly because JNIWeakRef is `final'.
222 // Doing it this way is much faster.
223 if (obj == NULL || obj->getClass () != &JNIWeakRef::class$)
224 return obj;
225 JNIWeakRef *wr = reinterpret_cast<JNIWeakRef *> (obj);
226 return reinterpret_cast<T *> (wr->get ());
229 jobject
230 _Jv_UnwrapJNIweakReference (jobject obj)
232 return unwrap (obj);
237 static jobject JNICALL
238 _Jv_JNI_NewGlobalRef (JNIEnv *, jobject obj)
240 // This seems weird but I think it is correct.
241 obj = unwrap (obj);
242 mark_for_gc (obj, global_ref_table);
243 return obj;
246 static void JNICALL
247 _Jv_JNI_DeleteGlobalRef (JNIEnv *, jobject obj)
249 // This seems weird but I think it is correct.
250 obj = unwrap (obj);
251 unmark_for_gc (obj, global_ref_table);
254 static void JNICALL
255 _Jv_JNI_DeleteLocalRef (JNIEnv *env, jobject obj)
257 _Jv_JNI_LocalFrame *frame;
259 // This seems weird but I think it is correct.
260 obj = unwrap (obj);
262 for (frame = env->locals; frame != NULL; frame = frame->next)
264 for (int i = 0; i < frame->size; ++i)
266 if (frame->vec[i] == obj)
268 frame->vec[i] = NULL;
269 unmark_for_gc (obj, local_ref_table);
270 return;
274 // Don't go past a marked frame.
275 JvAssert (frame->marker == MARK_NONE);
278 JvAssert (0);
281 static jint JNICALL
282 _Jv_JNI_EnsureLocalCapacity (JNIEnv *env, jint size)
284 // It is easier to just always allocate a new frame of the requested
285 // size. This isn't the most efficient thing, but for now we don't
286 // care. Note that _Jv_JNI_PushLocalFrame relies on this right now.
288 _Jv_JNI_LocalFrame *frame;
291 frame = (_Jv_JNI_LocalFrame *) _Jv_Malloc (sizeof (_Jv_JNI_LocalFrame)
292 + size * sizeof (jobject));
294 catch (jthrowable t)
296 env->ex = t;
297 return JNI_ERR;
300 frame->marker = MARK_NONE;
301 frame->size = size;
302 frame->allocated_p = 0;
303 memset (&frame->vec[0], 0, size * sizeof (jobject));
304 frame->next = env->locals;
305 env->locals = frame;
307 return 0;
310 static jint JNICALL
311 _Jv_JNI_PushLocalFrame (JNIEnv *env, jint size)
313 jint r = _Jv_JNI_EnsureLocalCapacity (env, size);
314 if (r < 0)
315 return r;
317 // The new frame is on top.
318 env->locals->marker = MARK_USER;
320 return 0;
323 static jobject JNICALL
324 _Jv_JNI_NewLocalRef (JNIEnv *env, jobject obj)
326 // This seems weird but I think it is correct.
327 obj = unwrap (obj);
329 // Try to find an open slot somewhere in the topmost frame.
330 _Jv_JNI_LocalFrame *frame = env->locals;
331 bool done = false, set = false;
332 for (; frame != NULL && ! done; frame = frame->next)
334 for (int i = 0; i < frame->size; ++i)
336 if (frame->vec[i] == NULL)
338 set = true;
339 done = true;
340 frame->vec[i] = obj;
341 frame->allocated_p = 1;
342 break;
346 // If we found a slot, or if the frame we just searched is the
347 // mark frame, then we are done.
348 if (done || frame == NULL || frame->marker != MARK_NONE)
349 break;
352 if (! set)
354 // No slots, so we allocate a new frame. According to the spec
355 // we could just die here. FIXME: return value.
356 _Jv_JNI_EnsureLocalCapacity (env, 16);
357 // We know the first element of the new frame will be ok.
358 env->locals->vec[0] = obj;
359 env->locals->allocated_p = 1;
362 mark_for_gc (obj, local_ref_table);
363 return obj;
366 static jobject JNICALL
367 _Jv_JNI_PopLocalFrame (JNIEnv *env, jobject result, int stop)
369 _Jv_JNI_LocalFrame *rf = env->locals;
371 bool done = false;
372 while (rf != NULL && ! done)
374 for (int i = 0; i < rf->size; ++i)
375 if (rf->vec[i] != NULL)
376 unmark_for_gc (rf->vec[i], local_ref_table);
378 // If the frame we just freed is the marker frame, we are done.
379 done = (rf->marker == stop);
381 _Jv_JNI_LocalFrame *n = rf->next;
382 // When N==NULL, we've reached the reusable bottom_locals, and we must
383 // not free it. However, we must be sure to clear all its elements.
384 if (n == NULL)
386 if (rf->allocated_p)
387 memset (&rf->vec[0], 0, rf->size * sizeof (jobject));
388 rf->allocated_p = 0;
389 rf = NULL;
390 break;
393 _Jv_Free (rf);
394 rf = n;
397 // Update the local frame information.
398 env->locals = rf;
400 return result == NULL ? NULL : _Jv_JNI_NewLocalRef (env, result);
403 static jobject JNICALL
404 _Jv_JNI_PopLocalFrame (JNIEnv *env, jobject result)
406 return _Jv_JNI_PopLocalFrame (env, result, MARK_USER);
409 // Make sure an array's type is compatible with the type of the
410 // destination.
411 template<typename T>
412 static bool
413 _Jv_JNI_check_types (JNIEnv *env, JArray<T> *array, jclass K)
415 jclass klass = array->getClass()->getComponentType();
416 if (__builtin_expect (klass != K, false))
418 env->ex = new java::lang::IllegalAccessError ();
419 return false;
421 else
422 return true;
425 // Pop a `system' frame from the stack. This is `extern "C"' as it is
426 // used by the compiler.
427 extern "C" void
428 _Jv_JNI_PopSystemFrame (JNIEnv *env)
430 // Only enter slow path when we're not at the bottom, or there have been
431 // allocations. Usually this is false and we can just null out the locals
432 // field.
434 if (__builtin_expect ((env->locals->next
435 || env->locals->allocated_p), false))
436 _Jv_JNI_PopLocalFrame (env, NULL, MARK_SYSTEM);
437 else
438 env->locals = NULL;
440 if (__builtin_expect (env->ex != NULL, false))
442 jthrowable t = env->ex;
443 env->ex = NULL;
444 throw t;
448 template<typename T> T extract_from_jvalue(jvalue const & t);
449 template<> jboolean extract_from_jvalue(jvalue const & jv) { return jv.z; }
450 template<> jbyte extract_from_jvalue(jvalue const & jv) { return jv.b; }
451 template<> jchar extract_from_jvalue(jvalue const & jv) { return jv.c; }
452 template<> jshort extract_from_jvalue(jvalue const & jv) { return jv.s; }
453 template<> jint extract_from_jvalue(jvalue const & jv) { return jv.i; }
454 template<> jlong extract_from_jvalue(jvalue const & jv) { return jv.j; }
455 template<> jfloat extract_from_jvalue(jvalue const & jv) { return jv.f; }
456 template<> jdouble extract_from_jvalue(jvalue const & jv) { return jv.d; }
457 template<> jobject extract_from_jvalue(jvalue const & jv) { return jv.l; }
460 // This function is used from other template functions. It wraps the
461 // return value appropriately; we specialize it so that object returns
462 // are turned into local references.
463 template<typename T>
464 static T
465 wrap_value (JNIEnv *, T value)
467 return value;
470 // This specialization is used for jobject, jclass, jstring, jarray,
471 // etc.
472 template<typename R, typename T>
473 static T *
474 wrap_value (JNIEnv *env, T *value)
476 return (value == NULL
477 ? value
478 : (T *) _Jv_JNI_NewLocalRef (env, (jobject) value));
483 static jint JNICALL
484 _Jv_JNI_GetVersion (JNIEnv *)
486 return JNI_VERSION_1_4;
489 static jclass JNICALL
490 _Jv_JNI_DefineClass (JNIEnv *env, const char *name, jobject loader,
491 const jbyte *buf, jsize bufLen)
495 loader = unwrap (loader);
497 jstring sname = JvNewStringUTF (name);
498 jbyteArray bytes = JvNewByteArray (bufLen);
500 jbyte *elts = elements (bytes);
501 memcpy (elts, buf, bufLen * sizeof (jbyte));
503 java::lang::ClassLoader *l
504 = reinterpret_cast<java::lang::ClassLoader *> (loader);
506 jclass result = l->defineClass (sname, bytes, 0, bufLen);
507 return (jclass) wrap_value (env, result);
509 catch (jthrowable t)
511 env->ex = t;
512 return NULL;
516 static jclass JNICALL
517 _Jv_JNI_FindClass (JNIEnv *env, const char *name)
519 // FIXME: assume that NAME isn't too long.
520 int len = strlen (name);
521 char s[len + 1];
522 for (int i = 0; i <= len; ++i)
523 s[i] = (name[i] == '/') ? '.' : name[i];
525 jclass r = NULL;
528 // This might throw an out of memory exception.
529 jstring n = JvNewStringUTF (s);
531 java::lang::ClassLoader *loader = NULL;
532 if (env->klass != NULL)
533 loader = env->klass->getClassLoaderInternal ();
535 if (loader == NULL)
537 // FIXME: should use getBaseClassLoader, but we don't have that
538 // yet.
539 loader = java::lang::ClassLoader::getSystemClassLoader ();
542 r = loader->loadClass (n);
544 catch (jthrowable t)
546 env->ex = t;
549 return (jclass) wrap_value (env, r);
552 static jclass JNICALL
553 _Jv_JNI_GetSuperclass (JNIEnv *env, jclass clazz)
555 return (jclass) wrap_value (env, unwrap (clazz)->getSuperclass ());
558 static jboolean JNICALL
559 _Jv_JNI_IsAssignableFrom (JNIEnv *, jclass clazz1, jclass clazz2)
561 return unwrap (clazz2)->isAssignableFrom (unwrap (clazz1));
564 static jint JNICALL
565 _Jv_JNI_Throw (JNIEnv *env, jthrowable obj)
567 // We check in case the user did some funky cast.
568 obj = unwrap (obj);
569 JvAssert (obj != NULL && java::lang::Throwable::class$.isInstance (obj));
570 env->ex = obj;
571 return 0;
574 static jint JNICALL
575 _Jv_JNI_ThrowNew (JNIEnv *env, jclass clazz, const char *message)
577 using namespace java::lang::reflect;
579 clazz = unwrap (clazz);
580 JvAssert (java::lang::Throwable::class$.isAssignableFrom (clazz));
582 int r = JNI_OK;
585 JArray<jclass> *argtypes
586 = (JArray<jclass> *) JvNewObjectArray (1, &java::lang::Class::class$,
587 NULL);
589 jclass *elts = elements (argtypes);
590 elts[0] = &java::lang::String::class$;
592 Constructor *cons = clazz->getConstructor (argtypes);
594 jobjectArray values = JvNewObjectArray (1, &java::lang::String::class$,
595 NULL);
596 jobject *velts = elements (values);
597 velts[0] = JvNewStringUTF (message);
599 jobject obj = cons->newInstance (values);
601 env->ex = reinterpret_cast<jthrowable> (obj);
603 catch (jthrowable t)
605 env->ex = t;
606 r = JNI_ERR;
609 return r;
612 static jthrowable JNICALL
613 _Jv_JNI_ExceptionOccurred (JNIEnv *env)
615 return (jthrowable) wrap_value (env, env->ex);
618 static void JNICALL
619 _Jv_JNI_ExceptionDescribe (JNIEnv *env)
621 if (env->ex != NULL)
622 env->ex->printStackTrace();
625 static void JNICALL
626 _Jv_JNI_ExceptionClear (JNIEnv *env)
628 env->ex = NULL;
631 static jboolean JNICALL
632 _Jv_JNI_ExceptionCheck (JNIEnv *env)
634 return env->ex != NULL;
637 static void JNICALL
638 _Jv_JNI_FatalError (JNIEnv *, const char *message)
640 JvFail (message);
645 static jboolean JNICALL
646 _Jv_JNI_IsSameObject (JNIEnv *, jobject obj1, jobject obj2)
648 return unwrap (obj1) == unwrap (obj2);
651 static jobject JNICALL
652 _Jv_JNI_AllocObject (JNIEnv *env, jclass clazz)
654 jobject obj = NULL;
655 using namespace java::lang::reflect;
659 clazz = unwrap (clazz);
660 JvAssert (clazz && ! clazz->isArray ());
661 if (clazz->isInterface() || Modifier::isAbstract(clazz->getModifiers()))
662 env->ex = new java::lang::InstantiationException ();
663 else
664 obj = _Jv_AllocObject (clazz);
666 catch (jthrowable t)
668 env->ex = t;
671 return wrap_value (env, obj);
674 static jclass JNICALL
675 _Jv_JNI_GetObjectClass (JNIEnv *env, jobject obj)
677 obj = unwrap (obj);
678 JvAssert (obj);
679 return (jclass) wrap_value (env, obj->getClass());
682 static jboolean JNICALL
683 _Jv_JNI_IsInstanceOf (JNIEnv *, jobject obj, jclass clazz)
685 return unwrap (clazz)->isInstance(unwrap (obj));
691 // This section concerns method invocation.
694 template<jboolean is_static>
695 static jmethodID JNICALL
696 _Jv_JNI_GetAnyMethodID (JNIEnv *env, jclass clazz,
697 const char *name, const char *sig)
701 clazz = unwrap (clazz);
702 _Jv_InitClass (clazz);
704 _Jv_Utf8Const *name_u = _Jv_makeUtf8Const ((char *) name, -1);
706 // FIXME: assume that SIG isn't too long.
707 int len = strlen (sig);
708 char s[len + 1];
709 for (int i = 0; i <= len; ++i)
710 s[i] = (sig[i] == '/') ? '.' : sig[i];
711 _Jv_Utf8Const *sig_u = _Jv_makeUtf8Const ((char *) s, -1);
713 JvAssert (! clazz->isPrimitive());
715 using namespace java::lang::reflect;
717 while (clazz != NULL)
719 jint count = JvNumMethods (clazz);
720 jmethodID meth = JvGetFirstMethod (clazz);
722 for (jint i = 0; i < count; ++i)
724 if (((is_static && Modifier::isStatic (meth->accflags))
725 || (! is_static && ! Modifier::isStatic (meth->accflags)))
726 && _Jv_equalUtf8Consts (meth->name, name_u)
727 && _Jv_equalUtf8Consts (meth->signature, sig_u))
728 return meth;
730 meth = meth->getNextMethod();
733 clazz = clazz->getSuperclass ();
736 java::lang::StringBuffer *name_sig =
737 new java::lang::StringBuffer (JvNewStringUTF (name));
738 name_sig->append ((jchar) ' ')->append (JvNewStringUTF (s));
739 env->ex = new java::lang::NoSuchMethodError (name_sig->toString ());
741 catch (jthrowable t)
743 env->ex = t;
746 return NULL;
749 // This is a helper function which turns a va_list into an array of
750 // `jvalue's. It needs signature information in order to do its work.
751 // The array of values must already be allocated.
752 static void
753 array_from_valist (jvalue *values, JArray<jclass> *arg_types, va_list vargs)
755 jclass *arg_elts = elements (arg_types);
756 for (int i = 0; i < arg_types->length; ++i)
758 // Here we assume that sizeof(int) >= sizeof(jint), because we
759 // use `int' when decoding the varargs. Likewise for
760 // float, and double. Also we assume that sizeof(jlong) >=
761 // sizeof(int), i.e. that jlong values are not further
762 // promoted.
763 JvAssert (sizeof (int) >= sizeof (jint));
764 JvAssert (sizeof (jlong) >= sizeof (int));
765 JvAssert (sizeof (double) >= sizeof (jfloat));
766 JvAssert (sizeof (double) >= sizeof (jdouble));
767 if (arg_elts[i] == JvPrimClass (byte))
768 values[i].b = (jbyte) va_arg (vargs, int);
769 else if (arg_elts[i] == JvPrimClass (short))
770 values[i].s = (jshort) va_arg (vargs, int);
771 else if (arg_elts[i] == JvPrimClass (int))
772 values[i].i = (jint) va_arg (vargs, int);
773 else if (arg_elts[i] == JvPrimClass (long))
774 values[i].j = (jlong) va_arg (vargs, jlong);
775 else if (arg_elts[i] == JvPrimClass (float))
776 values[i].f = (jfloat) va_arg (vargs, double);
777 else if (arg_elts[i] == JvPrimClass (double))
778 values[i].d = (jdouble) va_arg (vargs, double);
779 else if (arg_elts[i] == JvPrimClass (boolean))
780 values[i].z = (jboolean) va_arg (vargs, int);
781 else if (arg_elts[i] == JvPrimClass (char))
782 values[i].c = (jchar) va_arg (vargs, int);
783 else
785 // An object.
786 values[i].l = unwrap (va_arg (vargs, jobject));
791 // This can call any sort of method: virtual, "nonvirtual", static, or
792 // constructor.
793 template<typename T, invocation_type style>
794 static T JNICALL
795 _Jv_JNI_CallAnyMethodV (JNIEnv *env, jobject obj, jclass klass,
796 jmethodID id, va_list vargs)
798 obj = unwrap (obj);
799 klass = unwrap (klass);
801 jclass decl_class = klass ? klass : obj->getClass ();
802 JvAssert (decl_class != NULL);
804 jclass return_type;
805 JArray<jclass> *arg_types;
809 _Jv_GetTypesFromSignature (id, decl_class,
810 &arg_types, &return_type);
812 jvalue args[arg_types->length];
813 array_from_valist (args, arg_types, vargs);
815 // For constructors we need to pass the Class we are instantiating.
816 if (style == constructor)
817 return_type = klass;
819 jvalue result;
820 _Jv_CallAnyMethodA (obj, return_type, id,
821 style == constructor,
822 style == normal,
823 arg_types, args, &result);
825 return wrap_value (env, extract_from_jvalue<T>(result));
827 catch (jthrowable t)
829 env->ex = t;
832 return wrap_value (env, (T) 0);
835 template<typename T, invocation_type style>
836 static T JNICALL
837 _Jv_JNI_CallAnyMethod (JNIEnv *env, jobject obj, jclass klass,
838 jmethodID method, ...)
840 va_list args;
841 T result;
843 va_start (args, method);
844 result = _Jv_JNI_CallAnyMethodV<T, style> (env, obj, klass, method, args);
845 va_end (args);
847 return result;
850 template<typename T, invocation_type style>
851 static T JNICALL
852 _Jv_JNI_CallAnyMethodA (JNIEnv *env, jobject obj, jclass klass,
853 jmethodID id, jvalue *args)
855 obj = unwrap (obj);
856 klass = unwrap (klass);
858 jclass decl_class = klass ? klass : obj->getClass ();
859 JvAssert (decl_class != NULL);
861 jclass return_type;
862 JArray<jclass> *arg_types;
865 _Jv_GetTypesFromSignature (id, decl_class,
866 &arg_types, &return_type);
868 // For constructors we need to pass the Class we are instantiating.
869 if (style == constructor)
870 return_type = klass;
872 // Unwrap arguments as required. Eww.
873 jclass *type_elts = elements (arg_types);
874 jvalue arg_copy[arg_types->length];
875 for (int i = 0; i < arg_types->length; ++i)
877 if (type_elts[i]->isPrimitive ())
878 arg_copy[i] = args[i];
879 else
880 arg_copy[i].l = unwrap (args[i].l);
883 jvalue result;
884 _Jv_CallAnyMethodA (obj, return_type, id,
885 style == constructor,
886 style == normal,
887 arg_types, arg_copy, &result);
889 return wrap_value (env, extract_from_jvalue<T>(result));
891 catch (jthrowable t)
893 env->ex = t;
896 return wrap_value (env, (T) 0);
899 template<invocation_type style>
900 static void JNICALL
901 _Jv_JNI_CallAnyVoidMethodV (JNIEnv *env, jobject obj, jclass klass,
902 jmethodID id, va_list vargs)
904 obj = unwrap (obj);
905 klass = unwrap (klass);
907 jclass decl_class = klass ? klass : obj->getClass ();
908 JvAssert (decl_class != NULL);
910 jclass return_type;
911 JArray<jclass> *arg_types;
914 _Jv_GetTypesFromSignature (id, decl_class,
915 &arg_types, &return_type);
917 jvalue args[arg_types->length];
918 array_from_valist (args, arg_types, vargs);
920 // For constructors we need to pass the Class we are instantiating.
921 if (style == constructor)
922 return_type = klass;
924 _Jv_CallAnyMethodA (obj, return_type, id,
925 style == constructor,
926 style == normal,
927 arg_types, args, NULL);
929 catch (jthrowable t)
931 env->ex = t;
935 template<invocation_type style>
936 static void JNICALL
937 _Jv_JNI_CallAnyVoidMethod (JNIEnv *env, jobject obj, jclass klass,
938 jmethodID method, ...)
940 va_list args;
942 va_start (args, method);
943 _Jv_JNI_CallAnyVoidMethodV<style> (env, obj, klass, method, args);
944 va_end (args);
947 template<invocation_type style>
948 static void JNICALL
949 _Jv_JNI_CallAnyVoidMethodA (JNIEnv *env, jobject obj, jclass klass,
950 jmethodID id, jvalue *args)
952 jclass decl_class = klass ? klass : obj->getClass ();
953 JvAssert (decl_class != NULL);
955 jclass return_type;
956 JArray<jclass> *arg_types;
959 _Jv_GetTypesFromSignature (id, decl_class,
960 &arg_types, &return_type);
962 // Unwrap arguments as required. Eww.
963 jclass *type_elts = elements (arg_types);
964 jvalue arg_copy[arg_types->length];
965 for (int i = 0; i < arg_types->length; ++i)
967 if (type_elts[i]->isPrimitive ())
968 arg_copy[i] = args[i];
969 else
970 arg_copy[i].l = unwrap (args[i].l);
973 _Jv_CallAnyMethodA (obj, return_type, id,
974 style == constructor,
975 style == normal,
976 arg_types, args, NULL);
978 catch (jthrowable t)
980 env->ex = t;
984 // Functions with this signature are used to implement functions in
985 // the CallMethod family.
986 template<typename T>
987 static T JNICALL
988 _Jv_JNI_CallMethodV (JNIEnv *env, jobject obj,
989 jmethodID id, va_list args)
991 return _Jv_JNI_CallAnyMethodV<T, normal> (env, obj, NULL, id, args);
994 // Functions with this signature are used to implement functions in
995 // the CallMethod family.
996 template<typename T>
997 static T JNICALL
998 _Jv_JNI_CallMethod (JNIEnv *env, jobject obj, jmethodID id, ...)
1000 va_list args;
1001 T result;
1003 va_start (args, id);
1004 result = _Jv_JNI_CallAnyMethodV<T, normal> (env, obj, NULL, id, args);
1005 va_end (args);
1007 return result;
1010 // Functions with this signature are used to implement functions in
1011 // the CallMethod family.
1012 template<typename T>
1013 static T JNICALL
1014 _Jv_JNI_CallMethodA (JNIEnv *env, jobject obj,
1015 jmethodID id, jvalue *args)
1017 return _Jv_JNI_CallAnyMethodA<T, normal> (env, obj, NULL, id, args);
1020 static void JNICALL
1021 _Jv_JNI_CallVoidMethodV (JNIEnv *env, jobject obj,
1022 jmethodID id, va_list args)
1024 _Jv_JNI_CallAnyVoidMethodV<normal> (env, obj, NULL, id, args);
1027 static void JNICALL
1028 _Jv_JNI_CallVoidMethod (JNIEnv *env, jobject obj, jmethodID id, ...)
1030 va_list args;
1032 va_start (args, id);
1033 _Jv_JNI_CallAnyVoidMethodV<normal> (env, obj, NULL, id, args);
1034 va_end (args);
1037 static void JNICALL
1038 _Jv_JNI_CallVoidMethodA (JNIEnv *env, jobject obj,
1039 jmethodID id, jvalue *args)
1041 _Jv_JNI_CallAnyVoidMethodA<normal> (env, obj, NULL, id, args);
1044 // Functions with this signature are used to implement functions in
1045 // the CallStaticMethod family.
1046 template<typename T>
1047 static T JNICALL
1048 _Jv_JNI_CallStaticMethodV (JNIEnv *env, jclass klass,
1049 jmethodID id, va_list args)
1051 JvAssert (((id->accflags) & java::lang::reflect::Modifier::STATIC));
1052 JvAssert (java::lang::Class::class$.isInstance (unwrap (klass)));
1054 return _Jv_JNI_CallAnyMethodV<T, static_type> (env, NULL, klass, id, args);
1057 // Functions with this signature are used to implement functions in
1058 // the CallStaticMethod family.
1059 template<typename T>
1060 static T JNICALL
1061 _Jv_JNI_CallStaticMethod (JNIEnv *env, jclass klass,
1062 jmethodID id, ...)
1064 va_list args;
1065 T result;
1067 JvAssert (((id->accflags) & java::lang::reflect::Modifier::STATIC));
1068 JvAssert (java::lang::Class::class$.isInstance (unwrap (klass)));
1070 va_start (args, id);
1071 result = _Jv_JNI_CallAnyMethodV<T, static_type> (env, NULL, klass,
1072 id, args);
1073 va_end (args);
1075 return result;
1078 // Functions with this signature are used to implement functions in
1079 // the CallStaticMethod family.
1080 template<typename T>
1081 static T JNICALL
1082 _Jv_JNI_CallStaticMethodA (JNIEnv *env, jclass klass, jmethodID id,
1083 jvalue *args)
1085 JvAssert (((id->accflags) & java::lang::reflect::Modifier::STATIC));
1086 JvAssert (java::lang::Class::class$.isInstance (unwrap (klass)));
1088 return _Jv_JNI_CallAnyMethodA<T, static_type> (env, NULL, klass, id, args);
1091 static void JNICALL
1092 _Jv_JNI_CallStaticVoidMethodV (JNIEnv *env, jclass klass,
1093 jmethodID id, va_list args)
1095 _Jv_JNI_CallAnyVoidMethodV<static_type> (env, NULL, klass, id, args);
1098 static void JNICALL
1099 _Jv_JNI_CallStaticVoidMethod (JNIEnv *env, jclass klass,
1100 jmethodID id, ...)
1102 va_list args;
1104 va_start (args, id);
1105 _Jv_JNI_CallAnyVoidMethodV<static_type> (env, NULL, klass, id, args);
1106 va_end (args);
1109 static void JNICALL
1110 _Jv_JNI_CallStaticVoidMethodA (JNIEnv *env, jclass klass,
1111 jmethodID id, jvalue *args)
1113 _Jv_JNI_CallAnyVoidMethodA<static_type> (env, NULL, klass, id, args);
1116 static jobject JNICALL
1117 _Jv_JNI_NewObjectV (JNIEnv *env, jclass klass,
1118 jmethodID id, va_list args)
1120 JvAssert (klass && ! klass->isArray ());
1121 JvAssert (! strcmp (id->name->data, "<init>")
1122 && id->signature->length > 2
1123 && id->signature->data[0] == '('
1124 && ! strcmp (&id->signature->data[id->signature->length - 2],
1125 ")V"));
1127 return _Jv_JNI_CallAnyMethodV<jobject, constructor> (env, NULL, klass,
1128 id, args);
1131 static jobject JNICALL
1132 _Jv_JNI_NewObject (JNIEnv *env, jclass klass, jmethodID id, ...)
1134 JvAssert (klass && ! klass->isArray ());
1135 JvAssert (! strcmp (id->name->data, "<init>")
1136 && id->signature->length > 2
1137 && id->signature->data[0] == '('
1138 && ! strcmp (&id->signature->data[id->signature->length - 2],
1139 ")V"));
1141 va_list args;
1142 jobject result;
1144 va_start (args, id);
1145 result = _Jv_JNI_CallAnyMethodV<jobject, constructor> (env, NULL, klass,
1146 id, args);
1147 va_end (args);
1149 return result;
1152 static jobject JNICALL
1153 _Jv_JNI_NewObjectA (JNIEnv *env, jclass klass, jmethodID id,
1154 jvalue *args)
1156 JvAssert (klass && ! klass->isArray ());
1157 JvAssert (! strcmp (id->name->data, "<init>")
1158 && id->signature->length > 2
1159 && id->signature->data[0] == '('
1160 && ! strcmp (&id->signature->data[id->signature->length - 2],
1161 ")V"));
1163 return _Jv_JNI_CallAnyMethodA<jobject, constructor> (env, NULL, klass,
1164 id, args);
1169 template<typename T>
1170 static T JNICALL
1171 _Jv_JNI_GetField (JNIEnv *env, jobject obj, jfieldID field)
1173 obj = unwrap (obj);
1174 JvAssert (obj);
1175 T *ptr = (T *) ((char *) obj + field->getOffset ());
1176 return wrap_value (env, *ptr);
1179 template<typename T>
1180 static void JNICALL
1181 _Jv_JNI_SetField (JNIEnv *, jobject obj, jfieldID field, T value)
1183 obj = unwrap (obj);
1184 value = unwrap (value);
1186 JvAssert (obj);
1187 T *ptr = (T *) ((char *) obj + field->getOffset ());
1188 *ptr = value;
1191 template<jboolean is_static>
1192 static jfieldID JNICALL
1193 _Jv_JNI_GetAnyFieldID (JNIEnv *env, jclass clazz,
1194 const char *name, const char *sig)
1198 clazz = unwrap (clazz);
1200 _Jv_InitClass (clazz);
1202 _Jv_Utf8Const *a_name = _Jv_makeUtf8Const ((char *) name, -1);
1204 // FIXME: assume that SIG isn't too long.
1205 int len = strlen (sig);
1206 char s[len + 1];
1207 for (int i = 0; i <= len; ++i)
1208 s[i] = (sig[i] == '/') ? '.' : sig[i];
1209 java::lang::ClassLoader *loader = clazz->getClassLoaderInternal ();
1210 jclass field_class = _Jv_FindClassFromSignature ((char *) s, loader);
1211 if (! field_class)
1212 throw new java::lang::ClassNotFoundException(JvNewStringUTF(s));
1214 while (clazz != NULL)
1216 // We acquire the class lock so that fields aren't resolved
1217 // while we are running.
1218 JvSynchronize sync (clazz);
1220 jint count = (is_static
1221 ? JvNumStaticFields (clazz)
1222 : JvNumInstanceFields (clazz));
1223 jfieldID field = (is_static
1224 ? JvGetFirstStaticField (clazz)
1225 : JvGetFirstInstanceField (clazz));
1226 for (jint i = 0; i < count; ++i)
1228 _Jv_Utf8Const *f_name = field->getNameUtf8Const(clazz);
1230 // The field might be resolved or it might not be. It
1231 // is much simpler to always resolve it.
1232 _Jv_Linker::resolve_field (field, loader);
1233 if (_Jv_equalUtf8Consts (f_name, a_name)
1234 && field->getClass() == field_class)
1235 return field;
1237 field = field->getNextField ();
1240 clazz = clazz->getSuperclass ();
1243 env->ex = new java::lang::NoSuchFieldError ();
1245 catch (jthrowable t)
1247 env->ex = t;
1249 return NULL;
1252 template<typename T>
1253 static T JNICALL
1254 _Jv_JNI_GetStaticField (JNIEnv *env, jclass, jfieldID field)
1256 T *ptr = (T *) field->u.addr;
1257 return wrap_value (env, *ptr);
1260 template<typename T>
1261 static void JNICALL
1262 _Jv_JNI_SetStaticField (JNIEnv *, jclass, jfieldID field, T value)
1264 value = unwrap (value);
1265 T *ptr = (T *) field->u.addr;
1266 *ptr = value;
1269 static jstring JNICALL
1270 _Jv_JNI_NewString (JNIEnv *env, const jchar *unichars, jsize len)
1274 jstring r = _Jv_NewString (unichars, len);
1275 return (jstring) wrap_value (env, r);
1277 catch (jthrowable t)
1279 env->ex = t;
1280 return NULL;
1284 static jsize JNICALL
1285 _Jv_JNI_GetStringLength (JNIEnv *, jstring string)
1287 return unwrap (string)->length();
1290 static const jchar * JNICALL
1291 _Jv_JNI_GetStringChars (JNIEnv *, jstring string, jboolean *isCopy)
1293 string = unwrap (string);
1294 jchar *result = _Jv_GetStringChars (string);
1295 mark_for_gc (string, global_ref_table);
1296 if (isCopy)
1297 *isCopy = false;
1298 return (const jchar *) result;
1301 static void JNICALL
1302 _Jv_JNI_ReleaseStringChars (JNIEnv *, jstring string, const jchar *)
1304 unmark_for_gc (unwrap (string), global_ref_table);
1307 static jstring JNICALL
1308 _Jv_JNI_NewStringUTF (JNIEnv *env, const char *bytes)
1312 jstring result = JvNewStringUTF (bytes);
1313 return (jstring) wrap_value (env, result);
1315 catch (jthrowable t)
1317 env->ex = t;
1318 return NULL;
1322 static jsize JNICALL
1323 _Jv_JNI_GetStringUTFLength (JNIEnv *, jstring string)
1325 return JvGetStringUTFLength (unwrap (string));
1328 static const char * JNICALL
1329 _Jv_JNI_GetStringUTFChars (JNIEnv *env, jstring string,
1330 jboolean *isCopy)
1334 string = unwrap (string);
1335 if (string == NULL)
1336 return NULL;
1337 jsize len = JvGetStringUTFLength (string);
1338 char *r = (char *) _Jv_Malloc (len + 1);
1339 JvGetStringUTFRegion (string, 0, string->length(), r);
1340 r[len] = '\0';
1342 if (isCopy)
1343 *isCopy = true;
1345 return (const char *) r;
1347 catch (jthrowable t)
1349 env->ex = t;
1350 return NULL;
1354 static void JNICALL
1355 _Jv_JNI_ReleaseStringUTFChars (JNIEnv *, jstring, const char *utf)
1357 _Jv_Free ((void *) utf);
1360 static void JNICALL
1361 _Jv_JNI_GetStringRegion (JNIEnv *env, jstring string, jsize start,
1362 jsize len, jchar *buf)
1364 string = unwrap (string);
1365 jchar *result = _Jv_GetStringChars (string);
1366 if (start < 0 || start > string->length ()
1367 || len < 0 || start + len > string->length ())
1371 env->ex = new java::lang::StringIndexOutOfBoundsException ();
1373 catch (jthrowable t)
1375 env->ex = t;
1378 else
1379 memcpy (buf, &result[start], len * sizeof (jchar));
1382 static void JNICALL
1383 _Jv_JNI_GetStringUTFRegion (JNIEnv *env, jstring str, jsize start,
1384 jsize len, char *buf)
1386 str = unwrap (str);
1388 if (start < 0 || start > str->length ()
1389 || len < 0 || start + len > str->length ())
1393 env->ex = new java::lang::StringIndexOutOfBoundsException ();
1395 catch (jthrowable t)
1397 env->ex = t;
1400 else
1401 _Jv_GetStringUTFRegion (str, start, len, buf);
1404 static const jchar * JNICALL
1405 _Jv_JNI_GetStringCritical (JNIEnv *, jstring str, jboolean *isCopy)
1407 jchar *result = _Jv_GetStringChars (unwrap (str));
1408 if (isCopy)
1409 *isCopy = false;
1410 return result;
1413 static void JNICALL
1414 _Jv_JNI_ReleaseStringCritical (JNIEnv *, jstring, const jchar *)
1416 // Nothing.
1419 static jsize JNICALL
1420 _Jv_JNI_GetArrayLength (JNIEnv *, jarray array)
1422 return unwrap (array)->length;
1425 static jobjectArray JNICALL
1426 _Jv_JNI_NewObjectArray (JNIEnv *env, jsize length,
1427 jclass elementClass, jobject init)
1431 elementClass = unwrap (elementClass);
1432 init = unwrap (init);
1434 _Jv_CheckCast (elementClass, init);
1435 jarray result = JvNewObjectArray (length, elementClass, init);
1436 return (jobjectArray) wrap_value (env, result);
1438 catch (jthrowable t)
1440 env->ex = t;
1441 return NULL;
1445 static jobject JNICALL
1446 _Jv_JNI_GetObjectArrayElement (JNIEnv *env, jobjectArray array,
1447 jsize index)
1449 if ((unsigned) index >= (unsigned) array->length)
1450 _Jv_ThrowBadArrayIndex (index);
1451 jobject *elts = elements (unwrap (array));
1452 return wrap_value (env, elts[index]);
1455 static void JNICALL
1456 _Jv_JNI_SetObjectArrayElement (JNIEnv *env, jobjectArray array,
1457 jsize index, jobject value)
1461 array = unwrap (array);
1462 value = unwrap (value);
1464 _Jv_CheckArrayStore (array, value);
1465 if ((unsigned) index >= (unsigned) array->length)
1466 _Jv_ThrowBadArrayIndex (index);
1467 jobject *elts = elements (array);
1468 elts[index] = value;
1470 catch (jthrowable t)
1472 env->ex = t;
1476 template<typename T, jclass K>
1477 static JArray<T> * JNICALL
1478 _Jv_JNI_NewPrimitiveArray (JNIEnv *env, jsize length)
1482 return (JArray<T> *) wrap_value (env, _Jv_NewPrimArray (K, length));
1484 catch (jthrowable t)
1486 env->ex = t;
1487 return NULL;
1491 template<typename T, jclass K>
1492 static T * JNICALL
1493 _Jv_JNI_GetPrimitiveArrayElements (JNIEnv *env, JArray<T> *array,
1494 jboolean *isCopy)
1496 array = unwrap (array);
1497 if (! _Jv_JNI_check_types (env, array, K))
1498 return NULL;
1499 T *elts = elements (array);
1500 if (isCopy)
1502 // We elect never to copy.
1503 *isCopy = false;
1505 mark_for_gc (array, global_ref_table);
1506 return elts;
1509 template<typename T, jclass K>
1510 static void JNICALL
1511 _Jv_JNI_ReleasePrimitiveArrayElements (JNIEnv *env, JArray<T> *array,
1512 T *, jint /* mode */)
1514 array = unwrap (array);
1515 _Jv_JNI_check_types (env, array, K);
1516 // Note that we ignore MODE. We can do this because we never copy
1517 // the array elements. My reading of the JNI documentation is that
1518 // this is an option for the implementor.
1519 unmark_for_gc (array, global_ref_table);
1522 template<typename T, jclass K>
1523 static void JNICALL
1524 _Jv_JNI_GetPrimitiveArrayRegion (JNIEnv *env, JArray<T> *array,
1525 jsize start, jsize len,
1526 T *buf)
1528 array = unwrap (array);
1529 if (! _Jv_JNI_check_types (env, array, K))
1530 return;
1532 // The cast to unsigned lets us save a comparison.
1533 if (start < 0 || len < 0
1534 || (unsigned long) (start + len) > (unsigned long) array->length)
1538 // FIXME: index.
1539 env->ex = new java::lang::ArrayIndexOutOfBoundsException ();
1541 catch (jthrowable t)
1543 // Could have thown out of memory error.
1544 env->ex = t;
1547 else
1549 T *elts = elements (array) + start;
1550 memcpy (buf, elts, len * sizeof (T));
1554 template<typename T, jclass K>
1555 static void JNICALL
1556 _Jv_JNI_SetPrimitiveArrayRegion (JNIEnv *env, JArray<T> *array,
1557 jsize start, jsize len, T *buf)
1559 array = unwrap (array);
1560 if (! _Jv_JNI_check_types (env, array, K))
1561 return;
1563 // The cast to unsigned lets us save a comparison.
1564 if (start < 0 || len < 0
1565 || (unsigned long) (start + len) > (unsigned long) array->length)
1569 // FIXME: index.
1570 env->ex = new java::lang::ArrayIndexOutOfBoundsException ();
1572 catch (jthrowable t)
1574 env->ex = t;
1577 else
1579 T *elts = elements (array) + start;
1580 memcpy (elts, buf, len * sizeof (T));
1584 static void * JNICALL
1585 _Jv_JNI_GetPrimitiveArrayCritical (JNIEnv *, jarray array,
1586 jboolean *isCopy)
1588 array = unwrap (array);
1589 // FIXME: does this work?
1590 jclass klass = array->getClass()->getComponentType();
1591 JvAssert (klass->isPrimitive ());
1592 char *r = _Jv_GetArrayElementFromElementType (array, klass);
1593 if (isCopy)
1594 *isCopy = false;
1595 return r;
1598 static void JNICALL
1599 _Jv_JNI_ReleasePrimitiveArrayCritical (JNIEnv *, jarray, void *, jint)
1601 // Nothing.
1604 static jint JNICALL
1605 _Jv_JNI_MonitorEnter (JNIEnv *env, jobject obj)
1609 _Jv_MonitorEnter (unwrap (obj));
1610 return 0;
1612 catch (jthrowable t)
1614 env->ex = t;
1616 return JNI_ERR;
1619 static jint JNICALL
1620 _Jv_JNI_MonitorExit (JNIEnv *env, jobject obj)
1624 _Jv_MonitorExit (unwrap (obj));
1625 return 0;
1627 catch (jthrowable t)
1629 env->ex = t;
1631 return JNI_ERR;
1634 // JDK 1.2
1635 jobject JNICALL
1636 _Jv_JNI_ToReflectedField (JNIEnv *env, jclass cls, jfieldID fieldID,
1637 jboolean)
1641 cls = unwrap (cls);
1642 java::lang::reflect::Field *field = new java::lang::reflect::Field();
1643 field->declaringClass = cls;
1644 field->offset = (char*) fieldID - (char *) cls->fields;
1645 field->name = _Jv_NewStringUtf8Const (fieldID->getNameUtf8Const (cls));
1646 return wrap_value (env, field);
1648 catch (jthrowable t)
1650 env->ex = t;
1652 return NULL;
1655 // JDK 1.2
1656 static jfieldID JNICALL
1657 _Jv_JNI_FromReflectedField (JNIEnv *, jobject f)
1659 using namespace java::lang::reflect;
1661 f = unwrap (f);
1662 Field *field = reinterpret_cast<Field *> (f);
1663 return _Jv_FromReflectedField (field);
1666 jobject JNICALL
1667 _Jv_JNI_ToReflectedMethod (JNIEnv *env, jclass klass, jmethodID id,
1668 jboolean)
1670 using namespace java::lang::reflect;
1672 jobject result = NULL;
1673 klass = unwrap (klass);
1677 if (_Jv_equalUtf8Consts (id->name, init_name))
1679 // A constructor.
1680 Constructor *cons = new Constructor ();
1681 cons->offset = (char *) id - (char *) &klass->methods;
1682 cons->declaringClass = klass;
1683 result = cons;
1685 else
1687 Method *meth = new Method ();
1688 meth->offset = (char *) id - (char *) &klass->methods;
1689 meth->declaringClass = klass;
1690 result = meth;
1693 catch (jthrowable t)
1695 env->ex = t;
1698 return wrap_value (env, result);
1701 static jmethodID JNICALL
1702 _Jv_JNI_FromReflectedMethod (JNIEnv *, jobject method)
1704 using namespace java::lang::reflect;
1705 method = unwrap (method);
1706 if (Method::class$.isInstance (method))
1707 return _Jv_FromReflectedMethod (reinterpret_cast<Method *> (method));
1708 return
1709 _Jv_FromReflectedConstructor (reinterpret_cast<Constructor *> (method));
1712 // JDK 1.2.
1713 jweak JNICALL
1714 _Jv_JNI_NewWeakGlobalRef (JNIEnv *env, jobject obj)
1716 using namespace gnu::gcj::runtime;
1717 JNIWeakRef *ref = NULL;
1721 // This seems weird but I think it is correct.
1722 obj = unwrap (obj);
1723 ref = new JNIWeakRef (obj);
1724 mark_for_gc (ref, global_ref_table);
1726 catch (jthrowable t)
1728 env->ex = t;
1731 return reinterpret_cast<jweak> (ref);
1734 void JNICALL
1735 _Jv_JNI_DeleteWeakGlobalRef (JNIEnv *, jweak obj)
1737 using namespace gnu::gcj::runtime;
1738 JNIWeakRef *ref = reinterpret_cast<JNIWeakRef *> (obj);
1739 unmark_for_gc (ref, global_ref_table);
1740 ref->clear ();
1745 // Direct byte buffers.
1747 static jobject JNICALL
1748 _Jv_JNI_NewDirectByteBuffer (JNIEnv *, void *address, jlong length)
1750 using namespace gnu::gcj;
1751 using namespace java::nio;
1752 return new DirectByteBufferImpl$ReadWrite
1753 (reinterpret_cast<RawData *> (address), length);
1756 static void * JNICALL
1757 _Jv_JNI_GetDirectBufferAddress (JNIEnv *, jobject buffer)
1759 using namespace java::nio;
1760 if (! _Jv_IsInstanceOf (buffer, &Buffer::class$))
1761 return NULL;
1762 Buffer *tmp = static_cast<Buffer *> (buffer);
1763 return reinterpret_cast<void *> (tmp->address);
1766 static jlong JNICALL
1767 _Jv_JNI_GetDirectBufferCapacity (JNIEnv *, jobject buffer)
1769 using namespace java::nio;
1770 if (! _Jv_IsInstanceOf (buffer, &Buffer::class$))
1771 return -1;
1772 Buffer *tmp = static_cast<Buffer *> (buffer);
1773 if (tmp->address == NULL)
1774 return -1;
1775 return tmp->capacity();
1780 // Hash table of native methods.
1781 static JNINativeMethod *nathash;
1782 // Number of slots used.
1783 static int nathash_count = 0;
1784 // Number of slots available. Must be power of 2.
1785 static int nathash_size = 0;
1787 #define DELETED_ENTRY ((char *) (~0))
1789 // Compute a hash value for a native method descriptor.
1790 static int
1791 hash (const JNINativeMethod *method)
1793 char *ptr;
1794 int hash = 0;
1796 ptr = method->name;
1797 while (*ptr)
1798 hash = (31 * hash) + *ptr++;
1800 ptr = method->signature;
1801 while (*ptr)
1802 hash = (31 * hash) + *ptr++;
1804 return hash;
1807 // Find the slot where a native method goes.
1808 static JNINativeMethod *
1809 nathash_find_slot (const JNINativeMethod *method)
1811 jint h = hash (method);
1812 int step = (h ^ (h >> 16)) | 1;
1813 int w = h & (nathash_size - 1);
1814 int del = -1;
1816 for (;;)
1818 JNINativeMethod *slotp = &nathash[w];
1819 if (slotp->name == NULL)
1821 if (del >= 0)
1822 return &nathash[del];
1823 else
1824 return slotp;
1826 else if (slotp->name == DELETED_ENTRY)
1827 del = w;
1828 else if (! strcmp (slotp->name, method->name)
1829 && ! strcmp (slotp->signature, method->signature))
1830 return slotp;
1831 w = (w + step) & (nathash_size - 1);
1835 // Find a method. Return NULL if it isn't in the hash table.
1836 static void *
1837 nathash_find (JNINativeMethod *method)
1839 if (nathash == NULL)
1840 return NULL;
1841 JNINativeMethod *slot = nathash_find_slot (method);
1842 if (slot->name == NULL || slot->name == DELETED_ENTRY)
1843 return NULL;
1844 return slot->fnPtr;
1847 static void
1848 natrehash ()
1850 if (nathash == NULL)
1852 nathash_size = 1024;
1853 nathash =
1854 (JNINativeMethod *) _Jv_AllocBytes (nathash_size
1855 * sizeof (JNINativeMethod));
1856 memset (nathash, 0, nathash_size * sizeof (JNINativeMethod));
1858 else
1860 int savesize = nathash_size;
1861 JNINativeMethod *savehash = nathash;
1862 nathash_size *= 2;
1863 nathash =
1864 (JNINativeMethod *) _Jv_AllocBytes (nathash_size
1865 * sizeof (JNINativeMethod));
1866 memset (nathash, 0, nathash_size * sizeof (JNINativeMethod));
1868 for (int i = 0; i < savesize; ++i)
1870 if (savehash[i].name != NULL && savehash[i].name != DELETED_ENTRY)
1872 JNINativeMethod *slot = nathash_find_slot (&savehash[i]);
1873 *slot = savehash[i];
1879 static void
1880 nathash_add (const JNINativeMethod *method)
1882 if (3 * nathash_count >= 2 * nathash_size)
1883 natrehash ();
1884 JNINativeMethod *slot = nathash_find_slot (method);
1885 // If the slot has a real entry in it, then there is no work to do.
1886 if (slot->name != NULL && slot->name != DELETED_ENTRY)
1887 return;
1888 // FIXME
1889 slot->name = strdup (method->name);
1890 // This was already strduped in _Jv_JNI_RegisterNatives.
1891 slot->signature = method->signature;
1892 slot->fnPtr = method->fnPtr;
1895 static jint JNICALL
1896 _Jv_JNI_RegisterNatives (JNIEnv *env, jclass klass,
1897 const JNINativeMethod *methods,
1898 jint nMethods)
1900 // Synchronize while we do the work. This must match
1901 // synchronization in some other functions that manipulate or use
1902 // the nathash table.
1903 JvSynchronize sync (global_ref_table);
1905 JNINativeMethod dottedMethod;
1907 // Look at each descriptor given us, and find the corresponding
1908 // method in the class.
1909 for (int j = 0; j < nMethods; ++j)
1911 bool found = false;
1913 _Jv_Method *imeths = JvGetFirstMethod (klass);
1914 for (int i = 0; i < JvNumMethods (klass); ++i)
1916 _Jv_Method *self = &imeths[i];
1918 // Copy this JNINativeMethod and do a slash to dot
1919 // conversion on the signature.
1920 dottedMethod.name = methods[j].name;
1921 dottedMethod.signature = strdup (methods[j].signature);
1922 dottedMethod.fnPtr = methods[j].fnPtr;
1923 char *c = dottedMethod.signature;
1924 while (*c)
1926 if (*c == '/')
1927 *c = '.';
1928 c++;
1931 if (! strcmp (self->name->chars (), dottedMethod.name)
1932 && ! strcmp (self->signature->chars (), dottedMethod.signature))
1934 if (! (self->accflags & java::lang::reflect::Modifier::NATIVE))
1935 break;
1937 // Found a match that is native.
1938 found = true;
1939 nathash_add (&dottedMethod);
1941 break;
1945 if (! found)
1947 jstring m = JvNewStringUTF (methods[j].name);
1950 env->ex = new java::lang::NoSuchMethodError (m);
1952 catch (jthrowable t)
1954 env->ex = t;
1956 return JNI_ERR;
1960 return JNI_OK;
1963 static jint JNICALL
1964 _Jv_JNI_UnregisterNatives (JNIEnv *, jclass)
1966 // FIXME -- we could implement this.
1967 return JNI_ERR;
1972 // Add a character to the buffer, encoding properly.
1973 static void
1974 add_char (char *buf, jchar c, int *here)
1976 if (c == '_')
1978 buf[(*here)++] = '_';
1979 buf[(*here)++] = '1';
1981 else if (c == ';')
1983 buf[(*here)++] = '_';
1984 buf[(*here)++] = '2';
1986 else if (c == '[')
1988 buf[(*here)++] = '_';
1989 buf[(*here)++] = '3';
1992 // Also check for `.' here because we might be passed an internal
1993 // qualified class name like `foo.bar'.
1994 else if (c == '/' || c == '.')
1995 buf[(*here)++] = '_';
1996 else if ((c >= '0' && c <= '9')
1997 || (c >= 'a' && c <= 'z')
1998 || (c >= 'A' && c <= 'Z'))
1999 buf[(*here)++] = (char) c;
2000 else
2002 // "Unicode" character.
2003 buf[(*here)++] = '_';
2004 buf[(*here)++] = '0';
2005 for (int i = 0; i < 4; ++i)
2007 int val = c & 0x0f;
2008 buf[(*here) + 3 - i] = (val > 10) ? ('a' + val - 10) : ('0' + val);
2009 c >>= 4;
2011 *here += 4;
2015 // Compute a mangled name for a native function. This computes the
2016 // long name, and also returns an index which indicates where a NUL
2017 // can be placed to create the short name. This function assumes that
2018 // the buffer is large enough for its results.
2019 static void
2020 mangled_name (jclass klass, _Jv_Utf8Const *func_name,
2021 _Jv_Utf8Const *signature, char *buf, int *long_start)
2023 strcpy (buf, "Java_");
2024 int here = 5;
2026 // Add fully qualified class name.
2027 jchar *chars = _Jv_GetStringChars (klass->getName ());
2028 jint len = klass->getName ()->length ();
2029 for (int i = 0; i < len; ++i)
2030 add_char (buf, chars[i], &here);
2032 // Don't use add_char because we need a literal `_'.
2033 buf[here++] = '_';
2035 const unsigned char *fn = (const unsigned char *) func_name->chars ();
2036 const unsigned char *limit = fn + func_name->len ();
2037 for (int i = 0; ; ++i)
2039 int ch = UTF8_GET (fn, limit);
2040 if (ch < 0)
2041 break;
2042 add_char (buf, ch, &here);
2045 // This is where the long signature begins.
2046 *long_start = here;
2047 buf[here++] = '_';
2048 buf[here++] = '_';
2050 const unsigned char *sig = (const unsigned char *) signature->chars ();
2051 limit = sig + signature->len ();
2052 JvAssert (sig[0] == '(');
2053 ++sig;
2054 while (1)
2056 int ch = UTF8_GET (sig, limit);
2057 if (ch == ')' || ch < 0)
2058 break;
2059 add_char (buf, ch, &here);
2062 buf[here] = '\0';
2065 // Return the current thread's JNIEnv; if one does not exist, create
2066 // it. Also create a new system frame for use. This is `extern "C"'
2067 // because the compiler calls it.
2068 extern "C" JNIEnv *
2069 _Jv_GetJNIEnvNewFrame (jclass klass)
2071 JNIEnv *env = _Jv_GetCurrentJNIEnv ();
2072 if (__builtin_expect (env == NULL, false))
2074 env = (JNIEnv *) _Jv_MallocUnchecked (sizeof (JNIEnv));
2075 env->p = &_Jv_JNIFunctions;
2076 env->klass = klass;
2077 env->locals = NULL;
2078 // We set env->ex below.
2080 // Set up the bottom, reusable frame.
2081 env->bottom_locals = (_Jv_JNI_LocalFrame *)
2082 _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame)
2083 + (FRAME_SIZE
2084 * sizeof (jobject)));
2086 env->bottom_locals->marker = MARK_SYSTEM;
2087 env->bottom_locals->size = FRAME_SIZE;
2088 env->bottom_locals->next = NULL;
2089 env->bottom_locals->allocated_p = 0;
2090 memset (&env->bottom_locals->vec[0], 0,
2091 env->bottom_locals->size * sizeof (jobject));
2093 _Jv_SetCurrentJNIEnv (env);
2096 // If we're in a simple JNI call (non-nested), we can just reuse the
2097 // locals frame we allocated many calls ago, back when the env was first
2098 // built, above.
2100 if (__builtin_expect (env->locals == NULL, true))
2101 env->locals = env->bottom_locals;
2103 else
2105 // Alternatively, we might be re-entering JNI, in which case we can't
2106 // reuse the bottom_locals frame, because it is already underneath
2107 // us. So we need to make a new one.
2109 _Jv_JNI_LocalFrame *frame
2110 = (_Jv_JNI_LocalFrame *) _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame)
2111 + (FRAME_SIZE
2112 * sizeof (jobject)));
2114 frame->marker = MARK_SYSTEM;
2115 frame->size = FRAME_SIZE;
2116 frame->allocated_p = 0;
2117 frame->next = env->locals;
2119 memset (&frame->vec[0], 0,
2120 frame->size * sizeof (jobject));
2122 env->locals = frame;
2125 env->ex = NULL;
2127 return env;
2130 // Destroy the env's reusable resources. This is called from the thread
2131 // destructor "finalize_native" in natThread.cc
2132 void
2133 _Jv_FreeJNIEnv (_Jv_JNIEnv *env)
2135 if (env == NULL)
2136 return;
2138 if (env->bottom_locals != NULL)
2139 _Jv_Free (env->bottom_locals);
2141 _Jv_Free (env);
2144 // Return the function which implements a particular JNI method. If
2145 // we can't find the function, we throw the appropriate exception.
2146 // This is `extern "C"' because the compiler uses it.
2147 extern "C" void *
2148 _Jv_LookupJNIMethod (jclass klass, _Jv_Utf8Const *name,
2149 _Jv_Utf8Const *signature, MAYBE_UNUSED int args_size)
2151 int name_length = name->len();
2152 int sig_length = signature->len();
2153 char buf[10 + 6 * (name_length + sig_length) + 12];
2154 int long_start;
2155 void *function;
2157 // Synchronize on something convenient. Right now we use the hash.
2158 JvSynchronize sync (global_ref_table);
2160 // First see if we have an override in the hash table.
2161 strncpy (buf, name->chars (), name_length);
2162 buf[name_length] = '\0';
2163 strncpy (buf + name_length + 1, signature->chars (), sig_length);
2164 buf[name_length + sig_length + 1] = '\0';
2165 JNINativeMethod meth;
2166 meth.name = buf;
2167 meth.signature = buf + name_length + 1;
2168 function = nathash_find (&meth);
2169 if (function != NULL)
2170 return function;
2172 // If there was no override, then look in the symbol table.
2173 buf[0] = '_';
2174 mangled_name (klass, name, signature, buf + 1, &long_start);
2175 char c = buf[long_start + 1];
2176 buf[long_start + 1] = '\0';
2178 function = _Jv_FindSymbolInExecutable (buf + 1);
2179 #ifdef WIN32
2180 // On Win32, we use the "stdcall" calling convention (see JNICALL
2181 // in jni.h).
2183 // For a function named 'fooBar' that takes 'nn' bytes as arguments,
2184 // by default, MinGW GCC exports it as 'fooBar@nn', MSVC exports it
2185 // as '_fooBar@nn' and Borland C exports it as 'fooBar'. We try to
2186 // take care of all these variations here.
2188 char asz_buf[12]; /* '@' + '2147483647' (32-bit INT_MAX) + '\0' */
2189 char long_nm_sv[11]; /* Ditto, except for the '\0'. */
2191 if (function == NULL)
2193 // We have tried searching for the 'fooBar' form (BCC) - now
2194 // try the others.
2196 // First, save the part of the long name that will be damaged
2197 // by appending '@nn'.
2198 memcpy (long_nm_sv, (buf + long_start + 1 + 1), sizeof (long_nm_sv));
2200 sprintf (asz_buf, "@%d", args_size);
2201 strcat (buf, asz_buf);
2203 // Search for the '_fooBar@nn' form (MSVC).
2204 function = _Jv_FindSymbolInExecutable (buf);
2206 if (function == NULL)
2208 // Search for the 'fooBar@nn' form (MinGW GCC).
2209 function = _Jv_FindSymbolInExecutable (buf + 1);
2212 #endif /* WIN32 */
2214 if (function == NULL)
2216 buf[long_start + 1] = c;
2217 #ifdef WIN32
2218 // Restore the part of the long name that was damaged by
2219 // appending the '@nn'.
2220 memcpy ((buf + long_start + 1 + 1), long_nm_sv, sizeof (long_nm_sv));
2221 #endif /* WIN32 */
2222 function = _Jv_FindSymbolInExecutable (buf + 1);
2223 if (function == NULL)
2225 #ifdef WIN32
2226 strcat (buf, asz_buf);
2227 function = _Jv_FindSymbolInExecutable (buf);
2228 if (function == NULL)
2229 function = _Jv_FindSymbolInExecutable (buf + 1);
2231 if (function == NULL)
2232 #endif /* WIN32 */
2234 jstring str = JvNewStringUTF (name->chars ());
2235 throw new java::lang::UnsatisfiedLinkError (str);
2240 return function;
2243 #ifdef INTERPRETER
2245 // This function is the stub which is used to turn an ordinary (CNI)
2246 // method call into a JNI call.
2247 void
2248 _Jv_JNIMethod::call (ffi_cif *, void *ret, ffi_raw *args, void *__this)
2250 _Jv_JNIMethod* _this = (_Jv_JNIMethod *) __this;
2252 JNIEnv *env = _Jv_GetJNIEnvNewFrame (_this->defining_class);
2254 // FIXME: we should mark every reference parameter as a local. For
2255 // now we assume a conservative GC, and we assume that the
2256 // references are on the stack somewhere.
2258 // We cache the value that we find, of course, but if we don't find
2259 // a value we don't cache that fact -- we might subsequently load a
2260 // library which finds the function in question.
2262 // Synchronize on a convenient object to ensure sanity in case two
2263 // threads reach this point for the same function at the same
2264 // time.
2265 JvSynchronize sync (global_ref_table);
2266 if (_this->function == NULL)
2268 int args_size = sizeof (JNIEnv *) + _this->args_raw_size;
2270 if (_this->self->accflags & java::lang::reflect::Modifier::STATIC)
2271 args_size += sizeof (_this->defining_class);
2273 _this->function = _Jv_LookupJNIMethod (_this->defining_class,
2274 _this->self->name,
2275 _this->self->signature,
2276 args_size);
2280 JvAssert (_this->args_raw_size % sizeof (ffi_raw) == 0);
2281 ffi_raw real_args[2 + _this->args_raw_size / sizeof (ffi_raw)];
2282 int offset = 0;
2284 // First argument is always the environment pointer.
2285 real_args[offset++].ptr = env;
2287 // For a static method, we pass in the Class. For non-static
2288 // methods, the `this' argument is already handled.
2289 if ((_this->self->accflags & java::lang::reflect::Modifier::STATIC))
2290 real_args[offset++].ptr = _this->defining_class;
2292 // In libgcj, the callee synchronizes.
2293 jobject sync = NULL;
2294 if ((_this->self->accflags & java::lang::reflect::Modifier::SYNCHRONIZED))
2296 if ((_this->self->accflags & java::lang::reflect::Modifier::STATIC))
2297 sync = _this->defining_class;
2298 else
2299 sync = (jobject) args[0].ptr;
2300 _Jv_MonitorEnter (sync);
2303 // Copy over passed-in arguments.
2304 memcpy (&real_args[offset], args, _this->args_raw_size);
2306 // The actual call to the JNI function.
2307 #if FFI_NATIVE_RAW_API
2308 ffi_raw_call (&_this->jni_cif, (void (*)()) _this->function,
2309 ret, real_args);
2310 #else
2311 ffi_java_raw_call (&_this->jni_cif, (void (*)()) _this->function,
2312 ret, real_args);
2313 #endif
2315 // We might need to unwrap a JNI weak reference here.
2316 if (_this->jni_cif.rtype == &ffi_type_pointer)
2318 _Jv_value *val = (_Jv_value *) ret;
2319 val->object_value = unwrap (val->object_value);
2322 if (sync != NULL)
2323 _Jv_MonitorExit (sync);
2325 _Jv_JNI_PopSystemFrame (env);
2328 #endif /* INTERPRETER */
2333 // Invocation API.
2336 // An internal helper function.
2337 static jint
2338 _Jv_JNI_AttachCurrentThread (JavaVM *, jstring name, void **penv,
2339 void *args, jboolean is_daemon)
2341 JavaVMAttachArgs *attach = reinterpret_cast<JavaVMAttachArgs *> (args);
2342 java::lang::ThreadGroup *group = NULL;
2344 if (attach)
2346 // FIXME: do we really want to support 1.1?
2347 if (attach->version != JNI_VERSION_1_4
2348 && attach->version != JNI_VERSION_1_2
2349 && attach->version != JNI_VERSION_1_1)
2350 return JNI_EVERSION;
2352 JvAssert (java::lang::ThreadGroup::class$.isInstance (attach->group));
2353 group = reinterpret_cast<java::lang::ThreadGroup *> (attach->group);
2356 // Attaching an already-attached thread is a no-op.
2357 if (_Jv_GetCurrentJNIEnv () != NULL)
2358 return 0;
2360 JNIEnv *env = (JNIEnv *) _Jv_MallocUnchecked (sizeof (JNIEnv));
2361 if (env == NULL)
2362 return JNI_ERR;
2363 env->p = &_Jv_JNIFunctions;
2364 env->ex = NULL;
2365 env->klass = NULL;
2366 env->bottom_locals
2367 = (_Jv_JNI_LocalFrame *) _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame)
2368 + (FRAME_SIZE
2369 * sizeof (jobject)));
2370 env->locals = env->bottom_locals;
2371 if (env->locals == NULL)
2373 _Jv_Free (env);
2374 return JNI_ERR;
2377 env->locals->allocated_p = 0;
2378 env->locals->marker = MARK_SYSTEM;
2379 env->locals->size = FRAME_SIZE;
2380 env->locals->next = NULL;
2382 for (int i = 0; i < env->locals->size; ++i)
2383 env->locals->vec[i] = NULL;
2385 *penv = reinterpret_cast<void *> (env);
2387 // This thread might already be a Java thread -- this function might
2388 // have been called simply to set the new JNIEnv.
2389 if (_Jv_ThreadCurrent () == NULL)
2393 if (is_daemon)
2394 _Jv_AttachCurrentThreadAsDaemon (name, group);
2395 else
2396 _Jv_AttachCurrentThread (name, group);
2398 catch (jthrowable t)
2400 return JNI_ERR;
2403 _Jv_SetCurrentJNIEnv (env);
2405 return 0;
2408 // This is the one actually used by JNI.
2409 static jint JNICALL
2410 _Jv_JNI_AttachCurrentThread (JavaVM *vm, void **penv, void *args)
2412 return _Jv_JNI_AttachCurrentThread (vm, NULL, penv, args, false);
2415 static jint JNICALL
2416 _Jv_JNI_AttachCurrentThreadAsDaemon (JavaVM *vm, void **penv,
2417 void *args)
2419 return _Jv_JNI_AttachCurrentThread (vm, NULL, penv, args, true);
2422 static jint JNICALL
2423 _Jv_JNI_DestroyJavaVM (JavaVM *vm)
2425 JvAssert (the_vm && vm == the_vm);
2427 JNIEnv *env;
2428 if (_Jv_ThreadCurrent () != NULL)
2430 jstring main_name;
2431 // This sucks.
2434 main_name = JvNewStringLatin1 ("main");
2436 catch (jthrowable t)
2438 return JNI_ERR;
2441 jint r = _Jv_JNI_AttachCurrentThread (vm, main_name,
2442 reinterpret_cast<void **> (&env),
2443 NULL, false);
2444 if (r < 0)
2445 return r;
2447 else
2448 env = _Jv_GetCurrentJNIEnv ();
2450 _Jv_ThreadWait ();
2452 // Docs say that this always returns an error code.
2453 return JNI_ERR;
2456 jint JNICALL
2457 _Jv_JNI_DetachCurrentThread (JavaVM *)
2459 jint code = _Jv_DetachCurrentThread ();
2460 return code ? JNI_EDETACHED : 0;
2463 static jint JNICALL
2464 _Jv_JNI_GetEnv (JavaVM *, void **penv, jint version)
2466 if (_Jv_ThreadCurrent () == NULL)
2468 *penv = NULL;
2469 return JNI_EDETACHED;
2472 #ifdef ENABLE_JVMPI
2473 // Handle JVMPI requests.
2474 if (version == JVMPI_VERSION_1)
2476 *penv = (void *) &_Jv_JVMPI_Interface;
2477 return 0;
2479 #endif
2481 // FIXME: do we really want to support 1.1?
2482 if (version != JNI_VERSION_1_4 && version != JNI_VERSION_1_2
2483 && version != JNI_VERSION_1_1)
2485 *penv = NULL;
2486 return JNI_EVERSION;
2489 *penv = (void *) _Jv_GetCurrentJNIEnv ();
2490 return 0;
2493 jint JNICALL
2494 JNI_GetDefaultJavaVMInitArgs (void *args)
2496 jint version = * (jint *) args;
2497 // Here we only support 1.2 and 1.4.
2498 if (version != JNI_VERSION_1_2 && version != JNI_VERSION_1_4)
2499 return JNI_EVERSION;
2501 JavaVMInitArgs *ia = reinterpret_cast<JavaVMInitArgs *> (args);
2502 ia->version = JNI_VERSION_1_4;
2503 ia->nOptions = 0;
2504 ia->options = NULL;
2505 ia->ignoreUnrecognized = true;
2507 return 0;
2510 jint JNICALL
2511 JNI_CreateJavaVM (JavaVM **vm, void **penv, void *args)
2513 JvAssert (! the_vm);
2515 jint version = * (jint *) args;
2516 // We only support 1.2 and 1.4.
2517 if (version != JNI_VERSION_1_2 && version != JNI_VERSION_1_4)
2518 return JNI_EVERSION;
2520 JvVMInitArgs* vm_args = reinterpret_cast<JvVMInitArgs *> (args);
2522 jint result = _Jv_CreateJavaVM (vm_args);
2523 if (result)
2524 return result;
2526 // FIXME: synchronize
2527 JavaVM *nvm = (JavaVM *) _Jv_MallocUnchecked (sizeof (JavaVM));
2528 if (nvm == NULL)
2529 return JNI_ERR;
2530 nvm->functions = &_Jv_JNI_InvokeFunctions;
2532 jint r =_Jv_JNI_AttachCurrentThread (nvm, penv, NULL);
2533 if (r < 0)
2534 return r;
2536 the_vm = nvm;
2537 *vm = the_vm;
2539 return 0;
2542 jint JNICALL
2543 JNI_GetCreatedJavaVMs (JavaVM **vm_buffer, jsize buf_len, jsize *n_vms)
2545 if (buf_len <= 0)
2546 return JNI_ERR;
2548 // We only support a single VM.
2549 if (the_vm != NULL)
2551 vm_buffer[0] = the_vm;
2552 *n_vms = 1;
2554 else
2555 *n_vms = 0;
2556 return 0;
2559 JavaVM *
2560 _Jv_GetJavaVM ()
2562 // FIXME: synchronize
2563 if (! the_vm)
2565 JavaVM *nvm = (JavaVM *) _Jv_MallocUnchecked (sizeof (JavaVM));
2566 if (nvm != NULL)
2567 nvm->functions = &_Jv_JNI_InvokeFunctions;
2568 the_vm = nvm;
2571 // If this is a Java thread, we want to make sure it has an
2572 // associated JNIEnv.
2573 if (_Jv_ThreadCurrent () != NULL)
2575 void *ignore;
2576 _Jv_JNI_AttachCurrentThread (the_vm, &ignore, NULL);
2579 return the_vm;
2582 static jint JNICALL
2583 _Jv_JNI_GetJavaVM (JNIEnv *, JavaVM **vm)
2585 *vm = _Jv_GetJavaVM ();
2586 return *vm == NULL ? JNI_ERR : JNI_OK;
2591 #define RESERVED NULL
2593 struct JNINativeInterface _Jv_JNIFunctions =
2595 RESERVED,
2596 RESERVED,
2597 RESERVED,
2598 RESERVED,
2599 _Jv_JNI_GetVersion, // GetVersion
2600 _Jv_JNI_DefineClass, // DefineClass
2601 _Jv_JNI_FindClass, // FindClass
2602 _Jv_JNI_FromReflectedMethod, // FromReflectedMethod
2603 _Jv_JNI_FromReflectedField, // FromReflectedField
2604 _Jv_JNI_ToReflectedMethod, // ToReflectedMethod
2605 _Jv_JNI_GetSuperclass, // GetSuperclass
2606 _Jv_JNI_IsAssignableFrom, // IsAssignableFrom
2607 _Jv_JNI_ToReflectedField, // ToReflectedField
2608 _Jv_JNI_Throw, // Throw
2609 _Jv_JNI_ThrowNew, // ThrowNew
2610 _Jv_JNI_ExceptionOccurred, // ExceptionOccurred
2611 _Jv_JNI_ExceptionDescribe, // ExceptionDescribe
2612 _Jv_JNI_ExceptionClear, // ExceptionClear
2613 _Jv_JNI_FatalError, // FatalError
2615 _Jv_JNI_PushLocalFrame, // PushLocalFrame
2616 _Jv_JNI_PopLocalFrame, // PopLocalFrame
2617 _Jv_JNI_NewGlobalRef, // NewGlobalRef
2618 _Jv_JNI_DeleteGlobalRef, // DeleteGlobalRef
2619 _Jv_JNI_DeleteLocalRef, // DeleteLocalRef
2621 _Jv_JNI_IsSameObject, // IsSameObject
2623 _Jv_JNI_NewLocalRef, // NewLocalRef
2624 _Jv_JNI_EnsureLocalCapacity, // EnsureLocalCapacity
2626 _Jv_JNI_AllocObject, // AllocObject
2627 _Jv_JNI_NewObject, // NewObject
2628 _Jv_JNI_NewObjectV, // NewObjectV
2629 _Jv_JNI_NewObjectA, // NewObjectA
2630 _Jv_JNI_GetObjectClass, // GetObjectClass
2631 _Jv_JNI_IsInstanceOf, // IsInstanceOf
2632 _Jv_JNI_GetAnyMethodID<false>, // GetMethodID
2634 _Jv_JNI_CallMethod<jobject>, // CallObjectMethod
2635 _Jv_JNI_CallMethodV<jobject>, // CallObjectMethodV
2636 _Jv_JNI_CallMethodA<jobject>, // CallObjectMethodA
2637 _Jv_JNI_CallMethod<jboolean>, // CallBooleanMethod
2638 _Jv_JNI_CallMethodV<jboolean>, // CallBooleanMethodV
2639 _Jv_JNI_CallMethodA<jboolean>, // CallBooleanMethodA
2640 _Jv_JNI_CallMethod<jbyte>, // CallByteMethod
2641 _Jv_JNI_CallMethodV<jbyte>, // CallByteMethodV
2642 _Jv_JNI_CallMethodA<jbyte>, // CallByteMethodA
2643 _Jv_JNI_CallMethod<jchar>, // CallCharMethod
2644 _Jv_JNI_CallMethodV<jchar>, // CallCharMethodV
2645 _Jv_JNI_CallMethodA<jchar>, // CallCharMethodA
2646 _Jv_JNI_CallMethod<jshort>, // CallShortMethod
2647 _Jv_JNI_CallMethodV<jshort>, // CallShortMethodV
2648 _Jv_JNI_CallMethodA<jshort>, // CallShortMethodA
2649 _Jv_JNI_CallMethod<jint>, // CallIntMethod
2650 _Jv_JNI_CallMethodV<jint>, // CallIntMethodV
2651 _Jv_JNI_CallMethodA<jint>, // CallIntMethodA
2652 _Jv_JNI_CallMethod<jlong>, // CallLongMethod
2653 _Jv_JNI_CallMethodV<jlong>, // CallLongMethodV
2654 _Jv_JNI_CallMethodA<jlong>, // CallLongMethodA
2655 _Jv_JNI_CallMethod<jfloat>, // CallFloatMethod
2656 _Jv_JNI_CallMethodV<jfloat>, // CallFloatMethodV
2657 _Jv_JNI_CallMethodA<jfloat>, // CallFloatMethodA
2658 _Jv_JNI_CallMethod<jdouble>, // CallDoubleMethod
2659 _Jv_JNI_CallMethodV<jdouble>, // CallDoubleMethodV
2660 _Jv_JNI_CallMethodA<jdouble>, // CallDoubleMethodA
2661 _Jv_JNI_CallVoidMethod, // CallVoidMethod
2662 _Jv_JNI_CallVoidMethodV, // CallVoidMethodV
2663 _Jv_JNI_CallVoidMethodA, // CallVoidMethodA
2665 // Nonvirtual method invocation functions follow.
2666 _Jv_JNI_CallAnyMethod<jobject, nonvirtual>, // CallNonvirtualObjectMethod
2667 _Jv_JNI_CallAnyMethodV<jobject, nonvirtual>, // CallNonvirtualObjectMethodV
2668 _Jv_JNI_CallAnyMethodA<jobject, nonvirtual>, // CallNonvirtualObjectMethodA
2669 _Jv_JNI_CallAnyMethod<jboolean, nonvirtual>, // CallNonvirtualBooleanMethod
2670 _Jv_JNI_CallAnyMethodV<jboolean, nonvirtual>, // CallNonvirtualBooleanMethodV
2671 _Jv_JNI_CallAnyMethodA<jboolean, nonvirtual>, // CallNonvirtualBooleanMethodA
2672 _Jv_JNI_CallAnyMethod<jbyte, nonvirtual>, // CallNonvirtualByteMethod
2673 _Jv_JNI_CallAnyMethodV<jbyte, nonvirtual>, // CallNonvirtualByteMethodV
2674 _Jv_JNI_CallAnyMethodA<jbyte, nonvirtual>, // CallNonvirtualByteMethodA
2675 _Jv_JNI_CallAnyMethod<jchar, nonvirtual>, // CallNonvirtualCharMethod
2676 _Jv_JNI_CallAnyMethodV<jchar, nonvirtual>, // CallNonvirtualCharMethodV
2677 _Jv_JNI_CallAnyMethodA<jchar, nonvirtual>, // CallNonvirtualCharMethodA
2678 _Jv_JNI_CallAnyMethod<jshort, nonvirtual>, // CallNonvirtualShortMethod
2679 _Jv_JNI_CallAnyMethodV<jshort, nonvirtual>, // CallNonvirtualShortMethodV
2680 _Jv_JNI_CallAnyMethodA<jshort, nonvirtual>, // CallNonvirtualShortMethodA
2681 _Jv_JNI_CallAnyMethod<jint, nonvirtual>, // CallNonvirtualIntMethod
2682 _Jv_JNI_CallAnyMethodV<jint, nonvirtual>, // CallNonvirtualIntMethodV
2683 _Jv_JNI_CallAnyMethodA<jint, nonvirtual>, // CallNonvirtualIntMethodA
2684 _Jv_JNI_CallAnyMethod<jlong, nonvirtual>, // CallNonvirtualLongMethod
2685 _Jv_JNI_CallAnyMethodV<jlong, nonvirtual>, // CallNonvirtualLongMethodV
2686 _Jv_JNI_CallAnyMethodA<jlong, nonvirtual>, // CallNonvirtualLongMethodA
2687 _Jv_JNI_CallAnyMethod<jfloat, nonvirtual>, // CallNonvirtualFloatMethod
2688 _Jv_JNI_CallAnyMethodV<jfloat, nonvirtual>, // CallNonvirtualFloatMethodV
2689 _Jv_JNI_CallAnyMethodA<jfloat, nonvirtual>, // CallNonvirtualFloatMethodA
2690 _Jv_JNI_CallAnyMethod<jdouble, nonvirtual>, // CallNonvirtualDoubleMethod
2691 _Jv_JNI_CallAnyMethodV<jdouble, nonvirtual>, // CallNonvirtualDoubleMethodV
2692 _Jv_JNI_CallAnyMethodA<jdouble, nonvirtual>, // CallNonvirtualDoubleMethodA
2693 _Jv_JNI_CallAnyVoidMethod<nonvirtual>, // CallNonvirtualVoidMethod
2694 _Jv_JNI_CallAnyVoidMethodV<nonvirtual>, // CallNonvirtualVoidMethodV
2695 _Jv_JNI_CallAnyVoidMethodA<nonvirtual>, // CallNonvirtualVoidMethodA
2697 _Jv_JNI_GetAnyFieldID<false>, // GetFieldID
2698 _Jv_JNI_GetField<jobject>, // GetObjectField
2699 _Jv_JNI_GetField<jboolean>, // GetBooleanField
2700 _Jv_JNI_GetField<jbyte>, // GetByteField
2701 _Jv_JNI_GetField<jchar>, // GetCharField
2702 _Jv_JNI_GetField<jshort>, // GetShortField
2703 _Jv_JNI_GetField<jint>, // GetIntField
2704 _Jv_JNI_GetField<jlong>, // GetLongField
2705 _Jv_JNI_GetField<jfloat>, // GetFloatField
2706 _Jv_JNI_GetField<jdouble>, // GetDoubleField
2707 _Jv_JNI_SetField, // SetObjectField
2708 _Jv_JNI_SetField, // SetBooleanField
2709 _Jv_JNI_SetField, // SetByteField
2710 _Jv_JNI_SetField, // SetCharField
2711 _Jv_JNI_SetField, // SetShortField
2712 _Jv_JNI_SetField, // SetIntField
2713 _Jv_JNI_SetField, // SetLongField
2714 _Jv_JNI_SetField, // SetFloatField
2715 _Jv_JNI_SetField, // SetDoubleField
2716 _Jv_JNI_GetAnyMethodID<true>, // GetStaticMethodID
2718 _Jv_JNI_CallStaticMethod<jobject>, // CallStaticObjectMethod
2719 _Jv_JNI_CallStaticMethodV<jobject>, // CallStaticObjectMethodV
2720 _Jv_JNI_CallStaticMethodA<jobject>, // CallStaticObjectMethodA
2721 _Jv_JNI_CallStaticMethod<jboolean>, // CallStaticBooleanMethod
2722 _Jv_JNI_CallStaticMethodV<jboolean>, // CallStaticBooleanMethodV
2723 _Jv_JNI_CallStaticMethodA<jboolean>, // CallStaticBooleanMethodA
2724 _Jv_JNI_CallStaticMethod<jbyte>, // CallStaticByteMethod
2725 _Jv_JNI_CallStaticMethodV<jbyte>, // CallStaticByteMethodV
2726 _Jv_JNI_CallStaticMethodA<jbyte>, // CallStaticByteMethodA
2727 _Jv_JNI_CallStaticMethod<jchar>, // CallStaticCharMethod
2728 _Jv_JNI_CallStaticMethodV<jchar>, // CallStaticCharMethodV
2729 _Jv_JNI_CallStaticMethodA<jchar>, // CallStaticCharMethodA
2730 _Jv_JNI_CallStaticMethod<jshort>, // CallStaticShortMethod
2731 _Jv_JNI_CallStaticMethodV<jshort>, // CallStaticShortMethodV
2732 _Jv_JNI_CallStaticMethodA<jshort>, // CallStaticShortMethodA
2733 _Jv_JNI_CallStaticMethod<jint>, // CallStaticIntMethod
2734 _Jv_JNI_CallStaticMethodV<jint>, // CallStaticIntMethodV
2735 _Jv_JNI_CallStaticMethodA<jint>, // CallStaticIntMethodA
2736 _Jv_JNI_CallStaticMethod<jlong>, // CallStaticLongMethod
2737 _Jv_JNI_CallStaticMethodV<jlong>, // CallStaticLongMethodV
2738 _Jv_JNI_CallStaticMethodA<jlong>, // CallStaticLongMethodA
2739 _Jv_JNI_CallStaticMethod<jfloat>, // CallStaticFloatMethod
2740 _Jv_JNI_CallStaticMethodV<jfloat>, // CallStaticFloatMethodV
2741 _Jv_JNI_CallStaticMethodA<jfloat>, // CallStaticFloatMethodA
2742 _Jv_JNI_CallStaticMethod<jdouble>, // CallStaticDoubleMethod
2743 _Jv_JNI_CallStaticMethodV<jdouble>, // CallStaticDoubleMethodV
2744 _Jv_JNI_CallStaticMethodA<jdouble>, // CallStaticDoubleMethodA
2745 _Jv_JNI_CallStaticVoidMethod, // CallStaticVoidMethod
2746 _Jv_JNI_CallStaticVoidMethodV, // CallStaticVoidMethodV
2747 _Jv_JNI_CallStaticVoidMethodA, // CallStaticVoidMethodA
2749 _Jv_JNI_GetAnyFieldID<true>, // GetStaticFieldID
2750 _Jv_JNI_GetStaticField<jobject>, // GetStaticObjectField
2751 _Jv_JNI_GetStaticField<jboolean>, // GetStaticBooleanField
2752 _Jv_JNI_GetStaticField<jbyte>, // GetStaticByteField
2753 _Jv_JNI_GetStaticField<jchar>, // GetStaticCharField
2754 _Jv_JNI_GetStaticField<jshort>, // GetStaticShortField
2755 _Jv_JNI_GetStaticField<jint>, // GetStaticIntField
2756 _Jv_JNI_GetStaticField<jlong>, // GetStaticLongField
2757 _Jv_JNI_GetStaticField<jfloat>, // GetStaticFloatField
2758 _Jv_JNI_GetStaticField<jdouble>, // GetStaticDoubleField
2759 _Jv_JNI_SetStaticField, // SetStaticObjectField
2760 _Jv_JNI_SetStaticField, // SetStaticBooleanField
2761 _Jv_JNI_SetStaticField, // SetStaticByteField
2762 _Jv_JNI_SetStaticField, // SetStaticCharField
2763 _Jv_JNI_SetStaticField, // SetStaticShortField
2764 _Jv_JNI_SetStaticField, // SetStaticIntField
2765 _Jv_JNI_SetStaticField, // SetStaticLongField
2766 _Jv_JNI_SetStaticField, // SetStaticFloatField
2767 _Jv_JNI_SetStaticField, // SetStaticDoubleField
2768 _Jv_JNI_NewString, // NewString
2769 _Jv_JNI_GetStringLength, // GetStringLength
2770 _Jv_JNI_GetStringChars, // GetStringChars
2771 _Jv_JNI_ReleaseStringChars, // ReleaseStringChars
2772 _Jv_JNI_NewStringUTF, // NewStringUTF
2773 _Jv_JNI_GetStringUTFLength, // GetStringUTFLength
2774 _Jv_JNI_GetStringUTFChars, // GetStringUTFChars
2775 _Jv_JNI_ReleaseStringUTFChars, // ReleaseStringUTFChars
2776 _Jv_JNI_GetArrayLength, // GetArrayLength
2777 _Jv_JNI_NewObjectArray, // NewObjectArray
2778 _Jv_JNI_GetObjectArrayElement, // GetObjectArrayElement
2779 _Jv_JNI_SetObjectArrayElement, // SetObjectArrayElement
2780 _Jv_JNI_NewPrimitiveArray<jboolean, JvPrimClass (boolean)>,
2781 // NewBooleanArray
2782 _Jv_JNI_NewPrimitiveArray<jbyte, JvPrimClass (byte)>, // NewByteArray
2783 _Jv_JNI_NewPrimitiveArray<jchar, JvPrimClass (char)>, // NewCharArray
2784 _Jv_JNI_NewPrimitiveArray<jshort, JvPrimClass (short)>, // NewShortArray
2785 _Jv_JNI_NewPrimitiveArray<jint, JvPrimClass (int)>, // NewIntArray
2786 _Jv_JNI_NewPrimitiveArray<jlong, JvPrimClass (long)>, // NewLongArray
2787 _Jv_JNI_NewPrimitiveArray<jfloat, JvPrimClass (float)>, // NewFloatArray
2788 _Jv_JNI_NewPrimitiveArray<jdouble, JvPrimClass (double)>, // NewDoubleArray
2789 _Jv_JNI_GetPrimitiveArrayElements<jboolean, JvPrimClass (boolean)>,
2790 // GetBooleanArrayElements
2791 _Jv_JNI_GetPrimitiveArrayElements<jbyte, JvPrimClass (byte)>,
2792 // GetByteArrayElements
2793 _Jv_JNI_GetPrimitiveArrayElements<jchar, JvPrimClass (char)>,
2794 // GetCharArrayElements
2795 _Jv_JNI_GetPrimitiveArrayElements<jshort, JvPrimClass (short)>,
2796 // GetShortArrayElements
2797 _Jv_JNI_GetPrimitiveArrayElements<jint, JvPrimClass (int)>,
2798 // GetIntArrayElements
2799 _Jv_JNI_GetPrimitiveArrayElements<jlong, JvPrimClass (long)>,
2800 // GetLongArrayElements
2801 _Jv_JNI_GetPrimitiveArrayElements<jfloat, JvPrimClass (float)>,
2802 // GetFloatArrayElements
2803 _Jv_JNI_GetPrimitiveArrayElements<jdouble, JvPrimClass (double)>,
2804 // GetDoubleArrayElements
2805 _Jv_JNI_ReleasePrimitiveArrayElements<jboolean, JvPrimClass (boolean)>,
2806 // ReleaseBooleanArrayElements
2807 _Jv_JNI_ReleasePrimitiveArrayElements<jbyte, JvPrimClass (byte)>,
2808 // ReleaseByteArrayElements
2809 _Jv_JNI_ReleasePrimitiveArrayElements<jchar, JvPrimClass (char)>,
2810 // ReleaseCharArrayElements
2811 _Jv_JNI_ReleasePrimitiveArrayElements<jshort, JvPrimClass (short)>,
2812 // ReleaseShortArrayElements
2813 _Jv_JNI_ReleasePrimitiveArrayElements<jint, JvPrimClass (int)>,
2814 // ReleaseIntArrayElements
2815 _Jv_JNI_ReleasePrimitiveArrayElements<jlong, JvPrimClass (long)>,
2816 // ReleaseLongArrayElements
2817 _Jv_JNI_ReleasePrimitiveArrayElements<jfloat, JvPrimClass (float)>,
2818 // ReleaseFloatArrayElements
2819 _Jv_JNI_ReleasePrimitiveArrayElements<jdouble, JvPrimClass (double)>,
2820 // ReleaseDoubleArrayElements
2821 _Jv_JNI_GetPrimitiveArrayRegion<jboolean, JvPrimClass (boolean)>,
2822 // GetBooleanArrayRegion
2823 _Jv_JNI_GetPrimitiveArrayRegion<jbyte, JvPrimClass (byte)>,
2824 // GetByteArrayRegion
2825 _Jv_JNI_GetPrimitiveArrayRegion<jchar, JvPrimClass (char)>,
2826 // GetCharArrayRegion
2827 _Jv_JNI_GetPrimitiveArrayRegion<jshort, JvPrimClass (short)>,
2828 // GetShortArrayRegion
2829 _Jv_JNI_GetPrimitiveArrayRegion<jint, JvPrimClass (int)>,
2830 // GetIntArrayRegion
2831 _Jv_JNI_GetPrimitiveArrayRegion<jlong, JvPrimClass (long)>,
2832 // GetLongArrayRegion
2833 _Jv_JNI_GetPrimitiveArrayRegion<jfloat, JvPrimClass (float)>,
2834 // GetFloatArrayRegion
2835 _Jv_JNI_GetPrimitiveArrayRegion<jdouble, JvPrimClass (double)>,
2836 // GetDoubleArrayRegion
2837 _Jv_JNI_SetPrimitiveArrayRegion<jboolean, JvPrimClass (boolean)>,
2838 // SetBooleanArrayRegion
2839 _Jv_JNI_SetPrimitiveArrayRegion<jbyte, JvPrimClass (byte)>,
2840 // SetByteArrayRegion
2841 _Jv_JNI_SetPrimitiveArrayRegion<jchar, JvPrimClass (char)>,
2842 // SetCharArrayRegion
2843 _Jv_JNI_SetPrimitiveArrayRegion<jshort, JvPrimClass (short)>,
2844 // SetShortArrayRegion
2845 _Jv_JNI_SetPrimitiveArrayRegion<jint, JvPrimClass (int)>,
2846 // SetIntArrayRegion
2847 _Jv_JNI_SetPrimitiveArrayRegion<jlong, JvPrimClass (long)>,
2848 // SetLongArrayRegion
2849 _Jv_JNI_SetPrimitiveArrayRegion<jfloat, JvPrimClass (float)>,
2850 // SetFloatArrayRegion
2851 _Jv_JNI_SetPrimitiveArrayRegion<jdouble, JvPrimClass (double)>,
2852 // SetDoubleArrayRegion
2853 _Jv_JNI_RegisterNatives, // RegisterNatives
2854 _Jv_JNI_UnregisterNatives, // UnregisterNatives
2855 _Jv_JNI_MonitorEnter, // MonitorEnter
2856 _Jv_JNI_MonitorExit, // MonitorExit
2857 _Jv_JNI_GetJavaVM, // GetJavaVM
2859 _Jv_JNI_GetStringRegion, // GetStringRegion
2860 _Jv_JNI_GetStringUTFRegion, // GetStringUTFRegion
2861 _Jv_JNI_GetPrimitiveArrayCritical, // GetPrimitiveArrayCritical
2862 _Jv_JNI_ReleasePrimitiveArrayCritical, // ReleasePrimitiveArrayCritical
2863 _Jv_JNI_GetStringCritical, // GetStringCritical
2864 _Jv_JNI_ReleaseStringCritical, // ReleaseStringCritical
2866 _Jv_JNI_NewWeakGlobalRef, // NewWeakGlobalRef
2867 _Jv_JNI_DeleteWeakGlobalRef, // DeleteWeakGlobalRef
2869 _Jv_JNI_ExceptionCheck, // ExceptionCheck
2871 _Jv_JNI_NewDirectByteBuffer, // NewDirectByteBuffer
2872 _Jv_JNI_GetDirectBufferAddress, // GetDirectBufferAddress
2873 _Jv_JNI_GetDirectBufferCapacity // GetDirectBufferCapacity
2876 struct JNIInvokeInterface _Jv_JNI_InvokeFunctions =
2878 RESERVED,
2879 RESERVED,
2880 RESERVED,
2882 _Jv_JNI_DestroyJavaVM,
2883 _Jv_JNI_AttachCurrentThread,
2884 _Jv_JNI_DetachCurrentThread,
2885 _Jv_JNI_GetEnv,
2886 _Jv_JNI_AttachCurrentThreadAsDaemon