v8  3.25.30(node0.11.13)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
globals.h
Go to the documentation of this file.
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 #ifndef V8_GLOBALS_H_
29 #define V8_GLOBALS_H_
30 
31 #include "../include/v8stdint.h"
32 
33 // Unfortunately, the INFINITY macro cannot be used with the '-pedantic'
34 // warning flag and certain versions of GCC due to a bug:
35 // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11931
36 // For now, we use the more involved template-based version from <limits>, but
37 // only when compiling with GCC versions affected by the bug (2.96.x - 4.0.x)
38 #if V8_CC_GNU && V8_GNUC_PREREQ(2, 96, 0) && !V8_GNUC_PREREQ(4, 1, 0)
39 # include <limits> // NOLINT
40 # define V8_INFINITY std::numeric_limits<double>::infinity()
41 #elif V8_LIBC_MSVCRT
42 # define V8_INFINITY HUGE_VAL
43 #else
44 # define V8_INFINITY INFINITY
45 #endif
46 
47 namespace v8 {
48 namespace internal {
49 
50 // Processor architecture detection. For more info on what's defined, see:
51 // http://msdn.microsoft.com/en-us/library/b0084kay.aspx
52 // http://www.agner.org/optimize/calling_conventions.pdf
53 // or with gcc, run: "echo | gcc -E -dM -"
54 #if defined(_M_X64) || defined(__x86_64__)
55 #if defined(__native_client__)
56 // For Native Client builds of V8, use V8_TARGET_ARCH_ARM, so that V8
57 // generates ARM machine code, together with a portable ARM simulator
58 // compiled for the host architecture in question.
59 //
60 // Since Native Client is ILP-32 on all architectures we use
61 // V8_HOST_ARCH_IA32 on both 32- and 64-bit x86.
62 #define V8_HOST_ARCH_IA32 1
63 #define V8_HOST_ARCH_32_BIT 1
64 #define V8_HOST_CAN_READ_UNALIGNED 1
65 #else
66 #define V8_HOST_ARCH_X64 1
67 #define V8_HOST_ARCH_64_BIT 1
68 #define V8_HOST_CAN_READ_UNALIGNED 1
69 #endif // __native_client__
70 #elif defined(_M_IX86) || defined(__i386__)
71 #define V8_HOST_ARCH_IA32 1
72 #define V8_HOST_ARCH_32_BIT 1
73 #define V8_HOST_CAN_READ_UNALIGNED 1
74 #elif defined(__AARCH64EL__)
75 #define V8_HOST_ARCH_ARM64 1
76 #define V8_HOST_ARCH_64_BIT 1
77 #define V8_HOST_CAN_READ_UNALIGNED 1
78 #elif defined(__ARMEL__)
79 #define V8_HOST_ARCH_ARM 1
80 #define V8_HOST_ARCH_32_BIT 1
81 #elif defined(__MIPSEL__)
82 #define V8_HOST_ARCH_MIPS 1
83 #define V8_HOST_ARCH_32_BIT 1
84 #else
85 #error "Host architecture was not detected as supported by v8"
86 #endif
87 
88 #if defined(__ARM_ARCH_7A__) || \
89  defined(__ARM_ARCH_7R__) || \
90  defined(__ARM_ARCH_7__)
91 # define CAN_USE_ARMV7_INSTRUCTIONS 1
92 # ifndef CAN_USE_VFP3_INSTRUCTIONS
93 # define CAN_USE_VFP3_INSTRUCTIONS
94 # endif
95 #endif
96 
97 
98 // Target architecture detection. This may be set externally. If not, detect
99 // in the same way as the host architecture, that is, target the native
100 // environment as presented by the compiler.
101 #if !V8_TARGET_ARCH_X64 && !V8_TARGET_ARCH_IA32 && \
102  !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_ARM64 && !V8_TARGET_ARCH_MIPS
103 #if defined(_M_X64) || defined(__x86_64__)
104 #define V8_TARGET_ARCH_X64 1
105 #elif defined(_M_IX86) || defined(__i386__)
106 #define V8_TARGET_ARCH_IA32 1
107 #elif defined(__AARCH64EL__)
108 #define V8_TARGET_ARCH_ARM64 1
109 #elif defined(__ARMEL__)
110 #define V8_TARGET_ARCH_ARM 1
111 #elif defined(__MIPSEL__)
112 #define V8_TARGET_ARCH_MIPS 1
113 #else
114 #error Target architecture was not detected as supported by v8
115 #endif
116 #endif
117 
118 // Check for supported combinations of host and target architectures.
119 #if V8_TARGET_ARCH_IA32 && !V8_HOST_ARCH_IA32
120 #error Target architecture ia32 is only supported on ia32 host
121 #endif
122 #if V8_TARGET_ARCH_X64 && !V8_HOST_ARCH_X64
123 #error Target architecture x64 is only supported on x64 host
124 #endif
125 #if (V8_TARGET_ARCH_ARM && !(V8_HOST_ARCH_IA32 || V8_HOST_ARCH_ARM))
126 #error Target architecture arm is only supported on arm and ia32 host
127 #endif
128 #if (V8_TARGET_ARCH_ARM64 && !(V8_HOST_ARCH_X64 || V8_HOST_ARCH_ARM64))
129 #error Target architecture arm64 is only supported on arm64 and x64 host
130 #endif
131 #if (V8_TARGET_ARCH_MIPS && !(V8_HOST_ARCH_IA32 || V8_HOST_ARCH_MIPS))
132 #error Target architecture mips is only supported on mips and ia32 host
133 #endif
134 
135 // Determine whether we are running in a simulated environment.
136 // Setting USE_SIMULATOR explicitly from the build script will force
137 // the use of a simulated environment.
138 #if !defined(USE_SIMULATOR)
139 #if (V8_TARGET_ARCH_ARM64 && !V8_HOST_ARCH_ARM64)
140 #define USE_SIMULATOR 1
141 #endif
142 #if (V8_TARGET_ARCH_ARM && !V8_HOST_ARCH_ARM)
143 #define USE_SIMULATOR 1
144 #endif
145 #if (V8_TARGET_ARCH_MIPS && !V8_HOST_ARCH_MIPS)
146 #define USE_SIMULATOR 1
147 #endif
148 #endif
149 
150 // Determine architecture endiannes (we only support little-endian).
151 #if V8_TARGET_ARCH_IA32
152 #define V8_TARGET_LITTLE_ENDIAN 1
153 #elif V8_TARGET_ARCH_X64
154 #define V8_TARGET_LITTLE_ENDIAN 1
155 #elif V8_TARGET_ARCH_ARM
156 #define V8_TARGET_LITTLE_ENDIAN 1
157 #elif V8_TARGET_ARCH_ARM64
158 #define V8_TARGET_LITTLE_ENDIAN 1
159 #elif V8_TARGET_ARCH_MIPS
160 #define V8_TARGET_LITTLE_ENDIAN 1
161 #else
162 #error Unknown target architecture endiannes
163 #endif
164 
165 // Determine whether the architecture uses an out-of-line constant pool.
166 #define V8_OOL_CONSTANT_POOL 0
167 
168 // Support for alternative bool type. This is only enabled if the code is
169 // compiled with USE_MYBOOL defined. This catches some nasty type bugs.
170 // For instance, 'bool b = "false";' results in b == true! This is a hidden
171 // source of bugs.
172 // However, redefining the bool type does have some negative impact on some
173 // platforms. It gives rise to compiler warnings (i.e. with
174 // MSVC) in the API header files when mixing code that uses the standard
175 // bool with code that uses the redefined version.
176 // This does not actually belong in the platform code, but needs to be
177 // defined here because the platform code uses bool, and platform.h is
178 // include very early in the main include file.
179 
180 #ifdef USE_MYBOOL
181 typedef unsigned int __my_bool__;
182 #define bool __my_bool__ // use 'indirection' to avoid name clashes
183 #endif
184 
185 typedef uint8_t byte;
186 typedef byte* Address;
187 
188 // Define our own macros for writing 64-bit constants. This is less fragile
189 // than defining __STDC_CONSTANT_MACROS before including <stdint.h>, and it
190 // works on compilers that don't have it (like MSVC).
191 #if V8_CC_MSVC
192 # define V8_UINT64_C(x) (x ## UI64)
193 # define V8_INT64_C(x) (x ## I64)
194 # if V8_HOST_ARCH_64_BIT
195 # define V8_INTPTR_C(x) (x ## I64)
196 # define V8_PTR_PREFIX "ll"
197 # else
198 # define V8_INTPTR_C(x) (x)
199 # define V8_PTR_PREFIX ""
200 # endif // V8_HOST_ARCH_64_BIT
201 #elif V8_CC_MINGW64
202 # define V8_UINT64_C(x) (x ## ULL)
203 # define V8_INT64_C(x) (x ## LL)
204 # define V8_INTPTR_C(x) (x ## LL)
205 # define V8_PTR_PREFIX "I64"
206 #elif V8_HOST_ARCH_64_BIT
207 # if V8_OS_MACOSX
208 # define V8_UINT64_C(x) (x ## ULL)
209 # define V8_INT64_C(x) (x ## LL)
210 # else
211 # define V8_UINT64_C(x) (x ## UL)
212 # define V8_INT64_C(x) (x ## L)
213 # endif
214 # define V8_INTPTR_C(x) (x ## L)
215 # define V8_PTR_PREFIX "l"
216 #else
217 # define V8_UINT64_C(x) (x ## ULL)
218 # define V8_INT64_C(x) (x ## LL)
219 # define V8_INTPTR_C(x) (x)
220 # define V8_PTR_PREFIX ""
221 #endif
222 
223 // The following macro works on both 32 and 64-bit platforms.
224 // Usage: instead of writing 0x1234567890123456
225 // write V8_2PART_UINT64_C(0x12345678,90123456);
226 #define V8_2PART_UINT64_C(a, b) (((static_cast<uint64_t>(a) << 32) + 0x##b##u))
227 
228 #define V8PRIxPTR V8_PTR_PREFIX "x"
229 #define V8PRIdPTR V8_PTR_PREFIX "d"
230 #define V8PRIuPTR V8_PTR_PREFIX "u"
231 
232 // Fix for Mac OS X defining uintptr_t as "unsigned long":
233 #if V8_OS_MACOSX
234 #undef V8PRIxPTR
235 #define V8PRIxPTR "lx"
236 #endif
237 
238 #if V8_OS_MACOSX || defined(__FreeBSD__) || defined(__OpenBSD__)
239 #define USING_BSD_ABI
240 #endif
241 
242 // -----------------------------------------------------------------------------
243 // Constants
244 
245 const int KB = 1024;
246 const int MB = KB * KB;
247 const int GB = KB * KB * KB;
248 const int kMaxInt = 0x7FFFFFFF;
249 const int kMinInt = -kMaxInt - 1;
250 const int kMaxInt8 = (1 << 7) - 1;
251 const int kMinInt8 = -(1 << 7);
252 const int kMaxUInt8 = (1 << 8) - 1;
253 const int kMinUInt8 = 0;
254 const int kMaxInt16 = (1 << 15) - 1;
255 const int kMinInt16 = -(1 << 15);
256 const int kMaxUInt16 = (1 << 16) - 1;
257 const int kMinUInt16 = 0;
258 
259 const uint32_t kMaxUInt32 = 0xFFFFFFFFu;
260 
261 const int kCharSize = sizeof(char); // NOLINT
262 const int kShortSize = sizeof(short); // NOLINT
263 const int kIntSize = sizeof(int); // NOLINT
264 const int kInt32Size = sizeof(int32_t); // NOLINT
265 const int kInt64Size = sizeof(int64_t); // NOLINT
266 const int kDoubleSize = sizeof(double); // NOLINT
267 const int kIntptrSize = sizeof(intptr_t); // NOLINT
268 const int kPointerSize = sizeof(void*); // NOLINT
272 
273 const int kDoubleSizeLog2 = 3;
274 
275 #if V8_HOST_ARCH_64_BIT
276 const int kPointerSizeLog2 = 3;
277 const intptr_t kIntptrSignBit = V8_INT64_C(0x8000000000000000);
278 const uintptr_t kUintptrAllBitsSet = V8_UINT64_C(0xFFFFFFFFFFFFFFFF);
279 const bool kIs64BitArch = true;
280 #else
281 const int kPointerSizeLog2 = 2;
282 const intptr_t kIntptrSignBit = 0x80000000;
283 const uintptr_t kUintptrAllBitsSet = 0xFFFFFFFFu;
284 const bool kIs64BitArch = false;
285 #endif
286 
287 const int kBitsPerByte = 8;
288 const int kBitsPerByteLog2 = 3;
291 
292 // IEEE 754 single precision floating point number bit layout.
293 const uint32_t kBinary32SignMask = 0x80000000u;
294 const uint32_t kBinary32ExponentMask = 0x7f800000u;
295 const uint32_t kBinary32MantissaMask = 0x007fffffu;
296 const int kBinary32ExponentBias = 127;
297 const int kBinary32MaxExponent = 0xFE;
298 const int kBinary32MinExponent = 0x01;
299 const int kBinary32MantissaBits = 23;
300 const int kBinary32ExponentShift = 23;
301 
302 // Quiet NaNs have bits 51 to 62 set, possibly the sign bit, and no
303 // other bits set.
304 const uint64_t kQuietNaNMask = static_cast<uint64_t>(0xfff) << 51;
305 
306 // Latin1/UTF-16 constants
307 // Code-point values in Unicode 4.0 are 21 bits wide.
308 // Code units in UTF-16 are 16 bits wide.
309 typedef uint16_t uc16;
310 typedef int32_t uc32;
312 const int kUC16Size = sizeof(uc16); // NOLINT
313 
314 
315 // Round up n to be a multiple of sz, where sz is a power of 2.
316 #define ROUND_UP(n, sz) (((n) + ((sz) - 1)) & ~((sz) - 1))
317 
318 
319 // The expression OFFSET_OF(type, field) computes the byte-offset
320 // of the specified field relative to the containing type. This
321 // corresponds to 'offsetof' (in stddef.h), except that it doesn't
322 // use 0 or NULL, which causes a problem with the compiler warnings
323 // we have enabled (which is also why 'offsetof' doesn't seem to work).
324 // Here we simply use the non-zero value 4, which seems to work.
325 #define OFFSET_OF(type, field) \
326  (reinterpret_cast<intptr_t>(&(reinterpret_cast<type*>(4)->field)) - 4)
327 
328 
329 // The expression ARRAY_SIZE(a) is a compile-time constant of type
330 // size_t which represents the number of elements of the given
331 // array. You should only use ARRAY_SIZE on statically allocated
332 // arrays.
333 #define ARRAY_SIZE(a) \
334  ((sizeof(a) / sizeof(*(a))) / \
335  static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
336 
337 
338 // The USE(x) template is used to silence C++ compiler warnings
339 // issued for (yet) unused variables (typically parameters).
340 template <typename T>
341 inline void USE(T) { }
342 
343 
344 // FUNCTION_ADDR(f) gets the address of a C function f.
345 #define FUNCTION_ADDR(f) \
346  (reinterpret_cast<v8::internal::Address>(reinterpret_cast<intptr_t>(f)))
347 
348 
349 // FUNCTION_CAST<F>(addr) casts an address into a function
350 // of type F. Used to invoke generated code from within C.
351 template <typename F>
353  return reinterpret_cast<F>(reinterpret_cast<intptr_t>(addr));
354 }
355 
356 
357 // A macro to disallow the evil copy constructor and operator= functions
358 // This should be used in the private: declarations for a class
359 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
360  TypeName(const TypeName&) V8_DELETE; \
361  void operator=(const TypeName&) V8_DELETE
362 
363 
364 // A macro to disallow all the implicit constructors, namely the
365 // default constructor, copy constructor and operator= functions.
366 //
367 // This should be used in the private: declarations for a class
368 // that wants to prevent anyone from instantiating it. This is
369 // especially useful for classes containing only static methods.
370 #define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \
371  TypeName() V8_DELETE; \
372  DISALLOW_COPY_AND_ASSIGN(TypeName)
373 
374 
375 // Newly written code should use V8_INLINE and V8_NOINLINE directly.
376 #define INLINE(declarator) V8_INLINE declarator
377 #define NO_INLINE(declarator) V8_NOINLINE declarator
378 
379 
380 // Newly written code should use V8_WARN_UNUSED_RESULT.
381 #define MUST_USE_RESULT V8_WARN_UNUSED_RESULT
382 
383 
384 // Define DISABLE_ASAN macros.
385 #if defined(__has_feature)
386 #if __has_feature(address_sanitizer)
387 #define DISABLE_ASAN __attribute__((no_sanitize_address))
388 #endif
389 #endif
390 
391 
392 #ifndef DISABLE_ASAN
393 #define DISABLE_ASAN
394 #endif
395 
396 #if V8_CC_GNU
397 #define V8_IMMEDIATE_CRASH() __builtin_trap()
398 #else
399 #define V8_IMMEDIATE_CRASH() ((void(*)())0)()
400 #endif
401 
402 
403 // -----------------------------------------------------------------------------
404 // Forward declarations for frequently used classes
405 // (sorted alphabetically)
406 
407 class FreeStoreAllocationPolicy;
408 template <typename T, class P = FreeStoreAllocationPolicy> class List;
409 
410 // -----------------------------------------------------------------------------
411 // Declarations for use in both the preparser and the rest of V8.
412 
413 // The Strict Mode (ECMA-262 5th edition, 4.2.2).
414 
416 
417 
418 } } // namespace v8::internal
419 
420 #endif // V8_GLOBALS_H_
byte * Address
Definition: globals.h:186
const int kMinInt
Definition: globals.h:249
const int kBinary32ExponentShift
Definition: globals.h:300
const int kDoubleSizeLog2
Definition: globals.h:273
const uint32_t kBinary32MantissaMask
Definition: globals.h:295
const int kBinary32MaxExponent
Definition: globals.h:297
const int KB
Definition: globals.h:245
const int kMaxUInt16
Definition: globals.h:256
const intptr_t kIntptrSignBit
Definition: globals.h:282
const int kBitsPerPointer
Definition: globals.h:289
const int kMinInt8
Definition: globals.h:251
const uint64_t kQuietNaNMask
Definition: globals.h:304
const int kBinary32MantissaBits
Definition: globals.h:299
#define V8_UINT64_C(x)
Definition: globals.h:217
int32_t uc32
Definition: globals.h:310
int int32_t
Definition: unicode.cc:47
const int kMaxInt
Definition: globals.h:248
const int kBitsPerByteLog2
Definition: globals.h:288
const int kMinUInt16
Definition: globals.h:257
const int kPointerSizeLog2
Definition: globals.h:281
unsigned short uint16_t
Definition: unicode.cc:46
const bool kIs64BitArch
Definition: globals.h:284
const int kIntSize
Definition: globals.h:263
uint8_t byte
Definition: globals.h:185
const int kDoubleSize
Definition: globals.h:266
#define V8_INT64_C(x)
Definition: globals.h:218
const int kPointerSize
Definition: globals.h:268
const int kRegisterSize
Definition: globals.h:269
const uintptr_t kUintptrAllBitsSet
Definition: globals.h:283
const int kFPOnStackSize
Definition: globals.h:271
const int kBinary32MinExponent
Definition: globals.h:298
const int kBinary32ExponentBias
Definition: globals.h:296
const int kBitsPerByte
Definition: globals.h:287
const int kMinUInt8
Definition: globals.h:253
const int kBitsPerInt
Definition: globals.h:290
#define T(name, string, precedence)
Definition: token.cc:48
const int kMaxUInt8
Definition: globals.h:252
const int GB
Definition: globals.h:247
const int kMinInt16
Definition: globals.h:255
uint16_t uc16
Definition: globals.h:309
const int kInt64Size
Definition: globals.h:265
const int kShortSize
Definition: globals.h:262
void USE(T)
Definition: globals.h:341
const int kMaxInt16
Definition: globals.h:254
const uint32_t kBinary32ExponentMask
Definition: globals.h:294
const uint32_t kBinary32SignMask
Definition: globals.h:293
const uint32_t kMaxUInt32
Definition: globals.h:259
const int kOneByteSize
Definition: globals.h:311
const int kPCOnStackSize
Definition: globals.h:270
const int kInt32Size
Definition: globals.h:264
const int kMaxInt8
Definition: globals.h:250
const int kCharSize
Definition: globals.h:261
const int kIntptrSize
Definition: globals.h:267
const int kUC16Size
Definition: globals.h:312
F FUNCTION_CAST(Address addr)
Definition: globals.h:352
const int MB
Definition: globals.h:246