hotspot/src/share/vm/gc_implementation/g1/sparsePRT.cpp
author johnc
Fri, 06 Aug 2010 10:17:21 -0700
changeset 6250 5680f968c721
parent 5547 f4b087cbb361
child 6981 ecfe524b1fa7
permissions -rw-r--r--
6930581: G1: assert(ParallelGCThreads > 1 || n_yielded() == _hrrs->occupied(),"Should have yielded all the .. Summary: During RSet updating, when ParallelGCThreads is zero, references that point into the collection set are added directly the referenced region's RSet. This can cause the sparse table in the RSet to expand. RSet scanning and the "occupied" routine will then operate on different instances of the sparse table causing the assert to trip. This may also cause some cards added post expansion to be missed during RSet scanning. When ParallelGCThreads is non-zero such references are recorded on the "references to be scanned" queue and the card containing the reference is recorded in a dirty card queue for use in the event of an evacuation failure. Employ the parallel code in the serial case to avoid expanding the RSets of regions in the collection set. Reviewed-by: iveresov, ysr, tonyp
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
/*
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4902
diff changeset
     2
 * Copyright (c) 2001, 2009, 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
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    25
#include "incls/_precompiled.incl"
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    26
#include "incls/_sparsePRT.cpp.incl"
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    27
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    28
#define SPARSE_PRT_VERBOSE 0
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    29
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    30
#define UNROLL_CARD_LOOPS  1
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    31
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    32
void SparsePRT::init_iterator(SparsePRTIter* sprt_iter) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    33
    sprt_iter->init(this);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    34
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    35
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
    36
void SparsePRTEntry::init(RegionIdx_t region_ind) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    37
  _region_ind = region_ind;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    38
  _next_index = NullEntry;
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    39
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    40
#if UNROLL_CARD_LOOPS
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    41
  assert((cards_num() & (UnrollFactor - 1)) == 0, "Invalid number of cards in the entry");
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    42
  for (int i = 0; i < cards_num(); i += UnrollFactor) {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    43
    _cards[i] = NullEntry;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    44
    _cards[i + 1] = NullEntry;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    45
    _cards[i + 2] = NullEntry;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    46
    _cards[i + 3] = NullEntry;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    47
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    48
#else
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    49
  for (int i = 0; i < cards_num(); i++)
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
    50
    _cards[i] = NullEntry;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    51
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    52
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    53
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
    54
bool SparsePRTEntry::contains_card(CardIdx_t card_index) const {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    55
#if UNROLL_CARD_LOOPS
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    56
  assert((cards_num() & (UnrollFactor - 1)) == 0, "Invalid number of cards in the entry");
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    57
  for (int i = 0; i < cards_num(); i += UnrollFactor) {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    58
    if (_cards[i] == card_index ||
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    59
        _cards[i + 1] == card_index ||
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    60
        _cards[i + 2] == card_index ||
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    61
        _cards[i + 3] == card_index) return true;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    62
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    63
#else
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    64
  for (int i = 0; i < cards_num(); i++) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    65
    if (_cards[i] == card_index) return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    66
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    67
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    68
  // Otherwise, we're full.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    69
  return false;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    70
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    71
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    72
int SparsePRTEntry::num_valid_cards() const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    73
  int sum = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    74
#if UNROLL_CARD_LOOPS
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    75
  assert((cards_num() & (UnrollFactor - 1)) == 0, "Invalid number of cards in the entry");
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    76
  for (int i = 0; i < cards_num(); i += UnrollFactor) {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    77
    sum += (_cards[i] != NullEntry);
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    78
    sum += (_cards[i + 1] != NullEntry);
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    79
    sum += (_cards[i + 2] != NullEntry);
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    80
    sum += (_cards[i + 3] != NullEntry);
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    81
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    82
#else
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    83
  for (int i = 0; i < cards_num(); i++) {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    84
    sum += (_cards[i] != NullEntry);
1374
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
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    87
  // Otherwise, we're full.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    88
  return sum;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    89
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    90
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
    91
SparsePRTEntry::AddCardResult SparsePRTEntry::add_card(CardIdx_t card_index) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    92
#if UNROLL_CARD_LOOPS
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    93
  assert((cards_num() & (UnrollFactor - 1)) == 0, "Invalid number of cards in the entry");
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    94
  CardIdx_t c;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    95
  for (int i = 0; i < cards_num(); i += UnrollFactor) {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    96
    c = _cards[i];
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    97
    if (c == card_index) return found;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    98
    if (c == NullEntry) { _cards[i] = card_index; return added; }
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    99
    c = _cards[i + 1];
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   100
    if (c == card_index) return found;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   101
    if (c == NullEntry) { _cards[i + 1] = card_index; return added; }
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   102
    c = _cards[i + 2];
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   103
    if (c == card_index) return found;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   104
    if (c == NullEntry) { _cards[i + 2] = card_index; return added; }
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   105
    c = _cards[i + 3];
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   106
    if (c == card_index) return found;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   107
    if (c == NullEntry) { _cards[i + 3] = card_index; return added; }
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   108
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   109
#else
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   110
  for (int i = 0; i < cards_num(); i++) {
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   111
    CardIdx_t c = _cards[i];
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   112
    if (c == card_index) return found;
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   113
    if (c == NullEntry) { _cards[i] = card_index; return added; }
1374
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
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   116
  // Otherwise, we're full.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   117
  return overflow;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   118
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   119
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   120
void SparsePRTEntry::copy_cards(CardIdx_t* cards) const {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   121
#if UNROLL_CARD_LOOPS
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   122
  assert((cards_num() & (UnrollFactor - 1)) == 0, "Invalid number of cards in the entry");
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   123
  for (int i = 0; i < cards_num(); i += UnrollFactor) {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   124
    cards[i] = _cards[i];
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   125
    cards[i + 1] = _cards[i + 1];
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   126
    cards[i + 2] = _cards[i + 2];
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   127
    cards[i + 3] = _cards[i + 3];
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   128
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   129
#else
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   130
  for (int i = 0; i < cards_num(); i++) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   131
    cards[i] = _cards[i];
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   132
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   133
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   134
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   135
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   136
void SparsePRTEntry::copy_cards(SparsePRTEntry* e) const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   137
  copy_cards(&e->_cards[0]);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   138
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   139
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   140
// ----------------------------------------------------------------------
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
RSHashTable::RSHashTable(size_t capacity) :
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   143
  _capacity(capacity), _capacity_mask(capacity-1),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   144
  _occupied_entries(0), _occupied_cards(0),
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   145
  _entries((SparsePRTEntry*)NEW_C_HEAP_ARRAY(char, SparsePRTEntry::size() * capacity)),
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   146
  _buckets(NEW_C_HEAP_ARRAY(int, capacity)),
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   147
  _free_list(NullEntry), _free_region(0)
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   148
{
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   149
  clear();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   150
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   151
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   152
RSHashTable::~RSHashTable() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   153
  if (_entries != NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   154
    FREE_C_HEAP_ARRAY(SparsePRTEntry, _entries);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   155
    _entries = NULL;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   156
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   157
  if (_buckets != NULL) {
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   158
    FREE_C_HEAP_ARRAY(int, _buckets);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   159
    _buckets = NULL;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   160
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   161
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   162
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   163
void RSHashTable::clear() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   164
  _occupied_entries = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   165
  _occupied_cards = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   166
  guarantee(_entries != NULL, "INV");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   167
  guarantee(_buckets != NULL, "INV");
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   168
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   169
  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
   170
                "_capacity too large");
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   171
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   172
  // This will put -1 == NullEntry in the key field of all entries.
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   173
  memset(_entries, NullEntry, _capacity * SparsePRTEntry::size());
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   174
  memset(_buckets, NullEntry, _capacity * sizeof(int));
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   175
  _free_list = NullEntry;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   176
  _free_region = 0;
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
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
   180
  SparsePRTEntry* e = entry_for_region_ind_create(region_ind);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   181
  assert(e != NULL && e->r_ind() == region_ind,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   182
         "Postcondition of call above.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   183
  SparsePRTEntry::AddCardResult res = e->add_card(card_index);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   184
  if (res == SparsePRTEntry::added) _occupied_cards++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   185
#if SPARSE_PRT_VERBOSE
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   186
  gclog_or_tty->print_cr("       after add_card[%d]: valid-cards = %d.",
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   187
                         pointer_delta(e, _entries, SparsePRTEntry::size()),
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   188
                         e->num_valid_cards());
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   189
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   190
  assert(e->num_valid_cards() > 0, "Postcondition");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   191
  return res != SparsePRTEntry::overflow;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   192
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   193
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   194
bool RSHashTable::get_cards(RegionIdx_t region_ind, CardIdx_t* cards) {
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   195
  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
   196
  int cur_ind = _buckets[ind];
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   197
  SparsePRTEntry* cur;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   198
  while (cur_ind != NullEntry &&
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   199
         (cur = entry(cur_ind))->r_ind() != region_ind) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   200
    cur_ind = cur->next_index();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   201
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   202
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   203
  if (cur_ind == NullEntry) return false;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   204
  // Otherwise...
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   205
  assert(cur->r_ind() == region_ind, "Postcondition of loop + test above.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   206
  assert(cur->num_valid_cards() > 0, "Inv");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   207
  cur->copy_cards(cards);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   208
  return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   209
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   210
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   211
SparsePRTEntry* RSHashTable::get_entry(RegionIdx_t region_ind) {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   212
  int ind = (int) (region_ind & capacity_mask());
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   213
  int cur_ind = _buckets[ind];
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   214
  SparsePRTEntry* cur;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   215
  while (cur_ind != NullEntry &&
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   216
         (cur = entry(cur_ind))->r_ind() != region_ind) {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   217
    cur_ind = cur->next_index();
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   218
  }
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   219
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   220
  if (cur_ind == NullEntry) return NULL;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   221
  // Otherwise...
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   222
  assert(cur->r_ind() == region_ind, "Postcondition of loop + test above.");
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   223
  assert(cur->num_valid_cards() > 0, "Inv");
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   224
  return cur;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   225
}
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   226
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   227
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
   228
  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
   229
  int* prev_loc = &_buckets[ind];
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   230
  int cur_ind = *prev_loc;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   231
  SparsePRTEntry* cur;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   232
  while (cur_ind != NullEntry &&
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   233
         (cur = entry(cur_ind))->r_ind() != region_ind) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   234
    prev_loc = cur->next_index_addr();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   235
    cur_ind = *prev_loc;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   236
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   237
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   238
  if (cur_ind == NullEntry) return false;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   239
  // Otherwise, splice out "cur".
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   240
  *prev_loc = cur->next_index();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   241
  _occupied_cards -= cur->num_valid_cards();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   242
  free_entry(cur_ind);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   243
  _occupied_entries--;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   244
  return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   245
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   246
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   247
SparsePRTEntry*
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   248
RSHashTable::entry_for_region_ind(RegionIdx_t region_ind) const {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   249
  assert(occupied_entries() < capacity(), "Precondition");
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   250
  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
   251
  int cur_ind = _buckets[ind];
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   252
  SparsePRTEntry* cur;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   253
  while (cur_ind != NullEntry &&
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   254
         (cur = entry(cur_ind))->r_ind() != region_ind) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   255
    cur_ind = cur->next_index();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   256
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   257
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   258
  if (cur_ind != NullEntry) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   259
    assert(cur->r_ind() == region_ind, "Loop postcondition + test");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   260
    return cur;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   261
  } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   262
    return NULL;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   263
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   264
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   265
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   266
SparsePRTEntry*
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   267
RSHashTable::entry_for_region_ind_create(RegionIdx_t region_ind) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   268
  SparsePRTEntry* res = entry_for_region_ind(region_ind);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   269
  if (res == NULL) {
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   270
    int new_ind = alloc_entry();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   271
    assert(0 <= new_ind && (size_t)new_ind < capacity(), "There should be room.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   272
    res = entry(new_ind);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   273
    res->init(region_ind);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   274
    // Insert at front.
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   275
    int ind = (int) (region_ind & capacity_mask());
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   276
    res->set_next_index(_buckets[ind]);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   277
    _buckets[ind] = new_ind;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   278
    _occupied_entries++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   279
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   280
  return res;
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
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   283
int RSHashTable::alloc_entry() {
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   284
  int res;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   285
  if (_free_list != NullEntry) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   286
    res = _free_list;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   287
    _free_list = entry(res)->next_index();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   288
    return res;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   289
  } else if ((size_t) _free_region+1 < capacity()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   290
    res = _free_region;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   291
    _free_region++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   292
    return res;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   293
  } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   294
    return NullEntry;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   295
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   296
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   297
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   298
void RSHashTable::free_entry(int fi) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   299
  entry(fi)->set_next_index(_free_list);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   300
  _free_list = fi;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   301
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   302
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   303
void RSHashTable::add_entry(SparsePRTEntry* e) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   304
  assert(e->num_valid_cards() > 0, "Precondition.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   305
  SparsePRTEntry* e2 = entry_for_region_ind_create(e->r_ind());
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   306
  e->copy_cards(e2);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   307
  _occupied_cards += e2->num_valid_cards();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   308
  assert(e2->num_valid_cards() > 0, "Postcondition.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   309
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   310
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   311
CardIdx_t /* RSHashTable:: */ RSHashTableIter::find_first_card_in_list() {
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   312
  CardIdx_t res;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   313
  while (_bl_ind != RSHashTable::NullEntry) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   314
    res = _rsht->entry(_bl_ind)->card(0);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   315
    if (res != SparsePRTEntry::NullEntry) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   316
      return res;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   317
    } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   318
      _bl_ind = _rsht->entry(_bl_ind)->next_index();
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
  // Otherwise, none found:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   322
  return SparsePRTEntry::NullEntry;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   323
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   324
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   325
size_t /* RSHashTable:: */ RSHashTableIter::compute_card_ind(CardIdx_t ci) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   326
  return
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   327
    _heap_bot_card_ind
3697
ea9211aa02f5 6819085: G1: use larger and/or user settable region size
tonyp
parents: 3261
diff changeset
   328
    + (_rsht->entry(_bl_ind)->r_ind() * HeapRegion::CardsPerRegion)
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   329
    + ci;
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
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   332
bool /* RSHashTable:: */ RSHashTableIter::has_next(size_t& card_index) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   333
  _card_ind++;
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   334
  CardIdx_t ci;
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   335
  if (_card_ind < SparsePRTEntry::cards_num() &&
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   336
      ((ci = _rsht->entry(_bl_ind)->card(_card_ind)) !=
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   337
       SparsePRTEntry::NullEntry)) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   338
    card_index = compute_card_ind(ci);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   339
    return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   340
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   341
  // Otherwise, must find the next valid entry.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   342
  _card_ind = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   343
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   344
  if (_bl_ind != RSHashTable::NullEntry) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   345
      _bl_ind = _rsht->entry(_bl_ind)->next_index();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   346
      ci = find_first_card_in_list();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   347
      if (ci != SparsePRTEntry::NullEntry) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   348
        card_index = compute_card_ind(ci);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   349
        return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   350
      }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   351
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   352
  // 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
   353
  _tbl_ind++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   354
  while ((size_t)_tbl_ind < _rsht->capacity()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   355
    _bl_ind = _rsht->_buckets[_tbl_ind];
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   356
    ci = find_first_card_in_list();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   357
    if (ci != SparsePRTEntry::NullEntry) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   358
      card_index = compute_card_ind(ci);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   359
      return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   360
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   361
    // Otherwise, try next entry.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   362
    _tbl_ind++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   363
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   364
  // Otherwise, there were no entry.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   365
  return false;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   366
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   367
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   368
bool RSHashTable::contains_card(RegionIdx_t region_index, CardIdx_t card_index) const {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   369
  SparsePRTEntry* e = entry_for_region_ind(region_index);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   370
  return (e != NULL && e->contains_card(card_index));
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   371
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   372
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   373
size_t RSHashTable::mem_size() const {
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   374
  return sizeof(this) +
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   375
    capacity() * (SparsePRTEntry::size() + sizeof(int));
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   376
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   377
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   378
// ----------------------------------------------------------------------
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   379
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   380
SparsePRT* SparsePRT::_head_expanded_list = NULL;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   381
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   382
void SparsePRT::add_to_expanded_list(SparsePRT* sprt) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   383
  // We could expand multiple times in a pause -- only put on list once.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   384
  if (sprt->expanded()) return;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   385
  sprt->set_expanded(true);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   386
  SparsePRT* hd = _head_expanded_list;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   387
  while (true) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   388
    sprt->_next_expanded = hd;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   389
    SparsePRT* res =
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   390
      (SparsePRT*)
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   391
      Atomic::cmpxchg_ptr(sprt, &_head_expanded_list, hd);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   392
    if (res == hd) return;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   393
    else hd = res;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   394
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   395
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   396
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   397
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   398
SparsePRT* SparsePRT::get_from_expanded_list() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   399
  SparsePRT* hd = _head_expanded_list;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   400
  while (hd != NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   401
    SparsePRT* next = hd->next_expanded();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   402
    SparsePRT* res =
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   403
      (SparsePRT*)
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   404
      Atomic::cmpxchg_ptr(next, &_head_expanded_list, hd);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   405
    if (res == hd) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   406
      hd->set_next_expanded(NULL);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   407
      return hd;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   408
    } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   409
      hd = res;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   410
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   411
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   412
  return NULL;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   413
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   414
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   415
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   416
void SparsePRT::cleanup_all() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   417
  // First clean up all expanded tables so they agree on next and cur.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   418
  SparsePRT* sprt = get_from_expanded_list();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   419
  while (sprt != NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   420
    sprt->cleanup();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   421
    sprt = get_from_expanded_list();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   422
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   423
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   424
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   425
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   426
SparsePRT::SparsePRT(HeapRegion* hr) :
6250
5680f968c721 6930581: G1: assert(ParallelGCThreads > 1 || n_yielded() == _hrrs->occupied(),"Should have yielded all the ..
johnc
parents: 5547
diff changeset
   427
  _hr(hr), _expanded(false), _next_expanded(NULL)
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   428
{
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   429
  _cur = new RSHashTable(InitialCapacity);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   430
  _next = _cur;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   431
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   432
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   433
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   434
SparsePRT::~SparsePRT() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   435
  assert(_next != NULL && _cur != NULL, "Inv");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   436
  if (_cur != _next) { delete _cur; }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   437
  delete _next;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   438
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   439
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   440
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   441
size_t SparsePRT::mem_size() const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   442
  // 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
   443
  // on the deleted list.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   444
  return sizeof(this) + _next->mem_size();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   445
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   446
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   447
bool SparsePRT::add_card(RegionIdx_t region_id, CardIdx_t card_index) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   448
#if SPARSE_PRT_VERBOSE
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   449
  gclog_or_tty->print_cr("  Adding card %d from region %d to region %d sparse.",
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   450
                card_index, region_id, _hr->hrs_index());
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   451
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   452
  if (_next->occupied_entries() * 2 > _next->capacity()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   453
    expand();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   454
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   455
  return _next->add_card(region_id, card_index);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   456
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   457
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   458
bool SparsePRT::get_cards(RegionIdx_t region_id, CardIdx_t* cards) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   459
  return _next->get_cards(region_id, cards);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   460
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   461
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   462
SparsePRTEntry* SparsePRT::get_entry(RegionIdx_t region_id) {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   463
  return _next->get_entry(region_id);
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   464
}
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   465
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   466
bool SparsePRT::delete_entry(RegionIdx_t region_id) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   467
  return _next->delete_entry(region_id);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   468
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   469
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   470
void SparsePRT::clear() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   471
  // If they differ, _next is bigger then cur, so next has no chance of
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   472
  // being the initial size.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   473
  if (_next != _cur) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   474
    delete _next;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   475
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   476
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   477
  if (_cur->capacity() != InitialCapacity) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   478
    delete _cur;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   479
    _cur = new RSHashTable(InitialCapacity);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   480
  } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   481
    _cur->clear();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   482
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   483
  _next = _cur;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   484
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   485
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   486
void SparsePRT::cleanup() {
4100
4f43ba12619a 6870843: G1: G1 GC memory leak
apetrusenko
parents: 3697
diff changeset
   487
  // Make sure that the current and next tables agree.
4f43ba12619a 6870843: G1: G1 GC memory leak
apetrusenko
parents: 3697
diff changeset
   488
  if (_cur != _next) {
4f43ba12619a 6870843: G1: G1 GC memory leak
apetrusenko
parents: 3697
diff changeset
   489
    delete _cur;
4f43ba12619a 6870843: G1: G1 GC memory leak
apetrusenko
parents: 3697
diff changeset
   490
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   491
  _cur = _next;
2143
61babb9fbd6f 6810698: G1: two small bugs in the sparse remembered sets
tonyp
parents: 1374
diff changeset
   492
  set_expanded(false);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   493
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   494
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   495
void SparsePRT::expand() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   496
  RSHashTable* last = _next;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   497
  _next = new RSHashTable(last->capacity() * 2);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   498
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   499
#if SPARSE_PRT_VERBOSE
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   500
  gclog_or_tty->print_cr("  Expanded sparse table for %d to %d.",
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   501
                _hr->hrs_index(), _next->capacity());
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   502
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   503
  for (size_t i = 0; i < last->capacity(); i++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   504
    SparsePRTEntry* e = last->entry((int)i);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   505
    if (e->valid_entry()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   506
#if SPARSE_PRT_VERBOSE
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   507
      gclog_or_tty->print_cr("    During expansion, transferred entry for %d.",
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   508
                    e->r_ind());
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   509
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   510
      _next->add_entry(e);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   511
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   512
  }
4100
4f43ba12619a 6870843: G1: G1 GC memory leak
apetrusenko
parents: 3697
diff changeset
   513
  if (last != _cur) {
4f43ba12619a 6870843: G1: G1 GC memory leak
apetrusenko
parents: 3697
diff changeset
   514
    delete last;
4f43ba12619a 6870843: G1: G1 GC memory leak
apetrusenko
parents: 3697
diff changeset
   515
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   516
  add_to_expanded_list(this);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   517
}