Mercurial > hg > graal-jvmci-8
comparison src/share/vm/gc_implementation/g1/heapRegionSeq.hpp @ 12305:a19bea467577
7163191: G1: introduce a "heap spanning table" abstraction
Summary: Add G1BiasedArray<T> that is an array where each element represents a fixed-sized subdivision of the heap. Use this abstraction to refactor the HeapRegionSeq class.
Reviewed-by: brutisso
author | tschatzl |
---|---|
date | Wed, 25 Sep 2013 13:25:24 +0200 |
parents | b0d20fa374b4 |
children | de6a9e811145 |
comparison
equal
deleted
inserted
replaced
12304:10cc3b624f8f | 12305:a19bea467577 |
---|---|
23 */ | 23 */ |
24 | 24 |
25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSEQ_HPP | 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSEQ_HPP |
26 #define SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSEQ_HPP | 26 #define SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSEQ_HPP |
27 | 27 |
28 #include "gc_implementation/g1/g1BiasedArray.hpp" | |
29 | |
28 class HeapRegion; | 30 class HeapRegion; |
29 class HeapRegionClosure; | 31 class HeapRegionClosure; |
30 class FreeRegionList; | 32 class FreeRegionList; |
33 | |
34 class G1HeapRegionTable : public G1BiasedMappedArray<HeapRegion*> { | |
35 protected: | |
36 virtual HeapRegion* default_value() const { return NULL; } | |
37 }; | |
31 | 38 |
32 // This class keeps track of the region metadata (i.e., HeapRegion | 39 // This class keeps track of the region metadata (i.e., HeapRegion |
33 // instances). They are kept in the _regions array in address | 40 // instances). They are kept in the _regions array in address |
34 // order. A region's index in the array corresponds to its index in | 41 // order. A region's index in the array corresponds to its index in |
35 // the heap (i.e., 0 is the region at the bottom of the heap, 1 is | 42 // the heap (i.e., 0 is the region at the bottom of the heap, 1 is |
42 // region we retain the HeapRegion to be able to re-use it in the | 49 // region we retain the HeapRegion to be able to re-use it in the |
43 // future (in case we recommit it). | 50 // future (in case we recommit it). |
44 // | 51 // |
45 // We keep track of three lengths: | 52 // We keep track of three lengths: |
46 // | 53 // |
47 // * _length (returned by length()) is the number of currently | 54 // * _committed_length (returned by length()) is the number of currently |
48 // committed regions. | 55 // committed regions. |
49 // * _allocated_length (not exposed outside this class) is the | 56 // * _allocated_length (not exposed outside this class) is the |
50 // number of regions for which we have HeapRegions. | 57 // number of regions for which we have HeapRegions. |
51 // * _max_length (returned by max_length()) is the maximum number of | 58 // * max_length() returns the maximum number of regions the heap can have. |
52 // regions the heap can have. | |
53 // | 59 // |
54 // and maintain that: _length <= _allocated_length <= _max_length | 60 // and maintain that: _committed_length <= _allocated_length <= max_length() |
55 | 61 |
56 class HeapRegionSeq: public CHeapObj<mtGC> { | 62 class HeapRegionSeq: public CHeapObj<mtGC> { |
57 friend class VMStructs; | 63 friend class VMStructs; |
58 | 64 |
59 // The array that holds the HeapRegions. | 65 G1HeapRegionTable _regions; |
60 HeapRegion** _regions; | |
61 | |
62 // Version of _regions biased to address 0 | |
63 HeapRegion** _regions_biased; | |
64 | 66 |
65 // The number of regions committed in the heap. | 67 // The number of regions committed in the heap. |
66 uint _length; | 68 uint _committed_length; |
67 | |
68 // The address of the first reserved word in the heap. | |
69 HeapWord* _heap_bottom; | |
70 | |
71 // The address of the last reserved word in the heap - 1. | |
72 HeapWord* _heap_end; | |
73 | |
74 // The log of the region byte size. | |
75 uint _region_shift; | |
76 | 69 |
77 // A hint for which index to start searching from for humongous | 70 // A hint for which index to start searching from for humongous |
78 // allocations. | 71 // allocations. |
79 uint _next_search_index; | 72 uint _next_search_index; |
80 | 73 |
81 // The number of regions for which we have allocated HeapRegions for. | 74 // The number of regions for which we have allocated HeapRegions for. |
82 uint _allocated_length; | 75 uint _allocated_length; |
83 | 76 |
84 // The maximum number of regions in the heap. | |
85 uint _max_length; | |
86 | |
87 // Find a contiguous set of empty regions of length num, starting | 77 // Find a contiguous set of empty regions of length num, starting |
88 // from the given index. | 78 // from the given index. |
89 uint find_contiguous_from(uint from, uint num); | 79 uint find_contiguous_from(uint from, uint num); |
90 | 80 |
91 // Map a heap address to a biased region index. Assume that the | |
92 // address is valid. | |
93 inline uintx addr_to_index_biased(HeapWord* addr) const; | |
94 | |
95 void increment_allocated_length() { | 81 void increment_allocated_length() { |
96 assert(_allocated_length < _max_length, "pre-condition"); | 82 assert(_allocated_length < max_length(), "pre-condition"); |
97 _allocated_length++; | 83 _allocated_length++; |
98 } | 84 } |
99 | 85 |
100 void increment_length() { | 86 void increment_length() { |
101 assert(_length < _max_length, "pre-condition"); | 87 assert(length() < max_length(), "pre-condition"); |
102 _length++; | 88 _committed_length++; |
103 } | 89 } |
104 | 90 |
105 void decrement_length() { | 91 void decrement_length() { |
106 assert(_length > 0, "pre-condition"); | 92 assert(length() > 0, "pre-condition"); |
107 _length--; | 93 _committed_length--; |
108 } | 94 } |
95 | |
96 HeapWord* heap_bottom() const { return _regions.bottom_address_mapped(); } | |
97 HeapWord* heap_end() const {return _regions.end_address_mapped(); } | |
109 | 98 |
110 public: | 99 public: |
111 // Empty contructor, we'll initialize it with the initialize() method. | 100 // Empty contructor, we'll initialize it with the initialize() method. |
112 HeapRegionSeq() { } | 101 HeapRegionSeq() : _regions(), _committed_length(0), _next_search_index(0), _allocated_length(0) { } |
113 | 102 |
114 void initialize(HeapWord* bottom, HeapWord* end, uint max_length); | 103 void initialize(HeapWord* bottom, HeapWord* end); |
115 | 104 |
116 // Return the HeapRegion at the given index. Assume that the index | 105 // Return the HeapRegion at the given index. Assume that the index |
117 // is valid. | 106 // is valid. |
118 inline HeapRegion* at(uint index) const; | 107 inline HeapRegion* at(uint index) const; |
119 | 108 |
124 // Return the HeapRegion that corresponds to the given | 113 // Return the HeapRegion that corresponds to the given |
125 // address. Assume the address is valid. | 114 // address. Assume the address is valid. |
126 inline HeapRegion* addr_to_region_unsafe(HeapWord* addr) const; | 115 inline HeapRegion* addr_to_region_unsafe(HeapWord* addr) const; |
127 | 116 |
128 // Return the number of regions that have been committed in the heap. | 117 // Return the number of regions that have been committed in the heap. |
129 uint length() const { return _length; } | 118 uint length() const { return _committed_length; } |
130 | 119 |
131 // Return the maximum number of regions in the heap. | 120 // Return the maximum number of regions in the heap. |
132 uint max_length() const { return _max_length; } | 121 uint max_length() const { return (uint)_regions.length(); } |
133 | 122 |
134 // Expand the sequence to reflect that the heap has grown from | 123 // Expand the sequence to reflect that the heap has grown from |
135 // old_end to new_end. Either create new HeapRegions, or re-use | 124 // old_end to new_end. Either create new HeapRegions, or re-use |
136 // existing ones, and return them in the given list. Returns the | 125 // existing ones, and return them in the given list. Returns the |
137 // memory region that covers the newly-created regions. If a | 126 // memory region that covers the newly-created regions. If a |