ae7903826dfb1f9bd51416f1a4a7e236c0951f9a
[platform/framework/web/crosswalk.git] / src / v8 / 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 "src/base/build_config.h"
12 #include "src/base/logging.h"
13 #include "src/base/macros.h"
14
15 // Unfortunately, the INFINITY macro cannot be used with the '-pedantic'
16 // warning flag and certain versions of GCC due to a bug:
17 // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11931
18 // For now, we use the more involved template-based version from <limits>, but
19 // only when compiling with GCC versions affected by the bug (2.96.x - 4.0.x)
20 #if V8_CC_GNU && V8_GNUC_PREREQ(2, 96, 0) && !V8_GNUC_PREREQ(4, 1, 0)
21 # include <limits>  // NOLINT
22 # define V8_INFINITY std::numeric_limits<double>::infinity()
23 #elif V8_LIBC_MSVCRT
24 # define V8_INFINITY HUGE_VAL
25 #else
26 # define V8_INFINITY INFINITY
27 #endif
28
29 #if V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_X64 || V8_TARGET_ARCH_ARM || \
30     V8_TARGET_ARCH_ARM64 || V8_TARGET_ARCH_MIPS
31 #define V8_TURBOFAN_BACKEND 1
32 #else
33 #define V8_TURBOFAN_BACKEND 0
34 #endif
35 #if V8_TURBOFAN_BACKEND && !(V8_OS_WIN && V8_TARGET_ARCH_X64)
36 #define V8_TURBOFAN_TARGET 1
37 #else
38 #define V8_TURBOFAN_TARGET 0
39 #endif
40
41 namespace v8 {
42
43 namespace base {
44 class Mutex;
45 class RecursiveMutex;
46 class VirtualMemory;
47 }
48
49 namespace internal {
50
51 // Determine whether we are running in a simulated environment.
52 // Setting USE_SIMULATOR explicitly from the build script will force
53 // the use of a simulated environment.
54 #if !defined(USE_SIMULATOR)
55 #if (V8_TARGET_ARCH_ARM64 && !V8_HOST_ARCH_ARM64)
56 #define USE_SIMULATOR 1
57 #endif
58 #if (V8_TARGET_ARCH_ARM && !V8_HOST_ARCH_ARM)
59 #define USE_SIMULATOR 1
60 #endif
61 #if (V8_TARGET_ARCH_MIPS && !V8_HOST_ARCH_MIPS)
62 #define USE_SIMULATOR 1
63 #endif
64 #if (V8_TARGET_ARCH_MIPS64 && !V8_HOST_ARCH_MIPS64)
65 #define USE_SIMULATOR 1
66 #endif
67 #endif
68
69 // Determine whether the architecture uses an out-of-line constant pool.
70 #define V8_OOL_CONSTANT_POOL 0
71
72 #ifdef V8_TARGET_ARCH_ARM
73 // Set stack limit lower for ARM than for other architectures because
74 // stack allocating MacroAssembler takes 120K bytes.
75 // See issue crbug.com/405338
76 #define V8_DEFAULT_STACK_SIZE_KB 864
77 #else
78 // Slightly less than 1MB, since Windows' default stack size for
79 // the main execution thread is 1MB for both 32 and 64-bit.
80 #define V8_DEFAULT_STACK_SIZE_KB 984
81 #endif
82
83
84 // Support for alternative bool type. This is only enabled if the code is
85 // compiled with USE_MYBOOL defined. This catches some nasty type bugs.
86 // For instance, 'bool b = "false";' results in b == true! This is a hidden
87 // source of bugs.
88 // However, redefining the bool type does have some negative impact on some
89 // platforms. It gives rise to compiler warnings (i.e. with
90 // MSVC) in the API header files when mixing code that uses the standard
91 // bool with code that uses the redefined version.
92 // This does not actually belong in the platform code, but needs to be
93 // defined here because the platform code uses bool, and platform.h is
94 // include very early in the main include file.
95
96 #ifdef USE_MYBOOL
97 typedef unsigned int __my_bool__;
98 #define bool __my_bool__  // use 'indirection' to avoid name clashes
99 #endif
100
101 typedef uint8_t byte;
102 typedef byte* Address;
103
104 // -----------------------------------------------------------------------------
105 // Constants
106
107 const int KB = 1024;
108 const int MB = KB * KB;
109 const int GB = KB * KB * KB;
110 const int kMaxInt = 0x7FFFFFFF;
111 const int kMinInt = -kMaxInt - 1;
112 const int kMaxInt8 = (1 << 7) - 1;
113 const int kMinInt8 = -(1 << 7);
114 const int kMaxUInt8 = (1 << 8) - 1;
115 const int kMinUInt8 = 0;
116 const int kMaxInt16 = (1 << 15) - 1;
117 const int kMinInt16 = -(1 << 15);
118 const int kMaxUInt16 = (1 << 16) - 1;
119 const int kMinUInt16 = 0;
120
121 const uint32_t kMaxUInt32 = 0xFFFFFFFFu;
122
123 const int kCharSize      = sizeof(char);      // NOLINT
124 const int kShortSize     = sizeof(short);     // NOLINT
125 const int kIntSize       = sizeof(int);       // NOLINT
126 const int kInt32Size     = sizeof(int32_t);   // NOLINT
127 const int kInt64Size     = sizeof(int64_t);   // NOLINT
128 const int kDoubleSize    = sizeof(double);    // NOLINT
129 const int kIntptrSize    = sizeof(intptr_t);  // NOLINT
130 const int kPointerSize   = sizeof(void*);     // NOLINT
131 #if V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_32_BIT
132 const int kRegisterSize  = kPointerSize + kPointerSize;
133 #else
134 const int kRegisterSize  = kPointerSize;
135 #endif
136 const int kPCOnStackSize = kRegisterSize;
137 const int kFPOnStackSize = kRegisterSize;
138
139 const int kDoubleSizeLog2 = 3;
140
141 #if V8_HOST_ARCH_64_BIT
142 const int kPointerSizeLog2 = 3;
143 const intptr_t kIntptrSignBit = V8_INT64_C(0x8000000000000000);
144 const uintptr_t kUintptrAllBitsSet = V8_UINT64_C(0xFFFFFFFFFFFFFFFF);
145 const bool kRequiresCodeRange = true;
146 const size_t kMaximalCodeRangeSize = 512 * MB;
147 #if V8_OS_WIN
148 const size_t kMinimumCodeRangeSize = 4 * MB;
149 const size_t kReservedCodeRangePages = 1;
150 #else
151 const size_t kMinimumCodeRangeSize = 3 * MB;
152 const size_t kReservedCodeRangePages = 0;
153 #endif
154 #else
155 const int kPointerSizeLog2 = 2;
156 const intptr_t kIntptrSignBit = 0x80000000;
157 const uintptr_t kUintptrAllBitsSet = 0xFFFFFFFFu;
158 #if V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_32_BIT
159 // x32 port also requires code range.
160 const bool kRequiresCodeRange = true;
161 const size_t kMaximalCodeRangeSize = 256 * MB;
162 const size_t kMinimumCodeRangeSize = 3 * MB;
163 const size_t kReservedCodeRangePages = 0;
164 #else
165 const bool kRequiresCodeRange = false;
166 const size_t kMaximalCodeRangeSize = 0 * MB;
167 const size_t kMinimumCodeRangeSize = 0 * MB;
168 const size_t kReservedCodeRangePages = 0;
169 #endif
170 #endif
171
172 STATIC_ASSERT(kPointerSize == (1 << kPointerSizeLog2));
173
174 const int kBitsPerByte = 8;
175 const int kBitsPerByteLog2 = 3;
176 const int kBitsPerPointer = kPointerSize * kBitsPerByte;
177 const int kBitsPerInt = kIntSize * kBitsPerByte;
178
179 // IEEE 754 single precision floating point number bit layout.
180 const uint32_t kBinary32SignMask = 0x80000000u;
181 const uint32_t kBinary32ExponentMask = 0x7f800000u;
182 const uint32_t kBinary32MantissaMask = 0x007fffffu;
183 const int kBinary32ExponentBias = 127;
184 const int kBinary32MaxExponent  = 0xFE;
185 const int kBinary32MinExponent  = 0x01;
186 const int kBinary32MantissaBits = 23;
187 const int kBinary32ExponentShift = 23;
188
189 // Quiet NaNs have bits 51 to 62 set, possibly the sign bit, and no
190 // other bits set.
191 const uint64_t kQuietNaNMask = static_cast<uint64_t>(0xfff) << 51;
192
193 // Latin1/UTF-16 constants
194 // Code-point values in Unicode 4.0 are 21 bits wide.
195 // Code units in UTF-16 are 16 bits wide.
196 typedef uint16_t uc16;
197 typedef int32_t uc32;
198 const int kOneByteSize    = kCharSize;
199 const int kUC16Size     = sizeof(uc16);      // NOLINT
200
201
202 // Round up n to be a multiple of sz, where sz is a power of 2.
203 #define ROUND_UP(n, sz) (((n) + ((sz) - 1)) & ~((sz) - 1))
204
205
206 // FUNCTION_ADDR(f) gets the address of a C function f.
207 #define FUNCTION_ADDR(f)                                        \
208   (reinterpret_cast<v8::internal::Address>(reinterpret_cast<intptr_t>(f)))
209
210
211 // FUNCTION_CAST<F>(addr) casts an address into a function
212 // of type F. Used to invoke generated code from within C.
213 template <typename F>
214 F FUNCTION_CAST(Address addr) {
215   return reinterpret_cast<F>(reinterpret_cast<intptr_t>(addr));
216 }
217
218
219 // -----------------------------------------------------------------------------
220 // Forward declarations for frequently used classes
221 // (sorted alphabetically)
222
223 class FreeStoreAllocationPolicy;
224 template <typename T, class P = FreeStoreAllocationPolicy> class List;
225
226 // -----------------------------------------------------------------------------
227 // Declarations for use in both the preparser and the rest of V8.
228
229 // The Strict Mode (ECMA-262 5th edition, 4.2.2).
230
231 enum StrictMode { SLOPPY, STRICT };
232
233
234 // Mask for the sign bit in a smi.
235 const intptr_t kSmiSignMask = kIntptrSignBit;
236
237 const int kObjectAlignmentBits = kPointerSizeLog2;
238 const intptr_t kObjectAlignment = 1 << kObjectAlignmentBits;
239 const intptr_t kObjectAlignmentMask = kObjectAlignment - 1;
240
241 // Desired alignment for pointers.
242 const intptr_t kPointerAlignment = (1 << kPointerSizeLog2);
243 const intptr_t kPointerAlignmentMask = kPointerAlignment - 1;
244
245 // Desired alignment for double values.
246 const intptr_t kDoubleAlignment = 8;
247 const intptr_t kDoubleAlignmentMask = kDoubleAlignment - 1;
248
249 // Desired alignment for generated code is 32 bytes (to improve cache line
250 // utilization).
251 const int kCodeAlignmentBits = 5;
252 const intptr_t kCodeAlignment = 1 << kCodeAlignmentBits;
253 const intptr_t kCodeAlignmentMask = kCodeAlignment - 1;
254
255 // The owner field of a page is tagged with the page header tag. We need that
256 // to find out if a slot is part of a large object. If we mask out the lower
257 // 0xfffff bits (1M pages), go to the owner offset, and see that this field
258 // is tagged with the page header tag, we can just look up the owner.
259 // Otherwise, we know that we are somewhere (not within the first 1M) in a
260 // large object.
261 const int kPageHeaderTag = 3;
262 const int kPageHeaderTagSize = 2;
263 const intptr_t kPageHeaderTagMask = (1 << kPageHeaderTagSize) - 1;
264
265
266 // Zap-value: The value used for zapping dead objects.
267 // Should be a recognizable hex value tagged as a failure.
268 #ifdef V8_HOST_ARCH_64_BIT
269 const Address kZapValue =
270     reinterpret_cast<Address>(V8_UINT64_C(0xdeadbeedbeadbeef));
271 const Address kHandleZapValue =
272     reinterpret_cast<Address>(V8_UINT64_C(0x1baddead0baddeaf));
273 const Address kGlobalHandleZapValue =
274     reinterpret_cast<Address>(V8_UINT64_C(0x1baffed00baffedf));
275 const Address kFromSpaceZapValue =
276     reinterpret_cast<Address>(V8_UINT64_C(0x1beefdad0beefdaf));
277 const uint64_t kDebugZapValue = V8_UINT64_C(0xbadbaddbbadbaddb);
278 const uint64_t kSlotsZapValue = V8_UINT64_C(0xbeefdeadbeefdeef);
279 const uint64_t kFreeListZapValue = 0xfeed1eaffeed1eaf;
280 #else
281 const Address kZapValue = reinterpret_cast<Address>(0xdeadbeef);
282 const Address kHandleZapValue = reinterpret_cast<Address>(0xbaddeaf);
283 const Address kGlobalHandleZapValue = reinterpret_cast<Address>(0xbaffedf);
284 const Address kFromSpaceZapValue = reinterpret_cast<Address>(0xbeefdaf);
285 const uint32_t kSlotsZapValue = 0xbeefdeef;
286 const uint32_t kDebugZapValue = 0xbadbaddb;
287 const uint32_t kFreeListZapValue = 0xfeed1eaf;
288 #endif
289
290 const int kCodeZapValue = 0xbadc0de;
291 const uint32_t kPhantomReferenceZap = 0xca11bac;
292
293 // On Intel architecture, cache line size is 64 bytes.
294 // On ARM it may be less (32 bytes), but as far this constant is
295 // used for aligning data, it doesn't hurt to align on a greater value.
296 #define PROCESSOR_CACHE_LINE_SIZE 64
297
298 // Constants relevant to double precision floating point numbers.
299 // If looking only at the top 32 bits, the QNaN mask is bits 19 to 30.
300 const uint32_t kQuietNaNHighBitsMask = 0xfff << (51 - 32);
301
302
303 // -----------------------------------------------------------------------------
304 // Forward declarations for frequently used classes
305
306 class AccessorInfo;
307 class Allocation;
308 class Arguments;
309 class Assembler;
310 class Code;
311 class CodeGenerator;
312 class CodeStub;
313 class Context;
314 class Debug;
315 class Debugger;
316 class DebugInfo;
317 class Descriptor;
318 class DescriptorArray;
319 class TransitionArray;
320 class ExternalReference;
321 class FixedArray;
322 class FunctionTemplateInfo;
323 class MemoryChunk;
324 class SeededNumberDictionary;
325 class UnseededNumberDictionary;
326 class NameDictionary;
327 template <typename T> class MaybeHandle;
328 template <typename T> class Handle;
329 class Heap;
330 class HeapObject;
331 class IC;
332 class InterceptorInfo;
333 class Isolate;
334 class JSReceiver;
335 class JSArray;
336 class JSFunction;
337 class JSObject;
338 class LargeObjectSpace;
339 class LookupResult;
340 class MacroAssembler;
341 class Map;
342 class MapSpace;
343 class MarkCompactCollector;
344 class NewSpace;
345 class Object;
346 class OldSpace;
347 class Foreign;
348 class Scope;
349 class ScopeInfo;
350 class Script;
351 class Smi;
352 template <typename Config, class Allocator = FreeStoreAllocationPolicy>
353     class SplayTree;
354 class String;
355 class Name;
356 class Struct;
357 class Variable;
358 class RelocInfo;
359 class Deserializer;
360 class MessageLocation;
361
362 typedef bool (*WeakSlotCallback)(Object** pointer);
363
364 typedef bool (*WeakSlotCallbackWithHeap)(Heap* heap, Object** pointer);
365
366 // -----------------------------------------------------------------------------
367 // Miscellaneous
368
369 // NOTE: SpaceIterator depends on AllocationSpace enumeration values being
370 // consecutive.
371 enum AllocationSpace {
372   NEW_SPACE,            // Semispaces collected with copying collector.
373   OLD_POINTER_SPACE,    // May contain pointers to new space.
374   OLD_DATA_SPACE,       // Must not have pointers to new space.
375   CODE_SPACE,           // No pointers to new space, marked executable.
376   MAP_SPACE,            // Only and all map objects.
377   CELL_SPACE,           // Only and all cell objects.
378   PROPERTY_CELL_SPACE,  // Only and all global property cell objects.
379   LO_SPACE,             // Promoted large objects.
380
381   FIRST_SPACE = NEW_SPACE,
382   LAST_SPACE = LO_SPACE,
383   FIRST_PAGED_SPACE = OLD_POINTER_SPACE,
384   LAST_PAGED_SPACE = PROPERTY_CELL_SPACE
385 };
386 const int kSpaceTagSize = 3;
387 const int kSpaceTagMask = (1 << kSpaceTagSize) - 1;
388
389
390 // A flag that indicates whether objects should be pretenured when
391 // allocated (allocated directly into the old generation) or not
392 // (allocated in the young generation if the object size and type
393 // allows).
394 enum PretenureFlag { NOT_TENURED, TENURED };
395
396 enum MinimumCapacity {
397   USE_DEFAULT_MINIMUM_CAPACITY,
398   USE_CUSTOM_MINIMUM_CAPACITY
399 };
400
401 enum GarbageCollector { SCAVENGER, MARK_COMPACTOR };
402
403 enum Executability { NOT_EXECUTABLE, EXECUTABLE };
404
405 enum VisitMode {
406   VISIT_ALL,
407   VISIT_ALL_IN_SCAVENGE,
408   VISIT_ALL_IN_SWEEP_NEWSPACE,
409   VISIT_ONLY_STRONG
410 };
411
412 // Flag indicating whether code is built into the VM (one of the natives files).
413 enum NativesFlag { NOT_NATIVES_CODE, NATIVES_CODE };
414
415
416 // A CodeDesc describes a buffer holding instructions and relocation
417 // information. The instructions start at the beginning of the buffer
418 // and grow forward, the relocation information starts at the end of
419 // the buffer and grows backward.
420 //
421 //  |<--------------- buffer_size ---------------->|
422 //  |<-- instr_size -->|        |<-- reloc_size -->|
423 //  +==================+========+==================+
424 //  |   instructions   |  free  |    reloc info    |
425 //  +==================+========+==================+
426 //  ^
427 //  |
428 //  buffer
429
430 struct CodeDesc {
431   byte* buffer;
432   int buffer_size;
433   int instr_size;
434   int reloc_size;
435   Assembler* origin;
436 };
437
438
439 // Callback function used for iterating objects in heap spaces,
440 // for example, scanning heap objects.
441 typedef int (*HeapObjectCallback)(HeapObject* obj);
442
443
444 // Callback function used for checking constraints when copying/relocating
445 // objects. Returns true if an object can be copied/relocated from its
446 // old_addr to a new_addr.
447 typedef bool (*ConstraintCallback)(Address new_addr, Address old_addr);
448
449
450 // Callback function on inline caches, used for iterating over inline caches
451 // in compiled code.
452 typedef void (*InlineCacheCallback)(Code* code, Address ic);
453
454
455 // State for inline cache call sites. Aliased as IC::State.
456 enum InlineCacheState {
457   // Has never been executed.
458   UNINITIALIZED,
459   // Has been executed but monomorhic state has been delayed.
460   PREMONOMORPHIC,
461   // Has been executed and only one receiver type has been seen.
462   MONOMORPHIC,
463   // Check failed due to prototype (or map deprecation).
464   PROTOTYPE_FAILURE,
465   // Multiple receiver types have been seen.
466   POLYMORPHIC,
467   // Many receiver types have been seen.
468   MEGAMORPHIC,
469   // A generic handler is installed and no extra typefeedback is recorded.
470   GENERIC,
471   // Special state for debug break or step in prepare stubs.
472   DEBUG_STUB,
473   // Type-vector-based ICs have a default state, with the full calculation
474   // of IC state only determined by a look at the IC and the typevector
475   // together.
476   DEFAULT
477 };
478
479
480 enum CallFunctionFlags {
481   NO_CALL_FUNCTION_FLAGS,
482   CALL_AS_METHOD,
483   // Always wrap the receiver and call to the JSFunction. Only use this flag
484   // both the receiver type and the target method are statically known.
485   WRAP_AND_CALL
486 };
487
488
489 enum CallConstructorFlags {
490   NO_CALL_CONSTRUCTOR_FLAGS,
491   // The call target is cached in the instruction stream.
492   RECORD_CONSTRUCTOR_TARGET
493 };
494
495
496 enum CacheHolderFlag {
497   kCacheOnPrototype,
498   kCacheOnPrototypeReceiverIsDictionary,
499   kCacheOnPrototypeReceiverIsPrimitive,
500   kCacheOnReceiver
501 };
502
503
504 // The Store Buffer (GC).
505 typedef enum {
506   kStoreBufferFullEvent,
507   kStoreBufferStartScanningPagesEvent,
508   kStoreBufferScanningPageEvent
509 } StoreBufferEvent;
510
511
512 typedef void (*StoreBufferCallback)(Heap* heap,
513                                     MemoryChunk* page,
514                                     StoreBufferEvent event);
515
516
517 // Union used for fast testing of specific double values.
518 union DoubleRepresentation {
519   double  value;
520   int64_t bits;
521   DoubleRepresentation(double x) { value = x; }
522   bool operator==(const DoubleRepresentation& other) const {
523     return bits == other.bits;
524   }
525 };
526
527
528 // Union used for customized checking of the IEEE double types
529 // inlined within v8 runtime, rather than going to the underlying
530 // platform headers and libraries
531 union IeeeDoubleLittleEndianArchType {
532   double d;
533   struct {
534     unsigned int man_low  :32;
535     unsigned int man_high :20;
536     unsigned int exp      :11;
537     unsigned int sign     :1;
538   } bits;
539 };
540
541
542 union IeeeDoubleBigEndianArchType {
543   double d;
544   struct {
545     unsigned int sign     :1;
546     unsigned int exp      :11;
547     unsigned int man_high :20;
548     unsigned int man_low  :32;
549   } bits;
550 };
551
552
553 // AccessorCallback
554 struct AccessorDescriptor {
555   Object* (*getter)(Isolate* isolate, Object* object, void* data);
556   Object* (*setter)(
557       Isolate* isolate, JSObject* object, Object* value, void* data);
558   void* data;
559 };
560
561
562 // -----------------------------------------------------------------------------
563 // Macros
564
565 // Testers for test.
566
567 #define HAS_SMI_TAG(value) \
568   ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag)
569
570 #define HAS_FAILURE_TAG(value) \
571   ((reinterpret_cast<intptr_t>(value) & kFailureTagMask) == kFailureTag)
572
573 // OBJECT_POINTER_ALIGN returns the value aligned as a HeapObject pointer
574 #define OBJECT_POINTER_ALIGN(value)                             \
575   (((value) + kObjectAlignmentMask) & ~kObjectAlignmentMask)
576
577 // POINTER_SIZE_ALIGN returns the value aligned as a pointer.
578 #define POINTER_SIZE_ALIGN(value)                               \
579   (((value) + kPointerAlignmentMask) & ~kPointerAlignmentMask)
580
581 // CODE_POINTER_ALIGN returns the value aligned as a generated code segment.
582 #define CODE_POINTER_ALIGN(value)                               \
583   (((value) + kCodeAlignmentMask) & ~kCodeAlignmentMask)
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::NewEventStatic(name, result, size); \
595     return result; \
596   } \
597   void operator delete(void* object) { \
598     Logger::DeleteEventStatic(name, object); \
599     ::operator delete(object); \
600   }
601 #else
602 #define TRACK_MEMORY(name)
603 #endif
604
605
606 // CPU feature flags.
607 enum CpuFeature {
608   // x86
609   SSE4_1,
610   SSE3,
611   SAHF,
612   // ARM
613   VFP3,
614   ARMv7,
615   ARMv8,
616   SUDIV,
617   MLS,
618   UNALIGNED_ACCESSES,
619   MOVW_MOVT_IMMEDIATE_LOADS,
620   VFP32DREGS,
621   NEON,
622   // MIPS, MIPS64
623   FPU,
624   FP64FPU,
625   MIPSr1,
626   MIPSr2,
627   MIPSr6,
628   // ARM64
629   ALWAYS_ALIGN_CSP,
630   NUMBER_OF_CPU_FEATURES
631 };
632
633
634 // Used to specify if a macro instruction must perform a smi check on tagged
635 // values.
636 enum SmiCheckType {
637   DONT_DO_SMI_CHECK,
638   DO_SMI_CHECK
639 };
640
641
642 enum ScopeType {
643   EVAL_SCOPE,      // The top-level scope for an eval source.
644   FUNCTION_SCOPE,  // The top-level scope for a function.
645   MODULE_SCOPE,    // The scope introduced by a module literal
646   GLOBAL_SCOPE,    // The top-level scope for a program or a top-level eval.
647   CATCH_SCOPE,     // The scope introduced by catch.
648   BLOCK_SCOPE,     // The scope introduced by a new block.
649   WITH_SCOPE,      // The scope introduced by with.
650   ARROW_SCOPE      // The top-level scope for an arrow function literal.
651 };
652
653
654 const uint32_t kHoleNanUpper32 = 0x7FFFFFFF;
655 const uint32_t kHoleNanLower32 = 0xFFFFFFFF;
656 const uint32_t kNaNOrInfinityLowerBoundUpper32 = 0x7FF00000;
657
658 const uint64_t kHoleNanInt64 =
659     (static_cast<uint64_t>(kHoleNanUpper32) << 32) | kHoleNanLower32;
660 const uint64_t kLastNonNaNInt64 =
661     (static_cast<uint64_t>(kNaNOrInfinityLowerBoundUpper32) << 32);
662
663
664 // The order of this enum has to be kept in sync with the predicates below.
665 enum VariableMode {
666   // User declared variables:
667   VAR,             // declared via 'var', and 'function' declarations
668
669   CONST_LEGACY,    // declared via legacy 'const' declarations
670
671   LET,             // declared via 'let' declarations (first lexical)
672
673   CONST,           // declared via 'const' declarations
674
675   MODULE,          // declared via 'module' declaration (last lexical)
676
677   // Variables introduced by the compiler:
678   INTERNAL,        // like VAR, but not user-visible (may or may not
679                    // be in a context)
680
681   TEMPORARY,       // temporary variables (not user-visible), stack-allocated
682                    // unless the scope as a whole has forced context allocation
683
684   DYNAMIC,         // always require dynamic lookup (we don't know
685                    // the declaration)
686
687   DYNAMIC_GLOBAL,  // requires dynamic lookup, but we know that the
688                    // variable is global unless it has been shadowed
689                    // by an eval-introduced variable
690
691   DYNAMIC_LOCAL    // requires dynamic lookup, but we know that the
692                    // variable is local and where it is unless it
693                    // has been shadowed by an eval-introduced
694                    // variable
695 };
696
697
698 inline bool IsDynamicVariableMode(VariableMode mode) {
699   return mode >= DYNAMIC && mode <= DYNAMIC_LOCAL;
700 }
701
702
703 inline bool IsDeclaredVariableMode(VariableMode mode) {
704   return mode >= VAR && mode <= MODULE;
705 }
706
707
708 inline bool IsLexicalVariableMode(VariableMode mode) {
709   return mode >= LET && mode <= MODULE;
710 }
711
712
713 inline bool IsImmutableVariableMode(VariableMode mode) {
714   return (mode >= CONST && mode <= MODULE) || mode == CONST_LEGACY;
715 }
716
717
718 // ES6 Draft Rev3 10.2 specifies declarative environment records with mutable
719 // and immutable bindings that can be in two states: initialized and
720 // uninitialized. In ES5 only immutable bindings have these two states. When
721 // accessing a binding, it needs to be checked for initialization. However in
722 // the following cases the binding is initialized immediately after creation
723 // so the initialization check can always be skipped:
724 // 1. Var declared local variables.
725 //      var foo;
726 // 2. A local variable introduced by a function declaration.
727 //      function foo() {}
728 // 3. Parameters
729 //      function x(foo) {}
730 // 4. Catch bound variables.
731 //      try {} catch (foo) {}
732 // 6. Function variables of named function expressions.
733 //      var x = function foo() {}
734 // 7. Implicit binding of 'this'.
735 // 8. Implicit binding of 'arguments' in functions.
736 //
737 // ES5 specified object environment records which are introduced by ES elements
738 // such as Program and WithStatement that associate identifier bindings with the
739 // properties of some object. In the specification only mutable bindings exist
740 // (which may be non-writable) and have no distinct initialization step. However
741 // V8 allows const declarations in global code with distinct creation and
742 // initialization steps which are represented by non-writable properties in the
743 // global object. As a result also these bindings need to be checked for
744 // initialization.
745 //
746 // The following enum specifies a flag that indicates if the binding needs a
747 // distinct initialization step (kNeedsInitialization) or if the binding is
748 // immediately initialized upon creation (kCreatedInitialized).
749 enum InitializationFlag {
750   kNeedsInitialization,
751   kCreatedInitialized
752 };
753
754
755 enum MaybeAssignedFlag { kNotAssigned, kMaybeAssigned };
756
757
758 enum ClearExceptionFlag {
759   KEEP_EXCEPTION,
760   CLEAR_EXCEPTION
761 };
762
763
764 enum MinusZeroMode {
765   TREAT_MINUS_ZERO_AS_ZERO,
766   FAIL_ON_MINUS_ZERO
767 };
768
769
770 enum Signedness { kSigned, kUnsigned };
771
772
773 enum FunctionKind {
774   kNormalFunction = 0,
775   kArrowFunction = 1,
776   kGeneratorFunction = 2,
777   kConciseMethod = 4,
778   kConciseGeneratorMethod = kGeneratorFunction | kConciseMethod
779 };
780
781
782 inline bool IsValidFunctionKind(FunctionKind kind) {
783   return kind == FunctionKind::kNormalFunction ||
784          kind == FunctionKind::kArrowFunction ||
785          kind == FunctionKind::kGeneratorFunction ||
786          kind == FunctionKind::kConciseMethod ||
787          kind == FunctionKind::kConciseGeneratorMethod;
788 }
789
790
791 inline bool IsArrowFunction(FunctionKind kind) {
792   DCHECK(IsValidFunctionKind(kind));
793   return kind & FunctionKind::kArrowFunction;
794 }
795
796
797 inline bool IsGeneratorFunction(FunctionKind kind) {
798   DCHECK(IsValidFunctionKind(kind));
799   return kind & FunctionKind::kGeneratorFunction;
800 }
801
802
803 inline bool IsConciseMethod(FunctionKind kind) {
804   DCHECK(IsValidFunctionKind(kind));
805   return kind & FunctionKind::kConciseMethod;
806 }
807 } }  // namespace v8::internal
808
809 namespace i = v8::internal;
810
811 #endif  // V8_GLOBALS_H_