yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 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" |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 32 | #include "checks.h" |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 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 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 51 | // Desired alignment for double values. |
| 52 | const intptr_t kDoubleAlignment = 8; |
| 53 | const intptr_t kDoubleAlignmentMask = kDoubleAlignment - 1; |
| 54 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 55 | // Desired alignment for generated code is 32 bytes (to improve cache line |
| 56 | // utilization). |
| 57 | const int kCodeAlignmentBits = 5; |
| 58 | const intptr_t kCodeAlignment = 1 << kCodeAlignmentBits; |
| 59 | const intptr_t kCodeAlignmentMask = kCodeAlignment - 1; |
| 60 | |
| 61 | // Tag information for Failure. |
| 62 | const int kFailureTag = 3; |
| 63 | const int kFailureTagSize = 2; |
| 64 | const intptr_t kFailureTagMask = (1 << kFailureTagSize) - 1; |
| 65 | |
| 66 | |
| 67 | // Zap-value: The value used for zapping dead objects. |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 68 | // Should be a recognizable hex value tagged as a failure. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 69 | #ifdef V8_HOST_ARCH_64_BIT |
| 70 | const Address kZapValue = |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 71 | reinterpret_cast<Address>(V8_UINT64_C(0xdeadbeedbeadbeef)); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 72 | const Address kHandleZapValue = |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 73 | reinterpret_cast<Address>(V8_UINT64_C(0x1baddead0baddeaf)); |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 74 | const Address kGlobalHandleZapValue = |
| 75 | reinterpret_cast<Address>(V8_UINT64_C(0x1baffed00baffedf)); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 76 | const Address kFromSpaceZapValue = |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 77 | reinterpret_cast<Address>(V8_UINT64_C(0x1beefdad0beefdaf)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 78 | const uint64_t kDebugZapValue = V8_UINT64_C(0xbadbaddbbadbaddb); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 79 | const uint64_t kSlotsZapValue = V8_UINT64_C(0xbeefdeadbeefdeef); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 80 | const uint64_t kFreeListZapValue = 0xfeed1eaffeed1eaf; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 81 | #else |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 82 | const Address kZapValue = reinterpret_cast<Address>(0xdeadbeef); |
| 83 | const Address kHandleZapValue = reinterpret_cast<Address>(0xbaddeaf); |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 84 | const Address kGlobalHandleZapValue = reinterpret_cast<Address>(0xbaffedf); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 85 | const Address kFromSpaceZapValue = reinterpret_cast<Address>(0xbeefdaf); |
| 86 | const uint32_t kSlotsZapValue = 0xbeefdeef; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 87 | const uint32_t kDebugZapValue = 0xbadbaddb; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 88 | const uint32_t kFreeListZapValue = 0xfeed1eaf; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 89 | #endif |
| 90 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 91 | const int kCodeZapValue = 0xbadc0de; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 92 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 93 | // Number of bits to represent the page size for paged spaces. The value of 20 |
| 94 | // gives 1Mb bytes per page. |
| 95 | const int kPageSizeBits = 20; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 96 | |
| 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. |
rossberg@chromium.org | 9259716 | 2013-08-23 13:28:00 +0000 | [diff] [blame] | 100 | #define PROCESSOR_CACHE_LINE_SIZE 64 |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 101 | |
| 102 | // Constants relevant to double precision floating point numbers. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 103 | // If looking only at the top 32 bits, the QNaN mask is bits 19 to 30. |
| 104 | const uint32_t kQuietNaNHighBitsMask = 0xfff << (51 - 32); |
| 105 | |
| 106 | |
| 107 | // ----------------------------------------------------------------------------- |
| 108 | // Forward declarations for frequently used classes |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 109 | |
| 110 | class AccessorInfo; |
| 111 | class Allocation; |
| 112 | class Arguments; |
| 113 | class Assembler; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 114 | class Code; |
| 115 | class CodeGenerator; |
| 116 | class CodeStub; |
| 117 | class Context; |
| 118 | class Debug; |
| 119 | class Debugger; |
| 120 | class DebugInfo; |
| 121 | class Descriptor; |
| 122 | class DescriptorArray; |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 123 | class TransitionArray; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 124 | class ExternalReference; |
| 125 | class FixedArray; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 126 | class FunctionTemplateInfo; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 127 | class MemoryChunk; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 128 | class SeededNumberDictionary; |
| 129 | class UnseededNumberDictionary; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 130 | class NameDictionary; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 131 | template <typename T> class Handle; |
| 132 | class Heap; |
| 133 | class HeapObject; |
| 134 | class IC; |
| 135 | class InterceptorInfo; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 136 | class JSReceiver; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 137 | class JSArray; |
| 138 | class JSFunction; |
| 139 | class JSObject; |
| 140 | class LargeObjectSpace; |
| 141 | class LookupResult; |
| 142 | class MacroAssembler; |
| 143 | class Map; |
| 144 | class MapSpace; |
| 145 | class MarkCompactCollector; |
| 146 | class NewSpace; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 147 | class Object; |
| 148 | class MaybeObject; |
| 149 | class OldSpace; |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 150 | class Foreign; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 151 | class Scope; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 152 | class ScopeInfo; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 153 | class Script; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 154 | class Smi; |
| 155 | template <typename Config, class Allocator = FreeStoreAllocationPolicy> |
| 156 | class SplayTree; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 157 | class String; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 158 | class Name; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 159 | class Struct; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 160 | class Variable; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 161 | class RelocInfo; |
| 162 | class Deserializer; |
| 163 | class MessageLocation; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 164 | class VirtualMemory; |
| 165 | class Mutex; |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 166 | class RecursiveMutex; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 167 | |
| 168 | typedef bool (*WeakSlotCallback)(Object** pointer); |
| 169 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 170 | typedef bool (*WeakSlotCallbackWithHeap)(Heap* heap, Object** pointer); |
| 171 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 172 | // ----------------------------------------------------------------------------- |
| 173 | // Miscellaneous |
| 174 | |
| 175 | // NOTE: SpaceIterator depends on AllocationSpace enumeration values being |
| 176 | // consecutive. |
| 177 | enum AllocationSpace { |
| 178 | NEW_SPACE, // Semispaces collected with copying collector. |
| 179 | OLD_POINTER_SPACE, // May contain pointers to new space. |
| 180 | OLD_DATA_SPACE, // Must not have pointers to new space. |
| 181 | CODE_SPACE, // No pointers to new space, marked executable. |
| 182 | MAP_SPACE, // Only and all map objects. |
| 183 | CELL_SPACE, // Only and all cell objects. |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 184 | PROPERTY_CELL_SPACE, // Only and all global property cell objects. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 185 | LO_SPACE, // Promoted large objects. |
| 186 | |
| 187 | FIRST_SPACE = NEW_SPACE, |
| 188 | LAST_SPACE = LO_SPACE, |
| 189 | FIRST_PAGED_SPACE = OLD_POINTER_SPACE, |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 190 | LAST_PAGED_SPACE = PROPERTY_CELL_SPACE |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 191 | }; |
| 192 | const int kSpaceTagSize = 3; |
| 193 | const int kSpaceTagMask = (1 << kSpaceTagSize) - 1; |
| 194 | |
| 195 | |
| 196 | // A flag that indicates whether objects should be pretenured when |
| 197 | // allocated (allocated directly into the old generation) or not |
| 198 | // (allocated in the young generation if the object size and type |
| 199 | // allows). |
| 200 | enum PretenureFlag { NOT_TENURED, TENURED }; |
| 201 | |
| 202 | enum GarbageCollector { SCAVENGER, MARK_COMPACTOR }; |
| 203 | |
| 204 | enum Executability { NOT_EXECUTABLE, EXECUTABLE }; |
| 205 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 206 | enum VisitMode { |
| 207 | VISIT_ALL, |
| 208 | VISIT_ALL_IN_SCAVENGE, |
| 209 | VISIT_ALL_IN_SWEEP_NEWSPACE, |
| 210 | VISIT_ONLY_STRONG |
| 211 | }; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 212 | |
| 213 | // Flag indicating whether code is built into the VM (one of the natives files). |
| 214 | enum NativesFlag { NOT_NATIVES_CODE, NATIVES_CODE }; |
| 215 | |
| 216 | |
| 217 | // A CodeDesc describes a buffer holding instructions and relocation |
| 218 | // information. The instructions start at the beginning of the buffer |
| 219 | // and grow forward, the relocation information starts at the end of |
| 220 | // the buffer and grows backward. |
| 221 | // |
| 222 | // |<--------------- buffer_size ---------------->| |
| 223 | // |<-- instr_size -->| |<-- reloc_size -->| |
| 224 | // +==================+========+==================+ |
| 225 | // | instructions | free | reloc info | |
| 226 | // +==================+========+==================+ |
| 227 | // ^ |
| 228 | // | |
| 229 | // buffer |
| 230 | |
| 231 | struct CodeDesc { |
| 232 | byte* buffer; |
| 233 | int buffer_size; |
| 234 | int instr_size; |
| 235 | int reloc_size; |
| 236 | Assembler* origin; |
| 237 | }; |
| 238 | |
| 239 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 240 | // Callback function used for iterating objects in heap spaces, |
| 241 | // for example, scanning heap objects. |
| 242 | typedef int (*HeapObjectCallback)(HeapObject* obj); |
| 243 | |
| 244 | |
| 245 | // Callback function used for checking constraints when copying/relocating |
| 246 | // objects. Returns true if an object can be copied/relocated from its |
| 247 | // old_addr to a new_addr. |
| 248 | typedef bool (*ConstraintCallback)(Address new_addr, Address old_addr); |
| 249 | |
| 250 | |
| 251 | // Callback function on inline caches, used for iterating over inline caches |
| 252 | // in compiled code. |
| 253 | typedef void (*InlineCacheCallback)(Code* code, Address ic); |
| 254 | |
| 255 | |
| 256 | // State for inline cache call sites. Aliased as IC::State. |
| 257 | enum InlineCacheState { |
| 258 | // Has never been executed. |
| 259 | UNINITIALIZED, |
| 260 | // Has been executed but monomorhic state has been delayed. |
| 261 | PREMONOMORPHIC, |
| 262 | // Has been executed and only one receiver type has been seen. |
| 263 | MONOMORPHIC, |
| 264 | // Like MONOMORPHIC but check failed due to prototype. |
| 265 | MONOMORPHIC_PROTOTYPE_FAILURE, |
| 266 | // Multiple receiver types have been seen. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 267 | POLYMORPHIC, |
| 268 | // Many receiver types have been seen. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 269 | MEGAMORPHIC, |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 270 | // A generic handler is installed and no extra typefeedback is recorded. |
| 271 | GENERIC, |
yangguo@chromium.org | 9768bf1 | 2013-01-11 14:51:07 +0000 | [diff] [blame] | 272 | // Special state for debug break or step in prepare stubs. |
| 273 | DEBUG_STUB |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 274 | }; |
| 275 | |
| 276 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 277 | enum CheckType { |
| 278 | RECEIVER_MAP_CHECK, |
| 279 | STRING_CHECK, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 280 | SYMBOL_CHECK, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 281 | NUMBER_CHECK, |
| 282 | BOOLEAN_CHECK |
| 283 | }; |
| 284 | |
| 285 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 286 | enum CallFunctionFlags { |
| 287 | NO_CALL_FUNCTION_FLAGS = 0, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 288 | // Receiver might implicitly be the global objects. If it is, the |
| 289 | // hole is passed to the call function stub. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 290 | RECEIVER_MIGHT_BE_IMPLICIT = 1 << 0, |
| 291 | // The call target is cached in the instruction stream. |
| 292 | RECORD_CALL_TARGET = 1 << 1 |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 293 | }; |
| 294 | |
| 295 | |
| 296 | enum InlineCacheHolderFlag { |
| 297 | OWN_MAP, // For fast properties objects. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 298 | PROTOTYPE_MAP // For slow properties objects (except GlobalObjects). |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 299 | }; |
| 300 | |
| 301 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 302 | // The Store Buffer (GC). |
| 303 | typedef enum { |
| 304 | kStoreBufferFullEvent, |
| 305 | kStoreBufferStartScanningPagesEvent, |
| 306 | kStoreBufferScanningPageEvent |
| 307 | } StoreBufferEvent; |
| 308 | |
| 309 | |
| 310 | typedef void (*StoreBufferCallback)(Heap* heap, |
| 311 | MemoryChunk* page, |
| 312 | StoreBufferEvent event); |
| 313 | |
| 314 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 315 | // Union used for fast testing of specific double values. |
| 316 | union DoubleRepresentation { |
| 317 | double value; |
| 318 | int64_t bits; |
| 319 | DoubleRepresentation(double x) { value = x; } |
| 320 | }; |
| 321 | |
| 322 | |
| 323 | // Union used for customized checking of the IEEE double types |
| 324 | // inlined within v8 runtime, rather than going to the underlying |
| 325 | // platform headers and libraries |
| 326 | union IeeeDoubleLittleEndianArchType { |
| 327 | double d; |
| 328 | struct { |
| 329 | unsigned int man_low :32; |
| 330 | unsigned int man_high :20; |
| 331 | unsigned int exp :11; |
| 332 | unsigned int sign :1; |
| 333 | } bits; |
| 334 | }; |
| 335 | |
| 336 | |
| 337 | union IeeeDoubleBigEndianArchType { |
| 338 | double d; |
| 339 | struct { |
| 340 | unsigned int sign :1; |
| 341 | unsigned int exp :11; |
| 342 | unsigned int man_high :20; |
| 343 | unsigned int man_low :32; |
| 344 | } bits; |
| 345 | }; |
| 346 | |
| 347 | |
| 348 | // AccessorCallback |
| 349 | struct AccessorDescriptor { |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 350 | MaybeObject* (*getter)(Isolate* isolate, Object* object, void* data); |
| 351 | MaybeObject* (*setter)( |
| 352 | Isolate* isolate, JSObject* object, Object* value, void* data); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 353 | void* data; |
| 354 | }; |
| 355 | |
| 356 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 357 | // Logging and profiling. A StateTag represents a possible state of |
| 358 | // the VM. The logger maintains a stack of these. Creating a VMState |
| 359 | // object enters a state by pushing on the stack, and destroying a |
| 360 | // VMState object leaves a state by popping the current state from the |
| 361 | // stack. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 362 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 363 | enum StateTag { |
jkummerow@chromium.org | 5323a9c | 2012-12-10 19:00:50 +0000 | [diff] [blame] | 364 | JS, |
| 365 | GC, |
| 366 | COMPILER, |
jkummerow@chromium.org | 5323a9c | 2012-12-10 19:00:50 +0000 | [diff] [blame] | 367 | OTHER, |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 368 | EXTERNAL, |
| 369 | IDLE |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 370 | }; |
| 371 | |
| 372 | |
| 373 | // ----------------------------------------------------------------------------- |
| 374 | // Macros |
| 375 | |
| 376 | // Testers for test. |
| 377 | |
| 378 | #define HAS_SMI_TAG(value) \ |
| 379 | ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag) |
| 380 | |
| 381 | #define HAS_FAILURE_TAG(value) \ |
| 382 | ((reinterpret_cast<intptr_t>(value) & kFailureTagMask) == kFailureTag) |
| 383 | |
| 384 | // OBJECT_POINTER_ALIGN returns the value aligned as a HeapObject pointer |
| 385 | #define OBJECT_POINTER_ALIGN(value) \ |
| 386 | (((value) + kObjectAlignmentMask) & ~kObjectAlignmentMask) |
| 387 | |
| 388 | // POINTER_SIZE_ALIGN returns the value aligned as a pointer. |
| 389 | #define POINTER_SIZE_ALIGN(value) \ |
| 390 | (((value) + kPointerAlignmentMask) & ~kPointerAlignmentMask) |
| 391 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 392 | // CODE_POINTER_ALIGN returns the value aligned as a generated code segment. |
| 393 | #define CODE_POINTER_ALIGN(value) \ |
| 394 | (((value) + kCodeAlignmentMask) & ~kCodeAlignmentMask) |
| 395 | |
| 396 | // Support for tracking C++ memory allocation. Insert TRACK_MEMORY("Fisk") |
| 397 | // inside a C++ class and new and delete will be overloaded so logging is |
| 398 | // performed. |
| 399 | // This file (globals.h) is included before log.h, so we use direct calls to |
| 400 | // the Logger rather than the LOG macro. |
| 401 | #ifdef DEBUG |
| 402 | #define TRACK_MEMORY(name) \ |
| 403 | void* operator new(size_t size) { \ |
| 404 | void* result = ::operator new(size); \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 405 | Logger::NewEventStatic(name, result, size); \ |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 406 | return result; \ |
| 407 | } \ |
| 408 | void operator delete(void* object) { \ |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 409 | Logger::DeleteEventStatic(name, object); \ |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 410 | ::operator delete(object); \ |
| 411 | } |
| 412 | #else |
| 413 | #define TRACK_MEMORY(name) |
| 414 | #endif |
| 415 | |
| 416 | |
| 417 | // Feature flags bit positions. They are mostly based on the CPUID spec. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 418 | // On X86/X64, values below 32 are bits in EDX, values above 32 are bits in ECX. |
| 419 | enum CpuFeature { SSE4_1 = 32 + 19, // x86 |
| 420 | SSE3 = 32 + 0, // x86 |
| 421 | SSE2 = 26, // x86 |
| 422 | CMOV = 15, // x86 |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 423 | VFP3 = 1, // ARM |
| 424 | ARMv7 = 2, // ARM |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 425 | SUDIV = 3, // ARM |
| 426 | UNALIGNED_ACCESSES = 4, // ARM |
| 427 | MOVW_MOVT_IMMEDIATE_LOADS = 5, // ARM |
| 428 | VFP32DREGS = 6, // ARM |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 429 | NEON = 7, // ARM |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 430 | SAHF = 0, // x86 |
| 431 | FPU = 1}; // MIPS |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 432 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 433 | |
| 434 | // Used to specify if a macro instruction must perform a smi check on tagged |
| 435 | // values. |
| 436 | enum SmiCheckType { |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 437 | DONT_DO_SMI_CHECK, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 438 | DO_SMI_CHECK |
| 439 | }; |
| 440 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 441 | |
| 442 | // Used to specify whether a receiver is implicitly or explicitly |
| 443 | // provided to a call. |
| 444 | enum CallKind { |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 445 | CALL_AS_METHOD, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 446 | CALL_AS_FUNCTION |
| 447 | }; |
| 448 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 449 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 450 | enum ScopeType { |
| 451 | EVAL_SCOPE, // The top-level scope for an eval source. |
| 452 | FUNCTION_SCOPE, // The top-level scope for a function. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 453 | MODULE_SCOPE, // The scope introduced by a module literal |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 454 | GLOBAL_SCOPE, // The top-level scope for a program or a top-level eval. |
| 455 | CATCH_SCOPE, // The scope introduced by catch. |
| 456 | BLOCK_SCOPE, // The scope introduced by a new block. |
| 457 | WITH_SCOPE // The scope introduced by with. |
| 458 | }; |
| 459 | |
| 460 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 461 | const uint32_t kHoleNanUpper32 = 0x7FFFFFFF; |
| 462 | const uint32_t kHoleNanLower32 = 0xFFFFFFFF; |
| 463 | const uint32_t kNaNOrInfinityLowerBoundUpper32 = 0x7FF00000; |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 464 | |
| 465 | const uint64_t kHoleNanInt64 = |
| 466 | (static_cast<uint64_t>(kHoleNanUpper32) << 32) | kHoleNanLower32; |
| 467 | const uint64_t kLastNonNaNInt64 = |
| 468 | (static_cast<uint64_t>(kNaNOrInfinityLowerBoundUpper32) << 32); |
| 469 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 470 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 471 | // The order of this enum has to be kept in sync with the predicates below. |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 472 | enum VariableMode { |
| 473 | // User declared variables: |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 474 | VAR, // declared via 'var', and 'function' declarations |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 475 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 476 | CONST, // declared via 'const' declarations |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 477 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 478 | LET, // declared via 'let' declarations (first lexical) |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 479 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 480 | CONST_HARMONY, // declared via 'const' declarations in harmony mode |
| 481 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 482 | MODULE, // declared via 'module' declaration (last lexical) |
| 483 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 484 | // Variables introduced by the compiler: |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 485 | INTERNAL, // like VAR, but not user-visible (may or may not |
| 486 | // be in a context) |
| 487 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 488 | TEMPORARY, // temporary variables (not user-visible), stack-allocated |
| 489 | // unless the scope as a whole has forced context allocation |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 490 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 491 | DYNAMIC, // always require dynamic lookup (we don't know |
| 492 | // the declaration) |
| 493 | |
| 494 | DYNAMIC_GLOBAL, // requires dynamic lookup, but we know that the |
| 495 | // variable is global unless it has been shadowed |
| 496 | // by an eval-introduced variable |
| 497 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 498 | DYNAMIC_LOCAL // requires dynamic lookup, but we know that the |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 499 | // variable is local and where it is unless it |
| 500 | // has been shadowed by an eval-introduced |
| 501 | // variable |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 502 | }; |
| 503 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 504 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 505 | inline bool IsDynamicVariableMode(VariableMode mode) { |
| 506 | return mode >= DYNAMIC && mode <= DYNAMIC_LOCAL; |
| 507 | } |
| 508 | |
| 509 | |
| 510 | inline bool IsDeclaredVariableMode(VariableMode mode) { |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 511 | return mode >= VAR && mode <= MODULE; |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | |
| 515 | inline bool IsLexicalVariableMode(VariableMode mode) { |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 516 | return mode >= LET && mode <= MODULE; |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | |
| 520 | inline bool IsImmutableVariableMode(VariableMode mode) { |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 521 | return mode == CONST || (mode >= CONST_HARMONY && mode <= MODULE); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 525 | // ES6 Draft Rev3 10.2 specifies declarative environment records with mutable |
| 526 | // and immutable bindings that can be in two states: initialized and |
| 527 | // uninitialized. In ES5 only immutable bindings have these two states. When |
| 528 | // accessing a binding, it needs to be checked for initialization. However in |
| 529 | // the following cases the binding is initialized immediately after creation |
| 530 | // so the initialization check can always be skipped: |
| 531 | // 1. Var declared local variables. |
| 532 | // var foo; |
| 533 | // 2. A local variable introduced by a function declaration. |
| 534 | // function foo() {} |
| 535 | // 3. Parameters |
| 536 | // function x(foo) {} |
| 537 | // 4. Catch bound variables. |
| 538 | // try {} catch (foo) {} |
| 539 | // 6. Function variables of named function expressions. |
| 540 | // var x = function foo() {} |
| 541 | // 7. Implicit binding of 'this'. |
| 542 | // 8. Implicit binding of 'arguments' in functions. |
| 543 | // |
| 544 | // ES5 specified object environment records which are introduced by ES elements |
| 545 | // such as Program and WithStatement that associate identifier bindings with the |
| 546 | // properties of some object. In the specification only mutable bindings exist |
| 547 | // (which may be non-writable) and have no distinct initialization step. However |
| 548 | // V8 allows const declarations in global code with distinct creation and |
| 549 | // initialization steps which are represented by non-writable properties in the |
| 550 | // global object. As a result also these bindings need to be checked for |
| 551 | // initialization. |
| 552 | // |
| 553 | // The following enum specifies a flag that indicates if the binding needs a |
| 554 | // distinct initialization step (kNeedsInitialization) or if the binding is |
| 555 | // immediately initialized upon creation (kCreatedInitialized). |
| 556 | enum InitializationFlag { |
| 557 | kNeedsInitialization, |
| 558 | kCreatedInitialized |
| 559 | }; |
| 560 | |
| 561 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 562 | enum ClearExceptionFlag { |
| 563 | KEEP_EXCEPTION, |
| 564 | CLEAR_EXCEPTION |
| 565 | }; |
| 566 | |
| 567 | |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 568 | enum MinusZeroMode { |
| 569 | TREAT_MINUS_ZERO_AS_ZERO, |
| 570 | FAIL_ON_MINUS_ZERO |
| 571 | }; |
| 572 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 573 | } } // namespace v8::internal |
| 574 | |
| 575 | #endif // V8_V8GLOBALS_H_ |