314 buf->flush_and_retire_stats(stats);
315 stats->add_direct_allocated(_direct_allocated[state]);
316 _direct_allocated[state] = 0;
317 }
318 }
319 }
320
321 void G1DefaultPLABAllocator::waste(size_t& wasted, size_t& undo_wasted) {
322 wasted = 0;
323 undo_wasted = 0;
324 for (uint state = 0; state < InCSetState::Num; state++) {
325 G1PLAB * const buf = _alloc_buffers[state];
326 if (buf != NULL) {
327 wasted += buf->waste();
328 undo_wasted += buf->undo_waste();
329 }
330 }
331 }
332
333 bool G1ArchiveAllocator::_archive_check_enabled = false;
334 G1ArchiveRegionMap G1ArchiveAllocator::_archive_region_map;
335
336 G1ArchiveAllocator* G1ArchiveAllocator::create_allocator(G1CollectedHeap* g1h) {
337 // Create the archive allocator, and also enable archive object checking
338 // in mark-sweep, since we will be creating archive regions.
339 G1ArchiveAllocator* result = new G1ArchiveAllocator(g1h);
340 enable_archive_object_check();
341 return result;
342 }
343
344 bool G1ArchiveAllocator::alloc_new_region() {
345 // Allocate the highest free region in the reserved heap,
346 // and add it to our list of allocated regions. It is marked
347 // archive and added to the old set.
348 HeapRegion* hr = _g1h->alloc_highest_free_region();
349 if (hr == NULL) {
350 return false;
351 }
352 assert(hr->is_empty(), "expected empty region (index %u)", hr->hrm_index());
353 hr->set_archive();
354 _g1h->old_set_add(hr);
355 _g1h->hr_printer()->alloc(hr);
356 _allocated_regions.append(hr);
357 _allocation_region = hr;
358
359 // Set up _bottom and _max to begin allocating in the lowest
360 // min_region_size'd chunk of the allocated G1 region.
361 _bottom = hr->bottom();
362 _max = _bottom + HeapRegion::min_region_size_in_words();
363
364 // Tell mark-sweep that objects in this region are not to be marked.
365 set_range_archive(MemRegion(_bottom, HeapRegion::GrainWords), true);
366
367 // Since we've modified the old set, call update_sizes.
368 _g1h->g1mm()->update_sizes();
369 return true;
370 }
371
372 HeapWord* G1ArchiveAllocator::archive_mem_allocate(size_t word_size) {
373 assert(word_size != 0, "size must not be zero");
374 if (_allocation_region == NULL) {
375 if (!alloc_new_region()) {
376 return NULL;
377 }
378 }
379 HeapWord* old_top = _allocation_region->top();
380 assert(_bottom >= _allocation_region->bottom(),
381 "inconsistent allocation state: " PTR_FORMAT " < " PTR_FORMAT,
382 p2i(_bottom), p2i(_allocation_region->bottom()));
383 assert(_max <= _allocation_region->end(),
384 "inconsistent allocation state: " PTR_FORMAT " > " PTR_FORMAT,
385 p2i(_max), p2i(_allocation_region->end()));
|
314 buf->flush_and_retire_stats(stats);
315 stats->add_direct_allocated(_direct_allocated[state]);
316 _direct_allocated[state] = 0;
317 }
318 }
319 }
320
321 void G1DefaultPLABAllocator::waste(size_t& wasted, size_t& undo_wasted) {
322 wasted = 0;
323 undo_wasted = 0;
324 for (uint state = 0; state < InCSetState::Num; state++) {
325 G1PLAB * const buf = _alloc_buffers[state];
326 if (buf != NULL) {
327 wasted += buf->waste();
328 undo_wasted += buf->undo_waste();
329 }
330 }
331 }
332
333 bool G1ArchiveAllocator::_archive_check_enabled = false;
334 G1ArchiveRegionMap G1ArchiveAllocator::_closed_archive_region_map;
335 G1ArchiveRegionMap G1ArchiveAllocator::_open_archive_region_map;
336
337 G1ArchiveAllocator* G1ArchiveAllocator::create_allocator(G1CollectedHeap* g1h, bool open) {
338 // Create the archive allocator, and also enable archive object checking
339 // in mark-sweep, since we will be creating archive regions.
340 G1ArchiveAllocator* result = new G1ArchiveAllocator(g1h, open);
341 enable_archive_object_check();
342 return result;
343 }
344
345 bool G1ArchiveAllocator::alloc_new_region() {
346 // Allocate the highest free region in the reserved heap,
347 // and add it to our list of allocated regions. It is marked
348 // archive and added to the old set.
349 HeapRegion* hr = _g1h->alloc_highest_free_region();
350 if (hr == NULL) {
351 return false;
352 }
353 assert(hr->is_empty(), "expected empty region (index %u)", hr->hrm_index());
354 if (_open) {
355 hr->set_open_archive();
356 } else {
357 hr->set_closed_archive();
358 }
359 _g1h->old_set_add(hr);
360 _g1h->hr_printer()->alloc(hr);
361 _allocated_regions.append(hr);
362 _allocation_region = hr;
363
364 // Set up _bottom and _max to begin allocating in the lowest
365 // min_region_size'd chunk of the allocated G1 region.
366 _bottom = hr->bottom();
367 _max = _bottom + HeapRegion::min_region_size_in_words();
368
369 // Tell mark-sweep that objects in this region are not to be marked.
370 set_range_archive(MemRegion(_bottom, HeapRegion::GrainWords), _open);
371
372 // Since we've modified the old set, call update_sizes.
373 _g1h->g1mm()->update_sizes();
374 return true;
375 }
376
377 HeapWord* G1ArchiveAllocator::archive_mem_allocate(size_t word_size) {
378 assert(word_size != 0, "size must not be zero");
379 if (_allocation_region == NULL) {
380 if (!alloc_new_region()) {
381 return NULL;
382 }
383 }
384 HeapWord* old_top = _allocation_region->top();
385 assert(_bottom >= _allocation_region->bottom(),
386 "inconsistent allocation state: " PTR_FORMAT " < " PTR_FORMAT,
387 p2i(_bottom), p2i(_allocation_region->bottom()));
388 assert(_max <= _allocation_region->end(),
389 "inconsistent allocation state: " PTR_FORMAT " > " PTR_FORMAT,
390 p2i(_max), p2i(_allocation_region->end()));
|