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