メモリ確保の試みが全て失敗した場合, 最終的に CollectedHeap::mem_allocate() が呼び出される (See: here for details). GenCollectedHeap は CollectedHeap::mem_allocate() をオーバーライドしているので, 実際に呼び出されるのは GenCollectedHeap::mem_allocate() になる.
GenCollectedHeap::mem_allocate() 内では GC を実行してでも確保が試みられる. GC 処理は VM_GenCollectForAllocation クラスが Generation::collect() を呼び出すことで行われる. なお, Generation::collect() は Generation クラスの各サブクラスによってオーバーライドされているため, GC 処理は Generation 毎に異なる.
GenCollectedHeap::mem_allocate()
-> GenCollectorPolicy::mem_allocate_work()
-> (メモリ確保が成功するか, あるいは成功しないと判断するまで, 以下の処理をループ)
(1) young generation からの確保を試みる. 成功すれば結果をリターン
-> Generation::par_allocate() (<= 各 Generation クラスでオーバーライドされている)
-> (See: here for details)
(1) 各世代からの確保を試みる. 成功すれば結果をリターン
-> GenCollectedHeap::attempt_allocation()
-> Generation::allocate() (<= 各 Generation クラスでオーバーライドされている)
-> (See: here for details)
(1) ヒープを拡張しての確保を試みる. 成功すれば結果をリターン
-> GenCollectorPolicy::expand_heap_and_allocate()
-> OneContigSpaceCardGeneration::expand_and_allocate()
-> OneContigSpaceCardGeneration::expand()
-> CardGeneration::expand()
-> CardGeneration::grow_by()
(1) GC を行ってから確保を試みる. 成功すれば結果をリターン
-> VM_GenCollectForAllocation::doit()
-> GenCollectedHeap::satisfy_failed_allocation()
-> GenCollectorPolicy::satisfy_failed_allocation()
-> (1) Minor GC 又は Major GC を実行する
-> GenCollectedHeap::do_collection()
-> GenCollectedHeap::gc_prologue()
-> BiasedLocking::preserve_marks()
-> Generation::collect() (<= 各 Generation クラスでオーバーライドされている)
-> (See: here and here for details)
-> GenCollectedHeap::gc_epilogue()
-> BiasedLocking::restore_marks()
(1) 各世代からの確保を試みる. 成功すれば結果をリターン
-> GenCollectedHeap::attempt_allocation()
(1) ヒープを拡張しての確保を試みる. 成功すれば結果をリターン
-> GenCollectorPolicy::expand_heap_and_allocate()
(1) Full GC を実行する
-> GenCollectedHeap::do_collection()
-> (同上)
(1) 各世代からの確保を試みる. 成功すれば結果をリターン
-> GenCollectedHeap::attempt_allocation()
See: here for details
See: here for details
See: here for details
(#Under Construction)
See: here for details
See: here for details
See: here for details
(#Under Construction) See: here for details
(#Under Construction)
(#Under Construction)
(#Under Construction)
See: here for details
(See: here for details)
(#Under Construction)
(#Under Construction)
See: here for details
This document is available under the GNU GENERAL PUBLIC LICENSE Version 2.