299 AllocationContext_t context) { |
299 AllocationContext_t context) { |
300 assert(first != G1_NO_HRM_INDEX, "pre-condition"); |
300 assert(first != G1_NO_HRM_INDEX, "pre-condition"); |
301 assert(is_humongous(word_size), "word_size should be humongous"); |
301 assert(is_humongous(word_size), "word_size should be humongous"); |
302 assert(num_regions * HeapRegion::GrainWords >= word_size, "pre-condition"); |
302 assert(num_regions * HeapRegion::GrainWords >= word_size, "pre-condition"); |
303 |
303 |
304 // Index of last region in the series + 1. |
304 // Index of last region in the series. |
305 uint last = first + num_regions; |
305 uint last = first + num_regions - 1; |
306 |
306 |
307 // We need to initialize the region(s) we just discovered. This is |
307 // We need to initialize the region(s) we just discovered. This is |
308 // a bit tricky given that it can happen concurrently with |
308 // a bit tricky given that it can happen concurrently with |
309 // refinement threads refining cards on these regions and |
309 // refinement threads refining cards on these regions and |
310 // potentially wanting to refine the BOT as they are scanning |
310 // potentially wanting to refine the BOT as they are scanning |
337 // type and, for a very short period of time, the klass and length |
337 // type and, for a very short period of time, the klass and length |
338 // fields will be inconsistent. This could cause a refinement |
338 // fields will be inconsistent. This could cause a refinement |
339 // thread to calculate the object size incorrectly. |
339 // thread to calculate the object size incorrectly. |
340 Copy::fill_to_words(new_obj, oopDesc::header_size(), 0); |
340 Copy::fill_to_words(new_obj, oopDesc::header_size(), 0); |
341 |
341 |
342 size_t fill_size = word_size_sum - word_size; |
342 // How many words we use for filler objects. |
343 if (fill_size >= min_fill_size()) { |
343 size_t word_fill_size = word_size_sum - word_size; |
344 fill_with_objects(obj_top, fill_size); |
344 |
345 } else { |
345 // How many words memory we "waste" which cannot hold a filler object. |
346 fill_size = 0; |
346 size_t words_not_fillable = 0; |
|
347 |
|
348 if (word_fill_size >= min_fill_size()) { |
|
349 fill_with_objects(obj_top, word_fill_size); |
|
350 } else if (word_fill_size > 0) { |
|
351 // We have space to fill, but we cannot fit an object there. |
|
352 words_not_fillable = word_fill_size; |
|
353 word_fill_size = 0; |
347 } |
354 } |
348 |
355 |
349 // We will set up the first region as "starts humongous". This |
356 // We will set up the first region as "starts humongous". This |
350 // will also update the BOT covering all the regions to reflect |
357 // will also update the BOT covering all the regions to reflect |
351 // that there is a single object that starts at the bottom of the |
358 // that there is a single object that starts at the bottom of the |
352 // first region. |
359 // first region. |
353 first_hr->set_starts_humongous(obj_top, fill_size); |
360 first_hr->set_starts_humongous(obj_top, word_fill_size); |
354 first_hr->set_allocation_context(context); |
361 first_hr->set_allocation_context(context); |
355 // Then, if there are any, we will set up the "continues |
362 // Then, if there are any, we will set up the "continues |
356 // humongous" regions. |
363 // humongous" regions. |
357 HeapRegion* hr = NULL; |
364 HeapRegion* hr = NULL; |
358 for (uint i = first + 1; i < last; ++i) { |
365 for (uint i = first + 1; i <= last; ++i) { |
359 hr = region_at(i); |
366 hr = region_at(i); |
360 hr->set_continues_humongous(first_hr); |
367 hr->set_continues_humongous(first_hr); |
361 hr->set_allocation_context(context); |
368 hr->set_allocation_context(context); |
362 } |
369 } |
363 |
370 |
368 // update the top fields, we'll do a storestore to make sure that |
375 // update the top fields, we'll do a storestore to make sure that |
369 // no thread sees the update to top before the zeroing of the |
376 // no thread sees the update to top before the zeroing of the |
370 // object header and the BOT initialization. |
377 // object header and the BOT initialization. |
371 OrderAccess::storestore(); |
378 OrderAccess::storestore(); |
372 |
379 |
373 // Now that the BOT and the object header have been initialized, |
|
374 // we can update top of the "starts humongous" region. |
|
375 first_hr->set_top(first_hr->end()); |
|
376 if (_hr_printer.is_active()) { |
|
377 _hr_printer.alloc(G1HRPrinter::StartsHumongous, first_hr, first_hr->end()); |
|
378 } |
|
379 |
|
380 // Now, we will update the top fields of the "continues humongous" |
380 // Now, we will update the top fields of the "continues humongous" |
381 // regions. |
381 // regions except the last one. |
382 hr = NULL; |
382 for (uint i = first; i < last; ++i) { |
383 for (uint i = first + 1; i < last; ++i) { |
|
384 hr = region_at(i); |
383 hr = region_at(i); |
385 hr->set_top(hr->end()); |
384 hr->set_top(hr->end()); |
386 if (_hr_printer.is_active()) { |
385 } |
387 _hr_printer.alloc(G1HRPrinter::ContinuesHumongous, hr, hr->end()); |
386 |
388 } |
387 hr = region_at(last); |
389 } |
388 // If we cannot fit a filler object, we must set top to the end |
390 |
389 // of the humongous object, otherwise we cannot iterate the heap |
391 assert(hr == NULL || (hr->bottom() < obj_top && obj_top <= hr->end()), |
390 // and the BOT will not be complete. |
|
391 hr->set_top(hr->end() - words_not_fillable); |
|
392 |
|
393 assert(hr->bottom() < obj_top && obj_top <= hr->end(), |
392 "obj_top should be in last region"); |
394 "obj_top should be in last region"); |
393 |
395 |
394 check_bitmaps("Humongous Region Allocation", first_hr); |
396 check_bitmaps("Humongous Region Allocation", first_hr); |
395 |
397 |
396 increase_used(word_size_sum * HeapWordSize); |
398 assert(words_not_fillable == 0 || |
397 |
399 first_hr->bottom() + word_size_sum - words_not_fillable == hr->top(), |
398 for (uint i = first; i < last; ++i) { |
400 "Miscalculation in humongous allocation"); |
399 _humongous_set.add(region_at(i)); |
401 |
|
402 increase_used((word_size_sum - words_not_fillable) * HeapWordSize); |
|
403 |
|
404 for (uint i = first; i <= last; ++i) { |
|
405 hr = region_at(i); |
|
406 _humongous_set.add(hr); |
|
407 if (i == first) { |
|
408 _hr_printer.alloc(G1HRPrinter::StartsHumongous, hr, hr->top()); |
|
409 } else { |
|
410 _hr_printer.alloc(G1HRPrinter::ContinuesHumongous, hr, hr->top()); |
|
411 } |
400 } |
412 } |
401 |
413 |
402 return new_obj; |
414 return new_obj; |
403 } |
415 } |
404 |
416 |