src/share/vm/gc_implementation/g1/g1AllocRegion.cpp

changeset 7118
227a9e5e4b4a
parent 6911
ce8f6bb717c9
child 7535
7ae4e26cb1e0
child 7651
c132be0fb74d
     1.1 --- a/src/share/vm/gc_implementation/g1/g1AllocRegion.cpp	Thu Sep 04 16:53:27 2014 -0700
     1.2 +++ b/src/share/vm/gc_implementation/g1/g1AllocRegion.cpp	Fri Sep 05 09:49:19 2014 +0200
     1.3 @@ -129,8 +129,7 @@
     1.4      // Note that we first perform the allocation and then we store the
     1.5      // region in _alloc_region. This is the reason why an active region
     1.6      // can never be empty.
     1.7 -    _alloc_region = new_alloc_region;
     1.8 -    _count += 1;
     1.9 +    update_alloc_region(new_alloc_region);
    1.10      trace("region allocation successful");
    1.11      return result;
    1.12    } else {
    1.13 @@ -172,6 +171,19 @@
    1.14    trace("set");
    1.15  }
    1.16  
    1.17 +void G1AllocRegion::update_alloc_region(HeapRegion* alloc_region) {
    1.18 +  trace("update");
    1.19 +  // We explicitly check that the region is not empty to make sure we
    1.20 +  // maintain the "the alloc region cannot be empty" invariant.
    1.21 +  assert(alloc_region != NULL && !alloc_region->is_empty(),
    1.22 +         ar_ext_msg(this, "pre-condition"));
    1.23 +
    1.24 +  _alloc_region = alloc_region;
    1.25 +  _alloc_region->set_allocation_context(allocation_context());
    1.26 +  _count += 1;
    1.27 +  trace("updated");
    1.28 +}
    1.29 +
    1.30  HeapRegion* G1AllocRegion::release() {
    1.31    trace("releasing");
    1.32    HeapRegion* alloc_region = _alloc_region;
    1.33 @@ -225,5 +237,70 @@
    1.34  G1AllocRegion::G1AllocRegion(const char* name,
    1.35                               bool bot_updates)
    1.36    : _name(name), _bot_updates(bot_updates),
    1.37 -    _alloc_region(NULL), _count(0), _used_bytes_before(0) { }
    1.38 +    _alloc_region(NULL), _count(0), _used_bytes_before(0),
    1.39 +    _allocation_context(AllocationContext::system()) { }
    1.40  
    1.41 +
    1.42 +HeapRegion* MutatorAllocRegion::allocate_new_region(size_t word_size,
    1.43 +                                                    bool force) {
    1.44 +  return _g1h->new_mutator_alloc_region(word_size, force);
    1.45 +}
    1.46 +
    1.47 +void MutatorAllocRegion::retire_region(HeapRegion* alloc_region,
    1.48 +                                       size_t allocated_bytes) {
    1.49 +  _g1h->retire_mutator_alloc_region(alloc_region, allocated_bytes);
    1.50 +}
    1.51 +
    1.52 +HeapRegion* SurvivorGCAllocRegion::allocate_new_region(size_t word_size,
    1.53 +                                                       bool force) {
    1.54 +  assert(!force, "not supported for GC alloc regions");
    1.55 +  return _g1h->new_gc_alloc_region(word_size, count(), GCAllocForSurvived);
    1.56 +}
    1.57 +
    1.58 +void SurvivorGCAllocRegion::retire_region(HeapRegion* alloc_region,
    1.59 +                                          size_t allocated_bytes) {
    1.60 +  _g1h->retire_gc_alloc_region(alloc_region, allocated_bytes,
    1.61 +                               GCAllocForSurvived);
    1.62 +}
    1.63 +
    1.64 +HeapRegion* OldGCAllocRegion::allocate_new_region(size_t word_size,
    1.65 +                                                  bool force) {
    1.66 +  assert(!force, "not supported for GC alloc regions");
    1.67 +  return _g1h->new_gc_alloc_region(word_size, count(), GCAllocForTenured);
    1.68 +}
    1.69 +
    1.70 +void OldGCAllocRegion::retire_region(HeapRegion* alloc_region,
    1.71 +                                     size_t allocated_bytes) {
    1.72 +  _g1h->retire_gc_alloc_region(alloc_region, allocated_bytes,
    1.73 +                               GCAllocForTenured);
    1.74 +}
    1.75 +
    1.76 +HeapRegion* OldGCAllocRegion::release() {
    1.77 +  HeapRegion* cur = get();
    1.78 +  if (cur != NULL) {
    1.79 +    // Determine how far we are from the next card boundary. If it is smaller than
    1.80 +    // the minimum object size we can allocate into, expand into the next card.
    1.81 +    HeapWord* top = cur->top();
    1.82 +    HeapWord* aligned_top = (HeapWord*)align_ptr_up(top, G1BlockOffsetSharedArray::N_bytes);
    1.83 +
    1.84 +    size_t to_allocate_words = pointer_delta(aligned_top, top, HeapWordSize);
    1.85 +
    1.86 +    if (to_allocate_words != 0) {
    1.87 +      // We are not at a card boundary. Fill up, possibly into the next, taking the
    1.88 +      // end of the region and the minimum object size into account.
    1.89 +      to_allocate_words = MIN2(pointer_delta(cur->end(), cur->top(), HeapWordSize),
    1.90 +                               MAX2(to_allocate_words, G1CollectedHeap::min_fill_size()));
    1.91 +
    1.92 +      // Skip allocation if there is not enough space to allocate even the smallest
    1.93 +      // possible object. In this case this region will not be retained, so the
    1.94 +      // original problem cannot occur.
    1.95 +      if (to_allocate_words >= G1CollectedHeap::min_fill_size()) {
    1.96 +        HeapWord* dummy = attempt_allocation(to_allocate_words, true /* bot_updates */);
    1.97 +        CollectedHeap::fill_with_object(dummy, to_allocate_words);
    1.98 +      }
    1.99 +    }
   1.100 +  }
   1.101 +  return G1AllocRegion::release();
   1.102 +}
   1.103 +
   1.104 +

mercurial