You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/04/16 14:29:37 UTC

svn commit: r765607 - in /commons/sandbox/runtime/trunk/src: main/native/include/acr_pointer.h main/native/shared/pointer.c test/org/apache/commons/runtime/TestPrivate.java

Author: mturk
Date: Thu Apr 16 12:29:37 2009
New Revision: 765607

URL: http://svn.apache.org/viewvc?rev=765607&view=rev
Log:
Test Pointer garbage collection

Modified:
    commons/sandbox/runtime/trunk/src/main/native/include/acr_pointer.h
    commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c
    commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_pointer.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_pointer.h?rev=765607&r1=765606&r2=765607&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_pointer.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_pointer.h Thu Apr 16 12:29:37 2009
@@ -33,6 +33,8 @@
 
 /**
  * Pointer callback function prototype.
+ * The cleanup function must chech for data validity.
+ * Consecutive invocations will always contain NULL data.
  */
 typedef int (acr_pointer_callback_fn_t)(void *);
 

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c?rev=765607&r1=765606&r2=765607&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c Thu Apr 16 12:29:37 2009
@@ -108,11 +108,13 @@
     jlong h = GET_IFIELD_J(0000, _O);
     jlong c = GET_IFIELD_J(0001, _O);
 
+    if (h) {
+        SET_IFIELD_J(0000, _O, 0);
+    }
     cleanup = (acr_pointer_callback_fn_t *)((acr_ptr_t)c);
     if (cleanup) {
         (*cleanup)((void *)((acr_ptr_t)h));
     }
-    SET_IFIELD_J(0000, _O, 0);
 }
 
 #else
@@ -123,11 +125,13 @@
     jint h = GET_IFIELD_I(0000, _O);
     jint c = GET_IFIELD_I(0001, _O);
 
+    if (h) {
+        SET_IFIELD_I(0000, _O, 0);
+    }
     cleanup = (acr_pointer_callback_fn_t *)((acr_ptr_t)c);
     if (cleanup) {
         (*cleanup)((void *)((acr_ptr_t)h));
     }
-    SET_IFIELD_I(0000, _O, 0);
 }
 
 #endif

Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java?rev=765607&r1=765606&r2=765607&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java Thu Apr 16 12:29:37 2009
@@ -224,7 +224,6 @@
     public void testClassLoad()
         throws Exception
     {
-        // Shuold not be called as last
         int i = test016(0);
         assertEquals("Value", 0, i);
     }
@@ -232,12 +231,26 @@
     public void testPointerCb()
         throws Throwable
     {
-        // Shuold not be called as last
         Pointer p = test017(0xcafebabe);
         assertNotNull("Pointer",p);
         p.testCleanup();
-        // Second invocation should display (nil)
-        p.testCleanup();
+        p = null;
+        System.gc();
+        // This should be enough for a gc
+        // from Pointer.finalize()
+        Thread.sleep(1000);
+    }
+
+    public void testPointerGc()
+        throws Throwable
+    {
+        Pointer p = test017(0xdeadbeef);
+        assertNotNull("Pointer", p);
+        p = null;
+        System.gc();
+        // This should be enough for a first invocation
+        // from Pointer.finalize()
+        Thread.sleep(1000);
     }
 
 }