Skip to content

Commit

Permalink
Some cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
kstefanj committed Mar 18, 2024
1 parent 470ea48 commit 4655a16
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 41 deletions.
63 changes: 26 additions & 37 deletions src/hotspot/share/gc/z/zVirtualMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,48 +141,31 @@ size_t ZVirtualMemoryManager::reserve_discontiguous(size_t size) {
return reserved;
}

void ZSizedMemoryManager::initialize(zoffset &start, size_t &size) {
// Add a segment to the manager
size_t to_add = MIN2(size, (_capacity - _size));
free(zoffset(start), to_add);

log_trace(gc, heap)("Initial free segment: " PTR_FORMAT " %zuM", untype(start), to_add / M);
// Update the state
_size += to_add;
_limit = zoffset_end(untype(start) + to_add);

// Update paramters for use by next manager, but only advance start
// when there is any size left to handle.
size -= to_add;
start = size == 0 ? start : (start + to_add);
}
void ZSizedMemoryManager::initialize(ZMemoryManager& reserved) {
do {
size_t size_to_add = _capacity - _size;
size_t size_added = 0;

// Allocated a segment from the reservation to be added to this manager
zoffset start = reserved.alloc_at_most(size_to_add, &size_added);
if (start == zoffset(UINTPTR_MAX)) {
log_trace(gc, heap)("Limited address range. Manager lack " SIZE_FORMAT "M of address space", size_to_add / M);
return;
}

void ZVirtualMemoryManager::distribute_reserved_segments() {
ZMemory* segment = _reserved_segments.remove_first();
while (segment != nullptr) {
distribute_reserved_segment(segment->start(), segment->size());
delete segment;
segment = _reserved_segments.remove_first();
}
// Add segment to this manager
free(start, size_added);
_size += size_added;
_limit = zoffset_end(untype(start) + size_added);
log_trace(gc, heap)("Virtual address range initialized at: " PTR_FORMAT " %zuM", untype(ZOffset::address_unsafe(start)), size_added / M);
} while (!is_complete());
}

void ZVirtualMemoryManager::distribute_reserved_segment(zoffset start, size_t size) {
size_t current_size = size;
zoffset current_offset = start;
// First initialize the manager used for small page allocations.
if (!_small_manager.is_initialized()) {
_small_manager.initialize(current_offset, current_size);
}

// If there is more left of this segment, add it to the shared manager
// handling medium and large page allocations.
if (current_size > 0) {
assert(_small_manager.is_initialized(), "Should fully initialize small first");
_shared_manager.initialize(current_offset, current_size);
}
void ZVirtualMemoryManager::distribute_reserved_segments() {
_small_manager.initialize(_reserved_segments);
_shared_manager.initialize(_reserved_segments);
}


bool ZVirtualMemoryManager::reserve_contiguous(zoffset start, size_t size) {
assert(is_aligned(size, ZGranuleSize), "Must be granule aligned " SIZE_FORMAT_X, size);

Expand All @@ -200,6 +183,7 @@ bool ZVirtualMemoryManager::reserve_contiguous(zoffset start, size_t size) {
// Make the address range free and keep it in the reserved
// segment manager for later distribution.
_reserved_segments.free(start, size);
log_trace(gc, heap)("Virtual address range reserved at: " PTR_FORMAT " %zuM", untype(addr), size / M);

return true;
}
Expand Down Expand Up @@ -270,6 +254,11 @@ ZVirtualMemory ZVirtualMemoryManager::alloc(size_t size, bool force_low_address)
start = _small_manager.alloc(size);
} else {
start = _shared_manager.alloc(size);
if (start == zoffset(UINTPTR_MAX) && !_shared_manager.is_complete()) {
// In the case of a limited address space allow larger allocations
// through the small manager.
start = _small_manager.alloc(size);
}
}

if (start == zoffset(UINTPTR_MAX)) {
Expand Down
5 changes: 2 additions & 3 deletions src/hotspot/share/gc/z/zVirtualMemory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class ZSizedMemoryManager : public ZMemoryManager {
zoffset_end _limit;
public:
ZSizedMemoryManager(size_t capacity);
void initialize(zoffset& start, size_t& size);
bool is_initialized() const;
void initialize(ZMemoryManager& reserved);
bool is_complete() const;
zoffset_end limit() const;
};

Expand All @@ -81,7 +81,6 @@ class ZVirtualMemoryManager {
bool reserve(size_t max_capacity);

void distribute_reserved_segments();
void distribute_reserved_segment(zoffset start, size_t size);

DEBUG_ONLY(size_t force_reserve_discontiguous(size_t size);)

Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/z/zVirtualMemory.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ inline zoffset_end ZSizedMemoryManager::limit() const {
return _limit;
}

inline bool ZSizedMemoryManager::is_initialized() const {
inline bool ZSizedMemoryManager::is_complete() const {
return _size == _capacity;
}

Expand Down

0 comments on commit 4655a16

Please sign in to comment.