map()方法
直接将文件从硬盘拷贝到用户空间,只进行了一次数据拷贝。
mmap的内存开销是不受JVM heap控制的,也就是堆外内存。mmap的文件数据被从磁盘load进物理内存,RES增加。
/**
* Maps a region of this channel's file directly into memory.
*
* <p> A region of a file may be mapped into memory in one of three modes:
* </p>
*
* <ul>
*
* <li><p> <i>Read-only:</i> Any attempt to modify the resulting buffer
* will cause a {@link java.nio.ReadOnlyBufferException} to be thrown.
* ({@link MapMode#READ_ONLY MapMode.READ_ONLY}) </p></li>
*
* <li><p> <i>Read/write:</i> Changes made to the resulting buffer will
* eventually be propagated to the file; they may or may not be made
* visible to other programs that have mapped the same file. ({@link
* MapMode#READ_WRITE MapMode.READ_WRITE}) </p></li>
*
* <li><p> <i>Private:</i> Changes made to the resulting buffer will not
* be propagated to the file and will not be visible to other programs
* that have mapped the same file; instead, they will cause private
* copies of the modified portions of the buffer to be created. ({@link
* MapMode#PRIVATE MapMode.PRIVATE}) </p></li>
*
* </ul>
*
* <p> For a read-only mapping, this channel must have been opened for
* reading; for a read/write or private mapping, this channel must have
* been opened for both reading and writing.
*
* <p> The {@link MappedByteBuffer <i>mapped byte buffer</i>}
* returned by this method will have a position of zero and a limit and
* capacity of <tt>size</tt>; its mark will be undefined. The buffer and
* the mapping that it represents will remain valid until the buffer itself
* is garbage-collected.
*
* <p> A mapping, once established, is not dependent upon the file channel
* that was used to create it. Closing the channel, in particular, has no
* effect upon the validity o