* src/native/jni.c (jni_free_localref_table): Added.
authormichi <none@none>
Fri, 23 Feb 2007 20:15:31 +0000 (20:15 +0000)
committermichi <none@none>
Fri, 23 Feb 2007 20:15:31 +0000 (20:15 +0000)
* src/native/jni.c [ENABLE_GC_CACAO]: The localref_table is no longer put onto
the heap, but managed explicitly.

--HG--
branch : exact-gc

src/native/jni.c

index b81c1b2c5b456beab58364282bef6ac5a097c9af..036b13e605c755ab2eeddf468160067505f81410 100644 (file)
@@ -22,7 +22,7 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: jni.c 7384 2007-02-21 22:17:16Z twisti $
+   $Id: jni.c 7392 2007-02-23 20:15:31Z michi $
 
 */
 
@@ -227,7 +227,13 @@ bool jni_init_localref_table(void)
 {
        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;
@@ -247,6 +253,31 @@ bool jni_init_localref_table(void)
 }
 
 
+/* 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
@@ -1378,7 +1409,11 @@ jint _Jv_JNI_PushLocalFrame(JNIEnv* env, jint capacity)
        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;
@@ -1416,6 +1451,7 @@ jobject _Jv_JNI_PopLocalFrame(JNIEnv* env, jobject result)
        localref_table *lrt;
        localref_table *plrt;
        s4              localframes;
+       s4              additionalrefs;
 
        STATISTICS(jniinvokation());
 
@@ -1445,6 +1481,18 @@ jobject _Jv_JNI_PopLocalFrame(JNIEnv* env, jobject result)
 
                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;
@@ -5683,6 +5731,9 @@ jint _Jv_JNI_DetachCurrentThread(JavaVM *vm)
        if (thread == NULL)
                return JNI_ERR;
 
+       if (!jni_free_localref_table())
+               return JNI_ERR;
+
        if (!threads_detach_thread(thread))
                return JNI_ERR;
 #endif