src/hotspot/share/gc/g1/sparsePRT.cpp
author tschatzl
Wed, 28 Nov 2018 11:06:58 +0100
changeset 52716 877dd2b0f36c
parent 52347 14ef0f74667b
child 55510 3e31a8beaae4
child 58678 9cf78a70fa4f
permissions -rw-r--r--
8213996: Remove one of the SparsePRT entry tables Summary: Remove unused functionality in SparsePRT Reviewed-by: shade, sjohanss
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     1
/*
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 47634
diff changeset
     2
 * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     4
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     8
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    13
 * accompanied this code).
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    14
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4902
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4902
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4902
diff changeset
    21
 * questions.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    22
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    23
 */
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6983
diff changeset
    25
#include "precompiled.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 27880
diff changeset
    26
#include "gc/g1/heapRegion.hpp"
38271
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
    27
#include "gc/g1/heapRegionBounds.inline.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 27880
diff changeset
    28
#include "gc/g1/heapRegionRemSet.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 27880
diff changeset
    29
#include "gc/g1/sparsePRT.hpp"
49455
848864ed9b17 8199604: Rename CardTableModRefBS to CardTableBarrierSet
eosterlund
parents: 49164
diff changeset
    30
#include "gc/shared/cardTableBarrierSet.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 27880
diff changeset
    31
#include "gc/shared/space.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6983
diff changeset
    32
#include "memory/allocation.inline.hpp"
40655
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 38271
diff changeset
    33
#include "runtime/atomic.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6983
diff changeset
    34
#include "runtime/mutexLocker.hpp"
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    35
38271
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
    36
// Check that the size of the SparsePRTEntry is evenly divisible by the maximum
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
    37
// member type to avoid SIGBUS when accessing them.
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
    38
STATIC_ASSERT(sizeof(SparsePRTEntry) % sizeof(int) == 0);
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    39
38271
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
    40
