* arm.c (adjacent_mem_locations): Reject volatile memory refs.
[official-gcc.git] / libjava / jni.cc
blob5f9d5f79e719d50fba1d0b4df97d6382554251ee
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>
50 #include <gcj/method.h>
51 #include <gcj/field.h>
53 #include <java-interp.h>
54 #include <java-threads.h>
56 using namespace gcj;
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 16
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;
90 // Flag to indicate some locals were allocated.
91 int allocated_p;
93 // Number of elements in frame.
94 int size;
96 // Next frame in chain.
97 _Jv_JNI_LocalFrame *next;
99 // The elements. These are allocated using the C "struct hack".
100 jobject vec[0];
103 // This holds a reference count for all local references.
104 static java::util::IdentityHashMap *local_ref_table;
105 // This holds a reference count for all global references.
106 static java::util::IdentityHashMap *global_ref_table;
108 // The only VM.
109 static JavaVM *the_vm;
111 #ifdef ENABLE_JVMPI
112 // The only JVMPI interface description.
113 static JVMPI_Interface _Jv_JVMPI_Interface;
115 static jint
116 jvmpiEnableEvent (jint event_type, void *)
118 switch (event_type)
120 case JVMPI_EVENT_OBJECT_ALLOC:
121 _Jv_JVMPI_Notify_OBJECT_ALLOC = _Jv_JVMPI_Interface.NotifyEvent;
122 break;
124 case JVMPI_EVENT_THREAD_START:
125 _Jv_JVMPI_Notify_THREAD_START = _Jv_JVMPI_Interface.NotifyEvent;
126 break;
128 case JVMPI_EVENT_THREAD_END:
129 _Jv_JVMPI_Notify_THREAD_END = _Jv_JVMPI_Interface.NotifyEvent;
130 break;
132 default:
133 return JVMPI_NOT_AVAILABLE;
136 return JVMPI_SUCCESS;
139 static jint
140 jvmpiDisableEvent (jint event_type, void *)
142 switch (event_type)
144 case JVMPI_EVENT_OBJECT_ALLOC:
145 _Jv_JVMPI_Notify_OBJECT_ALLOC = NULL;
146 break;
148 default:
149 return JVMPI_NOT_AVAILABLE;
152 return JVMPI_SUCCESS;
154 #endif
158 void
159 _Jv_JNI_Init (void)
161 local_ref_table = new java::util::IdentityHashMap;
162 global_ref_table = new java::util::IdentityHashMap;
164 #ifdef ENABLE_JVMPI
165 _Jv_JVMPI_Interface.version = 1;
166 _Jv_JVMPI_Interface.EnableEvent = &jvmpiEnableEvent;
167 _Jv_JVMPI_Interface.DisableEvent = &jvmpiDisableEvent;
168 _Jv_JVMPI_Interface.EnableGC = &_Jv_EnableGC;
169 _Jv_JVMPI_Interface.DisableGC = &_Jv_DisableGC;
170 _Jv_JVMPI_Interface.RunGC = &_Jv_RunGC;
171 #endif
174 // Tell the GC that a certain pointer is live.
175 static void
176 mark_for_gc (jobject obj, java::util::IdentityHashMap *ref_table)
178 JvSynchronize sync (ref_table);
180 using namespace java::lang;
181 Integer *refcount = (Integer *) ref_table->get (obj);
182 jint val = (refcount == NULL) ? 0 : refcount->intValue ();
183 // FIXME: what about out of memory error?
184 ref_table->put (obj, new Integer (val + 1));
187 // Unmark a pointer.
188 static void
189 unmark_for_gc (jobject obj, java::util::IdentityHashMap *ref_table)
191 JvSynchronize sync (ref_table);
193 using namespace java::lang;
194 Integer *refcount = (Integer *) ref_table->get (obj);
195 JvAssert (refcount);
196 jint val = refcount->intValue () - 1;
197 JvAssert (val >= 0);
198 if (val == 0)
199 ref_table->remove (obj);
200 else
201 // FIXME: what about out of memory error?
202 ref_table->put (obj, new Integer (val));
205 // "Unwrap" some random non-reference type. This exists to simplify
206 // other template functions.
207 template<typename T>
208 static T
209 unwrap (T val)
211 return val;
214 // Unwrap a weak reference, if required.
215 template<typename T>
216 static T *
217 unwrap (T *obj)
219 using namespace gnu::gcj::runtime;
220 // We can compare the class directly because JNIWeakRef is `final'.
221 // Doing it this way is much faster.
222 if (obj == NULL || obj->getClass () != &JNIWeakRef::class$)
223 return obj;
224 JNIWeakRef *wr = reinterpret_cast<JNIWeakRef *> (obj);
225 return reinterpret_cast<T *> (wr->get ());
230 static jobject JNICALL
231 _Jv_JNI_NewGlobalRef (JNIEnv *, jobject obj)
233 // This seems weird but I think it is correct.
234 obj = unwrap (obj);
235 mark_for_gc (obj, global_ref_table);
236 return obj;
239 static void JNICALL
240 _Jv_JNI_DeleteGlobalRef (JNIEnv *, jobject obj)
242 // This seems weird but I think it is correct.
243 obj = unwrap (obj);
244 unmark_for_gc (obj, global_ref_table);
247 static void JNICALL
248 _Jv_JNI_DeleteLocalRef (JNIEnv *env, jobject obj)
250 _Jv_JNI_LocalFrame *frame;
252 // This seems weird but I think it is correct.
253 obj = unwrap (obj);
255 for (frame = env->locals; frame != NULL; frame = frame->next)
257 for (int i = 0; i < frame->size; ++i)
259 if (frame->vec[i] == obj)
261 frame->vec[i] = NULL;
262 unmark_for_gc (obj, local_ref_table);
263 return;
267 // Don't go past a marked frame.
268 JvAssert (frame->marker == MARK_NONE);
271 JvAssert (0);
274 static jint JNICALL
275 _Jv_JNI_EnsureLocalCapacity (JNIEnv *env, jint size)
277 // It is easier to just always allocate a new frame of the requested
278 // size. This isn't the most efficient thing, but for now we don't
279 // care. Note that _Jv_JNI_PushLocalFrame relies on this right now.
281 _Jv_JNI_LocalFrame *frame;
284 frame = (_Jv_JNI_LocalFrame *) _Jv_Malloc (sizeof (_Jv_JNI_LocalFrame)
285 + size * sizeof (jobject));
287 catch (jthrowable t)
289 env->ex = t;
290 return JNI_ERR;
293 frame->marker = MARK_NONE;
294 frame->size = size;
295 frame->allocated_p = 0;
296 memset (&frame->vec[0], 0, size * sizeof (jobject));
297 frame->next = env->locals;
298 env->locals = frame;
300 return 0;
303 static jint JNICALL
304 _Jv_JNI_PushLocalFrame (JNIEnv *env, jint size)
306 jint r = _Jv_JNI_EnsureLocalCapacity (env, size);
307 if (r < 0)
308 return r;
310 // The new frame is on top.
311 env->locals->marker = MARK_USER;
313 return 0;
316 static jobject JNICALL
317 _Jv_JNI_NewLocalRef (JNIEnv *env, jobject obj)
319 // This seems weird but I think it is correct.
320 obj = unwrap (obj);
322 // Try to find an open slot somewhere in the topmost frame.
323 _Jv_JNI_LocalFrame *frame = env->locals;
324 bool done = false, set = false;
325 for (; frame != NULL && ! done; frame = frame->next)
327 for (int i = 0; i < frame->size; ++i)
329 if (frame->vec[i] == NULL)
331 set = true;
332 done = true;
333 frame->vec[i] = obj;
334 frame->allocated_p = 1;
335 break;
339 // If we found a slot, or if the frame we just searched is the
340 // mark frame, then we are done.
341 if (done || frame == NULL || frame->marker != MARK_NONE)
342 break;
345 if (! set)
347 // No slots, so we allocate a new frame. According to the spec
348 // we could just die here. FIXME: return value.
349 _Jv_JNI_EnsureLocalCapacity (env, 16);
350 // We know the first element of the new frame will be ok.
351 env->locals->vec[0] = obj;
352 env->locals->allocated_p = 1;
355 mark_for_gc (obj, local_ref_table);
356 return obj;
359 static jobject JNICALL
360 _Jv_JNI_PopLocalFrame (JNIEnv *env, jobject result, int stop)
362 _Jv_JNI_LocalFrame *rf = env->locals;
364 bool done = false;
365 while (rf != NULL && ! done)
367 for (int i = 0; i < rf->size; ++i)
368 if (rf->vec[i] != NULL)
369 unmark_for_gc (rf->vec[i], local_ref_table);
371 // If the frame we just freed is the marker frame, we are done.
372 done = (rf->marker == stop);
374 _Jv_JNI_LocalFrame *n = rf->next;
375 // When N==NULL, we've reached the reusable bottom_locals, and we must
376 // not free it. However, we must be sure to clear all its elements.
377 if (n == NULL)
379 if (rf->allocated_p)
380 memset (&rf->vec[0], 0, rf->size * sizeof (jobject));
381 rf->allocated_p = 0;
382 rf = NULL;
383 break;
386 _Jv_Free (rf);
387 rf = n;
390 // Update the local frame information.
391 env->locals = rf;
393 return result == NULL ? NULL : _Jv_JNI_NewLocalRef (env, result);
396 static jobject JNICALL
397 _Jv_JNI_PopLocalFrame (JNIEnv *env, jobject result)
399 return _Jv_JNI_PopLocalFrame (env, result, MARK_USER);
402 // Make sure an array's type is compatible with the type of the
403 // destination.
404 template<typename T>
405 static bool
406 _Jv_JNI_check_types (JNIEnv *env, JArray<T> *array, jclass K)
408 jclass klass = array->getClass()->getComponentType();
409 if (__builtin_expect (klass != K, false))
411 env->ex = new java::lang::IllegalAccessError ();
412 return false;
414 else
415 return true;
418 // Pop a `system' frame from the stack. This is `extern "C"' as it is
419 // used by the compiler.
420 extern "C" void
421 _Jv_JNI_PopSystemFrame (JNIEnv *env)
423 // Only enter slow path when we're not at the bottom, or there have been
424 // allocations. Usually this is false and we can just null out the locals
425 // field.
427 if (__builtin_expect ((env->locals->next
428 || env->locals->allocated_p), false))
429 _Jv_JNI_PopLocalFrame (env, NULL, MARK_SYSTEM);
430 else
431 env->locals = NULL;
433 if (__builtin_expect (env->ex != NULL, false))
435 jthrowable t = env->ex;
436 env->ex = NULL;
437 throw t;
441 template<typename T> T extract_from_jvalue(jvalue const & t);
442 template<> jboolean extract_from_jvalue(jvalue const & jv) { return jv.z; }
443 template<> jbyte extract_from_jvalue(jvalue const & jv) { return jv.b; }
444 template<> jchar extract_from_jvalue(jvalue const & jv) { return jv.c; }
445 template<> jshort extract_from_jvalue(jvalue const & jv) { return jv.s; }
446 template<> jint extract_from_jvalue(jvalue const & jv) { return jv.i; }
447 template<> jlong extract_from_jvalue(jvalue const & jv) { return jv.j; }
448 template<> jfloat extract_from_jvalue(jvalue const & jv) { return jv.f; }
449 template<> jdouble extract_from_jvalue(jvalue const & jv) { return jv.d; }
450 template<> jobject extract_from_jvalue(jvalue const & jv) { return jv.l; }
453 // This function is used from other template functions. It wraps the
454 // return value appropriately; we specialize it so that object returns
455 // are turned into local references.
456 template<typename T>
457 static T
458 wrap_value (JNIEnv *, T value)
460 return value;
463 // This specialization is used for jobject, jclass, jstring, jarray,
464 // etc.
465 template<typename R, typename T>
466 static T *
467 wrap_value (JNIEnv *env, T *value)
469 return (value == NULL
470 ? value
471 : (T *) _Jv_JNI_NewLocalRef (env, (jobject) value));
476 static jint JNICALL
477 _Jv_JNI_GetVersion (JNIEnv *)
479 return JNI_VERSION_1_4;
482 static jclass JNICALL
483 _Jv_JNI_DefineClass (JNIEnv *env, const char *name, jobject loader,
484 const jbyte *buf, jsize bufLen)
488 loader = unwrap (loader);
490 jstring sname = JvNewStringUTF (name);
491 jbyteArray bytes = JvNewByteArray (bufLen);
493 jbyte *elts = elements (bytes);
494 memcpy (elts, buf, bufLen * sizeof (jbyte));
496 java::lang::ClassLoader *l
497 = reinterpret_cast<java::lang::ClassLoader *> (loader);
499 jclass result = l->defineClass (sname, bytes, 0, bufLen);
500 return (jclass) wrap_value (env, result);
502 catch (jthrowable t)
504 env->ex = t;
505 return NULL;
509 static jclass JNICALL
510 _Jv_JNI_FindClass (JNIEnv *env, const char *name)
512 // FIXME: assume that NAME isn't too long.
513 int len = strlen (name);
514 char s[len + 1];
515 for (int i = 0; i <= len; ++i)
516 s[i] = (name[i] == '/') ? '.' : name[i];
518 jclass r = NULL;
521 // This might throw an out of memory exception.
522 jstring n = JvNewStringUTF (s);
524 java::lang::ClassLoader *loader = NULL;
525 if (env->klass != NULL)
526 loader = env->klass->getClassLoaderInternal ();
528 if (loader == NULL)
530 // FIXME: should use getBaseClassLoader, but we don't have that
531 // yet.
532 loader = java::lang::ClassLoader::getSystemClassLoader ();
535 r = loader->loadClass (n);
537 catch (jthrowable t)
539 env->ex = t;
542 return (jclass) wrap_value (env, r);
545 static jclass JNICALL
546 _Jv_JNI_GetSuperclass (JNIEnv *env, jclass clazz)
548 return (jclass) wrap_value (env, unwrap (clazz)->getSuperclass ());
551 static jboolean JNICALL
552 _Jv_JNI_IsAssignableFrom (JNIEnv *, jclass clazz1, jclass clazz2)
554 return unwrap (clazz1)->isAssignableFrom (unwrap (clazz2));
557 static jint JNICALL
558 _Jv_JNI_Throw (JNIEnv *env, jthrowable obj)
560 // We check in case the user did some funky cast.
561 obj = unwrap (obj);
562 JvAssert (obj != NULL && java::lang::Throwable::class$.isInstance (obj));
563 env->ex = obj;
564 return 0;
567 static jint JNICALL
568 _Jv_JNI_ThrowNew (JNIEnv *env, jclass clazz, const char *message)
570 using namespace java::lang::reflect;
572 clazz = unwrap (clazz);
573 JvAssert (java::lang::Throwable::class$.isAssignableFrom (clazz));
575 int r = JNI_OK;
578 JArray<jclass> *argtypes
579 = (JArray<jclass> *) JvNewObjectArray (1, &java::lang::Class::class$,
580 NULL);
582 jclass *elts = elements (argtypes);
583 elts[0] = &java::lang::String::class$;
585 Constructor *cons = clazz->getConstructor (argtypes);
587 jobjectArray values = JvNewObjectArray (1, &java::lang::String::class$,
588 NULL);
589 jobject *velts = elements (values);
590 velts[0] = JvNewStringUTF (message);
592 jobject obj = cons->newInstance (values);
594 env->ex = reinterpret_cast<jthrowable> (obj);
596 catch (jthrowable t)
598 env->ex = t;
599 r = JNI_ERR;
602 return r;
605 static jthrowable JNICALL
606 _Jv_JNI_ExceptionOccurred (JNIEnv *env)
608 return (jthrowable) wrap_value (env, env->ex);
611 static void JNICALL
612 _Jv_JNI_ExceptionDescribe (JNIEnv *env)
614 if (env->ex != NULL)
615 env->ex->printStackTrace();
618 static void JNICALL
619 _Jv_JNI_ExceptionClear (JNIEnv *env)
621 env->ex = NULL;
624 static jboolean JNICALL
625 _Jv_JNI_ExceptionCheck (JNIEnv *env)
627 return env->ex != NULL;
630 static void JNICALL
631 _Jv_JNI_FatalError (JNIEnv *, const char *message)
633 JvFail (message);
638 static jboolean JNICALL
639 _Jv_JNI_IsSameObject (JNIEnv *, jobject obj1, jobject obj2)
641 return unwrap (obj1) == unwrap (obj2);
644 static jobject JNICALL
645 _Jv_JNI_AllocObject (JNIEnv *env, jclass clazz)
647 jobject obj = NULL;
648 using namespace java::lang::reflect;
652 clazz = unwrap (clazz);
653 JvAssert (clazz && ! clazz->isArray ());
654 if (clazz->isInterface() || Modifier::isAbstract(clazz->getModifiers()))
655 env->ex = new java::lang::InstantiationException ();
656 else
657 obj = _Jv_AllocObject (clazz);
659 catch (jthrowable t)
661 env->ex = t;
664 return wrap_value (env, obj);
667 static jclass JNICALL
668 _Jv_JNI_GetObjectClass (JNIEnv *env, jobject obj)
670 obj = unwrap (obj);
671 JvAssert (obj);
672 return (jclass) wrap_value (env, obj->getClass());
675 static jboolean JNICALL
676 _Jv_JNI_IsInstanceOf (JNIEnv *, jobject obj, jclass clazz)
678 return unwrap (clazz)->isInstance(unwrap (obj));
684 // This section concerns method invocation.
687 template<jboolean is_static>
688 static jmethodID JNICALL
689 _Jv_JNI_GetAnyMethodID (JNIEnv *env, jclass clazz,
690 const char *name, const char *sig)
694 clazz = unwrap (clazz);
695 _Jv_InitClass (clazz);
697 _Jv_Utf8Const *name_u = _Jv_makeUtf8Const ((char *) name, -1);
699 // FIXME: assume that SIG isn't too long.
700 int len = strlen (sig);
701 char s[len + 1];
702 for (int i = 0; i <= len; ++i)
703 s[i] = (sig[i] == '/') ? '.' : sig[i];
704 _Jv_Utf8Const *sig_u = _Jv_makeUtf8Const ((char *) s, -1);
706 JvAssert (! clazz->isPrimitive());
708 using namespace java::lang::reflect;
710 while (clazz != NULL)
712 jint count = JvNumMethods (clazz);
713 jmethodID meth = JvGetFirstMethod (clazz);
715 for (jint i = 0; i < count; ++i)
717 if (((is_static && Modifier::isStatic (meth->accflags))
718 || (! is_static && ! Modifier::isStatic (meth->accflags)))
719 && _Jv_equalUtf8Consts (meth->name, name_u)
720 && _Jv_equalUtf8Consts (meth->signature, sig_u))
721 return meth;
723 meth = meth->getNextMethod();
726 clazz = clazz->getSuperclass ();
729 java::lang::StringBuffer *name_sig =
730 new java::lang::StringBuffer (JvNewStringUTF (name));
731 name_sig->append ((jchar) ' ')->append (JvNewStringUTF (s));
732 env->ex = new java::lang::NoSuchMethodError (name_sig->toString ());
734 catch (jthrowable t)
736 env->ex = t;
739 return NULL;
742 // This is a helper function which turns a va_list into an array of
743 // `jvalue's. It needs signature information in order to do its work.
744 // The array of values must already be allocated.
745 static void
746 array_from_valist (jvalue *values, JArray<jclass> *arg_types, va_list vargs)
748 jclass *arg_elts = elements (arg_types);
749 for (int i = 0; i < arg_types->length; ++i)
751 // Here we assume that sizeof(int) >= sizeof(jint), because we
752 // use `int' when decoding the varargs. Likewise for
753 // float, and double. Also we assume that sizeof(jlong) >=
754 // sizeof(int), i.e. that jlong values are not further
755 // promoted.
756 JvAssert (sizeof (int) >= sizeof (jint));
757 JvAssert (sizeof (jlong) >= sizeof (int));
758 JvAssert (sizeof (double) >= sizeof (jfloat));
759 JvAssert (sizeof (double) >= sizeof (jdouble));
760 if (arg_elts[i] == JvPrimClass (byte))
761 values[i].b = (jbyte) va_arg (vargs, int);
762 else if (arg_elts[i] == JvPrimClass (short))
763 values[i].s = (jshort) va_arg (vargs, int);
764 else if (arg_elts[i] == JvPrimClass (int))
765 values[i].i = (jint) va_arg (vargs, int);
766 else if (arg_elts[i] == JvPrimClass (long))
767 values[i].j = (jlong) va_arg (vargs, jlong);
768 else if (arg_elts[i] == JvPrimClass (float))
769 values[i].f = (jfloat) va_arg (vargs, double);
770 else if (arg_elts[i] == JvPrimClass (double))
771 values[i].d = (jdouble) va_arg (vargs, double);
772 else if (arg_elts[i] == JvPrimClass (boolean))
773 values[i].z = (jboolean) va_arg (vargs, int);
774 else if (arg_elts[i] == JvPrimClass (char))
775 values[i].c = (jchar) va_arg (vargs, int);
776 else
778 // An object.
779 values[i].l = unwrap (va_arg (vargs, jobject));
784 // This can call any sort of method: virtual, "nonvirtual", static, or
785 // constructor.
786 template<typename T, invocation_type style>
787 static T JNICALL
788 _Jv_JNI_CallAnyMethodV (JNIEnv *env, jobject obj, jclass klass,
789 jmethodID id, va_list vargs)
791 obj = unwrap (obj);
792 klass = unwrap (klass);
794 jclass decl_class = klass ? klass : obj->getClass ();
795 JvAssert (decl_class != NULL);
797 jclass return_type;
798 JArray<jclass> *arg_types;
802 _Jv_GetTypesFromSignature (id, decl_class,
803 &arg_types, &return_type);
805 jvalue args[arg_types->length];
806 array_from_valist (args, arg_types, vargs);
808 // For constructors we need to pass the Class we are instantiating.
809 if (style == constructor)
810 return_type = klass;
812 jvalue result;
813 _Jv_CallAnyMethodA (obj, return_type, id,
814 style == constructor,
815 style == normal,
816 arg_types, args, &result);
818 return wrap_value (env, extract_from_jvalue<T>(result));
820 catch (jthrowable t)
822 env->ex = t;
825 return wrap_value (env, (T) 0);
828 template<typename T, invocation_type style>
829 static T JNICALL
830 _Jv_JNI_CallAnyMethod (JNIEnv *env, jobject obj, jclass klass,
831 jmethodID method, ...)
833 va_list args;
834 T result;
836 va_start (args, method);
837 result = _Jv_JNI_CallAnyMethodV<T, style> (env, obj, klass, method, args);
838 va_end (args);
840 return result;
843 template<typename T, invocation_type style>
844 static T JNICALL
845 _Jv_JNI_CallAnyMethodA (JNIEnv *env, jobject obj, jclass klass,
846 jmethodID id, jvalue *args)
848 obj = unwrap (obj);
849 klass = unwrap (klass);
851 jclass decl_class = klass ? klass : obj->getClass ();
852 JvAssert (decl_class != NULL);
854 jclass return_type;
855 JArray<jclass> *arg_types;
858 _Jv_GetTypesFromSignature (id, decl_class,
859 &arg_types, &return_type);
861 // For constructors we need to pass the Class we are instantiating.
862 if (style == constructor)
863 return_type = klass;
865 // Unwrap arguments as required. Eww.
866 jclass *type_elts = elements (arg_types);
867 jvalue arg_copy[arg_types->length];
868 for (int i = 0; i < arg_types->length; ++i)
870 if (type_elts[i]->isPrimitive ())
871 arg_copy[i] = args[i];
872 else
873 arg_copy[i].l = unwrap (args[i].l);
876 jvalue result;
877 _Jv_CallAnyMethodA (obj, return_type, id,
878 style == constructor,
879 style == normal,
880 arg_types, arg_copy, &result);
882 return wrap_value (env, extract_from_jvalue<T>(result));
884 catch (jthrowable t)
886 env->ex = t;
889 return wrap_value (env, (T) 0);
892 template<invocation_type style>
893 static void JNICALL
894 _Jv_JNI_CallAnyVoidMethodV (JNIEnv *env, jobject obj, jclass klass,
895 jmethodID id, va_list vargs)
897 obj = unwrap (obj);
898 klass = unwrap (klass);
900 jclass decl_class = klass ? klass : obj->getClass ();
901 JvAssert (decl_class != NULL);
903 jclass return_type;
904 JArray<jclass> *arg_types;
907 _Jv_GetTypesFromSignature (id, decl_class,
908 &arg_types, &return_type);
910 jvalue args[arg_types->length];
911 array_from_valist (args, arg_types, vargs);
913 // For constructors we need to pass the Class we are instantiating.
914 if (style == constructor)
915 return_type = klass;
917 _Jv_CallAnyMethodA (obj, return_type, id,
918 style == constructor,
919 style == normal,
920 arg_types, args, NULL);
922 catch (jthrowable t)
924 env->ex = t;
928 template<invocation_type style>
929 static void JNICALL
930 _Jv_JNI_CallAnyVoidMethod (JNIEnv *env, jobject obj, jclass klass,
931 jmethodID method, ...)
933 va_list args;
935 va_start (args, method);
936 _Jv_JNI_CallAnyVoidMethodV<style> (env, obj, klass, method, args);
937 va_end (args);
940 template<invocation_type style>
941 static void JNICALL
942 _Jv_JNI_CallAnyVoidMethodA (JNIEnv *env, jobject obj, jclass klass,
943 jmethodID id, jvalue *args)
945 jclass decl_class = klass ? klass : obj->getClass ();
946 JvAssert (decl_class != NULL);
948 jclass return_type;
949 JArray<jclass> *arg_types;
952 _Jv_GetTypesFromSignature (id, decl_class,
953 &arg_types, &return_type);
955 // Unwrap arguments as required. Eww.
956 jclass *type_elts = elements (arg_types);
957 jvalue arg_copy[arg_types->length];
958 for (int i = 0; i < arg_types->length; ++i)
960 if (type_elts[i]->isPrimitive ())
961 arg_copy[i] = args[i];
962 else
963 arg_copy[i].l = unwrap (args[i].l);
966 _Jv_CallAnyMethodA (obj, return_type, id,
967 style == constructor,
968 style == normal,
969 arg_types, args, NULL);
971 catch (jthrowable t)
973 env->ex = t;
977 // Functions with this signature are used to implement functions in
978 // the CallMethod family.
979 template<typename T>
980 static T JNICALL
981 _Jv_JNI_CallMethodV (JNIEnv *env, jobject obj,
982 jmethodID id, va_list args)
984 return _Jv_JNI_CallAnyMethodV<T, normal> (env, obj, NULL, id, args);
987 // Functions with this signature are used to implement functions in
988 // the CallMethod family.
989 template<typename T>
990 static T JNICALL
991 _Jv_JNI_CallMethod (JNIEnv *env, jobject obj, jmethodID id, ...)
993 va_list args;
994 T result;
996 va_start (args, id);
997 result = _Jv_JNI_CallAnyMethodV<T, normal> (env, obj, NULL, id, args);
998 va_end (args);
1000 return result;
1003 // Functions with this signature are used to implement functions in
1004 // the CallMethod family.
1005 template<typename T>
1006 static T JNICALL
1007 _Jv_JNI_CallMethodA (JNIEnv *env, jobject obj,
1008 jmethodID id, jvalue *args)
1010 return _Jv_JNI_CallAnyMethodA<T, normal> (env, obj, NULL, id, args);
1013 static void JNICALL
1014 _Jv_JNI_CallVoidMethodV (JNIEnv *env, jobject obj,
1015 jmethodID id, va_list args)
1017 _Jv_JNI_CallAnyVoidMethodV<normal> (env, obj, NULL, id, args);
1020 static void JNICALL
1021 _Jv_JNI_CallVoidMethod (JNIEnv *env, jobject obj, jmethodID id, ...)
1023 va_list args;
1025 va_start (args, id);
1026 _Jv_JNI_CallAnyVoidMethodV<normal> (env, obj, NULL, id, args);
1027 va_end (args);
1030 static void JNICALL
1031 _Jv_JNI_CallVoidMethodA (JNIEnv *env, jobject obj,
1032 jmethodID id, jvalue *args)
1034 _Jv_JNI_CallAnyVoidMethodA<normal> (env, obj, NULL, id, args);
1037 // Functions with this signature are used to implement functions in
1038 // the CallStaticMethod family.
1039 template<typename T>
1040 static T JNICALL
1041 _Jv_JNI_CallStaticMethodV (JNIEnv *env, jclass klass,
1042 jmethodID id, va_list args)
1044 JvAssert (((id->accflags) & java::lang::reflect::Modifier::STATIC));
1045 JvAssert (java::lang::Class::class$.isInstance (unwrap (klass)));
1047 return _Jv_JNI_CallAnyMethodV<T, static_type> (env, NULL, klass, id, args);
1050 // Functions with this signature are used to implement functions in
1051 // the CallStaticMethod family.
1052 template<typename T>
1053 static T JNICALL
1054 _Jv_JNI_CallStaticMethod (JNIEnv *env, jclass klass,
1055 jmethodID id, ...)
1057 va_list args;
1058 T result;
1060 JvAssert (((id->accflags) & java::lang::reflect::Modifier::STATIC));
1061 JvAssert (java::lang::Class::class$.isInstance (unwrap (klass)));
1063 va_start (args, id);
1064 result = _Jv_JNI_CallAnyMethodV<T, static_type> (env, NULL, klass,
1065 id, args);
1066 va_end (args);
1068 return result;
1071 // Functions with this signature are used to implement functions in
1072 // the CallStaticMethod family.
1073 template<typename T>
1074 static T JNICALL
1075 _Jv_JNI_CallStaticMethodA (JNIEnv *env, jclass klass, jmethodID id,
1076 jvalue *args)
1078 JvAssert (((id->accflags) & java::lang::reflect::Modifier::STATIC));
1079 JvAssert (java::lang::Class::class$.isInstance (unwrap (klass)));
1081 return _Jv_JNI_CallAnyMethodA<T, static_type> (env, NULL, klass, id, args);
1084 static void JNICALL
1085 _Jv_JNI_CallStaticVoidMethodV (JNIEnv *env, jclass klass,
1086 jmethodID id, va_list args)
1088 _Jv_JNI_CallAnyVoidMethodV<static_type> (env, NULL, klass, id, args);
1091 static void JNICALL
1092 _Jv_JNI_CallStaticVoidMethod (JNIEnv *env, jclass klass,
1093 jmethodID id, ...)
1095 va_list args;
1097 va_start (args, id);
1098 _Jv_JNI_CallAnyVoidMethodV<static_type> (env, NULL, klass, id, args);
1099 va_end (args);
1102 static void JNICALL
1103 _Jv_JNI_CallStaticVoidMethodA (JNIEnv *env, jclass klass,
1104 jmethodID id, jvalue *args)
1106 _Jv_JNI_CallAnyVoidMethodA<static_type> (env, NULL, klass, id, args);
1109 static jobject JNICALL
1110 _Jv_JNI_NewObjectV (JNIEnv *env, jclass klass,
1111 jmethodID id, va_list args)
1113 JvAssert (klass && ! klass->isArray ());
1114 JvAssert (! strcmp (id->name->data, "<init>")
1115 && id->signature->length > 2
1116 && id->signature->data[0] == '('
1117 && ! strcmp (&id->signature->data[id->signature->length - 2],
1118 ")V"));
1120 return _Jv_JNI_CallAnyMethodV<jobject, constructor> (env, NULL, klass,
1121 id, args);
1124 static jobject JNICALL
1125 _Jv_JNI_NewObject (JNIEnv *env, jclass klass, jmethodID id, ...)
1127 JvAssert (klass && ! klass->isArray ());
1128 JvAssert (! strcmp (id->name->data, "<init>")
1129 && id->signature->length > 2
1130 && id->signature->data[0] == '('
1131 && ! strcmp (&id->signature->data[id->signature->length - 2],
1132 ")V"));
1134 va_list args;
1135 jobject result;
1137 va_start (args, id);
1138 result = _Jv_JNI_CallAnyMethodV<jobject, constructor> (env, NULL, klass,
1139 id, args);
1140 va_end (args);
1142 return result;
1145 static jobject JNICALL
1146 _Jv_JNI_NewObjectA (JNIEnv *env, jclass klass, jmethodID id,
1147 jvalue *args)
1149 JvAssert (klass && ! klass->isArray ());
1150 JvAssert (! strcmp (id->name->data, "<init>")
1151 && id->signature->length > 2
1152 && id->signature->data[0] == '('
1153 && ! strcmp (&id->signature->data[id->signature->length - 2],
1154 ")V"));
1156 return _Jv_JNI_CallAnyMethodA<jobject, constructor> (env, NULL, klass,
1157 id, args);
1162 template<typename T>
1163 static T JNICALL
1164 _Jv_JNI_GetField (JNIEnv *env, jobject obj, jfieldID field)
1166 obj = unwrap (obj);
1167 JvAssert (obj);
1168 T *ptr = (T *) ((char *) obj + field->getOffset ());
1169 return wrap_value (env, *ptr);
1172 template<typename T>
1173 static void JNICALL
1174 _Jv_JNI_SetField (JNIEnv *, jobject obj, jfieldID field, T value)
1176 obj = unwrap (obj);
1177 value = unwrap (value);
1179 JvAssert (obj);
1180 T *ptr = (T *) ((char *) obj + field->getOffset ());
1181 *ptr = value;
1184 template<jboolean is_static>
1185 static jfieldID JNICALL
1186 _Jv_JNI_GetAnyFieldID (JNIEnv *env, jclass clazz,
1187 const char *name, const char *sig)
1191 clazz = unwrap (clazz);
1193 _Jv_InitClass (clazz);
1195 _Jv_Utf8Const *a_name = _Jv_makeUtf8Const ((char *) name, -1);
1197 // FIXME: assume that SIG isn't too long.
1198 int len = strlen (sig);
1199 char s[len + 1];
1200 for (int i = 0; i <= len; ++i)
1201 s[i] = (sig[i] == '/') ? '.' : sig[i];
1202 jclass field_class = _Jv_FindClassFromSignature ((char *) s, NULL);
1204 // FIXME: what if field_class == NULL?
1206 java::lang::ClassLoader *loader = clazz->getClassLoaderInternal ();
1207 while (clazz != NULL)
1209 // We acquire the class lock so that fields aren't resolved
1210 // while we are running.
1211 JvSynchronize sync (clazz);
1213 jint count = (is_static
1214 ? JvNumStaticFields (clazz)
1215 : JvNumInstanceFields (clazz));
1216 jfieldID field = (is_static
1217 ? JvGetFirstStaticField (clazz)
1218 : JvGetFirstInstanceField (clazz));
1219 for (jint i = 0; i < count; ++i)
1221 _Jv_Utf8Const *f_name = field->getNameUtf8Const(clazz);
1223 // The field might be resolved or it might not be. It
1224 // is much simpler to always resolve it.
1225 _Jv_Linker::resolve_field (field, loader);
1226 if (_Jv_equalUtf8Consts (f_name, a_name)
1227 && field->getClass() == field_class)
1228 return field;
1230 field = field->getNextField ();
1233 clazz = clazz->getSuperclass ();
1236 env->ex = new java::lang::NoSuchFieldError ();
1238 catch (jthrowable t)
1240 env->ex = t;
1242 return NULL;
1245 template<typename T>
1246 static T JNICALL
1247 _Jv_JNI_GetStaticField (JNIEnv *env, jclass, jfieldID field)
1249 T *ptr = (T *) field->u.addr;
1250 return wrap_value (env, *ptr);
1253 template<typename T>
1254 static void JNICALL
1255 _Jv_JNI_SetStaticField (JNIEnv *, jclass, jfieldID field, T value)
1257 value = unwrap (value);
1258 T *ptr = (T *) field->u.addr;
1259 *ptr = value;
1262 static jstring JNICALL
1263 _Jv_JNI_NewString (JNIEnv *env, const jchar *unichars, jsize len)
1267 jstring r = _Jv_NewString (unichars, len);
1268 return (jstring) wrap_value (env, r);
1270 catch (jthrowable t)
1272 env->ex = t;
1273 return NULL;
1277 static jsize JNICALL
1278 _Jv_JNI_GetStringLength (JNIEnv *, jstring string)
1280 return unwrap (string)->length();
1283 static const jchar * JNICALL
1284 _Jv_JNI_GetStringChars (JNIEnv *, jstring string, jboolean *isCopy)
1286 string = unwrap (string);
1287 jchar *result = _Jv_GetStringChars (string);
1288 mark_for_gc (string, global_ref_table);
1289 if (isCopy)
1290 *isCopy = false;
1291 return (const jchar *) result;
1294 static void JNICALL
1295 _Jv_JNI_ReleaseStringChars (JNIEnv *, jstring string, const jchar *)
1297 unmark_for_gc (unwrap (string), global_ref_table);
1300 static jstring JNICALL
1301 _Jv_JNI_NewStringUTF (JNIEnv *env, const char *bytes)
1305 jstring result = JvNewStringUTF (bytes);
1306 return (jstring) wrap_value (env, result);
1308 catch (jthrowable t)
1310 env->ex = t;
1311 return NULL;
1315 static jsize JNICALL
1316 _Jv_JNI_GetStringUTFLength (JNIEnv *, jstring string)
1318 return JvGetStringUTFLength (unwrap (string));
1321 static const char * JNICALL
1322 _Jv_JNI_GetStringUTFChars (JNIEnv *env, jstring string,
1323 jboolean *isCopy)
1327 string = unwrap (string);
1328 if (string == NULL)
1329 return NULL;
1330 jsize len = JvGetStringUTFLength (string);
1331 char *r = (char *) _Jv_Malloc (len + 1);
1332 JvGetStringUTFRegion (string, 0, string->length(), r);
1333 r[len] = '\0';
1335 if (isCopy)
1336 *isCopy = true;
1338 return (const char *) r;
1340 catch (jthrowable t)
1342 env->ex = t;
1343 return NULL;
1347 static void JNICALL
1348 _Jv_JNI_ReleaseStringUTFChars (JNIEnv *, jstring, const char *utf)
1350 _Jv_Free ((void *) utf);
1353 static void JNICALL
1354 _Jv_JNI_GetStringRegion (JNIEnv *env, jstring string, jsize start,
1355 jsize len, jchar *buf)
1357 string = unwrap (string);
1358 jchar *result = _Jv_GetStringChars (string);
1359 if (start < 0 || start > string->length ()
1360 || len < 0 || start + len > string->length ())
1364 env->ex = new java::lang::StringIndexOutOfBoundsException ();
1366 catch (jthrowable t)
1368 env->ex = t;
1371 else
1372 memcpy (buf, &result[start], len * sizeof (jchar));
1375 static void JNICALL
1376 _Jv_JNI_GetStringUTFRegion (JNIEnv *env, jstring str, jsize start,
1377 jsize len, char *buf)
1379 str = unwrap (str);
1381 if (start < 0 || start > str->length ()
1382 || len < 0 || start + len > str->length ())
1386 env->ex = new java::lang::StringIndexOutOfBoundsException ();
1388 catch (jthrowable t)
1390 env->ex = t;
1393 else
1394 _Jv_GetStringUTFRegion (str, start, len, buf);
1397 static const jchar * JNICALL
1398 _Jv_JNI_GetStringCritical (JNIEnv *, jstring str, jboolean *isCopy)
1400 jchar *result = _Jv_GetStringChars (unwrap (str));
1401 if (isCopy)
1402 *isCopy = false;
1403 return result;
1406 static void JNICALL
1407 _Jv_JNI_ReleaseStringCritical (JNIEnv *, jstring, const jchar *)
1409 // Nothing.
1412 static jsize JNICALL
1413 _Jv_JNI_GetArrayLength (JNIEnv *, jarray array)
1415 return unwrap (array)->length;
1418 static jobjectArray JNICALL
1419 _Jv_JNI_NewObjectArray (JNIEnv *env, jsize length,
1420 jclass elementClass, jobject init)
1424 elementClass = unwrap (elementClass);
1425 init = unwrap (init);
1427 _Jv_CheckCast (elementClass, init);
1428 jarray result = JvNewObjectArray (length, elementClass, init);
1429 return (jobjectArray) wrap_value (env, result);
1431 catch (jthrowable t)
1433 env->ex = t;
1434 return NULL;
1438 static jobject JNICALL
1439 _Jv_JNI_GetObjectArrayElement (JNIEnv *env, jobjectArray array,
1440 jsize index)
1442 if ((unsigned) index >= (unsigned) array->length)
1443 _Jv_ThrowBadArrayIndex (index);
1444 jobject *elts = elements (unwrap (array));
1445 return wrap_value (env, elts[index]);
1448 static void JNICALL
1449 _Jv_JNI_SetObjectArrayElement (JNIEnv *env, jobjectArray array,
1450 jsize index, jobject value)
1454 array = unwrap (array);
1455 value = unwrap (value);
1457 _Jv_CheckArrayStore (array, value);
1458 if ((unsigned) index >= (unsigned) array->length)
1459 _Jv_ThrowBadArrayIndex (index);
1460 jobject *elts = elements (array);
1461 elts[index] = value;
1463 catch (jthrowable t)
1465 env->ex = t;
1469 template<typename T, jclass K>
1470 static JArray<T> * JNICALL
1471 _Jv_JNI_NewPrimitiveArray (JNIEnv *env, jsize length)
1475 return (JArray<T> *) wrap_value (env, _Jv_NewPrimArray (K, length));
1477 catch (jthrowable t)
1479 env->ex = t;
1480 return NULL;
1484 template<typename T, jclass K>
1485 static T * JNICALL
1486 _Jv_JNI_GetPrimitiveArrayElements (JNIEnv *env, JArray<T> *array,
1487 jboolean *isCopy)
1489 array = unwrap (array);
1490 if (! _Jv_JNI_check_types (env, array, K))
1491 return NULL;
1492 T *elts = elements (array);
1493 if (isCopy)
1495 // We elect never to copy.
1496 *isCopy = false;
1498 mark_for_gc (array, global_ref_table);
1499 return elts;
1502 template<typename T, jclass K>
1503 static void JNICALL
1504 _Jv_JNI_ReleasePrimitiveArrayElements (JNIEnv *env, JArray<T> *array,
1505 T *, jint /* mode */)
1507 array = unwrap (array);
1508 _Jv_JNI_check_types (env, array, K);
1509 // Note that we ignore MODE. We can do this because we never copy
1510 // the array elements. My reading of the JNI documentation is that
1511 // this is an option for the implementor.
1512 unmark_for_gc (array, global_ref_table);
1515 template<typename T, jclass K>
1516 static void JNICALL
1517 _Jv_JNI_GetPrimitiveArrayRegion (JNIEnv *env, JArray<T> *array,
1518 jsize start, jsize len,
1519 T *buf)
1521 array = unwrap (array);
1522 if (! _Jv_JNI_check_types (env, array, K))
1523 return;
1525 // The cast to unsigned lets us save a comparison.
1526 if (start < 0 || len < 0
1527 || (unsigned long) (start + len) > (unsigned long) array->length)
1531 // FIXME: index.
1532 env->ex = new java::lang::ArrayIndexOutOfBoundsException ();
1534 catch (jthrowable t)
1536 // Could have thown out of memory error.
1537 env->ex = t;
1540 else
1542 T *elts = elements (array) + start;
1543 memcpy (buf, elts, len * sizeof (T));
1547 template<typename T, jclass K>
1548 static void JNICALL
1549 _Jv_JNI_SetPrimitiveArrayRegion (JNIEnv *env, JArray<T> *array,
1550 jsize start, jsize len, T *buf)
1552 array = unwrap (array);
1553 if (! _Jv_JNI_check_types (env, array, K))
1554 return;
1556 // The cast to unsigned lets us save a comparison.
1557 if (start < 0 || len < 0
1558 || (unsigned long) (start + len) > (unsigned long) array->length)
1562 // FIXME: index.
1563 env->ex = new java::lang::ArrayIndexOutOfBoundsException ();
1565 catch (jthrowable t)
1567 env->ex = t;
1570 else
1572 T *elts = elements (array) + start;
1573 memcpy (elts, buf, len * sizeof (T));
1577 static void * JNICALL
1578 _Jv_JNI_GetPrimitiveArrayCritical (JNIEnv *, jarray array,
1579 jboolean *isCopy)
1581 array = unwrap (array);
1582 // FIXME: does this work?
1583 jclass klass = array->getClass()->getComponentType();
1584 JvAssert (klass->isPrimitive ());
1585 char *r = _Jv_GetArrayElementFromElementType (array, klass);
1586 if (isCopy)
1587 *isCopy = false;
1588 return r;
1591 static void JNICALL
1592 _Jv_JNI_ReleasePrimitiveArrayCritical (JNIEnv *, jarray, void *, jint)
1594 // Nothing.
1597 static jint JNICALL
1598 _Jv_JNI_MonitorEnter (JNIEnv *env, jobject obj)
1602 _Jv_MonitorEnter (unwrap (obj));
1603 return 0;
1605 catch (jthrowable t)
1607 env->ex = t;
1609 return JNI_ERR;
1612 static jint JNICALL
1613 _Jv_JNI_MonitorExit (JNIEnv *env, jobject obj)
1617 _Jv_MonitorExit (unwrap (obj));
1618 return 0;
1620 catch (jthrowable t)
1622 env->ex = t;
1624 return JNI_ERR;
1627 // JDK 1.2
1628 jobject JNICALL
1629 _Jv_JNI_ToReflectedField (JNIEnv *env, jclass cls, jfieldID fieldID,
1630 jboolean)
1634 cls = unwrap (cls);
1635 java::lang::reflect::Field *field = new java::lang::reflect::Field();
1636 field->declaringClass = cls;
1637 field->offset = (char*) fieldID - (char *) cls->fields;
1638 field->name = _Jv_NewStringUtf8Const (fieldID->getNameUtf8Const (cls));
1639 return wrap_value (env, field);
1641 catch (jthrowable t)
1643 env->ex = t;
1645 return NULL;
1648 // JDK 1.2
1649 static jfieldID JNICALL
1650 _Jv_JNI_FromReflectedField (JNIEnv *, jobject f)
1652 using namespace java::lang::reflect;
1654 f = unwrap (f);
1655 Field *field = reinterpret_cast<Field *> (f);
1656 return _Jv_FromReflectedField (field);
1659 jobject JNICALL
1660 _Jv_JNI_ToReflectedMethod (JNIEnv *env, jclass klass, jmethodID id,
1661 jboolean)
1663 using namespace java::lang::reflect;
1665 jobject result = NULL;
1666 klass = unwrap (klass);
1670 if (_Jv_equalUtf8Consts (id->name, init_name))
1672 // A constructor.
1673 Constructor *cons = new Constructor ();
1674 cons->offset = (char *) id - (char *) &klass->methods;
1675 cons->declaringClass = klass;
1676 result = cons;
1678 else
1680 Method *meth = new Method ();
1681 meth->offset = (char *) id - (char *) &klass->methods;
1682 meth->declaringClass = klass;
1683 result = meth;
1686 catch (jthrowable t)
1688 env->ex = t;
1691 return wrap_value (env, result);
1694 static jmethodID JNICALL
1695 _Jv_JNI_FromReflectedMethod (JNIEnv *, jobject method)
1697 using namespace java::lang::reflect;
1698 method = unwrap (method);
1699 if (Method::class$.isInstance (method))
1700 return _Jv_FromReflectedMethod (reinterpret_cast<Method *> (method));
1701 return
1702 _Jv_FromReflectedConstructor (reinterpret_cast<Constructor *> (method));
1705 // JDK 1.2.
1706 jweak JNICALL
1707 _Jv_JNI_NewWeakGlobalRef (JNIEnv *env, jobject obj)
1709 using namespace gnu::gcj::runtime;
1710 JNIWeakRef *ref = NULL;
1714 // This seems weird but I think it is correct.
1715 obj = unwrap (obj);
1716 ref = new JNIWeakRef (obj);
1717 mark_for_gc (ref, global_ref_table);
1719 catch (jthrowable t)
1721 env->ex = t;
1724 return reinterpret_cast<jweak> (ref);
1727 void JNICALL
1728 _Jv_JNI_DeleteWeakGlobalRef (JNIEnv *, jweak obj)
1730 using namespace gnu::gcj::runtime;
1731 JNIWeakRef *ref = reinterpret_cast<JNIWeakRef *> (obj);
1732 unmark_for_gc (ref, global_ref_table);
1733 ref->clear ();
1738 // Direct byte buffers.
1740 static jobject JNICALL
1741 _Jv_JNI_NewDirectByteBuffer (JNIEnv *, void *address, jlong length)
1743 using namespace gnu::gcj;
1744 using namespace java::nio;
1745 return new DirectByteBufferImpl$ReadWrite
1746 (reinterpret_cast<RawData *> (address), length);
1749 static void * JNICALL
1750 _Jv_JNI_GetDirectBufferAddress (JNIEnv *, jobject buffer)
1752 using namespace java::nio;
1753 if (! _Jv_IsInstanceOf (buffer, &Buffer::class$))
1754 return NULL;
1755 Buffer *tmp = static_cast<Buffer *> (buffer);
1756 return reinterpret_cast<void *> (tmp->address);
1759 static jlong JNICALL
1760 _Jv_JNI_GetDirectBufferCapacity (JNIEnv *, jobject buffer)
1762 using namespace java::nio;
1763 if (! _Jv_IsInstanceOf (buffer, &Buffer::class$))
1764 return -1;
1765 Buffer *tmp = static_cast<Buffer *> (buffer);
1766 if (tmp->address == NULL)
1767 return -1;
1768 return tmp->capacity();
1773 // Hash table of native methods.
1774 static JNINativeMethod *nathash;
1775 // Number of slots used.
1776 static int nathash_count = 0;
1777 // Number of slots available. Must be power of 2.
1778 static int nathash_size = 0;
1780 #define DELETED_ENTRY ((char *) (~0))
1782 // Compute a hash value for a native method descriptor.
1783 static int
1784 hash (const JNINativeMethod *method)
1786 char *ptr;
1787 int hash = 0;
1789 ptr = method->name;
1790 while (*ptr)
1791 hash = (31 * hash) + *ptr++;
1793 ptr = method->signature;
1794 while (*ptr)
1795 hash = (31 * hash) + *ptr++;
1797 return hash;
1800 // Find the slot where a native method goes.
1801 static JNINativeMethod *
1802 nathash_find_slot (const JNINativeMethod *method)
1804 jint h = hash (method);
1805 int step = (h ^ (h >> 16)) | 1;
1806 int w = h & (nathash_size - 1);
1807 int del = -1;
1809 for (;;)
1811 JNINativeMethod *slotp = &nathash[w];
1812 if (slotp->name == NULL)
1814 if (del >= 0)
1815 return &nathash[del];
1816 else
1817 return slotp;
1819 else if (slotp->name == DELETED_ENTRY)
1820 del = w;
1821 else if (! strcmp (slotp->name, method->name)
1822 && ! strcmp (slotp->signature, method->signature))
1823 return slotp;
1824 w = (w + step) & (nathash_size - 1);
1828 // Find a method. Return NULL if it isn't in the hash table.
1829 static void *
1830 nathash_find (JNINativeMethod *method)
1832 if (nathash == NULL)
1833 return NULL;
1834 JNINativeMethod *slot = nathash_find_slot (method);
1835 if (slot->name == NULL || slot->name == DELETED_ENTRY)
1836 return NULL;
1837 return slot->fnPtr;
1840 static void
1841 natrehash ()
1843 if (nathash == NULL)
1845 nathash_size = 1024;
1846 nathash =
1847 (JNINativeMethod *) _Jv_AllocBytes (nathash_size
1848 * sizeof (JNINativeMethod));
1849 memset (nathash, 0, nathash_size * sizeof (JNINativeMethod));
1851 else
1853 int savesize = nathash_size;
1854 JNINativeMethod *savehash = nathash;
1855 nathash_size *= 2;
1856 nathash =
1857 (JNINativeMethod *) _Jv_AllocBytes (nathash_size
1858 * sizeof (JNINativeMethod));
1859 memset (nathash, 0, nathash_size * sizeof (JNINativeMethod));
1861 for (int i = 0; i < savesize; ++i)
1863 if (savehash[i].name != NULL && savehash[i].name != DELETED_ENTRY)
1865 JNINativeMethod *slot = nathash_find_slot (&savehash[i]);
1866 *slot = savehash[i];
1872 static void
1873 nathash_add (const JNINativeMethod *method)
1875 if (3 * nathash_count >= 2 * nathash_size)
1876 natrehash ();
1877 JNINativeMethod *slot = nathash_find_slot (method);
1878 // If the slot has a real entry in it, then there is no work to do.
1879 if (slot->name != NULL && slot->name != DELETED_ENTRY)
1880 return;
1881 // FIXME
1882 slot->name = strdup (method->name);
1883 // This was already strduped in _Jv_JNI_RegisterNatives.
1884 slot->signature = method->signature;
1885 slot->fnPtr = method->fnPtr;
1888 static jint JNICALL
1889 _Jv_JNI_RegisterNatives (JNIEnv *env, jclass klass,
1890 const JNINativeMethod *methods,
1891 jint nMethods)
1893 // Synchronize while we do the work. This must match
1894 // synchronization in some other functions that manipulate or use
1895 // the nathash table.
1896 JvSynchronize sync (global_ref_table);
1898 JNINativeMethod dottedMethod;
1900 // Look at each descriptor given us, and find the corresponding
1901 // method in the class.
1902 for (int j = 0; j < nMethods; ++j)
1904 bool found = false;
1906 _Jv_Method *imeths = JvGetFirstMethod (klass);
1907 for (int i = 0; i < JvNumMethods (klass); ++i)
1909 _Jv_Method *self = &imeths[i];
1911 // Copy this JNINativeMethod and do a slash to dot
1912 // conversion on the signature.
1913 dottedMethod.name = methods[j].name;
1914 dottedMethod.signature = strdup (methods[j].signature);
1915 dottedMethod.fnPtr = methods[j].fnPtr;
1916 char *c = dottedMethod.signature;
1917 while (*c)
1919 if (*c == '/')
1920 *c = '.';
1921 c++;
1924 if (! strcmp (self->name->chars (), dottedMethod.name)
1925 && ! strcmp (self->signature->chars (), dottedMethod.signature))
1927 if (! (self->accflags & java::lang::reflect::Modifier::NATIVE))
1928 break;
1930 // Found a match that is native.
1931 found = true;
1932 nathash_add (&dottedMethod);
1934 break;
1938 if (! found)
1940 jstring m = JvNewStringUTF (methods[j].name);
1943 env->ex = new java::lang::NoSuchMethodError (m);
1945 catch (jthrowable t)
1947 env->ex = t;
1949 return JNI_ERR;
1953 return JNI_OK;
1956 static jint JNICALL
1957 _Jv_JNI_UnregisterNatives (JNIEnv *, jclass)
1959 // FIXME -- we could implement this.
1960 return JNI_ERR;
1965 // Add a character to the buffer, encoding properly.
1966 static void
1967 add_char (char *buf, jchar c, int *here)
1969 if (c == '_')
1971 buf[(*here)++] = '_';
1972 buf[(*here)++] = '1';
1974 else if (c == ';')
1976 buf[(*here)++] = '_';
1977 buf[(*here)++] = '2';
1979 else if (c == '[')
1981 buf[(*here)++] = '_';
1982 buf[(*here)++] = '3';
1985 // Also check for `.' here because we might be passed an internal
1986 // qualified class name like `foo.bar'.
1987 else if (c == '/' || c == '.')
1988 buf[(*here)++] = '_';
1989 else if ((c >= '0' && c <= '9')
1990 || (c >= 'a' && c <= 'z')
1991 || (c >= 'A' && c <= 'Z'))
1992 buf[(*here)++] = (char) c;
1993 else
1995 // "Unicode" character.
1996 buf[(*here)++] = '_';
1997 buf[(*here)++] = '0';
1998 for (int i = 0; i < 4; ++i)
2000 int val = c & 0x0f;
2001 buf[(*here) + 3 - i] = (val > 10) ? ('a' + val - 10) : ('0' + val);
2002 c >>= 4;
2004 *here += 4;
2008 // Compute a mangled name for a native function. This computes the
2009 // long name, and also returns an index which indicates where a NUL
2010 // can be placed to create the short name. This function assumes that
2011 // the buffer is large enough for its results.
2012 static void
2013 mangled_name (jclass klass, _Jv_Utf8Const *func_name,
2014 _Jv_Utf8Const *signature, char *buf, int *long_start)
2016 strcpy (buf, "Java_");
2017 int here = 5;
2019 // Add fully qualified class name.
2020 jchar *chars = _Jv_GetStringChars (klass->getName ());
2021 jint len = klass->getName ()->length ();
2022 for (int i = 0; i < len; ++i)
2023 add_char (buf, chars[i], &here);
2025 // Don't use add_char because we need a literal `_'.
2026 buf[here++] = '_';
2028 const unsigned char *fn = (const unsigned char *) func_name->chars ();
2029 const unsigned char *limit = fn + func_name->len ();
2030 for (int i = 0; ; ++i)
2032 int ch = UTF8_GET (fn, limit);
2033 if (ch < 0)
2034 break;
2035 add_char (buf, ch, &here);
2038 // This is where the long signature begins.
2039 *long_start = here;
2040 buf[here++] = '_';
2041 buf[here++] = '_';
2043 const unsigned char *sig = (const unsigned char *) signature->chars ();
2044 limit = sig + signature->len ();
2045 JvAssert (sig[0] == '(');
2046 ++sig;
2047 while (1)
2049 int ch = UTF8_GET (sig, limit);
2050 if (ch == ')' || ch < 0)
2051 break;
2052 add_char (buf, ch, &here);
2055 buf[here] = '\0';
2058 // Return the current thread's JNIEnv; if one does not exist, create
2059 // it. Also create a new system frame for use. This is `extern "C"'
2060 // because the compiler calls it.
2061 extern "C" JNIEnv *
2062 _Jv_GetJNIEnvNewFrame (jclass klass)
2064 JNIEnv *env = _Jv_GetCurrentJNIEnv ();
2065 if (__builtin_expect (env == NULL, false))
2067 env = (JNIEnv *) _Jv_MallocUnchecked (sizeof (JNIEnv));
2068 env->p = &_Jv_JNIFunctions;
2069 env->klass = klass;
2070 env->locals = NULL;
2071 // We set env->ex below.
2073 // Set up the bottom, reusable frame.
2074 env->bottom_locals = (_Jv_JNI_LocalFrame *)
2075 _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame)
2076 + (FRAME_SIZE
2077 * sizeof (jobject)));
2079 env->bottom_locals->marker = MARK_SYSTEM;
2080 env->bottom_locals->size = FRAME_SIZE;
2081 env->bottom_locals->next = NULL;
2082 env->bottom_locals->allocated_p = 0;
2083 memset (&env->bottom_locals->vec[0], 0,
2084 env->bottom_locals->size * sizeof (jobject));
2086 _Jv_SetCurrentJNIEnv (env);
2089 // If we're in a simple JNI call (non-nested), we can just reuse the
2090 // locals frame we allocated many calls ago, back when the env was first
2091 // built, above.
2093 if (__builtin_expect (env->locals == NULL, true))
2094 env->locals = env->bottom_locals;
2096 else
2098 // Alternatively, we might be re-entering JNI, in which case we can't
2099 // reuse the bottom_locals frame, because it is already underneath
2100 // us. So we need to make a new one.
2102 _Jv_JNI_LocalFrame *frame
2103 = (_Jv_JNI_LocalFrame *) _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame)
2104 + (FRAME_SIZE
2105 * sizeof (jobject)));
2107 frame->marker = MARK_SYSTEM;
2108 frame->size = FRAME_SIZE;
2109 frame->allocated_p = 0;
2110 frame->next = env->locals;
2112 memset (&frame->vec[0], 0,
2113 frame->size * sizeof (jobject));
2115 env->locals = frame;
2118 env->ex = NULL;
2120 return env;
2123 // Destroy the env's reusable resources. This is called from the thread
2124 // destructor "finalize_native" in natThread.cc
2125 void
2126 _Jv_FreeJNIEnv (_Jv_JNIEnv *env)
2128 if (env == NULL)
2129 return;
2131 if (env->bottom_locals != NULL)
2132 _Jv_Free (env->bottom_locals);
2134 _Jv_Free (env);
2137 // Return the function which implements a particular JNI method. If
2138 // we can't find the function, we throw the appropriate exception.
2139 // This is `extern "C"' because the compiler uses it.
2140 extern "C" void *
2141 _Jv_LookupJNIMethod (jclass klass, _Jv_Utf8Const *name,
2142 _Jv_Utf8Const *signature, MAYBE_UNUSED int args_size)
2144 int name_length = name->len();
2145 int sig_length = signature->len();
2146 char buf[10 + 6 * (name_length + sig_length) + 12];
2147 int long_start;
2148 void *function;
2150 // Synchronize on something convenient. Right now we use the hash.
2151 JvSynchronize sync (global_ref_table);
2153 // First see if we have an override in the hash table.
2154 strncpy (buf, name->chars (), name_length);
2155 buf[name_length] = '\0';
2156 strncpy (buf + name_length + 1, signature->chars (), sig_length);
2157 buf[name_length + sig_length + 1] = '\0';
2158 JNINativeMethod meth;
2159 meth.name = buf;
2160 meth.signature = buf + name_length + 1;
2161 function = nathash_find (&meth);
2162 if (function != NULL)
2163 return function;
2165 // If there was no override, then look in the symbol table.
2166 buf[0] = '_';
2167 mangled_name (klass, name, signature, buf + 1, &long_start);
2168 char c = buf[long_start + 1];
2169 buf[long_start + 1] = '\0';
2171 function = _Jv_FindSymbolInExecutable (buf + 1);
2172 #ifdef WIN32
2173 // On Win32, we use the "stdcall" calling convention (see JNICALL
2174 // in jni.h).
2176 // For a function named 'fooBar' that takes 'nn' bytes as arguments,
2177 // by default, MinGW GCC exports it as 'fooBar@nn', MSVC exports it
2178 // as '_fooBar@nn' and Borland C exports it as 'fooBar'. We try to
2179 // take care of all these variations here.
2181 char asz_buf[12]; /* '@' + '2147483647' (32-bit INT_MAX) + '\0' */
2182 char long_nm_sv[11]; /* Ditto, except for the '\0'. */
2184 if (function == NULL)
2186 // We have tried searching for the 'fooBar' form (BCC) - now
2187 // try the others.
2189 // First, save the part of the long name that will be damaged
2190 // by appending '@nn'.
2191 memcpy (long_nm_sv, (buf + long_start + 1 + 1), sizeof (long_nm_sv));
2193 sprintf (asz_buf, "@%d", args_size);
2194 strcat (buf, asz_buf);
2196 // Search for the '_fooBar@nn' form (MSVC).
2197 function = _Jv_FindSymbolInExecutable (buf);
2199 if (function == NULL)
2201 // Search for the 'fooBar@nn' form (MinGW GCC).
2202 function = _Jv_FindSymbolInExecutable (buf + 1);
2205 #endif /* WIN32 */
2207 if (function == NULL)
2209 buf[long_start + 1] = c;
2210 #ifdef WIN32
2211 // Restore the part of the long name that was damaged by
2212 // appending the '@nn'.
2213 memcpy ((buf + long_start + 1 + 1), long_nm_sv, sizeof (long_nm_sv));
2214 #endif /* WIN32 */
2215 function = _Jv_FindSymbolInExecutable (buf + 1);
2216 if (function == NULL)
2218 #ifdef WIN32
2219 strcat (buf, asz_buf);
2220 function = _Jv_FindSymbolInExecutable (buf);
2221 if (function == NULL)
2222 function = _Jv_FindSymbolInExecutable (buf + 1);
2224 if (function == NULL)
2225 #endif /* WIN32 */
2227 jstring str = JvNewStringUTF (name->chars ());
2228 throw new java::lang::UnsatisfiedLinkError (str);
2233 return function;
2236 #ifdef INTERPRETER
2238 // This function is the stub which is used to turn an ordinary (CNI)
2239 // method call into a JNI call.
2240 void
2241 _Jv_JNIMethod::call (ffi_cif *, void *ret, ffi_raw *args, void *__this)
2243 _Jv_JNIMethod* _this = (_Jv_JNIMethod *) __this;
2245 JNIEnv *env = _Jv_GetJNIEnvNewFrame (_this->defining_class);
2247 // FIXME: we should mark every reference parameter as a local. For
2248 // now we assume a conservative GC, and we assume that the
2249 // references are on the stack somewhere.
2251 // We cache the value that we find, of course, but if we don't find
2252 // a value we don't cache that fact -- we might subsequently load a
2253 // library which finds the function in question.
2255 // Synchronize on a convenient object to ensure sanity in case two
2256 // threads reach this point for the same function at the same
2257 // time.
2258 JvSynchronize sync (global_ref_table);
2259 if (_this->function == NULL)
2261 int args_size = sizeof (JNIEnv *) + _this->args_raw_size;
2263 if (_this->self->accflags & java::lang::reflect::Modifier::STATIC)
2264 args_size += sizeof (_this->defining_class);
2266 _this->function = _Jv_LookupJNIMethod (_this->defining_class,
2267 _this->self->name,
2268 _this->self->signature,
2269 args_size);
2273 JvAssert (_this->args_raw_size % sizeof (ffi_raw) == 0);
2274 ffi_raw real_args[2 + _this->args_raw_size / sizeof (ffi_raw)];
2275 int offset = 0;
2277 // First argument is always the environment pointer.
2278 real_args[offset++].ptr = env;
2280 // For a static method, we pass in the Class. For non-static
2281 // methods, the `this' argument is already handled.
2282 if ((_this->self->accflags & java::lang::reflect::Modifier::STATIC))
2283 real_args[offset++].ptr = _this->defining_class;
2285 // In libgcj, the callee synchronizes.
2286 jobject sync = NULL;
2287 if ((_this->self->accflags & java::lang::reflect::Modifier::SYNCHRONIZED))
2289 if ((_this->self->accflags & java::lang::reflect::Modifier::STATIC))
2290 sync = _this->defining_class;
2291 else
2292 sync = (jobject) args[0].ptr;
2293 _Jv_MonitorEnter (sync);
2296 // Copy over passed-in arguments.
2297 memcpy (&real_args[offset], args, _this->args_raw_size);
2299 // The actual call to the JNI function.
2300 #if FFI_NATIVE_RAW_API
2301 ffi_raw_call (&_this->jni_cif, (void (*)()) _this->function,
2302 ret, real_args);
2303 #else
2304 ffi_java_raw_call (&_this->jni_cif, (void (*)()) _this->function,
2305 ret, real_args);
2306 #endif
2308 if (sync != NULL)
2309 _Jv_MonitorExit (sync);
2311 _Jv_JNI_PopSystemFrame (env);
2314 #endif /* INTERPRETER */
2319 // Invocation API.
2322 // An internal helper function.
2323 static jint
2324 _Jv_JNI_AttachCurrentThread (JavaVM *, jstring name, void **penv,
2325 void *args, jboolean is_daemon)
2327 JavaVMAttachArgs *attach = reinterpret_cast<JavaVMAttachArgs *> (args);
2328 java::lang::ThreadGroup *group = NULL;
2330 if (attach)
2332 // FIXME: do we really want to support 1.1?
2333 if (attach->version != JNI_VERSION_1_4
2334 && attach->version != JNI_VERSION_1_2
2335 && attach->version != JNI_VERSION_1_1)
2336 return JNI_EVERSION;
2338 JvAssert (java::lang::ThreadGroup::class$.isInstance (attach->group));
2339 group = reinterpret_cast<java::lang::ThreadGroup *> (attach->group);
2342 // Attaching an already-attached thread is a no-op.
2343 if (_Jv_GetCurrentJNIEnv () != NULL)
2344 return 0;
2346 JNIEnv *env = (JNIEnv *) _Jv_MallocUnchecked (sizeof (JNIEnv));
2347 if (env == NULL)
2348 return JNI_ERR;
2349 env->p = &_Jv_JNIFunctions;
2350 env->ex = NULL;
2351 env->klass = NULL;
2352 env->bottom_locals
2353 = (_Jv_JNI_LocalFrame *) _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame)
2354 + (FRAME_SIZE
2355 * sizeof (jobject)));
2356 env->locals = env->bottom_locals;
2357 if (env->locals == NULL)
2359 _Jv_Free (env);
2360 return JNI_ERR;
2363 env->locals->allocated_p = 0;
2364 env->locals->marker = MARK_SYSTEM;
2365 env->locals->size = FRAME_SIZE;
2366 env->locals->next = NULL;
2368 for (int i = 0; i < env->locals->size; ++i)
2369 env->locals->vec[i] = NULL;
2371 *penv = reinterpret_cast<void *> (env);
2373 // This thread might already be a Java thread -- this function might
2374 // have been called simply to set the new JNIEnv.
2375 if (_Jv_ThreadCurrent () == NULL)
2379 if (is_daemon)
2380 _Jv_AttachCurrentThreadAsDaemon (name, group);
2381 else
2382 _Jv_AttachCurrentThread (name, group);
2384 catch (jthrowable t)
2386 return JNI_ERR;
2389 _Jv_SetCurrentJNIEnv (env);
2391 return 0;
2394 // This is the one actually used by JNI.
2395 static jint JNICALL
2396 _Jv_JNI_AttachCurrentThread (JavaVM *vm, void **penv, void *args)
2398 return _Jv_JNI_AttachCurrentThread (vm, NULL, penv, args, false);
2401 static jint JNICALL
2402 _Jv_JNI_AttachCurrentThreadAsDaemon (JavaVM *vm, void **penv,
2403 void *args)
2405 return _Jv_JNI_AttachCurrentThread (vm, NULL, penv, args, true);
2408 static jint JNICALL
2409 _Jv_JNI_DestroyJavaVM (JavaVM *vm)
2411 JvAssert (the_vm && vm == the_vm);
2413 JNIEnv *env;
2414 if (_Jv_ThreadCurrent () != NULL)
2416 jstring main_name;
2417 // This sucks.
2420 main_name = JvNewStringLatin1 ("main");
2422 catch (jthrowable t)
2424 return JNI_ERR;
2427 jint r = _Jv_JNI_AttachCurrentThread (vm, main_name,
2428 reinterpret_cast<void **> (&env),
2429 NULL, false);
2430 if (r < 0)
2431 return r;
2433 else
2434 env = _Jv_GetCurrentJNIEnv ();
2436 _Jv_ThreadWait ();
2438 // Docs say that this always returns an error code.
2439 return JNI_ERR;
2442 jint JNICALL
2443 _Jv_JNI_DetachCurrentThread (JavaVM *)
2445 jint code = _Jv_DetachCurrentThread ();
2446 return code ? JNI_EDETACHED : 0;
2449 static jint JNICALL
2450 _Jv_JNI_GetEnv (JavaVM *, void **penv, jint version)
2452 if (_Jv_ThreadCurrent () == NULL)
2454 *penv = NULL;
2455 return JNI_EDETACHED;
2458 #ifdef ENABLE_JVMPI
2459 // Handle JVMPI requests.
2460 if (version == JVMPI_VERSION_1)
2462 *penv = (void *) &_Jv_JVMPI_Interface;
2463 return 0;
2465 #endif
2467 // FIXME: do we really want to support 1.1?
2468 if (version != JNI_VERSION_1_4 && version != JNI_VERSION_1_2
2469 && version != JNI_VERSION_1_1)
2471 *penv = NULL;
2472 return JNI_EVERSION;
2475 *penv = (void *) _Jv_GetCurrentJNIEnv ();
2476 return 0;
2479 jint JNICALL
2480 JNI_GetDefaultJavaVMInitArgs (void *args)
2482 jint version = * (jint *) args;
2483 // Here we only support 1.2 and 1.4.
2484 if (version != JNI_VERSION_1_2 && version != JNI_VERSION_1_4)
2485 return JNI_EVERSION;
2487 JavaVMInitArgs *ia = reinterpret_cast<JavaVMInitArgs *> (args);
2488 ia->version = JNI_VERSION_1_4;
2489 ia->nOptions = 0;
2490 ia->options = NULL;
2491 ia->ignoreUnrecognized = true;
2493 return 0;
2496 jint JNICALL
2497 JNI_CreateJavaVM (JavaVM **vm, void **penv, void *args)
2499 JvAssert (! the_vm);
2501 jint version = * (jint *) args;
2502 // We only support 1.2 and 1.4.
2503 if (version != JNI_VERSION_1_2 && version != JNI_VERSION_1_4)
2504 return JNI_EVERSION;
2506 JvVMInitArgs* vm_args = reinterpret_cast<JvVMInitArgs *> (args);
2508 jint result = _Jv_CreateJavaVM (vm_args);
2509 if (result)
2510 return result;
2512 // FIXME: synchronize
2513 JavaVM *nvm = (JavaVM *) _Jv_MallocUnchecked (sizeof (JavaVM));
2514 if (nvm == NULL)
2515 return JNI_ERR;
2516 nvm->functions = &_Jv_JNI_InvokeFunctions;
2518 jint r =_Jv_JNI_AttachCurrentThread (nvm, penv, NULL);
2519 if (r < 0)
2520 return r;
2522 the_vm = nvm;
2523 *vm = the_vm;
2525 return 0;
2528 jint JNICALL
2529 JNI_GetCreatedJavaVMs (JavaVM **vm_buffer, jsize buf_len, jsize *n_vms)
2531 if (buf_len <= 0)
2532 return JNI_ERR;
2534 // We only support a single VM.
2535 if (the_vm != NULL)
2537 vm_buffer[0] = the_vm;
2538 *n_vms = 1;
2540 else
2541 *n_vms = 0;
2542 return 0;
2545 JavaVM *
2546 _Jv_GetJavaVM ()
2548 // FIXME: synchronize
2549 if (! the_vm)
2551 JavaVM *nvm = (JavaVM *) _Jv_MallocUnchecked (sizeof (JavaVM));
2552 if (nvm != NULL)
2553 nvm->functions = &_Jv_JNI_InvokeFunctions;
2554 the_vm = nvm;
2557 // If this is a Java thread, we want to make sure it has an
2558 // associated JNIEnv.
2559 if (_Jv_ThreadCurrent () != NULL)
2561 void *ignore;
2562 _Jv_JNI_AttachCurrentThread (the_vm, &ignore, NULL);
2565 return the_vm;
2568 static jint JNICALL
2569 _Jv_JNI_GetJavaVM (JNIEnv *, JavaVM **vm)
2571 *vm = _Jv_GetJavaVM ();
2572 return *vm == NULL ? JNI_ERR : JNI_OK;
2577 #define RESERVED NULL
2579 struct JNINativeInterface _Jv_JNIFunctions =
2581 RESERVED,
2582 RESERVED,
2583 RESERVED,
2584 RESERVED,
2585 _Jv_JNI_GetVersion, // GetVersion
2586 _Jv_JNI_DefineClass, // DefineClass
2587 _Jv_JNI_FindClass, // FindClass
2588 _Jv_JNI_FromReflectedMethod, // FromReflectedMethod
2589 _Jv_JNI_FromReflectedField, // FromReflectedField
2590 _Jv_JNI_ToReflectedMethod, // ToReflectedMethod
2591 _Jv_JNI_GetSuperclass, // GetSuperclass
2592 _Jv_JNI_IsAssignableFrom, // IsAssignableFrom
2593 _Jv_JNI_ToReflectedField, // ToReflectedField
2594 _Jv_JNI_Throw, // Throw
2595 _Jv_JNI_ThrowNew, // ThrowNew
2596 _Jv_JNI_ExceptionOccurred, // ExceptionOccurred
2597 _Jv_JNI_ExceptionDescribe, // ExceptionDescribe
2598 _Jv_JNI_ExceptionClear, // ExceptionClear
2599 _Jv_JNI_FatalError, // FatalError
2601 _Jv_JNI_PushLocalFrame, // PushLocalFrame
2602 _Jv_JNI_PopLocalFrame, // PopLocalFrame
2603 _Jv_JNI_NewGlobalRef, // NewGlobalRef
2604 _Jv_JNI_DeleteGlobalRef, // DeleteGlobalRef
2605 _Jv_JNI_DeleteLocalRef, // DeleteLocalRef
2607 _Jv_JNI_IsSameObject, // IsSameObject
2609 _Jv_JNI_NewLocalRef, // NewLocalRef
2610 _Jv_JNI_EnsureLocalCapacity, // EnsureLocalCapacity
2612 _Jv_JNI_AllocObject, // AllocObject
2613 _Jv_JNI_NewObject, // NewObject
2614 _Jv_JNI_NewObjectV, // NewObjectV
2615 _Jv_JNI_NewObjectA, // NewObjectA
2616 _Jv_JNI_GetObjectClass, // GetObjectClass
2617 _Jv_JNI_IsInstanceOf, // IsInstanceOf
2618 _Jv_JNI_GetAnyMethodID<false>, // GetMethodID
2620 _Jv_JNI_CallMethod<jobject>, // CallObjectMethod
2621 _Jv_JNI_CallMethodV<jobject>, // CallObjectMethodV
2622 _Jv_JNI_CallMethodA<jobject>, // CallObjectMethodA
2623 _Jv_JNI_CallMethod<jboolean>, // CallBooleanMethod
2624 _Jv_JNI_CallMethodV<jboolean>, // CallBooleanMethodV
2625 _Jv_JNI_CallMethodA<jboolean>, // CallBooleanMethodA
2626 _Jv_JNI_CallMethod<jbyte>, // CallByteMethod
2627 _Jv_JNI_CallMethodV<jbyte>, // CallByteMethodV
2628 _Jv_JNI_CallMethodA<jbyte>, // CallByteMethodA
2629 _Jv_JNI_CallMethod<jchar>, // CallCharMethod
2630 _Jv_JNI_CallMethodV<jchar>, // CallCharMethodV
2631 _Jv_JNI_CallMethodA<jchar>, // CallCharMethodA
2632 _Jv_JNI_CallMethod<jshort>, // CallShortMethod
2633 _Jv_JNI_CallMethodV<jshort>, // CallShortMethodV
2634 _Jv_JNI_CallMethodA<jshort>, // CallShortMethodA
2635 _Jv_JNI_CallMethod<jint>, // CallIntMethod
2636 _Jv_JNI_CallMethodV<jint>, // CallIntMethodV
2637 _Jv_JNI_CallMethodA<jint>, // CallIntMethodA
2638 _Jv_JNI_CallMethod<jlong>, // CallLongMethod
2639 _Jv_JNI_CallMethodV<jlong>, // CallLongMethodV
2640 _Jv_JNI_CallMethodA<jlong>, // CallLongMethodA
2641 _Jv_JNI_CallMethod<jfloat>, // CallFloatMethod
2642 _Jv_JNI_CallMethodV<jfloat>, // CallFloatMethodV
2643 _Jv_JNI_CallMethodA<jfloat>, // CallFloatMethodA
2644 _Jv_JNI_CallMethod<jdouble>, // CallDoubleMethod
2645 _Jv_JNI_CallMethodV<jdouble>, // CallDoubleMethodV
2646 _Jv_JNI_CallMethodA<jdouble>, // CallDoubleMethodA
2647 _Jv_JNI_CallVoidMethod, // CallVoidMethod
2648 _Jv_JNI_CallVoidMethodV, // CallVoidMethodV
2649 _Jv_JNI_CallVoidMethodA, // CallVoidMethodA
2651 // Nonvirtual method invocation functions follow.
2652 _Jv_JNI_CallAnyMethod<jobject, nonvirtual>, // CallNonvirtualObjectMethod
2653 _Jv_JNI_CallAnyMethodV<jobject, nonvirtual>, // CallNonvirtualObjectMethodV
2654 _Jv_JNI_CallAnyMethodA<jobject, nonvirtual>, // CallNonvirtualObjectMethodA
2655 _Jv_JNI_CallAnyMethod<jboolean, nonvirtual>, // CallNonvirtualBooleanMethod
2656 _Jv_JNI_CallAnyMethodV<jboolean, nonvirtual>, // CallNonvirtualBooleanMethodV
2657 _Jv_JNI_CallAnyMethodA<jboolean, nonvirtual>, // CallNonvirtualBooleanMethodA
2658 _Jv_JNI_CallAnyMethod<jbyte, nonvirtual>, // CallNonvirtualByteMethod
2659 _Jv_JNI_CallAnyMethodV<jbyte, nonvirtual>, // CallNonvirtualByteMethodV
2660 _Jv_JNI_CallAnyMethodA<jbyte, nonvirtual>, // CallNonvirtualByteMethodA
2661 _Jv_JNI_CallAnyMethod<jchar, nonvirtual>, // CallNonvirtualCharMethod
2662 _Jv_JNI_CallAnyMethodV<jchar, nonvirtual>, // CallNonvirtualCharMethodV
2663 _Jv_JNI_CallAnyMethodA<jchar, nonvirtual>, // CallNonvirtualCharMethodA
2664 _Jv_JNI_CallAnyMethod<jshort, nonvirtual>, // CallNonvirtualShortMethod
2665 _Jv_JNI_CallAnyMethodV<jshort, nonvirtual>, // CallNonvirtualShortMethodV
2666 _Jv_JNI_CallAnyMethodA<jshort, nonvirtual>, // CallNonvirtualShortMethodA
2667 _Jv_JNI_CallAnyMethod<jint, nonvirtual>, // CallNonvirtualIntMethod
2668 _Jv_JNI_CallAnyMethodV<jint, nonvirtual>, // CallNonvirtualIntMethodV
2669 _Jv_JNI_CallAnyMethodA<jint, nonvirtual>, // CallNonvirtualIntMethodA
2670 _Jv_JNI_CallAnyMethod<jlong, nonvirtual>, // CallNonvirtualLongMethod
2671 _Jv_JNI_CallAnyMethodV<jlong, nonvirtual>, // CallNonvirtualLongMethodV
2672 _Jv_JNI_CallAnyMethodA<jlong, nonvirtual>, // CallNonvirtualLongMethodA
2673 _Jv_JNI_CallAnyMethod<jfloat, nonvirtual>, // CallNonvirtualFloatMethod
2674 _Jv_JNI_CallAnyMethodV<jfloat, nonvirtual>, // CallNonvirtualFloatMethodV
2675 _Jv_JNI_CallAnyMethodA<jfloat, nonvirtual>, // CallNonvirtualFloatMethodA
2676 _Jv_JNI_CallAnyMethod<jdouble, nonvirtual>, // CallNonvirtualDoubleMethod
2677 _Jv_JNI_CallAnyMethodV<jdouble, nonvirtual>, // CallNonvirtualDoubleMethodV
2678 _Jv_JNI_CallAnyMethodA<jdouble, nonvirtual>, // CallNonvirtualDoubleMethodA
2679 _Jv_JNI_CallAnyVoidMethod<nonvirtual>, // CallNonvirtualVoidMethod
2680 _Jv_JNI_CallAnyVoidMethodV<nonvirtual>, // CallNonvirtualVoidMethodV
2681 _Jv_JNI_CallAnyVoidMethodA<nonvirtual>, // CallNonvirtualVoidMethodA
2683 _Jv_JNI_GetAnyFieldID<false>, // GetFieldID
2684 _Jv_JNI_GetField<jobject>, // GetObjectField
2685 _Jv_JNI_GetField<jboolean>, // GetBooleanField
2686 _Jv_JNI_GetField<jbyte>, // GetByteField
2687 _Jv_JNI_GetField<jchar>, // GetCharField
2688 _Jv_JNI_GetField<jshort>, // GetShortField
2689 _Jv_JNI_GetField<jint>, // GetIntField
2690 _Jv_JNI_GetField<jlong>, // GetLongField
2691 _Jv_JNI_GetField<jfloat>, // GetFloatField
2692 _Jv_JNI_GetField<jdouble>, // GetDoubleField
2693 _Jv_JNI_SetField, // SetObjectField
2694 _Jv_JNI_SetField, // SetBooleanField
2695 _Jv_JNI_SetField, // SetByteField
2696 _Jv_JNI_SetField, // SetCharField
2697 _Jv_JNI_SetField, // SetShortField
2698 _Jv_JNI_SetField, // SetIntField
2699 _Jv_JNI_SetField, // SetLongField
2700 _Jv_JNI_SetField, // SetFloatField
2701 _Jv_JNI_SetField, // SetDoubleField
2702 _Jv_JNI_GetAnyMethodID<true>, // GetStaticMethodID
2704 _Jv_JNI_CallStaticMethod<jobject>, // CallStaticObjectMethod
2705 _Jv_JNI_CallStaticMethodV<jobject>, // CallStaticObjectMethodV
2706 _Jv_JNI_CallStaticMethodA<jobject>, // CallStaticObjectMethodA
2707 _Jv_JNI_CallStaticMethod<jboolean>, // CallStaticBooleanMethod
2708 _Jv_JNI_CallStaticMethodV<jboolean>, // CallStaticBooleanMethodV
2709 _Jv_JNI_CallStaticMethodA<jboolean>, // CallStaticBooleanMethodA
2710 _Jv_JNI_CallStaticMethod<jbyte>, // CallStaticByteMethod
2711 _Jv_JNI_CallStaticMethodV<jbyte>, // CallStaticByteMethodV
2712 _Jv_JNI_CallStaticMethodA<jbyte>, // CallStaticByteMethodA
2713 _Jv_JNI_CallStaticMethod<jchar>, // CallStaticCharMethod
2714 _Jv_JNI_CallStaticMethodV<jchar>, // CallStaticCharMethodV
2715 _Jv_JNI_CallStaticMethodA<jchar>, // CallStaticCharMethodA
2716 _Jv_JNI_CallStaticMethod<jshort>, // CallStaticShortMethod
2717 _Jv_JNI_CallStaticMethodV<jshort>, // CallStaticShortMethodV
2718 _Jv_JNI_CallStaticMethodA<jshort>, // CallStaticShortMethodA
2719 _Jv_JNI_CallStaticMethod<jint>, // CallStaticIntMethod
2720 _Jv_JNI_CallStaticMethodV<jint>, // CallStaticIntMethodV
2721 _Jv_JNI_CallStaticMethodA<jint>, // CallStaticIntMethodA
2722 _Jv_JNI_CallStaticMethod<jlong>, // CallStaticLongMethod
2723 _Jv_JNI_CallStaticMethodV<jlong>, // CallStaticLongMethodV
2724 _Jv_JNI_CallStaticMethodA<jlong>, // CallStaticLongMethodA
2725 _Jv_JNI_CallStaticMethod<jfloat>, // CallStaticFloatMethod
2726 _Jv_JNI_CallStaticMethodV<jfloat>, // CallStaticFloatMethodV
2727 _Jv_JNI_CallStaticMethodA<jfloat>, // CallStaticFloatMethodA
2728 _Jv_JNI_CallStaticMethod<jdouble>, // CallStaticDoubleMethod
2729 _Jv_JNI_CallStaticMethodV<jdouble>, // CallStaticDoubleMethodV
2730 _Jv_JNI_CallStaticMethodA<jdouble>, // CallStaticDoubleMethodA
2731 _Jv_JNI_CallStaticVoidMethod, // CallStaticVoidMethod
2732 _Jv_JNI_CallStaticVoidMethodV, // CallStaticVoidMethodV
2733 _Jv_JNI_CallStaticVoidMethodA, // CallStaticVoidMethodA
2735 _Jv_JNI_GetAnyFieldID<true>, // GetStaticFieldID
2736 _Jv_JNI_GetStaticField<jobject>, // GetStaticObjectField
2737 _Jv_JNI_GetStaticField<jboolean>, // GetStaticBooleanField
2738 _Jv_JNI_GetStaticField<jbyte>, // GetStaticByteField
2739 _Jv_JNI_GetStaticField<jchar>, // GetStaticCharField
2740 _Jv_JNI_GetStaticField<jshort>, // GetStaticShortField
2741 _Jv_JNI_GetStaticField<jint>, // GetStaticIntField
2742 _Jv_JNI_GetStaticField<jlong>, // GetStaticLongField
2743 _Jv_JNI_GetStaticField<jfloat>, // GetStaticFloatField
2744 _Jv_JNI_GetStaticField<jdouble>, // GetStaticDoubleField
2745 _Jv_JNI_SetStaticField, // SetStaticObjectField
2746 _Jv_JNI_SetStaticField, // SetStaticBooleanField
2747 _Jv_JNI_SetStaticField, // SetStaticByteField
2748 _Jv_JNI_SetStaticField, // SetStaticCharField
2749 _Jv_JNI_SetStaticField, // SetStaticShortField
2750 _Jv_JNI_SetStaticField, // SetStaticIntField
2751 _Jv_JNI_SetStaticField, // SetStaticLongField
2752 _Jv_JNI_SetStaticField, // SetStaticFloatField
2753 _Jv_JNI_SetStaticField, // SetStaticDoubleField
2754 _Jv_JNI_NewString, // NewString
2755 _Jv_JNI_GetStringLength, // GetStringLength
2756 _Jv_JNI_GetStringChars, // GetStringChars
2757 _Jv_JNI_ReleaseStringChars, // ReleaseStringChars
2758 _Jv_JNI_NewStringUTF, // NewStringUTF
2759 _Jv_JNI_GetStringUTFLength, // GetStringUTFLength
2760 _Jv_JNI_GetStringUTFChars, // GetStringUTFChars
2761 _Jv_JNI_ReleaseStringUTFChars, // ReleaseStringUTFChars
2762 _Jv_JNI_GetArrayLength, // GetArrayLength
2763 _Jv_JNI_NewObjectArray, // NewObjectArray
2764 _Jv_JNI_GetObjectArrayElement, // GetObjectArrayElement
2765 _Jv_JNI_SetObjectArrayElement, // SetObjectArrayElement
2766 _Jv_JNI_NewPrimitiveArray<jboolean, JvPrimClass (boolean)>,
2767 // NewBooleanArray
2768 _Jv_JNI_NewPrimitiveArray<jbyte, JvPrimClass (byte)>, // NewByteArray
2769 _Jv_JNI_NewPrimitiveArray<jchar, JvPrimClass (char)>, // NewCharArray
2770 _Jv_JNI_NewPrimitiveArray<jshort, JvPrimClass (short)>, // NewShortArray
2771 _Jv_JNI_NewPrimitiveArray<jint, JvPrimClass (int)>, // NewIntArray
2772 _Jv_JNI_NewPrimitiveArray<jlong, JvPrimClass (long)>, // NewLongArray
2773 _Jv_JNI_NewPrimitiveArray<jfloat, JvPrimClass (float)>, // NewFloatArray
2774 _Jv_JNI_NewPrimitiveArray<jdouble, JvPrimClass (double)>, // NewDoubleArray
2775 _Jv_JNI_GetPrimitiveArrayElements<jboolean, JvPrimClass (boolean)>,
2776 // GetBooleanArrayElements
2777 _Jv_JNI_GetPrimitiveArrayElements<jbyte, JvPrimClass (byte)>,
2778 // GetByteArrayElements
2779 _Jv_JNI_GetPrimitiveArrayElements<jchar, JvPrimClass (char)>,
2780 // GetCharArrayElements
2781 _Jv_JNI_GetPrimitiveArrayElements<jshort, JvPrimClass (short)>,
2782 // GetShortArrayElements
2783 _Jv_JNI_GetPrimitiveArrayElements<jint, JvPrimClass (int)>,
2784 // GetIntArrayElements
2785 _Jv_JNI_GetPrimitiveArrayElements<jlong, JvPrimClass (long)>,
2786 // GetLongArrayElements
2787 _Jv_JNI_GetPrimitiveArrayElements<jfloat, JvPrimClass (float)>,
2788 // GetFloatArrayElements
2789 _Jv_JNI_GetPrimitiveArrayElements<jdouble, JvPrimClass (double)>,
2790 // GetDoubleArrayElements
2791 _Jv_JNI_ReleasePrimitiveArrayElements<jboolean, JvPrimClass (boolean)>,
2792 // ReleaseBooleanArrayElements
2793 _Jv_JNI_ReleasePrimitiveArrayElements<jbyte, JvPrimClass (byte)>,
2794 // ReleaseByteArrayElements
2795 _Jv_JNI_ReleasePrimitiveArrayElements<jchar, JvPrimClass (char)>,
2796 // ReleaseCharArrayElements
2797 _Jv_JNI_ReleasePrimitiveArrayElements<jshort, JvPrimClass (short)>,
2798 // ReleaseShortArrayElements
2799 _Jv_JNI_ReleasePrimitiveArrayElements<jint, JvPrimClass (int)>,
2800 // ReleaseIntArrayElements
2801 _Jv_JNI_ReleasePrimitiveArrayElements<jlong, JvPrimClass (long)>,
2802 // ReleaseLongArrayElements
2803 _Jv_JNI_ReleasePrimitiveArrayElements<jfloat, JvPrimClass (float)>,
2804 // ReleaseFloatArrayElements
2805 _Jv_JNI_ReleasePrimitiveArrayElements<jdouble, JvPrimClass (double)>,
2806 // ReleaseDoubleArrayElements
2807 _Jv_JNI_GetPrimitiveArrayRegion<jboolean, JvPrimClass (boolean)>,
2808 // GetBooleanArrayRegion
2809 _Jv_JNI_GetPrimitiveArrayRegion<jbyte, JvPrimClass (byte)>,
2810 // GetByteArrayRegion
2811 _Jv_JNI_GetPrimitiveArrayRegion<jchar, JvPrimClass (char)>,
2812 // GetCharArrayRegion
2813 _Jv_JNI_GetPrimitiveArrayRegion<jshort, JvPrimClass (short)>,
2814 // GetShortArrayRegion
2815 _Jv_JNI_GetPrimitiveArrayRegion<jint, JvPrimClass (int)>,
2816 // GetIntArrayRegion
2817 _Jv_JNI_GetPrimitiveArrayRegion<jlong, JvPrimClass (long)>,
2818 // GetLongArrayRegion
2819 _Jv_JNI_GetPrimitiveArrayRegion<jfloat, JvPrimClass (float)>,
2820 // GetFloatArrayRegion
2821 _Jv_JNI_GetPrimitiveArrayRegion<jdouble, JvPrimClass (double)>,
2822 // GetDoubleArrayRegion
2823 _Jv_JNI_SetPrimitiveArrayRegion<jboolean, JvPrimClass (boolean)>,
2824 // SetBooleanArrayRegion
2825 _Jv_JNI_SetPrimitiveArrayRegion<jbyte, JvPrimClass (byte)>,
2826 // SetByteArrayRegion
2827 _Jv_JNI_SetPrimitiveArrayRegion<jchar, JvPrimClass (char)>,
2828 // SetCharArrayRegion
2829 _Jv_JNI_SetPrimitiveArrayRegion<jshort, JvPrimClass (short)>,
2830 // SetShortArrayRegion
2831 _Jv_JNI_SetPrimitiveArrayRegion<jint, JvPrimClass (int)>,
2832 // SetIntArrayRegion
2833 _Jv_JNI_SetPrimitiveArrayRegion<jlong, JvPrimClass (long)>,
2834 // SetLongArrayRegion
2835 _Jv_JNI_SetPrimitiveArrayRegion<jfloat, JvPrimClass (float)>,
2836 // SetFloatArrayRegion
2837 _Jv_JNI_SetPrimitiveArrayRegion<jdouble, JvPrimClass (double)>,
2838 // SetDoubleArrayRegion
2839 _Jv_JNI_RegisterNatives, // RegisterNatives
2840 _Jv_JNI_UnregisterNatives, // UnregisterNatives
2841 _Jv_JNI_MonitorEnter, // MonitorEnter
2842 _Jv_JNI_MonitorExit, // MonitorExit
2843 _Jv_JNI_GetJavaVM, // GetJavaVM
2845 _Jv_JNI_GetStringRegion, // GetStringRegion
2846 _Jv_JNI_GetStringUTFRegion, // GetStringUTFRegion
2847 _Jv_JNI_GetPrimitiveArrayCritical, // GetPrimitiveArrayCritical
2848 _Jv_JNI_ReleasePrimitiveArrayCritical, // ReleasePrimitiveArrayCritical
2849 _Jv_JNI_GetStringCritical, // GetStringCritical
2850 _Jv_JNI_ReleaseStringCritical, // ReleaseStringCritical
2852 _Jv_JNI_NewWeakGlobalRef, // NewWeakGlobalRef
2853 _Jv_JNI_DeleteWeakGlobalRef, // DeleteWeakGlobalRef
2855 _Jv_JNI_ExceptionCheck, // ExceptionCheck
2857 _Jv_JNI_NewDirectByteBuffer, // NewDirectByteBuffer
2858 _Jv_JNI_GetDirectBufferAddress, // GetDirectBufferAddress
2859 _Jv_JNI_GetDirectBufferCapacity // GetDirectBufferCapacity
2862 struct JNIInvokeInterface _Jv_JNI_InvokeFunctions =
2864 RESERVED,
2865 RESERVED,
2866 RESERVED,
2868 _Jv_JNI_DestroyJavaVM,
2869 _Jv_JNI_AttachCurrentThread,
2870 _Jv_JNI_DetachCurrentThread,
2871 _Jv_JNI_GetEnv,
2872 _Jv_JNI_AttachCurrentThreadAsDaemon