1 2 /* 3 * Copyright (c) 2016, Red Hat, Inc. and/or its affiliates. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_VM_GC_SHENANDOAH_SHENANDOAHFREESET_HPP 26 #define SHARE_VM_GC_SHENANDOAH_SHENANDOAHFREESET_HPP 27 28 #include "gc/shenandoah/shenandoahHeapRegionSet.hpp" 29 #include "shenandoahHeap.hpp" 30 31 class ShenandoahFreeSet : public CHeapObj<mtGC> { 32 private: 33 ShenandoahHeapRegionSet* _regions; 34 CHeapBitMap _free_bitmap; 35 size_t _max; 36 37 // Left-most and right-most region indexes. There are no free regions outside 38 // of [left-most; right-most] index intervals 39 size_t _leftmost, _rightmost; 40 41 size_t _capacity; 42 size_t _used; 43 44 void assert_bounds() const PRODUCT_RETURN; 45 void assert_heaplock_owned_by_current_thread() const PRODUCT_RETURN; 46 47 bool is_free(size_t idx) const; 48 49 HeapWord* allocate_small_memory(size_t words_size, ShenandoahHeap::AllocType type, bool& in_new_region); 50 HeapWord* allocate_large_memory(size_t words_size); 51 52 HeapWord* try_allocate_in(size_t word_size, ShenandoahHeap::AllocType type, size_t idx, bool& in_new_region); 53 HeapWord* allocate_single(size_t word_size, ShenandoahHeap::AllocType type, bool& in_new_region); 54 HeapWord* allocate_contiguous(size_t words_size); 55 56 void adjust_bounds(); 57 58 void increase_used(size_t amount); 59 void clear_internal(); 60 61 size_t count() const { return _free_bitmap.count_one_bits(); } 62 63 bool implicit_live(ShenandoahHeap::AllocType type) const; 64 public: 65 ShenandoahFreeSet(ShenandoahHeapRegionSet* regions, size_t max_regions); 66 67 void add_region(ShenandoahHeapRegion* r); 68 void clear(); 69 70 size_t capacity() const { return _capacity; } 71 size_t used() const { return _used; } 72 size_t available() const { 73 assert(_used <= _capacity, "must use less than capacity"); 74 return _capacity - _used; 75 } 76 77 HeapWord* allocate(size_t words_size, ShenandoahHeap::AllocType type, bool &in_new_region); 78 size_t unsafe_peek_free() const; 79 80 void print_on(outputStream* out) const; 81 }; 82 83 #endif //SHARE_VM_GC_SHENANDOAH_SHENANDOAHFREESET_HPP