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