| 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 | const intptr_t kSmiBits = kBitsPerWord - 2; | 
| 24 | const intptr_t kSmiMax = (static_cast<intptr_t>(1) << kSmiBits) - 1; | 
| 25 | const intptr_t kSmiMin = -(static_cast<intptr_t>(1) << kSmiBits); | 
| 26 |  | 
| 27 | // Hard coded from above but for 32-bit architectures. | 
| 28 | const intptr_t kSmiBits32 = kBitsPerInt32 - 2; | 
| 29 | const intptr_t kSmiMax32 = (static_cast<intptr_t>(1) << kSmiBits32) - 1; | 
| 30 | const intptr_t kSmiMin32 = -(static_cast<intptr_t>(1) << kSmiBits32); | 
| 31 |  | 
| 32 | // Number of bytes per BigInt digit. | 
| 33 | const intptr_t kBytesPerBigIntDigit = 4; | 
| 34 |  | 
| 35 | // The default old gen heap size in MB, where 0 == unlimited. | 
| 36 | // 32-bit: OS limit is 2 or 3 GB | 
| 37 | // 64-bit: Linux's limit is | 
| 38 | //   sysctl vm.max_map_count (default 2^16) * 512 KB OldPages = 32 GB | 
| 39 | // Set the VM limit below the OS limit to increase the likelihood of failing | 
| 40 | // gracefully with a Dart OutOfMemory exception instead of SIGABORT. | 
| 41 | const intptr_t kDefaultMaxOldGenHeapSize = (kWordSize <= 4) ? 1536 : 30720; | 
| 42 |  | 
| 43 | #define kPosInfinity bit_cast<double>(DART_UINT64_C(0x7ff0000000000000)) | 
| 44 | #define kNegInfinity bit_cast<double>(DART_UINT64_C(0xfff0000000000000)) | 
| 45 |  | 
| 46 | // The expression ARRAY_SIZE(array) is a compile-time constant of type | 
| 47 | // size_t which represents the number of elements of the given | 
| 48 | // array. You should only use ARRAY_SIZE on statically allocated | 
| 49 | // arrays. | 
| 50 | #define ARRAY_SIZE(array)                                                      \ | 
| 51 |   ((sizeof(array) / sizeof(*(array))) /                                        \ | 
| 52 |    static_cast<intptr_t>(!(sizeof(array) % sizeof(*(array)))))  // NOLINT | 
| 53 |  | 
| 54 | #if defined(PRODUCT) && defined(DEBUG) | 
| 55 | #error Both PRODUCT and DEBUG defined. | 
| 56 | #endif  // defined(PRODUCT) && defined(DEBUG) | 
| 57 |  | 
| 58 | #if defined(PRODUCT) | 
| 59 | #define NOT_IN_PRODUCT(code) | 
| 60 | #else  // defined(PRODUCT) | 
| 61 | #define NOT_IN_PRODUCT(code) code | 
| 62 | #endif  // defined(PRODUCT) | 
| 63 |  | 
| 64 | #if defined(DART_PRECOMPILED_RUNTIME) && defined(DART_PRECOMPILER) | 
| 65 | #error DART_PRECOMPILED_RUNTIME and DART_PRECOMPILER are mutually exclusive | 
| 66 | #endif  // defined(DART_PRECOMPILED_RUNTIME) && defined(DART_PRECOMPILER) | 
| 67 |  | 
| 68 | #if defined(DART_PRECOMPILED_RUNTIME) && defined(DART_NOSNAPSHOT) | 
| 69 | #error DART_PRECOMPILED_RUNTIME and DART_NOSNAPSHOT are mutually exclusive | 
| 70 | #endif  // defined(DART_PRECOMPILED_RUNTIME) && defined(DART_NOSNAPSHOT) | 
| 71 |  | 
| 72 | #if defined(DART_PRECOMPILED_RUNTIME) | 
| 73 | #define NOT_IN_PRECOMPILED(code) | 
| 74 | #else | 
| 75 | #define NOT_IN_PRECOMPILED(code) code | 
| 76 | #endif  // defined(DART_PRECOMPILED_RUNTIME) | 
| 77 |  | 
| 78 | #if defined(DART_PRECOMPILED_RUNTIME) | 
| 79 | #define ONLY_IN_PRECOMPILED(code) code | 
| 80 | #else | 
| 81 | #define ONLY_IN_PRECOMPILED(code) | 
| 82 | #endif  // defined(DART_PRECOMPILED_RUNTIME) | 
| 83 |  | 
| 84 | #if defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_ARM64) ||                  \ | 
| 85 |     defined(TARGET_ARCH_X64) | 
| 86 | #define ONLY_IN_ARM_ARM64_X64(code) code | 
| 87 | #else | 
| 88 | #define ONLY_IN_ARM_ARM64_X64(code) | 
| 89 | #endif | 
| 90 |  | 
| 91 | #if defined(DART_PRECOMPILED_RUNTIME) | 
| 92 | #define NOT_IN_PRECOMPILED_RUNTIME(code) | 
| 93 | #else | 
| 94 | #define NOT_IN_PRECOMPILED_RUNTIME(code) code | 
| 95 | #endif  // defined(DART_PRECOMPILED_RUNTIME) | 
| 96 |  | 
| 97 | #if !defined(PRODUCT) || defined(HOST_OS_FUCHSIA) || defined(TARGET_OS_FUCHSIA) | 
| 98 | #define SUPPORT_TIMELINE 1 | 
| 99 | #endif | 
| 100 |  | 
| 101 | #if defined(ARCH_IS_64_BIT) && !defined(IS_SIMARM_X64) | 
| 102 | #define  1 | 
| 103 | #endif | 
| 104 |  | 
| 105 | // The expression OFFSET_OF(type, field) computes the byte-offset of | 
| 106 | // the specified field relative to the containing type. | 
| 107 | // | 
| 108 | // The expression OFFSET_OF_RETURNED_VALUE(type, accessor) computes the | 
| 109 | // byte-offset of the return value of the accessor to the containing type. | 
| 110 | // | 
| 111 | // None of these use 0 or NULL, which causes a problem with the compiler | 
| 112 | // warnings we have enabled (which is also why 'offsetof' doesn't seem to work). | 
| 113 | // The workaround is to use the non-zero value kOffsetOfPtr. | 
| 114 | const intptr_t kOffsetOfPtr = 32; | 
| 115 |  | 
| 116 | #define OFFSET_OF(type, field)                                                 \ | 
| 117 |   (reinterpret_cast<intptr_t>(                                                 \ | 
| 118 |        &(reinterpret_cast<type*>(kOffsetOfPtr)->field)) -                      \ | 
| 119 |    kOffsetOfPtr)  // NOLINT | 
| 120 |  | 
| 121 | #define OFFSET_OF_RETURNED_VALUE(type, accessor)                               \ | 
| 122 |   (reinterpret_cast<intptr_t>(                                                 \ | 
| 123 |        (reinterpret_cast<type*>(kOffsetOfPtr)->accessor())) -                  \ | 
| 124 |    kOffsetOfPtr)  // NOLINT | 
| 125 |  | 
| 126 | #define SIZE_OF_RETURNED_VALUE(type, method)                                   \ | 
| 127 |   sizeof(reinterpret_cast<type*>(kOffsetOfPtr)->method()) | 
| 128 |  | 
| 129 | #define SIZE_OF_DEREFERENCED_RETURNED_VALUE(type, method)                      \ | 
| 130 |   sizeof(*(reinterpret_cast<type*>(kOffsetOfPtr))->method()) | 
| 131 |  | 
| 132 | #define OPEN_ARRAY_START(type, align)                                          \ | 
| 133 |   do {                                                                         \ | 
| 134 |     const uword result = reinterpret_cast<uword>(this) + sizeof(*this);        \ | 
| 135 |     ASSERT(Utils::IsAligned(result, sizeof(align)));                           \ | 
| 136 |     return reinterpret_cast<type*>(result);                                    \ | 
| 137 |   } while (0) | 
| 138 |  | 
| 139 | // A type large enough to contain the value of the C++ vtable. This is needed | 
| 140 | // to support the handle operations. | 
| 141 | typedef uword cpp_vtable; | 
| 142 |  | 
| 143 | // When using GCC we can use GCC attributes to ensure that certain | 
| 144 | // constants are 8 or 16 byte aligned. | 
| 145 | #if defined(HOST_OS_WINDOWS) | 
| 146 | #define ALIGN8 __declspec(align(8)) | 
| 147 | #define ALIGN16 __declspec(align(16)) | 
| 148 | #else | 
| 149 | #define ALIGN8 __attribute__((aligned(8))) | 
| 150 | #define ALIGN16 __attribute__((aligned(16))) | 
| 151 | #endif | 
| 152 |  | 
| 153 | // Zap value used to indicate uninitialized handle area (debug purposes). | 
| 154 | #if defined(ARCH_IS_32_BIT) | 
| 155 | static const uword kZapUninitializedWord = 0xabababab; | 
| 156 | #else | 
| 157 | static const uword kZapUninitializedWord = 0xabababababababab; | 
| 158 | #endif | 
| 159 |  | 
| 160 | // Macros to get the contents of the fp register. | 
| 161 | #if defined(HOST_OS_WINDOWS) | 
| 162 |  | 
| 163 | // clang-format off | 
| 164 | #if defined(HOST_ARCH_IA32) | 
| 165 | #define COPY_FP_REGISTER(fp)                                                   \ | 
| 166 |   __asm { mov fp, ebp}                                                         \ | 
| 167 |   ;  // NOLINT | 
| 168 | // clang-format on | 
| 169 | #elif defined(HOST_ARCH_X64) | 
| 170 | // We don't have the asm equivalent to get at the frame pointer on | 
| 171 | // windows x64, return the stack pointer instead. | 
| 172 | #define COPY_FP_REGISTER(fp) fp = OSThread::GetCurrentStackPointer(); | 
| 173 | #else | 
| 174 | #error Unknown host architecture. | 
| 175 | #endif | 
| 176 |  | 
| 177 | #else  // !defined(HOST_OS_WINDOWS)) | 
| 178 |  | 
| 179 | // Assume GCC-compatible builtins. | 
| 180 | #define COPY_FP_REGISTER(fp)                                                   \ | 
| 181 |   fp = reinterpret_cast<uintptr_t>(__builtin_frame_address(0)); | 
| 182 |  | 
| 183 | #endif  // !defined(HOST_OS_WINDOWS)) | 
| 184 |  | 
| 185 | #if defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_ARM64) ||                  \ | 
| 186 |     defined(TARGET_ARCH_X64) | 
| 187 | #define TARGET_USES_OBJECT_POOL 1 | 
| 188 | #endif | 
| 189 |  | 
| 190 | #if defined(DART_PRECOMPILER) &&                                               \ | 
| 191 |     (defined(TARGET_ARCH_X64) || defined(TARGET_ARCH_ARM) ||                   \ | 
| 192 |      defined(TARGET_ARCH_ARM64)) | 
| 193 | #define DART_SUPPORT_PRECOMPILATION 1 | 
| 194 | #endif | 
| 195 |  | 
| 196 | }  // namespace dart | 
| 197 |  | 
| 198 | #endif  // RUNTIME_VM_GLOBALS_H_ | 
| 199 |  |