Bug 115773 - [patch] java.nio channel selectors should use kqueue/kevent instead of poll
Summary: [patch] java.nio channel selectors should use kqueue/kevent instead of poll
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: java (show other bugs)
Version: 6.2-STABLE
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-java (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-08-24 02:10 UTC by Nick Johnson
Modified: 2010-08-07 19:50 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nick Johnson 2007-08-24 02:10:01 UTC
The FreeBSD Java port uses the poll(2) interface to implement java.nio channels.  
For high performance, especially when large numbers of descriptors are involved, 
it would be nice to use kqueue(2) / kevent(2) instead.

Fix: 

I think the cleanest thing may be to create a KEventArrayWrapper.c, KEventArrayWrapper.java,
KEventSelectorProvider.java and KEventSelectorImpl.java to handle the low-level kevent(2)
functions.  The Linux EPoll classes and native code could be examined for some ideas on how
to structure these classes.

Then DatagramChannelImpl.java, ServerSocketChannelImpl.java, SocketChannelImpl.java,
SinkChannelImpl.java, SourceChannelImpl.java and DefaultSelectorProvider.java would
need to be updated to point at the new KEvent* handlers.

The AbstractPoll* stuff could probably be ignored / done away with; it looks like it
was done that way to provide for both DevPoll* and Poll*.  The Linux EPoll classes
do not extend from AbstractPoll*.

An alternative might be to just modify the polling classes to wrap calls to use kevent(2),
but this would be fairly messy and possibly just as much work.

If I have some time I may take a stab at this, but if someone else is interested,
please feel free to jump on it- don't wait on me.
How-To-Repeat: Currently channel selection for java.nio involves these files in the JVM:

j2se/src/share/classes/sun/nio/ch/AbstractPollArrayWrapper.java
j2se/src/solaris/classes/sun/nio/ch/PollArrayWrapper.java
j2se/src/solaris/native/sun/nio/ch/PollArrayWrapper.c

j2se/src/share/classes/sun/nio/ch/AbstractPollSelectorImpl.java
j2se/src/solaris/classes/sun/nio/ch/PollSelectorImpl.java

j2se/src/solaris/classes/sun/nio/ch/DefaultSelectorProvider.java
j2se/src/share/classes/sun/nio/ch/PollSelectorProvider.java

j2se/src/share/classes/sun/nio/ch/DatagramChannelImpl.java
j2se/src/share/classes/sun/nio/ch/ServerSocketChannelImpl.java
j2se/src/share/classes/sun/nio/ch/SocketChannelImpl.java
j2se/src/solaris/classes/sun/nio/ch/SinkChannelImpl.java
j2se/src/solaris/classes/sun/nio/ch/SourceChannelImpl.java


As well as these files used for building:
j2se/make/java/nio/Makefile
j2se/make/java/nio/mapfile-solaris
Comment 1 David Xu freebsd_committer freebsd_triage 2010-08-02 10:20:21 UTC
I have a patch to let nio use kqueue(), I have roughly tested it,
and it works fine.

http://people.freebsd.org/~davidxu/patch/jdk16_nio_kqueue.patch

just cd into /usr/ports/jdk16, and type following commands:

make extract
make patch
cd work
patch < this_patch_file
cd ..
make install

note that the patch does not make kqueue method be default,
you should specify it on comand line like following:

java 
-Djava.nio.channels.spi.SelectorProvider=sun.nio.ch.KqueueSelectorProvider 
<application class>


Regards,
David Xu
Comment 2 dfilter service freebsd_committer freebsd_triage 2010-08-07 19:44:21 UTC
glewis      2010-08-07 18:44:12 UTC

  FreeBSD ports repository

  Modified files:
    java/jdk16           Makefile 
  Added files:
    java/jdk16/files     patch-nio-kqueue 
  Log:
  . Add a new NIO selector that uses kqueue(2) and make it the default.
  
  PR:             115773
  Submitted by:   davidxu@
  
  Revision  Changes    Path
  1.179     +1 -1      ports/java/jdk16/Makefile
  1.1       +699 -0    ports/java/jdk16/files/patch-nio-kqueue (new)
_______________________________________________
cvs-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/cvs-all
To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
Comment 3 Greg Lewis freebsd_committer freebsd_triage 2010-08-07 19:44:42 UTC
State Changed
From-To: open->closed

I've committed David's patch.  Thanks David!