blob: ed297e745d7fe6a11e4810ab70d52fe6c9ac24bf [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;
153#else
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000154const size_t kMaximalCodeRangeSize = 512 * MB;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000155#endif
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400156#if V8_OS_WIN
157const size_t kMinimumCodeRangeSize = 4 * MB;
158const size_t kReservedCodeRangePages = 1;
159#else
160const size_t kMinimumCodeRangeSize = 3 * MB;
161const size_t kReservedCodeRangePages = 0;
162#endif
Steve Blocka7e24c12009-10-30 11:49:00 +0000163#else
164const int kPointerSizeLog2 = 2;
165const intptr_t kIntptrSignBit = 0x80000000;
John Reck59135872010-11-02 12:39:01 -0700166const uintptr_t kUintptrAllBitsSet = 0xFFFFFFFFu;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000167#if V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_32_BIT
168// x32 port also requires code range.
169const bool kRequiresCodeRange = true;
170const size_t kMaximalCodeRangeSize = 256 * MB;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400171const size_t kMinimumCodeRangeSize = 3 * MB;
172const size_t kReservedCodeRangePages = 0;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000173#else
174const bool kRequiresCodeRange = false;
175const size_t kMaximalCodeRangeSize = 0 * MB;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400176const size_t kMinimumCodeRangeSize = 0 * MB;
177const size_t kReservedCodeRangePages = 0;
Steve Blocka7e24c12009-10-30 11:49:00 +0000178#endif
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000179#endif
180
181STATIC_ASSERT(kPointerSize == (1 << kPointerSizeLog2));
Steve Blocka7e24c12009-10-30 11:49:00 +0000182
Steve Blocka7e24c12009-10-30 11:49:00 +0000183const int kBitsPerByte = 8;
184const int kBitsPerByteLog2 = 3;
185const int kBitsPerPointer = kPointerSize * kBitsPerByte;
186const int kBitsPerInt = kIntSize * kBitsPerByte;
187
Steve Block6ded16b2010-05-10 14:33:55 +0100188// IEEE 754 single precision floating point number bit layout.
189const uint32_t kBinary32SignMask = 0x80000000u;
190const uint32_t kBinary32ExponentMask = 0x7f800000u;
191const uint32_t kBinary32MantissaMask = 0x007fffffu;
192const int kBinary32ExponentBias = 127;
193const int kBinary32MaxExponent = 0xFE;
194const int kBinary32MinExponent = 0x01;
195const int kBinary32MantissaBits = 23;
196const int kBinary32ExponentShift = 23;
Steve Blocka7e24c12009-10-30 11:49:00 +0000197
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100198// Quiet NaNs have bits 51 to 62 set, possibly the sign bit, and no
199// other bits set.
200const uint64_t kQuietNaNMask = static_cast<uint64_t>(0xfff) << 51;
201
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000202// Latin1/UTF-16 constants
Steve Block9fac8402011-05-12 15:51:54 +0100203// Code-point values in Unicode 4.0 are 21 bits wide.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100204// Code units in UTF-16 are 16 bits wide.
Steve Block9fac8402011-05-12 15:51:54 +0100205typedef uint16_t uc16;
206typedef int32_t uc32;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000207const int kOneByteSize = kCharSize;
Steve Block9fac8402011-05-12 15:51:54 +0100208const int kUC16Size = sizeof(uc16); // NOLINT
Steve Block9fac8402011-05-12 15:51:54 +0100209
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000210// 128 bit SIMD value size.
211const int kSimd128Size = 16;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100212
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000213// Round up n to be a multiple of sz, where sz is a power of 2.
214#define ROUND_UP(n, sz) (((n) + ((sz) - 1)) & ~((sz) - 1))
Steve Blocka7e24c12009-10-30 11:49:00 +0000215
216
217// FUNCTION_ADDR(f) gets the address of a C function f.
218#define FUNCTION_ADDR(f) \
219 (reinterpret_cast<v8::internal::Address>(reinterpret_cast<intptr_t>(f)))
220
221
222// FUNCTION_CAST<F>(addr) casts an address into a function
223// of type F. Used to invoke generated code from within C.
224template <typename F>
225F FUNCTION_CAST(Address addr) {
226 return reinterpret_cast<F>(reinterpret_cast<intptr_t>(addr));
227}
228
229
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000230// Determine whether the architecture uses function descriptors
231// which provide a level of indirection between the function pointer
232// and the function entrypoint.
233#if V8_HOST_ARCH_PPC && \
234 (V8_OS_AIX || (V8_TARGET_ARCH_PPC64 && V8_TARGET_BIG_ENDIAN))
235#define USES_FUNCTION_DESCRIPTORS 1
236#define FUNCTION_ENTRYPOINT_ADDRESS(f) \
237 (reinterpret_cast<v8::internal::Address*>( \
238 &(reinterpret_cast<intptr_t*>(f)[0])))
239#else
240#define USES_FUNCTION_DESCRIPTORS 0
241#endif
242
243
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800244// -----------------------------------------------------------------------------
245// Forward declarations for frequently used classes
246// (sorted alphabetically)
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100247
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800248class FreeStoreAllocationPolicy;
249template <typename T, class P = FreeStoreAllocationPolicy> class List;
Steve Blockd0582a62009-12-15 09:54:21 +0000250
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100251// -----------------------------------------------------------------------------
252// Declarations for use in both the preparser and the rest of V8.
253
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100254// The Strict Mode (ECMA-262 5th edition, 4.2.2).
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000255
Ben Murdochda12d292016-06-02 14:46:10 +0100256enum LanguageMode { SLOPPY, STRICT, LANGUAGE_END = 3 };
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000257
258
259inline std::ostream& operator<<(std::ostream& os, const LanguageMode& mode) {
260 switch (mode) {
Ben Murdochda12d292016-06-02 14:46:10 +0100261 case SLOPPY: return os << "sloppy";
262 case STRICT: return os << "strict";
263 default: UNREACHABLE();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000264 }
Ben Murdochda12d292016-06-02 14:46:10 +0100265 return os;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000266}
267
268
269inline bool is_sloppy(LanguageMode language_mode) {
Ben Murdochda12d292016-06-02 14:46:10 +0100270 return language_mode == SLOPPY;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000271}
272
273
274inline bool is_strict(LanguageMode language_mode) {
Ben Murdochda12d292016-06-02 14:46:10 +0100275 return language_mode != SLOPPY;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000276}
277
278
279inline bool is_valid_language_mode(int language_mode) {
Ben Murdochda12d292016-06-02 14:46:10 +0100280 return language_mode == SLOPPY || language_mode == STRICT;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000281}
282
283
Ben Murdochda12d292016-06-02 14:46:10 +0100284inline LanguageMode construct_language_mode(bool strict_bit) {
285 return static_cast<LanguageMode>(strict_bit);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000286}
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000287
288
289// Mask for the sign bit in a smi.
290const intptr_t kSmiSignMask = kIntptrSignBit;
291
292const int kObjectAlignmentBits = kPointerSizeLog2;
293const intptr_t kObjectAlignment = 1 << kObjectAlignmentBits;
294const intptr_t kObjectAlignmentMask = kObjectAlignment - 1;
295
296// Desired alignment for pointers.
297const intptr_t kPointerAlignment = (1 << kPointerSizeLog2);
298const intptr_t kPointerAlignmentMask = kPointerAlignment - 1;
299
300// Desired alignment for double values.
301const intptr_t kDoubleAlignment = 8;
302const intptr_t kDoubleAlignmentMask = kDoubleAlignment - 1;
303
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000304// Desired alignment for 128 bit SIMD values.
305const intptr_t kSimd128Alignment = 16;
306const intptr_t kSimd128AlignmentMask = kSimd128Alignment - 1;
307
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000308// Desired alignment for generated code is 32 bytes (to improve cache line
309// utilization).
310const int kCodeAlignmentBits = 5;
311const intptr_t kCodeAlignment = 1 << kCodeAlignmentBits;
312const intptr_t kCodeAlignmentMask = kCodeAlignment - 1;
313
314// The owner field of a page is tagged with the page header tag. We need that
315// to find out if a slot is part of a large object. If we mask out the lower
316// 0xfffff bits (1M pages), go to the owner offset, and see that this field
317// is tagged with the page header tag, we can just look up the owner.
318// Otherwise, we know that we are somewhere (not within the first 1M) in a
319// large object.
320const int kPageHeaderTag = 3;
321const int kPageHeaderTagSize = 2;
322const intptr_t kPageHeaderTagMask = (1 << kPageHeaderTagSize) - 1;
323
324
325// Zap-value: The value used for zapping dead objects.
326// Should be a recognizable hex value tagged as a failure.
327#ifdef V8_HOST_ARCH_64_BIT
328const Address kZapValue =
329 reinterpret_cast<Address>(V8_UINT64_C(0xdeadbeedbeadbeef));
330const Address kHandleZapValue =
331 reinterpret_cast<Address>(V8_UINT64_C(0x1baddead0baddeaf));
332const Address kGlobalHandleZapValue =
333 reinterpret_cast<Address>(V8_UINT64_C(0x1baffed00baffedf));
334const Address kFromSpaceZapValue =
335 reinterpret_cast<Address>(V8_UINT64_C(0x1beefdad0beefdaf));
336const uint64_t kDebugZapValue = V8_UINT64_C(0xbadbaddbbadbaddb);
337const uint64_t kSlotsZapValue = V8_UINT64_C(0xbeefdeadbeefdeef);
338const uint64_t kFreeListZapValue = 0xfeed1eaffeed1eaf;
339#else
340const Address kZapValue = reinterpret_cast<Address>(0xdeadbeef);
341const Address kHandleZapValue = reinterpret_cast<Address>(0xbaddeaf);
342const Address kGlobalHandleZapValue = reinterpret_cast<Address>(0xbaffedf);
343const Address kFromSpaceZapValue = reinterpret_cast<Address>(0xbeefdaf);
344const uint32_t kSlotsZapValue = 0xbeefdeef;
345const uint32_t kDebugZapValue = 0xbadbaddb;
346const uint32_t kFreeListZapValue = 0xfeed1eaf;
347#endif
348
349const int kCodeZapValue = 0xbadc0de;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400350const uint32_t kPhantomReferenceZap = 0xca11bac;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000351
352// On Intel architecture, cache line size is 64 bytes.
353// On ARM it may be less (32 bytes), but as far this constant is
354// used for aligning data, it doesn't hurt to align on a greater value.
355#define PROCESSOR_CACHE_LINE_SIZE 64
356
357// Constants relevant to double precision floating point numbers.
358// If looking only at the top 32 bits, the QNaN mask is bits 19 to 30.
359const uint32_t kQuietNaNHighBitsMask = 0xfff << (51 - 32);
360
361
362// -----------------------------------------------------------------------------
363// Forward declarations for frequently used classes
364
365class AccessorInfo;
366class Allocation;
367class Arguments;
368class Assembler;
369class Code;
370class CodeGenerator;
371class CodeStub;
372class Context;
373class Debug;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000374class DebugInfo;
375class Descriptor;
376class DescriptorArray;
377class TransitionArray;
378class ExternalReference;
379class FixedArray;
380class FunctionTemplateInfo;
381class MemoryChunk;
382class SeededNumberDictionary;
383class UnseededNumberDictionary;
384class NameDictionary;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000385class GlobalDictionary;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000386template <typename T> class MaybeHandle;
387template <typename T> class Handle;
388class Heap;
389class HeapObject;
390class IC;
391class InterceptorInfo;
392class Isolate;
393class JSReceiver;
394class JSArray;
395class JSFunction;
396class JSObject;
397class LargeObjectSpace;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000398class MacroAssembler;
399class Map;
400class MapSpace;
401class MarkCompactCollector;
402class NewSpace;
403class Object;
404class OldSpace;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000405class ParameterCount;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000406class Foreign;
407class Scope;
408class ScopeInfo;
409class Script;
410class Smi;
411template <typename Config, class Allocator = FreeStoreAllocationPolicy>
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000412class SplayTree;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000413class String;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400414class Symbol;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000415class Name;
416class Struct;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000417class TypeFeedbackVector;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000418class Variable;
419class RelocInfo;
420class Deserializer;
421class MessageLocation;
422
423typedef bool (*WeakSlotCallback)(Object** pointer);
424
425typedef bool (*WeakSlotCallbackWithHeap)(Heap* heap, Object** pointer);
426
427// -----------------------------------------------------------------------------
428// Miscellaneous
429
430// NOTE: SpaceIterator depends on AllocationSpace enumeration values being
431// consecutive.
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400432// Keep this enum in sync with the ObjectSpace enum in v8.h
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000433enum AllocationSpace {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000434 NEW_SPACE, // Semispaces collected with copying collector.
435 OLD_SPACE, // May contain pointers to new space.
436 CODE_SPACE, // No pointers to new space, marked executable.
437 MAP_SPACE, // Only and all map objects.
438 LO_SPACE, // Promoted large objects.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000439
440 FIRST_SPACE = NEW_SPACE,
441 LAST_SPACE = LO_SPACE,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000442 FIRST_PAGED_SPACE = OLD_SPACE,
443 LAST_PAGED_SPACE = MAP_SPACE
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000444};
445const int kSpaceTagSize = 3;
446const int kSpaceTagMask = (1 << kSpaceTagSize) - 1;
447
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000448enum AllocationAlignment {
449 kWordAligned,
450 kDoubleAligned,
451 kDoubleUnaligned,
452 kSimd128Unaligned
453};
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000454
Ben Murdochc5610432016-08-08 18:44:38 +0100455// Supported write barrier modes.
456enum WriteBarrierKind : uint8_t {
457 kNoWriteBarrier,
458 kMapWriteBarrier,
459 kPointerWriteBarrier,
460 kFullWriteBarrier
461};
462
463inline size_t hash_value(WriteBarrierKind kind) {
464 return static_cast<uint8_t>(kind);
465}
466
467inline std::ostream& operator<<(std::ostream& os, WriteBarrierKind kind) {
468 switch (kind) {
469 case kNoWriteBarrier:
470 return os << "NoWriteBarrier";
471 case kMapWriteBarrier:
472 return os << "MapWriteBarrier";
473 case kPointerWriteBarrier:
474 return os << "PointerWriteBarrier";
475 case kFullWriteBarrier:
476 return os << "FullWriteBarrier";
477 }
478 UNREACHABLE();
479 return os;
480}
481
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000482// A flag that indicates whether objects should be pretenured when
483// allocated (allocated directly into the old generation) or not
484// (allocated in the young generation if the object size and type
485// allows).
486enum PretenureFlag { NOT_TENURED, TENURED };
487
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000488inline std::ostream& operator<<(std::ostream& os, const PretenureFlag& flag) {
489 switch (flag) {
490 case NOT_TENURED:
491 return os << "NotTenured";
492 case TENURED:
493 return os << "Tenured";
494 }
495 UNREACHABLE();
496 return os;
497}
498
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000499enum MinimumCapacity {
500 USE_DEFAULT_MINIMUM_CAPACITY,
501 USE_CUSTOM_MINIMUM_CAPACITY
502};
503
504enum GarbageCollector { SCAVENGER, MARK_COMPACTOR };
505
506enum Executability { NOT_EXECUTABLE, EXECUTABLE };
507
508enum VisitMode {
509 VISIT_ALL,
510 VISIT_ALL_IN_SCAVENGE,
511 VISIT_ALL_IN_SWEEP_NEWSPACE,
Ben Murdochda12d292016-06-02 14:46:10 +0100512 VISIT_ONLY_STRONG,
513 VISIT_ONLY_STRONG_FOR_SERIALIZATION,
514 VISIT_ONLY_STRONG_ROOT_LIST,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000515};
516
517// Flag indicating whether code is built into the VM (one of the natives files).
Ben Murdoch097c5b22016-05-18 11:27:45 +0100518enum NativesFlag { NOT_NATIVES_CODE, EXTENSION_CODE, NATIVES_CODE };
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000519
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000520// JavaScript defines two kinds of 'nil'.
521enum NilValue { kNullValue, kUndefinedValue };
522
523// ParseRestriction is used to restrict the set of valid statements in a
524// unit of compilation. Restriction violations cause a syntax error.
525enum ParseRestriction {
526 NO_PARSE_RESTRICTION, // All expressions are allowed.
527 ONLY_SINGLE_FUNCTION_LITERAL // Only a single FunctionLiteral expression.
528};
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000529
530// A CodeDesc describes a buffer holding instructions and relocation
531// information. The instructions start at the beginning of the buffer
532// and grow forward, the relocation information starts at the end of
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000533// the buffer and grows backward. A constant pool may exist at the
534// end of the instructions.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100535//
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000536// |<--------------- buffer_size ----------------------------------->|
537// |<------------- instr_size ---------->| |<-- reloc_size -->|
538// | |<- const_pool_size ->| |
539// +=====================================+========+==================+
540// | instructions | data | free | reloc info |
541// +=====================================+========+==================+
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000542// ^
543// |
544// buffer
545
546struct CodeDesc {
547 byte* buffer;
548 int buffer_size;
549 int instr_size;
550 int reloc_size;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000551 int constant_pool_size;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000552 Assembler* origin;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100553};
554
555
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000556// Callback function used for checking constraints when copying/relocating
557// objects. Returns true if an object can be copied/relocated from its
558// old_addr to a new_addr.
559typedef bool (*ConstraintCallback)(Address new_addr, Address old_addr);
560
561
562// Callback function on inline caches, used for iterating over inline caches
563// in compiled code.
564typedef void (*InlineCacheCallback)(Code* code, Address ic);
565
566
567// State for inline cache call sites. Aliased as IC::State.
568enum InlineCacheState {
569 // Has never been executed.
570 UNINITIALIZED,
571 // Has been executed but monomorhic state has been delayed.
572 PREMONOMORPHIC,
573 // Has been executed and only one receiver type has been seen.
574 MONOMORPHIC,
575 // Check failed due to prototype (or map deprecation).
Ben Murdochc5610432016-08-08 18:44:38 +0100576 RECOMPUTE_HANDLER,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000577 // Multiple receiver types have been seen.
578 POLYMORPHIC,
579 // Many receiver types have been seen.
580 MEGAMORPHIC,
581 // A generic handler is installed and no extra typefeedback is recorded.
582 GENERIC,
583 // Special state for debug break or step in prepare stubs.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000584 DEBUG_STUB
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000585};
586
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000587enum CacheHolderFlag {
588 kCacheOnPrototype,
589 kCacheOnPrototypeReceiverIsDictionary,
590 kCacheOnPrototypeReceiverIsPrimitive,
591 kCacheOnReceiver
592};
593
594
595// The Store Buffer (GC).
596typedef enum {
597 kStoreBufferFullEvent,
598 kStoreBufferStartScanningPagesEvent,
599 kStoreBufferScanningPageEvent
600} StoreBufferEvent;
601
602
603typedef void (*StoreBufferCallback)(Heap* heap,
604 MemoryChunk* page,
605 StoreBufferEvent event);
606
607
608// Union used for fast testing of specific double values.
609union DoubleRepresentation {
610 double value;
611 int64_t bits;
612 DoubleRepresentation(double x) { value = x; }
613 bool operator==(const DoubleRepresentation& other) const {
614 return bits == other.bits;
615 }
616};
617
618
619// Union used for customized checking of the IEEE double types
620// inlined within v8 runtime, rather than going to the underlying
621// platform headers and libraries
622union IeeeDoubleLittleEndianArchType {
623 double d;
624 struct {
625 unsigned int man_low :32;
626 unsigned int man_high :20;
627 unsigned int exp :11;
628 unsigned int sign :1;
629 } bits;
630};
631
632
633union IeeeDoubleBigEndianArchType {
634 double d;
635 struct {
636 unsigned int sign :1;
637 unsigned int exp :11;
638 unsigned int man_high :20;
639 unsigned int man_low :32;
640 } bits;
641};
642
643
644// AccessorCallback
645struct AccessorDescriptor {
646 Object* (*getter)(Isolate* isolate, Object* object, void* data);
647 Object* (*setter)(
648 Isolate* isolate, JSObject* object, Object* value, void* data);
649 void* data;
650};
651
652
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000653// -----------------------------------------------------------------------------
654// Macros
655
656// Testers for test.
657
658#define HAS_SMI_TAG(value) \
659 ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag)
660
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000661// OBJECT_POINTER_ALIGN returns the value aligned as a HeapObject pointer
662#define OBJECT_POINTER_ALIGN(value) \
663 (((value) + kObjectAlignmentMask) & ~kObjectAlignmentMask)
664
665// POINTER_SIZE_ALIGN returns the value aligned as a pointer.
666#define POINTER_SIZE_ALIGN(value) \
667 (((value) + kPointerAlignmentMask) & ~kPointerAlignmentMask)
668
669// CODE_POINTER_ALIGN returns the value aligned as a generated code segment.
670#define CODE_POINTER_ALIGN(value) \
671 (((value) + kCodeAlignmentMask) & ~kCodeAlignmentMask)
672
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000673// DOUBLE_POINTER_ALIGN returns the value algined for double pointers.
674#define DOUBLE_POINTER_ALIGN(value) \
675 (((value) + kDoubleAlignmentMask) & ~kDoubleAlignmentMask)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000676
677
678// CPU feature flags.
679enum CpuFeature {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400680 // x86
681 SSE4_1,
682 SSE3,
683 SAHF,
684 AVX,
685 FMA3,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000686 BMI1,
687 BMI2,
688 LZCNT,
689 POPCNT,
690 ATOM,
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400691 // ARM
692 VFP3,
693 ARMv7,
694 ARMv8,
695 SUDIV,
696 MLS,
697 UNALIGNED_ACCESSES,
698 MOVW_MOVT_IMMEDIATE_LOADS,
699 VFP32DREGS,
700 NEON,
701 // MIPS, MIPS64
702 FPU,
703 FP64FPU,
704 MIPSr1,
705 MIPSr2,
706 MIPSr6,
707 // ARM64
708 ALWAYS_ALIGN_CSP,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000709 // PPC
710 FPR_GPR_MOV,
711 LWSYNC,
712 ISELECT,
Ben Murdochda12d292016-06-02 14:46:10 +0100713 // S390
714 DISTINCT_OPS,
715 GENERAL_INSTR_EXT,
716 FLOATING_POINT_EXT,
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400717 NUMBER_OF_CPU_FEATURES
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000718};
719
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000720// Defines hints about receiver values based on structural knowledge.
721enum class ConvertReceiverMode : unsigned {
722 kNullOrUndefined, // Guaranteed to be null or undefined.
723 kNotNullOrUndefined, // Guaranteed to never be null or undefined.
724 kAny // No specific knowledge about receiver.
725};
726
727inline size_t hash_value(ConvertReceiverMode mode) {
728 return bit_cast<unsigned>(mode);
729}
730
731inline std::ostream& operator<<(std::ostream& os, ConvertReceiverMode mode) {
732 switch (mode) {
733 case ConvertReceiverMode::kNullOrUndefined:
734 return os << "NULL_OR_UNDEFINED";
735 case ConvertReceiverMode::kNotNullOrUndefined:
736 return os << "NOT_NULL_OR_UNDEFINED";
737 case ConvertReceiverMode::kAny:
738 return os << "ANY";
739 }
740 UNREACHABLE();
741 return os;
742}
743
Ben Murdoch097c5b22016-05-18 11:27:45 +0100744// Defines whether tail call optimization is allowed.
745enum class TailCallMode : unsigned { kAllow, kDisallow };
746
747inline size_t hash_value(TailCallMode mode) { return bit_cast<unsigned>(mode); }
748
749inline std::ostream& operator<<(std::ostream& os, TailCallMode mode) {
750 switch (mode) {
751 case TailCallMode::kAllow:
752 return os << "ALLOW_TAIL_CALLS";
753 case TailCallMode::kDisallow:
754 return os << "DISALLOW_TAIL_CALLS";
755 }
756 UNREACHABLE();
757 return os;
758}
759
760// Defines specifics about arguments object or rest parameter creation.
761enum class CreateArgumentsType : uint8_t {
762 kMappedArguments,
763 kUnmappedArguments,
764 kRestParameter
765};
766
767inline size_t hash_value(CreateArgumentsType type) {
768 return bit_cast<uint8_t>(type);
769}
770
771inline std::ostream& operator<<(std::ostream& os, CreateArgumentsType type) {
772 switch (type) {
773 case CreateArgumentsType::kMappedArguments:
774 return os << "MAPPED_ARGUMENTS";
775 case CreateArgumentsType::kUnmappedArguments:
776 return os << "UNMAPPED_ARGUMENTS";
777 case CreateArgumentsType::kRestParameter:
778 return os << "REST_PARAMETER";
779 }
780 UNREACHABLE();
781 return os;
782}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000783
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000784// Used to specify if a macro instruction must perform a smi check on tagged
785// values.
786enum SmiCheckType {
787 DONT_DO_SMI_CHECK,
788 DO_SMI_CHECK
789};
790
791
792enum ScopeType {
793 EVAL_SCOPE, // The top-level scope for an eval source.
794 FUNCTION_SCOPE, // The top-level scope for a function.
795 MODULE_SCOPE, // The scope introduced by a module literal
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400796 SCRIPT_SCOPE, // The top-level scope for a script or a top-level eval.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000797 CATCH_SCOPE, // The scope introduced by catch.
798 BLOCK_SCOPE, // The scope introduced by a new block.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000799 WITH_SCOPE // The scope introduced by with.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000800};
801
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000802// The mips architecture prior to revision 5 has inverted encoding for sNaN.
803#if (V8_TARGET_ARCH_MIPS && !defined(_MIPS_ARCH_MIPS32R6)) || \
804 (V8_TARGET_ARCH_MIPS64 && !defined(_MIPS_ARCH_MIPS64R6))
805const uint32_t kHoleNanUpper32 = 0xFFFF7FFF;
806const uint32_t kHoleNanLower32 = 0xFFFF7FFF;
807#else
808const uint32_t kHoleNanUpper32 = 0xFFF7FFFF;
809const uint32_t kHoleNanLower32 = 0xFFF7FFFF;
810#endif
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000811
812const uint64_t kHoleNanInt64 =
813 (static_cast<uint64_t>(kHoleNanUpper32) << 32) | kHoleNanLower32;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000814
815
816// ES6 section 20.1.2.6 Number.MAX_SAFE_INTEGER
817const double kMaxSafeInteger = 9007199254740991.0; // 2^53-1
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000818
819
820// The order of this enum has to be kept in sync with the predicates below.
821enum VariableMode {
822 // User declared variables:
Ben Murdochc5610432016-08-08 18:44:38 +0100823 VAR, // declared via 'var', and 'function' declarations
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000824
Ben Murdochc5610432016-08-08 18:44:38 +0100825 CONST_LEGACY, // declared via legacy 'const' declarations
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000826
Ben Murdochc5610432016-08-08 18:44:38 +0100827 LET, // declared via 'let' declarations (first lexical)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000828
Ben Murdochc5610432016-08-08 18:44:38 +0100829 CONST, // declared via 'const' declarations (last lexical)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000830
831 // Variables introduced by the compiler:
Ben Murdochc5610432016-08-08 18:44:38 +0100832 TEMPORARY, // temporary variables (not user-visible), stack-allocated
833 // unless the scope as a whole has forced context allocation
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000834
Ben Murdochc5610432016-08-08 18:44:38 +0100835 DYNAMIC, // always require dynamic lookup (we don't know
836 // the declaration)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000837
838 DYNAMIC_GLOBAL, // requires dynamic lookup, but we know that the
839 // variable is global unless it has been shadowed
840 // by an eval-introduced variable
841
Ben Murdochc5610432016-08-08 18:44:38 +0100842 DYNAMIC_LOCAL // requires dynamic lookup, but we know that the
843 // variable is local and where it is unless it
844 // has been shadowed by an eval-introduced
845 // variable
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000846};
847
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000848inline bool IsDynamicVariableMode(VariableMode mode) {
849 return mode >= DYNAMIC && mode <= DYNAMIC_LOCAL;
850}
851
852
853inline bool IsDeclaredVariableMode(VariableMode mode) {
Ben Murdochc5610432016-08-08 18:44:38 +0100854 return mode >= VAR && mode <= CONST;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000855}
856
857
858inline bool IsLexicalVariableMode(VariableMode mode) {
Ben Murdochc5610432016-08-08 18:44:38 +0100859 return mode >= LET && mode <= CONST;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000860}
861
862
863inline bool IsImmutableVariableMode(VariableMode mode) {
Ben Murdochc5610432016-08-08 18:44:38 +0100864 return mode == CONST || mode == CONST_LEGACY;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000865}
866
867
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000868enum class VariableLocation {
869 // Before and during variable allocation, a variable whose location is
870 // not yet determined. After allocation, a variable looked up as a
871 // property on the global object (and possibly absent). name() is the
872 // variable name, index() is invalid.
873 UNALLOCATED,
874
875 // A slot in the parameter section on the stack. index() is the
876 // parameter index, counting left-to-right. The receiver is index -1;
877 // the first parameter is index 0.
878 PARAMETER,
879
880 // A slot in the local section on the stack. index() is the variable
881 // index in the stack frame, starting at 0.
882 LOCAL,
883
884 // An indexed slot in a heap context. index() is the variable index in
885 // the context object on the heap, starting at 0. scope() is the
886 // corresponding scope.
887 CONTEXT,
888
889 // An indexed slot in a script context that contains a respective global
890 // property cell. name() is the variable name, index() is the variable
891 // index in the context object on the heap, starting at 0. scope() is the
892 // corresponding script scope.
893 GLOBAL,
894
895 // A named slot in a heap context. name() is the variable name in the
896 // context object on the heap, with lookup starting at the current
897 // context. index() is invalid.
898 LOOKUP
899};
900
901
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000902// ES6 Draft Rev3 10.2 specifies declarative environment records with mutable
903// and immutable bindings that can be in two states: initialized and
904// uninitialized. In ES5 only immutable bindings have these two states. When
905// accessing a binding, it needs to be checked for initialization. However in
906// the following cases the binding is initialized immediately after creation
907// so the initialization check can always be skipped:
908// 1. Var declared local variables.
909// var foo;
910// 2. A local variable introduced by a function declaration.
911// function foo() {}
912// 3. Parameters
913// function x(foo) {}
914// 4. Catch bound variables.
915// try {} catch (foo) {}
916// 6. Function variables of named function expressions.
917// var x = function foo() {}
918// 7. Implicit binding of 'this'.
919// 8. Implicit binding of 'arguments' in functions.
920//
921// ES5 specified object environment records which are introduced by ES elements
922// such as Program and WithStatement that associate identifier bindings with the
923// properties of some object. In the specification only mutable bindings exist
924// (which may be non-writable) and have no distinct initialization step. However
925// V8 allows const declarations in global code with distinct creation and
926// initialization steps which are represented by non-writable properties in the
927// global object. As a result also these bindings need to be checked for
928// initialization.
929//
930// The following enum specifies a flag that indicates if the binding needs a
931// distinct initialization step (kNeedsInitialization) or if the binding is
932// immediately initialized upon creation (kCreatedInitialized).
933enum InitializationFlag {
934 kNeedsInitialization,
935 kCreatedInitialized
936};
937
938
939enum MaybeAssignedFlag { kNotAssigned, kMaybeAssigned };
940
941
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000942// Serialized in PreparseData, so numeric values should not be changed.
943enum ParseErrorType { kSyntaxError = 0, kReferenceError = 1 };
944
945
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000946enum MinusZeroMode {
947 TREAT_MINUS_ZERO_AS_ZERO,
948 FAIL_ON_MINUS_ZERO
949};
950
951
952enum Signedness { kSigned, kUnsigned };
953
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000954enum FunctionKind {
955 kNormalFunction = 0,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000956 kArrowFunction = 1 << 0,
957 kGeneratorFunction = 1 << 1,
958 kConciseMethod = 1 << 2,
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400959 kConciseGeneratorMethod = kGeneratorFunction | kConciseMethod,
Ben Murdoch097c5b22016-05-18 11:27:45 +0100960 kDefaultConstructor = 1 << 3,
961 kSubclassConstructor = 1 << 4,
962 kBaseConstructor = 1 << 5,
963 kGetterFunction = 1 << 6,
964 kSetterFunction = 1 << 7,
Ben Murdochc5610432016-08-08 18:44:38 +0100965 kAsyncFunction = 1 << 8,
Ben Murdoch097c5b22016-05-18 11:27:45 +0100966 kAccessorFunction = kGetterFunction | kSetterFunction,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000967 kDefaultBaseConstructor = kDefaultConstructor | kBaseConstructor,
968 kDefaultSubclassConstructor = kDefaultConstructor | kSubclassConstructor,
969 kClassConstructor =
970 kBaseConstructor | kSubclassConstructor | kDefaultConstructor,
Ben Murdochc5610432016-08-08 18:44:38 +0100971 kAsyncArrowFunction = kArrowFunction | kAsyncFunction,
972 kAsyncConciseMethod = kAsyncFunction | kConciseMethod
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000973};
974
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000975inline bool IsValidFunctionKind(FunctionKind kind) {
976 return kind == FunctionKind::kNormalFunction ||
977 kind == FunctionKind::kArrowFunction ||
978 kind == FunctionKind::kGeneratorFunction ||
979 kind == FunctionKind::kConciseMethod ||
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400980 kind == FunctionKind::kConciseGeneratorMethod ||
Ben Murdoch097c5b22016-05-18 11:27:45 +0100981 kind == FunctionKind::kGetterFunction ||
982 kind == FunctionKind::kSetterFunction ||
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000983 kind == FunctionKind::kAccessorFunction ||
984 kind == FunctionKind::kDefaultBaseConstructor ||
985 kind == FunctionKind::kDefaultSubclassConstructor ||
986 kind == FunctionKind::kBaseConstructor ||
Ben Murdochc5610432016-08-08 18:44:38 +0100987 kind == FunctionKind::kSubclassConstructor ||
988 kind == FunctionKind::kAsyncFunction ||
989 kind == FunctionKind::kAsyncArrowFunction ||
990 kind == FunctionKind::kAsyncConciseMethod;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000991}
992
993
994inline bool IsArrowFunction(FunctionKind kind) {
995 DCHECK(IsValidFunctionKind(kind));
996 return kind & FunctionKind::kArrowFunction;
997}
998
999
1000inline bool IsGeneratorFunction(FunctionKind kind) {
1001 DCHECK(IsValidFunctionKind(kind));
1002 return kind & FunctionKind::kGeneratorFunction;
1003}
1004
Ben Murdochc5610432016-08-08 18:44:38 +01001005inline bool IsAsyncFunction(FunctionKind kind) {
1006 DCHECK(IsValidFunctionKind(kind));
1007 return kind & FunctionKind::kAsyncFunction;
1008}
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001009
1010inline bool IsConciseMethod(FunctionKind kind) {
1011 DCHECK(IsValidFunctionKind(kind));
1012 return kind & FunctionKind::kConciseMethod;
1013}
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001014
Ben Murdoch097c5b22016-05-18 11:27:45 +01001015inline bool IsGetterFunction(FunctionKind kind) {
1016 DCHECK(IsValidFunctionKind(kind));
1017 return kind & FunctionKind::kGetterFunction;
1018}
1019
1020inline bool IsSetterFunction(FunctionKind kind) {
1021 DCHECK(IsValidFunctionKind(kind));
1022 return kind & FunctionKind::kSetterFunction;
1023}
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001024
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001025inline bool IsAccessorFunction(FunctionKind kind) {
1026 DCHECK(IsValidFunctionKind(kind));
1027 return kind & FunctionKind::kAccessorFunction;
1028}
1029
1030
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001031inline bool IsDefaultConstructor(FunctionKind kind) {
1032 DCHECK(IsValidFunctionKind(kind));
1033 return kind & FunctionKind::kDefaultConstructor;
1034}
1035
1036
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001037inline bool IsBaseConstructor(FunctionKind kind) {
1038 DCHECK(IsValidFunctionKind(kind));
1039 return kind & FunctionKind::kBaseConstructor;
1040}
1041
1042
1043inline bool IsSubclassConstructor(FunctionKind kind) {
1044 DCHECK(IsValidFunctionKind(kind));
1045 return kind & FunctionKind::kSubclassConstructor;
1046}
1047
1048
1049inline bool IsClassConstructor(FunctionKind kind) {
1050 DCHECK(IsValidFunctionKind(kind));
1051 return kind & FunctionKind::kClassConstructor;
1052}
1053
1054
1055inline bool IsConstructable(FunctionKind kind, LanguageMode mode) {
1056 if (IsAccessorFunction(kind)) return false;
Ben Murdoch097c5b22016-05-18 11:27:45 +01001057 if (IsConciseMethod(kind)) return false;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001058 if (IsArrowFunction(kind)) return false;
Ben Murdoch097c5b22016-05-18 11:27:45 +01001059 if (IsGeneratorFunction(kind)) return false;
Ben Murdochc5610432016-08-08 18:44:38 +01001060 if (IsAsyncFunction(kind)) return false;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001061 return true;
1062}
1063
1064
Ben Murdoch097c5b22016-05-18 11:27:45 +01001065inline uint32_t ObjectHash(Address address) {
1066 // All objects are at least pointer aligned, so we can remove the trailing
1067 // zeros.
1068 return static_cast<uint32_t>(bit_cast<uintptr_t>(address) >>
1069 kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001070}
1071
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001072} // namespace internal
1073} // namespace v8
Steve Blocka7e24c12009-10-30 11:49:00 +00001074
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001075namespace i = v8::internal;
1076
Steve Blocka7e24c12009-10-30 11:49:00 +00001077#endif // V8_GLOBALS_H_