From owner-freebsd-java@FreeBSD.ORG Sun Mar 23 19:15:41 2008 Return-Path: Delivered-To: freebsd-java@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E81EA1065683 for ; Sun, 23 Mar 2008 19:15:40 +0000 (UTC) (envelope-from dom@bishnet.net) Received: from carrick.bishnet.net (carrick.bishnet.net [IPv6:2a01:348:132::1]) by mx1.freebsd.org (Postfix) with ESMTP id 9FCAC8FC16 for ; Sun, 23 Mar 2008 19:15:40 +0000 (UTC) (envelope-from dom@bishnet.net) Received: from cpc1-warw1-0-0-cust384.sol2.cable.ntl.com ([86.20.169.129] helo=magellan.dom.bishnet.net ident=mailnull) by carrick.bishnet.net with esmtps (TLSv1:AES256-SHA:256) (Exim 4.66 (FreeBSD)) (envelope-from ) id 1JdVfK-000028-W6 for freebsd-java@freebsd.org; Sun, 23 Mar 2008 19:15:35 +0000 Received: from deimos.dom.bishnet.net ([192.168.3.100] helo=deimos) by magellan.dom.bishnet.net with esmtp (Exim 4.68 (FreeBSD)) (envelope-from ) id 1JdVfK-0007Vf-NT for freebsd-java@freebsd.org; Sun, 23 Mar 2008 19:15:34 +0000 From: "Dominic Bishop" To: Date: Sun, 23 Mar 2008 19:13:33 -0000 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook, Build 11.0.5510 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 Thread-Index: AciNGfzSWHkDdXL1TvGEJXs/nKcMAw== X-Bishnet-MailScanner-Information: Contact postmaster@bishnet.net X-Bishnet-MailScanner-VirusCheck: Found to be clean X-Bishnet-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=0.728, required 5, autolearn=not spam, AWL 0.52, BAYES_50 0.00, FORGED_RCVD_HELO 0.14, SPF_PASS -0.00, TW_DJ 0.08) X-Bishnet-MailScanner-From: dom@bishnet.net Message-Id: <20080323191540.9FCAC8FC16@mx1.freebsd.org> Subject: File descriptor leaks under java 1.6 X-BeenThere: freebsd-java@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting Java to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Mar 2008 19:15:41 -0000 I have an application that makes use of 2 way socket communcations, so uses Socket/ServerSocket, this is all standard IO, no java.nio is involved. When running this under diablo 1.5 everything works fine, watching allocated file descriptors with lsof shows nothing abnormal whatsoever. If I run this under a port build JDK 1.6 then it starts leaking file descriptors originating from TCP, until eventually the available descriptors are exhausted and the application crashes with a 'too many open files' error. I've tried both patchset 3 and 4 of the port, under amd64 and i386 architecture FreeBSD 6.3 and the same problem occurs under all circumstances. The problem file descriptors in the lsof output appear as: java 47065 djb 46u IPv4 0xffffff01354a4000 0t0 TCP *:* (CLOSED) java 47065 djb 47u IPv4 0xffffff006b2875f0 0t0 TCP *:* (CLOSED) java 47065 djb 48u IPv4 0xffffff0001bdcbe0 0t0 TCP *:* (CLOSED) java 47065 djb 49u IPv4 0xffffff015924c000 0t0 TCP *:* (CLOSED) java 47065 djb 50u IPv4 0xffffff01375078e8 0t0 TCP *:* (CLOSED) I ran the application with -Xrunhprof enabled under jdk 1.6 and then used jhat to look at the resulting dump. I managed to determine from this that the FD number (ie 46u) corresponds to the 'fd' field in a java.io.FileDescriptor instance. Using the Object Query Language in jhat I went looking for these file descriptor instances using: 'select f from java.io.FileDescriptor f where f.fd == ##' For numbers which were genuine file descriptors (ie connected sockets etc) this would always find the file descriptor instance and walking through the referenced objects/fields it was clear it had located the correct file descriptor. By that I mean the connected address, or for actual files, the pointed to filename agreed with the lsof output. If however I tried this query looking for file descriptor numbers which lsof was showing in the CLOSED state then it would fail to find them at all, so no FileDescriptor instance in the java heap referenced these file descriptor numbers. To make sure I did a: 'select f.fd from java.io.FileDescriptor f' This listed the 'fd' field value for all instances of java.io.FileDescriptor in the heap, I had numbers for the ones expected (ie actual bound sockets, open files/pipes etc that lsof showed) as well as quite a few set to -1 and a lot set to 0. Presumably these last 2 are either newly created instances or ones awaiting garbage collection. I've basically completely run out of ideas as to where these file descriptors are leaking, and given the working behaviour under diablo 1.5 and the lack of references in the heap dump I'm no longer sure that this is actually a problem in my code. Anyone more familiar with the JVM internals got any suggestions as to where to go next? Regards, Dominic Bishop