v8  3.14.5(node0.10.28)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
v8globals.h
Go to the documentation of this file.
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
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_V8GLOBALS_H_
29 #define V8_V8GLOBALS_H_
30 
31 #include "globals.h"
32 #include "checks.h"
33 
34 namespace v8 {
35 namespace internal {
36 
37 // This file contains constants and global declarations related to the
38 // V8 system.
39 
40 // Mask for the sign bit in a smi.
41 const intptr_t kSmiSignMask = kIntptrSignBit;
42 
44 const intptr_t kObjectAlignment = 1 << kObjectAlignmentBits;
46 
47 // Desired alignment for pointers.
48 const intptr_t kPointerAlignment = (1 << kPointerSizeLog2);
50 
51 // Desired alignment for double values.
52 const intptr_t kDoubleAlignment = 8;
54 
55 // Desired alignment for generated code is 32 bytes (to improve cache line
56 // utilization).
57 const int kCodeAlignmentBits = 5;
58 const intptr_t kCodeAlignment = 1 << kCodeAlignmentBits;
59 const intptr_t kCodeAlignmentMask = kCodeAlignment - 1;
60 
61 // Tag information for Failure.
62 const int kFailureTag = 3;
63 const int kFailureTagSize = 2;
64 const intptr_t kFailureTagMask = (1 << kFailureTagSize) - 1;
65 
66 
67 // Zap-value: The value used for zapping dead objects.
68 // Should be a recognizable hex value tagged as a failure.
69 #ifdef V8_HOST_ARCH_64_BIT
70 const Address kZapValue =
71  reinterpret_cast<Address>(V8_UINT64_C(0xdeadbeedbeadbeef));
73  reinterpret_cast<Address>(V8_UINT64_C(0x1baddead0baddeaf));
75  reinterpret_cast<Address>(V8_UINT64_C(0x1beefdad0beefdaf));
76 const uint64_t kDebugZapValue = V8_UINT64_C(0xbadbaddbbadbaddb);
77 const uint64_t kSlotsZapValue = V8_UINT64_C(0xbeefdeadbeefdeef);
78 const uint64_t kFreeListZapValue = 0xfeed1eaffeed1eaf;
79 #else
80 const Address kZapValue = reinterpret_cast<Address>(0xdeadbeef);
81 const Address kHandleZapValue = reinterpret_cast<Address>(0xbaddeaf);
82 const Address kFromSpaceZapValue = reinterpret_cast<Address>(0xbeefdaf);
83 const uint32_t kSlotsZapValue = 0xbeefdeef;
84 const uint32_t kDebugZapValue = 0xbadbaddb;
85 const uint32_t kFreeListZapValue = 0xfeed1eaf;
86 #endif
87 
88 const int kCodeZapValue = 0xbadc0de;
89 
90 // Number of bits to represent the page size for paged spaces. The value of 20
91 // gives 1Mb bytes per page.
92 const int kPageSizeBits = 20;
93 
94 // On Intel architecture, cache line size is 64 bytes.
95 // On ARM it may be less (32 bytes), but as far this constant is
96 // used for aligning data, it doesn't hurt to align on a greater value.
97 const int kProcessorCacheLineSize = 64;
98 
99 // Constants relevant to double precision floating point numbers.
100 // If looking only at the top 32 bits, the QNaN mask is bits 19 to 30.
101 const uint32_t kQuietNaNHighBitsMask = 0xfff << (51 - 32);
102 
103 
104 // -----------------------------------------------------------------------------
105 // Forward declarations for frequently used classes
106 
107 class AccessorInfo;
108 class Allocation;
109 class Arguments;
110 class Assembler;
111 class AssertNoAllocation;
112 class Code;
113 class CodeGenerator;
114 class CodeStub;
115 class Context;
116 class Debug;
117 class Debugger;
118 class DebugInfo;
119 class Descriptor;
120 class DescriptorArray;
121 class TransitionArray;
122 class ExternalReference;
123 class FixedArray;
125 class MemoryChunk;
128 class StringDictionary;
129 template <typename T> class Handle;
130 class Heap;
131 class HeapObject;
132 class IC;
133 class InterceptorInfo;
134 class JSArray;
135 class JSFunction;
136 class JSObject;
137 class LargeObjectSpace;
138 class LookupResult;
139 class MacroAssembler;
140 class Map;
141 class MapSpace;
143 class NewSpace;
144 class Object;
145 class MaybeObject;
146 class OldSpace;
147 class Foreign;
148 class Scope;
149 class ScopeInfo;
150 class Script;
151 class Smi;
152 template <typename Config, class Allocator = FreeStoreAllocationPolicy>
153  class SplayTree;
154 class String;
155 class Struct;
156 class Variable;
157 class RelocInfo;
158 class Deserializer;
159 class MessageLocation;
160 class ObjectGroup;
161 class TickSample;
162 class VirtualMemory;
163 class Mutex;
164 
165 typedef bool (*WeakSlotCallback)(Object** pointer);
166 
167 typedef bool (*WeakSlotCallbackWithHeap)(Heap* heap, Object** pointer);
168 
169 // -----------------------------------------------------------------------------
170 // Miscellaneous
171 
172 // NOTE: SpaceIterator depends on AllocationSpace enumeration values being
173 // consecutive.
175  NEW_SPACE, // Semispaces collected with copying collector.
176  OLD_POINTER_SPACE, // May contain pointers to new space.
177  OLD_DATA_SPACE, // Must not have pointers to new space.
178  CODE_SPACE, // No pointers to new space, marked executable.
179  MAP_SPACE, // Only and all map objects.
180  CELL_SPACE, // Only and all cell objects.
181  LO_SPACE, // Promoted large objects.
182 
187 };
188 const int kSpaceTagSize = 3;
189 const int kSpaceTagMask = (1 << kSpaceTagSize) - 1;
190 
191 
192 // A flag that indicates whether objects should be pretenured when
193 // allocated (allocated directly into the old generation) or not
194 // (allocated in the young generation if the object size and type
195 // allows).
197 
199 
201 
202 enum VisitMode {
207 };
208 
209 // Flag indicating whether code is built into the VM (one of the natives files).
211 
212 
213 // A CodeDesc describes a buffer holding instructions and relocation
214 // information. The instructions start at the beginning of the buffer
215 // and grow forward, the relocation information starts at the end of
216 // the buffer and grows backward.
217 //
218 // |<--------------- buffer_size ---------------->|
219 // |<-- instr_size -->| |<-- reloc_size -->|
220 // +==================+========+==================+
221 // | instructions | free | reloc info |
222 // +==================+========+==================+
223 // ^
224 // |
225 // buffer
226 
227 struct CodeDesc {
233 };
234 
235 
236 // Callback function used for iterating objects in heap spaces,
237 // for example, scanning heap objects.
238 typedef int (*HeapObjectCallback)(HeapObject* obj);
239 
240 
241 // Callback function used for checking constraints when copying/relocating
242 // objects. Returns true if an object can be copied/relocated from its
243 // old_addr to a new_addr.
244 typedef bool (*ConstraintCallback)(Address new_addr, Address old_addr);
245 
246 
247 // Callback function on inline caches, used for iterating over inline caches
248 // in compiled code.
249 typedef void (*InlineCacheCallback)(Code* code, Address ic);
250 
251 
252 // State for inline cache call sites. Aliased as IC::State.
254  // Has never been executed.
256  // Has been executed but monomorhic state has been delayed.
258  // Has been executed and only one receiver type has been seen.
260  // Like MONOMORPHIC but check failed due to prototype.
262  // Multiple receiver types have been seen.
264  // Special states for debug break or step in prepare stubs.
267 };
268 
269 
270 enum CheckType {
275 };
276 
277 
280  // Receiver might implicitly be the global objects. If it is, the
281  // hole is passed to the call function stub.
283  // The call target is cached in the instruction stream.
285 };
286 
287 
289  OWN_MAP, // For fast properties objects.
290  PROTOTYPE_MAP // For slow properties objects (except GlobalObjects).
291 };
292 
293 
294 // The Store Buffer (GC).
295 typedef enum {
300 
301 
302 typedef void (*StoreBufferCallback)(Heap* heap,
303  MemoryChunk* page,
304  StoreBufferEvent event);
305 
306 
307 // Union used for fast testing of specific double values.
309  double value;
310  int64_t bits;
311  DoubleRepresentation(double x) { value = x; }
312 };
313 
314 
315 // Union used for customized checking of the IEEE double types
316 // inlined within v8 runtime, rather than going to the underlying
317 // platform headers and libraries
319  double d;
320  struct {
321  unsigned int man_low :32;
322  unsigned int man_high :20;
323  unsigned int exp :11;
324  unsigned int sign :1;
325  } bits;
326 };
327 
328 
330  double d;
331  struct {
332  unsigned int sign :1;
333  unsigned int exp :11;
334  unsigned int man_high :20;
335  unsigned int man_low :32;
336  } bits;
337 };
338 
339 
340 // AccessorCallback
342  MaybeObject* (*getter)(Object* object, void* data);
343  MaybeObject* (*setter)(JSObject* object, Object* value, void* data);
344  void* data;
345 };
346 
347 
348 // Logging and profiling. A StateTag represents a possible state of
349 // the VM. The logger maintains a stack of these. Creating a VMState
350 // object enters a state by pushing on the stack, and destroying a
351 // VMState object leaves a state by popping the current state from the
352 // stack.
353 
354 #define STATE_TAG_LIST(V) \
355  V(JS) \
356  V(GC) \
357  V(COMPILER) \
358  V(PARALLEL_COMPILER_PROLOGUE) \
359  V(OTHER) \
360  V(EXTERNAL)
361 
362 enum StateTag {
363 #define DEF_STATE_TAG(name) name,
365 #undef DEF_STATE_TAG
366  // Pseudo-types.
368 };
369 
370 
371 // -----------------------------------------------------------------------------
372 // Macros
373 
374 // Testers for test.
375 
376 #define HAS_SMI_TAG(value) \
377  ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag)
378 
379 #define HAS_FAILURE_TAG(value) \
380  ((reinterpret_cast<intptr_t>(value) & kFailureTagMask) == kFailureTag)
381 
382 // OBJECT_POINTER_ALIGN returns the value aligned as a HeapObject pointer
383 #define OBJECT_POINTER_ALIGN(value) \
384  (((value) + kObjectAlignmentMask) & ~kObjectAlignmentMask)
385 
386 // POINTER_SIZE_ALIGN returns the value aligned as a pointer.
387 #define POINTER_SIZE_ALIGN(value) \
388  (((value) + kPointerAlignmentMask) & ~kPointerAlignmentMask)
389 
390 // CODE_POINTER_ALIGN returns the value aligned as a generated code segment.
391 #define CODE_POINTER_ALIGN(value) \
392  (((value) + kCodeAlignmentMask) & ~kCodeAlignmentMask)
393 
394 // Support for tracking C++ memory allocation. Insert TRACK_MEMORY("Fisk")
395 // inside a C++ class and new and delete will be overloaded so logging is
396 // performed.
397 // This file (globals.h) is included before log.h, so we use direct calls to
398 // the Logger rather than the LOG macro.
399 #ifdef DEBUG
400 #define TRACK_MEMORY(name) \
401  void* operator new(size_t size) { \
402  void* result = ::operator new(size); \
403  Logger::NewEventStatic(name, result, size); \
404  return result; \
405  } \
406  void operator delete(void* object) { \
407  Logger::DeleteEventStatic(name, object); \
408  ::operator delete(object); \
409  }
410 #else
411 #define TRACK_MEMORY(name)
412 #endif
413 
414 
419 };
420 
421 
422 // Feature flags bit positions. They are mostly based on the CPUID spec.
423 // (We assign CPUID itself to one of the currently reserved bits --
424 // feel free to change this if needed.)
425 // On X86/X64, values below 32 are bits in EDX, values above 32 are bits in ECX.
426 enum CpuFeature { SSE4_1 = 32 + 19, // x86
427  SSE3 = 32 + 0, // x86
428  SSE2 = 26, // x86
429  CMOV = 15, // x86
430  RDTSC = 4, // x86
431  CPUID = 10, // x86
432  VFP3 = 1, // ARM
433  ARMv7 = 2, // ARM
434  VFP2 = 3, // ARM
435  SUDIV = 4, // ARM
436  UNALIGNED_ACCESSES = 5, // ARM
438  SAHF = 0, // x86
439  FPU = 1}; // MIPS
440 
441 
442 // Used to specify if a macro instruction must perform a smi check on tagged
443 // values.
447 };
448 
449 
450 // Used to specify whether a receiver is implicitly or explicitly
451 // provided to a call.
452 enum CallKind {
455 };
456 
457 
458 enum ScopeType {
459  EVAL_SCOPE, // The top-level scope for an eval source.
460  FUNCTION_SCOPE, // The top-level scope for a function.
461  MODULE_SCOPE, // The scope introduced by a module literal
462  GLOBAL_SCOPE, // The top-level scope for a program or a top-level eval.
463  CATCH_SCOPE, // The scope introduced by catch.
464  BLOCK_SCOPE, // The scope introduced by a new block.
465  WITH_SCOPE // The scope introduced by with.
466 };
467 
468 
469 const uint32_t kHoleNanUpper32 = 0x7FFFFFFF;
470 const uint32_t kHoleNanLower32 = 0xFFFFFFFF;
471 const uint32_t kNaNOrInfinityLowerBoundUpper32 = 0x7FF00000;
472 
473 const uint64_t kHoleNanInt64 =
474  (static_cast<uint64_t>(kHoleNanUpper32) << 32) | kHoleNanLower32;
475 const uint64_t kLastNonNaNInt64 =
476  (static_cast<uint64_t>(kNaNOrInfinityLowerBoundUpper32) << 32);
477 
478 
479 // The order of this enum has to be kept in sync with the predicates below.
481  // User declared variables:
482  VAR, // declared via 'var', and 'function' declarations
483 
484  CONST, // declared via 'const' declarations
485 
486  LET, // declared via 'let' declarations
487 
488  CONST_HARMONY, // declared via 'const' declarations in harmony mode
489 
490  // Variables introduced by the compiler:
491  DYNAMIC, // always require dynamic lookup (we don't know
492  // the declaration)
493 
494  DYNAMIC_GLOBAL, // requires dynamic lookup, but we know that the
495  // variable is global unless it has been shadowed
496  // by an eval-introduced variable
497 
498  DYNAMIC_LOCAL, // requires dynamic lookup, but we know that the
499  // variable is local and where it is unless it
500  // has been shadowed by an eval-introduced
501  // variable
502 
503  INTERNAL, // like VAR, but not user-visible (may or may not
504  // be in a context)
505 
506  TEMPORARY // temporary variables (not user-visible), never
507  // in a context
508 };
509 
510 
512  return mode >= DYNAMIC && mode <= DYNAMIC_LOCAL;
513 }
514 
515 
517  return mode >= VAR && mode <= CONST_HARMONY;
518 }
519 
520 
522  return mode >= LET && mode <= CONST_HARMONY;
523 }
524 
525 
527  return mode == CONST || mode == CONST_HARMONY;
528 }
529 
530 
531 // ES6 Draft Rev3 10.2 specifies declarative environment records with mutable
532 // and immutable bindings that can be in two states: initialized and
533 // uninitialized. In ES5 only immutable bindings have these two states. When
534 // accessing a binding, it needs to be checked for initialization. However in
535 // the following cases the binding is initialized immediately after creation
536 // so the initialization check can always be skipped:
537 // 1. Var declared local variables.
538 // var foo;
539 // 2. A local variable introduced by a function declaration.
540 // function foo() {}
541 // 3. Parameters
542 // function x(foo) {}
543 // 4. Catch bound variables.
544 // try {} catch (foo) {}
545 // 6. Function variables of named function expressions.
546 // var x = function foo() {}
547 // 7. Implicit binding of 'this'.
548 // 8. Implicit binding of 'arguments' in functions.
549 //
550 // ES5 specified object environment records which are introduced by ES elements
551 // such as Program and WithStatement that associate identifier bindings with the
552 // properties of some object. In the specification only mutable bindings exist
553 // (which may be non-writable) and have no distinct initialization step. However
554 // V8 allows const declarations in global code with distinct creation and
555 // initialization steps which are represented by non-writable properties in the
556 // global object. As a result also these bindings need to be checked for
557 // initialization.
558 //
559 // The following enum specifies a flag that indicates if the binding needs a
560 // distinct initialization step (kNeedsInitialization) or if the binding is
561 // immediately initialized upon creation (kCreatedInitialized).
565 };
566 
567 
571 };
572 
573 
574 } } // namespace v8::internal
575 
576 #endif // V8_V8GLOBALS_H_
byte * Address
Definition: globals.h:157
bool(* WeakSlotCallbackWithHeap)(Heap *heap, Object **pointer)
Definition: v8globals.h:167
const intptr_t kSmiSignMask
Definition: v8globals.h:41
const intptr_t kDoubleAlignmentMask
Definition: v8globals.h:53
const uint32_t kNaNOrInfinityLowerBoundUpper32
Definition: v8globals.h:471
const intptr_t kCodeAlignmentMask
Definition: v8globals.h:59
const intptr_t kIntptrSignBit
Definition: globals.h:233
const int kProcessorCacheLineSize
Definition: v8globals.h:97
struct v8::internal::IeeeDoubleBigEndianArchType::@33 bits
const int kPointerSizeLog2
Definition: globals.h:232
const intptr_t kCodeAlignment
Definition: v8globals.h:58
const int kSpaceTagSize
Definition: v8globals.h:188
const intptr_t kObjectAlignmentMask
Definition: v8globals.h:45
void(* StoreBufferCallback)(Heap *heap, MemoryChunk *page, StoreBufferEvent event)
Definition: v8globals.h:302
uint8_t byte
Definition: globals.h:156
const uint32_t kSlotsZapValue
Definition: v8globals.h:83
const uint64_t kHoleNanInt64
Definition: v8globals.h:473
int(* HeapObjectCallback)(HeapObject *obj)
Definition: v8globals.h:238
const intptr_t kFailureTagMask
Definition: v8globals.h:64
const int kFailureTagSize
Definition: v8globals.h:63
const uint32_t kHoleNanUpper32
Definition: v8globals.h:469
const Address kZapValue
Definition: v8globals.h:80
const uint32_t kHoleNanLower32
Definition: v8globals.h:470
bool IsLexicalVariableMode(VariableMode mode)
Definition: v8globals.h:521
#define DEF_STATE_TAG(name)
Definition: v8globals.h:363
const uint32_t kQuietNaNHighBitsMask
Definition: v8globals.h:101
Assembler * origin
Definition: v8globals.h:232
const Address kFromSpaceZapValue
Definition: v8globals.h:82
bool IsDeclaredVariableMode(VariableMode mode)
Definition: v8globals.h:516
const intptr_t kPointerAlignmentMask
Definition: v8globals.h:49
const int kSpaceTagMask
Definition: v8globals.h:189
const uint32_t kFreeListZapValue
Definition: v8globals.h:85
void(* InlineCacheCallback)(Code *code, Address ic)
Definition: v8globals.h:249
const intptr_t kObjectAlignment
Definition: v8globals.h:44
const uint64_t kLastNonNaNInt64
Definition: v8globals.h:475
const intptr_t kPointerAlignment
Definition: v8globals.h:48
const int kObjectAlignmentBits
Definition: v8globals.h:43
const int kCodeAlignmentBits
Definition: v8globals.h:57
bool(* ConstraintCallback)(Address new_addr, Address old_addr)
Definition: v8globals.h:244
bool IsDynamicVariableMode(VariableMode mode)
Definition: v8globals.h:511
const int kFailureTag
Definition: v8globals.h:62
const uint32_t kDebugZapValue
Definition: v8globals.h:84
const int kPageSizeBits
Definition: v8globals.h:92
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra code(assertions) for debugging") DEFINE_bool(code_comments
bool IsImmutableVariableMode(VariableMode mode)
Definition: v8globals.h:526
const intptr_t kDoubleAlignment
Definition: v8globals.h:52
const int kCodeZapValue
Definition: v8globals.h:88
#define STATE_TAG_LIST(V)
Definition: v8globals.h:354
bool(* WeakSlotCallback)(Object **pointer)
Definition: v8globals.h:165
const Address kHandleZapValue
Definition: v8globals.h:81
struct v8::internal::IeeeDoubleLittleEndianArchType::@32 bits