public inbox for mauve-discuss@sourceware.org
 help / color / mirror / Atom feed
* PhantomReference
@ 2004-11-26 14:09 Jeroen Frijters
  0 siblings, 0 replies; only message in thread
From: Jeroen Frijters @ 2004-11-26 14:09 UTC (permalink / raw)
  To: Mauve Discuss

[-- Attachment #1: Type: text/plain, Size: 396 bytes --]

Hi,

Like (almost) all GC related tests, the PhantomReference test is
dubious, but I'd to propose the attached changes anyway, which I think
(hope?) will make it more robust on all VMs.

The prints are there to keep the references alive, not really nice to
use print for this, but I couldn't think of any other way that was both
simple and reliable.

Any comments?

Regards,
Jeroen

[-- Attachment #2: phantom.patch --]
[-- Type: application/octet-stream, Size: 1392 bytes --]

Index: gnu/testlet/java/lang/ref/PhantomReference/phantom.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/java/lang/ref/PhantomReference/phantom.java,v
retrieving revision 1.3
diff -u -r1.3 phantom.java
--- gnu/testlet/java/lang/ref/PhantomReference/phantom.java	18 Apr 2004 15:47:59 -0000	1.3
+++ gnu/testlet/java/lang/ref/PhantomReference/phantom.java	26 Nov 2004 14:05:42 -0000
@@ -56,14 +56,17 @@
 
     // Give the runtime some hints that it should really garbage collect.
     System.gc ();
-    Thread.yield ();
+    System.runFinalization();
     System.gc ();
+    System.runFinalization();
 
     Reference r = q.poll ();
     harness.check (r, null, "live reference");
     harness.check (final_count, 0);
 
-    // Must keep the PhantomReference live.
+    // Must keep the phantom object live.
+    System.out.println(twt);
+
     return wr;
   }
 
@@ -73,6 +76,9 @@
 
     PhantomReference wr = try1 (q, harness);
     System.gc ();
+    System.runFinalization();
+    System.gc ();
+    System.runFinalization();
 
     Reference r = null;
     try
@@ -86,5 +92,8 @@
 
     harness.check (r, wr, "unreachable");
     harness.check (final_count, 1, "object finalized");
+
+    // Make sure we're not GCed while running the test.
+    System.out.println(this);
   }
 }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-11-26 14:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-26 14:09 PhantomReference Jeroen Frijters

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).