Optimize byte-swapped accesses.

Brings the performance of byte-swapped accesses way down from about 3x to
less than 2x worst-case (char/short) and 20% best-case (long/double). The
main active ingredients are switching to a single-pass swapped-copy (rather
than copy in one pass, swap in a second pass), and ensuring we use ARM's
REV and REV16 instructions.

Because the array get/put methods were getting complicated again, I've
factored the implementations out using a couple of macros.

I've also removed the obsolete misaligned access workarounds for <= 32-bit
types, leaving only the code for misaligned 64-bit accesses.

Bug: 2935622
Change-Id: I5a2365c2bcf35e05dbea9ebc3463c73ef17e33d0

Conflicts:
	luni/src/main/native/org_apache_harmony_luni_platform_OSMemory.cpp
More nio speedups.

Small improvements this time. Stop penalizing getChar/putChar with an extra
level of indirection through getShort/putShort; our VM can't win that
back yet, and the extra method call is a significant fraction of the
total time taken for these operations (1/3rd). This applies to direct, heap,
and mapped buffers. (One day we'll be able to come back and remove this.)

Also remove the float/double specializations from MemoryBlock, rewriting
the two callers of each to use int/long directly. Those callers are public
API, so this is as far as the removal of useless duplication can go here.
This applies to direct and mapped buffers.

Unroll loops (!) used to load/store short/int/long values from Java heap
byte[]s for performance. This applies to heap buffers.

Bug: 2935622
Change-Id: I093122af2b49d3ef864b87dce637c781727445dd
Remove BufferIterator and his derived class
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
Fix problems discovered by Channels/Basic test.

In particular:
 - available() wasn't trying very hard for FileChannels
   where a reasonable value can be had.
 - short writes weren't handled, so bytes were being lost
 - the alternative InputStreamReader and OutputStreamReader
   classes were incorrect and redundant
 - the duplicated ChannelInputStream classes were redundant
   and one was missing a required IllegalBlockingModeException
 - bounds checks were redundant and handled by Bytebuffer.wrap
 - null checks were missing.

The new code doesn't honor the user's supplied minBufferCapacity
and instead always uses 8K. 8K is larger than the 'min' so it
should be fine for undersized buffers. And it's sufficient for
high performance, so it should be fine for oversized buffers.
It'll only be a problem for clients that create a very large
number of these Readers, which shouldn't happen in practice.

http://b/issue?id=2233508

Change-Id: I3688397baae4f69f9146aed6a3a60d8333e5df1d
Replace TODOs with comments describing why we're ignoring minBufferCapacity.

Change-Id: I3fb91ded4a574bd20198c35ab5f6f6ad23c856e6
Explode early when ICU's .dat file isn't available.

Also make it generally more obvious (and more obvious who's to blame) when
libcore's native code fails to initialize.

Bug: 3005342
Change-Id: I75496bb0c15391d7f32ba50b9c488ea0480e3e42

Conflicts:
	luni/src/main/native/ICU.cpp
	luni/src/main/native/Register.cpp
Make nio heap (non-direct) buffer bulk get orders of magnitude faster.

Bug: 2985452
Change-Id: I8bd210d1a623e434121f30eca6e2555e1aea11cd
Replace "ordered" puts with native implementation.

Instead of calling the full-on volatile version, call a dedicated
native version with a less-expensive barrier.

Bug 2579452

Change-Id: I1a8a19c82d987b891847c5c5b75021a1ec4fcd11
Optimize non-direct (heap) buffer bulk put.

I've also factored out the bounds checking, even though the JIT can't yet
inline it back. I'm unwilling to duplicate all that code again.

This patch also fixes bugs in the previous checkin relating to offsets
and positions. In real life (and, seemingly, in all our tests) these tend
to be 0, making it rare that anyone trips over these bugs. (The first nio
change I made was fixing just such a bug.) I've improved the test I added
last time so that it covers more of these cases.

Here are the "after" performance figures for heap buffer bulk copies:

        CharBuffer_getCharArray  5797
        CharBuffer_putCharArray  5818
    DoubleBuffer_getDoubleArray 13053
    DoubleBuffer_putDoubleArray 13026
      FloatBuffer_getFloatArray  8216
      FloatBuffer_putFloatArray  8283
          IntBuffer_getIntArray  8253
          IntBuffer_putIntArray  8371
        LongBuffer_getLongArray 13053
        LongBuffer_putLongArray 13020
      ShortBuffer_getShortArray  5796
      ShortBuffer_putShortArray  5864

This compares well with with direct buffer performance (just gets shown here):

        CharBuffer_getCharArray  4412
    DoubleBuffer_getDoubleArray 11594
      FloatBuffer_getFloatArray  6787
          IntBuffer_getIntArray  6791
        LongBuffer_getLongArray 11672
      ShortBuffer_getShortArray  4430

Bug: 2985452
Change-Id: I37307f9b304c87a87af5313790444dcdf6174ff1
Remove dead code.

Presumably frameworks/base/ used this at some point, but it doesn't now.

Change-Id: Id299958dc2352c25b1555c07bf4d114fafdd7aea
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
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
Fix build: nio implementation details accidentally made public.

Change-Id: I1bc4b40c2038088a1e22489f39d54e28d9ae21cb
Fix new FileInputStream(".") to throw.

Unlike Posix, Java disallows opening a directory for _reading_ too.

Bug: 2224954
Change-Id: I1414978c4fc530378937a250dea03aa647c6c1ed

Conflicts:
	luni/src/main/native/org_apache_harmony_luni_platform_OSFileSystem.cpp
Love for FileInputStream and FileOutputStream.

This changes FileOutputStream to open its channel lazily. Doing so
requires a new field, mode. It saves the allocation of the channel
and its accompanying infrastructure in the common case.

This adds example usage complete with the necessary buffers, and
removed documentation that was redundant from the superclass.

Change-Id: Ib23d12cef075169a574fddedcaf1fec018eb726c
http://b/3018687

Conflicts:
	luni/src/main/java/java/io/FileInputStream.java
	luni/src/main/java/java/io/FileOutputStream.java
Remove custom marker classes for locks.

Just use Object instead.

Bug: 3024308
Change-Id: I83a01020646d95e014743b76e27ca7134c155298
Fix setLength() to adjust pointer.

See http://b/2224985

Change-Id: Ie8b7a7a455fdbde051dea15f8d3e4dc6bf8f6fba
Remove unbuffered single-byte I/O from ZipFile.

This is enough to fool my current checking (and a little bit better than the
existing code), but I do plan on better checking and a rewrite of ZipFile.

Bug: 3018772
Change-Id: I607fee807c2bcbe9d59b883ef7bfbaa9a8f54ea8
Improve RandomAccessFile documentation.

Change-Id: I74ae5b018f2c140e97b516576ef582d213a1b7cc