hotspot/src/share/vm/gc_implementation/g1/heapRegionRemSet.cpp
author tonyp
Wed, 25 Jan 2012 12:58:23 -0500
changeset 11584 e1df4d08a1f4
parent 10767 4ce4a9b10523
child 12381 1438e0fbfa27
permissions -rw-r--r--
7127706: G1: re-enable survivors during the initial-mark pause Summary: Re-enable survivors during the initial-mark pause. Afterwards, the concurrent marking threads have to scan them and mark everything reachable from them. The next GC will have to wait for the survivors to be scanned. Reviewed-by: brutisso, johnc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     1
/*
8072
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
     2
 * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     4
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     8
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    13
 * accompanied this code).
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    14
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 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"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6981
diff changeset
    26
#include "gc_implementation/g1/concurrentG1Refine.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6981
diff changeset
    27
#include "gc_implementation/g1/g1BlockOffsetTable.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6981
diff changeset
    28
#include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6981
diff changeset
    29
#include "gc_implementation/g1/heapRegionRemSet.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6981
diff changeset
    30
#include "gc_implementation/g1/heapRegionSeq.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6981
diff changeset
    31
#include "memory/allocation.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6981
diff changeset
    32
#include "memory/space.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6981
diff changeset
    33
#include "utilities/bitMap.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6981
diff changeset
    34
#include "utilities/globalDefinitions.hpp"
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    35
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    36
#define HRRS_VERBOSE 0
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    37
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    38
#define PRT_COUNT_OCCUPIED 1
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    39
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    40
// OtherRegionsTable
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    41
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    42
class PerRegionTable: public CHeapObj {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    43
  friend class OtherRegionsTable;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    44
  friend class HeapRegionRemSetIterator;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    45
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    46
  HeapRegion*     _hr;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    47
  BitMap          _bm;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    48
#if PRT_COUNT_OCCUPIED
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    49
  jint            _occupied;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    50
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    51
  PerRegionTable* _next_free;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    52
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    53
  PerRegionTable* next_free() { return _next_free; }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    54
  void set_next_free(PerRegionTable* prt) { _next_free = prt; }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    55
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    56
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    57
  static PerRegionTable* _free_list;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    58
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    59
#ifdef _MSC_VER
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    60
  // For some reason even though the classes are marked as friend they are unable
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    61
  // to access CardsPerRegion when private/protected. Only the windows c++ compiler
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    62
  // says this Sun CC and linux gcc don't have a problem with access when private
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    63
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    64
  public:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    65
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    66
#endif // _MSC_VER
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    67
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    68
protected:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    69
  // 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
    70
  BitMap* bm() { return &_bm; }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    71
2009
4adf43957a1b 6484959: G1: introduce survivor spaces
apetrusenko
parents: 1676
diff changeset
    72
#if PRT_COUNT_OCCUPIED
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    73
  void recount_occupied() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    74
    _occupied = (jint) bm()->count_one_bits();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    75
  }
2009
4adf43957a1b 6484959: G1: introduce survivor spaces
apetrusenko
parents: 1676
diff changeset
    76
#endif
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    77
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    78
  PerRegionTable(HeapRegion* hr) :
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    79
    _hr(hr),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    80
#if PRT_COUNT_OCCUPIED
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    81
    _occupied(0),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    82
#endif
3697
ea9211aa02f5 6819085: G1: use larger and/or user settable region size
tonyp
parents: 3262
diff changeset
    83
    _bm(HeapRegion::CardsPerRegion, false /* in-resource-area */)
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    84
  {}
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
  static void free(PerRegionTable* prt) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    87
    while (true) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    88
      PerRegionTable* fl = _free_list;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    89
      prt->set_next_free(fl);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    90
      PerRegionTable* res =
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    91
        (PerRegionTable*)
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    92
        Atomic::cmpxchg_ptr(prt, &_free_list, fl);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    93
      if (res == fl) return;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    94
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    95
    ShouldNotReachHere();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    96
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    97
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    98
  static PerRegionTable* alloc(HeapRegion* hr) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    99
    PerRegionTable* fl = _free_list;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   100
    while (fl != NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   101
      PerRegionTable* nxt = fl->next_free();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   102
      PerRegionTable* res =
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   103
        (PerRegionTable*)
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   104
        Atomic::cmpxchg_ptr(nxt, &_free_list, fl);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   105
      if (res == fl) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   106
        fl->init(hr);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   107
        return fl;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   108
      } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   109
        fl = _free_list;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   110
      }
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
    assert(fl == NULL, "Loop condition.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   113
    return new PerRegionTable(hr);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   114
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   115
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2882
diff changeset
   116
  void add_card_work(CardIdx_t from_card, bool par) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   117
    if (!_bm.at(from_card)) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   118
      if (par) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   119
        if (_bm.par_at_put(from_card, 1)) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   120
#if PRT_COUNT_OCCUPIED
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   121
          Atomic::inc(&_occupied);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   122
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   123
        }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   124
      } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   125
        _bm.at_put(from_card, 1);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   126
#if PRT_COUNT_OCCUPIED
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   127
        _occupied++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   128
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   129
      }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   130
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   131
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   132
3262
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
   133
  void add_reference_work(OopOrNarrowOopStar from, bool par) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   134
    // 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
   135
    // concurrency.
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
#if HRRS_VERBOSE
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   138
    gclog_or_tty->print_cr("    PRT::Add_reference_work(" PTR_FORMAT "->" PTR_FORMAT").",
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   139
                           from, *from);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   140
#endif
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
    HeapRegion* loc_hr = hr();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   143
    // If the test below fails, then this table was reused concurrently
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   144
    // 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
   145
    // and adding a bit to the new table is never incorrect.
10767
4ce4a9b10523 7097516: G1: assert(0<= from_card && from_card<HeapRegion::CardsPerRegion) failed: Must be in range.
brutisso
parents: 10677
diff changeset
   146
    // If the table used to belong to a continues humongous region and is
4ce4a9b10523 7097516: G1: assert(0<= from_card && from_card<HeapRegion::CardsPerRegion) failed: Must be in range.
brutisso
parents: 10677
diff changeset
   147
    // now reused for the corresponding start humongous region, we need to
4ce4a9b10523 7097516: G1: assert(0<= from_card && from_card<HeapRegion::CardsPerRegion) failed: Must be in range.
brutisso
parents: 10677
diff changeset
   148
    // make sure that we detect this. Thus, we call is_in_reserved_raw()
4ce4a9b10523 7097516: G1: assert(0<= from_card && from_card<HeapRegion::CardsPerRegion) failed: Must be in range.
brutisso
parents: 10677
diff changeset
   149
    // instead of just is_in_reserved() here.
4ce4a9b10523 7097516: G1: assert(0<= from_card && from_card<HeapRegion::CardsPerRegion) failed: Must be in range.
brutisso
parents: 10677
diff changeset
   150
    if (loc_hr->is_in_reserved_raw(from)) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   151
      size_t hw_offset = pointer_delta((HeapWord*)from, loc_hr->bottom());
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2882
diff changeset
   152
      CardIdx_t from_card = (CardIdx_t)
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2882
diff changeset
   153
          hw_offset >> (CardTableModRefBS::card_shift - LogHeapWordSize);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   154
10677
370a8da2d63f 7095194: G1: HeapRegion::GrainBytes, GrainWords, and CardsPerRegion should be size_t
johnc
parents: 10243
diff changeset
   155
      assert(0 <= from_card && (size_t)from_card < HeapRegion::CardsPerRegion,
3697
ea9211aa02f5 6819085: G1: use larger and/or user settable region size
tonyp
parents: 3262
diff changeset
   156
             "Must be in range.");
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2882
diff changeset
   157
      add_card_work(from_card, par);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   158
    }
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
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   161
public:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   162
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   163
  HeapRegion* hr() const { return _hr; }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   164
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   165
#if PRT_COUNT_OCCUPIED
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   166
  jint occupied() const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   167
    // Overkill, but if we ever need it...
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   168
    // guarantee(_occupied == _bm.count_one_bits(), "Check");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   169
    return _occupied;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   170
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   171
#else
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   172
  jint occupied() const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   173
    return _bm.count_one_bits();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   174
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   175
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   176
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   177
  void init(HeapRegion* hr) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   178
    _hr = hr;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   179
#if PRT_COUNT_OCCUPIED
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   180
    _occupied = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   181
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   182
    _bm.clear();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   183
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   184
3262
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
   185
  void add_reference(OopOrNarrowOopStar from) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   186
    add_reference_work(from, /*parallel*/ true);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   187
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   188
3262
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
   189
  void seq_add_reference(OopOrNarrowOopStar from) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   190
    add_reference_work(from, /*parallel*/ false);
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
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   193
  void scrub(CardTableModRefBS* ctbs, BitMap* card_bm) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   194
    HeapWord* hr_bot = hr()->bottom();
