globals.h 53.7 KB
Newer Older
1
// Copyright 2012 the V8 project authors. All rights reserved.
2 3
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4

5 6 7
#ifndef V8_GLOBALS_H_
#define V8_GLOBALS_H_

8 9
#include <stddef.h>
#include <stdint.h>
10

11
#include <limits>
12 13
#include <ostream>

14
#include "include/v8-internal.h"
15
#include "src/base/atomic-utils.h"
16
#include "src/base/build_config.h"
17
#include "src/base/flags.h"
18
#include "src/base/logging.h"
19
#include "src/base/macros.h"
20

21
#define V8_INFINITY std::numeric_limits<double>::infinity()
22

23
namespace v8 {
24 25 26 27 28 29

namespace base {
class Mutex;
class RecursiveMutex;
}

30
namespace internal {
31

32
// Determine whether we are running in a simulated environment.
33 34 35
// Setting USE_SIMULATOR explicitly from the build script will force
// the use of a simulated environment.
#if !defined(USE_SIMULATOR)
36
#if (V8_TARGET_ARCH_ARM64 && !V8_HOST_ARCH_ARM64)
37 38
#define USE_SIMULATOR 1
#endif
39 40 41
#if (V8_TARGET_ARCH_ARM && !V8_HOST_ARCH_ARM)
#define USE_SIMULATOR 1
#endif
42 43 44
#if (V8_TARGET_ARCH_PPC && !V8_HOST_ARCH_PPC)
#define USE_SIMULATOR 1
#endif
45 46
#if (V8_TARGET_ARCH_MIPS && !V8_HOST_ARCH_MIPS)
#define USE_SIMULATOR 1
47
#endif
48 49 50
#if (V8_TARGET_ARCH_MIPS64 && !V8_HOST_ARCH_MIPS64)
#define USE_SIMULATOR 1
#endif
51 52 53
#if (V8_TARGET_ARCH_S390 && !V8_HOST_ARCH_S390)
#define USE_SIMULATOR 1
#endif
54 55
#endif

56 57 58
// Determine whether the architecture uses an embedded constant pool
// (contiguous constant pool embedded in code object).
#if V8_TARGET_ARCH_PPC
59
#define V8_EMBEDDED_CONSTANT_POOL true
60
#else
61
#define V8_EMBEDDED_CONSTANT_POOL false
62
#endif
63

64 65 66 67 68 69 70 71 72 73 74
#ifdef V8_TARGET_ARCH_ARM
// Set stack limit lower for ARM than for other architectures because
// stack allocating MacroAssembler takes 120K bytes.
// See issue crbug.com/405338
#define V8_DEFAULT_STACK_SIZE_KB 864
#else
// Slightly less than 1MB, since Windows' default stack size for
// the main execution thread is 1MB for both 32 and 64-bit.
#define V8_DEFAULT_STACK_SIZE_KB 984
#endif

75
// Minimum stack size in KB required by compilers.
76
constexpr int kStackSpaceRequiredForCompilation = 40;
77

78
// Determine whether double field unboxing feature is enabled.
79
#if V8_TARGET_ARCH_64_BIT
80
#define V8_DOUBLE_FIELDS_UNBOXING true
81
#else
82
#define V8_DOUBLE_FIELDS_UNBOXING false
83 84
#endif

85 86
// Some types of tracing require the SFI to store a unique ID.
#if defined(V8_TRACE_MAPS) || defined(V8_TRACE_IGNITION)
87
#define V8_SFI_HAS_UNIQUE_ID true
88 89
#endif

90 91 92 93 94 95 96 97 98
// Superclass for classes only using static method functions.
// The subclass of AllStatic cannot be instantiated at all.
class AllStatic {
#ifdef DEBUG
 public:
  AllStatic() = delete;
#endif
};

99 100
typedef uint8_t byte;

101 102 103
// -----------------------------------------------------------------------------
// Constants

104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
constexpr int KB = 1024;
constexpr int MB = KB * KB;
constexpr int GB = KB * KB * KB;
constexpr int kMaxInt = 0x7FFFFFFF;
constexpr int kMinInt = -kMaxInt - 1;
constexpr int kMaxInt8 = (1 << 7) - 1;
constexpr int kMinInt8 = -(1 << 7);
constexpr int kMaxUInt8 = (1 << 8) - 1;
constexpr int kMinUInt8 = 0;
constexpr int kMaxInt16 = (1 << 15) - 1;
constexpr int kMinInt16 = -(1 << 15);
constexpr int kMaxUInt16 = (1 << 16) - 1;
constexpr int kMinUInt16 = 0;

constexpr uint32_t kMaxUInt32 = 0xFFFFFFFFu;
constexpr int kMinUInt32 = 0;

constexpr int kUInt8Size = sizeof(uint8_t);
constexpr int kCharSize = sizeof(char);
constexpr int kShortSize = sizeof(short);  // NOLINT
constexpr int kUInt16Size = sizeof(uint16_t);
constexpr int kIntSize = sizeof(int);
constexpr int kInt32Size = sizeof(int32_t);
constexpr int kInt64Size = sizeof(int64_t);
constexpr int kUInt32Size = sizeof(uint32_t);
constexpr int kSizetSize = sizeof(size_t);
constexpr int kFloatSize = sizeof(float);
constexpr int kDoubleSize = sizeof(double);
constexpr int kIntptrSize = sizeof(intptr_t);
constexpr int kUIntptrSize = sizeof(uintptr_t);
134 135
constexpr int kSystemPointerSize = sizeof(void*);
constexpr int kSystemPointerHexDigits = kSystemPointerSize == 4 ? 8 : 12;
136
#if V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_32_BIT
137
constexpr int kRegisterSize = kSystemPointerSize + kSystemPointerSize;
138
#else
139
constexpr int kRegisterSize = kSystemPointerSize;
140
#endif
141 142
constexpr int kPCOnStackSize = kRegisterSize;
constexpr int kFPOnStackSize = kRegisterSize;
143

Jakob Kummerow's avatar
Jakob Kummerow committed
144
#if V8_TARGET_ARCH_X64 || V8_TARGET_ARCH_IA32
145
constexpr int kElidedFrameSlots = kPCOnStackSize / kSystemPointerSize;
146
#else
147
constexpr int kElidedFrameSlots = 0;
148 149
#endif

150
constexpr int kDoubleSizeLog2 = 3;
151 152 153 154
#if V8_TARGET_ARCH_ARM64
// ARM64 only supports direct calls within a 128 MB range.
constexpr size_t kMaxWasmCodeMemory = 128 * MB;
#else
155
constexpr size_t kMaxWasmCodeMemory = 1024 * MB;
156
#endif
157

158
#if V8_HOST_ARCH_64_BIT
159
constexpr int kSystemPointerSizeLog2 = 3;
160
constexpr intptr_t kIntptrSignBit =
161
    static_cast<intptr_t>(uintptr_t{0x8000000000000000});
162 163
constexpr uintptr_t kUintptrAllBitsSet = uintptr_t{0xFFFFFFFFFFFFFFFF};
constexpr bool kRequiresCodeRange = true;
164
#if V8_HOST_ARCH_PPC && V8_TARGET_ARCH_PPC && V8_OS_LINUX
165
constexpr size_t kMaximalCodeRangeSize = 512 * MB;
166
constexpr size_t kMinExpectedOSPageSize = 64 * KB;  // OS page on PPC Linux
167 168
#elif V8_TARGET_ARCH_ARM64
constexpr size_t kMaximalCodeRangeSize = 128 * MB;
169
constexpr size_t kMinExpectedOSPageSize = 4 * KB;  // OS page.
170
#else
171
constexpr size_t kMaximalCodeRangeSize = 128 * MB;
172
constexpr size_t kMinExpectedOSPageSize = 4 * KB;  // OS page.
173
#endif
174
#if V8_OS_WIN
175 176
constexpr size_t kMinimumCodeRangeSize = 4 * MB;
constexpr size_t kReservedCodeRangePages = 1;
177
#else
178 179
constexpr size_t kMinimumCodeRangeSize = 3 * MB;
constexpr size_t kReservedCodeRangePages = 0;
180
#endif
181
#else
182
constexpr int kSystemPointerSizeLog2 = 2;
183 184
constexpr intptr_t kIntptrSignBit = 0x80000000;
constexpr uintptr_t kUintptrAllBitsSet = 0xFFFFFFFFu;
185 186
#if V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_32_BIT
// x32 port also requires code range.
187 188 189
constexpr bool kRequiresCodeRange = true;
constexpr size_t kMaximalCodeRangeSize = 256 * MB;
constexpr size_t kMinimumCodeRangeSize = 3 * MB;
190
constexpr size_t kMinExpectedOSPageSize = 4 * KB;  // OS page.
191
#elif V8_HOST_ARCH_PPC && V8_TARGET_ARCH_PPC && V8_OS_LINUX
192 193 194
constexpr bool kRequiresCodeRange = false;
constexpr size_t kMaximalCodeRangeSize = 0 * MB;
constexpr size_t kMinimumCodeRangeSize = 0 * MB;
195
constexpr size_t kMinExpectedOSPageSize = 64 * KB;  // OS page on PPC Linux
196
#else
197 198 199
constexpr bool kRequiresCodeRange = false;
constexpr size_t kMaximalCodeRangeSize = 0 * MB;
constexpr size_t kMinimumCodeRangeSize = 0 * MB;
200
constexpr size_t kMinExpectedOSPageSize = 4 * KB;  // OS page.
201
#endif
202
constexpr size_t kReservedCodeRangePages = 0;
203
#endif
204

205 206 207 208 209 210
STATIC_ASSERT(kSystemPointerSize == (1 << kSystemPointerSizeLog2));

constexpr int kTaggedSize = kSystemPointerSize;
constexpr int kTaggedSizeLog2 = kSystemPointerSizeLog2;
STATIC_ASSERT(kTaggedSize == (1 << kTaggedSizeLog2));

211 212 213 214 215 216 217 218
// These types define raw and atomic storage types for tagged values stored
// on V8 heap.
using Tagged_t = Address;
using AtomicTagged_t = base::AtomicWord;
using AsAtomicTagged = base::AsAtomicPointerImpl<AtomicTagged_t>;
STATIC_ASSERT(sizeof(Tagged_t) == kTaggedSize);
STATIC_ASSERT(sizeof(AtomicTagged_t) == kTaggedSize);

219 220 221 222 223
// TODO(ishell): use kTaggedSize or kSystemPointerSize instead.
constexpr int kPointerSize = kSystemPointerSize;
constexpr int kPointerSizeLog2 = kSystemPointerSizeLog2;
STATIC_ASSERT(kPointerSize == (1 << kPointerSizeLog2));

224 225 226 227 228 229 230 231 232 233
constexpr int kEmbedderDataSlotSize =
#ifdef V8_COMPRESS_POINTERS
    kTaggedSize +
#endif
    kTaggedSize;

constexpr int kEmbedderDataSlotSizeInTaggedSlots =
    kEmbedderDataSlotSize / kTaggedSize;
STATIC_ASSERT(kEmbedderDataSlotSize >= kSystemPointerSize);

234 235
constexpr int kExternalAllocationSoftLimit =
    internal::Internals::kExternalAllocationSoftLimit;
236

237 238 239 240 241
// Maximum object size that gets allocated into regular pages. Objects larger
// than that size are allocated in large object space and are never moved in
// memory. This also applies to new space allocation, since objects are never
// migrated from new space to large object space. Takes double alignment into
// account.
242 243
//
// Current value: Page::kAllocatableMemory (on 32-bit arch) - 512 (slack).
244
constexpr int kMaxRegularHeapObjectSize = 507136;
245

246 247
constexpr int kBitsPerByte = 8;
constexpr int kBitsPerByteLog2 = 3;
248
constexpr int kBitsPerSystemPointer = kSystemPointerSize * kBitsPerByte;
249
constexpr int kBitsPerInt = kIntSize * kBitsPerByte;
250

251
// IEEE 754 single precision floating point number bit layout.
252 253 254 255 256 257 258 259
constexpr uint32_t kBinary32SignMask = 0x80000000u;
constexpr uint32_t kBinary32ExponentMask = 0x7f800000u;
constexpr uint32_t kBinary32MantissaMask = 0x007fffffu;
constexpr int kBinary32ExponentBias = 127;
constexpr int kBinary32MaxExponent = 0xFE;
constexpr int kBinary32MinExponent = 0x01;
constexpr int kBinary32MantissaBits = 23;
constexpr int kBinary32ExponentShift = 23;
260

261 262
// Quiet NaNs have bits 51 to 62 set, possibly the sign bit, and no
// other bits set.
263
constexpr uint64_t kQuietNaNMask = static_cast<uint64_t>(0xfff) << 51;
264

265
// Latin1/UTF-16 constants
266
// Code-point values in Unicode 4.0 are 21 bits wide.
267
// Code units in UTF-16 are 16 bits wide.
268 269
typedef uint16_t uc16;
typedef int32_t uc32;
270 271
constexpr int kOneByteSize = kCharSize;
constexpr int kUC16Size = sizeof(uc16);  // NOLINT
272

273
// 128 bit SIMD value size.
274
constexpr int kSimd128Size = 16;
275

276
// FUNCTION_ADDR(f) gets the address of a C function f.
277
#define FUNCTION_ADDR(f) (reinterpret_cast<v8::internal::Address>(f))
278 279 280

// FUNCTION_CAST<F>(addr) casts an address into a function
// of type F. Used to invoke generated code from within C.
281 282 283 284 285
template <typename F>
F FUNCTION_CAST(byte* addr) {
  return reinterpret_cast<F>(reinterpret_cast<Address>(addr));
}

286 287
template <typename F>
F FUNCTION_CAST(Address addr) {
288
  return reinterpret_cast<F>(addr);
289 290 291
}


292 293 294 295 296 297 298 299 300 301 302 303 304 305
// Determine whether the architecture uses function descriptors
// which provide a level of indirection between the function pointer
// and the function entrypoint.
#if V8_HOST_ARCH_PPC && \
    (V8_OS_AIX || (V8_TARGET_ARCH_PPC64 && V8_TARGET_BIG_ENDIAN))
#define USES_FUNCTION_DESCRIPTORS 1
#define FUNCTION_ENTRYPOINT_ADDRESS(f)       \
  (reinterpret_cast<v8::internal::Address*>( \
      &(reinterpret_cast<intptr_t*>(f)[0])))
#else
#define USES_FUNCTION_DESCRIPTORS 0
#endif


306 307 308 309
// -----------------------------------------------------------------------------
// Declarations for use in both the preparser and the rest of V8.

// The Strict Mode (ECMA-262 5th edition, 4.2.2).
310

311 312 313 314 315 316
enum class LanguageMode : bool { kSloppy, kStrict };
static const size_t LanguageModeSize = 2;

inline size_t hash_value(LanguageMode mode) {
  return static_cast<size_t>(mode);
}
marja's avatar
marja committed
317

318
inline std::ostream& operator<<(std::ostream& os, const LanguageMode& mode) {
319
  switch (mode) {
320 321 322 323
    case LanguageMode::kSloppy:
      return os << "sloppy";
    case LanguageMode::kStrict:
      return os << "strict";
324
  }
325
  UNREACHABLE();
326 327
}

marja's avatar
marja committed
328
inline bool is_sloppy(LanguageMode language_mode) {
329
  return language_mode == LanguageMode::kSloppy;
marja's avatar
marja committed
330 331
}

332
inline bool is_strict(LanguageMode language_mode) {
333
  return language_mode != LanguageMode::kSloppy;
334 335 336
}

inline bool is_valid_language_mode(int language_mode) {
337 338
  return language_mode == static_cast<int>(LanguageMode::kSloppy) ||
         language_mode == static_cast<int>(LanguageMode::kStrict);
marja's avatar
marja committed
339 340
}

341 342
inline LanguageMode construct_language_mode(bool strict_bit) {
  return static_cast<LanguageMode>(strict_bit);
343
}
344

345 346 347 348 349 350 351 352 353
// Return kStrict if either of the language modes is kStrict, or kSloppy
// otherwise.
inline LanguageMode stricter_language_mode(LanguageMode mode1,
                                           LanguageMode mode2) {
  STATIC_ASSERT(LanguageModeSize == 2);
  return static_cast<LanguageMode>(static_cast<int>(mode1) |
                                   static_cast<int>(mode2));
}

354 355 356 357
// A non-keyed store is of the form a.x = foo or a["x"] = foo whereas
// a keyed store is of the form a[expression] = foo.
enum class StoreOrigin { kMaybeKeyed, kNamed };

358 359
enum TypeofMode : int { INSIDE_TYPEOF, NOT_INSIDE_TYPEOF };

360 361 362 363
// Enums used by CEntry.
enum SaveFPRegsMode { kDontSaveFPRegs, kSaveFPRegs };
enum ArgvMode { kArgvOnStack, kArgvInRegister };

yangguo's avatar
yangguo committed
364
// This constant is used as an undefined value when passing source positions.
365
constexpr int kNoSourcePosition = -1;
marja's avatar
marja committed
366

367
// This constant is used to indicate missing deoptimization information.
368
constexpr int kNoDeoptimizationId = -1;
369

370 371 372 373 374 375 376 377 378 379 380 381 382 383
// Deoptimize bailout kind:
// - Eager: a check failed in the optimized code and deoptimization happens
//   immediately.
// - Lazy: the code has been marked as dependent on some assumption which
//   is checked elsewhere and can trigger deoptimization the next time the
//   code is executed.
// - Soft: similar to lazy deoptimization, but does not contribute to the
//   total deopt count which can lead to disabling optimization for a function.
enum class DeoptimizeKind : uint8_t {
  kEager,
  kSoft,
  kLazy,
  kLastDeoptimizeKind = kLazy
};
384 385 386 387 388 389 390 391 392
inline size_t hash_value(DeoptimizeKind kind) {
  return static_cast<size_t>(kind);
}
inline std::ostream& operator<<(std::ostream& os, DeoptimizeKind kind) {
  switch (kind) {
    case DeoptimizeKind::kEager:
      return os << "Eager";
    case DeoptimizeKind::kSoft:
      return os << "Soft";
393 394
    case DeoptimizeKind::kLazy:
      return os << "Lazy";
395 396 397 398
  }
  UNREACHABLE();
}

399 400
enum class IsolateAllocationMode {
  // Allocate Isolate in C++ heap using default new/delete operators.
401
  kInCppHeap,
402 403

