< prev index next >

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

Print this page

 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHHEAPREGION_INLINE_HPP
 26 #define SHARE_GC_SHENANDOAH_SHENANDOAHHEAPREGION_INLINE_HPP
 27 
 28 #include "gc/shenandoah/shenandoahHeapRegion.hpp"
 29 
 30 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
 31 #include "gc/shenandoah/shenandoahPacer.inline.hpp"
 32 #include "runtime/atomic.hpp"
 33 
 34 HeapWord* ShenandoahHeapRegion::allocate(size_t size, ShenandoahAllocRequest::Type type) {





































 35   shenandoah_assert_heaplocked_or_safepoint();
 36   assert(is_object_aligned(size), "alloc size breaks alignment: " SIZE_FORMAT, size);
 37 
 38   HeapWord* obj = top();
 39   if (pointer_delta(end(), obj) >= size) {
 40     make_regular_allocation();
 41     adjust_alloc_metadata(type, size);
 42 
 43     HeapWord* new_top = obj + size;
 44     set_top(new_top);
 45 
 46     assert(is_object_aligned(new_top), "new top breaks alignment: " PTR_FORMAT, p2i(new_top));
 47     assert(is_object_aligned(obj),     "obj is not aligned: "       PTR_FORMAT, p2i(obj));
 48 
 49     return obj;
 50   } else {
 51     return NULL;
 52   }
 53 }
 54 
 55 inline void ShenandoahHeapRegion::adjust_alloc_metadata(ShenandoahAllocRequest::Type type, size_t size) {
 56   switch (type) {
 57     case ShenandoahAllocRequest::_alloc_shared:
 58     case ShenandoahAllocRequest::_alloc_shared_gc:
 59       // Counted implicitly by tlab/gclab allocs
 60       break;
 61     case ShenandoahAllocRequest::_alloc_tlab:
 62       _tlab_allocs += size;
 63       break;
 64     case ShenandoahAllocRequest::_alloc_gclab:
 65       _gclab_allocs += size;
 66       break;



 67     default:
 68       ShouldNotReachHere();
 69   }
 70 }
 71 
 72 inline void ShenandoahHeapRegion::increase_live_data_alloc_words(size_t s) {
 73   internal_increase_live_data(s);
 74 }
 75 
 76 inline void ShenandoahHeapRegion::increase_live_data_gc_words(size_t s) {
 77   internal_increase_live_data(s);
 78   if (ShenandoahPacing) {
 79     ShenandoahHeap::heap()->pacer()->report_mark(s);
 80   }
 81 }
 82 
 83 inline void ShenandoahHeapRegion::internal_increase_live_data(size_t s) {
 84   size_t new_live_data = Atomic::add(&_live_data, s, memory_order_relaxed);
 85 #ifdef ASSERT
 86   size_t live_bytes = new_live_data * HeapWordSize;
 87   size_t used_bytes = used();
 88   assert(live_bytes <= used_bytes,
 89          "can't have more live data than used: " SIZE_FORMAT ", " SIZE_FORMAT, live_bytes, used_bytes);

 90 #endif
 91 }
 92 
 93 inline void ShenandoahHeapRegion::clear_live_data() {
 94   Atomic::store(&_live_data, (size_t)0);
 95 }
 96 
 97 inline size_t ShenandoahHeapRegion::get_live_data_words() const {
 98   return Atomic::load(&_live_data);
 99 }
