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