  // Allocate Isolate in a committed region inside V8 heap reservation.
404
  kInV8Heap,
405 406

#ifdef V8_COMPRESS_POINTERS
407
  kDefault = kInV8Heap,
408
#else
409
  kDefault = kInCppHeap,
410 411 412
#endif
};

413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
// Indicates whether the lookup is related to sloppy-mode block-scoped
// function hoisting, and is a synthetic assignment for that.
enum class LookupHoistingMode { kNormal, kLegacySloppy };

inline std::ostream& operator<<(std::ostream& os,
                                const LookupHoistingMode& mode) {
  switch (mode) {
    case LookupHoistingMode::kNormal:
      return os << "normal hoisting";
    case LookupHoistingMode::kLegacySloppy:
      return os << "legacy sloppy hoisting";
  }
  UNREACHABLE();
}

428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444
static_assert(kSmiValueSize <= 32, "Unsupported Smi tagging scheme");
// Smi sign bit position must be 32-bit aligned so we can use sign extension
// instructions on 64-bit architectures without additional shifts.
static_assert((kSmiValueSize + kSmiShiftSize + kSmiTagSize) % 32 == 0,
              "Unsupported Smi tagging scheme");

constexpr bool kIsSmiValueInUpper32Bits =
    (kSmiValueSize + kSmiShiftSize + kSmiTagSize) == 64;
constexpr bool kIsSmiValueInLower32Bits =
    (kSmiValueSize + kSmiShiftSize + kSmiTagSize) == 32;
static_assert(!SmiValuesAre32Bits() == SmiValuesAre31Bits(),
              "Unsupported Smi tagging scheme");
static_assert(SmiValuesAre32Bits() == kIsSmiValueInUpper32Bits,
              "Unsupported Smi tagging scheme");
static_assert(SmiValuesAre31Bits() == kIsSmiValueInLower32Bits,
              "Unsupported Smi tagging scheme");

445
// Mask for the sign bit in a smi.
446 447
constexpr intptr_t kSmiSignMask = static_cast<intptr_t>(
    uintptr_t{1} << (kSmiValueSize + kSmiShiftSize + kSmiTagSize - 1));
448

449 450
// Desired alignment for tagged pointers.
constexpr int kObjectAlignmentBits = kTaggedSizeLog2;
451 452
constexpr intptr_t kObjectAlignment = 1 << kObjectAlignmentBits;
constexpr intptr_t kObjectAlignmentMask = kObjectAlignment - 1;
453

454 455
// Desired alignment for system pointers.
constexpr intptr_t kPointerAlignment = (1 << kSystemPointerSizeLog2);
456
constexpr intptr_t kPointerAlignmentMask = kPointerAlignment - 1;
457 458

// Desired alignment for double values.
459 460
constexpr intptr_t kDoubleAlignment = 8;
constexpr intptr_t kDoubleAlignmentMask = kDoubleAlignment - 1;
461 462 463

// Desired alignment for generated code is 32 bytes (to improve cache line
// utilization).
464 465 466
constexpr int kCodeAlignmentBits = 5;
constexpr intptr_t kCodeAlignment = 1 << kCodeAlignmentBits;
constexpr intptr_t kCodeAlignmentMask = kCodeAlignment - 1;
467

468
const Address kWeakHeapObjectMask = 1 << 1;
469 470 471 472 473 474 475 476 477 478 479 480 481 482

// The lower 32 bits of the cleared weak reference value is always equal to
// the |kClearedWeakHeapObjectLower32| constant but on 64-bit architectures
// the value of the upper 32 bits part may be
// 1) zero when pointer compression is disabled,
// 2) upper 32 bits of the isolate root value when pointer compression is
//    enabled.
// This is necessary to make pointer decompression computation also suitable
// for cleared weak reference.
// Note, that real heap objects can't have lower 32 bits equal to 3 because
// this offset belongs to page header. So, in either case it's enough to
// compare only the lower 32 bits of a MaybeObject value in order to figure
// out if it's a cleared reference or not.
const uint32_t kClearedWeakHeapObjectLower32 = 3;
483 484 485 486

// Zap-value: The value used for zapping dead objects.
// Should be a recognizable hex value tagged as a failure.
#ifdef V8_HOST_ARCH_64_BIT
487
constexpr uint64_t kClearedFreeMemoryValue = 0;
488 489 490 491 492 493 494
constexpr uint64_t kZapValue = uint64_t{0xdeadbeedbeadbeef};
constexpr uint64_t kHandleZapValue = uint64_t{0x1baddead0baddeaf};
constexpr uint64_t kGlobalHandleZapValue = uint64_t{0x1baffed00baffedf};
constexpr uint64_t kFromSpaceZapValue = uint64_t{0x1beefdad0beefdaf};
constexpr uint64_t kDebugZapValue = uint64_t{0xbadbaddbbadbaddb};
constexpr uint64_t kSlotsZapValue = uint64_t{0xbeefdeadbeefdeef};
constexpr uint64_t kFreeListZapValue = 0xfeed1eaffeed1eaf;
495
#else
496
constexpr uint32_t kClearedFreeMemoryValue = 0;
497 498 499 500 501 502 503
constexpr uint32_t kZapValue = 0xdeadbeef;
constexpr uint32_t kHandleZapValue = 0xbaddeaf;
constexpr uint32_t kGlobalHandleZapValue = 0xbaffedf;
constexpr uint32_t kFromSpaceZapValue = 0xbeefdaf;
constexpr uint32_t kSlotsZapValue = 0xbeefdeef;
constexpr uint32_t kDebugZapValue = 0xbadbaddb;
constexpr uint32_t kFreeListZapValue = 0xfeed1eaf;
504 505
#endif

506 507
constexpr int kCodeZapValue = 0xbadc0de;
constexpr uint32_t kPhantomReferenceZap = 0xca11bac;
508

509 510 511
// Page constants.
static const intptr_t kPageAlignmentMask = (intptr_t{1} << kPageSizeBits) - 1;

512 513 514 515 516 517 518
// On Intel architecture, cache line size is 64 bytes.
// On ARM it may be less (32 bytes), but as far this constant is
// used for aligning data, it doesn't hurt to align on a greater value.
#define PROCESSOR_CACHE_LINE_SIZE 64

// Constants relevant to double precision floating point numbers.
// If looking only at the top 32 bits, the QNaN mask is bits 19 to 30.
519
constexpr uint32_t kQuietNaNHighBitsMask = 0xfff << (51 - 32);
520 521 522 523 524 525 526 527

// -----------------------------------------------------------------------------
// Forward declarations for frequently used classes

class AccessorInfo;
class Arguments;
class Assembler;
class Code;
528
class CodeSpace;
529 530
class CodeStub;
class Context;
531
class DeclarationScope;
532 533 534 535 536 537
class Debug;
class DebugInfo;
class Descriptor;
class DescriptorArray;
class TransitionArray;
class ExternalReference;
538
class FeedbackVector;
539
class FixedArray;
540
class Foreign;
541
class FreeStoreAllocationPolicy;
542
class FunctionTemplateInfo;
543
class GlobalDictionary;
544 545 546
template <typename T> class Handle;
class Heap;
class HeapObject;
547
class HeapObjectReference;
548 549 550 551 552 553 554 555 556 557 558 559
class IC;
class InterceptorInfo;
class Isolate;
class JSReceiver;
class JSArray;
class JSFunction;
class JSObject;
class LargeObjectSpace;
class MacroAssembler;
class Map;
class MapSpace;
class MarkCompactCollector;
560 561
template <typename T>
class MaybeHandle;
562
class MaybeObject;
563 564 565 566 567
class MemoryChunk;
class MessageLocation;
class ModuleScope;
class Name;
class NameDictionary;
568
class NewSpace;
569
class NewLargeObjectSpace;
570
class NumberDictionary;
571
class Object;
572
class ObjectSlot;
573
class OldSpace;
574
class ParameterCount;
575
class ReadOnlySpace;
576
class RelocInfo;
577 578 579
class Scope;
class ScopeInfo;
class Script;
580
class SimpleNumberDictionary;
581 582
class Smi;
template <typename Config, class Allocator = FreeStoreAllocationPolicy>
583
class SplayTree;
584 585
class String;
class Struct;
586
class Symbol;
587 588
class Variable;

589
typedef bool (*WeakSlotCallback)(ObjectSlot pointer);
590

591
typedef bool (*WeakSlotCallbackWithHeap)(Heap* heap, ObjectSlot pointer);
592 593 594 595 596 597 598

// -----------------------------------------------------------------------------
// Miscellaneous

// NOTE: SpaceIterator depends on AllocationSpace enumeration values being
// consecutive.
enum AllocationSpace {
599 600
  // TODO(v8:7464): Actually map this space's memory as read-only.
  RO_SPACE,    // Immortal, immovable and immutable objects,
601 602 603 604 605 606
  NEW_SPACE,   // Young generation semispaces for regular objects collected with
               // Scavenger.
  OLD_SPACE,   // Old generation regular object space.
  CODE_SPACE,  // Old generation code object space, marked executable.
  MAP_SPACE,   // Old generation map object space, non-movable.
  LO_SPACE,    // Old generation large object space.
607 608
  CODE_LO_SPACE,  // Old generation large code object space.
  NEW_LO_SPACE,   // Young generation large object space.
609

610
  FIRST_SPACE = RO_SPACE,
611
  LAST_SPACE = NEW_LO_SPACE,
612 613
  FIRST_GROWABLE_PAGED_SPACE = OLD_SPACE,
  LAST_GROWABLE_PAGED_SPACE = MAP_SPACE
614
};
615
constexpr int kSpaceTagSize = 4;
616
STATIC_ASSERT(FIRST_SPACE == 0);
617

618
enum AllocationAlignment { kWordAligned, kDoubleAligned, kDoubleUnaligned };
619

620 621
enum class AccessMode { ATOMIC, NON_ATOMIC };

622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647
// Supported write barrier modes.
enum WriteBarrierKind : uint8_t {
  kNoWriteBarrier,
  kMapWriteBarrier,
  kPointerWriteBarrier,
  kFullWriteBarrier
};

inline size_t hash_value(WriteBarrierKind kind) {
  return static_cast<uint8_t>(kind);
}

inline std::ostream& operator<<(std::ostream& os, WriteBarrierKind kind) {
  switch (kind) {
    case kNoWriteBarrier:
      return os << "NoWriteBarrier";
    case kMapWriteBarrier:
      return os << "MapWriteBarrier";
    case kPointerWriteBarrier:
      return os << "PointerWriteBarrier";
    case kFullWriteBarrier:
      return os << "FullWriteBarrier";
  }
  UNREACHABLE();
}

648
// A flag that indicates whether objects should be pretenured when
649 650
// allocated (allocated directly into either the old generation or read-only
// space), or not (allocated in the young generation if the object size and type
651
// allows).
652
enum PretenureFlag { NOT_TENURED, TENURED, TENURED_READ_ONLY };
653

654 655 656 657 658 659
inline std::ostream& operator<<(std::ostream& os, const PretenureFlag& flag) {
  switch (flag) {
    case NOT_TENURED:
      return os << "NotTenured";
    case TENURED:
      return os << "Tenured";
660 661
    case TENURED_READ_ONLY:
      return os << "TenuredReadOnly";
662 663 664 665
  }
  UNREACHABLE();
}

666 667 668 669 670
enum MinimumCapacity {
  USE_DEFAULT_MINIMUM_CAPACITY,
  USE_CUSTOM_MINIMUM_CAPACITY
};

671
enum GarbageCollector { SCAVENGER, MARK_COMPACTOR, MINOR_MARK_COMPACTOR };
672 673 674

enum Executability { NOT_EXECUTABLE, EXECUTABLE };

675 676
enum Movability { kMovable, kImmovable };

677 678
enum VisitMode {
  VISIT_ALL,
679
  VISIT_ALL_IN_MINOR_MC_MARK,
680
  VISIT_ALL_IN_MINOR_MC_UPDATE,
681 682
  VISIT_ALL_IN_SCAVENGE,
  VISIT_ALL_IN_SWEEP_NEWSPACE,
683
  VISIT_ONLY_STRONG,
684
  VISIT_FOR_SERIALIZATION,
685 686 687
};

// Flag indicating whether code is built into the VM (one of the natives files).
688 689 690 691 692 693
enum NativesFlag {
  NOT_NATIVES_CODE,
  EXTENSION_CODE,
  NATIVES_CODE,
  INSPECTOR_CODE
};
694

695 696 697 698 699 700 701
// ParseRestriction is used to restrict the set of valid statements in a
// unit of compilation.  Restriction violations cause a syntax error.
enum ParseRestriction {
  NO_PARSE_RESTRICTION,         // All expressions are allowed.
  ONLY_SINGLE_FUNCTION_LITERAL  // Only a single FunctionLiteral expression.
};

702 703 704
// A CodeDesc describes a buffer holding instructions and relocation
// information. The instructions start at the beginning of the buffer
// and grow forward, the relocation information starts at the end of
705 706
// the buffer and grows backward.  A constant pool may exist at the
// end of the instructions.
707
//
708 709 710 711 712 713
//  |<--------------- buffer_size ----------------------------------->|
//  |<------------- instr_size ---------->|        |<-- reloc_size -->|
//  |               |<- const_pool_size ->|                           |
//  +=====================================+========+==================+
//  |  instructions |        data         |  free  |    reloc info    |
//  +=====================================+========+==================+
714 715 716 717 718 719 720 721 722
//  ^
//  |
//  buffer

struct CodeDesc {
  byte* buffer;
  int buffer_size;
  int instr_size;
  int reloc_size;
723
  int constant_pool_size;
724 725
  byte* unwinding_info;
  int unwinding_info_size;
726 727 728 729 730 731 732 733 734 735 736
  Assembler* origin;
};

// State for inline cache call sites. Aliased as IC::State.
enum InlineCacheState {
  // Has never been executed.
  UNINITIALIZED,
  // Has been executed but monomorhic state has been delayed.
  PREMONOMORPHIC,
  // Has been executed and only one receiver type has been seen.
  MONOMORPHIC,
737
  // Check failed due to prototype (or map deprecation).
738
  RECOMPUTE_HANDLER,
739 740 741 742 743 744 745 746
  // Multiple receiver types have been seen.
  POLYMORPHIC,
  // Many receiver types have been seen.
  MEGAMORPHIC,
  // A generic handler is installed and no extra typefeedback is recorded.
  GENERIC,
};

747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767
// Printing support.
inline const char* InlineCacheState2String(InlineCacheState state) {
  switch (state) {
    case UNINITIALIZED:
      return "UNINITIALIZED";
    case PREMONOMORPHIC:
      return "PREMONOMORPHIC";
    case MONOMORPHIC:
      return "MONOMORPHIC";
    case RECOMPUTE_HANDLER:
      return "RECOMPUTE_HANDLER";
    case POLYMORPHIC:
      return "POLYMORPHIC";
    case MEGAMORPHIC:
      return "MEGAMORPHIC";
    case GENERIC:
      return "GENERIC";
  }
  UNREACHABLE();
}

768
enum WhereToStart { kStartAtReceiver, kStartAtPrototype };
769

770 771
enum ResultSentinel { kNotFound = -1, kUnsupported = -2 };

772 773
enum ShouldThrow { kThrowOnError, kDontThrow };

774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809
// The Store Buffer (GC).
typedef enum {
  kStoreBufferFullEvent,
  kStoreBufferStartScanningPagesEvent,
  kStoreBufferScanningPageEvent
} StoreBufferEvent;


typedef void (*StoreBufferCallback)(Heap* heap,
                                    MemoryChunk* page,
                                    StoreBufferEvent event);

// Union used for customized checking of the IEEE double types
// inlined within v8 runtime, rather than going to the underlying
// platform headers and libraries
union IeeeDoubleLittleEndianArchType {
  double d;
  struct {
    unsigned int man_low  :32;
    unsigned int man_high :20;
    unsigned int exp      :11;
    unsigned int sign     :1;
  } bits;
};


union IeeeDoubleBigEndianArchType {
  double d;
  struct {
    unsigned int sign     :1;
    unsigned int exp      :11;
    unsigned int man_high :20;
    unsigned int man_low  :32;
  } bits;
};

810 811
#if V8_TARGET_LITTLE_ENDIAN
typedef IeeeDoubleLittleEndianArchType IeeeDoubleArchType;
812 813
constexpr int kIeeeDoubleMantissaWordOffset = 0;
constexpr int kIeeeDoubleExponentWordOffset = 4;
814 815
#else
typedef IeeeDoubleBigEndianArchType IeeeDoubleArchType;
816 817
constexpr int kIeeeDoubleMantissaWordOffset = 4;
constexpr int kIeeeDoubleExponentWordOffset = 0;
818
#endif
819 820 821 822 823 824 825

// -----------------------------------------------------------------------------
// Macros

// Testers for test.

#define HAS_SMI_TAG(value) \
826
  ((static_cast<intptr_t>(value) & ::i::kSmiTagMask) == ::i::kSmiTag)
827

828 829
#define HAS_HEAP_OBJECT_TAG(value)                              \
  (((static_cast<intptr_t>(value) & ::i::kHeapObjectTagMask) == \
830
    ::i::kHeapObjectTag))
831 832 833 834 835

// OBJECT_POINTER_ALIGN returns the value aligned as a HeapObject pointer
#define OBJECT_POINTER_ALIGN(value)                             \
  (((value) + kObjectAlignmentMask) & ~kObjectAlignmentMask)

836 837 838 839
// OBJECT_POINTER_PADDING returns the padding size required to align value
// as a HeapObject pointer
#define OBJECT_POINTER_PADDING(value) (OBJECT_POINTER_ALIGN(value) - (value))

840 841 842 843
// POINTER_SIZE_ALIGN returns the value aligned as a pointer.
#define POINTER_SIZE_ALIGN(value)                               \
  (((value) + kPointerAlignmentMask) & ~kPointerAlignmentMask)

844 845 846 847
// POINTER_SIZE_PADDING returns the padding size required to align value
// as a system pointer.
#define POINTER_SIZE_PADDING(value) (POINTER_SIZE_ALIGN(value) - (value))

848 849 850 851
// CODE_POINTER_ALIGN returns the value aligned as a generated code segment.
#define CODE_POINTER_ALIGN(value)                               \
  (((value) + kCodeAlignmentMask) & ~kCodeAlignmentMask)

852 853 854 855
// CODE_POINTER_PADDING returns the padding size required to align value
// as a generated code segment.
#define CODE_POINTER_PADDING(value) (CODE_POINTER_ALIGN(value) - (value))

856 857 858 859
// DOUBLE_POINTER_ALIGN returns the value algined for double pointers.
#define DOUBLE_POINTER_ALIGN(value) \
  (((value) + kDoubleAlignmentMask) & ~kDoubleAlignmentMask)

860 861 862

// CPU feature flags.
enum CpuFeature {
863 864
  // x86
  SSE4_1,
865
  SSSE3,
866 867
  SSE3,
  SAHF,
868 869
  AVX,
  FMA3,
870 871 872 873
  BMI1,
  BMI2,
  LZCNT,
  POPCNT,
874
  ATOM,
875
  // ARM
876 877 878 879
  // - Standard configurations. The baseline is ARMv6+VFPv2.
  ARMv7,        // ARMv7-A + VFPv3-D32 + NEON
  ARMv7_SUDIV,  // ARMv7-A + VFPv4-D32 + NEON + SUDIV
  ARMv8,        // ARMv8-A (+ all of the above)
880 881 882 883 884 885
  // MIPS, MIPS64
  FPU,
  FP64FPU,
  MIPSr1,
  MIPSr2,
  MIPSr6,
886
  MIPS_SIMD,  // MSA instructions
887 888 889 890
  // PPC
  FPR_GPR_MOV,
  LWSYNC,
  ISELECT,
891
  VSX,
892
  MODULO,
893 894 895 896
  // S390
  DISTINCT_OPS,
  GENERAL_INSTR_EXT,
  FLOATING_POINT_EXT,
897
  VECTOR_FACILITY,
jyan's avatar
jyan committed
898
  MISC_INSTR_EXT2,
899

900 901 902
  NUMBER_OF_CPU_FEATURES,

