1 /*
2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
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 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
41 return (HeterogeneousHeapRegionManager*)hrm;
42 }
43
44 void HeterogeneousHeapRegionManager::initialize(G1RegionToSpaceMapper* heap_storage,
45 G1RegionToSpaceMapper* prev_bitmap,
46 G1RegionToSpaceMapper* next_bitmap,
47 G1RegionToSpaceMapper* bot,
48 G1RegionToSpaceMapper* cardtable,
49 G1RegionToSpaceMapper* card_counts) {
50 HeapRegionManager::initialize(heap_storage, prev_bitmap, next_bitmap, bot, cardtable, card_counts);
51
52 // We commit bitmap for all regions during initialization and mark the bitmap space as special.
53 // This allows regions to be un-committed while concurrent-marking threads are accessing the bitmap concurrently.
54 _prev_bitmap_mapper->commit_and_set_special();
55 _next_bitmap_mapper->commit_and_set_special();
56 }
57
58 // expand_by() is called to grow the heap. We grow into nvdimm now.
59 // Dram regions are committed later as needed during mutator region allocation or
60 // when young list target length is determined after gc cycle.
61 uint HeterogeneousHeapRegionManager::expand_by(uint num_regions, WorkGang* pretouch_workers) {
62 uint num_regions_possible = total_regions_committed() >= max_expandable_length() ? 0 : max_expandable_length() - total_regions_committed();
63 uint num_expanded = expand_nvdimm(MIN2(num_regions, num_regions_possible), pretouch_workers);
64 return num_expanded;
65 }
66
67 // Expands heap starting from 'start' index. The question is should we expand from one memory (e.g. nvdimm) to another (e.g. dram).
68 // Looking at the code, expand_at() is called for humongous allocation where 'start' is in nv-dimm.
69 // So we only allocate regions in the same kind of memory as 'start'.
70 uint HeterogeneousHeapRegionManager::expand_at(uint start, uint num_regions, WorkGang* pretouch_workers) {
71 if (num_regions == 0) {
72 return 0;
73 }
74 uint target_num_regions = MIN2(num_regions, max_expandable_length() - total_regions_committed());
75 uint end = is_in_nvdimm(start) ? end_index_of_nvdimm() : end_index_of_dram();
76
77 uint num_expanded = expand_in_range(start, end, target_num_regions, pretouch_workers);
78 assert(total_regions_committed() <= max_expandable_length(), "must be");
79 return num_expanded;
80 }
81
82 // This function ensures that there are 'expected_num_regions' committed regions in dram.
83 // If new regions are committed, it un-commits that many regions from nv-dimm.
84 // If there are already more regions committed in dram, extra regions are un-committed.
85 void HeterogeneousHeapRegionManager::adjust_dram_regions(uint expected_num_regions, WorkGang* pretouch_workers) {
86
87 // Release back the extra regions allocated in evacuation failure scenario.
88 if(_no_borrowed_regions > 0) {
89 _no_borrowed_regions -= shrink_dram(_no_borrowed_regions);
90 _no_borrowed_regions -= shrink_nvdimm(_no_borrowed_regions);
173 return num_regions;
174 }
175
176 uint HeterogeneousHeapRegionManager::expand_dram(uint num_regions, WorkGang* pretouch_workers) {
177 return expand_in_range(start_index_of_dram(), end_index_of_dram(), num_regions, pretouch_workers);
178 }
179
180 uint HeterogeneousHeapRegionManager::expand_nvdimm(uint num_regions, WorkGang* pretouch_workers) {
181 return expand_in_range(start_index_of_nvdimm(), end_index_of_nvdimm(), num_regions, pretouch_workers);
182 }
183
184 // Follows same logic as expand_at() form HeapRegionManager.
185 uint HeterogeneousHeapRegionManager::expand_in_range(uint start, uint end, uint num_regions, WorkGang* pretouch_gang) {
186
187 uint so_far = 0;
188 uint chunk_start = 0;
189 uint num_last_found = 0;
190 while (so_far < num_regions &&
191 (num_last_found = find_unavailable_in_range(start, end, &chunk_start)) > 0) {
192 uint to_commit = MIN2(num_regions - so_far, num_last_found);
193 make_regions_available(chunk_start, to_commit, pretouch_gang);
194 so_far += to_commit;
195 start = chunk_start + to_commit + 1;
196 }
197
198 return so_far;
199 }
200
201 // Shrink in the range of indexes which are reserved for dram.
202 uint HeterogeneousHeapRegionManager::shrink_dram(uint num_regions, bool update_free_list) {
203 return shrink_in_range(start_index_of_dram(), end_index_of_dram(), num_regions, update_free_list);
204 }
205
206 // Shrink in the range of indexes which are reserved for nv-dimm.
207 uint HeterogeneousHeapRegionManager::shrink_nvdimm(uint num_regions, bool update_free_list) {
208 return shrink_in_range(start_index_of_nvdimm(), end_index_of_nvdimm(), num_regions, update_free_list);
209 }
210
211 // Find empty regions in given range, un-commit them and return the count.
212 uint HeterogeneousHeapRegionManager::shrink_in_range(uint start, uint end, uint num_regions, bool update_free_list) {
213
246 }
247 if (cur == start_idx - 1) {
248 return num_regions_found;
249 }
250 jlong old_cur = cur;
251 // cur indexes the first empty region
252 while (cur >= start_idx && is_available(cur) && at(cur)->is_empty()) {
253 cur--;
254 }
255 *res_idx = cur + 1;
256 num_regions_found = old_cur - cur;
257
258 #ifdef ASSERT
259 for (uint i = *res_idx; i < (*res_idx + num_regions_found); i++) {
260 assert(at(i)->is_empty(), "just checking");
261 }
262 #endif
263 return num_regions_found;
264 }
265
266 HeapRegion* HeterogeneousHeapRegionManager::allocate_free_region(HeapRegionType type) {
267
268 // We want to prevent mutators from proceeding when we have borrowed regions from the last collection. This
269 // will force a full collection to remedy the situation.
270 // Free region requests from GC threads can proceed.
271 if(type.is_eden() || type.is_humongous()) {
272 if(has_borrowed_regions()) {
273 return NULL;
274 }
275 }
276
277 // old and humongous regions are allocated from nv-dimm; eden and survivor regions are allocated from dram
278 // assumption: dram regions take higher indexes
279 bool from_nvdimm = (type.is_old() || type.is_humongous()) ? true : false;
280 bool from_head = from_nvdimm;
281 HeapRegion* hr = _free_list.remove_region(from_head);
282
283 if (hr != NULL && ( (from_nvdimm && !is_in_nvdimm(hr->hrm_index())) || (!from_nvdimm && !is_in_dram(hr->hrm_index())) ) ) {
284 _free_list.add_ordered(hr);
285 hr = NULL;
286 }
|
1 /*
2 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
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 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
41 return (HeterogeneousHeapRegionManager*)hrm;
42 }
43
44 void HeterogeneousHeapRegionManager::initialize(G1RegionToSpaceMapper* heap_storage,
45 G1RegionToSpaceMapper* prev_bitmap,
46 G1RegionToSpaceMapper* next_bitmap,
47 G1RegionToSpaceMapper* bot,
48 G1RegionToSpaceMapper* cardtable,
49 G1RegionToSpaceMapper* card_counts) {
50 HeapRegionManager::initialize(heap_storage, prev_bitmap, next_bitmap, bot, cardtable, card_counts);
51
52 // We commit bitmap for all regions during initialization and mark the bitmap space as special.
53 // This allows regions to be un-committed while concurrent-marking threads are accessing the bitmap concurrently.
54 _prev_bitmap_mapper->commit_and_set_special();
55 _next_bitmap_mapper->commit_and_set_special();
56 }
57
58 // expand_by() is called to grow the heap. We grow into nvdimm now.
59 // Dram regions are committed later as needed during mutator region allocation or
60 // when young list target length is determined after gc cycle.
61 uint HeterogeneousHeapRegionManager::expand_by(uint num_regions, uint node_index, WorkGang* pretouch_workers) {
62 uint num_regions_possible = total_regions_committed() >= max_expandable_length() ? 0 : max_expandable_length() - total_regions_committed();
63 uint num_expanded = expand_nvdimm(MIN2(num_regions, num_regions_possible), pretouch_workers);
64 return num_expanded;
65 }
66
67 // Expands heap starting from 'start' index. The question is should we expand from one memory (e.g. nvdimm) to another (e.g. dram).
68 // Looking at the code, expand_at() is called for humongous allocation where 'start' is in nv-dimm.
69 // So we only allocate regions in the same kind of memory as 'start'.
70 uint HeterogeneousHeapRegionManager::expand_at(uint start, uint num_regions, uint node_index, WorkGang* pretouch_workers) {
71 if (num_regions == 0) {
72 return 0;
73 }
74 uint target_num_regions = MIN2(num_regions, max_expandable_length() - total_regions_committed());
75 uint end = is_in_nvdimm(start) ? end_index_of_nvdimm() : end_index_of_dram();
76
77 uint num_expanded = expand_in_range(start, end, target_num_regions, pretouch_workers);
78 assert(total_regions_committed() <= max_expandable_length(), "must be");
79 return num_expanded;
80 }
81
82 // This function ensures that there are 'expected_num_regions' committed regions in dram.
83 // If new regions are committed, it un-commits that many regions from nv-dimm.
84 // If there are already more regions committed in dram, extra regions are un-committed.
85 void HeterogeneousHeapRegionManager::adjust_dram_regions(uint expected_num_regions, WorkGang* pretouch_workers) {
86
87 // Release back the extra regions allocated in evacuation failure scenario.
88 if(_no_borrowed_regions > 0) {
89 _no_borrowed_regions -= shrink_dram(_no_borrowed_regions);
90 _no_borrowed_regions -= shrink_nvdimm(_no_borrowed_regions);
173 return num_regions;
174 }
175
176 uint HeterogeneousHeapRegionManager::expand_dram(uint num_regions, WorkGang* pretouch_workers) {
177 return expand_in_range(start_index_of_dram(), end_index_of_dram(), num_regions, pretouch_workers);
178 }
179
180 uint HeterogeneousHeapRegionManager::expand_nvdimm(uint num_regions, WorkGang* pretouch_workers) {
181 return expand_in_range(start_index_of_nvdimm(), end_index_of_nvdimm(), num_regions, pretouch_workers);
182 }
183
184 // Follows same logic as expand_at() form HeapRegionManager.
185 uint HeterogeneousHeapRegionManager::expand_in_range(uint start, uint end, uint num_regions, WorkGang* pretouch_gang) {
186
187 uint so_far = 0;
188 uint chunk_start = 0;
189 uint num_last_found = 0;
190 while (so_far < num_regions &&
191 (num_last_found = find_unavailable_in_range(start, end, &chunk_start)) > 0) {
192 uint to_commit = MIN2(num_regions - so_far, num_last_found);
193 make_regions_available(chunk_start, to_commit, G1MemoryNodeManager::AnyNodeIndex, pretouch_gang);
194 so_far += to_commit;
195 start = chunk_start + to_commit + 1;
196 }
197
198 return so_far;
199 }
200
201 // Shrink in the range of indexes which are reserved for dram.
202 uint HeterogeneousHeapRegionManager::shrink_dram(uint num_regions, bool update_free_list) {
203 return shrink_in_range(start_index_of_dram(), end_index_of_dram(), num_regions, update_free_list);
204 }
205
206 // Shrink in the range of indexes which are reserved for nv-dimm.
207 uint HeterogeneousHeapRegionManager::shrink_nvdimm(uint num_regions, bool update_free_list) {
208 return shrink_in_range(start_index_of_nvdimm(), end_index_of_nvdimm(), num_regions, update_free_list);
209 }
210
211 // Find empty regions in given range, un-commit them and return the count.
212 uint HeterogeneousHeapRegionManager::shrink_in_range(uint start, uint end, uint num_regions, bool update_free_list) {
213
246 }
247 if (cur == start_idx - 1) {
248 return num_regions_found;
249 }
250 jlong old_cur = cur;
251 // cur indexes the first empty region
252 while (cur >= start_idx && is_available(cur) && at(cur)->is_empty()) {
253 cur--;
254 }
255 *res_idx = cur + 1;
256 num_regions_found = old_cur - cur;
257
258 #ifdef ASSERT
259 for (uint i = *res_idx; i < (*res_idx + num_regions_found); i++) {
260 assert(at(i)->is_empty(), "just checking");
261 }
262 #endif
263 return num_regions_found;
264 }
265
266 HeapRegion* HeterogeneousHeapRegionManager::allocate_free_region(HeapRegionType type, uint node_index) {
267
268 // We want to prevent mutators from proceeding when we have borrowed regions from the last collection. This
269 // will force a full collection to remedy the situation.
270 // Free region requests from GC threads can proceed.
271 if(type.is_eden() || type.is_humongous()) {
272 if(has_borrowed_regions()) {
273 return NULL;
274 }
275 }
276
277 // old and humongous regions are allocated from nv-dimm; eden and survivor regions are allocated from dram
278 // assumption: dram regions take higher indexes
279 bool from_nvdimm = (type.is_old() || type.is_humongous()) ? true : false;
280 bool from_head = from_nvdimm;
281 HeapRegion* hr = _free_list.remove_region(from_head);
282
283 if (hr != NULL && ( (from_nvdimm && !is_in_nvdimm(hr->hrm_index())) || (!from_nvdimm && !is_in_dram(hr->hrm_index())) ) ) {
284 _free_list.add_ordered(hr);
285 hr = NULL;
286 }
|