Skip to content

8351167: ZGC: Lazily initialize livemap #23907

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/hotspot/share/gc/z/zLiveMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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());
}
}
5 changes: 4 additions & 1 deletion src/hotspot/share/gc/z/zLiveMap.hpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;

Expand All @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/gc/z/zLiveMap.inline.hpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/gc/z/zPage.inline.hpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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());
}
}

Expand Down