• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2010 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 
33 namespace v8 {
34 namespace internal {
35 
36 // This file contains constants and global declarations related to the
37 // V8 system.
38 
39 // Mask for the sign bit in a smi.
40 const intptr_t kSmiSignMask = kIntptrSignBit;
41 
42 const int kObjectAlignmentBits = kPointerSizeLog2;
43 const intptr_t kObjectAlignment = 1 << kObjectAlignmentBits;
44 const intptr_t kObjectAlignmentMask = kObjectAlignment - 1;
45 
46 // Desired alignment for pointers.
47 const intptr_t kPointerAlignment = (1 << kPointerSizeLog2);
48 const intptr_t kPointerAlignmentMask = kPointerAlignment - 1;
49 
50 // Desired alignment for maps.
51 #if V8_HOST_ARCH_64_BIT
52 const intptr_t kMapAlignmentBits = kObjectAlignmentBits;
53 #else
54 const intptr_t kMapAlignmentBits = kObjectAlignmentBits + 3;
55 #endif
56 const intptr_t kMapAlignment = (1 << kMapAlignmentBits);
57 const intptr_t kMapAlignmentMask = kMapAlignment - 1;
58 
59 // Desired alignment for generated code is 32 bytes (to improve cache line
60 // utilization).
61 const int kCodeAlignmentBits = 5;
62 const intptr_t kCodeAlignment = 1 << kCodeAlignmentBits;
63 const intptr_t kCodeAlignmentMask = kCodeAlignment - 1;
64 
65 // Tag information for Failure.
66 const int kFailureTag = 3;
67 const int kFailureTagSize = 2;
68 const intptr_t kFailureTagMask = (1 << kFailureTagSize) - 1;
69 
70 
71 // Zap-value: The value used for zapping dead objects.
72 // Should be a recognizable hex value tagged as a failure.
73 #ifdef V8_HOST_ARCH_64_BIT
74 const Address kZapValue =
75     reinterpret_cast<Address>(V8_UINT64_C(0xdeadbeedbeadbeef));
76 const Address kHandleZapValue =
77     reinterpret_cast<Address>(V8_UINT64_C(0x1baddead0baddeaf));
78 const Address kFromSpaceZapValue =
79     reinterpret_cast<Address>(V8_UINT64_C(0x1beefdad0beefdaf));
80 const uint64_t kDebugZapValue = V8_UINT64_C(0xbadbaddbbadbaddb);
81 const uint64_t kSlotsZapValue = V8_UINT64_C(0xbeefdeadbeefdeef);
82 #else
83 const Address kZapValue = reinterpret_cast<Address>(0xdeadbeef);
84 const Address kHandleZapValue = reinterpret_cast<Address>(0xbaddeaf);
85 const Address kFromSpaceZapValue = reinterpret_cast<Address>(0xbeefdaf);
86 const uint32_t kSlotsZapValue = 0xbeefdeef;
87 const uint32_t kDebugZapValue = 0xbadbaddb;
88 #endif
89 
90 
91 // Number of bits to represent the page size for paged spaces. The value of 13
92 // gives 8K bytes per page.
93 const int kPageSizeBits = 13;
94 
95 // On Intel architecture, cache line size is 64 bytes.
96 // On ARM it may be less (32 bytes), but as far this constant is
97 // used for aligning data, it doesn't hurt to align on a greater value.
98 const int kProcessorCacheLineSize = 64;
99 
100 // Constants relevant to double precision floating point numbers.
101 
102 // Quiet NaNs have bits 51 to 62 set, possibly the sign bit, and no
103 // other bits set.
104 const uint64_t kQuietNaNMask = static_cast<uint64_t>(0xfff) << 51;
105 // If looking only at the top 32 bits, the QNaN mask is bits 19 to 30.
106 const uint32_t kQuietNaNHighBitsMask = 0xfff << (51 - 32);
107 
108 
109 // -----------------------------------------------------------------------------
110 // Forward declarations for frequently used classes
111 // (sorted alphabetically)
112 
113 class AccessorInfo;
114 class Allocation;
115 class Arguments;
116 class Assembler;
117 class AssertNoAllocation;
118 class BreakableStatement;
119 class Code;
120 class CodeGenerator;
121 class CodeStub;
122 class Context;
123 class Debug;
124 class Debugger;
125 class DebugInfo;
126 class Descriptor;
127 class DescriptorArray;
128 class Expression;
129 class ExternalReference;
130 class FixedArray;
131 class FunctionEntry;
132 class FunctionLiteral;
133 class FunctionTemplateInfo;
134 class NumberDictionary;
135 class StringDictionary;
136 template <typename T> class Handle;
137 class Heap;
138 class HeapObject;
139 class IC;
140 class InterceptorInfo;
141 class IterationStatement;
142 class JSArray;
143 class JSFunction;
144 class JSObject;
145 class LargeObjectSpace;
146 class LookupResult;
147 class MacroAssembler;
148 class Map;
149 class MapSpace;
150 class MarkCompactCollector;
151 class NewSpace;
152 class NodeVisitor;
153 class Object;
154 class MaybeObject;
155 class OldSpace;
156 class Property;
157 class Proxy;
158 class RegExpNode;
159 struct RegExpCompileData;
160 class RegExpTree;
161 class RegExpCompiler;
162 class RegExpVisitor;
163 class Scope;
164 template<class Allocator = FreeStoreAllocationPolicy> class ScopeInfo;
165 class SerializedScopeInfo;
166 class Script;
167 class Slot;
168 class Smi;
169 template <typename Config, class Allocator = FreeStoreAllocationPolicy>
170     class SplayTree;
171 class Statement;
172 class String;
173 class Struct;
174 class SwitchStatement;
175 class AstVisitor;
176 class Variable;
177 class VariableProxy;
178 class RelocInfo;
179 class Deserializer;
180 class MessageLocation;
181 class ObjectGroup;
182 class TickSample;
183 class VirtualMemory;
184 class Mutex;
185 
186 typedef bool (*WeakSlotCallback)(Object** pointer);
187 
188 // -----------------------------------------------------------------------------
189 // Miscellaneous
190 
191 // NOTE: SpaceIterator depends on AllocationSpace enumeration values being
192 // consecutive.
193 enum AllocationSpace {
194   NEW_SPACE,            // Semispaces collected with copying collector.
195   OLD_POINTER_SPACE,    // May contain pointers to new space.
196   OLD_DATA_SPACE,       // Must not have pointers to new space.
197   CODE_SPACE,           // No pointers to new space, marked executable.
198   MAP_SPACE,            // Only and all map objects.
199   CELL_SPACE,           // Only and all cell objects.
200   LO_SPACE,             // Promoted large objects.
201 
202   FIRST_SPACE = NEW_SPACE,
203   LAST_SPACE = LO_SPACE,
204   FIRST_PAGED_SPACE = OLD_POINTER_SPACE,
205   LAST_PAGED_SPACE = CELL_SPACE
206 };
207 const int kSpaceTagSize = 3;
208 const int kSpaceTagMask = (1 << kSpaceTagSize) - 1;
209 
210 
211 // A flag that indicates whether objects should be pretenured when
212 // allocated (allocated directly into the old generation) or not
213 // (allocated in the young generation if the object size and type
214 // allows).
215 enum PretenureFlag { NOT_TENURED, TENURED };
216 
217 enum GarbageCollector { SCAVENGER, MARK_COMPACTOR };
218 
219 enum Executability { NOT_EXECUTABLE, EXECUTABLE };
220 
221 enum VisitMode { VISIT_ALL, VISIT_ALL_IN_SCAVENGE, VISIT_ONLY_STRONG };
222 
223 // Flag indicating whether code is built into the VM (one of the natives files).
224 enum NativesFlag { NOT_NATIVES_CODE, NATIVES_CODE };
225 
226 
227 // A CodeDesc describes a buffer holding instructions and relocation
228 // information. The instructions start at the beginning of the buffer
229 // and grow forward, the relocation information starts at the end of
230 // the buffer and grows backward.
231 //
232 //  |<--------------- buffer_size ---------------->|
233 //  |<-- instr_size -->|        |<-- reloc_size -->|
234 //  +==================+========+==================+
235 //  |   instructions   |  free  |    reloc info    |
236 //  +==================+========+==================+
237 //  ^
238 //  |
239 //  buffer
240 
241 struct CodeDesc {
242   byte* buffer;
243   int buffer_size;
244   int instr_size;
245   int reloc_size;
246   Assembler* origin;
247 };
248 
249 
250 // Callback function on object slots, used for iterating heap object slots in
251 // HeapObjects, global pointers to heap objects, etc. The callback allows the
252 // callback function to change the value of the slot.
253 typedef void (*ObjectSlotCallback)(HeapObject** pointer);
254 
255 
256 // Callback function used for iterating objects in heap spaces,
257 // for example, scanning heap objects.
258 typedef int (*HeapObjectCallback)(HeapObject* obj);
259 
260 
261 // Callback function used for checking constraints when copying/relocating
262 // objects. Returns true if an object can be copied/relocated from its
263 // old_addr to a new_addr.
264 typedef bool (*ConstraintCallback)(Address new_addr, Address old_addr);
265 
266 
267 // Callback function on inline caches, used for iterating over inline caches
268 // in compiled code.
269 typedef void (*InlineCacheCallback)(Code* code, Address ic);
270 
271 
272 // State for inline cache call sites. Aliased as IC::State.
273 enum InlineCacheState {
274   // Has never been executed.
275   UNINITIALIZED,
276   // Has been executed but monomorhic state has been delayed.
277   PREMONOMORPHIC,
278   // Has been executed and only one receiver type has been seen.
279   MONOMORPHIC,
280   // Like MONOMORPHIC but check failed due to prototype.
281   MONOMORPHIC_PROTOTYPE_FAILURE,
282   // Multiple receiver types have been seen.
283   MEGAMORPHIC,
284   // Special states for debug break or step in prepare stubs.
285   DEBUG_BREAK,
286   DEBUG_PREPARE_STEP_IN
287 };
288 
289 
290 enum CheckType {
291   RECEIVER_MAP_CHECK,
292   STRING_CHECK,
293   NUMBER_CHECK,
294   BOOLEAN_CHECK
295 };
296 
297 
298 enum InLoopFlag {
299   NOT_IN_LOOP,
300   IN_LOOP
301 };
302 
303 
304 enum CallFunctionFlags {
305   NO_CALL_FUNCTION_FLAGS = 0,
306   RECEIVER_MIGHT_BE_VALUE = 1 << 0  // Receiver might not be a JSObject.
307 };
308 
309 
310 enum InlineCacheHolderFlag {
311   OWN_MAP,  // For fast properties objects.
312   PROTOTYPE_MAP  // For slow properties objects (except GlobalObjects).
313 };
314 
315 
316 // Type of properties.
317 // Order of properties is significant.
318 // Must fit in the BitField PropertyDetails::TypeField.
319 // A copy of this is in mirror-debugger.js.
320 enum PropertyType {
321   NORMAL                    = 0,  // only in slow mode
322   FIELD                     = 1,  // only in fast mode
323   CONSTANT_FUNCTION         = 2,  // only in fast mode
324   CALLBACKS                 = 3,
325   INTERCEPTOR               = 4,  // only in lookup results, not in descriptors.
326   MAP_TRANSITION            = 5,  // only in fast mode
327   EXTERNAL_ARRAY_TRANSITION = 6,
328   CONSTANT_TRANSITION       = 7,  // only in fast mode
329   NULL_DESCRIPTOR           = 8,  // only in fast mode
330   // All properties before MAP_TRANSITION are real.
331   FIRST_PHANTOM_PROPERTY_TYPE = MAP_TRANSITION,
332   // There are no IC stubs for NULL_DESCRIPTORS. Therefore,
333   // NULL_DESCRIPTOR can be used as the type flag for IC stubs for
334   // nonexistent properties.
335   NONEXISTENT = NULL_DESCRIPTOR
336 };
337 
338 
339 // Whether to remove map transitions and constant transitions from a
340 // DescriptorArray.
341 enum TransitionFlag {
342   REMOVE_TRANSITIONS,
343   KEEP_TRANSITIONS
344 };
345 
346 
347 // Union used for fast testing of specific double values.
348 union DoubleRepresentation {
349   double  value;
350   int64_t bits;
DoubleRepresentation(double x)351   DoubleRepresentation(double x) { value = x; }
352 };
353 
354 
355 // Union used for customized checking of the IEEE double types
356 // inlined within v8 runtime, rather than going to the underlying
357 // platform headers and libraries
358 union IeeeDoubleLittleEndianArchType {
359   double d;
360   struct {
361     unsigned int man_low  :32;
362     unsigned int man_high :20;
363     unsigned int exp      :11;
364     unsigned int sign     :1;
365   } bits;
366 };
367 
368 
369 union IeeeDoubleBigEndianArchType {
370   double d;
371   struct {
372     unsigned int sign     :1;
373     unsigned int exp      :11;
374     unsigned int man_high :20;
375     unsigned int man_low  :32;
376   } bits;
377 };
378 
379 
380 // AccessorCallback
381 struct AccessorDescriptor {
382   MaybeObject* (*getter)(Object* object, void* data);
383   MaybeObject* (*setter)(JSObject* object, Object* value, void* data);
384   void* data;
385 };
386 
387 
388 // Logging and profiling.
389 // A StateTag represents a possible state of the VM.  When compiled with
390 // ENABLE_VMSTATE_TRACKING, the logger maintains a stack of these.
391 // Creating a VMState object enters a state by pushing on the stack, and
392 // destroying a VMState object leaves a state by popping the current state
393 // from the stack.
394 
395 #define STATE_TAG_LIST(V) \
396   V(JS)                   \
397   V(GC)                   \
398   V(COMPILER)             \
399   V(OTHER)                \
400   V(EXTERNAL)
401 
402 enum StateTag {
403 #define DEF_STATE_TAG(name) name,
404   STATE_TAG_LIST(DEF_STATE_TAG)
405 #undef DEF_STATE_TAG
406   // Pseudo-types.
407   state_tag_count
408 };
409 
410 
411 // -----------------------------------------------------------------------------
412 // Macros
413 
414 // Testers for test.
415 
416 #define HAS_SMI_TAG(value) \
417   ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag)
418 
419 #define HAS_FAILURE_TAG(value) \
420   ((reinterpret_cast<intptr_t>(value) & kFailureTagMask) == kFailureTag)
421 
422 // OBJECT_POINTER_ALIGN returns the value aligned as a HeapObject pointer
423 #define OBJECT_POINTER_ALIGN(value)                             \
424   (((value) + kObjectAlignmentMask) & ~kObjectAlignmentMask)
425 
426 // POINTER_SIZE_ALIGN returns the value aligned as a pointer.
427 #define POINTER_SIZE_ALIGN(value)                               \
428   (((value) + kPointerAlignmentMask) & ~kPointerAlignmentMask)
429 
430 // MAP_POINTER_ALIGN returns the value aligned as a map pointer.
431 #define MAP_POINTER_ALIGN(value)                                \
432   (((value) + kMapAlignmentMask) & ~kMapAlignmentMask)
433 
434 // CODE_POINTER_ALIGN returns the value aligned as a generated code segment.
435 #define CODE_POINTER_ALIGN(value)                               \
436   (((value) + kCodeAlignmentMask) & ~kCodeAlignmentMask)
437 
438 // Support for tracking C++ memory allocation.  Insert TRACK_MEMORY("Fisk")
439 // inside a C++ class and new and delete will be overloaded so logging is
440 // performed.
441 // This file (globals.h) is included before log.h, so we use direct calls to
442 // the Logger rather than the LOG macro.
443 #ifdef DEBUG
444 #define TRACK_MEMORY(name) \
445   void* operator new(size_t size) { \
446     void* result = ::operator new(size); \
447     Logger::NewEventStatic(name, result, size); \
448     return result; \
449   } \
450   void operator delete(void* object) { \
451     Logger::DeleteEventStatic(name, object); \
452     ::operator delete(object); \
453   }
454 #else
455 #define TRACK_MEMORY(name)
456 #endif
457 
458 
459 // Feature flags bit positions. They are mostly based on the CPUID spec.
460 // (We assign CPUID itself to one of the currently reserved bits --
461 // feel free to change this if needed.)
462 // On X86/X64, values below 32 are bits in EDX, values above 32 are bits in ECX.
463 enum CpuFeature { SSE4_1 = 32 + 19,  // x86
464                   SSE3 = 32 + 0,     // x86
465                   SSE2 = 26,   // x86
466                   CMOV = 15,   // x86
467                   RDTSC = 4,   // x86
468                   CPUID = 10,  // x86
469                   VFP3 = 1,    // ARM
470                   ARMv7 = 2,   // ARM
471                   SAHF = 0,    // x86
472                   FPU = 1};    // MIPS
473 
474 // The Strict Mode (ECMA-262 5th edition, 4.2.2).
475 enum StrictModeFlag {
476   kNonStrictMode,
477   kStrictMode,
478   // This value is never used, but is needed to prevent GCC 4.5 from failing
479   // to compile when we assert that a flag is either kNonStrictMode or
480   // kStrictMode.
481   kInvalidStrictFlag
482 };
483 
484 } }  // namespace v8::internal
485 
486 #endif  // V8_V8GLOBALS_H_
487