1 // jni.cc - JNI implementation, including the jump table.
3 /* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
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 "jvmti-int.h"
28 #include <java/lang/Class.h>
29 #include <java/lang/ClassLoader.h>
30 #include <java/lang/Throwable.h>
31 #include <java/lang/ArrayIndexOutOfBoundsException.h>
32 #include <java/lang/StringIndexOutOfBoundsException.h>
33 #include <java/lang/StringBuffer.h>
34 #include <java/lang/UnsatisfiedLinkError.h>
35 #include <java/lang/InstantiationException.h>
36 #include <java/lang/NoSuchFieldError.h>
37 #include <java/lang/NoSuchMethodError.h>
38 #include <java/lang/reflect/Constructor.h>
39 #include <java/lang/reflect/Method.h>
40 #include <java/lang/reflect/Modifier.h>
41 #include <java/lang/OutOfMemoryError.h>
42 #include <java/lang/Integer.h>
43 #include <java/lang/ThreadGroup.h>
44 #include <java/lang/Thread.h>
45 #include <java/lang/IllegalAccessError.h>
46 #include <java/nio/Buffer.h>
47 #include <java/nio/DirectByteBufferImpl.h>
48 #include <java/nio/DirectByteBufferImpl$ReadWrite.h>
49 #include <java/util/IdentityHashMap.h>
50 #include <gnu/gcj/RawData.h>
51 #include <java/lang/ClassNotFoundException.h>
53 #include <gcj/method.h>
54 #include <gcj/field.h>
56 #include <java-interp.h>
57 #include <java-threads.h>
61 // This enum is used to select different template instantiations in
62 // the invocation code.
71 // Forward declarations.
72 extern struct JNINativeInterface _Jv_JNIFunctions
;
73 extern struct JNIInvokeInterface _Jv_JNI_InvokeFunctions
;
75 // Number of slots in the default frame. The VM must allow at least
79 // Mark value indicating this is an overflow frame.
81 // Mark value indicating this is a user frame.
83 // Mark value indicating this is a system frame.
86 // This structure is used to keep track of local references.
87 struct _Jv_JNI_LocalFrame
89 // This is one of the MARK_ constants.
92 // Flag to indicate some locals were allocated.
95 // Number of elements in frame.
98 // The class loader of the JNI method that allocated this frame.
99 ::java::lang::ClassLoader
*loader
;
101 // Next frame in chain.
102 _Jv_JNI_LocalFrame
*next
;
104 // The elements. These are allocated using the C "struct hack".
108 // This holds a reference count for all local references.
109 static java::util::IdentityHashMap
*local_ref_table
;
110 // This holds a reference count for all global references.
111 static java::util::IdentityHashMap
*global_ref_table
;
117 // The only JVMPI interface description.
118 static JVMPI_Interface _Jv_JVMPI_Interface
;
121 jvmpiEnableEvent (jint event_type
, void *)
125 case JVMPI_EVENT_OBJECT_ALLOC
:
126 _Jv_JVMPI_Notify_OBJECT_ALLOC
= _Jv_JVMPI_Interface
.NotifyEvent
;
129 case JVMPI_EVENT_THREAD_START
:
130 _Jv_JVMPI_Notify_THREAD_START
= _Jv_JVMPI_Interface
.NotifyEvent
;
133 case JVMPI_EVENT_THREAD_END
:
134 _Jv_JVMPI_Notify_THREAD_END
= _Jv_JVMPI_Interface
.NotifyEvent
;
138 return JVMPI_NOT_AVAILABLE
;
141 return JVMPI_SUCCESS
;
145 jvmpiDisableEvent (jint event_type
, void *)
149 case JVMPI_EVENT_OBJECT_ALLOC
:
150 _Jv_JVMPI_Notify_OBJECT_ALLOC
= NULL
;
154 return JVMPI_NOT_AVAILABLE
;
157 return JVMPI_SUCCESS
;
166 local_ref_table
= new java::util::IdentityHashMap
;
167 global_ref_table
= new java::util::IdentityHashMap
;
170 _Jv_JVMPI_Interface
.version
= 1;
171 _Jv_JVMPI_Interface
.EnableEvent
= &jvmpiEnableEvent
;
172 _Jv_JVMPI_Interface
.DisableEvent
= &jvmpiDisableEvent
;
173 _Jv_JVMPI_Interface
.EnableGC
= &_Jv_EnableGC
;
174 _Jv_JVMPI_Interface
.DisableGC
= &_Jv_DisableGC
;
175 _Jv_JVMPI_Interface
.RunGC
= &_Jv_RunGC
;
179 // Tell the GC that a certain pointer is live.
181 mark_for_gc (jobject obj
, java::util::IdentityHashMap
*ref_table
)
183 JvSynchronize
sync (ref_table
);
185 using namespace java::lang
;
186 Integer
*refcount
= (Integer
*) ref_table
->get (obj
);
187 jint val
= (refcount
== NULL
) ? 0 : refcount
->intValue ();
188 // FIXME: what about out of memory error?
189 ref_table
->put (obj
, new Integer (val
+ 1));
194 unmark_for_gc (jobject obj
, java::util::IdentityHashMap
*ref_table
)
196 JvSynchronize
sync (ref_table
);
198 using namespace java::lang
;
199 Integer
*refcount
= (Integer
*) ref_table
->get (obj
);
201 jint val
= refcount
->intValue () - 1;
204 ref_table
->remove (obj
);
206 // FIXME: what about out of memory error?
207 ref_table
->put (obj
, new Integer (val
));
210 // "Unwrap" some random non-reference type. This exists to simplify
211 // other template functions.
219 // Unwrap a weak reference, if required.
224 using namespace gnu::gcj::runtime
;
225 // We can compare the class directly because JNIWeakRef is `final'.
226 // Doing it this way is much faster.
227 if (obj
== NULL
|| obj
->getClass () != &JNIWeakRef::class$
)
229 JNIWeakRef
*wr
= reinterpret_cast<JNIWeakRef
*> (obj
);
230 return reinterpret_cast<T
*> (wr
->get ());
234 _Jv_UnwrapJNIweakReference (jobject obj
)
241 static jobject JNICALL
242 _Jv_JNI_NewGlobalRef (JNIEnv
*, jobject obj
)
244 // This seems weird but I think it is correct.
246 mark_for_gc (obj
, global_ref_table
);
251 _Jv_JNI_DeleteGlobalRef (JNIEnv
*, jobject obj
)
253 // This seems weird but I think it is correct.
256 // NULL is ok here -- the JNI specification doesn't say so, but this
261 unmark_for_gc (obj
, global_ref_table
);
265 _Jv_JNI_DeleteLocalRef (JNIEnv
*env
, jobject obj
)
267 _Jv_JNI_LocalFrame
*frame
;
269 // This seems weird but I think it is correct.
272 // NULL is ok here -- the JNI specification doesn't say so, but this
277 for (frame
= env
->locals
; frame
!= NULL
; frame
= frame
->next
)
279 for (int i
= 0; i
< frame
->size
; ++i
)
281 if (frame
->vec
[i
] == obj
)
283 frame
->vec
[i
] = NULL
;
284 unmark_for_gc (obj
, local_ref_table
);
289 // Don't go past a marked frame.
290 JvAssert (frame
->marker
== MARK_NONE
);
297 _Jv_JNI_EnsureLocalCapacity (JNIEnv
*env
, jint size
)
299 // It is easier to just always allocate a new frame of the requested
300 // size. This isn't the most efficient thing, but for now we don't
301 // care. Note that _Jv_JNI_PushLocalFrame relies on this right now.
303 _Jv_JNI_LocalFrame
*frame
;
306 frame
= (_Jv_JNI_LocalFrame
*) _Jv_Malloc (sizeof (_Jv_JNI_LocalFrame
)
307 + size
* sizeof (jobject
));
315 frame
->marker
= MARK_NONE
;
317 frame
->allocated_p
= false;
318 memset (&frame
->vec
[0], 0, size
* sizeof (jobject
));
319 frame
->loader
= env
->locals
->loader
;
320 frame
->next
= env
->locals
;
327 _Jv_JNI_PushLocalFrame (JNIEnv
*env
, jint size
)
329 jint r
= _Jv_JNI_EnsureLocalCapacity (env
, size
);
333 // The new frame is on top.
334 env
->locals
->marker
= MARK_USER
;
339 static jobject JNICALL
340 _Jv_JNI_NewLocalRef (JNIEnv
*env
, jobject obj
)
342 // This seems weird but I think it is correct.
345 // Try to find an open slot somewhere in the topmost frame.
346 _Jv_JNI_LocalFrame
*frame
= env
->locals
;
347 bool done
= false, set
= false;
348 for (; frame
!= NULL
&& ! done
; frame
= frame
->next
)
350 for (int i
= 0; i
< frame
->size
; ++i
)
352 if (frame
->vec
[i
] == NULL
)
357 frame
->allocated_p
= true;
362 // If we found a slot, or if the frame we just searched is the
363 // mark frame, then we are done.
364 if (done
|| frame
== NULL
|| frame
->marker
!= MARK_NONE
)
370 // No slots, so we allocate a new frame. According to the spec
371 // we could just die here. FIXME: return value.
372 _Jv_JNI_EnsureLocalCapacity (env
, 16);
373 // We know the first element of the new frame will be ok.
374 env
->locals
->vec
[0] = obj
;
375 env
->locals
->allocated_p
= true;
378 mark_for_gc (obj
, local_ref_table
);
382 static jobject JNICALL
383 _Jv_JNI_PopLocalFrame (JNIEnv
*env
, jobject result
, int stop
)
385 _Jv_JNI_LocalFrame
*rf
= env
->locals
;
388 while (rf
!= NULL
&& ! done
)
390 for (int i
= 0; i
< rf
->size
; ++i
)
391 if (rf
->vec
[i
] != NULL
)
392 unmark_for_gc (rf
->vec
[i
], local_ref_table
);
394 // If the frame we just freed is the marker frame, we are done.
395 done
= (rf
->marker
== stop
);
397 _Jv_JNI_LocalFrame
*n
= rf
->next
;
398 // When N==NULL, we've reached the reusable bottom_locals, and we must
399 // not free it. However, we must be sure to clear all its elements.
403 memset (&rf
->vec
[0], 0, rf
->size
* sizeof (jobject
));
404 rf
->allocated_p
= false;
413 // Update the local frame information.
416 return result
== NULL
? NULL
: _Jv_JNI_NewLocalRef (env
, result
);
419 static jobject JNICALL
420 _Jv_JNI_PopLocalFrame (JNIEnv
*env
, jobject result
)
422 return _Jv_JNI_PopLocalFrame (env
, result
, MARK_USER
);
425 // Make sure an array's type is compatible with the type of the
429 _Jv_JNI_check_types (JNIEnv
*env
, JArray
<T
> *array
, jclass K
)
431 jclass klass
= array
->getClass()->getComponentType();
432 if (__builtin_expect (klass
!= K
, false))
434 env
->ex
= new java::lang::IllegalAccessError ();
441 // Pop a `system' frame from the stack. This is `extern "C"' as it is
442 // used by the compiler.
444 _Jv_JNI_PopSystemFrame (JNIEnv
*env
)
446 // Only enter slow path when we're not at the bottom, or there have been
447 // allocations. Usually this is false and we can just null out the locals
450 if (__builtin_expect ((env
->locals
->next
451 || env
->locals
->allocated_p
), false))
452 _Jv_JNI_PopLocalFrame (env
, NULL
, MARK_SYSTEM
);
456 if (__builtin_expect (env
->ex
!= NULL
, false))
458 jthrowable t
= env
->ex
;
460 if (JVMTI_REQUESTED_EVENT (Exception
))
461 _Jv_ReportJVMTIExceptionThrow (t
);
466 template<typename T
> T
extract_from_jvalue(jvalue
const & t
);
467 template<> jboolean
extract_from_jvalue(jvalue
const & jv
) { return jv
.z
; }
468 template<> jbyte
extract_from_jvalue(jvalue
const & jv
) { return jv
.b
; }
469 template<> jchar
extract_from_jvalue(jvalue
const & jv
) { return jv
.c
; }
470 template<> jshort
extract_from_jvalue(jvalue
const & jv
) { return jv
.s
; }
471 template<> jint
extract_from_jvalue(jvalue
const & jv
) { return jv
.i
; }
472 template<> jlong
extract_from_jvalue(jvalue
const & jv
) { return jv
.j
; }
473 template<> jfloat
extract_from_jvalue(jvalue
const & jv
) { return jv
.f
; }
474 template<> jdouble
extract_from_jvalue(jvalue
const & jv
) { return jv
.d
; }
475 template<> jobject
extract_from_jvalue(jvalue
const & jv
) { return jv
.l
; }
478 // This function is used from other template functions. It wraps the
479 // return value appropriately; we specialize it so that object returns
480 // are turned into local references.
483 wrap_value (JNIEnv
*, T value
)
488 // This specialization is used for jobject, jclass, jstring, jarray,
490 template<typename R
, typename T
>
492 wrap_value (JNIEnv
*env
, T
*value
)
494 return (value
== NULL
496 : (T
*) _Jv_JNI_NewLocalRef (env
, (jobject
) value
));
502 _Jv_JNI_GetVersion (JNIEnv
*)
504 return JNI_VERSION_1_4
;
507 static jclass JNICALL
508 _Jv_JNI_DefineClass (JNIEnv
*env
, const char *name
, jobject loader
,
509 const jbyte
*buf
, jsize bufLen
)
513 loader
= unwrap (loader
);
515 jstring sname
= JvNewStringUTF (name
);
516 jbyteArray bytes
= JvNewByteArray (bufLen
);
518 jbyte
*elts
= elements (bytes
);
519 memcpy (elts
, buf
, bufLen
* sizeof (jbyte
));
521 java::lang::ClassLoader
*l
522 = reinterpret_cast<java::lang::ClassLoader
*> (loader
);
524 jclass result
= l
->defineClass (sname
, bytes
, 0, bufLen
);
525 return (jclass
) wrap_value (env
, result
);
534 static jclass JNICALL
535 _Jv_JNI_FindClass (JNIEnv
*env
, const char *name
)
537 // FIXME: assume that NAME isn't too long.
538 int len
= strlen (name
);
540 for (int i
= 0; i
<= len
; ++i
)
541 s
[i
] = (name
[i
] == '/') ? '.' : name
[i
];
546 // This might throw an out of memory exception.
547 jstring n
= JvNewStringUTF (s
);
549 java::lang::ClassLoader
*loader
= NULL
;
550 if (env
->locals
->loader
!= NULL
)
551 loader
= env
->locals
->loader
;
555 // FIXME: should use getBaseClassLoader, but we don't have that
557 loader
= java::lang::ClassLoader::getSystemClassLoader ();
560 r
= loader
->loadClass (n
);
568 return (jclass
) wrap_value (env
, r
);
571 static jclass JNICALL
572 _Jv_JNI_GetSuperclass (JNIEnv
*env
, jclass clazz
)
574 return (jclass
) wrap_value (env
, unwrap (clazz
)->getSuperclass ());
577 static jboolean JNICALL
578 _Jv_JNI_IsAssignableFrom (JNIEnv
*, jclass clazz1
, jclass clazz2
)
580 return unwrap (clazz2
)->isAssignableFrom (unwrap (clazz1
));
584 _Jv_JNI_Throw (JNIEnv
*env
, jthrowable obj
)
586 // We check in case the user did some funky cast.
588 JvAssert (obj
!= NULL
&& java::lang::Throwable::class$
.isInstance (obj
));
594 _Jv_JNI_ThrowNew (JNIEnv
*env
, jclass clazz
, const char *message
)
596 using namespace java::lang::reflect
;
598 clazz
= unwrap (clazz
);
599 JvAssert (java::lang::Throwable::class$
.isAssignableFrom (clazz
));
604 JArray
<jclass
> *argtypes
605 = (JArray
<jclass
> *) JvNewObjectArray (1, &java::lang::Class::class$
,
608 jclass
*elts
= elements (argtypes
);
609 elts
[0] = &java::lang::String::class$
;
611 Constructor
*cons
= clazz
->getConstructor (argtypes
);
613 jobjectArray values
= JvNewObjectArray (1, &java::lang::String::class$
,
615 jobject
*velts
= elements (values
);
616 velts
[0] = JvNewStringUTF (message
);
618 jobject obj
= cons
->newInstance (values
);
620 env
->ex
= reinterpret_cast<jthrowable
> (obj
);
631 static jthrowable JNICALL
632 _Jv_JNI_ExceptionOccurred (JNIEnv
*env
)
634 return (jthrowable
) wrap_value (env
, env
->ex
);
638 _Jv_JNI_ExceptionDescribe (JNIEnv
*env
)
641 env
->ex
->printStackTrace();
645 _Jv_JNI_ExceptionClear (JNIEnv
*env
)
650 static jboolean JNICALL
651 _Jv_JNI_ExceptionCheck (JNIEnv
*env
)
653 return env
->ex
!= NULL
;
657 _Jv_JNI_FatalError (JNIEnv
*, const char *message
)
664 static jboolean JNICALL
665 _Jv_JNI_IsSameObject (JNIEnv
*, jobject obj1
, jobject obj2
)
667 return unwrap (obj1
) == unwrap (obj2
);
670 static jobject JNICALL
671 _Jv_JNI_AllocObject (JNIEnv
*env
, jclass clazz
)
674 using namespace java::lang::reflect
;
678 clazz
= unwrap (clazz
);
679 JvAssert (clazz
&& ! clazz
->isArray ());
680 if (clazz
->isInterface() || Modifier::isAbstract(clazz
->getModifiers()))
681 env
->ex
= new java::lang::InstantiationException ();
683 obj
= _Jv_AllocObject (clazz
);
690 return wrap_value (env
, obj
);
693 static jclass JNICALL
694 _Jv_JNI_GetObjectClass (JNIEnv
*env
, jobject obj
)
698 return (jclass
) wrap_value (env
, obj
->getClass());
701 static jboolean JNICALL
702 _Jv_JNI_IsInstanceOf (JNIEnv
*, jobject obj
, jclass clazz
)
704 return unwrap (clazz
)->isInstance(unwrap (obj
));
710 // This section concerns method invocation.
713 template<jboolean is_static
>
714 static jmethodID JNICALL
715 _Jv_JNI_GetAnyMethodID (JNIEnv
*env
, jclass clazz
,
716 const char *name
, const char *sig
)
720 clazz
= unwrap (clazz
);
721 _Jv_InitClass (clazz
);
723 _Jv_Utf8Const
*name_u
= _Jv_makeUtf8Const ((char *) name
, -1);
725 // FIXME: assume that SIG isn't too long.
726 int len
= strlen (sig
);
728 for (int i
= 0; i
<= len
; ++i
)
729 s
[i
] = (sig
[i
] == '/') ? '.' : sig
[i
];
730 _Jv_Utf8Const
*sig_u
= _Jv_makeUtf8Const ((char *) s
, -1);
732 JvAssert (! clazz
->isPrimitive());
734 using namespace java::lang::reflect
;
736 while (clazz
!= NULL
)
738 jint count
= JvNumMethods (clazz
);
739 jmethodID meth
= JvGetFirstMethod (clazz
);
741 for (jint i
= 0; i
< count
; ++i
)
743 if (((is_static
&& Modifier::isStatic (meth
->accflags
))
744 || (! is_static
&& ! Modifier::isStatic (meth
->accflags
)))
745 && _Jv_equalUtf8Consts (meth
->name
, name_u
)
746 && _Jv_equalUtf8Consts (meth
->signature
, sig_u
))
749 meth
= meth
->getNextMethod();
752 clazz
= clazz
->getSuperclass ();
755 java::lang::StringBuffer
*name_sig
=
756 new java::lang::StringBuffer (JvNewStringUTF (name
));
757 name_sig
->append ((jchar
) ' ');
758 name_sig
->append (JvNewStringUTF (s
));
759 env
->ex
= new java::lang::NoSuchMethodError (name_sig
->toString ());
769 // This is a helper function which turns a va_list into an array of
770 // `jvalue's. It needs signature information in order to do its work.
771 // The array of values must already be allocated.
773 array_from_valist (jvalue
*values
, JArray
<jclass
> *arg_types
, va_list vargs
)
775 jclass
*arg_elts
= elements (arg_types
);
776 for (int i
= 0; i
< arg_types
->length
; ++i
)
778 // Here we assume that sizeof(int) >= sizeof(jint), because we
779 // use `int' when decoding the varargs. Likewise for
780 // float, and double. Also we assume that sizeof(jlong) >=
781 // sizeof(int), i.e. that jlong values are not further
783 JvAssert (sizeof (int) >= sizeof (jint
));
784 JvAssert (sizeof (jlong
) >= sizeof (int));
785 JvAssert (sizeof (double) >= sizeof (jfloat
));
786 JvAssert (sizeof (double) >= sizeof (jdouble
));
787 if (arg_elts
[i
] == JvPrimClass (byte
))
788 values
[i
].b
= (jbyte
) va_arg (vargs
, int);
789 else if (arg_elts
[i
] == JvPrimClass (short))
790 values
[i
].s
= (jshort
) va_arg (vargs
, int);
791 else if (arg_elts
[i
] == JvPrimClass (int))
792 values
[i
].i
= (jint
) va_arg (vargs
, int);
793 else if (arg_elts
[i
] == JvPrimClass (long))
794 values
[i
].j
= (jlong
) va_arg (vargs
, jlong
);
795 else if (arg_elts
[i
] == JvPrimClass (float))
796 values
[i
].f
= (jfloat
) va_arg (vargs
, double);
797 else if (arg_elts
[i
] == JvPrimClass (double))
798 values
[i
].d
= (jdouble
) va_arg (vargs
, double);
799 else if (arg_elts
[i
] == JvPrimClass (boolean
))
800 values
[i
].z
= (jboolean
) va_arg (vargs
, int);
801 else if (arg_elts
[i
] == JvPrimClass (char))
802 values
[i
].c
= (jchar
) va_arg (vargs
, int);
806 values
[i
].l
= unwrap (va_arg (vargs
, jobject
));
811 // This can call any sort of method: virtual, "nonvirtual", static, or
813 template<typename T
, invocation_type style
>
815 _Jv_JNI_CallAnyMethodV (JNIEnv
*env
, jobject obj
, jclass klass
,
816 jmethodID id
, va_list vargs
)
819 klass
= unwrap (klass
);
821 jclass decl_class
= klass
? klass
: obj
->getClass ();
822 JvAssert (decl_class
!= NULL
);
825 JArray
<jclass
> *arg_types
;
829 _Jv_GetTypesFromSignature (id
, decl_class
,
830 &arg_types
, &return_type
);
832 jvalue args
[arg_types
->length
];
833 array_from_valist (args
, arg_types
, vargs
);
835 // For constructors we need to pass the Class we are instantiating.
836 if (style
== constructor
)
840 _Jv_CallAnyMethodA (obj
, return_type
, id
,
841 style
== constructor
,
843 arg_types
, args
, &result
);
845 return wrap_value (env
, extract_from_jvalue
<T
>(result
));
852 return wrap_value (env
, (T
) 0);
855 template<typename T
, invocation_type style
>
857 _Jv_JNI_CallAnyMethod (JNIEnv
*env
, jobject obj
, jclass klass
,
858 jmethodID method
, ...)
863 va_start (args
, method
);
864 result
= _Jv_JNI_CallAnyMethodV
<T
, style
> (env
, obj
, klass
, method
, args
);
870 template<typename T
, invocation_type style
>
872 _Jv_JNI_CallAnyMethodA (JNIEnv
*env
, jobject obj
, jclass klass
,
873 jmethodID id
, jvalue
*args
)
876 klass
= unwrap (klass
);
878 jclass decl_class
= klass
? klass
: obj
->getClass ();
879 JvAssert (decl_class
!= NULL
);
882 JArray
<jclass
> *arg_types
;
885 _Jv_GetTypesFromSignature (id
, decl_class
,
886 &arg_types
, &return_type
);
888 // For constructors we need to pass the Class we are instantiating.
889 if (style
== constructor
)
892 // Unwrap arguments as required. Eww.
893 jclass
*type_elts
= elements (arg_types
);
894 jvalue arg_copy
[arg_types
->length
];
895 for (int i
= 0; i
< arg_types
->length
; ++i
)
897 if (type_elts
[i
]->isPrimitive ())
898 arg_copy
[i
] = args
[i
];
900 arg_copy
[i
].l
= unwrap (args
[i
].l
);
904 _Jv_CallAnyMethodA (obj
, return_type
, id
,
905 style
== constructor
,
907 arg_types
, arg_copy
, &result
);
909 return wrap_value (env
, extract_from_jvalue
<T
>(result
));
916 return wrap_value (env
, (T
) 0);
919 template<invocation_type style
>
921 _Jv_JNI_CallAnyVoidMethodV (JNIEnv
*env
, jobject obj
, jclass klass
,
922 jmethodID id
, va_list vargs
)
925 klass
= unwrap (klass
);
927 jclass decl_class
= klass
? klass
: obj
->getClass ();
928 JvAssert (decl_class
!= NULL
);
931 JArray
<jclass
> *arg_types
;
934 _Jv_GetTypesFromSignature (id
, decl_class
,
935 &arg_types
, &return_type
);
937 jvalue args
[arg_types
->length
];
938 array_from_valist (args
, arg_types
, vargs
);
940 // For constructors we need to pass the Class we are instantiating.
941 if (style
== constructor
)
944 _Jv_CallAnyMethodA (obj
, return_type
, id
,
945 style
== constructor
,
947 arg_types
, args
, NULL
);
955 template<invocation_type style
>
957 _Jv_JNI_CallAnyVoidMethod (JNIEnv
*env
, jobject obj
, jclass klass
,
958 jmethodID method
, ...)
962 va_start (args
, method
);
963 _Jv_JNI_CallAnyVoidMethodV
<style
> (env
, obj
, klass
, method
, args
);
967 template<invocation_type style
>
969 _Jv_JNI_CallAnyVoidMethodA (JNIEnv
*env
, jobject obj
, jclass klass
,
970 jmethodID id
, jvalue
*args
)
972 jclass decl_class
= klass
? klass
: obj
->getClass ();
973 JvAssert (decl_class
!= NULL
);
976 JArray
<jclass
> *arg_types
;
979 _Jv_GetTypesFromSignature (id
, decl_class
,
980 &arg_types
, &return_type
);
982 // Unwrap arguments as required. Eww.
983 jclass
*type_elts
= elements (arg_types
);
984 jvalue arg_copy
[arg_types
->length
];
985 for (int i
= 0; i
< arg_types
->length
; ++i
)
987 if (type_elts
[i
]->isPrimitive ())
988 arg_copy
[i
] = args
[i
];
990 arg_copy
[i
].l
= unwrap (args
[i
].l
);
993 _Jv_CallAnyMethodA (obj
, return_type
, id
,
994 style
== constructor
,
996 arg_types
, args
, NULL
);
1004 // Functions with this signature are used to implement functions in
1005 // the CallMethod family.
1006 template<typename T
>
1008 _Jv_JNI_CallMethodV (JNIEnv
*env
, jobject obj
,
1009 jmethodID id
, va_list args
)
1011 return _Jv_JNI_CallAnyMethodV
<T
, normal
> (env
, obj
, NULL
, id
, args
);
1014 // Functions with this signature are used to implement functions in
1015 // the CallMethod family.
1016 template<typename T
>
1018 _Jv_JNI_CallMethod (JNIEnv
*env
, jobject obj
, jmethodID id
, ...)
1023 va_start (args
, id
);
1024 result
= _Jv_JNI_CallAnyMethodV
<T
, normal
> (env
, obj
, NULL
, id
, args
);
1030 // Functions with this signature are used to implement functions in
1031 // the CallMethod family.
1032 template<typename T
>
1034 _Jv_JNI_CallMethodA (JNIEnv
*env
, jobject obj
,
1035 jmethodID id
, jvalue
*args
)
1037 return _Jv_JNI_CallAnyMethodA
<T
, normal
> (env
, obj
, NULL
, id
, args
);
1041 _Jv_JNI_CallVoidMethodV (JNIEnv
*env
, jobject obj
,
1042 jmethodID id
, va_list args
)
1044 _Jv_JNI_CallAnyVoidMethodV
<normal
> (env
, obj
, NULL
, id
, args
);
1048 _Jv_JNI_CallVoidMethod (JNIEnv
*env
, jobject obj
, jmethodID id
, ...)
1052 va_start (args
, id
);
1053 _Jv_JNI_CallAnyVoidMethodV
<normal
> (env
, obj
, NULL
, id
, args
);
1058 _Jv_JNI_CallVoidMethodA (JNIEnv
*env
, jobject obj
,
1059 jmethodID id
, jvalue
*args
)
1061 _Jv_JNI_CallAnyVoidMethodA
<normal
> (env
, obj
, NULL
, id
, args
);
1064 // Functions with this signature are used to implement functions in
1065 // the CallStaticMethod family.
1066 template<typename T
>
1068 _Jv_JNI_CallStaticMethodV (JNIEnv
*env
, jclass klass
,
1069 jmethodID id
, va_list args
)
1071 JvAssert (((id
->accflags
) & java::lang::reflect::Modifier::STATIC
));
1072 JvAssert (java::lang::Class::class$
.isInstance (unwrap (klass
)));
1074 return _Jv_JNI_CallAnyMethodV
<T
, static_type
> (env
, NULL
, klass
, id
, args
);
1077 // Functions with this signature are used to implement functions in
1078 // the CallStaticMethod family.
1079 template<typename T
>
1081 _Jv_JNI_CallStaticMethod (JNIEnv
*env
, jclass klass
,
1087 JvAssert (((id
->accflags
) & java::lang::reflect::Modifier::STATIC
));
1088 JvAssert (java::lang::Class::class$
.isInstance (unwrap (klass
)));
1090 va_start (args
, id
);
1091 result
= _Jv_JNI_CallAnyMethodV
<T
, static_type
> (env
, NULL
, klass
,
1098 // Functions with this signature are used to implement functions in
1099 // the CallStaticMethod family.
1100 template<typename T
>
1102 _Jv_JNI_CallStaticMethodA (JNIEnv
*env
, jclass klass
, jmethodID id
,
1105 JvAssert (((id
->accflags
) & java::lang::reflect::Modifier::STATIC
));
1106 JvAssert (java::lang::Class::class$
.isInstance (unwrap (klass
)));
1108 return _Jv_JNI_CallAnyMethodA
<T
, static_type
> (env
, NULL
, klass
, id
, args
);
1112 _Jv_JNI_CallStaticVoidMethodV (JNIEnv
*env
, jclass klass
,
1113 jmethodID id
, va_list args
)
1115 _Jv_JNI_CallAnyVoidMethodV
<static_type
> (env
, NULL
, klass
, id
, args
);
1119 _Jv_JNI_CallStaticVoidMethod (JNIEnv
*env
, jclass klass
,
1124 va_start (args
, id
);
1125 _Jv_JNI_CallAnyVoidMethodV
<static_type
> (env
, NULL
, klass
, id
, args
);
1130 _Jv_JNI_CallStaticVoidMethodA (JNIEnv
*env
, jclass klass
,
1131 jmethodID id
, jvalue
*args
)
1133 _Jv_JNI_CallAnyVoidMethodA
<static_type
> (env
, NULL
, klass
, id
, args
);
1136 static jobject JNICALL
1137 _Jv_JNI_NewObjectV (JNIEnv
*env
, jclass klass
,
1138 jmethodID id
, va_list args
)
1140 JvAssert (klass
&& ! klass
->isArray ());
1141 JvAssert (! strcmp (id
->name
->chars(), "<init>")
1142 && id
->signature
->len() > 2
1143 && id
->signature
->chars()[0] == '('
1144 && ! strcmp (&id
->signature
->chars()[id
->signature
->len() - 2],
1147 return _Jv_JNI_CallAnyMethodV
<jobject
, constructor
> (env
, NULL
, klass
,
1151 static jobject JNICALL
1152 _Jv_JNI_NewObject (JNIEnv
*env
, jclass klass
, jmethodID id
, ...)
1154 JvAssert (klass
&& ! klass
->isArray ());
1155 JvAssert (! strcmp (id
->name
->chars(), "<init>")
1156 && id
->signature
->len() > 2
1157 && id
->signature
->chars()[0] == '('
1158 && ! strcmp (&id
->signature
->chars()[id
->signature
->len() - 2],
1164 va_start (args
, id
);
1165 result
= _Jv_JNI_CallAnyMethodV
<jobject
, constructor
> (env
, NULL
, klass
,
1172 static jobject JNICALL
1173 _Jv_JNI_NewObjectA (JNIEnv
*env
, jclass klass
, jmethodID id
,
1176 JvAssert (klass
&& ! klass
->isArray ());
1177 JvAssert (! strcmp (id
->name
->chars(), "<init>")
1178 && id
->signature
->len() > 2
1179 && id
->signature
->chars()[0] == '('
1180 && ! strcmp (&id
->signature
->chars()[id
->signature
->len() - 2],
1183 return _Jv_JNI_CallAnyMethodA
<jobject
, constructor
> (env
, NULL
, klass
,
1189 template<typename T
>
1191 _Jv_JNI_GetField (JNIEnv
*env
, jobject obj
, jfieldID field
)
1195 T
*ptr
= (T
*) ((char *) obj
+ field
->getOffset ());
1196 return wrap_value (env
, *ptr
);
1199 template<typename T
>
1201 _Jv_JNI_SetField (JNIEnv
*, jobject obj
, jfieldID field
, T value
)
1204 value
= unwrap (value
);
1207 T
*ptr
= (T
*) ((char *) obj
+ field
->getOffset ());
1211 template<jboolean is_static
>
1212 static jfieldID JNICALL
1213 _Jv_JNI_GetAnyFieldID (JNIEnv
*env
, jclass clazz
,
1214 const char *name
, const char *sig
)
1218 clazz
= unwrap (clazz
);
1220 _Jv_InitClass (clazz
);
1222 _Jv_Utf8Const
*a_name
= _Jv_makeUtf8Const ((char *) name
, -1);
1224 // FIXME: assume that SIG isn't too long.
1225 int len
= strlen (sig
);
1227 for (int i
= 0; i
<= len
; ++i
)
1228 s
[i
] = (sig
[i
] == '/') ? '.' : sig
[i
];
1229 java::lang::ClassLoader
*loader
= clazz
->getClassLoaderInternal ();
1230 jclass field_class
= _Jv_FindClassFromSignature ((char *) s
, loader
);
1232 throw new java::lang::ClassNotFoundException(JvNewStringUTF(s
));
1234 while (clazz
!= NULL
)
1236 // We acquire the class lock so that fields aren't resolved
1237 // while we are running.
1238 JvSynchronize
sync (clazz
);
1240 jint count
= (is_static
1241 ? JvNumStaticFields (clazz
)
1242 : JvNumInstanceFields (clazz
));
1243 jfieldID field
= (is_static
1244 ? JvGetFirstStaticField (clazz
)
1245 : JvGetFirstInstanceField (clazz
));
1246 for (jint i
= 0; i
< count
; ++i
)
1248 _Jv_Utf8Const
*f_name
= field
->getNameUtf8Const(clazz
);
1250 // The field might be resolved or it might not be. It
1251 // is much simpler to always resolve it.
1252 _Jv_Linker::resolve_field (field
, loader
);
1253 if (_Jv_equalUtf8Consts (f_name
, a_name
)
1254 && field
->getClass() == field_class
)
1257 field
= field
->getNextField ();
1260 clazz
= clazz
->getSuperclass ();
1263 env
->ex
= new java::lang::NoSuchFieldError ();
1265 catch (jthrowable t
)
1272 template<typename T
>
1274 _Jv_JNI_GetStaticField (JNIEnv
*env
, jclass
, jfieldID field
)
1276 T
*ptr
= (T
*) field
->u
.addr
;
1277 return wrap_value (env
, *ptr
);
1280 template<typename T
>
1282 _Jv_JNI_SetStaticField (JNIEnv
*, jclass
, jfieldID field
, T value
)
1284 value
= unwrap (value
);
1285 T
*ptr
= (T
*) field
->u
.addr
;
1289 static jstring JNICALL
1290 _Jv_JNI_NewString (JNIEnv
*env
, const jchar
*unichars
, jsize len
)
1294 jstring r
= _Jv_NewString (unichars
, len
);
1295 return (jstring
) wrap_value (env
, r
);
1297 catch (jthrowable t
)
1304 static jsize JNICALL
1305 _Jv_JNI_GetStringLength (JNIEnv
*, jstring string
)
1307 return unwrap (string
)->length();
1310 static const jchar
* JNICALL
1311 _Jv_JNI_GetStringChars (JNIEnv
*, jstring string
, jboolean
*isCopy
)
1313 string
= unwrap (string
);
1314 jchar
*result
= _Jv_GetStringChars (string
);
1315 mark_for_gc (string
, global_ref_table
);
1318 return (const jchar
*) result
;
1322 _Jv_JNI_ReleaseStringChars (JNIEnv
*, jstring string
, const jchar
*)
1324 unmark_for_gc (unwrap (string
), global_ref_table
);
1327 static jstring JNICALL
1328 _Jv_JNI_NewStringUTF (JNIEnv
*env
, const char *bytes
)
1332 jstring result
= JvNewStringUTF (bytes
);
1333 return (jstring
) wrap_value (env
, result
);
1335 catch (jthrowable t
)
1342 static jsize JNICALL
1343 _Jv_JNI_GetStringUTFLength (JNIEnv
*, jstring string
)
1345 return JvGetStringUTFLength (unwrap (string
));
1348 static const char * JNICALL
1349 _Jv_JNI_GetStringUTFChars (JNIEnv
*env
, jstring string
,
1354 string
= unwrap (string
);
1357 jsize len
= JvGetStringUTFLength (string
);
1358 char *r
= (char *) _Jv_Malloc (len
+ 1);
1359 JvGetStringUTFRegion (string
, 0, string
->length(), r
);
1365 return (const char *) r
;
1367 catch (jthrowable t
)
1375 _Jv_JNI_ReleaseStringUTFChars (JNIEnv
*, jstring
, const char *utf
)
1377 _Jv_Free ((void *) utf
);
1381 _Jv_JNI_GetStringRegion (JNIEnv
*env
, jstring string
, jsize start
,
1382 jsize len
, jchar
*buf
)
1384 string
= unwrap (string
);
1385 jchar
*result
= _Jv_GetStringChars (string
);
1386 if (start
< 0 || start
> string
->length ()
1387 || len
< 0 || start
+ len
> string
->length ())
1391 env
->ex
= new java::lang::StringIndexOutOfBoundsException ();
1393 catch (jthrowable t
)
1399 memcpy (buf
, &result
[start
], len
* sizeof (jchar
));
1403 _Jv_JNI_GetStringUTFRegion (JNIEnv
*env
, jstring str
, jsize start
,
1404 jsize len
, char *buf
)
1408 if (start
< 0 || start
> str
->length ()
1409 || len
< 0 || start
+ len
> str
->length ())
1413 env
->ex
= new java::lang::StringIndexOutOfBoundsException ();
1415 catch (jthrowable t
)
1421 _Jv_GetStringUTFRegion (str
, start
, len
, buf
);
1424 static const jchar
* JNICALL
1425 _Jv_JNI_GetStringCritical (JNIEnv
*, jstring str
, jboolean
*isCopy
)
1427 jchar
*result
= _Jv_GetStringChars (unwrap (str
));
1434 _Jv_JNI_ReleaseStringCritical (JNIEnv
*, jstring
, const jchar
*)
1439 static jsize JNICALL
1440 _Jv_JNI_GetArrayLength (JNIEnv
*, jarray array
)
1442 return unwrap (array
)->length
;
1445 static jobjectArray JNICALL
1446 _Jv_JNI_NewObjectArray (JNIEnv
*env
, jsize length
,
1447 jclass elementClass
, jobject init
)
1451 elementClass
= unwrap (elementClass
);
1452 init
= unwrap (init
);
1454 _Jv_CheckCast (elementClass
, init
);
1455 jarray result
= JvNewObjectArray (length
, elementClass
, init
);
1456 return (jobjectArray
) wrap_value (env
, result
);
1458 catch (jthrowable t
)
1465 static jobject JNICALL
1466 _Jv_JNI_GetObjectArrayElement (JNIEnv
*env
, jobjectArray array
,
1469 if ((unsigned) index
>= (unsigned) array
->length
)
1470 _Jv_ThrowBadArrayIndex (index
);
1471 jobject
*elts
= elements (unwrap (array
));
1472 return wrap_value (env
, elts
[index
]);
1476 _Jv_JNI_SetObjectArrayElement (JNIEnv
*env
, jobjectArray array
,
1477 jsize index
, jobject value
)
1481 array
= unwrap (array
);
1482 value
= unwrap (value
);
1484 _Jv_CheckArrayStore (array
, value
);
1485 if ((unsigned) index
>= (unsigned) array
->length
)
1486 _Jv_ThrowBadArrayIndex (index
);
1487 jobject
*elts
= elements (array
);
1488 elts
[index
] = value
;
1490 catch (jthrowable t
)
1496 template<typename T
, jclass K
>
1497 static JArray
<T
> * JNICALL
1498 _Jv_JNI_NewPrimitiveArray (JNIEnv
*env
, jsize length
)
1502 return (JArray
<T
> *) wrap_value (env
, _Jv_NewPrimArray (K
, length
));
1504 catch (jthrowable t
)
1511 template<typename T
, jclass K
>
1513 _Jv_JNI_GetPrimitiveArrayElements (JNIEnv
*env
, JArray
<T
> *array
,
1516 array
= unwrap (array
);
1517 if (! _Jv_JNI_check_types (env
, array
, K
))
1519 T
*elts
= elements (array
);
1522 // We elect never to copy.
1525 mark_for_gc (array
, global_ref_table
);
1529 template<typename T
, jclass K
>
1531 _Jv_JNI_ReleasePrimitiveArrayElements (JNIEnv
*env
, JArray
<T
> *array
,
1532 T
*, jint
/* mode */)
1534 array
= unwrap (array
);
1535 _Jv_JNI_check_types (env
, array
, K
);
1536 // Note that we ignore MODE. We can do this because we never copy
1537 // the array elements. My reading of the JNI documentation is that
1538 // this is an option for the implementor.
1539 unmark_for_gc (array
, global_ref_table
);
1542 template<typename T
, jclass K
>
1544 _Jv_JNI_GetPrimitiveArrayRegion (JNIEnv
*env
, JArray
<T
> *array
,
1545 jsize start
, jsize len
,
1548 array
= unwrap (array
);
1549 if (! _Jv_JNI_check_types (env
, array
, K
))
1552 // The cast to unsigned lets us save a comparison.
1553 if (start
< 0 || len
< 0
1554 || (unsigned long) (start
+ len
) > (unsigned long) array
->length
)
1559 env
->ex
= new java::lang::ArrayIndexOutOfBoundsException ();
1561 catch (jthrowable t
)
1563 // Could have thown out of memory error.
1569 T
*elts
= elements (array
) + start
;
1570 memcpy (buf
, elts
, len
* sizeof (T
));
1574 template<typename T
, jclass K
>
1576 _Jv_JNI_SetPrimitiveArrayRegion (JNIEnv
*env
, JArray
<T
> *array
,
1577 jsize start
, jsize len
, T
*buf
)
1579 array
= unwrap (array
);
1580 if (! _Jv_JNI_check_types (env
, array
, K
))
1583 // The cast to unsigned lets us save a comparison.
1584 if (start
< 0 || len
< 0
1585 || (unsigned long) (start
+ len
) > (unsigned long) array
->length
)
1590 env
->ex
= new java::lang::ArrayIndexOutOfBoundsException ();
1592 catch (jthrowable t
)
1599 T
*elts
= elements (array
) + start
;
1600 memcpy (elts
, buf
, len
* sizeof (T
));
1604 static void * JNICALL
1605 _Jv_JNI_GetPrimitiveArrayCritical (JNIEnv
*, jarray array
,
1608 array
= unwrap (array
);
1609 // FIXME: does this work?
1610 jclass klass
= array
->getClass()->getComponentType();
1611 JvAssert (klass
->isPrimitive ());
1612 char *r
= _Jv_GetArrayElementFromElementType (array
, klass
);
1619 _Jv_JNI_ReleasePrimitiveArrayCritical (JNIEnv
*, jarray
, void *, jint
)
1625 _Jv_JNI_MonitorEnter (JNIEnv
*env
, jobject obj
)
1629 _Jv_MonitorEnter (unwrap (obj
));
1632 catch (jthrowable t
)
1640 _Jv_JNI_MonitorExit (JNIEnv
*env
, jobject obj
)
1644 _Jv_MonitorExit (unwrap (obj
));
1647 catch (jthrowable t
)
1656 _Jv_JNI_ToReflectedField (JNIEnv
*env
, jclass cls
, jfieldID fieldID
,
1662 java::lang::reflect::Field
*field
= new java::lang::reflect::Field();
1663 field
->declaringClass
= cls
;
1664 field
->offset
= (char*) fieldID
- (char *) cls
->fields
;
1665 field
->name
= _Jv_NewStringUtf8Const (fieldID
->getNameUtf8Const (cls
));
1666 return wrap_value (env
, field
);
1668 catch (jthrowable t
)
1676 static jfieldID JNICALL
1677 _Jv_JNI_FromReflectedField (JNIEnv
*, jobject f
)
1679 using namespace java::lang::reflect
;
1682 Field
*field
= reinterpret_cast<Field
*> (f
);
1683 return _Jv_FromReflectedField (field
);
1687 _Jv_JNI_ToReflectedMethod (JNIEnv
*env
, jclass klass
, jmethodID id
,
1690 using namespace java::lang::reflect
;
1692 jobject result
= NULL
;
1693 klass
= unwrap (klass
);
1697 if (_Jv_equalUtf8Consts (id
->name
, init_name
))
1700 Constructor
*cons
= new Constructor ();
1701 cons
->offset
= (char *) id
- (char *) &klass
->methods
;
1702 cons
->declaringClass
= klass
;
1707 Method
*meth
= new Method ();
1708 meth
->offset
= (char *) id
- (char *) &klass
->methods
;
1709 meth
->declaringClass
= klass
;
1713 catch (jthrowable t
)
1718 return wrap_value (env
, result
);
1721 static jmethodID JNICALL
1722 _Jv_JNI_FromReflectedMethod (JNIEnv
*, jobject method
)
1724 using namespace java::lang::reflect
;
1725 method
= unwrap (method
);
1726 if (Method::class$
.isInstance (method
))
1727 return _Jv_FromReflectedMethod (reinterpret_cast<Method
*> (method
));
1729 _Jv_FromReflectedConstructor (reinterpret_cast<Constructor
*> (method
));
1734 _Jv_JNI_NewWeakGlobalRef (JNIEnv
*env
, jobject obj
)
1736 using namespace gnu::gcj::runtime
;
1737 JNIWeakRef
*ref
= NULL
;
1741 // This seems weird but I think it is correct.
1743 ref
= new JNIWeakRef (obj
);
1744 mark_for_gc (ref
, global_ref_table
);
1746 catch (jthrowable t
)
1751 return reinterpret_cast<jweak
> (ref
);
1755 _Jv_JNI_DeleteWeakGlobalRef (JNIEnv
*, jweak obj
)
1757 // JDK compatibility.
1761 using namespace gnu::gcj::runtime
;
1762 JNIWeakRef
*ref
= reinterpret_cast<JNIWeakRef
*> (obj
);
1763 unmark_for_gc (ref
, global_ref_table
);
1769 // Direct byte buffers.
1771 static jobject JNICALL
1772 _Jv_JNI_NewDirectByteBuffer (JNIEnv
*, void *address
, jlong length
)
1774 using namespace gnu::gcj
;
1775 using namespace java::nio
;
1776 return new DirectByteBufferImpl$ReadWrite
1777 (reinterpret_cast<RawData
*> (address
), length
);
1780 static void * JNICALL
1781 _Jv_JNI_GetDirectBufferAddress (JNIEnv
*, jobject buffer
)
1783 using namespace java::nio
;
1784 if (! _Jv_IsInstanceOf (buffer
, &Buffer::class$
))
1786 Buffer
*tmp
= static_cast<Buffer
*> (buffer
);
1787 return reinterpret_cast<void *> (tmp
->address
);
1790 static jlong JNICALL
1791 _Jv_JNI_GetDirectBufferCapacity (JNIEnv
*, jobject buffer
)
1793 using namespace java::nio
;
1794 if (! _Jv_IsInstanceOf (buffer
, &Buffer::class$
))
1796 Buffer
*tmp
= static_cast<Buffer
*> (buffer
);
1797 if (tmp
->address
== NULL
)
1799 return tmp
->capacity();
1804 struct NativeMethodCacheEntry
: public JNINativeMethod
1809 // Hash table of native methods.
1810 static NativeMethodCacheEntry
*nathash
;
1811 // Number of slots used.
1812 static int nathash_count
= 0;
1813 // Number of slots available. Must be power of 2.
1814 static int nathash_size
= 0;
1816 #define DELETED_ENTRY ((char *) (~0))
1818 // Compute a hash value for a native method descriptor.
1820 hash (const NativeMethodCacheEntry
*method
)
1825 ptr
= method
->className
;
1827 hash
= (31 * hash
) + *ptr
++;
1831 hash
= (31 * hash
) + *ptr
++;
1833 ptr
= method
->signature
;
1835 hash
= (31 * hash
) + *ptr
++;
1840 // Find the slot where a native method goes.
1841 static NativeMethodCacheEntry
*
1842 nathash_find_slot (const NativeMethodCacheEntry
*method
)
1844 jint h
= hash (method
);
1845 int step
= (h
^ (h
>> 16)) | 1;
1846 int w
= h
& (nathash_size
- 1);
1851 NativeMethodCacheEntry
*slotp
= &nathash
[w
];
1852 if (slotp
->name
== NULL
)
1855 return &nathash
[del
];
1859 else if (slotp
->name
== DELETED_ENTRY
)
1861 else if (! strcmp (slotp
->name
, method
->name
)
1862 && ! strcmp (slotp
->signature
, method
->signature
)
1863 && ! strcmp (slotp
->className
, method
->className
))
1865 w
= (w
+ step
) & (nathash_size
- 1);
1869 // Find a method. Return NULL if it isn't in the hash table.
1871 nathash_find (NativeMethodCacheEntry
*method
)
1873 if (nathash
== NULL
)
1875 NativeMethodCacheEntry
*slot
= nathash_find_slot (method
);
1876 if (slot
->name
== NULL
|| slot
->name
== DELETED_ENTRY
)
1884 if (nathash
== NULL
)
1886 nathash_size
= 1024;
1888 (NativeMethodCacheEntry
*) _Jv_AllocBytes (nathash_size
1889 * sizeof (NativeMethodCacheEntry
));
1893 int savesize
= nathash_size
;
1894 NativeMethodCacheEntry
*savehash
= nathash
;
1897 (NativeMethodCacheEntry
*) _Jv_AllocBytes (nathash_size
1898 * sizeof (NativeMethodCacheEntry
));
1900 for (int i
= 0; i
< savesize
; ++i
)
1902 if (savehash
[i
].name
!= NULL
&& savehash
[i
].name
!= DELETED_ENTRY
)
1904 NativeMethodCacheEntry
*slot
= nathash_find_slot (&savehash
[i
]);
1905 *slot
= savehash
[i
];
1912 nathash_add (const NativeMethodCacheEntry
*method
)
1914 if (3 * nathash_count
>= 2 * nathash_size
)
1916 NativeMethodCacheEntry
*slot
= nathash_find_slot (method
);
1917 // If the slot has a real entry in it, then there is no work to do.
1918 if (slot
->name
!= NULL
&& slot
->name
!= DELETED_ENTRY
)
1920 // FIXME: memory leak?
1921 slot
->name
= strdup (method
->name
);
1922 slot
->className
= strdup (method
->className
);
1923 // This was already strduped in _Jv_JNI_RegisterNatives.
1924 slot
->signature
= method
->signature
;
1925 slot
->fnPtr
= method
->fnPtr
;
1929 _Jv_JNI_RegisterNatives (JNIEnv
*env
, jclass klass
,
1930 const JNINativeMethod
*methods
,
1933 // Synchronize while we do the work. This must match
1934 // synchronization in some other functions that manipulate or use
1935 // the nathash table.
1936 JvSynchronize
sync (global_ref_table
);
1938 NativeMethodCacheEntry dottedMethod
;
1940 // Look at each descriptor given us, and find the corresponding
1941 // method in the class.
1942 for (int j
= 0; j
< nMethods
; ++j
)
1946 _Jv_Method
*imeths
= JvGetFirstMethod (klass
);
1947 for (int i
= 0; i
< JvNumMethods (klass
); ++i
)
1949 _Jv_Method
*self
= &imeths
[i
];
1951 // Copy this JNINativeMethod and do a slash to dot
1952 // conversion on the signature.
1953 dottedMethod
.name
= methods
[j
].name
;
1954 // FIXME: we leak a little memory here if the method
1956 dottedMethod
.signature
= strdup (methods
[j
].signature
);
1957 dottedMethod
.fnPtr
= methods
[j
].fnPtr
;
1958 dottedMethod
.className
= _Jv_GetClassNameUtf8 (klass
)->chars();
1959 char *c
= dottedMethod
.signature
;
1967 if (! strcmp (self
->name
->chars (), dottedMethod
.name
)
1968 && ! strcmp (self
->signature
->chars (), dottedMethod
.signature
))
1970 if (! (self
->accflags
& java::lang::reflect::Modifier::NATIVE
))
1973 // Found a match that is native.
1975 nathash_add (&dottedMethod
);
1983 jstring m
= JvNewStringUTF (methods
[j
].name
);
1986 env
->ex
= new java::lang::NoSuchMethodError (m
);
1988 catch (jthrowable t
)
2000 _Jv_JNI_UnregisterNatives (JNIEnv
*, jclass
)
2002 // FIXME -- we could implement this.
2008 // Add a character to the buffer, encoding properly.
2010 add_char (char *buf
, jchar c
, int *here
)
2014 buf
[(*here
)++] = '_';
2015 buf
[(*here
)++] = '1';
2019 buf
[(*here
)++] = '_';
2020 buf
[(*here
)++] = '2';
2024 buf
[(*here
)++] = '_';
2025 buf
[(*here
)++] = '3';
2028 // Also check for `.' here because we might be passed an internal
2029 // qualified class name like `foo.bar'.
2030 else if (c
== '/' || c
== '.')
2031 buf
[(*here
)++] = '_';
2032 else if ((c
>= '0' && c
<= '9')
2033 || (c
>= 'a' && c
<= 'z')
2034 || (c
>= 'A' && c
<= 'Z'))
2035 buf
[(*here
)++] = (char) c
;
2038 // "Unicode" character.
2039 buf
[(*here
)++] = '_';
2040 buf
[(*here
)++] = '0';
2041 for (int i
= 0; i
< 4; ++i
)
2044 buf
[(*here
) + 3 - i
] = (val
> 10) ? ('a' + val
- 10) : ('0' + val
);
2051 // Compute a mangled name for a native function. This computes the
2052 // long name, and also returns an index which indicates where a NUL
2053 // can be placed to create the short name. This function assumes that
2054 // the buffer is large enough for its results.
2056 mangled_name (jclass klass
, _Jv_Utf8Const
*func_name
,
2057 _Jv_Utf8Const
*signature
, char *buf
, int *long_start
)
2059 strcpy (buf
, "Java_");
2062 // Add fully qualified class name.
2063 jchar
*chars
= _Jv_GetStringChars (klass
->getName ());
2064 jint len
= klass
->getName ()->length ();
2065 for (int i
= 0; i
< len
; ++i
)
2066 add_char (buf
, chars
[i
], &here
);
2068 // Don't use add_char because we need a literal `_'.
2071 const unsigned char *fn
= (const unsigned char *) func_name
->chars ();
2072 const unsigned char *limit
= fn
+ func_name
->len ();
2073 for (int i
= 0; ; ++i
)
2075 int ch
= UTF8_GET (fn
, limit
);
2078 add_char (buf
, ch
, &here
);
2081 // This is where the long signature begins.
2086 const unsigned char *sig
= (const unsigned char *) signature
->chars ();
2087 limit
= sig
+ signature
->len ();
2088 JvAssert (sig
[0] == '(');
2092 int ch
= UTF8_GET (sig
, limit
);
2093 if (ch
== ')' || ch
< 0)
2095 add_char (buf
, ch
, &here
);
2102 _Jv_GetJNIEnvNewFrameWithLoader (::java::lang::ClassLoader
*loader
)
2104 JNIEnv
*env
= _Jv_GetCurrentJNIEnv ();
2105 if (__builtin_expect (env
== NULL
, false))
2107 env
= (JNIEnv
*) _Jv_MallocUnchecked (sizeof (JNIEnv
));
2108 env
->p
= &_Jv_JNIFunctions
;
2110 // We set env->ex below.
2112 // Set up the bottom, reusable frame.
2113 env
->bottom_locals
= (_Jv_JNI_LocalFrame
*)
2114 _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame
)
2116 * sizeof (jobject
)));
2118 env
->bottom_locals
->marker
= MARK_SYSTEM
;
2119 env
->bottom_locals
->size
= FRAME_SIZE
;
2120 env
->bottom_locals
->next
= NULL
;
2121 env
->bottom_locals
->allocated_p
= false;
2122 // We set the klass field below.
2123 memset (&env
->bottom_locals
->vec
[0], 0,
2124 env
->bottom_locals
->size
* sizeof (jobject
));
2126 _Jv_SetCurrentJNIEnv (env
);
2129 // If we're in a simple JNI call (non-nested), we can just reuse the
2130 // locals frame we allocated many calls ago, back when the env was first
2133 if (__builtin_expect (env
->locals
== NULL
, true))
2135 env
->locals
= env
->bottom_locals
;
2136 env
->locals
->loader
= loader
;
2140 // Alternatively, we might be re-entering JNI, in which case we can't
2141 // reuse the bottom_locals frame, because it is already underneath
2142 // us. So we need to make a new one.
2143 _Jv_JNI_LocalFrame
*frame
2144 = (_Jv_JNI_LocalFrame
*) _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame
)
2146 * sizeof (jobject
)));
2148 frame
->marker
= MARK_SYSTEM
;
2149 frame
->size
= FRAME_SIZE
;
2150 frame
->allocated_p
= false;
2151 frame
->next
= env
->locals
;
2152 frame
->loader
= loader
;
2154 memset (&frame
->vec
[0], 0,
2155 frame
->size
* sizeof (jobject
));
2157 env
->locals
= frame
;
2165 // Return the current thread's JNIEnv; if one does not exist, create
2166 // it. Also create a new system frame for use. This is `extern "C"'
2167 // because the compiler calls it.
2169 _Jv_GetJNIEnvNewFrame (jclass klass
)
2171 return _Jv_GetJNIEnvNewFrameWithLoader (klass
->getClassLoaderInternal());
2174 // Destroy the env's reusable resources. This is called from the thread
2175 // destructor "finalize_native" in natThread.cc
2177 _Jv_FreeJNIEnv (_Jv_JNIEnv
*env
)
2182 if (env
->bottom_locals
!= NULL
)
2183 _Jv_Free (env
->bottom_locals
);
2188 // Return the function which implements a particular JNI method. If
2189 // we can't find the function, we throw the appropriate exception.
2190 // This is `extern "C"' because the compiler uses it.
2192 _Jv_LookupJNIMethod (jclass klass
, _Jv_Utf8Const
*name
,
2193 _Jv_Utf8Const
*signature
, MAYBE_UNUSED
int args_size
)
2195 int name_length
= name
->len();
2196 int sig_length
= signature
->len();
2197 char buf
[10 + 6 * (name_length
+ sig_length
) + 12];
2201 // Synchronize on something convenient. Right now we use the hash.
2202 JvSynchronize
sync (global_ref_table
);
2204 // First see if we have an override in the hash table.
2205 strncpy (buf
, name
->chars (), name_length
);
2206 buf
[name_length
] = '\0';
2207 strncpy (buf
+ name_length
+ 1, signature
->chars (), sig_length
);
2208 buf
[name_length
+ sig_length
+ 1] = '\0';
2209 NativeMethodCacheEntry meth
;
2211 meth
.signature
= buf
+ name_length
+ 1;
2212 meth
.className
= _Jv_GetClassNameUtf8(klass
)->chars();
2213 function
= nathash_find (&meth
);
2214 if (function
!= NULL
)
2217 // If there was no override, then look in the symbol table.
2219 mangled_name (klass
, name
, signature
, buf
+ 1, &long_start
);
2220 char c
= buf
[long_start
+ 1];
2221 buf
[long_start
+ 1] = '\0';
2223 function
= _Jv_FindSymbolInExecutable (buf
+ 1);
2225 // On Win32, we use the "stdcall" calling convention (see JNICALL
2228 // For a function named 'fooBar' that takes 'nn' bytes as arguments,
2229 // by default, MinGW GCC exports it as 'fooBar@nn', MSVC exports it
2230 // as '_fooBar@nn' and Borland C exports it as 'fooBar'. We try to
2231 // take care of all these variations here.
2233 char asz_buf
[12]; /* '@' + '2147483647' (32-bit INT_MAX) + '\0' */
2234 char long_nm_sv
[11]; /* Ditto, except for the '\0'. */
2236 if (function
== NULL
)
2238 // We have tried searching for the 'fooBar' form (BCC) - now
2241 // First, save the part of the long name that will be damaged
2242 // by appending '@nn'.
2243 memcpy (long_nm_sv
, (buf
+ long_start
+ 1 + 1), sizeof (long_nm_sv
));
2245 sprintf (asz_buf
, "@%d", args_size
);
2246 strcat (buf
, asz_buf
);
2248 // Search for the '_fooBar@nn' form (MSVC).
2249 function
= _Jv_FindSymbolInExecutable (buf
);
2251 if (function
== NULL
)
2253 // Search for the 'fooBar@nn' form (MinGW GCC).
2254 function
= _Jv_FindSymbolInExecutable (buf
+ 1);
2259 if (function
== NULL
)
2261 buf
[long_start
+ 1] = c
;
2263 // Restore the part of the long name that was damaged by
2264 // appending the '@nn'.
2265 memcpy ((buf
+ long_start
+ 1 + 1), long_nm_sv
, sizeof (long_nm_sv
));
2267 function
= _Jv_FindSymbolInExecutable (buf
+ 1);
2268 if (function
== NULL
)
2271 strcat (buf
, asz_buf
);
2272 function
= _Jv_FindSymbolInExecutable (buf
);
2273 if (function
== NULL
)
2274 function
= _Jv_FindSymbolInExecutable (buf
+ 1);
2276 if (function
== NULL
)
2279 jstring str
= JvNewStringUTF (name
->chars ());
2280 throw new java::lang::UnsatisfiedLinkError (str
);
2290 // This function is the stub which is used to turn an ordinary (CNI)
2291 // method call into a JNI call.
2293 _Jv_JNIMethod::call (ffi_cif
*, void *ret
, ffi_raw
*args
, void *__this
)
2295 _Jv_JNIMethod
* _this
= (_Jv_JNIMethod
*) __this
;
2297 JNIEnv
*env
= _Jv_GetJNIEnvNewFrame (_this
->defining_class
);
2299 // FIXME: we should mark every reference parameter as a local. For
2300 // now we assume a conservative GC, and we assume that the
2301 // references are on the stack somewhere.
2303 // We cache the value that we find, of course, but if we don't find
2304 // a value we don't cache that fact -- we might subsequently load a
2305 // library which finds the function in question.
2307 // Synchronize on a convenient object to ensure sanity in case two
2308 // threads reach this point for the same function at the same
2310 JvSynchronize
sync (global_ref_table
);
2311 if (_this
->function
== NULL
)
2313 int args_size
= sizeof (JNIEnv
*) + _this
->args_raw_size
;
2315 if (_this
->self
->accflags
& java::lang::reflect::Modifier::STATIC
)
2316 args_size
+= sizeof (_this
->defining_class
);
2318 _this
->function
= _Jv_LookupJNIMethod (_this
->defining_class
,
2320 _this
->self
->signature
,
2325 JvAssert (_this
->args_raw_size
% sizeof (ffi_raw
) == 0);
2326 ffi_raw real_args
[2 + _this
->args_raw_size
/ sizeof (ffi_raw
)];
2329 // First argument is always the environment pointer.
2330 real_args
[offset
++].ptr
= env
;
2332 // For a static method, we pass in the Class. For non-static
2333 // methods, the `this' argument is already handled.
2334 if ((_this
->self
->accflags
& java::lang::reflect::Modifier::STATIC
))
2335 real_args
[offset
++].ptr
= _this
->defining_class
;
2337 // In libgcj, the callee synchronizes.
2338 jobject sync
= NULL
;
2339 if ((_this
->self
->accflags
& java::lang::reflect::Modifier::SYNCHRONIZED
))
2341 if ((_this
->self
->accflags
& java::lang::reflect::Modifier::STATIC
))
2342 sync
= _this
->defining_class
;
2344 sync
= (jobject
) args
[0].ptr
;
2345 _Jv_MonitorEnter (sync
);
2348 // Copy over passed-in arguments.
2349 memcpy (&real_args
[offset
], args
, _this
->args_raw_size
);
2351 // Add a frame to the composite (interpreted + JNI) call stack
2352 java::lang::Thread
*thread
= java::lang::Thread::currentThread();
2353 _Jv_NativeFrame
nat_frame (_this
, thread
);
2355 // The actual call to the JNI function.
2356 #if FFI_NATIVE_RAW_API
2357 ffi_raw_call (&_this
->jni_cif
, (void (*)()) _this
->function
,
2360 ffi_java_raw_call (&_this
->jni_cif
, (void (*)()) _this
->function
,
2364 // We might need to unwrap a JNI weak reference here.
2365 if (_this
->jni_cif
.rtype
== &ffi_type_pointer
)
2367 _Jv_value
*val
= (_Jv_value
*) ret
;
2368 val
->object_value
= unwrap (val
->object_value
);
2372 _Jv_MonitorExit (sync
);
2374 _Jv_JNI_PopSystemFrame (env
);
2377 #endif /* INTERPRETER */
2385 // An internal helper function.
2387 _Jv_JNI_AttachCurrentThread (JavaVM
*, jstring name
, void **penv
,
2388 void *args
, jboolean is_daemon
)
2390 JavaVMAttachArgs
*attach
= reinterpret_cast<JavaVMAttachArgs
*> (args
);
2391 java::lang::ThreadGroup
*group
= NULL
;
2395 // FIXME: do we really want to support 1.1?
2396 if (attach
->version
!= JNI_VERSION_1_4
2397 && attach
->version
!= JNI_VERSION_1_2
2398 && attach
->version
!= JNI_VERSION_1_1
)
2399 return JNI_EVERSION
;
2401 JvAssert (java::lang::ThreadGroup::class$
.isInstance (attach
->group
));
2402 group
= reinterpret_cast<java::lang::ThreadGroup
*> (attach
->group
);
2405 // Attaching an already-attached thread is a no-op.
2406 JNIEnv
*env
= _Jv_GetCurrentJNIEnv ();
2409 *penv
= reinterpret_cast<void *> (env
);
2413 env
= (JNIEnv
*) _Jv_MallocUnchecked (sizeof (JNIEnv
));
2416 env
->p
= &_Jv_JNIFunctions
;
2419 = (_Jv_JNI_LocalFrame
*) _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame
)
2421 * sizeof (jobject
)));
2422 env
->locals
= env
->bottom_locals
;
2423 if (env
->locals
== NULL
)
2429 env
->locals
->allocated_p
= false;
2430 env
->locals
->marker
= MARK_SYSTEM
;
2431 env
->locals
->size
= FRAME_SIZE
;
2432 env
->locals
->loader
= NULL
;
2433 env
->locals
->next
= NULL
;
2435 for (int i
= 0; i
< env
->locals
->size
; ++i
)
2436 env
->locals
->vec
[i
] = NULL
;
2438 *penv
= reinterpret_cast<void *> (env
);
2440 // This thread might already be a Java thread -- this function might
2441 // have been called simply to set the new JNIEnv.
2442 if (_Jv_ThreadCurrent () == NULL
)
2447 _Jv_AttachCurrentThreadAsDaemon (name
, group
);
2449 _Jv_AttachCurrentThread (name
, group
);
2451 catch (jthrowable t
)
2456 _Jv_SetCurrentJNIEnv (env
);
2461 // This is the one actually used by JNI.
2463 _Jv_JNI_AttachCurrentThread (JavaVM
*vm
, void **penv
, void *args
)
2465 return _Jv_JNI_AttachCurrentThread (vm
, NULL
, penv
, args
, false);
2469 _Jv_JNI_AttachCurrentThreadAsDaemon (JavaVM
*vm
, void **penv
,
2472 return _Jv_JNI_AttachCurrentThread (vm
, NULL
, penv
, args
, true);
2476 _Jv_JNI_DestroyJavaVM (JavaVM
*vm
)
2478 JvAssert (_Jv_the_vm
&& vm
== _Jv_the_vm
);
2486 if (_Jv_ThreadCurrent () != NULL
)
2492 main_name
= JvNewStringLatin1 ("main");
2494 catch (jthrowable t
)
2499 jint r
= _Jv_JNI_AttachCurrentThread (vm
, main_name
, &env_p
,
2505 env
= _Jv_GetCurrentJNIEnv ();
2509 // Docs say that this always returns an error code.
2514 _Jv_JNI_DetachCurrentThread (JavaVM
*)
2516 jint code
= _Jv_DetachCurrentThread ();
2517 return code
? JNI_EDETACHED
: 0;
2521 _Jv_JNI_GetEnv (JavaVM
*, void **penv
, jint version
)
2523 if (_Jv_ThreadCurrent () == NULL
)
2526 return JNI_EDETACHED
;
2530 // Handle JVMPI requests.
2531 if (version
== JVMPI_VERSION_1
)
2533 *penv
= (void *) &_Jv_JVMPI_Interface
;
2538 // Handle JVMTI requests
2539 if (version
== JVMTI_VERSION_1_0
)
2541 *penv
= (void *) _Jv_GetJVMTIEnv ();
2545 // FIXME: do we really want to support 1.1?
2546 if (version
!= JNI_VERSION_1_4
&& version
!= JNI_VERSION_1_2
2547 && version
!= JNI_VERSION_1_1
)
2550 return JNI_EVERSION
;
2553 *penv
= (void *) _Jv_GetCurrentJNIEnv ();
2560 // FIXME: synchronize
2563 JavaVM
*nvm
= (JavaVM
*) _Jv_MallocUnchecked (sizeof (JavaVM
));
2565 nvm
->functions
= &_Jv_JNI_InvokeFunctions
;
2569 // If this is a Java thread, we want to make sure it has an
2570 // associated JNIEnv.
2571 if (_Jv_ThreadCurrent () != NULL
)
2574 _Jv_JNI_AttachCurrentThread (_Jv_the_vm
, &ignore
, NULL
);
2581 _Jv_JNI_GetJavaVM (JNIEnv
*, JavaVM
**vm
)
2583 *vm
= _Jv_GetJavaVM ();
2584 return *vm
== NULL
? JNI_ERR
: JNI_OK
;
2589 #define RESERVED NULL
2591 struct JNINativeInterface _Jv_JNIFunctions
=
2597 _Jv_JNI_GetVersion
, // GetVersion
2598 _Jv_JNI_DefineClass
, // DefineClass
2599 _Jv_JNI_FindClass
, // FindClass
2600 _Jv_JNI_FromReflectedMethod
, // FromReflectedMethod
2601 _Jv_JNI_FromReflectedField
, // FromReflectedField
2602 _Jv_JNI_ToReflectedMethod
, // ToReflectedMethod
2603 _Jv_JNI_GetSuperclass
, // GetSuperclass
2604 _Jv_JNI_IsAssignableFrom
, // IsAssignableFrom
2605 _Jv_JNI_ToReflectedField
, // ToReflectedField
2606 _Jv_JNI_Throw
, // Throw
2607 _Jv_JNI_ThrowNew
, // ThrowNew
2608 _Jv_JNI_ExceptionOccurred
, // ExceptionOccurred
2609 _Jv_JNI_ExceptionDescribe
, // ExceptionDescribe
2610 _Jv_JNI_ExceptionClear
, // ExceptionClear
2611 _Jv_JNI_FatalError
, // FatalError
2613 _Jv_JNI_PushLocalFrame
, // PushLocalFrame
2614 _Jv_JNI_PopLocalFrame
, // PopLocalFrame
2615 _Jv_JNI_NewGlobalRef
, // NewGlobalRef
2616 _Jv_JNI_DeleteGlobalRef
, // DeleteGlobalRef
2617 _Jv_JNI_DeleteLocalRef
, // DeleteLocalRef
2619 _Jv_JNI_IsSameObject
, // IsSameObject
2621 _Jv_JNI_NewLocalRef
, // NewLocalRef
2622 _Jv_JNI_EnsureLocalCapacity
, // EnsureLocalCapacity
2624 _Jv_JNI_AllocObject
, // AllocObject
2625 _Jv_JNI_NewObject
, // NewObject
2626 _Jv_JNI_NewObjectV
, // NewObjectV
2627 _Jv_JNI_NewObjectA
, // NewObjectA
2628 _Jv_JNI_GetObjectClass
, // GetObjectClass
2629 _Jv_JNI_IsInstanceOf
, // IsInstanceOf
2630 _Jv_JNI_GetAnyMethodID
<false>, // GetMethodID
2632 _Jv_JNI_CallMethod
<jobject
>, // CallObjectMethod
2633 _Jv_JNI_CallMethodV
<jobject
>, // CallObjectMethodV
2634 _Jv_JNI_CallMethodA
<jobject
>, // CallObjectMethodA
2635 _Jv_JNI_CallMethod
<jboolean
>, // CallBooleanMethod
2636 _Jv_JNI_CallMethodV
<jboolean
>, // CallBooleanMethodV
2637 _Jv_JNI_CallMethodA
<jboolean
>, // CallBooleanMethodA
2638 _Jv_JNI_CallMethod
<jbyte
>, // CallByteMethod
2639 _Jv_JNI_CallMethodV
<jbyte
>, // CallByteMethodV
2640 _Jv_JNI_CallMethodA
<jbyte
>, // CallByteMethodA
2641 _Jv_JNI_CallMethod
<jchar
>, // CallCharMethod
2642 _Jv_JNI_CallMethodV
<jchar
>, // CallCharMethodV
2643 _Jv_JNI_CallMethodA
<jchar
>, // CallCharMethodA
2644 _Jv_JNI_CallMethod
<jshort
>, // CallShortMethod
2645 _Jv_JNI_CallMethodV
<jshort
>, // CallShortMethodV
2646 _Jv_JNI_CallMethodA
<jshort
>, // CallShortMethodA
2647 _Jv_JNI_CallMethod
<jint
>, // CallIntMethod
2648 _Jv_JNI_CallMethodV
<jint
>, // CallIntMethodV
2649 _Jv_JNI_CallMethodA
<jint
>, // CallIntMethodA
2650 _Jv_JNI_CallMethod
<jlong
>, // CallLongMethod
2651 _Jv_JNI_CallMethodV
<jlong
>, // CallLongMethodV
2652 _Jv_JNI_CallMethodA
<jlong
>, // CallLongMethodA
2653 _Jv_JNI_CallMethod
<jfloat
>, // CallFloatMethod
2654 _Jv_JNI_CallMethodV
<jfloat
>, // CallFloatMethodV
2655 _Jv_JNI_CallMethodA
<jfloat
>, // CallFloatMethodA
2656 _Jv_JNI_CallMethod
<jdouble
>, // CallDoubleMethod
2657 _Jv_JNI_CallMethodV
<jdouble
>, // CallDoubleMethodV
2658 _Jv_JNI_CallMethodA
<jdouble
>, // CallDoubleMethodA
2659 _Jv_JNI_CallVoidMethod
, // CallVoidMethod
2660 _Jv_JNI_CallVoidMethodV
, // CallVoidMethodV
2661 _Jv_JNI_CallVoidMethodA
, // CallVoidMethodA
2663 // Nonvirtual method invocation functions follow.
2664 _Jv_JNI_CallAnyMethod
<jobject
, nonvirtual
>, // CallNonvirtualObjectMethod
2665 _Jv_JNI_CallAnyMethodV
<jobject
, nonvirtual
>, // CallNonvirtualObjectMethodV
2666 _Jv_JNI_CallAnyMethodA
<jobject
, nonvirtual
>, // CallNonvirtualObjectMethodA
2667 _Jv_JNI_CallAnyMethod
<jboolean
, nonvirtual
>, // CallNonvirtualBooleanMethod
2668 _Jv_JNI_CallAnyMethodV
<jboolean
, nonvirtual
>, // CallNonvirtualBooleanMethodV
2669 _Jv_JNI_CallAnyMethodA
<jboolean
, nonvirtual
>, // CallNonvirtualBooleanMethodA
2670 _Jv_JNI_CallAnyMethod
<jbyte
, nonvirtual
>, // CallNonvirtualByteMethod
2671 _Jv_JNI_CallAnyMethodV
<jbyte
, nonvirtual
>, // CallNonvirtualByteMethodV
2672 _Jv_JNI_CallAnyMethodA
<jbyte
, nonvirtual
>, // CallNonvirtualByteMethodA
2673 _Jv_JNI_CallAnyMethod
<jchar
, nonvirtual
>, // CallNonvirtualCharMethod
2674 _Jv_JNI_CallAnyMethodV
<jchar
, nonvirtual
>, // CallNonvirtualCharMethodV
2675 _Jv_JNI_CallAnyMethodA
<jchar
, nonvirtual
>, // CallNonvirtualCharMethodA
2676 _Jv_JNI_CallAnyMethod
<jshort
, nonvirtual
>, // CallNonvirtualShortMethod
2677 _Jv_JNI_CallAnyMethodV
<jshort
, nonvirtual
>, // CallNonvirtualShortMethodV
2678 _Jv_JNI_CallAnyMethodA
<jshort
, nonvirtual
>, // CallNonvirtualShortMethodA
2679 _Jv_JNI_CallAnyMethod
<jint
, nonvirtual
>, // CallNonvirtualIntMethod
2680 _Jv_JNI_CallAnyMethodV
<jint
, nonvirtual
>, // CallNonvirtualIntMethodV
2681 _Jv_JNI_CallAnyMethodA
<jint
, nonvirtual
>, // CallNonvirtualIntMethodA
2682 _Jv_JNI_CallAnyMethod
<jlong
, nonvirtual
>, // CallNonvirtualLongMethod
2683 _Jv_JNI_CallAnyMethodV
<jlong
, nonvirtual
>, // CallNonvirtualLongMethodV
2684 _Jv_JNI_CallAnyMethodA
<jlong
, nonvirtual
>, // CallNonvirtualLongMethodA
2685 _Jv_JNI_CallAnyMethod
<jfloat
, nonvirtual
>, // CallNonvirtualFloatMethod
2686 _Jv_JNI_CallAnyMethodV
<jfloat
, nonvirtual
>, // CallNonvirtualFloatMethodV
2687 _Jv_JNI_CallAnyMethodA
<jfloat
, nonvirtual
>, // CallNonvirtualFloatMethodA
2688 _Jv_JNI_CallAnyMethod
<jdouble
, nonvirtual
>, // CallNonvirtualDoubleMethod
2689 _Jv_JNI_CallAnyMethodV
<jdouble
, nonvirtual
>, // CallNonvirtualDoubleMethodV
2690 _Jv_JNI_CallAnyMethodA
<jdouble
, nonvirtual
>, // CallNonvirtualDoubleMethodA
2691 _Jv_JNI_CallAnyVoidMethod
<nonvirtual
>, // CallNonvirtualVoidMethod
2692 _Jv_JNI_CallAnyVoidMethodV
<nonvirtual
>, // CallNonvirtualVoidMethodV
2693 _Jv_JNI_CallAnyVoidMethodA
<nonvirtual
>, // CallNonvirtualVoidMethodA
2695 _Jv_JNI_GetAnyFieldID
<false>, // GetFieldID
2696 _Jv_JNI_GetField
<jobject
>, // GetObjectField
2697 _Jv_JNI_GetField
<jboolean
>, // GetBooleanField
2698 _Jv_JNI_GetField
<jbyte
>, // GetByteField
2699 _Jv_JNI_GetField
<jchar
>, // GetCharField
2700 _Jv_JNI_GetField
<jshort
>, // GetShortField
2701 _Jv_JNI_GetField
<jint
>, // GetIntField
2702 _Jv_JNI_GetField
<jlong
>, // GetLongField
2703 _Jv_JNI_GetField
<jfloat
>, // GetFloatField
2704 _Jv_JNI_GetField
<jdouble
>, // GetDoubleField
2705 _Jv_JNI_SetField
, // SetObjectField
2706 _Jv_JNI_SetField
, // SetBooleanField
2707 _Jv_JNI_SetField
, // SetByteField
2708 _Jv_JNI_SetField
, // SetCharField
2709 _Jv_JNI_SetField
, // SetShortField
2710 _Jv_JNI_SetField
, // SetIntField
2711 _Jv_JNI_SetField
, // SetLongField
2712 _Jv_JNI_SetField
, // SetFloatField
2713 _Jv_JNI_SetField
, // SetDoubleField
2714 _Jv_JNI_GetAnyMethodID
<true>, // GetStaticMethodID
2716 _Jv_JNI_CallStaticMethod
<jobject
>, // CallStaticObjectMethod
2717 _Jv_JNI_CallStaticMethodV
<jobject
>, // CallStaticObjectMethodV
2718 _Jv_JNI_CallStaticMethodA
<jobject
>, // CallStaticObjectMethodA
2719 _Jv_JNI_CallStaticMethod
<jboolean
>, // CallStaticBooleanMethod
2720 _Jv_JNI_CallStaticMethodV
<jboolean
>, // CallStaticBooleanMethodV
2721 _Jv_JNI_CallStaticMethodA
<jboolean
>, // CallStaticBooleanMethodA
2722 _Jv_JNI_CallStaticMethod
<jbyte
>, // CallStaticByteMethod
2723 _Jv_JNI_CallStaticMethodV
<jbyte
>, // CallStaticByteMethodV
2724 _Jv_JNI_CallStaticMethodA
<jbyte
>, // CallStaticByteMethodA
2725 _Jv_JNI_CallStaticMethod
<jchar
>, // CallStaticCharMethod
2726 _Jv_JNI_CallStaticMethodV
<jchar
>, // CallStaticCharMethodV
2727 _Jv_JNI_CallStaticMethodA
<jchar
>, // CallStaticCharMethodA
2728 _Jv_JNI_CallStaticMethod
<jshort
>, // CallStaticShortMethod
2729 _Jv_JNI_CallStaticMethodV
<jshort
>, // CallStaticShortMethodV
2730 _Jv_JNI_CallStaticMethodA
<jshort
>, // CallStaticShortMethodA
2731 _Jv_JNI_CallStaticMethod
<jint
>, // CallStaticIntMethod
2732 _Jv_JNI_CallStaticMethodV
<jint
>, // CallStaticIntMethodV
2733 _Jv_JNI_CallStaticMethodA
<jint
>, // CallStaticIntMethodA
2734 _Jv_JNI_CallStaticMethod
<jlong
>, // CallStaticLongMethod
2735 _Jv_JNI_CallStaticMethodV
<jlong
>, // CallStaticLongMethodV
2736 _Jv_JNI_CallStaticMethodA
<jlong
>, // CallStaticLongMethodA
2737 _Jv_JNI_CallStaticMethod
<jfloat
>, // CallStaticFloatMethod
2738 _Jv_JNI_CallStaticMethodV
<jfloat
>, // CallStaticFloatMethodV
2739 _Jv_JNI_CallStaticMethodA
<jfloat
>, // CallStaticFloatMethodA
2740 _Jv_JNI_CallStaticMethod
<jdouble
>, // CallStaticDoubleMethod
2741 _Jv_JNI_CallStaticMethodV
<jdouble
>, // CallStaticDoubleMethodV
2742 _Jv_JNI_CallStaticMethodA
<jdouble
>, // CallStaticDoubleMethodA
2743 _Jv_JNI_CallStaticVoidMethod
, // CallStaticVoidMethod
2744 _Jv_JNI_CallStaticVoidMethodV
, // CallStaticVoidMethodV
2745 _Jv_JNI_CallStaticVoidMethodA
, // CallStaticVoidMethodA
2747 _Jv_JNI_GetAnyFieldID
<true>, // GetStaticFieldID
2748 _Jv_JNI_GetStaticField
<jobject
>, // GetStaticObjectField
2749 _Jv_JNI_GetStaticField
<jboolean
>, // GetStaticBooleanField
2750 _Jv_JNI_GetStaticField
<jbyte
>, // GetStaticByteField
2751 _Jv_JNI_GetStaticField
<jchar
>, // GetStaticCharField
2752 _Jv_JNI_GetStaticField
<jshort
>, // GetStaticShortField
2753 _Jv_JNI_GetStaticField
<jint
>, // GetStaticIntField
2754 _Jv_JNI_GetStaticField
<jlong
>, // GetStaticLongField
2755 _Jv_JNI_GetStaticField
<jfloat
>, // GetStaticFloatField
2756 _Jv_JNI_GetStaticField
<jdouble
>, // GetStaticDoubleField
2757 _Jv_JNI_SetStaticField
, // SetStaticObjectField
2758 _Jv_JNI_SetStaticField
, // SetStaticBooleanField
2759 _Jv_JNI_SetStaticField
, // SetStaticByteField
2760 _Jv_JNI_SetStaticField
, // SetStaticCharField
2761 _Jv_JNI_SetStaticField
, // SetStaticShortField
2762 _Jv_JNI_SetStaticField
, // SetStaticIntField
2763 _Jv_JNI_SetStaticField
, // SetStaticLongField
2764 _Jv_JNI_SetStaticField
, // SetStaticFloatField
2765 _Jv_JNI_SetStaticField
, // SetStaticDoubleField
2766 _Jv_JNI_NewString
, // NewString
2767 _Jv_JNI_GetStringLength
, // GetStringLength
2768 _Jv_JNI_GetStringChars
, // GetStringChars
2769 _Jv_JNI_ReleaseStringChars
, // ReleaseStringChars
2770 _Jv_JNI_NewStringUTF
, // NewStringUTF
2771 _Jv_JNI_GetStringUTFLength
, // GetStringUTFLength
2772 _Jv_JNI_GetStringUTFChars
, // GetStringUTFChars
2773 _Jv_JNI_ReleaseStringUTFChars
, // ReleaseStringUTFChars
2774 _Jv_JNI_GetArrayLength
, // GetArrayLength
2775 _Jv_JNI_NewObjectArray
, // NewObjectArray
2776 _Jv_JNI_GetObjectArrayElement
, // GetObjectArrayElement
2777 _Jv_JNI_SetObjectArrayElement
, // SetObjectArrayElement
2778 _Jv_JNI_NewPrimitiveArray
<jboolean
, JvPrimClass (boolean
)>,
2780 _Jv_JNI_NewPrimitiveArray
<jbyte
, JvPrimClass (byte
)>, // NewByteArray
2781 _Jv_JNI_NewPrimitiveArray
<jchar
, JvPrimClass (char)>, // NewCharArray
2782 _Jv_JNI_NewPrimitiveArray
<jshort
, JvPrimClass (short)>, // NewShortArray
2783 _Jv_JNI_NewPrimitiveArray
<jint
, JvPrimClass (int)>, // NewIntArray
2784 _Jv_JNI_NewPrimitiveArray
<jlong
, JvPrimClass (long)>, // NewLongArray
2785 _Jv_JNI_NewPrimitiveArray
<jfloat
, JvPrimClass (float)>, // NewFloatArray
2786 _Jv_JNI_NewPrimitiveArray
<jdouble
, JvPrimClass (double)>, // NewDoubleArray
2787 _Jv_JNI_GetPrimitiveArrayElements
<jboolean
, JvPrimClass (boolean
)>,
2788 // GetBooleanArrayElements
2789 _Jv_JNI_GetPrimitiveArrayElements
<jbyte
, JvPrimClass (byte
)>,
2790 // GetByteArrayElements
2791 _Jv_JNI_GetPrimitiveArrayElements
<jchar
, JvPrimClass (char)>,
2792 // GetCharArrayElements
2793 _Jv_JNI_GetPrimitiveArrayElements
<jshort
, JvPrimClass (short)>,
2794 // GetShortArrayElements
2795 _Jv_JNI_GetPrimitiveArrayElements
<jint
, JvPrimClass (int)>,
2796 // GetIntArrayElements
2797 _Jv_JNI_GetPrimitiveArrayElements
<jlong
, JvPrimClass (long)>,
2798 // GetLongArrayElements
2799 _Jv_JNI_GetPrimitiveArrayElements
<jfloat
, JvPrimClass (float)>,
2800 // GetFloatArrayElements
2801 _Jv_JNI_GetPrimitiveArrayElements
<jdouble
, JvPrimClass (double)>,
2802 // GetDoubleArrayElements
2803 _Jv_JNI_ReleasePrimitiveArrayElements
<jboolean
, JvPrimClass (boolean
)>,
2804 // ReleaseBooleanArrayElements
2805 _Jv_JNI_ReleasePrimitiveArrayElements
<jbyte
, JvPrimClass (byte
)>,
2806 // ReleaseByteArrayElements
2807 _Jv_JNI_ReleasePrimitiveArrayElements
<jchar
, JvPrimClass (char)>,
2808 // ReleaseCharArrayElements
2809 _Jv_JNI_ReleasePrimitiveArrayElements
<jshort
, JvPrimClass (short)>,
2810 // ReleaseShortArrayElements
2811 _Jv_JNI_ReleasePrimitiveArrayElements
<jint
, JvPrimClass (int)>,
2812 // ReleaseIntArrayElements
2813 _Jv_JNI_ReleasePrimitiveArrayElements
<jlong
, JvPrimClass (long)>,
2814 // ReleaseLongArrayElements
2815 _Jv_JNI_ReleasePrimitiveArrayElements
<jfloat
, JvPrimClass (float)>,
2816 // ReleaseFloatArrayElements
2817 _Jv_JNI_ReleasePrimitiveArrayElements
<jdouble
, JvPrimClass (double)>,
2818 // ReleaseDoubleArrayElements
2819 _Jv_JNI_GetPrimitiveArrayRegion
<jboolean
, JvPrimClass (boolean
)>,
2820 // GetBooleanArrayRegion
2821 _Jv_JNI_GetPrimitiveArrayRegion
<jbyte
, JvPrimClass (byte
)>,
2822 // GetByteArrayRegion
2823 _Jv_JNI_GetPrimitiveArrayRegion
<jchar
, JvPrimClass (char)>,
2824 // GetCharArrayRegion
2825 _Jv_JNI_GetPrimitiveArrayRegion
<jshort
, JvPrimClass (short)>,
2826 // GetShortArrayRegion
2827 _Jv_JNI_GetPrimitiveArrayRegion
<jint
, JvPrimClass (int)>,
2828 // GetIntArrayRegion
2829 _Jv_JNI_GetPrimitiveArrayRegion
<jlong
, JvPrimClass (long)>,
2830 // GetLongArrayRegion
2831 _Jv_JNI_GetPrimitiveArrayRegion
<jfloat
, JvPrimClass (float)>,
2832 // GetFloatArrayRegion
2833 _Jv_JNI_GetPrimitiveArrayRegion
<jdouble
, JvPrimClass (double)>,
2834 // GetDoubleArrayRegion
2835 _Jv_JNI_SetPrimitiveArrayRegion
<jboolean
, JvPrimClass (boolean
)>,
2836 // SetBooleanArrayRegion
2837 _Jv_JNI_SetPrimitiveArrayRegion
<jbyte
, JvPrimClass (byte
)>,
2838 // SetByteArrayRegion
2839 _Jv_JNI_SetPrimitiveArrayRegion
<jchar
, JvPrimClass (char)>,
2840 // SetCharArrayRegion
2841 _Jv_JNI_SetPrimitiveArrayRegion
<jshort
, JvPrimClass (short)>,
2842 // SetShortArrayRegion
2843 _Jv_JNI_SetPrimitiveArrayRegion
<jint
, JvPrimClass (int)>,
2844 // SetIntArrayRegion
2845 _Jv_JNI_SetPrimitiveArrayRegion
<jlong
, JvPrimClass (long)>,
2846 // SetLongArrayRegion
2847 _Jv_JNI_SetPrimitiveArrayRegion
<jfloat
, JvPrimClass (float)>,
2848 // SetFloatArrayRegion
2849 _Jv_JNI_SetPrimitiveArrayRegion
<jdouble
, JvPrimClass (double)>,
2850 // SetDoubleArrayRegion
2851 _Jv_JNI_RegisterNatives
, // RegisterNatives
2852 _Jv_JNI_UnregisterNatives
, // UnregisterNatives
2853 _Jv_JNI_MonitorEnter
, // MonitorEnter
2854 _Jv_JNI_MonitorExit
, // MonitorExit
2855 _Jv_JNI_GetJavaVM
, // GetJavaVM
2857 _Jv_JNI_GetStringRegion
, // GetStringRegion
2858 _Jv_JNI_GetStringUTFRegion
, // GetStringUTFRegion
2859 _Jv_JNI_GetPrimitiveArrayCritical
, // GetPrimitiveArrayCritical
2860 _Jv_JNI_ReleasePrimitiveArrayCritical
, // ReleasePrimitiveArrayCritical
2861 _Jv_JNI_GetStringCritical
, // GetStringCritical
2862 _Jv_JNI_ReleaseStringCritical
, // ReleaseStringCritical
2864 _Jv_JNI_NewWeakGlobalRef
, // NewWeakGlobalRef
2865 _Jv_JNI_DeleteWeakGlobalRef
, // DeleteWeakGlobalRef
2867 _Jv_JNI_ExceptionCheck
, // ExceptionCheck
2869 _Jv_JNI_NewDirectByteBuffer
, // NewDirectByteBuffer
2870 _Jv_JNI_GetDirectBufferAddress
, // GetDirectBufferAddress
2871 _Jv_JNI_GetDirectBufferCapacity
// GetDirectBufferCapacity
2874 struct JNIInvokeInterface _Jv_JNI_InvokeFunctions
=
2880 _Jv_JNI_DestroyJavaVM
,
2881 _Jv_JNI_AttachCurrentThread
,
2882 _Jv_JNI_DetachCurrentThread
,
2884 _Jv_JNI_AttachCurrentThreadAsDaemon