harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r936843 - in /harmony/enhanced/java/trunk/classlib/modules: luni/src/main/java/org/apache/harmony/luni/platform/ luni/src/main/native/luni/shared/ luni/src/main/native/luni/unix/ luni/src/main/native/luni/windows/ nio/src/main/java/common/o...
Date Thu, 22 Apr 2010 13:48:39 GMT
Author: hindessm
Date: Thu Apr 22 13:48:38 2010
New Revision: 936843

URL: http://svn.apache.org/viewvc?rev=936843&view=rev
Log:
Reconcile SocketChannelImpl.write and FileChannelImpl.writev differences:

 * short cut socket writev if nothing is left to write (or buffer
   array is 0 length).

 * Use a long count in shortcut calculation in both socket and file
   writev versions to avoid the unlikely two buffer lengths summing to
   int 0 case.

 * socket writevImpl return a long since the syscall returns long on
   unix (int on windows so don't expect large buffer cases to work
   there).

 * add buffer.hasArray == true case from file writev to socket writev.

 * rename some variables

 * Initialise noffset properly in Linux natives to fix one error case.

 * Remove unnecessary initialisation of toBeReleasedBuffers in windows natives.

 * use ssize_t for linux syscall return and cast to jlong on return.


Modified:
    harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java
    harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java
    harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/shared/OSFileSystem.h
    harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/shared/OSNetworkSystem.h
    harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/OSFileSystemLinux32.c
    harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c
    harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/windows/OSFileSystemWin32.c
    harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/windows/OSNetworkSystemWin32.c
    harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/FileChannelImpl.java
    harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SocketChannelImpl.java

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java?rev=936843&r1=936842&r2=936843&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java
Thu Apr 22 13:48:38 2010
@@ -62,8 +62,8 @@ public interface INetworkSystem {
     public int writeDirect(FileDescriptor fd, long address, int count)
             throws IOException;
 
-    public int writev(FileDescriptor fd, Object[] buffers, int[] offsets,
-            int[] counts, int length) throws IOException;
+    public long writev(FileDescriptor fd, Object[] buffers, int[] offsets,
+            int[] lengths, int length) throws IOException;
 
     public void setNonBlocking(FileDescriptor aFD, boolean block)
             throws IOException;

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java?rev=936843&r1=936842&r2=936843&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java
Thu Apr 22 13:48:38 2010
@@ -548,6 +548,6 @@ final class OSNetworkSystem implements I
      * @throws IOException
      *             if there is an underlying socket problem
      */
-    public native int writev(FileDescriptor fd, Object[] buffers,
-            int[] offsets, int[] counts, int length) throws IOException;
+    public native long writev(FileDescriptor fd, Object[] buffers,
+            int[] offsets, int[] lengths, int length) throws IOException;
 }

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/shared/OSFileSystem.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/shared/OSFileSystem.h?rev=936843&r1=936842&r2=936843&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/shared/OSFileSystem.h
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/shared/OSFileSystem.h
Thu Apr 22 13:48:38 2010
@@ -100,10 +100,10 @@ JNIEXPORT jlong JNICALL Java_org_apache_
 
 /*
  * Class:     org_apache_harmony_luni_platform_OSFileSystem
- * Method:    writevImpl
- * Signature: (J[J[I[II)J
+ * Method:    writev
+ * Signature: (J[Ljava/lang/Object;[I[II)J
  */
-JNIEXPORT jlong JNICALL Java_org_apache_harmony_luni_platform_OSFileSystem_writevImpl
+JNIEXPORT jlong JNICALL Java_org_apache_harmony_luni_platform_OSFileSystem_writev
   (JNIEnv *, jobject, jlong, jlongArray, jintArray, jintArray, jint);
 
 /*

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/shared/OSNetworkSystem.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/shared/OSNetworkSystem.h?rev=936843&r1=936842&r2=936843&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/shared/OSNetworkSystem.h
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/shared/OSNetworkSystem.h
Thu Apr 22 13:48:38 2010
@@ -469,9 +469,9 @@ JNIEXPORT jint JNICALL Java_org_apache_h
 /*
  * Class:     org_apache_harmony_luni_platform_OSNetworkSystem
  * Method:    writev
- * Signature: (Ljava/io/FileDescriptor;[Ljava/lang/Object;[I[II)I
+ * Signature: (Ljava/io/FileDescriptor;[Ljava/lang/Object;[I[II)J
  */
