JDK 9 RFR of 8168628: (ch) JVM Crash in : ~StubRoutines::jshort_disjoint_arraycopy
brian.burkhalter at oracle.com
Fri Dec 2 02:13:19 UTC 2016
Please review at your convenience:
The FileChannel.map() method extends the size of the file being mapped when it is not already sufficiently large. On Unix, file size extension is implemented via the ftruncate() function. On Linux, this function does not actually allocate any blocks for the file when the new size is larger than the existing size. This may cause problems when the file is memory-mapped. This might occur proximately because map() may be invoked from multiple, different threads wherein one thread reduces the size of a file previously mapped at a larger size by another thread. The eventual result is a SIGBUS.
This patch addresses the problem by using fallocate() on Linux when the requested size exceeds the allocated size, and by synchronizing on positionLock in the section in FileChannelImpl.map() where the file is extended. Note that the same crash is observed on OS X without the addition of this synchronization.
More information about the nio-dev