Improve dalvik based on CAF

Change-Id: I8885b3b9ec07d678a2a80caaf5e497916b5b5a7d

Conflicts:
	vm/Android.mk
	vm/alloc/HeapSource.cpp
dalvik: use bionic memmove

use memmove from bionic if it is halfword atomic.

Change-Id: I81c38c2b504483b69b0b1c1e4ffb63cb81d347d5
A char array copy optimization (dalvik).

Bug: 7103825

(cherry picked from commit dc6cb9c7cb4ef636aa6f542615410b56a67b94dc)

Change-Id: I0b8ab789ffb8702bc134b32398c120cc3ed29b9c
dalvik: Use Bionic's memmove on cortex-a15

Change-Id: Ia313d784cf9e261e0c82f1a6d412eca1731a5034
Dalvik: DMB Optimisation

Replaces use of 'dmb' and 'dmb st' with inner-shareable versions.
This should improve performance in certain cases without harming
correctness.

Change-Id: Id30f58b93b34bf0e232bb01dc3956a82f7a69c40
(cherry picked from commit 2ea163ba54731afcfa11341a525c33e08d0781fa)
Dalvik: DMB Optimisations for TracingJIT

Makes DMB domain ISH or ISHST instead of the implicit System.
ISH (Inner Shareable) should be sufficient for all cores/clusters,
but is not sufficient for GPU or other memory-mapped peripherals

Change-Id: Id159228daba97bc3692d2eb1ee2786bae2ee34a7
(cherry picked from commit 48704eccc23e91f3ee46ea4882d1dfef43646cc4)
Exclude sha1.c when building libdex for device

In bionic, there is already an optimized SHA-1 hash implementation,
and the file 'sha1.c' in libdex is almost identical.  It is only
necessary to build sha1.c for host version of libdex.

In addition, the SHA-1 hash implementation in bionic is slightly faster
than the one included in libdex.

Here is the reference SHA-1 benchmark on Nexus S:

[libdex]
Rounds: 100000, size: 6250K, time: 1.28s,  speed: 4.768 MB/s

[bionic]
Rounds: 100000, size: 6250K, time: 1.184s, speed: 5.156 MB/s

(manually cherry-picked commit 55ac5b0a908b85c050f34dc603f62dd4b1fc4e9f)
[PATCH] Basic KSM Support

Be sure to add '#define MADV_MERGEABLE 12' to
bionic/libc/include/sys/mman.h so we can have a central place for this

parse the process memory map and inform madvise common HEAP/Stack
regions on fork from zygote

These then can be used by the kernel KSM module to re-join (copy on write)
pages between the various dalvik processes.

As is on a fully loaded system you can expect ~12MB to be indicated to be
scanned by KSM.. of this 10-15% will be saved; as such a recommend a very
slow scan until as any logic to stop scanning while sleeping will require
another process and remove all memory savings provided by this logic.

To activate on a KSM kernel (2min for full scan of ~16m and 1%CPU):

echo 4000 > /sys/kernel/mm/ksm/sleep_millisecs
echo 128 > /sys/kernel/mm/ksm/pages_to_scan
echo 1 > /sys/kernel/mm/ksm/run

Newer kernels only require the last line.

In future additional memory regions and kernel logic may improve this.

Change-Id: I271cbee74a1f02a89c34c6ee9006a4ea81360154
ThumbVFP.cpp:231:10: error: variable 'wide' set but not used [-Werror=unused-but-set-variable]

Change-Id: If6828c8cf8c2c4ab28567f6e39126e537d0020c1
Added missing <include sys/resource.h> for gcc-4.7.1

Patch Set 2: Added gcc version check as suggested by jeagoss

Change-Id: I7743d5fab8d026e12ad9e9ef4d4fbabe0a9bded7
Zygote: Restrict slave mountspace so Dalvik apps can mount system-wide volumes

Android 4.2 implements multi-user storage using per-process mount
namespaces.  Originally, everything under "/" (the entire filesystem
hierarchy) is marked as a recursive-slave mountspace for all zygote
instances.  This is done so that user-storage sandbox mounts under
/storage/emulated are hidden from other apps and users.

Unfortunately this means that any Dalvik app (actually, any program whose
clone/fork ancestry includes a Dalvik zygote, which is everything except
services spawned directly from init) cannot mount system-wide volumes.
Thus, apps like CifsManager are effectively broken in Android 4.2, since
its cifs mounts are only visible to the CifsManager app itself.  All other
apps see empty mountpoints instead of the mounted volume.  Furthermore,
Linux provides no provision for a process to "escape" a recursive-slave
mountspace in versions prior to Linux 3.8 (setns syscall).

Here, we restrict the slave mountspace to /storage (and, due to a possible
kernel bug, /mnt/shell/emulated) so that Dalvik apps can mount system-wide
volumes elsewhere (with appropriate permission, as in earlier versions of
Android), while retaining full multi-user storage compatibility.

This change requires that a tmpfs volume is mounted as /storage in init.rc.
If this volume is unavailable, then Zygote falls back to the previous
behavior of marking the entire filesystem hierarchy as slave.  It also
implicitly requires that EMULATED_STORAGE_TARGET is path-prefixed by (part
of the subhierarchy of) ANDROID_STORAGE, which is the typical case.
JIT: Combine shift & sub for monitor unlock.

Optimize monitor unlock for ARM Thumb2 JIT.
Monitor unlock performs a logical shift left
and sub, replace it with a sub capable of
performing the shift in the same instruction.

This improves performance for usecases involving code
executing in Dalvik.

Change-Id: Iaf062d750c3bc941926f3c3b8a64dc9c7984a477
Signed-off-by: Patrik Ryd <patrik.ryd@stericsson.com>

Conflicts:
	vm/compiler/codegen/arm/Thumb2/Gen.cpp
JIT: Hoist loop load operations above loop.

Hoists Dalvik frame load operations outside of loops, when possible.
This improves performance in most loops, and is noticable in many
applications.

Change-Id: Ibe42b509b50a13f19758fd923f31d703e33a51c6
Signed-off-by: Henrik Smiding <henrik.smiding@stericsson.com>
Signed-off-by: Patrik Ryd <patrik.ryd@stericsson.com>
JIT: Combine add with shift.

Optimize logical shift for ARM JIT.
Whenever logical shift is followed by an add,
try to replace it with an add capable of performing
the shift in the same instruction.

This improves performance for usecases
involving code executing in Dalvik.

Change-Id: I3cb807b6d6ef4b053a19e2703676a93a930eb963
Signed-off-by: Patrik Ryd <patrik.ryd@stericsson.com>
JIT: Combine add with shift and offset for array load & store.

Optimize long and double array load / store for ARM JIT.
Array load / store performs a logical shift left and add,
replace it with add capable of performing shift in the
same instruction.
Array load / store performs an add instead of using offset
for vldr/vstr. Replace the add and vldr/vstr with a vldr/vstr
that is capable of handling offset.

This improves performance for usecases involving long and double
array code execution in Dalvik. E.g WindowOrientation.

Change-Id: I90220c349ab936cdba1987139ccdf4dc31d7bbb0
Signed-off-by: Patrik Ryd <patrik.ryd@stericsson.com>

Conflicts:
	vm/compiler/codegen/arm/CodegenDriver.cpp
Small tweak

Conflicts:
	vm/Dvm.mk