  // ARM feature aliases (based on the standard configurations above).
903
  VFPv3 = ARMv7,
904 905 906
  NEON = ARMv7,
  VFP32DREGS = ARMv7,
  SUDIV = ARMv7_SUDIV
907 908
};

909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931
// Defines hints about receiver values based on structural knowledge.
enum class ConvertReceiverMode : unsigned {
  kNullOrUndefined,     // Guaranteed to be null or undefined.
  kNotNullOrUndefined,  // Guaranteed to never be null or undefined.
  kAny                  // No specific knowledge about receiver.
};

inline size_t hash_value(ConvertReceiverMode mode) {
  return bit_cast<unsigned>(mode);
}

inline std::ostream& operator<<(std::ostream& os, ConvertReceiverMode mode) {
  switch (mode) {
    case ConvertReceiverMode::kNullOrUndefined:
      return os << "NULL_OR_UNDEFINED";
    case ConvertReceiverMode::kNotNullOrUndefined:
      return os << "NOT_NULL_OR_UNDEFINED";
    case ConvertReceiverMode::kAny:
      return os << "ANY";
  }
  UNREACHABLE();
}

932 933 934 935 936 937 938 939
// Valid hints for the abstract operation OrdinaryToPrimitive,
// implemented according to ES6, section 7.1.1.
enum class OrdinaryToPrimitiveHint { kNumber, kString };

// Valid hints for the abstract operation ToPrimitive,
// implemented according to ES6, section 7.1.1.
enum class ToPrimitiveHint { kDefault, kNumber, kString };

940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962
// Defines specifics about arguments object or rest parameter creation.
enum class CreateArgumentsType : uint8_t {
  kMappedArguments,
  kUnmappedArguments,
  kRestParameter
};

inline size_t hash_value(CreateArgumentsType type) {
  return bit_cast<uint8_t>(type);
}

inline std::ostream& operator<<(std::ostream& os, CreateArgumentsType type) {
  switch (type) {
    case CreateArgumentsType::kMappedArguments:
      return os << "MAPPED_ARGUMENTS";
    case CreateArgumentsType::kUnmappedArguments:
      return os << "UNMAPPED_ARGUMENTS";
    case CreateArgumentsType::kRestParameter:
      return os << "REST_PARAMETER";
  }
  UNREACHABLE();
}

963
enum ScopeType : uint8_t {
964 965 966
  EVAL_SCOPE,      // The top-level scope for an eval source.
  FUNCTION_SCOPE,  // The top-level scope for a function.
  MODULE_SCOPE,    // The scope introduced by a module literal
967
  SCRIPT_SCOPE,    // The top-level scope for a script or a top-level eval.
968 969
  CATCH_SCOPE,     // The scope introduced by catch.
  BLOCK_SCOPE,     // The scope introduced by a new block.
970
  WITH_SCOPE       // The scope introduced by with.
971 972
};

973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992
inline std::ostream& operator<<(std::ostream& os, ScopeType type) {
  switch (type) {
    case ScopeType::EVAL_SCOPE:
      return os << "EVAL_SCOPE";
    case ScopeType::FUNCTION_SCOPE:
      return os << "FUNCTION_SCOPE";
    case ScopeType::MODULE_SCOPE:
      return os << "MODULE_SCOPE";
    case ScopeType::SCRIPT_SCOPE:
      return os << "SCRIPT_SCOPE";
    case ScopeType::CATCH_SCOPE:
      return os << "CATCH_SCOPE";
    case ScopeType::BLOCK_SCOPE:
      return os << "BLOCK_SCOPE";
    case ScopeType::WITH_SCOPE:
      return os << "WITH_SCOPE";
  }
  UNREACHABLE();
}

993 994 995 996 997 998 999 1000
// AllocationSiteMode controls whether allocations are tracked by an allocation
// site.
enum AllocationSiteMode {
  DONT_TRACK_ALLOCATION_SITE,
  TRACK_ALLOCATION_SITE,
  LAST_ALLOCATION_SITE_MODE = TRACK_ALLOCATION_SITE
};

1001 1002
enum class AllocationSiteUpdateMode { kUpdate, kCheckOnly };

1003
// The mips architecture prior to revision 5 has inverted encoding for sNaN.
1004 1005 1006
#if (V8_TARGET_ARCH_MIPS && !defined(_MIPS_ARCH_MIPS32R6) &&           \
     (!defined(USE_SIMULATOR) || !defined(_MIPS_TARGET_SIMULATOR))) || \
    (V8_TARGET_ARCH_MIPS64 && !defined(_MIPS_ARCH_MIPS64R6) &&         \
Jakob Kummerow's avatar
Jakob Kummerow committed
1007
     (!defined(USE_SIMULATOR) || !defined(_MIPS_TARGET_SIMULATOR)))
1008 1009
constexpr uint32_t kHoleNanUpper32 = 0xFFFF7FFF;
constexpr uint32_t kHoleNanLower32 = 0xFFFF7FFF;
1010
#else
1011 1012
constexpr uint32_t kHoleNanUpper32 = 0xFFF7FFFF;
constexpr uint32_t kHoleNanLower32 = 0xFFF7FFFF;
1013
#endif
1014

1015
constexpr uint64_t kHoleNanInt64 =
1016 1017
    (static_cast<uint64_t>(kHoleNanUpper32) << 32) | kHoleNanLower32;

1018
// ES6 section 20.1.2.6 Number.MAX_SAFE_INTEGER
1019
constexpr double kMaxSafeInteger = 9007199254740991.0;  // 2^53-1
1020

1021
// The order of this enum has to be kept in sync with the predicates below.
1022
enum class VariableMode : uint8_t {
1023
  // User declared variables:
1024
  kLet,  // declared via 'let' declarations (first lexical)
1025

1026
  kConst,  // declared via 'const' declarations (last lexical)
1027

1028
  kVar,  // declared via 'var', and 'function' declarations
1029

1030
  // Variables introduced by the compiler:
1031 1032
  kTemporary,  // temporary variables (not user-visible), stack-allocated
               // unless the scope as a whole has forced context allocation
1033

1034 1035
  kDynamic,  // always require dynamic lookup (we don't know
             // the declaration)
1036

1037
  kDynamicGlobal,  // requires dynamic lookup, but we know that the
1038 1039 1040
                   // variable is global unless it has been shadowed
                   // by an eval-introduced variable

1041
  kDynamicLocal  // requires dynamic lookup, but we know that the
1042 1043 1044
                 // variable is local and where it is unless it
                 // has been shadowed by an eval-introduced
                 // variable
1045 1046
};

1047 1048 1049 1050
// Printing support
#ifdef DEBUG
inline const char* VariableMode2String(VariableMode mode) {
  switch (mode) {
1051
    case VariableMode::kVar:
1052
      return "VAR";
1053
    case VariableMode::kLet:
1054
      return "LET";
1055
    case VariableMode::kConst:
1056
      return "CONST";
1057
    case VariableMode::kDynamic:
1058
      return "DYNAMIC";
1059
    case VariableMode::kDynamicGlobal:
1060
      return "DYNAMIC_GLOBAL";
1061
    case VariableMode::kDynamicLocal:
1062
      return "DYNAMIC_LOCAL";
1063
    case VariableMode::kTemporary:
1064 1065 1066 1067 1068 1069 1070 1071 1072
      return "TEMPORARY";
  }
  UNREACHABLE();
}
#endif

enum VariableKind : uint8_t {
  NORMAL_VARIABLE,
  THIS_VARIABLE,
1073
  SLOPPY_FUNCTION_NAME_VARIABLE
1074 1075
};

1076
inline bool IsDynamicVariableMode(VariableMode mode) {
1077
  return mode >= VariableMode::kDynamic && mode <= VariableMode::kDynamicLocal;
1078 1079 1080
}

inline bool IsDeclaredVariableMode(VariableMode mode) {
1081 1082 1083
  STATIC_ASSERT(static_cast<uint8_t>(VariableMode::kLet) ==
                0);  // Implies that mode >= VariableMode::kLet.
  return mode <= VariableMode::kVar;
1084 1085 1086
}

inline bool IsLexicalVariableMode(VariableMode mode) {
1087 1088 1089
  STATIC_ASSERT(static_cast<uint8_t>(VariableMode::kLet) ==
                0);  // Implies that mode >= VariableMode::kLet.
  return mode <= VariableMode::kConst;
1090 1091
}

1092
enum VariableLocation : uint8_t {
1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115
  // Before and during variable allocation, a variable whose location is
  // not yet determined.  After allocation, a variable looked up as a
  // property on the global object (and possibly absent).  name() is the
  // variable name, index() is invalid.
  UNALLOCATED,

  // A slot in the parameter section on the stack.  index() is the
  // parameter index, counting left-to-right.  The receiver is index -1;
  // the first parameter is index 0.
  PARAMETER,

  // A slot in the local section on the stack.  index() is the variable
  // index in the stack frame, starting at 0.
  LOCAL,

  // An indexed slot in a heap context.  index() is the variable index in
  // the context object on the heap, starting at 0.  scope() is the
  // corresponding scope.
  CONTEXT,

  // A named slot in a heap context.  name() is the variable name in the
  // context object on the heap, with lookup starting at the current
  // context.  index() is invalid.
1116
  LOOKUP,
1117

1118
  // A named slot in a module's export table.
1119 1120 1121
  MODULE,

  kLastVariableLocation = MODULE
1122
};
1123

1124 1125 1126 1127 1128 1129
// ES6 specifies declarative environment records with mutable and immutable
// bindings that can be in two states: initialized and uninitialized.
// When accessing a binding, it needs to be checked for initialization.
// However in the following cases the binding is initialized immediately
// after creation so the initialization check can always be skipped:
//
1130 1131 1132 1133 1134 1135 1136 1137
// 1. Var declared local variables.
//      var foo;
// 2. A local variable introduced by a function declaration.
//      function foo() {}
// 3. Parameters
//      function x(foo) {}
// 4. Catch bound variables.
//      try {} catch (foo) {}
1138
// 6. Function name variables of named function expressions.
1139 1140 1141 1142 1143 1144 1145
//      var x = function foo() {}
// 7. Implicit binding of 'this'.
// 8. Implicit binding of 'arguments' in functions.
//
// The following enum specifies a flag that indicates if the binding needs a
// distinct initialization step (kNeedsInitialization) or if the binding is
// immediately initialized upon creation (kCreatedInitialized).
1146
enum InitializationFlag : uint8_t { kNeedsInitialization, kCreatedInitialized };
1147

1148
enum MaybeAssignedFlag : uint8_t { kNotAssigned, kMaybeAssigned };
1149

1150 1151
enum ParseErrorType { kSyntaxError = 0, kReferenceError = 1 };

1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162
enum FunctionKind : uint8_t {
  kNormalFunction,
  kArrowFunction,
  kGeneratorFunction,
  kConciseMethod,
  kDerivedConstructor,
  kBaseConstructor,
  kGetterFunction,
  kSetterFunction,
  kAsyncFunction,
  kModule,
1163
  kClassMembersInitializerFunction,
1164 1165 1166 1167 1168 1169 1170 1171 1172 1173

  kDefaultBaseConstructor,
  kDefaultDerivedConstructor,
  kAsyncArrowFunction,
  kAsyncConciseMethod,

  kConciseGeneratorMethod,
  kAsyncConciseGeneratorMethod,
  kAsyncGeneratorFunction,
  kLastFunctionKind = kAsyncGeneratorFunction,
1174 1175
};

1176
inline bool IsArrowFunction(FunctionKind kind) {
1177 1178
  return kind == FunctionKind::kArrowFunction ||
         kind == FunctionKind::kAsyncArrowFunction;
1179 1180
}

1181 1182
inline bool IsModule(FunctionKind kind) {
  return kind == FunctionKind::kModule;
1183 1184
}

1185 1186 1187
inline bool IsAsyncGeneratorFunction(FunctionKind kind) {
  return kind == FunctionKind::kAsyncGeneratorFunction ||
         kind == FunctionKind::kAsyncConciseGeneratorMethod;
1188
}
1189

1190 1191 1192 1193
inline bool IsGeneratorFunction(FunctionKind kind) {
  return kind == FunctionKind::kGeneratorFunction ||
         kind == FunctionKind::kConciseGeneratorMethod ||
         IsAsyncGeneratorFunction(kind);
1194 1195
}

1196 1197 1198 1199 1200
inline bool IsAsyncFunction(FunctionKind kind) {
  return kind == FunctionKind::kAsyncFunction ||
         kind == FunctionKind::kAsyncArrowFunction ||
         kind == FunctionKind::kAsyncConciseMethod ||
         IsAsyncGeneratorFunction(kind);
1201 1202
}

1203
inline bool IsResumableFunction(FunctionKind kind) {
1204
  return IsGeneratorFunction(kind) || IsAsyncFunction(kind) || IsModule(kind);
1205 1206
}

1207
inline bool IsConciseMethod(FunctionKind kind) {
1208 1209 1210 1211
  return kind == FunctionKind::kConciseMethod ||
         kind == FunctionKind::kConciseGeneratorMethod ||
         kind == FunctionKind::kAsyncConciseMethod ||
         kind == FunctionKind::kAsyncConciseGeneratorMethod ||
1212
         kind == FunctionKind::kClassMembersInitializerFunction;
1213
}
1214

1215
inline bool IsGetterFunction(FunctionKind kind) {
1216
  return kind == FunctionKind::kGetterFunction;
1217 1218 1219
}

inline bool IsSetterFunction(FunctionKind kind) {
1220
  return kind == FunctionKind::kSetterFunction;
1221
}
1222

1223
inline bool IsAccessorFunction(FunctionKind kind) {
1224 1225
  return kind == FunctionKind::kGetterFunction ||
         kind == FunctionKind::kSetterFunction;
1226 1227
}

1228
inline bool IsDefaultConstructor(FunctionKind kind) {
1229 1230
  return kind == FunctionKind::kDefaultBaseConstructor ||
         kind == FunctionKind::kDefaultDerivedConstructor;
1231 1232
}

1233
inline bool IsBaseConstructor(FunctionKind kind) {
1234 1235
  return kind == FunctionKind::kBaseConstructor ||
         kind == FunctionKind::kDefaultBaseConstructor;
1236 1237
}

1238
inline bool IsDerivedConstructor(FunctionKind kind) {
1239 1240
  return kind == FunctionKind::kDerivedConstructor ||
         kind == FunctionKind::kDefaultDerivedConstructor;
1241
}
1242 1243


1244
inline bool IsClassConstructor(FunctionKind kind) {
1245
  return IsBaseConstructor(kind) || IsDerivedConstructor(kind);
1246
}
1247

1248 1249
inline bool IsClassMembersInitializerFunction(FunctionKind kind) {
  return kind == FunctionKind::kClassMembersInitializerFunction;
1250 1251
}

1252
inline bool IsConstructable(FunctionKind kind) {
1253
  if (IsAccessorFunction(kind)) return false;
1254
  if (IsConciseMethod(kind)) return false;
1255
  if (IsArrowFunction(kind)) return false;
1256
  if (IsGeneratorFunction(kind)) return false;
1257
  if (IsAsyncFunction(kind)) return false;
1258 1259 1260
  return true;
}

1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282
inline std::ostream& operator<<(std::ostream& os, FunctionKind kind) {
  switch (kind) {
    case FunctionKind::kNormalFunction:
      return os << "NormalFunction";
    case FunctionKind::kArrowFunction:
      return os << "ArrowFunction";
    case FunctionKind::kGeneratorFunction:
      return os << "GeneratorFunction";
    case FunctionKind::kConciseMethod:
      return os << "ConciseMethod";
    case FunctionKind::kDerivedConstructor:
      return os << "DerivedConstructor";
    case FunctionKind::kBaseConstructor:
      return os << "BaseConstructor";
    case FunctionKind::kGetterFunction:
      return os << "GetterFunction";
    case FunctionKind::kSetterFunction:
      return os << "SetterFunction";
    case FunctionKind::kAsyncFunction:
      return os << "AsyncFunction";
    case FunctionKind::kModule:
      return os << "Module";
1283 1284
    case FunctionKind::kClassMembersInitializerFunction:
      return os << "ClassMembersInitializerFunction";
1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302
    case FunctionKind::kDefaultBaseConstructor:
      return os << "DefaultBaseConstructor";
    case FunctionKind::kDefaultDerivedConstructor:
      return os << "DefaultDerivedConstructor";
    case FunctionKind::kAsyncArrowFunction:
      return os << "AsyncArrowFunction";
    case FunctionKind::kAsyncConciseMethod:
      return os << "AsyncConciseMethod";
    case FunctionKind::kConciseGeneratorMethod:
      return os << "ConciseGeneratorMethod";
    case FunctionKind::kAsyncConciseGeneratorMethod:
      return os << "AsyncConciseGeneratorMethod";
    case FunctionKind::kAsyncGeneratorFunction:
      return os << "AsyncGeneratorFunction";
  }
  UNREACHABLE();
}

1303
enum class InterpreterPushArgsMode : unsigned {
1304
  kArrayFunction,
1305 1306 1307 1308
  kWithFinalSpread,
  kOther
};

1309
inline size_t hash_value(InterpreterPushArgsMode mode) {
1310 1311 1312
  return bit_cast<unsigned>(mode);
}

1313 1314
inline std::ostream& operator<<(std::ostream& os,
                                InterpreterPushArgsMode mode) {
1315
  switch (mode) {
1316 1317
    case InterpreterPushArgsMode::kArrayFunction:
      return os << "ArrayFunction";
1318
    case InterpreterPushArgsMode::kWithFinalSpread:
1319
      return os << "WithFinalSpread";
1320
    case InterpreterPushArgsMode::kOther:
1321 1322 1323 1324 1325
      return os << "Other";
  }
  UNREACHABLE();
}

1326 1327 1328
inline uint32_t ObjectHash(Address address) {
  // All objects are at least pointer aligned, so we can remove the trailing
  // zeros.
1329
  return static_cast<uint32_t>(address >> kTaggedSizeLog2);
1330 1331
}

1332
// Type feedback is encoded in such a way that, we can combine the feedback
1333 1334
// at different points by performing an 'OR' operation. Type feedback moves
// to a more generic type when we combine feedback.
1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345
//
//   kSignedSmall -> kSignedSmallInputs -> kNumber  -> kNumberOrOddball -> kAny
//                                                     kString          -> kAny
//                                                     kBigInt          -> kAny
//
// Technically we wouldn't need the separation between the kNumber and the
// kNumberOrOddball values here, since for binary operations, we always
// truncate oddballs to numbers. In practice though it causes TurboFan to
// generate quite a lot of unused code though if we always handle numbers
// and oddballs everywhere, although in 99% of the use sites they are only
// used with numbers.
1346 1347
class BinaryOperationFeedback {
 public:
1348 1349 1350
  enum {
    kNone = 0x0,
    kSignedSmall = 0x1,
1351
    kSignedSmallInputs = 0x3,
1352 1353 1354
    kNumber = 0x7,
    kNumberOrOddball = 0xF,
    kString = 0x10,
1355 1356
    kBigInt = 0x20,
    kAny = 0x7F
1357
  };
1358 1359
};

1360 1361 1362
// Type feedback is encoded in such a way that, we can combine the feedback
// at different points by performing an 'OR' operation. Type feedback moves
// to a more generic type when we combine feedback.
1363
//
1364 1365 1366 1367 1368
//   kSignedSmall -> kNumber             -> kNumberOrOddball           -> kAny
//                   kReceiver           -> kReceiverOrNullOrUndefined -> kAny
//                   kInternalizedString -> kString                    -> kAny
//                                          kSymbol                    -> kAny
//                                          kBigInt                    -> kAny
1369 1370 1371
//
// This is distinct from BinaryOperationFeedback on purpose, because the
// feedback that matters differs greatly as well as the way it is consumed.
1372 1373
class CompareOperationFeedback {
 public:
1374
  enum {
1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385
    kNone = 0x000,
    kSignedSmall = 0x001,
    kNumber = 0x003,
    kNumberOrOddball = 0x007,
    kInternalizedString = 0x008,
    kString = 0x018,
    kSymbol = 0x020,
    kBigInt = 0x040,
    kReceiver = 0x080,
    kReceiverOrNullOrUndefined = 0x180,
    kAny = 0x1ff
1386
  };
1387 1388
};

1389 1390 1391 1392 1393 1394 1395
enum class Operation {
  // Binary operations.
  kAdd,
  kSubtract,
  kMultiply,
  kDivide,
  kModulus,
1396
  kExponentiate,
1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416
  kBitwiseAnd,
  kBitwiseOr,
  kBitwiseXor,
  kShiftLeft,
  kShiftRight,
  kShiftRightLogical,
  // Unary operations.
  kBitwiseNot,
  kNegate,
  kIncrement,
  kDecrement,
  // Compare operations.
  kEqual,
  kStrictEqual,
  kLessThan,
  kLessThanOrEqual,
  kGreaterThan,
  kGreaterThanOrEqual,
};

1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437
// Type feedback is encoded in such a way that, we can combine the feedback
// at different points by performing an 'OR' operation. Type feedback moves
// to a more generic type when we combine feedback.
// kNone -> kEnumCacheKeysAndIndices -> kEnumCacheKeys -> kAny
class ForInFeedback {
 public:
  enum {
    kNone = 0x0,
    kEnumCacheKeysAndIndices = 0x1,
    kEnumCacheKeys = 0x3,
    kAny = 0x7
  };
};
STATIC_ASSERT((ForInFeedback::kNone |
               ForInFeedback::kEnumCacheKeysAndIndices) ==
              ForInFeedback::kEnumCacheKeysAndIndices);
STATIC_ASSERT((ForInFeedback::kEnumCacheKeysAndIndices |
               ForInFeedback::kEnumCacheKeys) == ForInFeedback::kEnumCacheKeys);
STATIC_ASSERT((ForInFeedback::kEnumCacheKeys | ForInFeedback::kAny) ==
              ForInFeedback::kAny);

1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457
enum class UnicodeEncoding : uint8_t {
  // Different unicode encodings in a |word32|:
  UTF16,  // hi 16bits -> trailing surrogate or 0, low 16bits -> lead surrogate
  UTF32,  // full UTF32 code unit / Unicode codepoint
};

inline size_t hash_value(UnicodeEncoding encoding) {
  return static_cast<uint8_t>(encoding);
}

inline std::ostream& operator<<(std::ostream& os, UnicodeEncoding encoding) {
  switch (encoding) {
    case UnicodeEncoding::UTF16:
      return os << "UTF16";
    case UnicodeEncoding::UTF32:
      return os << "UTF32";
  }
  UNREACHABLE();
}

1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471
enum class IterationKind { kKeys, kValues, kEntries };

inline std::ostream& operator<<(std::ostream& os, IterationKind kind) {
  switch (kind) {
    case IterationKind::kKeys:
      return os << "IterationKind::kKeys";
    case IterationKind::kValues:
      return os << "IterationKind::kValues";
    case IterationKind::kEntries:
      return os << "IterationKind::kEntries";
  }
  UNREACHABLE();
}

1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483
enum class CollectionKind { kMap, kSet };

inline std::ostream& operator<<(std::ostream& os, CollectionKind kind) {
  switch (kind) {
    case CollectionKind::kMap:
      return os << "CollectionKind::kMap";
    case CollectionKind::kSet:
      return os << "CollectionKind::kSet";
  }
  UNREACHABLE();
}

1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494
// Flags for the runtime function kDefineDataPropertyInLiteral. A property can
// be enumerable or not, and, in case of functions, the function name
// can be set or not.
enum class DataPropertyInLiteralFlag {
  kNoFlags = 0,
  kDontEnum = 1 << 0,
  kSetFunctionName = 1 << 1
};
typedef base::Flags<DataPropertyInLiteralFlag> DataPropertyInLiteralFlags;
DEFINE_OPERATORS_FOR_FLAGS(DataPropertyInLiteralFlags)

1495 1496 1497 1498 1499 1500 1501 1502 1503 1504
enum ExternalArrayType {
  kExternalInt8Array = 1,
  kExternalUint8Array,
  kExternalInt16Array,
  kExternalUint16Array,
  kExternalInt32Array,
  kExternalUint32Array,
  kExternalFloat32Array,
  kExternalFloat64Array,
  kExternalUint8ClampedArray,
1505 1506
  kExternalBigInt64Array,
  kExternalBigUint64Array,
1507 1508
};

1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522
struct AssemblerDebugInfo {
  AssemblerDebugInfo(const char* name, const char* file, int line)
      : name(name), file(file), line(line) {}
  const char* name;
  const char* file;
  int line;
};

inline std::ostream& operator<<(std::ostream& os,
                                const AssemblerDebugInfo& info) {
  os << "(" << info.name << ":" << info.file << ":" << info.line << ")";
  return os;
}

1523
enum class OptimizationMarker {
1524
  kLogFirstExecution,
1525 1526 1527 1528 1529 1530 1531 1532 1533
  kNone,
  kCompileOptimized,
  kCompileOptimizedConcurrent,
  kInOptimizationQueue
};

inline std::ostream& operator<<(std::ostream& os,
                                const OptimizationMarker& marker) {
  switch (marker) {
1534 1535
    case OptimizationMarker::kLogFirstExecution:
      return os << "OptimizationMarker::kLogFirstExecution";
1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548
    case OptimizationMarker::kNone:
      return os << "OptimizationMarker::kNone";
    case OptimizationMarker::kCompileOptimized:
      return os << "OptimizationMarker::kCompileOptimized";
    case OptimizationMarker::kCompileOptimizedConcurrent:
      return os << "OptimizationMarker::kCompileOptimizedConcurrent";
    case OptimizationMarker::kInOptimizationQueue:
      return os << "OptimizationMarker::kInOptimizationQueue";
  }
  UNREACHABLE();
  return os;
}

1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562
enum class SpeculationMode { kAllowSpeculation, kDisallowSpeculation };

inline std::ostream& operator<<(std::ostream& os,
                                SpeculationMode speculation_mode) {
  switch (speculation_mode) {
    case SpeculationMode::kAllowSpeculation:
      return os << "SpeculationMode::kAllowSpeculation";
    case SpeculationMode::kDisallowSpeculation:
      return os << "SpeculationMode::kDisallowSpeculation";
  }
  UNREACHABLE();
  return os;
}

1563 1564
enum class BlockingBehavior { kBlock, kDontBlock };

1565 1566
enum class ConcurrencyMode { kNotConcurrent, kConcurrent };

1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578
#define FOR_EACH_ISOLATE_ADDRESS_NAME(C)                       \
  C(Handler, handler)                                          \
  C(CEntryFP, c_entry_fp)                                      \
  C(CFunction, c_function)                                     \
  C(Context, context)                                          \
  C(PendingException, pending_exception)                       \
  C(PendingHandlerContext, pending_handler_context)            \
  C(PendingHandlerEntrypoint, pending_handler_entrypoint)      \
  C(PendingHandlerConstantPool, pending_handler_constant_pool) \
  C(PendingHandlerFP, pending_handler_fp)                      \
  C(PendingHandlerSP, pending_handler_sp)                      \
  C(ExternalCaughtException, external_caught_exception)        \
1579
  C(JSEntrySP, js_entry_sp)
1580 1581 1582 1583 1584 1585 1586 1587

enum IsolateAddressId {
#define DECLARE_ENUM(CamelName, hacker_name) k##CamelName##Address,
  FOR_EACH_ISOLATE_ADDRESS_NAME(DECLARE_ENUM)
#undef DECLARE_ENUM
      kIsolateAddressCount
};

1588 1589 1590
V8_INLINE static bool HasWeakHeapObjectTag(Address value) {
  // TODO(jkummerow): Consolidate integer types here.
  return ((static_cast<intptr_t>(value) & kHeapObjectTagMask) ==
1591 1592 1593 1594 1595 1596 1597 1598 1599 1600
          kWeakHeapObjectTag);
}

// Object* should never have the weak tag; this variant is for overzealous
// checking.
V8_INLINE static bool HasWeakHeapObjectTag(const Object* value) {
  return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) ==
          kWeakHeapObjectTag);
}

