globals.h 44.8 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 "src/base/build_config.h"
15
#include "src/base/flags.h"
16
#include "src/base/logging.h"
17
#include "src/base/macros.h"
18

19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
#ifdef V8_OS_WIN

// Setup for Windows shared library export.
#ifdef BUILDING_V8_SHARED
#define V8_EXPORT_PRIVATE __declspec(dllexport)
#elif USING_V8_SHARED
#define V8_EXPORT_PRIVATE __declspec(dllimport)
#else
#define V8_EXPORT_PRIVATE
#endif  // BUILDING_V8_SHARED

#else  // V8_OS_WIN

// Setup for Linux shared library export.
#if V8_HAS_ATTRIBUTE_VISIBILITY
#ifdef BUILDING_V8_SHARED
#define V8_EXPORT_PRIVATE __attribute__((visibility("default")))
#else
#define V8_EXPORT_PRIVATE
#endif
#else
#define V8_EXPORT_PRIVATE
#endif

#endif  // V8_OS_WIN

45
#define V8_INFINITY std::numeric_limits<double>::infinity()
46

47
namespace v8 {
48 49 50 51 52 53 54

namespace base {
class Mutex;
class RecursiveMutex;
class VirtualMemory;
}

55
namespace internal {
56

57
// Determine whether we are running in a simulated environment.
58 59 60
// Setting USE_SIMULATOR explicitly from the build script will force
// the use of a simulated environment.
#if !defined(USE_SIMULATOR)
61
#if (V8_TARGET_ARCH_ARM64 && !V8_HOST_ARCH_ARM64)
62 63
#define USE_SIMULATOR 1
#endif
64 65 66
#if (V8_TARGET_ARCH_ARM && !V8_HOST_ARCH_ARM)
#define USE_SIMULATOR 1
#endif
67 68 69
#if (V8_TARGET_ARCH_PPC && !V8_HOST_ARCH_PPC)
#define USE_SIMULATOR 1
#endif
70 71
#if (V8_TARGET_ARCH_MIPS && !V8_HOST_ARCH_MIPS)
#define USE_SIMULATOR 1
72
#endif
73 74 75
#if (V8_TARGET_ARCH_MIPS64 && !V8_HOST_ARCH_MIPS64)
#define USE_SIMULATOR 1
#endif
76 77 78
#if (V8_TARGET_ARCH_S390 && !V8_HOST_ARCH_S390)
#define USE_SIMULATOR 1
#endif
79 80
#endif

81 82 83 84 85 86 87
// Determine whether the architecture uses an embedded constant pool
// (contiguous constant pool embedded in code object).
#if V8_TARGET_ARCH_PPC
#define V8_EMBEDDED_CONSTANT_POOL 1
#else
#define V8_EMBEDDED_CONSTANT_POOL 0
#endif
88

89 90 91 92 93 94 95 96 97 98 99
#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

100 101
// Minimum stack size in KB required by compilers.
const int kStackSpaceRequiredForCompilation = 40;
102

103
// Determine whether double field unboxing feature is enabled.
104
#if V8_TARGET_ARCH_64_BIT
105
#define V8_DOUBLE_FIELDS_UNBOXING 1
106 107 108 109
#else
#define V8_DOUBLE_FIELDS_UNBOXING 0
#endif

110 111 112 113 114
// Some types of tracing require the SFI to store a unique ID.
#if defined(V8_TRACE_MAPS) || defined(V8_TRACE_IGNITION)
#define V8_SFI_HAS_UNIQUE_ID 1
#endif

115 116 117 118 119 120 121 122 123 124 125 126 127
// 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
};

// DEPRECATED
// TODO(leszeks): Delete this during a quiet period
#define BASE_EMBEDDED

128 129 130
typedef uint8_t byte;
typedef byte* Address;

131 132 133 134 135 136 137 138
// -----------------------------------------------------------------------------
// Constants

const int KB = 1024;
const int MB = KB * KB;
const int GB = KB * KB * KB;
const int kMaxInt = 0x7FFFFFFF;
const int kMinInt = -kMaxInt - 1;
139 140 141 142 143 144 145 146
const int kMaxInt8 = (1 << 7) - 1;
const int kMinInt8 = -(1 << 7);
const int kMaxUInt8 = (1 << 8) - 1;
const int kMinUInt8 = 0;
const int kMaxInt16 = (1 << 15) - 1;
const int kMinInt16 = -(1 << 15);
const int kMaxUInt16 = (1 << 16) - 1;
const int kMinUInt16 = 0;
147

148
const uint32_t kMaxUInt32 = 0xFFFFFFFFu;
149
const int kMinUInt32 = 0;
150

151
const int kUInt8Size = sizeof(uint8_t);
152 153
const int kCharSize = sizeof(char);
const int kShortSize = sizeof(short);  // NOLINT
154
const int kUInt16Size = sizeof(uint16_t);
155 156 157
const int kIntSize = sizeof(int);
const int kInt32Size = sizeof(int32_t);
const int kInt64Size = sizeof(int64_t);
158
const int kUInt32Size = sizeof(uint32_t);
159 160 161 162
const int kSizetSize = sizeof(size_t);
const int kFloatSize = sizeof(float);
const int kDoubleSize = sizeof(double);
const int kIntptrSize = sizeof(intptr_t);
163
const int kUIntptrSize = sizeof(uintptr_t);
164
const int kPointerSize = sizeof(void*);
165
#if V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_32_BIT
166
const int kRegisterSize = kPointerSize + kPointerSize;
167
#else
168
const int kRegisterSize = kPointerSize;
169
#endif
170 171
const int kPCOnStackSize = kRegisterSize;
const int kFPOnStackSize = kRegisterSize;
172

Jakob Kummerow's avatar
Jakob Kummerow committed
173
#if V8_TARGET_ARCH_X64 || V8_TARGET_ARCH_IA32
174 175 176 177 178
const int kElidedFrameSlots = kPCOnStackSize / kPointerSize;
#else
const int kElidedFrameSlots = 0;
#endif

179
const int kDoubleSizeLog2 = 3;
180
const size_t kMaxWasmCodeMemory = 256 * MB;
181

182
#if V8_HOST_ARCH_64_BIT
183
const int kPointerSizeLog2 = 3;
184 185
const intptr_t kIntptrSignBit =
    static_cast<intptr_t>(uintptr_t{0x8000000000000000});
186
const uintptr_t kUintptrAllBitsSet = uintptr_t{0xFFFFFFFFFFFFFFFF};
187
const bool kRequiresCodeRange = true;
188 189 190 191 192
#if V8_TARGET_ARCH_MIPS64
// To use pseudo-relative jumps such as j/jal instructions which have 28-bit
// encoded immediate, the addresses have to be in range of 256MB aligned
// region. Used only for large object space.
const size_t kMaximalCodeRangeSize = 256 * MB;
193
const size_t kCodeRangeAreaAlignment = 256 * MB;
194 195 196
#elif V8_HOST_ARCH_PPC && V8_TARGET_ARCH_PPC && V8_OS_LINUX
const size_t kMaximalCodeRangeSize = 512 * MB;
const size_t kCodeRangeAreaAlignment = 64 * KB;  // OS page on PPC Linux
197
#else
198
const size_t kMaximalCodeRangeSize = 512 * MB;
199
const size_t kCodeRangeAreaAlignment = 4 * KB;  // OS page.
200
#endif
201
#if V8_OS_WIN
202
const size_t kMinimumCodeRangeSize = 4 * MB;
203 204
const size_t kReservedCodeRangePages = 1;
#else
205
const size_t kMinimumCodeRangeSize = 3 * MB;
206 207
const size_t kReservedCodeRangePages = 0;
#endif
208
#else
209
const int kPointerSizeLog2 = 2;
210
const intptr_t kIntptrSignBit = 0x80000000;
211
const uintptr_t kUintptrAllBitsSet = 0xFFFFFFFFu;
212 213 214 215
#if V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_32_BIT
// x32 port also requires code range.
const bool kRequiresCodeRange = true;
const size_t kMaximalCodeRangeSize = 256 * MB;
216
const size_t kMinimumCodeRangeSize = 3 * MB;
217
const size_t kCodeRangeAreaAlignment = 4 * KB;  // OS page.
218 219 220 221 222
#elif V8_HOST_ARCH_PPC && V8_TARGET_ARCH_PPC && V8_OS_LINUX
const bool kRequiresCodeRange = false;
const size_t kMaximalCodeRangeSize = 0 * MB;
const size_t kMinimumCodeRangeSize = 0 * MB;
const size_t kCodeRangeAreaAlignment = 64 * KB;  // OS page on PPC Linux
223
#else
224 225
const bool kRequiresCodeRange = false;
const size_t kMaximalCodeRangeSize = 0 * MB;
226
const size_t kMinimumCodeRangeSize = 0 * MB;
227
const size_t kCodeRangeAreaAlignment = 4 * KB;  // OS page.
228
#endif
229
const size_t kReservedCodeRangePages = 0;
230
#endif
231

232 233
// Trigger an incremental GCs once the external memory reaches this limit.
const int kExternalAllocationSoftLimit = 64 * MB;
234

235 236 237 238 239
// 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.
240 241 242
//
// Current value: Page::kAllocatableMemory (on 32-bit arch) - 512 (slack).
const int kMaxRegularHeapObjectSize = 507136;
243

244 245
STATIC_ASSERT(kPointerSize == (1 << kPointerSizeLog2));

246 247 248 249 250
const int kBitsPerByte = 8;
const int kBitsPerByteLog2 = 3;
const int kBitsPerPointer = kPointerSize * kBitsPerByte;
const int kBitsPerInt = kIntSize * kBitsPerByte;

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

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

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
const int kOneByteSize    = kCharSize;
271 272
const int kUC16Size     = sizeof(uc16);      // NOLINT

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

276 277 278 279
// Round up n to be a multiple of sz, where sz is a power of 2.
#define ROUND_UP(n, sz) (((n) + ((sz) - 1)) & ~((sz) - 1))


280 281 282 283 284 285 286 287 288 289 290 291 292
// FUNCTION_ADDR(f) gets the address of a C function f.
#define FUNCTION_ADDR(f)                                        \
  (reinterpret_cast<v8::internal::Address>(reinterpret_cast<intptr_t>(f)))


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


293 294 295 296 297 298 299 300 301 302 303 304 305 306
// 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


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

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

312 313 314 315 316 317
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
318

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

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

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

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

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

346 347 348 349 350 351 352 353 354
// 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));
}

355 356
enum TypeofMode : int { INSIDE_TYPEOF, NOT_INSIDE_TYPEOF };

yangguo's avatar
yangguo committed
357 358
// This constant is used as an undefined value when passing source positions.
const int kNoSourcePosition = -1;
marja's avatar
marja committed
359

360 361 362
// This constant is used to indicate missing deoptimization information.
const int kNoDeoptimizationId = -1;

363
// Deoptimize bailout kind.
364
enum class DeoptimizeKind : uint8_t { kEager, kSoft, kLazy };
365 366 367 368 369 370 371 372 373
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";
374 375
    case DeoptimizeKind::kLazy:
      return os << "Lazy";
376 377 378 379
  }
  UNREACHABLE();
}

380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
// 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();
}

395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
// Mask for the sign bit in a smi.
const intptr_t kSmiSignMask = kIntptrSignBit;

const int kObjectAlignmentBits = kPointerSizeLog2;
const intptr_t kObjectAlignment = 1 << kObjectAlignmentBits;
const intptr_t kObjectAlignmentMask = kObjectAlignment - 1;

// Desired alignment for pointers.
const intptr_t kPointerAlignment = (1 << kPointerSizeLog2);
const intptr_t kPointerAlignmentMask = kPointerAlignment - 1;

// Desired alignment for double values.
const intptr_t kDoubleAlignment = 8;
const intptr_t kDoubleAlignmentMask = kDoubleAlignment - 1;

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

