annotate src/share/vm/gc_implementation/g1/collectionSetChooser.hpp @ 8733:9def4075da6d

8008079: G1: Add nextObject routine to CMBitMapRO and replace nextWord Summary: Update the task local finger to the start of the next object when marking aborts, in order to avoid the redundant scanning of all 0's when the marking task restarts, if otherwise updating to the next word. In addition, reuse the routine nextObject() in routine iterate(). Reviewed-by: johnc, ysr Contributed-by: tamao <tao.mao@oracle.com>
author tamao
date Tue, 05 Mar 2013 15:36:56 -0800
parents 27714220e50e
children de6a9e811145
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
1 /*
4912
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
2 * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
4 *
37f87013dfd8 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
37f87013dfd8 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
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
7 * published by the Free Software Foundation.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
8 *
37f87013dfd8 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
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
37f87013dfd8 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
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
13 * accompanied this code).
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
14 *
37f87013dfd8 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
37f87013dfd8 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,
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 579
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 579
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 579
diff changeset
21 * questions.
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
22 *
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
23 */
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_COLLECTIONSETCHOOSER_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #define SHARE_VM_GC_IMPLEMENTATION_G1_COLLECTIONSETCHOOSER_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "gc_implementation/g1/heapRegion.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "utilities/growableArray.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 6011
diff changeset
31 class CollectionSetChooser: public CHeapObj<mtGC> {
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
32
6011
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
33 GrowableArray<HeapRegion*> _regions;
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
34
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
35 // Unfortunately, GrowableArray uses ints for length and indexes. To
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
36 // avoid excessive casting in the rest of the class the following
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
37 // wrapper methods are provided that use uints.
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
38
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
39 uint regions_length() { return (uint) _regions.length(); }
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
40 HeapRegion* regions_at(uint i) { return _regions.at((int) i); }
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
41 void regions_at_put(uint i, HeapRegion* hr) {
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
42 _regions.at_put((int) i, hr);
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
43 }
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
44 void regions_at_put_grow(uint i, HeapRegion* hr) {
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
45 _regions.at_put_grow((int) i, hr);
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
46 }
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
47 void regions_trunc_to(uint i) { _regions.trunc_to((uint) i); }
4912
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
48
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
49 // The index of the next candidate old region to be considered for
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
50 // addition to the CSet.
6011
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
51 uint _curr_index;
4912
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
52
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
53 // The number of candidate old regions added to the CSet chooser.
8681
27714220e50e 8007036: G1: Too many old regions added to last mixed GC
johnc
parents: 6254
diff changeset
54 // Note: this is not updated when removing a region using
27714220e50e 8007036: G1: Too many old regions added to last mixed GC
johnc
parents: 6254
diff changeset
55 // remove_and_move_to_next() below.
6011
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
56 uint _length;
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
57
6011
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
58 // Keeps track of the start of the next array chunk to be claimed by
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
59 // parallel GC workers.
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
60 uint _first_par_unreserved_idx;
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
61
4912
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
62 // If a region has more live bytes than this threshold, it will not
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
63 // be added to the CSet chooser and will not be a candidate for
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
64 // collection.
6011
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
65 size_t _region_live_threshold_bytes;
4912
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
66
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
67 // The sum of reclaimable bytes over all the regions in the CSet chooser.
6011
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
68 size_t _remaining_reclaimable_bytes;
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
69
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
70 public:
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
71
4912
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
72 // Return the current candidate region to be considered for
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
73 // collection without removing it from the CSet chooser.
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
74 HeapRegion* peek() {
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
75 HeapRegion* res = NULL;
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
76 if (_curr_index < _length) {
6011
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
77 res = regions_at(_curr_index);
4912
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
78 assert(res != NULL,
6011
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
79 err_msg("Unexpected NULL hr in _regions at index %u",
4912
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
80 _curr_index));
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
81 }
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
82 return res;
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
83 }
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
84
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
85 // Remove the given region from the CSet chooser and move to the
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
86 // next one. The given region should be the current candidate region
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
87 // in the CSet chooser.
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
88 void remove_and_move_to_next(HeapRegion* hr) {
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
89 assert(hr != NULL, "pre-condition");
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
90 assert(_curr_index < _length, "pre-condition");
6011
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
91 assert(regions_at(_curr_index) == hr, "pre-condition");
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
92 regions_at_put(_curr_index, NULL);
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
93 assert(hr->reclaimable_bytes() <= _remaining_reclaimable_bytes,
4912
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
94 err_msg("remaining reclaimable bytes inconsistent "
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
95 "from region: "SIZE_FORMAT" remaining: "SIZE_FORMAT,
6011
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
96 hr->reclaimable_bytes(), _remaining_reclaimable_bytes));
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
97 _remaining_reclaimable_bytes -= hr->reclaimable_bytes();
4912
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
98 _curr_index += 1;
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
99 }
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
100
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
101 CollectionSetChooser();
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
102
6011
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
103 void sort_regions();
4912
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
104
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
105 // Determine whether to add the given region to the CSet chooser or
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
106 // not. Currently, we skip humongous regions (we never add them to
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
107 // the CSet, we only reclaim them during cleanup) and regions whose
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
108 // live bytes are over the threshold.
6011
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
109 bool should_add(HeapRegion* hr) {
4912
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
110 assert(hr->is_marked(), "pre-condition");
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
111 assert(!hr->is_young(), "should never consider young regions");
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
112 return !hr->isHumongous() &&
6011
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
113 hr->live_bytes() < _region_live_threshold_bytes;
4912
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
114 }
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
115
8681
27714220e50e 8007036: G1: Too many old regions added to last mixed GC
johnc
parents: 6254
diff changeset
116 // Returns the number candidate old regions added
27714220e50e 8007036: G1: Too many old regions added to last mixed GC
johnc
parents: 6254
diff changeset
117 uint length() { return _length; }
4912
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
118
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
119 // Serial version.
6011
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
120 void add_region(HeapRegion *hr);
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
121
6011
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
122 // Must be called before calls to claim_array_chunk().
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
123 // n_regions is the number of regions, chunk_size the chunk size.
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
124 void prepare_for_par_region_addition(uint n_regions, uint chunk_size);
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
125 // Returns the first index in a contiguous chunk of chunk_size indexes
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
126 // that the calling thread has reserved. These must be set by the
6011
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
127 // calling thread using set_region() (to NULL if necessary).
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
128 uint claim_array_chunk(uint chunk_size);
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
129 // Set the marked array entry at index to hr. Careful to claim the index
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
130 // first if in parallel.
6011
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
131 void set_region(uint index, HeapRegion* hr);
4912
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
132 // Atomically increment the number of added regions by region_num
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
133 // and the amount of reclaimable bytes by reclaimable_bytes.
6011
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
134 void update_totals(uint region_num, size_t reclaimable_bytes);
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
135
6011
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
136 void clear();
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
137
4912
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
138 // Return the number of candidate regions that remain to be collected.
6011
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
139 uint remaining_regions() { return _length - _curr_index; }
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
140
4912
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
141 // Determine whether the CSet chooser has more candidate regions or not.
6011
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
142 bool is_empty() { return remaining_regions() == 0; }
4912
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
143
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
144 // Return the reclaimable bytes that remain to be collected on
a9647476d1a4 7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents: 3989
diff changeset
145 // all the candidate regions in the CSet chooser.
6011
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
146 size_t remaining_reclaimable_bytes() { return _remaining_reclaimable_bytes; }
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
147
6011
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
148 // Returns true if the used portion of "_regions" is properly
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
149 // sorted, otherwise asserts false.
6011
f7a8920427a6 7145441: G1: collection set chooser-related cleanup
tonyp
parents: 6010
diff changeset
150 void verify() PRODUCT_RETURN;
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
151 };
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
152
6254
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
153 class CSetChooserParUpdater : public StackObj {
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
154 private:
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
155 CollectionSetChooser* _chooser;
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
156 bool _parallel;
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
157 uint _chunk_size;
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
158 uint _cur_chunk_idx;
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
159 uint _cur_chunk_end;
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
160 uint _regions_added;
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
161 size_t _reclaimable_bytes_added;
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
162
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
163 public:
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
164 CSetChooserParUpdater(CollectionSetChooser* chooser,
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
165 bool parallel, uint chunk_size) :
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
166 _chooser(chooser), _parallel(parallel), _chunk_size(chunk_size),
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
167 _cur_chunk_idx(0), _cur_chunk_end(0),
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
168 _regions_added(0), _reclaimable_bytes_added(0) { }
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
169
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
170 ~CSetChooserParUpdater() {
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
171 if (_parallel && _regions_added > 0) {
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
172 _chooser->update_totals(_regions_added, _reclaimable_bytes_added);
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
173 }
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
174 }
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
175
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
176 void add_region(HeapRegion* hr) {
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
177 if (_parallel) {
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
178 if (_cur_chunk_idx == _cur_chunk_end) {
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
179 _cur_chunk_idx = _chooser->claim_array_chunk(_chunk_size);
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
180 _cur_chunk_end = _cur_chunk_idx + _chunk_size;
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
181 }
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
182 assert(_cur_chunk_idx < _cur_chunk_end, "invariant");
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
183 _chooser->set_region(_cur_chunk_idx, hr);
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
184 _cur_chunk_idx += 1;
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
185 } else {
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
186 _chooser->add_region(hr);
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
187 }
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
188 _regions_added += 1;
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
189 _reclaimable_bytes_added += hr->reclaimable_bytes();
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
190 }
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
191
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
192 bool should_add(HeapRegion* hr) { return _chooser->should_add(hr); }
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
193 };
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
194
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
195 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_COLLECTIONSETCHOOSER_HPP
6254
a2f7274eb6ef 7114678: G1: various small fixes, code cleanup, and refactoring
tonyp
parents: 6197
diff changeset
196