blob: a31f2374bd633d64b84f5610d888d96c549bc4da [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 Murdoch4a90d5f2016-03-22 12:00:34 +000011#include <ostream>
12
Ben Murdochb8a8cc12014-11-26 15:28:44 +000013#include "src/base/build_config.h"
14#include "src/base/logging.h"
15#include "src/base/macros.h"
Ben Murdoch589d6972011-11-30 16:04:58 +000016
17// Unfortunately, the INFINITY macro cannot be used with the '-pedantic'
18// warning flag and certain versions of GCC due to a bug:
19// http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11931
20// For now, we use the more involved template-based version from <limits>, but
21// only when compiling with GCC versions affected by the bug (2.96.x - 4.0.x)
Ben Murdochb8a8cc12014-11-26 15:28:44 +000022#if V8_CC_GNU && V8_GNUC_PREREQ(2, 96, 0) && !V8_GNUC_PREREQ(4, 1, 0)
23# include <limits> // NOLINT
24# define V8_INFINITY std::numeric_limits<double>::infinity()
25#elif V8_LIBC_MSVCRT
26# define V8_INFINITY HUGE_VAL
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000027#elif V8_OS_AIX
28#define V8_INFINITY (__builtin_inff())
Ben Murdochb8a8cc12014-11-26 15:28:44 +000029#else
30# define V8_INFINITY INFINITY
Ben Murdoch589d6972011-11-30 16:04:58 +000031#endif
32
Steve Blocka7e24c12009-10-30 11:49:00 +000033namespace v8 {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000034
35namespace base {
36class Mutex;
37class RecursiveMutex;
38class VirtualMemory;
39}
40
Steve Blocka7e24c12009-10-30 11:49:00 +000041namespace internal {
42
John Reck59135872010-11-02 12:39:01 -070043// Determine whether we are running in a simulated environment.
44// Setting USE_SIMULATOR explicitly from the build script will force
45// the use of a simulated environment.
46#if !defined(USE_SIMULATOR)
Ben Murdochb8a8cc12014-11-26 15:28:44 +000047#if (V8_TARGET_ARCH_ARM64 && !V8_HOST_ARCH_ARM64)
John Reck59135872010-11-02 12:39:01 -070048#define USE_SIMULATOR 1
49#endif
Ben Murdochb8a8cc12014-11-26 15:28:44 +000050#if (V8_TARGET_ARCH_ARM && !V8_HOST_ARCH_ARM)
51#define USE_SIMULATOR 1
52#endif
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000053#if (V8_TARGET_ARCH_PPC && !V8_HOST_ARCH_PPC)
54#define USE_SIMULATOR 1
55#endif
Ben Murdochb8a8cc12014-11-26 15:28:44 +000056#if (V8_TARGET_ARCH_MIPS && !V8_HOST_ARCH_MIPS)
57#define USE_SIMULATOR 1
58#endif
59#if (V8_TARGET_ARCH_MIPS64 && !V8_HOST_ARCH_MIPS64)
John Reck59135872010-11-02 12:39:01 -070060#define USE_SIMULATOR 1
61#endif
Ben Murdochda12d292016-06-02 14:46:10 +010062#if (V8_TARGET_ARCH_S390 && !V8_HOST_ARCH_S390)
63#define USE_SIMULATOR 1
64#endif
John Reck59135872010-11-02 12:39:01 -070065#endif
66
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000067// Determine whether the architecture uses an embedded constant pool
68// (contiguous constant pool embedded in code object).
69#if V8_TARGET_ARCH_PPC
70#define V8_EMBEDDED_CONSTANT_POOL 1
71#else
72#define V8_EMBEDDED_CONSTANT_POOL 0
73#endif
Ben Murdochb8a8cc12014-11-26 15:28:44 +000074
75#ifdef V8_TARGET_ARCH_ARM
76// Set stack limit lower for ARM than for other architectures because
77// stack allocating MacroAssembler takes 120K bytes.
78// See issue crbug.com/405338
79#define V8_DEFAULT_STACK_SIZE_KB 864
Steve Blocka7e24c12009-10-30 11:49:00 +000080#else
Ben Murdochb8a8cc12014-11-26 15:28:44 +000081// Slightly less than 1MB, since Windows' default stack size for
82// the main execution thread is 1MB for both 32 and 64-bit.
83#define V8_DEFAULT_STACK_SIZE_KB 984
Steve Blocka7e24c12009-10-30 11:49:00 +000084#endif
85
Ben Murdochb8a8cc12014-11-26 15:28:44 +000086
Emily Bernierd0a1eb72015-03-24 16:35:39 -040087// Determine whether double field unboxing feature is enabled.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000088#if V8_TARGET_ARCH_64_BIT
89#define V8_DOUBLE_FIELDS_UNBOXING 1
Emily Bernierd0a1eb72015-03-24 16:35:39 -040090#else
91#define V8_DOUBLE_FIELDS_UNBOXING 0
Steve Blocka7e24c12009-10-30 11:49:00 +000092#endif
93
Emily Bernierd0a1eb72015-03-24 16:35:39 -040094
Steve Blocka7e24c12009-10-30 11:49:00 +000095typedef uint8_t byte;
96typedef byte* Address;
97
Steve Blocka7e24c12009-10-30 11:49:00 +000098// -----------------------------------------------------------------------------
99// Constants
100
101const int KB = 1024;
102const int MB = KB * KB;
103const int GB = KB * KB * KB;
104const int kMaxInt = 0x7FFFFFFF;
105const int kMinInt = -kMaxInt - 1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000106const int kMaxInt8 = (1 << 7) - 1;
107const int kMinInt8 = -(1 << 7);
108const int kMaxUInt8 = (1 << 8) - 1;
109const int kMinUInt8 = 0;
110const int kMaxInt16 = (1 << 15) - 1;
111const int kMinInt16 = -(1 << 15);
112const int kMaxUInt16 = (1 << 16) - 1;
113const int kMinUInt16 = 0;
Steve Blocka7e24c12009-10-30 11:49:00 +0000114
115const uint32_t kMaxUInt32 = 0xFFFFFFFFu;
Ben Murdochda12d292016-06-02 14:46:10 +0100116const int kMinUInt32 = 0;
Steve Blocka7e24c12009-10-30 11:49:00 +0000117
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000118const int kCharSize = sizeof(char); // NOLINT
119const int kShortSize = sizeof(short); // NOLINT
120const int kIntSize = sizeof(int); // NOLINT
121const int kInt32Size = sizeof(int32_t); // NOLINT
122const int kInt64Size = sizeof(int64_t); // NOLINT
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000123const int kFloatSize = sizeof(float); // NOLINT
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000124const int kDoubleSize = sizeof(double); // NOLINT
125const int kIntptrSize = sizeof(intptr_t); // NOLINT
126const int kPointerSize = sizeof(void*); // NOLINT
127#if V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_32_BIT
128const int kRegisterSize = kPointerSize + kPointerSize;
129#else
130const int kRegisterSize = kPointerSize;
131#endif
132const int kPCOnStackSize = kRegisterSize;
133const int kFPOnStackSize = kRegisterSize;
Steve Blocka7e24c12009-10-30 11:49:00 +0000134
Ben Murdochda12d292016-06-02 14:46:10 +0100135#if V8_TARGET_ARCH_X64 || V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_X87
136const int kElidedFrameSlots = kPCOnStackSize / kPointerSize;
137#else
138const int kElidedFrameSlots = 0;
139#endif
140
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000141const int kDoubleSizeLog2 = 3;
142
Steve Blocka7e24c12009-10-30 11:49:00 +0000143#if V8_HOST_ARCH_64_BIT
144const int kPointerSizeLog2 = 3;
145const intptr_t kIntptrSignBit = V8_INT64_C(0x8000000000000000);
John Reck59135872010-11-02 12:39:01 -0700146const uintptr_t kUintptrAllBitsSet = V8_UINT64_C(0xFFFFFFFFFFFFFFFF);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000147const bool kRequiresCodeRange = true;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000148#if V8_TARGET_ARCH_MIPS64
149// To use pseudo-relative jumps such as j/jal instructions which have 28-bit
150// encoded immediate, the addresses have to be in range of 256MB aligned
151// region. Used only for large object space.
152const size_t kMaximalCodeRangeSize = 256 * MB;
Ben Murdoch61f157c2016-09-16 13:49:30 +0100153const size_t kCodeRangeAreaAlignment = 256 * MB;
154#elif V8_HOST_ARCH_PPC && V8_TARGET_ARCH_PPC && V8_OS_LINUX
155const size_t kMaximalCodeRangeSize = 512 * MB;
156const size_t kCodeRangeAreaAlignment = 64 * KB; // OS page on PPC Linux
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000157#else
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000158const size_t kMaximalCodeRangeSize = 512 * MB;
Ben Murdoch61f157c2016-09-16 13:49:30 +0100159const size_t kCodeRangeAreaAlignment = 4 * KB; // OS page.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000160#endif
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400161#if V8_OS_WIN
162const size_t kMinimumCodeRangeSize = 4 * MB;
163const size_t kReservedCodeRangePages = 1;
Ben Murdoch61f157c2016-09-16 13:49:30 +0100164// On PPC Linux PageSize is 4MB
165#elif V8_HOST_ARCH_PPC && V8_TARGET_ARCH_PPC && V8_OS_LINUX
166const size_t kMinimumCodeRangeSize = 12 * MB;
167const size_t kReservedCodeRangePages = 0;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400168#else
169const size_t kMinimumCodeRangeSize = 3 * MB;
170const size_t kReservedCodeRangePages = 0;
171#endif
Steve Blocka7e24c12009-10-30 11:49:00 +0000172#else
173const int kPointerSizeLog2 = 2;
174const intptr_t kIntptrSignBit = 0x80000000;
John Reck59135872010-11-02 12:39:01 -0700175const uintptr_t kUintptrAllBitsSet = 0xFFFFFFFFu;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000176#if V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_32_BIT
177// x32 port also requires code range.
178const bool kRequiresCodeRange = true;
179const size_t kMaximalCodeRangeSize = 256 * MB;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400180const size_t kMinimumCodeRangeSize = 3 * MB;
Ben Murdoch61f157c2016-09-16 13:49:30 +0100181const size_t kCodeRangeAreaAlignment = 4 * KB; // OS page.
182#elif V8_HOST_ARCH_PPC && V8_TARGET_ARCH_PPC && V8_OS_LINUX
183const bool kRequiresCodeRange = false;
184const size_t kMaximalCodeRangeSize = 0 * MB;
185const size_t kMinimumCodeRangeSize = 0 * MB;
186const size_t kCodeRangeAreaAlignment = 64 * KB; // OS page on PPC Linux
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000187#else
188const bool kRequiresCodeRange = false;
189const size_t kMaximalCodeRangeSize = 0 * MB;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400190const size_t kMinimumCodeRangeSize = 0 * MB;
Ben Murdoch61f157c2016-09-16 13:49:30 +0100191const size_t kCodeRangeAreaAlignment = 4 * KB; // OS page.
192#endif
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400193const size_t kReservedCodeRangePages = 0;
Steve Blocka7e24c12009-10-30 11:49:00 +0000194#endif
Ben Murdoch61f157c2016-09-16 13:49:30 +0100195
196// The external allocation limit should be below 256 MB on all architectures
197// to avoid that resource-constrained embedders run low on memory.
198const int kExternalAllocationLimit = 192 * 1024 * 1024;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000199
200STATIC_ASSERT(kPointerSize == (1 << kPointerSizeLog2));
Steve Blocka7e24c12009-10-30 11:49:00 +0000201
Steve Blocka7e24c12009-10-30 11:49:00 +0000202const int kBitsPerByte = 8;
203const int kBitsPerByteLog2 = 3;
204const int kBitsPerPointer = kPointerSize * kBitsPerByte;
205const int kBitsPerInt = kIntSize * kBitsPerByte;
206
Steve Block6ded16b2010-05-10 14:33:55 +0100207// IEEE 754 single precision floating point number bit layout.
208const uint32_t kBinary32SignMask = 0x80000000u;
209const uint32_t kBinary32ExponentMask = 0x7f800000u;
210const uint32_t kBinary32MantissaMask = 0x007fffffu;
211const int kBinary32ExponentBias = 127;
212const int kBinary32MaxExponent = 0xFE;
213const int kBinary32MinExponent = 0x01;
214const int kBinary32MantissaBits = 23;
215const int kBinary32ExponentShift = 23;
Steve Blocka7e24c12009-10-30 11:49:00 +0000216
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100217// Quiet NaNs have bits 51 to 62 set, possibly the sign bit, and no
218// other bits set.
219const uint64_t kQuietNaNMask = static_cast<uint64_t>(0xfff) << 51;
220
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000221// Latin1/UTF-16 constants
Steve Block9fac8402011-05-12 15:51:54 +0100222// Code-point values in Unicode 4.0 are 21 bits wide.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100223// Code units in UTF-16 are 16 bits wide.
Steve Block9fac8402011-05-12 15:51:54 +0100224typedef uint16_t uc16;
225typedef int32_t uc32;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000226const int kOneByteSize = kCharSize;
Steve Block9fac8402011-05-12 15:51:54 +0100227const int kUC16Size = sizeof(uc16); // NOLINT
Steve Block9fac8402011-05-12 15:51:54 +0100228
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000229// 128 bit SIMD value size.
230const int kSimd128Size = 16;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100231
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000232// Round up n to be a multiple of sz, where sz is a power of 2.
233#define ROUND_UP(n, sz) (((n) + ((sz) - 1)) & ~((sz) - 1))
Steve Blocka7e24c12009-10-30 11:49:00 +0000234
235
236// FUNCTION_ADDR(f) gets the address of a C function f.
237#define FUNCTION_ADDR(f) \
238 (reinterpret_cast<v8::internal::Address>(reinterpret_cast<intptr_t>(f)))
239
240
241// FUNCTION_CAST<F>(addr) casts an address into a function
242// of type F. Used to invoke generated code from within C.
243template <typename F>
244F FUNCTION_CAST(Address addr) {
245 return reinterpret_cast<F>(reinterpret_cast<intptr_t>(addr));
246}
247
248
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000249// Determine whether the architecture uses function descriptors
250// which provide a level of indirection between the function pointer
251// and the function entrypoint.
252#if V8_HOST_ARCH_PPC && \
253 (V8_OS_AIX || (V8_TARGET_ARCH_PPC64 && V8_TARGET_BIG_ENDIAN))
254#define USES_FUNCTION_DESCRIPTORS 1
255#define FUNCTION_ENTRYPOINT_ADDRESS(f) \
256 (reinterpret_cast<v8::internal::Address*>( \
257 &(reinterpret_cast<intptr_t*>(f)[0])))
258#else
259#define USES_FUNCTION_DESCRIPTORS 0
260#endif
261
262
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800263// -----------------------------------------------------------------------------
264// Forward declarations for frequently used classes
265// (sorted alphabetically)
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100266
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800267class FreeStoreAllocationPolicy;
268template <typename T, class P = FreeStoreAllocationPolicy> class List;
Steve Blockd0582a62009-12-15 09:54:21 +0000269
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100270// -----------------------------------------------------------------------------
271// Declarations for use in both the preparser and the rest of V8.
272
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100273// The Strict Mode (ECMA-262 5th edition, 4.2.2).
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000274
Ben Murdochda12d292016-06-02 14:46:10 +0100275enum LanguageMode { SLOPPY, STRICT, LANGUAGE_END = 3 };
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000276
277
278inline std::ostream& operator<<(std::ostream& os, const LanguageMode& mode) {
279 switch (mode) {
Ben Murdochda12d292016-06-02 14:46:10 +0100280 case SLOPPY: return os << "sloppy";
281 case STRICT: return os << "strict";
282 default: UNREACHABLE();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000283 }
Ben Murdochda12d292016-06-02 14:46:10 +0100284 return os;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000285}
286
287
288inline bool is_sloppy(LanguageMode language_mode) {
Ben Murdochda12d292016-06-02 14:46:10 +0100289 return language_mode == SLOPPY;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000290}
291
292
293inline bool is_strict(LanguageMode language_mode) {
Ben Murdochda12d292016-06-02 14:46:10 +0100294 return language_mode != SLOPPY;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000295}
296
297
298inline bool is_valid_language_mode(int language_mode) {
Ben Murdochda12d292016-06-02 14:46:10 +0100299 return language_mode == SLOPPY || language_mode == STRICT;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000300}
301
302
Ben Murdochda12d292016-06-02 14:46:10 +0100303inline LanguageMode construct_language_mode(bool strict_bit) {
304 return static_cast<LanguageMode>(strict_bit);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000305}
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000306
307
308// Mask for the sign bit in a smi.
309const intptr_t kSmiSignMask = kIntptrSignBit;
310
311const int kObjectAlignmentBits = kPointerSizeLog2;
312const intptr_t kObjectAlignment = 1 << kObjectAlignmentBits;
313const intptr_t kObjectAlignmentMask = kObjectAlignment - 1;
314
315// Desired alignment for pointers.
316const intptr_t kPointerAlignment = (1 << kPointerSizeLog2);
317const intptr_t kPointerAlignmentMask = kPointerAlignment - 1;
318
319// Desired alignment for double values.
320const intptr_t kDoubleAlignment = 8;
321const intptr_t kDoubleAlignmentMask = kDoubleAlignment - 1;
322
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000323// Desired alignment for 128 bit SIMD values.
324const intptr_t kSimd128Alignment = 16;
325const intptr_t kSimd128AlignmentMask = kSimd128Alignment - 1;
326
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000327// Desired alignment for generated code is 32 bytes (to improve cache line
328// utilization).
329const int kCodeAlignmentBits = 5;
330const intptr_t kCodeAlignment = 1 << kCodeAlignmentBits;
331const intptr_t kCodeAlignmentMask = kCodeAlignment - 1;
332
333// The owner field of a page is tagged with the page header tag. We need that
334// to find out if a slot is part of a large object. If we mask out the lower
335// 0xfffff bits (1M pages), go to the owner offset, and see that this field
336// is tagged with the page header tag, we can just look up the owner.
337// Otherwise, we know that we are somewhere (not within the first 1M) in a
338// large object.
339const int kPageHeaderTag = 3;
340const int kPageHeaderTagSize = 2;
341const intptr_t kPageHeaderTagMask = (1 << kPageHeaderTagSize) - 1;
342
343
344// Zap-value: The value used for zapping dead objects.
345// Should be a recognizable hex value tagged as a failure.
346#ifdef V8_HOST_ARCH_64_BIT
347const Address kZapValue =
348 reinterpret_cast<Address>(V8_UINT64_C(0xdeadbeedbeadbeef));
349const Address kHandleZapValue =
350 reinterpret_cast<Address>(V8_UINT64_C(0x1baddead0baddeaf));
351const Address kGlobalHandleZapValue =
352 reinterpret_cast<Address>(V8_UINT64_C(0x1baffed00baffedf));
353const Address kFromSpaceZapValue =
354 reinterpret_cast<Address>(V8_UINT64_C(0x1beefdad0beefdaf));
355const uint64_t kDebugZapValue = V8_UINT64_C(0xbadbaddbbadbaddb);
356const uint64_t kSlotsZapValue = V8_UINT64_C(0xbeefdeadbeefdeef);
357const uint64_t kFreeListZapValue = 0xfeed1eaffeed1eaf;
358#else
359const Address kZapValue = reinterpret_cast<Address>(0xdeadbeef);
360const Address kHandleZapValue = reinterpret_cast<Address>(0xbaddeaf);
361const Address kGlobalHandleZapValue = reinterpret_cast<Address>(0xbaffedf);
362const Address kFromSpaceZapValue = reinterpret_cast<Address>(0xbeefdaf);
363const uint32_t kSlotsZapValue = 0xbeefdeef;
364const uint32_t kDebugZapValue = 0xbadbaddb;
365const uint32_t kFreeListZapValue = 0xfeed1eaf;
366#endif
367
368const int kCodeZapValue = 0xbadc0de;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400369const uint32_t kPhantomReferenceZap = 0xca11bac;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000370
371// On Intel architecture, cache line size is 64 bytes.
372// On ARM it may be less (32 bytes), but as far this constant is
373// used for aligning data, it doesn't hurt to align on a greater value.
374#define PROCESSOR_CACHE_LINE_SIZE 64
375
376// Constants relevant to double precision floating point numbers.
377// If looking only at the top 32 bits, the QNaN mask is bits 19 to 30.
378const uint32_t kQuietNaNHighBitsMask = 0xfff << (51 - 32);
379
380
381// -----------------------------------------------------------------------------
382// Forward declarations for frequently used classes
383
384class AccessorInfo;
385class Allocation;
386class Arguments;
387class Assembler;
388class Code;
389class CodeGenerator;
390class CodeStub;
391class Context;
392class Debug;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000393class DebugInfo;
394class Descriptor;
395class DescriptorArray;
396class TransitionArray;
397class ExternalReference;
398class FixedArray;
399class FunctionTemplateInfo;
400class MemoryChunk;
401class SeededNumberDictionary;
402class UnseededNumberDictionary;
403class NameDictionary;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000404class GlobalDictionary;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000405template <typename T> class MaybeHandle;
406template <typename T> class Handle;
407class Heap;
408class HeapObject;
409class IC;
410class InterceptorInfo;
411class Isolate;
412class JSReceiver;
413class JSArray;
414class JSFunction;
415class JSObject;
416class LargeObjectSpace;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000417class MacroAssembler;
418class Map;
419class MapSpace;
420class MarkCompactCollector;
421class NewSpace;
422class Object;
423class OldSpace;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000424class ParameterCount;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000425class Foreign;
426class Scope;
427class ScopeInfo;
428class Script;
429class Smi;
430template <typename Config, class Allocator = FreeStoreAllocationPolicy>
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000431class SplayTree;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000432class String;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400433class Symbol;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000434class Name;
435class Struct;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000436class TypeFeedbackVector;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000437class Variable;
438class RelocInfo;
439class Deserializer;
440class MessageLocation;
441
442typedef bool (*WeakSlotCallback)(Object** pointer);
443
444typedef bool (*WeakSlotCallbackWithHeap)(Heap* heap, Object** pointer);
445
446// -----------------------------------------------------------------------------
447// Miscellaneous
448
449// NOTE: SpaceIterator depends on AllocationSpace enumeration values being
450// consecutive.
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400451// Keep this enum in sync with the ObjectSpace enum in v8.h
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000452enum AllocationSpace {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000453 NEW_SPACE, // Semispaces collected with copying collector.
454 OLD_SPACE, // May contain pointers to new space.
455 CODE_SPACE, // No pointers to new space, marked executable.
456 MAP_SPACE, // Only and all map objects.
457 LO_SPACE, // Promoted large objects.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000458
459 FIRST_SPACE = NEW_SPACE,
460 LAST_SPACE = LO_SPACE,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000461 FIRST_PAGED_SPACE = OLD_SPACE,
462 LAST_PAGED_SPACE = MAP_SPACE
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000463};
464const int kSpaceTagSize = 3;
465const int kSpaceTagMask = (1 << kSpaceTagSize) - 1;
466
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000467enum AllocationAlignment {
468 kWordAligned,
469 kDoubleAligned,
470 kDoubleUnaligned,
471 kSimd128Unaligned
472};
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000473
Ben Murdoch61f157c2016-09-16 13:49:30 +0100474// Possible outcomes for decisions.
475enum class Decision : uint8_t { kUnknown, kTrue, kFalse };
476
477inline size_t hash_value(Decision decision) {
478 return static_cast<uint8_t>(decision);
479}
480
481inline std::ostream& operator<<(std::ostream& os, Decision decision) {
482 switch (decision) {
483 case Decision::kUnknown:
484 return os << "Unknown";
485 case Decision::kTrue:
486 return os << "True";
487 case Decision::kFalse:
488 return os << "False";
489 }
490 UNREACHABLE();
491 return os;
492}
493
Ben Murdochc5610432016-08-08 18:44:38 +0100494// Supported write barrier modes.
495enum WriteBarrierKind : uint8_t {
496 kNoWriteBarrier,
497 kMapWriteBarrier,
498 kPointerWriteBarrier,
499 kFullWriteBarrier
500};
501
502inline size_t hash_value(WriteBarrierKind kind) {
503 return static_cast<uint8_t>(kind);
504}
505
506inline std::ostream& operator<<(std::ostream& os, WriteBarrierKind kind) {
507 switch (kind) {
508 case kNoWriteBarrier:
509 return os << "NoWriteBarrier";
510 case kMapWriteBarrier:
511 return os << "MapWriteBarrier";
512 case kPointerWriteBarrier:
513 return os << "PointerWriteBarrier";
514 case kFullWriteBarrier:
515 return os << "FullWriteBarrier";
516 }
517 UNREACHABLE();
518 return os;
519}
520
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000521// A flag that indicates whether objects should be pretenured when
522// allocated (allocated directly into the old generation) or not
523// (allocated in the young generation if the object size and type
524// allows).
525enum PretenureFlag { NOT_TENURED, TENURED };
526
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000527inline std::ostream& operator<<(std::ostream& os, const PretenureFlag& flag) {
528 switch (flag) {
529 case NOT_TENURED:
530 return os << "NotTenured";
531 case TENURED:
532 return os << "Tenured";
533 }
534 UNREACHABLE();
535 return os;
536}
537
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000538enum MinimumCapacity {
539 USE_DEFAULT_MINIMUM_CAPACITY,
540 USE_CUSTOM_MINIMUM_CAPACITY
541};
542
543enum GarbageCollector { SCAVENGER, MARK_COMPACTOR };
544
545enum Executability { NOT_EXECUTABLE, EXECUTABLE };
546
547enum VisitMode {
548 VISIT_ALL,
549 VISIT_ALL_IN_SCAVENGE,
550 VISIT_ALL_IN_SWEEP_NEWSPACE,
Ben Murdochda12d292016-06-02 14:46:10 +0100551 VISIT_ONLY_STRONG,
552 VISIT_ONLY_STRONG_FOR_SERIALIZATION,
553 VISIT_ONLY_STRONG_ROOT_LIST,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000554};
555
556// Flag indicating whether code is built into the VM (one of the natives files).
Ben Murdoch097c5b22016-05-18 11:27:45 +0100557enum NativesFlag { NOT_NATIVES_CODE, EXTENSION_CODE, NATIVES_CODE };
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000558
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000559// JavaScript defines two kinds of 'nil'.
560enum NilValue { kNullValue, kUndefinedValue };
561
562// ParseRestriction is used to restrict the set of valid statements in a
563// unit of compilation. Restriction violations cause a syntax error.
564enum ParseRestriction {
565 NO_PARSE_RESTRICTION, // All expressions are allowed.
566 ONLY_SINGLE_FUNCTION_LITERAL // Only a single FunctionLiteral expression.
567};
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000568
569// A CodeDesc describes a buffer holding instructions and relocation
570// information. The instructions start at the beginning of the buffer
571// and grow forward, the relocation information starts at the end of
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000572// the buffer and grows backward. A constant pool may exist at the
573// end of the instructions.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100574//
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000575// |<--------------- buffer_size ----------------------------------->|
576// |<------------- instr_size ---------->| |<-- reloc_size -->|
577// | |<- const_pool_size ->| |
578// +=====================================+========+==================+
579// | instructions | data | free | reloc info |
580// +=====================================+========+==================+
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000581// ^
582// |
583// buffer
584
585struct CodeDesc {
586 byte* buffer;
587 int buffer_size;
588 int instr_size;
589 int reloc_size;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000590 int constant_pool_size;
Ben Murdoch61f157c2016-09-16 13:49:30 +0100591 byte* unwinding_info;
592 int unwinding_info_size;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000593 Assembler* origin;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100594};
595
596
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000597// Callback function used for checking constraints when copying/relocating
598// objects. Returns true if an object can be copied/relocated from its
599// old_addr to a new_addr.
600typedef bool (*ConstraintCallback)(Address new_addr, Address old_addr);
601
602
603// Callback function on inline caches, used for iterating over inline caches
604// in compiled code.
605typedef void (*InlineCacheCallback)(Code* code, Address ic);
606
607
608// State for inline cache call sites. Aliased as IC::State.
609enum InlineCacheState {
610 // Has never been executed.
611 UNINITIALIZED,
612 // Has been executed but monomorhic state has been delayed.
613 PREMONOMORPHIC,
614 // Has been executed and only one receiver type has been seen.
615 MONOMORPHIC,
616 // Check failed due to prototype (or map deprecation).
Ben Murdochc5610432016-08-08 18:44:38 +0100617 RECOMPUTE_HANDLER,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000618 // Multiple receiver types have been seen.
619 POLYMORPHIC,
620 // Many receiver types have been seen.
621 MEGAMORPHIC,
622 // A generic handler is installed and no extra typefeedback is recorded.
623 GENERIC,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000624};
625
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000626enum CacheHolderFlag {
627 kCacheOnPrototype,
628 kCacheOnPrototypeReceiverIsDictionary,
629 kCacheOnPrototypeReceiverIsPrimitive,
630 kCacheOnReceiver
631};
632
Ben Murdoch61f157c2016-09-16 13:49:30 +0100633enum WhereToStart { kStartAtReceiver, kStartAtPrototype };
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000634
635// The Store Buffer (GC).
636typedef enum {
637 kStoreBufferFullEvent,
638 kStoreBufferStartScanningPagesEvent,
639 kStoreBufferScanningPageEvent
640} StoreBufferEvent;
641
642
643typedef void (*StoreBufferCallback)(Heap* heap,
644 MemoryChunk* page,
645 StoreBufferEvent event);
646
647
648// Union used for fast testing of specific double values.
649union DoubleRepresentation {
650 double value;
651 int64_t bits;
652 DoubleRepresentation(double x) { value = x; }
653 bool operator==(const DoubleRepresentation& other) const {
654 return bits == other.bits;
655 }
656};
657
658
659// Union used for customized checking of the IEEE double types
660// inlined within v8 runtime, rather than going to the underlying
661// platform headers and libraries
662union IeeeDoubleLittleEndianArchType {
663 double d;
664 struct {
665 unsigned int man_low :32;
666 unsigned int man_high :20;
667 unsigned int exp :11;
668 unsigned int sign :1;
669 } bits;
670};
671
672
673union IeeeDoubleBigEndianArchType {
674 double d;
675 struct {
676 unsigned int sign :1;
677 unsigned int exp :11;
678 unsigned int man_high :20;
679 unsigned int man_low :32;
680 } bits;
681};
682
Ben Murdoch61f157c2016-09-16 13:49:30 +0100683#if V8_TARGET_LITTLE_ENDIAN
684typedef IeeeDoubleLittleEndianArchType IeeeDoubleArchType;
685const int kIeeeDoubleMantissaWordOffset = 0;
686const int kIeeeDoubleExponentWordOffset = 4;
687#else
688typedef IeeeDoubleBigEndianArchType IeeeDoubleArchType;
689const int kIeeeDoubleMantissaWordOffset = 4;
690const int kIeeeDoubleExponentWordOffset = 0;
691#endif
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000692
693// AccessorCallback
694struct AccessorDescriptor {
695 Object* (*getter)(Isolate* isolate, Object* object, void* data);
696 Object* (*setter)(
697 Isolate* isolate, JSObject* object, Object* value, void* data);
698 void* data;
699};
700
701
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000702// -----------------------------------------------------------------------------
703// Macros
704
705// Testers for test.
706
707#define HAS_SMI_TAG(value) \
708 ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag)
709
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000710// OBJECT_POINTER_ALIGN returns the value aligned as a HeapObject pointer
711#define OBJECT_POINTER_ALIGN(value) \
712 (((value) + kObjectAlignmentMask) & ~kObjectAlignmentMask)
713
714// POINTER_SIZE_ALIGN returns the value aligned as a pointer.
715#define POINTER_SIZE_ALIGN(value) \
716 (((value) + kPointerAlignmentMask) & ~kPointerAlignmentMask)
717
718// CODE_POINTER_ALIGN returns the value aligned as a generated code segment.
719#define CODE_POINTER_ALIGN(value) \
720 (((value) + kCodeAlignmentMask) & ~kCodeAlignmentMask)
721
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000722// DOUBLE_POINTER_ALIGN returns the value algined for double pointers.
723#define DOUBLE_POINTER_ALIGN(value) \
724 (((value) + kDoubleAlignmentMask) & ~kDoubleAlignmentMask)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000725
726
727// CPU feature flags.
728enum CpuFeature {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400729 // x86
730 SSE4_1,
731 SSE3,
732 SAHF,
733 AVX,
734 FMA3,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000735 BMI1,
736 BMI2,
737 LZCNT,
738 POPCNT,
739 ATOM,
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400740 // ARM
741 VFP3,
742 ARMv7,
743 ARMv8,
744 SUDIV,
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400745 UNALIGNED_ACCESSES,
746 MOVW_MOVT_IMMEDIATE_LOADS,
747 VFP32DREGS,
748 NEON,
749 // MIPS, MIPS64
750 FPU,
751 FP64FPU,
752 MIPSr1,
753 MIPSr2,
754 MIPSr6,
755 // ARM64
756 ALWAYS_ALIGN_CSP,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000757 // PPC
758 FPR_GPR_MOV,
759 LWSYNC,
760 ISELECT,
Ben Murdochda12d292016-06-02 14:46:10 +0100761 // S390
762 DISTINCT_OPS,
763 GENERAL_INSTR_EXT,
764 FLOATING_POINT_EXT,
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400765 NUMBER_OF_CPU_FEATURES
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000766};
767
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000768// Defines hints about receiver values based on structural knowledge.
769enum class ConvertReceiverMode : unsigned {
770 kNullOrUndefined, // Guaranteed to be null or undefined.
771 kNotNullOrUndefined, // Guaranteed to never be null or undefined.
772 kAny // No specific knowledge about receiver.
773};
774
775inline size_t hash_value(ConvertReceiverMode mode) {
776 return bit_cast<unsigned>(mode);
777}
778
779inline std::ostream& operator<<(std::ostream& os, ConvertReceiverMode mode) {
780 switch (mode) {
781 case ConvertReceiverMode::kNullOrUndefined:
782 return os << "NULL_OR_UNDEFINED";
783 case ConvertReceiverMode::kNotNullOrUndefined:
784 return os << "NOT_NULL_OR_UNDEFINED";
785 case ConvertReceiverMode::kAny:
786 return os << "ANY";
787 }
788 UNREACHABLE();
789 return os;
790}
791
Ben Murdoch097c5b22016-05-18 11:27:45 +0100792// Defines whether tail call optimization is allowed.
793enum class TailCallMode : unsigned { kAllow, kDisallow };
794
795inline size_t hash_value(TailCallMode mode) { return bit_cast<unsigned>(mode); }
796
797inline std::ostream& operator<<(std::ostream& os, TailCallMode mode) {
798 switch (mode) {
799 case TailCallMode::kAllow:
800 return os << "ALLOW_TAIL_CALLS";
801 case TailCallMode::kDisallow:
802 return os << "DISALLOW_TAIL_CALLS";
803 }
804 UNREACHABLE();
805 return os;
806}
807
808// Defines specifics about arguments object or rest parameter creation.
809enum class CreateArgumentsType : uint8_t {
810 kMappedArguments,
811 kUnmappedArguments,
812 kRestParameter
813};
814
815inline size_t hash_value(CreateArgumentsType type) {
816 return bit_cast<uint8_t>(type);
817}
818
819inline std::ostream& operator<<(std::ostream& os, CreateArgumentsType type) {
820 switch (type) {
821 case CreateArgumentsType::kMappedArguments:
822 return os << "MAPPED_ARGUMENTS";
823 case CreateArgumentsType::kUnmappedArguments:
824 return os << "UNMAPPED_ARGUMENTS";
825 case CreateArgumentsType::kRestParameter:
826 return os << "REST_PARAMETER";
827 }
828 UNREACHABLE();
829 return os;
830}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000831
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000832// Used to specify if a macro instruction must perform a smi check on tagged
833// values.
834enum SmiCheckType {
835 DONT_DO_SMI_CHECK,
836 DO_SMI_CHECK
837};
838
839
840enum ScopeType {
841 EVAL_SCOPE, // The top-level scope for an eval source.
842 FUNCTION_SCOPE, // The top-level scope for a function.
843 MODULE_SCOPE, // The scope introduced by a module literal
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400844 SCRIPT_SCOPE, // The top-level scope for a script or a top-level eval.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000845 CATCH_SCOPE, // The scope introduced by catch.
846 BLOCK_SCOPE, // The scope introduced by a new block.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000847 WITH_SCOPE // The scope introduced by with.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000848};
849
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000850// The mips architecture prior to revision 5 has inverted encoding for sNaN.
Ben Murdoch61f157c2016-09-16 13:49:30 +0100851// The x87 FPU convert the sNaN to qNaN automatically when loading sNaN from
852// memmory.
853// Use mips sNaN which is a not used qNaN in x87 port as sNaN to workaround this
854// issue
855// for some test cases.
856#if (V8_TARGET_ARCH_MIPS && !defined(_MIPS_ARCH_MIPS32R6)) || \
857 (V8_TARGET_ARCH_MIPS64 && !defined(_MIPS_ARCH_MIPS64R6)) || \
858 (V8_TARGET_ARCH_X87)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000859const uint32_t kHoleNanUpper32 = 0xFFFF7FFF;
860const uint32_t kHoleNanLower32 = 0xFFFF7FFF;
861#else
862const uint32_t kHoleNanUpper32 = 0xFFF7FFFF;
863const uint32_t kHoleNanLower32 = 0xFFF7FFFF;
864#endif
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000865
866const uint64_t kHoleNanInt64 =
867 (static_cast<uint64_t>(kHoleNanUpper32) << 32) | kHoleNanLower32;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000868
869
870// ES6 section 20.1.2.6 Number.MAX_SAFE_INTEGER
871const double kMaxSafeInteger = 9007199254740991.0; // 2^53-1
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000872
873
874// The order of this enum has to be kept in sync with the predicates below.
875enum VariableMode {
876 // User declared variables:
Ben Murdochc5610432016-08-08 18:44:38 +0100877 VAR, // declared via 'var', and 'function' declarations
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000878
Ben Murdochc5610432016-08-08 18:44:38 +0100879 CONST_LEGACY, // declared via legacy 'const' declarations
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000880
Ben Murdochc5610432016-08-08 18:44:38 +0100881 LET, // declared via 'let' declarations (first lexical)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000882
Ben Murdochc5610432016-08-08 18:44:38 +0100883 CONST, // declared via 'const' declarations (last lexical)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000884
885 // Variables introduced by the compiler:
Ben Murdochc5610432016-08-08 18:44:38 +0100886 TEMPORARY, // temporary variables (not user-visible), stack-allocated
887 // unless the scope as a whole has forced context allocation
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000888
Ben Murdochc5610432016-08-08 18:44:38 +0100889 DYNAMIC, // always require dynamic lookup (we don't know
890 // the declaration)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000891
892 DYNAMIC_GLOBAL, // requires dynamic lookup, but we know that the
893 // variable is global unless it has been shadowed
894 // by an eval-introduced variable
895
Ben Murdochc5610432016-08-08 18:44:38 +0100896 DYNAMIC_LOCAL // requires dynamic lookup, but we know that the
897 // variable is local and where it is unless it
898 // has been shadowed by an eval-introduced
899 // variable
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000900};
901
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000902inline bool IsDynamicVariableMode(VariableMode mode) {
903 return mode >= DYNAMIC && mode <= DYNAMIC_LOCAL;
904}
905
906
907inline bool IsDeclaredVariableMode(VariableMode mode) {
Ben Murdochc5610432016-08-08 18:44:38 +0100908 return mode >= VAR && mode <= CONST;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000909}
910
911
912inline bool IsLexicalVariableMode(VariableMode mode) {
Ben Murdochc5610432016-08-08 18:44:38 +0100913 return mode >= LET && mode <= CONST;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000914}
915
916
917inline bool IsImmutableVariableMode(VariableMode mode) {
Ben Murdochc5610432016-08-08 18:44:38 +0100918 return mode == CONST || mode == CONST_LEGACY;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000919}
920
921
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000922enum class VariableLocation {
923 // Before and during variable allocation, a variable whose location is
924 // not yet determined. After allocation, a variable looked up as a
925 // property on the global object (and possibly absent). name() is the
926 // variable name, index() is invalid.
927 UNALLOCATED,
928
929 // A slot in the parameter section on the stack. index() is the
930 // parameter index, counting left-to-right. The receiver is index -1;
931 // the first parameter is index 0.
932 PARAMETER,
933
934 // A slot in the local section on the stack. index() is the variable
935 // index in the stack frame, starting at 0.
936 LOCAL,
937
938 // An indexed slot in a heap context. index() is the variable index in
939 // the context object on the heap, starting at 0. scope() is the
940 // corresponding scope.
941 CONTEXT,
942
943 // An indexed slot in a script context that contains a respective global
944 // property cell. name() is the variable name, index() is the variable
945 // index in the context object on the heap, starting at 0. scope() is the
946 // corresponding script scope.
947 GLOBAL,
948
949 // A named slot in a heap context. name() is the variable name in the
950 // context object on the heap, with lookup starting at the current
951 // context. index() is invalid.
952 LOOKUP
953};
954
955
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000956// ES6 Draft Rev3 10.2 specifies declarative environment records with mutable
957// and immutable bindings that can be in two states: initialized and
958// uninitialized. In ES5 only immutable bindings have these two states. When
959// accessing a binding, it needs to be checked for initialization. However in
960// the following cases the binding is initialized immediately after creation
961// so the initialization check can always be skipped:
962// 1. Var declared local variables.
963// var foo;
964// 2. A local variable introduced by a function declaration.
965// function foo() {}
966// 3. Parameters
967// function x(foo) {}
968// 4. Catch bound variables.
969// try {} catch (foo) {}
970// 6. Function variables of named function expressions.
971// var x = function foo() {}
972// 7. Implicit binding of 'this'.
973// 8. Implicit binding of 'arguments' in functions.
974//
975// ES5 specified object environment records which are introduced by ES elements
976// such as Program and WithStatement that associate identifier bindings with the
977// properties of some object. In the specification only mutable bindings exist
978// (which may be non-writable) and have no distinct initialization step. However
979// V8 allows const declarations in global code with distinct creation and
980// initialization steps which are represented by non-writable properties in the
981// global object. As a result also these bindings need to be checked for
982// initialization.
983//
984// The following enum specifies a flag that indicates if the binding needs a
985// distinct initialization step (kNeedsInitialization) or if the binding is
986// immediately initialized upon creation (kCreatedInitialized).
987enum InitializationFlag {
988 kNeedsInitialization,
989 kCreatedInitialized
990};
991
992
993enum MaybeAssignedFlag { kNotAssigned, kMaybeAssigned };
994
995
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000996// Serialized in PreparseData, so numeric values should not be changed.
997enum ParseErrorType { kSyntaxError = 0, kReferenceError = 1 };
998
999
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001000enum MinusZeroMode {
1001 TREAT_MINUS_ZERO_AS_ZERO,
1002 FAIL_ON_MINUS_ZERO
1003};
1004
1005
1006enum Signedness { kSigned, kUnsigned };
1007
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001008enum FunctionKind {
1009 kNormalFunction = 0,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001010 kArrowFunction = 1 << 0,
1011 kGeneratorFunction = 1 << 1,
1012 kConciseMethod = 1 << 2,
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001013 kConciseGeneratorMethod = kGeneratorFunction | kConciseMethod,
Ben Murdoch097c5b22016-05-18 11:27:45 +01001014 kDefaultConstructor = 1 << 3,
1015 kSubclassConstructor = 1 << 4,
1016 kBaseConstructor = 1 << 5,
1017 kGetterFunction = 1 << 6,
1018 kSetterFunction = 1 << 7,
Ben Murdochc5610432016-08-08 18:44:38 +01001019 kAsyncFunction = 1 << 8,
Ben Murdoch097c5b22016-05-18 11:27:45 +01001020 kAccessorFunction = kGetterFunction | kSetterFunction,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001021 kDefaultBaseConstructor = kDefaultConstructor | kBaseConstructor,
1022 kDefaultSubclassConstructor = kDefaultConstructor | kSubclassConstructor,
1023 kClassConstructor =
1024 kBaseConstructor | kSubclassConstructor | kDefaultConstructor,
Ben Murdochc5610432016-08-08 18:44:38 +01001025 kAsyncArrowFunction = kArrowFunction | kAsyncFunction,
1026 kAsyncConciseMethod = kAsyncFunction | kConciseMethod
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001027};
1028
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001029inline bool IsValidFunctionKind(FunctionKind kind) {
1030 return kind == FunctionKind::kNormalFunction ||
1031 kind == FunctionKind::kArrowFunction ||
1032 kind == FunctionKind::kGeneratorFunction ||
1033 kind == FunctionKind::kConciseMethod ||
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001034 kind == FunctionKind::kConciseGeneratorMethod ||
Ben Murdoch097c5b22016-05-18 11:27:45 +01001035 kind == FunctionKind::kGetterFunction ||
1036 kind == FunctionKind::kSetterFunction ||
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001037 kind == FunctionKind::kAccessorFunction ||
1038 kind == FunctionKind::kDefaultBaseConstructor ||
1039 kind == FunctionKind::kDefaultSubclassConstructor ||
1040 kind == FunctionKind::kBaseConstructor ||
Ben Murdochc5610432016-08-08 18:44:38 +01001041 kind == FunctionKind::kSubclassConstructor ||
1042 kind == FunctionKind::kAsyncFunction ||
1043 kind == FunctionKind::kAsyncArrowFunction ||
1044 kind == FunctionKind::kAsyncConciseMethod;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001045}
1046
1047
1048inline bool IsArrowFunction(FunctionKind kind) {
1049 DCHECK(IsValidFunctionKind(kind));
1050 return kind & FunctionKind::kArrowFunction;
1051}
1052
1053
1054inline bool IsGeneratorFunction(FunctionKind kind) {
1055 DCHECK(IsValidFunctionKind(kind));
1056 return kind & FunctionKind::kGeneratorFunction;
1057}
1058
Ben Murdochc5610432016-08-08 18:44:38 +01001059inline bool IsAsyncFunction(FunctionKind kind) {
1060 DCHECK(IsValidFunctionKind(kind));
1061 return kind & FunctionKind::kAsyncFunction;
1062}
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001063
Ben Murdoch61f157c2016-09-16 13:49:30 +01001064inline bool IsResumableFunction(FunctionKind kind) {
1065 return IsGeneratorFunction(kind) || IsAsyncFunction(kind);
1066}
1067
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001068inline bool IsConciseMethod(FunctionKind kind) {
1069 DCHECK(IsValidFunctionKind(kind));
1070 return kind & FunctionKind::kConciseMethod;
1071}
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001072
Ben Murdoch097c5b22016-05-18 11:27:45 +01001073inline bool IsGetterFunction(FunctionKind kind) {
1074 DCHECK(IsValidFunctionKind(kind));
1075 return kind & FunctionKind::kGetterFunction;
1076}
1077
1078inline bool IsSetterFunction(FunctionKind kind) {
1079 DCHECK(IsValidFunctionKind(kind));
1080 return kind & FunctionKind::kSetterFunction;
1081}
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001082
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001083inline bool IsAccessorFunction(FunctionKind kind) {
1084 DCHECK(IsValidFunctionKind(kind));
1085 return kind & FunctionKind::kAccessorFunction;
1086}
1087
1088
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001089inline bool IsDefaultConstructor(FunctionKind kind) {
1090 DCHECK(IsValidFunctionKind(kind));
1091 return kind & FunctionKind::kDefaultConstructor;
1092}
1093
1094
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001095inline bool IsBaseConstructor(FunctionKind kind) {
1096 DCHECK(IsValidFunctionKind(kind));
1097 return kind & FunctionKind::kBaseConstructor;
1098}
1099
1100
1101inline bool IsSubclassConstructor(FunctionKind kind) {
1102 DCHECK(IsValidFunctionKind(kind));
1103 return kind & FunctionKind::kSubclassConstructor;
1104}
1105
1106
1107inline bool IsClassConstructor(FunctionKind kind) {
1108 DCHECK(IsValidFunctionKind(kind));
1109 return kind & FunctionKind::kClassConstructor;
1110}
1111
1112
1113inline bool IsConstructable(FunctionKind kind, LanguageMode mode) {
1114 if (IsAccessorFunction(kind)) return false;
Ben Murdoch097c5b22016-05-18 11:27:45 +01001115 if (IsConciseMethod(kind)) return false;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001116 if (IsArrowFunction(kind)) return false;
Ben Murdoch097c5b22016-05-18 11:27:45 +01001117 if (IsGeneratorFunction(kind)) return false;
Ben Murdochc5610432016-08-08 18:44:38 +01001118 if (IsAsyncFunction(kind)) return false;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001119 return true;
1120}
1121
1122
Ben Murdoch097c5b22016-05-18 11:27:45 +01001123inline uint32_t ObjectHash(Address address) {
1124 // All objects are at least pointer aligned, so we can remove the trailing
1125 // zeros.
1126 return static_cast<uint32_t>(bit_cast<uintptr_t>(address) >>
1127 kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001128}
1129
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001130} // namespace internal
1131} // namespace v8
Steve Blocka7e24c12009-10-30 11:49:00 +00001132
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001133namespace i = v8::internal;
1134
Steve Blocka7e24c12009-10-30 11:49:00 +00001135#endif // V8_GLOBALS_H_