1 | /* |
2 | * Copyright (c) 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 | * |
23 | */ |
24 | |
25 | #include "precompiled.hpp" |
26 | #include "gc/g1/g1CollectionSetCandidates.hpp" |
27 | #include "gc/g1/g1CollectionSetChooser.hpp" |
28 | #include "gc/g1/heapRegion.inline.hpp" |
29 | |
30 | void G1CollectionSetCandidates::remove(uint num_regions) { |
31 | assert(num_regions <= num_remaining(), "Trying to remove more regions (%u) than available (%u)" , num_regions, num_remaining()); |
32 | for (uint i = 0; i < num_regions; i++) { |
33 | _remaining_reclaimable_bytes -= at(_front_idx)->reclaimable_bytes(); |
34 | _front_idx++; |
35 | } |
36 | } |
37 | |
38 | void G1CollectionSetCandidates::iterate(HeapRegionClosure* cl) { |
39 | for (uint i = _front_idx; i < _num_regions; i++) { |
40 | HeapRegion* r = _regions[i]; |
41 | if (cl->do_heap_region(r)) { |
42 | cl->set_incomplete(); |
43 | break; |
44 | } |
45 | } |
46 | } |
47 | |
48 | #ifndef PRODUCT |
49 | void G1CollectionSetCandidates::verify() const { |
50 | guarantee(_front_idx <= _num_regions, "Index: %u Num_regions: %u" , _front_idx, _num_regions); |
51 | uint idx = _front_idx; |
52 | size_t sum_of_reclaimable_bytes = 0; |
53 | HeapRegion *prev = NULL; |
54 | for (; idx < _num_regions; idx++) { |
55 | HeapRegion *cur = _regions[idx]; |
56 | guarantee(cur != NULL, "Regions after _front_idx %u cannot be NULL but %u is" , _front_idx, idx); |
57 | guarantee(G1CollectionSetChooser::should_add(cur), "Region %u should be eligible for addition." , cur->hrm_index()); |
58 | if (prev != NULL) { |
59 | guarantee(prev->gc_efficiency() >= cur->gc_efficiency(), |
60 | "GC efficiency for region %u: %1.4f smaller than for region %u: %1.4f" , |
61 | prev->hrm_index(), prev->gc_efficiency(), cur->hrm_index(), cur->gc_efficiency()); |
62 | } |
63 | sum_of_reclaimable_bytes += cur->reclaimable_bytes(); |
64 | prev = cur; |
65 | } |
66 | guarantee(sum_of_reclaimable_bytes == _remaining_reclaimable_bytes, |
67 | "Inconsistent remaining_reclaimable bytes, remaining " SIZE_FORMAT " calculated " SIZE_FORMAT, |
68 | _remaining_reclaimable_bytes, sum_of_reclaimable_bytes); |
69 | } |
70 | #endif // !PRODUCT |
71 | |