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