Home | History | Annotate | Download | only in src
      1 // Copyright 2012 the V8 project authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef V8_GLOBALS_H_
      6 #define V8_GLOBALS_H_
      7 
      8 #include <stddef.h>
      9 #include <stdint.h>
     10 
     11 #include <ostream>
     12 
     13 #include "src/base/build_config.h"
     14 #include "src/base/logging.h"
     15 #include "src/base/macros.h"
     16 
     17 #ifdef V8_OS_WIN
     18 
     19 // Setup for Windows shared library export.
     20 #ifdef BUILDING_V8_SHARED
     21 #define V8_EXPORT_PRIVATE __declspec(dllexport)
     22 #elif USING_V8_SHARED
     23 #define V8_EXPORT_PRIVATE __declspec(dllimport)
     24 #else
     25 #define V8_EXPORT_PRIVATE
     26 #endif  // BUILDING_V8_SHARED
     27 
     28 #else  // V8_OS_WIN
     29 
     30 // Setup for Linux shared library export.
     31 #if V8_HAS_ATTRIBUTE_VISIBILITY
     32 #ifdef BUILDING_V8_SHARED
     33 #define V8_EXPORT_PRIVATE __attribute__((visibility("default")))
     34 #else
     35 #define V8_EXPORT_PRIVATE
     36 #endif
     37 #else
     38 #define V8_EXPORT_PRIVATE
     39 #endif
     40 
     41 #endif  // V8_OS_WIN
     42 
     43 // Unfortunately, the INFINITY macro cannot be used with the '-pedantic'
     44 // warning flag and certain versions of GCC due to a bug:
     45 // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11931
     46 // For now, we use the more involved template-based version from <limits>, but
     47 // only when compiling with GCC versions affected by the bug (2.96.x - 4.0.x)
     48 #if V8_CC_GNU && V8_GNUC_PREREQ(2, 96, 0) && !V8_GNUC_PREREQ(4, 1, 0)
     49 # include <limits>  // NOLINT
     50 # define V8_INFINITY std::numeric_limits<double>::infinity()
     51 #elif V8_LIBC_MSVCRT
     52 # define V8_INFINITY HUGE_VAL
     53 #elif V8_OS_AIX
     54 #define V8_INFINITY (__builtin_inff())
     55 #else
     56 # define V8_INFINITY INFINITY
     57 #endif
     58 
     59 namespace v8 {
     60 
     61 namespace base {
     62 class Mutex;
     63 class RecursiveMutex;
     64 class VirtualMemory;
     65 }
     66 
     67 namespace internal {
     68 
     69 // Determine whether we are running in a simulated environment.
     70 // Setting USE_SIMULATOR explicitly from the build script will force
     71 // the use of a simulated environment.
     72 #if !defined(USE_SIMULATOR)
     73 #if (V8_TARGET_ARCH_ARM64 && !V8_HOST_ARCH_ARM64)
     74 #define USE_SIMULATOR 1
     75 #endif
     76 #if (V8_TARGET_ARCH_ARM && !V8_HOST_ARCH_ARM)
     77 #define USE_SIMULATOR 1
     78 #endif
     79 #if (V8_TARGET_ARCH_PPC && !V8_HOST_ARCH_PPC)
     80 #define USE_SIMULATOR 1
     81 #endif
     82 #if (V8_TARGET_ARCH_MIPS && !V8_HOST_ARCH_MIPS)
     83 #define USE_SIMULATOR 1
     84 #endif
     85 #if (V8_TARGET_ARCH_MIPS64 && !V8_HOST_ARCH_MIPS64)
     86 #define USE_SIMULATOR 1
     87 #endif
     88 #if (V8_TARGET_ARCH_S390 && !V8_HOST_ARCH_S390)
     89 #define USE_SIMULATOR 1
     90 #endif
     91 #endif
     92 
     93 // Determine whether the architecture uses an embedded constant pool
     94 // (contiguous constant pool embedded in code object).
     95 #if V8_TARGET_ARCH_PPC
     96 #define V8_EMBEDDED_CONSTANT_POOL 1
     97 #else
     98 #define V8_EMBEDDED_CONSTANT_POOL 0
     99 #endif
    100 
    101 #ifdef V8_TARGET_ARCH_ARM
    102 // Set stack limit lower for ARM than for other architectures because
    103 // stack allocating MacroAssembler takes 120K bytes.
    104 // See issue crbug.com/405338
    105 #define V8_DEFAULT_STACK_SIZE_KB 864
    106 #else
    107 // Slightly less than 1MB, since Windows' default stack size for
    108 // the main execution thread is 1MB for both 32 and 64-bit.
    109 #define V8_DEFAULT_STACK_SIZE_KB 984
    110 #endif
    111 
    112 
    113 // Determine whether double field unboxing feature is enabled.
    114 #if V8_TARGET_ARCH_64_BIT
    115 #define V8_DOUBLE_FIELDS_UNBOXING 1
    116 #else
    117 #define V8_DOUBLE_FIELDS_UNBOXING 0
    118 #endif
    119 
    120 
    121 typedef uint8_t byte;
    122 typedef byte* Address;
    123 
    124 // -----------------------------------------------------------------------------
    125 // Constants
    126 
    127 const int KB = 1024;
    128 const int MB = KB * KB;
    129 const int GB = KB * KB * KB;
    130 const int kMaxInt = 0x7FFFFFFF;
    131 const int kMinInt = -kMaxInt - 1;
    132 const int kMaxInt8 = (1 << 7) - 1;
    133 const int kMinInt8 = -(1 << 7);
    134 const int kMaxUInt8 = (1 << 8) - 1;
    135 const int kMinUInt8 = 0;
    136 const int kMaxInt16 = (1 << 15) - 1;
    137 const int kMinInt16 = -(1 << 15);
    138 const int kMaxUInt16 = (1 << 16) - 1;
    139 const int kMinUInt16 = 0;
    140 
    141 const uint32_t kMaxUInt32 = 0xFFFFFFFFu;
    142 const int kMinUInt32 = 0;
    143 
    144 const int kCharSize = sizeof(char);
    145 const int kShortSize = sizeof(short);  // NOLINT
    146 const int kIntSize = sizeof(int);
    147 const int kInt32Size = sizeof(int32_t);
    148 const int kInt64Size = sizeof(int64_t);
    149 const int kSizetSize = sizeof(size_t);
    150 const int kFloatSize = sizeof(float);
    151 const int kDoubleSize = sizeof(double);
    152 const int kIntptrSize = sizeof(intptr_t);
    153 const int kPointerSize = sizeof(void*);
    154 #if V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_32_BIT
    155 const int kRegisterSize = kPointerSize + kPointerSize;
    156 #else
    157 const int kRegisterSize = kPointerSize;
    158 #endif
    159 const int kPCOnStackSize = kRegisterSize;
    160 const int kFPOnStackSize = kRegisterSize;
    161 
    162 #if V8_TARGET_ARCH_X64 || V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_X87
    163 const int kElidedFrameSlots = kPCOnStackSize / kPointerSize;
    164 #else
    165 const int kElidedFrameSlots = 0;
    166 #endif
    167 
    168 const int kDoubleSizeLog2 = 3;
    169 
    170 #if V8_HOST_ARCH_64_BIT
    171 const int kPointerSizeLog2 = 3;
    172 const intptr_t kIntptrSignBit = V8_INT64_C(0x8000000000000000);
    173 const uintptr_t kUintptrAllBitsSet = V8_UINT64_C(0xFFFFFFFFFFFFFFFF);
    174 const bool kRequiresCodeRange = true;
    175 #if V8_TARGET_ARCH_MIPS64
    176 // To use pseudo-relative jumps such as j/jal instructions which have 28-bit
    177 // encoded immediate, the addresses have to be in range of 256MB aligned
    178 // region. Used only for large object space.
    179 const size_t kMaximalCodeRangeSize = 256 * MB;
    180 const size_t kCodeRangeAreaAlignment = 256 * MB;
    181 #elif V8_HOST_ARCH_PPC && V8_TARGET_ARCH_PPC && V8_OS_LINUX
    182 const size_t kMaximalCodeRangeSize = 512 * MB;
    183 const size_t kCodeRangeAreaAlignment = 64 * KB;  // OS page on PPC Linux
    184 #else
    185 const size_t kMaximalCodeRangeSize = 512 * MB;
    186 const size_t kCodeRangeAreaAlignment = 4 * KB;  // OS page.
    187 #endif
    188 #if V8_OS_WIN
    189 const size_t kMinimumCodeRangeSize = 4 * MB;
    190 const size_t kReservedCodeRangePages = 1;
    191 #else
    192 const size_t kMinimumCodeRangeSize = 3 * MB;
    193 const size_t kReservedCodeRangePages = 0;
    194 #endif
    195 #else
    196 const int kPointerSizeLog2 = 2;
    197 const intptr_t kIntptrSignBit = 0x80000000;
    198 const uintptr_t kUintptrAllBitsSet = 0xFFFFFFFFu;
    199 #if V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_32_BIT
    200 // x32 port also requires code range.
    201 const bool kRequiresCodeRange = true;
    202 const size_t kMaximalCodeRangeSize = 256 * MB;
    203 const size_t kMinimumCodeRangeSize = 3 * MB;
    204 const size_t kCodeRangeAreaAlignment = 4 * KB;  // OS page.
    205 #elif V8_HOST_ARCH_PPC && V8_TARGET_ARCH_PPC && V8_OS_LINUX
    206 const bool kRequiresCodeRange = false;
    207 const size_t kMaximalCodeRangeSize = 0 * MB;
    208 const size_t kMinimumCodeRangeSize = 0 * MB;
    209 const size_t kCodeRangeAreaAlignment = 64 * KB;  // OS page on PPC Linux
    210 #else
    211 const bool kRequiresCodeRange = false;
    212 const size_t kMaximalCodeRangeSize = 0 * MB;
    213 const size_t kMinimumCodeRangeSize = 0 * MB;
    214 const size_t kCodeRangeAreaAlignment = 4 * KB;  // OS page.
    215 #endif
    216 const size_t kReservedCodeRangePages = 0;
    217 #endif
    218 
    219 // Trigger an incremental GCs once the external memory reaches this limit.
    220 const int kExternalAllocationSoftLimit = 64 * MB;
    221 
    222 // Maximum object size that gets allocated into regular pages. Objects larger
    223 // than that size are allocated in large object space and are never moved in
    224 // memory. This also applies to new space allocation, since objects are never
    225 // migrated from new space to large object space. Takes double alignment into
    226 // account.
    227 //
    228 // Current value: Page::kAllocatableMemory (on 32-bit arch) - 512 (slack).
    229 const int kMaxRegularHeapObjectSize = 507136;
    230 
    231 STATIC_ASSERT(kPointerSize == (1 << kPointerSizeLog2));
    232 
    233 const int kBitsPerByte = 8;
    234 const int kBitsPerByteLog2 = 3;
    235 const int kBitsPerPointer = kPointerSize * kBitsPerByte;
    236 const int kBitsPerInt = kIntSize * kBitsPerByte;
    237 
    238 // IEEE 754 single precision floating point number bit layout.
    239 const uint32_t kBinary32SignMask = 0x80000000u;
    240 const uint32_t kBinary32ExponentMask = 0x7f800000u;
    241 const uint32_t kBinary32MantissaMask = 0x007fffffu;
    242 const int kBinary32ExponentBias = 127;
    243 const int kBinary32MaxExponent  = 0xFE;
    244 const int kBinary32MinExponent  = 0x01;
    245 const int kBinary32MantissaBits = 23;
    246 const int kBinary32ExponentShift = 23;
    247 
    248 // Quiet NaNs have bits 51 to 62 set, possibly the sign bit, and no
    249 // other bits set.
    250 const uint64_t kQuietNaNMask = static_cast<uint64_t>(0xfff) << 51;
    251 
    252 // Latin1/UTF-16 constants
    253 // Code-point values in Unicode 4.0 are 21 bits wide.
    254 // Code units in UTF-16 are 16 bits wide.
    255 typedef uint16_t uc16;
    256 typedef int32_t uc32;
    257 const int kOneByteSize    = kCharSize;
    258 const int kUC16Size     = sizeof(uc16);      // NOLINT
    259 
    260 // 128 bit SIMD value size.
    261 const int kSimd128Size = 16;
    262 
    263 // Round up n to be a multiple of sz, where sz is a power of 2.
    264 #define ROUND_UP(n, sz) (((n) + ((sz) - 1)) & ~((sz) - 1))
    265 
    266 
    267 // FUNCTION_ADDR(f) gets the address of a C function f.
    268 #define FUNCTION_ADDR(f)                                        \
    269   (reinterpret_cast<v8::internal::Address>(reinterpret_cast<intptr_t>(f)))
    270 
    271 
    272 // FUNCTION_CAST<F>(addr) casts an address into a function
    273 // of type F. Used to invoke generated code from within C.
    274 template <typename F>
    275 F FUNCTION_CAST(Address addr) {
    276   return reinterpret_cast<F>(reinterpret_cast<intptr_t>(addr));
    277 }
    278 
    279 
    280 // Determine whether the architecture uses function descriptors
    281 // which provide a level of indirection between the function pointer
    282 // and the function entrypoint.
    283 #if V8_HOST_ARCH_PPC && \
    284     (V8_OS_AIX || (V8_TARGET_ARCH_PPC64 && V8_TARGET_BIG_ENDIAN))
    285 #define USES_FUNCTION_DESCRIPTORS 1
    286 #define FUNCTION_ENTRYPOINT_ADDRESS(f)       \
    287   (reinterpret_cast<v8::internal::Address*>( \
    288       &(reinterpret_cast<intptr_t*>(f)[0])))
    289 #else
    290 #define USES_FUNCTION_DESCRIPTORS 0
    291 #endif
    292 
    293 
    294 // -----------------------------------------------------------------------------
    295 // Forward declarations for frequently used classes
    296 // (sorted alphabetically)
    297 
    298 class FreeStoreAllocationPolicy;
    299 template <typename T, class P = FreeStoreAllocationPolicy> class List;
    300 
    301 // -----------------------------------------------------------------------------
    302 // Declarations for use in both the preparser and the rest of V8.
    303 
    304 // The Strict Mode (ECMA-262 5th edition, 4.2.2).
    305 
    306 enum LanguageMode : uint32_t { SLOPPY, STRICT, LANGUAGE_END };
    307 
    308 inline std::ostream& operator<<(std::ostream& os, const LanguageMode& mode) {
    309   switch (mode) {
    310     case SLOPPY: return os << "sloppy";
    311     case STRICT: return os << "strict";
    312     default: UNREACHABLE();
    313   }
    314   return os;
    315 }
    316 
    317 
    318 inline bool is_sloppy(LanguageMode language_mode) {
    319   return language_mode == SLOPPY;
    320 }
    321 
    322 
    323 inline bool is_strict(LanguageMode language_mode) {
    324   return language_mode != SLOPPY;
    325 }
    326 
    327 
    328 inline bool is_valid_language_mode(int language_mode) {
    329   return language_mode == SLOPPY || language_mode == STRICT;
    330 }
    331 
    332 
    333 inline LanguageMode construct_language_mode(bool strict_bit) {
    334   return static_cast<LanguageMode>(strict_bit);
    335 }
    336 
    337 // This constant is used as an undefined value when passing source positions.
    338 const int kNoSourcePosition = -1;
    339 
    340 // This constant is used to indicate missing deoptimization information.
    341 const int kNoDeoptimizationId = -1;
    342 
    343 // Mask for the sign bit in a smi.
    344 const intptr_t kSmiSignMask = kIntptrSignBit;
    345 
    346 const int kObjectAlignmentBits = kPointerSizeLog2;
    347 const intptr_t kObjectAlignment = 1 << kObjectAlignmentBits;
    348 const intptr_t kObjectAlignmentMask = kObjectAlignment - 1;
    349 
    350 // Desired alignment for pointers.
    351 const intptr_t kPointerAlignment = (1 << kPointerSizeLog2);
    352 const intptr_t kPointerAlignmentMask = kPointerAlignment - 1;
    353 
    354 // Desired alignment for double values.
    355 const intptr_t kDoubleAlignment = 8;
    356 const intptr_t kDoubleAlignmentMask = kDoubleAlignment - 1;
    357 
    358 // Desired alignment for 128 bit SIMD values.
    359 const intptr_t kSimd128Alignment = 16;
    360 const intptr_t kSimd128AlignmentMask = kSimd128Alignment - 1;
    361 
    362 // Desired alignment for generated code is 32 bytes (to improve cache line
    363 // utilization).
    364 const int kCodeAlignmentBits = 5;
    365 const intptr_t kCodeAlignment = 1 << kCodeAlignmentBits;
    366 const intptr_t kCodeAlignmentMask = kCodeAlignment - 1;
    367 
    368 // The owner field of a page is tagged with the page header tag. We need that
    369 // to find out if a slot is part of a large object. If we mask out the lower
    370 // 0xfffff bits (1M pages), go to the owner offset, and see that this field
    371 // is tagged with the page header tag, we can just look up the owner.
    372 // Otherwise, we know that we are somewhere (not within the first 1M) in a
    373 // large object.
    374 const int kPageHeaderTag = 3;
    375 const int kPageHeaderTagSize = 2;
    376 const intptr_t kPageHeaderTagMask = (1 << kPageHeaderTagSize) - 1;
    377 
    378 
    379 // Zap-value: The value used for zapping dead objects.
    380 // Should be a recognizable hex value tagged as a failure.
    381 #ifdef V8_HOST_ARCH_64_BIT
    382 const Address kZapValue =
    383     reinterpret_cast<Address>(V8_UINT64_C(0xdeadbeedbeadbeef));
    384 const Address kHandleZapValue =
    385     reinterpret_cast<Address>(V8_UINT64_C(0x1baddead0baddeaf));
    386 const Address kGlobalHandleZapValue =
    387     reinterpret_cast<Address>(V8_UINT64_C(0x1baffed00baffedf));
    388 const Address kFromSpaceZapValue =
    389     reinterpret_cast<Address>(V8_UINT64_C(0x1beefdad0beefdaf));
    390 const uint64_t kDebugZapValue = V8_UINT64_C(0xbadbaddbbadbaddb);
    391 const uint64_t kSlotsZapValue = V8_UINT64_C(0xbeefdeadbeefdeef);
    392 const uint64_t kFreeListZapValue = 0xfeed1eaffeed1eaf;
    393 #else
    394 const Address kZapValue = reinterpret_cast<Address>(0xdeadbeef);
    395 const Address kHandleZapValue = reinterpret_cast<Address>(0xbaddeaf);
    396 const Address kGlobalHandleZapValue = reinterpret_cast<Address>(0xbaffedf);
    397 const Address kFromSpaceZapValue = reinterpret_cast<Address>(0xbeefdaf);
    398 const uint32_t kSlotsZapValue = 0xbeefdeef;
    399 const uint32_t kDebugZapValue = 0xbadbaddb;
    400 const uint32_t kFreeListZapValue = 0xfeed1eaf;
    401 #endif
    402 
    403 const int kCodeZapValue = 0xbadc0de;
    404 const uint32_t kPhantomReferenceZap = 0xca11bac;
    405 
    406 // On Intel architecture, cache line size is 64 bytes.
    407 // On ARM it may be less (32 bytes), but as far this constant is
    408 // used for aligning data, it doesn't hurt to align on a greater value.
    409 #define PROCESSOR_CACHE_LINE_SIZE 64
    410 
    411 // Constants relevant to double precision floating point numbers.
    412 // If looking only at the top 32 bits, the QNaN mask is bits 19 to 30.
    413 const uint32_t kQuietNaNHighBitsMask = 0xfff << (51 - 32);
    414 
    415 
    416 // -----------------------------------------------------------------------------
    417 // Forward declarations for frequently used classes
    418 
    419 class AccessorInfo;
    420 class Allocation;
    421 class Arguments;
    422 class Assembler;
    423 class Code;
    424 class CodeGenerator;
    425 class CodeStub;
    426 class Context;
    427 class Debug;
    428 class DebugInfo;
    429 class Descriptor;
    430 class DescriptorArray;
    431 class TransitionArray;
    432 class ExternalReference;
    433 class FixedArray;
    434 class FunctionTemplateInfo;
    435 class MemoryChunk;
    436 class SeededNumberDictionary;
    437 class UnseededNumberDictionary;
    438 class NameDictionary;
    439 class GlobalDictionary;
    440 template <typename T> class MaybeHandle;
    441 template <typename T> class Handle;
    442 class Heap;
    443 class HeapObject;
    444 class IC;
    445 class InterceptorInfo;
    446 class Isolate;
    447 class JSReceiver;
    448 class JSArray;
    449 class JSFunction;
    450 class JSObject;
    451 class LargeObjectSpace;
    452 class MacroAssembler;
    453 class Map;
    454 class MapSpace;
    455 class MarkCompactCollector;
    456 class NewSpace;
    457 class Object;
    458 class OldSpace;
    459 class ParameterCount;
    460 class Foreign;
    461 class Scope;
    462 class DeclarationScope;
    463 class ModuleScope;
    464 class ScopeInfo;
    465 class Script;
    466 class Smi;
    467 template <typename Config, class Allocator = FreeStoreAllocationPolicy>
    468 class SplayTree;
    469 class String;
    470 class Symbol;
    471 class Name;
    472 class Struct;
    473 class TypeFeedbackVector;
    474 class Variable;
    475 class RelocInfo;
    476 class Deserializer;
    477 class MessageLocation;
    478 
    479 typedef bool (*WeakSlotCallback)(Object** pointer);
    480 
    481 typedef bool (*WeakSlotCallbackWithHeap)(Heap* heap, Object** pointer);
    482 
    483 // -----------------------------------------------------------------------------
    484 // Miscellaneous
    485 
    486 // NOTE: SpaceIterator depends on AllocationSpace enumeration values being
    487 // consecutive.
    488 // Keep this enum in sync with the ObjectSpace enum in v8.h
    489 enum AllocationSpace {
    490   NEW_SPACE,   // Semispaces collected with copying collector.
    491   OLD_SPACE,   // May contain pointers to new space.
    492   CODE_SPACE,  // No pointers to new space, marked executable.
    493   MAP_SPACE,   // Only and all map objects.
    494   LO_SPACE,    // Promoted large objects.
    495 
    496   FIRST_SPACE = NEW_SPACE,
    497   LAST_SPACE = LO_SPACE,
    498   FIRST_PAGED_SPACE = OLD_SPACE,
    499   LAST_PAGED_SPACE = MAP_SPACE
    500 };
    501 const int kSpaceTagSize = 3;
    502 const int kSpaceTagMask = (1 << kSpaceTagSize) - 1;
    503 
    504 enum AllocationAlignment {
    505   kWordAligned,
    506   kDoubleAligned,
    507   kDoubleUnaligned,
    508   kSimd128Unaligned
    509 };
    510 
    511 // Possible outcomes for decisions.
    512 enum class Decision : uint8_t { kUnknown, kTrue, kFalse };
    513 
    514 inline size_t hash_value(Decision decision) {
    515   return static_cast<uint8_t>(decision);
    516 }
    517 
    518 inline std::ostream& operator<<(std::ostream& os, Decision decision) {
    519   switch (decision) {
    520     case Decision::kUnknown:
    521       return os << "Unknown";
    522     case Decision::kTrue:
    523       return os << "True";
    524     case Decision::kFalse:
    525       return os << "False";
    526   }
    527   UNREACHABLE();
    528   return os;
    529 }
    530 
    531 // Supported write barrier modes.
    532 enum WriteBarrierKind : uint8_t {
    533   kNoWriteBarrier,
    534   kMapWriteBarrier,
    535   kPointerWriteBarrier,
    536   kFullWriteBarrier
    537 };
    538 
    539 inline size_t hash_value(WriteBarrierKind kind) {
    540   return static_cast<uint8_t>(kind);
    541 }
    542 
    543 inline std::ostream& operator<<(std::ostream& os, WriteBarrierKind kind) {
    544   switch (kind) {
    545     case kNoWriteBarrier:
    546       return os << "NoWriteBarrier";
    547     case kMapWriteBarrier:
    548       return os << "MapWriteBarrier";
    549     case kPointerWriteBarrier:
    550       return os << "PointerWriteBarrier";
    551     case kFullWriteBarrier:
    552       return os << "FullWriteBarrier";
    553   }
    554   UNREACHABLE();
    555   return os;
    556 }
    557 
    558 // A flag that indicates whether objects should be pretenured when
    559 // allocated (allocated directly into the old generation) or not
    560 // (allocated in the young generation if the object size and type
    561 // allows).
    562 enum PretenureFlag { NOT_TENURED, TENURED };
    563 
    564 inline std::ostream& operator<<(std::ostream& os, const PretenureFlag& flag) {
    565   switch (flag) {
    566     case NOT_TENURED:
    567       return os << "NotTenured";
    568     case TENURED:
    569       return os << "Tenured";
    570   }
    571   UNREACHABLE();
    572   return os;
    573 }
    574 
    575 enum MinimumCapacity {
    576   USE_DEFAULT_MINIMUM_CAPACITY,
    577   USE_CUSTOM_MINIMUM_CAPACITY
    578 };
    579 
    580 enum GarbageCollector { SCAVENGER, MARK_COMPACTOR, MINOR_MARK_COMPACTOR };
    581 
    582 enum Executability { NOT_EXECUTABLE, EXECUTABLE };
    583 
    584 enum VisitMode {
    585   VISIT_ALL,
    586   VISIT_ALL_IN_SCAVENGE,
    587   VISIT_ALL_IN_SWEEP_NEWSPACE,
    588   VISIT_ONLY_STRONG,
    589   VISIT_ONLY_STRONG_FOR_SERIALIZATION,
    590   VISIT_ONLY_STRONG_ROOT_LIST,
    591 };
    592 
    593 // Flag indicating whether code is built into the VM (one of the natives files).
    594 enum NativesFlag { NOT_NATIVES_CODE, EXTENSION_CODE, NATIVES_CODE };
    595 
    596 // JavaScript defines two kinds of 'nil'.
    597 enum NilValue { kNullValue, kUndefinedValue };
    598 
    599 // ParseRestriction is used to restrict the set of valid statements in a
    600 // unit of compilation.  Restriction violations cause a syntax error.
    601 enum ParseRestriction {
    602   NO_PARSE_RESTRICTION,         // All expressions are allowed.
    603   ONLY_SINGLE_FUNCTION_LITERAL  // Only a single FunctionLiteral expression.
    604 };
    605 
    606 // TODO(gsathya): Move this to JSPromise once we create it.
    607 // This should be in sync with the constants in promise.js
    608 enum PromiseStatus {
    609   kPromisePending,
    610   kPromiseFulfilled,
    611   kPromiseRejected,
    612 };
    613 
    614 // A CodeDesc describes a buffer holding instructions and relocation
    615 // information. The instructions start at the beginning of the buffer
    616 // and grow forward, the relocation information starts at the end of
    617 // the buffer and grows backward.  A constant pool may exist at the
    618 // end of the instructions.
    619 //
    620 //  |<--------------- buffer_size ----------------------------------->|
    621 //  |<------------- instr_size ---------->|        |<-- reloc_size -->|
    622 //  |               |<- const_pool_size ->|                           |
    623 //  +=====================================+========+==================+
    624 //  |  instructions |        data         |  free  |    reloc info    |
    625 //  +=====================================+========+==================+
    626 //  ^
    627 //  |
    628 //  buffer
    629 
    630 struct CodeDesc {
    631   byte* buffer;
    632   int buffer_size;
    633   int instr_size;
    634   int reloc_size;
    635   int constant_pool_size;
    636   byte* unwinding_info;
    637   int unwinding_info_size;
    638   Assembler* origin;
    639 };
    640 
    641 
    642 // Callback function used for checking constraints when copying/relocating
    643 // objects. Returns true if an object can be copied/relocated from its
    644 // old_addr to a new_addr.
    645 typedef bool (*ConstraintCallback)(Address new_addr, Address old_addr);
    646 
    647 
    648 // Callback function on inline caches, used for iterating over inline caches
    649 // in compiled code.
    650 typedef void (*InlineCacheCallback)(Code* code, Address ic);
    651 
    652 
    653 // State for inline cache call sites. Aliased as IC::State.
    654 enum InlineCacheState {
    655   // Has never been executed.
    656   UNINITIALIZED,
    657   // Has been executed but monomorhic state has been delayed.
    658   PREMONOMORPHIC,
    659   // Has been executed and only one receiver type has been seen.
    660   MONOMORPHIC,
    661   // Check failed due to prototype (or map deprecation).
    662   RECOMPUTE_HANDLER,
    663   // Multiple receiver types have been seen.
    664   POLYMORPHIC,
    665   // Many receiver types have been seen.
    666   MEGAMORPHIC,
    667   // A generic handler is installed and no extra typefeedback is recorded.
    668   GENERIC,
    669 };
    670 
    671 enum CacheHolderFlag {
    672   kCacheOnPrototype,
    673   kCacheOnPrototypeReceiverIsDictionary,
    674   kCacheOnPrototypeReceiverIsPrimitive,
    675   kCacheOnReceiver
    676 };
    677 
    678 enum WhereToStart { kStartAtReceiver, kStartAtPrototype };
    679 
    680 // The Store Buffer (GC).
    681 typedef enum {
    682   kStoreBufferFullEvent,
    683   kStoreBufferStartScanningPagesEvent,
    684   kStoreBufferScanningPageEvent
    685 } StoreBufferEvent;
    686 
    687 
    688 typedef void (*StoreBufferCallback)(Heap* heap,
    689                                     MemoryChunk* page,
    690                                     StoreBufferEvent event);
    691 
    692 // Union used for customized checking of the IEEE double types
    693 // inlined within v8 runtime, rather than going to the underlying
    694 // platform headers and libraries
    695 union IeeeDoubleLittleEndianArchType {
    696   double d;
    697   struct {
    698     unsigned int man_low  :32;
    699     unsigned int man_high :20;
    700     unsigned int exp      :11;
    701     unsigned int sign     :1;
    702   } bits;
    703 };
    704 
    705 
    706 union IeeeDoubleBigEndianArchType {
    707   double d;
    708   struct {
    709     unsigned int sign     :1;
    710     unsigned int exp      :11;
    711     unsigned int man_high :20;
    712     unsigned int man_low  :32;
    713   } bits;
    714 };
    715 
    716 #if V8_TARGET_LITTLE_ENDIAN
    717 typedef IeeeDoubleLittleEndianArchType IeeeDoubleArchType;
    718 const int kIeeeDoubleMantissaWordOffset = 0;
    719 const int kIeeeDoubleExponentWordOffset = 4;
    720 #else
    721 typedef IeeeDoubleBigEndianArchType IeeeDoubleArchType;
    722 const int kIeeeDoubleMantissaWordOffset = 4;
    723 const int kIeeeDoubleExponentWordOffset = 0;
    724 #endif
    725 
    726 // AccessorCallback
    727 struct AccessorDescriptor {
    728   Object* (*getter)(Isolate* isolate, Object* object, void* data);
    729   Object* (*setter)(
    730       Isolate* isolate, JSObject* object, Object* value, void* data);
    731   void* data;
    732 };
    733 
    734 
    735 // -----------------------------------------------------------------------------
    736 // Macros
    737 
    738 // Testers for test.
    739 
    740 #define HAS_SMI_TAG(value) \
    741   ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag)
    742 
    743 // OBJECT_POINTER_ALIGN returns the value aligned as a HeapObject pointer
    744 #define OBJECT_POINTER_ALIGN(value)                             \
    745   (((value) + kObjectAlignmentMask) & ~kObjectAlignmentMask)
    746 
    747 // POINTER_SIZE_ALIGN returns the value aligned as a pointer.
    748 #define POINTER_SIZE_ALIGN(value)                               \
    749   (((value) + kPointerAlignmentMask) & ~kPointerAlignmentMask)
    750 
    751 // CODE_POINTER_ALIGN returns the value aligned as a generated code segment.
    752 #define CODE_POINTER_ALIGN(value)                               \
    753   (((value) + kCodeAlignmentMask) & ~kCodeAlignmentMask)
    754 
    755 // DOUBLE_POINTER_ALIGN returns the value algined for double pointers.
    756 #define DOUBLE_POINTER_ALIGN(value) \
    757   (((value) + kDoubleAlignmentMask) & ~kDoubleAlignmentMask)
    758 
    759 
    760 // CPU feature flags.
    761 enum CpuFeature {
    762   // x86
    763   SSE4_1,
    764   SSSE3,
    765   SSE3,
    766   SAHF,
    767   AVX,
    768   FMA3,
    769   BMI1,
    770   BMI2,
    771   LZCNT,
    772   POPCNT,
    773   ATOM,
    774   // ARM
    775   // - Standard configurations. The baseline is ARMv6+VFPv2.
    776   ARMv7,        // ARMv7-A + VFPv3-D32 + NEON
    777   ARMv7_SUDIV,  // ARMv7-A + VFPv4-D32 + NEON + SUDIV
    778   ARMv8,        // ARMv8-A (+ all of the above)
    779   // MIPS, MIPS64
    780   FPU,
    781   FP64FPU,
    782   MIPSr1,
    783   MIPSr2,
    784   MIPSr6,
    785   // ARM64
    786   ALWAYS_ALIGN_CSP,
    787   // PPC
    788   FPR_GPR_MOV,
    789   LWSYNC,
    790   ISELECT,
    791   // S390
    792   DISTINCT_OPS,
    793   GENERAL_INSTR_EXT,
    794   FLOATING_POINT_EXT,
    795 
    796   NUMBER_OF_CPU_FEATURES,
    797 
    798   // ARM feature aliases (based on the standard configurations above).
    799   VFPv3 = ARMv7,
    800   NEON = ARMv7,
    801   VFP32DREGS = ARMv7,
    802   SUDIV = ARMv7_SUDIV
    803 };
    804 
    805 // Defines hints about receiver values based on structural knowledge.
    806 enum class ConvertReceiverMode : unsigned {
    807   kNullOrUndefined,     // Guaranteed to be null or undefined.
    808   kNotNullOrUndefined,  // Guaranteed to never be null or undefined.
    809   kAny                  // No specific knowledge about receiver.
    810 };
    811 
    812 inline size_t hash_value(ConvertReceiverMode mode) {
    813   return bit_cast<unsigned>(mode);
    814 }
    815 
    816 inline std::ostream& operator<<(std::ostream& os, ConvertReceiverMode mode) {
    817   switch (mode) {
    818     case ConvertReceiverMode::kNullOrUndefined:
    819       return os << "NULL_OR_UNDEFINED";
    820     case ConvertReceiverMode::kNotNullOrUndefined:
    821       return os << "NOT_NULL_OR_UNDEFINED";
    822     case ConvertReceiverMode::kAny:
    823       return os << "ANY";
    824   }
    825   UNREACHABLE();
    826   return os;
    827 }
    828 
    829 // Defines whether tail call optimization is allowed.
    830 enum class TailCallMode : unsigned { kAllow, kDisallow };
    831 
    832 inline size_t hash_value(TailCallMode mode) { return bit_cast<unsigned>(mode); }
    833 
    834 inline std::ostream& operator<<(std::ostream& os, TailCallMode mode) {
    835   switch (mode) {
    836     case TailCallMode::kAllow:
    837       return os << "ALLOW_TAIL_CALLS";
    838     case TailCallMode::kDisallow:
    839       return os << "DISALLOW_TAIL_CALLS";
    840   }
    841   UNREACHABLE();
    842   return os;
    843 }
    844 
    845 // Valid hints for the abstract operation OrdinaryToPrimitive,
    846 // implemented according to ES6, section 7.1.1.
    847 enum class OrdinaryToPrimitiveHint { kNumber, kString };
    848 
    849 // Valid hints for the abstract operation ToPrimitive,
    850 // implemented according to ES6, section 7.1.1.
    851 enum class ToPrimitiveHint { kDefault, kNumber, kString };
    852 
    853 // Defines specifics about arguments object or rest parameter creation.
    854 enum class CreateArgumentsType : uint8_t {
    855   kMappedArguments,
    856   kUnmappedArguments,
    857   kRestParameter
    858 };
    859 
    860 inline size_t hash_value(CreateArgumentsType type) {
    861   return bit_cast<uint8_t>(type);
    862 }
    863 
    864 inline std::ostream& operator<<(std::ostream& os, CreateArgumentsType type) {
    865   switch (type) {
    866     case CreateArgumentsType::kMappedArguments:
    867       return os << "MAPPED_ARGUMENTS";
    868     case CreateArgumentsType::kUnmappedArguments:
    869       return os << "UNMAPPED_ARGUMENTS";
    870     case CreateArgumentsType::kRestParameter:
    871       return os << "REST_PARAMETER";
    872   }
    873   UNREACHABLE();
    874   return os;
    875 }
    876 
    877 // Used to specify if a macro instruction must perform a smi check on tagged
    878 // values.
    879 enum SmiCheckType {
    880   DONT_DO_SMI_CHECK,
    881   DO_SMI_CHECK
    882 };
    883 
    884 enum ScopeType : uint8_t {
    885   EVAL_SCOPE,      // The top-level scope for an eval source.
    886   FUNCTION_SCOPE,  // The top-level scope for a function.
    887   MODULE_SCOPE,    // The scope introduced by a module literal
    888   SCRIPT_SCOPE,    // The top-level scope for a script or a top-level eval.
    889   CATCH_SCOPE,     // The scope introduced by catch.
    890   BLOCK_SCOPE,     // The scope introduced by a new block.
    891   WITH_SCOPE       // The scope introduced by with.
    892 };
    893 
    894 // The mips architecture prior to revision 5 has inverted encoding for sNaN.
    895 // The x87 FPU convert the sNaN to qNaN automatically when loading sNaN from
    896 // memmory.
    897 // Use mips sNaN which is a not used qNaN in x87 port as sNaN to workaround this
    898 // issue
    899 // for some test cases.
    900 #if (V8_TARGET_ARCH_MIPS && !defined(_MIPS_ARCH_MIPS32R6) &&           \
    901      (!defined(USE_SIMULATOR) || !defined(_MIPS_TARGET_SIMULATOR))) || \
    902     (V8_TARGET_ARCH_MIPS64 && !defined(_MIPS_ARCH_MIPS64R6) &&         \
    903      (!defined(USE_SIMULATOR) || !defined(_MIPS_TARGET_SIMULATOR))) || \
    904     (V8_TARGET_ARCH_X87)
    905 const uint32_t kHoleNanUpper32 = 0xFFFF7FFF;
    906 const uint32_t kHoleNanLower32 = 0xFFFF7FFF;
    907 #else
    908 const uint32_t kHoleNanUpper32 = 0xFFF7FFFF;
    909 const uint32_t kHoleNanLower32 = 0xFFF7FFFF;
    910 #endif
    911 
    912 const uint64_t kHoleNanInt64 =
    913     (static_cast<uint64_t>(kHoleNanUpper32) << 32) | kHoleNanLower32;
    914 
    915 
    916 // ES6 section 20.1.2.6 Number.MAX_SAFE_INTEGER
    917 const double kMaxSafeInteger = 9007199254740991.0;  // 2^53-1
    918 
    919 
    920 // The order of this enum has to be kept in sync with the predicates below.
    921 enum VariableMode : uint8_t {
    922   // User declared variables:
    923   VAR,  // declared via 'var', and 'function' declarations
    924 
    925   LET,  // declared via 'let' declarations (first lexical)
    926 
    927   CONST,  // declared via 'const' declarations (last lexical)
    928 
    929   // Variables introduced by the compiler:
    930   TEMPORARY,  // temporary variables (not user-visible), stack-allocated
    931               // unless the scope as a whole has forced context allocation
    932 
    933   DYNAMIC,  // always require dynamic lookup (we don't know
    934             // the declaration)
    935 
    936   DYNAMIC_GLOBAL,  // requires dynamic lookup, but we know that the
    937                    // variable is global unless it has been shadowed
    938                    // by an eval-introduced variable
    939 
    940   DYNAMIC_LOCAL,  // requires dynamic lookup, but we know that the
    941                   // variable is local and where it is unless it
    942                   // has been shadowed by an eval-introduced
    943                   // variable
    944 
    945   kLastVariableMode = DYNAMIC_LOCAL
    946 };
    947 
    948 // Printing support
    949 #ifdef DEBUG
    950 inline const char* VariableMode2String(VariableMode mode) {
    951   switch (mode) {
    952     case VAR:
    953       return "VAR";
    954     case LET:
    955       return "LET";
    956     case CONST:
    957       return "CONST";
    958     case DYNAMIC:
    959       return "DYNAMIC";
    960     case DYNAMIC_GLOBAL:
    961       return "DYNAMIC_GLOBAL";
    962     case DYNAMIC_LOCAL:
    963       return "DYNAMIC_LOCAL";
    964     case TEMPORARY:
    965       return "TEMPORARY";
    966   }
    967   UNREACHABLE();
    968   return NULL;
    969 }
    970 #endif
    971 
    972 enum VariableKind : uint8_t {
    973   NORMAL_VARIABLE,
    974   FUNCTION_VARIABLE,
    975   THIS_VARIABLE,
    976   SLOPPY_FUNCTION_NAME_VARIABLE,
    977   kLastKind = SLOPPY_FUNCTION_NAME_VARIABLE
    978 };
    979 
    980 inline bool IsDynamicVariableMode(VariableMode mode) {
    981   return mode >= DYNAMIC && mode <= DYNAMIC_LOCAL;
    982 }
    983 
    984 
    985 inline bool IsDeclaredVariableMode(VariableMode mode) {
    986   STATIC_ASSERT(VAR == 0);  // Implies that mode >= VAR.
    987   return mode <= CONST;
    988 }
    989 
    990 
    991 inline bool IsLexicalVariableMode(VariableMode mode) {
    992   return mode >= LET && mode <= CONST;
    993 }
    994 
    995 enum VariableLocation : uint8_t {
    996   // Before and during variable allocation, a variable whose location is
    997   // not yet determined.  After allocation, a variable looked up as a
    998   // property on the global object (and possibly absent).  name() is the
    999   // variable name, index() is invalid.
   1000   UNALLOCATED,
   1001 
   1002   // A slot in the parameter section on the stack.  index() is the
   1003   // parameter index, counting left-to-right.  The receiver is index -1;
   1004   // the first parameter is index 0.
   1005   PARAMETER,
   1006 
   1007   // A slot in the local section on the stack.  index() is the variable
   1008   // index in the stack frame, starting at 0.
   1009   LOCAL,
   1010 
   1011   // An indexed slot in a heap context.  index() is the variable index in
   1012   // the context object on the heap, starting at 0.  scope() is the
   1013   // corresponding scope.
   1014   CONTEXT,
   1015 
   1016   // A named slot in a heap context.  name() is the variable name in the
   1017   // context object on the heap, with lookup starting at the current
   1018   // context.  index() is invalid.
   1019   LOOKUP,
   1020 
   1021   // A named slot in a module's export table.
   1022   MODULE,
   1023 
   1024   kLastVariableLocation = MODULE
   1025 };
   1026 
   1027 // ES6 Draft Rev3 10.2 specifies declarative environment records with mutable
   1028 // and immutable bindings that can be in two states: initialized and
   1029 // uninitialized. In ES5 only immutable bindings have these two states. When
   1030 // accessing a binding, it needs to be checked for initialization. However in
   1031 // the following cases the binding is initialized immediately after creation
   1032 // so the initialization check can always be skipped:
   1033 // 1. Var declared local variables.
   1034 //      var foo;
   1035 // 2. A local variable introduced by a function declaration.
   1036 //      function foo() {}
   1037 // 3. Parameters
   1038 //      function x(foo) {}
   1039 // 4. Catch bound variables.
   1040 //      try {} catch (foo) {}
   1041 // 6. Function variables of named function expressions.
   1042 //      var x = function foo() {}
   1043 // 7. Implicit binding of 'this'.
   1044 // 8. Implicit binding of 'arguments' in functions.
   1045 //
   1046 // ES5 specified object environment records which are introduced by ES elements
   1047 // such as Program and WithStatement that associate identifier bindings with the
   1048 // properties of some object. In the specification only mutable bindings exist
   1049 // (which may be non-writable) and have no distinct initialization step. However
   1050 // V8 allows const declarations in global code with distinct creation and
   1051 // initialization steps which are represented by non-writable properties in the
   1052 // global object. As a result also these bindings need to be checked for
   1053 // initialization.
   1054 //
   1055 // The following enum specifies a flag that indicates if the binding needs a
   1056 // distinct initialization step (kNeedsInitialization) or if the binding is
   1057 // immediately initialized upon creation (kCreatedInitialized).
   1058 enum InitializationFlag : uint8_t { kNeedsInitialization, kCreatedInitialized };
   1059 
   1060 enum class HoleCheckMode { kRequired, kElided };
   1061 
   1062 enum MaybeAssignedFlag : uint8_t { kNotAssigned, kMaybeAssigned };
   1063 
   1064 // Serialized in PreparseData, so numeric values should not be changed.
   1065 enum ParseErrorType { kSyntaxError = 0, kReferenceError = 1 };
   1066 
   1067 
   1068 enum MinusZeroMode {
   1069   TREAT_MINUS_ZERO_AS_ZERO,
   1070   FAIL_ON_MINUS_ZERO
   1071 };
   1072 
   1073 
   1074 enum Signedness { kSigned, kUnsigned };
   1075 
   1076 enum FunctionKind : uint16_t {
   1077   kNormalFunction = 0,
   1078   kArrowFunction = 1 << 0,
   1079   kGeneratorFunction = 1 << 1,
   1080   kConciseMethod = 1 << 2,
   1081   kConciseGeneratorMethod = kGeneratorFunction | kConciseMethod,
   1082   kDefaultConstructor = 1 << 3,
   1083   kSubclassConstructor = 1 << 4,
   1084   kBaseConstructor = 1 << 5,
   1085   kGetterFunction = 1 << 6,
   1086   kSetterFunction = 1 << 7,
   1087   kAsyncFunction = 1 << 8,
   1088   kModule = 1 << 9,
   1089   kAccessorFunction = kGetterFunction | kSetterFunction,
   1090   kDefaultBaseConstructor = kDefaultConstructor | kBaseConstructor,
   1091   kDefaultSubclassConstructor = kDefaultConstructor | kSubclassConstructor,
   1092   kClassConstructor =
   1093       kBaseConstructor | kSubclassConstructor | kDefaultConstructor,
   1094   kAsyncArrowFunction = kArrowFunction | kAsyncFunction,
   1095   kAsyncConciseMethod = kAsyncFunction | kConciseMethod
   1096 };
   1097 
   1098 inline bool IsValidFunctionKind(FunctionKind kind) {
   1099   return kind == FunctionKind::kNormalFunction ||
   1100          kind == FunctionKind::kArrowFunction ||
   1101          kind == FunctionKind::kGeneratorFunction ||
   1102          kind == FunctionKind::kModule ||
   1103          kind == FunctionKind::kConciseMethod ||
   1104          kind == FunctionKind::kConciseGeneratorMethod ||
   1105          kind == FunctionKind::kGetterFunction ||
   1106          kind == FunctionKind::kSetterFunction ||
   1107          kind == FunctionKind::kAccessorFunction ||
   1108          kind == FunctionKind::kDefaultBaseConstructor ||
   1109          kind == FunctionKind::kDefaultSubclassConstructor ||
   1110          kind == FunctionKind::kBaseConstructor ||
   1111          kind == FunctionKind::kSubclassConstructor ||
   1112          kind == FunctionKind::kAsyncFunction ||
   1113          kind == FunctionKind::kAsyncArrowFunction ||
   1114          kind == FunctionKind::kAsyncConciseMethod;
   1115 }
   1116 
   1117 
   1118 inline bool IsArrowFunction(FunctionKind kind) {
   1119   DCHECK(IsValidFunctionKind(kind));
   1120   return kind & FunctionKind::kArrowFunction;
   1121 }
   1122 
   1123 
   1124 inline bool IsGeneratorFunction(FunctionKind kind) {
   1125   DCHECK(IsValidFunctionKind(kind));
   1126   return kind & FunctionKind::kGeneratorFunction;
   1127 }
   1128 
   1129 inline bool IsModule(FunctionKind kind) {
   1130   DCHECK(IsValidFunctionKind(kind));
   1131   return kind & FunctionKind::kModule;
   1132 }
   1133 
   1134 inline bool IsAsyncFunction(FunctionKind kind) {
   1135   DCHECK(IsValidFunctionKind(kind));
   1136   return kind & FunctionKind::kAsyncFunction;
   1137 }
   1138 
   1139 inline bool IsResumableFunction(FunctionKind kind) {
   1140   return IsGeneratorFunction(kind) || IsAsyncFunction(kind) || IsModule(kind);
   1141 }
   1142 
   1143 inline bool IsConciseMethod(FunctionKind kind) {
   1144   DCHECK(IsValidFunctionKind(kind));
   1145   return kind & FunctionKind::kConciseMethod;
   1146 }
   1147 
   1148 inline bool IsGetterFunction(FunctionKind kind) {
   1149   DCHECK(IsValidFunctionKind(kind));
   1150   return kind & FunctionKind::kGetterFunction;
   1151 }
   1152 
   1153 inline bool IsSetterFunction(FunctionKind kind) {
   1154   DCHECK(IsValidFunctionKind(kind));
   1155   return kind & FunctionKind::kSetterFunction;
   1156 }
   1157 
   1158 inline bool IsAccessorFunction(FunctionKind kind) {
   1159   DCHECK(IsValidFunctionKind(kind));
   1160   return kind & FunctionKind::kAccessorFunction;
   1161 }
   1162 
   1163 
   1164 inline bool IsDefaultConstructor(FunctionKind kind) {
   1165   DCHECK(IsValidFunctionKind(kind));
   1166   return kind & FunctionKind::kDefaultConstructor;
   1167 }
   1168 
   1169 
   1170 inline bool IsBaseConstructor(FunctionKind kind) {
   1171   DCHECK(IsValidFunctionKind(kind));
   1172   return kind & FunctionKind::kBaseConstructor;
   1173 }
   1174 
   1175 
   1176 inline bool IsSubclassConstructor(FunctionKind kind) {
   1177   DCHECK(IsValidFunctionKind(kind));
   1178   return kind & FunctionKind::kSubclassConstructor;
   1179 }
   1180 
   1181 
   1182 inline bool IsClassConstructor(FunctionKind kind) {
   1183   DCHECK(IsValidFunctionKind(kind));
   1184   return kind & FunctionKind::kClassConstructor;
   1185 }
   1186 
   1187 
   1188 inline bool IsConstructable(FunctionKind kind, LanguageMode mode) {
   1189   if (IsAccessorFunction(kind)) return false;
   1190   if (IsConciseMethod(kind)) return false;
   1191   if (IsArrowFunction(kind)) return false;
   1192   if (IsGeneratorFunction(kind)) return false;
   1193   if (IsAsyncFunction(kind)) return false;
   1194   return true;
   1195 }
   1196 
   1197 enum class CallableType : unsigned { kJSFunction, kAny };
   1198 
   1199 inline size_t hash_value(CallableType type) { return bit_cast<unsigned>(type); }
   1200 
   1201 inline std::ostream& operator<<(std::ostream& os, CallableType function_type) {
   1202   switch (function_type) {
   1203     case CallableType::kJSFunction:
   1204       return os << "JSFunction";
   1205     case CallableType::kAny:
   1206       return os << "Any";
   1207   }
   1208   UNREACHABLE();
   1209   return os;
   1210 }
   1211 
   1212 inline uint32_t ObjectHash(Address address) {
   1213   // All objects are at least pointer aligned, so we can remove the trailing
   1214   // zeros.
   1215   return static_cast<uint32_t>(bit_cast<uintptr_t>(address) >>
   1216                                kPointerSizeLog2);
   1217 }
   1218 
   1219 // Type feedback is encoded in such a way that, we can combine the feedback
   1220 // at different points by performing an 'OR' operation. Type feedback moves
   1221 // to a more generic type when we combine feedback.
   1222 // kSignedSmall -> kNumber  -> kNumberOrOddball -> kAny
   1223 //                             kString          -> kAny
   1224 // TODO(mythria): Remove kNumber type when crankshaft can handle Oddballs
   1225 // similar to Numbers. We don't need kNumber feedback for Turbofan. Extra
   1226 // information about Number might reduce few instructions but causes more
   1227 // deopts. We collect Number only because crankshaft does not handle all
   1228 // cases of oddballs.
   1229 class BinaryOperationFeedback {
   1230  public:
   1231   enum {
   1232     kNone = 0x0,
   1233     kSignedSmall = 0x1,
   1234     kNumber = 0x3,
   1235     kNumberOrOddball = 0x7,
   1236     kString = 0x8,
   1237     kAny = 0x1F
   1238   };
   1239 };
   1240 
   1241 // TODO(epertoso): consider unifying this with BinaryOperationFeedback.
   1242 class CompareOperationFeedback {
   1243  public:
   1244   enum { kNone = 0x00, kSignedSmall = 0x01, kNumber = 0x3, kAny = 0x7 };
   1245 };
   1246 
   1247 // Describes how exactly a frame has been dropped from stack.
   1248 enum LiveEditFrameDropMode {
   1249   // No frame has been dropped.
   1250   LIVE_EDIT_FRAMES_UNTOUCHED,
   1251   // The top JS frame had been calling debug break slot stub. Patch the
   1252   // address this stub jumps to in the end.
   1253   LIVE_EDIT_FRAME_DROPPED_IN_DEBUG_SLOT_CALL,
   1254   // The top JS frame had been calling some C++ function. The return address
   1255   // gets patched automatically.
   1256   LIVE_EDIT_FRAME_DROPPED_IN_DIRECT_CALL,
   1257   LIVE_EDIT_FRAME_DROPPED_IN_RETURN_CALL,
   1258   LIVE_EDIT_CURRENTLY_SET_MODE
   1259 };
   1260 
   1261 enum class UnicodeEncoding : uint8_t {
   1262   // Different unicode encodings in a |word32|:
   1263   UTF16,  // hi 16bits -> trailing surrogate or 0, low 16bits -> lead surrogate
   1264   UTF32,  // full UTF32 code unit / Unicode codepoint
   1265 };
   1266 
   1267 inline size_t hash_value(UnicodeEncoding encoding) {
   1268   return static_cast<uint8_t>(encoding);
   1269 }
   1270 
   1271 inline std::ostream& operator<<(std::ostream& os, UnicodeEncoding encoding) {
   1272   switch (encoding) {
   1273     case UnicodeEncoding::UTF16:
   1274       return os << "UTF16";
   1275     case UnicodeEncoding::UTF32:
   1276       return os << "UTF32";
   1277   }
   1278   UNREACHABLE();
   1279   return os;
   1280 }
   1281 
   1282 enum class IterationKind { kKeys, kValues, kEntries };
   1283 
   1284 inline std::ostream& operator<<(std::ostream& os, IterationKind kind) {
   1285   switch (kind) {
   1286     case IterationKind::kKeys:
   1287       return os << "IterationKind::kKeys";
   1288     case IterationKind::kValues:
   1289       return os << "IterationKind::kValues";
   1290     case IterationKind::kEntries:
   1291       return os << "IterationKind::kEntries";
   1292   }
   1293   UNREACHABLE();
   1294   return os;
   1295 }
   1296 
   1297 }  // namespace internal
   1298 }  // namespace v8
   1299 
   1300 // Used by js-builtin-reducer to identify whether ReduceArrayIterator() is
   1301 // reducing a JSArray method, or a JSTypedArray method.
   1302 enum class ArrayIteratorKind { kArray, kTypedArray };
   1303 
   1304 namespace i = v8::internal;
   1305 
   1306 #endif  // V8_GLOBALS_H_
   1307