Up Top

Memory allocation (& GC 処理) : メモリ確保以外の処理パスで発生する GC 処理 (java.lang.System.gc() 等)


概要(Summary)

メモリ確保以外の処理パスで発生する GC 処理 (java.lang.System.gc() 等)では, 最終的に CollectedHeap::collect() が呼び出される.

    ((cite: hotspot/src/share/vm/gc_interface/collectedHeap.hpp))
    class CollectedHeap : public CHeapObj {
    ...
      // Perform a collection of the heap; intended for use in implementing
      // "System.gc".  This probably implies as full a collection as the
      // "CollectedHeap" supports.
      virtual void collect(GCCause::Cause cause) = 0;

なお, この CollectedHeap::collect() メソッドは各サブクラスでオーバーライドされているため, 実際の GC 処理はそれぞれのサブクラス毎 (= GC アルゴリズム毎) に異なる.

処理の流れ (概要)(Execution Flows : Summary)

Java_java_lang_Runtime_gc()
-> JVM_GC()
   -> CollectedHeap::collect()
      -> (See: here, here, here and here for details)
JvmtiEnv::ForceGarbageCollection()
-> CollectedHeap::collect()
   -> (See: here, here, here and here for details)
(See: here for details)
-> jni_ReleasePrimitiveArrayCritical()
   -> GC_locker::unlock_critical()
      -> GC_locker::jni_unlock_slow()
         -> CollectedHeap::collect()
            -> (See: here, here, here and here for details)

(See: here for details)
-> jni_ReleaseStringCritical()
   -> GC_locker::unlock_critical()
      -> (同上)
InterfaceSupport::check_gc_alot()
-> InterfaceSupport::gc_alot()
   -> CollectedHeap::collect()
      -> (See: here, here, here and here for details)
(See: here for details)
-> before_exit()
   -> CollectedHeap::collect()
      -> (See: here, here, here and here for details)

備考(Notes)

どの処理パスから呼び出されたかは, CollectedHeap::collect() に渡される GCCause 引数で判断できる.

GCCause
GCCause::java_lang_systemgc java.lang.System.gc()
GCCause::jvmti_forcegc JVMTI の ForceGarbageCollection()
GCCause::_gc_locker JNI の ReleasePrimitiveArrayCritical() 及び ReleaseStringCritical()
GCCause::full_gcalot InterfaceSupport::gc_alot()
GCCause::scavengealot InterfaceSupport::gc_alot()
GCCause::allocationprofiler before_exit()

処理の流れ (詳細)(Execution Flows : Details)

Java_java_lang_Runtime_gc()

See: here for details

JVM_GC

See: here for details

JvmtiEnv::ForceGarbageCollection()

See: here for details

Subcategories


This document is available under the GNU GENERAL PUBLIC LICENSE Version 2.