hotspot/src/share/vm/gc/g1/sparsePRT.cpp
author pliden
Wed, 13 May 2015 15:16:06 +0200
changeset 30764 fec48bf5a827
parent 27880 hotspot/src/share/vm/gc_implementation/g1/sparsePRT.cpp@afb974a04396
child 30772 fe109817cc79
permissions -rw-r--r--
8079792: GC directory structure cleanup Reviewed-by: brutisso, stefank, david
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
/*
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 27880
diff changeset
     2
 * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     4
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     8
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    13
 * accompanied this code).
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    14
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4902
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4902
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4902
diff changeset
    21
 * questions.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    22
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    23
 */
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6983
diff changeset
    25
#include "precompiled.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 27880
diff changeset
    26
#include "gc/g1/heapRegion.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 27880
diff changeset
    27
#include "gc/g1/heapRegionRemSet.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 27880
diff changeset
    28
#include "gc/g1/sparsePRT.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 27880
diff changeset
    29
#include "gc/shared/cardTableModRefBS.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 27880
diff changeset
    30
#include "gc/shared/space.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6983
diff changeset
    31
#include "memory/allocation.inline.hpp"
25351
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24464
diff changeset
    32
#include "runtime/atomic.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6983
diff changeset
    33
#include "runtime/mutexLocker.hpp"
1374
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
#define SPARSE_PRT_VERBOSE 0
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    36
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    37
#define UNROLL_CARD_LOOPS  1
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    38
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
    39