1676
d80e69372634 6653214: MemoryPoolMXBean.setUsageThreshold() does not support large heap sizes.
swamyv
parents: 1374
diff changeset
   195
    size_t hr_first_card_index = ctbs->index_for(hr_bot);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   196
    bm()->set_intersection_at_offset(*card_bm, hr_first_card_index);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   197
#if PRT_COUNT_OCCUPIED
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   198
    recount_occupied();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   199
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   200
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   201
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2882
diff changeset
   202
  void add_card(CardIdx_t from_card_index) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   203
    add_card_work(from_card_index, /*parallel*/ true);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   204
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   205
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2882
diff changeset
   206
  void seq_add_card(CardIdx_t from_card_index) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   207
    add_card_work(from_card_index, /*parallel*/ false);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   208
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   209
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   210
  // (Destructively) union the bitmap of the current table into the given
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   211
  // bitmap (which is assumed to be of the same size.)
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   212
  void union_bitmap_into(BitMap* bm) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   213
    bm->set_union(_bm);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   214
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   215
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   216
  // Mem size in bytes.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   217
  size_t mem_size() const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   218
    return sizeof(this) + _bm.size_in_words() * HeapWordSize;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   219
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   220
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   221
  static size_t fl_mem_size() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   222
    PerRegionTable* cur = _free_list;
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) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   225
      res += sizeof(PerRegionTable);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   226
      cur = cur->next_free();
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
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   230
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   231
  // Requires "from" to be in "hr()".
