OSDN Git Service

2004-11-24 Michael Koch <konqueror@gmx.de>
authormkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 24 Nov 2004 10:44:18 +0000 (10:44 +0000)
committermkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 24 Nov 2004 10:44:18 +0000 (10:44 +0000)
* gnu/java/nio/NIOServerSocket.java: Added email to @author tag.
* java/nio/DirectByteBufferImpl.java:
Moved native methods to java.nio.VMDirectByteBuffer class.
* java/nio/MappedByteBufferImpl.java:
Use native methods from java.nio.VMDirectByteBuffer class.
* java/nio/VMDirectByteBuffer.java: New file,
* java/nio/natDirectByteBufferImpl.cc:
Moved all methods into java.nio.VMDirectByteBuffer class.
* java/nio/channels/spi/AbstractSelectableChannel.java
(register): Only re-use valid keys.
* Makefile.am: Added java/nio/VMDirectByteBuffer.java.
* Makefile.in: Regenerated.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@91146 138bc75d-0d04-0410-961f-82ee72b054a4

libjava/ChangeLog
libjava/Makefile.am
libjava/Makefile.in
libjava/gnu/java/nio/NIOServerSocket.java
libjava/java/nio/DirectByteBufferImpl.java
libjava/java/nio/MappedByteBufferImpl.java
libjava/java/nio/VMDirectByteBuffer.java [new file with mode: 0644]
libjava/java/nio/channels/spi/AbstractSelectableChannel.java
libjava/java/nio/natDirectByteBufferImpl.cc

index 444673d..1c60098 100644 (file)
@@ -1,5 +1,20 @@
 2004-11-24  Michael Koch  <konqueror@gmx.de>
 
+       * gnu/java/nio/NIOServerSocket.java: Added email to @author tag.
+       * java/nio/DirectByteBufferImpl.java:
+       Moved native methods to java.nio.VMDirectByteBuffer class.
+       * java/nio/MappedByteBufferImpl.java:
+       Use native methods from java.nio.VMDirectByteBuffer class.
+       * java/nio/VMDirectByteBuffer.java: New file,
+       * java/nio/natDirectByteBufferImpl.cc:
+       Moved all methods into java.nio.VMDirectByteBuffer class.
+       * java/nio/channels/spi/AbstractSelectableChannel.java
+       (register): Only re-use valid keys.
+       * Makefile.am: Added java/nio/VMDirectByteBuffer.java.
+       * Makefile.in: Regenerated.
+
+2004-11-24  Michael Koch  <konqueror@gmx.de>
+
        * java/nio/DirectByteBufferImpl.java,
        java/nio/MappedByteBufferImpl.java:
        Reformatted.
index 809dcc4..65d60de 100644 (file)
@@ -2957,6 +2957,7 @@ java/nio/ReadOnlyBufferException.java \
 java/nio/ShortBuffer.java \
 java/nio/ShortBufferImpl.java \
 java/nio/ShortViewBufferImpl.java \
+java/nio/VMDirectByteBuffer.java \
 java/nio/channels/AlreadyConnectedException.java \
 java/nio/channels/AsynchronousCloseException.java \
 java/nio/channels/ByteChannel.java \
index df0c597..c701c12 100644 (file)
@@ -949,6 +949,7 @@ am__libgcj_la_SOURCES_DIST = prims.cc jni.cc exception.cc resolve.cc \
        java/nio/ReadOnlyBufferException.java \
        java/nio/ShortBuffer.java java/nio/ShortBufferImpl.java \
        java/nio/ShortViewBufferImpl.java \
+       java/nio/VMDirectByteBuffer.java \
        java/nio/channels/AlreadyConnectedException.java \
        java/nio/channels/AsynchronousCloseException.java \
        java/nio/channels/ByteChannel.java \
@@ -3918,6 +3919,7 @@ am__objects_14 = $(am__objects_9) gnu/classpath/ServiceFactory.lo \
        java/nio/MappedByteBuffer.lo java/nio/MappedByteBufferImpl.lo \
        java/nio/ReadOnlyBufferException.lo java/nio/ShortBuffer.lo \
        java/nio/ShortBufferImpl.lo java/nio/ShortViewBufferImpl.lo \
+       java/nio/VMDirectByteBuffer.lo \
        java/nio/channels/AlreadyConnectedException.lo \
        java/nio/channels/AsynchronousCloseException.lo \
        java/nio/channels/ByteChannel.lo \
@@ -6830,6 +6832,7 @@ java/nio/ReadOnlyBufferException.java \
 java/nio/ShortBuffer.java \
 java/nio/ShortBufferImpl.java \
 java/nio/ShortViewBufferImpl.java \