-JNIEXPORT jint JNICALL Java_org_apache_harmony_luni_platform_OSNetworkSystem_writev
+JNIEXPORT jlong JNICALL Java_org_apache_harmony_luni_platform_OSNetworkSystem_writev
   (JNIEnv *, jobject, jobject, jobjectArray, jintArray, jintArray, jint);
 
 #ifdef __cplusplus

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/OSFileSystemLinux32.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/OSFileSystemLinux32.c?rev=936843&r1=936842&r2=936843&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/OSFileSystemLinux32.c
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/OSFileSystemLinux32.c
Thu Apr 22 13:48:38 2010
@@ -193,7 +193,7 @@ JNIEXPORT jlong JNICALL Java_org_apache_
 /*
  * Class:     org_apache_harmony_luni_platform_OSFileSystem
  * Method:    writev
- * Signature: (J[J[I[I)J
+ * Signature: (J[Ljava/lang/Object;[I[II)J
  */
 JNIEXPORT jlong JNICALL
 Java_org_apache_harmony_luni_platform_OSFileSystem_writev
@@ -201,9 +201,9 @@ Java_org_apache_harmony_luni_platform_OS
   PORT_ACCESS_FROM_ENV (env);
   jobject buffer;
   jobject* toBeReleasedBuffers;
-  jint *noffset;
+  jint *noffset = NULL;
   jboolean isDirectBuffer = JNI_FALSE;
-  jint result = 0;
+  ssize_t result = 0;
   jclass byteBufferClass;
   struct iovec* vect;
   int i;
@@ -211,7 +211,7 @@ Java_org_apache_harmony_luni_platform_OS
   vect = (struct iovec*) hymem_allocate_memory(sizeof(struct iovec) * length);
   if (vect == NULL) {
     throwNewOutOfMemoryError(env, "");
-    return 0;
+    return (jlong)0;
   }
 
   toBeReleasedBuffers =
@@ -286,7 +286,7 @@ Java_org_apache_harmony_luni_platform_OS
   hymem_free_memory(toBeReleasedBuffers);
   hymem_free_memory(vect);
 
