Basic KSM Support

[ported from ics commit]

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: If431bf77a21bc7358499678f83d84404e5db2738
Undecoded jobject leaking in through attachThread

picked from
https://android-review.googlesource.com/#/c/23058/
Don't malloc between fork and exec

This was causing hangs in DEX file loading.

Bug 5329833

picked from
https://github.com/android/platform_dalvik/commit/63cd4b08e623242066c63563bad3a9f414a2bd2d

Change-Id: Ie125c12013791156c9c7aa6b22ce90728b6f7fd5
Restore fp after calling JNI method in allstubs interpreter

The allstubs interpreter uses self->interpSave.curFrame as fp.
The invokeMethod native code sets self->interpSave.curFrame directly
effectively updating fp, so restore fp after the call has completed.

original Id: I0ffb15b71a48c2780251bbcd66e551bb0a52fe94
Signed-off-by: Chris Dearman <chris@mips.com>

Conflicts:

	vm/mterp/c/gotoTargets.c
	vm/mterp/out/InterpC-allstubs.c
	vm/mterp/out/InterpC-portdbg.c
	vm/mterp/out/InterpC-x86-atom.c
	vm/mterp/out/InterpC-x86.c
resolved:) and adapted to gingerbread

picked from
https://android-review.googlesource.com/#/c/31824/
Fix memory leaking in the VM

Doesn't correctly free the resources before return

original change id If7de75c1780f4240ee21bc536cc739de4729cd98

picked from:
https://android-review.googlesource.com/#/c/23248/
Don't pay for filename/line number lookup unless you need to.

picked from
https://github.com/android/platform_dalvik/commit/6cd72bd0161459e21d496b927967bd0ca6fe0f94
remove dependencies

Change-Id: I153d21a8456ef4a16bfe6777f153d28f57db9d19
Fixing a crash when doing lock profiling

This is a fix for a crash that can happen when logging Contention
events. This logging is performed when lock profiling is enabled.
This is by default enabled on userdebug builds. The crash happened
when a thread was being destroyed. When a thread is being
destroyed it is normal that the frame depth is zero, and thus the
current frame is null. logContentionEvent() requires that the
current frame is not null, or it will crash.

The fix is to check if the current frame is null, before calling
logContentionEvent().

original Id: I4c2b9ad94b663398645497fdffa1ec6f7ea86a51

picked from
https://android-review.googlesource.com/21321
cleanup redundant interfaces from iftable to avoid excessive LinearAlloc use

picked (without the tests) from
https://github.com/android/platform_dalvik/commit/a669206dc91323e664a84b2a4ca170ec0332c926

dependencies removal

Change-Id: Ice0a9672144bfe654622e4e8d0020a3f0053466d
Avoid method overriding if its super method is inaccessible.

A call to package private method could be redirected to subclass which
was not in the same package.
Modified vtable to retain virtual super methods which cannot be accessed.

This change affects vtable index in optimized dex.

Change-Id: I9cc7e309c305bca12e5061009c4245fb70014681
Signed-off-by: Im Sooin <ciecet@gmail.com>