2005-01-20 Michael Koch <konqueror@gmx.de>
[official-gcc.git] / libjava / jni.cc
bloba552360aee1ccc9f52b1f9547b19446062e7e0d3
1 // jni.cc - JNI implementation, including the jump table.
3 /* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004
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/DirectByteBufferImpl.h>
45 #include <java/util/IdentityHashMap.h>
46 #include <gnu/gcj/RawData.h>
48 #include <gcj/method.h>
49 #include <gcj/field.h>
51 #include <java-interp.h>
52 #include <java-threads.h>
54 using namespace gcj;
56 // This enum is used to select different template instantiations in
57 // the invocation code.
58 enum invocation_type
60 normal,
61 nonvirtual,
62 static_type,
63 constructor
66 // Forward declarations.
67 extern struct JNINativeInterface _Jv_JNIFunctions;
68 extern struct JNIInvokeInterface _Jv_JNI_InvokeFunctions;
70 // Number of slots in the default frame. The VM must allow at least
71 // 16.
72 #define FRAME_SIZE 16
74 // Mark value indicating this is an overflow frame.
75 #define MARK_NONE 0
76 // Mark value indicating this is a user frame.
77 #define MARK_USER 1
78 // Mark value indicating this is a system frame.
79 #define MARK_SYSTEM 2
81 // This structure is used to keep track of local references.
82 struct _Jv_JNI_LocalFrame
84 // This is true if this frame object represents a pushed frame (eg
85 // from PushLocalFrame).
86 int marker;
88 // Flag to indicate some locals were allocated.
89 int allocated_p;
91 // Number of elements in frame.
92 int size;
94 // Next frame in chain.
95 _Jv_JNI_LocalFrame *next;
97 // The elements. These are allocated using the C "struct hack".
98 jobject vec[0];
101 // This holds a reference count for all local references.
102 static java::util::IdentityHashMap *local_ref_table;
103 // This holds a reference count for all global references.
104 static java::util::IdentityHashMap *global_ref_table;
106 // The only VM.
107 static JavaVM *the_vm;
109 #ifdef ENABLE_JVMPI
110 // The only JVMPI interface description.
111 static JVMPI_Interface _Jv_JVMPI_Interface;
113 static jint
114 jvmpiEnableEvent (jint event_type, void *)
116 switch (event_type)
118 case JVMPI_EVENT_OBJECT_ALLOC:
119 _Jv_JVMPI_Notify_OBJECT_ALLOC = _Jv_JVMPI_Interface.NotifyEvent;
120 break;
122 case JVMPI_EVENT_THREAD_START:
123 _Jv_JVMPI_Notify_THREAD_START = _Jv_JVMPI_Interface.NotifyEvent;
124 break;
126 case JVMPI_EVENT_THREAD_END:
127 _Jv_JVMPI_Notify_THREAD_END = _Jv_JVMPI_Interface.NotifyEvent;
128 break;
130 default:
131 return JVMPI_NOT_AVAILABLE;
134 return JVMPI_SUCCESS;
137 static jint
138 jvmpiDisableEvent (jint event_type, void *)
140 switch (event_type)
142 case JVMPI_EVENT_OBJECT_ALLOC:
143 _Jv_JVMPI_Notify_OBJECT_ALLOC = NULL;
144 break;
146 default:
147 return JVMPI_NOT_AVAILABLE;
150 return JVMPI_SUCCESS;
152 #endif
156 void
157 _Jv_JNI_Init (void)
159 local_ref_table = new java::util::IdentityHashMap;
160 global_ref_table = new java::util::IdentityHashMap;
162 #ifdef ENABLE_JVMPI
163 _Jv_JVMPI_Interface.version = 1;
164 _Jv_JVMPI_Interface.EnableEvent = &jvmpiEnableEvent;
165 _Jv_JVMPI_Interface.DisableEvent = &jvmpiDisableEvent;
166 _Jv_JVMPI_Interface.EnableGC = &_Jv_EnableGC;
167 _Jv_JVMPI_Interface.DisableGC = &_Jv_DisableGC;
168 _Jv_JVMPI_Interface.RunGC = &_Jv_RunGC;
169 #endif
172 // Tell the GC that a certain pointer is live.
173 static void
174 mark_for_gc (jobject obj, java::util::IdentityHashMap *ref_table)
176 JvSynchronize sync (ref_table);
178 using namespace java::lang;
179 Integer *refcount = (Integer *) ref_table->get (obj);
180 jint val = (refcount == NULL) ? 0 : refcount->intValue ();
181 // FIXME: what about out of memory error?
182 ref_table->put (obj, new Integer (val + 1));
185 // Unmark a pointer.
186 static void
187 unmark_for_gc (jobject obj, java::util::IdentityHashMap *ref_table)
189 JvSynchronize sync (ref_table);
191 using namespace java::lang;
192 Integer *refcount = (Integer *) ref_table->get (obj);
193 JvAssert (refcount);
194 jint val = refcount->intValue () - 1;
195 JvAssert (val >= 0);
196 if (val == 0)
197 ref_table->remove (obj);
198 else
199 // FIXME: what about out of memory error?
200 ref_table->put (obj, new Integer (val));
203 // "Unwrap" some random non-reference type. This exists to simplify
204 // other template functions.
205 template<typename T>
206 static T
207 unwrap (T val)
209 return val;
212 // Unwrap a weak reference, if required.
213 template<typename T>
214 static T *
215 unwrap (T *obj)
217 using namespace gnu::gcj::runtime;
218 // We can compare the class directly because JNIWeakRef is `final'.
219 // Doing it this way is much faster.
220 if (obj == NULL || obj->getClass () != &JNIWeakRef::class$)
221 return obj;
222 JNIWeakRef *wr = reinterpret_cast<JNIWeakRef *> (obj);
223 return reinterpret_cast<T *> (wr->get ());
228 static jobject
229 (JNICALL _Jv_JNI_NewGlobalRef) (JNIEnv *, jobject obj)
231 // This seems weird but I think it is correct.
232 obj = unwrap (obj);
233 mark_for_gc (obj, global_ref_table);
234 return obj;
237 static void
238 (JNICALL _Jv_JNI_DeleteGlobalRef) (JNIEnv *, jobject obj)
240 // This seems weird but I think it is correct.
241 obj = unwrap (obj);
242 unmark_for_gc (obj, global_ref_table);
245 static void
246 (JNICALL _Jv_JNI_DeleteLocalRef) (JNIEnv *env, jobject obj)
248 _Jv_JNI_LocalFrame *frame;
250 // This seems weird but I think it is correct.
251 obj = unwrap (obj);
253 for (frame = env->locals; frame != NULL; frame = frame->next)
255 for (int i = 0; i < frame->size; ++i)
257 if (frame->vec[i] == obj)
259 frame->vec[i] = NULL;
260 unmark_for_gc (obj, local_ref_table);
261 return;
265 // Don't go past a marked frame.
266 JvAssert (frame->marker == MARK_NONE);
269 JvAssert (0);
272 static jint
273 (JNICALL _Jv_JNI_EnsureLocalCapacity) (JNIEnv *env, jint size)
275 // It is easier to just always allocate a new frame of the requested
276 // size. This isn't the most efficient thing, but for now we don't
277 // care. Note that _Jv_JNI_PushLocalFrame relies on this right now.
279 _Jv_JNI_LocalFrame *frame;
282 frame = (_Jv_JNI_LocalFrame *) _Jv_Malloc (sizeof (_Jv_JNI_LocalFrame)
283 + size * sizeof (jobject));
285 catch (jthrowable t)
287 env->ex = t;
288 return JNI_ERR;
291 frame->marker = MARK_NONE;
292 frame->size = size;
293 frame->allocated_p = 0;
294 memset (&frame->vec[0], 0, size * sizeof (jobject));
295 frame->next = env->locals;
296 env->locals = frame;
298 return 0;
301 static jint
302 (JNICALL _Jv_JNI_PushLocalFrame) (JNIEnv *env, jint size)
304 jint r = _Jv_JNI_EnsureLocalCapacity (env, size);
305 if (r < 0)
306 return r;
308 // The new frame is on top.
309 env->locals->marker = MARK_USER;
311 return 0;
314 static jobject
315 (JNICALL _Jv_JNI_NewLocalRef) (JNIEnv *env, jobject obj)
317 // This seems weird but I think it is correct.
318 obj = unwrap (obj);
320 // Try to find an open slot somewhere in the topmost frame.
321 _Jv_JNI_LocalFrame *frame = env->locals;
322 bool done = false, set = false;
323 for (; frame != NULL && ! done; frame = frame->next)
325 for (int i = 0; i < frame->size; ++i)
327 if (frame->vec[i] == NULL)
329 set = true;
330 done = true;
331 frame->vec[i] = obj;
332 frame->allocated_p = 1;
333 break;
337 // If we found a slot, or if the frame we just searched is the
338 // mark frame, then we are done.
339 if (done || frame == NULL || frame->marker != MARK_NONE)
340 break;
343 if (! set)
345 // No slots, so we allocate a new frame. According to the spec
346 // we could just die here. FIXME: return value.
347 _Jv_JNI_EnsureLocalCapacity (env, 16);
348 // We know the first element of the new frame will be ok.
349 env->locals->vec[0] = obj;
350 env->locals->allocated_p = 1;
353 mark_for_gc (obj, local_ref_table);
354 return obj;
357 static jobject
358 (JNICALL _Jv_JNI_PopLocalFrame) (JNIEnv *env, jobject result, int stop)
360 _Jv_JNI_LocalFrame *rf = env->locals;
362 bool done = false;
363 while (rf != NULL && ! done)
365 for (int i = 0; i < rf->size; ++i)
366 if (rf->vec[i] != NULL)
367 unmark_for_gc (rf->vec[i], local_ref_table);
369 // If the frame we just freed is the marker frame, we are done.
370 done = (rf->marker == stop);
372 _Jv_JNI_LocalFrame *n = rf->next;
373 // When N==NULL, we've reached the reusable bottom_locals, and we must
374 // not free it. However, we must be sure to clear all its elements.
375 if (n == NULL)
377 if (rf->allocated_p)
378 memset (&rf->vec[0], 0, rf->size * sizeof (jobject));
379 rf->allocated_p = 0;
380 rf = NULL;
381 break;
384 _Jv_Free (rf);
385 rf = n;
388 // Update the local frame information.
389 env->locals = rf;
391 return result == NULL ? NULL : _Jv_JNI_NewLocalRef (env, result);
394 static jobject
395 (JNICALL _Jv_JNI_PopLocalFrame) (JNIEnv *env, jobject result)
397 return _Jv_JNI_PopLocalFrame (env, result, MARK_USER);
400 // Make sure an array's type is compatible with the type of the
401 // destination.
402 template<typename T>
403 static bool
404 _Jv_JNI_check_types (JNIEnv *env, JArray<T> *array, jclass K)
406 jclass klass = array->getClass()->getComponentType();
407 if (__builtin_expect (klass != K, false))
409 env->ex = new java::lang::IllegalAccessError ();
410 return false;
412 else
413 return true;
416 // Pop a `system' frame from the stack. This is `extern "C"' as it is
417 // used by the compiler.
418 extern "C" void
419 _Jv_JNI_PopSystemFrame (JNIEnv *env)
421 // Only enter slow path when we're not at the bottom, or there have been
422 // allocations. Usually this is false and we can just null out the locals
423 // field.
425 if (__builtin_expect ((env->locals->next
426 || env->locals->allocated_p), false))
427 _Jv_JNI_PopLocalFrame (env, NULL, MARK_SYSTEM);
428 else
429 env->locals = NULL;
431 if (__builtin_expect (env->ex != NULL, false))
433 jthrowable t = env->ex;
434 env->ex = NULL;
435 throw t;
439 template<typename T> T extract_from_jvalue(jvalue const & t);
440 template<> jboolean extract_from_jvalue(jvalue const & jv) { return jv.z; }
441 template<> jbyte extract_from_jvalue(jvalue const & jv) { return jv.b; }
442 template<> jchar extract_from_jvalue(jvalue const & jv) { return jv.c; }
443 template<> jshort extract_from_jvalue(jvalue const & jv) { return jv.s; }
444 template<> jint extract_from_jvalue(jvalue const & jv) { return jv.i; }
445 template<> jlong extract_from_jvalue(jvalue const & jv) { return jv.j; }
446 template<> jfloat extract_from_jvalue(jvalue const & jv) { return jv.f; }
447 template<> jdouble extract_from_jvalue(jvalue const & jv) { return jv.d; }
448 template<> jobject extract_from_jvalue(jvalue const & jv) { return jv.l; }
451 // This function is used from other template functions. It wraps the
452 // return value appropriately; we specialize it so that object returns
453 // are turned into local references.
454 template<typename T>
455 static T
456 wrap_value (JNIEnv *, T value)
458 return value;
461 // This specialization is used for jobject, jclass, jstring, jarray,
462 // etc.
463 template<typename R, typename T>
464 static T *
465 wrap_value (JNIEnv *env, T *value)
467 return (value == NULL
468 ? value
469 : (T *) _Jv_JNI_NewLocalRef (env, (jobject) value));
474 static jint
475 (JNICALL _Jv_JNI_GetVersion) (JNIEnv *)
477 return JNI_VERSION_1_4;
480 static jclass
481 (JNICALL _Jv_JNI_DefineClass) (JNIEnv *env, const char *name, jobject loader,
482 const jbyte *buf, jsize bufLen)
486 loader = unwrap (loader);
488 jstring sname = JvNewStringUTF (name);
489 jbyteArray bytes = JvNewByteArray (bufLen);
491 jbyte *elts = elements (bytes);
492 memcpy (elts, buf, bufLen * sizeof (jbyte));
494 java::lang::ClassLoader *l
495 = reinterpret_cast<java::lang::ClassLoader *> (loader);
497 jclass result = l->defineClass (sname, bytes, 0, bufLen);
498 return (jclass) wrap_value (env, result);
500 catch (jthrowable t)
502 env->ex = t;
503 return NULL;
507 static jclass
508 (JNICALL _Jv_JNI_FindClass) (JNIEnv *env, const char *name)
510 // FIXME: assume that NAME isn't too long.
511 int len = strlen (name);
512 char s[len + 1];
513 for (int i = 0; i <= len; ++i)
514 s[i] = (name[i] == '/') ? '.' : name[i];
516 jclass r = NULL;
519 // This might throw an out of memory exception.
520 jstring n = JvNewStringUTF (s);
522 java::lang::ClassLoader *loader = NULL;
523 if (env->klass != NULL)
524 loader = env->klass->getClassLoaderInternal ();
526 if (loader == NULL)
528 // FIXME: should use getBaseClassLoader, but we don't have that
529 // yet.
530 loader = java::lang::ClassLoader::getSystemClassLoader ();
533 r = loader->loadClass (n);
535 catch (jthrowable t)
537 env->ex = t;
540 return (jclass) wrap_value (env, r);
543 static jclass
544 (JNICALL _Jv_JNI_GetSuperclass) (JNIEnv *env, jclass clazz)
546 return (jclass) wrap_value (env, unwrap (clazz)->getSuperclass ());
549 static jboolean
550 (JNICALL _Jv_JNI_IsAssignableFrom) (JNIEnv *, jclass clazz1, jclass clazz2)
552 return unwrap (clazz1)->isAssignableFrom (unwrap (clazz2));
555 static jint
556 (JNICALL _Jv_JNI_Throw) (JNIEnv *env, jthrowable obj)
558 // We check in case the user did some funky cast.
559 obj = unwrap (obj);
560 JvAssert (obj != NULL && java::lang::Throwable::class$.isInstance (obj));
561 env->ex = obj;
562 return 0;
565 static jint
566 (JNICALL _Jv_JNI_ThrowNew) (JNIEnv *env, jclass clazz, const char *message)
568 using namespace java::lang::reflect;
570 clazz = unwrap (clazz);
571 JvAssert (java::lang::Throwable::class$.isAssignableFrom (clazz));
573 int r = JNI_OK;
576 JArray<jclass> *argtypes
577 = (JArray<jclass> *) JvNewObjectArray (1, &java::lang::Class::class$,
578 NULL);
580 jclass *elts = elements (argtypes);
581 elts[0] = &StringClass;
583 Constructor *cons = clazz->getConstructor (argtypes);
585 jobjectArray values = JvNewObjectArray (1, &StringClass, NULL);
586 jobject *velts = elements (values);
587 velts[0] = JvNewStringUTF (message);
589 jobject obj = cons->newInstance (values);
591 env->ex = reinterpret_cast<jthrowable> (obj);
593 catch (jthrowable t)
595 env->ex = t;
596 r = JNI_ERR;
599 return r;
602 static jthrowable
603 (JNICALL _Jv_JNI_ExceptionOccurred) (JNIEnv *env)
605 return (jthrowable) wrap_value (env, env->ex);
608 static void
609 (JNICALL _Jv_JNI_ExceptionDescribe) (JNIEnv *env)
611 if (env->ex != NULL)
612 env->ex->printStackTrace();
615 static void
616 (JNICALL _Jv_JNI_ExceptionClear) (JNIEnv *env)
618 env->ex = NULL;
621 static jboolean
622 (JNICALL _Jv_JNI_ExceptionCheck) (JNIEnv *env)
624 return env->ex != NULL;
627 static void
628 (JNICALL _Jv_JNI_FatalError) (JNIEnv *, const char *message)
630 JvFail (message);
635 static jboolean
636 (JNICALL _Jv_JNI_IsSameObject) (JNIEnv *, jobject obj1, jobject obj2)
638 return unwrap (obj1) == unwrap (obj2);
641 static jobject
642 (JNICALL _Jv_JNI_AllocObject) (JNIEnv *env, jclass clazz)
644 jobject obj = NULL;
645 using namespace java::lang::reflect;
649 clazz = unwrap (clazz);
650 JvAssert (clazz && ! clazz->isArray ());
651 if (clazz->isInterface() || Modifier::isAbstract(clazz->getModifiers()))
652 env->ex = new java::lang::InstantiationException ();
653 else
654 obj = _Jv_AllocObject (clazz);
656 catch (jthrowable t)
658 env->ex = t;
661 return wrap_value (env, obj);
664 static jclass
665 (JNICALL _Jv_JNI_GetObjectClass) (JNIEnv *env, jobject obj)
667 obj = unwrap (obj);
668 JvAssert (obj);
669 return (jclass) wrap_value (env, obj->getClass());
672 static jboolean
673 (JNICALL _Jv_JNI_IsInstanceOf) (JNIEnv *, jobject obj, jclass clazz)
675 return unwrap (clazz)->isInstance(unwrap (obj));
681 // This section concerns method invocation.
684 template<jboolean is_static>
685 static jmethodID
686 (JNICALL _Jv_JNI_GetAnyMethodID) (JNIEnv *env, jclass clazz,
687 const char *name, const char *sig)
691 clazz = unwrap (clazz);
692 _Jv_InitClass (clazz);
694 _Jv_Utf8Const *name_u = _Jv_makeUtf8Const ((char *) name, -1);
696 // FIXME: assume that SIG isn't too long.
697 int len = strlen (sig);
698 char s[len + 1];
699 for (int i = 0; i <= len; ++i)
700 s[i] = (sig[i] == '/') ? '.' : sig[i];
701 _Jv_Utf8Const *sig_u = _Jv_makeUtf8Const ((char *) s, -1);
703 JvAssert (! clazz->isPrimitive());
705 using namespace java::lang::reflect;
707 while (clazz != NULL)
709 jint count = JvNumMethods (clazz);
710 jmethodID meth = JvGetFirstMethod (clazz);
712 for (jint i = 0; i < count; ++i)
714 if (((is_static && Modifier::isStatic (meth->accflags))
715 || (! is_static && ! Modifier::isStatic (meth->accflags)))
716 && _Jv_equalUtf8Consts (meth->name, name_u)
717 && _Jv_equalUtf8Consts (meth->signature, sig_u))
718 return meth;
720 meth = meth->getNextMethod();
723 clazz = clazz->getSuperclass ();
726 java::lang::StringBuffer *name_sig =
727 new java::lang::StringBuffer (JvNewStringUTF (name));
728 name_sig->append ((jchar) ' ')->append (JvNewStringUTF (s));
729 env->ex = new java::lang::NoSuchMethodError (name_sig->toString ());
731 catch (jthrowable t)
733 env->ex = t;
736 return NULL;
739 // This is a helper function which turns a va_list into an array of
740 // `jvalue's. It needs signature information in order to do its work.
741 // The array of values must already be allocated.
742 static void
743 array_from_valist (jvalue *values, JArray<jclass> *arg_types, va_list vargs)
745 jclass *arg_elts = elements (arg_types);
746 for (int i = 0; i < arg_types->length; ++i)
748 // Here we assume that sizeof(int) >= sizeof(jint), because we
749 // use `int' when decoding the varargs. Likewise for
750 // float, and double. Also we assume that sizeof(jlong) >=
751 // sizeof(int), i.e. that jlong values are not further
752 // promoted.
753 JvAssert (sizeof (int) >= sizeof (jint));
754 JvAssert (sizeof (jlong) >= sizeof (int));
755 JvAssert (sizeof (double) >= sizeof (jfloat));
756 JvAssert (sizeof (double) >= sizeof (jdouble));
757 if (arg_elts[i] == JvPrimClass (byte))
758 values[i].b = (jbyte) va_arg (vargs, int);
759 else if (arg_elts[i] == JvPrimClass (short))
760 values[i].s = (jshort) va_arg (vargs, int);
761 else if (arg_elts[i] == JvPrimClass (int))
762 values[i].i = (jint) va_arg (vargs, int);
763 else if (arg_elts[i] == JvPrimClass (long))
764 values[i].j = (jlong) va_arg (vargs, jlong);
765 else if (arg_elts[i] == JvPrimClass (float))
766 values[i].f = (jfloat) va_arg (vargs, double);
767 else if (arg_elts[i] == JvPrimClass (double))
768 values[i].d = (jdouble) va_arg (vargs, double);
769 else if (arg_elts[i] == JvPrimClass (boolean))
770 values[i].z = (jboolean) va_arg (vargs, int);
771 else if (arg_elts[i] == JvPrimClass (char))
772 values[i].c = (jchar) va_arg (vargs, int);
773 else
775 // An object.
776 values[i].l = unwrap (va_arg (vargs, jobject));
781 // This can call any sort of method: virtual, "nonvirtual", static, or
782 // constructor.
783 template<typename T, invocation_type style>
784 static T
785 (JNICALL _Jv_JNI_CallAnyMethodV) (JNIEnv *env, jobject obj, jclass klass,
786 jmethodID id, va_list vargs)
788 obj = unwrap (obj);
789 klass = unwrap (klass);
791 jclass decl_class = klass ? klass : obj->getClass ();
792 JvAssert (decl_class != NULL);
794 jclass return_type;
795 JArray<jclass> *arg_types;
799 _Jv_GetTypesFromSignature (id, decl_class,
800 &arg_types, &return_type);
802 jvalue args[arg_types->length];
803 array_from_valist (args, arg_types, vargs);
805 // For constructors we need to pass the Class we are instantiating.
806 if (style == constructor)
807 return_type = klass;
809 jvalue result;
810 _Jv_CallAnyMethodA (obj, return_type, id,
811 style == constructor,
812 style == normal,
813 arg_types, args, &result);
815 return wrap_value (env, extract_from_jvalue<T>(result));
817 catch (jthrowable t)
819 env->ex = t;
822 return wrap_value (env, (T) 0);
825 template<typename T, invocation_type style>
826 static T
827 (JNICALL _Jv_JNI_CallAnyMethod) (JNIEnv *env, jobject obj, jclass klass,
828 jmethodID method, ...)
830 va_list args;
831 T result;
833 va_start (args, method);
834 result = _Jv_JNI_CallAnyMethodV<T, style> (env, obj, klass, method, args);
835 va_end (args);
837 return result;
840 template<typename T, invocation_type style>
841 static T
842 (JNICALL _Jv_JNI_CallAnyMethodA) (JNIEnv *env, jobject obj, jclass klass,
843 jmethodID id, jvalue *args)
845 obj = unwrap (obj);
846 klass = unwrap (klass);
848 jclass decl_class = klass ? klass : obj->getClass ();
849 JvAssert (decl_class != NULL);
851 jclass return_type;
852 JArray<jclass> *arg_types;
855 _Jv_GetTypesFromSignature (id, decl_class,
856 &arg_types, &return_type);
858 // For constructors we need to pass the Class we are instantiating.
859 if (style == constructor)
860 return_type = klass;
862 // Unwrap arguments as required. Eww.
863 jclass *type_elts = elements (arg_types);
864 jvalue arg_copy[arg_types->length];
865 for (int i = 0; i < arg_types->length; ++i)
867 if (type_elts[i]->isPrimitive ())
868 arg_copy[i] = args[i];
869 else
870 arg_copy[i].l = unwrap (args[i].l);
873 jvalue result;
874 _Jv_CallAnyMethodA (obj, return_type, id,
875 style == constructor,
876 style == normal,
877 arg_types, arg_copy, &result);
879 return wrap_value (env, extract_from_jvalue<T>(result));
881 catch (jthrowable t)
883 env->ex = t;
886 return wrap_value (env, (T) 0);
889 template<invocation_type style>
890 static void
891 (JNICALL _Jv_JNI_CallAnyVoidMethodV) (JNIEnv *env, jobject obj, jclass klass,
892 jmethodID id, va_list vargs)
894 obj = unwrap (obj);
895 klass = unwrap (klass);
897 jclass decl_class = klass ? klass : obj->getClass ();
898 JvAssert (decl_class != NULL);
900 jclass return_type;
901 JArray<jclass> *arg_types;
904 _Jv_GetTypesFromSignature (id, decl_class,
905 &arg_types, &return_type);
907 jvalue args[arg_types->length];
908 array_from_valist (args, arg_types, vargs);
910 // For constructors we need to pass the Class we are instantiating.
911 if (style == constructor)
912 return_type = klass;
914 _Jv_CallAnyMethodA (obj, return_type, id,
915 style == constructor,
916 style == normal,
917 arg_types, args, NULL);
919 catch (jthrowable t)
921 env->ex = t;
925 template<invocation_type style>
926 static void
927 (JNICALL _Jv_JNI_CallAnyVoidMethod) (JNIEnv *env, jobject obj, jclass klass,
928 jmethodID method, ...)
930 va_list args;
932 va_start (args, method);
933 _Jv_JNI_CallAnyVoidMethodV<style> (env, obj, klass, method, args);
934 va_end (args);
937 template<invocation_type style>
938 static void
939 (JNICALL _Jv_JNI_CallAnyVoidMethodA) (JNIEnv *env, jobject obj, jclass klass,
940 jmethodID id, jvalue *args)
942 jclass decl_class = klass ? klass : obj->getClass ();
943 JvAssert (decl_class != NULL);
945 jclass return_type;
946 JArray<jclass> *arg_types;
949 _Jv_GetTypesFromSignature (id, decl_class,
950 &arg_types, &return_type);
952 // Unwrap arguments as required. Eww.
953 jclass *type_elts = elements (arg_types);
954 jvalue arg_copy[arg_types->length];
955 for (int i = 0; i < arg_types->length; ++i)
957 if (type_elts[i]->isPrimitive ())
958 arg_copy[i] = args[i];
959 else
960 arg_copy[i].l = unwrap (args[i].l);
963 _Jv_CallAnyMethodA (obj, return_type, id,
964 style == constructor,
965 style == normal,
966 arg_types, args, NULL);
968 catch (jthrowable t)
970 env->ex = t;
974 // Functions with this signature are used to implement functions in
975 // the CallMethod family.
976 template<typename T>
977 static T
978 (JNICALL _Jv_JNI_CallMethodV) (JNIEnv *env, jobject obj,
979 jmethodID id, va_list args)
981 return _Jv_JNI_CallAnyMethodV<T, normal> (env, obj, NULL, id, args);
984 // Functions with this signature are used to implement functions in
985 // the CallMethod family.
986 template<typename T>
987 static T
988 (JNICALL _Jv_JNI_CallMethod) (JNIEnv *env, jobject obj, jmethodID id, ...)
990 va_list args;
991 T result;
993 va_start (args, id);
994 result = _Jv_JNI_CallAnyMethodV<T, normal> (env, obj, NULL, id, args);
995 va_end (args);
997 return result;
1000 // Functions with this signature are used to implement functions in
1001 // the CallMethod family.
1002 template<typename T>
1003 static T
1004 (JNICALL _Jv_JNI_CallMethodA) (JNIEnv *env, jobject obj,
1005 jmethodID id, jvalue *args)
1007 return _Jv_JNI_CallAnyMethodA<T, normal> (env, obj, NULL, id, args);
1010 static void
1011 (JNICALL _Jv_JNI_CallVoidMethodV) (JNIEnv *env, jobject obj,
1012 jmethodID id, va_list args)
1014 _Jv_JNI_CallAnyVoidMethodV<normal> (env, obj, NULL, id, args);
1017 static void
1018 (JNICALL _Jv_JNI_CallVoidMethod) (JNIEnv *env, jobject obj, jmethodID id, ...)
1020 va_list args;
1022 va_start (args, id);
1023 _Jv_JNI_CallAnyVoidMethodV<normal> (env, obj, NULL, id, args);
1024 va_end (args);
1027 static void
1028 (JNICALL _Jv_JNI_CallVoidMethodA) (JNIEnv *env, jobject obj,
1029 jmethodID id, jvalue *args)
1031 _Jv_JNI_CallAnyVoidMethodA<normal> (env, obj, NULL, id, args);
1034 // Functions with this signature are used to implement functions in
1035 // the CallStaticMethod family.
1036 template<typename T>
1037 static T
1038 (JNICALL _Jv_JNI_CallStaticMethodV) (JNIEnv *env, jclass klass,
1039 jmethodID id, va_list args)
1041 JvAssert (((id->accflags) & java::lang::reflect::Modifier::STATIC));
1042 JvAssert (java::lang::Class::class$.isInstance (unwrap (klass)));
1044 return _Jv_JNI_CallAnyMethodV<T, static_type> (env, NULL, klass, id, args);
1047 // Functions with this signature are used to implement functions in
1048 // the CallStaticMethod family.
1049 template<typename T>
1050 static T
1051 (JNICALL _Jv_JNI_CallStaticMethod) (JNIEnv *env, jclass klass,
1052 jmethodID id, ...)
1054 va_list args;
1055 T result;
1057 JvAssert (((id->accflags) & java::lang::reflect::Modifier::STATIC));
1058 JvAssert (java::lang::Class::class$.isInstance (unwrap (klass)));
1060 va_start (args, id);
1061 result = _Jv_JNI_CallAnyMethodV<T, static_type> (env, NULL, klass,
1062 id, args);
1063 va_end (args);
1065 return result;
1068 // Functions with this signature are used to implement functions in
1069 // the CallStaticMethod family.
1070 template<typename T>
1071 static T
1072 (JNICALL _Jv_JNI_CallStaticMethodA) (JNIEnv *env, jclass klass, jmethodID id,
1073 jvalue *args)
1075 JvAssert (((id->accflags) & java::lang::reflect::Modifier::STATIC));
1076 JvAssert (java::lang::Class::class$.isInstance (unwrap (klass)));
1078 return _Jv_JNI_CallAnyMethodA<T, static_type> (env, NULL, klass, id, args);
1081 static void
1082 (JNICALL _Jv_JNI_CallStaticVoidMethodV) (JNIEnv *env, jclass klass,
1083 jmethodID id, va_list args)
1085 _Jv_JNI_CallAnyVoidMethodV<static_type> (env, NULL, klass, id, args);
1088 static void
1089 (JNICALL _Jv_JNI_CallStaticVoidMethod) (JNIEnv *env, jclass klass,
1090 jmethodID id, ...)
1092 va_list args;
1094 va_start (args, id);
1095 _Jv_JNI_CallAnyVoidMethodV<static_type> (env, NULL, klass, id, args);
1096 va_end (args);
1099 static void
1100 (JNICALL _Jv_JNI_CallStaticVoidMethodA) (JNIEnv *env, jclass klass,
1101 jmethodID id, jvalue *args)
1103 _Jv_JNI_CallAnyVoidMethodA<static_type> (env, NULL, klass, id, args);
1106 static jobject
1107 (JNICALL _Jv_JNI_NewObjectV) (JNIEnv *env, jclass klass,
1108 jmethodID id, va_list args)
1110 JvAssert (klass && ! klass->isArray ());
1111 JvAssert (! strcmp (id->name->data, "<init>")
1112 && id->signature->length > 2
1113 && id->signature->data[0] == '('
1114 && ! strcmp (&id->signature->data[id->signature->length - 2],
1115 ")V"));
1117 return _Jv_JNI_CallAnyMethodV<jobject, constructor> (env, NULL, klass,
1118 id, args);
1121 static jobject
1122 (JNICALL _Jv_JNI_NewObject) (JNIEnv *env, jclass klass, jmethodID id, ...)
1124 JvAssert (klass && ! klass->isArray ());
1125 JvAssert (! strcmp (id->name->data, "<init>")
1126 && id->signature->length > 2
1127 && id->signature->data[0] == '('
1128 && ! strcmp (&id->signature->data[id->signature->length - 2],
1129 ")V"));
1131 va_list args;
1132 jobject result;
1134 va_start (args, id);
1135 result = _Jv_JNI_CallAnyMethodV<jobject, constructor> (env, NULL, klass,
1136 id, args);
1137 va_end (args);
1139 return result;
1142 static jobject
1143 (JNICALL _Jv_JNI_NewObjectA) (JNIEnv *env, jclass klass, jmethodID id,
1144 jvalue *args)
1146 JvAssert (klass && ! klass->isArray ());
1147 JvAssert (! strcmp (id->name->data, "<init>")
1148 && id->signature->length > 2
1149 && id->signature->data[0] == '('
1150 && ! strcmp (&id->signature->data[id->signature->length - 2],
1151 ")V"));
1153 return _Jv_JNI_CallAnyMethodA<jobject, constructor> (env, NULL, klass,
1154 id, args);
1159 template<typename T>
1160 static T
1161 (JNICALL _Jv_JNI_GetField) (JNIEnv *env, jobject obj, jfieldID field)
1163 obj = unwrap (obj);
1164 JvAssert (obj);
1165 T *ptr = (T *) ((char *) obj + field->getOffset ());
1166 return wrap_value (env, *ptr);
1169 template<typename T>
1170 static void
1171 (JNICALL _Jv_JNI_SetField) (JNIEnv *, jobject obj, jfieldID field, T value)
1173 obj = unwrap (obj);
1174 value = unwrap (value);
1176 JvAssert (obj);
1177 T *ptr = (T *) ((char *) obj + field->getOffset ());
1178 *ptr = value;
1181 template<jboolean is_static>
1182 static jfieldID
1183 (JNICALL _Jv_JNI_GetAnyFieldID) (JNIEnv *env, jclass clazz,
1184 const char *name, const char *sig)
1188 clazz = unwrap (clazz);
1190 _Jv_InitClass (clazz);
1192 _Jv_Utf8Const *a_name = _Jv_makeUtf8Const ((char *) name, -1);
1194 // FIXME: assume that SIG isn't too long.
1195 int len = strlen (sig);
1196 char s[len + 1];
1197 for (int i = 0; i <= len; ++i)
1198 s[i] = (sig[i] == '/') ? '.' : sig[i];
1199 jclass field_class = _Jv_FindClassFromSignature ((char *) s, NULL);
1201 // FIXME: what if field_class == NULL?
1203 java::lang::ClassLoader *loader = clazz->getClassLoaderInternal ();
1204 while (clazz != NULL)
1206 // We acquire the class lock so that fields aren't resolved
1207 // while we are running.
1208 JvSynchronize sync (clazz);
1210 jint count = (is_static
1211 ? JvNumStaticFields (clazz)
1212 : JvNumInstanceFields (clazz));
1213 jfieldID field = (is_static
1214 ? JvGetFirstStaticField (clazz)
1215 : JvGetFirstInstanceField (clazz));
1216 for (jint i = 0; i < count; ++i)
1218 _Jv_Utf8Const *f_name = field->getNameUtf8Const(clazz);
1220 // The field might be resolved or it might not be. It
1221 // is much simpler to always resolve it.
1222 _Jv_ResolveField (field, loader);
1223 if (_Jv_equalUtf8Consts (f_name, a_name)
1224 && field->getClass() == field_class)
1225 return field;
1227 field = field->getNextField ();
1230 clazz = clazz->getSuperclass ();
1233 env->ex = new java::lang::NoSuchFieldError ();
1235 catch (jthrowable t)
1237 env->ex = t;
1239 return NULL;
1242 template<typename T>
1243 static T
1244 (JNICALL _Jv_JNI_GetStaticField) (JNIEnv *env, jclass, jfieldID field)
1246 T *ptr = (T *) field->u.addr;
1247 return wrap_value (env, *ptr);
1250 template<typename T>
1251 static void
1252 (JNICALL _Jv_JNI_SetStaticField) (JNIEnv *, jclass, jfieldID field, T value)
1254 value = unwrap (value);
1255 T *ptr = (T *) field->u.addr;
1256 *ptr = value;
1259 static jstring
1260 (JNICALL _Jv_JNI_NewString) (JNIEnv *env, const jchar *unichars, jsize len)
1264 jstring r = _Jv_NewString (unichars, len);
1265 return (jstring) wrap_value (env, r);
1267 catch (jthrowable t)
1269 env->ex = t;
1270 return NULL;
1274 static jsize
1275 (JNICALL _Jv_JNI_GetStringLength) (JNIEnv *, jstring string)
1277 return unwrap (string)->length();
1280 static const jchar *
1281 (JNICALL _Jv_JNI_GetStringChars) (JNIEnv *, jstring string, jboolean *isCopy)
1283 string = unwrap (string);
1284 jchar *result = _Jv_GetStringChars (string);
1285 mark_for_gc (string, global_ref_table);
1286 if (isCopy)
1287 *isCopy = false;
1288 return (const jchar *) result;
1291 static void
1292 (JNICALL _Jv_JNI_ReleaseStringChars) (JNIEnv *, jstring string, const jchar *)
1294 unmark_for_gc (unwrap (string), global_ref_table);
1297 static jstring
1298 (JNICALL _Jv_JNI_NewStringUTF) (JNIEnv *env, const char *bytes)
1302 jstring result = JvNewStringUTF (bytes);
1303 return (jstring) wrap_value (env, result);
1305 catch (jthrowable t)
1307 env->ex = t;
1308 return NULL;
1312 static jsize
1313 (JNICALL _Jv_JNI_GetStringUTFLength) (JNIEnv *, jstring string)
1315 return JvGetStringUTFLength (unwrap (string));
1318 static const char *
1319 (JNICALL _Jv_JNI_GetStringUTFChars) (JNIEnv *env, jstring string,
1320 jboolean *isCopy)
1324 string = unwrap (string);
1325 if (string == NULL)
1326 return NULL;
1327 jsize len = JvGetStringUTFLength (string);
1328 char *r = (char *) _Jv_Malloc (len + 1);
1329 JvGetStringUTFRegion (string, 0, string->length(), r);
1330 r[len] = '\0';
1332 if (isCopy)
1333 *isCopy = true;
1335 return (const char *) r;
1337 catch (jthrowable t)
1339 env->ex = t;
1340 return NULL;
1344 static void
1345 (JNICALL _Jv_JNI_ReleaseStringUTFChars) (JNIEnv *, jstring, const char *utf)
1347 _Jv_Free ((void *) utf);
1350 static void
1351 (JNICALL _Jv_JNI_GetStringRegion) (JNIEnv *env, jstring string, jsize start,
1352 jsize len, jchar *buf)
1354 string = unwrap (string);
1355 jchar *result = _Jv_GetStringChars (string);
1356 if (start < 0 || start > string->length ()
1357 || len < 0 || start + len > string->length ())
1361 env->ex = new java::lang::StringIndexOutOfBoundsException ();
1363 catch (jthrowable t)
1365 env->ex = t;
1368 else
1369 memcpy (buf, &result[start], len * sizeof (jchar));
1372 static void
1373 (JNICALL _Jv_JNI_GetStringUTFRegion) (JNIEnv *env, jstring str, jsize start,
1374 jsize len, char *buf)
1376 str = unwrap (str);
1378 if (start < 0 || start > str->length ()
1379 || len < 0 || start + len > str->length ())
1383 env->ex = new java::lang::StringIndexOutOfBoundsException ();
1385 catch (jthrowable t)
1387 env->ex = t;
1390 else
1391 _Jv_GetStringUTFRegion (str, start, len, buf);
1394 static const jchar *
1395 (JNICALL _Jv_JNI_GetStringCritical) (JNIEnv *, jstring str, jboolean *isCopy)
1397 jchar *result = _Jv_GetStringChars (unwrap (str));
1398 if (isCopy)
1399 *isCopy = false;
1400 return result;
1403 static void
1404 (JNICALL _Jv_JNI_ReleaseStringCritical) (JNIEnv *, jstring, const jchar *)
1406 // Nothing.
1409 static jsize
1410 (JNICALL _Jv_JNI_GetArrayLength) (JNIEnv *, jarray array)
1412 return unwrap (array)->length;
1415 static jarray
1416 (JNICALL _Jv_JNI_NewObjectArray) (JNIEnv *env, jsize length,
1417 jclass elementClass, jobject init)
1421 elementClass = unwrap (elementClass);
1422 init = unwrap (init);
1424 _Jv_CheckCast (elementClass, init);
1425 jarray result = JvNewObjectArray (length, elementClass, init);
1426 return (jarray) wrap_value (env, result);
1428 catch (jthrowable t)
1430 env->ex = t;
1431 return NULL;
1435 static jobject
1436 (JNICALL _Jv_JNI_GetObjectArrayElement) (JNIEnv *env, jobjectArray array,
1437 jsize index)
1439 if ((unsigned) index >= (unsigned) array->length)
1440 _Jv_ThrowBadArrayIndex (index);
1441 jobject *elts = elements (unwrap (array));
1442 return wrap_value (env, elts[index]);
1445 static void
1446 (JNICALL _Jv_JNI_SetObjectArrayElement) (JNIEnv *env, jobjectArray array,
1447 jsize index, jobject value)
1451 array = unwrap (array);
1452 value = unwrap (value);
1454 _Jv_CheckArrayStore (array, value);
1455 if ((unsigned) index >= (unsigned) array->length)
1456 _Jv_ThrowBadArrayIndex (index);
1457 jobject *elts = elements (array);
1458 elts[index] = value;
1460 catch (jthrowable t)
1462 env->ex = t;
1466 template<typename T, jclass K>
1467 static JArray<T> *
1468 (JNICALL _Jv_JNI_NewPrimitiveArray) (JNIEnv *env, jsize length)
1472 return (JArray<T> *) wrap_value (env, _Jv_NewPrimArray (K, length));
1474 catch (jthrowable t)
1476 env->ex = t;
1477 return NULL;
1481 template<typename T, jclass K>
1482 static T *
1483 (JNICALL _Jv_JNI_GetPrimitiveArrayElements) (JNIEnv *env, JArray<T> *array,
1484 jboolean *isCopy)
1486 array = unwrap (array);
1487 if (! _Jv_JNI_check_types (env, array, K))
1488 return NULL;
1489 T *elts = elements (array);
1490 if (isCopy)
1492 // We elect never to copy.
1493 *isCopy = false;
1495 mark_for_gc (array, global_ref_table);
1496 return elts;
1499 template<typename T, jclass K>
1500 static void
1501 (JNICALL _Jv_JNI_ReleasePrimitiveArrayElements) (JNIEnv *env, JArray<T> *array,
1502 T *, jint /* mode */)
1504 array = unwrap (array);
1505 _Jv_JNI_check_types (env, array, K);
1506 // Note that we ignore MODE. We can do this because we never copy
1507 // the array elements. My reading of the JNI documentation is that
1508 // this is an option for the implementor.
1509 unmark_for_gc (array, global_ref_table);
1512 template<typename T, jclass K>
1513 static void
1514 (JNICALL _Jv_JNI_GetPrimitiveArrayRegion) (JNIEnv *env, JArray<T> *array,
1515 jsize start, jsize len,
1516 T *buf)
1518 array = unwrap (array);
1519 if (! _Jv_JNI_check_types (env, array, K))
1520 return;
1522 // The cast to unsigned lets us save a comparison.
1523 if (start < 0 || len < 0
1524 || (unsigned long) (start + len) > (unsigned long) array->length)
1528 // FIXME: index.
1529 env->ex = new java::lang::ArrayIndexOutOfBoundsException ();
1531 catch (jthrowable t)
1533 // Could have thown out of memory error.
1534 env->ex = t;
1537 else
1539 T *elts = elements (array) + start;
1540 memcpy (buf, elts, len * sizeof (T));
1544 template<typename T, jclass K>
1545 static void
1546 (JNICALL _Jv_JNI_SetPrimitiveArrayRegion) (JNIEnv *env, JArray<T> *array,
1547 jsize start, jsize len, T *buf)
1549 array = unwrap (array);
1550 if (! _Jv_JNI_check_types (env, array, K))
1551 return;
1553 // The cast to unsigned lets us save a comparison.
1554 if (start < 0 || len < 0
1555 || (unsigned long) (start + len) > (unsigned long) array->length)
1559 // FIXME: index.
1560 env->ex = new java::lang::ArrayIndexOutOfBoundsException ();
1562 catch (jthrowable t)
1564 env->ex = t;
1567 else
1569 T *elts = elements (array) + start;
1570 memcpy (elts, buf, len * sizeof (T));
1574 static void *
1575 (JNICALL _Jv_JNI_GetPrimitiveArrayCritical) (JNIEnv *, jarray array,
1576 jboolean *isCopy)
1578 array = unwrap (array);
1579 // FIXME: does this work?
1580 jclass klass = array->getClass()->getComponentType();
1581 JvAssert (klass->isPrimitive ());
1582 char *r = _Jv_GetArrayElementFromElementType (array, klass);
1583 if (isCopy)
1584 *isCopy = false;
1585 return r;
1588 static void
1589 (JNICALL _Jv_JNI_ReleasePrimitiveArrayCritical) (JNIEnv *, jarray, void *, jint)
1591 // Nothing.
1594 static jint
1595 (JNICALL _Jv_JNI_MonitorEnter) (JNIEnv *env, jobject obj)
1599 _Jv_MonitorEnter (unwrap (obj));
1600 return 0;
1602 catch (jthrowable t)
1604 env->ex = t;
1606 return JNI_ERR;
1609 static jint
1610 (JNICALL _Jv_JNI_MonitorExit) (JNIEnv *env, jobject obj)
1614 _Jv_MonitorExit (unwrap (obj));
1615 return 0;
1617 catch (jthrowable t)
1619 env->ex = t;
1621 return JNI_ERR;
1624 // JDK 1.2
1625 jobject
1626 (JNICALL _Jv_JNI_ToReflectedField) (JNIEnv *env, jclass cls, jfieldID fieldID,
1627 jboolean)
1631 cls = unwrap (cls);
1632 java::lang::reflect::Field *field = new java::lang::reflect::Field();
1633 field->declaringClass = cls;
1634 field->offset = (char*) fieldID - (char *) cls->fields;
1635 field->name = _Jv_NewStringUtf8Const (fieldID->getNameUtf8Const (cls));
1636 return wrap_value (env, field);
1638 catch (jthrowable t)
1640 env->ex = t;
1642 return NULL;
1645 // JDK 1.2
1646 static jfieldID
1647 (JNICALL _Jv_JNI_FromReflectedField) (JNIEnv *, jobject f)
1649 using namespace java::lang::reflect;
1651 f = unwrap (f);
1652 Field *field = reinterpret_cast<Field *> (f);
1653 return _Jv_FromReflectedField (field);
1656 jobject
1657 (JNICALL _Jv_JNI_ToReflectedMethod) (JNIEnv *env, jclass klass, jmethodID id,
1658 jboolean)
1660 using namespace java::lang::reflect;
1662 jobject result = NULL;
1663 klass = unwrap (klass);
1667 if (_Jv_equalUtf8Consts (id->name, init_name))
1669 // A constructor.
1670 Constructor *cons = new Constructor ();
1671 cons->offset = (char *) id - (char *) &klass->methods;
1672 cons->declaringClass = klass;
1673 result = cons;
1675 else
1677 Method *meth = new Method ();
1678 meth->offset = (char *) id - (char *) &klass->methods;
1679 meth->declaringClass = klass;
1680 result = meth;
1683 catch (jthrowable t)
1685 env->ex = t;
1688 return wrap_value (env, result);
1691 static jmethodID
1692 (JNICALL _Jv_JNI_FromReflectedMethod) (JNIEnv *, jobject method)
1694 using namespace java::lang::reflect;
1695 method = unwrap (method);
1696 if (Method::class$.isInstance (method))
1697 return _Jv_FromReflectedMethod (reinterpret_cast<Method *> (method));
1698 return
1699 _Jv_FromReflectedConstructor (reinterpret_cast<Constructor *> (method));
1702 // JDK 1.2.
1703 jweak
1704 (JNICALL _Jv_JNI_NewWeakGlobalRef) (JNIEnv *env, jobject obj)
1706 using namespace gnu::gcj::runtime;
1707 JNIWeakRef *ref = NULL;
1711 // This seems weird but I think it is correct.
1712 obj = unwrap (obj);
1713 ref = new JNIWeakRef (obj);
1714 mark_for_gc (ref, global_ref_table);
1716 catch (jthrowable t)
1718 env->ex = t;
1721 return reinterpret_cast<jweak> (ref);
1724 void
1725 (JNICALL _Jv_JNI_DeleteWeakGlobalRef) (JNIEnv *, jweak obj)
1727 using namespace gnu::gcj::runtime;
1728 JNIWeakRef *ref = reinterpret_cast<JNIWeakRef *> (obj);
1729 unmark_for_gc (ref, global_ref_table);
1730 ref->clear ();
1735 // Direct byte buffers.
1737 static jobject
1738 (JNICALL _Jv_JNI_NewDirectByteBuffer) (JNIEnv *, void *address, jlong length)
1740 using namespace gnu::gcj;
1741 using namespace java::nio;
1742 return new DirectByteBufferImpl (reinterpret_cast<RawData *> (address),
1743 length);
1746 static void *
1747 (JNICALL _Jv_JNI_GetDirectBufferAddress) (JNIEnv *, jobject buffer)
1749 using namespace java::nio;
1750 DirectByteBufferImpl* bb = static_cast<DirectByteBufferImpl *> (buffer);
1751 return reinterpret_cast<void *> (bb->address);
1754 static jlong
1755 (JNICALL _Jv_JNI_GetDirectBufferCapacity) (JNIEnv *, jobject buffer)
1757 using namespace java::nio;
1758 DirectByteBufferImpl* bb = static_cast<DirectByteBufferImpl *> (buffer);
1759 return bb->capacity();
1764 // Hash table of native methods.
1765 static JNINativeMethod *nathash;
1766 // Number of slots used.
1767 static int nathash_count = 0;
1768 // Number of slots available. Must be power of 2.
1769 static int nathash_size = 0;
1771 #define DELETED_ENTRY ((char *) (~0))
1773 // Compute a hash value for a native method descriptor.
1774 static int
1775 hash (const JNINativeMethod *method)
1777 char *ptr;
1778 int hash = 0;
1780 ptr = method->name;
1781 while (*ptr)
1782 hash = (31 * hash) + *ptr++;
1784 ptr = method->signature;
1785 while (*ptr)
1786 hash = (31 * hash) + *ptr++;
1788 return hash;
1791 // Find the slot where a native method goes.
1792 static JNINativeMethod *
1793 nathash_find_slot (const JNINativeMethod *method)
1795 jint h = hash (method);
1796 int step = (h ^ (h >> 16)) | 1;
1797 int w = h & (nathash_size - 1);
1798 int del = -1;
1800 for (;;)
1802 JNINativeMethod *slotp = &nathash[w];
1803 if (slotp->name == NULL)
1805 if (del >= 0)
1806 return &nathash[del];
1807 else
1808 return slotp;
1810 else if (slotp->name == DELETED_ENTRY)
1811 del = w;
1812 else if (! strcmp (slotp->name, method->name)
1813 && ! strcmp (slotp->signature, method->signature))
1814 return slotp;
1815 w = (w + step) & (nathash_size - 1);
1819 // Find a method. Return NULL if it isn't in the hash table.
1820 static void *
1821 nathash_find (JNINativeMethod *method)
1823 if (nathash == NULL)
1824 return NULL;
1825 JNINativeMethod *slot = nathash_find_slot (method);
1826 if (slot->name == NULL || slot->name == DELETED_ENTRY)
1827 return NULL;
1828 return slot->fnPtr;
1831 static void
1832 natrehash ()
1834 if (nathash == NULL)
1836 nathash_size = 1024;
1837 nathash =
1838 (JNINativeMethod *) _Jv_AllocBytes (nathash_size
1839 * sizeof (JNINativeMethod));
1840 memset (nathash, 0, nathash_size * sizeof (JNINativeMethod));
1842 else
1844 int savesize = nathash_size;
1845 JNINativeMethod *savehash = nathash;
1846 nathash_size *= 2;
1847 nathash =
1848 (JNINativeMethod *) _Jv_AllocBytes (nathash_size
1849 * sizeof (JNINativeMethod));
1850 memset (nathash, 0, nathash_size * sizeof (JNINativeMethod));
1852 for (int i = 0; i < savesize; ++i)
1854 if (savehash[i].name != NULL && savehash[i].name != DELETED_ENTRY)
1856 JNINativeMethod *slot = nathash_find_slot (&savehash[i]);
1857 *slot = savehash[i];
1863 static void
1864 nathash_add (const JNINativeMethod *method)
1866 if (3 * nathash_count >= 2 * nathash_size)
1867 natrehash ();
1868 JNINativeMethod *slot = nathash_find_slot (method);
1869 // If the slot has a real entry in it, then there is no work to do.
1870 if (slot->name != NULL && slot->name != DELETED_ENTRY)
1871 return;
1872 // FIXME
1873 slot->name = strdup (method->name);
1874 slot->signature = strdup (method->signature);
1875 slot->fnPtr = method->fnPtr;
1878 static jint
1879 (JNICALL _Jv_JNI_RegisterNatives) (JNIEnv *env, jclass klass,
1880 const JNINativeMethod *methods,
1881 jint nMethods)
1883 // Synchronize while we do the work. This must match
1884 // synchronization in some other functions that manipulate or use
1885 // the nathash table.
1886 JvSynchronize sync (global_ref_table);
1888 // Look at each descriptor given us, and find the corresponding
1889 // method in the class.
1890 for (int j = 0; j < nMethods; ++j)
1892 bool found = false;
1894 _Jv_Method *imeths = JvGetFirstMethod (klass);
1895 for (int i = 0; i < JvNumMethods (klass); ++i)
1897 _Jv_Method *self = &imeths[i];
1899 if (! strcmp (self->name->data, methods[j].name)
1900 && ! strcmp (self->signature->data, methods[j].signature))
1902 if (! (self->accflags
1903 & java::lang::reflect::Modifier::NATIVE))
1904 break;
1906 // Found a match that is native.
1907 found = true;
1908 nathash_add (&methods[j]);
1910 break;
1914 if (! found)
1916 jstring m = JvNewStringUTF (methods[j].name);
1919 env->ex =new java::lang::NoSuchMethodError (m);
1921 catch (jthrowable t)
1923 env->ex = t;
1925 return JNI_ERR;
1929 return JNI_OK;
1932 static jint
1933 (JNICALL _Jv_JNI_UnregisterNatives) (JNIEnv *, jclass)
1935 // FIXME -- we could implement this.
1936 return JNI_ERR;
1941 // Add a character to the buffer, encoding properly.
1942 static void
1943 add_char (char *buf, jchar c, int *here)
1945 if (c == '_')
1947 buf[(*here)++] = '_';
1948 buf[(*here)++] = '1';
1950 else if (c == ';')
1952 buf[(*here)++] = '_';
1953 buf[(*here)++] = '2';
1955 else if (c == '[')
1957 buf[(*here)++] = '_';
1958 buf[(*here)++] = '3';
1961 // Also check for `.' here because we might be passed an internal
1962 // qualified class name like `foo.bar'.
1963 else if (c == '/' || c == '.')
1964 buf[(*here)++] = '_';
1965 else if ((c >= '0' && c <= '9')
1966 || (c >= 'a' && c <= 'z')
1967 || (c >= 'A' && c <= 'Z'))
1968 buf[(*here)++] = (char) c;
1969 else
1971 // "Unicode" character.
1972 buf[(*here)++] = '_';
1973 buf[(*here)++] = '0';
1974 for (int i = 0; i < 4; ++i)
1976 int val = c & 0x0f;
1977 buf[(*here) + 3 - i] = (val > 10) ? ('a' + val - 10) : ('0' + val);
1978 c >>= 4;
1980 *here += 4;
1984 // Compute a mangled name for a native function. This computes the
1985 // long name, and also returns an index which indicates where a NUL
1986 // can be placed to create the short name. This function assumes that
1987 // the buffer is large enough for its results.
1988 static void
1989 mangled_name (jclass klass, _Jv_Utf8Const *func_name,
1990 _Jv_Utf8Const *signature, char *buf, int *long_start)
1992 strcpy (buf, "Java_");
1993 int here = 5;
1995 // Add fully qualified class name.
1996 jchar *chars = _Jv_GetStringChars (klass->getName ());
1997 jint len = klass->getName ()->length ();
1998 for (int i = 0; i < len; ++i)
1999 add_char (buf, chars[i], &here);
2001 // Don't use add_char because we need a literal `_'.
2002 buf[here++] = '_';
2004 const unsigned char *fn = (const unsigned char *) func_name->data;
2005 const unsigned char *limit = fn + func_name->length;
2006 for (int i = 0; ; ++i)
2008 int ch = UTF8_GET (fn, limit);
2009 if (ch < 0)
2010 break;
2011 add_char (buf, ch, &here);
2014 // This is where the long signature begins.
2015 *long_start = here;
2016 buf[here++] = '_';
2017 buf[here++] = '_';
2019 const unsigned char *sig = (const unsigned char *) signature->data;
2020 limit = sig + signature->length;
2021 JvAssert (sig[0] == '(');
2022 ++sig;
2023 while (1)
2025 int ch = UTF8_GET (sig, limit);
2026 if (ch == ')' || ch < 0)
2027 break;
2028 add_char (buf, ch, &here);
2031 buf[here] = '\0';
2034 // Return the current thread's JNIEnv; if one does not exist, create
2035 // it. Also create a new system frame for use. This is `extern "C"'
2036 // because the compiler calls it.
2037 extern "C" JNIEnv *
2038 _Jv_GetJNIEnvNewFrame (jclass klass)
2040 JNIEnv *env = _Jv_GetCurrentJNIEnv ();
2041 if (__builtin_expect (env == NULL, false))
2043 env = (JNIEnv *) _Jv_MallocUnchecked (sizeof (JNIEnv));
2044 env->p = &_Jv_JNIFunctions;
2045 env->klass = klass;
2046 env->locals = NULL;
2047 // We set env->ex below.
2049 // Set up the bottom, reusable frame.
2050 env->bottom_locals = (_Jv_JNI_LocalFrame *)
2051 _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame)
2052 + (FRAME_SIZE
2053 * sizeof (jobject)));
2055 env->bottom_locals->marker = MARK_SYSTEM;
2056 env->bottom_locals->size = FRAME_SIZE;
2057 env->bottom_locals->next = NULL;
2058 env->bottom_locals->allocated_p = 0;
2059 memset (&env->bottom_locals->vec[0], 0,
2060 env->bottom_locals->size * sizeof (jobject));
2062 _Jv_SetCurrentJNIEnv (env);
2065 // If we're in a simple JNI call (non-nested), we can just reuse the
2066 // locals frame we allocated many calls ago, back when the env was first
2067 // built, above.
2069 if (__builtin_expect (env->locals == NULL, true))
2070 env->locals = env->bottom_locals;
2072 else
2074 // Alternatively, we might be re-entering JNI, in which case we can't
2075 // reuse the bottom_locals frame, because it is already underneath
2076 // us. So we need to make a new one.
2078 _Jv_JNI_LocalFrame *frame
2079 = (_Jv_JNI_LocalFrame *) _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame)
2080 + (FRAME_SIZE
2081 * sizeof (jobject)));
2083 frame->marker = MARK_SYSTEM;
2084 frame->size = FRAME_SIZE;
2085 frame->allocated_p = 0;
2086 frame->next = env->locals;
2088 memset (&frame->vec[0], 0,
2089 frame->size * sizeof (jobject));
2091 env->locals = frame;
2094 env->ex = NULL;
2096 return env;
2099 // Destroy the env's reusable resources. This is called from the thread
2100 // destructor "finalize_native" in natThread.cc
2101 void
2102 _Jv_FreeJNIEnv (_Jv_JNIEnv *env)
2104 if (env == NULL)
2105 return;
2107 if (env->bottom_locals != NULL)
2108 _Jv_Free (env->bottom_locals);
2110 _Jv_Free (env);
2113 // Return the function which implements a particular JNI method. If
2114 // we can't find the function, we throw the appropriate exception.
2115 // This is `extern "C"' because the compiler uses it.
2116 extern "C" void *
2117 _Jv_LookupJNIMethod (jclass klass, _Jv_Utf8Const *name,
2118 _Jv_Utf8Const *signature, MAYBE_UNUSED int args_size)
2120 char buf[10 + 6 * (name->length + signature->length) + 12];
2121 int long_start;
2122 void *function;
2124 // Synchronize on something convenient. Right now we use the hash.
2125 JvSynchronize sync (global_ref_table);
2127 // First see if we have an override in the hash table.
2128 strncpy (buf, name->data, name->length);
2129 buf[name->length] = '\0';
2130 strncpy (buf + name->length + 1, signature->data, signature->length);
2131 buf[name->length + signature->length + 1] = '\0';
2132 JNINativeMethod meth;
2133 meth.name = buf;
2134 meth.signature = buf + name->length + 1;
2135 function = nathash_find (&meth);
2136 if (function != NULL)
2137 return function;
2139 // If there was no override, then look in the symbol table.
2140 buf[0] = '_';
2141 mangled_name (klass, name, signature, buf + 1, &long_start);
2142 char c = buf[long_start + 1];
2143 buf[long_start + 1] = '\0';
2145 function = _Jv_FindSymbolInExecutable (buf + 1);
2146 #ifdef WIN32
2147 // On Win32, we use the "stdcall" calling convention (see JNICALL
2148 // in jni.h).
2150 // For a function named 'fooBar' that takes 'nn' bytes as arguments,
2151 // by default, MinGW GCC exports it as 'fooBar@nn', MSVC exports it
2152 // as '_fooBar@nn' and Borland C exports it as 'fooBar'. We try to
2153 // take care of all these variations here.
2155 char asz_buf[12]; /* '@' + '2147483647' (32-bit INT_MAX) + '\0' */
2156 char long_nm_sv[11]; /* Ditto, except for the '\0'. */
2158 if (function == NULL)
2160 // We have tried searching for the 'fooBar' form (BCC) - now
2161 // try the others.
2163 // First, save the part of the long name that will be damaged
2164 // by appending '@nn'.
2165 memcpy (long_nm_sv, (buf + long_start + 1 + 1), sizeof (long_nm_sv));
2167 sprintf (asz_buf, "@%d", args_size);
2168 strcat (buf, asz_buf);
2170 // Search for the '_fooBar@nn' form (MSVC).
2171 function = _Jv_FindSymbolInExecutable (buf);
2173 if (function == NULL)
2175 // Search for the 'fooBar@nn' form (MinGW GCC).
2176 function = _Jv_FindSymbolInExecutable (buf + 1);
2179 #endif /* WIN32 */
2181 if (function == NULL)
2183 buf[long_start + 1] = c;
2184 #ifdef WIN32
2185 // Restore the part of the long name that was damaged by
2186 // appending the '@nn'.
2187 memcpy ((buf + long_start + 1 + 1), long_nm_sv, sizeof (long_nm_sv));
2188 #endif /* WIN32 */
2189 function = _Jv_FindSymbolInExecutable (buf + 1);
2190 if (function == NULL)
2192 #ifdef WIN32
2193 strcat (buf, asz_buf);
2194 function = _Jv_FindSymbolInExecutable (buf);
2195 if (function == NULL)
2196 function = _Jv_FindSymbolInExecutable (buf + 1);
2198 if (function == NULL)
2199 #endif /* WIN32 */
2201 jstring str = JvNewStringUTF (name->data);
2202 throw new java::lang::UnsatisfiedLinkError (str);
2207 return function;
2210 #ifdef INTERPRETER
2212 // This function is the stub which is used to turn an ordinary (CNI)
2213 // method call into a JNI call.
2214 void
2215 _Jv_JNIMethod::call (ffi_cif *, void *ret, ffi_raw *args, void *__this)
2217 _Jv_JNIMethod* _this = (_Jv_JNIMethod *) __this;
2219 JNIEnv *env = _Jv_GetJNIEnvNewFrame (_this->defining_class);
2221 // FIXME: we should mark every reference parameter as a local. For
2222 // now we assume a conservative GC, and we assume that the
2223 // references are on the stack somewhere.
2225 // We cache the value that we find, of course, but if we don't find
2226 // a value we don't cache that fact -- we might subsequently load a
2227 // library which finds the function in question.
2229 // Synchronize on a convenient object to ensure sanity in case two
2230 // threads reach this point for the same function at the same
2231 // time.
2232 JvSynchronize sync (global_ref_table);
2233 if (_this->function == NULL)
2235 int args_size = sizeof (JNIEnv *) + _this->args_raw_size;
2237 if (_this->self->accflags & java::lang::reflect::Modifier::STATIC)
2238 args_size += sizeof (_this->defining_class);
2240 _this->function = _Jv_LookupJNIMethod (_this->defining_class,
2241 _this->self->name,
2242 _this->self->signature,
2243 args_size);
2247 JvAssert (_this->args_raw_size % sizeof (ffi_raw) == 0);
2248 ffi_raw real_args[2 + _this->args_raw_size / sizeof (ffi_raw)];
2249 int offset = 0;
2251 // First argument is always the environment pointer.
2252 real_args[offset++].ptr = env;
2254 // For a static method, we pass in the Class. For non-static
2255 // methods, the `this' argument is already handled.
2256 if ((_this->self->accflags & java::lang::reflect::Modifier::STATIC))
2257 real_args[offset++].ptr = _this->defining_class;
2259 // In libgcj, the callee synchronizes.
2260 jobject sync = NULL;
2261 if ((_this->self->accflags & java::lang::reflect::Modifier::SYNCHRONIZED))
2263 if ((_this->self->accflags & java::lang::reflect::Modifier::STATIC))
2264 sync = _this->defining_class;
2265 else
2266 sync = (jobject) args[0].ptr;
2267 _Jv_MonitorEnter (sync);
2270 // Copy over passed-in arguments.
2271 memcpy (&real_args[offset], args, _this->args_raw_size);
2273 // The actual call to the JNI function.
2274 ffi_raw_call (&_this->jni_cif, (void (*)()) _this->function,
2275 ret, real_args);
2277 if (sync != NULL)
2278 _Jv_MonitorExit (sync);
2280 _Jv_JNI_PopSystemFrame (env);
2283 #endif /* INTERPRETER */
2288 // Invocation API.
2291 // An internal helper function.
2292 static jint
2293 _Jv_JNI_AttachCurrentThread (JavaVM *, jstring name, void **penv,
2294 void *args, jboolean is_daemon)
2296 JavaVMAttachArgs *attach = reinterpret_cast<JavaVMAttachArgs *> (args);
2297 java::lang::ThreadGroup *group = NULL;
2299 if (attach)
2301 // FIXME: do we really want to support 1.1?
2302 if (attach->version != JNI_VERSION_1_4
2303 && attach->version != JNI_VERSION_1_2
2304 && attach->version != JNI_VERSION_1_1)
2305 return JNI_EVERSION;
2307 JvAssert (java::lang::ThreadGroup::class$.isInstance (attach->group));
2308 group = reinterpret_cast<java::lang::ThreadGroup *> (attach->group);
2311 // Attaching an already-attached thread is a no-op.
2312 if (_Jv_GetCurrentJNIEnv () != NULL)
2313 return 0;
2315 JNIEnv *env = (JNIEnv *) _Jv_MallocUnchecked (sizeof (JNIEnv));
2316 if (env == NULL)
2317 return JNI_ERR;
2318 env->p = &_Jv_JNIFunctions;
2319 env->ex = NULL;
2320 env->klass = NULL;
2321 env->bottom_locals
2322 = (_Jv_JNI_LocalFrame *) _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame)
2323 + (FRAME_SIZE
2324 * sizeof (jobject)));
2325 env->locals = env->bottom_locals;
2326 if (env->locals == NULL)
2328 _Jv_Free (env);
2329 return JNI_ERR;
2332 env->locals->allocated_p = 0;
2333 env->locals->marker = MARK_SYSTEM;
2334 env->locals->size = FRAME_SIZE;
2335 env->locals->next = NULL;
2337 for (int i = 0; i < env->locals->size; ++i)
2338 env->locals->vec[i] = NULL;
2340 *penv = reinterpret_cast<void *> (env);
2342 // This thread might already be a Java thread -- this function might
2343 // have been called simply to set the new JNIEnv.
2344 if (_Jv_ThreadCurrent () == NULL)
2348 if (is_daemon)
2349 _Jv_AttachCurrentThreadAsDaemon (name, group);
2350 else
2351 _Jv_AttachCurrentThread (name, group);
2353 catch (jthrowable t)
2355 return JNI_ERR;
2358 _Jv_SetCurrentJNIEnv (env);
2360 return 0;
2363 // This is the one actually used by JNI.
2364 static jint
2365 (JNICALL _Jv_JNI_AttachCurrentThread) (JavaVM *vm, void **penv, void *args)
2367 return _Jv_JNI_AttachCurrentThread (vm, NULL, penv, args, false);
2370 static jint
2371 (JNICALL _Jv_JNI_AttachCurrentThreadAsDaemon) (JavaVM *vm, void **penv,
2372 void *args)
2374 return _Jv_JNI_AttachCurrentThread (vm, NULL, penv, args, true);
2377 static jint
2378 (JNICALL _Jv_JNI_DestroyJavaVM) (JavaVM *vm)
2380 JvAssert (the_vm && vm == the_vm);
2382 JNIEnv *env;
2383 if (_Jv_ThreadCurrent () != NULL)
2385 jstring main_name;
2386 // This sucks.
2389 main_name = JvNewStringLatin1 ("main");
2391 catch (jthrowable t)
2393 return JNI_ERR;
2396 jint r = _Jv_JNI_AttachCurrentThread (vm, main_name,
2397 reinterpret_cast<void **> (&env),
2398 NULL, false);
2399 if (r < 0)
2400 return r;
2402 else
2403 env = _Jv_GetCurrentJNIEnv ();
2405 _Jv_ThreadWait ();
2407 // Docs say that this always returns an error code.
2408 return JNI_ERR;
2411 jint
2412 (JNICALL _Jv_JNI_DetachCurrentThread) (JavaVM *)
2414 jint code = _Jv_DetachCurrentThread ();
2415 return code ? JNI_EDETACHED : 0;
2418 static jint
2419 (JNICALL _Jv_JNI_GetEnv) (JavaVM *, void **penv, jint version)
2421 if (_Jv_ThreadCurrent () == NULL)
2423 *penv = NULL;
2424 return JNI_EDETACHED;
2427 #ifdef ENABLE_JVMPI
2428 // Handle JVMPI requests.
2429 if (version == JVMPI_VERSION_1)
2431 *penv = (void *) &_Jv_JVMPI_Interface;
2432 return 0;
2434 #endif
2436 // FIXME: do we really want to support 1.1?
2437 if (version != JNI_VERSION_1_4 && version != JNI_VERSION_1_2
2438 && version != JNI_VERSION_1_1)
2440 *penv = NULL;
2441 return JNI_EVERSION;
2444 *penv = (void *) _Jv_GetCurrentJNIEnv ();
2445 return 0;
2448 jint JNICALL
2449 JNI_GetDefaultJavaVMInitArgs (void *args)
2451 jint version = * (jint *) args;
2452 // Here we only support 1.2 and 1.4.
2453 if (version != JNI_VERSION_1_2 && version != JNI_VERSION_1_4)
2454 return JNI_EVERSION;
2456 JavaVMInitArgs *ia = reinterpret_cast<JavaVMInitArgs *> (args);
2457 ia->version = JNI_VERSION_1_4;
2458 ia->nOptions = 0;
2459 ia->options = NULL;
2460 ia->ignoreUnrecognized = true;
2462 return 0;
2465 jint JNICALL
2466 JNI_CreateJavaVM (JavaVM **vm, void **penv, void *args)
2468 JvAssert (! the_vm);
2470 _Jv_CreateJavaVM (NULL);
2472 // FIXME: synchronize
2473 JavaVM *nvm = (JavaVM *) _Jv_MallocUnchecked (sizeof (JavaVM));
2474 if (nvm == NULL)
2475 return JNI_ERR;
2476 nvm->functions = &_Jv_JNI_InvokeFunctions;
2478 // Parse the arguments.
2479 if (args != NULL)
2481 jint version = * (jint *) args;
2482 // We only support 1.2 and 1.4.
2483 if (version != JNI_VERSION_1_2 && version != JNI_VERSION_1_4)
2484 return JNI_EVERSION;
2485 JavaVMInitArgs *ia = reinterpret_cast<JavaVMInitArgs *> (args);
2486 for (int i = 0; i < ia->nOptions; ++i)
2488 if (! strcmp (ia->options[i].optionString, "vfprintf")
2489 || ! strcmp (ia->options[i].optionString, "exit")
2490 || ! strcmp (ia->options[i].optionString, "abort"))
2492 // We are required to recognize these, but for now we
2493 // don't handle them in any way. FIXME.
2494 continue;
2496 else if (! strncmp (ia->options[i].optionString,
2497 "-verbose", sizeof ("-verbose") - 1))
2499 // We don't do anything with this option either. We
2500 // might want to make sure the argument is valid, but we
2501 // don't really care all that much for now.
2502 continue;
2504 else if (! strncmp (ia->options[i].optionString, "-D", 2))
2506 // FIXME.
2507 continue;
2509 else if (ia->ignoreUnrecognized)
2511 if (ia->options[i].optionString[0] == '_'
2512 || ! strncmp (ia->options[i].optionString, "-X", 2))
2513 continue;
2516 return JNI_ERR;
2520 jint r =_Jv_JNI_AttachCurrentThread (nvm, penv, NULL);
2521 if (r < 0)
2522 return r;
2524 the_vm = nvm;
2525 *vm = the_vm;
2527 return 0;
2530 jint JNICALL
2531 JNI_GetCreatedJavaVMs (JavaVM **vm_buffer, jsize buf_len, jsize *n_vms)
2533 if (buf_len <= 0)
2534 return JNI_ERR;
2536 // We only support a single VM.
2537 if (the_vm != NULL)
2539 vm_buffer[0] = the_vm;
2540 *n_vms = 1;
2542 else
2543 *n_vms = 0;
2544 return 0;
2547 JavaVM *
2548 _Jv_GetJavaVM ()
2550 // FIXME: synchronize
2551 if (! the_vm)
2553 JavaVM *nvm = (JavaVM *) _Jv_MallocUnchecked (sizeof (JavaVM));
2554 if (nvm != NULL)
2555 nvm->functions = &_Jv_JNI_InvokeFunctions;
2556 the_vm = nvm;
2559 // If this is a Java thread, we want to make sure it has an
2560 // associated JNIEnv.
2561 if (_Jv_ThreadCurrent () != NULL)
2563 void *ignore;
2564 _Jv_JNI_AttachCurrentThread (the_vm, &ignore, NULL);
2567 return the_vm;
2570 static jint
2571 (JNICALL _Jv_JNI_GetJavaVM) (JNIEnv *, JavaVM **vm)
2573 *vm = _Jv_GetJavaVM ();
2574 return *vm == NULL ? JNI_ERR : JNI_OK;
2579 #define RESERVED NULL
2581 struct JNINativeInterface _Jv_JNIFunctions =
2583 RESERVED,
2584 RESERVED,
2585 RESERVED,
2586 RESERVED,
2587 _Jv_JNI_GetVersion, // GetVersion
2588 _Jv_JNI_DefineClass, // DefineClass
2589 _Jv_JNI_FindClass, // FindClass
2590 _Jv_JNI_FromReflectedMethod, // FromReflectedMethod
2591 _Jv_JNI_FromReflectedField, // FromReflectedField
2592 _Jv_JNI_ToReflectedMethod, // ToReflectedMethod
2593 _Jv_JNI_GetSuperclass, // GetSuperclass
2594 _Jv_JNI_IsAssignableFrom, // IsAssignableFrom
2595 _Jv_JNI_ToReflectedField, // ToReflectedField
2596 _Jv_JNI_Throw, // Throw
2597 _Jv_JNI_ThrowNew, // ThrowNew
2598 _Jv_JNI_ExceptionOccurred, // ExceptionOccurred
2599 _Jv_JNI_ExceptionDescribe, // ExceptionDescribe
2600 _Jv_JNI_ExceptionClear, // ExceptionClear
2601 _Jv_JNI_FatalError, // FatalError
2603 _Jv_JNI_PushLocalFrame, // PushLocalFrame
2604 _Jv_JNI_PopLocalFrame, // PopLocalFrame
2605 _Jv_JNI_NewGlobalRef, // NewGlobalRef
2606 _Jv_JNI_DeleteGlobalRef, // DeleteGlobalRef
2607 _Jv_JNI_DeleteLocalRef, // DeleteLocalRef
2609 _Jv_JNI_IsSameObject, // IsSameObject
2611 _Jv_JNI_NewLocalRef, // NewLocalRef
2612 _Jv_JNI_EnsureLocalCapacity, // EnsureLocalCapacity
2614 _Jv_JNI_AllocObject, // AllocObject
2615 _Jv_JNI_NewObject, // NewObject
2616 _Jv_JNI_NewObjectV, // NewObjectV
2617 _Jv_JNI_NewObjectA, // NewObjectA
2618 _Jv_JNI_GetObjectClass, // GetObjectClass
2619 _Jv_JNI_IsInstanceOf, // IsInstanceOf
2620 _Jv_JNI_GetAnyMethodID<false>, // GetMethodID
2622 _Jv_JNI_CallMethod<jobject>, // CallObjectMethod
2623 _Jv_JNI_CallMethodV<jobject>, // CallObjectMethodV
2624 _Jv_JNI_CallMethodA<jobject>, // CallObjectMethodA
2625 _Jv_JNI_CallMethod<jboolean>, // CallBooleanMethod
2626 _Jv_JNI_CallMethodV<jboolean>, // CallBooleanMethodV
2627 _Jv_JNI_CallMethodA<jboolean>, // CallBooleanMethodA
2628 _Jv_JNI_CallMethod<jbyte>, // CallByteMethod
2629 _Jv_JNI_CallMethodV<jbyte>, // CallByteMethodV
2630 _Jv_JNI_CallMethodA<jbyte>, // CallByteMethodA
2631 _Jv_JNI_CallMethod<jchar>, // CallCharMethod
2632 _Jv_JNI_CallMethodV<jchar>, // CallCharMethodV
2633 _Jv_JNI_CallMethodA<jchar>, // CallCharMethodA
2634 _Jv_JNI_CallMethod<jshort>, // CallShortMethod
2635 _Jv_JNI_CallMethodV<jshort>, // CallShortMethodV
2636 _Jv_JNI_CallMethodA<jshort>, // CallShortMethodA
2637 _Jv_JNI_CallMethod<jint>, // CallIntMethod
2638 _Jv_JNI_CallMethodV<jint>, // CallIntMethodV
2639 _Jv_JNI_CallMethodA<jint>, // CallIntMethodA
2640 _Jv_JNI_CallMethod<jlong>, // CallLongMethod
2641 _Jv_JNI_CallMethodV<jlong>, // CallLongMethodV
2642 _Jv_JNI_CallMethodA<jlong>, // CallLongMethodA
2643 _Jv_JNI_CallMethod<jfloat>, // CallFloatMethod
2644 _Jv_JNI_CallMethodV<jfloat>, // CallFloatMethodV
2645 _Jv_JNI_CallMethodA<jfloat>, // CallFloatMethodA
2646 _Jv_JNI_CallMethod<jdouble>, // CallDoubleMethod
2647 _Jv_JNI_CallMethodV<jdouble>, // CallDoubleMethodV
2648 _Jv_JNI_CallMethodA<jdouble>, // CallDoubleMethodA
2649 _Jv_JNI_CallVoidMethod, // CallVoidMethod
2650 _Jv_JNI_CallVoidMethodV, // CallVoidMethodV
2651 _Jv_JNI_CallVoidMethodA, // CallVoidMethodA
2653 // Nonvirtual method invocation functions follow.
2654 _Jv_JNI_CallAnyMethod<jobject, nonvirtual>, // CallNonvirtualObjectMethod
2655 _Jv_JNI_CallAnyMethodV<jobject, nonvirtual>, // CallNonvirtualObjectMethodV
2656 _Jv_JNI_CallAnyMethodA<jobject, nonvirtual>, // CallNonvirtualObjectMethodA
2657 _Jv_JNI_CallAnyMethod<jboolean, nonvirtual>, // CallNonvirtualBooleanMethod
2658 _Jv_JNI_CallAnyMethodV<jboolean, nonvirtual>, // CallNonvirtualBooleanMethodV
2659 _Jv_JNI_CallAnyMethodA<jboolean, nonvirtual>, // CallNonvirtualBooleanMethodA
2660 _Jv_JNI_CallAnyMethod<jbyte, nonvirtual>, // CallNonvirtualByteMethod
2661 _Jv_JNI_CallAnyMethodV<jbyte, nonvirtual>, // CallNonvirtualByteMethodV
2662 _Jv_JNI_CallAnyMethodA<jbyte, nonvirtual>, // CallNonvirtualByteMethodA
2663 _Jv_JNI_CallAnyMethod<jchar, nonvirtual>, // CallNonvirtualCharMethod
2664 _Jv_JNI_CallAnyMethodV<jchar, nonvirtual>, // CallNonvirtualCharMethodV
2665 _Jv_JNI_CallAnyMethodA<jchar, nonvirtual>, // CallNonvirtualCharMethodA
2666 _Jv_JNI_CallAnyMethod<jshort, nonvirtual>, // CallNonvirtualShortMethod
2667 _Jv_JNI_CallAnyMethodV<jshort, nonvirtual>, // CallNonvirtualShortMethodV
2668 _Jv_JNI_CallAnyMethodA<jshort, nonvirtual>, // CallNonvirtualShortMethodA
2669 _Jv_JNI_CallAnyMethod<jint, nonvirtual>, // CallNonvirtualIntMethod
2670 _Jv_JNI_CallAnyMethodV<jint, nonvirtual>, // CallNonvirtualIntMethodV
2671 _Jv_JNI_CallAnyMethodA<jint, nonvirtual>, // CallNonvirtualIntMethodA
2672 _Jv_JNI_CallAnyMethod<jlong, nonvirtual>, // CallNonvirtualLongMethod
2673 _Jv_JNI_CallAnyMethodV<jlong, nonvirtual>, // CallNonvirtualLongMethodV
2674 _Jv_JNI_CallAnyMethodA<jlong, nonvirtual>, // CallNonvirtualLongMethodA
2675 _Jv_JNI_CallAnyMethod<jfloat, nonvirtual>, // CallNonvirtualFloatMethod
2676 _Jv_JNI_CallAnyMethodV<jfloat, nonvirtual>, // CallNonvirtualFloatMethodV
2677 _Jv_JNI_CallAnyMethodA<jfloat, nonvirtual>, // CallNonvirtualFloatMethodA
2678 _Jv_JNI_CallAnyMethod<jdouble, nonvirtual>, // CallNonvirtualDoubleMethod
2679 _Jv_JNI_CallAnyMethodV<jdouble, nonvirtual>, // CallNonvirtualDoubleMethodV
2680 _Jv_JNI_CallAnyMethodA<jdouble, nonvirtual>, // CallNonvirtualDoubleMethodA
2681 _Jv_JNI_CallAnyVoidMethod<nonvirtual>, // CallNonvirtualVoidMethod
2682 _Jv_JNI_CallAnyVoidMethodV<nonvirtual>, // CallNonvirtualVoidMethodV
2683 _Jv_JNI_CallAnyVoidMethodA<nonvirtual>, // CallNonvirtualVoidMethodA
2685 _Jv_JNI_GetAnyFieldID<false>, // GetFieldID
2686 _Jv_JNI_GetField<jobject>, // GetObjectField
2687 _Jv_JNI_GetField<jboolean>, // GetBooleanField
2688 _Jv_JNI_GetField<jbyte>, // GetByteField
2689 _Jv_JNI_GetField<jchar>, // GetCharField
2690 _Jv_JNI_GetField<jshort>, // GetShortField
2691 _Jv_JNI_GetField<jint>, // GetIntField
2692 _Jv_JNI_GetField<jlong>, // GetLongField
2693 _Jv_JNI_GetField<jfloat>, // GetFloatField
2694 _Jv_JNI_GetField<jdouble>, // GetDoubleField
2695 _Jv_JNI_SetField, // SetObjectField
2696 _Jv_JNI_SetField, // SetBooleanField
2697 _Jv_JNI_SetField, // SetByteField
2698 _Jv_JNI_SetField, // SetCharField
2699 _Jv_JNI_SetField, // SetShortField
2700 _Jv_JNI_SetField, // SetIntField
2701 _Jv_JNI_SetField, // SetLongField
2702 _Jv_JNI_SetField, // SetFloatField
2703 _Jv_JNI_SetField, // SetDoubleField
2704 _Jv_JNI_GetAnyMethodID<true>, // GetStaticMethodID
2706 _Jv_JNI_CallStaticMethod<jobject>, // CallStaticObjectMethod
2707 _Jv_JNI_CallStaticMethodV<jobject>, // CallStaticObjectMethodV
2708 _Jv_JNI_CallStaticMethodA<jobject>, // CallStaticObjectMethodA
2709 _Jv_JNI_CallStaticMethod<jboolean>, // CallStaticBooleanMethod
2710 _Jv_JNI_CallStaticMethodV<jboolean>, // CallStaticBooleanMethodV
2711 _Jv_JNI_CallStaticMethodA<jboolean>, // CallStaticBooleanMethodA
2712 _Jv_JNI_CallStaticMethod<jbyte>, // CallStaticByteMethod
2713 _Jv_JNI_CallStaticMethodV<jbyte>, // CallStaticByteMethodV
2714 _Jv_JNI_CallStaticMethodA<jbyte>, // CallStaticByteMethodA
2715 _Jv_JNI_CallStaticMethod<jchar>, // CallStaticCharMethod
2716 _Jv_JNI_CallStaticMethodV<jchar>, // CallStaticCharMethodV
2717 _Jv_JNI_CallStaticMethodA<jchar>, // CallStaticCharMethodA
2718 _Jv_JNI_CallStaticMethod<jshort>, // CallStaticShortMethod
2719 _Jv_JNI_CallStaticMethodV<jshort>, // CallStaticShortMethodV
2720 _Jv_JNI_CallStaticMethodA<jshort>, // CallStaticShortMethodA
2721 _Jv_JNI_CallStaticMethod<jint>, // CallStaticIntMethod
2722 _Jv_JNI_CallStaticMethodV<jint>, // CallStaticIntMethodV
2723 _Jv_JNI_CallStaticMethodA<jint>, // CallStaticIntMethodA
2724 _Jv_JNI_CallStaticMethod<jlong>, // CallStaticLongMethod
2725 _Jv_JNI_CallStaticMethodV<jlong>, // CallStaticLongMethodV
2726 _Jv_JNI_CallStaticMethodA<jlong>, // CallStaticLongMethodA
2727 _Jv_JNI_CallStaticMethod<jfloat>, // CallStaticFloatMethod
2728 _Jv_JNI_CallStaticMethodV<jfloat>, // CallStaticFloatMethodV
2729 _Jv_JNI_CallStaticMethodA<jfloat>, // CallStaticFloatMethodA
2730 _Jv_JNI_CallStaticMethod<jdouble>, // CallStaticDoubleMethod
2731 _Jv_JNI_CallStaticMethodV<jdouble>, // CallStaticDoubleMethodV
2732 _Jv_JNI_CallStaticMethodA<jdouble>, // CallStaticDoubleMethodA
2733 _Jv_JNI_CallStaticVoidMethod, // CallStaticVoidMethod
2734 _Jv_JNI_CallStaticVoidMethodV, // CallStaticVoidMethodV
2735 _Jv_JNI_CallStaticVoidMethodA, // CallStaticVoidMethodA
2737 _Jv_JNI_GetAnyFieldID<true>, // GetStaticFieldID
2738 _Jv_JNI_GetStaticField<jobject>, // GetStaticObjectField
2739 _Jv_JNI_GetStaticField<jboolean>, // GetStaticBooleanField
2740 _Jv_JNI_GetStaticField<jbyte>, // GetStaticByteField
2741 _Jv_JNI_GetStaticField<jchar>, // GetStaticCharField
2742 _Jv_JNI_GetStaticField<jshort>, // GetStaticShortField
2743 _Jv_JNI_GetStaticField<jint>, // GetStaticIntField
2744 _Jv_JNI_GetStaticField<jlong>, // GetStaticLongField
2745 _Jv_JNI_GetStaticField<jfloat>, // GetStaticFloatField
2746 _Jv_JNI_GetStaticField<jdouble>, // GetStaticDoubleField
2747 _Jv_JNI_SetStaticField, // SetStaticObjectField
2748 _Jv_JNI_SetStaticField, // SetStaticBooleanField
2749 _Jv_JNI_SetStaticField, // SetStaticByteField
2750 _Jv_JNI_SetStaticField, // SetStaticCharField
2751 _Jv_JNI_SetStaticField, // SetStaticShortField
2752 _Jv_JNI_SetStaticField, // SetStaticIntField
2753 _Jv_JNI_SetStaticField, // SetStaticLongField
2754 _Jv_JNI_SetStaticField, // SetStaticFloatField
2755 _Jv_JNI_SetStaticField, // SetStaticDoubleField
2756 _Jv_JNI_NewString, // NewString
2757 _Jv_JNI_GetStringLength, // GetStringLength
2758 _Jv_JNI_GetStringChars, // GetStringChars
2759 _Jv_JNI_ReleaseStringChars, // ReleaseStringChars
2760 _Jv_JNI_NewStringUTF, // NewStringUTF
2761 _Jv_JNI_GetStringUTFLength, // GetStringUTFLength
2762 _Jv_JNI_GetStringUTFChars, // GetStringUTFChars
2763 _Jv_JNI_ReleaseStringUTFChars, // ReleaseStringUTFChars
2764 _Jv_JNI_GetArrayLength, // GetArrayLength
2765 _Jv_JNI_NewObjectArray, // NewObjectArray
2766 _Jv_JNI_GetObjectArrayElement, // GetObjectArrayElement
2767 _Jv_JNI_SetObjectArrayElement, // SetObjectArrayElement
2768 _Jv_JNI_NewPrimitiveArray<jboolean, JvPrimClass (boolean)>,
2769 // NewBooleanArray
2770 _Jv_JNI_NewPrimitiveArray<jbyte, JvPrimClass (byte)>, // NewByteArray
2771 _Jv_JNI_NewPrimitiveArray<jchar, JvPrimClass (char)>, // NewCharArray
2772 _Jv_JNI_NewPrimitiveArray<jshort, JvPrimClass (short)>, // NewShortArray
2773 _Jv_JNI_NewPrimitiveArray<jint, JvPrimClass (int)>, // NewIntArray
2774 _Jv_JNI_NewPrimitiveArray<jlong, JvPrimClass (long)>, // NewLongArray
2775 _Jv_JNI_NewPrimitiveArray<jfloat, JvPrimClass (float)>, // NewFloatArray
2776 _Jv_JNI_NewPrimitiveArray<jdouble, JvPrimClass (double)>, // NewDoubleArray
2777 _Jv_JNI_GetPrimitiveArrayElements<jboolean, JvPrimClass (boolean)>,
2778 // GetBooleanArrayElements
2779 _Jv_JNI_GetPrimitiveArrayElements<jbyte, JvPrimClass (byte)>,
2780 // GetByteArrayElements
2781 _Jv_JNI_GetPrimitiveArrayElements<jchar, JvPrimClass (char)>,
2782 // GetCharArrayElements
2783 _Jv_JNI_GetPrimitiveArrayElements<jshort, JvPrimClass (short)>,
2784 // GetShortArrayElements
2785 _Jv_JNI_GetPrimitiveArrayElements<jint, JvPrimClass (int)>,
2786 // GetIntArrayElements
2787 _Jv_JNI_GetPrimitiveArrayElements<jlong, JvPrimClass (long)>,
2788 // GetLongArrayElements
2789 _Jv_JNI_GetPrimitiveArrayElements<jfloat, JvPrimClass (float)>,
2790 // GetFloatArrayElements
2791 _Jv_JNI_GetPrimitiveArrayElements<jdouble, JvPrimClass (double)>,
2792 // GetDoubleArrayElements
2793 _Jv_JNI_ReleasePrimitiveArrayElements<jboolean, JvPrimClass (boolean)>,
2794 // ReleaseBooleanArrayElements
2795 _Jv_JNI_ReleasePrimitiveArrayElements<jbyte, JvPrimClass (byte)>,
2796 // ReleaseByteArrayElements
2797 _Jv_JNI_ReleasePrimitiveArrayElements<jchar, JvPrimClass (char)>,
2798 // ReleaseCharArrayElements
2799 _Jv_JNI_ReleasePrimitiveArrayElements<jshort, JvPrimClass (short)>,
2800 // ReleaseShortArrayElements
2801 _Jv_JNI_ReleasePrimitiveArrayElements<jint, JvPrimClass (int)>,
2802 // ReleaseIntArrayElements
2803 _Jv_JNI_ReleasePrimitiveArrayElements<jlong, JvPrimClass (long)>,
2804 // ReleaseLongArrayElements
2805 _Jv_JNI_ReleasePrimitiveArrayElements<jfloat, JvPrimClass (float)>,
2806 // ReleaseFloatArrayElements
2807 _Jv_JNI_ReleasePrimitiveArrayElements<jdouble, JvPrimClass (double)>,
2808 // ReleaseDoubleArrayElements
2809 _Jv_JNI_GetPrimitiveArrayRegion<jboolean, JvPrimClass (boolean)>,
2810 // GetBooleanArrayRegion
2811 _Jv_JNI_GetPrimitiveArrayRegion<jbyte, JvPrimClass (byte)>,
2812 // GetByteArrayRegion
2813 _Jv_JNI_GetPrimitiveArrayRegion<jchar, JvPrimClass (char)>,
2814 // GetCharArrayRegion
2815 _Jv_JNI_GetPrimitiveArrayRegion<jshort, JvPrimClass (short)>,
2816 // GetShortArrayRegion
2817 _Jv_JNI_GetPrimitiveArrayRegion<jint, JvPrimClass (int)>,
2818 // GetIntArrayRegion
2819 _Jv_JNI_GetPrimitiveArrayRegion<jlong, JvPrimClass (long)>,
2820 // GetLongArrayRegion
2821 _Jv_JNI_GetPrimitiveArrayRegion<jfloat, JvPrimClass (float)>,
2822 // GetFloatArrayRegion
2823 _Jv_JNI_GetPrimitiveArrayRegion<jdouble, JvPrimClass (double)>,
2824 // GetDoubleArrayRegion
2825 _Jv_JNI_SetPrimitiveArrayRegion<jboolean, JvPrimClass (boolean)>,
2826 // SetBooleanArrayRegion
2827 _Jv_JNI_SetPrimitiveArrayRegion<jbyte, JvPrimClass (byte)>,
2828 // SetByteArrayRegion
2829 _Jv_JNI_SetPrimitiveArrayRegion<jchar, JvPrimClass (char)>,
2830 // SetCharArrayRegion
2831 _Jv_JNI_SetPrimitiveArrayRegion<jshort, JvPrimClass (short)>,
2832 // SetShortArrayRegion
2833 _Jv_JNI_SetPrimitiveArrayRegion<jint, JvPrimClass (int)>,
2834 // SetIntArrayRegion
2835 _Jv_JNI_SetPrimitiveArrayRegion<jlong, JvPrimClass (long)>,
2836 // SetLongArrayRegion
2837 _Jv_JNI_SetPrimitiveArrayRegion<jfloat, JvPrimClass (float)>,
2838 // SetFloatArrayRegion
2839 _Jv_JNI_SetPrimitiveArrayRegion<jdouble, JvPrimClass (double)>,
2840 // SetDoubleArrayRegion
2841 _Jv_JNI_RegisterNatives, // RegisterNatives
2842 _Jv_JNI_UnregisterNatives, // UnregisterNatives
2843 _Jv_JNI_MonitorEnter, // MonitorEnter
2844 _Jv_JNI_MonitorExit, // MonitorExit
2845 _Jv_JNI_GetJavaVM, // GetJavaVM
2847 _Jv_JNI_GetStringRegion, // GetStringRegion
2848 _Jv_JNI_GetStringUTFRegion, // GetStringUTFRegion
2849 _Jv_JNI_GetPrimitiveArrayCritical, // GetPrimitiveArrayCritical
2850 _Jv_JNI_ReleasePrimitiveArrayCritical, // ReleasePrimitiveArrayCritical
2851 _Jv_JNI_GetStringCritical, // GetStringCritical
2852 _Jv_JNI_ReleaseStringCritical, // ReleaseStringCritical
2854 _Jv_JNI_NewWeakGlobalRef, // NewWeakGlobalRef
2855 _Jv_JNI_DeleteWeakGlobalRef, // DeleteWeakGlobalRef
2857 _Jv_JNI_ExceptionCheck, // ExceptionCheck
2859 _Jv_JNI_NewDirectByteBuffer, // NewDirectByteBuffer
2860 _Jv_JNI_GetDirectBufferAddress, // GetDirectBufferAddress
2861 _Jv_JNI_GetDirectBufferCapacity // GetDirectBufferCapacity
2864 struct JNIInvokeInterface _Jv_JNI_InvokeFunctions =
2866 RESERVED,
2867 RESERVED,
2868 RESERVED,
2870 _Jv_JNI_DestroyJavaVM,
2871 _Jv_JNI_AttachCurrentThread,
2872 _Jv_JNI_DetachCurrentThread,
2873 _Jv_JNI_GetEnv,
2874 _Jv_JNI_AttachCurrentThreadAsDaemon