< prev index next >

src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.inline.hpp

Print this page
*** 29,18 ***
  
  #include "gc/shenandoah/shenandoahHeap.inline.hpp"
  #include "gc/shenandoah/shenandoahPacer.inline.hpp"
  #include "runtime/atomic.hpp"
  
! HeapWord* ShenandoahHeapRegion::allocate(size_t size, ShenandoahAllocRequest::Type type) {
    shenandoah_assert_heaplocked_or_safepoint();
    assert(is_object_aligned(size), "alloc size breaks alignment: " SIZE_FORMAT, size);
  
    HeapWord* obj = top();
    if (pointer_delta(end(), obj) >= size) {
!     make_regular_allocation();
!     adjust_alloc_metadata(type, size);
  
      HeapWord* new_top = obj + size;
      set_top(new_top);
  
      assert(is_object_aligned(new_top), "new top breaks alignment: " PTR_FORMAT, p2i(new_top));
--- 29,55 ---
  
  #include "gc/shenandoah/shenandoahHeap.inline.hpp"
  #include "gc/shenandoah/shenandoahPacer.inline.hpp"
  #include "runtime/atomic.hpp"
  
! // If next available memory is not aligned on address that is multiple of alignment, fill the empty space
+ // so that returned object is aligned on an address that is a multiple of alignment_in_words.  Requested
+ // size is in words.
+ HeapWord* ShenandoahHeapRegion::allocate_aligned(size_t size, ShenandoahAllocRequest req, size_t alignment_in_bytes) {
+   shenandoah_assert_heaplocked_or_safepoint();
+   assert(is_object_aligned(size), "alloc size breaks alignment: " SIZE_FORMAT, size);
+ 
+   HeapWord* obj = top();
+   uintptr_t addr_as_int = (uintptr_t) obj;
+ 
+   size_t unalignment_bytes = addr_as_int % alignment_in_bytes;
+   size_t unalignment_words = unalignment_bytes / HeapWordSize;
+   if (pointer_delta(end(), obj + unalignment_words) >= size) {
+     if (unalignment_words > 0) {
+       size_t pad_words = (alignment_in_bytes / HeapWordSize) - unalignment_words;
+       if (pad_words < ShenandoahHeap::min_fill_size()) {
+         pad_words += (alignment_in_bytes / HeapWordSize);
+       }
+       ShenandoahHeap::fill_with_object(obj, pad_words);
+       ShenandoahHeap::heap()->card_scan()->register_object(obj);
+       obj += pad_words;
+     }
+ 
+     make_regular_allocation(req.affiliation());
+     adjust_alloc_metadata(req.type(), size);
+ 
+     HeapWord* new_top = obj + size;
+     set_top(new_top);
+     assert(is_object_aligned(new_top), "new top breaks alignment: " PTR_FORMAT, p2i(new_top));
+     assert(is_aligned(obj, alignment_in_bytes), "obj is not aligned: " PTR_FORMAT, p2i(obj));
+ 
+     return obj;
+   } else {
+     return NULL;
+   }
+ }
+ 
+ HeapWord* ShenandoahHeapRegion::allocate(size_t size, ShenandoahAllocRequest req) {
    shenandoah_assert_heaplocked_or_safepoint();
    assert(is_object_aligned(size), "alloc size breaks alignment: " SIZE_FORMAT, size);
  
    HeapWord* obj = top();
    if (pointer_delta(end(), obj) >= size) {
!     make_regular_allocation(req.affiliation());
!     adjust_alloc_metadata(req.type(), size);
  
      HeapWord* new_top = obj + size;
      set_top(new_top);
  
      assert(is_object_aligned(new_top), "new top breaks alignment: " PTR_FORMAT, p2i(new_top));

*** 62,10 ***
--- 99,13 ---
        _tlab_allocs += size;
        break;
      case ShenandoahAllocRequest::_alloc_gclab:
        _gclab_allocs += size;
        break;
+     case ShenandoahAllocRequest::_alloc_plab:
+       _plab_allocs += size;
+       break;
      default:
        ShouldNotReachHere();
    }
  }
  

*** 84,11 ***
    size_t new_live_data = Atomic::add(&_live_data, s, memory_order_relaxed);
  #ifdef ASSERT
    size_t live_bytes = new_live_data * HeapWordSize;
    size_t used_bytes = used();
    assert(live_bytes <= used_bytes,
!          "can't have more live data than used: " SIZE_FORMAT ", " SIZE_FORMAT, live_bytes, used_bytes);
  #endif
  }
  
  inline void ShenandoahHeapRegion::clear_live_data() {
    Atomic::store(&_live_data, (size_t)0);
--- 124,12 ---
    size_t new_live_data = Atomic::add(&_live_data, s, memory_order_relaxed);
  #ifdef ASSERT
    size_t live_bytes = new_live_data * HeapWordSize;
    size_t used_bytes = used();
    assert(live_bytes <= used_bytes,
!          "%s Region " SIZE_FORMAT " can't have more live data than used: " SIZE_FORMAT ", " SIZE_FORMAT " after adding " SIZE_FORMAT,
+          affiliation_name(affiliation()), index(), live_bytes, used_bytes, s * HeapWordSize);
  #endif
  }
  
  inline void ShenandoahHeapRegion::clear_live_data() {
    Atomic::store(&_live_data, (size_t)0);

*** 131,6 ***
--- 172,18 ---
    assert(bottom() <= w && w <= top(), "within bounds");
    assert(SafepointSynchronize::is_at_safepoint(), "Should be at Shenandoah safepoint");
    _update_watermark = w;
  }
  
+ inline void ShenandoahHeapRegion::clear_young_lab_flags() {
+   _has_young_lab = false;
+ }
+ 
+ inline void ShenandoahHeapRegion::set_young_lab_flag() {
+   _has_young_lab = true;
+ }
+ 
+ inline bool ShenandoahHeapRegion::has_young_lab_flag() {
+   return _has_young_lab;
+ }
+ 
  #endif // SHARE_GC_SHENANDOAH_SHENANDOAHHEAPREGION_INLINE_HPP
< prev index next >