History log of /libcore/luni/src/main/java/libcore/io/MemoryMappedFile.java
Revision Date Author Comments
d443d10a1a95b3020cba24b0940b3e1ea3e8ce7d 01-Dec-2016 Neil Fuller <nfuller@google.com> Boundary checks / synchronization / tests for MemoryMappedFile

Hardening MemoryMappedFile against boundary conditions and
edge cases. Many tests added.

Thread safety has been dropped entirely as part of this change:
expected usage is single threaded. It was previously possible
to unmap the file, but the BufferIterator would carry on
attempting to read from the address space.

Motivation: The ZoneInfoDB code will soon be modified to expect
exceptions if reads / writes are out of bounds and it's more
appropriate to make the exceptions part of the MemoryMappedFile
contract.

Bug: 31008728
Test: CtsLibcoreTestCases
Change-Id: I58cba7498c5fcd074054b13dbd6b313d6c1bfbe6
5d930cadc8f62aee5f18e7921296fe66a54f18ab 24-Apr-2014 Elliott Hughes <enh@google.com> Groundwork towards making the Libcore.os functionality public.

Change-Id: Ie700aa16d91fba53fc5eb2555829cb74d84b12ad
0121106d9dc1ba713b53822886355e4d9339e852 28-Feb-2013 Joel Dice <joel.dice@gmail.com> Use longs instead of ints to store pointers in NIO buffers.

This allows the code to be used on 64-bit VMs.

Change-Id: I4d01bfcd0ffea528c6179687771d047fdcb4d18a
9b510df35b57946d843ffc34cf23fdcfc84c5220 28-May-2011 Elliott Hughes <enh@google.com> Make ErrnoException a checked exception.

Bug: 4486011
Change-Id: I1877ce593d441653f75ab14884aa2d85f52652ad
462bdac45c10f43d88d8f07f6994e272a27c14a2 30-Mar-2011 Elliott Hughes <enh@google.com> Add close(2).

This is sufficient for non-socket fds, but may need to change to support the
asynchronous socket close monitor. (Hopefully not; I'd rather lift that into
Java.)

I've also changed the semantics of IoUtils.close to match those desired by
all callers: ignore null/invalid FileDescriptors.

Bug: 3107501
Change-Id: Iad5c31c8f0f34d2a5ab1ed4581509b46af28bd1f
2ffce92141c0b2a5f0543229f3ded34b0ee79ba1 23-Mar-2011 Elliott Hughes <enh@google.com> Move File.createNewFile into Java.

Also add improved tests.

Bug: 3107501
Change-Id: Ibea9bd71adf1e1230c14072fb4597ad5bd9c214b
0ac77ac8e915bff1a863e371f9b363033f9cf759 23-Mar-2011 Elliott Hughes <enh@google.com> Add open(2).

Bug: 3107501
Change-Id: I404030b4c678862465d04f723a6a324663e0af25
7e25eff38a191d9c19e45093f4fde5102fb09d78 19-Mar-2011 Elliott Hughes <enh@google.com> Add mmap(2), msync(2), and munmap(2).

Bug: 3107501
Change-Id: I6a7c4147ec27bab9ded280476bad1157ce03fab8
52724d3ebd4ccaaa4b9f5576e329d4272cde8ea9 17-Mar-2011 Elliott Hughes <enh@google.com> Add fsync(2) and fdatasync(2).

Interesting parts to this change:
* first BlockGuard support (and general delegation support).
* first rethrowing of ErrnoException as IOException.
* switching FileChannelImpl from int to FileDescriptor.

The special case in FileDescriptor.sync has been removed. Testing with the RI
showed that it doesn't treat syncing a FileDescriptor that corresponds to a
socket as a special case --- it throws SyncFailedException just like normal.

Bug: 3107501
Change-Id: I99faf120bd802aec0397a79772ed38c5e1542fed
f934c3d2c8dd9e6bc5299cef41adace2a671637d 15-Mar-2011 Elliott Hughes <enh@google.com> Make OSMemory the semi-supported libcore.io.Memory.

Looks like we're not going to bother with a separate libcore.os package,
when libcore.io will do.

Change-Id: I2806c59349ed4b6410d768c4207c384ced973c54
43a9f774d075e0e441d8b996e3f6c81ea483ec89 19-Oct-2010 Elliott Hughes <enh@google.com> BufferIterator support for byte[].

Bug: 3032515
Change-Id: I040a92c3ce241aa97719ff94e3cc31c62473bf46
ae704b984c10a63883cc366e823d53902d6ac7a9 21-Sep-2010 Elliott Hughes <enh@google.com> Minor tidy-up.

The nio implementation is still a bit of a mess because Java doesn't have any
kind of "module" concept, nor "friend". But this makes it a little less untidy,
and makes the deliberate access control subversions a little more explicit, and
makes various things less accessible than they were.

Change-Id: I514b1e24000b91f86b768ed408fedae115dc3080
bffb058e565a97f838247f1e092b0d17b26cb68e 21-Sep-2010 Elliott Hughes <enh@google.com> Stop doing unbuffered file I/O in ZoneInfoDB.

Use the new memory-mapped code for the index as well as for individual time
zones. This takes the (once-only, during boot) index-reading time down
from ~90ms to ~20ms. DataInputStream(BufferedInputStream(FileInputStream))
would have got us down to ~40ms.

Also remove duplication amongst code snippets that want to read a whole file
into a byte[].

Bug: 3014973
Change-Id: I9d8a326438663314b7f5ee0145cda32ea335f41d
d6b9f2e0e9640ff9c896b394716cf5e7eee6e257 14-Sep-2010 Elliott Hughes <enh@google.com> Much faster TimeZone.getTimeZone using a new private mmap(2) interface.

froyo:

benchmark us logarithmic runtime
TimeZone_getDefault 8.43 =
TimeZone_getTimeZoneUTC 1140.19 ===========================
TimeZone_getTimeZone_America_Caracas 1537.78 ============================
TimeZone_getTimeZone_America_Santiago 1920.50 =============================
TimeZone_getTimeZone_GMT_plus_10 1089.90 ==========================
TimeZone_getTimeZone_default 1105.54 ===========================

dalvik-dev:

benchmark us logarithmic runtime
TimeZone_getDefault 7.37 =
TimeZone_getTimeZoneUTC 30.35 ================
TimeZone_getTimeZone_America_Caracas 35.98 ==================
TimeZone_getTimeZone_America_Santiago 100.21 ==============================
TimeZone_getTimeZone_GMT_plus_10 43.83 ====================
TimeZone_getTimeZone_default 31.32 =================

There are two main changes. The biggest one is to use our own private mmap(2)
API. We might want to make this more generally available in the long term, but
for now it's pretty unsafe; we do nothing to detect invalidated iterators, and
we do no bounds checking. But that's fine for our internal use.

The other change is to recognize that we don't actually need the abbreviated
names. We were only using them for hashCode and equals, and the canonical Olson
id seems like a much better choice for those purposes! That then means that we
don't need to read in as much data in the first place. This makes more
difference for simpler time zones (such as Caracas in the example) because the
overhead is pretty much fixed.

The profile now has us spending most of our time in String.compareTo (for the
binary search) and in OSMemory (paying for our slow native method calling).

Change-Id: I848a318572008e0be8a4a330bb14d2f791353200