• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2022-2025 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 
16 #include "runtime/include/runtime.h"
17 #include "runtime/include/runtime_options.h"
18 #include "runtime/mem/gc/gc_settings.h"
19 #include "libpandabase/globals.h"
20 
21 namespace ark::mem {
22 
GCSettings(const RuntimeOptions & options,panda_file::SourceLang lang)23 GCSettings::GCSettings(const RuntimeOptions &options, panda_file::SourceLang lang)
24 {
25     auto runtimeLang = plugins::LangToRuntimeType(lang);
26     isDumpHeap_ = options.IsGcDumpHeap(runtimeLang);
27     isConcurrencyEnabled_ = options.IsConcurrentGcEnabled(runtimeLang);
28     isGcEnableTracing_ = options.IsGcEnableTracing(runtimeLang);
29     isExplicitConcurrentGcEnabled_ = options.IsExplicitConcurrentGcEnabled();
30     runGcInPlace_ = options.IsRunGcInPlace(runtimeLang);
31     fullGcBombingFrequency_ = options.GetFullGcBombingFrequency(runtimeLang);
32     nativeGcTriggerType_ = NativeGcTriggerTypeFromString(options.GetNativeGcTriggerType(runtimeLang));
33     enableFastHeapVerifier_ = options.IsEnableFastHeapVerifier(runtimeLang);
34     auto hvParams = options.GetHeapVerifier(runtimeLang);
35     preGcHeapVerification_ = std::find(hvParams.begin(), hvParams.end(), "pre") != hvParams.end();
36     intoGcHeapVerification_ = std::find(hvParams.begin(), hvParams.end(), "into") != hvParams.end();
37     postGcHeapVerification_ = std::find(hvParams.begin(), hvParams.end(), "post") != hvParams.end();
38     beforeG1ConcurrentHeapVerification_ =
39         std::find(hvParams.begin(), hvParams.end(), "before_g1_concurrent") != hvParams.end();
40     failOnHeapVerification_ = std::find(hvParams.begin(), hvParams.end(), "fail_on_verification") != hvParams.end();
41     runGcEverySafepoint_ = options.IsRunGcEverySafepoint();
42     g1RegionGarbageRateThreshold_ = options.GetG1RegionGarbageRateThreshold() / PERCENT_100_D;
43     g1NumberOfTenuredRegionsAtMixedCollection_ = options.GetG1NumberOfTenuredRegionsAtMixedCollection();
44     g1PromotionRegionAliveRate_ = options.GetG1PromotionRegionAliveRate();
45     g1FullGcRegionFragmentationRate_ = options.GetG1FullGcRegionFragmentationRate() / PERCENT_100_D;
46     g1TrackFreedObjects_ = options.IsG1TrackFreedObjects();
47     gcWorkersCount_ = options.GetGcWorkersCount();
48     manageGcThreadsAffinity_ = options.IsManageGcThreadsAffinity();
49     useWeakCpuForGcConcurrent_ = options.IsUseWeakCpuForGcConcurrent();
50     useThreadPoolForGcWorkers_ = !Runtime::IsTaskManagerUsed();
51     gcMarkingStackNewTasksFrequency_ = options.GetGcMarkingStackNewTasksFrequency();
52     gcRootMarkingStackMaxSize_ = options.GetGcRootMarkingStackMaxSize();
53     gcWorkersMarkingStackMaxSize_ = options.GetGcWorkersMarkingStackMaxSize();
54     youngSpaceSize_ = options.GetYoungSpaceSize();
55     logDetailedGcInfoEnabled_ = options.IsLogDetailedGcInfoEnabled();
56     logDetailedGcCompactionInfoEnabled_ = options.IsLogDetailedGcCompactionInfoEnabled();
57     parallelMarkingEnabled_ = options.IsGcParallelMarkingEnabled() && (options.GetGcWorkersCount() != 0);
58     parallelCompactingEnabled_ = options.IsGcParallelCompactingEnabled() && (options.GetGcWorkersCount() != 0);
59     parallelRefUpdatingEnabled_ = options.IsGcParallelRefUpdatingEnabled() && (options.GetGcWorkersCount() != 0);
60     g1EnableConcurrentUpdateRemset_ = options.IsG1EnableConcurrentUpdateRemset();
61     g1MinConcurrentCardsToProcess_ = options.GetG1MinConcurrentCardsToProcess();
62     g1HotCardsProcessingFrequency_ = options.GetG1HotCardsProcessingFrequency();
63     g1EnablePauseTimeGoal_ = options.IsG1PauseTimeGoal();
64     g1MaxGcPauseMs_ = options.GetG1PauseTimeGoalMaxGcPause();
65     g1GcPauseIntervalMs_ = options.WasSetG1PauseTimeGoalGcPauseInterval() ? options.GetG1PauseTimeGoalGcPauseInterval()
66                                                                           : g1MaxGcPauseMs_ + 1;
67     g1SinglePassCompactionEnabled_ = options.IsG1SinglePassCompactionEnabled();
68     LOG_IF(FullGCBombingFrequency() && RunGCInPlace(), FATAL, GC)
69         << "full-gc-bombimg-frequency and run-gc-in-place options can't be used together";
70 }
71 
IsGcEnableTracing() const72 bool GCSettings::IsGcEnableTracing() const
73 {
74     return isGcEnableTracing_;
75 }
76 
GetNativeGcTriggerType() const77 NativeGcTriggerType GCSettings::GetNativeGcTriggerType() const
78 {
79     return nativeGcTriggerType_;
80 }
81 
IsDumpHeap() const82 bool GCSettings::IsDumpHeap() const
83 {
84     return isDumpHeap_;
85 }
86 
IsConcurrencyEnabled() const87 bool GCSettings::IsConcurrencyEnabled() const
88 {
89     return isConcurrencyEnabled_;
90 }
91 
IsExplicitConcurrentGcEnabled() const92 bool GCSettings::IsExplicitConcurrentGcEnabled() const
93 {
94     return isExplicitConcurrentGcEnabled_;
95 }
96 
RunGCInPlace() const97 bool GCSettings::RunGCInPlace() const
98 {
99     return runGcInPlace_;
100 }
101 
EnableFastHeapVerifier() const102 bool GCSettings::EnableFastHeapVerifier() const
103 {
104     return enableFastHeapVerifier_;
105 }
106 
PreGCHeapVerification() const107 bool GCSettings::PreGCHeapVerification() const
108 {
109     return preGcHeapVerification_;
110 }
111 
IntoGCHeapVerification() const112 bool GCSettings::IntoGCHeapVerification() const
113 {
114     return intoGcHeapVerification_;
115 }
116 
PostGCHeapVerification() const117 bool GCSettings::PostGCHeapVerification() const
118 {
119     return postGcHeapVerification_;
120 }
121 
BeforeG1ConcurrentHeapVerification() const122 bool GCSettings::BeforeG1ConcurrentHeapVerification() const
123 {
124     return beforeG1ConcurrentHeapVerification_;
125 }
126 
FailOnHeapVerification() const127 bool GCSettings::FailOnHeapVerification() const
128 {
129     return failOnHeapVerification_;
130 }
131 
RunGCEverySafepoint() const132 bool GCSettings::RunGCEverySafepoint() const
133 {
134     return runGcEverySafepoint_;
135 }
136 
G1RegionGarbageRateThreshold() const137 double GCSettings::G1RegionGarbageRateThreshold() const
138 {
139     return g1RegionGarbageRateThreshold_;
140 }
141 
FullGCBombingFrequency() const142 uint32_t GCSettings::FullGCBombingFrequency() const
143 {
144     return fullGcBombingFrequency_;
145 }
146 
GetG1NumberOfTenuredRegionsAtMixedCollection() const147 uint32_t GCSettings::GetG1NumberOfTenuredRegionsAtMixedCollection() const
148 {
149     return g1NumberOfTenuredRegionsAtMixedCollection_;
150 }
151 
G1PromotionRegionAliveRate() const152 double GCSettings::G1PromotionRegionAliveRate() const
153 {
154     return g1PromotionRegionAliveRate_;
155 }
156 
G1FullGCRegionFragmentationRate() const157 double GCSettings::G1FullGCRegionFragmentationRate() const
158 {
159     return g1FullGcRegionFragmentationRate_;
160 }
161 
G1TrackFreedObjects() const162 bool GCSettings::G1TrackFreedObjects() const
163 {
164     return g1TrackFreedObjects_;
165 }
166 
GCWorkersCount() const167 size_t GCSettings::GCWorkersCount() const
168 {
169     return gcWorkersCount_;
170 }
171 
ManageGcThreadsAffinity() const172 bool GCSettings::ManageGcThreadsAffinity() const
173 {
174     return manageGcThreadsAffinity_;
175 }
176 
UseWeakCpuForGcConcurrent() const177 bool GCSettings::UseWeakCpuForGcConcurrent() const
178 {
179     return useWeakCpuForGcConcurrent_;
180 }
181 
SetGCWorkersCount(size_t value)182 void GCSettings::SetGCWorkersCount(size_t value)
183 {
184     gcWorkersCount_ = value;
185 }
186 
UseThreadPoolForGC() const187 bool GCSettings::UseThreadPoolForGC() const
188 {
189     return useThreadPoolForGcWorkers_;
190 }
191 
UseTaskManagerForGC() const192 bool GCSettings::UseTaskManagerForGC() const
193 {
194     return !useThreadPoolForGcWorkers_;
195 }
196 
GCMarkingStackNewTasksFrequency() const197 size_t GCSettings::GCMarkingStackNewTasksFrequency() const
198 {
199     return gcMarkingStackNewTasksFrequency_;
200 }
201 
GCRootMarkingStackMaxSize() const202 size_t GCSettings::GCRootMarkingStackMaxSize() const
203 {
204     return gcRootMarkingStackMaxSize_;
205 }
206 
GCWorkersMarkingStackMaxSize() const207 size_t GCSettings::GCWorkersMarkingStackMaxSize() const
208 {
209     return gcWorkersMarkingStackMaxSize_;
210 }
211 
YoungSpaceSize() const212 uint64_t GCSettings::YoungSpaceSize() const
213 {
214     return youngSpaceSize_;
215 }
216 
LogDetailedGCInfoEnabled() const217 bool GCSettings::LogDetailedGCInfoEnabled() const
218 {
219     return logDetailedGcInfoEnabled_;
220 }
221 
LogDetailedGCCompactionInfoEnabled() const222 bool GCSettings::LogDetailedGCCompactionInfoEnabled() const
223 {
224     return logDetailedGcCompactionInfoEnabled_;
225 }
226 
ParallelMarkingEnabled() const227 bool GCSettings::ParallelMarkingEnabled() const
228 {
229     return parallelMarkingEnabled_;
230 }
231 
SetParallelMarkingEnabled(bool value)232 void GCSettings::SetParallelMarkingEnabled(bool value)
233 {
234     parallelMarkingEnabled_ = value;
235 }
236 
ParallelCompactingEnabled() const237 bool GCSettings::ParallelCompactingEnabled() const
238 {
239     return parallelCompactingEnabled_;
240 }
241 
SetParallelCompactingEnabled(bool value)242 void GCSettings::SetParallelCompactingEnabled(bool value)
243 {
244     parallelCompactingEnabled_ = value;
245 }
246 
ParallelRefUpdatingEnabled() const247 bool GCSettings::ParallelRefUpdatingEnabled() const
248 {
249     return parallelRefUpdatingEnabled_;
250 }
251 
SetParallelRefUpdatingEnabled(bool value)252 void GCSettings::SetParallelRefUpdatingEnabled(bool value)
253 {
254     parallelRefUpdatingEnabled_ = value;
255 }
256 
G1EnableConcurrentUpdateRemset() const257 bool GCSettings::G1EnableConcurrentUpdateRemset() const
258 {
259     return g1EnableConcurrentUpdateRemset_;
260 }
261 
G1MinConcurrentCardsToProcess() const262 size_t GCSettings::G1MinConcurrentCardsToProcess() const
263 {
264     return g1MinConcurrentCardsToProcess_;
265 }
266 
G1HotCardsProcessingFrequency() const267 size_t GCSettings::G1HotCardsProcessingFrequency() const
268 {
269     return g1HotCardsProcessingFrequency_;
270 }
271 
G1EnablePauseTimeGoal() const272 bool GCSettings::G1EnablePauseTimeGoal() const
273 {
274     return g1EnablePauseTimeGoal_;
275 }
276 
GetG1MaxGcPauseInMillis() const277 uint32_t GCSettings::GetG1MaxGcPauseInMillis() const
278 {
279     return g1MaxGcPauseMs_;
280 }
281 
GetG1GcPauseIntervalInMillis() const282 uint32_t GCSettings::GetG1GcPauseIntervalInMillis() const
283 {
284     return g1GcPauseIntervalMs_;
285 }
286 
G1SinglePassCompactionEnabled() const287 bool GCSettings::G1SinglePassCompactionEnabled() const
288 {
289     return g1SinglePassCompactionEnabled_;
290 }
291 
292 }  // namespace ark::mem
293