hotspot/src/share/vm/memory/space.cpp
// This version is lock-free.
inline HeapWord* ContiguousSpace::par_allocate_impl(size_t size,
HeapWord* const end_value) {
{- -------------------------------------------
(1) 空き領域(top と end の差)が size 引数分より小さければ NULL をリターンするだけ.
そうでなければ, Atomic::cmpxchg_ptr() で top 位置を size 引数分だけ前進させてメモリを確保する.
(なお, Atomic::cmpxchg_ptr() が失敗した場合は,
成功するか空き領域が size より小さくなるまで以下の do...while ループを繰り返す)
---------------------------------------- -}
do {
HeapWord* obj = top();
if (pointer_delta(end_value, obj) >= size) {
HeapWord* new_top = obj + size;
HeapWord* result = (HeapWord*)Atomic::cmpxchg_ptr(new_top, top_addr(), obj);
// result can be one of two:
// the old top value: the exchange succeeded
// otherwise: the new value of the top is returned.
if (result == obj) {
assert(is_aligned(obj) && is_aligned(new_top), "checking alignment");
return obj;
}
} else {
return NULL;
}
} while (true);
}
This document is available under the GNU GENERAL PUBLIC LICENSE Version 2.