1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
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.
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.
28 #ifndef V8_V8GLOBALS_H_
29 #define V8_V8GLOBALS_H_
37 // This file contains constants and global declarations related to the
40 // Mask for the sign bit in a smi.
41 const intptr_t kSmiSignMask = kIntptrSignBit;
43 const int kObjectAlignmentBits = kPointerSizeLog2;
44 const intptr_t kObjectAlignment = 1 << kObjectAlignmentBits;
45 const intptr_t kObjectAlignmentMask = kObjectAlignment - 1;
47 // Desired alignment for pointers.
48 const intptr_t kPointerAlignment = (1 << kPointerSizeLog2);
49 const intptr_t kPointerAlignmentMask = kPointerAlignment - 1;
51 // Desired alignment for maps.
52 #if V8_HOST_ARCH_64_BIT
53 const intptr_t kMapAlignmentBits = kObjectAlignmentBits;
55 const intptr_t kMapAlignmentBits = kObjectAlignmentBits + 3;
57 const intptr_t kMapAlignment = (1 << kMapAlignmentBits);
58 const intptr_t kMapAlignmentMask = kMapAlignment - 1;
60 // Desired alignment for generated code is 32 bytes (to improve cache line
62 const int kCodeAlignmentBits = 5;
63 const intptr_t kCodeAlignment = 1 << kCodeAlignmentBits;
64 const intptr_t kCodeAlignmentMask = kCodeAlignment - 1;
66 // Tag information for Failure.
67 const int kFailureTag = 3;
68 const int kFailureTagSize = 2;
69 const intptr_t kFailureTagMask = (1 << kFailureTagSize) - 1;
72 // Zap-value: The value used for zapping dead objects.
73 // Should be a recognizable hex value tagged as a failure.
74 #ifdef V8_HOST_ARCH_64_BIT
75 const Address kZapValue =
76 reinterpret_cast<Address>(V8_UINT64_C(0xdeadbeedbeadbeef));
77 const Address kHandleZapValue =
78 reinterpret_cast<Address>(V8_UINT64_C(0x1baddead0baddeaf));
79 const Address kFromSpaceZapValue =
80 reinterpret_cast<Address>(V8_UINT64_C(0x1beefdad0beefdaf));
81 const uint64_t kDebugZapValue = V8_UINT64_C(0xbadbaddbbadbaddb);
82 const uint64_t kSlotsZapValue = V8_UINT64_C(0xbeefdeadbeefdeef);
83 const uint64_t kFreeListZapValue = 0xfeed1eaffeed1eaf;
85 const Address kZapValue = reinterpret_cast<Address>(0xdeadbeef);
86 const Address kHandleZapValue = reinterpret_cast<Address>(0xbaddeaf);
87 const Address kFromSpaceZapValue = reinterpret_cast<Address>(0xbeefdaf);
88 const uint32_t kSlotsZapValue = 0xbeefdeef;
89 const uint32_t kDebugZapValue = 0xbadbaddb;
90 const uint32_t kFreeListZapValue = 0xfeed1eaf;
94 // Number of bits to represent the page size for paged spaces. The value of 20
95 // gives 1Mb bytes per page.
96 const int kPageSizeBits = 20;
98 // On Intel architecture, cache line size is 64 bytes.
99 // On ARM it may be less (32 bytes), but as far this constant is
100 // used for aligning data, it doesn't hurt to align on a greater value.
101 const int kProcessorCacheLineSize = 64;
103 // Constants relevant to double precision floating point numbers.
104 // If looking only at the top 32 bits, the QNaN mask is bits 19 to 30.
105 const uint32_t kQuietNaNHighBitsMask = 0xfff << (51 - 32);
108 // -----------------------------------------------------------------------------
109 // Forward declarations for frequently used classes
115 class AssertNoAllocation;
124 class DescriptorArray;
125 class ExternalReference;
127 class FunctionTemplateInfo;
129 class SeededNumberDictionary;
130 class UnseededNumberDictionary;
131 class StringDictionary;
132 template <typename T> class Handle;
136 class InterceptorInfo;
140 class LargeObjectSpace;
142 class MacroAssembler;
145 class MarkCompactCollector;
155 template <typename Config, class Allocator = FreeStoreAllocationPolicy>
162 class MessageLocation;
168 typedef bool (*WeakSlotCallback)(Object** pointer);
170 typedef bool (*WeakSlotCallbackWithHeap)(Heap* heap, Object** pointer);
172 // -----------------------------------------------------------------------------
175 // NOTE: SpaceIterator depends on AllocationSpace enumeration values being
177 enum AllocationSpace {
178 NEW_SPACE, // Semispaces collected with copying collector.
179 OLD_POINTER_SPACE, // May contain pointers to new space.
180 OLD_DATA_SPACE, // Must not have pointers to new space.
181 CODE_SPACE, // No pointers to new space, marked executable.
182 MAP_SPACE, // Only and all map objects.
183 CELL_SPACE, // Only and all cell objects.
184 LO_SPACE, // Promoted large objects.
186 FIRST_SPACE = NEW_SPACE,
187 LAST_SPACE = LO_SPACE,
188 FIRST_PAGED_SPACE = OLD_POINTER_SPACE,
189 LAST_PAGED_SPACE = CELL_SPACE
191 const int kSpaceTagSize = 3;
192 const int kSpaceTagMask = (1 << kSpaceTagSize) - 1;
195 // A flag that indicates whether objects should be pretenured when
196 // allocated (allocated directly into the old generation) or not
197 // (allocated in the young generation if the object size and type
199 enum PretenureFlag { NOT_TENURED, TENURED };
201 enum GarbageCollector { SCAVENGER, MARK_COMPACTOR };
203 enum Executability { NOT_EXECUTABLE, EXECUTABLE };
207 VISIT_ALL_IN_SCAVENGE,
208 VISIT_ALL_IN_SWEEP_NEWSPACE,
212 // Flag indicating whether code is built into the VM (one of the natives files).
213 enum NativesFlag { NOT_NATIVES_CODE, NATIVES_CODE };
216 // A CodeDesc describes a buffer holding instructions and relocation
217 // information. The instructions start at the beginning of the buffer
218 // and grow forward, the relocation information starts at the end of
219 // the buffer and grows backward.
221 // |<--------------- buffer_size ---------------->|
222 // |<-- instr_size -->| |<-- reloc_size -->|
223 // +==================+========+==================+
224 // | instructions | free | reloc info |
225 // +==================+========+==================+
239 // Callback function used for iterating objects in heap spaces,
240 // for example, scanning heap objects.
241 typedef int (*HeapObjectCallback)(HeapObject* obj);
244 // Callback function used for checking constraints when copying/relocating
245 // objects. Returns true if an object can be copied/relocated from its
246 // old_addr to a new_addr.
247 typedef bool (*ConstraintCallback)(Address new_addr, Address old_addr);
250 // Callback function on inline caches, used for iterating over inline caches
252 typedef void (*InlineCacheCallback)(Code* code, Address ic);
255 // State for inline cache call sites. Aliased as IC::State.
256 enum InlineCacheState {
257 // Has never been executed.
259 // Has been executed but monomorhic state has been delayed.
261 // Has been executed and only one receiver type has been seen.
263 // Like MONOMORPHIC but check failed due to prototype.
264 MONOMORPHIC_PROTOTYPE_FAILURE,
265 // Multiple receiver types have been seen.
267 // Special states for debug break or step in prepare stubs.
269 DEBUG_PREPARE_STEP_IN
281 enum CallFunctionFlags {
282 NO_CALL_FUNCTION_FLAGS = 0,
283 // Receiver might implicitly be the global objects. If it is, the
284 // hole is passed to the call function stub.
285 RECEIVER_MIGHT_BE_IMPLICIT = 1 << 0,
286 // The call target is cached in the instruction stream.
287 RECORD_CALL_TARGET = 1 << 1
291 enum InlineCacheHolderFlag {
292 OWN_MAP, // For fast properties objects.
293 PROTOTYPE_MAP // For slow properties objects (except GlobalObjects).
297 // The Store Buffer (GC).
299 kStoreBufferFullEvent,
300 kStoreBufferStartScanningPagesEvent,
301 kStoreBufferScanningPageEvent
305 typedef void (*StoreBufferCallback)(Heap* heap,
307 StoreBufferEvent event);
310 // Whether to remove map transitions and constant transitions from a
312 enum TransitionFlag {
318 // Union used for fast testing of specific double values.
319 union DoubleRepresentation {
322 DoubleRepresentation(double x) { value = x; }
326 // Union used for customized checking of the IEEE double types
327 // inlined within v8 runtime, rather than going to the underlying
328 // platform headers and libraries
329 union IeeeDoubleLittleEndianArchType {
332 unsigned int man_low :32;
333 unsigned int man_high :20;
334 unsigned int exp :11;
335 unsigned int sign :1;
340 union IeeeDoubleBigEndianArchType {
343 unsigned int sign :1;
344 unsigned int exp :11;
345 unsigned int man_high :20;
346 unsigned int man_low :32;
352 struct AccessorDescriptor {
353 MaybeObject* (*getter)(Object* object, void* data);
354 MaybeObject* (*setter)(JSObject* object, Object* value, void* data);
359 // Logging and profiling. A StateTag represents a possible state of
360 // the VM. The logger maintains a stack of these. Creating a VMState
361 // object enters a state by pushing on the stack, and destroying a
362 // VMState object leaves a state by popping the current state from the
365 #define STATE_TAG_LIST(V) \
373 #define DEF_STATE_TAG(name) name,
374 STATE_TAG_LIST(DEF_STATE_TAG)
381 // -----------------------------------------------------------------------------
386 #define HAS_SMI_TAG(value) \
387 ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag)
389 #define HAS_FAILURE_TAG(value) \
390 ((reinterpret_cast<intptr_t>(value) & kFailureTagMask) == kFailureTag)
392 // OBJECT_POINTER_ALIGN returns the value aligned as a HeapObject pointer
393 #define OBJECT_POINTER_ALIGN(value) \
394 (((value) + kObjectAlignmentMask) & ~kObjectAlignmentMask)
396 // POINTER_SIZE_ALIGN returns the value aligned as a pointer.
397 #define POINTER_SIZE_ALIGN(value) \
398 (((value) + kPointerAlignmentMask) & ~kPointerAlignmentMask)
400 // MAP_POINTER_ALIGN returns the value aligned as a map pointer.
401 #define MAP_POINTER_ALIGN(value) \
402 (((value) + kMapAlignmentMask) & ~kMapAlignmentMask)
404 // CODE_POINTER_ALIGN returns the value aligned as a generated code segment.
405 #define CODE_POINTER_ALIGN(value) \
406 (((value) + kCodeAlignmentMask) & ~kCodeAlignmentMask)
408 // Support for tracking C++ memory allocation. Insert TRACK_MEMORY("Fisk")
409 // inside a C++ class and new and delete will be overloaded so logging is
411 // This file (globals.h) is included before log.h, so we use direct calls to
412 // the Logger rather than the LOG macro.
414 #define TRACK_MEMORY(name) \
415 void* operator new(size_t size) { \
416 void* result = ::operator new(size); \
417 Logger::NewEventStatic(name, result, size); \
420 void operator delete(void* object) { \
421 Logger::DeleteEventStatic(name, object); \
422 ::operator delete(object); \
425 #define TRACK_MEMORY(name)
429 // Feature flags bit positions. They are mostly based on the CPUID spec.
430 // (We assign CPUID itself to one of the currently reserved bits --
431 // feel free to change this if needed.)
432 // On X86/X64, values below 32 are bits in EDX, values above 32 are bits in ECX.
433 enum CpuFeature { SSE4_1 = 32 + 19, // x86
434 SSE3 = 32 + 0, // x86
445 // Used to specify if a macro instruction must perform a smi check on tagged
453 // Used to specify whether a receiver is implicitly or explicitly
454 // provided to a call.
462 EVAL_SCOPE, // The top-level scope for an eval source.
463 FUNCTION_SCOPE, // The top-level scope for a function.
464 MODULE_SCOPE, // The scope introduced by a module literal
465 GLOBAL_SCOPE, // The top-level scope for a program or a top-level eval.
466 CATCH_SCOPE, // The scope introduced by catch.
467 BLOCK_SCOPE, // The scope introduced by a new block.
468 WITH_SCOPE // The scope introduced by with.
472 const uint32_t kHoleNanUpper32 = 0x7FFFFFFF;
473 const uint32_t kHoleNanLower32 = 0xFFFFFFFF;
474 const uint32_t kNaNOrInfinityLowerBoundUpper32 = 0x7FF00000;
476 const uint64_t kHoleNanInt64 =
477 (static_cast<uint64_t>(kHoleNanUpper32) << 32) | kHoleNanLower32;
478 const uint64_t kLastNonNaNInt64 =
479 (static_cast<uint64_t>(kNaNOrInfinityLowerBoundUpper32) << 32);
483 // User declared variables:
484 VAR, // declared via 'var', and 'function' declarations
486 CONST, // declared via 'const' declarations
488 CONST_HARMONY, // declared via 'const' declarations in harmony mode
490 LET, // declared via 'let' declarations
492 // Variables introduced by the compiler:
493 DYNAMIC, // always require dynamic lookup (we don't know
496 DYNAMIC_GLOBAL, // requires dynamic lookup, but we know that the
497 // variable is global unless it has been shadowed
498 // by an eval-introduced variable
500 DYNAMIC_LOCAL, // requires dynamic lookup, but we know that the
501 // variable is local and where it is unless it
502 // has been shadowed by an eval-introduced
505 INTERNAL, // like VAR, but not user-visible (may or may not
508 TEMPORARY // temporary variables (not user-visible), never
513 // ES6 Draft Rev3 10.2 specifies declarative environment records with mutable
514 // and immutable bindings that can be in two states: initialized and
515 // uninitialized. In ES5 only immutable bindings have these two states. When
516 // accessing a binding, it needs to be checked for initialization. However in
517 // the following cases the binding is initialized immediately after creation
518 // so the initialization check can always be skipped:
519 // 1. Var declared local variables.
521 // 2. A local variable introduced by a function declaration.
524 // function x(foo) {}
525 // 4. Catch bound variables.
526 // try {} catch (foo) {}
527 // 6. Function variables of named function expressions.
528 // var x = function foo() {}
529 // 7. Implicit binding of 'this'.
530 // 8. Implicit binding of 'arguments' in functions.
532 // ES5 specified object environment records which are introduced by ES elements
533 // such as Program and WithStatement that associate identifier bindings with the
534 // properties of some object. In the specification only mutable bindings exist
535 // (which may be non-writable) and have no distinct initialization step. However
536 // V8 allows const declarations in global code with distinct creation and
537 // initialization steps which are represented by non-writable properties in the
538 // global object. As a result also these bindings need to be checked for
541 // The following enum specifies a flag that indicates if the binding needs a
542 // distinct initialization step (kNeedsInitialization) or if the binding is
543 // immediately initialized upon creation (kCreatedInitialized).
544 enum InitializationFlag {
545 kNeedsInitialization,
550 enum ClearExceptionFlag {
556 } } // namespace v8::internal
558 #endif // V8_V8GLOBALS_H_