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();

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -36,12 +36,17 @@ abstract class FileDispatcher extends NativeDispatcher {
public static final int RET_EX_LOCK = 1; // Obtained exclusive lock
public static final int INTERRUPTED = 2; // Request interrupted
/**
* Sets or reports this file's position
* If offset is -1, the current position is returned
* otherwise the position is set to offset.
*/
abstract long seek(FileDescriptor fd, long offset) throws IOException;
abstract int force(FileDescriptor fd, boolean metaData) throws IOException;
abstract int truncate(FileDescriptor fd, long size) throws IOException;
abstract int allocate(FileDescriptor fd, long size) throws IOException;
abstract long size(FileDescriptor fd) throws IOException;
abstract int lock(FileDescriptor fd, boolean blocking, long pos, long size,