1 /*
2 * Copyright (c) 2001, 2014, 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 *
253 #ifdef ASSERT
254 for (uint i = *res_idx; i < (*res_idx + num_regions); i++) {
255 assert(!is_available(i), "just checking");
256 }
257 assert(cur == max_length() || num_regions == 0 || is_available(cur),
258 err_msg("The region at the current position %u must be available or at the end of the heap.", cur));
259 #endif
260 return num_regions;
261 }
262
263 void HeapRegionManager::par_iterate(HeapRegionClosure* blk, uint worker_id, HeapRegionClaimer* hrclaimer, bool concurrent) const {
264 const uint start_index = hrclaimer->start_region_for_worker(worker_id);
265
266 // Every worker will actually look at all regions, skipping over regions that
267 // are currently not committed.
268 // This also (potentially) iterates over regions newly allocated during GC. This
269 // is no problem except for some extra work.
270 const uint n_regions = hrclaimer->n_regions();
271 for (uint count = 0; count < n_regions; count++) {
272 const uint index = (start_index + count) % n_regions;
273 assert(0 <= index && index < n_regions, "sanity");
274 // Skip over unavailable regions
275 if (!is_available(index)) {
276 continue;
277 }
278 HeapRegion* r = _regions.get_by_index(index);
279 // We'll ignore "continues humongous" regions (we'll process them
280 // when we come across their corresponding "start humongous"
281 // region) and regions already claimed.
282 // However, if the iteration is specified as concurrent, the values for
283 // is_starts_humongous and is_continues_humongous can not be trusted,
284 // and we should just blindly iterate over regions regardless of their
285 // humongous status.
286 if (hrclaimer->is_region_claimed(index) || (!concurrent && r->is_continues_humongous())) {
287 continue;
288 }
289 // OK, try to claim it
290 if (!hrclaimer->claim_region(index)) {
291 continue;
292 }
293 // Success!
|
1 /*
2 * Copyright (c) 2001, 2015, 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 *
253 #ifdef ASSERT
254 for (uint i = *res_idx; i < (*res_idx + num_regions); i++) {
255 assert(!is_available(i), "just checking");
256 }
257 assert(cur == max_length() || num_regions == 0 || is_available(cur),
258 err_msg("The region at the current position %u must be available or at the end of the heap.", cur));
259 #endif
260 return num_regions;
261 }
262
263 void HeapRegionManager::par_iterate(HeapRegionClosure* blk, uint worker_id, HeapRegionClaimer* hrclaimer, bool concurrent) const {
264 const uint start_index = hrclaimer->start_region_for_worker(worker_id);
265
266 // Every worker will actually look at all regions, skipping over regions that
267 // are currently not committed.
268 // This also (potentially) iterates over regions newly allocated during GC. This
269 // is no problem except for some extra work.
270 const uint n_regions = hrclaimer->n_regions();
271 for (uint count = 0; count < n_regions; count++) {
272 const uint index = (start_index + count) % n_regions;
273 assert(index < n_regions, "sanity");
274 // Skip over unavailable regions
275 if (!is_available(index)) {
276 continue;
277 }
278 HeapRegion* r = _regions.get_by_index(index);
279 // We'll ignore "continues humongous" regions (we'll process them
280 // when we come across their corresponding "start humongous"
281 // region) and regions already claimed.
282 // However, if the iteration is specified as concurrent, the values for
283 // is_starts_humongous and is_continues_humongous can not be trusted,
284 // and we should just blindly iterate over regions regardless of their
285 // humongous status.
286 if (hrclaimer->is_region_claimed(index) || (!concurrent && r->is_continues_humongous())) {
287 continue;
288 }
289 // OK, try to claim it
290 if (!hrclaimer->claim_region(index)) {
291 continue;
292 }
293 // Success!
|