• 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 ECMASCRIPT_MEM_MEM_H
17 #define ECMASCRIPT_MEM_MEM_H
18 
19 #include <cstdint>
20 
21 #include "libpandabase/mem/mem.h"
22 #include "ecmascript/mem/tagged_object.h"
23 #include "libpandabase/utils/logger.h"
24 #include "mem/gc/bitmap.h"
25 
26 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage, bugprone-lambda-function-name)
27 #define LOG_ECMA_MEM(type) LOG(type, ECMASCRIPT) << __func__ << " Line:" << __LINE__ << " "
28 
29 namespace panda::ecmascript {
30 enum class MemAlignment : uint8_t {
31     MEM_ALIGN_OBJECT = 8,
32     MEM_ALIGN_REGION = 16,
33 };
34 
35 static constexpr size_t SEMI_SPACE_TRIGGER_CONCURRENT_MARK = 1.5 * 1024 * 1024;
36 static constexpr size_t SEMI_SPACE_OVERSHOOT_SIZE = 2 * 1024 * 1024;
37 
38 static constexpr size_t MIN_OLD_SPACE_LIMIT = 2 * 1024 * 1024;
39 static constexpr size_t OLD_SPACE_LIMIT_BEGIN = 256 * 1024 * 1024;
40 static constexpr size_t GLOBAL_SPACE_LIMIT_BEGIN = 256 * 1024 * 1024;
41 static constexpr size_t MIN_GROWING_STEP = 16 * 1024 * 1024;
42 static constexpr size_t MIN_AllOC_LIMIT_GROWING_STEP = 2 * 1024 * 1024;
43 
44 static constexpr size_t REGION_SIZE_LOG2 = 18U;
45 
46 static constexpr size_t MAX_HEAP_SIZE = 512 * 1024 * 1024;
47 static constexpr size_t HALF_MAX_HEAP_SIZE = MAX_HEAP_SIZE / 2;
48 static constexpr size_t DEFAULT_HEAP_SIZE = 5 * 1024 * 1024;
49 
50 static constexpr size_t DEFAULT_REGION_SIZE = 1U << REGION_SIZE_LOG2;
51 static constexpr size_t DEFAULT_REGION_MASK = DEFAULT_REGION_SIZE - 1;
52 
53 static constexpr size_t DEFAULT_MARK_STACK_SIZE = 4 * 1024;
54 
55 static constexpr double MIN_OBJECT_SURVIVAL_RATE = 0.75;
56 
57 // Objects which are larger than half of the region size are huge objects.
58 // Regular objects will be allocated on regular regions and migrated on spaces.
59 // They will never be moved to huge object space. So we take half of a regular
60 // region as the border of regular objects.
61 static constexpr size_t MAX_32BIT_OBJECT_SPACE_SIZE = 1 * 1024 * 1024 * 1024;
62 static constexpr size_t MAX_REGULAR_HEAP_OBJECT_SIZE = DEFAULT_REGION_SIZE * 2 / 3;
63 static constexpr size_t MAX_HUGE_OBJECT_SIZE = 256 * 1024 * 1024;
64 static constexpr size_t MAX_HUGE_OBJECT_SPACE_SIZE = 256 * 1024 * 1024;
65 static constexpr size_t LARGE_BITMAP_MIN_SIZE = static_cast<uint8_t>(MemAlignment::MEM_ALIGN_OBJECT)
66                                                 << mem::Bitmap::LOG_BITSPERWORD;
67 // internal allocator
68 static constexpr size_t CHUNK_ALIGN_SIZE = 4 * 1024;
69 static constexpr size_t MIN_CHUNK_AREA_SIZE = 4 * 1024;
70 static constexpr size_t MAX_CACHED_CHUNK_AREA_SIZE = 16 * 1024;
71 static constexpr size_t MAX_CHUNK_AREA_SIZE = 1 * 1024 * 1024;
72 
73 static constexpr uintptr_t PANDA_32BITS_HEAP_START_ADDRESS_256 = 256_KB;
74 
75 template<typename T>
IsAligned(T value,size_t alignment)76 constexpr inline bool IsAligned(T value, size_t alignment)
77 {
78     return (value & (alignment - 1U)) == 0;
79 }
80 
81 template<typename T>
AlignDown(T x,size_t alignment)82 inline T AlignDown(T x, size_t alignment)
83 {
84     ASSERT(std::is_integral<T>::value);
85     // alignment must be a power of two.
86     ASSERT(alignment != 0 && ((alignment & (alignment - 1U)) == 0));
87     return x & ~(alignment - 1U);
88 }
89 
90 template<typename T>
AlignUp(T x,size_t alignment)91 inline T AlignUp(T x, size_t alignment)
92 {
93     ASSERT(std::is_integral<T>::value);
94     return AlignDown<T>(static_cast<T>(x + alignment - 1U), alignment);
95 }
96 }  // namespace panda::ecmascript
97 
98 #endif  // ECMASCRIPT_MEM_MEM_H
99