8335925: Serial: Move allocation API from Generation to subclasses

Reviewed-by: gli, kbarrett, iwalulya
This commit is contained in:
Albert Mingkun Yang 2024-08-07 07:48:05 +00:00
parent 66286b25a1
commit 41f784fe63
7 changed files with 22 additions and 54 deletions

View File

@ -572,11 +572,6 @@ HeapWord* DefNewGeneration::block_start(const void* p) const {
return block_start_const(to(), p);
}
HeapWord* DefNewGeneration::expand_and_allocate(size_t size, bool is_tlab) {
// We don't attempt to expand the young generation (but perhaps we should.)
return allocate(size, is_tlab);
}
void DefNewGeneration::adjust_desired_tenuring_threshold() {
// Set the desired survivor size to half the real survivor space
size_t const survivor_capacity = to()->capacity() / HeapWordSize;
@ -865,7 +860,7 @@ const char* DefNewGeneration::name() const {
return "def new generation";
}
HeapWord* DefNewGeneration::allocate(size_t word_size, bool is_tlab) {
HeapWord* DefNewGeneration::allocate(size_t word_size) {
// This is the slow-path allocation for the DefNewGeneration.
// Most allocations are fast-path in compiled code.
// We try to allocate from the eden. If that works, we are happy.
@ -875,8 +870,7 @@ HeapWord* DefNewGeneration::allocate(size_t word_size, bool is_tlab) {
return result;
}
HeapWord* DefNewGeneration::par_allocate(size_t word_size,
bool is_tlab) {
HeapWord* DefNewGeneration::par_allocate(size_t word_size) {
return eden()->par_allocate(word_size);
}

View File

@ -209,9 +209,9 @@ class DefNewGeneration: public Generation {
return result;
}
HeapWord* allocate(size_t word_size, bool is_tlab);
HeapWord* par_allocate(size_t word_size, bool is_tlab);
// Allocate requested size or return null; single-threaded and lock-free versions.
HeapWord* allocate(size_t word_size);
HeapWord* par_allocate(size_t word_size);
void gc_epilogue(bool full);
@ -227,8 +227,6 @@ class DefNewGeneration: public Generation {
bool collect(bool clear_all_soft_refs);
HeapWord* expand_and_allocate(size_t size, bool is_tlab);
oop copy_to_survivor_space(oop old);
uint tenuring_threshold() { return _tenuring_threshold; }

View File

@ -103,20 +103,6 @@ class Generation: public CHeapObj<mtGC> {
return _reserved.contains(p);
}
// Allocate and returns a block of the requested size, or returns "null".
// Assumes the caller has done any necessary locking.
virtual HeapWord* allocate(size_t word_size, bool is_tlab) = 0;
// Like "allocate", but performs any necessary locking internally.
virtual HeapWord* par_allocate(size_t word_size, bool is_tlab) = 0;
// Perform a heap collection, attempting to create (at least) enough
// space to support an allocation of the given "word_size". If
// successful, perform the allocation and return the resulting
// "oop" (initializing the allocated block). If the allocation is
// still unsuccessful, return "null".
virtual HeapWord* expand_and_allocate(size_t word_size, bool is_tlab) = 0;
// Printing
virtual const char* name() const = 0;
virtual const char* short_name() const = 0;

View File

@ -156,7 +156,7 @@ void SerialHeap::safepoint_synchronize_end() {
HeapWord* SerialHeap::allocate_loaded_archive_space(size_t word_size) {
MutexLocker ml(Heap_lock);
return old_gen()->allocate(word_size, false /* is_tlab */);
return old_gen()->allocate(word_size);
}
void SerialHeap::complete_loaded_archive_space(MemRegion archive_space) {
@ -292,11 +292,12 @@ bool SerialHeap::should_try_older_generation_allocation(size_t word_size) const
HeapWord* SerialHeap::expand_heap_and_allocate(size_t size, bool is_tlab) {
HeapWord* result = nullptr;
if (_old_gen->should_allocate(size, is_tlab)) {
result = _old_gen->expand_and_allocate(size, is_tlab);
result = _old_gen->expand_and_allocate(size);
}
if (result == nullptr) {
if (_young_gen->should_allocate(size, is_tlab)) {
result = _young_gen->expand_and_allocate(size, is_tlab);
// Young-gen is not expanded.
result = _young_gen->allocate(size);
}
}
assert(result == nullptr || is_in_reserved(result), "result not in heap");
@ -314,7 +315,7 @@ HeapWord* SerialHeap::mem_allocate_work(size_t size,
// First allocation attempt is lock-free.
DefNewGeneration *young = _young_gen;
if (young->should_allocate(size, is_tlab)) {
result = young->par_allocate(size, is_tlab);
result = young->par_allocate(size);
if (result != nullptr) {
assert(is_in_reserved(result), "result not in heap");
return result;
@ -406,14 +407,14 @@ HeapWord* SerialHeap::attempt_allocation(size_t size,
HeapWord* res = nullptr;
if (_young_gen->should_allocate(size, is_tlab)) {
res = _young_gen->allocate(size, is_tlab);
res = _young_gen->allocate(size);
if (res != nullptr || first_only) {
return res;
}
}
if (_old_gen->should_allocate(size, is_tlab)) {
res = _old_gen->allocate(size, is_tlab);
res = _old_gen->allocate(size);
}
return res;

View File

@ -397,20 +397,19 @@ oop TenuredGeneration::allocate_for_promotion(oop obj, size_t obj_size) {
#endif // #ifndef PRODUCT
// Allocate new object.
HeapWord* result = allocate(obj_size, false);
HeapWord* result = allocate(obj_size);
if (result == nullptr) {
// Promotion of obj into gen failed. Try to expand and allocate.
result = expand_and_allocate(obj_size, false);
result = expand_and_allocate(obj_size);
}
return cast_to_oop<HeapWord*>(result);
}
HeapWord*
TenuredGeneration::expand_and_allocate(size_t word_size, bool is_tlab) {
assert(!is_tlab, "TenuredGeneration does not support TLAB allocation");
TenuredGeneration::expand_and_allocate(size_t word_size) {
expand(word_size*HeapWordSize, _min_heap_delta_bytes);
return allocate(word_size, is_tlab);
return allocate(word_size);
}
void TenuredGeneration::assert_correct_size_change_locking() {

View File

@ -130,10 +130,12 @@ public:
void complete_loaded_archive_space(MemRegion archive_space);
inline void update_for_block(HeapWord* start, HeapWord* end);
virtual inline HeapWord* allocate(size_t word_size, bool is_tlab);
virtual inline HeapWord* par_allocate(size_t word_size, bool is_tlab);
// Allocate and returns a block of the requested size, or returns "null".
// Assumes the caller has done any necessary locking.
inline HeapWord* allocate(size_t word_size);
HeapWord* expand_and_allocate(size_t size, bool is_tlab);
// Expand the old-gen then invoke allocate above.
HeapWord* expand_and_allocate(size_t size);
void gc_prologue();
void gc_epilogue();

View File

@ -48,9 +48,7 @@ inline void TenuredGeneration::update_for_block(HeapWord* start, HeapWord* end)
_bts->update_for_block(start, end);
}
HeapWord* TenuredGeneration::allocate(size_t word_size,
bool is_tlab) {
assert(!is_tlab, "TenuredGeneration does not support TLAB allocation");
HeapWord* TenuredGeneration::allocate(size_t word_size) {
HeapWord* res = _the_space->allocate(word_size);
if (res != nullptr) {
_bts->update_for_block(res, res + word_size);
@ -58,14 +56,4 @@ HeapWord* TenuredGeneration::allocate(size_t word_size,
return res;
}
HeapWord* TenuredGeneration::par_allocate(size_t word_size,
bool is_tlab) {
assert(!is_tlab, "TenuredGeneration does not support TLAB allocation");
HeapWord* res = _the_space->par_allocate(word_size);
if (res != nullptr) {
_bts->update_for_block(res, res + word_size);
}
return res;
}
#endif // SHARE_GC_SERIAL_TENUREDGENERATION_INLINE_HPP