blob: e7ac2b9f7f6bd3a3534a55d03e359c4d86a1cd8d [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
Ben Murdochda12d292016-06-02 14:46:10 +0100127#if V8_TARGET_ARCH_ARM64
128const int kFrameAlignmentInBytes = 2 * kPointerSize;
129#else
130const int kFrameAlignmentInBytes = kPointerSize;
131#endif
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000132#if V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_32_BIT
133const int kRegisterSize = kPointerSize + kPointerSize;
134#else
135const int kRegisterSize = kPointerSize;
136#endif
137const int kPCOnStackSize = kRegisterSize;
138const int kFPOnStackSize = kRegisterSize;
Steve Blocka7e24c12009-10-30 11:49:00 +0000139
Ben Murdochda12d292016-06-02 14:46:10 +0100140#if V8_TARGET_ARCH_X64 || V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_X87
141const int kElidedFrameSlots = kPCOnStackSize / kPointerSize;
142#else
143const int kElidedFrameSlots = 0;
144#endif
145
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000146const int kDoubleSizeLog2 = 3;
147
Steve Blocka7e24c12009-10-30 11:49:00 +0000148#if V8_HOST_ARCH_64_BIT
149const int kPointerSizeLog2 = 3;
150const intptr_t kIntptrSignBit = V8_INT64_C(0x8000000000000000);
John Reck59135872010-11-02 12:39:01 -0700151const uintptr_t kUintptrAllBitsSet = V8_UINT64_C(0xFFFFFFFFFFFFFFFF);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000152const bool kRequiresCodeRange = true;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000153#if V8_TARGET_ARCH_MIPS64
154// To use pseudo-relative jumps such as j/jal instructions which have 28-bit
155// encoded immediate, the addresses have to be in range of 256MB aligned
156// region. Used only for large object space.
157const size_t kMaximalCodeRangeSize = 256 * MB;
158#else
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000159const size_t kMaximalCodeRangeSize = 512 * MB;
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;
164#else
165const size_t kMinimumCodeRangeSize = 3 * MB;
166const size_t kReservedCodeRangePages = 0;
167#endif
Steve Blocka7e24c12009-10-30 11:49:00 +0000168#else
169const int kPointerSizeLog2 = 2;
170const intptr_t kIntptrSignBit = 0x80000000;
John Reck59135872010-11-02 12:39:01 -0700171const uintptr_t kUintptrAllBitsSet = 0xFFFFFFFFu;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000172#if V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_32_BIT
173// x32 port also requires code range.
174const bool kRequiresCodeRange = true;
175const size_t kMaximalCodeRangeSize = 256 * MB;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400176const size_t kMinimumCodeRangeSize = 3 * MB;
177const size_t kReservedCodeRangePages = 0;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000178#else
179const bool kRequiresCodeRange = false;
180const size_t kMaximalCodeRangeSize = 0 * MB;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400181const size_t kMinimumCodeRangeSize = 0 * MB;
182const size_t kReservedCodeRangePages = 0;
Steve Blocka7e24c12009-10-30 11:49:00 +0000183#endif
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000184#endif
185
186STATIC_ASSERT(kPointerSize == (1 << kPointerSizeLog2));
Steve Blocka7e24c12009-10-30 11:49:00 +0000187
Steve Blocka7e24c12009-10-30 11:49:00 +0000188const int kBitsPerByte = 8;
189const int kBitsPerByteLog2 = 3;
190const int kBitsPerPointer = kPointerSize * kBitsPerByte;
191const int kBitsPerInt = kIntSize * kBitsPerByte;
192
Steve Block6ded16b2010-05-10 14:33:55 +0100193// IEEE 754 single precision floating point number bit layout.
194const uint32_t kBinary32SignMask = 0x80000000u;
195const uint32_t kBinary32ExponentMask = 0x7f800000u;
196const uint32_t kBinary32MantissaMask = 0x007fffffu;
197const int kBinary32ExponentBias = 127;
198const int kBinary32MaxExponent = 0xFE;
199const int kBinary32MinExponent = 0x01;
200const int kBinary32MantissaBits = 23;
201const int kBinary32ExponentShift = 23;
Steve Blocka7e24c12009-10-30 11:49:00 +0000202
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100203// Quiet NaNs have bits 51 to 62 set, possibly the sign bit, and no
204// other bits set.
205const uint64_t kQuietNaNMask = static_cast<uint64_t>(0xfff) << 51;
206
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000207// Latin1/UTF-16 constants
Steve Block9fac8402011-05-12 15:51:54 +0100208// Code-point values in Unicode 4.0 are 21 bits wide.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100209// Code units in UTF-16 are 16 bits wide.
Steve Block9fac8402011-05-12 15:51:54 +0100210typedef uint16_t uc16;
211typedef int32_t uc32;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000212const int kOneByteSize = kCharSize;
Steve Block9fac8402011-05-12 15:51:54 +0100213const int kUC16Size = sizeof(uc16); // NOLINT
Steve Block9fac8402011-05-12 15:51:54 +0100214
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000215// 128 bit SIMD value size.
216const int kSimd128Size = 16;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100217
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000218// Round up n to be a multiple of sz, where sz is a power of 2.
219#define ROUND_UP(n, sz) (((n) + ((sz) - 1)) & ~((sz) - 1))
Steve Blocka7e24c12009-10-30 11:49:00 +0000220
221
222// FUNCTION_ADDR(f) gets the address of a C function f.
223#define FUNCTION_ADDR(f) \
224 (reinterpret_cast<v8::internal::Address>(reinterpret_cast<intptr_t>(f)))
225
226
227// FUNCTION_CAST<F>(addr) casts an address into a function
228// of type F. Used to invoke generated code from within C.
229template <typename F>
230F FUNCTION_CAST(Address addr) {
231 return reinterpret_cast<F>(reinterpret_cast<intptr_t>(addr));
232}
233
234
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000235// Determine whether the architecture uses function descriptors
236// which provide a level of indirection between the function pointer
237// and the function entrypoint.
238#if V8_HOST_ARCH_PPC && \
239 (V8_OS_AIX || (V8_TARGET_ARCH_PPC64 && V8_TARGET_BIG_ENDIAN))
240#define USES_FUNCTION_DESCRIPTORS 1
241#define FUNCTION_ENTRYPOINT_ADDRESS(f) \
242 (reinterpret_cast<v8::internal::Address*>( \
243 &(reinterpret_cast<intptr_t*>(f)[0])))
244#else
245#define USES_FUNCTION_DESCRIPTORS 0
246#endif
247
248
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800249// -----------------------------------------------------------------------------
250// Forward declarations for frequently used classes
251// (sorted alphabetically)
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100252
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800253class FreeStoreAllocationPolicy;
254template <typename T, class P = FreeStoreAllocationPolicy> class List;
Steve Blockd0582a62009-12-15 09:54:21 +0000255
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100256// -----------------------------------------------------------------------------
257// Declarations for use in both the preparser and the rest of V8.
258
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100259// The Strict Mode (ECMA-262 5th edition, 4.2.2).
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000260
Ben Murdochda12d292016-06-02 14:46:10 +0100261enum LanguageMode { SLOPPY, STRICT, LANGUAGE_END = 3 };
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000262
263
264inline std::ostream& operator<<(std::ostream& os, const LanguageMode& mode) {
265 switch (mode) {
Ben Murdochda12d292016-06-02 14:46:10 +0100266 case SLOPPY: return os << "sloppy";
267 case STRICT: return os << "strict";
268 default: UNREACHABLE();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000269 }
Ben Murdochda12d292016-06-02 14:46:10 +0100270 return os;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000271}
272
273
274inline bool is_sloppy(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_strict(LanguageMode language_mode) {
Ben Murdochda12d292016-06-02 14:46:10 +0100280 return language_mode != SLOPPY;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000281}
282
283
284inline bool is_valid_language_mode(int language_mode) {
Ben Murdochda12d292016-06-02 14:46:10 +0100285 return language_mode == SLOPPY || language_mode == STRICT;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000286}
287
288
Ben Murdochda12d292016-06-02 14:46:10 +0100289inline LanguageMode construct_language_mode(bool strict_bit) {
290 return static_cast<LanguageMode>(strict_bit);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000291}
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000292
293
294// Mask for the sign bit in a smi.
295const intptr_t kSmiSignMask = kIntptrSignBit;
296
297const int kObjectAlignmentBits = kPointerSizeLog2;
298const intptr_t kObjectAlignment = 1 << kObjectAlignmentBits;
299const intptr_t kObjectAlignmentMask = kObjectAlignment - 1;
300
301// Desired alignment for pointers.
302const intptr_t kPointerAlignment = (1 << kPointerSizeLog2);
303const intptr_t kPointerAlignmentMask = kPointerAlignment - 1;
304
305// Desired alignment for double values.
306const intptr_t kDoubleAlignment = 8;
307const intptr_t kDoubleAlignmentMask = kDoubleAlignment - 1;
308
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000309// Desired alignment for 128 bit SIMD values.
310const intptr_t kSimd128Alignment = 16;
311const intptr_t kSimd128AlignmentMask = kSimd128Alignment - 1;
312
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000313// Desired alignment for generated code is 32 bytes (to improve cache line
314// utilization).
315const int kCodeAlignmentBits = 5;
316const intptr_t kCodeAlignment = 1 << kCodeAlignmentBits;
317const intptr_t kCodeAlignmentMask = kCodeAlignment - 1;
318
319// The owner field of a page is tagged with the page header tag. We need that
320// to find out if a slot is part of a large object. If we mask out the lower
321// 0xfffff bits (1M pages), go to the owner offset, and see that this field
322// is tagged with the page header tag, we can just look up the owner.
323// Otherwise, we know that we are somewhere (not within the first 1M) in a
324// large object.
325const int kPageHeaderTag = 3;
326const int kPageHeaderTagSize = 2;
327const intptr_t kPageHeaderTagMask = (1 << kPageHeaderTagSize) - 1;
328
329
330// Zap-value: The value used for zapping dead objects.
331// Should be a recognizable hex value tagged as a failure.
332#ifdef V8_HOST_ARCH_64_BIT
333const Address kZapValue =
334 reinterpret_cast<Address>(V8_UINT64_C(0xdeadbeedbeadbeef));
335const Address kHandleZapValue =
336 reinterpret_cast<Address>(V8_UINT64_C(0x1baddead0baddeaf));
337const Address kGlobalHandleZapValue =
338 reinterpret_cast<Address>(V8_UINT64_C(0x1baffed00baffedf));
339const Address kFromSpaceZapValue =
340 reinterpret_cast<Address>(V8_UINT64_C(0x1beefdad0beefdaf));
341const uint64_t kDebugZapValue = V8_UINT64_C(0xbadbaddbbadbaddb);
342const uint64_t kSlotsZapValue = V8_UINT64_C(0xbeefdeadbeefdeef);
343const uint64_t kFreeListZapValue = 0xfeed1eaffeed1eaf;
344#else
345const Address kZapValue = reinterpret_cast<Address>(0xdeadbeef);
346const Address kHandleZapValue = reinterpret_cast<Address>(0xbaddeaf);
347const Address kGlobalHandleZapValue = reinterpret_cast<Address>(0xbaffedf);
348const Address kFromSpaceZapValue = reinterpret_cast<Address>(0xbeefdaf);
349const uint32_t kSlotsZapValue = 0xbeefdeef;
350const uint32_t kDebugZapValue = 0xbadbaddb;
351const uint32_t kFreeListZapValue = 0xfeed1eaf;
352#endif
353
354const int kCodeZapValue = 0xbadc0de;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400355const uint32_t kPhantomReferenceZap = 0xca11bac;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000356
357// On Intel architecture, cache line size is 64 bytes.
358// On ARM it may be less (32 bytes), but as far this constant is
359// used for aligning data, it doesn't hurt to align on a greater value.
360#define PROCESSOR_CACHE_LINE_SIZE 64
361
362// Constants relevant to double precision floating point numbers.
363// If looking only at the top 32 bits, the QNaN mask is bits 19 to 30.
364const uint32_t kQuietNaNHighBitsMask = 0xfff << (51 - 32);
365
366
367// -----------------------------------------------------------------------------
368// Forward declarations for frequently used classes
369
370class AccessorInfo;
371class Allocation;
372class Arguments;
373class Assembler;
374class Code;
375class CodeGenerator;
376class CodeStub;
377class Context;
378class Debug;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000379class DebugInfo;
380class Descriptor;
381class DescriptorArray;
382class TransitionArray;
383class ExternalReference;
384class FixedArray;
385class FunctionTemplateInfo;
386class MemoryChunk;
387class SeededNumberDictionary;
388class UnseededNumberDictionary;
389class NameDictionary;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000390class GlobalDictionary;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000391template <typename T> class MaybeHandle;
392template <typename T> class Handle;
393class Heap;
394class HeapObject;
395class IC;
396class InterceptorInfo;
397class Isolate;
398class JSReceiver;
399class JSArray;
400class JSFunction;
401class JSObject;
402class LargeObjectSpace;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000403class MacroAssembler;
404class Map;
405class MapSpace;
406class MarkCompactCollector;
407class NewSpace;
408class Object;
409class OldSpace;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000410class ParameterCount;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000411class Foreign;
412class Scope;
413class ScopeInfo;
414class Script;
415class Smi;
416template <typename Config, class Allocator = FreeStoreAllocationPolicy>
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000417class SplayTree;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000418class String;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400419class Symbol;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000420class Name;
421class Struct;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000422class TypeFeedbackVector;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000423class Variable;
424class RelocInfo;
425class Deserializer;
426class MessageLocation;
427
428typedef bool (*WeakSlotCallback)(Object** pointer);
429
430typedef bool (*WeakSlotCallbackWithHeap)(Heap* heap, Object** pointer);
431
432// -----------------------------------------------------------------------------
433// Miscellaneous
434
435// NOTE: SpaceIterator depends on AllocationSpace enumeration values being
436// consecutive.
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400437// Keep this enum in sync with the ObjectSpace enum in v8.h
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000438enum AllocationSpace {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000439 NEW_SPACE, // Semispaces collected with copying collector.
440 OLD_SPACE, // May contain pointers to new space.
441 CODE_SPACE, // No pointers to new space, marked executable.
442 MAP_SPACE, // Only and all map objects.
443 LO_SPACE, // Promoted large objects.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000444
445 FIRST_SPACE = NEW_SPACE,
446 LAST_SPACE = LO_SPACE,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000447 FIRST_PAGED_SPACE = OLD_SPACE,
448 LAST_PAGED_SPACE = MAP_SPACE
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000449};
450const int kSpaceTagSize = 3;
451const int kSpaceTagMask = (1 << kSpaceTagSize) - 1;
452
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000453enum AllocationAlignment {
454 kWordAligned,
455 kDoubleAligned,
456 kDoubleUnaligned,
457 kSimd128Unaligned
458};
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000459
460// A flag that indicates whether objects should be pretenured when
461// allocated (allocated directly into the old generation) or not
462// (allocated in the young generation if the object size and type
463// allows).
464enum PretenureFlag { NOT_TENURED, TENURED };
465
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000466inline std::ostream& operator<<(std::ostream& os, const PretenureFlag& flag) {
467 switch (flag) {
468 case NOT_TENURED:
469 return os << "NotTenured";
470 case TENURED:
471 return os << "Tenured";
472 }
473 UNREACHABLE();
474 return os;
475}
476
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000477enum MinimumCapacity {
478 USE_DEFAULT_MINIMUM_CAPACITY,
479 USE_CUSTOM_MINIMUM_CAPACITY
480};
481
482enum GarbageCollector { SCAVENGER, MARK_COMPACTOR };
483
484enum Executability { NOT_EXECUTABLE, EXECUTABLE };
485
486enum VisitMode {
487 VISIT_ALL,
488 VISIT_ALL_IN_SCAVENGE,
489 VISIT_ALL_IN_SWEEP_NEWSPACE,
Ben Murdochda12d292016-06-02 14:46:10 +0100490 VISIT_ONLY_STRONG,
491 VISIT_ONLY_STRONG_FOR_SERIALIZATION,
492 VISIT_ONLY_STRONG_ROOT_LIST,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000493};
494
495// Flag indicating whether code is built into the VM (one of the natives files).
Ben Murdoch097c5b22016-05-18 11:27:45 +0100496enum NativesFlag { NOT_NATIVES_CODE, EXTENSION_CODE, NATIVES_CODE };
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000497
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000498// JavaScript defines two kinds of 'nil'.
499enum NilValue { kNullValue, kUndefinedValue };
500
501// ParseRestriction is used to restrict the set of valid statements in a
502// unit of compilation. Restriction violations cause a syntax error.
503enum ParseRestriction {
504 NO_PARSE_RESTRICTION, // All expressions are allowed.
505 ONLY_SINGLE_FUNCTION_LITERAL // Only a single FunctionLiteral expression.
506};
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000507
508// A CodeDesc describes a buffer holding instructions and relocation
509// information. The instructions start at the beginning of the buffer
510// and grow forward, the relocation information starts at the end of
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000511// the buffer and grows backward. A constant pool may exist at the
512// end of the instructions.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100513//
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000514// |<--------------- buffer_size ----------------------------------->|
515// |<------------- instr_size ---------->| |<-- reloc_size -->|
516// | |<- const_pool_size ->| |
517// +=====================================+========+==================+
518// | instructions | data | free | reloc info |
519// +=====================================+========+==================+
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000520// ^
521// |
522// buffer
523
524struct CodeDesc {
525 byte* buffer;
526 int buffer_size;
527 int instr_size;
528 int reloc_size;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000529 int constant_pool_size;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000530 Assembler* origin;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100531};
532
533
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000534// Callback function used for checking constraints when copying/relocating
535// objects. Returns true if an object can be copied/relocated from its
536// old_addr to a new_addr.
537typedef bool (*ConstraintCallback)(Address new_addr, Address old_addr);
538
539
540// Callback function on inline caches, used for iterating over inline caches
541// in compiled code.
542typedef void (*InlineCacheCallback)(Code* code, Address ic);
543
544
545// State for inline cache call sites. Aliased as IC::State.
546enum InlineCacheState {
547 // Has never been executed.
548 UNINITIALIZED,
549 // Has been executed but monomorhic state has been delayed.
550 PREMONOMORPHIC,
551 // Has been executed and only one receiver type has been seen.
552 MONOMORPHIC,
553 // Check failed due to prototype (or map deprecation).
554 PROTOTYPE_FAILURE,
555 // Multiple receiver types have been seen.
556 POLYMORPHIC,
557 // Many receiver types have been seen.
558 MEGAMORPHIC,
559 // A generic handler is installed and no extra typefeedback is recorded.
560 GENERIC,
561 // Special state for debug break or step in prepare stubs.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000562 DEBUG_STUB
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000563};
564
565
566enum CacheHolderFlag {
567 kCacheOnPrototype,
568 kCacheOnPrototypeReceiverIsDictionary,
569 kCacheOnPrototypeReceiverIsPrimitive,
570 kCacheOnReceiver
571};
572
573
574// The Store Buffer (GC).
575typedef enum {
576 kStoreBufferFullEvent,
577 kStoreBufferStartScanningPagesEvent,
578 kStoreBufferScanningPageEvent
579} StoreBufferEvent;
580
581
582typedef void (*StoreBufferCallback)(Heap* heap,
583 MemoryChunk* page,
584 StoreBufferEvent event);
585
586
587// Union used for fast testing of specific double values.
588union DoubleRepresentation {
589 double value;
590 int64_t bits;
591 DoubleRepresentation(double x) { value = x; }
592 bool operator==(const DoubleRepresentation& other) const {
593 return bits == other.bits;
594 }
595};
596
597
598// Union used for customized checking of the IEEE double types
599// inlined within v8 runtime, rather than going to the underlying
600// platform headers and libraries
601union IeeeDoubleLittleEndianArchType {
602 double d;
603 struct {
604 unsigned int man_low :32;
605 unsigned int man_high :20;
606 unsigned int exp :11;
607 unsigned int sign :1;
608 } bits;
609};
610
611
612union IeeeDoubleBigEndianArchType {
613 double d;
614 struct {
615 unsigned int sign :1;
616 unsigned int exp :11;
617 unsigned int man_high :20;
618 unsigned int man_low :32;
619 } bits;
620};
621
622
623// AccessorCallback
624struct AccessorDescriptor {
625 Object* (*getter)(Isolate* isolate, Object* object, void* data);
626 Object* (*setter)(
627 Isolate* isolate, JSObject* object, Object* value, void* data);
628 void* data;
629};
630
631
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000632// -----------------------------------------------------------------------------
633// Macros
634
635// Testers for test.
636
637#define HAS_SMI_TAG(value) \
638 ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag)
639
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000640// OBJECT_POINTER_ALIGN returns the value aligned as a HeapObject pointer
641#define OBJECT_POINTER_ALIGN(value) \
642 (((value) + kObjectAlignmentMask) & ~kObjectAlignmentMask)
643
644// POINTER_SIZE_ALIGN returns the value aligned as a pointer.
645#define POINTER_SIZE_ALIGN(value) \
646 (((value) + kPointerAlignmentMask) & ~kPointerAlignmentMask)
647
648// CODE_POINTER_ALIGN returns the value aligned as a generated code segment.
649#define CODE_POINTER_ALIGN(value) \
650 (((value) + kCodeAlignmentMask) & ~kCodeAlignmentMask)
651
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000652// DOUBLE_POINTER_ALIGN returns the value algined for double pointers.
653#define DOUBLE_POINTER_ALIGN(value) \
654 (((value) + kDoubleAlignmentMask) & ~kDoubleAlignmentMask)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000655
656
657// CPU feature flags.
658enum CpuFeature {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400659 // x86
660 SSE4_1,
661 SSE3,
662 SAHF,
663 AVX,
664 FMA3,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000665 BMI1,
666 BMI2,
667 LZCNT,
668 POPCNT,
669 ATOM,
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400670 // ARM
671 VFP3,
672 ARMv7,
673 ARMv8,
674 SUDIV,
675 MLS,
676 UNALIGNED_ACCESSES,
677 MOVW_MOVT_IMMEDIATE_LOADS,
678 VFP32DREGS,
679 NEON,
680 // MIPS, MIPS64
681 FPU,
682 FP64FPU,
683 MIPSr1,
684 MIPSr2,
685 MIPSr6,
686 // ARM64
687 ALWAYS_ALIGN_CSP,
688 COHERENT_CACHE,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000689 // PPC
690 FPR_GPR_MOV,
691 LWSYNC,
692 ISELECT,
Ben Murdochda12d292016-06-02 14:46:10 +0100693 // S390
694 DISTINCT_OPS,
695 GENERAL_INSTR_EXT,
696 FLOATING_POINT_EXT,
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400697 NUMBER_OF_CPU_FEATURES
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000698};
699
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000700// Defines hints about receiver values based on structural knowledge.
701enum class ConvertReceiverMode : unsigned {
702 kNullOrUndefined, // Guaranteed to be null or undefined.
703 kNotNullOrUndefined, // Guaranteed to never be null or undefined.
704 kAny // No specific knowledge about receiver.
705};
706
707inline size_t hash_value(ConvertReceiverMode mode) {
708 return bit_cast<unsigned>(mode);
709}
710
711inline std::ostream& operator<<(std::ostream& os, ConvertReceiverMode mode) {
712 switch (mode) {
713 case ConvertReceiverMode::kNullOrUndefined:
714 return os << "NULL_OR_UNDEFINED";
715 case ConvertReceiverMode::kNotNullOrUndefined:
716 return os << "NOT_NULL_OR_UNDEFINED";
717 case ConvertReceiverMode::kAny:
718 return os << "ANY";
719 }
720 UNREACHABLE();
721 return os;
722}
723
Ben Murdoch097c5b22016-05-18 11:27:45 +0100724// Defines whether tail call optimization is allowed.
725enum class TailCallMode : unsigned { kAllow, kDisallow };
726
727inline size_t hash_value(TailCallMode mode) { return bit_cast<unsigned>(mode); }
728
729inline std::ostream& operator<<(std::ostream& os, TailCallMode mode) {
730 switch (mode) {
731 case TailCallMode::kAllow:
732 return os << "ALLOW_TAIL_CALLS";
733 case TailCallMode::kDisallow:
734 return os << "DISALLOW_TAIL_CALLS";
735 }
736 UNREACHABLE();
737 return os;
738}
739
740// Defines specifics about arguments object or rest parameter creation.
741enum class CreateArgumentsType : uint8_t {
742 kMappedArguments,
743 kUnmappedArguments,
744 kRestParameter
745};
746
747inline size_t hash_value(CreateArgumentsType type) {
748 return bit_cast<uint8_t>(type);
749}
750
751inline std::ostream& operator<<(std::ostream& os, CreateArgumentsType type) {
752 switch (type) {
753 case CreateArgumentsType::kMappedArguments:
754 return os << "MAPPED_ARGUMENTS";
755 case CreateArgumentsType::kUnmappedArguments:
756 return os << "UNMAPPED_ARGUMENTS";
757 case CreateArgumentsType::kRestParameter:
758 return os << "REST_PARAMETER";
759 }
760 UNREACHABLE();
761 return os;
762}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000763
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000764// Used to specify if a macro instruction must perform a smi check on tagged
765// values.
766enum SmiCheckType {
767 DONT_DO_SMI_CHECK,
768 DO_SMI_CHECK
769};
770
771
772enum ScopeType {
773 EVAL_SCOPE, // The top-level scope for an eval source.
774 FUNCTION_SCOPE, // The top-level scope for a function.
775 MODULE_SCOPE, // The scope introduced by a module literal
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400776 SCRIPT_SCOPE, // The top-level scope for a script or a top-level eval.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000777 CATCH_SCOPE, // The scope introduced by catch.
778 BLOCK_SCOPE, // The scope introduced by a new block.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000779 WITH_SCOPE // The scope introduced by with.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000780};
781
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000782// The mips architecture prior to revision 5 has inverted encoding for sNaN.
783#if (V8_TARGET_ARCH_MIPS && !defined(_MIPS_ARCH_MIPS32R6)) || \
784 (V8_TARGET_ARCH_MIPS64 && !defined(_MIPS_ARCH_MIPS64R6))
785const uint32_t kHoleNanUpper32 = 0xFFFF7FFF;
786const uint32_t kHoleNanLower32 = 0xFFFF7FFF;
787#else
788const uint32_t kHoleNanUpper32 = 0xFFF7FFFF;
789const uint32_t kHoleNanLower32 = 0xFFF7FFFF;
790#endif
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000791
792const uint64_t kHoleNanInt64 =
793 (static_cast<uint64_t>(kHoleNanUpper32) << 32) | kHoleNanLower32;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000794
795
796// ES6 section 20.1.2.6 Number.MAX_SAFE_INTEGER
797const double kMaxSafeInteger = 9007199254740991.0; // 2^53-1
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000798
799
800// The order of this enum has to be kept in sync with the predicates below.
801enum VariableMode {
802 // User declared variables:
803 VAR, // declared via 'var', and 'function' declarations
804
805 CONST_LEGACY, // declared via legacy 'const' declarations
806
807 LET, // declared via 'let' declarations (first lexical)
808
809 CONST, // declared via 'const' declarations
810
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000811 IMPORT, // declared via 'import' declarations (last lexical)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000812
813 // Variables introduced by the compiler:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000814 TEMPORARY, // temporary variables (not user-visible), stack-allocated
815 // unless the scope as a whole has forced context allocation
816
817 DYNAMIC, // always require dynamic lookup (we don't know
818 // the declaration)
819
820 DYNAMIC_GLOBAL, // requires dynamic lookup, but we know that the
821 // variable is global unless it has been shadowed
822 // by an eval-introduced variable
823
824 DYNAMIC_LOCAL // requires dynamic lookup, but we know that the
825 // variable is local and where it is unless it
826 // has been shadowed by an eval-introduced
827 // variable
828};
829
830
831inline bool IsDynamicVariableMode(VariableMode mode) {
832 return mode >= DYNAMIC && mode <= DYNAMIC_LOCAL;
833}
834
835
836inline bool IsDeclaredVariableMode(VariableMode mode) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000837 return mode >= VAR && mode <= IMPORT;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000838}
839
840
841inline bool IsLexicalVariableMode(VariableMode mode) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000842 return mode >= LET && mode <= IMPORT;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000843}
844
845
846inline bool IsImmutableVariableMode(VariableMode mode) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000847 return mode == CONST || mode == CONST_LEGACY || mode == IMPORT;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000848}
849
850
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000851enum class VariableLocation {
852 // Before and during variable allocation, a variable whose location is
853 // not yet determined. After allocation, a variable looked up as a
854 // property on the global object (and possibly absent). name() is the
855 // variable name, index() is invalid.
856 UNALLOCATED,
857
858 // A slot in the parameter section on the stack. index() is the
859 // parameter index, counting left-to-right. The receiver is index -1;
860 // the first parameter is index 0.
861 PARAMETER,
862
863 // A slot in the local section on the stack. index() is the variable
864 // index in the stack frame, starting at 0.
865 LOCAL,
866
867 // An indexed slot in a heap context. index() is the variable index in
868 // the context object on the heap, starting at 0. scope() is the
869 // corresponding scope.
870 CONTEXT,
871
872 // An indexed slot in a script context that contains a respective global
873 // property cell. name() is the variable name, index() is the variable
874 // index in the context object on the heap, starting at 0. scope() is the
875 // corresponding script scope.
876 GLOBAL,
877
878 // A named slot in a heap context. name() is the variable name in the
879 // context object on the heap, with lookup starting at the current
880 // context. index() is invalid.
881 LOOKUP
882};
883
884
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000885// ES6 Draft Rev3 10.2 specifies declarative environment records with mutable
886// and immutable bindings that can be in two states: initialized and
887// uninitialized. In ES5 only immutable bindings have these two states. When
888// accessing a binding, it needs to be checked for initialization. However in
889// the following cases the binding is initialized immediately after creation
890// so the initialization check can always be skipped:
891// 1. Var declared local variables.
892// var foo;
893// 2. A local variable introduced by a function declaration.
894// function foo() {}
895// 3. Parameters
896// function x(foo) {}
897// 4. Catch bound variables.
898// try {} catch (foo) {}
899// 6. Function variables of named function expressions.
900// var x = function foo() {}
901// 7. Implicit binding of 'this'.
902// 8. Implicit binding of 'arguments' in functions.
903//
904// ES5 specified object environment records which are introduced by ES elements
905// such as Program and WithStatement that associate identifier bindings with the
906// properties of some object. In the specification only mutable bindings exist
907// (which may be non-writable) and have no distinct initialization step. However
908// V8 allows const declarations in global code with distinct creation and
909// initialization steps which are represented by non-writable properties in the
910// global object. As a result also these bindings need to be checked for
911// initialization.
912//
913// The following enum specifies a flag that indicates if the binding needs a
914// distinct initialization step (kNeedsInitialization) or if the binding is
915// immediately initialized upon creation (kCreatedInitialized).
916enum InitializationFlag {
917 kNeedsInitialization,
918 kCreatedInitialized
919};
920
921
922enum MaybeAssignedFlag { kNotAssigned, kMaybeAssigned };
923
924
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000925// Serialized in PreparseData, so numeric values should not be changed.
926enum ParseErrorType { kSyntaxError = 0, kReferenceError = 1 };
927
928
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000929enum MinusZeroMode {
930 TREAT_MINUS_ZERO_AS_ZERO,
931 FAIL_ON_MINUS_ZERO
932};
933
934
935enum Signedness { kSigned, kUnsigned };
936
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000937enum FunctionKind {
938 kNormalFunction = 0,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000939 kArrowFunction = 1 << 0,
940 kGeneratorFunction = 1 << 1,
941 kConciseMethod = 1 << 2,
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400942 kConciseGeneratorMethod = kGeneratorFunction | kConciseMethod,
Ben Murdoch097c5b22016-05-18 11:27:45 +0100943 kDefaultConstructor = 1 << 3,
944 kSubclassConstructor = 1 << 4,
945 kBaseConstructor = 1 << 5,
946 kGetterFunction = 1 << 6,
947 kSetterFunction = 1 << 7,
948 kAccessorFunction = kGetterFunction | kSetterFunction,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000949 kDefaultBaseConstructor = kDefaultConstructor | kBaseConstructor,
950 kDefaultSubclassConstructor = kDefaultConstructor | kSubclassConstructor,
951 kClassConstructor =
952 kBaseConstructor | kSubclassConstructor | kDefaultConstructor,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000953};
954
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000955inline bool IsValidFunctionKind(FunctionKind kind) {
956 return kind == FunctionKind::kNormalFunction ||
957 kind == FunctionKind::kArrowFunction ||
958 kind == FunctionKind::kGeneratorFunction ||
959 kind == FunctionKind::kConciseMethod ||
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400960 kind == FunctionKind::kConciseGeneratorMethod ||
Ben Murdoch097c5b22016-05-18 11:27:45 +0100961 kind == FunctionKind::kGetterFunction ||
962 kind == FunctionKind::kSetterFunction ||
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000963 kind == FunctionKind::kAccessorFunction ||
964 kind == FunctionKind::kDefaultBaseConstructor ||
965 kind == FunctionKind::kDefaultSubclassConstructor ||
966 kind == FunctionKind::kBaseConstructor ||
Ben Murdoch097c5b22016-05-18 11:27:45 +0100967 kind == FunctionKind::kSubclassConstructor;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000968}
969
970
971inline bool IsArrowFunction(FunctionKind kind) {
972 DCHECK(IsValidFunctionKind(kind));
973 return kind & FunctionKind::kArrowFunction;
974}
975
976
977inline bool IsGeneratorFunction(FunctionKind kind) {
978 DCHECK(IsValidFunctionKind(kind));
979 return kind & FunctionKind::kGeneratorFunction;
980}
981
982
983inline bool IsConciseMethod(FunctionKind kind) {
984 DCHECK(IsValidFunctionKind(kind));
985 return kind & FunctionKind::kConciseMethod;
986}
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400987
Ben Murdoch097c5b22016-05-18 11:27:45 +0100988inline bool IsGetterFunction(FunctionKind kind) {
989 DCHECK(IsValidFunctionKind(kind));
990 return kind & FunctionKind::kGetterFunction;
991}
992
993inline bool IsSetterFunction(FunctionKind kind) {
994 DCHECK(IsValidFunctionKind(kind));
995 return kind & FunctionKind::kSetterFunction;
996}
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400997
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000998inline bool IsAccessorFunction(FunctionKind kind) {
999 DCHECK(IsValidFunctionKind(kind));
1000 return kind & FunctionKind::kAccessorFunction;
1001}
1002
1003
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001004inline bool IsDefaultConstructor(FunctionKind kind) {
1005 DCHECK(IsValidFunctionKind(kind));
1006 return kind & FunctionKind::kDefaultConstructor;
1007}
1008
1009
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001010inline bool IsBaseConstructor(FunctionKind kind) {
1011 DCHECK(IsValidFunctionKind(kind));
1012 return kind & FunctionKind::kBaseConstructor;
1013}
1014
1015
1016inline bool IsSubclassConstructor(FunctionKind kind) {
1017 DCHECK(IsValidFunctionKind(kind));
1018 return kind & FunctionKind::kSubclassConstructor;
1019}
1020
1021
1022inline bool IsClassConstructor(FunctionKind kind) {
1023 DCHECK(IsValidFunctionKind(kind));
1024 return kind & FunctionKind::kClassConstructor;
1025}
1026
1027
1028inline bool IsConstructable(FunctionKind kind, LanguageMode mode) {
1029 if (IsAccessorFunction(kind)) return false;
Ben Murdoch097c5b22016-05-18 11:27:45 +01001030 if (IsConciseMethod(kind)) return false;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001031 if (IsArrowFunction(kind)) return false;
Ben Murdoch097c5b22016-05-18 11:27:45 +01001032 if (IsGeneratorFunction(kind)) return false;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001033 return true;
1034}
1035
1036
Ben Murdoch097c5b22016-05-18 11:27:45 +01001037inline uint32_t ObjectHash(Address address) {
1038 // All objects are at least pointer aligned, so we can remove the trailing
1039 // zeros.
1040 return static_cast<uint32_t>(bit_cast<uintptr_t>(address) >>
1041 kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001042}
1043
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001044} // namespace internal
1045} // namespace v8
Steve Blocka7e24c12009-10-30 11:49:00 +00001046
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001047namespace i = v8::internal;
1048
Steve Blocka7e24c12009-10-30 11:49:00 +00001049#endif // V8_GLOBALS_H_