+java/nio/VMDirectByteBuffer.java \
 java/nio/channels/AlreadyConnectedException.java \
 java/nio/channels/AsynchronousCloseException.java \
 java/nio/channels/ByteChannel.java \
@@ -9997,6 +10000,8 @@ java/nio/ShortBufferImpl.lo: java/nio/$(am__dirstamp) \
        java/nio/$(DEPDIR)/$(am__dirstamp)
 java/nio/ShortViewBufferImpl.lo: java/nio/$(am__dirstamp) \
        java/nio/$(DEPDIR)/$(am__dirstamp)
+java/nio/VMDirectByteBuffer.lo: java/nio/$(am__dirstamp) \
+       java/nio/$(DEPDIR)/$(am__dirstamp)
 java/nio/channels/AlreadyConnectedException.lo:  \
        java/nio/channels/$(am__dirstamp) \
        java/nio/channels/$(DEPDIR)/$(am__dirstamp)
@@ -16839,6 +16844,8 @@ mostlyclean-compile:
        -rm -f java/nio/ShortBufferImpl.lo
        -rm -f java/nio/ShortViewBufferImpl.$(OBJEXT)
        -rm -f java/nio/ShortViewBufferImpl.lo
+       -rm -f java/nio/VMDirectByteBuffer.$(OBJEXT)
+       -rm -f java/nio/VMDirectByteBuffer.lo
        -rm -f java/nio/channels/AlreadyConnectedException.$(OBJEXT)
        -rm -f java/nio/channels/AlreadyConnectedException.lo
        -rm -f java/nio/channels/AsynchronousCloseException.$(OBJEXT)
@@ -20700,6 +20707,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@java/nio/$(DEPDIR)/ShortBuffer.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@java/nio/$(DEPDIR)/ShortBufferImpl.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@java/nio/$(DEPDIR)/ShortViewBufferImpl.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@java/nio/$(DEPDIR)/VMDirectByteBuffer.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@java/nio/$(DEPDIR)/natDirectByteBufferImpl.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@java/nio/channels/$(DEPDIR)/AlreadyConnectedException.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@java/nio/channels/$(DEPDIR)/AsynchronousCloseException.Plo@am__quote@
index 3164247..f509774 100644 (file)
@@ -39,6 +39,7 @@ exception statement from your version. */
 package gnu.java.nio;
 
 import gnu.java.net.PlainSocketImpl;
+
 import java.io.IOException;
 import java.net.ServerSocket;
 import java.net.Socket;
@@ -46,7 +47,7 @@ import java.nio.channels.ServerSocketChannel;
 import java.nio.channels.SocketChannel;
 
 /**
- * @author Michael Koch
+ * @author Michael Koch (konqueror@gmx.de)
  */
 public final class NIOServerSocket extends ServerSocket
 {
index 6e4fa81..a92515d 100644 (file)
@@ -38,20 +38,10 @@ exception statement from your version. */
 
 package java.nio;
 
-import gnu.classpath.Configuration;
 import gnu.gcj.RawData;
 
 final class DirectByteBufferImpl extends ByteBuffer
 {
-  static
-  {
-    // load the shared library needed for native methods.
-    if (Configuration.INIT_LOAD_LIBRARY)
-      {
-        System.loadLibrary ("javanio");
-      }
-  }
-  
   /** Used by MappedByteBufferImpl and when slicing to prevent premature GC. */
   protected Object owner;
 
@@ -78,26 +68,21 @@ final class DirectByteBufferImpl extends ByteBuffer
    */ 
   public static ByteBuffer allocate(int capacity)
   {
-    return new DirectByteBufferImpl(allocateImpl(capacity), capacity);
+    return new DirectByteBufferImpl(VMDirectByteBuffer.allocate(capacity),
+                                   capacity);
   }
 
-  private static native RawData allocateImpl (int capacity);
-  private static native void freeImpl (RawData address);
-  
   protected void finalize() throws Throwable
   {
-    freeImpl (address);
+    VMDirectByteBuffer.free(address);
   }
   
-  static native byte getImpl (RawData address, int index);
-  static native void putImpl (RawData address, int index, byte value);
-
   public byte get()
   {
     checkForUnderflow();
 
     int pos = position();
-    byte result = getImpl (address, pos);
+    byte result = VMDirectByteBuffer.get(address, pos);
     position(pos + 1);
     return result;
   }
@@ -106,19 +91,16 @@ final class DirectByteBufferImpl extends ByteBuffer
   {
     checkIndex(index);
 
-    return getImpl (address, index);
+    return VMDirectByteBuffer.get(address, index);
   }
 
-  static native void getImpl (RawData address, int index,
-                             byte[] dst, int offset, int length);
-
   public ByteBuffer get(byte[] dst, int offset, int length)
   {
     checkArraySize(dst.length, offset, length);
     checkForUnderflow(length);
 
     int index = position();
-    getImpl(address, index, dst, offset, length);
+    VMDirectByteBuffer.get(address, index, dst, offset, length);
     position(index+length);
 
     return this;
@@ -130,7 +112,7 @@ final class DirectByteBufferImpl extends ByteBuffer
     checkForOverflow();
 
     int pos = position();
-    putImpl (address, pos, value);
+    VMDirectByteBuffer.put(address, pos, value);
     position(pos + 1);
     return this;
   }
@@ -140,15 +122,13 @@ final class DirectByteBufferImpl extends ByteBuffer
     checkIfReadOnly();
     checkIndex(index);
 
-    putImpl (address, index, value);
+    VMDirectByteBuffer.put(address, index, value);
     return this;
   }
   
-  static native void shiftDown(RawData address, int dst_offset, int src_offset, int count);
-
   void shiftDown(int dst_offset, int src_offset, int count)
   {
-    shiftDown(address, dst_offset, src_offset, count);
+    VMDirectByteBuffer.shiftDown(address, dst_offset, src_offset, count);
   }
   
   public ByteBuffer compact()
@@ -157,21 +137,19 @@ final class DirectByteBufferImpl extends ByteBuffer
     if (pos > 0)
       {
        int count = remaining();
-       shiftDown(address, 0, pos, count);
+       VMDirectByteBuffer.shiftDown(address, 0, pos, count);
        position(count);
        limit(capacity());
       }
     return this;
   }
 
