OSDN Git Service

Trim arena maps during heap trim
authorMathieu Chartier <mathieuc@google.com>
Mon, 26 Oct 2015 17:21:14 +0000 (10:21 -0700)
committerMathieu Chartier <mathieuc@google.com>
Mon, 26 Oct 2015 17:31:33 +0000 (10:31 -0700)
Reduces RAM with verify-at-runtime.

Before:
9985 kB: .LinearAlloc

After:
6594 kB: .LinearAlloc

Change-Id: I4d0a0359cc3b55c924790f749eaeaa5cf55ad7df

runtime/gc/heap.cc

index 657fcb5..1d38525 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "art_field-inl.h"
 #include "base/allocator.h"
+#include "base/arena_allocator.h"
 #include "base/dumpable.h"
 #include "base/histogram-inl.h"
 #include "base/stl_util.h"
@@ -1258,11 +1259,11 @@ void Heap::DoPendingCollectorTransition() {
 }
 
 void Heap::Trim(Thread* self) {
+  Runtime* const runtime = Runtime::Current();
   if (!CareAboutPauseTimes()) {
     ATRACE_BEGIN("Deflating monitors");
     // Deflate the monitors, this can cause a pause but shouldn't matter since we don't care
     // about pauses.
-    Runtime* runtime = Runtime::Current();
     {
       ScopedSuspendAll ssa(__FUNCTION__);
       uint64_t start_time = NanoTime();
@@ -1274,6 +1275,10 @@ void Heap::Trim(Thread* self) {
   }
   TrimIndirectReferenceTables(self);
   TrimSpaces(self);
+  // Trim arenas that may have been used by JIT or verifier.
+  ATRACE_BEGIN("Trimming arena maps");
+  runtime->GetArenaPool()->TrimMaps();
+  ATRACE_END();
 }
 
 class TrimIndirectReferenceTableClosure : public Closure {