Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / v8 / src / v8globals.h
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
43 const int kObjectAlignmentBits = kPointerSizeLog2;
44 const intptr_t kObjectAlignment = 1 << kObjectAlignmentBits;
45 const intptr_t kObjectAlignmentMask = kObjectAlignment - 1;
46
47 // Desired alignment for pointers.
48 const intptr_t kPointerAlignment = (1 << kPointerSizeLog2);
49 const intptr_t kPointerAlignmentMask = kPointerAlignment - 1;
50
51 // Desired alignment for double values.
52 const intptr_t kDoubleAlignment = 8;
53 const intptr_t kDoubleAlignmentMask = kDoubleAlignment - 1;
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));
72 const Address kHandleZapValue =
73     reinterpret_cast<Address>(V8_UINT64_C(0x1baddead0baddeaf));
74 const Address kGlobalHandleZapValue =
75     reinterpret_cast<Address>(V8_UINT64_C(0x1baffed00baffedf));
76 const Address kFromSpaceZapValue =
77     reinterpret_cast<Address>(V8_UINT64_C(0x1beefdad0beefdaf));
78 const uint64_t kDebugZapValue = V8_UINT64_C(0xbadbaddbbadbaddb);
79 const uint64_t kSlotsZapValue = V8_UINT64_C(0xbeefdeadbeefdeef);
80 const uint64_t kFreeListZapValue = 0xfeed1eaffeed1eaf;
81 #else
82 const Address kZapValue = reinterpret_cast<Address>(0xdeadbeef);
83 const Address kHandleZapValue = reinterpret_cast<Address>(0xbaddeaf);
84 const Address kGlobalHandleZapValue = reinterpret_cast<Address>(0xbaffedf);
85 const Address kFromSpaceZapValue = reinterpret_cast<Address>(0xbeefdaf);
86 const uint32_t kSlotsZapValue = 0xbeefdeef;
87 const uint32_t kDebugZapValue = 0xbadbaddb;
88 const uint32_t kFreeListZapValue = 0xfeed1eaf;
89 #endif
90
91 const int kCodeZapValue = 0xbadc0de;
92
93 // Number of bits to represent the page size for paged spaces. The value of 20
94 // gives 1Mb bytes per page.
95 const int kPageSizeBits = 20;
96
97 // On Intel architecture, cache line size is 64 bytes.
98 // On ARM it may be less (32 bytes), but as far this constant is
99 // used for aligning data, it doesn't hurt to align on a greater value.
100 #define PROCESSOR_CACHE_LINE_SIZE 64
101
102 // Constants relevant to double precision floating point numbers.
103 // If looking only at the top 32 bits, the QNaN mask is bits 19 to 30.
104 const uint32_t kQuietNaNHighBitsMask = 0xfff << (51 - 32);
105
106
107 // -----------------------------------------------------------------------------
108 // Forward declarations for frequently used classes
109
110 class AccessorInfo;
111 class Allocation;
112 class Arguments;
113 class Assembler;
114 class Code;
115 class CodeGenerator;
116 class CodeStub;
117 class Context;
118 class Debug;
119 class Debugger;
120 class DebugInfo;
121 class Descriptor;
122 class DescriptorArray;
123 class TransitionArray;
124 class ExternalReference;
125 class FixedArray;
126 class FunctionTemplateInfo;
127 class MemoryChunk;
128 class SeededNumberDictionary;
129 class UnseededNumberDictionary;
130 class NameDictionary;
131 template <typename T> class Handle;
132 class Heap;
133 class HeapObject;
134 class IC;
135 class InterceptorInfo;
136 class JSReceiver;
137 class JSArray;
138 class JSFunction;
139 class JSObject;
140 class LargeObjectSpace;
141 class LookupResult;
142 class MacroAssembler;
143 class Map;
144 class MapSpace;
145 class MarkCompactCollector;
146 class NewSpace;
147 class Object;
148 class MaybeObject;
149 class OldSpace;
150 class Foreign;
151 class Scope;
152 class ScopeInfo;
153 class Script;
154 class Smi;
155 template <typename Config, class Allocator = FreeStoreAllocationPolicy>
156     class SplayTree;
157 class String;
158 class Name;
159 class Struct;
160 class Variable;
161 class RelocInfo;
162 class Deserializer;
163 class MessageLocation;
164 class VirtualMemory;
165 class Mutex;
166 class RecursiveMutex;
167
168 typedef bool (*WeakSlotCallback)(Object** pointer);
169
170 typedef bool (*WeakSlotCallbackWithHeap)(Heap* heap, Object** pointer);
171
172 // -----------------------------------------------------------------------------
173 // Miscellaneous
174
175 // NOTE: SpaceIterator depends on AllocationSpace enumeration values being
176 // consecutive.
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   PROPERTY_CELL_SPACE,  // Only and all global property cell objects.
185   LO_SPACE,             // Promoted large objects.
186
187   FIRST_SPACE = NEW_SPACE,
188   LAST_SPACE = LO_SPACE,
189   FIRST_PAGED_SPACE = OLD_POINTER_SPACE,
190   LAST_PAGED_SPACE = PROPERTY_CELL_SPACE
191 };
192 const int kSpaceTagSize = 3;
193 const int kSpaceTagMask = (1 << kSpaceTagSize) - 1;
194
195
196 // A flag that indicates whether objects should be pretenured when
197 // allocated (allocated directly into the old generation) or not
198 // (allocated in the young generation if the object size and type
199 // allows).
200 enum PretenureFlag { NOT_TENURED, TENURED };
201
202 enum MinimumCapacity {
203   USE_DEFAULT_MINIMUM_CAPACITY,
204   USE_CUSTOM_MINIMUM_CAPACITY
205 };
206
207 enum GarbageCollector { SCAVENGER, MARK_COMPACTOR };
208
209 enum Executability { NOT_EXECUTABLE, EXECUTABLE };
210
211 enum VisitMode {
212   VISIT_ALL,
213   VISIT_ALL_IN_SCAVENGE,
214   VISIT_ALL_IN_SWEEP_NEWSPACE,
215   VISIT_ONLY_STRONG
216 };
217
218 // Flag indicating whether code is built into the VM (one of the natives files).
219 enum NativesFlag { NOT_NATIVES_CODE, NATIVES_CODE };
220
221
222 // A CodeDesc describes a buffer holding instructions and relocation
223 // information. The instructions start at the beginning of the buffer
224 // and grow forward, the relocation information starts at the end of
225 // the buffer and grows backward.
226 //
227 //  |<--------------- buffer_size ---------------->|
228 //  |<-- instr_size -->|        |<-- reloc_size -->|
229 //  +==================+========+==================+
230 //  |   instructions   |  free  |    reloc info    |
231 //  +==================+========+==================+
232 //  ^
233 //  |
234 //  buffer
235
236 struct CodeDesc {
237   byte* buffer;
238   int buffer_size;
239   int instr_size;
240   int reloc_size;
241   Assembler* origin;
242 };
243
244
245 // Callback function used for iterating objects in heap spaces,
246 // for example, scanning heap objects.
247 typedef int (*HeapObjectCallback)(HeapObject* obj);
248
249
250 // Callback function used for checking constraints when copying/relocating
251 // objects. Returns true if an object can be copied/relocated from its
252 // old_addr to a new_addr.
253 typedef bool (*ConstraintCallback)(Address new_addr, Address old_addr);
254
255
256 // Callback function on inline caches, used for iterating over inline caches
257 // in compiled code.
258 typedef void (*InlineCacheCallback)(Code* code, Address ic);
259
260
261 // State for inline cache call sites. Aliased as IC::State.
262 enum InlineCacheState {
263   // Has never been executed.
264   UNINITIALIZED,
265   // Has been executed but monomorhic state has been delayed.
266   PREMONOMORPHIC,
267   // Has been executed and only one receiver type has been seen.
268   MONOMORPHIC,
269   // Like MONOMORPHIC but check failed due to prototype.
270   MONOMORPHIC_PROTOTYPE_FAILURE,
271   // Multiple receiver types have been seen.
272   POLYMORPHIC,
273   // Many receiver types have been seen.
274   MEGAMORPHIC,
275   // A generic handler is installed and no extra typefeedback is recorded.
276   GENERIC,
277   // Special state for debug break or step in prepare stubs.
278   DEBUG_STUB
279 };
280
281
282 enum CallFunctionFlags {
283   NO_CALL_FUNCTION_FLAGS,
284   // The call target is cached in the instruction stream.
285   RECORD_CALL_TARGET,
286   CALL_AS_METHOD,
287   // Always wrap the receiver and call to the JSFunction. Only use this flag
288   // both the receiver type and the target method are statically known.
289   WRAP_AND_CALL
290 };
291
292
293 enum InlineCacheHolderFlag {
294   OWN_MAP,  // For fast properties objects.
295   PROTOTYPE_MAP  // For slow properties objects (except GlobalObjects).
296 };
297
298
299 // The Store Buffer (GC).
300 typedef enum {
301   kStoreBufferFullEvent,
302   kStoreBufferStartScanningPagesEvent,
303   kStoreBufferScanningPageEvent
304 } StoreBufferEvent;
305
306
307 typedef void (*StoreBufferCallback)(Heap* heap,
308                                     MemoryChunk* page,
309                                     StoreBufferEvent event);
310
311
312 // Union used for fast testing of specific double values.
313 union DoubleRepresentation {
314   double  value;
315   int64_t bits;
316   DoubleRepresentation(double x) { value = x; }
317   bool operator==(const DoubleRepresentation& other) const {
318     return bits == other.bits;
319   }
320 };
321
322
323 // Union used for customized checking of the IEEE double types
324 // inlined within v8 runtime, rather than going to the underlying
325 // platform headers and libraries
326 union IeeeDoubleLittleEndianArchType {
327   double d;
328   struct {
329     unsigned int man_low  :32;
330     unsigned int man_high :20;
331     unsigned int exp      :11;
332     unsigned int sign     :1;
333   } bits;
334 };
335
336
337 union IeeeDoubleBigEndianArchType {
338   double d;
339   struct {
340     unsigned int sign     :1;
341     unsigned int exp      :11;
342     unsigned int man_high :20;
343     unsigned int man_low  :32;
344   } bits;
345 };
346
347
348 // AccessorCallback
349 struct AccessorDescriptor {
350   MaybeObject* (*getter)(Isolate* isolate, Object* object, void* data);
351   MaybeObject* (*setter)(
352       Isolate* isolate, JSObject* object, Object* value, void* data);
353   void* data;
354 };
355
356
357 // Logging and profiling.  A StateTag represents a possible state of
358 // the VM. The logger maintains a stack of these. Creating a VMState
359 // object enters a state by pushing on the stack, and destroying a
360 // VMState object leaves a state by popping the current state from the
361 // stack.
362
363 enum StateTag {
364   JS,
365   GC,
366   COMPILER,
367   OTHER,
368   EXTERNAL,
369   IDLE
370 };
371
372
373 // -----------------------------------------------------------------------------
374 // Macros
375
376 // Testers for test.
377
378 #define HAS_SMI_TAG(value) \
379   ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag)
380
381 #define HAS_FAILURE_TAG(value) \
382   ((reinterpret_cast<intptr_t>(value) & kFailureTagMask) == kFailureTag)
383
384 // OBJECT_POINTER_ALIGN returns the value aligned as a HeapObject pointer
385 #define OBJECT_POINTER_ALIGN(value)                             \
386   (((value) + kObjectAlignmentMask) & ~kObjectAlignmentMask)
387
388 // POINTER_SIZE_ALIGN returns the value aligned as a pointer.
389 #define POINTER_SIZE_ALIGN(value)                               \
390   (((value) + kPointerAlignmentMask) & ~kPointerAlignmentMask)
391
392 // CODE_POINTER_ALIGN returns the value aligned as a generated code segment.
393 #define CODE_POINTER_ALIGN(value)                               \
394   (((value) + kCodeAlignmentMask) & ~kCodeAlignmentMask)
395
396 // Support for tracking C++ memory allocation.  Insert TRACK_MEMORY("Fisk")
397 // inside a C++ class and new and delete will be overloaded so logging is
398 // performed.
399 // This file (globals.h) is included before log.h, so we use direct calls to
400 // the Logger rather than the LOG macro.
401 #ifdef DEBUG
402 #define TRACK_MEMORY(name) \
403   void* operator new(size_t size) { \
404     void* result = ::operator new(size); \
405     Logger::NewEventStatic(name, result, size); \
406     return result; \
407   } \
408   void operator delete(void* object) { \
409     Logger::DeleteEventStatic(name, object); \
410     ::operator delete(object); \
411   }
412 #else
413 #define TRACK_MEMORY(name)
414 #endif
415
416
417 // Feature flags bit positions. They are mostly based on the CPUID spec.
418 // On X86/X64, values below 32 are bits in EDX, values above 32 are bits in ECX.
419 enum CpuFeature { SSE4_1 = 32 + 19,  // x86
420                   SSE3 = 32 + 0,     // x86
421                   SSE2 = 26,   // x86
422                   CMOV = 15,   // x86
423                   VFP3 = 1,    // ARM
424                   ARMv7 = 2,   // ARM
425                   SUDIV = 3,   // ARM
426                   UNALIGNED_ACCESSES = 4,  // ARM
427                   MOVW_MOVT_IMMEDIATE_LOADS = 5,  // ARM
428                   VFP32DREGS = 6,  // ARM
429                   NEON = 7,    // ARM
430                   SAHF = 0,    // x86
431                   FPU = 1};    // MIPS
432
433
434 // Used to specify if a macro instruction must perform a smi check on tagged
435 // values.
436 enum SmiCheckType {
437   DONT_DO_SMI_CHECK,
438   DO_SMI_CHECK
439 };
440
441
442 enum ScopeType {
443   EVAL_SCOPE,      // The top-level scope for an eval source.
444   FUNCTION_SCOPE,  // The top-level scope for a function.
445   MODULE_SCOPE,    // The scope introduced by a module literal
446   GLOBAL_SCOPE,    // The top-level scope for a program or a top-level eval.
447   CATCH_SCOPE,     // The scope introduced by catch.
448   BLOCK_SCOPE,     // The scope introduced by a new block.
449   WITH_SCOPE       // The scope introduced by with.
450 };
451
452
453 const uint32_t kHoleNanUpper32 = 0x7FFFFFFF;
454 const uint32_t kHoleNanLower32 = 0xFFFFFFFF;
455 const uint32_t kNaNOrInfinityLowerBoundUpper32 = 0x7FF00000;
456
457 const uint64_t kHoleNanInt64 =
458     (static_cast<uint64_t>(kHoleNanUpper32) << 32) | kHoleNanLower32;
459 const uint64_t kLastNonNaNInt64 =
460     (static_cast<uint64_t>(kNaNOrInfinityLowerBoundUpper32) << 32);
461
462
463 // The order of this enum has to be kept in sync with the predicates below.
464 enum VariableMode {
465   // User declared variables:
466   VAR,             // declared via 'var', and 'function' declarations
467
468   CONST,           // declared via 'const' declarations
469
470   LET,             // declared via 'let' declarations (first lexical)
471
472   CONST_HARMONY,   // declared via 'const' declarations in harmony mode
473
474   MODULE,          // declared via 'module' declaration (last lexical)
475
476   // Variables introduced by the compiler:
477   INTERNAL,        // like VAR, but not user-visible (may or may not
478                    // be in a context)
479
480   TEMPORARY,       // temporary variables (not user-visible), stack-allocated
481                    // unless the scope as a whole has forced context allocation
482
483   DYNAMIC,         // always require dynamic lookup (we don't know
484                    // the declaration)
485
486   DYNAMIC_GLOBAL,  // requires dynamic lookup, but we know that the
487                    // variable is global unless it has been shadowed
488                    // by an eval-introduced variable
489
490   DYNAMIC_LOCAL    // requires dynamic lookup, but we know that the
491                    // variable is local and where it is unless it
492                    // has been shadowed by an eval-introduced
493                    // variable
494 };
495
496
497 inline bool IsDynamicVariableMode(VariableMode mode) {
498   return mode >= DYNAMIC && mode <= DYNAMIC_LOCAL;
499 }
500
501
502 inline bool IsDeclaredVariableMode(VariableMode mode) {
503   return mode >= VAR && mode <= MODULE;
504 }
505
506
507 inline bool IsLexicalVariableMode(VariableMode mode) {
508   return mode >= LET && mode <= MODULE;
509 }
510
511
512 inline bool IsImmutableVariableMode(VariableMode mode) {
513   return mode == CONST || (mode >= CONST_HARMONY && mode <= MODULE);
514 }
515
516
517 // ES6 Draft Rev3 10.2 specifies declarative environment records with mutable
518 // and immutable bindings that can be in two states: initialized and
519 // uninitialized. In ES5 only immutable bindings have these two states. When
520 // accessing a binding, it needs to be checked for initialization. However in
521 // the following cases the binding is initialized immediately after creation
522 // so the initialization check can always be skipped:
523 // 1. Var declared local variables.
524 //      var foo;
525 // 2. A local variable introduced by a function declaration.
526 //      function foo() {}
527 // 3. Parameters
528 //      function x(foo) {}
529 // 4. Catch bound variables.
530 //      try {} catch (foo) {}
531 // 6. Function variables of named function expressions.
532 //      var x = function foo() {}
533 // 7. Implicit binding of 'this'.
534 // 8. Implicit binding of 'arguments' in functions.
535 //
536 // ES5 specified object environment records which are introduced by ES elements
537 // such as Program and WithStatement that associate identifier bindings with the
538 // properties of some object. In the specification only mutable bindings exist
539 // (which may be non-writable) and have no distinct initialization step. However
540 // V8 allows const declarations in global code with distinct creation and
541 // initialization steps which are represented by non-writable properties in the
542 // global object. As a result also these bindings need to be checked for
543 // initialization.
544 //
545 // The following enum specifies a flag that indicates if the binding needs a
546 // distinct initialization step (kNeedsInitialization) or if the binding is
547 // immediately initialized upon creation (kCreatedInitialized).
548 enum InitializationFlag {
549   kNeedsInitialization,
550   kCreatedInitialized
551 };
552
553
554 enum ClearExceptionFlag {
555   KEEP_EXCEPTION,
556   CLEAR_EXCEPTION
557 };
558
559
560 enum MinusZeroMode {
561   TREAT_MINUS_ZERO_AS_ZERO,
562   FAIL_ON_MINUS_ZERO
563 };
564
565 } }  // namespace v8::internal
566
567 #endif  // V8_V8GLOBALS_H_