Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/gc_implementation/shenandoah/shenandoahHeapRegionSet.cpp
38920 views
/*1* Copyright (c) 2013, 2019, 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#include "precompiled.hpp"24#include "gc_implementation/shenandoah/shenandoahHeapRegionSet.inline.hpp"25#include "gc_implementation/shenandoah/shenandoahHeap.inline.hpp"26#include "gc_implementation/shenandoah/shenandoahHeapRegion.hpp"27#include "gc_implementation/shenandoah/shenandoahUtils.hpp"28#include "runtime/atomic.hpp"29#include "utilities/copy.hpp"3031ShenandoahHeapRegionSetIterator::ShenandoahHeapRegionSetIterator(const ShenandoahHeapRegionSet* const set) :32_set(set), _heap(ShenandoahHeap::heap()), _current_index(0) {}3334void ShenandoahHeapRegionSetIterator::reset(const ShenandoahHeapRegionSet* const set) {35_set = set;36_current_index = 0;37}3839ShenandoahHeapRegionSet::ShenandoahHeapRegionSet() :40_heap(ShenandoahHeap::heap()),41_map_size(_heap->num_regions()),42_region_size_bytes_shift(ShenandoahHeapRegion::region_size_bytes_shift()),43_set_map(NEW_C_HEAP_ARRAY(jbyte, _map_size, mtGC)),44// Bias set map's base address for fast test if an oop is in set45_biased_set_map(_set_map - ((uintx)_heap->base() >> _region_size_bytes_shift)),46_region_count(0)47{48// Use 1-byte data type49STATIC_ASSERT(sizeof(jbyte) == 1);5051// Initialize cset map52Copy::zero_to_bytes(_set_map, _map_size);53}5455ShenandoahHeapRegionSet::~ShenandoahHeapRegionSet() {56FREE_C_HEAP_ARRAY(jbyte, _set_map, mtGC);57}5859void ShenandoahHeapRegionSet::add_region(ShenandoahHeapRegion* r) {60assert(!is_in(r), "Already in collection set");61_set_map[r->index()] = 1;62_region_count++;63}6465bool ShenandoahHeapRegionSet::add_region_check_for_duplicates(ShenandoahHeapRegion* r) {66if (!is_in(r)) {67add_region(r);68return true;69} else {70return false;71}72}7374void ShenandoahHeapRegionSet::remove_region(ShenandoahHeapRegion* r) {75assert(ShenandoahSafepoint::is_at_shenandoah_safepoint(), "Must be at a safepoint");76assert(Thread::current()->is_VM_thread(), "Must be VMThread");77assert(is_in(r), "Not in region set");78_set_map[r->index()] = 0;79_region_count --;80}8182void ShenandoahHeapRegionSet::clear() {83assert(ShenandoahSafepoint::is_at_shenandoah_safepoint(), "Must be at a safepoint");84Copy::zero_to_bytes(_set_map, _map_size);8586_region_count = 0;87}8889ShenandoahHeapRegion* ShenandoahHeapRegionSetIterator::claim_next() {90size_t num_regions = _heap->num_regions();91if (_current_index >= (jint)num_regions) {92return NULL;93}9495jint saved_current = _current_index;96size_t index = (size_t)saved_current;9798while(index < num_regions) {99if (_set->is_in(index)) {100jint cur = Atomic::cmpxchg((jint)(index + 1), &_current_index, saved_current);101assert(cur >= (jint)saved_current, "Must move forward");102if (cur == saved_current) {103assert(_set->is_in(index), "Invariant");104return _heap->get_region(index);105} else {106index = (size_t)cur;107saved_current = cur;108}109} else {110index ++;111}112}113return NULL;114}115116ShenandoahHeapRegion* ShenandoahHeapRegionSetIterator::next() {117size_t num_regions = _heap->num_regions();118for (size_t index = (size_t)_current_index; index < num_regions; index ++) {119if (_set->is_in(index)) {120_current_index = (jint)(index + 1);121return _heap->get_region(index);122}123}124125return NULL;126}127128void ShenandoahHeapRegionSet::print_on(outputStream* out) const {129out->print_cr("Region Set : " SIZE_FORMAT "", count());130131debug_only(size_t regions = 0;)132for (size_t index = 0; index < _heap->num_regions(); index ++) {133if (is_in(index)) {134_heap->get_region(index)->print_on(out);135debug_only(regions ++;)136}137}138assert(regions == count(), "Must match");139}140141142