1 /* 2 * Copyright (c) 2013, 2015, Red Hat, Inc. and/or its affiliates. 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_SHENANDOAHHEAPREGIONSET_HPP 25 #define SHARE_VM_GC_SHENANDOAH_SHENANDOAHHEAPREGIONSET_HPP 26 27 #include "gc/shenandoah/shenandoahHeapRegion.hpp" 28 29 30 class ShenandoahHeapRegionSet : public CHeapObj<mtGC> { 31 private: 32 ShenandoahHeapRegion** _regions; 33 // current region to be returned from get_next() 34 ShenandoahHeapRegion** _current; 35 ShenandoahHeapRegion** _next; 36 37 // last inserted region. 38 ShenandoahHeapRegion** _next_free; 39 ShenandoahHeapRegion** _concurrent_next_free; 40 41 // Maximum size of the set. 42 const size_t _max_regions; 43 44 size_t _garbage_threshold; 45 size_t _free_threshold; 46 47 size_t _available; 48 size_t _used; 49 50 void choose_collection_set(ShenandoahHeapRegion** regions, size_t length); 51 void choose_collection_set_min_garbage(ShenandoahHeapRegion** regions, size_t length, size_t min_garbage); 52 void choose_free_set(ShenandoahHeapRegion** regions, size_t length); 53 54 public: 55 ShenandoahHeapRegionSet(size_t max_regions); 56 57 ShenandoahHeapRegionSet(size_t max_regions, ShenandoahHeapRegion** regions, size_t num_regions); 58 59 ~ShenandoahHeapRegionSet(); 60 61 void set_garbage_threshold(size_t minimum_garbage) { _garbage_threshold = minimum_garbage;} 62 void set_free_threshold(size_t minimum_free) { _free_threshold = minimum_free;} 63 64 /** 65 * Appends a region to the set. This is implemented to be concurrency-safe. 66 */ 67 void append(ShenandoahHeapRegion* region); 68 69 void clear(); 70 71 size_t length(); 72 size_t used_regions() { 73 return _current - _regions; 74 } 75 size_t available_regions(); 76 void print(); 77 78 size_t garbage(); 79 size_t used(); 80 size_t live_data(); 81 size_t reclaimed() {return _reclaimed;} 82 83 /** 84 * Returns a pointer to the current region. 85 */ 86 ShenandoahHeapRegion* current(); 87 88 /** 89 * Gets the next region for allocation (from free-list). 90 * If multiple threads are competing, one will succeed to 91 * increment to the next region, the others will fail and return 92 * the region that the succeeding thread got. 93 */ 94 ShenandoahHeapRegion* get_next(); 95 96 /** 97 * Claims next region for processing. This is implemented to be concurrency-safe. 98 */ 99 ShenandoahHeapRegion* claim_next(); 100 101 void choose_collection_and_free_sets(ShenandoahHeapRegionSet* col_set, ShenandoahHeapRegionSet* free_set); 102 void choose_collection_and_free_sets_min_garbage(ShenandoahHeapRegionSet* col_set, ShenandoahHeapRegionSet* free_set, size_t min_garbage); 103 104 // Check for unreachable humongous regions and reclaim them. 105 void reclaim_humongous_regions(); 106 107 void set_concurrent_iteration_safe_limits(); 108 109 void decrease_available(size_t num_bytes); 110 111 size_t available() const; 112 size_t used() const; 113 114 private: 115 void reclaim_humongous_region_at(ShenandoahHeapRegion** r); 116 117 ShenandoahHeapRegion** limit_region(ShenandoahHeapRegion** region); 118 size_t _reclaimed; 119 120 }; 121 122 #endif //SHARE_VM_GC_SHENANDOAH_SHENANDOAHHEAPREGIONSET_HPP