NIOServerSocket.java: Added email to @author tag.
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. From-SVN: r91146
This commit is contained in:
parent
9114616933
commit
11dde1bb18
9 changed files with 115 additions and 61 deletions
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
53
libjava/java/nio/VMDirectByteBuffer.java
Normal file
53
libjava/java/nio/VMDirectByteBuffer.java
Normal file
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue