Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / v8 / src / v8globals.h
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.
4
5 #ifndef V8_V8GLOBALS_H_
6 #define V8_V8GLOBALS_H_
7
8 #include "globals.h"
9 #include "checks.h"
10
11 namespace v8 {
12 namespace internal {
13
14 // This file contains constants and global declarations related to the
15 // V8 system.
16
17 // Mask for the sign bit in a smi.
18 const intptr_t kSmiSignMask = kIntptrSignBit;
19
20 const int kObjectAlignmentBits = kPointerSizeLog2;
21 const intptr_t kObjectAlignment = 1 << kObjectAlignmentBits;
22 const intptr_t kObjectAlignmentMask = kObjectAlignment - 1;
23
24 // Desired alignment for pointers.
25 const intptr_t kPointerAlignment = (1 << kPointerSizeLog2);
26 const intptr_t kPointerAlignmentMask = kPointerAlignment - 1;
27
28 // Desired alignment for double values.
29 const intptr_t kDoubleAlignment = 8;
30 const intptr_t kDoubleAlignmentMask = kDoubleAlignment - 1;
31
32 // Desired alignment for generated code is 32 bytes (to improve cache line
33 // utilization).
34 const int kCodeAlignmentBits = 5;
35 const intptr_t kCodeAlignment = 1 << kCodeAlignmentBits;
36 const intptr_t kCodeAlignmentMask = kCodeAlignment - 1;
37
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;
43
44
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;
59 #else
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;
67 #endif
68
69 const int kCodeZapValue = 0xbadc0de;
70
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;
74
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
79
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);
83
84
85 // -----------------------------------------------------------------------------
86 // Forward declarations for frequently used classes
87
88 class AccessorInfo;
89 class Allocation;
90 class Arguments;
91 class Assembler;
92 class Code;
93 class CodeGenerator;
94 class CodeStub;
95 class Context;
96 class Debug;
97 class Debugger;
98 class DebugInfo;
99 class Descriptor;
100 class DescriptorArray;
101 class TransitionArray;
102 class ExternalReference;
103 class FixedArray;
104 class FunctionTemplateInfo;
105 class MemoryChunk;
106 class SeededNumberDictionary;
107 class UnseededNumberDictionary;
108 class NameDictionary;
109 template <typename T> class MaybeHandle;
110 template <typename T> class Handle;
111 class Heap;
112 class HeapObject;
113 class IC;
114 class InterceptorInfo;
115 class Isolate;
116 class JSReceiver;
117 class JSArray;
118 class JSFunction;
119 class JSObject;
120 class LargeObjectSpace;
121 class LookupResult;
122 class MacroAssembler;
123 class Map;
124 class MapSpace;
125 class MarkCompactCollector;
126 class NewSpace;
127 class Object;
128 class OldSpace;
129 class Foreign;
130 class Scope;
131 class ScopeInfo;
132 class Script;
133 class Smi;
134 template <typename Config, class Allocator = FreeStoreAllocationPolicy>
135     class SplayTree;
136 class String;
137 class Name;
138 class Struct;
139 class Variable;
140 class RelocInfo;
141 class Deserializer;
142 class MessageLocation;
143 class VirtualMemory;
144 class Mutex;
145 class RecursiveMutex;
146
147 typedef bool (*WeakSlotCallback)(Object** pointer);
148
149 typedef bool (*WeakSlotCallbackWithHeap)(Heap* heap, Object** pointer);
150
151 // -----------------------------------------------------------------------------
152 // Miscellaneous
153
154 // NOTE: SpaceIterator depends on AllocationSpace enumeration values being
155 // consecutive.
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.
166
167   FIRST_SPACE = NEW_SPACE,
168   LAST_SPACE = LO_SPACE,
169   FIRST_PAGED_SPACE = OLD_POINTER_SPACE,
170   LAST_PAGED_SPACE = PROPERTY_CELL_SPACE
171 };
172 const int kSpaceTagSize = 3;
173 const int kSpaceTagMask = (1 << kSpaceTagSize) - 1;
174
175
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
179 // allows).
180 enum PretenureFlag { NOT_TENURED, TENURED };
181
182 enum MinimumCapacity {
183   USE_DEFAULT_MINIMUM_CAPACITY,
184   USE_CUSTOM_MINIMUM_CAPACITY
185 };
186
187 enum GarbageCollector { SCAVENGER, MARK_COMPACTOR };
188
189 enum Executability { NOT_EXECUTABLE, EXECUTABLE };
190
191 enum VisitMode {
192   VISIT_ALL,
193   VISIT_ALL_IN_SCAVENGE,
194   VISIT_ALL_IN_SWEEP_NEWSPACE,
195   VISIT_ONLY_STRONG
196 };
197
198 // Flag indicating whether code is built into the VM (one of the natives files).
199 enum NativesFlag { NOT_NATIVES_CODE, NATIVES_CODE };
200
201
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.
206 //
207 //  |<--------------- buffer_size ---------------->|
208 //  |<-- instr_size -->|        |<-- reloc_size -->|
209 //  +==================+========+==================+
210 //  |   instructions   |  free  |    reloc info    |
211 //  +==================+========+==================+
212 //  ^
213 //  |
214 //  buffer
215
216 struct CodeDesc {
217   byte* buffer;
218   int buffer_size;
219   int instr_size;
220   int reloc_size;
221   Assembler* origin;
222 };
223
224
225 // Callback function used for iterating objects in heap spaces,
226 // for example, scanning heap objects.
227 typedef int (*HeapObjectCallback)(HeapObject* obj);
228
229
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);
234
235
236 // Callback function on inline caches, used for iterating over inline caches
237 // in compiled code.
238 typedef void (*InlineCacheCallback)(Code* code, Address ic);
239
240
241 // State for inline cache call sites. Aliased as IC::State.
242 enum InlineCacheState {
243   // Has never been executed.
244   UNINITIALIZED,
245   // Has been executed but monomorhic state has been delayed.
246   PREMONOMORPHIC,
247   // Has been executed and only one receiver type has been seen.
248   MONOMORPHIC,
249   // Like MONOMORPHIC but check failed due to prototype.
250   MONOMORPHIC_PROTOTYPE_FAILURE,
251   // Multiple receiver types have been seen.
252   POLYMORPHIC,
253   // Many receiver types have been seen.
254   MEGAMORPHIC,
255   // A generic handler is installed and no extra typefeedback is recorded.
256   GENERIC,
257   // Special state for debug break or step in prepare stubs.
258   DEBUG_STUB
259 };
260
261
262 enum CallFunctionFlags {
263   NO_CALL_FUNCTION_FLAGS,
264   CALL_AS_METHOD,
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.
267   WRAP_AND_CALL
268 };
269
270
271 enum CallConstructorFlags {
272   NO_CALL_CONSTRUCTOR_FLAGS,
273   // The call target is cached in the instruction stream.
274   RECORD_CONSTRUCTOR_TARGET
275 };
276
277
278 enum InlineCacheHolderFlag {
279   OWN_MAP,  // For fast properties objects.
280   PROTOTYPE_MAP  // For slow properties objects (except GlobalObjects).
281 };
282
283
284 // The Store Buffer (GC).
285 typedef enum {
286   kStoreBufferFullEvent,
287   kStoreBufferStartScanningPagesEvent,
288   kStoreBufferScanningPageEvent
289 } StoreBufferEvent;
290
291
292 typedef void (*StoreBufferCallback)(Heap* heap,
293                                     MemoryChunk* page,
294                                     StoreBufferEvent event);
295
296
297 // Union used for fast testing of specific double values.
298 union DoubleRepresentation {
299   double  value;
300   int64_t bits;
301   DoubleRepresentation(double x) { value = x; }
302   bool operator==(const DoubleRepresentation& other) const {
303     return bits == other.bits;
304   }
305 };
306
307
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 {
312   double d;
313   struct {
314     unsigned int man_low  :32;
315     unsigned int man_high :20;
316     unsigned int exp      :11;
317     unsigned int sign     :1;
318   } bits;
319 };
320
321
322 union IeeeDoubleBigEndianArchType {
323   double d;
324   struct {
325     unsigned int sign     :1;
326     unsigned int exp      :11;
327     unsigned int man_high :20;
328     unsigned int man_low  :32;
329   } bits;
330 };
331
332
333 // AccessorCallback
334 struct AccessorDescriptor {
335   Object* (*getter)(Isolate* isolate, Object* object, void* data);
336   Object* (*setter)(
337       Isolate* isolate, JSObject* object, Object* value, void* data);
338   void* data;
339 };
340
341
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
346 // stack.
347
348 enum StateTag {
349   JS,
350   GC,
351   COMPILER,
352   OTHER,
353   EXTERNAL,
354   IDLE
355 };
356
357
358 // -----------------------------------------------------------------------------
359 // Macros
360
361 // Testers for test.
362
363 #define HAS_SMI_TAG(value) \
364   ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag)
365
366 #define HAS_FAILURE_TAG(value) \
367   ((reinterpret_cast<intptr_t>(value) & kFailureTagMask) == kFailureTag)
368
369 // OBJECT_POINTER_ALIGN returns the value aligned as a HeapObject pointer
370 #define OBJECT_POINTER_ALIGN(value)                             \
371   (((value) + kObjectAlignmentMask) & ~kObjectAlignmentMask)
372
373 // POINTER_SIZE_ALIGN returns the value aligned as a pointer.
374 #define POINTER_SIZE_ALIGN(value)                               \
375   (((value) + kPointerAlignmentMask) & ~kPointerAlignmentMask)
376
377 // CODE_POINTER_ALIGN returns the value aligned as a generated code segment.
378 #define CODE_POINTER_ALIGN(value)                               \
379   (((value) + kCodeAlignmentMask) & ~kCodeAlignmentMask)
380
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
383 // performed.
384 // This file (globals.h) is included before log.h, so we use direct calls to
385 // the Logger rather than the LOG macro.
386 #ifdef DEBUG
387 #define TRACK_MEMORY(name) \
388   void* operator new(size_t size) { \
389     void* result = ::operator new(size); \
390     Logger::NewEventStatic(name, result, size); \
391     return result; \
392   } \
393   void operator delete(void* object) { \
394     Logger::DeleteEventStatic(name, object); \
395     ::operator delete(object); \
396   }
397 #else
398 #define TRACK_MEMORY(name)
399 #endif
400
401
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
406                   SSE2 = 26,   // x86
407                   CMOV = 15,   // x86
408                   VFP3 = 1,    // ARM
409                   ARMv7 = 2,   // ARM
410                   SUDIV = 3,   // ARM
411                   UNALIGNED_ACCESSES = 4,  // ARM
412                   MOVW_MOVT_IMMEDIATE_LOADS = 5,  // ARM
413                   VFP32DREGS = 6,  // ARM
414                   NEON = 7,    // ARM
415                   SAHF = 0,    // x86
416                   FPU = 1};    // MIPS
417
418
419 // Used to specify if a macro instruction must perform a smi check on tagged
420 // values.
421 enum SmiCheckType {
422   DONT_DO_SMI_CHECK,
423   DO_SMI_CHECK
424 };
425
426
427 enum ScopeType {
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.
435 };
436
437
438 const uint32_t kHoleNanUpper32 = 0x7FFFFFFF;
439 const uint32_t kHoleNanLower32 = 0xFFFFFFFF;
440 const uint32_t kNaNOrInfinityLowerBoundUpper32 = 0x7FF00000;
441
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);
446
447
448 // The order of this enum has to be kept in sync with the predicates below.
449 enum VariableMode {
450   // User declared variables:
451   VAR,             // declared via 'var', and 'function' declarations
452
453   CONST_LEGACY,    // declared via legacy 'const' declarations
454
455   LET,             // declared via 'let' declarations (first lexical)
456
457   CONST,           // declared via 'const' declarations
458
459   MODULE,          // declared via 'module' declaration (last lexical)
460
461   // Variables introduced by the compiler:
462   INTERNAL,        // like VAR, but not user-visible (may or may not
463                    // be in a context)
464
465   TEMPORARY,       // temporary variables (not user-visible), stack-allocated
466                    // unless the scope as a whole has forced context allocation
467
468   DYNAMIC,         // always require dynamic lookup (we don't know
469                    // the declaration)
470
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
474
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
478                    // variable
479 };
480
481
482 inline bool IsDynamicVariableMode(VariableMode mode) {
483   return mode >= DYNAMIC && mode <= DYNAMIC_LOCAL;
484 }
485
486
487 inline bool IsDeclaredVariableMode(VariableMode mode) {
488   return mode >= VAR && mode <= MODULE;
489 }
490
491
492 inline bool IsLexicalVariableMode(VariableMode mode) {
493   return mode >= LET && mode <= MODULE;
494 }
495
496
497 inline bool IsImmutableVariableMode(VariableMode mode) {
498   return (mode >= CONST && mode <= MODULE) || mode == CONST_LEGACY;
499 }
500
501
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.
509 //      var foo;
510 // 2. A local variable introduced by a function declaration.
511 //      function foo() {}
512 // 3. Parameters
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.
520 //
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
528 // initialization.
529 //
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,
535   kCreatedInitialized
536 };
537
538
539 enum ClearExceptionFlag {
540   KEEP_EXCEPTION,
541   CLEAR_EXCEPTION
542 };
543
544
545 enum MinusZeroMode {
546   TREAT_MINUS_ZERO_AS_ZERO,
547   FAIL_ON_MINUS_ZERO
548 };
549
550 } }  // namespace v8::internal
551
552 namespace i = v8::internal;
553
554 #endif  // V8_V8GLOBALS_H_