1 // jni.cc - JNI implementation, including the jump table.
3 /* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 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
19 #include <java-assert.h>
25 #include <java/lang/Class.h>
26 #include <java/lang/ClassLoader.h>
27 #include <java/lang/Throwable.h>
28 #include <java/lang/ArrayIndexOutOfBoundsException.h>
29 #include <java/lang/StringIndexOutOfBoundsException.h>
30 #include <java/lang/UnsatisfiedLinkError.h>
31 #include <java/lang/InstantiationException.h>
32 #include <java/lang/NoSuchFieldError.h>
33 #include <java/lang/NoSuchMethodError.h>
34 #include <java/lang/reflect/Constructor.h>
35 #include <java/lang/reflect/Method.h>
36 #include <java/lang/reflect/Modifier.h>
37 #include <java/lang/OutOfMemoryError.h>
38 #include <java/util/IdentityHashMap.h>
39 #include <java/lang/Integer.h>
40 #include <java/lang/ThreadGroup.h>
41 #include <java/lang/Thread.h>
43 #include <gcj/method.h>
44 #include <gcj/field.h>
46 #include <java-interp.h>
47 #include <java-threads.h>
51 // This enum is used to select different template instantiations in
52 // the invocation code.
61 // Forward declarations.
62 extern struct JNINativeInterface _Jv_JNIFunctions
;
63 extern struct JNIInvokeInterface _Jv_JNI_InvokeFunctions
;
65 // Number of slots in the default frame. The VM must allow at least
69 // Mark value indicating this is an overflow frame.
71 // Mark value indicating this is a user frame.
73 // Mark value indicating this is a system frame.
76 // This structure is used to keep track of local references.
77 struct _Jv_JNI_LocalFrame
79 // This is true if this frame object represents a pushed frame (eg
80 // from PushLocalFrame).
83 // Number of elements in frame.
86 // Next frame in chain.
87 _Jv_JNI_LocalFrame
*next
;
89 // The elements. These are allocated using the C "struct hack".
93 // This holds a reference count for all local references.
94 static java::util::IdentityHashMap
*local_ref_table
;
95 // This holds a reference count for all global references.
96 static java::util::IdentityHashMap
*global_ref_table
;
99 static JavaVM
*the_vm
;
102 // The only JVMPI interface description.
103 static JVMPI_Interface _Jv_JVMPI_Interface
;
106 jvmpiEnableEvent (jint event_type
, void *)
110 case JVMPI_EVENT_OBJECT_ALLOC
:
111 _Jv_JVMPI_Notify_OBJECT_ALLOC
= _Jv_JVMPI_Interface
.NotifyEvent
;
114 case JVMPI_EVENT_THREAD_START
:
115 _Jv_JVMPI_Notify_THREAD_START
= _Jv_JVMPI_Interface
.NotifyEvent
;
118 case JVMPI_EVENT_THREAD_END
:
119 _Jv_JVMPI_Notify_THREAD_END
= _Jv_JVMPI_Interface
.NotifyEvent
;
123 return JVMPI_NOT_AVAILABLE
;
126 return JVMPI_SUCCESS
;
130 jvmpiDisableEvent (jint event_type
, void *)
134 case JVMPI_EVENT_OBJECT_ALLOC
:
135 _Jv_JVMPI_Notify_OBJECT_ALLOC
= NULL
;
139 return JVMPI_NOT_AVAILABLE
;
142 return JVMPI_SUCCESS
;
151 local_ref_table
= new java::util::IdentityHashMap
;
152 global_ref_table
= new java::util::IdentityHashMap
;
155 _Jv_JVMPI_Interface
.version
= 1;
156 _Jv_JVMPI_Interface
.EnableEvent
= &jvmpiEnableEvent
;
157 _Jv_JVMPI_Interface
.DisableEvent
= &jvmpiDisableEvent
;
158 _Jv_JVMPI_Interface
.EnableGC
= &_Jv_EnableGC
;
159 _Jv_JVMPI_Interface
.DisableGC
= &_Jv_DisableGC
;
160 _Jv_JVMPI_Interface
.RunGC
= &_Jv_RunGC
;
164 // Tell the GC that a certain pointer is live.
166 mark_for_gc (jobject obj
, java::util::IdentityHashMap
*ref_table
)
168 JvSynchronize
sync (ref_table
);
170 using namespace java::lang
;
171 Integer
*refcount
= (Integer
*) ref_table
->get (obj
);
172 jint val
= (refcount
== NULL
) ? 0 : refcount
->intValue ();
173 // FIXME: what about out of memory error?
174 ref_table
->put (obj
, new Integer (val
+ 1));
179 unmark_for_gc (jobject obj
, java::util::IdentityHashMap
*ref_table
)
181 JvSynchronize
sync (ref_table
);
183 using namespace java::lang
;
184 Integer
*refcount
= (Integer
*) ref_table
->get (obj
);
186 jint val
= refcount
->intValue () - 1;
189 ref_table
->remove (obj
);
191 // FIXME: what about out of memory error?
192 ref_table
->put (obj
, new Integer (val
));
195 // "Unwrap" some random non-reference type. This exists to simplify
196 // other template functions.
204 // Unwrap a weak reference, if required.
209 using namespace gnu::gcj::runtime
;
210 // We can compare the class directly because JNIWeakRef is `final'.
211 // Doing it this way is much faster.
212 if (obj
== NULL
|| obj
->getClass () != &JNIWeakRef::class$
)
214 JNIWeakRef
*wr
= reinterpret_cast<JNIWeakRef
*> (obj
);
215 return reinterpret_cast<T
*> (wr
->get ());
221 (JNICALL _Jv_JNI_NewGlobalRef
) (JNIEnv
*, jobject obj
)
223 // This seems weird but I think it is correct.
225 mark_for_gc (obj
, global_ref_table
);
230 (JNICALL _Jv_JNI_DeleteGlobalRef
) (JNIEnv
*, jobject obj
)
232 // This seems weird but I think it is correct.
234 unmark_for_gc (obj
, global_ref_table
);
238 (JNICALL _Jv_JNI_DeleteLocalRef
) (JNIEnv
*env
, jobject obj
)
240 _Jv_JNI_LocalFrame
*frame
;
242 // This seems weird but I think it is correct.
245 for (frame
= env
->locals
; frame
!= NULL
; frame
= frame
->next
)
247 for (int i
= 0; i
< frame
->size
; ++i
)
249 if (frame
->vec
[i
] == obj
)
251 frame
->vec
[i
] = NULL
;
252 unmark_for_gc (obj
, local_ref_table
);
257 // Don't go past a marked frame.
258 JvAssert (frame
->marker
== MARK_NONE
);
265 (JNICALL _Jv_JNI_EnsureLocalCapacity
) (JNIEnv
*env
, jint size
)
267 // It is easier to just always allocate a new frame of the requested
268 // size. This isn't the most efficient thing, but for now we don't
269 // care. Note that _Jv_JNI_PushLocalFrame relies on this right now.
271 _Jv_JNI_LocalFrame
*frame
;
274 frame
= (_Jv_JNI_LocalFrame
*) _Jv_Malloc (sizeof (_Jv_JNI_LocalFrame
)
275 + size
* sizeof (jobject
));
283 frame
->marker
= MARK_NONE
;
285 memset (&frame
->vec
[0], 0, size
* sizeof (jobject
));
286 frame
->next
= env
->locals
;
293 (JNICALL _Jv_JNI_PushLocalFrame
) (JNIEnv
*env
, jint size
)
295 jint r
= _Jv_JNI_EnsureLocalCapacity (env
, size
);
299 // The new frame is on top.
300 env
->locals
->marker
= MARK_USER
;
306 (JNICALL _Jv_JNI_NewLocalRef
) (JNIEnv
*env
, jobject obj
)
308 // This seems weird but I think it is correct.
311 // Try to find an open slot somewhere in the topmost frame.
312 _Jv_JNI_LocalFrame
*frame
= env
->locals
;
313 bool done
= false, set
= false;
314 for (; frame
!= NULL
&& ! done
; frame
= frame
->next
)
316 for (int i
= 0; i
< frame
->size
; ++i
)
318 if (frame
->vec
[i
] == NULL
)
327 // If we found a slot, or if the frame we just searched is the
328 // mark frame, then we are done.
329 if (done
|| frame
== NULL
|| frame
->marker
!= MARK_NONE
)
335 // No slots, so we allocate a new frame. According to the spec
336 // we could just die here. FIXME: return value.
337 _Jv_JNI_EnsureLocalCapacity (env
, 16);
338 // We know the first element of the new frame will be ok.
339 env
->locals
->vec
[0] = obj
;
342 mark_for_gc (obj
, local_ref_table
);
347 (JNICALL _Jv_JNI_PopLocalFrame
) (JNIEnv
*env
, jobject result
, int stop
)
349 _Jv_JNI_LocalFrame
*rf
= env
->locals
;
352 while (rf
!= NULL
&& ! done
)
354 for (int i
= 0; i
< rf
->size
; ++i
)
355 if (rf
->vec
[i
] != NULL
)
356 unmark_for_gc (rf
->vec
[i
], local_ref_table
);
358 // If the frame we just freed is the marker frame, we are done.
359 done
= (rf
->marker
== stop
);
361 _Jv_JNI_LocalFrame
*n
= rf
->next
;
362 // When N==NULL, we've reached the stack-allocated frame, and we
363 // must not free it. However, we must be sure to clear all its
364 // elements, since we might conceivably reuse it.
367 memset (&rf
->vec
[0], 0, rf
->size
* sizeof (jobject
));
375 // Update the local frame information.
378 return result
== NULL
? NULL
: _Jv_JNI_NewLocalRef (env
, result
);
382 (JNICALL _Jv_JNI_PopLocalFrame
) (JNIEnv
*env
, jobject result
)
384 return _Jv_JNI_PopLocalFrame (env
, result
, MARK_USER
);
387 // Pop a `system' frame from the stack. This is `extern "C"' as it is
388 // used by the compiler.
390 _Jv_JNI_PopSystemFrame (JNIEnv
*env
)
392 _Jv_JNI_PopLocalFrame (env
, NULL
, MARK_SYSTEM
);
396 jthrowable t
= env
->ex
;
402 // This function is used from other template functions. It wraps the
403 // return value appropriately; we specialize it so that object returns
404 // are turned into local references.
407 wrap_value (JNIEnv
*, T value
)
412 // This specialization is used for jobject, jclass, jstring, jarray,
416 wrap_value (JNIEnv
*env
, T
*value
)
418 return (value
== NULL
420 : (T
*) _Jv_JNI_NewLocalRef (env
, (jobject
) value
));
426 (JNICALL _Jv_JNI_GetVersion
) (JNIEnv
*)
428 return JNI_VERSION_1_4
;
432 (JNICALL _Jv_JNI_DefineClass
) (JNIEnv
*env
, const char *name
, jobject loader
,
433 const jbyte
*buf
, jsize bufLen
)
437 loader
= unwrap (loader
);
439 jstring sname
= JvNewStringUTF (name
);
440 jbyteArray bytes
= JvNewByteArray (bufLen
);
442 jbyte
*elts
= elements (bytes
);
443 memcpy (elts
, buf
, bufLen
* sizeof (jbyte
));
445 java::lang::ClassLoader
*l
446 = reinterpret_cast<java::lang::ClassLoader
*> (loader
);
448 jclass result
= l
->defineClass (sname
, bytes
, 0, bufLen
);
449 return (jclass
) wrap_value (env
, result
);
459 (JNICALL _Jv_JNI_FindClass
) (JNIEnv
*env
, const char *name
)
461 // FIXME: assume that NAME isn't too long.
462 int len
= strlen (name
);
464 for (int i
= 0; i
<= len
; ++i
)
465 s
[i
] = (name
[i
] == '/') ? '.' : name
[i
];
470 // This might throw an out of memory exception.
471 jstring n
= JvNewStringUTF (s
);
473 java::lang::ClassLoader
*loader
= NULL
;
474 if (env
->klass
!= NULL
)
475 loader
= env
->klass
->getClassLoader ();
479 // FIXME: should use getBaseClassLoader, but we don't have that
481 loader
= java::lang::ClassLoader::getSystemClassLoader ();
484 r
= loader
->loadClass (n
);
491 return (jclass
) wrap_value (env
, r
);
495 (JNICALL _Jv_JNI_GetSuperclass
) (JNIEnv
*env
, jclass clazz
)
497 return (jclass
) wrap_value (env
, unwrap (clazz
)->getSuperclass ());
501 (JNICALL _Jv_JNI_IsAssignableFrom
) (JNIEnv
*, jclass clazz1
, jclass clazz2
)
503 return unwrap (clazz1
)->isAssignableFrom (unwrap (clazz2
));
507 (JNICALL _Jv_JNI_Throw
) (JNIEnv
*env
, jthrowable obj
)
509 // We check in case the user did some funky cast.
511 JvAssert (obj
!= NULL
&& java::lang::Throwable::class$
.isInstance (obj
));
517 (JNICALL _Jv_JNI_ThrowNew
) (JNIEnv
*env
, jclass clazz
, const char *message
)
519 using namespace java::lang::reflect
;
521 clazz
= unwrap (clazz
);
522 JvAssert (java::lang::Throwable::class$
.isAssignableFrom (clazz
));
527 JArray
<jclass
> *argtypes
528 = (JArray
<jclass
> *) JvNewObjectArray (1, &java::lang::Class::class$
,
531 jclass
*elts
= elements (argtypes
);
532 elts
[0] = &StringClass
;
534 Constructor
*cons
= clazz
->getConstructor (argtypes
);
536 jobjectArray values
= JvNewObjectArray (1, &StringClass
, NULL
);
537 jobject
*velts
= elements (values
);
538 velts
[0] = JvNewStringUTF (message
);
540 jobject obj
= cons
->newInstance (values
);
542 env
->ex
= reinterpret_cast<jthrowable
> (obj
);
554 (JNICALL _Jv_JNI_ExceptionOccurred
) (JNIEnv
*env
)
556 return (jthrowable
) wrap_value (env
, env
->ex
);
560 (JNICALL _Jv_JNI_ExceptionDescribe
) (JNIEnv
*env
)
563 env
->ex
->printStackTrace();
567 (JNICALL _Jv_JNI_ExceptionClear
) (JNIEnv
*env
)
573 (JNICALL _Jv_JNI_ExceptionCheck
) (JNIEnv
*env
)
575 return env
->ex
!= NULL
;
579 (JNICALL _Jv_JNI_FatalError
) (JNIEnv
*, const char *message
)
587 (JNICALL _Jv_JNI_IsSameObject
) (JNIEnv
*, jobject obj1
, jobject obj2
)
589 return unwrap (obj1
) == unwrap (obj2
);
593 (JNICALL _Jv_JNI_AllocObject
) (JNIEnv
*env
, jclass clazz
)
596 using namespace java::lang::reflect
;
600 clazz
= unwrap (clazz
);
601 JvAssert (clazz
&& ! clazz
->isArray ());
602 if (clazz
->isInterface() || Modifier::isAbstract(clazz
->getModifiers()))
603 env
->ex
= new java::lang::InstantiationException ();
605 obj
= JvAllocObject (clazz
);
612 return wrap_value (env
, obj
);
616 (JNICALL _Jv_JNI_GetObjectClass
) (JNIEnv
*env
, jobject obj
)
620 return (jclass
) wrap_value (env
, obj
->getClass());
624 (JNICALL _Jv_JNI_IsInstanceOf
) (JNIEnv
*, jobject obj
, jclass clazz
)
626 return unwrap (clazz
)->isInstance(unwrap (obj
));
632 // This section concerns method invocation.
635 template<jboolean is_static
>
637 (JNICALL _Jv_JNI_GetAnyMethodID
) (JNIEnv
*env
, jclass clazz
,
638 const char *name
, const char *sig
)
642 clazz
= unwrap (clazz
);
643 _Jv_InitClass (clazz
);
645 _Jv_Utf8Const
*name_u
= _Jv_makeUtf8Const ((char *) name
, -1);
647 // FIXME: assume that SIG isn't too long.
648 int len
= strlen (sig
);
650 for (int i
= 0; i
<= len
; ++i
)
651 s
[i
] = (sig
[i
] == '/') ? '.' : sig
[i
];
652 _Jv_Utf8Const
*sig_u
= _Jv_makeUtf8Const ((char *) s
, -1);
654 JvAssert (! clazz
->isPrimitive());
656 using namespace java::lang::reflect
;
658 while (clazz
!= NULL
)
660 jint count
= JvNumMethods (clazz
);
661 jmethodID meth
= JvGetFirstMethod (clazz
);
663 for (jint i
= 0; i
< count
; ++i
)
665 if (((is_static
&& Modifier::isStatic (meth
->accflags
))
666 || (! is_static
&& ! Modifier::isStatic (meth
->accflags
)))
667 && _Jv_equalUtf8Consts (meth
->name
, name_u
)
668 && _Jv_equalUtf8Consts (meth
->signature
, sig_u
))
671 meth
= meth
->getNextMethod();
674 clazz
= clazz
->getSuperclass ();
677 env
->ex
= new java::lang::NoSuchMethodError ();
687 // This is a helper function which turns a va_list into an array of
688 // `jvalue's. It needs signature information in order to do its work.
689 // The array of values must already be allocated.
691 array_from_valist (jvalue
*values
, JArray
<jclass
> *arg_types
, va_list vargs
)
693 jclass
*arg_elts
= elements (arg_types
);
694 for (int i
= 0; i
< arg_types
->length
; ++i
)
696 // Here we assume that sizeof(int) >= sizeof(jint), because we
697 // use `int' when decoding the varargs. Likewise for
698 // float, and double. Also we assume that sizeof(jlong) >=
699 // sizeof(int), i.e. that jlong values are not further
701 JvAssert (sizeof (int) >= sizeof (jint
));
702 JvAssert (sizeof (jlong
) >= sizeof (int));
703 JvAssert (sizeof (double) >= sizeof (jfloat
));
704 JvAssert (sizeof (double) >= sizeof (jdouble
));
705 if (arg_elts
[i
] == JvPrimClass (byte
))
706 values
[i
].b
= (jbyte
) va_arg (vargs
, int);
707 else if (arg_elts
[i
] == JvPrimClass (short))
708 values
[i
].s
= (jshort
) va_arg (vargs
, int);
709 else if (arg_elts
[i
] == JvPrimClass (int))
710 values
[i
].i
= (jint
) va_arg (vargs
, int);
711 else if (arg_elts
[i
] == JvPrimClass (long))
712 values
[i
].j
= (jlong
) va_arg (vargs
, jlong
);
713 else if (arg_elts
[i
] == JvPrimClass (float))
714 values
[i
].f
= (jfloat
) va_arg (vargs
, double);
715 else if (arg_elts
[i
] == JvPrimClass (double))
716 values
[i
].d
= (jdouble
) va_arg (vargs
, double);
717 else if (arg_elts
[i
] == JvPrimClass (boolean
))
718 values
[i
].z
= (jboolean
) va_arg (vargs
, int);
719 else if (arg_elts
[i
] == JvPrimClass (char))
720 values
[i
].c
= (jchar
) va_arg (vargs
, int);
724 values
[i
].l
= unwrap (va_arg (vargs
, jobject
));
729 // This can call any sort of method: virtual, "nonvirtual", static, or
731 template<typename T
, invocation_type style
>
733 (JNICALL _Jv_JNI_CallAnyMethodV
) (JNIEnv
*env
, jobject obj
, jclass klass
,
734 jmethodID id
, va_list vargs
)
737 klass
= unwrap (klass
);
740 id
= _Jv_LookupDeclaredMethod (obj
->getClass (), id
->name
, id
->signature
);
742 jclass decl_class
= klass
? klass
: obj
->getClass ();
743 JvAssert (decl_class
!= NULL
);
746 JArray
<jclass
> *arg_types
;
750 _Jv_GetTypesFromSignature (id
, decl_class
,
751 &arg_types
, &return_type
);
753 jvalue args
[arg_types
->length
];
754 array_from_valist (args
, arg_types
, vargs
);
756 // For constructors we need to pass the Class we are instantiating.
757 if (style
== constructor
)
761 jthrowable ex
= _Jv_CallAnyMethodA (obj
, return_type
, id
,
762 style
== constructor
,
763 arg_types
, args
, &result
);
768 // We cheat a little here. FIXME.
769 return wrap_value (env
, * (T
*) &result
);
776 return wrap_value (env
, (T
) 0);
779 template<typename T
, invocation_type style
>
781 (JNICALL _Jv_JNI_CallAnyMethod
) (JNIEnv
*env
, jobject obj
, jclass klass
,
782 jmethodID method
, ...)
787 va_start (args
, method
);
788 result
= _Jv_JNI_CallAnyMethodV
<T
, style
> (env
, obj
, klass
, method
, args
);
794 template<typename T
, invocation_type style
>
796 (JNICALL _Jv_JNI_CallAnyMethodA
) (JNIEnv
*env
, jobject obj
, jclass klass
,
797 jmethodID id
, jvalue
*args
)
800 klass
= unwrap (klass
);
803 id
= _Jv_LookupDeclaredMethod (obj
->getClass (), id
->name
, id
->signature
);
805 jclass decl_class
= klass
? klass
: obj
->getClass ();
806 JvAssert (decl_class
!= NULL
);
809 JArray
<jclass
> *arg_types
;
812 _Jv_GetTypesFromSignature (id
, decl_class
,
813 &arg_types
, &return_type
);
815 // For constructors we need to pass the Class we are instantiating.
816 if (style
== constructor
)
819 // Unwrap arguments as required. Eww.
820 jclass
*type_elts
= elements (arg_types
);
821 jvalue arg_copy
[arg_types
->length
];
822 for (int i
= 0; i
< arg_types
->length
; ++i
)
824 if (type_elts
[i
]->isPrimitive ())
825 arg_copy
[i
] = args
[i
];
827 arg_copy
[i
].l
= unwrap (args
[i
].l
);
831 jthrowable ex
= _Jv_CallAnyMethodA (obj
, return_type
, id
,
832 style
== constructor
,
833 arg_types
, arg_copy
, &result
);
838 // We cheat a little here. FIXME.
839 return wrap_value (env
, * (T
*) &result
);
846 return wrap_value (env
, (T
) 0);
849 template<invocation_type style
>
851 (JNICALL _Jv_JNI_CallAnyVoidMethodV
) (JNIEnv
*env
, jobject obj
, jclass klass
,
852 jmethodID id
, va_list vargs
)
855 klass
= unwrap (klass
);
858 id
= _Jv_LookupDeclaredMethod (obj
->getClass (), id
->name
, id
->signature
);
860 jclass decl_class
= klass
? klass
: obj
->getClass ();
861 JvAssert (decl_class
!= NULL
);
864 JArray
<jclass
> *arg_types
;
867 _Jv_GetTypesFromSignature (id
, decl_class
,
868 &arg_types
, &return_type
);
870 jvalue args
[arg_types
->length
];
871 array_from_valist (args
, arg_types
, vargs
);
873 // For constructors we need to pass the Class we are instantiating.
874 if (style
== constructor
)
877 jthrowable ex
= _Jv_CallAnyMethodA (obj
, return_type
, id
,
878 style
== constructor
,
879 arg_types
, args
, NULL
);
890 template<invocation_type style
>
892 (JNICALL _Jv_JNI_CallAnyVoidMethod
) (JNIEnv
*env
, jobject obj
, jclass klass
,
893 jmethodID method
, ...)
897 va_start (args
, method
);
898 _Jv_JNI_CallAnyVoidMethodV
<style
> (env
, obj
, klass
, method
, args
);
902 template<invocation_type style
>
904 (JNICALL _Jv_JNI_CallAnyVoidMethodA
) (JNIEnv
*env
, jobject obj
, jclass klass
,
905 jmethodID id
, jvalue
*args
)
908 id
= _Jv_LookupDeclaredMethod (obj
->getClass (), id
->name
, id
->signature
);
910 jclass decl_class
= klass
? klass
: obj
->getClass ();
911 JvAssert (decl_class
!= NULL
);
914 JArray
<jclass
> *arg_types
;
917 _Jv_GetTypesFromSignature (id
, decl_class
,
918 &arg_types
, &return_type
);
920 // Unwrap arguments as required. Eww.
921 jclass
*type_elts
= elements (arg_types
);
922 jvalue arg_copy
[arg_types
->length
];
923 for (int i
= 0; i
< arg_types
->length
; ++i
)
925 if (type_elts
[i
]->isPrimitive ())
926 arg_copy
[i
] = args
[i
];
928 arg_copy
[i
].l
= unwrap (args
[i
].l
);
931 jthrowable ex
= _Jv_CallAnyMethodA (obj
, return_type
, id
,
932 style
== constructor
,
933 arg_types
, args
, NULL
);
944 // Functions with this signature are used to implement functions in
945 // the CallMethod family.
948 (JNICALL _Jv_JNI_CallMethodV
) (JNIEnv
*env
, jobject obj
,
949 jmethodID id
, va_list args
)
951 return _Jv_JNI_CallAnyMethodV
<T
, normal
> (env
, obj
, NULL
, id
, args
);
954 // Functions with this signature are used to implement functions in
955 // the CallMethod family.
958 (JNICALL _Jv_JNI_CallMethod
) (JNIEnv
*env
, jobject obj
, jmethodID id
, ...)
964 result
= _Jv_JNI_CallAnyMethodV
<T
, normal
> (env
, obj
, NULL
, id
, args
);
970 // Functions with this signature are used to implement functions in
971 // the CallMethod family.
974 (JNICALL _Jv_JNI_CallMethodA
) (JNIEnv
*env
, jobject obj
,
975 jmethodID id
, jvalue
*args
)
977 return _Jv_JNI_CallAnyMethodA
<T
, normal
> (env
, obj
, NULL
, id
, args
);
981 (JNICALL _Jv_JNI_CallVoidMethodV
) (JNIEnv
*env
, jobject obj
,
982 jmethodID id
, va_list args
)
984 _Jv_JNI_CallAnyVoidMethodV
<normal
> (env
, obj
, NULL
, id
, args
);
988 (JNICALL _Jv_JNI_CallVoidMethod
) (JNIEnv
*env
, jobject obj
, jmethodID id
, ...)
993 _Jv_JNI_CallAnyVoidMethodV
<normal
> (env
, obj
, NULL
, id
, args
);
998 (JNICALL _Jv_JNI_CallVoidMethodA
) (JNIEnv
*env
, jobject obj
,
999 jmethodID id
, jvalue
*args
)
1001 _Jv_JNI_CallAnyVoidMethodA
<normal
> (env
, obj
, NULL
, id
, args
);
1004 // Functions with this signature are used to implement functions in
1005 // the CallStaticMethod family.
1006 template<typename T
>
1008 (JNICALL _Jv_JNI_CallStaticMethodV
) (JNIEnv
*env
, jclass klass
,
1009 jmethodID id
, va_list args
)
1011 JvAssert (((id
->accflags
) & java::lang::reflect::Modifier::STATIC
));
1012 JvAssert (java::lang::Class::class$
.isInstance (unwrap (klass
)));
1014 return _Jv_JNI_CallAnyMethodV
<T
, static_type
> (env
, NULL
, klass
, id
, args
);
1017 // Functions with this signature are used to implement functions in
1018 // the CallStaticMethod family.
1019 template<typename T
>
1021 (JNICALL _Jv_JNI_CallStaticMethod
) (JNIEnv
*env
, jclass klass
,
1027 JvAssert (((id
->accflags
) & java::lang::reflect::Modifier::STATIC
));
1028 JvAssert (java::lang::Class::class$
.isInstance (unwrap (klass
)));
1030 va_start (args
, id
);
1031 result
= _Jv_JNI_CallAnyMethodV
<T
, static_type
> (env
, NULL
, klass
,
1038 // Functions with this signature are used to implement functions in
1039 // the CallStaticMethod family.
1040 template<typename T
>
1042 (JNICALL _Jv_JNI_CallStaticMethodA
) (JNIEnv
*env
, jclass klass
, jmethodID id
,
1045 JvAssert (((id
->accflags
) & java::lang::reflect::Modifier::STATIC
));
1046 JvAssert (java::lang::Class::class$
.isInstance (unwrap (klass
)));
1048 return _Jv_JNI_CallAnyMethodA
<T
, static_type
> (env
, NULL
, klass
, id
, args
);
1052 (JNICALL _Jv_JNI_CallStaticVoidMethodV
) (JNIEnv
*env
, jclass klass
,
1053 jmethodID id
, va_list args
)
1055 _Jv_JNI_CallAnyVoidMethodV
<static_type
> (env
, NULL
, klass
, id
, args
);
1059 (JNICALL _Jv_JNI_CallStaticVoidMethod
) (JNIEnv
*env
, jclass klass
,
1064 va_start (args
, id
);
1065 _Jv_JNI_CallAnyVoidMethodV
<static_type
> (env
, NULL
, klass
, id
, args
);
1070 (JNICALL _Jv_JNI_CallStaticVoidMethodA
) (JNIEnv
*env
, jclass klass
,
1071 jmethodID id
, jvalue
*args
)
1073 _Jv_JNI_CallAnyVoidMethodA
<static_type
> (env
, NULL
, klass
, id
, args
);
1077 (JNICALL _Jv_JNI_NewObjectV
) (JNIEnv
*env
, jclass klass
,
1078 jmethodID id
, va_list args
)
1080 JvAssert (klass
&& ! klass
->isArray ());
1081 JvAssert (! strcmp (id
->name
->data
, "<init>")
1082 && id
->signature
->length
> 2
1083 && id
->signature
->data
[0] == '('
1084 && ! strcmp (&id
->signature
->data
[id
->signature
->length
- 2],
1087 return _Jv_JNI_CallAnyMethodV
<jobject
, constructor
> (env
, NULL
, klass
,
1092 (JNICALL _Jv_JNI_NewObject
) (JNIEnv
*env
, jclass klass
, jmethodID id
, ...)
1094 JvAssert (klass
&& ! klass
->isArray ());
1095 JvAssert (! strcmp (id
->name
->data
, "<init>")
1096 && id
->signature
->length
> 2
1097 && id
->signature
->data
[0] == '('
1098 && ! strcmp (&id
->signature
->data
[id
->signature
->length
- 2],
1104 va_start (args
, id
);
1105 result
= _Jv_JNI_CallAnyMethodV
<jobject
, constructor
> (env
, NULL
, klass
,
1113 (JNICALL _Jv_JNI_NewObjectA
) (JNIEnv
*env
, jclass klass
, jmethodID id
,
1116 JvAssert (klass
&& ! klass
->isArray ());
1117 JvAssert (! strcmp (id
->name
->data
, "<init>")
1118 && id
->signature
->length
> 2
1119 && id
->signature
->data
[0] == '('
1120 && ! strcmp (&id
->signature
->data
[id
->signature
->length
- 2],
1123 return _Jv_JNI_CallAnyMethodA
<jobject
, constructor
> (env
, NULL
, klass
,
1129 template<typename T
>
1131 (JNICALL _Jv_JNI_GetField
) (JNIEnv
*env
, jobject obj
, jfieldID field
)
1135 T
*ptr
= (T
*) ((char *) obj
+ field
->getOffset ());
1136 return wrap_value (env
, *ptr
);
1139 template<typename T
>
1141 (JNICALL _Jv_JNI_SetField
) (JNIEnv
*, jobject obj
, jfieldID field
, T value
)
1144 value
= unwrap (value
);
1147 T
*ptr
= (T
*) ((char *) obj
+ field
->getOffset ());
1151 template<jboolean is_static
>
1153 (JNICALL _Jv_JNI_GetAnyFieldID
) (JNIEnv
*env
, jclass clazz
,
1154 const char *name
, const char *sig
)
1158 clazz
= unwrap (clazz
);
1160 _Jv_InitClass (clazz
);
1162 _Jv_Utf8Const
*a_name
= _Jv_makeUtf8Const ((char *) name
, -1);
1164 // FIXME: assume that SIG isn't too long.
1165 int len
= strlen (sig
);
1167 for (int i
= 0; i
<= len
; ++i
)
1168 s
[i
] = (sig
[i
] == '/') ? '.' : sig
[i
];
1169 jclass field_class
= _Jv_FindClassFromSignature ((char *) s
, NULL
);
1171 // FIXME: what if field_class == NULL?
1173 java::lang::ClassLoader
*loader
= clazz
->getClassLoader ();
1174 while (clazz
!= NULL
)
1176 // We acquire the class lock so that fields aren't resolved
1177 // while we are running.
1178 JvSynchronize
sync (clazz
);
1180 jint count
= (is_static
1181 ? JvNumStaticFields (clazz
)
1182 : JvNumInstanceFields (clazz
));
1183 jfieldID field
= (is_static
1184 ? JvGetFirstStaticField (clazz
)
1185 : JvGetFirstInstanceField (clazz
));
1186 for (jint i
= 0; i
< count
; ++i
)
1188 _Jv_Utf8Const
*f_name
= field
->getNameUtf8Const(clazz
);
1190 // The field might be resolved or it might not be. It
1191 // is much simpler to always resolve it.
1192 _Jv_ResolveField (field
, loader
);
1193 if (_Jv_equalUtf8Consts (f_name
, a_name
)
1194 && field
->getClass() == field_class
)
1197 field
= field
->getNextField ();
1200 clazz
= clazz
->getSuperclass ();
1203 env
->ex
= new java::lang::NoSuchFieldError ();
1205 catch (jthrowable t
)
1212 template<typename T
>
1214 (JNICALL _Jv_JNI_GetStaticField
) (JNIEnv
*env
, jclass
, jfieldID field
)
1216 T
*ptr
= (T
*) field
->u
.addr
;
1217 return wrap_value (env
, *ptr
);
1220 template<typename T
>
1222 (JNICALL _Jv_JNI_SetStaticField
) (JNIEnv
*, jclass
, jfieldID field
, T value
)
1224 value
= unwrap (value
);
1225 T
*ptr
= (T
*) field
->u
.addr
;
1230 (JNICALL _Jv_JNI_NewString
) (JNIEnv
*env
, const jchar
*unichars
, jsize len
)
1234 jstring r
= _Jv_NewString (unichars
, len
);
1235 return (jstring
) wrap_value (env
, r
);
1237 catch (jthrowable t
)
1245 (JNICALL _Jv_JNI_GetStringLength
) (JNIEnv
*, jstring string
)
1247 return unwrap (string
)->length();
1250 static const jchar
*
1251 (JNICALL _Jv_JNI_GetStringChars
) (JNIEnv
*, jstring string
, jboolean
*isCopy
)
1253 string
= unwrap (string
);
1254 jchar
*result
= _Jv_GetStringChars (string
);
1255 mark_for_gc (string
, global_ref_table
);
1258 return (const jchar
*) result
;
1262 (JNICALL _Jv_JNI_ReleaseStringChars
) (JNIEnv
*, jstring string
, const jchar
*)
1264 unmark_for_gc (unwrap (string
), global_ref_table
);
1268 (JNICALL _Jv_JNI_NewStringUTF
) (JNIEnv
*env
, const char *bytes
)
1272 jstring result
= JvNewStringUTF (bytes
);
1273 return (jstring
) wrap_value (env
, result
);
1275 catch (jthrowable t
)
1283 (JNICALL _Jv_JNI_GetStringUTFLength
) (JNIEnv
*, jstring string
)
1285 return JvGetStringUTFLength (unwrap (string
));
1289 (JNICALL _Jv_JNI_GetStringUTFChars
) (JNIEnv
*env
, jstring string
,
1292 string
= unwrap (string
);
1293 jsize len
= JvGetStringUTFLength (string
);
1296 char *r
= (char *) _Jv_Malloc (len
+ 1);
1297 JvGetStringUTFRegion (string
, 0, len
, r
);
1303 return (const char *) r
;
1305 catch (jthrowable t
)
1313 (JNICALL _Jv_JNI_ReleaseStringUTFChars
) (JNIEnv
*, jstring
, const char *utf
)
1315 _Jv_Free ((void *) utf
);
1319 (JNICALL _Jv_JNI_GetStringRegion
) (JNIEnv
*env
, jstring string
, jsize start
,
1320 jsize len
, jchar
*buf
)
1322 string
= unwrap (string
);
1323 jchar
*result
= _Jv_GetStringChars (string
);
1324 if (start
< 0 || start
> string
->length ()
1325 || len
< 0 || start
+ len
> string
->length ())
1329 env
->ex
= new java::lang::StringIndexOutOfBoundsException ();
1331 catch (jthrowable t
)
1337 memcpy (buf
, &result
[start
], len
* sizeof (jchar
));
1341 (JNICALL _Jv_JNI_GetStringUTFRegion
) (JNIEnv
*env
, jstring str
, jsize start
,
1342 jsize len
, char *buf
)
1346 if (start
< 0 || start
> str
->length ()
1347 || len
< 0 || start
+ len
> str
->length ())
1351 env
->ex
= new java::lang::StringIndexOutOfBoundsException ();
1353 catch (jthrowable t
)
1359 _Jv_GetStringUTFRegion (str
, start
, len
, buf
);
1362 static const jchar
*
1363 (JNICALL _Jv_JNI_GetStringCritical
) (JNIEnv
*, jstring str
, jboolean
*isCopy
)
1365 jchar
*result
= _Jv_GetStringChars (unwrap (str
));
1372 (JNICALL _Jv_JNI_ReleaseStringCritical
) (JNIEnv
*, jstring
, const jchar
*)
1378 (JNICALL _Jv_JNI_GetArrayLength
) (JNIEnv
*, jarray array
)
1380 return unwrap (array
)->length
;
1384 (JNICALL _Jv_JNI_NewObjectArray
) (JNIEnv
*env
, jsize length
,
1385 jclass elementClass
, jobject init
)
1389 elementClass
= unwrap (elementClass
);
1390 init
= unwrap (init
);
1392 _Jv_CheckCast (elementClass
, init
);
1393 jarray result
= JvNewObjectArray (length
, elementClass
, init
);
1394 return (jarray
) wrap_value (env
, result
);
1396 catch (jthrowable t
)
1404 (JNICALL _Jv_JNI_GetObjectArrayElement
) (JNIEnv
*env
, jobjectArray array
,
1407 if ((unsigned) index
>= (unsigned) array
->length
)
1408 _Jv_ThrowBadArrayIndex (index
);
1409 jobject
*elts
= elements (unwrap (array
));
1410 return wrap_value (env
, elts
[index
]);
1414 (JNICALL _Jv_JNI_SetObjectArrayElement
) (JNIEnv
*env
, jobjectArray array
,
1415 jsize index
, jobject value
)
1419 array
= unwrap (array
);
1420 value
= unwrap (value
);
1422 _Jv_CheckArrayStore (array
, value
);
1423 if ((unsigned) index
>= (unsigned) array
->length
)
1424 _Jv_ThrowBadArrayIndex (index
);
1425 jobject
*elts
= elements (array
);
1426 elts
[index
] = value
;
1428 catch (jthrowable t
)
1434 template<typename T
, jclass K
>
1436 (JNICALL _Jv_JNI_NewPrimitiveArray
) (JNIEnv
*env
, jsize length
)
1440 return (JArray
<T
> *) wrap_value (env
, _Jv_NewPrimArray (K
, length
));
1442 catch (jthrowable t
)
1449 template<typename T
>
1451 (JNICALL _Jv_JNI_GetPrimitiveArrayElements
) (JNIEnv
*, JArray
<T
> *array
,
1454 array
= unwrap (array
);
1455 T
*elts
= elements (array
);
1458 // We elect never to copy.
1461 mark_for_gc (array
, global_ref_table
);
1465 template<typename T
>
1467 (JNICALL _Jv_JNI_ReleasePrimitiveArrayElements
) (JNIEnv
*, JArray
<T
> *array
,
1468 T
*, jint
/* mode */)
1470 array
= unwrap (array
);
1471 // Note that we ignore MODE. We can do this because we never copy
1472 // the array elements. My reading of the JNI documentation is that
1473 // this is an option for the implementor.
1474 unmark_for_gc (array
, global_ref_table
);
1477 template<typename T
>
1479 (JNICALL _Jv_JNI_GetPrimitiveArrayRegion
) (JNIEnv
*env
, JArray
<T
> *array
,
1480 jsize start
, jsize len
,
1483 array
= unwrap (array
);
1485 // The cast to unsigned lets us save a comparison.
1486 if (start
< 0 || len
< 0
1487 || (unsigned long) (start
+ len
) > (unsigned long) array
->length
)
1492 env
->ex
= new java::lang::ArrayIndexOutOfBoundsException ();
1494 catch (jthrowable t
)
1496 // Could have thown out of memory error.
1502 T
*elts
= elements (array
) + start
;
1503 memcpy (buf
, elts
, len
* sizeof (T
));
1507 template<typename T
>
1509 (JNICALL _Jv_JNI_SetPrimitiveArrayRegion
) (JNIEnv
*env
, JArray
<T
> *array
,
1510 jsize start
, jsize len
, T
*buf
)
1512 array
= unwrap (array
);
1514 // The cast to unsigned lets us save a comparison.
1515 if (start
< 0 || len
< 0
1516 || (unsigned long) (start
+ len
) > (unsigned long) array
->length
)
1521 env
->ex
= new java::lang::ArrayIndexOutOfBoundsException ();
1523 catch (jthrowable t
)
1530 T
*elts
= elements (array
) + start
;
1531 memcpy (elts
, buf
, len
* sizeof (T
));
1536 (JNICALL _Jv_JNI_GetPrimitiveArrayCritical
) (JNIEnv
*, jarray array
,
1539 array
= unwrap (array
);
1540 // FIXME: does this work?
1541 jclass klass
= array
->getClass()->getComponentType();
1542 JvAssert (klass
->isPrimitive ());
1543 char *r
= _Jv_GetArrayElementFromElementType (array
, klass
);
1550 (JNICALL _Jv_JNI_ReleasePrimitiveArrayCritical
) (JNIEnv
*, jarray
, void *, jint
)
1556 (JNICALL _Jv_JNI_MonitorEnter
) (JNIEnv
*env
, jobject obj
)
1560 _Jv_MonitorEnter (unwrap (obj
));
1563 catch (jthrowable t
)
1571 (JNICALL _Jv_JNI_MonitorExit
) (JNIEnv
*env
, jobject obj
)
1575 _Jv_MonitorExit (unwrap (obj
));
1578 catch (jthrowable t
)
1587 (JNICALL _Jv_JNI_ToReflectedField
) (JNIEnv
*env
, jclass cls
, jfieldID fieldID
,
1593 java::lang::reflect::Field
*field
= new java::lang::reflect::Field();
1594 field
->declaringClass
= cls
;
1595 field
->offset
= (char*) fieldID
- (char *) cls
->fields
;
1596 field
->name
= _Jv_NewStringUtf8Const (fieldID
->getNameUtf8Const (cls
));
1597 return wrap_value (env
, field
);
1599 catch (jthrowable t
)
1608 (JNICALL _Jv_JNI_FromReflectedField
) (JNIEnv
*, jobject f
)
1610 using namespace java::lang::reflect
;
1613 Field
*field
= reinterpret_cast<Field
*> (f
);
1614 return _Jv_FromReflectedField (field
);
1618 (JNICALL _Jv_JNI_ToReflectedMethod
) (JNIEnv
*env
, jclass klass
, jmethodID id
,
1621 using namespace java::lang::reflect
;
1623 jobject result
= NULL
;
1624 klass
= unwrap (klass
);
1628 if (_Jv_equalUtf8Consts (id
->name
, init_name
))
1631 Constructor
*cons
= new Constructor ();
1632 cons
->offset
= (char *) id
- (char *) &klass
->methods
;
1633 cons
->declaringClass
= klass
;
1638 Method
*meth
= new Method ();
1639 meth
->offset
= (char *) id
- (char *) &klass
->methods
;
1640 meth
->declaringClass
= klass
;
1644 catch (jthrowable t
)
1649 return wrap_value (env
, result
);
1653 (JNICALL _Jv_JNI_FromReflectedMethod
) (JNIEnv
*, jobject method
)
1655 using namespace java::lang::reflect
;
1656 method
= unwrap (method
);
1657 if (Method::class$
.isInstance (method
))
1658 return _Jv_FromReflectedMethod (reinterpret_cast<Method
*> (method
));
1660 _Jv_FromReflectedConstructor (reinterpret_cast<Constructor
*> (method
));
1665 (JNICALL _Jv_JNI_NewWeakGlobalRef
) (JNIEnv
*env
, jobject obj
)
1667 using namespace gnu::gcj::runtime
;
1668 JNIWeakRef
*ref
= NULL
;
1672 // This seems weird but I think it is correct.
1674 ref
= new JNIWeakRef (obj
);
1675 mark_for_gc (ref
, global_ref_table
);
1677 catch (jthrowable t
)
1682 return reinterpret_cast<jweak
> (ref
);
1686 (JNICALL _Jv_JNI_DeleteWeakGlobalRef
) (JNIEnv
*, jweak obj
)
1688 using namespace gnu::gcj::runtime
;
1689 JNIWeakRef
*ref
= reinterpret_cast<JNIWeakRef
*> (obj
);
1690 unmark_for_gc (ref
, global_ref_table
);
1696 // Direct byte buffers.
1699 (JNICALL _Jv_JNI_NewDirectByteBuffer
) (JNIEnv
*, void *, jlong
)
1701 // For now we don't support this.
1706 (JNICALL _Jv_JNI_GetDirectBufferAddress
) (JNIEnv
*, jobject
)
1708 // For now we don't support this.
1713 (JNICALL _Jv_JNI_GetDirectBufferCapacity
) (JNIEnv
*, jobject
)
1715 // For now we don't support this.
1721 // Hash table of native methods.
1722 static JNINativeMethod
*nathash
;
1723 // Number of slots used.
1724 static int nathash_count
= 0;
1725 // Number of slots available. Must be power of 2.
1726 static int nathash_size
= 0;
1728 #define DELETED_ENTRY ((char *) (~0))
1730 // Compute a hash value for a native method descriptor.
1732 hash (const JNINativeMethod
*method
)
1739 hash
= (31 * hash
) + *ptr
++;
1741 ptr
= method
->signature
;
1743 hash
= (31 * hash
) + *ptr
++;
1748 // Find the slot where a native method goes.
1749 static JNINativeMethod
*
1750 nathash_find_slot (const JNINativeMethod
*method
)
1752 jint h
= hash (method
);
1753 int step
= (h
^ (h
>> 16)) | 1;
1754 int w
= h
& (nathash_size
- 1);
1759 JNINativeMethod
*slotp
= &nathash
[w
];
1760 if (slotp
->name
== NULL
)
1763 return &nathash
[del
];
1767 else if (slotp
->name
== DELETED_ENTRY
)
1769 else if (! strcmp (slotp
->name
, method
->name
)
1770 && ! strcmp (slotp
->signature
, method
->signature
))
1772 w
= (w
+ step
) & (nathash_size
- 1);
1776 // Find a method. Return NULL if it isn't in the hash table.
1778 nathash_find (JNINativeMethod
*method
)
1780 if (nathash
== NULL
)
1782 JNINativeMethod
*slot
= nathash_find_slot (method
);
1783 if (slot
->name
== NULL
|| slot
->name
== DELETED_ENTRY
)
1791 if (nathash
== NULL
)
1793 nathash_size
= 1024;
1795 (JNINativeMethod
*) _Jv_AllocBytes (nathash_size
1796 * sizeof (JNINativeMethod
));
1797 memset (nathash
, 0, nathash_size
* sizeof (JNINativeMethod
));
1801 int savesize
= nathash_size
;
1802 JNINativeMethod
*savehash
= nathash
;
1805 (JNINativeMethod
*) _Jv_AllocBytes (nathash_size
1806 * sizeof (JNINativeMethod
));
1807 memset (nathash
, 0, nathash_size
* sizeof (JNINativeMethod
));
1809 for (int i
= 0; i
< savesize
; ++i
)
1811 if (savehash
[i
].name
!= NULL
&& savehash
[i
].name
!= DELETED_ENTRY
)
1813 JNINativeMethod
*slot
= nathash_find_slot (&savehash
[i
]);
1814 *slot
= savehash
[i
];
1821 nathash_add (const JNINativeMethod
*method
)
1823 if (3 * nathash_count
>= 2 * nathash_size
)
1825 JNINativeMethod
*slot
= nathash_find_slot (method
);
1826 // If the slot has a real entry in it, then there is no work to do.
1827 if (slot
->name
!= NULL
&& slot
->name
!= DELETED_ENTRY
)
1830 slot
->name
= strdup (method
->name
);
1831 slot
->signature
= strdup (method
->signature
);
1832 slot
->fnPtr
= method
->fnPtr
;
1836 (JNICALL _Jv_JNI_RegisterNatives
) (JNIEnv
*env
, jclass klass
,
1837 const JNINativeMethod
*methods
,
1840 // Synchronize while we do the work. This must match
1841 // synchronization in some other functions that manipulate or use
1842 // the nathash table.
1843 JvSynchronize
sync (global_ref_table
);
1845 // Look at each descriptor given us, and find the corresponding
1846 // method in the class.
1847 for (int j
= 0; j
< nMethods
; ++j
)
1851 _Jv_Method
*imeths
= JvGetFirstMethod (klass
);
1852 for (int i
= 0; i
< JvNumMethods (klass
); ++i
)
1854 _Jv_Method
*self
= &imeths
[i
];
1856 if (! strcmp (self
->name
->data
, methods
[j
].name
)
1857 && ! strcmp (self
->signature
->data
, methods
[j
].signature
))
1859 if (! (self
->accflags
1860 & java::lang::reflect::Modifier::NATIVE
))
1863 // Found a match that is native.
1865 nathash_add (&methods
[j
]);
1873 jstring m
= JvNewStringUTF (methods
[j
].name
);
1876 env
->ex
=new java::lang::NoSuchMethodError (m
);
1878 catch (jthrowable t
)
1890 (JNICALL _Jv_JNI_UnregisterNatives
) (JNIEnv
*, jclass
)
1892 // FIXME -- we could implement this.
1898 // Add a character to the buffer, encoding properly.
1900 add_char (char *buf
, jchar c
, int *here
)
1904 buf
[(*here
)++] = '_';
1905 buf
[(*here
)++] = '1';
1909 buf
[(*here
)++] = '_';
1910 buf
[(*here
)++] = '2';
1914 buf
[(*here
)++] = '_';
1915 buf
[(*here
)++] = '3';
1918 // Also check for `.' here because we might be passed an internal
1919 // qualified class name like `foo.bar'.
1920 else if (c
== '/' || c
== '.')
1921 buf
[(*here
)++] = '_';
1922 else if ((c
>= '0' && c
<= '9')
1923 || (c
>= 'a' && c
<= 'z')
1924 || (c
>= 'A' && c
<= 'Z'))
1925 buf
[(*here
)++] = (char) c
;
1928 // "Unicode" character.
1929 buf
[(*here
)++] = '_';
1930 buf
[(*here
)++] = '0';
1931 for (int i
= 0; i
< 4; ++i
)
1934 buf
[(*here
) + 3 - i
] = (val
> 10) ? ('a' + val
- 10) : ('0' + val
);
1941 // Compute a mangled name for a native function. This computes the
1942 // long name, and also returns an index which indicates where a NUL
1943 // can be placed to create the short name. This function assumes that
1944 // the buffer is large enough for its results.
1946 mangled_name (jclass klass
, _Jv_Utf8Const
*func_name
,
1947 _Jv_Utf8Const
*signature
, char *buf
, int *long_start
)
1949 strcpy (buf
, "Java_");
1952 // Add fully qualified class name.
1953 jchar
*chars
= _Jv_GetStringChars (klass
->getName ());
1954 jint len
= klass
->getName ()->length ();
1955 for (int i
= 0; i
< len
; ++i
)
1956 add_char (buf
, chars
[i
], &here
);
1958 // Don't use add_char because we need a literal `_'.
1961 const unsigned char *fn
= (const unsigned char *) func_name
->data
;
1962 const unsigned char *limit
= fn
+ func_name
->length
;
1963 for (int i
= 0; ; ++i
)
1965 int ch
= UTF8_GET (fn
, limit
);
1968 add_char (buf
, ch
, &here
);
1971 // This is where the long signature begins.
1976 const unsigned char *sig
= (const unsigned char *) signature
->data
;
1977 limit
= sig
+ signature
->length
;
1978 JvAssert (sig
[0] == '(');
1982 int ch
= UTF8_GET (sig
, limit
);
1983 if (ch
== ')' || ch
< 0)
1985 add_char (buf
, ch
, &here
);
1991 // Return the current thread's JNIEnv; if one does not exist, create
1992 // it. Also create a new system frame for use. This is `extern "C"'
1993 // because the compiler calls it.
1995 _Jv_GetJNIEnvNewFrame (jclass klass
)
1997 JNIEnv
*env
= _Jv_GetCurrentJNIEnv ();
2000 env
= (JNIEnv
*) _Jv_MallocUnchecked (sizeof (JNIEnv
));
2001 env
->p
= &_Jv_JNIFunctions
;
2004 // We set env->ex below.
2006 _Jv_SetCurrentJNIEnv (env
);
2009 _Jv_JNI_LocalFrame
*frame
2010 = (_Jv_JNI_LocalFrame
*) _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame
)
2012 * sizeof (jobject
)));
2014 frame
->marker
= MARK_SYSTEM
;
2015 frame
->size
= FRAME_SIZE
;
2016 frame
->next
= env
->locals
;
2018 for (int i
= 0; i
< frame
->size
; ++i
)
2019 frame
->vec
[i
] = NULL
;
2021 env
->locals
= frame
;
2027 // Return the function which implements a particular JNI method. If
2028 // we can't find the function, we throw the appropriate exception.
2029 // This is `extern "C"' because the compiler uses it.
2031 _Jv_LookupJNIMethod (jclass klass
, _Jv_Utf8Const
*name
,
2032 _Jv_Utf8Const
*signature
, int args_size
)
2034 char buf
[10 + 6 * (name
->length
+ signature
->length
) + 12];
2038 // Synchronize on something convenient. Right now we use the hash.
2039 JvSynchronize
sync (global_ref_table
);
2041 // First see if we have an override in the hash table.
2042 strncpy (buf
, name
->data
, name
->length
);
2043 buf
[name
->length
] = '\0';
2044 strncpy (buf
+ name
->length
+ 1, signature
->data
, signature
->length
);
2045 buf
[name
->length
+ signature
->length
+ 1] = '\0';
2046 JNINativeMethod meth
;
2048 meth
.signature
= buf
+ name
->length
+ 1;
2049 function
= nathash_find (&meth
);
2050 if (function
!= NULL
)
2053 // If there was no override, then look in the symbol table.
2055 mangled_name (klass
, name
, signature
, buf
+ 1, &long_start
);
2056 char c
= buf
[long_start
+ 1];
2057 buf
[long_start
+ 1] = '\0';
2059 function
= _Jv_FindSymbolInExecutable (buf
+ 1);
2061 // On Win32, we use the "stdcall" calling convention (see JNICALL
2064 // For a function named 'fooBar' that takes 'nn' bytes as arguments,
2065 // by default, MinGW GCC exports it as 'fooBar@nn', MSVC exports it
2066 // as '_fooBar@nn' and Borland C exports it as 'fooBar'. We try to
2067 // take care of all these variations here.
2069 char asz_buf
[12]; /* '@' + '2147483647' (32-bit INT_MAX) + '\0' */
2070 char long_nm_sv
[11]; /* Ditto, except for the '\0'. */
2072 if (function
== NULL
)
2074 // We have tried searching for the 'fooBar' form (BCC) - now
2077 // First, save the part of the long name that will be damaged
2078 // by appending '@nn'.
2079 memcpy (long_nm_sv
, (buf
+ long_start
+ 1 + 1), sizeof (long_nm_sv
));
2081 sprintf (asz_buf
, "@%d", args_size
);
2082 strcat (buf
, asz_buf
);
2084 // Search for the '_fooBar@nn' form (MSVC).
2085 function
= _Jv_FindSymbolInExecutable (buf
);
2087 if (function
== NULL
)
2089 // Search for the 'fooBar@nn' form (MinGW GCC).
2090 function
= _Jv_FindSymbolInExecutable (buf
+ 1);
2094 args_size
; /* Dummy statement to avoid unused parameter warning */
2095 #endif /* ! WIN32 */
2097 if (function
== NULL
)
2099 buf
[long_start
+ 1] = c
;
2101 // Restore the part of the long name that was damaged by
2102 // appending the '@nn'.
2103 memcpy ((buf
+ long_start
+ 1 + 1), long_nm_sv
, sizeof (long_nm_sv
));
2105 function
= _Jv_FindSymbolInExecutable (buf
+ 1);
2106 if (function
== NULL
)
2109 strcat (buf
, asz_buf
);
2110 function
= _Jv_FindSymbolInExecutable (buf
);
2111 if (function
== NULL
)
2112 function
= _Jv_FindSymbolInExecutable (buf
+ 1);
2114 if (function
== NULL
)
2117 jstring str
= JvNewStringUTF (name
->data
);
2118 throw new java::lang::UnsatisfiedLinkError (str
);
2128 // This function is the stub which is used to turn an ordinary (CNI)
2129 // method call into a JNI call.
2131 _Jv_JNIMethod::call (ffi_cif
*, void *ret
, ffi_raw
*args
, void *__this
)
2133 _Jv_JNIMethod
* _this
= (_Jv_JNIMethod
*) __this
;
2135 JNIEnv
*env
= _Jv_GetJNIEnvNewFrame (_this
->defining_class
);
2137 // FIXME: we should mark every reference parameter as a local. For
2138 // now we assume a conservative GC, and we assume that the
2139 // references are on the stack somewhere.
2141 // We cache the value that we find, of course, but if we don't find
2142 // a value we don't cache that fact -- we might subsequently load a
2143 // library which finds the function in question.
2145 // Synchronize on a convenient object to ensure sanity in case two
2146 // threads reach this point for the same function at the same
2148 JvSynchronize
sync (global_ref_table
);
2149 if (_this
->function
== NULL
)
2151 int args_size
= sizeof (JNIEnv
*) + _this
->args_raw_size
;
2153 if (_this
->self
->accflags
& java::lang::reflect::Modifier::STATIC
)
2154 args_size
+= sizeof (_this
->defining_class
);
2156 _this
->function
= _Jv_LookupJNIMethod (_this
->defining_class
,
2158 _this
->self
->signature
,
2163 JvAssert (_this
->args_raw_size
% sizeof (ffi_raw
) == 0);
2164 ffi_raw real_args
[2 + _this
->args_raw_size
/ sizeof (ffi_raw
)];
2167 // First argument is always the environment pointer.
2168 real_args
[offset
++].ptr
= env
;
2170 // For a static method, we pass in the Class. For non-static
2171 // methods, the `this' argument is already handled.
2172 if ((_this
->self
->accflags
& java::lang::reflect::Modifier::STATIC
))
2173 real_args
[offset
++].ptr
= _this
->defining_class
;
2175 // In libgcj, the callee synchronizes.
2176 jobject sync
= NULL
;
2177 if ((_this
->self
->accflags
& java::lang::reflect::Modifier::SYNCHRONIZED
))
2179 if ((_this
->self
->accflags
& java::lang::reflect::Modifier::STATIC
))
2180 sync
= _this
->defining_class
;
2182 sync
= (jobject
) args
[0].ptr
;
2183 _Jv_MonitorEnter (sync
);
2186 // Copy over passed-in arguments.
2187 memcpy (&real_args
[offset
], args
, _this
->args_raw_size
);
2189 // The actual call to the JNI function.
2190 ffi_raw_call (&_this
->jni_cif
, (void (*)()) _this
->function
,
2194 _Jv_MonitorExit (sync
);
2196 _Jv_JNI_PopSystemFrame (env
);
2199 #endif /* INTERPRETER */
2207 // An internal helper function.
2209 _Jv_JNI_AttachCurrentThread (JavaVM
*, jstring name
, void **penv
,
2210 void *args
, jboolean is_daemon
)
2212 JavaVMAttachArgs
*attach
= reinterpret_cast<JavaVMAttachArgs
*> (args
);
2213 java::lang::ThreadGroup
*group
= NULL
;
2217 // FIXME: do we really want to support 1.1?
2218 if (attach
->version
!= JNI_VERSION_1_4
2219 && attach
->version
!= JNI_VERSION_1_2
2220 && attach
->version
!= JNI_VERSION_1_1
)
2221 return JNI_EVERSION
;
2223 JvAssert (java::lang::ThreadGroup::class$
.isInstance (attach
->group
));
2224 group
= reinterpret_cast<java::lang::ThreadGroup
*> (attach
->group
);
2227 // Attaching an already-attached thread is a no-op.
2228 if (_Jv_GetCurrentJNIEnv () != NULL
)
2231 JNIEnv
*env
= (JNIEnv
*) _Jv_MallocUnchecked (sizeof (JNIEnv
));
2234 env
->p
= &_Jv_JNIFunctions
;
2238 = (_Jv_JNI_LocalFrame
*) _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame
)
2240 * sizeof (jobject
)));
2241 if (env
->locals
== NULL
)
2247 env
->locals
->marker
= MARK_SYSTEM
;
2248 env
->locals
->size
= FRAME_SIZE
;
2249 env
->locals
->next
= NULL
;
2251 for (int i
= 0; i
< env
->locals
->size
; ++i
)
2252 env
->locals
->vec
[i
] = NULL
;
2254 *penv
= reinterpret_cast<void *> (env
);
2256 // This thread might already be a Java thread -- this function might
2257 // have been called simply to set the new JNIEnv.
2258 if (_Jv_ThreadCurrent () == NULL
)
2263 _Jv_AttachCurrentThreadAsDaemon (name
, group
);
2265 _Jv_AttachCurrentThread (name
, group
);
2267 catch (jthrowable t
)
2272 _Jv_SetCurrentJNIEnv (env
);
2277 // This is the one actually used by JNI.
2279 (JNICALL _Jv_JNI_AttachCurrentThread
) (JavaVM
*vm
, void **penv
, void *args
)
2281 return _Jv_JNI_AttachCurrentThread (vm
, NULL
, penv
, args
, false);
2285 (JNICALL _Jv_JNI_AttachCurrentThreadAsDaemon
) (JavaVM
*vm
, void **penv
,
2288 return _Jv_JNI_AttachCurrentThread (vm
, NULL
, penv
, args
, true);
2292 (JNICALL _Jv_JNI_DestroyJavaVM
) (JavaVM
*vm
)
2294 JvAssert (the_vm
&& vm
== the_vm
);
2297 if (_Jv_ThreadCurrent () != NULL
)
2303 main_name
= JvNewStringLatin1 ("main");
2305 catch (jthrowable t
)
2310 jint r
= _Jv_JNI_AttachCurrentThread (vm
, main_name
,
2311 reinterpret_cast<void **> (&env
),
2317 env
= _Jv_GetCurrentJNIEnv ();
2321 // Docs say that this always returns an error code.
2326 (JNICALL _Jv_JNI_DetachCurrentThread
) (JavaVM
*)
2328 jint code
= _Jv_DetachCurrentThread ();
2329 return code
? JNI_EDETACHED
: 0;
2333 (JNICALL _Jv_JNI_GetEnv
) (JavaVM
*, void **penv
, jint version
)
2335 if (_Jv_ThreadCurrent () == NULL
)
2338 return JNI_EDETACHED
;
2342 // Handle JVMPI requests.
2343 if (version
== JVMPI_VERSION_1
)
2345 *penv
= (void *) &_Jv_JVMPI_Interface
;
2350 // FIXME: do we really want to support 1.1?
2351 if (version
!= JNI_VERSION_1_4
&& version
!= JNI_VERSION_1_2
2352 && version
!= JNI_VERSION_1_1
)
2355 return JNI_EVERSION
;
2358 *penv
= (void *) _Jv_GetCurrentJNIEnv ();
2362 JNIEXPORT jint JNICALL
2363 JNI_GetDefaultJavaVMInitArgs (void *args
)
2365 jint version
= * (jint
*) args
;
2366 // Here we only support 1.2 and 1.4.
2367 if (version
!= JNI_VERSION_1_2
&& version
!= JNI_VERSION_1_4
)
2368 return JNI_EVERSION
;
2370 JavaVMInitArgs
*ia
= reinterpret_cast<JavaVMInitArgs
*> (args
);
2371 ia
->version
= JNI_VERSION_1_4
;
2374 ia
->ignoreUnrecognized
= true;
2379 JNIEXPORT jint JNICALL
2380 JNI_CreateJavaVM (JavaVM
**vm
, void **penv
, void *args
)
2382 JvAssert (! the_vm
);
2384 _Jv_CreateJavaVM (NULL
);
2386 // FIXME: synchronize
2387 JavaVM
*nvm
= (JavaVM
*) _Jv_MallocUnchecked (sizeof (JavaVM
));
2390 nvm
->functions
= &_Jv_JNI_InvokeFunctions
;
2392 // Parse the arguments.
2395 jint version
= * (jint
*) args
;
2396 // We only support 1.2 and 1.4.
2397 if (version
!= JNI_VERSION_1_2
&& version
!= JNI_VERSION_1_4
)
2398 return JNI_EVERSION
;
2399 JavaVMInitArgs
*ia
= reinterpret_cast<JavaVMInitArgs
*> (args
);
2400 for (int i
= 0; i
< ia
->nOptions
; ++i
)
2402 if (! strcmp (ia
->options
[i
].optionString
, "vfprintf")
2403 || ! strcmp (ia
->options
[i
].optionString
, "exit")
2404 || ! strcmp (ia
->options
[i
].optionString
, "abort"))
2406 // We are required to recognize these, but for now we
2407 // don't handle them in any way. FIXME.
2410 else if (! strncmp (ia
->options
[i
].optionString
,
2411 "-verbose", sizeof ("-verbose") - 1))
2413 // We don't do anything with this option either. We
2414 // might want to make sure the argument is valid, but we
2415 // don't really care all that much for now.
2418 else if (! strncmp (ia
->options
[i
].optionString
, "-D", 2))
2423 else if (ia
->ignoreUnrecognized
)
2425 if (ia
->options
[i
].optionString
[0] == '_'
2426 || ! strncmp (ia
->options
[i
].optionString
, "-X", 2))
2434 jint r
=_Jv_JNI_AttachCurrentThread (nvm
, penv
, NULL
);
2444 JNIEXPORT jint JNICALL
2445 JNI_GetCreatedJavaVMs (JavaVM
**vm_buffer
, jsize buf_len
, jsize
*n_vms
)
2450 // We only support a single VM.
2453 vm_buffer
[0] = the_vm
;
2464 // FIXME: synchronize
2467 JavaVM
*nvm
= (JavaVM
*) _Jv_MallocUnchecked (sizeof (JavaVM
));
2469 nvm
->functions
= &_Jv_JNI_InvokeFunctions
;
2473 // If this is a Java thread, we want to make sure it has an
2474 // associated JNIEnv.
2475 if (_Jv_ThreadCurrent () != NULL
)
2478 _Jv_JNI_AttachCurrentThread (the_vm
, &ignore
, NULL
);
2485 (JNICALL _Jv_JNI_GetJavaVM
) (JNIEnv
*, JavaVM
**vm
)
2487 *vm
= _Jv_GetJavaVM ();
2488 return *vm
== NULL
? JNI_ERR
: JNI_OK
;
2493 #define RESERVED NULL
2495 struct JNINativeInterface _Jv_JNIFunctions
=
2501 _Jv_JNI_GetVersion
, // GetVersion
2502 _Jv_JNI_DefineClass
, // DefineClass
2503 _Jv_JNI_FindClass
, // FindClass
2504 _Jv_JNI_FromReflectedMethod
, // FromReflectedMethod
2505 _Jv_JNI_FromReflectedField
, // FromReflectedField
2506 _Jv_JNI_ToReflectedMethod
, // ToReflectedMethod
2507 _Jv_JNI_GetSuperclass
, // GetSuperclass
2508 _Jv_JNI_IsAssignableFrom
, // IsAssignableFrom
2509 _Jv_JNI_ToReflectedField
, // ToReflectedField
2510 _Jv_JNI_Throw
, // Throw
2511 _Jv_JNI_ThrowNew
, // ThrowNew
2512 _Jv_JNI_ExceptionOccurred
, // ExceptionOccurred
2513 _Jv_JNI_ExceptionDescribe
, // ExceptionDescribe
2514 _Jv_JNI_ExceptionClear
, // ExceptionClear
2515 _Jv_JNI_FatalError
, // FatalError
2517 _Jv_JNI_PushLocalFrame
, // PushLocalFrame
2518 _Jv_JNI_PopLocalFrame
, // PopLocalFrame
2519 _Jv_JNI_NewGlobalRef
, // NewGlobalRef
2520 _Jv_JNI_DeleteGlobalRef
, // DeleteGlobalRef
2521 _Jv_JNI_DeleteLocalRef
, // DeleteLocalRef
2523 _Jv_JNI_IsSameObject
, // IsSameObject
2525 _Jv_JNI_NewLocalRef
, // NewLocalRef
2526 _Jv_JNI_EnsureLocalCapacity
, // EnsureLocalCapacity
2528 _Jv_JNI_AllocObject
, // AllocObject
2529 _Jv_JNI_NewObject
, // NewObject
2530 _Jv_JNI_NewObjectV
, // NewObjectV
2531 _Jv_JNI_NewObjectA
, // NewObjectA
2532 _Jv_JNI_GetObjectClass
, // GetObjectClass
2533 _Jv_JNI_IsInstanceOf
, // IsInstanceOf
2534 _Jv_JNI_GetAnyMethodID
<false>, // GetMethodID
2536 _Jv_JNI_CallMethod
<jobject
>, // CallObjectMethod
2537 _Jv_JNI_CallMethodV
<jobject
>, // CallObjectMethodV
2538 _Jv_JNI_CallMethodA
<jobject
>, // CallObjectMethodA
2539 _Jv_JNI_CallMethod
<jboolean
>, // CallBooleanMethod
2540 _Jv_JNI_CallMethodV
<jboolean
>, // CallBooleanMethodV
2541 _Jv_JNI_CallMethodA
<jboolean
>, // CallBooleanMethodA
2542 _Jv_JNI_CallMethod
<jbyte
>, // CallByteMethod
2543 _Jv_JNI_CallMethodV
<jbyte
>, // CallByteMethodV
2544 _Jv_JNI_CallMethodA
<jbyte
>, // CallByteMethodA
2545 _Jv_JNI_CallMethod
<jchar
>, // CallCharMethod
2546 _Jv_JNI_CallMethodV
<jchar
>, // CallCharMethodV
2547 _Jv_JNI_CallMethodA
<jchar
>, // CallCharMethodA
2548 _Jv_JNI_CallMethod
<jshort
>, // CallShortMethod
2549 _Jv_JNI_CallMethodV
<jshort
>, // CallShortMethodV
2550 _Jv_JNI_CallMethodA
<jshort
>, // CallShortMethodA
2551 _Jv_JNI_CallMethod
<jint
>, // CallIntMethod
2552 _Jv_JNI_CallMethodV
<jint
>, // CallIntMethodV
2553 _Jv_JNI_CallMethodA
<jint
>, // CallIntMethodA
2554 _Jv_JNI_CallMethod
<jlong
>, // CallLongMethod
2555 _Jv_JNI_CallMethodV
<jlong
>, // CallLongMethodV
2556 _Jv_JNI_CallMethodA
<jlong
>, // CallLongMethodA
2557 _Jv_JNI_CallMethod
<jfloat
>, // CallFloatMethod
2558 _Jv_JNI_CallMethodV
<jfloat
>, // CallFloatMethodV
2559 _Jv_JNI_CallMethodA
<jfloat
>, // CallFloatMethodA
2560 _Jv_JNI_CallMethod
<jdouble
>, // CallDoubleMethod
2561 _Jv_JNI_CallMethodV
<jdouble
>, // CallDoubleMethodV
2562 _Jv_JNI_CallMethodA
<jdouble
>, // CallDoubleMethodA
2563 _Jv_JNI_CallVoidMethod
, // CallVoidMethod
2564 _Jv_JNI_CallVoidMethodV
, // CallVoidMethodV
2565 _Jv_JNI_CallVoidMethodA
, // CallVoidMethodA
2567 // Nonvirtual method invocation functions follow.
2568 _Jv_JNI_CallAnyMethod
<jobject
, nonvirtual
>, // CallNonvirtualObjectMethod
2569 _Jv_JNI_CallAnyMethodV
<jobject
, nonvirtual
>, // CallNonvirtualObjectMethodV
2570 _Jv_JNI_CallAnyMethodA
<jobject
, nonvirtual
>, // CallNonvirtualObjectMethodA
2571 _Jv_JNI_CallAnyMethod
<jboolean
, nonvirtual
>, // CallNonvirtualBooleanMethod
2572 _Jv_JNI_CallAnyMethodV
<jboolean
, nonvirtual
>, // CallNonvirtualBooleanMethodV
2573 _Jv_JNI_CallAnyMethodA
<jboolean
, nonvirtual
>, // CallNonvirtualBooleanMethodA
2574 _Jv_JNI_CallAnyMethod
<jbyte
, nonvirtual
>, // CallNonvirtualByteMethod
2575 _Jv_JNI_CallAnyMethodV
<jbyte
, nonvirtual
>, // CallNonvirtualByteMethodV
2576 _Jv_JNI_CallAnyMethodA
<jbyte
, nonvirtual
>, // CallNonvirtualByteMethodA
2577 _Jv_JNI_CallAnyMethod
<jchar
, nonvirtual
>, // CallNonvirtualCharMethod
2578 _Jv_JNI_CallAnyMethodV
<jchar
, nonvirtual
>, // CallNonvirtualCharMethodV
2579 _Jv_JNI_CallAnyMethodA
<jchar
, nonvirtual
>, // CallNonvirtualCharMethodA
2580 _Jv_JNI_CallAnyMethod
<jshort
, nonvirtual
>, // CallNonvirtualShortMethod
2581 _Jv_JNI_CallAnyMethodV
<jshort
, nonvirtual
>, // CallNonvirtualShortMethodV
2582 _Jv_JNI_CallAnyMethodA
<jshort
, nonvirtual
>, // CallNonvirtualShortMethodA
2583 _Jv_JNI_CallAnyMethod
<jint
, nonvirtual
>, // CallNonvirtualIntMethod
2584 _Jv_JNI_CallAnyMethodV
<jint
, nonvirtual
>, // CallNonvirtualIntMethodV
2585 _Jv_JNI_CallAnyMethodA
<jint
, nonvirtual
>, // CallNonvirtualIntMethodA
2586 _Jv_JNI_CallAnyMethod
<jlong
, nonvirtual
>, // CallNonvirtualLongMethod
2587 _Jv_JNI_CallAnyMethodV
<jlong
, nonvirtual
>, // CallNonvirtualLongMethodV
2588 _Jv_JNI_CallAnyMethodA
<jlong
, nonvirtual
>, // CallNonvirtualLongMethodA
2589 _Jv_JNI_CallAnyMethod
<jfloat
, nonvirtual
>, // CallNonvirtualFloatMethod
2590 _Jv_JNI_CallAnyMethodV
<jfloat
, nonvirtual
>, // CallNonvirtualFloatMethodV
2591 _Jv_JNI_CallAnyMethodA
<jfloat
, nonvirtual
>, // CallNonvirtualFloatMethodA
2592 _Jv_JNI_CallAnyMethod
<jdouble
, nonvirtual
>, // CallNonvirtualDoubleMethod
2593 _Jv_JNI_CallAnyMethodV
<jdouble
, nonvirtual
>, // CallNonvirtualDoubleMethodV
2594 _Jv_JNI_CallAnyMethodA
<jdouble
, nonvirtual
>, // CallNonvirtualDoubleMethodA
2595 _Jv_JNI_CallAnyVoidMethod
<nonvirtual
>, // CallNonvirtualVoidMethod
2596 _Jv_JNI_CallAnyVoidMethodV
<nonvirtual
>, // CallNonvirtualVoidMethodV
2597 _Jv_JNI_CallAnyVoidMethodA
<nonvirtual
>, // CallNonvirtualVoidMethodA
2599 _Jv_JNI_GetAnyFieldID
<false>, // GetFieldID
2600 _Jv_JNI_GetField
<jobject
>, // GetObjectField
2601 _Jv_JNI_GetField
<jboolean
>, // GetBooleanField
2602 _Jv_JNI_GetField
<jbyte
>, // GetByteField
2603 _Jv_JNI_GetField
<jchar
>, // GetCharField
2604 _Jv_JNI_GetField
<jshort
>, // GetShortField
2605 _Jv_JNI_GetField
<jint
>, // GetIntField
2606 _Jv_JNI_GetField
<jlong
>, // GetLongField
2607 _Jv_JNI_GetField
<jfloat
>, // GetFloatField
2608 _Jv_JNI_GetField
<jdouble
>, // GetDoubleField
2609 _Jv_JNI_SetField
, // SetObjectField
2610 _Jv_JNI_SetField
, // SetBooleanField
2611 _Jv_JNI_SetField
, // SetByteField
2612 _Jv_JNI_SetField
, // SetCharField
2613 _Jv_JNI_SetField
, // SetShortField
2614 _Jv_JNI_SetField
, // SetIntField
2615 _Jv_JNI_SetField
, // SetLongField
2616 _Jv_JNI_SetField
, // SetFloatField
2617 _Jv_JNI_SetField
, // SetDoubleField
2618 _Jv_JNI_GetAnyMethodID
<true>, // GetStaticMethodID
2620 _Jv_JNI_CallStaticMethod
<jobject
>, // CallStaticObjectMethod
2621 _Jv_JNI_CallStaticMethodV
<jobject
>, // CallStaticObjectMethodV
2622 _Jv_JNI_CallStaticMethodA
<jobject
>, // CallStaticObjectMethodA
2623 _Jv_JNI_CallStaticMethod
<jboolean
>, // CallStaticBooleanMethod
2624 _Jv_JNI_CallStaticMethodV
<jboolean
>, // CallStaticBooleanMethodV
2625 _Jv_JNI_CallStaticMethodA
<jboolean
>, // CallStaticBooleanMethodA
2626 _Jv_JNI_CallStaticMethod
<jbyte
>, // CallStaticByteMethod
2627 _Jv_JNI_CallStaticMethodV
<jbyte
>, // CallStaticByteMethodV
2628 _Jv_JNI_CallStaticMethodA
<jbyte
>, // CallStaticByteMethodA
2629 _Jv_JNI_CallStaticMethod
<jchar
>, // CallStaticCharMethod
2630 _Jv_JNI_CallStaticMethodV
<jchar
>, // CallStaticCharMethodV
2631 _Jv_JNI_CallStaticMethodA
<jchar
>, // CallStaticCharMethodA
2632 _Jv_JNI_CallStaticMethod
<jshort
>, // CallStaticShortMethod
2633 _Jv_JNI_CallStaticMethodV
<jshort
>, // CallStaticShortMethodV
2634 _Jv_JNI_CallStaticMethodA
<jshort
>, // CallStaticShortMethodA
2635 _Jv_JNI_CallStaticMethod
<jint
>, // CallStaticIntMethod
2636 _Jv_JNI_CallStaticMethodV
<jint
>, // CallStaticIntMethodV
2637 _Jv_JNI_CallStaticMethodA
<jint
>, // CallStaticIntMethodA
2638 _Jv_JNI_CallStaticMethod
<jlong
>, // CallStaticLongMethod
2639 _Jv_JNI_CallStaticMethodV
<jlong
>, // CallStaticLongMethodV
2640 _Jv_JNI_CallStaticMethodA
<jlong
>, // CallStaticLongMethodA
2641 _Jv_JNI_CallStaticMethod
<jfloat
>, // CallStaticFloatMethod
2642 _Jv_JNI_CallStaticMethodV
<jfloat
>, // CallStaticFloatMethodV
2643 _Jv_JNI_CallStaticMethodA
<jfloat
>, // CallStaticFloatMethodA
2644 _Jv_JNI_CallStaticMethod
<jdouble
>, // CallStaticDoubleMethod
2645 _Jv_JNI_CallStaticMethodV
<jdouble
>, // CallStaticDoubleMethodV
2646 _Jv_JNI_CallStaticMethodA
<jdouble
>, // CallStaticDoubleMethodA
2647 _Jv_JNI_CallStaticVoidMethod
, // CallStaticVoidMethod
2648 _Jv_JNI_CallStaticVoidMethodV
, // CallStaticVoidMethodV
2649 _Jv_JNI_CallStaticVoidMethodA
, // CallStaticVoidMethodA
2651 _Jv_JNI_GetAnyFieldID
<true>, // GetStaticFieldID
2652 _Jv_JNI_GetStaticField
<jobject
>, // GetStaticObjectField
2653 _Jv_JNI_GetStaticField
<jboolean
>, // GetStaticBooleanField
2654 _Jv_JNI_GetStaticField
<jbyte
>, // GetStaticByteField
2655 _Jv_JNI_GetStaticField
<jchar
>, // GetStaticCharField
2656 _Jv_JNI_GetStaticField
<jshort
>, // GetStaticShortField
2657 _Jv_JNI_GetStaticField
<jint
>, // GetStaticIntField
2658 _Jv_JNI_GetStaticField
<jlong
>, // GetStaticLongField
2659 _Jv_JNI_GetStaticField
<jfloat
>, // GetStaticFloatField
2660 _Jv_JNI_GetStaticField
<jdouble
>, // GetStaticDoubleField
2661 _Jv_JNI_SetStaticField
, // SetStaticObjectField
2662 _Jv_JNI_SetStaticField
, // SetStaticBooleanField
2663 _Jv_JNI_SetStaticField
, // SetStaticByteField
2664 _Jv_JNI_SetStaticField
, // SetStaticCharField
2665 _Jv_JNI_SetStaticField
, // SetStaticShortField
2666 _Jv_JNI_SetStaticField
, // SetStaticIntField
2667 _Jv_JNI_SetStaticField
, // SetStaticLongField
2668 _Jv_JNI_SetStaticField
, // SetStaticFloatField
2669 _Jv_JNI_SetStaticField
, // SetStaticDoubleField
2670 _Jv_JNI_NewString
, // NewString
2671 _Jv_JNI_GetStringLength
, // GetStringLength
2672 _Jv_JNI_GetStringChars
, // GetStringChars
2673 _Jv_JNI_ReleaseStringChars
, // ReleaseStringChars
2674 _Jv_JNI_NewStringUTF
, // NewStringUTF
2675 _Jv_JNI_GetStringUTFLength
, // GetStringUTFLength
2676 _Jv_JNI_GetStringUTFChars
, // GetStringUTFChars
2677 _Jv_JNI_ReleaseStringUTFChars
, // ReleaseStringUTFChars
2678 _Jv_JNI_GetArrayLength
, // GetArrayLength
2679 _Jv_JNI_NewObjectArray
, // NewObjectArray
2680 _Jv_JNI_GetObjectArrayElement
, // GetObjectArrayElement
2681 _Jv_JNI_SetObjectArrayElement
, // SetObjectArrayElement
2682 _Jv_JNI_NewPrimitiveArray
<jboolean
, JvPrimClass (boolean
)>,
2684 _Jv_JNI_NewPrimitiveArray
<jbyte
, JvPrimClass (byte
)>, // NewByteArray
2685 _Jv_JNI_NewPrimitiveArray
<jchar
, JvPrimClass (char)>, // NewCharArray
2686 _Jv_JNI_NewPrimitiveArray
<jshort
, JvPrimClass (short)>, // NewShortArray
2687 _Jv_JNI_NewPrimitiveArray
<jint
, JvPrimClass (int)>, // NewIntArray
2688 _Jv_JNI_NewPrimitiveArray
<jlong
, JvPrimClass (long)>, // NewLongArray
2689 _Jv_JNI_NewPrimitiveArray
<jfloat
, JvPrimClass (float)>, // NewFloatArray
2690 _Jv_JNI_NewPrimitiveArray
<jdouble
, JvPrimClass (double)>, // NewDoubleArray
2691 _Jv_JNI_GetPrimitiveArrayElements
, // GetBooleanArrayElements
2692 _Jv_JNI_GetPrimitiveArrayElements
, // GetByteArrayElements
2693 _Jv_JNI_GetPrimitiveArrayElements
, // GetCharArrayElements
2694 _Jv_JNI_GetPrimitiveArrayElements
, // GetShortArrayElements
2695 _Jv_JNI_GetPrimitiveArrayElements
, // GetIntArrayElements
2696 _Jv_JNI_GetPrimitiveArrayElements
, // GetLongArrayElements
2697 _Jv_JNI_GetPrimitiveArrayElements
, // GetFloatArrayElements
2698 _Jv_JNI_GetPrimitiveArrayElements
, // GetDoubleArrayElements
2699 _Jv_JNI_ReleasePrimitiveArrayElements
, // ReleaseBooleanArrayElements
2700 _Jv_JNI_ReleasePrimitiveArrayElements
, // ReleaseByteArrayElements
2701 _Jv_JNI_ReleasePrimitiveArrayElements
, // ReleaseCharArrayElements
2702 _Jv_JNI_ReleasePrimitiveArrayElements
, // ReleaseShortArrayElements
2703 _Jv_JNI_ReleasePrimitiveArrayElements
, // ReleaseIntArrayElements
2704 _Jv_JNI_ReleasePrimitiveArrayElements
, // ReleaseLongArrayElements
2705 _Jv_JNI_ReleasePrimitiveArrayElements
, // ReleaseFloatArrayElements
2706 _Jv_JNI_ReleasePrimitiveArrayElements
, // ReleaseDoubleArrayElements
2707 _Jv_JNI_GetPrimitiveArrayRegion
, // GetBooleanArrayRegion
2708 _Jv_JNI_GetPrimitiveArrayRegion
, // GetByteArrayRegion
2709 _Jv_JNI_GetPrimitiveArrayRegion
, // GetCharArrayRegion
2710 _Jv_JNI_GetPrimitiveArrayRegion
, // GetShortArrayRegion
2711 _Jv_JNI_GetPrimitiveArrayRegion
, // GetIntArrayRegion
2712 _Jv_JNI_GetPrimitiveArrayRegion
, // GetLongArrayRegion
2713 _Jv_JNI_GetPrimitiveArrayRegion
, // GetFloatArrayRegion
2714 _Jv_JNI_GetPrimitiveArrayRegion
, // GetDoubleArrayRegion
2715 _Jv_JNI_SetPrimitiveArrayRegion
, // SetBooleanArrayRegion
2716 _Jv_JNI_SetPrimitiveArrayRegion
, // SetByteArrayRegion
2717 _Jv_JNI_SetPrimitiveArrayRegion
, // SetCharArrayRegion
2718 _Jv_JNI_SetPrimitiveArrayRegion
, // SetShortArrayRegion
2719 _Jv_JNI_SetPrimitiveArrayRegion
, // SetIntArrayRegion
2720 _Jv_JNI_SetPrimitiveArrayRegion
, // SetLongArrayRegion
2721 _Jv_JNI_SetPrimitiveArrayRegion
, // SetFloatArrayRegion
2722 _Jv_JNI_SetPrimitiveArrayRegion
, // SetDoubleArrayRegion
2723 _Jv_JNI_RegisterNatives
, // RegisterNatives
2724 _Jv_JNI_UnregisterNatives
, // UnregisterNatives
2725 _Jv_JNI_MonitorEnter
, // MonitorEnter
2726 _Jv_JNI_MonitorExit
, // MonitorExit
2727 _Jv_JNI_GetJavaVM
, // GetJavaVM
2729 _Jv_JNI_GetStringRegion
, // GetStringRegion
2730 _Jv_JNI_GetStringUTFRegion
, // GetStringUTFRegion
2731 _Jv_JNI_GetPrimitiveArrayCritical
, // GetPrimitiveArrayCritical
2732 _Jv_JNI_ReleasePrimitiveArrayCritical
, // ReleasePrimitiveArrayCritical
2733 _Jv_JNI_GetStringCritical
, // GetStringCritical
2734 _Jv_JNI_ReleaseStringCritical
, // ReleaseStringCritical
2736 _Jv_JNI_NewWeakGlobalRef
, // NewWeakGlobalRef
2737 _Jv_JNI_DeleteWeakGlobalRef
, // DeleteWeakGlobalRef
2739 _Jv_JNI_ExceptionCheck
, // ExceptionCheck
2741 _Jv_JNI_NewDirectByteBuffer
, // NewDirectByteBuffer
2742 _Jv_JNI_GetDirectBufferAddress
, // GetDirectBufferAddress
2743 _Jv_JNI_GetDirectBufferCapacity
// GetDirectBufferCapacity
2746 struct JNIInvokeInterface _Jv_JNI_InvokeFunctions
=
2752 _Jv_JNI_DestroyJavaVM
,
2753 _Jv_JNI_AttachCurrentThread
,
2754 _Jv_JNI_DetachCurrentThread
,
2756 _Jv_JNI_AttachCurrentThreadAsDaemon