1 // jni.cc - JNI implementation, including the jump table.
3 /* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
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>
49 #include <java/lang/ClassNotFoundException.h>
51 #include <gcj/method.h>
52 #include <gcj/field.h>
54 #include <java-interp.h>
55 #include <java-threads.h>
59 // This enum is used to select different template instantiations in
60 // the invocation code.
69 // Forward declarations.
70 extern struct JNINativeInterface _Jv_JNIFunctions
;
71 extern struct JNIInvokeInterface _Jv_JNI_InvokeFunctions
;
73 // Number of slots in the default frame. The VM must allow at least
77 // Mark value indicating this is an overflow frame.
79 // Mark value indicating this is a user frame.
81 // Mark value indicating this is a system frame.
84 // This structure is used to keep track of local references.
85 struct _Jv_JNI_LocalFrame
87 // This is true if this frame object represents a pushed frame (eg
88 // from PushLocalFrame).
91 // Flag to indicate some locals were allocated.
94 // Number of elements in frame.
97 // Next frame in chain.
98 _Jv_JNI_LocalFrame
*next
;
100 // The elements. These are allocated using the C "struct hack".
104 // This holds a reference count for all local references.
105 static java::util::IdentityHashMap
*local_ref_table
;
106 // This holds a reference count for all global references.
107 static java::util::IdentityHashMap
*global_ref_table
;
110 static JavaVM
*the_vm
;
113 // The only JVMPI interface description.
114 static JVMPI_Interface _Jv_JVMPI_Interface
;
117 jvmpiEnableEvent (jint event_type
, void *)
121 case JVMPI_EVENT_OBJECT_ALLOC
:
122 _Jv_JVMPI_Notify_OBJECT_ALLOC
= _Jv_JVMPI_Interface
.NotifyEvent
;
125 case JVMPI_EVENT_THREAD_START
:
126 _Jv_JVMPI_Notify_THREAD_START
= _Jv_JVMPI_Interface
.NotifyEvent
;
129 case JVMPI_EVENT_THREAD_END
:
130 _Jv_JVMPI_Notify_THREAD_END
= _Jv_JVMPI_Interface
.NotifyEvent
;
134 return JVMPI_NOT_AVAILABLE
;
137 return JVMPI_SUCCESS
;
141 jvmpiDisableEvent (jint event_type
, void *)
145 case JVMPI_EVENT_OBJECT_ALLOC
:
146 _Jv_JVMPI_Notify_OBJECT_ALLOC
= NULL
;
150 return JVMPI_NOT_AVAILABLE
;
153 return JVMPI_SUCCESS
;
162 local_ref_table
= new java::util::IdentityHashMap
;
163 global_ref_table
= new java::util::IdentityHashMap
;
166 _Jv_JVMPI_Interface
.version
= 1;
167 _Jv_JVMPI_Interface
.EnableEvent
= &jvmpiEnableEvent
;
168 _Jv_JVMPI_Interface
.DisableEvent
= &jvmpiDisableEvent
;
169 _Jv_JVMPI_Interface
.EnableGC
= &_Jv_EnableGC
;
170 _Jv_JVMPI_Interface
.DisableGC
= &_Jv_DisableGC
;
171 _Jv_JVMPI_Interface
.RunGC
= &_Jv_RunGC
;
175 // Tell the GC that a certain pointer is live.
177 mark_for_gc (jobject obj
, java::util::IdentityHashMap
*ref_table
)
179 JvSynchronize
sync (ref_table
);
181 using namespace java::lang
;
182 Integer
*refcount
= (Integer
*) ref_table
->get (obj
);
183 jint val
= (refcount
== NULL
) ? 0 : refcount
->intValue ();
184 // FIXME: what about out of memory error?
185 ref_table
->put (obj
, new Integer (val
+ 1));
190 unmark_for_gc (jobject obj
, java::util::IdentityHashMap
*ref_table
)
192 JvSynchronize
sync (ref_table
);
194 using namespace java::lang
;
195 Integer
*refcount
= (Integer
*) ref_table
->get (obj
);
197 jint val
= refcount
->intValue () - 1;
200 ref_table
->remove (obj
);
202 // FIXME: what about out of memory error?
203 ref_table
->put (obj
, new Integer (val
));
206 // "Unwrap" some random non-reference type. This exists to simplify
207 // other template functions.
215 // Unwrap a weak reference, if required.
220 using namespace gnu::gcj::runtime
;
221 // We can compare the class directly because JNIWeakRef is `final'.
222 // Doing it this way is much faster.
223 if (obj
== NULL
|| obj
->getClass () != &JNIWeakRef::class$
)
225 JNIWeakRef
*wr
= reinterpret_cast<JNIWeakRef
*> (obj
);
226 return reinterpret_cast<T
*> (wr
->get ());
230 _Jv_UnwrapJNIweakReference (jobject obj
)
237 static jobject JNICALL
238 _Jv_JNI_NewGlobalRef (JNIEnv
*, jobject obj
)
240 // This seems weird but I think it is correct.
242 mark_for_gc (obj
, global_ref_table
);
247 _Jv_JNI_DeleteGlobalRef (JNIEnv
*, jobject obj
)
249 // This seems weird but I think it is correct.
251 unmark_for_gc (obj
, global_ref_table
);
255 _Jv_JNI_DeleteLocalRef (JNIEnv
*env
, jobject obj
)
257 _Jv_JNI_LocalFrame
*frame
;
259 // This seems weird but I think it is correct.
262 for (frame
= env
->locals
; frame
!= NULL
; frame
= frame
->next
)
264 for (int i
= 0; i
< frame
->size
; ++i
)
266 if (frame
->vec
[i
] == obj
)
268 frame
->vec
[i
] = NULL
;
269 unmark_for_gc (obj
, local_ref_table
);
274 // Don't go past a marked frame.
275 JvAssert (frame
->marker
== MARK_NONE
);
282 _Jv_JNI_EnsureLocalCapacity (JNIEnv
*env
, jint size
)
284 // It is easier to just always allocate a new frame of the requested
285 // size. This isn't the most efficient thing, but for now we don't
286 // care. Note that _Jv_JNI_PushLocalFrame relies on this right now.
288 _Jv_JNI_LocalFrame
*frame
;
291 frame
= (_Jv_JNI_LocalFrame
*) _Jv_Malloc (sizeof (_Jv_JNI_LocalFrame
)
292 + size
* sizeof (jobject
));
300 frame
->marker
= MARK_NONE
;
302 frame
->allocated_p
= 0;
303 memset (&frame
->vec
[0], 0, size
* sizeof (jobject
));
304 frame
->next
= env
->locals
;
311 _Jv_JNI_PushLocalFrame (JNIEnv
*env
, jint size
)
313 jint r
= _Jv_JNI_EnsureLocalCapacity (env
, size
);
317 // The new frame is on top.
318 env
->locals
->marker
= MARK_USER
;
323 static jobject JNICALL
324 _Jv_JNI_NewLocalRef (JNIEnv
*env
, jobject obj
)
326 // This seems weird but I think it is correct.
329 // Try to find an open slot somewhere in the topmost frame.
330 _Jv_JNI_LocalFrame
*frame
= env
->locals
;
331 bool done
= false, set
= false;
332 for (; frame
!= NULL
&& ! done
; frame
= frame
->next
)
334 for (int i
= 0; i
< frame
->size
; ++i
)
336 if (frame
->vec
[i
] == NULL
)
341 frame
->allocated_p
= 1;
346 // If we found a slot, or if the frame we just searched is the
347 // mark frame, then we are done.
348 if (done
|| frame
== NULL
|| frame
->marker
!= MARK_NONE
)
354 // No slots, so we allocate a new frame. According to the spec
355 // we could just die here. FIXME: return value.
356 _Jv_JNI_EnsureLocalCapacity (env
, 16);
357 // We know the first element of the new frame will be ok.
358 env
->locals
->vec
[0] = obj
;
359 env
->locals
->allocated_p
= 1;
362 mark_for_gc (obj
, local_ref_table
);
366 static jobject JNICALL
367 _Jv_JNI_PopLocalFrame (JNIEnv
*env
, jobject result
, int stop
)
369 _Jv_JNI_LocalFrame
*rf
= env
->locals
;
372 while (rf
!= NULL
&& ! done
)
374 for (int i
= 0; i
< rf
->size
; ++i
)
375 if (rf
->vec
[i
] != NULL
)
376 unmark_for_gc (rf
->vec
[i
], local_ref_table
);
378 // If the frame we just freed is the marker frame, we are done.
379 done
= (rf
->marker
== stop
);
381 _Jv_JNI_LocalFrame
*n
= rf
->next
;
382 // When N==NULL, we've reached the reusable bottom_locals, and we must
383 // not free it. However, we must be sure to clear all its elements.
387 memset (&rf
->vec
[0], 0, rf
->size
* sizeof (jobject
));
397 // Update the local frame information.
400 return result
== NULL
? NULL
: _Jv_JNI_NewLocalRef (env
, result
);
403 static jobject JNICALL
404 _Jv_JNI_PopLocalFrame (JNIEnv
*env
, jobject result
)
406 return _Jv_JNI_PopLocalFrame (env
, result
, MARK_USER
);
409 // Make sure an array's type is compatible with the type of the
413 _Jv_JNI_check_types (JNIEnv
*env
, JArray
<T
> *array
, jclass K
)
415 jclass klass
= array
->getClass()->getComponentType();
416 if (__builtin_expect (klass
!= K
, false))
418 env
->ex
= new java::lang::IllegalAccessError ();
425 // Pop a `system' frame from the stack. This is `extern "C"' as it is
426 // used by the compiler.
428 _Jv_JNI_PopSystemFrame (JNIEnv
*env
)
430 // Only enter slow path when we're not at the bottom, or there have been
431 // allocations. Usually this is false and we can just null out the locals
434 if (__builtin_expect ((env
->locals
->next
435 || env
->locals
->allocated_p
), false))
436 _Jv_JNI_PopLocalFrame (env
, NULL
, MARK_SYSTEM
);
440 if (__builtin_expect (env
->ex
!= NULL
, false))
442 jthrowable t
= env
->ex
;
448 template<typename T
> T
extract_from_jvalue(jvalue
const & t
);
449 template<> jboolean
extract_from_jvalue(jvalue
const & jv
) { return jv
.z
; }
450 template<> jbyte
extract_from_jvalue(jvalue
const & jv
) { return jv
.b
; }
451 template<> jchar
extract_from_jvalue(jvalue
const & jv
) { return jv
.c
; }
452 template<> jshort
extract_from_jvalue(jvalue
const & jv
) { return jv
.s
; }
453 template<> jint
extract_from_jvalue(jvalue
const & jv
) { return jv
.i
; }
454 template<> jlong
extract_from_jvalue(jvalue
const & jv
) { return jv
.j
; }
455 template<> jfloat
extract_from_jvalue(jvalue
const & jv
) { return jv
.f
; }
456 template<> jdouble
extract_from_jvalue(jvalue
const & jv
) { return jv
.d
; }
457 template<> jobject
extract_from_jvalue(jvalue
const & jv
) { return jv
.l
; }
460 // This function is used from other template functions. It wraps the
461 // return value appropriately; we specialize it so that object returns
462 // are turned into local references.
465 wrap_value (JNIEnv
*, T value
)
470 // This specialization is used for jobject, jclass, jstring, jarray,
472 template<typename R
, typename T
>
474 wrap_value (JNIEnv
*env
, T
*value
)
476 return (value
== NULL
478 : (T
*) _Jv_JNI_NewLocalRef (env
, (jobject
) value
));
484 _Jv_JNI_GetVersion (JNIEnv
*)
486 return JNI_VERSION_1_4
;
489 static jclass JNICALL
490 _Jv_JNI_DefineClass (JNIEnv
*env
, const char *name
, jobject loader
,
491 const jbyte
*buf
, jsize bufLen
)
495 loader
= unwrap (loader
);
497 jstring sname
= JvNewStringUTF (name
);
498 jbyteArray bytes
= JvNewByteArray (bufLen
);
500 jbyte
*elts
= elements (bytes
);
501 memcpy (elts
, buf
, bufLen
* sizeof (jbyte
));
503 java::lang::ClassLoader
*l
504 = reinterpret_cast<java::lang::ClassLoader
*> (loader
);
506 jclass result
= l
->defineClass (sname
, bytes
, 0, bufLen
);
507 return (jclass
) wrap_value (env
, result
);
516 static jclass JNICALL
517 _Jv_JNI_FindClass (JNIEnv
*env
, const char *name
)
519 // FIXME: assume that NAME isn't too long.
520 int len
= strlen (name
);
522 for (int i
= 0; i
<= len
; ++i
)
523 s
[i
] = (name
[i
] == '/') ? '.' : name
[i
];
528 // This might throw an out of memory exception.
529 jstring n
= JvNewStringUTF (s
);
531 java::lang::ClassLoader
*loader
= NULL
;
532 if (env
->klass
!= NULL
)
533 loader
= env
->klass
->getClassLoaderInternal ();
537 // FIXME: should use getBaseClassLoader, but we don't have that
539 loader
= java::lang::ClassLoader::getSystemClassLoader ();
542 r
= loader
->loadClass (n
);
549 return (jclass
) wrap_value (env
, r
);
552 static jclass JNICALL
553 _Jv_JNI_GetSuperclass (JNIEnv
*env
, jclass clazz
)
555 return (jclass
) wrap_value (env
, unwrap (clazz
)->getSuperclass ());
558 static jboolean JNICALL
559 _Jv_JNI_IsAssignableFrom (JNIEnv
*, jclass clazz1
, jclass clazz2
)
561 return unwrap (clazz2
)->isAssignableFrom (unwrap (clazz1
));
565 _Jv_JNI_Throw (JNIEnv
*env
, jthrowable obj
)
567 // We check in case the user did some funky cast.
569 JvAssert (obj
!= NULL
&& java::lang::Throwable::class$
.isInstance (obj
));
575 _Jv_JNI_ThrowNew (JNIEnv
*env
, jclass clazz
, const char *message
)
577 using namespace java::lang::reflect
;
579 clazz
= unwrap (clazz
);
580 JvAssert (java::lang::Throwable::class$
.isAssignableFrom (clazz
));
585 JArray
<jclass
> *argtypes
586 = (JArray
<jclass
> *) JvNewObjectArray (1, &java::lang::Class::class$
,
589 jclass
*elts
= elements (argtypes
);
590 elts
[0] = &java::lang::String::class$
;
592 Constructor
*cons
= clazz
->getConstructor (argtypes
);
594 jobjectArray values
= JvNewObjectArray (1, &java::lang::String::class$
,
596 jobject
*velts
= elements (values
);
597 velts
[0] = JvNewStringUTF (message
);
599 jobject obj
= cons
->newInstance (values
);
601 env
->ex
= reinterpret_cast<jthrowable
> (obj
);
612 static jthrowable JNICALL
613 _Jv_JNI_ExceptionOccurred (JNIEnv
*env
)
615 return (jthrowable
) wrap_value (env
, env
->ex
);
619 _Jv_JNI_ExceptionDescribe (JNIEnv
*env
)
622 env
->ex
->printStackTrace();
626 _Jv_JNI_ExceptionClear (JNIEnv
*env
)
631 static jboolean JNICALL
632 _Jv_JNI_ExceptionCheck (JNIEnv
*env
)
634 return env
->ex
!= NULL
;
638 _Jv_JNI_FatalError (JNIEnv
*, const char *message
)
645 static jboolean JNICALL
646 _Jv_JNI_IsSameObject (JNIEnv
*, jobject obj1
, jobject obj2
)
648 return unwrap (obj1
) == unwrap (obj2
);
651 static jobject JNICALL
652 _Jv_JNI_AllocObject (JNIEnv
*env
, jclass clazz
)
655 using namespace java::lang::reflect
;
659 clazz
= unwrap (clazz
);
660 JvAssert (clazz
&& ! clazz
->isArray ());
661 if (clazz
->isInterface() || Modifier::isAbstract(clazz
->getModifiers()))
662 env
->ex
= new java::lang::InstantiationException ();
664 obj
= _Jv_AllocObject (clazz
);
671 return wrap_value (env
, obj
);
674 static jclass JNICALL
675 _Jv_JNI_GetObjectClass (JNIEnv
*env
, jobject obj
)
679 return (jclass
) wrap_value (env
, obj
->getClass());
682 static jboolean JNICALL
683 _Jv_JNI_IsInstanceOf (JNIEnv
*, jobject obj
, jclass clazz
)
685 return unwrap (clazz
)->isInstance(unwrap (obj
));
691 // This section concerns method invocation.
694 template<jboolean is_static
>
695 static jmethodID JNICALL
696 _Jv_JNI_GetAnyMethodID (JNIEnv
*env
, jclass clazz
,
697 const char *name
, const char *sig
)
701 clazz
= unwrap (clazz
);
702 _Jv_InitClass (clazz
);
704 _Jv_Utf8Const
*name_u
= _Jv_makeUtf8Const ((char *) name
, -1);
706 // FIXME: assume that SIG isn't too long.
707 int len
= strlen (sig
);
709 for (int i
= 0; i
<= len
; ++i
)
710 s
[i
] = (sig
[i
] == '/') ? '.' : sig
[i
];
711 _Jv_Utf8Const
*sig_u
= _Jv_makeUtf8Const ((char *) s
, -1);
713 JvAssert (! clazz
->isPrimitive());
715 using namespace java::lang::reflect
;
717 while (clazz
!= NULL
)
719 jint count
= JvNumMethods (clazz
);
720 jmethodID meth
= JvGetFirstMethod (clazz
);
722 for (jint i
= 0; i
< count
; ++i
)
724 if (((is_static
&& Modifier::isStatic (meth
->accflags
))
725 || (! is_static
&& ! Modifier::isStatic (meth
->accflags
)))
726 && _Jv_equalUtf8Consts (meth
->name
, name_u
)
727 && _Jv_equalUtf8Consts (meth
->signature
, sig_u
))
730 meth
= meth
->getNextMethod();
733 clazz
= clazz
->getSuperclass ();
736 java::lang::StringBuffer
*name_sig
=
737 new java::lang::StringBuffer (JvNewStringUTF (name
));
738 name_sig
->append ((jchar
) ' ')->append (JvNewStringUTF (s
));
739 env
->ex
= new java::lang::NoSuchMethodError (name_sig
->toString ());
749 // This is a helper function which turns a va_list into an array of
750 // `jvalue's. It needs signature information in order to do its work.
751 // The array of values must already be allocated.
753 array_from_valist (jvalue
*values
, JArray
<jclass
> *arg_types
, va_list vargs
)
755 jclass
*arg_elts
= elements (arg_types
);
756 for (int i
= 0; i
< arg_types
->length
; ++i
)
758 // Here we assume that sizeof(int) >= sizeof(jint), because we
759 // use `int' when decoding the varargs. Likewise for
760 // float, and double. Also we assume that sizeof(jlong) >=
761 // sizeof(int), i.e. that jlong values are not further
763 JvAssert (sizeof (int) >= sizeof (jint
));
764 JvAssert (sizeof (jlong
) >= sizeof (int));
765 JvAssert (sizeof (double) >= sizeof (jfloat
));
766 JvAssert (sizeof (double) >= sizeof (jdouble
));
767 if (arg_elts
[i
] == JvPrimClass (byte
))
768 values
[i
].b
= (jbyte
) va_arg (vargs
, int);
769 else if (arg_elts
[i
] == JvPrimClass (short))
770 values
[i
].s
= (jshort
) va_arg (vargs
, int);
771 else if (arg_elts
[i
] == JvPrimClass (int))
772 values
[i
].i
= (jint
) va_arg (vargs
, int);
773 else if (arg_elts
[i
] == JvPrimClass (long))
774 values
[i
].j
= (jlong
) va_arg (vargs
, jlong
);
775 else if (arg_elts
[i
] == JvPrimClass (float))
776 values
[i
].f
= (jfloat
) va_arg (vargs
, double);
777 else if (arg_elts
[i
] == JvPrimClass (double))
778 values
[i
].d
= (jdouble
) va_arg (vargs
, double);
779 else if (arg_elts
[i
] == JvPrimClass (boolean
))
780 values
[i
].z
= (jboolean
) va_arg (vargs
, int);
781 else if (arg_elts
[i
] == JvPrimClass (char))
782 values
[i
].c
= (jchar
) va_arg (vargs
, int);
786 values
[i
].l
= unwrap (va_arg (vargs
, jobject
));
791 // This can call any sort of method: virtual, "nonvirtual", static, or
793 template<typename T
, invocation_type style
>
795 _Jv_JNI_CallAnyMethodV (JNIEnv
*env
, jobject obj
, jclass klass
,
796 jmethodID id
, va_list vargs
)
799 klass
= unwrap (klass
);
801 jclass decl_class
= klass
? klass
: obj
->getClass ();
802 JvAssert (decl_class
!= NULL
);
805 JArray
<jclass
> *arg_types
;
809 _Jv_GetTypesFromSignature (id
, decl_class
,
810 &arg_types
, &return_type
);
812 jvalue args
[arg_types
->length
];
813 array_from_valist (args
, arg_types
, vargs
);
815 // For constructors we need to pass the Class we are instantiating.
816 if (style
== constructor
)
820 _Jv_CallAnyMethodA (obj
, return_type
, id
,
821 style
== constructor
,
823 arg_types
, args
, &result
);
825 return wrap_value (env
, extract_from_jvalue
<T
>(result
));
832 return wrap_value (env
, (T
) 0);
835 template<typename T
, invocation_type style
>
837 _Jv_JNI_CallAnyMethod (JNIEnv
*env
, jobject obj
, jclass klass
,
838 jmethodID method
, ...)
843 va_start (args
, method
);
844 result
= _Jv_JNI_CallAnyMethodV
<T
, style
> (env
, obj
, klass
, method
, args
);
850 template<typename T
, invocation_type style
>
852 _Jv_JNI_CallAnyMethodA (JNIEnv
*env
, jobject obj
, jclass klass
,
853 jmethodID id
, jvalue
*args
)
856 klass
= unwrap (klass
);
858 jclass decl_class
= klass
? klass
: obj
->getClass ();
859 JvAssert (decl_class
!= NULL
);
862 JArray
<jclass
> *arg_types
;
865 _Jv_GetTypesFromSignature (id
, decl_class
,
866 &arg_types
, &return_type
);
868 // For constructors we need to pass the Class we are instantiating.
869 if (style
== constructor
)
872 // Unwrap arguments as required. Eww.
873 jclass
*type_elts
= elements (arg_types
);
874 jvalue arg_copy
[arg_types
->length
];
875 for (int i
= 0; i
< arg_types
->length
; ++i
)
877 if (type_elts
[i
]->isPrimitive ())
878 arg_copy
[i
] = args
[i
];
880 arg_copy
[i
].l
= unwrap (args
[i
].l
);
884 _Jv_CallAnyMethodA (obj
, return_type
, id
,
885 style
== constructor
,
887 arg_types
, arg_copy
, &result
);
889 return wrap_value (env
, extract_from_jvalue
<T
>(result
));
896 return wrap_value (env
, (T
) 0);
899 template<invocation_type style
>
901 _Jv_JNI_CallAnyVoidMethodV (JNIEnv
*env
, jobject obj
, jclass klass
,
902 jmethodID id
, va_list vargs
)
905 klass
= unwrap (klass
);
907 jclass decl_class
= klass
? klass
: obj
->getClass ();
908 JvAssert (decl_class
!= NULL
);
911 JArray
<jclass
> *arg_types
;
914 _Jv_GetTypesFromSignature (id
, decl_class
,
915 &arg_types
, &return_type
);
917 jvalue args
[arg_types
->length
];
918 array_from_valist (args
, arg_types
, vargs
);
920 // For constructors we need to pass the Class we are instantiating.
921 if (style
== constructor
)
924 _Jv_CallAnyMethodA (obj
, return_type
, id
,
925 style
== constructor
,
927 arg_types
, args
, NULL
);
935 template<invocation_type style
>
937 _Jv_JNI_CallAnyVoidMethod (JNIEnv
*env
, jobject obj
, jclass klass
,
938 jmethodID method
, ...)
942 va_start (args
, method
);
943 _Jv_JNI_CallAnyVoidMethodV
<style
> (env
, obj
, klass
, method
, args
);
947 template<invocation_type style
>
949 _Jv_JNI_CallAnyVoidMethodA (JNIEnv
*env
, jobject obj
, jclass klass
,
950 jmethodID id
, jvalue
*args
)
952 jclass decl_class
= klass
? klass
: obj
->getClass ();
953 JvAssert (decl_class
!= NULL
);
956 JArray
<jclass
> *arg_types
;
959 _Jv_GetTypesFromSignature (id
, decl_class
,
960 &arg_types
, &return_type
);
962 // Unwrap arguments as required. Eww.
963 jclass
*type_elts
= elements (arg_types
);
964 jvalue arg_copy
[arg_types
->length
];
965 for (int i
= 0; i
< arg_types
->length
; ++i
)
967 if (type_elts
[i
]->isPrimitive ())
968 arg_copy
[i
] = args
[i
];
970 arg_copy
[i
].l
= unwrap (args
[i
].l
);
973 _Jv_CallAnyMethodA (obj
, return_type
, id
,
974 style
== constructor
,
976 arg_types
, args
, NULL
);
984 // Functions with this signature are used to implement functions in
985 // the CallMethod family.
988 _Jv_JNI_CallMethodV (JNIEnv
*env
, jobject obj
,
989 jmethodID id
, va_list args
)
991 return _Jv_JNI_CallAnyMethodV
<T
, normal
> (env
, obj
, NULL
, id
, args
);
994 // Functions with this signature are used to implement functions in
995 // the CallMethod family.
998 _Jv_JNI_CallMethod (JNIEnv
*env
, jobject obj
, jmethodID id
, ...)
1003 va_start (args
, id
);
1004 result
= _Jv_JNI_CallAnyMethodV
<T
, normal
> (env
, obj
, NULL
, id
, args
);
1010 // Functions with this signature are used to implement functions in
1011 // the CallMethod family.
1012 template<typename T
>
1014 _Jv_JNI_CallMethodA (JNIEnv
*env
, jobject obj
,
1015 jmethodID id
, jvalue
*args
)
1017 return _Jv_JNI_CallAnyMethodA
<T
, normal
> (env
, obj
, NULL
, id
, args
);
1021 _Jv_JNI_CallVoidMethodV (JNIEnv
*env
, jobject obj
,
1022 jmethodID id
, va_list args
)
1024 _Jv_JNI_CallAnyVoidMethodV
<normal
> (env
, obj
, NULL
, id
, args
);
1028 _Jv_JNI_CallVoidMethod (JNIEnv
*env
, jobject obj
, jmethodID id
, ...)
1032 va_start (args
, id
);
1033 _Jv_JNI_CallAnyVoidMethodV
<normal
> (env
, obj
, NULL
, id
, args
);
1038 _Jv_JNI_CallVoidMethodA (JNIEnv
*env
, jobject obj
,
1039 jmethodID id
, jvalue
*args
)
1041 _Jv_JNI_CallAnyVoidMethodA
<normal
> (env
, obj
, NULL
, id
, args
);
1044 // Functions with this signature are used to implement functions in
1045 // the CallStaticMethod family.
1046 template<typename T
>
1048 _Jv_JNI_CallStaticMethodV (JNIEnv
*env
, jclass klass
,
1049 jmethodID id
, va_list args
)
1051 JvAssert (((id
->accflags
) & java::lang::reflect::Modifier::STATIC
));
1052 JvAssert (java::lang::Class::class$
.isInstance (unwrap (klass
)));
1054 return _Jv_JNI_CallAnyMethodV
<T
, static_type
> (env
, NULL
, klass
, id
, args
);
1057 // Functions with this signature are used to implement functions in
1058 // the CallStaticMethod family.
1059 template<typename T
>
1061 _Jv_JNI_CallStaticMethod (JNIEnv
*env
, jclass klass
,
1067 JvAssert (((id
->accflags
) & java::lang::reflect::Modifier::STATIC
));
1068 JvAssert (java::lang::Class::class$
.isInstance (unwrap (klass
)));
1070 va_start (args
, id
);
1071 result
= _Jv_JNI_CallAnyMethodV
<T
, static_type
> (env
, NULL
, klass
,
1078 // Functions with this signature are used to implement functions in
1079 // the CallStaticMethod family.
1080 template<typename T
>
1082 _Jv_JNI_CallStaticMethodA (JNIEnv
*env
, jclass klass
, jmethodID id
,
1085 JvAssert (((id
->accflags
) & java::lang::reflect::Modifier::STATIC
));
1086 JvAssert (java::lang::Class::class$
.isInstance (unwrap (klass
)));
1088 return _Jv_JNI_CallAnyMethodA
<T
, static_type
> (env
, NULL
, klass
, id
, args
);
1092 _Jv_JNI_CallStaticVoidMethodV (JNIEnv
*env
, jclass klass
,
1093 jmethodID id
, va_list args
)
1095 _Jv_JNI_CallAnyVoidMethodV
<static_type
> (env
, NULL
, klass
, id
, args
);
1099 _Jv_JNI_CallStaticVoidMethod (JNIEnv
*env
, jclass klass
,
1104 va_start (args
, id
);
1105 _Jv_JNI_CallAnyVoidMethodV
<static_type
> (env
, NULL
, klass
, id
, args
);
1110 _Jv_JNI_CallStaticVoidMethodA (JNIEnv
*env
, jclass klass
,
1111 jmethodID id
, jvalue
*args
)
1113 _Jv_JNI_CallAnyVoidMethodA
<static_type
> (env
, NULL
, klass
, id
, args
);
1116 static jobject JNICALL
1117 _Jv_JNI_NewObjectV (JNIEnv
*env
, jclass klass
,
1118 jmethodID id
, va_list args
)
1120 JvAssert (klass
&& ! klass
->isArray ());
1121 JvAssert (! strcmp (id
->name
->data
, "<init>")
1122 && id
->signature
->length
> 2
1123 && id
->signature
->data
[0] == '('
1124 && ! strcmp (&id
->signature
->data
[id
->signature
->length
- 2],
1127 return _Jv_JNI_CallAnyMethodV
<jobject
, constructor
> (env
, NULL
, klass
,
1131 static jobject JNICALL
1132 _Jv_JNI_NewObject (JNIEnv
*env
, jclass klass
, jmethodID id
, ...)
1134 JvAssert (klass
&& ! klass
->isArray ());
1135 JvAssert (! strcmp (id
->name
->data
, "<init>")
1136 && id
->signature
->length
> 2
1137 && id
->signature
->data
[0] == '('
1138 && ! strcmp (&id
->signature
->data
[id
->signature
->length
- 2],
1144 va_start (args
, id
);
1145 result
= _Jv_JNI_CallAnyMethodV
<jobject
, constructor
> (env
, NULL
, klass
,
1152 static jobject JNICALL
1153 _Jv_JNI_NewObjectA (JNIEnv
*env
, jclass klass
, jmethodID id
,
1156 JvAssert (klass
&& ! klass
->isArray ());
1157 JvAssert (! strcmp (id
->name
->data
, "<init>")
1158 && id
->signature
->length
> 2
1159 && id
->signature
->data
[0] == '('
1160 && ! strcmp (&id
->signature
->data
[id
->signature
->length
- 2],
1163 return _Jv_JNI_CallAnyMethodA
<jobject
, constructor
> (env
, NULL
, klass
,
1169 template<typename T
>
1171 _Jv_JNI_GetField (JNIEnv
*env
, jobject obj
, jfieldID field
)
1175 T
*ptr
= (T
*) ((char *) obj
+ field
->getOffset ());
1176 return wrap_value (env
, *ptr
);
1179 template<typename T
>
1181 _Jv_JNI_SetField (JNIEnv
*, jobject obj
, jfieldID field
, T value
)
1184 value
= unwrap (value
);
1187 T
*ptr
= (T
*) ((char *) obj
+ field
->getOffset ());
1191 template<jboolean is_static
>
1192 static jfieldID JNICALL
1193 _Jv_JNI_GetAnyFieldID (JNIEnv
*env
, jclass clazz
,
1194 const char *name
, const char *sig
)
1198 clazz
= unwrap (clazz
);
1200 _Jv_InitClass (clazz
);
1202 _Jv_Utf8Const
*a_name
= _Jv_makeUtf8Const ((char *) name
, -1);
1204 // FIXME: assume that SIG isn't too long.
1205 int len
= strlen (sig
);
1207 for (int i
= 0; i
<= len
; ++i
)
1208 s
[i
] = (sig
[i
] == '/') ? '.' : sig
[i
];
1209 java::lang::ClassLoader
*loader
= clazz
->getClassLoaderInternal ();
1210 jclass field_class
= _Jv_FindClassFromSignature ((char *) s
, loader
);
1212 throw new java::lang::ClassNotFoundException(JvNewStringUTF(s
));
1214 while (clazz
!= NULL
)
1216 // We acquire the class lock so that fields aren't resolved
1217 // while we are running.
1218 JvSynchronize
sync (clazz
);
1220 jint count
= (is_static
1221 ? JvNumStaticFields (clazz
)
1222 : JvNumInstanceFields (clazz
));
1223 jfieldID field
= (is_static
1224 ? JvGetFirstStaticField (clazz
)
1225 : JvGetFirstInstanceField (clazz
));
1226 for (jint i
= 0; i
< count
; ++i
)
1228 _Jv_Utf8Const
*f_name
= field
->getNameUtf8Const(clazz
);
1230 // The field might be resolved or it might not be. It
1231 // is much simpler to always resolve it.
1232 _Jv_Linker::resolve_field (field
, loader
);
1233 if (_Jv_equalUtf8Consts (f_name
, a_name
)
1234 && field
->getClass() == field_class
)
1237 field
= field
->getNextField ();
1240 clazz
= clazz
->getSuperclass ();
1243 env
->ex
= new java::lang::NoSuchFieldError ();
1245 catch (jthrowable t
)
1252 template<typename T
>
1254 _Jv_JNI_GetStaticField (JNIEnv
*env
, jclass
, jfieldID field
)
1256 T
*ptr
= (T
*) field
->u
.addr
;
1257 return wrap_value (env
, *ptr
);
1260 template<typename T
>
1262 _Jv_JNI_SetStaticField (JNIEnv
*, jclass
, jfieldID field
, T value
)
1264 value
= unwrap (value
);
1265 T
*ptr
= (T
*) field
->u
.addr
;
1269 static jstring JNICALL
1270 _Jv_JNI_NewString (JNIEnv
*env
, const jchar
*unichars
, jsize len
)
1274 jstring r
= _Jv_NewString (unichars
, len
);
1275 return (jstring
) wrap_value (env
, r
);
1277 catch (jthrowable t
)
1284 static jsize JNICALL
1285 _Jv_JNI_GetStringLength (JNIEnv
*, jstring string
)
1287 return unwrap (string
)->length();
1290 static const jchar
* JNICALL
1291 _Jv_JNI_GetStringChars (JNIEnv
*, jstring string
, jboolean
*isCopy
)
1293 string
= unwrap (string
);
1294 jchar
*result
= _Jv_GetStringChars (string
);
1295 mark_for_gc (string
, global_ref_table
);
1298 return (const jchar
*) result
;
1302 _Jv_JNI_ReleaseStringChars (JNIEnv
*, jstring string
, const jchar
*)
1304 unmark_for_gc (unwrap (string
), global_ref_table
);
1307 static jstring JNICALL
1308 _Jv_JNI_NewStringUTF (JNIEnv
*env
, const char *bytes
)
1312 jstring result
= JvNewStringUTF (bytes
);
1313 return (jstring
) wrap_value (env
, result
);
1315 catch (jthrowable t
)
1322 static jsize JNICALL
1323 _Jv_JNI_GetStringUTFLength (JNIEnv
*, jstring string
)
1325 return JvGetStringUTFLength (unwrap (string
));
1328 static const char * JNICALL
1329 _Jv_JNI_GetStringUTFChars (JNIEnv
*env
, jstring string
,
1334 string
= unwrap (string
);
1337 jsize len
= JvGetStringUTFLength (string
);
1338 char *r
= (char *) _Jv_Malloc (len
+ 1);
1339 JvGetStringUTFRegion (string
, 0, string
->length(), r
);
1345 return (const char *) r
;
1347 catch (jthrowable t
)
1355 _Jv_JNI_ReleaseStringUTFChars (JNIEnv
*, jstring
, const char *utf
)
1357 _Jv_Free ((void *) utf
);
1361 _Jv_JNI_GetStringRegion (JNIEnv
*env
, jstring string
, jsize start
,
1362 jsize len
, jchar
*buf
)
1364 string
= unwrap (string
);
1365 jchar
*result
= _Jv_GetStringChars (string
);
1366 if (start
< 0 || start
> string
->length ()
1367 || len
< 0 || start
+ len
> string
->length ())
1371 env
->ex
= new java::lang::StringIndexOutOfBoundsException ();
1373 catch (jthrowable t
)
1379 memcpy (buf
, &result
[start
], len
* sizeof (jchar
));
1383 _Jv_JNI_GetStringUTFRegion (JNIEnv
*env
, jstring str
, jsize start
,
1384 jsize len
, char *buf
)
1388 if (start
< 0 || start
> str
->length ()
1389 || len
< 0 || start
+ len
> str
->length ())
1393 env
->ex
= new java::lang::StringIndexOutOfBoundsException ();
1395 catch (jthrowable t
)
1401 _Jv_GetStringUTFRegion (str
, start
, len
, buf
);
1404 static const jchar
* JNICALL
1405 _Jv_JNI_GetStringCritical (JNIEnv
*, jstring str
, jboolean
*isCopy
)
1407 jchar
*result
= _Jv_GetStringChars (unwrap (str
));
1414 _Jv_JNI_ReleaseStringCritical (JNIEnv
*, jstring
, const jchar
*)
1419 static jsize JNICALL
1420 _Jv_JNI_GetArrayLength (JNIEnv
*, jarray array
)
1422 return unwrap (array
)->length
;
1425 static jobjectArray JNICALL
1426 _Jv_JNI_NewObjectArray (JNIEnv
*env
, jsize length
,
1427 jclass elementClass
, jobject init
)
1431 elementClass
= unwrap (elementClass
);
1432 init
= unwrap (init
);
1434 _Jv_CheckCast (elementClass
, init
);
1435 jarray result
= JvNewObjectArray (length
, elementClass
, init
);
1436 return (jobjectArray
) wrap_value (env
, result
);
1438 catch (jthrowable t
)
1445 static jobject JNICALL
1446 _Jv_JNI_GetObjectArrayElement (JNIEnv
*env
, jobjectArray array
,
1449 if ((unsigned) index
>= (unsigned) array
->length
)
1450 _Jv_ThrowBadArrayIndex (index
);
1451 jobject
*elts
= elements (unwrap (array
));
1452 return wrap_value (env
, elts
[index
]);
1456 _Jv_JNI_SetObjectArrayElement (JNIEnv
*env
, jobjectArray array
,
1457 jsize index
, jobject value
)
1461 array
= unwrap (array
);
1462 value
= unwrap (value
);
1464 _Jv_CheckArrayStore (array
, value
);
1465 if ((unsigned) index
>= (unsigned) array
->length
)
1466 _Jv_ThrowBadArrayIndex (index
);
1467 jobject
*elts
= elements (array
);
1468 elts
[index
] = value
;
1470 catch (jthrowable t
)
1476 template<typename T
, jclass K
>
1477 static JArray
<T
> * JNICALL
1478 _Jv_JNI_NewPrimitiveArray (JNIEnv
*env
, jsize length
)
1482 return (JArray
<T
> *) wrap_value (env
, _Jv_NewPrimArray (K
, length
));
1484 catch (jthrowable t
)
1491 template<typename T
, jclass K
>
1493 _Jv_JNI_GetPrimitiveArrayElements (JNIEnv
*env
, JArray
<T
> *array
,
1496 array
= unwrap (array
);
1497 if (! _Jv_JNI_check_types (env
, array
, K
))
1499 T
*elts
= elements (array
);
1502 // We elect never to copy.
1505 mark_for_gc (array
, global_ref_table
);
1509 template<typename T
, jclass K
>
1511 _Jv_JNI_ReleasePrimitiveArrayElements (JNIEnv
*env
, JArray
<T
> *array
,
1512 T
*, jint
/* mode */)
1514 array
= unwrap (array
);
1515 _Jv_JNI_check_types (env
, array
, K
);
1516 // Note that we ignore MODE. We can do this because we never copy
1517 // the array elements. My reading of the JNI documentation is that
1518 // this is an option for the implementor.
1519 unmark_for_gc (array
, global_ref_table
);
1522 template<typename T
, jclass K
>
1524 _Jv_JNI_GetPrimitiveArrayRegion (JNIEnv
*env
, JArray
<T
> *array
,
1525 jsize start
, jsize len
,
1528 array
= unwrap (array
);
1529 if (! _Jv_JNI_check_types (env
, array
, K
))
1532 // The cast to unsigned lets us save a comparison.
1533 if (start
< 0 || len
< 0
1534 || (unsigned long) (start
+ len
) > (unsigned long) array
->length
)
1539 env
->ex
= new java::lang::ArrayIndexOutOfBoundsException ();
1541 catch (jthrowable t
)
1543 // Could have thown out of memory error.
1549 T
*elts
= elements (array
) + start
;
1550 memcpy (buf
, elts
, len
* sizeof (T
));
1554 template<typename T
, jclass K
>
1556 _Jv_JNI_SetPrimitiveArrayRegion (JNIEnv
*env
, JArray
<T
> *array
,
1557 jsize start
, jsize len
, T
*buf
)
1559 array
= unwrap (array
);
1560 if (! _Jv_JNI_check_types (env
, array
, K
))
1563 // The cast to unsigned lets us save a comparison.
1564 if (start
< 0 || len
< 0
1565 || (unsigned long) (start
+ len
) > (unsigned long) array
->length
)
1570 env
->ex
= new java::lang::ArrayIndexOutOfBoundsException ();
1572 catch (jthrowable t
)
1579 T
*elts
= elements (array
) + start
;
1580 memcpy (elts
, buf
, len
* sizeof (T
));
1584 static void * JNICALL
1585 _Jv_JNI_GetPrimitiveArrayCritical (JNIEnv
*, jarray array
,
1588 array
= unwrap (array
);
1589 // FIXME: does this work?
1590 jclass klass
= array
->getClass()->getComponentType();
1591 JvAssert (klass
->isPrimitive ());
1592 char *r
= _Jv_GetArrayElementFromElementType (array
, klass
);
1599 _Jv_JNI_ReleasePrimitiveArrayCritical (JNIEnv
*, jarray
, void *, jint
)
1605 _Jv_JNI_MonitorEnter (JNIEnv
*env
, jobject obj
)
1609 _Jv_MonitorEnter (unwrap (obj
));
1612 catch (jthrowable t
)
1620 _Jv_JNI_MonitorExit (JNIEnv
*env
, jobject obj
)
1624 _Jv_MonitorExit (unwrap (obj
));
1627 catch (jthrowable t
)
1636 _Jv_JNI_ToReflectedField (JNIEnv
*env
, jclass cls
, jfieldID fieldID
,
1642 java::lang::reflect::Field
*field
= new java::lang::reflect::Field();
1643 field
->declaringClass
= cls
;
1644 field
->offset
= (char*) fieldID
- (char *) cls
->fields
;
1645 field
->name
= _Jv_NewStringUtf8Const (fieldID
->getNameUtf8Const (cls
));
1646 return wrap_value (env
, field
);
1648 catch (jthrowable t
)
1656 static jfieldID JNICALL
1657 _Jv_JNI_FromReflectedField (JNIEnv
*, jobject f
)
1659 using namespace java::lang::reflect
;
1662 Field
*field
= reinterpret_cast<Field
*> (f
);
1663 return _Jv_FromReflectedField (field
);
1667 _Jv_JNI_ToReflectedMethod (JNIEnv
*env
, jclass klass
, jmethodID id
,
1670 using namespace java::lang::reflect
;
1672 jobject result
= NULL
;
1673 klass
= unwrap (klass
);
1677 if (_Jv_equalUtf8Consts (id
->name
, init_name
))
1680 Constructor
*cons
= new Constructor ();
1681 cons
->offset
= (char *) id
- (char *) &klass
->methods
;
1682 cons
->declaringClass
= klass
;
1687 Method
*meth
= new Method ();
1688 meth
->offset
= (char *) id
- (char *) &klass
->methods
;
1689 meth
->declaringClass
= klass
;
1693 catch (jthrowable t
)
1698 return wrap_value (env
, result
);
1701 static jmethodID JNICALL
1702 _Jv_JNI_FromReflectedMethod (JNIEnv
*, jobject method
)
1704 using namespace java::lang::reflect
;
1705 method
= unwrap (method
);
1706 if (Method::class$
.isInstance (method
))
1707 return _Jv_FromReflectedMethod (reinterpret_cast<Method
*> (method
));
1709 _Jv_FromReflectedConstructor (reinterpret_cast<Constructor
*> (method
));
1714 _Jv_JNI_NewWeakGlobalRef (JNIEnv
*env
, jobject obj
)
1716 using namespace gnu::gcj::runtime
;
1717 JNIWeakRef
*ref
= NULL
;
1721 // This seems weird but I think it is correct.
1723 ref
= new JNIWeakRef (obj
);
1724 mark_for_gc (ref
, global_ref_table
);
1726 catch (jthrowable t
)
1731 return reinterpret_cast<jweak
> (ref
);
1735 _Jv_JNI_DeleteWeakGlobalRef (JNIEnv
*, jweak obj
)
1737 using namespace gnu::gcj::runtime
;
1738 JNIWeakRef
*ref
= reinterpret_cast<JNIWeakRef
*> (obj
);
1739 unmark_for_gc (ref
, global_ref_table
);
1745 // Direct byte buffers.
1747 static jobject JNICALL
1748 _Jv_JNI_NewDirectByteBuffer (JNIEnv
*, void *address
, jlong length
)
1750 using namespace gnu::gcj
;
1751 using namespace java::nio
;
1752 return new DirectByteBufferImpl$ReadWrite
1753 (reinterpret_cast<RawData
*> (address
), length
);
1756 static void * JNICALL
1757 _Jv_JNI_GetDirectBufferAddress (JNIEnv
*, jobject buffer
)
1759 using namespace java::nio
;
1760 if (! _Jv_IsInstanceOf (buffer
, &Buffer::class$
))
1762 Buffer
*tmp
= static_cast<Buffer
*> (buffer
);
1763 return reinterpret_cast<void *> (tmp
->address
);
1766 static jlong JNICALL
1767 _Jv_JNI_GetDirectBufferCapacity (JNIEnv
*, jobject buffer
)
1769 using namespace java::nio
;
1770 if (! _Jv_IsInstanceOf (buffer
, &Buffer::class$
))
1772 Buffer
*tmp
= static_cast<Buffer
*> (buffer
);
1773 if (tmp
->address
== NULL
)
1775 return tmp
->capacity();
1780 // Hash table of native methods.
1781 static JNINativeMethod
*nathash
;
1782 // Number of slots used.
1783 static int nathash_count
= 0;
1784 // Number of slots available. Must be power of 2.
1785 static int nathash_size
= 0;
1787 #define DELETED_ENTRY ((char *) (~0))
1789 // Compute a hash value for a native method descriptor.
1791 hash (const JNINativeMethod
*method
)
1798 hash
= (31 * hash
) + *ptr
++;
1800 ptr
= method
->signature
;
1802 hash
= (31 * hash
) + *ptr
++;
1807 // Find the slot where a native method goes.
1808 static JNINativeMethod
*
1809 nathash_find_slot (const JNINativeMethod
*method
)
1811 jint h
= hash (method
);
1812 int step
= (h
^ (h
>> 16)) | 1;
1813 int w
= h
& (nathash_size
- 1);
1818 JNINativeMethod
*slotp
= &nathash
[w
];
1819 if (slotp
->name
== NULL
)
1822 return &nathash
[del
];
1826 else if (slotp
->name
== DELETED_ENTRY
)
1828 else if (! strcmp (slotp
->name
, method
->name
)
1829 && ! strcmp (slotp
->signature
, method
->signature
))
1831 w
= (w
+ step
) & (nathash_size
- 1);
1835 // Find a method. Return NULL if it isn't in the hash table.
1837 nathash_find (JNINativeMethod
*method
)
1839 if (nathash
== NULL
)
1841 JNINativeMethod
*slot
= nathash_find_slot (method
);
1842 if (slot
->name
== NULL
|| slot
->name
== DELETED_ENTRY
)
1850 if (nathash
== NULL
)
1852 nathash_size
= 1024;
1854 (JNINativeMethod
*) _Jv_AllocBytes (nathash_size
1855 * sizeof (JNINativeMethod
));
1856 memset (nathash
, 0, nathash_size
* sizeof (JNINativeMethod
));
1860 int savesize
= nathash_size
;
1861 JNINativeMethod
*savehash
= nathash
;
1864 (JNINativeMethod
*) _Jv_AllocBytes (nathash_size
1865 * sizeof (JNINativeMethod
));
1866 memset (nathash
, 0, nathash_size
* sizeof (JNINativeMethod
));
1868 for (int i
= 0; i
< savesize
; ++i
)
1870 if (savehash
[i
].name
!= NULL
&& savehash
[i
].name
!= DELETED_ENTRY
)
1872 JNINativeMethod
*slot
= nathash_find_slot (&savehash
[i
]);
1873 *slot
= savehash
[i
];
1880 nathash_add (const JNINativeMethod
*method
)
1882 if (3 * nathash_count
>= 2 * nathash_size
)
1884 JNINativeMethod
*slot
= nathash_find_slot (method
);
1885 // If the slot has a real entry in it, then there is no work to do.
1886 if (slot
->name
!= NULL
&& slot
->name
!= DELETED_ENTRY
)
1889 slot
->name
= strdup (method
->name
);
1890 // This was already strduped in _Jv_JNI_RegisterNatives.
1891 slot
->signature
= method
->signature
;
1892 slot
->fnPtr
= method
->fnPtr
;
1896 _Jv_JNI_RegisterNatives (JNIEnv
*env
, jclass klass
,
1897 const JNINativeMethod
*methods
,
1900 // Synchronize while we do the work. This must match
1901 // synchronization in some other functions that manipulate or use
1902 // the nathash table.
1903 JvSynchronize
sync (global_ref_table
);
1905 JNINativeMethod dottedMethod
;
1907 // Look at each descriptor given us, and find the corresponding
1908 // method in the class.
1909 for (int j
= 0; j
< nMethods
; ++j
)
1913 _Jv_Method
*imeths
= JvGetFirstMethod (klass
);
1914 for (int i
= 0; i
< JvNumMethods (klass
); ++i
)
1916 _Jv_Method
*self
= &imeths
[i
];
1918 // Copy this JNINativeMethod and do a slash to dot
1919 // conversion on the signature.
1920 dottedMethod
.name
= methods
[j
].name
;
1921 dottedMethod
.signature
= strdup (methods
[j
].signature
);
1922 dottedMethod
.fnPtr
= methods
[j
].fnPtr
;
1923 char *c
= dottedMethod
.signature
;
1931 if (! strcmp (self
->name
->chars (), dottedMethod
.name
)
1932 && ! strcmp (self
->signature
->chars (), dottedMethod
.signature
))
1934 if (! (self
->accflags
& java::lang::reflect::Modifier::NATIVE
))
1937 // Found a match that is native.
1939 nathash_add (&dottedMethod
);
1947 jstring m
= JvNewStringUTF (methods
[j
].name
);
1950 env
->ex
= new java::lang::NoSuchMethodError (m
);
1952 catch (jthrowable t
)
1964 _Jv_JNI_UnregisterNatives (JNIEnv
*, jclass
)
1966 // FIXME -- we could implement this.
1972 // Add a character to the buffer, encoding properly.
1974 add_char (char *buf
, jchar c
, int *here
)
1978 buf
[(*here
)++] = '_';
1979 buf
[(*here
)++] = '1';
1983 buf
[(*here
)++] = '_';
1984 buf
[(*here
)++] = '2';
1988 buf
[(*here
)++] = '_';
1989 buf
[(*here
)++] = '3';
1992 // Also check for `.' here because we might be passed an internal
1993 // qualified class name like `foo.bar'.
1994 else if (c
== '/' || c
== '.')
1995 buf
[(*here
)++] = '_';
1996 else if ((c
>= '0' && c
<= '9')
1997 || (c
>= 'a' && c
<= 'z')
1998 || (c
>= 'A' && c
<= 'Z'))
1999 buf
[(*here
)++] = (char) c
;
2002 // "Unicode" character.
2003 buf
[(*here
)++] = '_';
2004 buf
[(*here
)++] = '0';
2005 for (int i
= 0; i
< 4; ++i
)
2008 buf
[(*here
) + 3 - i
] = (val
> 10) ? ('a' + val
- 10) : ('0' + val
);
2015 // Compute a mangled name for a native function. This computes the
2016 // long name, and also returns an index which indicates where a NUL
2017 // can be placed to create the short name. This function assumes that
2018 // the buffer is large enough for its results.
2020 mangled_name (jclass klass
, _Jv_Utf8Const
*func_name
,
2021 _Jv_Utf8Const
*signature
, char *buf
, int *long_start
)
2023 strcpy (buf
, "Java_");
2026 // Add fully qualified class name.
2027 jchar
*chars
= _Jv_GetStringChars (klass
->getName ());
2028 jint len
= klass
->getName ()->length ();
2029 for (int i
= 0; i
< len
; ++i
)
2030 add_char (buf
, chars
[i
], &here
);
2032 // Don't use add_char because we need a literal `_'.
2035 const unsigned char *fn
= (const unsigned char *) func_name
->chars ();
2036 const unsigned char *limit
= fn
+ func_name
->len ();
2037 for (int i
= 0; ; ++i
)
2039 int ch
= UTF8_GET (fn
, limit
);
2042 add_char (buf
, ch
, &here
);
2045 // This is where the long signature begins.
2050 const unsigned char *sig
= (const unsigned char *) signature
->chars ();
2051 limit
= sig
+ signature
->len ();
2052 JvAssert (sig
[0] == '(');
2056 int ch
= UTF8_GET (sig
, limit
);
2057 if (ch
== ')' || ch
< 0)
2059 add_char (buf
, ch
, &here
);
2065 // Return the current thread's JNIEnv; if one does not exist, create
2066 // it. Also create a new system frame for use. This is `extern "C"'
2067 // because the compiler calls it.
2069 _Jv_GetJNIEnvNewFrame (jclass klass
)
2071 JNIEnv
*env
= _Jv_GetCurrentJNIEnv ();
2072 if (__builtin_expect (env
== NULL
, false))
2074 env
= (JNIEnv
*) _Jv_MallocUnchecked (sizeof (JNIEnv
));
2075 env
->p
= &_Jv_JNIFunctions
;
2078 // We set env->ex below.
2080 // Set up the bottom, reusable frame.
2081 env
->bottom_locals
= (_Jv_JNI_LocalFrame
*)
2082 _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame
)
2084 * sizeof (jobject
)));
2086 env
->bottom_locals
->marker
= MARK_SYSTEM
;
2087 env
->bottom_locals
->size
= FRAME_SIZE
;
2088 env
->bottom_locals
->next
= NULL
;
2089 env
->bottom_locals
->allocated_p
= 0;
2090 memset (&env
->bottom_locals
->vec
[0], 0,
2091 env
->bottom_locals
->size
* sizeof (jobject
));
2093 _Jv_SetCurrentJNIEnv (env
);
2096 // If we're in a simple JNI call (non-nested), we can just reuse the
2097 // locals frame we allocated many calls ago, back when the env was first
2100 if (__builtin_expect (env
->locals
== NULL
, true))
2101 env
->locals
= env
->bottom_locals
;
2105 // Alternatively, we might be re-entering JNI, in which case we can't
2106 // reuse the bottom_locals frame, because it is already underneath
2107 // us. So we need to make a new one.
2109 _Jv_JNI_LocalFrame
*frame
2110 = (_Jv_JNI_LocalFrame
*) _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame
)
2112 * sizeof (jobject
)));
2114 frame
->marker
= MARK_SYSTEM
;
2115 frame
->size
= FRAME_SIZE
;
2116 frame
->allocated_p
= 0;
2117 frame
->next
= env
->locals
;
2119 memset (&frame
->vec
[0], 0,
2120 frame
->size
* sizeof (jobject
));
2122 env
->locals
= frame
;
2130 // Destroy the env's reusable resources. This is called from the thread
2131 // destructor "finalize_native" in natThread.cc
2133 _Jv_FreeJNIEnv (_Jv_JNIEnv
*env
)
2138 if (env
->bottom_locals
!= NULL
)
2139 _Jv_Free (env
->bottom_locals
);
2144 // Return the function which implements a particular JNI method. If
2145 // we can't find the function, we throw the appropriate exception.
2146 // This is `extern "C"' because the compiler uses it.
2148 _Jv_LookupJNIMethod (jclass klass
, _Jv_Utf8Const
*name
,
2149 _Jv_Utf8Const
*signature
, MAYBE_UNUSED
int args_size
)
2151 int name_length
= name
->len();
2152 int sig_length
= signature
->len();
2153 char buf
[10 + 6 * (name_length
+ sig_length
) + 12];
2157 // Synchronize on something convenient. Right now we use the hash.
2158 JvSynchronize
sync (global_ref_table
);
2160 // First see if we have an override in the hash table.
2161 strncpy (buf
, name
->chars (), name_length
);
2162 buf
[name_length
] = '\0';
2163 strncpy (buf
+ name_length
+ 1, signature
->chars (), sig_length
);
2164 buf
[name_length
+ sig_length
+ 1] = '\0';
2165 JNINativeMethod meth
;
2167 meth
.signature
= buf
+ name_length
+ 1;
2168 function
= nathash_find (&meth
);
2169 if (function
!= NULL
)
2172 // If there was no override, then look in the symbol table.
2174 mangled_name (klass
, name
, signature
, buf
+ 1, &long_start
);
2175 char c
= buf
[long_start
+ 1];
2176 buf
[long_start
+ 1] = '\0';
2178 function
= _Jv_FindSymbolInExecutable (buf
+ 1);
2180 // On Win32, we use the "stdcall" calling convention (see JNICALL
2183 // For a function named 'fooBar' that takes 'nn' bytes as arguments,
2184 // by default, MinGW GCC exports it as 'fooBar@nn', MSVC exports it
2185 // as '_fooBar@nn' and Borland C exports it as 'fooBar'. We try to
2186 // take care of all these variations here.
2188 char asz_buf
[12]; /* '@' + '2147483647' (32-bit INT_MAX) + '\0' */
2189 char long_nm_sv
[11]; /* Ditto, except for the '\0'. */
2191 if (function
== NULL
)
2193 // We have tried searching for the 'fooBar' form (BCC) - now
2196 // First, save the part of the long name that will be damaged
2197 // by appending '@nn'.
2198 memcpy (long_nm_sv
, (buf
+ long_start
+ 1 + 1), sizeof (long_nm_sv
));
2200 sprintf (asz_buf
, "@%d", args_size
);
2201 strcat (buf
, asz_buf
);
2203 // Search for the '_fooBar@nn' form (MSVC).
2204 function
= _Jv_FindSymbolInExecutable (buf
);
2206 if (function
== NULL
)
2208 // Search for the 'fooBar@nn' form (MinGW GCC).
2209 function
= _Jv_FindSymbolInExecutable (buf
+ 1);
2214 if (function
== NULL
)
2216 buf
[long_start
+ 1] = c
;
2218 // Restore the part of the long name that was damaged by
2219 // appending the '@nn'.
2220 memcpy ((buf
+ long_start
+ 1 + 1), long_nm_sv
, sizeof (long_nm_sv
));
2222 function
= _Jv_FindSymbolInExecutable (buf
+ 1);
2223 if (function
== NULL
)
2226 strcat (buf
, asz_buf
);
2227 function
= _Jv_FindSymbolInExecutable (buf
);
2228 if (function
== NULL
)
2229 function
= _Jv_FindSymbolInExecutable (buf
+ 1);
2231 if (function
== NULL
)
2234 jstring str
= JvNewStringUTF (name
->chars ());
2235 throw new java::lang::UnsatisfiedLinkError (str
);
2245 // This function is the stub which is used to turn an ordinary (CNI)
2246 // method call into a JNI call.
2248 _Jv_JNIMethod::call (ffi_cif
*, void *ret
, ffi_raw
*args
, void *__this
)
2250 _Jv_JNIMethod
* _this
= (_Jv_JNIMethod
*) __this
;
2252 JNIEnv
*env
= _Jv_GetJNIEnvNewFrame (_this
->defining_class
);
2254 // FIXME: we should mark every reference parameter as a local. For
2255 // now we assume a conservative GC, and we assume that the
2256 // references are on the stack somewhere.
2258 // We cache the value that we find, of course, but if we don't find
2259 // a value we don't cache that fact -- we might subsequently load a
2260 // library which finds the function in question.
2262 // Synchronize on a convenient object to ensure sanity in case two
2263 // threads reach this point for the same function at the same
2265 JvSynchronize
sync (global_ref_table
);
2266 if (_this
->function
== NULL
)
2268 int args_size
= sizeof (JNIEnv
*) + _this
->args_raw_size
;
2270 if (_this
->self
->accflags
& java::lang::reflect::Modifier::STATIC
)
2271 args_size
+= sizeof (_this
->defining_class
);
2273 _this
->function
= _Jv_LookupJNIMethod (_this
->defining_class
,
2275 _this
->self
->signature
,
2280 JvAssert (_this
->args_raw_size
% sizeof (ffi_raw
) == 0);
2281 ffi_raw real_args
[2 + _this
->args_raw_size
/ sizeof (ffi_raw
)];
2284 // First argument is always the environment pointer.
2285 real_args
[offset
++].ptr
= env
;
2287 // For a static method, we pass in the Class. For non-static
2288 // methods, the `this' argument is already handled.
2289 if ((_this
->self
->accflags
& java::lang::reflect::Modifier::STATIC
))
2290 real_args
[offset
++].ptr
= _this
->defining_class
;
2292 // In libgcj, the callee synchronizes.
2293 jobject sync
= NULL
;
2294 if ((_this
->self
->accflags
& java::lang::reflect::Modifier::SYNCHRONIZED
))
2296 if ((_this
->self
->accflags
& java::lang::reflect::Modifier::STATIC
))
2297 sync
= _this
->defining_class
;
2299 sync
= (jobject
) args
[0].ptr
;
2300 _Jv_MonitorEnter (sync
);
2303 // Copy over passed-in arguments.
2304 memcpy (&real_args
[offset
], args
, _this
->args_raw_size
);
2306 // The actual call to the JNI function.
2307 #if FFI_NATIVE_RAW_API
2308 ffi_raw_call (&_this
->jni_cif
, (void (*)()) _this
->function
,
2311 ffi_java_raw_call (&_this
->jni_cif
, (void (*)()) _this
->function
,
2315 // We might need to unwrap a JNI weak reference here.
2316 if (_this
->jni_cif
.rtype
== &ffi_type_pointer
)
2318 _Jv_value
*val
= (_Jv_value
*) ret
;
2319 val
->object_value
= unwrap (val
->object_value
);
2323 _Jv_MonitorExit (sync
);
2325 _Jv_JNI_PopSystemFrame (env
);
2328 #endif /* INTERPRETER */
2336 // An internal helper function.
2338 _Jv_JNI_AttachCurrentThread (JavaVM
*, jstring name
, void **penv
,
2339 void *args
, jboolean is_daemon
)
2341 JavaVMAttachArgs
*attach
= reinterpret_cast<JavaVMAttachArgs
*> (args
);
2342 java::lang::ThreadGroup
*group
= NULL
;
2346 // FIXME: do we really want to support 1.1?
2347 if (attach
->version
!= JNI_VERSION_1_4
2348 && attach
->version
!= JNI_VERSION_1_2
2349 && attach
->version
!= JNI_VERSION_1_1
)
2350 return JNI_EVERSION
;
2352 JvAssert (java::lang::ThreadGroup::class$
.isInstance (attach
->group
));
2353 group
= reinterpret_cast<java::lang::ThreadGroup
*> (attach
->group
);
2356 // Attaching an already-attached thread is a no-op.
2357 if (_Jv_GetCurrentJNIEnv () != NULL
)
2360 JNIEnv
*env
= (JNIEnv
*) _Jv_MallocUnchecked (sizeof (JNIEnv
));
2363 env
->p
= &_Jv_JNIFunctions
;
2367 = (_Jv_JNI_LocalFrame
*) _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame
)
2369 * sizeof (jobject
)));
2370 env
->locals
= env
->bottom_locals
;
2371 if (env
->locals
== NULL
)
2377 env
->locals
->allocated_p
= 0;
2378 env
->locals
->marker
= MARK_SYSTEM
;
2379 env
->locals
->size
= FRAME_SIZE
;
2380 env
->locals
->next
= NULL
;
2382 for (int i
= 0; i
< env
->locals
->size
; ++i
)
2383 env
->locals
->vec
[i
] = NULL
;
2385 *penv
= reinterpret_cast<void *> (env
);
2387 // This thread might already be a Java thread -- this function might
2388 // have been called simply to set the new JNIEnv.
2389 if (_Jv_ThreadCurrent () == NULL
)
2394 _Jv_AttachCurrentThreadAsDaemon (name
, group
);
2396 _Jv_AttachCurrentThread (name
, group
);
2398 catch (jthrowable t
)
2403 _Jv_SetCurrentJNIEnv (env
);
2408 // This is the one actually used by JNI.
2410 _Jv_JNI_AttachCurrentThread (JavaVM
*vm
, void **penv
, void *args
)
2412 return _Jv_JNI_AttachCurrentThread (vm
, NULL
, penv
, args
, false);
2416 _Jv_JNI_AttachCurrentThreadAsDaemon (JavaVM
*vm
, void **penv
,
2419 return _Jv_JNI_AttachCurrentThread (vm
, NULL
, penv
, args
, true);
2423 _Jv_JNI_DestroyJavaVM (JavaVM
*vm
)
2425 JvAssert (the_vm
&& vm
== the_vm
);
2428 if (_Jv_ThreadCurrent () != NULL
)
2434 main_name
= JvNewStringLatin1 ("main");
2436 catch (jthrowable t
)
2441 jint r
= _Jv_JNI_AttachCurrentThread (vm
, main_name
,
2442 reinterpret_cast<void **> (&env
),
2448 env
= _Jv_GetCurrentJNIEnv ();
2452 // Docs say that this always returns an error code.
2457 _Jv_JNI_DetachCurrentThread (JavaVM
*)
2459 jint code
= _Jv_DetachCurrentThread ();
2460 return code
? JNI_EDETACHED
: 0;
2464 _Jv_JNI_GetEnv (JavaVM
*, void **penv
, jint version
)
2466 if (_Jv_ThreadCurrent () == NULL
)
2469 return JNI_EDETACHED
;
2473 // Handle JVMPI requests.
2474 if (version
== JVMPI_VERSION_1
)
2476 *penv
= (void *) &_Jv_JVMPI_Interface
;
2481 // FIXME: do we really want to support 1.1?
2482 if (version
!= JNI_VERSION_1_4
&& version
!= JNI_VERSION_1_2
2483 && version
!= JNI_VERSION_1_1
)
2486 return JNI_EVERSION
;
2489 *penv
= (void *) _Jv_GetCurrentJNIEnv ();
2494 JNI_GetDefaultJavaVMInitArgs (void *args
)
2496 jint version
= * (jint
*) args
;
2497 // Here we only support 1.2 and 1.4.
2498 if (version
!= JNI_VERSION_1_2
&& version
!= JNI_VERSION_1_4
)
2499 return JNI_EVERSION
;
2501 JavaVMInitArgs
*ia
= reinterpret_cast<JavaVMInitArgs
*> (args
);
2502 ia
->version
= JNI_VERSION_1_4
;
2505 ia
->ignoreUnrecognized
= true;
2511 JNI_CreateJavaVM (JavaVM
**vm
, void **penv
, void *args
)
2513 JvAssert (! the_vm
);
2515 jint version
= * (jint
*) args
;
2516 // We only support 1.2 and 1.4.
2517 if (version
!= JNI_VERSION_1_2
&& version
!= JNI_VERSION_1_4
)
2518 return JNI_EVERSION
;
2520 JvVMInitArgs
* vm_args
= reinterpret_cast<JvVMInitArgs
*> (args
);
2522 jint result
= _Jv_CreateJavaVM (vm_args
);
2526 // FIXME: synchronize
2527 JavaVM
*nvm
= (JavaVM
*) _Jv_MallocUnchecked (sizeof (JavaVM
));
2530 nvm
->functions
= &_Jv_JNI_InvokeFunctions
;
2532 jint r
=_Jv_JNI_AttachCurrentThread (nvm
, penv
, NULL
);
2543 JNI_GetCreatedJavaVMs (JavaVM
**vm_buffer
, jsize buf_len
, jsize
*n_vms
)
2548 // We only support a single VM.
2551 vm_buffer
[0] = the_vm
;
2562 // FIXME: synchronize
2565 JavaVM
*nvm
= (JavaVM
*) _Jv_MallocUnchecked (sizeof (JavaVM
));
2567 nvm
->functions
= &_Jv_JNI_InvokeFunctions
;
2571 // If this is a Java thread, we want to make sure it has an
2572 // associated JNIEnv.
2573 if (_Jv_ThreadCurrent () != NULL
)
2576 _Jv_JNI_AttachCurrentThread (the_vm
, &ignore
, NULL
);
2583 _Jv_JNI_GetJavaVM (JNIEnv
*, JavaVM
**vm
)
2585 *vm
= _Jv_GetJavaVM ();
2586 return *vm
== NULL
? JNI_ERR
: JNI_OK
;
2591 #define RESERVED NULL
2593 struct JNINativeInterface _Jv_JNIFunctions
=
2599 _Jv_JNI_GetVersion
, // GetVersion
2600 _Jv_JNI_DefineClass
, // DefineClass
2601 _Jv_JNI_FindClass
, // FindClass
2602 _Jv_JNI_FromReflectedMethod
, // FromReflectedMethod
2603 _Jv_JNI_FromReflectedField
, // FromReflectedField
2604 _Jv_JNI_ToReflectedMethod
, // ToReflectedMethod
2605 _Jv_JNI_GetSuperclass
, // GetSuperclass
2606 _Jv_JNI_IsAssignableFrom
, // IsAssignableFrom
2607 _Jv_JNI_ToReflectedField
, // ToReflectedField
2608 _Jv_JNI_Throw
, // Throw
2609 _Jv_JNI_ThrowNew
, // ThrowNew
2610 _Jv_JNI_ExceptionOccurred
, // ExceptionOccurred
2611 _Jv_JNI_ExceptionDescribe
, // ExceptionDescribe
2612 _Jv_JNI_ExceptionClear
, // ExceptionClear
2613 _Jv_JNI_FatalError
, // FatalError
2615 _Jv_JNI_PushLocalFrame
, // PushLocalFrame
2616 _Jv_JNI_PopLocalFrame
, // PopLocalFrame
2617 _Jv_JNI_NewGlobalRef
, // NewGlobalRef
2618 _Jv_JNI_DeleteGlobalRef
, // DeleteGlobalRef
2619 _Jv_JNI_DeleteLocalRef
, // DeleteLocalRef
2621 _Jv_JNI_IsSameObject
, // IsSameObject
2623 _Jv_JNI_NewLocalRef
, // NewLocalRef
2624 _Jv_JNI_EnsureLocalCapacity
, // EnsureLocalCapacity
2626 _Jv_JNI_AllocObject
, // AllocObject
2627 _Jv_JNI_NewObject
, // NewObject
2628 _Jv_JNI_NewObjectV
, // NewObjectV
2629 _Jv_JNI_NewObjectA
, // NewObjectA
2630 _Jv_JNI_GetObjectClass
, // GetObjectClass
2631 _Jv_JNI_IsInstanceOf
, // IsInstanceOf
2632 _Jv_JNI_GetAnyMethodID
<false>, // GetMethodID
2634 _Jv_JNI_CallMethod
<jobject
>, // CallObjectMethod
2635 _Jv_JNI_CallMethodV
<jobject
>, // CallObjectMethodV
2636 _Jv_JNI_CallMethodA
<jobject
>, // CallObjectMethodA
2637 _Jv_JNI_CallMethod
<jboolean
>, // CallBooleanMethod
2638 _Jv_JNI_CallMethodV
<jboolean
>, // CallBooleanMethodV
2639 _Jv_JNI_CallMethodA
<jboolean
>, // CallBooleanMethodA
2640 _Jv_JNI_CallMethod
<jbyte
>, // CallByteMethod
2641 _Jv_JNI_CallMethodV
<jbyte
>, // CallByteMethodV
2642 _Jv_JNI_CallMethodA
<jbyte
>, // CallByteMethodA
2643 _Jv_JNI_CallMethod
<jchar
>, // CallCharMethod
2644 _Jv_JNI_CallMethodV
<jchar
>, // CallCharMethodV
2645 _Jv_JNI_CallMethodA
<jchar
>, // CallCharMethodA
2646 _Jv_JNI_CallMethod
<jshort
>, // CallShortMethod
2647 _Jv_JNI_CallMethodV
<jshort
>, // CallShortMethodV
2648 _Jv_JNI_CallMethodA
<jshort
>, // CallShortMethodA
2649 _Jv_JNI_CallMethod
<jint
>, // CallIntMethod
2650 _Jv_JNI_CallMethodV
<jint
>, // CallIntMethodV
2651 _Jv_JNI_CallMethodA
<jint
>, // CallIntMethodA
2652 _Jv_JNI_CallMethod
<jlong
>, // CallLongMethod
2653 _Jv_JNI_CallMethodV
<jlong
>, // CallLongMethodV
2654 _Jv_JNI_CallMethodA
<jlong
>, // CallLongMethodA
2655 _Jv_JNI_CallMethod
<jfloat
>, // CallFloatMethod
2656 _Jv_JNI_CallMethodV
<jfloat
>, // CallFloatMethodV
2657 _Jv_JNI_CallMethodA
<jfloat
>, // CallFloatMethodA
2658 _Jv_JNI_CallMethod
<jdouble
>, // CallDoubleMethod
2659 _Jv_JNI_CallMethodV
<jdouble
>, // CallDoubleMethodV
2660 _Jv_JNI_CallMethodA
<jdouble
>, // CallDoubleMethodA
2661 _Jv_JNI_CallVoidMethod
, // CallVoidMethod
2662 _Jv_JNI_CallVoidMethodV
, // CallVoidMethodV
2663 _Jv_JNI_CallVoidMethodA
, // CallVoidMethodA
2665 // Nonvirtual method invocation functions follow.
2666 _Jv_JNI_CallAnyMethod
<jobject
, nonvirtual
>, // CallNonvirtualObjectMethod
2667 _Jv_JNI_CallAnyMethodV
<jobject
, nonvirtual
>, // CallNonvirtualObjectMethodV
2668 _Jv_JNI_CallAnyMethodA
<jobject
, nonvirtual
>, // CallNonvirtualObjectMethodA
2669 _Jv_JNI_CallAnyMethod
<jboolean
, nonvirtual
>, // CallNonvirtualBooleanMethod
2670 _Jv_JNI_CallAnyMethodV
<jboolean
, nonvirtual
>, // CallNonvirtualBooleanMethodV
2671 _Jv_JNI_CallAnyMethodA
<jboolean
, nonvirtual
>, // CallNonvirtualBooleanMethodA
2672 _Jv_JNI_CallAnyMethod
<jbyte
, nonvirtual
>, // CallNonvirtualByteMethod
2673 _Jv_JNI_CallAnyMethodV
<jbyte
, nonvirtual
>, // CallNonvirtualByteMethodV
2674 _Jv_JNI_CallAnyMethodA
<jbyte
, nonvirtual
>, // CallNonvirtualByteMethodA
2675 _Jv_JNI_CallAnyMethod
<jchar
, nonvirtual
>, // CallNonvirtualCharMethod
2676 _Jv_JNI_CallAnyMethodV
<jchar
, nonvirtual
>, // CallNonvirtualCharMethodV
2677 _Jv_JNI_CallAnyMethodA
<jchar
, nonvirtual
>, // CallNonvirtualCharMethodA
2678 _Jv_JNI_CallAnyMethod
<jshort
, nonvirtual
>, // CallNonvirtualShortMethod
2679 _Jv_JNI_CallAnyMethodV
<jshort
, nonvirtual
>, // CallNonvirtualShortMethodV
2680 _Jv_JNI_CallAnyMethodA
<jshort
, nonvirtual
>, // CallNonvirtualShortMethodA
2681 _Jv_JNI_CallAnyMethod
<jint
, nonvirtual
>, // CallNonvirtualIntMethod
2682 _Jv_JNI_CallAnyMethodV
<jint
, nonvirtual
>, // CallNonvirtualIntMethodV
2683 _Jv_JNI_CallAnyMethodA
<jint
, nonvirtual
>, // CallNonvirtualIntMethodA
2684 _Jv_JNI_CallAnyMethod
<jlong
, nonvirtual
>, // CallNonvirtualLongMethod
2685 _Jv_JNI_CallAnyMethodV
<jlong
, nonvirtual
>, // CallNonvirtualLongMethodV
2686 _Jv_JNI_CallAnyMethodA
<jlong
, nonvirtual
>, // CallNonvirtualLongMethodA
2687 _Jv_JNI_CallAnyMethod
<jfloat
, nonvirtual
>, // CallNonvirtualFloatMethod
2688 _Jv_JNI_CallAnyMethodV
<jfloat
, nonvirtual
>, // CallNonvirtualFloatMethodV
2689 _Jv_JNI_CallAnyMethodA
<jfloat
, nonvirtual
>, // CallNonvirtualFloatMethodA
2690 _Jv_JNI_CallAnyMethod
<jdouble
, nonvirtual
>, // CallNonvirtualDoubleMethod
2691 _Jv_JNI_CallAnyMethodV
<jdouble
, nonvirtual
>, // CallNonvirtualDoubleMethodV
2692 _Jv_JNI_CallAnyMethodA
<jdouble
, nonvirtual
>, // CallNonvirtualDoubleMethodA
2693 _Jv_JNI_CallAnyVoidMethod
<nonvirtual
>, // CallNonvirtualVoidMethod
2694 _Jv_JNI_CallAnyVoidMethodV
<nonvirtual
>, // CallNonvirtualVoidMethodV
2695 _Jv_JNI_CallAnyVoidMethodA
<nonvirtual
>, // CallNonvirtualVoidMethodA
2697 _Jv_JNI_GetAnyFieldID
<false>, // GetFieldID
2698 _Jv_JNI_GetField
<jobject
>, // GetObjectField
2699 _Jv_JNI_GetField
<jboolean
>, // GetBooleanField
2700 _Jv_JNI_GetField
<jbyte
>, // GetByteField
2701 _Jv_JNI_GetField
<jchar
>, // GetCharField
2702 _Jv_JNI_GetField
<jshort
>, // GetShortField
2703 _Jv_JNI_GetField
<jint
>, // GetIntField
2704 _Jv_JNI_GetField
<jlong
>, // GetLongField
2705 _Jv_JNI_GetField
<jfloat
>, // GetFloatField
2706 _Jv_JNI_GetField
<jdouble
>, // GetDoubleField
2707 _Jv_JNI_SetField
, // SetObjectField
2708 _Jv_JNI_SetField
, // SetBooleanField
2709 _Jv_JNI_SetField
, // SetByteField
2710 _Jv_JNI_SetField
, // SetCharField
2711 _Jv_JNI_SetField
, // SetShortField
2712 _Jv_JNI_SetField
, // SetIntField
2713 _Jv_JNI_SetField
, // SetLongField
2714 _Jv_JNI_SetField
, // SetFloatField
2715 _Jv_JNI_SetField
, // SetDoubleField
2716 _Jv_JNI_GetAnyMethodID
<true>, // GetStaticMethodID
2718 _Jv_JNI_CallStaticMethod
<jobject
>, // CallStaticObjectMethod
2719 _Jv_JNI_CallStaticMethodV
<jobject
>, // CallStaticObjectMethodV
2720 _Jv_JNI_CallStaticMethodA
<jobject
>, // CallStaticObjectMethodA
2721 _Jv_JNI_CallStaticMethod
<jboolean
>, // CallStaticBooleanMethod
2722 _Jv_JNI_CallStaticMethodV
<jboolean
>, // CallStaticBooleanMethodV
2723 _Jv_JNI_CallStaticMethodA
<jboolean
>, // CallStaticBooleanMethodA
2724 _Jv_JNI_CallStaticMethod
<jbyte
>, // CallStaticByteMethod
2725 _Jv_JNI_CallStaticMethodV
<jbyte
>, // CallStaticByteMethodV
2726 _Jv_JNI_CallStaticMethodA
<jbyte
>, // CallStaticByteMethodA
2727 _Jv_JNI_CallStaticMethod
<jchar
>, // CallStaticCharMethod
2728 _Jv_JNI_CallStaticMethodV
<jchar
>, // CallStaticCharMethodV
2729 _Jv_JNI_CallStaticMethodA
<jchar
>, // CallStaticCharMethodA
2730 _Jv_JNI_CallStaticMethod
<jshort
>, // CallStaticShortMethod
2731 _Jv_JNI_CallStaticMethodV
<jshort
>, // CallStaticShortMethodV
2732 _Jv_JNI_CallStaticMethodA
<jshort
>, // CallStaticShortMethodA
2733 _Jv_JNI_CallStaticMethod
<jint
>, // CallStaticIntMethod
2734 _Jv_JNI_CallStaticMethodV
<jint
>, // CallStaticIntMethodV
2735 _Jv_JNI_CallStaticMethodA
<jint
>, // CallStaticIntMethodA
2736 _Jv_JNI_CallStaticMethod
<jlong
>, // CallStaticLongMethod
2737 _Jv_JNI_CallStaticMethodV
<jlong
>, // CallStaticLongMethodV
2738 _Jv_JNI_CallStaticMethodA
<jlong
>, // CallStaticLongMethodA
2739 _Jv_JNI_CallStaticMethod
<jfloat
>, // CallStaticFloatMethod
2740 _Jv_JNI_CallStaticMethodV
<jfloat
>, // CallStaticFloatMethodV
2741 _Jv_JNI_CallStaticMethodA
<jfloat
>, // CallStaticFloatMethodA
2742 _Jv_JNI_CallStaticMethod
<jdouble
>, // CallStaticDoubleMethod
2743 _Jv_JNI_CallStaticMethodV
<jdouble
>, // CallStaticDoubleMethodV
2744 _Jv_JNI_CallStaticMethodA
<jdouble
>, // CallStaticDoubleMethodA
2745 _Jv_JNI_CallStaticVoidMethod
, // CallStaticVoidMethod
2746 _Jv_JNI_CallStaticVoidMethodV
, // CallStaticVoidMethodV
2747 _Jv_JNI_CallStaticVoidMethodA
, // CallStaticVoidMethodA
2749 _Jv_JNI_GetAnyFieldID
<true>, // GetStaticFieldID
2750 _Jv_JNI_GetStaticField
<jobject
>, // GetStaticObjectField
2751 _Jv_JNI_GetStaticField
<jboolean
>, // GetStaticBooleanField
2752 _Jv_JNI_GetStaticField
<jbyte
>, // GetStaticByteField
2753 _Jv_JNI_GetStaticField
<jchar
>, // GetStaticCharField
2754 _Jv_JNI_GetStaticField
<jshort
>, // GetStaticShortField
2755 _Jv_JNI_GetStaticField
<jint
>, // GetStaticIntField
2756 _Jv_JNI_GetStaticField
<jlong
>, // GetStaticLongField
2757 _Jv_JNI_GetStaticField
<jfloat
>, // GetStaticFloatField
2758 _Jv_JNI_GetStaticField
<jdouble
>, // GetStaticDoubleField
2759 _Jv_JNI_SetStaticField
, // SetStaticObjectField
2760 _Jv_JNI_SetStaticField
, // SetStaticBooleanField
2761 _Jv_JNI_SetStaticField
, // SetStaticByteField
2762 _Jv_JNI_SetStaticField
, // SetStaticCharField
2763 _Jv_JNI_SetStaticField
, // SetStaticShortField
2764 _Jv_JNI_SetStaticField
, // SetStaticIntField
2765 _Jv_JNI_SetStaticField
, // SetStaticLongField
2766 _Jv_JNI_SetStaticField
, // SetStaticFloatField
2767 _Jv_JNI_SetStaticField
, // SetStaticDoubleField
2768 _Jv_JNI_NewString
, // NewString
2769 _Jv_JNI_GetStringLength
, // GetStringLength
2770 _Jv_JNI_GetStringChars
, // GetStringChars
2771 _Jv_JNI_ReleaseStringChars
, // ReleaseStringChars
2772 _Jv_JNI_NewStringUTF
, // NewStringUTF
2773 _Jv_JNI_GetStringUTFLength
, // GetStringUTFLength
2774 _Jv_JNI_GetStringUTFChars
, // GetStringUTFChars
2775 _Jv_JNI_ReleaseStringUTFChars
, // ReleaseStringUTFChars
2776 _Jv_JNI_GetArrayLength
, // GetArrayLength
2777 _Jv_JNI_NewObjectArray
, // NewObjectArray
2778 _Jv_JNI_GetObjectArrayElement
, // GetObjectArrayElement
2779 _Jv_JNI_SetObjectArrayElement
, // SetObjectArrayElement
2780 _Jv_JNI_NewPrimitiveArray
<jboolean
, JvPrimClass (boolean
)>,
2782 _Jv_JNI_NewPrimitiveArray
<jbyte
, JvPrimClass (byte
)>, // NewByteArray
2783 _Jv_JNI_NewPrimitiveArray
<jchar
, JvPrimClass (char)>, // NewCharArray
2784 _Jv_JNI_NewPrimitiveArray
<jshort
, JvPrimClass (short)>, // NewShortArray
2785 _Jv_JNI_NewPrimitiveArray
<jint
, JvPrimClass (int)>, // NewIntArray
2786 _Jv_JNI_NewPrimitiveArray
<jlong
, JvPrimClass (long)>, // NewLongArray
2787 _Jv_JNI_NewPrimitiveArray
<jfloat
, JvPrimClass (float)>, // NewFloatArray
2788 _Jv_JNI_NewPrimitiveArray
<jdouble
, JvPrimClass (double)>, // NewDoubleArray
2789 _Jv_JNI_GetPrimitiveArrayElements
<jboolean
, JvPrimClass (boolean
)>,
2790 // GetBooleanArrayElements
2791 _Jv_JNI_GetPrimitiveArrayElements
<jbyte
, JvPrimClass (byte
)>,
2792 // GetByteArrayElements
2793 _Jv_JNI_GetPrimitiveArrayElements
<jchar
, JvPrimClass (char)>,
2794 // GetCharArrayElements
2795 _Jv_JNI_GetPrimitiveArrayElements
<jshort
, JvPrimClass (short)>,
2796 // GetShortArrayElements
2797 _Jv_JNI_GetPrimitiveArrayElements
<jint
, JvPrimClass (int)>,
2798 // GetIntArrayElements
2799 _Jv_JNI_GetPrimitiveArrayElements
<jlong
, JvPrimClass (long)>,
2800 // GetLongArrayElements
2801 _Jv_JNI_GetPrimitiveArrayElements
<jfloat
, JvPrimClass (float)>,
2802 // GetFloatArrayElements
2803 _Jv_JNI_GetPrimitiveArrayElements
<jdouble
, JvPrimClass (double)>,
2804 // GetDoubleArrayElements
2805 _Jv_JNI_ReleasePrimitiveArrayElements
<jboolean
, JvPrimClass (boolean
)>,
2806 // ReleaseBooleanArrayElements
2807 _Jv_JNI_ReleasePrimitiveArrayElements
<jbyte
, JvPrimClass (byte
)>,
2808 // ReleaseByteArrayElements
2809 _Jv_JNI_ReleasePrimitiveArrayElements
<jchar
, JvPrimClass (char)>,
2810 // ReleaseCharArrayElements
2811 _Jv_JNI_ReleasePrimitiveArrayElements
<jshort
, JvPrimClass (short)>,
2812 // ReleaseShortArrayElements
2813 _Jv_JNI_ReleasePrimitiveArrayElements
<jint
, JvPrimClass (int)>,
2814 // ReleaseIntArrayElements
2815 _Jv_JNI_ReleasePrimitiveArrayElements
<jlong
, JvPrimClass (long)>,
2816 // ReleaseLongArrayElements
2817 _Jv_JNI_ReleasePrimitiveArrayElements
<jfloat
, JvPrimClass (float)>,
2818 // ReleaseFloatArrayElements
2819 _Jv_JNI_ReleasePrimitiveArrayElements
<jdouble
, JvPrimClass (double)>,
2820 // ReleaseDoubleArrayElements
2821 _Jv_JNI_GetPrimitiveArrayRegion
<jboolean
, JvPrimClass (boolean
)>,
2822 // GetBooleanArrayRegion
2823 _Jv_JNI_GetPrimitiveArrayRegion
<jbyte
, JvPrimClass (byte
)>,
2824 // GetByteArrayRegion
2825 _Jv_JNI_GetPrimitiveArrayRegion
<jchar
, JvPrimClass (char)>,
2826 // GetCharArrayRegion
2827 _Jv_JNI_GetPrimitiveArrayRegion
<jshort
, JvPrimClass (short)>,
2828 // GetShortArrayRegion
2829 _Jv_JNI_GetPrimitiveArrayRegion
<jint
, JvPrimClass (int)>,
2830 // GetIntArrayRegion
2831 _Jv_JNI_GetPrimitiveArrayRegion
<jlong
, JvPrimClass (long)>,
2832 // GetLongArrayRegion
2833 _Jv_JNI_GetPrimitiveArrayRegion
<jfloat
, JvPrimClass (float)>,
2834 // GetFloatArrayRegion
2835 _Jv_JNI_GetPrimitiveArrayRegion
<jdouble
, JvPrimClass (double)>,
2836 // GetDoubleArrayRegion
2837 _Jv_JNI_SetPrimitiveArrayRegion
<jboolean
, JvPrimClass (boolean
)>,
2838 // SetBooleanArrayRegion
2839 _Jv_JNI_SetPrimitiveArrayRegion
<jbyte
, JvPrimClass (byte
)>,
2840 // SetByteArrayRegion
2841 _Jv_JNI_SetPrimitiveArrayRegion
<jchar
, JvPrimClass (char)>,
2842 // SetCharArrayRegion
2843 _Jv_JNI_SetPrimitiveArrayRegion
<jshort
, JvPrimClass (short)>,
2844 // SetShortArrayRegion
2845 _Jv_JNI_SetPrimitiveArrayRegion
<jint
, JvPrimClass (int)>,
2846 // SetIntArrayRegion
2847 _Jv_JNI_SetPrimitiveArrayRegion
<jlong
, JvPrimClass (long)>,
2848 // SetLongArrayRegion
2849 _Jv_JNI_SetPrimitiveArrayRegion
<jfloat
, JvPrimClass (float)>,
2850 // SetFloatArrayRegion
2851 _Jv_JNI_SetPrimitiveArrayRegion
<jdouble
, JvPrimClass (double)>,
2852 // SetDoubleArrayRegion
2853 _Jv_JNI_RegisterNatives
, // RegisterNatives
2854 _Jv_JNI_UnregisterNatives
, // UnregisterNatives
2855 _Jv_JNI_MonitorEnter
, // MonitorEnter
2856 _Jv_JNI_MonitorExit
, // MonitorExit
2857 _Jv_JNI_GetJavaVM
, // GetJavaVM
2859 _Jv_JNI_GetStringRegion
, // GetStringRegion
2860 _Jv_JNI_GetStringUTFRegion
, // GetStringUTFRegion
2861 _Jv_JNI_GetPrimitiveArrayCritical
, // GetPrimitiveArrayCritical
2862 _Jv_JNI_ReleasePrimitiveArrayCritical
, // ReleasePrimitiveArrayCritical
2863 _Jv_JNI_GetStringCritical
, // GetStringCritical
2864 _Jv_JNI_ReleaseStringCritical
, // ReleaseStringCritical
2866 _Jv_JNI_NewWeakGlobalRef
, // NewWeakGlobalRef
2867 _Jv_JNI_DeleteWeakGlobalRef
, // DeleteWeakGlobalRef
2869 _Jv_JNI_ExceptionCheck
, // ExceptionCheck
2871 _Jv_JNI_NewDirectByteBuffer
, // NewDirectByteBuffer
2872 _Jv_JNI_GetDirectBufferAddress
, // GetDirectBufferAddress
2873 _Jv_JNI_GetDirectBufferCapacity
// GetDirectBufferCapacity
2876 struct JNIInvokeInterface _Jv_JNI_InvokeFunctions
=
2882 _Jv_JNI_DestroyJavaVM
,
2883 _Jv_JNI_AttachCurrentThread
,
2884 _Jv_JNI_DetachCurrentThread
,
2886 _Jv_JNI_AttachCurrentThreadAsDaemon