• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 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_SPACE_H
17 #define LIBPANDABASE_MEM_SPACE_H
18 
19 #include "utils/type_helpers.h"
20 
21 namespace ark {
22 
23 /// SpaceType and GCCollectMode provide info when we should collect from some allocator or not
24 enum class SpaceType : uint16_t {
25     SPACE_TYPE_UNDEFINED = 0,
26     SPACE_TYPE_OBJECT,              // Space for objects (all non-humongous sizes)
27     SPACE_TYPE_HUMONGOUS_OBJECT,    // Space for humongous objects
28     SPACE_TYPE_NON_MOVABLE_OBJECT,  // Space for non-movable objects
29     SPACE_TYPE_INTERNAL,            // Space for runtime internal needs
30     SPACE_TYPE_FRAMES,              // Space for runtime frames allocations
31     SPACE_TYPE_NATIVE_STACKS,       // Space for native stacks allocations (e.g. for fibers/threads)
32     SPACE_TYPE_CODE,                // Space for compiled code
33     SPACE_TYPE_COMPILER,            // Space for memory allocation in compiler
34 
35     SPACE_TYPE_LAST  // Count of different types
36 };
37 
ToSpaceType(size_t index)38 constexpr SpaceType ToSpaceType(size_t index)
39 {
40     return static_cast<SpaceType>(index);
41 }
42 
SpaceTypeToIndex(SpaceType spaceType)43 constexpr size_t SpaceTypeToIndex(SpaceType spaceType)
44 {
45     return helpers::ToUnderlying(spaceType);
46 }
47 
48 constexpr size_t SPACE_TYPE_SIZE = helpers::ToUnderlying(SpaceType::SPACE_TYPE_LAST);
49 
IsHeapSpace(SpaceType spaceType)50 constexpr bool IsHeapSpace(SpaceType spaceType)
51 {
52     return (spaceType == SpaceType::SPACE_TYPE_OBJECT) || (spaceType == SpaceType::SPACE_TYPE_HUMONGOUS_OBJECT) ||
53            (spaceType == SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT);
54 }
55 
SpaceTypeToString(SpaceType type)56 inline const char *SpaceTypeToString(SpaceType type)
57 {
58     switch (type) {
59         case SpaceType::SPACE_TYPE_UNDEFINED:
60             return "ark-Undefined Space";
61         case SpaceType::SPACE_TYPE_OBJECT:
62             return "ark-Object Space";
63         case SpaceType::SPACE_TYPE_HUMONGOUS_OBJECT:
64             return "ark-Humongous Object Space";
65         case SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT:
66             return "ark-Non Movable Space";
67         case SpaceType::SPACE_TYPE_INTERNAL:
68             return "ark-Internal Space";
69         case SpaceType::SPACE_TYPE_CODE:
70             return "ark-Code Space";
71         case SpaceType::SPACE_TYPE_COMPILER:
72             return "ark-Compiler Space";
73         case SpaceType::SPACE_TYPE_FRAMES:
74             return "ark-Frames Space";
75         case SpaceType::SPACE_TYPE_NATIVE_STACKS:
76             return "ark-Native Stacks Space";
77         default:
78             return "ark-Unknown Space";
79     }
80 }
81 
82 }  // namespace ark
83 
84 #endif  // LIBPANDABASE_MEM_SPACE_H
85