• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
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 panda::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::GetTaskScheduler() == nullptr;
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     g1EnablePauseTimeGoal_ = options.IsG1PauseTimeGoal();
63     g1MaxGcPauseMs_ = options.GetG1PauseTimeGoalMaxGcPause();
64     g1GcPauseIntervalMs_ = options.WasSetG1PauseTimeGoalGcPauseInterval() ? options.GetG1PauseTimeGoalGcPauseInterval()
65                                                                           : g1MaxGcPauseMs_ + 1;
66     LOG_IF(FullGCBombingFrequency() && RunGCInPlace(), FATAL, GC)
67         << "full-gc-bombimg-frequency and run-gc-in-place options can't be used together";
68 }
69 
IsGcEnableTracing() const70 bool GCSettings::IsGcEnableTracing() const
71 {
72     return isGcEnableTracing_;
73 }
74 
GetNativeGcTriggerType() const75 NativeGcTriggerType GCSettings::GetNativeGcTriggerType() const
76 {
77     return nativeGcTriggerType_;
78 }
79 
IsDumpHeap() const80 bool GCSettings::IsDumpHeap() const
81 {
82     return isDumpHeap_;
83 }
84 
IsConcurrencyEnabled() const85 bool GCSettings::IsConcurrencyEnabled() const
86 {
87     return isConcurrencyEnabled_;
88 }
89 
IsExplicitConcurrentGcEnabled() const90 bool GCSettings::IsExplicitConcurrentGcEnabled() const
91 {
92     return isExplicitConcurrentGcEnabled_;
93 }
94 
RunGCInPlace() const95 bool GCSettings::RunGCInPlace() const
96 {
97     return runGcInPlace_;
98 }
99 
EnableFastHeapVerifier() const100 bool GCSettings::EnableFastHeapVerifier() const
101 {
102     return enableFastHeapVerifier_;
103 }
104 
PreGCHeapVerification() const105 bool GCSettings::PreGCHeapVerification() const
106 {
107     return preGcHeapVerification_;
108 }
109 
IntoGCHeapVerification() const110 bool GCSettings::IntoGCHeapVerification() const
111 {
112     return intoGcHeapVerification_;
113 }
114 
PostGCHeapVerification() const115 bool GCSettings::PostGCHeapVerification() const
116 {
117     return postGcHeapVerification_;
118 }
119 
BeforeG1ConcurrentHeapVerification() const120 bool GCSettings::BeforeG1ConcurrentHeapVerification() const
121 {
122     return beforeG1ConcurrentHeapVerification_;
123 }
124 
FailOnHeapVerification() const125 bool GCSettings::FailOnHeapVerification() const
126 {
127     return failOnHeapVerification_;
128 }
129 
RunGCEverySafepoint() const130 bool GCSettings::RunGCEverySafepoint() const
131 {
132     return runGcEverySafepoint_;
133 }
134 
G1RegionGarbageRateThreshold() const135 double GCSettings::G1RegionGarbageRateThreshold() const
136 {
137     return g1RegionGarbageRateThreshold_;
138 }
139 
FullGCBombingFrequency() const140 uint32_t GCSettings::FullGCBombingFrequency() const
141 {
142     return fullGcBombingFrequency_;
143 }
144 
GetG1NumberOfTenuredRegionsAtMixedCollection() const145 uint32_t GCSettings::GetG1NumberOfTenuredRegionsAtMixedCollection() const
146 {
147     return g1NumberOfTenuredRegionsAtMixedCollection_;
148 }
149 
G1PromotionRegionAliveRate() const150 double GCSettings::G1PromotionRegionAliveRate() const
151 {
152     return g1PromotionRegionAliveRate_;
153 }
154 
G1FullGCRegionFragmentationRate() const155 double GCSettings::G1FullGCRegionFragmentationRate() const
156 {
157     return g1FullGcRegionFragmentationRate_;
158 }
159 
G1TrackFreedObjects() const160 bool GCSettings::G1TrackFreedObjects() const
161 {
162     return g1TrackFreedObjects_;
163 }
164 
GCWorkersCount() const165 size_t GCSettings::GCWorkersCount() const
166 {
167     return gcWorkersCount_;
168 }
169 
ManageGcThreadsAffinity() const170 bool GCSettings::ManageGcThreadsAffinity() const
171 {
172     return manageGcThreadsAffinity_;
173 }
174 
UseWeakCpuForGcConcurrent() const175 bool GCSettings::UseWeakCpuForGcConcurrent() const
176 {
177     return useWeakCpuForGcConcurrent_;
178 }
179 
SetGCWorkersCount(size_t value)180 void GCSettings::SetGCWorkersCount(size_t value)
181 {
182     gcWorkersCount_ = value;
183 }
184 
UseThreadPoolForGC() const185 bool GCSettings::UseThreadPoolForGC() const
186 {
187     return useThreadPoolForGcWorkers_;
188 }
189 
UseTaskManagerForGC() const190 bool GCSettings::UseTaskManagerForGC() const
191 {
192     return !useThreadPoolForGcWorkers_;
193 }
194 
GCMarkingStackNewTasksFrequency() const195 size_t GCSettings::GCMarkingStackNewTasksFrequency() const
196 {
197     return gcMarkingStackNewTasksFrequency_;
198 }
199 
GCRootMarkingStackMaxSize() const200 size_t GCSettings::GCRootMarkingStackMaxSize() const
201 {
202     return gcRootMarkingStackMaxSize_;
203 }
204 
GCWorkersMarkingStackMaxSize() const205 size_t GCSettings::GCWorkersMarkingStackMaxSize() const
206 {
207     return gcWorkersMarkingStackMaxSize_;
208 }
209 
YoungSpaceSize() const210 uint64_t GCSettings::YoungSpaceSize() const
211 {
212     return youngSpaceSize_;
213 }
214 
LogDetailedGCInfoEnabled() const215 bool GCSettings::LogDetailedGCInfoEnabled() const
216 {
217     return logDetailedGcInfoEnabled_;
218 }
219 
LogDetailedGCCompactionInfoEnabled() const220 bool GCSettings::LogDetailedGCCompactionInfoEnabled() const
221 {
222     return logDetailedGcCompactionInfoEnabled_;
223 }
224 
ParallelMarkingEnabled() const225 bool GCSettings::ParallelMarkingEnabled() const
226 {
227     return parallelMarkingEnabled_;
228 }
229 
SetParallelMarkingEnabled(bool value)230 void GCSettings::SetParallelMarkingEnabled(bool value)
231 {
232     parallelMarkingEnabled_ = value;
233 }
234 
ParallelCompactingEnabled() const235 bool GCSettings::ParallelCompactingEnabled() const
236 {
237     return parallelCompactingEnabled_;
238 }
239 
SetParallelCompactingEnabled(bool value)240 void GCSettings::SetParallelCompactingEnabled(bool value)
241 {
242     parallelCompactingEnabled_ = value;
243 }
244 
ParallelRefUpdatingEnabled() const245 bool GCSettings::ParallelRefUpdatingEnabled() const
246 {
247     return parallelRefUpdatingEnabled_;
248 }
249 
SetParallelRefUpdatingEnabled(bool value)250 void GCSettings::SetParallelRefUpdatingEnabled(bool value)
251 {
252     parallelRefUpdatingEnabled_ = value;
253 }
254 
G1EnableConcurrentUpdateRemset() const255 bool GCSettings::G1EnableConcurrentUpdateRemset() const
256 {
257     return g1EnableConcurrentUpdateRemset_;
258 }
259 
G1MinConcurrentCardsToProcess() const260 size_t GCSettings::G1MinConcurrentCardsToProcess() const
261 {
262     return g1MinConcurrentCardsToProcess_;
263 }
264 
G1EnablePauseTimeGoal() const265 bool GCSettings::G1EnablePauseTimeGoal() const
266 {
267     return g1EnablePauseTimeGoal_;
268 }
269 
GetG1MaxGcPauseInMillis() const270 uint32_t GCSettings::GetG1MaxGcPauseInMillis() const
271 {
272     return g1MaxGcPauseMs_;
273 }
274 
GetG1GcPauseIntervalInMillis() const275 uint32_t GCSettings::GetG1GcPauseIntervalInMillis() const
276 {
277     return g1GcPauseIntervalMs_;
278 }
279 
280 }  // namespace panda::mem
281