• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2022-2024 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 ark {
23 class RuntimeOptions;
24 }  // namespace ark
25 
26 namespace ark::mem {
27 
28 enum class NativeGcTriggerType { INVALID_NATIVE_GC_TRIGGER, NO_NATIVE_GC_TRIGGER, SIMPLE_STRATEGY };
NativeGcTriggerTypeFromString(std::string_view nativeGcTriggerTypeStr)29 inline NativeGcTriggerType NativeGcTriggerTypeFromString(std::string_view nativeGcTriggerTypeStr)
30 {
31     if (nativeGcTriggerTypeStr == "no-native-gc-trigger") {
32         return NativeGcTriggerType::NO_NATIVE_GC_TRIGGER;
33     }
34     if (nativeGcTriggerTypeStr == "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     /// @brief if true then enable tracing
46     bool IsGcEnableTracing() const;
47 
48     /// @brief type of native trigger
49     NativeGcTriggerType GetNativeGcTriggerType() const;
50 
51     /// @brief dump heap at the beginning and the end of GC
52     bool IsDumpHeap() const;
53 
54     /// @brief true if concurrency enabled
55     bool IsConcurrencyEnabled() const;
56 
57     /// @brief true if explicit GC should be running in concurrent
58     bool IsExplicitConcurrentGcEnabled() const;
59 
60     /// @brief true if GC should be running in place
61     bool RunGCInPlace() const;
62 
63     /// @brief use FastHeapVerifier if true
64     bool EnableFastHeapVerifier() const;
65 
66     /// @brief true if heap verification before GC enabled
67     bool PreGCHeapVerification() const;
68 
69     /// @brief true if heap verification during GC enabled
70     bool IntoGCHeapVerification() const;
71 
72     /// @brief true if heap verification after GC enabled
73     bool PostGCHeapVerification() const;
74 
75     /// true if heap verification before G1-GC concurrent phase enabled
76     bool BeforeG1ConcurrentHeapVerification() const;
77 
78     /// @brief if true then fail execution if heap verifier found heap corruption
79     bool FailOnHeapVerification() const;
80 
81     /// @brief if true then run gc every savepoint
82     bool RunGCEverySafepoint() const;
83 
84     /// @brief garbage rate threshold of a tenured region to be included into a mixed collection
85     double G1RegionGarbageRateThreshold() const;
86 
87     /// @brief runs full collection one of N times in GC thread
88     uint32_t FullGCBombingFrequency() const;
89 
90     /// @brief specify a max number of tenured regions which can be collected at mixed collection in G1GC.
91     uint32_t GetG1NumberOfTenuredRegionsAtMixedCollection() const;
92 
93     /// @brief minimum percentage of alive bytes in young region to promote it into tenured without moving for G1GC
94     double G1PromotionRegionAliveRate() const;
95 
96     /**
97      * @brief minimum percentage of not used bytes in tenured region to collect it on full even if we have no garbage
98      * inside
99      */
100     double G1FullGCRegionFragmentationRate() const;
101 
102     /**
103      * @brief Specify if we need to track removing objects
104      * (i.e. update objects count in memstats and log removed objects) during the G1GC collection or not.
105      */
106     bool G1TrackFreedObjects() const;
107 
108     /// @brief if not zero and gc supports workers, create a gc workers and try to use them
109     size_t GCWorkersCount() const;
110 
111     void SetGCWorkersCount(size_t value);
112 
113     bool ManageGcThreadsAffinity() const;
114 
115     bool UseWeakCpuForGcConcurrent() const;
116 
117     /// @return true if thread pool is used, false - if task manager is used
118     bool UseThreadPoolForGC() const;
119 
120     /// @return true if task manager is used, false - if thread pool is used
121     bool UseTaskManagerForGC() const;
122 
123     /**
124      * @brief Limit the creation rate of tasks during marking in nanoseconds.
125      * if average task creation is less than this value - it increases the stack size limit to create tasks less
126      * frequently.
127      */
128     size_t GCMarkingStackNewTasksFrequency() const;
129 
130     /**
131      * @brief Max stack size for marking in main thread, if it exceeds we will send a new task to workers,
132      * 0 means unlimited.
133      */
134     size_t GCRootMarkingStackMaxSize() const;
135 
136     /**
137      * @brief Max stack size for marking in a gc worker, if it exceeds we will send a new task to workers,
138      * 0 means unlimited.
139      */
140     size_t GCWorkersMarkingStackMaxSize() const;
141 
142     /// @brief size of young-space
143     uint64_t YoungSpaceSize() const;
144 
145     /// @brief true if print INFO log to get more detailed information in GC.
146     bool LogDetailedGCInfoEnabled() const;
147 
148     /// @brief true if print INFO log to get more detailed compaction/promotion information per region in GC.
149     bool LogDetailedGCCompactionInfoEnabled() const;
150 
151     /// @brief true if we want to do marking phase in multithreading mode.
152     bool ParallelMarkingEnabled() const;
153 
154     void SetParallelMarkingEnabled(bool value);
155 
156     /// @brief true if we want to do compacting phase in multithreading mode.
157     bool ParallelCompactingEnabled() const;
158 
159     void SetParallelCompactingEnabled(bool value);
160 
161     /// @brief true if we want to do ref updating phase in multithreading mode
162     bool ParallelRefUpdatingEnabled() const;
163 
164     void SetParallelRefUpdatingEnabled(bool value);
165 
166     /// @brief true if G1 should updates remsets concurrently
167     bool G1EnableConcurrentUpdateRemset() const;
168 
169     /// @brief
170     size_t G1MinConcurrentCardsToProcess() const;
171 
172     size_t G1HotCardsProcessingFrequency() const;
173 
174     bool G1EnablePauseTimeGoal() const;
175 
176     uint32_t GetG1MaxGcPauseInMillis() const;
177 
178     uint32_t GetG1GcPauseIntervalInMillis() const;
179 
180     bool G1SinglePassCompactionEnabled() const;
181 
182 private:
183     // clang-tidy complains about excessive padding
184     /// Garbage rate threshold of a tenured region to be included into a mixed collection
185     double g1RegionGarbageRateThreshold_ = 0;
186     /**
187      * Minimum percentage of not used bytes in tenured region to
188      * collect it on full even if we have no garbage inside
189      */
190     double g1FullGcRegionFragmentationRate_ = 0;
191     /**
192      * Limit the creation rate of tasks during marking in nanoseconds.
193      * If average task creation is less than this value - it increases the stack size limit twice to create tasks less
194      * frequently.
195      */
196     size_t gcMarkingStackNewTasksFrequency_ = 0;
197     /// Max stack size for marking in main thread, if it exceeds we will send a new task to workers, 0 means unlimited.
198     size_t gcRootMarkingStackMaxSize_ = 0;
199     /// Max stack size for marking in a gc worker, if it exceeds we will send a new task to workers, 0 means unlimited.
200     size_t gcWorkersMarkingStackMaxSize_ = 0;
201     /// If not zero and gc supports workers, create a gc workers and try to use them
202     size_t gcWorkersCount_ = 0;
203     /// Size of young-space
204     uint64_t youngSpaceSize_ = 0;
205     size_t g1MinConcurrentCardsToProcess_ = 0;
206     /// Frequency of proccessing hot cards in update remset thread
207     size_t g1HotCardsProcessingFrequency_ = 0;
208     /// Type of native trigger
209     NativeGcTriggerType nativeGcTriggerType_ = {NativeGcTriggerType::INVALID_NATIVE_GC_TRIGGER};
210     /// Runs full collection one of N times in GC thread
211     uint32_t fullGcBombingFrequency_ = 0;
212     /// Specify a max number of tenured regions which can be collected at mixed collection in G1GC.
213     uint32_t g1NumberOfTenuredRegionsAtMixedCollection_ = 0;
214     /// Minimum percentage of alive bytes in young region to promote it into tenured without moving for G1GC
215     uint32_t g1PromotionRegionAliveRate_ = 0;
216     uint32_t g1MaxGcPauseMs_ = 0;
217     uint32_t g1GcPauseIntervalMs_ = 0;
218     /// If true then enable tracing
219     bool isGcEnableTracing_ = false;
220     /// Dump heap at the beginning and the end of GC
221     bool isDumpHeap_ = false;
222     /// True if concurrency enabled
223     bool isConcurrencyEnabled_ = true;
224     /// True if explicit GC should be running in concurrent
225     bool isExplicitConcurrentGcEnabled_ = true;
226     /// True if GC should be running in place
227     bool runGcInPlace_ = false;
228     /// Use FastHeapVerifier if true
229     bool enableFastHeapVerifier_ = true;
230     /// True if heap verification before GC enabled
231     bool preGcHeapVerification_ = false;
232     /// True if heap verification during GC enabled
233     bool intoGcHeapVerification_ = false;
234     /// True if heap verification after GC enabled
235     bool postGcHeapVerification_ = false;
236     /// True if heap verification before G1-GC concurrent phase enabled
237     bool beforeG1ConcurrentHeapVerification_ = false;
238     /// If true then fail execution if heap verifier found heap corruption
239     bool failOnHeapVerification_ = false;
240     /// If true then run gc every savepoint
241     bool runGcEverySafepoint_ = false;
242     bool manageGcThreadsAffinity_ = true;
243     bool useWeakCpuForGcConcurrent_ = false;
244     /// if true then thread pool is used, false - task manager is used
245     bool useThreadPoolForGcWorkers_ = true;
246     /// If we need to track removing objects during the G1GC collection or not
247     bool g1TrackFreedObjects_ = false;
248     /// True if print INFO log to get more detailed information in GC
249     bool logDetailedGcInfoEnabled_ = false;
250     /// True if print INFO log to get more detailed compaction/promotion information per region in GC
251     bool logDetailedGcCompactionInfoEnabled_ = false;
252     /// True if we want to do marking phase in multithreading mode
253     bool parallelMarkingEnabled_ = false;
254     /// True if we want to do compacting phase in multithreading mode
255     bool parallelCompactingEnabled_ = false;
256     /// True if we want to do ref updating phase in multithreading mode
257     bool parallelRefUpdatingEnabled_ = false;
258     /// True if G1 should updates remsets concurrently
259     bool g1EnableConcurrentUpdateRemset_ = false;
260     bool g1EnablePauseTimeGoal_ {false};
261     bool g1SinglePassCompactionEnabled_ = true;
262 };
263 
264 }  // namespace ark::mem
265 
266 #endif  // PANDA_RUNTIME_MEM_GC_GC_SETTINGS_H
267