8351167: ZGC: Lazily initialize livemap

Reviewed-by: sjohanss, eosterlund, tschatzl
This commit is contained in:
Joel Sikström 2025-03-17 07:55:44 +00:00
parent 63bf79183d
commit 2672c40bf1
4 changed files with 24 additions and 8 deletions

View File

@ -45,9 +45,16 @@ ZLiveMap::ZLiveMap(uint32_t size)
_live_bytes(0),
_segment_live_bits(0),
_segment_claim_bits(0),
_bitmap(bitmap_size(size, NumSegments)),
_bitmap_size(bitmap_size(size, NumSegments)),
_bitmap(0),
_segment_shift(log2i_exact(segment_size())) {}
void ZLiveMap::allocate_bitmap() {
if (_bitmap.size() != _bitmap_size) {
_bitmap.initialize(_bitmap_size, false /* clear */);
}
}
void ZLiveMap::reset(ZGenerationId id) {
ZGeneration* const generation = ZGeneration::generation(id);
const uint32_t seqnum_initializing = (uint32_t)-1;
@ -64,6 +71,10 @@ void ZLiveMap::reset(ZGenerationId id) {
_live_bytes = 0;
_live_objects = 0;
// We lazily initialize the bitmap the first time the page is
// marked, i.e. a bit is about to be set for the first time.
allocate_bitmap();
// Clear segment claimed/live bits
segment_live_bits().clear();
segment_claim_bits().clear();
@ -127,8 +138,10 @@ void ZLiveMap::reset_segment(BitMap::idx_t segment) {
void ZLiveMap::resize(uint32_t size) {
const size_t new_bitmap_size = bitmap_size(size, NumSegments);
if (_bitmap.size() != new_bitmap_size) {
_bitmap_size = new_bitmap_size;
_segment_shift = log2i_exact(segment_size());
if (_bitmap.size() != 0 && _bitmap.size() != new_bitmap_size) {
_bitmap.reinitialize(new_bitmap_size, false /* clear */);
_segment_shift = log2i_exact(segment_size());
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -42,6 +42,7 @@ private:
volatile size_t _live_bytes;
BitMap::bm_word_t _segment_live_bits;
BitMap::bm_word_t _segment_claim_bits;
size_t _bitmap_size;
ZBitMap _bitmap;
int _segment_shift;
@ -65,6 +66,8 @@ private:
bool claim_segment(BitMap::idx_t segment);
void allocate_bitmap();
void reset(ZGenerationId id);
void reset_segment(BitMap::idx_t segment);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -88,7 +88,7 @@ inline BitMap::idx_t ZLiveMap::next_live_segment(BitMap::idx_t segment) const {
}
inline BitMap::idx_t ZLiveMap::segment_size() const {
return _bitmap.size() / NumSegments;
return _bitmap_size / NumSegments;
}
inline BitMap::idx_t ZLiveMap::index_to_segment(BitMap::idx_t index) const {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -76,7 +76,7 @@ inline uint32_t ZPage::object_max_count() const {
return 1;
default:
return (uint32_t)(size() >> object_alignment_shift());
return checked_cast<uint32_t>(size() >> object_alignment_shift());
}
}