src/share/vm/gc_implementation/g1/heapRegionSeq.hpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6198
55fb97c4c58d
parent 0
f90c822e73f8
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSEQ_HPP
aoqi@0 26 #define SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSEQ_HPP
aoqi@0 27
aoqi@0 28 #include "gc_implementation/g1/g1BiasedArray.hpp"
aoqi@0 29
aoqi@0 30 class HeapRegion;
aoqi@0 31 class HeapRegionClosure;
aoqi@0 32 class FreeRegionList;
aoqi@0 33
aoqi@0 34 class G1HeapRegionTable : public G1BiasedMappedArray<HeapRegion*> {
aoqi@0 35 protected:
aoqi@0 36 virtual HeapRegion* default_value() const { return NULL; }
aoqi@0 37 };
aoqi@0 38
aoqi@0 39 // This class keeps track of the region metadata (i.e., HeapRegion
aoqi@0 40 // instances). They are kept in the _regions array in address
aoqi@0 41 // order. A region's index in the array corresponds to its index in
aoqi@0 42 // the heap (i.e., 0 is the region at the bottom of the heap, 1 is
aoqi@0 43 // the one after it, etc.). Two regions that are consecutive in the
aoqi@0 44 // array should also be adjacent in the address space (i.e.,
aoqi@0 45 // region(i).end() == region(i+1).bottom().
aoqi@0 46 //
aoqi@0 47 // We create a HeapRegion when we commit the region's address space
aoqi@0 48 // for the first time. When we uncommit the address space of a
aoqi@0 49 // region we retain the HeapRegion to be able to re-use it in the
aoqi@0 50 // future (in case we recommit it).
aoqi@0 51 //
aoqi@0 52 // We keep track of three lengths:
aoqi@0 53 //
aoqi@0 54 // * _committed_length (returned by length()) is the number of currently
aoqi@0 55 // committed regions.
aoqi@0 56 // * _allocated_length (not exposed outside this class) is the
aoqi@0 57 // number of regions for which we have HeapRegions.
aoqi@0 58 // * max_length() returns the maximum number of regions the heap can have.
aoqi@0 59 //
aoqi@0 60 // and maintain that: _committed_length <= _allocated_length <= max_length()
aoqi@0 61
aoqi@0 62 class HeapRegionSeq: public CHeapObj<mtGC> {
aoqi@0 63 friend class VMStructs;
aoqi@0 64
aoqi@0 65 G1HeapRegionTable _regions;
aoqi@0 66
aoqi@0 67 // The number of regions committed in the heap.
aoqi@0 68 uint _committed_length;
aoqi@0 69
aoqi@0 70 // A hint for which index to start searching from for humongous
aoqi@0 71 // allocations.
aoqi@0 72 uint _next_search_index;
aoqi@0 73
aoqi@0 74 // The number of regions for which we have allocated HeapRegions for.
aoqi@0 75 uint _allocated_length;
aoqi@0 76
aoqi@0 77 // Find a contiguous set of empty regions of length num, starting
aoqi@0 78 // from the given index.
aoqi@0 79 uint find_contiguous_from(uint from, uint num);
aoqi@0 80
aoqi@0 81 void increment_allocated_length() {
aoqi@0 82 assert(_allocated_length < max_length(), "pre-condition");
aoqi@0 83 _allocated_length++;
aoqi@0 84 }
aoqi@0 85
aoqi@0 86 void increment_length() {
aoqi@0 87 assert(length() < max_length(), "pre-condition");
aoqi@0 88 _committed_length++;
aoqi@0 89 }
aoqi@0 90
aoqi@0 91 void decrement_length() {
aoqi@0 92 assert(length() > 0, "pre-condition");
aoqi@0 93 _committed_length--;
aoqi@0 94 }
aoqi@0 95
aoqi@0 96 HeapWord* heap_bottom() const { return _regions.bottom_address_mapped(); }
aoqi@0 97 HeapWord* heap_end() const {return _regions.end_address_mapped(); }
aoqi@0 98
aoqi@0 99 public:
aoqi@0 100 // Empty contructor, we'll initialize it with the initialize() method.
aoqi@0 101 HeapRegionSeq() : _regions(), _committed_length(0), _next_search_index(0), _allocated_length(0) { }
aoqi@0 102
aoqi@0 103 void initialize(HeapWord* bottom, HeapWord* end);
aoqi@0 104
aoqi@0 105 // Return the HeapRegion at the given index. Assume that the index
aoqi@0 106 // is valid.
aoqi@0 107 inline HeapRegion* at(uint index) const;
aoqi@0 108
aoqi@0 109 // If addr is within the committed space return its corresponding
aoqi@0 110 // HeapRegion, otherwise return NULL.
aoqi@0 111 inline HeapRegion* addr_to_region(HeapWord* addr) const;
aoqi@0 112
aoqi@0 113 // Return the HeapRegion that corresponds to the given
aoqi@0 114 // address. Assume the address is valid.
aoqi@0 115 inline HeapRegion* addr_to_region_unsafe(HeapWord* addr) const;
aoqi@0 116
aoqi@0 117 // Return the number of regions that have been committed in the heap.
aoqi@0 118 uint length() const { return _committed_length; }
aoqi@0 119
aoqi@0 120 // Return the maximum number of regions in the heap.
aoqi@0 121 uint max_length() const { return (uint)_regions.length(); }
aoqi@0 122
aoqi@0 123 // Expand the sequence to reflect that the heap has grown from
aoqi@0 124 // old_end to new_end. Either create new HeapRegions, or re-use
aoqi@0 125 // existing ones, and return them in the given list. Returns the
aoqi@0 126 // memory region that covers the newly-created regions. If a
aoqi@0 127 // HeapRegion allocation fails, the result memory region might be
aoqi@0 128 // smaller than the desired one.
aoqi@0 129 MemRegion expand_by(HeapWord* old_end, HeapWord* new_end,
aoqi@0 130 FreeRegionList* list);
aoqi@0 131
aoqi@0 132 // Return the number of contiguous regions at the end of the sequence
aoqi@0 133 // that are available for allocation.
aoqi@0 134 uint free_suffix();
aoqi@0 135
aoqi@0 136 // Find a contiguous set of empty regions of length num and return
aoqi@0 137 // the index of the first region or G1_NULL_HRS_INDEX if the
aoqi@0 138 // search was unsuccessful.
aoqi@0 139 uint find_contiguous(uint num);
aoqi@0 140
aoqi@0 141 // Apply blk->doHeapRegion() on all committed regions in address order,
aoqi@0 142 // terminating the iteration early if doHeapRegion() returns true.
aoqi@0 143 void iterate(HeapRegionClosure* blk) const;
aoqi@0 144
aoqi@0 145 // As above, but start the iteration from hr and loop around. If hr
aoqi@0 146 // is NULL, we start from the first region in the heap.
aoqi@0 147 void iterate_from(HeapRegion* hr, HeapRegionClosure* blk) const;
aoqi@0 148
aoqi@0 149 // Tag as uncommitted as many regions that are completely free as
aoqi@0 150 // possible, up to num_regions_to_remove, from the suffix of the committed
aoqi@0 151 // sequence. Return the actual number of removed regions.
aoqi@0 152 uint shrink_by(uint num_regions_to_remove);
aoqi@0 153
aoqi@0 154 // Do some sanity checking.
aoqi@0 155 void verify_optional() PRODUCT_RETURN;
aoqi@0 156 };
aoqi@0 157
aoqi@0 158 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSEQ_HPP

mercurial