8242036: G1 HeapRegionRemSet::_n_coarse_entries could be a bool

Reviewed-by: kbarrett, eosterlund, tschatzl, lkorinth
This commit is contained in:
Albert Yang 2020-07-27 12:59:32 +02:00 committed by Leo Korinth
parent 417e8e449d
commit af8c3b4a7e
3 changed files with 19 additions and 19 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -70,7 +70,7 @@ OtherRegionsTable::OtherRegionsTable(Mutex* m) :
_m(m), _m(m),
_num_occupied(0), _num_occupied(0),
_coarse_map(mtGC), _coarse_map(mtGC),
_n_coarse_entries(0), _has_coarse_entries(false),
_fine_grain_regions(NULL), _fine_grain_regions(NULL),
_n_fine_entries(0), _n_fine_entries(0),
_first_all_fine_prts(NULL), _first_all_fine_prts(NULL),
@ -261,19 +261,19 @@ PerRegionTable* OtherRegionsTable::delete_region_table(size_t& added_by_deleted)
guarantee(max != NULL, "Since _n_fine_entries > 0"); guarantee(max != NULL, "Since _n_fine_entries > 0");
guarantee(max_prev != NULL, "Since max != NULL."); guarantee(max_prev != NULL, "Since max != NULL.");
// Set the corresponding coarse bit. // Ensure the corresponding coarse bit is set.
size_t max_hrm_index = (size_t) max->hr()->hrm_index(); size_t max_hrm_index = (size_t) max->hr()->hrm_index();
if (_n_coarse_entries == 0) { if (Atomic::load(&_has_coarse_entries)) {
_coarse_map.at_put(max_hrm_index, true);
} else {
// This will lazily initialize an uninitialized bitmap // This will lazily initialize an uninitialized bitmap
_coarse_map.reinitialize(G1CollectedHeap::heap()->max_regions()); _coarse_map.reinitialize(G1CollectedHeap::heap()->max_regions());
assert(!_coarse_map.at(max_hrm_index), "No coarse entries");
_coarse_map.at_put(max_hrm_index, true); _coarse_map.at_put(max_hrm_index, true);
// Release store guarantees that the bitmap has initialized before any // Release store guarantees that the bitmap has initialized before any
// concurrent reader will ever see a non-zero value for _n_coarse_entries // concurrent reader will ever see _has_coarse_entries is true
// (when read with load_acquire) // (when read with load_acquire)
Atomic::release_store(&_n_coarse_entries, _n_coarse_entries + 1); Atomic::release_store(&_has_coarse_entries, true);
} else if (!_coarse_map.at(max_hrm_index)) {
_coarse_map.at_put(max_hrm_index, true);
_n_coarse_entries++;
} }
added_by_deleted = HeapRegion::CardsPerRegion - max_occ; added_by_deleted = HeapRegion::CardsPerRegion - max_occ;
@ -331,11 +331,11 @@ void OtherRegionsTable::clear() {
_first_all_fine_prts = _last_all_fine_prts = NULL; _first_all_fine_prts = _last_all_fine_prts = NULL;
_sparse_table.clear(); _sparse_table.clear();
if (_n_coarse_entries > 0) { if (Atomic::load(&_has_coarse_entries)) {
_coarse_map.clear(); _coarse_map.clear();
} }
_n_fine_entries = 0; _n_fine_entries = 0;
_n_coarse_entries = 0; Atomic::store(&_has_coarse_entries, false);
_num_occupied = 0; _num_occupied = 0;
} }
@ -362,11 +362,11 @@ bool OtherRegionsTable::contains_reference_locked(OopOrNarrowOopStar from) const
} }
} }
// A load_acquire on _n_coarse_entries - coupled with the release_store in // A load_acquire on _has_coarse_entries - coupled with the release_store in
// delete_region_table - guarantees we don't access _coarse_map before // delete_region_table - guarantees we don't access _coarse_map before
// it's been properly initialized. // it's been properly initialized.
bool OtherRegionsTable::is_region_coarsened(RegionIdx_t from_hrm_ind) const { bool OtherRegionsTable::is_region_coarsened(RegionIdx_t from_hrm_ind) const {
return Atomic::load_acquire(&_n_coarse_entries) > 0 && _coarse_map.at(from_hrm_ind); return Atomic::load_acquire(&_has_coarse_entries) && _coarse_map.at(from_hrm_ind);
} }
HeapRegionRemSet::HeapRegionRemSet(G1BlockOffsetTable* bot, HeapRegionRemSet::HeapRegionRemSet(G1BlockOffsetTable* bot,

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -74,9 +74,9 @@ class OtherRegionsTable {
size_t volatile _num_occupied; size_t volatile _num_occupied;
// These are protected by "_m". // These are protected by "_m".
CHeapBitMap _coarse_map; CHeapBitMap _coarse_map;
size_t _n_coarse_entries; bool volatile _has_coarse_entries;
static jint _n_coarsenings; static jint _n_coarsenings;
PerRegionTable** _fine_grain_regions; PerRegionTable** _fine_grain_regions;
size_t _n_fine_entries; size_t _n_fine_entries;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -73,7 +73,7 @@ inline void PerRegionTable::init(HeapRegion* hr, bool clear_links_to_all_list) {
template <class Closure> template <class Closure>
void OtherRegionsTable::iterate(Closure& cl) { void OtherRegionsTable::iterate(Closure& cl) {
if (_n_coarse_entries > 0) { if (Atomic::load(&_has_coarse_entries)) {
BitMap::idx_t cur = _coarse_map.get_next_one_offset(0); BitMap::idx_t cur = _coarse_map.get_next_one_offset(0);
while (cur != _coarse_map.size()) { while (cur != _coarse_map.size()) {
cl.next_coarse_prt((uint)cur); cl.next_coarse_prt((uint)cur);