mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 22:34:27 +02:00
4833719: (bf) Views of MappedByteBuffers are not MappedByteBuffers, and cannot be forced
Reviewed-by: adinn
This commit is contained in:
parent
8307aa6dcb
commit
b006f22f1f
3 changed files with 214 additions and 13 deletions
|
@ -198,11 +198,18 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
// For duplicates and slices
|
||||
//
|
||||
Direct$Type$Buffer$RW$$BO$(DirectBuffer db, // package-private
|
||||
int mark, int pos, int lim, int cap,
|
||||
int off, MemorySegmentProxy segment)
|
||||
int mark, int pos, int lim, int cap, int off,
|
||||
#if[byte]
|
||||
FileDescriptor fd, boolean isSync,
|
||||
#end[byte]
|
||||
MemorySegmentProxy segment)
|
||||
{
|
||||
#if[rw]
|
||||
super(mark, pos, lim, cap, segment);
|
||||
super(mark, pos, lim, cap,
|
||||
#if[byte]
|
||||
fd, isSync,
|
||||
#end[byte]
|
||||
segment);
|
||||
address = ((Buffer)db).address + off;
|
||||
#if[byte]
|
||||
cleaner = null;
|
||||
|
@ -210,7 +217,11 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
Object attachment = db.attachment();
|
||||
att = (attachment == null ? db : attachment);
|
||||
#else[rw]
|
||||
super(db, mark, pos, lim, cap, off, segment);
|
||||
super(db, mark, pos, lim, cap, off,
|
||||
#if[byte]
|
||||
fd, isSync,
|
||||
#end[byte]
|
||||
segment);
|
||||
this.isReadOnly = true;
|
||||
#end[rw]
|
||||
}
|
||||
|
@ -220,17 +231,27 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
return null;
|
||||
}
|
||||
|
||||
public $Type$Buffer slice() {
|
||||
public {#if[byte]?Mapped$Type$Buffer:$Type$Buffer} slice() {
|
||||
int pos = this.position();
|
||||
int lim = this.limit();
|
||||
int rem = (pos <= lim ? lim - pos : 0);
|
||||
int off = (pos << $LG_BYTES_PER_VALUE$);
|
||||
assert (off >= 0);
|
||||
return new Direct$Type$Buffer$RW$$BO$(this, -1, 0, rem, rem, off, segment);
|
||||
return new Direct$Type$Buffer$RW$$BO$(this,
|
||||
-1,
|
||||
0,
|
||||
rem,
|
||||
rem,
|
||||
off,
|
||||
#if[byte]
|
||||
fileDescriptor(),
|
||||
isSync(),
|
||||
#end[byte]
|
||||
segment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public $Type$Buffer slice(int index, int length) {
|
||||
public {#if[byte]?Mapped$Type$Buffer:$Type$Buffer} slice(int index, int length) {
|
||||
Objects.checkFromIndexSize(index, length, limit());
|
||||
return new Direct$Type$Buffer$RW$$BO$(this,
|
||||
-1,
|
||||
|
@ -238,16 +259,25 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
length,
|
||||
length,
|
||||
index << $LG_BYTES_PER_VALUE$,
|
||||
#if[byte]
|
||||
fileDescriptor(),
|
||||
isSync(),
|
||||
#end[byte]
|
||||
segment);
|
||||
}
|
||||
|
||||
public $Type$Buffer duplicate() {
|
||||
public {#if[byte]?Mapped$Type$Buffer:$Type$Buffer} duplicate() {
|
||||
return new Direct$Type$Buffer$RW$$BO$(this,
|
||||
this.markValue(),
|
||||
this.position(),
|
||||
this.limit(),
|
||||
this.capacity(),
|
||||
0, segment);
|
||||
0,
|
||||
#if[byte]
|
||||
fileDescriptor(),
|
||||
isSync(),
|
||||
#end[byte]
|
||||
segment);
|
||||
}
|
||||
|
||||
public $Type$Buffer asReadOnlyBuffer() {
|
||||
|
@ -257,7 +287,12 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
this.position(),
|
||||
this.limit(),
|
||||
this.capacity(),
|
||||
0, segment);
|
||||
0,
|
||||
#if[byte]
|
||||
fileDescriptor(),
|
||||
isSync(),
|
||||
#end[byte]
|
||||
segment);
|
||||
#else[rw]
|
||||
return duplicate();
|
||||
#end[rw]
|
||||
|
@ -506,7 +541,7 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
#end[rw]
|
||||
}
|
||||
|
||||
public $Type$Buffer compact() {
|
||||
public {#if[byte]?Mapped$Type$Buffer:$Type$Buffer} compact() {
|
||||
#if[rw]
|
||||
int pos = position();
|
||||
int lim = limit();
|
||||
|
|
|
@ -152,10 +152,20 @@ public abstract class MappedByteBuffer
|
|||
* @return true if the file was mapped using one of the sync map
|
||||
* modes, otherwise false.
|
||||
*/
|
||||
private boolean isSync() {
|
||||
final boolean isSync() { // package-private
|
||||
return isSync;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@code FileDescriptor} associated with this
|
||||
* {@code MappedByteBuffer}.
|
||||
*
|
||||
* @return the buffer's file descriptor; may be {@code null}
|
||||
*/
|
||||
final FileDescriptor fileDescriptor() { // package-private
|
||||
return fd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether or not this buffer's content is resident in physical
|
||||
* memory.
|
||||
|
@ -205,7 +215,10 @@ public abstract class MappedByteBuffer
|
|||
|
||||
/**
|
||||
* Forces any changes made to this buffer's content to be written to the
|
||||
* storage device containing the mapped file.
|
||||
* storage device containing the mapped file. The region starts at index
|
||||
* zero in this buffer and is {@code capacity()} bytes. An invocation of
|
||||
* this method behaves in exactly the same way as the invocation
|
||||
* {@link force(int,int) force(0,capacity())}.
|
||||
*
|
||||
* <p> If the file mapped into this buffer resides on a local storage
|
||||
* device then when this method returns it is guaranteed that all changes
|
||||
|
@ -362,4 +375,41 @@ public abstract class MappedByteBuffer
|
|||
super.rewind();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p> Reading bytes into physical memory by invoking {@code load()} on the
|
||||
* returned buffer, or writing bytes to the storage device by invoking
|
||||
* {@code force()} on the returned buffer, will only act on the sub-range
|
||||
* of this buffer that the returned buffer represents, namely
|
||||
* {@code [position(),limit())}.
|
||||
*/
|
||||
@Override
|
||||
public abstract MappedByteBuffer slice();
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p> Reading bytes into physical memory by invoking {@code load()} on the
|
||||
* returned buffer, or writing bytes to the storage device by invoking
|
||||
* {@code force()} on the returned buffer, will only act on the sub-range
|
||||
* of this buffer that the returned buffer represents, namely
|
||||
* {@code [index,index+length)}, where {@code index} and {@code length} are
|
||||
* assumed to satisfy the preconditions.
|
||||
*/
|
||||
@Override
|
||||
public abstract MappedByteBuffer slice(int index, int length);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public abstract MappedByteBuffer duplicate();
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public abstract MappedByteBuffer compact();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue