Re: [cp-patches] RFC: NIO, Non-blocking Scatter/Gather (Again)

2006-05-06 Thread Casey Marshall

On Mar 27, 2006, at 5:42 AM, Michael Barker wrote:


Hi,

Another punt at the Non-blocking IO and Scatter/Gather stuff.  This
patch also adds scatter/gather support to the FileChannelImpl.

ChangeLog:

2006-03-19  Michael Barker [EMAIL PROTECTED]

* vm/reference/gnu/java/nio/VMChannel.java: Added, supports setting
non-blocking and scatter-gather io operations.
* gnu/java/nio/PipeImpl.java: Retrofitted to use VMChannel
* gnu/java/nio/SelectorImpl.java
(register) Added condition for
gnu.java.nio.SocketChannelSelectionKeyImpl
* gnu/java/nio/SocketChannelSelectionKeyImpl.java Added.
* gnu/java/nio/channels/FileChannelImpl.java: Retrofitted to use
VMChannel
* java/nio/FileChannel.java
(read (ByteBuffer)) Changed to call abstract method.
(write (ByteBuffer)) Changed to call abstract method.
* include/gnu_java_nio_VMChannel.h: Added.
* native/jni/java-nio/gnu_java_nio_VMChannel.c: Added.



Hi Michael.

I (finally!) took a look at this patch, and it looks fine to me; any  
bugs with it are worth the risk to have a real implementation of  
scatter/gather IO, in my opinion.


One nit is that gnu_java_nio_VMChannel.c doesn't compile with -Werror  
for me (Darwin/x86, gcc 4.0.1), due to some unused variables and  
missing prototypes. I'll attach a patch that fixes these warnings.


Thanks,

--- native/jni/java-nio/gnu_java_nio_VMChannel.c2006-05-05 
23:15:51.0 -0700
+++ native/jni/java-nio/gnu_java_nio_VMChannel.c.mine   2006-04-18 
14:52:45.0 -0700
@@ -66,6 +66,24 @@
 {
 #endif
 
+enum JCL_buffer_type { DIRECT, ARRAY, UNKNOWN };
+
+struct JCL_buffer
+{
+  enum JCL_buffer_type type;
+  jbyte *ptr;
+  jint offset;
+  jint position;
+  jint limit;
+  jint count;
+};
+
+jmethodID get_method_id(JNIEnv *, jclass, const char *, const char *);
+void JCL_print_buffer(JNIEnv *, struct JCL_buffer *);
+int JCL_init_buffer(JNIEnv *, struct JCL_buffer *, jobject);
+void JCL_release_buffer(JNIEnv *, struct JCL_buffer *, jobject, jint);
+void JCL_cleanup_buffers(JNIEnv *, struct JCL_buffer *, jint, jobjectArray, 
jint, jlong);
+
 static jfieldID address_fid;
 static jmethodID get_position_mid;
 static jmethodID set_position_mid;
@@ -89,20 +107,8 @@
   return mid;
 }
 
-enum JCL_buffer_type { DIRECT, ARRAY, UNKNOWN };
-
-struct JCL_buffer
-{
-  enum JCL_buffer_type type;
-  jbyte *ptr;
-  jint offset;
-  jint position;
-  jint limit;
-  jint count;
-};
-
 void
