Print this page
rev 3463 : 7114678: G1: various small fixes, code cleanup, and refactoring
Summary: Various cleanups as a prelude to introducing iterators for HeapRegions.
Reviewed-by: johnc
Contributed-by: tonyp
Split |
Close |
Expand all |
Collapse all |
--- old/src/share/vm/gc_implementation/g1/collectionSetChooser.hpp
+++ new/src/share/vm/gc_implementation/g1/collectionSetChooser.hpp
1 1 /*
2 2 * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation.
8 8 *
9 9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 12 * version 2 for more details (a copy is included in the LICENSE file that
13 13 * accompanied this code).
14 14 *
15 15 * You should have received a copy of the GNU General Public License version
16 16 * 2 along with this work; if not, write to the Free Software Foundation,
17 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 18 *
19 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 20 * or visit www.oracle.com if you need additional information or have any
21 21 * questions.
22 22 *
23 23 */
24 24
25 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_COLLECTIONSETCHOOSER_HPP
26 26 #define SHARE_VM_GC_IMPLEMENTATION_G1_COLLECTIONSETCHOOSER_HPP
27 27
28 28 #include "gc_implementation/g1/heapRegion.hpp"
29 29 #include "utilities/growableArray.hpp"
30 30
31 31 class CollectionSetChooser: public CHeapObj {
32 32
33 33 GrowableArray<HeapRegion*> _regions;
34 34
35 35 // Unfortunately, GrowableArray uses ints for length and indexes. To
36 36 // avoid excessive casting in the rest of the class the following
37 37 // wrapper methods are provided that use uints.
38 38
39 39 uint regions_length() { return (uint) _regions.length(); }
40 40 HeapRegion* regions_at(uint i) { return _regions.at((int) i); }
41 41 void regions_at_put(uint i, HeapRegion* hr) {
42 42 _regions.at_put((int) i, hr);
43 43 }
44 44 void regions_at_put_grow(uint i, HeapRegion* hr) {
45 45 _regions.at_put_grow((int) i, hr);
46 46 }
47 47 void regions_trunc_to(uint i) { _regions.trunc_to((uint) i); }
48 48
49 49 // The index of the next candidate old region to be considered for
50 50 // addition to the CSet.
51 51 uint _curr_index;
52 52
53 53 // The number of candidate old regions added to the CSet chooser.
54 54 uint _length;
55 55
56 56 // Keeps track of the start of the next array chunk to be claimed by
57 57 // parallel GC workers.
58 58 uint _first_par_unreserved_idx;
59 59
60 60 // If a region has more live bytes than this threshold, it will not
61 61 // be added to the CSet chooser and will not be a candidate for
62 62 // collection.
63 63 size_t _region_live_threshold_bytes;
64 64
65 65 // The sum of reclaimable bytes over all the regions in the CSet chooser.
66 66 size_t _remaining_reclaimable_bytes;
67 67
68 68 public:
69 69
70 70 // Return the current candidate region to be considered for
71 71 // collection without removing it from the CSet chooser.
72 72 HeapRegion* peek() {
73 73 HeapRegion* res = NULL;
74 74 if (_curr_index < _length) {
75 75 res = regions_at(_curr_index);
76 76 assert(res != NULL,
77 77 err_msg("Unexpected NULL hr in _regions at index %u",
78 78 _curr_index));
79 79 }
80 80 return res;
81 81 }
82 82
83 83 // Remove the given region from the CSet chooser and move to the
84 84 // next one. The given region should be the current candidate region
85 85 // in the CSet chooser.
86 86 void remove_and_move_to_next(HeapRegion* hr) {
87 87 assert(hr != NULL, "pre-condition");
88 88 assert(_curr_index < _length, "pre-condition");
89 89 assert(regions_at(_curr_index) == hr, "pre-condition");
90 90 regions_at_put(_curr_index, NULL);
91 91 assert(hr->reclaimable_bytes() <= _remaining_reclaimable_bytes,
92 92 err_msg("remaining reclaimable bytes inconsistent "
93 93 "from region: "SIZE_FORMAT" remaining: "SIZE_FORMAT,
94 94 hr->reclaimable_bytes(), _remaining_reclaimable_bytes));
95 95 _remaining_reclaimable_bytes -= hr->reclaimable_bytes();
96 96 _curr_index += 1;
97 97 }
98 98
99 99 CollectionSetChooser();
100 100
101 101 void sort_regions();
102 102
103 103 // Determine whether to add the given region to the CSet chooser or
104 104 // not. Currently, we skip humongous regions (we never add them to
105 105 // the CSet, we only reclaim them during cleanup) and regions whose
106 106 // live bytes are over the threshold.
107 107 bool should_add(HeapRegion* hr) {
108 108 assert(hr->is_marked(), "pre-condition");
109 109 assert(!hr->is_young(), "should never consider young regions");
110 110 return !hr->isHumongous() &&
111 111 hr->live_bytes() < _region_live_threshold_bytes;
112 112 }
113 113
114 114 // Calculate the minimum number of old regions we'll add to the CSet
115 115 // during a mixed GC.
116 116 uint calc_min_old_cset_length();
117 117
118 118 // Calculate the maximum number of old regions we'll add to the CSet
119 119 // during a mixed GC.
120 120 uint calc_max_old_cset_length();
121 121
122 122 // Serial version.
123 123 void add_region(HeapRegion *hr);
124 124
125 125 // Must be called before calls to claim_array_chunk().
126 126 // n_regions is the number of regions, chunk_size the chunk size.
127 127 void prepare_for_par_region_addition(uint n_regions, uint chunk_size);
128 128 // Returns the first index in a contiguous chunk of chunk_size indexes
129 129 // that the calling thread has reserved. These must be set by the
130 130 // calling thread using set_region() (to NULL if necessary).
131 131 uint claim_array_chunk(uint chunk_size);
132 132 // Set the marked array entry at index to hr. Careful to claim the index
133 133 // first if in parallel.
134 134 void set_region(uint index, HeapRegion* hr);
135 135 // Atomically increment the number of added regions by region_num
136 136 // and the amount of reclaimable bytes by reclaimable_bytes.
137 137 void update_totals(uint region_num, size_t reclaimable_bytes);
138 138
139 139 void clear();
140 140
141 141 // Return the number of candidate regions that remain to be collected.
142 142 uint remaining_regions() { return _length - _curr_index; }
143 143
144 144 // Determine whether the CSet chooser has more candidate regions or not.
145 145 bool is_empty() { return remaining_regions() == 0; }
↓ open down ↓ |
145 lines elided |
↑ open up ↑ |
146 146
147 147 // Return the reclaimable bytes that remain to be collected on
148 148 // all the candidate regions in the CSet chooser.
149 149 size_t remaining_reclaimable_bytes() { return _remaining_reclaimable_bytes; }
150 150
151 151 // Returns true if the used portion of "_regions" is properly
152 152 // sorted, otherwise asserts false.
153 153 void verify() PRODUCT_RETURN;
154 154 };
155 155
156 +class CSetChooserParUpdater : public StackObj {
157 +private:
158 + CollectionSetChooser* _chooser;
159 + bool _parallel;
160 + uint _chunk_size;
161 + uint _cur_chunk_idx;
162 + uint _cur_chunk_end;
163 + uint _regions_added;
164 + size_t _reclaimable_bytes_added;
165 +
166 +public:
167 + CSetChooserParUpdater(CollectionSetChooser* chooser,
168 + bool parallel, uint chunk_size) :
169 + _chooser(chooser), _parallel(parallel), _chunk_size(chunk_size),
170 + _cur_chunk_idx(0), _cur_chunk_end(0),
171 + _regions_added(0), _reclaimable_bytes_added(0) { }
172 +
173 + ~CSetChooserParUpdater() {
174 + if (_parallel && _regions_added > 0) {
175 + _chooser->update_totals(_regions_added, _reclaimable_bytes_added);
176 + }
177 + }
178 +
179 + void add_region(HeapRegion* hr) {
180 + if (_parallel) {
181 + if (_cur_chunk_idx == _cur_chunk_end) {
182 + _cur_chunk_idx = _chooser->claim_array_chunk(_chunk_size);
183 + _cur_chunk_end = _cur_chunk_idx + _chunk_size;
184 + }
185 + assert(_cur_chunk_idx < _cur_chunk_end, "invariant");
186 + _chooser->set_region(_cur_chunk_idx, hr);
187 + _cur_chunk_idx += 1;
188 + } else {
189 + _chooser->add_region(hr);
190 + }
191 + _regions_added += 1;
192 + _reclaimable_bytes_added += hr->reclaimable_bytes();
193 + }
194 +
195 + bool should_add(HeapRegion* hr) { return _chooser->should_add(hr); }
196 +};
197 +
156 198 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_COLLECTIONSETCHOOSER_HPP
199 +
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX