1 // jni.cc - JNI implementation, including the jump table.
3 /* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004
4 Free Software Foundation
6 This file is part of libgcj.
8 This software is copyrighted work licensed under the terms of the
9 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
20 #include <java-assert.h>
26 #include <java/lang/Class.h>
27 #include <java/lang/ClassLoader.h>
28 #include <java/lang/Throwable.h>
29 #include <java/lang/ArrayIndexOutOfBoundsException.h>
30 #include <java/lang/StringIndexOutOfBoundsException.h>
31 #include <java/lang/StringBuffer.h>
32 #include <java/lang/UnsatisfiedLinkError.h>
33 #include <java/lang/InstantiationException.h>
34 #include <java/lang/NoSuchFieldError.h>
35 #include <java/lang/NoSuchMethodError.h>
36 #include <java/lang/reflect/Constructor.h>
37 #include <java/lang/reflect/Method.h>
38 #include <java/lang/reflect/Modifier.h>
39 #include <java/lang/OutOfMemoryError.h>
40 #include <java/lang/Integer.h>
41 #include <java/lang/ThreadGroup.h>
42 #include <java/lang/Thread.h>
43 #include <java/lang/IllegalAccessError.h>
44 #include <java/nio/Buffer.h>
45 #include <java/nio/DirectByteBufferImpl.h>
46 #include <java/nio/DirectByteBufferImpl$ReadWrite.h>
47 #include <java/util/IdentityHashMap.h>
48 #include <gnu/gcj/RawData.h>
50 #include <gcj/method.h>
51 #include <gcj/field.h>
53 #include <java-interp.h>
54 #include <java-threads.h>
58 // This enum is used to select different template instantiations in
59 // the invocation code.
68 // Forward declarations.
69 extern struct JNINativeInterface _Jv_JNIFunctions
;
70 extern struct JNIInvokeInterface _Jv_JNI_InvokeFunctions
;
72 // Number of slots in the default frame. The VM must allow at least
76 // Mark value indicating this is an overflow frame.
78 // Mark value indicating this is a user frame.
80 // Mark value indicating this is a system frame.
83 // This structure is used to keep track of local references.
84 struct _Jv_JNI_LocalFrame
86 // This is true if this frame object represents a pushed frame (eg
87 // from PushLocalFrame).
90 // Flag to indicate some locals were allocated.
93 // Number of elements in frame.
96 // Next frame in chain.
97 _Jv_JNI_LocalFrame
*next
;
99 // The elements. These are allocated using the C "struct hack".
103 // This holds a reference count for all local references.
104 static java::util::IdentityHashMap
*local_ref_table
;
105 // This holds a reference count for all global references.
106 static java::util::IdentityHashMap
*global_ref_table
;
109 static JavaVM
*the_vm
;
112 // The only JVMPI interface description.
113 static JVMPI_Interface _Jv_JVMPI_Interface
;
116 jvmpiEnableEvent (jint event_type
, void *)
120 case JVMPI_EVENT_OBJECT_ALLOC
:
121 _Jv_JVMPI_Notify_OBJECT_ALLOC
= _Jv_JVMPI_Interface
.NotifyEvent
;
124 case JVMPI_EVENT_THREAD_START
:
125 _Jv_JVMPI_Notify_THREAD_START
= _Jv_JVMPI_Interface
.NotifyEvent
;
128 case JVMPI_EVENT_THREAD_END
:
129 _Jv_JVMPI_Notify_THREAD_END
= _Jv_JVMPI_Interface
.NotifyEvent
;
133 return JVMPI_NOT_AVAILABLE
;
136 return JVMPI_SUCCESS
;
140 jvmpiDisableEvent (jint event_type
, void *)
144 case JVMPI_EVENT_OBJECT_ALLOC
:
145 _Jv_JVMPI_Notify_OBJECT_ALLOC
= NULL
;
149 return JVMPI_NOT_AVAILABLE
;
152 return JVMPI_SUCCESS
;
161 local_ref_table
= new java::util::IdentityHashMap
;
162 global_ref_table
= new java::util::IdentityHashMap
;
165 _Jv_JVMPI_Interface
.version
= 1;
166 _Jv_JVMPI_Interface
.EnableEvent
= &jvmpiEnableEvent
;
167 _Jv_JVMPI_Interface
.DisableEvent
= &jvmpiDisableEvent
;
168 _Jv_JVMPI_Interface
.EnableGC
= &_Jv_EnableGC
;
169 _Jv_JVMPI_Interface
.DisableGC
= &_Jv_DisableGC
;
170 _Jv_JVMPI_Interface
.RunGC
= &_Jv_RunGC
;
174 // Tell the GC that a certain pointer is live.
176 mark_for_gc (jobject obj
, java::util::IdentityHashMap
*ref_table
)
178 JvSynchronize
sync (ref_table
);
180 using namespace java::lang
;
181 Integer
*refcount
= (Integer
*) ref_table
->get (obj
);
182 jint val
= (refcount
== NULL
) ? 0 : refcount
->intValue ();
183 // FIXME: what about out of memory error?
184 ref_table
->put (obj
, new Integer (val
+ 1));
189 unmark_for_gc (jobject obj
, java::util::IdentityHashMap
*ref_table
)
191 JvSynchronize
sync (ref_table
);
193 using namespace java::lang
;
194 Integer
*refcount
= (Integer
*) ref_table
->get (obj
);
196 jint val
= refcount
->intValue () - 1;
199 ref_table
->remove (obj
);
201 // FIXME: what about out of memory error?
202 ref_table
->put (obj
, new Integer (val
));
205 // "Unwrap" some random non-reference type. This exists to simplify
206 // other template functions.
214 // Unwrap a weak reference, if required.
219 using namespace gnu::gcj::runtime
;
220 // We can compare the class directly because JNIWeakRef is `final'.
221 // Doing it this way is much faster.
222 if (obj
== NULL
|| obj
->getClass () != &JNIWeakRef::class$
)
224 JNIWeakRef
*wr
= reinterpret_cast<JNIWeakRef
*> (obj
);
225 return reinterpret_cast<T
*> (wr
->get ());
230 static jobject JNICALL
231 _Jv_JNI_NewGlobalRef (JNIEnv
*, jobject obj
)
233 // This seems weird but I think it is correct.
235 mark_for_gc (obj
, global_ref_table
);
240 _Jv_JNI_DeleteGlobalRef (JNIEnv
*, jobject obj
)
242 // This seems weird but I think it is correct.
244 unmark_for_gc (obj
, global_ref_table
);
248 _Jv_JNI_DeleteLocalRef (JNIEnv
*env
, jobject obj
)
250 _Jv_JNI_LocalFrame
*frame
;
252 // This seems weird but I think it is correct.
255 for (frame
= env
->locals
; frame
!= NULL
; frame
= frame
->next
)
257 for (int i
= 0; i
< frame
->size
; ++i
)
259 if (frame
->vec
[i
] == obj
)
261 frame
->vec
[i
] = NULL
;
262 unmark_for_gc (obj
, local_ref_table
);
267 // Don't go past a marked frame.
268 JvAssert (frame
->marker
== MARK_NONE
);
275 _Jv_JNI_EnsureLocalCapacity (JNIEnv
*env
, jint size
)
277 // It is easier to just always allocate a new frame of the requested
278 // size. This isn't the most efficient thing, but for now we don't
279 // care. Note that _Jv_JNI_PushLocalFrame relies on this right now.
281 _Jv_JNI_LocalFrame
*frame
;
284 frame
= (_Jv_JNI_LocalFrame
*) _Jv_Malloc (sizeof (_Jv_JNI_LocalFrame
)
285 + size
* sizeof (jobject
));
293 frame
->marker
= MARK_NONE
;
295 frame
->allocated_p
= 0;
296 memset (&frame
->vec
[0], 0, size
* sizeof (jobject
));
297 frame
->next
= env
->locals
;
304 _Jv_JNI_PushLocalFrame (JNIEnv
*env
, jint size
)
306 jint r
= _Jv_JNI_EnsureLocalCapacity (env
, size
);
310 // The new frame is on top.
311 env
->locals
->marker
= MARK_USER
;
316 static jobject JNICALL
317 _Jv_JNI_NewLocalRef (JNIEnv
*env
, jobject obj
)
319 // This seems weird but I think it is correct.
322 // Try to find an open slot somewhere in the topmost frame.
323 _Jv_JNI_LocalFrame
*frame
= env
->locals
;
324 bool done
= false, set
= false;
325 for (; frame
!= NULL
&& ! done
; frame
= frame
->next
)
327 for (int i
= 0; i
< frame
->size
; ++i
)
329 if (frame
->vec
[i
] == NULL
)
334 frame
->allocated_p
= 1;
339 // If we found a slot, or if the frame we just searched is the
340 // mark frame, then we are done.
341 if (done
|| frame
== NULL
|| frame
->marker
!= MARK_NONE
)
347 // No slots, so we allocate a new frame. According to the spec
348 // we could just die here. FIXME: return value.
349 _Jv_JNI_EnsureLocalCapacity (env
, 16);
350 // We know the first element of the new frame will be ok.
351 env
->locals
->vec
[0] = obj
;
352 env
->locals
->allocated_p
= 1;
355 mark_for_gc (obj
, local_ref_table
);
359 static jobject JNICALL
360 _Jv_JNI_PopLocalFrame (JNIEnv
*env
, jobject result
, int stop
)
362 _Jv_JNI_LocalFrame
*rf
= env
->locals
;
365 while (rf
!= NULL
&& ! done
)
367 for (int i
= 0; i
< rf
->size
; ++i
)
368 if (rf
->vec
[i
] != NULL
)
369 unmark_for_gc (rf
->vec
[i
], local_ref_table
);
371 // If the frame we just freed is the marker frame, we are done.
372 done
= (rf
->marker
== stop
);
374 _Jv_JNI_LocalFrame
*n
= rf
->next
;
375 // When N==NULL, we've reached the reusable bottom_locals, and we must
376 // not free it. However, we must be sure to clear all its elements.
380 memset (&rf
->vec
[0], 0, rf
->size
* sizeof (jobject
));
390 // Update the local frame information.
393 return result
== NULL
? NULL
: _Jv_JNI_NewLocalRef (env
, result
);
396 static jobject JNICALL
397 _Jv_JNI_PopLocalFrame (JNIEnv
*env
, jobject result
)
399 return _Jv_JNI_PopLocalFrame (env
, result
, MARK_USER
);
402 // Make sure an array's type is compatible with the type of the
406 _Jv_JNI_check_types (JNIEnv
*env
, JArray
<T
> *array
, jclass K
)
408 jclass klass
= array
->getClass()->getComponentType();
409 if (__builtin_expect (klass
!= K
, false))
411 env
->ex
= new java::lang::IllegalAccessError ();
418 // Pop a `system' frame from the stack. This is `extern "C"' as it is
419 // used by the compiler.
421 _Jv_JNI_PopSystemFrame (JNIEnv
*env
)
423 // Only enter slow path when we're not at the bottom, or there have been
424 // allocations. Usually this is false and we can just null out the locals
427 if (__builtin_expect ((env
->locals
->next
428 || env
->locals
->allocated_p
), false))
429 _Jv_JNI_PopLocalFrame (env
, NULL
, MARK_SYSTEM
);
433 if (__builtin_expect (env
->ex
!= NULL
, false))
435 jthrowable t
= env
->ex
;
441 template<typename T
> T
extract_from_jvalue(jvalue
const & t
);
442 template<> jboolean
extract_from_jvalue(jvalue
const & jv
) { return jv
.z
; }
443 template<> jbyte
extract_from_jvalue(jvalue
const & jv
) { return jv
.b
; }
444 template<> jchar
extract_from_jvalue(jvalue
const & jv
) { return jv
.c
; }
445 template<> jshort
extract_from_jvalue(jvalue
const & jv
) { return jv
.s
; }
446 template<> jint
extract_from_jvalue(jvalue
const & jv
) { return jv
.i
; }
447 template<> jlong
extract_from_jvalue(jvalue
const & jv
) { return jv
.j
; }
448 template<> jfloat
extract_from_jvalue(jvalue
const & jv
) { return jv
.f
; }
449 template<> jdouble
extract_from_jvalue(jvalue
const & jv
) { return jv
.d
; }
450 template<> jobject
extract_from_jvalue(jvalue
const & jv
) { return jv
.l
; }
453 // This function is used from other template functions. It wraps the
454 // return value appropriately; we specialize it so that object returns
455 // are turned into local references.
458 wrap_value (JNIEnv
*, T value
)
463 // This specialization is used for jobject, jclass, jstring, jarray,
465 template<typename R
, typename T
>
467 wrap_value (JNIEnv
*env
, T
*value
)
469 return (value
== NULL
471 : (T
*) _Jv_JNI_NewLocalRef (env
, (jobject
) value
));
477 _Jv_JNI_GetVersion (JNIEnv
*)
479 return JNI_VERSION_1_4
;
482 static jclass JNICALL
483 _Jv_JNI_DefineClass (JNIEnv
*env
, const char *name
, jobject loader
,
484 const jbyte
*buf
, jsize bufLen
)
488 loader
= unwrap (loader
);
490 jstring sname
= JvNewStringUTF (name
);
491 jbyteArray bytes
= JvNewByteArray (bufLen
);
493 jbyte
*elts
= elements (bytes
);
494 memcpy (elts
, buf
, bufLen
* sizeof (jbyte
));
496 java::lang::ClassLoader
*l
497 = reinterpret_cast<java::lang::ClassLoader
*> (loader
);
499 jclass result
= l
->defineClass (sname
, bytes
, 0, bufLen
);
500 return (jclass
) wrap_value (env
, result
);
509 static jclass JNICALL
510 _Jv_JNI_FindClass (JNIEnv
*env
, const char *name
)
512 // FIXME: assume that NAME isn't too long.
513 int len
= strlen (name
);
515 for (int i
= 0; i
<= len
; ++i
)
516 s
[i
] = (name
[i
] == '/') ? '.' : name
[i
];
521 // This might throw an out of memory exception.
522 jstring n
= JvNewStringUTF (s
);
524 java::lang::ClassLoader
*loader
= NULL
;
525 if (env
->klass
!= NULL
)
526 loader
= env
->klass
->getClassLoaderInternal ();
530 // FIXME: should use getBaseClassLoader, but we don't have that
532 loader
= java::lang::ClassLoader::getSystemClassLoader ();
535 r
= loader
->loadClass (n
);
542 return (jclass
) wrap_value (env
, r
);
545 static jclass JNICALL
546 _Jv_JNI_GetSuperclass (JNIEnv
*env
, jclass clazz
)
548 return (jclass
) wrap_value (env
, unwrap (clazz
)->getSuperclass ());
551 static jboolean JNICALL
552 _Jv_JNI_IsAssignableFrom (JNIEnv
*, jclass clazz1
, jclass clazz2
)
554 return unwrap (clazz1
)->isAssignableFrom (unwrap (clazz2
));
558 _Jv_JNI_Throw (JNIEnv
*env
, jthrowable obj
)
560 // We check in case the user did some funky cast.
562 JvAssert (obj
!= NULL
&& java::lang::Throwable::class$
.isInstance (obj
));
568 _Jv_JNI_ThrowNew (JNIEnv
*env
, jclass clazz
, const char *message
)
570 using namespace java::lang::reflect
;
572 clazz
= unwrap (clazz
);
573 JvAssert (java::lang::Throwable::class$
.isAssignableFrom (clazz
));
578 JArray
<jclass
> *argtypes
579 = (JArray
<jclass
> *) JvNewObjectArray (1, &java::lang::Class::class$
,
582 jclass
*elts
= elements (argtypes
);
583 elts
[0] = &java::lang::String::class$
;
585 Constructor
*cons
= clazz
->getConstructor (argtypes
);
587 jobjectArray values
= JvNewObjectArray (1, &java::lang::String::class$
,
589 jobject
*velts
= elements (values
);
590 velts
[0] = JvNewStringUTF (message
);
592 jobject obj
= cons
->newInstance (values
);
594 env
->ex
= reinterpret_cast<jthrowable
> (obj
);
605 static jthrowable JNICALL
606 _Jv_JNI_ExceptionOccurred (JNIEnv
*env
)
608 return (jthrowable
) wrap_value (env
, env
->ex
);
612 _Jv_JNI_ExceptionDescribe (JNIEnv
*env
)
615 env
->ex
->printStackTrace();
619 _Jv_JNI_ExceptionClear (JNIEnv
*env
)
624 static jboolean JNICALL
625 _Jv_JNI_ExceptionCheck (JNIEnv
*env
)
627 return env
->ex
!= NULL
;
631 _Jv_JNI_FatalError (JNIEnv
*, const char *message
)
638 static jboolean JNICALL
639 _Jv_JNI_IsSameObject (JNIEnv
*, jobject obj1
, jobject obj2
)
641 return unwrap (obj1
) == unwrap (obj2
);
644 static jobject JNICALL
645 _Jv_JNI_AllocObject (JNIEnv
*env
, jclass clazz
)
648 using namespace java::lang::reflect
;
652 clazz
= unwrap (clazz
);
653 JvAssert (clazz
&& ! clazz
->isArray ());
654 if (clazz
->isInterface() || Modifier::isAbstract(clazz
->getModifiers()))
655 env
->ex
= new java::lang::InstantiationException ();
657 obj
= _Jv_AllocObject (clazz
);
664 return wrap_value (env
, obj
);
667 static jclass JNICALL
668 _Jv_JNI_GetObjectClass (JNIEnv
*env
, jobject obj
)
672 return (jclass
) wrap_value (env
, obj
->getClass());
675 static jboolean JNICALL
676 _Jv_JNI_IsInstanceOf (JNIEnv
*, jobject obj
, jclass clazz
)
678 return unwrap (clazz
)->isInstance(unwrap (obj
));
684 // This section concerns method invocation.
687 template<jboolean is_static
>
688 static jmethodID JNICALL
689 _Jv_JNI_GetAnyMethodID (JNIEnv
*env
, jclass clazz
,
690 const char *name
, const char *sig
)
694 clazz
= unwrap (clazz
);
695 _Jv_InitClass (clazz
);
697 _Jv_Utf8Const
*name_u
= _Jv_makeUtf8Const ((char *) name
, -1);
699 // FIXME: assume that SIG isn't too long.
700 int len
= strlen (sig
);
702 for (int i
= 0; i
<= len
; ++i
)
703 s
[i
] = (sig
[i
] == '/') ? '.' : sig
[i
];
704 _Jv_Utf8Const
*sig_u
= _Jv_makeUtf8Const ((char *) s
, -1);
706 JvAssert (! clazz
->isPrimitive());
708 using namespace java::lang::reflect
;
710 while (clazz
!= NULL
)
712 jint count
= JvNumMethods (clazz
);
713 jmethodID meth
= JvGetFirstMethod (clazz
);
715 for (jint i
= 0; i
< count
; ++i
)
717 if (((is_static
&& Modifier::isStatic (meth
->accflags
))
718 || (! is_static
&& ! Modifier::isStatic (meth
->accflags
)))
719 && _Jv_equalUtf8Consts (meth
->name
, name_u
)
720 && _Jv_equalUtf8Consts (meth
->signature
, sig_u
))
723 meth
= meth
->getNextMethod();
726 clazz
= clazz
->getSuperclass ();
729 java::lang::StringBuffer
*name_sig
=
730 new java::lang::StringBuffer (JvNewStringUTF (name
));
731 name_sig
->append ((jchar
) ' ')->append (JvNewStringUTF (s
));
732 env
->ex
= new java::lang::NoSuchMethodError (name_sig
->toString ());
742 // This is a helper function which turns a va_list into an array of
743 // `jvalue's. It needs signature information in order to do its work.
744 // The array of values must already be allocated.
746 array_from_valist (jvalue
*values
, JArray
<jclass
> *arg_types
, va_list vargs
)
748 jclass
*arg_elts
= elements (arg_types
);
749 for (int i
= 0; i
< arg_types
->length
; ++i
)
751 // Here we assume that sizeof(int) >= sizeof(jint), because we
752 // use `int' when decoding the varargs. Likewise for
753 // float, and double. Also we assume that sizeof(jlong) >=
754 // sizeof(int), i.e. that jlong values are not further
756 JvAssert (sizeof (int) >= sizeof (jint
));
757 JvAssert (sizeof (jlong
) >= sizeof (int));
758 JvAssert (sizeof (double) >= sizeof (jfloat
));
759 JvAssert (sizeof (double) >= sizeof (jdouble
));
760 if (arg_elts
[i
] == JvPrimClass (byte
))
761 values
[i
].b
= (jbyte
) va_arg (vargs
, int);
762 else if (arg_elts
[i
] == JvPrimClass (short))
763 values
[i
].s
= (jshort
) va_arg (vargs
, int);
764 else if (arg_elts
[i
] == JvPrimClass (int))
765 values
[i
].i
= (jint
) va_arg (vargs
, int);
766 else if (arg_elts
[i
] == JvPrimClass (long))
767 values
[i
].j
= (jlong
) va_arg (vargs
, jlong
);
768 else if (arg_elts
[i
] == JvPrimClass (float))
769 values
[i
].f
= (jfloat
) va_arg (vargs
, double);
770 else if (arg_elts
[i
] == JvPrimClass (double))
771 values
[i
].d
= (jdouble
) va_arg (vargs
, double);
772 else if (arg_elts
[i
] == JvPrimClass (boolean
))
773 values
[i
].z
= (jboolean
) va_arg (vargs
, int);
774 else if (arg_elts
[i
] == JvPrimClass (char))
775 values
[i
].c
= (jchar
) va_arg (vargs
, int);
779 values
[i
].l
= unwrap (va_arg (vargs
, jobject
));
784 // This can call any sort of method: virtual, "nonvirtual", static, or
786 template<typename T
, invocation_type style
>
788 _Jv_JNI_CallAnyMethodV (JNIEnv
*env
, jobject obj
, jclass klass
,
789 jmethodID id
, va_list vargs
)
792 klass
= unwrap (klass
);
794 jclass decl_class
= klass
? klass
: obj
->getClass ();
795 JvAssert (decl_class
!= NULL
);
798 JArray
<jclass
> *arg_types
;
802 _Jv_GetTypesFromSignature (id
, decl_class
,
803 &arg_types
, &return_type
);
805 jvalue args
[arg_types
->length
];
806 array_from_valist (args
, arg_types
, vargs
);
808 // For constructors we need to pass the Class we are instantiating.
809 if (style
== constructor
)
813 _Jv_CallAnyMethodA (obj
, return_type
, id
,
814 style
== constructor
,
816 arg_types
, args
, &result
);
818 return wrap_value (env
, extract_from_jvalue
<T
>(result
));
825 return wrap_value (env
, (T
) 0);
828 template<typename T
, invocation_type style
>
830 _Jv_JNI_CallAnyMethod (JNIEnv
*env
, jobject obj
, jclass klass
,
831 jmethodID method
, ...)
836 va_start (args
, method
);
837 result
= _Jv_JNI_CallAnyMethodV
<T
, style
> (env
, obj
, klass
, method
, args
);
843 template<typename T
, invocation_type style
>
845 _Jv_JNI_CallAnyMethodA (JNIEnv
*env
, jobject obj
, jclass klass
,
846 jmethodID id
, jvalue
*args
)
849 klass
= unwrap (klass
);
851 jclass decl_class
= klass
? klass
: obj
->getClass ();
852 JvAssert (decl_class
!= NULL
);
855 JArray
<jclass
> *arg_types
;
858 _Jv_GetTypesFromSignature (id
, decl_class
,
859 &arg_types
, &return_type
);
861 // For constructors we need to pass the Class we are instantiating.
862 if (style
== constructor
)
865 // Unwrap arguments as required. Eww.
866 jclass
*type_elts
= elements (arg_types
);
867 jvalue arg_copy
[arg_types
->length
];
868 for (int i
= 0; i
< arg_types
->length
; ++i
)
870 if (type_elts
[i
]->isPrimitive ())
871 arg_copy
[i
] = args
[i
];
873 arg_copy
[i
].l
= unwrap (args
[i
].l
);
877 _Jv_CallAnyMethodA (obj
, return_type
, id
,
878 style
== constructor
,
880 arg_types
, arg_copy
, &result
);
882 return wrap_value (env
, extract_from_jvalue
<T
>(result
));
889 return wrap_value (env
, (T
) 0);
892 template<invocation_type style
>
894 _Jv_JNI_CallAnyVoidMethodV (JNIEnv
*env
, jobject obj
, jclass klass
,
895 jmethodID id
, va_list vargs
)
898 klass
= unwrap (klass
);
900 jclass decl_class
= klass
? klass
: obj
->getClass ();
901 JvAssert (decl_class
!= NULL
);
904 JArray
<jclass
> *arg_types
;
907 _Jv_GetTypesFromSignature (id
, decl_class
,
908 &arg_types
, &return_type
);
910 jvalue args
[arg_types
->length
];
911 array_from_valist (args
, arg_types
, vargs
);
913 // For constructors we need to pass the Class we are instantiating.
914 if (style
== constructor
)
917 _Jv_CallAnyMethodA (obj
, return_type
, id
,
918 style
== constructor
,
920 arg_types
, args
, NULL
);
928 template<invocation_type style
>
930 _Jv_JNI_CallAnyVoidMethod (JNIEnv
*env
, jobject obj
, jclass klass
,
931 jmethodID method
, ...)
935 va_start (args
, method
);
936 _Jv_JNI_CallAnyVoidMethodV
<style
> (env
, obj
, klass
, method
, args
);
940 template<invocation_type style
>
942 _Jv_JNI_CallAnyVoidMethodA (JNIEnv
*env
, jobject obj
, jclass klass
,
943 jmethodID id
, jvalue
*args
)
945 jclass decl_class
= klass
? klass
: obj
->getClass ();
946 JvAssert (decl_class
!= NULL
);
949 JArray
<jclass
> *arg_types
;
952 _Jv_GetTypesFromSignature (id
, decl_class
,
953 &arg_types
, &return_type
);
955 // Unwrap arguments as required. Eww.
956 jclass
*type_elts
= elements (arg_types
);
957 jvalue arg_copy
[arg_types
->length
];
958 for (int i
= 0; i
< arg_types
->length
; ++i
)
960 if (type_elts
[i
]->isPrimitive ())
961 arg_copy
[i
] = args
[i
];
963 arg_copy
[i
].l
= unwrap (args
[i
].l
);
966 _Jv_CallAnyMethodA (obj
, return_type
, id
,
967 style
== constructor
,
969 arg_types
, args
, NULL
);
977 // Functions with this signature are used to implement functions in
978 // the CallMethod family.
981 _Jv_JNI_CallMethodV (JNIEnv
*env
, jobject obj
,
982 jmethodID id
, va_list args
)
984 return _Jv_JNI_CallAnyMethodV
<T
, normal
> (env
, obj
, NULL
, id
, args
);
987 // Functions with this signature are used to implement functions in
988 // the CallMethod family.
991 _Jv_JNI_CallMethod (JNIEnv
*env
, jobject obj
, jmethodID id
, ...)
997 result
= _Jv_JNI_CallAnyMethodV
<T
, normal
> (env
, obj
, NULL
, id
, args
);
1003 // Functions with this signature are used to implement functions in
1004 // the CallMethod family.
1005 template<typename T
>
1007 _Jv_JNI_CallMethodA (JNIEnv
*env
, jobject obj
,
1008 jmethodID id
, jvalue
*args
)
1010 return _Jv_JNI_CallAnyMethodA
<T
, normal
> (env
, obj
, NULL
, id
, args
);
1014 _Jv_JNI_CallVoidMethodV (JNIEnv
*env
, jobject obj
,
1015 jmethodID id
, va_list args
)
1017 _Jv_JNI_CallAnyVoidMethodV
<normal
> (env
, obj
, NULL
, id
, args
);
1021 _Jv_JNI_CallVoidMethod (JNIEnv
*env
, jobject obj
, jmethodID id
, ...)
1025 va_start (args
, id
);
1026 _Jv_JNI_CallAnyVoidMethodV
<normal
> (env
, obj
, NULL
, id
, args
);
1031 _Jv_JNI_CallVoidMethodA (JNIEnv
*env
, jobject obj
,
1032 jmethodID id
, jvalue
*args
)
1034 _Jv_JNI_CallAnyVoidMethodA
<normal
> (env
, obj
, NULL
, id
, args
);
1037 // Functions with this signature are used to implement functions in
1038 // the CallStaticMethod family.
1039 template<typename T
>
1041 _Jv_JNI_CallStaticMethodV (JNIEnv
*env
, jclass klass
,
1042 jmethodID id
, va_list args
)
1044 JvAssert (((id
->accflags
) & java::lang::reflect::Modifier::STATIC
));
1045 JvAssert (java::lang::Class::class$
.isInstance (unwrap (klass
)));
1047 return _Jv_JNI_CallAnyMethodV
<T
, static_type
> (env
, NULL
, klass
, id
, args
);
1050 // Functions with this signature are used to implement functions in
1051 // the CallStaticMethod family.
1052 template<typename T
>
1054 _Jv_JNI_CallStaticMethod (JNIEnv
*env
, jclass klass
,
1060 JvAssert (((id
->accflags
) & java::lang::reflect::Modifier::STATIC
));
1061 JvAssert (java::lang::Class::class$
.isInstance (unwrap (klass
)));
1063 va_start (args
, id
);
1064 result
= _Jv_JNI_CallAnyMethodV
<T
, static_type
> (env
, NULL
, klass
,
1071 // Functions with this signature are used to implement functions in
1072 // the CallStaticMethod family.
1073 template<typename T
>
1075 _Jv_JNI_CallStaticMethodA (JNIEnv
*env
, jclass klass
, jmethodID id
,
1078 JvAssert (((id
->accflags
) & java::lang::reflect::Modifier::STATIC
));
1079 JvAssert (java::lang::Class::class$
.isInstance (unwrap (klass
)));
1081 return _Jv_JNI_CallAnyMethodA
<T
, static_type
> (env
, NULL
, klass
, id
, args
);
1085 _Jv_JNI_CallStaticVoidMethodV (JNIEnv
*env
, jclass klass
,
1086 jmethodID id
, va_list args
)
1088 _Jv_JNI_CallAnyVoidMethodV
<static_type
> (env
, NULL
, klass
, id
, args
);
1092 _Jv_JNI_CallStaticVoidMethod (JNIEnv
*env
, jclass klass
,
1097 va_start (args
, id
);
1098 _Jv_JNI_CallAnyVoidMethodV
<static_type
> (env
, NULL
, klass
, id
, args
);
1103 _Jv_JNI_CallStaticVoidMethodA (JNIEnv
*env
, jclass klass
,
1104 jmethodID id
, jvalue
*args
)
1106 _Jv_JNI_CallAnyVoidMethodA
<static_type
> (env
, NULL
, klass
, id
, args
);
1109 static jobject JNICALL
1110 _Jv_JNI_NewObjectV (JNIEnv
*env
, jclass klass
,
1111 jmethodID id
, va_list args
)
1113 JvAssert (klass
&& ! klass
->isArray ());
1114 JvAssert (! strcmp (id
->name
->data
, "<init>")
1115 && id
->signature
->length
> 2
1116 && id
->signature
->data
[0] == '('
1117 && ! strcmp (&id
->signature
->data
[id
->signature
->length
- 2],
1120 return _Jv_JNI_CallAnyMethodV
<jobject
, constructor
> (env
, NULL
, klass
,
1124 static jobject JNICALL
1125 _Jv_JNI_NewObject (JNIEnv
*env
, jclass klass
, jmethodID id
, ...)
1127 JvAssert (klass
&& ! klass
->isArray ());
1128 JvAssert (! strcmp (id
->name
->data
, "<init>")
1129 && id
->signature
->length
> 2
1130 && id
->signature
->data
[0] == '('
1131 && ! strcmp (&id
->signature
->data
[id
->signature
->length
- 2],
1137 va_start (args
, id
);
1138 result
= _Jv_JNI_CallAnyMethodV
<jobject
, constructor
> (env
, NULL
, klass
,
1145 static jobject JNICALL
1146 _Jv_JNI_NewObjectA (JNIEnv
*env
, jclass klass
, jmethodID id
,
1149 JvAssert (klass
&& ! klass
->isArray ());
1150 JvAssert (! strcmp (id
->name
->data
, "<init>")
1151 && id
->signature
->length
> 2
1152 && id
->signature
->data
[0] == '('
1153 && ! strcmp (&id
->signature
->data
[id
->signature
->length
- 2],
1156 return _Jv_JNI_CallAnyMethodA
<jobject
, constructor
> (env
, NULL
, klass
,
1162 template<typename T
>
1164 _Jv_JNI_GetField (JNIEnv
*env
, jobject obj
, jfieldID field
)
1168 T
*ptr
= (T
*) ((char *) obj
+ field
->getOffset ());
1169 return wrap_value (env
, *ptr
);
1172 template<typename T
>
1174 _Jv_JNI_SetField (JNIEnv
*, jobject obj
, jfieldID field
, T value
)
1177 value
= unwrap (value
);
1180 T
*ptr
= (T
*) ((char *) obj
+ field
->getOffset ());
1184 template<jboolean is_static
>
1185 static jfieldID JNICALL
1186 _Jv_JNI_GetAnyFieldID (JNIEnv
*env
, jclass clazz
,
1187 const char *name
, const char *sig
)
1191 clazz
= unwrap (clazz
);
1193 _Jv_InitClass (clazz
);
1195 _Jv_Utf8Const
*a_name
= _Jv_makeUtf8Const ((char *) name
, -1);
1197 // FIXME: assume that SIG isn't too long.
1198 int len
= strlen (sig
);
1200 for (int i
= 0; i
<= len
; ++i
)
1201 s
[i
] = (sig
[i
] == '/') ? '.' : sig
[i
];
1202 jclass field_class
= _Jv_FindClassFromSignature ((char *) s
, NULL
);
1204 // FIXME: what if field_class == NULL?
1206 java::lang::ClassLoader
*loader
= clazz
->getClassLoaderInternal ();
1207 while (clazz
!= NULL
)
1209 // We acquire the class lock so that fields aren't resolved
1210 // while we are running.
1211 JvSynchronize
sync (clazz
);
1213 jint count
= (is_static
1214 ? JvNumStaticFields (clazz
)
1215 : JvNumInstanceFields (clazz
));
1216 jfieldID field
= (is_static
1217 ? JvGetFirstStaticField (clazz
)
1218 : JvGetFirstInstanceField (clazz
));
1219 for (jint i
= 0; i
< count
; ++i
)
1221 _Jv_Utf8Const
*f_name
= field
->getNameUtf8Const(clazz
);
1223 // The field might be resolved or it might not be. It
1224 // is much simpler to always resolve it.
1225 _Jv_Linker::resolve_field (field
, loader
);
1226 if (_Jv_equalUtf8Consts (f_name
, a_name
)
1227 && field
->getClass() == field_class
)
1230 field
= field
->getNextField ();
1233 clazz
= clazz
->getSuperclass ();
1236 env
->ex
= new java::lang::NoSuchFieldError ();
1238 catch (jthrowable t
)
1245 template<typename T
>
1247 _Jv_JNI_GetStaticField (JNIEnv
*env
, jclass
, jfieldID field
)
1249 T
*ptr
= (T
*) field
->u
.addr
;
1250 return wrap_value (env
, *ptr
);
1253 template<typename T
>
1255 _Jv_JNI_SetStaticField (JNIEnv
*, jclass
, jfieldID field
, T value
)
1257 value
= unwrap (value
);
1258 T
*ptr
= (T
*) field
->u
.addr
;
1262 static jstring JNICALL
1263 _Jv_JNI_NewString (JNIEnv
*env
, const jchar
*unichars
, jsize len
)
1267 jstring r
= _Jv_NewString (unichars
, len
);
1268 return (jstring
) wrap_value (env
, r
);
1270 catch (jthrowable t
)
1277 static jsize JNICALL
1278 _Jv_JNI_GetStringLength (JNIEnv
*, jstring string
)
1280 return unwrap (string
)->length();
1283 static const jchar
* JNICALL
1284 _Jv_JNI_GetStringChars (JNIEnv
*, jstring string
, jboolean
*isCopy
)
1286 string
= unwrap (string
);
1287 jchar
*result
= _Jv_GetStringChars (string
);
1288 mark_for_gc (string
, global_ref_table
);
1291 return (const jchar
*) result
;
1295 _Jv_JNI_ReleaseStringChars (JNIEnv
*, jstring string
, const jchar
*)
1297 unmark_for_gc (unwrap (string
), global_ref_table
);
1300 static jstring JNICALL
1301 _Jv_JNI_NewStringUTF (JNIEnv
*env
, const char *bytes
)
1305 jstring result
= JvNewStringUTF (bytes
);
1306 return (jstring
) wrap_value (env
, result
);
1308 catch (jthrowable t
)
1315 static jsize JNICALL
1316 _Jv_JNI_GetStringUTFLength (JNIEnv
*, jstring string
)
1318 return JvGetStringUTFLength (unwrap (string
));
1321 static const char * JNICALL
1322 _Jv_JNI_GetStringUTFChars (JNIEnv
*env
, jstring string
,
1327 string
= unwrap (string
);
1330 jsize len
= JvGetStringUTFLength (string
);
1331 char *r
= (char *) _Jv_Malloc (len
+ 1);
1332 JvGetStringUTFRegion (string
, 0, string
->length(), r
);
1338 return (const char *) r
;
1340 catch (jthrowable t
)
1348 _Jv_JNI_ReleaseStringUTFChars (JNIEnv
*, jstring
, const char *utf
)
1350 _Jv_Free ((void *) utf
);
1354 _Jv_JNI_GetStringRegion (JNIEnv
*env
, jstring string
, jsize start
,
1355 jsize len
, jchar
*buf
)
1357 string
= unwrap (string
);
1358 jchar
*result
= _Jv_GetStringChars (string
);
1359 if (start
< 0 || start
> string
->length ()
1360 || len
< 0 || start
+ len
> string
->length ())
1364 env
->ex
= new java::lang::StringIndexOutOfBoundsException ();
1366 catch (jthrowable t
)
1372 memcpy (buf
, &result
[start
], len
* sizeof (jchar
));
1376 _Jv_JNI_GetStringUTFRegion (JNIEnv
*env
, jstring str
, jsize start
,
1377 jsize len
, char *buf
)
1381 if (start
< 0 || start
> str
->length ()
1382 || len
< 0 || start
+ len
> str
->length ())
1386 env
->ex
= new java::lang::StringIndexOutOfBoundsException ();
1388 catch (jthrowable t
)
1394 _Jv_GetStringUTFRegion (str
, start
, len
, buf
);
1397 static const jchar
* JNICALL
1398 _Jv_JNI_GetStringCritical (JNIEnv
*, jstring str
, jboolean
*isCopy
)
1400 jchar
*result
= _Jv_GetStringChars (unwrap (str
));
1407 _Jv_JNI_ReleaseStringCritical (JNIEnv
*, jstring
, const jchar
*)
1412 static jsize JNICALL
1413 _Jv_JNI_GetArrayLength (JNIEnv
*, jarray array
)
1415 return unwrap (array
)->length
;
1418 static jobjectArray JNICALL
1419 _Jv_JNI_NewObjectArray (JNIEnv
*env
, jsize length
,
1420 jclass elementClass
, jobject init
)
1424 elementClass
= unwrap (elementClass
);
1425 init
= unwrap (init
);
1427 _Jv_CheckCast (elementClass
, init
);
1428 jarray result
= JvNewObjectArray (length
, elementClass
, init
);
1429 return (jobjectArray
) wrap_value (env
, result
);
1431 catch (jthrowable t
)
1438 static jobject JNICALL
1439 _Jv_JNI_GetObjectArrayElement (JNIEnv
*env
, jobjectArray array
,
1442 if ((unsigned) index
>= (unsigned) array
->length
)
1443 _Jv_ThrowBadArrayIndex (index
);
1444 jobject
*elts
= elements (unwrap (array
));
1445 return wrap_value (env
, elts
[index
]);
1449 _Jv_JNI_SetObjectArrayElement (JNIEnv
*env
, jobjectArray array
,
1450 jsize index
, jobject value
)
1454 array
= unwrap (array
);
1455 value
= unwrap (value
);
1457 _Jv_CheckArrayStore (array
, value
);
1458 if ((unsigned) index
>= (unsigned) array
->length
)
1459 _Jv_ThrowBadArrayIndex (index
);
1460 jobject
*elts
= elements (array
);
1461 elts
[index
] = value
;
1463 catch (jthrowable t
)
1469 template<typename T
, jclass K
>
1470 static JArray
<T
> * JNICALL
1471 _Jv_JNI_NewPrimitiveArray (JNIEnv
*env
, jsize length
)
1475 return (JArray
<T
> *) wrap_value (env
, _Jv_NewPrimArray (K
, length
));
1477 catch (jthrowable t
)
1484 template<typename T
, jclass K
>
1486 _Jv_JNI_GetPrimitiveArrayElements (JNIEnv
*env
, JArray
<T
> *array
,
1489 array
= unwrap (array
);
1490 if (! _Jv_JNI_check_types (env
, array
, K
))
1492 T
*elts
= elements (array
);
1495 // We elect never to copy.
1498 mark_for_gc (array
, global_ref_table
);
1502 template<typename T
, jclass K
>
1504 _Jv_JNI_ReleasePrimitiveArrayElements (JNIEnv
*env
, JArray
<T
> *array
,
1505 T
*, jint
/* mode */)
1507 array
= unwrap (array
);
1508 _Jv_JNI_check_types (env
, array
, K
);
1509 // Note that we ignore MODE. We can do this because we never copy
1510 // the array elements. My reading of the JNI documentation is that
1511 // this is an option for the implementor.
1512 unmark_for_gc (array
, global_ref_table
);
1515 template<typename T
, jclass K
>
1517 _Jv_JNI_GetPrimitiveArrayRegion (JNIEnv
*env
, JArray
<T
> *array
,
1518 jsize start
, jsize len
,
1521 array
= unwrap (array
);
1522 if (! _Jv_JNI_check_types (env
, array
, K
))
1525 // The cast to unsigned lets us save a comparison.
1526 if (start
< 0 || len
< 0
1527 || (unsigned long) (start
+ len
) > (unsigned long) array
->length
)
1532 env
->ex
= new java::lang::ArrayIndexOutOfBoundsException ();
1534 catch (jthrowable t
)
1536 // Could have thown out of memory error.
1542 T
*elts
= elements (array
) + start
;
1543 memcpy (buf
, elts
, len
* sizeof (T
));
1547 template<typename T
, jclass K
>
1549 _Jv_JNI_SetPrimitiveArrayRegion (JNIEnv
*env
, JArray
<T
> *array
,
1550 jsize start
, jsize len
, T
*buf
)
1552 array
= unwrap (array
);
1553 if (! _Jv_JNI_check_types (env
, array
, K
))
1556 // The cast to unsigned lets us save a comparison.
1557 if (start
< 0 || len
< 0
1558 || (unsigned long) (start
+ len
) > (unsigned long) array
->length
)
1563 env
->ex
= new java::lang::ArrayIndexOutOfBoundsException ();
1565 catch (jthrowable t
)
1572 T
*elts
= elements (array
) + start
;
1573 memcpy (elts
, buf
, len
* sizeof (T
));
1577 static void * JNICALL
1578 _Jv_JNI_GetPrimitiveArrayCritical (JNIEnv
*, jarray array
,
1581 array
= unwrap (array
);
1582 // FIXME: does this work?
1583 jclass klass
= array
->getClass()->getComponentType();
1584 JvAssert (klass
->isPrimitive ());
1585 char *r
= _Jv_GetArrayElementFromElementType (array
, klass
);
1592 _Jv_JNI_ReleasePrimitiveArrayCritical (JNIEnv
*, jarray
, void *, jint
)
1598 _Jv_JNI_MonitorEnter (JNIEnv
*env
, jobject obj
)
1602 _Jv_MonitorEnter (unwrap (obj
));
1605 catch (jthrowable t
)
1613 _Jv_JNI_MonitorExit (JNIEnv
*env
, jobject obj
)
1617 _Jv_MonitorExit (unwrap (obj
));
1620 catch (jthrowable t
)
1629 _Jv_JNI_ToReflectedField (JNIEnv
*env
, jclass cls
, jfieldID fieldID
,
1635 java::lang::reflect::Field
*field
= new java::lang::reflect::Field();
1636 field
->declaringClass
= cls
;
1637 field
->offset
= (char*) fieldID
- (char *) cls
->fields
;
1638 field
->name
= _Jv_NewStringUtf8Const (fieldID
->getNameUtf8Const (cls
));
1639 return wrap_value (env
, field
);
1641 catch (jthrowable t
)
1649 static jfieldID JNICALL
1650 _Jv_JNI_FromReflectedField (JNIEnv
*, jobject f
)
1652 using namespace java::lang::reflect
;
1655 Field
*field
= reinterpret_cast<Field
*> (f
);
1656 return _Jv_FromReflectedField (field
);
1660 _Jv_JNI_ToReflectedMethod (JNIEnv
*env
, jclass klass
, jmethodID id
,
1663 using namespace java::lang::reflect
;
1665 jobject result
= NULL
;
1666 klass
= unwrap (klass
);
1670 if (_Jv_equalUtf8Consts (id
->name
, init_name
))
1673 Constructor
*cons
= new Constructor ();
1674 cons
->offset
= (char *) id
- (char *) &klass
->methods
;
1675 cons
->declaringClass
= klass
;
1680 Method
*meth
= new Method ();
1681 meth
->offset
= (char *) id
- (char *) &klass
->methods
;
1682 meth
->declaringClass
= klass
;
1686 catch (jthrowable t
)
1691 return wrap_value (env
, result
);
1694 static jmethodID JNICALL
1695 _Jv_JNI_FromReflectedMethod (JNIEnv
*, jobject method
)
1697 using namespace java::lang::reflect
;
1698 method
= unwrap (method
);
1699 if (Method::class$
.isInstance (method
))
1700 return _Jv_FromReflectedMethod (reinterpret_cast<Method
*> (method
));
1702 _Jv_FromReflectedConstructor (reinterpret_cast<Constructor
*> (method
));
1707 _Jv_JNI_NewWeakGlobalRef (JNIEnv
*env
, jobject obj
)
1709 using namespace gnu::gcj::runtime
;
1710 JNIWeakRef
*ref
= NULL
;
1714 // This seems weird but I think it is correct.
1716 ref
= new JNIWeakRef (obj
);
1717 mark_for_gc (ref
, global_ref_table
);
1719 catch (jthrowable t
)
1724 return reinterpret_cast<jweak
> (ref
);
1728 _Jv_JNI_DeleteWeakGlobalRef (JNIEnv
*, jweak obj
)
1730 using namespace gnu::gcj::runtime
;
1731 JNIWeakRef
*ref
= reinterpret_cast<JNIWeakRef
*> (obj
);
1732 unmark_for_gc (ref
, global_ref_table
);
1738 // Direct byte buffers.
1740 static jobject JNICALL
1741 _Jv_JNI_NewDirectByteBuffer (JNIEnv
*, void *address
, jlong length
)
1743 using namespace gnu::gcj
;
1744 using namespace java::nio
;
1745 return new DirectByteBufferImpl$ReadWrite
1746 (reinterpret_cast<RawData
*> (address
), length
);
1749 static void * JNICALL
1750 _Jv_JNI_GetDirectBufferAddress (JNIEnv
*, jobject buffer
)
1752 using namespace java::nio
;
1753 if (! _Jv_IsInstanceOf (buffer
, &Buffer::class$
))
1755 Buffer
*tmp
= static_cast<Buffer
*> (buffer
);
1756 return reinterpret_cast<void *> (tmp
->address
);
1759 static jlong JNICALL
1760 _Jv_JNI_GetDirectBufferCapacity (JNIEnv
*, jobject buffer
)
1762 using namespace java::nio
;
1763 if (! _Jv_IsInstanceOf (buffer
, &Buffer::class$
))
1765 Buffer
*tmp
= static_cast<Buffer
*> (buffer
);
1766 if (tmp
->address
== NULL
)
1768 return tmp
->capacity();
1773 // Hash table of native methods.
1774 static JNINativeMethod
*nathash
;
1775 // Number of slots used.
1776 static int nathash_count
= 0;
1777 // Number of slots available. Must be power of 2.
1778 static int nathash_size
= 0;
1780 #define DELETED_ENTRY ((char *) (~0))
1782 // Compute a hash value for a native method descriptor.
1784 hash (const JNINativeMethod
*method
)
1791 hash
= (31 * hash
) + *ptr
++;
1793 ptr
= method
->signature
;
1795 hash
= (31 * hash
) + *ptr
++;
1800 // Find the slot where a native method goes.
1801 static JNINativeMethod
*
1802 nathash_find_slot (const JNINativeMethod
*method
)
1804 jint h
= hash (method
);
1805 int step
= (h
^ (h
>> 16)) | 1;
1806 int w
= h
& (nathash_size
- 1);
1811 JNINativeMethod
*slotp
= &nathash
[w
];
1812 if (slotp
->name
== NULL
)
1815 return &nathash
[del
];
1819 else if (slotp
->name
== DELETED_ENTRY
)
1821 else if (! strcmp (slotp
->name
, method
->name
)
1822 && ! strcmp (slotp
->signature
, method
->signature
))
1824 w
= (w
+ step
) & (nathash_size
- 1);
1828 // Find a method. Return NULL if it isn't in the hash table.
1830 nathash_find (JNINativeMethod
*method
)
1832 if (nathash
== NULL
)
1834 JNINativeMethod
*slot
= nathash_find_slot (method
);
1835 if (slot
->name
== NULL
|| slot
->name
== DELETED_ENTRY
)
1843 if (nathash
== NULL
)
1845 nathash_size
= 1024;
1847 (JNINativeMethod
*) _Jv_AllocBytes (nathash_size
1848 * sizeof (JNINativeMethod
));
1849 memset (nathash
, 0, nathash_size
* sizeof (JNINativeMethod
));
1853 int savesize
= nathash_size
;
1854 JNINativeMethod
*savehash
= nathash
;
1857 (JNINativeMethod
*) _Jv_AllocBytes (nathash_size
1858 * sizeof (JNINativeMethod
));
1859 memset (nathash
, 0, nathash_size
* sizeof (JNINativeMethod
));
1861 for (int i
= 0; i
< savesize
; ++i
)
1863 if (savehash
[i
].name
!= NULL
&& savehash
[i
].name
!= DELETED_ENTRY
)
1865 JNINativeMethod
*slot
= nathash_find_slot (&savehash
[i
]);
1866 *slot
= savehash
[i
];
1873 nathash_add (const JNINativeMethod
*method
)
1875 if (3 * nathash_count
>= 2 * nathash_size
)
1877 JNINativeMethod
*slot
= nathash_find_slot (method
);
1878 // If the slot has a real entry in it, then there is no work to do.
1879 if (slot
->name
!= NULL
&& slot
->name
!= DELETED_ENTRY
)
1882 slot
->name
= strdup (method
->name
);
1883 slot
->signature
= strdup (method
->signature
);
1884 slot
->fnPtr
= method
->fnPtr
;
1888 _Jv_JNI_RegisterNatives (JNIEnv
*env
, jclass klass
,
1889 const JNINativeMethod
*methods
,
1892 // Synchronize while we do the work. This must match
1893 // synchronization in some other functions that manipulate or use
1894 // the nathash table.
1895 JvSynchronize
sync (global_ref_table
);
1897 // Look at each descriptor given us, and find the corresponding
1898 // method in the class.
1899 for (int j
= 0; j
< nMethods
; ++j
)
1903 _Jv_Method
*imeths
= JvGetFirstMethod (klass
);
1904 for (int i
= 0; i
< JvNumMethods (klass
); ++i
)
1906 _Jv_Method
*self
= &imeths
[i
];
1908 if (! strcmp (self
->name
->chars (), methods
[j
].name
)
1909 && ! strcmp (self
->signature
->chars (), methods
[j
].signature
))
1911 if (! (self
->accflags
& java::lang::reflect::Modifier::NATIVE
))
1914 // Found a match that is native.
1916 nathash_add (&methods
[j
]);
1924 jstring m
= JvNewStringUTF (methods
[j
].name
);
1927 env
->ex
= new java::lang::NoSuchMethodError (m
);
1929 catch (jthrowable t
)
1941 _Jv_JNI_UnregisterNatives (JNIEnv
*, jclass
)
1943 // FIXME -- we could implement this.
1949 // Add a character to the buffer, encoding properly.
1951 add_char (char *buf
, jchar c
, int *here
)
1955 buf
[(*here
)++] = '_';
1956 buf
[(*here
)++] = '1';
1960 buf
[(*here
)++] = '_';
1961 buf
[(*here
)++] = '2';
1965 buf
[(*here
)++] = '_';
1966 buf
[(*here
)++] = '3';
1969 // Also check for `.' here because we might be passed an internal
1970 // qualified class name like `foo.bar'.
1971 else if (c
== '/' || c
== '.')
1972 buf
[(*here
)++] = '_';
1973 else if ((c
>= '0' && c
<= '9')
1974 || (c
>= 'a' && c
<= 'z')
1975 || (c
>= 'A' && c
<= 'Z'))
1976 buf
[(*here
)++] = (char) c
;
1979 // "Unicode" character.
1980 buf
[(*here
)++] = '_';
1981 buf
[(*here
)++] = '0';
1982 for (int i
= 0; i
< 4; ++i
)
1985 buf
[(*here
) + 3 - i
] = (val
> 10) ? ('a' + val
- 10) : ('0' + val
);
1992 // Compute a mangled name for a native function. This computes the
1993 // long name, and also returns an index which indicates where a NUL
1994 // can be placed to create the short name. This function assumes that
1995 // the buffer is large enough for its results.
1997 mangled_name (jclass klass
, _Jv_Utf8Const
*func_name
,
1998 _Jv_Utf8Const
*signature
, char *buf
, int *long_start
)
2000 strcpy (buf
, "Java_");
2003 // Add fully qualified class name.
2004 jchar
*chars
= _Jv_GetStringChars (klass
->getName ());
2005 jint len
= klass
->getName ()->length ();
2006 for (int i
= 0; i
< len
; ++i
)
2007 add_char (buf
, chars
[i
], &here
);
2009 // Don't use add_char because we need a literal `_'.
2012 const unsigned char *fn
= (const unsigned char *) func_name
->chars ();
2013 const unsigned char *limit
= fn
+ func_name
->len ();
2014 for (int i
= 0; ; ++i
)
2016 int ch
= UTF8_GET (fn
, limit
);
2019 add_char (buf
, ch
, &here
);
2022 // This is where the long signature begins.
2027 const unsigned char *sig
= (const unsigned char *) signature
->chars ();
2028 limit
= sig
+ signature
->len ();
2029 JvAssert (sig
[0] == '(');
2033 int ch
= UTF8_GET (sig
, limit
);
2034 if (ch
== ')' || ch
< 0)
2036 add_char (buf
, ch
, &here
);
2042 // Return the current thread's JNIEnv; if one does not exist, create
2043 // it. Also create a new system frame for use. This is `extern "C"'
2044 // because the compiler calls it.
2046 _Jv_GetJNIEnvNewFrame (jclass klass
)
2048 JNIEnv
*env
= _Jv_GetCurrentJNIEnv ();
2049 if (__builtin_expect (env
== NULL
, false))
2051 env
= (JNIEnv
*) _Jv_MallocUnchecked (sizeof (JNIEnv
));
2052 env
->p
= &_Jv_JNIFunctions
;
2055 // We set env->ex below.
2057 // Set up the bottom, reusable frame.
2058 env
->bottom_locals
= (_Jv_JNI_LocalFrame
*)
2059 _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame
)
2061 * sizeof (jobject
)));
2063 env
->bottom_locals
->marker
= MARK_SYSTEM
;
2064 env
->bottom_locals
->size
= FRAME_SIZE
;
2065 env
->bottom_locals
->next
= NULL
;
2066 env
->bottom_locals
->allocated_p
= 0;
2067 memset (&env
->bottom_locals
->vec
[0], 0,
2068 env
->bottom_locals
->size
* sizeof (jobject
));
2070 _Jv_SetCurrentJNIEnv (env
);
2073 // If we're in a simple JNI call (non-nested), we can just reuse the
2074 // locals frame we allocated many calls ago, back when the env was first
2077 if (__builtin_expect (env
->locals
== NULL
, true))
2078 env
->locals
= env
->bottom_locals
;
2082 // Alternatively, we might be re-entering JNI, in which case we can't
2083 // reuse the bottom_locals frame, because it is already underneath
2084 // us. So we need to make a new one.
2086 _Jv_JNI_LocalFrame
*frame
2087 = (_Jv_JNI_LocalFrame
*) _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame
)
2089 * sizeof (jobject
)));
2091 frame
->marker
= MARK_SYSTEM
;
2092 frame
->size
= FRAME_SIZE
;
2093 frame
->allocated_p
= 0;
2094 frame
->next
= env
->locals
;
2096 memset (&frame
->vec
[0], 0,
2097 frame
->size
* sizeof (jobject
));
2099 env
->locals
= frame
;
2107 // Destroy the env's reusable resources. This is called from the thread
2108 // destructor "finalize_native" in natThread.cc
2110 _Jv_FreeJNIEnv (_Jv_JNIEnv
*env
)
2115 if (env
->bottom_locals
!= NULL
)
2116 _Jv_Free (env
->bottom_locals
);
2121 // Return the function which implements a particular JNI method. If
2122 // we can't find the function, we throw the appropriate exception.
2123 // This is `extern "C"' because the compiler uses it.
2125 _Jv_LookupJNIMethod (jclass klass
, _Jv_Utf8Const
*name
,
2126 _Jv_Utf8Const
*signature
, MAYBE_UNUSED
int args_size
)
2128 int name_length
= name
->len();
2129 int sig_length
= signature
->len();
2130 char buf
[10 + 6 * (name_length
+ sig_length
) + 12];
2134 // Synchronize on something convenient. Right now we use the hash.
2135 JvSynchronize
sync (global_ref_table
);
2137 // First see if we have an override in the hash table.
2138 strncpy (buf
, name
->chars (), name_length
);
2139 buf
[name_length
] = '\0';
2140 strncpy (buf
+ name_length
+ 1, signature
->chars (), sig_length
);
2141 buf
[name_length
+ sig_length
+ 1] = '\0';
2142 JNINativeMethod meth
;
2144 meth
.signature
= buf
+ name_length
+ 1;
2145 function
= nathash_find (&meth
);
2146 if (function
!= NULL
)
2149 // If there was no override, then look in the symbol table.
2151 mangled_name (klass
, name
, signature
, buf
+ 1, &long_start
);
2152 char c
= buf
[long_start
+ 1];
2153 buf
[long_start
+ 1] = '\0';
2155 function
= _Jv_FindSymbolInExecutable (buf
+ 1);
2157 // On Win32, we use the "stdcall" calling convention (see JNICALL
2160 // For a function named 'fooBar' that takes 'nn' bytes as arguments,
2161 // by default, MinGW GCC exports it as 'fooBar@nn', MSVC exports it
2162 // as '_fooBar@nn' and Borland C exports it as 'fooBar'. We try to
2163 // take care of all these variations here.
2165 char asz_buf
[12]; /* '@' + '2147483647' (32-bit INT_MAX) + '\0' */
2166 char long_nm_sv
[11]; /* Ditto, except for the '\0'. */
2168 if (function
== NULL
)
2170 // We have tried searching for the 'fooBar' form (BCC) - now
2173 // First, save the part of the long name that will be damaged
2174 // by appending '@nn'.
2175 memcpy (long_nm_sv
, (buf
+ long_start
+ 1 + 1), sizeof (long_nm_sv
));
2177 sprintf (asz_buf
, "@%d", args_size
);
2178 strcat (buf
, asz_buf
);
2180 // Search for the '_fooBar@nn' form (MSVC).
2181 function
= _Jv_FindSymbolInExecutable (buf
);
2183 if (function
== NULL
)
2185 // Search for the 'fooBar@nn' form (MinGW GCC).
2186 function
= _Jv_FindSymbolInExecutable (buf
+ 1);
2191 if (function
== NULL
)
2193 buf
[long_start
+ 1] = c
;
2195 // Restore the part of the long name that was damaged by
2196 // appending the '@nn'.
2197 memcpy ((buf
+ long_start
+ 1 + 1), long_nm_sv
, sizeof (long_nm_sv
));
2199 function
= _Jv_FindSymbolInExecutable (buf
+ 1);
2200 if (function
== NULL
)
2203 strcat (buf
, asz_buf
);
2204 function
= _Jv_FindSymbolInExecutable (buf
);
2205 if (function
== NULL
)
2206 function
= _Jv_FindSymbolInExecutable (buf
+ 1);
2208 if (function
== NULL
)
2211 jstring str
= JvNewStringUTF (name
->chars ());
2212 throw new java::lang::UnsatisfiedLinkError (str
);
2222 // This function is the stub which is used to turn an ordinary (CNI)
2223 // method call into a JNI call.
2225 _Jv_JNIMethod::call (ffi_cif
*, void *ret
, ffi_raw
*args
, void *__this
)
2227 _Jv_JNIMethod
* _this
= (_Jv_JNIMethod
*) __this
;
2229 JNIEnv
*env
= _Jv_GetJNIEnvNewFrame (_this
->defining_class
);
2231 // FIXME: we should mark every reference parameter as a local. For
2232 // now we assume a conservative GC, and we assume that the
2233 // references are on the stack somewhere.
2235 // We cache the value that we find, of course, but if we don't find
2236 // a value we don't cache that fact -- we might subsequently load a
2237 // library which finds the function in question.
2239 // Synchronize on a convenient object to ensure sanity in case two
2240 // threads reach this point for the same function at the same
2242 JvSynchronize
sync (global_ref_table
);
2243 if (_this
->function
== NULL
)
2245 int args_size
= sizeof (JNIEnv
*) + _this
->args_raw_size
;
2247 if (_this
->self
->accflags
& java::lang::reflect::Modifier::STATIC
)
2248 args_size
+= sizeof (_this
->defining_class
);
2250 _this
->function
= _Jv_LookupJNIMethod (_this
->defining_class
,
2252 _this
->self
->signature
,
2257 JvAssert (_this
->args_raw_size
% sizeof (ffi_raw
) == 0);
2258 ffi_raw real_args
[2 + _this
->args_raw_size
/ sizeof (ffi_raw
)];
2261 // First argument is always the environment pointer.
2262 real_args
[offset
++].ptr
= env
;
2264 // For a static method, we pass in the Class. For non-static
2265 // methods, the `this' argument is already handled.
2266 if ((_this
->self
->accflags
& java::lang::reflect::Modifier::STATIC
))
2267 real_args
[offset
++].ptr
= _this
->defining_class
;
2269 // In libgcj, the callee synchronizes.
2270 jobject sync
= NULL
;
2271 if ((_this
->self
->accflags
& java::lang::reflect::Modifier::SYNCHRONIZED
))
2273 if ((_this
->self
->accflags
& java::lang::reflect::Modifier::STATIC
))
2274 sync
= _this
->defining_class
;
2276 sync
= (jobject
) args
[0].ptr
;
2277 _Jv_MonitorEnter (sync
);
2280 // Copy over passed-in arguments.
2281 memcpy (&real_args
[offset
], args
, _this
->args_raw_size
);
2283 // The actual call to the JNI function.
2284 #if FFI_NATIVE_RAW_API
2285 ffi_raw_call (&_this
->jni_cif
, (void (*)()) _this
->function
,
2288 ffi_java_raw_call (&_this
->jni_cif
, (void (*)()) _this
->function
,
2293 _Jv_MonitorExit (sync
);
2295 _Jv_JNI_PopSystemFrame (env
);
2298 #endif /* INTERPRETER */
2306 // An internal helper function.
2308 _Jv_JNI_AttachCurrentThread (JavaVM
*, jstring name
, void **penv
,
2309 void *args
, jboolean is_daemon
)
2311 JavaVMAttachArgs
*attach
= reinterpret_cast<JavaVMAttachArgs
*> (args
);
2312 java::lang::ThreadGroup
*group
= NULL
;
2316 // FIXME: do we really want to support 1.1?
2317 if (attach
->version
!= JNI_VERSION_1_4
2318 && attach
->version
!= JNI_VERSION_1_2
2319 && attach
->version
!= JNI_VERSION_1_1
)
2320 return JNI_EVERSION
;
2322 JvAssert (java::lang::ThreadGroup::class$
.isInstance (attach
->group
));
2323 group
= reinterpret_cast<java::lang::ThreadGroup
*> (attach
->group
);
2326 // Attaching an already-attached thread is a no-op.
2327 if (_Jv_GetCurrentJNIEnv () != NULL
)
2330 JNIEnv
*env
= (JNIEnv
*) _Jv_MallocUnchecked (sizeof (JNIEnv
));
2333 env
->p
= &_Jv_JNIFunctions
;
2337 = (_Jv_JNI_LocalFrame
*) _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame
)
2339 * sizeof (jobject
)));
2340 env
->locals
= env
->bottom_locals
;
2341 if (env
->locals
== NULL
)
2347 env
->locals
->allocated_p
= 0;
2348 env
->locals
->marker
= MARK_SYSTEM
;
2349 env
->locals
->size
= FRAME_SIZE
;
2350 env
->locals
->next
= NULL
;
2352 for (int i
= 0; i
< env
->locals
->size
; ++i
)
2353 env
->locals
->vec
[i
] = NULL
;
2355 *penv
= reinterpret_cast<void *> (env
);
2357 // This thread might already be a Java thread -- this function might
2358 // have been called simply to set the new JNIEnv.
2359 if (_Jv_ThreadCurrent () == NULL
)
2364 _Jv_AttachCurrentThreadAsDaemon (name
, group
);
2366 _Jv_AttachCurrentThread (name
, group
);
2368 catch (jthrowable t
)
2373 _Jv_SetCurrentJNIEnv (env
);
2378 // This is the one actually used by JNI.
2380 _Jv_JNI_AttachCurrentThread (JavaVM
*vm
, void **penv
, void *args
)
2382 return _Jv_JNI_AttachCurrentThread (vm
, NULL
, penv
, args
, false);
2386 _Jv_JNI_AttachCurrentThreadAsDaemon (JavaVM
*vm
, void **penv
,
2389 return _Jv_JNI_AttachCurrentThread (vm
, NULL
, penv
, args
, true);
2393 _Jv_JNI_DestroyJavaVM (JavaVM
*vm
)
2395 JvAssert (the_vm
&& vm
== the_vm
);
2398 if (_Jv_ThreadCurrent () != NULL
)
2404 main_name
= JvNewStringLatin1 ("main");
2406 catch (jthrowable t
)
2411 jint r
= _Jv_JNI_AttachCurrentThread (vm
, main_name
,
2412 reinterpret_cast<void **> (&env
),
2418 env
= _Jv_GetCurrentJNIEnv ();
2422 // Docs say that this always returns an error code.
2427 _Jv_JNI_DetachCurrentThread (JavaVM
*)
2429 jint code
= _Jv_DetachCurrentThread ();
2430 return code
? JNI_EDETACHED
: 0;
2434 _Jv_JNI_GetEnv (JavaVM
*, void **penv
, jint version
)
2436 if (_Jv_ThreadCurrent () == NULL
)
2439 return JNI_EDETACHED
;
2443 // Handle JVMPI requests.
2444 if (version
== JVMPI_VERSION_1
)
2446 *penv
= (void *) &_Jv_JVMPI_Interface
;
2451 // FIXME: do we really want to support 1.1?
2452 if (version
!= JNI_VERSION_1_4
&& version
!= JNI_VERSION_1_2
2453 && version
!= JNI_VERSION_1_1
)
2456 return JNI_EVERSION
;
2459 *penv
= (void *) _Jv_GetCurrentJNIEnv ();
2464 JNI_GetDefaultJavaVMInitArgs (void *args
)
2466 jint version
= * (jint
*) args
;
2467 // Here we only support 1.2 and 1.4.
2468 if (version
!= JNI_VERSION_1_2
&& version
!= JNI_VERSION_1_4
)
2469 return JNI_EVERSION
;
2471 JavaVMInitArgs
*ia
= reinterpret_cast<JavaVMInitArgs
*> (args
);
2472 ia
->version
= JNI_VERSION_1_4
;
2475 ia
->ignoreUnrecognized
= true;
2481 JNI_CreateJavaVM (JavaVM
**vm
, void **penv
, void *args
)
2483 JvAssert (! the_vm
);
2485 _Jv_CreateJavaVM (NULL
);
2487 // FIXME: synchronize
2488 JavaVM
*nvm
= (JavaVM
*) _Jv_MallocUnchecked (sizeof (JavaVM
));
2491 nvm
->functions
= &_Jv_JNI_InvokeFunctions
;
2493 // Parse the arguments.
2496 jint version
= * (jint
*) args
;
2497 // We only support 1.2 and 1.4.
2498 if (version
!= JNI_VERSION_1_2
&& version
!= JNI_VERSION_1_4
)
2499 return JNI_EVERSION
;
2500 JavaVMInitArgs
*ia
= reinterpret_cast<JavaVMInitArgs
*> (args
);
2501 for (int i
= 0; i
< ia
->nOptions
; ++i
)
2503 if (! strcmp (ia
->options
[i
].optionString
, "vfprintf")
2504 || ! strcmp (ia
->options
[i
].optionString
, "exit")
2505 || ! strcmp (ia
->options
[i
].optionString
, "abort"))
2507 // We are required to recognize these, but for now we
2508 // don't handle them in any way. FIXME.
2511 else if (! strncmp (ia
->options
[i
].optionString
,
2512 "-verbose", sizeof ("-verbose") - 1))
2514 // We don't do anything with this option either. We
2515 // might want to make sure the argument is valid, but we
2516 // don't really care all that much for now.
2519 else if (! strncmp (ia
->options
[i
].optionString
, "-D", 2))
2524 else if (ia
->ignoreUnrecognized
)
2526 if (ia
->options
[i
].optionString
[0] == '_'
2527 || ! strncmp (ia
->options
[i
].optionString
, "-X", 2))
2535 jint r
=_Jv_JNI_AttachCurrentThread (nvm
, penv
, NULL
);
2546 JNI_GetCreatedJavaVMs (JavaVM
**vm_buffer
, jsize buf_len
, jsize
*n_vms
)
2551 // We only support a single VM.
2554 vm_buffer
[0] = the_vm
;
2565 // FIXME: synchronize
2568 JavaVM
*nvm
= (JavaVM
*) _Jv_MallocUnchecked (sizeof (JavaVM
));
2570 nvm
->functions
= &_Jv_JNI_InvokeFunctions
;
2574 // If this is a Java thread, we want to make sure it has an
2575 // associated JNIEnv.
2576 if (_Jv_ThreadCurrent () != NULL
)
2579 _Jv_JNI_AttachCurrentThread (the_vm
, &ignore
, NULL
);
2586 _Jv_JNI_GetJavaVM (JNIEnv
*, JavaVM
**vm
)
2588 *vm
= _Jv_GetJavaVM ();
2589 return *vm
== NULL
? JNI_ERR
: JNI_OK
;
2594 #define RESERVED NULL
2596 struct JNINativeInterface _Jv_JNIFunctions
=
2602 _Jv_JNI_GetVersion
, // GetVersion
2603 _Jv_JNI_DefineClass
, // DefineClass
2604 _Jv_JNI_FindClass
, // FindClass
2605 _Jv_JNI_FromReflectedMethod
, // FromReflectedMethod
2606 _Jv_JNI_FromReflectedField
, // FromReflectedField
2607 _Jv_JNI_ToReflectedMethod
, // ToReflectedMethod
2608 _Jv_JNI_GetSuperclass
, // GetSuperclass
2609 _Jv_JNI_IsAssignableFrom
, // IsAssignableFrom
2610 _Jv_JNI_ToReflectedField
, // ToReflectedField
2611 _Jv_JNI_Throw
, // Throw
2612 _Jv_JNI_ThrowNew
, // ThrowNew
2613 _Jv_JNI_ExceptionOccurred
, // ExceptionOccurred
2614 _Jv_JNI_ExceptionDescribe
, // ExceptionDescribe
2615 _Jv_JNI_ExceptionClear
, // ExceptionClear
2616 _Jv_JNI_FatalError
, // FatalError
2618 _Jv_JNI_PushLocalFrame
, // PushLocalFrame
2619 _Jv_JNI_PopLocalFrame
, // PopLocalFrame
2620 _Jv_JNI_NewGlobalRef
, // NewGlobalRef
2621 _Jv_JNI_DeleteGlobalRef
, // DeleteGlobalRef
2622 _Jv_JNI_DeleteLocalRef
, // DeleteLocalRef
2624 _Jv_JNI_IsSameObject
, // IsSameObject
2626 _Jv_JNI_NewLocalRef
, // NewLocalRef
2627 _Jv_JNI_EnsureLocalCapacity
, // EnsureLocalCapacity
2629 _Jv_JNI_AllocObject
, // AllocObject
2630 _Jv_JNI_NewObject
, // NewObject
2631 _Jv_JNI_NewObjectV
, // NewObjectV
2632 _Jv_JNI_NewObjectA
, // NewObjectA
2633 _Jv_JNI_GetObjectClass
, // GetObjectClass
2634 _Jv_JNI_IsInstanceOf
, // IsInstanceOf
2635 _Jv_JNI_GetAnyMethodID
<false>, // GetMethodID
2637 _Jv_JNI_CallMethod
<jobject
>, // CallObjectMethod
2638 _Jv_JNI_CallMethodV
<jobject
>, // CallObjectMethodV
2639 _Jv_JNI_CallMethodA
<jobject
>, // CallObjectMethodA
2640 _Jv_JNI_CallMethod
<jboolean
>, // CallBooleanMethod
2641 _Jv_JNI_CallMethodV
<jboolean
>, // CallBooleanMethodV
2642 _Jv_JNI_CallMethodA
<jboolean
>, // CallBooleanMethodA
2643 _Jv_JNI_CallMethod
<jbyte
>, // CallByteMethod
2644 _Jv_JNI_CallMethodV
<jbyte
>, // CallByteMethodV
2645 _Jv_JNI_CallMethodA
<jbyte
>, // CallByteMethodA
2646 _Jv_JNI_CallMethod
<jchar
>, // CallCharMethod
2647 _Jv_JNI_CallMethodV
<jchar
>, // CallCharMethodV
2648 _Jv_JNI_CallMethodA
<jchar
>, // CallCharMethodA
2649 _Jv_JNI_CallMethod
<jshort
>, // CallShortMethod
2650 _Jv_JNI_CallMethodV
<jshort
>, // CallShortMethodV
2651 _Jv_JNI_CallMethodA
<jshort
>, // CallShortMethodA
2652 _Jv_JNI_CallMethod
<jint
>, // CallIntMethod
2653 _Jv_JNI_CallMethodV
<jint
>, // CallIntMethodV
2654 _Jv_JNI_CallMethodA
<jint
>, // CallIntMethodA
2655 _Jv_JNI_CallMethod
<jlong
>, // CallLongMethod
2656 _Jv_JNI_CallMethodV
<jlong
>, // CallLongMethodV
2657 _Jv_JNI_CallMethodA
<jlong
>, // CallLongMethodA
2658 _Jv_JNI_CallMethod
<jfloat
>, // CallFloatMethod
2659 _Jv_JNI_CallMethodV
<jfloat
>, // CallFloatMethodV
2660 _Jv_JNI_CallMethodA
<jfloat
>, // CallFloatMethodA
2661 _Jv_JNI_CallMethod
<jdouble
>, // CallDoubleMethod
2662 _Jv_JNI_CallMethodV
<jdouble
>, // CallDoubleMethodV
2663 _Jv_JNI_CallMethodA
<jdouble
>, // CallDoubleMethodA
2664 _Jv_JNI_CallVoidMethod
, // CallVoidMethod
2665 _Jv_JNI_CallVoidMethodV
, // CallVoidMethodV
2666 _Jv_JNI_CallVoidMethodA
, // CallVoidMethodA
2668 // Nonvirtual method invocation functions follow.
2669 _Jv_JNI_CallAnyMethod
<jobject
, nonvirtual
>, // CallNonvirtualObjectMethod
2670 _Jv_JNI_CallAnyMethodV
<jobject
, nonvirtual
>, // CallNonvirtualObjectMethodV
2671 _Jv_JNI_CallAnyMethodA
<jobject
, nonvirtual
>, // CallNonvirtualObjectMethodA
2672 _Jv_JNI_CallAnyMethod
<jboolean
, nonvirtual
>, // CallNonvirtualBooleanMethod
2673 _Jv_JNI_CallAnyMethodV
<jboolean
, nonvirtual
>, // CallNonvirtualBooleanMethodV
2674 _Jv_JNI_CallAnyMethodA
<jboolean
, nonvirtual
>, // CallNonvirtualBooleanMethodA
2675 _Jv_JNI_CallAnyMethod
<jbyte
, nonvirtual
>, // CallNonvirtualByteMethod
2676 _Jv_JNI_CallAnyMethodV
<jbyte
, nonvirtual
>, // CallNonvirtualByteMethodV
2677 _Jv_JNI_CallAnyMethodA
<jbyte
, nonvirtual
>, // CallNonvirtualByteMethodA
2678 _Jv_JNI_CallAnyMethod
<jchar
, nonvirtual
>, // CallNonvirtualCharMethod
2679 _Jv_JNI_CallAnyMethodV
<jchar
, nonvirtual
>, // CallNonvirtualCharMethodV
2680 _Jv_JNI_CallAnyMethodA
<jchar
, nonvirtual
>, // CallNonvirtualCharMethodA
2681 _Jv_JNI_CallAnyMethod
<jshort
, nonvirtual
>, // CallNonvirtualShortMethod
2682 _Jv_JNI_CallAnyMethodV
<jshort
, nonvirtual
>, // CallNonvirtualShortMethodV
2683 _Jv_JNI_CallAnyMethodA
<jshort
, nonvirtual
>, // CallNonvirtualShortMethodA
2684 _Jv_JNI_CallAnyMethod
<jint
, nonvirtual
>, // CallNonvirtualIntMethod
2685 _Jv_JNI_CallAnyMethodV
<jint
, nonvirtual
>, // CallNonvirtualIntMethodV
2686 _Jv_JNI_CallAnyMethodA
<jint
, nonvirtual
>, // CallNonvirtualIntMethodA
2687 _Jv_JNI_CallAnyMethod
<jlong
, nonvirtual
>, // CallNonvirtualLongMethod
2688 _Jv_JNI_CallAnyMethodV
<jlong
, nonvirtual
>, // CallNonvirtualLongMethodV
2689 _Jv_JNI_CallAnyMethodA
<jlong
, nonvirtual
>, // CallNonvirtualLongMethodA
2690 _Jv_JNI_CallAnyMethod
<jfloat
, nonvirtual
>, // CallNonvirtualFloatMethod
2691 _Jv_JNI_CallAnyMethodV
<jfloat
, nonvirtual
>, // CallNonvirtualFloatMethodV
2692 _Jv_JNI_CallAnyMethodA
<jfloat
, nonvirtual
>, // CallNonvirtualFloatMethodA
2693 _Jv_JNI_CallAnyMethod
<jdouble
, nonvirtual
>, // CallNonvirtualDoubleMethod
2694 _Jv_JNI_CallAnyMethodV
<jdouble
, nonvirtual
>, // CallNonvirtualDoubleMethodV
2695 _Jv_JNI_CallAnyMethodA
<jdouble
, nonvirtual
>, // CallNonvirtualDoubleMethodA
2696 _Jv_JNI_CallAnyVoidMethod
<nonvirtual
>, // CallNonvirtualVoidMethod
2697 _Jv_JNI_CallAnyVoidMethodV
<nonvirtual
>, // CallNonvirtualVoidMethodV
2698 _Jv_JNI_CallAnyVoidMethodA
<nonvirtual
>, // CallNonvirtualVoidMethodA
2700 _Jv_JNI_GetAnyFieldID
<false>, // GetFieldID
2701 _Jv_JNI_GetField
<jobject
>, // GetObjectField
2702 _Jv_JNI_GetField
<jboolean
>, // GetBooleanField
2703 _Jv_JNI_GetField
<jbyte
>, // GetByteField
2704 _Jv_JNI_GetField
<jchar
>, // GetCharField
2705 _Jv_JNI_GetField
<jshort
>, // GetShortField
2706 _Jv_JNI_GetField
<jint
>, // GetIntField
2707 _Jv_JNI_GetField
<jlong
>, // GetLongField
2708 _Jv_JNI_GetField
<jfloat
>, // GetFloatField
2709 _Jv_JNI_GetField
<jdouble
>, // GetDoubleField
2710 _Jv_JNI_SetField
, // SetObjectField
2711 _Jv_JNI_SetField
, // SetBooleanField
2712 _Jv_JNI_SetField
, // SetByteField
2713 _Jv_JNI_SetField
, // SetCharField
2714 _Jv_JNI_SetField
, // SetShortField
2715 _Jv_JNI_SetField
, // SetIntField
2716 _Jv_JNI_SetField
, // SetLongField
2717 _Jv_JNI_SetField
, // SetFloatField
2718 _Jv_JNI_SetField
, // SetDoubleField
2719 _Jv_JNI_GetAnyMethodID
<true>, // GetStaticMethodID
2721 _Jv_JNI_CallStaticMethod
<jobject
>, // CallStaticObjectMethod
2722 _Jv_JNI_CallStaticMethodV
<jobject
>, // CallStaticObjectMethodV
2723 _Jv_JNI_CallStaticMethodA
<jobject
>, // CallStaticObjectMethodA
2724 _Jv_JNI_CallStaticMethod
<jboolean
>, // CallStaticBooleanMethod
2725 _Jv_JNI_CallStaticMethodV
<jboolean
>, // CallStaticBooleanMethodV
2726 _Jv_JNI_CallStaticMethodA
<jboolean
>, // CallStaticBooleanMethodA
2727 _Jv_JNI_CallStaticMethod
<jbyte
>, // CallStaticByteMethod
2728 _Jv_JNI_CallStaticMethodV
<jbyte
>, // CallStaticByteMethodV
2729 _Jv_JNI_CallStaticMethodA
<jbyte
>, // CallStaticByteMethodA
2730 _Jv_JNI_CallStaticMethod
<jchar
>, // CallStaticCharMethod
2731 _Jv_JNI_CallStaticMethodV
<jchar
>, // CallStaticCharMethodV
2732 _Jv_JNI_CallStaticMethodA
<jchar
>, // CallStaticCharMethodA
2733 _Jv_JNI_CallStaticMethod
<jshort
>, // CallStaticShortMethod
2734 _Jv_JNI_CallStaticMethodV
<jshort
>, // CallStaticShortMethodV
2735 _Jv_JNI_CallStaticMethodA
<jshort
>, // CallStaticShortMethodA
2736 _Jv_JNI_CallStaticMethod
<jint
>, // CallStaticIntMethod
2737 _Jv_JNI_CallStaticMethodV
<jint
>, // CallStaticIntMethodV
2738 _Jv_JNI_CallStaticMethodA
<jint
>, // CallStaticIntMethodA
2739 _Jv_JNI_CallStaticMethod
<jlong
>, // CallStaticLongMethod
2740 _Jv_JNI_CallStaticMethodV
<jlong
>, // CallStaticLongMethodV
2741 _Jv_JNI_CallStaticMethodA
<jlong
>, // CallStaticLongMethodA
2742 _Jv_JNI_CallStaticMethod
<jfloat
>, // CallStaticFloatMethod
2743 _Jv_JNI_CallStaticMethodV
<jfloat
>, // CallStaticFloatMethodV
2744 _Jv_JNI_CallStaticMethodA
<jfloat
>, // CallStaticFloatMethodA
2745 _Jv_JNI_CallStaticMethod
<jdouble
>, // CallStaticDoubleMethod
2746 _Jv_JNI_CallStaticMethodV
<jdouble
>, // CallStaticDoubleMethodV
2747 _Jv_JNI_CallStaticMethodA
<jdouble
>, // CallStaticDoubleMethodA
2748 _Jv_JNI_CallStaticVoidMethod
, // CallStaticVoidMethod
2749 _Jv_JNI_CallStaticVoidMethodV
, // CallStaticVoidMethodV
2750 _Jv_JNI_CallStaticVoidMethodA
, // CallStaticVoidMethodA
2752 _Jv_JNI_GetAnyFieldID
<true>, // GetStaticFieldID
2753 _Jv_JNI_GetStaticField
<jobject
>, // GetStaticObjectField
2754 _Jv_JNI_GetStaticField
<jboolean
>, // GetStaticBooleanField
2755 _Jv_JNI_GetStaticField
<jbyte
>, // GetStaticByteField
2756 _Jv_JNI_GetStaticField
<jchar
>, // GetStaticCharField
2757 _Jv_JNI_GetStaticField
<jshort
>, // GetStaticShortField
2758 _Jv_JNI_GetStaticField
<jint
>, // GetStaticIntField
2759 _Jv_JNI_GetStaticField
<jlong
>, // GetStaticLongField
2760 _Jv_JNI_GetStaticField
<jfloat
>, // GetStaticFloatField
2761 _Jv_JNI_GetStaticField
<jdouble
>, // GetStaticDoubleField
2762 _Jv_JNI_SetStaticField
, // SetStaticObjectField
2763 _Jv_JNI_SetStaticField
, // SetStaticBooleanField
2764 _Jv_JNI_SetStaticField
, // SetStaticByteField
2765 _Jv_JNI_SetStaticField
, // SetStaticCharField
2766 _Jv_JNI_SetStaticField
, // SetStaticShortField
2767 _Jv_JNI_SetStaticField
, // SetStaticIntField
2768 _Jv_JNI_SetStaticField
, // SetStaticLongField
2769 _Jv_JNI_SetStaticField
, // SetStaticFloatField
2770 _Jv_JNI_SetStaticField
, // SetStaticDoubleField
2771 _Jv_JNI_NewString
, // NewString
2772 _Jv_JNI_GetStringLength
, // GetStringLength
2773 _Jv_JNI_GetStringChars
, // GetStringChars
2774 _Jv_JNI_ReleaseStringChars
, // ReleaseStringChars
2775 _Jv_JNI_NewStringUTF
, // NewStringUTF
2776 _Jv_JNI_GetStringUTFLength
, // GetStringUTFLength
2777 _Jv_JNI_GetStringUTFChars
, // GetStringUTFChars
2778 _Jv_JNI_ReleaseStringUTFChars
, // ReleaseStringUTFChars
2779 _Jv_JNI_GetArrayLength
, // GetArrayLength
2780 _Jv_JNI_NewObjectArray
, // NewObjectArray
2781 _Jv_JNI_GetObjectArrayElement
, // GetObjectArrayElement
2782 _Jv_JNI_SetObjectArrayElement
, // SetObjectArrayElement
2783 _Jv_JNI_NewPrimitiveArray
<jboolean
, JvPrimClass (boolean
)>,
2785 _Jv_JNI_NewPrimitiveArray
<jbyte
, JvPrimClass (byte
)>, // NewByteArray
2786 _Jv_JNI_NewPrimitiveArray
<jchar
, JvPrimClass (char)>, // NewCharArray
2787 _Jv_JNI_NewPrimitiveArray
<jshort
, JvPrimClass (short)>, // NewShortArray
2788 _Jv_JNI_NewPrimitiveArray
<jint
, JvPrimClass (int)>, // NewIntArray
2789 _Jv_JNI_NewPrimitiveArray
<jlong
, JvPrimClass (long)>, // NewLongArray
2790 _Jv_JNI_NewPrimitiveArray
<jfloat
, JvPrimClass (float)>, // NewFloatArray
2791 _Jv_JNI_NewPrimitiveArray
<jdouble
, JvPrimClass (double)>, // NewDoubleArray
2792 _Jv_JNI_GetPrimitiveArrayElements
<jboolean
, JvPrimClass (boolean
)>,
2793 // GetBooleanArrayElements
2794 _Jv_JNI_GetPrimitiveArrayElements
<jbyte
, JvPrimClass (byte
)>,
2795 // GetByteArrayElements
2796 _Jv_JNI_GetPrimitiveArrayElements
<jchar
, JvPrimClass (char)>,
2797 // GetCharArrayElements
2798 _Jv_JNI_GetPrimitiveArrayElements
<jshort
, JvPrimClass (short)>,
2799 // GetShortArrayElements
2800 _Jv_JNI_GetPrimitiveArrayElements
<jint
, JvPrimClass (int)>,
2801 // GetIntArrayElements
2802 _Jv_JNI_GetPrimitiveArrayElements
<jlong
, JvPrimClass (long)>,
2803 // GetLongArrayElements
2804 _Jv_JNI_GetPrimitiveArrayElements
<jfloat
, JvPrimClass (float)>,
2805 // GetFloatArrayElements
2806 _Jv_JNI_GetPrimitiveArrayElements
<jdouble
, JvPrimClass (double)>,
2807 // GetDoubleArrayElements
2808 _Jv_JNI_ReleasePrimitiveArrayElements
<jboolean
, JvPrimClass (boolean
)>,
2809 // ReleaseBooleanArrayElements
2810 _Jv_JNI_ReleasePrimitiveArrayElements
<jbyte
, JvPrimClass (byte
)>,
2811 // ReleaseByteArrayElements
2812 _Jv_JNI_ReleasePrimitiveArrayElements
<jchar
, JvPrimClass (char)>,
2813 // ReleaseCharArrayElements
2814 _Jv_JNI_ReleasePrimitiveArrayElements
<jshort
, JvPrimClass (short)>,
2815 // ReleaseShortArrayElements
2816 _Jv_JNI_ReleasePrimitiveArrayElements
<jint
, JvPrimClass (int)>,
2817 // ReleaseIntArrayElements
2818 _Jv_JNI_ReleasePrimitiveArrayElements
<jlong
, JvPrimClass (long)>,
2819 // ReleaseLongArrayElements
2820 _Jv_JNI_ReleasePrimitiveArrayElements
<jfloat
, JvPrimClass (float)>,
2821 // ReleaseFloatArrayElements
2822 _Jv_JNI_ReleasePrimitiveArrayElements
<jdouble
, JvPrimClass (double)>,
2823 // ReleaseDoubleArrayElements
2824 _Jv_JNI_GetPrimitiveArrayRegion
<jboolean
, JvPrimClass (boolean
)>,
2825 // GetBooleanArrayRegion
2826 _Jv_JNI_GetPrimitiveArrayRegion
<jbyte
, JvPrimClass (byte
)>,
2827 // GetByteArrayRegion
2828 _Jv_JNI_GetPrimitiveArrayRegion
<jchar
, JvPrimClass (char)>,
2829 // GetCharArrayRegion
2830 _Jv_JNI_GetPrimitiveArrayRegion
<jshort
, JvPrimClass (short)>,
2831 // GetShortArrayRegion
2832 _Jv_JNI_GetPrimitiveArrayRegion
<jint
, JvPrimClass (int)>,
2833 // GetIntArrayRegion
2834 _Jv_JNI_GetPrimitiveArrayRegion
<jlong
, JvPrimClass (long)>,
2835 // GetLongArrayRegion
2836 _Jv_JNI_GetPrimitiveArrayRegion
<jfloat
, JvPrimClass (float)>,
2837 // GetFloatArrayRegion
2838 _Jv_JNI_GetPrimitiveArrayRegion
<jdouble
, JvPrimClass (double)>,
2839 // GetDoubleArrayRegion
2840 _Jv_JNI_SetPrimitiveArrayRegion
<jboolean
, JvPrimClass (boolean
)>,
2841 // SetBooleanArrayRegion
2842 _Jv_JNI_SetPrimitiveArrayRegion
<jbyte
, JvPrimClass (byte
)>,
2843 // SetByteArrayRegion
2844 _Jv_JNI_SetPrimitiveArrayRegion
<jchar
, JvPrimClass (char)>,
2845 // SetCharArrayRegion
2846 _Jv_JNI_SetPrimitiveArrayRegion
<jshort
, JvPrimClass (short)>,
2847 // SetShortArrayRegion
2848 _Jv_JNI_SetPrimitiveArrayRegion
<jint
, JvPrimClass (int)>,
2849 // SetIntArrayRegion
2850 _Jv_JNI_SetPrimitiveArrayRegion
<jlong
, JvPrimClass (long)>,
2851 // SetLongArrayRegion
2852 _Jv_JNI_SetPrimitiveArrayRegion
<jfloat
, JvPrimClass (float)>,
2853 // SetFloatArrayRegion
2854 _Jv_JNI_SetPrimitiveArrayRegion
<jdouble
, JvPrimClass (double)>,
2855 // SetDoubleArrayRegion
2856 _Jv_JNI_RegisterNatives
, // RegisterNatives
2857 _Jv_JNI_UnregisterNatives
, // UnregisterNatives
2858 _Jv_JNI_MonitorEnter
, // MonitorEnter
2859 _Jv_JNI_MonitorExit
, // MonitorExit
2860 _Jv_JNI_GetJavaVM
, // GetJavaVM
2862 _Jv_JNI_GetStringRegion
, // GetStringRegion
2863 _Jv_JNI_GetStringUTFRegion
, // GetStringUTFRegion
2864 _Jv_JNI_GetPrimitiveArrayCritical
, // GetPrimitiveArrayCritical
2865 _Jv_JNI_ReleasePrimitiveArrayCritical
, // ReleasePrimitiveArrayCritical
2866 _Jv_JNI_GetStringCritical
, // GetStringCritical
2867 _Jv_JNI_ReleaseStringCritical
, // ReleaseStringCritical
2869 _Jv_JNI_NewWeakGlobalRef
, // NewWeakGlobalRef
2870 _Jv_JNI_DeleteWeakGlobalRef
, // DeleteWeakGlobalRef
2872 _Jv_JNI_ExceptionCheck
, // ExceptionCheck
2874 _Jv_JNI_NewDirectByteBuffer
, // NewDirectByteBuffer
2875 _Jv_JNI_GetDirectBufferAddress
, // GetDirectBufferAddress
2876 _Jv_JNI_GetDirectBufferCapacity
// GetDirectBufferCapacity
2879 struct JNIInvokeInterface _Jv_JNI_InvokeFunctions
=
2885 _Jv_JNI_DestroyJavaVM
,
2886 _Jv_JNI_AttachCurrentThread
,
2887 _Jv_JNI_DetachCurrentThread
,
2889 _Jv_JNI_AttachCurrentThreadAsDaemon