blob: 292d8d804007c8101d544727a9bcc4d6b039d8bb [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
217// Tag information for Failure.
218const int kFailureTag = 3;
219const int kFailureTagSize = 2;
220const intptr_t kFailureTagMask = (1 << kFailureTagSize) - 1;
221
222
223const int kBitsPerByte = 8;
224const int kBitsPerByteLog2 = 3;
225const int kBitsPerPointer = kPointerSize * kBitsPerByte;
226const int kBitsPerInt = kIntSize * kBitsPerByte;
227
Steve Block6ded16b2010-05-10 14:33:55 +0100228// IEEE 754 single precision floating point number bit layout.
229const uint32_t kBinary32SignMask = 0x80000000u;
230const uint32_t kBinary32ExponentMask = 0x7f800000u;
231const uint32_t kBinary32MantissaMask = 0x007fffffu;
232const int kBinary32ExponentBias = 127;
233const int kBinary32MaxExponent = 0xFE;
234const int kBinary32MinExponent = 0x01;
235const int kBinary32MantissaBits = 23;
236const int kBinary32ExponentShift = 23;
Steve Blocka7e24c12009-10-30 11:49:00 +0000237
238// Zap-value: The value used for zapping dead objects.
239// Should be a recognizable hex value tagged as a heap object pointer.
240#ifdef V8_HOST_ARCH_64_BIT
241const Address kZapValue =
242 reinterpret_cast<Address>(V8_UINT64_C(0xdeadbeedbeadbeed));
243const Address kHandleZapValue =
244 reinterpret_cast<Address>(V8_UINT64_C(0x1baddead0baddead));
245const Address kFromSpaceZapValue =
246 reinterpret_cast<Address>(V8_UINT64_C(0x1beefdad0beefdad));
247#else
248const Address kZapValue = reinterpret_cast<Address>(0xdeadbeed);
249const Address kHandleZapValue = reinterpret_cast<Address>(0xbaddead);
250const Address kFromSpaceZapValue = reinterpret_cast<Address>(0xbeefdad);
251#endif
252
253
Leon Clarkee46be812010-01-19 14:06:41 +0000254// Number of bits to represent the page size for paged spaces. The value of 13
255// gives 8K bytes per page.
256const int kPageSizeBits = 13;
257
Steve Block6ded16b2010-05-10 14:33:55 +0100258// On Intel architecture, cache line size is 64 bytes.
259// On ARM it may be less (32 bytes), but as far this constant is
260// used for aligning data, it doesn't hurt to align on a greater value.
261const int kProcessorCacheLineSize = 64;
Leon Clarkee46be812010-01-19 14:06:41 +0000262
Steve Blockd0582a62009-12-15 09:54:21 +0000263// Constants relevant to double precision floating point numbers.
264
265// Quiet NaNs have bits 51 to 62 set, possibly the sign bit, and no
266// other bits set.
267const uint64_t kQuietNaNMask = static_cast<uint64_t>(0xfff) << 51;
268// If looking only at the top 32 bits, the QNaN mask is bits 19 to 30.
269const uint32_t kQuietNaNHighBitsMask = 0xfff << (51 - 32);
270
271
Steve Blocka7e24c12009-10-30 11:49:00 +0000272// -----------------------------------------------------------------------------
273// Forward declarations for frequently used classes
274// (sorted alphabetically)
275
276class AccessorInfo;
277class Allocation;
278class Arguments;
279class Assembler;
Leon Clarke4515c472010-02-03 11:58:03 +0000280class AssertNoAllocation;
Steve Blocka7e24c12009-10-30 11:49:00 +0000281class BreakableStatement;
282class Code;
283class CodeGenerator;
284class CodeStub;
285class Context;
286class Debug;
287class Debugger;
288class DebugInfo;
289class Descriptor;
290class DescriptorArray;
291class Expression;
292class ExternalReference;
293class FixedArray;
294class FunctionEntry;
295class FunctionLiteral;
296class FunctionTemplateInfo;
297class NumberDictionary;
298class StringDictionary;
299class FreeStoreAllocationPolicy;
300template <typename T> class Handle;
301class Heap;
302class HeapObject;
303class IC;
304class InterceptorInfo;
305class IterationStatement;
306class Array;
307class JSArray;
308class JSFunction;
309class JSObject;
310class LargeObjectSpace;
311template <typename T, class P = FreeStoreAllocationPolicy> class List;
312class LookupResult;
313class MacroAssembler;
314class Map;
315class MapSpace;
316class MarkCompactCollector;
317class NewSpace;
318class NodeVisitor;
319class Object;
320class OldSpace;
321class Property;
322class Proxy;
323class RegExpNode;
324struct RegExpCompileData;
325class RegExpTree;
326class RegExpCompiler;
327class RegExpVisitor;
328class Scope;
329template<class Allocator = FreeStoreAllocationPolicy> class ScopeInfo;
330class Script;
331class Slot;
332class Smi;
Steve Block6ded16b2010-05-10 14:33:55 +0100333template <typename Config, class Allocator = FreeStoreAllocationPolicy>
334 class SplayTree;
Steve Blocka7e24c12009-10-30 11:49:00 +0000335class Statement;
336class String;
337class Struct;
338class SwitchStatement;
339class AstVisitor;
340class Variable;
341class VariableProxy;
342class RelocInfo;
343class Deserializer;
344class MessageLocation;
345class ObjectGroup;
346class TickSample;
347class VirtualMemory;
348class Mutex;
349class ZoneScopeInfo;
350
351typedef bool (*WeakSlotCallback)(Object** pointer);
352
353// -----------------------------------------------------------------------------
354// Miscellaneous
355
356// NOTE: SpaceIterator depends on AllocationSpace enumeration values being
357// consecutive.
358enum AllocationSpace {
359 NEW_SPACE, // Semispaces collected with copying collector.
360 OLD_POINTER_SPACE, // May contain pointers to new space.
361 OLD_DATA_SPACE, // Must not have pointers to new space.
362 CODE_SPACE, // No pointers to new space, marked executable.
363 MAP_SPACE, // Only and all map objects.
364 CELL_SPACE, // Only and all cell objects.
365 LO_SPACE, // Promoted large objects.
366
367 FIRST_SPACE = NEW_SPACE,
Steve Blockd0582a62009-12-15 09:54:21 +0000368 LAST_SPACE = LO_SPACE,
369 FIRST_PAGED_SPACE = OLD_POINTER_SPACE,
370 LAST_PAGED_SPACE = CELL_SPACE
Steve Blocka7e24c12009-10-30 11:49:00 +0000371};
372const int kSpaceTagSize = 3;
373const int kSpaceTagMask = (1 << kSpaceTagSize) - 1;
374
375
376// A flag that indicates whether objects should be pretenured when
377// allocated (allocated directly into the old generation) or not
378// (allocated in the young generation if the object size and type
379// allows).
380enum PretenureFlag { NOT_TENURED, TENURED };
381
382enum GarbageCollector { SCAVENGER, MARK_COMPACTOR };
383
384enum Executability { NOT_EXECUTABLE, EXECUTABLE };
385
Leon Clarkee46be812010-01-19 14:06:41 +0000386enum VisitMode { VISIT_ALL, VISIT_ALL_IN_SCAVENGE, VISIT_ONLY_STRONG };
Steve Blockd0582a62009-12-15 09:54:21 +0000387
Steve Block6ded16b2010-05-10 14:33:55 +0100388// Flag indicating whether code is built into the VM (one of the natives files).
Andrei Popescu31002712010-02-23 13:46:05 +0000389enum NativesFlag { NOT_NATIVES_CODE, NATIVES_CODE };
390
Steve Blocka7e24c12009-10-30 11:49:00 +0000391
392// A CodeDesc describes a buffer holding instructions and relocation
393// information. The instructions start at the beginning of the buffer
394// and grow forward, the relocation information starts at the end of
395// the buffer and grows backward.
396//
397// |<--------------- buffer_size ---------------->|
398// |<-- instr_size -->| |<-- reloc_size -->|
399// +==================+========+==================+
400// | instructions | free | reloc info |
401// +==================+========+==================+
402// ^
403// |
404// buffer
405
406struct CodeDesc {
407 byte* buffer;
408 int buffer_size;
409 int instr_size;
410 int reloc_size;
411 Assembler* origin;
412};
413
414
415// Callback function on object slots, used for iterating heap object slots in
416// HeapObjects, global pointers to heap objects, etc. The callback allows the
417// callback function to change the value of the slot.
418typedef void (*ObjectSlotCallback)(HeapObject** pointer);
419
420
421// Callback function used for iterating objects in heap spaces,
422// for example, scanning heap objects.
423typedef int (*HeapObjectCallback)(HeapObject* obj);
424
425
426// Callback function used for checking constraints when copying/relocating
427// objects. Returns true if an object can be copied/relocated from its
428// old_addr to a new_addr.
429typedef bool (*ConstraintCallback)(Address new_addr, Address old_addr);
430
431
432// Callback function on inline caches, used for iterating over inline caches
433// in compiled code.
434typedef void (*InlineCacheCallback)(Code* code, Address ic);
435
436
437// State for inline cache call sites. Aliased as IC::State.
438enum InlineCacheState {
439 // Has never been executed.
440 UNINITIALIZED,
441 // Has been executed but monomorhic state has been delayed.
442 PREMONOMORPHIC,
443 // Has been executed and only one receiver type has been seen.
444 MONOMORPHIC,
445 // Like MONOMORPHIC but check failed due to prototype.
446 MONOMORPHIC_PROTOTYPE_FAILURE,
447 // Multiple receiver types have been seen.
448 MEGAMORPHIC,
449 // Special states for debug break or step in prepare stubs.
450 DEBUG_BREAK,
451 DEBUG_PREPARE_STEP_IN
452};
453
454
455enum InLoopFlag {
456 NOT_IN_LOOP,
457 IN_LOOP
458};
459
460
Leon Clarkee46be812010-01-19 14:06:41 +0000461enum CallFunctionFlags {
462 NO_CALL_FUNCTION_FLAGS = 0,
463 RECEIVER_MIGHT_BE_VALUE = 1 << 0 // Receiver might not be a JSObject.
464};
465
466
Steve Blocka7e24c12009-10-30 11:49:00 +0000467// Type of properties.
468// Order of properties is significant.
469// Must fit in the BitField PropertyDetails::TypeField.
Andrei Popescu31002712010-02-23 13:46:05 +0000470// A copy of this is in mirror-debugger.js.
Steve Blocka7e24c12009-10-30 11:49:00 +0000471enum PropertyType {
472 NORMAL = 0, // only in slow mode
473 FIELD = 1, // only in fast mode
474 CONSTANT_FUNCTION = 2, // only in fast mode
475 CALLBACKS = 3,
476 INTERCEPTOR = 4, // only in lookup results, not in descriptors.
477 MAP_TRANSITION = 5, // only in fast mode
478 CONSTANT_TRANSITION = 6, // only in fast mode
479 NULL_DESCRIPTOR = 7, // only in fast mode
480 // All properties before MAP_TRANSITION are real.
Steve Block6ded16b2010-05-10 14:33:55 +0100481 FIRST_PHANTOM_PROPERTY_TYPE = MAP_TRANSITION,
482 // There are no IC stubs for NULL_DESCRIPTORS. Therefore,
483 // NULL_DESCRIPTOR can be used as the type flag for IC stubs for
484 // nonexistent properties.
485 NONEXISTENT = NULL_DESCRIPTOR
Steve Blocka7e24c12009-10-30 11:49:00 +0000486};
487
488
489// Whether to remove map transitions and constant transitions from a
490// DescriptorArray.
491enum TransitionFlag {
492 REMOVE_TRANSITIONS,
493 KEEP_TRANSITIONS
494};
495
496
497// Union used for fast testing of specific double values.
498union DoubleRepresentation {
499 double value;
500 int64_t bits;
501 DoubleRepresentation(double x) { value = x; }
502};
503
504
505// AccessorCallback
506struct AccessorDescriptor {
507 Object* (*getter)(Object* object, void* data);
508 Object* (*setter)(JSObject* object, Object* value, void* data);
509 void* data;
510};
511
512
513// Logging and profiling.
514// A StateTag represents a possible state of the VM. When compiled with
Steve Block6ded16b2010-05-10 14:33:55 +0100515// ENABLE_VMSTATE_TRACKING, the logger maintains a stack of these.
Steve Blocka7e24c12009-10-30 11:49:00 +0000516// Creating a VMState object enters a state by pushing on the stack, and
517// destroying a VMState object leaves a state by popping the current state
518// from the stack.
519
520#define STATE_TAG_LIST(V) \
521 V(JS) \
522 V(GC) \
523 V(COMPILER) \
524 V(OTHER) \
525 V(EXTERNAL)
526
527enum StateTag {
528#define DEF_STATE_TAG(name) name,
529 STATE_TAG_LIST(DEF_STATE_TAG)
530#undef DEF_STATE_TAG
531 // Pseudo-types.
532 state_tag_count
533};
534
535
536// -----------------------------------------------------------------------------
537// Macros
538
539// Testers for test.
540
541#define HAS_SMI_TAG(value) \
542 ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag)
543
544#define HAS_FAILURE_TAG(value) \
545 ((reinterpret_cast<intptr_t>(value) & kFailureTagMask) == kFailureTag)
546
547// OBJECT_SIZE_ALIGN returns the value aligned HeapObject size
548#define OBJECT_SIZE_ALIGN(value) \
549 (((value) + kObjectAlignmentMask) & ~kObjectAlignmentMask)
550
551// POINTER_SIZE_ALIGN returns the value aligned as a pointer.
552#define POINTER_SIZE_ALIGN(value) \
553 (((value) + kPointerAlignmentMask) & ~kPointerAlignmentMask)
554
Leon Clarkee46be812010-01-19 14:06:41 +0000555// MAP_SIZE_ALIGN returns the value aligned as a map pointer.
556#define MAP_SIZE_ALIGN(value) \
557 (((value) + kMapAlignmentMask) & ~kMapAlignmentMask)
558
Steve Blocka7e24c12009-10-30 11:49:00 +0000559// The expression OFFSET_OF(type, field) computes the byte-offset
560// of the specified field relative to the containing type. This
561// corresponds to 'offsetof' (in stddef.h), except that it doesn't
562// use 0 or NULL, which causes a problem with the compiler warnings
563// we have enabled (which is also why 'offsetof' doesn't seem to work).
564// Here we simply use the non-zero value 4, which seems to work.
565#define OFFSET_OF(type, field) \
566 (reinterpret_cast<intptr_t>(&(reinterpret_cast<type*>(4)->field)) - 4)
567
568
569// The expression ARRAY_SIZE(a) is a compile-time constant of type
570// size_t which represents the number of elements of the given
571// array. You should only use ARRAY_SIZE on statically allocated
572// arrays.
573#define ARRAY_SIZE(a) \
574 ((sizeof(a) / sizeof(*(a))) / \
575 static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
576
577
578// The USE(x) template is used to silence C++ compiler warnings
579// issued for (yet) unused variables (typically parameters).
580template <typename T>
581static inline void USE(T) { }
582
583
584// FUNCTION_ADDR(f) gets the address of a C function f.
585#define FUNCTION_ADDR(f) \
586 (reinterpret_cast<v8::internal::Address>(reinterpret_cast<intptr_t>(f)))
587
588
589// FUNCTION_CAST<F>(addr) casts an address into a function
590// of type F. Used to invoke generated code from within C.
591template <typename F>
592F FUNCTION_CAST(Address addr) {
593 return reinterpret_cast<F>(reinterpret_cast<intptr_t>(addr));
594}
595
596
597// A macro to disallow the evil copy constructor and operator= functions
598// This should be used in the private: declarations for a class
599#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
600 TypeName(const TypeName&); \
601 void operator=(const TypeName&)
602
603
604// A macro to disallow all the implicit constructors, namely the
605// default constructor, copy constructor and operator= functions.
606//
607// This should be used in the private: declarations for a class
608// that wants to prevent anyone from instantiating it. This is
609// especially useful for classes containing only static methods.
610#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \
611 TypeName(); \
612 DISALLOW_COPY_AND_ASSIGN(TypeName)
613
614
615// Support for tracking C++ memory allocation. Insert TRACK_MEMORY("Fisk")
616// inside a C++ class and new and delete will be overloaded so logging is
617// performed.
618// This file (globals.h) is included before log.h, so we use direct calls to
619// the Logger rather than the LOG macro.
620#ifdef DEBUG
621#define TRACK_MEMORY(name) \
622 void* operator new(size_t size) { \
623 void* result = ::operator new(size); \
624 Logger::NewEvent(name, result, size); \
625 return result; \
626 } \
627 void operator delete(void* object) { \
628 Logger::DeleteEvent(name, object); \
629 ::operator delete(object); \
630 }
631#else
632#define TRACK_MEMORY(name)
633#endif
634
635// define used for helping GCC to make better inlining. Don't bother for debug
636// builds. On GCC 3.4.5 using __attribute__((always_inline)) causes compilation
637// errors in debug build.
638#if defined(__GNUC__) && !defined(DEBUG)
639#if (__GNUC__ >= 4)
640#define INLINE(header) inline header __attribute__((always_inline))
641#else
642#define INLINE(header) inline __attribute__((always_inline)) header
643#endif
644#else
645#define INLINE(header) inline header
646#endif
647
Steve Blockd0582a62009-12-15 09:54:21 +0000648// Feature flags bit positions. They are mostly based on the CPUID spec.
649// (We assign CPUID itself to one of the currently reserved bits --
650// feel free to change this if needed.)
651enum CpuFeature { SSE3 = 32, // x86
652 SSE2 = 26, // x86
653 CMOV = 15, // x86
654 RDTSC = 4, // x86
655 CPUID = 10, // x86
656 VFP3 = 1, // ARM
Andrei Popescu31002712010-02-23 13:46:05 +0000657 ARMv7 = 2, // ARM
Steve Blockd0582a62009-12-15 09:54:21 +0000658 SAHF = 0}; // x86
659
Steve Blocka7e24c12009-10-30 11:49:00 +0000660} } // namespace v8::internal
661
662#endif // V8_GLOBALS_H_