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)
dalvik: fix a bug in redundant branch elimination
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>
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>
Excessive JNI: Dump HPROF dump.

This change would dump the heap memory status before we abort the
VM because of excessive JNI refs.

Change-Id: Iaf43ee0f2f40fc007e231dd10d1c6c6d95284896

Conflicts:
	vm/Jni.cpp
Add barriers for proper observation sequence.

Change-Id: I5c2ef043920fe60c92304cd2c8a857a805b6e9af
GC triggering performance optimizations

Copy the correct starting heap size at process init.
Interfaces to set GC/managed heap parameters.

Change-Id: I454b1985a3225d7dbdea9c5d4e6f0c9f5e24352e
dalvik/libdex: Change to -O2 if we're building with -O3

This is a workaround for an apparent gcc bug.
https://bugs.launchpad.net/linaro-android/+bug/948255

Signed-off-by: Bernhard Rosenkraenzer <Bernhard.Rosenkranzer@linaro.org>
dalvik/libdex: Don't reduce optimization level to -O2

Don't reduce optimization level to -O2: It's sufficient to disable
function inlining

Change-Id: Ie6d9978cf0bf0e49cfa296c09c4eba913f22c303
Signed-off-by: Bernhard Rosenkraenzer <Bernhard.Rosenkranzer@linaro.org>
dalvik: Fix for broswer-crashing bug

This applies the fix proposed by Olivier Cozette in
https://code.google.com/p/android/issues/detail?id=37561
and fixes our bug:
https://bugs.launchpad.net/linaro-android/+bug/978060

An alternative fix has been applied since, leaving this one in
as a comment for reference

Change-Id: I54336c83650c1628fd1bb689148bc1dd8843d7c6
Signed-off-by: Jon Medhurst <tixy@linaro.org>
Fix that getClasses() method returns protected classes

In publicOnly condition, Dalvik_java_lang_Class_getDeclaredClasses()
returns non-public(protected) declared class.
It is not match with documentation and the result of host java vm.
Protected inner declared class is generated as ‘public’ class via host javac.
But, has ‘protected’ constructor.
This fix add check constructor’s modifier to decide whether public or not.
Related issue: http://code.google.com/p/android/issues/detail?id=60394

Change-Id: Ib93f8f8b117129a9fc588f5884490308c26cb802
Dump hprof when app encounters Out of memory

These changes will only dump application hprof when debug
property "dalvik.debug.oom" is set to -1.

CRs-Fixed: 471156

Change-Id: I41fbbd5cdaa852cd5e8896186e9d3993688a9cb0
(cherry picked from commit eac7514a989e78b191fde100475b907427158b8d)
(cherry picked from commit 63a1141f9bb9fc58beacdde1e8e24df82fe6e000)
Reject dex files that attempt to use unspecified class access flags

Change-Id: Ib1ecf3dfe1856a9014c2e9b0d6a1725ba7617f98
Move verification of class access flags to libdex

Change-Id: I020a168cfff46e319b0bebb6c7477f0b4139c6de

Conflicts:
	libdex/DexSwapVerify.cpp
Removed excessive GC freed lines instead disable them

CM has introduced a method to disable GC freed lines by setting dalvik.vm.debug.alloc to 0. See http://review.cyanogenmod.org/#/c/45785/
Now I doubt whether this method is effective or even could make the dalvik performance worse than before.
This method checks the property of dalvik.vm.debug.alloc and convert the property value from string to integer everytime before dalvik writes debug line to logcat.
It is probably better to let dalvik to do only one operation to write debug line rather than to do two operations:
* Looking a property from a map that could contains hundred of properties
* Converting property value from string to integer
Since Heap.cpp is not a class, we cannot have a member variable that holds the dalvik.vm.debug.alloc value by reading it only once.

Remove the debug lines together with other information that are used in the debug line.

Change-Id: I164584bc3f53e5471a2e194125a867fd244a5774