-  return (jint) result;
+  return (jlong) result;
 }
 
 /*

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c?rev=936843&r1=936842&r2=936843&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c
Thu Apr 22 13:48:38 2010
@@ -727,7 +727,7 @@ pollSelectRead (JNIEnv * env, jobject fi
   return result;
 }
 
-JNIEXPORT jint JNICALL
+JNIEXPORT jlong JNICALL
 Java_org_apache_harmony_luni_platform_OSNetworkSystem_writev
 (JNIEnv *env, jobject thiz, jobject fd, jobjectArray buffers, jintArray offset, jintArray
counts, jint length) {
 
@@ -735,9 +735,9 @@ Java_org_apache_harmony_luni_platform_OS
 
   jobject buffer;
   jobject* toBeReleasedBuffers;
-  jint *noffset;
+  jint *noffset = NULL;
   jboolean isDirectBuffer = JNI_FALSE;
-  jint result = 0;
+  ssize_t result = 0;
   jclass byteBufferClass;
   struct iovec* vect;
   int i;
@@ -746,13 +746,13 @@ Java_org_apache_harmony_luni_platform_OS
 
   if (!hysock_socketIsValid(socketP)) {
     throwJavaNetSocketException(env, HYPORT_ERROR_SOCKET_BADSOCKET);
-    return (jint) 0;
+    return (jlong)0;
   }
 
   vect = (struct iovec*) hymem_allocate_memory(sizeof(struct iovec) * length);
   if (vect == NULL) {
     throwNewOutOfMemoryError(env, "");
-    return 0;
+    return (jlong)0;
   }
 
   toBeReleasedBuffers =
@@ -799,7 +799,6 @@ Java_org_apache_harmony_luni_platform_OS
     (*env)->ReleasePrimitiveArrayCritical(env, counts, cts, JNI_ABORT);
   }
 
-
   result = writev(SOCKET_CAST (socketP), vect, length);
 
   if (0 > result) {
@@ -829,5 +828,5 @@ Java_org_apache_harmony_luni_platform_OS
   hymem_free_memory(toBeReleasedBuffers);
   hymem_free_memory(vect);
 
-  return (jint) result;
+  return (jlong)result;
 }

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/windows/OSFileSystemWin32.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/windows/OSFileSystemWin32.c?rev=936843&r1=936842&r2=936843&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/windows/OSFileSystemWin32.c
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/windows/OSFileSystemWin32.c
Thu Apr 22 13:48:38 2010
@@ -171,8 +171,8 @@ JNIEXPORT jlong JNICALL Java_org_apache_
 
 /*
  * Class:     org_apache_harmony_luni_platform_OSFileSystem
- * Method:    writevImpl
- * Signature: (J[J[I[I)J
+ * Method:    writev
+ * Signature: (J[Ljava/lang/Object;[I[II)J
  */
 JNIEXPORT jlong JNICALL
 Java_org_apache_harmony_luni_platform_OSFileSystem_writev

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/windows/OSNetworkSystemWin32.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/windows/OSNetworkSystemWin32.c?rev=936843&r1=936842&r2=936843&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/windows/OSNetworkSystemWin32.c
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/native/luni/windows/OSNetworkSystemWin32.c
Thu Apr 22 13:48:38 2010
@@ -435,17 +435,17 @@ pollSelectRead (JNIEnv * env, jobject fi
   return result;
 }
 
-JNIEXPORT jint JNICALL
+JNIEXPORT jlong JNICALL
 Java_org_apache_harmony_luni_platform_OSNetworkSystem_writev
   (JNIEnv *env, jobject thiz, jobject fd, jobjectArray buffers, jintArray offsets, jintArray
counts, jint length) {
 
   PORT_ACCESS_FROM_ENV(env);
 
   jobject buffer;
-  jobject* toBeReleasedBuffers = NULL;
+  jobject* toBeReleasedBuffers;
   jint *noffset = NULL;
   jboolean isDirectBuffer = JNI_FALSE;
-  jint result = 0;
+  jlong result = 0;
   LPWSABUF vect;
   int i;
   jint sentBytes;

Modified: harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/FileChannelImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/FileChannelImpl.java?rev=936843&r1=936842&r2=936843&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/FileChannelImpl.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/FileChannelImpl.java
Thu Apr 22 13:48:38 2010
@@ -564,15 +564,15 @@ public abstract class FileChannelImpl ex
         return bytesWritten;
     }
 
