Path: blob/master/src/hotspot/share/gc/shenandoah/shenandoahFreeSet.hpp
40957 views
/*1* Copyright (c) 2016, 2019, Red Hat, Inc. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 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 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_GC_SHENANDOAH_SHENANDOAHFREESET_HPP25#define SHARE_GC_SHENANDOAH_SHENANDOAHFREESET_HPP2627#include "gc/shenandoah/shenandoahHeapRegionSet.hpp"28#include "gc/shenandoah/shenandoahHeap.hpp"2930class ShenandoahFreeSet : public CHeapObj<mtGC> {31private:32ShenandoahHeap* const _heap;33CHeapBitMap _mutator_free_bitmap;34CHeapBitMap _collector_free_bitmap;35size_t _max;3637// Left-most and right-most region indexes. There are no free regions outside38// of [left-most; right-most] index intervals39size_t _mutator_leftmost, _mutator_rightmost;40size_t _collector_leftmost, _collector_rightmost;4142size_t _capacity;43size_t _used;4445void assert_bounds() const NOT_DEBUG_RETURN;4647bool is_mutator_free(size_t idx) const;48bool is_collector_free(size_t idx) const;4950HeapWord* try_allocate_in(ShenandoahHeapRegion* region, ShenandoahAllocRequest& req, bool& in_new_region);51HeapWord* allocate_single(ShenandoahAllocRequest& req, bool& in_new_region);52HeapWord* allocate_contiguous(ShenandoahAllocRequest& req);5354void flip_to_gc(ShenandoahHeapRegion* r);5556void recompute_bounds();57void adjust_bounds();58bool touches_bounds(size_t num) const;5960void increase_used(size_t amount);61void clear_internal();6263size_t collector_count() const { return _collector_free_bitmap.count_one_bits(); }64size_t mutator_count() const { return _mutator_free_bitmap.count_one_bits(); }6566void try_recycle_trashed(ShenandoahHeapRegion *r);6768bool can_allocate_from(ShenandoahHeapRegion *r);69size_t alloc_capacity(ShenandoahHeapRegion *r);70bool has_no_alloc_capacity(ShenandoahHeapRegion *r);7172public:73ShenandoahFreeSet(ShenandoahHeap* heap, size_t max_regions);7475void clear();76void rebuild();7778void recycle_trash();7980void log_status();8182size_t capacity() const { return _capacity; }83size_t used() const { return _used; }84size_t available() const {85assert(_used <= _capacity, "must use less than capacity");86return _capacity - _used;87}8889HeapWord* allocate(ShenandoahAllocRequest& req, bool& in_new_region);90size_t unsafe_peek_free() const;9192double internal_fragmentation();93double external_fragmentation();9495void print_on(outputStream* out) const;96};9798#endif // SHARE_GC_SHENANDOAH_SHENANDOAHFREESET_HPP99100101