hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp
// If could fit into free regions w/o expansion, try.
// Otherwise, if can expand, do so.
// Otherwise, if using ex regions might help, try with ex given back.
HeapWord* G1CollectedHeap::humongous_obj_allocate(size_t word_size) {
{- -------------------------------------------
(1) (assert)
---------------------------------------- -}
assert_heap_locked_or_at_safepoint(true /* should_be_vm_thread */);
{- -------------------------------------------
(1) (verify)
---------------------------------------- -}
verify_region_sets_optional();
{- -------------------------------------------
(1) (変数宣言など)
---------------------------------------- -}
size_t num_regions =
round_to(word_size, HeapRegion::GrainWords) / HeapRegion::GrainWords;
size_t x_size = expansion_regions();
size_t fs = _hrs->free_suffix();
{- -------------------------------------------
(1) G1CollectedHeap::humongous_obj_allocate_find_first() を呼んで,
メモリ確保用にフリーリストからの空きリージョンの取得を試みる.
---------------------------------------- -}
int first = humongous_obj_allocate_find_first(num_regions, word_size);
{- -------------------------------------------
(1) 失敗した場合は, ...#TODO であれば
G1CollectedHeap::expand() でヒープ領域を拡張した後で,
もう一度 G1CollectedHeap::humongous_obj_allocate_find_first() によるリージョンの取得を試みる.
---------------------------------------- -}
if (first == -1) {
// The only thing we can do now is attempt expansion.
if (fs + x_size >= num_regions) {
// If the number of regions we're trying to allocate for this
// object is at most the number of regions in the free suffix,
// then the call to humongous_obj_allocate_find_first() above
// should have succeeded and we wouldn't be here.
//
// We should only be trying to expand when the free suffix is
// not sufficient for the object _and_ we have some expansion
// room available.
assert(num_regions > fs, "earlier allocation should have succeeded");
if (expand((num_regions - fs) * HeapRegion::GrainBytes)) {
first = humongous_obj_allocate_find_first(num_regions, word_size);
// If the expansion was successful then the allocation
// should have been successful.
assert(first != -1, "this should have worked");
}
}
}
{- -------------------------------------------
(1) リージョンの取得が成功していれば,
G1CollectedHeap::humongous_obj_allocate_initialize_regions() を呼んで,
メモリ確保を試みる.
---------------------------------------- -}
HeapWord* result = NULL;
if (first != -1) {
result =
humongous_obj_allocate_initialize_regions(first, num_regions, word_size);
assert(result != NULL, "it should always return a valid result");
}
{- -------------------------------------------
(1) (verify)
---------------------------------------- -}
verify_region_sets_optional();
{- -------------------------------------------
(1) 結果をリターン
---------------------------------------- -}
return result;
}
This document is available under the GNU GENERAL PUBLIC LICENSE Version 2.