100 
101 inline size_t ShenandoahHeapRegion::get_live_data_bytes() const {
102   return get_live_data_words() * HeapWordSize;
103 }
104 
105 inline bool ShenandoahHeapRegion::has_live() const {
106   return get_live_data_words() != 0;
107 }
108 
109 inline size_t ShenandoahHeapRegion::garbage() const {

116 }
117 
118 inline HeapWord* ShenandoahHeapRegion::get_update_watermark() const {
119   HeapWord* watermark = Atomic::load_acquire(&_update_watermark);
120   assert(bottom() <= watermark && watermark <= top(), "within bounds");
121   return watermark;
122 }
123 
124 inline void ShenandoahHeapRegion::set_update_watermark(HeapWord* w) {
125   assert(bottom() <= w && w <= top(), "within bounds");
126   Atomic::release_store(&_update_watermark, w);
127 }
128 
129 // Fast version that avoids synchronization, only to be used at safepoints.
130 inline void ShenandoahHeapRegion::set_update_watermark_at_safepoint(HeapWord* w) {
131   assert(bottom() <= w && w <= top(), "within bounds");
132   assert(SafepointSynchronize::is_at_safepoint(), "Should be at Shenandoah safepoint");
133   _update_watermark = w;
134 }
135 












136 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHHEAPREGION_INLINE_HPP

 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHHEAPREGION_INLINE_HPP
 26 #define SHARE_GC_SHENANDOAH_SHENANDOAHHEAPREGION_INLINE_HPP
 27 
 28 #include "gc/shenandoah/shenandoahHeapRegion.hpp"
 29 
 30 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
 31 #include "gc/shenandoah/shenandoahPacer.inline.hpp"
 32 #include "runtime/atomic.hpp"
 33 
 34 // If next available memory is not aligned on address that is multiple of alignment, fill the empty space
 35 // so that returned object is aligned on an address that is a multiple of alignment_in_words.  Requested
 36 // size is in words.
 37 HeapWord* ShenandoahHeapRegion::allocate_aligned(size_t size, ShenandoahAllocRequest req, size_t alignment_in_bytes) {
 38   shenandoah_assert_heaplocked_or_safepoint();
 39   assert(is_object_aligned(size), "alloc size breaks alignment: " SIZE_FORMAT, size);
 40 
 41   HeapWord* obj = top();
 42   uintptr_t addr_as_int = (uintptr_t) obj;
 43 
 44   size_t unalignment_bytes = addr_as_int % alignment_in_bytes;
 45   size_t unalignment_words = unalignment_bytes / HeapWordSize;
 46   if (pointer_delta(end(), obj + unalignment_words) >= size) {
 47     if (unalignment_words > 0) {
 48       size_t pad_words = (alignment_in_bytes / HeapWordSize) - unalignment_words;
 49       if (pad_words < ShenandoahHeap::min_fill_size()) {
 50         pad_words += (alignment_in_bytes / HeapWordSize);
 51       }
 52       ShenandoahHeap::fill_with_object(obj, pad_words);
 53       ShenandoahHeap::heap()->card_scan()->register_object(obj);
 54       obj += pad_words;
 55     }
 56 
 57     make_regular_allocation(req.affiliation());
 58     adjust_alloc_metadata(req.type(), size);
 59 
 60     HeapWord* new_top = obj + size;
 61     set_top(new_top);
 62     assert(is_object_aligned(new_top), "new top breaks alignment: " PTR_FORMAT, p2i(new_top));
 63     assert(is_aligned(obj, alignment_in_bytes), "obj is not aligned: " PTR_FORMAT, p2i(obj));
 64 
 65     return obj;
 66   } else {
 67     return NULL;
 68   }
 69 }
 70 
 71 HeapWord* ShenandoahHeapRegion::allocate(size_t size, ShenandoahAllocRequest req) {
 72   shenandoah_assert_heaplocked_or_safepoint();
 73   assert(is_object_aligned(size), "alloc size breaks alignment: " SIZE_FORMAT, size);
 74 
 75   HeapWord* obj = top();
 76   if (pointer_delta(end(), obj) >= size) {
 77     make_regular_allocation(req.affiliation());
 78     adjust_alloc_metadata(req.type(), size);
 79 
 80     HeapWord* new_top = obj + size;
 81     set_top(new_top);
 82 
 83     assert(is_object_aligned(new_top), "new top breaks alignment: " PTR_FORMAT, p2i(new_top));
 84     assert(is_object_aligned(obj),     "obj is not aligned: "       PTR_FORMAT, p2i(obj));
 85 
 86     return obj;
 87   } else {
 88     return NULL;
 89   }
 90 }
 91 
 92 inline void ShenandoahHeapRegion::adjust_alloc_metadata(ShenandoahAllocRequest::Type type, size_t size) {
 93   switch (type) {
 94     case ShenandoahAllocRequest::_alloc_shared:
 95     case ShenandoahAllocRequest::_alloc_shared_gc:
 96       // Counted implicitly by tlab/gclab allocs
 97       break;
 98     case ShenandoahAllocRequest::_alloc_tlab:
 99       _tlab_allocs += size;
100       break;
101     case ShenandoahAllocRequest::_alloc_gclab:
102       _gclab_allocs += size;
103       break;
104     case ShenandoahAllocRequest::_alloc_plab:
105       _plab_allocs += size;
106       break;
107     default:
108       ShouldNotReachHere();
109   }
110 }
111 
112 inline void ShenandoahHeapRegion::increase_live_data_alloc_words(size_t s) {
113   internal_increase_live_data(s);
114 }
115 
116 inline void ShenandoahHeapRegion::increase_live_data_gc_words(size_t s) {
117   internal_increase_live_data(s);
118   if (ShenandoahPacing) {
119     ShenandoahHeap::heap()->pacer()->report_mark(s);
120   }
121 }
122 
123 inline void ShenandoahHeapRegion::internal_increase_live_data(size_t s) {
124   size_t new_live_data = Atomic::add(&_live_data, s, memory_order_relaxed);
125 #ifdef ASSERT
126   size_t live_bytes = new_live_data * HeapWordSize;
127   size_t used_bytes = used();
128   assert(live_bytes <= used_bytes,
129          "%s Region " SIZE_FORMAT " can't have more live data than used: " SIZE_FORMAT ", " SIZE_FORMAT " after adding " SIZE_FORMAT,
130          affiliation_name(affiliation()), index(), live_bytes, used_bytes, s * HeapWordSize);
131 #endif
132 }
133 
134 inline void ShenandoahHeapRegion::clear_live_data() {
135   Atomic::store(&_live_data, (size_t)0);
136 }
137 
138 inline size_t ShenandoahHeapRegion::get_live_data_words() const {
139   return Atomic::load(&_live_data);
140 }
141 
142 inline size_t ShenandoahHeapRegion::get_live_data_bytes() const {
143   return get_live_data_words() * HeapWordSize;
144 }
145 
146 inline bool ShenandoahHeapRegion::has_live() const {
147   return get_live_data_words() != 0;
148 }
149 
150 inline size_t ShenandoahHeapRegion::garbage() const {

157 }
158 
159 inline HeapWord* ShenandoahHeapRegion::get_update_watermark() const {
160   HeapWord* watermark = Atomic::load_acquire(&_update_watermark);
161   assert(bottom() <= watermark && watermark <= top(), "within bounds");
162   return watermark;
163 }
164 
165 inline void ShenandoahHeapRegion::set_update_watermark(HeapWord* w) {
166   assert(bottom() <= w && w <= top(), "within bounds");
167   Atomic::release_store(&_update_watermark, w);
168 }
169 
170 // Fast version that avoids synchronization, only to be used at safepoints.
171 inline void ShenandoahHeapRegion::set_update_watermark_at_safepoint(HeapWord* w) {
172   assert(bottom() <= w && w <= top(), "within bounds");
173   assert(SafepointSynchronize::is_at_safepoint(), "Should be at Shenandoah safepoint");
174   _update_watermark = w;
175 }
176 
177 inline void ShenandoahHeapRegion::clear_young_lab_flags() {
178   _has_young_lab = false;
179 }
180 
181 inline void ShenandoahHeapRegion::set_young_lab_flag() {
182   _has_young_lab = true;
183 }
184 
185 inline bool ShenandoahHeapRegion::has_young_lab_flag() {
186   return _has_young_lab;
187 }
188 
189 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHHEAPREGION_INLINE_HPP
< prev index next >