-    public long write(ByteBuffer[] buffers, int offset, int length)
+    public long write(ByteBuffer[] sources, int offset, int length)
             throws IOException {
-        if (offset < 0 || length < 0 || (offset + length) > buffers.length) {
+        if (offset < 0 || length < 0 || (offset + length) > sources.length) {
             throw new IndexOutOfBoundsException();
         }
         openCheck();
-        int count = 0;
+        long count = 0;
         for (int i = offset; i < offset + length; i++) {
-            count += buffers[i].remaining();
+            count += sources[i].remaining();
         }
         if (0 == count) {
             return 0;
@@ -581,11 +581,10 @@ public abstract class FileChannelImpl ex
         int[] offsets = new int[length];
         int[] lengths = new int[length];
         for (int i = 0; i < length; i++) {
-            ByteBuffer buffer = buffers[i + offset];
+            ByteBuffer buffer = sources[i + offset];
             if (!buffer.isDirect()) {
                 if (buffer.hasArray()) {
                     src[i] = buffer.array();
-                    lengths[i] = buffer.remaining();
                     offsets[i] = buffer.position();
                 } else {
                     ByteBuffer directBuffer = ByteBuffer.allocateDirect(buffer
@@ -619,13 +618,13 @@ public abstract class FileChannelImpl ex
 
         long bytesRemaining = bytesWritten;
         for (int i = offset; i < length + offset; i++) {
-            if (bytesRemaining > buffers[i].remaining()) {
-                int pos = buffers[i].limit();
-                buffers[i].position(pos);
-                bytesRemaining -= buffers[i].remaining();
+            if (bytesRemaining > sources[i].remaining()) {
+                int pos = sources[i].limit();
+                sources[i].position(pos);
+                bytesRemaining -= sources[i].remaining();
             } else {
-                int pos = buffers[i].position() + (int) bytesRemaining;
-                buffers[i].position(pos);
+                int pos = sources[i].position() + (int) bytesRemaining;
+                sources[i].position(pos);
                 break;
             }
         }

Modified: harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SocketChannelImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SocketChannelImpl.java?rev=936843&r1=936842&r2=936843&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SocketChannelImpl.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SocketChannelImpl.java
Thu Apr 22 13:48:38 2010
@@ -491,63 +491,67 @@ class SocketChannelImpl extends SocketCh
         }
 
         checkOpenConnected();
+        long count = 0;
+        for (int i = offset; i < offset + length; i++) {
+            count += sources[i].remaining();
+        }
+        if (0 == count) {
+            return 0;
+        }
 
         Object[] src = new Object[length];
         int[] offsets = new int[length];
-        int[] counts = new int[length];
-        for (int i = 0; i < length; ++i) {
+        int[] lengths = new int[length];
+        for (int i = 0; i < length; i++) {
             ByteBuffer buffer = sources[i + offset];
             if (!buffer.isDirect()) {
                 if (buffer.hasArray()) {
                     src[i] = buffer.array();
-                    counts[i] = buffer.remaining();
                     offsets[i] = buffer.position();
                 } else {
-                    ByteBuffer db = ByteBuffer.allocateDirect(buffer.remaining());
+                    ByteBuffer directBuffer = ByteBuffer.allocateDirect(buffer.remaining());
                     int oldPosition = buffer.position();
-                    db.put(buffer);
+                    directBuffer.put(buffer);
                     buffer.position(oldPosition);
-                    db.flip();
-                    src[i] = db;
-                    counts[i] = buffer.remaining();
+                    directBuffer.flip();
+                    src[i] = directBuffer;
                     offsets[i] = 0;
                 }
             } else {
                 src[i] = buffer;
-                counts[i] = buffer.remaining();
                 offsets[i] = buffer.position();
             }
+            lengths[i] = buffer.remaining();
         }
 
-        if (length == 0) {
-            return 0;
-        }
-
-        int result = writevImpl(src, offsets, counts);
-        int val = offset;
-        int written = result;
-        while (result > 0) {
-            ByteBuffer source = sources[val];
-            int gap = Math.min(result, source.remaining());
-            source.position(source.position() + gap);
-            val++;
-            result -= gap;
+        long bytesWritten = writevImpl(src, offsets, lengths);
+        long bytesRemaining = bytesWritten;
+        for (int i = offset; i < length + offset; i++) {
+            if (bytesRemaining > sources[i].remaining()) {
+                int pos = sources[i].limit();
+                sources[i].position(pos);
+                bytesRemaining -= sources[i].remaining();
+            } else {
+                int pos = sources[i].position() + (int) bytesRemaining;
+                sources[i].position(pos);
+                break;
+            }
         }
-        return written;
+        return bytesWritten;
     }
 
     /*
      * Write the source. return the count of bytes written.
      */
-    private int writevImpl(Object[] sources, int[] offsets, int[] counts) throws IOException
{
-        int writeCount = 0;
+    private long writevImpl(Object[] sources, int[] offsets, int[] lengths) throws IOException
{
+        long writeCount = 0;
         try {
             if (isBlocking()) {
                 begin();
             }
 
             synchronized (writeLock) {
-                writeCount = networkSystem.writev(fd, sources, offsets, counts, sources.length);
+                writeCount = networkSystem.writev(fd, sources, offsets, lengths, sources.length);
             }
         } catch (SocketException e) {
             if (e.getCause() instanceof ErrorCodeException) {



Mime
View raw message