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