ART GC

Java堆
  • Image Space: 存放一些预加载的类
  • Zygote Space: 对应Davlik的Zygote堆
  • Allocation Space: 对应Dalvik的Active堆
  • Large Object Space: 用来分配一些大对象
GC的类型
  • kGcCauseForAlloc: 内存不够的情况下引起的GC
  • kGcCauseBackground: 内存达到一定的阀值的时候引发的GC
  • kGcCauseExplicit: System.gc显示调用的GC
// heap.cc: CollectGarbageInternal
collector::GcType Heap::CollectGarbageInternal(collector::GcType gc_type,
                                               GcCause gc_cause,
                                               bool clear_soft_references) {
  collector->Run(gc_cause, clear_soft_references || runtime->IsZygote());
  RequestTrim(self);
  // Grow the heap so that we know when to perform the next GC.
  GrowForUtilization(collector, bytes_allocated_before_gc);
  Dbg::GcDidFinish();
  return gc_type;
}
Foreground GC和Background GC切换
// ActivityThread.scheduleLaunchActivity
public final void scheduleLaunchActivity(Intent intent, IBinder token, int ident) {
            updateProcessState(procState, false);

            sendMessage(H.LAUNCH_ACTIVITY, r);
        }
// heap.cc: UpdateProcessState
void Heap::UpdateProcessState(ProcessState old_process_state, ProcessState new_process_state) {
  if (old_process_state != new_process_state) {
    const bool jank_perceptible = new_process_state == kProcessStateJankPerceptible;
    if (jank_perceptible) {
      RequestCollectorTransition(foreground_collector_type_, 0);
    } else {
      RequestCollectorTransition(background_collector_type_,
                                 kIsDebugBuild ? 0 : kCollectorTransitionWait);
    }
  }
}
相关资料
  • Android GC 原理探究
  • 老罗讲ART GC

你可能感兴趣的:(ART GC)