| 1 | // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 | // for details. All rights reserved. Use of this source code is governed by a |
| 3 | // BSD-style license that can be found in the LICENSE file. |
| 4 | |
| 5 | #ifndef RUNTIME_VM_GLOBALS_H_ |
| 6 | #define RUNTIME_VM_GLOBALS_H_ |
| 7 | |
| 8 | // This file contains global definitions for the VM library only. Anything that |
| 9 | // is more globally useful should be added to 'vm/globals.h'. |
| 10 | |
| 11 | #include "platform/globals.h" |
| 12 | |
| 13 | #if defined(_WIN32) |
| 14 | // Undef conflicting defines. |
| 15 | #undef PARITY_EVEN |
| 16 | #undef PARITY_ODD |
| 17 | #undef near |
| 18 | #endif // defined(_WIN32) |
| 19 | |
| 20 | namespace dart { |
| 21 | // Smi value range is from -(2^N) to (2^N)-1. |
| 22 | // N=30 (32-bit build) or N=62 (64-bit build). |
| 23 | #if !defined(DART_COMPRESSED_POINTERS) |
| 24 | const intptr_t kSmiBits = kBitsPerWord - 2; |
| 25 | #else |
| 26 | const intptr_t kSmiBits = 30; |
| 27 | #endif |
| 28 | const intptr_t kSmiMax = (static_cast<intptr_t>(1) << kSmiBits) - 1; |
| 29 | const intptr_t kSmiMin = -(static_cast<intptr_t>(1) << kSmiBits); |
| 30 | |
| 31 | // Hard coded from above but for 32-bit architectures. |
| 32 | const intptr_t kSmiBits32 = kBitsPerInt32 - 2; |
| 33 | const intptr_t kSmiMax32 = (static_cast<intptr_t>(1) << kSmiBits32) - 1; |
| 34 | const intptr_t kSmiMin32 = -(static_cast<intptr_t>(1) << kSmiBits32); |
| 35 | |
| 36 | #if defined(DART_COMPRESSED_POINTERS) |
| 37 | static constexpr int kCompressedWordSize = kInt32Size; |
| 38 | static constexpr int kCompressedWordSizeLog2 = kInt32SizeLog2; |
| 39 | typedef uint32_t compressed_uword; |
| 40 | typedef int32_t compressed_word; |
| 41 | #else |
| 42 | static constexpr int kCompressedWordSize = kWordSize; |
| 43 | static constexpr int kCompressedWordSizeLog2 = kWordSizeLog2; |
| 44 | typedef uintptr_t compressed_uword; |
| 45 | typedef intptr_t compressed_word; |
| 46 | #endif |
| 47 | // 32-bit: 2^32 addresses => kMaxAddrSpaceMB = 2^(32 - MBLog2) = 2^12 MB |
| 48 | // 64-bit: 2^48 addresses => kMaxAddrSpaceMB = 2^(48 - MBLog2) = 2^28 MB |
| 49 | const intptr_t kMaxAddrSpaceMB = (kWordSize <= 4) ? 4096 : 268435456; |
| 50 | const intptr_t kMaxAddrSpaceInWords = kMaxAddrSpaceMB >> kWordSizeLog2 |
| 51 | << MBLog2; |
| 52 | |
| 53 | // Number of bytes per BigInt digit. |
| 54 | const intptr_t kBytesPerBigIntDigit = 4; |
| 55 | |
| 56 | // The default old gen heap size in MB, where 0 -- unlimited. |
| 57 | // 32-bit: OS limit is 2 or 3 GB |
| 58 | // 64-bit: Linux's limit is |
| 59 | // sysctl vm.max_map_count (default 2^16) * 512 KB Pages = 32 GB |
| 60 | // Set the VM limit below the OS limit to increase the likelihood of failing |
| 61 | // gracefully with a Dart OutOfMemory exception instead of SIGABORT. |
| 62 | const intptr_t kDefaultMaxOldGenHeapSize = (kWordSize <= 4) ? 1536 : 30720; |
| 63 | const intptr_t kDefaultNewGenSemiMaxSize = (kWordSize <= 4) ? 8 : 16; |
| 64 | |
| 65 | #define kPosInfinity bit_cast<double>(DART_UINT64_C(0x7ff0000000000000)) |
| 66 | #define kNegInfinity bit_cast<double>(DART_UINT64_C(0xfff0000000000000)) |
| 67 | |
| 68 | // The expression ARRAY_SIZE(array) is a compile-time constant of type |
| 69 | // size_t which represents the number of elements of the given |
| 70 | // array. You should only use ARRAY_SIZE on statically allocated |
| 71 | // arrays. |
| 72 | #define ARRAY_SIZE(array) \ |
| 73 | ((sizeof(array) / sizeof(*(array))) / \ |
| 74 | static_cast<intptr_t>(!(sizeof(array) % sizeof(*(array))))) // NOLINT |
| 75 | |
| 76 | #if defined(PRODUCT) && defined(DEBUG) |
| 77 | #error Both PRODUCT and DEBUG defined. |
| 78 | #endif // defined(PRODUCT) && defined(DEBUG) |
| 79 | |
| 80 | #if defined(PRODUCT) |
| 81 | #define NOT_IN_PRODUCT(code) |
| 82 | #define ONLY_IN_PRODUCT(code) code |
| 83 | #else // defined(PRODUCT) |
| 84 | #define NOT_IN_PRODUCT(code) code |
| 85 | #define ONLY_IN_PRODUCT(code) |
| 86 | #endif // defined(PRODUCT) |
| 87 | |
| 88 | #if defined(DART_PRECOMPILED_RUNTIME) && defined(DART_PRECOMPILER) |
| 89 | #error DART_PRECOMPILED_RUNTIME and DART_PRECOMPILER are mutually exclusive |
| 90 | #endif // defined(DART_PRECOMPILED_RUNTIME) && defined(DART_PRECOMPILER) |
| 91 | |
| 92 | #if defined(DART_PRECOMPILED_RUNTIME) && defined(DART_NOSNAPSHOT) |
| 93 | #error DART_PRECOMPILED_RUNTIME and DART_NOSNAPSHOT are mutually exclusive |
| 94 | #endif // defined(DART_PRECOMPILED_RUNTIME) && defined(DART_NOSNAPSHOT) |
| 95 | |
| 96 | #if defined(DART_PRECOMPILED_RUNTIME) |
| 97 | #define NOT_IN_PRECOMPILED(code) |
| 98 | #define ONLY_IN_PRECOMPILED(code) code |
| 99 | #else |
| 100 | #define NOT_IN_PRECOMPILED(code) code |
| 101 | #define ONLY_IN_PRECOMPILED(code) |
| 102 | #endif // defined(DART_PRECOMPILED_RUNTIME) |
| 103 | |
| 104 | #if defined(TARGET_ARCH_IA32) |
| 105 | #define NOT_IN_IA32(code) |
| 106 | #else |
| 107 | #define NOT_IN_IA32(code) code |
| 108 | #endif |
| 109 | |
| 110 | #if defined(DART_PRECOMPILED_RUNTIME) |
| 111 | #define NOT_IN_PRECOMPILED_RUNTIME(code) |
| 112 | #else |
| 113 | #define NOT_IN_PRECOMPILED_RUNTIME(code) code |
| 114 | #endif // defined(DART_PRECOMPILED_RUNTIME) |
| 115 | |
| 116 | #if !defined(DART_DISABLE_TIMELINE) && \ |
| 117 | (defined(DART_ENABLE_TIMELINE) || !defined(PRODUCT) || \ |
| 118 | defined(DART_HOST_OS_FUCHSIA) || defined(DART_TARGET_OS_FUCHSIA) || \ |
| 119 | defined(DART_TARGET_OS_ANDROID) || defined(DART_TARGET_OS_MACOS)) |
| 120 | #define SUPPORT_TIMELINE 1 |
| 121 | #endif |
| 122 | |
| 123 | #if defined(ARCH_IS_64_BIT) && !defined(IS_SIMARM_HOST64) |
| 124 | #define 1 |
| 125 | #endif |
| 126 | |
| 127 | // The expression OFFSET_OF(type, field) computes the byte-offset of |
| 128 | // the specified field relative to the containing type. |
| 129 | // |
| 130 | // The expression OFFSET_OF_RETURNED_VALUE(type, accessor) computes the |
| 131 | // byte-offset of the return value of the accessor to the containing type. |
| 132 | // |
| 133 | // None of these use 0 or nullptr, which causes a problem with the compiler |
| 134 | // warnings we have enabled (which is also why 'offsetof' doesn't seem to work). |
| 135 | // The workaround is to use the non-zero value kOffsetOfPtr. |
| 136 | const intptr_t kOffsetOfPtr = 32; |
| 137 | |
| 138 | #define OFFSET_OF(type, field) \ |
| 139 | (reinterpret_cast<intptr_t>( \ |
| 140 | &(reinterpret_cast<type*>(kOffsetOfPtr)->field)) - \ |
| 141 | kOffsetOfPtr) // NOLINT |
| 142 | |
| 143 | #define OFFSET_OF_RETURNED_VALUE(type, accessor) \ |
| 144 | (reinterpret_cast<intptr_t>( \ |
| 145 | (reinterpret_cast<type*>(kOffsetOfPtr)->accessor())) - \ |
| 146 | kOffsetOfPtr) // NOLINT |
| 147 | |
| 148 | #define SIZE_OF_RETURNED_VALUE(type, method) \ |
| 149 | sizeof(reinterpret_cast<type*>(kOffsetOfPtr)->method()) |
| 150 | |
| 151 | #define SIZE_OF_DEREFERENCED_RETURNED_VALUE(type, method) \ |
| 152 | sizeof(*(reinterpret_cast<type*>(kOffsetOfPtr))->method()) |
| 153 | |
| 154 | #define OPEN_ARRAY_START(type, align) \ |
| 155 | do { \ |
| 156 | const uword result = reinterpret_cast<uword>(this) + sizeof(*this); \ |
| 157 | ASSERT(Utils::IsAligned(result, alignof(align))); \ |
| 158 | return reinterpret_cast<type*>(result); \ |
| 159 | } while (0) |
| 160 | |
| 161 | // A type large enough to contain the value of the C++ vtable. This is needed |
| 162 | // to support the handle operations. |
| 163 | typedef uword cpp_vtable; |
| 164 | |
| 165 | // When using GCC we can use GCC attributes to ensure that certain |
| 166 | // constants are 8 or 16 byte aligned. |
| 167 | #if defined(DART_HOST_OS_WINDOWS) |
| 168 | #define ALIGN8 __declspec(align(8)) |
| 169 | #define ALIGN16 __declspec(align(16)) |
| 170 | #else |
| 171 | #define ALIGN8 __attribute__((aligned(8))) |
| 172 | #define ALIGN16 __attribute__((aligned(16))) |
| 173 | #endif |
| 174 | |
| 175 | // Zap value used to indicate uninitialized handle area (debug purposes). |
| 176 | #if defined(ARCH_IS_32_BIT) |
| 177 | static constexpr uword kZapUninitializedWord = 0xabababab; |
| 178 | #else |
| 179 | static constexpr uword kZapUninitializedWord = 0xabababababababab; |
| 180 | #endif |
| 181 | |
| 182 | // Macros to get the contents of the fp register. |
| 183 | #if defined(DART_HOST_OS_WINDOWS) |
| 184 | |
| 185 | // clang-format off |
| 186 | #if defined(HOST_ARCH_IA32) |
| 187 | #define COPY_FP_REGISTER(fp) \ |
| 188 | __asm { mov fp, ebp} \ |
| 189 | ; // NOLINT |
| 190 | // clang-format on |
| 191 | #else |
| 192 | // Inline assembly is only available on x86; return the stack pointer instead. |
| 193 | #define COPY_FP_REGISTER(fp) fp = OSThread::GetCurrentStackPointer(); |
| 194 | #endif |
| 195 | |
| 196 | #else // !defined(DART_HOST_OS_WINDOWS)) |
| 197 | |
| 198 | // Assume GCC-compatible builtins. |
| 199 | #define COPY_FP_REGISTER(fp) \ |
| 200 | fp = reinterpret_cast<uintptr_t>(__builtin_frame_address(0)); |
| 201 | |
| 202 | #endif // !defined(DART_HOST_OS_WINDOWS)) |
| 203 | |
| 204 | #if defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_ARM64) || \ |
| 205 | defined(TARGET_ARCH_X64) || defined(TARGET_ARCH_RISCV32) || \ |
| 206 | defined(TARGET_ARCH_RISCV64) |
| 207 | #define TARGET_USES_OBJECT_POOL 1 |
| 208 | #endif |
| 209 | |
| 210 | #if defined(DART_PRECOMPILER) && \ |
| 211 | (defined(TARGET_ARCH_X64) || defined(TARGET_ARCH_ARM) || \ |
| 212 | defined(TARGET_ARCH_ARM64) || defined(TARGET_ARCH_RISCV32) || \ |
| 213 | defined(TARGET_ARCH_RISCV64)) |
| 214 | #define DART_SUPPORT_PRECOMPILATION 1 |
| 215 | #endif |
| 216 | |
| 217 | } // namespace dart |
| 218 | |
| 219 | #endif // RUNTIME_VM_GLOBALS_H_ |
| 220 | |