1 /* 2 * Copyright (c) 2015, Red Hat, Inc. and/or its affiliates. 3 * 4 * This code is free software; you can redistribute it and/or modify it 5 * under the terms of the GNU General Public License version 2 only, as 6 * published by the Free Software Foundation. 7 * 8 * This code is distributed in the hope that it will be useful, but WITHOUT 9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 * version 2 for more details (a copy is included in the LICENSE file that 12 * accompanied this code). 13 * 14 * You should have received a copy of the GNU General Public License version 15 * 2 along with this work; if not, write to the Free Software Foundation, 16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 17 * 18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 19 * or visit www.oracle.com if you need additional information or have any 20 * questions. 21 * 22 */ 23 24 #ifndef SHARE_VM_GC_SHENANDOAH_SHENANDOAHHEAPREGION_INLINE_HPP 25 #define SHARE_VM_GC_SHENANDOAH_SHENANDOAHHEAPREGION_INLINE_HPP 26 27 #include "gc_implementation/shenandoah/shenandoahHeap.hpp" 28 #include "gc_implementation/shenandoah/shenandoahHeapRegion.hpp" 29 #include "gc_implementation/shenandoah/shenandoahPacer.inline.hpp" 30 #include "runtime/atomic.hpp" 31 32 HeapWord* ShenandoahHeapRegion::allocate(size_t size, ShenandoahHeap::AllocType type) { 33 _heap->assert_heaplock_or_safepoint(); 34 35 HeapWord* obj = top(); 36 if (pointer_delta(end(), obj) >= size) { 37 make_regular_allocation(); 38 adjust_alloc_metadata(type, size); 39 40 HeapWord* new_top = obj + size; 41 set_top(new_top); 42 assert(is_aligned(obj) && is_aligned(new_top), "checking alignment"); 43 44 return obj; 45 } else { 46 return NULL; 47 } 48 } 49 50 inline void ShenandoahHeapRegion::adjust_alloc_metadata(ShenandoahHeap::AllocType type, size_t size) { 51 switch (type) { 52 case ShenandoahHeap::_alloc_shared: 53 case ShenandoahHeap::_alloc_shared_gc: 54 _shared_allocs += size; 55 break; 56 case ShenandoahHeap::_alloc_tlab: 57 _tlab_allocs += size; 58 break; 59 case ShenandoahHeap::_alloc_gclab: 60 _gclab_allocs += size; 61 break; 62 default: 63 ShouldNotReachHere(); 64 } 65 } 66 67 inline void ShenandoahHeapRegion::increase_live_data_alloc_words(size_t s) { 68 if (!ShenandoahAllocImplicitLive) { 69 return; 70 } 71 internal_increase_live_data(s); 72 } 73 74 inline void ShenandoahHeapRegion::increase_live_data_gc_words(size_t s) { 75 internal_increase_live_data(s); 76 if (ShenandoahPacing) { 77 _pacer->report_mark(s); 78 } 79 } 80 81 inline void ShenandoahHeapRegion::internal_increase_live_data(size_t s) { 82 assert(s < (size_t)max_jint, "sanity"); 83 size_t new_live_data = (size_t)(Atomic::add((jint)s, &_live_data)); 84 #ifdef ASSERT 85 size_t live_bytes = new_live_data * HeapWordSize; 86 size_t used_bytes = used(); 87 assert(live_bytes <= used_bytes, 88 err_msg("can't have more live data than used: " SIZE_FORMAT ", " SIZE_FORMAT, live_bytes, used_bytes)); 89 #endif 90 } 91 92 #endif // SHARE_VM_GC_SHENANDOAH_SHENANDOAHHEAPREGION_INLINE_HPP