Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1 | // Copyright 2015 the V8 project authors. All rights reserved. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4 | |
| 5 | #ifndef V8_OBJECTS_H_ |
| 6 | #define V8_OBJECTS_H_ |
| 7 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8 | #include <iosfwd> |
| 9 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10 | #include "src/assert-scope.h" |
| 11 | #include "src/bailout-reason.h" |
| 12 | #include "src/base/bits.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 13 | #include "src/base/flags.h" |
| 14 | #include "src/base/smart-pointers.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 15 | #include "src/builtins.h" |
| 16 | #include "src/checks.h" |
| 17 | #include "src/elements-kind.h" |
| 18 | #include "src/field-index.h" |
| 19 | #include "src/flags.h" |
| 20 | #include "src/list.h" |
| 21 | #include "src/property-details.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 22 | #include "src/unicode.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 23 | #include "src/unicode-decoder.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 24 | #include "src/zone.h" |
| 25 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 26 | #if V8_TARGET_ARCH_ARM |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 27 | #include "src/arm/constants-arm.h" // NOLINT |
| 28 | #elif V8_TARGET_ARCH_ARM64 |
| 29 | #include "src/arm64/constants-arm64.h" // NOLINT |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 30 | #elif V8_TARGET_ARCH_MIPS |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 31 | #include "src/mips/constants-mips.h" // NOLINT |
| 32 | #elif V8_TARGET_ARCH_MIPS64 |
| 33 | #include "src/mips64/constants-mips64.h" // NOLINT |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 34 | #elif V8_TARGET_ARCH_PPC |
| 35 | #include "src/ppc/constants-ppc.h" // NOLINT |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 36 | #elif V8_TARGET_ARCH_S390 |
| 37 | #include "src/s390/constants-s390.h" // NOLINT |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 38 | #endif |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 39 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 40 | |
| 41 | // |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 42 | // Most object types in the V8 JavaScript are described in this file. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 43 | // |
| 44 | // Inheritance hierarchy: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 45 | // - Object |
| 46 | // - Smi (immediate small integer) |
| 47 | // - HeapObject (superclass for everything allocated in the heap) |
| 48 | // - JSReceiver (suitable for property access) |
| 49 | // - JSObject |
| 50 | // - JSArray |
| 51 | // - JSArrayBuffer |
| 52 | // - JSArrayBufferView |
| 53 | // - JSTypedArray |
| 54 | // - JSDataView |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 55 | // - JSBoundFunction |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 56 | // - JSCollection |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 57 | // - JSSet |
| 58 | // - JSMap |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 59 | // - JSSetIterator |
| 60 | // - JSMapIterator |
| 61 | // - JSWeakCollection |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 62 | // - JSWeakMap |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 63 | // - JSWeakSet |
| 64 | // - JSRegExp |
| 65 | // - JSFunction |
| 66 | // - JSGeneratorObject |
| 67 | // - JSModule |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 68 | // - JSGlobalObject |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 69 | // - JSGlobalProxy |
| 70 | // - JSValue |
| 71 | // - JSDate |
| 72 | // - JSMessageObject |
| 73 | // - JSProxy |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 74 | // - FixedArrayBase |
| 75 | // - ByteArray |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 76 | // - BytecodeArray |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 77 | // - FixedArray |
| 78 | // - DescriptorArray |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 79 | // - LiteralsArray |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 80 | // - HashTable |
| 81 | // - Dictionary |
| 82 | // - StringTable |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 83 | // - StringSet |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 84 | // - CompilationCacheTable |
| 85 | // - CodeCacheHashTable |
| 86 | // - MapCache |
| 87 | // - OrderedHashTable |
| 88 | // - OrderedHashSet |
| 89 | // - OrderedHashMap |
| 90 | // - Context |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 91 | // - TypeFeedbackMetadata |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 92 | // - TypeFeedbackVector |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 93 | // - ScopeInfo |
| 94 | // - TransitionArray |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 95 | // - ScriptContextTable |
| 96 | // - WeakFixedArray |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 97 | // - FixedDoubleArray |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 98 | // - Name |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 99 | // - String |
| 100 | // - SeqString |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 101 | // - SeqOneByteString |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 102 | // - SeqTwoByteString |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 103 | // - SlicedString |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 104 | // - ConsString |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 105 | // - ExternalString |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 106 | // - ExternalOneByteString |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 107 | // - ExternalTwoByteString |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 108 | // - InternalizedString |
| 109 | // - SeqInternalizedString |
| 110 | // - SeqOneByteInternalizedString |
| 111 | // - SeqTwoByteInternalizedString |
| 112 | // - ConsInternalizedString |
| 113 | // - ExternalInternalizedString |
| 114 | // - ExternalOneByteInternalizedString |
| 115 | // - ExternalTwoByteInternalizedString |
| 116 | // - Symbol |
| 117 | // - HeapNumber |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 118 | // - Simd128Value |
| 119 | // - Float32x4 |
| 120 | // - Int32x4 |
| 121 | // - Uint32x4 |
| 122 | // - Bool32x4 |
| 123 | // - Int16x8 |
| 124 | // - Uint16x8 |
| 125 | // - Bool16x8 |
| 126 | // - Int8x16 |
| 127 | // - Uint8x16 |
| 128 | // - Bool8x16 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 129 | // - Cell |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 130 | // - PropertyCell |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 131 | // - Code |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 132 | // - AbstractCode, a wrapper around Code or BytecodeArray |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 133 | // - Map |
| 134 | // - Oddball |
| 135 | // - Foreign |
| 136 | // - SharedFunctionInfo |
| 137 | // - Struct |
| 138 | // - Box |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 139 | // - AccessorInfo |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 140 | // - AccessorPair |
| 141 | // - AccessCheckInfo |
| 142 | // - InterceptorInfo |
| 143 | // - CallHandlerInfo |
| 144 | // - TemplateInfo |
| 145 | // - FunctionTemplateInfo |
| 146 | // - ObjectTemplateInfo |
| 147 | // - Script |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 148 | // - DebugInfo |
| 149 | // - BreakPointInfo |
| 150 | // - CodeCache |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 151 | // - PrototypeInfo |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 152 | // - WeakCell |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 153 | // |
| 154 | // Formats of Object*: |
| 155 | // Smi: [31 bit signed int] 0 |
| 156 | // HeapObject: [32 bit direct pointer] (4 byte aligned) | 01 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 157 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 158 | namespace v8 { |
| 159 | namespace internal { |
| 160 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 161 | enum KeyedAccessStoreMode { |
| 162 | STANDARD_STORE, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 163 | STORE_TRANSITION_TO_OBJECT, |
| 164 | STORE_TRANSITION_TO_DOUBLE, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 165 | STORE_AND_GROW_NO_TRANSITION, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 166 | STORE_AND_GROW_TRANSITION_TO_OBJECT, |
| 167 | STORE_AND_GROW_TRANSITION_TO_DOUBLE, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 168 | STORE_NO_TRANSITION_IGNORE_OUT_OF_BOUNDS, |
| 169 | STORE_NO_TRANSITION_HANDLE_COW |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 170 | }; |
| 171 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 172 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 173 | // Valid hints for the abstract operation ToPrimitive, |
| 174 | // implemented according to ES6, section 7.1.1. |
| 175 | enum class ToPrimitiveHint { kDefault, kNumber, kString }; |
| 176 | |
| 177 | |
| 178 | // Valid hints for the abstract operation OrdinaryToPrimitive, |
| 179 | // implemented according to ES6, section 7.1.1. |
| 180 | enum class OrdinaryToPrimitiveHint { kNumber, kString }; |
| 181 | |
| 182 | |
| 183 | enum TypeofMode : int { INSIDE_TYPEOF, NOT_INSIDE_TYPEOF }; |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 184 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 185 | |
| 186 | enum MutableMode { |
| 187 | MUTABLE, |
| 188 | IMMUTABLE |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 189 | }; |
| 190 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 191 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 192 | enum ExternalArrayType { |
| 193 | kExternalInt8Array = 1, |
| 194 | kExternalUint8Array, |
| 195 | kExternalInt16Array, |
| 196 | kExternalUint16Array, |
| 197 | kExternalInt32Array, |
| 198 | kExternalUint32Array, |
| 199 | kExternalFloat32Array, |
| 200 | kExternalFloat64Array, |
| 201 | kExternalUint8ClampedArray, |
| 202 | }; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 203 | |
| 204 | |
| 205 | static inline bool IsTransitionStoreMode(KeyedAccessStoreMode store_mode) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 206 | return store_mode == STORE_TRANSITION_TO_OBJECT || |
| 207 | store_mode == STORE_TRANSITION_TO_DOUBLE || |
| 208 | store_mode == STORE_AND_GROW_TRANSITION_TO_OBJECT || |
| 209 | store_mode == STORE_AND_GROW_TRANSITION_TO_DOUBLE; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | |
| 213 | static inline KeyedAccessStoreMode GetNonTransitioningStoreMode( |
| 214 | KeyedAccessStoreMode store_mode) { |
| 215 | if (store_mode >= STORE_NO_TRANSITION_IGNORE_OUT_OF_BOUNDS) { |
| 216 | return store_mode; |
| 217 | } |
| 218 | if (store_mode >= STORE_AND_GROW_NO_TRANSITION) { |
| 219 | return STORE_AND_GROW_NO_TRANSITION; |
| 220 | } |
| 221 | return STANDARD_STORE; |
| 222 | } |
| 223 | |
| 224 | |
| 225 | static inline bool IsGrowStoreMode(KeyedAccessStoreMode store_mode) { |
| 226 | return store_mode >= STORE_AND_GROW_NO_TRANSITION && |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 227 | store_mode <= STORE_AND_GROW_TRANSITION_TO_DOUBLE; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 228 | } |
| 229 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 230 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 231 | enum IcCheckType { ELEMENT, PROPERTY }; |
| 232 | |
| 233 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 234 | // SKIP_WRITE_BARRIER skips the write barrier. |
| 235 | // UPDATE_WEAK_WRITE_BARRIER skips the marking part of the write barrier and |
| 236 | // only performs the generational part. |
| 237 | // UPDATE_WRITE_BARRIER is doing the full barrier, marking and generational. |
| 238 | enum WriteBarrierMode { |
| 239 | SKIP_WRITE_BARRIER, |
| 240 | UPDATE_WEAK_WRITE_BARRIER, |
| 241 | UPDATE_WRITE_BARRIER |
| 242 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 243 | |
| 244 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 245 | // Indicates whether a value can be loaded as a constant. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 246 | enum StoreMode { ALLOW_IN_DESCRIPTOR, FORCE_FIELD }; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 247 | |
| 248 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 249 | // PropertyNormalizationMode is used to specify whether to keep |
| 250 | // inobject properties when normalizing properties of a JSObject. |
| 251 | enum PropertyNormalizationMode { |
| 252 | CLEAR_INOBJECT_PROPERTIES, |
| 253 | KEEP_INOBJECT_PROPERTIES |
| 254 | }; |
| 255 | |
| 256 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 257 | // Indicates how aggressively the prototype should be optimized. FAST_PROTOTYPE |
| 258 | // will give the fastest result by tailoring the map to the prototype, but that |
| 259 | // will cause polymorphism with other objects. REGULAR_PROTOTYPE is to be used |
| 260 | // (at least for now) when dynamically modifying the prototype chain of an |
| 261 | // object using __proto__ or Object.setPrototypeOf. |
| 262 | enum PrototypeOptimizationMode { REGULAR_PROTOTYPE, FAST_PROTOTYPE }; |
| 263 | |
| 264 | |
| 265 | // Indicates whether transitions can be added to a source map or not. |
| 266 | enum TransitionFlag { |
| 267 | INSERT_TRANSITION, |
| 268 | OMIT_TRANSITION |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 269 | }; |
| 270 | |
| 271 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 272 | // Indicates whether the transition is simple: the target map of the transition |
| 273 | // either extends the current map with a new property, or it modifies the |
| 274 | // property that was added last to the current map. |
| 275 | enum SimpleTransitionFlag { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 276 | SIMPLE_PROPERTY_TRANSITION, |
| 277 | PROPERTY_TRANSITION, |
| 278 | SPECIAL_TRANSITION |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 279 | }; |
| 280 | |
| 281 | |
| 282 | // Indicates whether we are only interested in the descriptors of a particular |
| 283 | // map, or in all descriptors in the descriptor array. |
| 284 | enum DescriptorFlag { |
| 285 | ALL_DESCRIPTORS, |
| 286 | OWN_DESCRIPTORS |
| 287 | }; |
| 288 | |
| 289 | // The GC maintains a bit of information, the MarkingParity, which toggles |
| 290 | // from odd to even and back every time marking is completed. Incremental |
| 291 | // marking can visit an object twice during a marking phase, so algorithms that |
| 292 | // that piggy-back on marking can use the parity to ensure that they only |
| 293 | // perform an operation on an object once per marking phase: they record the |
| 294 | // MarkingParity when they visit an object, and only re-visit the object when it |
| 295 | // is marked again and the MarkingParity changes. |
| 296 | enum MarkingParity { |
| 297 | NO_MARKING_PARITY, |
| 298 | ODD_MARKING_PARITY, |
| 299 | EVEN_MARKING_PARITY |
| 300 | }; |
| 301 | |
| 302 | // ICs store extra state in a Code object. The default extra state is |
| 303 | // kNoExtraICState. |
| 304 | typedef int ExtraICState; |
| 305 | static const ExtraICState kNoExtraICState = 0; |
| 306 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 307 | // Instance size sentinel for objects of variable size. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 308 | const int kVariableSizeSentinel = 0; |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 309 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 310 | // We may store the unsigned bit field as signed Smi value and do not |
| 311 | // use the sign bit. |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 312 | const int kStubMajorKeyBits = 8; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 313 | const int kStubMinorKeyBits = kSmiValueSize - kStubMajorKeyBits - 1; |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 314 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 315 | // All Maps have a field instance_type containing a InstanceType. |
| 316 | // It describes the type of the instances. |
| 317 | // |
| 318 | // As an example, a JavaScript object is a heap object and its map |
| 319 | // instance_type is JS_OBJECT_TYPE. |
| 320 | // |
| 321 | // The names of the string instance types are intended to systematically |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 322 | // mirror their encoding in the instance_type field of the map. The default |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 323 | // encoding is considered TWO_BYTE. It is not mentioned in the name. ONE_BYTE |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 324 | // encoding is mentioned explicitly in the name. Likewise, the default |
| 325 | // representation is considered sequential. It is not mentioned in the |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 326 | // name. The other representations (e.g. CONS, EXTERNAL) are explicitly |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 327 | // mentioned. Finally, the string is either a STRING_TYPE (if it is a normal |
| 328 | // string) or a INTERNALIZED_STRING_TYPE (if it is a internalized string). |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 329 | // |
| 330 | // NOTE: The following things are some that depend on the string types having |
| 331 | // instance_types that are less than those of all other types: |
| 332 | // HeapObject::Size, HeapObject::IterateBody, the typeof operator, and |
| 333 | // Object::IsString. |
| 334 | // |
| 335 | // NOTE: Everything following JS_VALUE_TYPE is considered a |
| 336 | // JSObject for GC purposes. The first four entries here have typeof |
| 337 | // 'object', whereas JS_FUNCTION_TYPE has typeof 'function'. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 338 | #define INSTANCE_TYPE_LIST(V) \ |
| 339 | V(STRING_TYPE) \ |
| 340 | V(ONE_BYTE_STRING_TYPE) \ |
| 341 | V(CONS_STRING_TYPE) \ |
| 342 | V(CONS_ONE_BYTE_STRING_TYPE) \ |
| 343 | V(SLICED_STRING_TYPE) \ |
| 344 | V(SLICED_ONE_BYTE_STRING_TYPE) \ |
| 345 | V(EXTERNAL_STRING_TYPE) \ |
| 346 | V(EXTERNAL_ONE_BYTE_STRING_TYPE) \ |
| 347 | V(EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE) \ |
| 348 | V(SHORT_EXTERNAL_STRING_TYPE) \ |
| 349 | V(SHORT_EXTERNAL_ONE_BYTE_STRING_TYPE) \ |
| 350 | V(SHORT_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE) \ |
| 351 | \ |
| 352 | V(INTERNALIZED_STRING_TYPE) \ |
| 353 | V(ONE_BYTE_INTERNALIZED_STRING_TYPE) \ |
| 354 | V(EXTERNAL_INTERNALIZED_STRING_TYPE) \ |
| 355 | V(EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE) \ |
| 356 | V(EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE) \ |
| 357 | V(SHORT_EXTERNAL_INTERNALIZED_STRING_TYPE) \ |
| 358 | V(SHORT_EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE) \ |
| 359 | V(SHORT_EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE) \ |
| 360 | \ |
| 361 | V(SYMBOL_TYPE) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 362 | V(SIMD128_VALUE_TYPE) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 363 | \ |
| 364 | V(MAP_TYPE) \ |
| 365 | V(CODE_TYPE) \ |
| 366 | V(ODDBALL_TYPE) \ |
| 367 | V(CELL_TYPE) \ |
| 368 | V(PROPERTY_CELL_TYPE) \ |
| 369 | \ |
| 370 | V(HEAP_NUMBER_TYPE) \ |
| 371 | V(MUTABLE_HEAP_NUMBER_TYPE) \ |
| 372 | V(FOREIGN_TYPE) \ |
| 373 | V(BYTE_ARRAY_TYPE) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 374 | V(BYTECODE_ARRAY_TYPE) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 375 | V(FREE_SPACE_TYPE) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 376 | \ |
| 377 | V(FIXED_INT8_ARRAY_TYPE) \ |
| 378 | V(FIXED_UINT8_ARRAY_TYPE) \ |
| 379 | V(FIXED_INT16_ARRAY_TYPE) \ |
| 380 | V(FIXED_UINT16_ARRAY_TYPE) \ |
| 381 | V(FIXED_INT32_ARRAY_TYPE) \ |
| 382 | V(FIXED_UINT32_ARRAY_TYPE) \ |
| 383 | V(FIXED_FLOAT32_ARRAY_TYPE) \ |
| 384 | V(FIXED_FLOAT64_ARRAY_TYPE) \ |
| 385 | V(FIXED_UINT8_CLAMPED_ARRAY_TYPE) \ |
| 386 | \ |
| 387 | V(FILLER_TYPE) \ |
| 388 | \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 389 | V(ACCESSOR_INFO_TYPE) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 390 | V(ACCESSOR_PAIR_TYPE) \ |
| 391 | V(ACCESS_CHECK_INFO_TYPE) \ |
| 392 | V(INTERCEPTOR_INFO_TYPE) \ |
| 393 | V(CALL_HANDLER_INFO_TYPE) \ |
| 394 | V(FUNCTION_TEMPLATE_INFO_TYPE) \ |
| 395 | V(OBJECT_TEMPLATE_INFO_TYPE) \ |
| 396 | V(SIGNATURE_INFO_TYPE) \ |
| 397 | V(TYPE_SWITCH_INFO_TYPE) \ |
| 398 | V(ALLOCATION_MEMENTO_TYPE) \ |
| 399 | V(ALLOCATION_SITE_TYPE) \ |
| 400 | V(SCRIPT_TYPE) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 401 | V(TYPE_FEEDBACK_INFO_TYPE) \ |
| 402 | V(ALIASED_ARGUMENTS_ENTRY_TYPE) \ |
| 403 | V(BOX_TYPE) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 404 | V(PROTOTYPE_INFO_TYPE) \ |
| 405 | V(SLOPPY_BLOCK_WITH_EVAL_CONTEXT_EXTENSION_TYPE) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 406 | \ |
| 407 | V(FIXED_ARRAY_TYPE) \ |
| 408 | V(FIXED_DOUBLE_ARRAY_TYPE) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 409 | V(SHARED_FUNCTION_INFO_TYPE) \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 410 | V(WEAK_CELL_TYPE) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 411 | V(TRANSITION_ARRAY_TYPE) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 412 | \ |
| 413 | V(JS_MESSAGE_OBJECT_TYPE) \ |
| 414 | \ |
| 415 | V(JS_VALUE_TYPE) \ |
| 416 | V(JS_DATE_TYPE) \ |
| 417 | V(JS_OBJECT_TYPE) \ |
| 418 | V(JS_CONTEXT_EXTENSION_OBJECT_TYPE) \ |
| 419 | V(JS_GENERATOR_OBJECT_TYPE) \ |
| 420 | V(JS_MODULE_TYPE) \ |
| 421 | V(JS_GLOBAL_OBJECT_TYPE) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 422 | V(JS_GLOBAL_PROXY_TYPE) \ |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 423 | V(JS_API_OBJECT_TYPE) \ |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 424 | V(JS_SPECIAL_API_OBJECT_TYPE) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 425 | V(JS_ARRAY_TYPE) \ |
| 426 | V(JS_ARRAY_BUFFER_TYPE) \ |
| 427 | V(JS_TYPED_ARRAY_TYPE) \ |
| 428 | V(JS_DATA_VIEW_TYPE) \ |
| 429 | V(JS_PROXY_TYPE) \ |
| 430 | V(JS_SET_TYPE) \ |
| 431 | V(JS_MAP_TYPE) \ |
| 432 | V(JS_SET_ITERATOR_TYPE) \ |
| 433 | V(JS_MAP_ITERATOR_TYPE) \ |
| 434 | V(JS_WEAK_MAP_TYPE) \ |
| 435 | V(JS_WEAK_SET_TYPE) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 436 | V(JS_PROMISE_TYPE) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 437 | V(JS_REGEXP_TYPE) \ |
| 438 | \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 439 | V(JS_BOUND_FUNCTION_TYPE) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 440 | V(JS_FUNCTION_TYPE) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 441 | V(DEBUG_INFO_TYPE) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 442 | V(BREAK_POINT_INFO_TYPE) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 443 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 444 | // Since string types are not consecutive, this macro is used to |
| 445 | // iterate over them. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 446 | #define STRING_TYPE_LIST(V) \ |
| 447 | V(STRING_TYPE, kVariableSizeSentinel, string, String) \ |
| 448 | V(ONE_BYTE_STRING_TYPE, kVariableSizeSentinel, one_byte_string, \ |
| 449 | OneByteString) \ |
| 450 | V(CONS_STRING_TYPE, ConsString::kSize, cons_string, ConsString) \ |
| 451 | V(CONS_ONE_BYTE_STRING_TYPE, ConsString::kSize, cons_one_byte_string, \ |
| 452 | ConsOneByteString) \ |
| 453 | V(SLICED_STRING_TYPE, SlicedString::kSize, sliced_string, SlicedString) \ |
| 454 | V(SLICED_ONE_BYTE_STRING_TYPE, SlicedString::kSize, sliced_one_byte_string, \ |
| 455 | SlicedOneByteString) \ |
| 456 | V(EXTERNAL_STRING_TYPE, ExternalTwoByteString::kSize, external_string, \ |
| 457 | ExternalString) \ |
| 458 | V(EXTERNAL_ONE_BYTE_STRING_TYPE, ExternalOneByteString::kSize, \ |
| 459 | external_one_byte_string, ExternalOneByteString) \ |
| 460 | V(EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE, ExternalTwoByteString::kSize, \ |
| 461 | external_string_with_one_byte_data, ExternalStringWithOneByteData) \ |
| 462 | V(SHORT_EXTERNAL_STRING_TYPE, ExternalTwoByteString::kShortSize, \ |
| 463 | short_external_string, ShortExternalString) \ |
| 464 | V(SHORT_EXTERNAL_ONE_BYTE_STRING_TYPE, ExternalOneByteString::kShortSize, \ |
| 465 | short_external_one_byte_string, ShortExternalOneByteString) \ |
| 466 | V(SHORT_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE, \ |
| 467 | ExternalTwoByteString::kShortSize, \ |
| 468 | short_external_string_with_one_byte_data, \ |
| 469 | ShortExternalStringWithOneByteData) \ |
| 470 | \ |
| 471 | V(INTERNALIZED_STRING_TYPE, kVariableSizeSentinel, internalized_string, \ |
| 472 | InternalizedString) \ |
| 473 | V(ONE_BYTE_INTERNALIZED_STRING_TYPE, kVariableSizeSentinel, \ |
| 474 | one_byte_internalized_string, OneByteInternalizedString) \ |
| 475 | V(EXTERNAL_INTERNALIZED_STRING_TYPE, ExternalTwoByteString::kSize, \ |
| 476 | external_internalized_string, ExternalInternalizedString) \ |
| 477 | V(EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE, ExternalOneByteString::kSize, \ |
| 478 | external_one_byte_internalized_string, ExternalOneByteInternalizedString) \ |
| 479 | V(EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE, \ |
| 480 | ExternalTwoByteString::kSize, \ |
| 481 | external_internalized_string_with_one_byte_data, \ |
| 482 | ExternalInternalizedStringWithOneByteData) \ |
| 483 | V(SHORT_EXTERNAL_INTERNALIZED_STRING_TYPE, \ |
| 484 | ExternalTwoByteString::kShortSize, short_external_internalized_string, \ |
| 485 | ShortExternalInternalizedString) \ |
| 486 | V(SHORT_EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE, \ |
| 487 | ExternalOneByteString::kShortSize, \ |
| 488 | short_external_one_byte_internalized_string, \ |
| 489 | ShortExternalOneByteInternalizedString) \ |
| 490 | V(SHORT_EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE, \ |
| 491 | ExternalTwoByteString::kShortSize, \ |
| 492 | short_external_internalized_string_with_one_byte_data, \ |
| 493 | ShortExternalInternalizedStringWithOneByteData) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 494 | |
| 495 | // A struct is a simple object a set of object-valued fields. Including an |
| 496 | // object type in this causes the compiler to generate most of the boilerplate |
| 497 | // code for the class including allocation and garbage collection routines, |
| 498 | // casts and predicates. All you need to define is the class, methods and |
| 499 | // object verification routines. Easy, no? |
| 500 | // |
| 501 | // Note that for subtle reasons related to the ordering or numerical values of |
| 502 | // type tags, elements in this list have to be added to the INSTANCE_TYPE_LIST |
| 503 | // manually. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 504 | #define STRUCT_LIST(V) \ |
| 505 | V(BOX, Box, box) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 506 | V(ACCESSOR_INFO, AccessorInfo, accessor_info) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 507 | V(ACCESSOR_PAIR, AccessorPair, accessor_pair) \ |
| 508 | V(ACCESS_CHECK_INFO, AccessCheckInfo, access_check_info) \ |
| 509 | V(INTERCEPTOR_INFO, InterceptorInfo, interceptor_info) \ |
| 510 | V(CALL_HANDLER_INFO, CallHandlerInfo, call_handler_info) \ |
| 511 | V(FUNCTION_TEMPLATE_INFO, FunctionTemplateInfo, function_template_info) \ |
| 512 | V(OBJECT_TEMPLATE_INFO, ObjectTemplateInfo, object_template_info) \ |
| 513 | V(SCRIPT, Script, script) \ |
| 514 | V(ALLOCATION_SITE, AllocationSite, allocation_site) \ |
| 515 | V(ALLOCATION_MEMENTO, AllocationMemento, allocation_memento) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 516 | V(TYPE_FEEDBACK_INFO, TypeFeedbackInfo, type_feedback_info) \ |
| 517 | V(ALIASED_ARGUMENTS_ENTRY, AliasedArgumentsEntry, aliased_arguments_entry) \ |
| 518 | V(DEBUG_INFO, DebugInfo, debug_info) \ |
| 519 | V(BREAK_POINT_INFO, BreakPointInfo, break_point_info) \ |
| 520 | V(PROTOTYPE_INFO, PrototypeInfo, prototype_info) \ |
| 521 | V(SLOPPY_BLOCK_WITH_EVAL_CONTEXT_EXTENSION, \ |
| 522 | SloppyBlockWithEvalContextExtension, \ |
| 523 | sloppy_block_with_eval_context_extension) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 524 | |
| 525 | // We use the full 8 bits of the instance_type field to encode heap object |
| 526 | // instance types. The high-order bit (bit 7) is set if the object is not a |
| 527 | // string, and cleared if it is a string. |
| 528 | const uint32_t kIsNotStringMask = 0x80; |
| 529 | const uint32_t kStringTag = 0x0; |
| 530 | const uint32_t kNotStringTag = 0x80; |
| 531 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 532 | // Bit 6 indicates that the object is an internalized string (if set) or not. |
| 533 | // Bit 7 has to be clear as well. |
| 534 | const uint32_t kIsNotInternalizedMask = 0x40; |
| 535 | const uint32_t kNotInternalizedTag = 0x40; |
| 536 | const uint32_t kInternalizedTag = 0x0; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 537 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 538 | // If bit 7 is clear then bit 2 indicates whether the string consists of |
| 539 | // two-byte characters or one-byte characters. |
| 540 | const uint32_t kStringEncodingMask = 0x4; |
| 541 | const uint32_t kTwoByteStringTag = 0x0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 542 | const uint32_t kOneByteStringTag = 0x4; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 543 | |
| 544 | // If bit 7 is clear, the low-order 2 bits indicate the representation |
| 545 | // of the string. |
| 546 | const uint32_t kStringRepresentationMask = 0x03; |
| 547 | enum StringRepresentationTag { |
| 548 | kSeqStringTag = 0x0, |
| 549 | kConsStringTag = 0x1, |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 550 | kExternalStringTag = 0x2, |
| 551 | kSlicedStringTag = 0x3 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 552 | }; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 553 | const uint32_t kIsIndirectStringMask = 0x1; |
| 554 | const uint32_t kIsIndirectStringTag = 0x1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 555 | STATIC_ASSERT((kSeqStringTag & kIsIndirectStringMask) == 0); // NOLINT |
| 556 | STATIC_ASSERT((kExternalStringTag & kIsIndirectStringMask) == 0); // NOLINT |
| 557 | STATIC_ASSERT((kConsStringTag & |
| 558 | kIsIndirectStringMask) == kIsIndirectStringTag); // NOLINT |
| 559 | STATIC_ASSERT((kSlicedStringTag & |
| 560 | kIsIndirectStringMask) == kIsIndirectStringTag); // NOLINT |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 561 | |
| 562 | // Use this mask to distinguish between cons and slice only after making |
| 563 | // sure that the string is one of the two (an indirect string). |
| 564 | const uint32_t kSlicedNotConsMask = kSlicedStringTag & ~kConsStringTag; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 565 | STATIC_ASSERT(IS_POWER_OF_TWO(kSlicedNotConsMask)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 566 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 567 | // If bit 7 is clear, then bit 3 indicates whether this two-byte |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 568 | // string actually contains one byte data. |
| 569 | const uint32_t kOneByteDataHintMask = 0x08; |
| 570 | const uint32_t kOneByteDataHintTag = 0x08; |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 571 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 572 | // If bit 7 is clear and string representation indicates an external string, |
| 573 | // then bit 4 indicates whether the data pointer is cached. |
| 574 | const uint32_t kShortExternalStringMask = 0x10; |
| 575 | const uint32_t kShortExternalStringTag = 0x10; |
| 576 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 577 | |
| 578 | // A ConsString with an empty string as the right side is a candidate |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 579 | // for being shortcut by the garbage collector. We don't allocate any |
| 580 | // non-flat internalized strings, so we do not shortcut them thereby |
| 581 | // avoiding turning internalized strings into strings. The bit-masks |
| 582 | // below contain the internalized bit as additional safety. |
| 583 | // See heap.cc, mark-compact.cc and objects-visiting.cc. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 584 | const uint32_t kShortcutTypeMask = |
| 585 | kIsNotStringMask | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 586 | kIsNotInternalizedMask | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 587 | kStringRepresentationMask; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 588 | const uint32_t kShortcutTypeTag = kConsStringTag | kNotInternalizedTag; |
| 589 | |
| 590 | static inline bool IsShortcutCandidate(int type) { |
| 591 | return ((type & kShortcutTypeMask) == kShortcutTypeTag); |
| 592 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 593 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 594 | enum InstanceType { |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 595 | // String types. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 596 | INTERNALIZED_STRING_TYPE = kTwoByteStringTag | kSeqStringTag | |
| 597 | kInternalizedTag, // FIRST_PRIMITIVE_TYPE |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 598 | ONE_BYTE_INTERNALIZED_STRING_TYPE = |
| 599 | kOneByteStringTag | kSeqStringTag | kInternalizedTag, |
| 600 | EXTERNAL_INTERNALIZED_STRING_TYPE = |
| 601 | kTwoByteStringTag | kExternalStringTag | kInternalizedTag, |
| 602 | EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE = |
| 603 | kOneByteStringTag | kExternalStringTag | kInternalizedTag, |
| 604 | EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE = |
| 605 | EXTERNAL_INTERNALIZED_STRING_TYPE | kOneByteDataHintTag | |
| 606 | kInternalizedTag, |
| 607 | SHORT_EXTERNAL_INTERNALIZED_STRING_TYPE = EXTERNAL_INTERNALIZED_STRING_TYPE | |
| 608 | kShortExternalStringTag | |
| 609 | kInternalizedTag, |
| 610 | SHORT_EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE = |
| 611 | EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE | kShortExternalStringTag | |
| 612 | kInternalizedTag, |
| 613 | SHORT_EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE = |
| 614 | EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE | |
| 615 | kShortExternalStringTag | kInternalizedTag, |
| 616 | STRING_TYPE = INTERNALIZED_STRING_TYPE | kNotInternalizedTag, |
| 617 | ONE_BYTE_STRING_TYPE = |
| 618 | ONE_BYTE_INTERNALIZED_STRING_TYPE | kNotInternalizedTag, |
| 619 | CONS_STRING_TYPE = kTwoByteStringTag | kConsStringTag | kNotInternalizedTag, |
| 620 | CONS_ONE_BYTE_STRING_TYPE = |
| 621 | kOneByteStringTag | kConsStringTag | kNotInternalizedTag, |
| 622 | SLICED_STRING_TYPE = |
| 623 | kTwoByteStringTag | kSlicedStringTag | kNotInternalizedTag, |
| 624 | SLICED_ONE_BYTE_STRING_TYPE = |
| 625 | kOneByteStringTag | kSlicedStringTag | kNotInternalizedTag, |
| 626 | EXTERNAL_STRING_TYPE = |
| 627 | EXTERNAL_INTERNALIZED_STRING_TYPE | kNotInternalizedTag, |
| 628 | EXTERNAL_ONE_BYTE_STRING_TYPE = |
| 629 | EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE | kNotInternalizedTag, |
| 630 | EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE = |
| 631 | EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE | |
| 632 | kNotInternalizedTag, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 633 | SHORT_EXTERNAL_STRING_TYPE = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 634 | SHORT_EXTERNAL_INTERNALIZED_STRING_TYPE | kNotInternalizedTag, |
| 635 | SHORT_EXTERNAL_ONE_BYTE_STRING_TYPE = |
| 636 | SHORT_EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE | kNotInternalizedTag, |
| 637 | SHORT_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE = |
| 638 | SHORT_EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE | |
| 639 | kNotInternalizedTag, |
| 640 | |
| 641 | // Non-string names |
| 642 | SYMBOL_TYPE = kNotStringTag, // FIRST_NONSTRING_TYPE, LAST_NAME_TYPE |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 643 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 644 | // Other primitives (cannot contain non-map-word pointers to heap objects). |
| 645 | HEAP_NUMBER_TYPE, |
| 646 | SIMD128_VALUE_TYPE, |
| 647 | ODDBALL_TYPE, // LAST_PRIMITIVE_TYPE |
| 648 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 649 | // Objects allocated in their own spaces (never in new space). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 650 | MAP_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 651 | CODE_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 652 | |
| 653 | // "Data", objects that cannot contain non-map-word pointers to heap |
| 654 | // objects. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 655 | MUTABLE_HEAP_NUMBER_TYPE, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 656 | FOREIGN_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 657 | BYTE_ARRAY_TYPE, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 658 | BYTECODE_ARRAY_TYPE, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 659 | FREE_SPACE_TYPE, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 660 | FIXED_INT8_ARRAY_TYPE, // FIRST_FIXED_TYPED_ARRAY_TYPE |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 661 | FIXED_UINT8_ARRAY_TYPE, |
| 662 | FIXED_INT16_ARRAY_TYPE, |
| 663 | FIXED_UINT16_ARRAY_TYPE, |
| 664 | FIXED_INT32_ARRAY_TYPE, |
| 665 | FIXED_UINT32_ARRAY_TYPE, |
| 666 | FIXED_FLOAT32_ARRAY_TYPE, |
| 667 | FIXED_FLOAT64_ARRAY_TYPE, |
| 668 | FIXED_UINT8_CLAMPED_ARRAY_TYPE, // LAST_FIXED_TYPED_ARRAY_TYPE |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 669 | FIXED_DOUBLE_ARRAY_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 670 | FILLER_TYPE, // LAST_DATA_TYPE |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 671 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 672 | // Structs. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 673 | ACCESSOR_INFO_TYPE, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 674 | ACCESSOR_PAIR_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 675 | ACCESS_CHECK_INFO_TYPE, |
| 676 | INTERCEPTOR_INFO_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 677 | CALL_HANDLER_INFO_TYPE, |
| 678 | FUNCTION_TEMPLATE_INFO_TYPE, |
| 679 | OBJECT_TEMPLATE_INFO_TYPE, |
| 680 | SIGNATURE_INFO_TYPE, |
| 681 | TYPE_SWITCH_INFO_TYPE, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 682 | ALLOCATION_SITE_TYPE, |
| 683 | ALLOCATION_MEMENTO_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 684 | SCRIPT_TYPE, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 685 | TYPE_FEEDBACK_INFO_TYPE, |
| 686 | ALIASED_ARGUMENTS_ENTRY_TYPE, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 687 | BOX_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 688 | DEBUG_INFO_TYPE, |
| 689 | BREAK_POINT_INFO_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 690 | FIXED_ARRAY_TYPE, |
| 691 | SHARED_FUNCTION_INFO_TYPE, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 692 | CELL_TYPE, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 693 | WEAK_CELL_TYPE, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 694 | TRANSITION_ARRAY_TYPE, |
| 695 | PROPERTY_CELL_TYPE, |
| 696 | PROTOTYPE_INFO_TYPE, |
| 697 | SLOPPY_BLOCK_WITH_EVAL_CONTEXT_EXTENSION_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 698 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 699 | // All the following types are subtypes of JSReceiver, which corresponds to |
| 700 | // objects in the JS sense. The first and the last type in this range are |
| 701 | // the two forms of function. This organization enables using the same |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 702 | // compares for checking the JS_RECEIVER and the NONCALLABLE_JS_OBJECT range. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 703 | JS_PROXY_TYPE, // FIRST_JS_RECEIVER_TYPE |
| 704 | JS_GLOBAL_OBJECT_TYPE, // FIRST_JS_OBJECT_TYPE |
| 705 | JS_GLOBAL_PROXY_TYPE, |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 706 | // Like JS_API_OBJECT_TYPE, but requires access checks and/or has |
| 707 | // interceptors. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 708 | JS_SPECIAL_API_OBJECT_TYPE, // LAST_SPECIAL_RECEIVER_TYPE |
| 709 | JS_VALUE_TYPE, // LAST_CUSTOM_ELEMENTS_RECEIVER |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 710 | JS_MESSAGE_OBJECT_TYPE, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 711 | JS_DATE_TYPE, |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 712 | // Like JS_OBJECT_TYPE, but created from API function. |
| 713 | JS_API_OBJECT_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 714 | JS_OBJECT_TYPE, |
| 715 | JS_CONTEXT_EXTENSION_OBJECT_TYPE, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 716 | JS_GENERATOR_OBJECT_TYPE, |
| 717 | JS_MODULE_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 718 | JS_ARRAY_TYPE, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 719 | JS_ARRAY_BUFFER_TYPE, |
| 720 | JS_TYPED_ARRAY_TYPE, |
| 721 | JS_DATA_VIEW_TYPE, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 722 | JS_SET_TYPE, |
| 723 | JS_MAP_TYPE, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 724 | JS_SET_ITERATOR_TYPE, |
| 725 | JS_MAP_ITERATOR_TYPE, |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 726 | JS_WEAK_MAP_TYPE, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 727 | JS_WEAK_SET_TYPE, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 728 | JS_PROMISE_TYPE, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 729 | JS_REGEXP_TYPE, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 730 | JS_BOUND_FUNCTION_TYPE, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 731 | JS_FUNCTION_TYPE, // LAST_JS_OBJECT_TYPE, LAST_JS_RECEIVER_TYPE |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 732 | |
| 733 | // Pseudo-types |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 734 | FIRST_TYPE = 0x0, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 735 | LAST_TYPE = JS_FUNCTION_TYPE, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 736 | FIRST_NAME_TYPE = FIRST_TYPE, |
| 737 | LAST_NAME_TYPE = SYMBOL_TYPE, |
| 738 | FIRST_UNIQUE_NAME_TYPE = INTERNALIZED_STRING_TYPE, |
| 739 | LAST_UNIQUE_NAME_TYPE = SYMBOL_TYPE, |
| 740 | FIRST_NONSTRING_TYPE = SYMBOL_TYPE, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 741 | FIRST_PRIMITIVE_TYPE = FIRST_NAME_TYPE, |
| 742 | LAST_PRIMITIVE_TYPE = ODDBALL_TYPE, |
| 743 | FIRST_FUNCTION_TYPE = JS_BOUND_FUNCTION_TYPE, |
| 744 | LAST_FUNCTION_TYPE = JS_FUNCTION_TYPE, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 745 | // Boundaries for testing for a fixed typed array. |
| 746 | FIRST_FIXED_TYPED_ARRAY_TYPE = FIXED_INT8_ARRAY_TYPE, |
| 747 | LAST_FIXED_TYPED_ARRAY_TYPE = FIXED_UINT8_CLAMPED_ARRAY_TYPE, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 748 | // Boundary for promotion to old space. |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 749 | LAST_DATA_TYPE = FILLER_TYPE, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 750 | // Boundary for objects represented as JSReceiver (i.e. JSObject or JSProxy). |
| 751 | // Note that there is no range for JSObject or JSProxy, since their subtypes |
| 752 | // are not continuous in this enum! The enum ranges instead reflect the |
| 753 | // external class names, where proxies are treated as either ordinary objects, |
| 754 | // or functions. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 755 | FIRST_JS_RECEIVER_TYPE = JS_PROXY_TYPE, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 756 | LAST_JS_RECEIVER_TYPE = LAST_TYPE, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 757 | // Boundaries for testing the types represented as JSObject |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 758 | FIRST_JS_OBJECT_TYPE = JS_GLOBAL_OBJECT_TYPE, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 759 | LAST_JS_OBJECT_TYPE = LAST_TYPE, |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 760 | // Boundary for testing JSReceivers that need special property lookup handling |
| 761 | LAST_SPECIAL_RECEIVER_TYPE = JS_SPECIAL_API_OBJECT_TYPE, |
| 762 | // Boundary case for testing JSReceivers that may have elements while having |
| 763 | // an empty fixed array as elements backing store. This is true for string |
| 764 | // wrappers. |
| 765 | LAST_CUSTOM_ELEMENTS_RECEIVER = JS_VALUE_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 766 | }; |
| 767 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 768 | STATIC_ASSERT(JS_OBJECT_TYPE == Internals::kJSObjectType); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 769 | STATIC_ASSERT(JS_API_OBJECT_TYPE == Internals::kJSApiObjectType); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 770 | STATIC_ASSERT(FIRST_NONSTRING_TYPE == Internals::kFirstNonstringType); |
| 771 | STATIC_ASSERT(ODDBALL_TYPE == Internals::kOddballType); |
| 772 | STATIC_ASSERT(FOREIGN_TYPE == Internals::kForeignType); |
| 773 | |
| 774 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 775 | std::ostream& operator<<(std::ostream& os, InstanceType instance_type); |
| 776 | |
| 777 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 778 | #define FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(V) \ |
| 779 | V(FAST_ELEMENTS_SUB_TYPE) \ |
| 780 | V(DICTIONARY_ELEMENTS_SUB_TYPE) \ |
| 781 | V(FAST_PROPERTIES_SUB_TYPE) \ |
| 782 | V(DICTIONARY_PROPERTIES_SUB_TYPE) \ |
| 783 | V(MAP_CODE_CACHE_SUB_TYPE) \ |
| 784 | V(SCOPE_INFO_SUB_TYPE) \ |
| 785 | V(STRING_TABLE_SUB_TYPE) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 786 | V(DESCRIPTOR_ARRAY_SUB_TYPE) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 787 | |
| 788 | enum FixedArraySubInstanceType { |
| 789 | #define DEFINE_FIXED_ARRAY_SUB_INSTANCE_TYPE(name) name, |
| 790 | FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(DEFINE_FIXED_ARRAY_SUB_INSTANCE_TYPE) |
| 791 | #undef DEFINE_FIXED_ARRAY_SUB_INSTANCE_TYPE |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 792 | LAST_FIXED_ARRAY_SUB_TYPE = DESCRIPTOR_ARRAY_SUB_TYPE |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 793 | }; |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 794 | |
| 795 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 796 | // TODO(bmeurer): Remove this in favor of the ComparisonResult below. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 797 | enum CompareResult { |
| 798 | LESS = -1, |
| 799 | EQUAL = 0, |
| 800 | GREATER = 1, |
| 801 | |
| 802 | NOT_EQUAL = GREATER |
| 803 | }; |
| 804 | |
| 805 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 806 | // Result of an abstract relational comparison of x and y, implemented according |
| 807 | // to ES6 section 7.2.11 Abstract Relational Comparison. |
| 808 | enum class ComparisonResult { |
| 809 | kLessThan, // x < y |
| 810 | kEqual, // x = y |
| 811 | kGreaterThan, // x > y |
| 812 | kUndefined // at least one of x or y was undefined or NaN |
| 813 | }; |
| 814 | |
| 815 | |
| 816 | #define DECL_BOOLEAN_ACCESSORS(name) \ |
| 817 | inline bool name() const; \ |
| 818 | inline void set_##name(bool value); |
| 819 | |
| 820 | #define DECL_INT_ACCESSORS(name) \ |
| 821 | inline int name() const; \ |
| 822 | inline void set_##name(int value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 823 | |
| 824 | |
| 825 | #define DECL_ACCESSORS(name, type) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 826 | inline type* name() const; \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 827 | inline void set_##name(type* value, \ |
| 828 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); \ |
| 829 | |
| 830 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 831 | #define DECLARE_CAST(type) \ |
| 832 | INLINE(static type* cast(Object* object)); \ |
| 833 | INLINE(static const type* cast(const Object* object)); |
| 834 | |
| 835 | |
| 836 | class AccessorPair; |
| 837 | class AllocationSite; |
| 838 | class AllocationSiteCreationContext; |
| 839 | class AllocationSiteUsageContext; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 840 | class Cell; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 841 | class ConsString; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 842 | class ElementsAccessor; |
| 843 | class FixedArrayBase; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 844 | class FunctionLiteral; |
| 845 | class JSGlobalObject; |
| 846 | class KeyAccumulator; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 847 | class LayoutDescriptor; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 848 | class LiteralsArray; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 849 | class LookupIterator; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 850 | class FieldType; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 851 | class ObjectHashTable; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 852 | class ObjectVisitor; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 853 | class PropertyCell; |
| 854 | class PropertyDescriptor; |
| 855 | class SafepointEntry; |
| 856 | class SharedFunctionInfo; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 857 | class StringStream; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 858 | class TypeFeedbackInfo; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 859 | class TypeFeedbackVector; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 860 | class WeakCell; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 861 | class TransitionArray; |
| 862 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 863 | |
| 864 | // A template-ized version of the IsXXX functions. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 865 | template <class C> inline bool Is(Object* obj); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 866 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 867 | #ifdef VERIFY_HEAP |
| 868 | #define DECLARE_VERIFIER(Name) void Name##Verify(); |
| 869 | #else |
| 870 | #define DECLARE_VERIFIER(Name) |
| 871 | #endif |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 872 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 873 | #ifdef OBJECT_PRINT |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 874 | #define DECLARE_PRINTER(Name) void Name##Print(std::ostream& os); // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 875 | #else |
| 876 | #define DECLARE_PRINTER(Name) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 877 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 878 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 879 | #define OBJECT_TYPE_LIST(V) \ |
| 880 | V(Smi) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 881 | V(LayoutDescriptor) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 882 | V(HeapObject) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 883 | V(Primitive) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 884 | V(Number) |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 885 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 886 | #define HEAP_OBJECT_TYPE_LIST(V) \ |
| 887 | V(HeapNumber) \ |
| 888 | V(MutableHeapNumber) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 889 | V(Simd128Value) \ |
| 890 | V(Float32x4) \ |
| 891 | V(Int32x4) \ |
| 892 | V(Uint32x4) \ |
| 893 | V(Bool32x4) \ |
| 894 | V(Int16x8) \ |
| 895 | V(Uint16x8) \ |
| 896 | V(Bool16x8) \ |
| 897 | V(Int8x16) \ |
| 898 | V(Uint8x16) \ |
| 899 | V(Bool8x16) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 900 | V(Name) \ |
| 901 | V(UniqueName) \ |
| 902 | V(String) \ |
| 903 | V(SeqString) \ |
| 904 | V(ExternalString) \ |
| 905 | V(ConsString) \ |
| 906 | V(SlicedString) \ |
| 907 | V(ExternalTwoByteString) \ |
| 908 | V(ExternalOneByteString) \ |
| 909 | V(SeqTwoByteString) \ |
| 910 | V(SeqOneByteString) \ |
| 911 | V(InternalizedString) \ |
| 912 | V(Symbol) \ |
| 913 | \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 914 | V(FixedTypedArrayBase) \ |
| 915 | V(FixedUint8Array) \ |
| 916 | V(FixedInt8Array) \ |
| 917 | V(FixedUint16Array) \ |
| 918 | V(FixedInt16Array) \ |
| 919 | V(FixedUint32Array) \ |
| 920 | V(FixedInt32Array) \ |
| 921 | V(FixedFloat32Array) \ |
| 922 | V(FixedFloat64Array) \ |
| 923 | V(FixedUint8ClampedArray) \ |
| 924 | V(ByteArray) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 925 | V(BytecodeArray) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 926 | V(FreeSpace) \ |
| 927 | V(JSReceiver) \ |
| 928 | V(JSObject) \ |
| 929 | V(JSContextExtensionObject) \ |
| 930 | V(JSGeneratorObject) \ |
| 931 | V(JSModule) \ |
| 932 | V(Map) \ |
| 933 | V(DescriptorArray) \ |
| 934 | V(TransitionArray) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 935 | V(LiteralsArray) \ |
| 936 | V(TypeFeedbackMetadata) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 937 | V(TypeFeedbackVector) \ |
| 938 | V(DeoptimizationInputData) \ |
| 939 | V(DeoptimizationOutputData) \ |
| 940 | V(DependentCode) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 941 | V(HandlerTable) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 942 | V(FixedArray) \ |
| 943 | V(FixedDoubleArray) \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 944 | V(WeakFixedArray) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 945 | V(ArrayList) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 946 | V(Context) \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 947 | V(ScriptContextTable) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 948 | V(NativeContext) \ |
| 949 | V(ScopeInfo) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 950 | V(JSBoundFunction) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 951 | V(JSFunction) \ |
| 952 | V(Code) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 953 | V(AbstractCode) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 954 | V(Oddball) \ |
| 955 | V(SharedFunctionInfo) \ |
| 956 | V(JSValue) \ |
| 957 | V(JSDate) \ |
| 958 | V(JSMessageObject) \ |
| 959 | V(StringWrapper) \ |
| 960 | V(Foreign) \ |
| 961 | V(Boolean) \ |
| 962 | V(JSArray) \ |
| 963 | V(JSArrayBuffer) \ |
| 964 | V(JSArrayBufferView) \ |
| 965 | V(JSTypedArray) \ |
| 966 | V(JSDataView) \ |
| 967 | V(JSProxy) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 968 | V(JSSet) \ |
| 969 | V(JSMap) \ |
| 970 | V(JSSetIterator) \ |
| 971 | V(JSMapIterator) \ |
| 972 | V(JSWeakCollection) \ |
| 973 | V(JSWeakMap) \ |
| 974 | V(JSWeakSet) \ |
| 975 | V(JSRegExp) \ |
| 976 | V(HashTable) \ |
| 977 | V(Dictionary) \ |
| 978 | V(StringTable) \ |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 979 | V(StringSet) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 980 | V(NormalizedMapCache) \ |
| 981 | V(CompilationCacheTable) \ |
| 982 | V(CodeCacheHashTable) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 983 | V(MapCache) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 984 | V(JSGlobalObject) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 985 | V(JSGlobalProxy) \ |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 986 | V(Undetectable) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 987 | V(AccessCheckNeeded) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 988 | V(Callable) \ |
| 989 | V(Function) \ |
| 990 | V(Constructor) \ |
| 991 | V(TemplateInfo) \ |
| 992 | V(Filler) \ |
| 993 | V(FixedArrayBase) \ |
| 994 | V(External) \ |
| 995 | V(Struct) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 996 | V(Cell) \ |
| 997 | V(PropertyCell) \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 998 | V(WeakCell) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 999 | V(ObjectHashTable) \ |
| 1000 | V(WeakHashTable) \ |
| 1001 | V(OrderedHashTable) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1002 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1003 | #define ODDBALL_LIST(V) \ |
| 1004 | V(Undefined) \ |
| 1005 | V(Null) \ |
| 1006 | V(TheHole) \ |
| 1007 | V(Exception) \ |
| 1008 | V(Uninitialized) \ |
| 1009 | V(True) \ |
| 1010 | V(False) \ |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1011 | V(ArgumentsMarker) \ |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1012 | V(OptimizedOut) \ |
| 1013 | V(StaleRegister) |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1014 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1015 | // The element types selection for CreateListFromArrayLike. |
| 1016 | enum class ElementTypes { kAll, kStringAndSymbol }; |
| 1017 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1018 | // Object is the abstract superclass for all classes in the |
| 1019 | // object hierarchy. |
| 1020 | // Object does not use any virtual functions to avoid the |
| 1021 | // allocation of the C++ vtable. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1022 | // Since both Smi and HeapObject are subclasses of Object no |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1023 | // data members can be present in Object. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1024 | class Object { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1025 | public: |
| 1026 | // Type testing. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1027 | bool IsObject() const { return true; } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1028 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1029 | #define IS_TYPE_FUNCTION_DECL(type_) INLINE(bool Is##type_() const); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1030 | OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL) |
| 1031 | HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL) |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1032 | ODDBALL_LIST(IS_TYPE_FUNCTION_DECL) |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1033 | #undef IS_TYPE_FUNCTION_DECL |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1034 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1035 | // A non-keyed store is of the form a.x = foo or a["x"] = foo whereas |
| 1036 | // a keyed store is of the form a[expression] = foo. |
| 1037 | enum StoreFromKeyed { |
| 1038 | MAY_BE_STORE_FROM_KEYED, |
| 1039 | CERTAINLY_NOT_STORE_FROM_KEYED |
| 1040 | }; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1041 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1042 | enum ShouldThrow { THROW_ON_ERROR, DONT_THROW }; |
| 1043 | |
| 1044 | #define RETURN_FAILURE(isolate, should_throw, call) \ |
| 1045 | do { \ |
| 1046 | if ((should_throw) == DONT_THROW) { \ |
| 1047 | return Just(false); \ |
| 1048 | } else { \ |
| 1049 | isolate->Throw(*isolate->factory()->call); \ |
| 1050 | return Nothing<bool>(); \ |
| 1051 | } \ |
| 1052 | } while (false) |
| 1053 | |
| 1054 | #define MAYBE_RETURN(call, value) \ |
| 1055 | do { \ |
| 1056 | if ((call).IsNothing()) return value; \ |
| 1057 | } while (false) |
| 1058 | |
| 1059 | #define MAYBE_RETURN_NULL(call) MAYBE_RETURN(call, MaybeHandle<Object>()) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1060 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1061 | #define DECLARE_STRUCT_PREDICATE(NAME, Name, name) \ |
| 1062 | INLINE(bool Is##Name() const); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1063 | STRUCT_LIST(DECLARE_STRUCT_PREDICATE) |
| 1064 | #undef DECLARE_STRUCT_PREDICATE |
| 1065 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1066 | // ES6, section 7.2.2 IsArray. NOT to be confused with %_IsArray. |
| 1067 | MUST_USE_RESULT static Maybe<bool> IsArray(Handle<Object> object); |
| 1068 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1069 | INLINE(bool IsNameDictionary() const); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1070 | INLINE(bool IsGlobalDictionary() const); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1071 | INLINE(bool IsSeededNumberDictionary() const); |
| 1072 | INLINE(bool IsUnseededNumberDictionary() const); |
| 1073 | INLINE(bool IsOrderedHashSet() const); |
| 1074 | INLINE(bool IsOrderedHashMap() const); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1075 | static bool IsPromise(Handle<Object> object); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1076 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1077 | // Extract the number. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1078 | inline double Number() const; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1079 | INLINE(bool IsNaN() const); |
| 1080 | INLINE(bool IsMinusZero() const); |
| 1081 | bool ToInt32(int32_t* value); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1082 | inline bool ToUint32(uint32_t* value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1083 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1084 | inline Representation OptimalRepresentation(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1085 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1086 | inline ElementsKind OptimalElementsKind(); |
| 1087 | |
| 1088 | inline bool FitsRepresentation(Representation representation); |
| 1089 | |
| 1090 | // Checks whether two valid primitive encodings of a property name resolve to |
| 1091 | // the same logical property. E.g., the smi 1, the string "1" and the double |
| 1092 | // 1 all refer to the same property, so this helper will return true. |
| 1093 | inline bool KeyEquals(Object* other); |
| 1094 | |
| 1095 | inline bool FilterKey(PropertyFilter filter); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1096 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1097 | Handle<FieldType> OptimalType(Isolate* isolate, |
| 1098 | Representation representation); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1099 | |
| 1100 | inline static Handle<Object> NewStorageFor(Isolate* isolate, |
| 1101 | Handle<Object> object, |
| 1102 | Representation representation); |
| 1103 | |
| 1104 | inline static Handle<Object> WrapForRead(Isolate* isolate, |
| 1105 | Handle<Object> object, |
| 1106 | Representation representation); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1107 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1108 | // Returns true if the object is of the correct type to be used as a |
| 1109 | // implementation of a JSObject's elements. |
| 1110 | inline bool HasValidElements(); |
| 1111 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1112 | inline bool HasSpecificClassOf(String* name); |
| 1113 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1114 | bool BooleanValue(); // ECMA-262 9.2. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1115 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1116 | // ES6 section 7.2.11 Abstract Relational Comparison |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1117 | MUST_USE_RESULT static Maybe<ComparisonResult> Compare(Handle<Object> x, |
| 1118 | Handle<Object> y); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1119 | |
| 1120 | // ES6 section 7.2.12 Abstract Equality Comparison |
| 1121 | MUST_USE_RESULT static Maybe<bool> Equals(Handle<Object> x, Handle<Object> y); |
| 1122 | |
| 1123 | // ES6 section 7.2.13 Strict Equality Comparison |
| 1124 | bool StrictEquals(Object* that); |
| 1125 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1126 | // Convert to a JSObject if needed. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1127 | // native_context is used when creating wrapper object. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1128 | MUST_USE_RESULT static inline MaybeHandle<JSReceiver> ToObject( |
| 1129 | Isolate* isolate, Handle<Object> object); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1130 | MUST_USE_RESULT static MaybeHandle<JSReceiver> ToObject( |
| 1131 | Isolate* isolate, Handle<Object> object, Handle<Context> context); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1132 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1133 | // ES6 section 9.2.1.2, OrdinaryCallBindThis for sloppy callee. |
| 1134 | MUST_USE_RESULT static MaybeHandle<JSReceiver> ConvertReceiver( |
| 1135 | Isolate* isolate, Handle<Object> object); |
| 1136 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1137 | // ES6 section 7.1.14 ToPropertyKey |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1138 | MUST_USE_RESULT static inline MaybeHandle<Name> ToName(Isolate* isolate, |
| 1139 | Handle<Object> input); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1140 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1141 | // ES6 section 7.1.1 ToPrimitive |
| 1142 | MUST_USE_RESULT static inline MaybeHandle<Object> ToPrimitive( |
| 1143 | Handle<Object> input, ToPrimitiveHint hint = ToPrimitiveHint::kDefault); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1144 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1145 | // ES6 section 7.1.3 ToNumber |
| 1146 | MUST_USE_RESULT static MaybeHandle<Object> ToNumber(Handle<Object> input); |
| 1147 | |
| 1148 | // ES6 section 7.1.4 ToInteger |
| 1149 | MUST_USE_RESULT static MaybeHandle<Object> ToInteger(Isolate* isolate, |
| 1150 | Handle<Object> input); |
| 1151 | |
| 1152 | // ES6 section 7.1.5 ToInt32 |
| 1153 | MUST_USE_RESULT static MaybeHandle<Object> ToInt32(Isolate* isolate, |
| 1154 | Handle<Object> input); |
| 1155 | |
| 1156 | // ES6 section 7.1.6 ToUint32 |
| 1157 | MUST_USE_RESULT static MaybeHandle<Object> ToUint32(Isolate* isolate, |
| 1158 | Handle<Object> input); |
| 1159 | |
| 1160 | // ES6 section 7.1.12 ToString |
| 1161 | MUST_USE_RESULT static MaybeHandle<String> ToString(Isolate* isolate, |
| 1162 | Handle<Object> input); |
| 1163 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1164 | // ES6 section 7.1.14 ToPropertyKey |
| 1165 | MUST_USE_RESULT static MaybeHandle<Object> ToPropertyKey( |
| 1166 | Isolate* isolate, Handle<Object> value); |
| 1167 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1168 | // ES6 section 7.1.15 ToLength |
| 1169 | MUST_USE_RESULT static MaybeHandle<Object> ToLength(Isolate* isolate, |
| 1170 | Handle<Object> input); |
| 1171 | |
| 1172 | // ES6 section 7.3.9 GetMethod |
| 1173 | MUST_USE_RESULT static MaybeHandle<Object> GetMethod( |
| 1174 | Handle<JSReceiver> receiver, Handle<Name> name); |
| 1175 | |
| 1176 | // ES6 section 7.3.17 CreateListFromArrayLike |
| 1177 | MUST_USE_RESULT static MaybeHandle<FixedArray> CreateListFromArrayLike( |
| 1178 | Isolate* isolate, Handle<Object> object, ElementTypes element_types); |
| 1179 | |
| 1180 | // Check whether |object| is an instance of Error or NativeError. |
| 1181 | static bool IsErrorObject(Isolate* isolate, Handle<Object> object); |
| 1182 | |
| 1183 | // ES6 section 12.5.6 The typeof Operator |
| 1184 | static Handle<String> TypeOf(Isolate* isolate, Handle<Object> object); |
| 1185 | |
| 1186 | // ES6 section 12.6 Multiplicative Operators |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1187 | MUST_USE_RESULT static MaybeHandle<Object> Multiply(Isolate* isolate, |
| 1188 | Handle<Object> lhs, |
| 1189 | Handle<Object> rhs); |
| 1190 | MUST_USE_RESULT static MaybeHandle<Object> Divide(Isolate* isolate, |
| 1191 | Handle<Object> lhs, |
| 1192 | Handle<Object> rhs); |
| 1193 | MUST_USE_RESULT static MaybeHandle<Object> Modulus(Isolate* isolate, |
| 1194 | Handle<Object> lhs, |
| 1195 | Handle<Object> rhs); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1196 | |
| 1197 | // ES6 section 12.7 Additive Operators |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1198 | MUST_USE_RESULT static MaybeHandle<Object> Add(Isolate* isolate, |
| 1199 | Handle<Object> lhs, |
| 1200 | Handle<Object> rhs); |
| 1201 | MUST_USE_RESULT static MaybeHandle<Object> Subtract(Isolate* isolate, |
| 1202 | Handle<Object> lhs, |
| 1203 | Handle<Object> rhs); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1204 | |
| 1205 | // ES6 section 12.8 Bitwise Shift Operators |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1206 | MUST_USE_RESULT static MaybeHandle<Object> ShiftLeft(Isolate* isolate, |
| 1207 | Handle<Object> lhs, |
| 1208 | Handle<Object> rhs); |
| 1209 | MUST_USE_RESULT static MaybeHandle<Object> ShiftRight(Isolate* isolate, |
| 1210 | Handle<Object> lhs, |
| 1211 | Handle<Object> rhs); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1212 | MUST_USE_RESULT static MaybeHandle<Object> ShiftRightLogical( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1213 | Isolate* isolate, Handle<Object> lhs, Handle<Object> rhs); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1214 | |
| 1215 | // ES6 section 12.9 Relational Operators |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1216 | MUST_USE_RESULT static inline Maybe<bool> GreaterThan(Handle<Object> x, |
| 1217 | Handle<Object> y); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1218 | MUST_USE_RESULT static inline Maybe<bool> GreaterThanOrEqual( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1219 | Handle<Object> x, Handle<Object> y); |
| 1220 | MUST_USE_RESULT static inline Maybe<bool> LessThan(Handle<Object> x, |
| 1221 | Handle<Object> y); |
| 1222 | MUST_USE_RESULT static inline Maybe<bool> LessThanOrEqual(Handle<Object> x, |
| 1223 | Handle<Object> y); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1224 | |
| 1225 | // ES6 section 12.11 Binary Bitwise Operators |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1226 | MUST_USE_RESULT static MaybeHandle<Object> BitwiseAnd(Isolate* isolate, |
| 1227 | Handle<Object> lhs, |
| 1228 | Handle<Object> rhs); |
| 1229 | MUST_USE_RESULT static MaybeHandle<Object> BitwiseOr(Isolate* isolate, |
| 1230 | Handle<Object> lhs, |
| 1231 | Handle<Object> rhs); |
| 1232 | MUST_USE_RESULT static MaybeHandle<Object> BitwiseXor(Isolate* isolate, |
| 1233 | Handle<Object> lhs, |
| 1234 | Handle<Object> rhs); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1235 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1236 | // ES6 section 7.3.19 OrdinaryHasInstance (C, O). |
| 1237 | MUST_USE_RESULT static MaybeHandle<Object> OrdinaryHasInstance( |
| 1238 | Isolate* isolate, Handle<Object> callable, Handle<Object> object); |
| 1239 | |
| 1240 | // ES6 section 12.10.4 Runtime Semantics: InstanceofOperator(O, C) |
| 1241 | MUST_USE_RESULT static MaybeHandle<Object> InstanceOf( |
| 1242 | Isolate* isolate, Handle<Object> object, Handle<Object> callable); |
| 1243 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1244 | MUST_USE_RESULT static MaybeHandle<Object> GetProperty(LookupIterator* it); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1245 | |
| 1246 | // ES6 [[Set]] (when passed DONT_THROW) |
| 1247 | // Invariants for this and related functions (unless stated otherwise): |
| 1248 | // 1) When the result is Nothing, an exception is pending. |
| 1249 | // 2) When passed THROW_ON_ERROR, the result is never Just(false). |
| 1250 | // In some cases, an exception is thrown regardless of the ShouldThrow |
| 1251 | // argument. These cases are either in accordance with the spec or not |
| 1252 | // covered by it (eg., concerning API callbacks). |
| 1253 | MUST_USE_RESULT static Maybe<bool> SetProperty(LookupIterator* it, |
| 1254 | Handle<Object> value, |
| 1255 | LanguageMode language_mode, |
| 1256 | StoreFromKeyed store_mode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1257 | MUST_USE_RESULT static MaybeHandle<Object> SetProperty( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1258 | Handle<Object> object, Handle<Name> name, Handle<Object> value, |
| 1259 | LanguageMode language_mode, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1260 | StoreFromKeyed store_mode = MAY_BE_STORE_FROM_KEYED); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1261 | MUST_USE_RESULT static inline MaybeHandle<Object> SetPropertyOrElement( |
| 1262 | Handle<Object> object, Handle<Name> name, Handle<Object> value, |
| 1263 | LanguageMode language_mode, |
| 1264 | StoreFromKeyed store_mode = MAY_BE_STORE_FROM_KEYED); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1265 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1266 | MUST_USE_RESULT static Maybe<bool> SetSuperProperty( |
| 1267 | LookupIterator* it, Handle<Object> value, LanguageMode language_mode, |
| 1268 | StoreFromKeyed store_mode); |
| 1269 | |
| 1270 | MUST_USE_RESULT static MaybeHandle<Object> ReadAbsentProperty( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1271 | LookupIterator* it); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1272 | MUST_USE_RESULT static MaybeHandle<Object> ReadAbsentProperty( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1273 | Isolate* isolate, Handle<Object> receiver, Handle<Object> name); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1274 | MUST_USE_RESULT static Maybe<bool> CannotCreateProperty( |
| 1275 | Isolate* isolate, Handle<Object> receiver, Handle<Object> name, |
| 1276 | Handle<Object> value, ShouldThrow should_throw); |
| 1277 | MUST_USE_RESULT static Maybe<bool> WriteToReadOnlyProperty( |
| 1278 | LookupIterator* it, Handle<Object> value, ShouldThrow should_throw); |
| 1279 | MUST_USE_RESULT static Maybe<bool> WriteToReadOnlyProperty( |
| 1280 | Isolate* isolate, Handle<Object> receiver, Handle<Object> name, |
| 1281 | Handle<Object> value, ShouldThrow should_throw); |
| 1282 | MUST_USE_RESULT static Maybe<bool> RedefineIncompatibleProperty( |
| 1283 | Isolate* isolate, Handle<Object> name, Handle<Object> value, |
| 1284 | ShouldThrow should_throw); |
| 1285 | MUST_USE_RESULT static Maybe<bool> SetDataProperty(LookupIterator* it, |
| 1286 | Handle<Object> value); |
| 1287 | MUST_USE_RESULT static Maybe<bool> AddDataProperty( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1288 | LookupIterator* it, Handle<Object> value, PropertyAttributes attributes, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1289 | ShouldThrow should_throw, StoreFromKeyed store_mode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1290 | MUST_USE_RESULT static inline MaybeHandle<Object> GetPropertyOrElement( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1291 | Handle<Object> object, Handle<Name> name); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1292 | MUST_USE_RESULT static inline MaybeHandle<Object> GetPropertyOrElement( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1293 | Handle<Object> receiver, Handle<Name> name, Handle<JSReceiver> holder); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1294 | MUST_USE_RESULT static inline MaybeHandle<Object> GetProperty( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1295 | Handle<Object> object, Handle<Name> name); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1296 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1297 | MUST_USE_RESULT static MaybeHandle<Object> GetPropertyWithAccessor( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1298 | LookupIterator* it); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1299 | MUST_USE_RESULT static Maybe<bool> SetPropertyWithAccessor( |
| 1300 | LookupIterator* it, Handle<Object> value, ShouldThrow should_throw); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1301 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1302 | MUST_USE_RESULT static MaybeHandle<Object> GetPropertyWithDefinedGetter( |
| 1303 | Handle<Object> receiver, |
| 1304 | Handle<JSReceiver> getter); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1305 | MUST_USE_RESULT static Maybe<bool> SetPropertyWithDefinedSetter( |
| 1306 | Handle<Object> receiver, Handle<JSReceiver> setter, Handle<Object> value, |
| 1307 | ShouldThrow should_throw); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1308 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1309 | MUST_USE_RESULT static inline MaybeHandle<Object> GetElement( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1310 | Isolate* isolate, Handle<Object> object, uint32_t index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1311 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1312 | MUST_USE_RESULT static inline MaybeHandle<Object> SetElement( |
| 1313 | Isolate* isolate, Handle<Object> object, uint32_t index, |
| 1314 | Handle<Object> value, LanguageMode language_mode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1315 | |
| 1316 | // Returns the permanent hash code associated with this object. May return |
| 1317 | // undefined if not yet created. |
| 1318 | Object* GetHash(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1319 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1320 | // Returns undefined for JSObjects, but returns the hash code for simple |
| 1321 | // objects. This avoids a double lookup in the cases where we know we will |
| 1322 | // add the hash to the JSObject if it does not already exist. |
| 1323 | Object* GetSimpleHash(); |
| 1324 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1325 | // Returns the permanent hash code associated with this object depending on |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1326 | // the actual object type. May create and store a hash code if needed and none |
| 1327 | // exists. |
| 1328 | static Handle<Smi> GetOrCreateHash(Isolate* isolate, Handle<Object> object); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1329 | |
| 1330 | // Checks whether this object has the same value as the given one. This |
| 1331 | // function is implemented according to ES5, section 9.12 and can be used |
| 1332 | // to implement the Harmony "egal" function. |
| 1333 | bool SameValue(Object* other); |
| 1334 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1335 | // Checks whether this object has the same value as the given one. |
| 1336 | // +0 and -0 are treated equal. Everything else is the same as SameValue. |
| 1337 | // This function is implemented according to ES6, section 7.2.4 and is used |
| 1338 | // by ES6 Map and Set. |
| 1339 | bool SameValueZero(Object* other); |
| 1340 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1341 | // ES6 section 9.4.2.3 ArraySpeciesCreate (part of it) |
| 1342 | MUST_USE_RESULT static MaybeHandle<Object> ArraySpeciesConstructor( |
| 1343 | Isolate* isolate, Handle<Object> original_array); |
| 1344 | |
| 1345 | // Tries to convert an object to an array length. Returns true and sets the |
| 1346 | // output parameter if it succeeds. |
| 1347 | inline bool ToArrayLength(uint32_t* index); |
| 1348 | |
| 1349 | // Tries to convert an object to an array index. Returns true and sets the |
| 1350 | // output parameter if it succeeds. Equivalent to ToArrayLength, but does not |
| 1351 | // allow kMaxUInt32. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1352 | inline bool ToArrayIndex(uint32_t* index); |
| 1353 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1354 | DECLARE_VERIFIER(Object) |
| 1355 | #ifdef VERIFY_HEAP |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1356 | // Verify a pointer is a valid object pointer. |
| 1357 | static void VerifyPointer(Object* p); |
| 1358 | #endif |
| 1359 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1360 | inline void VerifyApiCallResultType(); |
| 1361 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1362 | // ES6 19.1.3.6 Object.prototype.toString |
| 1363 | MUST_USE_RESULT static MaybeHandle<String> ObjectProtoToString( |
| 1364 | Isolate* isolate, Handle<Object> object); |
| 1365 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1366 | // Prints this object without details. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1367 | void ShortPrint(FILE* out = stdout); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1368 | |
| 1369 | // Prints this object without details to a message accumulator. |
| 1370 | void ShortPrint(StringStream* accumulator); |
| 1371 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1372 | void ShortPrint(std::ostream& os); // NOLINT |
| 1373 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1374 | DECLARE_CAST(Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1375 | |
| 1376 | // Layout description. |
| 1377 | static const int kHeaderSize = 0; // Object does not take up any space. |
| 1378 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1379 | #ifdef OBJECT_PRINT |
| 1380 | // For our gdb macros, we should perhaps change these in the future. |
| 1381 | void Print(); |
| 1382 | |
| 1383 | // Prints this object with details. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1384 | void Print(std::ostream& os); // NOLINT |
| 1385 | #else |
| 1386 | void Print() { ShortPrint(); } |
| 1387 | void Print(std::ostream& os) { ShortPrint(os); } // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1388 | #endif |
| 1389 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1390 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1391 | friend class LookupIterator; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1392 | friend class StringStream; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1393 | |
| 1394 | // Return the map of the root of object's prototype chain. |
| 1395 | Map* GetRootMap(Isolate* isolate); |
| 1396 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1397 | // Helper for SetProperty and SetSuperProperty. |
| 1398 | // Return value is only meaningful if [found] is set to true on return. |
| 1399 | MUST_USE_RESULT static Maybe<bool> SetPropertyInternal( |
| 1400 | LookupIterator* it, Handle<Object> value, LanguageMode language_mode, |
| 1401 | StoreFromKeyed store_mode, bool* found); |
| 1402 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1403 | MUST_USE_RESULT static MaybeHandle<Name> ConvertToName(Isolate* isolate, |
| 1404 | Handle<Object> input); |
| 1405 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1406 | DISALLOW_IMPLICIT_CONSTRUCTORS(Object); |
| 1407 | }; |
| 1408 | |
| 1409 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1410 | // In objects.h to be usable without objects-inl.h inclusion. |
| 1411 | bool Object::IsSmi() const { return HAS_SMI_TAG(this); } |
| 1412 | bool Object::IsHeapObject() const { return Internals::HasHeapObjectTag(this); } |
| 1413 | |
| 1414 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1415 | struct Brief { |
| 1416 | explicit Brief(const Object* const v) : value(v) {} |
| 1417 | const Object* value; |
| 1418 | }; |
| 1419 | |
| 1420 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1421 | std::ostream& operator<<(std::ostream& os, const Brief& v); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1422 | |
| 1423 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1424 | // Smi represents integer Numbers that can be stored in 31 bits. |
| 1425 | // Smis are immediate which means they are NOT allocated in the heap. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1426 | // The this pointer has the following format: [31 bit signed int] 0 |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1427 | // For long smis it has the following format: |
| 1428 | // [32 bit signed int] [31 bits zero padding] 0 |
| 1429 | // Smi stands for small integer. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1430 | class Smi: public Object { |
| 1431 | public: |
| 1432 | // Returns the integer value. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1433 | inline int value() const { return Internals::SmiValue(this); } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1434 | |
| 1435 | // Convert a value to a Smi object. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1436 | static inline Smi* FromInt(int value) { |
| 1437 | DCHECK(Smi::IsValid(value)); |
| 1438 | return reinterpret_cast<Smi*>(Internals::IntToSmi(value)); |
| 1439 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1440 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1441 | static inline Smi* FromIntptr(intptr_t value) { |
| 1442 | DCHECK(Smi::IsValid(value)); |
| 1443 | int smi_shift_bits = kSmiTagSize + kSmiShiftSize; |
| 1444 | return reinterpret_cast<Smi*>((value << smi_shift_bits) | kSmiTag); |
| 1445 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1446 | |
| 1447 | // Returns whether value can be represented in a Smi. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1448 | static inline bool IsValid(intptr_t value) { |
| 1449 | bool result = Internals::IsValidSmi(value); |
| 1450 | DCHECK_EQ(result, value >= kMinValue && value <= kMaxValue); |
| 1451 | return result; |
| 1452 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1453 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1454 | DECLARE_CAST(Smi) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1455 | |
| 1456 | // Dispatched behavior. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1457 | void SmiPrint(std::ostream& os) const; // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1458 | DECLARE_VERIFIER(Smi) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1459 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1460 | static const int kMinValue = |
| 1461 | (static_cast<unsigned int>(-1)) << (kSmiValueSize - 1); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1462 | static const int kMaxValue = -(kMinValue + 1); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1463 | |
| 1464 | private: |
| 1465 | DISALLOW_IMPLICIT_CONSTRUCTORS(Smi); |
| 1466 | }; |
| 1467 | |
| 1468 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1469 | // Heap objects typically have a map pointer in their first word. However, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1470 | // during GC other data (e.g. mark bits, forwarding addresses) is sometimes |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1471 | // encoded in the first word. The class MapWord is an abstraction of the |
| 1472 | // value in a heap object's first word. |
| 1473 | class MapWord BASE_EMBEDDED { |
| 1474 | public: |
| 1475 | // Normal state: the map word contains a map pointer. |
| 1476 | |
| 1477 | // Create a map word from a map pointer. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1478 | static inline MapWord FromMap(const Map* map); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1479 | |
| 1480 | // View this map word as a map pointer. |
| 1481 | inline Map* ToMap(); |
| 1482 | |
| 1483 | |
| 1484 | // Scavenge collection: the map word of live objects in the from space |
| 1485 | // contains a forwarding address (a heap object pointer in the to space). |
| 1486 | |
| 1487 | // True if this map word is a forwarding address for a scavenge |
| 1488 | // collection. Only valid during a scavenge collection (specifically, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1489 | // when all map words are heap object pointers, i.e. not during a full GC). |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1490 | inline bool IsForwardingAddress() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1491 | |
| 1492 | // Create a map word from a forwarding address. |
| 1493 | static inline MapWord FromForwardingAddress(HeapObject* object); |
| 1494 | |
| 1495 | // View this map word as a forwarding address. |
| 1496 | inline HeapObject* ToForwardingAddress(); |
| 1497 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1498 | static inline MapWord FromRawValue(uintptr_t value) { |
| 1499 | return MapWord(value); |
| 1500 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1501 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1502 | inline uintptr_t ToRawValue() { |
| 1503 | return value_; |
| 1504 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1505 | |
| 1506 | private: |
| 1507 | // HeapObject calls the private constructor and directly reads the value. |
| 1508 | friend class HeapObject; |
| 1509 | |
| 1510 | explicit MapWord(uintptr_t value) : value_(value) {} |
| 1511 | |
| 1512 | uintptr_t value_; |
| 1513 | }; |
| 1514 | |
| 1515 | |
| 1516 | // HeapObject is the superclass for all classes describing heap allocated |
| 1517 | // objects. |
| 1518 | class HeapObject: public Object { |
| 1519 | public: |
| 1520 | // [map]: Contains a map which contains the object's reflective |
| 1521 | // information. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1522 | inline Map* map() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1523 | inline void set_map(Map* value); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1524 | // The no-write-barrier version. This is OK if the object is white and in |
| 1525 | // new space, or if the value is an immortal immutable object, like the maps |
| 1526 | // of primitive (non-JS) objects like strings, heap numbers etc. |
| 1527 | inline void set_map_no_write_barrier(Map* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1528 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1529 | // Get the map using acquire load. |
| 1530 | inline Map* synchronized_map(); |
| 1531 | inline MapWord synchronized_map_word() const; |
| 1532 | |
| 1533 | // Set the map using release store |
| 1534 | inline void synchronized_set_map(Map* value); |
| 1535 | inline void synchronized_set_map_no_write_barrier(Map* value); |
| 1536 | inline void synchronized_set_map_word(MapWord map_word); |
| 1537 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1538 | // During garbage collection, the map word of a heap object does not |
| 1539 | // necessarily contain a map pointer. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1540 | inline MapWord map_word() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1541 | inline void set_map_word(MapWord map_word); |
| 1542 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1543 | // The Heap the object was allocated in. Used also to access Isolate. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1544 | inline Heap* GetHeap() const; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1545 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1546 | // Convenience method to get current isolate. |
| 1547 | inline Isolate* GetIsolate() const; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1548 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1549 | #define IS_TYPE_FUNCTION_DECL(type_) INLINE(bool Is##type_() const); |
| 1550 | HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL) |
| 1551 | ODDBALL_LIST(IS_TYPE_FUNCTION_DECL) |
| 1552 | #undef IS_TYPE_FUNCTION_DECL |
| 1553 | #define DECLARE_STRUCT_PREDICATE(NAME, Name, name) \ |
| 1554 | INLINE(bool Is##Name() const); |
| 1555 | STRUCT_LIST(DECLARE_STRUCT_PREDICATE) |
| 1556 | #undef DECLARE_STRUCT_PREDICATE |
| 1557 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1558 | // Converts an address to a HeapObject pointer. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1559 | static inline HeapObject* FromAddress(Address address) { |
| 1560 | DCHECK_TAG_ALIGNED(address); |
| 1561 | return reinterpret_cast<HeapObject*>(address + kHeapObjectTag); |
| 1562 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1563 | |
| 1564 | // Returns the address of this HeapObject. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1565 | inline Address address() { |
| 1566 | return reinterpret_cast<Address>(this) - kHeapObjectTag; |
| 1567 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1568 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1569 | // Iterates over pointers contained in the object (including the Map). |
| 1570 | // If it's not performance critical iteration use the non-templatized |
| 1571 | // version. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1572 | void Iterate(ObjectVisitor* v); |
| 1573 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1574 | template <typename ObjectVisitor> |
| 1575 | inline void IterateFast(ObjectVisitor* v); |
| 1576 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1577 | // Iterates over all pointers contained in the object except the |
| 1578 | // first map pointer. The object type is given in the first |
| 1579 | // parameter. This function does not access the map pointer in the |
| 1580 | // object, and so is safe to call while the map pointer is modified. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1581 | // If it's not performance critical iteration use the non-templatized |
| 1582 | // version. |
| 1583 | void IterateBody(ObjectVisitor* v); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1584 | void IterateBody(InstanceType type, int object_size, ObjectVisitor* v); |
| 1585 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1586 | template <typename ObjectVisitor> |
| 1587 | inline void IterateBodyFast(ObjectVisitor* v); |
| 1588 | |
| 1589 | template <typename ObjectVisitor> |
| 1590 | inline void IterateBodyFast(InstanceType type, int object_size, |
| 1591 | ObjectVisitor* v); |
| 1592 | |
| 1593 | // Returns true if the object contains a tagged value at given offset. |
| 1594 | // It is used for invalid slots filtering. If the offset points outside |
| 1595 | // of the object or to the map word, the result is UNDEFINED (!!!). |
| 1596 | bool IsValidSlot(int offset); |
| 1597 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1598 | // Returns the heap object's size in bytes |
| 1599 | inline int Size(); |
| 1600 | |
| 1601 | // Given a heap object's map pointer, returns the heap size in bytes |
| 1602 | // Useful when the map pointer field is used for other purposes. |
| 1603 | // GC internal. |
| 1604 | inline int SizeFromMap(Map* map); |
| 1605 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1606 | // Returns the field at offset in obj, as a read/write Object* reference. |
| 1607 | // Does no checking, and is safe to use during GC, while maps are invalid. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1608 | // Does not invoke write barrier, so should only be assigned to |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1609 | // during marking GC. |
| 1610 | static inline Object** RawField(HeapObject* obj, int offset); |
| 1611 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1612 | // Adds the |code| object related to |name| to the code cache of this map. If |
| 1613 | // this map is a dictionary map that is shared, the map copied and installed |
| 1614 | // onto the object. |
| 1615 | static void UpdateMapCodeCache(Handle<HeapObject> object, |
| 1616 | Handle<Name> name, |
| 1617 | Handle<Code> code); |
| 1618 | |
| 1619 | DECLARE_CAST(HeapObject) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1620 | |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 1621 | // Return the write barrier mode for this. Callers of this function |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1622 | // must be able to present a reference to an DisallowHeapAllocation |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 1623 | // object as a sign that they are not going to use this function |
| 1624 | // from code that allocates and thus invalidates the returned write |
| 1625 | // barrier mode. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1626 | inline WriteBarrierMode GetWriteBarrierMode( |
| 1627 | const DisallowHeapAllocation& promise); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1628 | |
| 1629 | // Dispatched behavior. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1630 | void HeapObjectShortPrint(std::ostream& os); // NOLINT |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1631 | #ifdef OBJECT_PRINT |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1632 | void PrintHeader(std::ostream& os, const char* id); // NOLINT |
Ben Murdoch | 85b7179 | 2012-04-11 18:30:58 +0100 | [diff] [blame] | 1633 | #endif |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1634 | DECLARE_PRINTER(HeapObject) |
| 1635 | DECLARE_VERIFIER(HeapObject) |
| 1636 | #ifdef VERIFY_HEAP |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1637 | inline void VerifyObjectField(int offset); |
| 1638 | inline void VerifySmiField(int offset); |
| 1639 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1640 | // Verify a pointer is a valid HeapObject pointer that points to object |
| 1641 | // areas in the heap. |
| 1642 | static void VerifyHeapPointer(Object* p); |
| 1643 | #endif |
| 1644 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1645 | inline AllocationAlignment RequiredAlignment(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1646 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1647 | // Layout description. |
| 1648 | // First field in a heap object is map. |
| 1649 | static const int kMapOffset = Object::kHeaderSize; |
| 1650 | static const int kHeaderSize = kMapOffset + kPointerSize; |
| 1651 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1652 | STATIC_ASSERT(kMapOffset == Internals::kHeapObjectMapOffset); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1653 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1654 | private: |
| 1655 | DISALLOW_IMPLICIT_CONSTRUCTORS(HeapObject); |
| 1656 | }; |
| 1657 | |
| 1658 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1659 | template <int start_offset, int end_offset, int size> |
| 1660 | class FixedBodyDescriptor; |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1661 | |
| 1662 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1663 | template <int start_offset> |
| 1664 | class FlexibleBodyDescriptor; |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1665 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1666 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1667 | // The HeapNumber class describes heap allocated numbers that cannot be |
| 1668 | // represented in a Smi (small integer) |
| 1669 | class HeapNumber: public HeapObject { |
| 1670 | public: |
| 1671 | // [value]: number value. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1672 | inline double value() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1673 | inline void set_value(double value); |
| 1674 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1675 | DECLARE_CAST(HeapNumber) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1676 | |
| 1677 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1678 | bool HeapNumberBooleanValue(); |
| 1679 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1680 | void HeapNumberPrint(std::ostream& os); // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1681 | DECLARE_VERIFIER(HeapNumber) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1682 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1683 | inline int get_exponent(); |
| 1684 | inline int get_sign(); |
| 1685 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1686 | // Layout description. |
| 1687 | static const int kValueOffset = HeapObject::kHeaderSize; |
| 1688 | // IEEE doubles are two 32 bit words. The first is just mantissa, the second |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1689 | // is a mixture of sign, exponent and mantissa. The offsets of two 32 bit |
| 1690 | // words within double numbers are endian dependent and they are set |
| 1691 | // accordingly. |
| 1692 | #if defined(V8_TARGET_LITTLE_ENDIAN) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1693 | static const int kMantissaOffset = kValueOffset; |
| 1694 | static const int kExponentOffset = kValueOffset + 4; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1695 | #elif defined(V8_TARGET_BIG_ENDIAN) |
| 1696 | static const int kMantissaOffset = kValueOffset + 4; |
| 1697 | static const int kExponentOffset = kValueOffset; |
| 1698 | #else |
| 1699 | #error Unknown byte ordering |
| 1700 | #endif |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1701 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1702 | static const int kSize = kValueOffset + kDoubleSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1703 | static const uint32_t kSignMask = 0x80000000u; |
| 1704 | static const uint32_t kExponentMask = 0x7ff00000u; |
| 1705 | static const uint32_t kMantissaMask = 0xfffffu; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1706 | static const int kMantissaBits = 52; |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 1707 | static const int kExponentBits = 11; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1708 | static const int kExponentBias = 1023; |
| 1709 | static const int kExponentShift = 20; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1710 | static const int kInfinityOrNanExponent = |
| 1711 | (kExponentMask >> kExponentShift) - kExponentBias; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1712 | static const int kMantissaBitsInTopWord = 20; |
| 1713 | static const int kNonMantissaBitsInTopWord = 12; |
| 1714 | |
| 1715 | private: |
| 1716 | DISALLOW_IMPLICIT_CONSTRUCTORS(HeapNumber); |
| 1717 | }; |
| 1718 | |
| 1719 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1720 | // The Simd128Value class describes heap allocated 128 bit SIMD values. |
| 1721 | class Simd128Value : public HeapObject { |
| 1722 | public: |
| 1723 | DECLARE_CAST(Simd128Value) |
| 1724 | |
| 1725 | DECLARE_PRINTER(Simd128Value) |
| 1726 | DECLARE_VERIFIER(Simd128Value) |
| 1727 | |
| 1728 | static Handle<String> ToString(Handle<Simd128Value> input); |
| 1729 | |
| 1730 | // Equality operations. |
| 1731 | inline bool Equals(Simd128Value* that); |
| 1732 | static inline bool Equals(Handle<Simd128Value> one, Handle<Simd128Value> two); |
| 1733 | |
| 1734 | // Checks that another instance is bit-wise equal. |
| 1735 | bool BitwiseEquals(const Simd128Value* other) const; |
| 1736 | // Computes a hash from the 128 bit value, viewed as 4 32-bit integers. |
| 1737 | uint32_t Hash() const; |
| 1738 | // Copies the 16 bytes of SIMD data to the destination address. |
| 1739 | void CopyBits(void* destination) const; |
| 1740 | |
| 1741 | // Layout description. |
| 1742 | static const int kValueOffset = HeapObject::kHeaderSize; |
| 1743 | static const int kSize = kValueOffset + kSimd128Size; |
| 1744 | |
| 1745 | private: |
| 1746 | DISALLOW_IMPLICIT_CONSTRUCTORS(Simd128Value); |
| 1747 | }; |
| 1748 | |
| 1749 | |
| 1750 | // V has parameters (TYPE, Type, type, lane count, lane type) |
| 1751 | #define SIMD128_TYPES(V) \ |
| 1752 | V(FLOAT32X4, Float32x4, float32x4, 4, float) \ |
| 1753 | V(INT32X4, Int32x4, int32x4, 4, int32_t) \ |
| 1754 | V(UINT32X4, Uint32x4, uint32x4, 4, uint32_t) \ |
| 1755 | V(BOOL32X4, Bool32x4, bool32x4, 4, bool) \ |
| 1756 | V(INT16X8, Int16x8, int16x8, 8, int16_t) \ |
| 1757 | V(UINT16X8, Uint16x8, uint16x8, 8, uint16_t) \ |
| 1758 | V(BOOL16X8, Bool16x8, bool16x8, 8, bool) \ |
| 1759 | V(INT8X16, Int8x16, int8x16, 16, int8_t) \ |
| 1760 | V(UINT8X16, Uint8x16, uint8x16, 16, uint8_t) \ |
| 1761 | V(BOOL8X16, Bool8x16, bool8x16, 16, bool) |
| 1762 | |
| 1763 | #define SIMD128_VALUE_CLASS(TYPE, Type, type, lane_count, lane_type) \ |
| 1764 | class Type final : public Simd128Value { \ |
| 1765 | public: \ |
| 1766 | inline lane_type get_lane(int lane) const; \ |
| 1767 | inline void set_lane(int lane, lane_type value); \ |
| 1768 | \ |
| 1769 | DECLARE_CAST(Type) \ |
| 1770 | \ |
| 1771 | DECLARE_PRINTER(Type) \ |
| 1772 | \ |
| 1773 | static Handle<String> ToString(Handle<Type> input); \ |
| 1774 | \ |
| 1775 | inline bool Equals(Type* that); \ |
| 1776 | \ |
| 1777 | private: \ |
| 1778 | DISALLOW_IMPLICIT_CONSTRUCTORS(Type); \ |
| 1779 | }; |
| 1780 | SIMD128_TYPES(SIMD128_VALUE_CLASS) |
| 1781 | #undef SIMD128_VALUE_CLASS |
| 1782 | |
| 1783 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1784 | enum EnsureElementsMode { |
| 1785 | DONT_ALLOW_DOUBLE_ELEMENTS, |
| 1786 | ALLOW_COPIED_DOUBLE_ELEMENTS, |
| 1787 | ALLOW_CONVERTED_DOUBLE_ELEMENTS |
| 1788 | }; |
| 1789 | |
| 1790 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1791 | // Indicator for one component of an AccessorPair. |
| 1792 | enum AccessorComponent { |
| 1793 | ACCESSOR_GETTER, |
| 1794 | ACCESSOR_SETTER |
| 1795 | }; |
| 1796 | |
| 1797 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1798 | enum GetKeysConversion { KEEP_NUMBERS, CONVERT_TO_STRING }; |
| 1799 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1800 | enum KeyCollectionType { OWN_ONLY, INCLUDE_PROTOS }; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1801 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1802 | // JSReceiver includes types on which properties can be defined, i.e., |
| 1803 | // JSObject and JSProxy. |
| 1804 | class JSReceiver: public HeapObject { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1805 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1806 | // [properties]: Backing storage for properties. |
| 1807 | // properties is a FixedArray in the fast case and a Dictionary in the |
| 1808 | // slow case. |
| 1809 | DECL_ACCESSORS(properties, FixedArray) // Get and set fast properties. |
| 1810 | inline void initialize_properties(); |
| 1811 | inline bool HasFastProperties(); |
| 1812 | // Gets slow properties for non-global objects. |
| 1813 | inline NameDictionary* property_dictionary(); |
| 1814 | |
| 1815 | // Deletes an existing named property in a normalized object. |
| 1816 | static void DeleteNormalizedProperty(Handle<JSReceiver> object, |
| 1817 | Handle<Name> name, int entry); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1818 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1819 | DECLARE_CAST(JSReceiver) |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1820 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1821 | // ES6 section 7.1.1 ToPrimitive |
| 1822 | MUST_USE_RESULT static MaybeHandle<Object> ToPrimitive( |
| 1823 | Handle<JSReceiver> receiver, |
| 1824 | ToPrimitiveHint hint = ToPrimitiveHint::kDefault); |
| 1825 | MUST_USE_RESULT static MaybeHandle<Object> OrdinaryToPrimitive( |
| 1826 | Handle<JSReceiver> receiver, OrdinaryToPrimitiveHint hint); |
| 1827 | |
| 1828 | static MaybeHandle<Context> GetFunctionRealm(Handle<JSReceiver> receiver); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1829 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1830 | // Get the first non-hidden prototype. |
| 1831 | static inline MaybeHandle<Object> GetPrototype(Isolate* isolate, |
| 1832 | Handle<JSReceiver> receiver); |
| 1833 | |
| 1834 | MUST_USE_RESULT static Maybe<bool> HasInPrototypeChain( |
| 1835 | Isolate* isolate, Handle<JSReceiver> object, Handle<Object> proto); |
| 1836 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1837 | // Implementation of [[HasProperty]], ECMA-262 5th edition, section 8.12.6. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1838 | MUST_USE_RESULT static Maybe<bool> HasProperty(LookupIterator* it); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1839 | MUST_USE_RESULT static inline Maybe<bool> HasProperty( |
| 1840 | Handle<JSReceiver> object, Handle<Name> name); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1841 | MUST_USE_RESULT static inline Maybe<bool> HasElement( |
| 1842 | Handle<JSReceiver> object, uint32_t index); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1843 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1844 | MUST_USE_RESULT static inline Maybe<bool> HasOwnProperty( |
| 1845 | Handle<JSReceiver> object, Handle<Name> name); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1846 | MUST_USE_RESULT static inline Maybe<bool> HasOwnProperty( |
| 1847 | Handle<JSReceiver> object, uint32_t index); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1848 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1849 | MUST_USE_RESULT static inline MaybeHandle<Object> GetProperty( |
| 1850 | Isolate* isolate, Handle<JSReceiver> receiver, const char* key); |
| 1851 | MUST_USE_RESULT static inline MaybeHandle<Object> GetProperty( |
| 1852 | Handle<JSReceiver> receiver, Handle<Name> name); |
| 1853 | MUST_USE_RESULT static inline MaybeHandle<Object> GetElement( |
| 1854 | Isolate* isolate, Handle<JSReceiver> receiver, uint32_t index); |
| 1855 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1856 | // Implementation of ES6 [[Delete]] |
| 1857 | MUST_USE_RESULT static Maybe<bool> DeletePropertyOrElement( |
| 1858 | Handle<JSReceiver> object, Handle<Name> name, |
| 1859 | LanguageMode language_mode = SLOPPY); |
| 1860 | MUST_USE_RESULT static Maybe<bool> DeleteProperty( |
| 1861 | Handle<JSReceiver> object, Handle<Name> name, |
| 1862 | LanguageMode language_mode = SLOPPY); |
| 1863 | MUST_USE_RESULT static Maybe<bool> DeleteProperty(LookupIterator* it, |
| 1864 | LanguageMode language_mode); |
| 1865 | MUST_USE_RESULT static Maybe<bool> DeleteElement( |
| 1866 | Handle<JSReceiver> object, uint32_t index, |
| 1867 | LanguageMode language_mode = SLOPPY); |
| 1868 | |
| 1869 | MUST_USE_RESULT static Object* DefineProperty(Isolate* isolate, |
| 1870 | Handle<Object> object, |
| 1871 | Handle<Object> name, |
| 1872 | Handle<Object> attributes); |
| 1873 | MUST_USE_RESULT static MaybeHandle<Object> DefineProperties( |
| 1874 | Isolate* isolate, Handle<Object> object, Handle<Object> properties); |
| 1875 | |
| 1876 | // "virtual" dispatcher to the correct [[DefineOwnProperty]] implementation. |
| 1877 | MUST_USE_RESULT static Maybe<bool> DefineOwnProperty( |
| 1878 | Isolate* isolate, Handle<JSReceiver> object, Handle<Object> key, |
| 1879 | PropertyDescriptor* desc, ShouldThrow should_throw); |
| 1880 | |
| 1881 | // ES6 7.3.4 (when passed DONT_THROW) |
| 1882 | MUST_USE_RESULT static Maybe<bool> CreateDataProperty( |
| 1883 | LookupIterator* it, Handle<Object> value, ShouldThrow should_throw); |
| 1884 | |
| 1885 | // ES6 9.1.6.1 |
| 1886 | MUST_USE_RESULT static Maybe<bool> OrdinaryDefineOwnProperty( |
| 1887 | Isolate* isolate, Handle<JSObject> object, Handle<Object> key, |
| 1888 | PropertyDescriptor* desc, ShouldThrow should_throw); |
| 1889 | MUST_USE_RESULT static Maybe<bool> OrdinaryDefineOwnProperty( |
| 1890 | LookupIterator* it, PropertyDescriptor* desc, ShouldThrow should_throw); |
| 1891 | // ES6 9.1.6.2 |
| 1892 | MUST_USE_RESULT static Maybe<bool> IsCompatiblePropertyDescriptor( |
| 1893 | Isolate* isolate, bool extensible, PropertyDescriptor* desc, |
| 1894 | PropertyDescriptor* current, Handle<Name> property_name, |
| 1895 | ShouldThrow should_throw); |
| 1896 | // ES6 9.1.6.3 |
| 1897 | // |it| can be NULL in cases where the ES spec passes |undefined| as the |
| 1898 | // receiver. Exactly one of |it| and |property_name| must be provided. |
| 1899 | MUST_USE_RESULT static Maybe<bool> ValidateAndApplyPropertyDescriptor( |
| 1900 | Isolate* isolate, LookupIterator* it, bool extensible, |
| 1901 | PropertyDescriptor* desc, PropertyDescriptor* current, |
| 1902 | ShouldThrow should_throw, Handle<Name> property_name = Handle<Name>()); |
| 1903 | |
| 1904 | MUST_USE_RESULT static Maybe<bool> GetOwnPropertyDescriptor( |
| 1905 | Isolate* isolate, Handle<JSReceiver> object, Handle<Object> key, |
| 1906 | PropertyDescriptor* desc); |
| 1907 | MUST_USE_RESULT static Maybe<bool> GetOwnPropertyDescriptor( |
| 1908 | LookupIterator* it, PropertyDescriptor* desc); |
| 1909 | |
| 1910 | typedef PropertyAttributes IntegrityLevel; |
| 1911 | |
| 1912 | // ES6 7.3.14 (when passed DONT_THROW) |
| 1913 | // 'level' must be SEALED or FROZEN. |
| 1914 | MUST_USE_RESULT static Maybe<bool> SetIntegrityLevel( |
| 1915 | Handle<JSReceiver> object, IntegrityLevel lvl, ShouldThrow should_throw); |
| 1916 | |
| 1917 | // ES6 7.3.15 |
| 1918 | // 'level' must be SEALED or FROZEN. |
| 1919 | MUST_USE_RESULT static Maybe<bool> TestIntegrityLevel( |
| 1920 | Handle<JSReceiver> object, IntegrityLevel lvl); |
| 1921 | |
| 1922 | // ES6 [[PreventExtensions]] (when passed DONT_THROW) |
| 1923 | MUST_USE_RESULT static Maybe<bool> PreventExtensions( |
| 1924 | Handle<JSReceiver> object, ShouldThrow should_throw); |
| 1925 | |
| 1926 | MUST_USE_RESULT static Maybe<bool> IsExtensible(Handle<JSReceiver> object); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1927 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1928 | // Returns the class name ([[Class]] property in the specification). |
| 1929 | String* class_name(); |
| 1930 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1931 | // Returns the builtin string tag used in Object.prototype.toString. |
| 1932 | MUST_USE_RESULT static MaybeHandle<String> BuiltinStringTag( |
| 1933 | Handle<JSReceiver> object); |
| 1934 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1935 | // Returns the constructor name (the name (possibly, inferred name) of the |
| 1936 | // function that was used to instantiate the object). |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1937 | static Handle<String> GetConstructorName(Handle<JSReceiver> receiver); |
| 1938 | |
| 1939 | Context* GetCreationContext(); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1940 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1941 | MUST_USE_RESULT static inline Maybe<PropertyAttributes> GetPropertyAttributes( |
| 1942 | Handle<JSReceiver> object, Handle<Name> name); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1943 | MUST_USE_RESULT static inline Maybe<PropertyAttributes> |
| 1944 | GetOwnPropertyAttributes(Handle<JSReceiver> object, Handle<Name> name); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1945 | MUST_USE_RESULT static inline Maybe<PropertyAttributes> |
| 1946 | GetOwnPropertyAttributes(Handle<JSReceiver> object, uint32_t index); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1947 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1948 | MUST_USE_RESULT static inline Maybe<PropertyAttributes> GetElementAttributes( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1949 | Handle<JSReceiver> object, uint32_t index); |
| 1950 | MUST_USE_RESULT static inline Maybe<PropertyAttributes> |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1951 | GetOwnElementAttributes(Handle<JSReceiver> object, uint32_t index); |
| 1952 | |
| 1953 | MUST_USE_RESULT static Maybe<PropertyAttributes> GetPropertyAttributes( |
| 1954 | LookupIterator* it); |
| 1955 | |
| 1956 | // Set the object's prototype (only JSReceiver and null are allowed values). |
| 1957 | MUST_USE_RESULT static Maybe<bool> SetPrototype(Handle<JSReceiver> object, |
| 1958 | Handle<Object> value, |
| 1959 | bool from_javascript, |
| 1960 | ShouldThrow should_throw); |
| 1961 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1962 | inline static Handle<Object> GetDataProperty(Handle<JSReceiver> object, |
| 1963 | Handle<Name> name); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1964 | static Handle<Object> GetDataProperty(LookupIterator* it); |
| 1965 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1966 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1967 | // Retrieves a permanent object identity hash code. The undefined value might |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1968 | // be returned in case no hash was created yet. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1969 | static inline Handle<Object> GetIdentityHash(Isolate* isolate, |
| 1970 | Handle<JSReceiver> object); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1971 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1972 | // Retrieves a permanent object identity hash code. May create and store a |
| 1973 | // hash code if needed and none exists. |
| 1974 | inline static Handle<Smi> GetOrCreateIdentityHash( |
| 1975 | Handle<JSReceiver> object); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1976 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1977 | // ES6 [[OwnPropertyKeys]] (modulo return type) |
| 1978 | MUST_USE_RESULT static MaybeHandle<FixedArray> OwnPropertyKeys( |
| 1979 | Handle<JSReceiver> object) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1980 | return GetKeys(object, OWN_ONLY, ALL_PROPERTIES, CONVERT_TO_STRING); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1981 | } |
| 1982 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1983 | // Computes the enumerable keys for a JSObject. Used for implementing |
| 1984 | // "for (n in object) { }". |
| 1985 | MUST_USE_RESULT static MaybeHandle<FixedArray> GetKeys( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1986 | Handle<JSReceiver> object, KeyCollectionType type, PropertyFilter filter, |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1987 | GetKeysConversion keys_conversion = KEEP_NUMBERS, |
| 1988 | bool filter_proxy_keys_ = true); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1989 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1990 | MUST_USE_RESULT static MaybeHandle<FixedArray> GetOwnValues( |
| 1991 | Handle<JSReceiver> object, PropertyFilter filter); |
| 1992 | |
| 1993 | MUST_USE_RESULT static MaybeHandle<FixedArray> GetOwnEntries( |
| 1994 | Handle<JSReceiver> object, PropertyFilter filter); |
| 1995 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1996 | // Layout description. |
| 1997 | static const int kPropertiesOffset = HeapObject::kHeaderSize; |
| 1998 | static const int kHeaderSize = HeapObject::kHeaderSize + kPointerSize; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1999 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2000 | private: |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2001 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSReceiver); |
| 2002 | }; |
| 2003 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2004 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2005 | // The JSObject describes real heap allocated JavaScript objects with |
| 2006 | // properties. |
| 2007 | // Note that the map of JSObject changes during execution to enable inline |
| 2008 | // caching. |
| 2009 | class JSObject: public JSReceiver { |
| 2010 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2011 | static MUST_USE_RESULT MaybeHandle<JSObject> New( |
| 2012 | Handle<JSFunction> constructor, Handle<JSReceiver> new_target, |
| 2013 | Handle<AllocationSite> site = Handle<AllocationSite>::null()); |
| 2014 | |
| 2015 | // Gets global object properties. |
| 2016 | inline GlobalDictionary* global_dictionary(); |
| 2017 | |
| 2018 | static MaybeHandle<Context> GetFunctionRealm(Handle<JSObject> object); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2019 | |
| 2020 | // [elements]: The elements (properties with names that are integers). |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2021 | // |
| 2022 | // Elements can be in two general modes: fast and slow. Each mode |
| 2023 | // corrensponds to a set of object representations of elements that |
| 2024 | // have something in common. |
| 2025 | // |
| 2026 | // In the fast mode elements is a FixedArray and so each element can |
| 2027 | // be quickly accessed. This fact is used in the generated code. The |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2028 | // elements array can have one of three maps in this mode: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2029 | // fixed_array_map, sloppy_arguments_elements_map or |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2030 | // fixed_cow_array_map (for copy-on-write arrays). In the latter case |
| 2031 | // the elements array may be shared by a few objects and so before |
| 2032 | // writing to any element the array must be copied. Use |
| 2033 | // EnsureWritableFastElements in this case. |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2034 | // |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2035 | // In the slow mode the elements is either a NumberDictionary, a |
| 2036 | // FixedArray parameter map for a (sloppy) arguments object. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2037 | DECL_ACCESSORS(elements, FixedArrayBase) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2038 | inline void initialize_elements(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2039 | static void ResetElements(Handle<JSObject> object); |
| 2040 | static inline void SetMapAndElements(Handle<JSObject> object, |
| 2041 | Handle<Map> map, |
| 2042 | Handle<FixedArrayBase> elements); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2043 | inline ElementsKind GetElementsKind(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2044 | ElementsAccessor* GetElementsAccessor(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2045 | // Returns true if an object has elements of FAST_SMI_ELEMENTS ElementsKind. |
| 2046 | inline bool HasFastSmiElements(); |
| 2047 | // Returns true if an object has elements of FAST_ELEMENTS ElementsKind. |
| 2048 | inline bool HasFastObjectElements(); |
| 2049 | // Returns true if an object has elements of FAST_ELEMENTS or |
| 2050 | // FAST_SMI_ONLY_ELEMENTS. |
| 2051 | inline bool HasFastSmiOrObjectElements(); |
| 2052 | // Returns true if an object has any of the fast elements kinds. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2053 | inline bool HasFastElements(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2054 | // Returns true if an object has elements of FAST_DOUBLE_ELEMENTS |
| 2055 | // ElementsKind. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2056 | inline bool HasFastDoubleElements(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2057 | // Returns true if an object has elements of FAST_HOLEY_*_ELEMENTS |
| 2058 | // ElementsKind. |
| 2059 | inline bool HasFastHoleyElements(); |
| 2060 | inline bool HasSloppyArgumentsElements(); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2061 | inline bool HasStringWrapperElements(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2062 | inline bool HasDictionaryElements(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2063 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2064 | inline bool HasFixedTypedArrayElements(); |
| 2065 | |
| 2066 | inline bool HasFixedUint8ClampedElements(); |
| 2067 | inline bool HasFixedArrayElements(); |
| 2068 | inline bool HasFixedInt8Elements(); |
| 2069 | inline bool HasFixedUint8Elements(); |
| 2070 | inline bool HasFixedInt16Elements(); |
| 2071 | inline bool HasFixedUint16Elements(); |
| 2072 | inline bool HasFixedInt32Elements(); |
| 2073 | inline bool HasFixedUint32Elements(); |
| 2074 | inline bool HasFixedFloat32Elements(); |
| 2075 | inline bool HasFixedFloat64Elements(); |
| 2076 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2077 | inline bool HasFastArgumentsElements(); |
| 2078 | inline bool HasSlowArgumentsElements(); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2079 | inline bool HasFastStringWrapperElements(); |
| 2080 | inline bool HasSlowStringWrapperElements(); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 2081 | bool HasEnumerableElements(); |
| 2082 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 2083 | inline SeededNumberDictionary* element_dictionary(); // Gets slow elements. |
| 2084 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2085 | // Requires: HasFastElements(). |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 2086 | static void EnsureWritableFastElements(Handle<JSObject> object); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2087 | |
| 2088 | // Collects elements starting at index 0. |
| 2089 | // Undefined values are placed after non-undefined values. |
| 2090 | // Returns the number of non-undefined values. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2091 | static Handle<Object> PrepareElementsForSort(Handle<JSObject> object, |
| 2092 | uint32_t limit); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2093 | // As PrepareElementsForSort, but only on objects where elements is |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2094 | // a dictionary, and it will stay a dictionary. Collates undefined and |
| 2095 | // unexisting elements below limit from position zero of the elements. |
| 2096 | static Handle<Object> PrepareSlowElementsForSort(Handle<JSObject> object, |
| 2097 | uint32_t limit); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2098 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2099 | MUST_USE_RESULT static Maybe<bool> SetPropertyWithInterceptor( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2100 | LookupIterator* it, ShouldThrow should_throw, Handle<Object> value); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2101 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2102 | // The API currently still wants DefineOwnPropertyIgnoreAttributes to convert |
| 2103 | // AccessorInfo objects to data fields. We allow FORCE_FIELD as an exception |
| 2104 | // to the default behavior that calls the setter. |
| 2105 | enum AccessorInfoHandling { FORCE_FIELD, DONT_FORCE_FIELD }; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2106 | |
| 2107 | MUST_USE_RESULT static MaybeHandle<Object> DefineOwnPropertyIgnoreAttributes( |
| 2108 | LookupIterator* it, Handle<Object> value, PropertyAttributes attributes, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2109 | AccessorInfoHandling handling = DONT_FORCE_FIELD); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2110 | |
| 2111 | MUST_USE_RESULT static Maybe<bool> DefineOwnPropertyIgnoreAttributes( |
| 2112 | LookupIterator* it, Handle<Object> value, PropertyAttributes attributes, |
| 2113 | ShouldThrow should_throw, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2114 | AccessorInfoHandling handling = DONT_FORCE_FIELD); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2115 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2116 | MUST_USE_RESULT static MaybeHandle<Object> SetOwnPropertyIgnoreAttributes( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2117 | Handle<JSObject> object, Handle<Name> name, Handle<Object> value, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2118 | PropertyAttributes attributes); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2119 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2120 | MUST_USE_RESULT static MaybeHandle<Object> SetOwnElementIgnoreAttributes( |
| 2121 | Handle<JSObject> object, uint32_t index, Handle<Object> value, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2122 | PropertyAttributes attributes); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2123 | |
| 2124 | // Equivalent to one of the above depending on whether |name| can be converted |
| 2125 | // to an array index. |
| 2126 | MUST_USE_RESULT static MaybeHandle<Object> |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2127 | DefinePropertyOrElementIgnoreAttributes(Handle<JSObject> object, |
| 2128 | Handle<Name> name, |
| 2129 | Handle<Object> value, |
| 2130 | PropertyAttributes attributes = NONE); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2131 | |
| 2132 | // Adds or reconfigures a property to attributes NONE. It will fail when it |
| 2133 | // cannot. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 2134 | MUST_USE_RESULT static Maybe<bool> CreateDataProperty( |
| 2135 | LookupIterator* it, Handle<Object> value, |
| 2136 | ShouldThrow should_throw = DONT_THROW); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2137 | |
| 2138 | static void AddProperty(Handle<JSObject> object, Handle<Name> name, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2139 | Handle<Object> value, PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2140 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2141 | MUST_USE_RESULT static Maybe<bool> AddDataElement( |
| 2142 | Handle<JSObject> receiver, uint32_t index, Handle<Object> value, |
| 2143 | PropertyAttributes attributes, ShouldThrow should_throw); |
| 2144 | MUST_USE_RESULT static MaybeHandle<Object> AddDataElement( |
| 2145 | Handle<JSObject> receiver, uint32_t index, Handle<Object> value, |
| 2146 | PropertyAttributes attributes); |
| 2147 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2148 | // Extend the receiver with a single fast property appeared first in the |
| 2149 | // passed map. This also extends the property backing store if necessary. |
| 2150 | static void AllocateStorageForMap(Handle<JSObject> object, Handle<Map> map); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2151 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2152 | // Migrates the given object to a map whose field representations are the |
| 2153 | // lowest upper bound of all known representations for that field. |
| 2154 | static void MigrateInstance(Handle<JSObject> instance); |
| 2155 | |
| 2156 | // Migrates the given object only if the target map is already available, |
| 2157 | // or returns false if such a map is not yet available. |
| 2158 | static bool TryMigrateInstance(Handle<JSObject> instance); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2159 | |
| 2160 | // Sets the property value in a normalized object given (key, value, details). |
| 2161 | // Handles the special representation of JS global objects. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2162 | static void SetNormalizedProperty(Handle<JSObject> object, Handle<Name> name, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2163 | Handle<Object> value, |
| 2164 | PropertyDetails details); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2165 | static void SetDictionaryElement(Handle<JSObject> object, uint32_t index, |
| 2166 | Handle<Object> value, |
| 2167 | PropertyAttributes attributes); |
| 2168 | static void SetDictionaryArgumentsElement(Handle<JSObject> object, |
| 2169 | uint32_t index, |
| 2170 | Handle<Object> value, |
| 2171 | PropertyAttributes attributes); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2172 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2173 | static void OptimizeAsPrototype(Handle<JSObject> object, |
| 2174 | PrototypeOptimizationMode mode); |
| 2175 | static void ReoptimizeIfPrototype(Handle<JSObject> object); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2176 | static void LazyRegisterPrototypeUser(Handle<Map> user, Isolate* isolate); |
| 2177 | static void UpdatePrototypeUserRegistration(Handle<Map> old_map, |
| 2178 | Handle<Map> new_map, |
| 2179 | Isolate* isolate); |
| 2180 | static bool UnregisterPrototypeUser(Handle<Map> user, Isolate* isolate); |
| 2181 | static void InvalidatePrototypeChains(Map* map); |
| 2182 | |
| 2183 | // Alternative implementation of WeakFixedArray::NullCallback. |
| 2184 | class PrototypeRegistryCompactionCallback { |
| 2185 | public: |
| 2186 | static void Callback(Object* value, int old_index, int new_index); |
| 2187 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2188 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2189 | // Retrieve interceptors. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 2190 | inline InterceptorInfo* GetNamedInterceptor(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2191 | inline InterceptorInfo* GetIndexedInterceptor(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2192 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2193 | // Used from JSReceiver. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2194 | MUST_USE_RESULT static Maybe<PropertyAttributes> |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2195 | GetPropertyAttributesWithInterceptor(LookupIterator* it); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2196 | MUST_USE_RESULT static Maybe<PropertyAttributes> |
| 2197 | GetPropertyAttributesWithFailedAccessCheck(LookupIterator* it); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2198 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2199 | // Defines an AccessorPair property on the given object. |
| 2200 | // TODO(mstarzinger): Rename to SetAccessor(). |
| 2201 | static MaybeHandle<Object> DefineAccessor(Handle<JSObject> object, |
| 2202 | Handle<Name> name, |
| 2203 | Handle<Object> getter, |
| 2204 | Handle<Object> setter, |
| 2205 | PropertyAttributes attributes); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2206 | static MaybeHandle<Object> DefineAccessor(LookupIterator* it, |
| 2207 | Handle<Object> getter, |
| 2208 | Handle<Object> setter, |
| 2209 | PropertyAttributes attributes); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2210 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2211 | // Defines an AccessorInfo property on the given object. |
| 2212 | MUST_USE_RESULT static MaybeHandle<Object> SetAccessor( |
| 2213 | Handle<JSObject> object, |
| 2214 | Handle<AccessorInfo> info); |
| 2215 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2216 | // The result must be checked first for exceptions. If there's no exception, |
| 2217 | // the output parameter |done| indicates whether the interceptor has a result |
| 2218 | // or not. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2219 | MUST_USE_RESULT static MaybeHandle<Object> GetPropertyWithInterceptor( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2220 | LookupIterator* it, bool* done); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2221 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2222 | static void ValidateElements(Handle<JSObject> object); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2223 | |
| 2224 | // Makes sure that this object can contain HeapObject as elements. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2225 | static inline void EnsureCanContainHeapObjectElements(Handle<JSObject> obj); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2226 | |
| 2227 | // Makes sure that this object can contain the specified elements. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2228 | static inline void EnsureCanContainElements( |
| 2229 | Handle<JSObject> object, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2230 | Object** elements, |
| 2231 | uint32_t count, |
| 2232 | EnsureElementsMode mode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2233 | static inline void EnsureCanContainElements( |
| 2234 | Handle<JSObject> object, |
| 2235 | Handle<FixedArrayBase> elements, |
| 2236 | uint32_t length, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2237 | EnsureElementsMode mode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2238 | static void EnsureCanContainElements( |
| 2239 | Handle<JSObject> object, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2240 | Arguments* arguments, |
| 2241 | uint32_t first_arg, |
| 2242 | uint32_t arg_count, |
| 2243 | EnsureElementsMode mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2244 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2245 | // Would we convert a fast elements array to dictionary mode given |
| 2246 | // an access at key? |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2247 | bool WouldConvertToSlowElements(uint32_t index); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 2248 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2249 | // Computes the new capacity when expanding the elements of a JSObject. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2250 | static uint32_t NewElementsCapacity(uint32_t old_capacity) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2251 | // (old_capacity + 50%) + 16 |
| 2252 | return old_capacity + (old_capacity >> 1) + 16; |
| 2253 | } |
| 2254 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2255 | // These methods do not perform access checks! |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2256 | static void UpdateAllocationSite(Handle<JSObject> object, |
| 2257 | ElementsKind to_kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2258 | |
| 2259 | // Lookup interceptors are used for handling properties controlled by host |
| 2260 | // objects. |
| 2261 | inline bool HasNamedInterceptor(); |
| 2262 | inline bool HasIndexedInterceptor(); |
| 2263 | |
| 2264 | // Support functions for v8 api (needed for correct interceptor behavior). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2265 | MUST_USE_RESULT static Maybe<bool> HasRealNamedProperty( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2266 | Handle<JSObject> object, Handle<Name> name); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2267 | MUST_USE_RESULT static Maybe<bool> HasRealElementProperty( |
| 2268 | Handle<JSObject> object, uint32_t index); |
| 2269 | MUST_USE_RESULT static Maybe<bool> HasRealNamedCallbackProperty( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2270 | Handle<JSObject> object, Handle<Name> name); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2271 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2272 | // Get the header size for a JSObject. Used to compute the index of |
| 2273 | // internal fields as well as the number of internal fields. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2274 | static inline int GetHeaderSize(InstanceType instance_type); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2275 | inline int GetHeaderSize(); |
| 2276 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2277 | static inline int GetInternalFieldCount(Map* map); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2278 | inline int GetInternalFieldCount(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2279 | inline int GetInternalFieldOffset(int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2280 | inline Object* GetInternalField(int index); |
| 2281 | inline void SetInternalField(int index, Object* value); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2282 | inline void SetInternalField(int index, Smi* value); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 2283 | bool WasConstructedFromApiFunction(); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 2284 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2285 | // Returns a new map with all transitions dropped from the object's current |
| 2286 | // map and the ElementsKind set. |
| 2287 | static Handle<Map> GetElementsTransitionMap(Handle<JSObject> object, |
| 2288 | ElementsKind to_kind); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2289 | static void TransitionElementsKind(Handle<JSObject> object, |
| 2290 | ElementsKind to_kind); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2291 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2292 | // Always use this to migrate an object to a new map. |
| 2293 | // |expected_additional_properties| is only used for fast-to-slow transitions |
| 2294 | // and ignored otherwise. |
| 2295 | static void MigrateToMap(Handle<JSObject> object, Handle<Map> new_map, |
| 2296 | int expected_additional_properties = 0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2297 | |
| 2298 | // Convert the object to use the canonical dictionary |
| 2299 | // representation. If the object is expected to have additional properties |
| 2300 | // added this number can be indicated to have the backing store allocated to |
| 2301 | // an initial capacity for holding these properties. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2302 | static void NormalizeProperties(Handle<JSObject> object, |
| 2303 | PropertyNormalizationMode mode, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2304 | int expected_additional_properties, |
| 2305 | const char* reason); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2306 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2307 | // Convert and update the elements backing store to be a |
| 2308 | // SeededNumberDictionary dictionary. Returns the backing after conversion. |
| 2309 | static Handle<SeededNumberDictionary> NormalizeElements( |
| 2310 | Handle<JSObject> object); |
| 2311 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2312 | void RequireSlowElements(SeededNumberDictionary* dictionary); |
| 2313 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2314 | // Transform slow named properties to fast variants. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2315 | static void MigrateSlowToFast(Handle<JSObject> object, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2316 | int unused_property_fields, const char* reason); |
| 2317 | |
| 2318 | inline bool IsUnboxedDoubleField(FieldIndex index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2319 | |
| 2320 | // Access fast-case object properties at index. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2321 | static Handle<Object> FastPropertyAt(Handle<JSObject> object, |
| 2322 | Representation representation, |
| 2323 | FieldIndex index); |
| 2324 | inline Object* RawFastPropertyAt(FieldIndex index); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2325 | inline double RawFastDoublePropertyAt(FieldIndex index); |
| 2326 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2327 | inline void FastPropertyAtPut(FieldIndex index, Object* value); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2328 | inline void RawFastPropertyAtPut(FieldIndex index, Object* value); |
| 2329 | inline void RawFastDoublePropertyAtPut(FieldIndex index, double value); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2330 | inline void WriteToField(int descriptor, PropertyDetails details, |
| 2331 | Object* value); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2332 | inline void WriteToField(int descriptor, Object* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2333 | |
| 2334 | // Access to in object properties. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2335 | inline int GetInObjectPropertyOffset(int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2336 | inline Object* InObjectPropertyAt(int index); |
| 2337 | inline Object* InObjectPropertyAtPut(int index, |
| 2338 | Object* value, |
| 2339 | WriteBarrierMode mode |
| 2340 | = UPDATE_WRITE_BARRIER); |
| 2341 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2342 | // Set the object's prototype (only JSReceiver and null are allowed values). |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2343 | MUST_USE_RESULT static Maybe<bool> SetPrototype(Handle<JSObject> object, |
| 2344 | Handle<Object> value, |
| 2345 | bool from_javascript, |
| 2346 | ShouldThrow should_throw); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2347 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2348 | // Initializes the body starting at |start_offset|. It is responsibility of |
| 2349 | // the caller to initialize object header. Fill the pre-allocated fields with |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2350 | // pre_allocated_value and the rest with filler_value. |
| 2351 | // Note: this call does not update write barrier, the caller is responsible |
| 2352 | // to ensure that |filler_value| can be collected without WB here. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2353 | inline void InitializeBody(Map* map, int start_offset, |
| 2354 | Object* pre_allocated_value, Object* filler_value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2355 | |
| 2356 | // Check whether this object references another object |
| 2357 | bool ReferencesObject(Object* obj); |
| 2358 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2359 | MUST_USE_RESULT static Maybe<bool> PreventExtensions( |
| 2360 | Handle<JSObject> object, ShouldThrow should_throw); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2361 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2362 | static bool IsExtensible(Handle<JSObject> object); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2363 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2364 | // Copy object. |
| 2365 | enum DeepCopyHints { kNoHints = 0, kObjectIsShallow = 1 }; |
| 2366 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2367 | MUST_USE_RESULT static MaybeHandle<JSObject> DeepCopy( |
| 2368 | Handle<JSObject> object, |
| 2369 | AllocationSiteUsageContext* site_context, |
| 2370 | DeepCopyHints hints = kNoHints); |
| 2371 | MUST_USE_RESULT static MaybeHandle<JSObject> DeepWalk( |
| 2372 | Handle<JSObject> object, |
| 2373 | AllocationSiteCreationContext* site_context); |
| 2374 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2375 | DECLARE_CAST(JSObject) |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2376 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2377 | // Dispatched behavior. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2378 | void JSObjectShortPrint(StringStream* accumulator); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2379 | DECLARE_PRINTER(JSObject) |
| 2380 | DECLARE_VERIFIER(JSObject) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2381 | #ifdef OBJECT_PRINT |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2382 | void PrintProperties(std::ostream& os); // NOLINT |
| 2383 | void PrintElements(std::ostream& os); // NOLINT |
| 2384 | #endif |
| 2385 | #if defined(DEBUG) || defined(OBJECT_PRINT) |
| 2386 | void PrintTransitions(std::ostream& os); // NOLINT |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2387 | #endif |
| 2388 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2389 | static void PrintElementsTransition( |
| 2390 | FILE* file, Handle<JSObject> object, |
| 2391 | ElementsKind from_kind, Handle<FixedArrayBase> from_elements, |
| 2392 | ElementsKind to_kind, Handle<FixedArrayBase> to_elements); |
| 2393 | |
| 2394 | void PrintInstanceMigration(FILE* file, Map* original_map, Map* new_map); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2395 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2396 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2397 | // Structure for collecting spill information about JSObjects. |
| 2398 | class SpillInformation { |
| 2399 | public: |
| 2400 | void Clear(); |
| 2401 | void Print(); |
| 2402 | int number_of_objects_; |
| 2403 | int number_of_objects_with_fast_properties_; |
| 2404 | int number_of_objects_with_fast_elements_; |
| 2405 | int number_of_fast_used_fields_; |
| 2406 | int number_of_fast_unused_fields_; |
| 2407 | int number_of_slow_used_properties_; |
| 2408 | int number_of_slow_unused_properties_; |
| 2409 | int number_of_fast_used_elements_; |
| 2410 | int number_of_fast_unused_elements_; |
| 2411 | int number_of_slow_used_elements_; |
| 2412 | int number_of_slow_unused_elements_; |
| 2413 | }; |
| 2414 | |
| 2415 | void IncrementSpillStatistics(SpillInformation* info); |
| 2416 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2417 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2418 | #ifdef VERIFY_HEAP |
| 2419 | // If a GC was caused while constructing this object, the elements pointer |
| 2420 | // may point to a one pointer filler map. The object won't be rooted, but |
| 2421 | // our heap verification code could stumble across it. |
| 2422 | bool ElementsAreSafeToExamine(); |
| 2423 | #endif |
| 2424 | |
| 2425 | Object* SlowReverseLookup(Object* value); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2426 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2427 | // Maximal number of elements (numbered 0 .. kMaxElementCount - 1). |
| 2428 | // Also maximal value of JSArray's length property. |
| 2429 | static const uint32_t kMaxElementCount = 0xffffffffu; |
| 2430 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2431 | // Constants for heuristics controlling conversion of fast elements |
| 2432 | // to slow elements. |
| 2433 | |
| 2434 | // Maximal gap that can be introduced by adding an element beyond |
| 2435 | // the current elements length. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2436 | static const uint32_t kMaxGap = 1024; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2437 | |
| 2438 | // Maximal length of fast elements array that won't be checked for |
| 2439 | // being dense enough on expansion. |
| 2440 | static const int kMaxUncheckedFastElementsLength = 5000; |
| 2441 | |
| 2442 | // Same as above but for old arrays. This limit is more strict. We |
| 2443 | // don't want to be wasteful with long lived objects. |
| 2444 | static const int kMaxUncheckedOldFastElementsLength = 500; |
| 2445 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2446 | // This constant applies only to the initial map of "global.Object" and |
| 2447 | // not to arbitrary other JSObject maps. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2448 | static const int kInitialGlobalObjectUnusedPropertiesCount = 4; |
| 2449 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2450 | static const int kMaxInstanceSize = 255 * kPointerSize; |
| 2451 | // When extending the backing storage for property values, we increase |
| 2452 | // its size by more than the 1 entry necessary, so sequentially adding fields |
| 2453 | // to the same object requires fewer allocations and copies. |
| 2454 | static const int kFieldsAdded = 3; |
| 2455 | |
| 2456 | // Layout description. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2457 | static const int kElementsOffset = JSReceiver::kHeaderSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2458 | static const int kHeaderSize = kElementsOffset + kPointerSize; |
| 2459 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2460 | STATIC_ASSERT(kHeaderSize == Internals::kJSObjectHeaderSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2461 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2462 | typedef FlexibleBodyDescriptor<JSReceiver::kPropertiesOffset> BodyDescriptor; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2463 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2464 | // Gets the number of currently used elements. |
| 2465 | int GetFastElementsUsage(); |
| 2466 | |
| 2467 | static bool AllCanRead(LookupIterator* it); |
| 2468 | static bool AllCanWrite(LookupIterator* it); |
| 2469 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2470 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2471 | friend class JSReceiver; |
| 2472 | friend class Object; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2473 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2474 | // Used from Object::GetProperty(). |
| 2475 | MUST_USE_RESULT static MaybeHandle<Object> GetPropertyWithFailedAccessCheck( |
| 2476 | LookupIterator* it); |
| 2477 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2478 | MUST_USE_RESULT static Maybe<bool> SetPropertyWithFailedAccessCheck( |
| 2479 | LookupIterator* it, Handle<Object> value, ShouldThrow should_throw); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2480 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2481 | // Add a property to a slow-case object. |
| 2482 | static void AddSlowProperty(Handle<JSObject> object, |
| 2483 | Handle<Name> name, |
| 2484 | Handle<Object> value, |
| 2485 | PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2486 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2487 | MUST_USE_RESULT static Maybe<bool> DeletePropertyWithInterceptor( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2488 | LookupIterator* it, ShouldThrow should_throw); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2489 | |
| 2490 | bool ReferencesObjectFromElements(FixedArray* elements, |
| 2491 | ElementsKind kind, |
| 2492 | Object* object); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2493 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 2494 | static Handle<Object> GetIdentityHash(Isolate* isolate, |
| 2495 | Handle<JSObject> object); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2496 | |
| 2497 | static Handle<Smi> GetOrCreateIdentityHash(Handle<JSObject> object); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2498 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2499 | // Helper for fast versions of preventExtensions, seal, and freeze. |
| 2500 | // attrs is one of NONE, SEALED, or FROZEN (depending on the operation). |
| 2501 | template <PropertyAttributes attrs> |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2502 | MUST_USE_RESULT static Maybe<bool> PreventExtensionsWithTransition( |
| 2503 | Handle<JSObject> object, ShouldThrow should_throw); |
| 2504 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2505 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSObject); |
| 2506 | }; |
| 2507 | |
| 2508 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2509 | // JSAccessorPropertyDescriptor is just a JSObject with a specific initial |
| 2510 | // map. This initial map adds in-object properties for "get", "set", |
| 2511 | // "enumerable" and "configurable" properties, as assigned by the |
| 2512 | // FromPropertyDescriptor function for regular accessor properties. |
| 2513 | class JSAccessorPropertyDescriptor: public JSObject { |
| 2514 | public: |
| 2515 | // Offsets of object fields. |
| 2516 | static const int kGetOffset = JSObject::kHeaderSize; |
| 2517 | static const int kSetOffset = kGetOffset + kPointerSize; |
| 2518 | static const int kEnumerableOffset = kSetOffset + kPointerSize; |
| 2519 | static const int kConfigurableOffset = kEnumerableOffset + kPointerSize; |
| 2520 | static const int kSize = kConfigurableOffset + kPointerSize; |
| 2521 | // Indices of in-object properties. |
| 2522 | static const int kGetIndex = 0; |
| 2523 | static const int kSetIndex = 1; |
| 2524 | static const int kEnumerableIndex = 2; |
| 2525 | static const int kConfigurableIndex = 3; |
| 2526 | |
| 2527 | private: |
| 2528 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSAccessorPropertyDescriptor); |
| 2529 | }; |
| 2530 | |
| 2531 | |
| 2532 | // JSDataPropertyDescriptor is just a JSObject with a specific initial map. |
| 2533 | // This initial map adds in-object properties for "value", "writable", |
| 2534 | // "enumerable" and "configurable" properties, as assigned by the |
| 2535 | // FromPropertyDescriptor function for regular data properties. |
| 2536 | class JSDataPropertyDescriptor: public JSObject { |
| 2537 | public: |
| 2538 | // Offsets of object fields. |
| 2539 | static const int kValueOffset = JSObject::kHeaderSize; |
| 2540 | static const int kWritableOffset = kValueOffset + kPointerSize; |
| 2541 | static const int kEnumerableOffset = kWritableOffset + kPointerSize; |
| 2542 | static const int kConfigurableOffset = kEnumerableOffset + kPointerSize; |
| 2543 | static const int kSize = kConfigurableOffset + kPointerSize; |
| 2544 | // Indices of in-object properties. |
| 2545 | static const int kValueIndex = 0; |
| 2546 | static const int kWritableIndex = 1; |
| 2547 | static const int kEnumerableIndex = 2; |
| 2548 | static const int kConfigurableIndex = 3; |
| 2549 | |
| 2550 | private: |
| 2551 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSDataPropertyDescriptor); |
| 2552 | }; |
| 2553 | |
| 2554 | |
| 2555 | // JSIteratorResult is just a JSObject with a specific initial map. |
| 2556 | // This initial map adds in-object properties for "done" and "value", |
| 2557 | // as specified by ES6 section 25.1.1.3 The IteratorResult Interface |
| 2558 | class JSIteratorResult: public JSObject { |
| 2559 | public: |
| 2560 | // Offsets of object fields. |
| 2561 | static const int kValueOffset = JSObject::kHeaderSize; |
| 2562 | static const int kDoneOffset = kValueOffset + kPointerSize; |
| 2563 | static const int kSize = kDoneOffset + kPointerSize; |
| 2564 | // Indices of in-object properties. |
| 2565 | static const int kValueIndex = 0; |
| 2566 | static const int kDoneIndex = 1; |
| 2567 | |
| 2568 | private: |
| 2569 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSIteratorResult); |
| 2570 | }; |
| 2571 | |
| 2572 | |
| 2573 | // Common superclass for JSSloppyArgumentsObject and JSStrictArgumentsObject. |
| 2574 | class JSArgumentsObject: public JSObject { |
| 2575 | public: |
| 2576 | // Offsets of object fields. |
| 2577 | static const int kLengthOffset = JSObject::kHeaderSize; |
| 2578 | static const int kHeaderSize = kLengthOffset + kPointerSize; |
| 2579 | // Indices of in-object properties. |
| 2580 | static const int kLengthIndex = 0; |
| 2581 | |
| 2582 | private: |
| 2583 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSArgumentsObject); |
| 2584 | }; |
| 2585 | |
| 2586 | |
| 2587 | // JSSloppyArgumentsObject is just a JSObject with specific initial map. |
| 2588 | // This initial map adds in-object properties for "length" and "callee". |
| 2589 | class JSSloppyArgumentsObject: public JSArgumentsObject { |
| 2590 | public: |
| 2591 | // Offsets of object fields. |
| 2592 | static const int kCalleeOffset = JSArgumentsObject::kHeaderSize; |
| 2593 | static const int kSize = kCalleeOffset + kPointerSize; |
| 2594 | // Indices of in-object properties. |
| 2595 | static const int kCalleeIndex = 1; |
| 2596 | |
| 2597 | private: |
| 2598 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSSloppyArgumentsObject); |
| 2599 | }; |
| 2600 | |
| 2601 | |
| 2602 | // JSStrictArgumentsObject is just a JSObject with specific initial map. |
| 2603 | // This initial map adds an in-object property for "length". |
| 2604 | class JSStrictArgumentsObject: public JSArgumentsObject { |
| 2605 | public: |
| 2606 | // Offsets of object fields. |
| 2607 | static const int kSize = JSArgumentsObject::kHeaderSize; |
| 2608 | |
| 2609 | private: |
| 2610 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSStrictArgumentsObject); |
| 2611 | }; |
| 2612 | |
| 2613 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2614 | // Common superclass for FixedArrays that allow implementations to share |
| 2615 | // common accessors and some code paths. |
| 2616 | class FixedArrayBase: public HeapObject { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2617 | public: |
| 2618 | // [length]: length of the array. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2619 | inline int length() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2620 | inline void set_length(int value); |
| 2621 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2622 | // Get and set the length using acquire loads and release stores. |
| 2623 | inline int synchronized_length() const; |
| 2624 | inline void synchronized_set_length(int value); |
| 2625 | |
| 2626 | DECLARE_CAST(FixedArrayBase) |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2627 | |
| 2628 | // Layout description. |
| 2629 | // Length is smi tagged when it is stored. |
| 2630 | static const int kLengthOffset = HeapObject::kHeaderSize; |
| 2631 | static const int kHeaderSize = kLengthOffset + kPointerSize; |
| 2632 | }; |
| 2633 | |
| 2634 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2635 | class FixedDoubleArray; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2636 | class IncrementalMarking; |
| 2637 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2638 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2639 | // FixedArray describes fixed-sized arrays with element type Object*. |
| 2640 | class FixedArray: public FixedArrayBase { |
| 2641 | public: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2642 | // Setter and getter for elements. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2643 | inline Object* get(int index) const; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2644 | static inline Handle<Object> get(FixedArray* array, int index, |
| 2645 | Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2646 | // Setter that uses write barrier. |
| 2647 | inline void set(int index, Object* value); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2648 | inline bool is_the_hole(int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2649 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2650 | // Setter that doesn't need write barrier. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2651 | inline void set(int index, Smi* value); |
| 2652 | // Setter with explicit barrier mode. |
| 2653 | inline void set(int index, Object* value, WriteBarrierMode mode); |
| 2654 | |
| 2655 | // Setters for frequently used oddballs located in old space. |
| 2656 | inline void set_undefined(int index); |
| 2657 | inline void set_null(int index); |
| 2658 | inline void set_the_hole(int index); |
| 2659 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2660 | inline Object** GetFirstElementAddress(); |
| 2661 | inline bool ContainsOnlySmisOrHoles(); |
| 2662 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2663 | // Gives access to raw memory which stores the array's data. |
| 2664 | inline Object** data_start(); |
| 2665 | |
| 2666 | inline void FillWithHoles(int from, int to); |
| 2667 | |
| 2668 | // Shrink length and insert filler objects. |
| 2669 | void Shrink(int length); |
| 2670 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2671 | // Copy a sub array from the receiver to dest. |
| 2672 | void CopyTo(int pos, FixedArray* dest, int dest_pos, int len); |
| 2673 | |
| 2674 | // Garbage collection support. |
| 2675 | static int SizeFor(int length) { return kHeaderSize + length * kPointerSize; } |
| 2676 | |
| 2677 | // Code Generation support. |
| 2678 | static int OffsetOfElementAt(int index) { return SizeFor(index); } |
| 2679 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2680 | // Garbage collection support. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2681 | inline Object** RawFieldOfElementAt(int index); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2682 | |
| 2683 | DECLARE_CAST(FixedArray) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2684 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2685 | // Maximal allowed size, in bytes, of a single FixedArray. |
| 2686 | // Prevents overflowing size computations, as well as extreme memory |
| 2687 | // consumption. |
Ben Murdoch | 692be65 | 2012-01-10 18:47:50 +0000 | [diff] [blame] | 2688 | static const int kMaxSize = 128 * MB * kPointerSize; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2689 | // Maximally allowed length of a FixedArray. |
| 2690 | static const int kMaxLength = (kMaxSize - kHeaderSize) / kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2691 | |
| 2692 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2693 | DECLARE_PRINTER(FixedArray) |
| 2694 | DECLARE_VERIFIER(FixedArray) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2695 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2696 | // Checks if two FixedArrays have identical contents. |
| 2697 | bool IsEqualTo(FixedArray* other); |
| 2698 | #endif |
| 2699 | |
| 2700 | // Swap two elements in a pair of arrays. If this array and the |
| 2701 | // numbers array are the same object, the elements are only swapped |
| 2702 | // once. |
| 2703 | void SwapPairs(FixedArray* numbers, int i, int j); |
| 2704 | |
| 2705 | // Sort prefix of this array and the numbers array as pairs wrt. the |
| 2706 | // numbers. If the numbers array and the this array are the same |
| 2707 | // object, the prefix of this array is sorted. |
| 2708 | void SortPairs(FixedArray* numbers, uint32_t len); |
| 2709 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2710 | typedef FlexibleBodyDescriptor<kHeaderSize> BodyDescriptor; |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2711 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2712 | protected: |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 2713 | // Set operation on FixedArray without using write barriers. Can |
| 2714 | // only be used for storing old space objects or smis. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2715 | static inline void NoWriteBarrierSet(FixedArray* array, |
| 2716 | int index, |
| 2717 | Object* value); |
| 2718 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2719 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2720 | STATIC_ASSERT(kHeaderSize == Internals::kFixedArrayHeaderSize); |
| 2721 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2722 | DISALLOW_IMPLICIT_CONSTRUCTORS(FixedArray); |
| 2723 | }; |
| 2724 | |
| 2725 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2726 | // FixedDoubleArray describes fixed-sized arrays with element type double. |
| 2727 | class FixedDoubleArray: public FixedArrayBase { |
| 2728 | public: |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2729 | // Setter and getter for elements. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2730 | inline double get_scalar(int index); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2731 | inline uint64_t get_representation(int index); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2732 | static inline Handle<Object> get(FixedDoubleArray* array, int index, |
| 2733 | Isolate* isolate); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2734 | inline void set(int index, double value); |
| 2735 | inline void set_the_hole(int index); |
| 2736 | |
| 2737 | // Checking for the hole. |
| 2738 | inline bool is_the_hole(int index); |
| 2739 | |
| 2740 | // Garbage collection support. |
| 2741 | inline static int SizeFor(int length) { |
| 2742 | return kHeaderSize + length * kDoubleSize; |
| 2743 | } |
| 2744 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2745 | // Gives access to raw memory which stores the array's data. |
| 2746 | inline double* data_start(); |
| 2747 | |
| 2748 | inline void FillWithHoles(int from, int to); |
| 2749 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2750 | // Code Generation support. |
| 2751 | static int OffsetOfElementAt(int index) { return SizeFor(index); } |
| 2752 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2753 | DECLARE_CAST(FixedDoubleArray) |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2754 | |
| 2755 | // Maximal allowed size, in bytes, of a single FixedDoubleArray. |
| 2756 | // Prevents overflowing size computations, as well as extreme memory |
| 2757 | // consumption. |
| 2758 | static const int kMaxSize = 512 * MB; |
| 2759 | // Maximally allowed length of a FixedArray. |
| 2760 | static const int kMaxLength = (kMaxSize - kHeaderSize) / kDoubleSize; |
| 2761 | |
| 2762 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2763 | DECLARE_PRINTER(FixedDoubleArray) |
| 2764 | DECLARE_VERIFIER(FixedDoubleArray) |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2765 | |
| 2766 | private: |
| 2767 | DISALLOW_IMPLICIT_CONSTRUCTORS(FixedDoubleArray); |
| 2768 | }; |
| 2769 | |
| 2770 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2771 | class WeakFixedArray : public FixedArray { |
| 2772 | public: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2773 | // If |maybe_array| is not a WeakFixedArray, a fresh one will be allocated. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2774 | // This function does not check if the value exists already, callers must |
| 2775 | // ensure this themselves if necessary. |
| 2776 | static Handle<WeakFixedArray> Add(Handle<Object> maybe_array, |
| 2777 | Handle<HeapObject> value, |
| 2778 | int* assigned_index = NULL); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2779 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2780 | // Returns true if an entry was found and removed. |
| 2781 | bool Remove(Handle<HeapObject> value); |
| 2782 | |
| 2783 | class NullCallback { |
| 2784 | public: |
| 2785 | static void Callback(Object* value, int old_index, int new_index) {} |
| 2786 | }; |
| 2787 | |
| 2788 | template <class CompactionCallback> |
| 2789 | void Compact(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2790 | |
| 2791 | inline Object* Get(int index) const; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2792 | inline void Clear(int index); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2793 | inline int Length() const; |
| 2794 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2795 | inline bool IsEmptySlot(int index) const; |
| 2796 | static Object* Empty() { return Smi::FromInt(0); } |
| 2797 | |
| 2798 | class Iterator { |
| 2799 | public: |
| 2800 | explicit Iterator(Object* maybe_array) : list_(NULL) { Reset(maybe_array); } |
| 2801 | void Reset(Object* maybe_array); |
| 2802 | |
| 2803 | template <class T> |
| 2804 | inline T* Next(); |
| 2805 | |
| 2806 | private: |
| 2807 | int index_; |
| 2808 | WeakFixedArray* list_; |
| 2809 | #ifdef DEBUG |
| 2810 | int last_used_index_; |
| 2811 | DisallowHeapAllocation no_gc_; |
| 2812 | #endif // DEBUG |
| 2813 | DISALLOW_COPY_AND_ASSIGN(Iterator); |
| 2814 | }; |
| 2815 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2816 | DECLARE_CAST(WeakFixedArray) |
| 2817 | |
| 2818 | private: |
| 2819 | static const int kLastUsedIndexIndex = 0; |
| 2820 | static const int kFirstIndex = 1; |
| 2821 | |
| 2822 | static Handle<WeakFixedArray> Allocate( |
| 2823 | Isolate* isolate, int size, Handle<WeakFixedArray> initialize_from); |
| 2824 | |
| 2825 | static void Set(Handle<WeakFixedArray> array, int index, |
| 2826 | Handle<HeapObject> value); |
| 2827 | inline void clear(int index); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2828 | |
| 2829 | inline int last_used_index() const; |
| 2830 | inline void set_last_used_index(int index); |
| 2831 | |
| 2832 | // Disallow inherited setters. |
| 2833 | void set(int index, Smi* value); |
| 2834 | void set(int index, Object* value); |
| 2835 | void set(int index, Object* value, WriteBarrierMode mode); |
| 2836 | DISALLOW_IMPLICIT_CONSTRUCTORS(WeakFixedArray); |
| 2837 | }; |
| 2838 | |
| 2839 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2840 | // Generic array grows dynamically with O(1) amortized insertion. |
| 2841 | class ArrayList : public FixedArray { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2842 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2843 | enum AddMode { |
| 2844 | kNone, |
| 2845 | // Use this if GC can delete elements from the array. |
| 2846 | kReloadLengthAfterAllocation, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2847 | }; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2848 | static Handle<ArrayList> Add(Handle<ArrayList> array, Handle<Object> obj, |
| 2849 | AddMode mode = kNone); |
| 2850 | static Handle<ArrayList> Add(Handle<ArrayList> array, Handle<Object> obj1, |
| 2851 | Handle<Object> obj2, AddMode = kNone); |
| 2852 | inline int Length(); |
| 2853 | inline void SetLength(int length); |
| 2854 | inline Object* Get(int index); |
| 2855 | inline Object** Slot(int index); |
| 2856 | inline void Set(int index, Object* obj); |
| 2857 | inline void Clear(int index, Object* undefined); |
| 2858 | bool IsFull(); |
| 2859 | DECLARE_CAST(ArrayList) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2860 | |
| 2861 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2862 | static Handle<ArrayList> EnsureSpace(Handle<ArrayList> array, int length); |
| 2863 | static const int kLengthIndex = 0; |
| 2864 | static const int kFirstIndex = 1; |
| 2865 | DISALLOW_IMPLICIT_CONSTRUCTORS(ArrayList); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2866 | }; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2867 | |
| 2868 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2869 | // DescriptorArrays are fixed arrays used to hold instance descriptors. |
| 2870 | // The format of the these objects is: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2871 | // [0]: Number of descriptors |
| 2872 | // [1]: Either Smi(0) if uninitialized, or a pointer to small fixed array: |
| 2873 | // [0]: pointer to fixed array with enum cache |
| 2874 | // [1]: either Smi(0) or pointer to fixed array with indices |
| 2875 | // [2]: first key |
| 2876 | // [2 + number of descriptors * kDescriptorSize]: start of slack |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2877 | class DescriptorArray: public FixedArray { |
| 2878 | public: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2879 | // Returns true for both shared empty_descriptor_array and for smis, which the |
| 2880 | // map uses to encode additional bit fields when the descriptor array is not |
| 2881 | // yet used. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2882 | inline bool IsEmpty(); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2883 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2884 | // Returns the number of descriptors in the array. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2885 | inline int number_of_descriptors(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2886 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2887 | inline int number_of_descriptors_storage(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2888 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2889 | inline int NumberOfSlackDescriptors(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2890 | |
| 2891 | inline void SetNumberOfDescriptors(int number_of_descriptors); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2892 | inline int number_of_entries(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2893 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2894 | inline bool HasEnumCache(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2895 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2896 | inline void CopyEnumCacheFrom(DescriptorArray* array); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2897 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2898 | inline FixedArray* GetEnumCache(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2899 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2900 | inline bool HasEnumIndicesCache(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2901 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2902 | inline FixedArray* GetEnumIndicesCache(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2903 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2904 | inline Object** GetEnumCacheSlot(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2905 | |
| 2906 | void ClearEnumCache(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2907 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2908 | // Initialize or change the enum cache, |
| 2909 | // using the supplied storage for the small "bridge". |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2910 | static void SetEnumCache(Handle<DescriptorArray> descriptors, |
| 2911 | Isolate* isolate, Handle<FixedArray> new_cache, |
| 2912 | Handle<FixedArray> new_index_cache); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2913 | |
| 2914 | // Accessors for fetching instance descriptor at descriptor number. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2915 | inline Name* GetKey(int descriptor_number); |
| 2916 | inline Object** GetKeySlot(int descriptor_number); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2917 | inline Object* GetValue(int descriptor_number); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2918 | inline void SetValue(int descriptor_number, Object* value); |
| 2919 | inline Object** GetValueSlot(int descriptor_number); |
| 2920 | static inline int GetValueOffset(int descriptor_number); |
| 2921 | inline Object** GetDescriptorStartSlot(int descriptor_number); |
| 2922 | inline Object** GetDescriptorEndSlot(int descriptor_number); |
| 2923 | inline PropertyDetails GetDetails(int descriptor_number); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2924 | inline PropertyType GetType(int descriptor_number); |
| 2925 | inline int GetFieldIndex(int descriptor_number); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2926 | FieldType* GetFieldType(int descriptor_number); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2927 | inline Object* GetConstant(int descriptor_number); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2928 | inline Object* GetCallbacksObject(int descriptor_number); |
| 2929 | inline AccessorDescriptor* GetCallbacks(int descriptor_number); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2930 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2931 | inline Name* GetSortedKey(int descriptor_number); |
| 2932 | inline int GetSortedKeyIndex(int descriptor_number); |
| 2933 | inline void SetSortedKey(int pointer, int descriptor_number); |
| 2934 | inline void SetRepresentation(int descriptor_number, |
| 2935 | Representation representation); |
| 2936 | |
| 2937 | // Accessor for complete descriptor. |
| 2938 | inline void Get(int descriptor_number, Descriptor* desc); |
| 2939 | inline void Set(int descriptor_number, Descriptor* desc); |
| 2940 | void Replace(int descriptor_number, Descriptor* descriptor); |
| 2941 | |
| 2942 | // Append automatically sets the enumeration index. This should only be used |
| 2943 | // to add descriptors in bulk at the end, followed by sorting the descriptor |
| 2944 | // array. |
| 2945 | inline void Append(Descriptor* desc); |
| 2946 | |
| 2947 | static Handle<DescriptorArray> CopyUpTo(Handle<DescriptorArray> desc, |
| 2948 | int enumeration_index, |
| 2949 | int slack = 0); |
| 2950 | |
| 2951 | static Handle<DescriptorArray> CopyUpToAddAttributes( |
| 2952 | Handle<DescriptorArray> desc, |
| 2953 | int enumeration_index, |
| 2954 | PropertyAttributes attributes, |
| 2955 | int slack = 0); |
| 2956 | |
| 2957 | // Sort the instance descriptors by the hash codes of their keys. |
| 2958 | void Sort(); |
| 2959 | |
| 2960 | // Search the instance descriptors for given name. |
| 2961 | INLINE(int Search(Name* name, int number_of_own_descriptors)); |
| 2962 | |
| 2963 | // As the above, but uses DescriptorLookupCache and updates it when |
| 2964 | // necessary. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2965 | INLINE(int SearchWithCache(Isolate* isolate, Name* name, Map* map)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2966 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2967 | bool IsEqualUpTo(DescriptorArray* desc, int nof_descriptors); |
| 2968 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2969 | // Allocates a DescriptorArray, but returns the singleton |
| 2970 | // empty descriptor array object if number_of_descriptors is 0. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2971 | static Handle<DescriptorArray> Allocate( |
| 2972 | Isolate* isolate, int number_of_descriptors, int slack, |
| 2973 | PretenureFlag pretenure = NOT_TENURED); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2974 | |
| 2975 | DECLARE_CAST(DescriptorArray) |
| 2976 | |
| 2977 | // Constant for denoting key was not found. |
| 2978 | static const int kNotFound = -1; |
| 2979 | |
| 2980 | static const int kDescriptorLengthIndex = 0; |
| 2981 | static const int kEnumCacheIndex = 1; |
| 2982 | static const int kFirstIndex = 2; |
| 2983 | |
| 2984 | // The length of the "bridge" to the enum cache. |
| 2985 | static const int kEnumCacheBridgeLength = 2; |
| 2986 | static const int kEnumCacheBridgeCacheIndex = 0; |
| 2987 | static const int kEnumCacheBridgeIndicesCacheIndex = 1; |
| 2988 | |
| 2989 | // Layout description. |
| 2990 | static const int kDescriptorLengthOffset = FixedArray::kHeaderSize; |
| 2991 | static const int kEnumCacheOffset = kDescriptorLengthOffset + kPointerSize; |
| 2992 | static const int kFirstOffset = kEnumCacheOffset + kPointerSize; |
| 2993 | |
| 2994 | // Layout description for the bridge array. |
| 2995 | static const int kEnumCacheBridgeCacheOffset = FixedArray::kHeaderSize; |
| 2996 | |
| 2997 | // Layout of descriptor. |
| 2998 | static const int kDescriptorKey = 0; |
| 2999 | static const int kDescriptorDetails = 1; |
| 3000 | static const int kDescriptorValue = 2; |
| 3001 | static const int kDescriptorSize = 3; |
| 3002 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3003 | #if defined(DEBUG) || defined(OBJECT_PRINT) |
| 3004 | // For our gdb macros, we should perhaps change these in the future. |
| 3005 | void Print(); |
| 3006 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3007 | // Print all the descriptors. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3008 | void PrintDescriptors(std::ostream& os); // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3009 | #endif |
| 3010 | |
| 3011 | #ifdef DEBUG |
| 3012 | // Is the descriptor array sorted and without duplicates? |
| 3013 | bool IsSortedNoDuplicates(int valid_descriptors = -1); |
| 3014 | |
| 3015 | // Is the descriptor array consistent with the back pointers in targets? |
| 3016 | bool IsConsistentWithBackPointers(Map* current_map); |
| 3017 | |
| 3018 | // Are two DescriptorArrays equal? |
| 3019 | bool IsEqualTo(DescriptorArray* other); |
| 3020 | #endif |
| 3021 | |
| 3022 | // Returns the fixed array length required to hold number_of_descriptors |
| 3023 | // descriptors. |
| 3024 | static int LengthFor(int number_of_descriptors) { |
| 3025 | return ToKeyIndex(number_of_descriptors); |
| 3026 | } |
| 3027 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 3028 | static int ToDetailsIndex(int descriptor_number) { |
| 3029 | return kFirstIndex + (descriptor_number * kDescriptorSize) + |
| 3030 | kDescriptorDetails; |
| 3031 | } |
| 3032 | |
| 3033 | // Conversion from descriptor number to array indices. |
| 3034 | static int ToKeyIndex(int descriptor_number) { |
| 3035 | return kFirstIndex + (descriptor_number * kDescriptorSize) + kDescriptorKey; |
| 3036 | } |
| 3037 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 3038 | static int ToValueIndex(int descriptor_number) { |
| 3039 | return kFirstIndex + (descriptor_number * kDescriptorSize) + |
| 3040 | kDescriptorValue; |
| 3041 | } |
| 3042 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3043 | private: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3044 | // An entry in a DescriptorArray, represented as an (array, index) pair. |
| 3045 | class Entry { |
| 3046 | public: |
| 3047 | inline explicit Entry(DescriptorArray* descs, int index) : |
| 3048 | descs_(descs), index_(index) { } |
| 3049 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3050 | inline PropertyType type(); |
| 3051 | inline Object* GetCallbackObject(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3052 | |
| 3053 | private: |
| 3054 | DescriptorArray* descs_; |
| 3055 | int index_; |
| 3056 | }; |
| 3057 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3058 | // Transfer a complete descriptor from the src descriptor array to this |
| 3059 | // descriptor array. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3060 | void CopyFrom(int index, DescriptorArray* src); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3061 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3062 | inline void SetDescriptor(int descriptor_number, Descriptor* desc); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3063 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3064 | // Swap first and second descriptor. |
| 3065 | inline void SwapSortedKeys(int first, int second); |
| 3066 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3067 | DISALLOW_IMPLICIT_CONSTRUCTORS(DescriptorArray); |
| 3068 | }; |
| 3069 | |
| 3070 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3071 | enum SearchMode { ALL_ENTRIES, VALID_ENTRIES }; |
| 3072 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3073 | template <SearchMode search_mode, typename T> |
| 3074 | inline int Search(T* array, Name* name, int valid_entries = 0, |
| 3075 | int* out_insertion_index = NULL); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3076 | |
| 3077 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3078 | // HashTable is a subclass of FixedArray that implements a hash table |
| 3079 | // that uses open addressing and quadratic probing. |
| 3080 | // |
| 3081 | // In order for the quadratic probing to work, elements that have not |
| 3082 | // yet been used and elements that have been deleted are |
| 3083 | // distinguished. Probing continues when deleted elements are |
| 3084 | // encountered and stops when unused elements are encountered. |
| 3085 | // |
| 3086 | // - Elements with key == undefined have not been used yet. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3087 | // - Elements with key == the_hole have been deleted. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3088 | // |
| 3089 | // The hash table class is parameterized with a Shape and a Key. |
| 3090 | // Shape must be a class with the following interface: |
| 3091 | // class ExampleShape { |
| 3092 | // public: |
| 3093 | // // Tells whether key matches other. |
| 3094 | // static bool IsMatch(Key key, Object* other); |
| 3095 | // // Returns the hash value for key. |
| 3096 | // static uint32_t Hash(Key key); |
| 3097 | // // Returns the hash value for object. |
| 3098 | // static uint32_t HashForObject(Key key, Object* object); |
| 3099 | // // Convert key to an object. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3100 | // static inline Handle<Object> AsHandle(Isolate* isolate, Key key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3101 | // // The prefix size indicates number of elements in the beginning |
| 3102 | // // of the backing storage. |
| 3103 | // static const int kPrefixSize = ..; |
| 3104 | // // The Element size indicates number of elements per entry. |
| 3105 | // static const int kEntrySize = ..; |
| 3106 | // }; |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3107 | // The prefix size indicates an amount of memory in the |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3108 | // beginning of the backing storage that can be used for non-element |
| 3109 | // information by subclasses. |
| 3110 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3111 | template<typename Key> |
| 3112 | class BaseShape { |
| 3113 | public: |
| 3114 | static const bool UsesSeed = false; |
| 3115 | static uint32_t Hash(Key key) { return 0; } |
| 3116 | static uint32_t SeededHash(Key key, uint32_t seed) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3117 | DCHECK(UsesSeed); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3118 | return Hash(key); |
| 3119 | } |
| 3120 | static uint32_t HashForObject(Key key, Object* object) { return 0; } |
| 3121 | static uint32_t SeededHashForObject(Key key, uint32_t seed, Object* object) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3122 | DCHECK(UsesSeed); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3123 | return HashForObject(key, object); |
| 3124 | } |
| 3125 | }; |
| 3126 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3127 | |
| 3128 | class HashTableBase : public FixedArray { |
| 3129 | public: |
| 3130 | // Returns the number of elements in the hash table. |
| 3131 | inline int NumberOfElements(); |
| 3132 | |
| 3133 | // Returns the number of deleted elements in the hash table. |
| 3134 | inline int NumberOfDeletedElements(); |
| 3135 | |
| 3136 | // Returns the capacity of the hash table. |
| 3137 | inline int Capacity(); |
| 3138 | |
| 3139 | // ElementAdded should be called whenever an element is added to a |
| 3140 | // hash table. |
| 3141 | inline void ElementAdded(); |
| 3142 | |
| 3143 | // ElementRemoved should be called whenever an element is removed from |
| 3144 | // a hash table. |
| 3145 | inline void ElementRemoved(); |
| 3146 | inline void ElementsRemoved(int n); |
| 3147 | |
| 3148 | // Computes the required capacity for a table holding the given |
| 3149 | // number of elements. May be more than HashTable::kMaxCapacity. |
| 3150 | static inline int ComputeCapacity(int at_least_space_for); |
| 3151 | |
| 3152 | // Tells whether k is a real key. The hole and undefined are not allowed |
| 3153 | // as keys and can be used to indicate missing or deleted elements. |
| 3154 | inline bool IsKey(Object* k); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 3155 | inline bool IsKey(Heap* heap, Object* k); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3156 | |
| 3157 | // Compute the probe offset (quadratic probing). |
| 3158 | INLINE(static uint32_t GetProbeOffset(uint32_t n)) { |
| 3159 | return (n + n * n) >> 1; |
| 3160 | } |
| 3161 | |
| 3162 | static const int kNumberOfElementsIndex = 0; |
| 3163 | static const int kNumberOfDeletedElementsIndex = 1; |
| 3164 | static const int kCapacityIndex = 2; |
| 3165 | static const int kPrefixStartIndex = 3; |
| 3166 | |
| 3167 | // Constant used for denoting a absent entry. |
| 3168 | static const int kNotFound = -1; |
| 3169 | |
| 3170 | protected: |
| 3171 | // Update the number of elements in the hash table. |
| 3172 | inline void SetNumberOfElements(int nof); |
| 3173 | |
| 3174 | // Update the number of deleted elements in the hash table. |
| 3175 | inline void SetNumberOfDeletedElements(int nod); |
| 3176 | |
| 3177 | // Returns probe entry. |
| 3178 | static uint32_t GetProbe(uint32_t hash, uint32_t number, uint32_t size) { |
| 3179 | DCHECK(base::bits::IsPowerOfTwo32(size)); |
| 3180 | return (hash + GetProbeOffset(number)) & (size - 1); |
| 3181 | } |
| 3182 | |
| 3183 | inline static uint32_t FirstProbe(uint32_t hash, uint32_t size) { |
| 3184 | return hash & (size - 1); |
| 3185 | } |
| 3186 | |
| 3187 | inline static uint32_t NextProbe( |
| 3188 | uint32_t last, uint32_t number, uint32_t size) { |
| 3189 | return (last + number) & (size - 1); |
| 3190 | } |
| 3191 | }; |
| 3192 | |
| 3193 | |
| 3194 | template <typename Derived, typename Shape, typename Key> |
| 3195 | class HashTable : public HashTableBase { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3196 | public: |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3197 | // Wrapper methods |
| 3198 | inline uint32_t Hash(Key key) { |
| 3199 | if (Shape::UsesSeed) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3200 | return Shape::SeededHash(key, GetHeap()->HashSeed()); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3201 | } else { |
| 3202 | return Shape::Hash(key); |
| 3203 | } |
| 3204 | } |
| 3205 | |
| 3206 | inline uint32_t HashForObject(Key key, Object* object) { |
| 3207 | if (Shape::UsesSeed) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3208 | return Shape::SeededHashForObject(key, GetHeap()->HashSeed(), object); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3209 | } else { |
| 3210 | return Shape::HashForObject(key, object); |
| 3211 | } |
| 3212 | } |
| 3213 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3214 | // Returns a new HashTable object. |
| 3215 | MUST_USE_RESULT static Handle<Derived> New( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3216 | Isolate* isolate, int at_least_space_for, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3217 | MinimumCapacity capacity_option = USE_DEFAULT_MINIMUM_CAPACITY, |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3218 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3219 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3220 | DECLARE_CAST(HashTable) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3221 | |
| 3222 | // Garbage collection support. |
| 3223 | void IteratePrefix(ObjectVisitor* visitor); |
| 3224 | void IterateElements(ObjectVisitor* visitor); |
| 3225 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3226 | // Find entry for key otherwise return kNotFound. |
| 3227 | inline int FindEntry(Key key); |
| 3228 | inline int FindEntry(Isolate* isolate, Key key, int32_t hash); |
| 3229 | int FindEntry(Isolate* isolate, Key key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3230 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3231 | // Rehashes the table in-place. |
| 3232 | void Rehash(Key key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3233 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3234 | // Returns the key at entry. |
| 3235 | Object* KeyAt(int entry) { return get(EntryToIndex(entry)); } |
| 3236 | |
| 3237 | static const int kElementsStartIndex = kPrefixStartIndex + Shape::kPrefixSize; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 3238 | static const int kEntrySize = Shape::kEntrySize; |
| 3239 | static const int kElementsStartOffset = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3240 | kHeaderSize + kElementsStartIndex * kPointerSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3241 | static const int kCapacityOffset = |
| 3242 | kHeaderSize + kCapacityIndex * kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3243 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3244 | // Returns the index for an entry (of the key) |
| 3245 | static inline int EntryToIndex(int entry) { |
| 3246 | return (entry * kEntrySize) + kElementsStartIndex; |
| 3247 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3248 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3249 | protected: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3250 | friend class ObjectHashTable; |
| 3251 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3252 | // Find the entry at which to insert element with the given key that |
| 3253 | // has the given hash value. |
| 3254 | uint32_t FindInsertionEntry(uint32_t hash); |
| 3255 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3256 | // Attempt to shrink hash table after removal of key. |
| 3257 | MUST_USE_RESULT static Handle<Derived> Shrink(Handle<Derived> table, Key key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3258 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3259 | // Ensure enough space for n additional elements. |
| 3260 | MUST_USE_RESULT static Handle<Derived> EnsureCapacity( |
| 3261 | Handle<Derived> table, |
| 3262 | int n, |
| 3263 | Key key, |
| 3264 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3265 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3266 | // Returns true if this table has sufficient capacity for adding n elements. |
| 3267 | bool HasSufficientCapacity(int n); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 3268 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3269 | // Sets the capacity of the hash table. |
| 3270 | void SetCapacity(int capacity) { |
| 3271 | // To scale a computed hash code to fit within the hash table, we |
| 3272 | // use bit-wise AND with a mask, so the capacity must be positive |
| 3273 | // and non-zero. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3274 | DCHECK(capacity > 0); |
| 3275 | DCHECK(capacity <= kMaxCapacity); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3276 | set(kCapacityIndex, Smi::FromInt(capacity)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3277 | } |
| 3278 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3279 | // Maximal capacity of HashTable. Based on maximal length of underlying |
| 3280 | // FixedArray. Staying below kMaxCapacity also ensures that EntryToIndex |
| 3281 | // cannot overflow. |
| 3282 | static const int kMaxCapacity = |
| 3283 | (FixedArray::kMaxLength - kElementsStartOffset) / kEntrySize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3284 | |
| 3285 | private: |
| 3286 | // Returns _expected_ if one of entries given by the first _probe_ probes is |
| 3287 | // equal to _expected_. Otherwise, returns the entry given by the probe |
| 3288 | // number _probe_. |
| 3289 | uint32_t EntryForProbe(Key key, Object* k, int probe, uint32_t expected); |
| 3290 | |
| 3291 | void Swap(uint32_t entry1, uint32_t entry2, WriteBarrierMode mode); |
| 3292 | |
| 3293 | // Rehashes this hash-table into the new table. |
| 3294 | void Rehash(Handle<Derived> new_table, Key key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3295 | }; |
| 3296 | |
| 3297 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3298 | // HashTableKey is an abstract superclass for virtual key behavior. |
| 3299 | class HashTableKey { |
| 3300 | public: |
| 3301 | // Returns whether the other object matches this key. |
| 3302 | virtual bool IsMatch(Object* other) = 0; |
| 3303 | // Returns the hash value for this key. |
| 3304 | virtual uint32_t Hash() = 0; |
| 3305 | // Returns the hash value for object. |
| 3306 | virtual uint32_t HashForObject(Object* key) = 0; |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3307 | // Returns the key object for storing into the hash table. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3308 | MUST_USE_RESULT virtual Handle<Object> AsHandle(Isolate* isolate) = 0; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3309 | // Required. |
| 3310 | virtual ~HashTableKey() {} |
| 3311 | }; |
| 3312 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3313 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3314 | class StringTableShape : public BaseShape<HashTableKey*> { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3315 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3316 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3317 | return key->IsMatch(value); |
| 3318 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3319 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3320 | static inline uint32_t Hash(HashTableKey* key) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3321 | return key->Hash(); |
| 3322 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3323 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3324 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3325 | return key->HashForObject(object); |
| 3326 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3327 | |
| 3328 | static inline Handle<Object> AsHandle(Isolate* isolate, HashTableKey* key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3329 | |
| 3330 | static const int kPrefixSize = 0; |
| 3331 | static const int kEntrySize = 1; |
| 3332 | }; |
| 3333 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3334 | class SeqOneByteString; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3335 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3336 | // StringTable. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3337 | // |
| 3338 | // No special elements in the prefix and the element size is 1 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3339 | // because only the string itself (the key) needs to be stored. |
| 3340 | class StringTable: public HashTable<StringTable, |
| 3341 | StringTableShape, |
| 3342 | HashTableKey*> { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3343 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3344 | // Find string in the string table. If it is not there yet, it is |
| 3345 | // added. The return value is the string found. |
| 3346 | static Handle<String> LookupString(Isolate* isolate, Handle<String> key); |
| 3347 | static Handle<String> LookupKey(Isolate* isolate, HashTableKey* key); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3348 | static String* LookupKeyIfExists(Isolate* isolate, HashTableKey* key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3349 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3350 | // Tries to internalize given string and returns string handle on success |
| 3351 | // or an empty handle otherwise. |
| 3352 | MUST_USE_RESULT static MaybeHandle<String> InternalizeStringIfExists( |
| 3353 | Isolate* isolate, |
| 3354 | Handle<String> string); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3355 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3356 | // Looks up a string that is equal to the given string and returns |
| 3357 | // string handle if it is found, or an empty handle otherwise. |
| 3358 | MUST_USE_RESULT static MaybeHandle<String> LookupStringIfExists( |
| 3359 | Isolate* isolate, |
| 3360 | Handle<String> str); |
| 3361 | MUST_USE_RESULT static MaybeHandle<String> LookupTwoCharsStringIfExists( |
| 3362 | Isolate* isolate, |
| 3363 | uint16_t c1, |
| 3364 | uint16_t c2); |
| 3365 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3366 | static void EnsureCapacityForDeserialization(Isolate* isolate, int expected); |
| 3367 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3368 | DECLARE_CAST(StringTable) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3369 | |
| 3370 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3371 | template <bool seq_one_byte> |
| 3372 | friend class JsonParser; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3373 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3374 | DISALLOW_IMPLICIT_CONSTRUCTORS(StringTable); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3375 | }; |
| 3376 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 3377 | class StringSetShape : public BaseShape<String*> { |
| 3378 | public: |
| 3379 | static inline bool IsMatch(String* key, Object* value); |
| 3380 | static inline uint32_t Hash(String* key); |
| 3381 | static inline uint32_t HashForObject(String* key, Object* object); |
| 3382 | |
| 3383 | static const int kPrefixSize = 0; |
| 3384 | static const int kEntrySize = 1; |
| 3385 | }; |
| 3386 | |
| 3387 | class StringSet : public HashTable<StringSet, StringSetShape, String*> { |
| 3388 | public: |
| 3389 | static Handle<StringSet> New(Isolate* isolate); |
| 3390 | static Handle<StringSet> Add(Handle<StringSet> blacklist, |
| 3391 | Handle<String> name); |
| 3392 | bool Has(Handle<String> name); |
| 3393 | |
| 3394 | DECLARE_CAST(StringSet) |
| 3395 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3396 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3397 | template <typename Derived, typename Shape, typename Key> |
| 3398 | class Dictionary: public HashTable<Derived, Shape, Key> { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3399 | typedef HashTable<Derived, Shape, Key> DerivedHashTable; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3400 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3401 | public: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3402 | // Returns the value at entry. |
| 3403 | Object* ValueAt(int entry) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3404 | return this->get(Derived::EntryToIndex(entry) + 1); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3405 | } |
| 3406 | |
| 3407 | // Set the value for entry. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3408 | void ValueAtPut(int entry, Object* value) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3409 | this->set(Derived::EntryToIndex(entry) + 1, value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3410 | } |
| 3411 | |
| 3412 | // Returns the property details for the property at entry. |
| 3413 | PropertyDetails DetailsAt(int entry) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3414 | return Shape::DetailsAt(static_cast<Derived*>(this), entry); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3415 | } |
| 3416 | |
| 3417 | // Set the details for entry. |
| 3418 | void DetailsAtPut(int entry, PropertyDetails value) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3419 | Shape::DetailsAtPut(static_cast<Derived*>(this), entry, value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3420 | } |
| 3421 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3422 | // Returns true if property at given entry is deleted. |
| 3423 | bool IsDeleted(int entry) { |
| 3424 | return Shape::IsDeleted(static_cast<Derived*>(this), entry); |
| 3425 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3426 | |
| 3427 | // Delete a property from the dictionary. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3428 | static Handle<Object> DeleteProperty(Handle<Derived> dictionary, int entry); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3429 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3430 | // Attempt to shrink the dictionary after deletion of key. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3431 | MUST_USE_RESULT static inline Handle<Derived> Shrink( |
| 3432 | Handle<Derived> dictionary, |
| 3433 | Key key) { |
| 3434 | return DerivedHashTable::Shrink(dictionary, key); |
| 3435 | } |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3436 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3437 | // Sorting support |
| 3438 | // TODO(dcarney): templatize or move to SeededNumberDictionary |
| 3439 | void CopyValuesTo(FixedArray* elements); |
| 3440 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3441 | // Returns the number of elements in the dictionary filtering out properties |
| 3442 | // with the specified attributes. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3443 | int NumberOfElementsFilterAttributes(PropertyFilter filter); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3444 | |
| 3445 | // Returns the number of enumerable elements in the dictionary. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3446 | int NumberOfEnumElements() { |
| 3447 | return NumberOfElementsFilterAttributes(ENUMERABLE_STRINGS); |
| 3448 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3449 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3450 | enum SortMode { UNSORTED, SORTED }; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3451 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3452 | // Collect the keys into the given KeyAccumulator, in ascending chronological |
| 3453 | // order of property creation. |
| 3454 | static void CollectKeysTo(Handle<Dictionary<Derived, Shape, Key> > dictionary, |
| 3455 | KeyAccumulator* keys, PropertyFilter filter); |
| 3456 | |
| 3457 | // Copies enumerable keys to preallocated fixed array. |
| 3458 | void CopyEnumKeysTo(FixedArray* storage); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3459 | |
| 3460 | // Accessors for next enumeration index. |
| 3461 | void SetNextEnumerationIndex(int index) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3462 | DCHECK(index != 0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3463 | this->set(kNextEnumerationIndexIndex, Smi::FromInt(index)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3464 | } |
| 3465 | |
| 3466 | int NextEnumerationIndex() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3467 | return Smi::cast(this->get(kNextEnumerationIndexIndex))->value(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3468 | } |
| 3469 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3470 | // Creates a new dictionary. |
| 3471 | MUST_USE_RESULT static Handle<Derived> New( |
| 3472 | Isolate* isolate, |
| 3473 | int at_least_space_for, |
| 3474 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3475 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3476 | // Ensures that a new dictionary is created when the capacity is checked. |
| 3477 | void SetRequiresCopyOnCapacityChange(); |
| 3478 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3479 | // Ensure enough space for n additional elements. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3480 | static Handle<Derived> EnsureCapacity(Handle<Derived> obj, int n, Key key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3481 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3482 | #ifdef OBJECT_PRINT |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3483 | void Print(std::ostream& os); // NOLINT |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3484 | #endif |
| 3485 | // Returns the key (slow). |
| 3486 | Object* SlowReverseLookup(Object* value); |
| 3487 | |
| 3488 | // Sets the entry to (key, value) pair. |
| 3489 | inline void SetEntry(int entry, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3490 | Handle<Object> key, |
| 3491 | Handle<Object> value); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3492 | inline void SetEntry(int entry, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3493 | Handle<Object> key, |
| 3494 | Handle<Object> value, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3495 | PropertyDetails details); |
| 3496 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3497 | MUST_USE_RESULT static Handle<Derived> Add( |
| 3498 | Handle<Derived> dictionary, |
| 3499 | Key key, |
| 3500 | Handle<Object> value, |
| 3501 | PropertyDetails details); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3502 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3503 | // Returns iteration indices array for the |dictionary|. |
| 3504 | // Values are direct indices in the |HashTable| array. |
| 3505 | static Handle<FixedArray> BuildIterationIndicesArray( |
| 3506 | Handle<Derived> dictionary); |
| 3507 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3508 | protected: |
| 3509 | // Generic at put operation. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3510 | MUST_USE_RESULT static Handle<Derived> AtPut( |
| 3511 | Handle<Derived> dictionary, |
| 3512 | Key key, |
| 3513 | Handle<Object> value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3514 | |
| 3515 | // Add entry to dictionary. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3516 | static void AddEntry( |
| 3517 | Handle<Derived> dictionary, |
| 3518 | Key key, |
| 3519 | Handle<Object> value, |
| 3520 | PropertyDetails details, |
| 3521 | uint32_t hash); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3522 | |
| 3523 | // Generate new enumeration indices to avoid enumeration index overflow. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3524 | // Returns iteration indices array for the |dictionary|. |
| 3525 | static Handle<FixedArray> GenerateNewEnumerationIndices( |
| 3526 | Handle<Derived> dictionary); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3527 | static const int kMaxNumberKeyIndex = DerivedHashTable::kPrefixStartIndex; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3528 | static const int kNextEnumerationIndexIndex = kMaxNumberKeyIndex + 1; |
| 3529 | }; |
| 3530 | |
| 3531 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3532 | template <typename Derived, typename Shape> |
| 3533 | class NameDictionaryBase : public Dictionary<Derived, Shape, Handle<Name> > { |
| 3534 | typedef Dictionary<Derived, Shape, Handle<Name> > DerivedDictionary; |
| 3535 | |
| 3536 | public: |
| 3537 | // Find entry for key, otherwise return kNotFound. Optimized version of |
| 3538 | // HashTable::FindEntry. |
| 3539 | int FindEntry(Handle<Name> key); |
| 3540 | }; |
| 3541 | |
| 3542 | |
| 3543 | template <typename Key> |
| 3544 | class BaseDictionaryShape : public BaseShape<Key> { |
| 3545 | public: |
| 3546 | template <typename Dictionary> |
| 3547 | static inline PropertyDetails DetailsAt(Dictionary* dict, int entry) { |
| 3548 | STATIC_ASSERT(Dictionary::kEntrySize == 3); |
| 3549 | DCHECK(entry >= 0); // Not found is -1, which is not caught by get(). |
| 3550 | return PropertyDetails( |
| 3551 | Smi::cast(dict->get(Dictionary::EntryToIndex(entry) + 2))); |
| 3552 | } |
| 3553 | |
| 3554 | template <typename Dictionary> |
| 3555 | static inline void DetailsAtPut(Dictionary* dict, int entry, |
| 3556 | PropertyDetails value) { |
| 3557 | STATIC_ASSERT(Dictionary::kEntrySize == 3); |
| 3558 | dict->set(Dictionary::EntryToIndex(entry) + 2, value.AsSmi()); |
| 3559 | } |
| 3560 | |
| 3561 | template <typename Dictionary> |
| 3562 | static bool IsDeleted(Dictionary* dict, int entry) { |
| 3563 | return false; |
| 3564 | } |
| 3565 | |
| 3566 | template <typename Dictionary> |
| 3567 | static inline void SetEntry(Dictionary* dict, int entry, Handle<Object> key, |
| 3568 | Handle<Object> value, PropertyDetails details); |
| 3569 | }; |
| 3570 | |
| 3571 | |
| 3572 | class NameDictionaryShape : public BaseDictionaryShape<Handle<Name> > { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3573 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3574 | static inline bool IsMatch(Handle<Name> key, Object* other); |
| 3575 | static inline uint32_t Hash(Handle<Name> key); |
| 3576 | static inline uint32_t HashForObject(Handle<Name> key, Object* object); |
| 3577 | static inline Handle<Object> AsHandle(Isolate* isolate, Handle<Name> key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3578 | static const int kPrefixSize = 2; |
| 3579 | static const int kEntrySize = 3; |
| 3580 | static const bool kIsEnumerable = true; |
| 3581 | }; |
| 3582 | |
| 3583 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3584 | class NameDictionary |
| 3585 | : public NameDictionaryBase<NameDictionary, NameDictionaryShape> { |
| 3586 | typedef NameDictionaryBase<NameDictionary, NameDictionaryShape> |
| 3587 | DerivedDictionary; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3588 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3589 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3590 | DECLARE_CAST(NameDictionary) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3591 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3592 | inline static Handle<FixedArray> DoGenerateNewEnumerationIndices( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3593 | Handle<NameDictionary> dictionary); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3594 | }; |
| 3595 | |
| 3596 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3597 | class GlobalDictionaryShape : public NameDictionaryShape { |
| 3598 | public: |
| 3599 | static const int kEntrySize = 2; // Overrides NameDictionaryShape::kEntrySize |
| 3600 | |
| 3601 | template <typename Dictionary> |
| 3602 | static inline PropertyDetails DetailsAt(Dictionary* dict, int entry); |
| 3603 | |
| 3604 | template <typename Dictionary> |
| 3605 | static inline void DetailsAtPut(Dictionary* dict, int entry, |
| 3606 | PropertyDetails value); |
| 3607 | |
| 3608 | template <typename Dictionary> |
| 3609 | static bool IsDeleted(Dictionary* dict, int entry); |
| 3610 | |
| 3611 | template <typename Dictionary> |
| 3612 | static inline void SetEntry(Dictionary* dict, int entry, Handle<Object> key, |
| 3613 | Handle<Object> value, PropertyDetails details); |
| 3614 | }; |
| 3615 | |
| 3616 | |
| 3617 | class GlobalDictionary |
| 3618 | : public NameDictionaryBase<GlobalDictionary, GlobalDictionaryShape> { |
| 3619 | public: |
| 3620 | DECLARE_CAST(GlobalDictionary) |
| 3621 | }; |
| 3622 | |
| 3623 | |
| 3624 | class NumberDictionaryShape : public BaseDictionaryShape<uint32_t> { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3625 | public: |
| 3626 | static inline bool IsMatch(uint32_t key, Object* other); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3627 | static inline Handle<Object> AsHandle(Isolate* isolate, uint32_t key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3628 | static const int kEntrySize = 3; |
| 3629 | static const bool kIsEnumerable = false; |
| 3630 | }; |
| 3631 | |
| 3632 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3633 | class SeededNumberDictionaryShape : public NumberDictionaryShape { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3634 | public: |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3635 | static const bool UsesSeed = true; |
| 3636 | static const int kPrefixSize = 2; |
| 3637 | |
| 3638 | static inline uint32_t SeededHash(uint32_t key, uint32_t seed); |
| 3639 | static inline uint32_t SeededHashForObject(uint32_t key, |
| 3640 | uint32_t seed, |
| 3641 | Object* object); |
| 3642 | }; |
| 3643 | |
| 3644 | |
| 3645 | class UnseededNumberDictionaryShape : public NumberDictionaryShape { |
| 3646 | public: |
| 3647 | static const int kPrefixSize = 0; |
| 3648 | |
| 3649 | static inline uint32_t Hash(uint32_t key); |
| 3650 | static inline uint32_t HashForObject(uint32_t key, Object* object); |
| 3651 | }; |
| 3652 | |
| 3653 | |
| 3654 | class SeededNumberDictionary |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3655 | : public Dictionary<SeededNumberDictionary, |
| 3656 | SeededNumberDictionaryShape, |
| 3657 | uint32_t> { |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3658 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3659 | DECLARE_CAST(SeededNumberDictionary) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3660 | |
| 3661 | // Type specific at put (default NONE attributes is used when adding). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3662 | MUST_USE_RESULT static Handle<SeededNumberDictionary> AtNumberPut( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3663 | Handle<SeededNumberDictionary> dictionary, uint32_t key, |
| 3664 | Handle<Object> value, bool used_as_prototype); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3665 | MUST_USE_RESULT static Handle<SeededNumberDictionary> AddNumberEntry( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3666 | Handle<SeededNumberDictionary> dictionary, uint32_t key, |
| 3667 | Handle<Object> value, PropertyDetails details, bool used_as_prototype); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3668 | |
| 3669 | // Set an existing entry or add a new one if needed. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3670 | // Return the updated dictionary. |
| 3671 | MUST_USE_RESULT static Handle<SeededNumberDictionary> Set( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3672 | Handle<SeededNumberDictionary> dictionary, uint32_t key, |
| 3673 | Handle<Object> value, PropertyDetails details, bool used_as_prototype); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3674 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3675 | void UpdateMaxNumberKey(uint32_t key, bool used_as_prototype); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3676 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 3677 | // Returns true if the dictionary contains any elements that are non-writable, |
| 3678 | // non-configurable, non-enumerable, or have getters/setters. |
| 3679 | bool HasComplexElements(); |
| 3680 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3681 | // If slow elements are required we will never go back to fast-case |
| 3682 | // for the elements kept in this dictionary. We require slow |
| 3683 | // elements if an element has been added at an index larger than |
| 3684 | // kRequiresSlowElementsLimit or set_requires_slow_elements() has been called |
| 3685 | // when defining a getter or setter with a number key. |
| 3686 | inline bool requires_slow_elements(); |
| 3687 | inline void set_requires_slow_elements(); |
| 3688 | |
| 3689 | // Get the value of the max number key that has been added to this |
| 3690 | // dictionary. max_number_key can only be called if |
| 3691 | // requires_slow_elements returns false. |
| 3692 | inline uint32_t max_number_key(); |
| 3693 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3694 | // Bit masks. |
| 3695 | static const int kRequiresSlowElementsMask = 1; |
| 3696 | static const int kRequiresSlowElementsTagSize = 1; |
| 3697 | static const uint32_t kRequiresSlowElementsLimit = (1 << 29) - 1; |
| 3698 | }; |
| 3699 | |
| 3700 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3701 | class UnseededNumberDictionary |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3702 | : public Dictionary<UnseededNumberDictionary, |
| 3703 | UnseededNumberDictionaryShape, |
| 3704 | uint32_t> { |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3705 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3706 | DECLARE_CAST(UnseededNumberDictionary) |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3707 | |
| 3708 | // Type specific at put (default NONE attributes is used when adding). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3709 | MUST_USE_RESULT static Handle<UnseededNumberDictionary> AtNumberPut( |
| 3710 | Handle<UnseededNumberDictionary> dictionary, |
| 3711 | uint32_t key, |
| 3712 | Handle<Object> value); |
| 3713 | MUST_USE_RESULT static Handle<UnseededNumberDictionary> AddNumberEntry( |
| 3714 | Handle<UnseededNumberDictionary> dictionary, |
| 3715 | uint32_t key, |
| 3716 | Handle<Object> value); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3717 | |
| 3718 | // Set an existing entry or add a new one if needed. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3719 | // Return the updated dictionary. |
| 3720 | MUST_USE_RESULT static Handle<UnseededNumberDictionary> Set( |
| 3721 | Handle<UnseededNumberDictionary> dictionary, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3722 | uint32_t key, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3723 | Handle<Object> value); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3724 | }; |
| 3725 | |
| 3726 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3727 | class ObjectHashTableShape : public BaseShape<Handle<Object> > { |
Ben Murdoch | 2b4ba11 | 2012-01-20 14:57:15 +0000 | [diff] [blame] | 3728 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3729 | static inline bool IsMatch(Handle<Object> key, Object* other); |
| 3730 | static inline uint32_t Hash(Handle<Object> key); |
| 3731 | static inline uint32_t HashForObject(Handle<Object> key, Object* object); |
| 3732 | static inline Handle<Object> AsHandle(Isolate* isolate, Handle<Object> key); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 3733 | static const int kPrefixSize = 0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3734 | static const int kEntrySize = 2; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3735 | }; |
| 3736 | |
| 3737 | |
| 3738 | // ObjectHashTable maps keys that are arbitrary objects to object values by |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3739 | // using the identity hash of the key for hashing purposes. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3740 | class ObjectHashTable: public HashTable<ObjectHashTable, |
| 3741 | ObjectHashTableShape, |
| 3742 | Handle<Object> > { |
| 3743 | typedef HashTable< |
| 3744 | ObjectHashTable, ObjectHashTableShape, Handle<Object> > DerivedHashTable; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3745 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3746 | DECLARE_CAST(ObjectHashTable) |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3747 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3748 | // Attempt to shrink hash table after removal of key. |
| 3749 | MUST_USE_RESULT static inline Handle<ObjectHashTable> Shrink( |
| 3750 | Handle<ObjectHashTable> table, |
| 3751 | Handle<Object> key); |
| 3752 | |
| 3753 | // Looks up the value associated with the given key. The hole value is |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3754 | // returned in case the key is not present. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3755 | Object* Lookup(Handle<Object> key); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3756 | Object* Lookup(Handle<Object> key, int32_t hash); |
| 3757 | Object* Lookup(Isolate* isolate, Handle<Object> key, int32_t hash); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3758 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3759 | // Adds (or overwrites) the value associated with the given key. |
| 3760 | static Handle<ObjectHashTable> Put(Handle<ObjectHashTable> table, |
| 3761 | Handle<Object> key, |
| 3762 | Handle<Object> value); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3763 | static Handle<ObjectHashTable> Put(Handle<ObjectHashTable> table, |
| 3764 | Handle<Object> key, Handle<Object> value, |
| 3765 | int32_t hash); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3766 | |
| 3767 | // Returns an ObjectHashTable (possibly |table|) where |key| has been removed. |
| 3768 | static Handle<ObjectHashTable> Remove(Handle<ObjectHashTable> table, |
| 3769 | Handle<Object> key, |
| 3770 | bool* was_present); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3771 | static Handle<ObjectHashTable> Remove(Handle<ObjectHashTable> table, |
| 3772 | Handle<Object> key, bool* was_present, |
| 3773 | int32_t hash); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3774 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3775 | protected: |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3776 | friend class MarkCompactCollector; |
| 3777 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3778 | void AddEntry(int entry, Object* key, Object* value); |
| 3779 | void RemoveEntry(int entry); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3780 | |
| 3781 | // Returns the index to the value of an entry. |
| 3782 | static inline int EntryToValueIndex(int entry) { |
| 3783 | return EntryToIndex(entry) + 1; |
| 3784 | } |
| 3785 | }; |
| 3786 | |
| 3787 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3788 | // OrderedHashTable is a HashTable with Object keys that preserves |
| 3789 | // insertion order. There are Map and Set interfaces (OrderedHashMap |
| 3790 | // and OrderedHashTable, below). It is meant to be used by JSMap/JSSet. |
| 3791 | // |
| 3792 | // Only Object* keys are supported, with Object::SameValueZero() used as the |
| 3793 | // equality operator and Object::GetHash() for the hash function. |
| 3794 | // |
| 3795 | // Based on the "Deterministic Hash Table" as described by Jason Orendorff at |
| 3796 | // https://wiki.mozilla.org/User:Jorend/Deterministic_hash_tables |
| 3797 | // Originally attributed to Tyler Close. |
| 3798 | // |
| 3799 | // Memory layout: |
| 3800 | // [0]: bucket count |
| 3801 | // [1]: element count |
| 3802 | // [2]: deleted element count |
| 3803 | // [3..(3 + NumberOfBuckets() - 1)]: "hash table", where each item is an |
| 3804 | // offset into the data table (see below) where the |
| 3805 | // first item in this bucket is stored. |
| 3806 | // [3 + NumberOfBuckets()..length]: "data table", an array of length |
| 3807 | // Capacity() * kEntrySize, where the first entrysize |
| 3808 | // items are handled by the derived class and the |
| 3809 | // item at kChainOffset is another entry into the |
| 3810 | // data table indicating the next entry in this hash |
| 3811 | // bucket. |
| 3812 | // |
| 3813 | // When we transition the table to a new version we obsolete it and reuse parts |
| 3814 | // of the memory to store information how to transition an iterator to the new |
| 3815 | // table: |
| 3816 | // |
| 3817 | // Memory layout for obsolete table: |
| 3818 | // [0]: bucket count |
| 3819 | // [1]: Next newer table |
| 3820 | // [2]: Number of removed holes or -1 when the table was cleared. |
| 3821 | // [3..(3 + NumberOfRemovedHoles() - 1)]: The indexes of the removed holes. |
| 3822 | // [3 + NumberOfRemovedHoles()..length]: Not used |
| 3823 | // |
| 3824 | template<class Derived, class Iterator, int entrysize> |
| 3825 | class OrderedHashTable: public FixedArray { |
| 3826 | public: |
| 3827 | // Returns an OrderedHashTable with a capacity of at least |capacity|. |
| 3828 | static Handle<Derived> Allocate( |
| 3829 | Isolate* isolate, int capacity, PretenureFlag pretenure = NOT_TENURED); |
| 3830 | |
| 3831 | // Returns an OrderedHashTable (possibly |table|) with enough space |
| 3832 | // to add at least one new element. |
| 3833 | static Handle<Derived> EnsureGrowable(Handle<Derived> table); |
| 3834 | |
| 3835 | // Returns an OrderedHashTable (possibly |table|) that's shrunken |
| 3836 | // if possible. |
| 3837 | static Handle<Derived> Shrink(Handle<Derived> table); |
| 3838 | |
| 3839 | // Returns a new empty OrderedHashTable and records the clearing so that |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 3840 | // existing iterators can be updated. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3841 | static Handle<Derived> Clear(Handle<Derived> table); |
| 3842 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3843 | // Returns a true if the OrderedHashTable contains the key |
| 3844 | static bool HasKey(Handle<Derived> table, Handle<Object> key); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3845 | |
| 3846 | int NumberOfElements() { |
| 3847 | return Smi::cast(get(kNumberOfElementsIndex))->value(); |
| 3848 | } |
| 3849 | |
| 3850 | int NumberOfDeletedElements() { |
| 3851 | return Smi::cast(get(kNumberOfDeletedElementsIndex))->value(); |
| 3852 | } |
| 3853 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 3854 | // Returns the number of contiguous entries in the data table, starting at 0, |
| 3855 | // that either are real entries or have been deleted. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3856 | int UsedCapacity() { return NumberOfElements() + NumberOfDeletedElements(); } |
| 3857 | |
| 3858 | int NumberOfBuckets() { |
| 3859 | return Smi::cast(get(kNumberOfBucketsIndex))->value(); |
| 3860 | } |
| 3861 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3862 | // Returns an index into |this| for the given entry. |
| 3863 | int EntryToIndex(int entry) { |
| 3864 | return kHashTableStartIndex + NumberOfBuckets() + (entry * kEntrySize); |
| 3865 | } |
| 3866 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3867 | int HashToBucket(int hash) { return hash & (NumberOfBuckets() - 1); } |
| 3868 | |
| 3869 | int HashToEntry(int hash) { |
| 3870 | int bucket = HashToBucket(hash); |
| 3871 | Object* entry = this->get(kHashTableStartIndex + bucket); |
| 3872 | return Smi::cast(entry)->value(); |
| 3873 | } |
| 3874 | |
| 3875 | int KeyToFirstEntry(Object* key) { |
| 3876 | Object* hash = key->GetHash(); |
| 3877 | // If the object does not have an identity hash, it was never used as a key |
| 3878 | if (hash->IsUndefined()) return kNotFound; |
| 3879 | return HashToEntry(Smi::cast(hash)->value()); |
| 3880 | } |
| 3881 | |
| 3882 | int NextChainEntry(int entry) { |
| 3883 | Object* next_entry = get(EntryToIndex(entry) + kChainOffset); |
| 3884 | return Smi::cast(next_entry)->value(); |
| 3885 | } |
| 3886 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 3887 | // use KeyAt(i)->IsTheHole() to determine if this is a deleted entry. |
| 3888 | Object* KeyAt(int entry) { |
| 3889 | DCHECK_LT(entry, this->UsedCapacity()); |
| 3890 | return get(EntryToIndex(entry)); |
| 3891 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3892 | |
| 3893 | bool IsObsolete() { |
| 3894 | return !get(kNextTableIndex)->IsSmi(); |
| 3895 | } |
| 3896 | |
| 3897 | // The next newer table. This is only valid if the table is obsolete. |
| 3898 | Derived* NextTable() { |
| 3899 | return Derived::cast(get(kNextTableIndex)); |
| 3900 | } |
| 3901 | |
| 3902 | // When the table is obsolete we store the indexes of the removed holes. |
| 3903 | int RemovedIndexAt(int index) { |
| 3904 | return Smi::cast(get(kRemovedHolesIndex + index))->value(); |
| 3905 | } |
| 3906 | |
| 3907 | static const int kNotFound = -1; |
| 3908 | static const int kMinCapacity = 4; |
| 3909 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3910 | static const int kNumberOfBucketsIndex = 0; |
| 3911 | static const int kNumberOfElementsIndex = kNumberOfBucketsIndex + 1; |
| 3912 | static const int kNumberOfDeletedElementsIndex = kNumberOfElementsIndex + 1; |
| 3913 | static const int kHashTableStartIndex = kNumberOfDeletedElementsIndex + 1; |
| 3914 | static const int kNextTableIndex = kNumberOfElementsIndex; |
| 3915 | |
| 3916 | static const int kNumberOfBucketsOffset = |
| 3917 | kHeaderSize + kNumberOfBucketsIndex * kPointerSize; |
| 3918 | static const int kNumberOfElementsOffset = |
| 3919 | kHeaderSize + kNumberOfElementsIndex * kPointerSize; |
| 3920 | static const int kNumberOfDeletedElementsOffset = |
| 3921 | kHeaderSize + kNumberOfDeletedElementsIndex * kPointerSize; |
| 3922 | static const int kHashTableStartOffset = |
| 3923 | kHeaderSize + kHashTableStartIndex * kPointerSize; |
| 3924 | static const int kNextTableOffset = |
| 3925 | kHeaderSize + kNextTableIndex * kPointerSize; |
| 3926 | |
| 3927 | static const int kEntrySize = entrysize + 1; |
| 3928 | static const int kChainOffset = entrysize; |
| 3929 | |
| 3930 | static const int kLoadFactor = 2; |
| 3931 | |
| 3932 | // NumberOfDeletedElements is set to kClearedTableSentinel when |
| 3933 | // the table is cleared, which allows iterator transitions to |
| 3934 | // optimize that case. |
| 3935 | static const int kClearedTableSentinel = -1; |
| 3936 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3937 | protected: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3938 | static Handle<Derived> Rehash(Handle<Derived> table, int new_capacity); |
| 3939 | |
| 3940 | void SetNumberOfBuckets(int num) { |
| 3941 | set(kNumberOfBucketsIndex, Smi::FromInt(num)); |
| 3942 | } |
| 3943 | |
| 3944 | void SetNumberOfElements(int num) { |
| 3945 | set(kNumberOfElementsIndex, Smi::FromInt(num)); |
| 3946 | } |
| 3947 | |
| 3948 | void SetNumberOfDeletedElements(int num) { |
| 3949 | set(kNumberOfDeletedElementsIndex, Smi::FromInt(num)); |
| 3950 | } |
| 3951 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 3952 | // Returns the number elements that can fit into the allocated buffer. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3953 | int Capacity() { |
| 3954 | return NumberOfBuckets() * kLoadFactor; |
| 3955 | } |
| 3956 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3957 | void SetNextTable(Derived* next_table) { |
| 3958 | set(kNextTableIndex, next_table); |
| 3959 | } |
| 3960 | |
| 3961 | void SetRemovedIndexAt(int index, int removed_index) { |
| 3962 | return set(kRemovedHolesIndex + index, Smi::FromInt(removed_index)); |
| 3963 | } |
| 3964 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3965 | static const int kRemovedHolesIndex = kHashTableStartIndex; |
| 3966 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3967 | static const int kMaxCapacity = |
| 3968 | (FixedArray::kMaxLength - kHashTableStartIndex) |
| 3969 | / (1 + (kEntrySize * kLoadFactor)); |
| 3970 | }; |
| 3971 | |
| 3972 | |
| 3973 | class JSSetIterator; |
| 3974 | |
| 3975 | |
| 3976 | class OrderedHashSet: public OrderedHashTable< |
| 3977 | OrderedHashSet, JSSetIterator, 1> { |
| 3978 | public: |
| 3979 | DECLARE_CAST(OrderedHashSet) |
| 3980 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3981 | static Handle<OrderedHashSet> Add(Handle<OrderedHashSet> table, |
| 3982 | Handle<Object> value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3983 | }; |
| 3984 | |
| 3985 | |
| 3986 | class JSMapIterator; |
| 3987 | |
| 3988 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3989 | class OrderedHashMap |
| 3990 | : public OrderedHashTable<OrderedHashMap, JSMapIterator, 2> { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3991 | public: |
| 3992 | DECLARE_CAST(OrderedHashMap) |
| 3993 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3994 | inline Object* ValueAt(int entry); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3995 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3996 | static const int kValueOffset = 1; |
| 3997 | }; |
| 3998 | |
| 3999 | |
| 4000 | template <int entrysize> |
| 4001 | class WeakHashTableShape : public BaseShape<Handle<Object> > { |
| 4002 | public: |
| 4003 | static inline bool IsMatch(Handle<Object> key, Object* other); |
| 4004 | static inline uint32_t Hash(Handle<Object> key); |
| 4005 | static inline uint32_t HashForObject(Handle<Object> key, Object* object); |
| 4006 | static inline Handle<Object> AsHandle(Isolate* isolate, Handle<Object> key); |
| 4007 | static const int kPrefixSize = 0; |
| 4008 | static const int kEntrySize = entrysize; |
| 4009 | }; |
| 4010 | |
| 4011 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4012 | // WeakHashTable maps keys that are arbitrary heap objects to heap object |
| 4013 | // values. The table wraps the keys in weak cells and store values directly. |
| 4014 | // Thus it references keys weakly and values strongly. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4015 | class WeakHashTable: public HashTable<WeakHashTable, |
| 4016 | WeakHashTableShape<2>, |
| 4017 | Handle<Object> > { |
| 4018 | typedef HashTable< |
| 4019 | WeakHashTable, WeakHashTableShape<2>, Handle<Object> > DerivedHashTable; |
| 4020 | public: |
| 4021 | DECLARE_CAST(WeakHashTable) |
| 4022 | |
| 4023 | // Looks up the value associated with the given key. The hole value is |
| 4024 | // returned in case the key is not present. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4025 | Object* Lookup(Handle<HeapObject> key); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4026 | |
| 4027 | // Adds (or overwrites) the value associated with the given key. Mapping a |
| 4028 | // key to the hole value causes removal of the whole entry. |
| 4029 | MUST_USE_RESULT static Handle<WeakHashTable> Put(Handle<WeakHashTable> table, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4030 | Handle<HeapObject> key, |
| 4031 | Handle<HeapObject> value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4032 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4033 | static Handle<FixedArray> GetValues(Handle<WeakHashTable> table); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4034 | |
| 4035 | private: |
| 4036 | friend class MarkCompactCollector; |
| 4037 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4038 | void AddEntry(int entry, Handle<WeakCell> key, Handle<HeapObject> value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4039 | |
| 4040 | // Returns the index to the value of an entry. |
| 4041 | static inline int EntryToValueIndex(int entry) { |
| 4042 | return EntryToIndex(entry) + 1; |
| 4043 | } |
| 4044 | }; |
| 4045 | |
| 4046 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4047 | // ScopeInfo represents information about different scopes of a source |
| 4048 | // program and the allocation of the scope's variables. Scope information |
| 4049 | // is stored in a compressed form in ScopeInfo objects and is used |
| 4050 | // at runtime (stack dumps, deoptimization, etc.). |
| 4051 | |
| 4052 | // This object provides quick access to scope info details for runtime |
| 4053 | // routines. |
| 4054 | class ScopeInfo : public FixedArray { |
| 4055 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4056 | DECLARE_CAST(ScopeInfo) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4057 | |
| 4058 | // Return the type of this scope. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4059 | ScopeType scope_type(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4060 | |
| 4061 | // Does this scope call eval? |
| 4062 | bool CallsEval(); |
| 4063 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4064 | // Return the language mode of this scope. |
| 4065 | LanguageMode language_mode(); |
| 4066 | |
| 4067 | // True if this scope is a (var) declaration scope. |
| 4068 | bool is_declaration_scope(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4069 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4070 | // Does this scope make a sloppy eval call? |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4071 | bool CallsSloppyEval() { return CallsEval() && is_sloppy(language_mode()); } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4072 | |
| 4073 | // Return the total number of locals allocated on the stack and in the |
| 4074 | // context. This includes the parameters that are allocated in the context. |
| 4075 | int LocalCount(); |
| 4076 | |
| 4077 | // Return the number of stack slots for code. This number consists of two |
| 4078 | // parts: |
| 4079 | // 1. One stack slot per stack allocated local. |
| 4080 | // 2. One stack slot for the function name if it is stack allocated. |
| 4081 | int StackSlotCount(); |
| 4082 | |
| 4083 | // Return the number of context slots for code if a context is allocated. This |
| 4084 | // number consists of three parts: |
| 4085 | // 1. Size of fixed header for every context: Context::MIN_CONTEXT_SLOTS |
| 4086 | // 2. One context slot per context allocated local. |
| 4087 | // 3. One context slot for the function name if it is context allocated. |
| 4088 | // Parameters allocated in the context count as context allocated locals. If |
| 4089 | // no contexts are allocated for this scope ContextLength returns 0. |
| 4090 | int ContextLength(); |
| 4091 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4092 | // Does this scope declare a "this" binding? |
| 4093 | bool HasReceiver(); |
| 4094 | |
| 4095 | // Does this scope declare a "this" binding, and the "this" binding is stack- |
| 4096 | // or context-allocated? |
| 4097 | bool HasAllocatedReceiver(); |
| 4098 | |
| 4099 | // Does this scope declare a "new.target" binding? |
| 4100 | bool HasNewTarget(); |
| 4101 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4102 | // Is this scope the scope of a named function expression? |
| 4103 | bool HasFunctionName(); |
| 4104 | |
| 4105 | // Return if this has context allocated locals. |
| 4106 | bool HasHeapAllocatedLocals(); |
| 4107 | |
| 4108 | // Return if contexts are allocated for this scope. |
| 4109 | bool HasContext(); |
| 4110 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4111 | // Return if this is a function scope with "use asm". |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4112 | inline bool IsAsmModule(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4113 | |
| 4114 | // Return if this is a nested function within an asm module scope. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4115 | inline bool IsAsmFunction(); |
| 4116 | |
| 4117 | inline bool HasSimpleParameters(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4118 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4119 | // Return the function_name if present. |
| 4120 | String* FunctionName(); |
| 4121 | |
| 4122 | // Return the name of the given parameter. |
| 4123 | String* ParameterName(int var); |
| 4124 | |
| 4125 | // Return the name of the given local. |
| 4126 | String* LocalName(int var); |
| 4127 | |
| 4128 | // Return the name of the given stack local. |
| 4129 | String* StackLocalName(int var); |
| 4130 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4131 | // Return the name of the given stack local. |
| 4132 | int StackLocalIndex(int var); |
| 4133 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4134 | // Return the name of the given context local. |
| 4135 | String* ContextLocalName(int var); |
| 4136 | |
| 4137 | // Return the mode of the given context local. |
| 4138 | VariableMode ContextLocalMode(int var); |
| 4139 | |
| 4140 | // Return the initialization flag of the given context local. |
| 4141 | InitializationFlag ContextLocalInitFlag(int var); |
| 4142 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4143 | // Return the initialization flag of the given context local. |
| 4144 | MaybeAssignedFlag ContextLocalMaybeAssignedFlag(int var); |
| 4145 | |
| 4146 | // Return true if this local was introduced by the compiler, and should not be |
| 4147 | // exposed to the user in a debugger. |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 4148 | static bool VariableIsSynthetic(String* name); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4149 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4150 | // Lookup support for serialized scope info. Returns the |
| 4151 | // the stack slot index for a given slot name if the slot is |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4152 | // present; otherwise returns a value < 0. The name must be an internalized |
| 4153 | // string. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4154 | int StackSlotIndex(String* name); |
| 4155 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4156 | // Lookup support for serialized scope info. Returns the local context slot |
| 4157 | // index for a given slot name if the slot is present; otherwise |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4158 | // returns a value < 0. The name must be an internalized string. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4159 | // If the slot is present and mode != NULL, sets *mode to the corresponding |
| 4160 | // mode for that variable. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4161 | static int ContextSlotIndex(Handle<ScopeInfo> scope_info, Handle<String> name, |
| 4162 | VariableMode* mode, InitializationFlag* init_flag, |
| 4163 | MaybeAssignedFlag* maybe_assigned_flag); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4164 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4165 | // Similar to ContextSlotIndex() but this method searches only among |
| 4166 | // global slots of the serialized scope info. Returns the context slot index |
| 4167 | // for a given slot name if the slot is present; otherwise returns a |
| 4168 | // value < 0. The name must be an internalized string. If the slot is present |
| 4169 | // and mode != NULL, sets *mode to the corresponding mode for that variable. |
| 4170 | static int ContextGlobalSlotIndex(Handle<ScopeInfo> scope_info, |
| 4171 | Handle<String> name, VariableMode* mode, |
| 4172 | InitializationFlag* init_flag, |
| 4173 | MaybeAssignedFlag* maybe_assigned_flag); |
| 4174 | |
| 4175 | // Lookup the name of a certain context slot by its index. |
| 4176 | String* ContextSlotName(int slot_index); |
| 4177 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4178 | // Lookup support for serialized scope info. Returns the |
| 4179 | // parameter index for a given parameter name if the parameter is present; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4180 | // otherwise returns a value < 0. The name must be an internalized string. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4181 | int ParameterIndex(String* name); |
| 4182 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4183 | // Lookup support for serialized scope info. Returns the function context |
| 4184 | // slot index if the function name is present and context-allocated (named |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4185 | // function expressions, only), otherwise returns a value < 0. The name |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4186 | // must be an internalized string. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4187 | int FunctionContextSlotIndex(String* name, VariableMode* mode); |
| 4188 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4189 | // Lookup support for serialized scope info. Returns the receiver context |
| 4190 | // slot index if scope has a "this" binding, and the binding is |
| 4191 | // context-allocated. Otherwise returns a value < 0. |
| 4192 | int ReceiverContextSlotIndex(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4193 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4194 | FunctionKind function_kind(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4195 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4196 | static Handle<ScopeInfo> Create(Isolate* isolate, Zone* zone, Scope* scope); |
| 4197 | static Handle<ScopeInfo> CreateGlobalThisBinding(Isolate* isolate); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4198 | |
| 4199 | // Serializes empty scope info. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4200 | static ScopeInfo* Empty(Isolate* isolate); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4201 | |
| 4202 | #ifdef DEBUG |
| 4203 | void Print(); |
| 4204 | #endif |
| 4205 | |
| 4206 | // The layout of the static part of a ScopeInfo is as follows. Each entry is |
| 4207 | // numeric and occupies one array slot. |
| 4208 | // 1. A set of properties of the scope |
| 4209 | // 2. The number of parameters. This only applies to function scopes. For |
| 4210 | // non-function scopes this is 0. |
| 4211 | // 3. The number of non-parameter variables allocated on the stack. |
| 4212 | // 4. The number of non-parameter and parameter variables allocated in the |
| 4213 | // context. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4214 | #define FOR_EACH_SCOPE_INFO_NUMERIC_FIELD(V) \ |
| 4215 | V(Flags) \ |
| 4216 | V(ParameterCount) \ |
| 4217 | V(StackLocalCount) \ |
| 4218 | V(ContextLocalCount) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4219 | V(ContextGlobalCount) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4220 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4221 | #define FIELD_ACCESSORS(name) \ |
| 4222 | inline void Set##name(int value); \ |
| 4223 | inline int name(); |
| 4224 | FOR_EACH_SCOPE_INFO_NUMERIC_FIELD(FIELD_ACCESSORS) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4225 | #undef FIELD_ACCESSORS |
| 4226 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4227 | enum { |
| 4228 | #define DECL_INDEX(name) k##name, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4229 | FOR_EACH_SCOPE_INFO_NUMERIC_FIELD(DECL_INDEX) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4230 | #undef DECL_INDEX |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4231 | kVariablePartIndex |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4232 | }; |
| 4233 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4234 | private: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4235 | // The layout of the variable part of a ScopeInfo is as follows: |
| 4236 | // 1. ParameterEntries: |
| 4237 | // This part stores the names of the parameters for function scopes. One |
| 4238 | // slot is used per parameter, so in total this part occupies |
| 4239 | // ParameterCount() slots in the array. For other scopes than function |
| 4240 | // scopes ParameterCount() is 0. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4241 | // 2. StackLocalFirstSlot: |
| 4242 | // Index of a first stack slot for stack local. Stack locals belonging to |
| 4243 | // this scope are located on a stack at slots starting from this index. |
| 4244 | // 3. StackLocalEntries: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4245 | // Contains the names of local variables that are allocated on the stack, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4246 | // in increasing order of the stack slot index. First local variable has |
| 4247 | // a stack slot index defined in StackLocalFirstSlot (point 2 above). |
| 4248 | // One slot is used per stack local, so in total this part occupies |
| 4249 | // StackLocalCount() slots in the array. |
| 4250 | // 4. ContextLocalNameEntries: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4251 | // Contains the names of local variables and parameters that are allocated |
| 4252 | // in the context. They are stored in increasing order of the context slot |
| 4253 | // index starting with Context::MIN_CONTEXT_SLOTS. One slot is used per |
| 4254 | // context local, so in total this part occupies ContextLocalCount() slots |
| 4255 | // in the array. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4256 | // 5. ContextLocalInfoEntries: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4257 | // Contains the variable modes and initialization flags corresponding to |
| 4258 | // the context locals in ContextLocalNameEntries. One slot is used per |
| 4259 | // context local, so in total this part occupies ContextLocalCount() |
| 4260 | // slots in the array. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4261 | // 6. RecieverEntryIndex: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4262 | // If the scope binds a "this" value, one slot is reserved to hold the |
| 4263 | // context or stack slot index for the variable. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4264 | // 7. FunctionNameEntryIndex: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4265 | // If the scope belongs to a named function expression this part contains |
| 4266 | // information about the function variable. It always occupies two array |
| 4267 | // slots: a. The name of the function variable. |
| 4268 | // b. The context or stack slot index for the variable. |
| 4269 | int ParameterEntriesIndex(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4270 | int StackLocalFirstSlotIndex(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4271 | int StackLocalEntriesIndex(); |
| 4272 | int ContextLocalNameEntriesIndex(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4273 | int ContextGlobalNameEntriesIndex(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4274 | int ContextLocalInfoEntriesIndex(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4275 | int ContextGlobalInfoEntriesIndex(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4276 | int ReceiverEntryIndex(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4277 | int FunctionNameEntryIndex(); |
| 4278 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4279 | int Lookup(Handle<String> name, int start, int end, VariableMode* mode, |
| 4280 | VariableLocation* location, InitializationFlag* init_flag, |
| 4281 | MaybeAssignedFlag* maybe_assigned_flag); |
| 4282 | |
| 4283 | // Used for the function name variable for named function expressions, and for |
| 4284 | // the receiver. |
| 4285 | enum VariableAllocationInfo { NONE, STACK, CONTEXT, UNUSED }; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4286 | |
| 4287 | // Properties of scopes. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 4288 | class ScopeTypeField : public BitField<ScopeType, 0, 4> {}; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4289 | class CallsEvalField : public BitField<bool, ScopeTypeField::kNext, 1> {}; |
| 4290 | STATIC_ASSERT(LANGUAGE_END == 3); |
| 4291 | class LanguageModeField |
| 4292 | : public BitField<LanguageMode, CallsEvalField::kNext, 2> {}; |
| 4293 | class DeclarationScopeField |
| 4294 | : public BitField<bool, LanguageModeField::kNext, 1> {}; |
| 4295 | class ReceiverVariableField |
| 4296 | : public BitField<VariableAllocationInfo, DeclarationScopeField::kNext, |
| 4297 | 2> {}; |
| 4298 | class HasNewTargetField |
| 4299 | : public BitField<bool, ReceiverVariableField::kNext, 1> {}; |
| 4300 | class FunctionVariableField |
| 4301 | : public BitField<VariableAllocationInfo, HasNewTargetField::kNext, 2> {}; |
| 4302 | class FunctionVariableMode |
| 4303 | : public BitField<VariableMode, FunctionVariableField::kNext, 3> {}; |
| 4304 | class AsmModuleField : public BitField<bool, FunctionVariableMode::kNext, 1> { |
| 4305 | }; |
| 4306 | class AsmFunctionField : public BitField<bool, AsmModuleField::kNext, 1> {}; |
| 4307 | class HasSimpleParametersField |
| 4308 | : public BitField<bool, AsmFunctionField::kNext, 1> {}; |
| 4309 | class FunctionKindField |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 4310 | : public BitField<FunctionKind, HasSimpleParametersField::kNext, 9> {}; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4311 | |
| 4312 | // BitFields representing the encoded information for context locals in the |
| 4313 | // ContextLocalInfoEntries part. |
| 4314 | class ContextLocalMode: public BitField<VariableMode, 0, 3> {}; |
| 4315 | class ContextLocalInitFlag: public BitField<InitializationFlag, 3, 1> {}; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4316 | class ContextLocalMaybeAssignedFlag |
| 4317 | : public BitField<MaybeAssignedFlag, 4, 1> {}; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4318 | |
| 4319 | friend class ScopeIterator; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4320 | }; |
| 4321 | |
| 4322 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4323 | // The cache for maps used by normalized (dictionary mode) objects. |
| 4324 | // Such maps do not have property descriptors, so a typical program |
| 4325 | // needs very limited number of distinct normalized maps. |
| 4326 | class NormalizedMapCache: public FixedArray { |
| 4327 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4328 | static Handle<NormalizedMapCache> New(Isolate* isolate); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4329 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4330 | MUST_USE_RESULT MaybeHandle<Map> Get(Handle<Map> fast_map, |
| 4331 | PropertyNormalizationMode mode); |
| 4332 | void Set(Handle<Map> fast_map, Handle<Map> normalized_map); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4333 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4334 | void Clear(); |
| 4335 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4336 | DECLARE_CAST(NormalizedMapCache) |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4337 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4338 | static inline bool IsNormalizedMapCache(const HeapObject* obj); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4339 | |
| 4340 | DECLARE_VERIFIER(NormalizedMapCache) |
| 4341 | private: |
| 4342 | static const int kEntries = 64; |
| 4343 | |
| 4344 | static inline int GetIndex(Handle<Map> map); |
| 4345 | |
| 4346 | // The following declarations hide base class methods. |
| 4347 | Object* get(int index); |
| 4348 | void set(int index, Object* value); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4349 | }; |
| 4350 | |
| 4351 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4352 | // ByteArray represents fixed sized byte arrays. Used for the relocation info |
| 4353 | // that is attached to code objects. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 4354 | class ByteArray: public FixedArrayBase { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4355 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4356 | inline int Size(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4357 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4358 | // Setter and getter. |
| 4359 | inline byte get(int index); |
| 4360 | inline void set(int index, byte value); |
| 4361 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 4362 | // Copy in / copy out whole byte slices. |
| 4363 | inline void copy_out(int index, byte* buffer, int length); |
| 4364 | inline void copy_in(int index, const byte* buffer, int length); |
| 4365 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4366 | // Treat contents as an int array. |
| 4367 | inline int get_int(int index); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 4368 | inline void set_int(int index, int value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4369 | |
| 4370 | static int SizeFor(int length) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4371 | return OBJECT_POINTER_ALIGN(kHeaderSize + length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4372 | } |
| 4373 | // We use byte arrays for free blocks in the heap. Given a desired size in |
| 4374 | // bytes that is a multiple of the word size and big enough to hold a byte |
| 4375 | // array, this function returns the number of elements a byte array should |
| 4376 | // have. |
| 4377 | static int LengthFor(int size_in_bytes) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4378 | DCHECK(IsAligned(size_in_bytes, kPointerSize)); |
| 4379 | DCHECK(size_in_bytes >= kHeaderSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4380 | return size_in_bytes - kHeaderSize; |
| 4381 | } |
| 4382 | |
| 4383 | // Returns data start address. |
| 4384 | inline Address GetDataStartAddress(); |
| 4385 | |
| 4386 | // Returns a pointer to the ByteArray object for a given data start address. |
| 4387 | static inline ByteArray* FromDataStartAddress(Address address); |
| 4388 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4389 | DECLARE_CAST(ByteArray) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4390 | |
| 4391 | // Dispatched behavior. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4392 | inline int ByteArraySize(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4393 | DECLARE_PRINTER(ByteArray) |
| 4394 | DECLARE_VERIFIER(ByteArray) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4395 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4396 | // Layout description. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4397 | static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4398 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4399 | // Maximal memory consumption for a single ByteArray. |
| 4400 | static const int kMaxSize = 512 * MB; |
| 4401 | // Maximal length of a single ByteArray. |
| 4402 | static const int kMaxLength = kMaxSize - kHeaderSize; |
| 4403 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4404 | private: |
| 4405 | DISALLOW_IMPLICIT_CONSTRUCTORS(ByteArray); |
| 4406 | }; |
| 4407 | |
| 4408 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4409 | // BytecodeArray represents a sequence of interpreter bytecodes. |
| 4410 | class BytecodeArray : public FixedArrayBase { |
| 4411 | public: |
| 4412 | static int SizeFor(int length) { |
| 4413 | return OBJECT_POINTER_ALIGN(kHeaderSize + length); |
| 4414 | } |
| 4415 | |
| 4416 | // Setter and getter |
| 4417 | inline byte get(int index); |
| 4418 | inline void set(int index, byte value); |
| 4419 | |
| 4420 | // Returns data start address. |
| 4421 | inline Address GetFirstBytecodeAddress(); |
| 4422 | |
| 4423 | // Accessors for frame size. |
| 4424 | inline int frame_size() const; |
| 4425 | inline void set_frame_size(int frame_size); |
| 4426 | |
| 4427 | // Accessor for register count (derived from frame_size). |
| 4428 | inline int register_count() const; |
| 4429 | |
| 4430 | // Accessors for parameter count (including implicit 'this' receiver). |
| 4431 | inline int parameter_count() const; |
| 4432 | inline void set_parameter_count(int number_of_parameters); |
| 4433 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4434 | // Accessors for profiling count. |
| 4435 | inline int interrupt_budget() const; |
| 4436 | inline void set_interrupt_budget(int interrupt_budget); |
| 4437 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4438 | // Accessors for the constant pool. |
| 4439 | DECL_ACCESSORS(constant_pool, FixedArray) |
| 4440 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4441 | // Accessors for handler table containing offsets of exception handlers. |
| 4442 | DECL_ACCESSORS(handler_table, FixedArray) |
| 4443 | |
| 4444 | // Accessors for source position table containing mappings between byte code |
| 4445 | // offset and source position. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 4446 | DECL_ACCESSORS(source_position_table, ByteArray) |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4447 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4448 | DECLARE_CAST(BytecodeArray) |
| 4449 | |
| 4450 | // Dispatched behavior. |
| 4451 | inline int BytecodeArraySize(); |
| 4452 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4453 | inline int instruction_size(); |
| 4454 | |
| 4455 | int SourcePosition(int offset); |
| 4456 | int SourceStatementPosition(int offset); |
| 4457 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4458 | DECLARE_PRINTER(BytecodeArray) |
| 4459 | DECLARE_VERIFIER(BytecodeArray) |
| 4460 | |
| 4461 | void Disassemble(std::ostream& os); |
| 4462 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4463 | void CopyBytecodesTo(BytecodeArray* to); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4464 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4465 | // Layout description. |
| 4466 | static const int kConstantPoolOffset = FixedArrayBase::kHeaderSize; |
| 4467 | static const int kHandlerTableOffset = kConstantPoolOffset + kPointerSize; |
| 4468 | static const int kSourcePositionTableOffset = |
| 4469 | kHandlerTableOffset + kPointerSize; |
| 4470 | static const int kFrameSizeOffset = kSourcePositionTableOffset + kPointerSize; |
| 4471 | static const int kParameterSizeOffset = kFrameSizeOffset + kIntSize; |
| 4472 | static const int kInterruptBudgetOffset = kParameterSizeOffset + kIntSize; |
| 4473 | static const int kHeaderSize = kInterruptBudgetOffset + kIntSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4474 | |
| 4475 | // Maximal memory consumption for a single BytecodeArray. |
| 4476 | static const int kMaxSize = 512 * MB; |
| 4477 | // Maximal length of a single BytecodeArray. |
| 4478 | static const int kMaxLength = kMaxSize - kHeaderSize; |
| 4479 | |
| 4480 | class BodyDescriptor; |
| 4481 | |
| 4482 | private: |
| 4483 | DISALLOW_IMPLICIT_CONSTRUCTORS(BytecodeArray); |
| 4484 | }; |
| 4485 | |
| 4486 | |
| 4487 | // FreeSpace are fixed-size free memory blocks used by the heap and GC. |
| 4488 | // They look like heap objects (are heap object tagged and have a map) so that |
| 4489 | // the heap remains iterable. They have a size and a next pointer. |
| 4490 | // The next pointer is the raw address of the next FreeSpace object (or NULL) |
| 4491 | // in the free list. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4492 | class FreeSpace: public HeapObject { |
| 4493 | public: |
| 4494 | // [size]: size of the free space including the header. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4495 | inline int size() const; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4496 | inline void set_size(int value); |
| 4497 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4498 | inline int nobarrier_size() const; |
| 4499 | inline void nobarrier_set_size(int value); |
| 4500 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4501 | inline int Size(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4502 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4503 | // Accessors for the next field. |
| 4504 | inline FreeSpace* next(); |
| 4505 | inline void set_next(FreeSpace* next); |
| 4506 | |
| 4507 | inline static FreeSpace* cast(HeapObject* obj); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4508 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4509 | // Dispatched behavior. |
| 4510 | DECLARE_PRINTER(FreeSpace) |
| 4511 | DECLARE_VERIFIER(FreeSpace) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4512 | |
| 4513 | // Layout description. |
| 4514 | // Size is smi tagged when it is stored. |
| 4515 | static const int kSizeOffset = HeapObject::kHeaderSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4516 | static const int kNextOffset = POINTER_SIZE_ALIGN(kSizeOffset + kPointerSize); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4517 | |
| 4518 | private: |
| 4519 | DISALLOW_IMPLICIT_CONSTRUCTORS(FreeSpace); |
| 4520 | }; |
| 4521 | |
| 4522 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4523 | // V has parameters (Type, type, TYPE, C type, element_size) |
| 4524 | #define TYPED_ARRAYS(V) \ |
| 4525 | V(Uint8, uint8, UINT8, uint8_t, 1) \ |
| 4526 | V(Int8, int8, INT8, int8_t, 1) \ |
| 4527 | V(Uint16, uint16, UINT16, uint16_t, 2) \ |
| 4528 | V(Int16, int16, INT16, int16_t, 2) \ |
| 4529 | V(Uint32, uint32, UINT32, uint32_t, 4) \ |
| 4530 | V(Int32, int32, INT32, int32_t, 4) \ |
| 4531 | V(Float32, float32, FLOAT32, float, 4) \ |
| 4532 | V(Float64, float64, FLOAT64, double, 8) \ |
| 4533 | V(Uint8Clamped, uint8_clamped, UINT8_CLAMPED, uint8_t, 1) |
| 4534 | |
| 4535 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4536 | class FixedTypedArrayBase: public FixedArrayBase { |
| 4537 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4538 | // [base_pointer]: Either points to the FixedTypedArrayBase itself or nullptr. |
| 4539 | DECL_ACCESSORS(base_pointer, Object) |
| 4540 | |
| 4541 | // [external_pointer]: Contains the offset between base_pointer and the start |
| 4542 | // of the data. If the base_pointer is a nullptr, the external_pointer |
| 4543 | // therefore points to the actual backing store. |
| 4544 | DECL_ACCESSORS(external_pointer, void) |
| 4545 | |
| 4546 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4547 | DECLARE_CAST(FixedTypedArrayBase) |
| 4548 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4549 | static const int kBasePointerOffset = FixedArrayBase::kHeaderSize; |
| 4550 | static const int kExternalPointerOffset = kBasePointerOffset + kPointerSize; |
| 4551 | static const int kHeaderSize = |
| 4552 | DOUBLE_POINTER_ALIGN(kExternalPointerOffset + kPointerSize); |
| 4553 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4554 | static const int kDataOffset = kHeaderSize; |
| 4555 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4556 | class BodyDescriptor; |
| 4557 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4558 | inline int size(); |
| 4559 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4560 | static inline int TypedArraySize(InstanceType type, int length); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4561 | inline int TypedArraySize(InstanceType type); |
| 4562 | |
| 4563 | // Use with care: returns raw pointer into heap. |
| 4564 | inline void* DataPtr(); |
| 4565 | |
| 4566 | inline int DataSize(); |
| 4567 | |
| 4568 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4569 | static inline int ElementSize(InstanceType type); |
| 4570 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4571 | inline int DataSize(InstanceType type); |
| 4572 | |
| 4573 | DISALLOW_IMPLICIT_CONSTRUCTORS(FixedTypedArrayBase); |
| 4574 | }; |
| 4575 | |
| 4576 | |
| 4577 | template <class Traits> |
| 4578 | class FixedTypedArray: public FixedTypedArrayBase { |
| 4579 | public: |
| 4580 | typedef typename Traits::ElementType ElementType; |
| 4581 | static const InstanceType kInstanceType = Traits::kInstanceType; |
| 4582 | |
| 4583 | DECLARE_CAST(FixedTypedArray<Traits>) |
| 4584 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4585 | inline ElementType get_scalar(int index); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4586 | static inline Handle<Object> get(FixedTypedArray* array, int index); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4587 | inline void set(int index, ElementType value); |
| 4588 | |
| 4589 | static inline ElementType from_int(int value); |
| 4590 | static inline ElementType from_double(double value); |
| 4591 | |
| 4592 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 4593 | // and undefined. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4594 | inline void SetValue(uint32_t index, Object* value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4595 | |
| 4596 | DECLARE_PRINTER(FixedTypedArray) |
| 4597 | DECLARE_VERIFIER(FixedTypedArray) |
| 4598 | |
| 4599 | private: |
| 4600 | DISALLOW_IMPLICIT_CONSTRUCTORS(FixedTypedArray); |
| 4601 | }; |
| 4602 | |
| 4603 | #define FIXED_TYPED_ARRAY_TRAITS(Type, type, TYPE, elementType, size) \ |
| 4604 | class Type##ArrayTraits { \ |
| 4605 | public: /* NOLINT */ \ |
| 4606 | typedef elementType ElementType; \ |
| 4607 | static const InstanceType kInstanceType = FIXED_##TYPE##_ARRAY_TYPE; \ |
| 4608 | static const char* Designator() { return #type " array"; } \ |
| 4609 | static inline Handle<Object> ToHandle(Isolate* isolate, \ |
| 4610 | elementType scalar); \ |
| 4611 | static inline elementType defaultValue(); \ |
| 4612 | }; \ |
| 4613 | \ |
| 4614 | typedef FixedTypedArray<Type##ArrayTraits> Fixed##Type##Array; |
| 4615 | |
| 4616 | TYPED_ARRAYS(FIXED_TYPED_ARRAY_TRAITS) |
| 4617 | |
| 4618 | #undef FIXED_TYPED_ARRAY_TRAITS |
| 4619 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 4620 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4621 | // DeoptimizationInputData is a fixed array used to hold the deoptimization |
| 4622 | // data for code generated by the Hydrogen/Lithium compiler. It also |
| 4623 | // contains information about functions that were inlined. If N different |
| 4624 | // functions were inlined then first N elements of the literal array will |
| 4625 | // contain these functions. |
| 4626 | // |
| 4627 | // It can be empty. |
| 4628 | class DeoptimizationInputData: public FixedArray { |
| 4629 | public: |
| 4630 | // Layout description. Indices in the array. |
| 4631 | static const int kTranslationByteArrayIndex = 0; |
| 4632 | static const int kInlinedFunctionCountIndex = 1; |
| 4633 | static const int kLiteralArrayIndex = 2; |
| 4634 | static const int kOsrAstIdIndex = 3; |
| 4635 | static const int kOsrPcOffsetIndex = 4; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4636 | static const int kOptimizationIdIndex = 5; |
| 4637 | static const int kSharedFunctionInfoIndex = 6; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4638 | static const int kWeakCellCacheIndex = 7; |
| 4639 | static const int kFirstDeoptEntryIndex = 8; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4640 | |
| 4641 | // Offsets of deopt entry elements relative to the start of the entry. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4642 | static const int kAstIdRawOffset = 0; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4643 | static const int kTranslationIndexOffset = 1; |
| 4644 | static const int kArgumentsStackHeightOffset = 2; |
Ben Murdoch | 2b4ba11 | 2012-01-20 14:57:15 +0000 | [diff] [blame] | 4645 | static const int kPcOffset = 3; |
| 4646 | static const int kDeoptEntrySize = 4; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4647 | |
| 4648 | // Simple element accessors. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4649 | #define DECLARE_ELEMENT_ACCESSORS(name, type) \ |
| 4650 | inline type* name(); \ |
| 4651 | inline void Set##name(type* value); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4652 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4653 | DECLARE_ELEMENT_ACCESSORS(TranslationByteArray, ByteArray) |
| 4654 | DECLARE_ELEMENT_ACCESSORS(InlinedFunctionCount, Smi) |
| 4655 | DECLARE_ELEMENT_ACCESSORS(LiteralArray, FixedArray) |
| 4656 | DECLARE_ELEMENT_ACCESSORS(OsrAstId, Smi) |
| 4657 | DECLARE_ELEMENT_ACCESSORS(OsrPcOffset, Smi) |
| 4658 | DECLARE_ELEMENT_ACCESSORS(OptimizationId, Smi) |
| 4659 | DECLARE_ELEMENT_ACCESSORS(SharedFunctionInfo, Object) |
| 4660 | DECLARE_ELEMENT_ACCESSORS(WeakCellCache, Object) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4661 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4662 | #undef DECLARE_ELEMENT_ACCESSORS |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4663 | |
| 4664 | // Accessors for elements of the ith deoptimization entry. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4665 | #define DECLARE_ENTRY_ACCESSORS(name, type) \ |
| 4666 | inline type* name(int i); \ |
| 4667 | inline void Set##name(int i, type* value); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4668 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4669 | DECLARE_ENTRY_ACCESSORS(AstIdRaw, Smi) |
| 4670 | DECLARE_ENTRY_ACCESSORS(TranslationIndex, Smi) |
| 4671 | DECLARE_ENTRY_ACCESSORS(ArgumentsStackHeight, Smi) |
| 4672 | DECLARE_ENTRY_ACCESSORS(Pc, Smi) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4673 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4674 | #undef DECLARE_ENTRY_ACCESSORS |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4675 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4676 | inline BailoutId AstId(int i); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4677 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4678 | inline void SetAstId(int i, BailoutId value); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4679 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4680 | inline int DeoptCount(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4681 | |
| 4682 | // Allocates a DeoptimizationInputData. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4683 | static Handle<DeoptimizationInputData> New(Isolate* isolate, |
| 4684 | int deopt_entry_count, |
| 4685 | PretenureFlag pretenure); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4686 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4687 | DECLARE_CAST(DeoptimizationInputData) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4688 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4689 | #ifdef ENABLE_DISASSEMBLER |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 4690 | void DeoptimizationInputDataPrint(std::ostream& os); // NOLINT |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4691 | #endif |
| 4692 | |
| 4693 | private: |
| 4694 | static int IndexForEntry(int i) { |
| 4695 | return kFirstDeoptEntryIndex + (i * kDeoptEntrySize); |
| 4696 | } |
| 4697 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4698 | |
| 4699 | static int LengthFor(int entry_count) { return IndexForEntry(entry_count); } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4700 | }; |
| 4701 | |
| 4702 | |
| 4703 | // DeoptimizationOutputData is a fixed array used to hold the deoptimization |
| 4704 | // data for code generated by the full compiler. |
| 4705 | // The format of the these objects is |
| 4706 | // [i * 2]: Ast ID for ith deoptimization. |
| 4707 | // [i * 2 + 1]: PC and state of ith deoptimization |
| 4708 | class DeoptimizationOutputData: public FixedArray { |
| 4709 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4710 | inline int DeoptPoints(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4711 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4712 | inline BailoutId AstId(int index); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4713 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4714 | inline void SetAstId(int index, BailoutId id); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4715 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4716 | inline Smi* PcAndState(int index); |
| 4717 | inline void SetPcAndState(int index, Smi* offset); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4718 | |
| 4719 | static int LengthOfFixedArray(int deopt_points) { |
| 4720 | return deopt_points * 2; |
| 4721 | } |
| 4722 | |
| 4723 | // Allocates a DeoptimizationOutputData. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4724 | static Handle<DeoptimizationOutputData> New(Isolate* isolate, |
| 4725 | int number_of_deopt_points, |
| 4726 | PretenureFlag pretenure); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4727 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4728 | DECLARE_CAST(DeoptimizationOutputData) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4729 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4730 | #ifdef ENABLE_DISASSEMBLER |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 4731 | void DeoptimizationOutputDataPrint(std::ostream& os); // NOLINT |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4732 | #endif |
| 4733 | }; |
| 4734 | |
| 4735 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4736 | // A literals array contains the literals for a JSFunction. It also holds |
| 4737 | // the type feedback vector. |
| 4738 | class LiteralsArray : public FixedArray { |
| 4739 | public: |
| 4740 | static const int kVectorIndex = 0; |
| 4741 | static const int kFirstLiteralIndex = 1; |
| 4742 | static const int kOffsetToFirstLiteral = |
| 4743 | FixedArray::kHeaderSize + kPointerSize; |
| 4744 | |
| 4745 | static int OffsetOfLiteralAt(int index) { |
| 4746 | return SizeFor(index + kFirstLiteralIndex); |
| 4747 | } |
| 4748 | |
| 4749 | inline TypeFeedbackVector* feedback_vector() const; |
| 4750 | inline void set_feedback_vector(TypeFeedbackVector* vector); |
| 4751 | inline Object* literal(int literal_index) const; |
| 4752 | inline void set_literal(int literal_index, Object* literal); |
| 4753 | inline int literals_count() const; |
| 4754 | |
| 4755 | static Handle<LiteralsArray> New(Isolate* isolate, |
| 4756 | Handle<TypeFeedbackVector> vector, |
| 4757 | int number_of_literals, |
| 4758 | PretenureFlag pretenure); |
| 4759 | |
| 4760 | DECLARE_CAST(LiteralsArray) |
| 4761 | |
| 4762 | private: |
| 4763 | inline Object* get(int index) const; |
| 4764 | inline void set(int index, Object* value); |
| 4765 | inline void set(int index, Smi* value); |
| 4766 | inline void set(int index, Object* value, WriteBarrierMode mode); |
| 4767 | }; |
| 4768 | |
| 4769 | |
| 4770 | // HandlerTable is a fixed array containing entries for exception handlers in |
| 4771 | // the code object it is associated with. The tables comes in two flavors: |
| 4772 | // 1) Based on ranges: Used for unoptimized code. Contains one entry per |
| 4773 | // exception handler and a range representing the try-block covered by that |
| 4774 | // handler. Layout looks as follows: |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4775 | // [ range-start , range-end , handler-offset , handler-data ] |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4776 | // 2) Based on return addresses: Used for turbofanned code. Contains one entry |
| 4777 | // per call-site that could throw an exception. Layout looks as follows: |
| 4778 | // [ return-address-offset , handler-offset ] |
| 4779 | class HandlerTable : public FixedArray { |
| 4780 | public: |
| 4781 | // Conservative prediction whether a given handler will locally catch an |
| 4782 | // exception or cause a re-throw to outside the code boundary. Since this is |
| 4783 | // undecidable it is merely an approximation (e.g. useful for debugger). |
| 4784 | enum CatchPrediction { UNCAUGHT, CAUGHT }; |
| 4785 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4786 | // Getters for handler table based on ranges. |
| 4787 | inline int GetRangeStart(int index) const; |
| 4788 | inline int GetRangeEnd(int index) const; |
| 4789 | inline int GetRangeHandler(int index) const; |
| 4790 | inline int GetRangeData(int index) const; |
| 4791 | |
| 4792 | // Setters for handler table based on ranges. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4793 | inline void SetRangeStart(int index, int value); |
| 4794 | inline void SetRangeEnd(int index, int value); |
| 4795 | inline void SetRangeHandler(int index, int offset, CatchPrediction pred); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4796 | inline void SetRangeData(int index, int value); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4797 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4798 | // Setters for handler table based on return addresses. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4799 | inline void SetReturnOffset(int index, int value); |
| 4800 | inline void SetReturnHandler(int index, int offset, CatchPrediction pred); |
| 4801 | |
| 4802 | // Lookup handler in a table based on ranges. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4803 | int LookupRange(int pc_offset, int* data, CatchPrediction* prediction); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4804 | |
| 4805 | // Lookup handler in a table based on return addresses. |
| 4806 | int LookupReturn(int pc_offset, CatchPrediction* prediction); |
| 4807 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4808 | // Returns the conservative catch predication. |
| 4809 | inline CatchPrediction GetRangePrediction(int index) const; |
| 4810 | |
| 4811 | // Returns the number of entries in the table. |
| 4812 | inline int NumberOfRangeEntries() const; |
| 4813 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4814 | // Returns the required length of the underlying fixed array. |
| 4815 | static int LengthForRange(int entries) { return entries * kRangeEntrySize; } |
| 4816 | static int LengthForReturn(int entries) { return entries * kReturnEntrySize; } |
| 4817 | |
| 4818 | DECLARE_CAST(HandlerTable) |
| 4819 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4820 | #ifdef ENABLE_DISASSEMBLER |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4821 | void HandlerTableRangePrint(std::ostream& os); // NOLINT |
| 4822 | void HandlerTableReturnPrint(std::ostream& os); // NOLINT |
| 4823 | #endif |
| 4824 | |
| 4825 | private: |
| 4826 | // Layout description for handler table based on ranges. |
| 4827 | static const int kRangeStartIndex = 0; |
| 4828 | static const int kRangeEndIndex = 1; |
| 4829 | static const int kRangeHandlerIndex = 2; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4830 | static const int kRangeDataIndex = 3; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4831 | static const int kRangeEntrySize = 4; |
| 4832 | |
| 4833 | // Layout description for handler table based on return addresses. |
| 4834 | static const int kReturnOffsetIndex = 0; |
| 4835 | static const int kReturnHandlerIndex = 1; |
| 4836 | static const int kReturnEntrySize = 2; |
| 4837 | |
| 4838 | // Encoding of the {handler} field. |
| 4839 | class HandlerPredictionField : public BitField<CatchPrediction, 0, 1> {}; |
| 4840 | class HandlerOffsetField : public BitField<int, 1, 30> {}; |
| 4841 | }; |
| 4842 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4843 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4844 | // Code describes objects with on-the-fly generated machine code. |
| 4845 | class Code: public HeapObject { |
| 4846 | public: |
| 4847 | // Opaque data type for encapsulating code flags like kind, inline |
| 4848 | // cache state, and arguments count. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4849 | typedef uint32_t Flags; |
| 4850 | |
| 4851 | #define NON_IC_KIND_LIST(V) \ |
| 4852 | V(FUNCTION) \ |
| 4853 | V(OPTIMIZED_FUNCTION) \ |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 4854 | V(BYTECODE_HANDLER) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4855 | V(STUB) \ |
| 4856 | V(HANDLER) \ |
| 4857 | V(BUILTIN) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4858 | V(REGEXP) \ |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 4859 | V(WASM_FUNCTION) \ |
| 4860 | V(WASM_TO_JS_FUNCTION) \ |
| 4861 | V(JS_TO_WASM_FUNCTION) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4862 | |
| 4863 | #define IC_KIND_LIST(V) \ |
| 4864 | V(LOAD_IC) \ |
| 4865 | V(KEYED_LOAD_IC) \ |
| 4866 | V(CALL_IC) \ |
| 4867 | V(STORE_IC) \ |
| 4868 | V(KEYED_STORE_IC) \ |
| 4869 | V(BINARY_OP_IC) \ |
| 4870 | V(COMPARE_IC) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4871 | V(TO_BOOLEAN_IC) |
| 4872 | |
| 4873 | #define CODE_KIND_LIST(V) \ |
| 4874 | NON_IC_KIND_LIST(V) \ |
| 4875 | IC_KIND_LIST(V) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4876 | |
| 4877 | enum Kind { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4878 | #define DEFINE_CODE_KIND_ENUM(name) name, |
| 4879 | CODE_KIND_LIST(DEFINE_CODE_KIND_ENUM) |
| 4880 | #undef DEFINE_CODE_KIND_ENUM |
| 4881 | NUMBER_OF_KINDS |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4882 | }; |
| 4883 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4884 | // No more than 32 kinds. The value is currently encoded in five bits in |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4885 | // Flags. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4886 | STATIC_ASSERT(NUMBER_OF_KINDS <= 32); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4887 | |
| 4888 | static const char* Kind2String(Kind kind); |
| 4889 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4890 | static const int kPrologueOffsetNotSet = -1; |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4891 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4892 | #ifdef ENABLE_DISASSEMBLER |
| 4893 | // Printing |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4894 | static const char* ICState2String(InlineCacheState state); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 4895 | static void PrintExtraICState(std::ostream& os, // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4896 | Kind kind, ExtraICState extra); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 4897 | void Disassemble(const char* name, std::ostream& os); // NOLINT |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4898 | #endif // ENABLE_DISASSEMBLER |
| 4899 | |
| 4900 | // [instruction_size]: Size of the native instructions |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4901 | inline int instruction_size() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4902 | inline void set_instruction_size(int value); |
| 4903 | |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 4904 | // [relocation_info]: Code relocation information |
| 4905 | DECL_ACCESSORS(relocation_info, ByteArray) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4906 | void InvalidateRelocation(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4907 | void InvalidateEmbeddedObjects(); |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 4908 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4909 | // [handler_table]: Fixed array containing offsets of exception handlers. |
| 4910 | DECL_ACCESSORS(handler_table, FixedArray) |
| 4911 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4912 | // [deoptimization_data]: Array containing data for deopt. |
| 4913 | DECL_ACCESSORS(deoptimization_data, FixedArray) |
| 4914 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4915 | // [raw_type_feedback_info]: This field stores various things, depending on |
| 4916 | // the kind of the code object. |
| 4917 | // FUNCTION => type feedback information. |
| 4918 | // STUB and ICs => major/minor key as Smi. |
| 4919 | DECL_ACCESSORS(raw_type_feedback_info, Object) |
| 4920 | inline Object* type_feedback_info(); |
| 4921 | inline void set_type_feedback_info( |
| 4922 | Object* value, WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| 4923 | inline uint32_t stub_key(); |
| 4924 | inline void set_stub_key(uint32_t key); |
| 4925 | |
| 4926 | // [next_code_link]: Link for lists of optimized or deoptimized code. |
| 4927 | // Note that storage for this field is overlapped with typefeedback_info. |
| 4928 | DECL_ACCESSORS(next_code_link, Object) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4929 | |
| 4930 | // [gc_metadata]: Field used to hold GC related metadata. The contents of this |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4931 | // field does not have to be traced during garbage collection since |
| 4932 | // it is only used by the garbage collector itself. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4933 | DECL_ACCESSORS(gc_metadata, Object) |
| 4934 | |
| 4935 | // [ic_age]: Inline caching age: the value of the Heap::global_ic_age |
| 4936 | // at the moment when this object was created. |
| 4937 | inline void set_ic_age(int count); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4938 | inline int ic_age() const; |
| 4939 | |
| 4940 | // [prologue_offset]: Offset of the function prologue, used for aging |
| 4941 | // FUNCTIONs and OPTIMIZED_FUNCTIONs. |
| 4942 | inline int prologue_offset() const; |
| 4943 | inline void set_prologue_offset(int offset); |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame] | 4944 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4945 | // [constant_pool offset]: Offset of the constant pool. |
| 4946 | // Valid for FLAG_enable_embedded_constant_pool only |
| 4947 | inline int constant_pool_offset() const; |
| 4948 | inline void set_constant_pool_offset(int offset); |
| 4949 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4950 | // Unchecked accessors to be used during GC. |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 4951 | inline ByteArray* unchecked_relocation_info(); |
| 4952 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4953 | inline int relocation_size(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4954 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4955 | // [flags]: Various code flags. |
| 4956 | inline Flags flags(); |
| 4957 | inline void set_flags(Flags flags); |
| 4958 | |
| 4959 | // [flags]: Access to specific code flags. |
| 4960 | inline Kind kind(); |
| 4961 | inline InlineCacheState ic_state(); // Only valid for IC stubs. |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4962 | inline ExtraICState extra_ic_state(); // Only valid for IC stubs. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4963 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4964 | // Testers for IC stub kinds. |
| 4965 | inline bool is_inline_cache_stub(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4966 | inline bool is_debug_stub(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4967 | inline bool is_handler(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4968 | inline bool is_call_stub(); |
| 4969 | inline bool is_binary_op_stub(); |
| 4970 | inline bool is_compare_ic_stub(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4971 | inline bool is_to_boolean_ic_stub(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4972 | inline bool is_optimized_code(); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 4973 | inline bool is_wasm_code(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4974 | inline bool embeds_maps_weakly(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4975 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4976 | inline bool IsCodeStubOrIC(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4977 | inline bool IsJavaScriptCode(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4978 | |
| 4979 | inline void set_raw_kind_specific_flags1(int value); |
| 4980 | inline void set_raw_kind_specific_flags2(int value); |
| 4981 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4982 | // Testers for interpreter builtins. |
| 4983 | inline bool is_interpreter_entry_trampoline(); |
| 4984 | inline bool is_interpreter_enter_bytecode_dispatch(); |
| 4985 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4986 | // [is_crankshafted]: For kind STUB or ICs, tells whether or not a code |
| 4987 | // object was generated by either the hydrogen or the TurboFan optimizing |
| 4988 | // compiler (but it may not be an optimized function). |
| 4989 | inline bool is_crankshafted(); |
| 4990 | inline bool is_hydrogen_stub(); // Crankshafted, but not a function. |
| 4991 | inline void set_is_crankshafted(bool value); |
| 4992 | |
| 4993 | // [is_turbofanned]: For kind STUB or OPTIMIZED_FUNCTION, tells whether the |
| 4994 | // code object was generated by the TurboFan optimizing compiler. |
| 4995 | inline bool is_turbofanned(); |
| 4996 | inline void set_is_turbofanned(bool value); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4997 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4998 | // [can_have_weak_objects]: For kind OPTIMIZED_FUNCTION, tells whether the |
| 4999 | // embedded objects in code should be treated weakly. |
| 5000 | inline bool can_have_weak_objects(); |
| 5001 | inline void set_can_have_weak_objects(bool value); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5002 | |
| 5003 | // [has_deoptimization_support]: For FUNCTION kind, tells if it has |
| 5004 | // deoptimization support. |
| 5005 | inline bool has_deoptimization_support(); |
| 5006 | inline void set_has_deoptimization_support(bool value); |
| 5007 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 5008 | // [has_debug_break_slots]: For FUNCTION kind, tells if it has |
| 5009 | // been compiled with debug break slots. |
| 5010 | inline bool has_debug_break_slots(); |
| 5011 | inline void set_has_debug_break_slots(bool value); |
| 5012 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5013 | // [has_reloc_info_for_serialization]: For FUNCTION kind, tells if its |
| 5014 | // reloc info includes runtime and external references to support |
| 5015 | // serialization/deserialization. |
| 5016 | inline bool has_reloc_info_for_serialization(); |
| 5017 | inline void set_has_reloc_info_for_serialization(bool value); |
| 5018 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5019 | // [allow_osr_at_loop_nesting_level]: For FUNCTION kind, tells for |
| 5020 | // how long the function has been marked for OSR and therefore which |
| 5021 | // level of loop nesting we are willing to do on-stack replacement |
| 5022 | // for. |
| 5023 | inline void set_allow_osr_at_loop_nesting_level(int level); |
| 5024 | inline int allow_osr_at_loop_nesting_level(); |
| 5025 | |
Ben Murdoch | 8f9999f | 2012-04-23 10:39:17 +0100 | [diff] [blame] | 5026 | // [profiler_ticks]: For FUNCTION kind, tells for how many profiler ticks |
| 5027 | // the code object was seen on the stack with no IC patching going on. |
| 5028 | inline int profiler_ticks(); |
| 5029 | inline void set_profiler_ticks(int ticks); |
| 5030 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5031 | // [builtin_index]: For BUILTIN kind, tells which builtin index it has. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5032 | // For builtins, tells which builtin index it has. |
| 5033 | // Note that builtins can have a code kind other than BUILTIN, which means |
| 5034 | // that for arbitrary code objects, this index value may be random garbage. |
| 5035 | // To verify in that case, compare the code object to the indexed builtin. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5036 | inline int builtin_index(); |
| 5037 | inline void set_builtin_index(int id); |
| 5038 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5039 | // [stack_slots]: For kind OPTIMIZED_FUNCTION, the number of stack slots |
| 5040 | // reserved in the code prologue. |
| 5041 | inline unsigned stack_slots(); |
| 5042 | inline void set_stack_slots(unsigned slots); |
| 5043 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5044 | // [safepoint_table_start]: For kind OPTIMIZED_FUNCTION, the offset in |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5045 | // the instruction stream where the safepoint table starts. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 5046 | inline unsigned safepoint_table_offset(); |
| 5047 | inline void set_safepoint_table_offset(unsigned offset); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5048 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5049 | // [back_edge_table_start]: For kind FUNCTION, the offset in the |
| 5050 | // instruction stream where the back edge table starts. |
| 5051 | inline unsigned back_edge_table_offset(); |
| 5052 | inline void set_back_edge_table_offset(unsigned offset); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5053 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5054 | inline bool back_edges_patched_for_osr(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5055 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 5056 | // [to_boolean_foo]: For kind TO_BOOLEAN_IC tells what state the stub is in. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5057 | inline uint16_t to_boolean_state(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5058 | |
| 5059 | // [marked_for_deoptimization]: For kind OPTIMIZED_FUNCTION tells whether |
| 5060 | // the code is going to be deoptimized because of dead embedded maps. |
| 5061 | inline bool marked_for_deoptimization(); |
| 5062 | inline void set_marked_for_deoptimization(bool flag); |
| 5063 | |
| 5064 | // [constant_pool]: The constant pool for this function. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5065 | inline Address constant_pool(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5066 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 5067 | // Get the safepoint entry for the given pc. |
| 5068 | SafepointEntry GetSafepointEntry(Address pc); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5069 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5070 | // Find an object in a stub with a specified map |
| 5071 | Object* FindNthObject(int n, Map* match_map); |
| 5072 | |
| 5073 | // Find the first allocation site in an IC stub. |
| 5074 | AllocationSite* FindFirstAllocationSite(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5075 | |
| 5076 | // Find the first map in an IC stub. |
| 5077 | Map* FindFirstMap(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5078 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5079 | class FindAndReplacePattern; |
| 5080 | // For each (map-to-find, object-to-replace) pair in the pattern, this |
| 5081 | // function replaces the corresponding placeholder in the code with the |
| 5082 | // object-to-replace. The function assumes that pairs in the pattern come in |
| 5083 | // the same order as the placeholders in the code. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5084 | // If the placeholder is a weak cell, then the value of weak cell is matched |
| 5085 | // against the map-to-find. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5086 | void FindAndReplace(const FindAndReplacePattern& pattern); |
| 5087 | |
| 5088 | // The entire code object including its header is copied verbatim to the |
| 5089 | // snapshot so that it can be written in one, fast, memcpy during |
| 5090 | // deserialization. The deserializer will overwrite some pointers, rather |
| 5091 | // like a runtime linker, but the random allocation addresses used in the |
| 5092 | // mksnapshot process would still be present in the unlinked snapshot data, |
| 5093 | // which would make snapshot production non-reproducible. This method wipes |
| 5094 | // out the to-be-overwritten header data for reproducible snapshots. |
| 5095 | inline void WipeOutHeader(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5096 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5097 | // Flags operations. |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 5098 | static inline Flags ComputeFlags( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5099 | Kind kind, InlineCacheState ic_state = UNINITIALIZED, |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 5100 | ExtraICState extra_ic_state = kNoExtraICState, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5101 | CacheHolderFlag holder = kCacheOnReceiver); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5102 | |
| 5103 | static inline Flags ComputeMonomorphicFlags( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5104 | Kind kind, ExtraICState extra_ic_state = kNoExtraICState, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5105 | CacheHolderFlag holder = kCacheOnReceiver); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5106 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 5107 | static inline Flags ComputeHandlerFlags( |
| 5108 | Kind handler_kind, CacheHolderFlag holder = kCacheOnReceiver); |
| 5109 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5110 | static inline InlineCacheState ExtractICStateFromFlags(Flags flags); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5111 | static inline CacheHolderFlag ExtractCacheHolderFromFlags(Flags flags); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 5112 | static inline Kind ExtractKindFromFlags(Flags flags); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 5113 | static inline ExtraICState ExtractExtraICStateFromFlags(Flags flags); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 5114 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 5115 | static inline Flags RemoveHolderFromFlags(Flags flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5116 | |
| 5117 | // Convert a target address into a code object. |
| 5118 | static inline Code* GetCodeFromTargetAddress(Address address); |
| 5119 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 5120 | // Convert an entry address into an object. |
| 5121 | static inline Object* GetObjectFromEntryAddress(Address location_of_address); |
| 5122 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5123 | // Returns the address of the first instruction. |
| 5124 | inline byte* instruction_start(); |
| 5125 | |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 5126 | // Returns the address right after the last instruction. |
| 5127 | inline byte* instruction_end(); |
| 5128 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5129 | // Returns the size of the instructions, padding, and relocation information. |
| 5130 | inline int body_size(); |
| 5131 | |
| 5132 | // Returns the address of the first relocation info (read backwards!). |
| 5133 | inline byte* relocation_start(); |
| 5134 | |
| 5135 | // Code entry point. |
| 5136 | inline byte* entry(); |
| 5137 | |
| 5138 | // Returns true if pc is inside this object's instructions. |
| 5139 | inline bool contains(byte* pc); |
| 5140 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5141 | // Relocate the code by delta bytes. Called to signal that this code |
| 5142 | // object has been moved by delta bytes. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5143 | void Relocate(intptr_t delta); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5144 | |
| 5145 | // Migrate code described by desc. |
| 5146 | void CopyFrom(const CodeDesc& desc); |
| 5147 | |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 5148 | // Returns the object size for a given body (used for allocation). |
| 5149 | static int SizeFor(int body_size) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5150 | DCHECK_SIZE_TAG_ALIGNED(body_size); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 5151 | return RoundUp(kHeaderSize + body_size, kCodeAlignment); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5152 | } |
| 5153 | |
| 5154 | // Calculate the size of the code object to report for log events. This takes |
| 5155 | // the layout of the code object into account. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5156 | inline int ExecutableSize(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5157 | |
| 5158 | // Locating source position. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5159 | int SourcePosition(int code_offset); |
| 5160 | int SourceStatementPosition(int code_offset); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5161 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5162 | DECLARE_CAST(Code) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5163 | |
| 5164 | // Dispatched behavior. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5165 | inline int CodeSize(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5166 | |
| 5167 | DECLARE_PRINTER(Code) |
| 5168 | DECLARE_VERIFIER(Code) |
| 5169 | |
Ben Murdoch | 8f9999f | 2012-04-23 10:39:17 +0100 | [diff] [blame] | 5170 | void ClearInlineCaches(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5171 | |
| 5172 | BailoutId TranslatePcOffsetToAstId(uint32_t pc_offset); |
| 5173 | uint32_t TranslateAstIdToPcOffset(BailoutId ast_id); |
| 5174 | |
| 5175 | #define DECLARE_CODE_AGE_ENUM(X) k##X##CodeAge, |
| 5176 | enum Age { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5177 | kToBeExecutedOnceCodeAge = -3, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5178 | kNotExecutedCodeAge = -2, |
| 5179 | kExecutedOnceCodeAge = -1, |
| 5180 | kNoAgeCodeAge = 0, |
| 5181 | CODE_AGE_LIST(DECLARE_CODE_AGE_ENUM) |
| 5182 | kAfterLastCodeAge, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5183 | kFirstCodeAge = kToBeExecutedOnceCodeAge, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5184 | kLastCodeAge = kAfterLastCodeAge - 1, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5185 | kCodeAgeCount = kAfterLastCodeAge - kFirstCodeAge - 1, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5186 | kIsOldCodeAge = kSexagenarianCodeAge, |
| 5187 | kPreAgedCodeAge = kIsOldCodeAge - 1 |
| 5188 | }; |
| 5189 | #undef DECLARE_CODE_AGE_ENUM |
| 5190 | |
| 5191 | // Code aging. Indicates how many full GCs this code has survived without |
| 5192 | // being entered through the prologue. Used to determine when it is |
| 5193 | // relatively safe to flush this code object and replace it with the lazy |
| 5194 | // compilation stub. |
| 5195 | static void MakeCodeAgeSequenceYoung(byte* sequence, Isolate* isolate); |
| 5196 | static void MarkCodeAsExecuted(byte* sequence, Isolate* isolate); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5197 | void MakeYoung(Isolate* isolate); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5198 | void PreAge(Isolate* isolate); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5199 | void MarkToBeExecutedOnce(Isolate* isolate); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5200 | void MakeOlder(MarkingParity); |
| 5201 | static bool IsYoungSequence(Isolate* isolate, byte* sequence); |
| 5202 | bool IsOld(); |
| 5203 | Age GetAge(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5204 | static inline Code* GetPreAgedCodeAgeStub(Isolate* isolate) { |
| 5205 | return GetCodeAgeStub(isolate, kNotExecutedCodeAge, NO_MARKING_PARITY); |
| 5206 | } |
| 5207 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5208 | void PrintDeoptLocation(FILE* out, Address pc); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5209 | bool CanDeoptAt(Address pc); |
| 5210 | |
| 5211 | #ifdef VERIFY_HEAP |
| 5212 | void VerifyEmbeddedObjectsDependency(); |
| 5213 | #endif |
| 5214 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5215 | #ifdef DEBUG |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5216 | enum VerifyMode { kNoContextSpecificPointers, kNoContextRetainingPointers }; |
| 5217 | void VerifyEmbeddedObjects(VerifyMode mode = kNoContextRetainingPointers); |
| 5218 | static void VerifyRecompiledCode(Code* old_code, Code* new_code); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5219 | #endif // DEBUG |
| 5220 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5221 | inline bool CanContainWeakObjects(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5222 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5223 | inline bool IsWeakObject(Object* object); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5224 | |
| 5225 | static inline bool IsWeakObjectInOptimizedCode(Object* object); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5226 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5227 | static Handle<WeakCell> WeakCellFor(Handle<Code> code); |
| 5228 | WeakCell* CachedWeakCell(); |
| 5229 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5230 | // Max loop nesting marker used to postpose OSR. We don't take loop |
| 5231 | // nesting that is deeper than 5 levels into account. |
| 5232 | static const int kMaxLoopNestingMarker = 6; |
| 5233 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5234 | static const int kConstantPoolSize = |
| 5235 | FLAG_enable_embedded_constant_pool ? kIntSize : 0; |
| 5236 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5237 | // Layout description. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5238 | static const int kRelocationInfoOffset = HeapObject::kHeaderSize; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5239 | static const int kHandlerTableOffset = kRelocationInfoOffset + kPointerSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5240 | static const int kDeoptimizationDataOffset = |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5241 | kHandlerTableOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5242 | // For FUNCTION kind, we store the type feedback info here. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5243 | static const int kTypeFeedbackInfoOffset = |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame] | 5244 | kDeoptimizationDataOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5245 | static const int kNextCodeLinkOffset = kTypeFeedbackInfoOffset + kPointerSize; |
| 5246 | static const int kGCMetadataOffset = kNextCodeLinkOffset + kPointerSize; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5247 | static const int kInstructionSizeOffset = kGCMetadataOffset + kPointerSize; |
| 5248 | static const int kICAgeOffset = kInstructionSizeOffset + kIntSize; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5249 | static const int kFlagsOffset = kICAgeOffset + kIntSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5250 | static const int kKindSpecificFlags1Offset = kFlagsOffset + kIntSize; |
| 5251 | static const int kKindSpecificFlags2Offset = |
| 5252 | kKindSpecificFlags1Offset + kIntSize; |
| 5253 | // Note: We might be able to squeeze this into the flags above. |
| 5254 | static const int kPrologueOffset = kKindSpecificFlags2Offset + kIntSize; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5255 | static const int kConstantPoolOffset = kPrologueOffset + kIntSize; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5256 | static const int kBuiltinIndexOffset = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5257 | kConstantPoolOffset + kConstantPoolSize; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5258 | static const int kHeaderPaddingStart = kBuiltinIndexOffset + kIntSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5259 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5260 | // Add padding to align the instruction start following right after |
| 5261 | // the Code object header. |
| 5262 | static const int kHeaderSize = |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5263 | (kHeaderPaddingStart + kCodeAlignmentMask) & ~kCodeAlignmentMask; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5264 | |
| 5265 | class BodyDescriptor; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5266 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5267 | // Byte offsets within kKindSpecificFlags1Offset. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5268 | static const int kFullCodeFlags = kKindSpecificFlags1Offset; |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 5269 | class FullCodeFlagsHasDeoptimizationSupportField: |
| 5270 | public BitField<bool, 0, 1> {}; // NOLINT |
| 5271 | class FullCodeFlagsHasDebugBreakSlotsField: public BitField<bool, 1, 1> {}; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5272 | class FullCodeFlagsHasRelocInfoForSerialization |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5273 | : public BitField<bool, 2, 1> {}; |
| 5274 | // Bit 3 in this bitfield is unused. |
| 5275 | class ProfilerTicksField : public BitField<int, 4, 28> {}; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5276 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 5277 | // Flags layout. BitField<type, shift, size>. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5278 | class ICStateField : public BitField<InlineCacheState, 0, 3> {}; |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 5279 | class CacheHolderField : public BitField<CacheHolderFlag, 3, 2> {}; |
| 5280 | class KindField : public BitField<Kind, 5, 5> {}; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5281 | class ExtraICStateField |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 5282 | : public BitField<ExtraICState, 10, PlatformSmiTagging::kSmiValueSize - |
| 5283 | 10 + 1> {}; // NOLINT |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5284 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5285 | // KindSpecificFlags1 layout (STUB, BUILTIN and OPTIMIZED_FUNCTION) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5286 | static const int kStackSlotsFirstBit = 0; |
| 5287 | static const int kStackSlotsBitCount = 24; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5288 | static const int kMarkedForDeoptimizationBit = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5289 | kStackSlotsFirstBit + kStackSlotsBitCount; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5290 | static const int kIsTurbofannedBit = kMarkedForDeoptimizationBit + 1; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5291 | static const int kCanHaveWeakObjects = kIsTurbofannedBit + 1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5292 | |
| 5293 | STATIC_ASSERT(kStackSlotsFirstBit + kStackSlotsBitCount <= 32); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5294 | STATIC_ASSERT(kCanHaveWeakObjects + 1 <= 32); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5295 | |
| 5296 | class StackSlotsField: public BitField<int, |
| 5297 | kStackSlotsFirstBit, kStackSlotsBitCount> {}; // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5298 | class MarkedForDeoptimizationField |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5299 | : public BitField<bool, kMarkedForDeoptimizationBit, 1> {}; // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5300 | class IsTurbofannedField : public BitField<bool, kIsTurbofannedBit, 1> { |
| 5301 | }; // NOLINT |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5302 | class CanHaveWeakObjectsField |
| 5303 | : public BitField<bool, kCanHaveWeakObjects, 1> {}; // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5304 | |
| 5305 | // KindSpecificFlags2 layout (ALL) |
| 5306 | static const int kIsCrankshaftedBit = 0; |
| 5307 | class IsCrankshaftedField: public BitField<bool, |
| 5308 | kIsCrankshaftedBit, 1> {}; // NOLINT |
| 5309 | |
| 5310 | // KindSpecificFlags2 layout (STUB and OPTIMIZED_FUNCTION) |
| 5311 | static const int kSafepointTableOffsetFirstBit = kIsCrankshaftedBit + 1; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5312 | static const int kSafepointTableOffsetBitCount = 30; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5313 | |
| 5314 | STATIC_ASSERT(kSafepointTableOffsetFirstBit + |
| 5315 | kSafepointTableOffsetBitCount <= 32); |
| 5316 | STATIC_ASSERT(1 + kSafepointTableOffsetBitCount <= 32); |
| 5317 | |
| 5318 | class SafepointTableOffsetField: public BitField<int, |
| 5319 | kSafepointTableOffsetFirstBit, |
| 5320 | kSafepointTableOffsetBitCount> {}; // NOLINT |
| 5321 | |
| 5322 | // KindSpecificFlags2 layout (FUNCTION) |
| 5323 | class BackEdgeTableOffsetField: public BitField<int, |
| 5324 | kIsCrankshaftedBit + 1, 27> {}; // NOLINT |
| 5325 | class AllowOSRAtLoopNestingLevelField: public BitField<int, |
| 5326 | kIsCrankshaftedBit + 1 + 27, 4> {}; // NOLINT |
| 5327 | STATIC_ASSERT(AllowOSRAtLoopNestingLevelField::kMax >= kMaxLoopNestingMarker); |
| 5328 | |
| 5329 | static const int kArgumentsBits = 16; |
| 5330 | static const int kMaxArguments = (1 << kArgumentsBits) - 1; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5331 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5332 | // This constant should be encodable in an ARM instruction. |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 5333 | static const int kFlagsNotUsedInLookup = CacheHolderField::kMask; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5334 | |
| 5335 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5336 | friend class RelocIterator; |
| 5337 | friend class Deoptimizer; // For FindCodeAgeSequence. |
| 5338 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5339 | // Code aging |
| 5340 | byte* FindCodeAgeSequence(); |
| 5341 | static void GetCodeAgeAndParity(Code* code, Age* age, |
| 5342 | MarkingParity* parity); |
| 5343 | static void GetCodeAgeAndParity(Isolate* isolate, byte* sequence, Age* age, |
| 5344 | MarkingParity* parity); |
| 5345 | static Code* GetCodeAgeStub(Isolate* isolate, Age age, MarkingParity parity); |
| 5346 | |
| 5347 | // Code aging -- platform-specific |
| 5348 | static void PatchPlatformCodeAge(Isolate* isolate, |
| 5349 | byte* sequence, Age age, |
| 5350 | MarkingParity parity); |
| 5351 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5352 | DISALLOW_IMPLICIT_CONSTRUCTORS(Code); |
| 5353 | }; |
| 5354 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5355 | class AbstractCode : public HeapObject { |
| 5356 | public: |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5357 | // All code kinds and INTERPRETED_FUNCTION. |
| 5358 | enum Kind { |
| 5359 | #define DEFINE_CODE_KIND_ENUM(name) name, |
| 5360 | CODE_KIND_LIST(DEFINE_CODE_KIND_ENUM) |
| 5361 | #undef DEFINE_CODE_KIND_ENUM |
| 5362 | INTERPRETED_FUNCTION, |
| 5363 | }; |
| 5364 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5365 | int SourcePosition(int offset); |
| 5366 | int SourceStatementPosition(int offset); |
| 5367 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5368 | // Returns the address of the first instruction. |
| 5369 | inline Address instruction_start(); |
| 5370 | |
| 5371 | // Returns the address right after the last instruction. |
| 5372 | inline Address instruction_end(); |
| 5373 | |
| 5374 | // Returns the of the code instructions. |
| 5375 | inline int instruction_size(); |
| 5376 | |
| 5377 | // Returns true if pc is inside this object's instructions. |
| 5378 | inline bool contains(byte* pc); |
| 5379 | |
| 5380 | // Returns the AbstractCode::Kind of the code. |
| 5381 | inline Kind kind(); |
| 5382 | |
| 5383 | // Calculate the size of the code object to report for log events. This takes |
| 5384 | // the layout of the code object into account. |
| 5385 | inline int ExecutableSize(); |
| 5386 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5387 | DECLARE_CAST(AbstractCode) |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5388 | inline Code* GetCode(); |
| 5389 | inline BytecodeArray* GetBytecodeArray(); |
| 5390 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5391 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5392 | // Dependent code is a singly linked list of fixed arrays. Each array contains |
| 5393 | // code objects in weak cells for one dependent group. The suffix of the array |
| 5394 | // can be filled with the undefined value if the number of codes is less than |
| 5395 | // the length of the array. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5396 | // |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5397 | // +------+-----------------+--------+--------+-----+--------+-----------+-----+ |
| 5398 | // | next | count & group 1 | code 1 | code 2 | ... | code n | undefined | ... | |
| 5399 | // +------+-----------------+--------+--------+-----+--------+-----------+-----+ |
| 5400 | // | |
| 5401 | // V |
| 5402 | // +------+-----------------+--------+--------+-----+--------+-----------+-----+ |
| 5403 | // | next | count & group 2 | code 1 | code 2 | ... | code m | undefined | ... | |
| 5404 | // +------+-----------------+--------+--------+-----+--------+-----------+-----+ |
| 5405 | // | |
| 5406 | // V |
| 5407 | // empty_fixed_array() |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5408 | // |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5409 | // The list of fixed arrays is ordered by dependency groups. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5410 | |
| 5411 | class DependentCode: public FixedArray { |
| 5412 | public: |
| 5413 | enum DependencyGroup { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5414 | // Group of code that weakly embed this map and depend on being |
| 5415 | // deoptimized when the map is garbage collected. |
| 5416 | kWeakCodeGroup, |
| 5417 | // Group of code that embed a transition to this map, and depend on being |
| 5418 | // deoptimized when the transition is replaced by a new version. |
| 5419 | kTransitionGroup, |
| 5420 | // Group of code that omit run-time prototype checks for prototypes |
| 5421 | // described by this map. The group is deoptimized whenever an object |
| 5422 | // described by this map changes shape (and transitions to a new map), |
| 5423 | // possibly invalidating the assumptions embedded in the code. |
| 5424 | kPrototypeCheckGroup, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5425 | // Group of code that depends on global property values in property cells |
| 5426 | // not being changed. |
| 5427 | kPropertyCellChangedGroup, |
| 5428 | // Group of code that omit run-time type checks for the field(s) introduced |
| 5429 | // by this map. |
| 5430 | kFieldTypeGroup, |
| 5431 | // Group of code that omit run-time type checks for initial maps of |
| 5432 | // constructors. |
| 5433 | kInitialMapChangedGroup, |
| 5434 | // Group of code that depends on tenuring information in AllocationSites |
| 5435 | // not being changed. |
| 5436 | kAllocationSiteTenuringChangedGroup, |
| 5437 | // Group of code that depends on element transition information in |
| 5438 | // AllocationSites not being changed. |
| 5439 | kAllocationSiteTransitionChangedGroup |
| 5440 | }; |
| 5441 | |
| 5442 | static const int kGroupCount = kAllocationSiteTransitionChangedGroup + 1; |
| 5443 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5444 | bool Contains(DependencyGroup group, WeakCell* code_cell); |
| 5445 | bool IsEmpty(DependencyGroup group); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5446 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5447 | static Handle<DependentCode> InsertCompilationDependencies( |
| 5448 | Handle<DependentCode> entries, DependencyGroup group, |
| 5449 | Handle<Foreign> info); |
| 5450 | |
| 5451 | static Handle<DependentCode> InsertWeakCode(Handle<DependentCode> entries, |
| 5452 | DependencyGroup group, |
| 5453 | Handle<WeakCell> code_cell); |
| 5454 | |
| 5455 | void UpdateToFinishedCode(DependencyGroup group, Foreign* info, |
| 5456 | WeakCell* code_cell); |
| 5457 | |
| 5458 | void RemoveCompilationDependencies(DependentCode::DependencyGroup group, |
| 5459 | Foreign* info); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5460 | |
| 5461 | void DeoptimizeDependentCodeGroup(Isolate* isolate, |
| 5462 | DependentCode::DependencyGroup group); |
| 5463 | |
| 5464 | bool MarkCodeForDeoptimization(Isolate* isolate, |
| 5465 | DependentCode::DependencyGroup group); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5466 | |
| 5467 | // The following low-level accessors should only be used by this class |
| 5468 | // and the mark compact collector. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5469 | inline DependentCode* next_link(); |
| 5470 | inline void set_next_link(DependentCode* next); |
| 5471 | inline int count(); |
| 5472 | inline void set_count(int value); |
| 5473 | inline DependencyGroup group(); |
| 5474 | inline void set_group(DependencyGroup group); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5475 | inline Object* object_at(int i); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5476 | inline void set_object_at(int i, Object* object); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5477 | inline void clear_at(int i); |
| 5478 | inline void copy(int from, int to); |
| 5479 | DECLARE_CAST(DependentCode) |
| 5480 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5481 | static const char* DependencyGroupName(DependencyGroup group); |
| 5482 | static void SetMarkedForDeoptimization(Code* code, DependencyGroup group); |
| 5483 | |
| 5484 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5485 | static Handle<DependentCode> Insert(Handle<DependentCode> entries, |
| 5486 | DependencyGroup group, |
| 5487 | Handle<Object> object); |
| 5488 | static Handle<DependentCode> New(DependencyGroup group, Handle<Object> object, |
| 5489 | Handle<DependentCode> next); |
| 5490 | static Handle<DependentCode> EnsureSpace(Handle<DependentCode> entries); |
| 5491 | // Compact by removing cleared weak cells and return true if there was |
| 5492 | // any cleared weak cell. |
| 5493 | bool Compact(); |
| 5494 | static int Grow(int number_of_entries) { |
| 5495 | if (number_of_entries < 5) return number_of_entries + 1; |
| 5496 | return number_of_entries * 5 / 4; |
| 5497 | } |
| 5498 | inline int flags(); |
| 5499 | inline void set_flags(int flags); |
| 5500 | class GroupField : public BitField<int, 0, 3> {}; |
| 5501 | class CountField : public BitField<int, 3, 27> {}; |
| 5502 | STATIC_ASSERT(kGroupCount <= GroupField::kMax + 1); |
| 5503 | static const int kNextLinkIndex = 0; |
| 5504 | static const int kFlagsIndex = 1; |
| 5505 | static const int kCodesStartIndex = 2; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5506 | }; |
| 5507 | |
| 5508 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5509 | class PrototypeInfo; |
| 5510 | |
| 5511 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5512 | // All heap objects have a Map that describes their structure. |
| 5513 | // A Map contains information about: |
| 5514 | // - Size information about the object |
| 5515 | // - How to iterate over an object (for garbage collection) |
| 5516 | class Map: public HeapObject { |
| 5517 | public: |
| 5518 | // Instance size. |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 5519 | // Size in bytes or kVariableSizeSentinel if instances do not have |
| 5520 | // a fixed size. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5521 | inline int instance_size(); |
| 5522 | inline void set_instance_size(int value); |
| 5523 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5524 | // Only to clear an unused byte, remove once byte is used. |
| 5525 | inline void clear_unused(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5526 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5527 | // [inobject_properties_or_constructor_function_index]: Provides access |
| 5528 | // to the inobject properties in case of JSObject maps, or the constructor |
| 5529 | // function index in case of primitive maps. |
| 5530 | inline int inobject_properties_or_constructor_function_index(); |
| 5531 | inline void set_inobject_properties_or_constructor_function_index(int value); |
| 5532 | // Count of properties allocated in the object (JSObject only). |
| 5533 | inline int GetInObjectProperties(); |
| 5534 | inline void SetInObjectProperties(int value); |
| 5535 | // Index of the constructor function in the native context (primitives only), |
| 5536 | // or the special sentinel value to indicate that there is no object wrapper |
| 5537 | // for the primitive (i.e. in case of null or undefined). |
| 5538 | static const int kNoConstructorFunctionIndex = 0; |
| 5539 | inline int GetConstructorFunctionIndex(); |
| 5540 | inline void SetConstructorFunctionIndex(int value); |
| 5541 | static MaybeHandle<JSFunction> GetConstructorFunction( |
| 5542 | Handle<Map> map, Handle<Context> native_context); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5543 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5544 | // Retrieve interceptors. |
| 5545 | inline InterceptorInfo* GetNamedInterceptor(); |
| 5546 | inline InterceptorInfo* GetIndexedInterceptor(); |
| 5547 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5548 | // Instance type. |
| 5549 | inline InstanceType instance_type(); |
| 5550 | inline void set_instance_type(InstanceType value); |
| 5551 | |
| 5552 | // Tells how many unused property fields are available in the |
| 5553 | // instance (only used for JSObject in fast mode). |
| 5554 | inline int unused_property_fields(); |
| 5555 | inline void set_unused_property_fields(int value); |
| 5556 | |
| 5557 | // Bit field. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5558 | inline byte bit_field() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5559 | inline void set_bit_field(byte value); |
| 5560 | |
| 5561 | // Bit field 2. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5562 | inline byte bit_field2() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5563 | inline void set_bit_field2(byte value); |
| 5564 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5565 | // Bit field 3. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5566 | inline uint32_t bit_field3() const; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5567 | inline void set_bit_field3(uint32_t bits); |
| 5568 | |
| 5569 | class EnumLengthBits: public BitField<int, |
| 5570 | 0, kDescriptorIndexBitCount> {}; // NOLINT |
| 5571 | class NumberOfOwnDescriptorsBits: public BitField<int, |
| 5572 | kDescriptorIndexBitCount, kDescriptorIndexBitCount> {}; // NOLINT |
| 5573 | STATIC_ASSERT(kDescriptorIndexBitCount + kDescriptorIndexBitCount == 20); |
| 5574 | class DictionaryMap : public BitField<bool, 20, 1> {}; |
| 5575 | class OwnsDescriptors : public BitField<bool, 21, 1> {}; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5576 | class HasHiddenPrototype : public BitField<bool, 22, 1> {}; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5577 | class Deprecated : public BitField<bool, 23, 1> {}; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5578 | class IsUnstable : public BitField<bool, 24, 1> {}; |
| 5579 | class IsMigrationTarget : public BitField<bool, 25, 1> {}; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5580 | // Bit 26 is free. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5581 | class NewTargetIsBase : public BitField<bool, 27, 1> {}; |
| 5582 | // Bit 28 is free. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5583 | |
| 5584 | // Keep this bit field at the very end for better code in |
| 5585 | // Builtins::kJSConstructStubGeneric stub. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5586 | // This counter is used for in-object slack tracking. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5587 | // The in-object slack tracking is considered enabled when the counter is |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5588 | // non zero. The counter only has a valid count for initial maps. For |
| 5589 | // transitioned maps only kNoSlackTracking has a meaning, namely that inobject |
| 5590 | // slack tracking already finished for the transition tree. Any other value |
| 5591 | // indicates that either inobject slack tracking is still in progress, or that |
| 5592 | // the map isn't part of the transition tree anymore. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5593 | class ConstructionCounter : public BitField<int, 29, 3> {}; |
| 5594 | static const int kSlackTrackingCounterStart = 7; |
| 5595 | static const int kSlackTrackingCounterEnd = 1; |
| 5596 | static const int kNoSlackTracking = 0; |
| 5597 | STATIC_ASSERT(kSlackTrackingCounterStart <= ConstructionCounter::kMax); |
| 5598 | |
| 5599 | |
| 5600 | // Inobject slack tracking is the way to reclaim unused inobject space. |
| 5601 | // |
| 5602 | // The instance size is initially determined by adding some slack to |
| 5603 | // expected_nof_properties (to allow for a few extra properties added |
| 5604 | // after the constructor). There is no guarantee that the extra space |
| 5605 | // will not be wasted. |
| 5606 | // |
| 5607 | // Here is the algorithm to reclaim the unused inobject space: |
| 5608 | // - Detect the first constructor call for this JSFunction. |
| 5609 | // When it happens enter the "in progress" state: initialize construction |
| 5610 | // counter in the initial_map. |
| 5611 | // - While the tracking is in progress initialize unused properties of a new |
| 5612 | // object with one_pointer_filler_map instead of undefined_value (the "used" |
| 5613 | // part is initialized with undefined_value as usual). This way they can |
| 5614 | // be resized quickly and safely. |
| 5615 | // - Once enough objects have been created compute the 'slack' |
| 5616 | // (traverse the map transition tree starting from the |
| 5617 | // initial_map and find the lowest value of unused_property_fields). |
| 5618 | // - Traverse the transition tree again and decrease the instance size |
| 5619 | // of every map. Existing objects will resize automatically (they are |
| 5620 | // filled with one_pointer_filler_map). All further allocations will |
| 5621 | // use the adjusted instance size. |
| 5622 | // - SharedFunctionInfo's expected_nof_properties left unmodified since |
| 5623 | // allocations made using different closures could actually create different |
| 5624 | // kind of objects (see prototype inheritance pattern). |
| 5625 | // |
| 5626 | // Important: inobject slack tracking is not attempted during the snapshot |
| 5627 | // creation. |
| 5628 | |
| 5629 | static const int kGenerousAllocationCount = |
| 5630 | kSlackTrackingCounterStart - kSlackTrackingCounterEnd + 1; |
| 5631 | |
| 5632 | // Starts the tracking by initializing object constructions countdown counter. |
| 5633 | void StartInobjectSlackTracking(); |
| 5634 | |
| 5635 | // True if the object constructions countdown counter is a range |
| 5636 | // [kSlackTrackingCounterEnd, kSlackTrackingCounterStart]. |
| 5637 | inline bool IsInobjectSlackTrackingInProgress(); |
| 5638 | |
| 5639 | // Does the tracking step. |
| 5640 | inline void InobjectSlackTrackingStep(); |
| 5641 | |
| 5642 | // Completes inobject slack tracking for the transition tree starting at this |
| 5643 | // initial map. |
| 5644 | void CompleteInobjectSlackTracking(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5645 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5646 | // Tells whether the object in the prototype property will be used |
| 5647 | // for instances created from this function. If the prototype |
| 5648 | // property is set to a value that is not a JSObject, the prototype |
| 5649 | // property will not be used to create instances of the function. |
| 5650 | // See ECMA-262, 13.2.2. |
| 5651 | inline void set_non_instance_prototype(bool value); |
| 5652 | inline bool has_non_instance_prototype(); |
| 5653 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5654 | // Tells whether the instance has a [[Construct]] internal method. |
| 5655 | // This property is implemented according to ES6, section 7.2.4. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5656 | inline void set_is_constructor(bool value); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5657 | inline bool is_constructor() const; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5658 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5659 | // Tells whether the instance with this map has a hidden prototype. |
| 5660 | inline void set_has_hidden_prototype(bool value); |
| 5661 | inline bool has_hidden_prototype() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5662 | |
| 5663 | // Records and queries whether the instance has a named interceptor. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5664 | inline void set_has_named_interceptor(); |
| 5665 | inline bool has_named_interceptor(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5666 | |
| 5667 | // Records and queries whether the instance has an indexed interceptor. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5668 | inline void set_has_indexed_interceptor(); |
| 5669 | inline bool has_indexed_interceptor(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5670 | |
| 5671 | // Tells whether the instance is undetectable. |
| 5672 | // An undetectable object is a special class of JSObject: 'typeof' operator |
| 5673 | // returns undefined, ToBoolean returns false. Otherwise it behaves like |
| 5674 | // a normal JS object. It is useful for implementing undetectable |
| 5675 | // document.all in Firefox & Safari. |
| 5676 | // See https://bugzilla.mozilla.org/show_bug.cgi?id=248549. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5677 | inline void set_is_undetectable(); |
| 5678 | inline bool is_undetectable(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5679 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5680 | // Tells whether the instance has a [[Call]] internal method. |
| 5681 | // This property is implemented according to ES6, section 7.2.3. |
| 5682 | inline void set_is_callable(); |
| 5683 | inline bool is_callable() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5684 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5685 | inline void set_new_target_is_base(bool value); |
| 5686 | inline bool new_target_is_base(); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 5687 | inline void set_is_extensible(bool value); |
| 5688 | inline bool is_extensible(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5689 | inline void set_is_prototype_map(bool value); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5690 | inline bool is_prototype_map() const; |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 5691 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5692 | inline void set_elements_kind(ElementsKind elements_kind); |
| 5693 | inline ElementsKind elements_kind(); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 5694 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5695 | // Tells whether the instance has fast elements that are only Smis. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5696 | inline bool has_fast_smi_elements(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5697 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 5698 | // Tells whether the instance has fast elements. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5699 | inline bool has_fast_object_elements(); |
| 5700 | inline bool has_fast_smi_or_object_elements(); |
| 5701 | inline bool has_fast_double_elements(); |
| 5702 | inline bool has_fast_elements(); |
| 5703 | inline bool has_sloppy_arguments_elements(); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5704 | inline bool has_fast_string_wrapper_elements(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5705 | inline bool has_fixed_typed_array_elements(); |
| 5706 | inline bool has_dictionary_elements(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5707 | |
| 5708 | static bool IsValidElementsTransition(ElementsKind from_kind, |
| 5709 | ElementsKind to_kind); |
| 5710 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5711 | // Returns true if the current map doesn't have DICTIONARY_ELEMENTS but if a |
| 5712 | // map with DICTIONARY_ELEMENTS was found in the prototype chain. |
| 5713 | bool DictionaryElementsInPrototypeChainOnly(); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5714 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5715 | inline Map* ElementsTransitionMap(); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5716 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5717 | inline FixedArrayBase* GetInitialElements(); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5718 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5719 | // [raw_transitions]: Provides access to the transitions storage field. |
| 5720 | // Don't call set_raw_transitions() directly to overwrite transitions, use |
| 5721 | // the TransitionArray::ReplaceTransitions() wrapper instead! |
| 5722 | DECL_ACCESSORS(raw_transitions, Object) |
| 5723 | // [prototype_info]: Per-prototype metadata. Aliased with transitions |
| 5724 | // (which prototype maps don't have). |
| 5725 | DECL_ACCESSORS(prototype_info, Object) |
| 5726 | // PrototypeInfo is created lazily using this helper (which installs it on |
| 5727 | // the given prototype's map). |
| 5728 | static Handle<PrototypeInfo> GetOrCreatePrototypeInfo( |
| 5729 | Handle<JSObject> prototype, Isolate* isolate); |
| 5730 | static Handle<PrototypeInfo> GetOrCreatePrototypeInfo( |
| 5731 | Handle<Map> prototype_map, Isolate* isolate); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5732 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5733 | // [prototype chain validity cell]: Associated with a prototype object, |
| 5734 | // stored in that object's map's PrototypeInfo, indicates that prototype |
| 5735 | // chains through this object are currently valid. The cell will be |
| 5736 | // invalidated and replaced when the prototype chain changes. |
| 5737 | static Handle<Cell> GetOrCreatePrototypeChainValidityCell(Handle<Map> map, |
| 5738 | Isolate* isolate); |
| 5739 | static const int kPrototypeChainValid = 0; |
| 5740 | static const int kPrototypeChainInvalid = 1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5741 | |
| 5742 | Map* FindRootMap(); |
| 5743 | Map* FindFieldOwner(int descriptor); |
| 5744 | |
| 5745 | inline int GetInObjectPropertyOffset(int index); |
| 5746 | |
| 5747 | int NumberOfFields(); |
| 5748 | |
| 5749 | // TODO(ishell): candidate with JSObject::MigrateToMap(). |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 5750 | bool InstancesNeedRewriting(Map* target); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5751 | bool InstancesNeedRewriting(Map* target, int target_number_of_fields, |
| 5752 | int target_inobject, int target_unused, |
| 5753 | int* old_number_of_fields); |
| 5754 | // TODO(ishell): moveit! |
| 5755 | static Handle<Map> GeneralizeAllFieldRepresentations(Handle<Map> map); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5756 | MUST_USE_RESULT static Handle<FieldType> GeneralizeFieldType( |
| 5757 | Representation rep1, Handle<FieldType> type1, Representation rep2, |
| 5758 | Handle<FieldType> type2, Isolate* isolate); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5759 | static void GeneralizeFieldType(Handle<Map> map, int modify_index, |
| 5760 | Representation new_representation, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5761 | Handle<FieldType> new_field_type); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 5762 | |
| 5763 | static inline Handle<Map> ReconfigureProperty( |
| 5764 | Handle<Map> map, int modify_index, PropertyKind new_kind, |
| 5765 | PropertyAttributes new_attributes, Representation new_representation, |
| 5766 | Handle<FieldType> new_field_type, StoreMode store_mode); |
| 5767 | |
| 5768 | static inline Handle<Map> ReconfigureElementsKind( |
| 5769 | Handle<Map> map, ElementsKind new_elements_kind); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5770 | |
| 5771 | static Handle<Map> PrepareForDataProperty(Handle<Map> old_map, |
| 5772 | int descriptor_number, |
| 5773 | Handle<Object> value); |
| 5774 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5775 | static Handle<Map> Normalize(Handle<Map> map, PropertyNormalizationMode mode, |
| 5776 | const char* reason); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5777 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5778 | // Tells whether the map is used for JSObjects in dictionary mode (ie |
| 5779 | // normalized objects, ie objects for which HasFastProperties returns false). |
| 5780 | // A map can never be used for both dictionary mode and fast mode JSObjects. |
| 5781 | // False by default and for HeapObjects that are not JSObjects. |
| 5782 | inline void set_dictionary_map(bool value); |
| 5783 | inline bool is_dictionary_map(); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5784 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5785 | // Tells whether the instance needs security checks when accessing its |
| 5786 | // properties. |
| 5787 | inline void set_is_access_check_needed(bool access_check_needed); |
| 5788 | inline bool is_access_check_needed(); |
| 5789 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5790 | // Returns true if map has a non-empty stub code cache. |
| 5791 | inline bool has_code_cache(); |
| 5792 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5793 | // [prototype]: implicit prototype object. |
| 5794 | DECL_ACCESSORS(prototype, Object) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5795 | // TODO(jkummerow): make set_prototype private. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5796 | static void SetPrototype( |
| 5797 | Handle<Map> map, Handle<Object> prototype, |
| 5798 | PrototypeOptimizationMode proto_mode = FAST_PROTOTYPE); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5799 | |
| 5800 | // [constructor]: points back to the function responsible for this map. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5801 | // The field overlaps with the back pointer. All maps in a transition tree |
| 5802 | // have the same constructor, so maps with back pointers can walk the |
| 5803 | // back pointer chain until they find the map holding their constructor. |
| 5804 | DECL_ACCESSORS(constructor_or_backpointer, Object) |
| 5805 | inline Object* GetConstructor() const; |
| 5806 | inline void SetConstructor(Object* constructor, |
| 5807 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| 5808 | // [back pointer]: points back to the parent map from which a transition |
| 5809 | // leads to this map. The field overlaps with the constructor (see above). |
| 5810 | inline Object* GetBackPointer(); |
| 5811 | inline void SetBackPointer(Object* value, |
| 5812 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5813 | |
| 5814 | // [instance descriptors]: describes the object. |
| 5815 | DECL_ACCESSORS(instance_descriptors, DescriptorArray) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5816 | |
| 5817 | // [layout descriptor]: describes the object layout. |
| 5818 | DECL_ACCESSORS(layout_descriptor, LayoutDescriptor) |
| 5819 | // |layout descriptor| accessor which can be used from GC. |
| 5820 | inline LayoutDescriptor* layout_descriptor_gc_safe(); |
| 5821 | inline bool HasFastPointerLayout() const; |
| 5822 | |
| 5823 | // |layout descriptor| accessor that is safe to call even when |
| 5824 | // FLAG_unbox_double_fields is disabled (in this case Map does not contain |
| 5825 | // |layout_descriptor| field at all). |
| 5826 | inline LayoutDescriptor* GetLayoutDescriptor(); |
| 5827 | |
| 5828 | inline void UpdateDescriptors(DescriptorArray* descriptors, |
| 5829 | LayoutDescriptor* layout_descriptor); |
| 5830 | inline void InitializeDescriptors(DescriptorArray* descriptors, |
| 5831 | LayoutDescriptor* layout_descriptor); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5832 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5833 | // [stub cache]: contains stubs compiled for this map. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5834 | DECL_ACCESSORS(code_cache, Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5835 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5836 | // [dependent code]: list of optimized codes that weakly embed this map. |
| 5837 | DECL_ACCESSORS(dependent_code, DependentCode) |
| 5838 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5839 | // [weak cell cache]: cache that stores a weak cell pointing to this map. |
| 5840 | DECL_ACCESSORS(weak_cell_cache, Object) |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5841 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5842 | inline PropertyDetails GetLastDescriptorDetails(); |
| 5843 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5844 | inline int LastAdded(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5845 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5846 | inline int NumberOfOwnDescriptors(); |
| 5847 | inline void SetNumberOfOwnDescriptors(int number); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5848 | |
| 5849 | inline Cell* RetrieveDescriptorsPointer(); |
| 5850 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5851 | // Checks whether all properties are stored either in the map or on the object |
| 5852 | // (inobject, properties, or elements backing store), requiring no special |
| 5853 | // checks. |
| 5854 | bool OnlyHasSimpleProperties(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5855 | inline int EnumLength(); |
| 5856 | inline void SetEnumLength(int length); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5857 | |
| 5858 | inline bool owns_descriptors(); |
| 5859 | inline void set_owns_descriptors(bool owns_descriptors); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5860 | inline void mark_unstable(); |
| 5861 | inline bool is_stable(); |
| 5862 | inline void set_migration_target(bool value); |
| 5863 | inline bool is_migration_target(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5864 | inline void set_construction_counter(int value); |
| 5865 | inline int construction_counter(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5866 | inline void deprecate(); |
| 5867 | inline bool is_deprecated(); |
| 5868 | inline bool CanBeDeprecated(); |
| 5869 | // Returns a non-deprecated version of the input. If the input was not |
| 5870 | // deprecated, it is directly returned. Otherwise, the non-deprecated version |
| 5871 | // is found by re-transitioning from the root of the transition tree using the |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5872 | // descriptor array of the map. Returns MaybeHandle<Map>() if no updated map |
| 5873 | // is found. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5874 | static MaybeHandle<Map> TryUpdate(Handle<Map> map) WARN_UNUSED_RESULT; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5875 | |
| 5876 | // Returns a non-deprecated version of the input. This method may deprecate |
| 5877 | // existing maps along the way if encodings conflict. Not for use while |
| 5878 | // gathering type feedback. Use TryUpdate in those cases instead. |
| 5879 | static Handle<Map> Update(Handle<Map> map); |
| 5880 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5881 | static inline Handle<Map> CopyInitialMap(Handle<Map> map); |
| 5882 | static Handle<Map> CopyInitialMap(Handle<Map> map, int instance_size, |
| 5883 | int in_object_properties, |
| 5884 | int unused_property_fields); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5885 | static Handle<Map> CopyDropDescriptors(Handle<Map> map); |
| 5886 | static Handle<Map> CopyInsertDescriptor(Handle<Map> map, |
| 5887 | Descriptor* descriptor, |
| 5888 | TransitionFlag flag); |
| 5889 | |
| 5890 | MUST_USE_RESULT static MaybeHandle<Map> CopyWithField( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5891 | Handle<Map> map, Handle<Name> name, Handle<FieldType> type, |
| 5892 | PropertyAttributes attributes, Representation representation, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5893 | TransitionFlag flag); |
| 5894 | |
| 5895 | MUST_USE_RESULT static MaybeHandle<Map> CopyWithConstant( |
| 5896 | Handle<Map> map, |
| 5897 | Handle<Name> name, |
| 5898 | Handle<Object> constant, |
| 5899 | PropertyAttributes attributes, |
| 5900 | TransitionFlag flag); |
| 5901 | |
| 5902 | // Returns a new map with all transitions dropped from the given map and |
| 5903 | // the ElementsKind set. |
| 5904 | static Handle<Map> TransitionElementsTo(Handle<Map> map, |
| 5905 | ElementsKind to_kind); |
| 5906 | |
| 5907 | static Handle<Map> AsElementsKind(Handle<Map> map, ElementsKind kind); |
| 5908 | |
| 5909 | static Handle<Map> CopyAsElementsKind(Handle<Map> map, |
| 5910 | ElementsKind kind, |
| 5911 | TransitionFlag flag); |
| 5912 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5913 | static Handle<Map> AsLanguageMode(Handle<Map> initial_map, |
| 5914 | LanguageMode language_mode, |
| 5915 | FunctionKind kind); |
| 5916 | |
| 5917 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5918 | static Handle<Map> CopyForPreventExtensions(Handle<Map> map, |
| 5919 | PropertyAttributes attrs_to_add, |
| 5920 | Handle<Symbol> transition_marker, |
| 5921 | const char* reason); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5922 | |
| 5923 | static Handle<Map> FixProxy(Handle<Map> map, InstanceType type, int size); |
| 5924 | |
| 5925 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5926 | // Maximal number of fast properties. Used to restrict the number of map |
| 5927 | // transitions to avoid an explosion in the number of maps for objects used as |
| 5928 | // dictionaries. |
| 5929 | inline bool TooManyFastProperties(StoreFromKeyed store_mode); |
| 5930 | static Handle<Map> TransitionToDataProperty(Handle<Map> map, |
| 5931 | Handle<Name> name, |
| 5932 | Handle<Object> value, |
| 5933 | PropertyAttributes attributes, |
| 5934 | StoreFromKeyed store_mode); |
| 5935 | static Handle<Map> TransitionToAccessorProperty( |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 5936 | Isolate* isolate, Handle<Map> map, Handle<Name> name, int descriptor, |
| 5937 | Handle<Object> getter, Handle<Object> setter, |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 5938 | PropertyAttributes attributes); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5939 | static Handle<Map> ReconfigureExistingProperty(Handle<Map> map, |
| 5940 | int descriptor, |
| 5941 | PropertyKind kind, |
| 5942 | PropertyAttributes attributes); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5943 | |
| 5944 | inline void AppendDescriptor(Descriptor* desc); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5945 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5946 | // Returns a copy of the map, prepared for inserting into the transition |
| 5947 | // tree (if the |map| owns descriptors then the new one will share |
| 5948 | // descriptors with |map|). |
| 5949 | static Handle<Map> CopyForTransition(Handle<Map> map, const char* reason); |
| 5950 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5951 | // Returns a copy of the map, with all transitions dropped from the |
| 5952 | // instance descriptors. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5953 | static Handle<Map> Copy(Handle<Map> map, const char* reason); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5954 | static Handle<Map> Create(Isolate* isolate, int inobject_properties); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5955 | |
| 5956 | // Returns the next free property index (only valid for FAST MODE). |
| 5957 | int NextFreePropertyIndex(); |
| 5958 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5959 | // Returns the number of properties described in instance_descriptors |
| 5960 | // filtering out properties with the specified attributes. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5961 | int NumberOfDescribedProperties(DescriptorFlag which = OWN_DESCRIPTORS, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5962 | PropertyFilter filter = ALL_PROPERTIES); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5963 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5964 | DECLARE_CAST(Map) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5965 | |
| 5966 | // Code cache operations. |
| 5967 | |
| 5968 | // Clears the code cache. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 5969 | inline void ClearCodeCache(Heap* heap); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5970 | |
| 5971 | // Update code cache. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5972 | static void UpdateCodeCache(Handle<Map> map, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5973 | Handle<Name> name, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5974 | Handle<Code> code); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5975 | |
| 5976 | // Extend the descriptor array of the map with the list of descriptors. |
| 5977 | // In case of duplicates, the latest descriptor is used. |
| 5978 | static void AppendCallbackDescriptors(Handle<Map> map, |
| 5979 | Handle<Object> descriptors); |
| 5980 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5981 | static inline int SlackForArraySize(int old_size, int size_limit); |
| 5982 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5983 | static void EnsureDescriptorSlack(Handle<Map> map, int slack); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5984 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 5985 | Code* LookupInCodeCache(Name* name, Code::Flags code); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5986 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 5987 | // Computes a hash value for this map, to be used in HashTables and such. |
| 5988 | int Hash(); |
| 5989 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5990 | // Returns the transitioned map for this map with the most generic |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 5991 | // elements_kind that's found in |candidates|, or |nullptr| if no match is |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5992 | // found at all. |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 5993 | Map* FindElementsKindTransitionedMap(MapHandleList* candidates); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5994 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5995 | inline bool CanTransition(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5996 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5997 | inline bool IsBooleanMap(); |
| 5998 | inline bool IsPrimitiveMap(); |
| 5999 | inline bool IsJSReceiverMap(); |
| 6000 | inline bool IsJSObjectMap(); |
| 6001 | inline bool IsJSArrayMap(); |
| 6002 | inline bool IsJSFunctionMap(); |
| 6003 | inline bool IsStringMap(); |
| 6004 | inline bool IsJSProxyMap(); |
| 6005 | inline bool IsJSGlobalProxyMap(); |
| 6006 | inline bool IsJSGlobalObjectMap(); |
| 6007 | inline bool IsJSTypedArrayMap(); |
| 6008 | inline bool IsJSDataViewMap(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6009 | |
| 6010 | inline bool CanOmitMapChecks(); |
| 6011 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6012 | static void AddDependentCode(Handle<Map> map, |
| 6013 | DependentCode::DependencyGroup group, |
| 6014 | Handle<Code> code); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6015 | |
| 6016 | bool IsMapInArrayPrototypeChain(); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 6017 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6018 | static Handle<WeakCell> WeakCellForMap(Handle<Map> map); |
| 6019 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6020 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6021 | DECLARE_PRINTER(Map) |
| 6022 | DECLARE_VERIFIER(Map) |
| 6023 | |
| 6024 | #ifdef VERIFY_HEAP |
| 6025 | void DictionaryMapVerify(); |
| 6026 | void VerifyOmittedMapChecks(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6027 | #endif |
| 6028 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 6029 | inline int visitor_id(); |
| 6030 | inline void set_visitor_id(int visitor_id); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 6031 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6032 | static Handle<Map> TransitionToPrototype(Handle<Map> map, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6033 | Handle<Object> prototype, |
| 6034 | PrototypeOptimizationMode mode); |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 6035 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6036 | static const int kMaxPreAllocatedPropertyFields = 255; |
| 6037 | |
| 6038 | // Layout description. |
| 6039 | static const int kInstanceSizesOffset = HeapObject::kHeaderSize; |
| 6040 | static const int kInstanceAttributesOffset = kInstanceSizesOffset + kIntSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6041 | static const int kBitField3Offset = kInstanceAttributesOffset + kIntSize; |
| 6042 | static const int kPrototypeOffset = kBitField3Offset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6043 | static const int kConstructorOrBackPointerOffset = |
| 6044 | kPrototypeOffset + kPointerSize; |
| 6045 | // When there is only one transition, it is stored directly in this field; |
| 6046 | // otherwise a transition array is used. |
| 6047 | // For prototype maps, this slot is used to store this map's PrototypeInfo |
| 6048 | // struct. |
| 6049 | static const int kTransitionsOrPrototypeInfoOffset = |
| 6050 | kConstructorOrBackPointerOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6051 | static const int kDescriptorsOffset = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6052 | kTransitionsOrPrototypeInfoOffset + kPointerSize; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6053 | #if V8_DOUBLE_FIELDS_UNBOXING |
| 6054 | static const int kLayoutDecriptorOffset = kDescriptorsOffset + kPointerSize; |
| 6055 | static const int kCodeCacheOffset = kLayoutDecriptorOffset + kPointerSize; |
| 6056 | #else |
| 6057 | static const int kLayoutDecriptorOffset = 1; // Must not be ever accessed. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6058 | static const int kCodeCacheOffset = kDescriptorsOffset + kPointerSize; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6059 | #endif |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6060 | static const int kDependentCodeOffset = kCodeCacheOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6061 | static const int kWeakCellCacheOffset = kDependentCodeOffset + kPointerSize; |
| 6062 | static const int kSize = kWeakCellCacheOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 6063 | |
| 6064 | // Layout of pointer fields. Heap iteration code relies on them |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 6065 | // being continuously allocated. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 6066 | static const int kPointerFieldsBeginOffset = Map::kPrototypeOffset; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6067 | static const int kPointerFieldsEndOffset = kSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6068 | |
| 6069 | // Byte offsets within kInstanceSizesOffset. |
| 6070 | static const int kInstanceSizeOffset = kInstanceSizesOffset + 0; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6071 | static const int kInObjectPropertiesOrConstructorFunctionIndexByte = 1; |
| 6072 | static const int kInObjectPropertiesOrConstructorFunctionIndexOffset = |
| 6073 | kInstanceSizesOffset + kInObjectPropertiesOrConstructorFunctionIndexByte; |
| 6074 | // Note there is one byte available for use here. |
| 6075 | static const int kUnusedByte = 2; |
| 6076 | static const int kUnusedOffset = kInstanceSizesOffset + kUnusedByte; |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 6077 | static const int kVisitorIdByte = 3; |
| 6078 | static const int kVisitorIdOffset = kInstanceSizesOffset + kVisitorIdByte; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6079 | |
| 6080 | // Byte offsets within kInstanceAttributesOffset attributes. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6081 | #if V8_TARGET_LITTLE_ENDIAN |
| 6082 | // Order instance type and bit field together such that they can be loaded |
| 6083 | // together as a 16-bit word with instance type in the lower 8 bits regardless |
| 6084 | // of endianess. Also provide endian-independent offset to that 16-bit word. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6085 | static const int kInstanceTypeOffset = kInstanceAttributesOffset + 0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6086 | static const int kBitFieldOffset = kInstanceAttributesOffset + 1; |
| 6087 | #else |
| 6088 | static const int kBitFieldOffset = kInstanceAttributesOffset + 0; |
| 6089 | static const int kInstanceTypeOffset = kInstanceAttributesOffset + 1; |
| 6090 | #endif |
| 6091 | static const int kInstanceTypeAndBitFieldOffset = |
| 6092 | kInstanceAttributesOffset + 0; |
| 6093 | static const int kBitField2Offset = kInstanceAttributesOffset + 2; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6094 | static const int kUnusedPropertyFieldsByte = 3; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6095 | static const int kUnusedPropertyFieldsOffset = kInstanceAttributesOffset + 3; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6096 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6097 | STATIC_ASSERT(kInstanceTypeAndBitFieldOffset == |
| 6098 | Internals::kMapInstanceTypeAndBitFieldOffset); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6099 | |
| 6100 | // Bit positions for bit field. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6101 | static const int kHasNonInstancePrototype = 0; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6102 | static const int kIsCallable = 1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6103 | static const int kHasNamedInterceptor = 2; |
| 6104 | static const int kHasIndexedInterceptor = 3; |
| 6105 | static const int kIsUndetectable = 4; |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 6106 | static const int kIsAccessCheckNeeded = 5; |
| 6107 | static const int kIsConstructor = 6; |
| 6108 | // Bit 7 is free. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6109 | |
| 6110 | // Bit positions for bit field 2 |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 6111 | static const int kIsExtensible = 0; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6112 | // Bit 1 is free. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6113 | class IsPrototypeMapBits : public BitField<bool, 2, 1> {}; |
| 6114 | class ElementsKindBits: public BitField<ElementsKind, 3, 5> {}; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6115 | |
| 6116 | // Derived values from bit field 2 |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6117 | static const int8_t kMaximumBitField2FastElementValue = static_cast<int8_t>( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6118 | (FAST_ELEMENTS + 1) << Map::ElementsKindBits::kShift) - 1; |
| 6119 | static const int8_t kMaximumBitField2FastSmiElementValue = |
| 6120 | static_cast<int8_t>((FAST_SMI_ELEMENTS + 1) << |
| 6121 | Map::ElementsKindBits::kShift) - 1; |
| 6122 | static const int8_t kMaximumBitField2FastHoleyElementValue = |
| 6123 | static_cast<int8_t>((FAST_HOLEY_ELEMENTS + 1) << |
| 6124 | Map::ElementsKindBits::kShift) - 1; |
| 6125 | static const int8_t kMaximumBitField2FastHoleySmiElementValue = |
| 6126 | static_cast<int8_t>((FAST_HOLEY_SMI_ELEMENTS + 1) << |
| 6127 | Map::ElementsKindBits::kShift) - 1; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6128 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 6129 | typedef FixedBodyDescriptor<kPointerFieldsBeginOffset, |
| 6130 | kPointerFieldsEndOffset, |
| 6131 | kSize> BodyDescriptor; |
| 6132 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6133 | // Compares this map to another to see if they describe equivalent objects. |
| 6134 | // If |mode| is set to CLEAR_INOBJECT_PROPERTIES, |other| is treated as if |
| 6135 | // it had exactly zero inobject properties. |
| 6136 | // The "shared" flags of both this map and |other| are ignored. |
| 6137 | bool EquivalentToForNormalization(Map* other, PropertyNormalizationMode mode); |
| 6138 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6139 | // Returns true if given field is unboxed double. |
| 6140 | inline bool IsUnboxedDoubleField(FieldIndex index); |
| 6141 | |
| 6142 | #if TRACE_MAPS |
| 6143 | static void TraceTransition(const char* what, Map* from, Map* to, Name* name); |
| 6144 | static void TraceAllTransitions(Map* map); |
| 6145 | #endif |
| 6146 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6147 | static inline Handle<Map> AddMissingTransitionsForTesting( |
| 6148 | Handle<Map> split_map, Handle<DescriptorArray> descriptors, |
| 6149 | Handle<LayoutDescriptor> full_layout_descriptor); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6150 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6151 | private: |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 6152 | // Returns the map that this (root) map transitions to if its elements_kind |
| 6153 | // is changed to |elements_kind|, or |nullptr| if no such map is cached yet. |
| 6154 | Map* LookupElementsTransitionMap(ElementsKind elements_kind); |
| 6155 | |
| 6156 | // Tries to replay property transitions starting from this (root) map using |
| 6157 | // the descriptor array of the |map|. The |root_map| is expected to have |
| 6158 | // proper elements kind and therefore elements kinds transitions are not |
| 6159 | // taken by this function. Returns |nullptr| if matching transition map is |
| 6160 | // not found. |
| 6161 | Map* TryReplayPropertyTransitions(Map* map); |
| 6162 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6163 | static void ConnectTransition(Handle<Map> parent, Handle<Map> child, |
| 6164 | Handle<Name> name, SimpleTransitionFlag flag); |
| 6165 | |
| 6166 | bool EquivalentToForTransition(Map* other); |
| 6167 | static Handle<Map> RawCopy(Handle<Map> map, int instance_size); |
| 6168 | static Handle<Map> ShareDescriptor(Handle<Map> map, |
| 6169 | Handle<DescriptorArray> descriptors, |
| 6170 | Descriptor* descriptor); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6171 | static Handle<Map> AddMissingTransitions( |
| 6172 | Handle<Map> map, Handle<DescriptorArray> descriptors, |
| 6173 | Handle<LayoutDescriptor> full_layout_descriptor); |
| 6174 | static void InstallDescriptors( |
| 6175 | Handle<Map> parent_map, Handle<Map> child_map, int new_descriptor, |
| 6176 | Handle<DescriptorArray> descriptors, |
| 6177 | Handle<LayoutDescriptor> full_layout_descriptor); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6178 | static Handle<Map> CopyAddDescriptor(Handle<Map> map, |
| 6179 | Descriptor* descriptor, |
| 6180 | TransitionFlag flag); |
| 6181 | static Handle<Map> CopyReplaceDescriptors( |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6182 | Handle<Map> map, Handle<DescriptorArray> descriptors, |
| 6183 | Handle<LayoutDescriptor> layout_descriptor, TransitionFlag flag, |
| 6184 | MaybeHandle<Name> maybe_name, const char* reason, |
| 6185 | SimpleTransitionFlag simple_flag); |
| 6186 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6187 | static Handle<Map> CopyReplaceDescriptor(Handle<Map> map, |
| 6188 | Handle<DescriptorArray> descriptors, |
| 6189 | Descriptor* descriptor, |
| 6190 | int index, |
| 6191 | TransitionFlag flag); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6192 | static MUST_USE_RESULT MaybeHandle<Map> TryReconfigureExistingProperty( |
| 6193 | Handle<Map> map, int descriptor, PropertyKind kind, |
| 6194 | PropertyAttributes attributes, const char** reason); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6195 | |
| 6196 | static Handle<Map> CopyNormalized(Handle<Map> map, |
| 6197 | PropertyNormalizationMode mode); |
| 6198 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 6199 | static Handle<Map> Reconfigure(Handle<Map> map, |
| 6200 | ElementsKind new_elements_kind, |
| 6201 | int modify_index, PropertyKind new_kind, |
| 6202 | PropertyAttributes new_attributes, |
| 6203 | Representation new_representation, |
| 6204 | Handle<FieldType> new_field_type, |
| 6205 | StoreMode store_mode); |
| 6206 | |
| 6207 | static Handle<Map> CopyGeneralizeAllRepresentations( |
| 6208 | Handle<Map> map, ElementsKind elements_kind, int modify_index, |
| 6209 | StoreMode store_mode, PropertyKind kind, PropertyAttributes attributes, |
| 6210 | const char* reason); |
| 6211 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6212 | // Fires when the layout of an object with a leaf map changes. |
| 6213 | // This includes adding transitions to the leaf map or changing |
| 6214 | // the descriptor array. |
| 6215 | inline void NotifyLeafMapLayoutChange(); |
| 6216 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6217 | void DeprecateTransitionTree(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6218 | |
| 6219 | void ReplaceDescriptors(DescriptorArray* new_descriptors, |
| 6220 | LayoutDescriptor* new_layout_descriptor); |
| 6221 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6222 | |
| 6223 | Map* FindLastMatchMap(int verbatim, int length, DescriptorArray* descriptors); |
| 6224 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6225 | // Update field type of the given descriptor to new representation and new |
| 6226 | // type. The type must be prepared for storing in descriptor array: |
| 6227 | // it must be either a simple type or a map wrapped in a weak cell. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6228 | void UpdateFieldType(int descriptor_number, Handle<Name> name, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6229 | Representation new_representation, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6230 | Handle<Object> new_wrapped_type); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6231 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6232 | void PrintReconfiguration(FILE* file, int modify_index, PropertyKind kind, |
| 6233 | PropertyAttributes attributes); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 6234 | void PrintGeneralization(FILE* file, const char* reason, int modify_index, |
| 6235 | int split, int descriptors, bool constant_to_field, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6236 | Representation old_representation, |
| 6237 | Representation new_representation, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 6238 | MaybeHandle<FieldType> old_field_type, |
| 6239 | MaybeHandle<Object> old_value, |
| 6240 | MaybeHandle<FieldType> new_field_type, |
| 6241 | MaybeHandle<Object> new_value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6242 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6243 | static const int kFastPropertiesSoftLimit = 12; |
| 6244 | static const int kMaxFastProperties = 128; |
| 6245 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6246 | DISALLOW_IMPLICIT_CONSTRUCTORS(Map); |
| 6247 | }; |
| 6248 | |
| 6249 | |
| 6250 | // An abstract superclass, a marker class really, for simple structure classes. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6251 | // It doesn't carry much functionality but allows struct classes to be |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6252 | // identified in the type system. |
| 6253 | class Struct: public HeapObject { |
| 6254 | public: |
| 6255 | inline void InitializeBody(int object_size); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6256 | DECLARE_CAST(Struct) |
| 6257 | }; |
| 6258 | |
| 6259 | |
| 6260 | // A simple one-element struct, useful where smis need to be boxed. |
| 6261 | class Box : public Struct { |
| 6262 | public: |
| 6263 | // [value]: the boxed contents. |
| 6264 | DECL_ACCESSORS(value, Object) |
| 6265 | |
| 6266 | DECLARE_CAST(Box) |
| 6267 | |
| 6268 | // Dispatched behavior. |
| 6269 | DECLARE_PRINTER(Box) |
| 6270 | DECLARE_VERIFIER(Box) |
| 6271 | |
| 6272 | static const int kValueOffset = HeapObject::kHeaderSize; |
| 6273 | static const int kSize = kValueOffset + kPointerSize; |
| 6274 | |
| 6275 | private: |
| 6276 | DISALLOW_IMPLICIT_CONSTRUCTORS(Box); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6277 | }; |
| 6278 | |
| 6279 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6280 | // Container for metadata stored on each prototype map. |
| 6281 | class PrototypeInfo : public Struct { |
| 6282 | public: |
| 6283 | static const int UNREGISTERED = -1; |
| 6284 | |
| 6285 | // [prototype_users]: WeakFixedArray containing maps using this prototype, |
| 6286 | // or Smi(0) if uninitialized. |
| 6287 | DECL_ACCESSORS(prototype_users, Object) |
| 6288 | // [registry_slot]: Slot in prototype's user registry where this user |
| 6289 | // is stored. Returns UNREGISTERED if this prototype has not been registered. |
| 6290 | inline int registry_slot() const; |
| 6291 | inline void set_registry_slot(int slot); |
| 6292 | // [validity_cell]: Cell containing the validity bit for prototype chains |
| 6293 | // going through this object, or Smi(0) if uninitialized. |
| 6294 | // When a prototype object changes its map, then both its own validity cell |
| 6295 | // and those of all "downstream" prototypes are invalidated; handlers for a |
| 6296 | // given receiver embed the currently valid cell for that receiver's prototype |
| 6297 | // during their compilation and check it on execution. |
| 6298 | DECL_ACCESSORS(validity_cell, Object) |
| 6299 | |
| 6300 | DECLARE_CAST(PrototypeInfo) |
| 6301 | |
| 6302 | // Dispatched behavior. |
| 6303 | DECLARE_PRINTER(PrototypeInfo) |
| 6304 | DECLARE_VERIFIER(PrototypeInfo) |
| 6305 | |
| 6306 | static const int kPrototypeUsersOffset = HeapObject::kHeaderSize; |
| 6307 | static const int kRegistrySlotOffset = kPrototypeUsersOffset + kPointerSize; |
| 6308 | static const int kValidityCellOffset = kRegistrySlotOffset + kPointerSize; |
| 6309 | static const int kConstructorNameOffset = kValidityCellOffset + kPointerSize; |
| 6310 | static const int kSize = kConstructorNameOffset + kPointerSize; |
| 6311 | |
| 6312 | private: |
| 6313 | DISALLOW_IMPLICIT_CONSTRUCTORS(PrototypeInfo); |
| 6314 | }; |
| 6315 | |
| 6316 | |
| 6317 | // Pair used to store both a ScopeInfo and an extension object in the extension |
| 6318 | // slot of a block context. Needed in the rare case where a declaration block |
| 6319 | // scope (a "varblock" as used to desugar parameter destructuring) also contains |
| 6320 | // a sloppy direct eval. (In no other case both are needed at the same time.) |
| 6321 | class SloppyBlockWithEvalContextExtension : public Struct { |
| 6322 | public: |
| 6323 | // [scope_info]: Scope info. |
| 6324 | DECL_ACCESSORS(scope_info, ScopeInfo) |
| 6325 | // [extension]: Extension object. |
| 6326 | DECL_ACCESSORS(extension, JSObject) |
| 6327 | |
| 6328 | DECLARE_CAST(SloppyBlockWithEvalContextExtension) |
| 6329 | |
| 6330 | // Dispatched behavior. |
| 6331 | DECLARE_PRINTER(SloppyBlockWithEvalContextExtension) |
| 6332 | DECLARE_VERIFIER(SloppyBlockWithEvalContextExtension) |
| 6333 | |
| 6334 | static const int kScopeInfoOffset = HeapObject::kHeaderSize; |
| 6335 | static const int kExtensionOffset = kScopeInfoOffset + kPointerSize; |
| 6336 | static const int kSize = kExtensionOffset + kPointerSize; |
| 6337 | |
| 6338 | private: |
| 6339 | DISALLOW_IMPLICIT_CONSTRUCTORS(SloppyBlockWithEvalContextExtension); |
| 6340 | }; |
| 6341 | |
| 6342 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6343 | // Script describes a script which has been added to the VM. |
| 6344 | class Script: public Struct { |
| 6345 | public: |
| 6346 | // Script types. |
| 6347 | enum Type { |
| 6348 | TYPE_NATIVE = 0, |
| 6349 | TYPE_EXTENSION = 1, |
| 6350 | TYPE_NORMAL = 2 |
| 6351 | }; |
| 6352 | |
| 6353 | // Script compilation types. |
| 6354 | enum CompilationType { |
| 6355 | COMPILATION_TYPE_HOST = 0, |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 6356 | COMPILATION_TYPE_EVAL = 1 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6357 | }; |
| 6358 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 6359 | // Script compilation state. |
| 6360 | enum CompilationState { |
| 6361 | COMPILATION_STATE_INITIAL = 0, |
| 6362 | COMPILATION_STATE_COMPILED = 1 |
| 6363 | }; |
| 6364 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6365 | // [source]: the script source. |
| 6366 | DECL_ACCESSORS(source, Object) |
| 6367 | |
| 6368 | // [name]: the script name. |
| 6369 | DECL_ACCESSORS(name, Object) |
| 6370 | |
| 6371 | // [id]: the script id. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6372 | DECL_INT_ACCESSORS(id) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6373 | |
| 6374 | // [line_offset]: script line offset in resource from where it was extracted. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6375 | DECL_INT_ACCESSORS(line_offset) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6376 | |
| 6377 | // [column_offset]: script column offset in resource from where it was |
| 6378 | // extracted. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6379 | DECL_INT_ACCESSORS(column_offset) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6380 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6381 | // [context_data]: context data for the context this script was compiled in. |
| 6382 | DECL_ACCESSORS(context_data, Object) |
| 6383 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6384 | // [wrapper]: the wrapper cache. This is either undefined or a WeakCell. |
| 6385 | DECL_ACCESSORS(wrapper, HeapObject) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6386 | |
| 6387 | // [type]: the script type. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6388 | DECL_INT_ACCESSORS(type) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6389 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6390 | // [line_ends]: FixedArray of line ends positions. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6391 | DECL_ACCESSORS(line_ends, Object) |
| 6392 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 6393 | // [eval_from_shared]: for eval scripts the shared function info for the |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6394 | // function from which eval was called. |
| 6395 | DECL_ACCESSORS(eval_from_shared, Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6396 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 6397 | // [eval_from_position]: the source position in the code for the function |
| 6398 | // from which eval was called, as positive integer. Or the code offset in the |
| 6399 | // code from which eval was called, as negative integer. |
| 6400 | DECL_INT_ACCESSORS(eval_from_position) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6401 | |
| 6402 | // [shared_function_infos]: weak fixed array containing all shared |
| 6403 | // function infos created from this script. |
| 6404 | DECL_ACCESSORS(shared_function_infos, Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6405 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6406 | // [flags]: Holds an exciting bitfield. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6407 | DECL_INT_ACCESSORS(flags) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6408 | |
| 6409 | // [source_url]: sourceURL from magic comment |
| 6410 | DECL_ACCESSORS(source_url, Object) |
| 6411 | |
| 6412 | // [source_url]: sourceMappingURL magic comment |
| 6413 | DECL_ACCESSORS(source_mapping_url, Object) |
| 6414 | |
| 6415 | // [compilation_type]: how the the script was compiled. Encoded in the |
| 6416 | // 'flags' field. |
| 6417 | inline CompilationType compilation_type(); |
| 6418 | inline void set_compilation_type(CompilationType type); |
| 6419 | |
| 6420 | // [compilation_state]: determines whether the script has already been |
| 6421 | // compiled. Encoded in the 'flags' field. |
| 6422 | inline CompilationState compilation_state(); |
| 6423 | inline void set_compilation_state(CompilationState state); |
| 6424 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6425 | // [hide_source]: determines whether the script source can be exposed as |
| 6426 | // function source. Encoded in the 'flags' field. |
| 6427 | inline bool hide_source(); |
| 6428 | inline void set_hide_source(bool value); |
| 6429 | |
| 6430 | // [origin_options]: optional attributes set by the embedder via ScriptOrigin, |
| 6431 | // and used by the embedder to make decisions about the script. V8 just passes |
| 6432 | // this through. Encoded in the 'flags' field. |
| 6433 | inline v8::ScriptOriginOptions origin_options(); |
| 6434 | inline void set_origin_options(ScriptOriginOptions origin_options); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6435 | |
| 6436 | DECLARE_CAST(Script) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6437 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 6438 | // If script source is an external string, check that the underlying |
| 6439 | // resource is accessible. Otherwise, always return true. |
| 6440 | inline bool HasValidSource(); |
| 6441 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 6442 | // Convert code offset into column number. |
| 6443 | static int GetColumnNumber(Handle<Script> script, int code_offset); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6444 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 6445 | // Convert code offset into (zero-based) line number. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6446 | // The non-handlified version does not allocate, but may be much slower. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 6447 | static int GetLineNumber(Handle<Script> script, int code_offset); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6448 | int GetLineNumber(int code_pos); |
| 6449 | |
| 6450 | static Handle<Object> GetNameOrSourceURL(Handle<Script> script); |
| 6451 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 6452 | // Set eval origin for stack trace formatting. |
| 6453 | static void SetEvalOrigin(Handle<Script> script, |
| 6454 | Handle<SharedFunctionInfo> outer, |
| 6455 | int eval_position); |
| 6456 | // Retrieve source position from where eval was called. |
| 6457 | int GetEvalPosition(); |
| 6458 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 6459 | // Init line_ends array with source code positions of line ends. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6460 | static void InitLineEnds(Handle<Script> script); |
| 6461 | |
| 6462 | // Get the JS object wrapping the given script; create it if none exists. |
| 6463 | static Handle<JSObject> GetWrapper(Handle<Script> script); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6464 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6465 | // Look through the list of existing shared function infos to find one |
| 6466 | // that matches the function literal. Return empty handle if not found. |
| 6467 | MaybeHandle<SharedFunctionInfo> FindSharedFunctionInfo(FunctionLiteral* fun); |
| 6468 | |
| 6469 | // Iterate over all script objects on the heap. |
| 6470 | class Iterator { |
| 6471 | public: |
| 6472 | explicit Iterator(Isolate* isolate); |
| 6473 | Script* Next(); |
| 6474 | |
| 6475 | private: |
| 6476 | WeakFixedArray::Iterator iterator_; |
| 6477 | DISALLOW_COPY_AND_ASSIGN(Iterator); |
| 6478 | }; |
| 6479 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6480 | // Dispatched behavior. |
| 6481 | DECLARE_PRINTER(Script) |
| 6482 | DECLARE_VERIFIER(Script) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6483 | |
| 6484 | static const int kSourceOffset = HeapObject::kHeaderSize; |
| 6485 | static const int kNameOffset = kSourceOffset + kPointerSize; |
| 6486 | static const int kLineOffsetOffset = kNameOffset + kPointerSize; |
| 6487 | static const int kColumnOffsetOffset = kLineOffsetOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6488 | static const int kContextOffset = kColumnOffsetOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6489 | static const int kWrapperOffset = kContextOffset + kPointerSize; |
| 6490 | static const int kTypeOffset = kWrapperOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6491 | static const int kLineEndsOffset = kTypeOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6492 | static const int kIdOffset = kLineEndsOffset + kPointerSize; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6493 | static const int kEvalFromSharedOffset = kIdOffset + kPointerSize; |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 6494 | static const int kEvalFromPositionOffset = |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6495 | kEvalFromSharedOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6496 | static const int kSharedFunctionInfosOffset = |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 6497 | kEvalFromPositionOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6498 | static const int kFlagsOffset = kSharedFunctionInfosOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6499 | static const int kSourceUrlOffset = kFlagsOffset + kPointerSize; |
| 6500 | static const int kSourceMappingUrlOffset = kSourceUrlOffset + kPointerSize; |
| 6501 | static const int kSize = kSourceMappingUrlOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6502 | |
| 6503 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6504 | int GetLineNumberWithArray(int code_pos); |
| 6505 | |
| 6506 | // Bit positions in the flags field. |
| 6507 | static const int kCompilationTypeBit = 0; |
| 6508 | static const int kCompilationStateBit = 1; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6509 | static const int kHideSourceBit = 2; |
| 6510 | static const int kOriginOptionsShift = 3; |
| 6511 | static const int kOriginOptionsSize = 3; |
| 6512 | static const int kOriginOptionsMask = ((1 << kOriginOptionsSize) - 1) |
| 6513 | << kOriginOptionsShift; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6514 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6515 | DISALLOW_IMPLICIT_CONSTRUCTORS(Script); |
| 6516 | }; |
| 6517 | |
| 6518 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6519 | // List of builtin functions we want to identify to improve code |
| 6520 | // generation. |
| 6521 | // |
| 6522 | // Each entry has a name of a global object property holding an object |
| 6523 | // optionally followed by ".prototype", a name of a builtin function |
| 6524 | // on the object (the one the id is set for), and a label. |
| 6525 | // |
| 6526 | // Installation of ids for the selected builtin functions is handled |
| 6527 | // by the bootstrapper. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 6528 | #define FUNCTIONS_WITH_ID_LIST(V) \ |
| 6529 | V(Array.prototype, indexOf, ArrayIndexOf) \ |
| 6530 | V(Array.prototype, lastIndexOf, ArrayLastIndexOf) \ |
| 6531 | V(Array.prototype, push, ArrayPush) \ |
| 6532 | V(Array.prototype, pop, ArrayPop) \ |
| 6533 | V(Array.prototype, shift, ArrayShift) \ |
| 6534 | V(Function.prototype, apply, FunctionApply) \ |
| 6535 | V(Function.prototype, call, FunctionCall) \ |
| 6536 | V(Object.prototype, hasOwnProperty, ObjectHasOwnProperty) \ |
| 6537 | V(String.prototype, charCodeAt, StringCharCodeAt) \ |
| 6538 | V(String.prototype, charAt, StringCharAt) \ |
| 6539 | V(String.prototype, concat, StringConcat) \ |
| 6540 | V(String.prototype, toLowerCase, StringToLowerCase) \ |
| 6541 | V(String.prototype, toUpperCase, StringToUpperCase) \ |
| 6542 | V(String, fromCharCode, StringFromCharCode) \ |
| 6543 | V(Math, random, MathRandom) \ |
| 6544 | V(Math, floor, MathFloor) \ |
| 6545 | V(Math, round, MathRound) \ |
| 6546 | V(Math, ceil, MathCeil) \ |
| 6547 | V(Math, abs, MathAbs) \ |
| 6548 | V(Math, log, MathLog) \ |
| 6549 | V(Math, exp, MathExp) \ |
| 6550 | V(Math, sqrt, MathSqrt) \ |
| 6551 | V(Math, pow, MathPow) \ |
| 6552 | V(Math, max, MathMax) \ |
| 6553 | V(Math, min, MathMin) \ |
| 6554 | V(Math, cos, MathCos) \ |
| 6555 | V(Math, sin, MathSin) \ |
| 6556 | V(Math, tan, MathTan) \ |
| 6557 | V(Math, acos, MathAcos) \ |
| 6558 | V(Math, asin, MathAsin) \ |
| 6559 | V(Math, atan, MathAtan) \ |
| 6560 | V(Math, atan2, MathAtan2) \ |
| 6561 | V(Math, imul, MathImul) \ |
| 6562 | V(Math, clz32, MathClz32) \ |
| 6563 | V(Math, fround, MathFround) \ |
| 6564 | V(Math, trunc, MathTrunc) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6565 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6566 | #define ATOMIC_FUNCTIONS_WITH_ID_LIST(V) \ |
| 6567 | V(Atomics, load, AtomicsLoad) \ |
| 6568 | V(Atomics, store, AtomicsStore) |
| 6569 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6570 | enum BuiltinFunctionId { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6571 | kArrayCode, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6572 | #define DECLARE_FUNCTION_ID(ignored1, ignore2, name) \ |
| 6573 | k##name, |
| 6574 | FUNCTIONS_WITH_ID_LIST(DECLARE_FUNCTION_ID) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6575 | ATOMIC_FUNCTIONS_WITH_ID_LIST(DECLARE_FUNCTION_ID) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6576 | #undef DECLARE_FUNCTION_ID |
| 6577 | // Fake id for a special case of Math.pow. Note, it continues the |
| 6578 | // list of math functions. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6579 | kMathPowHalf |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6580 | }; |
| 6581 | |
| 6582 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6583 | // Result of searching in an optimized code map of a SharedFunctionInfo. Note |
| 6584 | // that both {code} and {literals} can be NULL to pass search result status. |
| 6585 | struct CodeAndLiterals { |
| 6586 | Code* code; // Cached optimized code. |
| 6587 | LiteralsArray* literals; // Cached literals array. |
| 6588 | }; |
| 6589 | |
| 6590 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6591 | // SharedFunctionInfo describes the JSFunction information that can be |
| 6592 | // shared by multiple instances of the function. |
| 6593 | class SharedFunctionInfo: public HeapObject { |
| 6594 | public: |
| 6595 | // [name]: Function name. |
| 6596 | DECL_ACCESSORS(name, Object) |
| 6597 | |
| 6598 | // [code]: Function code. |
| 6599 | DECL_ACCESSORS(code, Code) |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 6600 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 6601 | // Get the abstract code associated with the function, which will either be |
| 6602 | // a Code object or a BytecodeArray. |
| 6603 | inline AbstractCode* abstract_code(); |
| 6604 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6605 | inline void ReplaceCode(Code* code); |
| 6606 | |
| 6607 | // [optimized_code_map]: Map from native context to optimized code |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6608 | // and a shared literals array. |
| 6609 | DECL_ACCESSORS(optimized_code_map, FixedArray) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6610 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6611 | // Returns entry from optimized code map for specified context and OSR entry. |
| 6612 | // Note that {code == nullptr, literals == nullptr} indicates no matching |
| 6613 | // entry has been found, whereas {code, literals == nullptr} indicates that |
| 6614 | // code is context-independent. |
| 6615 | CodeAndLiterals SearchOptimizedCodeMap(Context* native_context, |
| 6616 | BailoutId osr_ast_id); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6617 | |
| 6618 | // Clear optimized code map. |
| 6619 | void ClearOptimizedCodeMap(); |
| 6620 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6621 | // We have a special root FixedArray with the right shape and values |
| 6622 | // to represent the cleared optimized code map. This predicate checks |
| 6623 | // if that root is installed. |
| 6624 | inline bool OptimizedCodeMapIsCleared() const; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6625 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6626 | // Removes a specific optimized code object from the optimized code map. |
| 6627 | // In case of non-OSR the code reference is cleared from the cache entry but |
| 6628 | // the entry itself is left in the map in order to proceed sharing literals. |
| 6629 | void EvictFromOptimizedCodeMap(Code* optimized_code, const char* reason); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6630 | |
| 6631 | // Trims the optimized code map after entries have been removed. |
| 6632 | void TrimOptimizedCodeMap(int shrink_by); |
| 6633 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 6634 | // Add or update entry in the optimized code map for context-independent code. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6635 | static void AddSharedCodeToOptimizedCodeMap(Handle<SharedFunctionInfo> shared, |
| 6636 | Handle<Code> code); |
| 6637 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 6638 | // Add or update entry in the optimized code map for context-dependent code. |
| 6639 | // If {code} is not given, then an existing entry's code won't be overwritten. |
| 6640 | static void AddToOptimizedCodeMap(Handle<SharedFunctionInfo> shared, |
| 6641 | Handle<Context> native_context, |
| 6642 | MaybeHandle<Code> code, |
| 6643 | Handle<LiteralsArray> literals, |
| 6644 | BailoutId osr_ast_id); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6645 | |
| 6646 | // Set up the link between shared function info and the script. The shared |
| 6647 | // function info is added to the list on the script. |
| 6648 | static void SetScript(Handle<SharedFunctionInfo> shared, |
| 6649 | Handle<Object> script_object); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6650 | |
| 6651 | // Layout description of the optimized code map. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6652 | static const int kSharedCodeIndex = 0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6653 | static const int kEntriesStart = 1; |
| 6654 | static const int kContextOffset = 0; |
| 6655 | static const int kCachedCodeOffset = 1; |
| 6656 | static const int kLiteralsOffset = 2; |
| 6657 | static const int kOsrAstIdOffset = 3; |
| 6658 | static const int kEntryLength = 4; |
| 6659 | static const int kInitialLength = kEntriesStart + kEntryLength; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6660 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6661 | static const int kNotFound = -1; |
| 6662 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 6663 | // Helpers for assembly code that does a backwards walk of the optimized code |
| 6664 | // map. |
| 6665 | static const int kOffsetToPreviousContext = |
| 6666 | FixedArray::kHeaderSize + kPointerSize * (kContextOffset - kEntryLength); |
| 6667 | static const int kOffsetToPreviousCachedCode = |
| 6668 | FixedArray::kHeaderSize + |
| 6669 | kPointerSize * (kCachedCodeOffset - kEntryLength); |
| 6670 | static const int kOffsetToPreviousLiterals = |
| 6671 | FixedArray::kHeaderSize + kPointerSize * (kLiteralsOffset - kEntryLength); |
| 6672 | static const int kOffsetToPreviousOsrAstId = |
| 6673 | FixedArray::kHeaderSize + kPointerSize * (kOsrAstIdOffset - kEntryLength); |
| 6674 | |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 6675 | // [scope_info]: Scope info. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 6676 | DECL_ACCESSORS(scope_info, ScopeInfo) |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 6677 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6678 | // [construct stub]: Code stub for constructing instances of this function. |
| 6679 | DECL_ACCESSORS(construct_stub, Code) |
| 6680 | |
| 6681 | // Returns if this function has been compiled to native code yet. |
| 6682 | inline bool is_compiled(); |
| 6683 | |
| 6684 | // [length]: The function length - usually the number of declared parameters. |
| 6685 | // Use up to 2^30 parameters. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6686 | inline int length() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6687 | inline void set_length(int value); |
| 6688 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6689 | // [internal formal parameter count]: The declared number of parameters. |
| 6690 | // For subclass constructors, also includes new.target. |
| 6691 | // The size of function's frame is internal_formal_parameter_count + 1. |
| 6692 | inline int internal_formal_parameter_count() const; |
| 6693 | inline void set_internal_formal_parameter_count(int value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6694 | |
| 6695 | // Set the formal parameter count so the function code will be |
| 6696 | // called without using argument adaptor frames. |
| 6697 | inline void DontAdaptArguments(); |
| 6698 | |
| 6699 | // [expected_nof_properties]: Expected number of properties for the function. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6700 | inline int expected_nof_properties() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6701 | inline void set_expected_nof_properties(int value); |
| 6702 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6703 | // [feedback_vector] - accumulates ast node feedback from full-codegen and |
| 6704 | // (increasingly) from crankshafted code where sufficient feedback isn't |
| 6705 | // available. |
| 6706 | DECL_ACCESSORS(feedback_vector, TypeFeedbackVector) |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 6707 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6708 | // Unconditionally clear the type feedback vector (including vector ICs). |
| 6709 | void ClearTypeFeedbackInfo(); |
| 6710 | |
| 6711 | // Clear the type feedback vector with a more subtle policy at GC time. |
| 6712 | void ClearTypeFeedbackInfoAtGCTime(); |
| 6713 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6714 | #if TRACE_MAPS |
| 6715 | // [unique_id] - For --trace-maps purposes, an identifier that's persistent |
| 6716 | // even if the GC moves this SharedFunctionInfo. |
| 6717 | inline int unique_id() const; |
| 6718 | inline void set_unique_id(int value); |
| 6719 | #endif |
| 6720 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6721 | // [instance class name]: class name for instances. |
| 6722 | DECL_ACCESSORS(instance_class_name, Object) |
| 6723 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 6724 | // [function data]: This field holds some additional data for function. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6725 | // Currently it has one of: |
| 6726 | // - a FunctionTemplateInfo to make benefit the API [IsApiFunction()]. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6727 | // - a BytecodeArray for the interpreter [HasBytecodeArray()]. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6728 | DECL_ACCESSORS(function_data, Object) |
| 6729 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 6730 | inline bool IsApiFunction(); |
| 6731 | inline FunctionTemplateInfo* get_api_func_data(); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 6732 | inline void set_api_func_data(FunctionTemplateInfo* data); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6733 | inline bool HasBytecodeArray(); |
| 6734 | inline BytecodeArray* bytecode_array(); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 6735 | inline void set_bytecode_array(BytecodeArray* bytecode); |
| 6736 | inline void ClearBytecodeArray(); |
| 6737 | |
| 6738 | // [function identifier]: This field holds an additional identifier for the |
| 6739 | // function. |
| 6740 | // - a Smi identifying a builtin function [HasBuiltinFunctionId()]. |
| 6741 | // - a String identifying the function's inferred name [HasInferredName()]. |
| 6742 | // The inferred_name is inferred from variable or property |
| 6743 | // assignment of this function. It is used to facilitate debugging and |
| 6744 | // profiling of JavaScript code written in OO style, where almost |
| 6745 | // all functions are anonymous but are assigned to object |
| 6746 | // properties. |
| 6747 | DECL_ACCESSORS(function_identifier, Object) |
| 6748 | |
| 6749 | inline bool HasBuiltinFunctionId(); |
| 6750 | inline BuiltinFunctionId builtin_function_id(); |
| 6751 | inline void set_builtin_function_id(BuiltinFunctionId id); |
| 6752 | inline bool HasInferredName(); |
| 6753 | inline String* inferred_name(); |
| 6754 | inline void set_inferred_name(String* inferred_name); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 6755 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6756 | // [script info]: Script from which the function originates. |
| 6757 | DECL_ACCESSORS(script, Object) |
| 6758 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 6759 | // [num_literals]: Number of literals used by this function. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6760 | inline int num_literals() const; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 6761 | inline void set_num_literals(int value); |
| 6762 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6763 | // [start_position_and_type]: Field used to store both the source code |
| 6764 | // position, whether or not the function is a function expression, |
| 6765 | // and whether or not the function is a toplevel function. The two |
| 6766 | // least significants bit indicates whether the function is an |
| 6767 | // expression and the rest contains the source code position. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6768 | inline int start_position_and_type() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6769 | inline void set_start_position_and_type(int value); |
| 6770 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6771 | // The function is subject to debugging if a debug info is attached. |
| 6772 | inline bool HasDebugInfo(); |
| 6773 | inline DebugInfo* GetDebugInfo(); |
| 6774 | |
| 6775 | // A function has debug code if the compiled code has debug break slots. |
| 6776 | inline bool HasDebugCode(); |
| 6777 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6778 | // [debug info]: Debug information. |
| 6779 | DECL_ACCESSORS(debug_info, Object) |
| 6780 | |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 6781 | // The function's name if it is non-empty, otherwise the inferred name. |
| 6782 | String* DebugName(); |
| 6783 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 6784 | // Used for flags such as --hydrogen-filter. |
| 6785 | bool PassesFilter(const char* raw_filter); |
| 6786 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6787 | // Position of the 'function' token in the script source. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6788 | inline int function_token_position() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6789 | inline void set_function_token_position(int function_token_position); |
| 6790 | |
| 6791 | // Position of this function in the script source. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6792 | inline int start_position() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6793 | inline void set_start_position(int start_position); |
| 6794 | |
| 6795 | // End position of this function in the script source. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6796 | inline int end_position() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6797 | inline void set_end_position(int end_position); |
| 6798 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 6799 | // Is this function a named function expression in the source code. |
| 6800 | DECL_BOOLEAN_ACCESSORS(is_named_expression) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6801 | |
| 6802 | // Is this function a top-level function (scripts, evals). |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6803 | DECL_BOOLEAN_ACCESSORS(is_toplevel) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6804 | |
| 6805 | // Bit field containing various information collected by the compiler to |
| 6806 | // drive optimization. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6807 | inline int compiler_hints() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6808 | inline void set_compiler_hints(int value); |
| 6809 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6810 | inline int ast_node_count() const; |
Ben Murdoch | 8f9999f | 2012-04-23 10:39:17 +0100 | [diff] [blame] | 6811 | inline void set_ast_node_count(int count); |
| 6812 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6813 | inline int profiler_ticks() const; |
| 6814 | inline void set_profiler_ticks(int ticks); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 6815 | |
Ben Murdoch | 8f9999f | 2012-04-23 10:39:17 +0100 | [diff] [blame] | 6816 | // Inline cache age is used to infer whether the function survived a context |
| 6817 | // disposal or not. In the former case we reset the opt_count. |
| 6818 | inline int ic_age(); |
| 6819 | inline void set_ic_age(int age); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6820 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 6821 | // Indicates if this function can be lazy compiled. |
| 6822 | // This is used to determine if we can safely flush code from a function |
| 6823 | // when doing GC if we expect that the function will no longer be used. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6824 | DECL_BOOLEAN_ACCESSORS(allows_lazy_compilation) |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 6825 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6826 | // Indicates if this function can be lazy compiled without a context. |
| 6827 | // This is used to determine if we can force compilation without reaching |
| 6828 | // the function through program execution but through other means (e.g. heap |
| 6829 | // iteration by the debugger). |
| 6830 | DECL_BOOLEAN_ACCESSORS(allows_lazy_compilation_without_context) |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 6831 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6832 | // Indicates whether optimizations have been disabled for this |
| 6833 | // shared function info. If a function is repeatedly optimized or if |
| 6834 | // we cannot optimize the function we disable optimization to avoid |
| 6835 | // spending time attempting to optimize it again. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6836 | DECL_BOOLEAN_ACCESSORS(optimization_disabled) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6837 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6838 | // Indicates the language mode. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6839 | inline LanguageMode language_mode(); |
| 6840 | inline void set_language_mode(LanguageMode language_mode); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 6841 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6842 | // False if the function definitely does not allocate an arguments object. |
| 6843 | DECL_BOOLEAN_ACCESSORS(uses_arguments) |
| 6844 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6845 | // Indicates that this function uses a super property (or an eval that may |
| 6846 | // use a super property). |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6847 | // This is needed to set up the [[HomeObject]] on the function instance. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6848 | DECL_BOOLEAN_ACCESSORS(needs_home_object) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6849 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6850 | // True if the function has any duplicated parameter names. |
| 6851 | DECL_BOOLEAN_ACCESSORS(has_duplicate_parameters) |
| 6852 | |
| 6853 | // Indicates whether the function is a native function. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 6854 | // These needs special treatment in .call and .apply since |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6855 | // null passed as the receiver should not be translated to the |
| 6856 | // global object. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6857 | DECL_BOOLEAN_ACCESSORS(native) |
| 6858 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6859 | // Indicate that this function should always be inlined in optimized code. |
| 6860 | DECL_BOOLEAN_ACCESSORS(force_inline) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6861 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6862 | // Indicates that the function was created by the Function function. |
| 6863 | // Though it's anonymous, toString should treat it as if it had the name |
| 6864 | // "anonymous". We don't set the name itself so that the system does not |
| 6865 | // see a binding for it. |
| 6866 | DECL_BOOLEAN_ACCESSORS(name_should_print_as_anonymous) |
| 6867 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 6868 | // Indicates that the function is either an anonymous expression |
| 6869 | // or an arrow function (the name field can be set through the API, |
| 6870 | // which does not change this flag). |
| 6871 | DECL_BOOLEAN_ACCESSORS(is_anonymous_expression) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6872 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 6873 | // Is this a function or top-level/eval code. |
| 6874 | DECL_BOOLEAN_ACCESSORS(is_function) |
| 6875 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6876 | // Indicates that code for this function cannot be compiled with Crankshaft. |
| 6877 | DECL_BOOLEAN_ACCESSORS(dont_crankshaft) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 6878 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6879 | // Indicates that code for this function cannot be flushed. |
| 6880 | DECL_BOOLEAN_ACCESSORS(dont_flush) |
| 6881 | |
| 6882 | // Indicates that this function is a generator. |
| 6883 | DECL_BOOLEAN_ACCESSORS(is_generator) |
| 6884 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 6885 | // Indicates that this function is an async function. |
| 6886 | DECL_BOOLEAN_ACCESSORS(is_async) |
| 6887 | |
| 6888 | // Indicates that this function can be suspended, either via YieldExpressions |
| 6889 | // or AwaitExpressions. |
| 6890 | inline bool is_resumable() const; |
| 6891 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6892 | // Indicates that this function is an arrow function. |
| 6893 | DECL_BOOLEAN_ACCESSORS(is_arrow) |
| 6894 | |
| 6895 | // Indicates that this function is a concise method. |
| 6896 | DECL_BOOLEAN_ACCESSORS(is_concise_method) |
| 6897 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 6898 | // Indicates that this function is a getter. |
| 6899 | DECL_BOOLEAN_ACCESSORS(is_getter_function) |
| 6900 | |
| 6901 | // Indicates that this function is a setter. |
| 6902 | DECL_BOOLEAN_ACCESSORS(is_setter_function) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6903 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6904 | // Indicates that this function is a default constructor. |
| 6905 | DECL_BOOLEAN_ACCESSORS(is_default_constructor) |
| 6906 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6907 | // Indicates that this function is an asm function. |
| 6908 | DECL_BOOLEAN_ACCESSORS(asm_function) |
| 6909 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6910 | // Indicates that the the shared function info is deserialized from cache. |
| 6911 | DECL_BOOLEAN_ACCESSORS(deserialized) |
| 6912 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6913 | // Indicates that the the shared function info has never been compiled before. |
| 6914 | DECL_BOOLEAN_ACCESSORS(never_compiled) |
| 6915 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 6916 | // Whether this function was created from a FunctionDeclaration. |
| 6917 | DECL_BOOLEAN_ACCESSORS(is_declaration) |
| 6918 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6919 | inline FunctionKind kind(); |
| 6920 | inline void set_kind(FunctionKind kind); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 6921 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6922 | // Indicates whether or not the code in the shared function support |
| 6923 | // deoptimization. |
| 6924 | inline bool has_deoptimization_support(); |
| 6925 | |
| 6926 | // Enable deoptimization support through recompiled code. |
| 6927 | void EnableDeoptimizationSupport(Code* recompiled); |
| 6928 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6929 | // Disable (further) attempted optimization of all functions sharing this |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 6930 | // shared function info. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6931 | void DisableOptimization(BailoutReason reason); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6932 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6933 | inline BailoutReason disable_optimization_reason(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6934 | |
| 6935 | // Lookup the bailout ID and DCHECK that it exists in the non-optimized |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6936 | // code, returns whether it asserted (i.e., always true if assertions are |
| 6937 | // disabled). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6938 | bool VerifyBailoutId(BailoutId id); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6939 | |
| 6940 | // [source code]: Source code for the function. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6941 | bool HasSourceCode() const; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 6942 | Handle<Object> GetSourceCode(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6943 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6944 | // Number of times the function was optimized. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6945 | inline int opt_count(); |
| 6946 | inline void set_opt_count(int opt_count); |
| 6947 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6948 | // Number of times the function was deoptimized. |
| 6949 | inline void set_deopt_count(int value); |
| 6950 | inline int deopt_count(); |
| 6951 | inline void increment_deopt_count(); |
| 6952 | |
| 6953 | // Number of time we tried to re-enable optimization after it |
| 6954 | // was disabled due to high number of deoptimizations. |
| 6955 | inline void set_opt_reenable_tries(int value); |
| 6956 | inline int opt_reenable_tries(); |
| 6957 | |
| 6958 | inline void TryReenableOptimization(); |
| 6959 | |
| 6960 | // Stores deopt_count, opt_reenable_tries and ic_age as bit-fields. |
| 6961 | inline void set_counters(int value); |
| 6962 | inline int counters() const; |
| 6963 | |
| 6964 | // Stores opt_count and bailout_reason as bit-fields. |
| 6965 | inline void set_opt_count_and_bailout_reason(int value); |
| 6966 | inline int opt_count_and_bailout_reason() const; |
| 6967 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6968 | inline void set_disable_optimization_reason(BailoutReason reason); |
| 6969 | |
| 6970 | // Tells whether this function should be subject to debugging. |
| 6971 | inline bool IsSubjectToDebugging(); |
| 6972 | |
| 6973 | // Whether this function is defined in native code or extensions. |
| 6974 | inline bool IsBuiltin(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6975 | |
| 6976 | // Check whether or not this function is inlineable. |
| 6977 | bool IsInlineable(); |
| 6978 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6979 | // Source size of this function. |
| 6980 | int SourceSize(); |
| 6981 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6982 | // Returns `false` if formal parameters include rest parameters, optional |
| 6983 | // parameters, or destructuring parameters. |
| 6984 | // TODO(caitp): make this a flag set during parsing |
| 6985 | inline bool has_simple_parameters(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6986 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6987 | // Initialize a SharedFunctionInfo from a parsed function literal. |
| 6988 | static void InitFromFunctionLiteral(Handle<SharedFunctionInfo> shared_info, |
| 6989 | FunctionLiteral* lit); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6990 | |
| 6991 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6992 | DECLARE_PRINTER(SharedFunctionInfo) |
| 6993 | DECLARE_VERIFIER(SharedFunctionInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6994 | |
Ben Murdoch | 8f9999f | 2012-04-23 10:39:17 +0100 | [diff] [blame] | 6995 | void ResetForNewContext(int new_ic_age); |
| 6996 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6997 | // Iterate over all shared function infos. |
| 6998 | class Iterator { |
| 6999 | public: |
| 7000 | explicit Iterator(Isolate* isolate); |
| 7001 | SharedFunctionInfo* Next(); |
| 7002 | |
| 7003 | private: |
| 7004 | bool NextScript(); |
| 7005 | |
| 7006 | Script::Iterator script_iterator_; |
| 7007 | WeakFixedArray::Iterator sfi_iterator_; |
| 7008 | DisallowHeapAllocation no_gc_; |
| 7009 | DISALLOW_COPY_AND_ASSIGN(Iterator); |
| 7010 | }; |
| 7011 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7012 | DECLARE_CAST(SharedFunctionInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7013 | |
| 7014 | // Constants. |
| 7015 | static const int kDontAdaptArgumentsSentinel = -1; |
| 7016 | |
| 7017 | // Layout description. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 7018 | // Pointer fields. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7019 | static const int kNameOffset = HeapObject::kHeaderSize; |
| 7020 | static const int kCodeOffset = kNameOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7021 | static const int kOptimizedCodeMapOffset = kCodeOffset + kPointerSize; |
| 7022 | static const int kScopeInfoOffset = kOptimizedCodeMapOffset + kPointerSize; |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 7023 | static const int kConstructStubOffset = kScopeInfoOffset + kPointerSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 7024 | static const int kInstanceClassNameOffset = |
| 7025 | kConstructStubOffset + kPointerSize; |
| 7026 | static const int kFunctionDataOffset = |
| 7027 | kInstanceClassNameOffset + kPointerSize; |
| 7028 | static const int kScriptOffset = kFunctionDataOffset + kPointerSize; |
| 7029 | static const int kDebugInfoOffset = kScriptOffset + kPointerSize; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 7030 | static const int kFunctionIdentifierOffset = kDebugInfoOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7031 | static const int kFeedbackVectorOffset = |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 7032 | kFunctionIdentifierOffset + kPointerSize; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 7033 | #if TRACE_MAPS |
| 7034 | static const int kUniqueIdOffset = kFeedbackVectorOffset + kPointerSize; |
| 7035 | static const int kLastPointerFieldOffset = kUniqueIdOffset; |
| 7036 | #else |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7037 | // Just to not break the postmortrem support with conditional offsets |
| 7038 | static const int kUniqueIdOffset = kFeedbackVectorOffset; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 7039 | static const int kLastPointerFieldOffset = kFeedbackVectorOffset; |
| 7040 | #endif |
| 7041 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7042 | #if V8_HOST_ARCH_32_BIT |
| 7043 | // Smi fields. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 7044 | static const int kLengthOffset = kLastPointerFieldOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7045 | static const int kFormalParameterCountOffset = kLengthOffset + kPointerSize; |
| 7046 | static const int kExpectedNofPropertiesOffset = |
| 7047 | kFormalParameterCountOffset + kPointerSize; |
| 7048 | static const int kNumLiteralsOffset = |
| 7049 | kExpectedNofPropertiesOffset + kPointerSize; |
| 7050 | static const int kStartPositionAndTypeOffset = |
| 7051 | kNumLiteralsOffset + kPointerSize; |
| 7052 | static const int kEndPositionOffset = |
| 7053 | kStartPositionAndTypeOffset + kPointerSize; |
| 7054 | static const int kFunctionTokenPositionOffset = |
| 7055 | kEndPositionOffset + kPointerSize; |
| 7056 | static const int kCompilerHintsOffset = |
| 7057 | kFunctionTokenPositionOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7058 | static const int kOptCountAndBailoutReasonOffset = |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7059 | kCompilerHintsOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7060 | static const int kCountersOffset = |
| 7061 | kOptCountAndBailoutReasonOffset + kPointerSize; |
| 7062 | static const int kAstNodeCountOffset = |
| 7063 | kCountersOffset + kPointerSize; |
| 7064 | static const int kProfilerTicksOffset = |
| 7065 | kAstNodeCountOffset + kPointerSize; |
Ben Murdoch | 8f9999f | 2012-04-23 10:39:17 +0100 | [diff] [blame] | 7066 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7067 | // Total size. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7068 | static const int kSize = kProfilerTicksOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7069 | #else |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7070 | // The only reason to use smi fields instead of int fields is to allow |
| 7071 | // iteration without maps decoding during garbage collections. |
| 7072 | // To avoid wasting space on 64-bit architectures we use the following trick: |
| 7073 | // we group integer fields into pairs |
| 7074 | // The least significant integer in each pair is shifted left by 1. By doing |
| 7075 | // this we guarantee that LSB of each kPointerSize aligned word is not set and |
| 7076 | // thus this word cannot be treated as pointer to HeapObject during old space |
| 7077 | // traversal. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 7078 | #if V8_TARGET_LITTLE_ENDIAN |
| 7079 | static const int kLengthOffset = kLastPointerFieldOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7080 | static const int kFormalParameterCountOffset = |
| 7081 | kLengthOffset + kIntSize; |
| 7082 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7083 | static const int kExpectedNofPropertiesOffset = |
| 7084 | kFormalParameterCountOffset + kIntSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7085 | static const int kNumLiteralsOffset = |
| 7086 | kExpectedNofPropertiesOffset + kIntSize; |
| 7087 | |
| 7088 | static const int kEndPositionOffset = |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 7089 | kNumLiteralsOffset + kIntSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7090 | static const int kStartPositionAndTypeOffset = |
| 7091 | kEndPositionOffset + kIntSize; |
| 7092 | |
| 7093 | static const int kFunctionTokenPositionOffset = |
| 7094 | kStartPositionAndTypeOffset + kIntSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 7095 | static const int kCompilerHintsOffset = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7096 | kFunctionTokenPositionOffset + kIntSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7097 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7098 | static const int kOptCountAndBailoutReasonOffset = |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 7099 | kCompilerHintsOffset + kIntSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7100 | static const int kCountersOffset = |
| 7101 | kOptCountAndBailoutReasonOffset + kIntSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7102 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7103 | static const int kAstNodeCountOffset = |
| 7104 | kCountersOffset + kIntSize; |
| 7105 | static const int kProfilerTicksOffset = |
| 7106 | kAstNodeCountOffset + kIntSize; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7107 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 7108 | // Total size. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7109 | static const int kSize = kProfilerTicksOffset + kIntSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7110 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 7111 | #elif V8_TARGET_BIG_ENDIAN |
| 7112 | static const int kFormalParameterCountOffset = |
| 7113 | kLastPointerFieldOffset + kPointerSize; |
| 7114 | static const int kLengthOffset = kFormalParameterCountOffset + kIntSize; |
| 7115 | |
| 7116 | static const int kNumLiteralsOffset = kLengthOffset + kIntSize; |
| 7117 | static const int kExpectedNofPropertiesOffset = kNumLiteralsOffset + kIntSize; |
| 7118 | |
| 7119 | static const int kStartPositionAndTypeOffset = |
| 7120 | kExpectedNofPropertiesOffset + kIntSize; |
| 7121 | static const int kEndPositionOffset = kStartPositionAndTypeOffset + kIntSize; |
| 7122 | |
| 7123 | static const int kCompilerHintsOffset = kEndPositionOffset + kIntSize; |
| 7124 | static const int kFunctionTokenPositionOffset = |
| 7125 | kCompilerHintsOffset + kIntSize; |
| 7126 | |
| 7127 | static const int kCountersOffset = kFunctionTokenPositionOffset + kIntSize; |
| 7128 | static const int kOptCountAndBailoutReasonOffset = kCountersOffset + kIntSize; |
| 7129 | |
| 7130 | static const int kProfilerTicksOffset = |
| 7131 | kOptCountAndBailoutReasonOffset + kIntSize; |
| 7132 | static const int kAstNodeCountOffset = kProfilerTicksOffset + kIntSize; |
| 7133 | |
| 7134 | // Total size. |
| 7135 | static const int kSize = kAstNodeCountOffset + kIntSize; |
| 7136 | |
| 7137 | #else |
| 7138 | #error Unknown byte ordering |
| 7139 | #endif // Big endian |
| 7140 | #endif // 64-bit |
| 7141 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 7142 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 7143 | static const int kAlignedSize = POINTER_SIZE_ALIGN(kSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7144 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 7145 | typedef FixedBodyDescriptor<kNameOffset, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 7146 | kLastPointerFieldOffset + kPointerSize, |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 7147 | kSize> BodyDescriptor; |
| 7148 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7149 | // Bit positions in start_position_and_type. |
| 7150 | // The source code start position is in the 30 most significant bits of |
| 7151 | // the start_position_and_type field. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 7152 | static const int kIsNamedExpressionBit = 0; |
| 7153 | static const int kIsTopLevelBit = 1; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7154 | static const int kStartPositionShift = 2; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 7155 | static const int kStartPositionMask = ~((1 << kStartPositionShift) - 1); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7156 | |
| 7157 | // Bit positions in compiler_hints. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 7158 | enum CompilerHints { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7159 | // byte 0 |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 7160 | kAllowLazyCompilation, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7161 | kAllowLazyCompilationWithoutContext, |
| 7162 | kOptimizationDisabled, |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 7163 | kNeverCompiled, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 7164 | kNative, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7165 | kStrictModeFunction, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7166 | kUsesArguments, |
| 7167 | kNeedsHomeObject, |
| 7168 | // byte 1 |
| 7169 | kHasDuplicateParameters, |
| 7170 | kForceInline, |
| 7171 | kIsAsmFunction, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 7172 | kIsAnonymousExpression, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 7173 | kNameShouldPrintAsAnonymous, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7174 | kIsFunction, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7175 | kDontCrankshaft, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7176 | kDontFlush, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7177 | // byte 2 |
| 7178 | kFunctionKind, |
| 7179 | kIsArrow = kFunctionKind, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7180 | kIsGenerator, |
| 7181 | kIsConciseMethod, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 7182 | kIsDefaultConstructor, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7183 | kIsSubclassConstructor, |
| 7184 | kIsBaseConstructor, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 7185 | kIsGetterFunction, |
| 7186 | kIsSetterFunction, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7187 | // byte 3 |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 7188 | kIsAsyncFunction, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 7189 | kDeserialized, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 7190 | kIsDeclaration, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7191 | kCompilerHintsCount, // Pseudo entry |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 7192 | }; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7193 | // Add hints for other modes when they're added. |
| 7194 | STATIC_ASSERT(LANGUAGE_END == 3); |
| 7195 | // kFunctionKind has to be byte-aligned |
| 7196 | STATIC_ASSERT((kFunctionKind % kBitsPerByte) == 0); |
| 7197 | // Make sure that FunctionKind and byte 2 are in sync: |
| 7198 | #define ASSERT_FUNCTION_KIND_ORDER(functionKind, compilerFunctionKind) \ |
| 7199 | STATIC_ASSERT(FunctionKind::functionKind == \ |
| 7200 | 1 << (compilerFunctionKind - kFunctionKind)) |
| 7201 | ASSERT_FUNCTION_KIND_ORDER(kArrowFunction, kIsArrow); |
| 7202 | ASSERT_FUNCTION_KIND_ORDER(kGeneratorFunction, kIsGenerator); |
| 7203 | ASSERT_FUNCTION_KIND_ORDER(kConciseMethod, kIsConciseMethod); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7204 | ASSERT_FUNCTION_KIND_ORDER(kDefaultConstructor, kIsDefaultConstructor); |
| 7205 | ASSERT_FUNCTION_KIND_ORDER(kSubclassConstructor, kIsSubclassConstructor); |
| 7206 | ASSERT_FUNCTION_KIND_ORDER(kBaseConstructor, kIsBaseConstructor); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 7207 | ASSERT_FUNCTION_KIND_ORDER(kGetterFunction, kIsGetterFunction); |
| 7208 | ASSERT_FUNCTION_KIND_ORDER(kSetterFunction, kIsSetterFunction); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7209 | #undef ASSERT_FUNCTION_KIND_ORDER |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7210 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 7211 | class FunctionKindBits : public BitField<FunctionKind, kIsArrow, 9> {}; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7212 | |
| 7213 | class DeoptCountBits : public BitField<int, 0, 4> {}; |
| 7214 | class OptReenableTriesBits : public BitField<int, 4, 18> {}; |
| 7215 | class ICAgeBits : public BitField<int, 22, 8> {}; |
| 7216 | |
| 7217 | class OptCountBits : public BitField<int, 0, 22> {}; |
| 7218 | class DisabledOptimizationReasonBits : public BitField<int, 22, 8> {}; |
| 7219 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 7220 | private: |
| 7221 | #if V8_HOST_ARCH_32_BIT |
| 7222 | // On 32 bit platforms, compiler hints is a smi. |
| 7223 | static const int kCompilerHintsSmiTagSize = kSmiTagSize; |
| 7224 | static const int kCompilerHintsSize = kPointerSize; |
| 7225 | #else |
| 7226 | // On 64 bit platforms, compiler hints is not a smi, see comment above. |
| 7227 | static const int kCompilerHintsSmiTagSize = 0; |
| 7228 | static const int kCompilerHintsSize = kIntSize; |
| 7229 | #endif |
| 7230 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 7231 | STATIC_ASSERT(SharedFunctionInfo::kCompilerHintsCount <= |
| 7232 | SharedFunctionInfo::kCompilerHintsSize * kBitsPerByte); |
| 7233 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 7234 | public: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7235 | // Constants for optimizing codegen for strict mode function and |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7236 | // native tests when using integer-width instructions. |
| 7237 | static const int kStrictModeBit = |
| 7238 | kStrictModeFunction + kCompilerHintsSmiTagSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7239 | static const int kNativeBit = kNative + kCompilerHintsSmiTagSize; |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 7240 | static const int kHasDuplicateParametersBit = |
| 7241 | kHasDuplicateParameters + kCompilerHintsSmiTagSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7242 | |
| 7243 | static const int kClassConstructorBits = |
| 7244 | FunctionKind::kClassConstructor |
| 7245 | << (kFunctionKind + kCompilerHintsSmiTagSize); |
| 7246 | |
| 7247 | // Constants for optimizing codegen for strict mode function and |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 7248 | // native tests. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7249 | // Allows to use byte-width instructions. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7250 | static const int kStrictModeBitWithinByte = kStrictModeBit % kBitsPerByte; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7251 | static const int kNativeBitWithinByte = kNativeBit % kBitsPerByte; |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 7252 | static const int kHasDuplicateParametersBitWithinByte = |
| 7253 | kHasDuplicateParametersBit % kBitsPerByte; |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 7254 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7255 | static const int kClassConstructorBitsWithinByte = |
| 7256 | FunctionKind::kClassConstructor << kCompilerHintsSmiTagSize; |
| 7257 | STATIC_ASSERT(kClassConstructorBitsWithinByte < (1 << kBitsPerByte)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7258 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7259 | #if defined(V8_TARGET_LITTLE_ENDIAN) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7260 | #define BYTE_OFFSET(compiler_hint) \ |
| 7261 | kCompilerHintsOffset + \ |
| 7262 | (compiler_hint + kCompilerHintsSmiTagSize) / kBitsPerByte |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7263 | #elif defined(V8_TARGET_BIG_ENDIAN) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7264 | #define BYTE_OFFSET(compiler_hint) \ |
| 7265 | kCompilerHintsOffset + (kCompilerHintsSize - 1) - \ |
| 7266 | ((compiler_hint + kCompilerHintsSmiTagSize) / kBitsPerByte) |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 7267 | #else |
| 7268 | #error Unknown byte ordering |
| 7269 | #endif |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7270 | static const int kStrictModeByteOffset = BYTE_OFFSET(kStrictModeFunction); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7271 | static const int kNativeByteOffset = BYTE_OFFSET(kNative); |
| 7272 | static const int kFunctionKindByteOffset = BYTE_OFFSET(kFunctionKind); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 7273 | static const int kHasDuplicateParametersByteOffset = |
| 7274 | BYTE_OFFSET(kHasDuplicateParameters); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7275 | #undef BYTE_OFFSET |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 7276 | |
| 7277 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7278 | // Returns entry from optimized code map for specified context and OSR entry. |
| 7279 | // The result is either kNotFound, kSharedCodeIndex for context-independent |
| 7280 | // entry or a start index of the context-dependent entry. |
| 7281 | int SearchOptimizedCodeMapEntry(Context* native_context, |
| 7282 | BailoutId osr_ast_id); |
| 7283 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7284 | DISALLOW_IMPLICIT_CONSTRUCTORS(SharedFunctionInfo); |
| 7285 | }; |
| 7286 | |
| 7287 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7288 | // Printing support. |
| 7289 | struct SourceCodeOf { |
| 7290 | explicit SourceCodeOf(SharedFunctionInfo* v, int max = -1) |
| 7291 | : value(v), max_length(max) {} |
| 7292 | const SharedFunctionInfo* value; |
| 7293 | int max_length; |
| 7294 | }; |
| 7295 | |
| 7296 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 7297 | std::ostream& operator<<(std::ostream& os, const SourceCodeOf& v); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7298 | |
| 7299 | |
| 7300 | class JSGeneratorObject: public JSObject { |
| 7301 | public: |
| 7302 | // [function]: The function corresponding to this generator object. |
| 7303 | DECL_ACCESSORS(function, JSFunction) |
| 7304 | |
| 7305 | // [context]: The context of the suspended computation. |
| 7306 | DECL_ACCESSORS(context, Context) |
| 7307 | |
| 7308 | // [receiver]: The receiver of the suspended computation. |
| 7309 | DECL_ACCESSORS(receiver, Object) |
| 7310 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 7311 | // [input]: The most recent input value. |
| 7312 | DECL_ACCESSORS(input, Object) |
| 7313 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 7314 | // [resume_mode]: The most recent resume mode. |
| 7315 | enum ResumeMode { kNext, kReturn, kThrow }; |
| 7316 | DECL_INT_ACCESSORS(resume_mode) |
| 7317 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7318 | // [continuation]: Offset into code of continuation. |
| 7319 | // |
| 7320 | // A positive offset indicates a suspended generator. The special |
| 7321 | // kGeneratorExecuting and kGeneratorClosed values indicate that a generator |
| 7322 | // cannot be resumed. |
| 7323 | inline int continuation() const; |
| 7324 | inline void set_continuation(int continuation); |
| 7325 | inline bool is_closed(); |
| 7326 | inline bool is_executing(); |
| 7327 | inline bool is_suspended(); |
| 7328 | |
| 7329 | // [operand_stack]: Saved operand stack. |
| 7330 | DECL_ACCESSORS(operand_stack, FixedArray) |
| 7331 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7332 | DECLARE_CAST(JSGeneratorObject) |
| 7333 | |
| 7334 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7335 | DECLARE_VERIFIER(JSGeneratorObject) |
| 7336 | |
| 7337 | // Magic sentinel values for the continuation. |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 7338 | static const int kGeneratorExecuting = -2; |
| 7339 | static const int kGeneratorClosed = -1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7340 | |
| 7341 | // Layout description. |
| 7342 | static const int kFunctionOffset = JSObject::kHeaderSize; |
| 7343 | static const int kContextOffset = kFunctionOffset + kPointerSize; |
| 7344 | static const int kReceiverOffset = kContextOffset + kPointerSize; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 7345 | static const int kInputOffset = kReceiverOffset + kPointerSize; |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 7346 | static const int kResumeModeOffset = kInputOffset + kPointerSize; |
| 7347 | static const int kContinuationOffset = kResumeModeOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7348 | static const int kOperandStackOffset = kContinuationOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7349 | static const int kSize = kOperandStackOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7350 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7351 | private: |
| 7352 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGeneratorObject); |
| 7353 | }; |
| 7354 | |
| 7355 | |
| 7356 | // Representation for module instance objects. |
| 7357 | class JSModule: public JSObject { |
| 7358 | public: |
| 7359 | // [context]: the context holding the module's locals, or undefined if none. |
| 7360 | DECL_ACCESSORS(context, Object) |
| 7361 | |
| 7362 | // [scope_info]: Scope info. |
| 7363 | DECL_ACCESSORS(scope_info, ScopeInfo) |
| 7364 | |
| 7365 | DECLARE_CAST(JSModule) |
| 7366 | |
| 7367 | // Dispatched behavior. |
| 7368 | DECLARE_PRINTER(JSModule) |
| 7369 | DECLARE_VERIFIER(JSModule) |
| 7370 | |
| 7371 | // Layout description. |
| 7372 | static const int kContextOffset = JSObject::kHeaderSize; |
| 7373 | static const int kScopeInfoOffset = kContextOffset + kPointerSize; |
| 7374 | static const int kSize = kScopeInfoOffset + kPointerSize; |
| 7375 | |
| 7376 | private: |
| 7377 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSModule); |
| 7378 | }; |
| 7379 | |
| 7380 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7381 | // JSBoundFunction describes a bound function exotic object. |
| 7382 | class JSBoundFunction : public JSObject { |
| 7383 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7384 | // [bound_target_function]: The wrapped function object. |
| 7385 | DECL_ACCESSORS(bound_target_function, JSReceiver) |
| 7386 | |
| 7387 | // [bound_this]: The value that is always passed as the this value when |
| 7388 | // calling the wrapped function. |
| 7389 | DECL_ACCESSORS(bound_this, Object) |
| 7390 | |
| 7391 | // [bound_arguments]: A list of values whose elements are used as the first |
| 7392 | // arguments to any call to the wrapped function. |
| 7393 | DECL_ACCESSORS(bound_arguments, FixedArray) |
| 7394 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 7395 | static MaybeHandle<String> GetName(Isolate* isolate, |
| 7396 | Handle<JSBoundFunction> function); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7397 | static MaybeHandle<Context> GetFunctionRealm( |
| 7398 | Handle<JSBoundFunction> function); |
| 7399 | |
| 7400 | DECLARE_CAST(JSBoundFunction) |
| 7401 | |
| 7402 | // Dispatched behavior. |
| 7403 | DECLARE_PRINTER(JSBoundFunction) |
| 7404 | DECLARE_VERIFIER(JSBoundFunction) |
| 7405 | |
| 7406 | // The bound function's string representation implemented according |
| 7407 | // to ES6 section 19.2.3.5 Function.prototype.toString ( ). |
| 7408 | static Handle<String> ToString(Handle<JSBoundFunction> function); |
| 7409 | |
| 7410 | // Layout description. |
| 7411 | static const int kBoundTargetFunctionOffset = JSObject::kHeaderSize; |
| 7412 | static const int kBoundThisOffset = kBoundTargetFunctionOffset + kPointerSize; |
| 7413 | static const int kBoundArgumentsOffset = kBoundThisOffset + kPointerSize; |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 7414 | static const int kSize = kBoundArgumentsOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7415 | |
| 7416 | private: |
| 7417 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSBoundFunction); |
| 7418 | }; |
| 7419 | |
| 7420 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7421 | // JSFunction describes JavaScript functions. |
| 7422 | class JSFunction: public JSObject { |
| 7423 | public: |
| 7424 | // [prototype_or_initial_map]: |
| 7425 | DECL_ACCESSORS(prototype_or_initial_map, Object) |
| 7426 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 7427 | // [shared]: The information about the function that |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7428 | // can be shared by instances. |
| 7429 | DECL_ACCESSORS(shared, SharedFunctionInfo) |
| 7430 | |
| 7431 | // [context]: The context for this function. |
| 7432 | inline Context* context(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7433 | inline void set_context(Object* context); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7434 | inline JSObject* global_proxy(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7435 | inline Context* native_context(); |
| 7436 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 7437 | static Handle<Object> GetName(Isolate* isolate, Handle<JSFunction> function); |
| 7438 | static MaybeHandle<Smi> GetLength(Isolate* isolate, |
| 7439 | Handle<JSFunction> function); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7440 | static Handle<Context> GetFunctionRealm(Handle<JSFunction> function); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7441 | |
| 7442 | // [code]: The generated code object for this function. Executed |
| 7443 | // when the function is invoked, e.g. foo() or new foo(). See |
| 7444 | // [[Call]] and [[Construct]] description in ECMA-262, section |
| 7445 | // 8.6.2, page 27. |
| 7446 | inline Code* code(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7447 | inline void set_code(Code* code); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7448 | inline void set_code_no_write_barrier(Code* code); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7449 | inline void ReplaceCode(Code* code); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7450 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 7451 | // Get the abstract code associated with the function, which will either be |
| 7452 | // a Code object or a BytecodeArray. |
| 7453 | inline AbstractCode* abstract_code(); |
| 7454 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7455 | // Tells whether this function inlines the given shared function info. |
| 7456 | bool Inlines(SharedFunctionInfo* candidate); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7457 | |
| 7458 | // Tells whether or not this function has been optimized. |
| 7459 | inline bool IsOptimized(); |
| 7460 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 7461 | // Mark this function for lazy recompilation. The function will be recompiled |
| 7462 | // the next time it is executed. |
| 7463 | void MarkForBaseline(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7464 | void MarkForOptimization(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 7465 | void AttemptConcurrentOptimization(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7466 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 7467 | // Tells whether or not the function is already marked for lazy recompilation. |
| 7468 | inline bool IsMarkedForBaseline(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7469 | inline bool IsMarkedForOptimization(); |
| 7470 | inline bool IsMarkedForConcurrentOptimization(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7471 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7472 | // Tells whether or not the function is on the concurrent recompilation queue. |
| 7473 | inline bool IsInOptimizationQueue(); |
| 7474 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7475 | // Completes inobject slack tracking on initial map if it is active. |
| 7476 | inline void CompleteInobjectSlackTrackingIfActive(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7477 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7478 | // [literals]: Fixed array holding the materialized literals. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7479 | // |
| 7480 | // If the function contains object, regexp or array literals, the |
| 7481 | // literals array prefix contains the object, regexp, and array |
| 7482 | // function to be used when creating these literals. This is |
| 7483 | // necessary so that we do not dynamically lookup the object, regexp |
| 7484 | // or array functions. Performing a dynamic lookup, we might end up |
| 7485 | // using the functions from a new context that we should not have |
| 7486 | // access to. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7487 | DECL_ACCESSORS(literals, LiteralsArray) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7488 | |
| 7489 | // The initial map for an object created by this constructor. |
| 7490 | inline Map* initial_map(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7491 | static void SetInitialMap(Handle<JSFunction> function, Handle<Map> map, |
| 7492 | Handle<Object> prototype); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7493 | inline bool has_initial_map(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7494 | static void EnsureHasInitialMap(Handle<JSFunction> function); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7495 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7496 | // Creates a map that matches the constructor's initial map, but with |
| 7497 | // [[prototype]] being new.target.prototype. Because new.target can be a |
| 7498 | // JSProxy, this can call back into JavaScript. |
| 7499 | static MUST_USE_RESULT MaybeHandle<Map> GetDerivedMap( |
| 7500 | Isolate* isolate, Handle<JSFunction> constructor, |
| 7501 | Handle<JSReceiver> new_target); |
| 7502 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7503 | // Get and set the prototype property on a JSFunction. If the |
| 7504 | // function has an initial map the prototype is set on the initial |
| 7505 | // map. Otherwise, the prototype is put in the initial map field |
| 7506 | // until an initial map is needed. |
| 7507 | inline bool has_prototype(); |
| 7508 | inline bool has_instance_prototype(); |
| 7509 | inline Object* prototype(); |
| 7510 | inline Object* instance_prototype(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7511 | static void SetPrototype(Handle<JSFunction> function, |
| 7512 | Handle<Object> value); |
| 7513 | static void SetInstancePrototype(Handle<JSFunction> function, |
| 7514 | Handle<Object> value); |
| 7515 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 7516 | // After prototype is removed, it will not be created when accessed, and |
| 7517 | // [[Construct]] from this function will not be allowed. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7518 | bool RemovePrototype(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7519 | |
| 7520 | // Returns if this function has been compiled to native code yet. |
| 7521 | inline bool is_compiled(); |
| 7522 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7523 | // [next_function_link]: Links functions into various lists, e.g. the list |
| 7524 | // of optimized functions hanging off the native_context. The CodeFlusher |
| 7525 | // uses this link to chain together flushing candidates. Treated weakly |
| 7526 | // by the garbage collector. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7527 | DECL_ACCESSORS(next_function_link, Object) |
| 7528 | |
| 7529 | // Prints the name of the function using PrintF. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7530 | void PrintName(FILE* out = stdout); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7531 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7532 | DECLARE_CAST(JSFunction) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7533 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7534 | // Calculate the instance size and in-object properties count. |
| 7535 | void CalculateInstanceSize(InstanceType instance_type, |
| 7536 | int requested_internal_fields, int* instance_size, |
| 7537 | int* in_object_properties); |
| 7538 | void CalculateInstanceSizeForDerivedClass(InstanceType instance_type, |
| 7539 | int requested_internal_fields, |
| 7540 | int* instance_size, |
| 7541 | int* in_object_properties); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 7542 | static void CalculateInstanceSizeHelper(InstanceType instance_type, |
| 7543 | int requested_internal_fields, |
| 7544 | int requested_in_object_properties, |
| 7545 | int* instance_size, |
| 7546 | int* in_object_properties); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7547 | // Visiting policy flags define whether the code entry or next function |
| 7548 | // should be visited or not. |
| 7549 | enum BodyVisitingPolicy { |
| 7550 | kVisitCodeEntry = 1 << 0, |
| 7551 | kVisitNextFunction = 1 << 1, |
| 7552 | |
| 7553 | kSkipCodeEntryAndNextFunction = 0, |
| 7554 | kVisitCodeEntryAndNextFunction = kVisitCodeEntry | kVisitNextFunction |
| 7555 | }; |
| 7556 | // Iterates the function object according to the visiting policy. |
| 7557 | template <BodyVisitingPolicy> |
| 7558 | class BodyDescriptorImpl; |
| 7559 | |
| 7560 | // Visit the whole object. |
| 7561 | typedef BodyDescriptorImpl<kVisitCodeEntryAndNextFunction> BodyDescriptor; |
| 7562 | |
| 7563 | // Don't visit next function. |
| 7564 | typedef BodyDescriptorImpl<kVisitCodeEntry> BodyDescriptorStrongCode; |
| 7565 | typedef BodyDescriptorImpl<kSkipCodeEntryAndNextFunction> |
| 7566 | BodyDescriptorWeakCode; |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 7567 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7568 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7569 | DECLARE_PRINTER(JSFunction) |
| 7570 | DECLARE_VERIFIER(JSFunction) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7571 | |
| 7572 | // Returns the number of allocated literals. |
| 7573 | inline int NumberOfLiterals(); |
| 7574 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7575 | // The function's name if it is configured, otherwise shared function info |
| 7576 | // debug name. |
| 7577 | static Handle<String> GetName(Handle<JSFunction> function); |
| 7578 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 7579 | // ES6 section 9.2.11 SetFunctionName |
| 7580 | // Because of the way this abstract operation is used in the spec, |
| 7581 | // it should never fail. |
| 7582 | static void SetName(Handle<JSFunction> function, Handle<Name> name, |
| 7583 | Handle<String> prefix); |
| 7584 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7585 | // The function's displayName if it is set, otherwise name if it is |
| 7586 | // configured, otherwise shared function info |
| 7587 | // debug name. |
| 7588 | static Handle<String> GetDebugName(Handle<JSFunction> function); |
| 7589 | |
| 7590 | // The function's string representation implemented according to |
| 7591 | // ES6 section 19.2.3.5 Function.prototype.toString ( ). |
| 7592 | static Handle<String> ToString(Handle<JSFunction> function); |
| 7593 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7594 | // Layout descriptors. The last property (from kNonWeakFieldsEndOffset to |
| 7595 | // kSize) is weak and has special handling during garbage collection. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7596 | static const int kPrototypeOrInitialMapOffset = JSObject::kHeaderSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7597 | static const int kSharedFunctionInfoOffset = |
| 7598 | kPrototypeOrInitialMapOffset + kPointerSize; |
| 7599 | static const int kContextOffset = kSharedFunctionInfoOffset + kPointerSize; |
| 7600 | static const int kLiteralsOffset = kContextOffset + kPointerSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7601 | static const int kNonWeakFieldsEndOffset = kLiteralsOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7602 | static const int kCodeEntryOffset = kNonWeakFieldsEndOffset; |
| 7603 | static const int kNextFunctionLinkOffset = kCodeEntryOffset + kPointerSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7604 | static const int kSize = kNextFunctionLinkOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7605 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7606 | private: |
| 7607 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunction); |
| 7608 | }; |
| 7609 | |
| 7610 | |
| 7611 | // JSGlobalProxy's prototype must be a JSGlobalObject or null, |
| 7612 | // and the prototype is hidden. JSGlobalProxy always delegates |
| 7613 | // property accesses to its prototype if the prototype is not null. |
| 7614 | // |
| 7615 | // A JSGlobalProxy can be reinitialized which will preserve its identity. |
| 7616 | // |
| 7617 | // Accessing a JSGlobalProxy requires security check. |
| 7618 | |
| 7619 | class JSGlobalProxy : public JSObject { |
| 7620 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7621 | // [native_context]: the owner native context of this global proxy object. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7622 | // It is null value if this object is not used by any context. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7623 | DECL_ACCESSORS(native_context, Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7624 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7625 | // [hash]: The hash code property (undefined if not initialized yet). |
| 7626 | DECL_ACCESSORS(hash, Object) |
| 7627 | |
| 7628 | DECLARE_CAST(JSGlobalProxy) |
| 7629 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7630 | inline bool IsDetachedFrom(JSGlobalObject* global) const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7631 | |
| 7632 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7633 | DECLARE_PRINTER(JSGlobalProxy) |
| 7634 | DECLARE_VERIFIER(JSGlobalProxy) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7635 | |
| 7636 | // Layout description. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7637 | static const int kNativeContextOffset = JSObject::kHeaderSize; |
| 7638 | static const int kHashOffset = kNativeContextOffset + kPointerSize; |
| 7639 | static const int kSize = kHashOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7640 | |
| 7641 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7642 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalProxy); |
| 7643 | }; |
| 7644 | |
| 7645 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7646 | // JavaScript global object. |
| 7647 | class JSGlobalObject : public JSObject { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7648 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7649 | // [native context]: the natives corresponding to this global object. |
| 7650 | DECL_ACCESSORS(native_context, Context) |
| 7651 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7652 | // [global proxy]: the global proxy object of the context |
| 7653 | DECL_ACCESSORS(global_proxy, JSObject) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7654 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7655 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7656 | static void InvalidatePropertyCell(Handle<JSGlobalObject> object, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 7657 | Handle<Name> name); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7658 | // Ensure that the global object has a cell for the given property name. |
| 7659 | static Handle<PropertyCell> EnsurePropertyCell(Handle<JSGlobalObject> global, |
| 7660 | Handle<Name> name); |
| 7661 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7662 | DECLARE_CAST(JSGlobalObject) |
| 7663 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7664 | inline bool IsDetached(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7665 | |
| 7666 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7667 | DECLARE_PRINTER(JSGlobalObject) |
| 7668 | DECLARE_VERIFIER(JSGlobalObject) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7669 | |
| 7670 | // Layout description. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7671 | static const int kNativeContextOffset = JSObject::kHeaderSize; |
| 7672 | static const int kGlobalProxyOffset = kNativeContextOffset + kPointerSize; |
| 7673 | static const int kHeaderSize = kGlobalProxyOffset + kPointerSize; |
| 7674 | static const int kSize = kHeaderSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7675 | |
| 7676 | private: |
| 7677 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalObject); |
| 7678 | }; |
| 7679 | |
| 7680 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7681 | // Representation for JS Wrapper objects, String, Number, Boolean, etc. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7682 | class JSValue: public JSObject { |
| 7683 | public: |
| 7684 | // [value]: the object being wrapped. |
| 7685 | DECL_ACCESSORS(value, Object) |
| 7686 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7687 | DECLARE_CAST(JSValue) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7688 | |
| 7689 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7690 | DECLARE_PRINTER(JSValue) |
| 7691 | DECLARE_VERIFIER(JSValue) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7692 | |
| 7693 | // Layout description. |
| 7694 | static const int kValueOffset = JSObject::kHeaderSize; |
| 7695 | static const int kSize = kValueOffset + kPointerSize; |
| 7696 | |
| 7697 | private: |
| 7698 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSValue); |
| 7699 | }; |
| 7700 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 7701 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7702 | class DateCache; |
| 7703 | |
| 7704 | // Representation for JS date objects. |
| 7705 | class JSDate: public JSObject { |
| 7706 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7707 | static MUST_USE_RESULT MaybeHandle<JSDate> New(Handle<JSFunction> constructor, |
| 7708 | Handle<JSReceiver> new_target, |
| 7709 | double tv); |
| 7710 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7711 | // If one component is NaN, all of them are, indicating a NaN time value. |
| 7712 | // [value]: the time value. |
| 7713 | DECL_ACCESSORS(value, Object) |
| 7714 | // [year]: caches year. Either undefined, smi, or NaN. |
| 7715 | DECL_ACCESSORS(year, Object) |
| 7716 | // [month]: caches month. Either undefined, smi, or NaN. |
| 7717 | DECL_ACCESSORS(month, Object) |
| 7718 | // [day]: caches day. Either undefined, smi, or NaN. |
| 7719 | DECL_ACCESSORS(day, Object) |
| 7720 | // [weekday]: caches day of week. Either undefined, smi, or NaN. |
| 7721 | DECL_ACCESSORS(weekday, Object) |
| 7722 | // [hour]: caches hours. Either undefined, smi, or NaN. |
| 7723 | DECL_ACCESSORS(hour, Object) |
| 7724 | // [min]: caches minutes. Either undefined, smi, or NaN. |
| 7725 | DECL_ACCESSORS(min, Object) |
| 7726 | // [sec]: caches seconds. Either undefined, smi, or NaN. |
| 7727 | DECL_ACCESSORS(sec, Object) |
| 7728 | // [cache stamp]: sample of the date cache stamp at the |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7729 | // moment when chached fields were cached. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7730 | DECL_ACCESSORS(cache_stamp, Object) |
| 7731 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7732 | DECLARE_CAST(JSDate) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7733 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7734 | // Returns the time value (UTC) identifying the current time. |
| 7735 | static double CurrentTimeValue(Isolate* isolate); |
| 7736 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7737 | // Returns the date field with the specified index. |
| 7738 | // See FieldIndex for the list of date fields. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7739 | static Object* GetField(Object* date, Smi* index); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7740 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7741 | static Handle<Object> SetValue(Handle<JSDate> date, double v); |
| 7742 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7743 | void SetValue(Object* value, bool is_value_nan); |
| 7744 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7745 | // ES6 section 20.3.4.45 Date.prototype [ @@toPrimitive ] |
| 7746 | static MUST_USE_RESULT MaybeHandle<Object> ToPrimitive( |
| 7747 | Handle<JSReceiver> receiver, Handle<Object> hint); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7748 | |
| 7749 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7750 | DECLARE_PRINTER(JSDate) |
| 7751 | DECLARE_VERIFIER(JSDate) |
| 7752 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7753 | // The order is important. It must be kept in sync with date macros |
| 7754 | // in macros.py. |
| 7755 | enum FieldIndex { |
| 7756 | kDateValue, |
| 7757 | kYear, |
| 7758 | kMonth, |
| 7759 | kDay, |
| 7760 | kWeekday, |
| 7761 | kHour, |
| 7762 | kMinute, |
| 7763 | kSecond, |
| 7764 | kFirstUncachedField, |
| 7765 | kMillisecond = kFirstUncachedField, |
| 7766 | kDays, |
| 7767 | kTimeInDay, |
| 7768 | kFirstUTCField, |
| 7769 | kYearUTC = kFirstUTCField, |
| 7770 | kMonthUTC, |
| 7771 | kDayUTC, |
| 7772 | kWeekdayUTC, |
| 7773 | kHourUTC, |
| 7774 | kMinuteUTC, |
| 7775 | kSecondUTC, |
| 7776 | kMillisecondUTC, |
| 7777 | kDaysUTC, |
| 7778 | kTimeInDayUTC, |
| 7779 | kTimezoneOffset |
| 7780 | }; |
| 7781 | |
| 7782 | // Layout description. |
| 7783 | static const int kValueOffset = JSObject::kHeaderSize; |
| 7784 | static const int kYearOffset = kValueOffset + kPointerSize; |
| 7785 | static const int kMonthOffset = kYearOffset + kPointerSize; |
| 7786 | static const int kDayOffset = kMonthOffset + kPointerSize; |
| 7787 | static const int kWeekdayOffset = kDayOffset + kPointerSize; |
| 7788 | static const int kHourOffset = kWeekdayOffset + kPointerSize; |
| 7789 | static const int kMinOffset = kHourOffset + kPointerSize; |
| 7790 | static const int kSecOffset = kMinOffset + kPointerSize; |
| 7791 | static const int kCacheStampOffset = kSecOffset + kPointerSize; |
| 7792 | static const int kSize = kCacheStampOffset + kPointerSize; |
| 7793 | |
| 7794 | private: |
| 7795 | inline Object* DoGetField(FieldIndex index); |
| 7796 | |
| 7797 | Object* GetUTCField(FieldIndex index, double value, DateCache* date_cache); |
| 7798 | |
| 7799 | // Computes and caches the cacheable fields of the date. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7800 | inline void SetCachedFields(int64_t local_time_ms, DateCache* date_cache); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7801 | |
| 7802 | |
| 7803 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSDate); |
| 7804 | }; |
| 7805 | |
| 7806 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 7807 | // Representation of message objects used for error reporting through |
| 7808 | // the API. The messages are formatted in JavaScript so this object is |
| 7809 | // a real JavaScript object. The information used for formatting the |
| 7810 | // error messages are not directly accessible from JavaScript to |
| 7811 | // prevent leaking information to user code called during error |
| 7812 | // formatting. |
| 7813 | class JSMessageObject: public JSObject { |
| 7814 | public: |
| 7815 | // [type]: the type of error message. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7816 | inline int type() const; |
| 7817 | inline void set_type(int value); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 7818 | |
| 7819 | // [arguments]: the arguments for formatting the error message. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7820 | DECL_ACCESSORS(argument, Object) |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 7821 | |
| 7822 | // [script]: the script from which the error message originated. |
| 7823 | DECL_ACCESSORS(script, Object) |
| 7824 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 7825 | // [stack_frames]: an array of stack frames for this error object. |
| 7826 | DECL_ACCESSORS(stack_frames, Object) |
| 7827 | |
| 7828 | // [start_position]: the start position in the script for the error message. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7829 | inline int start_position() const; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 7830 | inline void set_start_position(int value); |
| 7831 | |
| 7832 | // [end_position]: the end position in the script for the error message. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7833 | inline int end_position() const; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 7834 | inline void set_end_position(int value); |
| 7835 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7836 | DECLARE_CAST(JSMessageObject) |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 7837 | |
| 7838 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7839 | DECLARE_PRINTER(JSMessageObject) |
| 7840 | DECLARE_VERIFIER(JSMessageObject) |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 7841 | |
| 7842 | // Layout description. |
| 7843 | static const int kTypeOffset = JSObject::kHeaderSize; |
| 7844 | static const int kArgumentsOffset = kTypeOffset + kPointerSize; |
| 7845 | static const int kScriptOffset = kArgumentsOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7846 | static const int kStackFramesOffset = kScriptOffset + kPointerSize; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 7847 | static const int kStartPositionOffset = kStackFramesOffset + kPointerSize; |
| 7848 | static const int kEndPositionOffset = kStartPositionOffset + kPointerSize; |
| 7849 | static const int kSize = kEndPositionOffset + kPointerSize; |
| 7850 | |
| 7851 | typedef FixedBodyDescriptor<HeapObject::kMapOffset, |
| 7852 | kStackFramesOffset + kPointerSize, |
| 7853 | kSize> BodyDescriptor; |
| 7854 | }; |
| 7855 | |
| 7856 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7857 | // Regular expressions |
| 7858 | // The regular expression holds a single reference to a FixedArray in |
| 7859 | // the kDataOffset field. |
| 7860 | // The FixedArray contains the following data: |
| 7861 | // - tag : type of regexp implementation (not compiled yet, atom or irregexp) |
| 7862 | // - reference to the original source string |
| 7863 | // - reference to the original flag string |
| 7864 | // If it is an atom regexp |
| 7865 | // - a reference to a literal string to search for |
| 7866 | // If it is an irregexp regexp: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7867 | // - a reference to code for Latin1 inputs (bytecode or compiled), or a smi |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7868 | // used for tracking the last usage (used for code flushing). |
| 7869 | // - a reference to code for UC16 inputs (bytecode or compiled), or a smi |
| 7870 | // used for tracking the last usage (used for code flushing).. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7871 | // - max number of registers used by irregexp implementations. |
| 7872 | // - number of capture registers (output values) of the regexp. |
| 7873 | class JSRegExp: public JSObject { |
| 7874 | public: |
| 7875 | // Meaning of Type: |
| 7876 | // NOT_COMPILED: Initial value. No data has been stored in the JSRegExp yet. |
| 7877 | // ATOM: A simple string to match against using an indexOf operation. |
| 7878 | // IRREGEXP: Compiled with Irregexp. |
| 7879 | // IRREGEXP_NATIVE: Compiled to native code with Irregexp. |
| 7880 | enum Type { NOT_COMPILED, ATOM, IRREGEXP }; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7881 | enum Flag { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7882 | kNone = 0, |
| 7883 | kGlobal = 1 << 0, |
| 7884 | kIgnoreCase = 1 << 1, |
| 7885 | kMultiline = 1 << 2, |
| 7886 | kSticky = 1 << 3, |
| 7887 | kUnicode = 1 << 4, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7888 | }; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7889 | typedef base::Flags<Flag> Flags; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7890 | |
| 7891 | DECL_ACCESSORS(data, Object) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7892 | DECL_ACCESSORS(flags, Object) |
| 7893 | DECL_ACCESSORS(source, Object) |
| 7894 | |
| 7895 | static MaybeHandle<JSRegExp> New(Handle<String> source, Flags flags); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7896 | static Handle<JSRegExp> Copy(Handle<JSRegExp> regexp); |
| 7897 | |
| 7898 | static MaybeHandle<JSRegExp> Initialize(Handle<JSRegExp> regexp, |
| 7899 | Handle<String> source, Flags flags); |
| 7900 | static MaybeHandle<JSRegExp> Initialize(Handle<JSRegExp> regexp, |
| 7901 | Handle<String> source, |
| 7902 | Handle<String> flags_string); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7903 | |
| 7904 | inline Type TypeTag(); |
| 7905 | inline int CaptureCount(); |
| 7906 | inline Flags GetFlags(); |
| 7907 | inline String* Pattern(); |
| 7908 | inline Object* DataAt(int index); |
| 7909 | // Set implementation data after the object has been prepared. |
| 7910 | inline void SetDataAt(int index, Object* value); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7911 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7912 | static int code_index(bool is_latin1) { |
| 7913 | if (is_latin1) { |
| 7914 | return kIrregexpLatin1CodeIndex; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7915 | } else { |
| 7916 | return kIrregexpUC16CodeIndex; |
| 7917 | } |
| 7918 | } |
| 7919 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7920 | static int saved_code_index(bool is_latin1) { |
| 7921 | if (is_latin1) { |
| 7922 | return kIrregexpLatin1CodeSavedIndex; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7923 | } else { |
| 7924 | return kIrregexpUC16CodeSavedIndex; |
| 7925 | } |
| 7926 | } |
| 7927 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7928 | DECLARE_CAST(JSRegExp) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7929 | |
| 7930 | // Dispatched behavior. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7931 | DECLARE_PRINTER(JSRegExp) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7932 | DECLARE_VERIFIER(JSRegExp) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7933 | |
| 7934 | static const int kDataOffset = JSObject::kHeaderSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7935 | static const int kSourceOffset = kDataOffset + kPointerSize; |
| 7936 | static const int kFlagsOffset = kSourceOffset + kPointerSize; |
| 7937 | static const int kSize = kFlagsOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7938 | |
| 7939 | // Indices in the data array. |
| 7940 | static const int kTagIndex = 0; |
| 7941 | static const int kSourceIndex = kTagIndex + 1; |
| 7942 | static const int kFlagsIndex = kSourceIndex + 1; |
| 7943 | static const int kDataIndex = kFlagsIndex + 1; |
| 7944 | // The data fields are used in different ways depending on the |
| 7945 | // value of the tag. |
| 7946 | // Atom regexps (literal strings). |
| 7947 | static const int kAtomPatternIndex = kDataIndex; |
| 7948 | |
| 7949 | static const int kAtomDataSize = kAtomPatternIndex + 1; |
| 7950 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7951 | // Irregexp compiled code or bytecode for Latin1. If compilation |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7952 | // fails, this fields hold an exception object that should be |
| 7953 | // thrown if the regexp is used again. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7954 | static const int kIrregexpLatin1CodeIndex = kDataIndex; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7955 | // Irregexp compiled code or bytecode for UC16. If compilation |
| 7956 | // fails, this fields hold an exception object that should be |
| 7957 | // thrown if the regexp is used again. |
| 7958 | static const int kIrregexpUC16CodeIndex = kDataIndex + 1; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7959 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7960 | // Saved instance of Irregexp compiled code or bytecode for Latin1 that |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7961 | // is a potential candidate for flushing. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7962 | static const int kIrregexpLatin1CodeSavedIndex = kDataIndex + 2; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7963 | // Saved instance of Irregexp compiled code or bytecode for UC16 that is |
| 7964 | // a potential candidate for flushing. |
| 7965 | static const int kIrregexpUC16CodeSavedIndex = kDataIndex + 3; |
| 7966 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7967 | // Maximal number of registers used by either Latin1 or UC16. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7968 | // Only used to check that there is enough stack space |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7969 | static const int kIrregexpMaxRegisterCountIndex = kDataIndex + 4; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7970 | // Number of captures in the compiled regexp. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7971 | static const int kIrregexpCaptureCountIndex = kDataIndex + 5; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7972 | |
| 7973 | static const int kIrregexpDataSize = kIrregexpCaptureCountIndex + 1; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 7974 | |
| 7975 | // Offsets directly into the data fixed array. |
| 7976 | static const int kDataTagOffset = |
| 7977 | FixedArray::kHeaderSize + kTagIndex * kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7978 | static const int kDataOneByteCodeOffset = |
| 7979 | FixedArray::kHeaderSize + kIrregexpLatin1CodeIndex * kPointerSize; |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 7980 | static const int kDataUC16CodeOffset = |
| 7981 | FixedArray::kHeaderSize + kIrregexpUC16CodeIndex * kPointerSize; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 7982 | static const int kIrregexpCaptureCountOffset = |
| 7983 | FixedArray::kHeaderSize + kIrregexpCaptureCountIndex * kPointerSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 7984 | |
| 7985 | // In-object fields. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7986 | static const int kLastIndexFieldIndex = 0; |
| 7987 | static const int kInObjectFieldCount = 1; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7988 | |
| 7989 | // The uninitialized value for a regexp code object. |
| 7990 | static const int kUninitializedValue = -1; |
| 7991 | |
| 7992 | // The compilation error value for the regexp code object. The real error |
| 7993 | // object is in the saved code field. |
| 7994 | static const int kCompilationErrorValue = -2; |
| 7995 | |
| 7996 | // When we store the sweep generation at which we moved the code from the |
| 7997 | // code index to the saved code index we mask it of to be in the [0:255] |
| 7998 | // range. |
| 7999 | static const int kCodeAgeMask = 0xff; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8000 | }; |
| 8001 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8002 | DEFINE_OPERATORS_FOR_FLAGS(JSRegExp::Flags) |
| 8003 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8004 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 8005 | class CompilationCacheShape : public BaseShape<HashTableKey*> { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8006 | public: |
| 8007 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
| 8008 | return key->IsMatch(value); |
| 8009 | } |
| 8010 | |
| 8011 | static inline uint32_t Hash(HashTableKey* key) { |
| 8012 | return key->Hash(); |
| 8013 | } |
| 8014 | |
| 8015 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
| 8016 | return key->HashForObject(object); |
| 8017 | } |
| 8018 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8019 | static inline Handle<Object> AsHandle(Isolate* isolate, HashTableKey* key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8020 | |
| 8021 | static const int kPrefixSize = 0; |
| 8022 | static const int kEntrySize = 2; |
| 8023 | }; |
| 8024 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 8025 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8026 | // This cache is used in two different variants. For regexp caching, it simply |
| 8027 | // maps identifying info of the regexp to the cached regexp object. Scripts and |
| 8028 | // eval code only gets cached after a second probe for the code object. To do |
| 8029 | // so, on first "put" only a hash identifying the source is entered into the |
| 8030 | // cache, mapping it to a lifetime count of the hash. On each call to Age all |
| 8031 | // such lifetimes get reduced, and removed once they reach zero. If a second put |
| 8032 | // is called while such a hash is live in the cache, the hash gets replaced by |
| 8033 | // an actual cache entry. Age also removes stale live entries from the cache. |
| 8034 | // Such entries are identified by SharedFunctionInfos pointing to either the |
| 8035 | // recompilation stub, or to "old" code. This avoids memory leaks due to |
| 8036 | // premature caching of scripts and eval strings that are never needed later. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8037 | class CompilationCacheTable: public HashTable<CompilationCacheTable, |
| 8038 | CompilationCacheShape, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8039 | HashTableKey*> { |
| 8040 | public: |
| 8041 | // Find cached value for a string key, otherwise return null. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8042 | Handle<Object> Lookup( |
| 8043 | Handle<String> src, Handle<Context> context, LanguageMode language_mode); |
| 8044 | Handle<Object> LookupEval( |
| 8045 | Handle<String> src, Handle<SharedFunctionInfo> shared, |
| 8046 | LanguageMode language_mode, int scope_position); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8047 | Handle<Object> LookupRegExp(Handle<String> source, JSRegExp::Flags flags); |
| 8048 | static Handle<CompilationCacheTable> Put( |
| 8049 | Handle<CompilationCacheTable> cache, Handle<String> src, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8050 | Handle<Context> context, LanguageMode language_mode, |
| 8051 | Handle<Object> value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8052 | static Handle<CompilationCacheTable> PutEval( |
| 8053 | Handle<CompilationCacheTable> cache, Handle<String> src, |
| 8054 | Handle<SharedFunctionInfo> context, Handle<SharedFunctionInfo> value, |
| 8055 | int scope_position); |
| 8056 | static Handle<CompilationCacheTable> PutRegExp( |
| 8057 | Handle<CompilationCacheTable> cache, Handle<String> src, |
| 8058 | JSRegExp::Flags flags, Handle<FixedArray> value); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 8059 | void Remove(Object* value); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8060 | void Age(); |
| 8061 | static const int kHashGenerations = 10; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 8062 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8063 | DECLARE_CAST(CompilationCacheTable) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8064 | |
| 8065 | private: |
| 8066 | DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheTable); |
| 8067 | }; |
| 8068 | |
| 8069 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 8070 | class CodeCacheHashTableShape : public BaseShape<HashTableKey*> { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8071 | public: |
| 8072 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
| 8073 | return key->IsMatch(value); |
| 8074 | } |
| 8075 | |
| 8076 | static inline uint32_t Hash(HashTableKey* key) { |
| 8077 | return key->Hash(); |
| 8078 | } |
| 8079 | |
| 8080 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
| 8081 | return key->HashForObject(object); |
| 8082 | } |
| 8083 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8084 | static inline Handle<Object> AsHandle(Isolate* isolate, HashTableKey* key); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8085 | |
| 8086 | static const int kPrefixSize = 0; |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 8087 | // The both the key (name + flags) and value (code object) can be derived from |
| 8088 | // the fixed array that stores both the name and code. |
| 8089 | // TODO(verwaest): Don't allocate a fixed array but inline name and code. |
| 8090 | // Rewrite IsMatch to get table + index as input rather than just the raw key. |
| 8091 | static const int kEntrySize = 1; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8092 | }; |
| 8093 | |
| 8094 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8095 | class CodeCacheHashTable: public HashTable<CodeCacheHashTable, |
| 8096 | CodeCacheHashTableShape, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8097 | HashTableKey*> { |
| 8098 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8099 | static Handle<CodeCacheHashTable> Put( |
| 8100 | Handle<CodeCacheHashTable> table, |
| 8101 | Handle<Name> name, |
| 8102 | Handle<Code> code); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8103 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 8104 | Code* Lookup(Name* name, Code::Flags flags); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8105 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8106 | DECLARE_CAST(CodeCacheHashTable) |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8107 | |
| 8108 | // Initial size of the fixed array backing the hash table. |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 8109 | static const int kInitialSize = 16; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8110 | |
| 8111 | private: |
| 8112 | DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCacheHashTable); |
| 8113 | }; |
| 8114 | |
| 8115 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8116 | class TypeFeedbackInfo: public Struct { |
| 8117 | public: |
| 8118 | inline int ic_total_count(); |
| 8119 | inline void set_ic_total_count(int count); |
| 8120 | |
Ben Murdoch | 8f9999f | 2012-04-23 10:39:17 +0100 | [diff] [blame] | 8121 | inline int ic_with_type_info_count(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8122 | inline void change_ic_with_type_info_count(int delta); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8123 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8124 | inline int ic_generic_count(); |
| 8125 | inline void change_ic_generic_count(int delta); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8126 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8127 | inline void initialize_storage(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8128 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8129 | inline void change_own_type_change_checksum(); |
| 8130 | inline int own_type_change_checksum(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8131 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8132 | inline void set_inlined_type_change_checksum(int checksum); |
| 8133 | inline bool matches_inlined_type_change_checksum(int checksum); |
| 8134 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8135 | DECLARE_CAST(TypeFeedbackInfo) |
| 8136 | |
| 8137 | // Dispatched behavior. |
| 8138 | DECLARE_PRINTER(TypeFeedbackInfo) |
| 8139 | DECLARE_VERIFIER(TypeFeedbackInfo) |
| 8140 | |
| 8141 | static const int kStorage1Offset = HeapObject::kHeaderSize; |
| 8142 | static const int kStorage2Offset = kStorage1Offset + kPointerSize; |
| 8143 | static const int kStorage3Offset = kStorage2Offset + kPointerSize; |
| 8144 | static const int kSize = kStorage3Offset + kPointerSize; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8145 | |
| 8146 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8147 | static const int kTypeChangeChecksumBits = 7; |
| 8148 | |
| 8149 | class ICTotalCountField: public BitField<int, 0, |
| 8150 | kSmiValueSize - kTypeChangeChecksumBits> {}; // NOLINT |
| 8151 | class OwnTypeChangeChecksum: public BitField<int, |
| 8152 | kSmiValueSize - kTypeChangeChecksumBits, |
| 8153 | kTypeChangeChecksumBits> {}; // NOLINT |
| 8154 | class ICsWithTypeInfoCountField: public BitField<int, 0, |
| 8155 | kSmiValueSize - kTypeChangeChecksumBits> {}; // NOLINT |
| 8156 | class InlinedTypeChangeChecksum: public BitField<int, |
| 8157 | kSmiValueSize - kTypeChangeChecksumBits, |
| 8158 | kTypeChangeChecksumBits> {}; // NOLINT |
| 8159 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8160 | DISALLOW_IMPLICIT_CONSTRUCTORS(TypeFeedbackInfo); |
| 8161 | }; |
| 8162 | |
| 8163 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8164 | enum AllocationSiteMode { |
| 8165 | DONT_TRACK_ALLOCATION_SITE, |
| 8166 | TRACK_ALLOCATION_SITE, |
| 8167 | LAST_ALLOCATION_SITE_MODE = TRACK_ALLOCATION_SITE |
| 8168 | }; |
| 8169 | |
| 8170 | |
| 8171 | class AllocationSite: public Struct { |
| 8172 | public: |
| 8173 | static const uint32_t kMaximumArrayBytesToPretransition = 8 * 1024; |
| 8174 | static const double kPretenureRatio; |
| 8175 | static const int kPretenureMinimumCreated = 100; |
| 8176 | |
| 8177 | // Values for pretenure decision field. |
| 8178 | enum PretenureDecision { |
| 8179 | kUndecided = 0, |
| 8180 | kDontTenure = 1, |
| 8181 | kMaybeTenure = 2, |
| 8182 | kTenure = 3, |
| 8183 | kZombie = 4, |
| 8184 | kLastPretenureDecisionValue = kZombie |
| 8185 | }; |
| 8186 | |
| 8187 | const char* PretenureDecisionName(PretenureDecision decision); |
| 8188 | |
| 8189 | DECL_ACCESSORS(transition_info, Object) |
| 8190 | // nested_site threads a list of sites that represent nested literals |
| 8191 | // walked in a particular order. So [[1, 2], 1, 2] will have one |
| 8192 | // nested_site, but [[1, 2], 3, [4]] will have a list of two. |
| 8193 | DECL_ACCESSORS(nested_site, Object) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8194 | DECL_INT_ACCESSORS(pretenure_data) |
| 8195 | DECL_INT_ACCESSORS(pretenure_create_count) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8196 | DECL_ACCESSORS(dependent_code, DependentCode) |
| 8197 | DECL_ACCESSORS(weak_next, Object) |
| 8198 | |
| 8199 | inline void Initialize(); |
| 8200 | |
| 8201 | // This method is expensive, it should only be called for reporting. |
| 8202 | bool IsNestedSite(); |
| 8203 | |
| 8204 | // transition_info bitfields, for constructed array transition info. |
| 8205 | class ElementsKindBits: public BitField<ElementsKind, 0, 15> {}; |
| 8206 | class UnusedBits: public BitField<int, 15, 14> {}; |
| 8207 | class DoNotInlineBit: public BitField<bool, 29, 1> {}; |
| 8208 | |
| 8209 | // Bitfields for pretenure_data |
| 8210 | class MementoFoundCountBits: public BitField<int, 0, 26> {}; |
| 8211 | class PretenureDecisionBits: public BitField<PretenureDecision, 26, 3> {}; |
| 8212 | class DeoptDependentCodeBit: public BitField<bool, 29, 1> {}; |
| 8213 | STATIC_ASSERT(PretenureDecisionBits::kMax >= kLastPretenureDecisionValue); |
| 8214 | |
| 8215 | // Increments the mementos found counter and returns true when the first |
| 8216 | // memento was found for a given allocation site. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8217 | inline bool IncrementMementoFoundCount(int increment = 1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8218 | |
| 8219 | inline void IncrementMementoCreateCount(); |
| 8220 | |
| 8221 | PretenureFlag GetPretenureMode(); |
| 8222 | |
| 8223 | void ResetPretenureDecision(); |
| 8224 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8225 | inline PretenureDecision pretenure_decision(); |
| 8226 | inline void set_pretenure_decision(PretenureDecision decision); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8227 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8228 | inline bool deopt_dependent_code(); |
| 8229 | inline void set_deopt_dependent_code(bool deopt); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8230 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8231 | inline int memento_found_count(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8232 | inline void set_memento_found_count(int count); |
| 8233 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8234 | inline int memento_create_count(); |
| 8235 | inline void set_memento_create_count(int count); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8236 | |
| 8237 | // The pretenuring decision is made during gc, and the zombie state allows |
| 8238 | // us to recognize when an allocation site is just being kept alive because |
| 8239 | // a later traversal of new space may discover AllocationMementos that point |
| 8240 | // to this AllocationSite. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8241 | inline bool IsZombie(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8242 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8243 | inline bool IsMaybeTenure(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8244 | |
| 8245 | inline void MarkZombie(); |
| 8246 | |
| 8247 | inline bool MakePretenureDecision(PretenureDecision current_decision, |
| 8248 | double ratio, |
| 8249 | bool maximum_size_scavenge); |
| 8250 | |
| 8251 | inline bool DigestPretenuringFeedback(bool maximum_size_scavenge); |
| 8252 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8253 | inline ElementsKind GetElementsKind(); |
| 8254 | inline void SetElementsKind(ElementsKind kind); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8255 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8256 | inline bool CanInlineCall(); |
| 8257 | inline void SetDoNotInlineCall(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8258 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8259 | inline bool SitePointsToLiteral(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8260 | |
| 8261 | static void DigestTransitionFeedback(Handle<AllocationSite> site, |
| 8262 | ElementsKind to_kind); |
| 8263 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8264 | DECLARE_PRINTER(AllocationSite) |
| 8265 | DECLARE_VERIFIER(AllocationSite) |
| 8266 | |
| 8267 | DECLARE_CAST(AllocationSite) |
| 8268 | static inline AllocationSiteMode GetMode( |
| 8269 | ElementsKind boilerplate_elements_kind); |
| 8270 | static inline AllocationSiteMode GetMode(ElementsKind from, ElementsKind to); |
| 8271 | static inline bool CanTrack(InstanceType type); |
| 8272 | |
| 8273 | static const int kTransitionInfoOffset = HeapObject::kHeaderSize; |
| 8274 | static const int kNestedSiteOffset = kTransitionInfoOffset + kPointerSize; |
| 8275 | static const int kPretenureDataOffset = kNestedSiteOffset + kPointerSize; |
| 8276 | static const int kPretenureCreateCountOffset = |
| 8277 | kPretenureDataOffset + kPointerSize; |
| 8278 | static const int kDependentCodeOffset = |
| 8279 | kPretenureCreateCountOffset + kPointerSize; |
| 8280 | static const int kWeakNextOffset = kDependentCodeOffset + kPointerSize; |
| 8281 | static const int kSize = kWeakNextOffset + kPointerSize; |
| 8282 | |
| 8283 | // During mark compact we need to take special care for the dependent code |
| 8284 | // field. |
| 8285 | static const int kPointerFieldsBeginOffset = kTransitionInfoOffset; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8286 | static const int kPointerFieldsEndOffset = kWeakNextOffset; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8287 | |
| 8288 | // For other visitors, use the fixed body descriptor below. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 8289 | typedef FixedBodyDescriptor<HeapObject::kHeaderSize, kSize, kSize> |
| 8290 | BodyDescriptor; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8291 | |
| 8292 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8293 | inline bool PretenuringDecisionMade(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8294 | |
| 8295 | DISALLOW_IMPLICIT_CONSTRUCTORS(AllocationSite); |
| 8296 | }; |
| 8297 | |
| 8298 | |
| 8299 | class AllocationMemento: public Struct { |
| 8300 | public: |
| 8301 | static const int kAllocationSiteOffset = HeapObject::kHeaderSize; |
| 8302 | static const int kSize = kAllocationSiteOffset + kPointerSize; |
| 8303 | |
| 8304 | DECL_ACCESSORS(allocation_site, Object) |
| 8305 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8306 | inline bool IsValid(); |
| 8307 | inline AllocationSite* GetAllocationSite(); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 8308 | inline Address GetAllocationSiteUnchecked(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8309 | |
| 8310 | DECLARE_PRINTER(AllocationMemento) |
| 8311 | DECLARE_VERIFIER(AllocationMemento) |
| 8312 | |
| 8313 | DECLARE_CAST(AllocationMemento) |
| 8314 | |
| 8315 | private: |
| 8316 | DISALLOW_IMPLICIT_CONSTRUCTORS(AllocationMemento); |
| 8317 | }; |
| 8318 | |
| 8319 | |
| 8320 | // Representation of a slow alias as part of a sloppy arguments objects. |
| 8321 | // For fast aliases (if HasSloppyArgumentsElements()): |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8322 | // - the parameter map contains an index into the context |
| 8323 | // - all attributes of the element have default values |
| 8324 | // For slow aliases (if HasDictionaryArgumentsElements()): |
| 8325 | // - the parameter map contains no fast alias mapping (i.e. the hole) |
| 8326 | // - this struct (in the slow backing store) contains an index into the context |
| 8327 | // - all attributes are available as part if the property details |
| 8328 | class AliasedArgumentsEntry: public Struct { |
| 8329 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8330 | inline int aliased_context_slot() const; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8331 | inline void set_aliased_context_slot(int count); |
| 8332 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8333 | DECLARE_CAST(AliasedArgumentsEntry) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8334 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8335 | // Dispatched behavior. |
| 8336 | DECLARE_PRINTER(AliasedArgumentsEntry) |
| 8337 | DECLARE_VERIFIER(AliasedArgumentsEntry) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8338 | |
| 8339 | static const int kAliasedContextSlot = HeapObject::kHeaderSize; |
| 8340 | static const int kSize = kAliasedContextSlot + kPointerSize; |
| 8341 | |
| 8342 | private: |
| 8343 | DISALLOW_IMPLICIT_CONSTRUCTORS(AliasedArgumentsEntry); |
| 8344 | }; |
| 8345 | |
| 8346 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8347 | enum AllowNullsFlag {ALLOW_NULLS, DISALLOW_NULLS}; |
| 8348 | enum RobustnessFlag {ROBUST_STRING_TRAVERSAL, FAST_STRING_TRAVERSAL}; |
| 8349 | |
| 8350 | |
| 8351 | class StringHasher { |
| 8352 | public: |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 8353 | explicit inline StringHasher(int length, uint32_t seed); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8354 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8355 | template <typename schar> |
| 8356 | static inline uint32_t HashSequentialString(const schar* chars, |
| 8357 | int length, |
| 8358 | uint32_t seed); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8359 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8360 | // Reads all the data, even for long strings and computes the utf16 length. |
| 8361 | static uint32_t ComputeUtf8Hash(Vector<const char> chars, |
| 8362 | uint32_t seed, |
| 8363 | int* utf16_length_out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8364 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 8365 | // Calculated hash value for a string consisting of 1 to |
| 8366 | // String::kMaxArrayIndexSize digits with no leading zeros (except "0"). |
| 8367 | // value is represented decimal value. |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 8368 | static uint32_t MakeArrayIndexHash(uint32_t value, int length); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 8369 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 8370 | // No string is allowed to have a hash of zero. That value is reserved |
| 8371 | // for internal properties. If the hash calculation yields zero then we |
| 8372 | // use 27 instead. |
| 8373 | static const int kZeroHash = 27; |
| 8374 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8375 | // Reusable parts of the hashing algorithm. |
| 8376 | INLINE(static uint32_t AddCharacterCore(uint32_t running_hash, uint16_t c)); |
| 8377 | INLINE(static uint32_t GetHashCore(uint32_t running_hash)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8378 | INLINE(static uint32_t ComputeRunningHash(uint32_t running_hash, |
| 8379 | const uc16* chars, int length)); |
| 8380 | INLINE(static uint32_t ComputeRunningHashOneByte(uint32_t running_hash, |
| 8381 | const char* chars, |
| 8382 | int length)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8383 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8384 | protected: |
| 8385 | // Returns the value to store in the hash field of a string with |
| 8386 | // the given length and contents. |
| 8387 | uint32_t GetHashField(); |
| 8388 | // Returns true if the hash of this string can be computed without |
| 8389 | // looking at the contents. |
| 8390 | inline bool has_trivial_hash(); |
| 8391 | // Adds a block of characters to the hash. |
| 8392 | template<typename Char> |
| 8393 | inline void AddCharacters(const Char* chars, int len); |
| 8394 | |
| 8395 | private: |
| 8396 | // Add a character to the hash. |
| 8397 | inline void AddCharacter(uint16_t c); |
| 8398 | // Update index. Returns true if string is still an index. |
| 8399 | inline bool UpdateIndex(uint16_t c); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8400 | |
| 8401 | int length_; |
| 8402 | uint32_t raw_running_hash_; |
| 8403 | uint32_t array_index_; |
| 8404 | bool is_array_index_; |
| 8405 | bool is_first_char_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8406 | DISALLOW_COPY_AND_ASSIGN(StringHasher); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8407 | }; |
| 8408 | |
| 8409 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8410 | class IteratingStringHasher : public StringHasher { |
| 8411 | public: |
| 8412 | static inline uint32_t Hash(String* string, uint32_t seed); |
| 8413 | inline void VisitOneByteString(const uint8_t* chars, int length); |
| 8414 | inline void VisitTwoByteString(const uint16_t* chars, int length); |
| 8415 | |
| 8416 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8417 | inline IteratingStringHasher(int len, uint32_t seed); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8418 | void VisitConsString(ConsString* cons_string); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8419 | DISALLOW_COPY_AND_ASSIGN(IteratingStringHasher); |
| 8420 | }; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 8421 | |
| 8422 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8423 | // The characteristics of a string are stored in its map. Retrieving these |
| 8424 | // few bits of information is moderately expensive, involving two memory |
| 8425 | // loads where the second is dependent on the first. To improve efficiency |
| 8426 | // the shape of the string is given its own class so that it can be retrieved |
| 8427 | // once and used for several string operations. A StringShape is small enough |
| 8428 | // to be passed by value and is immutable, but be aware that flattening a |
| 8429 | // string can potentially alter its shape. Also be aware that a GC caused by |
| 8430 | // something else can alter the shape of a string due to ConsString |
| 8431 | // shortcutting. Keeping these restrictions in mind has proven to be error- |
| 8432 | // prone and so we no longer put StringShapes in variables unless there is a |
| 8433 | // concrete performance benefit at that particular point in the code. |
| 8434 | class StringShape BASE_EMBEDDED { |
| 8435 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8436 | inline explicit StringShape(const String* s); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8437 | inline explicit StringShape(Map* s); |
| 8438 | inline explicit StringShape(InstanceType t); |
| 8439 | inline bool IsSequential(); |
| 8440 | inline bool IsExternal(); |
| 8441 | inline bool IsCons(); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8442 | inline bool IsSliced(); |
| 8443 | inline bool IsIndirect(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8444 | inline bool IsExternalOneByte(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8445 | inline bool IsExternalTwoByte(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8446 | inline bool IsSequentialOneByte(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8447 | inline bool IsSequentialTwoByte(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8448 | inline bool IsInternalized(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8449 | inline StringRepresentationTag representation_tag(); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8450 | inline uint32_t encoding_tag(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8451 | inline uint32_t full_representation_tag(); |
| 8452 | inline uint32_t size_tag(); |
| 8453 | #ifdef DEBUG |
| 8454 | inline uint32_t type() { return type_; } |
| 8455 | inline void invalidate() { valid_ = false; } |
| 8456 | inline bool valid() { return valid_; } |
| 8457 | #else |
| 8458 | inline void invalidate() { } |
| 8459 | #endif |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 8460 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8461 | private: |
| 8462 | uint32_t type_; |
| 8463 | #ifdef DEBUG |
| 8464 | inline void set_valid() { valid_ = true; } |
| 8465 | bool valid_; |
| 8466 | #else |
| 8467 | inline void set_valid() { } |
| 8468 | #endif |
| 8469 | }; |
| 8470 | |
| 8471 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8472 | // The Name abstract class captures anything that can be used as a property |
| 8473 | // name, i.e., strings and symbols. All names store a hash value. |
| 8474 | class Name: public HeapObject { |
| 8475 | public: |
| 8476 | // Get and set the hash field of the name. |
| 8477 | inline uint32_t hash_field(); |
| 8478 | inline void set_hash_field(uint32_t value); |
| 8479 | |
| 8480 | // Tells whether the hash code has been computed. |
| 8481 | inline bool HasHashCode(); |
| 8482 | |
| 8483 | // Returns a hash value used for the property table |
| 8484 | inline uint32_t Hash(); |
| 8485 | |
| 8486 | // Equality operations. |
| 8487 | inline bool Equals(Name* other); |
| 8488 | inline static bool Equals(Handle<Name> one, Handle<Name> two); |
| 8489 | |
| 8490 | // Conversion. |
| 8491 | inline bool AsArrayIndex(uint32_t* index); |
| 8492 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8493 | // If the name is private, it can only name own properties. |
| 8494 | inline bool IsPrivate(); |
| 8495 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 8496 | inline bool IsUniqueName() const; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8497 | |
| 8498 | // Return a string version of this name that is converted according to the |
| 8499 | // rules described in ES6 section 9.2.11. |
| 8500 | MUST_USE_RESULT static MaybeHandle<String> ToFunctionName(Handle<Name> name); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8501 | |
| 8502 | DECLARE_CAST(Name) |
| 8503 | |
| 8504 | DECLARE_PRINTER(Name) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8505 | #if TRACE_MAPS |
| 8506 | void NameShortPrint(); |
| 8507 | int NameShortPrint(Vector<char> str); |
| 8508 | #endif |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8509 | |
| 8510 | // Layout description. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8511 | static const int kHashFieldSlot = HeapObject::kHeaderSize; |
| 8512 | #if V8_TARGET_LITTLE_ENDIAN || !V8_HOST_ARCH_64_BIT |
| 8513 | static const int kHashFieldOffset = kHashFieldSlot; |
| 8514 | #else |
| 8515 | static const int kHashFieldOffset = kHashFieldSlot + kIntSize; |
| 8516 | #endif |
| 8517 | static const int kSize = kHashFieldSlot + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8518 | |
| 8519 | // Mask constant for checking if a name has a computed hash code |
| 8520 | // and if it is a string that is an array index. The least significant bit |
| 8521 | // indicates whether a hash code has been computed. If the hash code has |
| 8522 | // been computed the 2nd bit tells whether the string can be used as an |
| 8523 | // array index. |
| 8524 | static const int kHashNotComputedMask = 1; |
| 8525 | static const int kIsNotArrayIndexMask = 1 << 1; |
| 8526 | static const int kNofHashBitFields = 2; |
| 8527 | |
| 8528 | // Shift constant retrieving hash code from hash field. |
| 8529 | static const int kHashShift = kNofHashBitFields; |
| 8530 | |
| 8531 | // Only these bits are relevant in the hash, since the top two are shifted |
| 8532 | // out. |
| 8533 | static const uint32_t kHashBitMask = 0xffffffffu >> kHashShift; |
| 8534 | |
| 8535 | // Array index strings this short can keep their index in the hash field. |
| 8536 | static const int kMaxCachedArrayIndexLength = 7; |
| 8537 | |
| 8538 | // For strings which are array indexes the hash value has the string length |
| 8539 | // mixed into the hash, mainly to avoid a hash value of zero which would be |
| 8540 | // the case for the string '0'. 24 bits are used for the array index value. |
| 8541 | static const int kArrayIndexValueBits = 24; |
| 8542 | static const int kArrayIndexLengthBits = |
| 8543 | kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields; |
| 8544 | |
| 8545 | STATIC_ASSERT((kArrayIndexLengthBits > 0)); |
| 8546 | |
| 8547 | class ArrayIndexValueBits : public BitField<unsigned int, kNofHashBitFields, |
| 8548 | kArrayIndexValueBits> {}; // NOLINT |
| 8549 | class ArrayIndexLengthBits : public BitField<unsigned int, |
| 8550 | kNofHashBitFields + kArrayIndexValueBits, |
| 8551 | kArrayIndexLengthBits> {}; // NOLINT |
| 8552 | |
| 8553 | // Check that kMaxCachedArrayIndexLength + 1 is a power of two so we |
| 8554 | // could use a mask to test if the length of string is less than or equal to |
| 8555 | // kMaxCachedArrayIndexLength. |
| 8556 | STATIC_ASSERT(IS_POWER_OF_TWO(kMaxCachedArrayIndexLength + 1)); |
| 8557 | |
| 8558 | static const unsigned int kContainsCachedArrayIndexMask = |
| 8559 | (~static_cast<unsigned>(kMaxCachedArrayIndexLength) |
| 8560 | << ArrayIndexLengthBits::kShift) | |
| 8561 | kIsNotArrayIndexMask; |
| 8562 | |
| 8563 | // Value of empty hash field indicating that the hash is not computed. |
| 8564 | static const int kEmptyHashField = |
| 8565 | kIsNotArrayIndexMask | kHashNotComputedMask; |
| 8566 | |
| 8567 | protected: |
| 8568 | static inline bool IsHashFieldComputed(uint32_t field); |
| 8569 | |
| 8570 | private: |
| 8571 | DISALLOW_IMPLICIT_CONSTRUCTORS(Name); |
| 8572 | }; |
| 8573 | |
| 8574 | |
| 8575 | // ES6 symbols. |
| 8576 | class Symbol: public Name { |
| 8577 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8578 | // [name]: The print name of a symbol, or undefined if none. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8579 | DECL_ACCESSORS(name, Object) |
| 8580 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8581 | DECL_INT_ACCESSORS(flags) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8582 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8583 | // [is_private]: Whether this is a private symbol. Private symbols can only |
| 8584 | // be used to designate own properties of objects. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8585 | DECL_BOOLEAN_ACCESSORS(is_private) |
| 8586 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8587 | // [is_well_known_symbol]: Whether this is a spec-defined well-known symbol, |
| 8588 | // or not. Well-known symbols do not throw when an access check fails during |
| 8589 | // a load. |
| 8590 | DECL_BOOLEAN_ACCESSORS(is_well_known_symbol) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8591 | |
| 8592 | DECLARE_CAST(Symbol) |
| 8593 | |
| 8594 | // Dispatched behavior. |
| 8595 | DECLARE_PRINTER(Symbol) |
| 8596 | DECLARE_VERIFIER(Symbol) |
| 8597 | |
| 8598 | // Layout description. |
| 8599 | static const int kNameOffset = Name::kSize; |
| 8600 | static const int kFlagsOffset = kNameOffset + kPointerSize; |
| 8601 | static const int kSize = kFlagsOffset + kPointerSize; |
| 8602 | |
| 8603 | typedef FixedBodyDescriptor<kNameOffset, kFlagsOffset, kSize> BodyDescriptor; |
| 8604 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8605 | void SymbolShortPrint(std::ostream& os); |
| 8606 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8607 | private: |
| 8608 | static const int kPrivateBit = 0; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8609 | static const int kWellKnownSymbolBit = 1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8610 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8611 | const char* PrivateSymbolToName() const; |
| 8612 | |
| 8613 | #if TRACE_MAPS |
| 8614 | friend class Name; // For PrivateSymbolToName. |
| 8615 | #endif |
| 8616 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8617 | DISALLOW_IMPLICIT_CONSTRUCTORS(Symbol); |
| 8618 | }; |
| 8619 | |
| 8620 | |
| 8621 | class ConsString; |
| 8622 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8623 | // The String abstract class captures JavaScript string values: |
| 8624 | // |
| 8625 | // Ecma-262: |
| 8626 | // 4.3.16 String Value |
| 8627 | // A string value is a member of the type String and is a finite |
| 8628 | // ordered sequence of zero or more 16-bit unsigned integer values. |
| 8629 | // |
| 8630 | // All string values have a length field. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8631 | class String: public Name { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8632 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8633 | enum Encoding { ONE_BYTE_ENCODING, TWO_BYTE_ENCODING }; |
| 8634 | |
| 8635 | // Array index strings this short can keep their index in the hash field. |
| 8636 | static const int kMaxCachedArrayIndexLength = 7; |
| 8637 | |
| 8638 | // For strings which are array indexes the hash value has the string length |
| 8639 | // mixed into the hash, mainly to avoid a hash value of zero which would be |
| 8640 | // the case for the string '0'. 24 bits are used for the array index value. |
| 8641 | static const int kArrayIndexValueBits = 24; |
| 8642 | static const int kArrayIndexLengthBits = |
| 8643 | kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields; |
| 8644 | |
| 8645 | STATIC_ASSERT((kArrayIndexLengthBits > 0)); |
| 8646 | |
| 8647 | class ArrayIndexValueBits : public BitField<unsigned int, kNofHashBitFields, |
| 8648 | kArrayIndexValueBits> {}; // NOLINT |
| 8649 | class ArrayIndexLengthBits : public BitField<unsigned int, |
| 8650 | kNofHashBitFields + kArrayIndexValueBits, |
| 8651 | kArrayIndexLengthBits> {}; // NOLINT |
| 8652 | |
| 8653 | // Check that kMaxCachedArrayIndexLength + 1 is a power of two so we |
| 8654 | // could use a mask to test if the length of string is less than or equal to |
| 8655 | // kMaxCachedArrayIndexLength. |
| 8656 | STATIC_ASSERT(IS_POWER_OF_TWO(kMaxCachedArrayIndexLength + 1)); |
| 8657 | |
| 8658 | static const unsigned int kContainsCachedArrayIndexMask = |
| 8659 | (~static_cast<unsigned>(kMaxCachedArrayIndexLength) |
| 8660 | << ArrayIndexLengthBits::kShift) | |
| 8661 | kIsNotArrayIndexMask; |
| 8662 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8663 | class SubStringRange { |
| 8664 | public: |
| 8665 | explicit inline SubStringRange(String* string, int first = 0, |
| 8666 | int length = -1); |
| 8667 | class iterator; |
| 8668 | inline iterator begin(); |
| 8669 | inline iterator end(); |
| 8670 | |
| 8671 | private: |
| 8672 | String* string_; |
| 8673 | int first_; |
| 8674 | int length_; |
| 8675 | }; |
| 8676 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8677 | // Representation of the flat content of a String. |
| 8678 | // A non-flat string doesn't have flat content. |
| 8679 | // A flat string has content that's encoded as a sequence of either |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8680 | // one-byte chars or two-byte UC16. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8681 | // Returned by String::GetFlatContent(). |
| 8682 | class FlatContent { |
| 8683 | public: |
| 8684 | // Returns true if the string is flat and this structure contains content. |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 8685 | bool IsFlat() const { return state_ != NON_FLAT; } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8686 | // Returns true if the structure contains one-byte content. |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 8687 | bool IsOneByte() const { return state_ == ONE_BYTE; } |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8688 | // Returns true if the structure contains two-byte content. |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 8689 | bool IsTwoByte() const { return state_ == TWO_BYTE; } |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8690 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8691 | // Return the one byte content of the string. Only use if IsOneByte() |
| 8692 | // returns true. |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 8693 | Vector<const uint8_t> ToOneByteVector() const { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8694 | DCHECK_EQ(ONE_BYTE, state_); |
| 8695 | return Vector<const uint8_t>(onebyte_start, length_); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8696 | } |
| 8697 | // Return the two-byte content of the string. Only use if IsTwoByte() |
| 8698 | // returns true. |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 8699 | Vector<const uc16> ToUC16Vector() const { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8700 | DCHECK_EQ(TWO_BYTE, state_); |
| 8701 | return Vector<const uc16>(twobyte_start, length_); |
| 8702 | } |
| 8703 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 8704 | uc16 Get(int i) const { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8705 | DCHECK(i < length_); |
| 8706 | DCHECK(state_ != NON_FLAT); |
| 8707 | if (state_ == ONE_BYTE) return onebyte_start[i]; |
| 8708 | return twobyte_start[i]; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8709 | } |
| 8710 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8711 | bool UsesSameString(const FlatContent& other) const { |
| 8712 | return onebyte_start == other.onebyte_start; |
| 8713 | } |
| 8714 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8715 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8716 | enum State { NON_FLAT, ONE_BYTE, TWO_BYTE }; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8717 | |
| 8718 | // Constructors only used by String::GetFlatContent(). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8719 | explicit FlatContent(const uint8_t* start, int length) |
| 8720 | : onebyte_start(start), length_(length), state_(ONE_BYTE) {} |
| 8721 | explicit FlatContent(const uc16* start, int length) |
| 8722 | : twobyte_start(start), length_(length), state_(TWO_BYTE) { } |
| 8723 | FlatContent() : onebyte_start(NULL), length_(0), state_(NON_FLAT) { } |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8724 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8725 | union { |
| 8726 | const uint8_t* onebyte_start; |
| 8727 | const uc16* twobyte_start; |
| 8728 | }; |
| 8729 | int length_; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8730 | State state_; |
| 8731 | |
| 8732 | friend class String; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8733 | friend class IterableSubString; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8734 | }; |
| 8735 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8736 | template <typename Char> |
| 8737 | INLINE(Vector<const Char> GetCharVector()); |
| 8738 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8739 | // Get and set the length of the string. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8740 | inline int length() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8741 | inline void set_length(int value); |
| 8742 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8743 | // Get and set the length of the string using acquire loads and release |
| 8744 | // stores. |
| 8745 | inline int synchronized_length() const; |
| 8746 | inline void synchronized_set_length(int value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8747 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8748 | // Returns whether this string has only one-byte chars, i.e. all of them can |
| 8749 | // be one-byte encoded. This might be the case even if the string is |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8750 | // two-byte. Such strings may appear when the embedder prefers |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8751 | // two-byte external representations even for one-byte data. |
| 8752 | inline bool IsOneByteRepresentation() const; |
| 8753 | inline bool IsTwoByteRepresentation() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8754 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8755 | // Cons and slices have an encoding flag that may not represent the actual |
| 8756 | // encoding of the underlying string. This is taken into account here. |
| 8757 | // Requires: this->IsFlat() |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8758 | inline bool IsOneByteRepresentationUnderneath(); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8759 | inline bool IsTwoByteRepresentationUnderneath(); |
| 8760 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 8761 | // NOTE: this should be considered only a hint. False negatives are |
| 8762 | // possible. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8763 | inline bool HasOnlyOneByteChars(); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8764 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8765 | // Get and set individual two byte chars in the string. |
| 8766 | inline void Set(int index, uint16_t value); |
| 8767 | // Get individual two byte char in the string. Repeated calls |
| 8768 | // to this method are not efficient unless the string is flat. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8769 | INLINE(uint16_t Get(int index)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8770 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8771 | // ES6 section 7.1.3.1 ToNumber Applied to the String Type |
| 8772 | static Handle<Object> ToNumber(Handle<String> subject); |
| 8773 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8774 | // Flattens the string. Checks first inline to see if it is |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 8775 | // necessary. Does nothing if the string is not a cons string. |
| 8776 | // Flattening allocates a sequential string with the same data as |
| 8777 | // the given string and mutates the cons string to a degenerate |
| 8778 | // form, where the first component is the new sequential string and |
| 8779 | // the second component is the empty string. If allocation fails, |
| 8780 | // this function returns a failure. If flattening succeeds, this |
| 8781 | // function returns the sequential string that is now the first |
| 8782 | // component of the cons string. |
| 8783 | // |
| 8784 | // Degenerate cons strings are handled specially by the garbage |
| 8785 | // collector (see IsShortcutCandidate). |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8786 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8787 | static inline Handle<String> Flatten(Handle<String> string, |
| 8788 | PretenureFlag pretenure = NOT_TENURED); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 8789 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8790 | // Tries to return the content of a flat string as a structure holding either |
| 8791 | // a flat vector of char or of uc16. |
| 8792 | // If the string isn't flat, and therefore doesn't have flat content, the |
| 8793 | // returned structure will report so, and can't provide a vector of either |
| 8794 | // kind. |
| 8795 | FlatContent GetFlatContent(); |
| 8796 | |
| 8797 | // Returns the parent of a sliced string or first part of a flat cons string. |
| 8798 | // Requires: StringShape(this).IsIndirect() && this->IsFlat() |
| 8799 | inline String* GetUnderlying(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8800 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8801 | // String relational comparison, implemented according to ES6 section 7.2.11 |
| 8802 | // Abstract Relational Comparison (step 5): The comparison of Strings uses a |
| 8803 | // simple lexicographic ordering on sequences of code unit values. There is no |
| 8804 | // attempt to use the more complex, semantically oriented definitions of |
| 8805 | // character or string equality and collating order defined in the Unicode |
| 8806 | // specification. Therefore String values that are canonically equal according |
| 8807 | // to the Unicode standard could test as unequal. In effect this algorithm |
| 8808 | // assumes that both Strings are already in normalized form. Also, note that |
| 8809 | // for strings containing supplementary characters, lexicographic ordering on |
| 8810 | // sequences of UTF-16 code unit values differs from that on sequences of code |
| 8811 | // point values. |
| 8812 | MUST_USE_RESULT static ComparisonResult Compare(Handle<String> x, |
| 8813 | Handle<String> y); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8814 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8815 | // String equality operations. |
| 8816 | inline bool Equals(String* other); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8817 | inline static bool Equals(Handle<String> one, Handle<String> two); |
| 8818 | bool IsUtf8EqualTo(Vector<const char> str, bool allow_prefix_match = false); |
| 8819 | bool IsOneByteEqualTo(Vector<const uint8_t> str); |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 8820 | bool IsTwoByteEqualTo(Vector<const uc16> str); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8821 | |
| 8822 | // Return a UTF8 representation of the string. The string is null |
| 8823 | // terminated but may optionally contain nulls. Length is returned |
| 8824 | // in length_output if length_output is not a null pointer The string |
| 8825 | // should be nearly flat, otherwise the performance of this method may |
| 8826 | // be very slow (quadratic in the length). Setting robustness_flag to |
| 8827 | // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it |
| 8828 | // handles unexpected data without causing assert failures and it does not |
| 8829 | // do any heap allocations. This is useful when printing stack traces. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8830 | base::SmartArrayPointer<char> ToCString(AllowNullsFlag allow_nulls, |
| 8831 | RobustnessFlag robustness_flag, |
| 8832 | int offset, int length, |
| 8833 | int* length_output = 0); |
| 8834 | base::SmartArrayPointer<char> ToCString( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8835 | AllowNullsFlag allow_nulls = DISALLOW_NULLS, |
| 8836 | RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL, |
| 8837 | int* length_output = 0); |
| 8838 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8839 | bool ComputeArrayIndex(uint32_t* index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8840 | |
| 8841 | // Externalization. |
| 8842 | bool MakeExternal(v8::String::ExternalStringResource* resource); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8843 | bool MakeExternal(v8::String::ExternalOneByteStringResource* resource); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8844 | |
| 8845 | // Conversion. |
| 8846 | inline bool AsArrayIndex(uint32_t* index); |
| 8847 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8848 | DECLARE_CAST(String) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8849 | |
| 8850 | void PrintOn(FILE* out); |
| 8851 | |
| 8852 | // For use during stack traces. Performs rudimentary sanity check. |
| 8853 | bool LooksValid(); |
| 8854 | |
| 8855 | // Dispatched behavior. |
| 8856 | void StringShortPrint(StringStream* accumulator); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8857 | void PrintUC16(std::ostream& os, int start = 0, int end = -1); // NOLINT |
| 8858 | #if defined(DEBUG) || defined(OBJECT_PRINT) |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8859 | char* ToAsciiArray(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 8860 | #endif |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8861 | DECLARE_PRINTER(String) |
| 8862 | DECLARE_VERIFIER(String) |
| 8863 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8864 | inline bool IsFlat(); |
| 8865 | |
| 8866 | // Layout description. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8867 | static const int kLengthOffset = Name::kSize; |
| 8868 | static const int kSize = kLengthOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8869 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 8870 | // Maximum number of characters to consider when trying to convert a string |
| 8871 | // value into an array index. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8872 | static const int kMaxArrayIndexSize = 10; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8873 | STATIC_ASSERT(kMaxArrayIndexSize < (1 << kArrayIndexLengthBits)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8874 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8875 | // Max char codes. |
| 8876 | static const int32_t kMaxOneByteCharCode = unibrow::Latin1::kMaxChar; |
| 8877 | static const uint32_t kMaxOneByteCharCodeU = unibrow::Latin1::kMaxChar; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8878 | static const int kMaxUtf16CodeUnit = 0xffff; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8879 | static const uint32_t kMaxUtf16CodeUnitU = kMaxUtf16CodeUnit; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 8880 | static const uc32 kMaxCodePoint = 0x10ffff; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 8881 | |
| 8882 | // Maximal string length. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8883 | static const int kMaxLength = (1 << 28) - 16; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 8884 | |
| 8885 | // Max length for computing hash. For strings longer than this limit the |
| 8886 | // string length is used as the hash value. |
| 8887 | static const int kMaxHashCalcLength = 16383; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8888 | |
| 8889 | // Limit for truncation in short printing. |
| 8890 | static const int kMaxShortPrintLength = 1024; |
| 8891 | |
| 8892 | // Support for regular expressions. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8893 | const uc16* GetTwoByteData(unsigned start); |
| 8894 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8895 | // Helper function for flattening strings. |
| 8896 | template <typename sinkchar> |
| 8897 | static void WriteToFlat(String* source, |
| 8898 | sinkchar* sink, |
| 8899 | int from, |
| 8900 | int to); |
| 8901 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8902 | // The return value may point to the first aligned word containing the first |
| 8903 | // non-one-byte character, rather than directly to the non-one-byte character. |
| 8904 | // If the return value is >= the passed length, the entire string was |
| 8905 | // one-byte. |
| 8906 | static inline int NonAsciiStart(const char* chars, int length) { |
| 8907 | const char* start = chars; |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 8908 | const char* limit = chars + length; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8909 | |
| 8910 | if (length >= kIntptrSize) { |
| 8911 | // Check unaligned bytes. |
| 8912 | while (!IsAligned(reinterpret_cast<intptr_t>(chars), sizeof(uintptr_t))) { |
| 8913 | if (static_cast<uint8_t>(*chars) > unibrow::Utf8::kMaxOneByteChar) { |
| 8914 | return static_cast<int>(chars - start); |
| 8915 | } |
| 8916 | ++chars; |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 8917 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8918 | // Check aligned words. |
| 8919 | DCHECK(unibrow::Utf8::kMaxOneByteChar == 0x7F); |
| 8920 | const uintptr_t non_one_byte_mask = kUintptrAllBitsSet / 0xFF * 0x80; |
| 8921 | while (chars + sizeof(uintptr_t) <= limit) { |
| 8922 | if (*reinterpret_cast<const uintptr_t*>(chars) & non_one_byte_mask) { |
| 8923 | return static_cast<int>(chars - start); |
| 8924 | } |
| 8925 | chars += sizeof(uintptr_t); |
| 8926 | } |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 8927 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8928 | // Check remaining unaligned bytes. |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 8929 | while (chars < limit) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8930 | if (static_cast<uint8_t>(*chars) > unibrow::Utf8::kMaxOneByteChar) { |
| 8931 | return static_cast<int>(chars - start); |
| 8932 | } |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 8933 | ++chars; |
| 8934 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8935 | |
| 8936 | return static_cast<int>(chars - start); |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 8937 | } |
| 8938 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8939 | static inline bool IsAscii(const char* chars, int length) { |
| 8940 | return NonAsciiStart(chars, length) >= length; |
| 8941 | } |
| 8942 | |
| 8943 | static inline bool IsAscii(const uint8_t* chars, int length) { |
| 8944 | return |
| 8945 | NonAsciiStart(reinterpret_cast<const char*>(chars), length) >= length; |
| 8946 | } |
| 8947 | |
| 8948 | static inline int NonOneByteStart(const uc16* chars, int length) { |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 8949 | const uc16* limit = chars + length; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8950 | const uc16* start = chars; |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 8951 | while (chars < limit) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8952 | if (*chars > kMaxOneByteCharCodeU) return static_cast<int>(chars - start); |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 8953 | ++chars; |
| 8954 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8955 | return static_cast<int>(chars - start); |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 8956 | } |
| 8957 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8958 | static inline bool IsOneByte(const uc16* chars, int length) { |
| 8959 | return NonOneByteStart(chars, length) >= length; |
| 8960 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8961 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8962 | template<class Visitor> |
| 8963 | static inline ConsString* VisitFlat(Visitor* visitor, |
| 8964 | String* string, |
| 8965 | int offset = 0); |
| 8966 | |
| 8967 | static Handle<FixedArray> CalculateLineEnds(Handle<String> string, |
| 8968 | bool include_ending_line); |
| 8969 | |
| 8970 | // Use the hash field to forward to the canonical internalized string |
| 8971 | // when deserializing an internalized string. |
| 8972 | inline void SetForwardedInternalizedString(String* string); |
| 8973 | inline String* GetForwardedInternalizedString(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8974 | |
| 8975 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8976 | friend class Name; |
| 8977 | friend class StringTableInsertionKey; |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 8978 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8979 | static Handle<String> SlowFlatten(Handle<ConsString> cons, |
| 8980 | PretenureFlag tenure); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 8981 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8982 | // Slow case of String::Equals. This implementation works on any strings |
| 8983 | // but it is most efficient on strings that are almost flat. |
| 8984 | bool SlowEquals(String* other); |
| 8985 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8986 | static bool SlowEquals(Handle<String> one, Handle<String> two); |
| 8987 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8988 | // Slow case of AsArrayIndex. |
| 8989 | bool SlowAsArrayIndex(uint32_t* index); |
| 8990 | |
| 8991 | // Compute and set the hash code. |
| 8992 | uint32_t ComputeAndSetHash(); |
| 8993 | |
| 8994 | DISALLOW_IMPLICIT_CONSTRUCTORS(String); |
| 8995 | }; |
| 8996 | |
| 8997 | |
| 8998 | // The SeqString abstract class captures sequential string values. |
| 8999 | class SeqString: public String { |
| 9000 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9001 | DECLARE_CAST(SeqString) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9002 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9003 | // Layout description. |
| 9004 | static const int kHeaderSize = String::kSize; |
| 9005 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9006 | // Truncate the string in-place if possible and return the result. |
| 9007 | // In case of new_length == 0, the empty string is returned without |
| 9008 | // truncating the original string. |
| 9009 | MUST_USE_RESULT static Handle<String> Truncate(Handle<SeqString> string, |
| 9010 | int new_length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9011 | private: |
| 9012 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqString); |
| 9013 | }; |
| 9014 | |
| 9015 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9016 | // The OneByteString class captures sequential one-byte string objects. |
| 9017 | // Each character in the OneByteString is an one-byte character. |
| 9018 | class SeqOneByteString: public SeqString { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9019 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9020 | static const bool kHasOneByteEncoding = true; |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 9021 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9022 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9023 | inline uint16_t SeqOneByteStringGet(int index); |
| 9024 | inline void SeqOneByteStringSet(int index, uint16_t value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9025 | |
| 9026 | // Get the address of the characters in this string. |
| 9027 | inline Address GetCharsAddress(); |
| 9028 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9029 | inline uint8_t* GetChars(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9030 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9031 | DECLARE_CAST(SeqOneByteString) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9032 | |
| 9033 | // Garbage collection support. This method is called by the |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9034 | // garbage collector to compute the actual size of an OneByteString |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9035 | // instance. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9036 | inline int SeqOneByteStringSize(InstanceType instance_type); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9037 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9038 | // Computes the size for an OneByteString instance of a given length. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9039 | static int SizeFor(int length) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 9040 | return OBJECT_POINTER_ALIGN(kHeaderSize + length * kCharSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9041 | } |
| 9042 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9043 | // Maximal memory usage for a single sequential one-byte string. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9044 | static const int kMaxSize = 512 * MB - 1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9045 | STATIC_ASSERT((kMaxSize - kHeaderSize) >= String::kMaxLength); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9046 | |
| 9047 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9048 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqOneByteString); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9049 | }; |
| 9050 | |
| 9051 | |
| 9052 | // The TwoByteString class captures sequential unicode string objects. |
| 9053 | // Each character in the TwoByteString is a two-byte uint16_t. |
| 9054 | class SeqTwoByteString: public SeqString { |
| 9055 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9056 | static const bool kHasOneByteEncoding = false; |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 9057 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9058 | // Dispatched behavior. |
| 9059 | inline uint16_t SeqTwoByteStringGet(int index); |
| 9060 | inline void SeqTwoByteStringSet(int index, uint16_t value); |
| 9061 | |
| 9062 | // Get the address of the characters in this string. |
| 9063 | inline Address GetCharsAddress(); |
| 9064 | |
| 9065 | inline uc16* GetChars(); |
| 9066 | |
| 9067 | // For regexp code. |
| 9068 | const uint16_t* SeqTwoByteStringGetData(unsigned start); |
| 9069 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9070 | DECLARE_CAST(SeqTwoByteString) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9071 | |
| 9072 | // Garbage collection support. This method is called by the |
| 9073 | // garbage collector to compute the actual size of a TwoByteString |
| 9074 | // instance. |
| 9075 | inline int SeqTwoByteStringSize(InstanceType instance_type); |
| 9076 | |
| 9077 | // Computes the size for a TwoByteString instance of a given length. |
| 9078 | static int SizeFor(int length) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 9079 | return OBJECT_POINTER_ALIGN(kHeaderSize + length * kShortSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9080 | } |
| 9081 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 9082 | // Maximal memory usage for a single sequential two-byte string. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9083 | static const int kMaxSize = 512 * MB - 1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9084 | STATIC_ASSERT(static_cast<int>((kMaxSize - kHeaderSize)/sizeof(uint16_t)) >= |
| 9085 | String::kMaxLength); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9086 | |
| 9087 | private: |
| 9088 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqTwoByteString); |
| 9089 | }; |
| 9090 | |
| 9091 | |
| 9092 | // The ConsString class describes string values built by using the |
| 9093 | // addition operator on strings. A ConsString is a pair where the |
| 9094 | // first and second components are pointers to other string values. |
| 9095 | // One or both components of a ConsString can be pointers to other |
| 9096 | // ConsStrings, creating a binary tree of ConsStrings where the leaves |
| 9097 | // are non-ConsString string values. The string value represented by |
| 9098 | // a ConsString can be obtained by concatenating the leaf string |
| 9099 | // values in a left-to-right depth-first traversal of the tree. |
| 9100 | class ConsString: public String { |
| 9101 | public: |
| 9102 | // First string of the cons cell. |
| 9103 | inline String* first(); |
| 9104 | // Doesn't check that the result is a string, even in debug mode. This is |
| 9105 | // useful during GC where the mark bits confuse the checks. |
| 9106 | inline Object* unchecked_first(); |
| 9107 | inline void set_first(String* first, |
| 9108 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| 9109 | |
| 9110 | // Second string of the cons cell. |
| 9111 | inline String* second(); |
| 9112 | // Doesn't check that the result is a string, even in debug mode. This is |
| 9113 | // useful during GC where the mark bits confuse the checks. |
| 9114 | inline Object* unchecked_second(); |
| 9115 | inline void set_second(String* second, |
| 9116 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| 9117 | |
| 9118 | // Dispatched behavior. |
| 9119 | uint16_t ConsStringGet(int index); |
| 9120 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9121 | DECLARE_CAST(ConsString) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9122 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9123 | // Layout description. |
| 9124 | static const int kFirstOffset = POINTER_SIZE_ALIGN(String::kSize); |
| 9125 | static const int kSecondOffset = kFirstOffset + kPointerSize; |
| 9126 | static const int kSize = kSecondOffset + kPointerSize; |
| 9127 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9128 | // Minimum length for a cons string. |
| 9129 | static const int kMinLength = 13; |
| 9130 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 9131 | typedef FixedBodyDescriptor<kFirstOffset, kSecondOffset + kPointerSize, kSize> |
| 9132 | BodyDescriptor; |
| 9133 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9134 | DECLARE_VERIFIER(ConsString) |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 9135 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9136 | private: |
| 9137 | DISALLOW_IMPLICIT_CONSTRUCTORS(ConsString); |
| 9138 | }; |
| 9139 | |
| 9140 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 9141 | // The Sliced String class describes strings that are substrings of another |
| 9142 | // sequential string. The motivation is to save time and memory when creating |
| 9143 | // a substring. A Sliced String is described as a pointer to the parent, |
| 9144 | // the offset from the start of the parent string and the length. Using |
| 9145 | // a Sliced String therefore requires unpacking of the parent string and |
| 9146 | // adding the offset to the start address. A substring of a Sliced String |
| 9147 | // are not nested since the double indirection is simplified when creating |
| 9148 | // such a substring. |
| 9149 | // Currently missing features are: |
| 9150 | // - handling externalized parent strings |
| 9151 | // - external strings as parent |
| 9152 | // - truncating sliced string to enable otherwise unneeded parent to be GC'ed. |
| 9153 | class SlicedString: public String { |
| 9154 | public: |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 9155 | inline String* parent(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9156 | inline void set_parent(String* parent, |
| 9157 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| 9158 | inline int offset() const; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 9159 | inline void set_offset(int offset); |
| 9160 | |
| 9161 | // Dispatched behavior. |
| 9162 | uint16_t SlicedStringGet(int index); |
| 9163 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9164 | DECLARE_CAST(SlicedString) |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 9165 | |
| 9166 | // Layout description. |
| 9167 | static const int kParentOffset = POINTER_SIZE_ALIGN(String::kSize); |
| 9168 | static const int kOffsetOffset = kParentOffset + kPointerSize; |
| 9169 | static const int kSize = kOffsetOffset + kPointerSize; |
| 9170 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 9171 | // Minimum length for a sliced string. |
| 9172 | static const int kMinLength = 13; |
| 9173 | |
| 9174 | typedef FixedBodyDescriptor<kParentOffset, |
| 9175 | kOffsetOffset + kPointerSize, kSize> |
| 9176 | BodyDescriptor; |
| 9177 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9178 | DECLARE_VERIFIER(SlicedString) |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 9179 | |
| 9180 | private: |
| 9181 | DISALLOW_IMPLICIT_CONSTRUCTORS(SlicedString); |
| 9182 | }; |
| 9183 | |
| 9184 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9185 | // The ExternalString class describes string values that are backed by |
| 9186 | // a string resource that lies outside the V8 heap. ExternalStrings |
| 9187 | // consist of the length field common to all strings, a pointer to the |
| 9188 | // external resource. It is important to ensure (externally) that the |
| 9189 | // resource is not deallocated while the ExternalString is live in the |
| 9190 | // V8 heap. |
| 9191 | // |
| 9192 | // The API expects that all ExternalStrings are created through the |
| 9193 | // API. Therefore, ExternalStrings should not be used internally. |
| 9194 | class ExternalString: public String { |
| 9195 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9196 | DECLARE_CAST(ExternalString) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9197 | |
| 9198 | // Layout description. |
| 9199 | static const int kResourceOffset = POINTER_SIZE_ALIGN(String::kSize); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9200 | static const int kShortSize = kResourceOffset + kPointerSize; |
| 9201 | static const int kResourceDataOffset = kResourceOffset + kPointerSize; |
| 9202 | static const int kSize = kResourceDataOffset + kPointerSize; |
| 9203 | |
| 9204 | // Return whether external string is short (data pointer is not cached). |
| 9205 | inline bool is_short(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9206 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9207 | STATIC_ASSERT(kResourceOffset == Internals::kStringResourceOffset); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9208 | |
| 9209 | private: |
| 9210 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalString); |
| 9211 | }; |
| 9212 | |
| 9213 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9214 | // The ExternalOneByteString class is an external string backed by an |
| 9215 | // one-byte string. |
| 9216 | class ExternalOneByteString : public ExternalString { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9217 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9218 | static const bool kHasOneByteEncoding = true; |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 9219 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9220 | typedef v8::String::ExternalOneByteStringResource Resource; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9221 | |
| 9222 | // The underlying resource. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9223 | inline const Resource* resource(); |
| 9224 | inline void set_resource(const Resource* buffer); |
| 9225 | |
| 9226 | // Update the pointer cache to the external character array. |
| 9227 | // The cached pointer is always valid, as the external character array does = |
| 9228 | // not move during lifetime. Deserialization is the only exception, after |
| 9229 | // which the pointer cache has to be refreshed. |
| 9230 | inline void update_data_cache(); |
| 9231 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9232 | inline const uint8_t* GetChars(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9233 | |
| 9234 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9235 | inline uint16_t ExternalOneByteStringGet(int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9236 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9237 | DECLARE_CAST(ExternalOneByteString) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9238 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9239 | class BodyDescriptor; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9240 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9241 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9242 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalOneByteString); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9243 | }; |
| 9244 | |
| 9245 | |
| 9246 | // The ExternalTwoByteString class is an external string backed by a UTF-16 |
| 9247 | // encoded string. |
| 9248 | class ExternalTwoByteString: public ExternalString { |
| 9249 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9250 | static const bool kHasOneByteEncoding = false; |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 9251 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9252 | typedef v8::String::ExternalStringResource Resource; |
| 9253 | |
| 9254 | // The underlying string resource. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9255 | inline const Resource* resource(); |
| 9256 | inline void set_resource(const Resource* buffer); |
| 9257 | |
| 9258 | // Update the pointer cache to the external character array. |
| 9259 | // The cached pointer is always valid, as the external character array does = |
| 9260 | // not move during lifetime. Deserialization is the only exception, after |
| 9261 | // which the pointer cache has to be refreshed. |
| 9262 | inline void update_data_cache(); |
| 9263 | |
| 9264 | inline const uint16_t* GetChars(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9265 | |
| 9266 | // Dispatched behavior. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9267 | inline uint16_t ExternalTwoByteStringGet(int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9268 | |
| 9269 | // For regexp code. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9270 | inline const uint16_t* ExternalTwoByteStringGetData(unsigned start); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9271 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9272 | DECLARE_CAST(ExternalTwoByteString) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9273 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9274 | class BodyDescriptor; |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 9275 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9276 | private: |
| 9277 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalTwoByteString); |
| 9278 | }; |
| 9279 | |
| 9280 | |
| 9281 | // Utility superclass for stack-allocated objects that must be updated |
| 9282 | // on gc. It provides two ways for the gc to update instances, either |
| 9283 | // iterating or updating after gc. |
| 9284 | class Relocatable BASE_EMBEDDED { |
| 9285 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 9286 | explicit inline Relocatable(Isolate* isolate); |
| 9287 | inline virtual ~Relocatable(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9288 | virtual void IterateInstance(ObjectVisitor* v) { } |
| 9289 | virtual void PostGarbageCollection() { } |
| 9290 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9291 | static void PostGarbageCollectionProcessing(Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9292 | static int ArchiveSpacePerThread(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 9293 | static char* ArchiveState(Isolate* isolate, char* to); |
| 9294 | static char* RestoreState(Isolate* isolate, char* from); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9295 | static void Iterate(Isolate* isolate, ObjectVisitor* v); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9296 | static void Iterate(ObjectVisitor* v, Relocatable* top); |
| 9297 | static char* Iterate(ObjectVisitor* v, char* t); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9298 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9299 | private: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 9300 | Isolate* isolate_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9301 | Relocatable* prev_; |
| 9302 | }; |
| 9303 | |
| 9304 | |
| 9305 | // A flat string reader provides random access to the contents of a |
| 9306 | // string independent of the character width of the string. The handle |
| 9307 | // must be valid as long as the reader is being used. |
| 9308 | class FlatStringReader : public Relocatable { |
| 9309 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 9310 | FlatStringReader(Isolate* isolate, Handle<String> str); |
| 9311 | FlatStringReader(Isolate* isolate, Vector<const char> input); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9312 | void PostGarbageCollection(); |
| 9313 | inline uc32 Get(int index); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 9314 | template <typename Char> |
| 9315 | inline Char Get(int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9316 | int length() { return length_; } |
| 9317 | private: |
| 9318 | String** str_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9319 | bool is_one_byte_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9320 | int length_; |
| 9321 | const void* start_; |
| 9322 | }; |
| 9323 | |
| 9324 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9325 | // This maintains an off-stack representation of the stack frames required |
| 9326 | // to traverse a ConsString, allowing an entirely iterative and restartable |
| 9327 | // traversal of the entire string |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 9328 | class ConsStringIterator { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9329 | public: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 9330 | inline ConsStringIterator() {} |
| 9331 | inline explicit ConsStringIterator(ConsString* cons_string, int offset = 0) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9332 | Reset(cons_string, offset); |
| 9333 | } |
| 9334 | inline void Reset(ConsString* cons_string, int offset = 0) { |
| 9335 | depth_ = 0; |
| 9336 | // Next will always return NULL. |
| 9337 | if (cons_string == NULL) return; |
| 9338 | Initialize(cons_string, offset); |
| 9339 | } |
| 9340 | // Returns NULL when complete. |
| 9341 | inline String* Next(int* offset_out) { |
| 9342 | *offset_out = 0; |
| 9343 | if (depth_ == 0) return NULL; |
| 9344 | return Continue(offset_out); |
| 9345 | } |
| 9346 | |
| 9347 | private: |
| 9348 | static const int kStackSize = 32; |
| 9349 | // Use a mask instead of doing modulo operations for stack wrapping. |
| 9350 | static const int kDepthMask = kStackSize-1; |
| 9351 | STATIC_ASSERT(IS_POWER_OF_TWO(kStackSize)); |
| 9352 | static inline int OffsetForDepth(int depth); |
| 9353 | |
| 9354 | inline void PushLeft(ConsString* string); |
| 9355 | inline void PushRight(ConsString* string); |
| 9356 | inline void AdjustMaximumDepth(); |
| 9357 | inline void Pop(); |
| 9358 | inline bool StackBlown() { return maximum_depth_ - depth_ == kStackSize; } |
| 9359 | void Initialize(ConsString* cons_string, int offset); |
| 9360 | String* Continue(int* offset_out); |
| 9361 | String* NextLeaf(bool* blew_stack); |
| 9362 | String* Search(int* offset_out); |
| 9363 | |
| 9364 | // Stack must always contain only frames for which right traversal |
| 9365 | // has not yet been performed. |
| 9366 | ConsString* frames_[kStackSize]; |
| 9367 | ConsString* root_; |
| 9368 | int depth_; |
| 9369 | int maximum_depth_; |
| 9370 | int consumed_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 9371 | DISALLOW_COPY_AND_ASSIGN(ConsStringIterator); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9372 | }; |
| 9373 | |
| 9374 | |
| 9375 | class StringCharacterStream { |
| 9376 | public: |
| 9377 | inline StringCharacterStream(String* string, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9378 | int offset = 0); |
| 9379 | inline uint16_t GetNext(); |
| 9380 | inline bool HasMore(); |
| 9381 | inline void Reset(String* string, int offset = 0); |
| 9382 | inline void VisitOneByteString(const uint8_t* chars, int length); |
| 9383 | inline void VisitTwoByteString(const uint16_t* chars, int length); |
| 9384 | |
| 9385 | private: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 9386 | ConsStringIterator iter_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9387 | bool is_one_byte_; |
| 9388 | union { |
| 9389 | const uint8_t* buffer8_; |
| 9390 | const uint16_t* buffer16_; |
| 9391 | }; |
| 9392 | const uint8_t* end_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9393 | DISALLOW_COPY_AND_ASSIGN(StringCharacterStream); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9394 | }; |
| 9395 | |
| 9396 | |
| 9397 | template <typename T> |
| 9398 | class VectorIterator { |
| 9399 | public: |
| 9400 | VectorIterator(T* d, int l) : data_(Vector<const T>(d, l)), index_(0) { } |
| 9401 | explicit VectorIterator(Vector<const T> data) : data_(data), index_(0) { } |
| 9402 | T GetNext() { return data_[index_++]; } |
| 9403 | bool has_more() { return index_ < data_.length(); } |
| 9404 | private: |
| 9405 | Vector<const T> data_; |
| 9406 | int index_; |
| 9407 | }; |
| 9408 | |
| 9409 | |
| 9410 | // The Oddball describes objects null, undefined, true, and false. |
| 9411 | class Oddball: public HeapObject { |
| 9412 | public: |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 9413 | // [to_number_raw]: Cached raw to_number computed at startup. |
| 9414 | inline double to_number_raw() const; |
| 9415 | inline void set_to_number_raw(double value); |
| 9416 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9417 | // [to_string]: Cached to_string computed at startup. |
| 9418 | DECL_ACCESSORS(to_string, String) |
| 9419 | |
| 9420 | // [to_number]: Cached to_number computed at startup. |
| 9421 | DECL_ACCESSORS(to_number, Object) |
| 9422 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 9423 | // [to_number]: Cached to_boolean computed at startup. |
| 9424 | DECL_ACCESSORS(to_boolean, Oddball) |
| 9425 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9426 | // [typeof]: Cached type_of computed at startup. |
| 9427 | DECL_ACCESSORS(type_of, String) |
| 9428 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9429 | inline byte kind() const; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 9430 | inline void set_kind(byte kind); |
| 9431 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9432 | // ES6 section 7.1.3 ToNumber for Boolean, Null, Undefined. |
| 9433 | MUST_USE_RESULT static inline Handle<Object> ToNumber(Handle<Oddball> input); |
| 9434 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9435 | DECLARE_CAST(Oddball) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9436 | |
| 9437 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9438 | DECLARE_VERIFIER(Oddball) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9439 | |
| 9440 | // Initialize the fields. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9441 | static void Initialize(Isolate* isolate, Handle<Oddball> oddball, |
| 9442 | const char* to_string, Handle<Object> to_number, |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 9443 | bool to_boolean, const char* type_of, byte kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9444 | |
| 9445 | // Layout description. |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 9446 | static const int kToNumberRawOffset = HeapObject::kHeaderSize; |
| 9447 | static const int kToStringOffset = kToNumberRawOffset + kDoubleSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9448 | static const int kToNumberOffset = kToStringOffset + kPointerSize; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 9449 | static const int kToBooleanOffset = kToNumberOffset + kPointerSize; |
| 9450 | static const int kTypeOfOffset = kToBooleanOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9451 | static const int kKindOffset = kTypeOfOffset + kPointerSize; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 9452 | static const int kSize = kKindOffset + kPointerSize; |
| 9453 | |
| 9454 | static const byte kFalse = 0; |
| 9455 | static const byte kTrue = 1; |
| 9456 | static const byte kNotBooleanMask = ~1; |
| 9457 | static const byte kTheHole = 2; |
| 9458 | static const byte kNull = 3; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 9459 | static const byte kArgumentsMarker = 4; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 9460 | static const byte kUndefined = 5; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9461 | static const byte kUninitialized = 6; |
| 9462 | static const byte kOther = 7; |
| 9463 | static const byte kException = 8; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 9464 | static const byte kOptimizedOut = 9; |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 9465 | static const byte kStaleRegister = 10; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9466 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9467 | typedef FixedBodyDescriptor<kToStringOffset, kTypeOfOffset + kPointerSize, |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 9468 | kSize> BodyDescriptor; |
| 9469 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 9470 | STATIC_ASSERT(kToNumberRawOffset == HeapNumber::kValueOffset); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9471 | STATIC_ASSERT(kKindOffset == Internals::kOddballKindOffset); |
| 9472 | STATIC_ASSERT(kNull == Internals::kNullOddballKind); |
| 9473 | STATIC_ASSERT(kUndefined == Internals::kUndefinedOddballKind); |
| 9474 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9475 | private: |
| 9476 | DISALLOW_IMPLICIT_CONSTRUCTORS(Oddball); |
| 9477 | }; |
| 9478 | |
| 9479 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9480 | class Cell: public HeapObject { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9481 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9482 | // [value]: value of the cell. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9483 | DECL_ACCESSORS(value, Object) |
| 9484 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9485 | DECLARE_CAST(Cell) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9486 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9487 | static inline Cell* FromValueAddress(Address value) { |
| 9488 | Object* result = FromAddress(value - kValueOffset); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9489 | return static_cast<Cell*>(result); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 9490 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9491 | |
| 9492 | inline Address ValueAddress() { |
| 9493 | return address() + kValueOffset; |
| 9494 | } |
| 9495 | |
| 9496 | // Dispatched behavior. |
| 9497 | DECLARE_PRINTER(Cell) |
| 9498 | DECLARE_VERIFIER(Cell) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9499 | |
| 9500 | // Layout description. |
| 9501 | static const int kValueOffset = HeapObject::kHeaderSize; |
| 9502 | static const int kSize = kValueOffset + kPointerSize; |
| 9503 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 9504 | typedef FixedBodyDescriptor<kValueOffset, |
| 9505 | kValueOffset + kPointerSize, |
| 9506 | kSize> BodyDescriptor; |
| 9507 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9508 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9509 | DISALLOW_IMPLICIT_CONSTRUCTORS(Cell); |
| 9510 | }; |
| 9511 | |
| 9512 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9513 | class PropertyCell : public HeapObject { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9514 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9515 | // [property_details]: details of the global property. |
| 9516 | DECL_ACCESSORS(property_details_raw, Object) |
| 9517 | // [value]: value of the global property. |
| 9518 | DECL_ACCESSORS(value, Object) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9519 | // [dependent_code]: dependent code that depends on the type of the global |
| 9520 | // property. |
| 9521 | DECL_ACCESSORS(dependent_code, DependentCode) |
| 9522 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9523 | inline PropertyDetails property_details(); |
| 9524 | inline void set_property_details(PropertyDetails details); |
| 9525 | |
| 9526 | PropertyCellConstantType GetConstantType(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9527 | |
| 9528 | // Computes the new type of the cell's contents for the given value, but |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9529 | // without actually modifying the details. |
| 9530 | static PropertyCellType UpdatedType(Handle<PropertyCell> cell, |
| 9531 | Handle<Object> value, |
| 9532 | PropertyDetails details); |
| 9533 | static void UpdateCell(Handle<GlobalDictionary> dictionary, int entry, |
| 9534 | Handle<Object> value, PropertyDetails details); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9535 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9536 | static Handle<PropertyCell> InvalidateEntry( |
| 9537 | Handle<GlobalDictionary> dictionary, int entry); |
| 9538 | |
| 9539 | static void SetValueWithInvalidation(Handle<PropertyCell> cell, |
| 9540 | Handle<Object> new_value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9541 | |
| 9542 | DECLARE_CAST(PropertyCell) |
| 9543 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9544 | // Dispatched behavior. |
| 9545 | DECLARE_PRINTER(PropertyCell) |
| 9546 | DECLARE_VERIFIER(PropertyCell) |
| 9547 | |
| 9548 | // Layout description. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9549 | static const int kDetailsOffset = HeapObject::kHeaderSize; |
| 9550 | static const int kValueOffset = kDetailsOffset + kPointerSize; |
| 9551 | static const int kDependentCodeOffset = kValueOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9552 | static const int kSize = kDependentCodeOffset + kPointerSize; |
| 9553 | |
| 9554 | static const int kPointerFieldsBeginOffset = kValueOffset; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9555 | static const int kPointerFieldsEndOffset = kSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9556 | |
| 9557 | typedef FixedBodyDescriptor<kValueOffset, |
| 9558 | kSize, |
| 9559 | kSize> BodyDescriptor; |
| 9560 | |
| 9561 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9562 | DISALLOW_IMPLICIT_CONSTRUCTORS(PropertyCell); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9563 | }; |
| 9564 | |
| 9565 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 9566 | class WeakCell : public HeapObject { |
| 9567 | public: |
| 9568 | inline Object* value() const; |
| 9569 | |
| 9570 | // This should not be called by anyone except GC. |
| 9571 | inline void clear(); |
| 9572 | |
| 9573 | // This should not be called by anyone except allocator. |
| 9574 | inline void initialize(HeapObject* value); |
| 9575 | |
| 9576 | inline bool cleared() const; |
| 9577 | |
| 9578 | DECL_ACCESSORS(next, Object) |
| 9579 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9580 | inline void clear_next(Object* the_hole_value); |
| 9581 | |
| 9582 | inline bool next_cleared(); |
| 9583 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 9584 | DECLARE_CAST(WeakCell) |
| 9585 | |
| 9586 | DECLARE_PRINTER(WeakCell) |
| 9587 | DECLARE_VERIFIER(WeakCell) |
| 9588 | |
| 9589 | // Layout description. |
| 9590 | static const int kValueOffset = HeapObject::kHeaderSize; |
| 9591 | static const int kNextOffset = kValueOffset + kPointerSize; |
| 9592 | static const int kSize = kNextOffset + kPointerSize; |
| 9593 | |
| 9594 | typedef FixedBodyDescriptor<kValueOffset, kSize, kSize> BodyDescriptor; |
| 9595 | |
| 9596 | private: |
| 9597 | DISALLOW_IMPLICIT_CONSTRUCTORS(WeakCell); |
| 9598 | }; |
| 9599 | |
| 9600 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 9601 | // The JSProxy describes EcmaScript Harmony proxies |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 9602 | class JSProxy: public JSReceiver { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9603 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9604 | MUST_USE_RESULT static MaybeHandle<JSProxy> New(Isolate* isolate, |
| 9605 | Handle<Object>, |
| 9606 | Handle<Object>); |
| 9607 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 9608 | // [handler]: The handler property. |
| 9609 | DECL_ACCESSORS(handler, Object) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9610 | // [target]: The target property. |
| 9611 | DECL_ACCESSORS(target, JSReceiver) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9612 | // [hash]: The hash code property (undefined if not initialized yet). |
| 9613 | DECL_ACCESSORS(hash, Object) |
| 9614 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9615 | static MaybeHandle<Context> GetFunctionRealm(Handle<JSProxy> proxy); |
| 9616 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9617 | DECLARE_CAST(JSProxy) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9618 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9619 | INLINE(bool IsRevoked() const); |
| 9620 | static void Revoke(Handle<JSProxy> proxy); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 9621 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9622 | // ES6 9.5.1 |
| 9623 | static MaybeHandle<Object> GetPrototype(Handle<JSProxy> receiver); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9624 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9625 | // ES6 9.5.2 |
| 9626 | MUST_USE_RESULT static Maybe<bool> SetPrototype(Handle<JSProxy> proxy, |
| 9627 | Handle<Object> value, |
| 9628 | bool from_javascript, |
| 9629 | ShouldThrow should_throw); |
| 9630 | // ES6 9.5.3 |
| 9631 | MUST_USE_RESULT static Maybe<bool> IsExtensible(Handle<JSProxy> proxy); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 9632 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9633 | // ES6 9.5.4 (when passed DONT_THROW) |
| 9634 | MUST_USE_RESULT static Maybe<bool> PreventExtensions( |
| 9635 | Handle<JSProxy> proxy, ShouldThrow should_throw); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 9636 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9637 | // ES6 9.5.5 |
| 9638 | MUST_USE_RESULT static Maybe<bool> GetOwnPropertyDescriptor( |
| 9639 | Isolate* isolate, Handle<JSProxy> proxy, Handle<Name> name, |
| 9640 | PropertyDescriptor* desc); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 9641 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9642 | // ES6 9.5.6 |
| 9643 | MUST_USE_RESULT static Maybe<bool> DefineOwnProperty( |
| 9644 | Isolate* isolate, Handle<JSProxy> object, Handle<Object> key, |
| 9645 | PropertyDescriptor* desc, ShouldThrow should_throw); |
| 9646 | |
| 9647 | // ES6 9.5.7 |
| 9648 | MUST_USE_RESULT static Maybe<bool> HasProperty(Isolate* isolate, |
| 9649 | Handle<JSProxy> proxy, |
| 9650 | Handle<Name> name); |
| 9651 | |
| 9652 | // ES6 9.5.8 |
| 9653 | MUST_USE_RESULT static MaybeHandle<Object> GetProperty( |
| 9654 | Isolate* isolate, Handle<JSProxy> proxy, Handle<Name> name, |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 9655 | Handle<Object> receiver, bool* was_found); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9656 | |
| 9657 | // ES6 9.5.9 |
| 9658 | MUST_USE_RESULT static Maybe<bool> SetProperty(Handle<JSProxy> proxy, |
| 9659 | Handle<Name> name, |
| 9660 | Handle<Object> value, |
| 9661 | Handle<Object> receiver, |
| 9662 | LanguageMode language_mode); |
| 9663 | |
| 9664 | // ES6 9.5.10 (when passed SLOPPY) |
| 9665 | MUST_USE_RESULT static Maybe<bool> DeletePropertyOrElement( |
| 9666 | Handle<JSProxy> proxy, Handle<Name> name, LanguageMode language_mode); |
| 9667 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9668 | // ES6 9.5.12 |
| 9669 | MUST_USE_RESULT static Maybe<bool> OwnPropertyKeys( |
| 9670 | Isolate* isolate, Handle<JSReceiver> receiver, Handle<JSProxy> proxy, |
| 9671 | PropertyFilter filter, KeyAccumulator* accumulator); |
| 9672 | |
| 9673 | MUST_USE_RESULT static Maybe<PropertyAttributes> GetPropertyAttributes( |
| 9674 | LookupIterator* it); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9675 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9676 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9677 | DECLARE_PRINTER(JSProxy) |
| 9678 | DECLARE_VERIFIER(JSProxy) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 9679 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9680 | // Layout description. |
| 9681 | static const int kTargetOffset = JSReceiver::kHeaderSize; |
| 9682 | static const int kHandlerOffset = kTargetOffset + kPointerSize; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9683 | static const int kHashOffset = kHandlerOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9684 | static const int kSize = kHashOffset + kPointerSize; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 9685 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9686 | typedef FixedBodyDescriptor<JSReceiver::kPropertiesOffset, kSize, kSize> |
| 9687 | BodyDescriptor; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9688 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 9689 | static Handle<Object> GetIdentityHash(Isolate* isolate, |
| 9690 | Handle<JSProxy> receiver); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9691 | |
| 9692 | static Handle<Smi> GetOrCreateIdentityHash(Handle<JSProxy> proxy); |
| 9693 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 9694 | static Maybe<bool> SetPrivateProperty(Isolate* isolate, Handle<JSProxy> proxy, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9695 | Handle<Symbol> private_name, |
| 9696 | PropertyDescriptor* desc, |
| 9697 | ShouldThrow should_throw); |
| 9698 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 9699 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9700 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSProxy); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 9701 | }; |
| 9702 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 9703 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9704 | class JSCollection : public JSObject { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9705 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9706 | // [table]: the backing hash table |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9707 | DECL_ACCESSORS(table, Object) |
| 9708 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9709 | static const int kTableOffset = JSObject::kHeaderSize; |
| 9710 | static const int kSize = kTableOffset + kPointerSize; |
| 9711 | |
| 9712 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9713 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSCollection); |
| 9714 | }; |
| 9715 | |
| 9716 | |
| 9717 | // The JSSet describes EcmaScript Harmony sets |
| 9718 | class JSSet : public JSCollection { |
| 9719 | public: |
| 9720 | DECLARE_CAST(JSSet) |
| 9721 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9722 | static void Initialize(Handle<JSSet> set, Isolate* isolate); |
| 9723 | static void Clear(Handle<JSSet> set); |
| 9724 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9725 | // Dispatched behavior. |
| 9726 | DECLARE_PRINTER(JSSet) |
| 9727 | DECLARE_VERIFIER(JSSet) |
| 9728 | |
| 9729 | private: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9730 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSSet); |
| 9731 | }; |
| 9732 | |
| 9733 | |
| 9734 | // The JSMap describes EcmaScript Harmony maps |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9735 | class JSMap : public JSCollection { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9736 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9737 | DECLARE_CAST(JSMap) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9738 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9739 | static void Initialize(Handle<JSMap> map, Isolate* isolate); |
| 9740 | static void Clear(Handle<JSMap> map); |
| 9741 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9742 | // Dispatched behavior. |
| 9743 | DECLARE_PRINTER(JSMap) |
| 9744 | DECLARE_VERIFIER(JSMap) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9745 | |
| 9746 | private: |
| 9747 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSMap); |
| 9748 | }; |
| 9749 | |
| 9750 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9751 | // OrderedHashTableIterator is an iterator that iterates over the keys and |
| 9752 | // values of an OrderedHashTable. |
| 9753 | // |
| 9754 | // The iterator has a reference to the underlying OrderedHashTable data, |
| 9755 | // [table], as well as the current [index] the iterator is at. |
| 9756 | // |
| 9757 | // When the OrderedHashTable is rehashed it adds a reference from the old table |
| 9758 | // to the new table as well as storing enough data about the changes so that the |
| 9759 | // iterator [index] can be adjusted accordingly. |
| 9760 | // |
| 9761 | // When the [Next] result from the iterator is requested, the iterator checks if |
| 9762 | // there is a newer table that it needs to transition to. |
| 9763 | template<class Derived, class TableType> |
| 9764 | class OrderedHashTableIterator: public JSObject { |
| 9765 | public: |
| 9766 | // [table]: the backing hash table mapping keys to values. |
| 9767 | DECL_ACCESSORS(table, Object) |
| 9768 | |
| 9769 | // [index]: The index into the data table. |
| 9770 | DECL_ACCESSORS(index, Object) |
| 9771 | |
| 9772 | // [kind]: The kind of iteration this is. One of the [Kind] enum values. |
| 9773 | DECL_ACCESSORS(kind, Object) |
| 9774 | |
| 9775 | #ifdef OBJECT_PRINT |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 9776 | void OrderedHashTableIteratorPrint(std::ostream& os); // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9777 | #endif |
| 9778 | |
| 9779 | static const int kTableOffset = JSObject::kHeaderSize; |
| 9780 | static const int kIndexOffset = kTableOffset + kPointerSize; |
| 9781 | static const int kKindOffset = kIndexOffset + kPointerSize; |
| 9782 | static const int kSize = kKindOffset + kPointerSize; |
| 9783 | |
| 9784 | enum Kind { |
| 9785 | kKindKeys = 1, |
| 9786 | kKindValues = 2, |
| 9787 | kKindEntries = 3 |
| 9788 | }; |
| 9789 | |
| 9790 | // Whether the iterator has more elements. This needs to be called before |
| 9791 | // calling |CurrentKey| and/or |CurrentValue|. |
| 9792 | bool HasMore(); |
| 9793 | |
| 9794 | // Move the index forward one. |
| 9795 | void MoveNext() { |
| 9796 | set_index(Smi::FromInt(Smi::cast(index())->value() + 1)); |
| 9797 | } |
| 9798 | |
| 9799 | // Populates the array with the next key and value and then moves the iterator |
| 9800 | // forward. |
| 9801 | // This returns the |kind| or 0 if the iterator is already at the end. |
| 9802 | Smi* Next(JSArray* value_array); |
| 9803 | |
| 9804 | // Returns the current key of the iterator. This should only be called when |
| 9805 | // |HasMore| returns true. |
| 9806 | inline Object* CurrentKey(); |
| 9807 | |
| 9808 | private: |
| 9809 | // Transitions the iterator to the non obsolete backing store. This is a NOP |
| 9810 | // if the [table] is not obsolete. |
| 9811 | void Transition(); |
| 9812 | |
| 9813 | DISALLOW_IMPLICIT_CONSTRUCTORS(OrderedHashTableIterator); |
| 9814 | }; |
| 9815 | |
| 9816 | |
| 9817 | class JSSetIterator: public OrderedHashTableIterator<JSSetIterator, |
| 9818 | OrderedHashSet> { |
| 9819 | public: |
| 9820 | // Dispatched behavior. |
| 9821 | DECLARE_PRINTER(JSSetIterator) |
| 9822 | DECLARE_VERIFIER(JSSetIterator) |
| 9823 | |
| 9824 | DECLARE_CAST(JSSetIterator) |
| 9825 | |
| 9826 | // Called by |Next| to populate the array. This allows the subclasses to |
| 9827 | // populate the array differently. |
| 9828 | inline void PopulateValueArray(FixedArray* array); |
| 9829 | |
| 9830 | private: |
| 9831 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSSetIterator); |
| 9832 | }; |
| 9833 | |
| 9834 | |
| 9835 | class JSMapIterator: public OrderedHashTableIterator<JSMapIterator, |
| 9836 | OrderedHashMap> { |
| 9837 | public: |
| 9838 | // Dispatched behavior. |
| 9839 | DECLARE_PRINTER(JSMapIterator) |
| 9840 | DECLARE_VERIFIER(JSMapIterator) |
| 9841 | |
| 9842 | DECLARE_CAST(JSMapIterator) |
| 9843 | |
| 9844 | // Called by |Next| to populate the array. This allows the subclasses to |
| 9845 | // populate the array differently. |
| 9846 | inline void PopulateValueArray(FixedArray* array); |
| 9847 | |
| 9848 | private: |
| 9849 | // Returns the current value of the iterator. This should only be called when |
| 9850 | // |HasMore| returns true. |
| 9851 | inline Object* CurrentValue(); |
| 9852 | |
| 9853 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSMapIterator); |
| 9854 | }; |
| 9855 | |
| 9856 | |
| 9857 | // Base class for both JSWeakMap and JSWeakSet |
| 9858 | class JSWeakCollection: public JSObject { |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 9859 | public: |
| 9860 | // [table]: the backing hash table mapping keys to values. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9861 | DECL_ACCESSORS(table, Object) |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 9862 | |
| 9863 | // [next]: linked list of encountered weak maps during GC. |
| 9864 | DECL_ACCESSORS(next, Object) |
| 9865 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9866 | static void Initialize(Handle<JSWeakCollection> collection, Isolate* isolate); |
| 9867 | static void Set(Handle<JSWeakCollection> collection, Handle<Object> key, |
| 9868 | Handle<Object> value, int32_t hash); |
| 9869 | static bool Delete(Handle<JSWeakCollection> collection, Handle<Object> key, |
| 9870 | int32_t hash); |
| 9871 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 9872 | static const int kTableOffset = JSObject::kHeaderSize; |
| 9873 | static const int kNextOffset = kTableOffset + kPointerSize; |
| 9874 | static const int kSize = kNextOffset + kPointerSize; |
| 9875 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9876 | // Visiting policy defines whether the table and next collection fields |
| 9877 | // should be visited or not. |
| 9878 | enum BodyVisitingPolicy { kVisitStrong, kVisitWeak }; |
| 9879 | |
| 9880 | // Iterates the function object according to the visiting policy. |
| 9881 | template <BodyVisitingPolicy> |
| 9882 | class BodyDescriptorImpl; |
| 9883 | |
| 9884 | // Visit the whole object. |
| 9885 | typedef BodyDescriptorImpl<kVisitStrong> BodyDescriptor; |
| 9886 | |
| 9887 | // Don't visit table and next collection fields. |
| 9888 | typedef BodyDescriptorImpl<kVisitWeak> BodyDescriptorWeak; |
| 9889 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 9890 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9891 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSWeakCollection); |
| 9892 | }; |
| 9893 | |
| 9894 | |
| 9895 | // The JSWeakMap describes EcmaScript Harmony weak maps |
| 9896 | class JSWeakMap: public JSWeakCollection { |
| 9897 | public: |
| 9898 | DECLARE_CAST(JSWeakMap) |
| 9899 | |
| 9900 | // Dispatched behavior. |
| 9901 | DECLARE_PRINTER(JSWeakMap) |
| 9902 | DECLARE_VERIFIER(JSWeakMap) |
| 9903 | |
| 9904 | private: |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 9905 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSWeakMap); |
| 9906 | }; |
| 9907 | |
| 9908 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9909 | // The JSWeakSet describes EcmaScript Harmony weak sets |
| 9910 | class JSWeakSet: public JSWeakCollection { |
| 9911 | public: |
| 9912 | DECLARE_CAST(JSWeakSet) |
| 9913 | |
| 9914 | // Dispatched behavior. |
| 9915 | DECLARE_PRINTER(JSWeakSet) |
| 9916 | DECLARE_VERIFIER(JSWeakSet) |
| 9917 | |
| 9918 | private: |
| 9919 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSWeakSet); |
| 9920 | }; |
| 9921 | |
| 9922 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9923 | // Whether a JSArrayBuffer is a SharedArrayBuffer or not. |
| 9924 | enum class SharedFlag { kNotShared, kShared }; |
| 9925 | |
| 9926 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9927 | class JSArrayBuffer: public JSObject { |
| 9928 | public: |
| 9929 | // [backing_store]: backing memory for this array |
| 9930 | DECL_ACCESSORS(backing_store, void) |
| 9931 | |
| 9932 | // [byte_length]: length in bytes |
| 9933 | DECL_ACCESSORS(byte_length, Object) |
| 9934 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9935 | inline uint32_t bit_field() const; |
| 9936 | inline void set_bit_field(uint32_t bits); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9937 | |
| 9938 | inline bool is_external(); |
| 9939 | inline void set_is_external(bool value); |
| 9940 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 9941 | inline bool is_neuterable(); |
| 9942 | inline void set_is_neuterable(bool value); |
| 9943 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9944 | inline bool was_neutered(); |
| 9945 | inline void set_was_neutered(bool value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9946 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9947 | inline bool is_shared(); |
| 9948 | inline void set_is_shared(bool value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9949 | |
| 9950 | DECLARE_CAST(JSArrayBuffer) |
| 9951 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9952 | void Neuter(); |
| 9953 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9954 | static void Setup(Handle<JSArrayBuffer> array_buffer, Isolate* isolate, |
| 9955 | bool is_external, void* data, size_t allocated_length, |
| 9956 | SharedFlag shared = SharedFlag::kNotShared); |
| 9957 | |
| 9958 | static bool SetupAllocatingData(Handle<JSArrayBuffer> array_buffer, |
| 9959 | Isolate* isolate, size_t allocated_length, |
| 9960 | bool initialize = true, |
| 9961 | SharedFlag shared = SharedFlag::kNotShared); |
| 9962 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9963 | // Dispatched behavior. |
| 9964 | DECLARE_PRINTER(JSArrayBuffer) |
| 9965 | DECLARE_VERIFIER(JSArrayBuffer) |
| 9966 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9967 | static const int kByteLengthOffset = JSObject::kHeaderSize; |
| 9968 | static const int kBackingStoreOffset = kByteLengthOffset + kPointerSize; |
| 9969 | static const int kBitFieldSlot = kBackingStoreOffset + kPointerSize; |
| 9970 | #if V8_TARGET_LITTLE_ENDIAN || !V8_HOST_ARCH_64_BIT |
| 9971 | static const int kBitFieldOffset = kBitFieldSlot; |
| 9972 | #else |
| 9973 | static const int kBitFieldOffset = kBitFieldSlot + kIntSize; |
| 9974 | #endif |
| 9975 | static const int kSize = kBitFieldSlot + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9976 | |
| 9977 | static const int kSizeWithInternalFields = |
| 9978 | kSize + v8::ArrayBuffer::kInternalFieldCount * kPointerSize; |
| 9979 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9980 | // Iterates all fields in the object including internal ones except |
| 9981 | // kBackingStoreOffset and kBitFieldSlot. |
| 9982 | class BodyDescriptor; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9983 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9984 | class IsExternal : public BitField<bool, 1, 1> {}; |
| 9985 | class IsNeuterable : public BitField<bool, 2, 1> {}; |
| 9986 | class WasNeutered : public BitField<bool, 3, 1> {}; |
| 9987 | class IsShared : public BitField<bool, 4, 1> {}; |
| 9988 | |
| 9989 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9990 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSArrayBuffer); |
| 9991 | }; |
| 9992 | |
| 9993 | |
| 9994 | class JSArrayBufferView: public JSObject { |
| 9995 | public: |
| 9996 | // [buffer]: ArrayBuffer that this typed array views. |
| 9997 | DECL_ACCESSORS(buffer, Object) |
| 9998 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9999 | // [byte_offset]: offset of typed array in bytes. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10000 | DECL_ACCESSORS(byte_offset, Object) |
| 10001 | |
| 10002 | // [byte_length]: length of typed array in bytes. |
| 10003 | DECL_ACCESSORS(byte_length, Object) |
| 10004 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10005 | DECLARE_CAST(JSArrayBufferView) |
| 10006 | |
| 10007 | DECLARE_VERIFIER(JSArrayBufferView) |
| 10008 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10009 | inline bool WasNeutered() const; |
| 10010 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10011 | static const int kBufferOffset = JSObject::kHeaderSize; |
| 10012 | static const int kByteOffsetOffset = kBufferOffset + kPointerSize; |
| 10013 | static const int kByteLengthOffset = kByteOffsetOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10014 | static const int kViewSize = kByteLengthOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10015 | |
| 10016 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10017 | #ifdef VERIFY_HEAP |
| 10018 | DECL_ACCESSORS(raw_byte_offset, Object) |
| 10019 | DECL_ACCESSORS(raw_byte_length, Object) |
| 10020 | #endif |
| 10021 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10022 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSArrayBufferView); |
| 10023 | }; |
| 10024 | |
| 10025 | |
| 10026 | class JSTypedArray: public JSArrayBufferView { |
| 10027 | public: |
| 10028 | // [length]: length of typed array in elements. |
| 10029 | DECL_ACCESSORS(length, Object) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10030 | inline uint32_t length_value() const; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10031 | |
| 10032 | DECLARE_CAST(JSTypedArray) |
| 10033 | |
| 10034 | ExternalArrayType type(); |
| 10035 | size_t element_size(); |
| 10036 | |
| 10037 | Handle<JSArrayBuffer> GetBuffer(); |
| 10038 | |
| 10039 | // Dispatched behavior. |
| 10040 | DECLARE_PRINTER(JSTypedArray) |
| 10041 | DECLARE_VERIFIER(JSTypedArray) |
| 10042 | |
| 10043 | static const int kLengthOffset = kViewSize + kPointerSize; |
| 10044 | static const int kSize = kLengthOffset + kPointerSize; |
| 10045 | |
| 10046 | static const int kSizeWithInternalFields = |
| 10047 | kSize + v8::ArrayBufferView::kInternalFieldCount * kPointerSize; |
| 10048 | |
| 10049 | private: |
| 10050 | static Handle<JSArrayBuffer> MaterializeArrayBuffer( |
| 10051 | Handle<JSTypedArray> typed_array); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10052 | #ifdef VERIFY_HEAP |
| 10053 | DECL_ACCESSORS(raw_length, Object) |
| 10054 | #endif |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10055 | |
| 10056 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSTypedArray); |
| 10057 | }; |
| 10058 | |
| 10059 | |
| 10060 | class JSDataView: public JSArrayBufferView { |
| 10061 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10062 | DECLARE_CAST(JSDataView) |
| 10063 | |
| 10064 | // Dispatched behavior. |
| 10065 | DECLARE_PRINTER(JSDataView) |
| 10066 | DECLARE_VERIFIER(JSDataView) |
| 10067 | |
| 10068 | static const int kSize = kViewSize; |
| 10069 | |
| 10070 | static const int kSizeWithInternalFields = |
| 10071 | kSize + v8::ArrayBufferView::kInternalFieldCount * kPointerSize; |
| 10072 | |
| 10073 | private: |
| 10074 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSDataView); |
| 10075 | }; |
| 10076 | |
| 10077 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 10078 | // Foreign describes objects pointing from JavaScript to C structures. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 10079 | class Foreign: public HeapObject { |
| 10080 | public: |
| 10081 | // [address]: field containing the address. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10082 | inline Address foreign_address(); |
| 10083 | inline void set_foreign_address(Address value); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 10084 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10085 | DECLARE_CAST(Foreign) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 10086 | |
| 10087 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10088 | DECLARE_PRINTER(Foreign) |
| 10089 | DECLARE_VERIFIER(Foreign) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10090 | |
| 10091 | // Layout description. |
| 10092 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10093 | static const int kForeignAddressOffset = HeapObject::kHeaderSize; |
| 10094 | static const int kSize = kForeignAddressOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10095 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10096 | STATIC_ASSERT(kForeignAddressOffset == Internals::kForeignAddressOffset); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10097 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10098 | class BodyDescriptor; |
| 10099 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10100 | private: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 10101 | DISALLOW_IMPLICIT_CONSTRUCTORS(Foreign); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10102 | }; |
| 10103 | |
| 10104 | |
| 10105 | // The JSArray describes JavaScript Arrays |
| 10106 | // Such an array can be in one of two modes: |
| 10107 | // - fast, backing storage is a FixedArray and length <= elements.length(); |
| 10108 | // Please note: push and pop can be used to grow and shrink the array. |
| 10109 | // - slow, backing storage is a HashTable with numbers as keys. |
| 10110 | class JSArray: public JSObject { |
| 10111 | public: |
| 10112 | // [length]: The length property. |
| 10113 | DECL_ACCESSORS(length, Object) |
| 10114 | |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 10115 | // Overload the length setter to skip write barrier when the length |
| 10116 | // is set to a smi. This matches the set function on FixedArray. |
| 10117 | inline void set_length(Smi* length); |
| 10118 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 10119 | static bool HasReadOnlyLength(Handle<JSArray> array); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10120 | static bool WouldChangeReadOnlyLength(Handle<JSArray> array, uint32_t index); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 10121 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10122 | // Initialize the array with the given capacity. The function may |
| 10123 | // fail due to out-of-memory situations, but only if the requested |
| 10124 | // capacity is non-zero. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10125 | static void Initialize(Handle<JSArray> array, int capacity, int length = 0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10126 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10127 | // If the JSArray has fast elements, and new_length would result in |
| 10128 | // normalization, returns true. |
| 10129 | bool SetLengthWouldNormalize(uint32_t new_length); |
| 10130 | static inline bool SetLengthWouldNormalize(Heap* heap, uint32_t new_length); |
| 10131 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10132 | // Initializes the array to a certain length. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10133 | inline bool AllowsSetLength(); |
| 10134 | |
| 10135 | static void SetLength(Handle<JSArray> array, uint32_t length); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10136 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10137 | // Set the content of the array to the content of storage. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10138 | static inline void SetContent(Handle<JSArray> array, |
| 10139 | Handle<FixedArrayBase> storage); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10140 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10141 | // ES6 9.4.2.1 |
| 10142 | MUST_USE_RESULT static Maybe<bool> DefineOwnProperty( |
| 10143 | Isolate* isolate, Handle<JSArray> o, Handle<Object> name, |
| 10144 | PropertyDescriptor* desc, ShouldThrow should_throw); |
| 10145 | |
| 10146 | static bool AnythingToArrayLength(Isolate* isolate, |
| 10147 | Handle<Object> length_object, |
| 10148 | uint32_t* output); |
| 10149 | MUST_USE_RESULT static Maybe<bool> ArraySetLength(Isolate* isolate, |
| 10150 | Handle<JSArray> a, |
| 10151 | PropertyDescriptor* desc, |
| 10152 | ShouldThrow should_throw); |
| 10153 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 10154 | // Checks whether the Array has the current realm's Array.prototype as its |
| 10155 | // prototype. This function is best-effort and only gives a conservative |
| 10156 | // approximation, erring on the side of false, in particular with respect |
| 10157 | // to Proxies and objects with a hidden prototype. |
| 10158 | inline bool HasArrayPrototype(Isolate* isolate); |
| 10159 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10160 | DECLARE_CAST(JSArray) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10161 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10162 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10163 | DECLARE_PRINTER(JSArray) |
| 10164 | DECLARE_VERIFIER(JSArray) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10165 | |
| 10166 | // Number of element slots to pre-allocate for an empty array. |
| 10167 | static const int kPreallocatedArrayElements = 4; |
| 10168 | |
| 10169 | // Layout description. |
| 10170 | static const int kLengthOffset = JSObject::kHeaderSize; |
| 10171 | static const int kSize = kLengthOffset + kPointerSize; |
| 10172 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10173 | // 600 * KB is the Page::kMaxRegularHeapObjectSize defined in spaces.h which |
| 10174 | // we do not want to include in objects.h |
| 10175 | // Note that Page::kMaxRegularHeapObjectSize has to be in sync with |
| 10176 | // kInitialMaxFastElementArray which is checked in a DCHECK in heap.cc. |
| 10177 | static const int kInitialMaxFastElementArray = |
| 10178 | (600 * KB - FixedArray::kHeaderSize - kSize - AllocationMemento::kSize) / |
| 10179 | kPointerSize; |
| 10180 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10181 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10182 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSArray); |
| 10183 | }; |
| 10184 | |
| 10185 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10186 | Handle<Object> CacheInitialJSArrayMaps(Handle<Context> native_context, |
| 10187 | Handle<Map> initial_map); |
| 10188 | |
| 10189 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 10190 | // JSRegExpResult is just a JSArray with a specific initial map. |
| 10191 | // This initial map adds in-object properties for "index" and "input" |
| 10192 | // properties, as assigned by RegExp.prototype.exec, which allows |
| 10193 | // faster creation of RegExp exec results. |
| 10194 | // This class just holds constants used when creating the result. |
| 10195 | // After creation the result must be treated as a JSArray in all regards. |
| 10196 | class JSRegExpResult: public JSArray { |
| 10197 | public: |
| 10198 | // Offsets of object fields. |
| 10199 | static const int kIndexOffset = JSArray::kSize; |
| 10200 | static const int kInputOffset = kIndexOffset + kPointerSize; |
| 10201 | static const int kSize = kInputOffset + kPointerSize; |
| 10202 | // Indices of in-object properties. |
| 10203 | static const int kIndexIndex = 0; |
| 10204 | static const int kInputIndex = 1; |
| 10205 | private: |
| 10206 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSRegExpResult); |
| 10207 | }; |
| 10208 | |
| 10209 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10210 | // An accessor must have a getter, but can have no setter. |
| 10211 | // |
| 10212 | // When setting a property, V8 searches accessors in prototypes. |
| 10213 | // If an accessor was found and it does not have a setter, |
| 10214 | // the request is ignored. |
| 10215 | // |
| 10216 | // If the accessor in the prototype has the READ_ONLY property attribute, then |
| 10217 | // a new value is added to the derived object when the property is set. |
| 10218 | // This shadows the accessor in the prototype. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10219 | class AccessorInfo: public Struct { |
| 10220 | public: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10221 | DECL_ACCESSORS(name, Object) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10222 | DECL_INT_ACCESSORS(flag) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10223 | DECL_ACCESSORS(expected_receiver_type, Object) |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 10224 | // This directly points at a foreign C function to be used from the runtime. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10225 | DECL_ACCESSORS(getter, Object) |
| 10226 | DECL_ACCESSORS(setter, Object) |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 10227 | // This either points at the same as above, or a trampoline in case we are |
| 10228 | // running with the simulator. Use these entries from generated code. |
| 10229 | DECL_ACCESSORS(js_getter, Object) |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10230 | DECL_ACCESSORS(data, Object) |
| 10231 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 10232 | static Address redirect(Isolate* isolate, Address address, |
| 10233 | AccessorComponent component); |
| 10234 | Address redirected_getter() const; |
| 10235 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10236 | // Dispatched behavior. |
| 10237 | DECLARE_PRINTER(AccessorInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10238 | |
| 10239 | inline bool all_can_read(); |
| 10240 | inline void set_all_can_read(bool value); |
| 10241 | |
| 10242 | inline bool all_can_write(); |
| 10243 | inline void set_all_can_write(bool value); |
| 10244 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10245 | inline bool is_special_data_property(); |
| 10246 | inline void set_is_special_data_property(bool value); |
| 10247 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 10248 | inline bool is_sloppy(); |
| 10249 | inline void set_is_sloppy(bool value); |
| 10250 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10251 | inline PropertyAttributes property_attributes(); |
| 10252 | inline void set_property_attributes(PropertyAttributes attributes); |
| 10253 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10254 | // Checks whether the given receiver is compatible with this accessor. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10255 | static bool IsCompatibleReceiverMap(Isolate* isolate, |
| 10256 | Handle<AccessorInfo> info, |
| 10257 | Handle<Map> map); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10258 | inline bool IsCompatibleReceiver(Object* receiver); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10259 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10260 | DECLARE_CAST(AccessorInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10261 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10262 | // Dispatched behavior. |
| 10263 | DECLARE_VERIFIER(AccessorInfo) |
| 10264 | |
| 10265 | // Append all descriptors to the array that are not already there. |
| 10266 | // Return number added. |
| 10267 | static int AppendUnique(Handle<Object> descriptors, |
| 10268 | Handle<FixedArray> array, |
| 10269 | int valid_descriptors); |
| 10270 | |
| 10271 | static const int kNameOffset = HeapObject::kHeaderSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10272 | static const int kFlagOffset = kNameOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10273 | static const int kExpectedReceiverTypeOffset = kFlagOffset + kPointerSize; |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 10274 | static const int kSetterOffset = kExpectedReceiverTypeOffset + kPointerSize; |
| 10275 | static const int kGetterOffset = kSetterOffset + kPointerSize; |
| 10276 | static const int kJsGetterOffset = kGetterOffset + kPointerSize; |
| 10277 | static const int kDataOffset = kJsGetterOffset + kPointerSize; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10278 | static const int kSize = kDataOffset + kPointerSize; |
| 10279 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10280 | |
| 10281 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10282 | inline bool HasExpectedReceiverType(); |
| 10283 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10284 | // Bit positions in flag. |
| 10285 | static const int kAllCanReadBit = 0; |
| 10286 | static const int kAllCanWriteBit = 1; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10287 | static const int kSpecialDataProperty = 2; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 10288 | static const int kIsSloppy = 3; |
| 10289 | class AttributesField : public BitField<PropertyAttributes, 4, 3> {}; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10290 | |
| 10291 | DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorInfo); |
| 10292 | }; |
| 10293 | |
| 10294 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10295 | // Support for JavaScript accessors: A pair of a getter and a setter. Each |
| 10296 | // accessor can either be |
| 10297 | // * a pointer to a JavaScript function or proxy: a real accessor |
| 10298 | // * undefined: considered an accessor by the spec, too, strangely enough |
| 10299 | // * the hole: an accessor which has not been set |
| 10300 | // * a pointer to a map: a transition used to ensure map sharing |
| 10301 | class AccessorPair: public Struct { |
| 10302 | public: |
| 10303 | DECL_ACCESSORS(getter, Object) |
| 10304 | DECL_ACCESSORS(setter, Object) |
| 10305 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10306 | DECLARE_CAST(AccessorPair) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10307 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10308 | static Handle<AccessorPair> Copy(Handle<AccessorPair> pair); |
| 10309 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10310 | inline Object* get(AccessorComponent component); |
| 10311 | inline void set(AccessorComponent component, Object* value); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10312 | |
| 10313 | // Note: Returns undefined instead in case of a hole. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10314 | static Handle<Object> GetComponent(Handle<AccessorPair> accessor_pair, |
| 10315 | AccessorComponent component); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10316 | |
| 10317 | // Set both components, skipping arguments which are a JavaScript null. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10318 | inline void SetComponents(Object* getter, Object* setter); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10319 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10320 | inline bool Equals(AccessorPair* pair); |
| 10321 | inline bool Equals(Object* getter_value, Object* setter_value); |
| 10322 | |
| 10323 | inline bool ContainsAccessor(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10324 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10325 | // Dispatched behavior. |
| 10326 | DECLARE_PRINTER(AccessorPair) |
| 10327 | DECLARE_VERIFIER(AccessorPair) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10328 | |
| 10329 | static const int kGetterOffset = HeapObject::kHeaderSize; |
| 10330 | static const int kSetterOffset = kGetterOffset + kPointerSize; |
| 10331 | static const int kSize = kSetterOffset + kPointerSize; |
| 10332 | |
| 10333 | private: |
| 10334 | // Strangely enough, in addition to functions and harmony proxies, the spec |
| 10335 | // requires us to consider undefined as a kind of accessor, too: |
| 10336 | // var obj = {}; |
| 10337 | // Object.defineProperty(obj, "foo", {get: undefined}); |
| 10338 | // assertTrue("foo" in obj); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10339 | inline bool IsJSAccessor(Object* obj); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10340 | |
| 10341 | DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorPair); |
| 10342 | }; |
| 10343 | |
| 10344 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10345 | class AccessCheckInfo: public Struct { |
| 10346 | public: |
| 10347 | DECL_ACCESSORS(named_callback, Object) |
| 10348 | DECL_ACCESSORS(indexed_callback, Object) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10349 | DECL_ACCESSORS(callback, Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10350 | DECL_ACCESSORS(data, Object) |
| 10351 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10352 | DECLARE_CAST(AccessCheckInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10353 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10354 | // Dispatched behavior. |
| 10355 | DECLARE_PRINTER(AccessCheckInfo) |
| 10356 | DECLARE_VERIFIER(AccessCheckInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10357 | |
| 10358 | static const int kNamedCallbackOffset = HeapObject::kHeaderSize; |
| 10359 | static const int kIndexedCallbackOffset = kNamedCallbackOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10360 | static const int kCallbackOffset = kIndexedCallbackOffset + kPointerSize; |
| 10361 | static const int kDataOffset = kCallbackOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10362 | static const int kSize = kDataOffset + kPointerSize; |
| 10363 | |
| 10364 | private: |
| 10365 | DISALLOW_IMPLICIT_CONSTRUCTORS(AccessCheckInfo); |
| 10366 | }; |
| 10367 | |
| 10368 | |
| 10369 | class InterceptorInfo: public Struct { |
| 10370 | public: |
| 10371 | DECL_ACCESSORS(getter, Object) |
| 10372 | DECL_ACCESSORS(setter, Object) |
| 10373 | DECL_ACCESSORS(query, Object) |
| 10374 | DECL_ACCESSORS(deleter, Object) |
| 10375 | DECL_ACCESSORS(enumerator, Object) |
| 10376 | DECL_ACCESSORS(data, Object) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 10377 | DECL_BOOLEAN_ACCESSORS(can_intercept_symbols) |
| 10378 | DECL_BOOLEAN_ACCESSORS(all_can_read) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10379 | DECL_BOOLEAN_ACCESSORS(non_masking) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 10380 | |
| 10381 | inline int flags() const; |
| 10382 | inline void set_flags(int flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10383 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10384 | DECLARE_CAST(InterceptorInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10385 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10386 | // Dispatched behavior. |
| 10387 | DECLARE_PRINTER(InterceptorInfo) |
| 10388 | DECLARE_VERIFIER(InterceptorInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10389 | |
| 10390 | static const int kGetterOffset = HeapObject::kHeaderSize; |
| 10391 | static const int kSetterOffset = kGetterOffset + kPointerSize; |
| 10392 | static const int kQueryOffset = kSetterOffset + kPointerSize; |
| 10393 | static const int kDeleterOffset = kQueryOffset + kPointerSize; |
| 10394 | static const int kEnumeratorOffset = kDeleterOffset + kPointerSize; |
| 10395 | static const int kDataOffset = kEnumeratorOffset + kPointerSize; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 10396 | static const int kFlagsOffset = kDataOffset + kPointerSize; |
| 10397 | static const int kSize = kFlagsOffset + kPointerSize; |
| 10398 | |
| 10399 | static const int kCanInterceptSymbolsBit = 0; |
| 10400 | static const int kAllCanReadBit = 1; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10401 | static const int kNonMasking = 2; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10402 | |
| 10403 | private: |
| 10404 | DISALLOW_IMPLICIT_CONSTRUCTORS(InterceptorInfo); |
| 10405 | }; |
| 10406 | |
| 10407 | |
| 10408 | class CallHandlerInfo: public Struct { |
| 10409 | public: |
| 10410 | DECL_ACCESSORS(callback, Object) |
| 10411 | DECL_ACCESSORS(data, Object) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10412 | DECL_ACCESSORS(fast_handler, Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10413 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10414 | DECLARE_CAST(CallHandlerInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10415 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10416 | // Dispatched behavior. |
| 10417 | DECLARE_PRINTER(CallHandlerInfo) |
| 10418 | DECLARE_VERIFIER(CallHandlerInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10419 | |
| 10420 | static const int kCallbackOffset = HeapObject::kHeaderSize; |
| 10421 | static const int kDataOffset = kCallbackOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10422 | static const int kFastHandlerOffset = kDataOffset + kPointerSize; |
| 10423 | static const int kSize = kFastHandlerOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10424 | |
| 10425 | private: |
| 10426 | DISALLOW_IMPLICIT_CONSTRUCTORS(CallHandlerInfo); |
| 10427 | }; |
| 10428 | |
| 10429 | |
| 10430 | class TemplateInfo: public Struct { |
| 10431 | public: |
| 10432 | DECL_ACCESSORS(tag, Object) |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10433 | DECL_ACCESSORS(serial_number, Object) |
| 10434 | DECL_INT_ACCESSORS(number_of_properties) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10435 | DECL_ACCESSORS(property_list, Object) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10436 | DECL_ACCESSORS(property_accessors, Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10437 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10438 | DECLARE_VERIFIER(TemplateInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10439 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10440 | static const int kTagOffset = HeapObject::kHeaderSize; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10441 | static const int kSerialNumberOffset = kTagOffset + kPointerSize; |
| 10442 | static const int kNumberOfProperties = kSerialNumberOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10443 | static const int kPropertyListOffset = kNumberOfProperties + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10444 | static const int kPropertyAccessorsOffset = |
| 10445 | kPropertyListOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10446 | static const int kPropertyIntrinsicsOffset = |
| 10447 | kPropertyAccessorsOffset + kPointerSize; |
| 10448 | static const int kHeaderSize = kPropertyIntrinsicsOffset + kPointerSize; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10449 | |
| 10450 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10451 | DISALLOW_IMPLICIT_CONSTRUCTORS(TemplateInfo); |
| 10452 | }; |
| 10453 | |
| 10454 | |
| 10455 | class FunctionTemplateInfo: public TemplateInfo { |
| 10456 | public: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10457 | DECL_ACCESSORS(call_code, Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10458 | DECL_ACCESSORS(prototype_template, Object) |
| 10459 | DECL_ACCESSORS(parent_template, Object) |
| 10460 | DECL_ACCESSORS(named_property_handler, Object) |
| 10461 | DECL_ACCESSORS(indexed_property_handler, Object) |
| 10462 | DECL_ACCESSORS(instance_template, Object) |
| 10463 | DECL_ACCESSORS(class_name, Object) |
| 10464 | DECL_ACCESSORS(signature, Object) |
| 10465 | DECL_ACCESSORS(instance_call_handler, Object) |
| 10466 | DECL_ACCESSORS(access_check_info, Object) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10467 | DECL_INT_ACCESSORS(flag) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10468 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10469 | inline int length() const; |
| 10470 | inline void set_length(int value); |
| 10471 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10472 | // Following properties use flag bits. |
| 10473 | DECL_BOOLEAN_ACCESSORS(hidden_prototype) |
| 10474 | DECL_BOOLEAN_ACCESSORS(undetectable) |
| 10475 | // If the bit is set, object instances created by this function |
| 10476 | // requires access check. |
| 10477 | DECL_BOOLEAN_ACCESSORS(needs_access_check) |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 10478 | DECL_BOOLEAN_ACCESSORS(read_only_prototype) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10479 | DECL_BOOLEAN_ACCESSORS(remove_prototype) |
| 10480 | DECL_BOOLEAN_ACCESSORS(do_not_cache) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10481 | DECL_BOOLEAN_ACCESSORS(instantiated) |
| 10482 | DECL_BOOLEAN_ACCESSORS(accept_any_receiver) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10483 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10484 | DECLARE_CAST(FunctionTemplateInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10485 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10486 | // Dispatched behavior. |
| 10487 | DECLARE_PRINTER(FunctionTemplateInfo) |
| 10488 | DECLARE_VERIFIER(FunctionTemplateInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10489 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10490 | static const int kCallCodeOffset = TemplateInfo::kHeaderSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10491 | static const int kPrototypeTemplateOffset = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10492 | kCallCodeOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10493 | static const int kParentTemplateOffset = |
| 10494 | kPrototypeTemplateOffset + kPointerSize; |
| 10495 | static const int kNamedPropertyHandlerOffset = |
| 10496 | kParentTemplateOffset + kPointerSize; |
| 10497 | static const int kIndexedPropertyHandlerOffset = |
| 10498 | kNamedPropertyHandlerOffset + kPointerSize; |
| 10499 | static const int kInstanceTemplateOffset = |
| 10500 | kIndexedPropertyHandlerOffset + kPointerSize; |
| 10501 | static const int kClassNameOffset = kInstanceTemplateOffset + kPointerSize; |
| 10502 | static const int kSignatureOffset = kClassNameOffset + kPointerSize; |
| 10503 | static const int kInstanceCallHandlerOffset = kSignatureOffset + kPointerSize; |
| 10504 | static const int kAccessCheckInfoOffset = |
| 10505 | kInstanceCallHandlerOffset + kPointerSize; |
| 10506 | static const int kFlagOffset = kAccessCheckInfoOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10507 | static const int kLengthOffset = kFlagOffset + kPointerSize; |
| 10508 | static const int kSize = kLengthOffset + kPointerSize; |
| 10509 | |
| 10510 | // Returns true if |object| is an instance of this function template. |
| 10511 | bool IsTemplateFor(Object* object); |
| 10512 | bool IsTemplateFor(Map* map); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10513 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10514 | // Returns the holder JSObject if the function can legally be called with this |
| 10515 | // receiver. Returns Heap::null_value() if the call is illegal. |
| 10516 | Object* GetCompatibleReceiver(Isolate* isolate, Object* receiver); |
| 10517 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10518 | private: |
| 10519 | // Bit position in the flag, from least significant bit position. |
| 10520 | static const int kHiddenPrototypeBit = 0; |
| 10521 | static const int kUndetectableBit = 1; |
| 10522 | static const int kNeedsAccessCheckBit = 2; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 10523 | static const int kReadOnlyPrototypeBit = 3; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10524 | static const int kRemovePrototypeBit = 4; |
| 10525 | static const int kDoNotCacheBit = 5; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10526 | static const int kInstantiatedBit = 6; |
| 10527 | static const int kAcceptAnyReceiver = 7; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10528 | |
| 10529 | DISALLOW_IMPLICIT_CONSTRUCTORS(FunctionTemplateInfo); |
| 10530 | }; |
| 10531 | |
| 10532 | |
| 10533 | class ObjectTemplateInfo: public TemplateInfo { |
| 10534 | public: |
| 10535 | DECL_ACCESSORS(constructor, Object) |
| 10536 | DECL_ACCESSORS(internal_field_count, Object) |
| 10537 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10538 | DECLARE_CAST(ObjectTemplateInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10539 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10540 | // Dispatched behavior. |
| 10541 | DECLARE_PRINTER(ObjectTemplateInfo) |
| 10542 | DECLARE_VERIFIER(ObjectTemplateInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10543 | |
| 10544 | static const int kConstructorOffset = TemplateInfo::kHeaderSize; |
| 10545 | static const int kInternalFieldCountOffset = |
| 10546 | kConstructorOffset + kPointerSize; |
| 10547 | static const int kSize = kInternalFieldCountOffset + kPointerSize; |
| 10548 | }; |
| 10549 | |
| 10550 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10551 | // The DebugInfo class holds additional information for a function being |
| 10552 | // debugged. |
| 10553 | class DebugInfo: public Struct { |
| 10554 | public: |
| 10555 | // The shared function info for the source being debugged. |
| 10556 | DECL_ACCESSORS(shared, SharedFunctionInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10557 | // Code object for the patched code. This code object is the code object |
| 10558 | // currently active for the function. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10559 | DECL_ACCESSORS(abstract_code, AbstractCode) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10560 | // Fixed array holding status information for each active break point. |
| 10561 | DECL_ACCESSORS(break_points, FixedArray) |
| 10562 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10563 | // Check if there is a break point at a code offset. |
| 10564 | bool HasBreakPoint(int code_offset); |
| 10565 | // Get the break point info object for a code offset. |
| 10566 | Object* GetBreakPointInfo(int code_offset); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10567 | // Clear a break point. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10568 | static void ClearBreakPoint(Handle<DebugInfo> debug_info, int code_offset, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10569 | Handle<Object> break_point_object); |
| 10570 | // Set a break point. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10571 | static void SetBreakPoint(Handle<DebugInfo> debug_info, int code_offset, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10572 | int source_position, int statement_position, |
| 10573 | Handle<Object> break_point_object); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10574 | // Get the break point objects for a code offset. |
| 10575 | Handle<Object> GetBreakPointObjects(int code_offset); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10576 | // Find the break point info holding this break point object. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10577 | static Handle<Object> FindBreakPointInfo(Handle<DebugInfo> debug_info, |
| 10578 | Handle<Object> break_point_object); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10579 | // Get the number of break points for this function. |
| 10580 | int GetBreakPointCount(); |
| 10581 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10582 | static Smi* uninitialized() { return Smi::FromInt(0); } |
| 10583 | |
| 10584 | inline BytecodeArray* original_bytecode_array(); |
| 10585 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10586 | DECLARE_CAST(DebugInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10587 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10588 | // Dispatched behavior. |
| 10589 | DECLARE_PRINTER(DebugInfo) |
| 10590 | DECLARE_VERIFIER(DebugInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10591 | |
| 10592 | static const int kSharedFunctionInfoIndex = Struct::kHeaderSize; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10593 | static const int kAbstractCodeIndex = kSharedFunctionInfoIndex + kPointerSize; |
| 10594 | static const int kBreakPointsStateIndex = kAbstractCodeIndex + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10595 | static const int kSize = kBreakPointsStateIndex + kPointerSize; |
| 10596 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10597 | static const int kEstimatedNofBreakPointsInFunction = 16; |
| 10598 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10599 | private: |
| 10600 | static const int kNoBreakPointInfo = -1; |
| 10601 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10602 | // Lookup the index in the break_points array for a code offset. |
| 10603 | int GetBreakPointInfoIndex(int code_offset); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10604 | |
| 10605 | DISALLOW_IMPLICIT_CONSTRUCTORS(DebugInfo); |
| 10606 | }; |
| 10607 | |
| 10608 | |
| 10609 | // The BreakPointInfo class holds information for break points set in a |
| 10610 | // function. The DebugInfo object holds a BreakPointInfo object for each code |
| 10611 | // position with one or more break points. |
| 10612 | class BreakPointInfo: public Struct { |
| 10613 | public: |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10614 | // The code offset for the break point. |
| 10615 | DECL_INT_ACCESSORS(code_offset) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10616 | // The position in the source for the break position. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10617 | DECL_INT_ACCESSORS(source_position) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10618 | // The position in the source for the last statement before this break |
| 10619 | // position. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10620 | DECL_INT_ACCESSORS(statement_position) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10621 | // List of related JavaScript break points. |
| 10622 | DECL_ACCESSORS(break_point_objects, Object) |
| 10623 | |
| 10624 | // Removes a break point. |
| 10625 | static void ClearBreakPoint(Handle<BreakPointInfo> info, |
| 10626 | Handle<Object> break_point_object); |
| 10627 | // Set a break point. |
| 10628 | static void SetBreakPoint(Handle<BreakPointInfo> info, |
| 10629 | Handle<Object> break_point_object); |
| 10630 | // Check if break point info has this break point object. |
| 10631 | static bool HasBreakPointObject(Handle<BreakPointInfo> info, |
| 10632 | Handle<Object> break_point_object); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10633 | // Get the number of break points for this code offset. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10634 | int GetBreakPointCount(); |
| 10635 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10636 | DECLARE_CAST(BreakPointInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10637 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10638 | // Dispatched behavior. |
| 10639 | DECLARE_PRINTER(BreakPointInfo) |
| 10640 | DECLARE_VERIFIER(BreakPointInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10641 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10642 | static const int kCodeOffsetIndex = Struct::kHeaderSize; |
| 10643 | static const int kSourcePositionIndex = kCodeOffsetIndex + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10644 | static const int kStatementPositionIndex = |
| 10645 | kSourcePositionIndex + kPointerSize; |
| 10646 | static const int kBreakPointObjectsIndex = |
| 10647 | kStatementPositionIndex + kPointerSize; |
| 10648 | static const int kSize = kBreakPointObjectsIndex + kPointerSize; |
| 10649 | |
| 10650 | private: |
| 10651 | DISALLOW_IMPLICIT_CONSTRUCTORS(BreakPointInfo); |
| 10652 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10653 | |
| 10654 | |
| 10655 | #undef DECL_BOOLEAN_ACCESSORS |
| 10656 | #undef DECL_ACCESSORS |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10657 | #undef DECLARE_CAST |
| 10658 | #undef DECLARE_VERIFIER |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10659 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10660 | #define VISITOR_SYNCHRONIZATION_TAGS_LIST(V) \ |
| 10661 | V(kStringTable, "string_table", "(Internalized strings)") \ |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10662 | V(kExternalStringsTable, "external_strings_table", "(External strings)") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10663 | V(kStrongRootList, "strong_root_list", "(Strong roots)") \ |
| 10664 | V(kSmiRootList, "smi_root_list", "(Smi roots)") \ |
| 10665 | V(kBootstrapper, "bootstrapper", "(Bootstrapper)") \ |
| 10666 | V(kTop, "top", "(Isolate)") \ |
| 10667 | V(kRelocatable, "relocatable", "(Relocatable)") \ |
| 10668 | V(kDebug, "debug", "(Debugger)") \ |
| 10669 | V(kCompilationCache, "compilationcache", "(Compilation cache)") \ |
| 10670 | V(kHandleScope, "handlescope", "(Handle scope)") \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10671 | V(kDispatchTable, "dispatchtable", "(Dispatch table)") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10672 | V(kBuiltins, "builtins", "(Builtins)") \ |
| 10673 | V(kGlobalHandles, "globalhandles", "(Global handles)") \ |
| 10674 | V(kEternalHandles, "eternalhandles", "(Eternal handles)") \ |
| 10675 | V(kThreadManager, "threadmanager", "(Thread manager)") \ |
| 10676 | V(kStrongRoots, "strong roots", "(Strong roots)") \ |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10677 | V(kExtensions, "Extensions", "(Extensions)") |
| 10678 | |
| 10679 | class VisitorSynchronization : public AllStatic { |
| 10680 | public: |
| 10681 | #define DECLARE_ENUM(enum_item, ignore1, ignore2) enum_item, |
| 10682 | enum SyncTag { |
| 10683 | VISITOR_SYNCHRONIZATION_TAGS_LIST(DECLARE_ENUM) |
| 10684 | kNumberOfSyncTags |
| 10685 | }; |
| 10686 | #undef DECLARE_ENUM |
| 10687 | |
| 10688 | static const char* const kTags[kNumberOfSyncTags]; |
| 10689 | static const char* const kTagNames[kNumberOfSyncTags]; |
| 10690 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10691 | |
| 10692 | // Abstract base class for visiting, and optionally modifying, the |
| 10693 | // pointers contained in Objects. Used in GC and serialization/deserialization. |
| 10694 | class ObjectVisitor BASE_EMBEDDED { |
| 10695 | public: |
| 10696 | virtual ~ObjectVisitor() {} |
| 10697 | |
| 10698 | // Visits a contiguous arrays of pointers in the half-open range |
| 10699 | // [start, end). Any or all of the values may be modified on return. |
| 10700 | virtual void VisitPointers(Object** start, Object** end) = 0; |
| 10701 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10702 | // Handy shorthand for visiting a single pointer. |
| 10703 | virtual void VisitPointer(Object** p) { VisitPointers(p, p + 1); } |
| 10704 | |
| 10705 | // Visit weak next_code_link in Code object. |
| 10706 | virtual void VisitNextCodeLink(Object** p) { VisitPointers(p, p + 1); } |
| 10707 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10708 | // To allow lazy clearing of inline caches the visitor has |
| 10709 | // a rich interface for iterating over Code objects.. |
| 10710 | |
| 10711 | // Visits a code target in the instruction stream. |
| 10712 | virtual void VisitCodeTarget(RelocInfo* rinfo); |
| 10713 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 10714 | // Visits a code entry in a JS function. |
| 10715 | virtual void VisitCodeEntry(Address entry_address); |
| 10716 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 10717 | // Visits a global property cell reference in the instruction stream. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10718 | virtual void VisitCell(RelocInfo* rinfo); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 10719 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10720 | // Visits a runtime entry in the instruction stream. |
| 10721 | virtual void VisitRuntimeEntry(RelocInfo* rinfo) {} |
| 10722 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10723 | // Visits the resource of an one-byte or two-byte string. |
| 10724 | virtual void VisitExternalOneByteString( |
| 10725 | v8::String::ExternalOneByteStringResource** resource) {} |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 10726 | virtual void VisitExternalTwoByteString( |
| 10727 | v8::String::ExternalStringResource** resource) {} |
| 10728 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10729 | // Visits a debug call target in the instruction stream. |
| 10730 | virtual void VisitDebugTarget(RelocInfo* rinfo); |
| 10731 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10732 | // Visits the byte sequence in a function's prologue that contains information |
| 10733 | // about the code's age. |
| 10734 | virtual void VisitCodeAgeSequence(RelocInfo* rinfo); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10735 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10736 | // Visit pointer embedded into a code object. |
| 10737 | virtual void VisitEmbeddedPointer(RelocInfo* rinfo); |
| 10738 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10739 | // Visits an external reference embedded into a code object. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10740 | virtual void VisitExternalReference(RelocInfo* rinfo); |
| 10741 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10742 | // Visits an external reference. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10743 | virtual void VisitExternalReference(Address* p) {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10744 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10745 | // Visits an (encoded) internal reference. |
| 10746 | virtual void VisitInternalReference(RelocInfo* rinfo) {} |
| 10747 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 10748 | // Visits a handle that has an embedder-assigned class ID. |
| 10749 | virtual void VisitEmbedderReference(Object** p, uint16_t class_id) {} |
| 10750 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10751 | // Intended for serialization/deserialization checking: insert, or |
| 10752 | // check for the presence of, a tag at this position in the stream. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10753 | // Also used for marking up GC roots in heap snapshots. |
| 10754 | virtual void Synchronize(VisitorSynchronization::SyncTag tag) {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10755 | }; |
| 10756 | |
| 10757 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10758 | // BooleanBit is a helper class for setting and getting a bit in an integer. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10759 | class BooleanBit : public AllStatic { |
| 10760 | public: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10761 | static inline bool get(int value, int bit_position) { |
| 10762 | return (value & (1 << bit_position)) != 0; |
| 10763 | } |
| 10764 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10765 | static inline int set(int value, int bit_position, bool v) { |
| 10766 | if (v) { |
| 10767 | value |= (1 << bit_position); |
| 10768 | } else { |
| 10769 | value &= ~(1 << bit_position); |
| 10770 | } |
| 10771 | return value; |
| 10772 | } |
| 10773 | }; |
| 10774 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10775 | |
| 10776 | } // NOLINT, false-positive due to second-order macros. |
| 10777 | } // NOLINT, false-positive due to second-order macros. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10778 | |
| 10779 | #endif // V8_OBJECTS_H_ |