void SparsePRTEntry::init(RegionIdx_t region_ind) {
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
    41
  // Check that the card array element type can represent all cards in the region.
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
    42
  // Choose a large SparsePRTEntry::card_elem_t (e.g. CardIdx_t) if required.
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
    43
  assert(((size_t)1 << (sizeof(SparsePRTEntry::card_elem_t) * BitsPerByte)) *
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 47634
diff changeset
    44
         G1CardTable::card_size >= HeapRegionBounds::max_size(), "precondition");
38271
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
    45
  assert(G1RSetSparseRegionEntries > 0, "precondition");
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
    46
  _region_ind = region_ind;
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
    47
  _next_index = RSHashTable::NullEntry;
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
    48
  _next_null = 0;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    49
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    50
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
    51
bool SparsePRTEntry::contains_card(CardIdx_t card_index) const {
38271
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
    52
  for (int i = 0; i < num_valid_cards(); i++) {
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
    53
    if (card(i) == card_index) {
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
    54
      return true;
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
    55
    }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    56
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    57
  return false;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    58
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    59
38271
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
    60
SparsePRTEntry::AddCardResult SparsePRTEntry::add_card(CardIdx_t card_index) {
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
    61
  for (int i = 0; i < num_valid_cards(); i++) {
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
    62
    if (card(i) == card_index) {
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
    63
      return found;
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
    64
    }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    65
  }
38271
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
    66
  if (num_valid_cards() < cards_num() - 1) {
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
    67
    _cards[_next_null] = (card_elem_t)card_index;
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
    68
    _next_null++;
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
    69
    return added;
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
    70
   }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    71
  // Otherwise, we're full.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    72
  return overflow;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    73
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    74
38271
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
    75
void SparsePRTEntry::copy_cards(card_elem_t* cards) const {
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
    76
  memcpy(cards, _cards, cards_num() * sizeof(card_elem_t));
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    77
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    78
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    79
void SparsePRTEntry::copy_cards(SparsePRTEntry* e) const {
38271
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
    80
  copy_cards(e->_cards);
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
    81
  assert(_next_null >= 0, "invariant");
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
    82
  assert(_next_null <= cards_num(), "invariant");
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
    83
  e->_next_null = _next_null;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    84
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    85
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    86
// ----------------------------------------------------------------------
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    87
38269
d18cab031e64 8155721: Sparse remset wastes half of entry memory
tschatzl
parents: 33741
diff changeset
    88
float RSHashTable::TableOccupancyFactor = 0.5f;
d18cab031e64 8155721: Sparse remset wastes half of entry memory
tschatzl
parents: 33741
diff changeset
    89
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    90
RSHashTable::RSHashTable(size_t capacity) :
51332
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 49455
diff changeset
    91
  _num_entries(0),
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 49455
diff changeset
    92
  _capacity(capacity),
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 49455
diff changeset
    93
  _capacity_mask(capacity-1),
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 49455
diff changeset
    94
  _occupied_entries(0),
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 49455
diff changeset
    95
  _occupied_cards(0),
38269
d18cab031e64 8155721: Sparse remset wastes half of entry memory
tschatzl
parents: 33741
diff changeset
    96
  _entries(NULL),
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12381
diff changeset
    97
  _buckets(NEW_C_HEAP_ARRAY(int, capacity, mtGC)),
51332
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 49455
diff changeset
    98
  _free_region(0),
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 49455
diff changeset
    99
  _free_list(NullEntry)
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   100
{
38269
d18cab031e64 8155721: Sparse remset wastes half of entry memory
tschatzl
parents: 33741
diff changeset
   101
  _num_entries = (capacity * TableOccupancyFactor) + 1;
d18cab031e64 8155721: Sparse remset wastes half of entry memory
tschatzl
parents: 33741
diff changeset
   102
  _entries = (SparsePRTEntry*)NEW_C_HEAP_ARRAY(char, _num_entries * SparsePRTEntry::size(), mtGC);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   103
  clear();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   104
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   105
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   106
RSHashTable::~RSHashTable() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   107
  if (_entries != NULL) {
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 26316
diff changeset
   108
    FREE_C_HEAP_ARRAY(SparsePRTEntry, _entries);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   109
    _entries = NULL;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   110
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   111
  if (_buckets != NULL) {
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 26316
diff changeset
   112
    FREE_C_HEAP_ARRAY(int, _buckets);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   113
    _buckets = NULL;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   114
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   115
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   116
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   117
void RSHashTable::clear() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   118
  _occupied_entries = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   119
  _occupied_cards = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   120
  guarantee(_entries != NULL, "INV");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   121
  guarantee(_buckets != NULL, "INV");
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   122
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   123
  guarantee(_capacity <= ((size_t)1 << (sizeof(int)*BitsPerByte-1)) - 1,
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   124
                "_capacity too large");
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   125
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   126
  // This will put -1 == NullEntry in the key field of all entries.
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 41283
diff changeset
   127
  memset((void*)_entries, NullEntry, _num_entries * SparsePRTEntry::size());
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 41283
diff changeset
   128
  memset((void*)_buckets, NullEntry, _capacity * sizeof(int));
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   129
  _free_list = NullEntry;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   130
  _free_region = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   131
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   132
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   133
bool RSHashTable::add_card(RegionIdx_t region_ind, CardIdx_t card_index) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   134
  SparsePRTEntry* e = entry_for_region_ind_create(region_ind);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   135
  assert(e != NULL && e->r_ind() == region_ind,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   136
         "Postcondition of call above.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   137
  SparsePRTEntry::AddCardResult res = e->add_card(card_index);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   138
  if (res == SparsePRTEntry::added) _occupied_cards++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   139
  assert(e->num_valid_cards() > 0, "Postcondition");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   140
  return res != SparsePRTEntry::overflow;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   141
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   142
24464
901aa0dcba08 8042474: Clean up duplicated code in RSHashTable
brutisso
parents: 24108
diff changeset
   143
SparsePRTEntry* RSHashTable::get_entry(RegionIdx_t region_ind) const {
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   144
  int ind = (int) (region_ind & capacity_mask());
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   145
  int cur_ind = _buckets[ind];
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   146
  SparsePRTEntry* cur;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   147
  while (cur_ind != NullEntry &&
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   148
         (cur = entry(cur_ind))->r_ind() != region_ind) {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   149
    cur_ind = cur->next_index();
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   150
  }
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   151
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   152
  if (cur_ind == NullEntry) return NULL;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   153
  // Otherwise...
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   154
  assert(cur->r_ind() == region_ind, "Postcondition of loop + test above.");
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   155
  assert(cur->num_valid_cards() > 0, "Inv");
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   156
  return cur;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   157
}
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   158
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   159
bool RSHashTable::delete_entry(RegionIdx_t region_ind) {
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   160
  int ind = (int) (region_ind & capacity_mask());
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   161
  int* prev_loc = &_buckets[ind];
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   162
  int cur_ind = *prev_loc;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   163
  SparsePRTEntry* cur;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   164
  while (cur_ind != NullEntry &&
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   165
         (cur = entry(cur_ind))->r_ind() != region_ind) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   166
    prev_loc = cur->next_index_addr();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   167
    cur_ind = *prev_loc;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   168
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   169
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   170
  if (cur_ind == NullEntry) return false;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   171
  // Otherwise, splice out "cur".
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   172
  *prev_loc = cur->next_index();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   173
  _occupied_cards -= cur->num_valid_cards();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   174
  free_entry(cur_ind);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   175
  _occupied_entries--;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   176
  return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   177
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   178
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   179
SparsePRTEntry*
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   180
RSHashTable::entry_for_region_ind_create(RegionIdx_t region_ind) {
24464
901aa0dcba08 8042474: Clean up duplicated code in RSHashTable
brutisso
parents: 24108
diff changeset
   181
  SparsePRTEntry* res = get_entry(region_ind);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   182
  if (res == NULL) {
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   183
    int new_ind = alloc_entry();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   184
    res = entry(new_ind);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   185
    res->init(region_ind);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   186
    // Insert at front.
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   187
    int ind = (int) (region_ind & capacity_mask());
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   188
    res->set_next_index(_buckets[ind]);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   189
    _buckets[ind] = new_ind;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   190
    _occupied_entries++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   191
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   192
  return res;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   193
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   194
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   195
int RSHashTable::alloc_entry() {
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   196
  int res;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   197
  if (_free_list != NullEntry) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   198
    res = _free_list;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   199
    _free_list = entry(res)->next_index();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   200
    return res;
38269
d18cab031e64 8155721: Sparse remset wastes half of entry memory
tschatzl
parents: 33741
diff changeset
   201
  } else if ((size_t)_free_region < _num_entries) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   202
    res = _free_region;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   203
    _free_region++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   204
    return res;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   205
  } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   206
    return NullEntry;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   207
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   208
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   209
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   210
void RSHashTable::free_entry(int fi) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   211
  entry(fi)->set_next_index(_free_list);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   212
  _free_list = fi;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   213
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   214
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   215
void RSHashTable::add_entry(SparsePRTEntry* e) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   216
  assert(e->num_valid_cards() > 0, "Precondition.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   217
  SparsePRTEntry* e2 = entry_for_region_ind_create(e->r_ind());
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   218
  e->copy_cards(e2);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   219
  _occupied_cards += e2->num_valid_cards();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   220
  assert(e2->num_valid_cards() > 0, "Postcondition.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   221
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   222
6983
a8c50cedbce9 6991377: G1: race between concurrent refinement and humongous object allocation
tonyp
parents: 6981
diff changeset
   223
CardIdx_t RSHashTableIter::find_first_card_in_list() {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   224
  while (_bl_ind != RSHashTable::NullEntry) {
38271
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
   225
    SparsePRTEntry* sparse_entry = _rsht->entry(_bl_ind);
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
   226
    if (sparse_entry->num_valid_cards() > 0) {
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
   227
      return sparse_entry->card(0);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   228
    } else {
38271
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
   229
      _bl_ind = sparse_entry->next_index();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   230
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   231
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   232
  // Otherwise, none found:
38271
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
   233
  return NoCardFound;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   234
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   235
6983
a8c50cedbce9 6991377: G1: race between concurrent refinement and humongous object allocation
tonyp
parents: 6981
diff changeset
   236
size_t RSHashTableIter::compute_card_ind(CardIdx_t ci) {
6981
ecfe524b1fa7 6992189: G1: inconsistent base used in sparse rem set iterator
tonyp
parents: 6250
diff changeset
   237
  return (_rsht->entry(_bl_ind)->r_ind() * HeapRegion::CardsPerRegion) + ci;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   238
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   239
6983
a8c50cedbce9 6991377: G1: race between concurrent refinement and humongous object allocation
tonyp
parents: 6981
diff changeset
   240
bool RSHashTableIter::has_next(size_t& card_index) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   241
  _card_ind++;
38271
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
   242
  if (_bl_ind >= 0) {
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
   243
    SparsePRTEntry* e = _rsht->entry(_bl_ind);
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
   244
    if (_card_ind < e->num_valid_cards()) {
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
   245
      CardIdx_t ci = e->card(_card_ind);
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
   246
      card_index = compute_card_ind(ci);
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
   247
      return true;
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
   248
    }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   249
  }
38271
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
   250
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   251
  // Otherwise, must find the next valid entry.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   252
  _card_ind = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   253
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   254
  if (_bl_ind != RSHashTable::NullEntry) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   255
      _bl_ind = _rsht->entry(_bl_ind)->next_index();
38271
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
   256
      CardIdx_t ci = find_first_card_in_list();
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
   257
      if (ci != NoCardFound) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   258
        card_index = compute_card_ind(ci);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   259
        return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   260
      }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   261
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   262
  // If we didn't return above, must go to the next non-null table index.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   263
  _tbl_ind++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   264
  while ((size_t)_tbl_ind < _rsht->capacity()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   265
    _bl_ind = _rsht->_buckets[_tbl_ind];
38271
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
   266
    CardIdx_t ci = find_first_card_in_list();
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38269
diff changeset
   267
    if (ci != NoCardFound) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   268
      card_index = compute_card_ind(ci);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   269
      return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   270
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   271
    // Otherwise, try next entry.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   272
    _tbl_ind++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   273
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   274
  // Otherwise, there were no entry.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   275
  return false;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   276
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   277
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   278
bool RSHashTable::contains_card(RegionIdx_t region_index, CardIdx_t card_index) const {
24464
901aa0dcba08 8042474: Clean up duplicated code in RSHashTable
brutisso
parents: 24108
diff changeset
   279
  SparsePRTEntry* e = get_entry(region_index);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   280
  return (e != NULL && e->contains_card(card_index));
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   281
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   282
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   283
size_t RSHashTable::mem_size() const {
24108
dfc2242fc6b0 8040792: G1: Memory usage calculation uses sizeof(this) instead of sizeof(classname)
tschatzl
parents: 22234
diff changeset
   284
  return sizeof(RSHashTable) +
38269
d18cab031e64 8155721: Sparse remset wastes half of entry memory
tschatzl
parents: 33741
diff changeset
   285
    _num_entries * (SparsePRTEntry::size() + sizeof(int));
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   286
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   287
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   288
// ----------------------------------------------------------------------
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   289
52347
14ef0f74667b 8211388: Make OtherRegionsTable independent of the region it is for
tschatzl
parents: 51332
diff changeset
   290
SparsePRT::SparsePRT() :
52716
877dd2b0f36c 8213996: Remove one of the SparsePRT entry tables
tschatzl
parents: 52347
diff changeset
   291
  _table(new RSHashTable(InitialCapacity)) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   292
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   293
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   294
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   295
SparsePRT::~SparsePRT() {
52716
877dd2b0f36c 8213996: Remove one of the SparsePRT entry tables
tschatzl
parents: 52347
diff changeset
   296
  delete _table;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   297
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   298
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   299
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   300
size_t SparsePRT::mem_size() const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   301
  // We ignore "_cur" here, because it either = _next, or else it is
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   302
  // on the deleted list.
52716
877dd2b0f36c 8213996: Remove one of the SparsePRT entry tables
tschatzl
parents: 52347
diff changeset
   303
  return sizeof(SparsePRT) + _table->mem_size();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   304
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   305
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   306
bool SparsePRT::add_card(RegionIdx_t region_id, CardIdx_t card_index) {
52716
877dd2b0f36c 8213996: Remove one of the SparsePRT entry tables
tschatzl
parents: 52347
diff changeset
   307
  if (_table->should_expand()) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   308
    expand();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   309
  }
52716
877dd2b0f36c 8213996: Remove one of the SparsePRT entry tables
tschatzl
parents: 52347
diff changeset
   310
  return _table->add_card(region_id, card_index);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   311
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   312
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   313
SparsePRTEntry* SparsePRT::get_entry(RegionIdx_t region_id) {
52716
877dd2b0f36c 8213996: Remove one of the SparsePRT entry tables
tschatzl
parents: 52347
diff changeset
   314
  return _table->get_entry(region_id);
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   315
}
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   316
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   317
bool SparsePRT::delete_entry(RegionIdx_t region_id) {
52716
877dd2b0f36c 8213996: Remove one of the SparsePRT entry tables
tschatzl
parents: 52347
diff changeset
   318
  return _table->delete_entry(region_id);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   319
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   320
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   321
void SparsePRT::clear() {
52716
877dd2b0f36c 8213996: Remove one of the SparsePRT entry tables
tschatzl
parents: 52347
diff changeset
   322
  // If the entry table is not at initial capacity, just create a new one.
877dd2b0f36c 8213996: Remove one of the SparsePRT entry tables
tschatzl
parents: 52347
diff changeset
   323
  if (_table->capacity() != InitialCapacity) {
877dd2b0f36c 8213996: Remove one of the SparsePRT entry tables
tschatzl
parents: 52347
diff changeset
   324
    delete _table;
877dd2b0f36c 8213996: Remove one of the SparsePRT entry tables
tschatzl
parents: 52347
diff changeset
   325
    _table = new RSHashTable(InitialCapacity);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   326
  } else {
52716
877dd2b0f36c 8213996: Remove one of the SparsePRT entry tables
tschatzl
parents: 52347
diff changeset
   327
    _table->clear();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   328
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   329
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   330
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   331
void SparsePRT::expand() {
52716
877dd2b0f36c 8213996: Remove one of the SparsePRT entry tables
tschatzl
parents: 52347
diff changeset
   332
  RSHashTable* last = _table;
877dd2b0f36c 8213996: Remove one of the SparsePRT entry tables
tschatzl
parents: 52347
diff changeset
   333
  _table = new RSHashTable(last->capacity() * 2);
38269
d18cab031e64 8155721: Sparse remset wastes half of entry memory
tschatzl
parents: 33741
diff changeset
   334
  for (size_t i = 0; i < last->num_entries(); i++) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   335
    SparsePRTEntry* e = last->entry((int)i);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   336
    if (e->valid_entry()) {
52716
877dd2b0f36c 8213996: Remove one of the SparsePRT entry tables
tschatzl
parents: 52347
diff changeset
   337
      _table->add_entry(e);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   338
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   339
  }
52716
877dd2b0f36c 8213996: Remove one of the SparsePRT entry tables
tschatzl
parents: 52347
diff changeset
   340
  delete last;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   341
}