• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #ifndef COMMON_INTERFACES_BASE_RUNTIME_PARAM_H
17 #define COMMON_INTERFACES_BASE_RUNTIME_PARAM_H
18 
19 #include "base/common.h"
20 
21 namespace common {
22 /*
23 * @struct HeapParam
24 * @brief Data structure for Arkcommon heap configuration parameters,\n
25 * including the heap size, region size at runtime, and etc.
26 */
27 struct HeapParam {
28     /*
29     * The reference value of region size, measured in KB, default to 64 KB, must be in range [4KB, 64KB].
30     * It will be set to default value if assigned with 0.
31     */
32     size_t regionSize;
33 
34     /*
35     * The maximum size of arkcommon heap, measured in KB, default to 256 * 1024 KB, must >= 4MB.
36     * It will be set to default value if assigned with 0.
37     */
38     size_t heapSize;
39 
40     /*
41     * Threshold used to determine whether a region is exempted (i.e., will not be forwarded).
42     * If the percentage of live objects in a region is greater than this value, this region will not be exempted.
43     * Default to 0.8, must be in range (0, 1].
44     * It will be set to default value if assigned with 0.
45     */
46     double exemptionThreshold;
47 
48     /*
49     * A hint to guide collector to release physical memory to OS.
50     * heap utilization = heap-used-memory / total-heap-memory.
51     * During each gc, collector determines how much memory should be cached,
52     * and let the heap utilization be close to this value.
53     * Default to 0.80, must be in range (0, 1].
54     * It will be set to default value if assigned with 0.
55     */
56     double heapUtilization;
57 
58     /*
59     * The ratio to expand heap after each GC.
60     * GC is probably triggered more often if this value is set to an improperly small number.
61     * Default to 0.15, must > 0.
62     * It will be set to default value if assigned with 0.
63     */
64     double heapGrowth;
65 
66     /*
67     * The rate of allocating memory from heap.
68     * this value is the lower bound of the real allocation rate.
69     * allocator maybe wait some time if this value is set with an improperly small number.
70     * Mesured in MB/s, default to 10240 MB/s, must be > 0 MB/s.
71     * It will be set to default value if assigned with 0.
72     */
73     double allocationRate;
74 
75     /*
76     * The maximum wait time when allocating memory from heap.
77     * The latter alloction will wait a number of time if the two alloction interval is less than the wait time.
78     * The real wait time is the minimum of allocationWaitTime and the wait time calculated from real alloction rate.
79     * Measured in ns, default to 1000 ns, must > 0 ns.
80     * It will be set to default value if assigned with 0.
81     */
82     size_t allocationWaitTime;
83 };
84 
85 /*
86 * @struct GCParam
87 * @brief Data structure for Arkcommon garbage collection configuration parameters,\n
88 * including the garbage ratio, garbage collection interval and etc.
89 */
90 struct GCParam {
91     /*
92     * Set false to disable GC, default is true
93     */
94     bool enableGC;
95 
96     /*
97     * Set true swicth to stop-the-world GC, set false swicth to concurrent-copying GC, default is false
98     */
99     bool enableStwGC;
100 
101     /*
102     * GC will be triggered when heap allocated size is greater than this threshold.
103     * Measured in KB, must be > 0.
104     */
105     size_t gcThreshold;
106 
107     /*
108     * The threshold used to determine whether to collect from-space during GC.
109     * The from-space will be collected if the percentage of the garbage in from space is greater than this threshold.
110     * default to 0.5, must be in range [0.1, 1.0].
111     */
112     double garbageThreshold;
113 
114     /*
115     * Minimum interval each GC request will be responded. If two adjacent GC requests with
116     * interval less than this value, the latter one is ignored.
117     * Measured in ns, default to 150 ms, must be > 0 ms.
118     * It will be set default value if the value is 0.
119     */
120     uint64_t gcInterval;
121 
122     /*
123     * Minimum interval each backup GC request will be responded.
124     * Backup GC will be triggered if there is no GC during this interval.
125     * Measured in ns, default to 240 s, must be > 0 s.
126     * It will be set default value if the value is 0.
127     */
128     uint64_t backupGCInterval;
129 
130     /*
131     * Parameters for adjusting the number of GC threads.
132     * The number of gc threads is ((the hardware concurrency / this value) - 1).
133     * default to 8, must be > 0.
134     * It will be set default value if the value is 0.
135     */
136     uint32_t gcThreads;
137 
138     /*
139     * The maximum grow bytes of next heuristic gc threshold, the default value is 32MB;
140     */
141     size_t maxGrowBytes;
142 
143     /*
144     * The minimum grow bytes of next heuristic gc threshold, the default value is 8MB;
145     */
146     size_t minGrowBytes;
147 
148     /*
149     * Heruistic gc grow bytes multiplier, The default value of foreground is 1.0, background is 2.0.
150     */
151     double multiplier;
152 
153     /*
154     * Young gc throughput adjustment factor, the default value is 0.5.
155     */
156     double ygcRateAdjustment;
157 
158     /*
159     * The minimum remaining bytes for next heuristic gc, the default value is 128KB.
160     */
161     size_t kMinConcurrentRemainingBytes;
162 
163     /*
164     * The maximum remaining bytes for next heuristic gc, the default value is 512KB.
165     */
166     size_t kMaxConcurrentRemainingBytes;
167 
168     /*
169     * The maximum size for garbage cache, the default size is 16M.
170     */
171     uint64_t maxGarbageCacheSize;
172 };
173 
174 /*
175 * @struct RuntimeParam
176 * @brief Data structure for Arkcommon runtime parameters,\n
177 * including the config information of heap, garbage collection, thread and log.
178 */
179 struct RuntimeParam {
180     struct HeapParam heapParam;
181     struct GCParam gcParam;
182 };
183 }  // namespace common
184 
185 #endif  // COMMON_INTERFACES_BASE_RUNTIME_PARAM_H
186