blob: fbc749da854684718ee37a7bba875939cf462b86 [file] [log] [blame]
Steve Blocka7e24c12009-10-30 11:49:00 +00001// Copyright 2006-2009 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
31namespace v8 {
32namespace internal {
33
34// Processor architecture detection. For more info on what's defined, see:
35// http://msdn.microsoft.com/en-us/library/b0084kay.aspx
36// http://www.agner.org/optimize/calling_conventions.pdf
37// or with gcc, run: "echo | gcc -E -dM -"
38#if defined(_M_X64) || defined(__x86_64__)
39#define V8_HOST_ARCH_X64 1
40#define V8_HOST_ARCH_64_BIT 1
41#define V8_HOST_CAN_READ_UNALIGNED 1
42#elif defined(_M_IX86) || defined(__i386__)
43#define V8_HOST_ARCH_IA32 1
44#define V8_HOST_ARCH_32_BIT 1
45#define V8_HOST_CAN_READ_UNALIGNED 1
46#elif defined(__ARMEL__)
47#define V8_HOST_ARCH_ARM 1
48#define V8_HOST_ARCH_32_BIT 1
Kristian Monsen25f61362010-05-21 11:50:48 +010049// Some CPU-OS combinations allow unaligned access on ARM. We assume
50// that unaligned accesses are not allowed unless the build system
51// defines the CAN_USE_UNALIGNED_ACCESSES macro to be non-zero.
52#if CAN_USE_UNALIGNED_ACCESSES
53#define V8_HOST_CAN_READ_UNALIGNED 1
54#endif
Andrei Popescu31002712010-02-23 13:46:05 +000055#elif defined(_MIPS_ARCH_MIPS32R2)
56#define V8_HOST_ARCH_MIPS 1
57#define V8_HOST_ARCH_32_BIT 1
Steve Blocka7e24c12009-10-30 11:49:00 +000058#else
Steve Block6ded16b2010-05-10 14:33:55 +010059#error Host architecture was not detected as supported by v8
Steve Blocka7e24c12009-10-30 11:49:00 +000060#endif
61
Leon Clarkef7060e22010-06-03 12:02:55 +010062// Target architecture detection. This may be set externally. If not, detect
63// in the same way as the host architecture, that is, target the native
64// environment as presented by the compiler.
65#if !defined(V8_TARGET_ARCH_X64) && !defined(V8_TARGET_ARCH_IA32) && \
66 !defined(V8_TARGET_ARCH_ARM) && !defined(V8_TARGET_ARCH_MIPS)
67#if defined(_M_X64) || defined(__x86_64__)
68#define V8_TARGET_ARCH_X64 1
69#elif defined(_M_IX86) || defined(__i386__)
70#define V8_TARGET_ARCH_IA32 1
71#elif defined(__ARMEL__)
72#define V8_TARGET_ARCH_ARM 1
73#elif defined(_MIPS_ARCH_MIPS32R2)
74#define V8_TARGET_ARCH_MIPS 1
75#else
76#error Target architecture was not detected as supported by v8
77#endif
78#endif
79
Steve Block6ded16b2010-05-10 14:33:55 +010080// Check for supported combinations of host and target architectures.
81#if defined(V8_TARGET_ARCH_IA32) && !defined(V8_HOST_ARCH_IA32)
82#error Target architecture ia32 is only supported on ia32 host
83#endif
84#if defined(V8_TARGET_ARCH_X64) && !defined(V8_HOST_ARCH_X64)
85#error Target architecture x64 is only supported on x64 host
86#endif
87#if (defined(V8_TARGET_ARCH_ARM) && \
88 !(defined(V8_HOST_ARCH_IA32) || defined(V8_HOST_ARCH_ARM)))
89#error Target architecture arm is only supported on arm and ia32 host
90#endif
91#if (defined(V8_TARGET_ARCH_MIPS) && \
92 !(defined(V8_HOST_ARCH_IA32) || defined(V8_HOST_ARCH_MIPS)))
93#error Target architecture mips is only supported on mips and ia32 host
94#endif
95
96// Define unaligned read for the target architectures supporting it.
Steve Blocka7e24c12009-10-30 11:49:00 +000097#if defined(V8_TARGET_ARCH_X64) || defined(V8_TARGET_ARCH_IA32)
98#define V8_TARGET_CAN_READ_UNALIGNED 1
99#elif V8_TARGET_ARCH_ARM
Kristian Monsen25f61362010-05-21 11:50:48 +0100100// Some CPU-OS combinations allow unaligned access on ARM. We assume
101// that unaligned accesses are not allowed unless the build system
102// defines the CAN_USE_UNALIGNED_ACCESSES macro to be non-zero.
103#if CAN_USE_UNALIGNED_ACCESSES
104#define V8_TARGET_CAN_READ_UNALIGNED 1
105#endif
Andrei Popescu31002712010-02-23 13:46:05 +0000106#elif V8_TARGET_ARCH_MIPS
Steve Blocka7e24c12009-10-30 11:49:00 +0000107#else
Steve Block6ded16b2010-05-10 14:33:55 +0100108#error Target architecture is not supported by v8
Steve Blocka7e24c12009-10-30 11:49:00 +0000109#endif
110
111// Support for alternative bool type. This is only enabled if the code is
112// compiled with USE_MYBOOL defined. This catches some nasty type bugs.
113// For instance, 'bool b = "false";' results in b == true! This is a hidden
114// source of bugs.
115// However, redefining the bool type does have some negative impact on some
116// platforms. It gives rise to compiler warnings (i.e. with
117// MSVC) in the API header files when mixing code that uses the standard
118// bool with code that uses the redefined version.
119// This does not actually belong in the platform code, but needs to be
120// defined here because the platform code uses bool, and platform.h is
121// include very early in the main include file.
122
123#ifdef USE_MYBOOL
124typedef unsigned int __my_bool__;
125#define bool __my_bool__ // use 'indirection' to avoid name clashes
126#endif
127
128typedef uint8_t byte;
129typedef byte* Address;
130
131// Define our own macros for writing 64-bit constants. This is less fragile
132// than defining __STDC_CONSTANT_MACROS before including <stdint.h>, and it
133// works on compilers that don't have it (like MSVC).
134#if V8_HOST_ARCH_64_BIT
135#ifdef _MSC_VER
136#define V8_UINT64_C(x) (x ## UI64)
137#define V8_INT64_C(x) (x ## I64)
138#define V8_PTR_PREFIX "ll"
139#else // _MSC_VER
140#define V8_UINT64_C(x) (x ## UL)
141#define V8_INT64_C(x) (x ## L)
142#define V8_PTR_PREFIX "l"
143#endif // _MSC_VER
144#else // V8_HOST_ARCH_64_BIT
145#define V8_PTR_PREFIX ""
146#endif // V8_HOST_ARCH_64_BIT
147
Steve Block6ded16b2010-05-10 14:33:55 +0100148// The following macro works on both 32 and 64-bit platforms.
149// Usage: instead of writing 0x1234567890123456
150// write V8_2PART_UINT64_C(0x12345678,90123456);
151#define V8_2PART_UINT64_C(a, b) (((static_cast<uint64_t>(a) << 32) + 0x##b##u))
152
Steve Blocka7e24c12009-10-30 11:49:00 +0000153#define V8PRIxPTR V8_PTR_PREFIX "x"
154#define V8PRIdPTR V8_PTR_PREFIX "d"
155
156// Fix for Mac OS X defining uintptr_t as "unsigned long":
157#if defined(__APPLE__) && defined(__MACH__)
158#undef V8PRIxPTR
159#define V8PRIxPTR "lx"
160#endif
161
Steve Block6ded16b2010-05-10 14:33:55 +0100162#if (defined(__APPLE__) && defined(__MACH__)) || \
163 defined(__FreeBSD__) || defined(__OpenBSD__)
164#define USING_BSD_ABI
Steve Blockd0582a62009-12-15 09:54:21 +0000165#endif
166
Steve Blocka7e24c12009-10-30 11:49:00 +0000167// Code-point values in Unicode 4.0 are 21 bits wide.
168typedef uint16_t uc16;
169typedef int32_t uc32;
170
171// -----------------------------------------------------------------------------
172// Constants
173
174const int KB = 1024;
175const int MB = KB * KB;
176const int GB = KB * KB * KB;
177const int kMaxInt = 0x7FFFFFFF;
178const int kMinInt = -kMaxInt - 1;
179
180const uint32_t kMaxUInt32 = 0xFFFFFFFFu;
181
182const int kCharSize = sizeof(char); // NOLINT
183const int kShortSize = sizeof(short); // NOLINT
184const int kIntSize = sizeof(int); // NOLINT
185const int kDoubleSize = sizeof(double); // NOLINT
186const int kPointerSize = sizeof(void*); // NOLINT
187const int kIntptrSize = sizeof(intptr_t); // NOLINT
188
189#if V8_HOST_ARCH_64_BIT
190const int kPointerSizeLog2 = 3;
191const intptr_t kIntptrSignBit = V8_INT64_C(0x8000000000000000);
192#else
193const int kPointerSizeLog2 = 2;
194const intptr_t kIntptrSignBit = 0x80000000;
195#endif
196
Steve Block6ded16b2010-05-10 14:33:55 +0100197// Mask for the sign bit in a smi.
198const intptr_t kSmiSignMask = kIntptrSignBit;
199
Steve Blocka7e24c12009-10-30 11:49:00 +0000200const int kObjectAlignmentBits = kPointerSizeLog2;
201const intptr_t kObjectAlignment = 1 << kObjectAlignmentBits;
202const intptr_t kObjectAlignmentMask = kObjectAlignment - 1;
203
204// Desired alignment for pointers.
205const intptr_t kPointerAlignment = (1 << kPointerSizeLog2);
206const intptr_t kPointerAlignmentMask = kPointerAlignment - 1;
207
Leon Clarkee46be812010-01-19 14:06:41 +0000208// Desired alignment for maps.
209#if V8_HOST_ARCH_64_BIT
210const intptr_t kMapAlignmentBits = kObjectAlignmentBits;
211#else
212const intptr_t kMapAlignmentBits = kObjectAlignmentBits + 3;
213#endif
214const intptr_t kMapAlignment = (1 << kMapAlignmentBits);
215const intptr_t kMapAlignmentMask = kMapAlignment - 1;
Steve Blocka7e24c12009-10-30 11:49:00 +0000216
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100217// Desired alignment for generated code is 32 bytes (to improve cache line
218// utilization).
219const int kCodeAlignmentBits = 5;
220const intptr_t kCodeAlignment = 1 << kCodeAlignmentBits;
221const intptr_t kCodeAlignmentMask = kCodeAlignment - 1;
222
Steve Blocka7e24c12009-10-30 11:49:00 +0000223// Tag information for Failure.
224const int kFailureTag = 3;
225const int kFailureTagSize = 2;
226const intptr_t kFailureTagMask = (1 << kFailureTagSize) - 1;
227
228
229const int kBitsPerByte = 8;
230const int kBitsPerByteLog2 = 3;
231const int kBitsPerPointer = kPointerSize * kBitsPerByte;
232const int kBitsPerInt = kIntSize * kBitsPerByte;
233
Steve Block6ded16b2010-05-10 14:33:55 +0100234// IEEE 754 single precision floating point number bit layout.
235const uint32_t kBinary32SignMask = 0x80000000u;
236const uint32_t kBinary32ExponentMask = 0x7f800000u;
237const uint32_t kBinary32MantissaMask = 0x007fffffu;
238const int kBinary32ExponentBias = 127;
239const int kBinary32MaxExponent = 0xFE;
240const int kBinary32MinExponent = 0x01;
241const int kBinary32MantissaBits = 23;
242const int kBinary32ExponentShift = 23;
Steve Blocka7e24c12009-10-30 11:49:00 +0000243
244// Zap-value: The value used for zapping dead objects.
245// Should be a recognizable hex value tagged as a heap object pointer.
246#ifdef V8_HOST_ARCH_64_BIT
247const Address kZapValue =
248 reinterpret_cast<Address>(V8_UINT64_C(0xdeadbeedbeadbeed));
249const Address kHandleZapValue =
250 reinterpret_cast<Address>(V8_UINT64_C(0x1baddead0baddead));
251const Address kFromSpaceZapValue =
252 reinterpret_cast<Address>(V8_UINT64_C(0x1beefdad0beefdad));
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100253const uint64_t kDebugZapValue = 0xbadbaddbbadbaddb;
Steve Blocka7e24c12009-10-30 11:49:00 +0000254#else
255const Address kZapValue = reinterpret_cast<Address>(0xdeadbeed);
256const Address kHandleZapValue = reinterpret_cast<Address>(0xbaddead);
257const Address kFromSpaceZapValue = reinterpret_cast<Address>(0xbeefdad);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100258const uint32_t kDebugZapValue = 0xbadbaddb;
Steve Blocka7e24c12009-10-30 11:49:00 +0000259#endif
260
261
Leon Clarkee46be812010-01-19 14:06:41 +0000262// Number of bits to represent the page size for paged spaces. The value of 13
263// gives 8K bytes per page.
264const int kPageSizeBits = 13;
265
Steve Block6ded16b2010-05-10 14:33:55 +0100266// On Intel architecture, cache line size is 64 bytes.
267// On ARM it may be less (32 bytes), but as far this constant is
268// used for aligning data, it doesn't hurt to align on a greater value.
269const int kProcessorCacheLineSize = 64;
Leon Clarkee46be812010-01-19 14:06:41 +0000270
Steve Blockd0582a62009-12-15 09:54:21 +0000271// Constants relevant to double precision floating point numbers.
272
273// Quiet NaNs have bits 51 to 62 set, possibly the sign bit, and no
274// other bits set.
275const uint64_t kQuietNaNMask = static_cast<uint64_t>(0xfff) << 51;
276// If looking only at the top 32 bits, the QNaN mask is bits 19 to 30.
277const uint32_t kQuietNaNHighBitsMask = 0xfff << (51 - 32);
278
279
Steve Blocka7e24c12009-10-30 11:49:00 +0000280// -----------------------------------------------------------------------------
281// Forward declarations for frequently used classes
282// (sorted alphabetically)
283
284class AccessorInfo;
285class Allocation;
286class Arguments;
287class Assembler;
Leon Clarke4515c472010-02-03 11:58:03 +0000288class AssertNoAllocation;
Steve Blocka7e24c12009-10-30 11:49:00 +0000289class BreakableStatement;
290class Code;
291class CodeGenerator;
292class CodeStub;
293class Context;
294class Debug;
295class Debugger;
296class DebugInfo;
297class Descriptor;
298class DescriptorArray;
299class Expression;
300class ExternalReference;
301class FixedArray;
302class FunctionEntry;
303class FunctionLiteral;
304class FunctionTemplateInfo;
305class NumberDictionary;
306class StringDictionary;
307class FreeStoreAllocationPolicy;
308template <typename T> class Handle;
309class Heap;
310class HeapObject;
311class IC;
312class InterceptorInfo;
313class IterationStatement;
Steve Blocka7e24c12009-10-30 11:49:00 +0000314class JSArray;
315class JSFunction;
316class JSObject;
317class LargeObjectSpace;
318template <typename T, class P = FreeStoreAllocationPolicy> class List;
319class LookupResult;
320class MacroAssembler;
321class Map;
322class MapSpace;
323class MarkCompactCollector;
324class NewSpace;
325class NodeVisitor;
326class Object;
327class OldSpace;
328class Property;
329class Proxy;
330class RegExpNode;
331struct RegExpCompileData;
332class RegExpTree;
333class RegExpCompiler;
334class RegExpVisitor;
335class Scope;
336template<class Allocator = FreeStoreAllocationPolicy> class ScopeInfo;
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100337class SerializedScopeInfo;
Steve Blocka7e24c12009-10-30 11:49:00 +0000338class Script;
339class Slot;
340class Smi;
Steve Block6ded16b2010-05-10 14:33:55 +0100341template <typename Config, class Allocator = FreeStoreAllocationPolicy>
342 class SplayTree;
Steve Blocka7e24c12009-10-30 11:49:00 +0000343class Statement;
344class String;
345class Struct;
346class SwitchStatement;
347class AstVisitor;
348class Variable;
349class VariableProxy;
350class RelocInfo;
351class Deserializer;
352class MessageLocation;
353class ObjectGroup;
354class TickSample;
355class VirtualMemory;
356class Mutex;
Steve Blocka7e24c12009-10-30 11:49:00 +0000357
358typedef bool (*WeakSlotCallback)(Object** pointer);
359
360// -----------------------------------------------------------------------------
361// Miscellaneous
362
363// NOTE: SpaceIterator depends on AllocationSpace enumeration values being
364// consecutive.
365enum AllocationSpace {
366 NEW_SPACE, // Semispaces collected with copying collector.
367 OLD_POINTER_SPACE, // May contain pointers to new space.
368 OLD_DATA_SPACE, // Must not have pointers to new space.
369 CODE_SPACE, // No pointers to new space, marked executable.
370 MAP_SPACE, // Only and all map objects.
371 CELL_SPACE, // Only and all cell objects.
372 LO_SPACE, // Promoted large objects.
373
374 FIRST_SPACE = NEW_SPACE,
Steve Blockd0582a62009-12-15 09:54:21 +0000375 LAST_SPACE = LO_SPACE,
376 FIRST_PAGED_SPACE = OLD_POINTER_SPACE,
377 LAST_PAGED_SPACE = CELL_SPACE
Steve Blocka7e24c12009-10-30 11:49:00 +0000378};
379const int kSpaceTagSize = 3;
380const int kSpaceTagMask = (1 << kSpaceTagSize) - 1;
381
382
383// A flag that indicates whether objects should be pretenured when
384// allocated (allocated directly into the old generation) or not
385// (allocated in the young generation if the object size and type
386// allows).
387enum PretenureFlag { NOT_TENURED, TENURED };
388
389enum GarbageCollector { SCAVENGER, MARK_COMPACTOR };
390
391enum Executability { NOT_EXECUTABLE, EXECUTABLE };
392
Leon Clarkee46be812010-01-19 14:06:41 +0000393enum VisitMode { VISIT_ALL, VISIT_ALL_IN_SCAVENGE, VISIT_ONLY_STRONG };
Steve Blockd0582a62009-12-15 09:54:21 +0000394
Steve Block6ded16b2010-05-10 14:33:55 +0100395// Flag indicating whether code is built into the VM (one of the natives files).
Andrei Popescu31002712010-02-23 13:46:05 +0000396enum NativesFlag { NOT_NATIVES_CODE, NATIVES_CODE };
397
Steve Blocka7e24c12009-10-30 11:49:00 +0000398
399// A CodeDesc describes a buffer holding instructions and relocation
400// information. The instructions start at the beginning of the buffer
401// and grow forward, the relocation information starts at the end of
402// the buffer and grows backward.
403//
404// |<--------------- buffer_size ---------------->|
405// |<-- instr_size -->| |<-- reloc_size -->|
406// +==================+========+==================+
407// | instructions | free | reloc info |
408// +==================+========+==================+
409// ^
410// |
411// buffer
412
413struct CodeDesc {
414 byte* buffer;
415 int buffer_size;
416 int instr_size;
417 int reloc_size;
418 Assembler* origin;
419};
420
421
422// Callback function on object slots, used for iterating heap object slots in
423// HeapObjects, global pointers to heap objects, etc. The callback allows the
424// callback function to change the value of the slot.
425typedef void (*ObjectSlotCallback)(HeapObject** pointer);
426
427
428// Callback function used for iterating objects in heap spaces,
429// for example, scanning heap objects.
430typedef int (*HeapObjectCallback)(HeapObject* obj);
431
432
433// Callback function used for checking constraints when copying/relocating
434// objects. Returns true if an object can be copied/relocated from its
435// old_addr to a new_addr.
436typedef bool (*ConstraintCallback)(Address new_addr, Address old_addr);
437
438
439// Callback function on inline caches, used for iterating over inline caches
440// in compiled code.
441typedef void (*InlineCacheCallback)(Code* code, Address ic);
442
443
444// State for inline cache call sites. Aliased as IC::State.
445enum InlineCacheState {
446 // Has never been executed.
447 UNINITIALIZED,
448 // Has been executed but monomorhic state has been delayed.
449 PREMONOMORPHIC,
450 // Has been executed and only one receiver type has been seen.
451 MONOMORPHIC,
452 // Like MONOMORPHIC but check failed due to prototype.
453 MONOMORPHIC_PROTOTYPE_FAILURE,
454 // Multiple receiver types have been seen.
455 MEGAMORPHIC,
456 // Special states for debug break or step in prepare stubs.
457 DEBUG_BREAK,
458 DEBUG_PREPARE_STEP_IN
459};
460
461
462enum InLoopFlag {
463 NOT_IN_LOOP,
464 IN_LOOP
465};
466
467
Leon Clarkee46be812010-01-19 14:06:41 +0000468enum CallFunctionFlags {
469 NO_CALL_FUNCTION_FLAGS = 0,
470 RECEIVER_MIGHT_BE_VALUE = 1 << 0 // Receiver might not be a JSObject.
471};
472
473
Steve Block8defd9f2010-07-08 12:39:36 +0100474enum InlineCacheHolderFlag {
475 OWN_MAP, // For fast properties objects.
476 PROTOTYPE_MAP // For slow properties objects (except GlobalObjects).
477};
478
479
Steve Blocka7e24c12009-10-30 11:49:00 +0000480// Type of properties.
481// Order of properties is significant.
482// Must fit in the BitField PropertyDetails::TypeField.
Andrei Popescu31002712010-02-23 13:46:05 +0000483// A copy of this is in mirror-debugger.js.
Steve Blocka7e24c12009-10-30 11:49:00 +0000484enum PropertyType {
485 NORMAL = 0, // only in slow mode
486 FIELD = 1, // only in fast mode
487 CONSTANT_FUNCTION = 2, // only in fast mode
488 CALLBACKS = 3,
489 INTERCEPTOR = 4, // only in lookup results, not in descriptors.
490 MAP_TRANSITION = 5, // only in fast mode
491 CONSTANT_TRANSITION = 6, // only in fast mode
492 NULL_DESCRIPTOR = 7, // only in fast mode
493 // All properties before MAP_TRANSITION are real.
Steve Block6ded16b2010-05-10 14:33:55 +0100494 FIRST_PHANTOM_PROPERTY_TYPE = MAP_TRANSITION,
495 // There are no IC stubs for NULL_DESCRIPTORS. Therefore,
496 // NULL_DESCRIPTOR can be used as the type flag for IC stubs for
497 // nonexistent properties.
498 NONEXISTENT = NULL_DESCRIPTOR
Steve Blocka7e24c12009-10-30 11:49:00 +0000499};
500
501
502// Whether to remove map transitions and constant transitions from a
503// DescriptorArray.
504enum TransitionFlag {
505 REMOVE_TRANSITIONS,
506 KEEP_TRANSITIONS
507};
508
509
510// Union used for fast testing of specific double values.
511union DoubleRepresentation {
512 double value;
513 int64_t bits;
514 DoubleRepresentation(double x) { value = x; }
515};
516
517
Iain Merrick75681382010-08-19 15:07:18 +0100518// Union used for customized checking of the IEEE double types
519// inlined within v8 runtime, rather than going to the underlying
520// platform headers and libraries
521union IeeeDoubleLittleEndianArchType {
522 double d;
523 struct {
524 unsigned int man_low :32;
525 unsigned int man_high :20;
526 unsigned int exp :11;
527 unsigned int sign :1;
528 } bits;
529};
530
531
532union IeeeDoubleBigEndianArchType {
533 double d;
534 struct {
535 unsigned int sign :1;
536 unsigned int exp :11;
537 unsigned int man_high :20;
538 unsigned int man_low :32;
539 } bits;
540};
541
542
Steve Blocka7e24c12009-10-30 11:49:00 +0000543// AccessorCallback
544struct AccessorDescriptor {
545 Object* (*getter)(Object* object, void* data);
546 Object* (*setter)(JSObject* object, Object* value, void* data);
547 void* data;
548};
549
550
551// Logging and profiling.
552// A StateTag represents a possible state of the VM. When compiled with
Steve Block6ded16b2010-05-10 14:33:55 +0100553// ENABLE_VMSTATE_TRACKING, the logger maintains a stack of these.
Steve Blocka7e24c12009-10-30 11:49:00 +0000554// Creating a VMState object enters a state by pushing on the stack, and
555// destroying a VMState object leaves a state by popping the current state
556// from the stack.
557
558#define STATE_TAG_LIST(V) \
559 V(JS) \
560 V(GC) \
561 V(COMPILER) \
562 V(OTHER) \
563 V(EXTERNAL)
564
565enum StateTag {
566#define DEF_STATE_TAG(name) name,
567 STATE_TAG_LIST(DEF_STATE_TAG)
568#undef DEF_STATE_TAG
569 // Pseudo-types.
570 state_tag_count
571};
572
573
574// -----------------------------------------------------------------------------
575// Macros
576
577// Testers for test.
578
579#define HAS_SMI_TAG(value) \
580 ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag)
581
582#define HAS_FAILURE_TAG(value) \
583 ((reinterpret_cast<intptr_t>(value) & kFailureTagMask) == kFailureTag)
584
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100585// OBJECT_POINTER_ALIGN returns the value aligned as a HeapObject pointer
586#define OBJECT_POINTER_ALIGN(value) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000587 (((value) + kObjectAlignmentMask) & ~kObjectAlignmentMask)
588
589// POINTER_SIZE_ALIGN returns the value aligned as a pointer.
590#define POINTER_SIZE_ALIGN(value) \
591 (((value) + kPointerAlignmentMask) & ~kPointerAlignmentMask)
592
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100593// MAP_POINTER_ALIGN returns the value aligned as a map pointer.
594#define MAP_POINTER_ALIGN(value) \
Leon Clarkee46be812010-01-19 14:06:41 +0000595 (((value) + kMapAlignmentMask) & ~kMapAlignmentMask)
596
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100597// CODE_POINTER_ALIGN returns the value aligned as a generated code segment.
598#define CODE_POINTER_ALIGN(value) \
599 (((value) + kCodeAlignmentMask) & ~kCodeAlignmentMask)
600
Steve Blocka7e24c12009-10-30 11:49:00 +0000601// The expression OFFSET_OF(type, field) computes the byte-offset
602// of the specified field relative to the containing type. This
603// corresponds to 'offsetof' (in stddef.h), except that it doesn't
604// use 0 or NULL, which causes a problem with the compiler warnings
605// we have enabled (which is also why 'offsetof' doesn't seem to work).
606// Here we simply use the non-zero value 4, which seems to work.
607#define OFFSET_OF(type, field) \
608 (reinterpret_cast<intptr_t>(&(reinterpret_cast<type*>(4)->field)) - 4)
609
610
611// The expression ARRAY_SIZE(a) is a compile-time constant of type
612// size_t which represents the number of elements of the given
613// array. You should only use ARRAY_SIZE on statically allocated
614// arrays.
615#define ARRAY_SIZE(a) \
616 ((sizeof(a) / sizeof(*(a))) / \
617 static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
618
619
620// The USE(x) template is used to silence C++ compiler warnings
621// issued for (yet) unused variables (typically parameters).
622template <typename T>
623static inline void USE(T) { }
624
625
626// FUNCTION_ADDR(f) gets the address of a C function f.
627#define FUNCTION_ADDR(f) \
628 (reinterpret_cast<v8::internal::Address>(reinterpret_cast<intptr_t>(f)))
629
630
631// FUNCTION_CAST<F>(addr) casts an address into a function
632// of type F. Used to invoke generated code from within C.
633template <typename F>
634F FUNCTION_CAST(Address addr) {
635 return reinterpret_cast<F>(reinterpret_cast<intptr_t>(addr));
636}
637
638
639// A macro to disallow the evil copy constructor and operator= functions
640// This should be used in the private: declarations for a class
641#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
642 TypeName(const TypeName&); \
643 void operator=(const TypeName&)
644
645
646// A macro to disallow all the implicit constructors, namely the
647// default constructor, copy constructor and operator= functions.
648//
649// This should be used in the private: declarations for a class
650// that wants to prevent anyone from instantiating it. This is
651// especially useful for classes containing only static methods.
652#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \
653 TypeName(); \
654 DISALLOW_COPY_AND_ASSIGN(TypeName)
655
656
657// Support for tracking C++ memory allocation. Insert TRACK_MEMORY("Fisk")
658// inside a C++ class and new and delete will be overloaded so logging is
659// performed.
660// This file (globals.h) is included before log.h, so we use direct calls to
661// the Logger rather than the LOG macro.
662#ifdef DEBUG
663#define TRACK_MEMORY(name) \
664 void* operator new(size_t size) { \
665 void* result = ::operator new(size); \
666 Logger::NewEvent(name, result, size); \
667 return result; \
668 } \
669 void operator delete(void* object) { \
670 Logger::DeleteEvent(name, object); \
671 ::operator delete(object); \
672 }
673#else
674#define TRACK_MEMORY(name)
675#endif
676
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100677// Define used for helping GCC to make better inlining. Don't bother for debug
Steve Blocka7e24c12009-10-30 11:49:00 +0000678// builds. On GCC 3.4.5 using __attribute__((always_inline)) causes compilation
679// errors in debug build.
680#if defined(__GNUC__) && !defined(DEBUG)
681#if (__GNUC__ >= 4)
682#define INLINE(header) inline header __attribute__((always_inline))
Ben Murdochbb769b22010-08-11 14:56:33 +0100683#define NO_INLINE(header) header __attribute__((noinline))
Steve Blocka7e24c12009-10-30 11:49:00 +0000684#else
685#define INLINE(header) inline __attribute__((always_inline)) header
Ben Murdochbb769b22010-08-11 14:56:33 +0100686#define NO_INLINE(header) __attribute__((noinline)) header
Steve Blocka7e24c12009-10-30 11:49:00 +0000687#endif
688#else
689#define INLINE(header) inline header
Ben Murdochbb769b22010-08-11 14:56:33 +0100690#define NO_INLINE(header) header
Steve Blocka7e24c12009-10-30 11:49:00 +0000691#endif
692
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100693
694#if defined(__GNUC__) && __GNUC__ >= 4
695#define MUST_USE_RESULT __attribute__ ((warn_unused_result))
696#else
697#define MUST_USE_RESULT
698#endif
699
700
Steve Blockd0582a62009-12-15 09:54:21 +0000701// Feature flags bit positions. They are mostly based on the CPUID spec.
702// (We assign CPUID itself to one of the currently reserved bits --
703// feel free to change this if needed.)
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100704// On X86/X64, values below 32 are bits in EDX, values above 32 are bits in ECX.
705enum CpuFeature { SSE4_1 = 32 + 19, // x86
706 SSE3 = 32 + 0, // x86
Steve Blockd0582a62009-12-15 09:54:21 +0000707 SSE2 = 26, // x86
708 CMOV = 15, // x86
709 RDTSC = 4, // x86
710 CPUID = 10, // x86
711 VFP3 = 1, // ARM
Andrei Popescu31002712010-02-23 13:46:05 +0000712 ARMv7 = 2, // ARM
Steve Blockd0582a62009-12-15 09:54:21 +0000713 SAHF = 0}; // x86
714
Steve Blocka7e24c12009-10-30 11:49:00 +0000715} } // namespace v8::internal
716
717#endif // V8_GLOBALS_H_