Simple heap trimming.

Change-Id: I8a94b637e64c6b5586db3c41b6e9230e7c8250c8
diff --git a/src/dalvik_system_VMRuntime.cc b/src/dalvik_system_VMRuntime.cc
index 76da622..feb7749 100644
--- a/src/dalvik_system_VMRuntime.cc
+++ b/src/dalvik_system_VMRuntime.cc
@@ -19,7 +19,9 @@
 #include "jni_internal.h"
 #include "object.h"
 #include "object_utils.h"
+#include "space.h"
 #include "thread.h"
+#include "thread_list.h"
 
 #include "JniConstants.h" // Last to avoid problems with LOG redefinition.
 #include "toStringArray.h"
@@ -131,6 +133,13 @@
   }
 }
 
+void VMRuntime_trimHeap(JNIEnv* env, jobject) {
+  ScopedThreadListLock thread_list_lock;
+  uint64_t start_ns = NanoTime();
+  Heap::GetAllocSpace()->Trim();
+  VLOG(gc) << "VMRuntime_trimHeap took " << PrettyDuration(NanoTime() - start_ns);
+}
+
 JNINativeMethod gMethods[] = {
   NATIVE_METHOD(VMRuntime, addressOf, "(Ljava/lang/Object;)J"),
   NATIVE_METHOD(VMRuntime, bootClassPath, "()Ljava/lang/String;"),
@@ -144,6 +153,7 @@
   NATIVE_METHOD(VMRuntime, properties, "()[Ljava/lang/String;"),
   NATIVE_METHOD(VMRuntime, setTargetSdkVersion, "(I)V"),
   NATIVE_METHOD(VMRuntime, startJitCompilation, "()V"),
+  NATIVE_METHOD(VMRuntime, trimHeap, "()V"),
   NATIVE_METHOD(VMRuntime, vmVersion, "()Ljava/lang/String;"),
 };