hotspot/src/share/vm/gc_implementation/g1/sparsePRT.cpp
author tonyp
Fri, 10 Jun 2011 13:16:40 -0400
changeset 9989 305a76435cf1
parent 8072 f223f43cd62f
child 12381 1438e0fbfa27
permissions -rw-r--r--
7045330: G1: Simplify/fix the HeapRegionSeq class 7042285: G1: native memory leak during humongous object allocation 6804436: G1: heap region indices should be size_t Summary: A series of fixes and improvements to the HeapRegionSeq class: a) replace the _regions growable array with a standard C array, b) avoid de-allocating / re-allocating HeapRegion instances when the heap shrinks / grows (fix for 7042285), c) introduce fast method to map address to HeapRegion via a "biased" array pointer, d) embed the _hrs object in G1CollectedHeap, instead of pointing to it via an indirection, e) assume that all the regions added to the HeapRegionSeq instance are contiguous, f) replace int's with size_t's for indexes (and expand that to HeapRegion as part of 6804436), g) remove unnecessary / unused methods, h) rename a couple of fields (_alloc_search_start and _seq_bottom), i) fix iterate_from() not to always start from index 0 irrespective of the region passed to it, j) add a verification method to check the HeapRegionSeq assumptions, k) always call the wrappers for _hrs.iterate(), _hrs_length(), and _hrs.at() from G1CollectedHeap, not those methods directly, and l) unify the code that expands the sequence (by either re-using or creating a new HeapRegion) and make it robust wrt to a HeapRegion allocation failing. Reviewed-by: stefank, johnc, brutisso
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
/*
8072
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
     2
 * Copyright (c) 2001, 2011, 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"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6983
diff changeset
    26
#include "gc_implementation/g1/heapRegion.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6983
diff changeset
    27
#include "gc_implementation/g1/heapRegionRemSet.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6983
diff changeset
    28
#include "gc_implementation/g1/sparsePRT.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6983
diff changeset
    29
#include "memory/allocation.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6983
diff changeset
    30
#include "memory/cardTableModRefBS.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6983
diff changeset
    31
#include "memory/space.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6983
diff changeset
    32
#include "runtime/mutexLocker.hpp"
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    33
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    34
#define SPARSE_PRT_VERBOSE 0
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    35
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    36
#define UNROLL_CARD_LOOPS  1
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    37
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    38
void SparsePRT::init_iterator(SparsePRTIter* sprt_iter) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    39
    sprt_iter->init(this);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    40
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    41
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
    42
void SparsePRTEntry::init(RegionIdx_t region_ind) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    43
  _region_ind = region_ind;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    44
  _next_index = NullEntry;
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    45
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    46
#if UNROLL_CARD_LOOPS
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    47
  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
    48
  for (int i = 0; i < cards_num(); i += UnrollFactor) {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    49
    _cards[i] = NullEntry;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    50
    _cards[i + 1] = NullEntry;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    51
    _cards[i + 2] = NullEntry;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    52
    _cards[i + 3] = NullEntry;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    53
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    54
#else
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    55
  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
    56
    _cards[i] = NullEntry;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    57
#endif
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
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
    60
bool SparsePRTEntry::contains_card(CardIdx_t card_index) const {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    61
#if UNROLL_CARD_LOOPS
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    62
  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
    63
  for (int i = 0; i < cards_num(); i += UnrollFactor) {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    64
    if (_cards[i] == card_index ||
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    65
        _cards[i + 1] == card_index ||
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    66
        _cards[i + 2] == card_index ||
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    67
        _cards[i + 3] == card_index) return true;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    68
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    69
#else
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    70
  for (int i = 0; i < cards_num(); i++) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    71
    if (_cards[i] == card_index) return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    72
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    73
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    74
  // Otherwise, we're full.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    75
  return false;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    76
}
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
int SparsePRTEntry::num_valid_cards() const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    79
  int sum = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    80
#if UNROLL_CARD_LOOPS
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    81
  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
    82
  for (int i = 0; i < cards_num(); i += UnrollFactor) {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    83
    sum += (_cards[i] != NullEntry);
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    84
    sum += (_cards[i + 1] != NullEntry);
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    85
    sum += (_cards[i + 2] != NullEntry);
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    86
    sum += (_cards[i + 3] != NullEntry);
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    87
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    88
#else
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    89
  for (int i = 0; i < cards_num(); i++) {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    90
    sum += (_cards[i] != NullEntry);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    91
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    92
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    93
  // Otherwise, we're full.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    94
  return sum;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    95
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    96
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
    97
SparsePRTEntry::AddCardResult SparsePRTEntry::add_card(CardIdx_t card_index) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    98
#if UNROLL_CARD_LOOPS
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    99
  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
   100
  CardIdx_t c;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   101
  for (int i = 0; i < cards_num(); i += UnrollFactor) {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   102
    c = _cards[i];
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] = card_index; return added; }
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   105
    c = _cards[i + 1];
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 + 1] = card_index; return added; }
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   108
    c = _cards[i + 2];
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   109
    if (c == card_index) return found;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   110
    if (c == NullEntry) { _cards[i + 2] = card_index; return added; }
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   111
    c = _cards[i + 3];
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   112
    if (c == card_index) return found;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   113
    if (c == NullEntry) { _cards[i + 3] = card_index; return added; }
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   114
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   115
#else
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   116
  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
   117
    CardIdx_t c = _cards[i];
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   118
    if (c == card_index) return found;
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   119
    if (c == NullEntry) { _cards[i] = card_index; return added; }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   120
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   121
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   122
  // Otherwise, we're full.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   123
  return overflow;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   124
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   125
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   126
void SparsePRTEntry::copy_cards(CardIdx_t* cards) const {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   127
#if UNROLL_CARD_LOOPS
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   128
  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
   129
  for (int i = 0; i < cards_num(); i += UnrollFactor) {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   130
    cards[i] = _cards[i];
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   131
    cards[i + 1] = _cards[i + 1];
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   132
    cards[i + 2] = _cards[i + 2];
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   133
    cards[i + 3] = _cards[i + 3];
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   134
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   135
#else
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   136
  for (int i = 0; i < cards_num(); i++) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   137
    cards[i] = _cards[i];
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
#endif
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
void SparsePRTEntry::copy_cards(SparsePRTEntry* e) const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   143
  copy_cards(&e->_cards[0]);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   144
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   145
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   146
// ----------------------------------------------------------------------
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   147
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   148
RSHashTable::RSHashTable(size_t capacity) :
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   149
  _capacity(capacity), _capacity_mask(capacity-1),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   150
  _occupied_entries(0), _occupied_cards(0),
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   151
  _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
   152
  _buckets(NEW_C_HEAP_ARRAY(int, capacity)),
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   153
  _free_list(NullEntry), _free_region(0)
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   154
{
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   155
  clear();
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
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   158
RSHashTable::~RSHashTable() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   159
  if (_entries != NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   160
    FREE_C_HEAP_ARRAY(SparsePRTEntry, _entries);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   161
    _entries = NULL;
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
  if (_buckets != NULL) {
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   164
    FREE_C_HEAP_ARRAY(int, _buckets);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   165
    _buckets = NULL;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   166
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   167
}
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
void RSHashTable::clear() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   170
  _occupied_entries = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   171
  _occupied_cards = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   172
  guarantee(_entries != NULL, "INV");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   173
  guarantee(_buckets != NULL, "INV");
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   174
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   175
  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
   176
                "_capacity too large");
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   177
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   178
  // 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
   179
  memset(_entries, NullEntry, _capacity * SparsePRTEntry::size());
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   180
  memset(_buckets, NullEntry, _capacity * sizeof(int));
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   181
  _free_list = NullEntry;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   182
  _free_region = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   183
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   184
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   185
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
   186
  SparsePRTEntry* e = entry_for_region_ind_create(region_ind);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   187
  assert(e != NULL && e->r_ind() == region_ind,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   188
         "Postcondition of call above.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   189
  SparsePRTEntry::AddCardResult res = e->add_card(card_index);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   190
  if (res == SparsePRTEntry::added) _occupied_cards++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   191
#if SPARSE_PRT_VERBOSE
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   192
  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
   193
                         pointer_delta(e, _entries, SparsePRTEntry::size()),
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   194
                         e->num_valid_cards());
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   195
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   196
  assert(e->num_valid_cards() > 0, "Postcondition");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   197
  return res != SparsePRTEntry::overflow;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   198
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   199
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   200
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
   201
  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
   202
  int cur_ind = _buckets[ind];
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   203
  SparsePRTEntry* cur;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   204
  while (cur_ind != NullEntry &&
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   205
         (cur = entry(cur_ind))->r_ind() != region_ind) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   206
    cur_ind = cur->next_index();
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
  if (cur_ind == NullEntry) return false;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   210
  // Otherwise...
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   211
  assert(cur->r_ind() == region_ind, "Postcondition of loop + test above.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   212
  assert(cur->num_valid_cards() > 0, "Inv");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   213
  cur->copy_cards(cards);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   214
  return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   215
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   216
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   217
SparsePRTEntry* RSHashTable::get_entry(RegionIdx_t region_ind) {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   218
  int ind = (int) (region_ind & capacity_mask());
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   219
  int cur_ind = _buckets[ind];
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   220
  SparsePRTEntry* cur;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   221
  while (cur_ind != NullEntry &&
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   222
         (cur = entry(cur_ind))->r_ind() != region_ind) {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   223
    cur_ind = cur->next_index();
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   224
  }
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
  if (cur_ind == NullEntry) return NULL;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   227
  // Otherwise...
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   228
  assert(cur->r_ind() == region_ind, "Postcondition of loop + test above.");
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   229
  assert(cur->num_valid_cards() > 0, "Inv");
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   230
  return cur;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   231
}
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   232
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   233
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
   234
  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
   235
  int* prev_loc = &_buckets[ind];
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   236
  int cur_ind = *prev_loc;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   237
  SparsePRTEntry* cur;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   238
  while (cur_ind != NullEntry &&
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   239
         (cur = entry(cur_ind))->r_ind() != region_ind) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   240
    prev_loc = cur->next_index_addr();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   241
    cur_ind = *prev_loc;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   242
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   243
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   244
  if (cur_ind == NullEntry) return false;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   245
  // Otherwise, splice out "cur".
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   246
  *prev_loc = cur->next_index();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   247
  _occupied_cards -= cur->num_valid_cards();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   248
  free_entry(cur_ind);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   249
  _occupied_entries--;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   250
  return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   251
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   252
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   253
SparsePRTEntry*
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   254
RSHashTable::entry_for_region_ind(RegionIdx_t region_ind) const {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   255
  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
   256
  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
   257
  int cur_ind = _buckets[ind];
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   258
  SparsePRTEntry* cur;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   259
  while (cur_ind != NullEntry &&
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   260
         (cur = entry(cur_ind))->r_ind() != region_ind) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   261
    cur_ind = cur->next_index();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   262
  }
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
  if (cur_ind != NullEntry) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   265
    assert(cur->r_ind() == region_ind, "Loop postcondition + test");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   266
    return cur;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   267
  } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   268
    return NULL;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   269
  }
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
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   272
SparsePRTEntry*
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   273
RSHashTable::entry_for_region_ind_create(RegionIdx_t region_ind) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   274
  SparsePRTEntry* res = entry_for_region_ind(region_ind);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   275
  if (res == NULL) {
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   276
    int new_ind = alloc_entry();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   277
    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
   278
    res = entry(new_ind);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   279
    res->init(region_ind);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   280
    // Insert at front.
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   281
    int ind = (int) (region_ind & capacity_mask());
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   282
    res->set_next_index(_buckets[ind]);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   283
    _buckets[ind] = new_ind;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   284
    _occupied_entries++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   285
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   286
  return res;
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
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   289
int RSHashTable::alloc_entry() {
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   290
  int res;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   291
  if (_free_list != NullEntry) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   292
    res = _free_list;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   293
    _free_list = entry(res)->next_index();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   294
    return res;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   295
  } else if ((size_t) _free_region+1 < capacity()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   296
    res = _free_region;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   297
    _free_region++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   298
    return res;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   299
  } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   300
    return NullEntry;
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
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   304
void RSHashTable::free_entry(int fi) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   305
  entry(fi)->set_next_index(_free_list);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   306
  _free_list = fi;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   307
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   308
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   309
void RSHashTable::add_entry(SparsePRTEntry* e) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   310
  assert(e->num_valid_cards() > 0, "Precondition.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   311
  SparsePRTEntry* e2 = entry_for_region_ind_create(e->r_ind());
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   312
  e->copy_cards(e2);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   313
  _occupied_cards += e2->num_valid_cards();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   314
  assert(e2->num_valid_cards() > 0, "Postcondition.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   315
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   316
6983
a8c50cedbce9 6991377: G1: race between concurrent refinement and humongous object allocation
tonyp
parents: 6981
diff changeset
   317
CardIdx_t RSHashTableIter::find_first_card_in_list() {
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   318
  CardIdx_t res;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   319
  while (_bl_ind != RSHashTable::NullEntry) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   320
    res = _rsht->entry(_bl_ind)->card(0);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   321
    if (res != SparsePRTEntry::NullEntry) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   322
      return res;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   323
    } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   324
      _bl_ind = _rsht->entry(_bl_ind)->next_index();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   325
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   326
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   327
  // Otherwise, none found:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   328
  return SparsePRTEntry::NullEntry;
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
6983
a8c50cedbce9 6991377: G1: race between concurrent refinement and humongous object allocation
tonyp
parents: 6981
diff changeset
   331
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
   332
  return (_rsht->entry(_bl_ind)->r_ind() * HeapRegion::CardsPerRegion) + ci;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   333
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   334
6983
a8c50cedbce9 6991377: G1: race between concurrent refinement and humongous object allocation
tonyp
parents: 6981
diff changeset
   335
bool RSHashTableIter::has_next(size_t& card_index) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   336
  _card_ind++;
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   337
  CardIdx_t ci;
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   338
  if (_card_ind < SparsePRTEntry::cards_num() &&
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   339
      ((ci = _rsht->entry(_bl_ind)->card(_card_ind)) !=
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   340
       SparsePRTEntry::NullEntry)) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   341
    card_index = compute_card_ind(ci);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   342
    return true;
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
  // Otherwise, must find the next valid entry.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   345
  _card_ind = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   346
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   347
  if (_bl_ind != RSHashTable::NullEntry) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   348
      _bl_ind = _rsht->entry(_bl_ind)->next_index();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   349
      ci = find_first_card_in_list();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   350
      if (ci != SparsePRTEntry::NullEntry) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   351
        card_index = compute_card_ind(ci);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   352
        return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   353
      }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   354
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   355
  // 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
   356
  _tbl_ind++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   357
  while ((size_t)_tbl_ind < _rsht->capacity()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   358
    _bl_ind = _rsht->_buckets[_tbl_ind];
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   359
    ci = find_first_card_in_list();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   360
    if (ci != SparsePRTEntry::NullEntry) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   361
      card_index = compute_card_ind(ci);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   362
      return true;
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, try next entry.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   365
    _tbl_ind++;
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
  // Otherwise, there were no entry.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   368
  return false;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   369
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   370
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   371
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
   372
  SparsePRTEntry* e = entry_for_region_ind(region_index);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   373
  return (e != NULL && e->contains_card(card_index));
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   374
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   375
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   376
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
   377
  return sizeof(this) +
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   378
    capacity() * (SparsePRTEntry::size() + sizeof(int));
1374
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
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
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   383
SparsePRT* SparsePRT::_head_expanded_list = NULL;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   384
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   385
void SparsePRT::add_to_expanded_list(SparsePRT* sprt) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   386
  // 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
   387
  if (sprt->expanded()) return;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   388
  sprt->set_expanded(true);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   389
  SparsePRT* hd = _head_expanded_list;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   390
  while (true) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   391
    sprt->_next_expanded = hd;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   392
    SparsePRT* res =
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   393
      (SparsePRT*)
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   394
      Atomic::cmpxchg_ptr(sprt, &_head_expanded_list, hd);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   395
    if (res == hd) return;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   396
    else hd = res;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   397
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   398
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   399
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   400
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   401
SparsePRT* SparsePRT::get_from_expanded_list() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   402
  SparsePRT* hd = _head_expanded_list;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   403
  while (hd != NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   404
    SparsePRT* next = hd->next_expanded();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   405
    SparsePRT* res =
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   406
      (SparsePRT*)
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   407
      Atomic::cmpxchg_ptr(next, &_head_expanded_list, hd);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   408
    if (res == hd) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   409
      hd->set_next_expanded(NULL);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   410
      return hd;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   411
    } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   412
      hd = res;
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
  return NULL;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   416
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   417
8072
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   418
void SparsePRT::reset_for_cleanup_tasks() {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   419
  _head_expanded_list = NULL;
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   420
}
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   421
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   422
void SparsePRT::do_cleanup_work(SparsePRTCleanupTask* sprt_cleanup_task) {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   423
  if (should_be_on_expanded_list()) {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   424
    sprt_cleanup_task->add(this);
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   425
  }
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   426
}
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   427
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   428
void SparsePRT::finish_cleanup_task(SparsePRTCleanupTask* sprt_cleanup_task) {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   429
  assert(ParGCRareEvent_lock->owned_by_self(), "pre-condition");
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   430
  SparsePRT* head = sprt_cleanup_task->head();
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   431
  SparsePRT* tail = sprt_cleanup_task->tail();
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   432
  if (head != NULL) {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   433
    assert(tail != NULL, "if head is not NULL, so should tail");
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   434
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   435
    tail->set_next_expanded(_head_expanded_list);
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   436
    _head_expanded_list = head;
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   437
  } else {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   438
    assert(tail == NULL, "if head is NULL, so should tail");
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   439
  }
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   440
}
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   441
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   442
bool SparsePRT::should_be_on_expanded_list() {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   443
  if (_expanded) {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   444
    assert(_cur != _next, "if _expanded is true, cur should be != _next");
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   445
  } else {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   446
    assert(_cur == _next, "if _expanded is false, cur should be == _next");
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   447
  }
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   448
  return expanded();
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   449
}
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   450
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   451
void SparsePRT::cleanup_all() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   452
  // 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
   453
  SparsePRT* sprt = get_from_expanded_list();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   454
  while (sprt != NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   455
    sprt->cleanup();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   456
    sprt = get_from_expanded_list();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   457
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   458
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   459
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
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
   462
  _hr(hr), _expanded(false), _next_expanded(NULL)
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   463
{
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   464
  _cur = new RSHashTable(InitialCapacity);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   465
  _next = _cur;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   466
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   467
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   468
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   469
SparsePRT::~SparsePRT() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   470
  assert(_next != NULL && _cur != NULL, "Inv");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   471
  if (_cur != _next) { delete _cur; }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   472
  delete _next;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   473
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   474
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
size_t SparsePRT::mem_size() const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   477
  // 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
   478
  // on the deleted list.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   479
  return sizeof(this) + _next->mem_size();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   480
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   481
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   482
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
   483
#if SPARSE_PRT_VERBOSE
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8072
diff changeset
   484
  gclog_or_tty->print_cr("  Adding card %d from region %d to region "
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8072
diff changeset
   485
                         SIZE_FORMAT" sparse.",
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8072
diff changeset
   486
                         card_index, region_id, _hr->hrs_index());
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   487
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   488
  if (_next->occupied_entries() * 2 > _next->capacity()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   489
    expand();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   490
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   491
  return _next->add_card(region_id, card_index);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   492
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   493
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   494
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
   495
  return _next->get_cards(region_id, cards);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   496
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   497
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   498
SparsePRTEntry* SparsePRT::get_entry(RegionIdx_t region_id) {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   499
  return _next->get_entry(region_id);
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   500
}
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   501
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   502
bool SparsePRT::delete_entry(RegionIdx_t region_id) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   503
  return _next->delete_entry(region_id);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   504
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   505
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   506
void SparsePRT::clear() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   507
  // 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
   508
  // being the initial size.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   509
  if (_next != _cur) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   510
    delete _next;
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
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   513
  if (_cur->capacity() != InitialCapacity) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   514
    delete _cur;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   515
    _cur = new RSHashTable(InitialCapacity);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   516
  } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   517
    _cur->clear();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   518
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   519
  _next = _cur;
8072
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   520
  _expanded = false;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   521
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   522
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   523
void SparsePRT::cleanup() {
4100
4f43ba12619a 6870843: G1: G1 GC memory leak
apetrusenko
parents: 3697
diff changeset
   524
  // Make sure that the current and next tables agree.
4f43ba12619a 6870843: G1: G1 GC memory leak
apetrusenko
parents: 3697
diff changeset
   525
  if (_cur != _next) {
4f43ba12619a 6870843: G1: G1 GC memory leak
apetrusenko
parents: 3697
diff changeset
   526
    delete _cur;
4f43ba12619a 6870843: G1: G1 GC memory leak
apetrusenko
parents: 3697
diff changeset
   527
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   528
  _cur = _next;
2143
61babb9fbd6f 6810698: G1: two small bugs in the sparse remembered sets
tonyp
parents: 1374
diff changeset
   529
  set_expanded(false);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   530
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   531
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   532
void SparsePRT::expand() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   533
  RSHashTable* last = _next;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   534
  _next = new RSHashTable(last->capacity() * 2);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   535
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   536
#if SPARSE_PRT_VERBOSE
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8072
diff changeset
   537
  gclog_or_tty->print_cr("  Expanded sparse table for "SIZE_FORMAT" to %d.",
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8072
diff changeset
   538
                         _hr->hrs_index(), _next->capacity());
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   539
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   540
  for (size_t i = 0; i < last->capacity(); i++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   541
    SparsePRTEntry* e = last->entry((int)i);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   542
    if (e->valid_entry()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   543
#if SPARSE_PRT_VERBOSE
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   544
      gclog_or_tty->print_cr("    During expansion, transferred entry for %d.",
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   545
                    e->r_ind());
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   546
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   547
      _next->add_entry(e);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   548
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   549
  }
4100
4f43ba12619a 6870843: G1: G1 GC memory leak
apetrusenko
parents: 3697
diff changeset
   550
  if (last != _cur) {
4f43ba12619a 6870843: G1: G1 GC memory leak
apetrusenko
parents: 3697
diff changeset
   551
    delete last;
4f43ba12619a 6870843: G1: G1 GC memory leak
apetrusenko
parents: 3697
diff changeset
   552
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   553
  add_to_expanded_list(this);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   554
}
8072
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   555
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   556
void SparsePRTCleanupTask::add(SparsePRT* sprt) {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   557
  assert(sprt->should_be_on_expanded_list(), "pre-condition");
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   558
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   559
  sprt->set_next_expanded(NULL);
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   560
  if (_tail != NULL) {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   561
    _tail->set_next_expanded(sprt);
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   562
  } else {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   563
    _head = sprt;
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   564
  }
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   565
  _tail = sprt;
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   566
}