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_COMPONENTS_BASE_RUNTIME_BASE_RUNTIME_PARAM_H 17 #define COMMON_COMPONENTS_BASE_RUNTIME_BASE_RUNTIME_PARAM_H 18 19 #include "common_components/base/globals.h" 20 #include "common_interfaces/base/common.h" 21 #include "common_interfaces/base/runtime_param.h" 22 23 namespace common { 24 class BaseRuntimeParam { 25 public: 26 static RuntimeParam DefaultRuntimeParam(); 27 static size_t InitHeapSize(); 28 static void SetConfigHeapSize(RuntimeParam ¶m, size_t configHeapSize); 29 static void SetMaxGarbageCacheSize(RuntimeParam ¶m, uint64_t maxGarbageCacheSize); 30 #ifdef PANDA_TARGET_32 31 static constexpr size_t MAX_HEAP_POOL_SIZE = 1 * GB; 32 #else 33 static constexpr size_t MAX_HEAP_POOL_SIZE = 3.6 * GB; 34 #endif 35 36 private: 37 BaseRuntimeParam() = delete; 38 ~BaseRuntimeParam() = delete; 39 NO_COPY_SEMANTIC_CC(BaseRuntimeParam); 40 NO_MOVE_SEMANTIC_CC(BaseRuntimeParam); 41 }; 42 43 #if defined(PANDA_TARGET_OHOS) 44 #define RUNTIME_PARAM_LIST(V) \ 45 /* KEY SUB_KEY TYPE MIN MAX DEFAULT */ /* UNIT */ \ 46 V(heapParam, heapSize, size_t, 65536, 4194304, \ 47 BaseRuntimeParam::InitHeapSize() ) /* KB */; \ 48 V(heapParam, regionSize, size_t, 4, 2048, 1024 ) /* KB */; \ 49 V(heapParam, exemptionThreshold, double, 0.0, 1.0, 0.8 ) /* % */; \ 50 V(heapParam, heapUtilization, double, 0.0, 1.0, 0.95 ) /* % */; \ 51 V(heapParam, heapGrowth, double, 0.0, INT64_MAX, 1.15 ) /* times */; \ 52 V(heapParam, allocationRate, double, 0.0, INT64_MAX, 10240 ) /* rate */; \ 53 V(heapParam, allocationWaitTime, uint64_t, 0, INT64_MAX, 1000 ) /* ns */; \ 54 V(gcParam, enableGC, bool, 0, 1, 1 ) /* y/n */; \ 55 V(gcParam, enableStwGC, bool, 0, 1, 0 ) /* y/n */; \ 56 V(gcParam, gcThreads, uint32_t, 1, 32, 5 ) /* NUM */; \ 57 V(gcParam, garbageThreshold, double, 0.1, 1.0, 0.5 ) /* % */;; \ 58 V(gcParam, gcThreshold, size_t, 0, INT64_MAX, \ 59 BaseRuntimeParam::InitHeapSize() * KB ) /* byte */;\ 60 V(gcParam, gcInterval, uint64_t, 0, INT64_MAX, 150000000 ) /* ns */; \ 61 V(gcParam, backupGCInterval, uint64_t, 0, INT64_MAX, 240000 ) /* ms */; \ 62 V(gcParam, maxGrowBytes, size_t, 0, INT64_MAX, 32 * MB ) /* byte */; \ 63 V(gcParam, minGrowBytes, size_t, 0, INT64_MAX, 8 * MB ) /* byte */; \ 64 V(gcParam, multiplier, double, 0.0, 10.0, 1.0 ) /* % */; \ 65 V(gcParam, ygcRateAdjustment, double, 0.0, 1.0, 0.8 ) /* % */; \ 66 V(gcParam, kMinConcurrentRemainingBytes, \ 67 size_t, 0, INT64_MAX, 128 * KB ) /* byte */; \ 68 V(gcParam, kMaxConcurrentRemainingBytes, \ 69 size_t, 0, INT64_MAX, 512 * KB ) /* byte */; \ 70 V(gcParam, maxGarbageCacheSize, uint64_t, 0, INT64_MAX, 16 * MB ) /* byte */; 71 #else // PANDA_TARGET_OHOS 72 #define RUNTIME_PARAM_LIST(V) \ 73 /* KEY SUB_KEY TYPE MIN MAX DEFAULT */ /* UNIT */ \ 74 V(heapParam, heapSize, size_t, 4096, 4194304, \ 75 BaseRuntimeParam::InitHeapSize() ) /* KB */; \ 76 V(heapParam, regionSize, size_t, 4, 2048, 64 ) /* KB */; \ 77 V(heapParam, exemptionThreshold, double, 0.0, 1.0, 0.8 ) /* % */; \ 78 V(heapParam, heapUtilization, double, 0.0, 1.0, 0.6 ) /* % */; \ 79 V(heapParam, heapGrowth, double, 0.0, INT64_MAX, 1.15 ) /* times */; \ 80 V(heapParam, allocationRate, double, 0.0, INT64_MAX, 10240 ) /* rate */; \ 81 V(heapParam, allocationWaitTime, uint64_t, 0, INT64_MAX, 1000 ) /* ns */; \ 82 V(gcParam, enableGC, bool, 0, 1, 1 ) /* y/n */; \ 83 V(gcParam, enableStwGC, bool, 0, 1, 0 ) /* y/n */; \ 84 V(gcParam, gcThreads, uint32_t, 1, 64, 5 ) /* NUM */; \ 85 V(gcParam, garbageThreshold, double, 0.1, 1.0, 0.5 ) /* % */; \ 86 V(gcParam, gcThreshold, size_t, 0, INT64_MAX, \ 87 BaseRuntimeParam::InitHeapSize() * KB ) /* byte */; \ 88 V(gcParam, gcInterval, uint64_t, 0, INT64_MAX, 150000000 ) /* ns */; \ 89 V(gcParam, backupGCInterval, uint64_t, 0, INT64_MAX, 240000 ) /* ms */; \ 90 V(gcParam, maxGrowBytes, size_t, 0, INT64_MAX, 32 * MB ) /* byte */; \ 91 V(gcParam, minGrowBytes, size_t, 0, INT64_MAX, 8 * MB ) /* byte */; \ 92 V(gcParam, multiplier, double, 0.0, 10.0, 1.0 ) /* % */; \ 93 V(gcParam, ygcRateAdjustment, double, 0.0, 1.0, 0.8 ) /* % */; \ 94 V(gcParam, kMinConcurrentRemainingBytes, \ 95 size_t, 0, INT64_MAX, 128 * KB ) /* byte */; \ 96 V(gcParam, kMaxConcurrentRemainingBytes, \ 97 size_t, 0, INT64_MAX, 512 * KB ) /* byte */; 98 99 #endif // PANDA_TARGET_OHOS 100 } // namespace common 101 102 #endif // COMMON_COMPONENTS_BASE_RUNTIME_BASE_RUNTIME_PARAM_H 103