-  public static native RawData adjustAddress(RawData address, int offset);
-
   public ByteBuffer slice()
   {
     int rem = remaining();
-    return new DirectByteBufferImpl (owner,
-                                    adjustAddress(address, position()),
-                                    rem, rem, 0, isReadOnly ());
+    return new DirectByteBufferImpl
+      (owner, VMDirectByteBuffer.adjustAddress(address, position()),
+       rem, rem, 0, isReadOnly());
   }
 
   private ByteBuffer duplicate(boolean readOnly)
index 8f41322..c5cf355 100644 (file)
@@ -72,8 +72,8 @@ final class MappedByteBufferImpl extends MappedByteBuffer
     checkForUnderflow();
 
     int pos = position();
-    byte result = DirectByteBufferImpl.getImpl(address, pos);
-    position (pos + 1);
+    byte result = VMDirectByteBuffer.get(address, pos);
+    position(pos + 1);
     return result;
   }
 
@@ -83,7 +83,7 @@ final class MappedByteBufferImpl extends MappedByteBuffer
     checkForOverflow();
 
     int pos = position();
-    DirectByteBufferImpl.putImpl(address, pos, value);
+    VMDirectByteBuffer.put(address, pos, value);
     position(pos + 1);
     return this;
   }
@@ -92,7 +92,7 @@ final class MappedByteBufferImpl extends MappedByteBuffer
   {
     checkIndex(index);
 
-    return DirectByteBufferImpl.getImpl(address, index);
+    return VMDirectByteBuffer.get(address, index);
   }
 
   public ByteBuffer get(byte[] dst, int offset, int length)
@@ -101,7 +101,7 @@ final class MappedByteBufferImpl extends MappedByteBuffer
     checkForUnderflow(length);
 
     int index = position();
-    DirectByteBufferImpl.getImpl(address, index, dst, offset, length);
+    VMDirectByteBuffer.get(address, index, dst, offset, length);
     position(index+length);
 
     return this;
@@ -112,7 +112,7 @@ final class MappedByteBufferImpl extends MappedByteBuffer
     checkIfReadOnly();
     checkIndex(index);
 
-    DirectByteBufferImpl.putImpl(address, index, value);
+    VMDirectByteBuffer.put(address, index, value);
     return this;
   }
 
@@ -123,7 +123,7 @@ final class MappedByteBufferImpl extends MappedByteBuffer
       {
        int count = remaining();
        // Call shiftDown method optimized for direct buffers.
-       DirectByteBufferImpl.shiftDown(address, 0, pos, count);
+       VMDirectByteBuffer.shiftDown(address, 0, pos, count);
        position(count);
        limit(capacity());
       }
@@ -138,10 +138,9 @@ final class MappedByteBufferImpl extends MappedByteBuffer
   public ByteBuffer slice()
   {
     int rem = remaining();
-    return new DirectByteBufferImpl (this,
-                                    DirectByteBufferImpl
-                                    .adjustAddress(address, position()),
-                                    rem, rem, 0, isReadOnly ());
+    return new DirectByteBufferImpl
+      (this, VMDirectByteBuffer.adjustAddress(address, position()),
+       rem, rem, 0, isReadOnly());
   }
 
   private ByteBuffer duplicate(boolean readOnly)
