src/hotspot/share/gc/g1/g1CollectionSetCandidates.hpp
author tschatzl
Fri, 29 Nov 2019 10:20:17 +0100
changeset 59321 5775e4825e58
parent 54465 c4f16445675a
permissions -rw-r--r--
8233998: New young regions registered too early in collection set Reviewed-by: sangheki, sjohanss
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
53703
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
     1
/*
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
     4
 *
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
     7
 * published by the Free Software Foundation.
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
     8
 *
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    13
 * accompanied this code).
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    14
 *
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    18
 *
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    21
 * questions.
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    22
 *
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    23
 */
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    24
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    25
#ifndef SHARE_GC_G1_G1COLLECTIONSETCANDIDATES_HPP
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    26
#define SHARE_GC_G1_G1COLLECTIONSETCANDIDATES_HPP
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    27
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    28
#include "gc/g1/g1CollectionSetCandidates.hpp"
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    29
#include "gc/shared/workgroup.hpp"
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    30
#include "memory/allocation.hpp"
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    31
#include "runtime/globals.hpp"
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    32
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    33
class HeapRegion;
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    34
class HeapRegionClosure;
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    35
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    36
// Set of collection set candidates, i.e. all old gen regions we consider worth
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    37
// collecting in the remainder of the current mixed phase. Regions are sorted by decreasing
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    38
// gc efficiency.
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    39
// Maintains a cursor into the list that specifies the next collection set candidate
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    40
// to put into the current collection set.
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    41
class G1CollectionSetCandidates : public CHeapObj<mtGC> {
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    42
  HeapRegion** _regions;
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    43
  uint _num_regions; // Total number of regions in the collection set candidate set.
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    44
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    45
  // The sum of bytes that can be reclaimed in the remaining set of collection
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    46
  // set candidates.
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    47
  size_t _remaining_reclaimable_bytes;
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    48
  // The index of the next candidate old region to be considered for
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    49
  // addition to the current collection set.
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    50
  uint _front_idx;
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    51
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    52
public:
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    53
  G1CollectionSetCandidates(HeapRegion** regions, uint num_regions, size_t remaining_reclaimable_bytes) :
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    54
    _regions(regions),
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    55
    _num_regions(num_regions),
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    56
    _remaining_reclaimable_bytes(remaining_reclaimable_bytes),
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    57
    _front_idx(0) { }
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    58
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    59
  ~G1CollectionSetCandidates() {
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    60
    FREE_C_HEAP_ARRAY(HeapRegion*, _regions);
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    61
  }
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    62
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    63
  // Returns the total number of collection set candidate old regions added.
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    64
  uint num_regions() { return _num_regions; }
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    65
54465
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 53703
diff changeset
    66
  uint cur_idx() const { return _front_idx; }
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 53703
diff changeset
    67
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 53703
diff changeset
    68
  HeapRegion* at(uint idx) const {
53703
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    69
    HeapRegion* res = NULL;
54465
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 53703
diff changeset
    70
    if (idx < _num_regions) {
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 53703
diff changeset
    71
      res = _regions[idx];
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 53703
diff changeset
    72
      assert(res != NULL, "Unexpected NULL HeapRegion at index %u", idx);
53703
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    73
    }
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    74
    return res;
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    75
  }
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    76
54465
c4f16445675a 8218668: Clean up evacuation of optional collection set
tschatzl
parents: 53703
diff changeset
    77
  void remove(uint num_regions);
53703
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    78
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    79
  // Iterate over all remaining collection set candidate regions.
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    80
  void iterate(HeapRegionClosure* cl);
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    81
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    82
  // Return the number of candidate regions remaining.
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    83
  uint num_remaining() { return _num_regions - _front_idx; }
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    84
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    85
  bool is_empty() { return num_remaining() == 0; }
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    86
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    87
  // Return the amount of reclaimable bytes that may be collected by the remaining
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    88
  // candidate regions.
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    89
  size_t remaining_reclaimable_bytes() { return _remaining_reclaimable_bytes; }
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    90
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    91
  void verify() const PRODUCT_RETURN;
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    92
};
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    93
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    94
#endif /* SHARE_GC_G1_G1COLLECTIONSETCANDIDATES_HPP */
24341625d8f2 8217330: Split G1CollectionSetChooser into collection set candidate container and the chooser algorithm
tschatzl
parents:
diff changeset
    95