1 /* 2 * Copyright (c) 2020, 2021 Amazon.com, Inc. and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 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_SHENANDOAHGENERATION_HPP 26 #define SHARE_VM_GC_SHENANDOAH_SHENANDOAHGENERATION_HPP 27 28 #include "memory/allocation.hpp" 29 #include "gc/shenandoah/heuristics/shenandoahOldHeuristics.hpp" 30 #include "gc/shenandoah/mode/shenandoahGenerationalMode.hpp" 31 #include "gc/shenandoah/shenandoahLock.hpp" 32 #include "gc/shenandoah/shenandoahMarkingContext.hpp" 33 34 class ShenandoahHeapRegion; 35 class ShenandoahHeapRegionClosure; 36 class ShenandoahReferenceProcessor; 37 38 class ShenandoahGeneration : public CHeapObj<mtGC> { 39 private: 40 GenerationMode const _generation_mode; 41 42 // Marking task queues and completeness 43 ShenandoahObjToScanQueueSet* _task_queues; 44 ShenandoahSharedFlag _is_marking_complete; 45 46 ShenandoahReferenceProcessor* const _ref_processor; 47 48 protected: 49 // Usage 50 size_t _affiliated_region_count; 51 volatile size_t _used; 52 volatile size_t _bytes_allocated_since_gc_start; 53 size_t _max_capacity; 54 size_t _soft_max_capacity; 55 56 size_t _adjusted_capacity; 57 58 ShenandoahHeuristics* _heuristics; 59 public: 60 ShenandoahGeneration(GenerationMode generation_mode, uint max_workers, size_t max_capacity, size_t soft_max_capacity); 61 ~ShenandoahGeneration(); 62 63 inline GenerationMode generation_mode() const { return _generation_mode; } 64 65 inline ShenandoahHeuristics* heuristics() const { return _heuristics; } 66 67 ShenandoahReferenceProcessor* ref_processor() { return _ref_processor; } 68 69 virtual const char* name() const = 0; 70 71 virtual ShenandoahHeuristics* initialize_heuristics(ShenandoahMode* gc_mode); 72 73 virtual size_t soft_max_capacity() const { return _soft_max_capacity; } 74 virtual size_t max_capacity() const { return _max_capacity; } 75 virtual size_t used_regions() const; 76 virtual size_t used_regions_size() const; 77 virtual size_t free_unaffiliated_regions() const; 78 virtual size_t used() const { return _used; } 79 virtual size_t available() const; 80 81 // During evacuation and update-refs, some memory may be shifted between generations. In particular, memory 82 // may be loaned by old-gen to young-gen based on the promise the loan will be promptly repaid from the memory reclaimed 83 // when the current collection set is recycled. The capacity adjustment also takes into consideration memory that is 84 // set aside within each generation to hold the results of evacuation, but not promotion, into that region. Promotions 85 // into old-gen are bounded by adjusted_available() whereas evacuations into old-gen are pre-committed. 86 virtual size_t adjusted_available() const; 87 88 // Both of following return new value of available 89 virtual size_t adjust_available(intptr_t adjustment); 90 virtual size_t unadjust_available(); 91 92 size_t bytes_allocated_since_gc_start(); 93 void reset_bytes_allocated_since_gc_start(); 94 void increase_allocated(size_t bytes); 95 96 void set_soft_max_capacity(size_t soft_max_capacity) { 97 _soft_max_capacity = soft_max_capacity; 98 } 99 100 void log_status() const; 101 102 // Used directly by FullGC 103 void reset_mark_bitmap(); 104 105 // Used by concurrent and degenerated GC to reset remembered set. 106 void swap_remembered_set(); 107 108 // Update the read cards with the state of the write table (write table is not cleared). 109 void merge_write_table(); 110 111 // Used by concurrent and degenerated GC to reset regions. 112 void prepare_gc(bool do_old_gc_bootstrap); 113 114 // Return true iff prepared collection set includes at least one old-gen HeapRegion. 115 virtual void prepare_regions_and_collection_set(bool concurrent); 116 117 // Cancel marking (used by Full collect and when cancelling cycle). 118 virtual void cancel_marking(); 119 120 // Return true if this region is affiliated with this generation. 121 virtual bool contains(ShenandoahHeapRegion* region) const = 0; 122 123 // Return true if this object is affiliated with this generation. 124 virtual bool contains(oop obj) const = 0; 125 126 // Apply closure to all regions affiliated with this generation. 127 virtual void parallel_heap_region_iterate(ShenandoahHeapRegionClosure* cl) = 0; 128 129 // Apply closure to all regions affiliated with this generation (single threaded). 130 virtual void heap_region_iterate(ShenandoahHeapRegionClosure* cl) = 0; 131 132 // This is public to support cancellation of marking when a Full cycle is started. 133 virtual void set_concurrent_mark_in_progress(bool in_progress) = 0; 134 135 // Check the bitmap only for regions belong to this generation. 136 bool is_bitmap_clear(); 137 138 // We need to track the status of marking for different generations. 139 bool is_mark_complete(); 140 void set_mark_complete(); 141 void set_mark_incomplete(); 142 143 ShenandoahMarkingContext* complete_marking_context(); 144 145 // Task queues 146 ShenandoahObjToScanQueueSet* task_queues() const { return _task_queues; } 147 virtual void reserve_task_queues(uint workers); 148 virtual ShenandoahObjToScanQueueSet* old_gen_task_queues() const; 149 150 // Scan remembered set at start of concurrent young-gen marking. */ 151 void scan_remembered_set(); 152 153 void increment_affiliated_region_count(); 154 void decrement_affiliated_region_count(); 155 156 void clear_used(); 157 void increase_used(size_t bytes); 158 void decrease_used(size_t bytes); 159 160 virtual bool is_concurrent_mark_in_progress() = 0; 161 void confirm_heuristics_mode(); 162 }; 163 164 #endif // SHARE_VM_GC_SHENANDOAH_SHENANDOAHGENERATION_HPP