Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: jni.c 7282 2007-02-04 16:08:27Z twisti $
+ $Id: jni.c 7723 2007-04-16 18:03:08Z michi $
*/
#include "native/jni.h"
#include "native/native.h"
-#include "native/include/gnu_classpath_Pointer.h"
+#if defined(ENABLE_JAVASE)
+# if defined(WITH_CLASSPATH_GNU)
+# include "native/include/gnu_classpath_Pointer.h"
-#if SIZEOF_VOID_P == 8
-# include "native/include/gnu_classpath_Pointer64.h"
-#else
-# include "native/include/gnu_classpath_Pointer32.h"
+# if SIZEOF_VOID_P == 8
+# include "native/include/gnu_classpath_Pointer64.h"
+# else
+# include "native/include/gnu_classpath_Pointer32.h"
+# endif
+# endif
#endif
#include "native/include/java_lang_Object.h"
#include "native/include/java_lang_Double.h"
#include "native/include/java_lang_String.h"
#include "native/include/java_lang_Throwable.h"
-#include "native/include/java_lang_reflect_Method.h"
-#include "native/include/java_lang_reflect_Constructor.h"
-#include "native/include/java_lang_reflect_Field.h"
-#include "native/include/java_lang_ClassLoader.h"
-#include "native/include/java_lang_Class.h" /* for java_lang_VMClass.h */
-#include "native/include/java_lang_VMClass.h"
-#include "native/include/java_lang_VMClassLoader.h"
-#include "native/include/java_nio_Buffer.h"
-#include "native/include/java_nio_DirectByteBufferImpl.h"
+#if defined(ENABLE_JAVASE)
+# include "native/include/java_lang_ClassLoader.h"
+
+# include "native/include/java_lang_reflect_Constructor.h"
+# include "native/include/java_lang_reflect_Field.h"
+# include "native/include/java_lang_reflect_Method.h"
+
+# include "native/include/java_nio_Buffer.h"
+# include "native/include/java_nio_DirectByteBufferImpl.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"
+#endif
+
#if defined(ENABLE_THREADS)
# include "threads/native/lock.h"
# include "threads/native/threads.h"
#else
# include "threads/none/lock.h"
+# include "threads/none/threads.h"
#endif
#include "toolbox/logging.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/resolve.h"
+#include "vm/resolve.h"
#include "vmcore/statistics.h"
#define HASHTABLE_GLOBAL_REF_SIZE 64 /* initial size of globalref-hash */
-static hashtable *hashtable_global_ref; /* hashtable for globalrefs */
+hashtable *hashtable_global_ref; /* hashtable for globalrefs */
/* direct buffer stuff ********************************************************/
+#if defined(ENABLE_JAVASE)
static classinfo *class_java_nio_Buffer;
static classinfo *class_java_nio_DirectByteBufferImpl;
static classinfo *class_java_nio_DirectByteBufferImpl_ReadWrite;
-#if SIZEOF_VOID_P == 8
+
+# if defined(WITH_CLASSPATH_GNU)
+# if SIZEOF_VOID_P == 8
static classinfo *class_gnu_classpath_Pointer64;
-#else
+# else
static classinfo *class_gnu_classpath_Pointer32;
-#endif
+# endif
+# endif
static methodinfo *dbbirw_init;
+#endif
/* local reference table ******************************************************/
hashtable_create(hashtable_global_ref, HASHTABLE_GLOBAL_REF_SIZE);
+#if defined(ENABLE_JAVASE)
/* direct buffer stuff */
if (!(class_java_nio_Buffer =
utf_new_char("(Ljava/lang/Object;Lgnu/classpath/Pointer;III)V"))))
return false;
-#if SIZEOF_VOID_P == 8
+# if defined(WITH_CLASSPATH_GNU)
+# if SIZEOF_VOID_P == 8
if (!(class_gnu_classpath_Pointer64 =
load_class_bootstrap(utf_new_char("gnu/classpath/Pointer64"))) ||
!link_class(class_gnu_classpath_Pointer64))
return false;
-#else
+# else
if (!(class_gnu_classpath_Pointer32 =
load_class_bootstrap(utf_new_char("gnu/classpath/Pointer32"))) ||
!link_class(class_gnu_classpath_Pointer32))
return false;
-#endif
+# endif
+# endif
+#endif /* defined(ENABLE_JAVASE) */
return true;
}
{
localref_table *lrt;
+#if defined(ENABLE_GC_CACAO)
+ /* XXX this one will never get freed for the main thread;
+ call jni_free_localref_table() if you want to do it! */
+ lrt = NEW(localref_table);
+#else
lrt = GCNEW(localref_table);
+#endif
if (lrt == NULL)
return false;
}
+/* jni_init_localref_table *****************************************************
+
+ Frees the local references table of the current thread.
+
+*******************************************************************************/
+
+bool jni_free_localref_table(void)
+{
+ localref_table *lrt;
+
+#if defined(ENABLE_GC_CACAO)
+ lrt = LOCALREFTABLE;
+
+ assert(lrt);
+ assert(lrt->prev == NULL);
+
+ FREE(lrt, localref_table);
+
+ LOCALREFTABLE = NULL;
+#endif
+
+ return true;
+}
+
+
/* _Jv_jni_vmargs_from_objectarray *********************************************
XXX
vmargs = MNEW(vm_arg, argcount);
- if (!_Jv_jni_vmargs_from_objectarray(o, resm->parseddesc, vmargs, params))
+ if (!_Jv_jni_vmargs_from_objectarray(o, resm->parseddesc, vmargs, params)) {
+ MFREE(vmargs, vm_arg, argcount);
return NULL;
+ }
switch (resm->parseddesc->returntype.decltype) {
case TYPE_VOID:
jclass _Jv_JNI_DefineClass(JNIEnv *env, const char *name, jobject loader,
const jbyte *buf, jsize bufLen)
{
+#if defined(ENABLE_JAVASE)
java_lang_ClassLoader *cl;
java_lang_String *s;
java_bytearray *ba;
STATISTICS(jniinvokation());
cl = (java_lang_ClassLoader *) loader;
- s = javastring_new_from_utf_string(name);
+ s = (java_lang_String *) javastring_new_from_utf_string(name);
ba = (java_bytearray *) buf;
- c = (jclass) Java_java_lang_VMClassLoader_defineClass(env, NULL, cl, s, ba,
- 0, bufLen, NULL);
+ c = (jclass) _Jv_java_lang_ClassLoader_defineClass(cl, s, ba, 0, bufLen,
+ NULL);
return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
+#else
+ vm_abort("_Jv_JNI_DefineClass: not implemented in this configuration");
+
+ /* keep compiler happy */
+
+ return 0;
+#endif
}
jclass _Jv_JNI_FindClass(JNIEnv *env, const char *name)
{
+#if defined(ENABLE_JAVASE)
utf *u;
classinfo *cc;
classinfo *c;
return NULL;
return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
+#else
+ vm_abort("_Jv_JNI_FindClass: not implemented in this configuration");
+
+ /* keep compiler happy */
+
+ return NULL;
+#endif
}
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;
+
STATISTICS(jniinvokation());
- return Java_java_lang_VMClass_isAssignableFrom(env,
- NULL,
- (java_lang_Class *) sup,
- (java_lang_Class *) sub);
+ return _Jv_java_lang_Class_isAssignableFrom(csup, csub);
}
else
additionalrefs = 0;
+#if defined(ENABLE_GC_CACAO)
+ nlrt = MNEW(u1, sizeof(localref_table) + additionalrefs * SIZEOF_VOID_P);
+#else
nlrt = GCMNEW(u1, sizeof(localref_table) + additionalrefs * SIZEOF_VOID_P);
+#endif
if (nlrt == NULL)
return -1;
localref_table *lrt;
localref_table *plrt;
s4 localframes;
+ s4 additionalrefs;
STATISTICS(jniinvokation());
lrt->prev = NULL;
+#if defined(ENABLE_GC_CACAO)
+ /* for the exact GC local reference tables are not on the heap,
+ so we need to free them explicitly here. */
+
+ if (lrt->capacity > LOCALREFTABLE_CAPACITY)
+ additionalrefs = lrt->capacity - LOCALREFTABLE_CAPACITY;
+ else
+ additionalrefs = 0;
+
+ MFREE(lrt, u1, sizeof(localref_table) + additionalrefs * SIZEOF_VOID_P);
+#endif
+
/* set new local references table */
lrt = plrt;
{
localref_table *lrt;
- log_text("JNI-Call: EnsureLocalCapacity");
-
STATISTICS(jniinvokation());
/* get local reference table (thread specific) */
jboolean _Jv_JNI_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)
{
+ java_lang_Class *c;
+ java_lang_Object *o;
+
STATISTICS(jniinvokation());
- return Java_java_lang_VMClass_isInstance(env,
- NULL,
- (java_lang_Class *) clazz,
- (java_lang_Object *) obj);
+ c = (java_lang_Class *) clazz;
+ o = (java_lang_Object *) obj;
+
+ return _Jv_java_lang_Class_isInstance(c, o);
}
jmethodID _Jv_JNI_FromReflectedMethod(JNIEnv *env, jobject method)
{
+#if defined(ENABLE_JAVASE)
methodinfo *mi;
classinfo *c;
s4 slot;
mi = &(c->methods[slot]);
return (jmethodID) mi;
+#else
+ vm_abort("_Jv_JNI_FromReflectedMethod: not implemented in this configuration");
+
+ /* keep compiler happy */
+
+ return NULL;
+#endif
}
jfieldID _Jv_JNI_FromReflectedField(JNIEnv* env, jobject field)
{
+#if defined(ENABLE_JAVASE)
java_lang_reflect_Field *rf;
classinfo *c;
fieldinfo *f;
f = &(c->fields[rf->slot]);
return (jfieldID) f;
+#else
+ vm_abort("_Jv_JNI_FromReflectedField: not implemented in this configuration");
+
+ /* keep compiler happy */
+
+ return NULL;
+#endif
}
/* GetStringChars **************************************************************
Returns a pointer to the array of Unicode characters of the
- string. This pointer is valid until ReleaseStringchars() is called.
+ string. This pointer is valid until ReleaseStringChars() is called.
*******************************************************************************/
/* NewStringUTF ****************************************************************
- Constructs a new java.lang.String object from an array of UTF-8 characters.
+ Constructs a new java.lang.String object from an array of UTF-8
+ characters.
*******************************************************************************/
STATISTICS(jniinvokation());
- s = javastring_safe_new_from_utf8(bytes);
+ s = (java_lang_String *) javastring_safe_new_from_utf8(bytes);
return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
}
if (isCopy)
*isCopy = JNI_TRUE;
- u = javastring_toutf((java_lang_String *) string, false);
+ u = javastring_toutf((java_objectheader *) string, false);
if (u != NULL)
return u->text;
/* check if the class of value is a subclass of the element class
of the array */
- if (!builtin_canstore(oa, o)) {
- exceptions_throw_arraystoreexception();
+ if (!builtin_canstore(oa, o))
return;
- }
oa->data[index] = val;
}
jobject _Jv_JNI_NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity)
{
+#if defined(ENABLE_JAVASE)
java_objectheader *nbuf;
-#if SIZEOF_VOID_P == 8
+# if SIZEOF_VOID_P == 8
gnu_classpath_Pointer64 *paddress;
-#else
+# else
gnu_classpath_Pointer32 *paddress;
-#endif
+# endif
STATISTICS(jniinvokation());
/* alocate a gnu.classpath.Pointer{32,64} object */
-#if SIZEOF_VOID_P == 8
+# if SIZEOF_VOID_P == 8
if (!(paddress = (gnu_classpath_Pointer64 *)
builtin_new(class_gnu_classpath_Pointer64)))
-#else
+# else
if (!(paddress = (gnu_classpath_Pointer32 *)
builtin_new(class_gnu_classpath_Pointer32)))
-#endif
+# endif
return NULL;
/* fill gnu.classpath.Pointer{32,64} with address */
/* add local reference and return the value */
return _Jv_JNI_NewLocalRef(env, nbuf);
+#else
+ vm_abort("_Jv_JNI_NewDirectByteBuffer: not implemented in this configuration");
+
+ /* keep compiler happy */
+
+ return NULL;
+#endif
}
void *_Jv_JNI_GetDirectBufferAddress(JNIEnv *env, jobject buf)
{
+#if defined(ENABLE_JAVASE)
java_nio_DirectByteBufferImpl *nbuf;
-#if SIZEOF_VOID_P == 8
+# if SIZEOF_VOID_P == 8
gnu_classpath_Pointer64 *address;
-#else
+# else
gnu_classpath_Pointer32 *address;
-#endif
+# endif
STATISTICS(jniinvokation());
nbuf = (java_nio_DirectByteBufferImpl *) buf;
-#if SIZEOF_VOID_P == 8
+# if SIZEOF_VOID_P == 8
address = (gnu_classpath_Pointer64 *) nbuf->address;
-#else
+# else
address = (gnu_classpath_Pointer32 *) nbuf->address;
-#endif
+# endif
if (address == NULL)
return NULL;
return (void *) address->data;
+#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)
java_nio_Buffer *nbuf;
STATISTICS(jniinvokation());
nbuf = (java_nio_Buffer *) buf;
return (jlong) nbuf->cap;
+#else
+ vm_abort("_Jv_JNI_GetDirectBufferCapacity: not implemented in this configuration");
+
+ /* keep compiler happy */
+
+ return 0;
+#endif
}
if (thread == NULL)
return JNI_ERR;
+ if (!jni_free_localref_table())
+ return JNI_ERR;
+
if (!threads_detach_thread(thread))
return JNI_ERR;
#endif