file size growth on FileChannel.map

ArtemGr artemciy at gmail.com
Thu Jul 23 11:04:11 UTC 2009


When I use a FileChannel.map several times to map a large region into 
memory, the file size suddenly increase.
The mapped region is always withing the file, e.g. always less than 
FileChannel.position!
I monitored FileChannel.position and FileChannel.size: 
FileChannel.position stays the same, yet FileChannel.size increases 
after mapping. The file itself increases too, with the new space 
containing all zeroes. The increase is large, tens and hundreds of 
megabytes. I had my files grow to several gigabytes just by mmaping 
regions of them.
I don't think it is an expected behaviour, AFAIK. FreeBSD mmap might 
return a larger portion of memory to match a page size, but it isn't 
supposed to grow the underlying file. Therefore I suspect it might be a 
bug in (FreeBSD version of) the JDK.

I encountered the problem on
7.2-RELEASE amd64, openjdk version "1.6.0-internal", ZFS
and
7.2-STABLE (May 25) amd64, java version "1.6.0_07", UFS2

Had anybody seen such behaviour from FileChannel.map? Am I right 
supposing it shouldn't grow the file?

Should I investigate further?


More information about the freebsd-java mailing list