3262
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
   232
  bool contains_reference(OopOrNarrowOopStar from) const {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   233
    assert(hr()->is_in_reserved(from), "Precondition.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   234
    size_t card_ind = pointer_delta(from, hr()->bottom(),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   235
                                    CardTableModRefBS::card_size);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   236
    return _bm.at(card_ind);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   237
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   238
};
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   239
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   240
PerRegionTable* PerRegionTable::_free_list = NULL;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   241
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   242
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   243
#define COUNT_PAR_EXPANDS 0
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   244
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   245
#if COUNT_PAR_EXPANDS
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   246
static jint n_par_expands = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   247
static jint n_par_contracts = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   248
static jint par_expand_list_len = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   249
static jint max_par_expand_list_len = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   250
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   251
static void print_par_expand() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   252
  Atomic::inc(&n_par_expands);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   253
  Atomic::inc(&par_expand_list_len);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   254
  if (par_expand_list_len > max_par_expand_list_len) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   255
    max_par_expand_list_len = par_expand_list_len;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   256
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   257
  if ((n_par_expands % 10) == 0) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   258
    gclog_or_tty->print_cr("\n\n%d par expands: %d contracts, "
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   259
                  "len = %d, max_len = %d\n.",
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   260
                  n_par_expands, n_par_contracts, par_expand_list_len,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   261
                  max_par_expand_list_len);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   262
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   263
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   264
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   265
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   266
class PosParPRT: public PerRegionTable {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   267
  PerRegionTable** _par_tables;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   268
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   269
  enum SomePrivateConstants {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   270
    ReserveParTableExpansion = 1
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   271
  };
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   272
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   273
  void par_contract() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   274
    assert(_par_tables != NULL, "Precondition.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   275
    int n = HeapRegionRemSet::num_par_rem_sets()-1;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   276
    for (int i = 0; i < n; i++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   277
      _par_tables[i]->union_bitmap_into(bm());
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   278
      PerRegionTable::free(_par_tables[i]);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   279
      _par_tables[i] = NULL;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   280
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   281
#if PRT_COUNT_OCCUPIED
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   282
    // We must recount the "occupied."
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   283
    recount_occupied();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   284
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   285
    FREE_C_HEAP_ARRAY(PerRegionTable*, _par_tables);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   286
    _par_tables = NULL;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   287
#if COUNT_PAR_EXPANDS
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   288
    Atomic::inc(&n_par_contracts);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   289
    Atomic::dec(&par_expand_list_len);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   290
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   291
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   292
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   293
  static PerRegionTable** _par_table_fl;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   294
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   295
  PosParPRT* _next;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   296
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   297
  static PosParPRT* _free_list;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   298
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   299
  PerRegionTable** par_tables() const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   300
    assert(uintptr_t(NULL) == 0, "Assumption.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   301
    if (uintptr_t(_par_tables) <= ReserveParTableExpansion)
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   302
      return NULL;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   303
    else
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   304
      return _par_tables;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   305
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   306
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   307
  PosParPRT* _next_par_expanded;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   308
  PosParPRT* next_par_expanded() { return _next_par_expanded; }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   309
  void set_next_par_expanded(PosParPRT* ppprt) { _next_par_expanded = ppprt; }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   310
  static PosParPRT* _par_expanded_list;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   311
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   312
public:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   313
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   314
  PosParPRT(HeapRegion* hr) : PerRegionTable(hr), _par_tables(NULL) {}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   315
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   316
  jint occupied() const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   317
    jint res = PerRegionTable::occupied();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   318
    if (par_tables() != NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   319
      for (int i = 0; i < HeapRegionRemSet::num_par_rem_sets()-1; i++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   320
        res += par_tables()[i]->occupied();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   321
      }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   322
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   323
    return res;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   324
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   325
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   326
  void init(HeapRegion* hr) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   327
    PerRegionTable::init(hr);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   328
    _next = NULL;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   329
    if (par_tables() != NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   330
      for (int i = 0; i < HeapRegionRemSet::num_par_rem_sets()-1; i++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   331
        par_tables()[i]->init(hr);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   332
      }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   333
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   334
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   335
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   336
  static void free(PosParPRT* prt) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   337
    while (true) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   338
      PosParPRT* fl = _free_list;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   339
      prt->set_next(fl);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   340
      PosParPRT* res =
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   341
        (PosParPRT*)
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   342
        Atomic::cmpxchg_ptr(prt, &_free_list, fl);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   343
      if (res == fl) return;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   344
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   345
    ShouldNotReachHere();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   346
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   347
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   348
  static PosParPRT* alloc(HeapRegion* hr) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   349
    PosParPRT* fl = _free_list;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   350
    while (fl != NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   351
      PosParPRT* nxt = fl->next();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   352
      PosParPRT* res =
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   353
        (PosParPRT*)
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   354
        Atomic::cmpxchg_ptr(nxt, &_free_list, fl);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   355
      if (res == fl) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   356
        fl->init(hr);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   357
        return fl;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   358
      } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   359
        fl = _free_list;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   360
      }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   361
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   362
    assert(fl == NULL, "Loop condition.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   363
    return new PosParPRT(hr);
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
  PosParPRT* next() const { return _next; }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   367
  void set_next(PosParPRT* nxt) { _next = nxt; }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   368
  PosParPRT** next_addr() { return &_next; }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   369
4900
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   370
  bool should_expand(int tid) {
10243
d00a21009f1f 7039627: G1: avoid BOT updates for survivor allocations and dirty survivor regions incrementally
tonyp
parents: 10000
diff changeset
   371
    // Given that we now defer RSet updates for after a GC we don't
d00a21009f1f 7039627: G1: avoid BOT updates for survivor allocations and dirty survivor regions incrementally
tonyp
parents: 10000
diff changeset
   372
    // really need to expand the tables any more. This code should be
d00a21009f1f 7039627: G1: avoid BOT updates for survivor allocations and dirty survivor regions incrementally
tonyp
parents: 10000
diff changeset
   373
    // cleaned up in the future (see CR 6921087).
d00a21009f1f 7039627: G1: avoid BOT updates for survivor allocations and dirty survivor regions incrementally
tonyp
parents: 10000
diff changeset
   374
    return false;
4900
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   375
  }
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   376
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   377
  void par_expand() {
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   378
    int n = HeapRegionRemSet::num_par_rem_sets()-1;
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   379
    if (n <= 0) return;
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   380
    if (_par_tables == NULL) {
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   381
      PerRegionTable* res =
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   382
        (PerRegionTable*)
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   383
        Atomic::cmpxchg_ptr((PerRegionTable*)ReserveParTableExpansion,
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   384
                            &_par_tables, NULL);
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   385
      if (res != NULL) return;
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   386
      // Otherwise, we reserved the right to do the expansion.
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   387
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   388
      PerRegionTable** ptables = NEW_C_HEAP_ARRAY(PerRegionTable*, n);
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   389
      for (int i = 0; i < n; i++) {
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   390
        PerRegionTable* ptable = PerRegionTable::alloc(hr());
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   391
        ptables[i] = ptable;
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   392
      }
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   393
      // Here we do not need an atomic.
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   394
      _par_tables = ptables;
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   395
#if COUNT_PAR_EXPANDS
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   396
      print_par_expand();
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   397
#endif
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   398
      // We must put this table on the expanded list.
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   399
      PosParPRT* exp_head = _par_expanded_list;
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   400
      while (true) {
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   401
        set_next_par_expanded(exp_head);
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   402
        PosParPRT* res =
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   403
          (PosParPRT*)
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   404
          Atomic::cmpxchg_ptr(this, &_par_expanded_list, exp_head);
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   405
        if (res == exp_head) return;
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   406
        // Otherwise.
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   407
        exp_head = res;
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   408
      }
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   409
      ShouldNotReachHere();
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   410
    }
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   411
  }
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   412
3262
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
   413
  void add_reference(OopOrNarrowOopStar from, int tid) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   414
    // Expand if necessary.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   415
    PerRegionTable** pt = par_tables();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   416
    if (pt != NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   417
      // We always have to assume that mods to table 0 are in parallel,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   418
      // because of the claiming scheme in parallel expansion.  A thread
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   419
      // with tid != 0 that finds the table to be NULL, but doesn't succeed
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   420
      // in claiming the right of expanding it, will end up in the else
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   421
      // clause of the above if test.  That thread could be delayed, and a
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   422
      // thread 0 add reference could see the table expanded, and come
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   423
      // here.  Both threads would be adding in parallel.  But we get to
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   424
      // not use atomics for tids > 0.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   425
      if (tid == 0) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   426
        PerRegionTable::add_reference(from);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   427
      } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   428
        pt[tid-1]->seq_add_reference(from);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   429
      }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   430
    } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   431
      // Not expanded -- add to the base table.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   432
      PerRegionTable::add_reference(from);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   433
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   434
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   435
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   436
  void scrub(CardTableModRefBS* ctbs, BitMap* card_bm) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   437
    assert(_par_tables == NULL, "Precondition");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   438
    PerRegionTable::scrub(ctbs, card_bm);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   439
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   440
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   441
  size_t mem_size() const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   442
    size_t res =
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   443
      PerRegionTable::mem_size() + sizeof(this) - sizeof(PerRegionTable);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   444
    if (_par_tables != NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   445
      for (int i = 0; i < HeapRegionRemSet::num_par_rem_sets()-1; i++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   446
        res += _par_tables[i]->mem_size();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   447
      }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   448
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   449
    return res;
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
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   452
  static size_t fl_mem_size() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   453
    PosParPRT* cur = _free_list;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   454
    size_t res = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   455
    while (cur != NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   456
      res += sizeof(PosParPRT);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   457
      cur = cur->next();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   458
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   459
    return res;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   460
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   461
3262
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
   462
  bool contains_reference(OopOrNarrowOopStar from) const {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   463
    if (PerRegionTable::contains_reference(from)) return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   464
    if (_par_tables != NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   465
      for (int i = 0; i < HeapRegionRemSet::num_par_rem_sets()-1; i++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   466
        if (_par_tables[i]->contains_reference(from)) return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   467
      }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   468
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   469
    return false;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   470
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   471
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   472
  static void par_contract_all();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   473
};
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   474
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   475
void PosParPRT::par_contract_all() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   476
  PosParPRT* hd = _par_expanded_list;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   477
  while (hd != NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   478
    PosParPRT* nxt = hd->next_par_expanded();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   479
    PosParPRT* res =
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   480
      (PosParPRT*)
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   481
      Atomic::cmpxchg_ptr(nxt, &_par_expanded_list, hd);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   482
    if (res == hd) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   483
      // We claimed the right to contract this table.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   484
      hd->set_next_par_expanded(NULL);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   485
      hd->par_contract();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   486
      hd = _par_expanded_list;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   487
    } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   488
      hd = res;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   489
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   490
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   491
}
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
PosParPRT* PosParPRT::_free_list = NULL;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   494
PosParPRT* PosParPRT::_par_expanded_list = NULL;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   495
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   496
jint OtherRegionsTable::_cache_probes = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   497
jint OtherRegionsTable::_cache_hits = 0;
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
size_t OtherRegionsTable::_max_fine_entries = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   500
size_t OtherRegionsTable::_mod_max_fine_entries_mask = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   501
#if SAMPLE_FOR_EVICTION
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   502
size_t OtherRegionsTable::_fine_eviction_stride = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   503
size_t OtherRegionsTable::_fine_eviction_sample_size = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   504
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   505
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   506
OtherRegionsTable::OtherRegionsTable(HeapRegion* hr) :
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   507
  _g1h(G1CollectedHeap::heap()),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   508
  _m(Mutex::leaf, "An OtherRegionsTable lock", true),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   509
  _hr(hr),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   510
  _coarse_map(G1CollectedHeap::heap()->max_regions(),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   511
              false /* in-resource-area */),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   512
  _fine_grain_regions(NULL),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   513
  _n_fine_entries(0), _n_coarse_entries(0),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   514
#if SAMPLE_FOR_EVICTION
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   515
  _fine_eviction_start(0),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   516
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   517
  _sparse_table(hr)
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   518
{
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   519
  typedef PosParPRT* PosParPRTPtr;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   520
  if (_max_fine_entries == 0) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   521
    assert(_mod_max_fine_entries_mask == 0, "Both or none.");
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
   522
    size_t max_entries_log = (size_t)log2_long((jlong)G1RSetRegionEntries);
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
   523
    _max_fine_entries = (size_t)(1 << max_entries_log);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   524
    _mod_max_fine_entries_mask = _max_fine_entries - 1;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   525
#if SAMPLE_FOR_EVICTION
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   526
    assert(_fine_eviction_sample_size == 0
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   527
           && _fine_eviction_stride == 0, "All init at same time.");
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
   528
    _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
   529
    _fine_eviction_stride = _max_fine_entries / _fine_eviction_sample_size;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   530
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   531
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   532
  _fine_grain_regions = new PosParPRTPtr[_max_fine_entries];
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   533
  if (_fine_grain_regions == NULL)
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   534
    vm_exit_out_of_memory(sizeof(void*)*_max_fine_entries,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   535
                          "Failed to allocate _fine_grain_entries.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   536
  for (size_t i = 0; i < _max_fine_entries; i++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   537
    _fine_grain_regions[i] = NULL;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   538
  }
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
int** OtherRegionsTable::_from_card_cache = NULL;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   542
size_t OtherRegionsTable::_from_card_cache_max_regions = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   543
size_t OtherRegionsTable::_from_card_cache_mem_size = 0;
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
void OtherRegionsTable::init_from_card_cache(size_t max_regions) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   546
  _from_card_cache_max_regions = max_regions;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   547
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   548
  int n_par_rs = HeapRegionRemSet::num_par_rem_sets();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   549
  _from_card_cache = NEW_C_HEAP_ARRAY(int*, n_par_rs);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   550
  for (int i = 0; i < n_par_rs; i++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   551
    _from_card_cache[i] = NEW_C_HEAP_ARRAY(int, max_regions);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   552
    for (size_t j = 0; j < max_regions; j++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   553
      _from_card_cache[i][j] = -1;  // An invalid value.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   554
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   555
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   556
  _from_card_cache_mem_size = n_par_rs * max_regions * sizeof(int);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   557
}
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
void OtherRegionsTable::shrink_from_card_cache(size_t new_n_regs) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   560
  for (int i = 0; i < HeapRegionRemSet::num_par_rem_sets(); i++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   561
    assert(new_n_regs <= _from_card_cache_max_regions, "Must be within max.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   562
    for (size_t j = new_n_regs; j < _from_card_cache_max_regions; j++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   563
      _from_card_cache[i][j] = -1;  // An invalid value.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   564
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   565
  }
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
#ifndef PRODUCT
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   569
void OtherRegionsTable::print_from_card_cache() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   570
  for (int i = 0; i < HeapRegionRemSet::num_par_rem_sets(); i++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   571
    for (size_t j = 0; j < _from_card_cache_max_regions; j++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   572
      gclog_or_tty->print_cr("_from_card_cache[%d][%d] = %d.",
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   573
                    i, j, _from_card_cache[i][j]);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   574
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   575
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   576
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   577
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   578
3262
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
   579
void OtherRegionsTable::add_reference(OopOrNarrowOopStar from, int tid) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   580
  size_t cur_hrs_ind = hr()->hrs_index();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   581
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   582
#if HRRS_VERBOSE
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   583
  gclog_or_tty->print_cr("ORT::add_reference_work(" PTR_FORMAT "->" PTR_FORMAT ").",
3262
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
   584
                                                  from,
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
   585
                                                  UseCompressedOops
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
   586
                                                  ? oopDesc::load_decode_heap_oop((narrowOop*)from)
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
   587
                                                  : oopDesc::load_decode_heap_oop((oop*)from));
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   588
#endif
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
  int from_card = (int)(uintptr_t(from) >> CardTableModRefBS::card_shift);
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
#if HRRS_VERBOSE
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   593
  gclog_or_tty->print_cr("Table for [" PTR_FORMAT "...): card %d (cache = %d)",
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   594
                hr()->bottom(), from_card,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   595
                _from_card_cache[tid][cur_hrs_ind]);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   596
#endif
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
#define COUNT_CACHE 0
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   599
#if COUNT_CACHE
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   600
  jint p = Atomic::add(1, &_cache_probes);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   601
  if ((p % 10000) == 0) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   602
    jint hits = _cache_hits;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   603
    gclog_or_tty->print_cr("%d/%d = %5.2f%% RS cache hits.",
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   604
                  _cache_hits, p, 100.0* (float)hits/(float)p);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   605
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   606
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   607
  if (from_card == _from_card_cache[tid][cur_hrs_ind]) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   608
#if HRRS_VERBOSE
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   609
    gclog_or_tty->print_cr("  from-card cache hit.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   610
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   611
#if COUNT_CACHE
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   612
    Atomic::inc(&_cache_hits);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   613
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   614
    assert(contains_reference(from), "We just added it!");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   615
    return;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   616
  } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   617
    _from_card_cache[tid][cur_hrs_ind] = from_card;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   618
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   619
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   620
  // Note that this may be a continued H region.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   621
  HeapRegion* from_hr = _g1h->heap_region_containing_raw(from);
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2882
diff changeset
   622
  RegionIdx_t from_hrs_ind = (RegionIdx_t) from_hr->hrs_index();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   623
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   624
  // If the region is already coarsened, return.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   625
  if (_coarse_map.at(from_hrs_ind)) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   626
#if HRRS_VERBOSE
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   627
    gclog_or_tty->print_cr("  coarse map hit.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   628
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   629
    assert(contains_reference(from), "We just added it!");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   630
    return;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   631
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   632
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   633
  // Otherwise find a per-region table to add it to.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   634
  size_t ind = from_hrs_ind & _mod_max_fine_entries_mask;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   635
  PosParPRT* prt = find_region_table(ind, from_hr);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   636
  if (prt == NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   637
    MutexLockerEx x(&_m, Mutex::_no_safepoint_check_flag);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   638
    // Confirm that it's really not there...
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   639
    prt = find_region_table(ind, from_hr);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   640
    if (prt == NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   641
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   642
      uintptr_t from_hr_bot_card_index =
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   643
        uintptr_t(from_hr->bottom())
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   644
          >> CardTableModRefBS::card_shift;
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2882
diff changeset
   645
      CardIdx_t card_index = from_card - from_hr_bot_card_index;
10677
370a8da2d63f 7095194: G1: HeapRegion::GrainBytes, GrainWords, and CardsPerRegion should be size_t
johnc
parents: 10243
diff changeset
   646
      assert(0 <= card_index && (size_t)card_index < HeapRegion::CardsPerRegion,
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   647
             "Must be in range.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   648
      if (G1HRRSUseSparseTable &&
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2882
diff changeset
   649
          _sparse_table.add_card(from_hrs_ind, card_index)) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   650
        if (G1RecordHRRSOops) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   651
          HeapRegionRemSet::record(hr(), from);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   652
#if HRRS_VERBOSE
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   653
          gclog_or_tty->print("   Added card " PTR_FORMAT " to region "
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   654
                              "[" PTR_FORMAT "...) for ref " PTR_FORMAT ".\n",
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   655
                              align_size_down(uintptr_t(from),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   656
                                              CardTableModRefBS::card_size),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   657
                              hr()->bottom(), from);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   658
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   659
        }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   660
#if HRRS_VERBOSE
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   661
        gclog_or_tty->print_cr("   added card to sparse table.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   662
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   663
        assert(contains_reference_locked(from), "We just added it!");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   664
        return;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   665
      } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   666
#if HRRS_VERBOSE
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   667
        gclog_or_tty->print_cr("   [tid %d] sparse table entry "
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   668
                      "overflow(f: %d, t: %d)",
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   669
                      tid, from_hrs_ind, cur_hrs_ind);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   670
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   671
      }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   672
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   673
      if (_n_fine_entries == _max_fine_entries) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   674
        prt = delete_region_table();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   675
      } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   676
        prt = PosParPRT::alloc(from_hr);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   677
      }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   678
      prt->init(from_hr);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   679
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   680
      PosParPRT* first_prt = _fine_grain_regions[ind];
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   681
      prt->set_next(first_prt);  // XXX Maybe move to init?
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   682
      _fine_grain_regions[ind] = prt;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   683
      _n_fine_entries++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   684
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   685
      if (G1HRRSUseSparseTable) {
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
   686
        // Transfer from sparse to fine-grain.
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
   687
        SparsePRTEntry *sprt_entry = _sparse_table.get_entry(from_hrs_ind);
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
   688
        assert(sprt_entry != NULL, "There should have been an entry");
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
   689
        for (int i = 0; i < SparsePRTEntry::cards_num(); i++) {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
   690
          CardIdx_t c = sprt_entry->card(i);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   691
          if (c != SparsePRTEntry::NullEntry) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   692
            prt->add_card(c);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   693
          }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   694
        }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   695
        // Now we can delete the sparse entry.
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2882
diff changeset
   696
        bool res = _sparse_table.delete_entry(from_hrs_ind);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   697
        assert(res, "It should have been there.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   698
      }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   699
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   700
    assert(prt != NULL && prt->hr() == from_hr, "consequence");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   701
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   702
  // 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
   703
  // possibility of concurrent reuse.  But see head comment of
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   704
  // OtherRegionsTable for why this is OK.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   705
  assert(prt != NULL, "Inv");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   706
4900
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   707
  if (prt->should_expand(tid)) {
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   708
    MutexLockerEx x(&_m, Mutex::_no_safepoint_check_flag);
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   709
    HeapRegion* prt_hr = prt->hr();
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   710
    if (prt_hr == from_hr) {
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   711
      // Make sure the table still corresponds to the same region
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   712
      prt->par_expand();
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   713
      prt->add_reference(from, tid);
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   714
    }
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   715
    // else: The table has been concurrently coarsened, evicted, and
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   716
    // the table data structure re-used for another table. So, we
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   717
    // don't need to add the reference any more given that the table
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   718
    // has been coarsened and the whole region will be scanned anyway.
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   719
  } else {
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   720
    prt->add_reference(from, tid);
3fab535e2fd6 6802453: G1: hr()->is_in_reserved(from),"Precondition."
tonyp
parents: 3697
diff changeset
   721
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   722
  if (G1RecordHRRSOops) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   723
    HeapRegionRemSet::record(hr(), from);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   724
#if HRRS_VERBOSE
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   725
    gclog_or_tty->print("Added card " PTR_FORMAT " to region "
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   726
                        "[" PTR_FORMAT "...) for ref " PTR_FORMAT ".\n",
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   727
                        align_size_down(uintptr_t(from),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   728
                                        CardTableModRefBS::card_size),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   729
                        hr()->bottom(), from);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   730
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   731
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   732
  assert(contains_reference(from), "We just added it!");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   733
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   734
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   735
PosParPRT*
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   736
OtherRegionsTable::find_region_table(size_t ind, HeapRegion* hr) const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   737
  assert(0 <= ind && ind < _max_fine_entries, "Preconditions.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   738
  PosParPRT* prt = _fine_grain_regions[ind];
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   739
  while (prt != NULL && prt->hr() != hr) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   740
    prt = prt->next();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   741
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   742
  // Loop postcondition is the method postcondition.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   743
  return prt;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   744
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   745
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   746
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   747
#define DRT_CENSUS 0
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   748
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   749
#if DRT_CENSUS
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   750
static const int HistoSize = 6;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   751
static int global_histo[HistoSize] = { 0, 0, 0, 0, 0, 0 };
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   752
static int coarsenings = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   753
static int occ_sum = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   754
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   755
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   756
jint OtherRegionsTable::_n_coarsenings = 0;
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
PosParPRT* OtherRegionsTable::delete_region_table() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   759
#if DRT_CENSUS
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   760
  int histo[HistoSize] = { 0, 0, 0, 0, 0, 0 };
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   761
  const int histo_limits[] = { 1, 4, 16, 64, 256, 2048 };
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   762
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   763
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   764
  assert(_m.owned_by_self(), "Precondition");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   765
  assert(_n_fine_entries == _max_fine_entries, "Precondition");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   766
  PosParPRT* max = NULL;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   767
  jint max_occ = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   768
  PosParPRT** max_prev;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   769
  size_t max_ind;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   770
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   771
#if SAMPLE_FOR_EVICTION
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   772
  size_t i = _fine_eviction_start;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   773
  for (size_t k = 0; k < _fine_eviction_sample_size; k++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   774
    size_t ii = i;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   775
    // Make sure we get a non-NULL sample.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   776
    while (_fine_grain_regions[ii] == NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   777
      ii++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   778
      if (ii == _max_fine_entries) ii = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   779
      guarantee(ii != i, "We must find one.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   780
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   781
    PosParPRT** prev = &_fine_grain_regions[ii];
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   782
    PosParPRT* cur = *prev;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   783
    while (cur != NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   784
      jint cur_occ = cur->occupied();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   785
      if (max == NULL || cur_occ > max_occ) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   786
        max = cur;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   787
        max_prev = prev;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   788
        max_ind = i;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   789
        max_occ = cur_occ;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   790
      }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   791
      prev = cur->next_addr();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   792
      cur = cur->next();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   793
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   794
    i = i + _fine_eviction_stride;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   795
    if (i >= _n_fine_entries) i = i - _n_fine_entries;
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
  _fine_eviction_start++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   798
  if (_fine_eviction_start >= _n_fine_entries)
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   799
    _fine_eviction_start -= _n_fine_entries;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   800
#else
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   801
  for (int i = 0; i < _max_fine_entries; i++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   802
    PosParPRT** prev = &_fine_grain_regions[i];
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   803
    PosParPRT* cur = *prev;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   804
    while (cur != NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   805
      jint cur_occ = cur->occupied();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   806
#if DRT_CENSUS
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   807
      for (int k = 0; k < HistoSize; k++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   808
        if (cur_occ <= histo_limits[k]) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   809
          histo[k]++; global_histo[k]++; break;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   810
        }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   811
      }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   812
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   813
      if (max == NULL || cur_occ > max_occ) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   814
        max = cur;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   815
        max_prev = prev;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   816
        max_ind = i;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   817
        max_occ = cur_occ;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   818
      }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   819
      prev = cur->next_addr();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   820
      cur = cur->next();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   821
    }
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
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   824
  // XXX
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   825
  guarantee(max != NULL, "Since _n_fine_entries > 0");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   826
#if DRT_CENSUS
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   827
  gclog_or_tty->print_cr("In a coarsening: histo of occs:");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   828
  for (int k = 0; k < HistoSize; k++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   829
    gclog_or_tty->print_cr("  <= %4d: %5d.", histo_limits[k], histo[k]);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   830
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   831
  coarsenings++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   832
  occ_sum += max_occ;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   833
  if ((coarsenings % 100) == 0) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   834
    gclog_or_tty->print_cr("\ncoarsenings = %d; global summary:", coarsenings);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   835
    for (int k = 0; k < HistoSize; k++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   836
      gclog_or_tty->print_cr("  <= %4d: %5d.", histo_limits[k], global_histo[k]);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   837
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   838
    gclog_or_tty->print_cr("Avg occ of deleted region = %6.2f.",
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   839
                  (float)occ_sum/(float)coarsenings);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   840
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   841
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   842
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   843
  // Set the corresponding coarse bit.
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8072
diff changeset
   844
  size_t max_hrs_index = max->hr()->hrs_index();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   845
  if (!_coarse_map.at(max_hrs_index)) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   846
    _coarse_map.at_put(max_hrs_index, true);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   847
    _n_coarse_entries++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   848
#if 0
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   849
    gclog_or_tty->print("Coarsened entry in region [" PTR_FORMAT "...] "
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   850
               "for region [" PTR_FORMAT "...] (%d coarse entries).\n",
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   851
               hr()->bottom(),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   852
               max->hr()->bottom(),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   853
               _n_coarse_entries);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   854
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   855
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   856
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   857
  // Unsplice.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   858
  *max_prev = max->next();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   859
  Atomic::inc(&_n_coarsenings);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   860
  _n_fine_entries--;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   861
  return max;
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
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   864
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   865
// At present, this must be called stop-world single-threaded.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   866
void OtherRegionsTable::scrub(CardTableModRefBS* ctbs,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   867
                              BitMap* region_bm, BitMap* card_bm) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   868
  // First eliminated garbage regions from the coarse map.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   869
  if (G1RSScrubVerbose)
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8072
diff changeset
   870
    gclog_or_tty->print_cr("Scrubbing region "SIZE_FORMAT":",
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8072
diff changeset
   871
                           hr()->hrs_index());
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   872
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   873
  assert(_coarse_map.size() == region_bm->size(), "Precondition");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   874
  if (G1RSScrubVerbose)
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   875
    gclog_or_tty->print("   Coarse map: before = %d...", _n_coarse_entries);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   876
  _coarse_map.set_intersection(*region_bm);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   877
  _n_coarse_entries = _coarse_map.count_one_bits();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   878
  if (G1RSScrubVerbose)
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   879
    gclog_or_tty->print_cr("   after = %d.", _n_coarse_entries);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   880
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   881
  // Now do the fine-grained maps.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   882
  for (size_t i = 0; i < _max_fine_entries; i++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   883
    PosParPRT* cur = _fine_grain_regions[i];
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   884
    PosParPRT** prev = &_fine_grain_regions[i];
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   885
    while (cur != NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   886
      PosParPRT* nxt = cur->next();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   887
      // If the entire region is dead, eliminate.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   888
      if (G1RSScrubVerbose)
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8072
diff changeset
   889
        gclog_or_tty->print_cr("     For other region "SIZE_FORMAT":",
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8072
diff changeset
   890
                               cur->hr()->hrs_index());
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   891
      if (!region_bm->at(cur->hr()->hrs_index())) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   892
        *prev = nxt;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   893
        cur->set_next(NULL);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   894
        _n_fine_entries--;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   895
        if (G1RSScrubVerbose)
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   896
          gclog_or_tty->print_cr("          deleted via region map.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   897
        PosParPRT::free(cur);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   898
      } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   899
        // Do fine-grain elimination.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   900
        if (G1RSScrubVerbose)
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   901
          gclog_or_tty->print("          occ: before = %4d.", cur->occupied());
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   902
        cur->scrub(ctbs, card_bm);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   903
        if (G1RSScrubVerbose)
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   904
          gclog_or_tty->print_cr("          after = %4d.", cur->occupied());
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   905
        // Did that empty the table completely?
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   906
        if (cur->occupied() == 0) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   907
          *prev = nxt;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   908
          cur->set_next(NULL);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   909
          _n_fine_entries--;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   910
          PosParPRT::free(cur);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   911
        } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   912
          prev = cur->next_addr();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   913
        }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   914
      }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   915
      cur = nxt;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   916
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   917
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   918
  // Since we may have deleted a from_card_cache entry from the RS, clear
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   919
  // the FCC.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   920
  clear_fcc();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   921
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   922
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   923
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   924
size_t OtherRegionsTable::occupied() const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   925
  // Cast away const in this case.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   926
  MutexLockerEx x((Mutex*)&_m, Mutex::_no_safepoint_check_flag);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   927
  size_t sum = occ_fine();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   928
  sum += occ_sparse();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   929
  sum += occ_coarse();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   930
  return sum;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   931
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   932
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   933
size_t OtherRegionsTable::occ_fine() const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   934
  size_t sum = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   935
  for (size_t i = 0; i < _max_fine_entries; i++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   936
    PosParPRT* cur = _fine_grain_regions[i];
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   937
    while (cur != NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   938
      sum += cur->occupied();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   939
      cur = cur->next();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   940
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   941
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   942
  return sum;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   943
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   944
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   945
size_t OtherRegionsTable::occ_coarse() const {
3697
ea9211aa02f5 6819085: G1: use larger and/or user settable region size
tonyp
parents: 3262
diff changeset
   946
  return (_n_coarse_entries * HeapRegion::CardsPerRegion);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   947
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   948
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   949
size_t OtherRegionsTable::occ_sparse() const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   950
  return _sparse_table.occupied();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   951
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   952
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   953
size_t OtherRegionsTable::mem_size() const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   954
  // Cast away const in this case.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   955
  MutexLockerEx x((Mutex*)&_m, Mutex::_no_safepoint_check_flag);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   956
  size_t sum = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   957
  for (size_t i = 0; i < _max_fine_entries; i++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   958
    PosParPRT* cur = _fine_grain_regions[i];
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   959
    while (cur != NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   960
      sum += cur->mem_size();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   961
      cur = cur->next();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   962
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   963
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   964
  sum += (sizeof(PosParPRT*) * _max_fine_entries);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   965
  sum += (_coarse_map.size_in_words() * HeapWordSize);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   966
  sum += (_sparse_table.mem_size());
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   967
  sum += sizeof(*this) - sizeof(_sparse_table); // Avoid double counting above.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   968
  return sum;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   969
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   970
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   971
size_t OtherRegionsTable::static_mem_size() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   972
  return _from_card_cache_mem_size;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   973
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   974
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   975
size_t OtherRegionsTable::fl_mem_size() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   976
  return PerRegionTable::fl_mem_size() + PosParPRT::fl_mem_size();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   977
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   978
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   979
void OtherRegionsTable::clear_fcc() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   980
  for (int i = 0; i < HeapRegionRemSet::num_par_rem_sets(); i++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   981
    _from_card_cache[i][hr()->hrs_index()] = -1;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   982
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   983
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   984
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   985
void OtherRegionsTable::clear() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   986
  MutexLockerEx x(&_m, Mutex::_no_safepoint_check_flag);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   987
  for (size_t i = 0; i < _max_fine_entries; i++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   988
    PosParPRT* cur = _fine_grain_regions[i];
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   989
    while (cur != NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   990
      PosParPRT* nxt = cur->next();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   991
      PosParPRT::free(cur);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   992
      cur = nxt;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   993
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   994
    _fine_grain_regions[i] = NULL;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   995
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   996
  _sparse_table.clear();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   997
  _coarse_map.clear();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   998
  _n_fine_entries = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   999
  _n_coarse_entries = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1000
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1001
  clear_fcc();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1002
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1003
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1004
void OtherRegionsTable::clear_incoming_entry(HeapRegion* from_hr) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1005
  MutexLockerEx x(&_m, Mutex::_no_safepoint_check_flag);
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8072
diff changeset
  1006
  size_t hrs_ind = from_hr->hrs_index();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1007
  size_t ind = hrs_ind & _mod_max_fine_entries_mask;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1008
  if (del_single_region_table(ind, from_hr)) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1009
    assert(!_coarse_map.at(hrs_ind), "Inv");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1010
  } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1011
    _coarse_map.par_at_put(hrs_ind, 0);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1012
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1013
  // Check to see if any of the fcc entries come from here.
9989
305a76435cf1 7045330: G1: Simplify/fix the HeapRegionSeq class
tonyp
parents: 8072
diff changeset
  1014
  size_t hr_ind = hr()->hrs_index();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1015
  for (int tid = 0; tid < HeapRegionRemSet::num_par_rem_sets(); tid++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1016
    int fcc_ent = _from_card_cache[tid][hr_ind];
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1017
    if (fcc_ent != -1) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1018
      HeapWord* card_addr = (HeapWord*)
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1019
        (uintptr_t(fcc_ent) << CardTableModRefBS::card_shift);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1020
      if (hr()->is_in_reserved(card_addr)) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1021
        // Clear the from card cache.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1022
        _from_card_cache[tid][hr_ind] = -1;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1023
      }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1024
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1025
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1026
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1027
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1028
bool OtherRegionsTable::del_single_region_table(size_t ind,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1029
                                                HeapRegion* hr) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1030
  assert(0 <= ind && ind < _max_fine_entries, "Preconditions.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1031
  PosParPRT** prev_addr = &_fine_grain_regions[ind];
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1032
  PosParPRT* prt = *prev_addr;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1033
  while (prt != NULL && prt->hr() != hr) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1034
    prev_addr = prt->next_addr();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1035
    prt = prt->next();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1036
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1037
  if (prt != NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1038
    assert(prt->hr() == hr, "Loop postcondition.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1039
    *prev_addr = prt->next();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1040
    PosParPRT::free(prt);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1041
    _n_fine_entries--;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1042
    return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1043
  } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1044
    return false;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1045
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1046
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1047
3262
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
  1048
bool OtherRegionsTable::contains_reference(OopOrNarrowOopStar from) const {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1049
  // Cast away const in this case.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1050
  MutexLockerEx x((Mutex*)&_m, Mutex::_no_safepoint_check_flag);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1051
  return contains_reference_locked(from);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1052
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1053
3262
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
  1054
bool OtherRegionsTable::contains_reference_locked(OopOrNarrowOopStar from) const {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1055
  HeapRegion* hr = _g1h->heap_region_containing_raw(from);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1056
  if (hr == NULL) return false;
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2882
diff changeset
  1057
  RegionIdx_t hr_ind = (RegionIdx_t) hr->hrs_index();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1058
  // Is this region in the coarse map?
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1059
  if (_coarse_map.at(hr_ind)) return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1060
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1061
  PosParPRT* prt = find_region_table(hr_ind & _mod_max_fine_entries_mask,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1062
                                     hr);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1063
  if (prt != NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1064
    return prt->contains_reference(from);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1065
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1066
  } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1067
    uintptr_t from_card =
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1068
      (uintptr_t(from) >> CardTableModRefBS::card_shift);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1069
    uintptr_t hr_bot_card_index =
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1070
      uintptr_t(hr->bottom()) >> CardTableModRefBS::card_shift;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1071
    assert(from_card >= hr_bot_card_index, "Inv");
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2882
diff changeset
  1072
    CardIdx_t card_index = from_card - hr_bot_card_index;
10677
370a8da2d63f 7095194: G1: HeapRegion::GrainBytes, GrainWords, and CardsPerRegion should be size_t
johnc
parents: 10243
diff changeset
  1073
    assert(0 <= card_index && (size_t)card_index < HeapRegion::CardsPerRegion,
3697
ea9211aa02f5 6819085: G1: use larger and/or user settable region size
tonyp
parents: 3262
diff changeset
  1074
           "Must be in range.");
2996
1097030e5ec3 6843694: G1: assert(index < _vs.committed_size(),"bad index"), g1BlockOffsetTable.inline.hpp:55
johnc
parents: 2882
diff changeset
  1075
    return _sparse_table.contains_card(hr_ind, card_index);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1076
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1077
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1078
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1079
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1080
8072
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
  1081
void
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
  1082
OtherRegionsTable::do_cleanup_work(HRRSCleanupTask* hrrs_cleanup_task) {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
  1083
  _sparse_table.do_cleanup_work(hrrs_cleanup_task);
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
  1084
}
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
  1085
2882
d508a8bac491 6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents: 2881
diff changeset
  1086
// Determines how many threads can add records to an rset in parallel.
d508a8bac491 6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents: 2881
diff changeset
  1087
// This can be done by either mutator threads together with the
d508a8bac491 6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents: 2881
diff changeset
  1088
// concurrent refinement threads or GC threads.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1089
int HeapRegionRemSet::num_par_rem_sets() {
2882
d508a8bac491 6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents: 2881
diff changeset
  1090
  return (int)MAX2(DirtyCardQueueSet::num_par_ids() + ConcurrentG1Refine::thread_num(), ParallelGCThreads);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1091
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1092
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1093
HeapRegionRemSet::HeapRegionRemSet(G1BlockOffsetSharedArray* bosa,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1094
                                   HeapRegion* hr)
10000
5bbb58b0dbb9 7046182: G1: remove unnecessary iterations over the collection set
tonyp
parents: 9989
diff changeset
  1095
  : _bosa(bosa), _other_regions(hr) {
5bbb58b0dbb9 7046182: G1: remove unnecessary iterations over the collection set
tonyp
parents: 9989
diff changeset
  1096
  reset_for_par_iteration();
5bbb58b0dbb9 7046182: G1: remove unnecessary iterations over the collection set
tonyp
parents: 9989
diff changeset
  1097
}
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1098
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
  1099
void HeapRegionRemSet::setup_remset_size() {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
  1100
  // Setup sparse and fine-grain tables sizes.
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
  1101
  // table_size = base * (log(region_size / 1M) + 1)
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
  1102
  int region_size_log_mb = MAX2((int)HeapRegion::LogOfHRGrainBytes - (int)LOG_M, 0);
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
  1103
  if (FLAG_IS_DEFAULT(G1RSetSparseRegionEntries)) {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
  1104
    G1RSetSparseRegionEntries = G1RSetSparseRegionEntriesBase * (region_size_log_mb + 1);
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
  1105
  }
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
  1106
  if (FLAG_IS_DEFAULT(G1RSetRegionEntries)) {
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
  1107
    G1RSetRegionEntries = G1RSetRegionEntriesBase * (region_size_log_mb + 1);
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
  1108
  }
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
  1109
  guarantee(G1RSetSparseRegionEntries > 0 && G1RSetRegionEntries > 0 , "Sanity");
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
  1110
}
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
  1111
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1112
bool HeapRegionRemSet::claim_iter() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1113
  if (_iter_state != Unclaimed) return false;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1114
  jint res = Atomic::cmpxchg(Claimed, (jint*)(&_iter_state), Unclaimed);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1115
  return (res == Unclaimed);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1116
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1117
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1118
void HeapRegionRemSet::set_iter_complete() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1119
  _iter_state = Complete;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1120
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1121
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1122
bool HeapRegionRemSet::iter_is_complete() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1123
  return _iter_state == Complete;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1124
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1125
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1126
void HeapRegionRemSet::init_iterator(HeapRegionRemSetIterator* iter) const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1127
  iter->initialize(this);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1128
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1129
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1130
#ifndef PRODUCT
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1131
void HeapRegionRemSet::print() const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1132
  HeapRegionRemSetIterator iter;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1133
  init_iterator(&iter);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1134
  size_t card_index;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1135
  while (iter.has_next(card_index)) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1136
    HeapWord* card_start =
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1137
      G1CollectedHeap::heap()->bot_shared()->address_for_index(card_index);
10000
5bbb58b0dbb9 7046182: G1: remove unnecessary iterations over the collection set
tonyp
parents: 9989
diff changeset
  1138
    gclog_or_tty->print_cr("  Card " PTR_FORMAT, card_start);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1139
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1140
  // XXX
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1141
  if (iter.n_yielded() != occupied()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1142
    gclog_or_tty->print_cr("Yielded disagrees with occupied:");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1143
    gclog_or_tty->print_cr("  %6d yielded (%6d coarse, %6d fine).",
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1144
                  iter.n_yielded(),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1145
                  iter.n_yielded_coarse(), iter.n_yielded_fine());
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1146
    gclog_or_tty->print_cr("  %6d occ     (%6d coarse, %6d fine).",
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1147
                  occupied(), occ_coarse(), occ_fine());
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1148
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1149
  guarantee(iter.n_yielded() == occupied(),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1150
            "We should have yielded all the represented cards.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1151
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1152
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1153
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1154
void HeapRegionRemSet::cleanup() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1155
  SparsePRT::cleanup_all();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1156
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1157
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1158
void HeapRegionRemSet::par_cleanup() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1159
  PosParPRT::par_contract_all();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1160
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1161
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1162
void HeapRegionRemSet::clear() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1163
  _other_regions.clear();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1164
  assert(occupied() == 0, "Should be clear.");
10000
5bbb58b0dbb9 7046182: G1: remove unnecessary iterations over the collection set
tonyp
parents: 9989
diff changeset
  1165
  reset_for_par_iteration();
5bbb58b0dbb9 7046182: G1: remove unnecessary iterations over the collection set
tonyp
parents: 9989
diff changeset
  1166
}
5bbb58b0dbb9 7046182: G1: remove unnecessary iterations over the collection set
tonyp
parents: 9989
diff changeset
  1167
5bbb58b0dbb9 7046182: G1: remove unnecessary iterations over the collection set
tonyp
parents: 9989
diff changeset
  1168
void HeapRegionRemSet::reset_for_par_iteration() {
5bbb58b0dbb9 7046182: G1: remove unnecessary iterations over the collection set
tonyp
parents: 9989
diff changeset
  1169
  _iter_state = Unclaimed;
5bbb58b0dbb9 7046182: G1: remove unnecessary iterations over the collection set
tonyp
parents: 9989
diff changeset
  1170
  _iter_claimed = 0;
5bbb58b0dbb9 7046182: G1: remove unnecessary iterations over the collection set
tonyp
parents: 9989
diff changeset
  1171
  // It's good to check this to make sure that the two methods are in sync.
5bbb58b0dbb9 7046182: G1: remove unnecessary iterations over the collection set
tonyp
parents: 9989
diff changeset
  1172
  assert(verify_ready_for_par_iteration(), "post-condition");
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1173
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1174
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1175
void HeapRegionRemSet::scrub(CardTableModRefBS* ctbs,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1176
                             BitMap* region_bm, BitMap* card_bm) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1177
  _other_regions.scrub(ctbs, region_bm, card_bm);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1178
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1179
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1180
//-------------------- Iteration --------------------
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1181
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1182
HeapRegionRemSetIterator::
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1183
HeapRegionRemSetIterator() :
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1184
  _hrrs(NULL),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1185
  _g1h(G1CollectedHeap::heap()),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1186
  _bosa(NULL),
6981
ecfe524b1fa7 6992189: G1: inconsistent base used in sparse rem set iterator
tonyp
parents: 5547
diff changeset
  1187
  _sparse_iter() { }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1188
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1189
void HeapRegionRemSetIterator::initialize(const HeapRegionRemSet* hrrs) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1190
  _hrrs = hrrs;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1191
  _coarse_map = &_hrrs->_other_regions._coarse_map;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1192
  _fine_grain_regions = _hrrs->_other_regions._fine_grain_regions;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1193
  _bosa = _hrrs->bosa();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1194
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1195
  _is = Sparse;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1196
  // Set these values so that we increment to the first region.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1197
  _coarse_cur_region_index = -1;
10677
370a8da2d63f 7095194: G1: HeapRegion::GrainBytes, GrainWords, and CardsPerRegion should be size_t
johnc
parents: 10243
diff changeset
  1198
  _coarse_cur_region_cur_card = (HeapRegion::CardsPerRegion-1);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1199
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1200
  _cur_region_cur_card = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1201
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1202
  _fine_array_index = -1;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1203
  _fine_cur_prt = NULL;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1204
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1205
  _n_yielded_coarse = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1206
  _n_yielded_fine = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1207
  _n_yielded_sparse = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1208
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1209
  _sparse_iter.init(&hrrs->_other_regions._sparse_table);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1210
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1211
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1212
bool HeapRegionRemSetIterator::coarse_has_next(size_t& card_index) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1213
  if (_hrrs->_other_regions._n_coarse_entries == 0) return false;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1214
  // Go to the next card.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1215
  _coarse_cur_region_cur_card++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1216
  // 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
  1217
  if (_coarse_cur_region_cur_card == HeapRegion::CardsPerRegion) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1218
    // 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
  1219
    // 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
  1220
    // regions.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1221
    _coarse_cur_region_index =
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1222
      (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
  1223
    if ((size_t)_coarse_cur_region_index < _coarse_map->size()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1224
      _coarse_cur_region_cur_card = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1225
      HeapWord* r_bot =
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1226
        _g1h->region_at(_coarse_cur_region_index)->bottom();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1227
      _cur_region_card_offset = _bosa->index_for(r_bot);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1228
    } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1229
      return false;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1230
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1231
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1232
  // 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
  1233
  card_index = _cur_region_card_offset + _coarse_cur_region_cur_card;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1234
  return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1235
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1236
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1237
void HeapRegionRemSetIterator::fine_find_next_non_null_prt() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1238
  // Otherwise, find the next bucket list in the array.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1239
  _fine_array_index++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1240
  while (_fine_array_index < (int) OtherRegionsTable::_max_fine_entries) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1241
    _fine_cur_prt = _fine_grain_regions[_fine_array_index];
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1242
    if (_fine_cur_prt != NULL) return;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1243
    else _fine_array_index++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1244
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1245
  assert(_fine_cur_prt == NULL, "Loop post");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1246
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1247
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1248
bool HeapRegionRemSetIterator::fine_has_next(size_t& card_index) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1249
  if (fine_has_next()) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1250
    _cur_region_cur_card =
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1251
      _fine_cur_prt->_bm.get_next_one_offset(_cur_region_cur_card + 1);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1252
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1253
  while (!fine_has_next()) {
3697
ea9211aa02f5 6819085: G1: use larger and/or user settable region size
tonyp
parents: 3262
diff changeset
  1254
    if (_cur_region_cur_card == (size_t) HeapRegion::CardsPerRegion) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1255
      _cur_region_cur_card = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1256
      _fine_cur_prt = _fine_cur_prt->next();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1257
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1258
    if (_fine_cur_prt == NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1259
      fine_find_next_non_null_prt();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1260
      if (_fine_cur_prt == NULL) return false;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1261
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1262
    assert(_fine_cur_prt != NULL && _cur_region_cur_card == 0,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1263
           "inv.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1264
    HeapWord* r_bot =
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1265
      _fine_cur_prt->hr()->bottom();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1266
    _cur_region_card_offset = _bosa->index_for(r_bot);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1267
    _cur_region_cur_card = _fine_cur_prt->_bm.get_next_one_offset(0);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1268
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1269
  assert(fine_has_next(), "Or else we exited the loop via the return.");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1270
  card_index = _cur_region_card_offset + _cur_region_cur_card;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1271
  return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1272
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1273
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1274
bool HeapRegionRemSetIterator::fine_has_next() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1275
  return
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1276
    _fine_cur_prt != NULL &&
10677
370a8da2d63f 7095194: G1: HeapRegion::GrainBytes, GrainWords, and CardsPerRegion should be size_t
johnc
parents: 10243
diff changeset
  1277
    _cur_region_cur_card < HeapRegion::CardsPerRegion;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1278
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1279
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1280
bool HeapRegionRemSetIterator::has_next(size_t& card_index) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1281
  switch (_is) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1282
  case Sparse:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1283
    if (_sparse_iter.has_next(card_index)) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1284
      _n_yielded_sparse++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1285
      return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1286
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1287
    // Otherwise, deliberate fall-through
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1288
    _is = Fine;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1289
  case Fine:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1290
    if (fine_has_next(card_index)) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1291
      _n_yielded_fine++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1292
      return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1293
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1294
    // Otherwise, deliberate fall-through
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1295
    _is = Coarse;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1296
  case Coarse:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1297
    if (coarse_has_next(card_index)) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1298
      _n_yielded_coarse++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1299
      return true;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1300
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1301
    // Otherwise...
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1302
    break;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1303
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1304
  assert(ParallelGCThreads > 1 ||
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1305
         n_yielded() == _hrrs->occupied(),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1306
         "Should have yielded all the cards in the rem set "
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1307
         "(in the non-par case).");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1308
  return false;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1309
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1310
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1311
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1312
3262
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
  1313
OopOrNarrowOopStar* HeapRegionRemSet::_recorded_oops = NULL;
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
  1314
HeapWord**          HeapRegionRemSet::_recorded_cards = NULL;
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
  1315
HeapRegion**        HeapRegionRemSet::_recorded_regions = NULL;
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
  1316
int                 HeapRegionRemSet::_n_recorded = 0;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1317
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1318
HeapRegionRemSet::Event* HeapRegionRemSet::_recorded_events = NULL;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1319
int*         HeapRegionRemSet::_recorded_event_index = NULL;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1320
int          HeapRegionRemSet::_n_recorded_events = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1321
3262
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
  1322
void HeapRegionRemSet::record(HeapRegion* hr, OopOrNarrowOopStar f) {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1323
  if (_recorded_oops == NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1324
    assert(_n_recorded == 0
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1325
           && _recorded_cards == NULL
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1326
           && _recorded_regions == NULL,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1327
           "Inv");
3262
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
  1328
    _recorded_oops    = NEW_C_HEAP_ARRAY(OopOrNarrowOopStar, MaxRecorded);
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
  1329
    _recorded_cards   = NEW_C_HEAP_ARRAY(HeapWord*,          MaxRecorded);
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
  1330
    _recorded_regions = NEW_C_HEAP_ARRAY(HeapRegion*,        MaxRecorded);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1331
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1332
  if (_n_recorded == MaxRecorded) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1333
    gclog_or_tty->print_cr("Filled up 'recorded' (%d).", MaxRecorded);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1334
  } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1335
    _recorded_cards[_n_recorded] =
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1336
      (HeapWord*)align_size_down(uintptr_t(f),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1337
                                 CardTableModRefBS::card_size);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1338
    _recorded_oops[_n_recorded] = f;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1339
    _recorded_regions[_n_recorded] = hr;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1340
    _n_recorded++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1341
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1342
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1343
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1344
void HeapRegionRemSet::record_event(Event evnt) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1345
  if (!G1RecordHRRSEvents) return;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1346
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1347
  if (_recorded_events == NULL) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1348
    assert(_n_recorded_events == 0
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1349
           && _recorded_event_index == NULL,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1350
           "Inv");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1351
    _recorded_events = NEW_C_HEAP_ARRAY(Event, MaxRecordedEvents);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1352
    _recorded_event_index = NEW_C_HEAP_ARRAY(int, MaxRecordedEvents);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1353
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1354
  if (_n_recorded_events == MaxRecordedEvents) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1355
    gclog_or_tty->print_cr("Filled up 'recorded_events' (%d).", MaxRecordedEvents);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1356
  } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1357
    _recorded_events[_n_recorded_events] = evnt;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1358
    _recorded_event_index[_n_recorded_events] = _n_recorded;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1359
    _n_recorded_events++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1360
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1361
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1362
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1363
void HeapRegionRemSet::print_event(outputStream* str, Event evnt) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1364
  switch (evnt) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1365
  case Event_EvacStart:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1366
    str->print("Evac Start");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1367
    break;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1368
  case Event_EvacEnd:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1369
    str->print("Evac End");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1370
    break;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1371
  case Event_RSUpdateEnd:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1372
    str->print("RS Update End");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1373
    break;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1374
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1375
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1376
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1377
void HeapRegionRemSet::print_recorded() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1378
  int cur_evnt = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1379
  Event cur_evnt_kind;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1380
  int cur_evnt_ind = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1381
  if (_n_recorded_events > 0) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1382
    cur_evnt_kind = _recorded_events[cur_evnt];
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1383
    cur_evnt_ind = _recorded_event_index[cur_evnt];
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1384
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1385
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1386
  for (int i = 0; i < _n_recorded; i++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1387
    while (cur_evnt < _n_recorded_events && i == cur_evnt_ind) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1388
      gclog_or_tty->print("Event: ");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1389
      print_event(gclog_or_tty, cur_evnt_kind);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1390
      gclog_or_tty->print_cr("");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1391
      cur_evnt++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1392
      if (cur_evnt < MaxRecordedEvents) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1393
        cur_evnt_kind = _recorded_events[cur_evnt];
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1394
        cur_evnt_ind = _recorded_event_index[cur_evnt];
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1395
      }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1396
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1397
    gclog_or_tty->print("Added card " PTR_FORMAT " to region [" PTR_FORMAT "...]"
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1398
                        " for ref " PTR_FORMAT ".\n",
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1399
                        _recorded_cards[i], _recorded_regions[i]->bottom(),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1400
                        _recorded_oops[i]);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1401
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1402
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1403
8072
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
  1404
void HeapRegionRemSet::reset_for_cleanup_tasks() {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
  1405
  SparsePRT::reset_for_cleanup_tasks();
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
  1406
}
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
  1407
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
  1408
void HeapRegionRemSet::do_cleanup_work(HRRSCleanupTask* hrrs_cleanup_task) {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
  1409
  _other_regions.do_cleanup_work(hrrs_cleanup_task);
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
  1410
}
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
  1411
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
  1412
void
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
  1413
HeapRegionRemSet::finish_cleanup_task(HRRSCleanupTask* hrrs_cleanup_task) {
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
  1414
  SparsePRT::finish_cleanup_task(hrrs_cleanup_task);
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
  1415
}
f223f43cd62f 7014261: G1: RSet-related failures
tonyp
parents: 7397
diff changeset
  1416
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1417
#ifndef PRODUCT
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1418
void HeapRegionRemSet::test() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1419
  os::sleep(Thread::current(), (jlong)5000, false);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1420
  G1CollectedHeap* g1h = G1CollectedHeap::heap();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1421
4902
991aaddb5165 6923991: G1: improve scalability of RSet scanning
iveresov
parents: 4900
diff changeset
  1422
  // 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
  1423
  // hash bucket.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1424
  HeapRegion* hr0 = g1h->region_at(0);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1425
  HeapRegion* hr1 = g1h->region_at(1);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1426
  HeapRegion* hr2 = g1h->region_at(5);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1427
  HeapRegion* hr3 = g1h->region_at(6);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1428
  HeapRegion* hr4 = g1h->region_at(7);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1429
  HeapRegion* hr5 = g1h->region_at(8);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1430
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1431
  HeapWord* hr1_start = hr1->bottom();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1432
  HeapWord* hr1_mid = hr1_start + HeapRegion::GrainWords/2;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1433
  HeapWord* hr1_last = hr1->end() - 1;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1434
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1435
  HeapWord* hr2_start = hr2->bottom();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1436
  HeapWord* hr2_mid = hr2_start + HeapRegion::GrainWords/2;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1437
  HeapWord* hr2_last = hr2->end() - 1;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1438
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1439
  HeapWord* hr3_start = hr3->bottom();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1440
  HeapWord* hr3_mid = hr3_start + HeapRegion::GrainWords/2;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1441
  HeapWord* hr3_last = hr3->end() - 1;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1442
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1443
  HeapRegionRemSet* hrrs = hr0->rem_set();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1444
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1445
  // Make three references from region 0x101...
3262
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
  1446
  hrrs->add_reference((OopOrNarrowOopStar)hr1_start);
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
  1447
  hrrs->add_reference((OopOrNarrowOopStar)hr1_mid);
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
  1448
  hrrs->add_reference((OopOrNarrowOopStar)hr1_last);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1449
3262
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
  1450
  hrrs->add_reference((OopOrNarrowOopStar)hr2_start);
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
  1451
  hrrs->add_reference((OopOrNarrowOopStar)hr2_mid);
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
  1452
  hrrs->add_reference((OopOrNarrowOopStar)hr2_last);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1453
3262
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
  1454
  hrrs->add_reference((OopOrNarrowOopStar)hr3_start);
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
  1455
  hrrs->add_reference((OopOrNarrowOopStar)hr3_mid);
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
  1456
  hrrs->add_reference((OopOrNarrowOopStar)hr3_last);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1457
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1458
  // Now cause a coarsening.
3262
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
  1459
  hrrs->add_reference((OopOrNarrowOopStar)hr4->bottom());
30d1c247fc25 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 2996
diff changeset
  1460
  hrrs->add_reference((OopOrNarrowOopStar)hr5->bottom());
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1461
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1462
  // Now, does iteration yield these three?
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1463
  HeapRegionRemSetIterator iter;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1464
  hrrs->init_iterator(&iter);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1465
  size_t sum = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1466
  size_t card_index;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1467
  while (iter.has_next(card_index)) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1468
    HeapWord* card_start =
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1469
      G1CollectedHeap::heap()->bot_shared()->address_for_index(card_index);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1470
    gclog_or_tty->print_cr("  Card " PTR_FORMAT ".", card_start);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1471
    sum++;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1472
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1473
  guarantee(sum == 11 - 3 + 2048, "Failure");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1474
  guarantee(sum == hrrs->occupied(), "Failure");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1475
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
  1476
#endif