blob: aff27579f8d78b6cd8337f9b8fba578237993c42 [file] [log] [blame]
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +00001// Copyright 2011 the V8 project authors. All rights reserved.
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00002// 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
33namespace v8 {
34namespace 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.
40const intptr_t kSmiSignMask = kIntptrSignBit;
41
42const int kObjectAlignmentBits = kPointerSizeLog2;
43const intptr_t kObjectAlignment = 1 << kObjectAlignmentBits;
44const intptr_t kObjectAlignmentMask = kObjectAlignment - 1;
45
46// Desired alignment for pointers.
47const intptr_t kPointerAlignment = (1 << kPointerSizeLog2);
48const intptr_t kPointerAlignmentMask = kPointerAlignment - 1;
49
50// Desired alignment for maps.
51#if V8_HOST_ARCH_64_BIT
52const intptr_t kMapAlignmentBits = kObjectAlignmentBits;
53#else
54const intptr_t kMapAlignmentBits = kObjectAlignmentBits + 3;
55#endif
56const intptr_t kMapAlignment = (1 << kMapAlignmentBits);
57const intptr_t kMapAlignmentMask = kMapAlignment - 1;
58
59// Desired alignment for generated code is 32 bytes (to improve cache line
60// utilization).
61const int kCodeAlignmentBits = 5;
62const intptr_t kCodeAlignment = 1 << kCodeAlignmentBits;
63const intptr_t kCodeAlignmentMask = kCodeAlignment - 1;
64
65// Tag information for Failure.
66const int kFailureTag = 3;
67const int kFailureTagSize = 2;
68const intptr_t kFailureTagMask = (1 << kFailureTagSize) - 1;
69
70
71// Zap-value: The value used for zapping dead objects.
erik.corry@gmail.comd91075f2011-02-10 07:45:38 +000072// Should be a recognizable hex value tagged as a failure.
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +000073#ifdef V8_HOST_ARCH_64_BIT
74const Address kZapValue =
erik.corry@gmail.comd91075f2011-02-10 07:45:38 +000075 reinterpret_cast<Address>(V8_UINT64_C(0xdeadbeedbeadbeef));
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +000076const Address kHandleZapValue =
erik.corry@gmail.comd91075f2011-02-10 07:45:38 +000077 reinterpret_cast<Address>(V8_UINT64_C(0x1baddead0baddeaf));
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +000078const Address kFromSpaceZapValue =
erik.corry@gmail.comd91075f2011-02-10 07:45:38 +000079 reinterpret_cast<Address>(V8_UINT64_C(0x1beefdad0beefdaf));
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +000080const uint64_t kDebugZapValue = V8_UINT64_C(0xbadbaddbbadbaddb);
erik.corry@gmail.comd91075f2011-02-10 07:45:38 +000081const uint64_t kSlotsZapValue = V8_UINT64_C(0xbeefdeadbeefdeef);
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +000082#else
erik.corry@gmail.comd91075f2011-02-10 07:45:38 +000083const Address kZapValue = reinterpret_cast<Address>(0xdeadbeef);
84const Address kHandleZapValue = reinterpret_cast<Address>(0xbaddeaf);
85const Address kFromSpaceZapValue = reinterpret_cast<Address>(0xbeefdaf);
86const uint32_t kSlotsZapValue = 0xbeefdeef;
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +000087const 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.
93const 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.
98const 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.
104const 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.
106const uint32_t kQuietNaNHighBitsMask = 0xfff << (51 - 32);
107
108
109// -----------------------------------------------------------------------------
110// Forward declarations for frequently used classes
111// (sorted alphabetically)
112
113class AccessorInfo;
114class Allocation;
115class Arguments;
116class Assembler;
117class AssertNoAllocation;
118class BreakableStatement;
119class Code;
120class CodeGenerator;
121class CodeStub;
122class Context;
123class Debug;
124class Debugger;
125class DebugInfo;
126class Descriptor;
127class DescriptorArray;
128class Expression;
129class ExternalReference;
130class FixedArray;
131class FunctionEntry;
132class FunctionLiteral;
133class FunctionTemplateInfo;
134class NumberDictionary;
135class StringDictionary;
136template <typename T> class Handle;
137class Heap;
138class HeapObject;
139class IC;
140class InterceptorInfo;
141class IterationStatement;
142class JSArray;
143class JSFunction;
144class JSObject;
145class LargeObjectSpace;
146class LookupResult;
147class MacroAssembler;
148class Map;
149class MapSpace;
150class MarkCompactCollector;
151class NewSpace;
152class NodeVisitor;
153class Object;
154class MaybeObject;
155class OldSpace;
156class Property;
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000157class Foreign;
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000158class RegExpNode;
159struct RegExpCompileData;
160class RegExpTree;
161class RegExpCompiler;
162class RegExpVisitor;
163class Scope;
164template<class Allocator = FreeStoreAllocationPolicy> class ScopeInfo;
165class SerializedScopeInfo;
166class Script;
167class Slot;
168class Smi;
169template <typename Config, class Allocator = FreeStoreAllocationPolicy>
170 class SplayTree;
171class Statement;
172class String;
173class Struct;
174class SwitchStatement;
175class AstVisitor;
176class Variable;
177class VariableProxy;
178class RelocInfo;
179class Deserializer;
180class MessageLocation;
181class ObjectGroup;
182class TickSample;
183class VirtualMemory;
184class Mutex;
185
186typedef bool (*WeakSlotCallback)(Object** pointer);
187
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000188typedef bool (*WeakSlotCallbackWithHeap)(Heap* heap, Object** pointer);
189
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000190// -----------------------------------------------------------------------------
191// Miscellaneous
192
193// NOTE: SpaceIterator depends on AllocationSpace enumeration values being
194// consecutive.
195enum AllocationSpace {
196 NEW_SPACE, // Semispaces collected with copying collector.
197 OLD_POINTER_SPACE, // May contain pointers to new space.
198 OLD_DATA_SPACE, // Must not have pointers to new space.
199 CODE_SPACE, // No pointers to new space, marked executable.
200 MAP_SPACE, // Only and all map objects.
201 CELL_SPACE, // Only and all cell objects.
202 LO_SPACE, // Promoted large objects.
203
204 FIRST_SPACE = NEW_SPACE,
205 LAST_SPACE = LO_SPACE,
206 FIRST_PAGED_SPACE = OLD_POINTER_SPACE,
207 LAST_PAGED_SPACE = CELL_SPACE
208};
209const int kSpaceTagSize = 3;
210const int kSpaceTagMask = (1 << kSpaceTagSize) - 1;
211
212
213// A flag that indicates whether objects should be pretenured when
214// allocated (allocated directly into the old generation) or not
215// (allocated in the young generation if the object size and type
216// allows).
217enum PretenureFlag { NOT_TENURED, TENURED };
218
219enum GarbageCollector { SCAVENGER, MARK_COMPACTOR };
220
221enum Executability { NOT_EXECUTABLE, EXECUTABLE };
222
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000223enum VisitMode {
224 VISIT_ALL,
225 VISIT_ALL_IN_SCAVENGE,
226 VISIT_ALL_IN_SWEEP_NEWSPACE,
227 VISIT_ONLY_STRONG
228};
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000229
230// Flag indicating whether code is built into the VM (one of the natives files).
231enum NativesFlag { NOT_NATIVES_CODE, NATIVES_CODE };
232
233
234// A CodeDesc describes a buffer holding instructions and relocation
235// information. The instructions start at the beginning of the buffer
236// and grow forward, the relocation information starts at the end of
237// the buffer and grows backward.
238//
239// |<--------------- buffer_size ---------------->|
240// |<-- instr_size -->| |<-- reloc_size -->|
241// +==================+========+==================+
242// | instructions | free | reloc info |
243// +==================+========+==================+
244// ^
245// |
246// buffer
247
248struct CodeDesc {
249 byte* buffer;
250 int buffer_size;
251 int instr_size;
252 int reloc_size;
253 Assembler* origin;
254};
255
256
257// Callback function on object slots, used for iterating heap object slots in
258// HeapObjects, global pointers to heap objects, etc. The callback allows the
259// callback function to change the value of the slot.
260typedef void (*ObjectSlotCallback)(HeapObject** pointer);
261
262
263// Callback function used for iterating objects in heap spaces,
264// for example, scanning heap objects.
265typedef int (*HeapObjectCallback)(HeapObject* obj);
266
267
268// Callback function used for checking constraints when copying/relocating
269// objects. Returns true if an object can be copied/relocated from its
270// old_addr to a new_addr.
271typedef bool (*ConstraintCallback)(Address new_addr, Address old_addr);
272
273
274// Callback function on inline caches, used for iterating over inline caches
275// in compiled code.
276typedef void (*InlineCacheCallback)(Code* code, Address ic);
277
278
279// State for inline cache call sites. Aliased as IC::State.
280enum InlineCacheState {
281 // Has never been executed.
282 UNINITIALIZED,
283 // Has been executed but monomorhic state has been delayed.
284 PREMONOMORPHIC,
285 // Has been executed and only one receiver type has been seen.
286 MONOMORPHIC,
287 // Like MONOMORPHIC but check failed due to prototype.
288 MONOMORPHIC_PROTOTYPE_FAILURE,
289 // Multiple receiver types have been seen.
290 MEGAMORPHIC,
291 // Special states for debug break or step in prepare stubs.
292 DEBUG_BREAK,
293 DEBUG_PREPARE_STEP_IN
294};
295
296
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000297enum CheckType {
298 RECEIVER_MAP_CHECK,
299 STRING_CHECK,
300 NUMBER_CHECK,
301 BOOLEAN_CHECK
302};
303
304
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000305enum InLoopFlag {
306 NOT_IN_LOOP,
307 IN_LOOP
308};
309
310
311enum CallFunctionFlags {
312 NO_CALL_FUNCTION_FLAGS = 0,
danno@chromium.org40cb8782011-05-25 07:58:50 +0000313 // Receiver might implicitly be the global objects. If it is, the
314 // hole is passed to the call function stub.
315 RECEIVER_MIGHT_BE_IMPLICIT = 1 << 0
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000316};
317
318
319enum InlineCacheHolderFlag {
320 OWN_MAP, // For fast properties objects.
321 PROTOTYPE_MAP // For slow properties objects (except GlobalObjects).
322};
323
324
325// Type of properties.
326// Order of properties is significant.
327// Must fit in the BitField PropertyDetails::TypeField.
328// A copy of this is in mirror-debugger.js.
329enum PropertyType {
fschneider@chromium.org7979bbb2011-03-28 10:47:03 +0000330 NORMAL = 0, // only in slow mode
331 FIELD = 1, // only in fast mode
332 CONSTANT_FUNCTION = 2, // only in fast mode
333 CALLBACKS = 3,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000334 HANDLER = 4, // only in lookup results, not in descriptors
335 INTERCEPTOR = 5, // only in lookup results, not in descriptors
336 MAP_TRANSITION = 6, // only in fast mode
337 EXTERNAL_ARRAY_TRANSITION = 7,
338 CONSTANT_TRANSITION = 8, // only in fast mode
339 NULL_DESCRIPTOR = 9, // only in fast mode
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000340 // All properties before MAP_TRANSITION are real.
341 FIRST_PHANTOM_PROPERTY_TYPE = MAP_TRANSITION,
342 // There are no IC stubs for NULL_DESCRIPTORS. Therefore,
343 // NULL_DESCRIPTOR can be used as the type flag for IC stubs for
344 // nonexistent properties.
345 NONEXISTENT = NULL_DESCRIPTOR
346};
347
348
349// Whether to remove map transitions and constant transitions from a
350// DescriptorArray.
351enum TransitionFlag {
352 REMOVE_TRANSITIONS,
353 KEEP_TRANSITIONS
354};
355
356
357// Union used for fast testing of specific double values.
358union DoubleRepresentation {
359 double value;
360 int64_t bits;
361 DoubleRepresentation(double x) { value = x; }
362};
363
364
365// Union used for customized checking of the IEEE double types
366// inlined within v8 runtime, rather than going to the underlying
367// platform headers and libraries
368union IeeeDoubleLittleEndianArchType {
369 double d;
370 struct {
371 unsigned int man_low :32;
372 unsigned int man_high :20;
373 unsigned int exp :11;
374 unsigned int sign :1;
375 } bits;
376};
377
378
379union IeeeDoubleBigEndianArchType {
380 double d;
381 struct {
382 unsigned int sign :1;
383 unsigned int exp :11;
384 unsigned int man_high :20;
385 unsigned int man_low :32;
386 } bits;
387};
388
389
390// AccessorCallback
391struct AccessorDescriptor {
392 MaybeObject* (*getter)(Object* object, void* data);
393 MaybeObject* (*setter)(JSObject* object, Object* value, void* data);
394 void* data;
395};
396
397
whesse@chromium.org030d38e2011-07-13 13:23:34 +0000398// Logging and profiling. A StateTag represents a possible state of
399// the VM. The logger maintains a stack of these. Creating a VMState
400// object enters a state by pushing on the stack, and destroying a
401// VMState object leaves a state by popping the current state from the
402// stack.
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000403
404#define STATE_TAG_LIST(V) \
405 V(JS) \
406 V(GC) \
407 V(COMPILER) \
408 V(OTHER) \
409 V(EXTERNAL)
410
411enum StateTag {
412#define DEF_STATE_TAG(name) name,
413 STATE_TAG_LIST(DEF_STATE_TAG)
414#undef DEF_STATE_TAG
415 // Pseudo-types.
416 state_tag_count
417};
418
419
420// -----------------------------------------------------------------------------
421// Macros
422
423// Testers for test.
424
425#define HAS_SMI_TAG(value) \
426 ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag)
427
428#define HAS_FAILURE_TAG(value) \
429 ((reinterpret_cast<intptr_t>(value) & kFailureTagMask) == kFailureTag)
430
431// OBJECT_POINTER_ALIGN returns the value aligned as a HeapObject pointer
432#define OBJECT_POINTER_ALIGN(value) \
433 (((value) + kObjectAlignmentMask) & ~kObjectAlignmentMask)
434
435// POINTER_SIZE_ALIGN returns the value aligned as a pointer.
436#define POINTER_SIZE_ALIGN(value) \
437 (((value) + kPointerAlignmentMask) & ~kPointerAlignmentMask)
438
439// MAP_POINTER_ALIGN returns the value aligned as a map pointer.
440#define MAP_POINTER_ALIGN(value) \
441 (((value) + kMapAlignmentMask) & ~kMapAlignmentMask)
442
443// CODE_POINTER_ALIGN returns the value aligned as a generated code segment.
444#define CODE_POINTER_ALIGN(value) \
445 (((value) + kCodeAlignmentMask) & ~kCodeAlignmentMask)
446
447// Support for tracking C++ memory allocation. Insert TRACK_MEMORY("Fisk")
448// inside a C++ class and new and delete will be overloaded so logging is
449// performed.
450// This file (globals.h) is included before log.h, so we use direct calls to
451// the Logger rather than the LOG macro.
452#ifdef DEBUG
453#define TRACK_MEMORY(name) \
454 void* operator new(size_t size) { \
455 void* result = ::operator new(size); \
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000456 Logger::NewEventStatic(name, result, size); \
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000457 return result; \
458 } \
459 void operator delete(void* object) { \
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000460 Logger::DeleteEventStatic(name, object); \
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000461 ::operator delete(object); \
462 }
463#else
464#define TRACK_MEMORY(name)
465#endif
466
467
468// Feature flags bit positions. They are mostly based on the CPUID spec.
469// (We assign CPUID itself to one of the currently reserved bits --
470// feel free to change this if needed.)
471// On X86/X64, values below 32 are bits in EDX, values above 32 are bits in ECX.
472enum CpuFeature { SSE4_1 = 32 + 19, // x86
473 SSE3 = 32 + 0, // x86
474 SSE2 = 26, // x86
475 CMOV = 15, // x86
476 RDTSC = 4, // x86
477 CPUID = 10, // x86
478 VFP3 = 1, // ARM
479 ARMv7 = 2, // ARM
lrn@chromium.org7516f052011-03-30 08:52:27 +0000480 SAHF = 0, // x86
481 FPU = 1}; // MIPS
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000482
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000483// The Strict Mode (ECMA-262 5th edition, 4.2.2).
484enum StrictModeFlag {
485 kNonStrictMode,
whesse@chromium.orgb08986c2011-03-14 16:13:42 +0000486 kStrictMode,
487 // This value is never used, but is needed to prevent GCC 4.5 from failing
488 // to compile when we assert that a flag is either kNonStrictMode or
489 // kStrictMode.
490 kInvalidStrictFlag
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000491};
492
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000493
494// Used to specify if a macro instruction must perform a smi check on tagged
495// values.
496enum SmiCheckType {
497 DONT_DO_SMI_CHECK = 0,
498 DO_SMI_CHECK
499};
500
danno@chromium.org40cb8782011-05-25 07:58:50 +0000501
502// Used to specify whether a receiver is implicitly or explicitly
503// provided to a call.
504enum CallKind {
505 CALL_AS_METHOD = 0,
506 CALL_AS_FUNCTION
507};
508
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +0000509
510static const uint32_t kHoleNanUpper32 = 0x7FFFFFFF;
511static const uint32_t kHoleNanLower32 = 0xFFFFFFFF;
512static const uint32_t kNaNOrInfinityLowerBoundUpper32 = 0x7FF00000;
513
514const uint64_t kHoleNanInt64 =
515 (static_cast<uint64_t>(kHoleNanUpper32) << 32) | kHoleNanLower32;
516const uint64_t kLastNonNaNInt64 =
517 (static_cast<uint64_t>(kNaNOrInfinityLowerBoundUpper32) << 32);
518
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000519} } // namespace v8::internal
520
521#endif // V8_V8GLOBALS_H_