-JCL_print_buffer(JNIEnv *env, struct JCL_buffer *buf)
+JCL_print_buffer(JNIEnv *env __attribute__((__unused__)), struct JCL_buffer 
*buf)
 {
   fprintf(stdout, Buffer - type: %d, ptr: %d\n, buf-type, (int)buf-ptr);
   fflush(stdout);
@@ -378,8 +384,8 @@
jint length)
 {
   jint i;
-  jboolean is_error = JNI_FALSE;
-  char *error_msg;
+/*   jboolean is_error = JNI_FALSE; */
+/*   char *error_msg; */
   struct iovec buffers[JCL_IOV_MAX];
   struct JCL_buffer bi_list[JCL_IOV_MAX];
   ssize_t result;
@@ -454,8 +460,8 @@
jint length)
 {
   int i;
-  jboolean is_error = JNI_FALSE;
-  char *error_msg;
+/*   jboolean is_error = JNI_FALSE; */
+/*   char *error_msg; */
   struct iovec buffers[JCL_IOV_MAX];
   struct JCL_buffer bi_list[JCL_IOV_MAX];
   ssize_t result;


PGP.sig
Description: This is a digitally signed message part


Re: [cp-patches] RFC: NIO, Non-blocking Scatter/Gather (Again)

2006-05-06 Thread Casey Marshall

On May 6, 2006, at 5:30 AM, Michael Barker wrote:


One nit is that gnu_java_nio_VMChannel.c doesn't compile with -Werror
for me (Darwin/x86, gcc 4.0.1), due to some unused variables and
missing prototypes. I'll attach a patch that fixes these warnings.


What's the next step?  I don't have CVS access.  Should I reissue a
patch with your changes or would someone be able to apply both patches
to CVS.



I'll commit this, after I make sure that your paperwork is taken care  
of.


Thanks.


PGP.sig
Description: This is a digitally signed message part


Re: [cp-patches] RFC: NIO, Non-blocking Scatter/Gather (Again)

2006-04-06 Thread Mark Wielaard
Hi Michael,

On Mon, 2006-03-27 at 14:42 +0100, Michael Barker wrote:
 Another punt at the Non-blocking IO and Scatter/Gather stuff.  This
 patch also adds scatter/gather support to the FileChannelImpl.

 ChangeLog:
 
 2006-03-19  Michael Barker [EMAIL PROTECTED]
   
   * vm/reference/gnu/java/nio/VMChannel.java: Added, supports setting 
   non-blocking and scatter-gather io operations.
   * gnu/java/nio/PipeImpl.java: Retrofitted to use VMChannel
   * gnu/java/nio/SelectorImpl.java
   (register) Added condition for
 gnu.java.nio.SocketChannelSelectionKeyImpl
   * gnu/java/nio/SocketChannelSelectionKeyImpl.java Added.
   * gnu/java/nio/channels/FileChannelImpl.java: Retrofitted to use
 VMChannel
   * java/nio/FileChannel.java
   (read (ByteBuffer)) Changed to call abstract method.
   (write (ByteBuffer)) Changed to call abstract method.
   * include/gnu_java_nio_VMChannel.h: Added.
   * native/jni/java-nio/gnu_java_nio_VMChannel.c: Added.

My apologies for forgetting this patch. I'll try to look at it asap.
Clearly we don't have much other hackers working on nio at this time
(even though we have some bugs in this area). If someone else has time
and can go over this patch that would be appreciated (it has been a
while since I last looked at nio). Michael also already has paperwork on
file with the FSF. So if this is good we can immediately use it.

Michael, do you have some test programs that use this functionality
around?

Thanks,

Mark


signature.asc
Description: This is a digitally signed message part


Re: [cp-patches] RFC: NIO, Non-blocking Scatter/Gather (Again)

2006-04-06 Thread Michael Barker
On Thu, 2006-04-06 at 09:26 +0200, Mark Wielaard wrote:
 My apologies for forgetting this patch. I'll try to look at it asap.

No worries.

 Michael, do you have some test programs that use this functionality
 around?

I have some mauve tests that covers most of it.  There are a few edge
cases that I might not of covered yet.

Mike.






[cp-patches] RFC: NIO, Non-blocking Scatter/Gather (Again)

2006-03-27 Thread Michael Barker
Hi,

Another punt at the Non-blocking IO and Scatter/Gather stuff.  This
patch also adds scatter/gather support to the FileChannelImpl.

ChangeLog:

2006-03-19  Michael Barker [EMAIL PROTECTED]

* vm/reference/gnu/java/nio/VMChannel.java: Added, supports setting 
non-blocking and scatter-gather io operations.
* gnu/java/nio/PipeImpl.java: Retrofitted to use VMChannel
* gnu/java/nio/SelectorImpl.java
(register) Added condition for
gnu.java.nio.SocketChannelSelectionKeyImpl
* gnu/java/nio/SocketChannelSelectionKeyImpl.java Added.
* gnu/java/nio/channels/FileChannelImpl.java: Retrofitted to use
VMChannel
* java/nio/FileChannel.java
(read (ByteBuffer)) Changed to call abstract method.
(write (ByteBuffer)) Changed to call abstract method.
* include/gnu_java_nio_VMChannel.h: Added.
* native/jni/java-nio/gnu_java_nio_VMChannel.c: Added.

Regards,
Michael Barker
Index: ChangeLog
===
RCS file: /cvsroot/classpath/classpath/ChangeLog,v
retrieving revision 1.6923
diff -u -r1.6923 ChangeLog
--- ChangeLog	27 Mar 2006 20:05:15 -	1.6923
+++ ChangeLog	27 Mar 2006 20:15:10 -
@@ -1360,6 +1360,21 @@
 	* vm/reference/gnu/classpath/Unsafe.java:
 	New class to handle low-level facilities for concurrency.
 
+2006-03-19  Michael Barker [EMAIL PROTECTED]
+	
+	* vm/reference/gnu/java/nio/VMChannel.java: Added, supports setting 
+	non-blocking and scatter-gather io operations.
+	* gnu/java/nio/PipeImpl.java: Retrofitted to use VMChannel
+	* gnu/java/nio/SelectorImpl.java
+	(register) Added condition for gnu.java.nio.SocketChannelSelectionKeyImpl
+	* gnu/java/nio/SocketChannelSelectionKeyImpl.java Added.
+	* gnu/java/nio/channels/FileChannelImpl.java: Retrofitted to use VMChannel
+	* java/nio/FileChannel.java
+	(read (ByteBuffer)) Changed to call abstract method.
+	(write (ByteBuffer)) Changed to call abstract method.
+	* include/gnu_java_nio_VMChannel.h: Added.
+	* native/jni/java-nio/gnu_java_nio_VMChannel.c: Added.
+
 2006-03-19  Mark Wielaard  [EMAIL PROTECTED]
 
 	* include/Makefile.am: Rename PlainDatagramSocketImpl to
Index: gnu/java/nio/PipeImpl.java
===
RCS file: /cvsroot/classpath/classpath/gnu/java/nio/PipeImpl.java,v
retrieving revision 1.11
diff -u -r1.11 PipeImpl.java
--- gnu/java/nio/PipeImpl.java	2 Jul 2005 20:32:13 -	1.11
+++ gnu/java/nio/PipeImpl.java	27 Mar 2006 20:15:12 -
@@ -37,6 +37,7 @@
 
 package gnu.java.nio;
 
+
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.nio.channels.Pipe;
@@ -47,12 +48,14 @@
   public static final class SourceChannelImpl extends Pipe.SourceChannel
   {
 private int native_fd;
+private VMChannel vmch;
 
 public SourceChannelImpl (SelectorProvider selectorProvider,
   int native_fd)
 {
   super (selectorProvider);
   this.native_fd = native_fd;
+  vmch = VMChannel.getVMChannel(this);
 }
 
 protected final void implCloseSelectableChannel()
@@ -64,19 +67,19 @@
 protected void implConfigureBlocking (boolean blocking)
   throws IOException
 {
-  throw new Error (Not implemented);
+  vmch.setBlocking(blocking);
 }
 
 public final int read (ByteBuffer src)
   throws IOException
 {
-  throw new Error (Not implemented);
+  return vmch.read(src);
 }
 
 public final long read (ByteBuffer[] srcs)
   throws IOException
 {
-  return read (srcs, 0, srcs.length);
+  return vmch.readScattering(srcs, 0, srcs.length);
 }
 
 public final synchronized long read (ByteBuffer[] srcs, int offset,
@@ -89,13 +92,7 @@
 	  || len  srcs.length - offset)
 	throw new IndexOutOfBoundsException();
 
-  long bytesRead = 0;
-  
-  for (int index = 0; index  len; index++)
-	bytesRead += read (srcs [offset + index]);
-
-  return bytesRead;
-
+  return vmch.readScattering(srcs, offset, len);
 }
 
 public final int getNativeFD()
@@ -107,12 +104,14 @@
   public static final class SinkChannelImpl extends Pipe.SinkChannel
   {
 private int native_fd;
+private VMChannel vmch;
 
 public SinkChannelImpl (SelectorProvider selectorProvider,
 int native_fd)
 {
   super (selectorProvider);
   this.native_fd = native_fd;
+  vmch = VMChannel.getVMChannel(this);
 }
 
 protected final void implCloseSelectableChannel()
@@ -124,19 +123,19 @@
 protected final void implConfigureBlocking (boolean blocking)
   throws IOException
 {
-  throw new Error (Not implemented);
+  vmch.setBlocking(blocking);
 }
 
 public final int write (ByteBuffer dst)
   throws IOException
 {
-  throw new Error (Not implemented);
+  return vmch.write(dst);
 }
 
 public final long write (ByteBuffer[] srcs)