* src/native/jni.c (_Jv_JNI_DeleteLocalRef): Moved code to localref_del.
authormichi <none@none>
Tue, 21 Aug 2007 20:34:27 +0000 (20:34 +0000)
committermichi <none@none>
Tue, 21 Aug 2007 20:34:27 +0000 (20:34 +0000)
* 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

src/native/jni.c
src/native/localref.c
src/native/localref.h

index 048ca6e942d128e165304fe75bdb690c1ef7ced1..2a938e88bab339dac619289217e42596c945426d 100644 (file)
@@ -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);
 }
 
 
index f86395f65b0b2d535a2714a5430214b00a9884bb..9b3198726b878576c595a86acbf76e6bc3314074 100644 (file)
@@ -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);
 }
 
 
index 85277dc93179ddc7d90a035086c1dfe348a21d84..0c038ebdbe2e52c00df13ef5409e948a2f345cfe 100644 (file)
@@ -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);