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