blob: bef5e8ed03586e69b38cfe027cfdc3c6a66347e6 [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
Andrei Popescu31002712010-02-23 13:46:05 +000049#elif defined(_MIPS_ARCH_MIPS32R2)
50#define V8_HOST_ARCH_MIPS 1
51#define V8_HOST_ARCH_32_BIT 1
Steve Blocka7e24c12009-10-30 11:49:00 +000052#else
Steve Block6ded16b2010-05-10 14:33:55 +010053#error Host architecture was not detected as supported by v8
Steve Blocka7e24c12009-10-30 11:49:00 +000054#endif
55
Steve Block6ded16b2010-05-10 14:33:55 +010056// Check for supported combinations of host and target architectures.
57#if defined(V8_TARGET_ARCH_IA32) && !defined(V8_HOST_ARCH_IA32)
58#error Target architecture ia32 is only supported on ia32 host
59#endif
60#if defined(V8_TARGET_ARCH_X64) && !defined(V8_HOST_ARCH_X64)
61#error Target architecture x64 is only supported on x64 host
62#endif
63#if (defined(V8_TARGET_ARCH_ARM) && \
64 !(defined(V8_HOST_ARCH_IA32) || defined(V8_HOST_ARCH_ARM)))
65#error Target architecture arm is only supported on arm and ia32 host
66#endif
67#if (defined(V8_TARGET_ARCH_MIPS) && \
68 !(defined(V8_HOST_ARCH_IA32) || defined(V8_HOST_ARCH_MIPS)))
69#error Target architecture mips is only supported on mips and ia32 host
70#endif
71
72// Define unaligned read for the target architectures supporting it.
Steve Blocka7e24c12009-10-30 11:49:00 +000073#if defined(V8_TARGET_ARCH_X64) || defined(V8_TARGET_ARCH_IA32)
74#define V8_TARGET_CAN_READ_UNALIGNED 1
75#elif V8_TARGET_ARCH_ARM
Andrei Popescu31002712010-02-23 13:46:05 +000076#elif V8_TARGET_ARCH_MIPS
Steve Blocka7e24c12009-10-30 11:49:00 +000077#else
Steve Block6ded16b2010-05-10 14:33:55 +010078#error Target architecture is not supported by v8
Steve Blocka7e24c12009-10-30 11:49:00 +000079#endif
80
81// Support for alternative bool type. This is only enabled if the code is
82// compiled with USE_MYBOOL defined. This catches some nasty type bugs.
83// For instance, 'bool b = "false";' results in b == true! This is a hidden
84// source of bugs.
85// However, redefining the bool type does have some negative impact on some
86// platforms. It gives rise to compiler warnings (i.e. with
87// MSVC) in the API header files when mixing code that uses the standard
88// bool with code that uses the redefined version.
89// This does not actually belong in the platform code, but needs to be
90// defined here because the platform code uses bool, and platform.h is
91// include very early in the main include file.
92
93#ifdef USE_MYBOOL
94typedef unsigned int __my_bool__;
95#define bool __my_bool__ // use 'indirection' to avoid name clashes
96#endif
97
98typedef uint8_t byte;
99typedef byte* Address;
100
101// Define our own macros for writing 64-bit constants. This is less fragile
102// than defining __STDC_CONSTANT_MACROS before including <stdint.h>, and it
103// works on compilers that don't have it (like MSVC).
104#if V8_HOST_ARCH_64_BIT
105#ifdef _MSC_VER
106#define V8_UINT64_C(x) (x ## UI64)
107#define V8_INT64_C(x) (x ## I64)
108#define V8_PTR_PREFIX "ll"
109#else // _MSC_VER
110#define V8_UINT64_C(x) (x ## UL)
111#define V8_INT64_C(x) (x ## L)
112#define V8_PTR_PREFIX "l"
113#endif // _MSC_VER
114#else // V8_HOST_ARCH_64_BIT
115#define V8_PTR_PREFIX ""
116#endif // V8_HOST_ARCH_64_BIT
117
Steve Block6ded16b2010-05-10 14:33:55 +0100118// The following macro works on both 32 and 64-bit platforms.
119// Usage: instead of writing 0x1234567890123456
120// write V8_2PART_UINT64_C(0x12345678,90123456);
121#define V8_2PART_UINT64_C(a, b) (((static_cast<uint64_t>(a) << 32) + 0x##b##u))
122
Steve Blocka7e24c12009-10-30 11:49:00 +0000123#define V8PRIxPTR V8_PTR_PREFIX "x"
124#define V8PRIdPTR V8_PTR_PREFIX "d"
125
126// Fix for Mac OS X defining uintptr_t as "unsigned long":
127#if defined(__APPLE__) && defined(__MACH__)
128#undef V8PRIxPTR
129#define V8PRIxPTR "lx"
130#endif
131
Steve Block6ded16b2010-05-10 14:33:55 +0100132#if (defined(__APPLE__) && defined(__MACH__)) || \
133 defined(__FreeBSD__) || defined(__OpenBSD__)
134#define USING_BSD_ABI
Steve Blockd0582a62009-12-15 09:54:21 +0000135#endif
136
Steve Blocka7e24c12009-10-30 11:49:00 +0000137// Code-point values in Unicode 4.0 are 21 bits wide.
138typedef uint16_t uc16;
139typedef int32_t uc32;
140
141// -----------------------------------------------------------------------------
142// Constants
143
144const int KB = 1024;
145const int MB = KB * KB;
146const int GB = KB * KB * KB;
147const int kMaxInt = 0x7FFFFFFF;
148const int kMinInt = -kMaxInt - 1;
149
150const uint32_t kMaxUInt32 = 0xFFFFFFFFu;
151
152const int kCharSize = sizeof(char); // NOLINT
153const int kShortSize = sizeof(short); // NOLINT
154const int kIntSize = sizeof(int); // NOLINT
155const int kDoubleSize = sizeof(double); // NOLINT
156const int kPointerSize = sizeof(void*); // NOLINT
157const int kIntptrSize = sizeof(intptr_t); // NOLINT
158
159#if V8_HOST_ARCH_64_BIT
160const int kPointerSizeLog2 = 3;
161const intptr_t kIntptrSignBit = V8_INT64_C(0x8000000000000000);
162#else
163const int kPointerSizeLog2 = 2;
164const intptr_t kIntptrSignBit = 0x80000000;
165#endif
166
Steve Block6ded16b2010-05-10 14:33:55 +0100167// Mask for the sign bit in a smi.
168const intptr_t kSmiSignMask = kIntptrSignBit;
169
Steve Blocka7e24c12009-10-30 11:49:00 +0000170const int kObjectAlignmentBits = kPointerSizeLog2;
171const intptr_t kObjectAlignment = 1 << kObjectAlignmentBits;
172const intptr_t kObjectAlignmentMask = kObjectAlignment - 1;
173
174// Desired alignment for pointers.
175const intptr_t kPointerAlignment = (1 << kPointerSizeLog2);
176const intptr_t kPointerAlignmentMask = kPointerAlignment - 1;
177
Leon Clarkee46be812010-01-19 14:06:41 +0000178// Desired alignment for maps.
179#if V8_HOST_ARCH_64_BIT
180const intptr_t kMapAlignmentBits = kObjectAlignmentBits;
181#else
182const intptr_t kMapAlignmentBits = kObjectAlignmentBits + 3;
183#endif
184const intptr_t kMapAlignment = (1 << kMapAlignmentBits);
185const intptr_t kMapAlignmentMask = kMapAlignment - 1;
Steve Blocka7e24c12009-10-30 11:49:00 +0000186
187// Tag information for Failure.
188const int kFailureTag = 3;
189const int kFailureTagSize = 2;
190const intptr_t kFailureTagMask = (1 << kFailureTagSize) - 1;
191
192
193const int kBitsPerByte = 8;
194const int kBitsPerByteLog2 = 3;
195const int kBitsPerPointer = kPointerSize * kBitsPerByte;
196const int kBitsPerInt = kIntSize * kBitsPerByte;
197
Steve Block6ded16b2010-05-10 14:33:55 +0100198// IEEE 754 single precision floating point number bit layout.
199const uint32_t kBinary32SignMask = 0x80000000u;
200const uint32_t kBinary32ExponentMask = 0x7f800000u;
201const uint32_t kBinary32MantissaMask = 0x007fffffu;
202const int kBinary32ExponentBias = 127;
203const int kBinary32MaxExponent = 0xFE;
204const int kBinary32MinExponent = 0x01;
205const int kBinary32MantissaBits = 23;
206const int kBinary32ExponentShift = 23;
Steve Blocka7e24c12009-10-30 11:49:00 +0000207
208// Zap-value: The value used for zapping dead objects.
209// Should be a recognizable hex value tagged as a heap object pointer.
210#ifdef V8_HOST_ARCH_64_BIT
211const Address kZapValue =
212 reinterpret_cast<Address>(V8_UINT64_C(0xdeadbeedbeadbeed));
213const Address kHandleZapValue =
214 reinterpret_cast<Address>(V8_UINT64_C(0x1baddead0baddead));
215const Address kFromSpaceZapValue =
216 reinterpret_cast<Address>(V8_UINT64_C(0x1beefdad0beefdad));
217#else
218const Address kZapValue = reinterpret_cast<Address>(0xdeadbeed);
219const Address kHandleZapValue = reinterpret_cast<Address>(0xbaddead);
220const Address kFromSpaceZapValue = reinterpret_cast<Address>(0xbeefdad);
221#endif
222
223
Leon Clarkee46be812010-01-19 14:06:41 +0000224// Number of bits to represent the page size for paged spaces. The value of 13
225// gives 8K bytes per page.
226const int kPageSizeBits = 13;
227
Steve Block6ded16b2010-05-10 14:33:55 +0100228// On Intel architecture, cache line size is 64 bytes.
229// On ARM it may be less (32 bytes), but as far this constant is
230// used for aligning data, it doesn't hurt to align on a greater value.
231const int kProcessorCacheLineSize = 64;
Leon Clarkee46be812010-01-19 14:06:41 +0000232
Steve Blockd0582a62009-12-15 09:54:21 +0000233// Constants relevant to double precision floating point numbers.
234
235// Quiet NaNs have bits 51 to 62 set, possibly the sign bit, and no
236// other bits set.
237const uint64_t kQuietNaNMask = static_cast<uint64_t>(0xfff) << 51;
238// If looking only at the top 32 bits, the QNaN mask is bits 19 to 30.
239const uint32_t kQuietNaNHighBitsMask = 0xfff << (51 - 32);
240
241
Steve Blocka7e24c12009-10-30 11:49:00 +0000242// -----------------------------------------------------------------------------
243// Forward declarations for frequently used classes
244// (sorted alphabetically)
245
246class AccessorInfo;
247class Allocation;
248class Arguments;
249class Assembler;
Leon Clarke4515c472010-02-03 11:58:03 +0000250class AssertNoAllocation;
Steve Blocka7e24c12009-10-30 11:49:00 +0000251class BreakableStatement;
252class Code;
253class CodeGenerator;
254class CodeStub;
255class Context;
256class Debug;
257class Debugger;
258class DebugInfo;
259class Descriptor;
260class DescriptorArray;
261class Expression;
262class ExternalReference;
263class FixedArray;
264class FunctionEntry;
265class FunctionLiteral;
266class FunctionTemplateInfo;
267class NumberDictionary;
268class StringDictionary;
269class FreeStoreAllocationPolicy;
270template <typename T> class Handle;
271class Heap;
272class HeapObject;
273class IC;
274class InterceptorInfo;
275class IterationStatement;
276class Array;
277class JSArray;
278class JSFunction;
279class JSObject;
280class LargeObjectSpace;
281template <typename T, class P = FreeStoreAllocationPolicy> class List;
282class LookupResult;
283class MacroAssembler;
284class Map;
285class MapSpace;
286class MarkCompactCollector;
287class NewSpace;
288class NodeVisitor;
289class Object;
290class OldSpace;
291class Property;
292class Proxy;
293class RegExpNode;
294struct RegExpCompileData;
295class RegExpTree;
296class RegExpCompiler;
297class RegExpVisitor;
298class Scope;
299template<class Allocator = FreeStoreAllocationPolicy> class ScopeInfo;
300class Script;
301class Slot;
302class Smi;
Steve Block6ded16b2010-05-10 14:33:55 +0100303template <typename Config, class Allocator = FreeStoreAllocationPolicy>
304 class SplayTree;
Steve Blocka7e24c12009-10-30 11:49:00 +0000305class Statement;
306class String;
307class Struct;
308class SwitchStatement;
309class AstVisitor;
310class Variable;
311class VariableProxy;
312class RelocInfo;
313class Deserializer;
314class MessageLocation;
315class ObjectGroup;
316class TickSample;
317class VirtualMemory;
318class Mutex;
319class ZoneScopeInfo;
320
321typedef bool (*WeakSlotCallback)(Object** pointer);
322
323// -----------------------------------------------------------------------------
324// Miscellaneous
325
326// NOTE: SpaceIterator depends on AllocationSpace enumeration values being
327// consecutive.
328enum AllocationSpace {
329 NEW_SPACE, // Semispaces collected with copying collector.
330 OLD_POINTER_SPACE, // May contain pointers to new space.
331 OLD_DATA_SPACE, // Must not have pointers to new space.
332 CODE_SPACE, // No pointers to new space, marked executable.
333 MAP_SPACE, // Only and all map objects.
334 CELL_SPACE, // Only and all cell objects.
335 LO_SPACE, // Promoted large objects.
336
337 FIRST_SPACE = NEW_SPACE,
Steve Blockd0582a62009-12-15 09:54:21 +0000338 LAST_SPACE = LO_SPACE,
339 FIRST_PAGED_SPACE = OLD_POINTER_SPACE,
340 LAST_PAGED_SPACE = CELL_SPACE
Steve Blocka7e24c12009-10-30 11:49:00 +0000341};
342const int kSpaceTagSize = 3;
343const int kSpaceTagMask = (1 << kSpaceTagSize) - 1;
344
345
346// A flag that indicates whether objects should be pretenured when
347// allocated (allocated directly into the old generation) or not
348// (allocated in the young generation if the object size and type
349// allows).
350enum PretenureFlag { NOT_TENURED, TENURED };
351
352enum GarbageCollector { SCAVENGER, MARK_COMPACTOR };
353
354enum Executability { NOT_EXECUTABLE, EXECUTABLE };
355
Leon Clarkee46be812010-01-19 14:06:41 +0000356enum VisitMode { VISIT_ALL, VISIT_ALL_IN_SCAVENGE, VISIT_ONLY_STRONG };
Steve Blockd0582a62009-12-15 09:54:21 +0000357
Steve Block6ded16b2010-05-10 14:33:55 +0100358// Flag indicating whether code is built into the VM (one of the natives files).
Andrei Popescu31002712010-02-23 13:46:05 +0000359enum NativesFlag { NOT_NATIVES_CODE, NATIVES_CODE };
360
Steve Blocka7e24c12009-10-30 11:49:00 +0000361
362// A CodeDesc describes a buffer holding instructions and relocation
363// information. The instructions start at the beginning of the buffer
364// and grow forward, the relocation information starts at the end of
365// the buffer and grows backward.
366//
367// |<--------------- buffer_size ---------------->|
368// |<-- instr_size -->| |<-- reloc_size -->|
369// +==================+========+==================+
370// | instructions | free | reloc info |
371// +==================+========+==================+
372// ^
373// |
374// buffer
375
376struct CodeDesc {
377 byte* buffer;
378 int buffer_size;
379 int instr_size;
380 int reloc_size;
381 Assembler* origin;
382};
383
384
385// Callback function on object slots, used for iterating heap object slots in
386// HeapObjects, global pointers to heap objects, etc. The callback allows the
387// callback function to change the value of the slot.
388typedef void (*ObjectSlotCallback)(HeapObject** pointer);
389
390
391// Callback function used for iterating objects in heap spaces,
392// for example, scanning heap objects.
393typedef int (*HeapObjectCallback)(HeapObject* obj);
394
395
396// Callback function used for checking constraints when copying/relocating
397// objects. Returns true if an object can be copied/relocated from its
398// old_addr to a new_addr.
399typedef bool (*ConstraintCallback)(Address new_addr, Address old_addr);
400
401
402// Callback function on inline caches, used for iterating over inline caches
403// in compiled code.
404typedef void (*InlineCacheCallback)(Code* code, Address ic);
405
406
407// State for inline cache call sites. Aliased as IC::State.
408enum InlineCacheState {
409 // Has never been executed.
410 UNINITIALIZED,
411 // Has been executed but monomorhic state has been delayed.
412 PREMONOMORPHIC,
413 // Has been executed and only one receiver type has been seen.
414 MONOMORPHIC,
415 // Like MONOMORPHIC but check failed due to prototype.
416 MONOMORPHIC_PROTOTYPE_FAILURE,
417 // Multiple receiver types have been seen.
418 MEGAMORPHIC,
419 // Special states for debug break or step in prepare stubs.
420 DEBUG_BREAK,
421 DEBUG_PREPARE_STEP_IN
422};
423
424
425enum InLoopFlag {
426 NOT_IN_LOOP,
427 IN_LOOP
428};
429
430
Leon Clarkee46be812010-01-19 14:06:41 +0000431enum CallFunctionFlags {
432 NO_CALL_FUNCTION_FLAGS = 0,
433 RECEIVER_MIGHT_BE_VALUE = 1 << 0 // Receiver might not be a JSObject.
434};
435
436
Steve Blocka7e24c12009-10-30 11:49:00 +0000437// Type of properties.
438// Order of properties is significant.
439// Must fit in the BitField PropertyDetails::TypeField.
Andrei Popescu31002712010-02-23 13:46:05 +0000440// A copy of this is in mirror-debugger.js.
Steve Blocka7e24c12009-10-30 11:49:00 +0000441enum PropertyType {
442 NORMAL = 0, // only in slow mode
443 FIELD = 1, // only in fast mode
444 CONSTANT_FUNCTION = 2, // only in fast mode
445 CALLBACKS = 3,
446 INTERCEPTOR = 4, // only in lookup results, not in descriptors.
447 MAP_TRANSITION = 5, // only in fast mode
448 CONSTANT_TRANSITION = 6, // only in fast mode
449 NULL_DESCRIPTOR = 7, // only in fast mode
450 // All properties before MAP_TRANSITION are real.
Steve Block6ded16b2010-05-10 14:33:55 +0100451 FIRST_PHANTOM_PROPERTY_TYPE = MAP_TRANSITION,
452 // There are no IC stubs for NULL_DESCRIPTORS. Therefore,
453 // NULL_DESCRIPTOR can be used as the type flag for IC stubs for
454 // nonexistent properties.
455 NONEXISTENT = NULL_DESCRIPTOR
Steve Blocka7e24c12009-10-30 11:49:00 +0000456};
457
458
459// Whether to remove map transitions and constant transitions from a
460// DescriptorArray.
461enum TransitionFlag {
462 REMOVE_TRANSITIONS,
463 KEEP_TRANSITIONS
464};
465
466
467// Union used for fast testing of specific double values.
468union DoubleRepresentation {
469 double value;
470 int64_t bits;
471 DoubleRepresentation(double x) { value = x; }
472};
473
474
475// AccessorCallback
476struct AccessorDescriptor {
477 Object* (*getter)(Object* object, void* data);
478 Object* (*setter)(JSObject* object, Object* value, void* data);
479 void* data;
480};
481
482
483// Logging and profiling.
484// A StateTag represents a possible state of the VM. When compiled with
Steve Block6ded16b2010-05-10 14:33:55 +0100485// ENABLE_VMSTATE_TRACKING, the logger maintains a stack of these.
Steve Blocka7e24c12009-10-30 11:49:00 +0000486// Creating a VMState object enters a state by pushing on the stack, and
487// destroying a VMState object leaves a state by popping the current state
488// from the stack.
489
490#define STATE_TAG_LIST(V) \
491 V(JS) \
492 V(GC) \
493 V(COMPILER) \
494 V(OTHER) \
495 V(EXTERNAL)
496
497enum StateTag {
498#define DEF_STATE_TAG(name) name,
499 STATE_TAG_LIST(DEF_STATE_TAG)
500#undef DEF_STATE_TAG
501 // Pseudo-types.
502 state_tag_count
503};
504
505
506// -----------------------------------------------------------------------------
507// Macros
508
509// Testers for test.
510
511#define HAS_SMI_TAG(value) \
512 ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag)
513
514#define HAS_FAILURE_TAG(value) \
515 ((reinterpret_cast<intptr_t>(value) & kFailureTagMask) == kFailureTag)
516
517// OBJECT_SIZE_ALIGN returns the value aligned HeapObject size
518#define OBJECT_SIZE_ALIGN(value) \
519 (((value) + kObjectAlignmentMask) & ~kObjectAlignmentMask)
520
521// POINTER_SIZE_ALIGN returns the value aligned as a pointer.
522#define POINTER_SIZE_ALIGN(value) \
523 (((value) + kPointerAlignmentMask) & ~kPointerAlignmentMask)
524
Leon Clarkee46be812010-01-19 14:06:41 +0000525// MAP_SIZE_ALIGN returns the value aligned as a map pointer.
526#define MAP_SIZE_ALIGN(value) \
527 (((value) + kMapAlignmentMask) & ~kMapAlignmentMask)
528
Steve Blocka7e24c12009-10-30 11:49:00 +0000529// The expression OFFSET_OF(type, field) computes the byte-offset
530// of the specified field relative to the containing type. This
531// corresponds to 'offsetof' (in stddef.h), except that it doesn't
532// use 0 or NULL, which causes a problem with the compiler warnings
533// we have enabled (which is also why 'offsetof' doesn't seem to work).
534// Here we simply use the non-zero value 4, which seems to work.
535#define OFFSET_OF(type, field) \
536 (reinterpret_cast<intptr_t>(&(reinterpret_cast<type*>(4)->field)) - 4)
537
538
539// The expression ARRAY_SIZE(a) is a compile-time constant of type
540// size_t which represents the number of elements of the given
541// array. You should only use ARRAY_SIZE on statically allocated
542// arrays.
543#define ARRAY_SIZE(a) \
544 ((sizeof(a) / sizeof(*(a))) / \
545 static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
546
547
548// The USE(x) template is used to silence C++ compiler warnings
549// issued for (yet) unused variables (typically parameters).
550template <typename T>
551static inline void USE(T) { }
552
553
554// FUNCTION_ADDR(f) gets the address of a C function f.
555#define FUNCTION_ADDR(f) \
556 (reinterpret_cast<v8::internal::Address>(reinterpret_cast<intptr_t>(f)))
557
558
559// FUNCTION_CAST<F>(addr) casts an address into a function
560// of type F. Used to invoke generated code from within C.
561template <typename F>
562F FUNCTION_CAST(Address addr) {
563 return reinterpret_cast<F>(reinterpret_cast<intptr_t>(addr));
564}
565
566
567// A macro to disallow the evil copy constructor and operator= functions
568// This should be used in the private: declarations for a class
569#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
570 TypeName(const TypeName&); \
571 void operator=(const TypeName&)
572
573
574// A macro to disallow all the implicit constructors, namely the
575// default constructor, copy constructor and operator= functions.
576//
577// This should be used in the private: declarations for a class
578// that wants to prevent anyone from instantiating it. This is
579// especially useful for classes containing only static methods.
580#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \
581 TypeName(); \
582 DISALLOW_COPY_AND_ASSIGN(TypeName)
583
584
585// Support for tracking C++ memory allocation. Insert TRACK_MEMORY("Fisk")
586// inside a C++ class and new and delete will be overloaded so logging is
587// performed.
588// This file (globals.h) is included before log.h, so we use direct calls to
589// the Logger rather than the LOG macro.
590#ifdef DEBUG
591#define TRACK_MEMORY(name) \
592 void* operator new(size_t size) { \
593 void* result = ::operator new(size); \
594 Logger::NewEvent(name, result, size); \
595 return result; \
596 } \
597 void operator delete(void* object) { \
598 Logger::DeleteEvent(name, object); \
599 ::operator delete(object); \
600 }
601#else
602#define TRACK_MEMORY(name)
603#endif
604
605// define used for helping GCC to make better inlining. Don't bother for debug
606// builds. On GCC 3.4.5 using __attribute__((always_inline)) causes compilation
607// errors in debug build.
608#if defined(__GNUC__) && !defined(DEBUG)
609#if (__GNUC__ >= 4)
610#define INLINE(header) inline header __attribute__((always_inline))
611#else
612#define INLINE(header) inline __attribute__((always_inline)) header
613#endif
614#else
615#define INLINE(header) inline header
616#endif
617
Steve Blockd0582a62009-12-15 09:54:21 +0000618// Feature flags bit positions. They are mostly based on the CPUID spec.
619// (We assign CPUID itself to one of the currently reserved bits --
620// feel free to change this if needed.)
621enum CpuFeature { SSE3 = 32, // x86
622 SSE2 = 26, // x86
623 CMOV = 15, // x86
624 RDTSC = 4, // x86
625 CPUID = 10, // x86
626 VFP3 = 1, // ARM
Andrei Popescu31002712010-02-23 13:46:05 +0000627 ARMv7 = 2, // ARM
Steve Blockd0582a62009-12-15 09:54:21 +0000628 SAHF = 0}; // x86
629
Steve Blocka7e24c12009-10-30 11:49:00 +0000630} } // namespace v8::internal
631
632#endif // V8_GLOBALS_H_