1 // jni.cc - JNI implementation, including the jump table.
3 /* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
16 // Define this before including jni.h.
17 #define __GCJ_JNI_IMPL__
21 #include <java-assert.h>
27 #include <java/lang/Class.h>
28 #include <java/lang/ClassLoader.h>
29 #include <java/lang/Throwable.h>
30 #include <java/lang/ArrayIndexOutOfBoundsException.h>
31 #include <java/lang/StringIndexOutOfBoundsException.h>
32 #include <java/lang/AbstractMethodError.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/util/IdentityHashMap.h>
41 #include <java/lang/Integer.h>
42 #include <java/lang/ThreadGroup.h>
43 #include <java/lang/Thread.h>
44 #include <gnu/gcj/runtime/JNIWeakRef.h>
46 #include <gcj/method.h>
47 #include <gcj/field.h>
49 #include <java-interp.h>
50 #include <java-threads.h>
54 // This enum is used to select different template instantiations in
55 // the invocation code.
64 // Forward declarations.
65 extern struct JNINativeInterface _Jv_JNIFunctions
;
66 extern struct JNIInvokeInterface _Jv_JNI_InvokeFunctions
;
68 // Number of slots in the default frame. The VM must allow at least
72 // Mark value indicating this is an overflow frame.
74 // Mark value indicating this is a user frame.
76 // Mark value indicating this is a system frame.
79 // This structure is used to keep track of local references.
80 struct _Jv_JNI_LocalFrame
82 // This is true if this frame object represents a pushed frame (eg
83 // from PushLocalFrame).
86 // Number of elements in frame.
89 // Next frame in chain.
90 _Jv_JNI_LocalFrame
*next
;
92 // The elements. These are allocated using the C "struct hack".
96 // This holds a reference count for all local references.
97 static java::util::IdentityHashMap
*local_ref_table
;
98 // This holds a reference count for all global references.
99 static java::util::IdentityHashMap
*global_ref_table
;
102 static JavaVM
*the_vm
;
105 // The only JVMPI interface description.
106 static JVMPI_Interface _Jv_JVMPI_Interface
;
109 jvmpiEnableEvent (jint event_type
, void *)
113 case JVMPI_EVENT_OBJECT_ALLOC
:
114 _Jv_JVMPI_Notify_OBJECT_ALLOC
= _Jv_JVMPI_Interface
.NotifyEvent
;
117 case JVMPI_EVENT_THREAD_START
:
118 _Jv_JVMPI_Notify_THREAD_START
= _Jv_JVMPI_Interface
.NotifyEvent
;
121 case JVMPI_EVENT_THREAD_END
:
122 _Jv_JVMPI_Notify_THREAD_END
= _Jv_JVMPI_Interface
.NotifyEvent
;
126 return JVMPI_NOT_AVAILABLE
;
129 return JVMPI_SUCCESS
;
133 jvmpiDisableEvent (jint event_type
, void *)
137 case JVMPI_EVENT_OBJECT_ALLOC
:
138 _Jv_JVMPI_Notify_OBJECT_ALLOC
= NULL
;
142 return JVMPI_NOT_AVAILABLE
;
145 return JVMPI_SUCCESS
;
154 local_ref_table
= new java::util::IdentityHashMap
;
155 global_ref_table
= new java::util::IdentityHashMap
;
158 _Jv_JVMPI_Interface
.version
= 1;
159 _Jv_JVMPI_Interface
.EnableEvent
= &jvmpiEnableEvent
;
160 _Jv_JVMPI_Interface
.DisableEvent
= &jvmpiDisableEvent
;
161 _Jv_JVMPI_Interface
.EnableGC
= &_Jv_EnableGC
;
162 _Jv_JVMPI_Interface
.DisableGC
= &_Jv_DisableGC
;
163 _Jv_JVMPI_Interface
.RunGC
= &_Jv_RunGC
;
167 // Tell the GC that a certain pointer is live.
169 mark_for_gc (jobject obj
, java::util::IdentityHashMap
*ref_table
)
171 JvSynchronize
sync (ref_table
);
173 using namespace java::lang
;
174 Integer
*refcount
= (Integer
*) ref_table
->get (obj
);
175 jint val
= (refcount
== NULL
) ? 0 : refcount
->intValue ();
176 // FIXME: what about out of memory error?
177 ref_table
->put (obj
, new Integer (val
+ 1));
182 unmark_for_gc (jobject obj
, java::util::IdentityHashMap
*ref_table
)
184 JvSynchronize
sync (ref_table
);
186 using namespace java::lang
;
187 Integer
*refcount
= (Integer
*) ref_table
->get (obj
);
189 jint val
= refcount
->intValue () - 1;
192 ref_table
->remove (obj
);
194 // FIXME: what about out of memory error?
195 ref_table
->put (obj
, new Integer (val
));
198 // "Unwrap" some random non-reference type. This exists to simplify
199 // other template functions.
207 // Unwrap a weak reference, if required.
212 using namespace gnu::gcj::runtime
;
213 // We can compare the class directly because JNIWeakRef is `final'.
214 // Doing it this way is much faster.
215 if (obj
== NULL
|| obj
->getClass () != &JNIWeakRef::class$
)
217 JNIWeakRef
*wr
= reinterpret_cast<JNIWeakRef
*> (obj
);
218 return reinterpret_cast<T
*> (wr
->get ());
224 _Jv_JNI_NewGlobalRef (JNIEnv
*, jobject obj
)
226 // This seems weird but I think it is correct.
228 mark_for_gc (obj
, global_ref_table
);
233 _Jv_JNI_DeleteGlobalRef (JNIEnv
*, jobject obj
)
235 // This seems weird but I think it is correct.
237 unmark_for_gc (obj
, global_ref_table
);
241 _Jv_JNI_DeleteLocalRef (JNIEnv
*env
, jobject obj
)
243 _Jv_JNI_LocalFrame
*frame
;
245 // This seems weird but I think it is correct.
248 for (frame
= env
->locals
; frame
!= NULL
; frame
= frame
->next
)
250 for (int i
= 0; i
< frame
->size
; ++i
)
252 if (frame
->vec
[i
] == obj
)
254 frame
->vec
[i
] = NULL
;
255 unmark_for_gc (obj
, local_ref_table
);
260 // Don't go past a marked frame.
261 JvAssert (frame
->marker
== MARK_NONE
);
268 _Jv_JNI_EnsureLocalCapacity (JNIEnv
*env
, jint size
)
270 // It is easier to just always allocate a new frame of the requested
271 // size. This isn't the most efficient thing, but for now we don't
272 // care. Note that _Jv_JNI_PushLocalFrame relies on this right now.
274 _Jv_JNI_LocalFrame
*frame
;
277 frame
= (_Jv_JNI_LocalFrame
*) _Jv_Malloc (sizeof (_Jv_JNI_LocalFrame
)
278 + size
* sizeof (jobject
));
286 frame
->marker
= MARK_NONE
;
288 memset (&frame
->vec
[0], 0, size
* sizeof (jobject
));
289 frame
->next
= env
->locals
;
296 _Jv_JNI_PushLocalFrame (JNIEnv
*env
, jint size
)
298 jint r
= _Jv_JNI_EnsureLocalCapacity (env
, size
);
302 // The new frame is on top.
303 env
->locals
->marker
= MARK_USER
;
309 _Jv_JNI_NewLocalRef (JNIEnv
*env
, jobject obj
)
311 // This seems weird but I think it is correct.
314 // Try to find an open slot somewhere in the topmost frame.
315 _Jv_JNI_LocalFrame
*frame
= env
->locals
;
316 bool done
= false, set
= false;
317 for (; frame
!= NULL
&& ! done
; frame
= frame
->next
)
319 for (int i
= 0; i
< frame
->size
; ++i
)
321 if (frame
->vec
[i
] == NULL
)
330 // If we found a slot, or if the frame we just searched is the
331 // mark frame, then we are done.
332 if (done
|| frame
->marker
!= MARK_NONE
)
338 // No slots, so we allocate a new frame. According to the spec
339 // we could just die here. FIXME: return value.
340 _Jv_JNI_EnsureLocalCapacity (env
, 16);
341 // We know the first element of the new frame will be ok.
342 env
->locals
->vec
[0] = obj
;
345 mark_for_gc (obj
, local_ref_table
);
350 _Jv_JNI_PopLocalFrame (JNIEnv
*env
, jobject result
, int stop
)
352 _Jv_JNI_LocalFrame
*rf
= env
->locals
;
355 while (rf
!= NULL
&& ! done
)
357 for (int i
= 0; i
< rf
->size
; ++i
)
358 if (rf
->vec
[i
] != NULL
)
359 unmark_for_gc (rf
->vec
[i
], local_ref_table
);
361 // If the frame we just freed is the marker frame, we are done.
362 done
= (rf
->marker
== stop
);
364 _Jv_JNI_LocalFrame
*n
= rf
->next
;
365 // When N==NULL, we've reached the stack-allocated frame, and we
366 // must not free it. However, we must be sure to clear all its
367 // elements, since we might conceivably reuse it.
370 memset (&rf
->vec
[0], 0, rf
->size
* sizeof (jobject
));
378 // Update the local frame information.
381 return result
== NULL
? NULL
: _Jv_JNI_NewLocalRef (env
, result
);
385 _Jv_JNI_PopLocalFrame (JNIEnv
*env
, jobject result
)
387 return _Jv_JNI_PopLocalFrame (env
, result
, MARK_USER
);
390 // Pop a `system' frame from the stack. This is `extern "C"' as it is
391 // used by the compiler.
393 _Jv_JNI_PopSystemFrame (JNIEnv
*env
)
395 _Jv_JNI_PopLocalFrame (env
, NULL
, MARK_SYSTEM
);
399 jthrowable t
= env
->ex
;
405 // This function is used from other template functions. It wraps the
406 // return value appropriately; we specialize it so that object returns
407 // are turned into local references.
410 wrap_value (JNIEnv
*, T value
)
415 // This specialization is used for jobject, jclass, jstring, jarray,
419 wrap_value (JNIEnv
*env
, T
*value
)
421 return (value
== NULL
423 : (T
*) _Jv_JNI_NewLocalRef (env
, (jobject
) value
));
429 _Jv_JNI_GetVersion (JNIEnv
*)
431 return JNI_VERSION_1_2
;
435 _Jv_JNI_DefineClass (JNIEnv
*env
, jobject loader
,
436 const jbyte
*buf
, jsize bufLen
)
440 loader
= unwrap (loader
);
442 jbyteArray bytes
= JvNewByteArray (bufLen
);
444 jbyte
*elts
= elements (bytes
);
445 memcpy (elts
, buf
, bufLen
* sizeof (jbyte
));
447 java::lang::ClassLoader
*l
448 = reinterpret_cast<java::lang::ClassLoader
*> (loader
);
450 jclass result
= l
->defineClass (bytes
, 0, bufLen
);
451 return (jclass
) wrap_value (env
, result
);
461 _Jv_JNI_FindClass (JNIEnv
*env
, const char *name
)
463 // FIXME: assume that NAME isn't too long.
464 int len
= strlen (name
);
466 for (int i
= 0; i
<= len
; ++i
)
467 s
[i
] = (name
[i
] == '/') ? '.' : name
[i
];
472 // This might throw an out of memory exception.
473 jstring n
= JvNewStringUTF (s
);
475 java::lang::ClassLoader
*loader
= NULL
;
476 if (env
->klass
!= NULL
)
477 loader
= env
->klass
->getClassLoader ();
481 // FIXME: should use getBaseClassLoader, but we don't have that
483 loader
= java::lang::ClassLoader::getSystemClassLoader ();
486 r
= loader
->loadClass (n
);
493 return (jclass
) wrap_value (env
, r
);
497 _Jv_JNI_GetSuperclass (JNIEnv
*env
, jclass clazz
)
499 return (jclass
) wrap_value (env
, unwrap (clazz
)->getSuperclass ());
503 _Jv_JNI_IsAssignableFrom(JNIEnv
*, jclass clazz1
, jclass clazz2
)
505 return unwrap (clazz1
)->isAssignableFrom (unwrap (clazz2
));
509 _Jv_JNI_Throw (JNIEnv
*env
, jthrowable obj
)
511 // We check in case the user did some funky cast.
513 JvAssert (obj
!= NULL
&& java::lang::Throwable::class$
.isInstance (obj
));
519 _Jv_JNI_ThrowNew (JNIEnv
*env
, jclass clazz
, const char *message
)
521 using namespace java::lang::reflect
;
523 clazz
= unwrap (clazz
);
524 JvAssert (java::lang::Throwable::class$
.isAssignableFrom (clazz
));
529 JArray
<jclass
> *argtypes
530 = (JArray
<jclass
> *) JvNewObjectArray (1, &java::lang::Class::class$
,
533 jclass
*elts
= elements (argtypes
);
534 elts
[0] = &StringClass
;
536 Constructor
*cons
= clazz
->getConstructor (argtypes
);
538 jobjectArray values
= JvNewObjectArray (1, &StringClass
, NULL
);
539 jobject
*velts
= elements (values
);
540 velts
[0] = JvNewStringUTF (message
);
542 jobject obj
= cons
->newInstance (values
);
544 env
->ex
= reinterpret_cast<jthrowable
> (obj
);
556 _Jv_JNI_ExceptionOccurred (JNIEnv
*env
)
558 return (jthrowable
) wrap_value (env
, env
->ex
);
562 _Jv_JNI_ExceptionDescribe (JNIEnv
*env
)
565 env
->ex
->printStackTrace();
569 _Jv_JNI_ExceptionClear (JNIEnv
*env
)
575 _Jv_JNI_ExceptionCheck (JNIEnv
*env
)
577 return env
->ex
!= NULL
;
581 _Jv_JNI_FatalError (JNIEnv
*, const char *message
)
589 _Jv_JNI_IsSameObject (JNIEnv
*, jobject obj1
, jobject obj2
)
591 return unwrap (obj1
) == unwrap (obj2
);
595 _Jv_JNI_AllocObject (JNIEnv
*env
, jclass clazz
)
598 using namespace java::lang::reflect
;
602 clazz
= unwrap (clazz
);
603 JvAssert (clazz
&& ! clazz
->isArray ());
604 if (clazz
->isInterface() || Modifier::isAbstract(clazz
->getModifiers()))
605 env
->ex
= new java::lang::InstantiationException ();
608 // FIXME: will this work for String?
609 obj
= JvAllocObject (clazz
);
617 return wrap_value (env
, obj
);
621 _Jv_JNI_GetObjectClass (JNIEnv
*env
, jobject obj
)
625 return (jclass
) wrap_value (env
, obj
->getClass());
629 _Jv_JNI_IsInstanceOf (JNIEnv
*, jobject obj
, jclass clazz
)
631 return unwrap (clazz
)->isInstance(unwrap (obj
));
637 // This section concerns method invocation.
640 template<jboolean is_static
>
642 _Jv_JNI_GetAnyMethodID (JNIEnv
*env
, jclass clazz
,
643 const char *name
, const char *sig
)
647 clazz
= unwrap (clazz
);
648 _Jv_InitClass (clazz
);
650 _Jv_Utf8Const
*name_u
= _Jv_makeUtf8Const ((char *) name
, -1);
652 // FIXME: assume that SIG isn't too long.
653 int len
= strlen (sig
);
655 for (int i
= 0; i
<= len
; ++i
)
656 s
[i
] = (sig
[i
] == '/') ? '.' : sig
[i
];
657 _Jv_Utf8Const
*sig_u
= _Jv_makeUtf8Const ((char *) s
, -1);
659 JvAssert (! clazz
->isPrimitive());
661 using namespace java::lang::reflect
;
663 while (clazz
!= NULL
)
665 jint count
= JvNumMethods (clazz
);
666 jmethodID meth
= JvGetFirstMethod (clazz
);
668 for (jint i
= 0; i
< count
; ++i
)
670 if (((is_static
&& Modifier::isStatic (meth
->accflags
))
671 || (! is_static
&& ! Modifier::isStatic (meth
->accflags
)))
672 && _Jv_equalUtf8Consts (meth
->name
, name_u
)
673 && _Jv_equalUtf8Consts (meth
->signature
, sig_u
))
676 meth
= meth
->getNextMethod();
679 clazz
= clazz
->getSuperclass ();
682 env
->ex
= new java::lang::NoSuchMethodError ();
692 // This is a helper function which turns a va_list into an array of
693 // `jvalue's. It needs signature information in order to do its work.
694 // The array of values must already be allocated.
696 array_from_valist (jvalue
*values
, JArray
<jclass
> *arg_types
, va_list vargs
)
698 jclass
*arg_elts
= elements (arg_types
);
699 for (int i
= 0; i
< arg_types
->length
; ++i
)
701 if (arg_elts
[i
] == JvPrimClass (byte
))
702 values
[i
].b
= (jbyte
) va_arg (vargs
, int);
703 else if (arg_elts
[i
] == JvPrimClass (short))
704 values
[i
].s
= (jshort
) va_arg (vargs
, int);
705 else if (arg_elts
[i
] == JvPrimClass (int))
706 values
[i
].i
= va_arg (vargs
, jint
);
707 else if (arg_elts
[i
] == JvPrimClass (long))
708 values
[i
].j
= va_arg (vargs
, jlong
);
709 else if (arg_elts
[i
] == JvPrimClass (float))
710 values
[i
].f
= va_arg (vargs
, jfloat
);
711 else if (arg_elts
[i
] == JvPrimClass (double))
712 values
[i
].d
= va_arg (vargs
, jdouble
);
713 else if (arg_elts
[i
] == JvPrimClass (boolean
))
714 values
[i
].z
= (jboolean
) va_arg (vargs
, int);
715 else if (arg_elts
[i
] == JvPrimClass (char))
716 values
[i
].c
= (jchar
) va_arg (vargs
, int);
720 values
[i
].l
= unwrap (va_arg (vargs
, jobject
));
725 // This can call any sort of method: virtual, "nonvirtual", static, or
727 template<typename T
, invocation_type style
>
729 _Jv_JNI_CallAnyMethodV (JNIEnv
*env
, jobject obj
, jclass klass
,
730 jmethodID id
, va_list vargs
)
733 klass
= unwrap (klass
);
736 id
= _Jv_LookupDeclaredMethod (obj
->getClass (), id
->name
, id
->signature
);
738 jclass decl_class
= klass
? klass
: obj
->getClass ();
739 JvAssert (decl_class
!= NULL
);
742 JArray
<jclass
> *arg_types
;
746 _Jv_GetTypesFromSignature (id
, decl_class
,
747 &arg_types
, &return_type
);
749 jvalue args
[arg_types
->length
];
750 array_from_valist (args
, arg_types
, vargs
);
752 // For constructors we need to pass the Class we are instantiating.
753 if (style
== constructor
)
757 jthrowable ex
= _Jv_CallAnyMethodA (obj
, return_type
, id
,
758 style
== constructor
,
759 arg_types
, args
, &result
);
764 // We cheat a little here. FIXME.
765 return wrap_value (env
, * (T
*) &result
);
772 return wrap_value (env
, (T
) 0);
775 template<typename T
, invocation_type style
>
777 _Jv_JNI_CallAnyMethod (JNIEnv
*env
, jobject obj
, jclass klass
,
778 jmethodID method
, ...)
783 va_start (args
, method
);
784 result
= _Jv_JNI_CallAnyMethodV
<T
, style
> (env
, obj
, klass
, method
, args
);
790 template<typename T
, invocation_type style
>
792 _Jv_JNI_CallAnyMethodA (JNIEnv
*env
, jobject obj
, jclass klass
,
793 jmethodID id
, jvalue
*args
)
796 klass
= unwrap (klass
);
799 id
= _Jv_LookupDeclaredMethod (obj
->getClass (), id
->name
, id
->signature
);
801 jclass decl_class
= klass
? klass
: obj
->getClass ();
802 JvAssert (decl_class
!= NULL
);
805 JArray
<jclass
> *arg_types
;
808 _Jv_GetTypesFromSignature (id
, decl_class
,
809 &arg_types
, &return_type
);
811 // For constructors we need to pass the Class we are instantiating.
812 if (style
== constructor
)
815 // Unwrap arguments as required. Eww.
816 jclass
*type_elts
= elements (arg_types
);
817 jvalue arg_copy
[arg_types
->length
];
818 for (int i
= 0; i
< arg_types
->length
; ++i
)
820 if (type_elts
[i
]->isPrimitive ())
821 arg_copy
[i
] = args
[i
];
823 arg_copy
[i
].l
= unwrap (args
[i
].l
);
827 jthrowable ex
= _Jv_CallAnyMethodA (obj
, return_type
, id
,
828 style
== constructor
,
829 arg_types
, arg_copy
, &result
);
834 // We cheat a little here. FIXME.
835 return wrap_value (env
, * (T
*) &result
);
842 return wrap_value (env
, (T
) 0);
845 template<invocation_type style
>
847 _Jv_JNI_CallAnyVoidMethodV (JNIEnv
*env
, jobject obj
, jclass klass
,
848 jmethodID id
, va_list vargs
)
851 klass
= unwrap (klass
);
854 id
= _Jv_LookupDeclaredMethod (obj
->getClass (), id
->name
, id
->signature
);
856 jclass decl_class
= klass
? klass
: obj
->getClass ();
857 JvAssert (decl_class
!= NULL
);
860 JArray
<jclass
> *arg_types
;
863 _Jv_GetTypesFromSignature (id
, decl_class
,
864 &arg_types
, &return_type
);
866 jvalue args
[arg_types
->length
];
867 array_from_valist (args
, arg_types
, vargs
);
869 // For constructors we need to pass the Class we are instantiating.
870 if (style
== constructor
)
873 jthrowable ex
= _Jv_CallAnyMethodA (obj
, return_type
, id
,
874 style
== constructor
,
875 arg_types
, args
, NULL
);
886 template<invocation_type style
>
888 _Jv_JNI_CallAnyVoidMethod (JNIEnv
*env
, jobject obj
, jclass klass
,
889 jmethodID method
, ...)
893 va_start (args
, method
);
894 _Jv_JNI_CallAnyVoidMethodV
<style
> (env
, obj
, klass
, method
, args
);
898 template<invocation_type style
>
900 _Jv_JNI_CallAnyVoidMethodA (JNIEnv
*env
, jobject obj
, jclass klass
,
901 jmethodID id
, jvalue
*args
)
904 id
= _Jv_LookupDeclaredMethod (obj
->getClass (), id
->name
, id
->signature
);
906 jclass decl_class
= klass
? klass
: obj
->getClass ();
907 JvAssert (decl_class
!= NULL
);
910 JArray
<jclass
> *arg_types
;
913 _Jv_GetTypesFromSignature (id
, decl_class
,
914 &arg_types
, &return_type
);
916 // Unwrap arguments as required. Eww.
917 jclass
*type_elts
= elements (arg_types
);
918 jvalue arg_copy
[arg_types
->length
];
919 for (int i
= 0; i
< arg_types
->length
; ++i
)
921 if (type_elts
[i
]->isPrimitive ())
922 arg_copy
[i
] = args
[i
];
924 arg_copy
[i
].l
= unwrap (args
[i
].l
);
927 jthrowable ex
= _Jv_CallAnyMethodA (obj
, return_type
, id
,
928 style
== constructor
,
929 arg_types
, args
, NULL
);
940 // Functions with this signature are used to implement functions in
941 // the CallMethod family.
944 _Jv_JNI_CallMethodV (JNIEnv
*env
, jobject obj
, jmethodID id
, va_list args
)
946 return _Jv_JNI_CallAnyMethodV
<T
, normal
> (env
, obj
, NULL
, id
, args
);
949 // Functions with this signature are used to implement functions in
950 // the CallMethod family.
953 _Jv_JNI_CallMethod (JNIEnv
*env
, jobject obj
, jmethodID id
, ...)
959 result
= _Jv_JNI_CallAnyMethodV
<T
, normal
> (env
, obj
, NULL
, id
, args
);
965 // Functions with this signature are used to implement functions in
966 // the CallMethod family.
969 _Jv_JNI_CallMethodA (JNIEnv
*env
, jobject obj
, jmethodID id
, jvalue
*args
)
971 return _Jv_JNI_CallAnyMethodA
<T
, normal
> (env
, obj
, NULL
, id
, args
);
975 _Jv_JNI_CallVoidMethodV (JNIEnv
*env
, jobject obj
, jmethodID id
, va_list args
)
977 _Jv_JNI_CallAnyVoidMethodV
<normal
> (env
, obj
, NULL
, id
, args
);
981 _Jv_JNI_CallVoidMethod (JNIEnv
*env
, jobject obj
, jmethodID id
, ...)
986 _Jv_JNI_CallAnyVoidMethodV
<normal
> (env
, obj
, NULL
, id
, args
);
991 _Jv_JNI_CallVoidMethodA (JNIEnv
*env
, jobject obj
, jmethodID id
, jvalue
*args
)
993 _Jv_JNI_CallAnyVoidMethodA
<normal
> (env
, obj
, NULL
, id
, args
);
996 // Functions with this signature are used to implement functions in
997 // the CallStaticMethod family.
1000 _Jv_JNI_CallStaticMethodV (JNIEnv
*env
, jclass klass
,
1001 jmethodID id
, va_list args
)
1003 JvAssert (((id
->accflags
) & java::lang::reflect::Modifier::STATIC
));
1004 JvAssert (java::lang::Class::class$
.isInstance (unwrap (klass
)));
1006 return _Jv_JNI_CallAnyMethodV
<T
, static_type
> (env
, NULL
, klass
, id
, args
);
1009 // Functions with this signature are used to implement functions in
1010 // the CallStaticMethod family.
1011 template<typename T
>
1013 _Jv_JNI_CallStaticMethod (JNIEnv
*env
, jclass klass
, jmethodID id
, ...)
1018 JvAssert (((id
->accflags
) & java::lang::reflect::Modifier::STATIC
));
1019 JvAssert (java::lang::Class::class$
.isInstance (unwrap (klass
)));
1021 va_start (args
, id
);
1022 result
= _Jv_JNI_CallAnyMethodV
<T
, static_type
> (env
, NULL
, klass
,
1029 // Functions with this signature are used to implement functions in
1030 // the CallStaticMethod family.
1031 template<typename T
>
1033 _Jv_JNI_CallStaticMethodA (JNIEnv
*env
, jclass klass
, jmethodID id
,
1036 JvAssert (((id
->accflags
) & java::lang::reflect::Modifier::STATIC
));
1037 JvAssert (java::lang::Class::class$
.isInstance (unwrap (klass
)));
1039 return _Jv_JNI_CallAnyMethodA
<T
, static_type
> (env
, NULL
, klass
, id
, args
);
1043 _Jv_JNI_CallStaticVoidMethodV (JNIEnv
*env
, jclass klass
, jmethodID id
,
1046 _Jv_JNI_CallAnyVoidMethodV
<static_type
> (env
, NULL
, klass
, id
, args
);
1050 _Jv_JNI_CallStaticVoidMethod (JNIEnv
*env
, jclass klass
, jmethodID id
, ...)
1054 va_start (args
, id
);
1055 _Jv_JNI_CallAnyVoidMethodV
<static_type
> (env
, NULL
, klass
, id
, args
);
1060 _Jv_JNI_CallStaticVoidMethodA (JNIEnv
*env
, jclass klass
, jmethodID id
,
1063 _Jv_JNI_CallAnyVoidMethodA
<static_type
> (env
, NULL
, klass
, id
, args
);
1067 _Jv_JNI_NewObjectV (JNIEnv
*env
, jclass klass
,
1068 jmethodID id
, va_list args
)
1070 JvAssert (klass
&& ! klass
->isArray ());
1071 JvAssert (! strcmp (id
->name
->data
, "<init>")
1072 && id
->signature
->length
> 2
1073 && id
->signature
->data
[0] == '('
1074 && ! strcmp (&id
->signature
->data
[id
->signature
->length
- 2],
1077 return _Jv_JNI_CallAnyMethodV
<jobject
, constructor
> (env
, NULL
, klass
,
1082 _Jv_JNI_NewObject (JNIEnv
*env
, jclass klass
, jmethodID id
, ...)
1084 JvAssert (klass
&& ! klass
->isArray ());
1085 JvAssert (! strcmp (id
->name
->data
, "<init>")
1086 && id
->signature
->length
> 2
1087 && id
->signature
->data
[0] == '('
1088 && ! strcmp (&id
->signature
->data
[id
->signature
->length
- 2],
1094 va_start (args
, id
);
1095 result
= _Jv_JNI_CallAnyMethodV
<jobject
, constructor
> (env
, NULL
, klass
,
1103 _Jv_JNI_NewObjectA (JNIEnv
*env
, jclass klass
, jmethodID id
,
1106 JvAssert (klass
&& ! klass
->isArray ());
1107 JvAssert (! strcmp (id
->name
->data
, "<init>")
1108 && id
->signature
->length
> 2
1109 && id
->signature
->data
[0] == '('
1110 && ! strcmp (&id
->signature
->data
[id
->signature
->length
- 2],
1113 return _Jv_JNI_CallAnyMethodA
<jobject
, constructor
> (env
, NULL
, klass
,
1119 template<typename T
>
1121 _Jv_JNI_GetField (JNIEnv
*env
, jobject obj
, jfieldID field
)
1125 T
*ptr
= (T
*) ((char *) obj
+ field
->getOffset ());
1126 return wrap_value (env
, *ptr
);
1129 template<typename T
>
1131 _Jv_JNI_SetField (JNIEnv
*, jobject obj
, jfieldID field
, T value
)
1134 value
= unwrap (value
);
1137 T
*ptr
= (T
*) ((char *) obj
+ field
->getOffset ());
1141 template<jboolean is_static
>
1143 _Jv_JNI_GetAnyFieldID (JNIEnv
*env
, jclass clazz
,
1144 const char *name
, const char *sig
)
1148 clazz
= unwrap (clazz
);
1150 _Jv_InitClass (clazz
);
1152 _Jv_Utf8Const
*a_name
= _Jv_makeUtf8Const ((char *) name
, -1);
1154 // FIXME: assume that SIG isn't too long.
1155 int len
= strlen (sig
);
1157 for (int i
= 0; i
<= len
; ++i
)
1158 s
[i
] = (sig
[i
] == '/') ? '.' : sig
[i
];
1159 jclass field_class
= _Jv_FindClassFromSignature ((char *) s
, NULL
);
1161 // FIXME: what if field_class == NULL?
1163 java::lang::ClassLoader
*loader
= clazz
->getClassLoader ();
1164 while (clazz
!= NULL
)
1166 // We acquire the class lock so that fields aren't resolved
1167 // while we are running.
1168 JvSynchronize
sync (clazz
);
1170 jint count
= (is_static
1171 ? JvNumStaticFields (clazz
)
1172 : JvNumInstanceFields (clazz
));
1173 jfieldID field
= (is_static
1174 ? JvGetFirstStaticField (clazz
)
1175 : JvGetFirstInstanceField (clazz
));
1176 for (jint i
= 0; i
< count
; ++i
)
1178 _Jv_Utf8Const
*f_name
= field
->getNameUtf8Const(clazz
);
1180 // The field might be resolved or it might not be. It
1181 // is much simpler to always resolve it.
1182 _Jv_ResolveField (field
, loader
);
1183 if (_Jv_equalUtf8Consts (f_name
, a_name
)
1184 && field
->getClass() == field_class
)
1187 field
= field
->getNextField ();
1190 clazz
= clazz
->getSuperclass ();
1193 env
->ex
= new java::lang::NoSuchFieldError ();
1195 catch (jthrowable t
)
1202 template<typename T
>
1204 _Jv_JNI_GetStaticField (JNIEnv
*env
, jclass
, jfieldID field
)
1206 T
*ptr
= (T
*) field
->u
.addr
;
1207 return wrap_value (env
, *ptr
);
1210 template<typename T
>
1212 _Jv_JNI_SetStaticField (JNIEnv
*, jclass
, jfieldID field
, T value
)
1214 value
= unwrap (value
);
1215 T
*ptr
= (T
*) field
->u
.addr
;
1220 _Jv_JNI_NewString (JNIEnv
*env
, const jchar
*unichars
, jsize len
)
1224 jstring r
= _Jv_NewString (unichars
, len
);
1225 return (jstring
) wrap_value (env
, r
);
1227 catch (jthrowable t
)
1235 _Jv_JNI_GetStringLength (JNIEnv
*, jstring string
)
1237 return unwrap (string
)->length();
1240 static const jchar
*
1241 _Jv_JNI_GetStringChars (JNIEnv
*, jstring string
, jboolean
*isCopy
)
1243 string
= unwrap (string
);
1244 jchar
*result
= _Jv_GetStringChars (string
);
1245 mark_for_gc (string
, global_ref_table
);
1248 return (const jchar
*) result
;
1252 _Jv_JNI_ReleaseStringChars (JNIEnv
*, jstring string
, const jchar
*)
1254 unmark_for_gc (unwrap (string
), global_ref_table
);
1258 _Jv_JNI_NewStringUTF (JNIEnv
*env
, const char *bytes
)
1262 jstring result
= JvNewStringUTF (bytes
);
1263 return (jstring
) wrap_value (env
, result
);
1265 catch (jthrowable t
)
1273 _Jv_JNI_GetStringUTFLength (JNIEnv
*, jstring string
)
1275 return JvGetStringUTFLength (unwrap (string
));
1279 _Jv_JNI_GetStringUTFChars (JNIEnv
*env
, jstring string
, jboolean
*isCopy
)
1281 string
= unwrap (string
);
1282 jsize len
= JvGetStringUTFLength (string
);
1285 char *r
= (char *) _Jv_Malloc (len
+ 1);
1286 JvGetStringUTFRegion (string
, 0, len
, r
);
1292 return (const char *) r
;
1294 catch (jthrowable t
)
1302 _Jv_JNI_ReleaseStringUTFChars (JNIEnv
*, jstring
, const char *utf
)
1304 _Jv_Free ((void *) utf
);
1308 _Jv_JNI_GetStringRegion (JNIEnv
*env
, jstring string
, jsize start
, jsize len
,
1311 string
= unwrap (string
);
1312 jchar
*result
= _Jv_GetStringChars (string
);
1313 if (start
< 0 || start
> string
->length ()
1314 || len
< 0 || start
+ len
> string
->length ())
1318 env
->ex
= new java::lang::StringIndexOutOfBoundsException ();
1320 catch (jthrowable t
)
1326 memcpy (buf
, &result
[start
], len
* sizeof (jchar
));
1330 _Jv_JNI_GetStringUTFRegion (JNIEnv
*env
, jstring str
, jsize start
,
1331 jsize len
, char *buf
)
1335 if (start
< 0 || start
> str
->length ()
1336 || len
< 0 || start
+ len
> str
->length ())
1340 env
->ex
= new java::lang::StringIndexOutOfBoundsException ();
1342 catch (jthrowable t
)
1348 _Jv_GetStringUTFRegion (str
, start
, len
, buf
);
1351 static const jchar
*
1352 _Jv_JNI_GetStringCritical (JNIEnv
*, jstring str
, jboolean
*isCopy
)
1354 jchar
*result
= _Jv_GetStringChars (unwrap (str
));
1361 _Jv_JNI_ReleaseStringCritical (JNIEnv
*, jstring
, const jchar
*)
1367 _Jv_JNI_GetArrayLength (JNIEnv
*, jarray array
)
1369 return unwrap (array
)->length
;
1373 _Jv_JNI_NewObjectArray (JNIEnv
*env
, jsize length
, jclass elementClass
,
1378 elementClass
= unwrap (elementClass
);
1379 init
= unwrap (init
);
1381 jarray result
= JvNewObjectArray (length
, elementClass
, init
);
1382 return (jarray
) wrap_value (env
, result
);
1384 catch (jthrowable t
)
1392 _Jv_JNI_GetObjectArrayElement (JNIEnv
*env
, jobjectArray array
, jsize index
)
1394 jobject
*elts
= elements (unwrap (array
));
1395 return wrap_value (env
, elts
[index
]);
1399 _Jv_JNI_SetObjectArrayElement (JNIEnv
*env
, jobjectArray array
, jsize index
,
1404 array
= unwrap (array
);
1405 value
= unwrap (value
);
1407 _Jv_CheckArrayStore (array
, value
);
1408 jobject
*elts
= elements (array
);
1409 elts
[index
] = value
;
1411 catch (jthrowable t
)
1417 template<typename T
, jclass K
>
1419 _Jv_JNI_NewPrimitiveArray (JNIEnv
*env
, jsize length
)
1423 return (JArray
<T
> *) wrap_value (env
, _Jv_NewPrimArray (K
, length
));
1425 catch (jthrowable t
)
1432 template<typename T
>
1434 _Jv_JNI_GetPrimitiveArrayElements (JNIEnv
*, JArray
<T
> *array
,
1437 array
= unwrap (array
);
1438 T
*elts
= elements (array
);
1441 // We elect never to copy.
1444 mark_for_gc (array
, global_ref_table
);
1448 template<typename T
>
1450 _Jv_JNI_ReleasePrimitiveArrayElements (JNIEnv
*, JArray
<T
> *array
,
1451 T
*, jint
/* mode */)
1453 array
= unwrap (array
);
1454 // Note that we ignore MODE. We can do this because we never copy
1455 // the array elements. My reading of the JNI documentation is that
1456 // this is an option for the implementor.
1457 unmark_for_gc (array
, global_ref_table
);
1460 template<typename T
>
1462 _Jv_JNI_GetPrimitiveArrayRegion (JNIEnv
*env
, JArray
<T
> *array
,
1463 jsize start
, jsize len
,
1466 array
= unwrap (array
);
1468 // The cast to unsigned lets us save a comparison.
1469 if (start
< 0 || len
< 0
1470 || (unsigned long) (start
+ len
) > (unsigned long) array
->length
)
1475 env
->ex
= new java::lang::ArrayIndexOutOfBoundsException ();
1477 catch (jthrowable t
)
1479 // Could have thown out of memory error.
1485 T
*elts
= elements (array
) + start
;
1486 memcpy (buf
, elts
, len
* sizeof (T
));
1490 template<typename T
>
1492 _Jv_JNI_SetPrimitiveArrayRegion (JNIEnv
*env
, JArray
<T
> *array
,
1493 jsize start
, jsize len
, T
*buf
)
1495 array
= unwrap (array
);
1497 // The cast to unsigned lets us save a comparison.
1498 if (start
< 0 || len
< 0
1499 || (unsigned long) (start
+ len
) > (unsigned long) array
->length
)
1504 env
->ex
= new java::lang::ArrayIndexOutOfBoundsException ();
1506 catch (jthrowable t
)
1513 T
*elts
= elements (array
) + start
;
1514 memcpy (elts
, buf
, len
* sizeof (T
));
1519 _Jv_JNI_GetPrimitiveArrayCritical (JNIEnv
*, jarray array
,
1522 array
= unwrap (array
);
1523 // FIXME: does this work?
1524 jclass klass
= array
->getClass()->getComponentType();
1525 JvAssert (klass
->isPrimitive ());
1526 char *r
= _Jv_GetArrayElementFromElementType (array
, klass
);
1533 _Jv_JNI_ReleasePrimitiveArrayCritical (JNIEnv
*, jarray
, void *, jint
)
1539 _Jv_JNI_MonitorEnter (JNIEnv
*env
, jobject obj
)
1543 _Jv_MonitorEnter (unwrap (obj
));
1546 catch (jthrowable t
)
1554 _Jv_JNI_MonitorExit (JNIEnv
*env
, jobject obj
)
1558 _Jv_MonitorExit (unwrap (obj
));
1561 catch (jthrowable t
)
1570 _Jv_JNI_ToReflectedField (JNIEnv
*env
, jclass cls
, jfieldID fieldID
,
1576 java::lang::reflect::Field
*field
= new java::lang::reflect::Field();
1577 field
->declaringClass
= cls
;
1578 field
->offset
= (char*) fieldID
- (char *) cls
->fields
;
1579 field
->name
= _Jv_NewStringUtf8Const (fieldID
->getNameUtf8Const (cls
));
1580 return wrap_value (env
, field
);
1582 catch (jthrowable t
)
1591 _Jv_JNI_FromReflectedField (JNIEnv
*, jobject f
)
1593 using namespace java::lang::reflect
;
1596 Field
*field
= reinterpret_cast<Field
*> (f
);
1597 return _Jv_FromReflectedField (field
);
1601 _Jv_JNI_ToReflectedMethod (JNIEnv
*env
, jclass klass
, jmethodID id
,
1604 using namespace java::lang::reflect
;
1606 jobject result
= NULL
;
1607 klass
= unwrap (klass
);
1611 if (_Jv_equalUtf8Consts (id
->name
, init_name
))
1614 Constructor
*cons
= new Constructor ();
1615 cons
->offset
= (char *) id
- (char *) &klass
->methods
;
1616 cons
->declaringClass
= klass
;
1621 Method
*meth
= new Method ();
1622 meth
->offset
= (char *) id
- (char *) &klass
->methods
;
1623 meth
->declaringClass
= klass
;
1627 catch (jthrowable t
)
1632 return wrap_value (env
, result
);
1636 _Jv_JNI_FromReflectedMethod (JNIEnv
*, jobject method
)
1638 using namespace java::lang::reflect
;
1639 method
= unwrap (method
);
1640 if (Method::class$
.isInstance (method
))
1641 return _Jv_FromReflectedMethod (reinterpret_cast<Method
*> (method
));
1643 _Jv_FromReflectedConstructor (reinterpret_cast<Constructor
*> (method
));
1648 _Jv_JNI_NewWeakGlobalRef (JNIEnv
*env
, jobject obj
)
1650 using namespace gnu::gcj::runtime
;
1651 JNIWeakRef
*ref
= NULL
;
1655 // This seems weird but I think it is correct.
1657 ref
= new JNIWeakRef (obj
);
1658 mark_for_gc (ref
, global_ref_table
);
1660 catch (jthrowable t
)
1665 return reinterpret_cast<jweak
> (ref
);
1669 _Jv_JNI_DeleteWeakGlobalRef (JNIEnv
*, jweak obj
)
1671 using namespace gnu::gcj::runtime
;
1672 JNIWeakRef
*ref
= reinterpret_cast<JNIWeakRef
*> (obj
);
1673 unmark_for_gc (ref
, global_ref_table
);
1679 // Hash table of native methods.
1680 static JNINativeMethod
*nathash
;
1681 // Number of slots used.
1682 static int nathash_count
= 0;
1683 // Number of slots available. Must be power of 2.
1684 static int nathash_size
= 0;
1686 #define DELETED_ENTRY ((char *) (~0))
1688 // Compute a hash value for a native method descriptor.
1690 hash (const JNINativeMethod
*method
)
1697 hash
= (31 * hash
) + *ptr
++;
1699 ptr
= method
->signature
;
1701 hash
= (31 * hash
) + *ptr
++;
1706 // Find the slot where a native method goes.
1707 static JNINativeMethod
*
1708 nathash_find_slot (const JNINativeMethod
*method
)
1710 jint h
= hash (method
);
1711 int step
= (h
^ (h
>> 16)) | 1;
1712 int w
= h
& (nathash_size
- 1);
1717 JNINativeMethod
*slotp
= &nathash
[w
];
1718 if (slotp
->name
== NULL
)
1721 return &nathash
[del
];
1725 else if (slotp
->name
== DELETED_ENTRY
)
1727 else if (! strcmp (slotp
->name
, method
->name
)
1728 && ! strcmp (slotp
->signature
, method
->signature
))
1730 w
= (w
+ step
) & (nathash_size
- 1);
1734 // Find a method. Return NULL if it isn't in the hash table.
1736 nathash_find (JNINativeMethod
*method
)
1738 if (nathash
== NULL
)
1740 JNINativeMethod
*slot
= nathash_find_slot (method
);
1741 if (slot
->name
== NULL
|| slot
->name
== DELETED_ENTRY
)
1749 if (nathash
== NULL
)
1751 nathash_size
= 1024;
1753 (JNINativeMethod
*) _Jv_AllocBytes (nathash_size
1754 * sizeof (JNINativeMethod
));
1755 memset (nathash
, 0, nathash_size
* sizeof (JNINativeMethod
));
1759 int savesize
= nathash_size
;
1760 JNINativeMethod
*savehash
= nathash
;
1763 (JNINativeMethod
*) _Jv_AllocBytes (nathash_size
1764 * sizeof (JNINativeMethod
));
1765 memset (nathash
, 0, nathash_size
* sizeof (JNINativeMethod
));
1767 for (int i
= 0; i
< savesize
; ++i
)
1769 if (savehash
[i
].name
!= NULL
&& savehash
[i
].name
!= DELETED_ENTRY
)
1771 JNINativeMethod
*slot
= nathash_find_slot (&savehash
[i
]);
1772 *slot
= savehash
[i
];
1779 nathash_add (const JNINativeMethod
*method
)
1781 if (3 * nathash_count
>= 2 * nathash_size
)
1783 JNINativeMethod
*slot
= nathash_find_slot (method
);
1784 // If the slot has a real entry in it, then there is no work to do.
1785 if (slot
->name
!= NULL
&& slot
->name
!= DELETED_ENTRY
)
1788 slot
->name
= strdup (method
->name
);
1789 slot
->signature
= strdup (method
->signature
);
1790 slot
->fnPtr
= method
->fnPtr
;
1794 _Jv_JNI_RegisterNatives (JNIEnv
*env
, jclass klass
,
1795 const JNINativeMethod
*methods
,
1798 // Synchronize while we do the work. This must match
1799 // synchronization in some other functions that manipulate or use
1800 // the nathash table.
1801 JvSynchronize
sync (global_ref_table
);
1803 // Look at each descriptor given us, and find the corresponding
1804 // method in the class.
1805 for (int j
= 0; j
< nMethods
; ++j
)
1809 _Jv_Method
*imeths
= JvGetFirstMethod (klass
);
1810 for (int i
= 0; i
< JvNumMethods (klass
); ++i
)
1812 _Jv_Method
*self
= &imeths
[i
];
1814 if (! strcmp (self
->name
->data
, methods
[j
].name
)
1815 && ! strcmp (self
->signature
->data
, methods
[j
].signature
))
1817 if (! (self
->accflags
1818 & java::lang::reflect::Modifier::NATIVE
))
1821 // Found a match that is native.
1823 nathash_add (&methods
[j
]);
1831 jstring m
= JvNewStringUTF (methods
[j
].name
);
1834 env
->ex
=new java::lang::NoSuchMethodError (m
);
1836 catch (jthrowable t
)
1848 _Jv_JNI_UnregisterNatives (JNIEnv
*, jclass
)
1850 // FIXME -- we could implement this.
1856 // Add a character to the buffer, encoding properly.
1858 add_char (char *buf
, jchar c
, int *here
)
1862 buf
[(*here
)++] = '_';
1863 buf
[(*here
)++] = '1';
1867 buf
[(*here
)++] = '_';
1868 buf
[(*here
)++] = '2';
1872 buf
[(*here
)++] = '_';
1873 buf
[(*here
)++] = '3';
1876 // Also check for `.' here because we might be passed an internal
1877 // qualified class name like `foo.bar'.
1878 else if (c
== '/' || c
== '.')
1879 buf
[(*here
)++] = '_';
1880 else if ((c
>= '0' && c
<= '9')
1881 || (c
>= 'a' && c
<= 'z')
1882 || (c
>= 'A' && c
<= 'Z'))
1883 buf
[(*here
)++] = (char) c
;
1886 // "Unicode" character.
1887 buf
[(*here
)++] = '_';
1888 buf
[(*here
)++] = '0';
1889 for (int i
= 0; i
< 4; ++i
)
1892 buf
[(*here
) + 3 - i
] = (val
> 10) ? ('a' + val
- 10) : ('0' + val
);
1899 // Compute a mangled name for a native function. This computes the
1900 // long name, and also returns an index which indicates where a NUL
1901 // can be placed to create the short name. This function assumes that
1902 // the buffer is large enough for its results.
1904 mangled_name (jclass klass
, _Jv_Utf8Const
*func_name
,
1905 _Jv_Utf8Const
*signature
, char *buf
, int *long_start
)
1907 strcpy (buf
, "Java_");
1910 // Add fully qualified class name.
1911 jchar
*chars
= _Jv_GetStringChars (klass
->getName ());
1912 jint len
= klass
->getName ()->length ();
1913 for (int i
= 0; i
< len
; ++i
)
1914 add_char (buf
, chars
[i
], &here
);
1916 // Don't use add_char because we need a literal `_'.
1919 const unsigned char *fn
= (const unsigned char *) func_name
->data
;
1920 const unsigned char *limit
= fn
+ func_name
->length
;
1921 for (int i
= 0; ; ++i
)
1923 int ch
= UTF8_GET (fn
, limit
);
1926 add_char (buf
, ch
, &here
);
1929 // This is where the long signature begins.
1934 const unsigned char *sig
= (const unsigned char *) signature
->data
;
1935 limit
= sig
+ signature
->length
;
1936 JvAssert (sig
[0] == '(');
1940 int ch
= UTF8_GET (sig
, limit
);
1941 if (ch
== ')' || ch
< 0)
1943 add_char (buf
, ch
, &here
);
1949 // Return the current thread's JNIEnv; if one does not exist, create
1950 // it. Also create a new system frame for use. This is `extern "C"'
1951 // because the compiler calls it.
1953 _Jv_GetJNIEnvNewFrame (jclass klass
)
1955 JNIEnv
*env
= _Jv_GetCurrentJNIEnv ();
1958 env
= (JNIEnv
*) _Jv_MallocUnchecked (sizeof (JNIEnv
));
1959 env
->p
= &_Jv_JNIFunctions
;
1964 _Jv_SetCurrentJNIEnv (env
);
1967 _Jv_JNI_LocalFrame
*frame
1968 = (_Jv_JNI_LocalFrame
*) _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame
)
1970 * sizeof (jobject
)));
1972 frame
->marker
= MARK_SYSTEM
;
1973 frame
->size
= FRAME_SIZE
;
1974 frame
->next
= env
->locals
;
1975 env
->locals
= frame
;
1977 for (int i
= 0; i
< frame
->size
; ++i
)
1978 frame
->vec
[i
] = NULL
;
1983 // Return the function which implements a particular JNI method. If
1984 // we can't find the function, we throw the appropriate exception.
1985 // This is `extern "C"' because the compiler uses it.
1987 _Jv_LookupJNIMethod (jclass klass
, _Jv_Utf8Const
*name
,
1988 _Jv_Utf8Const
*signature
)
1990 char buf
[10 + 6 * (name
->length
+ signature
->length
)];
1994 // Synchronize on something convenient. Right now we use the hash.
1995 JvSynchronize
sync (global_ref_table
);
1997 // First see if we have an override in the hash table.
1998 strncpy (buf
, name
->data
, name
->length
);
1999 buf
[name
->length
] = '\0';
2000 strncpy (buf
+ name
->length
+ 1, signature
->data
, signature
->length
);
2001 buf
[name
->length
+ signature
->length
+ 1] = '\0';
2002 JNINativeMethod meth
;
2004 meth
.signature
= buf
+ name
->length
+ 1;
2005 function
= nathash_find (&meth
);
2006 if (function
!= NULL
)
2009 // If there was no override, then look in the symbol table.
2010 mangled_name (klass
, name
, signature
, buf
, &long_start
);
2011 char c
= buf
[long_start
];
2012 buf
[long_start
] = '\0';
2013 function
= _Jv_FindSymbolInExecutable (buf
);
2014 if (function
== NULL
)
2016 buf
[long_start
] = c
;
2017 function
= _Jv_FindSymbolInExecutable (buf
);
2018 if (function
== NULL
)
2020 jstring str
= JvNewStringUTF (name
->data
);
2021 throw new java::lang::AbstractMethodError (str
);
2030 // This function is the stub which is used to turn an ordinary (CNI)
2031 // method call into a JNI call.
2033 _Jv_JNIMethod::call (ffi_cif
*, void *ret
, ffi_raw
*args
, void *__this
)
2035 _Jv_JNIMethod
* _this
= (_Jv_JNIMethod
*) __this
;
2037 JNIEnv
*env
= _Jv_GetJNIEnvNewFrame (_this
->defining_class
);
2039 // FIXME: we should mark every reference parameter as a local. For
2040 // now we assume a conservative GC, and we assume that the
2041 // references are on the stack somewhere.
2043 // We cache the value that we find, of course, but if we don't find
2044 // a value we don't cache that fact -- we might subsequently load a
2045 // library which finds the function in question.
2047 // Synchronize on a convenient object to ensure sanity in case two
2048 // threads reach this point for the same function at the same
2050 JvSynchronize
sync (global_ref_table
);
2051 if (_this
->function
== NULL
)
2052 _this
->function
= _Jv_LookupJNIMethod (_this
->defining_class
,
2054 _this
->self
->signature
);
2057 JvAssert (_this
->args_raw_size
% sizeof (ffi_raw
) == 0);
2058 ffi_raw real_args
[2 + _this
->args_raw_size
/ sizeof (ffi_raw
)];
2061 // First argument is always the environment pointer.
2062 real_args
[offset
++].ptr
= env
;
2064 // For a static method, we pass in the Class. For non-static
2065 // methods, the `this' argument is already handled.
2066 if ((_this
->self
->accflags
& java::lang::reflect::Modifier::STATIC
))
2067 real_args
[offset
++].ptr
= _this
->defining_class
;
2069 // Copy over passed-in arguments.
2070 memcpy (&real_args
[offset
], args
, _this
->args_raw_size
);
2072 // The actual call to the JNI function.
2073 ffi_raw_call (&_this
->jni_cif
, (void (*)()) _this
->function
,
2076 _Jv_JNI_PopSystemFrame (env
);
2079 #endif /* INTERPRETER */
2087 // An internal helper function.
2089 _Jv_JNI_AttachCurrentThread (JavaVM
*, jstring name
, void **penv
, void *args
)
2091 JavaVMAttachArgs
*attach
= reinterpret_cast<JavaVMAttachArgs
*> (args
);
2092 java::lang::ThreadGroup
*group
= NULL
;
2096 // FIXME: do we really want to support 1.1?
2097 if (attach
->version
!= JNI_VERSION_1_2
2098 && attach
->version
!= JNI_VERSION_1_1
)
2099 return JNI_EVERSION
;
2101 JvAssert (java::lang::ThreadGroup::class$
.isInstance (attach
->group
));
2102 group
= reinterpret_cast<java::lang::ThreadGroup
*> (attach
->group
);
2105 // Attaching an already-attached thread is a no-op.
2106 if (_Jv_GetCurrentJNIEnv () != NULL
)
2109 JNIEnv
*env
= (JNIEnv
*) _Jv_MallocUnchecked (sizeof (JNIEnv
));
2112 env
->p
= &_Jv_JNIFunctions
;
2116 = (_Jv_JNI_LocalFrame
*) _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame
)
2118 * sizeof (jobject
)));
2119 if (env
->locals
== NULL
)
2124 *penv
= reinterpret_cast<void *> (env
);
2126 // This thread might already be a Java thread -- this function might
2127 // have been called simply to set the new JNIEnv.
2128 if (_Jv_ThreadCurrent () == NULL
)
2132 _Jv_AttachCurrentThread (name
, group
);
2134 catch (jthrowable t
)
2139 _Jv_SetCurrentJNIEnv (env
);
2144 // This is the one actually used by JNI.
2146 _Jv_JNI_AttachCurrentThread (JavaVM
*vm
, void **penv
, void *args
)
2148 return _Jv_JNI_AttachCurrentThread (vm
, NULL
, penv
, args
);
2152 _Jv_JNI_DestroyJavaVM (JavaVM
*vm
)
2154 JvAssert (the_vm
&& vm
== the_vm
);
2157 if (_Jv_ThreadCurrent () != NULL
)
2163 main_name
= JvNewStringLatin1 ("main");
2165 catch (jthrowable t
)
2170 jint r
= _Jv_JNI_AttachCurrentThread (vm
,
2172 reinterpret_cast<void **> (&env
),
2178 env
= _Jv_GetCurrentJNIEnv ();
2182 // Docs say that this always returns an error code.
2187 _Jv_JNI_DetachCurrentThread (JavaVM
*)
2189 jint code
= _Jv_DetachCurrentThread ();
2190 return code
? JNI_EDETACHED
: 0;
2194 _Jv_JNI_GetEnv (JavaVM
*, void **penv
, jint version
)
2196 if (_Jv_ThreadCurrent () == NULL
)
2199 return JNI_EDETACHED
;
2203 // Handle JVMPI requests.
2204 if (version
== JVMPI_VERSION_1
)
2206 *penv
= (void *) &_Jv_JVMPI_Interface
;
2211 // FIXME: do we really want to support 1.1?
2212 if (version
!= JNI_VERSION_1_2
&& version
!= JNI_VERSION_1_1
)
2215 return JNI_EVERSION
;
2218 *penv
= (void *) _Jv_GetCurrentJNIEnv ();
2223 JNI_GetDefaultJavaVMInitArgs (void *args
)
2225 jint version
= * (jint
*) args
;
2226 // Here we only support 1.2.
2227 if (version
!= JNI_VERSION_1_2
)
2228 return JNI_EVERSION
;
2230 JavaVMInitArgs
*ia
= reinterpret_cast<JavaVMInitArgs
*> (args
);
2231 ia
->version
= JNI_VERSION_1_2
;
2234 ia
->ignoreUnrecognized
= true;
2240 JNI_CreateJavaVM (JavaVM
**vm
, void **penv
, void *args
)
2242 JvAssert (! the_vm
);
2244 _Jv_CreateJavaVM (NULL
);
2246 // FIXME: synchronize
2247 JavaVM
*nvm
= (JavaVM
*) _Jv_MallocUnchecked (sizeof (JavaVM
));
2250 nvm
->functions
= &_Jv_JNI_InvokeFunctions
;
2252 // Parse the arguments.
2255 jint version
= * (jint
*) args
;
2256 // We only support 1.2.
2257 if (version
!= JNI_VERSION_1_2
)
2258 return JNI_EVERSION
;
2259 JavaVMInitArgs
*ia
= reinterpret_cast<JavaVMInitArgs
*> (args
);
2260 for (int i
= 0; i
< ia
->nOptions
; ++i
)
2262 if (! strcmp (ia
->options
[i
].optionString
, "vfprintf")
2263 || ! strcmp (ia
->options
[i
].optionString
, "exit")
2264 || ! strcmp (ia
->options
[i
].optionString
, "abort"))
2266 // We are required to recognize these, but for now we
2267 // don't handle them in any way. FIXME.
2270 else if (! strncmp (ia
->options
[i
].optionString
,
2271 "-verbose", sizeof ("-verbose") - 1))
2273 // We don't do anything with this option either. We
2274 // might want to make sure the argument is valid, but we
2275 // don't really care all that much for now.
2278 else if (! strncmp (ia
->options
[i
].optionString
, "-D", 2))
2283 else if (ia
->ignoreUnrecognized
)
2285 if (ia
->options
[i
].optionString
[0] == '_'
2286 || ! strncmp (ia
->options
[i
].optionString
, "-X", 2))
2294 jint r
=_Jv_JNI_AttachCurrentThread (nvm
, penv
, NULL
);
2305 JNI_GetCreatedJavaVMs (JavaVM
**vm_buffer
, jsize buf_len
, jsize
*n_vms
)
2310 // We only support a single VM.
2313 vm_buffer
[0] = the_vm
;
2324 // FIXME: synchronize
2327 JavaVM
*nvm
= (JavaVM
*) _Jv_MallocUnchecked (sizeof (JavaVM
));
2329 nvm
->functions
= &_Jv_JNI_InvokeFunctions
;
2333 // If this is a Java thread, we want to make sure it has an
2334 // associated JNIEnv.
2335 if (_Jv_ThreadCurrent () != NULL
)
2338 _Jv_JNI_AttachCurrentThread (the_vm
, &ignore
, NULL
);
2345 _Jv_JNI_GetJavaVM (JNIEnv
*, JavaVM
**vm
)
2347 *vm
= _Jv_GetJavaVM ();
2348 return *vm
== NULL
? JNI_ERR
: JNI_OK
;
2353 #define RESERVED NULL
2355 struct JNINativeInterface _Jv_JNIFunctions
=
2361 _Jv_JNI_GetVersion
, // GetVersion
2362 _Jv_JNI_DefineClass
, // DefineClass
2363 _Jv_JNI_FindClass
, // FindClass
2364 _Jv_JNI_FromReflectedMethod
, // FromReflectedMethod
2365 _Jv_JNI_FromReflectedField
, // FromReflectedField
2366 _Jv_JNI_ToReflectedMethod
, // ToReflectedMethod
2367 _Jv_JNI_GetSuperclass
, // GetSuperclass
2368 _Jv_JNI_IsAssignableFrom
, // IsAssignableFrom
2369 _Jv_JNI_ToReflectedField
, // ToReflectedField
2370 _Jv_JNI_Throw
, // Throw
2371 _Jv_JNI_ThrowNew
, // ThrowNew
2372 _Jv_JNI_ExceptionOccurred
, // ExceptionOccurred
2373 _Jv_JNI_ExceptionDescribe
, // ExceptionDescribe
2374 _Jv_JNI_ExceptionClear
, // ExceptionClear
2375 _Jv_JNI_FatalError
, // FatalError
2377 _Jv_JNI_PushLocalFrame
, // PushLocalFrame
2378 _Jv_JNI_PopLocalFrame
, // PopLocalFrame
2379 _Jv_JNI_NewGlobalRef
, // NewGlobalRef
2380 _Jv_JNI_DeleteGlobalRef
, // DeleteGlobalRef
2381 _Jv_JNI_DeleteLocalRef
, // DeleteLocalRef
2383 _Jv_JNI_IsSameObject
, // IsSameObject
2385 _Jv_JNI_NewLocalRef
, // NewLocalRef
2386 _Jv_JNI_EnsureLocalCapacity
, // EnsureLocalCapacity
2388 _Jv_JNI_AllocObject
, // AllocObject
2389 _Jv_JNI_NewObject
, // NewObject
2390 _Jv_JNI_NewObjectV
, // NewObjectV
2391 _Jv_JNI_NewObjectA
, // NewObjectA
2392 _Jv_JNI_GetObjectClass
, // GetObjectClass
2393 _Jv_JNI_IsInstanceOf
, // IsInstanceOf
2394 _Jv_JNI_GetAnyMethodID
<false>, // GetMethodID
2396 _Jv_JNI_CallMethod
<jobject
>, // CallObjectMethod
2397 _Jv_JNI_CallMethodV
<jobject
>, // CallObjectMethodV
2398 _Jv_JNI_CallMethodA
<jobject
>, // CallObjectMethodA
2399 _Jv_JNI_CallMethod
<jboolean
>, // CallBooleanMethod
2400 _Jv_JNI_CallMethodV
<jboolean
>, // CallBooleanMethodV
2401 _Jv_JNI_CallMethodA
<jboolean
>, // CallBooleanMethodA
2402 _Jv_JNI_CallMethod
<jbyte
>, // CallByteMethod
2403 _Jv_JNI_CallMethodV
<jbyte
>, // CallByteMethodV
2404 _Jv_JNI_CallMethodA
<jbyte
>, // CallByteMethodA
2405 _Jv_JNI_CallMethod
<jchar
>, // CallCharMethod
2406 _Jv_JNI_CallMethodV
<jchar
>, // CallCharMethodV
2407 _Jv_JNI_CallMethodA
<jchar
>, // CallCharMethodA
2408 _Jv_JNI_CallMethod
<jshort
>, // CallShortMethod
2409 _Jv_JNI_CallMethodV
<jshort
>, // CallShortMethodV
2410 _Jv_JNI_CallMethodA
<jshort
>, // CallShortMethodA
2411 _Jv_JNI_CallMethod
<jint
>, // CallIntMethod
2412 _Jv_JNI_CallMethodV
<jint
>, // CallIntMethodV
2413 _Jv_JNI_CallMethodA
<jint
>, // CallIntMethodA
2414 _Jv_JNI_CallMethod
<jlong
>, // CallLongMethod
2415 _Jv_JNI_CallMethodV
<jlong
>, // CallLongMethodV
2416 _Jv_JNI_CallMethodA
<jlong
>, // CallLongMethodA
2417 _Jv_JNI_CallMethod
<jfloat
>, // CallFloatMethod
2418 _Jv_JNI_CallMethodV
<jfloat
>, // CallFloatMethodV
2419 _Jv_JNI_CallMethodA
<jfloat
>, // CallFloatMethodA
2420 _Jv_JNI_CallMethod
<jdouble
>, // CallDoubleMethod
2421 _Jv_JNI_CallMethodV
<jdouble
>, // CallDoubleMethodV
2422 _Jv_JNI_CallMethodA
<jdouble
>, // CallDoubleMethodA
2423 _Jv_JNI_CallVoidMethod
, // CallVoidMethod
2424 _Jv_JNI_CallVoidMethodV
, // CallVoidMethodV
2425 _Jv_JNI_CallVoidMethodA
, // CallVoidMethodA
2427 // Nonvirtual method invocation functions follow.
2428 _Jv_JNI_CallAnyMethod
<jobject
, nonvirtual
>, // CallNonvirtualObjectMethod
2429 _Jv_JNI_CallAnyMethodV
<jobject
, nonvirtual
>, // CallNonvirtualObjectMethodV
2430 _Jv_JNI_CallAnyMethodA
<jobject
, nonvirtual
>, // CallNonvirtualObjectMethodA
2431 _Jv_JNI_CallAnyMethod
<jboolean
, nonvirtual
>, // CallNonvirtualBooleanMethod
2432 _Jv_JNI_CallAnyMethodV
<jboolean
, nonvirtual
>, // CallNonvirtualBooleanMethodV
2433 _Jv_JNI_CallAnyMethodA
<jboolean
, nonvirtual
>, // CallNonvirtualBooleanMethodA
2434 _Jv_JNI_CallAnyMethod
<jbyte
, nonvirtual
>, // CallNonvirtualByteMethod
2435 _Jv_JNI_CallAnyMethodV
<jbyte
, nonvirtual
>, // CallNonvirtualByteMethodV
2436 _Jv_JNI_CallAnyMethodA
<jbyte
, nonvirtual
>, // CallNonvirtualByteMethodA
2437 _Jv_JNI_CallAnyMethod
<jchar
, nonvirtual
>, // CallNonvirtualCharMethod
2438 _Jv_JNI_CallAnyMethodV
<jchar
, nonvirtual
>, // CallNonvirtualCharMethodV
2439 _Jv_JNI_CallAnyMethodA
<jchar
, nonvirtual
>, // CallNonvirtualCharMethodA
2440 _Jv_JNI_CallAnyMethod
<jshort
, nonvirtual
>, // CallNonvirtualShortMethod
2441 _Jv_JNI_CallAnyMethodV
<jshort
, nonvirtual
>, // CallNonvirtualShortMethodV
2442 _Jv_JNI_CallAnyMethodA
<jshort
, nonvirtual
>, // CallNonvirtualShortMethodA
2443 _Jv_JNI_CallAnyMethod
<jint
, nonvirtual
>, // CallNonvirtualIntMethod
2444 _Jv_JNI_CallAnyMethodV
<jint
, nonvirtual
>, // CallNonvirtualIntMethodV
2445 _Jv_JNI_CallAnyMethodA
<jint
, nonvirtual
>, // CallNonvirtualIntMethodA
2446 _Jv_JNI_CallAnyMethod
<jlong
, nonvirtual
>, // CallNonvirtualLongMethod
2447 _Jv_JNI_CallAnyMethodV
<jlong
, nonvirtual
>, // CallNonvirtualLongMethodV
2448 _Jv_JNI_CallAnyMethodA
<jlong
, nonvirtual
>, // CallNonvirtualLongMethodA
2449 _Jv_JNI_CallAnyMethod
<jfloat
, nonvirtual
>, // CallNonvirtualFloatMethod
2450 _Jv_JNI_CallAnyMethodV
<jfloat
, nonvirtual
>, // CallNonvirtualFloatMethodV
2451 _Jv_JNI_CallAnyMethodA
<jfloat
, nonvirtual
>, // CallNonvirtualFloatMethodA
2452 _Jv_JNI_CallAnyMethod
<jdouble
, nonvirtual
>, // CallNonvirtualDoubleMethod
2453 _Jv_JNI_CallAnyMethodV
<jdouble
, nonvirtual
>, // CallNonvirtualDoubleMethodV
2454 _Jv_JNI_CallAnyMethodA
<jdouble
, nonvirtual
>, // CallNonvirtualDoubleMethodA
2455 _Jv_JNI_CallAnyVoidMethod
<nonvirtual
>, // CallNonvirtualVoidMethod
2456 _Jv_JNI_CallAnyVoidMethodV
<nonvirtual
>, // CallNonvirtualVoidMethodV
2457 _Jv_JNI_CallAnyVoidMethodA
<nonvirtual
>, // CallNonvirtualVoidMethodA
2459 _Jv_JNI_GetAnyFieldID
<false>, // GetFieldID
2460 _Jv_JNI_GetField
<jobject
>, // GetObjectField
2461 _Jv_JNI_GetField
<jboolean
>, // GetBooleanField
2462 _Jv_JNI_GetField
<jbyte
>, // GetByteField
2463 _Jv_JNI_GetField
<jchar
>, // GetCharField
2464 _Jv_JNI_GetField
<jshort
>, // GetShortField
2465 _Jv_JNI_GetField
<jint
>, // GetIntField
2466 _Jv_JNI_GetField
<jlong
>, // GetLongField
2467 _Jv_JNI_GetField
<jfloat
>, // GetFloatField
2468 _Jv_JNI_GetField
<jdouble
>, // GetDoubleField
2469 _Jv_JNI_SetField
, // SetObjectField
2470 _Jv_JNI_SetField
, // SetBooleanField
2471 _Jv_JNI_SetField
, // SetByteField
2472 _Jv_JNI_SetField
, // SetCharField
2473 _Jv_JNI_SetField
, // SetShortField
2474 _Jv_JNI_SetField
, // SetIntField
2475 _Jv_JNI_SetField
, // SetLongField
2476 _Jv_JNI_SetField
, // SetFloatField
2477 _Jv_JNI_SetField
, // SetDoubleField
2478 _Jv_JNI_GetAnyMethodID
<true>, // GetStaticMethodID
2480 _Jv_JNI_CallStaticMethod
<jobject
>, // CallStaticObjectMethod
2481 _Jv_JNI_CallStaticMethodV
<jobject
>, // CallStaticObjectMethodV
2482 _Jv_JNI_CallStaticMethodA
<jobject
>, // CallStaticObjectMethodA
2483 _Jv_JNI_CallStaticMethod
<jboolean
>, // CallStaticBooleanMethod
2484 _Jv_JNI_CallStaticMethodV
<jboolean
>, // CallStaticBooleanMethodV
2485 _Jv_JNI_CallStaticMethodA
<jboolean
>, // CallStaticBooleanMethodA
2486 _Jv_JNI_CallStaticMethod
<jbyte
>, // CallStaticByteMethod
2487 _Jv_JNI_CallStaticMethodV
<jbyte
>, // CallStaticByteMethodV
2488 _Jv_JNI_CallStaticMethodA
<jbyte
>, // CallStaticByteMethodA
2489 _Jv_JNI_CallStaticMethod
<jchar
>, // CallStaticCharMethod
2490 _Jv_JNI_CallStaticMethodV
<jchar
>, // CallStaticCharMethodV
2491 _Jv_JNI_CallStaticMethodA
<jchar
>, // CallStaticCharMethodA
2492 _Jv_JNI_CallStaticMethod
<jshort
>, // CallStaticShortMethod
2493 _Jv_JNI_CallStaticMethodV
<jshort
>, // CallStaticShortMethodV
2494 _Jv_JNI_CallStaticMethodA
<jshort
>, // CallStaticShortMethodA
2495 _Jv_JNI_CallStaticMethod
<jint
>, // CallStaticIntMethod
2496 _Jv_JNI_CallStaticMethodV
<jint
>, // CallStaticIntMethodV
2497 _Jv_JNI_CallStaticMethodA
<jint
>, // CallStaticIntMethodA
2498 _Jv_JNI_CallStaticMethod
<jlong
>, // CallStaticLongMethod
2499 _Jv_JNI_CallStaticMethodV
<jlong
>, // CallStaticLongMethodV
2500 _Jv_JNI_CallStaticMethodA
<jlong
>, // CallStaticLongMethodA
2501 _Jv_JNI_CallStaticMethod
<jfloat
>, // CallStaticFloatMethod
2502 _Jv_JNI_CallStaticMethodV
<jfloat
>, // CallStaticFloatMethodV
2503 _Jv_JNI_CallStaticMethodA
<jfloat
>, // CallStaticFloatMethodA
2504 _Jv_JNI_CallStaticMethod
<jdouble
>, // CallStaticDoubleMethod
2505 _Jv_JNI_CallStaticMethodV
<jdouble
>, // CallStaticDoubleMethodV
2506 _Jv_JNI_CallStaticMethodA
<jdouble
>, // CallStaticDoubleMethodA
2507 _Jv_JNI_CallStaticVoidMethod
, // CallStaticVoidMethod
2508 _Jv_JNI_CallStaticVoidMethodV
, // CallStaticVoidMethodV
2509 _Jv_JNI_CallStaticVoidMethodA
, // CallStaticVoidMethodA
2511 _Jv_JNI_GetAnyFieldID
<true>, // GetStaticFieldID
2512 _Jv_JNI_GetStaticField
<jobject
>, // GetStaticObjectField
2513 _Jv_JNI_GetStaticField
<jboolean
>, // GetStaticBooleanField
2514 _Jv_JNI_GetStaticField
<jbyte
>, // GetStaticByteField
2515 _Jv_JNI_GetStaticField
<jchar
>, // GetStaticCharField
2516 _Jv_JNI_GetStaticField
<jshort
>, // GetStaticShortField
2517 _Jv_JNI_GetStaticField
<jint
>, // GetStaticIntField
2518 _Jv_JNI_GetStaticField
<jlong
>, // GetStaticLongField
2519 _Jv_JNI_GetStaticField
<jfloat
>, // GetStaticFloatField
2520 _Jv_JNI_GetStaticField
<jdouble
>, // GetStaticDoubleField
2521 _Jv_JNI_SetStaticField
, // SetStaticObjectField
2522 _Jv_JNI_SetStaticField
, // SetStaticBooleanField
2523 _Jv_JNI_SetStaticField
, // SetStaticByteField
2524 _Jv_JNI_SetStaticField
, // SetStaticCharField
2525 _Jv_JNI_SetStaticField
, // SetStaticShortField
2526 _Jv_JNI_SetStaticField
, // SetStaticIntField
2527 _Jv_JNI_SetStaticField
, // SetStaticLongField
2528 _Jv_JNI_SetStaticField
, // SetStaticFloatField
2529 _Jv_JNI_SetStaticField
, // SetStaticDoubleField
2530 _Jv_JNI_NewString
, // NewString
2531 _Jv_JNI_GetStringLength
, // GetStringLength
2532 _Jv_JNI_GetStringChars
, // GetStringChars
2533 _Jv_JNI_ReleaseStringChars
, // ReleaseStringChars
2534 _Jv_JNI_NewStringUTF
, // NewStringUTF
2535 _Jv_JNI_GetStringUTFLength
, // GetStringUTFLength
2536 _Jv_JNI_GetStringUTFChars
, // GetStringUTFLength
2537 _Jv_JNI_ReleaseStringUTFChars
, // ReleaseStringUTFChars
2538 _Jv_JNI_GetArrayLength
, // GetArrayLength
2539 _Jv_JNI_NewObjectArray
, // NewObjectArray
2540 _Jv_JNI_GetObjectArrayElement
, // GetObjectArrayElement
2541 _Jv_JNI_SetObjectArrayElement
, // SetObjectArrayElement
2542 _Jv_JNI_NewPrimitiveArray
<jboolean
, JvPrimClass (boolean
)>,
2544 _Jv_JNI_NewPrimitiveArray
<jbyte
, JvPrimClass (byte
)>, // NewByteArray
2545 _Jv_JNI_NewPrimitiveArray
<jchar
, JvPrimClass (char)>, // NewCharArray
2546 _Jv_JNI_NewPrimitiveArray
<jshort
, JvPrimClass (short)>, // NewShortArray
2547 _Jv_JNI_NewPrimitiveArray
<jint
, JvPrimClass (int)>, // NewIntArray
2548 _Jv_JNI_NewPrimitiveArray
<jlong
, JvPrimClass (long)>, // NewLongArray
2549 _Jv_JNI_NewPrimitiveArray
<jfloat
, JvPrimClass (float)>, // NewFloatArray
2550 _Jv_JNI_NewPrimitiveArray
<jdouble
, JvPrimClass (double)>, // NewDoubleArray
2551 _Jv_JNI_GetPrimitiveArrayElements
, // GetBooleanArrayElements
2552 _Jv_JNI_GetPrimitiveArrayElements
, // GetByteArrayElements
2553 _Jv_JNI_GetPrimitiveArrayElements
, // GetCharArrayElements
2554 _Jv_JNI_GetPrimitiveArrayElements
, // GetShortArrayElements
2555 _Jv_JNI_GetPrimitiveArrayElements
, // GetIntArrayElements
2556 _Jv_JNI_GetPrimitiveArrayElements
, // GetLongArrayElements
2557 _Jv_JNI_GetPrimitiveArrayElements
, // GetFloatArrayElements
2558 _Jv_JNI_GetPrimitiveArrayElements
, // GetDoubleArrayElements
2559 _Jv_JNI_ReleasePrimitiveArrayElements
, // ReleaseBooleanArrayElements
2560 _Jv_JNI_ReleasePrimitiveArrayElements
, // ReleaseByteArrayElements
2561 _Jv_JNI_ReleasePrimitiveArrayElements
, // ReleaseCharArrayElements
2562 _Jv_JNI_ReleasePrimitiveArrayElements
, // ReleaseShortArrayElements
2563 _Jv_JNI_ReleasePrimitiveArrayElements
, // ReleaseIntArrayElements
2564 _Jv_JNI_ReleasePrimitiveArrayElements
, // ReleaseLongArrayElements
2565 _Jv_JNI_ReleasePrimitiveArrayElements
, // ReleaseFloatArrayElements
2566 _Jv_JNI_ReleasePrimitiveArrayElements
, // ReleaseDoubleArrayElements
2567 _Jv_JNI_GetPrimitiveArrayRegion
, // GetBooleanArrayRegion
2568 _Jv_JNI_GetPrimitiveArrayRegion
, // GetByteArrayRegion
2569 _Jv_JNI_GetPrimitiveArrayRegion
, // GetCharArrayRegion
2570 _Jv_JNI_GetPrimitiveArrayRegion
, // GetShortArrayRegion
2571 _Jv_JNI_GetPrimitiveArrayRegion
, // GetIntArrayRegion
2572 _Jv_JNI_GetPrimitiveArrayRegion
, // GetLongArrayRegion
2573 _Jv_JNI_GetPrimitiveArrayRegion
, // GetFloatArrayRegion
2574 _Jv_JNI_GetPrimitiveArrayRegion
, // GetDoubleArrayRegion
2575 _Jv_JNI_SetPrimitiveArrayRegion
, // SetBooleanArrayRegion
2576 _Jv_JNI_SetPrimitiveArrayRegion
, // SetByteArrayRegion
2577 _Jv_JNI_SetPrimitiveArrayRegion
, // SetCharArrayRegion
2578 _Jv_JNI_SetPrimitiveArrayRegion
, // SetShortArrayRegion
2579 _Jv_JNI_SetPrimitiveArrayRegion
, // SetIntArrayRegion
2580 _Jv_JNI_SetPrimitiveArrayRegion
, // SetLongArrayRegion
2581 _Jv_JNI_SetPrimitiveArrayRegion
, // SetFloatArrayRegion
2582 _Jv_JNI_SetPrimitiveArrayRegion
, // SetDoubleArrayRegion
2583 _Jv_JNI_RegisterNatives
, // RegisterNatives
2584 _Jv_JNI_UnregisterNatives
, // UnregisterNatives
2585 _Jv_JNI_MonitorEnter
, // MonitorEnter
2586 _Jv_JNI_MonitorExit
, // MonitorExit
2587 _Jv_JNI_GetJavaVM
, // GetJavaVM
2589 _Jv_JNI_GetStringRegion
, // GetStringRegion
2590 _Jv_JNI_GetStringUTFRegion
, // GetStringUTFRegion
2591 _Jv_JNI_GetPrimitiveArrayCritical
, // GetPrimitiveArrayCritical
2592 _Jv_JNI_ReleasePrimitiveArrayCritical
, // ReleasePrimitiveArrayCritical
2593 _Jv_JNI_GetStringCritical
, // GetStringCritical
2594 _Jv_JNI_ReleaseStringCritical
, // ReleaseStringCritical
2596 _Jv_JNI_NewWeakGlobalRef
, // NewWeakGlobalRef
2597 _Jv_JNI_DeleteWeakGlobalRef
, // DeleteWeakGlobalRef
2599 _Jv_JNI_ExceptionCheck
2602 struct JNIInvokeInterface _Jv_JNI_InvokeFunctions
=
2608 _Jv_JNI_DestroyJavaVM
,
2609 _Jv_JNI_AttachCurrentThread
,
2610 _Jv_JNI_DetachCurrentThread
,