hotspot/src/share/vm/gc/g1/sparsePRT.cpp
author ecaspole
Mon, 21 Sep 2015 10:36:36 -0400
changeset 33093 5aa0f908f8cd
parent 30772 fe109817cc79
child 33741 7d2494a226aa
permissions -rw-r--r--
8131645: [ARM64] crash on Cavium when using G1 Summary: Add a fence when creating the CodeRootSetTable so the readers do not see invalid memory. Reviewed-by: aph, tschatzl
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
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
    37
void SparsePRTEntry::init(RegionIdx_t region_ind) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    38
  _region_ind = region_ind;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    39
  _next_index = NullEntry;
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    40
30772
fe109817cc79 8047330: Remove unrolled card loops in G1 SparsePRTEntry
brutisso
parents: 30764
diff changeset
    41
  for (int i = 0; i < cards_num(); i++) {
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    42
    _cards[i] = NullEntry;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    43
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    44
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    45
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
    46
bool SparsePRTEntry::contains_card(CardIdx_t card_index) const {
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    47
  for (int i = 0; i < cards_num(); i++) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    48
    if (_cards[i] == card_index) return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    49
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    50
  return false;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    51
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    52
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    53
int SparsePRTEntry::num_valid_cards() const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    54
  int sum = 0;
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    55
  for (int i = 0; i < cards_num(); i++) {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    56
    sum += (_cards[i] != NullEntry);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    57
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    58
  return sum;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    59
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    60
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
    61
SparsePRTEntry::AddCardResult SparsePRTEntry::add_card(CardIdx_t card_index) {
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    62
  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
    63
    CardIdx_t c = _cards[i];
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    64
    if (c == card_index) return found;
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
    65
    if (c == NullEntry) { _cards[i] = card_index; return added; }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    66
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    67
  // Otherwise, we're full.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    68
  return overflow;
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
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
    71
void SparsePRTEntry::copy_cards(CardIdx_t* cards) const {
30772
fe109817cc79 8047330: Remove unrolled card loops in G1 SparsePRTEntry
brutisso
parents: 30764
diff changeset
    72
  memcpy(cards, _cards, cards_num() * sizeof(CardIdx_t));
1374
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
void SparsePRTEntry::copy_cards(SparsePRTEntry* e) const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    76
  copy_cards(&e->_cards[0]);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    77
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    78
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    79
// ----------------------------------------------------------------------
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    80
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    81
RSHashTable::RSHashTable(size_t capacity) :
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    82
  _capacity(capacity), _capacity_mask(capacity-1),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    83
  _occupied_entries(0), _occupied_cards(0),
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12381
diff changeset
    84
  _entries((SparsePRTEntry*)NEW_C_HEAP_ARRAY(char, SparsePRTEntry::size() * capacity, mtGC)),
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12381
diff changeset
    85
  _buckets(NEW_C_HEAP_ARRAY(int, capacity, mtGC)),
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    86
  _free_list(NullEntry), _free_region(0)
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    87
{
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    88
  clear();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    89
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    90
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    91
RSHashTable::~RSHashTable() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    92
  if (_entries != NULL) {
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 26316
diff changeset
    93
    FREE_C_HEAP_ARRAY(SparsePRTEntry, _entries);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    94
    _entries = NULL;
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
  if (_buckets != NULL) {
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 26316
diff changeset
    97
    FREE_C_HEAP_ARRAY(int, _buckets);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    98
    _buckets = NULL;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    99
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   100
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   101
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   102
void RSHashTable::clear() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   103
  _occupied_entries = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   104
  _occupied_cards = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   105
  guarantee(_entries != NULL, "INV");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   106
  guarantee(_buckets != NULL, "INV");
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   107
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   108
  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
   109
                "_capacity too large");
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   110
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   111
  // 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
   112
  memset(_entries, NullEntry, _capacity * SparsePRTEntry::size());
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   113
  memset(_buckets, NullEntry, _capacity * sizeof(int));
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   114
  _free_list = NullEntry;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   115
  _free_region = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   116
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   117
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   118
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
   119
  SparsePRTEntry* e = entry_for_region_ind_create(region_ind);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   120
  assert(e != NULL && e->r_ind() == region_ind,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   121
         "Postcondition of call above.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   122
  SparsePRTEntry::AddCardResult res = e->add_card(card_index);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   123
  if (res == SparsePRTEntry::added) _occupied_cards++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   124
#if SPARSE_PRT_VERBOSE
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   125
  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
   126
                         pointer_delta(e, _entries, SparsePRTEntry::size()),
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   127
                         e->num_valid_cards());
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   128
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   129
  assert(e->num_valid_cards() > 0, "Postcondition");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   130
  return res != SparsePRTEntry::overflow;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   131
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   132
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   133
bool RSHashTable::get_cards(RegionIdx_t region_ind, CardIdx_t* cards) {
24464
901aa0dcba08 8042474: Clean up duplicated code in RSHashTable
brutisso
parents: 24108
diff changeset
   134
  SparsePRTEntry* entry = get_entry(region_ind);
901aa0dcba08 8042474: Clean up duplicated code in RSHashTable
brutisso
parents: 24108
diff changeset
   135
  if (entry == NULL) {
901aa0dcba08 8042474: Clean up duplicated code in RSHashTable
brutisso
parents: 24108
diff changeset
   136
    return false;
1374
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
  // Otherwise...
24464
901aa0dcba08 8042474: Clean up duplicated code in RSHashTable
brutisso
parents: 24108
diff changeset
   139
  entry->copy_cards(cards);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   140
  return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   141
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   142
24464
901aa0dcba08 8042474: Clean up duplicated code in RSHashTable
brutisso
parents: 24108
diff changeset
   143
SparsePRTEntry* RSHashTable::get_entry(RegionIdx_t region_ind) const {
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   144
  int ind = (int) (region_ind & capacity_mask());
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   145
  int cur_ind = _buckets[ind];
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   146
  SparsePRTEntry* cur;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   147
  while (cur_ind != NullEntry &&
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   148
         (cur = entry(cur_ind))->r_ind() != region_ind) {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   149
    cur_ind = cur->next_index();
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   150
  }
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   151
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   152
  if (cur_ind == NullEntry) return NULL;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   153
  // Otherwise...
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   154
  assert(cur->r_ind() == region_ind, "Postcondition of loop + test above.");
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   155
  assert(cur->num_valid_cards() > 0, "Inv");
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   156
  return cur;
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   157
}
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   158
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   159
bool RSHashTable::delete_entry(RegionIdx_t region_ind) {
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   160
  int ind = (int) (region_ind & capacity_mask());
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   161
  int* prev_loc = &_buckets[ind];
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   162
  int cur_ind = *prev_loc;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   163
  SparsePRTEntry* cur;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   164
  while (cur_ind != NullEntry &&
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   165
         (cur = entry(cur_ind))->r_ind() != region_ind) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   166
    prev_loc = cur->next_index_addr();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   167
    cur_ind = *prev_loc;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   168
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   169
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   170
  if (cur_ind == NullEntry) return false;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   171
  // Otherwise, splice out "cur".
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   172
  *prev_loc = cur->next_index();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   173
  _occupied_cards -= cur->num_valid_cards();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   174
  free_entry(cur_ind);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   175
  _occupied_entries--;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   176
  return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   177
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   178
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   179
SparsePRTEntry*
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   180
RSHashTable::entry_for_region_ind_create(RegionIdx_t region_ind) {
24464
901aa0dcba08 8042474: Clean up duplicated code in RSHashTable
brutisso
parents: 24108
diff changeset
   181
  SparsePRTEntry* res = get_entry(region_ind);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   182
  if (res == NULL) {
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   183
    int new_ind = alloc_entry();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   184
    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
   185
    res = entry(new_ind);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   186
    res->init(region_ind);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   187
    // Insert at front.
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   188
    int ind = (int) (region_ind & capacity_mask());
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   189
    res->set_next_index(_buckets[ind]);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   190
    _buckets[ind] = new_ind;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   191
    _occupied_entries++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   192
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   193
  return res;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   194
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   195
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   196
int RSHashTable::alloc_entry() {
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   197
  int res;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   198
  if (_free_list != NullEntry) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   199
    res = _free_list;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   200
    _free_list = entry(res)->next_index();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   201
    return res;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   202
  } else if ((size_t) _free_region+1 < capacity()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   203
    res = _free_region;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   204
    _free_region++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   205
    return res;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   206
  } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   207
    return NullEntry;
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
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   210
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   211
void RSHashTable::free_entry(int fi) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   212
  entry(fi)->set_next_index(_free_list);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   213
  _free_list = fi;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   214
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   215
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   216
void RSHashTable::add_entry(SparsePRTEntry* e) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   217
  assert(e->num_valid_cards() > 0, "Precondition.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   218
  SparsePRTEntry* e2 = entry_for_region_ind_create(e->r_ind());
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   219
  e->copy_cards(e2);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   220
  _occupied_cards += e2->num_valid_cards();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   221
  assert(e2->num_valid_cards() > 0, "Postcondition.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   222
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   223
6983
a8c50cedbce9 6991377: G1: race between concurrent refinement and humongous object allocation
tonyp
parents: 6981
diff changeset
   224
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
   225
  CardIdx_t res;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   226
  while (_bl_ind != RSHashTable::NullEntry) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   227
    res = _rsht->entry(_bl_ind)->card(0);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   228
    if (res != SparsePRTEntry::NullEntry) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   229
      return res;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   230
    } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   231
      _bl_ind = _rsht->entry(_bl_ind)->next_index();
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
  // Otherwise, none found:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   235
  return SparsePRTEntry::NullEntry;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   236
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   237
6983
a8c50cedbce9 6991377: G1: race between concurrent refinement and humongous object allocation
tonyp
parents: 6981
diff changeset
   238
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
   239
  return (_rsht->entry(_bl_ind)->r_ind() * HeapRegion::CardsPerRegion) + ci;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   240
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   241
6983
a8c50cedbce9 6991377: G1: race between concurrent refinement and humongous object allocation
tonyp
parents: 6981
diff changeset
   242
bool RSHashTableIter::has_next(size_t& card_index) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   243
  _card_ind++;
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   244
  CardIdx_t ci;
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   245
  if (_card_ind < SparsePRTEntry::cards_num() &&
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   246
      ((ci = _rsht->entry(_bl_ind)->card(_card_ind)) !=
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   247
       SparsePRTEntry::NullEntry)) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   248
    card_index = compute_card_ind(ci);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   249
    return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   250
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   251
  // Otherwise, must find the next valid entry.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   252
  _card_ind = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   253
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   254
  if (_bl_ind != RSHashTable::NullEntry) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   255
      _bl_ind = _rsht->entry(_bl_ind)->next_index();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   256
      ci = find_first_card_in_list();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   257
      if (ci != SparsePRTEntry::NullEntry) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   258
        card_index = compute_card_ind(ci);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   259
        return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   260
      }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   261
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   262
  // If we didn't return above, must go to the next non-null table index.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   263
  _tbl_ind++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   264
  while ((size_t)_tbl_ind < _rsht->capacity()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   265
    _bl_ind = _rsht->_buckets[_tbl_ind];
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   266
    ci = find_first_card_in_list();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   267
    if (ci != SparsePRTEntry::NullEntry) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   268
      card_index = compute_card_ind(ci);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   269
      return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   270
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   271
    // Otherwise, try next entry.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   272
    _tbl_ind++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   273
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   274
  // Otherwise, there were no entry.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   275
  return false;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   276
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   277
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   278
bool RSHashTable::contains_card(RegionIdx_t region_index, CardIdx_t card_index) const {
24464
901aa0dcba08 8042474: Clean up duplicated code in RSHashTable
brutisso
parents: 24108
diff changeset
   279
  SparsePRTEntry* e = get_entry(region_index);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   280
  return (e != NULL && e->contains_card(card_index));
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   281
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   282
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   283
size_t RSHashTable::mem_size() const {
24108
dfc2242fc6b0 8040792: G1: Memory usage calculation uses sizeof(this) instead of sizeof(classname)
tschatzl
parents: 22234
diff changeset
   284
  return sizeof(RSHashTable) +
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   285
    capacity() * (SparsePRTEntry::size() + sizeof(int));
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   286
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   287
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   288
// ----------------------------------------------------------------------
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   289
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   290
SparsePRT* SparsePRT::_head_expanded_list = NULL;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   291
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   292
void SparsePRT::add_to_expanded_list(SparsePRT* sprt) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   293
  // 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
   294
  if (sprt->expanded()) return;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   295
  sprt->set_expanded(true);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   296
  SparsePRT* hd = _head_expanded_list;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   297
  while (true) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   298
    sprt->_next_expanded = hd;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   299
    SparsePRT* res =
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   300
      (SparsePRT*)
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   301
      Atomic::cmpxchg_ptr(sprt, &_head_expanded_list, hd);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   302
    if (res == hd) return;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   303
    else hd = res;
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
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   306
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   307
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   308
SparsePRT* SparsePRT::get_from_expanded_list() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   309
  SparsePRT* hd = _head_expanded_list;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   310
  while (hd != NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   311
    SparsePRT* next = hd->next_expanded();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   312
    SparsePRT* res =
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   313
      (SparsePRT*)
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   314
      Atomic::cmpxchg_ptr(next, &_head_expanded_list, hd);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   315
    if (res == hd) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   316
      hd->set_next_expanded(NULL);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   317
      return hd;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   318
    } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   319
      hd = res;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   320
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   321
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   322
  return NULL;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   323
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   324
8072
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   325
void SparsePRT::reset_for_cleanup_tasks() {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   326
  _head_expanded_list = NULL;
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   327
}
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   328
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   329
void SparsePRT::do_cleanup_work(SparsePRTCleanupTask* sprt_cleanup_task) {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   330
  if (should_be_on_expanded_list()) {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   331
    sprt_cleanup_task->add(this);
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   332
  }
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   333
}
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   334
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   335
void SparsePRT::finish_cleanup_task(SparsePRTCleanupTask* sprt_cleanup_task) {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   336
  assert(ParGCRareEvent_lock->owned_by_self(), "pre-condition");
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   337
  SparsePRT* head = sprt_cleanup_task->head();
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   338
  SparsePRT* tail = sprt_cleanup_task->tail();
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   339
  if (head != NULL) {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   340
    assert(tail != NULL, "if head is not NULL, so should tail");
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   341
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   342
    tail->set_next_expanded(_head_expanded_list);
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   343
    _head_expanded_list = head;
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   344
  } else {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   345
    assert(tail == NULL, "if head is NULL, so should tail");
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   346
  }
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   347
}
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   348
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   349
bool SparsePRT::should_be_on_expanded_list() {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   350
  if (_expanded) {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   351
    assert(_cur != _next, "if _expanded is true, cur should be != _next");
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   352
  } else {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   353
    assert(_cur == _next, "if _expanded is false, cur should be == _next");
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   354
  }
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   355
  return expanded();
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   356
}
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   357
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   358
void SparsePRT::cleanup_all() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   359
  // 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
   360
  SparsePRT* sprt = get_from_expanded_list();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   361
  while (sprt != NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   362
    sprt->cleanup();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   363
    sprt = get_from_expanded_list();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   364
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   365
}
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
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   368
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
   369
  _hr(hr), _expanded(false), _next_expanded(NULL)
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   370
{
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   371
  _cur = new RSHashTable(InitialCapacity);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   372
  _next = _cur;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   373
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   374
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   375
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   376
SparsePRT::~SparsePRT() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   377
  assert(_next != NULL && _cur != NULL, "Inv");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   378
  if (_cur != _next) { delete _cur; }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   379
  delete _next;
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
size_t SparsePRT::mem_size() const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   384
  // 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
   385
  // on the deleted list.
24108
dfc2242fc6b0 8040792: G1: Memory usage calculation uses sizeof(this) instead of sizeof(classname)
tschatzl
parents: 22234
diff changeset
   386
  return sizeof(SparsePRT) + _next->mem_size();
1374
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
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   389
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
   390
#if SPARSE_PRT_VERBOSE
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
   391
  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
   392
                         card_index, region_id, _hr->hrm_index());
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   393
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   394
  if (_next->occupied_entries() * 2 > _next->capacity()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   395
    expand();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   396
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   397
  return _next->add_card(region_id, card_index);
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
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
   401
  return _next->get_cards(region_id, cards);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   402
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   403
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   404
SparsePRTEntry* SparsePRT::get_entry(RegionIdx_t region_id) {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   405
  return _next->get_entry(region_id);
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   406
}
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4100
diff changeset
   407
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2143
diff changeset
   408
bool SparsePRT::delete_entry(RegionIdx_t region_id) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   409
  return _next->delete_entry(region_id);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   410
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   411
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   412
void SparsePRT::clear() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   413
  // 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
   414
  // being the initial size.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   415
  if (_next != _cur) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   416
    delete _next;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   417
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   418
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   419
  if (_cur->capacity() != InitialCapacity) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   420
    delete _cur;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   421
    _cur = new RSHashTable(InitialCapacity);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   422
  } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   423
    _cur->clear();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   424
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   425
  _next = _cur;
8072
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   426
  _expanded = false;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   427
}
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
void SparsePRT::cleanup() {
4100
4f43ba12619a 6870843: G1: G1 GC memory leak
apetrusenko
parents: 3697
diff changeset
   430
  // Make sure that the current and next tables agree.
4f43ba12619a 6870843: G1: G1 GC memory leak
apetrusenko
parents: 3697
diff changeset
   431
  if (_cur != _next) {
4f43ba12619a 6870843: G1: G1 GC memory leak
apetrusenko
parents: 3697
diff changeset
   432
    delete _cur;
4f43ba12619a 6870843: G1: G1 GC memory leak
apetrusenko
parents: 3697
diff changeset
   433
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   434
  _cur = _next;
2143
61babb9fbd6f 6810698: G1: two small bugs in the sparse remembered sets
tonyp
parents: 1374
diff changeset
   435
  set_expanded(false);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   436
}
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
void SparsePRT::expand() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   439
  RSHashTable* last = _next;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   440
  _next = new RSHashTable(last->capacity() * 2);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   441
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   442
#if SPARSE_PRT_VERBOSE
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 9989
diff changeset
   443
  gclog_or_tty->print_cr("  Expanded sparse table for %u to %d.",
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 25351
diff changeset
   444
                         _hr->hrm_index(), _next->capacity());
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   445
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   446
  for (size_t i = 0; i < last->capacity(); i++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   447
    SparsePRTEntry* e = last->entry((int)i);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   448
    if (e->valid_entry()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   449
#if SPARSE_PRT_VERBOSE
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   450
      gclog_or_tty->print_cr("    During expansion, transferred entry for %d.",
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   451
                    e->r_ind());
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   452
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   453
      _next->add_entry(e);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   454
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   455
  }
4100
4f43ba12619a 6870843: G1: G1 GC memory leak
apetrusenko
parents: 3697
diff changeset
   456
  if (last != _cur) {
4f43ba12619a 6870843: G1: G1 GC memory leak
apetrusenko
parents: 3697
diff changeset
   457
    delete last;
4f43ba12619a 6870843: G1: G1 GC memory leak
apetrusenko
parents: 3697
diff changeset
   458
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   459
  add_to_expanded_list(this);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   460
}
8072
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   461
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   462
void SparsePRTCleanupTask::add(SparsePRT* sprt) {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   463
  assert(sprt->should_be_on_expanded_list(), "pre-condition");
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   464
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   465
  sprt->set_next_expanded(NULL);
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   466
  if (_tail != NULL) {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   467
    _tail->set_next_expanded(sprt);
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   468
  } else {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   469
    _head = sprt;
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   470
  }
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   471
  _tail = sprt;
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   472
}