src/hotspot/share/gc/g1/heapRegionRemSet.cpp
author tschatzl
Wed, 04 Apr 2018 14:51:26 +0200
changeset 49672 f1d2b6c0693b
parent 49632 64f9ebc85e67
child 49806 2d62570a615c
permissions -rw-r--r--
8200305: Update gc,liveness output with remset state after rebuild remset concurrently changes Reviewed-by: sjohanss, sangheki
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     1
/*
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 47789
diff changeset
     2
 * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     4
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     8
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    13
 * accompanied this code).
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    14
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5346
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5346
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: 5346
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: 6981
diff changeset
    25
#include "precompiled.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29796
diff changeset
    26
#include "gc/g1/g1BlockOffsetTable.inline.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29796
diff changeset
    27
#include "gc/g1/g1CollectedHeap.inline.hpp"
47789
a77a7d3bc4f6 8149127: Rename g1/concurrentMarkThread.* to g1/g1ConcurrentMarkThread.*
tschatzl
parents: 47634
diff changeset
    28
#include "gc/g1/g1ConcurrentRefine.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29796
diff changeset
    29
#include "gc/g1/heapRegionManager.inline.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29796
diff changeset
    30
#include "gc/g1/heapRegionRemSet.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29796
diff changeset
    31
#include "gc/shared/space.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6981
diff changeset
    32
#include "memory/allocation.hpp"
23452
d7dca4e6b95d 8035815: Cache-align and pad the from card cache
tschatzl
parents: 23451
diff changeset
    33
#include "memory/padded.inline.hpp"
13113
ab3870a79b18 6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents: 12779
diff changeset
    34
#include "oops/oop.inline.hpp"
40655
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 38271
diff changeset
    35
#include "runtime/atomic.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6981
diff changeset
    36
#include "utilities/bitMap.inline.hpp"
46560
388aa8d67c80 8181449: Fix debug.hpp / globalDefinitions.hpp dependency inversion
kbarrett
parents: 43666
diff changeset
    37
#include "utilities/debug.hpp"
388aa8d67c80 8181449: Fix debug.hpp / globalDefinitions.hpp dependency inversion
kbarrett
parents: 43666
diff changeset
    38
#include "utilities/formatBuffer.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6981
diff changeset
    39
#include "utilities/globalDefinitions.hpp"
19339
d247781beec7 7145569: G1: optimize nmethods scanning
johnc
parents: 17631
diff changeset
    40
#include "utilities/growableArray.hpp"
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    41
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49164
diff changeset
    42
const char* HeapRegionRemSet::_state_strings[] =  {"Untracked", "Updating", "Complete"};
49672
f1d2b6c0693b 8200305: Update gc,liveness output with remset state after rebuild remset concurrently changes
tschatzl
parents: 49632
diff changeset
    43
const char* HeapRegionRemSet::_short_state_strings[] =  {"UNTRA", "UPDAT", "CMPLT"};
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49164
diff changeset
    44
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12779
diff changeset
    45
class PerRegionTable: public CHeapObj<mtGC> {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    46
  friend class OtherRegionsTable;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    47
  friend class HeapRegionRemSetIterator;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    48
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    49
  HeapRegion*     _hr;
38177
b0c9cb06506b 8141501: Problems with BitMap buffer management
stefank
parents: 38161
diff changeset
    50
  CHeapBitMap     _bm;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    51
  jint            _occupied;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    52
13335
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
    53
  // next pointer for free/allocated 'all' list
13113
ab3870a79b18 6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents: 12779
diff changeset
    54
  PerRegionTable* _next;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    55
13335
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
    56
  // prev pointer for the allocated 'all' list
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
    57
  PerRegionTable* _prev;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    58
13335
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
    59
  // next pointer in collision list
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
    60
  PerRegionTable * _collision_list_next;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    61
13335
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
    62
  // Global free list of PRTs
41283
2615c024f3eb 8033552: Fix missing missing volatile specifiers in CAS operations in GC code
eosterlund
parents: 40655
diff changeset
    63
  static PerRegionTable* volatile _free_list;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    64
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    65
protected:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    66
  // We need access in order to union things into the base table.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    67
  BitMap* bm() { return &_bm; }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    68
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    69
  PerRegionTable(HeapRegion* hr) :
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    70
    _hr(hr),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    71
    _occupied(0),
46745
f7b9bb98bb72 8176571: Fine bitmaps should be allocated as belonging to mtGC, not mtInternal
kbarrett
parents: 46560
diff changeset
    72
    _bm(HeapRegion::CardsPerRegion, mtGC),
13335
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
    73
    _collision_list_next(NULL), _next(NULL), _prev(NULL)
1374
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
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2882
diff changeset
    76
  void add_card_work(CardIdx_t from_card, bool par) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    77
    if (!_bm.at(from_card)) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    78
      if (par) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    79
        if (_bm.par_at_put(from_card, 1)) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    80
          Atomic::inc(&_occupied);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    81
        }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    82
      } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    83
        _bm.at_put(from_card, 1);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    84
        _occupied++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    85
      }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    86
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    87
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    88
3262
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
    89
  void add_reference_work(OopOrNarrowOopStar from, bool par) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    90
    // Must make this robust in case "from" is not in "_hr", because of
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    91
    // concurrency.
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
    HeapRegion* loc_hr = hr();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    94
    // If the test below fails, then this table was reused concurrently
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    95
    // with this operation.  This is OK, since the old table was coarsened,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    96
    // and adding a bit to the new table is never incorrect.
33786
ac8da6513351 8139867: Change how startsHumongous and continuesHumongous regions work in G1.
david
parents: 33783
diff changeset
    97
    if (loc_hr->is_in_reserved(from)) {
49608
1852b17b0efc 8196485: FromCardCache default card index can cause crashes
tschatzl
parents: 49607
diff changeset
    98
      CardIdx_t from_card = OtherRegionsTable::card_within_region(from, loc_hr);
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2882
diff changeset
    99
      add_card_work(from_card, par);
1374
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
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   103
public:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   104
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47216
diff changeset
   105
  HeapRegion* hr() const { return OrderAccess::load_acquire(&_hr); }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   106
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   107
  jint occupied() const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   108
    // Overkill, but if we ever need it...
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   109
    // guarantee(_occupied == _bm.count_one_bits(), "Check");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   110
    return _occupied;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   111
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   112
13335
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   113
  void init(HeapRegion* hr, bool clear_links_to_all_list) {
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   114
    if (clear_links_to_all_list) {
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   115
      set_next(NULL);
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   116
      set_prev(NULL);
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   117
    }
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   118
    _collision_list_next = NULL;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   119
    _occupied = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   120
    _bm.clear();
35875
8ea0b4b0bcc8 8147087: Race when reusing PerRegionTable bitmaps may result in dropped remembered set entries
tschatzl
parents: 35461
diff changeset
   121
    // Make sure that the bitmap clearing above has been finished before publishing
8ea0b4b0bcc8 8147087: Race when reusing PerRegionTable bitmaps may result in dropped remembered set entries
tschatzl
parents: 35461
diff changeset
   122
    // this PRT to concurrent threads.
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47216
diff changeset
   123
    OrderAccess::release_store(&_hr, hr);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   124
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   125
3262
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
   126
  void add_reference(OopOrNarrowOopStar from) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   127
    add_reference_work(from, /*parallel*/ true);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   128
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   129
3262
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
   130
  void seq_add_reference(OopOrNarrowOopStar from) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   131
    add_reference_work(from, /*parallel*/ false);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   132
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   133
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2882
diff changeset
   134
  void add_card(CardIdx_t from_card_index) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   135
    add_card_work(from_card_index, /*parallel*/ true);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   136
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   137
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2882
diff changeset
   138
  void seq_add_card(CardIdx_t from_card_index) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   139
    add_card_work(from_card_index, /*parallel*/ false);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   140
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   141
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   142
  // (Destructively) union the bitmap of the current table into the given
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   143
  // bitmap (which is assumed to be of the same size.)
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   144
  void union_bitmap_into(BitMap* bm) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   145
    bm->set_union(_bm);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   146
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   147
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   148
  // Mem size in bytes.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   149
  size_t mem_size() const {
24108
dfc2242fc6b0 8040792: G1: Memory usage calculation uses sizeof(this) instead of sizeof(classname)
tschatzl
parents: 24106
diff changeset
   150
    return sizeof(PerRegionTable) + _bm.size_in_words() * HeapWordSize;
1374
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
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   153
  // Requires "from" to be in "hr()".
3262
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
   154
  bool contains_reference(OopOrNarrowOopStar from) const {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   155
    assert(hr()->is_in_reserved(from), "Precondition.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   156
    size_t card_ind = pointer_delta(from, hr()->bottom(),
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 47789
diff changeset
   157
                                    G1CardTable::card_size);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   158
    return _bm.at(card_ind);
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
13335
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   161
  // Bulk-free the PRTs from prt to last, assumes that they are
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   162
  // linked together using their _next field.
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   163
  static void bulk_free(PerRegionTable* prt, PerRegionTable* last) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   164
    while (true) {
13113
ab3870a79b18 6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents: 12779
diff changeset
   165
      PerRegionTable* fl = _free_list;
13335
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   166
      last->set_next(fl);
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47216
diff changeset
   167
      PerRegionTable* res = Atomic::cmpxchg(prt, &_free_list, fl);
13335
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   168
      if (res == fl) {
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   169
        return;
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   170
      }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   171
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   172
    ShouldNotReachHere();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   173
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   174
13335
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   175
  static void free(PerRegionTable* prt) {
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   176
    bulk_free(prt, prt);
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   177
  }
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   178
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   179
  // Returns an initialized PerRegionTable instance.
13113
ab3870a79b18 6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents: 12779
diff changeset
   180
  static PerRegionTable* alloc(HeapRegion* hr) {
ab3870a79b18 6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents: 12779
diff changeset
   181
    PerRegionTable* fl = _free_list;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   182
    while (fl != NULL) {
13113
ab3870a79b18 6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents: 12779
diff changeset
   183
      PerRegionTable* nxt = fl->next();
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47216
diff changeset
   184
      PerRegionTable* res = Atomic::cmpxchg(nxt, &_free_list, fl);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   185
      if (res == fl) {
13335
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   186
        fl->init(hr, true);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   187
        return fl;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   188
      } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   189
        fl = _free_list;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   190
      }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   191
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   192
    assert(fl == NULL, "Loop condition.");
13113
ab3870a79b18 6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents: 12779
diff changeset
   193
    return new PerRegionTable(hr);
1374
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
13335
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   196
  PerRegionTable* next() const { return _next; }
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   197
  void set_next(PerRegionTable* next) { _next = next; }
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   198
  PerRegionTable* prev() const { return _prev; }
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   199
  void set_prev(PerRegionTable* prev) { _prev = prev; }
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   200
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   201
  // Accessor and Modification routines for the pointer for the
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   202
  // singly linked collision list that links the PRTs within the
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   203
  // OtherRegionsTable::_fine_grain_regions hash table.
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   204
  //
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   205
  // It might be useful to also make the collision list doubly linked
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   206
  // to avoid iteration over the collisions list during scrubbing/deletion.
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   207
  // OTOH there might not be many collisions.
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   208
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   209
  PerRegionTable* collision_list_next() const {
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   210
    return _collision_list_next;
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   211
  }
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   212
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   213
  void set_collision_list_next(PerRegionTable* next) {
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   214
    _collision_list_next = next;
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   215
  }
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   216
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   217
  PerRegionTable** collision_list_next_addr() {
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   218
    return &_collision_list_next;
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   219
  }
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   220
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   221
  static size_t fl_mem_size() {
13113
ab3870a79b18 6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents: 12779
diff changeset
   222
    PerRegionTable* cur = _free_list;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   223
    size_t res = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   224
    while (cur != NULL) {
17631
17992863b0ab 8014405: G1: PerRegionTable::fl_mem_size() calculates size of the free list using wrong element sizes
tschatzl
parents: 17398
diff changeset
   225
      res += cur->mem_size();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   226
      cur = cur->next();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   227
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   228
    return res;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   229
  }
17631
17992863b0ab 8014405: G1: PerRegionTable::fl_mem_size() calculates size of the free list using wrong element sizes
tschatzl
parents: 17398
diff changeset
   230
17992863b0ab 8014405: G1: PerRegionTable::fl_mem_size() calculates size of the free list using wrong element sizes
tschatzl
parents: 17398
diff changeset
   231
  static void test_fl_mem_size();
1374
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
41283
2615c024f3eb 8033552: Fix missing missing volatile specifiers in CAS operations in GC code
eosterlund
parents: 40655
diff changeset
   234
PerRegionTable* volatile PerRegionTable::_free_list = NULL;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   235
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   236
size_t OtherRegionsTable::_max_fine_entries = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   237
size_t OtherRegionsTable::_mod_max_fine_entries_mask = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   238
size_t OtherRegionsTable::_fine_eviction_stride = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   239
size_t OtherRegionsTable::_fine_eviction_sample_size = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   240
23451
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents: 21563
diff changeset
   241
OtherRegionsTable::OtherRegionsTable(HeapRegion* hr, Mutex* m) :
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   242
  _g1h(G1CollectedHeap::heap()),
23451
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents: 21563
diff changeset
   243
  _hr(hr), _m(m),
46745
f7b9bb98bb72 8176571: Fine bitmaps should be allocated as belonging to mtGC, not mtInternal
kbarrett
parents: 46560
diff changeset
   244
  _coarse_map(G1CollectedHeap::heap()->max_regions(), mtGC),
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   245
  _fine_grain_regions(NULL),
13335
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   246
  _first_all_fine_prts(NULL), _last_all_fine_prts(NULL),
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   247
  _n_fine_entries(0), _n_coarse_entries(0),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   248
  _fine_eviction_start(0),
38161
1c7dd1e39fcf 8155811: Remove HeapRegionRemSet::_coarse_dirty flag
tschatzl
parents: 38156
diff changeset
   249
  _sparse_table(hr)
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   250
{
13113
ab3870a79b18 6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents: 12779
diff changeset
   251
  typedef PerRegionTable* PerRegionTablePtr;
ab3870a79b18 6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents: 12779
diff changeset
   252
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   253
  if (_max_fine_entries == 0) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   254
    assert(_mod_max_fine_entries_mask == 0, "Both or none.");
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
   255
    size_t max_entries_log = (size_t)log2_long((jlong)G1RSetRegionEntries);
13752
92f03fcf979a 7197906: BlockOffsetArray::power_to_cards_back() needs to handle > 32 bit shifts
brutisso
parents: 13335
diff changeset
   256
    _max_fine_entries = (size_t)1 << max_entries_log;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   257
    _mod_max_fine_entries_mask = _max_fine_entries - 1;
13113
ab3870a79b18 6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents: 12779
diff changeset
   258
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   259
    assert(_fine_eviction_sample_size == 0
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   260
           && _fine_eviction_stride == 0, "All init at same time.");
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
   261
    _fine_eviction_sample_size = MAX2((size_t)4, max_entries_log);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   262
    _fine_eviction_stride = _max_fine_entries / _fine_eviction_sample_size;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   263
  }
13113
ab3870a79b18 6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents: 12779
diff changeset
   264
17376
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17119
diff changeset
   265
  _fine_grain_regions = NEW_C_HEAP_ARRAY3(PerRegionTablePtr, _max_fine_entries,
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 25889
diff changeset
   266
                        mtGC, CURRENT_PC, AllocFailStrategy::RETURN_NULL);
13113
ab3870a79b18 6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents: 12779
diff changeset
   267
ab3870a79b18 6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents: 12779
diff changeset
   268
  if (_fine_grain_regions == NULL) {
17087
f0b76c4c93a0 8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents: 17031
diff changeset
   269
    vm_exit_out_of_memory(sizeof(void*)*_max_fine_entries, OOM_MALLOC_ERROR,
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   270
                          "Failed to allocate _fine_grain_entries.");
13113
ab3870a79b18 6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents: 12779
diff changeset
   271
  }
ab3870a79b18 6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents: 12779
diff changeset
   272
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   273
  for (size_t i = 0; i < _max_fine_entries; i++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   274
    _fine_grain_regions[i] = NULL;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   275
  }
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
13335
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   278
void OtherRegionsTable::link_to_all(PerRegionTable* prt) {
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   279
  // We always append to the beginning of the list for convenience;
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   280
  // the order of entries in this list does not matter.
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   281
  if (_first_all_fine_prts != NULL) {
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   282
    assert(_first_all_fine_prts->prev() == NULL, "invariant");
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   283
    _first_all_fine_prts->set_prev(prt);
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   284
    prt->set_next(_first_all_fine_prts);
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   285
  } else {
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   286
    // this is the first element we insert. Adjust the "last" pointer
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   287
    _last_all_fine_prts = prt;
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   288
    assert(prt->next() == NULL, "just checking");
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   289
  }
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   290
  // the new element is always the first element without a predecessor
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   291
  prt->set_prev(NULL);
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   292
  _first_all_fine_prts = prt;
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   293
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   294
  assert(prt->prev() == NULL, "just checking");
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   295
  assert(_first_all_fine_prts == prt, "just checking");
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   296
  assert((_first_all_fine_prts == NULL && _last_all_fine_prts == NULL) ||
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   297
         (_first_all_fine_prts != NULL && _last_all_fine_prts != NULL),
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   298
         "just checking");
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   299
  assert(_last_all_fine_prts == NULL || _last_all_fine_prts->next() == NULL,
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   300
         "just checking");
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   301
  assert(_first_all_fine_prts == NULL || _first_all_fine_prts->prev() == NULL,
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   302
         "just checking");
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   303
}
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   304
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   305
void OtherRegionsTable::unlink_from_all(PerRegionTable* prt) {
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   306
  if (prt->prev() != NULL) {
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   307
    assert(_first_all_fine_prts != prt, "just checking");
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   308
    prt->prev()->set_next(prt->next());
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   309
    // removing the last element in the list?
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   310
    if (_last_all_fine_prts == prt) {
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   311
      _last_all_fine_prts = prt->prev();
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   312
    }
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   313
  } else {
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   314
    assert(_first_all_fine_prts == prt, "just checking");
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   315
    _first_all_fine_prts = prt->next();
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   316
    // list is empty now?
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   317
    if (_first_all_fine_prts == NULL) {
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   318
      _last_all_fine_prts = NULL;
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   319
    }
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   320
  }
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   321
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   322
  if (prt->next() != NULL) {
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   323
    prt->next()->set_prev(prt->prev());
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   324
  }
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   325
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   326
  prt->set_next(NULL);
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   327
  prt->set_prev(NULL);
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   328
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   329
  assert((_first_all_fine_prts == NULL && _last_all_fine_prts == NULL) ||
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   330
         (_first_all_fine_prts != NULL && _last_all_fine_prts != NULL),
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   331
         "just checking");
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   332
  assert(_last_all_fine_prts == NULL || _last_all_fine_prts->next() == NULL,
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   333
         "just checking");
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   334
  assert(_first_all_fine_prts == NULL || _first_all_fine_prts->prev() == NULL,
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   335
         "just checking");
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   336
}
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   337
49608
1852b17b0efc 8196485: FromCardCache default card index can cause crashes
tschatzl
parents: 49607
diff changeset
   338
CardIdx_t OtherRegionsTable::card_within_region(OopOrNarrowOopStar within_region, HeapRegion* hr) {
1852b17b0efc 8196485: FromCardCache default card index can cause crashes
tschatzl
parents: 49607
diff changeset
   339
  assert(hr->is_in_reserved(within_region),
1852b17b0efc 8196485: FromCardCache default card index can cause crashes
tschatzl
parents: 49607
diff changeset
   340
         "HeapWord " PTR_FORMAT " is outside of region %u [" PTR_FORMAT ", " PTR_FORMAT ")",
1852b17b0efc 8196485: FromCardCache default card index can cause crashes
tschatzl
parents: 49607
diff changeset
   341
         p2i(within_region), hr->hrm_index(), p2i(hr->bottom()), p2i(hr->end()));
1852b17b0efc 8196485: FromCardCache default card index can cause crashes
tschatzl
parents: 49607
diff changeset
   342
  CardIdx_t result = (CardIdx_t)(pointer_delta((HeapWord*)within_region, hr->bottom()) >> (CardTable::card_shift - LogHeapWordSize));
1852b17b0efc 8196485: FromCardCache default card index can cause crashes
tschatzl
parents: 49607
diff changeset
   343
  return result;
1852b17b0efc 8196485: FromCardCache default card index can cause crashes
tschatzl
parents: 49607
diff changeset
   344
}
1852b17b0efc 8196485: FromCardCache default card index can cause crashes
tschatzl
parents: 49607
diff changeset
   345
26850
515ff48cf5f0 8036116: Fix thread-id types in G1 remembered set implementations
brutisso
parents: 26424
diff changeset
   346
void OtherRegionsTable::add_reference(OopOrNarrowOopStar from, uint tid) {
28030
c36c6703366d 8066102: Clean up HeapRegionRemSet files
tschatzl
parents: 26850
diff changeset
   347
  uint cur_hrm_ind = _hr->hrm_index();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   348
49608
1852b17b0efc 8196485: FromCardCache default card index can cause crashes
tschatzl
parents: 49607
diff changeset
   349
  uintptr_t from_card = uintptr_t(from) >> CardTable::card_shift;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   350
35200
7802299b31e7 8145671: Rename FromCardCache to G1FromCardCache
tschatzl
parents: 35199
diff changeset
   351
  if (G1FromCardCache::contains_or_replace(tid, cur_hrm_ind, from_card)) {
35875
8ea0b4b0bcc8 8147087: Race when reusing PerRegionTable bitmaps may result in dropped remembered set entries
tschatzl
parents: 35461
diff changeset
   352
    assert(contains_reference(from), "We just found " PTR_FORMAT " in the FromCardCache", p2i(from));
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   353
    return;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   354
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   355
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   356
  // Note that this may be a continued H region.
33786
ac8da6513351 8139867: Change how startsHumongous and continuesHumongous regions work in G1.
david
parents: 33783
diff changeset
   357
  HeapRegion* from_hr = _g1h->heap_region_containing(from);
26424
639e661f19f3 8057143: Incomplete renaming of variables containing "hrs" to "hrm" related to HeapRegionSeq
tschatzl
parents: 26422
diff changeset
   358
  RegionIdx_t from_hrm_ind = (RegionIdx_t) from_hr->hrm_index();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   359
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   360
  // If the region is already coarsened, return.
26424
639e661f19f3 8057143: Incomplete renaming of variables containing "hrs" to "hrm" related to HeapRegionSeq
tschatzl
parents: 26422
diff changeset
   361
  if (_coarse_map.at(from_hrm_ind)) {
35875
8ea0b4b0bcc8 8147087: Race when reusing PerRegionTable bitmaps may result in dropped remembered set entries
tschatzl
parents: 35461
diff changeset
   362
    assert(contains_reference(from), "We just found " PTR_FORMAT " in the Coarse table", p2i(from));
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   363
    return;
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
  // Otherwise find a per-region table to add it to.
26424
639e661f19f3 8057143: Incomplete renaming of variables containing "hrs" to "hrm" related to HeapRegionSeq
tschatzl
parents: 26422
diff changeset
   367
  size_t ind = from_hrm_ind & _mod_max_fine_entries_mask;
13113
ab3870a79b18 6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents: 12779
diff changeset
   368
  PerRegionTable* prt = find_region_table(ind, from_hr);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   369
  if (prt == NULL) {
23451
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents: 21563
diff changeset
   370
    MutexLockerEx x(_m, Mutex::_no_safepoint_check_flag);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   371
    // Confirm that it's really not there...
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   372
    prt = find_region_table(ind, from_hr);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   373
    if (prt == NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   374
49608
1852b17b0efc 8196485: FromCardCache default card index can cause crashes
tschatzl
parents: 49607
diff changeset
   375
      CardIdx_t card_index = card_within_region(from, from_hr);
1852b17b0efc 8196485: FromCardCache default card index can cause crashes
tschatzl
parents: 49607
diff changeset
   376
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   377
      if (G1HRRSUseSparseTable &&
26424
639e661f19f3 8057143: Incomplete renaming of variables containing "hrs" to "hrm" related to HeapRegionSeq
tschatzl
parents: 26422
diff changeset
   378
          _sparse_table.add_card(from_hrm_ind, card_index)) {
35875
8ea0b4b0bcc8 8147087: Race when reusing PerRegionTable bitmaps may result in dropped remembered set entries
tschatzl
parents: 35461
diff changeset
   379
        assert(contains_reference_locked(from), "We just added " PTR_FORMAT " to the Sparse table", p2i(from));
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   380
        return;
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
      if (_n_fine_entries == _max_fine_entries) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   384
        prt = delete_region_table();
13335
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   385
        // There is no need to clear the links to the 'all' list here:
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   386
        // prt will be reused immediately, i.e. remain in the 'all' list.
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   387
        prt->init(from_hr, false /* clear_links_to_all_list */);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   388
      } else {
13113
ab3870a79b18 6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents: 12779
diff changeset
   389
        prt = PerRegionTable::alloc(from_hr);
13335
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   390
        link_to_all(prt);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   391
      }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   392
13113
ab3870a79b18 6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents: 12779
diff changeset
   393
      PerRegionTable* first_prt = _fine_grain_regions[ind];
13335
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   394
      prt->set_collision_list_next(first_prt);
30765
32398da8ba8f 8035496: G1 ARM: missing remset entry noticed by VerifyAfterGC for vm/gc/concurrent/lp50yp10rp70mr30st0
bdelsart
parents: 30764
diff changeset
   395
      // The assignment into _fine_grain_regions allows the prt to
32398da8ba8f 8035496: G1 ARM: missing remset entry noticed by VerifyAfterGC for vm/gc/concurrent/lp50yp10rp70mr30st0
bdelsart
parents: 30764
diff changeset
   396
      // start being used concurrently. In addition to
32398da8ba8f 8035496: G1 ARM: missing remset entry noticed by VerifyAfterGC for vm/gc/concurrent/lp50yp10rp70mr30st0
bdelsart
parents: 30764
diff changeset
   397
      // collision_list_next which must be visible (else concurrent
32398da8ba8f 8035496: G1 ARM: missing remset entry noticed by VerifyAfterGC for vm/gc/concurrent/lp50yp10rp70mr30st0
bdelsart
parents: 30764
diff changeset
   398
      // parsing of the list, if any, may fail to see other entries),
32398da8ba8f 8035496: G1 ARM: missing remset entry noticed by VerifyAfterGC for vm/gc/concurrent/lp50yp10rp70mr30st0
bdelsart
parents: 30764
diff changeset
   399
      // the content of the prt must be visible (else for instance
32398da8ba8f 8035496: G1 ARM: missing remset entry noticed by VerifyAfterGC for vm/gc/concurrent/lp50yp10rp70mr30st0
bdelsart
parents: 30764
diff changeset
   400
      // some mark bits may not yet seem cleared or a 'later' update
32398da8ba8f 8035496: G1 ARM: missing remset entry noticed by VerifyAfterGC for vm/gc/concurrent/lp50yp10rp70mr30st0
bdelsart
parents: 30764
diff changeset
   401
      // performed by a concurrent thread could be undone when the
32398da8ba8f 8035496: G1 ARM: missing remset entry noticed by VerifyAfterGC for vm/gc/concurrent/lp50yp10rp70mr30st0
bdelsart
parents: 30764
diff changeset
   402
      // zeroing becomes visible). This requires store ordering.
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47216
diff changeset
   403
      OrderAccess::release_store(&_fine_grain_regions[ind], prt);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   404
      _n_fine_entries++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   405
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   406
      if (G1HRRSUseSparseTable) {
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
   407
        // Transfer from sparse to fine-grain.
26424
639e661f19f3 8057143: Incomplete renaming of variables containing "hrs" to "hrm" related to HeapRegionSeq
tschatzl
parents: 26422
diff changeset
   408
        SparsePRTEntry *sprt_entry = _sparse_table.get_entry(from_hrm_ind);
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
   409
        assert(sprt_entry != NULL, "There should have been an entry");
38271
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38177
diff changeset
   410
        for (int i = 0; i < sprt_entry->num_valid_cards(); i++) {
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
   411
          CardIdx_t c = sprt_entry->card(i);
38271
4425ba8ed50f 8047328: Improve memory usage for cards in SparsePRTEntry
tschatzl
parents: 38177
diff changeset
   412
          prt->add_card(c);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   413
        }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   414
        // Now we can delete the sparse entry.
26424
639e661f19f3 8057143: Incomplete renaming of variables containing "hrs" to "hrm" related to HeapRegionSeq
tschatzl
parents: 26422
diff changeset
   415
        bool res = _sparse_table.delete_entry(from_hrm_ind);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   416
        assert(res, "It should have been there.");
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
    assert(prt != NULL && prt->hr() == from_hr, "consequence");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   420
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   421
  // Note that we can't assert "prt->hr() == from_hr", because of the
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   422
  // possibility of concurrent reuse.  But see head comment of
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   423
  // OtherRegionsTable for why this is OK.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   424
  assert(prt != NULL, "Inv");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   425
13113
ab3870a79b18 6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents: 12779
diff changeset
   426
  prt->add_reference(from);
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49164
diff changeset
   427
  assert(contains_reference(from), "We just added " PTR_FORMAT " to the PRT (%d)", p2i(from), prt->contains_reference(from));
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   428
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   429
13113
ab3870a79b18 6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents: 12779
diff changeset
   430
PerRegionTable*
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   431
OtherRegionsTable::find_region_table(size_t ind, HeapRegion* hr) const {
29580
a67a581cfe11 8073315: Enable gcc -Wtype-limits and fix upcoming issues.
goetz
parents: 28379
diff changeset
   432
  assert(ind < _max_fine_entries, "Preconditions.");
13113
ab3870a79b18 6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents: 12779
diff changeset
   433
  PerRegionTable* prt = _fine_grain_regions[ind];
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   434
  while (prt != NULL && prt->hr() != hr) {
13335
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   435
    prt = prt->collision_list_next();
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
  // Loop postcondition is the method postcondition.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   438
  return prt;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   439
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   440
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   441
jint OtherRegionsTable::_n_coarsenings = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   442
13113
ab3870a79b18 6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents: 12779
diff changeset
   443
PerRegionTable* OtherRegionsTable::delete_region_table() {
23451
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents: 21563
diff changeset
   444
  assert(_m->owned_by_self(), "Precondition");
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   445
  assert(_n_fine_entries == _max_fine_entries, "Precondition");
13113
ab3870a79b18 6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents: 12779
diff changeset
   446
  PerRegionTable* max = NULL;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   447
  jint max_occ = 0;
33589
7cbd1b2c139b 8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
goetz
parents: 33105
diff changeset
   448
  PerRegionTable** max_prev = NULL;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   449
  size_t max_ind;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   450
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   451
  size_t i = _fine_eviction_start;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   452
  for (size_t k = 0; k < _fine_eviction_sample_size; k++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   453
    size_t ii = i;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   454
    // Make sure we get a non-NULL sample.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   455
    while (_fine_grain_regions[ii] == NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   456
      ii++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   457
      if (ii == _max_fine_entries) ii = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   458
      guarantee(ii != i, "We must find one.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   459
    }
13113
ab3870a79b18 6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents: 12779
diff changeset
   460
    PerRegionTable** prev = &_fine_grain_regions[ii];
ab3870a79b18 6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents: 12779
diff changeset
   461
    PerRegionTable* cur = *prev;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   462
    while (cur != NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   463
      jint cur_occ = cur->occupied();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   464
      if (max == NULL || cur_occ > max_occ) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   465
        max = cur;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   466
        max_prev = prev;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   467
        max_ind = i;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   468
        max_occ = cur_occ;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   469
      }
13335
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   470
      prev = cur->collision_list_next_addr();
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   471
      cur = cur->collision_list_next();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   472
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   473
    i = i + _fine_eviction_stride;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   474
    if (i >= _n_fine_entries) i = i - _n_fine_entries;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   475
  }
13113
ab3870a79b18 6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents: 12779
diff changeset
   476
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   477
  _fine_eviction_start++;
13113
ab3870a79b18 6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents: 12779
diff changeset
   478
ab3870a79b18 6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents: 12779
diff changeset
   479
  if (_fine_eviction_start >= _n_fine_entries) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   480
    _fine_eviction_start -= _n_fine_entries;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   481
  }
13113
ab3870a79b18 6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents: 12779
diff changeset
   482
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   483
  guarantee(max != NULL, "Since _n_fine_entries > 0");
33589
7cbd1b2c139b 8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
goetz
parents: 33105
diff changeset
   484
  guarantee(max_prev != NULL, "Since max != NULL.");
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   485
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   486
  // Set the corresponding coarse bit.
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
   487
  size_t max_hrm_index = (size_t) max->hr()->hrm_index();
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
   488
  if (!_coarse_map.at(max_hrm_index)) {
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
   489
    _coarse_map.at_put(max_hrm_index, true);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   490
    _n_coarse_entries++;
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
  // Unsplice.
13335
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   494
  *max_prev = max->collision_list_next();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   495
  Atomic::inc(&_n_coarsenings);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   496
  _n_fine_entries--;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   497
  return max;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   498
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   499
28379
e6784fc8fff2 8048179: Early reclaim of large objects that are referenced by a few objects
tschatzl
parents: 28170
diff changeset
   500
bool OtherRegionsTable::occupancy_less_or_equal_than(size_t limit) const {
e6784fc8fff2 8048179: Early reclaim of large objects that are referenced by a few objects
tschatzl
parents: 28170
diff changeset
   501
  if (limit <= (size_t)G1RSetSparseRegionEntries) {
e6784fc8fff2 8048179: Early reclaim of large objects that are referenced by a few objects
tschatzl
parents: 28170
diff changeset
   502
    return occ_coarse() == 0 && _first_all_fine_prts == NULL && occ_sparse() <= limit;
e6784fc8fff2 8048179: Early reclaim of large objects that are referenced by a few objects
tschatzl
parents: 28170
diff changeset
   503
  } else {
e6784fc8fff2 8048179: Early reclaim of large objects that are referenced by a few objects
tschatzl
parents: 28170
diff changeset
   504
    // Current uses of this method may only use values less than G1RSetSparseRegionEntries
e6784fc8fff2 8048179: Early reclaim of large objects that are referenced by a few objects
tschatzl
parents: 28170
diff changeset
   505
    // for the limit. The solution, comparing against occupied() would be too slow
e6784fc8fff2 8048179: Early reclaim of large objects that are referenced by a few objects
tschatzl
parents: 28170
diff changeset
   506
    // at this time.
e6784fc8fff2 8048179: Early reclaim of large objects that are referenced by a few objects
tschatzl
parents: 28170
diff changeset
   507
    Unimplemented();
e6784fc8fff2 8048179: Early reclaim of large objects that are referenced by a few objects
tschatzl
parents: 28170
diff changeset
   508
    return false;
e6784fc8fff2 8048179: Early reclaim of large objects that are referenced by a few objects
tschatzl
parents: 28170
diff changeset
   509
  }
e6784fc8fff2 8048179: Early reclaim of large objects that are referenced by a few objects
tschatzl
parents: 28170
diff changeset
   510
}
e6784fc8fff2 8048179: Early reclaim of large objects that are referenced by a few objects
tschatzl
parents: 28170
diff changeset
   511
25889
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents: 25492
diff changeset
   512
bool OtherRegionsTable::is_empty() const {
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents: 25492
diff changeset
   513
  return occ_sparse() == 0 && occ_coarse() == 0 && _first_all_fine_prts == NULL;
221296ac4359 8027959: Early reclamation of large objects in G1
tschatzl
parents: 25492
diff changeset
   514
}
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   515
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   516
size_t OtherRegionsTable::occupied() const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   517
  size_t sum = occ_fine();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   518
  sum += occ_sparse();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   519
  sum += occ_coarse();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   520
  return sum;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   521
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   522
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   523
size_t OtherRegionsTable::occ_fine() const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   524
  size_t sum = 0;
13335
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   525
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   526
  size_t num = 0;
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   527
  PerRegionTable * cur = _first_all_fine_prts;
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   528
  while (cur != NULL) {
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   529
    sum += cur->occupied();
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   530
    cur = cur->next();
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   531
    num++;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   532
  }
13335
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   533
  guarantee(num == _n_fine_entries, "just checking");
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   534
  return sum;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   535
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   536
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   537
size_t OtherRegionsTable::occ_coarse() const {
3697
ea9211aa02f5 6819085: G1: use larger and/or user settable region size
tonyp
parents: 3262
diff changeset
   538
  return (_n_coarse_entries * HeapRegion::CardsPerRegion);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   539
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   540
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   541
size_t OtherRegionsTable::occ_sparse() const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   542
  return _sparse_table.occupied();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   543
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   544
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   545
size_t OtherRegionsTable::mem_size() const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   546
  size_t sum = 0;
17395
2cd3ef1be718 8014240: G1: Add remembered set size information to output of G1PrintRegionLivenessInfo
tschatzl
parents: 17119
diff changeset
   547
  // all PRTs are of the same size so it is sufficient to query only one of them.
2cd3ef1be718 8014240: G1: Add remembered set size information to output of G1PrintRegionLivenessInfo
tschatzl
parents: 17119
diff changeset
   548
  if (_first_all_fine_prts != NULL) {
2cd3ef1be718 8014240: G1: Add remembered set size information to output of G1PrintRegionLivenessInfo
tschatzl
parents: 17119
diff changeset
   549
    assert(_last_all_fine_prts != NULL &&
2cd3ef1be718 8014240: G1: Add remembered set size information to output of G1PrintRegionLivenessInfo
tschatzl
parents: 17119
diff changeset
   550
      _first_all_fine_prts->mem_size() == _last_all_fine_prts->mem_size(), "check that mem_size() is constant");
2cd3ef1be718 8014240: G1: Add remembered set size information to output of G1PrintRegionLivenessInfo
tschatzl
parents: 17119
diff changeset
   551
    sum += _first_all_fine_prts->mem_size() * _n_fine_entries;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   552
  }
13113
ab3870a79b18 6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents: 12779
diff changeset
   553
  sum += (sizeof(PerRegionTable*) * _max_fine_entries);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   554
  sum += (_coarse_map.size_in_words() * HeapWordSize);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   555
  sum += (_sparse_table.mem_size());
24108
dfc2242fc6b0 8040792: G1: Memory usage calculation uses sizeof(this) instead of sizeof(classname)
tschatzl
parents: 24106
diff changeset
   556
  sum += sizeof(OtherRegionsTable) - sizeof(_sparse_table); // Avoid double counting above.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   557
  return sum;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   558
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   559
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   560
size_t OtherRegionsTable::static_mem_size() {
35200
7802299b31e7 8145671: Rename FromCardCache to G1FromCardCache
tschatzl
parents: 35199
diff changeset
   561
  return G1FromCardCache::static_mem_size();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   562
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   563
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   564
size_t OtherRegionsTable::fl_mem_size() {
13113
ab3870a79b18 6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents: 12779
diff changeset
   565
  return PerRegionTable::fl_mem_size();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   566
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   567
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   568
void OtherRegionsTable::clear_fcc() {
35200
7802299b31e7 8145671: Rename FromCardCache to G1FromCardCache
tschatzl
parents: 35199
diff changeset
   569
  G1FromCardCache::clear(_hr->hrm_index());
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   570
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   571
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   572
void OtherRegionsTable::clear() {
13335
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   573
  // if there are no entries, skip this step
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   574
  if (_first_all_fine_prts != NULL) {
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   575
    guarantee(_first_all_fine_prts != NULL && _last_all_fine_prts != NULL, "just checking");
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   576
    PerRegionTable::bulk_free(_first_all_fine_prts, _last_all_fine_prts);
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   577
    memset(_fine_grain_regions, 0, _max_fine_entries * sizeof(_fine_grain_regions[0]));
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   578
  } else {
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   579
    guarantee(_first_all_fine_prts == NULL && _last_all_fine_prts == NULL, "just checking");
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   580
  }
13335
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   581
f2e823305677 7182260: G1: Fine grain RSet freeing bottleneck
johnc
parents: 13196
diff changeset
   582
  _first_all_fine_prts = _last_all_fine_prts = NULL;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   583
  _sparse_table.clear();
38161
1c7dd1e39fcf 8155811: Remove HeapRegionRemSet::_coarse_dirty flag
tschatzl
parents: 38156
diff changeset
   584
  if (_n_coarse_entries > 0) {
38156
e0ff734fa7de 8155233: Lazy coarse map clear
tschatzl
parents: 37988
diff changeset
   585
    _coarse_map.clear();
e0ff734fa7de 8155233: Lazy coarse map clear
tschatzl
parents: 37988
diff changeset
   586
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   587
  _n_fine_entries = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   588
  _n_coarse_entries = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   589
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   590
  clear_fcc();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   591
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   592
3262
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
   593
bool OtherRegionsTable::contains_reference(OopOrNarrowOopStar from) const {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   594
  // Cast away const in this case.
23451
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents: 21563
diff changeset
   595
  MutexLockerEx x((Mutex*)_m, Mutex::_no_safepoint_check_flag);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   596
  return contains_reference_locked(from);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   597
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   598
3262
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
   599
bool OtherRegionsTable::contains_reference_locked(OopOrNarrowOopStar from) const {
33786
ac8da6513351 8139867: Change how startsHumongous and continuesHumongous regions work in G1.
david
parents: 33783
diff changeset
   600
  HeapRegion* hr = _g1h->heap_region_containing(from);
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26160
diff changeset
   601
  RegionIdx_t hr_ind = (RegionIdx_t) hr->hrm_index();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   602
  // Is this region in the coarse map?
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   603
  if (_coarse_map.at(hr_ind)) return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   604
13113
ab3870a79b18 6921087: G1: remove per-GC-thread expansion tables from the fine-grain remembered sets
johnc
parents: 12779
diff changeset
   605
  PerRegionTable* prt = find_region_table(hr_ind & _mod_max_fine_entries_mask,
49608
1852b17b0efc 8196485: FromCardCache default card index can cause crashes
tschatzl
parents: 49607
diff changeset
   606
                                          hr);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   607
  if (prt != NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   608
    return prt->contains_reference(from);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   609
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   610
  } else {
49608
1852b17b0efc 8196485: FromCardCache default card index can cause crashes
tschatzl
parents: 49607
diff changeset
   611
    CardIdx_t card_index = card_within_region(from, hr);
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2882
diff changeset
   612
    return _sparse_table.contains_card(hr_ind, card_index);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   613
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   614
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   615
8072
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   616
void
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   617
OtherRegionsTable::do_cleanup_work(HRRSCleanupTask* hrrs_cleanup_task) {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   618
  _sparse_table.do_cleanup_work(hrrs_cleanup_task);
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   619
}
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   620
35461
1068dcb8d315 8146399: Refactor the BlockOffsetTable classes.
david
parents: 35210
diff changeset
   621
HeapRegionRemSet::HeapRegionRemSet(G1BlockOffsetTable* bot,
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   622
                                   HeapRegion* hr)
35461
1068dcb8d315 8146399: Refactor the BlockOffsetTable classes.
david
parents: 35210
diff changeset
   623
  : _bot(bot),
28163
322d55d167be 8047290: Make Mutex::_no_safepoint_check_flag locks verify that this lock never checks for safepoint
coleenp
parents: 26850
diff changeset
   624
    _m(Mutex::leaf, FormatBuffer<128>("HeapRegionRemSet lock #%u", hr->hrm_index()), true, Monitor::_safepoint_check_never),
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37414
diff changeset
   625
    _code_roots(),
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49164
diff changeset
   626
    _state(Untracked),
37988
bf4018edea5e 8153503: Move remset scan iteration claim to remset local data structure
tschatzl
parents: 37414
diff changeset
   627
    _other_regions(hr, &_m) {
10000
5bbb58b0dbb9 7046182: G1: remove unnecessary iterations over the collection set
tonyp
parents: 9989
diff changeset
   628
}
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   629
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
   630
void HeapRegionRemSet::setup_remset_size() {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
   631
  // Setup sparse and fine-grain tables sizes.
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
   632
  // table_size = base * (log(region_size / 1M) + 1)
12779
06778de5193e 7171936: LOG_G incorrectly defined in globalDefinitions.hpp
brutisso
parents: 12381
diff changeset
   633
  const int LOG_M = 20;
06778de5193e 7171936: LOG_G incorrectly defined in globalDefinitions.hpp
brutisso
parents: 12381
diff changeset
   634
  int region_size_log_mb = MAX2(HeapRegion::LogOfHRGrainBytes - LOG_M, 0);
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
   635
  if (FLAG_IS_DEFAULT(G1RSetSparseRegionEntries)) {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
   636
    G1RSetSparseRegionEntries = G1RSetSparseRegionEntriesBase * (region_size_log_mb + 1);
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
   637
  }
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
   638
  if (FLAG_IS_DEFAULT(G1RSetRegionEntries)) {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
   639
    G1RSetRegionEntries = G1RSetRegionEntriesBase * (region_size_log_mb + 1);
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
   640
  }
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
   641
  guarantee(G1RSetSparseRegionEntries > 0 && G1RSetRegionEntries > 0 , "Sanity");
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
   642
}
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
   643
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   644
void HeapRegionRemSet::cleanup() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   645
  SparsePRT::cleanup_all();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   646
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   647
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49164
diff changeset
   648
void HeapRegionRemSet::clear(bool only_cardset) {
23451
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents: 21563
diff changeset
   649
  MutexLockerEx x(&_m, Mutex::_no_safepoint_check_flag);
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49164
diff changeset
   650
  clear_locked(only_cardset);
23451
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents: 21563
diff changeset
   651
}
19339
d247781beec7 7145569: G1: optimize nmethods scanning
johnc
parents: 17631
diff changeset
   652
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49164
diff changeset
   653
void HeapRegionRemSet::clear_locked(bool only_cardset) {
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49164
diff changeset
   654
  if (!only_cardset) {
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49164
diff changeset
   655
    _code_roots.clear();
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49164
diff changeset
   656
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   657
  _other_regions.clear();
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49164
diff changeset
   658
  set_state_empty();
23451
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents: 21563
diff changeset
   659
  assert(occupied_locked() == 0, "Should be clear.");
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   660
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   661
19339
d247781beec7 7145569: G1: optimize nmethods scanning
johnc
parents: 17631
diff changeset
   662
// Code roots support
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 26316
diff changeset
   663
//
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 26316
diff changeset
   664
// The code root set is protected by two separate locking schemes
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 26316
diff changeset
   665
// When at safepoint the per-hrrs lock must be held during modifications
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 26316
diff changeset
   666
// except when doing a full gc.
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 26316
diff changeset
   667
// When not at safepoint the CodeCache_lock must be held during modifications.
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 26316
diff changeset
   668
// When concurrent readers access the contains() function
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 26316
diff changeset
   669
// (during the evacuation phase) no removals are allowed.
19339
d247781beec7 7145569: G1: optimize nmethods scanning
johnc
parents: 17631
diff changeset
   670
d247781beec7 7145569: G1: optimize nmethods scanning
johnc
parents: 17631
diff changeset
   671
void HeapRegionRemSet::add_strong_code_root(nmethod* nm) {
d247781beec7 7145569: G1: optimize nmethods scanning
johnc
parents: 17631
diff changeset
   672
  assert(nm != NULL, "sanity");
35879
9892f53e92c9 8141421: Various test fail with OOME on win x86
drwhite
parents: 35461
diff changeset
   673
  assert((!CodeCache_lock->owned_by_self() || SafepointSynchronize::is_at_safepoint()),
9892f53e92c9 8141421: Various test fail with OOME on win x86
drwhite
parents: 35461
diff changeset
   674
          "should call add_strong_code_root_locked instead. CodeCache_lock->owned_by_self(): %s, is_at_safepoint(): %s",
9892f53e92c9 8141421: Various test fail with OOME on win x86
drwhite
parents: 35461
diff changeset
   675
          BOOL_TO_STR(CodeCache_lock->owned_by_self()), BOOL_TO_STR(SafepointSynchronize::is_at_safepoint()));
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 26316
diff changeset
   676
  // Optimistic unlocked contains-check
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 26316
diff changeset
   677
  if (!_code_roots.contains(nm)) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 26316
diff changeset
   678
    MutexLockerEx ml(&_m, Mutex::_no_safepoint_check_flag);
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 26316
diff changeset
   679
    add_strong_code_root_locked(nm);
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 26316
diff changeset
   680
  }
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 26316
diff changeset
   681
}
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 26316
diff changeset
   682
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 26316
diff changeset
   683
void HeapRegionRemSet::add_strong_code_root_locked(nmethod* nm) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 26316
diff changeset
   684
  assert(nm != NULL, "sanity");
35879
9892f53e92c9 8141421: Various test fail with OOME on win x86
drwhite
parents: 35461
diff changeset
   685
  assert((CodeCache_lock->owned_by_self() ||
9892f53e92c9 8141421: Various test fail with OOME on win x86
drwhite
parents: 35461
diff changeset
   686
         (SafepointSynchronize::is_at_safepoint() &&
9892f53e92c9 8141421: Various test fail with OOME on win x86
drwhite
parents: 35461
diff changeset
   687
          (_m.owned_by_self() || Thread::current()->is_VM_thread()))),
9892f53e92c9 8141421: Various test fail with OOME on win x86
drwhite
parents: 35461
diff changeset
   688
          "not safely locked. CodeCache_lock->owned_by_self(): %s, is_at_safepoint(): %s, _m.owned_by_self(): %s, Thread::current()->is_VM_thread(): %s",
9892f53e92c9 8141421: Various test fail with OOME on win x86
drwhite
parents: 35461
diff changeset
   689
          BOOL_TO_STR(CodeCache_lock->owned_by_self()), BOOL_TO_STR(SafepointSynchronize::is_at_safepoint()),
9892f53e92c9 8141421: Various test fail with OOME on win x86
drwhite
parents: 35461
diff changeset
   690
          BOOL_TO_STR(_m.owned_by_self()), BOOL_TO_STR(Thread::current()->is_VM_thread()));
23451
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents: 21563
diff changeset
   691
  _code_roots.add(nm);
19339
d247781beec7 7145569: G1: optimize nmethods scanning
johnc
parents: 17631
diff changeset
   692
}
d247781beec7 7145569: G1: optimize nmethods scanning
johnc
parents: 17631
diff changeset
   693
d247781beec7 7145569: G1: optimize nmethods scanning
johnc
parents: 17631
diff changeset
   694
void HeapRegionRemSet::remove_strong_code_root(nmethod* nm) {
d247781beec7 7145569: G1: optimize nmethods scanning
johnc
parents: 17631
diff changeset
   695
  assert(nm != NULL, "sanity");
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   696
  assert_locked_or_safepoint(CodeCache_lock);
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   697
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 26316
diff changeset
   698
  MutexLockerEx ml(CodeCache_lock->owned_by_self() ? NULL : &_m, Mutex::_no_safepoint_check_flag);
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 26316
diff changeset
   699
  _code_roots.remove(nm);
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   700
19339
d247781beec7 7145569: G1: optimize nmethods scanning
johnc
parents: 17631
diff changeset
   701
  // Check that there were no duplicates
23451
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents: 21563
diff changeset
   702
  guarantee(!_code_roots.contains(nm), "duplicate entry found");
19339
d247781beec7 7145569: G1: optimize nmethods scanning
johnc
parents: 17631
diff changeset
   703
}
d247781beec7 7145569: G1: optimize nmethods scanning
johnc
parents: 17631
diff changeset
   704
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 26316
diff changeset
   705
void HeapRegionRemSet::strong_code_roots_do(CodeBlobClosure* blk) const {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 26316
diff changeset
   706
  _code_roots.nmethods_do(blk);
19339
d247781beec7 7145569: G1: optimize nmethods scanning
johnc
parents: 17631
diff changeset
   707
}
d247781beec7 7145569: G1: optimize nmethods scanning
johnc
parents: 17631
diff changeset
   708
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 26316
diff changeset
   709
void HeapRegionRemSet::clean_strong_code_roots(HeapRegion* hr) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 26316
diff changeset
   710
  _code_roots.clean(hr);
19339
d247781beec7 7145569: G1: optimize nmethods scanning
johnc
parents: 17631
diff changeset
   711
}
d247781beec7 7145569: G1: optimize nmethods scanning
johnc
parents: 17631
diff changeset
   712
d247781beec7 7145569: G1: optimize nmethods scanning
johnc
parents: 17631
diff changeset
   713
size_t HeapRegionRemSet::strong_code_roots_mem_size() {
23451
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents: 21563
diff changeset
   714
  return _code_roots.mem_size();
19339
d247781beec7 7145569: G1: optimize nmethods scanning
johnc
parents: 17631
diff changeset
   715
}
d247781beec7 7145569: G1: optimize nmethods scanning
johnc
parents: 17631
diff changeset
   716
23451
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents: 21563
diff changeset
   717
HeapRegionRemSetIterator:: HeapRegionRemSetIterator(HeapRegionRemSet* hrrs) :
17108
cf72dcf9a8f2 8011724: G1: Stack allocate instances of HeapRegionRemSetIterator
johnc
parents: 13752
diff changeset
   718
  _hrrs(hrrs),
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   719
  _g1h(G1CollectedHeap::heap()),
17108
cf72dcf9a8f2 8011724: G1: Stack allocate instances of HeapRegionRemSetIterator
johnc
parents: 13752
diff changeset
   720
  _coarse_map(&hrrs->_other_regions._coarse_map),
35461
1068dcb8d315 8146399: Refactor the BlockOffsetTable classes.
david
parents: 35210
diff changeset
   721
  _bot(hrrs->_bot),
17108
cf72dcf9a8f2 8011724: G1: Stack allocate instances of HeapRegionRemSetIterator
johnc
parents: 13752
diff changeset
   722
  _is(Sparse),
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   723
  // Set these values so that we increment to the first region.
17108
cf72dcf9a8f2 8011724: G1: Stack allocate instances of HeapRegionRemSetIterator
johnc
parents: 13752
diff changeset
   724
  _coarse_cur_region_index(-1),
cf72dcf9a8f2 8011724: G1: Stack allocate instances of HeapRegionRemSetIterator
johnc
parents: 13752
diff changeset
   725
  _coarse_cur_region_cur_card(HeapRegion::CardsPerRegion-1),
24101
bd1a2ee20760 8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents: 24092
diff changeset
   726
  _cur_card_in_prt(HeapRegion::CardsPerRegion),
17108
cf72dcf9a8f2 8011724: G1: Stack allocate instances of HeapRegionRemSetIterator
johnc
parents: 13752
diff changeset
   727
  _fine_cur_prt(NULL),
cf72dcf9a8f2 8011724: G1: Stack allocate instances of HeapRegionRemSetIterator
johnc
parents: 13752
diff changeset
   728
  _n_yielded_coarse(0),
cf72dcf9a8f2 8011724: G1: Stack allocate instances of HeapRegionRemSetIterator
johnc
parents: 13752
diff changeset
   729
  _n_yielded_fine(0),
cf72dcf9a8f2 8011724: G1: Stack allocate instances of HeapRegionRemSetIterator
johnc
parents: 13752
diff changeset
   730
  _n_yielded_sparse(0),
cf72dcf9a8f2 8011724: G1: Stack allocate instances of HeapRegionRemSetIterator
johnc
parents: 13752
diff changeset
   731
  _sparse_iter(&hrrs->_other_regions._sparse_table) {}
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   732
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   733
bool HeapRegionRemSetIterator::coarse_has_next(size_t& card_index) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   734
  if (_hrrs->_other_regions._n_coarse_entries == 0) return false;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   735
  // Go to the next card.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   736
  _coarse_cur_region_cur_card++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   737
  // Was the last the last card in the current region?
3697
ea9211aa02f5 6819085: G1: use larger and/or user settable region size
tonyp
parents: 3262
diff changeset
   738
  if (_coarse_cur_region_cur_card == HeapRegion::CardsPerRegion) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   739
    // Yes: find the next region.  This may leave _coarse_cur_region_index
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   740
    // Set to the last index, in which case there are no more coarse
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   741
    // regions.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   742
    _coarse_cur_region_index =
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   743
      (int) _coarse_map->get_next_one_offset(_coarse_cur_region_index + 1);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   744
    if ((size_t)_coarse_cur_region_index < _coarse_map->size()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   745
      _coarse_cur_region_cur_card = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   746
      HeapWord* r_bot =
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 10767
diff changeset
   747
        _g1h->region_at((uint) _coarse_cur_region_index)->bottom();
35461
1068dcb8d315 8146399: Refactor the BlockOffsetTable classes.
david
parents: 35210
diff changeset
   748
      _cur_region_card_offset = _bot->index_for(r_bot);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   749
    } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   750
      return false;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   751
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   752
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   753
  // If we didn't return false above, then we can yield a card.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   754
  card_index = _cur_region_card_offset + _coarse_cur_region_cur_card;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   755
  return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   756
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   757
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   758
bool HeapRegionRemSetIterator::fine_has_next(size_t& card_index) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   759
  if (fine_has_next()) {
24101
bd1a2ee20760 8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents: 24092
diff changeset
   760
    _cur_card_in_prt =
bd1a2ee20760 8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents: 24092
diff changeset
   761
      _fine_cur_prt->_bm.get_next_one_offset(_cur_card_in_prt + 1);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   762
  }
24101
bd1a2ee20760 8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents: 24092
diff changeset
   763
  if (_cur_card_in_prt == HeapRegion::CardsPerRegion) {
bd1a2ee20760 8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents: 24092
diff changeset
   764
    // _fine_cur_prt may still be NULL in case if there are not PRTs at all for
bd1a2ee20760 8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents: 24092
diff changeset
   765
    // the remembered set.
bd1a2ee20760 8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents: 24092
diff changeset
   766
    if (_fine_cur_prt == NULL || _fine_cur_prt->next() == NULL) {
bd1a2ee20760 8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents: 24092
diff changeset
   767
      return false;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   768
    }
24101
bd1a2ee20760 8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents: 24092
diff changeset
   769
    PerRegionTable* next_prt = _fine_cur_prt->next();
bd1a2ee20760 8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents: 24092
diff changeset
   770
    switch_to_prt(next_prt);
bd1a2ee20760 8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents: 24092
diff changeset
   771
    _cur_card_in_prt = _fine_cur_prt->_bm.get_next_one_offset(_cur_card_in_prt + 1);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   772
  }
24101
bd1a2ee20760 8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents: 24092
diff changeset
   773
bd1a2ee20760 8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents: 24092
diff changeset
   774
  card_index = _cur_region_card_offset + _cur_card_in_prt;
bd1a2ee20760 8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents: 24092
diff changeset
   775
  guarantee(_cur_card_in_prt < HeapRegion::CardsPerRegion,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31592
diff changeset
   776
            "Card index " SIZE_FORMAT " must be within the region", _cur_card_in_prt);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   777
  return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   778
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   779
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   780
bool HeapRegionRemSetIterator::fine_has_next() {
24101
bd1a2ee20760 8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents: 24092
diff changeset
   781
  return _cur_card_in_prt != HeapRegion::CardsPerRegion;
bd1a2ee20760 8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents: 24092
diff changeset
   782
}
bd1a2ee20760 8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents: 24092
diff changeset
   783
bd1a2ee20760 8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents: 24092
diff changeset
   784
void HeapRegionRemSetIterator::switch_to_prt(PerRegionTable* prt) {
bd1a2ee20760 8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents: 24092
diff changeset
   785
  assert(prt != NULL, "Cannot switch to NULL prt");
bd1a2ee20760 8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents: 24092
diff changeset
   786
  _fine_cur_prt = prt;
bd1a2ee20760 8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents: 24092
diff changeset
   787
bd1a2ee20760 8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents: 24092
diff changeset
   788
  HeapWord* r_bot = _fine_cur_prt->hr()->bottom();
35461
1068dcb8d315 8146399: Refactor the BlockOffsetTable classes.
david
parents: 35210
diff changeset
   789
  _cur_region_card_offset = _bot->index_for(r_bot);
24101
bd1a2ee20760 8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents: 24092
diff changeset
   790
bd1a2ee20760 8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents: 24092
diff changeset
   791
  // The bitmap scan for the PRT always scans from _cur_region_cur_card + 1.
bd1a2ee20760 8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents: 24092
diff changeset
   792
  // To avoid special-casing this start case, and not miss the first bitmap
bd1a2ee20760 8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents: 24092
diff changeset
   793
  // entry, initialize _cur_region_cur_card with -1 instead of 0.
bd1a2ee20760 8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents: 24092
diff changeset
   794
  _cur_card_in_prt = (size_t)-1;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   795
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   796
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   797
bool HeapRegionRemSetIterator::has_next(size_t& card_index) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   798
  switch (_is) {
24101
bd1a2ee20760 8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents: 24092
diff changeset
   799
  case Sparse: {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   800
    if (_sparse_iter.has_next(card_index)) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   801
      _n_yielded_sparse++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   802
      return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   803
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   804
    // Otherwise, deliberate fall-through
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   805
    _is = Fine;
24101
bd1a2ee20760 8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents: 24092
diff changeset
   806
    PerRegionTable* initial_fine_prt = _hrrs->_other_regions._first_all_fine_prts;
bd1a2ee20760 8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents: 24092
diff changeset
   807
    if (initial_fine_prt != NULL) {
bd1a2ee20760 8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents: 24092
diff changeset
   808
      switch_to_prt(_hrrs->_other_regions._first_all_fine_prts);
bd1a2ee20760 8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents: 24092
diff changeset
   809
    }
bd1a2ee20760 8037344: Use the "next" field to iterate over fine remembered instead of using the hash table
tschatzl
parents: 24092
diff changeset
   810
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   811
  case Fine:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   812
    if (fine_has_next(card_index)) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   813
      _n_yielded_fine++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   814
      return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   815
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   816
    // Otherwise, deliberate fall-through
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   817
    _is = Coarse;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   818
  case Coarse:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   819
    if (coarse_has_next(card_index)) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   820
      _n_yielded_coarse++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   821
      return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   822
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   823
    // Otherwise...
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   824
    break;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   825
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   826
  return false;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   827
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   828
8072
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   829
void HeapRegionRemSet::reset_for_cleanup_tasks() {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   830
  SparsePRT::reset_for_cleanup_tasks();
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   831
}
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   832
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   833
void HeapRegionRemSet::do_cleanup_work(HRRSCleanupTask* hrrs_cleanup_task) {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   834
  _other_regions.do_cleanup_work(hrrs_cleanup_task);
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   835
}
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   836
49632
64f9ebc85e67 8197573: Remove concurrent cleanup and secondary free list handling
tschatzl
parents: 49608
diff changeset
   837
void HeapRegionRemSet::finish_cleanup_task(HRRSCleanupTask* hrrs_cleanup_task) {
8072
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   838
  SparsePRT::finish_cleanup_task(hrrs_cleanup_task);
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   839
}
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
   840
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   841
#ifndef PRODUCT
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   842
void HeapRegionRemSet::test() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   843
  os::sleep(Thread::current(), (jlong)5000, false);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   844
  G1CollectedHeap* g1h = G1CollectedHeap::heap();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   845
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
   846
  // Run with "-XX:G1LogRSetRegionEntries=2", so that 1 and 5 end up in same
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   847
  // hash bucket.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   848
  HeapRegion* hr0 = g1h->region_at(0);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   849
  HeapRegion* hr1 = g1h->region_at(1);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   850
  HeapRegion* hr2 = g1h->region_at(5);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   851
  HeapRegion* hr3 = g1h->region_at(6);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   852
  HeapRegion* hr4 = g1h->region_at(7);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   853
  HeapRegion* hr5 = g1h->region_at(8);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   854
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   855
  HeapWord* hr1_start = hr1->bottom();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   856
  HeapWord* hr1_mid = hr1_start + HeapRegion::GrainWords/2;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   857
  HeapWord* hr1_last = hr1->end() - 1;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   858
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   859
  HeapWord* hr2_start = hr2->bottom();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   860
  HeapWord* hr2_mid = hr2_start + HeapRegion::GrainWords/2;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   861
  HeapWord* hr2_last = hr2->end() - 1;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   862
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   863
  HeapWord* hr3_start = hr3->bottom();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   864
  HeapWord* hr3_mid = hr3_start + HeapRegion::GrainWords/2;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   865
  HeapWord* hr3_last = hr3->end() - 1;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   866
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   867
  HeapRegionRemSet* hrrs = hr0->rem_set();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   868
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   869
  // Make three references from region 0x101...
3262
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
   870
  hrrs->add_reference((OopOrNarrowOopStar)hr1_start);
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
   871
  hrrs->add_reference((OopOrNarrowOopStar)hr1_mid);
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
   872
  hrrs->add_reference((OopOrNarrowOopStar)hr1_last);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   873
3262
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
   874
  hrrs->add_reference((OopOrNarrowOopStar)hr2_start);
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
   875
  hrrs->add_reference((OopOrNarrowOopStar)hr2_mid);
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
   876
  hrrs->add_reference((OopOrNarrowOopStar)hr2_last);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   877
3262
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
   878
  hrrs->add_reference((OopOrNarrowOopStar)hr3_start);
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
   879
  hrrs->add_reference((OopOrNarrowOopStar)hr3_mid);
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
   880
  hrrs->add_reference((OopOrNarrowOopStar)hr3_last);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   881
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   882
  // Now cause a coarsening.
3262
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
   883
  hrrs->add_reference((OopOrNarrowOopStar)hr4->bottom());
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
   884
  hrrs->add_reference((OopOrNarrowOopStar)hr5->bottom());
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   885
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   886
  // Now, does iteration yield these three?
17108
cf72dcf9a8f2 8011724: G1: Stack allocate instances of HeapRegionRemSetIterator
johnc
parents: 13752
diff changeset
   887
  HeapRegionRemSetIterator iter(hrrs);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   888
  size_t sum = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   889
  size_t card_index;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   890
  while (iter.has_next(card_index)) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   891
    HeapWord* card_start =
35461
1068dcb8d315 8146399: Refactor the BlockOffsetTable classes.
david
parents: 35210
diff changeset
   892
      G1CollectedHeap::heap()->bot()->address_for_index(card_index);
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34649
diff changeset
   893
    tty->print_cr("  Card " PTR_FORMAT ".", p2i(card_start));
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   894
    sum++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   895
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   896
  guarantee(sum == 11 - 3 + 2048, "Failure");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   897
  guarantee(sum == hrrs->occupied(), "Failure");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   898
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   899
#endif