This is the mail archive of the java-patches@sourceware.cygnus.com mailing list for the Java project.


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

Try to gc when we run out of file handles


There's a memory and file descriptor leak in createTempFile().  This
fixes it, I think.

OK?

Andrew.


2000-06-26  Andrew Haley  <aph@cygnus.com>

	* java/io/natFileDescriptorPosix.cc (open): Run gc when open()
	fails due to too many open files.

	* java/io/File.java (createTempFile): Use new FileDescriptor
	rather than re-opening an old decriptor.

Index: File.java
===================================================================
RCS file: /cvs/cvsfiles/devo/libjava/java/io/File.java,v
retrieving revision 1.11
diff -c -2 -p -r1.11 File.java
*** File.java	2000/03/13 21:03:01	1.11
--- File.java	2000/06/26 14:35:09
*************** public class File implements Serializabl
*** 261,265 ****
  	try
  	  {
! 	    desc.open (l, FileDescriptor.WRITE | FileDescriptor.EXCL);
  	    ret.setPath(l);
  	    return ret;
--- 261,266 ----
  	try
  	  {
! 	    desc = new FileDescriptor 
! 	      (l, FileDescriptor.WRITE | FileDescriptor.EXCL);
  	    ret.setPath(l);
  	    return ret;

Index: natFileDescriptorPosix.cc
===================================================================
RCS file: /cvs/cvsfiles/devo/libjava/java/io/natFileDescriptorPosix.cc,v
retrieving revision 1.15
diff -c -2 -p -r1.15 natFileDescriptorPosix.cc
*** natFileDescriptorPosix.cc	2000/06/02 18:09:01	1.15
--- natFileDescriptorPosix.cc	2000/06/26 14:35:09
*************** details.  */
*** 44,47 ****
--- 44,48 ----
  #include <java/lang/ArrayIndexOutOfBoundsException.h>
  #include <java/lang/NullPointerException.h>
+ #include <java/lang/System.h>
  #include <java/lang/String.h>
  #include <java/lang/Thread.h>
*************** java::io::FileDescriptor::open (jstring 
*** 106,109 ****
--- 107,116 ----
  
    int fd = ::open (buf, flags, mode);
+   if (fd == -1 && errno == EMFILE)
+     {
+       // Because finalize () calls close () we might be able to continue.
+       java::lang::System::gc ();
+       fd = ::open (buf, flags, mode);
+     }
    if (fd == -1)
      {

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