127 size_t G1Allocator::unsafe_max_tlab_alloc(AllocationContext_t context) {
128 // Return the remaining space in the cur alloc region, but not less than
129 // the min TLAB size.
130
131 // Also, this value can be at most the humongous object threshold,
132 // since we can't allow tlabs to grow big enough to accommodate
133 // humongous objects.
134
135 HeapRegion* hr = mutator_alloc_region(context)->get();
136 size_t max_tlab = _g1h->max_tlab_size() * wordSize;
137 if (hr == NULL) {
138 return max_tlab;
139 } else {
140 return MIN2(MAX2(hr->free(), (size_t) MinTLABSize), max_tlab);
141 }
142 }
143
144 HeapWord* G1Allocator::par_allocate_during_gc(InCSetState dest,
145 size_t word_size,
146 AllocationContext_t context) {
147 size_t temp;
148 return par_allocate_during_gc(dest, word_size, word_size, &temp, context);
149 }
150
151 HeapWord* G1Allocator::par_allocate_during_gc(InCSetState dest,
152 size_t min_word_size,
153 size_t desired_word_size,
154 size_t* actual_word_size,
155 AllocationContext_t context) {
156 switch (dest.value()) {
157 case InCSetState::Young:
158 return survivor_attempt_allocation(min_word_size, desired_word_size, actual_word_size, context);
159 case InCSetState::Old:
160 return old_attempt_allocation(min_word_size, desired_word_size, actual_word_size, context);
161 default:
162 ShouldNotReachHere();
163 return NULL; // Keep some compilers happy
164 }
165 }
166
167 bool G1Allocator::survivor_is_full(AllocationContext_t context) const {
168 return _survivor_is_full;
247
248 bool G1PLABAllocator::may_throw_away_buffer(size_t const allocation_word_sz, size_t const buffer_size) const {
249 return (allocation_word_sz * 100 < buffer_size * ParallelGCBufferWastePct);
250 }
251
252 HeapWord* G1PLABAllocator::allocate_direct_or_new_plab(InCSetState dest,
253 size_t word_sz,
254 AllocationContext_t context,
255 bool* plab_refill_failed) {
256 size_t plab_word_size = G1CollectedHeap::heap()->desired_plab_sz(dest);
257 size_t required_in_plab = PLAB::size_required_for_allocation(word_sz);
258
259 // Only get a new PLAB if the allocation fits and it would not waste more than
260 // ParallelGCBufferWastePct in the existing buffer.
261 if ((required_in_plab <= plab_word_size) &&
262 may_throw_away_buffer(required_in_plab, plab_word_size)) {
263
264 G1PLAB* alloc_buf = alloc_buffer(dest, context);
265 alloc_buf->retire();
266
267 size_t actual_plab_size;
268 HeapWord* buf = _allocator->par_allocate_during_gc(dest,
269 required_in_plab,
270 plab_word_size,
271 &actual_plab_size,
272 context);
273 if (buf != NULL) {
274 alloc_buf->set_buf(buf, actual_plab_size);
275
276 HeapWord* const obj = alloc_buf->allocate(word_sz);
277 assert(obj != NULL, err_msg("PLAB should have been big enough, tried to allocate "
278 SIZE_FORMAT " requiring " SIZE_FORMAT " PLAB size " SIZE_FORMAT,
279 word_sz, required_in_plab, plab_word_size));
280 return obj;
281 }
282 // Otherwise.
283 *plab_refill_failed = true;
284 }
285 // Try direct allocation.
286 HeapWord* result = _allocator->par_allocate_during_gc(dest, word_sz, context);
287 if (result != NULL) {
288 _direct_allocated[dest.value()] += word_sz;
289 }
290 return result;
291 }
292
|
127 size_t G1Allocator::unsafe_max_tlab_alloc(AllocationContext_t context) {
128 // Return the remaining space in the cur alloc region, but not less than
129 // the min TLAB size.
130
131 // Also, this value can be at most the humongous object threshold,
132 // since we can't allow tlabs to grow big enough to accommodate
133 // humongous objects.
134
135 HeapRegion* hr = mutator_alloc_region(context)->get();
136 size_t max_tlab = _g1h->max_tlab_size() * wordSize;
137 if (hr == NULL) {
138 return max_tlab;
139 } else {
140 return MIN2(MAX2(hr->free(), (size_t) MinTLABSize), max_tlab);
141 }
142 }
143
144 HeapWord* G1Allocator::par_allocate_during_gc(InCSetState dest,
145 size_t word_size,
146 AllocationContext_t context) {
147 size_t temp = 0;
148 HeapWord* result = par_allocate_during_gc(dest, word_size, word_size, &temp, context);
149 assert(result == NULL || temp == word_size,
150 err_msg("Requested " SIZE_FORMAT " words, but got " SIZE_FORMAT " at " PTR_FORMAT,
151 word_size, temp, p2i(result)));
152 return result;
153 }
154
155 HeapWord* G1Allocator::par_allocate_during_gc(InCSetState dest,
156 size_t min_word_size,
157 size_t desired_word_size,
158 size_t* actual_word_size,
159 AllocationContext_t context) {
160 switch (dest.value()) {
161 case InCSetState::Young:
162 return survivor_attempt_allocation(min_word_size, desired_word_size, actual_word_size, context);
163 case InCSetState::Old:
164 return old_attempt_allocation(min_word_size, desired_word_size, actual_word_size, context);
165 default:
166 ShouldNotReachHere();
167 return NULL; // Keep some compilers happy
168 }
169 }
170
171 bool G1Allocator::survivor_is_full(AllocationContext_t context) const {
172 return _survivor_is_full;
251
252 bool G1PLABAllocator::may_throw_away_buffer(size_t const allocation_word_sz, size_t const buffer_size) const {
253 return (allocation_word_sz * 100 < buffer_size * ParallelGCBufferWastePct);
254 }
255
256 HeapWord* G1PLABAllocator::allocate_direct_or_new_plab(InCSetState dest,
257 size_t word_sz,
258 AllocationContext_t context,
259 bool* plab_refill_failed) {
260 size_t plab_word_size = G1CollectedHeap::heap()->desired_plab_sz(dest);
261 size_t required_in_plab = PLAB::size_required_for_allocation(word_sz);
262
263 // Only get a new PLAB if the allocation fits and it would not waste more than
264 // ParallelGCBufferWastePct in the existing buffer.
265 if ((required_in_plab <= plab_word_size) &&
266 may_throw_away_buffer(required_in_plab, plab_word_size)) {
267
268 G1PLAB* alloc_buf = alloc_buffer(dest, context);
269 alloc_buf->retire();
270
271 size_t actual_plab_size = 0;
272 HeapWord* buf = _allocator->par_allocate_during_gc(dest,
273 required_in_plab,
274 plab_word_size,
275 &actual_plab_size,
276 context);
277
278 assert(buf == NULL || ((actual_plab_size >= required_in_plab) && (actual_plab_size <= plab_word_size)),
279 err_msg("Requested at minimum " SIZE_FORMAT ", desired " SIZE_FORMAT " words, but got " SIZE_FORMAT " at " PTR_FORMAT,
280 required_in_plab, plab_word_size, actual_plab_size, p2i(buf)));
281
282 if (buf != NULL) {
283 alloc_buf->set_buf(buf, actual_plab_size);
284
285 HeapWord* const obj = alloc_buf->allocate(word_sz);
286 assert(obj != NULL, err_msg("PLAB should have been big enough, tried to allocate "
287 SIZE_FORMAT " requiring " SIZE_FORMAT " PLAB size " SIZE_FORMAT,
288 word_sz, required_in_plab, plab_word_size));
289 return obj;
290 }
291 // Otherwise.
292 *plab_refill_failed = true;
293 }
294 // Try direct allocation.
295 HeapWord* result = _allocator->par_allocate_during_gc(dest, word_sz, context);
296 if (result != NULL) {
297 _direct_allocated[dest.value()] += word_sz;
298 }
299 return result;
300 }
301
|