diff --git a/src/hotspot/share/gc/z/zLiveMap.cpp b/src/hotspot/share/gc/z/zLiveMap.cpp index cc7271f99a7dc..ef125af9c2e8f 100644 --- a/src/hotspot/share/gc/z/zLiveMap.cpp +++ b/src/hotspot/share/gc/z/zLiveMap.cpp @@ -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()); } } diff --git a/src/hotspot/share/gc/z/zLiveMap.hpp b/src/hotspot/share/gc/z/zLiveMap.hpp index 7c18e1db06096..9f6514b574f7a 100644 --- a/src/hotspot/share/gc/z/zLiveMap.hpp +++ b/src/hotspot/share/gc/z/zLiveMap.hpp @@ -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 @@ class ZLiveMap { 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 @@ class ZLiveMap { bool claim_segment(BitMap::idx_t segment); + void allocate_bitmap(); + void reset(ZGenerationId id); void reset_segment(BitMap::idx_t segment); diff --git a/src/hotspot/share/gc/z/zLiveMap.inline.hpp b/src/hotspot/share/gc/z/zLiveMap.inline.hpp index 9a5529dac0428..fdbbdfaba0e08 100644 --- a/src/hotspot/share/gc/z/zLiveMap.inline.hpp +++ b/src/hotspot/share/gc/z/zLiveMap.inline.hpp @@ -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 { diff --git a/src/hotspot/share/gc/z/zPage.inline.hpp b/src/hotspot/share/gc/z/zPage.inline.hpp index d8ecad571907c..5d476f273d3e2 100644 --- a/src/hotspot/share/gc/z/zPage.inline.hpp +++ b/src/hotspot/share/gc/z/zPage.inline.hpp @@ -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(size() >> object_alignment_shift()); } }