OSDN Git Service

Change native allocations to use growth limit.
authorMathieu Chartier <mathieuc@google.com>
Tue, 2 Sep 2014 23:21:01 +0000 (16:21 -0700)
committerMathieu Chartier <mathieuc@google.com>
Wed, 3 Sep 2014 00:01:23 +0000 (17:01 -0700)
Previously native allocation tracking used a GC footprint limit
which would cause GC in the allocating thread. This prevented
excessive growth of the heap but could cause jank due to GC in
the allocating thread. The new behavior is using the growth_limit
instead of the native footprint limit.

Bug: 17006948

Change-Id: I40f30af09bb25596a9f57fa50e2a155fb947b5fe

runtime/gc/heap.cc
runtime/gc/heap.h

index 8d614e1..ce914e5 100644 (file)
@@ -138,7 +138,6 @@ Heap::Heap(size_t initial_size, size_t growth_limit, size_t min_free, size_t max
       growth_limit_(growth_limit),
       max_allowed_footprint_(initial_size),
       native_footprint_gc_watermark_(initial_size),
-      native_footprint_limit_(2 * initial_size),
       native_need_to_run_finalization_(false),
       // Initially assume we perceive jank in case the process state is never updated.
       process_state_(kProcessStateJankPerceptible),
@@ -2833,7 +2832,6 @@ void Heap::UpdateMaxNativeFootprint() {
     target_size = native_size + min_free_;
   }
   native_footprint_gc_watermark_ = target_size;
-  native_footprint_limit_ = 2 * target_size - native_size;
 }
 
 collector::GarbageCollector* Heap::FindCollectorByGcType(collector::GcType gc_type) {
@@ -3105,14 +3103,14 @@ void Heap::RegisterNativeAllocation(JNIEnv* env, int bytes) {
 
     // The second watermark is higher than the gc watermark. If you hit this it means you are
     // allocating native objects faster than the GC can keep up with.
-    if (new_native_bytes_allocated > native_footprint_limit_) {
+    if (new_native_bytes_allocated > growth_limit_) {
       if (WaitForGcToComplete(kGcCauseForNativeAlloc, self) != collector::kGcTypeNone) {
         // Just finished a GC, attempt to run finalizers.
         RunFinalization(env);
         CHECK(!env->ExceptionCheck());
       }
       // If we still are over the watermark, attempt a GC for alloc and run finalizers.
-      if (new_native_bytes_allocated > native_footprint_limit_) {
+      if (new_native_bytes_allocated > growth_limit_) {
         CollectGarbageInternal(gc_type, kGcCauseForNativeAlloc, false);
         RunFinalization(env);
         native_need_to_run_finalization_ = false;
index d2cc350..a0fcf53 100644 (file)
@@ -887,9 +887,6 @@ class Heap {
   // The watermark at which a concurrent GC is requested by registerNativeAllocation.
   size_t native_footprint_gc_watermark_;
 
-  // The watermark at which a GC is performed inside of registerNativeAllocation.
-  size_t native_footprint_limit_;
-
   // Whether or not we need to run finalizers in the next native allocation.
   bool native_need_to_run_finalization_;