###@###.###:
> We have a test program that has 10 threads that exec 1000 processes
> one at a time, wait for it to terminate then repeat. On linux this
> quickly encounters IOException because the maximum number of open
> files is exceeded. The test program is a bad citizen and doesn't
> explicitly close the process streams.
>
> On JDK 1.4.2, 1.5 and 1.6 the test still passes because eventually the
> finalization of the streams closes the underlying fds.
>
> In Java 7 the fds are never reclaimed and the test program goes into
> an infinite process of throwing IOExceptions.
>
> Looking at 6524062 and the code in FileInputStream and FileDescriptor
> I think I see why. The UNIXProcess class creates FileDescriptor
> objects and passes them to FIS/FOS constructors. The FileDescriptor
> constructor sets the useCount to 1. The FIS/FOS constructor increments
> the useCount to 2. When close() is called during finalization we have
> the following:
>
> int useCount = fd.decrementAndGetUseCount();
> if ((useCount <= 0) || !isRunningFinalize()) {
> close0();
> }
>
> We only decremented the useCount *once* so it is still 1, hence we
> will not call close0() if finalization is active. Hence the fd gets
> leaked.
>
> It seems to me that the FileDescriptor constructor should not be
> initializing the useCount to 1 as the FD is not yet in use.