This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
System.gc() to close file descriptors (was RE: status of gcj's boehm collector?)
- From: Andrew Haley <aph at cambridge dot redhat dot com>
- To: "Boehm, Hans" <hans_boehm at hp dot com>
- Cc: java at gcc dot gnu dot org
- Date: Wed, 12 Dec 2001 03:15:14 +0000 (GMT)
- Subject: System.gc() to close file descriptors (was RE: status of gcj's boehm collector?)
- References: <40700B4C02ABD5119F000090278766443BEDFE@hplex1.hpl.hp.com>
Boehm, Hans writes:
> > From: Andrew Haley [mailto:aph@cambridge.redhat.com]
> > Boehm, Hans writes:
> > > Interesting. Unfortunately, I think the standard Java
> > interface isn't quite
> > > sufficient to do that right. I think the logic to do this
> > properly is:
> > >
> > > if (I'm out of file descriptors and need one, but not before) {
> > > for (;;) {
> > > System.gc();
> > > System.runFinalization();
> > > if (the preceding call ran no finalizers || file descriptor is
> > > available) break;
> > > }
> > > }
> > >
> > > The loop is needed because running finalizers may result in
> > > dropping more objects. If finalization dependencies are correctly
> > > enforced (in Java the client code needs to do that), that's even
> > > reasonably likely. I think this mean you really need
> > > runFinalization to return an indication of whether or not it did
> > > anything so that you can avoid a potentially infinite loop here.
> >
> > What I'm wondering is whether this is a real or a theoretical
> > requirement for gcj. So, for our current implementation, is there any
> > chance that calling System.gc() might not call finalizers for files
> > that are garmbge before returing?
I can confirm that this really is broken in the current libgcj.
Here's a test case that I'll commit. I'm working on a fix.
Andrew.
import java.io.*;
public class FileHandleGcTest
{
static void kill () throws FileNotFoundException
{
for (int i = 0; i < 65536; i++)
{
FileInputStream f = new FileInputStream ("/dev/null");
}
}
public static void
main (String argv [])
{
try
{
kill ();
}
catch (FileNotFoundException _)
{
System.err.println (_);
}
}
}