Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: jni.c 8388 2007-08-21 16:24:12Z michi $
+ $Id: jni.c 8390 2007-08-21 19:22:16Z michi $
*/
const jbyte *buf, jsize bufLen)
{
#if defined(ENABLE_JAVASE)
- utf *u;
- classloader *cl;
- classinfo *c;
+ utf *u;
+ classloader *cl;
+ classinfo *c;
+ java_lang_Class *co;
TRACEJNICALLS("_Jv_JNI_DefineClass(env=%p, name=%s, loader=%p, buf=%p, bufLen=%d", env, name, loader, buf, bufLen);
c = class_define(u, cl, bufLen, (const uint8_t *) buf);
- return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
+ co = LLNI_classinfo_wrap(c);
+
+ return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) co);
#else
vm_abort("_Jv_JNI_DefineClass: not implemented in this configuration");
jclass _Jv_JNI_FindClass(JNIEnv *env, const char *name)
{
#if defined(ENABLE_JAVASE)
- utf *u;
- classinfo *cc;
- classinfo *c;
+ utf *u;
+ classinfo *cc;
+ classinfo *c;
+ java_lang_Class *co;
STATISTICS(jniinvokation());
if (!link_class(c))
return NULL;
- return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
+ co = LLNI_classinfo_wrap(c);
+
+ return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) co);
#else
vm_abort("_Jv_JNI_FindClass: not implemented in this configuration");
jclass _Jv_JNI_GetSuperclass(JNIEnv *env, jclass sub)
{
- classinfo *c;
- classinfo *super;
+ classinfo *c;
+ classinfo *super;
+ java_lang_Class *co;
TRACEJNICALLS("_Jv_JNI_GetSuperclass(env=%p, sub=%p)", env, sub);
super = class_get_superclass(c);
- return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) super);
+ co = LLNI_classinfo_wrap(super);
+
+ return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) co);
}
jboolean _Jv_JNI_IsSameObject(JNIEnv *env, jobject ref1, jobject ref2)
{
+ java_handle_t *o1;
+ java_handle_t *o2;
+ jboolean result;
+
STATISTICS(jniinvokation());
- if (ref1 == ref2)
- return JNI_TRUE;
+ o1 = (java_handle_t *) ref1;
+ o2 = (java_handle_t *) ref2;
+
+ LLNI_CRITICAL_START;
+
+ if (LLNI_UNWRAP(o1) == LLNI_UNWRAP(o2))
+ result = JNI_TRUE;
else
- return JNI_FALSE;
+ result = JNI_FALSE;
+
+ LLNI_CRITICAL_END;
+
+ return result;
}
jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref)
{
+ java_handle_t *o;
java_handle_t *localref;
STATISTICS(jniinvokation());
if (ref == NULL)
return NULL;
+ o = (java_handle_t *) ref;
+
/* insert the reference */
- localref = localref_add(ref);
+ localref = localref_add(LLNI_DIRECT(o));
return localref;
}
jclass _Jv_JNI_GetObjectClass(JNIEnv *env, jobject obj)
{
- java_handle_t *o;
- classinfo *c;
+ java_handle_t *o;
+ classinfo *c;
+ java_lang_Class *co;
STATISTICS(jniinvokation());
LLNI_class_get(o, c);
- return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
+ co = LLNI_classinfo_wrap(c);
+
+ return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) co);
}
STATISTICS(jniinvokation());
-#warning this needs to be fixed
+ vm_abort("this needs to be fixed");
o = GET_FIELD(obj, java_handle_t*, fieldID);
return _Jv_JNI_NewLocalRef(env, (jobject) o);
{
STATISTICS(jniinvokation());
-#warning this needs to be fixed
+ vm_abort("this needs to be fixed");
SET_FIELD(obj, java_handle_t*, fieldID, value);
}
/* check if the class of value is a subclass of the element class
of the array */
- if (!builtin_canstore(oa, o))
+ if (!builtin_canstore(LLNI_DIRECT(oa), LLNI_DIRECT(o)))
return;
LLNI_objectarray_element_set(oa, index, o);
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 */
+#if defined(ENABLE_GC_CACAO)
+ key = heap_get_hashcode(LLNI_DIRECT(o)) >> 4;
+#else
+ key = ((u4) (ptrint) o) >> 4; /* align to 16-byte boundaries */
+#endif
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 */
/* global ref not found, create a new one */
- gre = NEW(hashtable_global_ref_entry);
+ if (gre == NULL) {
+ gre = NEW(hashtable_global_ref_entry);
#if defined(ENABLE_GC_CACAO)
- /* register global ref with the GC */
+ /* register global ref with the GC */
- gc_reference_register(&(gre->o), GC_REFTYPE_JNI_GLOBALREF);
+ gc_reference_register(&(gre->o), GC_REFTYPE_JNI_GLOBALREF);
#endif
- gre->o = o;
- gre->refs = 1;
+ gre->o = LLNI_DIRECT(o);
+ gre->refs = 1;
- /* 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++;
+ LLNI_CRITICAL_END;
LOCK_MONITOR_EXIT(hashtable_global_ref->header);
+#if defined(ENABLE_HANDLES)
+ return gre;
+#else
return obj;
+#endif
}
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 */
+#if defined(ENABLE_GC_CACAO)
+ key = heap_get_hashcode(LLNI_DIRECT(o)) >> 4;
+#else
+ key = ((u4) (ptrint) o) >> 4; /* align to 16-byte boundaries */
+#endif
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--;
FREE(gre, hashtable_global_ref_entry);
}
+ LLNI_CRITICAL_END;
+
LOCK_MONITOR_EXIT(hashtable_global_ref->header);
return;
log_println("JNI-DeleteGlobalRef: global reference not found");
+ LLNI_CRITICAL_END;
+
LOCK_MONITOR_EXIT(hashtable_global_ref->header);
}