src/hotspot/share/gc/g1/collectionSetChooser.hpp
author tschatzl
Thu, 14 Jun 2018 13:07:33 +0200
changeset 50565 69e82329ad01
parent 49607 acffe6ff3ae7
child 53244 9807daeb47c4
permissions -rw-r--r--
8204169: Humongous continues region remembered set states do not match the one from the corresponding humongous start region Summary: Make sure and verify that the remembered set state of humongous continues regions matches the one from the corresponding humongous start region. Reviewed-by: kbarrett, sjohanss
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
/*
49605
784f3f2dea14 8197570: Make rules for choosing collection set candidates more explicit
tschatzl
parents: 47216
diff changeset
     2
 * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     4
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     8
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    13
 * accompanied this code).
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    14
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 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
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 26846
diff changeset
    25
#ifndef SHARE_VM_GC_G1_COLLECTIONSETCHOOSER_HPP
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 26846
diff changeset
    26
#define SHARE_VM_GC_G1_COLLECTIONSETCHOOSER_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 26846
diff changeset
    28
#include "gc/g1/heapRegion.hpp"
7397
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
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12382
diff changeset
    31
class CollectionSetChooser: public CHeapObj<mtGC> {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    32
12382
6aaecb1cbfe1 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 12381
diff changeset
    33
  GrowableArray<HeapRegion*> _regions;
6aaecb1cbfe1 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 12381
diff changeset
    34
6aaecb1cbfe1 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 12381
diff changeset
    35
  // Unfortunately, GrowableArray uses ints for length and indexes. To
6aaecb1cbfe1 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 12381
diff changeset
    36
  // avoid excessive casting in the rest of the class the following
6aaecb1cbfe1 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 12381
diff changeset
    37
  // wrapper methods are provided that use uints.
6aaecb1cbfe1 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 12381
diff changeset
    38
6aaecb1cbfe1 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 12381
diff changeset
    39
  uint regions_length()          { return (uint) _regions.length(); }
6aaecb1cbfe1 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 12381
diff changeset
    40
  HeapRegion* regions_at(uint i) { return _regions.at((int) i);     }
6aaecb1cbfe1 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 12381
diff changeset
    41
  void regions_at_put(uint i, HeapRegion* hr) {
6aaecb1cbfe1 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 12381
diff changeset
    42
    _regions.at_put((int) i, hr);
6aaecb1cbfe1 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 12381
diff changeset
    43
  }
6aaecb1cbfe1 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 12381
diff changeset
    44
  void regions_at_put_grow(uint i, HeapRegion* hr) {
6aaecb1cbfe1 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 12381
diff changeset
    45
    _regions.at_put_grow((int) i, hr);
6aaecb1cbfe1 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 12381
diff changeset
    46
  }
6aaecb1cbfe1 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 12381
diff changeset
    47
  void regions_trunc_to(uint i)  { _regions.trunc_to((uint) i); }
11756
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
    48
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
    49
  // 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
    50
  // addition to the CSet.
32745
d238cd8170fc 8135253: Add push method to CollectionSetChooser
ehelin
parents: 31592
diff changeset
    51
  uint _front;
11756
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
    52
32745
d238cd8170fc 8135253: Add push method to CollectionSetChooser
ehelin
parents: 31592
diff changeset
    53
  // The index of the last candidate old region
d238cd8170fc 8135253: Add push method to CollectionSetChooser
ehelin
parents: 31592
diff changeset
    54
  uint _end;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    55
12382
6aaecb1cbfe1 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 12381
diff changeset
    56
  // Keeps track of the start of the next array chunk to be claimed by
6aaecb1cbfe1 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 12381
diff changeset
    57
  // parallel GC workers.
6aaecb1cbfe1 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 12381
diff changeset
    58
  uint _first_par_unreserved_idx;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    59
11756
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
    60
  // 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
    61
  // 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
    62
  // collection.
12382
6aaecb1cbfe1 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 12381
diff changeset
    63
  size_t _region_live_threshold_bytes;
11756
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
    64
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
    65
  // The sum of reclaimable bytes over all the regions in the CSet chooser.
12382
6aaecb1cbfe1 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 12381
diff changeset
    66
  size_t _remaining_reclaimable_bytes;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    67
37143
345ad6728be3 8151637: Move CollectionSetChooser rebuild code into CollectionSetChooser
mgerdin
parents: 33105
diff changeset
    68
  // Calculate and return chunk size (in number of regions) for parallel
345ad6728be3 8151637: Move CollectionSetChooser rebuild code into CollectionSetChooser
mgerdin
parents: 33105
diff changeset
    69
  // addition of regions
345ad6728be3 8151637: Move CollectionSetChooser rebuild code into CollectionSetChooser
mgerdin
parents: 33105
diff changeset
    70
  uint calculate_parallel_work_chunk_size(uint n_workers, uint n_regions) const;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    71
public:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    72
11756
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
    73
  // 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
    74
  // 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
    75
  HeapRegion* peek() {
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
    76
    HeapRegion* res = NULL;
32745
d238cd8170fc 8135253: Add push method to CollectionSetChooser
ehelin
parents: 31592
diff changeset
    77
    if (_front < _end) {
d238cd8170fc 8135253: Add push method to CollectionSetChooser
ehelin
parents: 31592
diff changeset
    78
      res = regions_at(_front);
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32745
diff changeset
    79
      assert(res != NULL, "Unexpected NULL hr in _regions at index %u", _front);
11756
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
    80
    }
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
    81
    return res;
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
    82
  }
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
    83
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
    84
  // Remove the given region from the CSet chooser and move to the
32745
d238cd8170fc 8135253: Add push method to CollectionSetChooser
ehelin
parents: 31592
diff changeset
    85
  // next one.
d238cd8170fc 8135253: Add push method to CollectionSetChooser
ehelin
parents: 31592
diff changeset
    86
  HeapRegion* pop() {
d238cd8170fc 8135253: Add push method to CollectionSetChooser
ehelin
parents: 31592
diff changeset
    87
    HeapRegion* hr = regions_at(_front);
11756
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
    88
    assert(hr != NULL, "pre-condition");
32745
d238cd8170fc 8135253: Add push method to CollectionSetChooser
ehelin
parents: 31592
diff changeset
    89
    assert(_front < _end, "pre-condition");
d238cd8170fc 8135253: Add push method to CollectionSetChooser
ehelin
parents: 31592
diff changeset
    90
    regions_at_put(_front, NULL);
12382
6aaecb1cbfe1 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 12381
diff changeset
    91
    assert(hr->reclaimable_bytes() <= _remaining_reclaimable_bytes,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32745
diff changeset
    92
           "remaining reclaimable bytes inconsistent "
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32745
diff changeset
    93
           "from region: " SIZE_FORMAT " remaining: " SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32745
diff changeset
    94
           hr->reclaimable_bytes(), _remaining_reclaimable_bytes);
12382
6aaecb1cbfe1 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 12381
diff changeset
    95
    _remaining_reclaimable_bytes -= hr->reclaimable_bytes();
32745
d238cd8170fc 8135253: Add push method to CollectionSetChooser
ehelin
parents: 31592
diff changeset
    96
    _front += 1;
d238cd8170fc 8135253: Add push method to CollectionSetChooser
ehelin
parents: 31592
diff changeset
    97
    return hr;
11756
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
    98
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    99
32745
d238cd8170fc 8135253: Add push method to CollectionSetChooser
ehelin
parents: 31592
diff changeset
   100
  void push(HeapRegion* hr);
d238cd8170fc 8135253: Add push method to CollectionSetChooser
ehelin
parents: 31592
diff changeset
   101
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   102
  CollectionSetChooser();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   103
49605
784f3f2dea14 8197570: Make rules for choosing collection set candidates more explicit
tschatzl
parents: 47216
diff changeset
   104
  static size_t mixed_gc_live_threshold_bytes() {
784f3f2dea14 8197570: Make rules for choosing collection set candidates more explicit
tschatzl
parents: 47216
diff changeset
   105
    return HeapRegion::GrainBytes * (size_t) G1MixedGCLiveThresholdPercent / 100;
784f3f2dea14 8197570: Make rules for choosing collection set candidates more explicit
tschatzl
parents: 47216
diff changeset
   106
  }
784f3f2dea14 8197570: Make rules for choosing collection set candidates more explicit
tschatzl
parents: 47216
diff changeset
   107
784f3f2dea14 8197570: Make rules for choosing collection set candidates more explicit
tschatzl
parents: 47216
diff changeset
   108
  static bool region_occupancy_low_enough_for_evac(size_t live_bytes);
784f3f2dea14 8197570: Make rules for choosing collection set candidates more explicit
tschatzl
parents: 47216
diff changeset
   109
12382
6aaecb1cbfe1 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 12381
diff changeset
   110
  void sort_regions();
11756
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   111
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   112
  // Determine whether to add the given region to the CSet chooser or
31346
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30874
diff changeset
   113
  // not. Currently, we skip pinned regions and regions whose live
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30874
diff changeset
   114
  // bytes are over the threshold. Humongous regions may be reclaimed during cleanup.
49607
acffe6ff3ae7 8180415: Rebuild remembered sets during the concurrent cycle
tschatzl
parents: 49605
diff changeset
   115
  // Regions also need a complete remembered set to be a candidate.
49605
784f3f2dea14 8197570: Make rules for choosing collection set candidates more explicit
tschatzl
parents: 47216
diff changeset
   116
  bool should_add(HeapRegion* hr) const;
11756
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   117
15861
974c3ccaa5d2 8007036: G1: Too many old regions added to last mixed GC
johnc
parents: 13336
diff changeset
   118
  // Returns the number candidate old regions added
32745
d238cd8170fc 8135253: Add push method to CollectionSetChooser
ehelin
parents: 31592
diff changeset
   119
  uint length() { return _end; }
11756
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   120
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   121
  // Serial version.
12382
6aaecb1cbfe1 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 12381
diff changeset
   122
  void add_region(HeapRegion *hr);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   123
12382
6aaecb1cbfe1 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 12381
diff changeset
   124
  // Must be called before calls to claim_array_chunk().
6aaecb1cbfe1 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 12381
diff changeset
   125
  // n_regions is the number of regions, chunk_size the chunk size.
30874
18714bae50db 8080837: Move number of workers calculation out of CollectionSetChooser::prepare_for_par_region_addition
stefank
parents: 30764
diff changeset
   126
  void prepare_for_par_region_addition(uint n_threads, uint n_regions, uint chunk_size);
12382
6aaecb1cbfe1 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 12381
diff changeset
   127
  // Returns the first index in a contiguous chunk of chunk_size indexes
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   128
  // that the calling thread has reserved.  These must be set by the
12382
6aaecb1cbfe1 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 12381
diff changeset
   129
  // calling thread using set_region() (to NULL if necessary).
6aaecb1cbfe1 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 12381
diff changeset
   130
  uint claim_array_chunk(uint chunk_size);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   131
  // 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
   132
  // first if in parallel.
12382
6aaecb1cbfe1 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 12381
diff changeset
   133
  void set_region(uint index, HeapRegion* hr);
11756
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   134
  // 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
   135
  // and the amount of reclaimable bytes by reclaimable_bytes.
12382
6aaecb1cbfe1 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 12381
diff changeset
   136
  void update_totals(uint region_num, size_t reclaimable_bytes);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   137
49605
784f3f2dea14 8197570: Make rules for choosing collection set candidates more explicit
tschatzl
parents: 47216
diff changeset
   138
  // Iterate over all collection set candidate regions.
784f3f2dea14 8197570: Make rules for choosing collection set candidates more explicit
tschatzl
parents: 47216
diff changeset
   139
  void iterate(HeapRegionClosure* cl);
784f3f2dea14 8197570: Make rules for choosing collection set candidates more explicit
tschatzl
parents: 47216
diff changeset
   140
12382
6aaecb1cbfe1 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 12381
diff changeset
   141
  void clear();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   142
37143
345ad6728be3 8151637: Move CollectionSetChooser rebuild code into CollectionSetChooser
mgerdin
parents: 33105
diff changeset
   143
  void rebuild(WorkGang* workers, uint n_regions);
345ad6728be3 8151637: Move CollectionSetChooser rebuild code into CollectionSetChooser
mgerdin
parents: 33105
diff changeset
   144
11756
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   145
  // Return the number of candidate regions that remain to be collected.
32745
d238cd8170fc 8135253: Add push method to CollectionSetChooser
ehelin
parents: 31592
diff changeset
   146
  uint remaining_regions() { return _end - _front; }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   147
11756
28b6fe22e43d 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 10680
diff changeset
   148
  // Determine whether the CSet chooser has more candidate regions or not.
12382
6aaecb1cbfe1 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 12381
diff changeset
   149
  bool is_empty() { return remaining_regions() == 0; }
11756
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
  // 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
   152
  // all the candidate regions in the CSet chooser.
12382
6aaecb1cbfe1 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 12381
diff changeset
   153
  size_t remaining_reclaimable_bytes() { return _remaining_reclaimable_bytes; }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   154
12382
6aaecb1cbfe1 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 12381
diff changeset
   155
  // Returns true if the used portion of "_regions" is properly
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   156
  // sorted, otherwise asserts false.
12382
6aaecb1cbfe1 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 12381
diff changeset
   157
  void verify() PRODUCT_RETURN;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   158
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   159
13336
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   160
class CSetChooserParUpdater : public StackObj {
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   161
private:
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   162
  CollectionSetChooser* _chooser;
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   163
  bool _parallel;
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   164
  uint _chunk_size;
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   165
  uint _cur_chunk_idx;
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   166
  uint _cur_chunk_end;
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   167
  uint _regions_added;
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   168
  size_t _reclaimable_bytes_added;
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   169
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   170
public:
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   171
  CSetChooserParUpdater(CollectionSetChooser* chooser,
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   172
                        bool parallel, uint chunk_size) :
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   173
    _chooser(chooser), _parallel(parallel), _chunk_size(chunk_size),
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   174
    _cur_chunk_idx(0), _cur_chunk_end(0),
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   175
    _regions_added(0), _reclaimable_bytes_added(0) { }
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   176
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   177
  ~CSetChooserParUpdater() {
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   178
    if (_parallel && _regions_added > 0) {
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   179
      _chooser->update_totals(_regions_added, _reclaimable_bytes_added);
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   180
    }
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   181
  }
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   182
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   183
  void add_region(HeapRegion* hr) {
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   184
    if (_parallel) {
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   185
      if (_cur_chunk_idx == _cur_chunk_end) {
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   186
        _cur_chunk_idx = _chooser->claim_array_chunk(_chunk_size);
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   187
        _cur_chunk_end = _cur_chunk_idx + _chunk_size;
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   188
      }
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   189
      assert(_cur_chunk_idx < _cur_chunk_end, "invariant");
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   190
      _chooser->set_region(_cur_chunk_idx, hr);
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   191
      _cur_chunk_idx += 1;
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   192
    } else {
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   193
      _chooser->add_region(hr);
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   194
    }
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   195
    _regions_added += 1;
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   196
    _reclaimable_bytes_added += hr->reclaimable_bytes();
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   197
  }
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   198
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   199
  bool should_add(HeapRegion* hr) { return _chooser->should_add(hr); }
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   200
};
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   201
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 26846
diff changeset
   202
#endif // SHARE_VM_GC_G1_COLLECTIONSETCHOOSER_HPP
13336
e582172ff6ff 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 13195
diff changeset
   203