416 417 418 419 420 421 422 423 424
// The owner field of a page is tagged with the page header tag. We need that
// to find out if a slot is part of a large object. If we mask out the lower
// 0xfffff bits (1M pages), go to the owner offset, and see that this field
// is tagged with the page header tag, we can just look up the owner.
// Otherwise, we know that we are somewhere (not within the first 1M) in a
// large object.
const int kPageHeaderTag = 3;
const int kPageHeaderTagSize = 2;
const intptr_t kPageHeaderTagMask = (1 << kPageHeaderTagSize) - 1;
425

426 427 428 429 430

// 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
const Address kZapValue =
431
    reinterpret_cast<Address>(uint64_t{0xdeadbeedbeadbeef});
432
const Address kHandleZapValue =
433
    reinterpret_cast<Address>(uint64_t{0x1baddead0baddeaf});
434
const Address kGlobalHandleZapValue =
435
    reinterpret_cast<Address>(uint64_t{0x1baffed00baffedf});
436
const Address kFromSpaceZapValue =
437 438 439
    reinterpret_cast<Address>(uint64_t{0x1beefdad0beefdaf});
const uint64_t kDebugZapValue = uint64_t{0xbadbaddbbadbaddb};
const uint64_t kSlotsZapValue = uint64_t{0xbeefdeadbeefdeef};
440 441 442 443 444 445 446 447 448 449 450 451
const uint64_t kFreeListZapValue = 0xfeed1eaffeed1eaf;
#else
const Address kZapValue = reinterpret_cast<Address>(0xdeadbeef);
const Address kHandleZapValue = reinterpret_cast<Address>(0xbaddeaf);
const Address kGlobalHandleZapValue = reinterpret_cast<Address>(0xbaffedf);
const Address kFromSpaceZapValue = reinterpret_cast<Address>(0xbeefdaf);
const uint32_t kSlotsZapValue = 0xbeefdeef;
const uint32_t kDebugZapValue = 0xbadbaddb;
const uint32_t kFreeListZapValue = 0xfeed1eaf;
#endif

const int kCodeZapValue = 0xbadc0de;
452
const uint32_t kPhantomReferenceZap = 0xca11bac;
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479

// 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.
const uint32_t kQuietNaNHighBitsMask = 0xfff << (51 - 32);


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

class AccessorInfo;
class Arguments;
class Assembler;
class Code;
class CodeStub;
class Context;
class Debug;
class DebugInfo;
class Descriptor;
class DescriptorArray;
class TransitionArray;
class ExternalReference;
class FixedArray;
480
class FreeStoreAllocationPolicy;
481 482
class FunctionTemplateInfo;
class MemoryChunk;
483
class NumberDictionary;
484
class NameDictionary;
485
class GlobalDictionary;
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504
template <typename T> class MaybeHandle;
template <typename T> class Handle;
class Heap;
class HeapObject;
class IC;
class InterceptorInfo;
class Isolate;
class JSReceiver;
class JSArray;
class JSFunction;
class JSObject;
class LargeObjectSpace;
class MacroAssembler;
class Map;
class MapSpace;
class MarkCompactCollector;
class NewSpace;
class Object;
class OldSpace;
505
class ParameterCount;
506 507
class Foreign;
class Scope;
508
class DeclarationScope;
509
class ModuleScope;
510 511 512 513
class ScopeInfo;
class Script;
class Smi;
template <typename Config, class Allocator = FreeStoreAllocationPolicy>
514
class SplayTree;
515
class String;
516
class Symbol;
517 518
class Name;
class Struct;
519
class FeedbackVector;
520 521 522 523 524 525 526 527 528 529 530 531 532
class Variable;
class RelocInfo;
class MessageLocation;

