1 /*
2 * Copyright (c) 2001, 2013, 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 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONMANAGER_HPP
26 #define SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONMANAGER_HPP
27
28 #include "gc_implementation/g1/g1BiasedArray.hpp"
29 #include "gc_implementation/g1/g1RegionToSpaceMapper.hpp"
30 #include "gc_implementation/g1/heapRegionSet.hpp"
31
32 class HeapRegion;
33 class HeapRegionClosure;
34 class HeapRegionClaimer;
35 class FreeRegionList;
36
37 class G1HeapRegionTable : public G1BiasedMappedArray<HeapRegion*> {
38 protected:
39 virtual HeapRegion* default_value() const { return NULL; }
40 };
41
42 // This class keeps track of the actual heap memory, auxiliary data
43 // and its metadata (i.e., HeapRegion instances) and the list of free regions.
44 //
45 // This allows maximum flexibility for deciding what to commit or uncommit given
46 // a request from outside.
47 //
48 // HeapRegions are kept in the _regions array in address order. A region's
49 // index in the array corresponds to its index in the heap (i.e., 0 is the
50 // region at the bottom of the heap, 1 is the one after it, etc.). Two
178 _free_list.remove_all();
179 }
180
181 // Return the number of committed free regions in the heap.
182 uint num_free_regions() const {
183 return _free_list.length();
184 }
185
186 size_t total_capacity_bytes() const {
187 return num_free_regions() * HeapRegion::GrainBytes;
188 }
189
190 // Return the number of available (uncommitted) regions.
191 uint available() const { return max_length() - length(); }
192
193 // Return the number of regions that have been committed in the heap.
194 uint length() const { return _num_committed; }
195
196 // Return the maximum number of regions in the heap.
197 uint max_length() const { return (uint)_regions.length(); }
198
199 MemRegion reserved() const { return MemRegion(heap_bottom(), heap_end()); }
200
201 // Expand the sequence to reflect that the heap has grown. Either create new
202 // HeapRegions, or re-use existing ones. Returns the number of regions the
203 // sequence was expanded by. If a HeapRegion allocation fails, the resulting
204 // number of regions might be smaller than what's desired.
205 uint expand_by(uint num_regions);
206
207 // Makes sure that the regions from start to start+num_regions-1 are available
208 // for allocation. Returns the number of regions that were committed to achieve
209 // this.
210 uint expand_at(uint start, uint num_regions);
211
212 // Find a contiguous set of empty regions of length num. Returns the start index of
213 // that set, or G1_NO_HRM_INDEX.
214 uint find_contiguous_only_empty(size_t num) { return find_contiguous(num, true); }
215 // Find a contiguous set of empty or unavailable regions of length num. Returns the
216 // start index of that set, or G1_NO_HRM_INDEX.
217 uint find_contiguous_empty_or_unavailable(size_t num) { return find_contiguous(num, false); }
|
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 *
23 */
24
25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONMANAGER_HPP
26 #define SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONMANAGER_HPP
27
28 #include "gc_implementation/g1/g1BiasedArray.hpp"
29 #include "gc_implementation/g1/g1RegionToSpaceMapper.hpp"
30 #include "gc_implementation/g1/heapRegionSet.hpp"
31 #include "services/memoryUsage.hpp"
32
33 class HeapRegion;
34 class HeapRegionClosure;
35 class HeapRegionClaimer;
36 class FreeRegionList;
37
38 class G1HeapRegionTable : public G1BiasedMappedArray<HeapRegion*> {
39 protected:
40 virtual HeapRegion* default_value() const { return NULL; }
41 };
42
43 // This class keeps track of the actual heap memory, auxiliary data
44 // and its metadata (i.e., HeapRegion instances) and the list of free regions.
45 //
46 // This allows maximum flexibility for deciding what to commit or uncommit given
47 // a request from outside.
48 //
49 // HeapRegions are kept in the _regions array in address order. A region's
50 // index in the array corresponds to its index in the heap (i.e., 0 is the
51 // region at the bottom of the heap, 1 is the one after it, etc.). Two
179 _free_list.remove_all();
180 }
181
182 // Return the number of committed free regions in the heap.
183 uint num_free_regions() const {
184 return _free_list.length();
185 }
186
187 size_t total_capacity_bytes() const {
188 return num_free_regions() * HeapRegion::GrainBytes;
189 }
190
191 // Return the number of available (uncommitted) regions.
192 uint available() const { return max_length() - length(); }
193
194 // Return the number of regions that have been committed in the heap.
195 uint length() const { return _num_committed; }
196
197 // Return the maximum number of regions in the heap.
198 uint max_length() const { return (uint)_regions.length(); }
199
200 MemoryUsage get_auxiliary_data_memory_usage() const;
201
202 MemRegion reserved() const { return MemRegion(heap_bottom(), heap_end()); }
203
204 // Expand the sequence to reflect that the heap has grown. Either create new
205 // HeapRegions, or re-use existing ones. Returns the number of regions the
206 // sequence was expanded by. If a HeapRegion allocation fails, the resulting
207 // number of regions might be smaller than what's desired.
208 uint expand_by(uint num_regions);
209
210 // Makes sure that the regions from start to start+num_regions-1 are available
211 // for allocation. Returns the number of regions that were committed to achieve
212 // this.
213 uint expand_at(uint start, uint num_regions);
214
215 // Find a contiguous set of empty regions of length num. Returns the start index of
216 // that set, or G1_NO_HRM_INDEX.
217 uint find_contiguous_only_empty(size_t num) { return find_contiguous(num, true); }
218 // Find a contiguous set of empty or unavailable regions of length num. Returns the
219 // start index of that set, or G1_NO_HRM_INDEX.
220 uint find_contiguous_empty_or_unavailable(size_t num) { return find_contiguous(num, false); }
|