1 // jni.cc - JNI implementation, including the jump table.
3 /* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
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/Buffer.h>
45 #include <java/nio/DirectByteBufferImpl.h>
46 #include <java/nio/DirectByteBufferImpl$ReadWrite.h>
47 #include <java/util/IdentityHashMap.h>
48 #include <gnu/gcj/RawData.h>
49 #include <java/lang/ClassNotFoundException.h>
51 #include <gcj/method.h>
52 #include <gcj/field.h>
54 #include <java-interp.h>
55 #include <java-threads.h>
59 // This enum is used to select different template instantiations in
60 // the invocation code.
69 // Forward declarations.
70 extern struct JNINativeInterface _Jv_JNIFunctions
;
71 extern struct JNIInvokeInterface _Jv_JNI_InvokeFunctions
;
73 // Number of slots in the default frame. The VM must allow at least
77 // Mark value indicating this is an overflow frame.
79 // Mark value indicating this is a user frame.
81 // Mark value indicating this is a system frame.
84 // This structure is used to keep track of local references.
85 struct _Jv_JNI_LocalFrame
87 // This is true if this frame object represents a pushed frame (eg
88 // from PushLocalFrame).
91 // Flag to indicate some locals were allocated.
94 // Number of elements in frame.
97 // Next frame in chain.
98 _Jv_JNI_LocalFrame
*next
;
100 // The elements. These are allocated using the C "struct hack".
104 // This holds a reference count for all local references.
105 static java::util::IdentityHashMap
*local_ref_table
;
106 // This holds a reference count for all global references.
107 static java::util::IdentityHashMap
*global_ref_table
;
113 // The only JVMPI interface description.
114 static JVMPI_Interface _Jv_JVMPI_Interface
;
117 jvmpiEnableEvent (jint event_type
, void *)
121 case JVMPI_EVENT_OBJECT_ALLOC
:
122 _Jv_JVMPI_Notify_OBJECT_ALLOC
= _Jv_JVMPI_Interface
.NotifyEvent
;
125 case JVMPI_EVENT_THREAD_START
:
126 _Jv_JVMPI_Notify_THREAD_START
= _Jv_JVMPI_Interface
.NotifyEvent
;
129 case JVMPI_EVENT_THREAD_END
:
130 _Jv_JVMPI_Notify_THREAD_END
= _Jv_JVMPI_Interface
.NotifyEvent
;
134 return JVMPI_NOT_AVAILABLE
;
137 return JVMPI_SUCCESS
;
141 jvmpiDisableEvent (jint event_type
, void *)
145 case JVMPI_EVENT_OBJECT_ALLOC
:
146 _Jv_JVMPI_Notify_OBJECT_ALLOC
= NULL
;
150 return JVMPI_NOT_AVAILABLE
;
153 return JVMPI_SUCCESS
;
162 local_ref_table
= new java::util::IdentityHashMap
;
163 global_ref_table
= new java::util::IdentityHashMap
;
166 _Jv_JVMPI_Interface
.version
= 1;
167 _Jv_JVMPI_Interface
.EnableEvent
= &jvmpiEnableEvent
;
168 _Jv_JVMPI_Interface
.DisableEvent
= &jvmpiDisableEvent
;
169 _Jv_JVMPI_Interface
.EnableGC
= &_Jv_EnableGC
;
170 _Jv_JVMPI_Interface
.DisableGC
= &_Jv_DisableGC
;
171 _Jv_JVMPI_Interface
.RunGC
= &_Jv_RunGC
;
175 // Tell the GC that a certain pointer is live.
177 mark_for_gc (jobject obj
, java::util::IdentityHashMap
*ref_table
)
179 JvSynchronize
sync (ref_table
);
181 using namespace java::lang
;
182 Integer
*refcount
= (Integer
*) ref_table
->get (obj
);
183 jint val
= (refcount
== NULL
) ? 0 : refcount
->intValue ();
184 // FIXME: what about out of memory error?
185 ref_table
->put (obj
, new Integer (val
+ 1));
190 unmark_for_gc (jobject obj
, java::util::IdentityHashMap
*ref_table
)
192 JvSynchronize
sync (ref_table
);
194 using namespace java::lang
;
195 Integer
*refcount
= (Integer
*) ref_table
->get (obj
);
197 jint val
= refcount
->intValue () - 1;
200 ref_table
->remove (obj
);
202 // FIXME: what about out of memory error?
203 ref_table
->put (obj
, new Integer (val
));
206 // "Unwrap" some random non-reference type. This exists to simplify
207 // other template functions.
215 // Unwrap a weak reference, if required.
220 using namespace gnu::gcj::runtime
;
221 // We can compare the class directly because JNIWeakRef is `final'.
222 // Doing it this way is much faster.
223 if (obj
== NULL
|| obj
->getClass () != &JNIWeakRef::class$
)
225 JNIWeakRef
*wr
= reinterpret_cast<JNIWeakRef
*> (obj
);
226 return reinterpret_cast<T
*> (wr
->get ());
230 _Jv_UnwrapJNIweakReference (jobject obj
)
237 static jobject JNICALL
238 _Jv_JNI_NewGlobalRef (JNIEnv
*, jobject obj
)
240 // This seems weird but I think it is correct.
242 mark_for_gc (obj
, global_ref_table
);
247 _Jv_JNI_DeleteGlobalRef (JNIEnv
*, jobject obj
)
249 // This seems weird but I think it is correct.
252 // NULL is ok here -- the JNI specification doesn't say so, but this
257 unmark_for_gc (obj
, global_ref_table
);
261 _Jv_JNI_DeleteLocalRef (JNIEnv
*env
, jobject obj
)
263 _Jv_JNI_LocalFrame
*frame
;
265 // This seems weird but I think it is correct.
268 // NULL is ok here -- the JNI specification doesn't say so, but this
273 for (frame
= env
->locals
; frame
!= NULL
; frame
= frame
->next
)
275 for (int i
= 0; i
< frame
->size
; ++i
)
277 if (frame
->vec
[i
] == obj
)
279 frame
->vec
[i
] = NULL
;
280 unmark_for_gc (obj
, local_ref_table
);
285 // Don't go past a marked frame.
286 JvAssert (frame
->marker
== MARK_NONE
);
293 _Jv_JNI_EnsureLocalCapacity (JNIEnv
*env
, jint size
)
295 // It is easier to just always allocate a new frame of the requested
296 // size. This isn't the most efficient thing, but for now we don't
297 // care. Note that _Jv_JNI_PushLocalFrame relies on this right now.
299 _Jv_JNI_LocalFrame
*frame
;
302 frame
= (_Jv_JNI_LocalFrame
*) _Jv_Malloc (sizeof (_Jv_JNI_LocalFrame
)
303 + size
* sizeof (jobject
));
311 frame
->marker
= MARK_NONE
;
313 frame
->allocated_p
= 0;
314 memset (&frame
->vec
[0], 0, size
* sizeof (jobject
));
315 frame
->next
= env
->locals
;
322 _Jv_JNI_PushLocalFrame (JNIEnv
*env
, jint size
)
324 jint r
= _Jv_JNI_EnsureLocalCapacity (env
, size
);
328 // The new frame is on top.
329 env
->locals
->marker
= MARK_USER
;
334 static jobject JNICALL
335 _Jv_JNI_NewLocalRef (JNIEnv
*env
, jobject obj
)
337 // This seems weird but I think it is correct.
340 // Try to find an open slot somewhere in the topmost frame.
341 _Jv_JNI_LocalFrame
*frame
= env
->locals
;
342 bool done
= false, set
= false;
343 for (; frame
!= NULL
&& ! done
; frame
= frame
->next
)
345 for (int i
= 0; i
< frame
->size
; ++i
)
347 if (frame
->vec
[i
] == NULL
)
352 frame
->allocated_p
= 1;
357 // If we found a slot, or if the frame we just searched is the
358 // mark frame, then we are done.
359 if (done
|| frame
== NULL
|| frame
->marker
!= MARK_NONE
)
365 // No slots, so we allocate a new frame. According to the spec
366 // we could just die here. FIXME: return value.
367 _Jv_JNI_EnsureLocalCapacity (env
, 16);
368 // We know the first element of the new frame will be ok.
369 env
->locals
->vec
[0] = obj
;
370 env
->locals
->allocated_p
= 1;
373 mark_for_gc (obj
, local_ref_table
);
377 static jobject JNICALL
378 _Jv_JNI_PopLocalFrame (JNIEnv
*env
, jobject result
, int stop
)
380 _Jv_JNI_LocalFrame
*rf
= env
->locals
;
383 while (rf
!= NULL
&& ! done
)
385 for (int i
= 0; i
< rf
->size
; ++i
)
386 if (rf
->vec
[i
] != NULL
)
387 unmark_for_gc (rf
->vec
[i
], local_ref_table
);
389 // If the frame we just freed is the marker frame, we are done.
390 done
= (rf
->marker
== stop
);
392 _Jv_JNI_LocalFrame
*n
= rf
->next
;
393 // When N==NULL, we've reached the reusable bottom_locals, and we must
394 // not free it. However, we must be sure to clear all its elements.
398 memset (&rf
->vec
[0], 0, rf
->size
* sizeof (jobject
));
408 // Update the local frame information.
411 return result
== NULL
? NULL
: _Jv_JNI_NewLocalRef (env
, result
);
414 static jobject JNICALL
415 _Jv_JNI_PopLocalFrame (JNIEnv
*env
, jobject result
)
417 return _Jv_JNI_PopLocalFrame (env
, result
, MARK_USER
);
420 // Make sure an array's type is compatible with the type of the
424 _Jv_JNI_check_types (JNIEnv
*env
, JArray
<T
> *array
, jclass K
)
426 jclass klass
= array
->getClass()->getComponentType();
427 if (__builtin_expect (klass
!= K
, false))
429 env
->ex
= new java::lang::IllegalAccessError ();
436 // Pop a `system' frame from the stack. This is `extern "C"' as it is
437 // used by the compiler.
439 _Jv_JNI_PopSystemFrame (JNIEnv
*env
)
441 // Only enter slow path when we're not at the bottom, or there have been
442 // allocations. Usually this is false and we can just null out the locals
445 if (__builtin_expect ((env
->locals
->next
446 || env
->locals
->allocated_p
), false))
447 _Jv_JNI_PopLocalFrame (env
, NULL
, MARK_SYSTEM
);
451 if (__builtin_expect (env
->ex
!= NULL
, false))
453 jthrowable t
= env
->ex
;
459 template<typename T
> T
extract_from_jvalue(jvalue
const & t
);
460 template<> jboolean
extract_from_jvalue(jvalue
const & jv
) { return jv
.z
; }
461 template<> jbyte
extract_from_jvalue(jvalue
const & jv
) { return jv
.b
; }
462 template<> jchar
extract_from_jvalue(jvalue
const & jv
) { return jv
.c
; }
463 template<> jshort
extract_from_jvalue(jvalue
const & jv
) { return jv
.s
; }
464 template<> jint
extract_from_jvalue(jvalue
const & jv
) { return jv
.i
; }
465 template<> jlong
extract_from_jvalue(jvalue
const & jv
) { return jv
.j
; }
466 template<> jfloat
extract_from_jvalue(jvalue
const & jv
) { return jv
.f
; }
467 template<> jdouble
extract_from_jvalue(jvalue
const & jv
) { return jv
.d
; }
468 template<> jobject
extract_from_jvalue(jvalue
const & jv
) { return jv
.l
; }
471 // This function is used from other template functions. It wraps the
472 // return value appropriately; we specialize it so that object returns
473 // are turned into local references.
476 wrap_value (JNIEnv
*, T value
)
481 // This specialization is used for jobject, jclass, jstring, jarray,
483 template<typename R
, typename T
>
485 wrap_value (JNIEnv
*env
, T
*value
)
487 return (value
== NULL
489 : (T
*) _Jv_JNI_NewLocalRef (env
, (jobject
) value
));
495 _Jv_JNI_GetVersion (JNIEnv
*)
497 return JNI_VERSION_1_4
;
500 static jclass JNICALL
501 _Jv_JNI_DefineClass (JNIEnv
*env
, const char *name
, jobject loader
,
502 const jbyte
*buf
, jsize bufLen
)
506 loader
= unwrap (loader
);
508 jstring sname
= JvNewStringUTF (name
);
509 jbyteArray bytes
= JvNewByteArray (bufLen
);
511 jbyte
*elts
= elements (bytes
);
512 memcpy (elts
, buf
, bufLen
* sizeof (jbyte
));
514 java::lang::ClassLoader
*l
515 = reinterpret_cast<java::lang::ClassLoader
*> (loader
);
517 jclass result
= l
->defineClass (sname
, bytes
, 0, bufLen
);
518 return (jclass
) wrap_value (env
, result
);
527 static jclass JNICALL
528 _Jv_JNI_FindClass (JNIEnv
*env
, const char *name
)
530 // FIXME: assume that NAME isn't too long.
531 int len
= strlen (name
);
533 for (int i
= 0; i
<= len
; ++i
)
534 s
[i
] = (name
[i
] == '/') ? '.' : name
[i
];
539 // This might throw an out of memory exception.
540 jstring n
= JvNewStringUTF (s
);
542 java::lang::ClassLoader
*loader
= NULL
;
543 if (env
->klass
!= NULL
)
544 loader
= env
->klass
->getClassLoaderInternal ();
548 // FIXME: should use getBaseClassLoader, but we don't have that
550 loader
= java::lang::ClassLoader::getSystemClassLoader ();
553 r
= loader
->loadClass (n
);
560 return (jclass
) wrap_value (env
, r
);
563 static jclass JNICALL
564 _Jv_JNI_GetSuperclass (JNIEnv
*env
, jclass clazz
)
566 return (jclass
) wrap_value (env
, unwrap (clazz
)->getSuperclass ());
569 static jboolean JNICALL
570 _Jv_JNI_IsAssignableFrom (JNIEnv
*, jclass clazz1
, jclass clazz2
)
572 return unwrap (clazz2
)->isAssignableFrom (unwrap (clazz1
));
576 _Jv_JNI_Throw (JNIEnv
*env
, jthrowable obj
)
578 // We check in case the user did some funky cast.
580 JvAssert (obj
!= NULL
&& java::lang::Throwable::class$
.isInstance (obj
));
586 _Jv_JNI_ThrowNew (JNIEnv
*env
, jclass clazz
, const char *message
)
588 using namespace java::lang::reflect
;
590 clazz
= unwrap (clazz
);
591 JvAssert (java::lang::Throwable::class$
.isAssignableFrom (clazz
));
596 JArray
<jclass
> *argtypes
597 = (JArray
<jclass
> *) JvNewObjectArray (1, &java::lang::Class::class$
,
600 jclass
*elts
= elements (argtypes
);
601 elts
[0] = &java::lang::String::class$
;
603 Constructor
*cons
= clazz
->getConstructor (argtypes
);
605 jobjectArray values
= JvNewObjectArray (1, &java::lang::String::class$
,
607 jobject
*velts
= elements (values
);
608 velts
[0] = JvNewStringUTF (message
);
610 jobject obj
= cons
->newInstance (values
);
612 env
->ex
= reinterpret_cast<jthrowable
> (obj
);
623 static jthrowable JNICALL
624 _Jv_JNI_ExceptionOccurred (JNIEnv
*env
)
626 return (jthrowable
) wrap_value (env
, env
->ex
);
630 _Jv_JNI_ExceptionDescribe (JNIEnv
*env
)
633 env
->ex
->printStackTrace();
637 _Jv_JNI_ExceptionClear (JNIEnv
*env
)
642 static jboolean JNICALL
643 _Jv_JNI_ExceptionCheck (JNIEnv
*env
)
645 return env
->ex
!= NULL
;
649 _Jv_JNI_FatalError (JNIEnv
*, const char *message
)
656 static jboolean JNICALL
657 _Jv_JNI_IsSameObject (JNIEnv
*, jobject obj1
, jobject obj2
)
659 return unwrap (obj1
) == unwrap (obj2
);
662 static jobject JNICALL
663 _Jv_JNI_AllocObject (JNIEnv
*env
, jclass clazz
)
666 using namespace java::lang::reflect
;
670 clazz
= unwrap (clazz
);
671 JvAssert (clazz
&& ! clazz
->isArray ());
672 if (clazz
->isInterface() || Modifier::isAbstract(clazz
->getModifiers()))
673 env
->ex
= new java::lang::InstantiationException ();
675 obj
= _Jv_AllocObject (clazz
);
682 return wrap_value (env
, obj
);
685 static jclass JNICALL
686 _Jv_JNI_GetObjectClass (JNIEnv
*env
, jobject obj
)
690 return (jclass
) wrap_value (env
, obj
->getClass());
693 static jboolean JNICALL
694 _Jv_JNI_IsInstanceOf (JNIEnv
*, jobject obj
, jclass clazz
)
696 return unwrap (clazz
)->isInstance(unwrap (obj
));
702 // This section concerns method invocation.
705 template<jboolean is_static
>
706 static jmethodID JNICALL
707 _Jv_JNI_GetAnyMethodID (JNIEnv
*env
, jclass clazz
,
708 const char *name
, const char *sig
)
712 clazz
= unwrap (clazz
);
713 _Jv_InitClass (clazz
);
715 _Jv_Utf8Const
*name_u
= _Jv_makeUtf8Const ((char *) name
, -1);
717 // FIXME: assume that SIG isn't too long.
718 int len
= strlen (sig
);
720 for (int i
= 0; i
<= len
; ++i
)
721 s
[i
] = (sig
[i
] == '/') ? '.' : sig
[i
];
722 _Jv_Utf8Const
*sig_u
= _Jv_makeUtf8Const ((char *) s
, -1);
724 JvAssert (! clazz
->isPrimitive());
726 using namespace java::lang::reflect
;
728 while (clazz
!= NULL
)
730 jint count
= JvNumMethods (clazz
);
731 jmethodID meth
= JvGetFirstMethod (clazz
);
733 for (jint i
= 0; i
< count
; ++i
)
735 if (((is_static
&& Modifier::isStatic (meth
->accflags
))
736 || (! is_static
&& ! Modifier::isStatic (meth
->accflags
)))
737 && _Jv_equalUtf8Consts (meth
->name
, name_u
)
738 && _Jv_equalUtf8Consts (meth
->signature
, sig_u
))
741 meth
= meth
->getNextMethod();
744 clazz
= clazz
->getSuperclass ();
747 java::lang::StringBuffer
*name_sig
=
748 new java::lang::StringBuffer (JvNewStringUTF (name
));
749 name_sig
->append ((jchar
) ' ')->append (JvNewStringUTF (s
));
750 env
->ex
= new java::lang::NoSuchMethodError (name_sig
->toString ());
760 // This is a helper function which turns a va_list into an array of
761 // `jvalue's. It needs signature information in order to do its work.
762 // The array of values must already be allocated.
764 array_from_valist (jvalue
*values
, JArray
<jclass
> *arg_types
, va_list vargs
)
766 jclass
*arg_elts
= elements (arg_types
);
767 for (int i
= 0; i
< arg_types
->length
; ++i
)
769 // Here we assume that sizeof(int) >= sizeof(jint), because we
770 // use `int' when decoding the varargs. Likewise for
771 // float, and double. Also we assume that sizeof(jlong) >=
772 // sizeof(int), i.e. that jlong values are not further
774 JvAssert (sizeof (int) >= sizeof (jint
));
775 JvAssert (sizeof (jlong
) >= sizeof (int));
776 JvAssert (sizeof (double) >= sizeof (jfloat
));
777 JvAssert (sizeof (double) >= sizeof (jdouble
));
778 if (arg_elts
[i
] == JvPrimClass (byte
))
779 values
[i
].b
= (jbyte
) va_arg (vargs
, int);
780 else if (arg_elts
[i
] == JvPrimClass (short))
781 values
[i
].s
= (jshort
) va_arg (vargs
, int);
782 else if (arg_elts
[i
] == JvPrimClass (int))
783 values
[i
].i
= (jint
) va_arg (vargs
, int);
784 else if (arg_elts
[i
] == JvPrimClass (long))
785 values
[i
].j
= (jlong
) va_arg (vargs
, jlong
);
786 else if (arg_elts
[i
] == JvPrimClass (float))
787 values
[i
].f
= (jfloat
) va_arg (vargs
, double);
788 else if (arg_elts
[i
] == JvPrimClass (double))
789 values
[i
].d
= (jdouble
) va_arg (vargs
, double);
790 else if (arg_elts
[i
] == JvPrimClass (boolean
))
791 values
[i
].z
= (jboolean
) va_arg (vargs
, int);
792 else if (arg_elts
[i
] == JvPrimClass (char))
793 values
[i
].c
= (jchar
) va_arg (vargs
, int);
797 values
[i
].l
= unwrap (va_arg (vargs
, jobject
));
802 // This can call any sort of method: virtual, "nonvirtual", static, or
804 template<typename T
, invocation_type style
>
806 _Jv_JNI_CallAnyMethodV (JNIEnv
*env
, jobject obj
, jclass klass
,
807 jmethodID id
, va_list vargs
)
810 klass
= unwrap (klass
);
812 jclass decl_class
= klass
? klass
: obj
->getClass ();
813 JvAssert (decl_class
!= NULL
);
816 JArray
<jclass
> *arg_types
;
820 _Jv_GetTypesFromSignature (id
, decl_class
,
821 &arg_types
, &return_type
);
823 jvalue args
[arg_types
->length
];
824 array_from_valist (args
, arg_types
, vargs
);
826 // For constructors we need to pass the Class we are instantiating.
827 if (style
== constructor
)
831 _Jv_CallAnyMethodA (obj
, return_type
, id
,
832 style
== constructor
,
834 arg_types
, args
, &result
);
836 return wrap_value (env
, extract_from_jvalue
<T
>(result
));
843 return wrap_value (env
, (T
) 0);
846 template<typename T
, invocation_type style
>
848 _Jv_JNI_CallAnyMethod (JNIEnv
*env
, jobject obj
, jclass klass
,
849 jmethodID method
, ...)
854 va_start (args
, method
);
855 result
= _Jv_JNI_CallAnyMethodV
<T
, style
> (env
, obj
, klass
, method
, args
);
861 template<typename T
, invocation_type style
>
863 _Jv_JNI_CallAnyMethodA (JNIEnv
*env
, jobject obj
, jclass klass
,
864 jmethodID id
, jvalue
*args
)
867 klass
= unwrap (klass
);
869 jclass decl_class
= klass
? klass
: obj
->getClass ();
870 JvAssert (decl_class
!= NULL
);
873 JArray
<jclass
> *arg_types
;
876 _Jv_GetTypesFromSignature (id
, decl_class
,
877 &arg_types
, &return_type
);
879 // For constructors we need to pass the Class we are instantiating.
880 if (style
== constructor
)
883 // Unwrap arguments as required. Eww.
884 jclass
*type_elts
= elements (arg_types
);
885 jvalue arg_copy
[arg_types
->length
];
886 for (int i
= 0; i
< arg_types
->length
; ++i
)
888 if (type_elts
[i
]->isPrimitive ())
889 arg_copy
[i
] = args
[i
];
891 arg_copy
[i
].l
= unwrap (args
[i
].l
);
895 _Jv_CallAnyMethodA (obj
, return_type
, id
,
896 style
== constructor
,
898 arg_types
, arg_copy
, &result
);
900 return wrap_value (env
, extract_from_jvalue
<T
>(result
));
907 return wrap_value (env
, (T
) 0);
910 template<invocation_type style
>
912 _Jv_JNI_CallAnyVoidMethodV (JNIEnv
*env
, jobject obj
, jclass klass
,
913 jmethodID id
, va_list vargs
)
916 klass
= unwrap (klass
);
918 jclass decl_class
= klass
? klass
: obj
->getClass ();
919 JvAssert (decl_class
!= NULL
);
922 JArray
<jclass
> *arg_types
;
925 _Jv_GetTypesFromSignature (id
, decl_class
,
926 &arg_types
, &return_type
);
928 jvalue args
[arg_types
->length
];
929 array_from_valist (args
, arg_types
, vargs
);
931 // For constructors we need to pass the Class we are instantiating.
932 if (style
== constructor
)
935 _Jv_CallAnyMethodA (obj
, return_type
, id
,
936 style
== constructor
,
938 arg_types
, args
, NULL
);
946 template<invocation_type style
>
948 _Jv_JNI_CallAnyVoidMethod (JNIEnv
*env
, jobject obj
, jclass klass
,
949 jmethodID method
, ...)
953 va_start (args
, method
);
954 _Jv_JNI_CallAnyVoidMethodV
<style
> (env
, obj
, klass
, method
, args
);
958 template<invocation_type style
>
960 _Jv_JNI_CallAnyVoidMethodA (JNIEnv
*env
, jobject obj
, jclass klass
,
961 jmethodID id
, jvalue
*args
)
963 jclass decl_class
= klass
? klass
: obj
->getClass ();
964 JvAssert (decl_class
!= NULL
);
967 JArray
<jclass
> *arg_types
;
970 _Jv_GetTypesFromSignature (id
, decl_class
,
971 &arg_types
, &return_type
);
973 // Unwrap arguments as required. Eww.
974 jclass
*type_elts
= elements (arg_types
);
975 jvalue arg_copy
[arg_types
->length
];
976 for (int i
= 0; i
< arg_types
->length
; ++i
)
978 if (type_elts
[i
]->isPrimitive ())
979 arg_copy
[i
] = args
[i
];
981 arg_copy
[i
].l
= unwrap (args
[i
].l
);
984 _Jv_CallAnyMethodA (obj
, return_type
, id
,
985 style
== constructor
,
987 arg_types
, args
, NULL
);
995 // Functions with this signature are used to implement functions in
996 // the CallMethod family.
999 _Jv_JNI_CallMethodV (JNIEnv
*env
, jobject obj
,
1000 jmethodID id
, va_list args
)
1002 return _Jv_JNI_CallAnyMethodV
<T
, normal
> (env
, obj
, NULL
, id
, args
);
1005 // Functions with this signature are used to implement functions in
1006 // the CallMethod family.
1007 template<typename T
>
1009 _Jv_JNI_CallMethod (JNIEnv
*env
, jobject obj
, jmethodID id
, ...)
1014 va_start (args
, id
);
1015 result
= _Jv_JNI_CallAnyMethodV
<T
, normal
> (env
, obj
, NULL
, id
, args
);
1021 // Functions with this signature are used to implement functions in
1022 // the CallMethod family.
1023 template<typename T
>
1025 _Jv_JNI_CallMethodA (JNIEnv
*env
, jobject obj
,
1026 jmethodID id
, jvalue
*args
)
1028 return _Jv_JNI_CallAnyMethodA
<T
, normal
> (env
, obj
, NULL
, id
, args
);
1032 _Jv_JNI_CallVoidMethodV (JNIEnv
*env
, jobject obj
,
1033 jmethodID id
, va_list args
)
1035 _Jv_JNI_CallAnyVoidMethodV
<normal
> (env
, obj
, NULL
, id
, args
);
1039 _Jv_JNI_CallVoidMethod (JNIEnv
*env
, jobject obj
, jmethodID id
, ...)
1043 va_start (args
, id
);
1044 _Jv_JNI_CallAnyVoidMethodV
<normal
> (env
, obj
, NULL
, id
, args
);
1049 _Jv_JNI_CallVoidMethodA (JNIEnv
*env
, jobject obj
,
1050 jmethodID id
, jvalue
*args
)
1052 _Jv_JNI_CallAnyVoidMethodA
<normal
> (env
, obj
, NULL
, id
, args
);
1055 // Functions with this signature are used to implement functions in
1056 // the CallStaticMethod family.
1057 template<typename T
>
1059 _Jv_JNI_CallStaticMethodV (JNIEnv
*env
, jclass klass
,
1060 jmethodID id
, va_list args
)
1062 JvAssert (((id
->accflags
) & java::lang::reflect::Modifier::STATIC
));
1063 JvAssert (java::lang::Class::class$
.isInstance (unwrap (klass
)));
1065 return _Jv_JNI_CallAnyMethodV
<T
, static_type
> (env
, NULL
, klass
, id
, args
);
1068 // Functions with this signature are used to implement functions in
1069 // the CallStaticMethod family.
1070 template<typename T
>
1072 _Jv_JNI_CallStaticMethod (JNIEnv
*env
, jclass klass
,
1078 JvAssert (((id
->accflags
) & java::lang::reflect::Modifier::STATIC
));
1079 JvAssert (java::lang::Class::class$
.isInstance (unwrap (klass
)));
1081 va_start (args
, id
);
1082 result
= _Jv_JNI_CallAnyMethodV
<T
, static_type
> (env
, NULL
, klass
,
1089 // Functions with this signature are used to implement functions in
1090 // the CallStaticMethod family.
1091 template<typename T
>
1093 _Jv_JNI_CallStaticMethodA (JNIEnv
*env
, jclass klass
, jmethodID id
,
1096 JvAssert (((id
->accflags
) & java::lang::reflect::Modifier::STATIC
));
1097 JvAssert (java::lang::Class::class$
.isInstance (unwrap (klass
)));
1099 return _Jv_JNI_CallAnyMethodA
<T
, static_type
> (env
, NULL
, klass
, id
, args
);
1103 _Jv_JNI_CallStaticVoidMethodV (JNIEnv
*env
, jclass klass
,
1104 jmethodID id
, va_list args
)
1106 _Jv_JNI_CallAnyVoidMethodV
<static_type
> (env
, NULL
, klass
, id
, args
);
1110 _Jv_JNI_CallStaticVoidMethod (JNIEnv
*env
, jclass klass
,
1115 va_start (args
, id
);
1116 _Jv_JNI_CallAnyVoidMethodV
<static_type
> (env
, NULL
, klass
, id
, args
);
1121 _Jv_JNI_CallStaticVoidMethodA (JNIEnv
*env
, jclass klass
,
1122 jmethodID id
, jvalue
*args
)
1124 _Jv_JNI_CallAnyVoidMethodA
<static_type
> (env
, NULL
, klass
, id
, args
);
1127 static jobject JNICALL
1128 _Jv_JNI_NewObjectV (JNIEnv
*env
, jclass klass
,
1129 jmethodID id
, va_list args
)
1131 JvAssert (klass
&& ! klass
->isArray ());
1132 JvAssert (! strcmp (id
->name
->chars(), "<init>")
1133 && id
->signature
->len() > 2
1134 && id
->signature
->chars()[0] == '('
1135 && ! strcmp (&id
->signature
->chars()[id
->signature
->len() - 2],
1138 return _Jv_JNI_CallAnyMethodV
<jobject
, constructor
> (env
, NULL
, klass
,
1142 static jobject JNICALL
1143 _Jv_JNI_NewObject (JNIEnv
*env
, jclass klass
, jmethodID id
, ...)
1145 JvAssert (klass
&& ! klass
->isArray ());
1146 JvAssert (! strcmp (id
->name
->chars(), "<init>")
1147 && id
->signature
->len() > 2
1148 && id
->signature
->chars()[0] == '('
1149 && ! strcmp (&id
->signature
->chars()[id
->signature
->len() - 2],
1155 va_start (args
, id
);
1156 result
= _Jv_JNI_CallAnyMethodV
<jobject
, constructor
> (env
, NULL
, klass
,
1163 static jobject JNICALL
1164 _Jv_JNI_NewObjectA (JNIEnv
*env
, jclass klass
, jmethodID id
,
1167 JvAssert (klass
&& ! klass
->isArray ());
1168 JvAssert (! strcmp (id
->name
->chars(), "<init>")
1169 && id
->signature
->len() > 2
1170 && id
->signature
->chars()[0] == '('
1171 && ! strcmp (&id
->signature
->chars()[id
->signature
->len() - 2],
1174 return _Jv_JNI_CallAnyMethodA
<jobject
, constructor
> (env
, NULL
, klass
,
1180 template<typename T
>
1182 _Jv_JNI_GetField (JNIEnv
*env
, jobject obj
, jfieldID field
)
1186 T
*ptr
= (T
*) ((char *) obj
+ field
->getOffset ());
1187 return wrap_value (env
, *ptr
);
1190 template<typename T
>
1192 _Jv_JNI_SetField (JNIEnv
*, jobject obj
, jfieldID field
, T value
)
1195 value
= unwrap (value
);
1198 T
*ptr
= (T
*) ((char *) obj
+ field
->getOffset ());
1202 template<jboolean is_static
>
1203 static jfieldID JNICALL
1204 _Jv_JNI_GetAnyFieldID (JNIEnv
*env
, jclass clazz
,
1205 const char *name
, const char *sig
)
1209 clazz
= unwrap (clazz
);
1211 _Jv_InitClass (clazz
);
1213 _Jv_Utf8Const
*a_name
= _Jv_makeUtf8Const ((char *) name
, -1);
1215 // FIXME: assume that SIG isn't too long.
1216 int len
= strlen (sig
);
1218 for (int i
= 0; i
<= len
; ++i
)
1219 s
[i
] = (sig
[i
] == '/') ? '.' : sig
[i
];
1220 java::lang::ClassLoader
*loader
= clazz
->getClassLoaderInternal ();
1221 jclass field_class
= _Jv_FindClassFromSignature ((char *) s
, loader
);
1223 throw new java::lang::ClassNotFoundException(JvNewStringUTF(s
));
1225 while (clazz
!= NULL
)
1227 // We acquire the class lock so that fields aren't resolved
1228 // while we are running.
1229 JvSynchronize
sync (clazz
);
1231 jint count
= (is_static
1232 ? JvNumStaticFields (clazz
)
1233 : JvNumInstanceFields (clazz
));
1234 jfieldID field
= (is_static
1235 ? JvGetFirstStaticField (clazz
)
1236 : JvGetFirstInstanceField (clazz
));
1237 for (jint i
= 0; i
< count
; ++i
)
1239 _Jv_Utf8Const
*f_name
= field
->getNameUtf8Const(clazz
);
1241 // The field might be resolved or it might not be. It
1242 // is much simpler to always resolve it.
1243 _Jv_Linker::resolve_field (field
, loader
);
1244 if (_Jv_equalUtf8Consts (f_name
, a_name
)
1245 && field
->getClass() == field_class
)
1248 field
= field
->getNextField ();
1251 clazz
= clazz
->getSuperclass ();
1254 env
->ex
= new java::lang::NoSuchFieldError ();
1256 catch (jthrowable t
)
1263 template<typename T
>
1265 _Jv_JNI_GetStaticField (JNIEnv
*env
, jclass
, jfieldID field
)
1267 T
*ptr
= (T
*) field
->u
.addr
;
1268 return wrap_value (env
, *ptr
);
1271 template<typename T
>
1273 _Jv_JNI_SetStaticField (JNIEnv
*, jclass
, jfieldID field
, T value
)
1275 value
= unwrap (value
);
1276 T
*ptr
= (T
*) field
->u
.addr
;
1280 static jstring JNICALL
1281 _Jv_JNI_NewString (JNIEnv
*env
, const jchar
*unichars
, jsize len
)
1285 jstring r
= _Jv_NewString (unichars
, len
);
1286 return (jstring
) wrap_value (env
, r
);
1288 catch (jthrowable t
)
1295 static jsize JNICALL
1296 _Jv_JNI_GetStringLength (JNIEnv
*, jstring string
)
1298 return unwrap (string
)->length();
1301 static const jchar
* JNICALL
1302 _Jv_JNI_GetStringChars (JNIEnv
*, jstring string
, jboolean
*isCopy
)
1304 string
= unwrap (string
);
1305 jchar
*result
= _Jv_GetStringChars (string
);
1306 mark_for_gc (string
, global_ref_table
);
1309 return (const jchar
*) result
;
1313 _Jv_JNI_ReleaseStringChars (JNIEnv
*, jstring string
, const jchar
*)
1315 unmark_for_gc (unwrap (string
), global_ref_table
);
1318 static jstring JNICALL
1319 _Jv_JNI_NewStringUTF (JNIEnv
*env
, const char *bytes
)
1323 jstring result
= JvNewStringUTF (bytes
);
1324 return (jstring
) wrap_value (env
, result
);
1326 catch (jthrowable t
)
1333 static jsize JNICALL
1334 _Jv_JNI_GetStringUTFLength (JNIEnv
*, jstring string
)
1336 return JvGetStringUTFLength (unwrap (string
));
1339 static const char * JNICALL
1340 _Jv_JNI_GetStringUTFChars (JNIEnv
*env
, jstring string
,
1345 string
= unwrap (string
);
1348 jsize len
= JvGetStringUTFLength (string
);
1349 char *r
= (char *) _Jv_Malloc (len
+ 1);
1350 JvGetStringUTFRegion (string
, 0, string
->length(), r
);
1356 return (const char *) r
;
1358 catch (jthrowable t
)
1366 _Jv_JNI_ReleaseStringUTFChars (JNIEnv
*, jstring
, const char *utf
)
1368 _Jv_Free ((void *) utf
);
1372 _Jv_JNI_GetStringRegion (JNIEnv
*env
, jstring string
, jsize start
,
1373 jsize len
, jchar
*buf
)
1375 string
= unwrap (string
);
1376 jchar
*result
= _Jv_GetStringChars (string
);
1377 if (start
< 0 || start
> string
->length ()
1378 || len
< 0 || start
+ len
> string
->length ())
1382 env
->ex
= new java::lang::StringIndexOutOfBoundsException ();
1384 catch (jthrowable t
)
1390 memcpy (buf
, &result
[start
], len
* sizeof (jchar
));
1394 _Jv_JNI_GetStringUTFRegion (JNIEnv
*env
, jstring str
, jsize start
,
1395 jsize len
, char *buf
)
1399 if (start
< 0 || start
> str
->length ()
1400 || len
< 0 || start
+ len
> str
->length ())
1404 env
->ex
= new java::lang::StringIndexOutOfBoundsException ();
1406 catch (jthrowable t
)
1412 _Jv_GetStringUTFRegion (str
, start
, len
, buf
);
1415 static const jchar
* JNICALL
1416 _Jv_JNI_GetStringCritical (JNIEnv
*, jstring str
, jboolean
*isCopy
)
1418 jchar
*result
= _Jv_GetStringChars (unwrap (str
));
1425 _Jv_JNI_ReleaseStringCritical (JNIEnv
*, jstring
, const jchar
*)
1430 static jsize JNICALL
1431 _Jv_JNI_GetArrayLength (JNIEnv
*, jarray array
)
1433 return unwrap (array
)->length
;
1436 static jobjectArray JNICALL
1437 _Jv_JNI_NewObjectArray (JNIEnv
*env
, jsize length
,
1438 jclass elementClass
, jobject init
)
1442 elementClass
= unwrap (elementClass
);
1443 init
= unwrap (init
);
1445 _Jv_CheckCast (elementClass
, init
);
1446 jarray result
= JvNewObjectArray (length
, elementClass
, init
);
1447 return (jobjectArray
) wrap_value (env
, result
);
1449 catch (jthrowable t
)
1456 static jobject JNICALL
1457 _Jv_JNI_GetObjectArrayElement (JNIEnv
*env
, jobjectArray array
,
1460 if ((unsigned) index
>= (unsigned) array
->length
)
1461 _Jv_ThrowBadArrayIndex (index
);
1462 jobject
*elts
= elements (unwrap (array
));
1463 return wrap_value (env
, elts
[index
]);
1467 _Jv_JNI_SetObjectArrayElement (JNIEnv
*env
, jobjectArray array
,
1468 jsize index
, jobject value
)
1472 array
= unwrap (array
);
1473 value
= unwrap (value
);
1475 _Jv_CheckArrayStore (array
, value
);
1476 if ((unsigned) index
>= (unsigned) array
->length
)
1477 _Jv_ThrowBadArrayIndex (index
);
1478 jobject
*elts
= elements (array
);
1479 elts
[index
] = value
;
1481 catch (jthrowable t
)
1487 template<typename T
, jclass K
>
1488 static JArray
<T
> * JNICALL
1489 _Jv_JNI_NewPrimitiveArray (JNIEnv
*env
, jsize length
)
1493 return (JArray
<T
> *) wrap_value (env
, _Jv_NewPrimArray (K
, length
));
1495 catch (jthrowable t
)
1502 template<typename T
, jclass K
>
1504 _Jv_JNI_GetPrimitiveArrayElements (JNIEnv
*env
, JArray
<T
> *array
,
1507 array
= unwrap (array
);
1508 if (! _Jv_JNI_check_types (env
, array
, K
))
1510 T
*elts
= elements (array
);
1513 // We elect never to copy.
1516 mark_for_gc (array
, global_ref_table
);
1520 template<typename T
, jclass K
>
1522 _Jv_JNI_ReleasePrimitiveArrayElements (JNIEnv
*env
, JArray
<T
> *array
,
1523 T
*, jint
/* mode */)
1525 array
= unwrap (array
);
1526 _Jv_JNI_check_types (env
, array
, K
);
1527 // Note that we ignore MODE. We can do this because we never copy
1528 // the array elements. My reading of the JNI documentation is that
1529 // this is an option for the implementor.
1530 unmark_for_gc (array
, global_ref_table
);
1533 template<typename T
, jclass K
>
1535 _Jv_JNI_GetPrimitiveArrayRegion (JNIEnv
*env
, JArray
<T
> *array
,
1536 jsize start
, jsize len
,
1539 array
= unwrap (array
);
1540 if (! _Jv_JNI_check_types (env
, array
, K
))
1543 // The cast to unsigned lets us save a comparison.
1544 if (start
< 0 || len
< 0
1545 || (unsigned long) (start
+ len
) > (unsigned long) array
->length
)
1550 env
->ex
= new java::lang::ArrayIndexOutOfBoundsException ();
1552 catch (jthrowable t
)
1554 // Could have thown out of memory error.
1560 T
*elts
= elements (array
) + start
;
1561 memcpy (buf
, elts
, len
* sizeof (T
));
1565 template<typename T
, jclass K
>
1567 _Jv_JNI_SetPrimitiveArrayRegion (JNIEnv
*env
, JArray
<T
> *array
,
1568 jsize start
, jsize len
, T
*buf
)
1570 array
= unwrap (array
);
1571 if (! _Jv_JNI_check_types (env
, array
, K
))
1574 // The cast to unsigned lets us save a comparison.
1575 if (start
< 0 || len
< 0
1576 || (unsigned long) (start
+ len
) > (unsigned long) array
->length
)
1581 env
->ex
= new java::lang::ArrayIndexOutOfBoundsException ();
1583 catch (jthrowable t
)
1590 T
*elts
= elements (array
) + start
;
1591 memcpy (elts
, buf
, len
* sizeof (T
));
1595 static void * JNICALL
1596 _Jv_JNI_GetPrimitiveArrayCritical (JNIEnv
*, jarray array
,
1599 array
= unwrap (array
);
1600 // FIXME: does this work?
1601 jclass klass
= array
->getClass()->getComponentType();
1602 JvAssert (klass
->isPrimitive ());
1603 char *r
= _Jv_GetArrayElementFromElementType (array
, klass
);
1610 _Jv_JNI_ReleasePrimitiveArrayCritical (JNIEnv
*, jarray
, void *, jint
)
1616 _Jv_JNI_MonitorEnter (JNIEnv
*env
, jobject obj
)
1620 _Jv_MonitorEnter (unwrap (obj
));
1623 catch (jthrowable t
)
1631 _Jv_JNI_MonitorExit (JNIEnv
*env
, jobject obj
)
1635 _Jv_MonitorExit (unwrap (obj
));
1638 catch (jthrowable t
)
1647 _Jv_JNI_ToReflectedField (JNIEnv
*env
, jclass cls
, jfieldID fieldID
,
1653 java::lang::reflect::Field
*field
= new java::lang::reflect::Field();
1654 field
->declaringClass
= cls
;
1655 field
->offset
= (char*) fieldID
- (char *) cls
->fields
;
1656 field
->name
= _Jv_NewStringUtf8Const (fieldID
->getNameUtf8Const (cls
));
1657 return wrap_value (env
, field
);
1659 catch (jthrowable t
)
1667 static jfieldID JNICALL
1668 _Jv_JNI_FromReflectedField (JNIEnv
*, jobject f
)
1670 using namespace java::lang::reflect
;
1673 Field
*field
= reinterpret_cast<Field
*> (f
);
1674 return _Jv_FromReflectedField (field
);
1678 _Jv_JNI_ToReflectedMethod (JNIEnv
*env
, jclass klass
, jmethodID id
,
1681 using namespace java::lang::reflect
;
1683 jobject result
= NULL
;
1684 klass
= unwrap (klass
);
1688 if (_Jv_equalUtf8Consts (id
->name
, init_name
))
1691 Constructor
*cons
= new Constructor ();
1692 cons
->offset
= (char *) id
- (char *) &klass
->methods
;
1693 cons
->declaringClass
= klass
;
1698 Method
*meth
= new Method ();
1699 meth
->offset
= (char *) id
- (char *) &klass
->methods
;
1700 meth
->declaringClass
= klass
;
1704 catch (jthrowable t
)
1709 return wrap_value (env
, result
);
1712 static jmethodID JNICALL
1713 _Jv_JNI_FromReflectedMethod (JNIEnv
*, jobject method
)
1715 using namespace java::lang::reflect
;
1716 method
= unwrap (method
);
1717 if (Method::class$
.isInstance (method
))
1718 return _Jv_FromReflectedMethod (reinterpret_cast<Method
*> (method
));
1720 _Jv_FromReflectedConstructor (reinterpret_cast<Constructor
*> (method
));
1725 _Jv_JNI_NewWeakGlobalRef (JNIEnv
*env
, jobject obj
)
1727 using namespace gnu::gcj::runtime
;
1728 JNIWeakRef
*ref
= NULL
;
1732 // This seems weird but I think it is correct.
1734 ref
= new JNIWeakRef (obj
);
1735 mark_for_gc (ref
, global_ref_table
);
1737 catch (jthrowable t
)
1742 return reinterpret_cast<jweak
> (ref
);
1746 _Jv_JNI_DeleteWeakGlobalRef (JNIEnv
*, jweak obj
)
1748 using namespace gnu::gcj::runtime
;
1749 JNIWeakRef
*ref
= reinterpret_cast<JNIWeakRef
*> (obj
);
1750 unmark_for_gc (ref
, global_ref_table
);
1756 // Direct byte buffers.
1758 static jobject JNICALL
1759 _Jv_JNI_NewDirectByteBuffer (JNIEnv
*, void *address
, jlong length
)
1761 using namespace gnu::gcj
;
1762 using namespace java::nio
;
1763 return new DirectByteBufferImpl$ReadWrite
1764 (reinterpret_cast<RawData
*> (address
), length
);
1767 static void * JNICALL
1768 _Jv_JNI_GetDirectBufferAddress (JNIEnv
*, jobject buffer
)
1770 using namespace java::nio
;
1771 if (! _Jv_IsInstanceOf (buffer
, &Buffer::class$
))
1773 Buffer
*tmp
= static_cast<Buffer
*> (buffer
);
1774 return reinterpret_cast<void *> (tmp
->address
);
1777 static jlong JNICALL
1778 _Jv_JNI_GetDirectBufferCapacity (JNIEnv
*, jobject buffer
)
1780 using namespace java::nio
;
1781 if (! _Jv_IsInstanceOf (buffer
, &Buffer::class$
))
1783 Buffer
*tmp
= static_cast<Buffer
*> (buffer
);
1784 if (tmp
->address
== NULL
)
1786 return tmp
->capacity();
1791 // Hash table of native methods.
1792 static JNINativeMethod
*nathash
;
1793 // Number of slots used.
1794 static int nathash_count
= 0;
1795 // Number of slots available. Must be power of 2.
1796 static int nathash_size
= 0;
1798 #define DELETED_ENTRY ((char *) (~0))
1800 // Compute a hash value for a native method descriptor.
1802 hash (const JNINativeMethod
*method
)
1809 hash
= (31 * hash
) + *ptr
++;
1811 ptr
= method
->signature
;
1813 hash
= (31 * hash
) + *ptr
++;
1818 // Find the slot where a native method goes.
1819 static JNINativeMethod
*
1820 nathash_find_slot (const JNINativeMethod
*method
)
1822 jint h
= hash (method
);
1823 int step
= (h
^ (h
>> 16)) | 1;
1824 int w
= h
& (nathash_size
- 1);
1829 JNINativeMethod
*slotp
= &nathash
[w
];
1830 if (slotp
->name
== NULL
)
1833 return &nathash
[del
];
1837 else if (slotp
->name
== DELETED_ENTRY
)
1839 else if (! strcmp (slotp
->name
, method
->name
)
1840 && ! strcmp (slotp
->signature
, method
->signature
))
1842 w
= (w
+ step
) & (nathash_size
- 1);
1846 // Find a method. Return NULL if it isn't in the hash table.
1848 nathash_find (JNINativeMethod
*method
)
1850 if (nathash
== NULL
)
1852 JNINativeMethod
*slot
= nathash_find_slot (method
);
1853 if (slot
->name
== NULL
|| slot
->name
== DELETED_ENTRY
)
1861 if (nathash
== NULL
)
1863 nathash_size
= 1024;
1865 (JNINativeMethod
*) _Jv_AllocBytes (nathash_size
1866 * sizeof (JNINativeMethod
));
1870 int savesize
= nathash_size
;
1871 JNINativeMethod
*savehash
= nathash
;
1874 (JNINativeMethod
*) _Jv_AllocBytes (nathash_size
1875 * sizeof (JNINativeMethod
));
1877 for (int i
= 0; i
< savesize
; ++i
)
1879 if (savehash
[i
].name
!= NULL
&& savehash
[i
].name
!= DELETED_ENTRY
)
1881 JNINativeMethod
*slot
= nathash_find_slot (&savehash
[i
]);
1882 *slot
= savehash
[i
];
1889 nathash_add (const JNINativeMethod
*method
)
1891 if (3 * nathash_count
>= 2 * nathash_size
)
1893 JNINativeMethod
*slot
= nathash_find_slot (method
);
1894 // If the slot has a real entry in it, then there is no work to do.
1895 if (slot
->name
!= NULL
&& slot
->name
!= DELETED_ENTRY
)
1898 slot
->name
= strdup (method
->name
);
1899 // This was already strduped in _Jv_JNI_RegisterNatives.
1900 slot
->signature
= method
->signature
;
1901 slot
->fnPtr
= method
->fnPtr
;
1905 _Jv_JNI_RegisterNatives (JNIEnv
*env
, jclass klass
,
1906 const JNINativeMethod
*methods
,
1909 // Synchronize while we do the work. This must match
1910 // synchronization in some other functions that manipulate or use
1911 // the nathash table.
1912 JvSynchronize
sync (global_ref_table
);
1914 JNINativeMethod dottedMethod
;
1916 // Look at each descriptor given us, and find the corresponding
1917 // method in the class.
1918 for (int j
= 0; j
< nMethods
; ++j
)
1922 _Jv_Method
*imeths
= JvGetFirstMethod (klass
);
1923 for (int i
= 0; i
< JvNumMethods (klass
); ++i
)
1925 _Jv_Method
*self
= &imeths
[i
];
1927 // Copy this JNINativeMethod and do a slash to dot
1928 // conversion on the signature.
1929 dottedMethod
.name
= methods
[j
].name
;
1930 dottedMethod
.signature
= strdup (methods
[j
].signature
);
1931 dottedMethod
.fnPtr
= methods
[j
].fnPtr
;
1932 char *c
= dottedMethod
.signature
;
1940 if (! strcmp (self
->name
->chars (), dottedMethod
.name
)
1941 && ! strcmp (self
->signature
->chars (), dottedMethod
.signature
))
1943 if (! (self
->accflags
& java::lang::reflect::Modifier::NATIVE
))
1946 // Found a match that is native.
1948 nathash_add (&dottedMethod
);
1956 jstring m
= JvNewStringUTF (methods
[j
].name
);
1959 env
->ex
= new java::lang::NoSuchMethodError (m
);
1961 catch (jthrowable t
)
1973 _Jv_JNI_UnregisterNatives (JNIEnv
*, jclass
)
1975 // FIXME -- we could implement this.
1981 // Add a character to the buffer, encoding properly.
1983 add_char (char *buf
, jchar c
, int *here
)
1987 buf
[(*here
)++] = '_';
1988 buf
[(*here
)++] = '1';
1992 buf
[(*here
)++] = '_';
1993 buf
[(*here
)++] = '2';
1997 buf
[(*here
)++] = '_';
1998 buf
[(*here
)++] = '3';
2001 // Also check for `.' here because we might be passed an internal
2002 // qualified class name like `foo.bar'.
2003 else if (c
== '/' || c
== '.')
2004 buf
[(*here
)++] = '_';
2005 else if ((c
>= '0' && c
<= '9')
2006 || (c
>= 'a' && c
<= 'z')
2007 || (c
>= 'A' && c
<= 'Z'))
2008 buf
[(*here
)++] = (char) c
;
2011 // "Unicode" character.
2012 buf
[(*here
)++] = '_';
2013 buf
[(*here
)++] = '0';
2014 for (int i
= 0; i
< 4; ++i
)
2017 buf
[(*here
) + 3 - i
] = (val
> 10) ? ('a' + val
- 10) : ('0' + val
);
2024 // Compute a mangled name for a native function. This computes the
2025 // long name, and also returns an index which indicates where a NUL
2026 // can be placed to create the short name. This function assumes that
2027 // the buffer is large enough for its results.
2029 mangled_name (jclass klass
, _Jv_Utf8Const
*func_name
,
2030 _Jv_Utf8Const
*signature
, char *buf
, int *long_start
)
2032 strcpy (buf
, "Java_");
2035 // Add fully qualified class name.
2036 jchar
*chars
= _Jv_GetStringChars (klass
->getName ());
2037 jint len
= klass
->getName ()->length ();
2038 for (int i
= 0; i
< len
; ++i
)
2039 add_char (buf
, chars
[i
], &here
);
2041 // Don't use add_char because we need a literal `_'.
2044 const unsigned char *fn
= (const unsigned char *) func_name
->chars ();
2045 const unsigned char *limit
= fn
+ func_name
->len ();
2046 for (int i
= 0; ; ++i
)
2048 int ch
= UTF8_GET (fn
, limit
);
2051 add_char (buf
, ch
, &here
);
2054 // This is where the long signature begins.
2059 const unsigned char *sig
= (const unsigned char *) signature
->chars ();
2060 limit
= sig
+ signature
->len ();
2061 JvAssert (sig
[0] == '(');
2065 int ch
= UTF8_GET (sig
, limit
);
2066 if (ch
== ')' || ch
< 0)
2068 add_char (buf
, ch
, &here
);
2074 // Return the current thread's JNIEnv; if one does not exist, create
2075 // it. Also create a new system frame for use. This is `extern "C"'
2076 // because the compiler calls it.
2078 _Jv_GetJNIEnvNewFrame (jclass klass
)
2080 JNIEnv
*env
= _Jv_GetCurrentJNIEnv ();
2081 if (__builtin_expect (env
== NULL
, false))
2083 env
= (JNIEnv
*) _Jv_MallocUnchecked (sizeof (JNIEnv
));
2084 env
->p
= &_Jv_JNIFunctions
;
2087 // We set env->ex below.
2089 // Set up the bottom, reusable frame.
2090 env
->bottom_locals
= (_Jv_JNI_LocalFrame
*)
2091 _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame
)
2093 * sizeof (jobject
)));
2095 env
->bottom_locals
->marker
= MARK_SYSTEM
;
2096 env
->bottom_locals
->size
= FRAME_SIZE
;
2097 env
->bottom_locals
->next
= NULL
;
2098 env
->bottom_locals
->allocated_p
= 0;
2099 memset (&env
->bottom_locals
->vec
[0], 0,
2100 env
->bottom_locals
->size
* sizeof (jobject
));
2102 _Jv_SetCurrentJNIEnv (env
);
2105 // If we're in a simple JNI call (non-nested), we can just reuse the
2106 // locals frame we allocated many calls ago, back when the env was first
2109 if (__builtin_expect (env
->locals
== NULL
, true))
2110 env
->locals
= env
->bottom_locals
;
2114 // Alternatively, we might be re-entering JNI, in which case we can't
2115 // reuse the bottom_locals frame, because it is already underneath
2116 // us. So we need to make a new one.
2118 _Jv_JNI_LocalFrame
*frame
2119 = (_Jv_JNI_LocalFrame
*) _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame
)
2121 * sizeof (jobject
)));
2123 frame
->marker
= MARK_SYSTEM
;
2124 frame
->size
= FRAME_SIZE
;
2125 frame
->allocated_p
= 0;
2126 frame
->next
= env
->locals
;
2128 memset (&frame
->vec
[0], 0,
2129 frame
->size
* sizeof (jobject
));
2131 env
->locals
= frame
;
2139 // Destroy the env's reusable resources. This is called from the thread
2140 // destructor "finalize_native" in natThread.cc
2142 _Jv_FreeJNIEnv (_Jv_JNIEnv
*env
)
2147 if (env
->bottom_locals
!= NULL
)
2148 _Jv_Free (env
->bottom_locals
);
2153 // Return the function which implements a particular JNI method. If
2154 // we can't find the function, we throw the appropriate exception.
2155 // This is `extern "C"' because the compiler uses it.
2157 _Jv_LookupJNIMethod (jclass klass
, _Jv_Utf8Const
*name
,
2158 _Jv_Utf8Const
*signature
, MAYBE_UNUSED
int args_size
)
2160 int name_length
= name
->len();
2161 int sig_length
= signature
->len();
2162 char buf
[10 + 6 * (name_length
+ sig_length
) + 12];
2166 // Synchronize on something convenient. Right now we use the hash.
2167 JvSynchronize
sync (global_ref_table
);
2169 // First see if we have an override in the hash table.
2170 strncpy (buf
, name
->chars (), name_length
);
2171 buf
[name_length
] = '\0';
2172 strncpy (buf
+ name_length
+ 1, signature
->chars (), sig_length
);
2173 buf
[name_length
+ sig_length
+ 1] = '\0';
2174 JNINativeMethod meth
;
2176 meth
.signature
= buf
+ name_length
+ 1;
2177 function
= nathash_find (&meth
);
2178 if (function
!= NULL
)
2181 // If there was no override, then look in the symbol table.
2183 mangled_name (klass
, name
, signature
, buf
+ 1, &long_start
);
2184 char c
= buf
[long_start
+ 1];
2185 buf
[long_start
+ 1] = '\0';
2187 function
= _Jv_FindSymbolInExecutable (buf
+ 1);
2189 // On Win32, we use the "stdcall" calling convention (see JNICALL
2192 // For a function named 'fooBar' that takes 'nn' bytes as arguments,
2193 // by default, MinGW GCC exports it as 'fooBar@nn', MSVC exports it
2194 // as '_fooBar@nn' and Borland C exports it as 'fooBar'. We try to
2195 // take care of all these variations here.
2197 char asz_buf
[12]; /* '@' + '2147483647' (32-bit INT_MAX) + '\0' */
2198 char long_nm_sv
[11]; /* Ditto, except for the '\0'. */
2200 if (function
== NULL
)
2202 // We have tried searching for the 'fooBar' form (BCC) - now
2205 // First, save the part of the long name that will be damaged
2206 // by appending '@nn'.
2207 memcpy (long_nm_sv
, (buf
+ long_start
+ 1 + 1), sizeof (long_nm_sv
));
2209 sprintf (asz_buf
, "@%d", args_size
);
2210 strcat (buf
, asz_buf
);
2212 // Search for the '_fooBar@nn' form (MSVC).
2213 function
= _Jv_FindSymbolInExecutable (buf
);
2215 if (function
== NULL
)
2217 // Search for the 'fooBar@nn' form (MinGW GCC).
2218 function
= _Jv_FindSymbolInExecutable (buf
+ 1);
2223 if (function
== NULL
)
2225 buf
[long_start
+ 1] = c
;
2227 // Restore the part of the long name that was damaged by
2228 // appending the '@nn'.
2229 memcpy ((buf
+ long_start
+ 1 + 1), long_nm_sv
, sizeof (long_nm_sv
));
2231 function
= _Jv_FindSymbolInExecutable (buf
+ 1);
2232 if (function
== NULL
)
2235 strcat (buf
, asz_buf
);
2236 function
= _Jv_FindSymbolInExecutable (buf
);
2237 if (function
== NULL
)
2238 function
= _Jv_FindSymbolInExecutable (buf
+ 1);
2240 if (function
== NULL
)
2243 jstring str
= JvNewStringUTF (name
->chars ());
2244 throw new java::lang::UnsatisfiedLinkError (str
);
2254 // This function is the stub which is used to turn an ordinary (CNI)
2255 // method call into a JNI call.
2257 _Jv_JNIMethod::call (ffi_cif
*, void *ret
, ffi_raw
*args
, void *__this
)
2259 _Jv_JNIMethod
* _this
= (_Jv_JNIMethod
*) __this
;
2261 JNIEnv
*env
= _Jv_GetJNIEnvNewFrame (_this
->defining_class
);
2263 // FIXME: we should mark every reference parameter as a local. For
2264 // now we assume a conservative GC, and we assume that the
2265 // references are on the stack somewhere.
2267 // We cache the value that we find, of course, but if we don't find
2268 // a value we don't cache that fact -- we might subsequently load a
2269 // library which finds the function in question.
2271 // Synchronize on a convenient object to ensure sanity in case two
2272 // threads reach this point for the same function at the same
2274 JvSynchronize
sync (global_ref_table
);
2275 if (_this
->function
== NULL
)
2277 int args_size
= sizeof (JNIEnv
*) + _this
->args_raw_size
;
2279 if (_this
->self
->accflags
& java::lang::reflect::Modifier::STATIC
)
2280 args_size
+= sizeof (_this
->defining_class
);
2282 _this
->function
= _Jv_LookupJNIMethod (_this
->defining_class
,
2284 _this
->self
->signature
,
2289 JvAssert (_this
->args_raw_size
% sizeof (ffi_raw
) == 0);
2290 ffi_raw real_args
[2 + _this
->args_raw_size
/ sizeof (ffi_raw
)];
2293 // First argument is always the environment pointer.
2294 real_args
[offset
++].ptr
= env
;
2296 // For a static method, we pass in the Class. For non-static
2297 // methods, the `this' argument is already handled.
2298 if ((_this
->self
->accflags
& java::lang::reflect::Modifier::STATIC
))
2299 real_args
[offset
++].ptr
= _this
->defining_class
;
2301 // In libgcj, the callee synchronizes.
2302 jobject sync
= NULL
;
2303 if ((_this
->self
->accflags
& java::lang::reflect::Modifier::SYNCHRONIZED
))
2305 if ((_this
->self
->accflags
& java::lang::reflect::Modifier::STATIC
))
2306 sync
= _this
->defining_class
;
2308 sync
= (jobject
) args
[0].ptr
;
2309 _Jv_MonitorEnter (sync
);
2312 // Copy over passed-in arguments.
2313 memcpy (&real_args
[offset
], args
, _this
->args_raw_size
);
2315 // The actual call to the JNI function.
2316 #if FFI_NATIVE_RAW_API
2317 ffi_raw_call (&_this
->jni_cif
, (void (*)()) _this
->function
,
2320 ffi_java_raw_call (&_this
->jni_cif
, (void (*)()) _this
->function
,
2324 // We might need to unwrap a JNI weak reference here.
2325 if (_this
->jni_cif
.rtype
== &ffi_type_pointer
)
2327 _Jv_value
*val
= (_Jv_value
*) ret
;
2328 val
->object_value
= unwrap (val
->object_value
);
2332 _Jv_MonitorExit (sync
);
2334 _Jv_JNI_PopSystemFrame (env
);
2337 #endif /* INTERPRETER */
2345 // An internal helper function.
2347 _Jv_JNI_AttachCurrentThread (JavaVM
*, jstring name
, void **penv
,
2348 void *args
, jboolean is_daemon
)
2350 JavaVMAttachArgs
*attach
= reinterpret_cast<JavaVMAttachArgs
*> (args
);
2351 java::lang::ThreadGroup
*group
= NULL
;
2355 // FIXME: do we really want to support 1.1?
2356 if (attach
->version
!= JNI_VERSION_1_4
2357 && attach
->version
!= JNI_VERSION_1_2
2358 && attach
->version
!= JNI_VERSION_1_1
)
2359 return JNI_EVERSION
;
2361 JvAssert (java::lang::ThreadGroup::class$
.isInstance (attach
->group
));
2362 group
= reinterpret_cast<java::lang::ThreadGroup
*> (attach
->group
);
2365 // Attaching an already-attached thread is a no-op.
2366 JNIEnv
*env
= _Jv_GetCurrentJNIEnv ();
2369 *penv
= reinterpret_cast<void *> (env
);
2373 env
= (JNIEnv
*) _Jv_MallocUnchecked (sizeof (JNIEnv
));
2376 env
->p
= &_Jv_JNIFunctions
;
2380 = (_Jv_JNI_LocalFrame
*) _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame
)
2382 * sizeof (jobject
)));
2383 env
->locals
= env
->bottom_locals
;
2384 if (env
->locals
== NULL
)
2390 env
->locals
->allocated_p
= 0;
2391 env
->locals
->marker
= MARK_SYSTEM
;
2392 env
->locals
->size
= FRAME_SIZE
;
2393 env
->locals
->next
= NULL
;
2395 for (int i
= 0; i
< env
->locals
->size
; ++i
)
2396 env
->locals
->vec
[i
] = NULL
;
2398 *penv
= reinterpret_cast<void *> (env
);
2400 // This thread might already be a Java thread -- this function might
2401 // have been called simply to set the new JNIEnv.
2402 if (_Jv_ThreadCurrent () == NULL
)
2407 _Jv_AttachCurrentThreadAsDaemon (name
, group
);
2409 _Jv_AttachCurrentThread (name
, group
);
2411 catch (jthrowable t
)
2416 _Jv_SetCurrentJNIEnv (env
);
2421 // This is the one actually used by JNI.
2423 _Jv_JNI_AttachCurrentThread (JavaVM
*vm
, void **penv
, void *args
)
2425 return _Jv_JNI_AttachCurrentThread (vm
, NULL
, penv
, args
, false);
2429 _Jv_JNI_AttachCurrentThreadAsDaemon (JavaVM
*vm
, void **penv
,
2432 return _Jv_JNI_AttachCurrentThread (vm
, NULL
, penv
, args
, true);
2436 _Jv_JNI_DestroyJavaVM (JavaVM
*vm
)
2438 JvAssert (_Jv_the_vm
&& vm
== _Jv_the_vm
);
2446 if (_Jv_ThreadCurrent () != NULL
)
2452 main_name
= JvNewStringLatin1 ("main");
2454 catch (jthrowable t
)
2459 jint r
= _Jv_JNI_AttachCurrentThread (vm
, main_name
, &env_p
,
2465 env
= _Jv_GetCurrentJNIEnv ();
2469 // Docs say that this always returns an error code.
2474 _Jv_JNI_DetachCurrentThread (JavaVM
*)
2476 jint code
= _Jv_DetachCurrentThread ();
2477 return code
? JNI_EDETACHED
: 0;
2481 _Jv_JNI_GetEnv (JavaVM
*, void **penv
, jint version
)
2483 if (_Jv_ThreadCurrent () == NULL
)
2486 return JNI_EDETACHED
;
2490 // Handle JVMPI requests.
2491 if (version
== JVMPI_VERSION_1
)
2493 *penv
= (void *) &_Jv_JVMPI_Interface
;
2498 // FIXME: do we really want to support 1.1?
2499 if (version
!= JNI_VERSION_1_4
&& version
!= JNI_VERSION_1_2
2500 && version
!= JNI_VERSION_1_1
)
2503 return JNI_EVERSION
;
2506 *penv
= (void *) _Jv_GetCurrentJNIEnv ();
2513 // FIXME: synchronize
2516 JavaVM
*nvm
= (JavaVM
*) _Jv_MallocUnchecked (sizeof (JavaVM
));
2518 nvm
->functions
= &_Jv_JNI_InvokeFunctions
;
2522 // If this is a Java thread, we want to make sure it has an
2523 // associated JNIEnv.
2524 if (_Jv_ThreadCurrent () != NULL
)
2527 _Jv_JNI_AttachCurrentThread (_Jv_the_vm
, &ignore
, NULL
);
2534 _Jv_JNI_GetJavaVM (JNIEnv
*, JavaVM
**vm
)
2536 *vm
= _Jv_GetJavaVM ();
2537 return *vm
== NULL
? JNI_ERR
: JNI_OK
;
2542 #define RESERVED NULL
2544 struct JNINativeInterface _Jv_JNIFunctions
=
2550 _Jv_JNI_GetVersion
, // GetVersion
2551 _Jv_JNI_DefineClass
, // DefineClass
2552 _Jv_JNI_FindClass
, // FindClass
2553 _Jv_JNI_FromReflectedMethod
, // FromReflectedMethod
2554 _Jv_JNI_FromReflectedField
, // FromReflectedField
2555 _Jv_JNI_ToReflectedMethod
, // ToReflectedMethod
2556 _Jv_JNI_GetSuperclass
, // GetSuperclass
2557 _Jv_JNI_IsAssignableFrom
, // IsAssignableFrom
2558 _Jv_JNI_ToReflectedField
, // ToReflectedField
2559 _Jv_JNI_Throw
, // Throw
2560 _Jv_JNI_ThrowNew
, // ThrowNew
2561 _Jv_JNI_ExceptionOccurred
, // ExceptionOccurred
2562 _Jv_JNI_ExceptionDescribe
, // ExceptionDescribe
2563 _Jv_JNI_ExceptionClear
, // ExceptionClear
2564 _Jv_JNI_FatalError
, // FatalError
2566 _Jv_JNI_PushLocalFrame
, // PushLocalFrame
2567 _Jv_JNI_PopLocalFrame
, // PopLocalFrame
2568 _Jv_JNI_NewGlobalRef
, // NewGlobalRef
2569 _Jv_JNI_DeleteGlobalRef
, // DeleteGlobalRef
2570 _Jv_JNI_DeleteLocalRef
, // DeleteLocalRef
2572 _Jv_JNI_IsSameObject
, // IsSameObject
2574 _Jv_JNI_NewLocalRef
, // NewLocalRef
2575 _Jv_JNI_EnsureLocalCapacity
, // EnsureLocalCapacity
2577 _Jv_JNI_AllocObject
, // AllocObject
2578 _Jv_JNI_NewObject
, // NewObject
2579 _Jv_JNI_NewObjectV
, // NewObjectV
2580 _Jv_JNI_NewObjectA
, // NewObjectA
2581 _Jv_JNI_GetObjectClass
, // GetObjectClass
2582 _Jv_JNI_IsInstanceOf
, // IsInstanceOf
2583 _Jv_JNI_GetAnyMethodID
<false>, // GetMethodID
2585 _Jv_JNI_CallMethod
<jobject
>, // CallObjectMethod
2586 _Jv_JNI_CallMethodV
<jobject
>, // CallObjectMethodV
2587 _Jv_JNI_CallMethodA
<jobject
>, // CallObjectMethodA
2588 _Jv_JNI_CallMethod
<jboolean
>, // CallBooleanMethod
2589 _Jv_JNI_CallMethodV
<jboolean
>, // CallBooleanMethodV
2590 _Jv_JNI_CallMethodA
<jboolean
>, // CallBooleanMethodA
2591 _Jv_JNI_CallMethod
<jbyte
>, // CallByteMethod
2592 _Jv_JNI_CallMethodV
<jbyte
>, // CallByteMethodV
2593 _Jv_JNI_CallMethodA
<jbyte
>, // CallByteMethodA
2594 _Jv_JNI_CallMethod
<jchar
>, // CallCharMethod
2595 _Jv_JNI_CallMethodV
<jchar
>, // CallCharMethodV
2596 _Jv_JNI_CallMethodA
<jchar
>, // CallCharMethodA
2597 _Jv_JNI_CallMethod
<jshort
>, // CallShortMethod
2598 _Jv_JNI_CallMethodV
<jshort
>, // CallShortMethodV
2599 _Jv_JNI_CallMethodA
<jshort
>, // CallShortMethodA
2600 _Jv_JNI_CallMethod
<jint
>, // CallIntMethod
2601 _Jv_JNI_CallMethodV
<jint
>, // CallIntMethodV
2602 _Jv_JNI_CallMethodA
<jint
>, // CallIntMethodA
2603 _Jv_JNI_CallMethod
<jlong
>, // CallLongMethod
2604 _Jv_JNI_CallMethodV
<jlong
>, // CallLongMethodV
2605 _Jv_JNI_CallMethodA
<jlong
>, // CallLongMethodA
2606 _Jv_JNI_CallMethod
<jfloat
>, // CallFloatMethod
2607 _Jv_JNI_CallMethodV
<jfloat
>, // CallFloatMethodV
2608 _Jv_JNI_CallMethodA
<jfloat
>, // CallFloatMethodA
2609 _Jv_JNI_CallMethod
<jdouble
>, // CallDoubleMethod
2610 _Jv_JNI_CallMethodV
<jdouble
>, // CallDoubleMethodV
2611 _Jv_JNI_CallMethodA
<jdouble
>, // CallDoubleMethodA
2612 _Jv_JNI_CallVoidMethod
, // CallVoidMethod
2613 _Jv_JNI_CallVoidMethodV
, // CallVoidMethodV
2614 _Jv_JNI_CallVoidMethodA
, // CallVoidMethodA
2616 // Nonvirtual method invocation functions follow.
2617 _Jv_JNI_CallAnyMethod
<jobject
, nonvirtual
>, // CallNonvirtualObjectMethod
2618 _Jv_JNI_CallAnyMethodV
<jobject
, nonvirtual
>, // CallNonvirtualObjectMethodV
2619 _Jv_JNI_CallAnyMethodA
<jobject
, nonvirtual
>, // CallNonvirtualObjectMethodA
2620 _Jv_JNI_CallAnyMethod
<jboolean
, nonvirtual
>, // CallNonvirtualBooleanMethod
2621 _Jv_JNI_CallAnyMethodV
<jboolean
, nonvirtual
>, // CallNonvirtualBooleanMethodV
2622 _Jv_JNI_CallAnyMethodA
<jboolean
, nonvirtual
>, // CallNonvirtualBooleanMethodA
2623 _Jv_JNI_CallAnyMethod
<jbyte
, nonvirtual
>, // CallNonvirtualByteMethod
2624 _Jv_JNI_CallAnyMethodV
<jbyte
, nonvirtual
>, // CallNonvirtualByteMethodV
2625 _Jv_JNI_CallAnyMethodA
<jbyte
, nonvirtual
>, // CallNonvirtualByteMethodA
2626 _Jv_JNI_CallAnyMethod
<jchar
, nonvirtual
>, // CallNonvirtualCharMethod
2627 _Jv_JNI_CallAnyMethodV
<jchar
, nonvirtual
>, // CallNonvirtualCharMethodV
2628 _Jv_JNI_CallAnyMethodA
<jchar
, nonvirtual
>, // CallNonvirtualCharMethodA
2629 _Jv_JNI_CallAnyMethod
<jshort
, nonvirtual
>, // CallNonvirtualShortMethod
2630 _Jv_JNI_CallAnyMethodV
<jshort
, nonvirtual
>, // CallNonvirtualShortMethodV
2631 _Jv_JNI_CallAnyMethodA
<jshort
, nonvirtual
>, // CallNonvirtualShortMethodA
2632 _Jv_JNI_CallAnyMethod
<jint
, nonvirtual
>, // CallNonvirtualIntMethod
2633 _Jv_JNI_CallAnyMethodV
<jint
, nonvirtual
>, // CallNonvirtualIntMethodV
2634 _Jv_JNI_CallAnyMethodA
<jint
, nonvirtual
>, // CallNonvirtualIntMethodA
2635 _Jv_JNI_CallAnyMethod
<jlong
, nonvirtual
>, // CallNonvirtualLongMethod
2636 _Jv_JNI_CallAnyMethodV
<jlong
, nonvirtual
>, // CallNonvirtualLongMethodV
2637 _Jv_JNI_CallAnyMethodA
<jlong
, nonvirtual
>, // CallNonvirtualLongMethodA
2638 _Jv_JNI_CallAnyMethod
<jfloat
, nonvirtual
>, // CallNonvirtualFloatMethod
2639 _Jv_JNI_CallAnyMethodV
<jfloat
, nonvirtual
>, // CallNonvirtualFloatMethodV
2640 _Jv_JNI_CallAnyMethodA
<jfloat
, nonvirtual
>, // CallNonvirtualFloatMethodA
2641 _Jv_JNI_CallAnyMethod
<jdouble
, nonvirtual
>, // CallNonvirtualDoubleMethod
2642 _Jv_JNI_CallAnyMethodV
<jdouble
, nonvirtual
>, // CallNonvirtualDoubleMethodV
2643 _Jv_JNI_CallAnyMethodA
<jdouble
, nonvirtual
>, // CallNonvirtualDoubleMethodA
2644 _Jv_JNI_CallAnyVoidMethod
<nonvirtual
>, // CallNonvirtualVoidMethod
2645 _Jv_JNI_CallAnyVoidMethodV
<nonvirtual
>, // CallNonvirtualVoidMethodV
2646 _Jv_JNI_CallAnyVoidMethodA
<nonvirtual
>, // CallNonvirtualVoidMethodA
2648 _Jv_JNI_GetAnyFieldID
<false>, // GetFieldID
2649 _Jv_JNI_GetField
<jobject
>, // GetObjectField
2650 _Jv_JNI_GetField
<jboolean
>, // GetBooleanField
2651 _Jv_JNI_GetField
<jbyte
>, // GetByteField
2652 _Jv_JNI_GetField
<jchar
>, // GetCharField
2653 _Jv_JNI_GetField
<jshort
>, // GetShortField
2654 _Jv_JNI_GetField
<jint
>, // GetIntField
2655 _Jv_JNI_GetField
<jlong
>, // GetLongField
2656 _Jv_JNI_GetField
<jfloat
>, // GetFloatField
2657 _Jv_JNI_GetField
<jdouble
>, // GetDoubleField
2658 _Jv_JNI_SetField
, // SetObjectField
2659 _Jv_JNI_SetField
, // SetBooleanField
2660 _Jv_JNI_SetField
, // SetByteField
2661 _Jv_JNI_SetField
, // SetCharField
2662 _Jv_JNI_SetField
, // SetShortField
2663 _Jv_JNI_SetField
, // SetIntField
2664 _Jv_JNI_SetField
, // SetLongField
2665 _Jv_JNI_SetField
, // SetFloatField
2666 _Jv_JNI_SetField
, // SetDoubleField
2667 _Jv_JNI_GetAnyMethodID
<true>, // GetStaticMethodID
2669 _Jv_JNI_CallStaticMethod
<jobject
>, // CallStaticObjectMethod
2670 _Jv_JNI_CallStaticMethodV
<jobject
>, // CallStaticObjectMethodV
2671 _Jv_JNI_CallStaticMethodA
<jobject
>, // CallStaticObjectMethodA
2672 _Jv_JNI_CallStaticMethod
<jboolean
>, // CallStaticBooleanMethod
2673 _Jv_JNI_CallStaticMethodV
<jboolean
>, // CallStaticBooleanMethodV
2674 _Jv_JNI_CallStaticMethodA
<jboolean
>, // CallStaticBooleanMethodA
2675 _Jv_JNI_CallStaticMethod
<jbyte
>, // CallStaticByteMethod
2676 _Jv_JNI_CallStaticMethodV
<jbyte
>, // CallStaticByteMethodV
2677 _Jv_JNI_CallStaticMethodA
<jbyte
>, // CallStaticByteMethodA
2678 _Jv_JNI_CallStaticMethod
<jchar
>, // CallStaticCharMethod
2679 _Jv_JNI_CallStaticMethodV
<jchar
>, // CallStaticCharMethodV
2680 _Jv_JNI_CallStaticMethodA
<jchar
>, // CallStaticCharMethodA
2681 _Jv_JNI_CallStaticMethod
<jshort
>, // CallStaticShortMethod
2682 _Jv_JNI_CallStaticMethodV
<jshort
>, // CallStaticShortMethodV
2683 _Jv_JNI_CallStaticMethodA
<jshort
>, // CallStaticShortMethodA
2684 _Jv_JNI_CallStaticMethod
<jint
>, // CallStaticIntMethod
2685 _Jv_JNI_CallStaticMethodV
<jint
>, // CallStaticIntMethodV
2686 _Jv_JNI_CallStaticMethodA
<jint
>, // CallStaticIntMethodA
2687 _Jv_JNI_CallStaticMethod
<jlong
>, // CallStaticLongMethod
2688 _Jv_JNI_CallStaticMethodV
<jlong
>, // CallStaticLongMethodV
2689 _Jv_JNI_CallStaticMethodA
<jlong
>, // CallStaticLongMethodA
2690 _Jv_JNI_CallStaticMethod
<jfloat
>, // CallStaticFloatMethod
2691 _Jv_JNI_CallStaticMethodV
<jfloat
>, // CallStaticFloatMethodV
2692 _Jv_JNI_CallStaticMethodA
<jfloat
>, // CallStaticFloatMethodA
2693 _Jv_JNI_CallStaticMethod
<jdouble
>, // CallStaticDoubleMethod
2694 _Jv_JNI_CallStaticMethodV
<jdouble
>, // CallStaticDoubleMethodV
2695 _Jv_JNI_CallStaticMethodA
<jdouble
>, // CallStaticDoubleMethodA
2696 _Jv_JNI_CallStaticVoidMethod
, // CallStaticVoidMethod
2697 _Jv_JNI_CallStaticVoidMethodV
, // CallStaticVoidMethodV
2698 _Jv_JNI_CallStaticVoidMethodA
, // CallStaticVoidMethodA
2700 _Jv_JNI_GetAnyFieldID
<true>, // GetStaticFieldID
2701 _Jv_JNI_GetStaticField
<jobject
>, // GetStaticObjectField
2702 _Jv_JNI_GetStaticField
<jboolean
>, // GetStaticBooleanField
2703 _Jv_JNI_GetStaticField
<jbyte
>, // GetStaticByteField
2704 _Jv_JNI_GetStaticField
<jchar
>, // GetStaticCharField
2705 _Jv_JNI_GetStaticField
<jshort
>, // GetStaticShortField
2706 _Jv_JNI_GetStaticField
<jint
>, // GetStaticIntField
2707 _Jv_JNI_GetStaticField
<jlong
>, // GetStaticLongField
2708 _Jv_JNI_GetStaticField
<jfloat
>, // GetStaticFloatField
2709 _Jv_JNI_GetStaticField
<jdouble
>, // GetStaticDoubleField
2710 _Jv_JNI_SetStaticField
, // SetStaticObjectField
2711 _Jv_JNI_SetStaticField
, // SetStaticBooleanField
2712 _Jv_JNI_SetStaticField
, // SetStaticByteField
2713 _Jv_JNI_SetStaticField
, // SetStaticCharField
2714 _Jv_JNI_SetStaticField
, // SetStaticShortField
2715 _Jv_JNI_SetStaticField
, // SetStaticIntField
2716 _Jv_JNI_SetStaticField
, // SetStaticLongField
2717 _Jv_JNI_SetStaticField
, // SetStaticFloatField
2718 _Jv_JNI_SetStaticField
, // SetStaticDoubleField
2719 _Jv_JNI_NewString
, // NewString
2720 _Jv_JNI_GetStringLength
, // GetStringLength
2721 _Jv_JNI_GetStringChars
, // GetStringChars
2722 _Jv_JNI_ReleaseStringChars
, // ReleaseStringChars
2723 _Jv_JNI_NewStringUTF
, // NewStringUTF
2724 _Jv_JNI_GetStringUTFLength
, // GetStringUTFLength
2725 _Jv_JNI_GetStringUTFChars
, // GetStringUTFChars
2726 _Jv_JNI_ReleaseStringUTFChars
, // ReleaseStringUTFChars
2727 _Jv_JNI_GetArrayLength
, // GetArrayLength
2728 _Jv_JNI_NewObjectArray
, // NewObjectArray
2729 _Jv_JNI_GetObjectArrayElement
, // GetObjectArrayElement
2730 _Jv_JNI_SetObjectArrayElement
, // SetObjectArrayElement
2731 _Jv_JNI_NewPrimitiveArray
<jboolean
, JvPrimClass (boolean
)>,
2733 _Jv_JNI_NewPrimitiveArray
<jbyte
, JvPrimClass (byte
)>, // NewByteArray
2734 _Jv_JNI_NewPrimitiveArray
<jchar
, JvPrimClass (char)>, // NewCharArray
2735 _Jv_JNI_NewPrimitiveArray
<jshort
, JvPrimClass (short)>, // NewShortArray
2736 _Jv_JNI_NewPrimitiveArray
<jint
, JvPrimClass (int)>, // NewIntArray
2737 _Jv_JNI_NewPrimitiveArray
<jlong
, JvPrimClass (long)>, // NewLongArray
2738 _Jv_JNI_NewPrimitiveArray
<jfloat
, JvPrimClass (float)>, // NewFloatArray
2739 _Jv_JNI_NewPrimitiveArray
<jdouble
, JvPrimClass (double)>, // NewDoubleArray
2740 _Jv_JNI_GetPrimitiveArrayElements
<jboolean
, JvPrimClass (boolean
)>,
2741 // GetBooleanArrayElements
2742 _Jv_JNI_GetPrimitiveArrayElements
<jbyte
, JvPrimClass (byte
)>,
2743 // GetByteArrayElements
2744 _Jv_JNI_GetPrimitiveArrayElements
<jchar
, JvPrimClass (char)>,
2745 // GetCharArrayElements
2746 _Jv_JNI_GetPrimitiveArrayElements
<jshort
, JvPrimClass (short)>,
2747 // GetShortArrayElements
2748 _Jv_JNI_GetPrimitiveArrayElements
<jint
, JvPrimClass (int)>,
2749 // GetIntArrayElements
2750 _Jv_JNI_GetPrimitiveArrayElements
<jlong
, JvPrimClass (long)>,
2751 // GetLongArrayElements
2752 _Jv_JNI_GetPrimitiveArrayElements
<jfloat
, JvPrimClass (float)>,
2753 // GetFloatArrayElements
2754 _Jv_JNI_GetPrimitiveArrayElements
<jdouble
, JvPrimClass (double)>,
2755 // GetDoubleArrayElements
2756 _Jv_JNI_ReleasePrimitiveArrayElements
<jboolean
, JvPrimClass (boolean
)>,
2757 // ReleaseBooleanArrayElements
2758 _Jv_JNI_ReleasePrimitiveArrayElements
<jbyte
, JvPrimClass (byte
)>,
2759 // ReleaseByteArrayElements
2760 _Jv_JNI_ReleasePrimitiveArrayElements
<jchar
, JvPrimClass (char)>,
2761 // ReleaseCharArrayElements
2762 _Jv_JNI_ReleasePrimitiveArrayElements
<jshort
, JvPrimClass (short)>,
2763 // ReleaseShortArrayElements
2764 _Jv_JNI_ReleasePrimitiveArrayElements
<jint
, JvPrimClass (int)>,
2765 // ReleaseIntArrayElements
2766 _Jv_JNI_ReleasePrimitiveArrayElements
<jlong
, JvPrimClass (long)>,
2767 // ReleaseLongArrayElements
2768 _Jv_JNI_ReleasePrimitiveArrayElements
<jfloat
, JvPrimClass (float)>,
2769 // ReleaseFloatArrayElements
2770 _Jv_JNI_ReleasePrimitiveArrayElements
<jdouble
, JvPrimClass (double)>,
2771 // ReleaseDoubleArrayElements
2772 _Jv_JNI_GetPrimitiveArrayRegion
<jboolean
, JvPrimClass (boolean
)>,
2773 // GetBooleanArrayRegion
2774 _Jv_JNI_GetPrimitiveArrayRegion
<jbyte
, JvPrimClass (byte
)>,
2775 // GetByteArrayRegion
2776 _Jv_JNI_GetPrimitiveArrayRegion
<jchar
, JvPrimClass (char)>,
2777 // GetCharArrayRegion
2778 _Jv_JNI_GetPrimitiveArrayRegion
<jshort
, JvPrimClass (short)>,
2779 // GetShortArrayRegion
2780 _Jv_JNI_GetPrimitiveArrayRegion
<jint
, JvPrimClass (int)>,
2781 // GetIntArrayRegion
2782 _Jv_JNI_GetPrimitiveArrayRegion
<jlong
, JvPrimClass (long)>,
2783 // GetLongArrayRegion
2784 _Jv_JNI_GetPrimitiveArrayRegion
<jfloat
, JvPrimClass (float)>,
2785 // GetFloatArrayRegion
2786 _Jv_JNI_GetPrimitiveArrayRegion
<jdouble
, JvPrimClass (double)>,
2787 // GetDoubleArrayRegion
2788 _Jv_JNI_SetPrimitiveArrayRegion
<jboolean
, JvPrimClass (boolean
)>,
2789 // SetBooleanArrayRegion
2790 _Jv_JNI_SetPrimitiveArrayRegion
<jbyte
, JvPrimClass (byte
)>,
2791 // SetByteArrayRegion
2792 _Jv_JNI_SetPrimitiveArrayRegion
<jchar
, JvPrimClass (char)>,
2793 // SetCharArrayRegion
2794 _Jv_JNI_SetPrimitiveArrayRegion
<jshort
, JvPrimClass (short)>,
2795 // SetShortArrayRegion
2796 _Jv_JNI_SetPrimitiveArrayRegion
<jint
, JvPrimClass (int)>,
2797 // SetIntArrayRegion
2798 _Jv_JNI_SetPrimitiveArrayRegion
<jlong
, JvPrimClass (long)>,
2799 // SetLongArrayRegion
2800 _Jv_JNI_SetPrimitiveArrayRegion
<jfloat
, JvPrimClass (float)>,
2801 // SetFloatArrayRegion
2802 _Jv_JNI_SetPrimitiveArrayRegion
<jdouble
, JvPrimClass (double)>,
2803 // SetDoubleArrayRegion
2804 _Jv_JNI_RegisterNatives
, // RegisterNatives
2805 _Jv_JNI_UnregisterNatives
, // UnregisterNatives
2806 _Jv_JNI_MonitorEnter
, // MonitorEnter
2807 _Jv_JNI_MonitorExit
, // MonitorExit
2808 _Jv_JNI_GetJavaVM
, // GetJavaVM
2810 _Jv_JNI_GetStringRegion
, // GetStringRegion
2811 _Jv_JNI_GetStringUTFRegion
, // GetStringUTFRegion
2812 _Jv_JNI_GetPrimitiveArrayCritical
, // GetPrimitiveArrayCritical
2813 _Jv_JNI_ReleasePrimitiveArrayCritical
, // ReleasePrimitiveArrayCritical
2814 _Jv_JNI_GetStringCritical
, // GetStringCritical
2815 _Jv_JNI_ReleaseStringCritical
, // ReleaseStringCritical
2817 _Jv_JNI_NewWeakGlobalRef
, // NewWeakGlobalRef
2818 _Jv_JNI_DeleteWeakGlobalRef
, // DeleteWeakGlobalRef
2820 _Jv_JNI_ExceptionCheck
, // ExceptionCheck
2822 _Jv_JNI_NewDirectByteBuffer
, // NewDirectByteBuffer
2823 _Jv_JNI_GetDirectBufferAddress
, // GetDirectBufferAddress
2824 _Jv_JNI_GetDirectBufferCapacity
// GetDirectBufferCapacity
2827 struct JNIInvokeInterface _Jv_JNI_InvokeFunctions
=
2833 _Jv_JNI_DestroyJavaVM
,
2834 _Jv_JNI_AttachCurrentThread
,
2835 _Jv_JNI_DetachCurrentThread
,
2837 _Jv_JNI_AttachCurrentThreadAsDaemon