hotspot/src/share/vm/gc_implementation/g1/collectionSetChooser.hpp
author tonyp
Wed, 15 Feb 2012 13:06:53 -0500
changeset 11756 28b6fe22e43d
parent 10680 f7bdba11999b
child 12381 1438e0fbfa27
permissions -rw-r--r--
7132029: G1: mixed GC phase lasts for longer than it should Summary: Revamp of the mechanism that chooses old regions for inclusion in the CSet. It simplifies the code and introduces min and max bounds on the number of old regions added to the CSet at each mixed GC to avoid pathological cases. It also ensures that when we do a mixed GC we'll always find old regions to add to the CSet (i.e., it eliminates the case where a mixed GC will collect no old regions which can happen today). Reviewed-by: johnc, brutisso
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     1
/*
11756
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
     2
 * Copyright (c) 2001, 2012, 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: 2105
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2105
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: 2105
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: 5547
diff changeset
    25
#ifndef SHARE_VM_GC_IMPLEMENTATION_G1_COLLECTIONSETCHOOSER_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#define SHARE_VM_GC_IMPLEMENTATION_G1_COLLECTIONSETCHOOSER_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "gc_implementation/g1/heapRegion.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "utilities/growableArray.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
2013
49e915da0905 6700941: G1: allocation spec missing for some G1 classes
apetrusenko
parents: 1374
diff changeset
    31
class CSetChooserCache VALUE_OBJ_CLASS_SPEC {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    32
private:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    33
  enum {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    34
    CacheLength = 16
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    35
  } PrivateConstants;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    36
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    37
  HeapRegion*  _cache[CacheLength];
10680
f7bdba11999b 7095236: G1: _markedRegions never contains NULL regions
ysr
parents: 8930
diff changeset
    38
  int          _occupancy; // number of regions in cache
f7bdba11999b 7095236: G1: _markedRegions never contains NULL regions
ysr
parents: 8930
diff changeset
    39
  int          _first;     // (index of) "first" region in the cache
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    40
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    41
  // adding CacheLength to deal with negative values
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    42
  inline int trim_index(int index) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    43
    return (index + CacheLength) % CacheLength;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    44
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    45
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    46
  inline int get_sort_index(int index) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    47
    return -index-2;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    48
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    49
  inline int get_index(int sort_index) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    50
    return -sort_index-2;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    51
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    52
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    53
public:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    54
  CSetChooserCache(void);
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
  inline int occupancy(void) { return _occupancy; }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    57
  inline bool is_full()      { return _occupancy == CacheLength; }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    58
  inline bool is_empty()     { return _occupancy == 0; }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    59
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    60
  void clear(void);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    61
  void insert(HeapRegion *hr);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    62
  HeapRegion *remove_first(void);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    63
  inline HeapRegion *get_first(void) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    64
    return _cache[_first];
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
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    67
#ifndef PRODUCT
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    68
  bool verify (void);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    69
  bool region_in_cache(HeapRegion *hr) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    70
    int sort_index = hr->sort_index();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    71
    if (sort_index < -1) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    72
      int index = get_index(sort_index);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    73
      guarantee(index < CacheLength, "should be within bounds");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    74
      return _cache[index] == hr;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    75
    } else
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    76
      return 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    77
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    78
#endif // PRODUCT
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    79
};
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    80
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    81
class CollectionSetChooser: public CHeapObj {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    82
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    83
  GrowableArray<HeapRegion*> _markedRegions;
11756
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
    84
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
    85
  // The index of the next candidate old region to be considered for
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
    86
  // addition to the CSet.
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
    87
  int _curr_index;
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
    88
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
    89
  // The number of candidate old regions added to the CSet chooser.
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
    90
  int _length;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    91
11756
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
    92
  CSetChooserCache _cache;
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
    93
  jint _first_par_unreserved_idx;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    94
11756
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
    95
  // If a region has more live bytes than this threshold, it will not
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
    96
  // be added to the CSet chooser and will not be a candidate for
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
    97
  // collection.
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
    98
  size_t _regionLiveThresholdBytes;
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
    99
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   100
  // The sum of reclaimable bytes over all the regions in the CSet chooser.
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   101
  size_t _remainingReclaimableBytes;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   102
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   103
public:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   104
11756
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   105
  // Return the current candidate region to be considered for
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   106
  // collection without removing it from the CSet chooser.
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   107
  HeapRegion* peek() {
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   108
    HeapRegion* res = NULL;
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   109
    if (_curr_index < _length) {
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   110
      res = _markedRegions.at(_curr_index);
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   111
      assert(res != NULL,
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   112
             err_msg("Unexpected NULL hr in _markedRegions at index %d",
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   113
                     _curr_index));
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   114
    }
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   115
    return res;
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   116
  }
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   117
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   118
  // Remove the given region from the CSet chooser and move to the
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   119
  // next one. The given region should be the current candidate region
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   120
  // in the CSet chooser.
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   121
  void remove_and_move_to_next(HeapRegion* hr) {
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   122
    assert(hr != NULL, "pre-condition");
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   123
    assert(_curr_index < _length, "pre-condition");
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   124
    assert(_markedRegions.at(_curr_index) == hr, "pre-condition");
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   125
    hr->set_sort_index(-1);
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   126
    _markedRegions.at_put(_curr_index, NULL);
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   127
    assert(hr->reclaimable_bytes() <= _remainingReclaimableBytes,
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   128
           err_msg("remaining reclaimable bytes inconsistent "
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   129
                   "from region: "SIZE_FORMAT" remaining: "SIZE_FORMAT,
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   130
                   hr->reclaimable_bytes(), _remainingReclaimableBytes));
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   131
    _remainingReclaimableBytes -= hr->reclaimable_bytes();
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   132
    _curr_index += 1;
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   133
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   134
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   135
  CollectionSetChooser();
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
  void sortMarkedHeapRegions();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   138
  void fillCache();
11756
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   139
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   140
  // Determine whether to add the given region to the CSet chooser or
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   141
  // not. Currently, we skip humongous regions (we never add them to
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   142
  // the CSet, we only reclaim them during cleanup) and regions whose
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   143
  // live bytes are over the threshold.
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   144
  bool shouldAdd(HeapRegion* hr) {
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   145
    assert(hr->is_marked(), "pre-condition");
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   146
    assert(!hr->is_young(), "should never consider young regions");
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   147
    return !hr->isHumongous() &&
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   148
            hr->live_bytes() < _regionLiveThresholdBytes;
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   149
  }
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   150
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   151
  // Calculate the minimum number of old regions we'll add to the CSet
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   152
  // during a mixed GC.
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   153
  size_t calcMinOldCSetLength();
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   154
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   155
  // Calculate the maximum number of old regions we'll add to the CSet
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   156
  // during a mixed GC.
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   157
  size_t calcMaxOldCSetLength();
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   158
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   159
  // Serial version.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   160
  void addMarkedHeapRegion(HeapRegion *hr);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   161
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   162
  // Must be called before calls to getParMarkedHeapRegionChunk.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   163
  // "n_regions" is the number of regions, "chunkSize" the chunk size.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   164
  void prepareForAddMarkedHeapRegionsPar(size_t n_regions, size_t chunkSize);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   165
  // Returns the first index in a contiguous chunk of "n_regions" indexes
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   166
  // that the calling thread has reserved.  These must be set by the
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   167
  // calling thread using "setMarkedHeapRegion" (to NULL if necessary).
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   168
  jint getParMarkedHeapRegionChunk(jint n_regions);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   169
  // Set the marked array entry at index to hr.  Careful to claim the index
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   170
  // first if in parallel.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   171
  void setMarkedHeapRegion(jint index, HeapRegion* hr);
11756
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   172
  // Atomically increment the number of added regions by region_num
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   173
  // and the amount of reclaimable bytes by reclaimable_bytes.
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   174
  void updateTotals(jint region_num, size_t reclaimable_bytes);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   175
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   176
  void clearMarkedHeapRegions();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   177
11756
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   178
  // Return the number of candidate regions that remain to be collected.
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   179
  size_t remainingRegions() { return _length - _curr_index; }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   180
11756
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   181
  // Determine whether the CSet chooser has more candidate regions or not.
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   182
  bool isEmpty() { return remainingRegions() == 0; }
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   183
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   184
  // Return the reclaimable bytes that remain to be collected on
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   185
  // all the candidate regions in the CSet chooser.
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   186
  size_t remainingReclaimableBytes () { return _remainingReclaimableBytes; }
1374
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
  // Returns true if the used portion of "_markedRegions" is properly
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   189
  // sorted, otherwise asserts false.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   190
#ifndef PRODUCT
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   191
  bool verify(void);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   192
  bool regionProperlyOrdered(HeapRegion* r) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   193
    int si = r->sort_index();
11756
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   194
    if (si > -1) {
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   195
      guarantee(_curr_index <= si && si < _length,
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   196
                err_msg("curr: %d sort index: %d: length: %d",
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   197
                        _curr_index, si, _length));
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   198
      guarantee(_markedRegions.at(si) == r,
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   199
                err_msg("sort index: %d at: "PTR_FORMAT" r: "PTR_FORMAT,
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   200
                        si, _markedRegions.at(si), r));
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   201
    } else {
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   202
      guarantee(si == -1, err_msg("sort index: %d", si));
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   203
    }
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   204
    return true;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   205
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   206
#endif
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   207
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   208
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   209
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   210
#endif // SHARE_VM_GC_IMPLEMENTATION_G1_COLLECTIONSETCHOOSER_HPP