Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/gc_implementation/shenandoah/shenandoahHeapRegion.inline.hpp
38920 views
/*1* Copyright (c) 2015, 2018, Red Hat, Inc. All rights reserved.2*3* This code is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License version 2 only, as5* published by the Free Software Foundation.6*7* This code is distributed in the hope that it will be useful, but WITHOUT8* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or9* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License10* version 2 for more details (a copy is included in the LICENSE file that11* accompanied this code).12*13* You should have received a copy of the GNU General Public License version14* 2 along with this work; if not, write to the Free Software Foundation,15* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.16*17* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA18* or visit www.oracle.com if you need additional information or have any19* questions.20*21*/2223#ifndef SHARE_VM_GC_SHENANDOAH_SHENANDOAHHEAPREGION_INLINE_HPP24#define SHARE_VM_GC_SHENANDOAH_SHENANDOAHHEAPREGION_INLINE_HPP2526#include "gc_implementation/shenandoah/shenandoahHeap.inline.hpp"27#include "gc_implementation/shenandoah/shenandoahHeapRegion.hpp"28#include "gc_implementation/shenandoah/shenandoahPacer.inline.hpp"29#include "runtime/atomic.hpp"3031HeapWord* ShenandoahHeapRegion::allocate(size_t size, ShenandoahAllocRequest::Type type) {32shenandoah_assert_heaplocked_or_safepoint();3334assert(is_object_aligned((intptr_t)size), err_msg("alloc size breaks alignment: " SIZE_FORMAT, size));3536HeapWord* obj = top();37if (pointer_delta(end(), obj) >= size) {38make_regular_allocation();39adjust_alloc_metadata(type, size);4041HeapWord* new_top = obj + size;42set_top(new_top);4344assert(is_object_aligned((intptr_t)new_top), err_msg("new top breaks alignment: " PTR_FORMAT, p2i(new_top)));45assert(is_object_aligned((intptr_t)obj), err_msg("obj is not aligned: " PTR_FORMAT, p2i(obj)));4647return obj;48} else {49return NULL;50}51}5253inline void ShenandoahHeapRegion::adjust_alloc_metadata(ShenandoahAllocRequest::Type type, size_t size) {54switch (type) {55case ShenandoahAllocRequest::_alloc_shared:56case ShenandoahAllocRequest::_alloc_shared_gc:57// Counted implicitly by tlab/gclab allocs58break;59case ShenandoahAllocRequest::_alloc_tlab:60_tlab_allocs += size;61break;62case ShenandoahAllocRequest::_alloc_gclab:63_gclab_allocs += size;64break;65default:66ShouldNotReachHere();67}68}6970void ShenandoahHeapRegion::clear_live_data() {71OrderAccess::release_store_fence((volatile jint*)&_live_data, 0);72}7374inline void ShenandoahHeapRegion::increase_live_data_alloc_words(size_t s) {75internal_increase_live_data(s);76}7778inline void ShenandoahHeapRegion::increase_live_data_gc_words(size_t s) {79internal_increase_live_data(s);80if (ShenandoahPacing) {81ShenandoahHeap::heap()->pacer()->report_mark(s);82}83}8485inline void ShenandoahHeapRegion::internal_increase_live_data(size_t s) {86assert(s < (size_t)max_jint, "sanity");87size_t new_live_data = (size_t)(Atomic::add((jint)s, &_live_data));88#ifdef ASSERT89size_t live_bytes = new_live_data * HeapWordSize;90size_t used_bytes = used();91assert(live_bytes <= used_bytes,92err_msg("can't have more live data than used: " SIZE_FORMAT ", " SIZE_FORMAT, live_bytes, used_bytes));93#endif94}9596size_t ShenandoahHeapRegion::get_live_data_words() const {97jint v = OrderAccess::load_acquire((volatile jint*)&_live_data);98assert(v >= 0, "sanity");99return (size_t)v;100}101102size_t ShenandoahHeapRegion::get_live_data_bytes() const {103return get_live_data_words() * HeapWordSize;104}105106bool ShenandoahHeapRegion::has_live() const {107return get_live_data_words() != 0;108}109110size_t ShenandoahHeapRegion::garbage() const {111assert(used() >= get_live_data_bytes(), err_msg("Live Data must be a subset of used() live: " SIZE_FORMAT " used: " SIZE_FORMAT,112get_live_data_bytes(), used()));113size_t result = used() - get_live_data_bytes();114return result;115}116117inline HeapWord* ShenandoahHeapRegion::get_update_watermark() const {118HeapWord* watermark = (HeapWord*)OrderAccess::load_ptr_acquire(&_update_watermark);119assert(bottom() <= watermark && watermark <= top(), "within bounds");120return watermark;121}122123inline void ShenandoahHeapRegion::set_update_watermark(HeapWord* w) {124assert(bottom() <= w && w <= top(), "within bounds");125OrderAccess::release_store_ptr(&_update_watermark, w);126}127128// Fast version that avoids synchronization, only to be used at safepoints.129inline void ShenandoahHeapRegion::set_update_watermark_at_safepoint(HeapWord* w) {130assert(bottom() <= w && w <= top(), "within bounds");131assert(SafepointSynchronize::is_at_safepoint(), "Should be at Shenandoah safepoint");132_update_watermark = w;133}134135#endif // SHARE_VM_GC_SHENANDOAH_SHENANDOAHHEAPREGION_INLINE_HPP136137138