1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef V8_V8GLOBALS_H_
6 #define V8_V8GLOBALS_H_
14 // This file contains constants and global declarations related to the
17 // Mask for the sign bit in a smi.
18 const intptr_t kSmiSignMask = kIntptrSignBit;
20 const int kObjectAlignmentBits = kPointerSizeLog2;
21 const intptr_t kObjectAlignment = 1 << kObjectAlignmentBits;
22 const intptr_t kObjectAlignmentMask = kObjectAlignment - 1;
24 // Desired alignment for pointers.
25 const intptr_t kPointerAlignment = (1 << kPointerSizeLog2);
26 const intptr_t kPointerAlignmentMask = kPointerAlignment - 1;
28 // Desired alignment for double values.
29 const intptr_t kDoubleAlignment = 8;
30 const intptr_t kDoubleAlignmentMask = kDoubleAlignment - 1;
32 // Desired alignment for generated code is 32 bytes (to improve cache line
34 const int kCodeAlignmentBits = 5;
35 const intptr_t kCodeAlignment = 1 << kCodeAlignmentBits;
36 const intptr_t kCodeAlignmentMask = kCodeAlignment - 1;
38 // Tag information for Failure.
39 // TODO(yangguo): remove this from space owner calculation.
40 const int kFailureTag = 3;
41 const int kFailureTagSize = 2;
42 const intptr_t kFailureTagMask = (1 << kFailureTagSize) - 1;
45 // Zap-value: The value used for zapping dead objects.
46 // Should be a recognizable hex value tagged as a failure.
47 #ifdef V8_HOST_ARCH_64_BIT
48 const Address kZapValue =
49 reinterpret_cast<Address>(V8_UINT64_C(0xdeadbeedbeadbeef));
50 const Address kHandleZapValue =
51 reinterpret_cast<Address>(V8_UINT64_C(0x1baddead0baddeaf));
52 const Address kGlobalHandleZapValue =
53 reinterpret_cast<Address>(V8_UINT64_C(0x1baffed00baffedf));
54 const Address kFromSpaceZapValue =
55 reinterpret_cast<Address>(V8_UINT64_C(0x1beefdad0beefdaf));
56 const uint64_t kDebugZapValue = V8_UINT64_C(0xbadbaddbbadbaddb);
57 const uint64_t kSlotsZapValue = V8_UINT64_C(0xbeefdeadbeefdeef);
58 const uint64_t kFreeListZapValue = 0xfeed1eaffeed1eaf;
60 const Address kZapValue = reinterpret_cast<Address>(0xdeadbeef);
61 const Address kHandleZapValue = reinterpret_cast<Address>(0xbaddeaf);
62 const Address kGlobalHandleZapValue = reinterpret_cast<Address>(0xbaffedf);
63 const Address kFromSpaceZapValue = reinterpret_cast<Address>(0xbeefdaf);
64 const uint32_t kSlotsZapValue = 0xbeefdeef;
65 const uint32_t kDebugZapValue = 0xbadbaddb;
66 const uint32_t kFreeListZapValue = 0xfeed1eaf;
69 const int kCodeZapValue = 0xbadc0de;
71 // Number of bits to represent the page size for paged spaces. The value of 20
72 // gives 1Mb bytes per page.
73 const int kPageSizeBits = 20;
75 // On Intel architecture, cache line size is 64 bytes.
76 // On ARM it may be less (32 bytes), but as far this constant is
77 // used for aligning data, it doesn't hurt to align on a greater value.
78 #define PROCESSOR_CACHE_LINE_SIZE 64
80 // Constants relevant to double precision floating point numbers.
81 // If looking only at the top 32 bits, the QNaN mask is bits 19 to 30.
82 const uint32_t kQuietNaNHighBitsMask = 0xfff << (51 - 32);
85 // -----------------------------------------------------------------------------
86 // Forward declarations for frequently used classes
100 class DescriptorArray;
101 class TransitionArray;
102 class ExternalReference;
104 class FunctionTemplateInfo;
106 class SeededNumberDictionary;
107 class UnseededNumberDictionary;
108 class NameDictionary;
109 template <typename T> class MaybeHandle;
110 template <typename T> class Handle;
114 class InterceptorInfo;
120 class LargeObjectSpace;
122 class MacroAssembler;
125 class MarkCompactCollector;
134 template <typename Config, class Allocator = FreeStoreAllocationPolicy>
142 class MessageLocation;
145 class RecursiveMutex;
147 typedef bool (*WeakSlotCallback)(Object** pointer);
149 typedef bool (*WeakSlotCallbackWithHeap)(Heap* heap, Object** pointer);
151 // -----------------------------------------------------------------------------
154 // NOTE: SpaceIterator depends on AllocationSpace enumeration values being
156 enum AllocationSpace {
157 NEW_SPACE, // Semispaces collected with copying collector.
158 OLD_POINTER_SPACE, // May contain pointers to new space.
159 OLD_DATA_SPACE, // Must not have pointers to new space.
160 CODE_SPACE, // No pointers to new space, marked executable.
161 MAP_SPACE, // Only and all map objects.
162 CELL_SPACE, // Only and all cell objects.
163 PROPERTY_CELL_SPACE, // Only and all global property cell objects.
164 LO_SPACE, // Promoted large objects.
165 INVALID_SPACE, // Only used in AllocationResult to signal success.
167 FIRST_SPACE = NEW_SPACE,
168 LAST_SPACE = LO_SPACE,
169 FIRST_PAGED_SPACE = OLD_POINTER_SPACE,
170 LAST_PAGED_SPACE = PROPERTY_CELL_SPACE
172 const int kSpaceTagSize = 3;
173 const int kSpaceTagMask = (1 << kSpaceTagSize) - 1;
176 // A flag that indicates whether objects should be pretenured when
177 // allocated (allocated directly into the old generation) or not
178 // (allocated in the young generation if the object size and type
180 enum PretenureFlag { NOT_TENURED, TENURED };
182 enum MinimumCapacity {
183 USE_DEFAULT_MINIMUM_CAPACITY,
184 USE_CUSTOM_MINIMUM_CAPACITY
187 enum GarbageCollector { SCAVENGER, MARK_COMPACTOR };
189 enum Executability { NOT_EXECUTABLE, EXECUTABLE };
193 VISIT_ALL_IN_SCAVENGE,
194 VISIT_ALL_IN_SWEEP_NEWSPACE,
198 // Flag indicating whether code is built into the VM (one of the natives files).
199 enum NativesFlag { NOT_NATIVES_CODE, NATIVES_CODE };
202 // A CodeDesc describes a buffer holding instructions and relocation
203 // information. The instructions start at the beginning of the buffer
204 // and grow forward, the relocation information starts at the end of
205 // the buffer and grows backward.
207 // |<--------------- buffer_size ---------------->|
208 // |<-- instr_size -->| |<-- reloc_size -->|
209 // +==================+========+==================+
210 // | instructions | free | reloc info |
211 // +==================+========+==================+
225 // Callback function used for iterating objects in heap spaces,
226 // for example, scanning heap objects.
227 typedef int (*HeapObjectCallback)(HeapObject* obj);
230 // Callback function used for checking constraints when copying/relocating
231 // objects. Returns true if an object can be copied/relocated from its
232 // old_addr to a new_addr.
233 typedef bool (*ConstraintCallback)(Address new_addr, Address old_addr);
236 // Callback function on inline caches, used for iterating over inline caches
238 typedef void (*InlineCacheCallback)(Code* code, Address ic);
241 // State for inline cache call sites. Aliased as IC::State.
242 enum InlineCacheState {
243 // Has never been executed.
245 // Has been executed but monomorhic state has been delayed.
247 // Has been executed and only one receiver type has been seen.
249 // Like MONOMORPHIC but check failed due to prototype.
250 MONOMORPHIC_PROTOTYPE_FAILURE,
251 // Multiple receiver types have been seen.
253 // Many receiver types have been seen.
255 // A generic handler is installed and no extra typefeedback is recorded.
257 // Special state for debug break or step in prepare stubs.
262 enum CallFunctionFlags {
263 NO_CALL_FUNCTION_FLAGS,
265 // Always wrap the receiver and call to the JSFunction. Only use this flag
266 // both the receiver type and the target method are statically known.
271 enum CallConstructorFlags {
272 NO_CALL_CONSTRUCTOR_FLAGS,
273 // The call target is cached in the instruction stream.
274 RECORD_CONSTRUCTOR_TARGET
278 enum InlineCacheHolderFlag {
279 OWN_MAP, // For fast properties objects.
280 PROTOTYPE_MAP // For slow properties objects (except GlobalObjects).
284 // The Store Buffer (GC).
286 kStoreBufferFullEvent,
287 kStoreBufferStartScanningPagesEvent,
288 kStoreBufferScanningPageEvent
292 typedef void (*StoreBufferCallback)(Heap* heap,
294 StoreBufferEvent event);
297 // Union used for fast testing of specific double values.
298 union DoubleRepresentation {
301 DoubleRepresentation(double x) { value = x; }
302 bool operator==(const DoubleRepresentation& other) const {
303 return bits == other.bits;
308 // Union used for customized checking of the IEEE double types
309 // inlined within v8 runtime, rather than going to the underlying
310 // platform headers and libraries
311 union IeeeDoubleLittleEndianArchType {
314 unsigned int man_low :32;
315 unsigned int man_high :20;
316 unsigned int exp :11;
317 unsigned int sign :1;
322 union IeeeDoubleBigEndianArchType {
325 unsigned int sign :1;
326 unsigned int exp :11;
327 unsigned int man_high :20;
328 unsigned int man_low :32;
334 struct AccessorDescriptor {
335 Object* (*getter)(Isolate* isolate, Object* object, void* data);
337 Isolate* isolate, JSObject* object, Object* value, void* data);
342 // Logging and profiling. A StateTag represents a possible state of
343 // the VM. The logger maintains a stack of these. Creating a VMState
344 // object enters a state by pushing on the stack, and destroying a
345 // VMState object leaves a state by popping the current state from the
358 // -----------------------------------------------------------------------------
363 #define HAS_SMI_TAG(value) \
364 ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag)
366 #define HAS_FAILURE_TAG(value) \
367 ((reinterpret_cast<intptr_t>(value) & kFailureTagMask) == kFailureTag)
369 // OBJECT_POINTER_ALIGN returns the value aligned as a HeapObject pointer
370 #define OBJECT_POINTER_ALIGN(value) \
371 (((value) + kObjectAlignmentMask) & ~kObjectAlignmentMask)
373 // POINTER_SIZE_ALIGN returns the value aligned as a pointer.
374 #define POINTER_SIZE_ALIGN(value) \
375 (((value) + kPointerAlignmentMask) & ~kPointerAlignmentMask)
377 // CODE_POINTER_ALIGN returns the value aligned as a generated code segment.
378 #define CODE_POINTER_ALIGN(value) \
379 (((value) + kCodeAlignmentMask) & ~kCodeAlignmentMask)
381 // Support for tracking C++ memory allocation. Insert TRACK_MEMORY("Fisk")
382 // inside a C++ class and new and delete will be overloaded so logging is
384 // This file (globals.h) is included before log.h, so we use direct calls to
385 // the Logger rather than the LOG macro.
387 #define TRACK_MEMORY(name) \
388 void* operator new(size_t size) { \
389 void* result = ::operator new(size); \
390 Logger::NewEventStatic(name, result, size); \
393 void operator delete(void* object) { \
394 Logger::DeleteEventStatic(name, object); \
395 ::operator delete(object); \
398 #define TRACK_MEMORY(name)
402 // Feature flags bit positions. They are mostly based on the CPUID spec.
403 // On X86/X64, values below 32 are bits in EDX, values above 32 are bits in ECX.
404 enum CpuFeature { SSE4_1 = 32 + 19, // x86
405 SSE3 = 32 + 0, // x86
411 UNALIGNED_ACCESSES = 4, // ARM
412 MOVW_MOVT_IMMEDIATE_LOADS = 5, // ARM
413 VFP32DREGS = 6, // ARM
419 // Used to specify if a macro instruction must perform a smi check on tagged
428 EVAL_SCOPE, // The top-level scope for an eval source.
429 FUNCTION_SCOPE, // The top-level scope for a function.
430 MODULE_SCOPE, // The scope introduced by a module literal
431 GLOBAL_SCOPE, // The top-level scope for a program or a top-level eval.
432 CATCH_SCOPE, // The scope introduced by catch.
433 BLOCK_SCOPE, // The scope introduced by a new block.
434 WITH_SCOPE // The scope introduced by with.
438 const uint32_t kHoleNanUpper32 = 0x7FFFFFFF;
439 const uint32_t kHoleNanLower32 = 0xFFFFFFFF;
440 const uint32_t kNaNOrInfinityLowerBoundUpper32 = 0x7FF00000;
442 const uint64_t kHoleNanInt64 =
443 (static_cast<uint64_t>(kHoleNanUpper32) << 32) | kHoleNanLower32;
444 const uint64_t kLastNonNaNInt64 =
445 (static_cast<uint64_t>(kNaNOrInfinityLowerBoundUpper32) << 32);
448 // The order of this enum has to be kept in sync with the predicates below.
450 // User declared variables:
451 VAR, // declared via 'var', and 'function' declarations
453 CONST_LEGACY, // declared via legacy 'const' declarations
455 LET, // declared via 'let' declarations (first lexical)
457 CONST, // declared via 'const' declarations
459 MODULE, // declared via 'module' declaration (last lexical)
461 // Variables introduced by the compiler:
462 INTERNAL, // like VAR, but not user-visible (may or may not
465 TEMPORARY, // temporary variables (not user-visible), stack-allocated
466 // unless the scope as a whole has forced context allocation
468 DYNAMIC, // always require dynamic lookup (we don't know
471 DYNAMIC_GLOBAL, // requires dynamic lookup, but we know that the
472 // variable is global unless it has been shadowed
473 // by an eval-introduced variable
475 DYNAMIC_LOCAL // requires dynamic lookup, but we know that the
476 // variable is local and where it is unless it
477 // has been shadowed by an eval-introduced
482 inline bool IsDynamicVariableMode(VariableMode mode) {
483 return mode >= DYNAMIC && mode <= DYNAMIC_LOCAL;
487 inline bool IsDeclaredVariableMode(VariableMode mode) {
488 return mode >= VAR && mode <= MODULE;
492 inline bool IsLexicalVariableMode(VariableMode mode) {
493 return mode >= LET && mode <= MODULE;
497 inline bool IsImmutableVariableMode(VariableMode mode) {
498 return (mode >= CONST && mode <= MODULE) || mode == CONST_LEGACY;
502 // ES6 Draft Rev3 10.2 specifies declarative environment records with mutable
503 // and immutable bindings that can be in two states: initialized and
504 // uninitialized. In ES5 only immutable bindings have these two states. When
505 // accessing a binding, it needs to be checked for initialization. However in
506 // the following cases the binding is initialized immediately after creation
507 // so the initialization check can always be skipped:
508 // 1. Var declared local variables.
510 // 2. A local variable introduced by a function declaration.
513 // function x(foo) {}
514 // 4. Catch bound variables.
515 // try {} catch (foo) {}
516 // 6. Function variables of named function expressions.
517 // var x = function foo() {}
518 // 7. Implicit binding of 'this'.
519 // 8. Implicit binding of 'arguments' in functions.
521 // ES5 specified object environment records which are introduced by ES elements
522 // such as Program and WithStatement that associate identifier bindings with the
523 // properties of some object. In the specification only mutable bindings exist
524 // (which may be non-writable) and have no distinct initialization step. However
525 // V8 allows const declarations in global code with distinct creation and
526 // initialization steps which are represented by non-writable properties in the
527 // global object. As a result also these bindings need to be checked for
530 // The following enum specifies a flag that indicates if the binding needs a
531 // distinct initialization step (kNeedsInitialization) or if the binding is
532 // immediately initialized upon creation (kCreatedInitialized).
533 enum InitializationFlag {
534 kNeedsInitialization,
539 enum ClearExceptionFlag {
546 TREAT_MINUS_ZERO_AS_ZERO,
550 } } // namespace v8::internal
552 namespace i = v8::internal;
554 #endif // V8_V8GLOBALS_H_