Mercurial > hg > truffle
annotate src/share/vm/gc_implementation/g1/heapRegionManager.cpp @ 20404:227a9e5e4b4a
8057536: Refactor G1 to allow context specific allocations
Summary: Splitting out a g1 allocator class to simply specialized allocators which can associate each allocation with a given context.
Reviewed-by: mgerdin, brutisso
author | sjohanss |
---|---|
date | Fri, 05 Sep 2014 09:49:19 +0200 |
parents | b1266b08b994 |
children | d35872270666 |
rev | line source |
---|---|
342 | 1 /* |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17736
diff
changeset
|
2 * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. |
342 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
960
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
960
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:
960
diff
changeset
|
21 * questions. |
342 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
3766 | 26 #include "gc_implementation/g1/heapRegion.hpp" |
20377
a8ea2f110d87
8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents:
20337
diff
changeset
|
27 #include "gc_implementation/g1/heapRegionManager.inline.hpp" |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
28 #include "gc_implementation/g1/heapRegionSet.inline.hpp" |
1972 | 29 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
30 #include "gc_implementation/g1/concurrentG1Refine.hpp" |
1972 | 31 #include "memory/allocation.hpp" |
342 | 32 |
20377
a8ea2f110d87
8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents:
20337
diff
changeset
|
33 void HeapRegionManager::initialize(G1RegionToSpaceMapper* heap_storage, |
20337 | 34 G1RegionToSpaceMapper* prev_bitmap, |
35 G1RegionToSpaceMapper* next_bitmap, | |
36 G1RegionToSpaceMapper* bot, | |
37 G1RegionToSpaceMapper* cardtable, | |
38 G1RegionToSpaceMapper* card_counts) { | |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
39 _allocated_heapregions_length = 0; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
40 |
20337 | 41 _heap_mapper = heap_storage; |
42 | |
43 _prev_bitmap_mapper = prev_bitmap; | |
44 _next_bitmap_mapper = next_bitmap; | |
45 | |
46 _bot_mapper = bot; | |
47 _cardtable_mapper = cardtable; | |
48 | |
49 _card_counts_mapper = card_counts; | |
50 | |
51 MemRegion reserved = heap_storage->reserved(); | |
52 _regions.initialize(reserved.start(), reserved.end(), HeapRegion::GrainBytes); | |
53 | |
54 _available_map.resize(_regions.length(), false); | |
55 _available_map.clear(); | |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
56 } |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
57 |
20377
a8ea2f110d87
8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents:
20337
diff
changeset
|
58 bool HeapRegionManager::is_available(uint region) const { |
20337 | 59 return _available_map.at(region); |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
60 } |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
61 |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
62 #ifdef ASSERT |
20377
a8ea2f110d87
8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents:
20337
diff
changeset
|
63 bool HeapRegionManager::is_free(HeapRegion* hr) const { |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
64 return _free_list.contains(hr); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
65 } |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
66 #endif |
342 | 67 |
20377
a8ea2f110d87
8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents:
20337
diff
changeset
|
68 HeapRegion* HeapRegionManager::new_heap_region(uint hrm_index) { |
a8ea2f110d87
8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents:
20337
diff
changeset
|
69 HeapWord* bottom = G1CollectedHeap::heap()->bottom_addr_for_region(hrm_index); |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
70 MemRegion mr(bottom, bottom + HeapRegion::GrainWords); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
71 assert(reserved().contains(mr), "invariant"); |
20377
a8ea2f110d87
8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents:
20337
diff
changeset
|
72 return new HeapRegion(hrm_index, G1CollectedHeap::heap()->bot_shared(), mr); |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
73 } |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
74 |
20377
a8ea2f110d87
8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents:
20337
diff
changeset
|
75 void HeapRegionManager::commit_regions(uint index, size_t num_regions) { |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
76 guarantee(num_regions > 0, "Must commit more than zero regions"); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
77 guarantee(_num_committed + num_regions <= max_length(), "Cannot commit more than the maximum amount of regions"); |
342 | 78 |
20337 | 79 _num_committed += (uint)num_regions; |
80 | |
81 _heap_mapper->commit_regions(index, num_regions); | |
82 | |
83 // Also commit auxiliary data | |
84 _prev_bitmap_mapper->commit_regions(index, num_regions); | |
85 _next_bitmap_mapper->commit_regions(index, num_regions); | |
86 | |
87 _bot_mapper->commit_regions(index, num_regions); | |
88 _cardtable_mapper->commit_regions(index, num_regions); | |
89 | |
90 _card_counts_mapper->commit_regions(index, num_regions); | |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
91 } |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
92 |
20377
a8ea2f110d87
8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents:
20337
diff
changeset
|
93 void HeapRegionManager::uncommit_regions(uint start, size_t num_regions) { |
20337 | 94 guarantee(num_regions >= 1, err_msg("Need to specify at least one region to uncommit, tried to uncommit zero regions at %u", start)); |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
95 guarantee(_num_committed >= num_regions, "pre-condition"); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
96 |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
97 // Print before uncommitting. |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
98 if (G1CollectedHeap::heap()->hr_printer()->is_active()) { |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
99 for (uint i = start; i < start + num_regions; i++) { |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
100 HeapRegion* hr = at(i); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
101 G1CollectedHeap::heap()->hr_printer()->uncommit(hr->bottom(), hr->end()); |
2152 | 102 } |
103 } | |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
104 |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
105 _num_committed -= (uint)num_regions; |
20337 | 106 |
107 _available_map.par_clear_range(start, start + num_regions, BitMap::unknown_range); | |
108 _heap_mapper->uncommit_regions(start, num_regions); | |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
109 |
20337 | 110 // Also uncommit auxiliary data |
111 _prev_bitmap_mapper->uncommit_regions(start, num_regions); | |
112 _next_bitmap_mapper->uncommit_regions(start, num_regions); | |
113 | |
114 _bot_mapper->uncommit_regions(start, num_regions); | |
115 _cardtable_mapper->uncommit_regions(start, num_regions); | |
116 | |
117 _card_counts_mapper->uncommit_regions(start, num_regions); | |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
118 } |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
119 |
20377
a8ea2f110d87
8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents:
20337
diff
changeset
|
120 void HeapRegionManager::make_regions_available(uint start, uint num_regions) { |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
121 guarantee(num_regions > 0, "No point in calling this for zero regions"); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
122 commit_regions(start, num_regions); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
123 for (uint i = start; i < start + num_regions; i++) { |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
124 if (_regions.get_by_index(i) == NULL) { |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
125 HeapRegion* new_hr = new_heap_region(i); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
126 _regions.set_by_index(i, new_hr); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
127 _allocated_heapregions_length = MAX2(_allocated_heapregions_length, i + 1); |
2152 | 128 } |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
129 } |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
130 |
20337 | 131 _available_map.par_set_range(start, start + num_regions, BitMap::unknown_range); |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
132 |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
133 for (uint i = start; i < start + num_regions; i++) { |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
134 assert(is_available(i), err_msg("Just made region %u available but is apparently not.", i)); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
135 HeapRegion* hr = at(i); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
136 if (G1CollectedHeap::heap()->hr_printer()->is_active()) { |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
137 G1CollectedHeap::heap()->hr_printer()->commit(hr->bottom(), hr->end()); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
138 } |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
139 HeapWord* bottom = G1CollectedHeap::heap()->bottom_addr_for_region(i); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
140 MemRegion mr(bottom, bottom + HeapRegion::GrainWords); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
141 |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
142 hr->initialize(mr); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
143 insert_into_free_list(at(i)); |
2152 | 144 } |
145 } | |
146 | |
20377
a8ea2f110d87
8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents:
20337
diff
changeset
|
147 uint HeapRegionManager::expand_by(uint num_regions) { |
20337 | 148 return expand_at(0, num_regions); |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
149 } |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
150 |
20377
a8ea2f110d87
8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents:
20337
diff
changeset
|
151 uint HeapRegionManager::expand_at(uint start, uint num_regions) { |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
152 if (num_regions == 0) { |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
153 return 0; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
154 } |
3766 | 155 |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
156 uint cur = start; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
157 uint idx_last_found = 0; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
158 uint num_last_found = 0; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
159 |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
160 uint expanded = 0; |
3766 | 161 |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
162 while (expanded < num_regions && |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
163 (num_last_found = find_unavailable_from_idx(cur, &idx_last_found)) > 0) { |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
164 uint to_expand = MIN2(num_regions - expanded, num_last_found); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
165 make_regions_available(idx_last_found, to_expand); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
166 expanded += to_expand; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
167 cur = idx_last_found + num_last_found + 1; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
168 } |
3766 | 169 |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
170 verify_optional(); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
171 return expanded; |
3766 | 172 } |
173 | |
20377
a8ea2f110d87
8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents:
20337
diff
changeset
|
174 uint HeapRegionManager::find_contiguous(size_t num, bool empty_only) { |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
175 uint found = 0; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
176 size_t length_found = 0; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
177 uint cur = 0; |
3766 | 178 |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
179 while (length_found < num && cur < max_length()) { |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
180 HeapRegion* hr = _regions.get_by_index(cur); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
181 if ((!empty_only && !is_available(cur)) || (is_available(cur) && hr != NULL && hr->is_empty())) { |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
182 // This region is a potential candidate for allocation into. |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
183 length_found++; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
184 } else { |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
185 // This region is not a candidate. The next region is the next possible one. |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
186 found = cur + 1; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
187 length_found = 0; |
3766 | 188 } |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
189 cur++; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
190 } |
3766 | 191 |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
192 if (length_found == num) { |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
193 for (uint i = found; i < (found + num); i++) { |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
194 HeapRegion* hr = _regions.get_by_index(i); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
195 // sanity check |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
196 guarantee((!empty_only && !is_available(i)) || (is_available(i) && hr != NULL && hr->is_empty()), |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
197 err_msg("Found region sequence starting at " UINT32_FORMAT ", length " SIZE_FORMAT |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
198 " that is not empty at " UINT32_FORMAT ". Hr is " PTR_FORMAT, found, num, i, p2i(hr))); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
199 } |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
200 return found; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
201 } else { |
20377
a8ea2f110d87
8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents:
20337
diff
changeset
|
202 return G1_NO_HRM_INDEX; |
2152 | 203 } |
3766 | 204 } |
205 | |
20377
a8ea2f110d87
8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents:
20337
diff
changeset
|
206 HeapRegion* HeapRegionManager::next_region_in_heap(const HeapRegion* r) const { |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
207 guarantee(r != NULL, "Start region must be a valid region"); |
20377
a8ea2f110d87
8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents:
20337
diff
changeset
|
208 guarantee(is_available(r->hrm_index()), err_msg("Trying to iterate starting from region %u which is not in the heap", r->hrm_index())); |
a8ea2f110d87
8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents:
20337
diff
changeset
|
209 for (uint i = r->hrm_index() + 1; i < _allocated_heapregions_length; i++) { |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
210 HeapRegion* hr = _regions.get_by_index(i); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
211 if (is_available(i)) { |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
212 return hr; |
3766 | 213 } |
2152 | 214 } |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
215 return NULL; |
342 | 216 } |
217 | |
20377
a8ea2f110d87
8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents:
20337
diff
changeset
|
218 void HeapRegionManager::iterate(HeapRegionClosure* blk) const { |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
219 uint len = max_length(); |
3766 | 220 |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
221 for (uint i = 0; i < len; i++) { |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
222 if (!is_available(i)) { |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
223 continue; |
342 | 224 } |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
225 guarantee(at(i) != NULL, err_msg("Tried to access region %u that has a NULL HeapRegion*", i)); |
3766 | 226 bool res = blk->doHeapRegion(at(i)); |
342 | 227 if (res) { |
228 blk->incomplete(); | |
229 return; | |
230 } | |
231 } | |
232 } | |
233 | |
20377
a8ea2f110d87
8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents:
20337
diff
changeset
|
234 uint HeapRegionManager::find_unavailable_from_idx(uint start_idx, uint* res_idx) const { |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
235 guarantee(res_idx != NULL, "checking"); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
236 guarantee(start_idx <= (max_length() + 1), "checking"); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
237 |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
238 uint num_regions = 0; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
239 |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
240 uint cur = start_idx; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
241 while (cur < max_length() && is_available(cur)) { |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
242 cur++; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
243 } |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
244 if (cur == max_length()) { |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
245 return num_regions; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
246 } |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
247 *res_idx = cur; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
248 while (cur < max_length() && !is_available(cur)) { |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
249 cur++; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
250 } |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
251 num_regions = cur - *res_idx; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
252 #ifdef ASSERT |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
253 for (uint i = *res_idx; i < (*res_idx + num_regions); i++) { |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
254 assert(!is_available(i), "just checking"); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
255 } |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
256 assert(cur == max_length() || num_regions == 0 || is_available(cur), |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
257 err_msg("The region at the current position %u must be available or at the end of the heap.", cur)); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
258 #endif |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
259 return num_regions; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
260 } |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
261 |
20377
a8ea2f110d87
8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents:
20337
diff
changeset
|
262 uint HeapRegionManager::start_region_for_worker(uint worker_i, uint num_workers, uint num_regions) const { |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
263 return num_regions * worker_i / num_workers; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
264 } |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
265 |
20377
a8ea2f110d87
8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents:
20337
diff
changeset
|
266 void HeapRegionManager::par_iterate(HeapRegionClosure* blk, uint worker_id, uint num_workers, jint claim_value) const { |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
267 const uint start_index = start_region_for_worker(worker_id, num_workers, _allocated_heapregions_length); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
268 |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
269 // Every worker will actually look at all regions, skipping over regions that |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
270 // are currently not committed. |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
271 // This also (potentially) iterates over regions newly allocated during GC. This |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
272 // is no problem except for some extra work. |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
273 for (uint count = 0; count < _allocated_heapregions_length; count++) { |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
274 const uint index = (start_index + count) % _allocated_heapregions_length; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
275 assert(0 <= index && index < _allocated_heapregions_length, "sanity"); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
276 // Skip over unavailable regions |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
277 if (!is_available(index)) { |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
278 continue; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
279 } |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
280 HeapRegion* r = _regions.get_by_index(index); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
281 // We'll ignore "continues humongous" regions (we'll process them |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
282 // when we come across their corresponding "start humongous" |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
283 // region) and regions already claimed. |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
284 if (r->claim_value() == claim_value || r->continuesHumongous()) { |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
285 continue; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
286 } |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
287 // OK, try to claim it |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
288 if (!r->claimHeapRegion(claim_value)) { |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
289 continue; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
290 } |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
291 // Success! |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
292 if (r->startsHumongous()) { |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
293 // If the region is "starts humongous" we'll iterate over its |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
294 // "continues humongous" first; in fact we'll do them |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
295 // first. The order is important. In one case, calling the |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
296 // closure on the "starts humongous" region might de-allocate |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
297 // and clear all its "continues humongous" regions and, as a |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
298 // result, we might end up processing them twice. So, we'll do |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
299 // them first (note: most closures will ignore them anyway) and |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
300 // then we'll do the "starts humongous" region. |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
301 for (uint ch_index = index + 1; ch_index < index + r->region_num(); ch_index++) { |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
302 HeapRegion* chr = _regions.get_by_index(ch_index); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
303 |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
304 assert(chr->continuesHumongous(), "Must be humongous region"); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
305 assert(chr->humongous_start_region() == r, |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
306 err_msg("Must work on humongous continuation of the original start region " |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
307 PTR_FORMAT ", but is " PTR_FORMAT, p2i(r), p2i(chr))); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
308 assert(chr->claim_value() != claim_value, |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
309 "Must not have been claimed yet because claiming of humongous continuation first claims the start region"); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
310 |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
311 bool claim_result = chr->claimHeapRegion(claim_value); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
312 // We should always be able to claim it; no one else should |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
313 // be trying to claim this region. |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
314 guarantee(claim_result, "We should always be able to claim the continuesHumongous part of the humongous object"); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
315 |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
316 bool res2 = blk->doHeapRegion(chr); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
317 if (res2) { |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
318 return; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
319 } |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
320 |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
321 // Right now, this holds (i.e., no closure that actually |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
322 // does something with "continues humongous" regions |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
323 // clears them). We might have to weaken it in the future, |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
324 // but let's leave these two asserts here for extra safety. |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
325 assert(chr->continuesHumongous(), "should still be the case"); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
326 assert(chr->humongous_start_region() == r, "sanity"); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
327 } |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
328 } |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
329 |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
330 bool res = blk->doHeapRegion(r); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
331 if (res) { |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
332 return; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
333 } |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
334 } |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
335 } |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
336 |
20377
a8ea2f110d87
8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents:
20337
diff
changeset
|
337 uint HeapRegionManager::shrink_by(uint num_regions_to_remove) { |
3766 | 338 assert(length() > 0, "the region sequence should not be empty"); |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
339 assert(length() <= _allocated_heapregions_length, "invariant"); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
340 assert(_allocated_heapregions_length > 0, "we should have at least one region committed"); |
10242
b0d20fa374b4
8013872: G1: HeapRegionSeq::shrink_by() has invalid assert
brutisso
parents:
6197
diff
changeset
|
341 assert(num_regions_to_remove < length(), "We should never remove all regions"); |
342 | 342 |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
343 if (num_regions_to_remove == 0) { |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
344 return 0; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
345 } |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
346 |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
347 uint removed = 0; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
348 uint cur = _allocated_heapregions_length - 1; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
349 uint idx_last_found = 0; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
350 uint num_last_found = 0; |
3766 | 351 |
20337 | 352 while ((removed < num_regions_to_remove) && |
353 (num_last_found = find_empty_from_idx_reverse(cur, &idx_last_found)) > 0) { | |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
354 uint to_remove = MIN2(num_regions_to_remove - removed, num_last_found); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
355 |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
356 uncommit_regions(idx_last_found + num_last_found - to_remove, to_remove); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
357 |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
358 cur -= num_last_found; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
359 removed += to_remove; |
342 | 360 } |
10242
b0d20fa374b4
8013872: G1: HeapRegionSeq::shrink_by() has invalid assert
brutisso
parents:
6197
diff
changeset
|
361 |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
362 verify_optional(); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
363 |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
364 return removed; |
342 | 365 } |
366 | |
20377
a8ea2f110d87
8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents:
20337
diff
changeset
|
367 uint HeapRegionManager::find_empty_from_idx_reverse(uint start_idx, uint* res_idx) const { |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
368 guarantee(start_idx < _allocated_heapregions_length, "checking"); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
369 guarantee(res_idx != NULL, "checking"); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
370 |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
371 uint num_regions_found = 0; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
372 |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
373 jlong cur = start_idx; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
374 while (cur != -1 && !(is_available(cur) && at(cur)->is_empty())) { |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
375 cur--; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
376 } |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
377 if (cur == -1) { |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
378 return num_regions_found; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
379 } |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
380 jlong old_cur = cur; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
381 // cur indexes the first empty region |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
382 while (cur != -1 && is_available(cur) && at(cur)->is_empty()) { |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
383 cur--; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
384 } |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
385 *res_idx = cur + 1; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
386 num_regions_found = old_cur - cur; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
387 |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
388 #ifdef ASSERT |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
389 for (uint i = *res_idx; i < (*res_idx + num_regions_found); i++) { |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
390 assert(at(i)->is_empty(), "just checking"); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
391 } |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
392 #endif |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
393 return num_regions_found; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
394 } |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
395 |
20377
a8ea2f110d87
8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents:
20337
diff
changeset
|
396 void HeapRegionManager::verify() { |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
397 guarantee(length() <= _allocated_heapregions_length, |
6010
720b6a76dd9d
7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents:
3766
diff
changeset
|
398 err_msg("invariant: _length: %u _allocated_length: %u", |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
399 length(), _allocated_heapregions_length)); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
400 guarantee(_allocated_heapregions_length <= max_length(), |
6010
720b6a76dd9d
7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents:
3766
diff
changeset
|
401 err_msg("invariant: _allocated_length: %u _max_length: %u", |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
402 _allocated_heapregions_length, max_length())); |
3766 | 403 |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
404 bool prev_committed = true; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
405 uint num_committed = 0; |
12305
a19bea467577
7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
10242
diff
changeset
|
406 HeapWord* prev_end = heap_bottom(); |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
407 for (uint i = 0; i < _allocated_heapregions_length; i++) { |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
408 if (!is_available(i)) { |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
409 prev_committed = false; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
410 continue; |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
411 } |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
412 num_committed++; |
12305
a19bea467577
7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
10242
diff
changeset
|
413 HeapRegion* hr = _regions.get_by_index(i); |
6010
720b6a76dd9d
7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents:
3766
diff
changeset
|
414 guarantee(hr != NULL, err_msg("invariant: i: %u", i)); |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
415 guarantee(!prev_committed || hr->bottom() == prev_end, |
6010
720b6a76dd9d
7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents:
3766
diff
changeset
|
416 err_msg("invariant i: %u "HR_FORMAT" prev_end: "PTR_FORMAT, |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17736
diff
changeset
|
417 i, HR_FORMAT_PARAMS(hr), p2i(prev_end))); |
20377
a8ea2f110d87
8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents:
20337
diff
changeset
|
418 guarantee(hr->hrm_index() == i, |
a8ea2f110d87
8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents:
20337
diff
changeset
|
419 err_msg("invariant: i: %u hrm_index(): %u", i, hr->hrm_index())); |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
420 // Asserts will fire if i is >= _length |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
421 HeapWord* addr = hr->bottom(); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
422 guarantee(addr_to_region(addr) == hr, "sanity"); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
423 // We cannot check whether the region is part of a particular set: at the time |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
424 // this method may be called, we have only completed allocation of the regions, |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
425 // but not put into a region set. |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
426 prev_committed = true; |
3766 | 427 if (hr->startsHumongous()) { |
428 prev_end = hr->orig_end(); | |
429 } else { | |
430 prev_end = hr->end(); | |
431 } | |
342 | 432 } |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
433 for (uint i = _allocated_heapregions_length; i < max_length(); i++) { |
12305
a19bea467577
7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
10242
diff
changeset
|
434 guarantee(_regions.get_by_index(i) == NULL, err_msg("invariant i: %u", i)); |
3766 | 435 } |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
436 |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
437 guarantee(num_committed == _num_committed, err_msg("Found %u committed regions, but should be %u", num_committed, _num_committed)); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
438 _free_list.verify(); |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
439 } |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
440 |
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
441 #ifndef PRODUCT |
20377
a8ea2f110d87
8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents:
20337
diff
changeset
|
442 void HeapRegionManager::verify_optional() { |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
443 verify(); |
342 | 444 } |
3766 | 445 #endif // PRODUCT |
20336
6701abbc4441
8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents:
20335
diff
changeset
|
446 |