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 #define SCOPE_LIST(V) \ 54 V(TotalGC) \ 55 V(Initialize) \ 56 V(ConcurrentMark) \ 57 V(WaitConcurrentMarkFinished) \ 58 V(ReMark) \ 59 V(Mark) \ 60 V(MarkRoots) \ 61 V(ProcessMarkStack) \ 62 V(Sweep) \ 63 V(ClearNativeObject) \ 64 V(Evacuate) \ 65 V(Finish) \ 66 V(UpdateReference) \ 67 V(EvacuateSpace) 68 69 #define RECORD_DATA(V) \ 70 V(START_OBJ_SIZE) \ 71 V(END_OBJ_SIZE) \ 72 V(START_COMMIT_SIZE) \ 73 V(END_COMMIT_SIZE) \ 74 V(START_YOUNG_OBJ_SIZE) \ 75 V(SEMI_ALIVE_SIZE) \ 76 V(SEMI_COMMIT_SIZE) \ 77 V(SEMI_PROMOTE_SIZE) \ 78 V(YOUNG_ALIVE_SIZE) \ 79 V(YOUNG_COMMIT_SIZE) \ 80 V(YOUNG_PROMOTE_SIZE) \ 81 V(OLD_ALIVE_SIZE) \ 82 V(OLD_COMMIT_SIZE) \ 83 V(COMPRESS_ALIVE_SIZE) \ 84 V(COMPRESS_COMMIT_SIZE) \ 85 V(START_NATIVE_POINTER_NUM) \ 86 V(COLLECT_REGION_SET_SIZE) \ 87 SEMI_RECORD_DATA(V) \ 88 PARTIAL_RECORD_DATA(V) \ 89 FULL_RECORD_DATA(V) 90 91 #define RECORD_DURATION(V) \ 92 V(SEMI_MIN_PAUSE) \ 93 V(SEMI_MAX_PAUSE) \ 94 V(SEMI_TOTAL_PAUSE) \ 95 V(YOUNG_MIN_PAUSE) \ 96 V(YOUNG_MAX_PAUSE) \ 97 V(YOUNG_TOTAL_PAUSE) \ 98 V(OLD_MIN_PAUSE) \ 99 V(OLD_MAX_PAUSE) \ 100 V(OLD_TOTAL_PAUSE) \ 101 V(COMPRESS_MIN_PAUSE) \ 102 V(COMPRESS_MAX_PAUSE) \ 103 V(COMPRESS_TOTAL_PAUSE) 104 105 #define SEMI_RECORD_DATA(V) \ 106 V(SEMI_COUNT) \ 107 V(SEMI_TOTAL_ALIVE) \ 108 V(SEMI_TOTAL_COMMIT) \ 109 V(SEMI_TOTAL_PROMOTE) 110 111 #define PARTIAL_RECORD_DATA(V) \ 112 V(YOUNG_COUNT) \ 113 V(YOUNG_TOTAL_ALIVE) \ 114 V(YOUNG_TOTAL_COMMIT) \ 115 V(YOUNG_TOTAL_PROMOTE) \ 116 V(OLD_COUNT) \ 117 V(OLD_TOTAL_ALIVE) \ 118 V(OLD_TOTAL_COMMIT) 119 120 #define FULL_RECORD_DATA(V) \ 121 V(COMPRESS_COUNT) \ 122 V(COMPRESS_TOTAL_ALIVE) \ 123 V(COMPRESS_TOTAL_COMMIT) 124 125 #define TRACE_GC_SPEED(V) \ 126 V(UPDATE_REFERENCE_SPEED) \ 127 V(OLD_CLEAR_NATIVE_OBJ_SPEED) \ 128 V(OLD_EVACUATE_SPACE_SPEED) \ 129 V(YOUNG_CLEAR_NATIVE_OBJ_SPEED) \ 130 V(YOUNG_UPDATE_REFERENCE_SPEED) \ 131 V(YOUNG_EVACUATE_SPACE_SPEED) \ 132 V(MARK_SPEED) \ 133 V(SWEEP_SPEED) 134 135 constexpr uint32_t NUM_MANDATORY_JSFUNC_ARGS = 3; 136 constexpr uint32_t INVALID_INDEX = std::numeric_limits<uint32_t>::max(); 137 138 using Address = uintptr_t; 139 140 #define PUBLIC_API PANDA_PUBLIC_API 141 142 #ifdef NDEBUG 143 #define DUMP_API_ATTR __attribute__((unused)) 144 #else 145 #ifndef PANDA_TARGET_WINDOWS 146 #define DUMP_API_ATTR __attribute__((visibility ("default"), used)) 147 #else 148 #define DUMP_API_ATTR __attribute__((unused)) 149 #endif 150 #endif 151 152 #ifdef PANDA_TARGET_32 153 #define STATIC_ASSERT_EQ_ARCH32(a, b) static_assert(a == b) 154 #else 155 #define STATIC_ASSERT_EQ_ARCH32(a, b) 156 #endif 157 158 #ifdef PANDA_TARGET_64 159 #define STATIC_ASSERT_EQ_ARCH64(a, b) static_assert(a == b) 160 #else 161 #define STATIC_ASSERT_EQ_ARCH64(a, b) 162 #endif 163 164 #if defined(PANDA_TARGET_WINDOWS) || defined(PANDA_TARGET_MACOS) || defined(PANDA_TARGET_IOS) 165 #define WIN_OR_MAC_OR_IOS_PLATFORM true 166 #else 167 #define WIN_OR_MAC_OR_IOS_PLATFORM false 168 #endif 169 170 #define STATIC_ASSERT_EQ_ARCH(expect, valueArch32, valueArch64) \ 171 STATIC_ASSERT_EQ_ARCH32(expect, valueArch32) \ 172 STATIC_ASSERT_EQ_ARCH64(expect, valueArch64) 173 } // namespace ecmascript 174 } // namespace panda 175 176 #endif // ECMASCRIPT_COMMON_H 177