• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 PANDA_LIBPANDABASE_MEM_MEM_CONFIG_H_
17 #define PANDA_LIBPANDABASE_MEM_MEM_CONFIG_H_
18 
19 #include "macros.h"
20 #include "mem/mem.h"
21 #include "utils/asan_interface.h"
22 
23 #include <cstddef>
24 
25 namespace panda::mem {
26 
27 /**
28  * class for global memory parameters
29  */
30 class MemConfig {
31 public:
Initialize(size_t object_pool_size,size_t internal_size,size_t compiler_size,size_t code_size)32     static void Initialize(size_t object_pool_size, size_t internal_size, size_t compiler_size, size_t code_size)
33     {
34         ASSERT(!is_initialized);
35         heap_pool_size = object_pool_size;
36         internal_pool_size = internal_size;
37         compiler_pool_size = compiler_size;
38         code_pool_size = code_size;
39         is_initialized = true;
40     }
41 
Finalize()42     static void Finalize()
43     {
44         is_initialized = false;
45         heap_pool_size = 0;
46         internal_pool_size = 0;
47         code_pool_size = 0;
48     }
49 
GetObjectPoolSize()50     static size_t GetObjectPoolSize()
51     {
52         ASSERT(is_initialized);
53         return heap_pool_size;
54     }
55 
GetInternalPoolSize()56     static size_t GetInternalPoolSize()
57     {
58         ASSERT(is_initialized);
59         return internal_pool_size;
60     }
61 
GetCodePoolSize()62     static size_t GetCodePoolSize()
63     {
64         ASSERT(is_initialized);
65         return code_pool_size;
66     }
67 
GetCompilerPoolSize()68     static size_t GetCompilerPoolSize()
69     {
70         ASSERT(is_initialized);
71         return compiler_pool_size;
72     }
73 
74     MemConfig() = delete;
75 
76     ~MemConfig() = delete;
77 
78     NO_COPY_SEMANTIC(MemConfig);
79     NO_MOVE_SEMANTIC(MemConfig);
80 
81 private:
82     static bool is_initialized;
83     static size_t heap_pool_size;      // Pool size used for object storage
84     static size_t internal_pool_size;  // Pool size used for internal storage
85     static size_t code_pool_size;      // Pool size used for compiled code storage
86     static size_t compiler_pool_size;  // Pool size used for internal compiler storage
87 };
88 
89 }  // namespace panda::mem
90 
91 #endif  // PANDA_LIBPANDABASE_MEM_MEM_CONFIG_H_
92