1 /** 2 * Copyright (c) 2021-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 #ifndef LIBPANDABASE_MEM_MEM_CONFIG_H 17 #define LIBPANDABASE_MEM_MEM_CONFIG_H 18 19 #include <cstddef> 20 21 #include "macros.h" 22 23 namespace panda::mem { 24 25 /** 26 * class for global memory parameters 27 */ 28 class MemConfig { 29 public: Initialize(size_t object_pool_size,size_t internal_size,size_t compiler_size,size_t code_size,size_t initial_object_pool_size)30 static void Initialize(size_t object_pool_size, size_t internal_size, size_t compiler_size, size_t code_size, 31 size_t initial_object_pool_size) 32 { 33 ASSERT(!is_initialized); 34 initial_heap_size_limit = initial_object_pool_size; 35 heap_size_limit = object_pool_size; 36 internal_memory_size_limit = internal_size; 37 compiler_memory_size_limit = compiler_size; 38 code_cache_size_limit = code_size; 39 is_initialized = true; 40 } 41 Initialize(size_t object_pool_size,size_t internal_size,size_t compiler_size,size_t code_size)42 static void Initialize(size_t object_pool_size, size_t internal_size, size_t compiler_size, size_t code_size) 43 { 44 Initialize(object_pool_size, internal_size, compiler_size, code_size, object_pool_size); 45 } 46 Finalize()47 static void Finalize() 48 { 49 is_initialized = false; 50 heap_size_limit = 0; 51 internal_memory_size_limit = 0; 52 code_cache_size_limit = 0; 53 } 54 GetInitialHeapSizeLimit()55 static size_t GetInitialHeapSizeLimit() 56 { 57 ASSERT(is_initialized); 58 return initial_heap_size_limit; 59 } 60 GetHeapSizeLimit()61 static size_t GetHeapSizeLimit() 62 { 63 ASSERT(is_initialized); 64 return heap_size_limit; 65 } 66 GetInternalMemorySizeLimit()67 static size_t GetInternalMemorySizeLimit() 68 { 69 ASSERT(is_initialized); 70 return internal_memory_size_limit; 71 } 72 GetCodeCacheSizeLimit()73 static size_t GetCodeCacheSizeLimit() 74 { 75 ASSERT(is_initialized); 76 return code_cache_size_limit; 77 } 78 GetCompilerMemorySizeLimit()79 static size_t GetCompilerMemorySizeLimit() 80 { 81 ASSERT(is_initialized); 82 return compiler_memory_size_limit; 83 } 84 85 MemConfig() = delete; 86 87 ~MemConfig() = delete; 88 89 NO_COPY_SEMANTIC(MemConfig); 90 NO_MOVE_SEMANTIC(MemConfig); 91 92 private: 93 static bool is_initialized; 94 static size_t initial_heap_size_limit; // Initial heap size 95 static size_t heap_size_limit; // Max heap size 96 static size_t internal_memory_size_limit; // Max internal memory used by the VM 97 static size_t code_cache_size_limit; // The limit for compiled code size. 98 static size_t compiler_memory_size_limit; // Max memory used by compiler 99 }; 100 101 } // namespace panda::mem 102 103 #endif // LIBPANDABASE_MEM_MEM_CONFIG_H 104