1601 1602 1603 1604 1605
enum class HeapObjectReferenceType {
  WEAK,
  STRONG,
};

1606 1607 1608 1609 1610
enum class PoisoningMitigationLevel {
  kPoisonAll,
  kDontPoison,
  kPoisonCriticalOnly
};
1611

1612 1613 1614 1615 1616 1617 1618
enum class LoadSensitivity {
  kCritical,  // Critical loads are poisoned whenever we can run untrusted
              // code (i.e., when --untrusted-code-mitigations is on).
  kUnsafe,    // Unsafe loads are poisoned when full poisoning is on
              // (--branch-load-poisoning).
  kSafe       // Safe loads are never poisoned.
};
1619

1620 1621 1622 1623
// The reason for a WebAssembly trap.
#define FOREACH_WASM_TRAPREASON(V) \
  V(TrapUnreachable)               \
  V(TrapMemOutOfBounds)            \
1624
  V(TrapUnalignedAccess)           \
1625 1626 1627 1628 1629 1630 1631
  V(TrapDivByZero)                 \
  V(TrapDivUnrepresentable)        \
  V(TrapRemByZero)                 \
  V(TrapFloatUnrepresentable)      \
  V(TrapFuncInvalid)               \
  V(TrapFuncSigMismatch)

1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690
enum KeyedAccessLoadMode {
  STANDARD_LOAD,
  LOAD_IGNORE_OUT_OF_BOUNDS,
};