typedef bool (*WeakSlotCallback)(Object** pointer);

typedef bool (*WeakSlotCallbackWithHeap)(Heap* heap, Object** pointer);

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

// NOTE: SpaceIterator depends on AllocationSpace enumeration values being
// consecutive.
533
// Keep this enum in sync with the ObjectSpace enum in v8.h
534
enum AllocationSpace {
535 536 537 538 539
  NEW_SPACE,   // Semispaces collected with copying collector.
  OLD_SPACE,   // May contain pointers to new space.
  CODE_SPACE,  // No pointers to new space, marked executable.
  MAP_SPACE,   // Only and all map objects.
  LO_SPACE,    // Promoted large objects.
540 541 542

  FIRST_SPACE = NEW_SPACE,
  LAST_SPACE = LO_SPACE,
543
  FIRST_PAGED_SPACE = OLD_SPACE,
544
  LAST_PAGED_SPACE = MAP_SPACE
545 546 547 548
};
const int kSpaceTagSize = 3;
const int kSpaceTagMask = (1 << kSpaceTagSize) - 1;

549
enum AllocationAlignment { kWordAligned, kDoubleAligned, kDoubleUnaligned };
550

551 552
enum class AccessMode { ATOMIC, NON_ATOMIC };

553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571
// Possible outcomes for decisions.
enum class Decision : uint8_t { kUnknown, kTrue, kFalse };

inline size_t hash_value(Decision decision) {
  return static_cast<uint8_t>(decision);
}

inline std::ostream& operator<<(std::ostream& os, Decision decision) {
  switch (decision) {
    case Decision::kUnknown:
      return os << "Unknown";
    case Decision::kTrue:
      return os << "True";
    case Decision::kFalse:
      return os << "False";
  }
  UNREACHABLE();
}

572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597
// 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();
}

598 599 600 601 602 603
// A flag that indicates whether objects should be pretenured when
// allocated (allocated directly into the old generation) or not
// (allocated in the young generation if the object size and type
// allows).
enum PretenureFlag { NOT_TENURED, TENURED };

604 605 606 607 608 609 610 611 612 613
inline std::ostream& operator<<(std::ostream& os, const PretenureFlag& flag) {
  switch (flag) {
    case NOT_TENURED:
      return os << "NotTenured";
    case TENURED:
      return os << "Tenured";
  }
  UNREACHABLE();
}

614 615 616 617 618
enum MinimumCapacity {
  USE_DEFAULT_MINIMUM_CAPACITY,
  USE_CUSTOM_MINIMUM_CAPACITY
};

619
enum GarbageCollector { SCAVENGER, MARK_COMPACTOR, MINOR_MARK_COMPACTOR };
620 621 622

enum Executability { NOT_EXECUTABLE, EXECUTABLE };

623 624
enum Movability { kMovable, kImmovable };

625 626
enum VisitMode {
  VISIT_ALL,
627
  VISIT_ALL_IN_MINOR_MC_MARK,
628
  VISIT_ALL_IN_MINOR_MC_UPDATE,
629 630
  VISIT_ALL_IN_SCAVENGE,
  VISIT_ALL_IN_SWEEP_NEWSPACE,
631
  VISIT_ONLY_STRONG,
632
  VISIT_ONLY_STRONG_FOR_SERIALIZATION,
633 634 635
};

// Flag indicating whether code is built into the VM (one of the natives files).
636 637 638 639 640 641
enum NativesFlag {
  NOT_NATIVES_CODE,
  EXTENSION_CODE,
  NATIVES_CODE,
  INSPECTOR_CODE
};
642

643 644
// JavaScript defines two kinds of 'nil'.
enum NilValue { kNullValue, kUndefinedValue };
645

646 647 648 649 650 651 652
// 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.
};

653 654 655
// 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
656 657
// the buffer and grows backward.  A constant pool may exist at the
// end of the instructions.
658
//
659 660 661 662 663 664
//  |<--------------- buffer_size ----------------------------------->|
//  |<------------- instr_size ---------->|        |<-- reloc_size -->|
//  |               |<- const_pool_size ->|                           |
//  +=====================================+========+==================+
//  |  instructions |        data         |  free  |    reloc info    |
//  +=====================================+========+==================+
665 666 667 668 669 670 671 672 673
//  ^
//  |
//  buffer

struct CodeDesc {
  byte* buffer;
  int buffer_size;
  int instr_size;
  int reloc_size;
674
  int constant_pool_size;
675 676
  byte* unwinding_info;
  int unwinding_info_size;
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699
  Assembler* origin;
};


// Callback function used for checking constraints when copying/relocating
// objects. Returns true if an object can be copied/relocated from its
// old_addr to a new_addr.
typedef bool (*ConstraintCallback)(Address new_addr, Address old_addr);


// Callback function on inline caches, used for iterating over inline caches
// in compiled code.
typedef void (*InlineCacheCallback)(Code* code, Address ic);


// 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,
700
  // Check failed due to prototype (or map deprecation).
701
  RECOMPUTE_HANDLER,
702 703 704 705 706 707 708 709
  // 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,
};

710
enum WhereToStart { kStartAtReceiver, kStartAtPrototype };
711

712 713
enum ResultSentinel { kNotFound = -1, kUnsupported = -2 };

714 715
enum ShouldThrow { kThrowOnError, kDontThrow };

716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751
// 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;
};

752 753 754 755 756 757 758 759 760
#if V8_TARGET_LITTLE_ENDIAN
typedef IeeeDoubleLittleEndianArchType IeeeDoubleArchType;
const int kIeeeDoubleMantissaWordOffset = 0;
const int kIeeeDoubleExponentWordOffset = 4;
#else
typedef IeeeDoubleBigEndianArchType IeeeDoubleArchType;
const int kIeeeDoubleMantissaWordOffset = 4;
const int kIeeeDoubleExponentWordOffset = 0;
#endif
761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776

// AccessorCallback
struct AccessorDescriptor {
  Object* (*getter)(Isolate* isolate, Object* object, void* data);
  Object* (*setter)(
      Isolate* isolate, JSObject* object, Object* value, void* data);
  void* data;
};


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

// Testers for test.

#define HAS_SMI_TAG(value) \
777 778 779 780 781
  ((reinterpret_cast<intptr_t>(value) & ::i::kSmiTagMask) == ::i::kSmiTag)

#define HAS_HEAP_OBJECT_TAG(value)                                   \
  (((reinterpret_cast<intptr_t>(value) & ::i::kHeapObjectTagMask) == \
    ::i::kHeapObjectTag))
782 783 784 785 786 787 788 789 790 791 792 793 794

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

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

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

795 796 797 798
// DOUBLE_POINTER_ALIGN returns the value algined for double pointers.
#define DOUBLE_POINTER_ALIGN(value) \
  (((value) + kDoubleAlignmentMask) & ~kDoubleAlignmentMask)

799 800 801

// CPU feature flags.
enum CpuFeature {
802 803
  // x86
  SSE4_1,
804
  SSSE3,
805 806
  SSE3,
  SAHF,
807 808
  AVX,
  FMA3,
809 810 811 812
  BMI1,
  BMI2,
  LZCNT,
  POPCNT,
813
  ATOM,
814
  // ARM
815 816 817 818
  // - 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)
819 820 821 822 823 824
  // MIPS, MIPS64
  FPU,
  FP64FPU,
  MIPSr1,
  MIPSr2,
  MIPSr6,
825
  MIPS_SIMD,  // MSA instructions
826 827
  // ARM64
  ALWAYS_ALIGN_CSP,
828 829 830 831
  // PPC
  FPR_GPR_MOV,
  LWSYNC,
  ISELECT,
832
  VSX,
833
  MODULO,
834 835 836 837
  // S390
  DISTINCT_OPS,
  GENERAL_INSTR_EXT,
  FLOATING_POINT_EXT,
838
  VECTOR_FACILITY,
jyan's avatar
jyan committed
839
  MISC_INSTR_EXT2,
840

841 842 843
  NUMBER_OF_CPU_FEATURES,

  // ARM feature aliases (based on the standard configurations above).
844
  VFPv3 = ARMv7,
845 846 847
  NEON = ARMv7,
  VFP32DREGS = ARMv7,
  SUDIV = ARMv7_SUDIV
848 849
};

850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872
// 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();
}

873 874 875 876 877 878 879 880
// 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 };

881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903
// 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();
}

904 905 906 907 908 909 910
// Used to specify if a macro instruction must perform a smi check on tagged
// values.
enum SmiCheckType {
  DONT_DO_SMI_CHECK,
  DO_SMI_CHECK
};

911
enum ScopeType : uint8_t {
912 913 914
  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
915
  SCRIPT_SCOPE,    // The top-level scope for a script or a top-level eval.
916 917
  CATCH_SCOPE,     // The scope introduced by catch.
  BLOCK_SCOPE,     // The scope introduced by a new block.
918
  WITH_SCOPE       // The scope introduced by with.
919 920
};

921 922 923 924 925 926 927 928
// 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
};

929
// The mips architecture prior to revision 5 has inverted encoding for sNaN.
930 931 932
#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
933
     (!defined(USE_SIMULATOR) || !defined(_MIPS_TARGET_SIMULATOR)))
934 935 936
const uint32_t kHoleNanUpper32 = 0xFFFF7FFF;
const uint32_t kHoleNanLower32 = 0xFFFF7FFF;
#else
937 938
const uint32_t kHoleNanUpper32 = 0xFFF7FFFF;
const uint32_t kHoleNanLower32 = 0xFFF7FFFF;
939
#endif
940 941 942 943 944

const uint64_t kHoleNanInt64 =
    (static_cast<uint64_t>(kHoleNanUpper32) << 32) | kHoleNanLower32;


945 946 947 948
// ES6 section 20.1.2.6 Number.MAX_SAFE_INTEGER
const double kMaxSafeInteger = 9007199254740991.0;  // 2^53-1


949
// The order of this enum has to be kept in sync with the predicates below.
950
enum VariableMode : uint8_t {
951
  // User declared variables:
952
  LET,  // declared via 'let' declarations (first lexical)
953

954
  CONST,  // declared via 'const' declarations (last lexical)
955

956 957
  VAR,  // declared via 'var', and 'function' declarations

958
  // Variables introduced by the compiler:
959 960
  TEMPORARY,  // temporary variables (not user-visible), stack-allocated
              // unless the scope as a whole has forced context allocation
961

962 963
  DYNAMIC,  // always require dynamic lookup (we don't know
            // the declaration)
964 965 966 967 968

  DYNAMIC_GLOBAL,  // requires dynamic lookup, but we know that the
                   // variable is global unless it has been shadowed
                   // by an eval-introduced variable

969 970 971 972
  DYNAMIC_LOCAL  // requires dynamic lookup, but we know that the
                 // variable is local and where it is unless it
                 // has been shadowed by an eval-introduced
                 // variable
973 974
};

975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001
// Printing support
#ifdef DEBUG
inline const char* VariableMode2String(VariableMode mode) {
  switch (mode) {
    case VAR:
      return "VAR";
    case LET:
      return "LET";
    case CONST:
      return "CONST";
    case DYNAMIC:
      return "DYNAMIC";
    case DYNAMIC_GLOBAL:
      return "DYNAMIC_GLOBAL";
    case DYNAMIC_LOCAL:
      return "DYNAMIC_LOCAL";
    case TEMPORARY:
      return "TEMPORARY";
  }
  UNREACHABLE();
}
#endif

enum VariableKind : uint8_t {
  NORMAL_VARIABLE,
  FUNCTION_VARIABLE,
  THIS_VARIABLE,
1002
  SLOPPY_FUNCTION_NAME_VARIABLE
1003 1004
};

1005 1006 1007 1008 1009 1010
inline bool IsDynamicVariableMode(VariableMode mode) {
  return mode >= DYNAMIC && mode <= DYNAMIC_LOCAL;
}


inline bool IsDeclaredVariableMode(VariableMode mode) {
1011 1012
  STATIC_ASSERT(LET == 0);  // Implies that mode >= LET.
  return mode <= VAR;
1013 1014 1015 1016
}


inline bool IsLexicalVariableMode(VariableMode mode) {
1017 1018
  STATIC_ASSERT(LET == 0);  // Implies that mode >= LET.
  return mode <= CONST;
1019 1020
}

1021
enum VariableLocation : uint8_t {
1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044
  // 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.
1045
  LOOKUP,
1046

1047
  // A named slot in a module's export table.
1048 1049 1050
  MODULE,

  kLastVariableLocation = MODULE
1051
};
1052

1053 1054 1055 1056 1057 1058
// 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:
//
1059 1060 1061 1062 1063 1064 1065 1066
// 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) {}
1067
// 6. Function name variables of named function expressions.
1068 1069 1070 1071 1072 1073 1074
//      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).
1075
enum InitializationFlag : uint8_t { kNeedsInitialization, kCreatedInitialized };
1076

1077 1078
enum class HoleCheckMode { kRequired, kElided };

1079
enum MaybeAssignedFlag : uint8_t { kNotAssigned, kMaybeAssigned };
1080

1081
// Serialized in PreparseData, so numeric values should not be changed.
1082 1083
enum ParseErrorType { kSyntaxError = 0, kReferenceError = 1 };

1084

1085 1086 1087 1088 1089
enum MinusZeroMode {
  TREAT_MINUS_ZERO_AS_ZERO,
  FAIL_ON_MINUS_ZERO
};

1090

1091 1092
enum Signedness { kSigned, kUnsigned };

1093
enum FunctionKind : uint16_t {
1094
  kNormalFunction = 0,
1095 1096 1097
  kArrowFunction = 1 << 0,
  kGeneratorFunction = 1 << 1,
  kConciseMethod = 1 << 2,
1098
  kConciseGeneratorMethod = kGeneratorFunction | kConciseMethod,
1099
  kDefaultConstructor = 1 << 3,
1100
  kDerivedConstructor = 1 << 4,
1101 1102 1103
  kBaseConstructor = 1 << 5,
  kGetterFunction = 1 << 6,
  kSetterFunction = 1 << 7,
1104
  kAsyncFunction = 1 << 8,
1105
  kModule = 1 << 9,
1106
  kAccessorFunction = kGetterFunction | kSetterFunction,
1107
  kDefaultBaseConstructor = kDefaultConstructor | kBaseConstructor,
1108
  kDefaultDerivedConstructor = kDefaultConstructor | kDerivedConstructor,
1109
  kClassConstructor =
1110
      kBaseConstructor | kDerivedConstructor | kDefaultConstructor,
1111
  kAsyncArrowFunction = kArrowFunction | kAsyncFunction,
1112 1113 1114 1115 1116
  kAsyncConciseMethod = kAsyncFunction | kConciseMethod,

  // https://tc39.github.io/proposal-async-iteration/
  kAsyncConciseGeneratorMethod = kAsyncFunction | kConciseGeneratorMethod,
  kAsyncGeneratorFunction = kAsyncFunction | kGeneratorFunction
1117 1118 1119 1120 1121 1122
};

inline bool IsValidFunctionKind(FunctionKind kind) {
  return kind == FunctionKind::kNormalFunction ||
         kind == FunctionKind::kArrowFunction ||
         kind == FunctionKind::kGeneratorFunction ||
1123
         kind == FunctionKind::kModule ||
1124
         kind == FunctionKind::kConciseMethod ||
1125
         kind == FunctionKind::kConciseGeneratorMethod ||
1126 1127
         kind == FunctionKind::kGetterFunction ||
         kind == FunctionKind::kSetterFunction ||
1128
         kind == FunctionKind::kAccessorFunction ||
1129
         kind == FunctionKind::kDefaultBaseConstructor ||
1130
         kind == FunctionKind::kDefaultDerivedConstructor ||
1131
         kind == FunctionKind::kBaseConstructor ||
1132
         kind == FunctionKind::kDerivedConstructor ||
1133 1134
         kind == FunctionKind::kAsyncFunction ||
         kind == FunctionKind::kAsyncArrowFunction ||
1135 1136 1137
         kind == FunctionKind::kAsyncConciseMethod ||
         kind == FunctionKind::kAsyncConciseGeneratorMethod ||
         kind == FunctionKind::kAsyncGeneratorFunction;
1138 1139 1140 1141 1142
}


inline bool IsArrowFunction(FunctionKind kind) {
  DCHECK(IsValidFunctionKind(kind));
1143
  return (kind & FunctionKind::kArrowFunction) != 0;
1144 1145 1146 1147 1148
}


inline bool IsGeneratorFunction(FunctionKind kind) {
  DCHECK(IsValidFunctionKind(kind));
1149
  return (kind & FunctionKind::kGeneratorFunction) != 0;
1150 1151
}

1152 1153
inline bool IsModule(FunctionKind kind) {
  DCHECK(IsValidFunctionKind(kind));
1154
  return (kind & FunctionKind::kModule) != 0;
1155 1156
}

1157 1158
inline bool IsAsyncFunction(FunctionKind kind) {
  DCHECK(IsValidFunctionKind(kind));
1159
  return (kind & FunctionKind::kAsyncFunction) != 0;
1160
}
1161

1162 1163 1164 1165 1166 1167
inline bool IsAsyncGeneratorFunction(FunctionKind kind) {
  DCHECK(IsValidFunctionKind(kind));
  const FunctionKind kMask = FunctionKind::kAsyncGeneratorFunction;
  return (kind & kMask) == kMask;
}

1168
inline bool IsResumableFunction(FunctionKind kind) {
1169
  return IsGeneratorFunction(kind) || IsAsyncFunction(kind) || IsModule(kind);
1170 1171
}

1172 1173
inline bool IsConciseMethod(FunctionKind kind) {
  DCHECK(IsValidFunctionKind(kind));
1174
  return (kind & FunctionKind::kConciseMethod) != 0;
1175
}
1176

1177 1178
inline bool IsGetterFunction(FunctionKind kind) {
  DCHECK(IsValidFunctionKind(kind));
1179
  return (kind & FunctionKind::kGetterFunction) != 0;
1180 1181 1182 1183
}

inline bool IsSetterFunction(FunctionKind kind) {
  DCHECK(IsValidFunctionKind(kind));
1184
  return (kind & FunctionKind::kSetterFunction) != 0;
1185
}
1186

1187 1188
inline bool IsAccessorFunction(FunctionKind kind) {
  DCHECK(IsValidFunctionKind(kind));
1189
  return (kind & FunctionKind::kAccessorFunction) != 0;
1190 1191 1192
}


1193 1194
inline bool IsDefaultConstructor(FunctionKind kind) {
  DCHECK(IsValidFunctionKind(kind));
1195
  return (kind & FunctionKind::kDefaultConstructor) != 0;
1196 1197
}

1198

1199 1200
inline bool IsBaseConstructor(FunctionKind kind) {
  DCHECK(IsValidFunctionKind(kind));
1201
  return (kind & FunctionKind::kBaseConstructor) != 0;
1202 1203
}

1204
inline bool IsDerivedConstructor(FunctionKind kind) {
1205
  DCHECK(IsValidFunctionKind(kind));
1206
  return (kind & FunctionKind::kDerivedConstructor) != 0;
1207
}
1208 1209


1210
inline bool IsClassConstructor(FunctionKind kind) {
1211
  DCHECK(IsValidFunctionKind(kind));
1212
  return (kind & FunctionKind::kClassConstructor) != 0;
1213
}
1214

1215
inline bool IsConstructable(FunctionKind kind) {
1216
  if (IsAccessorFunction(kind)) return false;
1217
  if (IsConciseMethod(kind)) return false;
1218
  if (IsArrowFunction(kind)) return false;
1219
  if (IsGeneratorFunction(kind)) return false;
1220
  if (IsAsyncFunction(kind)) return false;
1221 1222 1223
  return true;
}

1224
enum class InterpreterPushArgsMode : unsigned {
1225 1226 1227 1228 1229
  kJSFunction,
  kWithFinalSpread,
  kOther
};

1230
inline size_t hash_value(InterpreterPushArgsMode mode) {
1231 1232 1233
  return bit_cast<unsigned>(mode);
}

1234 1235
inline std::ostream& operator<<(std::ostream& os,
                                InterpreterPushArgsMode mode) {
1236
  switch (mode) {
1237
    case InterpreterPushArgsMode::kJSFunction:
1238
      return os << "JSFunction";
1239
    case InterpreterPushArgsMode::kWithFinalSpread:
1240
      return os << "WithFinalSpread";
1241
    case InterpreterPushArgsMode::kOther:
1242 1243 1244 1245 1246
      return os << "Other";
  }
  UNREACHABLE();
}

1247 1248 1249 1250 1251 1252 1253
inline uint32_t ObjectHash(Address address) {
  // All objects are at least pointer aligned, so we can remove the trailing
  // zeros.
  return static_cast<uint32_t>(bit_cast<uintptr_t>(address) >>
                               kPointerSizeLog2);
}

1254
// Type feedback is encoded in such a way that, we can combine the feedback
1255 1256
// at different points by performing an 'OR' operation. Type feedback moves
// to a more generic type when we combine feedback.
1257 1258
// kSignedSmall -> kSignedSmallInputs -> kNumber  -> kNumberOrOddball -> kAny
//                                                   kString          -> kAny
1259
// kBigInt -> kAny
1260 1261 1262 1263 1264
// TODO(mythria): Remove kNumber type when crankshaft can handle Oddballs
// similar to Numbers. We don't need kNumber feedback for Turbofan. Extra
// information about Number might reduce few instructions but causes more
// deopts. We collect Number only because crankshaft does not handle all
// cases of oddballs.
1265 1266
class BinaryOperationFeedback {
 public:
1267 1268 1269
  enum {
    kNone = 0x0,
    kSignedSmall = 0x1,
1270
    kSignedSmallInputs = 0x3,
1271 1272 1273
    kNumber = 0x7,
    kNumberOrOddball = 0xF,
    kString = 0x10,
1274 1275
    kBigInt = 0x20,
    kAny = 0x7F
1276
  };
1277 1278
};

1279 1280 1281
// 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.
1282 1283
// kSignedSmall        -> kNumber   -> kAny
// kInternalizedString -> kString   -> kAny
1284
//                        kSymbol   -> kAny
1285
//                        kReceiver -> kAny
1286
// TODO(epertoso): consider unifying this with BinaryOperationFeedback.
1287 1288
class CompareOperationFeedback {
 public:
1289 1290 1291 1292
  enum {
    kNone = 0x00,
    kSignedSmall = 0x01,
    kNumber = 0x3,
1293
    kNumberOrOddball = 0x7,
1294 1295
    kInternalizedString = 0x8,
    kString = 0x18,
1296 1297 1298
    kSymbol = 0x20,
    kReceiver = 0x40,
    kAny = 0xff
1299
  };
1300 1301
};

1302 1303 1304 1305 1306 1307 1308
enum class Operation {
  // Binary operations.
  kAdd,
  kSubtract,
  kMultiply,
  kDivide,
  kModulus,
1309
  kExponentiate,
1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329
  kBitwiseAnd,
  kBitwiseOr,
  kBitwiseXor,
  kShiftLeft,
  kShiftRight,
  kShiftRightLogical,
  // Unary operations.
  kBitwiseNot,
  kNegate,
  kIncrement,
  kDecrement,
  // Compare operations.
  kEqual,
  kStrictEqual,
  kLessThan,
  kLessThanOrEqual,
  kGreaterThan,
  kGreaterThanOrEqual,
};

1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350
// 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);

1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370
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();
}

1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384
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();
}

1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395
// 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)

1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407
enum ExternalArrayType {
  kExternalInt8Array = 1,
  kExternalUint8Array,
  kExternalInt16Array,
  kExternalUint16Array,
  kExternalInt32Array,
  kExternalUint32Array,
  kExternalFloat32Array,
  kExternalFloat64Array,
  kExternalUint8ClampedArray,
};

1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421
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;
}

1422
enum class OptimizationMarker {
1423
  kLogFirstExecution,
1424 1425 1426 1427 1428 1429 1430 1431 1432
  kNone,
  kCompileOptimized,
  kCompileOptimizedConcurrent,
  kInOptimizationQueue
};

inline std::ostream& operator<<(std::ostream& os,
                                const OptimizationMarker& marker) {
  switch (marker) {
1433 1434
    case OptimizationMarker::kLogFirstExecution:
      return os << "OptimizationMarker::kLogFirstExecution";
1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449
    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;
}

enum class ConcurrencyMode { kNotConcurrent, kConcurrent };

1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461
#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)        \
1462 1463 1464
  C(JSEntrySP, js_entry_sp)                                    \
  C(MicrotaskQueueBailoutIndex, microtask_queue_bailout_index) \
  C(MicrotaskQueueBailoutCount, microtask_queue_bailout_count)
1465 1466 1467 1468 1469 1470 1471 1472

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

1473 1474
}  // namespace internal
}  // namespace v8
1475

1476 1477
namespace i = v8::internal;

1478
#endif  // V8_GLOBALS_H_