8202261: (fc) FileChannel.map and RandomAccessFile.setLength should not preallocate space

Reviewed-by: bpb
This commit is contained in:
Alan Bateman 2018-04-26 09:04:18 +01:00
parent ccc74fdd60
commit 2df7aa7b9f
9 changed files with 101 additions and 144 deletions

View file

@ -334,7 +334,7 @@ public class FileChannelImpl
boolean append = fdAccess.getAppend(fd);
do {
// in append-mode then position is advanced to end before writing
p = (append) ? nd.size(fd) : position0(fd, -1);
p = (append) ? nd.size(fd) : nd.seek(fd, -1);
} while ((p == IOStatus.INTERRUPTED) && isOpen());
return IOStatus.normalize(p);
} finally {
@ -358,7 +358,7 @@ public class FileChannelImpl
if (!isOpen())
return null;
do {
p = position0(fd, newPosition);
p = nd.seek(fd, newPosition);
} while ((p == IOStatus.INTERRUPTED) && isOpen());
return this;
} finally {
@ -418,7 +418,7 @@ public class FileChannelImpl
// get current position
do {
p = position0(fd, -1);
p = nd.seek(fd, -1);
} while ((p == IOStatus.INTERRUPTED) && isOpen());
if (!isOpen())
return null;
@ -437,7 +437,7 @@ public class FileChannelImpl
if (p > newSize)
p = newSize;
do {
rp = position0(fd, p);
rp = nd.seek(fd, p);
} while ((rp == IOStatus.INTERRUPTED) && isOpen());
return this;
} finally {
@ -985,7 +985,7 @@ public class FileChannelImpl
}
int rv;
do {
rv = nd.allocate(fd, position + size);
rv = nd.truncate(fd, position + size);
} while ((rv == IOStatus.INTERRUPTED) && isOpen());
if (!isOpen())
return null;
@ -1212,11 +1212,6 @@ public class FileChannelImpl
private native long transferTo0(FileDescriptor src, long position,
long count, FileDescriptor dst);
// Sets or reports this file's position
// If offset is -1, the current position is returned
// otherwise the position is set to offset
private native long position0(FileDescriptor fd, long offset);
// Caches fieldIDs
private static native long initIDs();