From nobody@FreeBSD.org  Mon Nov 13 15:54:13 2006
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id F306716A4A0
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 13 Nov 2006 15:54:12 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 65AC743E6E
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 13 Nov 2006 15:48:44 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id kADFmLKS094036
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 13 Nov 2006 15:48:21 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id kADFmLwX094035;
	Mon, 13 Nov 2006 15:48:21 GMT
	(envelope-from nobody)
Message-Id: <200611131548.kADFmLwX094035@www.freebsd.org>
Date: Mon, 13 Nov 2006 15:48:21 GMT
From: Kostik Belousov<kostikbel@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: diablo-jdk1.5.0/jdk-1.5.0 java.nio.Selector bug
X-Send-Pr-Version: www-3.0

>Number:         105482
>Category:       java
>Synopsis:       diablo-jdk1.5.0/jdk-1.5.0 java.nio.Selector bug
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    freebsd-java
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Nov 13 16:00:15 GMT 2006
>Closed-Date:    Sat Feb 26 21:14:35 EST 2011
>Last-Modified:  Sat Feb 26 21:14:35 EST 2011
>Originator:     Kostik Belousov
>Release:        RELENG_6
>Organization:
-
>Environment:
FreeBSD deviant.kiev.zoral.com.ua 6.2-PRERELEASE FreeBSD 6.2-PRERELEASE #2: Mon Oct 30 10:37:21 EET 2006     root@deviant.kiev.zoral.com.ua:/usr/obj/usr/src/sys/DEVIANT  i386
>Description:
The following is reproducable on both diablo-jdk-1.5.0.07.01_1 and
jdk-1.5.0p3_6 on RELENG_6/i386.

The key added to the java.nio.Selector initally has only SelectionKey.OP_READ
in the interestOps(). Due to some external events, OP_WRITE was added to the
interestOps() and Selector.wakeup() was called. Socket associated with key is
definitely ready to be written, but the next Selector.select() call will sleep
until some data appears to be ready to be read from the socket.

I expect that Selector.select() would return immediately in this situation,
returning specified key with isWritable() == true.

Below is the trace
(SELECTED is printed when the Selector.select() returns;
R XX W XX show the OP_READ|OP_WRITE registration for the channel;
PROCESS is printed when key is active;
IS WRITABLE is printed when key is active and isWritable returned true).

 [java] SELECTED
     [java] accepted java.nio.channels.SocketChannel[connected local=/127.0.0.1:5090 remote=/127.0.0.1:63157]
     [java] UPDATE REG java.nio.channels.SocketChannel[connected local=/127.0.0.1:5090 remote=/127.0.0.1:63157] 1
     [java] SENDCMD 12342324

     [java] UPDATE REG java.nio.channels.SocketChannel[connected local=/127.0.0.1:5090 remote=/127.0.0.1:63157] 5
     [java] SELECTED
     [java] SELECTED
     [java] PROCESS java.nio.channels.SocketChannel[connected local=/127.0.0.1:5090 remote=/127.0.0.1:63157]5 R true W false
     [java] f
     [java] UPDATE REG java.nio.channels.SocketChannel[connected local=/127.0.0.1:5090 remote=/127.0.0.1:63157] 5
     [java] SELECTED
     [java] PROCESS java.nio.channels.SocketChannel[connected local=/127.0.0.1:5090 remote=/127.0.0.1:63157]5 R false W true
     [java] PROCESS IS WRITABLE java.nio.channels.SocketChannel[connected local=/127.0.0.1:5090 remote=/127.0.0.1:63157]
     [java] UPDATE REG java.nio.channels.SocketChannel[connected local=/127.0.0.1:5090 remote=/127.0.0.1:63157] 1
>How-To-Repeat:

>Fix:

>Release-Note:
>Audit-Trail:

From: Kurt Miller <kurt@intricatesoftware.com>
To: bug-followup@freebsd.org, kostikbel@gmail.com
Cc:  
Subject: Re: java/105482: diablo-jdk1.5.0/jdk-1.5.0 java.nio.Selector bug
Date: Mon, 9 Mar 2009 13:07:13 -0500

 I debugged a similar problem with OpenJDK and found
 the root cause to be the poll() system call over
 writting the complete pollfd struct upon return.
 
 See the following bug report for details:
 
 http://www.freebsd.org/cgi/query-pr.cgi?pr=130924
State-Changed-From-To: open->feedback 
State-Changed-By: rwatson 
State-Changed-When: Thu Mar 12 11:22:06 UTC 2009 
State-Changed-Why:  
Dear Kostik: 

Could you confirm that the poll(2) changes fixes this problem for you?  If 
so, I will go ahead and close this after an MFC of the patch to 7.x. 

Thanks, 


http://www.freebsd.org/cgi/query-pr.cgi?pr=105482 

From: Robert Watson <rwatson@FreeBSD.org>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: java/105482
Date: Thu, 12 Mar 2009 11:50:07 +0000 (GMT)

 This commit may also be of interest to java/105482.
 
 ---------- Forwarded message ----------
 Date: Wed, 11 Mar 2009 22:10:03 GMT
 From: dfilter service <dfilter@FreeBSD.ORG>
 To: rwatson@FreeBSD.org
 Subject: Re: kern/130924: commit references a PR
 
 The following reply was made to PR kern/130924; it has been noted by GNATS.
 
 From: dfilter@FreeBSD.ORG (dfilter service)
 To: bug-followup@FreeBSD.org
 Cc:
 Subject: Re: kern/130924: commit references a PR
 Date: Wed, 11 Mar 2009 22:00:15 +0000 (UTC)
 
   Author: rwatson
   Date: Wed Mar 11 22:00:03 2009
   New Revision: 189708
   URL: http://svn.freebsd.org/changeset/base/189708
 
   Log:
     When writing out updated pollfd records when returning from
     poll(), only copy out the revents field, not the whole pollfd
     structure.  Otherwise, if the events field is updated
     concurrently by another thread, that update may be lost.
 
     This issue apparently causes problems for the JDK on FreeBSD,
     which expects the Linux behavior of not updating all fields
     (somewhat oddly, Solaris does not implement the required
     behavior, but presumably our adaptation of the JDK is based
     on the Linux port?).
 
     MFC after:      2 weeks
     PR:          kern/130924
     Submitted by:   Kurt Miller <kurt @ intricatesoftware.com>
     Discussed with:      kib
 
   Modified:
     head/sys/kern/sys_generic.c
 
State-Changed-From-To: feedback->closed 
State-Changed-By: eadler 
State-Changed-When: Sat Feb 26 21:14:18 EST 2011 
State-Changed-Why:  


http://www.freebsd.org/cgi/query-pr.cgi?pr=105482 
>Unformatted:
