author | zgu |
Thu, 28 Jun 2012 17:03:16 -0400 | |
changeset 13195 | be27e1b6a4b9 |
parent 12382 | 6aaecb1cbfe1 |
child 13336 | e582172ff6ff |
permissions | -rw-r--r-- |
1374 | 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 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
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 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#ifndef SHARE_VM_GC_IMPLEMENTATION_G1_COLLECTIONSETCHOOSER_HPP |
26 |
#define SHARE_VM_GC_IMPLEMENTATION_G1_COLLECTIONSETCHOOSER_HPP |
|
27 |
||
28 |
#include "gc_implementation/g1/heapRegion.hpp" |
|
29 |
#include "utilities/growableArray.hpp" |
|
30 |
||
13195 | 31 |
class CollectionSetChooser: public CHeapObj<mtGC> { |
1374 | 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. |
12382
6aaecb1cbfe1
7145441: G1: collection set chooser-related cleanup
tonyp
parents:
12381
diff
changeset
|
51 |
uint _curr_index; |
11756
28b6fe22e43d
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
10680
diff
changeset
|
52 |
|
28b6fe22e43d
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
10680
diff
changeset
|
53 |
// The number of candidate old regions added to the CSet chooser. |
12382
6aaecb1cbfe1
7145441: G1: collection set chooser-related cleanup
tonyp
parents:
12381
diff
changeset
|
54 |
uint _length; |
1374 | 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 | 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 | 67 |
|
68 |
public: |
|
69 |
||
11756
28b6fe22e43d
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
10680
diff
changeset
|
70 |
// 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
|
71 |
// 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
|
72 |
HeapRegion* peek() { |
28b6fe22e43d
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
10680
diff
changeset
|
73 |
HeapRegion* res = NULL; |
28b6fe22e43d
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
10680
diff
changeset
|
74 |
if (_curr_index < _length) { |
12382
6aaecb1cbfe1
7145441: G1: collection set chooser-related cleanup
tonyp
parents:
12381
diff
changeset
|
75 |
res = regions_at(_curr_index); |
11756
28b6fe22e43d
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
10680
diff
changeset
|
76 |
assert(res != NULL, |
12382
6aaecb1cbfe1
7145441: G1: collection set chooser-related cleanup
tonyp
parents:
12381
diff
changeset
|
77 |
err_msg("Unexpected NULL hr in _regions at index %u", |
11756
28b6fe22e43d
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
10680
diff
changeset
|
78 |
_curr_index)); |
28b6fe22e43d
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
10680
diff
changeset
|
79 |
} |
28b6fe22e43d
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
10680
diff
changeset
|
80 |
return res; |
28b6fe22e43d
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
10680
diff
changeset
|
81 |
} |
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 |
// 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
|
84 |
// 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
|
85 |
// in the CSet chooser. |
28b6fe22e43d
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
10680
diff
changeset
|
86 |
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
|
87 |
assert(hr != NULL, "pre-condition"); |
28b6fe22e43d
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
10680
diff
changeset
|
88 |
assert(_curr_index < _length, "pre-condition"); |
12382
6aaecb1cbfe1
7145441: G1: collection set chooser-related cleanup
tonyp
parents:
12381
diff
changeset
|
89 |
assert(regions_at(_curr_index) == hr, "pre-condition"); |
6aaecb1cbfe1
7145441: G1: collection set chooser-related cleanup
tonyp
parents:
12381
diff
changeset
|
90 |
regions_at_put(_curr_index, NULL); |
6aaecb1cbfe1
7145441: G1: collection set chooser-related cleanup
tonyp
parents:
12381
diff
changeset
|
91 |
assert(hr->reclaimable_bytes() <= _remaining_reclaimable_bytes, |
11756
28b6fe22e43d
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
10680
diff
changeset
|
92 |
err_msg("remaining reclaimable bytes inconsistent " |
28b6fe22e43d
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
10680
diff
changeset
|
93 |
"from region: "SIZE_FORMAT" remaining: "SIZE_FORMAT, |
12382
6aaecb1cbfe1
7145441: G1: collection set chooser-related cleanup
tonyp
parents:
12381
diff
changeset
|
94 |
hr->reclaimable_bytes(), _remaining_reclaimable_bytes)); |
6aaecb1cbfe1
7145441: G1: collection set chooser-related cleanup
tonyp
parents:
12381
diff
changeset
|
95 |
_remaining_reclaimable_bytes -= hr->reclaimable_bytes(); |
11756
28b6fe22e43d
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
10680
diff
changeset
|
96 |
_curr_index += 1; |
28b6fe22e43d
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
10680
diff
changeset
|
97 |
} |
1374 | 98 |
|
99 |
CollectionSetChooser(); |
|
100 |
||
12382
6aaecb1cbfe1
7145441: G1: collection set chooser-related cleanup
tonyp
parents:
12381
diff
changeset
|
101 |
void sort_regions(); |
11756
28b6fe22e43d
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
10680
diff
changeset
|
102 |
|
28b6fe22e43d
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
10680
diff
changeset
|
103 |
// 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
|
104 |
// 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
|
105 |
// 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
|
106 |
// live bytes are over the threshold. |
12382
6aaecb1cbfe1
7145441: G1: collection set chooser-related cleanup
tonyp
parents:
12381
diff
changeset
|
107 |
bool should_add(HeapRegion* hr) { |
11756
28b6fe22e43d
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
10680
diff
changeset
|
108 |
assert(hr->is_marked(), "pre-condition"); |
28b6fe22e43d
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
10680
diff
changeset
|
109 |
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
|
110 |
return !hr->isHumongous() && |
12382
6aaecb1cbfe1
7145441: G1: collection set chooser-related cleanup
tonyp
parents:
12381
diff
changeset
|
111 |
hr->live_bytes() < _region_live_threshold_bytes; |
11756
28b6fe22e43d
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
10680
diff
changeset
|
112 |
} |
28b6fe22e43d
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
10680
diff
changeset
|
113 |
|
28b6fe22e43d
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
10680
diff
changeset
|
114 |
// 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
|
115 |
// during a mixed GC. |
12382
6aaecb1cbfe1
7145441: G1: collection set chooser-related cleanup
tonyp
parents:
12381
diff
changeset
|
116 |
uint calc_min_old_cset_length(); |
11756
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 |
// 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
|
119 |
// during a mixed GC. |
12382
6aaecb1cbfe1
7145441: G1: collection set chooser-related cleanup
tonyp
parents:
12381
diff
changeset
|
120 |
uint calc_max_old_cset_length(); |
11756
28b6fe22e43d
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
10680
diff
changeset
|
121 |
|
28b6fe22e43d
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
10680
diff
changeset
|
122 |
// Serial version. |
12382
6aaecb1cbfe1
7145441: G1: collection set chooser-related cleanup
tonyp
parents:
12381
diff
changeset
|
123 |
void add_region(HeapRegion *hr); |
1374 | 124 |
|
12382
6aaecb1cbfe1
7145441: G1: collection set chooser-related cleanup
tonyp
parents:
12381
diff
changeset
|
125 |
// Must be called before calls to claim_array_chunk(). |
6aaecb1cbfe1
7145441: G1: collection set chooser-related cleanup
tonyp
parents:
12381
diff
changeset
|
126 |
// n_regions is the number of regions, chunk_size the chunk size. |
6aaecb1cbfe1
7145441: G1: collection set chooser-related cleanup
tonyp
parents:
12381
diff
changeset
|
127 |
void prepare_for_par_region_addition(uint n_regions, uint chunk_size); |
6aaecb1cbfe1
7145441: G1: collection set chooser-related cleanup
tonyp
parents:
12381
diff
changeset
|
128 |
// Returns the first index in a contiguous chunk of chunk_size indexes |
1374 | 129 |
// 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
|
130 |
// calling thread using set_region() (to NULL if necessary). |
6aaecb1cbfe1
7145441: G1: collection set chooser-related cleanup
tonyp
parents:
12381
diff
changeset
|
131 |
uint claim_array_chunk(uint chunk_size); |
1374 | 132 |
// Set the marked array entry at index to hr. Careful to claim the index |
133 |
// first if in parallel. |
|
12382
6aaecb1cbfe1
7145441: G1: collection set chooser-related cleanup
tonyp
parents:
12381
diff
changeset
|
134 |
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
|
135 |
// 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
|
136 |
// and the amount of reclaimable bytes by reclaimable_bytes. |
12382
6aaecb1cbfe1
7145441: G1: collection set chooser-related cleanup
tonyp
parents:
12381
diff
changeset
|
137 |
void update_totals(uint region_num, size_t reclaimable_bytes); |
1374 | 138 |
|
12382
6aaecb1cbfe1
7145441: G1: collection set chooser-related cleanup
tonyp
parents:
12381
diff
changeset
|
139 |
void clear(); |
1374 | 140 |
|
11756
28b6fe22e43d
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
10680
diff
changeset
|
141 |
// Return the number of candidate regions that remain to be collected. |
12382
6aaecb1cbfe1
7145441: G1: collection set chooser-related cleanup
tonyp
parents:
12381
diff
changeset
|
142 |
uint remaining_regions() { return _length - _curr_index; } |
1374 | 143 |
|
11756
28b6fe22e43d
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
10680
diff
changeset
|
144 |
// 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
|
145 |
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
|
146 |
|
28b6fe22e43d
7132029: G1: mixed GC phase lasts for longer than it should
tonyp
parents:
10680
diff
changeset
|
147 |
// 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
|
148 |
// all the candidate regions in the CSet chooser. |
12382
6aaecb1cbfe1
7145441: G1: collection set chooser-related cleanup
tonyp
parents:
12381
diff
changeset
|
149 |
size_t remaining_reclaimable_bytes() { return _remaining_reclaimable_bytes; } |
1374 | 150 |
|
12382
6aaecb1cbfe1
7145441: G1: collection set chooser-related cleanup
tonyp
parents:
12381
diff
changeset
|
151 |
// Returns true if the used portion of "_regions" is properly |
1374 | 152 |
// sorted, otherwise asserts false. |
12382
6aaecb1cbfe1
7145441: G1: collection set chooser-related cleanup
tonyp
parents:
12381
diff
changeset
|
153 |
void verify() PRODUCT_RETURN; |
1374 | 154 |
}; |
7397 | 155 |
|
156 |
#endif // SHARE_VM_GC_IMPLEMENTATION_G1_COLLECTIONSETCHOOSER_HPP |