• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_SPACE_H
17 #define LIBPANDABASE_MEM_SPACE_H
18 
19 #include "utils/type_helpers.h"
20 
21 namespace panda {
22 
23 /**
24  * SpaceType and GCCollectMode provide info when we should collect from some allocator or not
25  */
26 enum class SpaceType : size_t {
27     SPACE_TYPE_UNDEFINED = 0,
28     SPACE_TYPE_OBJECT,              // Space for objects (all non-humongous sizes)
29     SPACE_TYPE_HUMONGOUS_OBJECT,    // Space for humongous objects
30     SPACE_TYPE_NON_MOVABLE_OBJECT,  // Space for non-movable objects
31     SPACE_TYPE_INTERNAL,            // Space for runtime internal needs
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 
43 constexpr size_t SPACE_TYPE_SIZE = helpers::ToUnderlying(SpaceType::SPACE_TYPE_LAST);
44 
IsHeapSpace(SpaceType space_type)45 constexpr bool IsHeapSpace(SpaceType space_type)
46 {
47     return (space_type == SpaceType::SPACE_TYPE_OBJECT) || (space_type == SpaceType::SPACE_TYPE_HUMONGOUS_OBJECT) ||
48            (space_type == SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT);
49 }
50 
SpaceTypeToString(SpaceType type)51 inline const char *SpaceTypeToString(SpaceType type)
52 {
53     switch (type) {
54         case SpaceType::SPACE_TYPE_UNDEFINED:
55             return "ark-Undefined Space";
56         case SpaceType::SPACE_TYPE_OBJECT:
57             return "ark-Object Space";
58         case SpaceType::SPACE_TYPE_HUMONGOUS_OBJECT:
59             return "ark-Humongous Object Space";
60         case SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT:
61             return "ark-Non Movable Space";
62         case SpaceType::SPACE_TYPE_INTERNAL:
63             return "ark-Internal Space";
64         case SpaceType::SPACE_TYPE_CODE:
65             return "ark-Code Space";
66         case SpaceType::SPACE_TYPE_COMPILER:
67             return "ark-Compiler Space";
68         default:
69             return "ark-Unknown Space";
70     }
71 }
72 
73 }  // namespace panda
74 
75 #endif  // LIBPANDABASE_MEM_SPACE_H
76