Mon, 02 Jul 2012 13:11:28 -0400
Merge
ysr@777 | 1 | /* |
tonyp@3539 | 2 | * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. |
ysr@777 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ysr@777 | 4 | * |
ysr@777 | 5 | * This code is free software; you can redistribute it and/or modify it |
ysr@777 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ysr@777 | 7 | * published by the Free Software Foundation. |
ysr@777 | 8 | * |
ysr@777 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
ysr@777 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ysr@777 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ysr@777 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
ysr@777 | 13 | * accompanied this code). |
ysr@777 | 14 | * |
ysr@777 | 15 | * You should have received a copy of the GNU General Public License version |
ysr@777 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
ysr@777 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ysr@777 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
ysr@777 | 22 | * |
ysr@777 | 23 | */ |
ysr@777 | 24 | |
stefank@2314 | 25 | #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_COLLECTIONSETCHOOSER_HPP |
stefank@2314 | 26 | #define SHARE_VM_GC_IMPLEMENTATION_G1_COLLECTIONSETCHOOSER_HPP |
stefank@2314 | 27 | |
stefank@2314 | 28 | #include "gc_implementation/g1/heapRegion.hpp" |
stefank@2314 | 29 | #include "utilities/growableArray.hpp" |
stefank@2314 | 30 | |
zgu@3900 | 31 | class CollectionSetChooser: public CHeapObj<mtGC> { |
ysr@777 | 32 | |
tonyp@3714 | 33 | GrowableArray<HeapRegion*> _regions; |
tonyp@3714 | 34 | |
tonyp@3714 | 35 | // Unfortunately, GrowableArray uses ints for length and indexes. To |
tonyp@3714 | 36 | // avoid excessive casting in the rest of the class the following |
tonyp@3714 | 37 | // wrapper methods are provided that use uints. |
tonyp@3714 | 38 | |
tonyp@3714 | 39 | uint regions_length() { return (uint) _regions.length(); } |
tonyp@3714 | 40 | HeapRegion* regions_at(uint i) { return _regions.at((int) i); } |
tonyp@3714 | 41 | void regions_at_put(uint i, HeapRegion* hr) { |
tonyp@3714 | 42 | _regions.at_put((int) i, hr); |
tonyp@3714 | 43 | } |
tonyp@3714 | 44 | void regions_at_put_grow(uint i, HeapRegion* hr) { |
tonyp@3714 | 45 | _regions.at_put_grow((int) i, hr); |
tonyp@3714 | 46 | } |
tonyp@3714 | 47 | void regions_trunc_to(uint i) { _regions.trunc_to((uint) i); } |
tonyp@3539 | 48 | |
tonyp@3539 | 49 | // The index of the next candidate old region to be considered for |
tonyp@3539 | 50 | // addition to the CSet. |
tonyp@3714 | 51 | uint _curr_index; |
tonyp@3539 | 52 | |
tonyp@3539 | 53 | // The number of candidate old regions added to the CSet chooser. |
tonyp@3714 | 54 | uint _length; |
tonyp@3539 | 55 | |
tonyp@3714 | 56 | // Keeps track of the start of the next array chunk to be claimed by |
tonyp@3714 | 57 | // parallel GC workers. |
tonyp@3714 | 58 | uint _first_par_unreserved_idx; |
ysr@777 | 59 | |
tonyp@3539 | 60 | // If a region has more live bytes than this threshold, it will not |
tonyp@3539 | 61 | // be added to the CSet chooser and will not be a candidate for |
tonyp@3539 | 62 | // collection. |
tonyp@3714 | 63 | size_t _region_live_threshold_bytes; |
ysr@777 | 64 | |
tonyp@3539 | 65 | // The sum of reclaimable bytes over all the regions in the CSet chooser. |
tonyp@3714 | 66 | size_t _remaining_reclaimable_bytes; |
ysr@777 | 67 | |
ysr@777 | 68 | public: |
ysr@777 | 69 | |
tonyp@3539 | 70 | // Return the current candidate region to be considered for |
tonyp@3539 | 71 | // collection without removing it from the CSet chooser. |
tonyp@3539 | 72 | HeapRegion* peek() { |
tonyp@3539 | 73 | HeapRegion* res = NULL; |
tonyp@3539 | 74 | if (_curr_index < _length) { |
tonyp@3714 | 75 | res = regions_at(_curr_index); |
tonyp@3539 | 76 | assert(res != NULL, |
tonyp@3714 | 77 | err_msg("Unexpected NULL hr in _regions at index %u", |
tonyp@3539 | 78 | _curr_index)); |
tonyp@3539 | 79 | } |
tonyp@3539 | 80 | return res; |
tonyp@3539 | 81 | } |
tonyp@3539 | 82 | |
tonyp@3539 | 83 | // Remove the given region from the CSet chooser and move to the |
tonyp@3539 | 84 | // next one. The given region should be the current candidate region |
tonyp@3539 | 85 | // in the CSet chooser. |
tonyp@3539 | 86 | void remove_and_move_to_next(HeapRegion* hr) { |
tonyp@3539 | 87 | assert(hr != NULL, "pre-condition"); |
tonyp@3539 | 88 | assert(_curr_index < _length, "pre-condition"); |
tonyp@3714 | 89 | assert(regions_at(_curr_index) == hr, "pre-condition"); |
tonyp@3714 | 90 | regions_at_put(_curr_index, NULL); |
tonyp@3714 | 91 | assert(hr->reclaimable_bytes() <= _remaining_reclaimable_bytes, |
tonyp@3539 | 92 | err_msg("remaining reclaimable bytes inconsistent " |
tonyp@3539 | 93 | "from region: "SIZE_FORMAT" remaining: "SIZE_FORMAT, |
tonyp@3714 | 94 | hr->reclaimable_bytes(), _remaining_reclaimable_bytes)); |
tonyp@3714 | 95 | _remaining_reclaimable_bytes -= hr->reclaimable_bytes(); |
tonyp@3539 | 96 | _curr_index += 1; |
tonyp@3539 | 97 | } |
ysr@777 | 98 | |
ysr@777 | 99 | CollectionSetChooser(); |
ysr@777 | 100 | |
tonyp@3714 | 101 | void sort_regions(); |
tonyp@3539 | 102 | |
tonyp@3539 | 103 | // Determine whether to add the given region to the CSet chooser or |
tonyp@3539 | 104 | // not. Currently, we skip humongous regions (we never add them to |
tonyp@3539 | 105 | // the CSet, we only reclaim them during cleanup) and regions whose |
tonyp@3539 | 106 | // live bytes are over the threshold. |
tonyp@3714 | 107 | bool should_add(HeapRegion* hr) { |
tonyp@3539 | 108 | assert(hr->is_marked(), "pre-condition"); |
tonyp@3539 | 109 | assert(!hr->is_young(), "should never consider young regions"); |
tonyp@3539 | 110 | return !hr->isHumongous() && |
tonyp@3714 | 111 | hr->live_bytes() < _region_live_threshold_bytes; |
tonyp@3539 | 112 | } |
tonyp@3539 | 113 | |
tonyp@3539 | 114 | // Calculate the minimum number of old regions we'll add to the CSet |
tonyp@3539 | 115 | // during a mixed GC. |
tonyp@3714 | 116 | uint calc_min_old_cset_length(); |
tonyp@3539 | 117 | |
tonyp@3539 | 118 | // Calculate the maximum number of old regions we'll add to the CSet |
tonyp@3539 | 119 | // during a mixed GC. |
tonyp@3714 | 120 | uint calc_max_old_cset_length(); |
tonyp@3539 | 121 | |
tonyp@3539 | 122 | // Serial version. |
tonyp@3714 | 123 | void add_region(HeapRegion *hr); |
ysr@777 | 124 | |
tonyp@3714 | 125 | // Must be called before calls to claim_array_chunk(). |
tonyp@3714 | 126 | // n_regions is the number of regions, chunk_size the chunk size. |
tonyp@3714 | 127 | void prepare_for_par_region_addition(uint n_regions, uint chunk_size); |
tonyp@3714 | 128 | // Returns the first index in a contiguous chunk of chunk_size indexes |
ysr@777 | 129 | // that the calling thread has reserved. These must be set by the |
tonyp@3714 | 130 | // calling thread using set_region() (to NULL if necessary). |
tonyp@3714 | 131 | uint claim_array_chunk(uint chunk_size); |
ysr@777 | 132 | // Set the marked array entry at index to hr. Careful to claim the index |
ysr@777 | 133 | // first if in parallel. |
tonyp@3714 | 134 | void set_region(uint index, HeapRegion* hr); |
tonyp@3539 | 135 | // Atomically increment the number of added regions by region_num |
tonyp@3539 | 136 | // and the amount of reclaimable bytes by reclaimable_bytes. |
tonyp@3714 | 137 | void update_totals(uint region_num, size_t reclaimable_bytes); |
ysr@777 | 138 | |
tonyp@3714 | 139 | void clear(); |
ysr@777 | 140 | |
tonyp@3539 | 141 | // Return the number of candidate regions that remain to be collected. |
tonyp@3714 | 142 | uint remaining_regions() { return _length - _curr_index; } |
ysr@777 | 143 | |
tonyp@3539 | 144 | // Determine whether the CSet chooser has more candidate regions or not. |
tonyp@3714 | 145 | bool is_empty() { return remaining_regions() == 0; } |
tonyp@3539 | 146 | |
tonyp@3539 | 147 | // Return the reclaimable bytes that remain to be collected on |
tonyp@3539 | 148 | // all the candidate regions in the CSet chooser. |
tonyp@3714 | 149 | size_t remaining_reclaimable_bytes() { return _remaining_reclaimable_bytes; } |
ysr@777 | 150 | |
tonyp@3714 | 151 | // Returns true if the used portion of "_regions" is properly |
ysr@777 | 152 | // sorted, otherwise asserts false. |
tonyp@3714 | 153 | void verify() PRODUCT_RETURN; |
ysr@777 | 154 | }; |
stefank@2314 | 155 | |
stefank@2314 | 156 | #endif // SHARE_VM_GC_IMPLEMENTATION_G1_COLLECTIONSETCHOOSER_HPP |