2012-02-22 12:26:36 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-11-05 19:18:10 +00:00
|
|
|
#ifndef V8_GLOBALS_H_
|
|
|
|
#define V8_GLOBALS_H_
|
|
|
|
|
2014-10-21 08:25:14 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
2011-09-07 12:39:53 +00:00
|
|
|
|
2015-04-27 09:12:58 +00:00
|
|
|
#include <ostream>
|
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/base/build_config.h"
|
2014-06-30 13:25:46 +00:00
|
|
|
#include "src/base/logging.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/base/macros.h"
|
2014-04-23 11:51:28 +00:00
|
|
|
|
2014-12-20 13:17:20 +00:00
|
|
|
// Unfortunately, the INFINITY macro cannot be used with the '-pedantic'
|
|
|
|
// warning flag and certain versions of GCC due to a bug:
|
|
|
|
// http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11931
|
|
|
|
// For now, we use the more involved template-based version from <limits>, but
|
|
|
|
// only when compiling with GCC versions affected by the bug (2.96.x - 4.0.x)
|
|
|
|
#if V8_CC_GNU && V8_GNUC_PREREQ(2, 96, 0) && !V8_GNUC_PREREQ(4, 1, 0)
|
|
|
|
# include <limits> // NOLINT
|
|
|
|
# define V8_INFINITY std::numeric_limits<double>::infinity()
|
|
|
|
#elif V8_LIBC_MSVCRT
|
|
|
|
# define V8_INFINITY HUGE_VAL
|
2015-01-30 08:01:53 +00:00
|
|
|
#elif V8_OS_AIX
|
|
|
|
#define V8_INFINITY (__builtin_inff())
|
2014-12-20 13:17:20 +00:00
|
|
|
#else
|
|
|
|
# define V8_INFINITY INFINITY
|
|
|
|
#endif
|
|
|
|
|
2013-07-31 07:51:46 +00:00
|
|
|
namespace v8 {
|
2014-06-30 13:25:46 +00:00
|
|
|
|
|
|
|
namespace base {
|
|
|
|
class Mutex;
|
|
|
|
class RecursiveMutex;
|
|
|
|
class VirtualMemory;
|
|
|
|
}
|
|
|
|
|
2013-07-31 07:51:46 +00:00
|
|
|
namespace internal {
|
2013-07-29 12:12:39 +00:00
|
|
|
|
2010-10-25 16:40:41 +00:00
|
|
|
// Determine whether we are running in a simulated environment.
|
2010-10-26 08:12:17 +00:00
|
|
|
// Setting USE_SIMULATOR explicitly from the build script will force
|
|
|
|
// the use of a simulated environment.
|
|
|
|
#if !defined(USE_SIMULATOR)
|
2014-03-21 09:28:26 +00:00
|
|
|
#if (V8_TARGET_ARCH_ARM64 && !V8_HOST_ARCH_ARM64)
|
2014-02-12 09:19:30 +00:00
|
|
|
#define USE_SIMULATOR 1
|
|
|
|
#endif
|
2013-07-31 07:51:46 +00:00
|
|
|
#if (V8_TARGET_ARCH_ARM && !V8_HOST_ARCH_ARM)
|
|
|
|
#define USE_SIMULATOR 1
|
|
|
|
#endif
|
2015-01-16 07:42:00 +00:00
|
|
|
#if (V8_TARGET_ARCH_PPC && !V8_HOST_ARCH_PPC)
|
|
|
|
#define USE_SIMULATOR 1
|
|
|
|
#endif
|
2013-07-31 07:51:46 +00:00
|
|
|
#if (V8_TARGET_ARCH_MIPS && !V8_HOST_ARCH_MIPS)
|
|
|
|
#define USE_SIMULATOR 1
|
2010-10-26 08:12:17 +00:00
|
|
|
#endif
|
2014-07-09 11:08:26 +00:00
|
|
|
#if (V8_TARGET_ARCH_MIPS64 && !V8_HOST_ARCH_MIPS64)
|
|
|
|
#define USE_SIMULATOR 1
|
|
|
|
#endif
|
2013-06-21 13:02:38 +00:00
|
|
|
#endif
|
|
|
|
|
2015-06-04 14:44:00 +00:00
|
|
|
// 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
|
2014-03-11 20:52:00 +00:00
|
|
|
|
2014-09-19 11:26:36 +00:00
|
|
|
#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
|
|
|
|
|
|
|
|
|
2014-11-11 10:24:52 +00:00
|
|
|
// Determine whether double field unboxing feature is enabled.
|
2015-01-16 07:42:00 +00:00
|
|
|
#if V8_TARGET_ARCH_64_BIT
|
2015-02-26 12:26:49 +00:00
|
|
|
#define V8_DOUBLE_FIELDS_UNBOXING 1
|
2014-11-11 10:24:52 +00:00
|
|
|
#else
|
|
|
|
#define V8_DOUBLE_FIELDS_UNBOXING 0
|
|
|
|
#endif
|
|
|
|
|
2013-07-29 12:12:39 +00:00
|
|
|
|
2013-07-30 10:36:58 +00:00
|
|
|
typedef uint8_t byte;
|
|
|
|
typedef byte* Address;
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// 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;
|
2013-11-08 17:35:58 +00:00
|
|
|
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;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-04-27 11:16:59 +00:00
|
|
|
const uint32_t kMaxUInt32 = 0xFFFFFFFFu;
|
|
|
|
|
2013-07-23 13:46:10 +00:00
|
|
|
const int kCharSize = sizeof(char); // NOLINT
|
|
|
|
const int kShortSize = sizeof(short); // NOLINT
|
|
|
|
const int kIntSize = sizeof(int); // NOLINT
|
2013-10-14 13:35:06 +00:00
|
|
|
const int kInt32Size = sizeof(int32_t); // NOLINT
|
|
|
|
const int kInt64Size = sizeof(int64_t); // NOLINT
|
2015-06-03 23:56:21 +00:00
|
|
|
const int kFloatSize = sizeof(float); // NOLINT
|
2013-07-23 13:46:10 +00:00
|
|
|
const int kDoubleSize = sizeof(double); // NOLINT
|
|
|
|
const int kIntptrSize = sizeof(intptr_t); // NOLINT
|
|
|
|
const int kPointerSize = sizeof(void*); // NOLINT
|
2014-06-24 05:27:44 +00:00
|
|
|
#if V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_32_BIT
|
|
|
|
const int kRegisterSize = kPointerSize + kPointerSize;
|
|
|
|
#else
|
2013-07-23 13:46:10 +00:00
|
|
|
const int kRegisterSize = kPointerSize;
|
2014-06-24 05:27:44 +00:00
|
|
|
#endif
|
2013-07-23 13:46:10 +00:00
|
|
|
const int kPCOnStackSize = kRegisterSize;
|
|
|
|
const int kFPOnStackSize = kRegisterSize;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-07-13 13:50:27 +00:00
|
|
|
const int kDoubleSizeLog2 = 3;
|
|
|
|
|
2009-05-05 12:06:20 +00:00
|
|
|
#if V8_HOST_ARCH_64_BIT
|
2009-05-04 13:29:29 +00:00
|
|
|
const int kPointerSizeLog2 = 3;
|
2009-06-17 11:50:33 +00:00
|
|
|
const intptr_t kIntptrSignBit = V8_INT64_C(0x8000000000000000);
|
2010-10-26 18:14:45 +00:00
|
|
|
const uintptr_t kUintptrAllBitsSet = V8_UINT64_C(0xFFFFFFFFFFFFFFFF);
|
2014-06-13 11:06:42 +00:00
|
|
|
const bool kRequiresCodeRange = true;
|
2015-06-09 14:50:26 +00:00
|
|
|
#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;
|
|
|
|
#else
|
2014-06-13 11:06:42 +00:00
|
|
|
const size_t kMaximalCodeRangeSize = 512 * MB;
|
2015-06-09 14:50:26 +00:00
|
|
|
#endif
|
2014-10-01 09:16:57 +00:00
|
|
|
#if V8_OS_WIN
|
2014-10-02 08:28:29 +00:00
|
|
|
const size_t kMinimumCodeRangeSize = 4 * MB;
|
2014-10-01 09:16:57 +00:00
|
|
|
const size_t kReservedCodeRangePages = 1;
|
|
|
|
#else
|
2014-10-02 08:28:29 +00:00
|
|
|
const size_t kMinimumCodeRangeSize = 3 * MB;
|
2014-10-01 09:16:57 +00:00
|
|
|
const size_t kReservedCodeRangePages = 0;
|
|
|
|
#endif
|
2009-05-04 13:29:29 +00:00
|
|
|
#else
|
2008-07-03 15:10:15 +00:00
|
|
|
const int kPointerSizeLog2 = 2;
|
2009-06-17 11:50:33 +00:00
|
|
|
const intptr_t kIntptrSignBit = 0x80000000;
|
2010-10-26 18:14:45 +00:00
|
|
|
const uintptr_t kUintptrAllBitsSet = 0xFFFFFFFFu;
|
2014-06-24 05:27:44 +00:00
|
|
|
#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;
|
2014-10-02 08:28:29 +00:00
|
|
|
const size_t kMinimumCodeRangeSize = 3 * MB;
|
2014-10-01 09:16:57 +00:00
|
|
|
const size_t kReservedCodeRangePages = 0;
|
2014-06-24 05:27:44 +00:00
|
|
|
#else
|
2014-06-13 11:06:42 +00:00
|
|
|
const bool kRequiresCodeRange = false;
|
|
|
|
const size_t kMaximalCodeRangeSize = 0 * MB;
|
2014-10-01 09:16:57 +00:00
|
|
|
const size_t kMinimumCodeRangeSize = 0 * MB;
|
|
|
|
const size_t kReservedCodeRangePages = 0;
|
2009-05-04 13:29:29 +00:00
|
|
|
#endif
|
2014-06-24 05:27:44 +00:00
|
|
|
#endif
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-06-24 09:31:30 +00:00
|
|
|
STATIC_ASSERT(kPointerSize == (1 << kPointerSizeLog2));
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
const int kBitsPerByte = 8;
|
|
|
|
const int kBitsPerByteLog2 = 3;
|
|
|
|
const int kBitsPerPointer = kPointerSize * kBitsPerByte;
|
|
|
|
const int kBitsPerInt = kIntSize * kBitsPerByte;
|
|
|
|
|
2010-03-23 13:38:04 +00:00
|
|
|
// 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;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-09-26 12:44:36 +00:00
|
|
|
// 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;
|
|
|
|
|
2013-01-09 10:30:54 +00:00
|
|
|
// Latin1/UTF-16 constants
|
2010-12-22 20:14:19 +00:00
|
|
|
// Code-point values in Unicode 4.0 are 21 bits wide.
|
2012-03-12 12:35:28 +00:00
|
|
|
// Code units in UTF-16 are 16 bits wide.
|
2010-12-22 20:14:19 +00:00
|
|
|
typedef uint16_t uc16;
|
|
|
|
typedef int32_t uc32;
|
2013-01-09 10:30:54 +00:00
|
|
|
const int kOneByteSize = kCharSize;
|
2010-12-22 20:14:19 +00:00
|
|
|
const int kUC16Size = sizeof(uc16); // NOLINT
|
|
|
|
|
2015-06-02 22:56:00 +00:00
|
|
|
// 128 bit SIMD value size.
|
|
|
|
const int kSimd128Size = 16;
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2013-08-23 08:22:07 +00:00
|
|
|
// 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))
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// 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));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-15 13:23:30 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Forward declarations for frequently used classes
|
|
|
|
// (sorted alphabetically)
|
2010-08-31 08:05:42 +00:00
|
|
|
|
2010-11-15 13:23:30 +00:00
|
|
|
class FreeStoreAllocationPolicy;
|
|
|
|
template <typename T, class P = FreeStoreAllocationPolicy> class List;
|
2009-11-13 12:32:57 +00:00
|
|
|
|
2011-10-27 13:08:51 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Declarations for use in both the preparser and the rest of V8.
|
|
|
|
|
|
|
|
// The Strict Mode (ECMA-262 5th edition, 4.2.2).
|
2014-03-11 14:41:22 +00:00
|
|
|
|
2015-02-04 09:34:05 +00:00
|
|
|
enum LanguageMode {
|
|
|
|
// LanguageMode is expressed as a bitmask. Descriptions of the bits:
|
2015-02-05 14:11:34 +00:00
|
|
|
STRICT_BIT = 1 << 0,
|
|
|
|
STRONG_BIT = 1 << 1,
|
2015-02-04 09:34:05 +00:00
|
|
|
LANGUAGE_END,
|
2011-10-27 13:08:51 +00:00
|
|
|
|
2015-02-04 09:34:05 +00:00
|
|
|
// Shorthands for some common language modes.
|
2015-02-05 14:11:34 +00:00
|
|
|
SLOPPY = 0,
|
|
|
|
STRICT = STRICT_BIT,
|
|
|
|
STRONG = STRICT_BIT | STRONG_BIT
|
2015-02-04 09:34:05 +00:00
|
|
|
};
|
|
|
|
|
2015-02-05 14:11:34 +00:00
|
|
|
|
2015-05-21 14:31:41 +00:00
|
|
|
inline std::ostream& operator<<(std::ostream& os, const LanguageMode& mode) {
|
2015-04-27 09:12:58 +00:00
|
|
|
switch (mode) {
|
|
|
|
case SLOPPY:
|
|
|
|
return os << "sloppy";
|
|
|
|
case STRICT:
|
|
|
|
return os << "strict";
|
|
|
|
case STRONG:
|
|
|
|
return os << "strong";
|
|
|
|
default:
|
|
|
|
return os << "unknown";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-05 14:11:34 +00:00
|
|
|
inline bool is_sloppy(LanguageMode language_mode) {
|
|
|
|
return (language_mode & STRICT_BIT) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-04 09:34:05 +00:00
|
|
|
inline bool is_strict(LanguageMode language_mode) {
|
2015-02-05 14:11:34 +00:00
|
|
|
return language_mode & STRICT_BIT;
|
2015-02-04 09:34:05 +00:00
|
|
|
}
|
|
|
|
|
2015-02-05 14:11:34 +00:00
|
|
|
|
|
|
|
inline bool is_strong(LanguageMode language_mode) {
|
|
|
|
return language_mode & STRONG_BIT;
|
2015-02-04 09:34:05 +00:00
|
|
|
}
|
|
|
|
|
2015-02-05 14:11:34 +00:00
|
|
|
|
2015-02-04 09:34:05 +00:00
|
|
|
inline bool is_valid_language_mode(int language_mode) {
|
2015-02-05 14:11:34 +00:00
|
|
|
return language_mode == SLOPPY || language_mode == STRICT ||
|
|
|
|
language_mode == STRONG;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline LanguageMode construct_language_mode(bool strict_bit, bool strong_bit) {
|
|
|
|
int language_mode = 0;
|
|
|
|
if (strict_bit) language_mode |= STRICT_BIT;
|
|
|
|
if (strong_bit) language_mode |= STRONG_BIT;
|
|
|
|
DCHECK(is_valid_language_mode(language_mode));
|
|
|
|
return static_cast<LanguageMode>(language_mode);
|
2015-02-04 09:34:05 +00:00
|
|
|
}
|
2011-10-27 13:08:51 +00:00
|
|
|
|
2015-02-05 14:11:34 +00:00
|
|
|
|
2015-06-08 12:17:58 +00:00
|
|
|
// Strong mode behaviour must sometimes be signalled by a two valued enum where
|
|
|
|
// caching is involved, to prevent sloppy and strict mode from being incorrectly
|
|
|
|
// differentiated.
|
|
|
|
enum class Strength : bool {
|
|
|
|
WEAK, // sloppy, strict behaviour
|
|
|
|
STRONG // strong behaviour
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
inline bool is_strong(Strength strength) {
|
|
|
|
return strength == Strength::STRONG;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline std::ostream& operator<<(std::ostream& os, const Strength& strength) {
|
|
|
|
return os << (is_strong(strength) ? "strong" : "weak");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline Strength strength(LanguageMode language_mode) {
|
|
|
|
return is_strong(language_mode) ? Strength::STRONG : Strength::WEAK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline size_t hash_value(Strength strength) {
|
|
|
|
return static_cast<size_t>(strength);
|
2015-06-02 11:46:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-26 11:28:08 +00:00
|
|
|
// 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;
|
|
|
|
|
2015-06-02 22:56:00 +00:00
|
|
|
// Desired alignment for 128 bit SIMD values.
|
|
|
|
const intptr_t kSimd128Alignment = 16;
|
|
|
|
const intptr_t kSimd128AlignmentMask = kSimd128Alignment - 1;
|
|
|
|
|
2014-05-26 11:28:08 +00:00
|
|
|
// 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;
|
|
|
|
|
2014-07-28 18:54:06 +00:00
|
|
|
// 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;
|
2014-07-15 12:22:38 +00:00
|
|
|
|
2014-05-26 11:28:08 +00:00
|
|
|
|
|
|
|
// 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 =
|
|
|
|
reinterpret_cast<Address>(V8_UINT64_C(0xdeadbeedbeadbeef));
|
|
|
|
const Address kHandleZapValue =
|
|
|
|
reinterpret_cast<Address>(V8_UINT64_C(0x1baddead0baddeaf));
|
|
|
|
const Address kGlobalHandleZapValue =
|
|
|
|
reinterpret_cast<Address>(V8_UINT64_C(0x1baffed00baffedf));
|
|
|
|
const Address kFromSpaceZapValue =
|
|
|
|
reinterpret_cast<Address>(V8_UINT64_C(0x1beefdad0beefdaf));
|
|
|
|
const uint64_t kDebugZapValue = V8_UINT64_C(0xbadbaddbbadbaddb);
|
|
|
|
const uint64_t kSlotsZapValue = V8_UINT64_C(0xbeefdeadbeefdeef);
|
|
|
|
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;
|
2014-11-03 17:23:55 +00:00
|
|
|
const uint32_t kPhantomReferenceZap = 0xca11bac;
|
2014-05-26 11:28:08 +00:00
|
|
|
|
|
|
|
// 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 Allocation;
|
|
|
|
class Arguments;
|
|
|
|
class Assembler;
|
|
|
|
class Code;
|
|
|
|
class CodeGenerator;
|
|
|
|
class CodeStub;
|
|
|
|
class Context;
|
|
|
|
class Debug;
|
|
|
|
class DebugInfo;
|
|
|
|
class Descriptor;
|
|
|
|
class DescriptorArray;
|
|
|
|
class TransitionArray;
|
|
|
|
class ExternalReference;
|
|
|
|
class FixedArray;
|
|
|
|
class FunctionTemplateInfo;
|
|
|
|
class MemoryChunk;
|
|
|
|
class SeededNumberDictionary;
|
|
|
|
class UnseededNumberDictionary;
|
|
|
|
class NameDictionary;
|
2015-06-01 15:43:24 +00:00
|
|
|
class GlobalDictionary;
|
2014-05-26 11:28:08 +00:00
|
|
|
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;
|
2015-08-21 10:25:10 +00:00
|
|
|
class ParameterCount;
|
2014-05-26 11:28:08 +00:00
|
|
|
class Foreign;
|
|
|
|
class Scope;
|
|
|
|
class ScopeInfo;
|
|
|
|
class Script;
|
|
|
|
class Smi;
|
|
|
|
template <typename Config, class Allocator = FreeStoreAllocationPolicy>
|
2015-09-01 15:19:57 +00:00
|
|
|
class SplayTree;
|
2014-05-26 11:28:08 +00:00
|
|
|
class String;
|
2014-12-10 20:02:48 +00:00
|
|
|
class Symbol;
|
2014-05-26 11:28:08 +00:00
|
|
|
class Name;
|
|
|
|
class Struct;
|
|
|
|
class Variable;
|
|
|
|
class RelocInfo;
|
|
|
|
class Deserializer;
|
|
|
|
class MessageLocation;
|
|
|
|
|
|
|
|
typedef bool (*WeakSlotCallback)(Object** pointer);
|
|
|
|
|
|
|
|
typedef bool (*WeakSlotCallbackWithHeap)(Heap* heap, Object** pointer);
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Miscellaneous
|
|
|
|
|
|
|
|
// NOTE: SpaceIterator depends on AllocationSpace enumeration values being
|
|
|
|
// consecutive.
|
2014-12-22 08:51:57 +00:00
|
|
|
// Keep this enum in sync with the ObjectSpace enum in v8.h
|
2014-05-26 11:28:08 +00:00
|
|
|
enum AllocationSpace {
|
2015-04-07 11:31:57 +00:00
|
|
|
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.
|
2014-05-26 11:28:08 +00:00
|
|
|
|
|
|
|
FIRST_SPACE = NEW_SPACE,
|
|
|
|
LAST_SPACE = LO_SPACE,
|
2015-04-07 11:31:57 +00:00
|
|
|
FIRST_PAGED_SPACE = OLD_SPACE,
|
2015-04-10 13:54:09 +00:00
|
|
|
LAST_PAGED_SPACE = MAP_SPACE
|
2014-05-26 11:28:08 +00:00
|
|
|
};
|
|
|
|
const int kSpaceTagSize = 3;
|
|
|
|
const int kSpaceTagMask = (1 << kSpaceTagSize) - 1;
|
|
|
|
|
2015-06-02 22:56:00 +00:00
|
|
|
enum AllocationAlignment {
|
|
|
|
kWordAligned,
|
|
|
|
kDoubleAligned,
|
|
|
|
kDoubleUnaligned,
|
|
|
|
kSimd128Unaligned
|
|
|
|
};
|
2014-05-26 11:28:08 +00:00
|
|
|
|
|
|
|
// 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 };
|
|
|
|
|
2015-05-21 14:31:41 +00:00
|
|
|
inline std::ostream& operator<<(std::ostream& os, const PretenureFlag& flag) {
|
|
|
|
switch (flag) {
|
|
|
|
case NOT_TENURED:
|
|
|
|
return os << "NotTenured";
|
|
|
|
case TENURED:
|
|
|
|
return os << "Tenured";
|
|
|
|
}
|
|
|
|
UNREACHABLE();
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
2014-05-26 11:28:08 +00:00
|
|
|
enum MinimumCapacity {
|
|
|
|
USE_DEFAULT_MINIMUM_CAPACITY,
|
|
|
|
USE_CUSTOM_MINIMUM_CAPACITY
|
|
|
|
};
|
|
|
|
|
|
|
|
enum GarbageCollector { SCAVENGER, MARK_COMPACTOR };
|
|
|
|
|
|
|
|
enum Executability { NOT_EXECUTABLE, EXECUTABLE };
|
|
|
|
|
|
|
|
enum VisitMode {
|
|
|
|
VISIT_ALL,
|
|
|
|
VISIT_ALL_IN_SCAVENGE,
|
|
|
|
VISIT_ALL_IN_SWEEP_NEWSPACE,
|
|
|
|
VISIT_ONLY_STRONG
|
|
|
|
};
|
|
|
|
|
|
|
|
// Flag indicating whether code is built into the VM (one of the natives files).
|
|
|
|
enum NativesFlag { NOT_NATIVES_CODE, NATIVES_CODE };
|
|
|
|
|
2015-08-11 07:34:10 +00:00
|
|
|
// JavaScript defines two kinds of 'nil'.
|
|
|
|
enum NilValue { kNullValue, kUndefinedValue };
|
2014-05-26 11:28:08 +00:00
|
|
|
|
2015-03-09 14:51:13 +00:00
|
|
|
// 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.
|
|
|
|
};
|
|
|
|
|
2014-05-26 11:28:08 +00:00
|
|
|
// 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
|
2015-06-04 14:44:00 +00:00
|
|
|
// the buffer and grows backward. A constant pool may exist at the
|
|
|
|
// end of the instructions.
|
2014-05-26 11:28:08 +00:00
|
|
|
//
|
2015-06-04 14:44:00 +00:00
|
|
|
// |<--------------- buffer_size ----------------------------------->|
|
|
|
|
// |<------------- instr_size ---------->| |<-- reloc_size -->|
|
|
|
|
// | |<- const_pool_size ->| |
|
|
|
|
// +=====================================+========+==================+
|
|
|
|
// | instructions | data | free | reloc info |
|
|
|
|
// +=====================================+========+==================+
|
2014-05-26 11:28:08 +00:00
|
|
|
// ^
|
|
|
|
// |
|
|
|
|
// buffer
|
|
|
|
|
|
|
|
struct CodeDesc {
|
|
|
|
byte* buffer;
|
|
|
|
int buffer_size;
|
|
|
|
int instr_size;
|
|
|
|
int reloc_size;
|
2015-06-04 14:44:00 +00:00
|
|
|
int constant_pool_size;
|
2014-05-26 11:28:08 +00:00
|
|
|
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,
|
2014-07-18 13:50:21 +00:00
|
|
|
// Check failed due to prototype (or map deprecation).
|
|
|
|
PROTOTYPE_FAILURE,
|
2014-05-26 11:28:08 +00:00
|
|
|
// 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,
|
|
|
|
// Special state for debug break or step in prepare stubs.
|
2014-08-07 15:33:14 +00:00
|
|
|
DEBUG_STUB,
|
|
|
|
// Type-vector-based ICs have a default state, with the full calculation
|
|
|
|
// of IC state only determined by a look at the IC and the typevector
|
|
|
|
// together.
|
|
|
|
DEFAULT
|
2014-05-26 11:28:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
enum CallFunctionFlags {
|
|
|
|
NO_CALL_FUNCTION_FLAGS,
|
|
|
|
CALL_AS_METHOD,
|
|
|
|
// Always wrap the receiver and call to the JSFunction. Only use this flag
|
|
|
|
// both the receiver type and the target method are statically known.
|
|
|
|
WRAP_AND_CALL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
enum CallConstructorFlags {
|
2015-02-11 09:47:32 +00:00
|
|
|
NO_CALL_CONSTRUCTOR_FLAGS = 0,
|
2014-05-26 11:28:08 +00:00
|
|
|
// The call target is cached in the instruction stream.
|
2015-02-11 09:47:32 +00:00
|
|
|
RECORD_CONSTRUCTOR_TARGET = 1,
|
2015-09-22 04:27:14 +00:00
|
|
|
// TODO(bmeurer): Kill these SUPER_* modes and use the Construct builtin
|
|
|
|
// directly instead; also there's no point in collecting any "targets" for
|
|
|
|
// super constructor calls, since these are known when we optimize the
|
|
|
|
// constructor that contains the super call.
|
2015-02-11 09:47:32 +00:00
|
|
|
SUPER_CONSTRUCTOR_CALL = 1 << 1,
|
|
|
|
SUPER_CALL_RECORD_TARGET = SUPER_CONSTRUCTOR_CALL | RECORD_CONSTRUCTOR_TARGET
|
2014-05-26 11:28:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-07-18 13:50:21 +00:00
|
|
|
enum CacheHolderFlag {
|
|
|
|
kCacheOnPrototype,
|
|
|
|
kCacheOnPrototypeReceiverIsDictionary,
|
|
|
|
kCacheOnPrototypeReceiverIsPrimitive,
|
|
|
|
kCacheOnReceiver
|
2014-05-26 11:28:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// The Store Buffer (GC).
|
|
|
|
typedef enum {
|
|
|
|
kStoreBufferFullEvent,
|
|
|
|
kStoreBufferStartScanningPagesEvent,
|
|
|
|
kStoreBufferScanningPageEvent
|
|
|
|
} StoreBufferEvent;
|
|
|
|
|
|
|
|
|
|
|
|
typedef void (*StoreBufferCallback)(Heap* heap,
|
|
|
|
MemoryChunk* page,
|
|
|
|
StoreBufferEvent event);
|
|
|
|
|
|
|
|
|
|
|
|
// Union used for fast testing of specific double values.
|
|
|
|
union DoubleRepresentation {
|
|
|
|
double value;
|
|
|
|
int64_t bits;
|
|
|
|
DoubleRepresentation(double x) { value = x; }
|
|
|
|
bool operator==(const DoubleRepresentation& other) const {
|
|
|
|
return bits == other.bits;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 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) \
|
|
|
|
((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag)
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
|
2015-05-07 05:44:47 +00:00
|
|
|
// DOUBLE_POINTER_ALIGN returns the value algined for double pointers.
|
|
|
|
#define DOUBLE_POINTER_ALIGN(value) \
|
|
|
|
(((value) + kDoubleAlignmentMask) & ~kDoubleAlignmentMask)
|
|
|
|
|
2014-05-26 11:28:08 +00:00
|
|
|
|
|
|
|
// CPU feature flags.
|
|
|
|
enum CpuFeature {
|
2014-10-28 15:22:22 +00:00
|
|
|
// x86
|
|
|
|
SSE4_1,
|
|
|
|
SSE3,
|
|
|
|
SAHF,
|
2014-11-26 05:31:41 +00:00
|
|
|
AVX,
|
|
|
|
FMA3,
|
2015-04-08 07:15:51 +00:00
|
|
|
BMI1,
|
|
|
|
BMI2,
|
|
|
|
LZCNT,
|
|
|
|
POPCNT,
|
2015-01-20 14:59:47 +00:00
|
|
|
ATOM,
|
2014-10-28 15:22:22 +00:00
|
|
|
// ARM
|
|
|
|
VFP3,
|
|
|
|
ARMv7,
|
|
|
|
ARMv8,
|
|
|
|
SUDIV,
|
|
|
|
MLS,
|
|
|
|
UNALIGNED_ACCESSES,
|
|
|
|
MOVW_MOVT_IMMEDIATE_LOADS,
|
|
|
|
VFP32DREGS,
|
|
|
|
NEON,
|
|
|
|
// MIPS, MIPS64
|
|
|
|
FPU,
|
|
|
|
FP64FPU,
|
|
|
|
MIPSr1,
|
|
|
|
MIPSr2,
|
|
|
|
MIPSr6,
|
|
|
|
// ARM64
|
|
|
|
ALWAYS_ALIGN_CSP,
|
2014-12-19 11:16:23 +00:00
|
|
|
COHERENT_CACHE,
|
2015-01-16 07:42:00 +00:00
|
|
|
// PPC
|
|
|
|
FPR_GPR_MOV,
|
|
|
|
LWSYNC,
|
|
|
|
ISELECT,
|
2014-10-28 15:22:22 +00:00
|
|
|
NUMBER_OF_CPU_FEATURES
|
2014-05-26 11:28:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Used to specify if a macro instruction must perform a smi check on tagged
|
|
|
|
// values.
|
|
|
|
enum SmiCheckType {
|
|
|
|
DONT_DO_SMI_CHECK,
|
|
|
|
DO_SMI_CHECK
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
enum ScopeType {
|
|
|
|
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
|
2014-11-12 11:34:09 +00:00
|
|
|
SCRIPT_SCOPE, // The top-level scope for a script or a top-level eval.
|
2014-05-26 11:28:08 +00:00
|
|
|
CATCH_SCOPE, // The scope introduced by catch.
|
|
|
|
BLOCK_SCOPE, // The scope introduced by a new block.
|
2014-10-16 13:19:36 +00:00
|
|
|
WITH_SCOPE, // The scope introduced by with.
|
|
|
|
ARROW_SCOPE // The top-level scope for an arrow function literal.
|
2014-05-26 11:28:08 +00:00
|
|
|
};
|
|
|
|
|
2015-02-20 19:09:18 +00:00
|
|
|
// The mips architecture prior to revision 5 has inverted encoding for sNaN.
|
|
|
|
#if (V8_TARGET_ARCH_MIPS && !defined(_MIPS_ARCH_MIPS32R6)) || \
|
|
|
|
(V8_TARGET_ARCH_MIPS64 && !defined(_MIPS_ARCH_MIPS64R6))
|
|
|
|
const uint32_t kHoleNanUpper32 = 0xFFFF7FFF;
|
|
|
|
const uint32_t kHoleNanLower32 = 0xFFFF7FFF;
|
|
|
|
#else
|
2015-01-21 08:52:00 +00:00
|
|
|
const uint32_t kHoleNanUpper32 = 0xFFF7FFFF;
|
|
|
|
const uint32_t kHoleNanLower32 = 0xFFF7FFFF;
|
2015-02-20 19:09:18 +00:00
|
|
|
#endif
|
2014-05-26 11:28:08 +00:00
|
|
|
|
|
|
|
const uint64_t kHoleNanInt64 =
|
|
|
|
(static_cast<uint64_t>(kHoleNanUpper32) << 32) | kHoleNanLower32;
|
|
|
|
|
|
|
|
|
2015-09-29 07:41:03 +00:00
|
|
|
// ES6 section 20.1.2.6 Number.MAX_SAFE_INTEGER
|
|
|
|
const double kMaxSafeInteger = 9007199254740991.0; // 2^53-1
|
|
|
|
|
|
|
|
|
2014-05-26 11:28:08 +00:00
|
|
|
// The order of this enum has to be kept in sync with the predicates below.
|
|
|
|
enum VariableMode {
|
|
|
|
// User declared variables:
|
|
|
|
VAR, // declared via 'var', and 'function' declarations
|
|
|
|
|
|
|
|
CONST_LEGACY, // declared via legacy 'const' declarations
|
|
|
|
|
2015-02-26 18:40:50 +00:00
|
|
|
LET, // declared via 'let' declarations (first lexical)
|
2014-05-26 11:28:08 +00:00
|
|
|
|
|
|
|
CONST, // declared via 'const' declarations
|
|
|
|
|
2015-02-26 18:40:50 +00:00
|
|
|
IMPORT, // declared via 'import' declarations (last lexical)
|
|
|
|
|
2014-05-26 11:28:08 +00:00
|
|
|
// Variables introduced by the compiler:
|
|
|
|
TEMPORARY, // temporary variables (not user-visible), stack-allocated
|
|
|
|
// unless the scope as a whole has forced context allocation
|
|
|
|
|
|
|
|
DYNAMIC, // always require dynamic lookup (we don't know
|
|
|
|
// the declaration)
|
|
|
|
|
|
|
|
DYNAMIC_GLOBAL, // requires dynamic lookup, but we know that the
|
|
|
|
// variable is global unless it has been shadowed
|
|
|
|
// by an eval-introduced variable
|
|
|
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
inline bool IsDynamicVariableMode(VariableMode mode) {
|
|
|
|
return mode >= DYNAMIC && mode <= DYNAMIC_LOCAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline bool IsDeclaredVariableMode(VariableMode mode) {
|
2015-02-26 18:40:50 +00:00
|
|
|
return mode >= VAR && mode <= IMPORT;
|
2014-05-26 11:28:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline bool IsLexicalVariableMode(VariableMode mode) {
|
2015-02-26 18:40:50 +00:00
|
|
|
return mode >= LET && mode <= IMPORT;
|
2014-05-26 11:28:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline bool IsImmutableVariableMode(VariableMode mode) {
|
2015-02-26 18:40:50 +00:00
|
|
|
return mode == CONST || mode == CONST_LEGACY || mode == IMPORT;
|
2014-05-26 11:28:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-06 16:36:28 +00:00
|
|
|
enum class VariableLocation {
|
|
|
|
// 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,
|
|
|
|
|
|
|
|
// An indexed slot in a script context that contains a respective global
|
|
|
|
// property cell. name() is the variable name, index() is the variable
|
|
|
|
// index in the context object on the heap, starting at 0. scope() is the
|
|
|
|
// corresponding script scope.
|
|
|
|
GLOBAL,
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
LOOKUP
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-05-26 11:28:08 +00:00
|
|
|
// ES6 Draft Rev3 10.2 specifies declarative environment records with mutable
|
|
|
|
// and immutable bindings that can be in two states: initialized and
|
|
|
|
// uninitialized. In ES5 only immutable bindings have these two states. 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:
|
|
|
|
// 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) {}
|
|
|
|
// 6. Function variables of named function expressions.
|
|
|
|
// var x = function foo() {}
|
|
|
|
// 7. Implicit binding of 'this'.
|
|
|
|
// 8. Implicit binding of 'arguments' in functions.
|
|
|
|
//
|
|
|
|
// ES5 specified object environment records which are introduced by ES elements
|
|
|
|
// such as Program and WithStatement that associate identifier bindings with the
|
|
|
|
// properties of some object. In the specification only mutable bindings exist
|
|
|
|
// (which may be non-writable) and have no distinct initialization step. However
|
|
|
|
// V8 allows const declarations in global code with distinct creation and
|
|
|
|
// initialization steps which are represented by non-writable properties in the
|
|
|
|
// global object. As a result also these bindings need to be checked for
|
|
|
|
// initialization.
|
|
|
|
//
|
|
|
|
// 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).
|
|
|
|
enum InitializationFlag {
|
|
|
|
kNeedsInitialization,
|
|
|
|
kCreatedInitialized
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
enum MaybeAssignedFlag { kNotAssigned, kMaybeAssigned };
|
|
|
|
|
|
|
|
|
2015-02-20 21:19:43 +00:00
|
|
|
// Serialized in PreparseData, so numeric values should not be changed.
|
|
|
|
enum ParseErrorType { kSyntaxError = 0, kReferenceError = 1 };
|
|
|
|
|
|
|
|
|
2014-05-26 11:28:08 +00:00
|
|
|
enum ClearExceptionFlag {
|
|
|
|
KEEP_EXCEPTION,
|
|
|
|
CLEAR_EXCEPTION
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
enum MinusZeroMode {
|
|
|
|
TREAT_MINUS_ZERO_AS_ZERO,
|
|
|
|
FAIL_ON_MINUS_ZERO
|
|
|
|
};
|
|
|
|
|
2014-09-10 16:39:42 +00:00
|
|
|
|
2014-09-24 08:49:32 +00:00
|
|
|
enum Signedness { kSigned, kUnsigned };
|
|
|
|
|
|
|
|
|
2014-09-10 16:39:42 +00:00
|
|
|
enum FunctionKind {
|
|
|
|
kNormalFunction = 0,
|
2015-02-05 23:34:16 +00:00
|
|
|
kArrowFunction = 1 << 0,
|
|
|
|
kGeneratorFunction = 1 << 1,
|
|
|
|
kConciseMethod = 1 << 2,
|
2014-11-07 16:39:00 +00:00
|
|
|
kConciseGeneratorMethod = kGeneratorFunction | kConciseMethod,
|
2015-02-05 23:34:16 +00:00
|
|
|
kAccessorFunction = 1 << 3,
|
|
|
|
kDefaultConstructor = 1 << 4,
|
2015-02-06 10:34:50 +00:00
|
|
|
kSubclassConstructor = 1 << 5,
|
2015-02-11 17:22:50 +00:00
|
|
|
kBaseConstructor = 1 << 6,
|
2015-03-10 16:47:50 +00:00
|
|
|
kInObjectLiteral = 1 << 7,
|
2015-02-11 17:22:50 +00:00
|
|
|
kDefaultBaseConstructor = kDefaultConstructor | kBaseConstructor,
|
2015-03-10 16:47:50 +00:00
|
|
|
kDefaultSubclassConstructor = kDefaultConstructor | kSubclassConstructor,
|
|
|
|
kConciseMethodInObjectLiteral = kConciseMethod | kInObjectLiteral,
|
|
|
|
kConciseGeneratorMethodInObjectLiteral =
|
|
|
|
kConciseGeneratorMethod | kInObjectLiteral,
|
|
|
|
kAccessorFunctionInObjectLiteral = kAccessorFunction | kInObjectLiteral,
|
2014-09-10 16:39:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
inline bool IsValidFunctionKind(FunctionKind kind) {
|
|
|
|
return kind == FunctionKind::kNormalFunction ||
|
|
|
|
kind == FunctionKind::kArrowFunction ||
|
|
|
|
kind == FunctionKind::kGeneratorFunction ||
|
2014-09-18 17:14:13 +00:00
|
|
|
kind == FunctionKind::kConciseMethod ||
|
2014-11-07 16:39:00 +00:00
|
|
|
kind == FunctionKind::kConciseGeneratorMethod ||
|
2015-02-05 23:34:16 +00:00
|
|
|
kind == FunctionKind::kAccessorFunction ||
|
2015-02-11 17:22:50 +00:00
|
|
|
kind == FunctionKind::kDefaultBaseConstructor ||
|
|
|
|
kind == FunctionKind::kDefaultSubclassConstructor ||
|
2015-02-06 10:34:50 +00:00
|
|
|
kind == FunctionKind::kBaseConstructor ||
|
2015-03-10 16:47:50 +00:00
|
|
|
kind == FunctionKind::kSubclassConstructor ||
|
|
|
|
kind == FunctionKind::kConciseMethodInObjectLiteral ||
|
|
|
|
kind == FunctionKind::kConciseGeneratorMethodInObjectLiteral ||
|
|
|
|
kind == FunctionKind::kAccessorFunctionInObjectLiteral;
|
2014-09-10 16:39:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline bool IsArrowFunction(FunctionKind kind) {
|
|
|
|
DCHECK(IsValidFunctionKind(kind));
|
|
|
|
return kind & FunctionKind::kArrowFunction;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline bool IsGeneratorFunction(FunctionKind kind) {
|
|
|
|
DCHECK(IsValidFunctionKind(kind));
|
|
|
|
return kind & FunctionKind::kGeneratorFunction;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline bool IsConciseMethod(FunctionKind kind) {
|
|
|
|
DCHECK(IsValidFunctionKind(kind));
|
|
|
|
return kind & FunctionKind::kConciseMethod;
|
|
|
|
}
|
2014-11-07 16:39:00 +00:00
|
|
|
|
|
|
|
|
2015-02-05 23:34:16 +00:00
|
|
|
inline bool IsAccessorFunction(FunctionKind kind) {
|
|
|
|
DCHECK(IsValidFunctionKind(kind));
|
|
|
|
return kind & FunctionKind::kAccessorFunction;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-07 16:39:00 +00:00
|
|
|
inline bool IsDefaultConstructor(FunctionKind kind) {
|
|
|
|
DCHECK(IsValidFunctionKind(kind));
|
|
|
|
return kind & FunctionKind::kDefaultConstructor;
|
|
|
|
}
|
|
|
|
|
2015-02-05 23:34:16 +00:00
|
|
|
|
2015-02-06 10:34:50 +00:00
|
|
|
inline bool IsBaseConstructor(FunctionKind kind) {
|
|
|
|
DCHECK(IsValidFunctionKind(kind));
|
|
|
|
return kind & FunctionKind::kBaseConstructor;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-03 17:42:41 +00:00
|
|
|
inline bool IsSubclassConstructor(FunctionKind kind) {
|
|
|
|
DCHECK(IsValidFunctionKind(kind));
|
|
|
|
return kind & FunctionKind::kSubclassConstructor;
|
|
|
|
}
|
2015-02-06 10:34:50 +00:00
|
|
|
|
|
|
|
|
2015-09-24 06:50:01 +00:00
|
|
|
inline bool IsClassConstructor(FunctionKind kind) {
|
2015-02-06 10:34:50 +00:00
|
|
|
DCHECK(IsValidFunctionKind(kind));
|
|
|
|
return kind &
|
|
|
|
(FunctionKind::kBaseConstructor | FunctionKind::kSubclassConstructor |
|
|
|
|
FunctionKind::kDefaultConstructor);
|
|
|
|
}
|
2015-03-10 16:47:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
inline bool IsInObjectLiteral(FunctionKind kind) {
|
|
|
|
DCHECK(IsValidFunctionKind(kind));
|
|
|
|
return kind & FunctionKind::kInObjectLiteral;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline FunctionKind WithObjectLiteralBit(FunctionKind kind) {
|
|
|
|
kind = static_cast<FunctionKind>(kind | FunctionKind::kInObjectLiteral);
|
|
|
|
DCHECK(IsValidFunctionKind(kind));
|
|
|
|
return kind;
|
|
|
|
}
|
2015-09-30 13:46:56 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-05-26 11:28:08 +00:00
|
|
|
namespace i = v8::internal;
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
#endif // V8_GLOBALS_H_
|