void SparsePRTEntry::init(RegionIdx_t region_ind) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    40
  _region_ind = region_ind;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    41
  _next_index = NullEntry;
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    42
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    43
#if UNROLL_CARD_LOOPS
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    44
  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
    45
  for (int i = 0; i < cards_num(); i += UnrollFactor) {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    46
    _cards[i] = NullEntry;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    47
    _cards[i + 1] = NullEntry;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    48
    _cards[i + 2] = NullEntry;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    49
    _cards[i + 3] = NullEntry;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    50
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    51
#else
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    52
  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
    53
    _cards[i] = NullEntry;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    54
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    55
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    56
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
    57
bool SparsePRTEntry::contains_card(CardIdx_t card_index) const {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    58
#if UNROLL_CARD_LOOPS
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    59
  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
    60
  for (int i = 0; i < cards_num(); i += UnrollFactor) {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    61
    if (_cards[i] == card_index ||
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    62
        _cards[i + 1] == card_index ||
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    63
        _cards[i + 2] == card_index ||
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    64
        _cards[i + 3] == card_index) return true;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    65
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    66
#else
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    67
  for (int i = 0; i < cards_num(); i++) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    68
    if (_cards[i] == card_index) return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    69
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    70
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    71
  // Otherwise, we're full.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    72
  return false;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    73
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    74
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    75
int SparsePRTEntry::num_valid_cards() const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    76
  int sum = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    77
#if UNROLL_CARD_LOOPS
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    78
  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
    79
  for (int i = 0; i < cards_num(); i += UnrollFactor) {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    80
    sum += (_cards[i] != NullEntry);
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    81
    sum += (_cards[i + 1] != NullEntry);
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    82
    sum += (_cards[i + 2] != NullEntry);
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    83
    sum += (_cards[i + 3] != NullEntry);
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    84
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    85
#else
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    86
  for (int i = 0; i < cards_num(); i++) {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    87
    sum += (_cards[i] != NullEntry);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    88
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    89
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    90
  // Otherwise, we're full.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    91
  return sum;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    92
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    93
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
    94
SparsePRTEntry::AddCardResult SparsePRTEntry::add_card(CardIdx_t card_index) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    95
#if UNROLL_CARD_LOOPS
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    96
  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
    97
  CardIdx_t c;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    98
  for (int i = 0; i < cards_num(); i += UnrollFactor) {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    99
    c = _cards[i];
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] = card_index; return added; }
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   102
    c = _cards[i + 1];
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 + 1] = card_index; return added; }
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   105
    c = _cards[i + 2];
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 + 2] = card_index; return added; }
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   108
    c = _cards[i + 3];
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 + 3] = card_index; return added; }
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   111
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   112
#else
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   113
  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
   114
    CardIdx_t c = _cards[i];
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   115
    if (c == card_index) return found;
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   116
    if (c == NullEntry) { _cards[i] = card_index; return added; }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   117
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   118
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   119
  // Otherwise, we're full.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   120
  return overflow;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   121
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   122
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   123
void SparsePRTEntry::copy_cards(CardIdx_t* cards) const {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   124
#if UNROLL_CARD_LOOPS
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   125
  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
   126
  for (int i = 0; i < cards_num(); i += UnrollFactor) {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   127
    cards[i] = _cards[i];
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   128
    cards[i + 1] = _cards[i + 1];
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   129
    cards[i + 2] = _cards[i + 2];
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   130
    cards[i + 3] = _cards[i + 3];
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   131
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   132
#else
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   133
  for (int i = 0; i < cards_num(); i++) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   134
    cards[i] = _cards[i];
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
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   137
}
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
void SparsePRTEntry::copy_cards(SparsePRTEntry* e) const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   140
  copy_cards(&e->_cards[0]);
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
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   143
// ----------------------------------------------------------------------
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
RSHashTable::RSHashTable(size_t capacity) :
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   146
  _capacity(capacity), _capacity_mask(capacity-1),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   147
  _occupied_entries(0), _occupied_cards(0),
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12381
diff changeset
   148
  _entries((SparsePRTEntry*)NEW_C_HEAP_ARRAY(char, SparsePRTEntry::size() * capacity, mtGC)),
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12381
diff changeset
   149
  _buckets(NEW_C_HEAP_ARRAY(int, capacity, mtGC)),
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   150
  _free_list(NullEntry), _free_region(0)
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
  clear();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   153
}
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
RSHashTable::~RSHashTable() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   156
  if (_entries != NULL) {
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 26316
diff changeset
   157
    FREE_C_HEAP_ARRAY(SparsePRTEntry, _entries);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   158
    _entries = NULL;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   159
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   160
  if (_buckets != NULL) {
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 26316
diff changeset
   161
    FREE_C_HEAP_ARRAY(int, _buckets);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   162
    _buckets = NULL;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   163
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   164
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   165
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   166
void RSHashTable::clear() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   167
  _occupied_entries = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   168
  _occupied_cards = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   169
  guarantee(_entries != NULL, "INV");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   170
  guarantee(_buckets != NULL, "INV");
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   171
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   172
  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
   173
                "_capacity too large");
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   174
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   175
  // 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
   176
  memset(_entries, NullEntry, _capacity * SparsePRTEntry::size());
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   177
  memset(_buckets, NullEntry, _capacity * sizeof(int));
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   178
  _free_list = NullEntry;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   179
  _free_region = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   180
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   181
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   182
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
   183
  SparsePRTEntry* e = entry_for_region_ind_create(region_ind);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   184
  assert(e != NULL && e->r_ind() == region_ind,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   185
         "Postcondition of call above.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   186
  SparsePRTEntry::AddCardResult res = e->add_card(card_index);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   187
  if (res == SparsePRTEntry::added) _occupied_cards++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   188
#if SPARSE_PRT_VERBOSE
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   189
  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
   190
                         pointer_delta(e, _entries, SparsePRTEntry::size()),
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   191
                         e->num_valid_cards());
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   192
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   193
  assert(e->num_valid_cards() > 0, "Postcondition");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   194
  return res != SparsePRTEntry::overflow;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   195
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   196
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   197
bool RSHashTable::get_cards(RegionIdx_t region_ind, CardIdx_t* cards) {
24464
901aa0dcba08 8042474: Clean up duplicated code in RSHashTable
brutisso
parents: 24108
diff changeset
   198
  SparsePRTEntry* entry = get_entry(region_ind);
901aa0dcba08 8042474: Clean up duplicated code in RSHashTable
brutisso
parents: 24108
diff changeset
   199
  if (entry == NULL) {
901aa0dcba08 8042474: Clean up duplicated code in RSHashTable
brutisso
parents: 24108
diff changeset
   200
    return false;
1374
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
  // Otherwise...
24464
901aa0dcba08 8042474: Clean up duplicated code in RSHashTable
brutisso
parents: 24108
diff changeset
   203
  entry->copy_cards(cards);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   204
  return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   205
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   206
24464
901aa0dcba08 8042474: Clean up duplicated code in RSHashTable
brutisso
parents: 24108
diff changeset
   207
SparsePRTEntry* RSHashTable::get_entry(RegionIdx_t region_ind) const {
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   208
  int ind = (int) (region_ind & capacity_mask());
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   209
  int cur_ind = _buckets[ind];
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   210
  SparsePRTEntry* cur;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   211
  while (cur_ind != NullEntry &&
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   212
         (cur = entry(cur_ind))->r_ind() != region_ind) {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   213
    cur_ind = cur->next_index();
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   214
  }
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   215
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   216
  if (cur_ind == NullEntry) return NULL;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   217
  // Otherwise...
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   218
  assert(cur->r_ind() == region_ind, "Postcondition of loop + test above.");
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   219
  assert(cur->num_valid_cards() > 0, "Inv");
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   220
  return cur;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   221
}
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   222
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   223
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
   224
  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
   225
  int* prev_loc = &_buckets[ind];
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   226
  int cur_ind = *prev_loc;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   227
  SparsePRTEntry* cur;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   228
  while (cur_ind != NullEntry &&
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   229
         (cur = entry(cur_ind))->r_ind() != region_ind) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   230
    prev_loc = cur->next_index_addr();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   231
    cur_ind = *prev_loc;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   232
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   233
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   234
  if (cur_ind == NullEntry) return false;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   235
  // Otherwise, splice out "cur".
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   236
  *prev_loc = cur->next_index();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   237
  _occupied_cards -= cur->num_valid_cards();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   238
  free_entry(cur_ind);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   239
  _occupied_entries--;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   240
  return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   241
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   242
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   243
SparsePRTEntry*
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   244
RSHashTable::entry_for_region_ind_create(RegionIdx_t region_ind) {
24464
901aa0dcba08 8042474: Clean up duplicated code in RSHashTable
brutisso
parents: 24108
diff changeset
   245
  SparsePRTEntry* res = get_entry(region_ind);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   246
  if (res == NULL) {
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   247
    int new_ind = alloc_entry();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   248
    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
   249
    res = entry(new_ind);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   250
    res->init(region_ind);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   251
    // Insert at front.
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   252
    int ind = (int) (region_ind & capacity_mask());
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   253
    res->set_next_index(_buckets[ind]);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   254
    _buckets[ind] = new_ind;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   255
    _occupied_entries++;
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
  return res;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   258
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   259
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   260
int RSHashTable::alloc_entry() {
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   261
  int res;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   262
  if (_free_list != NullEntry) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   263
    res = _free_list;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   264
    _free_list = entry(res)->next_index();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   265
    return res;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   266
  } else if ((size_t) _free_region+1 < capacity()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   267
    res = _free_region;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   268
    _free_region++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   269
    return res;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   270
  } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   271
    return NullEntry;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   272
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   273
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   274
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   275
void RSHashTable::free_entry(int fi) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   276
  entry(fi)->set_next_index(_free_list);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   277
  _free_list = fi;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   278
}
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
void RSHashTable::add_entry(SparsePRTEntry* e) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   281
  assert(e->num_valid_cards() > 0, "Precondition.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   282
  SparsePRTEntry* e2 = entry_for_region_ind_create(e->r_ind());
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   283
  e->copy_cards(e2);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   284
  _occupied_cards += e2->num_valid_cards();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   285
  assert(e2->num_valid_cards() > 0, "Postcondition.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   286
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   287
6983
a8c50cedbce9 6991377: G1: race between concurrent refinement and humongous object allocation
tonyp
parents: 6981
diff changeset
   288
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
   289
  CardIdx_t res;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   290
  while (_bl_ind != RSHashTable::NullEntry) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   291
    res = _rsht->entry(_bl_ind)->card(0);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   292
    if (res != SparsePRTEntry::NullEntry) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   293
      return res;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   294
    } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   295
      _bl_ind = _rsht->entry(_bl_ind)->next_index();
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
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   298
  // Otherwise, none found:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   299
  return SparsePRTEntry::NullEntry;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   300
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   301
6983
a8c50cedbce9 6991377: G1: race between concurrent refinement and humongous object allocation
tonyp
parents: 6981
diff changeset
   302
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
   303
  return (_rsht->entry(_bl_ind)->r_ind() * HeapRegion::CardsPerRegion) + ci;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   304
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   305
6983
a8c50cedbce9 6991377: G1: race between concurrent refinement and humongous object allocation
tonyp
parents: 6981
diff changeset
   306
bool RSHashTableIter::has_next(size_t& card_index) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   307
  _card_ind++;
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   308
  CardIdx_t ci;
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   309
  if (_card_ind < SparsePRTEntry::cards_num() &&
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   310
      ((ci = _rsht->entry(_bl_ind)->card(_card_ind)) !=
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   311
       SparsePRTEntry::NullEntry)) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   312
    card_index = compute_card_ind(ci);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   313
    return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   314
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   315
  // Otherwise, must find the next valid entry.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   316
  _card_ind = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   317
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   318
  if (_bl_ind != RSHashTable::NullEntry) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   319
      _bl_ind = _rsht->entry(_bl_ind)->next_index();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   320
      ci = find_first_card_in_list();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   321
      if (ci != SparsePRTEntry::NullEntry) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   322
        card_index = compute_card_ind(ci);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   323
        return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   324
      }
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
  // 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
   327
  _tbl_ind++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   328
  while ((size_t)_tbl_ind < _rsht->capacity()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   329
    _bl_ind = _rsht->_buckets[_tbl_ind];
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   330
    ci = find_first_card_in_list();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   331
    if (ci != SparsePRTEntry::NullEntry) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   332
      card_index = compute_card_ind(ci);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   333
      return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   334
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   335
    // Otherwise, try next entry.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   336
    _tbl_ind++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   337
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   338
  // Otherwise, there were no entry.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   339
  return false;
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
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   342
bool RSHashTable::contains_card(RegionIdx_t region_index, CardIdx_t card_index) const {
24464
901aa0dcba08 8042474: Clean up duplicated code in RSHashTable
brutisso
parents: 24108
diff changeset
   343
  SparsePRTEntry* e = get_entry(region_index);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   344
  return (e != NULL && e->contains_card(card_index));
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   345
}
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
size_t RSHashTable::mem_size() const {
24108
dfc2242fc6b0 8040792: G1: Memory usage calculation uses sizeof(this) instead of sizeof(classname)
tschatzl
parents: 22234
diff changeset
   348
  return sizeof(RSHashTable) +
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   349
    capacity() * (SparsePRTEntry::size() + sizeof(int));
1374
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
// ----------------------------------------------------------------------
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
SparsePRT* SparsePRT::_head_expanded_list = NULL;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   355
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   356
void SparsePRT::add_to_expanded_list(SparsePRT* sprt) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   357
  // 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
   358
  if (sprt->expanded()) return;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   359
  sprt->set_expanded(true);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   360
  SparsePRT* hd = _head_expanded_list;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   361
  while (true) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   362
    sprt->_next_expanded = hd;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   363
    SparsePRT* res =
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   364
      (SparsePRT*)
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   365
      Atomic::cmpxchg_ptr(sprt, &_head_expanded_list, hd);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   366
    if (res == hd) return;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   367
    else hd = res;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   368
  }
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
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   372
SparsePRT* SparsePRT::get_from_expanded_list() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   373
  SparsePRT* hd = _head_expanded_list;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   374
  while (hd != NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   375
    SparsePRT* next = hd->next_expanded();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   376
    SparsePRT* res =
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   377
      (SparsePRT*)
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   378
      Atomic::cmpxchg_ptr(next, &_head_expanded_list, hd);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   379
    if (res == hd) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   380
      hd->set_next_expanded(NULL);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   381
      return hd;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   382
    } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   383
      hd = res;
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
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   386
  return NULL;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   387
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   388
8072
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   389
void SparsePRT::reset_for_cleanup_tasks() {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   390
  _head_expanded_list = NULL;
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   391
}
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   392
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   393
void SparsePRT::do_cleanup_work(SparsePRTCleanupTask* sprt_cleanup_task) {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   394
  if (should_be_on_expanded_list()) {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   395
    sprt_cleanup_task->add(this);
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   396
  }
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   397
}
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   398
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   399
void SparsePRT::finish_cleanup_task(SparsePRTCleanupTask* sprt_cleanup_task) {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   400
  assert(ParGCRareEvent_lock->owned_by_self(), "pre-condition");
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   401
  SparsePRT* head = sprt_cleanup_task->head();
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   402
  SparsePRT* tail = sprt_cleanup_task->tail();
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   403
  if (head != NULL) {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   404
    assert(tail != NULL, "if head is not NULL, so should tail");
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   405
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   406
    tail->set_next_expanded(_head_expanded_list);
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   407
    _head_expanded_list = head;
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   408
  } else {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   409
    assert(tail == NULL, "if head is NULL, so should tail");
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   410
  }
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   411
}
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   412
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   413
bool SparsePRT::should_be_on_expanded_list() {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   414
  if (_expanded) {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   415
    assert(_cur != _next, "if _expanded is true, cur should be != _next");
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   416
  } else {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   417
    assert(_cur == _next, "if _expanded is false, cur should be == _next");
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   418
  }
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   419
  return expanded();
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   420
}
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   421
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   422
void SparsePRT::cleanup_all() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   423
  // 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
   424
  SparsePRT* sprt = get_from_expanded_list();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   425
  while (sprt != NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   426
    sprt->cleanup();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   427
    sprt = get_from_expanded_list();
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
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   430
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
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
   433
  _hr(hr), _expanded(false), _next_expanded(NULL)
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   434
{
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   435
  _cur = new RSHashTable(InitialCapacity);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   436
  _next = _cur;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   437
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   438
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   439
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   440
SparsePRT::~SparsePRT() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   441
  assert(_next != NULL && _cur != NULL, "Inv");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   442
  if (_cur != _next) { delete _cur; }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   443
  delete _next;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   444
}
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
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   447
size_t SparsePRT::mem_size() const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   448
  // 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
   449
  // on the deleted list.
24108
dfc2242fc6b0 8040792: G1: Memory usage calculation uses sizeof(this) instead of sizeof(classname)
tschatzl
parents: 22234
diff changeset
   450
  return sizeof(SparsePRT) + _next->mem_size();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   451
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   452
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   453
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
   454
#if SPARSE_PRT_VERBOSE
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
   455
  gclog_or_tty->print_cr("  Adding card %d from region %d to region %u sparse.",
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 25351
diff changeset
   456
                         card_index, region_id, _hr->hrm_index());
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   457
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   458
  if (_next->occupied_entries() * 2 > _next->capacity()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   459
    expand();
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
  return _next->add_card(region_id, card_index);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   462
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   463
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   464
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
   465
  return _next->get_cards(region_id, cards);
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
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   468
SparsePRTEntry* SparsePRT::get_entry(RegionIdx_t region_id) {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   469
  return _next->get_entry(region_id);
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   470
}
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   471
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   472
bool SparsePRT::delete_entry(RegionIdx_t region_id) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   473
  return _next->delete_entry(region_id);
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
void SparsePRT::clear() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   477
  // 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
   478
  // being the initial size.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   479
  if (_next != _cur) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   480
    delete _next;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   481
  }
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
  if (_cur->capacity() != InitialCapacity) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   484
    delete _cur;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   485
    _cur = new RSHashTable(InitialCapacity);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   486
  } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   487
    _cur->clear();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   488
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   489
  _next = _cur;
8072
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   490
  _expanded = false;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   491
}
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
void SparsePRT::cleanup() {
4100
4f43ba12619a 6870843: G1: G1 GC memory leak
apetrusenko
parents: 3697
diff changeset
   494
  // Make sure that the current and next tables agree.
4f43ba12619a 6870843: G1: G1 GC memory leak
apetrusenko
parents: 3697
diff changeset
   495
  if (_cur != _next) {
4f43ba12619a 6870843: G1: G1 GC memory leak
apetrusenko
parents: 3697
diff changeset
   496
    delete _cur;
4f43ba12619a 6870843: G1: G1 GC memory leak
apetrusenko
parents: 3697
diff changeset
   497
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   498
  _cur = _next;
2143
61babb9fbd6f 6810698: G1: two small bugs in the sparse remembered sets
tonyp
parents: 1374
diff changeset
   499
  set_expanded(false);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   500
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   501
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   502
void SparsePRT::expand() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   503
  RSHashTable* last = _next;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   504
  _next = new RSHashTable(last->capacity() * 2);
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
#if SPARSE_PRT_VERBOSE
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
   507
  gclog_or_tty->print_cr("  Expanded sparse table for %u to %d.",
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 25351
diff changeset
   508
                         _hr->hrm_index(), _next->capacity());
1374
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
  for (size_t i = 0; i < last->capacity(); i++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   511
    SparsePRTEntry* e = last->entry((int)i);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   512
    if (e->valid_entry()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   513
#if SPARSE_PRT_VERBOSE
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   514
      gclog_or_tty->print_cr("    During expansion, transferred entry for %d.",
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   515
                    e->r_ind());
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   516
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   517
      _next->add_entry(e);
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
  }
4100
4f43ba12619a 6870843: G1: G1 GC memory leak
apetrusenko
parents: 3697
diff changeset
   520
  if (last != _cur) {
4f43ba12619a 6870843: G1: G1 GC memory leak
apetrusenko
parents: 3697
diff changeset
   521
    delete last;
4f43ba12619a 6870843: G1: G1 GC memory leak
apetrusenko
parents: 3697
diff changeset
   522
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   523
  add_to_expanded_list(this);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   524
}
8072
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   525
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   526
void SparsePRTCleanupTask::add(SparsePRT* sprt) {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   527
  assert(sprt->should_be_on_expanded_list(), "pre-condition");
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   528
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   529
  sprt->set_next_expanded(NULL);
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   530
  if (_tail != NULL) {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   531
    _tail->set_next_expanded(sprt);
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   532
  } else {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   533
    _head = sprt;
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   534
  }
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   535
  _tail = sprt;
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   536
}