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 #include "libpandabase/macros.h" 21 22 namespace panda { 23 namespace ecmascript { 24 enum BarrierMode { SKIP_BARRIER, WRITE_BARRIER, READ_BARRIER }; 25 26 /* 27 * TriggerGCType is categorized according to the scope the GC expects to cover. 28 * Different GC algorithms may be applied to different GC types. 29 * For example, SemiSpace GC for young generation GC, Mark-Sweep-Compact for full GC, etc. 30 */ 31 enum TriggerGCType { 32 // GC is expected to cover young space only; 33 YOUNG_GC, 34 // GC is expected to cover young space and necessary old spaces; 35 OLD_GC, 36 // GC is expected to cover all valid heap spaces; 37 FULL_GC, 38 // GC is expected to compress objects into appspawn space; 39 APPSPAWN_FULL_GC, 40 GC_TYPE_LAST 41 }; 42 43 constexpr uint32_t NUM_MANDATORY_JSFUNC_ARGS = 3; 44 constexpr uint32_t INVALID_INDEX = std::numeric_limits<uint32_t>::max(); 45 46 using Address = uintptr_t; 47 48 #define PUBLIC_API PANDA_PUBLIC_API 49 50 #ifdef NDEBUG 51 #define DUMP_API_ATTR __attribute__((unused)) 52 #else 53 #ifndef PANDA_TARGET_WINDOWS 54 #define DUMP_API_ATTR __attribute__((visibility ("default"), used)) 55 #else 56 #define DUMP_API_ATTR __attribute__((unused)) 57 #endif 58 #endif 59 60 #ifdef PANDA_TARGET_32 61 #define STATIC_ASSERT_EQ_ARCH32(a, b) static_assert(a == b) 62 #else 63 #define STATIC_ASSERT_EQ_ARCH32(a, b) 64 #endif 65 66 #ifdef PANDA_TARGET_64 67 #define STATIC_ASSERT_EQ_ARCH64(a, b) static_assert(a == b) 68 #else 69 #define STATIC_ASSERT_EQ_ARCH64(a, b) 70 #endif 71 72 #if defined(PANDA_TARGET_WINDOWS) || defined(PANDA_TARGET_MACOS) || defined(PANDA_TARGET_IOS) 73 #define WIN_OR_MAC_OR_IOS_PLATFORM true 74 #else 75 #define WIN_OR_MAC_OR_IOS_PLATFORM false 76 #endif 77 78 #define STATIC_ASSERT_EQ_ARCH(expect, valueArch32, valueArch64) \ 79 STATIC_ASSERT_EQ_ARCH32(expect, valueArch32) \ 80 STATIC_ASSERT_EQ_ARCH64(expect, valueArch64) 81 } // namespace ecmascript 82 } // namespace panda 83 84 #endif // ECMASCRIPT_COMMON_H 85