v8  3.14.5(node0.10.28)
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 // Define V8_INFINITY
32 #define V8_INFINITY INFINITY
33 
34 // GCC specific stuff
35 #ifdef __GNUC__
36 
37 #define __GNUC_VERSION_FOR_INFTY__ (__GNUC__ * 10000 + __GNUC_MINOR__ * 100)
38 
39 // Unfortunately, the INFINITY macro cannot be used with the '-pedantic'
40 // warning flag and certain versions of GCC due to a bug:
41 // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11931
42 // For now, we use the more involved template-based version from <limits>, but
43 // only when compiling with GCC versions affected by the bug (2.96.x - 4.0.x)
44 // __GNUC_PREREQ is not defined in GCC for Mac OS X, so we define our own macro
45 #if __GNUC_VERSION_FOR_INFTY__ >= 29600 && __GNUC_VERSION_FOR_INFTY__ < 40100
46 #include <limits>
47 #undef V8_INFINITY
48 #define V8_INFINITY std::numeric_limits<double>::infinity()
49 #endif
50 #undef __GNUC_VERSION_FOR_INFTY__
51 
52 #endif // __GNUC__
53 
54 #ifdef _MSC_VER
55 #undef V8_INFINITY
56 #define V8_INFINITY HUGE_VAL
57 #endif
58 
59 
60 #include "../include/v8stdint.h"
61 
62 namespace v8 {
63 namespace internal {
64 
65 // Processor architecture detection. For more info on what's defined, see:
66 // http://msdn.microsoft.com/en-us/library/b0084kay.aspx
67 // http://www.agner.org/optimize/calling_conventions.pdf
68 // or with gcc, run: "echo | gcc -E -dM -"
69 #if defined(_M_X64) || defined(__x86_64__)
70 #define V8_HOST_ARCH_X64 1
71 #define V8_HOST_ARCH_64_BIT 1
72 #define V8_HOST_CAN_READ_UNALIGNED 1
73 #elif defined(_M_IX86) || defined(__i386__)
74 #define V8_HOST_ARCH_IA32 1
75 #define V8_HOST_ARCH_32_BIT 1
76 #define V8_HOST_CAN_READ_UNALIGNED 1
77 #elif defined(__ARMEL__)
78 #define V8_HOST_ARCH_ARM 1
79 #define V8_HOST_ARCH_32_BIT 1
80 // Some CPU-OS combinations allow unaligned access on ARM. We assume
81 // that unaligned accesses are not allowed unless the build system
82 // defines the CAN_USE_UNALIGNED_ACCESSES macro to be non-zero.
83 #if CAN_USE_UNALIGNED_ACCESSES
84 #define V8_HOST_CAN_READ_UNALIGNED 1
85 #endif
86 #elif defined(__MIPSEL__)
87 #define V8_HOST_ARCH_MIPS 1
88 #define V8_HOST_ARCH_32_BIT 1
89 #else
90 #error Host architecture was not detected as supported by v8
91 #endif
92 
93 // Target architecture detection. This may be set externally. If not, detect
94 // in the same way as the host architecture, that is, target the native
95 // environment as presented by the compiler.
96 #if !defined(V8_TARGET_ARCH_X64) && !defined(V8_TARGET_ARCH_IA32) && \
97  !defined(V8_TARGET_ARCH_ARM) && !defined(V8_TARGET_ARCH_MIPS)
98 #if defined(_M_X64) || defined(__x86_64__)
99 #define V8_TARGET_ARCH_X64 1
100 #elif defined(_M_IX86) || defined(__i386__)
101 #define V8_TARGET_ARCH_IA32 1
102 #elif defined(__ARMEL__)
103 #define V8_TARGET_ARCH_ARM 1
104 #elif defined(__MIPSEL__)
105 #define V8_TARGET_ARCH_MIPS 1
106 #else
107 #error Target architecture was not detected as supported by v8
108 #endif
109 #endif
110 
111 // Check for supported combinations of host and target architectures.
112 #if defined(V8_TARGET_ARCH_IA32) && !defined(V8_HOST_ARCH_IA32)
113 #error Target architecture ia32 is only supported on ia32 host
114 #endif
115 #if defined(V8_TARGET_ARCH_X64) && !defined(V8_HOST_ARCH_X64)
116 #error Target architecture x64 is only supported on x64 host
117 #endif
118 #if (defined(V8_TARGET_ARCH_ARM) && \
119  !(defined(V8_HOST_ARCH_IA32) || defined(V8_HOST_ARCH_ARM)))
120 #error Target architecture arm is only supported on arm and ia32 host
121 #endif
122 #if (defined(V8_TARGET_ARCH_MIPS) && \
123  !(defined(V8_HOST_ARCH_IA32) || defined(V8_HOST_ARCH_MIPS)))
124 #error Target architecture mips is only supported on mips and ia32 host
125 #endif
126 
127 // Determine whether we are running in a simulated environment.
128 // Setting USE_SIMULATOR explicitly from the build script will force
129 // the use of a simulated environment.
130 #if !defined(USE_SIMULATOR)
131 #if (defined(V8_TARGET_ARCH_ARM) && !defined(V8_HOST_ARCH_ARM))
132 #define USE_SIMULATOR 1
133 #endif
134 #if (defined(V8_TARGET_ARCH_MIPS) && !defined(V8_HOST_ARCH_MIPS))
135 #define USE_SIMULATOR 1
136 #endif
137 #endif
138 
139 // Support for alternative bool type. This is only enabled if the code is
140 // compiled with USE_MYBOOL defined. This catches some nasty type bugs.
141 // For instance, 'bool b = "false";' results in b == true! This is a hidden
142 // source of bugs.
143 // However, redefining the bool type does have some negative impact on some
144 // platforms. It gives rise to compiler warnings (i.e. with
145 // MSVC) in the API header files when mixing code that uses the standard
146 // bool with code that uses the redefined version.
147 // This does not actually belong in the platform code, but needs to be
148 // defined here because the platform code uses bool, and platform.h is
149 // include very early in the main include file.
150 
151 #ifdef USE_MYBOOL
152 typedef unsigned int __my_bool__;
153 #define bool __my_bool__ // use 'indirection' to avoid name clashes
154 #endif
155 
156 typedef uint8_t byte;
157 typedef byte* Address;
158 
159 // Define our own macros for writing 64-bit constants. This is less fragile
160 // than defining __STDC_CONSTANT_MACROS before including <stdint.h>, and it
161 // works on compilers that don't have it (like MSVC).
162 #if V8_HOST_ARCH_64_BIT
163 #if defined(_MSC_VER)
164 #define V8_UINT64_C(x) (x ## UI64)
165 #define V8_INT64_C(x) (x ## I64)
166 #define V8_INTPTR_C(x) (x ## I64)
167 #define V8_PTR_PREFIX "ll"
168 #elif defined(__MINGW64__)
169 #define V8_UINT64_C(x) (x ## ULL)
170 #define V8_INT64_C(x) (x ## LL)
171 #define V8_INTPTR_C(x) (x ## LL)
172 #define V8_PTR_PREFIX "I64"
173 #else
174 #define V8_UINT64_C(x) (x ## UL)
175 #define V8_INT64_C(x) (x ## L)
176 #define V8_INTPTR_C(x) (x ## L)
177 #define V8_PTR_PREFIX "l"
178 #endif
179 #else // V8_HOST_ARCH_64_BIT
180 #define V8_INTPTR_C(x) (x)
181 #define V8_PTR_PREFIX ""
182 #endif // V8_HOST_ARCH_64_BIT
183 
184 // The following macro works on both 32 and 64-bit platforms.
185 // Usage: instead of writing 0x1234567890123456
186 // write V8_2PART_UINT64_C(0x12345678,90123456);
187 #define V8_2PART_UINT64_C(a, b) (((static_cast<uint64_t>(a) << 32) + 0x##b##u))
188 
189 #define V8PRIxPTR V8_PTR_PREFIX "x"
190 #define V8PRIdPTR V8_PTR_PREFIX "d"
191 #define V8PRIuPTR V8_PTR_PREFIX "u"
192 
193 // Fix for Mac OS X defining uintptr_t as "unsigned long":
194 #if defined(__APPLE__) && defined(__MACH__)
195 #undef V8PRIxPTR
196 #define V8PRIxPTR "lx"
197 #endif
198 
199 #if (defined(__APPLE__) && defined(__MACH__)) || \
200  defined(__FreeBSD__) || defined(__OpenBSD__)
201 #define USING_BSD_ABI
202 #endif
203 
204 // -----------------------------------------------------------------------------
205 // Constants
206 
207 const int KB = 1024;
208 const int MB = KB * KB;
209 const int GB = KB * KB * KB;
210 const int kMaxInt = 0x7FFFFFFF;
211 const int kMinInt = -kMaxInt - 1;
212 
213 const uint32_t kMaxUInt32 = 0xFFFFFFFFu;
214 
215 const int kCharSize = sizeof(char); // NOLINT
216 const int kShortSize = sizeof(short); // NOLINT
217 const int kIntSize = sizeof(int); // NOLINT
218 const int kDoubleSize = sizeof(double); // NOLINT
219 const int kIntptrSize = sizeof(intptr_t); // NOLINT
220 const int kPointerSize = sizeof(void*); // NOLINT
221 
222 const int kDoubleSizeLog2 = 3;
223 
224 // Size of the state of a the random number generator.
225 const int kRandomStateSize = 2 * kIntSize;
226 
227 #if V8_HOST_ARCH_64_BIT
228 const int kPointerSizeLog2 = 3;
229 const intptr_t kIntptrSignBit = V8_INT64_C(0x8000000000000000);
230 const uintptr_t kUintptrAllBitsSet = V8_UINT64_C(0xFFFFFFFFFFFFFFFF);
231 #else
232 const int kPointerSizeLog2 = 2;
233 const intptr_t kIntptrSignBit = 0x80000000;
234 const uintptr_t kUintptrAllBitsSet = 0xFFFFFFFFu;
235 #endif
236 
237 const int kBitsPerByte = 8;
238 const int kBitsPerByteLog2 = 3;
241 
242 // IEEE 754 single precision floating point number bit layout.
243 const uint32_t kBinary32SignMask = 0x80000000u;
244 const uint32_t kBinary32ExponentMask = 0x7f800000u;
245 const uint32_t kBinary32MantissaMask = 0x007fffffu;
246 const int kBinary32ExponentBias = 127;
247 const int kBinary32MaxExponent = 0xFE;
248 const int kBinary32MinExponent = 0x01;
249 const int kBinary32MantissaBits = 23;
250 const int kBinary32ExponentShift = 23;
251 
252 // Quiet NaNs have bits 51 to 62 set, possibly the sign bit, and no
253 // other bits set.
254 const uint64_t kQuietNaNMask = static_cast<uint64_t>(0xfff) << 51;
255 
256 // ASCII/UTF-16 constants
257 // Code-point values in Unicode 4.0 are 21 bits wide.
258 // Code units in UTF-16 are 16 bits wide.
259 typedef uint16_t uc16;
260 typedef int32_t uc32;
261 const int kASCIISize = kCharSize;
262 const int kUC16Size = sizeof(uc16); // NOLINT
263 const uc32 kMaxAsciiCharCode = 0x7f;
264 const uint32_t kMaxAsciiCharCodeU = 0x7fu;
265 
266 
267 // The expression OFFSET_OF(type, field) computes the byte-offset
268 // of the specified field relative to the containing type. This
269 // corresponds to 'offsetof' (in stddef.h), except that it doesn't
270 // use 0 or NULL, which causes a problem with the compiler warnings
271 // we have enabled (which is also why 'offsetof' doesn't seem to work).
272 // Here we simply use the non-zero value 4, which seems to work.
273 #define OFFSET_OF(type, field) \
274  (reinterpret_cast<intptr_t>(&(reinterpret_cast<type*>(4)->field)) - 4)
275 
276 
277 // The expression ARRAY_SIZE(a) is a compile-time constant of type
278 // size_t which represents the number of elements of the given
279 // array. You should only use ARRAY_SIZE on statically allocated
280 // arrays.
281 #define ARRAY_SIZE(a) \
282  ((sizeof(a) / sizeof(*(a))) / \
283  static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
284 
285 
286 // The USE(x) template is used to silence C++ compiler warnings
287 // issued for (yet) unused variables (typically parameters).
288 template <typename T>
289 inline void USE(T) { }
290 
291 
292 // FUNCTION_ADDR(f) gets the address of a C function f.
293 #define FUNCTION_ADDR(f) \
294  (reinterpret_cast<v8::internal::Address>(reinterpret_cast<intptr_t>(f)))
295 
296 
297 // FUNCTION_CAST<F>(addr) casts an address into a function
298 // of type F. Used to invoke generated code from within C.
299 template <typename F>
301  return reinterpret_cast<F>(reinterpret_cast<intptr_t>(addr));
302 }
303 
304 
305 // A macro to disallow the evil copy constructor and operator= functions
306 // This should be used in the private: declarations for a class
307 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
308  TypeName(const TypeName&); \
309  void operator=(const TypeName&)
310 
311 
312 // A macro to disallow all the implicit constructors, namely the
313 // default constructor, copy constructor and operator= functions.
314 //
315 // This should be used in the private: declarations for a class
316 // that wants to prevent anyone from instantiating it. This is
317 // especially useful for classes containing only static methods.
318 #define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \
319  TypeName(); \
320  DISALLOW_COPY_AND_ASSIGN(TypeName)
321 
322 
323 // Define used for helping GCC to make better inlining. Don't bother for debug
324 // builds. On GCC 3.4.5 using __attribute__((always_inline)) causes compilation
325 // errors in debug build.
326 #if defined(__GNUC__) && !defined(DEBUG)
327 #if (__GNUC__ >= 4)
328 #define INLINE(header) inline header __attribute__((always_inline))
329 #define NO_INLINE(header) header __attribute__((noinline))
330 #else
331 #define INLINE(header) inline __attribute__((always_inline)) header
332 #define NO_INLINE(header) __attribute__((noinline)) header
333 #endif
334 #elif defined(_MSC_VER) && !defined(DEBUG)
335 #define INLINE(header) __forceinline header
336 #define NO_INLINE(header) header
337 #else
338 #define INLINE(header) inline header
339 #define NO_INLINE(header) header
340 #endif
341 
342 
343 #if defined(__GNUC__) && __GNUC__ >= 4
344 #define MUST_USE_RESULT __attribute__ ((warn_unused_result))
345 #else
346 #define MUST_USE_RESULT
347 #endif
348 
349 
350 // Define DISABLE_ASAN macros.
351 #if defined(__has_feature)
352 #if __has_feature(address_sanitizer)
353 #define DISABLE_ASAN __attribute__((no_address_safety_analysis))
354 #endif
355 #endif
356 
357 
358 #ifndef DISABLE_ASAN
359 #define DISABLE_ASAN
360 #endif
361 
362 
363 // -----------------------------------------------------------------------------
364 // Forward declarations for frequently used classes
365 // (sorted alphabetically)
366 
367 class FreeStoreAllocationPolicy;
368 template <typename T, class P = FreeStoreAllocationPolicy> class List;
369 
370 // -----------------------------------------------------------------------------
371 // Declarations for use in both the preparser and the rest of V8.
372 
373 // The different language modes that V8 implements. ES5 defines two language
374 // modes: an unrestricted mode respectively a strict mode which are indicated by
375 // CLASSIC_MODE respectively STRICT_MODE in the enum. The harmony spec drafts
376 // for the next ES standard specify a new third mode which is called 'extended
377 // mode'. The extended mode is only available if the harmony flag is set. It is
378 // based on the 'strict mode' and adds new functionality to it. This means that
379 // most of the semantics of these two modes coincide.
380 //
381 // In the current draft the term 'base code' is used to refer to code that is
382 // neither in strict nor extended mode. However, the more distinguishing term
383 // 'classic mode' is used in V8 instead to avoid mix-ups.
384 
389 };
390 
391 
392 // The Strict Mode (ECMA-262 5th edition, 4.2.2).
393 //
394 // This flag is used in the backend to represent the language mode. So far
395 // there is no semantic difference between the strict and the extended mode in
396 // the backend, so both modes are represented by the kStrictMode value.
400 };
401 
402 
403 } } // namespace v8::internal
404 
405 #endif // V8_GLOBALS_H_
byte * Address
Definition: globals.h:157
const int kMinInt
Definition: globals.h:211
const int kBinary32ExponentShift
Definition: globals.h:250
const int kDoubleSizeLog2
Definition: globals.h:222
const uint32_t kBinary32MantissaMask
Definition: globals.h:245
const int kBinary32MaxExponent
Definition: globals.h:247
const int KB
Definition: globals.h:207
const intptr_t kIntptrSignBit
Definition: globals.h:233
const int kBitsPerPointer
Definition: globals.h:239
const uint64_t kQuietNaNMask
Definition: globals.h:254
const int kBinary32MantissaBits
Definition: globals.h:249
int32_t uc32
Definition: globals.h:260
const uint32_t kMaxAsciiCharCodeU
Definition: globals.h:264
int int32_t
Definition: unicode.cc:47
const int kMaxInt
Definition: globals.h:210
const int kBitsPerByteLog2
Definition: globals.h:238
const int kPointerSizeLog2
Definition: globals.h:232
unsigned short uint16_t
Definition: unicode.cc:46
const int kIntSize
Definition: globals.h:217
uint8_t byte
Definition: globals.h:156
const int kDoubleSize
Definition: globals.h:218
const int kPointerSize
Definition: globals.h:220
const uintptr_t kUintptrAllBitsSet
Definition: globals.h:234
const int kBinary32MinExponent
Definition: globals.h:248
const int kBinary32ExponentBias
Definition: globals.h:246
const int kBitsPerByte
Definition: globals.h:237
const int kBitsPerInt
Definition: globals.h:240
#define T(name, string, precedence)
Definition: token.cc:48
const int GB
Definition: globals.h:209
uint16_t uc16
Definition: globals.h:259
const int kASCIISize
Definition: globals.h:261
const int kRandomStateSize
Definition: globals.h:225
const int kShortSize
Definition: globals.h:216
void USE(T)
Definition: globals.h:289
const uint32_t kBinary32ExponentMask
Definition: globals.h:244
const uint32_t kBinary32SignMask
Definition: globals.h:243
const uint32_t kMaxUInt32
Definition: globals.h:213
const uc32 kMaxAsciiCharCode
Definition: globals.h:263
const int kCharSize
Definition: globals.h:215
const int kIntptrSize
Definition: globals.h:219
const int kUC16Size
Definition: globals.h:262
F FUNCTION_CAST(Address addr)
Definition: globals.h:300
const int MB
Definition: globals.h:208