87 // == end()). When we don't have a valid active region we make
88 // _alloc_region point to this. This allows us to skip checking
89 // whether the _alloc_region is NULL or not.
90 static HeapRegion* _dummy_region;
91
92 // Some of the methods below take a bot_updates parameter. Its value
93 // should be the same as the _bot_updates field. The idea is that
94 // the parameter will be a constant for a particular alloc region
95 // and, given that these methods will be hopefully inlined, the
96 // compiler should compile out the test.
97
98 // Perform a non-MT-safe allocation out of the given region.
99 static inline HeapWord* allocate(HeapRegion* alloc_region,
100 size_t word_size,
101 bool bot_updates);
102
103 // Perform a MT-safe allocation out of the given region.
104 static inline HeapWord* par_allocate(HeapRegion* alloc_region,
105 size_t word_size,
106 bool bot_updates);
107
108 // Ensure that the region passed as a parameter has been filled up
109 // so that noone else can allocate out of it any more.
110 // Returns the number of bytes that have been wasted by filled up
111 // the space.
112 static size_t fill_up_remaining_space(HeapRegion* alloc_region,
113 bool bot_updates);
114
115 // After a region is allocated by alloc_new_region, this
116 // method is used to set it as the active alloc_region
117 void update_alloc_region(HeapRegion* alloc_region);
118
119 // Allocate a new active region and use it to perform a word_size
120 // allocation. The force parameter will be passed on to
121 // G1CollectedHeap::allocate_new_alloc_region() and tells it to try
122 // to allocate a new region even if the max has been reached.
123 HeapWord* new_alloc_region_and_allocate(size_t word_size, bool force);
124
125 void fill_in_ext_msg(ar_ext_msg* msg, const char* message);
126
142
143 public:
144 static void setup(G1CollectedHeap* g1h, HeapRegion* dummy_region);
145
146 HeapRegion* get() const {
147 HeapRegion * hr = _alloc_region;
148 // Make sure that the dummy region does not escape this class.
149 return (hr == _dummy_region) ? NULL : hr;
150 }
151
152 void set_allocation_context(AllocationContext_t context) { _allocation_context = context; }
153 AllocationContext_t allocation_context() { return _allocation_context; }
154
155 uint count() { return _count; }
156
157 // The following two are the building blocks for the allocation method.
158
159 // First-level allocation: Should be called without holding a
160 // lock. It will try to allocate lock-free out of the active region,
161 // or return NULL if it was unable to.
162 inline HeapWord* attempt_allocation(size_t word_size, bool bot_updates);
163
164 // Second-level allocation: Should be called while holding a
165 // lock. It will try to first allocate lock-free out of the active
166 // region or, if it's unable to, it will try to replace the active
167 // alloc region with a new one. We require that the caller takes the
168 // appropriate lock before calling this so that it is easier to make
169 // it conform to its locking protocol.
170 inline HeapWord* attempt_allocation_locked(size_t word_size,
171 bool bot_updates);
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 bool bot_updates);
179
180 // Should be called before we start using this object.
181 void init();
182
183 // This can be used to set the active region to a specific
184 // region. (Use Example: we try to retain the last old GC alloc
185 // region that we've used during a GC and we can use set() to
186 // re-instate it at the beginning of the next GC.)
187 void set(HeapRegion* alloc_region);
188
189 // Should be called when we want to release the active region which
190 // is returned after it's been retired.
191 virtual HeapRegion* release();
192
193 #if G1_ALLOC_REGION_TRACING
194 void trace(const char* str, size_t word_size = 0, HeapWord* result = NULL);
195 #else // G1_ALLOC_REGION_TRACING
196 void trace(const char* str, size_t word_size = 0, HeapWord* result = NULL) { }
197 #endif // G1_ALLOC_REGION_TRACING
198 };
199
200 class MutatorAllocRegion : public G1AllocRegion {
201 protected:
202 virtual HeapRegion* allocate_new_region(size_t word_size, bool force);
203 virtual void retire_region(HeapRegion* alloc_region, size_t allocated_bytes);
204 public:
205 MutatorAllocRegion()
206 : G1AllocRegion("Mutator Alloc Region", false /* bot_updates */) { }
207 };
208
209 // Common base class for allocation regions used during GC.
210 class G1GCAllocRegion : public G1AllocRegion {
211 protected:
212 G1EvacStats* _stats;
213 InCSetState::in_cset_state_t _purpose;
214
215 virtual HeapRegion* allocate_new_region(size_t word_size, bool force);
216 virtual void retire_region(HeapRegion* alloc_region, size_t allocated_bytes);
|
87 // == end()). When we don't have a valid active region we make
88 // _alloc_region point to this. This allows us to skip checking
89 // whether the _alloc_region is NULL or not.
90 static HeapRegion* _dummy_region;
91
92 // Some of the methods below take a bot_updates parameter. Its value
93 // should be the same as the _bot_updates field. The idea is that
94 // the parameter will be a constant for a particular alloc region
95 // and, given that these methods will be hopefully inlined, the
96 // compiler should compile out the test.
97
98 // Perform a non-MT-safe allocation out of the given region.
99 static inline HeapWord* allocate(HeapRegion* alloc_region,
100 size_t word_size,
101 bool bot_updates);
102
103 // Perform a MT-safe allocation out of the given region.
104 static inline HeapWord* par_allocate(HeapRegion* alloc_region,
105 size_t word_size,
106 bool bot_updates);
107 // Perform a MT-safe allocation out of the given region, with the given
108 // minimum and desired size. Returns the actual size allocated (between
109 // minimum and desired size) in actual_word_size if the allocation has been
110 // successful.
111 static inline HeapWord* par_allocate(HeapRegion* alloc_region,
112 size_t min_word_size,
113 size_t desired_word_size,
114 size_t* actual_word_size,
115 bool bot_updates);
116
117 // Ensure that the region passed as a parameter has been filled up
118 // so that noone else can allocate out of it any more.
119 // Returns the number of bytes that have been wasted by filled up
120 // the space.
121 static size_t fill_up_remaining_space(HeapRegion* alloc_region,
122 bool bot_updates);
123
124 // After a region is allocated by alloc_new_region, this
125 // method is used to set it as the active alloc_region
126 void update_alloc_region(HeapRegion* alloc_region);
127
128 // Allocate a new active region and use it to perform a word_size
129 // allocation. The force parameter will be passed on to
130 // G1CollectedHeap::allocate_new_alloc_region() and tells it to try
131 // to allocate a new region even if the max has been reached.
132 HeapWord* new_alloc_region_and_allocate(size_t word_size, bool force);
133
134 void fill_in_ext_msg(ar_ext_msg* msg, const char* message);
135
151
152 public:
153 static void setup(G1CollectedHeap* g1h, HeapRegion* dummy_region);
154
155 HeapRegion* get() const {
156 HeapRegion * hr = _alloc_region;
157 // Make sure that the dummy region does not escape this class.
158 return (hr == _dummy_region) ? NULL : hr;
159 }
160
161 void set_allocation_context(AllocationContext_t context) { _allocation_context = context; }
162 AllocationContext_t allocation_context() { return _allocation_context; }
163
164 uint count() { return _count; }
165
166 // The following two are the building blocks for the allocation method.
167
168 // First-level allocation: Should be called without holding a
169 // lock. It will try to allocate lock-free out of the active region,
170 // or return NULL if it was unable to.
171 inline HeapWord* attempt_allocation(size_t word_size,
172 bool bot_updates);
173 // Perform an allocation out of the current allocation region, with the given
174 // minimum and desired size. Returns the actual size allocated (between
175 // minimum and desired size) in actual_word_size if the allocation has been
176 // successful.
177 // Should be called without holding a lock. It will try to allocate lock-free
178 // out of the active region, or return NULL if it was unable to.
179 inline HeapWord* attempt_allocation(size_t min_word_size,
180 size_t desired_word_size,
181 size_t* actual_word_size,
182 bool bot_updates);
183
184 // Second-level allocation: Should be called while holding a
185 // lock. It will try to first allocate lock-free out of the active
186 // region or, if it's unable to, it will try to replace the active
187 // alloc region with a new one. We require that the caller takes the
188 // appropriate lock before calling this so that it is easier to make
189 // it conform to its locking protocol.
190 inline HeapWord* attempt_allocation_locked(size_t word_size,
191 bool bot_updates);
192 // Same as attempt_allocation_locked(size_t, bool), but allowing specification
193 // of minimum word size of the block in min_word_size, and the maximum word
194 // size of the allocation in desired_word_size. The actual size of the block is
195 // returned in actual_word_size.
196 inline HeapWord* attempt_allocation_locked(size_t min_word_size,
197 size_t desired_word_size,
198 size_t* actual_word_size,
199 bool bot_updates);
200
201 // Should be called to allocate a new region even if the max of this
202 // type of regions has been reached. Should only be called if other
203 // allocation attempts have failed and we are not holding a valid
204 // active region.
205 inline HeapWord* attempt_allocation_force(size_t word_size,
206 bool bot_updates);
207
208 // Should be called before we start using this object.
209 void init();
210
211 // This can be used to set the active region to a specific
212 // region. (Use Example: we try to retain the last old GC alloc
213 // region that we've used during a GC and we can use set() to
214 // re-instate it at the beginning of the next GC.)
215 void set(HeapRegion* alloc_region);
216
217 // Should be called when we want to release the active region which
218 // is returned after it's been retired.
219 virtual HeapRegion* release();
220
221 #if G1_ALLOC_REGION_TRACING
222 void trace(const char* str,
223 size_t min_word_size = 0,
224 size_t desired_word_size = 0,
225 size_t actual_word_size = 0,
226 HeapWord* result = NULL);
227 #else // G1_ALLOC_REGION_TRACING
228 void trace(const char* str,
229 size_t min_word_size = 0,
230 size_t desired_word_size = 0,
231 size_t actual_word_size = 0,
232 HeapWord* result = NULL) { }
233 #endif // G1_ALLOC_REGION_TRACING
234 };
235
236 class MutatorAllocRegion : public G1AllocRegion {
237 protected:
238 virtual HeapRegion* allocate_new_region(size_t word_size, bool force);
239 virtual void retire_region(HeapRegion* alloc_region, size_t allocated_bytes);
240 public:
241 MutatorAllocRegion()
242 : G1AllocRegion("Mutator Alloc Region", false /* bot_updates */) { }
243 };
244
245 // Common base class for allocation regions used during GC.
246 class G1GCAllocRegion : public G1AllocRegion {
247 protected:
248 G1EvacStats* _stats;
249 InCSetState::in_cset_state_t _purpose;
250
251 virtual HeapRegion* allocate_new_region(size_t word_size, bool force);
252 virtual void retire_region(HeapRegion* alloc_region, size_t allocated_bytes);
|