8202116: (fc) FileChannel.map should ensure mapped region is backed by disk space

Alan Bateman Alan.Bateman at oracle.com
Mon Apr 23 19:32:17 UTC 2018


This is a follow-up to the "Changes to RandomAccessFile in jdk9" thread 
and the change in JDK 9 (and 8u162) to RandomAccessFile.setLengthforce 
to force disk space to be allocated for otherwise sparse files.

The patch here is essentially a re-visit of JDK-8168628. 
RandomAccessFile.setLength is reverted so that it doesn't allocate the 
disk space. Instead, FileChannel.map is changed to allocate the disk 
space for the case that the region to be mapped overlaps with a hole in 
a sparse file. Testing the changes is awkward as the conditions for 
JDK-8168628 require filing up the file system to prevent space being 
allocated. Brian created an @ignore-ed test for JDK-8168628 so that is 
useful to re-create the conditions. In addition, several of the existing 
tests exercise this code as they (unknowingly) create spare files.

The webrev with the changes is here:
    http://cr.openjdk.java.net/~alanb/8202116/webrev/

-Alan


More information about the nio-dev mailing list