enum KeyedAccessStoreMode {
  STANDARD_STORE,
  STORE_TRANSITION_TO_OBJECT,
  STORE_TRANSITION_TO_DOUBLE,
  STORE_AND_GROW_NO_TRANSITION_HANDLE_COW,
  STORE_AND_GROW_TRANSITION_TO_OBJECT,
  STORE_AND_GROW_TRANSITION_TO_DOUBLE,
  STORE_NO_TRANSITION_IGNORE_OUT_OF_BOUNDS,
  STORE_NO_TRANSITION_HANDLE_COW
};

enum MutableMode { MUTABLE, IMMUTABLE };

static inline bool IsTransitionStoreMode(KeyedAccessStoreMode store_mode) {
  return store_mode == STORE_TRANSITION_TO_OBJECT ||
         store_mode == STORE_TRANSITION_TO_DOUBLE ||
         store_mode == STORE_AND_GROW_TRANSITION_TO_OBJECT ||
         store_mode == STORE_AND_GROW_TRANSITION_TO_DOUBLE;
}

static inline bool IsCOWHandlingStoreMode(KeyedAccessStoreMode store_mode) {
  return store_mode == STORE_NO_TRANSITION_HANDLE_COW ||
         store_mode == STORE_AND_GROW_NO_TRANSITION_HANDLE_COW;
}

