[V8] Introduce a QML compilation mode
[profile/ivi/qtjsbackend.git] / src / 3rdparty / 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 maps.
56 #if V8_HOST_ARCH_64_BIT
57 const intptr_t kMapAlignmentBits = kObjectAlignmentBits;
58 #else
59 const intptr_t kMapAlignmentBits = kObjectAlignmentBits + 3;
60 #endif
61 const intptr_t kMapAlignment = (1 << kMapAlignmentBits);
62 const intptr_t kMapAlignmentMask = kMapAlignment - 1;
63
64 // Desired alignment for generated code is 32 bytes (to improve cache line
65 // utilization).
66 const int kCodeAlignmentBits = 5;
67 const intptr_t kCodeAlignment = 1 << kCodeAlignmentBits;
68 const intptr_t kCodeAlignmentMask = kCodeAlignment - 1;
69
70 // Tag information for Failure.
71 const int kFailureTag = 3;
72 const int kFailureTagSize = 2;
73 const intptr_t kFailureTagMask = (1 << kFailureTagSize) - 1;
74
75
76 // Zap-value: The value used for zapping dead objects.
77 // Should be a recognizable hex value tagged as a failure.
78 #ifdef V8_HOST_ARCH_64_BIT
79 const Address kZapValue =
80     reinterpret_cast<Address>(V8_UINT64_C(0xdeadbeedbeadbeef));
81 const Address kHandleZapValue =
82     reinterpret_cast<Address>(V8_UINT64_C(0x1baddead0baddeaf));
83 const Address kFromSpaceZapValue =
84     reinterpret_cast<Address>(V8_UINT64_C(0x1beefdad0beefdaf));
85 const uint64_t kDebugZapValue = V8_UINT64_C(0xbadbaddbbadbaddb);
86 const uint64_t kSlotsZapValue = V8_UINT64_C(0xbeefdeadbeefdeef);
87 const uint64_t kFreeListZapValue = 0xfeed1eaffeed1eaf;
88 #else
89 const Address kZapValue = reinterpret_cast<Address>(0xdeadbeef);
90 const Address kHandleZapValue = reinterpret_cast<Address>(0xbaddeaf);
91 const Address kFromSpaceZapValue = reinterpret_cast<Address>(0xbeefdaf);
92 const uint32_t kSlotsZapValue = 0xbeefdeef;
93 const uint32_t kDebugZapValue = 0xbadbaddb;
94 const uint32_t kFreeListZapValue = 0xfeed1eaf;
95 #endif
96
97
98 // Number of bits to represent the page size for paged spaces. The value of 20
99 // gives 1Mb bytes per page.
100 const int kPageSizeBits = 20;
101
102 // On Intel architecture, cache line size is 64 bytes.
103 // On ARM it may be less (32 bytes), but as far this constant is
104 // used for aligning data, it doesn't hurt to align on a greater value.
105 const int kProcessorCacheLineSize = 64;
106
107 // Constants relevant to double precision floating point numbers.
108 // If looking only at the top 32 bits, the QNaN mask is bits 19 to 30.
109 const uint32_t kQuietNaNHighBitsMask = 0xfff << (51 - 32);
110
111
112 // -----------------------------------------------------------------------------
113 // Forward declarations for frequently used classes
114
115 class AccessorInfo;
116 class Allocation;
117 class Arguments;
118 class Assembler;
119 class AssertNoAllocation;
120 class Code;
121 class CodeGenerator;
122 class CodeStub;
123 class Context;
124 class Debug;
125 class Debugger;
126 class DebugInfo;
127 class Descriptor;
128 class DescriptorArray;
129 class ExternalReference;
130 class FixedArray;
131 class FunctionTemplateInfo;
132 class MemoryChunk;
133 class SeededNumberDictionary;
134 class UnseededNumberDictionary;
135 class StringDictionary;
136 template <typename T> class Handle;
137 class Heap;
138 class HeapObject;
139 class IC;
140 class InterceptorInfo;
141 class JSArray;
142 class JSFunction;
143 class JSObject;
144 class LargeObjectSpace;
145 class LookupResult;
146 class MacroAssembler;
147 class Map;
148 class MapSpace;
149 class MarkCompactCollector;
150 class NewSpace;
151 class Object;
152 class MaybeObject;
153 class OldSpace;
154 class Foreign;
155 class Scope;
156 class ScopeInfo;
157 class Script;
158 class Smi;
159 template <typename Config, class Allocator = FreeStoreAllocationPolicy>
160     class SplayTree;
161 class String;
162 class Struct;
163 class Variable;
164 class RelocInfo;
165 class Deserializer;
166 class MessageLocation;
167 class ObjectGroup;
168 class TickSample;
169 class VirtualMemory;
170 class Mutex;
171
172 typedef bool (*WeakSlotCallback)(Object** pointer);
173
174 typedef bool (*WeakSlotCallbackWithHeap)(Heap* heap, Object** pointer);
175
176 // -----------------------------------------------------------------------------
177 // Miscellaneous
178
179 // NOTE: SpaceIterator depends on AllocationSpace enumeration values being
180 // consecutive.
181 enum AllocationSpace {
182   NEW_SPACE,            // Semispaces collected with copying collector.
183   OLD_POINTER_SPACE,    // May contain pointers to new space.
184   OLD_DATA_SPACE,       // Must not have pointers to new space.
185   CODE_SPACE,           // No pointers to new space, marked executable.
186   MAP_SPACE,            // Only and all map objects.
187   CELL_SPACE,           // Only and all cell objects.
188   LO_SPACE,             // Promoted large objects.
189
190   FIRST_SPACE = NEW_SPACE,
191   LAST_SPACE = LO_SPACE,
192   FIRST_PAGED_SPACE = OLD_POINTER_SPACE,
193   LAST_PAGED_SPACE = CELL_SPACE
194 };
195 const int kSpaceTagSize = 3;
196 const int kSpaceTagMask = (1 << kSpaceTagSize) - 1;
197
198
199 // A flag that indicates whether objects should be pretenured when
200 // allocated (allocated directly into the old generation) or not
201 // (allocated in the young generation if the object size and type
202 // allows).
203 enum PretenureFlag { NOT_TENURED, TENURED };
204
205 enum GarbageCollector { SCAVENGER, MARK_COMPACTOR };
206
207 enum Executability { NOT_EXECUTABLE, EXECUTABLE };
208
209 enum VisitMode {
210   VISIT_ALL,
211   VISIT_ALL_IN_SCAVENGE,
212   VISIT_ALL_IN_SWEEP_NEWSPACE,
213   VISIT_ONLY_STRONG
214 };
215
216 // Flag indicating whether code is built into the VM (one of the natives files).
217 enum NativesFlag { NOT_NATIVES_CODE, NATIVES_CODE };
218
219
220 // A CodeDesc describes a buffer holding instructions and relocation
221 // information. The instructions start at the beginning of the buffer
222 // and grow forward, the relocation information starts at the end of
223 // the buffer and grows backward.
224 //
225 //  |<--------------- buffer_size ---------------->|
226 //  |<-- instr_size -->|        |<-- reloc_size -->|
227 //  +==================+========+==================+
228 //  |   instructions   |  free  |    reloc info    |
229 //  +==================+========+==================+
230 //  ^
231 //  |
232 //  buffer
233
234 struct CodeDesc {
235   byte* buffer;
236   int buffer_size;
237   int instr_size;
238   int reloc_size;
239   Assembler* origin;
240 };
241
242
243 // Callback function used for iterating objects in heap spaces,
244 // for example, scanning heap objects.
245 typedef int (*HeapObjectCallback)(HeapObject* obj);
246
247
248 // Callback function used for checking constraints when copying/relocating
249 // objects. Returns true if an object can be copied/relocated from its
250 // old_addr to a new_addr.
251 typedef bool (*ConstraintCallback)(Address new_addr, Address old_addr);
252
253
254 // Callback function on inline caches, used for iterating over inline caches
255 // in compiled code.
256 typedef void (*InlineCacheCallback)(Code* code, Address ic);
257
258
259 // State for inline cache call sites. Aliased as IC::State.
260 enum InlineCacheState {
261   // Has never been executed.
262   UNINITIALIZED,
263   // Has been executed but monomorhic state has been delayed.
264   PREMONOMORPHIC,
265   // Has been executed and only one receiver type has been seen.
266   MONOMORPHIC,
267   // Like MONOMORPHIC but check failed due to prototype.
268   MONOMORPHIC_PROTOTYPE_FAILURE,
269   // Multiple receiver types have been seen.
270   MEGAMORPHIC,
271   // Special states for debug break or step in prepare stubs.
272   DEBUG_BREAK,
273   DEBUG_PREPARE_STEP_IN
274 };
275
276
277 enum CheckType {
278   RECEIVER_MAP_CHECK,
279   STRING_CHECK,
280   NUMBER_CHECK,
281   BOOLEAN_CHECK
282 };
283
284
285 enum CallFunctionFlags {
286   NO_CALL_FUNCTION_FLAGS = 0,
287   // Receiver might implicitly be the global objects. If it is, the
288   // hole is passed to the call function stub.
289   RECEIVER_MIGHT_BE_IMPLICIT = 1 << 0,
290   // The call target is cached in the instruction stream.
291   RECORD_CALL_TARGET = 1 << 1
292 };
293
294
295 enum InlineCacheHolderFlag {
296   OWN_MAP,  // For fast properties objects.
297   PROTOTYPE_MAP  // For slow properties objects (except GlobalObjects).
298 };
299
300
301 // The Store Buffer (GC).
302 typedef enum {
303   kStoreBufferFullEvent,
304   kStoreBufferStartScanningPagesEvent,
305   kStoreBufferScanningPageEvent
306 } StoreBufferEvent;
307
308
309 typedef void (*StoreBufferCallback)(Heap* heap,
310                                     MemoryChunk* page,
311                                     StoreBufferEvent event);
312
313
314 // Whether to remove map transitions and constant transitions from a
315 // DescriptorArray.
316 enum TransitionFlag {
317   REMOVE_TRANSITIONS,
318   KEEP_TRANSITIONS
319 };
320
321
322 // Union used for fast testing of specific double values.
323 union DoubleRepresentation {
324   double  value;
325   int64_t bits;
326   DoubleRepresentation(double x) { value = x; }
327 };
328
329
330 // Union used for customized checking of the IEEE double types
331 // inlined within v8 runtime, rather than going to the underlying
332 // platform headers and libraries
333 union IeeeDoubleLittleEndianArchType {
334   double d;
335   struct {
336     unsigned int man_low  :32;
337     unsigned int man_high :20;
338     unsigned int exp      :11;
339     unsigned int sign     :1;
340   } bits;
341 };
342
343
344 union IeeeDoubleBigEndianArchType {
345   double d;
346   struct {
347     unsigned int sign     :1;
348     unsigned int exp      :11;
349     unsigned int man_high :20;
350     unsigned int man_low  :32;
351   } bits;
352 };
353
354
355 // AccessorCallback
356 struct AccessorDescriptor {
357   MaybeObject* (*getter)(Object* object, void* data);
358   MaybeObject* (*setter)(JSObject* object, Object* value, void* data);
359   void* data;
360 };
361
362
363 // Logging and profiling.  A StateTag represents a possible state of
364 // the VM. The logger maintains a stack of these. Creating a VMState
365 // object enters a state by pushing on the stack, and destroying a
366 // VMState object leaves a state by popping the current state from the
367 // stack.
368
369 #define STATE_TAG_LIST(V) \
370   V(JS)                   \
371   V(GC)                   \
372   V(COMPILER)             \
373   V(OTHER)                \
374   V(EXTERNAL)
375
376 enum StateTag {
377 #define DEF_STATE_TAG(name) name,
378   STATE_TAG_LIST(DEF_STATE_TAG)
379 #undef DEF_STATE_TAG
380   // Pseudo-types.
381   state_tag_count
382 };
383
384
385 // -----------------------------------------------------------------------------
386 // Macros
387
388 // Testers for test.
389
390 #define HAS_SMI_TAG(value) \
391   ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag)
392
393 #define HAS_FAILURE_TAG(value) \
394   ((reinterpret_cast<intptr_t>(value) & kFailureTagMask) == kFailureTag)
395
396 // OBJECT_POINTER_ALIGN returns the value aligned as a HeapObject pointer
397 #define OBJECT_POINTER_ALIGN(value)                             \
398   (((value) + kObjectAlignmentMask) & ~kObjectAlignmentMask)
399
400 // POINTER_SIZE_ALIGN returns the value aligned as a pointer.
401 #define POINTER_SIZE_ALIGN(value)                               \
402   (((value) + kPointerAlignmentMask) & ~kPointerAlignmentMask)
403
404 // MAP_POINTER_ALIGN returns the value aligned as a map pointer.
405 #define MAP_POINTER_ALIGN(value)                                \
406   (((value) + kMapAlignmentMask) & ~kMapAlignmentMask)
407
408 // CODE_POINTER_ALIGN returns the value aligned as a generated code segment.
409 #define CODE_POINTER_ALIGN(value)                               \
410   (((value) + kCodeAlignmentMask) & ~kCodeAlignmentMask)
411
412 // Support for tracking C++ memory allocation.  Insert TRACK_MEMORY("Fisk")
413 // inside a C++ class and new and delete will be overloaded so logging is
414 // performed.
415 // This file (globals.h) is included before log.h, so we use direct calls to
416 // the Logger rather than the LOG macro.
417 #ifdef DEBUG
418 #define TRACK_MEMORY(name) \
419   void* operator new(size_t size) { \
420     void* result = ::operator new(size); \
421     Logger::NewEventStatic(name, result, size); \
422     return result; \
423   } \
424   void operator delete(void* object) { \
425     Logger::DeleteEventStatic(name, object); \
426     ::operator delete(object); \
427   }
428 #else
429 #define TRACK_MEMORY(name)
430 #endif
431
432
433 // Feature flags bit positions. They are mostly based on the CPUID spec.
434 // (We assign CPUID itself to one of the currently reserved bits --
435 // feel free to change this if needed.)
436 // On X86/X64, values below 32 are bits in EDX, values above 32 are bits in ECX.
437 enum CpuFeature { SSE4_1 = 32 + 19,  // x86
438                   SSE3 = 32 + 0,     // x86
439                   SSE2 = 26,   // x86
440                   CMOV = 15,   // x86
441                   RDTSC = 4,   // x86
442                   CPUID = 10,  // x86
443                   VFP3 = 1,    // ARM
444                   ARMv7 = 2,   // ARM
445                   SAHF = 0,    // x86
446                   FPU = 1};    // MIPS
447
448
449 // Used to specify if a macro instruction must perform a smi check on tagged
450 // values.
451 enum SmiCheckType {
452   DONT_DO_SMI_CHECK,
453   DO_SMI_CHECK
454 };
455
456
457 // Used to specify whether a receiver is implicitly or explicitly
458 // provided to a call.
459 enum CallKind {
460   CALL_AS_METHOD,
461   CALL_AS_FUNCTION
462 };
463
464
465 enum ScopeType {
466   EVAL_SCOPE,      // The top-level scope for an eval source.
467   FUNCTION_SCOPE,  // The top-level scope for a function.
468   MODULE_SCOPE,    // The scope introduced by a module literal
469   GLOBAL_SCOPE,    // The top-level scope for a program or a top-level eval.
470   CATCH_SCOPE,     // The scope introduced by catch.
471   BLOCK_SCOPE,     // The scope introduced by a new block.
472   WITH_SCOPE       // The scope introduced by with.
473 };
474
475
476 const uint32_t kHoleNanUpper32 = 0x7FFFFFFF;
477 const uint32_t kHoleNanLower32 = 0xFFFFFFFF;
478 const uint32_t kNaNOrInfinityLowerBoundUpper32 = 0x7FF00000;
479
480 const uint64_t kHoleNanInt64 =
481     (static_cast<uint64_t>(kHoleNanUpper32) << 32) | kHoleNanLower32;
482 const uint64_t kLastNonNaNInt64 =
483     (static_cast<uint64_t>(kNaNOrInfinityLowerBoundUpper32) << 32);
484
485
486 enum VariableMode {
487   // User declared variables:
488   VAR,             // declared via 'var', and 'function' declarations
489
490   CONST,           // declared via 'const' declarations
491
492   CONST_HARMONY,   // declared via 'const' declarations in harmony mode
493
494   LET,             // declared via 'let' declarations
495
496   // Variables introduced by the compiler:
497   DYNAMIC,         // always require dynamic lookup (we don't know
498                    // the declaration)
499
500   DYNAMIC_GLOBAL,  // requires dynamic lookup, but we know that the
501                    // variable is global unless it has been shadowed
502                    // by an eval-introduced variable
503
504   DYNAMIC_LOCAL,   // requires dynamic lookup, but we know that the
505                    // variable is local and where it is unless it
506                    // has been shadowed by an eval-introduced
507                    // variable
508
509   INTERNAL,        // like VAR, but not user-visible (may or may not
510                    // be in a context)
511
512   TEMPORARY        // temporary variables (not user-visible), never
513                    // in a context
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 } }  // namespace v8::internal
561
562 #endif  // V8_V8GLOBALS_H_