Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4 | |
| 5 | #ifndef V8_GLOBALS_H_ |
| 6 | #define V8_GLOBALS_H_ |
| 7 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8 | #include <stddef.h> |
| 9 | #include <stdint.h> |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 10 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 11 | #include <ostream> |
| 12 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 13 | #include "src/base/build_config.h" |
| 14 | #include "src/base/logging.h" |
| 15 | #include "src/base/macros.h" |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 16 | |
| 17 | // Unfortunately, the INFINITY macro cannot be used with the '-pedantic' |
| 18 | // warning flag and certain versions of GCC due to a bug: |
| 19 | // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11931 |
| 20 | // For now, we use the more involved template-based version from <limits>, but |
| 21 | // only when compiling with GCC versions affected by the bug (2.96.x - 4.0.x) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 22 | #if V8_CC_GNU && V8_GNUC_PREREQ(2, 96, 0) && !V8_GNUC_PREREQ(4, 1, 0) |
| 23 | # include <limits> // NOLINT |
| 24 | # define V8_INFINITY std::numeric_limits<double>::infinity() |
| 25 | #elif V8_LIBC_MSVCRT |
| 26 | # define V8_INFINITY HUGE_VAL |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 27 | #elif V8_OS_AIX |
| 28 | #define V8_INFINITY (__builtin_inff()) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 29 | #else |
| 30 | # define V8_INFINITY INFINITY |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 31 | #endif |
| 32 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 33 | namespace v8 { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 34 | |
| 35 | namespace base { |
| 36 | class Mutex; |
| 37 | class RecursiveMutex; |
| 38 | class VirtualMemory; |
| 39 | } |
| 40 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 41 | namespace internal { |
| 42 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 43 | // Determine whether we are running in a simulated environment. |
| 44 | // Setting USE_SIMULATOR explicitly from the build script will force |
| 45 | // the use of a simulated environment. |
| 46 | #if !defined(USE_SIMULATOR) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 47 | #if (V8_TARGET_ARCH_ARM64 && !V8_HOST_ARCH_ARM64) |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 48 | #define USE_SIMULATOR 1 |
| 49 | #endif |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 50 | #if (V8_TARGET_ARCH_ARM && !V8_HOST_ARCH_ARM) |
| 51 | #define USE_SIMULATOR 1 |
| 52 | #endif |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 53 | #if (V8_TARGET_ARCH_PPC && !V8_HOST_ARCH_PPC) |
| 54 | #define USE_SIMULATOR 1 |
| 55 | #endif |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 56 | #if (V8_TARGET_ARCH_MIPS && !V8_HOST_ARCH_MIPS) |
| 57 | #define USE_SIMULATOR 1 |
| 58 | #endif |
| 59 | #if (V8_TARGET_ARCH_MIPS64 && !V8_HOST_ARCH_MIPS64) |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 60 | #define USE_SIMULATOR 1 |
| 61 | #endif |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 62 | #if (V8_TARGET_ARCH_S390 && !V8_HOST_ARCH_S390) |
| 63 | #define USE_SIMULATOR 1 |
| 64 | #endif |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 65 | #endif |
| 66 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 67 | // Determine whether the architecture uses an embedded constant pool |
| 68 | // (contiguous constant pool embedded in code object). |
| 69 | #if V8_TARGET_ARCH_PPC |
| 70 | #define V8_EMBEDDED_CONSTANT_POOL 1 |
| 71 | #else |
| 72 | #define V8_EMBEDDED_CONSTANT_POOL 0 |
| 73 | #endif |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 74 | |
| 75 | #ifdef V8_TARGET_ARCH_ARM |
| 76 | // Set stack limit lower for ARM than for other architectures because |
| 77 | // stack allocating MacroAssembler takes 120K bytes. |
| 78 | // See issue crbug.com/405338 |
| 79 | #define V8_DEFAULT_STACK_SIZE_KB 864 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 80 | #else |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 81 | // Slightly less than 1MB, since Windows' default stack size for |
| 82 | // the main execution thread is 1MB for both 32 and 64-bit. |
| 83 | #define V8_DEFAULT_STACK_SIZE_KB 984 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 84 | #endif |
| 85 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 86 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 87 | // Determine whether double field unboxing feature is enabled. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 88 | #if V8_TARGET_ARCH_64_BIT |
| 89 | #define V8_DOUBLE_FIELDS_UNBOXING 1 |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 90 | #else |
| 91 | #define V8_DOUBLE_FIELDS_UNBOXING 0 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 92 | #endif |
| 93 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 94 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 95 | typedef uint8_t byte; |
| 96 | typedef byte* Address; |
| 97 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 98 | // ----------------------------------------------------------------------------- |
| 99 | // Constants |
| 100 | |
| 101 | const int KB = 1024; |
| 102 | const int MB = KB * KB; |
| 103 | const int GB = KB * KB * KB; |
| 104 | const int kMaxInt = 0x7FFFFFFF; |
| 105 | const int kMinInt = -kMaxInt - 1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 106 | const int kMaxInt8 = (1 << 7) - 1; |
| 107 | const int kMinInt8 = -(1 << 7); |
| 108 | const int kMaxUInt8 = (1 << 8) - 1; |
| 109 | const int kMinUInt8 = 0; |
| 110 | const int kMaxInt16 = (1 << 15) - 1; |
| 111 | const int kMinInt16 = -(1 << 15); |
| 112 | const int kMaxUInt16 = (1 << 16) - 1; |
| 113 | const int kMinUInt16 = 0; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 114 | |
| 115 | const uint32_t kMaxUInt32 = 0xFFFFFFFFu; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 116 | const int kMinUInt32 = 0; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 117 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 118 | const int kCharSize = sizeof(char); // NOLINT |
| 119 | const int kShortSize = sizeof(short); // NOLINT |
| 120 | const int kIntSize = sizeof(int); // NOLINT |
| 121 | const int kInt32Size = sizeof(int32_t); // NOLINT |
| 122 | const int kInt64Size = sizeof(int64_t); // NOLINT |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 123 | const int kFloatSize = sizeof(float); // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 124 | const int kDoubleSize = sizeof(double); // NOLINT |
| 125 | const int kIntptrSize = sizeof(intptr_t); // NOLINT |
| 126 | const int kPointerSize = sizeof(void*); // NOLINT |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 127 | #if V8_TARGET_ARCH_ARM64 |
| 128 | const int kFrameAlignmentInBytes = 2 * kPointerSize; |
| 129 | #else |
| 130 | const int kFrameAlignmentInBytes = kPointerSize; |
| 131 | #endif |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 132 | #if V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_32_BIT |
| 133 | const int kRegisterSize = kPointerSize + kPointerSize; |
| 134 | #else |
| 135 | const int kRegisterSize = kPointerSize; |
| 136 | #endif |
| 137 | const int kPCOnStackSize = kRegisterSize; |
| 138 | const int kFPOnStackSize = kRegisterSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 139 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 140 | #if V8_TARGET_ARCH_X64 || V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_X87 |
| 141 | const int kElidedFrameSlots = kPCOnStackSize / kPointerSize; |
| 142 | #else |
| 143 | const int kElidedFrameSlots = 0; |
| 144 | #endif |
| 145 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 146 | const int kDoubleSizeLog2 = 3; |
| 147 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 148 | #if V8_HOST_ARCH_64_BIT |
| 149 | const int kPointerSizeLog2 = 3; |
| 150 | const intptr_t kIntptrSignBit = V8_INT64_C(0x8000000000000000); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 151 | const uintptr_t kUintptrAllBitsSet = V8_UINT64_C(0xFFFFFFFFFFFFFFFF); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 152 | const bool kRequiresCodeRange = true; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 153 | #if V8_TARGET_ARCH_MIPS64 |
| 154 | // To use pseudo-relative jumps such as j/jal instructions which have 28-bit |
| 155 | // encoded immediate, the addresses have to be in range of 256MB aligned |
| 156 | // region. Used only for large object space. |
| 157 | const size_t kMaximalCodeRangeSize = 256 * MB; |
| 158 | #else |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 159 | const size_t kMaximalCodeRangeSize = 512 * MB; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 160 | #endif |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 161 | #if V8_OS_WIN |
| 162 | const size_t kMinimumCodeRangeSize = 4 * MB; |
| 163 | const size_t kReservedCodeRangePages = 1; |
| 164 | #else |
| 165 | const size_t kMinimumCodeRangeSize = 3 * MB; |
| 166 | const size_t kReservedCodeRangePages = 0; |
| 167 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 168 | #else |
| 169 | const int kPointerSizeLog2 = 2; |
| 170 | const intptr_t kIntptrSignBit = 0x80000000; |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 171 | const uintptr_t kUintptrAllBitsSet = 0xFFFFFFFFu; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 172 | #if V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_32_BIT |
| 173 | // x32 port also requires code range. |
| 174 | const bool kRequiresCodeRange = true; |
| 175 | const size_t kMaximalCodeRangeSize = 256 * MB; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 176 | const size_t kMinimumCodeRangeSize = 3 * MB; |
| 177 | const size_t kReservedCodeRangePages = 0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 178 | #else |
| 179 | const bool kRequiresCodeRange = false; |
| 180 | const size_t kMaximalCodeRangeSize = 0 * MB; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 181 | const size_t kMinimumCodeRangeSize = 0 * MB; |
| 182 | const size_t kReservedCodeRangePages = 0; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 183 | #endif |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 184 | #endif |
| 185 | |
| 186 | STATIC_ASSERT(kPointerSize == (1 << kPointerSizeLog2)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 187 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 188 | const int kBitsPerByte = 8; |
| 189 | const int kBitsPerByteLog2 = 3; |
| 190 | const int kBitsPerPointer = kPointerSize * kBitsPerByte; |
| 191 | const int kBitsPerInt = kIntSize * kBitsPerByte; |
| 192 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 193 | // IEEE 754 single precision floating point number bit layout. |
| 194 | const uint32_t kBinary32SignMask = 0x80000000u; |
| 195 | const uint32_t kBinary32ExponentMask = 0x7f800000u; |
| 196 | const uint32_t kBinary32MantissaMask = 0x007fffffu; |
| 197 | const int kBinary32ExponentBias = 127; |
| 198 | const int kBinary32MaxExponent = 0xFE; |
| 199 | const int kBinary32MinExponent = 0x01; |
| 200 | const int kBinary32MantissaBits = 23; |
| 201 | const int kBinary32ExponentShift = 23; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 202 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 203 | // Quiet NaNs have bits 51 to 62 set, possibly the sign bit, and no |
| 204 | // other bits set. |
| 205 | const uint64_t kQuietNaNMask = static_cast<uint64_t>(0xfff) << 51; |
| 206 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 207 | // Latin1/UTF-16 constants |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 208 | // Code-point values in Unicode 4.0 are 21 bits wide. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 209 | // Code units in UTF-16 are 16 bits wide. |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 210 | typedef uint16_t uc16; |
| 211 | typedef int32_t uc32; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 212 | const int kOneByteSize = kCharSize; |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 213 | const int kUC16Size = sizeof(uc16); // NOLINT |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 214 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 215 | // 128 bit SIMD value size. |
| 216 | const int kSimd128Size = 16; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 217 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 218 | // Round up n to be a multiple of sz, where sz is a power of 2. |
| 219 | #define ROUND_UP(n, sz) (((n) + ((sz) - 1)) & ~((sz) - 1)) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 220 | |
| 221 | |
| 222 | // FUNCTION_ADDR(f) gets the address of a C function f. |
| 223 | #define FUNCTION_ADDR(f) \ |
| 224 | (reinterpret_cast<v8::internal::Address>(reinterpret_cast<intptr_t>(f))) |
| 225 | |
| 226 | |
| 227 | // FUNCTION_CAST<F>(addr) casts an address into a function |
| 228 | // of type F. Used to invoke generated code from within C. |
| 229 | template <typename F> |
| 230 | F FUNCTION_CAST(Address addr) { |
| 231 | return reinterpret_cast<F>(reinterpret_cast<intptr_t>(addr)); |
| 232 | } |
| 233 | |
| 234 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 235 | // Determine whether the architecture uses function descriptors |
| 236 | // which provide a level of indirection between the function pointer |
| 237 | // and the function entrypoint. |
| 238 | #if V8_HOST_ARCH_PPC && \ |
| 239 | (V8_OS_AIX || (V8_TARGET_ARCH_PPC64 && V8_TARGET_BIG_ENDIAN)) |
| 240 | #define USES_FUNCTION_DESCRIPTORS 1 |
| 241 | #define FUNCTION_ENTRYPOINT_ADDRESS(f) \ |
| 242 | (reinterpret_cast<v8::internal::Address*>( \ |
| 243 | &(reinterpret_cast<intptr_t*>(f)[0]))) |
| 244 | #else |
| 245 | #define USES_FUNCTION_DESCRIPTORS 0 |
| 246 | #endif |
| 247 | |
| 248 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 249 | // ----------------------------------------------------------------------------- |
| 250 | // Forward declarations for frequently used classes |
| 251 | // (sorted alphabetically) |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 252 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 253 | class FreeStoreAllocationPolicy; |
| 254 | template <typename T, class P = FreeStoreAllocationPolicy> class List; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 255 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 256 | // ----------------------------------------------------------------------------- |
| 257 | // Declarations for use in both the preparser and the rest of V8. |
| 258 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 259 | // The Strict Mode (ECMA-262 5th edition, 4.2.2). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 260 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 261 | enum LanguageMode { SLOPPY, STRICT, LANGUAGE_END = 3 }; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 262 | |
| 263 | |
| 264 | inline std::ostream& operator<<(std::ostream& os, const LanguageMode& mode) { |
| 265 | switch (mode) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 266 | case SLOPPY: return os << "sloppy"; |
| 267 | case STRICT: return os << "strict"; |
| 268 | default: UNREACHABLE(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 269 | } |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 270 | return os; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | |
| 274 | inline bool is_sloppy(LanguageMode language_mode) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 275 | return language_mode == SLOPPY; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | |
| 279 | inline bool is_strict(LanguageMode language_mode) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 280 | return language_mode != SLOPPY; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | |
| 284 | inline bool is_valid_language_mode(int language_mode) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 285 | return language_mode == SLOPPY || language_mode == STRICT; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 289 | inline LanguageMode construct_language_mode(bool strict_bit) { |
| 290 | return static_cast<LanguageMode>(strict_bit); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 291 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 292 | |
| 293 | |
| 294 | // Mask for the sign bit in a smi. |
| 295 | const intptr_t kSmiSignMask = kIntptrSignBit; |
| 296 | |
| 297 | const int kObjectAlignmentBits = kPointerSizeLog2; |
| 298 | const intptr_t kObjectAlignment = 1 << kObjectAlignmentBits; |
| 299 | const intptr_t kObjectAlignmentMask = kObjectAlignment - 1; |
| 300 | |
| 301 | // Desired alignment for pointers. |
| 302 | const intptr_t kPointerAlignment = (1 << kPointerSizeLog2); |
| 303 | const intptr_t kPointerAlignmentMask = kPointerAlignment - 1; |
| 304 | |
| 305 | // Desired alignment for double values. |
| 306 | const intptr_t kDoubleAlignment = 8; |
| 307 | const intptr_t kDoubleAlignmentMask = kDoubleAlignment - 1; |
| 308 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 309 | // Desired alignment for 128 bit SIMD values. |
| 310 | const intptr_t kSimd128Alignment = 16; |
| 311 | const intptr_t kSimd128AlignmentMask = kSimd128Alignment - 1; |
| 312 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 313 | // Desired alignment for generated code is 32 bytes (to improve cache line |
| 314 | // utilization). |
| 315 | const int kCodeAlignmentBits = 5; |
| 316 | const intptr_t kCodeAlignment = 1 << kCodeAlignmentBits; |
| 317 | const intptr_t kCodeAlignmentMask = kCodeAlignment - 1; |
| 318 | |
| 319 | // The owner field of a page is tagged with the page header tag. We need that |
| 320 | // to find out if a slot is part of a large object. If we mask out the lower |
| 321 | // 0xfffff bits (1M pages), go to the owner offset, and see that this field |
| 322 | // is tagged with the page header tag, we can just look up the owner. |
| 323 | // Otherwise, we know that we are somewhere (not within the first 1M) in a |
| 324 | // large object. |
| 325 | const int kPageHeaderTag = 3; |
| 326 | const int kPageHeaderTagSize = 2; |
| 327 | const intptr_t kPageHeaderTagMask = (1 << kPageHeaderTagSize) - 1; |
| 328 | |
| 329 | |
| 330 | // Zap-value: The value used for zapping dead objects. |
| 331 | // Should be a recognizable hex value tagged as a failure. |
| 332 | #ifdef V8_HOST_ARCH_64_BIT |
| 333 | const Address kZapValue = |
| 334 | reinterpret_cast<Address>(V8_UINT64_C(0xdeadbeedbeadbeef)); |
| 335 | const Address kHandleZapValue = |
| 336 | reinterpret_cast<Address>(V8_UINT64_C(0x1baddead0baddeaf)); |
| 337 | const Address kGlobalHandleZapValue = |
| 338 | reinterpret_cast<Address>(V8_UINT64_C(0x1baffed00baffedf)); |
| 339 | const Address kFromSpaceZapValue = |
| 340 | reinterpret_cast<Address>(V8_UINT64_C(0x1beefdad0beefdaf)); |
| 341 | const uint64_t kDebugZapValue = V8_UINT64_C(0xbadbaddbbadbaddb); |
| 342 | const uint64_t kSlotsZapValue = V8_UINT64_C(0xbeefdeadbeefdeef); |
| 343 | const uint64_t kFreeListZapValue = 0xfeed1eaffeed1eaf; |
| 344 | #else |
| 345 | const Address kZapValue = reinterpret_cast<Address>(0xdeadbeef); |
| 346 | const Address kHandleZapValue = reinterpret_cast<Address>(0xbaddeaf); |
| 347 | const Address kGlobalHandleZapValue = reinterpret_cast<Address>(0xbaffedf); |
| 348 | const Address kFromSpaceZapValue = reinterpret_cast<Address>(0xbeefdaf); |
| 349 | const uint32_t kSlotsZapValue = 0xbeefdeef; |
| 350 | const uint32_t kDebugZapValue = 0xbadbaddb; |
| 351 | const uint32_t kFreeListZapValue = 0xfeed1eaf; |
| 352 | #endif |
| 353 | |
| 354 | const int kCodeZapValue = 0xbadc0de; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 355 | const uint32_t kPhantomReferenceZap = 0xca11bac; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 356 | |
| 357 | // On Intel architecture, cache line size is 64 bytes. |
| 358 | // On ARM it may be less (32 bytes), but as far this constant is |
| 359 | // used for aligning data, it doesn't hurt to align on a greater value. |
| 360 | #define PROCESSOR_CACHE_LINE_SIZE 64 |
| 361 | |
| 362 | // Constants relevant to double precision floating point numbers. |
| 363 | // If looking only at the top 32 bits, the QNaN mask is bits 19 to 30. |
| 364 | const uint32_t kQuietNaNHighBitsMask = 0xfff << (51 - 32); |
| 365 | |
| 366 | |
| 367 | // ----------------------------------------------------------------------------- |
| 368 | // Forward declarations for frequently used classes |
| 369 | |
| 370 | class AccessorInfo; |
| 371 | class Allocation; |
| 372 | class Arguments; |
| 373 | class Assembler; |
| 374 | class Code; |
| 375 | class CodeGenerator; |
| 376 | class CodeStub; |
| 377 | class Context; |
| 378 | class Debug; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 379 | class DebugInfo; |
| 380 | class Descriptor; |
| 381 | class DescriptorArray; |
| 382 | class TransitionArray; |
| 383 | class ExternalReference; |
| 384 | class FixedArray; |
| 385 | class FunctionTemplateInfo; |
| 386 | class MemoryChunk; |
| 387 | class SeededNumberDictionary; |
| 388 | class UnseededNumberDictionary; |
| 389 | class NameDictionary; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 390 | class GlobalDictionary; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 391 | template <typename T> class MaybeHandle; |
| 392 | template <typename T> class Handle; |
| 393 | class Heap; |
| 394 | class HeapObject; |
| 395 | class IC; |
| 396 | class InterceptorInfo; |
| 397 | class Isolate; |
| 398 | class JSReceiver; |
| 399 | class JSArray; |
| 400 | class JSFunction; |
| 401 | class JSObject; |
| 402 | class LargeObjectSpace; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 403 | class MacroAssembler; |
| 404 | class Map; |
| 405 | class MapSpace; |
| 406 | class MarkCompactCollector; |
| 407 | class NewSpace; |
| 408 | class Object; |
| 409 | class OldSpace; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 410 | class ParameterCount; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 411 | class Foreign; |
| 412 | class Scope; |
| 413 | class ScopeInfo; |
| 414 | class Script; |
| 415 | class Smi; |
| 416 | template <typename Config, class Allocator = FreeStoreAllocationPolicy> |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 417 | class SplayTree; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 418 | class String; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 419 | class Symbol; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 420 | class Name; |
| 421 | class Struct; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 422 | class TypeFeedbackVector; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 423 | class Variable; |
| 424 | class RelocInfo; |
| 425 | class Deserializer; |
| 426 | class MessageLocation; |
| 427 | |
| 428 | typedef bool (*WeakSlotCallback)(Object** pointer); |
| 429 | |
| 430 | typedef bool (*WeakSlotCallbackWithHeap)(Heap* heap, Object** pointer); |
| 431 | |
| 432 | // ----------------------------------------------------------------------------- |
| 433 | // Miscellaneous |
| 434 | |
| 435 | // NOTE: SpaceIterator depends on AllocationSpace enumeration values being |
| 436 | // consecutive. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 437 | // Keep this enum in sync with the ObjectSpace enum in v8.h |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 438 | enum AllocationSpace { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 439 | NEW_SPACE, // Semispaces collected with copying collector. |
| 440 | OLD_SPACE, // May contain pointers to new space. |
| 441 | CODE_SPACE, // No pointers to new space, marked executable. |
| 442 | MAP_SPACE, // Only and all map objects. |
| 443 | LO_SPACE, // Promoted large objects. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 444 | |
| 445 | FIRST_SPACE = NEW_SPACE, |
| 446 | LAST_SPACE = LO_SPACE, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 447 | FIRST_PAGED_SPACE = OLD_SPACE, |
| 448 | LAST_PAGED_SPACE = MAP_SPACE |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 449 | }; |
| 450 | const int kSpaceTagSize = 3; |
| 451 | const int kSpaceTagMask = (1 << kSpaceTagSize) - 1; |
| 452 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 453 | enum AllocationAlignment { |
| 454 | kWordAligned, |
| 455 | kDoubleAligned, |
| 456 | kDoubleUnaligned, |
| 457 | kSimd128Unaligned |
| 458 | }; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 459 | |
| 460 | // A flag that indicates whether objects should be pretenured when |
| 461 | // allocated (allocated directly into the old generation) or not |
| 462 | // (allocated in the young generation if the object size and type |
| 463 | // allows). |
| 464 | enum PretenureFlag { NOT_TENURED, TENURED }; |
| 465 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 466 | inline std::ostream& operator<<(std::ostream& os, const PretenureFlag& flag) { |
| 467 | switch (flag) { |
| 468 | case NOT_TENURED: |
| 469 | return os << "NotTenured"; |
| 470 | case TENURED: |
| 471 | return os << "Tenured"; |
| 472 | } |
| 473 | UNREACHABLE(); |
| 474 | return os; |
| 475 | } |
| 476 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 477 | enum MinimumCapacity { |
| 478 | USE_DEFAULT_MINIMUM_CAPACITY, |
| 479 | USE_CUSTOM_MINIMUM_CAPACITY |
| 480 | }; |
| 481 | |
| 482 | enum GarbageCollector { SCAVENGER, MARK_COMPACTOR }; |
| 483 | |
| 484 | enum Executability { NOT_EXECUTABLE, EXECUTABLE }; |
| 485 | |
| 486 | enum VisitMode { |
| 487 | VISIT_ALL, |
| 488 | VISIT_ALL_IN_SCAVENGE, |
| 489 | VISIT_ALL_IN_SWEEP_NEWSPACE, |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 490 | VISIT_ONLY_STRONG, |
| 491 | VISIT_ONLY_STRONG_FOR_SERIALIZATION, |
| 492 | VISIT_ONLY_STRONG_ROOT_LIST, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 493 | }; |
| 494 | |
| 495 | // Flag indicating whether code is built into the VM (one of the natives files). |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 496 | enum NativesFlag { NOT_NATIVES_CODE, EXTENSION_CODE, NATIVES_CODE }; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 497 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 498 | // JavaScript defines two kinds of 'nil'. |
| 499 | enum NilValue { kNullValue, kUndefinedValue }; |
| 500 | |
| 501 | // ParseRestriction is used to restrict the set of valid statements in a |
| 502 | // unit of compilation. Restriction violations cause a syntax error. |
| 503 | enum ParseRestriction { |
| 504 | NO_PARSE_RESTRICTION, // All expressions are allowed. |
| 505 | ONLY_SINGLE_FUNCTION_LITERAL // Only a single FunctionLiteral expression. |
| 506 | }; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 507 | |
| 508 | // A CodeDesc describes a buffer holding instructions and relocation |
| 509 | // information. The instructions start at the beginning of the buffer |
| 510 | // and grow forward, the relocation information starts at the end of |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 511 | // the buffer and grows backward. A constant pool may exist at the |
| 512 | // end of the instructions. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 513 | // |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 514 | // |<--------------- buffer_size ----------------------------------->| |
| 515 | // |<------------- instr_size ---------->| |<-- reloc_size -->| |
| 516 | // | |<- const_pool_size ->| | |
| 517 | // +=====================================+========+==================+ |
| 518 | // | instructions | data | free | reloc info | |
| 519 | // +=====================================+========+==================+ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 520 | // ^ |
| 521 | // | |
| 522 | // buffer |
| 523 | |
| 524 | struct CodeDesc { |
| 525 | byte* buffer; |
| 526 | int buffer_size; |
| 527 | int instr_size; |
| 528 | int reloc_size; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 529 | int constant_pool_size; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 530 | Assembler* origin; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 531 | }; |
| 532 | |
| 533 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 534 | // Callback function used for checking constraints when copying/relocating |
| 535 | // objects. Returns true if an object can be copied/relocated from its |
| 536 | // old_addr to a new_addr. |
| 537 | typedef bool (*ConstraintCallback)(Address new_addr, Address old_addr); |
| 538 | |
| 539 | |
| 540 | // Callback function on inline caches, used for iterating over inline caches |
| 541 | // in compiled code. |
| 542 | typedef void (*InlineCacheCallback)(Code* code, Address ic); |
| 543 | |
| 544 | |
| 545 | // State for inline cache call sites. Aliased as IC::State. |
| 546 | enum InlineCacheState { |
| 547 | // Has never been executed. |
| 548 | UNINITIALIZED, |
| 549 | // Has been executed but monomorhic state has been delayed. |
| 550 | PREMONOMORPHIC, |
| 551 | // Has been executed and only one receiver type has been seen. |
| 552 | MONOMORPHIC, |
| 553 | // Check failed due to prototype (or map deprecation). |
| 554 | PROTOTYPE_FAILURE, |
| 555 | // Multiple receiver types have been seen. |
| 556 | POLYMORPHIC, |
| 557 | // Many receiver types have been seen. |
| 558 | MEGAMORPHIC, |
| 559 | // A generic handler is installed and no extra typefeedback is recorded. |
| 560 | GENERIC, |
| 561 | // Special state for debug break or step in prepare stubs. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 562 | DEBUG_STUB |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 563 | }; |
| 564 | |
| 565 | |
| 566 | enum CacheHolderFlag { |
| 567 | kCacheOnPrototype, |
| 568 | kCacheOnPrototypeReceiverIsDictionary, |
| 569 | kCacheOnPrototypeReceiverIsPrimitive, |
| 570 | kCacheOnReceiver |
| 571 | }; |
| 572 | |
| 573 | |
| 574 | // The Store Buffer (GC). |
| 575 | typedef enum { |
| 576 | kStoreBufferFullEvent, |
| 577 | kStoreBufferStartScanningPagesEvent, |
| 578 | kStoreBufferScanningPageEvent |
| 579 | } StoreBufferEvent; |
| 580 | |
| 581 | |
| 582 | typedef void (*StoreBufferCallback)(Heap* heap, |
| 583 | MemoryChunk* page, |
| 584 | StoreBufferEvent event); |
| 585 | |
| 586 | |
| 587 | // Union used for fast testing of specific double values. |
| 588 | union DoubleRepresentation { |
| 589 | double value; |
| 590 | int64_t bits; |
| 591 | DoubleRepresentation(double x) { value = x; } |
| 592 | bool operator==(const DoubleRepresentation& other) const { |
| 593 | return bits == other.bits; |
| 594 | } |
| 595 | }; |
| 596 | |
| 597 | |
| 598 | // Union used for customized checking of the IEEE double types |
| 599 | // inlined within v8 runtime, rather than going to the underlying |
| 600 | // platform headers and libraries |
| 601 | union IeeeDoubleLittleEndianArchType { |
| 602 | double d; |
| 603 | struct { |
| 604 | unsigned int man_low :32; |
| 605 | unsigned int man_high :20; |
| 606 | unsigned int exp :11; |
| 607 | unsigned int sign :1; |
| 608 | } bits; |
| 609 | }; |
| 610 | |
| 611 | |
| 612 | union IeeeDoubleBigEndianArchType { |
| 613 | double d; |
| 614 | struct { |
| 615 | unsigned int sign :1; |
| 616 | unsigned int exp :11; |
| 617 | unsigned int man_high :20; |
| 618 | unsigned int man_low :32; |
| 619 | } bits; |
| 620 | }; |
| 621 | |
| 622 | |
| 623 | // AccessorCallback |
| 624 | struct AccessorDescriptor { |
| 625 | Object* (*getter)(Isolate* isolate, Object* object, void* data); |
| 626 | Object* (*setter)( |
| 627 | Isolate* isolate, JSObject* object, Object* value, void* data); |
| 628 | void* data; |
| 629 | }; |
| 630 | |
| 631 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 632 | // ----------------------------------------------------------------------------- |
| 633 | // Macros |
| 634 | |
| 635 | // Testers for test. |
| 636 | |
| 637 | #define HAS_SMI_TAG(value) \ |
| 638 | ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag) |
| 639 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 640 | // OBJECT_POINTER_ALIGN returns the value aligned as a HeapObject pointer |
| 641 | #define OBJECT_POINTER_ALIGN(value) \ |
| 642 | (((value) + kObjectAlignmentMask) & ~kObjectAlignmentMask) |
| 643 | |
| 644 | // POINTER_SIZE_ALIGN returns the value aligned as a pointer. |
| 645 | #define POINTER_SIZE_ALIGN(value) \ |
| 646 | (((value) + kPointerAlignmentMask) & ~kPointerAlignmentMask) |
| 647 | |
| 648 | // CODE_POINTER_ALIGN returns the value aligned as a generated code segment. |
| 649 | #define CODE_POINTER_ALIGN(value) \ |
| 650 | (((value) + kCodeAlignmentMask) & ~kCodeAlignmentMask) |
| 651 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 652 | // DOUBLE_POINTER_ALIGN returns the value algined for double pointers. |
| 653 | #define DOUBLE_POINTER_ALIGN(value) \ |
| 654 | (((value) + kDoubleAlignmentMask) & ~kDoubleAlignmentMask) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 655 | |
| 656 | |
| 657 | // CPU feature flags. |
| 658 | enum CpuFeature { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 659 | // x86 |
| 660 | SSE4_1, |
| 661 | SSE3, |
| 662 | SAHF, |
| 663 | AVX, |
| 664 | FMA3, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 665 | BMI1, |
| 666 | BMI2, |
| 667 | LZCNT, |
| 668 | POPCNT, |
| 669 | ATOM, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 670 | // ARM |
| 671 | VFP3, |
| 672 | ARMv7, |
| 673 | ARMv8, |
| 674 | SUDIV, |
| 675 | MLS, |
| 676 | UNALIGNED_ACCESSES, |
| 677 | MOVW_MOVT_IMMEDIATE_LOADS, |
| 678 | VFP32DREGS, |
| 679 | NEON, |
| 680 | // MIPS, MIPS64 |
| 681 | FPU, |
| 682 | FP64FPU, |
| 683 | MIPSr1, |
| 684 | MIPSr2, |
| 685 | MIPSr6, |
| 686 | // ARM64 |
| 687 | ALWAYS_ALIGN_CSP, |
| 688 | COHERENT_CACHE, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 689 | // PPC |
| 690 | FPR_GPR_MOV, |
| 691 | LWSYNC, |
| 692 | ISELECT, |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 693 | // S390 |
| 694 | DISTINCT_OPS, |
| 695 | GENERAL_INSTR_EXT, |
| 696 | FLOATING_POINT_EXT, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 697 | NUMBER_OF_CPU_FEATURES |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 698 | }; |
| 699 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 700 | // Defines hints about receiver values based on structural knowledge. |
| 701 | enum class ConvertReceiverMode : unsigned { |
| 702 | kNullOrUndefined, // Guaranteed to be null or undefined. |
| 703 | kNotNullOrUndefined, // Guaranteed to never be null or undefined. |
| 704 | kAny // No specific knowledge about receiver. |
| 705 | }; |
| 706 | |
| 707 | inline size_t hash_value(ConvertReceiverMode mode) { |
| 708 | return bit_cast<unsigned>(mode); |
| 709 | } |
| 710 | |
| 711 | inline std::ostream& operator<<(std::ostream& os, ConvertReceiverMode mode) { |
| 712 | switch (mode) { |
| 713 | case ConvertReceiverMode::kNullOrUndefined: |
| 714 | return os << "NULL_OR_UNDEFINED"; |
| 715 | case ConvertReceiverMode::kNotNullOrUndefined: |
| 716 | return os << "NOT_NULL_OR_UNDEFINED"; |
| 717 | case ConvertReceiverMode::kAny: |
| 718 | return os << "ANY"; |
| 719 | } |
| 720 | UNREACHABLE(); |
| 721 | return os; |
| 722 | } |
| 723 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 724 | // Defines whether tail call optimization is allowed. |
| 725 | enum class TailCallMode : unsigned { kAllow, kDisallow }; |
| 726 | |
| 727 | inline size_t hash_value(TailCallMode mode) { return bit_cast<unsigned>(mode); } |
| 728 | |
| 729 | inline std::ostream& operator<<(std::ostream& os, TailCallMode mode) { |
| 730 | switch (mode) { |
| 731 | case TailCallMode::kAllow: |
| 732 | return os << "ALLOW_TAIL_CALLS"; |
| 733 | case TailCallMode::kDisallow: |
| 734 | return os << "DISALLOW_TAIL_CALLS"; |
| 735 | } |
| 736 | UNREACHABLE(); |
| 737 | return os; |
| 738 | } |
| 739 | |
| 740 | // Defines specifics about arguments object or rest parameter creation. |
| 741 | enum class CreateArgumentsType : uint8_t { |
| 742 | kMappedArguments, |
| 743 | kUnmappedArguments, |
| 744 | kRestParameter |
| 745 | }; |
| 746 | |
| 747 | inline size_t hash_value(CreateArgumentsType type) { |
| 748 | return bit_cast<uint8_t>(type); |
| 749 | } |
| 750 | |
| 751 | inline std::ostream& operator<<(std::ostream& os, CreateArgumentsType type) { |
| 752 | switch (type) { |
| 753 | case CreateArgumentsType::kMappedArguments: |
| 754 | return os << "MAPPED_ARGUMENTS"; |
| 755 | case CreateArgumentsType::kUnmappedArguments: |
| 756 | return os << "UNMAPPED_ARGUMENTS"; |
| 757 | case CreateArgumentsType::kRestParameter: |
| 758 | return os << "REST_PARAMETER"; |
| 759 | } |
| 760 | UNREACHABLE(); |
| 761 | return os; |
| 762 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 763 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 764 | // Used to specify if a macro instruction must perform a smi check on tagged |
| 765 | // values. |
| 766 | enum SmiCheckType { |
| 767 | DONT_DO_SMI_CHECK, |
| 768 | DO_SMI_CHECK |
| 769 | }; |
| 770 | |
| 771 | |
| 772 | enum ScopeType { |
| 773 | EVAL_SCOPE, // The top-level scope for an eval source. |
| 774 | FUNCTION_SCOPE, // The top-level scope for a function. |
| 775 | MODULE_SCOPE, // The scope introduced by a module literal |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 776 | SCRIPT_SCOPE, // The top-level scope for a script or a top-level eval. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 777 | CATCH_SCOPE, // The scope introduced by catch. |
| 778 | BLOCK_SCOPE, // The scope introduced by a new block. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 779 | WITH_SCOPE // The scope introduced by with. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 780 | }; |
| 781 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 782 | // The mips architecture prior to revision 5 has inverted encoding for sNaN. |
| 783 | #if (V8_TARGET_ARCH_MIPS && !defined(_MIPS_ARCH_MIPS32R6)) || \ |
| 784 | (V8_TARGET_ARCH_MIPS64 && !defined(_MIPS_ARCH_MIPS64R6)) |
| 785 | const uint32_t kHoleNanUpper32 = 0xFFFF7FFF; |
| 786 | const uint32_t kHoleNanLower32 = 0xFFFF7FFF; |
| 787 | #else |
| 788 | const uint32_t kHoleNanUpper32 = 0xFFF7FFFF; |
| 789 | const uint32_t kHoleNanLower32 = 0xFFF7FFFF; |
| 790 | #endif |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 791 | |
| 792 | const uint64_t kHoleNanInt64 = |
| 793 | (static_cast<uint64_t>(kHoleNanUpper32) << 32) | kHoleNanLower32; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 794 | |
| 795 | |
| 796 | // ES6 section 20.1.2.6 Number.MAX_SAFE_INTEGER |
| 797 | const double kMaxSafeInteger = 9007199254740991.0; // 2^53-1 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 798 | |
| 799 | |
| 800 | // The order of this enum has to be kept in sync with the predicates below. |
| 801 | enum VariableMode { |
| 802 | // User declared variables: |
| 803 | VAR, // declared via 'var', and 'function' declarations |
| 804 | |
| 805 | CONST_LEGACY, // declared via legacy 'const' declarations |
| 806 | |
| 807 | LET, // declared via 'let' declarations (first lexical) |
| 808 | |
| 809 | CONST, // declared via 'const' declarations |
| 810 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 811 | IMPORT, // declared via 'import' declarations (last lexical) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 812 | |
| 813 | // Variables introduced by the compiler: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 814 | TEMPORARY, // temporary variables (not user-visible), stack-allocated |
| 815 | // unless the scope as a whole has forced context allocation |
| 816 | |
| 817 | DYNAMIC, // always require dynamic lookup (we don't know |
| 818 | // the declaration) |
| 819 | |
| 820 | DYNAMIC_GLOBAL, // requires dynamic lookup, but we know that the |
| 821 | // variable is global unless it has been shadowed |
| 822 | // by an eval-introduced variable |
| 823 | |
| 824 | DYNAMIC_LOCAL // requires dynamic lookup, but we know that the |
| 825 | // variable is local and where it is unless it |
| 826 | // has been shadowed by an eval-introduced |
| 827 | // variable |
| 828 | }; |
| 829 | |
| 830 | |
| 831 | inline bool IsDynamicVariableMode(VariableMode mode) { |
| 832 | return mode >= DYNAMIC && mode <= DYNAMIC_LOCAL; |
| 833 | } |
| 834 | |
| 835 | |
| 836 | inline bool IsDeclaredVariableMode(VariableMode mode) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 837 | return mode >= VAR && mode <= IMPORT; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | |
| 841 | inline bool IsLexicalVariableMode(VariableMode mode) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 842 | return mode >= LET && mode <= IMPORT; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | |
| 846 | inline bool IsImmutableVariableMode(VariableMode mode) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 847 | return mode == CONST || mode == CONST_LEGACY || mode == IMPORT; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 851 | enum class VariableLocation { |
| 852 | // Before and during variable allocation, a variable whose location is |
| 853 | // not yet determined. After allocation, a variable looked up as a |
| 854 | // property on the global object (and possibly absent). name() is the |
| 855 | // variable name, index() is invalid. |
| 856 | UNALLOCATED, |
| 857 | |
| 858 | // A slot in the parameter section on the stack. index() is the |
| 859 | // parameter index, counting left-to-right. The receiver is index -1; |
| 860 | // the first parameter is index 0. |
| 861 | PARAMETER, |
| 862 | |
| 863 | // A slot in the local section on the stack. index() is the variable |
| 864 | // index in the stack frame, starting at 0. |
| 865 | LOCAL, |
| 866 | |
| 867 | // An indexed slot in a heap context. index() is the variable index in |
| 868 | // the context object on the heap, starting at 0. scope() is the |
| 869 | // corresponding scope. |
| 870 | CONTEXT, |
| 871 | |
| 872 | // An indexed slot in a script context that contains a respective global |
| 873 | // property cell. name() is the variable name, index() is the variable |
| 874 | // index in the context object on the heap, starting at 0. scope() is the |
| 875 | // corresponding script scope. |
| 876 | GLOBAL, |
| 877 | |
| 878 | // A named slot in a heap context. name() is the variable name in the |
| 879 | // context object on the heap, with lookup starting at the current |
| 880 | // context. index() is invalid. |
| 881 | LOOKUP |
| 882 | }; |
| 883 | |
| 884 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 885 | // ES6 Draft Rev3 10.2 specifies declarative environment records with mutable |
| 886 | // and immutable bindings that can be in two states: initialized and |
| 887 | // uninitialized. In ES5 only immutable bindings have these two states. When |
| 888 | // accessing a binding, it needs to be checked for initialization. However in |
| 889 | // the following cases the binding is initialized immediately after creation |
| 890 | // so the initialization check can always be skipped: |
| 891 | // 1. Var declared local variables. |
| 892 | // var foo; |
| 893 | // 2. A local variable introduced by a function declaration. |
| 894 | // function foo() {} |
| 895 | // 3. Parameters |
| 896 | // function x(foo) {} |
| 897 | // 4. Catch bound variables. |
| 898 | // try {} catch (foo) {} |
| 899 | // 6. Function variables of named function expressions. |
| 900 | // var x = function foo() {} |
| 901 | // 7. Implicit binding of 'this'. |
| 902 | // 8. Implicit binding of 'arguments' in functions. |
| 903 | // |
| 904 | // ES5 specified object environment records which are introduced by ES elements |
| 905 | // such as Program and WithStatement that associate identifier bindings with the |
| 906 | // properties of some object. In the specification only mutable bindings exist |
| 907 | // (which may be non-writable) and have no distinct initialization step. However |
| 908 | // V8 allows const declarations in global code with distinct creation and |
| 909 | // initialization steps which are represented by non-writable properties in the |
| 910 | // global object. As a result also these bindings need to be checked for |
| 911 | // initialization. |
| 912 | // |
| 913 | // The following enum specifies a flag that indicates if the binding needs a |
| 914 | // distinct initialization step (kNeedsInitialization) or if the binding is |
| 915 | // immediately initialized upon creation (kCreatedInitialized). |
| 916 | enum InitializationFlag { |
| 917 | kNeedsInitialization, |
| 918 | kCreatedInitialized |
| 919 | }; |
| 920 | |
| 921 | |
| 922 | enum MaybeAssignedFlag { kNotAssigned, kMaybeAssigned }; |
| 923 | |
| 924 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 925 | // Serialized in PreparseData, so numeric values should not be changed. |
| 926 | enum ParseErrorType { kSyntaxError = 0, kReferenceError = 1 }; |
| 927 | |
| 928 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 929 | enum MinusZeroMode { |
| 930 | TREAT_MINUS_ZERO_AS_ZERO, |
| 931 | FAIL_ON_MINUS_ZERO |
| 932 | }; |
| 933 | |
| 934 | |
| 935 | enum Signedness { kSigned, kUnsigned }; |
| 936 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 937 | enum FunctionKind { |
| 938 | kNormalFunction = 0, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 939 | kArrowFunction = 1 << 0, |
| 940 | kGeneratorFunction = 1 << 1, |
| 941 | kConciseMethod = 1 << 2, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 942 | kConciseGeneratorMethod = kGeneratorFunction | kConciseMethod, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 943 | kDefaultConstructor = 1 << 3, |
| 944 | kSubclassConstructor = 1 << 4, |
| 945 | kBaseConstructor = 1 << 5, |
| 946 | kGetterFunction = 1 << 6, |
| 947 | kSetterFunction = 1 << 7, |
| 948 | kAccessorFunction = kGetterFunction | kSetterFunction, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 949 | kDefaultBaseConstructor = kDefaultConstructor | kBaseConstructor, |
| 950 | kDefaultSubclassConstructor = kDefaultConstructor | kSubclassConstructor, |
| 951 | kClassConstructor = |
| 952 | kBaseConstructor | kSubclassConstructor | kDefaultConstructor, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 953 | }; |
| 954 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 955 | inline bool IsValidFunctionKind(FunctionKind kind) { |
| 956 | return kind == FunctionKind::kNormalFunction || |
| 957 | kind == FunctionKind::kArrowFunction || |
| 958 | kind == FunctionKind::kGeneratorFunction || |
| 959 | kind == FunctionKind::kConciseMethod || |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 960 | kind == FunctionKind::kConciseGeneratorMethod || |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 961 | kind == FunctionKind::kGetterFunction || |
| 962 | kind == FunctionKind::kSetterFunction || |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 963 | kind == FunctionKind::kAccessorFunction || |
| 964 | kind == FunctionKind::kDefaultBaseConstructor || |
| 965 | kind == FunctionKind::kDefaultSubclassConstructor || |
| 966 | kind == FunctionKind::kBaseConstructor || |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 967 | kind == FunctionKind::kSubclassConstructor; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | |
| 971 | inline bool IsArrowFunction(FunctionKind kind) { |
| 972 | DCHECK(IsValidFunctionKind(kind)); |
| 973 | return kind & FunctionKind::kArrowFunction; |
| 974 | } |
| 975 | |
| 976 | |
| 977 | inline bool IsGeneratorFunction(FunctionKind kind) { |
| 978 | DCHECK(IsValidFunctionKind(kind)); |
| 979 | return kind & FunctionKind::kGeneratorFunction; |
| 980 | } |
| 981 | |
| 982 | |
| 983 | inline bool IsConciseMethod(FunctionKind kind) { |
| 984 | DCHECK(IsValidFunctionKind(kind)); |
| 985 | return kind & FunctionKind::kConciseMethod; |
| 986 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 987 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 988 | inline bool IsGetterFunction(FunctionKind kind) { |
| 989 | DCHECK(IsValidFunctionKind(kind)); |
| 990 | return kind & FunctionKind::kGetterFunction; |
| 991 | } |
| 992 | |
| 993 | inline bool IsSetterFunction(FunctionKind kind) { |
| 994 | DCHECK(IsValidFunctionKind(kind)); |
| 995 | return kind & FunctionKind::kSetterFunction; |
| 996 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 997 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 998 | inline bool IsAccessorFunction(FunctionKind kind) { |
| 999 | DCHECK(IsValidFunctionKind(kind)); |
| 1000 | return kind & FunctionKind::kAccessorFunction; |
| 1001 | } |
| 1002 | |
| 1003 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1004 | inline bool IsDefaultConstructor(FunctionKind kind) { |
| 1005 | DCHECK(IsValidFunctionKind(kind)); |
| 1006 | return kind & FunctionKind::kDefaultConstructor; |
| 1007 | } |
| 1008 | |
| 1009 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1010 | inline bool IsBaseConstructor(FunctionKind kind) { |
| 1011 | DCHECK(IsValidFunctionKind(kind)); |
| 1012 | return kind & FunctionKind::kBaseConstructor; |
| 1013 | } |
| 1014 | |
| 1015 | |
| 1016 | inline bool IsSubclassConstructor(FunctionKind kind) { |
| 1017 | DCHECK(IsValidFunctionKind(kind)); |
| 1018 | return kind & FunctionKind::kSubclassConstructor; |
| 1019 | } |
| 1020 | |
| 1021 | |
| 1022 | inline bool IsClassConstructor(FunctionKind kind) { |
| 1023 | DCHECK(IsValidFunctionKind(kind)); |
| 1024 | return kind & FunctionKind::kClassConstructor; |
| 1025 | } |
| 1026 | |
| 1027 | |
| 1028 | inline bool IsConstructable(FunctionKind kind, LanguageMode mode) { |
| 1029 | if (IsAccessorFunction(kind)) return false; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1030 | if (IsConciseMethod(kind)) return false; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1031 | if (IsArrowFunction(kind)) return false; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1032 | if (IsGeneratorFunction(kind)) return false; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1033 | return true; |
| 1034 | } |
| 1035 | |
| 1036 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1037 | inline uint32_t ObjectHash(Address address) { |
| 1038 | // All objects are at least pointer aligned, so we can remove the trailing |
| 1039 | // zeros. |
| 1040 | return static_cast<uint32_t>(bit_cast<uintptr_t>(address) >> |
| 1041 | kPointerSizeLog2); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1042 | } |
| 1043 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1044 | } // namespace internal |
| 1045 | } // namespace v8 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1046 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1047 | namespace i = v8::internal; |
| 1048 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1049 | #endif // V8_GLOBALS_H_ |