diff options
Diffstat (limited to 'libjava/java/nio/DirectByteBufferImpl.java')
-rw-r--r-- | libjava/java/nio/DirectByteBufferImpl.java | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/libjava/java/nio/DirectByteBufferImpl.java b/libjava/java/nio/DirectByteBufferImpl.java index c272bacbf72..a0599c722a9 100644 --- a/libjava/java/nio/DirectByteBufferImpl.java +++ b/libjava/java/nio/DirectByteBufferImpl.java @@ -42,21 +42,22 @@ import gnu.gcj.RawData; abstract class DirectByteBufferImpl extends ByteBuffer { - /** The owner is used to keep alive the object that actually owns the - * memory. There are three possibilities: - * 1) owner == this: We allocated the memory and we should free it, - * but *only* in finalize (if we've been sliced - * other objects will also have access to the - * memory). - * 2) owner == null: The byte buffer was created thru - * JNI.NewDirectByteBuffer. The JNI code is - * responsible for freeing the memory. - * 3) owner == some other object: The other object allocated the - * memory and should free it. - */ + /** + * The owner is used to keep alive the object that actually owns the + * memory. There are three possibilities: + * 1) owner == this: We allocated the memory and we should free it, + * but *only* in finalize (if we've been sliced + * other objects will also have access to the + * memory). + * 2) owner == null: The byte buffer was created thru + * JNI.NewDirectByteBuffer. The JNI code is + * responsible for freeing the memory. + * 3) owner == some other object: The other object allocated the + * memory and should free it. + */ private final Object owner; - final static class ReadOnly extends DirectByteBufferImpl + static final class ReadOnly extends DirectByteBufferImpl { ReadOnly(Object owner, RawData address, int capacity, int limit, @@ -81,7 +82,7 @@ abstract class DirectByteBufferImpl extends ByteBuffer } } - final static class ReadWrite extends DirectByteBufferImpl + static final class ReadWrite extends DirectByteBufferImpl { ReadWrite(int capacity) { @@ -116,7 +117,7 @@ abstract class DirectByteBufferImpl extends ByteBuffer DirectByteBufferImpl(RawData address, int capacity) { super(capacity, capacity, 0, -1); - this.owner = this; + this.owner = null; this.address = address; } @@ -197,6 +198,8 @@ abstract class DirectByteBufferImpl extends ByteBuffer public ByteBuffer compact() { + checkIfReadOnly(); + mark = -1; int pos = position(); if (pos > 0) { @@ -205,6 +208,11 @@ abstract class DirectByteBufferImpl extends ByteBuffer position(count); limit(capacity()); } + else + { + position(limit()); + limit(capacity()); + } return this; } |