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
20 #include <java-assert.h>
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>
56 // This enum is used to select different template instantiations in
57 // the invocation code.
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
74 // Mark value indicating this is an overflow frame.
76 // Mark value indicating this is a user frame.
78 // Mark value indicating this is a system frame.
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).
88 // Flag to indicate some locals were allocated.
91 // Number of elements in frame.
94 // Next frame in chain.
95 _Jv_JNI_LocalFrame
*next
;
97 // The elements. These are allocated using the C "struct hack".
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
;
107 static JavaVM
*the_vm
;
110 // The only JVMPI interface description.
111 static JVMPI_Interface _Jv_JVMPI_Interface
;
114 jvmpiEnableEvent (jint event_type
, void *)
118 case JVMPI_EVENT_OBJECT_ALLOC
:
119 _Jv_JVMPI_Notify_OBJECT_ALLOC
= _Jv_JVMPI_Interface
.NotifyEvent
;
122 case JVMPI_EVENT_THREAD_START
:
123 _Jv_JVMPI_Notify_THREAD_START
= _Jv_JVMPI_Interface
.NotifyEvent
;
126 case JVMPI_EVENT_THREAD_END
:
127 _Jv_JVMPI_Notify_THREAD_END
= _Jv_JVMPI_Interface
.NotifyEvent
;
131 return JVMPI_NOT_AVAILABLE
;
134 return JVMPI_SUCCESS
;
138 jvmpiDisableEvent (jint event_type
, void *)
142 case JVMPI_EVENT_OBJECT_ALLOC
:
143 _Jv_JVMPI_Notify_OBJECT_ALLOC
= NULL
;
147 return JVMPI_NOT_AVAILABLE
;
150 return JVMPI_SUCCESS
;
159 local_ref_table
= new java::util::IdentityHashMap
;
160 global_ref_table
= new java::util::IdentityHashMap
;
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
;
172 // Tell the GC that a certain pointer is live.
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));
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
);
194 jint val
= refcount
->intValue () - 1;
197 ref_table
->remove (obj
);
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.
212 // Unwrap a weak reference, if required.
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$
)
222 JNIWeakRef
*wr
= reinterpret_cast<JNIWeakRef
*> (obj
);
223 return reinterpret_cast<T
*> (wr
->get ());
229 (JNICALL _Jv_JNI_NewGlobalRef
) (JNIEnv
*, jobject obj
)
231 // This seems weird but I think it is correct.
233 mark_for_gc (obj
, global_ref_table
);
238 (JNICALL _Jv_JNI_DeleteGlobalRef
) (JNIEnv
*, jobject obj
)
240 // This seems weird but I think it is correct.
242 unmark_for_gc (obj
, global_ref_table
);
246 (JNICALL _Jv_JNI_DeleteLocalRef
) (JNIEnv
*env
, jobject obj
)
248 _Jv_JNI_LocalFrame
*frame
;
250 // This seems weird but I think it is correct.
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
);
265 // Don't go past a marked frame.
266 JvAssert (frame
->marker
== MARK_NONE
);
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
));
291 frame
->marker
= MARK_NONE
;
293 frame
->allocated_p
= 0;
294 memset (&frame
->vec
[0], 0, size
* sizeof (jobject
));
295 frame
->next
= env
->locals
;
302 (JNICALL _Jv_JNI_PushLocalFrame
) (JNIEnv
*env
, jint size
)
304 jint r
= _Jv_JNI_EnsureLocalCapacity (env
, size
);
308 // The new frame is on top.
309 env
->locals
->marker
= MARK_USER
;
315 (JNICALL _Jv_JNI_NewLocalRef
) (JNIEnv
*env
, jobject obj
)
317 // This seems weird but I think it is correct.
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
)
332 frame
->allocated_p
= 1;
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
)
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
);
358 (JNICALL _Jv_JNI_PopLocalFrame
) (JNIEnv
*env
, jobject result
, int stop
)
360 _Jv_JNI_LocalFrame
*rf
= env
->locals
;
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.
378 memset (&rf
->vec
[0], 0, rf
->size
* sizeof (jobject
));
388 // Update the local frame information.
391 return result
== NULL
? NULL
: _Jv_JNI_NewLocalRef (env
, result
);
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
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 ();
416 // Pop a `system' frame from the stack. This is `extern "C"' as it is
417 // used by the compiler.
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
425 if (__builtin_expect ((env
->locals
->next
426 || env
->locals
->allocated_p
), false))
427 _Jv_JNI_PopLocalFrame (env
, NULL
, MARK_SYSTEM
);
431 if (__builtin_expect (env
->ex
!= NULL
, false))
433 jthrowable t
= env
->ex
;
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.
456 wrap_value (JNIEnv
*, T value
)
461 // This specialization is used for jobject, jclass, jstring, jarray,
463 template<typename R
, typename T
>
465 wrap_value (JNIEnv
*env
, T
*value
)
467 return (value
== NULL
469 : (T
*) _Jv_JNI_NewLocalRef (env
, (jobject
) value
));
475 (JNICALL _Jv_JNI_GetVersion
) (JNIEnv
*)
477 return JNI_VERSION_1_4
;
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
);
508 (JNICALL _Jv_JNI_FindClass
) (JNIEnv
*env
, const char *name
)
510 // FIXME: assume that NAME isn't too long.
511 int len
= strlen (name
);
513 for (int i
= 0; i
<= len
; ++i
)
514 s
[i
] = (name
[i
] == '/') ? '.' : name
[i
];
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 ();
528 // FIXME: should use getBaseClassLoader, but we don't have that
530 loader
= java::lang::ClassLoader::getSystemClassLoader ();
533 r
= loader
->loadClass (n
);
540 return (jclass
) wrap_value (env
, r
);
544 (JNICALL _Jv_JNI_GetSuperclass
) (JNIEnv
*env
, jclass clazz
)
546 return (jclass
) wrap_value (env
, unwrap (clazz
)->getSuperclass ());
550 (JNICALL _Jv_JNI_IsAssignableFrom
) (JNIEnv
*, jclass clazz1
, jclass clazz2
)
552 return unwrap (clazz1
)->isAssignableFrom (unwrap (clazz2
));
556 (JNICALL _Jv_JNI_Throw
) (JNIEnv
*env
, jthrowable obj
)
558 // We check in case the user did some funky cast.
560 JvAssert (obj
!= NULL
&& java::lang::Throwable::class$
.isInstance (obj
));
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
));
576 JArray
<jclass
> *argtypes
577 = (JArray
<jclass
> *) JvNewObjectArray (1, &java::lang::Class::class$
,
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
);
603 (JNICALL _Jv_JNI_ExceptionOccurred
) (JNIEnv
*env
)
605 return (jthrowable
) wrap_value (env
, env
->ex
);
609 (JNICALL _Jv_JNI_ExceptionDescribe
) (JNIEnv
*env
)
612 env
->ex
->printStackTrace();
616 (JNICALL _Jv_JNI_ExceptionClear
) (JNIEnv
*env
)
622 (JNICALL _Jv_JNI_ExceptionCheck
) (JNIEnv
*env
)
624 return env
->ex
!= NULL
;
628 (JNICALL _Jv_JNI_FatalError
) (JNIEnv
*, const char *message
)
636 (JNICALL _Jv_JNI_IsSameObject
) (JNIEnv
*, jobject obj1
, jobject obj2
)
638 return unwrap (obj1
) == unwrap (obj2
);
642 (JNICALL _Jv_JNI_AllocObject
) (JNIEnv
*env
, jclass clazz
)
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 ();
654 obj
= _Jv_AllocObject (clazz
);
661 return wrap_value (env
, obj
);
665 (JNICALL _Jv_JNI_GetObjectClass
) (JNIEnv
*env
, jobject obj
)
669 return (jclass
) wrap_value (env
, obj
->getClass());
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
>
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
);
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
))
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 ());
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.
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
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);
776 values
[i
].l
= unwrap (va_arg (vargs
, jobject
));
781 // This can call any sort of method: virtual, "nonvirtual", static, or
783 template<typename T
, invocation_type style
>
785 (JNICALL _Jv_JNI_CallAnyMethodV
) (JNIEnv
*env
, jobject obj
, jclass klass
,
786 jmethodID id
, va_list vargs
)
789 klass
= unwrap (klass
);
791 jclass decl_class
= klass
? klass
: obj
->getClass ();
792 JvAssert (decl_class
!= NULL
);
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
)
810 _Jv_CallAnyMethodA (obj
, return_type
, id
,
811 style
== constructor
,
813 arg_types
, args
, &result
);
815 return wrap_value (env
, extract_from_jvalue
<T
>(result
));
822 return wrap_value (env
, (T
) 0);
825 template<typename T
, invocation_type style
>
827 (JNICALL _Jv_JNI_CallAnyMethod
) (JNIEnv
*env
, jobject obj
, jclass klass
,
828 jmethodID method
, ...)
833 va_start (args
, method
);
834 result
= _Jv_JNI_CallAnyMethodV
<T
, style
> (env
, obj
, klass
, method
, args
);
840 template<typename T
, invocation_type style
>
842 (JNICALL _Jv_JNI_CallAnyMethodA
) (JNIEnv
*env
, jobject obj
, jclass klass
,
843 jmethodID id
, jvalue
*args
)
846 klass
= unwrap (klass
);
848 jclass decl_class
= klass
? klass
: obj
->getClass ();
849 JvAssert (decl_class
!= NULL
);
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
)
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
];
870 arg_copy
[i
].l
= unwrap (args
[i
].l
);
874 _Jv_CallAnyMethodA (obj
, return_type
, id
,
875 style
== constructor
,
877 arg_types
, arg_copy
, &result
);
879 return wrap_value (env
, extract_from_jvalue
<T
>(result
));
886 return wrap_value (env
, (T
) 0);
889 template<invocation_type style
>
891 (JNICALL _Jv_JNI_CallAnyVoidMethodV
) (JNIEnv
*env
, jobject obj
, jclass klass
,
892 jmethodID id
, va_list vargs
)
895 klass
= unwrap (klass
);
897 jclass decl_class
= klass
? klass
: obj
->getClass ();
898 JvAssert (decl_class
!= NULL
);
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
)
914 _Jv_CallAnyMethodA (obj
, return_type
, id
,
915 style
== constructor
,
917 arg_types
, args
, NULL
);
925 template<invocation_type style
>
927 (JNICALL _Jv_JNI_CallAnyVoidMethod
) (JNIEnv
*env
, jobject obj
, jclass klass
,
928 jmethodID method
, ...)
932 va_start (args
, method
);
933 _Jv_JNI_CallAnyVoidMethodV
<style
> (env
, obj
, klass
, method
, args
);
937 template<invocation_type style
>
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
);
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
];
960 arg_copy
[i
].l
= unwrap (args
[i
].l
);
963 _Jv_CallAnyMethodA (obj
, return_type
, id
,
964 style
== constructor
,
966 arg_types
, args
, NULL
);
974 // Functions with this signature are used to implement functions in
975 // the CallMethod family.
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.
988 (JNICALL _Jv_JNI_CallMethod
) (JNIEnv
*env
, jobject obj
, jmethodID id
, ...)
994 result
= _Jv_JNI_CallAnyMethodV
<T
, normal
> (env
, obj
, NULL
, id
, args
);
1000 // Functions with this signature are used to implement functions in
1001 // the CallMethod family.
1002 template<typename 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
);
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
);
1018 (JNICALL _Jv_JNI_CallVoidMethod
) (JNIEnv
*env
, jobject obj
, jmethodID id
, ...)
1022 va_start (args
, id
);
1023 _Jv_JNI_CallAnyVoidMethodV
<normal
> (env
, obj
, NULL
, id
, args
);
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
>
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
>
1051 (JNICALL _Jv_JNI_CallStaticMethod
) (JNIEnv
*env
, jclass klass
,
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
,
1068 // Functions with this signature are used to implement functions in
1069 // the CallStaticMethod family.
1070 template<typename T
>
1072 (JNICALL _Jv_JNI_CallStaticMethodA
) (JNIEnv
*env
, jclass klass
, jmethodID id
,
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
);
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
);
1089 (JNICALL _Jv_JNI_CallStaticVoidMethod
) (JNIEnv
*env
, jclass klass
,
1094 va_start (args
, id
);
1095 _Jv_JNI_CallAnyVoidMethodV
<static_type
> (env
, NULL
, klass
, id
, args
);
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
);
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],
1117 return _Jv_JNI_CallAnyMethodV
<jobject
, constructor
> (env
, NULL
, klass
,
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],
1134 va_start (args
, id
);
1135 result
= _Jv_JNI_CallAnyMethodV
<jobject
, constructor
> (env
, NULL
, klass
,
1143 (JNICALL _Jv_JNI_NewObjectA
) (JNIEnv
*env
, jclass klass
, jmethodID id
,
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],
1153 return _Jv_JNI_CallAnyMethodA
<jobject
, constructor
> (env
, NULL
, klass
,
1159 template<typename T
>
1161 (JNICALL _Jv_JNI_GetField
) (JNIEnv
*env
, jobject obj
, jfieldID field
)
1165 T
*ptr
= (T
*) ((char *) obj
+ field
->getOffset ());
1166 return wrap_value (env
, *ptr
);
1169 template<typename T
>
1171 (JNICALL _Jv_JNI_SetField
) (JNIEnv
*, jobject obj
, jfieldID field
, T value
)
1174 value
= unwrap (value
);
1177 T
*ptr
= (T
*) ((char *) obj
+ field
->getOffset ());
1181 template<jboolean is_static
>
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
);
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
)
1227 field
= field
->getNextField ();
1230 clazz
= clazz
->getSuperclass ();
1233 env
->ex
= new java::lang::NoSuchFieldError ();
1235 catch (jthrowable t
)
1242 template<typename 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
>
1252 (JNICALL _Jv_JNI_SetStaticField
) (JNIEnv
*, jclass
, jfieldID field
, T value
)
1254 value
= unwrap (value
);
1255 T
*ptr
= (T
*) field
->u
.addr
;
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
)
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
);
1288 return (const jchar
*) result
;
1292 (JNICALL _Jv_JNI_ReleaseStringChars
) (JNIEnv
*, jstring string
, const jchar
*)
1294 unmark_for_gc (unwrap (string
), global_ref_table
);
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
)
1313 (JNICALL _Jv_JNI_GetStringUTFLength
) (JNIEnv
*, jstring string
)
1315 return JvGetStringUTFLength (unwrap (string
));
1319 (JNICALL _Jv_JNI_GetStringUTFChars
) (JNIEnv
*env
, jstring string
,
1324 string
= unwrap (string
);
1327 jsize len
= JvGetStringUTFLength (string
);
1328 char *r
= (char *) _Jv_Malloc (len
+ 1);
1329 JvGetStringUTFRegion (string
, 0, string
->length(), r
);
1335 return (const char *) r
;
1337 catch (jthrowable t
)
1345 (JNICALL _Jv_JNI_ReleaseStringUTFChars
) (JNIEnv
*, jstring
, const char *utf
)
1347 _Jv_Free ((void *) utf
);
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
)
1369 memcpy (buf
, &result
[start
], len
* sizeof (jchar
));
1373 (JNICALL _Jv_JNI_GetStringUTFRegion
) (JNIEnv
*env
, jstring str
, jsize start
,
1374 jsize len
, char *buf
)
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
)
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
));
1404 (JNICALL _Jv_JNI_ReleaseStringCritical
) (JNIEnv
*, jstring
, const jchar
*)
1410 (JNICALL _Jv_JNI_GetArrayLength
) (JNIEnv
*, jarray array
)
1412 return unwrap (array
)->length
;
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
)
1436 (JNICALL _Jv_JNI_GetObjectArrayElement
) (JNIEnv
*env
, jobjectArray array
,
1439 if ((unsigned) index
>= (unsigned) array
->length
)
1440 _Jv_ThrowBadArrayIndex (index
);
1441 jobject
*elts
= elements (unwrap (array
));
1442 return wrap_value (env
, elts
[index
]);
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
)
1466 template<typename T
, jclass K
>
1468 (JNICALL _Jv_JNI_NewPrimitiveArray
) (JNIEnv
*env
, jsize length
)
1472 return (JArray
<T
> *) wrap_value (env
, _Jv_NewPrimArray (K
, length
));
1474 catch (jthrowable t
)
1481 template<typename T
, jclass K
>
1483 (JNICALL _Jv_JNI_GetPrimitiveArrayElements
) (JNIEnv
*env
, JArray
<T
> *array
,
1486 array
= unwrap (array
);
1487 if (! _Jv_JNI_check_types (env
, array
, K
))
1489 T
*elts
= elements (array
);
1492 // We elect never to copy.
1495 mark_for_gc (array
, global_ref_table
);
1499 template<typename T
, jclass K
>
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
>
1514 (JNICALL _Jv_JNI_GetPrimitiveArrayRegion
) (JNIEnv
*env
, JArray
<T
> *array
,
1515 jsize start
, jsize len
,
1518 array
= unwrap (array
);
1519 if (! _Jv_JNI_check_types (env
, array
, K
))
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
)
1529 env
->ex
= new java::lang::ArrayIndexOutOfBoundsException ();
1531 catch (jthrowable t
)
1533 // Could have thown out of memory error.
1539 T
*elts
= elements (array
) + start
;
1540 memcpy (buf
, elts
, len
* sizeof (T
));
1544 template<typename T
, jclass K
>
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
))
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
)
1560 env
->ex
= new java::lang::ArrayIndexOutOfBoundsException ();
1562 catch (jthrowable t
)
1569 T
*elts
= elements (array
) + start
;
1570 memcpy (elts
, buf
, len
* sizeof (T
));
1575 (JNICALL _Jv_JNI_GetPrimitiveArrayCritical
) (JNIEnv
*, jarray array
,
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
);
1589 (JNICALL _Jv_JNI_ReleasePrimitiveArrayCritical
) (JNIEnv
*, jarray
, void *, jint
)
1595 (JNICALL _Jv_JNI_MonitorEnter
) (JNIEnv
*env
, jobject obj
)
1599 _Jv_MonitorEnter (unwrap (obj
));
1602 catch (jthrowable t
)
1610 (JNICALL _Jv_JNI_MonitorExit
) (JNIEnv
*env
, jobject obj
)
1614 _Jv_MonitorExit (unwrap (obj
));
1617 catch (jthrowable t
)
1626 (JNICALL _Jv_JNI_ToReflectedField
) (JNIEnv
*env
, jclass cls
, jfieldID fieldID
,
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
)
1647 (JNICALL _Jv_JNI_FromReflectedField
) (JNIEnv
*, jobject f
)
1649 using namespace java::lang::reflect
;
1652 Field
*field
= reinterpret_cast<Field
*> (f
);
1653 return _Jv_FromReflectedField (field
);
1657 (JNICALL _Jv_JNI_ToReflectedMethod
) (JNIEnv
*env
, jclass klass
, jmethodID id
,
1660 using namespace java::lang::reflect
;
1662 jobject result
= NULL
;
1663 klass
= unwrap (klass
);
1667 if (_Jv_equalUtf8Consts (id
->name
, init_name
))
1670 Constructor
*cons
= new Constructor ();
1671 cons
->offset
= (char *) id
- (char *) &klass
->methods
;
1672 cons
->declaringClass
= klass
;
1677 Method
*meth
= new Method ();
1678 meth
->offset
= (char *) id
- (char *) &klass
->methods
;
1679 meth
->declaringClass
= klass
;
1683 catch (jthrowable t
)
1688 return wrap_value (env
, result
);
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
));
1699 _Jv_FromReflectedConstructor (reinterpret_cast<Constructor
*> (method
));
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.
1713 ref
= new JNIWeakRef (obj
);
1714 mark_for_gc (ref
, global_ref_table
);
1716 catch (jthrowable t
)
1721 return reinterpret_cast<jweak
> (ref
);
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
);
1735 // Direct byte buffers.
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
),
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
);
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.
1775 hash (const JNINativeMethod
*method
)
1782 hash
= (31 * hash
) + *ptr
++;
1784 ptr
= method
->signature
;
1786 hash
= (31 * hash
) + *ptr
++;
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);
1802 JNINativeMethod
*slotp
= &nathash
[w
];
1803 if (slotp
->name
== NULL
)
1806 return &nathash
[del
];
1810 else if (slotp
->name
== DELETED_ENTRY
)
1812 else if (! strcmp (slotp
->name
, method
->name
)
1813 && ! strcmp (slotp
->signature
, method
->signature
))
1815 w
= (w
+ step
) & (nathash_size
- 1);
1819 // Find a method. Return NULL if it isn't in the hash table.
1821 nathash_find (JNINativeMethod
*method
)
1823 if (nathash
== NULL
)
1825 JNINativeMethod
*slot
= nathash_find_slot (method
);
1826 if (slot
->name
== NULL
|| slot
->name
== DELETED_ENTRY
)
1834 if (nathash
== NULL
)
1836 nathash_size
= 1024;
1838 (JNINativeMethod
*) _Jv_AllocBytes (nathash_size
1839 * sizeof (JNINativeMethod
));
1840 memset (nathash
, 0, nathash_size
* sizeof (JNINativeMethod
));
1844 int savesize
= nathash_size
;
1845 JNINativeMethod
*savehash
= 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
];
1864 nathash_add (const JNINativeMethod
*method
)
1866 if (3 * nathash_count
>= 2 * nathash_size
)
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
)
1873 slot
->name
= strdup (method
->name
);
1874 slot
->signature
= strdup (method
->signature
);
1875 slot
->fnPtr
= method
->fnPtr
;
1879 (JNICALL _Jv_JNI_RegisterNatives
) (JNIEnv
*env
, jclass klass
,
1880 const JNINativeMethod
*methods
,
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
)
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
))
1906 // Found a match that is native.
1908 nathash_add (&methods
[j
]);
1916 jstring m
= JvNewStringUTF (methods
[j
].name
);
1919 env
->ex
=new java::lang::NoSuchMethodError (m
);
1921 catch (jthrowable t
)
1933 (JNICALL _Jv_JNI_UnregisterNatives
) (JNIEnv
*, jclass
)
1935 // FIXME -- we could implement this.
1941 // Add a character to the buffer, encoding properly.
1943 add_char (char *buf
, jchar c
, int *here
)
1947 buf
[(*here
)++] = '_';
1948 buf
[(*here
)++] = '1';
1952 buf
[(*here
)++] = '_';
1953 buf
[(*here
)++] = '2';
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
;
1971 // "Unicode" character.
1972 buf
[(*here
)++] = '_';
1973 buf
[(*here
)++] = '0';
1974 for (int i
= 0; i
< 4; ++i
)
1977 buf
[(*here
) + 3 - i
] = (val
> 10) ? ('a' + val
- 10) : ('0' + val
);
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.
1989 mangled_name (jclass klass
, _Jv_Utf8Const
*func_name
,
1990 _Jv_Utf8Const
*signature
, char *buf
, int *long_start
)
1992 strcpy (buf
, "Java_");
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 `_'.
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
);
2011 add_char (buf
, ch
, &here
);
2014 // This is where the long signature begins.
2019 const unsigned char *sig
= (const unsigned char *) signature
->data
;
2020 limit
= sig
+ signature
->length
;
2021 JvAssert (sig
[0] == '(');
2025 int ch
= UTF8_GET (sig
, limit
);
2026 if (ch
== ')' || ch
< 0)
2028 add_char (buf
, ch
, &here
);
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.
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
;
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
)
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
2069 if (__builtin_expect (env
->locals
== NULL
, true))
2070 env
->locals
= env
->bottom_locals
;
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
)
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
;
2099 // Destroy the env's reusable resources. This is called from the thread
2100 // destructor "finalize_native" in natThread.cc
2102 _Jv_FreeJNIEnv (_Jv_JNIEnv
*env
)
2107 if (env
->bottom_locals
!= NULL
)
2108 _Jv_Free (env
->bottom_locals
);
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.
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];
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
;
2134 meth
.signature
= buf
+ name
->length
+ 1;
2135 function
= nathash_find (&meth
);
2136 if (function
!= NULL
)
2139 // If there was no override, then look in the symbol table.
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);
2147 // On Win32, we use the "stdcall" calling convention (see JNICALL
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
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);
2181 if (function
== NULL
)
2183 buf
[long_start
+ 1] = c
;
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
));
2189 function
= _Jv_FindSymbolInExecutable (buf
+ 1);
2190 if (function
== NULL
)
2193 strcat (buf
, asz_buf
);
2194 function
= _Jv_FindSymbolInExecutable (buf
);
2195 if (function
== NULL
)
2196 function
= _Jv_FindSymbolInExecutable (buf
+ 1);
2198 if (function
== NULL
)
2201 jstring str
= JvNewStringUTF (name
->data
);
2202 throw new java::lang::UnsatisfiedLinkError (str
);
2212 // This function is the stub which is used to turn an ordinary (CNI)
2213 // method call into a JNI call.
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
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
,
2242 _this
->self
->signature
,
2247 JvAssert (_this
->args_raw_size
% sizeof (ffi_raw
) == 0);
2248 ffi_raw real_args
[2 + _this
->args_raw_size
/ sizeof (ffi_raw
)];
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
;
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
,
2278 _Jv_MonitorExit (sync
);
2280 _Jv_JNI_PopSystemFrame (env
);
2283 #endif /* INTERPRETER */
2291 // An internal helper function.
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
;
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
)
2315 JNIEnv
*env
= (JNIEnv
*) _Jv_MallocUnchecked (sizeof (JNIEnv
));
2318 env
->p
= &_Jv_JNIFunctions
;
2322 = (_Jv_JNI_LocalFrame
*) _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame
)
2324 * sizeof (jobject
)));
2325 env
->locals
= env
->bottom_locals
;
2326 if (env
->locals
== NULL
)
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
)
2349 _Jv_AttachCurrentThreadAsDaemon (name
, group
);
2351 _Jv_AttachCurrentThread (name
, group
);
2353 catch (jthrowable t
)
2358 _Jv_SetCurrentJNIEnv (env
);
2363 // This is the one actually used by JNI.
2365 (JNICALL _Jv_JNI_AttachCurrentThread
) (JavaVM
*vm
, void **penv
, void *args
)
2367 return _Jv_JNI_AttachCurrentThread (vm
, NULL
, penv
, args
, false);
2371 (JNICALL _Jv_JNI_AttachCurrentThreadAsDaemon
) (JavaVM
*vm
, void **penv
,
2374 return _Jv_JNI_AttachCurrentThread (vm
, NULL
, penv
, args
, true);
2378 (JNICALL _Jv_JNI_DestroyJavaVM
) (JavaVM
*vm
)
2380 JvAssert (the_vm
&& vm
== the_vm
);
2383 if (_Jv_ThreadCurrent () != NULL
)
2389 main_name
= JvNewStringLatin1 ("main");
2391 catch (jthrowable t
)
2396 jint r
= _Jv_JNI_AttachCurrentThread (vm
, main_name
,
2397 reinterpret_cast<void **> (&env
),
2403 env
= _Jv_GetCurrentJNIEnv ();
2407 // Docs say that this always returns an error code.
2412 (JNICALL _Jv_JNI_DetachCurrentThread
) (JavaVM
*)
2414 jint code
= _Jv_DetachCurrentThread ();
2415 return code
? JNI_EDETACHED
: 0;
2419 (JNICALL _Jv_JNI_GetEnv
) (JavaVM
*, void **penv
, jint version
)
2421 if (_Jv_ThreadCurrent () == NULL
)
2424 return JNI_EDETACHED
;
2428 // Handle JVMPI requests.
2429 if (version
== JVMPI_VERSION_1
)
2431 *penv
= (void *) &_Jv_JVMPI_Interface
;
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
)
2441 return JNI_EVERSION
;
2444 *penv
= (void *) _Jv_GetCurrentJNIEnv ();
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
;
2460 ia
->ignoreUnrecognized
= true;
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
));
2476 nvm
->functions
= &_Jv_JNI_InvokeFunctions
;
2478 // Parse the arguments.
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.
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.
2504 else if (! strncmp (ia
->options
[i
].optionString
, "-D", 2))
2509 else if (ia
->ignoreUnrecognized
)
2511 if (ia
->options
[i
].optionString
[0] == '_'
2512 || ! strncmp (ia
->options
[i
].optionString
, "-X", 2))
2520 jint r
=_Jv_JNI_AttachCurrentThread (nvm
, penv
, NULL
);
2531 JNI_GetCreatedJavaVMs (JavaVM
**vm_buffer
, jsize buf_len
, jsize
*n_vms
)
2536 // We only support a single VM.
2539 vm_buffer
[0] = the_vm
;
2550 // FIXME: synchronize
2553 JavaVM
*nvm
= (JavaVM
*) _Jv_MallocUnchecked (sizeof (JavaVM
));
2555 nvm
->functions
= &_Jv_JNI_InvokeFunctions
;
2559 // If this is a Java thread, we want to make sure it has an
2560 // associated JNIEnv.
2561 if (_Jv_ThreadCurrent () != NULL
)
2564 _Jv_JNI_AttachCurrentThread (the_vm
, &ignore
, NULL
);
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
=
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
)>,
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
=
2870 _Jv_JNI_DestroyJavaVM
,
2871 _Jv_JNI_AttachCurrentThread
,
2872 _Jv_JNI_DetachCurrentThread
,
2874 _Jv_JNI_AttachCurrentThreadAsDaemon