/* src/native/jni.c - implementation of the Java Native Interface functions
- Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
- C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
- E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
- J. Wenninger, Institut f. Computersprachen - TU Wien
+ Copyright (C) 1996-2005, 2006, 2007, 2008
+ CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
This file is part of CACAO.
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: jni.c 8170 2007-06-30 14:03:18Z twisti $
-
*/
#include "mm/gc-common.h"
#include "mm/memory.h"
+
#include "native/jni.h"
+#include "native/llni.h"
+#include "native/localref.h"
#include "native/native.h"
#if defined(ENABLE_JAVASE)
-# if defined(WITH_CLASSPATH_GNU)
+# if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
# include "native/include/gnu_classpath_Pointer.h"
# if SIZEOF_VOID_P == 8
#endif
#include "native/include/java_lang_Object.h"
-#include "native/include/java_lang_Byte.h"
-#include "native/include/java_lang_Character.h"
-#include "native/include/java_lang_Short.h"
-#include "native/include/java_lang_Integer.h"
-#include "native/include/java_lang_Boolean.h"
-#include "native/include/java_lang_Long.h"
-#include "native/include/java_lang_Float.h"
-#include "native/include/java_lang_Double.h"
#include "native/include/java_lang_String.h"
#include "native/include/java_lang_Throwable.h"
#if defined(ENABLE_JAVASE)
-# if defined(WITH_CLASSPATH_SUN)
+
+# if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
# include "native/include/java_nio_ByteBuffer.h" /* required by j.l.CL */
# endif
+/* java_lang_ClassLoader is used in java_lang_Class and vice versa, so
+ we pre-define it here to prevent a compiler warning for Sun
+ configurations. */
+
+struct java_lang_ClassLoader;
+
+# include "native/include/java_lang_Class.h"
# include "native/include/java_lang_ClassLoader.h"
# include "native/include/java_lang_reflect_Constructor.h"
# include "native/include/java_nio_Buffer.h"
-# if defined(WITH_CLASSPATH_GNU)
+# if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
+# include "native/include/java_lang_reflect_VMConstructor.h"
+# include "native/include/java_lang_reflect_VMField.h"
+# include "native/include/java_lang_reflect_VMMethod.h"
+
# include "native/include/java_nio_DirectByteBufferImpl.h"
# endif
+#elif defined(ENABLE_JAVAME_CLDC1_1)
+# include "native/include/java_lang_Class.h"
#endif
#if defined(ENABLE_JVMTI)
# include "native/jvmti/cacaodbg.h"
#endif
-#include "native/vm/java_lang_Class.h"
-
#if defined(ENABLE_JAVASE)
-# include "native/vm/java_lang_ClassLoader.h"
# include "native/vm/reflect.h"
#endif
#include "threads/lock-common.h"
-#include "threads/threads-common.h"
+#include "threads/thread.h"
#include "toolbox/logging.h"
+#include "vm/array.h"
#include "vm/builtin.h"
#include "vm/exceptions.h"
#include "vm/global.h"
#include "vm/initialize.h"
+#include "vm/primitive.hpp"
#include "vm/resolve.h"
#include "vm/stringlocal.h"
#include "vm/vm.h"
+#include "vm/jit/argument.h"
#include "vm/jit/asmpart.h"
#include "vm/jit/jit.h"
#include "vm/jit/stacktrace.h"
#include "vmcore/loader.h"
#include "vmcore/options.h"
-#include "vmcore/primitive.h"
#include "vmcore/statistics.h"
+/* debug **********************************************************************/
+
+#if !defined(NDEBUG)
+
+# define TRACEJNICALLS(x) \
+ do { \
+ if (opt_TraceJNICalls) { \
+ log_println x; \
+ } \
+ } while (0)
+
+# define TRACEJNICALLSENTER(x) \
+ do { \
+ if (opt_TraceJNICalls) { \
+ log_start(); \
+ log_print x; \
+ } \
+ } while (0)
+
+# define TRACEJNICALLSEXIT(x) \
+ do { \
+ if (opt_TraceJNICalls) { \
+ log_print x; \
+ log_finish(); \
+ } \
+ } while (0)
+
+#else
+
+# define TRACEJNICALLS(x)
+# define TRACEJNICALLSENTER(x)
+# define TRACEJNICALLSEXIT(x)
+
+#endif
+
+
/* global variables ***********************************************************/
/* global reference table *****************************************************/
#if defined(ENABLE_JAVASE)
static classinfo *class_java_nio_Buffer;
+
+# if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
+
static classinfo *class_java_nio_DirectByteBufferImpl;
static classinfo *class_java_nio_DirectByteBufferImpl_ReadWrite;
-# if defined(WITH_CLASSPATH_GNU)
# if SIZEOF_VOID_P == 8
static classinfo *class_gnu_classpath_Pointer64;
# else
static classinfo *class_gnu_classpath_Pointer32;
# endif
-# endif
static methodinfo *dbbirw_init;
-#endif
-
-
-/* local reference table ******************************************************/
-
-#if !defined(ENABLE_THREADS)
-localref_table *_no_threads_localref_table;
-#endif
+# elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
-/* accessing instance fields macros *******************************************/
+static classinfo *class_sun_nio_ch_DirectBuffer;
+static classinfo *class_java_nio_DirectByteBuffer;
-#define SET_FIELD(o,type,f,value) \
- *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset)) = (type) (value)
+static methodinfo *dbb_init;
-#define GET_FIELD(o,type,f) \
- *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset))
+# endif
+#endif
/* some forward declarations **************************************************/
-jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref);
-jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity);
+jobject jni_NewLocalRef(JNIEnv *env, jobject ref);
/* jni_init ********************************************************************
bool jni_init(void)
{
+ TRACESUBSYSTEMINITIALIZATION("jni_init");
+
/* create global ref hashtable */
hashtable_global_ref = NEW(hashtable);
#if defined(ENABLE_JAVASE)
- /* direct buffer stuff */
+ /* Direct buffer stuff. */
if (!(class_java_nio_Buffer =
load_class_bootstrap(utf_new_char("java/nio/Buffer"))) ||
!link_class(class_java_nio_Buffer))
return false;
-# if defined(WITH_CLASSPATH_GNU)
+# if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
+
if (!(class_java_nio_DirectByteBufferImpl =
load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl"))) ||
!link_class(class_java_nio_DirectByteBufferImpl))
!link_class(class_gnu_classpath_Pointer32))
return false;
# endif
-# endif
-#endif /* defined(ENABLE_JAVASE) */
- return true;
-}
+# elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
+ if (!(class_sun_nio_ch_DirectBuffer =
+ load_class_bootstrap(utf_new_char("sun/nio/ch/DirectBuffer"))))
+ vm_abort("jni_init: loading sun/nio/ch/DirectBuffer failed");
-/* jni_init_localref_table *****************************************************
+ if (!link_class(class_sun_nio_ch_DirectBuffer))
+ vm_abort("jni_init: linking sun/nio/ch/DirectBuffer failed");
- Initializes the local references table of the current thread.
+ if (!(class_java_nio_DirectByteBuffer =
+ load_class_bootstrap(utf_new_char("java/nio/DirectByteBuffer"))))
+ vm_abort("jni_init: loading java/nio/DirectByteBuffer failed");
-*******************************************************************************/
+ if (!link_class(class_java_nio_DirectByteBuffer))
+ vm_abort("jni_init: linking java/nio/DirectByteBuffer failed");
-bool jni_init_localref_table(void)
-{
- localref_table *lrt;
+ if (!(dbb_init =
+ class_resolvemethod(class_java_nio_DirectByteBuffer,
+ utf_init,
+ utf_new_char("(JI)V"))))
+ vm_abort("jni_init: resolving java/nio/DirectByteBuffer.init(JI)V failed");
+
+# endif
- lrt = GCNEW(localref_table);
+#endif /* defined(ENABLE_JAVASE) */
- if (lrt == NULL)
- return false;
+ return true;
+}
- lrt->capacity = LOCALREFTABLE_CAPACITY;
- lrt->used = 0;
- lrt->localframes = 1;
- lrt->prev = LOCALREFTABLE;
- /* clear the references array (memset is faster then a for-loop) */
+/* jni_version_check ***********************************************************
- MSET(lrt->refs, 0, java_objectheader*, LOCALREFTABLE_CAPACITY);
+ Check if the given JNI version is supported.
- LOCALREFTABLE = lrt;
+ IN:
+ version....JNI version to check
- return true;
+ RETURN VALUE:
+ true.......supported
+ false......not supported
+
+*******************************************************************************/
+
+bool jni_version_check(int version)
+{
+ switch (version) {
+ case JNI_VERSION_1_1:
+ case JNI_VERSION_1_2:
+ case JNI_VERSION_1_4:
+ case JNI_VERSION_1_6:
+ return true;
+ default:
+ return false;
+ }
}
*******************************************************************************/
-static java_objectheader *_Jv_jni_CallObjectMethod(java_objectheader *o,
- vftbl_t *vftbl,
- methodinfo *m, va_list ap)
+static java_handle_t *_Jv_jni_CallObjectMethod(java_handle_t *o,
+ vftbl_t *vftbl,
+ methodinfo *m, va_list ap)
{
- methodinfo *resm;
- java_objectheader *ro;
+ methodinfo *resm;
+ java_handle_t *ro;
STATISTICS(jniinvokation());
*******************************************************************************/
-static java_objectheader *_Jv_jni_CallObjectMethodA(java_objectheader *o,
- vftbl_t *vftbl,
- methodinfo *m,
- const jvalue *args)
+static java_handle_t *_Jv_jni_CallObjectMethodA(java_handle_t *o,
+ vftbl_t *vftbl,
+ methodinfo *m,
+ const jvalue *args)
{
- methodinfo *resm;
- java_objectheader *ro;
+ methodinfo *resm;
+ java_handle_t *ro;
STATISTICS(jniinvokation());
*******************************************************************************/
-static jint _Jv_jni_CallIntMethod(java_objectheader *o, vftbl_t *vftbl,
+static jint _Jv_jni_CallIntMethod(java_handle_t *o, vftbl_t *vftbl,
methodinfo *m, va_list ap)
{
methodinfo *resm;
*******************************************************************************/
-static jint _Jv_jni_CallIntMethodA(java_objectheader *o, vftbl_t *vftbl,
+static jint _Jv_jni_CallIntMethodA(java_handle_t *o, vftbl_t *vftbl,
methodinfo *m, const jvalue *args)
{
methodinfo *resm;
*******************************************************************************/
-static jlong _Jv_jni_CallLongMethod(java_objectheader *o, vftbl_t *vftbl,
+static jlong _Jv_jni_CallLongMethod(java_handle_t *o, vftbl_t *vftbl,
methodinfo *m, va_list ap)
{
methodinfo *resm;
*******************************************************************************/
-static jlong _Jv_jni_CallLongMethodA(java_objectheader *o, vftbl_t *vftbl,
+static jlong _Jv_jni_CallLongMethodA(java_handle_t *o, vftbl_t *vftbl,
methodinfo *m, const jvalue *args)
{
methodinfo *resm;
*******************************************************************************/
-static jfloat _Jv_jni_CallFloatMethod(java_objectheader *o, vftbl_t *vftbl,
+static jfloat _Jv_jni_CallFloatMethod(java_handle_t *o, vftbl_t *vftbl,
methodinfo *m, va_list ap)
{
methodinfo *resm;
*******************************************************************************/
-static jfloat _Jv_jni_CallFloatMethodA(java_objectheader *o, vftbl_t *vftbl,
+static jfloat _Jv_jni_CallFloatMethodA(java_handle_t *o, vftbl_t *vftbl,
methodinfo *m, const jvalue *args)
{
methodinfo *resm;
*******************************************************************************/
-static jdouble _Jv_jni_CallDoubleMethod(java_objectheader *o, vftbl_t *vftbl,
+static jdouble _Jv_jni_CallDoubleMethod(java_handle_t *o, vftbl_t *vftbl,
methodinfo *m, va_list ap)
{
methodinfo *resm;
*******************************************************************************/
-static jdouble _Jv_jni_CallDoubleMethodA(java_objectheader *o, vftbl_t *vftbl,
+static jdouble _Jv_jni_CallDoubleMethodA(java_handle_t *o, vftbl_t *vftbl,
methodinfo *m, const jvalue *args)
{
methodinfo *resm;
*******************************************************************************/
-static void _Jv_jni_CallVoidMethod(java_objectheader *o, vftbl_t *vftbl,
+static void _Jv_jni_CallVoidMethod(java_handle_t *o, vftbl_t *vftbl,
methodinfo *m, va_list ap)
{
methodinfo *resm;
*******************************************************************************/
-static void _Jv_jni_CallVoidMethodA(java_objectheader *o, vftbl_t *vftbl,
+static void _Jv_jni_CallVoidMethodA(java_handle_t *o, vftbl_t *vftbl,
methodinfo *m, const jvalue *args)
{
methodinfo *resm;
}
-/* _Jv_jni_invokeNative ********************************************************
-
- Invoke a method on the given object with the given arguments.
-
- For instance methods OBJ must be != NULL and the method is looked up
- in the vftbl of the object.
+/* GetVersion ******************************************************************
- For static methods, OBJ is ignored.
+ Returns the major version number in the higher 16 bits and the
+ minor version number in the lower 16 bits.
*******************************************************************************/
-#if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) \
- && !defined(__M68K__) && !defined(__ARM__) && !defined(__SPARC_64__)
-java_objectheader *_Jv_jni_invokeNative(methodinfo *m, java_objectheader *o,
- java_objectarray *params)
+jint _Jv_JNI_GetVersion(JNIEnv *env)
{
- methodinfo *resm;
- vm_arg *vmargs;
- java_objectheader *ro;
- s4 argcount;
- s4 paramcount;
- java_objectheader *xptr;
-
- if (m == NULL) {
- exceptions_throw_nullpointerexception();
- return NULL;
- }
+ TRACEJNICALLS(("_Jv_JNI_GetVersion(env=%p)", env));
- argcount = m->parseddesc->paramcount;
- paramcount = argcount;
+ /* We support JNI 1.6. */
- /* if method is non-static, remove the `this' pointer */
+ return JNI_VERSION_1_6;
+}
- if (!(m->flags & ACC_STATIC))
- paramcount--;
- /* For instance methods the object has to be an instance of the
- class the method belongs to. For static methods the obj
- parameter is ignored. */
+/* Class Operations ***********************************************************/
- if (!(m->flags & ACC_STATIC) && o && (!builtin_instanceof(o, m->class))) {
- exceptions_throw_illegalargumentexception();
- return NULL;
- }
+/* DefineClass *****************************************************************
- /* check if we got the right number of arguments */
+ Loads a class from a buffer of raw class data. The buffer
+ containing the raw class data is not referenced by the VM after the
+ DefineClass call returns, and it may be discarded if desired.
- if (((params == NULL) && (paramcount != 0)) ||
- (params && (params->header.size != paramcount)))
- {
- exceptions_throw_illegalargumentexception();
- return NULL;
- }
+*******************************************************************************/
- /* for instance methods we need an object */
+jclass _Jv_JNI_DefineClass(JNIEnv *env, const char *name, jobject loader,
+ const jbyte *buf, jsize bufLen)
+{
+#if defined(ENABLE_JAVASE)
+ utf *u;
+ classloader_t *cl;
+ classinfo *c;
+ java_lang_Class *co;
- if (!(m->flags & ACC_STATIC) && (o == NULL)) {
- /* XXX not sure if that is the correct exception */
- exceptions_throw_nullpointerexception();
- return NULL;
- }
+ TRACEJNICALLS(("_Jv_JNI_DefineClass(env=%p, name=%s, loader=%p, buf=%p, bufLen=%d)", env, name, loader, buf, bufLen));
- /* for static methods, zero object to make subsequent code simpler */
- if (m->flags & ACC_STATIC)
- o = NULL;
+ u = utf_new_char(name);
+ cl = loader_hashtable_classloader_add((java_handle_t *) loader);
- if (o != NULL) {
- /* for instance methods we must do a vftbl lookup */
- resm = method_vftbl_lookup(o->vftbl, m);
- }
- else {
- /* for static methods, just for convenience */
- resm = m;
- }
+ c = class_define(u, cl, bufLen, (uint8_t *) buf, NULL);
- vmargs = MNEW(vm_arg, argcount);
+ co = LLNI_classinfo_wrap(c);
- if (!vm_vmargs_from_objectarray(resm, o, vmargs, params)) {
- MFREE(vmargs, vm_arg, argcount);
- return NULL;
- }
+ return (jclass) jni_NewLocalRef(env, (jobject) co);
+#else
+ vm_abort("_Jv_JNI_DefineClass: not implemented in this configuration");
- switch (resm->parseddesc->returntype.decltype) {
- case TYPE_VOID:
- (void) vm_call_method_vmarg(resm, argcount, vmargs);
+ /* keep compiler happy */
- ro = NULL;
- break;
+ return 0;
+#endif
+}
- case PRIMITIVETYPE_BOOLEAN: {
- s4 i;
- java_lang_Boolean *bo;
- i = vm_call_method_int_vmarg(resm, argcount, vmargs);
+/* FindClass *******************************************************************
- ro = builtin_new(class_java_lang_Boolean);
+ This function loads a locally-defined class. It searches the
+ directories and zip files specified by the CLASSPATH environment
+ variable for the class with the specified name.
- /* setting the value of the object direct */
+*******************************************************************************/
- bo = (java_lang_Boolean *) ro;
- bo->value = i;
- }
- break;
+jclass jni_FindClass(JNIEnv *env, const char *name)
+{
+#if defined(ENABLE_JAVASE)
- case PRIMITIVETYPE_BYTE: {
- s4 i;
- java_lang_Byte *bo;
+ utf *u;
+ classinfo *cc;
+ classinfo *c;
+ java_lang_Class *co;
- i = vm_call_method_int_vmarg(resm, argcount, vmargs);
+ TRACEJNICALLS(("jni_FindClass(env=%p, name=%s)", env, name));
- ro = builtin_new(class_java_lang_Byte);
+ /* FIXME If name is NULL we have a problem here. */
- /* setting the value of the object direct */
+ u = utf_new_char_classname((char *) name);
- bo = (java_lang_Byte *) ro;
- bo->value = i;
+ if ((u == NULL) /*|| (int)strlen(name) > symbolOopDesc::max_length() */) {
+ exceptions_throw_noclassdeffounderror(u);
+ return NULL;
}
- break;
- case PRIMITIVETYPE_CHAR: {
- s4 i;
- java_lang_Character *co;
+ /* Check stacktrace for classloader, if one found use it,
+ otherwise use the system classloader. */
- i = vm_call_method_int_vmarg(resm, argcount, vmargs);
+ /* Quote from the JNI documentation:
+
+ In the Java 2 Platform, FindClass locates the class loader
+ associated with the current native method. If the native code
+ belongs to a system class, no class loader will be
+ involved. Otherwise, the proper class loader will be invoked to
+ load and link the named class. When FindClass is called through
+ the Invocation Interface, there is no current native method or
+ its associated class loader. In that case, the result of
+ ClassLoader.getBaseClassLoader is used." */
- ro = builtin_new(class_java_lang_Character);
+ cc = stacktrace_get_current_class();
- /* setting the value of the object direct */
+ if (cc == NULL)
+ c = load_class_from_sysloader(u);
+ else
+ c = load_class_from_classloader(u, cc->classloader);
- co = (java_lang_Character *) ro;
- co->value = i;
+ if (c == NULL) {
+ resolve_handle_pending_exception(true);
+ return NULL;
}
- break;
-
- case PRIMITIVETYPE_SHORT: {
- s4 i;
- java_lang_Short *so;
-
- i = vm_call_method_int_vmarg(resm, argcount, vmargs);
- ro = builtin_new(class_java_lang_Short);
+ if (!link_class(c))
+ return NULL;
- /* setting the value of the object direct */
+ co = LLNI_classinfo_wrap(c);
- so = (java_lang_Short *) ro;
- so->value = i;
- }
- break;
+ return (jclass) jni_NewLocalRef(env, (jobject) co);
- case PRIMITIVETYPE_INT: {
- s4 i;
- java_lang_Integer *io;
+#elif defined(ENABLE_JAVAME_CLDC1_1)
- i = vm_call_method_int_vmarg(resm, argcount, vmargs);
+ utf *u;
+ classinfo *c;
- ro = builtin_new(class_java_lang_Integer);
+ TRACEJNICALLS(("jni_FindClass(env=%p, name=%s)", env, name));
- /* setting the value of the object direct */
+ u = utf_new_char_classname((char *) name);
+ c = load_class_bootstrap(u);
- io = (java_lang_Integer *) ro;
- io->value = i;
+ if (c == NULL) {
+ resolve_handle_pending_exception(true);
+ return NULL;
}
- break;
-
- case PRIMITIVETYPE_LONG: {
- s8 l;
- java_lang_Long *lo;
- l = vm_call_method_long_vmarg(resm, argcount, vmargs);
+ if (!link_class(c))
+ return NULL;
- ro = builtin_new(class_java_lang_Long);
+ return (jclass) jni_NewLocalRef(env, (jobject) c);
+
+#else
+ vm_abort("jni_FindClass: not implemented in this configuration");
- /* setting the value of the object direct */
+ /* keep compiler happy */
- lo = (java_lang_Long *) ro;
- lo->value = l;
- }
- break;
+ return NULL;
+#endif
+}
+
- case PRIMITIVETYPE_FLOAT: {
- float f;
- java_lang_Float *fo;
+/* GetSuperclass ***************************************************************
- f = vm_call_method_float_vmarg(resm, argcount, vmargs);
+ If clazz represents any class other than the class Object, then
+ this function returns the object that represents the superclass of
+ the class specified by clazz.
- ro = builtin_new(class_java_lang_Float);
+*******************************************************************************/
+
+jclass _Jv_JNI_GetSuperclass(JNIEnv *env, jclass sub)
+{
+ classinfo *c;
+ classinfo *super;
+ java_lang_Class *co;
- /* setting the value of the object direct */
+ TRACEJNICALLS(("_Jv_JNI_GetSuperclass(env=%p, sub=%p)", env, sub));
- fo = (java_lang_Float *) ro;
- fo->value = f;
- }
- break;
+ c = LLNI_classinfo_unwrap(sub);
- case PRIMITIVETYPE_DOUBLE: {
- double d;
- java_lang_Double *_do;
+ if (c == NULL)
+ return NULL;
- d = vm_call_method_double_vmarg(resm, argcount, vmargs);
+ super = class_get_superclass(c);
- ro = builtin_new(class_java_lang_Double);
+ co = LLNI_classinfo_wrap(super);
- /* setting the value of the object direct */
+ return (jclass) jni_NewLocalRef(env, (jobject) co);
+}
+
+
+/* IsAssignableFrom ************************************************************
- _do = (java_lang_Double *) ro;
- _do->value = d;
- }
- break;
+ Determines whether an object of sub can be safely cast to sup.
- case TYPE_ADR:
- ro = vm_call_method_vmarg(resm, argcount, vmargs);
- break;
+*******************************************************************************/
- default:
- /* if this happens the exception has already been set by
- fill_callblock_from_objectarray */
+jboolean _Jv_JNI_IsAssignableFrom(JNIEnv *env, jclass sub, jclass sup)
+{
+ classinfo *to;
+ classinfo *from;
- MFREE(vmargs, vm_arg, argcount);
+ TRACEJNICALLS(("_Jv_JNI_IsAssignableFrom(env=%p, sub=%p, sup=%p)", env, sub, sup));
- return NULL;
- }
+ to = (classinfo *) sup;
+ from = (classinfo *) sub;
- MFREE(vmargs, vm_arg, argcount);
+ return class_is_assignable_from(to, from);
+}
- xptr = exceptions_get_exception();
- if (xptr != NULL) {
- /* clear exception pointer, we are calling JIT code again */
+/* Throw ***********************************************************************
- exceptions_clear_exception();
+ Causes a java.lang.Throwable object to be thrown.
- exceptions_throw_invocationtargetexception(xptr);
- }
+*******************************************************************************/
- return ro;
-}
-#else
-java_objectheader *_Jv_jni_invokeNative(methodinfo *m, java_objectheader *o,
- java_objectarray *params)
+jint _Jv_JNI_Throw(JNIEnv *env, jthrowable obj)
{
- methodinfo *resm;
- java_objectheader *ro;
- s4 argcount;
- s4 paramcount;
- java_objectheader *xptr;
- int32_t dumpsize;
- uint64_t *array;
+ java_handle_t *o;
- if (m == NULL) {
- exceptions_throw_nullpointerexception();
- return NULL;
- }
+ STATISTICS(jniinvokation());
- argcount = m->parseddesc->paramcount;
- paramcount = argcount;
+ o = (java_handle_t *) obj;
- /* if method is non-static, remove the `this' pointer */
+ exceptions_set_exception(o);
- if (!(m->flags & ACC_STATIC))
- paramcount--;
+ return JNI_OK;
+}
- /* For instance methods the object has to be an instance of the
- class the method belongs to. For static methods the obj
- parameter is ignored. */
- if (!(m->flags & ACC_STATIC) && o && (!builtin_instanceof(o, m->class))) {
- exceptions_throw_illegalargumentexception();
- return NULL;
- }
+/* ThrowNew ********************************************************************
- /* check if we got the right number of arguments */
+ Constructs an exception object from the specified class with the
+ message specified by message and causes that exception to be
+ thrown.
- if (((params == NULL) && (paramcount != 0)) ||
- (params && (params->header.size != paramcount)))
- {
- exceptions_throw_illegalargumentexception();
- return NULL;
- }
+*******************************************************************************/
- /* for instance methods we need an object */
+jint _Jv_JNI_ThrowNew(JNIEnv* env, jclass clazz, const char *msg)
+{
+ classinfo *c;
+ java_handle_t *o;
+ java_handle_t *s;
- if (!(m->flags & ACC_STATIC) && (o == NULL)) {
- /* XXX not sure if that is the correct exception */
- exceptions_throw_nullpointerexception();
- return NULL;
- }
+ STATISTICS(jniinvokation());
- /* for static methods, zero object to make subsequent code simpler */
- if (m->flags & ACC_STATIC)
- o = NULL;
+ c = LLNI_classinfo_unwrap(clazz);
+ if (msg == NULL)
+ msg = "";
+ s = javastring_new_from_utf_string(msg);
- if (o != NULL) {
- /* for instance methods we must do a vftbl lookup */
- resm = method_vftbl_lookup(o->vftbl, m);
- }
- else {
- /* for static methods, just for convenience */
- resm = m;
- }
+ /* instantiate exception object */
- /* mark start of dump memory area */
+ o = native_new_and_init_string(c, s);
- dumpsize = dump_size();
+ if (o == NULL)
+ return -1;
- /* fill the argument array from a object-array */
+ exceptions_set_exception(o);
- array = vm_array_from_objectarray(resm, o, params);
+ return 0;
+}
- if (array == NULL) {
- /* release dump area */
- dump_release(dumpsize);
+/* ExceptionOccurred ***********************************************************
- return NULL;
- }
+ Determines if an exception is being thrown. The exception stays
+ being thrown until either the native code calls ExceptionClear(),
+ or the Java code handles the exception.
- switch (resm->parseddesc->returntype.decltype) {
- case TYPE_VOID:
- (void) vm_call_array(resm, array);
+*******************************************************************************/
- ro = NULL;
- break;
+jthrowable _Jv_JNI_ExceptionOccurred(JNIEnv *env)
+{
+ java_handle_t *o;
- case PRIMITIVETYPE_BOOLEAN: {
- s4 i;
- java_lang_Boolean *bo;
+ TRACEJNICALLS(("_Jv_JNI_ExceptionOccurred(env=%p)", env));
- i = vm_call_int_array(resm, array);
+ o = exceptions_get_exception();
- ro = builtin_new(class_java_lang_Boolean);
+ return jni_NewLocalRef(env, (jthrowable) o);
+}
- /* setting the value of the object direct */
- bo = (java_lang_Boolean *) ro;
- bo->value = i;
- }
- break;
+/* ExceptionDescribe ***********************************************************
- case PRIMITIVETYPE_BYTE: {
- s4 i;
- java_lang_Byte *bo;
+ Prints an exception and a backtrace of the stack to a system
+ error-reporting channel, such as stderr. This is a convenience
+ routine provided for debugging.
- i = vm_call_int_array(resm, array);
+*******************************************************************************/
- ro = builtin_new(class_java_lang_Byte);
+void jni_ExceptionDescribe(JNIEnv *env)
+{
+ TRACEJNICALLS(("jni_ExceptionDescribe(env=%p)", env));
- /* setting the value of the object direct */
+ exceptions_print_stacktrace();
+}
- bo = (java_lang_Byte *) ro;
- bo->value = i;
- }
- break;
- case PRIMITIVETYPE_CHAR: {
- s4 i;
- java_lang_Character *co;
+/* ExceptionClear **************************************************************
- i = vm_call_int_array(resm, array);
+ Clears any exception that is currently being thrown. If no
+ exception is currently being thrown, this routine has no effect.
- ro = builtin_new(class_java_lang_Character);
+*******************************************************************************/
- /* setting the value of the object direct */
+void jni_ExceptionClear(JNIEnv *env)
+{
+ TRACEJNICALLS(("jni_ExceptionClear(env=%p)", env));
- co = (java_lang_Character *) ro;
- co->value = i;
- }
- break;
+ exceptions_clear_exception();
+}
- case PRIMITIVETYPE_SHORT: {
- s4 i;
- java_lang_Short *so;
- i = vm_call_int_array(resm, array);
+/* FatalError ******************************************************************
- ro = builtin_new(class_java_lang_Short);
+ Raises a fatal error and does not expect the VM to recover. This
+ function does not return.
- /* setting the value of the object direct */
+*******************************************************************************/
- so = (java_lang_Short *) ro;
- so->value = i;
- }
- break;
+void _Jv_JNI_FatalError(JNIEnv *env, const char *msg)
+{
+ STATISTICS(jniinvokation());
- case PRIMITIVETYPE_INT: {
- s4 i;
- java_lang_Integer *io;
+ /* this seems to be the best way */
- i = vm_call_int_array(resm, array);
+ vm_abort("JNI Fatal error: %s", msg);
+}
- ro = builtin_new(class_java_lang_Integer);
- /* setting the value of the object direct */
+/* PushLocalFrame **************************************************************
- io = (java_lang_Integer *) ro;
- io->value = i;
- }
- break;
-
- case PRIMITIVETYPE_LONG: {
- s8 l;
- java_lang_Long *lo;
-
- l = vm_call_long_array(resm, array);
+ Creates a new local reference frame, in which at least a given
+ number of local references can be created.
- ro = builtin_new(class_java_lang_Long);
+*******************************************************************************/
- /* setting the value of the object direct */
+jint jni_PushLocalFrame(JNIEnv* env, jint capacity)
+{
+ TRACEJNICALLS(("jni_PushLocalFrame(env=%p, capacity=%d)", env, capacity));
- lo = (java_lang_Long *) ro;
- lo->value = l;
- }
- break;
+ if (capacity <= 0)
+ return -1;
- case PRIMITIVETYPE_FLOAT: {
- float f;
- java_lang_Float *fo;
+ /* add new local reference frame to current table */
- f = vm_call_float_array(resm, array);
+ if (!localref_frame_push(capacity))
+ return -1;
- ro = builtin_new(class_java_lang_Float);
+ return 0;
+}
- /* setting the value of the object direct */
- fo = (java_lang_Float *) ro;
- fo->value = f;
- }
- break;
+/* PopLocalFrame ***************************************************************
- case PRIMITIVETYPE_DOUBLE: {
- double d;
- java_lang_Double *_do;
+ Pops off the current local reference frame, frees all the local
+ references, and returns a local reference in the previous local
+ reference frame for the given result object.
- d = vm_call_double_array(resm, array);
+*******************************************************************************/
- ro = builtin_new(class_java_lang_Double);
+jobject jni_PopLocalFrame(JNIEnv* env, jobject result)
+{
+ TRACEJNICALLS(("jni_PopLocalFrame(env=%p, result=%p)", env, result));
- /* setting the value of the object direct */
+ /* release all current local frames */
- _do = (java_lang_Double *) ro;
- _do->value = d;
- }
- break;
+ localref_frame_pop_all();
- case TYPE_ADR:
- ro = vm_call_array(resm, array);
- break;
+ /* add local reference and return the value */
- default:
- /* if this happens the exception has already been set by
- fill_callblock_from_objectarray */
+ return jni_NewLocalRef(env, result);
+}
- /* release dump area */
- dump_release(dumpsize);
+/* DeleteLocalRef **************************************************************
- return NULL;
- }
+ Deletes the local reference pointed to by localRef.
- xptr = exceptions_get_exception();
+*******************************************************************************/
- if (xptr != NULL) {
- /* clear exception pointer, we are calling JIT code again */
+void jni_DeleteLocalRef(JNIEnv *env, jobject localRef)
+{
+ java_handle_t *o;
- exceptions_clear_exception();
+ TRACEJNICALLS(("jni_DeleteLocalRef(env=%p, ref=%p)", env, localRef));
- exceptions_throw_invocationtargetexception(xptr);
- }
+ o = (java_handle_t *) localRef;
- /* release dump area */
+ if (o == NULL)
+ return;
- dump_release(dumpsize);
+ /* delete the reference */
- return ro;
+ localref_del(o);
}
-#endif
-/* GetVersion ******************************************************************
+/* IsSameObject ****************************************************************
- Returns the major version number in the higher 16 bits and the
- minor version number in the lower 16 bits.
+ Tests whether two references refer to the same Java object.
*******************************************************************************/
-jint _Jv_JNI_GetVersion(JNIEnv *env)
+jboolean _Jv_JNI_IsSameObject(JNIEnv *env, jobject ref1, jobject ref2)
{
+ java_handle_t *o1;
+ java_handle_t *o2;
+ jboolean result;
+
STATISTICS(jniinvokation());
- /* we support JNI 1.4 */
+ o1 = (java_handle_t *) ref1;
+ o2 = (java_handle_t *) ref2;
- return JNI_VERSION_1_4;
-}
+ LLNI_CRITICAL_START;
+ if (LLNI_UNWRAP(o1) == LLNI_UNWRAP(o2))
+ result = JNI_TRUE;
+ else
+ result = JNI_FALSE;
-/* Class Operations ***********************************************************/
+ LLNI_CRITICAL_END;
-/* DefineClass *****************************************************************
+ return result;
+}
- Loads a class from a buffer of raw class data. The buffer
- containing the raw class data is not referenced by the VM after the
- DefineClass call returns, and it may be discarded if desired.
+
+/* NewLocalRef *****************************************************************
+
+ Creates a new local reference that refers to the same object as ref.
*******************************************************************************/
-jclass _Jv_JNI_DefineClass(JNIEnv *env, const char *name, jobject loader,
- const jbyte *buf, jsize bufLen)
+jobject jni_NewLocalRef(JNIEnv *env, jobject ref)
{
-#if defined(ENABLE_JAVASE)
- java_lang_ClassLoader *cl;
- java_lang_String *s;
- java_bytearray *ba;
- jclass c;
+ java_handle_t *o;
+ java_handle_t *localref;
- STATISTICS(jniinvokation());
+ TRACEJNICALLS(("jni_NewLocalRef(env=%p, ref=%p)", env, ref));
- cl = (java_lang_ClassLoader *) loader;
- s = (java_lang_String *) javastring_new_from_utf_string(name);
- ba = (java_bytearray *) buf;
+ o = (java_handle_t *) ref;
- c = (jclass) _Jv_java_lang_ClassLoader_defineClass(cl, s, ba, 0, bufLen,
- NULL);
+ if (o == NULL)
+ return NULL;
- return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
-#else
- vm_abort("_Jv_JNI_DefineClass: not implemented in this configuration");
+ /* insert the reference */
- /* keep compiler happy */
+ localref = localref_add(LLNI_DIRECT(o));
- return 0;
-#endif
+ return (jobject) localref;
}
-/* FindClass *******************************************************************
+/* EnsureLocalCapacity *********************************************************
- This function loads a locally-defined class. It searches the
- directories and zip files specified by the CLASSPATH environment
- variable for the class with the specified name.
+ Ensures that at least a given number of local references can be
+ created in the current thread
*******************************************************************************/
-jclass _Jv_JNI_FindClass(JNIEnv *env, const char *name)
+jint jni_EnsureLocalCapacity(JNIEnv* env, jint capacity)
{
-#if defined(ENABLE_JAVASE)
- utf *u;
- classinfo *cc;
- classinfo *c;
-
- STATISTICS(jniinvokation());
-
- u = utf_new_char_classname((char *) name);
-
- /* Check stacktrace for classloader, if one found use it,
- otherwise use the system classloader. */
-
- /* Quote from the JNI documentation:
-
- In the Java 2 Platform, FindClass locates the class loader
- associated with the current native method. If the native code
- belongs to a system class, no class loader will be
- involved. Otherwise, the proper class loader will be invoked to
- load and link the named class. When FindClass is called through
- the Invocation Interface, there is no current native method or
- its associated class loader. In that case, the result of
- ClassLoader.getBaseClassLoader is used." */
-
- cc = stacktrace_getCurrentClass();
+ localref_table *lrt;
- if (cc == NULL)
- c = load_class_from_sysloader(u);
- else
- c = load_class_from_classloader(u, cc->classloader);
+ TRACEJNICALLS(("jni_EnsureLocalCapacity(env=%p, capacity=%d)", env, capacity));
- if (c == NULL)
- return NULL;
+ /* get local reference table (thread specific) */
- if (!link_class(c))
- return NULL;
+ lrt = LOCALREFTABLE;
- return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
-#else
- vm_abort("_Jv_JNI_FindClass: not implemented in this configuration");
+ /* check if capacity elements are available in the local references table */
- /* keep compiler happy */
+ if ((lrt->used + capacity) > lrt->capacity)
+ return jni_PushLocalFrame(env, capacity);
- return NULL;
-#endif
+ return 0;
}
-
-/* GetSuperclass ***************************************************************
- If clazz represents any class other than the class Object, then
- this function returns the object that represents the superclass of
- the class specified by clazz.
+/* AllocObject *****************************************************************
+
+ Allocates a new Java object without invoking any of the
+ constructors for the object. Returns a reference to the object.
*******************************************************************************/
-
-jclass _Jv_JNI_GetSuperclass(JNIEnv *env, jclass sub)
+
+jobject _Jv_JNI_AllocObject(JNIEnv *env, jclass clazz)
{
- classinfo *c;
+ classinfo *c;
+ java_handle_t *o;
STATISTICS(jniinvokation());
- c = ((classinfo *) sub)->super.cls;
+ c = LLNI_classinfo_unwrap(clazz);
- if (!c)
+ if ((c->flags & ACC_INTERFACE) || (c->flags & ACC_ABSTRACT)) {
+ exceptions_throw_instantiationexception(c);
return NULL;
+ }
+
+ o = builtin_new(c);
- return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
+ return jni_NewLocalRef(env, (jobject) o);
}
-
-
-/* IsAssignableFrom ************************************************************
-
- Determines whether an object of sub can be safely cast to sup.
-*******************************************************************************/
-
-jboolean _Jv_JNI_IsAssignableFrom(JNIEnv *env, jclass sub, jclass sup)
-{
- java_lang_Class *csup;
- java_lang_Class *csub;
- csup = (java_lang_Class *) sup;
- csub = (java_lang_Class *) sub;
+/* NewObject *******************************************************************
- STATISTICS(jniinvokation());
+ Programmers place all arguments that are to be passed to the
+ constructor immediately following the methodID
+ argument. NewObject() accepts these arguments and passes them to
+ the Java method that the programmer wishes to invoke.
- return _Jv_java_lang_Class_isAssignableFrom(csup, csub);
-}
+*******************************************************************************/
+jobject jni_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
+{
+ java_handle_t *o;
+ classinfo *c;
+ methodinfo *m;
+ va_list ap;
-/* Throw ***********************************************************************
+ TRACEJNICALLSENTER(("jni_NewObject(env=%p, clazz=%p, methodID=%p, ...)", env, clazz, methodID));
- Causes a java.lang.Throwable object to be thrown.
+ c = LLNI_classinfo_unwrap(clazz);
+ m = (methodinfo *) methodID;
-*******************************************************************************/
+ /* create object */
-jint _Jv_JNI_Throw(JNIEnv *env, jthrowable obj)
-{
- java_objectheader *o;
+ o = builtin_new(c);
+
+ if (o == NULL)
+ return NULL;
- STATISTICS(jniinvokation());
+ /* call constructor */
- o = (java_objectheader *) obj;
+ va_start(ap, methodID);
+ _Jv_jni_CallVoidMethod(o, LLNI_vftbl_direct(o), m, ap);
+ va_end(ap);
- exceptions_set_exception(o);
+ TRACEJNICALLSEXIT(("->%p", o));
- return JNI_OK;
+ return jni_NewLocalRef(env, (jobject) o);
}
-/* ThrowNew ********************************************************************
+/* NewObjectV ******************************************************************
- Constructs an exception object from the specified class with the
- message specified by message and causes that exception to be
- thrown.
+ Programmers place all arguments that are to be passed to the
+ constructor in an args argument of type va_list that immediately
+ follows the methodID argument. NewObjectV() accepts these
+ arguments, and, in turn, passes them to the Java method that the
+ programmer wishes to invoke.
*******************************************************************************/
-jint _Jv_JNI_ThrowNew(JNIEnv* env, jclass clazz, const char *msg)
+jobject _Jv_JNI_NewObjectV(JNIEnv* env, jclass clazz, jmethodID methodID,
+ va_list args)
{
- classinfo *c;
- java_objectheader *o;
- java_objectheader *s;
+ java_handle_t *o;
+ classinfo *c;
+ methodinfo *m;
STATISTICS(jniinvokation());
- c = (classinfo *) clazz;
- if (msg == NULL)
- msg = "";
- s = javastring_new_from_utf_string(msg);
-
- /* instantiate exception object */
+ c = LLNI_classinfo_unwrap(clazz);
+ m = (methodinfo *) methodID;
- o = native_new_and_init_string(c, s);
+ /* create object */
+ o = builtin_new(c);
+
if (o == NULL)
- return -1;
+ return NULL;
- exceptions_set_exception(o);
+ /* call constructor */
- return 0;
+ _Jv_jni_CallVoidMethod(o, LLNI_vftbl_direct(o), m, args);
+
+ return jni_NewLocalRef(env, (jobject) o);
}
-/* ExceptionOccurred ***********************************************************
+/* NewObjectA *****************************************************************
- Determines if an exception is being thrown. The exception stays
- being thrown until either the native code calls ExceptionClear(),
- or the Java code handles the exception.
+ Programmers place all arguments that are to be passed to the
+ constructor in an args array of jvalues that immediately follows
+ the methodID argument. NewObjectA() accepts the arguments in this
+ array, and, in turn, passes them to the Java method that the
+ programmer wishes to invoke.
*******************************************************************************/
-jthrowable _Jv_JNI_ExceptionOccurred(JNIEnv *env)
+jobject _Jv_JNI_NewObjectA(JNIEnv* env, jclass clazz, jmethodID methodID,
+ const jvalue *args)
{
- java_objectheader *o;
+ java_handle_t *o;
+ classinfo *c;
+ methodinfo *m;
STATISTICS(jniinvokation());
- o = exceptions_get_exception();
+ c = LLNI_classinfo_unwrap(clazz);
+ m = (methodinfo *) methodID;
+
+ /* create object */
+
+ o = builtin_new(c);
+
+ if (o == NULL)
+ return NULL;
+
+ /* call constructor */
+
+ _Jv_jni_CallVoidMethodA(o, LLNI_vftbl_direct(o), m, args);
- return _Jv_JNI_NewLocalRef(env, (jthrowable) o);
+ return jni_NewLocalRef(env, (jobject) o);
}
-/* ExceptionDescribe ***********************************************************
+/* GetObjectClass **************************************************************
- Prints an exception and a backtrace of the stack to a system
- error-reporting channel, such as stderr. This is a convenience
- routine provided for debugging.
+ Returns the class of an object.
*******************************************************************************/
-void _Jv_JNI_ExceptionDescribe(JNIEnv *env)
+jclass _Jv_JNI_GetObjectClass(JNIEnv *env, jobject obj)
{
- java_objectheader *o;
- methodinfo *m;
+ java_handle_t *o;
+ classinfo *c;
+ java_lang_Class *co;
STATISTICS(jniinvokation());
- o = exceptions_get_exception();
-
- if (o == NULL) {
- /* clear exception, because we are calling jit code again */
-
- exceptions_clear_exception();
+ o = (java_handle_t *) obj;
- /* get printStackTrace method from exception class */
-
- m = class_resolveclassmethod(o->vftbl->class,
- utf_printStackTrace,
- utf_void__void,
- NULL,
- true);
+ if ((o == NULL) || (LLNI_vftbl_direct(o) == NULL))
+ return NULL;
- if (m == NULL)
- /* XXX what should we do? */
- return;
+ LLNI_class_get(o, c);
- /* print the stacktrace */
+ co = LLNI_classinfo_wrap(c);
- (void) vm_call_method(m, o);
- }
+ return (jclass) jni_NewLocalRef(env, (jobject) co);
}
-/* ExceptionClear **************************************************************
+/* IsInstanceOf ****************************************************************
- Clears any exception that is currently being thrown. If no
- exception is currently being thrown, this routine has no effect.
+ Tests whether an object is an instance of a class.
*******************************************************************************/
-void _Jv_JNI_ExceptionClear(JNIEnv *env)
+jboolean _Jv_JNI_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)
{
- STATISTICS(jniinvokation());
+ classinfo *c;
+ java_handle_t *h;
- exceptions_clear_exception();
+ TRACEJNICALLS(("_Jv_JNI_IsInstanceOf(env=%p, obj=%p, clazz=%p)", env, obj, clazz));
+
+ /* XXX Is this correct? */
+ c = LLNI_classinfo_unwrap(clazz);
+ h = (java_handle_t *) obj;
+
+ return class_is_instance(c, h);
}
-/* FatalError ******************************************************************
+/* Reflection Support *********************************************************/
- Raises a fatal error and does not expect the VM to recover. This
- function does not return.
+/* FromReflectedMethod *********************************************************
+ Converts java.lang.reflect.Method or java.lang.reflect.Constructor
+ object to a method ID.
+
*******************************************************************************/
-
-void _Jv_JNI_FatalError(JNIEnv *env, const char *msg)
+
+jmethodID jni_FromReflectedMethod(JNIEnv *env, jobject method)
{
- STATISTICS(jniinvokation());
-
- /* this seems to be the best way */
+#if defined(ENABLE_JAVASE)
+ java_handle_t *o;
+ java_lang_reflect_Method *rm;
+ java_lang_reflect_Constructor *rc;
+ classinfo *c;
+ methodinfo *m;
+ int32_t slot;
+
+#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
+ java_lang_reflect_VMMethod *rvmm;
+ java_lang_reflect_VMConstructor *rvmc;
+#endif
- vm_abort("JNI Fatal error: %s", msg);
-}
+ TRACEJNICALLS(("jni_FromReflectedMethod(env=%p, method=%p)", env, method));
+ o = (java_handle_t *) method;
-/* PushLocalFrame **************************************************************
+ if (o == NULL)
+ return NULL;
- Creates a new local reference frame, in which at least a given
- number of local references can be created.
+ if (o->vftbl->clazz == class_java_lang_reflect_Constructor) {
+ rc = (java_lang_reflect_Constructor *) method;
-*******************************************************************************/
+#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
-jint _Jv_JNI_PushLocalFrame(JNIEnv* env, jint capacity)
-{
- s4 additionalrefs;
- localref_table *lrt;
- localref_table *nlrt;
+ LLNI_field_get_ref(rc, cons , rvmc);
+ LLNI_field_get_cls(rvmc, clazz, c);
+ LLNI_field_get_val(rvmc, slot , slot);
- STATISTICS(jniinvokation());
+#elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
- if (capacity <= 0)
- return -1;
+ LLNI_field_get_cls(rc, clazz, c);
+ LLNI_field_get_val(rc, slot , slot);
- /* Allocate new local reference table on Java heap. Calculate the
- additional memory we have to allocate. */
+#else
+# error unknown configuration
+#endif
+ }
+ else {
+ assert(o->vftbl->clazz == class_java_lang_reflect_Method);
- if (capacity > LOCALREFTABLE_CAPACITY)
- additionalrefs = capacity - LOCALREFTABLE_CAPACITY;
- else
- additionalrefs = 0;
+ rm = (java_lang_reflect_Method *) method;
- nlrt = GCMNEW(u1, sizeof(localref_table) + additionalrefs * SIZEOF_VOID_P);
+#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
- if (nlrt == NULL)
- return -1;
+ LLNI_field_get_ref(rm, m , rvmm);
+ LLNI_field_get_cls(rvmm, clazz, c);
+ LLNI_field_get_val(rvmm, slot , slot);
- /* get current local reference table from thread */
+#elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
- lrt = LOCALREFTABLE;
+ LLNI_field_get_cls(rm, clazz, c);
+ LLNI_field_get_val(rm, slot , slot);
- /* Set up the new local reference table and add it to the local
- frames chain. */
+#else
+# error unknown configuration
+#endif
+ }
- nlrt->capacity = capacity;
- nlrt->used = 0;
- nlrt->localframes = lrt->localframes + 1;
- nlrt->prev = lrt;
+ m = &(c->methods[slot]);
- /* store new local reference table in thread */
+ return (jmethodID) m;
+#else
+ vm_abort("jni_FromReflectedMethod: Not implemented in this configuration.");
- LOCALREFTABLE = nlrt;
+ /* Keep compiler happy. */
- return 0;
+ return NULL;
+#endif
}
-/* PopLocalFrame ***************************************************************
+/* FromReflectedField **********************************************************
- Pops off the current local reference frame, frees all the local
- references, and returns a local reference in the previous local
- reference frame for the given result object.
+ Converts a java.lang.reflect.Field to a field ID.
*******************************************************************************/
-
-jobject _Jv_JNI_PopLocalFrame(JNIEnv* env, jobject result)
+
+jfieldID jni_FromReflectedField(JNIEnv* env, jobject field)
{
- localref_table *lrt;
- localref_table *plrt;
- s4 localframes;
-
- STATISTICS(jniinvokation());
-
- /* get current local reference table from thread */
-
- lrt = LOCALREFTABLE;
-
- localframes = lrt->localframes;
-
- /* Don't delete the top local frame, as this one is allocated in
- the native stub on the stack and is freed automagically on
- return. */
+#if defined(ENABLE_JAVASE)
+ java_lang_reflect_Field *rf;
+ classinfo *c;
+ fieldinfo *f;
+ int32_t slot;
- if (localframes == 1)
- return _Jv_JNI_NewLocalRef(env, result);
+#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
+ java_lang_reflect_VMField *rvmf;
+#endif
- /* release all current local frames */
+ TRACEJNICALLS(("jni_FromReflectedField(env=%p, field=%p)", env, field));
- for (; localframes >= 1; localframes--) {
- /* get previous frame */
+ rf = (java_lang_reflect_Field *) field;
- plrt = lrt->prev;
+ if (rf == NULL)
+ return NULL;
- /* clear all reference entries */
+#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
- MSET(&lrt->refs[0], 0, java_objectheader*, lrt->capacity);
+ LLNI_field_get_ref(rf, f, rvmf);
+ LLNI_field_get_cls(rvmf, clazz, c);
+ LLNI_field_get_val(rvmf, slot , slot);
- lrt->prev = NULL;
+#elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
- /* set new local references table */
+ LLNI_field_get_cls(rf, clazz, c);
+ LLNI_field_get_val(rf, slot , slot);
- lrt = plrt;
- }
+#else
+# error unknown configuration
+#endif
- /* store new local reference table in thread */
+ f = &(c->fields[slot]);
- LOCALREFTABLE = lrt;
+ return (jfieldID) f;
+#else
+ vm_abort("jni_FromReflectedField: Not implemented in this configuration.");
- /* add local reference and return the value */
+ /* Keep compiler happy. */
- return _Jv_JNI_NewLocalRef(env, result);
+ return NULL;
+#endif
}
-/* DeleteLocalRef **************************************************************
+/* ToReflectedMethod ***********************************************************
- Deletes the local reference pointed to by localRef.
+ Converts a method ID derived from cls to an instance of the
+ java.lang.reflect.Method class or to an instance of the
+ java.lang.reflect.Constructor class.
*******************************************************************************/
-void _Jv_JNI_DeleteLocalRef(JNIEnv *env, jobject localRef)
+jobject _Jv_JNI_ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID,
+ jboolean isStatic)
{
- java_objectheader *o;
- localref_table *lrt;
- s4 i;
-
- STATISTICS(jniinvokation());
-
- o = (java_objectheader *) localRef;
+#if defined(ENABLE_JAVASE)
+ methodinfo *m;
+ java_lang_reflect_Constructor *rc;
+ java_lang_reflect_Method *rm;
- /* get local reference table (thread specific) */
+ TRACEJNICALLS(("_Jv_JNI_ToReflectedMethod(env=%p, cls=%p, methodID=%p, isStatic=%d)", env, cls, methodID, isStatic));
- lrt = LOCALREFTABLE;
+ m = (methodinfo *) methodID;
- /* go through all local frames */
+ /* HotSpot does the same assert. */
- for (; lrt != NULL; lrt = lrt->prev) {
+ assert(((m->flags & ACC_STATIC) != 0) == (isStatic != 0));
- /* and try to remove the reference */
+ if (m->name == utf_init) {
+ rc = reflect_constructor_new(m);
- for (i = 0; i < lrt->capacity; i++) {
- if (lrt->refs[i] == o) {
- lrt->refs[i] = NULL;
- lrt->used--;
+ return (jobject) rc;
+ }
+ else {
+ rm = reflect_method_new(m);
- return;
- }
- }
+ return (jobject) rm;
}
+#else
+ vm_abort("_Jv_JNI_ToReflectedMethod: not implemented in this configuration");
- /* this should not happen */
+ /* keep compiler happy */
-/* if (opt_checkjni) */
-/* FatalError(env, "Bad global or local ref passed to JNI"); */
- log_text("JNI-DeleteLocalRef: Local ref passed to JNI not found");
+ return NULL;
+#endif
}
-/* IsSameObject ****************************************************************
+/* ToReflectedField ************************************************************
- Tests whether two references refer to the same Java object.
+ Converts a field ID derived from cls to an instance of the
+ java.lang.reflect.Field class.
*******************************************************************************/
-jboolean _Jv_JNI_IsSameObject(JNIEnv *env, jobject ref1, jobject ref2)
+jobject _Jv_JNI_ToReflectedField(JNIEnv* env, jclass cls, jfieldID fieldID,
+ jboolean isStatic)
{
STATISTICS(jniinvokation());
- if (ref1 == ref2)
- return JNI_TRUE;
- else
- return JNI_FALSE;
+ log_text("JNI-Call: ToReflectedField: IMPLEMENT ME!");
+
+ return NULL;
}
-/* NewLocalRef *****************************************************************
+/* Calling Instance Methods ***************************************************/
- Creates a new local reference that refers to the same object as ref.
+/* GetMethodID *****************************************************************
+
+ Returns the method ID for an instance (nonstatic) method of a class
+ or interface. The method may be defined in one of the clazz's
+ superclasses and inherited by clazz. The method is determined by
+ its name and signature.
+
+ GetMethodID() causes an uninitialized class to be initialized.
*******************************************************************************/
-jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref)
+jmethodID _Jv_JNI_GetMethodID(JNIEnv* env, jclass clazz, const char *name,
+ const char *sig)
{
- localref_table *lrt;
- s4 i;
+ classinfo *c;
+ utf *uname;
+ utf *udesc;
+ methodinfo *m;
STATISTICS(jniinvokation());
- if (ref == NULL)
+ c = LLNI_classinfo_unwrap(clazz);
+
+ if (c == NULL)
return NULL;
- /* get local reference table (thread specific) */
+ if (!(c->state & CLASS_INITIALIZED))
+ if (!initialize_class(c))
+ return NULL;
- lrt = LOCALREFTABLE;
+ /* try to get the method of the class or one of it's superclasses */
- /* Check if we have space for the requested reference? No,
- allocate a new frame. This is actually not what the spec says,
- but for compatibility reasons... */
+ uname = utf_new_char((char *) name);
+ udesc = utf_new_char((char *) sig);
- if (lrt->used == lrt->capacity) {
- if (_Jv_JNI_EnsureLocalCapacity(env, 16) != 0)
- return NULL;
+ m = class_resolvemethod(c, uname, udesc);
- /* get the new local reference table */
+ if ((m == NULL) || (m->flags & ACC_STATIC)) {
+ exceptions_throw_nosuchmethoderror(c, uname, udesc);
- lrt = LOCALREFTABLE;
+ return NULL;
}
- /* insert the reference */
-
- for (i = 0; i < lrt->capacity; i++) {
- if (lrt->refs[i] == NULL) {
- lrt->refs[i] = (java_objectheader *) ref;
- lrt->used++;
+ return (jmethodID) m;
+}
- return ref;
- }
- }
- /* should not happen, just to be sure */
+/* JNI-functions for calling instance methods *********************************/
- assert(0);
+#define JNI_CALL_VIRTUAL_METHOD(name, type, intern) \
+type _Jv_JNI_Call##name##Method(JNIEnv *env, jobject obj, \
+ jmethodID methodID, ...) \
+{ \
+ java_handle_t *o; \
+ methodinfo *m; \
+ va_list ap; \
+ type ret; \
+ \
+ o = (java_handle_t *) obj; \
+ m = (methodinfo *) methodID; \
+ \
+ va_start(ap, methodID); \
+ ret = _Jv_jni_Call##intern##Method(o, LLNI_vftbl_direct(o), m, ap); \
+ va_end(ap); \
+ \
+ return ret; \
+}
+
+JNI_CALL_VIRTUAL_METHOD(Boolean, jboolean, Int)
+JNI_CALL_VIRTUAL_METHOD(Byte, jbyte, Int)
+JNI_CALL_VIRTUAL_METHOD(Char, jchar, Int)
+JNI_CALL_VIRTUAL_METHOD(Short, jshort, Int)
+JNI_CALL_VIRTUAL_METHOD(Int, jint, Int)
+JNI_CALL_VIRTUAL_METHOD(Long, jlong, Long)
+JNI_CALL_VIRTUAL_METHOD(Float, jfloat, Float)
+JNI_CALL_VIRTUAL_METHOD(Double, jdouble, Double)
+
+
+#define JNI_CALL_VIRTUAL_METHOD_V(name, type, intern) \
+type _Jv_JNI_Call##name##MethodV(JNIEnv *env, jobject obj, \
+ jmethodID methodID, va_list args) \
+{ \
+ java_handle_t *o; \
+ methodinfo *m; \
+ type ret; \
+ \
+ o = (java_handle_t *) obj; \
+ m = (methodinfo *) methodID; \
+ \
+ ret = _Jv_jni_Call##intern##Method(o, LLNI_vftbl_direct(o), m, args); \
+ \
+ return ret; \
+}
+
+JNI_CALL_VIRTUAL_METHOD_V(Boolean, jboolean, Int)
+JNI_CALL_VIRTUAL_METHOD_V(Byte, jbyte, Int)
+JNI_CALL_VIRTUAL_METHOD_V(Char, jchar, Int)
+JNI_CALL_VIRTUAL_METHOD_V(Short, jshort, Int)
+JNI_CALL_VIRTUAL_METHOD_V(Int, jint, Int)
+JNI_CALL_VIRTUAL_METHOD_V(Long, jlong, Long)
+JNI_CALL_VIRTUAL_METHOD_V(Float, jfloat, Float)
+JNI_CALL_VIRTUAL_METHOD_V(Double, jdouble, Double)
+
+
+#define JNI_CALL_VIRTUAL_METHOD_A(name, type, intern) \
+type _Jv_JNI_Call##name##MethodA(JNIEnv *env, jobject obj, \
+ jmethodID methodID, \
+ const jvalue *args) \
+{ \
+ java_handle_t *o; \
+ methodinfo *m; \
+ type ret; \
+ \
+ o = (java_handle_t *) obj; \
+ m = (methodinfo *) methodID; \
+ \
+ ret = _Jv_jni_Call##intern##MethodA(o, LLNI_vftbl_direct(o), m, args); \
+ \
+ return ret; \
+}
+
+JNI_CALL_VIRTUAL_METHOD_A(Boolean, jboolean, Int)
+JNI_CALL_VIRTUAL_METHOD_A(Byte, jbyte, Int)
+JNI_CALL_VIRTUAL_METHOD_A(Char, jchar, Int)
+JNI_CALL_VIRTUAL_METHOD_A(Short, jshort, Int)
+JNI_CALL_VIRTUAL_METHOD_A(Int, jint, Int)
+JNI_CALL_VIRTUAL_METHOD_A(Long, jlong, Long)
+JNI_CALL_VIRTUAL_METHOD_A(Float, jfloat, Float)
+JNI_CALL_VIRTUAL_METHOD_A(Double, jdouble, Double)
- /* keep compiler happy */
- return NULL;
-}
+jobject _Jv_JNI_CallObjectMethod(JNIEnv *env, jobject obj, jmethodID methodID,
+ ...)
+{
+ java_handle_t *o;
+ methodinfo *m;
+ java_handle_t *ret;
+ va_list ap;
+ o = (java_handle_t *) obj;
+ m = (methodinfo *) methodID;
-/* EnsureLocalCapacity *********************************************************
+ va_start(ap, methodID);
+ ret = _Jv_jni_CallObjectMethod(o, LLNI_vftbl_direct(o), m, ap);
+ va_end(ap);
- Ensures that at least a given number of local references can be
- created in the current thread
+ return jni_NewLocalRef(env, (jobject) ret);
+}
-*******************************************************************************/
-jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity)
+jobject _Jv_JNI_CallObjectMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
+ va_list args)
{
- localref_table *lrt;
+ java_handle_t *o;
+ methodinfo *m;
+ java_handle_t *ret;
- STATISTICS(jniinvokation());
+ o = (java_handle_t *) obj;
+ m = (methodinfo *) methodID;
- /* get local reference table (thread specific) */
+ ret = _Jv_jni_CallObjectMethod(o, LLNI_vftbl_direct(o), m, args);
- lrt = LOCALREFTABLE;
+ return jni_NewLocalRef(env, (jobject) ret);
+}
- /* check if capacity elements are available in the local references table */
- if ((lrt->used + capacity) > lrt->capacity)
- return _Jv_JNI_PushLocalFrame(env, capacity);
+jobject _Jv_JNI_CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
+ const jvalue *args)
+{
+ java_handle_t *o;
+ methodinfo *m;
+ java_handle_t *ret;
- return 0;
-}
+ o = (java_handle_t *) obj;
+ m = (methodinfo *) methodID;
+ ret = _Jv_jni_CallObjectMethodA(o, LLNI_vftbl_direct(o), m, args);
-/* AllocObject *****************************************************************
+ return jni_NewLocalRef(env, (jobject) ret);
+}
- Allocates a new Java object without invoking any of the
- constructors for the object. Returns a reference to the object.
-*******************************************************************************/
-jobject _Jv_JNI_AllocObject(JNIEnv *env, jclass clazz)
+void _Jv_JNI_CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
{
- classinfo *c;
- java_objectheader *o;
-
- STATISTICS(jniinvokation());
+ java_handle_t *o;
+ methodinfo *m;
+ va_list ap;
- c = (classinfo *) clazz;
-
- if ((c->flags & ACC_INTERFACE) || (c->flags & ACC_ABSTRACT)) {
- exceptions_throw_instantiationexception(c);
- return NULL;
- }
-
- o = builtin_new(c);
+ o = (java_handle_t *) obj;
+ m = (methodinfo *) methodID;
- return _Jv_JNI_NewLocalRef(env, (jobject) o);
+ va_start(ap, methodID);
+ _Jv_jni_CallVoidMethod(o, LLNI_vftbl_direct(o), m, ap);
+ va_end(ap);
}
-/* NewObject *******************************************************************
+void _Jv_JNI_CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
+ va_list args)
+{
+ java_handle_t *o;
+ methodinfo *m;
- Programmers place all arguments that are to be passed to the
- constructor immediately following the methodID
- argument. NewObject() accepts these arguments and passes them to
- the Java method that the programmer wishes to invoke.
+ o = (java_handle_t *) obj;
+ m = (methodinfo *) methodID;
-*******************************************************************************/
+ _Jv_jni_CallVoidMethod(o, LLNI_vftbl_direct(o), m, args);
+}
-jobject _Jv_JNI_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
-{
- java_objectheader *o;
- classinfo *c;
- methodinfo *m;
- va_list ap;
- STATISTICS(jniinvokation());
+void _Jv_JNI_CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
+ const jvalue *args)
+{
+ java_handle_t *o;
+ methodinfo *m;
- c = (classinfo *) clazz;
+ o = (java_handle_t *) obj;
m = (methodinfo *) methodID;
- /* create object */
+ _Jv_jni_CallVoidMethodA(o, LLNI_vftbl_direct(o), m, args);
+}
+
+
+
+#define JNI_CALL_NONVIRTUAL_METHOD(name, type, intern) \
+type _Jv_JNI_CallNonvirtual##name##Method(JNIEnv *env, jobject obj, \
+ jclass clazz, jmethodID methodID, \
+ ...) \
+{ \
+ java_handle_t *o; \
+ classinfo *c; \
+ methodinfo *m; \
+ va_list ap; \
+ type ret; \
+ \
+ o = (java_handle_t *) obj; \
+ c = LLNI_classinfo_unwrap(clazz); \
+ m = (methodinfo *) methodID; \
+ \
+ va_start(ap, methodID); \
+ ret = _Jv_jni_Call##intern##Method(o, c->vftbl, m, ap); \
+ va_end(ap); \
+ \
+ return ret; \
+}
+
+JNI_CALL_NONVIRTUAL_METHOD(Boolean, jboolean, Int)
+JNI_CALL_NONVIRTUAL_METHOD(Byte, jbyte, Int)
+JNI_CALL_NONVIRTUAL_METHOD(Char, jchar, Int)
+JNI_CALL_NONVIRTUAL_METHOD(Short, jshort, Int)
+JNI_CALL_NONVIRTUAL_METHOD(Int, jint, Int)
+JNI_CALL_NONVIRTUAL_METHOD(Long, jlong, Long)
+JNI_CALL_NONVIRTUAL_METHOD(Float, jfloat, Float)
+JNI_CALL_NONVIRTUAL_METHOD(Double, jdouble, Double)
+
+
+#define JNI_CALL_NONVIRTUAL_METHOD_V(name, type, intern) \
+type _Jv_JNI_CallNonvirtual##name##MethodV(JNIEnv *env, jobject obj, \
+ jclass clazz, jmethodID methodID, \
+ va_list args) \
+{ \
+ java_handle_t *o; \
+ classinfo *c; \
+ methodinfo *m; \
+ type ret; \
+ \
+ o = (java_handle_t *) obj; \
+ c = LLNI_classinfo_unwrap(clazz); \
+ m = (methodinfo *) methodID; \
+ \
+ ret = _Jv_jni_CallIntMethod(o, c->vftbl, m, args); \
+ \
+ return ret; \
+}
+
+JNI_CALL_NONVIRTUAL_METHOD_V(Boolean, jboolean, Int)
+JNI_CALL_NONVIRTUAL_METHOD_V(Byte, jbyte, Int)
+JNI_CALL_NONVIRTUAL_METHOD_V(Char, jchar, Int)
+JNI_CALL_NONVIRTUAL_METHOD_V(Short, jshort, Int)
+JNI_CALL_NONVIRTUAL_METHOD_V(Int, jint, Int)
+JNI_CALL_NONVIRTUAL_METHOD_V(Long, jlong, Long)
+JNI_CALL_NONVIRTUAL_METHOD_V(Float, jfloat, Float)
+JNI_CALL_NONVIRTUAL_METHOD_V(Double, jdouble, Double)
+
+
+#define JNI_CALL_NONVIRTUAL_METHOD_A(name, type, intern) \
+type _Jv_JNI_CallNonvirtual##name##MethodA(JNIEnv *env, jobject obj, \
+ jclass clazz, jmethodID methodID, \
+ const jvalue *args) \
+{ \
+ log_text("JNI-Call: CallNonvirtual##name##MethodA: IMPLEMENT ME!"); \
+ \
+ return 0; \
+}
+
+JNI_CALL_NONVIRTUAL_METHOD_A(Boolean, jboolean, Int)
+JNI_CALL_NONVIRTUAL_METHOD_A(Byte, jbyte, Int)
+JNI_CALL_NONVIRTUAL_METHOD_A(Char, jchar, Int)
+JNI_CALL_NONVIRTUAL_METHOD_A(Short, jshort, Int)
+JNI_CALL_NONVIRTUAL_METHOD_A(Int, jint, Int)
+JNI_CALL_NONVIRTUAL_METHOD_A(Long, jlong, Long)
+JNI_CALL_NONVIRTUAL_METHOD_A(Float, jfloat, Float)
+JNI_CALL_NONVIRTUAL_METHOD_A(Double, jdouble, Double)
- o = builtin_new(c);
-
- if (o == NULL)
- return NULL;
+jobject _Jv_JNI_CallNonvirtualObjectMethod(JNIEnv *env, jobject obj,
+ jclass clazz, jmethodID methodID,
+ ...)
+{
+ java_handle_t *o;
+ classinfo *c;
+ methodinfo *m;
+ java_handle_t *r;
+ va_list ap;
- /* call constructor */
+ o = (java_handle_t *) obj;
+ c = LLNI_classinfo_unwrap(clazz);
+ m = (methodinfo *) methodID;
va_start(ap, methodID);
- _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
+ r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, ap);
va_end(ap);
- return _Jv_JNI_NewLocalRef(env, (jobject) o);
+ return jni_NewLocalRef(env, (jobject) r);
}
-/* NewObjectV ******************************************************************
-
- Programmers place all arguments that are to be passed to the
- constructor in an args argument of type va_list that immediately
- follows the methodID argument. NewObjectV() accepts these
- arguments, and, in turn, passes them to the Java method that the
- programmer wishes to invoke.
-
-*******************************************************************************/
-
-jobject _Jv_JNI_NewObjectV(JNIEnv* env, jclass clazz, jmethodID methodID,
- va_list args)
+jobject _Jv_JNI_CallNonvirtualObjectMethodV(JNIEnv *env, jobject obj,
+ jclass clazz, jmethodID methodID,
+ va_list args)
{
- java_objectheader *o;
- classinfo *c;
- methodinfo *m;
-
- STATISTICS(jniinvokation());
+ java_handle_t *o;
+ classinfo *c;
+ methodinfo *m;
+ java_handle_t *r;
- c = (classinfo *) clazz;
+ o = (java_handle_t *) obj;
+ c = LLNI_classinfo_unwrap(clazz);
m = (methodinfo *) methodID;
- /* create object */
-
- o = builtin_new(c);
-
- if (o == NULL)
- return NULL;
+ r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, args);
- /* call constructor */
+ return jni_NewLocalRef(env, (jobject) r);
+}
- _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
- return _Jv_JNI_NewLocalRef(env, (jobject) o);
-}
-
-
-/* NewObjectA *****************************************************************
-
- Programmers place all arguments that are to be passed to the
- constructor in an args array of jvalues that immediately follows
- the methodID argument. NewObjectA() accepts the arguments in this
- array, and, in turn, passes them to the Java method that the
- programmer wishes to invoke.
-
-*******************************************************************************/
-
-jobject _Jv_JNI_NewObjectA(JNIEnv* env, jclass clazz, jmethodID methodID,
- const jvalue *args)
+jobject _Jv_JNI_CallNonvirtualObjectMethodA(JNIEnv *env, jobject obj,
+ jclass clazz, jmethodID methodID,
+ const jvalue *args)
{
- java_objectheader *o;
- classinfo *c;
- methodinfo *m;
-
- STATISTICS(jniinvokation());
-
- c = (classinfo *) clazz;
- m = (methodinfo *) methodID;
-
- /* create object */
-
- o = builtin_new(c);
-
- if (o == NULL)
- return NULL;
-
- /* call constructor */
-
- _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
+ log_text("JNI-Call: CallNonvirtualObjectMethodA: IMPLEMENT ME!");
- return _Jv_JNI_NewLocalRef(env, (jobject) o);
+ return jni_NewLocalRef(env, NULL);
}
-/* GetObjectClass **************************************************************
-
- Returns the class of an object.
-
-*******************************************************************************/
-
-jclass _Jv_JNI_GetObjectClass(JNIEnv *env, jobject obj)
+void _Jv_JNI_CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass clazz,
+ jmethodID methodID, ...)
{
- java_objectheader *o;
- classinfo *c;
-
- STATISTICS(jniinvokation());
+ java_handle_t *o;
+ classinfo *c;
+ methodinfo *m;
+ va_list ap;
- o = (java_objectheader *) obj;
-
- if ((o == NULL) || (o->vftbl == NULL))
- return NULL;
-
- c = o->vftbl->class;
+ o = (java_handle_t *) obj;
+ c = LLNI_classinfo_unwrap(clazz);
+ m = (methodinfo *) methodID;
- return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
+ va_start(ap, methodID);
+ _Jv_jni_CallVoidMethod(o, c->vftbl, m, ap);
+ va_end(ap);
}
-/* IsInstanceOf ****************************************************************
-
- Tests whether an object is an instance of a class.
-
-*******************************************************************************/
-
-jboolean _Jv_JNI_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)
+void _Jv_JNI_CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass clazz,
+ jmethodID methodID, va_list args)
{
- java_lang_Class *c;
- java_lang_Object *o;
+ java_handle_t *o;
+ classinfo *c;
+ methodinfo *m;
- STATISTICS(jniinvokation());
-
- c = (java_lang_Class *) clazz;
- o = (java_lang_Object *) obj;
+ o = (java_handle_t *) obj;
+ c = LLNI_classinfo_unwrap(clazz);
+ m = (methodinfo *) methodID;
- return _Jv_java_lang_Class_isInstance(c, o);
+ _Jv_jni_CallVoidMethod(o, c->vftbl, m, args);
}
-/* Reflection Support *********************************************************/
-
-/* FromReflectedMethod *********************************************************
-
- Converts java.lang.reflect.Method or java.lang.reflect.Constructor
- object to a method ID.
-
-*******************************************************************************/
-
-jmethodID _Jv_JNI_FromReflectedMethod(JNIEnv *env, jobject method)
-{
-#if defined(ENABLE_JAVASE)
- java_objectheader *o;
- classinfo *c;
- methodinfo *m;
- s4 slot;
-
- STATISTICS(jniinvokation());
-
- o = (java_objectheader *) method;
-
- if (o == NULL)
- return NULL;
-
- if (builtin_instanceof(o, class_java_lang_reflect_Method)) {
- java_lang_reflect_Method *rm;
-
- rm = (java_lang_reflect_Method *) method;
- c = (classinfo *) (rm->clazz);
- slot = rm->slot;
- }
- else if (builtin_instanceof(o, class_java_lang_reflect_Constructor)) {
- java_lang_reflect_Constructor *rc;
-
- rc = (java_lang_reflect_Constructor *) method;
- c = (classinfo *) (rc->clazz);
- slot = rc->slot;
- }
- else
- return NULL;
-
- m = &(c->methods[slot]);
-
- return (jmethodID) m;
-#else
- vm_abort("_Jv_JNI_FromReflectedMethod: not implemented in this configuration");
+void _Jv_JNI_CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass clazz,
+ jmethodID methodID, const jvalue * args)
+{
+ java_handle_t *o;
+ classinfo *c;
+ methodinfo *m;
- /* keep compiler happy */
+ o = (java_handle_t *) obj;
+ c = LLNI_classinfo_unwrap(clazz);
+ m = (methodinfo *) methodID;
- return NULL;
-#endif
+ _Jv_jni_CallVoidMethodA(o, c->vftbl, m, args);
}
-/* FromReflectedField **********************************************************
+/* Accessing Fields of Objects ************************************************/
- Converts a java.lang.reflect.Field to a field ID.
+/* GetFieldID ******************************************************************
+
+ Returns the field ID for an instance (nonstatic) field of a
+ class. The field is specified by its name and signature. The
+ Get<type>Field and Set<type>Field families of accessor functions
+ use field IDs to retrieve object fields.
*******************************************************************************/
-
-jfieldID _Jv_JNI_FromReflectedField(JNIEnv* env, jobject field)
+
+jfieldID _Jv_JNI_GetFieldID(JNIEnv *env, jclass clazz, const char *name,
+ const char *sig)
{
-#if defined(ENABLE_JAVASE)
- java_lang_reflect_Field *rf;
- classinfo *c;
- fieldinfo *f;
+ classinfo *c;
+ fieldinfo *f;
+ utf *uname;
+ utf *udesc;
STATISTICS(jniinvokation());
- rf = (java_lang_reflect_Field *) field;
-
- if (rf == NULL)
- return NULL;
+ c = LLNI_classinfo_unwrap(clazz);
- c = (classinfo *) rf->clazz;
- f = &(c->fields[rf->slot]);
+ /* XXX NPE check? */
- return (jfieldID) f;
-#else
- vm_abort("_Jv_JNI_FromReflectedField: not implemented in this configuration");
+ uname = utf_new_char((char *) name);
+ udesc = utf_new_char((char *) sig);
- /* keep compiler happy */
+ f = class_findfield(c, uname, udesc);
+
+ if (f == NULL)
+ exceptions_throw_nosuchfielderror(c, uname);
- return NULL;
-#endif
+ return (jfieldID) f;
}
-/* ToReflectedMethod ***********************************************************
+/* Get<type>Field Routines *****************************************************
- Converts a method ID derived from cls to an instance of the
- java.lang.reflect.Method class or to an instance of the
- java.lang.reflect.Constructor class.
+ This family of accessor routines returns the value of an instance
+ (nonstatic) field of an object. The field to access is specified by
+ a field ID obtained by calling GetFieldID().
*******************************************************************************/
-jobject _Jv_JNI_ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID,
- jboolean isStatic)
-{
-#if defined(ENABLE_JAVASE)
- methodinfo *m;
- java_lang_reflect_Constructor *rc;
- java_lang_reflect_Method *rm;
-
- STATISTICS(jniinvokation());
-
- m = (methodinfo *) methodID;
+#define GET_FIELD(o,type,f) \
+ *((type *) (((intptr_t) (o)) + ((intptr_t) ((fieldinfo *) (f))->offset)))
+
+#define JNI_GET_FIELD(name, type, intern) \
+type _Jv_JNI_Get##name##Field(JNIEnv *env, jobject obj, jfieldID fieldID) \
+{ \
+ intern ret; \
+ \
+ TRACEJNICALLS(("_Jv_JNI_Get" STR(name) "Field(env=%p, obj=%p, fieldId=%p)", env, obj, fieldID)); \
+ \
+ LLNI_CRITICAL_START; \
+ \
+ ret = GET_FIELD(LLNI_DIRECT((java_handle_t *) obj), intern, fieldID); \
+ \
+ LLNI_CRITICAL_END; \
+ \
+ return (type) ret; \
+}
+
+JNI_GET_FIELD(Boolean, jboolean, s4)
+JNI_GET_FIELD(Byte, jbyte, s4)
+JNI_GET_FIELD(Char, jchar, s4)
+JNI_GET_FIELD(Short, jshort, s4)
+JNI_GET_FIELD(Int, jint, s4)
+JNI_GET_FIELD(Long, jlong, s8)
+JNI_GET_FIELD(Float, jfloat, float)
+JNI_GET_FIELD(Double, jdouble, double)
- /* HotSpot does the same assert. */
- assert(((m->flags & ACC_STATIC) != 0) == (isStatic != 0));
+jobject _Jv_JNI_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID)
+{
+ java_handle_t *o;
- if (m->name == utf_init) {
- rc = reflect_constructor_new(m);
+ TRACEJNICALLS(("_Jv_JNI_GetObjectField(env=%p, obj=%p, fieldId=%p)", env, obj, fieldID));
- return (jobject) rc;
- }
- else {
- rm = reflect_method_new(m);
+ LLNI_CRITICAL_START;
- return (jobject) rm;
- }
-#else
- vm_abort("_Jv_JNI_ToReflectedMethod: not implemented in this configuration");
+ o = LLNI_WRAP(GET_FIELD(LLNI_DIRECT((java_handle_t *) obj), java_object_t*, fieldID));
- /* keep compiler happy */
+ LLNI_CRITICAL_END;
- return NULL;
-#endif
+ return jni_NewLocalRef(env, (jobject) o);
}
-/* ToReflectedField ************************************************************
+/* Set<type>Field Routines *****************************************************
- Converts a field ID derived from cls to an instance of the
- java.lang.reflect.Field class.
+ This family of accessor routines sets the value of an instance
+ (nonstatic) field of an object. The field to access is specified by
+ a field ID obtained by calling GetFieldID().
*******************************************************************************/
-jobject _Jv_JNI_ToReflectedField(JNIEnv* env, jclass cls, jfieldID fieldID,
- jboolean isStatic)
+#define SET_FIELD(o,type,f,value) \
+ *((type *) (((intptr_t) (o)) + ((intptr_t) ((fieldinfo *) (f))->offset))) = (type) (value)
+
+#define JNI_SET_FIELD(name, type, intern) \
+void _Jv_JNI_Set##name##Field(JNIEnv *env, jobject obj, jfieldID fieldID, \
+ type value) \
+{ \
+ TRACEJNICALLS(("_Jv_JNI_Set" STR(name) "Field(env=%p, obj=%p, fieldId=%p, value=%p)", env, obj, fieldID, value)); \
+ \
+ LLNI_CRITICAL_START; \
+ \
+ SET_FIELD(LLNI_DIRECT((java_handle_t *) obj), intern, fieldID, value); \
+ \
+ LLNI_CRITICAL_START; \
+}
+
+JNI_SET_FIELD(Boolean, jboolean, s4)
+JNI_SET_FIELD(Byte, jbyte, s4)
+JNI_SET_FIELD(Char, jchar, s4)
+JNI_SET_FIELD(Short, jshort, s4)
+JNI_SET_FIELD(Int, jint, s4)
+JNI_SET_FIELD(Long, jlong, s8)
+JNI_SET_FIELD(Float, jfloat, float)
+JNI_SET_FIELD(Double, jdouble, double)
+
+
+void _Jv_JNI_SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID,
+ jobject value)
{
- STATISTICS(jniinvokation());
+ TRACEJNICALLS(("_Jv_JNI_SetObjectField(env=%p, obj=%p, fieldId=%p, value=%p)", env, obj, fieldID, value));
- log_text("JNI-Call: ToReflectedField: IMPLEMENT ME!");
+ LLNI_CRITICAL_START;
- return NULL;
+ SET_FIELD(obj, java_handle_t*, fieldID, LLNI_UNWRAP((java_handle_t*) value));
+
+ LLNI_CRITICAL_END;
}
-/* Calling Instance Methods ***************************************************/
+/* Calling Static Methods *****************************************************/
-/* GetMethodID *****************************************************************
+/* GetStaticMethodID ***********************************************************
- Returns the method ID for an instance (nonstatic) method of a class
- or interface. The method may be defined in one of the clazz's
- superclasses and inherited by clazz. The method is determined by
- its name and signature.
+ Returns the method ID for a static method of a class. The method is
+ specified by its name and signature.
- GetMethodID() causes an uninitialized class to be initialized.
+ GetStaticMethodID() causes an uninitialized class to be
+ initialized.
*******************************************************************************/
-jmethodID _Jv_JNI_GetMethodID(JNIEnv* env, jclass clazz, const char *name,
- const char *sig)
+jmethodID _Jv_JNI_GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name,
+ const char *sig)
{
classinfo *c;
utf *uname;
utf *udesc;
methodinfo *m;
- STATISTICS(jniinvokation());
+ TRACEJNICALLS(("_Jv_JNI_GetStaticMethodID(env=%p, clazz=%p, name=%s, sig=%s)", env, clazz, name, sig));
- c = (classinfo *) clazz;
+ c = LLNI_classinfo_unwrap(clazz);
if (c == NULL)
return NULL;
if (!initialize_class(c))
return NULL;
- /* try to get the method of the class or one of it's superclasses */
+ /* try to get the static method of the class */
uname = utf_new_char((char *) name);
udesc = utf_new_char((char *) sig);
m = class_resolvemethod(c, uname, udesc);
- if ((m == NULL) || (m->flags & ACC_STATIC)) {
+ if ((m == NULL) || !(m->flags & ACC_STATIC)) {
exceptions_throw_nosuchmethoderror(c, uname, udesc);
return NULL;
}
-/* JNI-functions for calling instance methods *********************************/
+#define JNI_CALL_STATIC_METHOD(name, type, intern) \
+type _Jv_JNI_CallStatic##name##Method(JNIEnv *env, jclass clazz, \
+ jmethodID methodID, ...) \
+{ \
+ methodinfo *m; \
+ va_list ap; \
+ type res; \
+ \
+ m = (methodinfo *) methodID; \
+ \
+ va_start(ap, methodID); \
+ res = _Jv_jni_Call##intern##Method(NULL, NULL, m, ap); \
+ va_end(ap); \
+ \
+ return res; \
+}
+
+JNI_CALL_STATIC_METHOD(Boolean, jboolean, Int)
+JNI_CALL_STATIC_METHOD(Byte, jbyte, Int)
+JNI_CALL_STATIC_METHOD(Char, jchar, Int)
+JNI_CALL_STATIC_METHOD(Short, jshort, Int)
+JNI_CALL_STATIC_METHOD(Int, jint, Int)
+JNI_CALL_STATIC_METHOD(Long, jlong, Long)
+JNI_CALL_STATIC_METHOD(Float, jfloat, Float)
+JNI_CALL_STATIC_METHOD(Double, jdouble, Double)
+
+
+#define JNI_CALL_STATIC_METHOD_V(name, type, intern) \
+type _Jv_JNI_CallStatic##name##MethodV(JNIEnv *env, jclass clazz, \
+ jmethodID methodID, va_list args) \
+{ \
+ methodinfo *m; \
+ type res; \
+ \
+ m = (methodinfo *) methodID; \
+ \
+ res = _Jv_jni_Call##intern##Method(NULL, NULL, m, args); \
+ \
+ return res; \
+}
+
+JNI_CALL_STATIC_METHOD_V(Boolean, jboolean, Int)
+JNI_CALL_STATIC_METHOD_V(Byte, jbyte, Int)
+JNI_CALL_STATIC_METHOD_V(Char, jchar, Int)
+JNI_CALL_STATIC_METHOD_V(Short, jshort, Int)
+JNI_CALL_STATIC_METHOD_V(Int, jint, Int)
+JNI_CALL_STATIC_METHOD_V(Long, jlong, Long)
+JNI_CALL_STATIC_METHOD_V(Float, jfloat, Float)
+JNI_CALL_STATIC_METHOD_V(Double, jdouble, Double)
+
+
+#define JNI_CALL_STATIC_METHOD_A(name, type, intern) \
+type _Jv_JNI_CallStatic##name##MethodA(JNIEnv *env, jclass clazz, \
+ jmethodID methodID, const jvalue *args) \
+{ \
+ methodinfo *m; \
+ type res; \
+ \
+ m = (methodinfo *) methodID; \
+ \
+ res = _Jv_jni_Call##intern##MethodA(NULL, NULL, m, args); \
+ \
+ return res; \
+}
+
+JNI_CALL_STATIC_METHOD_A(Boolean, jboolean, Int)
+JNI_CALL_STATIC_METHOD_A(Byte, jbyte, Int)
+JNI_CALL_STATIC_METHOD_A(Char, jchar, Int)
+JNI_CALL_STATIC_METHOD_A(Short, jshort, Int)
+JNI_CALL_STATIC_METHOD_A(Int, jint, Int)
+JNI_CALL_STATIC_METHOD_A(Long, jlong, Long)
+JNI_CALL_STATIC_METHOD_A(Float, jfloat, Float)
+JNI_CALL_STATIC_METHOD_A(Double, jdouble, Double)
-jobject _Jv_JNI_CallObjectMethod(JNIEnv *env, jobject obj, jmethodID methodID,
- ...)
+
+jobject _Jv_JNI_CallStaticObjectMethod(JNIEnv *env, jclass clazz,
+ jmethodID methodID, ...)
{
- java_objectheader *o;
- methodinfo *m;
- java_objectheader *ret;
- va_list ap;
+ methodinfo *m;
+ java_handle_t *o;
+ va_list ap;
+
+ TRACEJNICALLS(("_Jv_JNI_CallStaticObjectMethod(env=%p, clazz=%p, methodID=%p, ...)", env, clazz, methodID));
- o = (java_objectheader *) obj;
m = (methodinfo *) methodID;
va_start(ap, methodID);
- ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, ap);
+ o = _Jv_jni_CallObjectMethod(NULL, NULL, m, ap);
va_end(ap);
- return _Jv_JNI_NewLocalRef(env, (jobject) ret);
+ return jni_NewLocalRef(env, (jobject) o);
}
-jobject _Jv_JNI_CallObjectMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
- va_list args)
+jobject _Jv_JNI_CallStaticObjectMethodV(JNIEnv *env, jclass clazz,
+ jmethodID methodID, va_list args)
{
- java_objectheader *o;
- methodinfo *m;
- java_objectheader *ret;
+ methodinfo *m;
+ java_handle_t *o;
+
+ TRACEJNICALLS(("_Jv_JNI_CallStaticObjectMethodV(env=%p, clazz=%p, methodID=%p, args=%p)", env, clazz, methodID, args));
- o = (java_objectheader *) obj;
m = (methodinfo *) methodID;
- ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, args);
+ o = _Jv_jni_CallObjectMethod(NULL, NULL, m, args);
- return _Jv_JNI_NewLocalRef(env, (jobject) ret);
+ return jni_NewLocalRef(env, (jobject) o);
}
-jobject _Jv_JNI_CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
- const jvalue *args)
+jobject _Jv_JNI_CallStaticObjectMethodA(JNIEnv *env, jclass clazz,
+ jmethodID methodID, const jvalue *args)
{
- java_objectheader *o;
- methodinfo *m;
- java_objectheader *ret;
+ methodinfo *m;
+ java_handle_t *o;
+
+ TRACEJNICALLS(("_Jv_JNI_CallStaticObjectMethodA(env=%p, clazz=%p, methodID=%p, args=%p)", env, clazz, methodID, args));
- o = (java_objectheader *) obj;
m = (methodinfo *) methodID;
- ret = _Jv_jni_CallObjectMethodA(o, o->vftbl, m, args);
+ o = _Jv_jni_CallObjectMethodA(NULL, NULL, m, args);
- return _Jv_JNI_NewLocalRef(env, (jobject) ret);
+ return jni_NewLocalRef(env, (jobject) o);
}
-jboolean _Jv_JNI_CallBooleanMethod(JNIEnv *env, jobject obj, jmethodID methodID,
- ...)
+void _Jv_JNI_CallStaticVoidMethod(JNIEnv *env, jclass clazz,
+ jmethodID methodID, ...)
{
- java_objectheader *o;
- methodinfo *m;
- va_list ap;
- jboolean b;
+ methodinfo *m;
+ va_list ap;
+
+ TRACEJNICALLS(("_Jv_JNI_CallStaticVoidMethod(env=%p, clazz=%p, methodID=%p, ...)", env, clazz, methodID));
- o = (java_objectheader *) obj;
m = (methodinfo *) methodID;
va_start(ap, methodID);
- b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
+ _Jv_jni_CallVoidMethod(NULL, NULL, m, ap);
va_end(ap);
-
- return b;
}
-jboolean _Jv_JNI_CallBooleanMethodV(JNIEnv *env, jobject obj,
- jmethodID methodID, va_list args)
+void _Jv_JNI_CallStaticVoidMethodV(JNIEnv *env, jclass clazz,
+ jmethodID methodID, va_list args)
{
- java_objectheader *o;
- methodinfo *m;
- jboolean b;
+ methodinfo *m;
- o = (java_objectheader *) obj;
- m = (methodinfo *) methodID;
+ TRACEJNICALLS(("_Jv_JNI_CallStaticVoidMethodV(env=%p, clazz=%p, methodID=%p, args=%p)", env, clazz, methodID, args));
- b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
+ m = (methodinfo *) methodID;
- return b;
+ _Jv_jni_CallVoidMethod(NULL, NULL, m, args);
}
-jboolean _Jv_JNI_CallBooleanMethodA(JNIEnv *env, jobject obj,
- jmethodID methodID, const jvalue *args)
+void _Jv_JNI_CallStaticVoidMethodA(JNIEnv *env, jclass clazz,
+ jmethodID methodID, const jvalue * args)
{
- java_objectheader *o;
- methodinfo *m;
- jboolean b;
+ methodinfo *m;
- o = (java_objectheader *) obj;
- m = (methodinfo *) methodID;
+ TRACEJNICALLS(("_Jv_JNI_CallStaticVoidMethodA(env=%p, clazz=%p, methodID=%p, args=%p)", env, clazz, methodID, args));
- b = _Jv_jni_CallIntMethodA(o, o->vftbl, m, args);
+ m = (methodinfo *) methodID;
- return b;
+ _Jv_jni_CallVoidMethodA(NULL, NULL, m, args);
}
-jbyte _Jv_JNI_CallByteMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
-{
- java_objectheader *o;
- methodinfo *m;
- va_list ap;
- jbyte b;
+/* Accessing Static Fields ****************************************************/
- o = (java_objectheader *) obj;
- m = (methodinfo *) methodID;
+/* GetStaticFieldID ************************************************************
- va_start(ap, methodID);
- b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
- va_end(ap);
-
- return b;
-
-}
-
-
-jbyte _Jv_JNI_CallByteMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
- va_list args)
-{
- java_objectheader *o;
- methodinfo *m;
- jbyte b;
-
- o = (java_objectheader *) obj;
- m = (methodinfo *) methodID;
-
- b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
-
- return b;
-}
-
-
-jbyte _Jv_JNI_CallByteMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
- const jvalue *args)
-{
- log_text("JNI-Call: CallByteMethodA: IMPLEMENT ME!");
-
- return 0;
-}
-
-
-jchar _Jv_JNI_CallCharMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
-{
- java_objectheader *o;
- methodinfo *m;
- va_list ap;
- jchar c;
-
- o = (java_objectheader *) obj;
- m = (methodinfo *) methodID;
-
- va_start(ap, methodID);
- c = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
- va_end(ap);
-
- return c;
-}
-
-
-jchar _Jv_JNI_CallCharMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
- va_list args)
-{
- java_objectheader *o;
- methodinfo *m;
- jchar c;
-
- o = (java_objectheader *) obj;
- m = (methodinfo *) methodID;
-
- c = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
-
- return c;
-}
-
-
-jchar _Jv_JNI_CallCharMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
- const jvalue *args)
-{
- log_text("JNI-Call: CallCharMethodA: IMPLEMENT ME!");
-
- return 0;
-}
-
-
-jshort _Jv_JNI_CallShortMethod(JNIEnv *env, jobject obj, jmethodID methodID,
- ...)
-{
- java_objectheader *o;
- methodinfo *m;
- va_list ap;
- jshort s;
-
- o = (java_objectheader *) obj;
- m = (methodinfo *) methodID;
-
- va_start(ap, methodID);
- s = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
- va_end(ap);
-
- return s;
-}
-
-
-jshort _Jv_JNI_CallShortMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
- va_list args)
-{
- java_objectheader *o;
- methodinfo *m;
- jshort s;
-
- o = (java_objectheader *) obj;
- m = (methodinfo *) methodID;
-
- s = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
-
- return s;
-}
-
-
-jshort _Jv_JNI_CallShortMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
- const jvalue *args)
-{
- log_text("JNI-Call: CallShortMethodA: IMPLEMENT ME!");
-
- return 0;
-}
-
-
-
-jint _Jv_JNI_CallIntMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
-{
- java_objectheader *o;
- methodinfo *m;
- va_list ap;
- jint i;
-
- o = (java_objectheader *) obj;
- m = (methodinfo *) methodID;
-
- va_start(ap, methodID);
- i = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
- va_end(ap);
-
- return i;
-}
-
-
-jint _Jv_JNI_CallIntMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
- va_list args)
-{
- java_objectheader *o;
- methodinfo *m;
- jint i;
-
- o = (java_objectheader *) obj;
- m = (methodinfo *) methodID;
-
- i = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
-
- return i;
-}
-
-
-jint _Jv_JNI_CallIntMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
- const jvalue *args)
-{
- log_text("JNI-Call: CallIntMethodA: IMPLEMENT ME!");
-
- return 0;
-}
-
-
-
-jlong _Jv_JNI_CallLongMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
-{
- java_objectheader *o;
- methodinfo *m;
- va_list ap;
- jlong l;
-
- o = (java_objectheader *) obj;
- m = (methodinfo *) methodID;
-
- va_start(ap, methodID);
- l = _Jv_jni_CallLongMethod(o, o->vftbl, m, ap);
- va_end(ap);
-
- return l;
-}
-
-
-jlong _Jv_JNI_CallLongMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
- va_list args)
-{
- java_objectheader *o;
- methodinfo *m;
- jlong l;
-
- o = (java_objectheader *) obj;
- m = (methodinfo *) methodID;
-
- l = _Jv_jni_CallLongMethod(o, o->vftbl, m, args);
-
- return l;
-}
-
-
-jlong _Jv_JNI_CallLongMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
- const jvalue *args)
-{
- log_text("JNI-Call: CallLongMethodA: IMPLEMENT ME!");
-
- return 0;
-}
-
-
-
-jfloat _Jv_JNI_CallFloatMethod(JNIEnv *env, jobject obj, jmethodID methodID,
- ...)
-{
- java_objectheader *o;
- methodinfo *m;
- va_list ap;
- jfloat f;
-
- o = (java_objectheader *) obj;
- m = (methodinfo *) methodID;
-
- va_start(ap, methodID);
- f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, ap);
- va_end(ap);
-
- return f;
-}
-
-
-jfloat _Jv_JNI_CallFloatMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
- va_list args)
-{
- java_objectheader *o;
- methodinfo *m;
- jfloat f;
-
- o = (java_objectheader *) obj;
- m = (methodinfo *) methodID;
-
- f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, args);
-
- return f;
-}
-
-
-jfloat _Jv_JNI_CallFloatMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
- const jvalue *args)
-{
- log_text("JNI-Call: CallFloatMethodA: IMPLEMENT ME!");
-
- return 0;
-}
-
-
-
-jdouble _Jv_JNI_CallDoubleMethod(JNIEnv *env, jobject obj, jmethodID methodID,
- ...)
-{
- java_objectheader *o;
- methodinfo *m;
- va_list ap;
- jdouble d;
-
- o = (java_objectheader *) obj;
- m = (methodinfo *) methodID;
-
- va_start(ap, methodID);
- d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, ap);
- va_end(ap);
-
- return d;
-}
-
-
-jdouble _Jv_JNI_CallDoubleMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
- va_list args)
-{
- java_objectheader *o;
- methodinfo *m;
- jdouble d;
-
- o = (java_objectheader *) obj;
- m = (methodinfo *) methodID;
-
- d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, args);
-
- return d;
-}
-
-
-jdouble _Jv_JNI_CallDoubleMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
- const jvalue *args)
-{
- log_text("JNI-Call: CallDoubleMethodA: IMPLEMENT ME!");
-
- return 0;
-}
-
-
-
-void _Jv_JNI_CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
-{
- java_objectheader *o;
- methodinfo *m;
- va_list ap;
-
- o = (java_objectheader *) obj;
- m = (methodinfo *) methodID;
-
- va_start(ap, methodID);
- _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
- va_end(ap);
-}
-
-
-void _Jv_JNI_CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
- va_list args)
-{
- java_objectheader *o;
- methodinfo *m;
-
- o = (java_objectheader *) obj;
- m = (methodinfo *) methodID;
-
- _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
-}
-
-
-void _Jv_JNI_CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
- const jvalue *args)
-{
- java_objectheader *o;
- methodinfo *m;
-
- o = (java_objectheader *) obj;
- m = (methodinfo *) methodID;
-
- _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
-}
-
-
-
-jobject _Jv_JNI_CallNonvirtualObjectMethod(JNIEnv *env, jobject obj,
- jclass clazz, jmethodID methodID,
- ...)
-{
- java_objectheader *o;
- classinfo *c;
- methodinfo *m;
- java_objectheader *r;
- va_list ap;
-
- o = (java_objectheader *) obj;
- c = (classinfo *) clazz;
- m = (methodinfo *) methodID;
-
- va_start(ap, methodID);
- r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, ap);
- va_end(ap);
-
- return _Jv_JNI_NewLocalRef(env, (jobject) r);
-}
-
-
-jobject _Jv_JNI_CallNonvirtualObjectMethodV(JNIEnv *env, jobject obj,
- jclass clazz, jmethodID methodID,
- va_list args)
-{
- java_objectheader *o;
- classinfo *c;
- methodinfo *m;
- java_objectheader *r;
-
- o = (java_objectheader *) obj;
- c = (classinfo *) clazz;
- m = (methodinfo *) methodID;
-
- r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, args);
-
- return _Jv_JNI_NewLocalRef(env, (jobject) r);
-}
-
-
-jobject _Jv_JNI_CallNonvirtualObjectMethodA(JNIEnv *env, jobject obj,
- jclass clazz, jmethodID methodID,
- const jvalue *args)
-{
- log_text("JNI-Call: CallNonvirtualObjectMethodA: IMPLEMENT ME!");
-
- return _Jv_JNI_NewLocalRef(env, NULL);
-}
-
-
-
-jboolean _Jv_JNI_CallNonvirtualBooleanMethod(JNIEnv *env, jobject obj,
- jclass clazz, jmethodID methodID,
- ...)
-{
- java_objectheader *o;
- classinfo *c;
- methodinfo *m;
- va_list ap;
- jboolean b;
-
- o = (java_objectheader *) obj;
- c = (classinfo *) clazz;
- m = (methodinfo *) methodID;
-
- va_start(ap, methodID);
- b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
- va_end(ap);
-
- return b;
-}
-
-
-jboolean _Jv_JNI_CallNonvirtualBooleanMethodV(JNIEnv *env, jobject obj,
- jclass clazz, jmethodID methodID,
- va_list args)
-{
- java_objectheader *o;
- classinfo *c;
- methodinfo *m;
- jboolean b;
-
- o = (java_objectheader *) obj;
- c = (classinfo *) clazz;
- m = (methodinfo *) methodID;
-
- b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
-
- return b;
-}
-
-
-jboolean _Jv_JNI_CallNonvirtualBooleanMethodA(JNIEnv *env, jobject obj,
- jclass clazz, jmethodID methodID,
- const jvalue *args)
-{
- log_text("JNI-Call: CallNonvirtualBooleanMethodA: IMPLEMENT ME!");
-
- return 0;
-}
-
-
-jbyte _Jv_JNI_CallNonvirtualByteMethod(JNIEnv *env, jobject obj, jclass clazz,
- jmethodID methodID, ...)
-{
- java_objectheader *o;
- classinfo *c;
- methodinfo *m;
- va_list ap;
- jbyte b;
-
- o = (java_objectheader *) obj;
- c = (classinfo *) clazz;
- m = (methodinfo *) methodID;
-
- va_start(ap, methodID);
- b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
- va_end(ap);
-
- return b;
-}
-
-
-jbyte _Jv_JNI_CallNonvirtualByteMethodV(JNIEnv *env, jobject obj, jclass clazz,
- jmethodID methodID, va_list args)
-{
- java_objectheader *o;
- classinfo *c;
- methodinfo *m;
- jbyte b;
-
- o = (java_objectheader *) obj;
- c = (classinfo *) clazz;
- m = (methodinfo *) methodID;
-
- b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
-
- return b;
-}
-
-
-jbyte _Jv_JNI_CallNonvirtualByteMethodA(JNIEnv *env, jobject obj, jclass clazz,
- jmethodID methodID, const jvalue *args)
-{
- log_text("JNI-Call: CallNonvirtualByteMethodA: IMPLEMENT ME!");
-
- return 0;
-}
-
-
-
-jchar _Jv_JNI_CallNonvirtualCharMethod(JNIEnv *env, jobject obj, jclass clazz,
- jmethodID methodID, ...)
-{
- java_objectheader *o;
- classinfo *c;
- methodinfo *m;
- va_list ap;
- jchar ch;
-
- o = (java_objectheader *) obj;
- c = (classinfo *) clazz;
- m = (methodinfo *) methodID;
-
- va_start(ap, methodID);
- ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
- va_end(ap);
-
- return ch;
-}
-
-
-jchar _Jv_JNI_CallNonvirtualCharMethodV(JNIEnv *env, jobject obj, jclass clazz,
- jmethodID methodID, va_list args)
-{
- java_objectheader *o;
- classinfo *c;
- methodinfo *m;
- jchar ch;
-
- o = (java_objectheader *) obj;
- c = (classinfo *) clazz;
- m = (methodinfo *) methodID;
-
- ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
-
- return ch;
-}
-
-
-jchar _Jv_JNI_CallNonvirtualCharMethodA(JNIEnv *env, jobject obj, jclass clazz,
- jmethodID methodID, const jvalue *args)
-{
- log_text("JNI-Call: CallNonvirtualCharMethodA: IMPLEMENT ME!");
-
- return 0;
-}
-
-
-
-jshort _Jv_JNI_CallNonvirtualShortMethod(JNIEnv *env, jobject obj,
- jclass clazz, jmethodID methodID, ...)
-{
- java_objectheader *o;
- classinfo *c;
- methodinfo *m;
- va_list ap;
- jshort s;
-
- o = (java_objectheader *) obj;
- c = (classinfo *) clazz;
- m = (methodinfo *) methodID;
-
- va_start(ap, methodID);
- s = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
- va_end(ap);
-
- return s;
-}
-
-
-jshort _Jv_JNI_CallNonvirtualShortMethodV(JNIEnv *env, jobject obj,
- jclass clazz, jmethodID methodID,
- va_list args)
-{
- java_objectheader *o;
- classinfo *c;
- methodinfo *m;
- jshort s;
-
- o = (java_objectheader *) obj;
- c = (classinfo *) clazz;
- m = (methodinfo *) methodID;
-
- s = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
-
- return s;
-}
-
-
-jshort _Jv_JNI_CallNonvirtualShortMethodA(JNIEnv *env, jobject obj,
- jclass clazz, jmethodID methodID,
- const jvalue *args)
-{
- log_text("JNI-Call: CallNonvirtualShortMethodA: IMPLEMENT ME!");
-
- return 0;
-}
-
-
-
-jint _Jv_JNI_CallNonvirtualIntMethod(JNIEnv *env, jobject obj, jclass clazz,
- jmethodID methodID, ...)
-{
- java_objectheader *o;
- classinfo *c;
- methodinfo *m;
- va_list ap;
- jint i;
-
- o = (java_objectheader *) obj;
- c = (classinfo *) clazz;
- m = (methodinfo *) methodID;
-
- va_start(ap, methodID);
- i = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
- va_end(ap);
-
- return i;
-}
-
-
-jint _Jv_JNI_CallNonvirtualIntMethodV(JNIEnv *env, jobject obj, jclass clazz,
- jmethodID methodID, va_list args)
-{
- java_objectheader *o;
- classinfo *c;
- methodinfo *m;
- jint i;
-
- o = (java_objectheader *) obj;
- c = (classinfo *) clazz;
- m = (methodinfo *) methodID;
-
- i = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
-
- return i;
-}
-
-
-jint _Jv_JNI_CallNonvirtualIntMethodA(JNIEnv *env, jobject obj, jclass clazz,
- jmethodID methodID, const jvalue *args)
-{
- log_text("JNI-Call: CallNonvirtualIntMethodA: IMPLEMENT ME!");
-
- return 0;
-}
-
-
-
-jlong _Jv_JNI_CallNonvirtualLongMethod(JNIEnv *env, jobject obj, jclass clazz,
- jmethodID methodID, ...)
-{
- java_objectheader *o;
- classinfo *c;
- methodinfo *m;
- va_list ap;
- jlong l;
-
- o = (java_objectheader *) obj;
- c = (classinfo *) clazz;
- m = (methodinfo *) methodID;
-
- va_start(ap, methodID);
- l = _Jv_jni_CallLongMethod(o, c->vftbl, m, ap);
- va_end(ap);
-
- return l;
-}
-
-
-jlong _Jv_JNI_CallNonvirtualLongMethodV(JNIEnv *env, jobject obj, jclass clazz,
- jmethodID methodID, va_list args)
-{
- java_objectheader *o;
- classinfo *c;
- methodinfo *m;
- jlong l;
-
- o = (java_objectheader *) obj;
- c = (classinfo *) clazz;
- m = (methodinfo *) methodID;
-
- l = _Jv_jni_CallLongMethod(o, c->vftbl, m, args);
-
- return l;
-}
-
-
-jlong _Jv_JNI_CallNonvirtualLongMethodA(JNIEnv *env, jobject obj, jclass clazz,
- jmethodID methodID, const jvalue *args)
-{
- log_text("JNI-Call: CallNonvirtualLongMethodA: IMPLEMENT ME!");
-
- return 0;
-}
-
-
-
-jfloat _Jv_JNI_CallNonvirtualFloatMethod(JNIEnv *env, jobject obj,
- jclass clazz, jmethodID methodID, ...)
-{
- java_objectheader *o;
- classinfo *c;
- methodinfo *m;
- va_list ap;
- jfloat f;
-
- o = (java_objectheader *) obj;
- c = (classinfo *) clazz;
- m = (methodinfo *) methodID;
-
- va_start(ap, methodID);
- f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, ap);
- va_end(ap);
-
- return f;
-}
-
-
-jfloat _Jv_JNI_CallNonvirtualFloatMethodV(JNIEnv *env, jobject obj,
- jclass clazz, jmethodID methodID,
- va_list args)
-{
- java_objectheader *o;
- classinfo *c;
- methodinfo *m;
- jfloat f;
-
- o = (java_objectheader *) obj;
- c = (classinfo *) clazz;
- m = (methodinfo *) methodID;
-
- f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, args);
-
- return f;
-}
-
-
-jfloat _Jv_JNI_CallNonvirtualFloatMethodA(JNIEnv *env, jobject obj,
- jclass clazz, jmethodID methodID,
- const jvalue *args)
-{
- log_text("JNI-Call: CallNonvirtualFloatMethodA: IMPLEMENT ME!");
-
- return 0;
-}
-
-
-
-jdouble _Jv_JNI_CallNonvirtualDoubleMethod(JNIEnv *env, jobject obj,
- jclass clazz, jmethodID methodID,
- ...)
-{
- java_objectheader *o;
- classinfo *c;
- methodinfo *m;
- va_list ap;
- jdouble d;
-
- o = (java_objectheader *) obj;
- c = (classinfo *) clazz;
- m = (methodinfo *) methodID;
-
- va_start(ap, methodID);
- d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, ap);
- va_end(ap);
-
- return d;
-}
-
-
-jdouble _Jv_JNI_CallNonvirtualDoubleMethodV(JNIEnv *env, jobject obj,
- jclass clazz, jmethodID methodID,
- va_list args)
-{
- java_objectheader *o;
- classinfo *c;
- methodinfo *m;
- jdouble d;
-
- o = (java_objectheader *) obj;
- c = (classinfo *) clazz;
- m = (methodinfo *) methodID;
-
- d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, args);
-
- return d;
-}
-
-
-jdouble _Jv_JNI_CallNonvirtualDoubleMethodA(JNIEnv *env, jobject obj,
- jclass clazz, jmethodID methodID,
- const jvalue *args)
-{
- log_text("JNI-Call: CallNonvirtualDoubleMethodA: IMPLEMENT ME!");
-
- return 0;
-}
-
-
-
-void _Jv_JNI_CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass clazz,
- jmethodID methodID, ...)
-{
- java_objectheader *o;
- classinfo *c;
- methodinfo *m;
- va_list ap;
-
- o = (java_objectheader *) obj;
- c = (classinfo *) clazz;
- m = (methodinfo *) methodID;
-
- va_start(ap, methodID);
- _Jv_jni_CallVoidMethod(o, c->vftbl, m, ap);
- va_end(ap);
-}
-
-
-void _Jv_JNI_CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass clazz,
- jmethodID methodID, va_list args)
-{
- java_objectheader *o;
- classinfo *c;
- methodinfo *m;
-
- o = (java_objectheader *) obj;
- c = (classinfo *) clazz;
- m = (methodinfo *) methodID;
-
- _Jv_jni_CallVoidMethod(o, c->vftbl, m, args);
-}
-
-
-void _Jv_JNI_CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass clazz,
- jmethodID methodID, const jvalue * args)
-{
- java_objectheader *o;
- classinfo *c;
- methodinfo *m;
-
- o = (java_objectheader *) obj;
- c = (classinfo *) clazz;
- m = (methodinfo *) methodID;
-
- _Jv_jni_CallVoidMethodA(o, c->vftbl, m, args);
-}
-
-
-/* Accessing Fields of Objects ************************************************/
-
-/* GetFieldID ******************************************************************
-
- Returns the field ID for an instance (nonstatic) field of a
- class. The field is specified by its name and signature. The
- Get<type>Field and Set<type>Field families of accessor functions
- use field IDs to retrieve object fields.
-
-*******************************************************************************/
-
-jfieldID _Jv_JNI_GetFieldID(JNIEnv *env, jclass clazz, const char *name,
- const char *sig)
-{
- classinfo *c;
- fieldinfo *f;
- utf *uname;
- utf *udesc;
-
- STATISTICS(jniinvokation());
-
- c = (classinfo *) clazz;
-
- /* XXX NPE check? */
-
- uname = utf_new_char((char *) name);
- udesc = utf_new_char((char *) sig);
-
- f = class_findfield(c, uname, udesc);
-
- if (f == NULL)
- exceptions_throw_nosuchfielderror(c, uname);
-
- return (jfieldID) f;
-}
-
-
-/* Get<type>Field Routines *****************************************************
-
- This family of accessor routines returns the value of an instance
- (nonstatic) field of an object. The field to access is specified by
- a field ID obtained by calling GetFieldID().
-
-*******************************************************************************/
-
-jobject _Jv_JNI_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID)
-{
- java_objectheader *o;
-
- STATISTICS(jniinvokation());
-
- o = GET_FIELD(obj, java_objectheader*, fieldID);
-
- return _Jv_JNI_NewLocalRef(env, (jobject) o);
-}
-
-
-jboolean _Jv_JNI_GetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID)
-{
- s4 i;
-
- STATISTICS(jniinvokation());
-
- i = GET_FIELD(obj, s4, fieldID);
-
- return (jboolean) i;
-}
-
-
-jbyte _Jv_JNI_GetByteField(JNIEnv *env, jobject obj, jfieldID fieldID)
-{
- s4 i;
-
- STATISTICS(jniinvokation());
-
- i = GET_FIELD(obj, s4, fieldID);
-
- return (jbyte) i;
-}
-
-
-jchar _Jv_JNI_GetCharField(JNIEnv *env, jobject obj, jfieldID fieldID)
-{
- s4 i;
-
- STATISTICS(jniinvokation());
-
- i = GET_FIELD(obj, s4, fieldID);
-
- return (jchar) i;
-}
-
-
-jshort _Jv_JNI_GetShortField(JNIEnv *env, jobject obj, jfieldID fieldID)
-{
- s4 i;
-
- STATISTICS(jniinvokation());
-
- i = GET_FIELD(obj, s4, fieldID);
-
- return (jshort) i;
-}
-
-
-jint _Jv_JNI_GetIntField(JNIEnv *env, jobject obj, jfieldID fieldID)
-{
- java_objectheader *o;
- fieldinfo *f;
- s4 i;
-
- STATISTICS(jniinvokation());
-
- o = (java_objectheader *) obj;
- f = (fieldinfo *) fieldID;
-
- i = GET_FIELD(o, s4, f);
-
- return i;
-}
-
-
-jlong _Jv_JNI_GetLongField(JNIEnv *env, jobject obj, jfieldID fieldID)
-{
- s8 l;
-
- STATISTICS(jniinvokation());
-
- l = GET_FIELD(obj, s8, fieldID);
-
- return l;
-}
-
-
-jfloat _Jv_JNI_GetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID)
-{
- float f;
-
- STATISTICS(jniinvokation());
-
- f = GET_FIELD(obj, float, fieldID);
-
- return f;
-}
-
-
-jdouble _Jv_JNI_GetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID)
-{
- double d;
-
- STATISTICS(jniinvokation());
-
- d = GET_FIELD(obj, double, fieldID);
-
- return d;
-}
-
-
-/* Set<type>Field Routines *****************************************************
-
- This family of accessor routines sets the value of an instance
- (nonstatic) field of an object. The field to access is specified by
- a field ID obtained by calling GetFieldID().
-
-*******************************************************************************/
-
-void _Jv_JNI_SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID,
- jobject value)
-{
- STATISTICS(jniinvokation());
-
- SET_FIELD(obj, java_objectheader*, fieldID, value);
-}
-
-
-void _Jv_JNI_SetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID,
- jboolean value)
-{
- STATISTICS(jniinvokation());
-
- SET_FIELD(obj, s4, fieldID, value);
-}
-
-
-void _Jv_JNI_SetByteField(JNIEnv *env, jobject obj, jfieldID fieldID,
- jbyte value)
-{
- STATISTICS(jniinvokation());
-
- SET_FIELD(obj, s4, fieldID, value);
-}
-
-
-void _Jv_JNI_SetCharField(JNIEnv *env, jobject obj, jfieldID fieldID,
- jchar value)
-{
- STATISTICS(jniinvokation());
-
- SET_FIELD(obj, s4, fieldID, value);
-}
-
-
-void _Jv_JNI_SetShortField(JNIEnv *env, jobject obj, jfieldID fieldID,
- jshort value)
-{
- STATISTICS(jniinvokation());
-
- SET_FIELD(obj, s4, fieldID, value);
-}
-
-
-void _Jv_JNI_SetIntField(JNIEnv *env, jobject obj, jfieldID fieldID, jint value)
-{
- STATISTICS(jniinvokation());
-
- SET_FIELD(obj, s4, fieldID, value);
-}
-
-
-void _Jv_JNI_SetLongField(JNIEnv *env, jobject obj, jfieldID fieldID,
- jlong value)
-{
- STATISTICS(jniinvokation());
-
- SET_FIELD(obj, s8, fieldID, value);
-}
-
-
-void _Jv_JNI_SetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID,
- jfloat value)
-{
- STATISTICS(jniinvokation());
-
- SET_FIELD(obj, float, fieldID, value);
-}
-
-
-void _Jv_JNI_SetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID,
- jdouble value)
-{
- STATISTICS(jniinvokation());
-
- SET_FIELD(obj, double, fieldID, value);
-}
-
-
-/* Calling Static Methods *****************************************************/
-
-/* GetStaticMethodID ***********************************************************
-
- Returns the method ID for a static method of a class. The method is
- specified by its name and signature.
-
- GetStaticMethodID() causes an uninitialized class to be
- initialized.
-
-*******************************************************************************/
-
-jmethodID _Jv_JNI_GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name,
- const char *sig)
-{
- classinfo *c;
- utf *uname;
- utf *udesc;
- methodinfo *m;
-
- STATISTICS(jniinvokation());
-
- c = (classinfo *) clazz;
-
- if (!c)
- return NULL;
-
- if (!(c->state & CLASS_INITIALIZED))
- if (!initialize_class(c))
- return NULL;
-
- /* try to get the static method of the class */
-
- uname = utf_new_char((char *) name);
- udesc = utf_new_char((char *) sig);
-
- m = class_resolvemethod(c, uname, udesc);
-
- if ((m == NULL) || !(m->flags & ACC_STATIC)) {
- exceptions_throw_nosuchmethoderror(c, uname, udesc);
-
- return NULL;
- }
-
- return (jmethodID) m;
-}
-
-
-jobject _Jv_JNI_CallStaticObjectMethod(JNIEnv *env, jclass clazz,
- jmethodID methodID, ...)
-{
- methodinfo *m;
- java_objectheader *o;
- va_list ap;
-
- m = (methodinfo *) methodID;
-
- va_start(ap, methodID);
- o = _Jv_jni_CallObjectMethod(NULL, NULL, m, ap);
- va_end(ap);
-
- return _Jv_JNI_NewLocalRef(env, (jobject) o);
-}
-
-
-jobject _Jv_JNI_CallStaticObjectMethodV(JNIEnv *env, jclass clazz,
- jmethodID methodID, va_list args)
-{
- methodinfo *m;
- java_objectheader *o;
-
- m = (methodinfo *) methodID;
-
- o = _Jv_jni_CallObjectMethod(NULL, NULL, m, args);
-
- return _Jv_JNI_NewLocalRef(env, (jobject) o);
-}
-
-
-jobject _Jv_JNI_CallStaticObjectMethodA(JNIEnv *env, jclass clazz,
- jmethodID methodID, const jvalue *args)
-{
- methodinfo *m;
- java_objectheader *o;
-
- m = (methodinfo *) methodID;
-
- o = _Jv_jni_CallObjectMethodA(NULL, NULL, m, args);
-
- return _Jv_JNI_NewLocalRef(env, (jobject) o);
-}
-
-
-jboolean _Jv_JNI_CallStaticBooleanMethod(JNIEnv *env, jclass clazz,
- jmethodID methodID, ...)
-{
- methodinfo *m;
- va_list ap;
- jboolean b;
-
- m = (methodinfo *) methodID;
-
- va_start(ap, methodID);
- b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
- va_end(ap);
-
- return b;
-}
-
-
-jboolean _Jv_JNI_CallStaticBooleanMethodV(JNIEnv *env, jclass clazz,
- jmethodID methodID, va_list args)
-{
- methodinfo *m;
- jboolean b;
-
- m = (methodinfo *) methodID;
-
- b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
-
- return b;
-}
-
-
-jboolean _Jv_JNI_CallStaticBooleanMethodA(JNIEnv *env, jclass clazz,
- jmethodID methodID, const jvalue *args)
-{
- methodinfo *m;
- jboolean b;
-
- m = (methodinfo *) methodID;
-
- b = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
-
- return b;
-}
-
-
-jbyte _Jv_JNI_CallStaticByteMethod(JNIEnv *env, jclass clazz,
- jmethodID methodID, ...)
-{
- methodinfo *m;
- va_list ap;
- jbyte b;
-
- m = (methodinfo *) methodID;
-
- va_start(ap, methodID);
- b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
- va_end(ap);
-
- return b;
-}
-
-
-jbyte _Jv_JNI_CallStaticByteMethodV(JNIEnv *env, jclass clazz,
- jmethodID methodID, va_list args)
-{
- methodinfo *m;
- jbyte b;
-
- m = (methodinfo *) methodID;
-
- b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
-
- return b;
-}
-
-
-jbyte _Jv_JNI_CallStaticByteMethodA(JNIEnv *env, jclass clazz,
- jmethodID methodID, const jvalue *args)
-{
- methodinfo *m;
- jbyte b;
-
- m = (methodinfo *) methodID;
-
- b = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
-
- return b;
-}
-
-
-jchar _Jv_JNI_CallStaticCharMethod(JNIEnv *env, jclass clazz,
- jmethodID methodID, ...)
-{
- methodinfo *m;
- va_list ap;
- jchar c;
-
- m = (methodinfo *) methodID;
-
- va_start(ap, methodID);
- c = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
- va_end(ap);
-
- return c;
-}
-
-
-jchar _Jv_JNI_CallStaticCharMethodV(JNIEnv *env, jclass clazz,
- jmethodID methodID, va_list args)
-{
- methodinfo *m;
- jchar c;
-
- m = (methodinfo *) methodID;
-
- c = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
-
- return c;
-}
-
-
-jchar _Jv_JNI_CallStaticCharMethodA(JNIEnv *env, jclass clazz,
- jmethodID methodID, const jvalue *args)
-{
- methodinfo *m;
- jchar c;
-
- m = (methodinfo *) methodID;
-
- c = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
-
- return c;
-}
-
-
-jshort _Jv_JNI_CallStaticShortMethod(JNIEnv *env, jclass clazz,
- jmethodID methodID, ...)
-{
- methodinfo *m;
- va_list ap;
- jshort s;
-
- m = (methodinfo *) methodID;
-
- va_start(ap, methodID);
- s = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
- va_end(ap);
-
- return s;
-}
-
-
-jshort _Jv_JNI_CallStaticShortMethodV(JNIEnv *env, jclass clazz,
- jmethodID methodID, va_list args)
-{
- methodinfo *m;
- jshort s;
-
- m = (methodinfo *) methodID;
-
- s = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
-
- return s;
-}
-
-
-jshort _Jv_JNI_CallStaticShortMethodA(JNIEnv *env, jclass clazz,
- jmethodID methodID, const jvalue *args)
-{
- methodinfo *m;
- jshort s;
-
- m = (methodinfo *) methodID;
-
- s = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
-
- return s;
-}
-
-
-jint _Jv_JNI_CallStaticIntMethod(JNIEnv *env, jclass clazz, jmethodID methodID,
- ...)
-{
- methodinfo *m;
- va_list ap;
- jint i;
-
- m = (methodinfo *) methodID;
-
- va_start(ap, methodID);
- i = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
- va_end(ap);
-
- return i;
-}
-
-
-jint _Jv_JNI_CallStaticIntMethodV(JNIEnv *env, jclass clazz,
- jmethodID methodID, va_list args)
-{
- methodinfo *m;
- jint i;
-
- m = (methodinfo *) methodID;
-
- i = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
-
- return i;
-}
-
-
-jint _Jv_JNI_CallStaticIntMethodA(JNIEnv *env, jclass clazz,
- jmethodID methodID, const jvalue *args)
-{
- methodinfo *m;
- jint i;
-
- m = (methodinfo *) methodID;
-
- i = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
-
- return i;
-}
-
-
-jlong _Jv_JNI_CallStaticLongMethod(JNIEnv *env, jclass clazz,
- jmethodID methodID, ...)
-{
- methodinfo *m;
- va_list ap;
- jlong l;
-
- m = (methodinfo *) methodID;
-
- va_start(ap, methodID);
- l = _Jv_jni_CallLongMethod(NULL, NULL, m, ap);
- va_end(ap);
-
- return l;
-}
-
-
-jlong _Jv_JNI_CallStaticLongMethodV(JNIEnv *env, jclass clazz,
- jmethodID methodID, va_list args)
-{
- methodinfo *m;
- jlong l;
-
- m = (methodinfo *) methodID;
-
- l = _Jv_jni_CallLongMethod(NULL, NULL, m, args);
-
- return l;
-}
-
-
-jlong _Jv_JNI_CallStaticLongMethodA(JNIEnv *env, jclass clazz,
- jmethodID methodID, const jvalue *args)
-{
- methodinfo *m;
- jlong l;
-
- m = (methodinfo *) methodID;
-
- l = _Jv_jni_CallLongMethodA(NULL, NULL, m, args);
-
- return l;
-}
-
-
-
-jfloat _Jv_JNI_CallStaticFloatMethod(JNIEnv *env, jclass clazz,
- jmethodID methodID, ...)
-{
- methodinfo *m;
- va_list ap;
- jfloat f;
-
- m = (methodinfo *) methodID;
-
- va_start(ap, methodID);
- f = _Jv_jni_CallFloatMethod(NULL, NULL, m, ap);
- va_end(ap);
-
- return f;
-}
-
-
-jfloat _Jv_JNI_CallStaticFloatMethodV(JNIEnv *env, jclass clazz,
- jmethodID methodID, va_list args)
-{
- methodinfo *m;
- jfloat f;
-
- m = (methodinfo *) methodID;
-
- f = _Jv_jni_CallFloatMethod(NULL, NULL, m, args);
-
- return f;
-}
-
-
-jfloat _Jv_JNI_CallStaticFloatMethodA(JNIEnv *env, jclass clazz,
- jmethodID methodID, const jvalue *args)
-{
- methodinfo *m;
- jfloat f;
-
- m = (methodinfo *) methodID;
-
- f = _Jv_jni_CallFloatMethodA(NULL, NULL, m, args);
-
- return f;
-}
-
-
-jdouble _Jv_JNI_CallStaticDoubleMethod(JNIEnv *env, jclass clazz,
- jmethodID methodID, ...)
-{
- methodinfo *m;
- va_list ap;
- jdouble d;
-
- m = (methodinfo *) methodID;
-
- va_start(ap, methodID);
- d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, ap);
- va_end(ap);
-
- return d;
-}
-
-
-jdouble _Jv_JNI_CallStaticDoubleMethodV(JNIEnv *env, jclass clazz,
- jmethodID methodID, va_list args)
-{
- methodinfo *m;
- jdouble d;
-
- m = (methodinfo *) methodID;
-
- d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, args);
-
- return d;
-}
-
-
-jdouble _Jv_JNI_CallStaticDoubleMethodA(JNIEnv *env, jclass clazz,
- jmethodID methodID, const jvalue *args)
-{
- methodinfo *m;
- jdouble d;
-
- m = (methodinfo *) methodID;
-
- d = _Jv_jni_CallDoubleMethodA(NULL, NULL, m, args);
-
- return d;
-}
-
-
-void _Jv_JNI_CallStaticVoidMethod(JNIEnv *env, jclass clazz,
- jmethodID methodID, ...)
-{
- methodinfo *m;
- va_list ap;
-
- m = (methodinfo *) methodID;
-
- va_start(ap, methodID);
- _Jv_jni_CallVoidMethod(NULL, NULL, m, ap);
- va_end(ap);
-}
-
-
-void _Jv_JNI_CallStaticVoidMethodV(JNIEnv *env, jclass clazz,
- jmethodID methodID, va_list args)
-{
- methodinfo *m;
-
- m = (methodinfo *) methodID;
-
- _Jv_jni_CallVoidMethod(NULL, NULL, m, args);
-}
-
-
-void _Jv_JNI_CallStaticVoidMethodA(JNIEnv *env, jclass clazz,
- jmethodID methodID, const jvalue * args)
-{
- methodinfo *m;
-
- m = (methodinfo *) methodID;
-
- _Jv_jni_CallVoidMethodA(NULL, NULL, m, args);
-}
-
-
-/* Accessing Static Fields ****************************************************/
-
-/* GetStaticFieldID ************************************************************
-
- Returns the field ID for a static field of a class. The field is
- specified by its name and signature. The GetStatic<type>Field and
- SetStatic<type>Field families of accessor functions use field IDs
- to retrieve static fields.
-
-*******************************************************************************/
-
-jfieldID _Jv_JNI_GetStaticFieldID(JNIEnv *env, jclass clazz, const char *name,
- const char *sig)
-{
- classinfo *c;
- fieldinfo *f;
- utf *uname;
- utf *usig;
-
- STATISTICS(jniinvokation());
-
- c = (classinfo *) clazz;
-
- uname = utf_new_char((char *) name);
- usig = utf_new_char((char *) sig);
-
- f = class_findfield(c, uname, usig);
-
- if (f == NULL)
- exceptions_throw_nosuchfielderror(c, uname);
-
- return (jfieldID) f;
-}
-
-
-/* GetStatic<type>Field ********************************************************
-
- This family of accessor routines returns the value of a static
- field of an object.
-
-*******************************************************************************/
-
-jobject _Jv_JNI_GetStaticObjectField(JNIEnv *env, jclass clazz,
- jfieldID fieldID)
-{
- classinfo *c;
- fieldinfo *f;
-
- STATISTICS(jniinvokation());
-
- c = (classinfo *) clazz;
- f = (fieldinfo *) fieldID;
-
- if (!(c->state & CLASS_INITIALIZED))
- if (!initialize_class(c))
- return NULL;
-
- return _Jv_JNI_NewLocalRef(env, f->value.a);
-}
-
-
-jboolean _Jv_JNI_GetStaticBooleanField(JNIEnv *env, jclass clazz,
- jfieldID fieldID)
-{
- classinfo *c;
- fieldinfo *f;
-
- STATISTICS(jniinvokation());
-
- c = (classinfo *) clazz;
- f = (fieldinfo *) fieldID;
-
- if (!(c->state & CLASS_INITIALIZED))
- if (!initialize_class(c))
- return false;
-
- return f->value.i;
-}
-
-
-jbyte _Jv_JNI_GetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID)
-{
- classinfo *c;
- fieldinfo *f;
-
- STATISTICS(jniinvokation());
-
- c = (classinfo *) clazz;
- f = (fieldinfo *) fieldID;
-
- if (!(c->state & CLASS_INITIALIZED))
- if (!initialize_class(c))
- return 0;
-
- return f->value.i;
-}
-
-
-jchar _Jv_JNI_GetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID)
-{
- classinfo *c;
- fieldinfo *f;
-
- STATISTICS(jniinvokation());
-
- c = (classinfo *) clazz;
- f = (fieldinfo *) fieldID;
-
- if (!(c->state & CLASS_INITIALIZED))
- if (!initialize_class(c))
- return 0;
-
- return f->value.i;
-}
-
-
-jshort _Jv_JNI_GetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID)
-{
- classinfo *c;
- fieldinfo *f;
-
- STATISTICS(jniinvokation());
-
- c = (classinfo *) clazz;
- f = (fieldinfo *) fieldID;
-
- if (!(c->state & CLASS_INITIALIZED))
- if (!initialize_class(c))
- return 0;
-
- return f->value.i;
-}
-
-
-jint _Jv_JNI_GetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID)
-{
- classinfo *c;
- fieldinfo *f;
-
- STATISTICS(jniinvokation());
-
- c = (classinfo *) clazz;
- f = (fieldinfo *) fieldID;
-
- if (!(c->state & CLASS_INITIALIZED))
- if (!initialize_class(c))
- return 0;
-
- return f->value.i;
-}
-
-
-jlong _Jv_JNI_GetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID)
-{
- classinfo *c;
- fieldinfo *f;
-
- STATISTICS(jniinvokation());
-
- c = (classinfo *) clazz;
- f = (fieldinfo *) fieldID;
-
- if (!(c->state & CLASS_INITIALIZED))
- if (!initialize_class(c))
- return 0;
-
- return f->value.l;
-}
-
-
-jfloat _Jv_JNI_GetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID)
-{
- classinfo *c;
- fieldinfo *f;
-
- STATISTICS(jniinvokation());
-
- c = (classinfo *) clazz;
- f = (fieldinfo *) fieldID;
-
- if (!(c->state & CLASS_INITIALIZED))
- if (!initialize_class(c))
- return 0.0;
-
- return f->value.f;
-}
-
-
-jdouble _Jv_JNI_GetStaticDoubleField(JNIEnv *env, jclass clazz,
- jfieldID fieldID)
-{
- classinfo *c;
- fieldinfo *f;
-
- STATISTICS(jniinvokation());
-
- c = (classinfo *) clazz;
- f = (fieldinfo *) fieldID;
-
- if (!(c->state & CLASS_INITIALIZED))
- if (!initialize_class(c))
- return 0.0;
-
- return f->value.d;
-}
-
-
-/* SetStatic<type>Field *******************************************************
-
- This family of accessor routines sets the value of a static field
- of an object.
-
-*******************************************************************************/
-
-void _Jv_JNI_SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID,
- jobject value)
-{
- classinfo *c;
- fieldinfo *f;
-
- STATISTICS(jniinvokation());
-
- c = (classinfo *) clazz;
- f = (fieldinfo *) fieldID;
-
- if (!(c->state & CLASS_INITIALIZED))
- if (!initialize_class(c))
- return;
-
- f->value.a = value;
-}
-
-
-void _Jv_JNI_SetStaticBooleanField(JNIEnv *env, jclass clazz, jfieldID fieldID,
- jboolean value)
-{
- classinfo *c;
- fieldinfo *f;
-
- STATISTICS(jniinvokation());
-
- c = (classinfo *) clazz;
- f = (fieldinfo *) fieldID;
-
- if (!(c->state & CLASS_INITIALIZED))
- if (!initialize_class(c))
- return;
-
- f->value.i = value;
-}
-
-
-void _Jv_JNI_SetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID,
- jbyte value)
-{
- classinfo *c;
- fieldinfo *f;
-
- STATISTICS(jniinvokation());
-
- c = (classinfo *) clazz;
- f = (fieldinfo *) fieldID;
-
- if (!(c->state & CLASS_INITIALIZED))
- if (!initialize_class(c))
- return;
-
- f->value.i = value;
-}
-
-
-void _Jv_JNI_SetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID,
- jchar value)
-{
- classinfo *c;
- fieldinfo *f;
-
- STATISTICS(jniinvokation());
-
- c = (classinfo *) clazz;
- f = (fieldinfo *) fieldID;
-
- if (!(c->state & CLASS_INITIALIZED))
- if (!initialize_class(c))
- return;
-
- f->value.i = value;
-}
-
-
-void _Jv_JNI_SetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID,
- jshort value)
-{
- classinfo *c;
- fieldinfo *f;
-
- STATISTICS(jniinvokation());
-
- c = (classinfo *) clazz;
- f = (fieldinfo *) fieldID;
-
- if (!(c->state & CLASS_INITIALIZED))
- if (!initialize_class(c))
- return;
-
- f->value.i = value;
-}
-
-
-void _Jv_JNI_SetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID,
- jint value)
-{
- classinfo *c;
- fieldinfo *f;
-
- STATISTICS(jniinvokation());
-
- c = (classinfo *) clazz;
- f = (fieldinfo *) fieldID;
-
- if (!(c->state & CLASS_INITIALIZED))
- if (!initialize_class(c))
- return;
-
- f->value.i = value;
-}
-
-
-void _Jv_JNI_SetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID,
- jlong value)
-{
- classinfo *c;
- fieldinfo *f;
-
- STATISTICS(jniinvokation());
-
- c = (classinfo *) clazz;
- f = (fieldinfo *) fieldID;
-
- if (!(c->state & CLASS_INITIALIZED))
- if (!initialize_class(c))
- return;
-
- f->value.l = value;
-}
-
-
-void _Jv_JNI_SetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID,
- jfloat value)
-{
- classinfo *c;
- fieldinfo *f;
-
- STATISTICS(jniinvokation());
-
- c = (classinfo *) clazz;
- f = (fieldinfo *) fieldID;
-
- if (!(c->state & CLASS_INITIALIZED))
- if (!initialize_class(c))
- return;
-
- f->value.f = value;
-}
-
-
-void _Jv_JNI_SetStaticDoubleField(JNIEnv *env, jclass clazz, jfieldID fieldID,
- jdouble value)
-{
- classinfo *c;
- fieldinfo *f;
-
- STATISTICS(jniinvokation());
-
- c = (classinfo *) clazz;
- f = (fieldinfo *) fieldID;
-
- if (!(c->state & CLASS_INITIALIZED))
- if (!initialize_class(c))
- return;
-
- f->value.d = value;
-}
-
-
-/* String Operations **********************************************************/
-
-/* NewString *******************************************************************
-
- Create new java.lang.String object from an array of Unicode
- characters.
-
-*******************************************************************************/
-
-jstring _Jv_JNI_NewString(JNIEnv *env, const jchar *buf, jsize len)
-{
- java_lang_String *s;
- java_chararray *a;
- u4 i;
-
- STATISTICS(jniinvokation());
-
- s = (java_lang_String *) builtin_new(class_java_lang_String);
- a = builtin_newarray_char(len);
-
- /* javastring or characterarray could not be created */
- if ((a == NULL) || (s == NULL))
- return NULL;
-
- /* copy text */
- for (i = 0; i < len; i++)
- a->data[i] = buf[i];
-
- s->value = a;
- s->offset = 0;
- s->count = len;
-
- return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
-}
-
-
-static jchar emptyStringJ[]={0,0};
-
-/* GetStringLength *************************************************************
-
- Returns the length (the count of Unicode characters) of a Java
- string.
-
-*******************************************************************************/
-
-jsize _Jv_JNI_GetStringLength(JNIEnv *env, jstring str)
-{
- java_lang_String *s;
-
- s = (java_lang_String *) str;
-
- return s->count;
-}
-
-
-/******************** convertes javastring to u2-array ****************************/
-
-u2 *javastring_tou2(jstring so)
-{
- java_lang_String *s;
- java_chararray *a;
- u2 *stringbuffer;
- u4 i;
-
- STATISTICS(jniinvokation());
-
- s = (java_lang_String *) so;
-
- if (!s)
- return NULL;
-
- a = s->value;
-
- if (!a)
- return NULL;
-
- /* allocate memory */
-
- stringbuffer = MNEW(u2, s->count + 1);
-
- /* copy text */
-
- for (i = 0; i < s->count; i++)
- stringbuffer[i] = a->data[s->offset + i];
-
- /* terminate string */
-
- stringbuffer[i] = '\0';
-
- return stringbuffer;
-}
-
-
-/* GetStringChars **************************************************************
-
- Returns a pointer to the array of Unicode characters of the
- string. This pointer is valid until ReleaseStringChars() is called.
-
-*******************************************************************************/
-
-const jchar *_Jv_JNI_GetStringChars(JNIEnv *env, jstring str, jboolean *isCopy)
-{
- jchar *jc;
-
- STATISTICS(jniinvokation());
-
- jc = javastring_tou2(str);
-
- if (jc) {
- if (isCopy)
- *isCopy = JNI_TRUE;
-
- return jc;
- }
-
- if (isCopy)
- *isCopy = JNI_TRUE;
-
- return emptyStringJ;
-}
-
-
-/* ReleaseStringChars **********************************************************
-
- Informs the VM that the native code no longer needs access to
- chars. The chars argument is a pointer obtained from string using
- GetStringChars().
-
-*******************************************************************************/
-
-void _Jv_JNI_ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars)
-{
- STATISTICS(jniinvokation());
-
- if (chars == emptyStringJ)
- return;
-
- MFREE(((jchar *) chars), jchar, ((java_lang_String *) str)->count + 1);
-}
-
-
-/* NewStringUTF ****************************************************************
-
- Constructs a new java.lang.String object from an array of UTF-8
- characters.
-
-*******************************************************************************/
-
-jstring _Jv_JNI_NewStringUTF(JNIEnv *env, const char *bytes)
-{
- java_lang_String *s;
-
- STATISTICS(jniinvokation());
-
- s = (java_lang_String *) javastring_safe_new_from_utf8(bytes);
-
- return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
-}
-
-
-/****************** returns the utf8 length in bytes of a string *******************/
-
-jsize _Jv_JNI_GetStringUTFLength(JNIEnv *env, jstring string)
-{
- java_lang_String *s;
- s4 length;
-
- STATISTICS(jniinvokation());
-
- s = (java_lang_String *) string;
-
- length = u2_utflength(s->value->data, s->count);
-
- return length;
-}
-
-
-/* GetStringUTFChars ***********************************************************
-
- Returns a pointer to an array of UTF-8 characters of the
- string. This array is valid until it is released by
- ReleaseStringUTFChars().
-
-*******************************************************************************/
-
-const char *_Jv_JNI_GetStringUTFChars(JNIEnv *env, jstring string,
- jboolean *isCopy)
-{
- utf *u;
-
- STATISTICS(jniinvokation());
-
- if (string == NULL)
- return "";
-
- if (isCopy)
- *isCopy = JNI_TRUE;
-
- u = javastring_toutf((java_objectheader *) string, false);
-
- if (u != NULL)
- return u->text;
-
- return "";
-}
-
-
-/* ReleaseStringUTFChars *******************************************************
-
- Informs the VM that the native code no longer needs access to
- utf. The utf argument is a pointer derived from string using
- GetStringUTFChars().
-
-*******************************************************************************/
-
-void _Jv_JNI_ReleaseStringUTFChars(JNIEnv *env, jstring string, const char *utf)
-{
- STATISTICS(jniinvokation());
-
- /* XXX we don't release utf chars right now, perhaps that should be done
- later. Since there is always one reference the garbage collector will
- never get them */
-}
-
-
-/* Array Operations ***********************************************************/
-
-/* GetArrayLength **************************************************************
-
- Returns the number of elements in the array.
-
-*******************************************************************************/
-
-jsize _Jv_JNI_GetArrayLength(JNIEnv *env, jarray array)
-{
- java_arrayheader *a;
-
- STATISTICS(jniinvokation());
-
- a = (java_arrayheader *) array;
-
- return a->size;
-}
-
-
-/* NewObjectArray **************************************************************
-
- Constructs a new array holding objects in class elementClass. All
- elements are initially set to initialElement.
-
-*******************************************************************************/
-
-jobjectArray _Jv_JNI_NewObjectArray(JNIEnv *env, jsize length,
- jclass elementClass, jobject initialElement)
-{
- classinfo *c;
- java_objectheader *o;
- java_objectarray *oa;
- s4 i;
-
- STATISTICS(jniinvokation());
-
- c = (classinfo *) elementClass;
- o = (java_objectheader *) initialElement;
-
- if (length < 0) {
- exceptions_throw_negativearraysizeexception();
- return NULL;
- }
-
- oa = builtin_anewarray(length, c);
-
- if (oa == NULL)
- return NULL;
-
- /* set all elements to initialElement */
-
- for (i = 0; i < length; i++)
- oa->data[i] = o;
-
- return (jobjectArray) _Jv_JNI_NewLocalRef(env, (jobject) oa);
-}
-
-
-jobject _Jv_JNI_GetObjectArrayElement(JNIEnv *env, jobjectArray array,
- jsize index)
-{
- java_objectarray *oa;
- java_objectheader *o;
-
- STATISTICS(jniinvokation());
-
- oa = (java_objectarray *) array;
-
- if (index >= oa->header.size) {
- exceptions_throw_arrayindexoutofboundsexception();
- return NULL;
- }
-
- o = oa->data[index];
-
- return _Jv_JNI_NewLocalRef(env, (jobject) o);
-}
-
-
-void _Jv_JNI_SetObjectArrayElement(JNIEnv *env, jobjectArray array,
- jsize index, jobject val)
-{
- java_objectarray *oa;
- java_objectheader *o;
-
- STATISTICS(jniinvokation());
-
- oa = (java_objectarray *) array;
- o = (java_objectheader *) val;
-
- if (index >= oa->header.size) {
- exceptions_throw_arrayindexoutofboundsexception();
- return;
- }
-
- /* check if the class of value is a subclass of the element class
- of the array */
-
- if (!builtin_canstore(oa, o))
- return;
-
- oa->data[index] = o;
-}
-
-
-jbooleanArray _Jv_JNI_NewBooleanArray(JNIEnv *env, jsize len)
-{
- java_booleanarray *ba;
-
- STATISTICS(jniinvokation());
-
- if (len < 0) {
- exceptions_throw_negativearraysizeexception();
- return NULL;
- }
-
- ba = builtin_newarray_boolean(len);
-
- return (jbooleanArray) _Jv_JNI_NewLocalRef(env, (jobject) ba);
-}
-
-
-jbyteArray _Jv_JNI_NewByteArray(JNIEnv *env, jsize len)
-{
- java_bytearray *ba;
-
- STATISTICS(jniinvokation());
-
- if (len < 0) {
- exceptions_throw_negativearraysizeexception();
- return NULL;
- }
-
- ba = builtin_newarray_byte(len);
-
- return (jbyteArray) _Jv_JNI_NewLocalRef(env, (jobject) ba);
-}
-
-
-jcharArray _Jv_JNI_NewCharArray(JNIEnv *env, jsize len)
-{
- java_chararray *ca;
-
- STATISTICS(jniinvokation());
-
- if (len < 0) {
- exceptions_throw_negativearraysizeexception();
- return NULL;
- }
-
- ca = builtin_newarray_char(len);
-
- return (jcharArray) _Jv_JNI_NewLocalRef(env, (jobject) ca);
-}
-
-
-jshortArray _Jv_JNI_NewShortArray(JNIEnv *env, jsize len)
-{
- java_shortarray *sa;
-
- STATISTICS(jniinvokation());
-
- if (len < 0) {
- exceptions_throw_negativearraysizeexception();
- return NULL;
- }
-
- sa = builtin_newarray_short(len);
-
- return (jshortArray) _Jv_JNI_NewLocalRef(env, (jobject) sa);
-}
-
-
-jintArray _Jv_JNI_NewIntArray(JNIEnv *env, jsize len)
-{
- java_intarray *ia;
-
- STATISTICS(jniinvokation());
-
- if (len < 0) {
- exceptions_throw_negativearraysizeexception();
- return NULL;
- }
-
- ia = builtin_newarray_int(len);
-
- return (jintArray) _Jv_JNI_NewLocalRef(env, (jobject) ia);
-}
-
-
-jlongArray _Jv_JNI_NewLongArray(JNIEnv *env, jsize len)
-{
- java_longarray *la;
-
- STATISTICS(jniinvokation());
-
- if (len < 0) {
- exceptions_throw_negativearraysizeexception();
- return NULL;
- }
-
- la = builtin_newarray_long(len);
-
- return (jlongArray) _Jv_JNI_NewLocalRef(env, (jobject) la);
-}
-
-
-jfloatArray _Jv_JNI_NewFloatArray(JNIEnv *env, jsize len)
-{
- java_floatarray *fa;
-
- STATISTICS(jniinvokation());
-
- if (len < 0) {
- exceptions_throw_negativearraysizeexception();
- return NULL;
- }
-
- fa = builtin_newarray_float(len);
-
- return (jfloatArray) _Jv_JNI_NewLocalRef(env, (jobject) fa);
-}
-
-
-jdoubleArray _Jv_JNI_NewDoubleArray(JNIEnv *env, jsize len)
-{
- java_doublearray *da;
-
- STATISTICS(jniinvokation());
-
- if (len < 0) {
- exceptions_throw_negativearraysizeexception();
- return NULL;
- }
-
- da = builtin_newarray_double(len);
-
- return (jdoubleArray) _Jv_JNI_NewLocalRef(env, (jobject) da);
-}
-
-
-/* Get<PrimitiveType>ArrayElements *********************************************
-
- A family of functions that returns the body of the primitive array.
-
-*******************************************************************************/
-
-jboolean *_Jv_JNI_GetBooleanArrayElements(JNIEnv *env, jbooleanArray array,
- jboolean *isCopy)
-{
- java_booleanarray *ba;
-
- STATISTICS(jniinvokation());
-
- ba = (java_booleanarray *) array;
-
- if (isCopy)
- *isCopy = JNI_FALSE;
-
- return ba->data;
-}
-
-
-jbyte *_Jv_JNI_GetByteArrayElements(JNIEnv *env, jbyteArray array,
- jboolean *isCopy)
-{
- java_bytearray *ba;
-
- STATISTICS(jniinvokation());
-
- ba = (java_bytearray *) array;
-
- if (isCopy)
- *isCopy = JNI_FALSE;
-
- return ba->data;
-}
-
-
-jchar *_Jv_JNI_GetCharArrayElements(JNIEnv *env, jcharArray array,
- jboolean *isCopy)
-{
- java_chararray *ca;
-
- STATISTICS(jniinvokation());
-
- ca = (java_chararray *) array;
-
- if (isCopy)
- *isCopy = JNI_FALSE;
-
- return ca->data;
-}
+ Returns the field ID for a static field of a class. The field is
+ specified by its name and signature. The GetStatic<type>Field and
+ SetStatic<type>Field families of accessor functions use field IDs
+ to retrieve static fields.
+*******************************************************************************/
-jshort *_Jv_JNI_GetShortArrayElements(JNIEnv *env, jshortArray array,
- jboolean *isCopy)
+jfieldID _Jv_JNI_GetStaticFieldID(JNIEnv *env, jclass clazz, const char *name,
+ const char *sig)
{
- java_shortarray *sa;
+ classinfo *c;
+ fieldinfo *f;
+ utf *uname;
+ utf *usig;
STATISTICS(jniinvokation());
- sa = (java_shortarray *) array;
+ c = LLNI_classinfo_unwrap(clazz);
- if (isCopy)
- *isCopy = JNI_FALSE;
+ uname = utf_new_char((char *) name);
+ usig = utf_new_char((char *) sig);
- return sa->data;
-}
+ f = class_findfield(c, uname, usig);
+
+ if (f == NULL)
+ exceptions_throw_nosuchfielderror(c, uname);
+ return (jfieldID) f;
+}
-jint *_Jv_JNI_GetIntArrayElements(JNIEnv *env, jintArray array,
- jboolean *isCopy)
-{
- java_intarray *ia;
- STATISTICS(jniinvokation());
+/* GetStatic<type>Field ********************************************************
- ia = (java_intarray *) array;
+ This family of accessor routines returns the value of a static
+ field of an object.
- if (isCopy)
- *isCopy = JNI_FALSE;
+*******************************************************************************/
- return ia->data;
-}
+#define JNI_GET_STATIC_FIELD(name, type, field) \
+type _Jv_JNI_GetStatic##name##Field(JNIEnv *env, jclass clazz, \
+ jfieldID fieldID) \
+{ \
+ classinfo *c; \
+ fieldinfo *f; \
+ \
+ STATISTICS(jniinvokation()); \
+ \
+ c = LLNI_classinfo_unwrap(clazz); \
+ f = (fieldinfo *) fieldID; \
+ \
+ if (!(c->state & CLASS_INITIALIZED)) \
+ if (!initialize_class(c)) \
+ return 0; \
+ \
+ return f->value->field; \
+}
+
+JNI_GET_STATIC_FIELD(Boolean, jboolean, i)
+JNI_GET_STATIC_FIELD(Byte, jbyte, i)
+JNI_GET_STATIC_FIELD(Char, jchar, i)
+JNI_GET_STATIC_FIELD(Short, jshort, i)
+JNI_GET_STATIC_FIELD(Int, jint, i)
+JNI_GET_STATIC_FIELD(Long, jlong, l)
+JNI_GET_STATIC_FIELD(Float, jfloat, f)
+JNI_GET_STATIC_FIELD(Double, jdouble, d)
-jlong *_Jv_JNI_GetLongArrayElements(JNIEnv *env, jlongArray array,
- jboolean *isCopy)
+jobject _Jv_JNI_GetStaticObjectField(JNIEnv *env, jclass clazz,
+ jfieldID fieldID)
{
- java_longarray *la;
+ classinfo *c;
+ fieldinfo *f;
+ java_handle_t *h;
STATISTICS(jniinvokation());
- la = (java_longarray *) array;
+ c = LLNI_classinfo_unwrap(clazz);
+ f = (fieldinfo *) fieldID;
- if (isCopy)
- *isCopy = JNI_FALSE;
+ if (!(c->state & CLASS_INITIALIZED))
+ if (!initialize_class(c))
+ return NULL;
- /* We cast this one to prevent a compiler warning on 64-bit
- systems since GNU Classpath typedef jlong to long long. */
+ h = LLNI_WRAP(f->value->a);
- return (jlong *) la->data;
+ return jni_NewLocalRef(env, (jobject) h);
}
-jfloat *_Jv_JNI_GetFloatArrayElements(JNIEnv *env, jfloatArray array,
- jboolean *isCopy)
-{
- java_floatarray *fa;
-
- STATISTICS(jniinvokation());
+/* SetStatic<type>Field *******************************************************
- fa = (java_floatarray *) array;
+ This family of accessor routines sets the value of a static field
+ of an object.
- if (isCopy)
- *isCopy = JNI_FALSE;
+*******************************************************************************/
- return fa->data;
-}
+#define JNI_SET_STATIC_FIELD(name, type, field) \
+void _Jv_JNI_SetStatic##name##Field(JNIEnv *env, jclass clazz, \
+ jfieldID fieldID, \
+ type value) \
+{ \
+ classinfo *c; \
+ fieldinfo *f; \
+ \
+ STATISTICS(jniinvokation()); \
+ \
+ c = LLNI_classinfo_unwrap(clazz); \
+ f = (fieldinfo *) fieldID; \
+ \
+ if (!(c->state & CLASS_INITIALIZED)) \
+ if (!initialize_class(c)) \
+ return; \
+ \
+ f->value->field = value; \
+}
+
+JNI_SET_STATIC_FIELD(Boolean, jboolean, i)
+JNI_SET_STATIC_FIELD(Byte, jbyte, i)
+JNI_SET_STATIC_FIELD(Char, jchar, i)
+JNI_SET_STATIC_FIELD(Short, jshort, i)
+JNI_SET_STATIC_FIELD(Int, jint, i)
+JNI_SET_STATIC_FIELD(Long, jlong, l)
+JNI_SET_STATIC_FIELD(Float, jfloat, f)
+JNI_SET_STATIC_FIELD(Double, jdouble, d)
-jdouble *_Jv_JNI_GetDoubleArrayElements(JNIEnv *env, jdoubleArray array,
- jboolean *isCopy)
+void _Jv_JNI_SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID,
+ jobject value)
{
- java_doublearray *da;
+ classinfo *c;
+ fieldinfo *f;
STATISTICS(jniinvokation());
- da = (java_doublearray *) array;
+ c = LLNI_classinfo_unwrap(clazz);
+ f = (fieldinfo *) fieldID;
- if (isCopy)
- *isCopy = JNI_FALSE;
+ if (!(c->state & CLASS_INITIALIZED))
+ if (!initialize_class(c))
+ return;
- return da->data;
+ f->value->a = LLNI_UNWRAP((java_handle_t *) value);
}
-/* Release<PrimitiveType>ArrayElements *****************************************
+/* String Operations **********************************************************/
- A family of functions that informs the VM that the native code no
- longer needs access to elems. The elems argument is a pointer
- derived from array using the corresponding
- Get<PrimitiveType>ArrayElements() function. If necessary, this
- function copies back all changes made to elems to the original
- array.
+/* NewString *******************************************************************
+
+ Create new java.lang.String object from an array of Unicode
+ characters.
*******************************************************************************/
-void _Jv_JNI_ReleaseBooleanArrayElements(JNIEnv *env, jbooleanArray array,
- jboolean *elems, jint mode)
+jstring _Jv_JNI_NewString(JNIEnv *env, const jchar *buf, jsize len)
{
- java_booleanarray *ba;
+ java_lang_String *s;
+ java_handle_chararray_t *a;
+ u4 i;
STATISTICS(jniinvokation());
+
+ s = (java_lang_String *) builtin_new(class_java_lang_String);
+ a = builtin_newarray_char(len);
- ba = (java_booleanarray *) array;
-
- if (elems != ba->data) {
- switch (mode) {
- case JNI_COMMIT:
- MCOPY(ba->data, elems, u1, ba->header.size);
- break;
- case 0:
- MCOPY(ba->data, elems, u1, ba->header.size);
- /* XXX TWISTI how should it be freed? */
- break;
- case JNI_ABORT:
- /* XXX TWISTI how should it be freed? */
- break;
- }
- }
-}
-
-
-void _Jv_JNI_ReleaseByteArrayElements(JNIEnv *env, jbyteArray array,
- jbyte *elems, jint mode)
-{
- java_bytearray *ba;
+ /* javastring or characterarray could not be created */
+ if ((a == NULL) || (s == NULL))
+ return NULL;
- STATISTICS(jniinvokation());
+ /* copy text */
+ for (i = 0; i < len; i++)
+ LLNI_array_direct(a, i) = buf[i];
- ba = (java_bytearray *) array;
+ LLNI_field_set_ref(s, value , a);
+ LLNI_field_set_val(s, offset, 0);
+ LLNI_field_set_val(s, count , len);
- if (elems != ba->data) {
- switch (mode) {
- case JNI_COMMIT:
- MCOPY(ba->data, elems, s1, ba->header.size);
- break;
- case 0:
- MCOPY(ba->data, elems, s1, ba->header.size);
- /* XXX TWISTI how should it be freed? */
- break;
- case JNI_ABORT:
- /* XXX TWISTI how should it be freed? */
- break;
- }
- }
+ return (jstring) jni_NewLocalRef(env, (jobject) s);
}
-void _Jv_JNI_ReleaseCharArrayElements(JNIEnv *env, jcharArray array,
- jchar *elems, jint mode)
-{
- java_chararray *ca;
-
- STATISTICS(jniinvokation());
+static jchar emptyStringJ[]={0,0};
- ca = (java_chararray *) array;
+/* GetStringLength *************************************************************
- if (elems != ca->data) {
- switch (mode) {
- case JNI_COMMIT:
- MCOPY(ca->data, elems, u2, ca->header.size);
- break;
- case 0:
- MCOPY(ca->data, elems, u2, ca->header.size);
- /* XXX TWISTI how should it be freed? */
- break;
- case JNI_ABORT:
- /* XXX TWISTI how should it be freed? */
- break;
- }
- }
-}
+ Returns the length (the count of Unicode characters) of a Java
+ string.
+*******************************************************************************/
-void _Jv_JNI_ReleaseShortArrayElements(JNIEnv *env, jshortArray array,
- jshort *elems, jint mode)
+jsize _Jv_JNI_GetStringLength(JNIEnv *env, jstring str)
{
- java_shortarray *sa;
+ java_lang_String *s;
+ jsize len;
- STATISTICS(jniinvokation());
+ TRACEJNICALLS(("_Jv_JNI_GetStringLength(env=%p, str=%p)", env, str));
- sa = (java_shortarray *) array;
+ s = (java_lang_String *) str;
- if (elems != sa->data) {
- switch (mode) {
- case JNI_COMMIT:
- MCOPY(sa->data, elems, s2, sa->header.size);
- break;
- case 0:
- MCOPY(sa->data, elems, s2, sa->header.size);
- /* XXX TWISTI how should it be freed? */
- break;
- case JNI_ABORT:
- /* XXX TWISTI how should it be freed? */
- break;
- }
- }
+ LLNI_field_get_val(s, count, len);
+
+ return len;
}
-void _Jv_JNI_ReleaseIntArrayElements(JNIEnv *env, jintArray array, jint *elems,
- jint mode)
+/******************** convertes javastring to u2-array ****************************/
+
+u2 *javastring_tou2(jstring so)
{
- java_intarray *ia;
+ java_lang_String *s;
+ java_handle_chararray_t *a;
+ u2 *stringbuffer;
+ u4 i;
+ int32_t count;
+ int32_t offset;
STATISTICS(jniinvokation());
+
+ s = (java_lang_String *) so;
- ia = (java_intarray *) array;
+ if (!s)
+ return NULL;
- if (elems != ia->data) {
- switch (mode) {
- case JNI_COMMIT:
- MCOPY(ia->data, elems, s4, ia->header.size);
- break;
- case 0:
- MCOPY(ia->data, elems, s4, ia->header.size);
- /* XXX TWISTI how should it be freed? */
- break;
- case JNI_ABORT:
- /* XXX TWISTI how should it be freed? */
- break;
- }
- }
-}
+ LLNI_field_get_ref(s, value, a);
+ if (!a)
+ return NULL;
-void _Jv_JNI_ReleaseLongArrayElements(JNIEnv *env, jlongArray array,
- jlong *elems, jint mode)
-{
- java_longarray *la;
+ LLNI_field_get_val(s, count, count);
+ LLNI_field_get_val(s, offset, offset);
- STATISTICS(jniinvokation());
+ /* allocate memory */
- la = (java_longarray *) array;
+ stringbuffer = MNEW(u2, count + 1);
- /* We cast this one to prevent a compiler warning on 64-bit
- systems since GNU Classpath typedef jlong to long long. */
+ /* copy text */
- if ((s8 *) elems != la->data) {
- switch (mode) {
- case JNI_COMMIT:
- MCOPY(la->data, elems, s8, la->header.size);
- break;
- case 0:
- MCOPY(la->data, elems, s8, la->header.size);
- /* XXX TWISTI how should it be freed? */
- break;
- case JNI_ABORT:
- /* XXX TWISTI how should it be freed? */
- break;
- }
- }
-}
+ for (i = 0; i < count; i++)
+ stringbuffer[i] = LLNI_array_direct(a, offset + i);
+
+ /* terminate string */
+ stringbuffer[i] = '\0';
-void _Jv_JNI_ReleaseFloatArrayElements(JNIEnv *env, jfloatArray array,
- jfloat *elems, jint mode)
-{
- java_floatarray *fa;
+ return stringbuffer;
+}
- STATISTICS(jniinvokation());
- fa = (java_floatarray *) array;
+/* GetStringChars **************************************************************
- if (elems != fa->data) {
- switch (mode) {
- case JNI_COMMIT:
- MCOPY(fa->data, elems, float, fa->header.size);
- break;
- case 0:
- MCOPY(fa->data, elems, float, fa->header.size);
- /* XXX TWISTI how should it be freed? */
- break;
- case JNI_ABORT:
- /* XXX TWISTI how should it be freed? */
- break;
- }
- }
-}
+ Returns a pointer to the array of Unicode characters of the
+ string. This pointer is valid until ReleaseStringChars() is called.
+*******************************************************************************/
-void _Jv_JNI_ReleaseDoubleArrayElements(JNIEnv *env, jdoubleArray array,
- jdouble *elems, jint mode)
-{
- java_doublearray *da;
+const jchar *_Jv_JNI_GetStringChars(JNIEnv *env, jstring str, jboolean *isCopy)
+{
+ jchar *jc;
STATISTICS(jniinvokation());
- da = (java_doublearray *) array;
+ jc = javastring_tou2(str);
- if (elems != da->data) {
- switch (mode) {
- case JNI_COMMIT:
- MCOPY(da->data, elems, double, da->header.size);
- break;
- case 0:
- MCOPY(da->data, elems, double, da->header.size);
- /* XXX TWISTI how should it be freed? */
- break;
- case JNI_ABORT:
- /* XXX TWISTI how should it be freed? */
- break;
- }
+ if (jc) {
+ if (isCopy)
+ *isCopy = JNI_TRUE;
+
+ return jc;
}
+
+ if (isCopy)
+ *isCopy = JNI_TRUE;
+
+ return emptyStringJ;
}
-/* Get<PrimitiveType>ArrayRegion **********************************************
+/* ReleaseStringChars **********************************************************
- A family of functions that copies a region of a primitive array
- into a buffer.
+ Informs the VM that the native code no longer needs access to
+ chars. The chars argument is a pointer obtained from string using
+ GetStringChars().
*******************************************************************************/
-void _Jv_JNI_GetBooleanArrayRegion(JNIEnv *env, jbooleanArray array,
- jsize start, jsize len, jboolean *buf)
+void _Jv_JNI_ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars)
{
- java_booleanarray *ba;
+ java_lang_String *s;
STATISTICS(jniinvokation());
- ba = (java_booleanarray *) array;
+ if (chars == emptyStringJ)
+ return;
- if ((start < 0) || (len < 0) || (start + len > ba->header.size))
- exceptions_throw_arrayindexoutofboundsexception();
- else
- MCOPY(buf, &ba->data[start], u1, len);
+ s = (java_lang_String *) str;
+
+ MFREE(((jchar *) chars), jchar, LLNI_field_direct(s, count) + 1);
}
-void _Jv_JNI_GetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start,
- jsize len, jbyte *buf)
+/* NewStringUTF ****************************************************************
+
+ Constructs a new java.lang.String object from an array of UTF-8
+ characters.
+
+*******************************************************************************/
+
+jstring _Jv_JNI_NewStringUTF(JNIEnv *env, const char *bytes)
{
- java_bytearray *ba;
+ java_lang_String *s;
- STATISTICS(jniinvokation());
+ TRACEJNICALLS(("_Jv_JNI_NewStringUTF(env=%p, bytes=%s)", env, bytes));
- ba = (java_bytearray *) array;
+ s = (java_lang_String *) javastring_safe_new_from_utf8(bytes);
- if ((start < 0) || (len < 0) || (start + len > ba->header.size))
- exceptions_throw_arrayindexoutofboundsexception();
- else
- MCOPY(buf, &ba->data[start], s1, len);
+ return (jstring) jni_NewLocalRef(env, (jobject) s);
}
-void _Jv_JNI_GetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start,
- jsize len, jchar *buf)
-{
- java_chararray *ca;
+/****************** returns the utf8 length in bytes of a string *******************/
- STATISTICS(jniinvokation());
+jsize _Jv_JNI_GetStringUTFLength(JNIEnv *env, jstring string)
+{
+ java_lang_String *s;
+ s4 length;
- ca = (java_chararray *) array;
+ TRACEJNICALLS(("_Jv_JNI_GetStringUTFLength(env=%p, string=%p)", env, string));
- if ((start < 0) || (len < 0) || (start + len > ca->header.size))
- exceptions_throw_arrayindexoutofboundsexception();
- else
- MCOPY(buf, &ca->data[start], u2, len);
-}
+ s = (java_lang_String *) string;
+ length = u2_utflength(LLNI_field_direct(s, value)->data, LLNI_field_direct(s, count));
-void _Jv_JNI_GetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
- jsize len, jshort *buf)
-{
- java_shortarray *sa;
+ return length;
+}
- STATISTICS(jniinvokation());
- sa = (java_shortarray *) array;
+/* GetStringUTFChars ***********************************************************
- if ((start < 0) || (len < 0) || (start + len > sa->header.size))
- exceptions_throw_arrayindexoutofboundsexception();
- else
- MCOPY(buf, &sa->data[start], s2, len);
-}
+ Returns a pointer to an array of UTF-8 characters of the
+ string. This array is valid until it is released by
+ ReleaseStringUTFChars().
+*******************************************************************************/
-void _Jv_JNI_GetIntArrayRegion(JNIEnv *env, jintArray array, jsize start,
- jsize len, jint *buf)
+const char *_Jv_JNI_GetStringUTFChars(JNIEnv *env, jstring string,
+ jboolean *isCopy)
{
- java_intarray *ia;
+ utf *u;
STATISTICS(jniinvokation());
- ia = (java_intarray *) array;
+ if (string == NULL)
+ return "";
- if ((start < 0) || (len < 0) || (start + len > ia->header.size))
- exceptions_throw_arrayindexoutofboundsexception();
- else
- MCOPY(buf, &ia->data[start], s4, len);
+ if (isCopy)
+ *isCopy = JNI_TRUE;
+
+ u = javastring_toutf((java_handle_t *) string, false);
+
+ if (u != NULL)
+ return u->text;
+
+ return "";
}
-void _Jv_JNI_GetLongArrayRegion(JNIEnv *env, jlongArray array, jsize start,
- jsize len, jlong *buf)
-{
- java_longarray *la;
+/* ReleaseStringUTFChars *******************************************************
- STATISTICS(jniinvokation());
+ Informs the VM that the native code no longer needs access to
+ utf. The utf argument is a pointer derived from string using
+ GetStringUTFChars().
- la = (java_longarray *) array;
+*******************************************************************************/
- if ((start < 0) || (len < 0) || (start + len > la->header.size))
- exceptions_throw_arrayindexoutofboundsexception();
- else
- MCOPY(buf, &la->data[start], s8, len);
-}
+void _Jv_JNI_ReleaseStringUTFChars(JNIEnv *env, jstring string, const char *utf)
+{
+ STATISTICS(jniinvokation());
+ /* XXX we don't release utf chars right now, perhaps that should be done
+ later. Since there is always one reference the garbage collector will
+ never get them */
+}
-void _Jv_JNI_GetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
- jsize len, jfloat *buf)
-{
- java_floatarray *fa;
- STATISTICS(jniinvokation());
+/* Array Operations ***********************************************************/
- fa = (java_floatarray *) array;
+/* GetArrayLength **************************************************************
- if ((start < 0) || (len < 0) || (start + len > fa->header.size))
- exceptions_throw_arrayindexoutofboundsexception();
- else
- MCOPY(buf, &fa->data[start], float, len);
-}
+ Returns the number of elements in the array.
+*******************************************************************************/
-void _Jv_JNI_GetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
- jsize len, jdouble *buf)
+jsize _Jv_JNI_GetArrayLength(JNIEnv *env, jarray array)
{
- java_doublearray *da;
+ java_handle_t *a;
+ jsize size;
- STATISTICS(jniinvokation());
+ TRACEJNICALLS(("_Jv_JNI_GetArrayLength(env=%p, array=%p)", env, array));
- da = (java_doublearray *) array;
+ a = (java_handle_t *) array;
- if ((start < 0) || (len < 0) || (start + len > da->header.size))
- exceptions_throw_arrayindexoutofboundsexception();
- else
- MCOPY(buf, &da->data[start], double, len);
+ size = LLNI_array_size(a);
+
+ return size;
}
-/* Set<PrimitiveType>ArrayRegion **********************************************
+/* NewObjectArray **************************************************************
- A family of functions that copies back a region of a primitive
- array from a buffer.
+ Constructs a new array holding objects in class elementClass. All
+ elements are initially set to initialElement.
*******************************************************************************/
-void _Jv_JNI_SetBooleanArrayRegion(JNIEnv *env, jbooleanArray array,
- jsize start, jsize len, const jboolean *buf)
+jobjectArray _Jv_JNI_NewObjectArray(JNIEnv *env, jsize length,
+ jclass elementClass, jobject initialElement)
{
- java_booleanarray *ba;
+ classinfo *c;
+ java_handle_t *o;
+ java_handle_objectarray_t *oa;
+ s4 i;
STATISTICS(jniinvokation());
- ba = (java_booleanarray *) array;
+ c = LLNI_classinfo_unwrap(elementClass);
+ o = (java_handle_t *) initialElement;
- if ((start < 0) || (len < 0) || (start + len > ba->header.size))
- exceptions_throw_arrayindexoutofboundsexception();
- else
- MCOPY(&ba->data[start], buf, u1, len);
-}
+ if (length < 0) {
+ exceptions_throw_negativearraysizeexception();
+ return NULL;
+ }
+ oa = builtin_anewarray(length, c);
-void _Jv_JNI_SetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start,
- jsize len, const jbyte *buf)
-{
- java_bytearray *ba;
+ if (oa == NULL)
+ return NULL;
- STATISTICS(jniinvokation());
+ /* set all elements to initialElement */
- ba = (java_bytearray *) array;
+ for (i = 0; i < length; i++)
+ array_objectarray_element_set(oa, i, o);
- if ((start < 0) || (len < 0) || (start + len > ba->header.size))
- exceptions_throw_arrayindexoutofboundsexception();
- else
- MCOPY(&ba->data[start], buf, s1, len);
+ return (jobjectArray) jni_NewLocalRef(env, (jobject) oa);
}
-void _Jv_JNI_SetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start,
- jsize len, const jchar *buf)
+jobject _Jv_JNI_GetObjectArrayElement(JNIEnv *env, jobjectArray array,
+ jsize index)
{
- java_chararray *ca;
+ java_handle_objectarray_t *oa;
+ java_handle_t *o;
STATISTICS(jniinvokation());
- ca = (java_chararray *) array;
+ oa = (java_handle_objectarray_t *) array;
- if ((start < 0) || (len < 0) || (start + len > ca->header.size))
+ if (index >= LLNI_array_size(oa)) {
exceptions_throw_arrayindexoutofboundsexception();
- else
- MCOPY(&ca->data[start], buf, u2, len);
+ return NULL;
+ }
+
+ o = array_objectarray_element_get(oa, index);
+
+ return jni_NewLocalRef(env, (jobject) o);
}
-void _Jv_JNI_SetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
- jsize len, const jshort *buf)
+void _Jv_JNI_SetObjectArrayElement(JNIEnv *env, jobjectArray array,
+ jsize index, jobject val)
{
- java_shortarray *sa;
+ java_handle_objectarray_t *oa;
+ java_handle_t *o;
STATISTICS(jniinvokation());
- sa = (java_shortarray *) array;
+ oa = (java_handle_objectarray_t *) array;
+ o = (java_handle_t *) val;
- if ((start < 0) || (len < 0) || (start + len > sa->header.size))
+ if (index >= LLNI_array_size(oa)) {
exceptions_throw_arrayindexoutofboundsexception();
- else
- MCOPY(&sa->data[start], buf, s2, len);
-}
+ return;
+ }
+ /* check if the class of value is a subclass of the element class
+ of the array */
-void _Jv_JNI_SetIntArrayRegion(JNIEnv *env, jintArray array, jsize start,
- jsize len, const jint *buf)
-{
- java_intarray *ia;
+ if (!builtin_canstore(oa, o))
+ return;
- STATISTICS(jniinvokation());
+ array_objectarray_element_set(oa, index, o);
+}
- ia = (java_intarray *) array;
- if ((start < 0) || (len < 0) || (start + len > ia->header.size))
- exceptions_throw_arrayindexoutofboundsexception();
- else
- MCOPY(&ia->data[start], buf, s4, len);
+#define JNI_NEW_ARRAY(name, type, intern) \
+type _Jv_JNI_New##name##Array(JNIEnv *env, jsize len) \
+{ \
+ java_handle_##intern##array_t *a; \
+ \
+ STATISTICS(jniinvokation()); \
+ \
+ if (len < 0) { \
+ exceptions_throw_negativearraysizeexception(); \
+ return NULL; \
+ } \
+ \
+ a = builtin_newarray_##intern(len); \
+ \
+ return (type) jni_NewLocalRef(env, (jobject) a); \
}
+JNI_NEW_ARRAY(Boolean, jbooleanArray, boolean)
+JNI_NEW_ARRAY(Byte, jbyteArray, byte)
+JNI_NEW_ARRAY(Char, jcharArray, char)
+JNI_NEW_ARRAY(Short, jshortArray, short)
+JNI_NEW_ARRAY(Int, jintArray, int)
+JNI_NEW_ARRAY(Long, jlongArray, long)
+JNI_NEW_ARRAY(Float, jfloatArray, float)
+JNI_NEW_ARRAY(Double, jdoubleArray, double)
-void _Jv_JNI_SetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start,
- jsize len, const jlong *buf)
-{
- java_longarray *la;
- STATISTICS(jniinvokation());
+/* Get<PrimitiveType>ArrayElements *********************************************
- la = (java_longarray *) array;
+ A family of functions that returns the body of the primitive array.
- if ((start < 0) || (len < 0) || (start + len > la->header.size))
- exceptions_throw_arrayindexoutofboundsexception();
- else
- MCOPY(&la->data[start], buf, s8, len);
-}
+*******************************************************************************/
+#define JNI_GET_ARRAY_ELEMENTS(name, type, intern) \
+type *_Jv_JNI_Get##name##ArrayElements(JNIEnv *env, type##Array array, \
+ jboolean *isCopy) \
+{ \
+ java_handle_##intern##array_t *a; \
+ \
+ TRACEJNICALLS(("_Jv_JNI_Get" STR(name) "ArrayElements(env=%p, array=%p, isCopy=%d)", env, array, isCopy)); \
+ \
+ a = (java_handle_##intern##array_t *) array; \
+ \
+ if (isCopy) \
+ *isCopy = JNI_FALSE; \
+ \
+ return (type *) LLNI_array_data(a); \
+}
+
+JNI_GET_ARRAY_ELEMENTS(Boolean, jboolean, boolean)
+JNI_GET_ARRAY_ELEMENTS(Byte, jbyte, byte)
+JNI_GET_ARRAY_ELEMENTS(Char, jchar, char)
+JNI_GET_ARRAY_ELEMENTS(Short, jshort, short)
+JNI_GET_ARRAY_ELEMENTS(Int, jint, int)
+JNI_GET_ARRAY_ELEMENTS(Long, jlong, long)
+JNI_GET_ARRAY_ELEMENTS(Float, jfloat, float)
+JNI_GET_ARRAY_ELEMENTS(Double, jdouble, double)
-void _Jv_JNI_SetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
- jsize len, const jfloat *buf)
-{
- java_floatarray *fa;
- STATISTICS(jniinvokation());
+/* Release<PrimitiveType>ArrayElements *****************************************
+
+ A family of functions that informs the VM that the native code no
+ longer needs access to elems. The elems argument is a pointer
+ derived from array using the corresponding
+ Get<PrimitiveType>ArrayElements() function. If necessary, this
+ function copies back all changes made to elems to the original
+ array.
- fa = (java_floatarray *) array;
+*******************************************************************************/
- if ((start < 0) || (len < 0) || (start + len > fa->header.size))
- exceptions_throw_arrayindexoutofboundsexception();
- else
- MCOPY(&fa->data[start], buf, float, len);
-}
+#define JNI_RELEASE_ARRAY_ELEMENTS(name, type, intern, intern2) \
+void _Jv_JNI_Release##name##ArrayElements(JNIEnv *env, type##Array array, \
+ type *elems, jint mode) \
+{ \
+ java_handle_##intern##array_t *a; \
+ \
+ STATISTICS(jniinvokation()); \
+ \
+ a = (java_handle_##intern##array_t *) array; \
+ \
+ if (elems != (type *) LLNI_array_data(a)) { \
+ switch (mode) { \
+ case JNI_COMMIT: \
+ MCOPY(LLNI_array_data(a), elems, intern2, LLNI_array_size(a)); \
+ break; \
+ case 0: \
+ MCOPY(LLNI_array_data(a), elems, intern2, LLNI_array_size(a)); \
+ /* XXX TWISTI how should it be freed? */ \
+ break; \
+ case JNI_ABORT: \
+ /* XXX TWISTI how should it be freed? */ \
+ break; \
+ } \
+ } \
+}
+
+JNI_RELEASE_ARRAY_ELEMENTS(Boolean, jboolean, boolean, u1)
+JNI_RELEASE_ARRAY_ELEMENTS(Byte, jbyte, byte, s1)
+JNI_RELEASE_ARRAY_ELEMENTS(Char, jchar, char, u2)
+JNI_RELEASE_ARRAY_ELEMENTS(Short, jshort, short, s2)
+JNI_RELEASE_ARRAY_ELEMENTS(Int, jint, int, s4)
+JNI_RELEASE_ARRAY_ELEMENTS(Long, jlong, long, s8)
+JNI_RELEASE_ARRAY_ELEMENTS(Float, jfloat, float, float)
+JNI_RELEASE_ARRAY_ELEMENTS(Double, jdouble, double, double)
-void _Jv_JNI_SetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
- jsize len, const jdouble *buf)
-{
- java_doublearray *da;
+/* Get<PrimitiveType>ArrayRegion **********************************************
- STATISTICS(jniinvokation());
+ A family of functions that copies a region of a primitive array
+ into a buffer.
- da = (java_doublearray *) array;
+*******************************************************************************/
- if ((start < 0) || (len < 0) || (start + len > da->header.size))
- exceptions_throw_arrayindexoutofboundsexception();
- else
- MCOPY(&da->data[start], buf, double, len);
-}
+#define JNI_GET_ARRAY_REGION(name, type, intern, intern2) \
+void _Jv_JNI_Get##name##ArrayRegion(JNIEnv *env, type##Array array, \
+ jsize start, jsize len, type *buf) \
+{ \
+ java_handle_##intern##array_t *a; \
+ \
+ TRACEJNICALLS(("_Jv_JNI_Get" STR(name) "ArrayRegion(env=%p, array=%p, start=%d, len=%d, buf=%p)", env, array, start, len, buf)); \
+ \
+ a = (java_handle_##intern##array_t *) array; \
+ \
+ if ((start < 0) || (len < 0) || (start + len > LLNI_array_size(a))) \
+ exceptions_throw_arrayindexoutofboundsexception(); \
+ else \
+ MCOPY(buf, &LLNI_array_direct(a, start), intern2, len); \
+}
+
+JNI_GET_ARRAY_REGION(Boolean, jboolean, boolean, u1)
+JNI_GET_ARRAY_REGION(Byte, jbyte, byte, s1)
+JNI_GET_ARRAY_REGION(Char, jchar, char, u2)
+JNI_GET_ARRAY_REGION(Short, jshort, short, s2)
+JNI_GET_ARRAY_REGION(Int, jint, int, s4)
+JNI_GET_ARRAY_REGION(Long, jlong, long, s8)
+JNI_GET_ARRAY_REGION(Float, jfloat, float, float)
+JNI_GET_ARRAY_REGION(Double, jdouble, double, double)
+
+
+/* Set<PrimitiveType>ArrayRegion **********************************************
+
+ A family of functions that copies back a region of a primitive
+ array from a buffer.
+
+*******************************************************************************/
+
+#define JNI_SET_ARRAY_REGION(name, type, intern, intern2) \
+void _Jv_JNI_Set##name##ArrayRegion(JNIEnv *env, type##Array array, \
+ jsize start, jsize len, const type *buf) \
+{ \
+ java_handle_##intern##array_t *a; \
+ \
+ STATISTICS(jniinvokation()); \
+ \
+ a = (java_handle_##intern##array_t *) array; \
+ \
+ if ((start < 0) || (len < 0) || (start + len > LLNI_array_size(a))) \
+ exceptions_throw_arrayindexoutofboundsexception(); \
+ else \
+ MCOPY(&LLNI_array_direct(a, start), buf, intern2, len); \
+}
+
+JNI_SET_ARRAY_REGION(Boolean, jboolean, boolean, u1)
+JNI_SET_ARRAY_REGION(Byte, jbyte, byte, s1)
+JNI_SET_ARRAY_REGION(Char, jchar, char, u2)
+JNI_SET_ARRAY_REGION(Short, jshort, short, s2)
+JNI_SET_ARRAY_REGION(Int, jint, int, s4)
+JNI_SET_ARRAY_REGION(Long, jlong, long, s8)
+JNI_SET_ARRAY_REGION(Float, jfloat, float, float)
+JNI_SET_ARRAY_REGION(Double, jdouble, double, double)
/* Registering Native Methods *************************************************/
STATISTICS(jniinvokation());
- c = (classinfo *) clazz;
+ c = LLNI_classinfo_unwrap(clazz);
/* XXX: if implemented this needs a call to jvmti_NativeMethodBind
if (jvmti) jvmti_NativeMethodBind(method, address, new_address_ptr);
void _Jv_JNI_GetStringRegion(JNIEnv* env, jstring str, jsize start, jsize len,
jchar *buf)
{
- java_lang_String *s;
- java_chararray *ca;
+ java_lang_String *s;
+ java_handle_chararray_t *ca;
STATISTICS(jniinvokation());
s = (java_lang_String *) str;
- ca = s->value;
+ LLNI_field_get_ref(s, value, ca);
- if ((start < 0) || (len < 0) || (start > s->count) ||
- (start + len > s->count)) {
+ if ((start < 0) || (len < 0) || (start > LLNI_field_direct(s, count)) ||
+ (start + len > LLNI_field_direct(s, count))) {
exceptions_throw_stringindexoutofboundsexception();
return;
}
- MCOPY(buf, &ca->data[start], u2, len);
+ MCOPY(buf, &LLNI_array_direct(ca, start), u2, len);
}
void _Jv_JNI_GetStringUTFRegion(JNIEnv* env, jstring str, jsize start,
jsize len, char *buf)
{
- java_lang_String *s;
- java_chararray *ca;
- s4 i;
+ java_lang_String *s;
+ java_handle_chararray_t *ca;
+ s4 i;
+ int32_t count;
+ int32_t offset;
- STATISTICS(jniinvokation());
+ TRACEJNICALLS(("_Jv_JNI_GetStringUTFRegion(env=%p, str=%p, start=%d, len=%d, buf=%p)", env, str, start, len, buf));
s = (java_lang_String *) str;
- ca = s->value;
+ LLNI_field_get_ref(s, value, ca);
+ LLNI_field_get_val(s, count, count);
+ LLNI_field_get_val(s, offset, offset);
- if ((start < 0) || (len < 0) || (start > s->count) ||
- (start + len > s->count)) {
+ if ((start < 0) || (len < 0) || (start > count) || (start + len > count)) {
exceptions_throw_stringindexoutofboundsexception();
return;
}
- /* XXX not sure if this is correct */
-
for (i = 0; i < len; i++)
- buf[i] = ca->data[start + i];
+ buf[i] = LLNI_array_direct(ca, offset + start + i);
buf[i] = '\0';
}
Obtain a direct pointer to array elements.
+ ATTENTION: Critical section keeps open when this function returns!
+ See ReleasePrimitiveArrayCritical.
+
*******************************************************************************/
-void *_Jv_JNI_GetPrimitiveArrayCritical(JNIEnv *env, jarray array,
- jboolean *isCopy)
+void* jni_GetPrimitiveArrayCritical(JNIEnv *env, jarray array, jboolean *isCopy)
{
- java_bytearray *ba;
- jbyte *bp;
+ java_handle_t* h;
+ java_array_t* a;
+ arraydescriptor* ad;
+ void* data;
+
+ TRACEJNICALLS(("jni_GetPrimitiveArrayCritical(env=%p, array=%p, isCopy=%d)", env, array, isCopy));
+
+ if (isCopy != NULL) {
+ *isCopy = JNI_FALSE;
+ }
+
+ LLNI_CRITICAL_START;
+
+ h = (java_handle_t*) array;
+ a = (java_array_t*) LLNI_UNWRAP(h);
+ ad = a->objheader.vftbl->arraydesc;
- ba = (java_bytearray *) array;
+ /* Sanity check. */
- /* do the same as Kaffe does */
+ assert(ad != NULL);
- bp = _Jv_JNI_GetByteArrayElements(env, (jbyteArray) ba, isCopy);
+ data = (void*) (((intptr_t) a) + ad->dataoffset);
- return (void *) bp;
+ return data;
}
No specific documentation.
+ ATTENTION: This function closes the critical section opened in
+ GetPrimitiveArrayCritical!
+
*******************************************************************************/
-void _Jv_JNI_ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array,
- void *carray, jint mode)
+void jni_ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array, void *carray, jint mode)
{
- STATISTICS(jniinvokation());
+ TRACEJNICALLS(("jni_ReleasePrimitiveArrayCritical(env=%p, array=%p, carray=%p, mode=%d)", env, array, carray, mode));
- /* do the same as Kaffe does */
-
- _Jv_JNI_ReleaseByteArrayElements(env, (jbyteArray) array, (jbyte *) carray,
- mode);
+ LLNI_CRITICAL_END;
}
jweak _Jv_JNI_NewWeakGlobalRef(JNIEnv* env, jobject obj)
{
- STATISTICS(jniinvokation());
-
- log_text("JNI-Call: NewWeakGlobalRef: IMPLEMENT ME!");
+ TRACEJNICALLS(("_Jv_JNI_NewWeakGlobalRef(env=%p, obj=%p): IMPLEMENT ME!", env, obj));
return obj;
}
void _Jv_JNI_DeleteWeakGlobalRef(JNIEnv* env, jweak ref)
{
- STATISTICS(jniinvokation());
-
- log_text("JNI-Call: DeleteWeakGlobalRef: IMPLEMENT ME");
+ TRACEJNICALLS(("_Jv_JNI_DeleteWeakGlobalRef(env=%p, ref=%p): IMPLEMENT ME", env, ref));
}
*******************************************************************************/
-jobject _Jv_JNI_NewGlobalRef(JNIEnv* env, jobject obj)
+jobject jni_NewGlobalRef(JNIEnv* env, jobject obj)
{
hashtable_global_ref_entry *gre;
u4 key; /* hashkey */
u4 slot; /* slot in hashtable */
- java_objectheader *o;
+ java_handle_t *o;
- STATISTICS(jniinvokation());
+ TRACEJNICALLS(("jni_NewGlobalRef(env=%p, obj=%p)", env, obj));
- o = (java_objectheader *) obj;
+ o = (java_handle_t *) obj;
LOCK_MONITOR_ENTER(hashtable_global_ref->header);
+ LLNI_CRITICAL_START;
+
/* normally addresses are aligned to 4, 8 or 16 bytes */
- key = ((u4) (ptrint) obj) >> 4; /* align to 16-byte boundaries */
+ key = heap_hashcode(LLNI_DIRECT(o)) >> 4; /* align to 16-byte boundaries */
slot = key & (hashtable_global_ref->size - 1);
gre = hashtable_global_ref->ptr[slot];
/* search external hash chain for the entry */
while (gre) {
- if (gre->o == o) {
+ if (gre->o == LLNI_DIRECT(o)) {
/* global object found, increment the reference */
gre->refs++;
- LOCK_MONITOR_EXIT(hashtable_global_ref->header);
-
- return obj;
+ break;
}
gre = gre->hashlink; /* next element in external chain */
}
+ LLNI_CRITICAL_END;
+
/* global ref not found, create a new one */
- gre = NEW(hashtable_global_ref_entry);
+ if (gre == NULL) {
+ gre = GCNEW_UNCOLLECTABLE(hashtable_global_ref_entry, 1);
+
+#if defined(ENABLE_GC_CACAO)
+ /* register global ref with the GC */
+
+ gc_reference_register(&(gre->o), GC_REFTYPE_JNI_GLOBALREF);
+#endif
+
+ LLNI_CRITICAL_START;
+
+ gre->o = LLNI_DIRECT(o);
+ gre->refs = 1;
- gre->o = o;
- gre->refs = 1;
+ LLNI_CRITICAL_END;
- /* insert entry into hashtable */
+ /* insert entry into hashtable */
- gre->hashlink = hashtable_global_ref->ptr[slot];
+ gre->hashlink = hashtable_global_ref->ptr[slot];
- hashtable_global_ref->ptr[slot] = gre;
+ hashtable_global_ref->ptr[slot] = gre;
- /* update number of hashtable-entries */
+ /* update number of hashtable-entries */
- hashtable_global_ref->entries++;
+ hashtable_global_ref->entries++;
+ }
LOCK_MONITOR_EXIT(hashtable_global_ref->header);
+#if defined(ENABLE_HANDLES)
+ return gre;
+#else
return obj;
+#endif
}
*******************************************************************************/
-void _Jv_JNI_DeleteGlobalRef(JNIEnv* env, jobject globalRef)
+void jni_DeleteGlobalRef(JNIEnv* env, jobject globalRef)
{
hashtable_global_ref_entry *gre;
hashtable_global_ref_entry *prevgre;
u4 key; /* hashkey */
u4 slot; /* slot in hashtable */
- java_objectheader *o;
+ java_handle_t *o;
- STATISTICS(jniinvokation());
+ TRACEJNICALLS(("jni_DeleteGlobalRef(env=%p, globalRef=%p)", env, globalRef));
- o = (java_objectheader *) globalRef;
+ o = (java_handle_t *) globalRef;
LOCK_MONITOR_ENTER(hashtable_global_ref->header);
+ LLNI_CRITICAL_START;
+
/* normally addresses are aligned to 4, 8 or 16 bytes */
- key = ((u4) (ptrint) globalRef) >> 4; /* align to 16-byte boundaries */
+ key = heap_hashcode(LLNI_DIRECT(o)) >> 4; /* align to 16-byte boundaries */
slot = key & (hashtable_global_ref->size - 1);
gre = hashtable_global_ref->ptr[slot];
/* search external hash chain for the entry */
while (gre) {
- if (gre->o == o) {
+ if (gre->o == LLNI_DIRECT(o)) {
/* global object found, decrement the reference count */
gre->refs--;
else
prevgre->hashlink = gre->hashlink;
- FREE(gre, hashtable_global_ref_entry);
+#if defined(ENABLE_GC_CACAO)
+ /* unregister global ref with the GC */
+
+ gc_reference_unregister(&(gre->o));
+#endif
+
+ GCFREE(gre);
}
+ LLNI_CRITICAL_END;
+
LOCK_MONITOR_EXIT(hashtable_global_ref->header);
return;
gre = gre->hashlink; /* next element in external chain */
}
- log_println("JNI-DeleteGlobalRef: global reference not found");
+ log_println("jni_DeleteGlobalRef: Global reference not found.");
+
+ LLNI_CRITICAL_END;
LOCK_MONITOR_EXIT(hashtable_global_ref->header);
}
jboolean _Jv_JNI_ExceptionCheck(JNIEnv *env)
{
- java_objectheader *o;
+ java_handle_t *o;
STATISTICS(jniinvokation());
*******************************************************************************/
-jobject _Jv_JNI_NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity)
+jobject jni_NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity)
{
-#if defined(ENABLE_JAVASE) && defined(WITH_CLASSPATH_GNU)
- java_objectheader *nbuf;
+#if defined(ENABLE_JAVASE)
+# if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
+ java_handle_t *nbuf;
# if SIZEOF_VOID_P == 8
gnu_classpath_Pointer64 *paddress;
gnu_classpath_Pointer32 *paddress;
# endif
- STATISTICS(jniinvokation());
+ TRACEJNICALLSENTER(("jni_NewDirectByteBuffer(env=%p, address=%p, capacity=%ld)", env, address, capacity));
/* alocate a gnu.classpath.Pointer{32,64} object */
/* fill gnu.classpath.Pointer{32,64} with address */
- paddress->data = (ptrint) address;
+ LLNI_field_set_val(paddress, data, (ptrint) address);
/* create a java.nio.DirectByteBufferImpl$ReadWrite object */
/* add local reference and return the value */
- return _Jv_JNI_NewLocalRef(env, nbuf);
+ TRACEJNICALLSEXIT(("->%p", nbuf));
+
+ return jni_NewLocalRef(env, nbuf);
+
+# elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
+
+ jobject o;
+ int64_t addr;
+ int32_t cap;
+
+ TRACEJNICALLSENTER(("jni_NewDirectByteBuffer(env=%p, address=%p, capacity=%ld)", env, address, capacity));
+
+ /* Be paranoid about address sign-extension. */
+
+ addr = (int64_t) ((uintptr_t) address);
+ cap = (int32_t) capacity;
+
+ o = (*env)->NewObject(env, (jclass) class_java_nio_DirectByteBuffer,
+ (jmethodID) dbb_init, addr, cap);
+
+ /* Add local reference and return the value. */
+
+ TRACEJNICALLSEXIT(("->%p", o));
+
+ return jni_NewLocalRef(env, o);
+
+# else
+# error unknown classpath configuration
+# endif
+
#else
- vm_abort("_Jv_JNI_NewDirectByteBuffer: not implemented in this configuration");
+ vm_abort("jni_NewDirectByteBuffer: Not implemented in this configuration.");
/* keep compiler happy */
void *_Jv_JNI_GetDirectBufferAddress(JNIEnv *env, jobject buf)
{
-#if defined(ENABLE_JAVASE) && defined(WITH_CLASSPATH_GNU)
+#if defined(ENABLE_JAVASE)
+ java_handle_t *h;
+
+# if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
+
java_nio_DirectByteBufferImpl *nbuf;
-# if SIZEOF_VOID_P == 8
- gnu_classpath_Pointer64 *address;
-# else
- gnu_classpath_Pointer32 *address;
-# endif
+ gnu_classpath_Pointer *po;
+# if SIZEOF_VOID_P == 8
+ gnu_classpath_Pointer64 *paddress;
+ int64_t address;
+# else
+ gnu_classpath_Pointer32 *paddress;
+ int32_t address;
+# endif
+ void *p;
- STATISTICS(jniinvokation());
+ TRACEJNICALLS(("_Jv_JNI_GetDirectBufferAddress(env=%p, buf=%p)", env, buf));
+
+ /* Prevent compiler warning. */
+
+ h = (java_handle_t *) buf;
- if (!builtin_instanceof(buf, class_java_nio_Buffer))
+ if ((h != NULL) && !builtin_instanceof(h, class_java_nio_Buffer))
return NULL;
nbuf = (java_nio_DirectByteBufferImpl *) buf;
-# if SIZEOF_VOID_P == 8
- address = (gnu_classpath_Pointer64 *) nbuf->address;
-# else
- address = (gnu_classpath_Pointer32 *) nbuf->address;
-# endif
+ LLNI_field_get_ref(nbuf, address, po);
+
+# if SIZEOF_VOID_P == 8
+ paddress = (gnu_classpath_Pointer64 *) po;
+# else
+ paddress = (gnu_classpath_Pointer32 *) po;
+# endif
+
+ if (paddress == NULL)
+ return NULL;
+
+ LLNI_field_get_val(paddress, data, address);
+
+ p = (void *) (intptr_t) address;
+
+ return p;
- if (address == NULL)
+# elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
+
+ java_nio_Buffer *o;
+ int64_t address;
+ void *p;
+
+ TRACEJNICALLS(("_Jv_JNI_GetDirectBufferAddress(env=%p, buf=%p)", env, buf));
+
+ /* Prevent compiler warning. */
+
+ h = (java_handle_t *) buf;
+
+ if ((h != NULL) && !builtin_instanceof(h, class_sun_nio_ch_DirectBuffer))
return NULL;
- return (void *) address->data;
+ o = (java_nio_Buffer *) buf;
+
+ LLNI_field_get_val(o, address, address);
+
+ p = (void *) (intptr_t) address;
+
+ return p;
+
+# else
+# error unknown classpath configuration
+# endif
+
#else
+
vm_abort("_Jv_JNI_GetDirectBufferAddress: not implemented in this configuration");
/* keep compiler happy */
return NULL;
+
#endif
}
jlong _Jv_JNI_GetDirectBufferCapacity(JNIEnv* env, jobject buf)
{
-#if defined(ENABLE_JAVASE) && defined(WITH_CLASSPATH_GNU)
- java_objectheader *o;
- java_nio_Buffer *nbuf;
+#if defined(ENABLE_JAVASE) && defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
+ java_handle_t *o;
+ java_nio_Buffer *nbuf;
+ jlong capacity;
STATISTICS(jniinvokation());
- o = (java_objectheader *) buf;
+ o = (java_handle_t *) buf;
if (!builtin_instanceof(o, class_java_nio_DirectByteBufferImpl))
return -1;
nbuf = (java_nio_Buffer *) o;
- return (jlong) nbuf->cap;
+ LLNI_field_get_val(nbuf, cap, capacity);
+
+ return capacity;
#else
vm_abort("_Jv_JNI_GetDirectBufferCapacity: not implemented in this configuration");
}
+/* GetObjectRefType ************************************************************
+
+ Returns the type of the object referred to by the obj argument. The
+ argument obj can either be a local, global or weak global
+ reference.
+
+*******************************************************************************/
+
+jobjectRefType jni_GetObjectRefType(JNIEnv *env, jobject obj)
+{
+ log_println("jni_GetObjectRefType: IMPLEMENT ME!");
+
+ return -1;
+}
+
+
/* DestroyJavaVM ***************************************************************
Unloads a Java VM and reclaims its resources. Only the main thread
jint _Jv_JNI_DestroyJavaVM(JavaVM *vm)
{
- s4 status;
+ int status;
- STATISTICS(jniinvokation());
+ TRACEJNICALLS(("_Jv_JNI_DestroyJavaVM(vm=%p)", vm));
+
+ if (vm_created == false)
+ return JNI_ERR;
status = vm_destroy(vm);
*******************************************************************************/
-static s4 jni_attach_current_thread(void **p_env, void *thr_args, bool isdaemon)
+static int jni_attach_current_thread(void **p_env, void *thr_args, bool isdaemon)
{
+#if defined(ENABLE_THREADS)
JavaVMAttachArgs *vm_aargs;
+ bool result;
-#if defined(ENABLE_THREADS)
- if (threads_get_current_threadobject() == NULL) {
- vm_aargs = (JavaVMAttachArgs *) thr_args;
+ /* If the current thread has already been attached, this operation
+ is a no-op. */
- if (vm_aargs != NULL) {
- if ((vm_aargs->version != JNI_VERSION_1_2) &&
- (vm_aargs->version != JNI_VERSION_1_4))
- return JNI_EVERSION;
- }
+ result = thread_current_is_attached();
+
+ if (result == true) {
+ *p_env = _Jv_env;
+
+ return JNI_OK;
+ }
- if (!threads_attach_current_thread(vm_aargs, false))
- return JNI_ERR;
+ vm_aargs = (JavaVMAttachArgs *) thr_args;
- if (!jni_init_localref_table())
- return JNI_ERR;
+ if (vm_aargs != NULL) {
+ if ((vm_aargs->version != JNI_VERSION_1_2) &&
+ (vm_aargs->version != JNI_VERSION_1_4))
+ return JNI_EVERSION;
}
+
+ if (!thread_attach_current_external_thread(vm_aargs, false))
+ return JNI_ERR;
+
+ if (!localref_table_init())
+ return JNI_ERR;
#endif
*p_env = _Jv_env;
}
-jint _Jv_JNI_AttachCurrentThread(JavaVM *vm, void **p_env, void *thr_args)
+jint jni_AttachCurrentThread(JavaVM *vm, void **p_env, void *thr_args)
{
- STATISTICS(jniinvokation());
+ int result;
+
+ TRACEJNICALLS(("jni_AttachCurrentThread(vm=%p, p_env=%p, thr_args=%p)", vm, p_env, thr_args));
- return jni_attach_current_thread(p_env, thr_args, false);
+ if (vm_created == false)
+ return JNI_ERR;
+
+ result = jni_attach_current_thread(p_env, thr_args, false);
+
+ return result;
}
*******************************************************************************/
-jint _Jv_JNI_DetachCurrentThread(JavaVM *vm)
+jint jni_DetachCurrentThread(JavaVM *vm)
{
#if defined(ENABLE_THREADS)
- threadobject *thread;
+ bool result;
- STATISTICS(jniinvokation());
+ TRACEJNICALLS(("jni_DetachCurrentThread(vm=%p)", vm));
+
+ /* If the current thread has already been detached, this operation
+ is a no-op. */
+
+ result = thread_current_is_attached();
+
+ if (result == false)
+ return true;
+
+ /* We need to pop all frames before we can destroy the table. */
- thread = threads_get_current_threadobject();
+ localref_frame_pop_all();
- if (thread == NULL)
+ if (!localref_table_destroy())
return JNI_ERR;
- if (!threads_detach_thread(thread))
+ if (!thread_detach_current_external_thread())
return JNI_ERR;
#endif
*******************************************************************************/
-jint _Jv_JNI_GetEnv(JavaVM *vm, void **env, jint version)
+jint jni_GetEnv(JavaVM *vm, void **env, jint version)
{
- STATISTICS(jniinvokation());
+ TRACEJNICALLS(("jni_GetEnv(vm=%p, env=%p, version=%d)", vm, env, version));
+
+ if (vm_created == false) {
+ *env = NULL;
+ return JNI_EDETACHED;
+ }
#if defined(ENABLE_THREADS)
- if (threads_get_current_threadobject() == NULL) {
+ if (thread_get_current() == NULL) {
*env = NULL;
return JNI_EDETACHED;
}
#endif
- /* check the JNI version */
+ /* Check the JNI version. */
- switch (version) {
- case JNI_VERSION_1_1:
- case JNI_VERSION_1_2:
- case JNI_VERSION_1_4:
+ if (jni_version_check(version) == true) {
*env = _Jv_env;
return JNI_OK;
-
- default:
- ;
}
#if defined(ENABLE_JVMTI)
*******************************************************************************/
-jint _Jv_JNI_AttachCurrentThreadAsDaemon(JavaVM *vm, void **penv, void *args)
+jint jni_AttachCurrentThreadAsDaemon(JavaVM *vm, void **penv, void *args)
{
- STATISTICS(jniinvokation());
+ int result;
+
+ TRACEJNICALLS(("jni_AttachCurrentThreadAsDaemon(vm=%p, penv=%p, args=%p)", vm, penv, args));
+
+ if (vm_created == false)
+ return JNI_ERR;
+
+ result = jni_attach_current_thread(penv, args, true);
- return jni_attach_current_thread(penv, args, true);
+ return result;
}
NULL,
_Jv_JNI_DestroyJavaVM,
- _Jv_JNI_AttachCurrentThread,
- _Jv_JNI_DetachCurrentThread,
- _Jv_JNI_GetEnv,
- _Jv_JNI_AttachCurrentThreadAsDaemon
+ jni_AttachCurrentThread,
+ jni_DetachCurrentThread,
+ jni_GetEnv,
+ jni_AttachCurrentThreadAsDaemon
};
_Jv_JNI_GetVersion,
_Jv_JNI_DefineClass,
- _Jv_JNI_FindClass,
- _Jv_JNI_FromReflectedMethod,
- _Jv_JNI_FromReflectedField,
+ jni_FindClass,
+ jni_FromReflectedMethod,
+ jni_FromReflectedField,
_Jv_JNI_ToReflectedMethod,
_Jv_JNI_GetSuperclass,
_Jv_JNI_IsAssignableFrom,
_Jv_JNI_Throw,
_Jv_JNI_ThrowNew,
_Jv_JNI_ExceptionOccurred,
- _Jv_JNI_ExceptionDescribe,
- _Jv_JNI_ExceptionClear,
+ jni_ExceptionDescribe,
+ jni_ExceptionClear,
_Jv_JNI_FatalError,
- _Jv_JNI_PushLocalFrame,
- _Jv_JNI_PopLocalFrame,
+ jni_PushLocalFrame,
+ jni_PopLocalFrame,
- _Jv_JNI_NewGlobalRef,
- _Jv_JNI_DeleteGlobalRef,
- _Jv_JNI_DeleteLocalRef,
+ jni_NewGlobalRef,
+ jni_DeleteGlobalRef,
+ jni_DeleteLocalRef,
_Jv_JNI_IsSameObject,
- _Jv_JNI_NewLocalRef,
- _Jv_JNI_EnsureLocalCapacity,
+ jni_NewLocalRef,
+ jni_EnsureLocalCapacity,
_Jv_JNI_AllocObject,
- _Jv_JNI_NewObject,
+ jni_NewObject,
_Jv_JNI_NewObjectV,
_Jv_JNI_NewObjectA,
_Jv_JNI_GetJavaVM,
- /* new JNI 1.2 functions */
+ /* New JNI 1.2 functions. */
_Jv_JNI_GetStringRegion,
_Jv_JNI_GetStringUTFRegion,
- _Jv_JNI_GetPrimitiveArrayCritical,
- _Jv_JNI_ReleasePrimitiveArrayCritical,
+ jni_GetPrimitiveArrayCritical,
+ jni_ReleasePrimitiveArrayCritical,
_Jv_JNI_GetStringCritical,
_Jv_JNI_ReleaseStringCritical,
_Jv_JNI_ExceptionCheck,
- /* new JNI 1.4 functions */
+ /* New JNI 1.4 functions. */
- _Jv_JNI_NewDirectByteBuffer,
+ jni_NewDirectByteBuffer,
_Jv_JNI_GetDirectBufferAddress,
- _Jv_JNI_GetDirectBufferCapacity
+ _Jv_JNI_GetDirectBufferCapacity,
+
+ /* New JNI 1.6 functions. */
+
+ jni_GetObjectRefType
};
jint JNI_GetCreatedJavaVMs(JavaVM **vmBuf, jsize bufLen, jsize *nVMs)
{
- log_text("JNI_GetCreatedJavaVMs: IMPLEMENT ME!!!");
+ TRACEJNICALLS(("JNI_GetCreatedJavaVMs(vmBuf=%p, jsize=%d, jsize=%p)", vmBuf, bufLen, nVMs));
- return 0;
+ if (bufLen <= 0)
+ return JNI_ERR;
+
+ /* We currently only support 1 VM running. */
+
+ vmBuf[0] = (JavaVM *) _Jv_jvm;
+ *nVMs = 1;
+
+ return JNI_OK;
}
jint JNI_CreateJavaVM(JavaVM **p_vm, void **p_env, void *vm_args)
{
+ TRACEJNICALLS(("JNI_CreateJavaVM(p_vm=%p, p_env=%p, vm_args=%p)", p_vm, p_env, vm_args));
+
/* actually create the JVM */
if (!vm_createjvm(p_vm, p_env, vm_args))