From: michi Date: Tue, 21 Aug 2007 20:34:27 +0000 (+0000) Subject: * src/native/jni.c (_Jv_JNI_DeleteLocalRef): Moved code to localref_del. X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=fbeed59fffd94249fe0e1509820a38c0ef29c599;p=cacao.git * src/native/jni.c (_Jv_JNI_DeleteLocalRef): Moved code to localref_del. * src/native/localref.c (localref_add): Minor code cleanup. (localref_del): Moved from jni.c and adapted to work with handles. * src/native/localref.h (localref_del): Minor signature change. --HG-- branch : exact-gc --- diff --git a/src/native/jni.c b/src/native/jni.c index 048ca6e94..2a938e88b 100644 --- a/src/native/jni.c +++ b/src/native/jni.c @@ -22,7 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - $Id: jni.c 8390 2007-08-21 19:22:16Z michi $ + $Id: jni.c 8391 2007-08-21 20:34:27Z michi $ */ @@ -1271,38 +1271,14 @@ jobject _Jv_JNI_PopLocalFrame(JNIEnv* env, jobject result) void _Jv_JNI_DeleteLocalRef(JNIEnv *env, jobject localRef) { java_handle_t *o; - localref_table *lrt; - s4 i; STATISTICS(jniinvokation()); o = (java_handle_t *) localRef; - /* get local reference table (thread specific) */ - - lrt = LOCALREFTABLE; - - /* go through all local frames */ - - for (; lrt != NULL; lrt = lrt->prev) { - - /* and try to remove the reference */ - - for (i = 0; i < lrt->capacity; i++) { - if (lrt->refs[i] == o) { - lrt->refs[i] = NULL; - lrt->used--; - - return; - } - } - } - - /* this should not happen */ + /* delete the reference */ -/* if (opt_checkjni) */ -/* FatalError(env, "Bad global or local ref passed to JNI"); */ - log_text("JNI-DeleteLocalRef: Local ref passed to JNI not found"); + localref_del(o); } diff --git a/src/native/localref.c b/src/native/localref.c index f86395f65..9b3198726 100644 --- a/src/native/localref.c +++ b/src/native/localref.c @@ -22,7 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - $Id: localref.c 8365 2007-08-20 19:57:08Z michi $ + $Id: localref.c 8391 2007-08-21 20:34:27Z michi $ */ @@ -339,8 +339,6 @@ java_handle_t *localref_add(java_object_t *o) /* insert the reference into the local reference table */ - h = NULL; - for (i = 0; i < lrt->capacity; i++) { if (lrt->refs[i] == NULL) { lrt->refs[i] = o; @@ -352,26 +350,72 @@ java_handle_t *localref_add(java_object_t *o) h = (java_handle_t *) o; #endif - break; +#if 0 + { + int count = 0; + for (lrt = LOCALREFTABLE; lrt != NULL; lrt = lrt->prev) + count += lrt->used; + log_println("added localref %p for %p (total count %d)", h, o, count); + /*localref_dump();*/ + } +#endif + + return h; } } /* this should not happen */ - if (h == NULL) - assert(0); + log_println("localref_add: WARNING: unable to add localref for %p", o); -#if 0 - { - int count = 0; - for (lrt = LOCALREFTABLE; lrt != NULL; lrt = lrt->prev) - count += lrt->used; - log_println("added localref %p for %p (total count %d)", h, o, count); - /*localref_dump();*/ - } + return NULL; +} + + +/* localref_del **************************************************************** + + Deletes an entry from the local reference table. + +*******************************************************************************/ + +void localref_del(java_handle_t *localref) +{ + localref_table *lrt; + java_handle_t *h; + int32_t i; + + /* get local reference table from thread */ + + lrt = LOCALREFTABLE; + + assert(lrt != NULL); + + /* go through all local frames */ + + /* XXX: this is definitely not what the spec wants! */ + /*for (; lrt != NULL; lrt = lrt->prev) {*/ + + /* and try to remove the reference */ + + for (i = 0; i < lrt->capacity; i++) { +#if defined(ENABLE_HANDLES) + h = (java_handle_t *) &(lrt->refs[i]); +#else + h = (java_handle_t *) lrt->refs[i]; #endif - return h; + if (h == localref) { + lrt->refs[i] = NULL; + lrt->used--; + + return; + } + } + /*}*/ + + /* this should not happen */ + + log_println("localref_del: WARNING: unable to find localref %p", localref); } diff --git a/src/native/localref.h b/src/native/localref.h index 85277dc93..0c038ebdb 100644 --- a/src/native/localref.h +++ b/src/native/localref.h @@ -22,7 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - $Id: localref.h 8364 2007-08-20 19:52:00Z michi $ + $Id: localref.h 8391 2007-08-21 20:34:27Z michi $ */ @@ -79,7 +79,7 @@ bool localref_frame_push(int32_t capacity); void localref_frame_pop_all(void); java_handle_t *localref_add(java_object_t *o); -void localref_del(java_handle_t *h); +void localref_del(java_handle_t *localref); #if !defined(NDEBUG) void localref_dump(void);