This is the mail archive of the mauve-patches@sources.redhat.com mailing list for the Mauve project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patches for java.lang.ref.PhantomReference.phantom and WeakReference.weak


Hi,

I propose attached patches.

Background is that a single System.gc does not guarantee that the weakly referenced object is collected (especially on systems with incremental garbage collection). But forcing the VM into an out-of-memory situation
should result in the collection of all available garbage. Since finalization is checked also the Runtime.runFinalization() should be called.


This makes also a nice test if a VM recovers nicely from an out-of-memory situation :-)

Thanks
--ingo
diff -Naur mauve.org/gnu/testlet/java/lang/ref/WeakReference/weakref.java Mauve/gnu/testlet/java/lang/ref/WeakReference/weakref.java
--- mauve.org/gnu/testlet/java/lang/ref/WeakReference/weakref.java	2001-09-27 17:44:09.000000000 +0200
+++ Mauve/gnu/testlet/java/lang/ref/WeakReference/weakref.java	2003-08-13 18:11:09.000000000 +0200
@@ -43,7 +43,14 @@
     Integer twt = new Integer (23);
     WeakReference wr = genRef (q, twt);
 
-    System.gc ();
+    try
+      {
+      long[] suckUpAllMemory = new long[(int)(Runtime.getRuntime().totalMemory()/8)];
+      }
+    catch (OutOfMemoryError e)
+      {
+      }  
+	Runtime.getRuntime().runFinalization();
 
     Reference r = q.poll ();
     harness.check (r, null, "live reference");
@@ -58,8 +65,16 @@
     ReferenceQueue q = new ReferenceQueue ();
 
     WeakReference wr = try1 (q, harness);
-    System.gc ();
-
+	try
+	  {
+		long[] suckUpAllMemory = new long[(int)(Runtime.getRuntime().totalMemory()/8)];
+	  }
+	catch (OutOfMemoryError e)
+	  {
+	  }  
+	Runtime.getRuntime().runFinalization();
+	
+	
     Reference r = null;
     try
       {
diff -Naur mauve.org/gnu/testlet/java/lang/ref/PhantomReference/phantom.java Mauve/gnu/testlet/java/lang/ref/PhantomReference/phantom.java
--- mauve.org/gnu/testlet/java/lang/ref/PhantomReference/phantom.java	2001-09-27 17:44:09.000000000 +0200
+++ Mauve/gnu/testlet/java/lang/ref/PhantomReference/phantom.java	2003-08-13 18:09:04.000000000 +0200
@@ -54,7 +54,14 @@
     phantom twt = new phantom ();
     PhantomReference wr = genRef (q, twt);
 
-    System.gc ();
+    try
+      {
+      long[] suckUpAllMemory = new long[(int)(Runtime.getRuntime().totalMemory()/8)];
+      }
+    catch (OutOfMemoryError e)
+      {
+      }
+	Runtime.getRuntime().runFinalization();
 
     Reference r = q.poll ();
     harness.check (r, null, "live reference");
@@ -69,8 +76,16 @@
     ReferenceQueue q = new ReferenceQueue ();
 
     PhantomReference wr = try1 (q, harness);
-    System.gc ();
-
+    
+    try
+      {
+      long[] suckUpAllMemory = new long[(int)(Runtime.getRuntime().totalMemory()/8)];
+      }
+    catch (OutOfMemoryError e)
+      {
+      }
+	Runtime.getRuntime().runFinalization();
+	
     Reference r = null;
     try
       {

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]