slow-path の処理は, 以下のどれかのメソッドを経由し, 最終的に CollectedHeap::common_mem_allocate_init() にたどり着く. その中で確保処理が行われる.
CollectedHeap::common_mem_allocate_init() での確保処理は, 大別すると以下の2つからなる.
TLAB からの確保 (See: here for details)
CollectedHeap::mem_allocate() による確保 (See: here for details)
CollectedHeap::mem_allocate() は, 必要があれば Garbage Collection を実行してメモリ確保を行うメソッド. なお, このメソッドは各 CollectedHeap のサブクラスでオーバーライドされているため, 実際の処理は GC アルゴリズム毎に異なる.
(正確には arrayKlass::multi_allocate() 自体は空のメソッドで, 実際にはそれをサブクラスがオーバーライドしたものが呼び出される. より具体的には, objArrayKlass::multi_allocate() または typeArrayKlass::multi_allocate() が呼び出される)
(多次元配列は, 最後の一段以外は参照の配列なので, objArrayKlass::multi_allocate() 内部で必要な次元数分だけ objArrayKlass::allocate() による確保が行われる. 正確には, objArrayKlass::multi_allocate() の再起呼び出しで確保が行われる. プリミティブ型の場合は最後の一段だけは typeArrayKlass::multi_allocate() になるが, typeArrayKlass::multi_allocate() も中身は typeArrayKlass::allocate() を呼ぶだけ)
-> instanceKlass::allocate_instance()
-> CollectedHeap::obj_allocate()
-> CollectedHeap::common_mem_allocate_init()
-> CollectedHeap::common_mem_allocate_noinit()
-> (1) 以下の2つ(UseTLAB オプションが指定されてなければ1つ)の方法でメモリの確保を試みる.
-> CollectedHeap::allocate_from_tlab() (<= UseTLAB オプションが指定されている場合にのみ実行)
-> ThreadLocalAllocBuffer::allocate() (<= 現在の TLAB からメモリを確保)
-> CollectedHeap::allocate_from_tlab_slow() (<= もし現在の TLAB で足りなければ, これで新しい TLAB を確保)
-> ThreadLocalAllocBuffer::compute_size()
-> CollectedHeap::allocate_new_tlab() (<= 実際にはこのメソッドの中身は各サブクラスでオーバーライドされている)
-> (See: here, here, here and here for details)
-> CollectedHeap::mem_allocate() (<= 実際にはこのメソッドの中身は各サブクラスでオーバーライドされている)
-> (See: here, here, here and here for details)
(1) 以上の二つで確保できなければ OutOfMemoryError を送出する.
(なお, -XX:+HeapDumpOnOutOfMemoryError オプションや
-XX:OnOutOfMemoryError オプション,
および JVMTI の ResourceExhausted の処理も行う)
-> report_java_out_of_memory()
-> JvmtiExport::post_resource_exhausted()
-> THROW_OOP_0()
-> CollectedHeap::init_obj() で, 確保したメモリのヘッダー部以外の領域を 0 クリアする
-> CollectedHeap::post_allocation_setup_obj() でヘッダー部を初期化する. (また, ここが JVMTI や DTrace, JMM のフック点でもある)
-> oopFactory::new_typeArray()
-> typeArrayKlass::allocate()
-> CollectedHeap::array_allocate() または CollectedHeap::large_typearray_allocate()
-> CollectedHeap::common_mem_allocate_init()
-> 同上
-> CollectedHeap::post_allocation_setup_array() でヘッダー部を初期化する. (また, ここが JVMTI や DTrace, JMM のフック点でもある)
-> oopFactory::new_objArray()
-> arrayKlass::allocate_arrayArray() または instanceKlass::allocate_objArray()
-> CollectedHeap::array_allocate()
-> 同上
-> objArrayKlass::multi_allocate() or typeArrayKlass::multi_allocate()
-> objArrayKlass::allocate()
-> CollectedHeap::array_allocate()
-> 同上
-> typeArrayKlass::allocate()
-> 同上
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
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
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
This document is available under the GNU GENERAL PUBLIC LICENSE Version 2.