63 uint _count;
64
65 // When we set up a new active region we save its used bytes in this
66 // field so that, when we retire it, we can calculate how much space
67 // we allocated in it.
68 size_t _used_bytes_before;
69
70 // When true, indicates that allocate calls should do BOT updates.
71 const bool _bot_updates;
72
73 // Useful for debugging and tracing.
74 const char* _name;
75
76 // A dummy region (i.e., it's been allocated specially for this
77 // purpose and it is not part of the heap) that is full (i.e., top()
78 // == end()). When we don't have a valid active region we make
79 // _alloc_region point to this. This allows us to skip checking
80 // whether the _alloc_region is NULL or not.
81 static HeapRegion* _dummy_region;
82
83 // Perform a non-MT-safe allocation out of the given region.
84 inline HeapWord* allocate(HeapRegion* alloc_region,
85 size_t word_size);
86
87 // Perform a MT-safe allocation out of the given region.
88 inline HeapWord* par_allocate(HeapRegion* alloc_region,
89 size_t word_size);
90 // Perform a MT-safe allocation out of the given region, with the given
91 // minimum and desired size. Returns the actual size allocated (between
92 // minimum and desired size) in actual_word_size if the allocation has been
93 // successful.
94 inline HeapWord* par_allocate(HeapRegion* alloc_region,
95 size_t min_word_size,
96 size_t desired_word_size,
97 size_t* actual_word_size);
98
99 // Ensure that the region passed as a parameter has been filled up
100 // so that noone else can allocate out of it any more.
101 // Returns the number of bytes that have been wasted by filled up
102 // the space.
103 size_t fill_up_remaining_space(HeapRegion* alloc_region);
104
105 // After a region is allocated by alloc_new_region, this
106 // method is used to set it as the active alloc_region
107 void update_alloc_region(HeapRegion* alloc_region);
108
109 // Allocate a new active region and use it to perform a word_size
110 // allocation. The force parameter will be passed on to
111 // G1CollectedHeap::allocate_new_alloc_region() and tells it to try
112 // to allocate a new region even if the max has been reached.
113 HeapWord* new_alloc_region_and_allocate(size_t word_size, bool force);
114
115 protected:
116 // Retire the active allocating region. If fill_up is true then make
117 // sure that the region is full before we retire it so that no one
118 // else can allocate out of it.
119 // Returns the number of bytes that have been filled up during retire.
120 virtual size_t retire(bool fill_up);
121
122 // For convenience as subclasses use it.
123 static G1CollectedHeap* _g1h;
124
125 virtual HeapRegion* allocate_new_region(size_t word_size, bool force) = 0;
126 virtual void retire_region(HeapRegion* alloc_region,
127 size_t allocated_bytes) = 0;
128
129 G1AllocRegion(const char* name, bool bot_updates);
130
131 public:
132 static void setup(G1CollectedHeap* g1h, HeapRegion* dummy_region);
133
134 HeapRegion* get() const {
135 HeapRegion * hr = _alloc_region;
136 // Make sure that the dummy region does not escape this class.
137 return (hr == _dummy_region) ? NULL : hr;
138 }
139
140 uint count() { return _count; }
141
160 // region or, if it's unable to, it will try to replace the active
161 // alloc region with a new one. We require that the caller takes the
162 // appropriate lock before calling this so that it is easier to make
163 // it conform to its locking protocol.
164 inline HeapWord* attempt_allocation_locked(size_t word_size);
165 // Same as attempt_allocation_locked(size_t, bool), but allowing specification
166 // of minimum word size of the block in min_word_size, and the maximum word
167 // size of the allocation in desired_word_size. The actual size of the block is
168 // returned in actual_word_size.
169 inline HeapWord* attempt_allocation_locked(size_t min_word_size,
170 size_t desired_word_size,
171 size_t* actual_word_size);
172
173 // Should be called to allocate a new region even if the max of this
174 // type of regions has been reached. Should only be called if other
175 // allocation attempts have failed and we are not holding a valid
176 // active region.
177 inline HeapWord* attempt_allocation_force(size_t word_size);
178
179 // Should be called before we start using this object.
180 void init();
181
182 // This can be used to set the active region to a specific
183 // region. (Use Example: we try to retain the last old GC alloc
184 // region that we've used during a GC and we can use set() to
185 // re-instate it at the beginning of the next GC.)
186 void set(HeapRegion* alloc_region);
187
188 // Should be called when we want to release the active region which
189 // is returned after it's been retired.
190 virtual HeapRegion* release();
191
192 void trace(const char* str,
193 size_t min_word_size = 0,
194 size_t desired_word_size = 0,
195 size_t actual_word_size = 0,
196 HeapWord* result = NULL) PRODUCT_RETURN;
197 };
198
199 class MutatorAllocRegion : public G1AllocRegion {
200 protected:
201 virtual HeapRegion* allocate_new_region(size_t word_size, bool force);
202 virtual void retire_region(HeapRegion* alloc_region, size_t allocated_bytes);
203 public:
204 MutatorAllocRegion()
205 : G1AllocRegion("Mutator Alloc Region", false /* bot_updates */) { }
206 };
207
208 // Common base class for allocation regions used during GC.
209 class G1GCAllocRegion : public G1AllocRegion {
210 protected:
211 G1EvacStats* _stats;
212 InCSetState::in_cset_state_t _purpose;
213
214 virtual HeapRegion* allocate_new_region(size_t word_size, bool force);
215 virtual void retire_region(HeapRegion* alloc_region, size_t allocated_bytes);
216
217 virtual size_t retire(bool fill_up);
218
219 G1GCAllocRegion(const char* name, bool bot_updates, G1EvacStats* stats, InCSetState::in_cset_state_t purpose)
220 : G1AllocRegion(name, bot_updates), _stats(stats), _purpose(purpose) {
221 assert(stats != NULL, "Must pass non-NULL PLAB statistics");
222 }
223 };
224
225 class SurvivorGCAllocRegion : public G1GCAllocRegion {
226 public:
227 SurvivorGCAllocRegion(G1EvacStats* stats)
|
63 uint _count;
64
65 // When we set up a new active region we save its used bytes in this
66 // field so that, when we retire it, we can calculate how much space
67 // we allocated in it.
68 size_t _used_bytes_before;
69
70 // When true, indicates that allocate calls should do BOT updates.
71 const bool _bot_updates;
72
73 // Useful for debugging and tracing.
74 const char* _name;
75
76 // A dummy region (i.e., it's been allocated specially for this
77 // purpose and it is not part of the heap) that is full (i.e., top()
78 // == end()). When we don't have a valid active region we make
79 // _alloc_region point to this. This allows us to skip checking
80 // whether the _alloc_region is NULL or not.
81 static HeapRegion* _dummy_region;
82
83 // After a region is allocated by alloc_new_region, this
84 // method is used to set it as the active alloc_region
85 void update_alloc_region(HeapRegion* alloc_region);
86
87 // Allocate a new active region and use it to perform a word_size
88 // allocation. The force parameter will be passed on to
89 // G1CollectedHeap::allocate_new_alloc_region() and tells it to try
90 // to allocate a new region even if the max has been reached.
91 HeapWord* new_alloc_region_and_allocate(size_t word_size, bool force);
92
93 protected:
94 // Reset the alloc region to point a the dummy region.
95 void reset_alloc_region();
96
97 // Perform a non-MT-safe allocation out of the given region.
98 inline HeapWord* allocate(HeapRegion* alloc_region,
99 size_t word_size);
100
101 // Perform a MT-safe allocation out of the given region.
102 inline HeapWord* par_allocate(HeapRegion* alloc_region,
103 size_t word_size);
104 // Perform a MT-safe allocation out of the given region, with the given
105 // minimum and desired size. Returns the actual size allocated (between
106 // minimum and desired size) in actual_word_size if the allocation has been
107 // successful.
108 inline HeapWord* par_allocate(HeapRegion* alloc_region,
109 size_t min_word_size,
110 size_t desired_word_size,
111 size_t* actual_word_size);
112
113 // Ensure that the region passed as a parameter has been filled up
114 // so that noone else can allocate out of it any more.
115 // Returns the number of bytes that have been wasted by filled up
116 // the space.
117 size_t fill_up_remaining_space(HeapRegion* alloc_region);
118
119 // Retire the active allocating region. If fill_up is true then make
120 // sure that the region is full before we retire it so that no one
121 // else can allocate out of it.
122 // Returns the number of bytes that have been filled up during retire.
123 virtual size_t retire(bool fill_up);
124
125 size_t retire_internal(HeapRegion* alloc_region, bool fill_up);
126
127 // For convenience as subclasses use it.
128 static G1CollectedHeap* _g1h;
129
130 virtual HeapRegion* allocate_new_region(size_t word_size, bool force) = 0;
131 virtual void retire_region(HeapRegion* alloc_region,
132 size_t allocated_bytes) = 0;
133
134 G1AllocRegion(const char* name, bool bot_updates);
135
136 public:
137 static void setup(G1CollectedHeap* g1h, HeapRegion* dummy_region);
138
139 HeapRegion* get() const {
140 HeapRegion * hr = _alloc_region;
141 // Make sure that the dummy region does not escape this class.
142 return (hr == _dummy_region) ? NULL : hr;
143 }
144
145 uint count() { return _count; }
146
165 // region or, if it's unable to, it will try to replace the active
166 // alloc region with a new one. We require that the caller takes the
167 // appropriate lock before calling this so that it is easier to make
168 // it conform to its locking protocol.
169 inline HeapWord* attempt_allocation_locked(size_t word_size);
170 // Same as attempt_allocation_locked(size_t, bool), but allowing specification
171 // of minimum word size of the block in min_word_size, and the maximum word
172 // size of the allocation in desired_word_size. The actual size of the block is
173 // returned in actual_word_size.
174 inline HeapWord* attempt_allocation_locked(size_t min_word_size,
175 size_t desired_word_size,
176 size_t* actual_word_size);
177
178 // Should be called to allocate a new region even if the max of this
179 // type of regions has been reached. Should only be called if other
180 // allocation attempts have failed and we are not holding a valid
181 // active region.
182 inline HeapWord* attempt_allocation_force(size_t word_size);
183
184 // Should be called before we start using this object.
185 virtual void init();
186
187 // This can be used to set the active region to a specific
188 // region. (Use Example: we try to retain the last old GC alloc
189 // region that we've used during a GC and we can use set() to
190 // re-instate it at the beginning of the next GC.)
191 void set(HeapRegion* alloc_region);
192
193 // Should be called when we want to release the active region which
194 // is returned after it's been retired.
195 virtual HeapRegion* release();
196
197 void trace(const char* str,
198 size_t min_word_size = 0,
199 size_t desired_word_size = 0,
200 size_t actual_word_size = 0,
201 HeapWord* result = NULL) PRODUCT_RETURN;
202 };
203
204 class MutatorAllocRegion : public G1AllocRegion {
205 private:
206 // Keeps track of the total waste generated during the current
207 // mutator phase.
208 size_t _wasted_bytes;
209
210 // Retained allocation region. Used to lower the waste generated
211 // during mutation by having two active regions if the free space
212 // in a region about to be retired still could fit a TLAB.
213 HeapRegion* volatile _retained_alloc_region;
214
215 // Decide if the region should be retained, based on the free size
216 // in it and the free size in the currently retained region, if any.
217 bool should_retain(HeapRegion* region);
218 protected:
219 virtual HeapRegion* allocate_new_region(size_t word_size, bool force);
220 virtual void retire_region(HeapRegion* alloc_region, size_t allocated_bytes);
221 virtual size_t retire(bool fill_up);
222 public:
223 MutatorAllocRegion()
224 : G1AllocRegion("Mutator Alloc Region", false /* bot_updates */),
225 _wasted_bytes(0),
226 _retained_alloc_region(NULL) { }
227
228 // Returns the combined used memory in the current alloc region and
229 // the retained alloc region.
230 size_t used_in_alloc_regions();
231
232 // Perform an allocation out of the retained allocation region, with the given
233 // minimum and desired size. Returns the actual size allocated (between
234 // minimum and desired size) in actual_word_size if the allocation has been
235 // successful.
236 // Should be called without holding a lock. It will try to allocate lock-free
237 // out of the retained region, or return NULL if it was unable to.
238 inline HeapWord* attempt_retained_allocation(size_t min_word_size,
239 size_t desired_word_size,
240 size_t* actual_word_size);
241
242 // This specialization of release() makes sure that the retained alloc
243 // region is retired and set to NULL.
244 virtual HeapRegion* release();
245
246 virtual void init();
247 };
248 // Common base class for allocation regions used during GC.
249 class G1GCAllocRegion : public G1AllocRegion {
250 protected:
251 G1EvacStats* _stats;
252 InCSetState::in_cset_state_t _purpose;
253
254 virtual HeapRegion* allocate_new_region(size_t word_size, bool force);
255 virtual void retire_region(HeapRegion* alloc_region, size_t allocated_bytes);
256
257 virtual size_t retire(bool fill_up);
258
259 G1GCAllocRegion(const char* name, bool bot_updates, G1EvacStats* stats, InCSetState::in_cset_state_t purpose)
260 : G1AllocRegion(name, bot_updates), _stats(stats), _purpose(purpose) {
261 assert(stats != NULL, "Must pass non-NULL PLAB statistics");
262 }
263 };
264
265 class SurvivorGCAllocRegion : public G1GCAllocRegion {
266 public:
267 SurvivorGCAllocRegion(G1EvacStats* stats)
|