static inline KeyedAccessStoreMode GetNonTransitioningStoreMode(
    KeyedAccessStoreMode store_mode, bool receiver_was_cow) {
  switch (store_mode) {
    case STORE_AND_GROW_NO_TRANSITION_HANDLE_COW:
    case STORE_AND_GROW_TRANSITION_TO_OBJECT:
    case STORE_AND_GROW_TRANSITION_TO_DOUBLE:
      store_mode = STORE_AND_GROW_NO_TRANSITION_HANDLE_COW;
      break;
    case STANDARD_STORE:
    case STORE_TRANSITION_TO_OBJECT:
    case STORE_TRANSITION_TO_DOUBLE:
      store_mode =
          receiver_was_cow ? STORE_NO_TRANSITION_HANDLE_COW : STANDARD_STORE;
      break;
    case STORE_NO_TRANSITION_IGNORE_OUT_OF_BOUNDS:
    case STORE_NO_TRANSITION_HANDLE_COW:
      break;
  }
  DCHECK(!IsTransitionStoreMode(store_mode));
  DCHECK_IMPLIES(receiver_was_cow, IsCOWHandlingStoreMode(store_mode));
  return store_mode;
}

static inline bool IsGrowStoreMode(KeyedAccessStoreMode store_mode) {
  return store_mode >= STORE_AND_GROW_NO_TRANSITION_HANDLE_COW &&
         store_mode <= STORE_AND_GROW_TRANSITION_TO_DOUBLE;
}

enum IcCheckType { ELEMENT, PROPERTY };
1691 1692
}  // namespace internal
}  // namespace v8
1693

1694 1695
namespace i = v8::internal;

1696
#endif  // V8_GLOBALS_H_