1 // jni.cc - JNI implementation, including the jump table.
3 /* Copyright (C) 1998, 1999, 2000, 2001, 2002 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
18 #include <java-assert.h>
24 #include <java/lang/Class.h>
25 #include <java/lang/ClassLoader.h>
26 #include <java/lang/Throwable.h>
27 #include <java/lang/ArrayIndexOutOfBoundsException.h>
28 #include <java/lang/StringIndexOutOfBoundsException.h>
29 #include <java/lang/UnsatisfiedLinkError.h>
30 #include <java/lang/InstantiationException.h>
31 #include <java/lang/NoSuchFieldError.h>
32 #include <java/lang/NoSuchMethodError.h>
33 #include <java/lang/reflect/Constructor.h>
34 #include <java/lang/reflect/Method.h>
35 #include <java/lang/reflect/Modifier.h>
36 #include <java/lang/OutOfMemoryError.h>
37 #include <java/util/IdentityHashMap.h>
38 #include <java/lang/Integer.h>
39 #include <java/lang/ThreadGroup.h>
40 #include <java/lang/Thread.h>
42 #include <gcj/method.h>
43 #include <gcj/field.h>
45 #include <java-interp.h>
46 #include <java-threads.h>
50 // This enum is used to select different template instantiations in
51 // the invocation code.
60 // Forward declarations.
61 extern struct JNINativeInterface _Jv_JNIFunctions
;
62 extern struct JNIInvokeInterface _Jv_JNI_InvokeFunctions
;
64 // Number of slots in the default frame. The VM must allow at least
68 // Mark value indicating this is an overflow frame.
70 // Mark value indicating this is a user frame.
72 // Mark value indicating this is a system frame.
75 // This structure is used to keep track of local references.
76 struct _Jv_JNI_LocalFrame
78 // This is true if this frame object represents a pushed frame (eg
79 // from PushLocalFrame).
82 // Number of elements in frame.
85 // Next frame in chain.
86 _Jv_JNI_LocalFrame
*next
;
88 // The elements. These are allocated using the C "struct hack".
92 // This holds a reference count for all local references.
93 static java::util::IdentityHashMap
*local_ref_table
;
94 // This holds a reference count for all global references.
95 static java::util::IdentityHashMap
*global_ref_table
;
98 static JavaVM
*the_vm
;
101 // The only JVMPI interface description.
102 static JVMPI_Interface _Jv_JVMPI_Interface
;
105 jvmpiEnableEvent (jint event_type
, void *)
109 case JVMPI_EVENT_OBJECT_ALLOC
:
110 _Jv_JVMPI_Notify_OBJECT_ALLOC
= _Jv_JVMPI_Interface
.NotifyEvent
;
113 case JVMPI_EVENT_THREAD_START
:
114 _Jv_JVMPI_Notify_THREAD_START
= _Jv_JVMPI_Interface
.NotifyEvent
;
117 case JVMPI_EVENT_THREAD_END
:
118 _Jv_JVMPI_Notify_THREAD_END
= _Jv_JVMPI_Interface
.NotifyEvent
;
122 return JVMPI_NOT_AVAILABLE
;
125 return JVMPI_SUCCESS
;
129 jvmpiDisableEvent (jint event_type
, void *)
133 case JVMPI_EVENT_OBJECT_ALLOC
:
134 _Jv_JVMPI_Notify_OBJECT_ALLOC
= NULL
;
138 return JVMPI_NOT_AVAILABLE
;
141 return JVMPI_SUCCESS
;
150 local_ref_table
= new java::util::IdentityHashMap
;
151 global_ref_table
= new java::util::IdentityHashMap
;
154 _Jv_JVMPI_Interface
.version
= 1;
155 _Jv_JVMPI_Interface
.EnableEvent
= &jvmpiEnableEvent
;
156 _Jv_JVMPI_Interface
.DisableEvent
= &jvmpiDisableEvent
;
157 _Jv_JVMPI_Interface
.EnableGC
= &_Jv_EnableGC
;
158 _Jv_JVMPI_Interface
.DisableGC
= &_Jv_DisableGC
;
159 _Jv_JVMPI_Interface
.RunGC
= &_Jv_RunGC
;
163 // Tell the GC that a certain pointer is live.
165 mark_for_gc (jobject obj
, java::util::IdentityHashMap
*ref_table
)
167 JvSynchronize
sync (ref_table
);
169 using namespace java::lang
;
170 Integer
*refcount
= (Integer
*) ref_table
->get (obj
);
171 jint val
= (refcount
== NULL
) ? 0 : refcount
->intValue ();
172 // FIXME: what about out of memory error?
173 ref_table
->put (obj
, new Integer (val
+ 1));
178 unmark_for_gc (jobject obj
, java::util::IdentityHashMap
*ref_table
)
180 JvSynchronize
sync (ref_table
);
182 using namespace java::lang
;
183 Integer
*refcount
= (Integer
*) ref_table
->get (obj
);
185 jint val
= refcount
->intValue () - 1;
188 ref_table
->remove (obj
);
190 // FIXME: what about out of memory error?
191 ref_table
->put (obj
, new Integer (val
));
194 // "Unwrap" some random non-reference type. This exists to simplify
195 // other template functions.
203 // Unwrap a weak reference, if required.
208 using namespace gnu::gcj::runtime
;
209 // We can compare the class directly because JNIWeakRef is `final'.
210 // Doing it this way is much faster.
211 if (obj
== NULL
|| obj
->getClass () != &JNIWeakRef::class$
)
213 JNIWeakRef
*wr
= reinterpret_cast<JNIWeakRef
*> (obj
);
214 return reinterpret_cast<T
*> (wr
->get ());
220 (JNICALL _Jv_JNI_NewGlobalRef
) (JNIEnv
*, jobject obj
)
222 // This seems weird but I think it is correct.
224 mark_for_gc (obj
, global_ref_table
);
229 (JNICALL _Jv_JNI_DeleteGlobalRef
) (JNIEnv
*, jobject obj
)
231 // This seems weird but I think it is correct.
233 unmark_for_gc (obj
, global_ref_table
);
237 (JNICALL _Jv_JNI_DeleteLocalRef
) (JNIEnv
*env
, jobject obj
)
239 _Jv_JNI_LocalFrame
*frame
;
241 // This seems weird but I think it is correct.
244 for (frame
= env
->locals
; frame
!= NULL
; frame
= frame
->next
)
246 for (int i
= 0; i
< frame
->size
; ++i
)
248 if (frame
->vec
[i
] == obj
)
250 frame
->vec
[i
] = NULL
;
251 unmark_for_gc (obj
, local_ref_table
);
256 // Don't go past a marked frame.
257 JvAssert (frame
->marker
== MARK_NONE
);
264 (JNICALL _Jv_JNI_EnsureLocalCapacity
) (JNIEnv
*env
, jint size
)
266 // It is easier to just always allocate a new frame of the requested
267 // size. This isn't the most efficient thing, but for now we don't
268 // care. Note that _Jv_JNI_PushLocalFrame relies on this right now.
270 _Jv_JNI_LocalFrame
*frame
;
273 frame
= (_Jv_JNI_LocalFrame
*) _Jv_Malloc (sizeof (_Jv_JNI_LocalFrame
)
274 + size
* sizeof (jobject
));
282 frame
->marker
= MARK_NONE
;
284 memset (&frame
->vec
[0], 0, size
* sizeof (jobject
));
285 frame
->next
= env
->locals
;
292 (JNICALL _Jv_JNI_PushLocalFrame
) (JNIEnv
*env
, jint size
)
294 jint r
= _Jv_JNI_EnsureLocalCapacity (env
, size
);
298 // The new frame is on top.
299 env
->locals
->marker
= MARK_USER
;
305 (JNICALL _Jv_JNI_NewLocalRef
) (JNIEnv
*env
, jobject obj
)
307 // This seems weird but I think it is correct.
310 // Try to find an open slot somewhere in the topmost frame.
311 _Jv_JNI_LocalFrame
*frame
= env
->locals
;
312 bool done
= false, set
= false;
313 for (; frame
!= NULL
&& ! done
; frame
= frame
->next
)
315 for (int i
= 0; i
< frame
->size
; ++i
)
317 if (frame
->vec
[i
] == NULL
)
326 // If we found a slot, or if the frame we just searched is the
327 // mark frame, then we are done.
328 if (done
|| frame
== NULL
|| frame
->marker
!= MARK_NONE
)
334 // No slots, so we allocate a new frame. According to the spec
335 // we could just die here. FIXME: return value.
336 _Jv_JNI_EnsureLocalCapacity (env
, 16);
337 // We know the first element of the new frame will be ok.
338 env
->locals
->vec
[0] = obj
;
341 mark_for_gc (obj
, local_ref_table
);
346 (JNICALL _Jv_JNI_PopLocalFrame
) (JNIEnv
*env
, jobject result
, int stop
)
348 _Jv_JNI_LocalFrame
*rf
= env
->locals
;
351 while (rf
!= NULL
&& ! done
)
353 for (int i
= 0; i
< rf
->size
; ++i
)
354 if (rf
->vec
[i
] != NULL
)
355 unmark_for_gc (rf
->vec
[i
], local_ref_table
);
357 // If the frame we just freed is the marker frame, we are done.
358 done
= (rf
->marker
== stop
);
360 _Jv_JNI_LocalFrame
*n
= rf
->next
;
361 // When N==NULL, we've reached the stack-allocated frame, and we
362 // must not free it. However, we must be sure to clear all its
363 // elements, since we might conceivably reuse it.
366 memset (&rf
->vec
[0], 0, rf
->size
* sizeof (jobject
));
374 // Update the local frame information.
377 return result
== NULL
? NULL
: _Jv_JNI_NewLocalRef (env
, result
);
381 (JNICALL _Jv_JNI_PopLocalFrame
) (JNIEnv
*env
, jobject result
)
383 return _Jv_JNI_PopLocalFrame (env
, result
, MARK_USER
);
386 // Pop a `system' frame from the stack. This is `extern "C"' as it is
387 // used by the compiler.
389 _Jv_JNI_PopSystemFrame (JNIEnv
*env
)
391 _Jv_JNI_PopLocalFrame (env
, NULL
, MARK_SYSTEM
);
395 jthrowable t
= env
->ex
;
401 // This function is used from other template functions. It wraps the
402 // return value appropriately; we specialize it so that object returns
403 // are turned into local references.
406 wrap_value (JNIEnv
*, T value
)
411 // This specialization is used for jobject, jclass, jstring, jarray,
415 wrap_value (JNIEnv
*env
, T
*value
)
417 return (value
== NULL
419 : (T
*) _Jv_JNI_NewLocalRef (env
, (jobject
) value
));
425 (JNICALL _Jv_JNI_GetVersion
) (JNIEnv
*)
427 return JNI_VERSION_1_4
;
431 (JNICALL _Jv_JNI_DefineClass
) (JNIEnv
*env
, const char *name
, jobject loader
,
432 const jbyte
*buf
, jsize bufLen
)
436 loader
= unwrap (loader
);
438 jstring sname
= JvNewStringUTF (name
);
439 jbyteArray bytes
= JvNewByteArray (bufLen
);
441 jbyte
*elts
= elements (bytes
);
442 memcpy (elts
, buf
, bufLen
* sizeof (jbyte
));
444 java::lang::ClassLoader
*l
445 = reinterpret_cast<java::lang::ClassLoader
*> (loader
);
447 jclass result
= l
->defineClass (sname
, bytes
, 0, bufLen
);
448 return (jclass
) wrap_value (env
, result
);
458 (JNICALL _Jv_JNI_FindClass
) (JNIEnv
*env
, const char *name
)
460 // FIXME: assume that NAME isn't too long.
461 int len
= strlen (name
);
463 for (int i
= 0; i
<= len
; ++i
)
464 s
[i
] = (name
[i
] == '/') ? '.' : name
[i
];
469 // This might throw an out of memory exception.
470 jstring n
= JvNewStringUTF (s
);
472 java::lang::ClassLoader
*loader
= NULL
;
473 if (env
->klass
!= NULL
)
474 loader
= env
->klass
->getClassLoader ();
478 // FIXME: should use getBaseClassLoader, but we don't have that
480 loader
= java::lang::ClassLoader::getSystemClassLoader ();
483 r
= loader
->loadClass (n
);
490 return (jclass
) wrap_value (env
, r
);
494 (JNICALL _Jv_JNI_GetSuperclass
) (JNIEnv
*env
, jclass clazz
)
496 return (jclass
) wrap_value (env
, unwrap (clazz
)->getSuperclass ());
500 (JNICALL _Jv_JNI_IsAssignableFrom
) (JNIEnv
*, jclass clazz1
, jclass clazz2
)
502 return unwrap (clazz1
)->isAssignableFrom (unwrap (clazz2
));
506 (JNICALL _Jv_JNI_Throw
) (JNIEnv
*env
, jthrowable obj
)
508 // We check in case the user did some funky cast.
510 JvAssert (obj
!= NULL
&& java::lang::Throwable::class$
.isInstance (obj
));
516 (JNICALL _Jv_JNI_ThrowNew
) (JNIEnv
*env
, jclass clazz
, const char *message
)
518 using namespace java::lang::reflect
;
520 clazz
= unwrap (clazz
);
521 JvAssert (java::lang::Throwable::class$
.isAssignableFrom (clazz
));
526 JArray
<jclass
> *argtypes
527 = (JArray
<jclass
> *) JvNewObjectArray (1, &java::lang::Class::class$
,
530 jclass
*elts
= elements (argtypes
);
531 elts
[0] = &StringClass
;
533 Constructor
*cons
= clazz
->getConstructor (argtypes
);
535 jobjectArray values
= JvNewObjectArray (1, &StringClass
, NULL
);
536 jobject
*velts
= elements (values
);
537 velts
[0] = JvNewStringUTF (message
);
539 jobject obj
= cons
->newInstance (values
);
541 env
->ex
= reinterpret_cast<jthrowable
> (obj
);
553 (JNICALL _Jv_JNI_ExceptionOccurred
) (JNIEnv
*env
)
555 return (jthrowable
) wrap_value (env
, env
->ex
);
559 (JNICALL _Jv_JNI_ExceptionDescribe
) (JNIEnv
*env
)
562 env
->ex
->printStackTrace();
566 (JNICALL _Jv_JNI_ExceptionClear
) (JNIEnv
*env
)
572 (JNICALL _Jv_JNI_ExceptionCheck
) (JNIEnv
*env
)
574 return env
->ex
!= NULL
;
578 (JNICALL _Jv_JNI_FatalError
) (JNIEnv
*, const char *message
)
586 (JNICALL _Jv_JNI_IsSameObject
) (JNIEnv
*, jobject obj1
, jobject obj2
)
588 return unwrap (obj1
) == unwrap (obj2
);
592 (JNICALL _Jv_JNI_AllocObject
) (JNIEnv
*env
, jclass clazz
)
595 using namespace java::lang::reflect
;
599 clazz
= unwrap (clazz
);
600 JvAssert (clazz
&& ! clazz
->isArray ());
601 if (clazz
->isInterface() || Modifier::isAbstract(clazz
->getModifiers()))
602 env
->ex
= new java::lang::InstantiationException ();
604 obj
= JvAllocObject (clazz
);
611 return wrap_value (env
, obj
);
615 (JNICALL _Jv_JNI_GetObjectClass
) (JNIEnv
*env
, jobject obj
)
619 return (jclass
) wrap_value (env
, obj
->getClass());
623 (JNICALL _Jv_JNI_IsInstanceOf
) (JNIEnv
*, jobject obj
, jclass clazz
)
625 return unwrap (clazz
)->isInstance(unwrap (obj
));
631 // This section concerns method invocation.
634 template<jboolean is_static
>
636 (JNICALL _Jv_JNI_GetAnyMethodID
) (JNIEnv
*env
, jclass clazz
,
637 const char *name
, const char *sig
)
641 clazz
= unwrap (clazz
);
642 _Jv_InitClass (clazz
);
644 _Jv_Utf8Const
*name_u
= _Jv_makeUtf8Const ((char *) name
, -1);
646 // FIXME: assume that SIG isn't too long.
647 int len
= strlen (sig
);
649 for (int i
= 0; i
<= len
; ++i
)
650 s
[i
] = (sig
[i
] == '/') ? '.' : sig
[i
];
651 _Jv_Utf8Const
*sig_u
= _Jv_makeUtf8Const ((char *) s
, -1);
653 JvAssert (! clazz
->isPrimitive());
655 using namespace java::lang::reflect
;
657 while (clazz
!= NULL
)
659 jint count
= JvNumMethods (clazz
);
660 jmethodID meth
= JvGetFirstMethod (clazz
);
662 for (jint i
= 0; i
< count
; ++i
)
664 if (((is_static
&& Modifier::isStatic (meth
->accflags
))
665 || (! is_static
&& ! Modifier::isStatic (meth
->accflags
)))
666 && _Jv_equalUtf8Consts (meth
->name
, name_u
)
667 && _Jv_equalUtf8Consts (meth
->signature
, sig_u
))
670 meth
= meth
->getNextMethod();
673 clazz
= clazz
->getSuperclass ();
676 env
->ex
= new java::lang::NoSuchMethodError ();
686 // This is a helper function which turns a va_list into an array of
687 // `jvalue's. It needs signature information in order to do its work.
688 // The array of values must already be allocated.
690 array_from_valist (jvalue
*values
, JArray
<jclass
> *arg_types
, va_list vargs
)
692 jclass
*arg_elts
= elements (arg_types
);
693 for (int i
= 0; i
< arg_types
->length
; ++i
)
695 // Here we assume that sizeof(int) >= sizeof(jint), because we
696 // use `int' when decoding the varargs. Likewise for
697 // float, and double. Also we assume that sizeof(jlong) >=
698 // sizeof(int), i.e. that jlong values are not further
700 JvAssert (sizeof (int) >= sizeof (jint
));
701 JvAssert (sizeof (jlong
) >= sizeof (int));
702 JvAssert (sizeof (double) >= sizeof (jfloat
));
703 JvAssert (sizeof (double) >= sizeof (jdouble
));
704 if (arg_elts
[i
] == JvPrimClass (byte
))
705 values
[i
].b
= (jbyte
) va_arg (vargs
, int);
706 else if (arg_elts
[i
] == JvPrimClass (short))
707 values
[i
].s
= (jshort
) va_arg (vargs
, int);
708 else if (arg_elts
[i
] == JvPrimClass (int))
709 values
[i
].i
= (jint
) va_arg (vargs
, int);
710 else if (arg_elts
[i
] == JvPrimClass (long))
711 values
[i
].j
= (jlong
) va_arg (vargs
, jlong
);
712 else if (arg_elts
[i
] == JvPrimClass (float))
713 values
[i
].f
= (jfloat
) va_arg (vargs
, double);
714 else if (arg_elts
[i
] == JvPrimClass (double))
715 values
[i
].d
= (jdouble
) va_arg (vargs
, double);
716 else if (arg_elts
[i
] == JvPrimClass (boolean
))
717 values
[i
].z
= (jboolean
) va_arg (vargs
, int);
718 else if (arg_elts
[i
] == JvPrimClass (char))
719 values
[i
].c
= (jchar
) va_arg (vargs
, int);
723 values
[i
].l
= unwrap (va_arg (vargs
, jobject
));
728 // This can call any sort of method: virtual, "nonvirtual", static, or
730 template<typename T
, invocation_type style
>
732 (JNICALL _Jv_JNI_CallAnyMethodV
) (JNIEnv
*env
, jobject obj
, jclass klass
,
733 jmethodID id
, va_list vargs
)
736 klass
= unwrap (klass
);
739 id
= _Jv_LookupDeclaredMethod (obj
->getClass (), id
->name
, id
->signature
);
741 jclass decl_class
= klass
? klass
: obj
->getClass ();
742 JvAssert (decl_class
!= NULL
);
745 JArray
<jclass
> *arg_types
;
749 _Jv_GetTypesFromSignature (id
, decl_class
,
750 &arg_types
, &return_type
);
752 jvalue args
[arg_types
->length
];
753 array_from_valist (args
, arg_types
, vargs
);
755 // For constructors we need to pass the Class we are instantiating.
756 if (style
== constructor
)
760 jthrowable ex
= _Jv_CallAnyMethodA (obj
, return_type
, id
,
761 style
== constructor
,
762 arg_types
, args
, &result
);
767 // We cheat a little here. FIXME.
768 return wrap_value (env
, * (T
*) &result
);
775 return wrap_value (env
, (T
) 0);
778 template<typename T
, invocation_type style
>
780 (JNICALL _Jv_JNI_CallAnyMethod
) (JNIEnv
*env
, jobject obj
, jclass klass
,
781 jmethodID method
, ...)
786 va_start (args
, method
);
787 result
= _Jv_JNI_CallAnyMethodV
<T
, style
> (env
, obj
, klass
, method
, args
);
793 template<typename T
, invocation_type style
>
795 (JNICALL _Jv_JNI_CallAnyMethodA
) (JNIEnv
*env
, jobject obj
, jclass klass
,
796 jmethodID id
, jvalue
*args
)
799 klass
= unwrap (klass
);
802 id
= _Jv_LookupDeclaredMethod (obj
->getClass (), id
->name
, id
->signature
);
804 jclass decl_class
= klass
? klass
: obj
->getClass ();
805 JvAssert (decl_class
!= NULL
);
808 JArray
<jclass
> *arg_types
;
811 _Jv_GetTypesFromSignature (id
, decl_class
,
812 &arg_types
, &return_type
);
814 // For constructors we need to pass the Class we are instantiating.
815 if (style
== constructor
)
818 // Unwrap arguments as required. Eww.
819 jclass
*type_elts
= elements (arg_types
);
820 jvalue arg_copy
[arg_types
->length
];
821 for (int i
= 0; i
< arg_types
->length
; ++i
)
823 if (type_elts
[i
]->isPrimitive ())
824 arg_copy
[i
] = args
[i
];
826 arg_copy
[i
].l
= unwrap (args
[i
].l
);
830 jthrowable ex
= _Jv_CallAnyMethodA (obj
, return_type
, id
,
831 style
== constructor
,
832 arg_types
, arg_copy
, &result
);
837 // We cheat a little here. FIXME.
838 return wrap_value (env
, * (T
*) &result
);
845 return wrap_value (env
, (T
) 0);
848 template<invocation_type style
>
850 (JNICALL _Jv_JNI_CallAnyVoidMethodV
) (JNIEnv
*env
, jobject obj
, jclass klass
,
851 jmethodID id
, va_list vargs
)
854 klass
= unwrap (klass
);
857 id
= _Jv_LookupDeclaredMethod (obj
->getClass (), id
->name
, id
->signature
);
859 jclass decl_class
= klass
? klass
: obj
->getClass ();
860 JvAssert (decl_class
!= NULL
);
863 JArray
<jclass
> *arg_types
;
866 _Jv_GetTypesFromSignature (id
, decl_class
,
867 &arg_types
, &return_type
);
869 jvalue args
[arg_types
->length
];
870 array_from_valist (args
, arg_types
, vargs
);
872 // For constructors we need to pass the Class we are instantiating.
873 if (style
== constructor
)
876 jthrowable ex
= _Jv_CallAnyMethodA (obj
, return_type
, id
,
877 style
== constructor
,
878 arg_types
, args
, NULL
);
889 template<invocation_type style
>
891 (JNICALL _Jv_JNI_CallAnyVoidMethod
) (JNIEnv
*env
, jobject obj
, jclass klass
,
892 jmethodID method
, ...)
896 va_start (args
, method
);
897 _Jv_JNI_CallAnyVoidMethodV
<style
> (env
, obj
, klass
, method
, args
);
901 template<invocation_type style
>
903 (JNICALL _Jv_JNI_CallAnyVoidMethodA
) (JNIEnv
*env
, jobject obj
, jclass klass
,
904 jmethodID id
, jvalue
*args
)
907 id
= _Jv_LookupDeclaredMethod (obj
->getClass (), id
->name
, id
->signature
);
909 jclass decl_class
= klass
? klass
: obj
->getClass ();
910 JvAssert (decl_class
!= NULL
);
913 JArray
<jclass
> *arg_types
;
916 _Jv_GetTypesFromSignature (id
, decl_class
,
917 &arg_types
, &return_type
);
919 // Unwrap arguments as required. Eww.
920 jclass
*type_elts
= elements (arg_types
);
921 jvalue arg_copy
[arg_types
->length
];
922 for (int i
= 0; i
< arg_types
->length
; ++i
)
924 if (type_elts
[i
]->isPrimitive ())
925 arg_copy
[i
] = args
[i
];
927 arg_copy
[i
].l
= unwrap (args
[i
].l
);
930 jthrowable ex
= _Jv_CallAnyMethodA (obj
, return_type
, id
,
931 style
== constructor
,
932 arg_types
, args
, NULL
);
943 // Functions with this signature are used to implement functions in
944 // the CallMethod family.
947 (JNICALL _Jv_JNI_CallMethodV
) (JNIEnv
*env
, jobject obj
,
948 jmethodID id
, va_list args
)
950 return _Jv_JNI_CallAnyMethodV
<T
, normal
> (env
, obj
, NULL
, id
, args
);
953 // Functions with this signature are used to implement functions in
954 // the CallMethod family.
957 (JNICALL _Jv_JNI_CallMethod
) (JNIEnv
*env
, jobject obj
, jmethodID id
, ...)
963 result
= _Jv_JNI_CallAnyMethodV
<T
, normal
> (env
, obj
, NULL
, id
, args
);
969 // Functions with this signature are used to implement functions in
970 // the CallMethod family.
973 (JNICALL _Jv_JNI_CallMethodA
) (JNIEnv
*env
, jobject obj
,
974 jmethodID id
, jvalue
*args
)
976 return _Jv_JNI_CallAnyMethodA
<T
, normal
> (env
, obj
, NULL
, id
, args
);
980 (JNICALL _Jv_JNI_CallVoidMethodV
) (JNIEnv
*env
, jobject obj
,
981 jmethodID id
, va_list args
)
983 _Jv_JNI_CallAnyVoidMethodV
<normal
> (env
, obj
, NULL
, id
, args
);
987 (JNICALL _Jv_JNI_CallVoidMethod
) (JNIEnv
*env
, jobject obj
, jmethodID id
, ...)
992 _Jv_JNI_CallAnyVoidMethodV
<normal
> (env
, obj
, NULL
, id
, args
);
997 (JNICALL _Jv_JNI_CallVoidMethodA
) (JNIEnv
*env
, jobject obj
,
998 jmethodID id
, jvalue
*args
)
1000 _Jv_JNI_CallAnyVoidMethodA
<normal
> (env
, obj
, NULL
, id
, args
);
1003 // Functions with this signature are used to implement functions in
1004 // the CallStaticMethod family.
1005 template<typename T
>
1007 (JNICALL _Jv_JNI_CallStaticMethodV
) (JNIEnv
*env
, jclass klass
,
1008 jmethodID id
, va_list args
)
1010 JvAssert (((id
->accflags
) & java::lang::reflect::Modifier::STATIC
));
1011 JvAssert (java::lang::Class::class$
.isInstance (unwrap (klass
)));
1013 return _Jv_JNI_CallAnyMethodV
<T
, static_type
> (env
, NULL
, klass
, id
, args
);
1016 // Functions with this signature are used to implement functions in
1017 // the CallStaticMethod family.
1018 template<typename T
>
1020 (JNICALL _Jv_JNI_CallStaticMethod
) (JNIEnv
*env
, jclass klass
,
1026 JvAssert (((id
->accflags
) & java::lang::reflect::Modifier::STATIC
));
1027 JvAssert (java::lang::Class::class$
.isInstance (unwrap (klass
)));
1029 va_start (args
, id
);
1030 result
= _Jv_JNI_CallAnyMethodV
<T
, static_type
> (env
, NULL
, klass
,
1037 // Functions with this signature are used to implement functions in
1038 // the CallStaticMethod family.
1039 template<typename T
>
1041 (JNICALL _Jv_JNI_CallStaticMethodA
) (JNIEnv
*env
, jclass klass
, jmethodID id
,
1044 JvAssert (((id
->accflags
) & java::lang::reflect::Modifier::STATIC
));
1045 JvAssert (java::lang::Class::class$
.isInstance (unwrap (klass
)));
1047 return _Jv_JNI_CallAnyMethodA
<T
, static_type
> (env
, NULL
, klass
, id
, args
);
1051 (JNICALL _Jv_JNI_CallStaticVoidMethodV
) (JNIEnv
*env
, jclass klass
,
1052 jmethodID id
, va_list args
)
1054 _Jv_JNI_CallAnyVoidMethodV
<static_type
> (env
, NULL
, klass
, id
, args
);
1058 (JNICALL _Jv_JNI_CallStaticVoidMethod
) (JNIEnv
*env
, jclass klass
,
1063 va_start (args
, id
);
1064 _Jv_JNI_CallAnyVoidMethodV
<static_type
> (env
, NULL
, klass
, id
, args
);
1069 (JNICALL _Jv_JNI_CallStaticVoidMethodA
) (JNIEnv
*env
, jclass klass
,
1070 jmethodID id
, jvalue
*args
)
1072 _Jv_JNI_CallAnyVoidMethodA
<static_type
> (env
, NULL
, klass
, id
, args
);
1076 (JNICALL _Jv_JNI_NewObjectV
) (JNIEnv
*env
, jclass klass
,
1077 jmethodID id
, va_list args
)
1079 JvAssert (klass
&& ! klass
->isArray ());
1080 JvAssert (! strcmp (id
->name
->data
, "<init>")
1081 && id
->signature
->length
> 2
1082 && id
->signature
->data
[0] == '('
1083 && ! strcmp (&id
->signature
->data
[id
->signature
->length
- 2],
1086 return _Jv_JNI_CallAnyMethodV
<jobject
, constructor
> (env
, NULL
, klass
,
1091 (JNICALL _Jv_JNI_NewObject
) (JNIEnv
*env
, jclass klass
, jmethodID id
, ...)
1093 JvAssert (klass
&& ! klass
->isArray ());
1094 JvAssert (! strcmp (id
->name
->data
, "<init>")
1095 && id
->signature
->length
> 2
1096 && id
->signature
->data
[0] == '('
1097 && ! strcmp (&id
->signature
->data
[id
->signature
->length
- 2],
1103 va_start (args
, id
);
1104 result
= _Jv_JNI_CallAnyMethodV
<jobject
, constructor
> (env
, NULL
, klass
,
1112 (JNICALL _Jv_JNI_NewObjectA
) (JNIEnv
*env
, jclass klass
, jmethodID id
,
1115 JvAssert (klass
&& ! klass
->isArray ());
1116 JvAssert (! strcmp (id
->name
->data
, "<init>")
1117 && id
->signature
->length
> 2
1118 && id
->signature
->data
[0] == '('
1119 && ! strcmp (&id
->signature
->data
[id
->signature
->length
- 2],
1122 return _Jv_JNI_CallAnyMethodA
<jobject
, constructor
> (env
, NULL
, klass
,
1128 template<typename T
>
1130 (JNICALL _Jv_JNI_GetField
) (JNIEnv
*env
, jobject obj
, jfieldID field
)
1134 T
*ptr
= (T
*) ((char *) obj
+ field
->getOffset ());
1135 return wrap_value (env
, *ptr
);
1138 template<typename T
>
1140 (JNICALL _Jv_JNI_SetField
) (JNIEnv
*, jobject obj
, jfieldID field
, T value
)
1143 value
= unwrap (value
);
1146 T
*ptr
= (T
*) ((char *) obj
+ field
->getOffset ());
1150 template<jboolean is_static
>
1152 (JNICALL _Jv_JNI_GetAnyFieldID
) (JNIEnv
*env
, jclass clazz
,
1153 const char *name
, const char *sig
)
1157 clazz
= unwrap (clazz
);
1159 _Jv_InitClass (clazz
);
1161 _Jv_Utf8Const
*a_name
= _Jv_makeUtf8Const ((char *) name
, -1);
1163 // FIXME: assume that SIG isn't too long.
1164 int len
= strlen (sig
);
1166 for (int i
= 0; i
<= len
; ++i
)
1167 s
[i
] = (sig
[i
] == '/') ? '.' : sig
[i
];
1168 jclass field_class
= _Jv_FindClassFromSignature ((char *) s
, NULL
);
1170 // FIXME: what if field_class == NULL?
1172 java::lang::ClassLoader
*loader
= clazz
->getClassLoader ();
1173 while (clazz
!= NULL
)
1175 // We acquire the class lock so that fields aren't resolved
1176 // while we are running.
1177 JvSynchronize
sync (clazz
);
1179 jint count
= (is_static
1180 ? JvNumStaticFields (clazz
)
1181 : JvNumInstanceFields (clazz
));
1182 jfieldID field
= (is_static
1183 ? JvGetFirstStaticField (clazz
)
1184 : JvGetFirstInstanceField (clazz
));
1185 for (jint i
= 0; i
< count
; ++i
)
1187 _Jv_Utf8Const
*f_name
= field
->getNameUtf8Const(clazz
);
1189 // The field might be resolved or it might not be. It
1190 // is much simpler to always resolve it.
1191 _Jv_ResolveField (field
, loader
);
1192 if (_Jv_equalUtf8Consts (f_name
, a_name
)
1193 && field
->getClass() == field_class
)
1196 field
= field
->getNextField ();
1199 clazz
= clazz
->getSuperclass ();
1202 env
->ex
= new java::lang::NoSuchFieldError ();
1204 catch (jthrowable t
)
1211 template<typename T
>
1213 (JNICALL _Jv_JNI_GetStaticField
) (JNIEnv
*env
, jclass
, jfieldID field
)
1215 T
*ptr
= (T
*) field
->u
.addr
;
1216 return wrap_value (env
, *ptr
);
1219 template<typename T
>
1221 (JNICALL _Jv_JNI_SetStaticField
) (JNIEnv
*, jclass
, jfieldID field
, T value
)
1223 value
= unwrap (value
);
1224 T
*ptr
= (T
*) field
->u
.addr
;
1229 (JNICALL _Jv_JNI_NewString
) (JNIEnv
*env
, const jchar
*unichars
, jsize len
)
1233 jstring r
= _Jv_NewString (unichars
, len
);
1234 return (jstring
) wrap_value (env
, r
);
1236 catch (jthrowable t
)
1244 (JNICALL _Jv_JNI_GetStringLength
) (JNIEnv
*, jstring string
)
1246 return unwrap (string
)->length();
1249 static const jchar
*
1250 (JNICALL _Jv_JNI_GetStringChars
) (JNIEnv
*, jstring string
, jboolean
*isCopy
)
1252 string
= unwrap (string
);
1253 jchar
*result
= _Jv_GetStringChars (string
);
1254 mark_for_gc (string
, global_ref_table
);
1257 return (const jchar
*) result
;
1261 (JNICALL _Jv_JNI_ReleaseStringChars
) (JNIEnv
*, jstring string
, const jchar
*)
1263 unmark_for_gc (unwrap (string
), global_ref_table
);
1267 (JNICALL _Jv_JNI_NewStringUTF
) (JNIEnv
*env
, const char *bytes
)
1271 jstring result
= JvNewStringUTF (bytes
);
1272 return (jstring
) wrap_value (env
, result
);
1274 catch (jthrowable t
)
1282 (JNICALL _Jv_JNI_GetStringUTFLength
) (JNIEnv
*, jstring string
)
1284 return JvGetStringUTFLength (unwrap (string
));
1288 (JNICALL _Jv_JNI_GetStringUTFChars
) (JNIEnv
*env
, jstring string
,
1291 string
= unwrap (string
);
1292 jsize len
= JvGetStringUTFLength (string
);
1295 char *r
= (char *) _Jv_Malloc (len
+ 1);
1296 JvGetStringUTFRegion (string
, 0, len
, r
);
1302 return (const char *) r
;
1304 catch (jthrowable t
)
1312 (JNICALL _Jv_JNI_ReleaseStringUTFChars
) (JNIEnv
*, jstring
, const char *utf
)
1314 _Jv_Free ((void *) utf
);
1318 (JNICALL _Jv_JNI_GetStringRegion
) (JNIEnv
*env
, jstring string
, jsize start
,
1319 jsize len
, jchar
*buf
)
1321 string
= unwrap (string
);
1322 jchar
*result
= _Jv_GetStringChars (string
);
1323 if (start
< 0 || start
> string
->length ()
1324 || len
< 0 || start
+ len
> string
->length ())
1328 env
->ex
= new java::lang::StringIndexOutOfBoundsException ();
1330 catch (jthrowable t
)
1336 memcpy (buf
, &result
[start
], len
* sizeof (jchar
));
1340 (JNICALL _Jv_JNI_GetStringUTFRegion
) (JNIEnv
*env
, jstring str
, jsize start
,
1341 jsize len
, char *buf
)
1345 if (start
< 0 || start
> str
->length ()
1346 || len
< 0 || start
+ len
> str
->length ())
1350 env
->ex
= new java::lang::StringIndexOutOfBoundsException ();
1352 catch (jthrowable t
)
1358 _Jv_GetStringUTFRegion (str
, start
, len
, buf
);
1361 static const jchar
*
1362 (JNICALL _Jv_JNI_GetStringCritical
) (JNIEnv
*, jstring str
, jboolean
*isCopy
)
1364 jchar
*result
= _Jv_GetStringChars (unwrap (str
));
1371 (JNICALL _Jv_JNI_ReleaseStringCritical
) (JNIEnv
*, jstring
, const jchar
*)
1377 (JNICALL _Jv_JNI_GetArrayLength
) (JNIEnv
*, jarray array
)
1379 return unwrap (array
)->length
;
1383 (JNICALL _Jv_JNI_NewObjectArray
) (JNIEnv
*env
, jsize length
,
1384 jclass elementClass
, jobject init
)
1388 elementClass
= unwrap (elementClass
);
1389 init
= unwrap (init
);
1391 jarray result
= JvNewObjectArray (length
, elementClass
, init
);
1392 return (jarray
) wrap_value (env
, result
);
1394 catch (jthrowable t
)
1402 (JNICALL _Jv_JNI_GetObjectArrayElement
) (JNIEnv
*env
, jobjectArray array
,
1405 jobject
*elts
= elements (unwrap (array
));
1406 return wrap_value (env
, elts
[index
]);
1410 (JNICALL _Jv_JNI_SetObjectArrayElement
) (JNIEnv
*env
, jobjectArray array
,
1411 jsize index
, jobject value
)
1415 array
= unwrap (array
);
1416 value
= unwrap (value
);
1418 _Jv_CheckArrayStore (array
, value
);
1419 jobject
*elts
= elements (array
);
1420 elts
[index
] = value
;
1422 catch (jthrowable t
)
1428 template<typename T
, jclass K
>
1430 (JNICALL _Jv_JNI_NewPrimitiveArray
) (JNIEnv
*env
, jsize length
)
1434 return (JArray
<T
> *) wrap_value (env
, _Jv_NewPrimArray (K
, length
));
1436 catch (jthrowable t
)
1443 template<typename T
>
1445 (JNICALL _Jv_JNI_GetPrimitiveArrayElements
) (JNIEnv
*, JArray
<T
> *array
,
1448 array
= unwrap (array
);
1449 T
*elts
= elements (array
);
1452 // We elect never to copy.
1455 mark_for_gc (array
, global_ref_table
);
1459 template<typename T
>
1461 (JNICALL _Jv_JNI_ReleasePrimitiveArrayElements
) (JNIEnv
*, JArray
<T
> *array
,
1462 T
*, jint
/* mode */)
1464 array
= unwrap (array
);
1465 // Note that we ignore MODE. We can do this because we never copy
1466 // the array elements. My reading of the JNI documentation is that
1467 // this is an option for the implementor.
1468 unmark_for_gc (array
, global_ref_table
);
1471 template<typename T
>
1473 (JNICALL _Jv_JNI_GetPrimitiveArrayRegion
) (JNIEnv
*env
, JArray
<T
> *array
,
1474 jsize start
, jsize len
,
1477 array
= unwrap (array
);
1479 // The cast to unsigned lets us save a comparison.
1480 if (start
< 0 || len
< 0
1481 || (unsigned long) (start
+ len
) > (unsigned long) array
->length
)
1486 env
->ex
= new java::lang::ArrayIndexOutOfBoundsException ();
1488 catch (jthrowable t
)
1490 // Could have thown out of memory error.
1496 T
*elts
= elements (array
) + start
;
1497 memcpy (buf
, elts
, len
* sizeof (T
));
1501 template<typename T
>
1503 (JNICALL _Jv_JNI_SetPrimitiveArrayRegion
) (JNIEnv
*env
, JArray
<T
> *array
,
1504 jsize start
, jsize len
, T
*buf
)
1506 array
= unwrap (array
);
1508 // The cast to unsigned lets us save a comparison.
1509 if (start
< 0 || len
< 0
1510 || (unsigned long) (start
+ len
) > (unsigned long) array
->length
)
1515 env
->ex
= new java::lang::ArrayIndexOutOfBoundsException ();
1517 catch (jthrowable t
)
1524 T
*elts
= elements (array
) + start
;
1525 memcpy (elts
, buf
, len
* sizeof (T
));
1530 (JNICALL _Jv_JNI_GetPrimitiveArrayCritical
) (JNIEnv
*, jarray array
,
1533 array
= unwrap (array
);
1534 // FIXME: does this work?
1535 jclass klass
= array
->getClass()->getComponentType();
1536 JvAssert (klass
->isPrimitive ());
1537 char *r
= _Jv_GetArrayElementFromElementType (array
, klass
);
1544 (JNICALL _Jv_JNI_ReleasePrimitiveArrayCritical
) (JNIEnv
*, jarray
, void *, jint
)
1550 (JNICALL _Jv_JNI_MonitorEnter
) (JNIEnv
*env
, jobject obj
)
1554 _Jv_MonitorEnter (unwrap (obj
));
1557 catch (jthrowable t
)
1565 (JNICALL _Jv_JNI_MonitorExit
) (JNIEnv
*env
, jobject obj
)
1569 _Jv_MonitorExit (unwrap (obj
));
1572 catch (jthrowable t
)
1581 (JNICALL _Jv_JNI_ToReflectedField
) (JNIEnv
*env
, jclass cls
, jfieldID fieldID
,
1587 java::lang::reflect::Field
*field
= new java::lang::reflect::Field();
1588 field
->declaringClass
= cls
;
1589 field
->offset
= (char*) fieldID
- (char *) cls
->fields
;
1590 field
->name
= _Jv_NewStringUtf8Const (fieldID
->getNameUtf8Const (cls
));
1591 return wrap_value (env
, field
);
1593 catch (jthrowable t
)
1602 (JNICALL _Jv_JNI_FromReflectedField
) (JNIEnv
*, jobject f
)
1604 using namespace java::lang::reflect
;
1607 Field
*field
= reinterpret_cast<Field
*> (f
);
1608 return _Jv_FromReflectedField (field
);
1612 (JNICALL _Jv_JNI_ToReflectedMethod
) (JNIEnv
*env
, jclass klass
, jmethodID id
,
1615 using namespace java::lang::reflect
;
1617 jobject result
= NULL
;
1618 klass
= unwrap (klass
);
1622 if (_Jv_equalUtf8Consts (id
->name
, init_name
))
1625 Constructor
*cons
= new Constructor ();
1626 cons
->offset
= (char *) id
- (char *) &klass
->methods
;
1627 cons
->declaringClass
= klass
;
1632 Method
*meth
= new Method ();
1633 meth
->offset
= (char *) id
- (char *) &klass
->methods
;
1634 meth
->declaringClass
= klass
;
1638 catch (jthrowable t
)
1643 return wrap_value (env
, result
);
1647 (JNICALL _Jv_JNI_FromReflectedMethod
) (JNIEnv
*, jobject method
)
1649 using namespace java::lang::reflect
;
1650 method
= unwrap (method
);
1651 if (Method::class$
.isInstance (method
))
1652 return _Jv_FromReflectedMethod (reinterpret_cast<Method
*> (method
));
1654 _Jv_FromReflectedConstructor (reinterpret_cast<Constructor
*> (method
));
1659 (JNICALL _Jv_JNI_NewWeakGlobalRef
) (JNIEnv
*env
, jobject obj
)
1661 using namespace gnu::gcj::runtime
;
1662 JNIWeakRef
*ref
= NULL
;
1666 // This seems weird but I think it is correct.
1668 ref
= new JNIWeakRef (obj
);
1669 mark_for_gc (ref
, global_ref_table
);
1671 catch (jthrowable t
)
1676 return reinterpret_cast<jweak
> (ref
);
1680 (JNICALL _Jv_JNI_DeleteWeakGlobalRef
) (JNIEnv
*, jweak obj
)
1682 using namespace gnu::gcj::runtime
;
1683 JNIWeakRef
*ref
= reinterpret_cast<JNIWeakRef
*> (obj
);
1684 unmark_for_gc (ref
, global_ref_table
);
1690 // Direct byte buffers.
1693 (JNICALL _Jv_JNI_NewDirectByteBuffer
) (JNIEnv
*, void *, jlong
)
1695 // For now we don't support this.
1700 (JNICALL _Jv_JNI_GetDirectBufferAddress
) (JNIEnv
*, jobject
)
1702 // For now we don't support this.
1707 (JNICALL _Jv_JNI_GetDirectBufferCapacity
) (JNIEnv
*, jobject
)
1709 // For now we don't support this.
1715 // Hash table of native methods.
1716 static JNINativeMethod
*nathash
;
1717 // Number of slots used.
1718 static int nathash_count
= 0;
1719 // Number of slots available. Must be power of 2.
1720 static int nathash_size
= 0;
1722 #define DELETED_ENTRY ((char *) (~0))
1724 // Compute a hash value for a native method descriptor.
1726 hash (const JNINativeMethod
*method
)
1733 hash
= (31 * hash
) + *ptr
++;
1735 ptr
= method
->signature
;
1737 hash
= (31 * hash
) + *ptr
++;
1742 // Find the slot where a native method goes.
1743 static JNINativeMethod
*
1744 nathash_find_slot (const JNINativeMethod
*method
)
1746 jint h
= hash (method
);
1747 int step
= (h
^ (h
>> 16)) | 1;
1748 int w
= h
& (nathash_size
- 1);
1753 JNINativeMethod
*slotp
= &nathash
[w
];
1754 if (slotp
->name
== NULL
)
1757 return &nathash
[del
];
1761 else if (slotp
->name
== DELETED_ENTRY
)
1763 else if (! strcmp (slotp
->name
, method
->name
)
1764 && ! strcmp (slotp
->signature
, method
->signature
))
1766 w
= (w
+ step
) & (nathash_size
- 1);
1770 // Find a method. Return NULL if it isn't in the hash table.
1772 nathash_find (JNINativeMethod
*method
)
1774 if (nathash
== NULL
)
1776 JNINativeMethod
*slot
= nathash_find_slot (method
);
1777 if (slot
->name
== NULL
|| slot
->name
== DELETED_ENTRY
)
1785 if (nathash
== NULL
)
1787 nathash_size
= 1024;
1789 (JNINativeMethod
*) _Jv_AllocBytes (nathash_size
1790 * sizeof (JNINativeMethod
));
1791 memset (nathash
, 0, nathash_size
* sizeof (JNINativeMethod
));
1795 int savesize
= nathash_size
;
1796 JNINativeMethod
*savehash
= nathash
;
1799 (JNINativeMethod
*) _Jv_AllocBytes (nathash_size
1800 * sizeof (JNINativeMethod
));
1801 memset (nathash
, 0, nathash_size
* sizeof (JNINativeMethod
));
1803 for (int i
= 0; i
< savesize
; ++i
)
1805 if (savehash
[i
].name
!= NULL
&& savehash
[i
].name
!= DELETED_ENTRY
)
1807 JNINativeMethod
*slot
= nathash_find_slot (&savehash
[i
]);
1808 *slot
= savehash
[i
];
1815 nathash_add (const JNINativeMethod
*method
)
1817 if (3 * nathash_count
>= 2 * nathash_size
)
1819 JNINativeMethod
*slot
= nathash_find_slot (method
);
1820 // If the slot has a real entry in it, then there is no work to do.
1821 if (slot
->name
!= NULL
&& slot
->name
!= DELETED_ENTRY
)
1824 slot
->name
= strdup (method
->name
);
1825 slot
->signature
= strdup (method
->signature
);
1826 slot
->fnPtr
= method
->fnPtr
;
1830 (JNICALL _Jv_JNI_RegisterNatives
) (JNIEnv
*env
, jclass klass
,
1831 const JNINativeMethod
*methods
,
1834 // Synchronize while we do the work. This must match
1835 // synchronization in some other functions that manipulate or use
1836 // the nathash table.
1837 JvSynchronize
sync (global_ref_table
);
1839 // Look at each descriptor given us, and find the corresponding
1840 // method in the class.
1841 for (int j
= 0; j
< nMethods
; ++j
)
1845 _Jv_Method
*imeths
= JvGetFirstMethod (klass
);
1846 for (int i
= 0; i
< JvNumMethods (klass
); ++i
)
1848 _Jv_Method
*self
= &imeths
[i
];
1850 if (! strcmp (self
->name
->data
, methods
[j
].name
)
1851 && ! strcmp (self
->signature
->data
, methods
[j
].signature
))
1853 if (! (self
->accflags
1854 & java::lang::reflect::Modifier::NATIVE
))
1857 // Found a match that is native.
1859 nathash_add (&methods
[j
]);
1867 jstring m
= JvNewStringUTF (methods
[j
].name
);
1870 env
->ex
=new java::lang::NoSuchMethodError (m
);
1872 catch (jthrowable t
)
1884 (JNICALL _Jv_JNI_UnregisterNatives
) (JNIEnv
*, jclass
)
1886 // FIXME -- we could implement this.
1892 // Add a character to the buffer, encoding properly.
1894 add_char (char *buf
, jchar c
, int *here
)
1898 buf
[(*here
)++] = '_';
1899 buf
[(*here
)++] = '1';
1903 buf
[(*here
)++] = '_';
1904 buf
[(*here
)++] = '2';
1908 buf
[(*here
)++] = '_';
1909 buf
[(*here
)++] = '3';
1912 // Also check for `.' here because we might be passed an internal
1913 // qualified class name like `foo.bar'.
1914 else if (c
== '/' || c
== '.')
1915 buf
[(*here
)++] = '_';
1916 else if ((c
>= '0' && c
<= '9')
1917 || (c
>= 'a' && c
<= 'z')
1918 || (c
>= 'A' && c
<= 'Z'))
1919 buf
[(*here
)++] = (char) c
;
1922 // "Unicode" character.
1923 buf
[(*here
)++] = '_';
1924 buf
[(*here
)++] = '0';
1925 for (int i
= 0; i
< 4; ++i
)
1928 buf
[(*here
) + 3 - i
] = (val
> 10) ? ('a' + val
- 10) : ('0' + val
);
1935 // Compute a mangled name for a native function. This computes the
1936 // long name, and also returns an index which indicates where a NUL
1937 // can be placed to create the short name. This function assumes that
1938 // the buffer is large enough for its results.
1940 mangled_name (jclass klass
, _Jv_Utf8Const
*func_name
,
1941 _Jv_Utf8Const
*signature
, char *buf
, int *long_start
)
1943 strcpy (buf
, "Java_");
1946 // Add fully qualified class name.
1947 jchar
*chars
= _Jv_GetStringChars (klass
->getName ());
1948 jint len
= klass
->getName ()->length ();
1949 for (int i
= 0; i
< len
; ++i
)
1950 add_char (buf
, chars
[i
], &here
);
1952 // Don't use add_char because we need a literal `_'.
1955 const unsigned char *fn
= (const unsigned char *) func_name
->data
;
1956 const unsigned char *limit
= fn
+ func_name
->length
;
1957 for (int i
= 0; ; ++i
)
1959 int ch
= UTF8_GET (fn
, limit
);
1962 add_char (buf
, ch
, &here
);
1965 // This is where the long signature begins.
1970 const unsigned char *sig
= (const unsigned char *) signature
->data
;
1971 limit
= sig
+ signature
->length
;
1972 JvAssert (sig
[0] == '(');
1976 int ch
= UTF8_GET (sig
, limit
);
1977 if (ch
== ')' || ch
< 0)
1979 add_char (buf
, ch
, &here
);
1985 // Return the current thread's JNIEnv; if one does not exist, create
1986 // it. Also create a new system frame for use. This is `extern "C"'
1987 // because the compiler calls it.
1989 _Jv_GetJNIEnvNewFrame (jclass klass
)
1991 JNIEnv
*env
= _Jv_GetCurrentJNIEnv ();
1994 env
= (JNIEnv
*) _Jv_MallocUnchecked (sizeof (JNIEnv
));
1995 env
->p
= &_Jv_JNIFunctions
;
1998 // We set env->ex below.
2000 _Jv_SetCurrentJNIEnv (env
);
2003 _Jv_JNI_LocalFrame
*frame
2004 = (_Jv_JNI_LocalFrame
*) _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame
)
2006 * sizeof (jobject
)));
2008 frame
->marker
= MARK_SYSTEM
;
2009 frame
->size
= FRAME_SIZE
;
2010 frame
->next
= env
->locals
;
2012 for (int i
= 0; i
< frame
->size
; ++i
)
2013 frame
->vec
[i
] = NULL
;
2015 env
->locals
= frame
;
2021 // Return the function which implements a particular JNI method. If
2022 // we can't find the function, we throw the appropriate exception.
2023 // This is `extern "C"' because the compiler uses it.
2025 _Jv_LookupJNIMethod (jclass klass
, _Jv_Utf8Const
*name
,
2026 _Jv_Utf8Const
*signature
)
2028 char buf
[10 + 6 * (name
->length
+ signature
->length
)];
2032 // Synchronize on something convenient. Right now we use the hash.
2033 JvSynchronize
sync (global_ref_table
);
2035 // First see if we have an override in the hash table.
2036 strncpy (buf
, name
->data
, name
->length
);
2037 buf
[name
->length
] = '\0';
2038 strncpy (buf
+ name
->length
+ 1, signature
->data
, signature
->length
);
2039 buf
[name
->length
+ signature
->length
+ 1] = '\0';
2040 JNINativeMethod meth
;
2042 meth
.signature
= buf
+ name
->length
+ 1;
2043 function
= nathash_find (&meth
);
2044 if (function
!= NULL
)
2047 // If there was no override, then look in the symbol table.
2048 mangled_name (klass
, name
, signature
, buf
, &long_start
);
2049 char c
= buf
[long_start
];
2050 buf
[long_start
] = '\0';
2051 function
= _Jv_FindSymbolInExecutable (buf
);
2052 if (function
== NULL
)
2054 buf
[long_start
] = c
;
2055 function
= _Jv_FindSymbolInExecutable (buf
);
2056 if (function
== NULL
)
2058 jstring str
= JvNewStringUTF (name
->data
);
2059 throw new java::lang::UnsatisfiedLinkError (str
);
2068 // This function is the stub which is used to turn an ordinary (CNI)
2069 // method call into a JNI call.
2071 _Jv_JNIMethod::call (ffi_cif
*, void *ret
, ffi_raw
*args
, void *__this
)
2073 _Jv_JNIMethod
* _this
= (_Jv_JNIMethod
*) __this
;
2075 JNIEnv
*env
= _Jv_GetJNIEnvNewFrame (_this
->defining_class
);
2077 // FIXME: we should mark every reference parameter as a local. For
2078 // now we assume a conservative GC, and we assume that the
2079 // references are on the stack somewhere.
2081 // We cache the value that we find, of course, but if we don't find
2082 // a value we don't cache that fact -- we might subsequently load a
2083 // library which finds the function in question.
2085 // Synchronize on a convenient object to ensure sanity in case two
2086 // threads reach this point for the same function at the same
2088 JvSynchronize
sync (global_ref_table
);
2089 if (_this
->function
== NULL
)
2090 _this
->function
= _Jv_LookupJNIMethod (_this
->defining_class
,
2092 _this
->self
->signature
);
2095 JvAssert (_this
->args_raw_size
% sizeof (ffi_raw
) == 0);
2096 ffi_raw real_args
[2 + _this
->args_raw_size
/ sizeof (ffi_raw
)];
2099 // First argument is always the environment pointer.
2100 real_args
[offset
++].ptr
= env
;
2102 // For a static method, we pass in the Class. For non-static
2103 // methods, the `this' argument is already handled.
2104 if ((_this
->self
->accflags
& java::lang::reflect::Modifier::STATIC
))
2105 real_args
[offset
++].ptr
= _this
->defining_class
;
2107 // In libgcj, the callee synchronizes.
2108 jobject sync
= NULL
;
2109 if ((_this
->self
->accflags
& java::lang::reflect::Modifier::SYNCHRONIZED
))
2111 if ((_this
->self
->accflags
& java::lang::reflect::Modifier::STATIC
))
2112 sync
= _this
->defining_class
;
2114 sync
= (jobject
) args
[0].ptr
;
2115 _Jv_MonitorEnter (sync
);
2118 // Copy over passed-in arguments.
2119 memcpy (&real_args
[offset
], args
, _this
->args_raw_size
);
2121 // The actual call to the JNI function.
2122 ffi_raw_call (&_this
->jni_cif
, (void (*)()) _this
->function
,
2126 _Jv_MonitorExit (sync
);
2128 _Jv_JNI_PopSystemFrame (env
);
2131 #endif /* INTERPRETER */
2139 // An internal helper function.
2141 _Jv_JNI_AttachCurrentThread (JavaVM
*, jstring name
, void **penv
,
2142 void *args
, jboolean is_daemon
)
2144 JavaVMAttachArgs
*attach
= reinterpret_cast<JavaVMAttachArgs
*> (args
);
2145 java::lang::ThreadGroup
*group
= NULL
;
2149 // FIXME: do we really want to support 1.1?
2150 if (attach
->version
!= JNI_VERSION_1_4
2151 && attach
->version
!= JNI_VERSION_1_2
2152 && attach
->version
!= JNI_VERSION_1_1
)
2153 return JNI_EVERSION
;
2155 JvAssert (java::lang::ThreadGroup::class$
.isInstance (attach
->group
));
2156 group
= reinterpret_cast<java::lang::ThreadGroup
*> (attach
->group
);
2159 // Attaching an already-attached thread is a no-op.
2160 if (_Jv_GetCurrentJNIEnv () != NULL
)
2163 JNIEnv
*env
= (JNIEnv
*) _Jv_MallocUnchecked (sizeof (JNIEnv
));
2166 env
->p
= &_Jv_JNIFunctions
;
2170 = (_Jv_JNI_LocalFrame
*) _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame
)
2172 * sizeof (jobject
)));
2173 if (env
->locals
== NULL
)
2179 env
->locals
->marker
= MARK_SYSTEM
;
2180 env
->locals
->size
= FRAME_SIZE
;
2181 env
->locals
->next
= NULL
;
2183 for (int i
= 0; i
< env
->locals
->size
; ++i
)
2184 env
->locals
->vec
[i
] = NULL
;
2186 *penv
= reinterpret_cast<void *> (env
);
2188 // This thread might already be a Java thread -- this function might
2189 // have been called simply to set the new JNIEnv.
2190 if (_Jv_ThreadCurrent () == NULL
)
2195 _Jv_AttachCurrentThreadAsDaemon (name
, group
);
2197 _Jv_AttachCurrentThread (name
, group
);
2199 catch (jthrowable t
)
2204 _Jv_SetCurrentJNIEnv (env
);
2209 // This is the one actually used by JNI.
2211 (JNICALL _Jv_JNI_AttachCurrentThread
) (JavaVM
*vm
, void **penv
, void *args
)
2213 return _Jv_JNI_AttachCurrentThread (vm
, NULL
, penv
, args
, false);
2217 (JNICALL _Jv_JNI_AttachCurrentThreadAsDaemon
) (JavaVM
*vm
, void **penv
,
2220 return _Jv_JNI_AttachCurrentThread (vm
, NULL
, penv
, args
, true);
2224 (JNICALL _Jv_JNI_DestroyJavaVM
) (JavaVM
*vm
)
2226 JvAssert (the_vm
&& vm
== the_vm
);
2229 if (_Jv_ThreadCurrent () != NULL
)
2235 main_name
= JvNewStringLatin1 ("main");
2237 catch (jthrowable t
)
2242 jint r
= _Jv_JNI_AttachCurrentThread (vm
, main_name
,
2243 reinterpret_cast<void **> (&env
),
2249 env
= _Jv_GetCurrentJNIEnv ();
2253 // Docs say that this always returns an error code.
2258 (JNICALL _Jv_JNI_DetachCurrentThread
) (JavaVM
*)
2260 jint code
= _Jv_DetachCurrentThread ();
2261 return code
? JNI_EDETACHED
: 0;
2265 (JNICALL _Jv_JNI_GetEnv
) (JavaVM
*, void **penv
, jint version
)
2267 if (_Jv_ThreadCurrent () == NULL
)
2270 return JNI_EDETACHED
;
2274 // Handle JVMPI requests.
2275 if (version
== JVMPI_VERSION_1
)
2277 *penv
= (void *) &_Jv_JVMPI_Interface
;
2282 // FIXME: do we really want to support 1.1?
2283 if (version
!= JNI_VERSION_1_4
&& version
!= JNI_VERSION_1_2
2284 && version
!= JNI_VERSION_1_1
)
2287 return JNI_EVERSION
;
2290 *penv
= (void *) _Jv_GetCurrentJNIEnv ();
2294 JNIEXPORT jint JNICALL
2295 JNI_GetDefaultJavaVMInitArgs (void *args
)
2297 jint version
= * (jint
*) args
;
2298 // Here we only support 1.2 and 1.4.
2299 if (version
!= JNI_VERSION_1_2
&& version
!= JNI_VERSION_1_4
)
2300 return JNI_EVERSION
;
2302 JavaVMInitArgs
*ia
= reinterpret_cast<JavaVMInitArgs
*> (args
);
2303 ia
->version
= JNI_VERSION_1_4
;
2306 ia
->ignoreUnrecognized
= true;
2311 JNIEXPORT jint JNICALL
2312 JNI_CreateJavaVM (JavaVM
**vm
, void **penv
, void *args
)
2314 JvAssert (! the_vm
);
2316 _Jv_CreateJavaVM (NULL
);
2318 // FIXME: synchronize
2319 JavaVM
*nvm
= (JavaVM
*) _Jv_MallocUnchecked (sizeof (JavaVM
));
2322 nvm
->functions
= &_Jv_JNI_InvokeFunctions
;
2324 // Parse the arguments.
2327 jint version
= * (jint
*) args
;
2328 // We only support 1.2 and 1.4.
2329 if (version
!= JNI_VERSION_1_2
&& version
!= JNI_VERSION_1_4
)
2330 return JNI_EVERSION
;
2331 JavaVMInitArgs
*ia
= reinterpret_cast<JavaVMInitArgs
*> (args
);
2332 for (int i
= 0; i
< ia
->nOptions
; ++i
)
2334 if (! strcmp (ia
->options
[i
].optionString
, "vfprintf")
2335 || ! strcmp (ia
->options
[i
].optionString
, "exit")
2336 || ! strcmp (ia
->options
[i
].optionString
, "abort"))
2338 // We are required to recognize these, but for now we
2339 // don't handle them in any way. FIXME.
2342 else if (! strncmp (ia
->options
[i
].optionString
,
2343 "-verbose", sizeof ("-verbose") - 1))
2345 // We don't do anything with this option either. We
2346 // might want to make sure the argument is valid, but we
2347 // don't really care all that much for now.
2350 else if (! strncmp (ia
->options
[i
].optionString
, "-D", 2))
2355 else if (ia
->ignoreUnrecognized
)
2357 if (ia
->options
[i
].optionString
[0] == '_'
2358 || ! strncmp (ia
->options
[i
].optionString
, "-X", 2))
2366 jint r
=_Jv_JNI_AttachCurrentThread (nvm
, penv
, NULL
);
2376 JNIEXPORT jint JNICALL
2377 JNI_GetCreatedJavaVMs (JavaVM
**vm_buffer
, jsize buf_len
, jsize
*n_vms
)
2382 // We only support a single VM.
2385 vm_buffer
[0] = the_vm
;
2396 // FIXME: synchronize
2399 JavaVM
*nvm
= (JavaVM
*) _Jv_MallocUnchecked (sizeof (JavaVM
));
2401 nvm
->functions
= &_Jv_JNI_InvokeFunctions
;
2405 // If this is a Java thread, we want to make sure it has an
2406 // associated JNIEnv.
2407 if (_Jv_ThreadCurrent () != NULL
)
2410 _Jv_JNI_AttachCurrentThread (the_vm
, &ignore
, NULL
);
2417 (JNICALL _Jv_JNI_GetJavaVM
) (JNIEnv
*, JavaVM
**vm
)
2419 *vm
= _Jv_GetJavaVM ();
2420 return *vm
== NULL
? JNI_ERR
: JNI_OK
;
2425 #define RESERVED NULL
2427 struct JNINativeInterface _Jv_JNIFunctions
=
2433 _Jv_JNI_GetVersion
, // GetVersion
2434 _Jv_JNI_DefineClass
, // DefineClass
2435 _Jv_JNI_FindClass
, // FindClass
2436 _Jv_JNI_FromReflectedMethod
, // FromReflectedMethod
2437 _Jv_JNI_FromReflectedField
, // FromReflectedField
2438 _Jv_JNI_ToReflectedMethod
, // ToReflectedMethod
2439 _Jv_JNI_GetSuperclass
, // GetSuperclass
2440 _Jv_JNI_IsAssignableFrom
, // IsAssignableFrom
2441 _Jv_JNI_ToReflectedField
, // ToReflectedField
2442 _Jv_JNI_Throw
, // Throw
2443 _Jv_JNI_ThrowNew
, // ThrowNew
2444 _Jv_JNI_ExceptionOccurred
, // ExceptionOccurred
2445 _Jv_JNI_ExceptionDescribe
, // ExceptionDescribe
2446 _Jv_JNI_ExceptionClear
, // ExceptionClear
2447 _Jv_JNI_FatalError
, // FatalError
2449 _Jv_JNI_PushLocalFrame
, // PushLocalFrame
2450 _Jv_JNI_PopLocalFrame
, // PopLocalFrame
2451 _Jv_JNI_NewGlobalRef
, // NewGlobalRef
2452 _Jv_JNI_DeleteGlobalRef
, // DeleteGlobalRef
2453 _Jv_JNI_DeleteLocalRef
, // DeleteLocalRef
2455 _Jv_JNI_IsSameObject
, // IsSameObject
2457 _Jv_JNI_NewLocalRef
, // NewLocalRef
2458 _Jv_JNI_EnsureLocalCapacity
, // EnsureLocalCapacity
2460 _Jv_JNI_AllocObject
, // AllocObject
2461 _Jv_JNI_NewObject
, // NewObject
2462 _Jv_JNI_NewObjectV
, // NewObjectV
2463 _Jv_JNI_NewObjectA
, // NewObjectA
2464 _Jv_JNI_GetObjectClass
, // GetObjectClass
2465 _Jv_JNI_IsInstanceOf
, // IsInstanceOf
2466 _Jv_JNI_GetAnyMethodID
<false>, // GetMethodID
2468 _Jv_JNI_CallMethod
<jobject
>, // CallObjectMethod
2469 _Jv_JNI_CallMethodV
<jobject
>, // CallObjectMethodV
2470 _Jv_JNI_CallMethodA
<jobject
>, // CallObjectMethodA
2471 _Jv_JNI_CallMethod
<jboolean
>, // CallBooleanMethod
2472 _Jv_JNI_CallMethodV
<jboolean
>, // CallBooleanMethodV
2473 _Jv_JNI_CallMethodA
<jboolean
>, // CallBooleanMethodA
2474 _Jv_JNI_CallMethod
<jbyte
>, // CallByteMethod
2475 _Jv_JNI_CallMethodV
<jbyte
>, // CallByteMethodV
2476 _Jv_JNI_CallMethodA
<jbyte
>, // CallByteMethodA
2477 _Jv_JNI_CallMethod
<jchar
>, // CallCharMethod
2478 _Jv_JNI_CallMethodV
<jchar
>, // CallCharMethodV
2479 _Jv_JNI_CallMethodA
<jchar
>, // CallCharMethodA
2480 _Jv_JNI_CallMethod
<jshort
>, // CallShortMethod
2481 _Jv_JNI_CallMethodV
<jshort
>, // CallShortMethodV
2482 _Jv_JNI_CallMethodA
<jshort
>, // CallShortMethodA
2483 _Jv_JNI_CallMethod
<jint
>, // CallIntMethod
2484 _Jv_JNI_CallMethodV
<jint
>, // CallIntMethodV
2485 _Jv_JNI_CallMethodA
<jint
>, // CallIntMethodA
2486 _Jv_JNI_CallMethod
<jlong
>, // CallLongMethod
2487 _Jv_JNI_CallMethodV
<jlong
>, // CallLongMethodV
2488 _Jv_JNI_CallMethodA
<jlong
>, // CallLongMethodA
2489 _Jv_JNI_CallMethod
<jfloat
>, // CallFloatMethod
2490 _Jv_JNI_CallMethodV
<jfloat
>, // CallFloatMethodV
2491 _Jv_JNI_CallMethodA
<jfloat
>, // CallFloatMethodA
2492 _Jv_JNI_CallMethod
<jdouble
>, // CallDoubleMethod
2493 _Jv_JNI_CallMethodV
<jdouble
>, // CallDoubleMethodV
2494 _Jv_JNI_CallMethodA
<jdouble
>, // CallDoubleMethodA
2495 _Jv_JNI_CallVoidMethod
, // CallVoidMethod
2496 _Jv_JNI_CallVoidMethodV
, // CallVoidMethodV
2497 _Jv_JNI_CallVoidMethodA
, // CallVoidMethodA
2499 // Nonvirtual method invocation functions follow.
2500 _Jv_JNI_CallAnyMethod
<jobject
, nonvirtual
>, // CallNonvirtualObjectMethod
2501 _Jv_JNI_CallAnyMethodV
<jobject
, nonvirtual
>, // CallNonvirtualObjectMethodV
2502 _Jv_JNI_CallAnyMethodA
<jobject
, nonvirtual
>, // CallNonvirtualObjectMethodA
2503 _Jv_JNI_CallAnyMethod
<jboolean
, nonvirtual
>, // CallNonvirtualBooleanMethod
2504 _Jv_JNI_CallAnyMethodV
<jboolean
, nonvirtual
>, // CallNonvirtualBooleanMethodV
2505 _Jv_JNI_CallAnyMethodA
<jboolean
, nonvirtual
>, // CallNonvirtualBooleanMethodA
2506 _Jv_JNI_CallAnyMethod
<jbyte
, nonvirtual
>, // CallNonvirtualByteMethod
2507 _Jv_JNI_CallAnyMethodV
<jbyte
, nonvirtual
>, // CallNonvirtualByteMethodV
2508 _Jv_JNI_CallAnyMethodA
<jbyte
, nonvirtual
>, // CallNonvirtualByteMethodA
2509 _Jv_JNI_CallAnyMethod
<jchar
, nonvirtual
>, // CallNonvirtualCharMethod
2510 _Jv_JNI_CallAnyMethodV
<jchar
, nonvirtual
>, // CallNonvirtualCharMethodV
2511 _Jv_JNI_CallAnyMethodA
<jchar
, nonvirtual
>, // CallNonvirtualCharMethodA
2512 _Jv_JNI_CallAnyMethod
<jshort
, nonvirtual
>, // CallNonvirtualShortMethod
2513 _Jv_JNI_CallAnyMethodV
<jshort
, nonvirtual
>, // CallNonvirtualShortMethodV
2514 _Jv_JNI_CallAnyMethodA
<jshort
, nonvirtual
>, // CallNonvirtualShortMethodA
2515 _Jv_JNI_CallAnyMethod
<jint
, nonvirtual
>, // CallNonvirtualIntMethod
2516 _Jv_JNI_CallAnyMethodV
<jint
, nonvirtual
>, // CallNonvirtualIntMethodV
2517 _Jv_JNI_CallAnyMethodA
<jint
, nonvirtual
>, // CallNonvirtualIntMethodA
2518 _Jv_JNI_CallAnyMethod
<jlong
, nonvirtual
>, // CallNonvirtualLongMethod
2519 _Jv_JNI_CallAnyMethodV
<jlong
, nonvirtual
>, // CallNonvirtualLongMethodV
2520 _Jv_JNI_CallAnyMethodA
<jlong
, nonvirtual
>, // CallNonvirtualLongMethodA
2521 _Jv_JNI_CallAnyMethod
<jfloat
, nonvirtual
>, // CallNonvirtualFloatMethod
2522 _Jv_JNI_CallAnyMethodV
<jfloat
, nonvirtual
>, // CallNonvirtualFloatMethodV
2523 _Jv_JNI_CallAnyMethodA
<jfloat
, nonvirtual
>, // CallNonvirtualFloatMethodA
2524 _Jv_JNI_CallAnyMethod
<jdouble
, nonvirtual
>, // CallNonvirtualDoubleMethod
2525 _Jv_JNI_CallAnyMethodV
<jdouble
, nonvirtual
>, // CallNonvirtualDoubleMethodV
2526 _Jv_JNI_CallAnyMethodA
<jdouble
, nonvirtual
>, // CallNonvirtualDoubleMethodA
2527 _Jv_JNI_CallAnyVoidMethod
<nonvirtual
>, // CallNonvirtualVoidMethod
2528 _Jv_JNI_CallAnyVoidMethodV
<nonvirtual
>, // CallNonvirtualVoidMethodV
2529 _Jv_JNI_CallAnyVoidMethodA
<nonvirtual
>, // CallNonvirtualVoidMethodA
2531 _Jv_JNI_GetAnyFieldID
<false>, // GetFieldID
2532 _Jv_JNI_GetField
<jobject
>, // GetObjectField
2533 _Jv_JNI_GetField
<jboolean
>, // GetBooleanField
2534 _Jv_JNI_GetField
<jbyte
>, // GetByteField
2535 _Jv_JNI_GetField
<jchar
>, // GetCharField
2536 _Jv_JNI_GetField
<jshort
>, // GetShortField
2537 _Jv_JNI_GetField
<jint
>, // GetIntField
2538 _Jv_JNI_GetField
<jlong
>, // GetLongField
2539 _Jv_JNI_GetField
<jfloat
>, // GetFloatField
2540 _Jv_JNI_GetField
<jdouble
>, // GetDoubleField
2541 _Jv_JNI_SetField
, // SetObjectField
2542 _Jv_JNI_SetField
, // SetBooleanField
2543 _Jv_JNI_SetField
, // SetByteField
2544 _Jv_JNI_SetField
, // SetCharField
2545 _Jv_JNI_SetField
, // SetShortField
2546 _Jv_JNI_SetField
, // SetIntField
2547 _Jv_JNI_SetField
, // SetLongField
2548 _Jv_JNI_SetField
, // SetFloatField
2549 _Jv_JNI_SetField
, // SetDoubleField
2550 _Jv_JNI_GetAnyMethodID
<true>, // GetStaticMethodID
2552 _Jv_JNI_CallStaticMethod
<jobject
>, // CallStaticObjectMethod
2553 _Jv_JNI_CallStaticMethodV
<jobject
>, // CallStaticObjectMethodV
2554 _Jv_JNI_CallStaticMethodA
<jobject
>, // CallStaticObjectMethodA
2555 _Jv_JNI_CallStaticMethod
<jboolean
>, // CallStaticBooleanMethod
2556 _Jv_JNI_CallStaticMethodV
<jboolean
>, // CallStaticBooleanMethodV
2557 _Jv_JNI_CallStaticMethodA
<jboolean
>, // CallStaticBooleanMethodA
2558 _Jv_JNI_CallStaticMethod
<jbyte
>, // CallStaticByteMethod
2559 _Jv_JNI_CallStaticMethodV
<jbyte
>, // CallStaticByteMethodV
2560 _Jv_JNI_CallStaticMethodA
<jbyte
>, // CallStaticByteMethodA
2561 _Jv_JNI_CallStaticMethod
<jchar
>, // CallStaticCharMethod
2562 _Jv_JNI_CallStaticMethodV
<jchar
>, // CallStaticCharMethodV
2563 _Jv_JNI_CallStaticMethodA
<jchar
>, // CallStaticCharMethodA
2564 _Jv_JNI_CallStaticMethod
<jshort
>, // CallStaticShortMethod
2565 _Jv_JNI_CallStaticMethodV
<jshort
>, // CallStaticShortMethodV
2566 _Jv_JNI_CallStaticMethodA
<jshort
>, // CallStaticShortMethodA
2567 _Jv_JNI_CallStaticMethod
<jint
>, // CallStaticIntMethod
2568 _Jv_JNI_CallStaticMethodV
<jint
>, // CallStaticIntMethodV
2569 _Jv_JNI_CallStaticMethodA
<jint
>, // CallStaticIntMethodA
2570 _Jv_JNI_CallStaticMethod
<jlong
>, // CallStaticLongMethod
2571 _Jv_JNI_CallStaticMethodV
<jlong
>, // CallStaticLongMethodV
2572 _Jv_JNI_CallStaticMethodA
<jlong
>, // CallStaticLongMethodA
2573 _Jv_JNI_CallStaticMethod
<jfloat
>, // CallStaticFloatMethod
2574 _Jv_JNI_CallStaticMethodV
<jfloat
>, // CallStaticFloatMethodV
2575 _Jv_JNI_CallStaticMethodA
<jfloat
>, // CallStaticFloatMethodA
2576 _Jv_JNI_CallStaticMethod
<jdouble
>, // CallStaticDoubleMethod
2577 _Jv_JNI_CallStaticMethodV
<jdouble
>, // CallStaticDoubleMethodV
2578 _Jv_JNI_CallStaticMethodA
<jdouble
>, // CallStaticDoubleMethodA
2579 _Jv_JNI_CallStaticVoidMethod
, // CallStaticVoidMethod
2580 _Jv_JNI_CallStaticVoidMethodV
, // CallStaticVoidMethodV
2581 _Jv_JNI_CallStaticVoidMethodA
, // CallStaticVoidMethodA
2583 _Jv_JNI_GetAnyFieldID
<true>, // GetStaticFieldID
2584 _Jv_JNI_GetStaticField
<jobject
>, // GetStaticObjectField
2585 _Jv_JNI_GetStaticField
<jboolean
>, // GetStaticBooleanField
2586 _Jv_JNI_GetStaticField
<jbyte
>, // GetStaticByteField
2587 _Jv_JNI_GetStaticField
<jchar
>, // GetStaticCharField
2588 _Jv_JNI_GetStaticField
<jshort
>, // GetStaticShortField
2589 _Jv_JNI_GetStaticField
<jint
>, // GetStaticIntField
2590 _Jv_JNI_GetStaticField
<jlong
>, // GetStaticLongField
2591 _Jv_JNI_GetStaticField
<jfloat
>, // GetStaticFloatField
2592 _Jv_JNI_GetStaticField
<jdouble
>, // GetStaticDoubleField
2593 _Jv_JNI_SetStaticField
, // SetStaticObjectField
2594 _Jv_JNI_SetStaticField
, // SetStaticBooleanField
2595 _Jv_JNI_SetStaticField
, // SetStaticByteField
2596 _Jv_JNI_SetStaticField
, // SetStaticCharField
2597 _Jv_JNI_SetStaticField
, // SetStaticShortField
2598 _Jv_JNI_SetStaticField
, // SetStaticIntField
2599 _Jv_JNI_SetStaticField
, // SetStaticLongField
2600 _Jv_JNI_SetStaticField
, // SetStaticFloatField
2601 _Jv_JNI_SetStaticField
, // SetStaticDoubleField
2602 _Jv_JNI_NewString
, // NewString
2603 _Jv_JNI_GetStringLength
, // GetStringLength
2604 _Jv_JNI_GetStringChars
, // GetStringChars
2605 _Jv_JNI_ReleaseStringChars
, // ReleaseStringChars
2606 _Jv_JNI_NewStringUTF
, // NewStringUTF
2607 _Jv_JNI_GetStringUTFLength
, // GetStringUTFLength
2608 _Jv_JNI_GetStringUTFChars
, // GetStringUTFChars
2609 _Jv_JNI_ReleaseStringUTFChars
, // ReleaseStringUTFChars
2610 _Jv_JNI_GetArrayLength
, // GetArrayLength
2611 _Jv_JNI_NewObjectArray
, // NewObjectArray
2612 _Jv_JNI_GetObjectArrayElement
, // GetObjectArrayElement
2613 _Jv_JNI_SetObjectArrayElement
, // SetObjectArrayElement
2614 _Jv_JNI_NewPrimitiveArray
<jboolean
, JvPrimClass (boolean
)>,
2616 _Jv_JNI_NewPrimitiveArray
<jbyte
, JvPrimClass (byte
)>, // NewByteArray
2617 _Jv_JNI_NewPrimitiveArray
<jchar
, JvPrimClass (char)>, // NewCharArray
2618 _Jv_JNI_NewPrimitiveArray
<jshort
, JvPrimClass (short)>, // NewShortArray
2619 _Jv_JNI_NewPrimitiveArray
<jint
, JvPrimClass (int)>, // NewIntArray
2620 _Jv_JNI_NewPrimitiveArray
<jlong
, JvPrimClass (long)>, // NewLongArray
2621 _Jv_JNI_NewPrimitiveArray
<jfloat
, JvPrimClass (float)>, // NewFloatArray
2622 _Jv_JNI_NewPrimitiveArray
<jdouble
, JvPrimClass (double)>, // NewDoubleArray
2623 _Jv_JNI_GetPrimitiveArrayElements
, // GetBooleanArrayElements
2624 _Jv_JNI_GetPrimitiveArrayElements
, // GetByteArrayElements
2625 _Jv_JNI_GetPrimitiveArrayElements
, // GetCharArrayElements
2626 _Jv_JNI_GetPrimitiveArrayElements
, // GetShortArrayElements
2627 _Jv_JNI_GetPrimitiveArrayElements
, // GetIntArrayElements
2628 _Jv_JNI_GetPrimitiveArrayElements
, // GetLongArrayElements
2629 _Jv_JNI_GetPrimitiveArrayElements
, // GetFloatArrayElements
2630 _Jv_JNI_GetPrimitiveArrayElements
, // GetDoubleArrayElements
2631 _Jv_JNI_ReleasePrimitiveArrayElements
, // ReleaseBooleanArrayElements
2632 _Jv_JNI_ReleasePrimitiveArrayElements
, // ReleaseByteArrayElements
2633 _Jv_JNI_ReleasePrimitiveArrayElements
, // ReleaseCharArrayElements
2634 _Jv_JNI_ReleasePrimitiveArrayElements
, // ReleaseShortArrayElements
2635 _Jv_JNI_ReleasePrimitiveArrayElements
, // ReleaseIntArrayElements
2636 _Jv_JNI_ReleasePrimitiveArrayElements
, // ReleaseLongArrayElements
2637 _Jv_JNI_ReleasePrimitiveArrayElements
, // ReleaseFloatArrayElements
2638 _Jv_JNI_ReleasePrimitiveArrayElements
, // ReleaseDoubleArrayElements
2639 _Jv_JNI_GetPrimitiveArrayRegion
, // GetBooleanArrayRegion
2640 _Jv_JNI_GetPrimitiveArrayRegion
, // GetByteArrayRegion
2641 _Jv_JNI_GetPrimitiveArrayRegion
, // GetCharArrayRegion
2642 _Jv_JNI_GetPrimitiveArrayRegion
, // GetShortArrayRegion
2643 _Jv_JNI_GetPrimitiveArrayRegion
, // GetIntArrayRegion
2644 _Jv_JNI_GetPrimitiveArrayRegion
, // GetLongArrayRegion
2645 _Jv_JNI_GetPrimitiveArrayRegion
, // GetFloatArrayRegion
2646 _Jv_JNI_GetPrimitiveArrayRegion
, // GetDoubleArrayRegion
2647 _Jv_JNI_SetPrimitiveArrayRegion
, // SetBooleanArrayRegion
2648 _Jv_JNI_SetPrimitiveArrayRegion
, // SetByteArrayRegion
2649 _Jv_JNI_SetPrimitiveArrayRegion
, // SetCharArrayRegion
2650 _Jv_JNI_SetPrimitiveArrayRegion
, // SetShortArrayRegion
2651 _Jv_JNI_SetPrimitiveArrayRegion
, // SetIntArrayRegion
2652 _Jv_JNI_SetPrimitiveArrayRegion
, // SetLongArrayRegion
2653 _Jv_JNI_SetPrimitiveArrayRegion
, // SetFloatArrayRegion
2654 _Jv_JNI_SetPrimitiveArrayRegion
, // SetDoubleArrayRegion
2655 _Jv_JNI_RegisterNatives
, // RegisterNatives
2656 _Jv_JNI_UnregisterNatives
, // UnregisterNatives
2657 _Jv_JNI_MonitorEnter
, // MonitorEnter
2658 _Jv_JNI_MonitorExit
, // MonitorExit
2659 _Jv_JNI_GetJavaVM
, // GetJavaVM
2661 _Jv_JNI_GetStringRegion
, // GetStringRegion
2662 _Jv_JNI_GetStringUTFRegion
, // GetStringUTFRegion
2663 _Jv_JNI_GetPrimitiveArrayCritical
, // GetPrimitiveArrayCritical
2664 _Jv_JNI_ReleasePrimitiveArrayCritical
, // ReleasePrimitiveArrayCritical
2665 _Jv_JNI_GetStringCritical
, // GetStringCritical
2666 _Jv_JNI_ReleaseStringCritical
, // ReleaseStringCritical
2668 _Jv_JNI_NewWeakGlobalRef
, // NewWeakGlobalRef
2669 _Jv_JNI_DeleteWeakGlobalRef
, // DeleteWeakGlobalRef
2671 _Jv_JNI_ExceptionCheck
, // ExceptionCheck
2673 _Jv_JNI_NewDirectByteBuffer
, // NewDirectByteBuffer
2674 _Jv_JNI_GetDirectBufferAddress
, // GetDirectBufferAddress
2675 _Jv_JNI_GetDirectBufferCapacity
// GetDirectBufferCapacity
2678 struct JNIInvokeInterface _Jv_JNI_InvokeFunctions
=
2684 _Jv_JNI_DestroyJavaVM
,
2685 _Jv_JNI_AttachCurrentThread
,
2686 _Jv_JNI_DetachCurrentThread
,
2688 _Jv_JNI_AttachCurrentThreadAsDaemon