diff --git a/libjava/java/nio/VMDirectByteBuffer.java b/libjava/java/nio/VMDirectByteBuffer.java
new file mode 100644 (file)
index 0000000..99d21b9
--- /dev/null
@@ -0,0 +1,53 @@
+/* VMDirectByteBuffer.java -- 
+   Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package java.nio;
+
+import gnu.classpath.Configuration;
+import gnu.gcj.RawData;
+
+final class VMDirectByteBuffer
+{
+  static native RawData allocate (int capacity);
+  static native void free(RawData address);
+  static native byte get(RawData address, int index);
+  static native void get(RawData address, int index, byte[] dst, int offset, int length);
+  static native void put(RawData address, int index, byte value);
+  static native RawData adjustAddress(RawData address, int offset);
+  static native void shiftDown(RawData address, int dst_offset, int src_offset, int count);
+}
index ccc48c9..2255af0 100644 (file)
@@ -35,6 +35,7 @@ this exception to your version of the library, but you are not
 obligated to do so.  If you do not wish to do so, delete this
 exception statement from your version. */
 
+
 package java.nio.channels.spi;
 
 import java.io.IOException;
@@ -45,7 +46,6 @@ import java.nio.channels.Selector;
 import java.util.LinkedList;
 import java.util.ListIterator;
 
-
 public abstract class AbstractSelectableChannel extends SelectableChannel
 {
   private boolean blocking = true;
@@ -226,7 +226,7 @@ public abstract class AbstractSelectableChannel extends SelectableChannel
       {
        key = locate(selector);
 
-       if (key != null)
+       if (key != null && key.isValid())
          {
            if (att != null)
              key.attach(att);
index 88f53fc..3119fde 100644 (file)
@@ -16,56 +16,55 @@ details.  */
 #include <stdlib.h>
 
 #include <gnu/gcj/RawData.h>
-#include <java/nio/DirectByteBufferImpl.h>
+#include <java/nio/VMDirectByteBuffer.h>
 
 using gnu::gcj::RawData;
-using java::nio::DirectByteBufferImpl;
 
 RawData*
-java::nio::DirectByteBufferImpl::allocateImpl (jint capacity)
+java::nio::VMDirectByteBuffer::allocate (jint capacity)
 {
   return reinterpret_cast<gnu::gcj::RawData*> (::malloc (capacity));
 }
 
 void
-java::nio::DirectByteBufferImpl::freeImpl (gnu::gcj::RawData* address)
+java::nio::VMDirectByteBuffer::free (gnu::gcj::RawData* address)
 {
   ::free (reinterpret_cast<void*> (address));
 }
 
 jbyte
-DirectByteBufferImpl::getImpl (RawData* address, jint index)
+java::nio::VMDirectByteBuffer::get (RawData* address, jint index)
 {
   jbyte* pointer = reinterpret_cast<jbyte*> (address) + index;
   return *pointer;
 }
 
 void
-DirectByteBufferImpl::getImpl (RawData* address, jint index,
-                              jbyteArray dst, jint offset, jint length)
+java::nio::VMDirectByteBuffer::get (RawData* address, jint index,
+                                   jbyteArray dst, jint offset, jint length)
 {
   jbyte* src = reinterpret_cast<jbyte*> (address) + index;
   memcpy (elements (dst) + offset, src, length);
 }
 
 void
-java::nio::DirectByteBufferImpl::putImpl (gnu::gcj::RawData* address,
-                                         jint index, jbyte value)
+java::nio::VMDirectByteBuffer::put (gnu::gcj::RawData* address,
+                                   jint index, jbyte value)
 {
   jbyte* pointer = reinterpret_cast<jbyte*> (address) + index;
   *pointer = value;
 }
 
 RawData*
-java::nio::DirectByteBufferImpl::adjustAddress (RawData* address, jint offset)
+java::nio::VMDirectByteBuffer::adjustAddress (RawData* address, jint offset)
 {
   jbyte* start = reinterpret_cast<jbyte*> (address) + offset;
   return reinterpret_cast<RawData*>(start);
 }
 
 void
-java::nio::DirectByteBufferImpl::shiftDown
-(RawData* address, jint dst_offset, jint src_offset, jint count)
+java::nio::VMDirectByteBuffer::shiftDown (RawData* address, jint dst_offset,
+                                         jint src_offset, jint count)
 {
   jbyte* dst = reinterpret_cast<jbyte*> (address) + dst_offset;
   jbyte* src = reinterpret_cast<jbyte*> (address) + src_offset;