1 /* 2 * Copyright (c) 2015, 2018, Red Hat, Inc. All rights reserved. 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, ShenandoahAllocRequest::Type 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(ShenandoahAllocRequest::Type type, size_t size) { 51 switch (type) { 52 case ShenandoahAllocRequest::_alloc_shared: 53 case ShenandoahAllocRequest::_alloc_shared_gc: 54 _shared_allocs += size; 55 break; 56 case ShenandoahAllocRequest::_alloc_tlab: 57 _tlab_allocs += size; 58 break; 59 case ShenandoahAllocRequest::_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 internal_increase_live_data(s); 69 } 70 71 inline void ShenandoahHeapRegion::increase_live_data_gc_words(size_t s) { 72 internal_increase_live_data(s); 73 if (ShenandoahPacing) { 74 _heap->pacer()->report_mark(s); 75 } 76 } 77 78 inline void ShenandoahHeapRegion::internal_increase_live_data(size_t s) { 79 assert(s < (size_t)max_jint, "sanity"); 80 size_t new_live_data = (size_t)(Atomic::add((jint)s, &_live_data)); 81 #ifdef ASSERT 82 size_t live_bytes = new_live_data * HeapWordSize; 83 size_t used_bytes = used(); 84 assert(live_bytes <= used_bytes, 85 err_msg("can't have more live data than used: " SIZE_FORMAT ", " SIZE_FORMAT, live_bytes, used_bytes)); 86 #endif 87 } 88 89 #endif // SHARE_VM_GC_SHENANDOAH_SHENANDOAHHEAPREGION_INLINE_HPP