1 /** 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef PANDA_RUNTIME_MEM_GC_GC_SETTINGS_H 16 #define PANDA_RUNTIME_MEM_GC_GC_SETTINGS_H 17 18 #include <cstddef> 19 #include <string_view> 20 #include <cstdint> 21 22 namespace panda { 23 class RuntimeOptions; 24 } // namespace panda 25 26 namespace panda::mem { 27 28 enum class NativeGcTriggerType { INVALID_NATIVE_GC_TRIGGER, NO_NATIVE_GC_TRIGGER, SIMPLE_STRATEGY }; NativeGcTriggerTypeFromString(std::string_view native_gc_trigger_type_str)29 inline NativeGcTriggerType NativeGcTriggerTypeFromString(std::string_view native_gc_trigger_type_str) 30 { 31 if (native_gc_trigger_type_str == "no-native-gc-trigger") { 32 return NativeGcTriggerType::NO_NATIVE_GC_TRIGGER; 33 } 34 if (native_gc_trigger_type_str == "simple-strategy") { 35 return NativeGcTriggerType::SIMPLE_STRATEGY; 36 } 37 return NativeGcTriggerType::INVALID_NATIVE_GC_TRIGGER; 38 } 39 40 class GCSettings { 41 public: 42 GCSettings() = default; 43 explicit GCSettings(const RuntimeOptions &options, panda_file::SourceLang lang); 44 45 /** 46 * \brief if true then enable tracing 47 */ 48 bool IsGcEnableTracing() const; 49 50 /** 51 * \brief type of native trigger 52 */ 53 NativeGcTriggerType GetNativeGcTriggerType() const; 54 55 /** 56 * \brief dump heap at the beginning and the end of GC 57 */ 58 bool IsDumpHeap() const; 59 60 /** 61 * \brief true if concurrency enabled 62 */ 63 bool IsConcurrencyEnabled() const; 64 65 /** 66 * \brief true if GC should be running in place 67 */ 68 bool RunGCInPlace() const; 69 70 /** 71 * \brief use FastHeapVerifier if true 72 */ 73 bool EnableFastHeapVerifier() const; 74 75 /** 76 * \brief true if heap verification before GC enabled 77 */ 78 bool PreGCHeapVerification() const; 79 80 /** 81 * \brief true if heap verification during GC enabled 82 */ 83 bool IntoGCHeapVerification() const; 84 85 /** 86 * \brief true if heap verification after GC enabled 87 */ 88 bool PostGCHeapVerification() const; 89 90 /** 91 * \brief if true then fail execution if heap verifier found heap corruption 92 */ 93 bool FailOnHeapVerification() const; 94 95 /** 96 * \brief garbage rate threshold of a tenured region to be included into a mixed collection 97 */ 98 double G1RegionGarbageRateThreshold() const; 99 100 /** 101 * \brief minimum percentage of alive bytes in young region to promote it into tenured without moving for G1GC 102 */ 103 double G1PromotionRegionAliveRate() const; 104 105 /** 106 * \brief Specify if we need to track removing objects 107 * (i.e. update objects count in memstats and log removed objects) during the G1GC collection or not. 108 */ 109 bool G1TrackFreedObjects() const; 110 111 /** 112 * \brief if not zero and gc supports workers, create a gc workers and try to use them 113 */ 114 size_t GCWorkersCount() const; 115 116 void SetGCWorkersCount(size_t value); 117 118 /** 119 * \brief Max stack size for marking in main thread, if it exceeds we will send a new task to workers, 120 * 0 means unlimited. 121 */ 122 size_t GCRootMarkingStackMaxSize() const; 123 124 /** 125 * \brief Max stack size for marking in a gc worker, if it exceeds we will send a new task to workers, 126 * 0 means unlimited. 127 */ 128 size_t GCWorkersMarkingStackMaxSize() const; 129 130 /** 131 * \brief size of young-space 132 */ 133 uint64_t YoungSpaceSize() const; 134 135 /** 136 * \brief true if print INFO log to get more detailed information in GC. 137 */ 138 bool LogDetailedGCInfoEnabled() const; 139 140 /** 141 * \brief true if we want to do marking phase in multithreading mode. 142 */ 143 bool ParallelMarkingEnabled() const; 144 145 void SetParallelMarkingEnabled(bool value); 146 147 /** 148 * \brief true if we want to do compacting phase in multithreading mode. 149 */ 150 bool ParallelCompactingEnabled() const; 151 152 void SetParallelCompactingEnabled(bool value); 153 154 /** 155 * \brief true if G1 should updates remsets concurrently 156 */ 157 bool G1EnableConcurrentUpdateRemset() const; 158 159 /** 160 * \brief 161 */ 162 size_t G1MinConcurrentCardsToProcess() const; 163 164 private: 165 bool is_gc_enable_tracing_ = false; /// if true then enable tracing 166 NativeGcTriggerType native_gc_trigger_type_ = { 167 NativeGcTriggerType::INVALID_NATIVE_GC_TRIGGER}; /// type of native trigger 168 bool is_dump_heap_ = false; /// dump heap at the beginning and the end of GC 169 bool is_concurrency_enabled_ = true; /// true if concurrency enabled 170 bool run_gc_in_place_ = false; /// true if GC should be running in place 171 bool enable_fast_heap_verifier_ = true; /// use FastHeapVerifier if true 172 bool pre_gc_heap_verification_ = false; /// true if heap verification before GC enabled 173 bool into_gc_heap_verification_ = false; /// true if heap verification during GC enabled 174 bool post_gc_heap_verification_ = false; /// true if heap verification after GC enabled 175 bool fail_on_heap_verification_ = false; /// if true then fail execution if heap verifier found heap corruption 176 double g1_region_garbage_rate_threshold_ = 177 0; /// garbage rate threshold of a tenured region to be included into a mixed collection 178 uint32_t g1_promotion_region_alive_rate_ = 179 0; /// minimum percentage of alive bytes in young region to promote it into tenured without moving for G1GC 180 size_t gc_workers_count_ = 0; /// if not zero and gc supports workers, create a gc workers and try to use them 181 /// Max stack size for marking in main thread, if it exceeds we will send a new task to workers, 0 means unlimited. 182 size_t gc_root_marking_stack_max_size_ = 0; 183 /// Max stack size for marking in a gc worker, if it exceeds we will send a new task to workers, 0 means unlimited. 184 size_t gc_workers_marking_stack_max_size_ = 0; 185 bool g1_track_freed_objects_ = false; /// if we need to track removing objects during the G1GC collection or not 186 uint64_t young_space_size_ = 0; /// size of young-space 187 bool log_detailed_gc_info_enabled_ = false; /// true if print INFO log to get more detailed information in GC. 188 bool parallel_marking_enabled_ = false; /// true if we want to do marking phase in multithreading mode. 189 bool parallel_compacting_enabled_ = false; /// true if we want to do compacting phase in multithreading mode. 190 bool g1_enable_concurrent_update_remset_ = false; /// true if G1 should updates remsets concurrently 191 size_t g1_min_concurrent_cards_to_process_ = 0; 192 }; 193 194 } // namespace panda::mem 195 196 #endif // PANDA_RUNTIME_MEM_GC_GC_SETTINGS_H