• 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_COMMON_H
17 #define ECMASCRIPT_COMMON_H
18 
19 #include <limits>
20 
21 #include "libpandabase/macros.h"
22 
23 namespace panda {
24 namespace ecmascript {
25 enum BarrierMode { SKIP_BARRIER, WRITE_BARRIER, READ_BARRIER };
26 
27 /*
28  * TriggerGCType is categorized according to the scope the GC expects to cover.
29  * Different GC algorithms may be applied to different GC types.
30  * For example, SemiSpace GC for young generation GC, Mark-Sweep-Compact for full GC, etc.
31  */
32 enum TriggerGCType {
33     // GC is expected to cover young space only;
34     YOUNG_GC,
35     // GC is expected to cover young space and necessary old spaces;
36     OLD_GC,
37     // GC is expected to cover all valid heap spaces;
38     FULL_GC,
39     // GC is expected to compress objects into appspawn space;
40     APPSPAWN_FULL_GC,
41     GC_TYPE_LAST
42 };
43 
44 enum class GCReason : uint8_t {
45     ALLOCATION_LIMIT,
46     ALLOCATION_FAILED,
47     IDLE,
48     SWITCH_BACKGROUND,
49     EXTERNAL_TRIGGER,
50     OTHER,
51 };
52 
53 enum class RequestAotMode : uint8_t {
54     RE_COMPILE_ON_IDLE = 0
55 };
56 
57 #define SCOPE_LIST(V)                    \
58     V(TotalGC)                           \
59     V(Initialize)                        \
60     V(ConcurrentMark)                    \
61     V(WaitConcurrentMarkFinished)        \
62     V(ReMark)                            \
63     V(Mark)                              \
64     V(MarkRoots)                         \
65     V(ProcessMarkStack)                  \
66     V(Sweep)                             \
67     V(ClearNativeObject)                 \
68     V(Evacuate)                          \
69     V(Finish)                            \
70     V(UpdateReference)                   \
71     V(EvacuateSpace)
72 
73 #define RECORD_DATA(V)                   \
74     V(START_OBJ_SIZE)                    \
75     V(END_OBJ_SIZE)                      \
76     V(START_COMMIT_SIZE)                 \
77     V(END_COMMIT_SIZE)                   \
78     V(START_YOUNG_OBJ_SIZE)              \
79     V(SEMI_ALIVE_SIZE)                   \
80     V(SEMI_COMMIT_SIZE)                  \
81     V(SEMI_PROMOTE_SIZE)                 \
82     V(YOUNG_ALIVE_SIZE)                  \
83     V(YOUNG_COMMIT_SIZE)                 \
84     V(YOUNG_PROMOTE_SIZE)                \
85     V(OLD_ALIVE_SIZE)                    \
86     V(OLD_COMMIT_SIZE)                   \
87     V(COMPRESS_ALIVE_SIZE)               \
88     V(COMPRESS_COMMIT_SIZE)              \
89     V(START_NATIVE_POINTER_NUM)          \
90     V(COLLECT_REGION_SET_SIZE)           \
91     SEMI_RECORD_DATA(V)                  \
92     PARTIAL_RECORD_DATA(V)               \
93     FULL_RECORD_DATA(V)
94 
95 #define RECORD_DURATION(V)               \
96     V(SEMI_MIN_PAUSE)                    \
97     V(SEMI_MAX_PAUSE)                    \
98     V(SEMI_TOTAL_PAUSE)                  \
99     V(YOUNG_MIN_PAUSE)                   \
100     V(YOUNG_MAX_PAUSE)                   \
101     V(YOUNG_TOTAL_PAUSE)                 \
102     V(OLD_MIN_PAUSE)                     \
103     V(OLD_MAX_PAUSE)                     \
104     V(OLD_TOTAL_PAUSE)                   \
105     V(COMPRESS_MIN_PAUSE)                \
106     V(COMPRESS_MAX_PAUSE)                \
107     V(COMPRESS_TOTAL_PAUSE)
108 
109 #define SEMI_RECORD_DATA(V)              \
110     V(SEMI_COUNT)                        \
111     V(SEMI_TOTAL_ALIVE)                  \
112     V(SEMI_TOTAL_COMMIT)                 \
113     V(SEMI_TOTAL_PROMOTE)
114 
115 #define PARTIAL_RECORD_DATA(V)           \
116     V(YOUNG_COUNT)                       \
117     V(YOUNG_TOTAL_ALIVE)                 \
118     V(YOUNG_TOTAL_COMMIT)                \
119     V(YOUNG_TOTAL_PROMOTE)               \
120     V(OLD_COUNT)                         \
121     V(OLD_TOTAL_ALIVE)                   \
122     V(OLD_TOTAL_COMMIT)
123 
124 #define FULL_RECORD_DATA(V)              \
125     V(COMPRESS_COUNT)                    \
126     V(COMPRESS_TOTAL_ALIVE)              \
127     V(COMPRESS_TOTAL_COMMIT)
128 
129 #define TRACE_GC_SPEED(V)                \
130     V(UPDATE_REFERENCE_SPEED)            \
131     V(OLD_CLEAR_NATIVE_OBJ_SPEED)        \
132     V(OLD_EVACUATE_SPACE_SPEED)          \
133     V(YOUNG_CLEAR_NATIVE_OBJ_SPEED)      \
134     V(YOUNG_UPDATE_REFERENCE_SPEED)      \
135     V(YOUNG_EVACUATE_SPACE_SPEED)        \
136     V(MARK_SPEED)                        \
137     V(SWEEP_SPEED)
138 
139 constexpr uint32_t NUM_MANDATORY_JSFUNC_ARGS = 3;
140 constexpr uint32_t INVALID_INDEX = std::numeric_limits<uint32_t>::max();
141 
142 using Address = uintptr_t;
143 
144 #define PUBLIC_API PANDA_PUBLIC_API
145 
146 #ifdef NDEBUG
147 #define DUMP_API_ATTR __attribute__((unused))
148 #else
149 #ifndef PANDA_TARGET_WINDOWS
150 #define DUMP_API_ATTR __attribute__((visibility ("default"), used))
151 #else
152 #define DUMP_API_ATTR __attribute__((unused))
153 #endif
154 #endif
155 
156 #ifdef PANDA_TARGET_32
157 #define STATIC_ASSERT_EQ_ARCH32(a, b) static_assert(a == b)
158 #else
159 #define STATIC_ASSERT_EQ_ARCH32(a, b) static_assert(true)
160 #endif
161 
162 #ifdef PANDA_TARGET_64
163 #define STATIC_ASSERT_EQ_ARCH64(a, b) static_assert(a == b)
164 #else
165 #define STATIC_ASSERT_EQ_ARCH64(a, b) static_assert(true)
166 #endif
167 
168 #if defined(PANDA_TARGET_WINDOWS) || defined(PANDA_TARGET_MACOS) || defined(PANDA_TARGET_IOS)
169 #define WIN_OR_MAC_OR_IOS_PLATFORM true
170 #else
171 #define WIN_OR_MAC_OR_IOS_PLATFORM false
172 #endif
173 
174 #define ECMASCRIPT_ENABLE_VALUE_SERIALIZER 1
175 
176 #define STATIC_ASSERT_EQ_ARCH(expect, valueArch32, valueArch64) \
177     STATIC_ASSERT_EQ_ARCH32(expect, valueArch32);               \
178     STATIC_ASSERT_EQ_ARCH64(expect, valueArch64)
179 }  // namespace ecmascript
180 }  // namespace panda
181 
182 #endif  // ECMASCRIPT_COMMON_H
183