blob: 6ec75478875af0e4cfc87cdff84c7348176d5960 [file] [log] [blame]
yangguo@chromium.org659ceec2012-01-26 07:37:54 +00001// Copyright 2012 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"
danno@chromium.orgc612e022011-11-10 11:38:15 +000032#include "checks.h"
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +000033
34namespace v8 {
35namespace 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.
41const intptr_t kSmiSignMask = kIntptrSignBit;
42
43const int kObjectAlignmentBits = kPointerSizeLog2;
44const intptr_t kObjectAlignment = 1 << kObjectAlignmentBits;
45const intptr_t kObjectAlignmentMask = kObjectAlignment - 1;
46
47// Desired alignment for pointers.
48const intptr_t kPointerAlignment = (1 << kPointerSizeLog2);
49const intptr_t kPointerAlignmentMask = kPointerAlignment - 1;
50
erik.corry@gmail.comed49e962012-04-17 11:57:53 +000051// Desired alignment for double values.
52const intptr_t kDoubleAlignment = 8;
53const intptr_t kDoubleAlignmentMask = kDoubleAlignment - 1;
54
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +000055// Desired alignment for generated code is 32 bytes (to improve cache line
56// utilization).
57const int kCodeAlignmentBits = 5;
58const intptr_t kCodeAlignment = 1 << kCodeAlignmentBits;
59const intptr_t kCodeAlignmentMask = kCodeAlignment - 1;
60
61// Tag information for Failure.
62const int kFailureTag = 3;
63const int kFailureTagSize = 2;
64const intptr_t kFailureTagMask = (1 << kFailureTagSize) - 1;
65
66
67// Zap-value: The value used for zapping dead objects.
erik.corry@gmail.comd91075f2011-02-10 07:45:38 +000068// Should be a recognizable hex value tagged as a failure.
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +000069#ifdef V8_HOST_ARCH_64_BIT
70const Address kZapValue =
erik.corry@gmail.comd91075f2011-02-10 07:45:38 +000071 reinterpret_cast<Address>(V8_UINT64_C(0xdeadbeedbeadbeef));
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +000072const Address kHandleZapValue =
erik.corry@gmail.comd91075f2011-02-10 07:45:38 +000073 reinterpret_cast<Address>(V8_UINT64_C(0x1baddead0baddeaf));
yangguo@chromium.orgc03a1922013-02-19 13:55:47 +000074const Address kGlobalHandleZapValue =
75 reinterpret_cast<Address>(V8_UINT64_C(0x1baffed00baffedf));
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +000076const Address kFromSpaceZapValue =
erik.corry@gmail.comd91075f2011-02-10 07:45:38 +000077 reinterpret_cast<Address>(V8_UINT64_C(0x1beefdad0beefdaf));
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +000078const uint64_t kDebugZapValue = V8_UINT64_C(0xbadbaddbbadbaddb);
erik.corry@gmail.comd91075f2011-02-10 07:45:38 +000079const uint64_t kSlotsZapValue = V8_UINT64_C(0xbeefdeadbeefdeef);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +000080const uint64_t kFreeListZapValue = 0xfeed1eaffeed1eaf;
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +000081#else
erik.corry@gmail.comd91075f2011-02-10 07:45:38 +000082const Address kZapValue = reinterpret_cast<Address>(0xdeadbeef);
83const Address kHandleZapValue = reinterpret_cast<Address>(0xbaddeaf);
yangguo@chromium.orgc03a1922013-02-19 13:55:47 +000084const Address kGlobalHandleZapValue = reinterpret_cast<Address>(0xbaffedf);
erik.corry@gmail.comd91075f2011-02-10 07:45:38 +000085const 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;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +000088const uint32_t kFreeListZapValue = 0xfeed1eaf;
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +000089#endif
90
yangguo@chromium.org46839fb2012-08-28 09:06:19 +000091const int kCodeZapValue = 0xbadc0de;
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +000092
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +000093// Number of bits to represent the page size for paged spaces. The value of 20
94// gives 1Mb bytes per page.
95const int kPageSizeBits = 20;
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +000096
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.
100const int kProcessorCacheLineSize = 64;
101
102// Constants relevant to double precision floating point numbers.
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000103// If looking only at the top 32 bits, the QNaN mask is bits 19 to 30.
104const uint32_t kQuietNaNHighBitsMask = 0xfff << (51 - 32);
105
106
107// -----------------------------------------------------------------------------
108// Forward declarations for frequently used classes
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000109
110class AccessorInfo;
111class Allocation;
112class Arguments;
113class Assembler;
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000114class Code;
115class CodeGenerator;
116class CodeStub;
117class Context;
118class Debug;
119class Debugger;
120class DebugInfo;
121class Descriptor;
122class DescriptorArray;
yangguo@chromium.org99aa4902012-07-06 16:21:55 +0000123class TransitionArray;
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000124class ExternalReference;
125class FixedArray;
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000126class FunctionTemplateInfo;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000127class MemoryChunk;
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +0000128class SeededNumberDictionary;
129class UnseededNumberDictionary;
ulan@chromium.org750145a2013-03-07 15:14:13 +0000130class NameDictionary;
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000131template <typename T> class Handle;
132class Heap;
133class HeapObject;
134class IC;
135class InterceptorInfo;
ulan@chromium.org750145a2013-03-07 15:14:13 +0000136class JSReceiver;
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000137class JSArray;
138class JSFunction;
139class JSObject;
140class LargeObjectSpace;
141class LookupResult;
142class MacroAssembler;
143class Map;
144class MapSpace;
145class MarkCompactCollector;
146class NewSpace;
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000147class Object;
148class MaybeObject;
149class OldSpace;
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000150class Foreign;
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000151class Scope;
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000152class ScopeInfo;
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000153class Script;
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000154class Smi;
155template <typename Config, class Allocator = FreeStoreAllocationPolicy>
156 class SplayTree;
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000157class String;
ulan@chromium.org750145a2013-03-07 15:14:13 +0000158class Name;
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000159class Struct;
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000160class Variable;
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000161class RelocInfo;
162class Deserializer;
163class MessageLocation;
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000164class VirtualMemory;
165class Mutex;
166
167typedef bool (*WeakSlotCallback)(Object** pointer);
168
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000169typedef bool (*WeakSlotCallbackWithHeap)(Heap* heap, Object** pointer);
170
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000171// -----------------------------------------------------------------------------
172// Miscellaneous
173
174// NOTE: SpaceIterator depends on AllocationSpace enumeration values being
175// consecutive.
176enum AllocationSpace {
177 NEW_SPACE, // Semispaces collected with copying collector.
178 OLD_POINTER_SPACE, // May contain pointers to new space.
179 OLD_DATA_SPACE, // Must not have pointers to new space.
180 CODE_SPACE, // No pointers to new space, marked executable.
181 MAP_SPACE, // Only and all map objects.
182 CELL_SPACE, // Only and all cell objects.
danno@chromium.org41728482013-06-12 22:31:22 +0000183 PROPERTY_CELL_SPACE, // Only and all global property cell objects.
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000184 LO_SPACE, // Promoted large objects.
185
186 FIRST_SPACE = NEW_SPACE,
187 LAST_SPACE = LO_SPACE,
188 FIRST_PAGED_SPACE = OLD_POINTER_SPACE,
danno@chromium.org41728482013-06-12 22:31:22 +0000189 LAST_PAGED_SPACE = PROPERTY_CELL_SPACE
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000190};
191const int kSpaceTagSize = 3;
192const int kSpaceTagMask = (1 << kSpaceTagSize) - 1;
193
194
195// A flag that indicates whether objects should be pretenured when
196// allocated (allocated directly into the old generation) or not
197// (allocated in the young generation if the object size and type
198// allows).
199enum PretenureFlag { NOT_TENURED, TENURED };
200
201enum GarbageCollector { SCAVENGER, MARK_COMPACTOR };
202
203enum Executability { NOT_EXECUTABLE, EXECUTABLE };
204
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000205enum VisitMode {
206 VISIT_ALL,
207 VISIT_ALL_IN_SCAVENGE,
208 VISIT_ALL_IN_SWEEP_NEWSPACE,
209 VISIT_ONLY_STRONG
210};
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000211
212// Flag indicating whether code is built into the VM (one of the natives files).
213enum NativesFlag { NOT_NATIVES_CODE, NATIVES_CODE };
214
215
216// A CodeDesc describes a buffer holding instructions and relocation
217// information. The instructions start at the beginning of the buffer
218// and grow forward, the relocation information starts at the end of
219// the buffer and grows backward.
220//
221// |<--------------- buffer_size ---------------->|
222// |<-- instr_size -->| |<-- reloc_size -->|
223// +==================+========+==================+
224// | instructions | free | reloc info |
225// +==================+========+==================+
226// ^
227// |
228// buffer
229
230struct CodeDesc {
231 byte* buffer;
232 int buffer_size;
233 int instr_size;
234 int reloc_size;
235 Assembler* origin;
236};
237
238
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000239// Callback function used for iterating objects in heap spaces,
240// for example, scanning heap objects.
241typedef int (*HeapObjectCallback)(HeapObject* obj);
242
243
244// Callback function used for checking constraints when copying/relocating
245// objects. Returns true if an object can be copied/relocated from its
246// old_addr to a new_addr.
247typedef bool (*ConstraintCallback)(Address new_addr, Address old_addr);
248
249
250// Callback function on inline caches, used for iterating over inline caches
251// in compiled code.
252typedef void (*InlineCacheCallback)(Code* code, Address ic);
253
254
255// State for inline cache call sites. Aliased as IC::State.
256enum InlineCacheState {
257 // Has never been executed.
258 UNINITIALIZED,
259 // Has been executed but monomorhic state has been delayed.
260 PREMONOMORPHIC,
261 // Has been executed and only one receiver type has been seen.
262 MONOMORPHIC,
263 // Like MONOMORPHIC but check failed due to prototype.
264 MONOMORPHIC_PROTOTYPE_FAILURE,
265 // Multiple receiver types have been seen.
jkummerow@chromium.org59297c72013-01-09 16:32:23 +0000266 POLYMORPHIC,
267 // Many receiver types have been seen.
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000268 MEGAMORPHIC,
yangguo@chromium.org46a2a512013-01-18 16:29:40 +0000269 // A generic handler is installed and no extra typefeedback is recorded.
270 GENERIC,
yangguo@chromium.org9768bf12013-01-11 14:51:07 +0000271 // Special state for debug break or step in prepare stubs.
272 DEBUG_STUB
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000273};
274
275
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000276enum CheckType {
277 RECEIVER_MAP_CHECK,
278 STRING_CHECK,
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +0000279 SYMBOL_CHECK,
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000280 NUMBER_CHECK,
281 BOOLEAN_CHECK
282};
283
284
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000285enum CallFunctionFlags {
286 NO_CALL_FUNCTION_FLAGS = 0,
danno@chromium.org40cb8782011-05-25 07:58:50 +0000287 // Receiver might implicitly be the global objects. If it is, the
288 // hole is passed to the call function stub.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000289 RECEIVER_MIGHT_BE_IMPLICIT = 1 << 0,
290 // The call target is cached in the instruction stream.
291 RECORD_CALL_TARGET = 1 << 1
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000292};
293
294
295enum InlineCacheHolderFlag {
296 OWN_MAP, // For fast properties objects.
mstarzinger@chromium.orgf705b502013-04-04 11:38:09 +0000297 PROTOTYPE_MAP // For slow properties objects (except GlobalObjects).
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000298};
299
300
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000301// The Store Buffer (GC).
302typedef enum {
303 kStoreBufferFullEvent,
304 kStoreBufferStartScanningPagesEvent,
305 kStoreBufferScanningPageEvent
306} StoreBufferEvent;
307
308
309typedef void (*StoreBufferCallback)(Heap* heap,
310 MemoryChunk* page,
311 StoreBufferEvent event);
312
313
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000314// Union used for fast testing of specific double values.
315union DoubleRepresentation {
316 double value;
317 int64_t bits;
318 DoubleRepresentation(double x) { value = x; }
319};
320
321
322// Union used for customized checking of the IEEE double types
323// inlined within v8 runtime, rather than going to the underlying
324// platform headers and libraries
325union IeeeDoubleLittleEndianArchType {
326 double d;
327 struct {
328 unsigned int man_low :32;
329 unsigned int man_high :20;
330 unsigned int exp :11;
331 unsigned int sign :1;
332 } bits;
333};
334
335
336union IeeeDoubleBigEndianArchType {
337 double d;
338 struct {
339 unsigned int sign :1;
340 unsigned int exp :11;
341 unsigned int man_high :20;
342 unsigned int man_low :32;
343 } bits;
344};
345
346
347// AccessorCallback
348struct AccessorDescriptor {
349 MaybeObject* (*getter)(Object* object, void* data);
350 MaybeObject* (*setter)(JSObject* object, Object* value, void* data);
351 void* data;
352};
353
354
whesse@chromium.org030d38e2011-07-13 13:23:34 +0000355// Logging and profiling. A StateTag represents a possible state of
356// the VM. The logger maintains a stack of these. Creating a VMState
357// object enters a state by pushing on the stack, and destroying a
358// VMState object leaves a state by popping the current state from the
359// stack.
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000360
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000361enum StateTag {
jkummerow@chromium.org5323a9c2012-12-10 19:00:50 +0000362 JS,
363 GC,
364 COMPILER,
jkummerow@chromium.org5323a9c2012-12-10 19:00:50 +0000365 OTHER,
danno@chromium.org59400602013-08-13 17:09:37 +0000366 EXTERNAL,
367 IDLE
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000368};
369
370
371// -----------------------------------------------------------------------------
372// Macros
373
374// Testers for test.
375
376#define HAS_SMI_TAG(value) \
377 ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag)
378
379#define HAS_FAILURE_TAG(value) \
380 ((reinterpret_cast<intptr_t>(value) & kFailureTagMask) == kFailureTag)
381
382// OBJECT_POINTER_ALIGN returns the value aligned as a HeapObject pointer
383#define OBJECT_POINTER_ALIGN(value) \
384 (((value) + kObjectAlignmentMask) & ~kObjectAlignmentMask)
385
386// POINTER_SIZE_ALIGN returns the value aligned as a pointer.
387#define POINTER_SIZE_ALIGN(value) \
388 (((value) + kPointerAlignmentMask) & ~kPointerAlignmentMask)
389
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000390// CODE_POINTER_ALIGN returns the value aligned as a generated code segment.
391#define CODE_POINTER_ALIGN(value) \
392 (((value) + kCodeAlignmentMask) & ~kCodeAlignmentMask)
393
394// Support for tracking C++ memory allocation. Insert TRACK_MEMORY("Fisk")
395// inside a C++ class and new and delete will be overloaded so logging is
396// performed.
397// This file (globals.h) is included before log.h, so we use direct calls to
398// the Logger rather than the LOG macro.
399#ifdef DEBUG
400#define TRACK_MEMORY(name) \
401 void* operator new(size_t size) { \
402 void* result = ::operator new(size); \
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000403 Logger::NewEventStatic(name, result, size); \
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000404 return result; \
405 } \
406 void operator delete(void* object) { \
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000407 Logger::DeleteEventStatic(name, object); \
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000408 ::operator delete(object); \
409 }
410#else
411#define TRACK_MEMORY(name)
412#endif
413
414
rossberg@chromium.org89e18f52012-10-22 13:09:53 +0000415enum CpuImplementer {
416 UNKNOWN_IMPLEMENTER,
417 ARM_IMPLEMENTER,
418 QUALCOMM_IMPLEMENTER
419};
420
421
danno@chromium.org169691d2013-07-15 08:01:13 +0000422enum CpuPart {
423 CPU_UNKNOWN,
424 CORTEX_A15,
425 CORTEX_A12,
426 CORTEX_A9,
427 CORTEX_A8,
428 CORTEX_A7,
429 CORTEX_A5
430};
431
432
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000433// 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.
437enum 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
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000445 SUDIV = 3, // ARM
446 UNALIGNED_ACCESSES = 4, // ARM
447 MOVW_MOVT_IMMEDIATE_LOADS = 5, // ARM
448 VFP32DREGS = 6, // ARM
danno@chromium.org169691d2013-07-15 08:01:13 +0000449 NEON = 7, // ARM
lrn@chromium.org7516f052011-03-30 08:52:27 +0000450 SAHF = 0, // x86
451 FPU = 1}; // MIPS
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000452
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000453
454// Used to specify if a macro instruction must perform a smi check on tagged
455// values.
456enum SmiCheckType {
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000457 DONT_DO_SMI_CHECK,
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000458 DO_SMI_CHECK
459};
460
danno@chromium.org40cb8782011-05-25 07:58:50 +0000461
462// Used to specify whether a receiver is implicitly or explicitly
463// provided to a call.
464enum CallKind {
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000465 CALL_AS_METHOD,
danno@chromium.org40cb8782011-05-25 07:58:50 +0000466 CALL_AS_FUNCTION
467};
468
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +0000469
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000470enum ScopeType {
471 EVAL_SCOPE, // The top-level scope for an eval source.
472 FUNCTION_SCOPE, // The top-level scope for a function.
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +0000473 MODULE_SCOPE, // The scope introduced by a module literal
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000474 GLOBAL_SCOPE, // The top-level scope for a program or a top-level eval.
475 CATCH_SCOPE, // The scope introduced by catch.
476 BLOCK_SCOPE, // The scope introduced by a new block.
477 WITH_SCOPE // The scope introduced by with.
478};
479
480
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +0000481const uint32_t kHoleNanUpper32 = 0x7FFFFFFF;
482const uint32_t kHoleNanLower32 = 0xFFFFFFFF;
483const uint32_t kNaNOrInfinityLowerBoundUpper32 = 0x7FF00000;
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +0000484
485const uint64_t kHoleNanInt64 =
486 (static_cast<uint64_t>(kHoleNanUpper32) << 32) | kHoleNanLower32;
487const uint64_t kLastNonNaNInt64 =
488 (static_cast<uint64_t>(kNaNOrInfinityLowerBoundUpper32) << 32);
489
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000490
yangguo@chromium.org355cfd12012-08-29 15:32:24 +0000491// The order of this enum has to be kept in sync with the predicates below.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000492enum VariableMode {
493 // User declared variables:
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000494 VAR, // declared via 'var', and 'function' declarations
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000495
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000496 CONST, // declared via 'const' declarations
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000497
ulan@chromium.org8e8d8822012-11-23 14:36:46 +0000498 LET, // declared via 'let' declarations (first lexical)
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000499
yangguo@chromium.org355cfd12012-08-29 15:32:24 +0000500 CONST_HARMONY, // declared via 'const' declarations in harmony mode
501
ulan@chromium.org8e8d8822012-11-23 14:36:46 +0000502 MODULE, // declared via 'module' declaration (last lexical)
503
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000504 // Variables introduced by the compiler:
ulan@chromium.org8e8d8822012-11-23 14:36:46 +0000505 INTERNAL, // like VAR, but not user-visible (may or may not
506 // be in a context)
507
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000508 TEMPORARY, // temporary variables (not user-visible), stack-allocated
509 // unless the scope as a whole has forced context allocation
ulan@chromium.org8e8d8822012-11-23 14:36:46 +0000510
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000511 DYNAMIC, // always require dynamic lookup (we don't know
512 // the declaration)
513
514 DYNAMIC_GLOBAL, // requires dynamic lookup, but we know that the
515 // variable is global unless it has been shadowed
516 // by an eval-introduced variable
517
ulan@chromium.org8e8d8822012-11-23 14:36:46 +0000518 DYNAMIC_LOCAL // requires dynamic lookup, but we know that the
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000519 // variable is local and where it is unless it
520 // has been shadowed by an eval-introduced
521 // variable
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000522};
523
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000524
yangguo@chromium.org355cfd12012-08-29 15:32:24 +0000525inline bool IsDynamicVariableMode(VariableMode mode) {
526 return mode >= DYNAMIC && mode <= DYNAMIC_LOCAL;
527}
528
529
530inline bool IsDeclaredVariableMode(VariableMode mode) {
ulan@chromium.org8e8d8822012-11-23 14:36:46 +0000531 return mode >= VAR && mode <= MODULE;
yangguo@chromium.org355cfd12012-08-29 15:32:24 +0000532}
533
534
535inline bool IsLexicalVariableMode(VariableMode mode) {
ulan@chromium.org8e8d8822012-11-23 14:36:46 +0000536 return mode >= LET && mode <= MODULE;
yangguo@chromium.org355cfd12012-08-29 15:32:24 +0000537}
538
539
540inline bool IsImmutableVariableMode(VariableMode mode) {
ulan@chromium.org8e8d8822012-11-23 14:36:46 +0000541 return mode == CONST || (mode >= CONST_HARMONY && mode <= MODULE);
yangguo@chromium.org355cfd12012-08-29 15:32:24 +0000542}
543
544
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000545// ES6 Draft Rev3 10.2 specifies declarative environment records with mutable
546// and immutable bindings that can be in two states: initialized and
547// uninitialized. In ES5 only immutable bindings have these two states. When
548// accessing a binding, it needs to be checked for initialization. However in
549// the following cases the binding is initialized immediately after creation
550// so the initialization check can always be skipped:
551// 1. Var declared local variables.
552// var foo;
553// 2. A local variable introduced by a function declaration.
554// function foo() {}
555// 3. Parameters
556// function x(foo) {}
557// 4. Catch bound variables.
558// try {} catch (foo) {}
559// 6. Function variables of named function expressions.
560// var x = function foo() {}
561// 7. Implicit binding of 'this'.
562// 8. Implicit binding of 'arguments' in functions.
563//
564// ES5 specified object environment records which are introduced by ES elements
565// such as Program and WithStatement that associate identifier bindings with the
566// properties of some object. In the specification only mutable bindings exist
567// (which may be non-writable) and have no distinct initialization step. However
568// V8 allows const declarations in global code with distinct creation and
569// initialization steps which are represented by non-writable properties in the
570// global object. As a result also these bindings need to be checked for
571// initialization.
572//
573// The following enum specifies a flag that indicates if the binding needs a
574// distinct initialization step (kNeedsInitialization) or if the binding is
575// immediately initialized upon creation (kCreatedInitialized).
576enum InitializationFlag {
577 kNeedsInitialization,
578 kCreatedInitialized
579};
580
581
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000582enum ClearExceptionFlag {
583 KEEP_EXCEPTION,
584 CLEAR_EXCEPTION
585};
586
587
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +0000588} } // namespace v8::internal
589
590#endif // V8_V8GLOBALS_H_