Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1 | // Copyright 2006-2009 the V8 project authors. All rights reserved. |
| 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #ifndef V8_GLOBALS_H_ |
| 29 | #define V8_GLOBALS_H_ |
| 30 | |
| 31 | namespace v8 { |
| 32 | namespace internal { |
| 33 | |
| 34 | // Processor architecture detection. For more info on what's defined, see: |
| 35 | // http://msdn.microsoft.com/en-us/library/b0084kay.aspx |
| 36 | // http://www.agner.org/optimize/calling_conventions.pdf |
| 37 | // or with gcc, run: "echo | gcc -E -dM -" |
| 38 | #if defined(_M_X64) || defined(__x86_64__) |
| 39 | #define V8_HOST_ARCH_X64 1 |
| 40 | #define V8_HOST_ARCH_64_BIT 1 |
| 41 | #define V8_HOST_CAN_READ_UNALIGNED 1 |
| 42 | #elif defined(_M_IX86) || defined(__i386__) |
| 43 | #define V8_HOST_ARCH_IA32 1 |
| 44 | #define V8_HOST_ARCH_32_BIT 1 |
| 45 | #define V8_HOST_CAN_READ_UNALIGNED 1 |
| 46 | #elif defined(__ARMEL__) |
| 47 | #define V8_HOST_ARCH_ARM 1 |
| 48 | #define V8_HOST_ARCH_32_BIT 1 |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 49 | // Some CPU-OS combinations allow unaligned access on ARM. We assume |
| 50 | // that unaligned accesses are not allowed unless the build system |
| 51 | // defines the CAN_USE_UNALIGNED_ACCESSES macro to be non-zero. |
| 52 | #if CAN_USE_UNALIGNED_ACCESSES |
| 53 | #define V8_HOST_CAN_READ_UNALIGNED 1 |
| 54 | #endif |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 55 | #elif defined(_MIPS_ARCH_MIPS32R2) |
| 56 | #define V8_HOST_ARCH_MIPS 1 |
| 57 | #define V8_HOST_ARCH_32_BIT 1 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 58 | #else |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 59 | #error Host architecture was not detected as supported by v8 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 60 | #endif |
| 61 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 62 | // Target architecture detection. This may be set externally. If not, detect |
| 63 | // in the same way as the host architecture, that is, target the native |
| 64 | // environment as presented by the compiler. |
| 65 | #if !defined(V8_TARGET_ARCH_X64) && !defined(V8_TARGET_ARCH_IA32) && \ |
| 66 | !defined(V8_TARGET_ARCH_ARM) && !defined(V8_TARGET_ARCH_MIPS) |
| 67 | #if defined(_M_X64) || defined(__x86_64__) |
| 68 | #define V8_TARGET_ARCH_X64 1 |
| 69 | #elif defined(_M_IX86) || defined(__i386__) |
| 70 | #define V8_TARGET_ARCH_IA32 1 |
| 71 | #elif defined(__ARMEL__) |
| 72 | #define V8_TARGET_ARCH_ARM 1 |
| 73 | #elif defined(_MIPS_ARCH_MIPS32R2) |
| 74 | #define V8_TARGET_ARCH_MIPS 1 |
| 75 | #else |
| 76 | #error Target architecture was not detected as supported by v8 |
| 77 | #endif |
| 78 | #endif |
| 79 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 80 | // Check for supported combinations of host and target architectures. |
| 81 | #if defined(V8_TARGET_ARCH_IA32) && !defined(V8_HOST_ARCH_IA32) |
| 82 | #error Target architecture ia32 is only supported on ia32 host |
| 83 | #endif |
| 84 | #if defined(V8_TARGET_ARCH_X64) && !defined(V8_HOST_ARCH_X64) |
| 85 | #error Target architecture x64 is only supported on x64 host |
| 86 | #endif |
| 87 | #if (defined(V8_TARGET_ARCH_ARM) && \ |
| 88 | !(defined(V8_HOST_ARCH_IA32) || defined(V8_HOST_ARCH_ARM))) |
| 89 | #error Target architecture arm is only supported on arm and ia32 host |
| 90 | #endif |
| 91 | #if (defined(V8_TARGET_ARCH_MIPS) && \ |
| 92 | !(defined(V8_HOST_ARCH_IA32) || defined(V8_HOST_ARCH_MIPS))) |
| 93 | #error Target architecture mips is only supported on mips and ia32 host |
| 94 | #endif |
| 95 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame^] | 96 | // Determine whether we are running in a simulated environment. |
| 97 | // Setting USE_SIMULATOR explicitly from the build script will force |
| 98 | // the use of a simulated environment. |
| 99 | #if !defined(USE_SIMULATOR) |
| 100 | #if (defined(V8_TARGET_ARCH_ARM) && !defined(V8_HOST_ARCH_ARM)) |
| 101 | #define USE_SIMULATOR 1 |
| 102 | #endif |
| 103 | #if (defined(V8_TARGET_ARCH_MIPS) && !defined(V8_HOST_ARCH_MIPS)) |
| 104 | #define USE_SIMULATOR 1 |
| 105 | #endif |
| 106 | #endif |
| 107 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 108 | // Define unaligned read for the target architectures supporting it. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 109 | #if defined(V8_TARGET_ARCH_X64) || defined(V8_TARGET_ARCH_IA32) |
| 110 | #define V8_TARGET_CAN_READ_UNALIGNED 1 |
| 111 | #elif V8_TARGET_ARCH_ARM |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 112 | // Some CPU-OS combinations allow unaligned access on ARM. We assume |
| 113 | // that unaligned accesses are not allowed unless the build system |
| 114 | // defines the CAN_USE_UNALIGNED_ACCESSES macro to be non-zero. |
| 115 | #if CAN_USE_UNALIGNED_ACCESSES |
| 116 | #define V8_TARGET_CAN_READ_UNALIGNED 1 |
| 117 | #endif |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 118 | #elif V8_TARGET_ARCH_MIPS |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 119 | #else |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 120 | #error Target architecture is not supported by v8 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 121 | #endif |
| 122 | |
| 123 | // Support for alternative bool type. This is only enabled if the code is |
| 124 | // compiled with USE_MYBOOL defined. This catches some nasty type bugs. |
| 125 | // For instance, 'bool b = "false";' results in b == true! This is a hidden |
| 126 | // source of bugs. |
| 127 | // However, redefining the bool type does have some negative impact on some |
| 128 | // platforms. It gives rise to compiler warnings (i.e. with |
| 129 | // MSVC) in the API header files when mixing code that uses the standard |
| 130 | // bool with code that uses the redefined version. |
| 131 | // This does not actually belong in the platform code, but needs to be |
| 132 | // defined here because the platform code uses bool, and platform.h is |
| 133 | // include very early in the main include file. |
| 134 | |
| 135 | #ifdef USE_MYBOOL |
| 136 | typedef unsigned int __my_bool__; |
| 137 | #define bool __my_bool__ // use 'indirection' to avoid name clashes |
| 138 | #endif |
| 139 | |
| 140 | typedef uint8_t byte; |
| 141 | typedef byte* Address; |
| 142 | |
| 143 | // Define our own macros for writing 64-bit constants. This is less fragile |
| 144 | // than defining __STDC_CONSTANT_MACROS before including <stdint.h>, and it |
| 145 | // works on compilers that don't have it (like MSVC). |
| 146 | #if V8_HOST_ARCH_64_BIT |
| 147 | #ifdef _MSC_VER |
| 148 | #define V8_UINT64_C(x) (x ## UI64) |
| 149 | #define V8_INT64_C(x) (x ## I64) |
| 150 | #define V8_PTR_PREFIX "ll" |
| 151 | #else // _MSC_VER |
| 152 | #define V8_UINT64_C(x) (x ## UL) |
| 153 | #define V8_INT64_C(x) (x ## L) |
| 154 | #define V8_PTR_PREFIX "l" |
| 155 | #endif // _MSC_VER |
| 156 | #else // V8_HOST_ARCH_64_BIT |
| 157 | #define V8_PTR_PREFIX "" |
| 158 | #endif // V8_HOST_ARCH_64_BIT |
| 159 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 160 | // The following macro works on both 32 and 64-bit platforms. |
| 161 | // Usage: instead of writing 0x1234567890123456 |
| 162 | // write V8_2PART_UINT64_C(0x12345678,90123456); |
| 163 | #define V8_2PART_UINT64_C(a, b) (((static_cast<uint64_t>(a) << 32) + 0x##b##u)) |
| 164 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 165 | #define V8PRIxPTR V8_PTR_PREFIX "x" |
| 166 | #define V8PRIdPTR V8_PTR_PREFIX "d" |
| 167 | |
| 168 | // Fix for Mac OS X defining uintptr_t as "unsigned long": |
| 169 | #if defined(__APPLE__) && defined(__MACH__) |
| 170 | #undef V8PRIxPTR |
| 171 | #define V8PRIxPTR "lx" |
| 172 | #endif |
| 173 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 174 | #if (defined(__APPLE__) && defined(__MACH__)) || \ |
| 175 | defined(__FreeBSD__) || defined(__OpenBSD__) |
| 176 | #define USING_BSD_ABI |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 177 | #endif |
| 178 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 179 | // Code-point values in Unicode 4.0 are 21 bits wide. |
| 180 | typedef uint16_t uc16; |
| 181 | typedef int32_t uc32; |
| 182 | |
| 183 | // ----------------------------------------------------------------------------- |
| 184 | // Constants |
| 185 | |
| 186 | const int KB = 1024; |
| 187 | const int MB = KB * KB; |
| 188 | const int GB = KB * KB * KB; |
| 189 | const int kMaxInt = 0x7FFFFFFF; |
| 190 | const int kMinInt = -kMaxInt - 1; |
| 191 | |
| 192 | const uint32_t kMaxUInt32 = 0xFFFFFFFFu; |
| 193 | |
| 194 | const int kCharSize = sizeof(char); // NOLINT |
| 195 | const int kShortSize = sizeof(short); // NOLINT |
| 196 | const int kIntSize = sizeof(int); // NOLINT |
| 197 | const int kDoubleSize = sizeof(double); // NOLINT |
| 198 | const int kPointerSize = sizeof(void*); // NOLINT |
| 199 | const int kIntptrSize = sizeof(intptr_t); // NOLINT |
| 200 | |
| 201 | #if V8_HOST_ARCH_64_BIT |
| 202 | const int kPointerSizeLog2 = 3; |
| 203 | const intptr_t kIntptrSignBit = V8_INT64_C(0x8000000000000000); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame^] | 204 | const uintptr_t kUintptrAllBitsSet = V8_UINT64_C(0xFFFFFFFFFFFFFFFF); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 205 | #else |
| 206 | const int kPointerSizeLog2 = 2; |
| 207 | const intptr_t kIntptrSignBit = 0x80000000; |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame^] | 208 | const uintptr_t kUintptrAllBitsSet = 0xFFFFFFFFu; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 209 | #endif |
| 210 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 211 | // Mask for the sign bit in a smi. |
| 212 | const intptr_t kSmiSignMask = kIntptrSignBit; |
| 213 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 214 | const int kObjectAlignmentBits = kPointerSizeLog2; |
| 215 | const intptr_t kObjectAlignment = 1 << kObjectAlignmentBits; |
| 216 | const intptr_t kObjectAlignmentMask = kObjectAlignment - 1; |
| 217 | |
| 218 | // Desired alignment for pointers. |
| 219 | const intptr_t kPointerAlignment = (1 << kPointerSizeLog2); |
| 220 | const intptr_t kPointerAlignmentMask = kPointerAlignment - 1; |
| 221 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 222 | // Desired alignment for maps. |
| 223 | #if V8_HOST_ARCH_64_BIT |
| 224 | const intptr_t kMapAlignmentBits = kObjectAlignmentBits; |
| 225 | #else |
| 226 | const intptr_t kMapAlignmentBits = kObjectAlignmentBits + 3; |
| 227 | #endif |
| 228 | const intptr_t kMapAlignment = (1 << kMapAlignmentBits); |
| 229 | const intptr_t kMapAlignmentMask = kMapAlignment - 1; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 230 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 231 | // Desired alignment for generated code is 32 bytes (to improve cache line |
| 232 | // utilization). |
| 233 | const int kCodeAlignmentBits = 5; |
| 234 | const intptr_t kCodeAlignment = 1 << kCodeAlignmentBits; |
| 235 | const intptr_t kCodeAlignmentMask = kCodeAlignment - 1; |
| 236 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 237 | // Tag information for Failure. |
| 238 | const int kFailureTag = 3; |
| 239 | const int kFailureTagSize = 2; |
| 240 | const intptr_t kFailureTagMask = (1 << kFailureTagSize) - 1; |
| 241 | |
| 242 | |
| 243 | const int kBitsPerByte = 8; |
| 244 | const int kBitsPerByteLog2 = 3; |
| 245 | const int kBitsPerPointer = kPointerSize * kBitsPerByte; |
| 246 | const int kBitsPerInt = kIntSize * kBitsPerByte; |
| 247 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 248 | // IEEE 754 single precision floating point number bit layout. |
| 249 | const uint32_t kBinary32SignMask = 0x80000000u; |
| 250 | const uint32_t kBinary32ExponentMask = 0x7f800000u; |
| 251 | const uint32_t kBinary32MantissaMask = 0x007fffffu; |
| 252 | const int kBinary32ExponentBias = 127; |
| 253 | const int kBinary32MaxExponent = 0xFE; |
| 254 | const int kBinary32MinExponent = 0x01; |
| 255 | const int kBinary32MantissaBits = 23; |
| 256 | const int kBinary32ExponentShift = 23; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 257 | |
| 258 | // Zap-value: The value used for zapping dead objects. |
| 259 | // Should be a recognizable hex value tagged as a heap object pointer. |
| 260 | #ifdef V8_HOST_ARCH_64_BIT |
| 261 | const Address kZapValue = |
| 262 | reinterpret_cast<Address>(V8_UINT64_C(0xdeadbeedbeadbeed)); |
| 263 | const Address kHandleZapValue = |
| 264 | reinterpret_cast<Address>(V8_UINT64_C(0x1baddead0baddead)); |
| 265 | const Address kFromSpaceZapValue = |
| 266 | reinterpret_cast<Address>(V8_UINT64_C(0x1beefdad0beefdad)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 267 | const uint64_t kDebugZapValue = 0xbadbaddbbadbaddb; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 268 | #else |
| 269 | const Address kZapValue = reinterpret_cast<Address>(0xdeadbeed); |
| 270 | const Address kHandleZapValue = reinterpret_cast<Address>(0xbaddead); |
| 271 | const Address kFromSpaceZapValue = reinterpret_cast<Address>(0xbeefdad); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 272 | const uint32_t kDebugZapValue = 0xbadbaddb; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 273 | #endif |
| 274 | |
| 275 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 276 | // Number of bits to represent the page size for paged spaces. The value of 13 |
| 277 | // gives 8K bytes per page. |
| 278 | const int kPageSizeBits = 13; |
| 279 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 280 | // On Intel architecture, cache line size is 64 bytes. |
| 281 | // On ARM it may be less (32 bytes), but as far this constant is |
| 282 | // used for aligning data, it doesn't hurt to align on a greater value. |
| 283 | const int kProcessorCacheLineSize = 64; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 284 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 285 | // Constants relevant to double precision floating point numbers. |
| 286 | |
| 287 | // Quiet NaNs have bits 51 to 62 set, possibly the sign bit, and no |
| 288 | // other bits set. |
| 289 | const uint64_t kQuietNaNMask = static_cast<uint64_t>(0xfff) << 51; |
| 290 | // If looking only at the top 32 bits, the QNaN mask is bits 19 to 30. |
| 291 | const uint32_t kQuietNaNHighBitsMask = 0xfff << (51 - 32); |
| 292 | |
| 293 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 294 | // ----------------------------------------------------------------------------- |
| 295 | // Forward declarations for frequently used classes |
| 296 | // (sorted alphabetically) |
| 297 | |
| 298 | class AccessorInfo; |
| 299 | class Allocation; |
| 300 | class Arguments; |
| 301 | class Assembler; |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 302 | class AssertNoAllocation; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 303 | class BreakableStatement; |
| 304 | class Code; |
| 305 | class CodeGenerator; |
| 306 | class CodeStub; |
| 307 | class Context; |
| 308 | class Debug; |
| 309 | class Debugger; |
| 310 | class DebugInfo; |
| 311 | class Descriptor; |
| 312 | class DescriptorArray; |
| 313 | class Expression; |
| 314 | class ExternalReference; |
| 315 | class FixedArray; |
| 316 | class FunctionEntry; |
| 317 | class FunctionLiteral; |
| 318 | class FunctionTemplateInfo; |
| 319 | class NumberDictionary; |
| 320 | class StringDictionary; |
| 321 | class FreeStoreAllocationPolicy; |
| 322 | template <typename T> class Handle; |
| 323 | class Heap; |
| 324 | class HeapObject; |
| 325 | class IC; |
| 326 | class InterceptorInfo; |
| 327 | class IterationStatement; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 328 | class JSArray; |
| 329 | class JSFunction; |
| 330 | class JSObject; |
| 331 | class LargeObjectSpace; |
| 332 | template <typename T, class P = FreeStoreAllocationPolicy> class List; |
| 333 | class LookupResult; |
| 334 | class MacroAssembler; |
| 335 | class Map; |
| 336 | class MapSpace; |
| 337 | class MarkCompactCollector; |
| 338 | class NewSpace; |
| 339 | class NodeVisitor; |
| 340 | class Object; |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame^] | 341 | class MaybeObject; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 342 | class OldSpace; |
| 343 | class Property; |
| 344 | class Proxy; |
| 345 | class RegExpNode; |
| 346 | struct RegExpCompileData; |
| 347 | class RegExpTree; |
| 348 | class RegExpCompiler; |
| 349 | class RegExpVisitor; |
| 350 | class Scope; |
| 351 | template<class Allocator = FreeStoreAllocationPolicy> class ScopeInfo; |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 352 | class SerializedScopeInfo; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 353 | class Script; |
| 354 | class Slot; |
| 355 | class Smi; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 356 | template <typename Config, class Allocator = FreeStoreAllocationPolicy> |
| 357 | class SplayTree; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 358 | class Statement; |
| 359 | class String; |
| 360 | class Struct; |
| 361 | class SwitchStatement; |
| 362 | class AstVisitor; |
| 363 | class Variable; |
| 364 | class VariableProxy; |
| 365 | class RelocInfo; |
| 366 | class Deserializer; |
| 367 | class MessageLocation; |
| 368 | class ObjectGroup; |
| 369 | class TickSample; |
| 370 | class VirtualMemory; |
| 371 | class Mutex; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 372 | |
| 373 | typedef bool (*WeakSlotCallback)(Object** pointer); |
| 374 | |
| 375 | // ----------------------------------------------------------------------------- |
| 376 | // Miscellaneous |
| 377 | |
| 378 | // NOTE: SpaceIterator depends on AllocationSpace enumeration values being |
| 379 | // consecutive. |
| 380 | enum AllocationSpace { |
| 381 | NEW_SPACE, // Semispaces collected with copying collector. |
| 382 | OLD_POINTER_SPACE, // May contain pointers to new space. |
| 383 | OLD_DATA_SPACE, // Must not have pointers to new space. |
| 384 | CODE_SPACE, // No pointers to new space, marked executable. |
| 385 | MAP_SPACE, // Only and all map objects. |
| 386 | CELL_SPACE, // Only and all cell objects. |
| 387 | LO_SPACE, // Promoted large objects. |
| 388 | |
| 389 | FIRST_SPACE = NEW_SPACE, |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 390 | LAST_SPACE = LO_SPACE, |
| 391 | FIRST_PAGED_SPACE = OLD_POINTER_SPACE, |
| 392 | LAST_PAGED_SPACE = CELL_SPACE |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 393 | }; |
| 394 | const int kSpaceTagSize = 3; |
| 395 | const int kSpaceTagMask = (1 << kSpaceTagSize) - 1; |
| 396 | |
| 397 | |
| 398 | // A flag that indicates whether objects should be pretenured when |
| 399 | // allocated (allocated directly into the old generation) or not |
| 400 | // (allocated in the young generation if the object size and type |
| 401 | // allows). |
| 402 | enum PretenureFlag { NOT_TENURED, TENURED }; |
| 403 | |
| 404 | enum GarbageCollector { SCAVENGER, MARK_COMPACTOR }; |
| 405 | |
| 406 | enum Executability { NOT_EXECUTABLE, EXECUTABLE }; |
| 407 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 408 | enum VisitMode { VISIT_ALL, VISIT_ALL_IN_SCAVENGE, VISIT_ONLY_STRONG }; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 409 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 410 | // Flag indicating whether code is built into the VM (one of the natives files). |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 411 | enum NativesFlag { NOT_NATIVES_CODE, NATIVES_CODE }; |
| 412 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 413 | |
| 414 | // A CodeDesc describes a buffer holding instructions and relocation |
| 415 | // information. The instructions start at the beginning of the buffer |
| 416 | // and grow forward, the relocation information starts at the end of |
| 417 | // the buffer and grows backward. |
| 418 | // |
| 419 | // |<--------------- buffer_size ---------------->| |
| 420 | // |<-- instr_size -->| |<-- reloc_size -->| |
| 421 | // +==================+========+==================+ |
| 422 | // | instructions | free | reloc info | |
| 423 | // +==================+========+==================+ |
| 424 | // ^ |
| 425 | // | |
| 426 | // buffer |
| 427 | |
| 428 | struct CodeDesc { |
| 429 | byte* buffer; |
| 430 | int buffer_size; |
| 431 | int instr_size; |
| 432 | int reloc_size; |
| 433 | Assembler* origin; |
| 434 | }; |
| 435 | |
| 436 | |
| 437 | // Callback function on object slots, used for iterating heap object slots in |
| 438 | // HeapObjects, global pointers to heap objects, etc. The callback allows the |
| 439 | // callback function to change the value of the slot. |
| 440 | typedef void (*ObjectSlotCallback)(HeapObject** pointer); |
| 441 | |
| 442 | |
| 443 | // Callback function used for iterating objects in heap spaces, |
| 444 | // for example, scanning heap objects. |
| 445 | typedef int (*HeapObjectCallback)(HeapObject* obj); |
| 446 | |
| 447 | |
| 448 | // Callback function used for checking constraints when copying/relocating |
| 449 | // objects. Returns true if an object can be copied/relocated from its |
| 450 | // old_addr to a new_addr. |
| 451 | typedef bool (*ConstraintCallback)(Address new_addr, Address old_addr); |
| 452 | |
| 453 | |
| 454 | // Callback function on inline caches, used for iterating over inline caches |
| 455 | // in compiled code. |
| 456 | typedef void (*InlineCacheCallback)(Code* code, Address ic); |
| 457 | |
| 458 | |
| 459 | // State for inline cache call sites. Aliased as IC::State. |
| 460 | enum InlineCacheState { |
| 461 | // Has never been executed. |
| 462 | UNINITIALIZED, |
| 463 | // Has been executed but monomorhic state has been delayed. |
| 464 | PREMONOMORPHIC, |
| 465 | // Has been executed and only one receiver type has been seen. |
| 466 | MONOMORPHIC, |
| 467 | // Like MONOMORPHIC but check failed due to prototype. |
| 468 | MONOMORPHIC_PROTOTYPE_FAILURE, |
| 469 | // Multiple receiver types have been seen. |
| 470 | MEGAMORPHIC, |
| 471 | // Special states for debug break or step in prepare stubs. |
| 472 | DEBUG_BREAK, |
| 473 | DEBUG_PREPARE_STEP_IN |
| 474 | }; |
| 475 | |
| 476 | |
| 477 | enum InLoopFlag { |
| 478 | NOT_IN_LOOP, |
| 479 | IN_LOOP |
| 480 | }; |
| 481 | |
| 482 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 483 | enum CallFunctionFlags { |
| 484 | NO_CALL_FUNCTION_FLAGS = 0, |
| 485 | RECEIVER_MIGHT_BE_VALUE = 1 << 0 // Receiver might not be a JSObject. |
| 486 | }; |
| 487 | |
| 488 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 489 | enum InlineCacheHolderFlag { |
| 490 | OWN_MAP, // For fast properties objects. |
| 491 | PROTOTYPE_MAP // For slow properties objects (except GlobalObjects). |
| 492 | }; |
| 493 | |
| 494 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 495 | // Type of properties. |
| 496 | // Order of properties is significant. |
| 497 | // Must fit in the BitField PropertyDetails::TypeField. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 498 | // A copy of this is in mirror-debugger.js. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 499 | enum PropertyType { |
| 500 | NORMAL = 0, // only in slow mode |
| 501 | FIELD = 1, // only in fast mode |
| 502 | CONSTANT_FUNCTION = 2, // only in fast mode |
| 503 | CALLBACKS = 3, |
| 504 | INTERCEPTOR = 4, // only in lookup results, not in descriptors. |
| 505 | MAP_TRANSITION = 5, // only in fast mode |
| 506 | CONSTANT_TRANSITION = 6, // only in fast mode |
| 507 | NULL_DESCRIPTOR = 7, // only in fast mode |
| 508 | // All properties before MAP_TRANSITION are real. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 509 | FIRST_PHANTOM_PROPERTY_TYPE = MAP_TRANSITION, |
| 510 | // There are no IC stubs for NULL_DESCRIPTORS. Therefore, |
| 511 | // NULL_DESCRIPTOR can be used as the type flag for IC stubs for |
| 512 | // nonexistent properties. |
| 513 | NONEXISTENT = NULL_DESCRIPTOR |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 514 | }; |
| 515 | |
| 516 | |
| 517 | // Whether to remove map transitions and constant transitions from a |
| 518 | // DescriptorArray. |
| 519 | enum TransitionFlag { |
| 520 | REMOVE_TRANSITIONS, |
| 521 | KEEP_TRANSITIONS |
| 522 | }; |
| 523 | |
| 524 | |
| 525 | // Union used for fast testing of specific double values. |
| 526 | union DoubleRepresentation { |
| 527 | double value; |
| 528 | int64_t bits; |
| 529 | DoubleRepresentation(double x) { value = x; } |
| 530 | }; |
| 531 | |
| 532 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 533 | // Union used for customized checking of the IEEE double types |
| 534 | // inlined within v8 runtime, rather than going to the underlying |
| 535 | // platform headers and libraries |
| 536 | union IeeeDoubleLittleEndianArchType { |
| 537 | double d; |
| 538 | struct { |
| 539 | unsigned int man_low :32; |
| 540 | unsigned int man_high :20; |
| 541 | unsigned int exp :11; |
| 542 | unsigned int sign :1; |
| 543 | } bits; |
| 544 | }; |
| 545 | |
| 546 | |
| 547 | union IeeeDoubleBigEndianArchType { |
| 548 | double d; |
| 549 | struct { |
| 550 | unsigned int sign :1; |
| 551 | unsigned int exp :11; |
| 552 | unsigned int man_high :20; |
| 553 | unsigned int man_low :32; |
| 554 | } bits; |
| 555 | }; |
| 556 | |
| 557 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 558 | // AccessorCallback |
| 559 | struct AccessorDescriptor { |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame^] | 560 | MaybeObject* (*getter)(Object* object, void* data); |
| 561 | MaybeObject* (*setter)(JSObject* object, Object* value, void* data); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 562 | void* data; |
| 563 | }; |
| 564 | |
| 565 | |
| 566 | // Logging and profiling. |
| 567 | // A StateTag represents a possible state of the VM. When compiled with |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 568 | // ENABLE_VMSTATE_TRACKING, the logger maintains a stack of these. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 569 | // Creating a VMState object enters a state by pushing on the stack, and |
| 570 | // destroying a VMState object leaves a state by popping the current state |
| 571 | // from the stack. |
| 572 | |
| 573 | #define STATE_TAG_LIST(V) \ |
| 574 | V(JS) \ |
| 575 | V(GC) \ |
| 576 | V(COMPILER) \ |
| 577 | V(OTHER) \ |
| 578 | V(EXTERNAL) |
| 579 | |
| 580 | enum StateTag { |
| 581 | #define DEF_STATE_TAG(name) name, |
| 582 | STATE_TAG_LIST(DEF_STATE_TAG) |
| 583 | #undef DEF_STATE_TAG |
| 584 | // Pseudo-types. |
| 585 | state_tag_count |
| 586 | }; |
| 587 | |
| 588 | |
| 589 | // ----------------------------------------------------------------------------- |
| 590 | // Macros |
| 591 | |
| 592 | // Testers for test. |
| 593 | |
| 594 | #define HAS_SMI_TAG(value) \ |
| 595 | ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag) |
| 596 | |
| 597 | #define HAS_FAILURE_TAG(value) \ |
| 598 | ((reinterpret_cast<intptr_t>(value) & kFailureTagMask) == kFailureTag) |
| 599 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 600 | // OBJECT_POINTER_ALIGN returns the value aligned as a HeapObject pointer |
| 601 | #define OBJECT_POINTER_ALIGN(value) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 602 | (((value) + kObjectAlignmentMask) & ~kObjectAlignmentMask) |
| 603 | |
| 604 | // POINTER_SIZE_ALIGN returns the value aligned as a pointer. |
| 605 | #define POINTER_SIZE_ALIGN(value) \ |
| 606 | (((value) + kPointerAlignmentMask) & ~kPointerAlignmentMask) |
| 607 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 608 | // MAP_POINTER_ALIGN returns the value aligned as a map pointer. |
| 609 | #define MAP_POINTER_ALIGN(value) \ |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 610 | (((value) + kMapAlignmentMask) & ~kMapAlignmentMask) |
| 611 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 612 | // CODE_POINTER_ALIGN returns the value aligned as a generated code segment. |
| 613 | #define CODE_POINTER_ALIGN(value) \ |
| 614 | (((value) + kCodeAlignmentMask) & ~kCodeAlignmentMask) |
| 615 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 616 | // The expression OFFSET_OF(type, field) computes the byte-offset |
| 617 | // of the specified field relative to the containing type. This |
| 618 | // corresponds to 'offsetof' (in stddef.h), except that it doesn't |
| 619 | // use 0 or NULL, which causes a problem with the compiler warnings |
| 620 | // we have enabled (which is also why 'offsetof' doesn't seem to work). |
| 621 | // Here we simply use the non-zero value 4, which seems to work. |
| 622 | #define OFFSET_OF(type, field) \ |
| 623 | (reinterpret_cast<intptr_t>(&(reinterpret_cast<type*>(4)->field)) - 4) |
| 624 | |
| 625 | |
| 626 | // The expression ARRAY_SIZE(a) is a compile-time constant of type |
| 627 | // size_t which represents the number of elements of the given |
| 628 | // array. You should only use ARRAY_SIZE on statically allocated |
| 629 | // arrays. |
| 630 | #define ARRAY_SIZE(a) \ |
| 631 | ((sizeof(a) / sizeof(*(a))) / \ |
| 632 | static_cast<size_t>(!(sizeof(a) % sizeof(*(a))))) |
| 633 | |
| 634 | |
| 635 | // The USE(x) template is used to silence C++ compiler warnings |
| 636 | // issued for (yet) unused variables (typically parameters). |
| 637 | template <typename T> |
| 638 | static inline void USE(T) { } |
| 639 | |
| 640 | |
| 641 | // FUNCTION_ADDR(f) gets the address of a C function f. |
| 642 | #define FUNCTION_ADDR(f) \ |
| 643 | (reinterpret_cast<v8::internal::Address>(reinterpret_cast<intptr_t>(f))) |
| 644 | |
| 645 | |
| 646 | // FUNCTION_CAST<F>(addr) casts an address into a function |
| 647 | // of type F. Used to invoke generated code from within C. |
| 648 | template <typename F> |
| 649 | F FUNCTION_CAST(Address addr) { |
| 650 | return reinterpret_cast<F>(reinterpret_cast<intptr_t>(addr)); |
| 651 | } |
| 652 | |
| 653 | |
| 654 | // A macro to disallow the evil copy constructor and operator= functions |
| 655 | // This should be used in the private: declarations for a class |
| 656 | #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ |
| 657 | TypeName(const TypeName&); \ |
| 658 | void operator=(const TypeName&) |
| 659 | |
| 660 | |
| 661 | // A macro to disallow all the implicit constructors, namely the |
| 662 | // default constructor, copy constructor and operator= functions. |
| 663 | // |
| 664 | // This should be used in the private: declarations for a class |
| 665 | // that wants to prevent anyone from instantiating it. This is |
| 666 | // especially useful for classes containing only static methods. |
| 667 | #define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ |
| 668 | TypeName(); \ |
| 669 | DISALLOW_COPY_AND_ASSIGN(TypeName) |
| 670 | |
| 671 | |
| 672 | // Support for tracking C++ memory allocation. Insert TRACK_MEMORY("Fisk") |
| 673 | // inside a C++ class and new and delete will be overloaded so logging is |
| 674 | // performed. |
| 675 | // This file (globals.h) is included before log.h, so we use direct calls to |
| 676 | // the Logger rather than the LOG macro. |
| 677 | #ifdef DEBUG |
| 678 | #define TRACK_MEMORY(name) \ |
| 679 | void* operator new(size_t size) { \ |
| 680 | void* result = ::operator new(size); \ |
| 681 | Logger::NewEvent(name, result, size); \ |
| 682 | return result; \ |
| 683 | } \ |
| 684 | void operator delete(void* object) { \ |
| 685 | Logger::DeleteEvent(name, object); \ |
| 686 | ::operator delete(object); \ |
| 687 | } |
| 688 | #else |
| 689 | #define TRACK_MEMORY(name) |
| 690 | #endif |
| 691 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 692 | // Define used for helping GCC to make better inlining. Don't bother for debug |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 693 | // builds. On GCC 3.4.5 using __attribute__((always_inline)) causes compilation |
| 694 | // errors in debug build. |
| 695 | #if defined(__GNUC__) && !defined(DEBUG) |
| 696 | #if (__GNUC__ >= 4) |
| 697 | #define INLINE(header) inline header __attribute__((always_inline)) |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 698 | #define NO_INLINE(header) header __attribute__((noinline)) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 699 | #else |
| 700 | #define INLINE(header) inline __attribute__((always_inline)) header |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 701 | #define NO_INLINE(header) __attribute__((noinline)) header |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 702 | #endif |
| 703 | #else |
| 704 | #define INLINE(header) inline header |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 705 | #define NO_INLINE(header) header |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 706 | #endif |
| 707 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 708 | |
| 709 | #if defined(__GNUC__) && __GNUC__ >= 4 |
| 710 | #define MUST_USE_RESULT __attribute__ ((warn_unused_result)) |
| 711 | #else |
| 712 | #define MUST_USE_RESULT |
| 713 | #endif |
| 714 | |
| 715 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 716 | // Feature flags bit positions. They are mostly based on the CPUID spec. |
| 717 | // (We assign CPUID itself to one of the currently reserved bits -- |
| 718 | // feel free to change this if needed.) |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 719 | // On X86/X64, values below 32 are bits in EDX, values above 32 are bits in ECX. |
| 720 | enum CpuFeature { SSE4_1 = 32 + 19, // x86 |
| 721 | SSE3 = 32 + 0, // x86 |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 722 | SSE2 = 26, // x86 |
| 723 | CMOV = 15, // x86 |
| 724 | RDTSC = 4, // x86 |
| 725 | CPUID = 10, // x86 |
| 726 | VFP3 = 1, // ARM |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 727 | ARMv7 = 2, // ARM |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 728 | SAHF = 0}; // x86 |
| 729 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 730 | } } // namespace v8::internal |
| 731 | |
| 732 | #endif // V8_GLOBALS_H_ |