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. |
| 312 | const int kStubMajorKeyBits = 7; |
| 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) \ |
| 401 | V(CODE_CACHE_TYPE) \ |
| 402 | V(POLYMORPHIC_CODE_CACHE_TYPE) \ |
| 403 | V(TYPE_FEEDBACK_INFO_TYPE) \ |
| 404 | V(ALIASED_ARGUMENTS_ENTRY_TYPE) \ |
| 405 | V(BOX_TYPE) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 406 | V(PROTOTYPE_INFO_TYPE) \ |
| 407 | V(SLOPPY_BLOCK_WITH_EVAL_CONTEXT_EXTENSION_TYPE) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 408 | \ |
| 409 | V(FIXED_ARRAY_TYPE) \ |
| 410 | V(FIXED_DOUBLE_ARRAY_TYPE) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 411 | V(SHARED_FUNCTION_INFO_TYPE) \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 412 | V(WEAK_CELL_TYPE) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 413 | V(TRANSITION_ARRAY_TYPE) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 414 | \ |
| 415 | V(JS_MESSAGE_OBJECT_TYPE) \ |
| 416 | \ |
| 417 | V(JS_VALUE_TYPE) \ |
| 418 | V(JS_DATE_TYPE) \ |
| 419 | V(JS_OBJECT_TYPE) \ |
| 420 | V(JS_CONTEXT_EXTENSION_OBJECT_TYPE) \ |
| 421 | V(JS_GENERATOR_OBJECT_TYPE) \ |
| 422 | V(JS_MODULE_TYPE) \ |
| 423 | V(JS_GLOBAL_OBJECT_TYPE) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 424 | V(JS_GLOBAL_PROXY_TYPE) \ |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 425 | V(JS_SPECIAL_API_OBJECT_TYPE) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 426 | V(JS_ARRAY_TYPE) \ |
| 427 | V(JS_ARRAY_BUFFER_TYPE) \ |
| 428 | V(JS_TYPED_ARRAY_TYPE) \ |
| 429 | V(JS_DATA_VIEW_TYPE) \ |
| 430 | V(JS_PROXY_TYPE) \ |
| 431 | V(JS_SET_TYPE) \ |
| 432 | V(JS_MAP_TYPE) \ |
| 433 | V(JS_SET_ITERATOR_TYPE) \ |
| 434 | V(JS_MAP_ITERATOR_TYPE) \ |
| 435 | V(JS_WEAK_MAP_TYPE) \ |
| 436 | V(JS_WEAK_SET_TYPE) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 437 | V(JS_PROMISE_TYPE) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 438 | V(JS_REGEXP_TYPE) \ |
| 439 | \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 440 | V(JS_BOUND_FUNCTION_TYPE) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 441 | V(JS_FUNCTION_TYPE) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 442 | V(DEBUG_INFO_TYPE) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 443 | V(BREAK_POINT_INFO_TYPE) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 444 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 445 | // Since string types are not consecutive, this macro is used to |
| 446 | // iterate over them. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 447 | #define STRING_TYPE_LIST(V) \ |
| 448 | V(STRING_TYPE, kVariableSizeSentinel, string, String) \ |
| 449 | V(ONE_BYTE_STRING_TYPE, kVariableSizeSentinel, one_byte_string, \ |
| 450 | OneByteString) \ |
| 451 | V(CONS_STRING_TYPE, ConsString::kSize, cons_string, ConsString) \ |
| 452 | V(CONS_ONE_BYTE_STRING_TYPE, ConsString::kSize, cons_one_byte_string, \ |
| 453 | ConsOneByteString) \ |
| 454 | V(SLICED_STRING_TYPE, SlicedString::kSize, sliced_string, SlicedString) \ |
| 455 | V(SLICED_ONE_BYTE_STRING_TYPE, SlicedString::kSize, sliced_one_byte_string, \ |
| 456 | SlicedOneByteString) \ |
| 457 | V(EXTERNAL_STRING_TYPE, ExternalTwoByteString::kSize, external_string, \ |
| 458 | ExternalString) \ |
| 459 | V(EXTERNAL_ONE_BYTE_STRING_TYPE, ExternalOneByteString::kSize, \ |
| 460 | external_one_byte_string, ExternalOneByteString) \ |
| 461 | V(EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE, ExternalTwoByteString::kSize, \ |
| 462 | external_string_with_one_byte_data, ExternalStringWithOneByteData) \ |
| 463 | V(SHORT_EXTERNAL_STRING_TYPE, ExternalTwoByteString::kShortSize, \ |
| 464 | short_external_string, ShortExternalString) \ |
| 465 | V(SHORT_EXTERNAL_ONE_BYTE_STRING_TYPE, ExternalOneByteString::kShortSize, \ |
| 466 | short_external_one_byte_string, ShortExternalOneByteString) \ |
| 467 | V(SHORT_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE, \ |
| 468 | ExternalTwoByteString::kShortSize, \ |
| 469 | short_external_string_with_one_byte_data, \ |
| 470 | ShortExternalStringWithOneByteData) \ |
| 471 | \ |
| 472 | V(INTERNALIZED_STRING_TYPE, kVariableSizeSentinel, internalized_string, \ |
| 473 | InternalizedString) \ |
| 474 | V(ONE_BYTE_INTERNALIZED_STRING_TYPE, kVariableSizeSentinel, \ |
| 475 | one_byte_internalized_string, OneByteInternalizedString) \ |
| 476 | V(EXTERNAL_INTERNALIZED_STRING_TYPE, ExternalTwoByteString::kSize, \ |
| 477 | external_internalized_string, ExternalInternalizedString) \ |
| 478 | V(EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE, ExternalOneByteString::kSize, \ |
| 479 | external_one_byte_internalized_string, ExternalOneByteInternalizedString) \ |
| 480 | V(EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE, \ |
| 481 | ExternalTwoByteString::kSize, \ |
| 482 | external_internalized_string_with_one_byte_data, \ |
| 483 | ExternalInternalizedStringWithOneByteData) \ |
| 484 | V(SHORT_EXTERNAL_INTERNALIZED_STRING_TYPE, \ |
| 485 | ExternalTwoByteString::kShortSize, short_external_internalized_string, \ |
| 486 | ShortExternalInternalizedString) \ |
| 487 | V(SHORT_EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE, \ |
| 488 | ExternalOneByteString::kShortSize, \ |
| 489 | short_external_one_byte_internalized_string, \ |
| 490 | ShortExternalOneByteInternalizedString) \ |
| 491 | V(SHORT_EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE, \ |
| 492 | ExternalTwoByteString::kShortSize, \ |
| 493 | short_external_internalized_string_with_one_byte_data, \ |
| 494 | ShortExternalInternalizedStringWithOneByteData) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 495 | |
| 496 | // A struct is a simple object a set of object-valued fields. Including an |
| 497 | // object type in this causes the compiler to generate most of the boilerplate |
| 498 | // code for the class including allocation and garbage collection routines, |
| 499 | // casts and predicates. All you need to define is the class, methods and |
| 500 | // object verification routines. Easy, no? |
| 501 | // |
| 502 | // Note that for subtle reasons related to the ordering or numerical values of |
| 503 | // type tags, elements in this list have to be added to the INSTANCE_TYPE_LIST |
| 504 | // manually. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 505 | #define STRUCT_LIST(V) \ |
| 506 | V(BOX, Box, box) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 507 | V(ACCESSOR_INFO, AccessorInfo, accessor_info) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 508 | V(ACCESSOR_PAIR, AccessorPair, accessor_pair) \ |
| 509 | V(ACCESS_CHECK_INFO, AccessCheckInfo, access_check_info) \ |
| 510 | V(INTERCEPTOR_INFO, InterceptorInfo, interceptor_info) \ |
| 511 | V(CALL_HANDLER_INFO, CallHandlerInfo, call_handler_info) \ |
| 512 | V(FUNCTION_TEMPLATE_INFO, FunctionTemplateInfo, function_template_info) \ |
| 513 | V(OBJECT_TEMPLATE_INFO, ObjectTemplateInfo, object_template_info) \ |
| 514 | V(SCRIPT, Script, script) \ |
| 515 | V(ALLOCATION_SITE, AllocationSite, allocation_site) \ |
| 516 | V(ALLOCATION_MEMENTO, AllocationMemento, allocation_memento) \ |
| 517 | V(CODE_CACHE, CodeCache, code_cache) \ |
| 518 | V(POLYMORPHIC_CODE_CACHE, PolymorphicCodeCache, polymorphic_code_cache) \ |
| 519 | V(TYPE_FEEDBACK_INFO, TypeFeedbackInfo, type_feedback_info) \ |
| 520 | V(ALIASED_ARGUMENTS_ENTRY, AliasedArgumentsEntry, aliased_arguments_entry) \ |
| 521 | V(DEBUG_INFO, DebugInfo, debug_info) \ |
| 522 | V(BREAK_POINT_INFO, BreakPointInfo, break_point_info) \ |
| 523 | V(PROTOTYPE_INFO, PrototypeInfo, prototype_info) \ |
| 524 | V(SLOPPY_BLOCK_WITH_EVAL_CONTEXT_EXTENSION, \ |
| 525 | SloppyBlockWithEvalContextExtension, \ |
| 526 | sloppy_block_with_eval_context_extension) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 527 | |
| 528 | // We use the full 8 bits of the instance_type field to encode heap object |
| 529 | // instance types. The high-order bit (bit 7) is set if the object is not a |
| 530 | // string, and cleared if it is a string. |
| 531 | const uint32_t kIsNotStringMask = 0x80; |
| 532 | const uint32_t kStringTag = 0x0; |
| 533 | const uint32_t kNotStringTag = 0x80; |
| 534 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 535 | // Bit 6 indicates that the object is an internalized string (if set) or not. |
| 536 | // Bit 7 has to be clear as well. |
| 537 | const uint32_t kIsNotInternalizedMask = 0x40; |
| 538 | const uint32_t kNotInternalizedTag = 0x40; |
| 539 | const uint32_t kInternalizedTag = 0x0; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 540 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 541 | // If bit 7 is clear then bit 2 indicates whether the string consists of |
| 542 | // two-byte characters or one-byte characters. |
| 543 | const uint32_t kStringEncodingMask = 0x4; |
| 544 | const uint32_t kTwoByteStringTag = 0x0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 545 | const uint32_t kOneByteStringTag = 0x4; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 546 | |
| 547 | // If bit 7 is clear, the low-order 2 bits indicate the representation |
| 548 | // of the string. |
| 549 | const uint32_t kStringRepresentationMask = 0x03; |
| 550 | enum StringRepresentationTag { |
| 551 | kSeqStringTag = 0x0, |
| 552 | kConsStringTag = 0x1, |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 553 | kExternalStringTag = 0x2, |
| 554 | kSlicedStringTag = 0x3 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 555 | }; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 556 | const uint32_t kIsIndirectStringMask = 0x1; |
| 557 | const uint32_t kIsIndirectStringTag = 0x1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 558 | STATIC_ASSERT((kSeqStringTag & kIsIndirectStringMask) == 0); // NOLINT |
| 559 | STATIC_ASSERT((kExternalStringTag & kIsIndirectStringMask) == 0); // NOLINT |
| 560 | STATIC_ASSERT((kConsStringTag & |
| 561 | kIsIndirectStringMask) == kIsIndirectStringTag); // NOLINT |
| 562 | STATIC_ASSERT((kSlicedStringTag & |
| 563 | kIsIndirectStringMask) == kIsIndirectStringTag); // NOLINT |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 564 | |
| 565 | // Use this mask to distinguish between cons and slice only after making |
| 566 | // sure that the string is one of the two (an indirect string). |
| 567 | const uint32_t kSlicedNotConsMask = kSlicedStringTag & ~kConsStringTag; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 568 | STATIC_ASSERT(IS_POWER_OF_TWO(kSlicedNotConsMask)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 569 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 570 | // 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] | 571 | // string actually contains one byte data. |
| 572 | const uint32_t kOneByteDataHintMask = 0x08; |
| 573 | const uint32_t kOneByteDataHintTag = 0x08; |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 574 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 575 | // If bit 7 is clear and string representation indicates an external string, |
| 576 | // then bit 4 indicates whether the data pointer is cached. |
| 577 | const uint32_t kShortExternalStringMask = 0x10; |
| 578 | const uint32_t kShortExternalStringTag = 0x10; |
| 579 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 580 | |
| 581 | // 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] | 582 | // for being shortcut by the garbage collector. We don't allocate any |
| 583 | // non-flat internalized strings, so we do not shortcut them thereby |
| 584 | // avoiding turning internalized strings into strings. The bit-masks |
| 585 | // below contain the internalized bit as additional safety. |
| 586 | // See heap.cc, mark-compact.cc and objects-visiting.cc. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 587 | const uint32_t kShortcutTypeMask = |
| 588 | kIsNotStringMask | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 589 | kIsNotInternalizedMask | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 590 | kStringRepresentationMask; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 591 | const uint32_t kShortcutTypeTag = kConsStringTag | kNotInternalizedTag; |
| 592 | |
| 593 | static inline bool IsShortcutCandidate(int type) { |
| 594 | return ((type & kShortcutTypeMask) == kShortcutTypeTag); |
| 595 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 596 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 597 | enum InstanceType { |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 598 | // String types. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 599 | INTERNALIZED_STRING_TYPE = kTwoByteStringTag | kSeqStringTag | |
| 600 | kInternalizedTag, // FIRST_PRIMITIVE_TYPE |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 601 | ONE_BYTE_INTERNALIZED_STRING_TYPE = |
| 602 | kOneByteStringTag | kSeqStringTag | kInternalizedTag, |
| 603 | EXTERNAL_INTERNALIZED_STRING_TYPE = |
| 604 | kTwoByteStringTag | kExternalStringTag | kInternalizedTag, |
| 605 | EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE = |
| 606 | kOneByteStringTag | kExternalStringTag | kInternalizedTag, |
| 607 | EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE = |
| 608 | EXTERNAL_INTERNALIZED_STRING_TYPE | kOneByteDataHintTag | |
| 609 | kInternalizedTag, |
| 610 | SHORT_EXTERNAL_INTERNALIZED_STRING_TYPE = EXTERNAL_INTERNALIZED_STRING_TYPE | |
| 611 | kShortExternalStringTag | |
| 612 | kInternalizedTag, |
| 613 | SHORT_EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE = |
| 614 | EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE | kShortExternalStringTag | |
| 615 | kInternalizedTag, |
| 616 | SHORT_EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE = |
| 617 | EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE | |
| 618 | kShortExternalStringTag | kInternalizedTag, |
| 619 | STRING_TYPE = INTERNALIZED_STRING_TYPE | kNotInternalizedTag, |
| 620 | ONE_BYTE_STRING_TYPE = |
| 621 | ONE_BYTE_INTERNALIZED_STRING_TYPE | kNotInternalizedTag, |
| 622 | CONS_STRING_TYPE = kTwoByteStringTag | kConsStringTag | kNotInternalizedTag, |
| 623 | CONS_ONE_BYTE_STRING_TYPE = |
| 624 | kOneByteStringTag | kConsStringTag | kNotInternalizedTag, |
| 625 | SLICED_STRING_TYPE = |
| 626 | kTwoByteStringTag | kSlicedStringTag | kNotInternalizedTag, |
| 627 | SLICED_ONE_BYTE_STRING_TYPE = |
| 628 | kOneByteStringTag | kSlicedStringTag | kNotInternalizedTag, |
| 629 | EXTERNAL_STRING_TYPE = |
| 630 | EXTERNAL_INTERNALIZED_STRING_TYPE | kNotInternalizedTag, |
| 631 | EXTERNAL_ONE_BYTE_STRING_TYPE = |
| 632 | EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE | kNotInternalizedTag, |
| 633 | EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE = |
| 634 | EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE | |
| 635 | kNotInternalizedTag, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 636 | SHORT_EXTERNAL_STRING_TYPE = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 637 | SHORT_EXTERNAL_INTERNALIZED_STRING_TYPE | kNotInternalizedTag, |
| 638 | SHORT_EXTERNAL_ONE_BYTE_STRING_TYPE = |
| 639 | SHORT_EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE | kNotInternalizedTag, |
| 640 | SHORT_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE = |
| 641 | SHORT_EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE | |
| 642 | kNotInternalizedTag, |
| 643 | |
| 644 | // Non-string names |
| 645 | SYMBOL_TYPE = kNotStringTag, // FIRST_NONSTRING_TYPE, LAST_NAME_TYPE |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 646 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 647 | // Other primitives (cannot contain non-map-word pointers to heap objects). |
| 648 | HEAP_NUMBER_TYPE, |
| 649 | SIMD128_VALUE_TYPE, |
| 650 | ODDBALL_TYPE, // LAST_PRIMITIVE_TYPE |
| 651 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 652 | // Objects allocated in their own spaces (never in new space). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 653 | MAP_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 654 | CODE_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 655 | |
| 656 | // "Data", objects that cannot contain non-map-word pointers to heap |
| 657 | // objects. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 658 | MUTABLE_HEAP_NUMBER_TYPE, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 659 | FOREIGN_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 660 | BYTE_ARRAY_TYPE, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 661 | BYTECODE_ARRAY_TYPE, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 662 | FREE_SPACE_TYPE, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 663 | FIXED_INT8_ARRAY_TYPE, // FIRST_FIXED_TYPED_ARRAY_TYPE |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 664 | FIXED_UINT8_ARRAY_TYPE, |
| 665 | FIXED_INT16_ARRAY_TYPE, |
| 666 | FIXED_UINT16_ARRAY_TYPE, |
| 667 | FIXED_INT32_ARRAY_TYPE, |
| 668 | FIXED_UINT32_ARRAY_TYPE, |
| 669 | FIXED_FLOAT32_ARRAY_TYPE, |
| 670 | FIXED_FLOAT64_ARRAY_TYPE, |
| 671 | FIXED_UINT8_CLAMPED_ARRAY_TYPE, // LAST_FIXED_TYPED_ARRAY_TYPE |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 672 | FIXED_DOUBLE_ARRAY_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 673 | FILLER_TYPE, // LAST_DATA_TYPE |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 674 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 675 | // Structs. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 676 | ACCESSOR_INFO_TYPE, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 677 | ACCESSOR_PAIR_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 678 | ACCESS_CHECK_INFO_TYPE, |
| 679 | INTERCEPTOR_INFO_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 680 | CALL_HANDLER_INFO_TYPE, |
| 681 | FUNCTION_TEMPLATE_INFO_TYPE, |
| 682 | OBJECT_TEMPLATE_INFO_TYPE, |
| 683 | SIGNATURE_INFO_TYPE, |
| 684 | TYPE_SWITCH_INFO_TYPE, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 685 | ALLOCATION_SITE_TYPE, |
| 686 | ALLOCATION_MEMENTO_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 687 | SCRIPT_TYPE, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 688 | CODE_CACHE_TYPE, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 689 | POLYMORPHIC_CODE_CACHE_TYPE, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 690 | TYPE_FEEDBACK_INFO_TYPE, |
| 691 | ALIASED_ARGUMENTS_ENTRY_TYPE, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 692 | BOX_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 693 | DEBUG_INFO_TYPE, |
| 694 | BREAK_POINT_INFO_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 695 | FIXED_ARRAY_TYPE, |
| 696 | SHARED_FUNCTION_INFO_TYPE, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 697 | CELL_TYPE, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 698 | WEAK_CELL_TYPE, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 699 | TRANSITION_ARRAY_TYPE, |
| 700 | PROPERTY_CELL_TYPE, |
| 701 | PROTOTYPE_INFO_TYPE, |
| 702 | SLOPPY_BLOCK_WITH_EVAL_CONTEXT_EXTENSION_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 703 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 704 | // All the following types are subtypes of JSReceiver, which corresponds to |
| 705 | // objects in the JS sense. The first and the last type in this range are |
| 706 | // the two forms of function. This organization enables using the same |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 707 | // compares for checking the JS_RECEIVER and the NONCALLABLE_JS_OBJECT range. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 708 | JS_PROXY_TYPE, // FIRST_JS_RECEIVER_TYPE |
| 709 | JS_GLOBAL_OBJECT_TYPE, // FIRST_JS_OBJECT_TYPE |
| 710 | JS_GLOBAL_PROXY_TYPE, |
| 711 | // Like JS_OBJECT_TYPE, but requires access checks and/or has interceptors. |
| 712 | JS_SPECIAL_API_OBJECT_TYPE, // LAST_SPECIAL_RECEIVER_TYPE |
| 713 | JS_VALUE_TYPE, // LAST_CUSTOM_ELEMENTS_RECEIVER |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 714 | JS_MESSAGE_OBJECT_TYPE, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 715 | JS_DATE_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 716 | JS_OBJECT_TYPE, |
| 717 | JS_CONTEXT_EXTENSION_OBJECT_TYPE, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 718 | JS_GENERATOR_OBJECT_TYPE, |
| 719 | JS_MODULE_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 720 | JS_ARRAY_TYPE, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 721 | JS_ARRAY_BUFFER_TYPE, |
| 722 | JS_TYPED_ARRAY_TYPE, |
| 723 | JS_DATA_VIEW_TYPE, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 724 | JS_SET_TYPE, |
| 725 | JS_MAP_TYPE, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 726 | JS_SET_ITERATOR_TYPE, |
| 727 | JS_MAP_ITERATOR_TYPE, |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 728 | JS_WEAK_MAP_TYPE, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 729 | JS_WEAK_SET_TYPE, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 730 | JS_PROMISE_TYPE, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 731 | JS_REGEXP_TYPE, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 732 | JS_BOUND_FUNCTION_TYPE, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 733 | JS_FUNCTION_TYPE, // LAST_JS_OBJECT_TYPE, LAST_JS_RECEIVER_TYPE |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 734 | |
| 735 | // Pseudo-types |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 736 | FIRST_TYPE = 0x0, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 737 | LAST_TYPE = JS_FUNCTION_TYPE, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 738 | FIRST_NAME_TYPE = FIRST_TYPE, |
| 739 | LAST_NAME_TYPE = SYMBOL_TYPE, |
| 740 | FIRST_UNIQUE_NAME_TYPE = INTERNALIZED_STRING_TYPE, |
| 741 | LAST_UNIQUE_NAME_TYPE = SYMBOL_TYPE, |
| 742 | FIRST_NONSTRING_TYPE = SYMBOL_TYPE, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 743 | FIRST_PRIMITIVE_TYPE = FIRST_NAME_TYPE, |
| 744 | LAST_PRIMITIVE_TYPE = ODDBALL_TYPE, |
| 745 | FIRST_FUNCTION_TYPE = JS_BOUND_FUNCTION_TYPE, |
| 746 | LAST_FUNCTION_TYPE = JS_FUNCTION_TYPE, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 747 | // Boundaries for testing for a fixed typed array. |
| 748 | FIRST_FIXED_TYPED_ARRAY_TYPE = FIXED_INT8_ARRAY_TYPE, |
| 749 | LAST_FIXED_TYPED_ARRAY_TYPE = FIXED_UINT8_CLAMPED_ARRAY_TYPE, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 750 | // Boundary for promotion to old space. |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 751 | LAST_DATA_TYPE = FILLER_TYPE, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 752 | // Boundary for objects represented as JSReceiver (i.e. JSObject or JSProxy). |
| 753 | // Note that there is no range for JSObject or JSProxy, since their subtypes |
| 754 | // are not continuous in this enum! The enum ranges instead reflect the |
| 755 | // external class names, where proxies are treated as either ordinary objects, |
| 756 | // or functions. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 757 | FIRST_JS_RECEIVER_TYPE = JS_PROXY_TYPE, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 758 | LAST_JS_RECEIVER_TYPE = LAST_TYPE, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 759 | // Boundaries for testing the types represented as JSObject |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 760 | FIRST_JS_OBJECT_TYPE = JS_GLOBAL_OBJECT_TYPE, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 761 | LAST_JS_OBJECT_TYPE = LAST_TYPE, |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 762 | // Boundary for testing JSReceivers that need special property lookup handling |
| 763 | LAST_SPECIAL_RECEIVER_TYPE = JS_SPECIAL_API_OBJECT_TYPE, |
| 764 | // Boundary case for testing JSReceivers that may have elements while having |
| 765 | // an empty fixed array as elements backing store. This is true for string |
| 766 | // wrappers. |
| 767 | LAST_CUSTOM_ELEMENTS_RECEIVER = JS_VALUE_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 768 | }; |
| 769 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 770 | STATIC_ASSERT(JS_OBJECT_TYPE == Internals::kJSObjectType); |
| 771 | STATIC_ASSERT(FIRST_NONSTRING_TYPE == Internals::kFirstNonstringType); |
| 772 | STATIC_ASSERT(ODDBALL_TYPE == Internals::kOddballType); |
| 773 | STATIC_ASSERT(FOREIGN_TYPE == Internals::kForeignType); |
| 774 | |
| 775 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 776 | std::ostream& operator<<(std::ostream& os, InstanceType instance_type); |
| 777 | |
| 778 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 779 | #define FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(V) \ |
| 780 | V(FAST_ELEMENTS_SUB_TYPE) \ |
| 781 | V(DICTIONARY_ELEMENTS_SUB_TYPE) \ |
| 782 | V(FAST_PROPERTIES_SUB_TYPE) \ |
| 783 | V(DICTIONARY_PROPERTIES_SUB_TYPE) \ |
| 784 | V(MAP_CODE_CACHE_SUB_TYPE) \ |
| 785 | V(SCOPE_INFO_SUB_TYPE) \ |
| 786 | V(STRING_TABLE_SUB_TYPE) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 787 | V(DESCRIPTOR_ARRAY_SUB_TYPE) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 788 | |
| 789 | enum FixedArraySubInstanceType { |
| 790 | #define DEFINE_FIXED_ARRAY_SUB_INSTANCE_TYPE(name) name, |
| 791 | FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(DEFINE_FIXED_ARRAY_SUB_INSTANCE_TYPE) |
| 792 | #undef DEFINE_FIXED_ARRAY_SUB_INSTANCE_TYPE |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 793 | LAST_FIXED_ARRAY_SUB_TYPE = DESCRIPTOR_ARRAY_SUB_TYPE |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 794 | }; |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 795 | |
| 796 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 797 | // TODO(bmeurer): Remove this in favor of the ComparisonResult below. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 798 | enum CompareResult { |
| 799 | LESS = -1, |
| 800 | EQUAL = 0, |
| 801 | GREATER = 1, |
| 802 | |
| 803 | NOT_EQUAL = GREATER |
| 804 | }; |
| 805 | |
| 806 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 807 | // Result of an abstract relational comparison of x and y, implemented according |
| 808 | // to ES6 section 7.2.11 Abstract Relational Comparison. |
| 809 | enum class ComparisonResult { |
| 810 | kLessThan, // x < y |
| 811 | kEqual, // x = y |
| 812 | kGreaterThan, // x > y |
| 813 | kUndefined // at least one of x or y was undefined or NaN |
| 814 | }; |
| 815 | |
| 816 | |
| 817 | #define DECL_BOOLEAN_ACCESSORS(name) \ |
| 818 | inline bool name() const; \ |
| 819 | inline void set_##name(bool value); |
| 820 | |
| 821 | #define DECL_INT_ACCESSORS(name) \ |
| 822 | inline int name() const; \ |
| 823 | inline void set_##name(int value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 824 | |
| 825 | |
| 826 | #define DECL_ACCESSORS(name, type) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 827 | inline type* name() const; \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 828 | inline void set_##name(type* value, \ |
| 829 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); \ |
| 830 | |
| 831 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 832 | #define DECLARE_CAST(type) \ |
| 833 | INLINE(static type* cast(Object* object)); \ |
| 834 | INLINE(static const type* cast(const Object* object)); |
| 835 | |
| 836 | |
| 837 | class AccessorPair; |
| 838 | class AllocationSite; |
| 839 | class AllocationSiteCreationContext; |
| 840 | class AllocationSiteUsageContext; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 841 | class Cell; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 842 | class ConsString; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 843 | class ElementsAccessor; |
| 844 | class FixedArrayBase; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 845 | class FunctionLiteral; |
| 846 | class JSGlobalObject; |
| 847 | class KeyAccumulator; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 848 | class LayoutDescriptor; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 849 | class LiteralsArray; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 850 | class LookupIterator; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 851 | class FieldType; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 852 | class ObjectHashTable; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 853 | class ObjectVisitor; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 854 | class PropertyCell; |
| 855 | class PropertyDescriptor; |
| 856 | class SafepointEntry; |
| 857 | class SharedFunctionInfo; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 858 | class StringStream; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 859 | class TypeFeedbackInfo; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 860 | class TypeFeedbackVector; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 861 | class WeakCell; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 862 | class TransitionArray; |
| 863 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 864 | |
| 865 | // A template-ized version of the IsXXX functions. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 866 | template <class C> inline bool Is(Object* obj); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 867 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 868 | #ifdef VERIFY_HEAP |
| 869 | #define DECLARE_VERIFIER(Name) void Name##Verify(); |
| 870 | #else |
| 871 | #define DECLARE_VERIFIER(Name) |
| 872 | #endif |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 873 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 874 | #ifdef OBJECT_PRINT |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 875 | #define DECLARE_PRINTER(Name) void Name##Print(std::ostream& os); // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 876 | #else |
| 877 | #define DECLARE_PRINTER(Name) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 878 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 879 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 880 | #define OBJECT_TYPE_LIST(V) \ |
| 881 | V(Smi) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 882 | V(LayoutDescriptor) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 883 | V(HeapObject) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 884 | V(Primitive) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 885 | V(Number) |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 886 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 887 | #define HEAP_OBJECT_TYPE_LIST(V) \ |
| 888 | V(HeapNumber) \ |
| 889 | V(MutableHeapNumber) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 890 | V(Simd128Value) \ |
| 891 | V(Float32x4) \ |
| 892 | V(Int32x4) \ |
| 893 | V(Uint32x4) \ |
| 894 | V(Bool32x4) \ |
| 895 | V(Int16x8) \ |
| 896 | V(Uint16x8) \ |
| 897 | V(Bool16x8) \ |
| 898 | V(Int8x16) \ |
| 899 | V(Uint8x16) \ |
| 900 | V(Bool8x16) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 901 | V(Name) \ |
| 902 | V(UniqueName) \ |
| 903 | V(String) \ |
| 904 | V(SeqString) \ |
| 905 | V(ExternalString) \ |
| 906 | V(ConsString) \ |
| 907 | V(SlicedString) \ |
| 908 | V(ExternalTwoByteString) \ |
| 909 | V(ExternalOneByteString) \ |
| 910 | V(SeqTwoByteString) \ |
| 911 | V(SeqOneByteString) \ |
| 912 | V(InternalizedString) \ |
| 913 | V(Symbol) \ |
| 914 | \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 915 | V(FixedTypedArrayBase) \ |
| 916 | V(FixedUint8Array) \ |
| 917 | V(FixedInt8Array) \ |
| 918 | V(FixedUint16Array) \ |
| 919 | V(FixedInt16Array) \ |
| 920 | V(FixedUint32Array) \ |
| 921 | V(FixedInt32Array) \ |
| 922 | V(FixedFloat32Array) \ |
| 923 | V(FixedFloat64Array) \ |
| 924 | V(FixedUint8ClampedArray) \ |
| 925 | V(ByteArray) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 926 | V(BytecodeArray) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 927 | V(FreeSpace) \ |
| 928 | V(JSReceiver) \ |
| 929 | V(JSObject) \ |
| 930 | V(JSContextExtensionObject) \ |
| 931 | V(JSGeneratorObject) \ |
| 932 | V(JSModule) \ |
| 933 | V(Map) \ |
| 934 | V(DescriptorArray) \ |
| 935 | V(TransitionArray) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 936 | V(LiteralsArray) \ |
| 937 | V(TypeFeedbackMetadata) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 938 | V(TypeFeedbackVector) \ |
| 939 | V(DeoptimizationInputData) \ |
| 940 | V(DeoptimizationOutputData) \ |
| 941 | V(DependentCode) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 942 | V(HandlerTable) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 943 | V(FixedArray) \ |
| 944 | V(FixedDoubleArray) \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 945 | V(WeakFixedArray) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 946 | V(ArrayList) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 947 | V(Context) \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 948 | V(ScriptContextTable) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 949 | V(NativeContext) \ |
| 950 | V(ScopeInfo) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 951 | V(JSBoundFunction) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 952 | V(JSFunction) \ |
| 953 | V(Code) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 954 | V(AbstractCode) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 955 | V(Oddball) \ |
| 956 | V(SharedFunctionInfo) \ |
| 957 | V(JSValue) \ |
| 958 | V(JSDate) \ |
| 959 | V(JSMessageObject) \ |
| 960 | V(StringWrapper) \ |
| 961 | V(Foreign) \ |
| 962 | V(Boolean) \ |
| 963 | V(JSArray) \ |
| 964 | V(JSArrayBuffer) \ |
| 965 | V(JSArrayBufferView) \ |
| 966 | V(JSTypedArray) \ |
| 967 | V(JSDataView) \ |
| 968 | V(JSProxy) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 969 | V(JSSet) \ |
| 970 | V(JSMap) \ |
| 971 | V(JSSetIterator) \ |
| 972 | V(JSMapIterator) \ |
| 973 | V(JSWeakCollection) \ |
| 974 | V(JSWeakMap) \ |
| 975 | V(JSWeakSet) \ |
| 976 | V(JSRegExp) \ |
| 977 | V(HashTable) \ |
| 978 | V(Dictionary) \ |
| 979 | V(StringTable) \ |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 980 | V(StringSet) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 981 | V(NormalizedMapCache) \ |
| 982 | V(CompilationCacheTable) \ |
| 983 | V(CodeCacheHashTable) \ |
| 984 | V(PolymorphicCodeCacheHashTable) \ |
| 985 | V(MapCache) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 986 | V(JSGlobalObject) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 987 | V(JSGlobalProxy) \ |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 988 | V(Undetectable) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 989 | V(AccessCheckNeeded) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 990 | V(Callable) \ |
| 991 | V(Function) \ |
| 992 | V(Constructor) \ |
| 993 | V(TemplateInfo) \ |
| 994 | V(Filler) \ |
| 995 | V(FixedArrayBase) \ |
| 996 | V(External) \ |
| 997 | V(Struct) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 998 | V(Cell) \ |
| 999 | V(PropertyCell) \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1000 | V(WeakCell) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1001 | V(ObjectHashTable) \ |
| 1002 | V(WeakHashTable) \ |
| 1003 | V(OrderedHashTable) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1004 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1005 | #define ODDBALL_LIST(V) \ |
| 1006 | V(Undefined) \ |
| 1007 | V(Null) \ |
| 1008 | V(TheHole) \ |
| 1009 | V(Exception) \ |
| 1010 | V(Uninitialized) \ |
| 1011 | V(True) \ |
| 1012 | V(False) \ |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1013 | V(ArgumentsMarker) \ |
| 1014 | V(OptimizedOut) |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1015 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1016 | // The element types selection for CreateListFromArrayLike. |
| 1017 | enum class ElementTypes { kAll, kStringAndSymbol }; |
| 1018 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1019 | // Object is the abstract superclass for all classes in the |
| 1020 | // object hierarchy. |
| 1021 | // Object does not use any virtual functions to avoid the |
| 1022 | // allocation of the C++ vtable. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1023 | // Since both Smi and HeapObject are subclasses of Object no |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1024 | // data members can be present in Object. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1025 | class Object { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1026 | public: |
| 1027 | // Type testing. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1028 | bool IsObject() const { return true; } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1029 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1030 | #define IS_TYPE_FUNCTION_DECL(type_) INLINE(bool Is##type_() const); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1031 | OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL) |
| 1032 | HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL) |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1033 | ODDBALL_LIST(IS_TYPE_FUNCTION_DECL) |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1034 | #undef IS_TYPE_FUNCTION_DECL |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1035 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1036 | // A non-keyed store is of the form a.x = foo or a["x"] = foo whereas |
| 1037 | // a keyed store is of the form a[expression] = foo. |
| 1038 | enum StoreFromKeyed { |
| 1039 | MAY_BE_STORE_FROM_KEYED, |
| 1040 | CERTAINLY_NOT_STORE_FROM_KEYED |
| 1041 | }; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1042 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1043 | enum ShouldThrow { THROW_ON_ERROR, DONT_THROW }; |
| 1044 | |
| 1045 | #define RETURN_FAILURE(isolate, should_throw, call) \ |
| 1046 | do { \ |
| 1047 | if ((should_throw) == DONT_THROW) { \ |
| 1048 | return Just(false); \ |
| 1049 | } else { \ |
| 1050 | isolate->Throw(*isolate->factory()->call); \ |
| 1051 | return Nothing<bool>(); \ |
| 1052 | } \ |
| 1053 | } while (false) |
| 1054 | |
| 1055 | #define MAYBE_RETURN(call, value) \ |
| 1056 | do { \ |
| 1057 | if ((call).IsNothing()) return value; \ |
| 1058 | } while (false) |
| 1059 | |
| 1060 | #define MAYBE_RETURN_NULL(call) MAYBE_RETURN(call, MaybeHandle<Object>()) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1061 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1062 | #define DECLARE_STRUCT_PREDICATE(NAME, Name, name) \ |
| 1063 | INLINE(bool Is##Name() const); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1064 | STRUCT_LIST(DECLARE_STRUCT_PREDICATE) |
| 1065 | #undef DECLARE_STRUCT_PREDICATE |
| 1066 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1067 | // ES6, section 7.2.2 IsArray. NOT to be confused with %_IsArray. |
| 1068 | MUST_USE_RESULT static Maybe<bool> IsArray(Handle<Object> object); |
| 1069 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1070 | INLINE(bool IsNameDictionary() const); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1071 | INLINE(bool IsGlobalDictionary() const); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1072 | INLINE(bool IsSeededNumberDictionary() const); |
| 1073 | INLINE(bool IsUnseededNumberDictionary() const); |
| 1074 | INLINE(bool IsOrderedHashSet() const); |
| 1075 | INLINE(bool IsOrderedHashMap() const); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1076 | static bool IsPromise(Handle<Object> object); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1077 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1078 | // Extract the number. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1079 | inline double Number() const; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1080 | INLINE(bool IsNaN() const); |
| 1081 | INLINE(bool IsMinusZero() const); |
| 1082 | bool ToInt32(int32_t* value); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1083 | inline bool ToUint32(uint32_t* value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1084 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1085 | inline Representation OptimalRepresentation(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1086 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1087 | inline ElementsKind OptimalElementsKind(); |
| 1088 | |
| 1089 | inline bool FitsRepresentation(Representation representation); |
| 1090 | |
| 1091 | // Checks whether two valid primitive encodings of a property name resolve to |
| 1092 | // the same logical property. E.g., the smi 1, the string "1" and the double |
| 1093 | // 1 all refer to the same property, so this helper will return true. |
| 1094 | inline bool KeyEquals(Object* other); |
| 1095 | |
| 1096 | inline bool FilterKey(PropertyFilter filter); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1097 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1098 | Handle<FieldType> OptimalType(Isolate* isolate, |
| 1099 | Representation representation); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1100 | |
| 1101 | inline static Handle<Object> NewStorageFor(Isolate* isolate, |
| 1102 | Handle<Object> object, |
| 1103 | Representation representation); |
| 1104 | |
| 1105 | inline static Handle<Object> WrapForRead(Isolate* isolate, |
| 1106 | Handle<Object> object, |
| 1107 | Representation representation); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1108 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1109 | // Returns true if the object is of the correct type to be used as a |
| 1110 | // implementation of a JSObject's elements. |
| 1111 | inline bool HasValidElements(); |
| 1112 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1113 | inline bool HasSpecificClassOf(String* name); |
| 1114 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1115 | bool BooleanValue(); // ECMA-262 9.2. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1116 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1117 | // ES6 section 7.2.11 Abstract Relational Comparison |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1118 | MUST_USE_RESULT static Maybe<ComparisonResult> Compare(Handle<Object> x, |
| 1119 | Handle<Object> y); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1120 | |
| 1121 | // ES6 section 7.2.12 Abstract Equality Comparison |
| 1122 | MUST_USE_RESULT static Maybe<bool> Equals(Handle<Object> x, Handle<Object> y); |
| 1123 | |
| 1124 | // ES6 section 7.2.13 Strict Equality Comparison |
| 1125 | bool StrictEquals(Object* that); |
| 1126 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1127 | // Convert to a JSObject if needed. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1128 | // native_context is used when creating wrapper object. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1129 | MUST_USE_RESULT static inline MaybeHandle<JSReceiver> ToObject( |
| 1130 | Isolate* isolate, Handle<Object> object); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1131 | MUST_USE_RESULT static MaybeHandle<JSReceiver> ToObject( |
| 1132 | Isolate* isolate, Handle<Object> object, Handle<Context> context); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1133 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1134 | // ES6 section 9.2.1.2, OrdinaryCallBindThis for sloppy callee. |
| 1135 | MUST_USE_RESULT static MaybeHandle<JSReceiver> ConvertReceiver( |
| 1136 | Isolate* isolate, Handle<Object> object); |
| 1137 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1138 | // ES6 section 7.1.14 ToPropertyKey |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1139 | MUST_USE_RESULT static inline MaybeHandle<Name> ToName(Isolate* isolate, |
| 1140 | Handle<Object> input); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1141 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1142 | // ES6 section 7.1.1 ToPrimitive |
| 1143 | MUST_USE_RESULT static inline MaybeHandle<Object> ToPrimitive( |
| 1144 | Handle<Object> input, ToPrimitiveHint hint = ToPrimitiveHint::kDefault); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1145 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1146 | // ES6 section 7.1.3 ToNumber |
| 1147 | MUST_USE_RESULT static MaybeHandle<Object> ToNumber(Handle<Object> input); |
| 1148 | |
| 1149 | // ES6 section 7.1.4 ToInteger |
| 1150 | MUST_USE_RESULT static MaybeHandle<Object> ToInteger(Isolate* isolate, |
| 1151 | Handle<Object> input); |
| 1152 | |
| 1153 | // ES6 section 7.1.5 ToInt32 |
| 1154 | MUST_USE_RESULT static MaybeHandle<Object> ToInt32(Isolate* isolate, |
| 1155 | Handle<Object> input); |
| 1156 | |
| 1157 | // ES6 section 7.1.6 ToUint32 |
| 1158 | MUST_USE_RESULT static MaybeHandle<Object> ToUint32(Isolate* isolate, |
| 1159 | Handle<Object> input); |
| 1160 | |
| 1161 | // ES6 section 7.1.12 ToString |
| 1162 | MUST_USE_RESULT static MaybeHandle<String> ToString(Isolate* isolate, |
| 1163 | Handle<Object> input); |
| 1164 | |
| 1165 | // ES6 section 7.1.15 ToLength |
| 1166 | MUST_USE_RESULT static MaybeHandle<Object> ToLength(Isolate* isolate, |
| 1167 | Handle<Object> input); |
| 1168 | |
| 1169 | // ES6 section 7.3.9 GetMethod |
| 1170 | MUST_USE_RESULT static MaybeHandle<Object> GetMethod( |
| 1171 | Handle<JSReceiver> receiver, Handle<Name> name); |
| 1172 | |
| 1173 | // ES6 section 7.3.17 CreateListFromArrayLike |
| 1174 | MUST_USE_RESULT static MaybeHandle<FixedArray> CreateListFromArrayLike( |
| 1175 | Isolate* isolate, Handle<Object> object, ElementTypes element_types); |
| 1176 | |
| 1177 | // Check whether |object| is an instance of Error or NativeError. |
| 1178 | static bool IsErrorObject(Isolate* isolate, Handle<Object> object); |
| 1179 | |
| 1180 | // ES6 section 12.5.6 The typeof Operator |
| 1181 | static Handle<String> TypeOf(Isolate* isolate, Handle<Object> object); |
| 1182 | |
| 1183 | // ES6 section 12.6 Multiplicative Operators |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1184 | MUST_USE_RESULT static MaybeHandle<Object> Multiply(Isolate* isolate, |
| 1185 | Handle<Object> lhs, |
| 1186 | Handle<Object> rhs); |
| 1187 | MUST_USE_RESULT static MaybeHandle<Object> Divide(Isolate* isolate, |
| 1188 | Handle<Object> lhs, |
| 1189 | Handle<Object> rhs); |
| 1190 | MUST_USE_RESULT static MaybeHandle<Object> Modulus(Isolate* isolate, |
| 1191 | Handle<Object> lhs, |
| 1192 | Handle<Object> rhs); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1193 | |
| 1194 | // ES6 section 12.7 Additive Operators |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1195 | MUST_USE_RESULT static MaybeHandle<Object> Add(Isolate* isolate, |
| 1196 | Handle<Object> lhs, |
| 1197 | Handle<Object> rhs); |
| 1198 | MUST_USE_RESULT static MaybeHandle<Object> Subtract(Isolate* isolate, |
| 1199 | Handle<Object> lhs, |
| 1200 | Handle<Object> rhs); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1201 | |
| 1202 | // ES6 section 12.8 Bitwise Shift Operators |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1203 | MUST_USE_RESULT static MaybeHandle<Object> ShiftLeft(Isolate* isolate, |
| 1204 | Handle<Object> lhs, |
| 1205 | Handle<Object> rhs); |
| 1206 | MUST_USE_RESULT static MaybeHandle<Object> ShiftRight(Isolate* isolate, |
| 1207 | Handle<Object> lhs, |
| 1208 | Handle<Object> rhs); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1209 | MUST_USE_RESULT static MaybeHandle<Object> ShiftRightLogical( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1210 | Isolate* isolate, Handle<Object> lhs, Handle<Object> rhs); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1211 | |
| 1212 | // ES6 section 12.9 Relational Operators |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1213 | MUST_USE_RESULT static inline Maybe<bool> GreaterThan(Handle<Object> x, |
| 1214 | Handle<Object> y); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1215 | MUST_USE_RESULT static inline Maybe<bool> GreaterThanOrEqual( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1216 | Handle<Object> x, Handle<Object> y); |
| 1217 | MUST_USE_RESULT static inline Maybe<bool> LessThan(Handle<Object> x, |
| 1218 | Handle<Object> y); |
| 1219 | MUST_USE_RESULT static inline Maybe<bool> LessThanOrEqual(Handle<Object> x, |
| 1220 | Handle<Object> y); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1221 | |
| 1222 | // ES6 section 12.11 Binary Bitwise Operators |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1223 | MUST_USE_RESULT static MaybeHandle<Object> BitwiseAnd(Isolate* isolate, |
| 1224 | Handle<Object> lhs, |
| 1225 | Handle<Object> rhs); |
| 1226 | MUST_USE_RESULT static MaybeHandle<Object> BitwiseOr(Isolate* isolate, |
| 1227 | Handle<Object> lhs, |
| 1228 | Handle<Object> rhs); |
| 1229 | MUST_USE_RESULT static MaybeHandle<Object> BitwiseXor(Isolate* isolate, |
| 1230 | Handle<Object> lhs, |
| 1231 | Handle<Object> rhs); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1232 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1233 | MUST_USE_RESULT static MaybeHandle<Object> GetProperty(LookupIterator* it); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1234 | |
| 1235 | // ES6 [[Set]] (when passed DONT_THROW) |
| 1236 | // Invariants for this and related functions (unless stated otherwise): |
| 1237 | // 1) When the result is Nothing, an exception is pending. |
| 1238 | // 2) When passed THROW_ON_ERROR, the result is never Just(false). |
| 1239 | // In some cases, an exception is thrown regardless of the ShouldThrow |
| 1240 | // argument. These cases are either in accordance with the spec or not |
| 1241 | // covered by it (eg., concerning API callbacks). |
| 1242 | MUST_USE_RESULT static Maybe<bool> SetProperty(LookupIterator* it, |
| 1243 | Handle<Object> value, |
| 1244 | LanguageMode language_mode, |
| 1245 | StoreFromKeyed store_mode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1246 | MUST_USE_RESULT static MaybeHandle<Object> SetProperty( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1247 | Handle<Object> object, Handle<Name> name, Handle<Object> value, |
| 1248 | LanguageMode language_mode, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1249 | StoreFromKeyed store_mode = MAY_BE_STORE_FROM_KEYED); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1250 | MUST_USE_RESULT static inline MaybeHandle<Object> SetPropertyOrElement( |
| 1251 | Handle<Object> object, Handle<Name> name, Handle<Object> value, |
| 1252 | LanguageMode language_mode, |
| 1253 | StoreFromKeyed store_mode = MAY_BE_STORE_FROM_KEYED); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1254 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1255 | MUST_USE_RESULT static Maybe<bool> SetSuperProperty( |
| 1256 | LookupIterator* it, Handle<Object> value, LanguageMode language_mode, |
| 1257 | StoreFromKeyed store_mode); |
| 1258 | |
| 1259 | MUST_USE_RESULT static MaybeHandle<Object> ReadAbsentProperty( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1260 | LookupIterator* it); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1261 | MUST_USE_RESULT static MaybeHandle<Object> ReadAbsentProperty( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1262 | Isolate* isolate, Handle<Object> receiver, Handle<Object> name); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1263 | MUST_USE_RESULT static Maybe<bool> CannotCreateProperty( |
| 1264 | Isolate* isolate, Handle<Object> receiver, Handle<Object> name, |
| 1265 | Handle<Object> value, ShouldThrow should_throw); |
| 1266 | MUST_USE_RESULT static Maybe<bool> WriteToReadOnlyProperty( |
| 1267 | LookupIterator* it, Handle<Object> value, ShouldThrow should_throw); |
| 1268 | MUST_USE_RESULT static Maybe<bool> WriteToReadOnlyProperty( |
| 1269 | Isolate* isolate, Handle<Object> receiver, Handle<Object> name, |
| 1270 | Handle<Object> value, ShouldThrow should_throw); |
| 1271 | MUST_USE_RESULT static Maybe<bool> RedefineIncompatibleProperty( |
| 1272 | Isolate* isolate, Handle<Object> name, Handle<Object> value, |
| 1273 | ShouldThrow should_throw); |
| 1274 | MUST_USE_RESULT static Maybe<bool> SetDataProperty(LookupIterator* it, |
| 1275 | Handle<Object> value); |
| 1276 | MUST_USE_RESULT static Maybe<bool> AddDataProperty( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1277 | LookupIterator* it, Handle<Object> value, PropertyAttributes attributes, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1278 | ShouldThrow should_throw, StoreFromKeyed store_mode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1279 | MUST_USE_RESULT static inline MaybeHandle<Object> GetPropertyOrElement( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1280 | Handle<Object> object, Handle<Name> name); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1281 | MUST_USE_RESULT static inline MaybeHandle<Object> GetPropertyOrElement( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1282 | Handle<Object> receiver, Handle<Name> name, Handle<JSReceiver> holder); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1283 | MUST_USE_RESULT static inline MaybeHandle<Object> GetProperty( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1284 | Handle<Object> object, Handle<Name> name); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1285 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1286 | MUST_USE_RESULT static MaybeHandle<Object> GetPropertyWithAccessor( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1287 | LookupIterator* it); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1288 | MUST_USE_RESULT static Maybe<bool> SetPropertyWithAccessor( |
| 1289 | LookupIterator* it, Handle<Object> value, ShouldThrow should_throw); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1290 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1291 | MUST_USE_RESULT static MaybeHandle<Object> GetPropertyWithDefinedGetter( |
| 1292 | Handle<Object> receiver, |
| 1293 | Handle<JSReceiver> getter); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1294 | MUST_USE_RESULT static Maybe<bool> SetPropertyWithDefinedSetter( |
| 1295 | Handle<Object> receiver, Handle<JSReceiver> setter, Handle<Object> value, |
| 1296 | ShouldThrow should_throw); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1297 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1298 | MUST_USE_RESULT static inline MaybeHandle<Object> GetElement( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1299 | Isolate* isolate, Handle<Object> object, uint32_t index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1300 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1301 | MUST_USE_RESULT static inline MaybeHandle<Object> SetElement( |
| 1302 | Isolate* isolate, Handle<Object> object, uint32_t index, |
| 1303 | Handle<Object> value, LanguageMode language_mode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1304 | |
| 1305 | // Returns the permanent hash code associated with this object. May return |
| 1306 | // undefined if not yet created. |
| 1307 | Object* GetHash(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1308 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1309 | // Returns undefined for JSObjects, but returns the hash code for simple |
| 1310 | // objects. This avoids a double lookup in the cases where we know we will |
| 1311 | // add the hash to the JSObject if it does not already exist. |
| 1312 | Object* GetSimpleHash(); |
| 1313 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1314 | // Returns the permanent hash code associated with this object depending on |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1315 | // the actual object type. May create and store a hash code if needed and none |
| 1316 | // exists. |
| 1317 | static Handle<Smi> GetOrCreateHash(Isolate* isolate, Handle<Object> object); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1318 | |
| 1319 | // Checks whether this object has the same value as the given one. This |
| 1320 | // function is implemented according to ES5, section 9.12 and can be used |
| 1321 | // to implement the Harmony "egal" function. |
| 1322 | bool SameValue(Object* other); |
| 1323 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1324 | // Checks whether this object has the same value as the given one. |
| 1325 | // +0 and -0 are treated equal. Everything else is the same as SameValue. |
| 1326 | // This function is implemented according to ES6, section 7.2.4 and is used |
| 1327 | // by ES6 Map and Set. |
| 1328 | bool SameValueZero(Object* other); |
| 1329 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1330 | // ES6 section 9.4.2.3 ArraySpeciesCreate (part of it) |
| 1331 | MUST_USE_RESULT static MaybeHandle<Object> ArraySpeciesConstructor( |
| 1332 | Isolate* isolate, Handle<Object> original_array); |
| 1333 | |
| 1334 | // Tries to convert an object to an array length. Returns true and sets the |
| 1335 | // output parameter if it succeeds. |
| 1336 | inline bool ToArrayLength(uint32_t* index); |
| 1337 | |
| 1338 | // Tries to convert an object to an array index. Returns true and sets the |
| 1339 | // output parameter if it succeeds. Equivalent to ToArrayLength, but does not |
| 1340 | // allow kMaxUInt32. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1341 | inline bool ToArrayIndex(uint32_t* index); |
| 1342 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1343 | DECLARE_VERIFIER(Object) |
| 1344 | #ifdef VERIFY_HEAP |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1345 | // Verify a pointer is a valid object pointer. |
| 1346 | static void VerifyPointer(Object* p); |
| 1347 | #endif |
| 1348 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1349 | inline void VerifyApiCallResultType(); |
| 1350 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1351 | // ES6 19.1.3.6 Object.prototype.toString |
| 1352 | MUST_USE_RESULT static MaybeHandle<String> ObjectProtoToString( |
| 1353 | Isolate* isolate, Handle<Object> object); |
| 1354 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1355 | // Prints this object without details. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1356 | void ShortPrint(FILE* out = stdout); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1357 | |
| 1358 | // Prints this object without details to a message accumulator. |
| 1359 | void ShortPrint(StringStream* accumulator); |
| 1360 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1361 | void ShortPrint(std::ostream& os); // NOLINT |
| 1362 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1363 | DECLARE_CAST(Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1364 | |
| 1365 | // Layout description. |
| 1366 | static const int kHeaderSize = 0; // Object does not take up any space. |
| 1367 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1368 | #ifdef OBJECT_PRINT |
| 1369 | // For our gdb macros, we should perhaps change these in the future. |
| 1370 | void Print(); |
| 1371 | |
| 1372 | // Prints this object with details. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1373 | void Print(std::ostream& os); // NOLINT |
| 1374 | #else |
| 1375 | void Print() { ShortPrint(); } |
| 1376 | void Print(std::ostream& os) { ShortPrint(os); } // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1377 | #endif |
| 1378 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1379 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1380 | friend class LookupIterator; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1381 | friend class StringStream; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1382 | |
| 1383 | // Return the map of the root of object's prototype chain. |
| 1384 | Map* GetRootMap(Isolate* isolate); |
| 1385 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1386 | // Helper for SetProperty and SetSuperProperty. |
| 1387 | // Return value is only meaningful if [found] is set to true on return. |
| 1388 | MUST_USE_RESULT static Maybe<bool> SetPropertyInternal( |
| 1389 | LookupIterator* it, Handle<Object> value, LanguageMode language_mode, |
| 1390 | StoreFromKeyed store_mode, bool* found); |
| 1391 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1392 | MUST_USE_RESULT static MaybeHandle<Name> ConvertToName(Isolate* isolate, |
| 1393 | Handle<Object> input); |
| 1394 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1395 | DISALLOW_IMPLICIT_CONSTRUCTORS(Object); |
| 1396 | }; |
| 1397 | |
| 1398 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1399 | // In objects.h to be usable without objects-inl.h inclusion. |
| 1400 | bool Object::IsSmi() const { return HAS_SMI_TAG(this); } |
| 1401 | bool Object::IsHeapObject() const { return Internals::HasHeapObjectTag(this); } |
| 1402 | |
| 1403 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1404 | struct Brief { |
| 1405 | explicit Brief(const Object* const v) : value(v) {} |
| 1406 | const Object* value; |
| 1407 | }; |
| 1408 | |
| 1409 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1410 | std::ostream& operator<<(std::ostream& os, const Brief& v); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1411 | |
| 1412 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1413 | // Smi represents integer Numbers that can be stored in 31 bits. |
| 1414 | // Smis are immediate which means they are NOT allocated in the heap. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1415 | // The this pointer has the following format: [31 bit signed int] 0 |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1416 | // For long smis it has the following format: |
| 1417 | // [32 bit signed int] [31 bits zero padding] 0 |
| 1418 | // Smi stands for small integer. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1419 | class Smi: public Object { |
| 1420 | public: |
| 1421 | // Returns the integer value. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1422 | inline int value() const { return Internals::SmiValue(this); } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1423 | |
| 1424 | // Convert a value to a Smi object. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1425 | static inline Smi* FromInt(int value) { |
| 1426 | DCHECK(Smi::IsValid(value)); |
| 1427 | return reinterpret_cast<Smi*>(Internals::IntToSmi(value)); |
| 1428 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1429 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1430 | static inline Smi* FromIntptr(intptr_t value) { |
| 1431 | DCHECK(Smi::IsValid(value)); |
| 1432 | int smi_shift_bits = kSmiTagSize + kSmiShiftSize; |
| 1433 | return reinterpret_cast<Smi*>((value << smi_shift_bits) | kSmiTag); |
| 1434 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1435 | |
| 1436 | // Returns whether value can be represented in a Smi. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1437 | static inline bool IsValid(intptr_t value) { |
| 1438 | bool result = Internals::IsValidSmi(value); |
| 1439 | DCHECK_EQ(result, value >= kMinValue && value <= kMaxValue); |
| 1440 | return result; |
| 1441 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1442 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1443 | DECLARE_CAST(Smi) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1444 | |
| 1445 | // Dispatched behavior. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1446 | void SmiPrint(std::ostream& os) const; // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1447 | DECLARE_VERIFIER(Smi) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1448 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1449 | static const int kMinValue = |
| 1450 | (static_cast<unsigned int>(-1)) << (kSmiValueSize - 1); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1451 | static const int kMaxValue = -(kMinValue + 1); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1452 | |
| 1453 | private: |
| 1454 | DISALLOW_IMPLICIT_CONSTRUCTORS(Smi); |
| 1455 | }; |
| 1456 | |
| 1457 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1458 | // Heap objects typically have a map pointer in their first word. However, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1459 | // during GC other data (e.g. mark bits, forwarding addresses) is sometimes |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1460 | // encoded in the first word. The class MapWord is an abstraction of the |
| 1461 | // value in a heap object's first word. |
| 1462 | class MapWord BASE_EMBEDDED { |
| 1463 | public: |
| 1464 | // Normal state: the map word contains a map pointer. |
| 1465 | |
| 1466 | // Create a map word from a map pointer. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1467 | static inline MapWord FromMap(const Map* map); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1468 | |
| 1469 | // View this map word as a map pointer. |
| 1470 | inline Map* ToMap(); |
| 1471 | |
| 1472 | |
| 1473 | // Scavenge collection: the map word of live objects in the from space |
| 1474 | // contains a forwarding address (a heap object pointer in the to space). |
| 1475 | |
| 1476 | // True if this map word is a forwarding address for a scavenge |
| 1477 | // collection. Only valid during a scavenge collection (specifically, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1478 | // when all map words are heap object pointers, i.e. not during a full GC). |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1479 | inline bool IsForwardingAddress(); |
| 1480 | |
| 1481 | // Create a map word from a forwarding address. |
| 1482 | static inline MapWord FromForwardingAddress(HeapObject* object); |
| 1483 | |
| 1484 | // View this map word as a forwarding address. |
| 1485 | inline HeapObject* ToForwardingAddress(); |
| 1486 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1487 | static inline MapWord FromRawValue(uintptr_t value) { |
| 1488 | return MapWord(value); |
| 1489 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1490 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1491 | inline uintptr_t ToRawValue() { |
| 1492 | return value_; |
| 1493 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1494 | |
| 1495 | private: |
| 1496 | // HeapObject calls the private constructor and directly reads the value. |
| 1497 | friend class HeapObject; |
| 1498 | |
| 1499 | explicit MapWord(uintptr_t value) : value_(value) {} |
| 1500 | |
| 1501 | uintptr_t value_; |
| 1502 | }; |
| 1503 | |
| 1504 | |
| 1505 | // HeapObject is the superclass for all classes describing heap allocated |
| 1506 | // objects. |
| 1507 | class HeapObject: public Object { |
| 1508 | public: |
| 1509 | // [map]: Contains a map which contains the object's reflective |
| 1510 | // information. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1511 | inline Map* map() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1512 | inline void set_map(Map* value); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1513 | // The no-write-barrier version. This is OK if the object is white and in |
| 1514 | // new space, or if the value is an immortal immutable object, like the maps |
| 1515 | // of primitive (non-JS) objects like strings, heap numbers etc. |
| 1516 | inline void set_map_no_write_barrier(Map* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1517 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1518 | // Get the map using acquire load. |
| 1519 | inline Map* synchronized_map(); |
| 1520 | inline MapWord synchronized_map_word() const; |
| 1521 | |
| 1522 | // Set the map using release store |
| 1523 | inline void synchronized_set_map(Map* value); |
| 1524 | inline void synchronized_set_map_no_write_barrier(Map* value); |
| 1525 | inline void synchronized_set_map_word(MapWord map_word); |
| 1526 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1527 | // During garbage collection, the map word of a heap object does not |
| 1528 | // necessarily contain a map pointer. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1529 | inline MapWord map_word() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1530 | inline void set_map_word(MapWord map_word); |
| 1531 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1532 | // The Heap the object was allocated in. Used also to access Isolate. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1533 | inline Heap* GetHeap() const; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1534 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1535 | // Convenience method to get current isolate. |
| 1536 | inline Isolate* GetIsolate() const; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1537 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1538 | #define IS_TYPE_FUNCTION_DECL(type_) INLINE(bool Is##type_() const); |
| 1539 | HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL) |
| 1540 | ODDBALL_LIST(IS_TYPE_FUNCTION_DECL) |
| 1541 | #undef IS_TYPE_FUNCTION_DECL |
| 1542 | #define DECLARE_STRUCT_PREDICATE(NAME, Name, name) \ |
| 1543 | INLINE(bool Is##Name() const); |
| 1544 | STRUCT_LIST(DECLARE_STRUCT_PREDICATE) |
| 1545 | #undef DECLARE_STRUCT_PREDICATE |
| 1546 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1547 | // Converts an address to a HeapObject pointer. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1548 | static inline HeapObject* FromAddress(Address address) { |
| 1549 | DCHECK_TAG_ALIGNED(address); |
| 1550 | return reinterpret_cast<HeapObject*>(address + kHeapObjectTag); |
| 1551 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1552 | |
| 1553 | // Returns the address of this HeapObject. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1554 | inline Address address() { |
| 1555 | return reinterpret_cast<Address>(this) - kHeapObjectTag; |
| 1556 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1557 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1558 | // Iterates over pointers contained in the object (including the Map). |
| 1559 | // If it's not performance critical iteration use the non-templatized |
| 1560 | // version. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1561 | void Iterate(ObjectVisitor* v); |
| 1562 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1563 | template <typename ObjectVisitor> |
| 1564 | inline void IterateFast(ObjectVisitor* v); |
| 1565 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1566 | // Iterates over all pointers contained in the object except the |
| 1567 | // first map pointer. The object type is given in the first |
| 1568 | // parameter. This function does not access the map pointer in the |
| 1569 | // 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] | 1570 | // If it's not performance critical iteration use the non-templatized |
| 1571 | // version. |
| 1572 | void IterateBody(ObjectVisitor* v); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1573 | void IterateBody(InstanceType type, int object_size, ObjectVisitor* v); |
| 1574 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1575 | template <typename ObjectVisitor> |
| 1576 | inline void IterateBodyFast(ObjectVisitor* v); |
| 1577 | |
| 1578 | template <typename ObjectVisitor> |
| 1579 | inline void IterateBodyFast(InstanceType type, int object_size, |
| 1580 | ObjectVisitor* v); |
| 1581 | |
| 1582 | // Returns true if the object contains a tagged value at given offset. |
| 1583 | // It is used for invalid slots filtering. If the offset points outside |
| 1584 | // of the object or to the map word, the result is UNDEFINED (!!!). |
| 1585 | bool IsValidSlot(int offset); |
| 1586 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1587 | // Returns the heap object's size in bytes |
| 1588 | inline int Size(); |
| 1589 | |
| 1590 | // Given a heap object's map pointer, returns the heap size in bytes |
| 1591 | // Useful when the map pointer field is used for other purposes. |
| 1592 | // GC internal. |
| 1593 | inline int SizeFromMap(Map* map); |
| 1594 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1595 | // Returns the field at offset in obj, as a read/write Object* reference. |
| 1596 | // 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] | 1597 | // Does not invoke write barrier, so should only be assigned to |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1598 | // during marking GC. |
| 1599 | static inline Object** RawField(HeapObject* obj, int offset); |
| 1600 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1601 | // Adds the |code| object related to |name| to the code cache of this map. If |
| 1602 | // this map is a dictionary map that is shared, the map copied and installed |
| 1603 | // onto the object. |
| 1604 | static void UpdateMapCodeCache(Handle<HeapObject> object, |
| 1605 | Handle<Name> name, |
| 1606 | Handle<Code> code); |
| 1607 | |
| 1608 | DECLARE_CAST(HeapObject) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1609 | |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 1610 | // Return the write barrier mode for this. Callers of this function |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1611 | // must be able to present a reference to an DisallowHeapAllocation |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 1612 | // object as a sign that they are not going to use this function |
| 1613 | // from code that allocates and thus invalidates the returned write |
| 1614 | // barrier mode. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1615 | inline WriteBarrierMode GetWriteBarrierMode( |
| 1616 | const DisallowHeapAllocation& promise); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1617 | |
| 1618 | // Dispatched behavior. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1619 | void HeapObjectShortPrint(std::ostream& os); // NOLINT |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1620 | #ifdef OBJECT_PRINT |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1621 | void PrintHeader(std::ostream& os, const char* id); // NOLINT |
Ben Murdoch | 85b7179 | 2012-04-11 18:30:58 +0100 | [diff] [blame] | 1622 | #endif |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1623 | DECLARE_PRINTER(HeapObject) |
| 1624 | DECLARE_VERIFIER(HeapObject) |
| 1625 | #ifdef VERIFY_HEAP |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1626 | inline void VerifyObjectField(int offset); |
| 1627 | inline void VerifySmiField(int offset); |
| 1628 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1629 | // Verify a pointer is a valid HeapObject pointer that points to object |
| 1630 | // areas in the heap. |
| 1631 | static void VerifyHeapPointer(Object* p); |
| 1632 | #endif |
| 1633 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1634 | inline AllocationAlignment RequiredAlignment(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1635 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1636 | // Layout description. |
| 1637 | // First field in a heap object is map. |
| 1638 | static const int kMapOffset = Object::kHeaderSize; |
| 1639 | static const int kHeaderSize = kMapOffset + kPointerSize; |
| 1640 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1641 | STATIC_ASSERT(kMapOffset == Internals::kHeapObjectMapOffset); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1642 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1643 | private: |
| 1644 | DISALLOW_IMPLICIT_CONSTRUCTORS(HeapObject); |
| 1645 | }; |
| 1646 | |
| 1647 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1648 | template <int start_offset, int end_offset, int size> |
| 1649 | class FixedBodyDescriptor; |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1650 | |
| 1651 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1652 | template <int start_offset> |
| 1653 | class FlexibleBodyDescriptor; |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1654 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1655 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1656 | // The HeapNumber class describes heap allocated numbers that cannot be |
| 1657 | // represented in a Smi (small integer) |
| 1658 | class HeapNumber: public HeapObject { |
| 1659 | public: |
| 1660 | // [value]: number value. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1661 | inline double value() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1662 | inline void set_value(double value); |
| 1663 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1664 | DECLARE_CAST(HeapNumber) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1665 | |
| 1666 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1667 | bool HeapNumberBooleanValue(); |
| 1668 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1669 | void HeapNumberPrint(std::ostream& os); // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1670 | DECLARE_VERIFIER(HeapNumber) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1671 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1672 | inline int get_exponent(); |
| 1673 | inline int get_sign(); |
| 1674 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1675 | // Layout description. |
| 1676 | static const int kValueOffset = HeapObject::kHeaderSize; |
| 1677 | // 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] | 1678 | // is a mixture of sign, exponent and mantissa. The offsets of two 32 bit |
| 1679 | // words within double numbers are endian dependent and they are set |
| 1680 | // accordingly. |
| 1681 | #if defined(V8_TARGET_LITTLE_ENDIAN) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1682 | static const int kMantissaOffset = kValueOffset; |
| 1683 | static const int kExponentOffset = kValueOffset + 4; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1684 | #elif defined(V8_TARGET_BIG_ENDIAN) |
| 1685 | static const int kMantissaOffset = kValueOffset + 4; |
| 1686 | static const int kExponentOffset = kValueOffset; |
| 1687 | #else |
| 1688 | #error Unknown byte ordering |
| 1689 | #endif |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1690 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1691 | static const int kSize = kValueOffset + kDoubleSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1692 | static const uint32_t kSignMask = 0x80000000u; |
| 1693 | static const uint32_t kExponentMask = 0x7ff00000u; |
| 1694 | static const uint32_t kMantissaMask = 0xfffffu; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1695 | static const int kMantissaBits = 52; |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 1696 | static const int kExponentBits = 11; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1697 | static const int kExponentBias = 1023; |
| 1698 | static const int kExponentShift = 20; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1699 | static const int kInfinityOrNanExponent = |
| 1700 | (kExponentMask >> kExponentShift) - kExponentBias; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1701 | static const int kMantissaBitsInTopWord = 20; |
| 1702 | static const int kNonMantissaBitsInTopWord = 12; |
| 1703 | |
| 1704 | private: |
| 1705 | DISALLOW_IMPLICIT_CONSTRUCTORS(HeapNumber); |
| 1706 | }; |
| 1707 | |
| 1708 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1709 | // The Simd128Value class describes heap allocated 128 bit SIMD values. |
| 1710 | class Simd128Value : public HeapObject { |
| 1711 | public: |
| 1712 | DECLARE_CAST(Simd128Value) |
| 1713 | |
| 1714 | DECLARE_PRINTER(Simd128Value) |
| 1715 | DECLARE_VERIFIER(Simd128Value) |
| 1716 | |
| 1717 | static Handle<String> ToString(Handle<Simd128Value> input); |
| 1718 | |
| 1719 | // Equality operations. |
| 1720 | inline bool Equals(Simd128Value* that); |
| 1721 | static inline bool Equals(Handle<Simd128Value> one, Handle<Simd128Value> two); |
| 1722 | |
| 1723 | // Checks that another instance is bit-wise equal. |
| 1724 | bool BitwiseEquals(const Simd128Value* other) const; |
| 1725 | // Computes a hash from the 128 bit value, viewed as 4 32-bit integers. |
| 1726 | uint32_t Hash() const; |
| 1727 | // Copies the 16 bytes of SIMD data to the destination address. |
| 1728 | void CopyBits(void* destination) const; |
| 1729 | |
| 1730 | // Layout description. |
| 1731 | static const int kValueOffset = HeapObject::kHeaderSize; |
| 1732 | static const int kSize = kValueOffset + kSimd128Size; |
| 1733 | |
| 1734 | private: |
| 1735 | DISALLOW_IMPLICIT_CONSTRUCTORS(Simd128Value); |
| 1736 | }; |
| 1737 | |
| 1738 | |
| 1739 | // V has parameters (TYPE, Type, type, lane count, lane type) |
| 1740 | #define SIMD128_TYPES(V) \ |
| 1741 | V(FLOAT32X4, Float32x4, float32x4, 4, float) \ |
| 1742 | V(INT32X4, Int32x4, int32x4, 4, int32_t) \ |
| 1743 | V(UINT32X4, Uint32x4, uint32x4, 4, uint32_t) \ |
| 1744 | V(BOOL32X4, Bool32x4, bool32x4, 4, bool) \ |
| 1745 | V(INT16X8, Int16x8, int16x8, 8, int16_t) \ |
| 1746 | V(UINT16X8, Uint16x8, uint16x8, 8, uint16_t) \ |
| 1747 | V(BOOL16X8, Bool16x8, bool16x8, 8, bool) \ |
| 1748 | V(INT8X16, Int8x16, int8x16, 16, int8_t) \ |
| 1749 | V(UINT8X16, Uint8x16, uint8x16, 16, uint8_t) \ |
| 1750 | V(BOOL8X16, Bool8x16, bool8x16, 16, bool) |
| 1751 | |
| 1752 | #define SIMD128_VALUE_CLASS(TYPE, Type, type, lane_count, lane_type) \ |
| 1753 | class Type final : public Simd128Value { \ |
| 1754 | public: \ |
| 1755 | inline lane_type get_lane(int lane) const; \ |
| 1756 | inline void set_lane(int lane, lane_type value); \ |
| 1757 | \ |
| 1758 | DECLARE_CAST(Type) \ |
| 1759 | \ |
| 1760 | DECLARE_PRINTER(Type) \ |
| 1761 | \ |
| 1762 | static Handle<String> ToString(Handle<Type> input); \ |
| 1763 | \ |
| 1764 | inline bool Equals(Type* that); \ |
| 1765 | \ |
| 1766 | private: \ |
| 1767 | DISALLOW_IMPLICIT_CONSTRUCTORS(Type); \ |
| 1768 | }; |
| 1769 | SIMD128_TYPES(SIMD128_VALUE_CLASS) |
| 1770 | #undef SIMD128_VALUE_CLASS |
| 1771 | |
| 1772 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1773 | enum EnsureElementsMode { |
| 1774 | DONT_ALLOW_DOUBLE_ELEMENTS, |
| 1775 | ALLOW_COPIED_DOUBLE_ELEMENTS, |
| 1776 | ALLOW_CONVERTED_DOUBLE_ELEMENTS |
| 1777 | }; |
| 1778 | |
| 1779 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1780 | // Indicator for one component of an AccessorPair. |
| 1781 | enum AccessorComponent { |
| 1782 | ACCESSOR_GETTER, |
| 1783 | ACCESSOR_SETTER |
| 1784 | }; |
| 1785 | |
| 1786 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1787 | enum GetKeysConversion { KEEP_NUMBERS, CONVERT_TO_STRING }; |
| 1788 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1789 | enum KeyCollectionType { OWN_ONLY, INCLUDE_PROTOS }; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1790 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1791 | // JSReceiver includes types on which properties can be defined, i.e., |
| 1792 | // JSObject and JSProxy. |
| 1793 | class JSReceiver: public HeapObject { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1794 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1795 | // [properties]: Backing storage for properties. |
| 1796 | // properties is a FixedArray in the fast case and a Dictionary in the |
| 1797 | // slow case. |
| 1798 | DECL_ACCESSORS(properties, FixedArray) // Get and set fast properties. |
| 1799 | inline void initialize_properties(); |
| 1800 | inline bool HasFastProperties(); |
| 1801 | // Gets slow properties for non-global objects. |
| 1802 | inline NameDictionary* property_dictionary(); |
| 1803 | |
| 1804 | // Deletes an existing named property in a normalized object. |
| 1805 | static void DeleteNormalizedProperty(Handle<JSReceiver> object, |
| 1806 | Handle<Name> name, int entry); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1807 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1808 | DECLARE_CAST(JSReceiver) |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1809 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1810 | // ES6 section 7.1.1 ToPrimitive |
| 1811 | MUST_USE_RESULT static MaybeHandle<Object> ToPrimitive( |
| 1812 | Handle<JSReceiver> receiver, |
| 1813 | ToPrimitiveHint hint = ToPrimitiveHint::kDefault); |
| 1814 | MUST_USE_RESULT static MaybeHandle<Object> OrdinaryToPrimitive( |
| 1815 | Handle<JSReceiver> receiver, OrdinaryToPrimitiveHint hint); |
| 1816 | |
| 1817 | static MaybeHandle<Context> GetFunctionRealm(Handle<JSReceiver> receiver); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1818 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1819 | // Get the first non-hidden prototype. |
| 1820 | static inline MaybeHandle<Object> GetPrototype(Isolate* isolate, |
| 1821 | Handle<JSReceiver> receiver); |
| 1822 | |
| 1823 | MUST_USE_RESULT static Maybe<bool> HasInPrototypeChain( |
| 1824 | Isolate* isolate, Handle<JSReceiver> object, Handle<Object> proto); |
| 1825 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1826 | // Implementation of [[HasProperty]], ECMA-262 5th edition, section 8.12.6. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1827 | MUST_USE_RESULT static Maybe<bool> HasProperty(LookupIterator* it); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1828 | MUST_USE_RESULT static inline Maybe<bool> HasProperty( |
| 1829 | Handle<JSReceiver> object, Handle<Name> name); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1830 | MUST_USE_RESULT static inline Maybe<bool> HasElement( |
| 1831 | Handle<JSReceiver> object, uint32_t index); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1832 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1833 | MUST_USE_RESULT static inline Maybe<bool> HasOwnProperty( |
| 1834 | Handle<JSReceiver> object, Handle<Name> name); |
| 1835 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1836 | MUST_USE_RESULT static inline MaybeHandle<Object> GetProperty( |
| 1837 | Isolate* isolate, Handle<JSReceiver> receiver, const char* key); |
| 1838 | MUST_USE_RESULT static inline MaybeHandle<Object> GetProperty( |
| 1839 | Handle<JSReceiver> receiver, Handle<Name> name); |
| 1840 | MUST_USE_RESULT static inline MaybeHandle<Object> GetElement( |
| 1841 | Isolate* isolate, Handle<JSReceiver> receiver, uint32_t index); |
| 1842 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1843 | // Implementation of ES6 [[Delete]] |
| 1844 | MUST_USE_RESULT static Maybe<bool> DeletePropertyOrElement( |
| 1845 | Handle<JSReceiver> object, Handle<Name> name, |
| 1846 | LanguageMode language_mode = SLOPPY); |
| 1847 | MUST_USE_RESULT static Maybe<bool> DeleteProperty( |
| 1848 | Handle<JSReceiver> object, Handle<Name> name, |
| 1849 | LanguageMode language_mode = SLOPPY); |
| 1850 | MUST_USE_RESULT static Maybe<bool> DeleteProperty(LookupIterator* it, |
| 1851 | LanguageMode language_mode); |
| 1852 | MUST_USE_RESULT static Maybe<bool> DeleteElement( |
| 1853 | Handle<JSReceiver> object, uint32_t index, |
| 1854 | LanguageMode language_mode = SLOPPY); |
| 1855 | |
| 1856 | MUST_USE_RESULT static Object* DefineProperty(Isolate* isolate, |
| 1857 | Handle<Object> object, |
| 1858 | Handle<Object> name, |
| 1859 | Handle<Object> attributes); |
| 1860 | MUST_USE_RESULT static MaybeHandle<Object> DefineProperties( |
| 1861 | Isolate* isolate, Handle<Object> object, Handle<Object> properties); |
| 1862 | |
| 1863 | // "virtual" dispatcher to the correct [[DefineOwnProperty]] implementation. |
| 1864 | MUST_USE_RESULT static Maybe<bool> DefineOwnProperty( |
| 1865 | Isolate* isolate, Handle<JSReceiver> object, Handle<Object> key, |
| 1866 | PropertyDescriptor* desc, ShouldThrow should_throw); |
| 1867 | |
| 1868 | // ES6 7.3.4 (when passed DONT_THROW) |
| 1869 | MUST_USE_RESULT static Maybe<bool> CreateDataProperty( |
| 1870 | LookupIterator* it, Handle<Object> value, ShouldThrow should_throw); |
| 1871 | |
| 1872 | // ES6 9.1.6.1 |
| 1873 | MUST_USE_RESULT static Maybe<bool> OrdinaryDefineOwnProperty( |
| 1874 | Isolate* isolate, Handle<JSObject> object, Handle<Object> key, |
| 1875 | PropertyDescriptor* desc, ShouldThrow should_throw); |
| 1876 | MUST_USE_RESULT static Maybe<bool> OrdinaryDefineOwnProperty( |
| 1877 | LookupIterator* it, PropertyDescriptor* desc, ShouldThrow should_throw); |
| 1878 | // ES6 9.1.6.2 |
| 1879 | MUST_USE_RESULT static Maybe<bool> IsCompatiblePropertyDescriptor( |
| 1880 | Isolate* isolate, bool extensible, PropertyDescriptor* desc, |
| 1881 | PropertyDescriptor* current, Handle<Name> property_name, |
| 1882 | ShouldThrow should_throw); |
| 1883 | // ES6 9.1.6.3 |
| 1884 | // |it| can be NULL in cases where the ES spec passes |undefined| as the |
| 1885 | // receiver. Exactly one of |it| and |property_name| must be provided. |
| 1886 | MUST_USE_RESULT static Maybe<bool> ValidateAndApplyPropertyDescriptor( |
| 1887 | Isolate* isolate, LookupIterator* it, bool extensible, |
| 1888 | PropertyDescriptor* desc, PropertyDescriptor* current, |
| 1889 | ShouldThrow should_throw, Handle<Name> property_name = Handle<Name>()); |
| 1890 | |
| 1891 | MUST_USE_RESULT static Maybe<bool> GetOwnPropertyDescriptor( |
| 1892 | Isolate* isolate, Handle<JSReceiver> object, Handle<Object> key, |
| 1893 | PropertyDescriptor* desc); |
| 1894 | MUST_USE_RESULT static Maybe<bool> GetOwnPropertyDescriptor( |
| 1895 | LookupIterator* it, PropertyDescriptor* desc); |
| 1896 | |
| 1897 | typedef PropertyAttributes IntegrityLevel; |
| 1898 | |
| 1899 | // ES6 7.3.14 (when passed DONT_THROW) |
| 1900 | // 'level' must be SEALED or FROZEN. |
| 1901 | MUST_USE_RESULT static Maybe<bool> SetIntegrityLevel( |
| 1902 | Handle<JSReceiver> object, IntegrityLevel lvl, ShouldThrow should_throw); |
| 1903 | |
| 1904 | // ES6 7.3.15 |
| 1905 | // 'level' must be SEALED or FROZEN. |
| 1906 | MUST_USE_RESULT static Maybe<bool> TestIntegrityLevel( |
| 1907 | Handle<JSReceiver> object, IntegrityLevel lvl); |
| 1908 | |
| 1909 | // ES6 [[PreventExtensions]] (when passed DONT_THROW) |
| 1910 | MUST_USE_RESULT static Maybe<bool> PreventExtensions( |
| 1911 | Handle<JSReceiver> object, ShouldThrow should_throw); |
| 1912 | |
| 1913 | MUST_USE_RESULT static Maybe<bool> IsExtensible(Handle<JSReceiver> object); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1914 | |
| 1915 | // Tests for the fast common case for property enumeration. |
| 1916 | bool IsSimpleEnum(); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1917 | |
| 1918 | // Returns the class name ([[Class]] property in the specification). |
| 1919 | String* class_name(); |
| 1920 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1921 | // Returns the builtin string tag used in Object.prototype.toString. |
| 1922 | MUST_USE_RESULT static MaybeHandle<String> BuiltinStringTag( |
| 1923 | Handle<JSReceiver> object); |
| 1924 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1925 | // Returns the constructor name (the name (possibly, inferred name) of the |
| 1926 | // function that was used to instantiate the object). |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1927 | static Handle<String> GetConstructorName(Handle<JSReceiver> receiver); |
| 1928 | |
| 1929 | Context* GetCreationContext(); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1930 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1931 | MUST_USE_RESULT static inline Maybe<PropertyAttributes> GetPropertyAttributes( |
| 1932 | Handle<JSReceiver> object, Handle<Name> name); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1933 | MUST_USE_RESULT static inline Maybe<PropertyAttributes> |
| 1934 | GetOwnPropertyAttributes(Handle<JSReceiver> object, Handle<Name> name); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1935 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1936 | MUST_USE_RESULT static inline Maybe<PropertyAttributes> GetElementAttributes( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1937 | Handle<JSReceiver> object, uint32_t index); |
| 1938 | MUST_USE_RESULT static inline Maybe<PropertyAttributes> |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1939 | GetOwnElementAttributes(Handle<JSReceiver> object, uint32_t index); |
| 1940 | |
| 1941 | MUST_USE_RESULT static Maybe<PropertyAttributes> GetPropertyAttributes( |
| 1942 | LookupIterator* it); |
| 1943 | |
| 1944 | // Set the object's prototype (only JSReceiver and null are allowed values). |
| 1945 | MUST_USE_RESULT static Maybe<bool> SetPrototype(Handle<JSReceiver> object, |
| 1946 | Handle<Object> value, |
| 1947 | bool from_javascript, |
| 1948 | ShouldThrow should_throw); |
| 1949 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1950 | inline static Handle<Object> GetDataProperty(Handle<JSReceiver> object, |
| 1951 | Handle<Name> name); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1952 | static Handle<Object> GetDataProperty(LookupIterator* it); |
| 1953 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1954 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1955 | // Retrieves a permanent object identity hash code. The undefined value might |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1956 | // be returned in case no hash was created yet. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1957 | static inline Handle<Object> GetIdentityHash(Isolate* isolate, |
| 1958 | Handle<JSReceiver> object); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1959 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1960 | // Retrieves a permanent object identity hash code. May create and store a |
| 1961 | // hash code if needed and none exists. |
| 1962 | inline static Handle<Smi> GetOrCreateIdentityHash( |
| 1963 | Handle<JSReceiver> object); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1964 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1965 | // ES6 [[OwnPropertyKeys]] (modulo return type) |
| 1966 | MUST_USE_RESULT static MaybeHandle<FixedArray> OwnPropertyKeys( |
| 1967 | Handle<JSReceiver> object) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1968 | return GetKeys(object, OWN_ONLY, ALL_PROPERTIES, CONVERT_TO_STRING); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1969 | } |
| 1970 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1971 | // Computes the enumerable keys for a JSObject. Used for implementing |
| 1972 | // "for (n in object) { }". |
| 1973 | MUST_USE_RESULT static MaybeHandle<FixedArray> GetKeys( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1974 | Handle<JSReceiver> object, KeyCollectionType type, PropertyFilter filter, |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1975 | GetKeysConversion keys_conversion = KEEP_NUMBERS, |
| 1976 | bool filter_proxy_keys_ = true); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1977 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1978 | MUST_USE_RESULT static MaybeHandle<FixedArray> GetOwnValues( |
| 1979 | Handle<JSReceiver> object, PropertyFilter filter); |
| 1980 | |
| 1981 | MUST_USE_RESULT static MaybeHandle<FixedArray> GetOwnEntries( |
| 1982 | Handle<JSReceiver> object, PropertyFilter filter); |
| 1983 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1984 | // Layout description. |
| 1985 | static const int kPropertiesOffset = HeapObject::kHeaderSize; |
| 1986 | static const int kHeaderSize = HeapObject::kHeaderSize + kPointerSize; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1987 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1988 | private: |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1989 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSReceiver); |
| 1990 | }; |
| 1991 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1992 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1993 | // The JSObject describes real heap allocated JavaScript objects with |
| 1994 | // properties. |
| 1995 | // Note that the map of JSObject changes during execution to enable inline |
| 1996 | // caching. |
| 1997 | class JSObject: public JSReceiver { |
| 1998 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1999 | static MUST_USE_RESULT MaybeHandle<JSObject> New( |
| 2000 | Handle<JSFunction> constructor, Handle<JSReceiver> new_target, |
| 2001 | Handle<AllocationSite> site = Handle<AllocationSite>::null()); |
| 2002 | |
| 2003 | // Gets global object properties. |
| 2004 | inline GlobalDictionary* global_dictionary(); |
| 2005 | |
| 2006 | static MaybeHandle<Context> GetFunctionRealm(Handle<JSObject> object); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2007 | |
| 2008 | // [elements]: The elements (properties with names that are integers). |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2009 | // |
| 2010 | // Elements can be in two general modes: fast and slow. Each mode |
| 2011 | // corrensponds to a set of object representations of elements that |
| 2012 | // have something in common. |
| 2013 | // |
| 2014 | // In the fast mode elements is a FixedArray and so each element can |
| 2015 | // be quickly accessed. This fact is used in the generated code. The |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2016 | // elements array can have one of three maps in this mode: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2017 | // fixed_array_map, sloppy_arguments_elements_map or |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2018 | // fixed_cow_array_map (for copy-on-write arrays). In the latter case |
| 2019 | // the elements array may be shared by a few objects and so before |
| 2020 | // writing to any element the array must be copied. Use |
| 2021 | // EnsureWritableFastElements in this case. |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2022 | // |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2023 | // In the slow mode the elements is either a NumberDictionary, a |
| 2024 | // FixedArray parameter map for a (sloppy) arguments object. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2025 | DECL_ACCESSORS(elements, FixedArrayBase) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2026 | inline void initialize_elements(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2027 | static void ResetElements(Handle<JSObject> object); |
| 2028 | static inline void SetMapAndElements(Handle<JSObject> object, |
| 2029 | Handle<Map> map, |
| 2030 | Handle<FixedArrayBase> elements); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2031 | inline ElementsKind GetElementsKind(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2032 | ElementsAccessor* GetElementsAccessor(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2033 | // Returns true if an object has elements of FAST_SMI_ELEMENTS ElementsKind. |
| 2034 | inline bool HasFastSmiElements(); |
| 2035 | // Returns true if an object has elements of FAST_ELEMENTS ElementsKind. |
| 2036 | inline bool HasFastObjectElements(); |
| 2037 | // Returns true if an object has elements of FAST_ELEMENTS or |
| 2038 | // FAST_SMI_ONLY_ELEMENTS. |
| 2039 | inline bool HasFastSmiOrObjectElements(); |
| 2040 | // Returns true if an object has any of the fast elements kinds. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2041 | inline bool HasFastElements(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2042 | // Returns true if an object has elements of FAST_DOUBLE_ELEMENTS |
| 2043 | // ElementsKind. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2044 | inline bool HasFastDoubleElements(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2045 | // Returns true if an object has elements of FAST_HOLEY_*_ELEMENTS |
| 2046 | // ElementsKind. |
| 2047 | inline bool HasFastHoleyElements(); |
| 2048 | inline bool HasSloppyArgumentsElements(); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2049 | inline bool HasStringWrapperElements(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2050 | inline bool HasDictionaryElements(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2051 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2052 | inline bool HasFixedTypedArrayElements(); |
| 2053 | |
| 2054 | inline bool HasFixedUint8ClampedElements(); |
| 2055 | inline bool HasFixedArrayElements(); |
| 2056 | inline bool HasFixedInt8Elements(); |
| 2057 | inline bool HasFixedUint8Elements(); |
| 2058 | inline bool HasFixedInt16Elements(); |
| 2059 | inline bool HasFixedUint16Elements(); |
| 2060 | inline bool HasFixedInt32Elements(); |
| 2061 | inline bool HasFixedUint32Elements(); |
| 2062 | inline bool HasFixedFloat32Elements(); |
| 2063 | inline bool HasFixedFloat64Elements(); |
| 2064 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2065 | inline bool HasFastArgumentsElements(); |
| 2066 | inline bool HasSlowArgumentsElements(); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2067 | inline bool HasFastStringWrapperElements(); |
| 2068 | inline bool HasSlowStringWrapperElements(); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 2069 | bool HasEnumerableElements(); |
| 2070 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 2071 | inline SeededNumberDictionary* element_dictionary(); // Gets slow elements. |
| 2072 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2073 | // Requires: HasFastElements(). |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 2074 | static void EnsureWritableFastElements(Handle<JSObject> object); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2075 | |
| 2076 | // Collects elements starting at index 0. |
| 2077 | // Undefined values are placed after non-undefined values. |
| 2078 | // Returns the number of non-undefined values. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2079 | static Handle<Object> PrepareElementsForSort(Handle<JSObject> object, |
| 2080 | uint32_t limit); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2081 | // As PrepareElementsForSort, but only on objects where elements is |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2082 | // a dictionary, and it will stay a dictionary. Collates undefined and |
| 2083 | // unexisting elements below limit from position zero of the elements. |
| 2084 | static Handle<Object> PrepareSlowElementsForSort(Handle<JSObject> object, |
| 2085 | uint32_t limit); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2086 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2087 | MUST_USE_RESULT static Maybe<bool> SetPropertyWithInterceptor( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2088 | LookupIterator* it, ShouldThrow should_throw, Handle<Object> value); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2089 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2090 | // The API currently still wants DefineOwnPropertyIgnoreAttributes to convert |
| 2091 | // AccessorInfo objects to data fields. We allow FORCE_FIELD as an exception |
| 2092 | // to the default behavior that calls the setter. |
| 2093 | enum AccessorInfoHandling { FORCE_FIELD, DONT_FORCE_FIELD }; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2094 | |
| 2095 | MUST_USE_RESULT static MaybeHandle<Object> DefineOwnPropertyIgnoreAttributes( |
| 2096 | LookupIterator* it, Handle<Object> value, PropertyAttributes attributes, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2097 | AccessorInfoHandling handling = DONT_FORCE_FIELD); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2098 | |
| 2099 | MUST_USE_RESULT static Maybe<bool> DefineOwnPropertyIgnoreAttributes( |
| 2100 | LookupIterator* it, Handle<Object> value, PropertyAttributes attributes, |
| 2101 | ShouldThrow should_throw, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2102 | AccessorInfoHandling handling = DONT_FORCE_FIELD); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2103 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2104 | MUST_USE_RESULT static MaybeHandle<Object> SetOwnPropertyIgnoreAttributes( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2105 | Handle<JSObject> object, Handle<Name> name, Handle<Object> value, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2106 | PropertyAttributes attributes); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2107 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2108 | MUST_USE_RESULT static MaybeHandle<Object> SetOwnElementIgnoreAttributes( |
| 2109 | Handle<JSObject> object, uint32_t index, Handle<Object> value, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2110 | PropertyAttributes attributes); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2111 | |
| 2112 | // Equivalent to one of the above depending on whether |name| can be converted |
| 2113 | // to an array index. |
| 2114 | MUST_USE_RESULT static MaybeHandle<Object> |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2115 | DefinePropertyOrElementIgnoreAttributes(Handle<JSObject> object, |
| 2116 | Handle<Name> name, |
| 2117 | Handle<Object> value, |
| 2118 | PropertyAttributes attributes = NONE); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2119 | |
| 2120 | // Adds or reconfigures a property to attributes NONE. It will fail when it |
| 2121 | // cannot. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 2122 | MUST_USE_RESULT static Maybe<bool> CreateDataProperty( |
| 2123 | LookupIterator* it, Handle<Object> value, |
| 2124 | ShouldThrow should_throw = DONT_THROW); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2125 | |
| 2126 | static void AddProperty(Handle<JSObject> object, Handle<Name> name, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2127 | Handle<Object> value, PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2128 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2129 | MUST_USE_RESULT static Maybe<bool> AddDataElement( |
| 2130 | Handle<JSObject> receiver, uint32_t index, Handle<Object> value, |
| 2131 | PropertyAttributes attributes, ShouldThrow should_throw); |
| 2132 | MUST_USE_RESULT static MaybeHandle<Object> AddDataElement( |
| 2133 | Handle<JSObject> receiver, uint32_t index, Handle<Object> value, |
| 2134 | PropertyAttributes attributes); |
| 2135 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2136 | // Extend the receiver with a single fast property appeared first in the |
| 2137 | // passed map. This also extends the property backing store if necessary. |
| 2138 | static void AllocateStorageForMap(Handle<JSObject> object, Handle<Map> map); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2139 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2140 | // Migrates the given object to a map whose field representations are the |
| 2141 | // lowest upper bound of all known representations for that field. |
| 2142 | static void MigrateInstance(Handle<JSObject> instance); |
| 2143 | |
| 2144 | // Migrates the given object only if the target map is already available, |
| 2145 | // or returns false if such a map is not yet available. |
| 2146 | static bool TryMigrateInstance(Handle<JSObject> instance); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2147 | |
| 2148 | // Sets the property value in a normalized object given (key, value, details). |
| 2149 | // Handles the special representation of JS global objects. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2150 | static void SetNormalizedProperty(Handle<JSObject> object, Handle<Name> name, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2151 | Handle<Object> value, |
| 2152 | PropertyDetails details); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2153 | static void SetDictionaryElement(Handle<JSObject> object, uint32_t index, |
| 2154 | Handle<Object> value, |
| 2155 | PropertyAttributes attributes); |
| 2156 | static void SetDictionaryArgumentsElement(Handle<JSObject> object, |
| 2157 | uint32_t index, |
| 2158 | Handle<Object> value, |
| 2159 | PropertyAttributes attributes); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2160 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2161 | static void OptimizeAsPrototype(Handle<JSObject> object, |
| 2162 | PrototypeOptimizationMode mode); |
| 2163 | static void ReoptimizeIfPrototype(Handle<JSObject> object); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2164 | static void LazyRegisterPrototypeUser(Handle<Map> user, Isolate* isolate); |
| 2165 | static void UpdatePrototypeUserRegistration(Handle<Map> old_map, |
| 2166 | Handle<Map> new_map, |
| 2167 | Isolate* isolate); |
| 2168 | static bool UnregisterPrototypeUser(Handle<Map> user, Isolate* isolate); |
| 2169 | static void InvalidatePrototypeChains(Map* map); |
| 2170 | |
| 2171 | // Alternative implementation of WeakFixedArray::NullCallback. |
| 2172 | class PrototypeRegistryCompactionCallback { |
| 2173 | public: |
| 2174 | static void Callback(Object* value, int old_index, int new_index); |
| 2175 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2176 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2177 | // Retrieve interceptors. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 2178 | inline InterceptorInfo* GetNamedInterceptor(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2179 | inline InterceptorInfo* GetIndexedInterceptor(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2180 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2181 | // Used from JSReceiver. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2182 | MUST_USE_RESULT static Maybe<PropertyAttributes> |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2183 | GetPropertyAttributesWithInterceptor(LookupIterator* it); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2184 | MUST_USE_RESULT static Maybe<PropertyAttributes> |
| 2185 | GetPropertyAttributesWithFailedAccessCheck(LookupIterator* it); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2186 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2187 | // Retrieves an AccessorPair property from the given object. Might return |
| 2188 | // undefined if the property doesn't exist or is of a different kind. |
| 2189 | MUST_USE_RESULT static MaybeHandle<Object> GetAccessor( |
| 2190 | Handle<JSObject> object, |
| 2191 | Handle<Name> name, |
| 2192 | AccessorComponent component); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2193 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2194 | // Defines an AccessorPair property on the given object. |
| 2195 | // TODO(mstarzinger): Rename to SetAccessor(). |
| 2196 | static MaybeHandle<Object> DefineAccessor(Handle<JSObject> object, |
| 2197 | Handle<Name> name, |
| 2198 | Handle<Object> getter, |
| 2199 | Handle<Object> setter, |
| 2200 | PropertyAttributes attributes); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2201 | static MaybeHandle<Object> DefineAccessor(LookupIterator* it, |
| 2202 | Handle<Object> getter, |
| 2203 | Handle<Object> setter, |
| 2204 | PropertyAttributes attributes); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2205 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2206 | // Defines an AccessorInfo property on the given object. |
| 2207 | MUST_USE_RESULT static MaybeHandle<Object> SetAccessor( |
| 2208 | Handle<JSObject> object, |
| 2209 | Handle<AccessorInfo> info); |
| 2210 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2211 | // The result must be checked first for exceptions. If there's no exception, |
| 2212 | // the output parameter |done| indicates whether the interceptor has a result |
| 2213 | // or not. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2214 | MUST_USE_RESULT static MaybeHandle<Object> GetPropertyWithInterceptor( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2215 | LookupIterator* it, bool* done); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2216 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2217 | // Accessors for hidden properties object. |
| 2218 | // |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2219 | // Hidden properties are not own properties of the object itself. Instead |
| 2220 | // they are stored in an auxiliary structure kept as an own property with a |
| 2221 | // special name Heap::hidden_properties_symbol(). But if the receiver is a |
| 2222 | // JSGlobalProxy then the auxiliary object is a property of its prototype, and |
| 2223 | // if it's a detached proxy, then you can't have hidden properties. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2224 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2225 | // Sets a hidden property on this object. Returns this object if successful, |
| 2226 | // undefined if called on a detached proxy. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2227 | static Handle<Object> SetHiddenProperty(Handle<JSObject> object, |
| 2228 | Handle<Name> key, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2229 | Handle<Object> value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2230 | // Gets the value of a hidden property with the given key. Returns the hole |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2231 | // if the property doesn't exist (or if called on a detached proxy), |
| 2232 | // otherwise returns the value set for the key. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2233 | Object* GetHiddenProperty(Handle<Name> key); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2234 | // Deletes a hidden property. Deleting a non-existing property is |
| 2235 | // considered successful. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2236 | static void DeleteHiddenProperty(Handle<JSObject> object, |
| 2237 | Handle<Name> key); |
| 2238 | // Returns true if the object has a property with the hidden string as name. |
| 2239 | static bool HasHiddenProperties(Handle<JSObject> object); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2240 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2241 | static void ValidateElements(Handle<JSObject> object); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2242 | |
| 2243 | // Makes sure that this object can contain HeapObject as elements. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2244 | static inline void EnsureCanContainHeapObjectElements(Handle<JSObject> obj); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2245 | |
| 2246 | // Makes sure that this object can contain the specified elements. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2247 | static inline void EnsureCanContainElements( |
| 2248 | Handle<JSObject> object, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2249 | Object** elements, |
| 2250 | uint32_t count, |
| 2251 | EnsureElementsMode mode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2252 | static inline void EnsureCanContainElements( |
| 2253 | Handle<JSObject> object, |
| 2254 | Handle<FixedArrayBase> elements, |
| 2255 | uint32_t length, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2256 | EnsureElementsMode mode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2257 | static void EnsureCanContainElements( |
| 2258 | Handle<JSObject> object, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2259 | Arguments* arguments, |
| 2260 | uint32_t first_arg, |
| 2261 | uint32_t arg_count, |
| 2262 | EnsureElementsMode mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2263 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2264 | // Would we convert a fast elements array to dictionary mode given |
| 2265 | // an access at key? |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2266 | bool WouldConvertToSlowElements(uint32_t index); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 2267 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2268 | // Computes the new capacity when expanding the elements of a JSObject. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2269 | static uint32_t NewElementsCapacity(uint32_t old_capacity) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2270 | // (old_capacity + 50%) + 16 |
| 2271 | return old_capacity + (old_capacity >> 1) + 16; |
| 2272 | } |
| 2273 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2274 | // These methods do not perform access checks! |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2275 | static void UpdateAllocationSite(Handle<JSObject> object, |
| 2276 | ElementsKind to_kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2277 | |
| 2278 | // Lookup interceptors are used for handling properties controlled by host |
| 2279 | // objects. |
| 2280 | inline bool HasNamedInterceptor(); |
| 2281 | inline bool HasIndexedInterceptor(); |
| 2282 | |
| 2283 | // Support functions for v8 api (needed for correct interceptor behavior). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2284 | MUST_USE_RESULT static Maybe<bool> HasRealNamedProperty( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2285 | Handle<JSObject> object, Handle<Name> name); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2286 | MUST_USE_RESULT static Maybe<bool> HasRealElementProperty( |
| 2287 | Handle<JSObject> object, uint32_t index); |
| 2288 | MUST_USE_RESULT static Maybe<bool> HasRealNamedCallbackProperty( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2289 | Handle<JSObject> object, Handle<Name> name); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2290 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2291 | // Get the header size for a JSObject. Used to compute the index of |
| 2292 | // internal fields as well as the number of internal fields. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2293 | static inline int GetHeaderSize(InstanceType instance_type); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2294 | inline int GetHeaderSize(); |
| 2295 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2296 | static inline int GetInternalFieldCount(Map* map); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2297 | inline int GetInternalFieldCount(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2298 | inline int GetInternalFieldOffset(int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2299 | inline Object* GetInternalField(int index); |
| 2300 | inline void SetInternalField(int index, Object* value); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2301 | inline void SetInternalField(int index, Smi* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2302 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2303 | void CollectOwnPropertyNames(KeyAccumulator* keys, |
| 2304 | PropertyFilter filter = ALL_PROPERTIES); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2305 | |
| 2306 | // Returns the number of properties on this object filtering out properties |
| 2307 | // with the specified attributes (ignoring interceptors). |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2308 | // TODO(jkummerow): Deprecated, only used by Object.observe. |
| 2309 | int NumberOfOwnElements(PropertyFilter filter); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2310 | // Returns the number of elements on this object filtering out elements |
| 2311 | // with the specified attributes (ignoring interceptors). |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2312 | // TODO(jkummerow): Deprecated, only used by Object.observe. |
| 2313 | int GetOwnElementKeys(FixedArray* storage, PropertyFilter filter); |
| 2314 | |
| 2315 | static void CollectOwnElementKeys(Handle<JSObject> object, |
| 2316 | KeyAccumulator* keys, |
| 2317 | PropertyFilter filter); |
| 2318 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2319 | static Handle<FixedArray> GetEnumPropertyKeys(Handle<JSObject> object); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2320 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 2321 | static Handle<FixedArray> GetFastEnumPropertyKeys(Isolate* isolate, |
| 2322 | Handle<JSObject> object); |
| 2323 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2324 | // Returns a new map with all transitions dropped from the object's current |
| 2325 | // map and the ElementsKind set. |
| 2326 | static Handle<Map> GetElementsTransitionMap(Handle<JSObject> object, |
| 2327 | ElementsKind to_kind); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2328 | static void TransitionElementsKind(Handle<JSObject> object, |
| 2329 | ElementsKind to_kind); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2330 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2331 | // Always use this to migrate an object to a new map. |
| 2332 | // |expected_additional_properties| is only used for fast-to-slow transitions |
| 2333 | // and ignored otherwise. |
| 2334 | static void MigrateToMap(Handle<JSObject> object, Handle<Map> new_map, |
| 2335 | int expected_additional_properties = 0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2336 | |
| 2337 | // Convert the object to use the canonical dictionary |
| 2338 | // representation. If the object is expected to have additional properties |
| 2339 | // added this number can be indicated to have the backing store allocated to |
| 2340 | // an initial capacity for holding these properties. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2341 | static void NormalizeProperties(Handle<JSObject> object, |
| 2342 | PropertyNormalizationMode mode, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2343 | int expected_additional_properties, |
| 2344 | const char* reason); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2345 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2346 | // Convert and update the elements backing store to be a |
| 2347 | // SeededNumberDictionary dictionary. Returns the backing after conversion. |
| 2348 | static Handle<SeededNumberDictionary> NormalizeElements( |
| 2349 | Handle<JSObject> object); |
| 2350 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2351 | void RequireSlowElements(SeededNumberDictionary* dictionary); |
| 2352 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2353 | // Transform slow named properties to fast variants. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2354 | static void MigrateSlowToFast(Handle<JSObject> object, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2355 | int unused_property_fields, const char* reason); |
| 2356 | |
| 2357 | inline bool IsUnboxedDoubleField(FieldIndex index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2358 | |
| 2359 | // Access fast-case object properties at index. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2360 | static Handle<Object> FastPropertyAt(Handle<JSObject> object, |
| 2361 | Representation representation, |
| 2362 | FieldIndex index); |
| 2363 | inline Object* RawFastPropertyAt(FieldIndex index); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2364 | inline double RawFastDoublePropertyAt(FieldIndex index); |
| 2365 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2366 | inline void FastPropertyAtPut(FieldIndex index, Object* value); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2367 | inline void RawFastPropertyAtPut(FieldIndex index, Object* value); |
| 2368 | inline void RawFastDoublePropertyAtPut(FieldIndex index, double value); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2369 | inline void WriteToField(int descriptor, PropertyDetails details, |
| 2370 | Object* value); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2371 | inline void WriteToField(int descriptor, Object* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2372 | |
| 2373 | // Access to in object properties. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2374 | inline int GetInObjectPropertyOffset(int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2375 | inline Object* InObjectPropertyAt(int index); |
| 2376 | inline Object* InObjectPropertyAtPut(int index, |
| 2377 | Object* value, |
| 2378 | WriteBarrierMode mode |
| 2379 | = UPDATE_WRITE_BARRIER); |
| 2380 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2381 | // Set the object's prototype (only JSReceiver and null are allowed values). |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2382 | MUST_USE_RESULT static Maybe<bool> SetPrototype(Handle<JSObject> object, |
| 2383 | Handle<Object> value, |
| 2384 | bool from_javascript, |
| 2385 | ShouldThrow should_throw); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2386 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2387 | // Initializes the body starting at |start_offset|. It is responsibility of |
| 2388 | // the caller to initialize object header. Fill the pre-allocated fields with |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2389 | // pre_allocated_value and the rest with filler_value. |
| 2390 | // Note: this call does not update write barrier, the caller is responsible |
| 2391 | // to ensure that |filler_value| can be collected without WB here. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2392 | inline void InitializeBody(Map* map, int start_offset, |
| 2393 | Object* pre_allocated_value, Object* filler_value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2394 | |
| 2395 | // Check whether this object references another object |
| 2396 | bool ReferencesObject(Object* obj); |
| 2397 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2398 | MUST_USE_RESULT static Maybe<bool> PreventExtensions( |
| 2399 | Handle<JSObject> object, ShouldThrow should_throw); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2400 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2401 | static bool IsExtensible(Handle<JSObject> object); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2402 | |
| 2403 | // Called the first time an object is observed with ES7 Object.observe. |
| 2404 | static void SetObserved(Handle<JSObject> object); |
| 2405 | |
| 2406 | // Copy object. |
| 2407 | enum DeepCopyHints { kNoHints = 0, kObjectIsShallow = 1 }; |
| 2408 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2409 | MUST_USE_RESULT static MaybeHandle<JSObject> DeepCopy( |
| 2410 | Handle<JSObject> object, |
| 2411 | AllocationSiteUsageContext* site_context, |
| 2412 | DeepCopyHints hints = kNoHints); |
| 2413 | MUST_USE_RESULT static MaybeHandle<JSObject> DeepWalk( |
| 2414 | Handle<JSObject> object, |
| 2415 | AllocationSiteCreationContext* site_context); |
| 2416 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2417 | DECLARE_CAST(JSObject) |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2418 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2419 | // Dispatched behavior. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2420 | void JSObjectShortPrint(StringStream* accumulator); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2421 | DECLARE_PRINTER(JSObject) |
| 2422 | DECLARE_VERIFIER(JSObject) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2423 | #ifdef OBJECT_PRINT |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2424 | void PrintProperties(std::ostream& os); // NOLINT |
| 2425 | void PrintElements(std::ostream& os); // NOLINT |
| 2426 | #endif |
| 2427 | #if defined(DEBUG) || defined(OBJECT_PRINT) |
| 2428 | void PrintTransitions(std::ostream& os); // NOLINT |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2429 | #endif |
| 2430 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2431 | static void PrintElementsTransition( |
| 2432 | FILE* file, Handle<JSObject> object, |
| 2433 | ElementsKind from_kind, Handle<FixedArrayBase> from_elements, |
| 2434 | ElementsKind to_kind, Handle<FixedArrayBase> to_elements); |
| 2435 | |
| 2436 | void PrintInstanceMigration(FILE* file, Map* original_map, Map* new_map); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2437 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2438 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2439 | // Structure for collecting spill information about JSObjects. |
| 2440 | class SpillInformation { |
| 2441 | public: |
| 2442 | void Clear(); |
| 2443 | void Print(); |
| 2444 | int number_of_objects_; |
| 2445 | int number_of_objects_with_fast_properties_; |
| 2446 | int number_of_objects_with_fast_elements_; |
| 2447 | int number_of_fast_used_fields_; |
| 2448 | int number_of_fast_unused_fields_; |
| 2449 | int number_of_slow_used_properties_; |
| 2450 | int number_of_slow_unused_properties_; |
| 2451 | int number_of_fast_used_elements_; |
| 2452 | int number_of_fast_unused_elements_; |
| 2453 | int number_of_slow_used_elements_; |
| 2454 | int number_of_slow_unused_elements_; |
| 2455 | }; |
| 2456 | |
| 2457 | void IncrementSpillStatistics(SpillInformation* info); |
| 2458 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2459 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2460 | #ifdef VERIFY_HEAP |
| 2461 | // If a GC was caused while constructing this object, the elements pointer |
| 2462 | // may point to a one pointer filler map. The object won't be rooted, but |
| 2463 | // our heap verification code could stumble across it. |
| 2464 | bool ElementsAreSafeToExamine(); |
| 2465 | #endif |
| 2466 | |
| 2467 | Object* SlowReverseLookup(Object* value); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2468 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2469 | // Maximal number of elements (numbered 0 .. kMaxElementCount - 1). |
| 2470 | // Also maximal value of JSArray's length property. |
| 2471 | static const uint32_t kMaxElementCount = 0xffffffffu; |
| 2472 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2473 | // Constants for heuristics controlling conversion of fast elements |
| 2474 | // to slow elements. |
| 2475 | |
| 2476 | // Maximal gap that can be introduced by adding an element beyond |
| 2477 | // the current elements length. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2478 | static const uint32_t kMaxGap = 1024; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2479 | |
| 2480 | // Maximal length of fast elements array that won't be checked for |
| 2481 | // being dense enough on expansion. |
| 2482 | static const int kMaxUncheckedFastElementsLength = 5000; |
| 2483 | |
| 2484 | // Same as above but for old arrays. This limit is more strict. We |
| 2485 | // don't want to be wasteful with long lived objects. |
| 2486 | static const int kMaxUncheckedOldFastElementsLength = 500; |
| 2487 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2488 | // This constant applies only to the initial map of "global.Object" and |
| 2489 | // not to arbitrary other JSObject maps. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2490 | static const int kInitialGlobalObjectUnusedPropertiesCount = 4; |
| 2491 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2492 | static const int kMaxInstanceSize = 255 * kPointerSize; |
| 2493 | // When extending the backing storage for property values, we increase |
| 2494 | // its size by more than the 1 entry necessary, so sequentially adding fields |
| 2495 | // to the same object requires fewer allocations and copies. |
| 2496 | static const int kFieldsAdded = 3; |
| 2497 | |
| 2498 | // Layout description. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2499 | static const int kElementsOffset = JSReceiver::kHeaderSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2500 | static const int kHeaderSize = kElementsOffset + kPointerSize; |
| 2501 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2502 | STATIC_ASSERT(kHeaderSize == Internals::kJSObjectHeaderSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2503 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2504 | typedef FlexibleBodyDescriptor<JSReceiver::kPropertiesOffset> BodyDescriptor; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2505 | |
| 2506 | // Enqueue change record for Object.observe. May cause GC. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2507 | MUST_USE_RESULT static MaybeHandle<Object> EnqueueChangeRecord( |
| 2508 | Handle<JSObject> object, const char* type, Handle<Name> name, |
| 2509 | Handle<Object> old_value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2510 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2511 | // Gets the number of currently used elements. |
| 2512 | int GetFastElementsUsage(); |
| 2513 | |
| 2514 | static bool AllCanRead(LookupIterator* it); |
| 2515 | static bool AllCanWrite(LookupIterator* it); |
| 2516 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2517 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2518 | friend class JSReceiver; |
| 2519 | friend class Object; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2520 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2521 | // Used from Object::GetProperty(). |
| 2522 | MUST_USE_RESULT static MaybeHandle<Object> GetPropertyWithFailedAccessCheck( |
| 2523 | LookupIterator* it); |
| 2524 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2525 | MUST_USE_RESULT static Maybe<bool> SetPropertyWithFailedAccessCheck( |
| 2526 | LookupIterator* it, Handle<Object> value, ShouldThrow should_throw); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2527 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2528 | // Add a property to a slow-case object. |
| 2529 | static void AddSlowProperty(Handle<JSObject> object, |
| 2530 | Handle<Name> name, |
| 2531 | Handle<Object> value, |
| 2532 | PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2533 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2534 | MUST_USE_RESULT static Maybe<bool> DeletePropertyWithInterceptor( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2535 | LookupIterator* it, ShouldThrow should_throw); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2536 | |
| 2537 | bool ReferencesObjectFromElements(FixedArray* elements, |
| 2538 | ElementsKind kind, |
| 2539 | Object* object); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2540 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2541 | // Return the hash table backing store or the inline stored identity hash, |
| 2542 | // whatever is found. |
| 2543 | MUST_USE_RESULT Object* GetHiddenPropertiesHashTable(); |
| 2544 | |
| 2545 | // Return the hash table backing store for hidden properties. If there is no |
| 2546 | // backing store, allocate one. |
| 2547 | static Handle<ObjectHashTable> GetOrCreateHiddenPropertiesHashtable( |
| 2548 | Handle<JSObject> object); |
| 2549 | |
| 2550 | // Set the hidden property backing store to either a hash table or |
| 2551 | // the inline-stored identity hash. |
| 2552 | static Handle<Object> SetHiddenPropertiesHashTable( |
| 2553 | Handle<JSObject> object, |
| 2554 | Handle<Object> value); |
| 2555 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 2556 | static Handle<Object> GetIdentityHash(Isolate* isolate, |
| 2557 | Handle<JSObject> object); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2558 | |
| 2559 | static Handle<Smi> GetOrCreateIdentityHash(Handle<JSObject> object); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2560 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2561 | // Helper for fast versions of preventExtensions, seal, and freeze. |
| 2562 | // attrs is one of NONE, SEALED, or FROZEN (depending on the operation). |
| 2563 | template <PropertyAttributes attrs> |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2564 | MUST_USE_RESULT static Maybe<bool> PreventExtensionsWithTransition( |
| 2565 | Handle<JSObject> object, ShouldThrow should_throw); |
| 2566 | |
| 2567 | MUST_USE_RESULT static Maybe<bool> SetPrototypeUnobserved( |
| 2568 | Handle<JSObject> object, Handle<Object> value, bool from_javascript, |
| 2569 | ShouldThrow should_throw); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2570 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2571 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSObject); |
| 2572 | }; |
| 2573 | |
| 2574 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2575 | // JSAccessorPropertyDescriptor is just a JSObject with a specific initial |
| 2576 | // map. This initial map adds in-object properties for "get", "set", |
| 2577 | // "enumerable" and "configurable" properties, as assigned by the |
| 2578 | // FromPropertyDescriptor function for regular accessor properties. |
| 2579 | class JSAccessorPropertyDescriptor: public JSObject { |
| 2580 | public: |
| 2581 | // Offsets of object fields. |
| 2582 | static const int kGetOffset = JSObject::kHeaderSize; |
| 2583 | static const int kSetOffset = kGetOffset + kPointerSize; |
| 2584 | static const int kEnumerableOffset = kSetOffset + kPointerSize; |
| 2585 | static const int kConfigurableOffset = kEnumerableOffset + kPointerSize; |
| 2586 | static const int kSize = kConfigurableOffset + kPointerSize; |
| 2587 | // Indices of in-object properties. |
| 2588 | static const int kGetIndex = 0; |
| 2589 | static const int kSetIndex = 1; |
| 2590 | static const int kEnumerableIndex = 2; |
| 2591 | static const int kConfigurableIndex = 3; |
| 2592 | |
| 2593 | private: |
| 2594 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSAccessorPropertyDescriptor); |
| 2595 | }; |
| 2596 | |
| 2597 | |
| 2598 | // JSDataPropertyDescriptor is just a JSObject with a specific initial map. |
| 2599 | // This initial map adds in-object properties for "value", "writable", |
| 2600 | // "enumerable" and "configurable" properties, as assigned by the |
| 2601 | // FromPropertyDescriptor function for regular data properties. |
| 2602 | class JSDataPropertyDescriptor: public JSObject { |
| 2603 | public: |
| 2604 | // Offsets of object fields. |
| 2605 | static const int kValueOffset = JSObject::kHeaderSize; |
| 2606 | static const int kWritableOffset = kValueOffset + kPointerSize; |
| 2607 | static const int kEnumerableOffset = kWritableOffset + kPointerSize; |
| 2608 | static const int kConfigurableOffset = kEnumerableOffset + kPointerSize; |
| 2609 | static const int kSize = kConfigurableOffset + kPointerSize; |
| 2610 | // Indices of in-object properties. |
| 2611 | static const int kValueIndex = 0; |
| 2612 | static const int kWritableIndex = 1; |
| 2613 | static const int kEnumerableIndex = 2; |
| 2614 | static const int kConfigurableIndex = 3; |
| 2615 | |
| 2616 | private: |
| 2617 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSDataPropertyDescriptor); |
| 2618 | }; |
| 2619 | |
| 2620 | |
| 2621 | // JSIteratorResult is just a JSObject with a specific initial map. |
| 2622 | // This initial map adds in-object properties for "done" and "value", |
| 2623 | // as specified by ES6 section 25.1.1.3 The IteratorResult Interface |
| 2624 | class JSIteratorResult: public JSObject { |
| 2625 | public: |
| 2626 | // Offsets of object fields. |
| 2627 | static const int kValueOffset = JSObject::kHeaderSize; |
| 2628 | static const int kDoneOffset = kValueOffset + kPointerSize; |
| 2629 | static const int kSize = kDoneOffset + kPointerSize; |
| 2630 | // Indices of in-object properties. |
| 2631 | static const int kValueIndex = 0; |
| 2632 | static const int kDoneIndex = 1; |
| 2633 | |
| 2634 | private: |
| 2635 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSIteratorResult); |
| 2636 | }; |
| 2637 | |
| 2638 | |
| 2639 | // Common superclass for JSSloppyArgumentsObject and JSStrictArgumentsObject. |
| 2640 | class JSArgumentsObject: public JSObject { |
| 2641 | public: |
| 2642 | // Offsets of object fields. |
| 2643 | static const int kLengthOffset = JSObject::kHeaderSize; |
| 2644 | static const int kHeaderSize = kLengthOffset + kPointerSize; |
| 2645 | // Indices of in-object properties. |
| 2646 | static const int kLengthIndex = 0; |
| 2647 | |
| 2648 | private: |
| 2649 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSArgumentsObject); |
| 2650 | }; |
| 2651 | |
| 2652 | |
| 2653 | // JSSloppyArgumentsObject is just a JSObject with specific initial map. |
| 2654 | // This initial map adds in-object properties for "length" and "callee". |
| 2655 | class JSSloppyArgumentsObject: public JSArgumentsObject { |
| 2656 | public: |
| 2657 | // Offsets of object fields. |
| 2658 | static const int kCalleeOffset = JSArgumentsObject::kHeaderSize; |
| 2659 | static const int kSize = kCalleeOffset + kPointerSize; |
| 2660 | // Indices of in-object properties. |
| 2661 | static const int kCalleeIndex = 1; |
| 2662 | |
| 2663 | private: |
| 2664 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSSloppyArgumentsObject); |
| 2665 | }; |
| 2666 | |
| 2667 | |
| 2668 | // JSStrictArgumentsObject is just a JSObject with specific initial map. |
| 2669 | // This initial map adds an in-object property for "length". |
| 2670 | class JSStrictArgumentsObject: public JSArgumentsObject { |
| 2671 | public: |
| 2672 | // Offsets of object fields. |
| 2673 | static const int kSize = JSArgumentsObject::kHeaderSize; |
| 2674 | |
| 2675 | private: |
| 2676 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSStrictArgumentsObject); |
| 2677 | }; |
| 2678 | |
| 2679 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2680 | // Common superclass for FixedArrays that allow implementations to share |
| 2681 | // common accessors and some code paths. |
| 2682 | class FixedArrayBase: public HeapObject { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2683 | public: |
| 2684 | // [length]: length of the array. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2685 | inline int length() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2686 | inline void set_length(int value); |
| 2687 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2688 | // Get and set the length using acquire loads and release stores. |
| 2689 | inline int synchronized_length() const; |
| 2690 | inline void synchronized_set_length(int value); |
| 2691 | |
| 2692 | DECLARE_CAST(FixedArrayBase) |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2693 | |
| 2694 | // Layout description. |
| 2695 | // Length is smi tagged when it is stored. |
| 2696 | static const int kLengthOffset = HeapObject::kHeaderSize; |
| 2697 | static const int kHeaderSize = kLengthOffset + kPointerSize; |
| 2698 | }; |
| 2699 | |
| 2700 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2701 | class FixedDoubleArray; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2702 | class IncrementalMarking; |
| 2703 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2704 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2705 | // FixedArray describes fixed-sized arrays with element type Object*. |
| 2706 | class FixedArray: public FixedArrayBase { |
| 2707 | public: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2708 | // Setter and getter for elements. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2709 | inline Object* get(int index) const; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2710 | static inline Handle<Object> get(FixedArray* array, int index, |
| 2711 | Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2712 | // Setter that uses write barrier. |
| 2713 | inline void set(int index, Object* value); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2714 | inline bool is_the_hole(int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2715 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2716 | // Setter that doesn't need write barrier. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2717 | inline void set(int index, Smi* value); |
| 2718 | // Setter with explicit barrier mode. |
| 2719 | inline void set(int index, Object* value, WriteBarrierMode mode); |
| 2720 | |
| 2721 | // Setters for frequently used oddballs located in old space. |
| 2722 | inline void set_undefined(int index); |
| 2723 | inline void set_null(int index); |
| 2724 | inline void set_the_hole(int index); |
| 2725 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2726 | inline Object** GetFirstElementAddress(); |
| 2727 | inline bool ContainsOnlySmisOrHoles(); |
| 2728 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2729 | // Gives access to raw memory which stores the array's data. |
| 2730 | inline Object** data_start(); |
| 2731 | |
| 2732 | inline void FillWithHoles(int from, int to); |
| 2733 | |
| 2734 | // Shrink length and insert filler objects. |
| 2735 | void Shrink(int length); |
| 2736 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2737 | // Copy a sub array from the receiver to dest. |
| 2738 | void CopyTo(int pos, FixedArray* dest, int dest_pos, int len); |
| 2739 | |
| 2740 | // Garbage collection support. |
| 2741 | static int SizeFor(int length) { return kHeaderSize + length * kPointerSize; } |
| 2742 | |
| 2743 | // Code Generation support. |
| 2744 | static int OffsetOfElementAt(int index) { return SizeFor(index); } |
| 2745 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2746 | // Garbage collection support. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2747 | inline Object** RawFieldOfElementAt(int index); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2748 | |
| 2749 | DECLARE_CAST(FixedArray) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2750 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2751 | // Maximal allowed size, in bytes, of a single FixedArray. |
| 2752 | // Prevents overflowing size computations, as well as extreme memory |
| 2753 | // consumption. |
Ben Murdoch | 692be65 | 2012-01-10 18:47:50 +0000 | [diff] [blame] | 2754 | static const int kMaxSize = 128 * MB * kPointerSize; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2755 | // Maximally allowed length of a FixedArray. |
| 2756 | static const int kMaxLength = (kMaxSize - kHeaderSize) / kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2757 | |
| 2758 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2759 | DECLARE_PRINTER(FixedArray) |
| 2760 | DECLARE_VERIFIER(FixedArray) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2761 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2762 | // Checks if two FixedArrays have identical contents. |
| 2763 | bool IsEqualTo(FixedArray* other); |
| 2764 | #endif |
| 2765 | |
| 2766 | // Swap two elements in a pair of arrays. If this array and the |
| 2767 | // numbers array are the same object, the elements are only swapped |
| 2768 | // once. |
| 2769 | void SwapPairs(FixedArray* numbers, int i, int j); |
| 2770 | |
| 2771 | // Sort prefix of this array and the numbers array as pairs wrt. the |
| 2772 | // numbers. If the numbers array and the this array are the same |
| 2773 | // object, the prefix of this array is sorted. |
| 2774 | void SortPairs(FixedArray* numbers, uint32_t len); |
| 2775 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2776 | typedef FlexibleBodyDescriptor<kHeaderSize> BodyDescriptor; |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2777 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2778 | protected: |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 2779 | // Set operation on FixedArray without using write barriers. Can |
| 2780 | // only be used for storing old space objects or smis. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2781 | static inline void NoWriteBarrierSet(FixedArray* array, |
| 2782 | int index, |
| 2783 | Object* value); |
| 2784 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2785 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2786 | STATIC_ASSERT(kHeaderSize == Internals::kFixedArrayHeaderSize); |
| 2787 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2788 | DISALLOW_IMPLICIT_CONSTRUCTORS(FixedArray); |
| 2789 | }; |
| 2790 | |
| 2791 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2792 | // FixedDoubleArray describes fixed-sized arrays with element type double. |
| 2793 | class FixedDoubleArray: public FixedArrayBase { |
| 2794 | public: |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2795 | // Setter and getter for elements. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2796 | inline double get_scalar(int index); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2797 | inline uint64_t get_representation(int index); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2798 | static inline Handle<Object> get(FixedDoubleArray* array, int index, |
| 2799 | Isolate* isolate); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2800 | inline void set(int index, double value); |
| 2801 | inline void set_the_hole(int index); |
| 2802 | |
| 2803 | // Checking for the hole. |
| 2804 | inline bool is_the_hole(int index); |
| 2805 | |
| 2806 | // Garbage collection support. |
| 2807 | inline static int SizeFor(int length) { |
| 2808 | return kHeaderSize + length * kDoubleSize; |
| 2809 | } |
| 2810 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2811 | // Gives access to raw memory which stores the array's data. |
| 2812 | inline double* data_start(); |
| 2813 | |
| 2814 | inline void FillWithHoles(int from, int to); |
| 2815 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2816 | // Code Generation support. |
| 2817 | static int OffsetOfElementAt(int index) { return SizeFor(index); } |
| 2818 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2819 | DECLARE_CAST(FixedDoubleArray) |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2820 | |
| 2821 | // Maximal allowed size, in bytes, of a single FixedDoubleArray. |
| 2822 | // Prevents overflowing size computations, as well as extreme memory |
| 2823 | // consumption. |
| 2824 | static const int kMaxSize = 512 * MB; |
| 2825 | // Maximally allowed length of a FixedArray. |
| 2826 | static const int kMaxLength = (kMaxSize - kHeaderSize) / kDoubleSize; |
| 2827 | |
| 2828 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2829 | DECLARE_PRINTER(FixedDoubleArray) |
| 2830 | DECLARE_VERIFIER(FixedDoubleArray) |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2831 | |
| 2832 | private: |
| 2833 | DISALLOW_IMPLICIT_CONSTRUCTORS(FixedDoubleArray); |
| 2834 | }; |
| 2835 | |
| 2836 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2837 | class WeakFixedArray : public FixedArray { |
| 2838 | public: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2839 | // 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] | 2840 | // This function does not check if the value exists already, callers must |
| 2841 | // ensure this themselves if necessary. |
| 2842 | static Handle<WeakFixedArray> Add(Handle<Object> maybe_array, |
| 2843 | Handle<HeapObject> value, |
| 2844 | int* assigned_index = NULL); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2845 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2846 | // Returns true if an entry was found and removed. |
| 2847 | bool Remove(Handle<HeapObject> value); |
| 2848 | |
| 2849 | class NullCallback { |
| 2850 | public: |
| 2851 | static void Callback(Object* value, int old_index, int new_index) {} |
| 2852 | }; |
| 2853 | |
| 2854 | template <class CompactionCallback> |
| 2855 | void Compact(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2856 | |
| 2857 | inline Object* Get(int index) const; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2858 | inline void Clear(int index); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2859 | inline int Length() const; |
| 2860 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2861 | inline bool IsEmptySlot(int index) const; |
| 2862 | static Object* Empty() { return Smi::FromInt(0); } |
| 2863 | |
| 2864 | class Iterator { |
| 2865 | public: |
| 2866 | explicit Iterator(Object* maybe_array) : list_(NULL) { Reset(maybe_array); } |
| 2867 | void Reset(Object* maybe_array); |
| 2868 | |
| 2869 | template <class T> |
| 2870 | inline T* Next(); |
| 2871 | |
| 2872 | private: |
| 2873 | int index_; |
| 2874 | WeakFixedArray* list_; |
| 2875 | #ifdef DEBUG |
| 2876 | int last_used_index_; |
| 2877 | DisallowHeapAllocation no_gc_; |
| 2878 | #endif // DEBUG |
| 2879 | DISALLOW_COPY_AND_ASSIGN(Iterator); |
| 2880 | }; |
| 2881 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2882 | DECLARE_CAST(WeakFixedArray) |
| 2883 | |
| 2884 | private: |
| 2885 | static const int kLastUsedIndexIndex = 0; |
| 2886 | static const int kFirstIndex = 1; |
| 2887 | |
| 2888 | static Handle<WeakFixedArray> Allocate( |
| 2889 | Isolate* isolate, int size, Handle<WeakFixedArray> initialize_from); |
| 2890 | |
| 2891 | static void Set(Handle<WeakFixedArray> array, int index, |
| 2892 | Handle<HeapObject> value); |
| 2893 | inline void clear(int index); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2894 | |
| 2895 | inline int last_used_index() const; |
| 2896 | inline void set_last_used_index(int index); |
| 2897 | |
| 2898 | // Disallow inherited setters. |
| 2899 | void set(int index, Smi* value); |
| 2900 | void set(int index, Object* value); |
| 2901 | void set(int index, Object* value, WriteBarrierMode mode); |
| 2902 | DISALLOW_IMPLICIT_CONSTRUCTORS(WeakFixedArray); |
| 2903 | }; |
| 2904 | |
| 2905 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2906 | // Generic array grows dynamically with O(1) amortized insertion. |
| 2907 | class ArrayList : public FixedArray { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2908 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2909 | enum AddMode { |
| 2910 | kNone, |
| 2911 | // Use this if GC can delete elements from the array. |
| 2912 | kReloadLengthAfterAllocation, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2913 | }; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2914 | static Handle<ArrayList> Add(Handle<ArrayList> array, Handle<Object> obj, |
| 2915 | AddMode mode = kNone); |
| 2916 | static Handle<ArrayList> Add(Handle<ArrayList> array, Handle<Object> obj1, |
| 2917 | Handle<Object> obj2, AddMode = kNone); |
| 2918 | inline int Length(); |
| 2919 | inline void SetLength(int length); |
| 2920 | inline Object* Get(int index); |
| 2921 | inline Object** Slot(int index); |
| 2922 | inline void Set(int index, Object* obj); |
| 2923 | inline void Clear(int index, Object* undefined); |
| 2924 | bool IsFull(); |
| 2925 | DECLARE_CAST(ArrayList) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2926 | |
| 2927 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2928 | static Handle<ArrayList> EnsureSpace(Handle<ArrayList> array, int length); |
| 2929 | static const int kLengthIndex = 0; |
| 2930 | static const int kFirstIndex = 1; |
| 2931 | DISALLOW_IMPLICIT_CONSTRUCTORS(ArrayList); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2932 | }; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2933 | |
| 2934 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2935 | // DescriptorArrays are fixed arrays used to hold instance descriptors. |
| 2936 | // The format of the these objects is: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2937 | // [0]: Number of descriptors |
| 2938 | // [1]: Either Smi(0) if uninitialized, or a pointer to small fixed array: |
| 2939 | // [0]: pointer to fixed array with enum cache |
| 2940 | // [1]: either Smi(0) or pointer to fixed array with indices |
| 2941 | // [2]: first key |
| 2942 | // [2 + number of descriptors * kDescriptorSize]: start of slack |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2943 | class DescriptorArray: public FixedArray { |
| 2944 | public: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2945 | // Returns true for both shared empty_descriptor_array and for smis, which the |
| 2946 | // map uses to encode additional bit fields when the descriptor array is not |
| 2947 | // yet used. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2948 | inline bool IsEmpty(); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2949 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2950 | // Returns the number of descriptors in the array. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2951 | inline int number_of_descriptors(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2952 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2953 | inline int number_of_descriptors_storage(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2954 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2955 | inline int NumberOfSlackDescriptors(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2956 | |
| 2957 | inline void SetNumberOfDescriptors(int number_of_descriptors); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2958 | inline int number_of_entries(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2959 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2960 | inline bool HasEnumCache(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2961 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2962 | inline void CopyEnumCacheFrom(DescriptorArray* array); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2963 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2964 | inline FixedArray* GetEnumCache(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2965 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2966 | inline bool HasEnumIndicesCache(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2967 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2968 | inline FixedArray* GetEnumIndicesCache(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2969 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2970 | inline Object** GetEnumCacheSlot(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2971 | |
| 2972 | void ClearEnumCache(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2973 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2974 | // Initialize or change the enum cache, |
| 2975 | // using the supplied storage for the small "bridge". |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2976 | static void SetEnumCache(Handle<DescriptorArray> descriptors, |
| 2977 | Isolate* isolate, Handle<FixedArray> new_cache, |
| 2978 | Handle<FixedArray> new_index_cache); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2979 | |
| 2980 | // Accessors for fetching instance descriptor at descriptor number. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2981 | inline Name* GetKey(int descriptor_number); |
| 2982 | inline Object** GetKeySlot(int descriptor_number); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2983 | inline Object* GetValue(int descriptor_number); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2984 | inline void SetValue(int descriptor_number, Object* value); |
| 2985 | inline Object** GetValueSlot(int descriptor_number); |
| 2986 | static inline int GetValueOffset(int descriptor_number); |
| 2987 | inline Object** GetDescriptorStartSlot(int descriptor_number); |
| 2988 | inline Object** GetDescriptorEndSlot(int descriptor_number); |
| 2989 | inline PropertyDetails GetDetails(int descriptor_number); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2990 | inline PropertyType GetType(int descriptor_number); |
| 2991 | inline int GetFieldIndex(int descriptor_number); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 2992 | FieldType* GetFieldType(int descriptor_number); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2993 | inline Object* GetConstant(int descriptor_number); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2994 | inline Object* GetCallbacksObject(int descriptor_number); |
| 2995 | inline AccessorDescriptor* GetCallbacks(int descriptor_number); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2996 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2997 | inline Name* GetSortedKey(int descriptor_number); |
| 2998 | inline int GetSortedKeyIndex(int descriptor_number); |
| 2999 | inline void SetSortedKey(int pointer, int descriptor_number); |
| 3000 | inline void SetRepresentation(int descriptor_number, |
| 3001 | Representation representation); |
| 3002 | |
| 3003 | // Accessor for complete descriptor. |
| 3004 | inline void Get(int descriptor_number, Descriptor* desc); |
| 3005 | inline void Set(int descriptor_number, Descriptor* desc); |
| 3006 | void Replace(int descriptor_number, Descriptor* descriptor); |
| 3007 | |
| 3008 | // Append automatically sets the enumeration index. This should only be used |
| 3009 | // to add descriptors in bulk at the end, followed by sorting the descriptor |
| 3010 | // array. |
| 3011 | inline void Append(Descriptor* desc); |
| 3012 | |
| 3013 | static Handle<DescriptorArray> CopyUpTo(Handle<DescriptorArray> desc, |
| 3014 | int enumeration_index, |
| 3015 | int slack = 0); |
| 3016 | |
| 3017 | static Handle<DescriptorArray> CopyUpToAddAttributes( |
| 3018 | Handle<DescriptorArray> desc, |
| 3019 | int enumeration_index, |
| 3020 | PropertyAttributes attributes, |
| 3021 | int slack = 0); |
| 3022 | |
| 3023 | // Sort the instance descriptors by the hash codes of their keys. |
| 3024 | void Sort(); |
| 3025 | |
| 3026 | // Search the instance descriptors for given name. |
| 3027 | INLINE(int Search(Name* name, int number_of_own_descriptors)); |
| 3028 | |
| 3029 | // As the above, but uses DescriptorLookupCache and updates it when |
| 3030 | // necessary. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3031 | INLINE(int SearchWithCache(Isolate* isolate, Name* name, Map* map)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3032 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3033 | bool IsEqualUpTo(DescriptorArray* desc, int nof_descriptors); |
| 3034 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3035 | // Allocates a DescriptorArray, but returns the singleton |
| 3036 | // empty descriptor array object if number_of_descriptors is 0. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 3037 | static Handle<DescriptorArray> Allocate( |
| 3038 | Isolate* isolate, int number_of_descriptors, int slack, |
| 3039 | PretenureFlag pretenure = NOT_TENURED); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3040 | |
| 3041 | DECLARE_CAST(DescriptorArray) |
| 3042 | |
| 3043 | // Constant for denoting key was not found. |
| 3044 | static const int kNotFound = -1; |
| 3045 | |
| 3046 | static const int kDescriptorLengthIndex = 0; |
| 3047 | static const int kEnumCacheIndex = 1; |
| 3048 | static const int kFirstIndex = 2; |
| 3049 | |
| 3050 | // The length of the "bridge" to the enum cache. |
| 3051 | static const int kEnumCacheBridgeLength = 2; |
| 3052 | static const int kEnumCacheBridgeCacheIndex = 0; |
| 3053 | static const int kEnumCacheBridgeIndicesCacheIndex = 1; |
| 3054 | |
| 3055 | // Layout description. |
| 3056 | static const int kDescriptorLengthOffset = FixedArray::kHeaderSize; |
| 3057 | static const int kEnumCacheOffset = kDescriptorLengthOffset + kPointerSize; |
| 3058 | static const int kFirstOffset = kEnumCacheOffset + kPointerSize; |
| 3059 | |
| 3060 | // Layout description for the bridge array. |
| 3061 | static const int kEnumCacheBridgeCacheOffset = FixedArray::kHeaderSize; |
| 3062 | |
| 3063 | // Layout of descriptor. |
| 3064 | static const int kDescriptorKey = 0; |
| 3065 | static const int kDescriptorDetails = 1; |
| 3066 | static const int kDescriptorValue = 2; |
| 3067 | static const int kDescriptorSize = 3; |
| 3068 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3069 | #if defined(DEBUG) || defined(OBJECT_PRINT) |
| 3070 | // For our gdb macros, we should perhaps change these in the future. |
| 3071 | void Print(); |
| 3072 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3073 | // Print all the descriptors. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3074 | void PrintDescriptors(std::ostream& os); // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3075 | #endif |
| 3076 | |
| 3077 | #ifdef DEBUG |
| 3078 | // Is the descriptor array sorted and without duplicates? |
| 3079 | bool IsSortedNoDuplicates(int valid_descriptors = -1); |
| 3080 | |
| 3081 | // Is the descriptor array consistent with the back pointers in targets? |
| 3082 | bool IsConsistentWithBackPointers(Map* current_map); |
| 3083 | |
| 3084 | // Are two DescriptorArrays equal? |
| 3085 | bool IsEqualTo(DescriptorArray* other); |
| 3086 | #endif |
| 3087 | |
| 3088 | // Returns the fixed array length required to hold number_of_descriptors |
| 3089 | // descriptors. |
| 3090 | static int LengthFor(int number_of_descriptors) { |
| 3091 | return ToKeyIndex(number_of_descriptors); |
| 3092 | } |
| 3093 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 3094 | static int ToDetailsIndex(int descriptor_number) { |
| 3095 | return kFirstIndex + (descriptor_number * kDescriptorSize) + |
| 3096 | kDescriptorDetails; |
| 3097 | } |
| 3098 | |
| 3099 | // Conversion from descriptor number to array indices. |
| 3100 | static int ToKeyIndex(int descriptor_number) { |
| 3101 | return kFirstIndex + (descriptor_number * kDescriptorSize) + kDescriptorKey; |
| 3102 | } |
| 3103 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3104 | private: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3105 | // An entry in a DescriptorArray, represented as an (array, index) pair. |
| 3106 | class Entry { |
| 3107 | public: |
| 3108 | inline explicit Entry(DescriptorArray* descs, int index) : |
| 3109 | descs_(descs), index_(index) { } |
| 3110 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3111 | inline PropertyType type(); |
| 3112 | inline Object* GetCallbackObject(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3113 | |
| 3114 | private: |
| 3115 | DescriptorArray* descs_; |
| 3116 | int index_; |
| 3117 | }; |
| 3118 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3119 | static int ToValueIndex(int descriptor_number) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3120 | return kFirstIndex + |
| 3121 | (descriptor_number * kDescriptorSize) + |
| 3122 | kDescriptorValue; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3123 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3124 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3125 | // Transfer a complete descriptor from the src descriptor array to this |
| 3126 | // descriptor array. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3127 | void CopyFrom(int index, DescriptorArray* src); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3128 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3129 | inline void SetDescriptor(int descriptor_number, Descriptor* desc); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3130 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3131 | // Swap first and second descriptor. |
| 3132 | inline void SwapSortedKeys(int first, int second); |
| 3133 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3134 | DISALLOW_IMPLICIT_CONSTRUCTORS(DescriptorArray); |
| 3135 | }; |
| 3136 | |
| 3137 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3138 | enum SearchMode { ALL_ENTRIES, VALID_ENTRIES }; |
| 3139 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3140 | template <SearchMode search_mode, typename T> |
| 3141 | inline int Search(T* array, Name* name, int valid_entries = 0, |
| 3142 | int* out_insertion_index = NULL); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3143 | |
| 3144 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3145 | // HashTable is a subclass of FixedArray that implements a hash table |
| 3146 | // that uses open addressing and quadratic probing. |
| 3147 | // |
| 3148 | // In order for the quadratic probing to work, elements that have not |
| 3149 | // yet been used and elements that have been deleted are |
| 3150 | // distinguished. Probing continues when deleted elements are |
| 3151 | // encountered and stops when unused elements are encountered. |
| 3152 | // |
| 3153 | // - Elements with key == undefined have not been used yet. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3154 | // - Elements with key == the_hole have been deleted. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3155 | // |
| 3156 | // The hash table class is parameterized with a Shape and a Key. |
| 3157 | // Shape must be a class with the following interface: |
| 3158 | // class ExampleShape { |
| 3159 | // public: |
| 3160 | // // Tells whether key matches other. |
| 3161 | // static bool IsMatch(Key key, Object* other); |
| 3162 | // // Returns the hash value for key. |
| 3163 | // static uint32_t Hash(Key key); |
| 3164 | // // Returns the hash value for object. |
| 3165 | // static uint32_t HashForObject(Key key, Object* object); |
| 3166 | // // Convert key to an object. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3167 | // static inline Handle<Object> AsHandle(Isolate* isolate, Key key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3168 | // // The prefix size indicates number of elements in the beginning |
| 3169 | // // of the backing storage. |
| 3170 | // static const int kPrefixSize = ..; |
| 3171 | // // The Element size indicates number of elements per entry. |
| 3172 | // static const int kEntrySize = ..; |
| 3173 | // }; |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3174 | // The prefix size indicates an amount of memory in the |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3175 | // beginning of the backing storage that can be used for non-element |
| 3176 | // information by subclasses. |
| 3177 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3178 | template<typename Key> |
| 3179 | class BaseShape { |
| 3180 | public: |
| 3181 | static const bool UsesSeed = false; |
| 3182 | static uint32_t Hash(Key key) { return 0; } |
| 3183 | static uint32_t SeededHash(Key key, uint32_t seed) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3184 | DCHECK(UsesSeed); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3185 | return Hash(key); |
| 3186 | } |
| 3187 | static uint32_t HashForObject(Key key, Object* object) { return 0; } |
| 3188 | static uint32_t SeededHashForObject(Key key, uint32_t seed, Object* object) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3189 | DCHECK(UsesSeed); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3190 | return HashForObject(key, object); |
| 3191 | } |
| 3192 | }; |
| 3193 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3194 | |
| 3195 | class HashTableBase : public FixedArray { |
| 3196 | public: |
| 3197 | // Returns the number of elements in the hash table. |
| 3198 | inline int NumberOfElements(); |
| 3199 | |
| 3200 | // Returns the number of deleted elements in the hash table. |
| 3201 | inline int NumberOfDeletedElements(); |
| 3202 | |
| 3203 | // Returns the capacity of the hash table. |
| 3204 | inline int Capacity(); |
| 3205 | |
| 3206 | // ElementAdded should be called whenever an element is added to a |
| 3207 | // hash table. |
| 3208 | inline void ElementAdded(); |
| 3209 | |
| 3210 | // ElementRemoved should be called whenever an element is removed from |
| 3211 | // a hash table. |
| 3212 | inline void ElementRemoved(); |
| 3213 | inline void ElementsRemoved(int n); |
| 3214 | |
| 3215 | // Computes the required capacity for a table holding the given |
| 3216 | // number of elements. May be more than HashTable::kMaxCapacity. |
| 3217 | static inline int ComputeCapacity(int at_least_space_for); |
| 3218 | |
| 3219 | // Tells whether k is a real key. The hole and undefined are not allowed |
| 3220 | // as keys and can be used to indicate missing or deleted elements. |
| 3221 | inline bool IsKey(Object* k); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 3222 | inline bool IsKey(Heap* heap, Object* k); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3223 | |
| 3224 | // Compute the probe offset (quadratic probing). |
| 3225 | INLINE(static uint32_t GetProbeOffset(uint32_t n)) { |
| 3226 | return (n + n * n) >> 1; |
| 3227 | } |
| 3228 | |
| 3229 | static const int kNumberOfElementsIndex = 0; |
| 3230 | static const int kNumberOfDeletedElementsIndex = 1; |
| 3231 | static const int kCapacityIndex = 2; |
| 3232 | static const int kPrefixStartIndex = 3; |
| 3233 | |
| 3234 | // Constant used for denoting a absent entry. |
| 3235 | static const int kNotFound = -1; |
| 3236 | |
| 3237 | protected: |
| 3238 | // Update the number of elements in the hash table. |
| 3239 | inline void SetNumberOfElements(int nof); |
| 3240 | |
| 3241 | // Update the number of deleted elements in the hash table. |
| 3242 | inline void SetNumberOfDeletedElements(int nod); |
| 3243 | |
| 3244 | // Returns probe entry. |
| 3245 | static uint32_t GetProbe(uint32_t hash, uint32_t number, uint32_t size) { |
| 3246 | DCHECK(base::bits::IsPowerOfTwo32(size)); |
| 3247 | return (hash + GetProbeOffset(number)) & (size - 1); |
| 3248 | } |
| 3249 | |
| 3250 | inline static uint32_t FirstProbe(uint32_t hash, uint32_t size) { |
| 3251 | return hash & (size - 1); |
| 3252 | } |
| 3253 | |
| 3254 | inline static uint32_t NextProbe( |
| 3255 | uint32_t last, uint32_t number, uint32_t size) { |
| 3256 | return (last + number) & (size - 1); |
| 3257 | } |
| 3258 | }; |
| 3259 | |
| 3260 | |
| 3261 | template <typename Derived, typename Shape, typename Key> |
| 3262 | class HashTable : public HashTableBase { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3263 | public: |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3264 | // Wrapper methods |
| 3265 | inline uint32_t Hash(Key key) { |
| 3266 | if (Shape::UsesSeed) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3267 | return Shape::SeededHash(key, GetHeap()->HashSeed()); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3268 | } else { |
| 3269 | return Shape::Hash(key); |
| 3270 | } |
| 3271 | } |
| 3272 | |
| 3273 | inline uint32_t HashForObject(Key key, Object* object) { |
| 3274 | if (Shape::UsesSeed) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3275 | return Shape::SeededHashForObject(key, GetHeap()->HashSeed(), object); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3276 | } else { |
| 3277 | return Shape::HashForObject(key, object); |
| 3278 | } |
| 3279 | } |
| 3280 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3281 | // Returns a new HashTable object. |
| 3282 | MUST_USE_RESULT static Handle<Derived> New( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3283 | Isolate* isolate, int at_least_space_for, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3284 | MinimumCapacity capacity_option = USE_DEFAULT_MINIMUM_CAPACITY, |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3285 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3286 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3287 | DECLARE_CAST(HashTable) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3288 | |
| 3289 | // Garbage collection support. |
| 3290 | void IteratePrefix(ObjectVisitor* visitor); |
| 3291 | void IterateElements(ObjectVisitor* visitor); |
| 3292 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3293 | // Find entry for key otherwise return kNotFound. |
| 3294 | inline int FindEntry(Key key); |
| 3295 | inline int FindEntry(Isolate* isolate, Key key, int32_t hash); |
| 3296 | int FindEntry(Isolate* isolate, Key key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3297 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3298 | // Rehashes the table in-place. |
| 3299 | void Rehash(Key key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3300 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3301 | // Returns the key at entry. |
| 3302 | Object* KeyAt(int entry) { return get(EntryToIndex(entry)); } |
| 3303 | |
| 3304 | static const int kElementsStartIndex = kPrefixStartIndex + Shape::kPrefixSize; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 3305 | static const int kEntrySize = Shape::kEntrySize; |
| 3306 | static const int kElementsStartOffset = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3307 | kHeaderSize + kElementsStartIndex * kPointerSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3308 | static const int kCapacityOffset = |
| 3309 | kHeaderSize + kCapacityIndex * kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3310 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3311 | // Returns the index for an entry (of the key) |
| 3312 | static inline int EntryToIndex(int entry) { |
| 3313 | return (entry * kEntrySize) + kElementsStartIndex; |
| 3314 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3315 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3316 | protected: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3317 | friend class ObjectHashTable; |
| 3318 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3319 | // Find the entry at which to insert element with the given key that |
| 3320 | // has the given hash value. |
| 3321 | uint32_t FindInsertionEntry(uint32_t hash); |
| 3322 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3323 | // Attempt to shrink hash table after removal of key. |
| 3324 | MUST_USE_RESULT static Handle<Derived> Shrink(Handle<Derived> table, Key key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3325 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3326 | // Ensure enough space for n additional elements. |
| 3327 | MUST_USE_RESULT static Handle<Derived> EnsureCapacity( |
| 3328 | Handle<Derived> table, |
| 3329 | int n, |
| 3330 | Key key, |
| 3331 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3332 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3333 | // Returns true if this table has sufficient capacity for adding n elements. |
| 3334 | bool HasSufficientCapacity(int n); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 3335 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3336 | // Sets the capacity of the hash table. |
| 3337 | void SetCapacity(int capacity) { |
| 3338 | // To scale a computed hash code to fit within the hash table, we |
| 3339 | // use bit-wise AND with a mask, so the capacity must be positive |
| 3340 | // and non-zero. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3341 | DCHECK(capacity > 0); |
| 3342 | DCHECK(capacity <= kMaxCapacity); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3343 | set(kCapacityIndex, Smi::FromInt(capacity)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3344 | } |
| 3345 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3346 | // Maximal capacity of HashTable. Based on maximal length of underlying |
| 3347 | // FixedArray. Staying below kMaxCapacity also ensures that EntryToIndex |
| 3348 | // cannot overflow. |
| 3349 | static const int kMaxCapacity = |
| 3350 | (FixedArray::kMaxLength - kElementsStartOffset) / kEntrySize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3351 | |
| 3352 | private: |
| 3353 | // Returns _expected_ if one of entries given by the first _probe_ probes is |
| 3354 | // equal to _expected_. Otherwise, returns the entry given by the probe |
| 3355 | // number _probe_. |
| 3356 | uint32_t EntryForProbe(Key key, Object* k, int probe, uint32_t expected); |
| 3357 | |
| 3358 | void Swap(uint32_t entry1, uint32_t entry2, WriteBarrierMode mode); |
| 3359 | |
| 3360 | // Rehashes this hash-table into the new table. |
| 3361 | void Rehash(Handle<Derived> new_table, Key key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3362 | }; |
| 3363 | |
| 3364 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3365 | // HashTableKey is an abstract superclass for virtual key behavior. |
| 3366 | class HashTableKey { |
| 3367 | public: |
| 3368 | // Returns whether the other object matches this key. |
| 3369 | virtual bool IsMatch(Object* other) = 0; |
| 3370 | // Returns the hash value for this key. |
| 3371 | virtual uint32_t Hash() = 0; |
| 3372 | // Returns the hash value for object. |
| 3373 | virtual uint32_t HashForObject(Object* key) = 0; |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3374 | // Returns the key object for storing into the hash table. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3375 | MUST_USE_RESULT virtual Handle<Object> AsHandle(Isolate* isolate) = 0; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3376 | // Required. |
| 3377 | virtual ~HashTableKey() {} |
| 3378 | }; |
| 3379 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3380 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3381 | class StringTableShape : public BaseShape<HashTableKey*> { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3382 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3383 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3384 | return key->IsMatch(value); |
| 3385 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3386 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3387 | static inline uint32_t Hash(HashTableKey* key) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3388 | return key->Hash(); |
| 3389 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3390 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3391 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3392 | return key->HashForObject(object); |
| 3393 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3394 | |
| 3395 | static inline Handle<Object> AsHandle(Isolate* isolate, HashTableKey* key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3396 | |
| 3397 | static const int kPrefixSize = 0; |
| 3398 | static const int kEntrySize = 1; |
| 3399 | }; |
| 3400 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3401 | class SeqOneByteString; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3402 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3403 | // StringTable. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3404 | // |
| 3405 | // No special elements in the prefix and the element size is 1 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3406 | // because only the string itself (the key) needs to be stored. |
| 3407 | class StringTable: public HashTable<StringTable, |
| 3408 | StringTableShape, |
| 3409 | HashTableKey*> { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3410 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3411 | // Find string in the string table. If it is not there yet, it is |
| 3412 | // added. The return value is the string found. |
| 3413 | static Handle<String> LookupString(Isolate* isolate, Handle<String> key); |
| 3414 | static Handle<String> LookupKey(Isolate* isolate, HashTableKey* key); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3415 | static String* LookupKeyIfExists(Isolate* isolate, HashTableKey* key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3416 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3417 | // Tries to internalize given string and returns string handle on success |
| 3418 | // or an empty handle otherwise. |
| 3419 | MUST_USE_RESULT static MaybeHandle<String> InternalizeStringIfExists( |
| 3420 | Isolate* isolate, |
| 3421 | Handle<String> string); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3422 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3423 | // Looks up a string that is equal to the given string and returns |
| 3424 | // string handle if it is found, or an empty handle otherwise. |
| 3425 | MUST_USE_RESULT static MaybeHandle<String> LookupStringIfExists( |
| 3426 | Isolate* isolate, |
| 3427 | Handle<String> str); |
| 3428 | MUST_USE_RESULT static MaybeHandle<String> LookupTwoCharsStringIfExists( |
| 3429 | Isolate* isolate, |
| 3430 | uint16_t c1, |
| 3431 | uint16_t c2); |
| 3432 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3433 | static void EnsureCapacityForDeserialization(Isolate* isolate, int expected); |
| 3434 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3435 | DECLARE_CAST(StringTable) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3436 | |
| 3437 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3438 | template <bool seq_one_byte> |
| 3439 | friend class JsonParser; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3440 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3441 | DISALLOW_IMPLICIT_CONSTRUCTORS(StringTable); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3442 | }; |
| 3443 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 3444 | class StringSetShape : public BaseShape<String*> { |
| 3445 | public: |
| 3446 | static inline bool IsMatch(String* key, Object* value); |
| 3447 | static inline uint32_t Hash(String* key); |
| 3448 | static inline uint32_t HashForObject(String* key, Object* object); |
| 3449 | |
| 3450 | static const int kPrefixSize = 0; |
| 3451 | static const int kEntrySize = 1; |
| 3452 | }; |
| 3453 | |
| 3454 | class StringSet : public HashTable<StringSet, StringSetShape, String*> { |
| 3455 | public: |
| 3456 | static Handle<StringSet> New(Isolate* isolate); |
| 3457 | static Handle<StringSet> Add(Handle<StringSet> blacklist, |
| 3458 | Handle<String> name); |
| 3459 | bool Has(Handle<String> name); |
| 3460 | |
| 3461 | DECLARE_CAST(StringSet) |
| 3462 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3463 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3464 | template <typename Derived, typename Shape, typename Key> |
| 3465 | class Dictionary: public HashTable<Derived, Shape, Key> { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3466 | typedef HashTable<Derived, Shape, Key> DerivedHashTable; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3467 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3468 | public: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3469 | // Returns the value at entry. |
| 3470 | Object* ValueAt(int entry) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3471 | return this->get(Derived::EntryToIndex(entry) + 1); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3472 | } |
| 3473 | |
| 3474 | // Set the value for entry. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3475 | void ValueAtPut(int entry, Object* value) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3476 | this->set(Derived::EntryToIndex(entry) + 1, value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3477 | } |
| 3478 | |
| 3479 | // Returns the property details for the property at entry. |
| 3480 | PropertyDetails DetailsAt(int entry) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3481 | return Shape::DetailsAt(static_cast<Derived*>(this), entry); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3482 | } |
| 3483 | |
| 3484 | // Set the details for entry. |
| 3485 | void DetailsAtPut(int entry, PropertyDetails value) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3486 | Shape::DetailsAtPut(static_cast<Derived*>(this), entry, value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3487 | } |
| 3488 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3489 | // Returns true if property at given entry is deleted. |
| 3490 | bool IsDeleted(int entry) { |
| 3491 | return Shape::IsDeleted(static_cast<Derived*>(this), entry); |
| 3492 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3493 | |
| 3494 | // Delete a property from the dictionary. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3495 | static Handle<Object> DeleteProperty(Handle<Derived> dictionary, int entry); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3496 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3497 | // Attempt to shrink the dictionary after deletion of key. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3498 | MUST_USE_RESULT static inline Handle<Derived> Shrink( |
| 3499 | Handle<Derived> dictionary, |
| 3500 | Key key) { |
| 3501 | return DerivedHashTable::Shrink(dictionary, key); |
| 3502 | } |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3503 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3504 | // Sorting support |
| 3505 | // TODO(dcarney): templatize or move to SeededNumberDictionary |
| 3506 | void CopyValuesTo(FixedArray* elements); |
| 3507 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3508 | // Returns the number of elements in the dictionary filtering out properties |
| 3509 | // with the specified attributes. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3510 | // TODO(jkummerow): Deprecated, only used by Object.observe. |
| 3511 | int NumberOfElementsFilterAttributes(PropertyFilter filter); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3512 | |
| 3513 | // Returns the number of enumerable elements in the dictionary. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3514 | // TODO(jkummerow): Deprecated, only used by Object.observe. |
| 3515 | int NumberOfEnumElements() { |
| 3516 | return NumberOfElementsFilterAttributes(ENUMERABLE_STRINGS); |
| 3517 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3518 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3519 | enum SortMode { UNSORTED, SORTED }; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3520 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3521 | // Fill in details for properties into storage. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3522 | // Returns the number of properties added. |
| 3523 | // TODO(jkummerow): Deprecated, only used by Object.observe. |
| 3524 | int CopyKeysTo(FixedArray* storage, int index, PropertyFilter filter, |
| 3525 | SortMode sort_mode); |
| 3526 | // Collect the keys into the given KeyAccumulator, in ascending chronological |
| 3527 | // order of property creation. |
| 3528 | static void CollectKeysTo(Handle<Dictionary<Derived, Shape, Key> > dictionary, |
| 3529 | KeyAccumulator* keys, PropertyFilter filter); |
| 3530 | |
| 3531 | // Copies enumerable keys to preallocated fixed array. |
| 3532 | void CopyEnumKeysTo(FixedArray* storage); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3533 | |
| 3534 | // Accessors for next enumeration index. |
| 3535 | void SetNextEnumerationIndex(int index) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3536 | DCHECK(index != 0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3537 | this->set(kNextEnumerationIndexIndex, Smi::FromInt(index)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3538 | } |
| 3539 | |
| 3540 | int NextEnumerationIndex() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3541 | return Smi::cast(this->get(kNextEnumerationIndexIndex))->value(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3542 | } |
| 3543 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3544 | // Creates a new dictionary. |
| 3545 | MUST_USE_RESULT static Handle<Derived> New( |
| 3546 | Isolate* isolate, |
| 3547 | int at_least_space_for, |
| 3548 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3549 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3550 | // Ensures that a new dictionary is created when the capacity is checked. |
| 3551 | void SetRequiresCopyOnCapacityChange(); |
| 3552 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3553 | // Ensure enough space for n additional elements. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3554 | static Handle<Derived> EnsureCapacity(Handle<Derived> obj, int n, Key key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3555 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3556 | #ifdef OBJECT_PRINT |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3557 | void Print(std::ostream& os); // NOLINT |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3558 | #endif |
| 3559 | // Returns the key (slow). |
| 3560 | Object* SlowReverseLookup(Object* value); |
| 3561 | |
| 3562 | // Sets the entry to (key, value) pair. |
| 3563 | inline void SetEntry(int entry, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3564 | Handle<Object> key, |
| 3565 | Handle<Object> value); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3566 | inline void SetEntry(int entry, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3567 | Handle<Object> key, |
| 3568 | Handle<Object> value, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3569 | PropertyDetails details); |
| 3570 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3571 | MUST_USE_RESULT static Handle<Derived> Add( |
| 3572 | Handle<Derived> dictionary, |
| 3573 | Key key, |
| 3574 | Handle<Object> value, |
| 3575 | PropertyDetails details); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3576 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3577 | // Returns iteration indices array for the |dictionary|. |
| 3578 | // Values are direct indices in the |HashTable| array. |
| 3579 | static Handle<FixedArray> BuildIterationIndicesArray( |
| 3580 | Handle<Derived> dictionary); |
| 3581 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3582 | protected: |
| 3583 | // Generic at put operation. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3584 | MUST_USE_RESULT static Handle<Derived> AtPut( |
| 3585 | Handle<Derived> dictionary, |
| 3586 | Key key, |
| 3587 | Handle<Object> value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3588 | |
| 3589 | // Add entry to dictionary. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3590 | static void AddEntry( |
| 3591 | Handle<Derived> dictionary, |
| 3592 | Key key, |
| 3593 | Handle<Object> value, |
| 3594 | PropertyDetails details, |
| 3595 | uint32_t hash); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3596 | |
| 3597 | // Generate new enumeration indices to avoid enumeration index overflow. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3598 | // Returns iteration indices array for the |dictionary|. |
| 3599 | static Handle<FixedArray> GenerateNewEnumerationIndices( |
| 3600 | Handle<Derived> dictionary); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3601 | static const int kMaxNumberKeyIndex = DerivedHashTable::kPrefixStartIndex; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3602 | static const int kNextEnumerationIndexIndex = kMaxNumberKeyIndex + 1; |
| 3603 | }; |
| 3604 | |
| 3605 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3606 | template <typename Derived, typename Shape> |
| 3607 | class NameDictionaryBase : public Dictionary<Derived, Shape, Handle<Name> > { |
| 3608 | typedef Dictionary<Derived, Shape, Handle<Name> > DerivedDictionary; |
| 3609 | |
| 3610 | public: |
| 3611 | // Find entry for key, otherwise return kNotFound. Optimized version of |
| 3612 | // HashTable::FindEntry. |
| 3613 | int FindEntry(Handle<Name> key); |
| 3614 | }; |
| 3615 | |
| 3616 | |
| 3617 | template <typename Key> |
| 3618 | class BaseDictionaryShape : public BaseShape<Key> { |
| 3619 | public: |
| 3620 | template <typename Dictionary> |
| 3621 | static inline PropertyDetails DetailsAt(Dictionary* dict, int entry) { |
| 3622 | STATIC_ASSERT(Dictionary::kEntrySize == 3); |
| 3623 | DCHECK(entry >= 0); // Not found is -1, which is not caught by get(). |
| 3624 | return PropertyDetails( |
| 3625 | Smi::cast(dict->get(Dictionary::EntryToIndex(entry) + 2))); |
| 3626 | } |
| 3627 | |
| 3628 | template <typename Dictionary> |
| 3629 | static inline void DetailsAtPut(Dictionary* dict, int entry, |
| 3630 | PropertyDetails value) { |
| 3631 | STATIC_ASSERT(Dictionary::kEntrySize == 3); |
| 3632 | dict->set(Dictionary::EntryToIndex(entry) + 2, value.AsSmi()); |
| 3633 | } |
| 3634 | |
| 3635 | template <typename Dictionary> |
| 3636 | static bool IsDeleted(Dictionary* dict, int entry) { |
| 3637 | return false; |
| 3638 | } |
| 3639 | |
| 3640 | template <typename Dictionary> |
| 3641 | static inline void SetEntry(Dictionary* dict, int entry, Handle<Object> key, |
| 3642 | Handle<Object> value, PropertyDetails details); |
| 3643 | }; |
| 3644 | |
| 3645 | |
| 3646 | class NameDictionaryShape : public BaseDictionaryShape<Handle<Name> > { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3647 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3648 | static inline bool IsMatch(Handle<Name> key, Object* other); |
| 3649 | static inline uint32_t Hash(Handle<Name> key); |
| 3650 | static inline uint32_t HashForObject(Handle<Name> key, Object* object); |
| 3651 | static inline Handle<Object> AsHandle(Isolate* isolate, Handle<Name> key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3652 | static const int kPrefixSize = 2; |
| 3653 | static const int kEntrySize = 3; |
| 3654 | static const bool kIsEnumerable = true; |
| 3655 | }; |
| 3656 | |
| 3657 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3658 | class NameDictionary |
| 3659 | : public NameDictionaryBase<NameDictionary, NameDictionaryShape> { |
| 3660 | typedef NameDictionaryBase<NameDictionary, NameDictionaryShape> |
| 3661 | DerivedDictionary; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3662 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3663 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3664 | DECLARE_CAST(NameDictionary) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3665 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3666 | inline static Handle<FixedArray> DoGenerateNewEnumerationIndices( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3667 | Handle<NameDictionary> dictionary); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3668 | }; |
| 3669 | |
| 3670 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3671 | class GlobalDictionaryShape : public NameDictionaryShape { |
| 3672 | public: |
| 3673 | static const int kEntrySize = 2; // Overrides NameDictionaryShape::kEntrySize |
| 3674 | |
| 3675 | template <typename Dictionary> |
| 3676 | static inline PropertyDetails DetailsAt(Dictionary* dict, int entry); |
| 3677 | |
| 3678 | template <typename Dictionary> |
| 3679 | static inline void DetailsAtPut(Dictionary* dict, int entry, |
| 3680 | PropertyDetails value); |
| 3681 | |
| 3682 | template <typename Dictionary> |
| 3683 | static bool IsDeleted(Dictionary* dict, int entry); |
| 3684 | |
| 3685 | template <typename Dictionary> |
| 3686 | static inline void SetEntry(Dictionary* dict, int entry, Handle<Object> key, |
| 3687 | Handle<Object> value, PropertyDetails details); |
| 3688 | }; |
| 3689 | |
| 3690 | |
| 3691 | class GlobalDictionary |
| 3692 | : public NameDictionaryBase<GlobalDictionary, GlobalDictionaryShape> { |
| 3693 | public: |
| 3694 | DECLARE_CAST(GlobalDictionary) |
| 3695 | }; |
| 3696 | |
| 3697 | |
| 3698 | class NumberDictionaryShape : public BaseDictionaryShape<uint32_t> { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3699 | public: |
| 3700 | static inline bool IsMatch(uint32_t key, Object* other); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3701 | static inline Handle<Object> AsHandle(Isolate* isolate, uint32_t key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3702 | static const int kEntrySize = 3; |
| 3703 | static const bool kIsEnumerable = false; |
| 3704 | }; |
| 3705 | |
| 3706 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3707 | class SeededNumberDictionaryShape : public NumberDictionaryShape { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3708 | public: |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3709 | static const bool UsesSeed = true; |
| 3710 | static const int kPrefixSize = 2; |
| 3711 | |
| 3712 | static inline uint32_t SeededHash(uint32_t key, uint32_t seed); |
| 3713 | static inline uint32_t SeededHashForObject(uint32_t key, |
| 3714 | uint32_t seed, |
| 3715 | Object* object); |
| 3716 | }; |
| 3717 | |
| 3718 | |
| 3719 | class UnseededNumberDictionaryShape : public NumberDictionaryShape { |
| 3720 | public: |
| 3721 | static const int kPrefixSize = 0; |
| 3722 | |
| 3723 | static inline uint32_t Hash(uint32_t key); |
| 3724 | static inline uint32_t HashForObject(uint32_t key, Object* object); |
| 3725 | }; |
| 3726 | |
| 3727 | |
| 3728 | class SeededNumberDictionary |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3729 | : public Dictionary<SeededNumberDictionary, |
| 3730 | SeededNumberDictionaryShape, |
| 3731 | uint32_t> { |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3732 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3733 | DECLARE_CAST(SeededNumberDictionary) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3734 | |
| 3735 | // Type specific at put (default NONE attributes is used when adding). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3736 | MUST_USE_RESULT static Handle<SeededNumberDictionary> AtNumberPut( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3737 | Handle<SeededNumberDictionary> dictionary, uint32_t key, |
| 3738 | Handle<Object> value, bool used_as_prototype); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3739 | MUST_USE_RESULT static Handle<SeededNumberDictionary> AddNumberEntry( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3740 | Handle<SeededNumberDictionary> dictionary, uint32_t key, |
| 3741 | Handle<Object> value, PropertyDetails details, bool used_as_prototype); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3742 | |
| 3743 | // Set an existing entry or add a new one if needed. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3744 | // Return the updated dictionary. |
| 3745 | MUST_USE_RESULT static Handle<SeededNumberDictionary> Set( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3746 | Handle<SeededNumberDictionary> dictionary, uint32_t key, |
| 3747 | Handle<Object> value, PropertyDetails details, bool used_as_prototype); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3748 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3749 | void UpdateMaxNumberKey(uint32_t key, bool used_as_prototype); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3750 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 3751 | // Returns true if the dictionary contains any elements that are non-writable, |
| 3752 | // non-configurable, non-enumerable, or have getters/setters. |
| 3753 | bool HasComplexElements(); |
| 3754 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3755 | // If slow elements are required we will never go back to fast-case |
| 3756 | // for the elements kept in this dictionary. We require slow |
| 3757 | // elements if an element has been added at an index larger than |
| 3758 | // kRequiresSlowElementsLimit or set_requires_slow_elements() has been called |
| 3759 | // when defining a getter or setter with a number key. |
| 3760 | inline bool requires_slow_elements(); |
| 3761 | inline void set_requires_slow_elements(); |
| 3762 | |
| 3763 | // Get the value of the max number key that has been added to this |
| 3764 | // dictionary. max_number_key can only be called if |
| 3765 | // requires_slow_elements returns false. |
| 3766 | inline uint32_t max_number_key(); |
| 3767 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3768 | // Bit masks. |
| 3769 | static const int kRequiresSlowElementsMask = 1; |
| 3770 | static const int kRequiresSlowElementsTagSize = 1; |
| 3771 | static const uint32_t kRequiresSlowElementsLimit = (1 << 29) - 1; |
| 3772 | }; |
| 3773 | |
| 3774 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3775 | class UnseededNumberDictionary |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3776 | : public Dictionary<UnseededNumberDictionary, |
| 3777 | UnseededNumberDictionaryShape, |
| 3778 | uint32_t> { |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3779 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3780 | DECLARE_CAST(UnseededNumberDictionary) |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3781 | |
| 3782 | // Type specific at put (default NONE attributes is used when adding). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3783 | MUST_USE_RESULT static Handle<UnseededNumberDictionary> AtNumberPut( |
| 3784 | Handle<UnseededNumberDictionary> dictionary, |
| 3785 | uint32_t key, |
| 3786 | Handle<Object> value); |
| 3787 | MUST_USE_RESULT static Handle<UnseededNumberDictionary> AddNumberEntry( |
| 3788 | Handle<UnseededNumberDictionary> dictionary, |
| 3789 | uint32_t key, |
| 3790 | Handle<Object> value); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3791 | |
| 3792 | // Set an existing entry or add a new one if needed. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3793 | // Return the updated dictionary. |
| 3794 | MUST_USE_RESULT static Handle<UnseededNumberDictionary> Set( |
| 3795 | Handle<UnseededNumberDictionary> dictionary, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3796 | uint32_t key, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3797 | Handle<Object> value); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3798 | }; |
| 3799 | |
| 3800 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3801 | class ObjectHashTableShape : public BaseShape<Handle<Object> > { |
Ben Murdoch | 2b4ba11 | 2012-01-20 14:57:15 +0000 | [diff] [blame] | 3802 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3803 | static inline bool IsMatch(Handle<Object> key, Object* other); |
| 3804 | static inline uint32_t Hash(Handle<Object> key); |
| 3805 | static inline uint32_t HashForObject(Handle<Object> key, Object* object); |
| 3806 | static inline Handle<Object> AsHandle(Isolate* isolate, Handle<Object> key); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 3807 | static const int kPrefixSize = 0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3808 | static const int kEntrySize = 2; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3809 | }; |
| 3810 | |
| 3811 | |
| 3812 | // ObjectHashTable maps keys that are arbitrary objects to object values by |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3813 | // using the identity hash of the key for hashing purposes. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3814 | class ObjectHashTable: public HashTable<ObjectHashTable, |
| 3815 | ObjectHashTableShape, |
| 3816 | Handle<Object> > { |
| 3817 | typedef HashTable< |
| 3818 | ObjectHashTable, ObjectHashTableShape, Handle<Object> > DerivedHashTable; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3819 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3820 | DECLARE_CAST(ObjectHashTable) |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3821 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3822 | // Attempt to shrink hash table after removal of key. |
| 3823 | MUST_USE_RESULT static inline Handle<ObjectHashTable> Shrink( |
| 3824 | Handle<ObjectHashTable> table, |
| 3825 | Handle<Object> key); |
| 3826 | |
| 3827 | // 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] | 3828 | // returned in case the key is not present. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3829 | Object* Lookup(Handle<Object> key); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3830 | Object* Lookup(Handle<Object> key, int32_t hash); |
| 3831 | Object* Lookup(Isolate* isolate, Handle<Object> key, int32_t hash); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3832 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3833 | // Adds (or overwrites) the value associated with the given key. |
| 3834 | static Handle<ObjectHashTable> Put(Handle<ObjectHashTable> table, |
| 3835 | Handle<Object> key, |
| 3836 | Handle<Object> value); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3837 | static Handle<ObjectHashTable> Put(Handle<ObjectHashTable> table, |
| 3838 | Handle<Object> key, Handle<Object> value, |
| 3839 | int32_t hash); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3840 | |
| 3841 | // Returns an ObjectHashTable (possibly |table|) where |key| has been removed. |
| 3842 | static Handle<ObjectHashTable> Remove(Handle<ObjectHashTable> table, |
| 3843 | Handle<Object> key, |
| 3844 | bool* was_present); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3845 | static Handle<ObjectHashTable> Remove(Handle<ObjectHashTable> table, |
| 3846 | Handle<Object> key, bool* was_present, |
| 3847 | int32_t hash); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3848 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3849 | protected: |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3850 | friend class MarkCompactCollector; |
| 3851 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3852 | void AddEntry(int entry, Object* key, Object* value); |
| 3853 | void RemoveEntry(int entry); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3854 | |
| 3855 | // Returns the index to the value of an entry. |
| 3856 | static inline int EntryToValueIndex(int entry) { |
| 3857 | return EntryToIndex(entry) + 1; |
| 3858 | } |
| 3859 | }; |
| 3860 | |
| 3861 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3862 | // OrderedHashTable is a HashTable with Object keys that preserves |
| 3863 | // insertion order. There are Map and Set interfaces (OrderedHashMap |
| 3864 | // and OrderedHashTable, below). It is meant to be used by JSMap/JSSet. |
| 3865 | // |
| 3866 | // Only Object* keys are supported, with Object::SameValueZero() used as the |
| 3867 | // equality operator and Object::GetHash() for the hash function. |
| 3868 | // |
| 3869 | // Based on the "Deterministic Hash Table" as described by Jason Orendorff at |
| 3870 | // https://wiki.mozilla.org/User:Jorend/Deterministic_hash_tables |
| 3871 | // Originally attributed to Tyler Close. |
| 3872 | // |
| 3873 | // Memory layout: |
| 3874 | // [0]: bucket count |
| 3875 | // [1]: element count |
| 3876 | // [2]: deleted element count |
| 3877 | // [3..(3 + NumberOfBuckets() - 1)]: "hash table", where each item is an |
| 3878 | // offset into the data table (see below) where the |
| 3879 | // first item in this bucket is stored. |
| 3880 | // [3 + NumberOfBuckets()..length]: "data table", an array of length |
| 3881 | // Capacity() * kEntrySize, where the first entrysize |
| 3882 | // items are handled by the derived class and the |
| 3883 | // item at kChainOffset is another entry into the |
| 3884 | // data table indicating the next entry in this hash |
| 3885 | // bucket. |
| 3886 | // |
| 3887 | // When we transition the table to a new version we obsolete it and reuse parts |
| 3888 | // of the memory to store information how to transition an iterator to the new |
| 3889 | // table: |
| 3890 | // |
| 3891 | // Memory layout for obsolete table: |
| 3892 | // [0]: bucket count |
| 3893 | // [1]: Next newer table |
| 3894 | // [2]: Number of removed holes or -1 when the table was cleared. |
| 3895 | // [3..(3 + NumberOfRemovedHoles() - 1)]: The indexes of the removed holes. |
| 3896 | // [3 + NumberOfRemovedHoles()..length]: Not used |
| 3897 | // |
| 3898 | template<class Derived, class Iterator, int entrysize> |
| 3899 | class OrderedHashTable: public FixedArray { |
| 3900 | public: |
| 3901 | // Returns an OrderedHashTable with a capacity of at least |capacity|. |
| 3902 | static Handle<Derived> Allocate( |
| 3903 | Isolate* isolate, int capacity, PretenureFlag pretenure = NOT_TENURED); |
| 3904 | |
| 3905 | // Returns an OrderedHashTable (possibly |table|) with enough space |
| 3906 | // to add at least one new element. |
| 3907 | static Handle<Derived> EnsureGrowable(Handle<Derived> table); |
| 3908 | |
| 3909 | // Returns an OrderedHashTable (possibly |table|) that's shrunken |
| 3910 | // if possible. |
| 3911 | static Handle<Derived> Shrink(Handle<Derived> table); |
| 3912 | |
| 3913 | // Returns a new empty OrderedHashTable and records the clearing so that |
| 3914 | // exisiting iterators can be updated. |
| 3915 | static Handle<Derived> Clear(Handle<Derived> table); |
| 3916 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3917 | // Returns a true if the OrderedHashTable contains the key |
| 3918 | static bool HasKey(Handle<Derived> table, Handle<Object> key); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3919 | |
| 3920 | int NumberOfElements() { |
| 3921 | return Smi::cast(get(kNumberOfElementsIndex))->value(); |
| 3922 | } |
| 3923 | |
| 3924 | int NumberOfDeletedElements() { |
| 3925 | return Smi::cast(get(kNumberOfDeletedElementsIndex))->value(); |
| 3926 | } |
| 3927 | |
| 3928 | int UsedCapacity() { return NumberOfElements() + NumberOfDeletedElements(); } |
| 3929 | |
| 3930 | int NumberOfBuckets() { |
| 3931 | return Smi::cast(get(kNumberOfBucketsIndex))->value(); |
| 3932 | } |
| 3933 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3934 | // Returns an index into |this| for the given entry. |
| 3935 | int EntryToIndex(int entry) { |
| 3936 | return kHashTableStartIndex + NumberOfBuckets() + (entry * kEntrySize); |
| 3937 | } |
| 3938 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3939 | int HashToBucket(int hash) { return hash & (NumberOfBuckets() - 1); } |
| 3940 | |
| 3941 | int HashToEntry(int hash) { |
| 3942 | int bucket = HashToBucket(hash); |
| 3943 | Object* entry = this->get(kHashTableStartIndex + bucket); |
| 3944 | return Smi::cast(entry)->value(); |
| 3945 | } |
| 3946 | |
| 3947 | int KeyToFirstEntry(Object* key) { |
| 3948 | Object* hash = key->GetHash(); |
| 3949 | // If the object does not have an identity hash, it was never used as a key |
| 3950 | if (hash->IsUndefined()) return kNotFound; |
| 3951 | return HashToEntry(Smi::cast(hash)->value()); |
| 3952 | } |
| 3953 | |
| 3954 | int NextChainEntry(int entry) { |
| 3955 | Object* next_entry = get(EntryToIndex(entry) + kChainOffset); |
| 3956 | return Smi::cast(next_entry)->value(); |
| 3957 | } |
| 3958 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3959 | Object* KeyAt(int entry) { return get(EntryToIndex(entry)); } |
| 3960 | |
| 3961 | bool IsObsolete() { |
| 3962 | return !get(kNextTableIndex)->IsSmi(); |
| 3963 | } |
| 3964 | |
| 3965 | // The next newer table. This is only valid if the table is obsolete. |
| 3966 | Derived* NextTable() { |
| 3967 | return Derived::cast(get(kNextTableIndex)); |
| 3968 | } |
| 3969 | |
| 3970 | // When the table is obsolete we store the indexes of the removed holes. |
| 3971 | int RemovedIndexAt(int index) { |
| 3972 | return Smi::cast(get(kRemovedHolesIndex + index))->value(); |
| 3973 | } |
| 3974 | |
| 3975 | static const int kNotFound = -1; |
| 3976 | static const int kMinCapacity = 4; |
| 3977 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3978 | static const int kNumberOfBucketsIndex = 0; |
| 3979 | static const int kNumberOfElementsIndex = kNumberOfBucketsIndex + 1; |
| 3980 | static const int kNumberOfDeletedElementsIndex = kNumberOfElementsIndex + 1; |
| 3981 | static const int kHashTableStartIndex = kNumberOfDeletedElementsIndex + 1; |
| 3982 | static const int kNextTableIndex = kNumberOfElementsIndex; |
| 3983 | |
| 3984 | static const int kNumberOfBucketsOffset = |
| 3985 | kHeaderSize + kNumberOfBucketsIndex * kPointerSize; |
| 3986 | static const int kNumberOfElementsOffset = |
| 3987 | kHeaderSize + kNumberOfElementsIndex * kPointerSize; |
| 3988 | static const int kNumberOfDeletedElementsOffset = |
| 3989 | kHeaderSize + kNumberOfDeletedElementsIndex * kPointerSize; |
| 3990 | static const int kHashTableStartOffset = |
| 3991 | kHeaderSize + kHashTableStartIndex * kPointerSize; |
| 3992 | static const int kNextTableOffset = |
| 3993 | kHeaderSize + kNextTableIndex * kPointerSize; |
| 3994 | |
| 3995 | static const int kEntrySize = entrysize + 1; |
| 3996 | static const int kChainOffset = entrysize; |
| 3997 | |
| 3998 | static const int kLoadFactor = 2; |
| 3999 | |
| 4000 | // NumberOfDeletedElements is set to kClearedTableSentinel when |
| 4001 | // the table is cleared, which allows iterator transitions to |
| 4002 | // optimize that case. |
| 4003 | static const int kClearedTableSentinel = -1; |
| 4004 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4005 | protected: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4006 | static Handle<Derived> Rehash(Handle<Derived> table, int new_capacity); |
| 4007 | |
| 4008 | void SetNumberOfBuckets(int num) { |
| 4009 | set(kNumberOfBucketsIndex, Smi::FromInt(num)); |
| 4010 | } |
| 4011 | |
| 4012 | void SetNumberOfElements(int num) { |
| 4013 | set(kNumberOfElementsIndex, Smi::FromInt(num)); |
| 4014 | } |
| 4015 | |
| 4016 | void SetNumberOfDeletedElements(int num) { |
| 4017 | set(kNumberOfDeletedElementsIndex, Smi::FromInt(num)); |
| 4018 | } |
| 4019 | |
| 4020 | int Capacity() { |
| 4021 | return NumberOfBuckets() * kLoadFactor; |
| 4022 | } |
| 4023 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4024 | void SetNextTable(Derived* next_table) { |
| 4025 | set(kNextTableIndex, next_table); |
| 4026 | } |
| 4027 | |
| 4028 | void SetRemovedIndexAt(int index, int removed_index) { |
| 4029 | return set(kRemovedHolesIndex + index, Smi::FromInt(removed_index)); |
| 4030 | } |
| 4031 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4032 | static const int kRemovedHolesIndex = kHashTableStartIndex; |
| 4033 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4034 | static const int kMaxCapacity = |
| 4035 | (FixedArray::kMaxLength - kHashTableStartIndex) |
| 4036 | / (1 + (kEntrySize * kLoadFactor)); |
| 4037 | }; |
| 4038 | |
| 4039 | |
| 4040 | class JSSetIterator; |
| 4041 | |
| 4042 | |
| 4043 | class OrderedHashSet: public OrderedHashTable< |
| 4044 | OrderedHashSet, JSSetIterator, 1> { |
| 4045 | public: |
| 4046 | DECLARE_CAST(OrderedHashSet) |
| 4047 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4048 | static Handle<OrderedHashSet> Add(Handle<OrderedHashSet> table, |
| 4049 | Handle<Object> value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4050 | }; |
| 4051 | |
| 4052 | |
| 4053 | class JSMapIterator; |
| 4054 | |
| 4055 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4056 | class OrderedHashMap |
| 4057 | : public OrderedHashTable<OrderedHashMap, JSMapIterator, 2> { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4058 | public: |
| 4059 | DECLARE_CAST(OrderedHashMap) |
| 4060 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4061 | inline Object* ValueAt(int entry); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4062 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4063 | static const int kValueOffset = 1; |
| 4064 | }; |
| 4065 | |
| 4066 | |
| 4067 | template <int entrysize> |
| 4068 | class WeakHashTableShape : public BaseShape<Handle<Object> > { |
| 4069 | public: |
| 4070 | static inline bool IsMatch(Handle<Object> key, Object* other); |
| 4071 | static inline uint32_t Hash(Handle<Object> key); |
| 4072 | static inline uint32_t HashForObject(Handle<Object> key, Object* object); |
| 4073 | static inline Handle<Object> AsHandle(Isolate* isolate, Handle<Object> key); |
| 4074 | static const int kPrefixSize = 0; |
| 4075 | static const int kEntrySize = entrysize; |
| 4076 | }; |
| 4077 | |
| 4078 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4079 | // WeakHashTable maps keys that are arbitrary heap objects to heap object |
| 4080 | // values. The table wraps the keys in weak cells and store values directly. |
| 4081 | // Thus it references keys weakly and values strongly. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4082 | class WeakHashTable: public HashTable<WeakHashTable, |
| 4083 | WeakHashTableShape<2>, |
| 4084 | Handle<Object> > { |
| 4085 | typedef HashTable< |
| 4086 | WeakHashTable, WeakHashTableShape<2>, Handle<Object> > DerivedHashTable; |
| 4087 | public: |
| 4088 | DECLARE_CAST(WeakHashTable) |
| 4089 | |
| 4090 | // Looks up the value associated with the given key. The hole value is |
| 4091 | // returned in case the key is not present. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4092 | Object* Lookup(Handle<HeapObject> key); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4093 | |
| 4094 | // Adds (or overwrites) the value associated with the given key. Mapping a |
| 4095 | // key to the hole value causes removal of the whole entry. |
| 4096 | MUST_USE_RESULT static Handle<WeakHashTable> Put(Handle<WeakHashTable> table, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4097 | Handle<HeapObject> key, |
| 4098 | Handle<HeapObject> value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4099 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4100 | static Handle<FixedArray> GetValues(Handle<WeakHashTable> table); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4101 | |
| 4102 | private: |
| 4103 | friend class MarkCompactCollector; |
| 4104 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4105 | void AddEntry(int entry, Handle<WeakCell> key, Handle<HeapObject> value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4106 | |
| 4107 | // Returns the index to the value of an entry. |
| 4108 | static inline int EntryToValueIndex(int entry) { |
| 4109 | return EntryToIndex(entry) + 1; |
| 4110 | } |
| 4111 | }; |
| 4112 | |
| 4113 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4114 | // ScopeInfo represents information about different scopes of a source |
| 4115 | // program and the allocation of the scope's variables. Scope information |
| 4116 | // is stored in a compressed form in ScopeInfo objects and is used |
| 4117 | // at runtime (stack dumps, deoptimization, etc.). |
| 4118 | |
| 4119 | // This object provides quick access to scope info details for runtime |
| 4120 | // routines. |
| 4121 | class ScopeInfo : public FixedArray { |
| 4122 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4123 | DECLARE_CAST(ScopeInfo) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4124 | |
| 4125 | // Return the type of this scope. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4126 | ScopeType scope_type(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4127 | |
| 4128 | // Does this scope call eval? |
| 4129 | bool CallsEval(); |
| 4130 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4131 | // Return the language mode of this scope. |
| 4132 | LanguageMode language_mode(); |
| 4133 | |
| 4134 | // True if this scope is a (var) declaration scope. |
| 4135 | bool is_declaration_scope(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4136 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4137 | // Does this scope make a sloppy eval call? |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4138 | bool CallsSloppyEval() { return CallsEval() && is_sloppy(language_mode()); } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4139 | |
| 4140 | // Return the total number of locals allocated on the stack and in the |
| 4141 | // context. This includes the parameters that are allocated in the context. |
| 4142 | int LocalCount(); |
| 4143 | |
| 4144 | // Return the number of stack slots for code. This number consists of two |
| 4145 | // parts: |
| 4146 | // 1. One stack slot per stack allocated local. |
| 4147 | // 2. One stack slot for the function name if it is stack allocated. |
| 4148 | int StackSlotCount(); |
| 4149 | |
| 4150 | // Return the number of context slots for code if a context is allocated. This |
| 4151 | // number consists of three parts: |
| 4152 | // 1. Size of fixed header for every context: Context::MIN_CONTEXT_SLOTS |
| 4153 | // 2. One context slot per context allocated local. |
| 4154 | // 3. One context slot for the function name if it is context allocated. |
| 4155 | // Parameters allocated in the context count as context allocated locals. If |
| 4156 | // no contexts are allocated for this scope ContextLength returns 0. |
| 4157 | int ContextLength(); |
| 4158 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4159 | // Does this scope declare a "this" binding? |
| 4160 | bool HasReceiver(); |
| 4161 | |
| 4162 | // Does this scope declare a "this" binding, and the "this" binding is stack- |
| 4163 | // or context-allocated? |
| 4164 | bool HasAllocatedReceiver(); |
| 4165 | |
| 4166 | // Does this scope declare a "new.target" binding? |
| 4167 | bool HasNewTarget(); |
| 4168 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4169 | // Is this scope the scope of a named function expression? |
| 4170 | bool HasFunctionName(); |
| 4171 | |
| 4172 | // Return if this has context allocated locals. |
| 4173 | bool HasHeapAllocatedLocals(); |
| 4174 | |
| 4175 | // Return if contexts are allocated for this scope. |
| 4176 | bool HasContext(); |
| 4177 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4178 | // Return if this is a function scope with "use asm". |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4179 | inline bool IsAsmModule(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4180 | |
| 4181 | // Return if this is a nested function within an asm module scope. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4182 | inline bool IsAsmFunction(); |
| 4183 | |
| 4184 | inline bool HasSimpleParameters(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4185 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4186 | // Return the function_name if present. |
| 4187 | String* FunctionName(); |
| 4188 | |
| 4189 | // Return the name of the given parameter. |
| 4190 | String* ParameterName(int var); |
| 4191 | |
| 4192 | // Return the name of the given local. |
| 4193 | String* LocalName(int var); |
| 4194 | |
| 4195 | // Return the name of the given stack local. |
| 4196 | String* StackLocalName(int var); |
| 4197 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4198 | // Return the name of the given stack local. |
| 4199 | int StackLocalIndex(int var); |
| 4200 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4201 | // Return the name of the given context local. |
| 4202 | String* ContextLocalName(int var); |
| 4203 | |
| 4204 | // Return the mode of the given context local. |
| 4205 | VariableMode ContextLocalMode(int var); |
| 4206 | |
| 4207 | // Return the initialization flag of the given context local. |
| 4208 | InitializationFlag ContextLocalInitFlag(int var); |
| 4209 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4210 | // Return the initialization flag of the given context local. |
| 4211 | MaybeAssignedFlag ContextLocalMaybeAssignedFlag(int var); |
| 4212 | |
| 4213 | // Return true if this local was introduced by the compiler, and should not be |
| 4214 | // exposed to the user in a debugger. |
| 4215 | bool LocalIsSynthetic(int var); |
| 4216 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4217 | // Lookup support for serialized scope info. Returns the |
| 4218 | // 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] | 4219 | // present; otherwise returns a value < 0. The name must be an internalized |
| 4220 | // string. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4221 | int StackSlotIndex(String* name); |
| 4222 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4223 | // Lookup support for serialized scope info. Returns the local context slot |
| 4224 | // index for a given slot name if the slot is present; otherwise |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4225 | // returns a value < 0. The name must be an internalized string. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4226 | // If the slot is present and mode != NULL, sets *mode to the corresponding |
| 4227 | // mode for that variable. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4228 | static int ContextSlotIndex(Handle<ScopeInfo> scope_info, Handle<String> name, |
| 4229 | VariableMode* mode, InitializationFlag* init_flag, |
| 4230 | MaybeAssignedFlag* maybe_assigned_flag); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4231 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4232 | // Similar to ContextSlotIndex() but this method searches only among |
| 4233 | // global slots of the serialized scope info. Returns the context slot index |
| 4234 | // for a given slot name if the slot is present; otherwise returns a |
| 4235 | // value < 0. The name must be an internalized string. If the slot is present |
| 4236 | // and mode != NULL, sets *mode to the corresponding mode for that variable. |
| 4237 | static int ContextGlobalSlotIndex(Handle<ScopeInfo> scope_info, |
| 4238 | Handle<String> name, VariableMode* mode, |
| 4239 | InitializationFlag* init_flag, |
| 4240 | MaybeAssignedFlag* maybe_assigned_flag); |
| 4241 | |
| 4242 | // Lookup the name of a certain context slot by its index. |
| 4243 | String* ContextSlotName(int slot_index); |
| 4244 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4245 | // Lookup support for serialized scope info. Returns the |
| 4246 | // parameter index for a given parameter name if the parameter is present; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4247 | // otherwise returns a value < 0. The name must be an internalized string. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4248 | int ParameterIndex(String* name); |
| 4249 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4250 | // Lookup support for serialized scope info. Returns the function context |
| 4251 | // slot index if the function name is present and context-allocated (named |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4252 | // function expressions, only), otherwise returns a value < 0. The name |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4253 | // must be an internalized string. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4254 | int FunctionContextSlotIndex(String* name, VariableMode* mode); |
| 4255 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4256 | // Lookup support for serialized scope info. Returns the receiver context |
| 4257 | // slot index if scope has a "this" binding, and the binding is |
| 4258 | // context-allocated. Otherwise returns a value < 0. |
| 4259 | int ReceiverContextSlotIndex(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4260 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4261 | FunctionKind function_kind(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4262 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4263 | static Handle<ScopeInfo> Create(Isolate* isolate, Zone* zone, Scope* scope); |
| 4264 | static Handle<ScopeInfo> CreateGlobalThisBinding(Isolate* isolate); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4265 | |
| 4266 | // Serializes empty scope info. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4267 | static ScopeInfo* Empty(Isolate* isolate); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4268 | |
| 4269 | #ifdef DEBUG |
| 4270 | void Print(); |
| 4271 | #endif |
| 4272 | |
| 4273 | // The layout of the static part of a ScopeInfo is as follows. Each entry is |
| 4274 | // numeric and occupies one array slot. |
| 4275 | // 1. A set of properties of the scope |
| 4276 | // 2. The number of parameters. This only applies to function scopes. For |
| 4277 | // non-function scopes this is 0. |
| 4278 | // 3. The number of non-parameter variables allocated on the stack. |
| 4279 | // 4. The number of non-parameter and parameter variables allocated in the |
| 4280 | // context. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4281 | #define FOR_EACH_SCOPE_INFO_NUMERIC_FIELD(V) \ |
| 4282 | V(Flags) \ |
| 4283 | V(ParameterCount) \ |
| 4284 | V(StackLocalCount) \ |
| 4285 | V(ContextLocalCount) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4286 | V(ContextGlobalCount) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4287 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4288 | #define FIELD_ACCESSORS(name) \ |
| 4289 | inline void Set##name(int value); \ |
| 4290 | inline int name(); |
| 4291 | FOR_EACH_SCOPE_INFO_NUMERIC_FIELD(FIELD_ACCESSORS) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4292 | #undef FIELD_ACCESSORS |
| 4293 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4294 | enum { |
| 4295 | #define DECL_INDEX(name) k##name, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4296 | FOR_EACH_SCOPE_INFO_NUMERIC_FIELD(DECL_INDEX) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4297 | #undef DECL_INDEX |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4298 | kVariablePartIndex |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4299 | }; |
| 4300 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4301 | private: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4302 | // The layout of the variable part of a ScopeInfo is as follows: |
| 4303 | // 1. ParameterEntries: |
| 4304 | // This part stores the names of the parameters for function scopes. One |
| 4305 | // slot is used per parameter, so in total this part occupies |
| 4306 | // ParameterCount() slots in the array. For other scopes than function |
| 4307 | // scopes ParameterCount() is 0. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4308 | // 2. StackLocalFirstSlot: |
| 4309 | // Index of a first stack slot for stack local. Stack locals belonging to |
| 4310 | // this scope are located on a stack at slots starting from this index. |
| 4311 | // 3. StackLocalEntries: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4312 | // Contains the names of local variables that are allocated on the stack, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4313 | // in increasing order of the stack slot index. First local variable has |
| 4314 | // a stack slot index defined in StackLocalFirstSlot (point 2 above). |
| 4315 | // One slot is used per stack local, so in total this part occupies |
| 4316 | // StackLocalCount() slots in the array. |
| 4317 | // 4. ContextLocalNameEntries: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4318 | // Contains the names of local variables and parameters that are allocated |
| 4319 | // in the context. They are stored in increasing order of the context slot |
| 4320 | // index starting with Context::MIN_CONTEXT_SLOTS. One slot is used per |
| 4321 | // context local, so in total this part occupies ContextLocalCount() slots |
| 4322 | // in the array. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4323 | // 5. ContextLocalInfoEntries: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4324 | // Contains the variable modes and initialization flags corresponding to |
| 4325 | // the context locals in ContextLocalNameEntries. One slot is used per |
| 4326 | // context local, so in total this part occupies ContextLocalCount() |
| 4327 | // slots in the array. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4328 | // 6. RecieverEntryIndex: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4329 | // If the scope binds a "this" value, one slot is reserved to hold the |
| 4330 | // context or stack slot index for the variable. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4331 | // 7. FunctionNameEntryIndex: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4332 | // If the scope belongs to a named function expression this part contains |
| 4333 | // information about the function variable. It always occupies two array |
| 4334 | // slots: a. The name of the function variable. |
| 4335 | // b. The context or stack slot index for the variable. |
| 4336 | int ParameterEntriesIndex(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4337 | int StackLocalFirstSlotIndex(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4338 | int StackLocalEntriesIndex(); |
| 4339 | int ContextLocalNameEntriesIndex(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4340 | int ContextGlobalNameEntriesIndex(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4341 | int ContextLocalInfoEntriesIndex(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4342 | int ContextGlobalInfoEntriesIndex(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4343 | int ReceiverEntryIndex(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4344 | int FunctionNameEntryIndex(); |
| 4345 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4346 | int Lookup(Handle<String> name, int start, int end, VariableMode* mode, |
| 4347 | VariableLocation* location, InitializationFlag* init_flag, |
| 4348 | MaybeAssignedFlag* maybe_assigned_flag); |
| 4349 | |
| 4350 | // Used for the function name variable for named function expressions, and for |
| 4351 | // the receiver. |
| 4352 | enum VariableAllocationInfo { NONE, STACK, CONTEXT, UNUSED }; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4353 | |
| 4354 | // Properties of scopes. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 4355 | class ScopeTypeField : public BitField<ScopeType, 0, 4> {}; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4356 | class CallsEvalField : public BitField<bool, ScopeTypeField::kNext, 1> {}; |
| 4357 | STATIC_ASSERT(LANGUAGE_END == 3); |
| 4358 | class LanguageModeField |
| 4359 | : public BitField<LanguageMode, CallsEvalField::kNext, 2> {}; |
| 4360 | class DeclarationScopeField |
| 4361 | : public BitField<bool, LanguageModeField::kNext, 1> {}; |
| 4362 | class ReceiverVariableField |
| 4363 | : public BitField<VariableAllocationInfo, DeclarationScopeField::kNext, |
| 4364 | 2> {}; |
| 4365 | class HasNewTargetField |
| 4366 | : public BitField<bool, ReceiverVariableField::kNext, 1> {}; |
| 4367 | class FunctionVariableField |
| 4368 | : public BitField<VariableAllocationInfo, HasNewTargetField::kNext, 2> {}; |
| 4369 | class FunctionVariableMode |
| 4370 | : public BitField<VariableMode, FunctionVariableField::kNext, 3> {}; |
| 4371 | class AsmModuleField : public BitField<bool, FunctionVariableMode::kNext, 1> { |
| 4372 | }; |
| 4373 | class AsmFunctionField : public BitField<bool, AsmModuleField::kNext, 1> {}; |
| 4374 | class HasSimpleParametersField |
| 4375 | : public BitField<bool, AsmFunctionField::kNext, 1> {}; |
| 4376 | class FunctionKindField |
| 4377 | : public BitField<FunctionKind, HasSimpleParametersField::kNext, 8> {}; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4378 | |
| 4379 | // BitFields representing the encoded information for context locals in the |
| 4380 | // ContextLocalInfoEntries part. |
| 4381 | class ContextLocalMode: public BitField<VariableMode, 0, 3> {}; |
| 4382 | class ContextLocalInitFlag: public BitField<InitializationFlag, 3, 1> {}; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4383 | class ContextLocalMaybeAssignedFlag |
| 4384 | : public BitField<MaybeAssignedFlag, 4, 1> {}; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4385 | |
| 4386 | friend class ScopeIterator; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4387 | }; |
| 4388 | |
| 4389 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4390 | // The cache for maps used by normalized (dictionary mode) objects. |
| 4391 | // Such maps do not have property descriptors, so a typical program |
| 4392 | // needs very limited number of distinct normalized maps. |
| 4393 | class NormalizedMapCache: public FixedArray { |
| 4394 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4395 | static Handle<NormalizedMapCache> New(Isolate* isolate); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4396 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4397 | MUST_USE_RESULT MaybeHandle<Map> Get(Handle<Map> fast_map, |
| 4398 | PropertyNormalizationMode mode); |
| 4399 | void Set(Handle<Map> fast_map, Handle<Map> normalized_map); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4400 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4401 | void Clear(); |
| 4402 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4403 | DECLARE_CAST(NormalizedMapCache) |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4404 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4405 | static inline bool IsNormalizedMapCache(const HeapObject* obj); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4406 | |
| 4407 | DECLARE_VERIFIER(NormalizedMapCache) |
| 4408 | private: |
| 4409 | static const int kEntries = 64; |
| 4410 | |
| 4411 | static inline int GetIndex(Handle<Map> map); |
| 4412 | |
| 4413 | // The following declarations hide base class methods. |
| 4414 | Object* get(int index); |
| 4415 | void set(int index, Object* value); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4416 | }; |
| 4417 | |
| 4418 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4419 | // ByteArray represents fixed sized byte arrays. Used for the relocation info |
| 4420 | // that is attached to code objects. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 4421 | class ByteArray: public FixedArrayBase { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4422 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4423 | inline int Size(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4424 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4425 | // Setter and getter. |
| 4426 | inline byte get(int index); |
| 4427 | inline void set(int index, byte value); |
| 4428 | |
| 4429 | // Treat contents as an int array. |
| 4430 | inline int get_int(int index); |
| 4431 | |
| 4432 | static int SizeFor(int length) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4433 | return OBJECT_POINTER_ALIGN(kHeaderSize + length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4434 | } |
| 4435 | // We use byte arrays for free blocks in the heap. Given a desired size in |
| 4436 | // bytes that is a multiple of the word size and big enough to hold a byte |
| 4437 | // array, this function returns the number of elements a byte array should |
| 4438 | // have. |
| 4439 | static int LengthFor(int size_in_bytes) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4440 | DCHECK(IsAligned(size_in_bytes, kPointerSize)); |
| 4441 | DCHECK(size_in_bytes >= kHeaderSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4442 | return size_in_bytes - kHeaderSize; |
| 4443 | } |
| 4444 | |
| 4445 | // Returns data start address. |
| 4446 | inline Address GetDataStartAddress(); |
| 4447 | |
| 4448 | // Returns a pointer to the ByteArray object for a given data start address. |
| 4449 | static inline ByteArray* FromDataStartAddress(Address address); |
| 4450 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4451 | DECLARE_CAST(ByteArray) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4452 | |
| 4453 | // Dispatched behavior. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4454 | inline int ByteArraySize(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4455 | DECLARE_PRINTER(ByteArray) |
| 4456 | DECLARE_VERIFIER(ByteArray) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4457 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4458 | // Layout description. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4459 | static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4460 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4461 | // Maximal memory consumption for a single ByteArray. |
| 4462 | static const int kMaxSize = 512 * MB; |
| 4463 | // Maximal length of a single ByteArray. |
| 4464 | static const int kMaxLength = kMaxSize - kHeaderSize; |
| 4465 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4466 | private: |
| 4467 | DISALLOW_IMPLICIT_CONSTRUCTORS(ByteArray); |
| 4468 | }; |
| 4469 | |
| 4470 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4471 | // BytecodeArray represents a sequence of interpreter bytecodes. |
| 4472 | class BytecodeArray : public FixedArrayBase { |
| 4473 | public: |
| 4474 | static int SizeFor(int length) { |
| 4475 | return OBJECT_POINTER_ALIGN(kHeaderSize + length); |
| 4476 | } |
| 4477 | |
| 4478 | // Setter and getter |
| 4479 | inline byte get(int index); |
| 4480 | inline void set(int index, byte value); |
| 4481 | |
| 4482 | // Returns data start address. |
| 4483 | inline Address GetFirstBytecodeAddress(); |
| 4484 | |
| 4485 | // Accessors for frame size. |
| 4486 | inline int frame_size() const; |
| 4487 | inline void set_frame_size(int frame_size); |
| 4488 | |
| 4489 | // Accessor for register count (derived from frame_size). |
| 4490 | inline int register_count() const; |
| 4491 | |
| 4492 | // Accessors for parameter count (including implicit 'this' receiver). |
| 4493 | inline int parameter_count() const; |
| 4494 | inline void set_parameter_count(int number_of_parameters); |
| 4495 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4496 | // Accessors for profiling count. |
| 4497 | inline int interrupt_budget() const; |
| 4498 | inline void set_interrupt_budget(int interrupt_budget); |
| 4499 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4500 | // Accessors for the constant pool. |
| 4501 | DECL_ACCESSORS(constant_pool, FixedArray) |
| 4502 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4503 | // Accessors for handler table containing offsets of exception handlers. |
| 4504 | DECL_ACCESSORS(handler_table, FixedArray) |
| 4505 | |
| 4506 | // Accessors for source position table containing mappings between byte code |
| 4507 | // offset and source position. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 4508 | DECL_ACCESSORS(source_position_table, ByteArray) |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4509 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4510 | DECLARE_CAST(BytecodeArray) |
| 4511 | |
| 4512 | // Dispatched behavior. |
| 4513 | inline int BytecodeArraySize(); |
| 4514 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4515 | inline int instruction_size(); |
| 4516 | |
| 4517 | int SourcePosition(int offset); |
| 4518 | int SourceStatementPosition(int offset); |
| 4519 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4520 | DECLARE_PRINTER(BytecodeArray) |
| 4521 | DECLARE_VERIFIER(BytecodeArray) |
| 4522 | |
| 4523 | void Disassemble(std::ostream& os); |
| 4524 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4525 | void CopyBytecodesTo(BytecodeArray* to); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4526 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4527 | // Layout description. |
| 4528 | static const int kConstantPoolOffset = FixedArrayBase::kHeaderSize; |
| 4529 | static const int kHandlerTableOffset = kConstantPoolOffset + kPointerSize; |
| 4530 | static const int kSourcePositionTableOffset = |
| 4531 | kHandlerTableOffset + kPointerSize; |
| 4532 | static const int kFrameSizeOffset = kSourcePositionTableOffset + kPointerSize; |
| 4533 | static const int kParameterSizeOffset = kFrameSizeOffset + kIntSize; |
| 4534 | static const int kInterruptBudgetOffset = kParameterSizeOffset + kIntSize; |
| 4535 | static const int kHeaderSize = kInterruptBudgetOffset + kIntSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4536 | |
| 4537 | // Maximal memory consumption for a single BytecodeArray. |
| 4538 | static const int kMaxSize = 512 * MB; |
| 4539 | // Maximal length of a single BytecodeArray. |
| 4540 | static const int kMaxLength = kMaxSize - kHeaderSize; |
| 4541 | |
| 4542 | class BodyDescriptor; |
| 4543 | |
| 4544 | private: |
| 4545 | DISALLOW_IMPLICIT_CONSTRUCTORS(BytecodeArray); |
| 4546 | }; |
| 4547 | |
| 4548 | |
| 4549 | // FreeSpace are fixed-size free memory blocks used by the heap and GC. |
| 4550 | // They look like heap objects (are heap object tagged and have a map) so that |
| 4551 | // the heap remains iterable. They have a size and a next pointer. |
| 4552 | // The next pointer is the raw address of the next FreeSpace object (or NULL) |
| 4553 | // in the free list. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4554 | class FreeSpace: public HeapObject { |
| 4555 | public: |
| 4556 | // [size]: size of the free space including the header. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4557 | inline int size() const; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4558 | inline void set_size(int value); |
| 4559 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4560 | inline int nobarrier_size() const; |
| 4561 | inline void nobarrier_set_size(int value); |
| 4562 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4563 | inline int Size(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4564 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4565 | // Accessors for the next field. |
| 4566 | inline FreeSpace* next(); |
| 4567 | inline void set_next(FreeSpace* next); |
| 4568 | |
| 4569 | inline static FreeSpace* cast(HeapObject* obj); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4570 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4571 | // Dispatched behavior. |
| 4572 | DECLARE_PRINTER(FreeSpace) |
| 4573 | DECLARE_VERIFIER(FreeSpace) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4574 | |
| 4575 | // Layout description. |
| 4576 | // Size is smi tagged when it is stored. |
| 4577 | static const int kSizeOffset = HeapObject::kHeaderSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4578 | static const int kNextOffset = POINTER_SIZE_ALIGN(kSizeOffset + kPointerSize); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4579 | |
| 4580 | private: |
| 4581 | DISALLOW_IMPLICIT_CONSTRUCTORS(FreeSpace); |
| 4582 | }; |
| 4583 | |
| 4584 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4585 | // V has parameters (Type, type, TYPE, C type, element_size) |
| 4586 | #define TYPED_ARRAYS(V) \ |
| 4587 | V(Uint8, uint8, UINT8, uint8_t, 1) \ |
| 4588 | V(Int8, int8, INT8, int8_t, 1) \ |
| 4589 | V(Uint16, uint16, UINT16, uint16_t, 2) \ |
| 4590 | V(Int16, int16, INT16, int16_t, 2) \ |
| 4591 | V(Uint32, uint32, UINT32, uint32_t, 4) \ |
| 4592 | V(Int32, int32, INT32, int32_t, 4) \ |
| 4593 | V(Float32, float32, FLOAT32, float, 4) \ |
| 4594 | V(Float64, float64, FLOAT64, double, 8) \ |
| 4595 | V(Uint8Clamped, uint8_clamped, UINT8_CLAMPED, uint8_t, 1) |
| 4596 | |
| 4597 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4598 | class FixedTypedArrayBase: public FixedArrayBase { |
| 4599 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4600 | // [base_pointer]: Either points to the FixedTypedArrayBase itself or nullptr. |
| 4601 | DECL_ACCESSORS(base_pointer, Object) |
| 4602 | |
| 4603 | // [external_pointer]: Contains the offset between base_pointer and the start |
| 4604 | // of the data. If the base_pointer is a nullptr, the external_pointer |
| 4605 | // therefore points to the actual backing store. |
| 4606 | DECL_ACCESSORS(external_pointer, void) |
| 4607 | |
| 4608 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4609 | DECLARE_CAST(FixedTypedArrayBase) |
| 4610 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4611 | static const int kBasePointerOffset = FixedArrayBase::kHeaderSize; |
| 4612 | static const int kExternalPointerOffset = kBasePointerOffset + kPointerSize; |
| 4613 | static const int kHeaderSize = |
| 4614 | DOUBLE_POINTER_ALIGN(kExternalPointerOffset + kPointerSize); |
| 4615 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4616 | static const int kDataOffset = kHeaderSize; |
| 4617 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4618 | class BodyDescriptor; |
| 4619 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4620 | inline int size(); |
| 4621 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4622 | static inline int TypedArraySize(InstanceType type, int length); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4623 | inline int TypedArraySize(InstanceType type); |
| 4624 | |
| 4625 | // Use with care: returns raw pointer into heap. |
| 4626 | inline void* DataPtr(); |
| 4627 | |
| 4628 | inline int DataSize(); |
| 4629 | |
| 4630 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4631 | static inline int ElementSize(InstanceType type); |
| 4632 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4633 | inline int DataSize(InstanceType type); |
| 4634 | |
| 4635 | DISALLOW_IMPLICIT_CONSTRUCTORS(FixedTypedArrayBase); |
| 4636 | }; |
| 4637 | |
| 4638 | |
| 4639 | template <class Traits> |
| 4640 | class FixedTypedArray: public FixedTypedArrayBase { |
| 4641 | public: |
| 4642 | typedef typename Traits::ElementType ElementType; |
| 4643 | static const InstanceType kInstanceType = Traits::kInstanceType; |
| 4644 | |
| 4645 | DECLARE_CAST(FixedTypedArray<Traits>) |
| 4646 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4647 | inline ElementType get_scalar(int index); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4648 | static inline Handle<Object> get(FixedTypedArray* array, int index); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4649 | inline void set(int index, ElementType value); |
| 4650 | |
| 4651 | static inline ElementType from_int(int value); |
| 4652 | static inline ElementType from_double(double value); |
| 4653 | |
| 4654 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 4655 | // and undefined. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4656 | inline void SetValue(uint32_t index, Object* value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4657 | |
| 4658 | DECLARE_PRINTER(FixedTypedArray) |
| 4659 | DECLARE_VERIFIER(FixedTypedArray) |
| 4660 | |
| 4661 | private: |
| 4662 | DISALLOW_IMPLICIT_CONSTRUCTORS(FixedTypedArray); |
| 4663 | }; |
| 4664 | |
| 4665 | #define FIXED_TYPED_ARRAY_TRAITS(Type, type, TYPE, elementType, size) \ |
| 4666 | class Type##ArrayTraits { \ |
| 4667 | public: /* NOLINT */ \ |
| 4668 | typedef elementType ElementType; \ |
| 4669 | static const InstanceType kInstanceType = FIXED_##TYPE##_ARRAY_TYPE; \ |
| 4670 | static const char* Designator() { return #type " array"; } \ |
| 4671 | static inline Handle<Object> ToHandle(Isolate* isolate, \ |
| 4672 | elementType scalar); \ |
| 4673 | static inline elementType defaultValue(); \ |
| 4674 | }; \ |
| 4675 | \ |
| 4676 | typedef FixedTypedArray<Type##ArrayTraits> Fixed##Type##Array; |
| 4677 | |
| 4678 | TYPED_ARRAYS(FIXED_TYPED_ARRAY_TRAITS) |
| 4679 | |
| 4680 | #undef FIXED_TYPED_ARRAY_TRAITS |
| 4681 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 4682 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4683 | // DeoptimizationInputData is a fixed array used to hold the deoptimization |
| 4684 | // data for code generated by the Hydrogen/Lithium compiler. It also |
| 4685 | // contains information about functions that were inlined. If N different |
| 4686 | // functions were inlined then first N elements of the literal array will |
| 4687 | // contain these functions. |
| 4688 | // |
| 4689 | // It can be empty. |
| 4690 | class DeoptimizationInputData: public FixedArray { |
| 4691 | public: |
| 4692 | // Layout description. Indices in the array. |
| 4693 | static const int kTranslationByteArrayIndex = 0; |
| 4694 | static const int kInlinedFunctionCountIndex = 1; |
| 4695 | static const int kLiteralArrayIndex = 2; |
| 4696 | static const int kOsrAstIdIndex = 3; |
| 4697 | static const int kOsrPcOffsetIndex = 4; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4698 | static const int kOptimizationIdIndex = 5; |
| 4699 | static const int kSharedFunctionInfoIndex = 6; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4700 | static const int kWeakCellCacheIndex = 7; |
| 4701 | static const int kFirstDeoptEntryIndex = 8; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4702 | |
| 4703 | // Offsets of deopt entry elements relative to the start of the entry. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4704 | static const int kAstIdRawOffset = 0; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4705 | static const int kTranslationIndexOffset = 1; |
| 4706 | static const int kArgumentsStackHeightOffset = 2; |
Ben Murdoch | 2b4ba11 | 2012-01-20 14:57:15 +0000 | [diff] [blame] | 4707 | static const int kPcOffset = 3; |
| 4708 | static const int kDeoptEntrySize = 4; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4709 | |
| 4710 | // Simple element accessors. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4711 | #define DECLARE_ELEMENT_ACCESSORS(name, type) \ |
| 4712 | inline type* name(); \ |
| 4713 | inline void Set##name(type* value); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4714 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4715 | DECLARE_ELEMENT_ACCESSORS(TranslationByteArray, ByteArray) |
| 4716 | DECLARE_ELEMENT_ACCESSORS(InlinedFunctionCount, Smi) |
| 4717 | DECLARE_ELEMENT_ACCESSORS(LiteralArray, FixedArray) |
| 4718 | DECLARE_ELEMENT_ACCESSORS(OsrAstId, Smi) |
| 4719 | DECLARE_ELEMENT_ACCESSORS(OsrPcOffset, Smi) |
| 4720 | DECLARE_ELEMENT_ACCESSORS(OptimizationId, Smi) |
| 4721 | DECLARE_ELEMENT_ACCESSORS(SharedFunctionInfo, Object) |
| 4722 | DECLARE_ELEMENT_ACCESSORS(WeakCellCache, Object) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4723 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4724 | #undef DECLARE_ELEMENT_ACCESSORS |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4725 | |
| 4726 | // Accessors for elements of the ith deoptimization entry. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4727 | #define DECLARE_ENTRY_ACCESSORS(name, type) \ |
| 4728 | inline type* name(int i); \ |
| 4729 | inline void Set##name(int i, type* value); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4730 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4731 | DECLARE_ENTRY_ACCESSORS(AstIdRaw, Smi) |
| 4732 | DECLARE_ENTRY_ACCESSORS(TranslationIndex, Smi) |
| 4733 | DECLARE_ENTRY_ACCESSORS(ArgumentsStackHeight, Smi) |
| 4734 | DECLARE_ENTRY_ACCESSORS(Pc, Smi) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4735 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4736 | #undef DECLARE_ENTRY_ACCESSORS |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4737 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4738 | inline BailoutId AstId(int i); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4739 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4740 | inline void SetAstId(int i, BailoutId value); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4741 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4742 | inline int DeoptCount(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4743 | |
| 4744 | // Allocates a DeoptimizationInputData. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4745 | static Handle<DeoptimizationInputData> New(Isolate* isolate, |
| 4746 | int deopt_entry_count, |
| 4747 | PretenureFlag pretenure); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4748 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4749 | DECLARE_CAST(DeoptimizationInputData) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4750 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4751 | #ifdef ENABLE_DISASSEMBLER |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 4752 | void DeoptimizationInputDataPrint(std::ostream& os); // NOLINT |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4753 | #endif |
| 4754 | |
| 4755 | private: |
| 4756 | static int IndexForEntry(int i) { |
| 4757 | return kFirstDeoptEntryIndex + (i * kDeoptEntrySize); |
| 4758 | } |
| 4759 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4760 | |
| 4761 | static int LengthFor(int entry_count) { return IndexForEntry(entry_count); } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4762 | }; |
| 4763 | |
| 4764 | |
| 4765 | // DeoptimizationOutputData is a fixed array used to hold the deoptimization |
| 4766 | // data for code generated by the full compiler. |
| 4767 | // The format of the these objects is |
| 4768 | // [i * 2]: Ast ID for ith deoptimization. |
| 4769 | // [i * 2 + 1]: PC and state of ith deoptimization |
| 4770 | class DeoptimizationOutputData: public FixedArray { |
| 4771 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4772 | inline int DeoptPoints(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4773 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4774 | inline BailoutId AstId(int index); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4775 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4776 | inline void SetAstId(int index, BailoutId id); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4777 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4778 | inline Smi* PcAndState(int index); |
| 4779 | inline void SetPcAndState(int index, Smi* offset); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4780 | |
| 4781 | static int LengthOfFixedArray(int deopt_points) { |
| 4782 | return deopt_points * 2; |
| 4783 | } |
| 4784 | |
| 4785 | // Allocates a DeoptimizationOutputData. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4786 | static Handle<DeoptimizationOutputData> New(Isolate* isolate, |
| 4787 | int number_of_deopt_points, |
| 4788 | PretenureFlag pretenure); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4789 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4790 | DECLARE_CAST(DeoptimizationOutputData) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4791 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4792 | #ifdef ENABLE_DISASSEMBLER |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 4793 | void DeoptimizationOutputDataPrint(std::ostream& os); // NOLINT |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4794 | #endif |
| 4795 | }; |
| 4796 | |
| 4797 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4798 | // A literals array contains the literals for a JSFunction. It also holds |
| 4799 | // the type feedback vector. |
| 4800 | class LiteralsArray : public FixedArray { |
| 4801 | public: |
| 4802 | static const int kVectorIndex = 0; |
| 4803 | static const int kFirstLiteralIndex = 1; |
| 4804 | static const int kOffsetToFirstLiteral = |
| 4805 | FixedArray::kHeaderSize + kPointerSize; |
| 4806 | |
| 4807 | static int OffsetOfLiteralAt(int index) { |
| 4808 | return SizeFor(index + kFirstLiteralIndex); |
| 4809 | } |
| 4810 | |
| 4811 | inline TypeFeedbackVector* feedback_vector() const; |
| 4812 | inline void set_feedback_vector(TypeFeedbackVector* vector); |
| 4813 | inline Object* literal(int literal_index) const; |
| 4814 | inline void set_literal(int literal_index, Object* literal); |
| 4815 | inline int literals_count() const; |
| 4816 | |
| 4817 | static Handle<LiteralsArray> New(Isolate* isolate, |
| 4818 | Handle<TypeFeedbackVector> vector, |
| 4819 | int number_of_literals, |
| 4820 | PretenureFlag pretenure); |
| 4821 | |
| 4822 | DECLARE_CAST(LiteralsArray) |
| 4823 | |
| 4824 | private: |
| 4825 | inline Object* get(int index) const; |
| 4826 | inline void set(int index, Object* value); |
| 4827 | inline void set(int index, Smi* value); |
| 4828 | inline void set(int index, Object* value, WriteBarrierMode mode); |
| 4829 | }; |
| 4830 | |
| 4831 | |
| 4832 | // HandlerTable is a fixed array containing entries for exception handlers in |
| 4833 | // the code object it is associated with. The tables comes in two flavors: |
| 4834 | // 1) Based on ranges: Used for unoptimized code. Contains one entry per |
| 4835 | // exception handler and a range representing the try-block covered by that |
| 4836 | // handler. Layout looks as follows: |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4837 | // [ range-start , range-end , handler-offset , handler-data ] |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4838 | // 2) Based on return addresses: Used for turbofanned code. Contains one entry |
| 4839 | // per call-site that could throw an exception. Layout looks as follows: |
| 4840 | // [ return-address-offset , handler-offset ] |
| 4841 | class HandlerTable : public FixedArray { |
| 4842 | public: |
| 4843 | // Conservative prediction whether a given handler will locally catch an |
| 4844 | // exception or cause a re-throw to outside the code boundary. Since this is |
| 4845 | // undecidable it is merely an approximation (e.g. useful for debugger). |
| 4846 | enum CatchPrediction { UNCAUGHT, CAUGHT }; |
| 4847 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4848 | // Getters for handler table based on ranges. |
| 4849 | inline int GetRangeStart(int index) const; |
| 4850 | inline int GetRangeEnd(int index) const; |
| 4851 | inline int GetRangeHandler(int index) const; |
| 4852 | inline int GetRangeData(int index) const; |
| 4853 | |
| 4854 | // Setters for handler table based on ranges. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4855 | inline void SetRangeStart(int index, int value); |
| 4856 | inline void SetRangeEnd(int index, int value); |
| 4857 | inline void SetRangeHandler(int index, int offset, CatchPrediction pred); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4858 | inline void SetRangeData(int index, int value); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4859 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4860 | // Setters for handler table based on return addresses. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4861 | inline void SetReturnOffset(int index, int value); |
| 4862 | inline void SetReturnHandler(int index, int offset, CatchPrediction pred); |
| 4863 | |
| 4864 | // Lookup handler in a table based on ranges. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4865 | int LookupRange(int pc_offset, int* data, CatchPrediction* prediction); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4866 | |
| 4867 | // Lookup handler in a table based on return addresses. |
| 4868 | int LookupReturn(int pc_offset, CatchPrediction* prediction); |
| 4869 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4870 | // Returns the conservative catch predication. |
| 4871 | inline CatchPrediction GetRangePrediction(int index) const; |
| 4872 | |
| 4873 | // Returns the number of entries in the table. |
| 4874 | inline int NumberOfRangeEntries() const; |
| 4875 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4876 | // Returns the required length of the underlying fixed array. |
| 4877 | static int LengthForRange(int entries) { return entries * kRangeEntrySize; } |
| 4878 | static int LengthForReturn(int entries) { return entries * kReturnEntrySize; } |
| 4879 | |
| 4880 | DECLARE_CAST(HandlerTable) |
| 4881 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4882 | #ifdef ENABLE_DISASSEMBLER |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4883 | void HandlerTableRangePrint(std::ostream& os); // NOLINT |
| 4884 | void HandlerTableReturnPrint(std::ostream& os); // NOLINT |
| 4885 | #endif |
| 4886 | |
| 4887 | private: |
| 4888 | // Layout description for handler table based on ranges. |
| 4889 | static const int kRangeStartIndex = 0; |
| 4890 | static const int kRangeEndIndex = 1; |
| 4891 | static const int kRangeHandlerIndex = 2; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 4892 | static const int kRangeDataIndex = 3; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4893 | static const int kRangeEntrySize = 4; |
| 4894 | |
| 4895 | // Layout description for handler table based on return addresses. |
| 4896 | static const int kReturnOffsetIndex = 0; |
| 4897 | static const int kReturnHandlerIndex = 1; |
| 4898 | static const int kReturnEntrySize = 2; |
| 4899 | |
| 4900 | // Encoding of the {handler} field. |
| 4901 | class HandlerPredictionField : public BitField<CatchPrediction, 0, 1> {}; |
| 4902 | class HandlerOffsetField : public BitField<int, 1, 30> {}; |
| 4903 | }; |
| 4904 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4905 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4906 | // Code describes objects with on-the-fly generated machine code. |
| 4907 | class Code: public HeapObject { |
| 4908 | public: |
| 4909 | // Opaque data type for encapsulating code flags like kind, inline |
| 4910 | // cache state, and arguments count. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4911 | typedef uint32_t Flags; |
| 4912 | |
| 4913 | #define NON_IC_KIND_LIST(V) \ |
| 4914 | V(FUNCTION) \ |
| 4915 | V(OPTIMIZED_FUNCTION) \ |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 4916 | V(BYTECODE_HANDLER) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4917 | V(STUB) \ |
| 4918 | V(HANDLER) \ |
| 4919 | V(BUILTIN) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4920 | V(REGEXP) \ |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 4921 | V(WASM_FUNCTION) \ |
| 4922 | V(WASM_TO_JS_FUNCTION) \ |
| 4923 | V(JS_TO_WASM_FUNCTION) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4924 | |
| 4925 | #define IC_KIND_LIST(V) \ |
| 4926 | V(LOAD_IC) \ |
| 4927 | V(KEYED_LOAD_IC) \ |
| 4928 | V(CALL_IC) \ |
| 4929 | V(STORE_IC) \ |
| 4930 | V(KEYED_STORE_IC) \ |
| 4931 | V(BINARY_OP_IC) \ |
| 4932 | V(COMPARE_IC) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4933 | V(TO_BOOLEAN_IC) |
| 4934 | |
| 4935 | #define CODE_KIND_LIST(V) \ |
| 4936 | NON_IC_KIND_LIST(V) \ |
| 4937 | IC_KIND_LIST(V) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4938 | |
| 4939 | enum Kind { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4940 | #define DEFINE_CODE_KIND_ENUM(name) name, |
| 4941 | CODE_KIND_LIST(DEFINE_CODE_KIND_ENUM) |
| 4942 | #undef DEFINE_CODE_KIND_ENUM |
| 4943 | NUMBER_OF_KINDS |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4944 | }; |
| 4945 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4946 | // 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] | 4947 | // Flags. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4948 | STATIC_ASSERT(NUMBER_OF_KINDS <= 32); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4949 | |
| 4950 | static const char* Kind2String(Kind kind); |
| 4951 | |
| 4952 | // Types of stubs. |
| 4953 | enum StubType { |
| 4954 | NORMAL, |
| 4955 | FAST |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4956 | }; |
| 4957 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4958 | static const int kPrologueOffsetNotSet = -1; |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4959 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4960 | #ifdef ENABLE_DISASSEMBLER |
| 4961 | // Printing |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4962 | static const char* ICState2String(InlineCacheState state); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4963 | static const char* StubType2String(StubType type); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 4964 | static void PrintExtraICState(std::ostream& os, // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4965 | Kind kind, ExtraICState extra); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 4966 | void Disassemble(const char* name, std::ostream& os); // NOLINT |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4967 | #endif // ENABLE_DISASSEMBLER |
| 4968 | |
| 4969 | // [instruction_size]: Size of the native instructions |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4970 | inline int instruction_size() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4971 | inline void set_instruction_size(int value); |
| 4972 | |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 4973 | // [relocation_info]: Code relocation information |
| 4974 | DECL_ACCESSORS(relocation_info, ByteArray) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4975 | void InvalidateRelocation(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4976 | void InvalidateEmbeddedObjects(); |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 4977 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4978 | // [handler_table]: Fixed array containing offsets of exception handlers. |
| 4979 | DECL_ACCESSORS(handler_table, FixedArray) |
| 4980 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4981 | // [deoptimization_data]: Array containing data for deopt. |
| 4982 | DECL_ACCESSORS(deoptimization_data, FixedArray) |
| 4983 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4984 | // [raw_type_feedback_info]: This field stores various things, depending on |
| 4985 | // the kind of the code object. |
| 4986 | // FUNCTION => type feedback information. |
| 4987 | // STUB and ICs => major/minor key as Smi. |
| 4988 | DECL_ACCESSORS(raw_type_feedback_info, Object) |
| 4989 | inline Object* type_feedback_info(); |
| 4990 | inline void set_type_feedback_info( |
| 4991 | Object* value, WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| 4992 | inline uint32_t stub_key(); |
| 4993 | inline void set_stub_key(uint32_t key); |
| 4994 | |
| 4995 | // [next_code_link]: Link for lists of optimized or deoptimized code. |
| 4996 | // Note that storage for this field is overlapped with typefeedback_info. |
| 4997 | DECL_ACCESSORS(next_code_link, Object) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4998 | |
| 4999 | // [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] | 5000 | // field does not have to be traced during garbage collection since |
| 5001 | // it is only used by the garbage collector itself. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5002 | DECL_ACCESSORS(gc_metadata, Object) |
| 5003 | |
| 5004 | // [ic_age]: Inline caching age: the value of the Heap::global_ic_age |
| 5005 | // at the moment when this object was created. |
| 5006 | inline void set_ic_age(int count); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5007 | inline int ic_age() const; |
| 5008 | |
| 5009 | // [prologue_offset]: Offset of the function prologue, used for aging |
| 5010 | // FUNCTIONs and OPTIMIZED_FUNCTIONs. |
| 5011 | inline int prologue_offset() const; |
| 5012 | inline void set_prologue_offset(int offset); |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame] | 5013 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5014 | // [constant_pool offset]: Offset of the constant pool. |
| 5015 | // Valid for FLAG_enable_embedded_constant_pool only |
| 5016 | inline int constant_pool_offset() const; |
| 5017 | inline void set_constant_pool_offset(int offset); |
| 5018 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5019 | // Unchecked accessors to be used during GC. |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 5020 | inline ByteArray* unchecked_relocation_info(); |
| 5021 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5022 | inline int relocation_size(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5023 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5024 | // [flags]: Various code flags. |
| 5025 | inline Flags flags(); |
| 5026 | inline void set_flags(Flags flags); |
| 5027 | |
| 5028 | // [flags]: Access to specific code flags. |
| 5029 | inline Kind kind(); |
| 5030 | inline InlineCacheState ic_state(); // Only valid for IC stubs. |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 5031 | inline ExtraICState extra_ic_state(); // Only valid for IC stubs. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5032 | |
| 5033 | inline StubType type(); // Only valid for monomorphic IC stubs. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5034 | |
| 5035 | // Testers for IC stub kinds. |
| 5036 | inline bool is_inline_cache_stub(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5037 | inline bool is_debug_stub(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5038 | inline bool is_handler(); |
| 5039 | inline bool is_load_stub(); |
| 5040 | inline bool is_keyed_load_stub(); |
| 5041 | inline bool is_store_stub(); |
| 5042 | inline bool is_keyed_store_stub(); |
| 5043 | inline bool is_call_stub(); |
| 5044 | inline bool is_binary_op_stub(); |
| 5045 | inline bool is_compare_ic_stub(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5046 | inline bool is_to_boolean_ic_stub(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5047 | inline bool is_keyed_stub(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5048 | inline bool is_optimized_code(); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 5049 | inline bool is_wasm_code(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5050 | inline bool embeds_maps_weakly(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5051 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5052 | inline bool IsCodeStubOrIC(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5053 | inline bool IsJavaScriptCode(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5054 | |
| 5055 | inline void set_raw_kind_specific_flags1(int value); |
| 5056 | inline void set_raw_kind_specific_flags2(int value); |
| 5057 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5058 | // Testers for interpreter builtins. |
| 5059 | inline bool is_interpreter_entry_trampoline(); |
| 5060 | inline bool is_interpreter_enter_bytecode_dispatch(); |
| 5061 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5062 | // [is_crankshafted]: For kind STUB or ICs, tells whether or not a code |
| 5063 | // object was generated by either the hydrogen or the TurboFan optimizing |
| 5064 | // compiler (but it may not be an optimized function). |
| 5065 | inline bool is_crankshafted(); |
| 5066 | inline bool is_hydrogen_stub(); // Crankshafted, but not a function. |
| 5067 | inline void set_is_crankshafted(bool value); |
| 5068 | |
| 5069 | // [is_turbofanned]: For kind STUB or OPTIMIZED_FUNCTION, tells whether the |
| 5070 | // code object was generated by the TurboFan optimizing compiler. |
| 5071 | inline bool is_turbofanned(); |
| 5072 | inline void set_is_turbofanned(bool value); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5073 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5074 | // [can_have_weak_objects]: For kind OPTIMIZED_FUNCTION, tells whether the |
| 5075 | // embedded objects in code should be treated weakly. |
| 5076 | inline bool can_have_weak_objects(); |
| 5077 | inline void set_can_have_weak_objects(bool value); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5078 | |
| 5079 | // [has_deoptimization_support]: For FUNCTION kind, tells if it has |
| 5080 | // deoptimization support. |
| 5081 | inline bool has_deoptimization_support(); |
| 5082 | inline void set_has_deoptimization_support(bool value); |
| 5083 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 5084 | // [has_debug_break_slots]: For FUNCTION kind, tells if it has |
| 5085 | // been compiled with debug break slots. |
| 5086 | inline bool has_debug_break_slots(); |
| 5087 | inline void set_has_debug_break_slots(bool value); |
| 5088 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5089 | // [has_reloc_info_for_serialization]: For FUNCTION kind, tells if its |
| 5090 | // reloc info includes runtime and external references to support |
| 5091 | // serialization/deserialization. |
| 5092 | inline bool has_reloc_info_for_serialization(); |
| 5093 | inline void set_has_reloc_info_for_serialization(bool value); |
| 5094 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5095 | // [allow_osr_at_loop_nesting_level]: For FUNCTION kind, tells for |
| 5096 | // how long the function has been marked for OSR and therefore which |
| 5097 | // level of loop nesting we are willing to do on-stack replacement |
| 5098 | // for. |
| 5099 | inline void set_allow_osr_at_loop_nesting_level(int level); |
| 5100 | inline int allow_osr_at_loop_nesting_level(); |
| 5101 | |
Ben Murdoch | 8f9999f | 2012-04-23 10:39:17 +0100 | [diff] [blame] | 5102 | // [profiler_ticks]: For FUNCTION kind, tells for how many profiler ticks |
| 5103 | // the code object was seen on the stack with no IC patching going on. |
| 5104 | inline int profiler_ticks(); |
| 5105 | inline void set_profiler_ticks(int ticks); |
| 5106 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5107 | // [builtin_index]: For BUILTIN kind, tells which builtin index it has. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5108 | // For builtins, tells which builtin index it has. |
| 5109 | // Note that builtins can have a code kind other than BUILTIN, which means |
| 5110 | // that for arbitrary code objects, this index value may be random garbage. |
| 5111 | // 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] | 5112 | inline int builtin_index(); |
| 5113 | inline void set_builtin_index(int id); |
| 5114 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5115 | // [stack_slots]: For kind OPTIMIZED_FUNCTION, the number of stack slots |
| 5116 | // reserved in the code prologue. |
| 5117 | inline unsigned stack_slots(); |
| 5118 | inline void set_stack_slots(unsigned slots); |
| 5119 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5120 | // [safepoint_table_start]: For kind OPTIMIZED_FUNCTION, the offset in |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5121 | // the instruction stream where the safepoint table starts. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 5122 | inline unsigned safepoint_table_offset(); |
| 5123 | inline void set_safepoint_table_offset(unsigned offset); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5124 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5125 | // [back_edge_table_start]: For kind FUNCTION, the offset in the |
| 5126 | // instruction stream where the back edge table starts. |
| 5127 | inline unsigned back_edge_table_offset(); |
| 5128 | inline void set_back_edge_table_offset(unsigned offset); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5129 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5130 | inline bool back_edges_patched_for_osr(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5131 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 5132 | // [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] | 5133 | inline uint16_t to_boolean_state(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5134 | |
| 5135 | // [marked_for_deoptimization]: For kind OPTIMIZED_FUNCTION tells whether |
| 5136 | // the code is going to be deoptimized because of dead embedded maps. |
| 5137 | inline bool marked_for_deoptimization(); |
| 5138 | inline void set_marked_for_deoptimization(bool flag); |
| 5139 | |
| 5140 | // [constant_pool]: The constant pool for this function. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5141 | inline Address constant_pool(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5142 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 5143 | // Get the safepoint entry for the given pc. |
| 5144 | SafepointEntry GetSafepointEntry(Address pc); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5145 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5146 | // Find an object in a stub with a specified map |
| 5147 | Object* FindNthObject(int n, Map* match_map); |
| 5148 | |
| 5149 | // Find the first allocation site in an IC stub. |
| 5150 | AllocationSite* FindFirstAllocationSite(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5151 | |
| 5152 | // Find the first map in an IC stub. |
| 5153 | Map* FindFirstMap(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5154 | void FindAllMaps(MapHandleList* maps); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5155 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5156 | // Find the first handler in an IC stub. |
| 5157 | Code* FindFirstHandler(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5158 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5159 | // Find |length| handlers and put them into |code_list|. Returns false if not |
| 5160 | // enough handlers can be found. |
| 5161 | bool FindHandlers(CodeHandleList* code_list, int length = -1); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5162 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5163 | // Find the handler for |map|. |
| 5164 | MaybeHandle<Code> FindHandlerForMap(Map* map); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5165 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5166 | // Find the first name in an IC stub. |
| 5167 | Name* FindFirstName(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5168 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5169 | class FindAndReplacePattern; |
| 5170 | // For each (map-to-find, object-to-replace) pair in the pattern, this |
| 5171 | // function replaces the corresponding placeholder in the code with the |
| 5172 | // object-to-replace. The function assumes that pairs in the pattern come in |
| 5173 | // the same order as the placeholders in the code. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5174 | // If the placeholder is a weak cell, then the value of weak cell is matched |
| 5175 | // against the map-to-find. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5176 | void FindAndReplace(const FindAndReplacePattern& pattern); |
| 5177 | |
| 5178 | // The entire code object including its header is copied verbatim to the |
| 5179 | // snapshot so that it can be written in one, fast, memcpy during |
| 5180 | // deserialization. The deserializer will overwrite some pointers, rather |
| 5181 | // like a runtime linker, but the random allocation addresses used in the |
| 5182 | // mksnapshot process would still be present in the unlinked snapshot data, |
| 5183 | // which would make snapshot production non-reproducible. This method wipes |
| 5184 | // out the to-be-overwritten header data for reproducible snapshots. |
| 5185 | inline void WipeOutHeader(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5186 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5187 | // Flags operations. |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 5188 | static inline Flags ComputeFlags( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5189 | Kind kind, InlineCacheState ic_state = UNINITIALIZED, |
| 5190 | ExtraICState extra_ic_state = kNoExtraICState, StubType type = NORMAL, |
| 5191 | CacheHolderFlag holder = kCacheOnReceiver); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5192 | |
| 5193 | static inline Flags ComputeMonomorphicFlags( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5194 | Kind kind, ExtraICState extra_ic_state = kNoExtraICState, |
| 5195 | CacheHolderFlag holder = kCacheOnReceiver, StubType type = NORMAL); |
| 5196 | |
| 5197 | static inline Flags ComputeHandlerFlags( |
| 5198 | Kind handler_kind, StubType type = NORMAL, |
| 5199 | CacheHolderFlag holder = kCacheOnReceiver); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5200 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5201 | static inline InlineCacheState ExtractICStateFromFlags(Flags flags); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5202 | static inline StubType ExtractTypeFromFlags(Flags flags); |
| 5203 | static inline CacheHolderFlag ExtractCacheHolderFromFlags(Flags flags); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 5204 | static inline Kind ExtractKindFromFlags(Flags flags); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 5205 | static inline ExtraICState ExtractExtraICStateFromFlags(Flags flags); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 5206 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5207 | static inline Flags RemoveTypeFromFlags(Flags flags); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5208 | static inline Flags RemoveTypeAndHolderFromFlags(Flags flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5209 | |
| 5210 | // Convert a target address into a code object. |
| 5211 | static inline Code* GetCodeFromTargetAddress(Address address); |
| 5212 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 5213 | // Convert an entry address into an object. |
| 5214 | static inline Object* GetObjectFromEntryAddress(Address location_of_address); |
| 5215 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5216 | // Returns the address of the first instruction. |
| 5217 | inline byte* instruction_start(); |
| 5218 | |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 5219 | // Returns the address right after the last instruction. |
| 5220 | inline byte* instruction_end(); |
| 5221 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5222 | // Returns the size of the instructions, padding, and relocation information. |
| 5223 | inline int body_size(); |
| 5224 | |
| 5225 | // Returns the address of the first relocation info (read backwards!). |
| 5226 | inline byte* relocation_start(); |
| 5227 | |
| 5228 | // Code entry point. |
| 5229 | inline byte* entry(); |
| 5230 | |
| 5231 | // Returns true if pc is inside this object's instructions. |
| 5232 | inline bool contains(byte* pc); |
| 5233 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5234 | // Relocate the code by delta bytes. Called to signal that this code |
| 5235 | // object has been moved by delta bytes. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5236 | void Relocate(intptr_t delta); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5237 | |
| 5238 | // Migrate code described by desc. |
| 5239 | void CopyFrom(const CodeDesc& desc); |
| 5240 | |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 5241 | // Returns the object size for a given body (used for allocation). |
| 5242 | static int SizeFor(int body_size) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5243 | DCHECK_SIZE_TAG_ALIGNED(body_size); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 5244 | return RoundUp(kHeaderSize + body_size, kCodeAlignment); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5245 | } |
| 5246 | |
| 5247 | // Calculate the size of the code object to report for log events. This takes |
| 5248 | // the layout of the code object into account. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5249 | inline int ExecutableSize(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5250 | |
| 5251 | // Locating source position. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5252 | int SourcePosition(int code_offset); |
| 5253 | int SourceStatementPosition(int code_offset); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5254 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5255 | DECLARE_CAST(Code) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5256 | |
| 5257 | // Dispatched behavior. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5258 | inline int CodeSize(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5259 | |
| 5260 | DECLARE_PRINTER(Code) |
| 5261 | DECLARE_VERIFIER(Code) |
| 5262 | |
Ben Murdoch | 8f9999f | 2012-04-23 10:39:17 +0100 | [diff] [blame] | 5263 | void ClearInlineCaches(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5264 | void ClearInlineCaches(Kind kind); |
| 5265 | |
| 5266 | BailoutId TranslatePcOffsetToAstId(uint32_t pc_offset); |
| 5267 | uint32_t TranslateAstIdToPcOffset(BailoutId ast_id); |
| 5268 | |
| 5269 | #define DECLARE_CODE_AGE_ENUM(X) k##X##CodeAge, |
| 5270 | enum Age { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5271 | kToBeExecutedOnceCodeAge = -3, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5272 | kNotExecutedCodeAge = -2, |
| 5273 | kExecutedOnceCodeAge = -1, |
| 5274 | kNoAgeCodeAge = 0, |
| 5275 | CODE_AGE_LIST(DECLARE_CODE_AGE_ENUM) |
| 5276 | kAfterLastCodeAge, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5277 | kFirstCodeAge = kToBeExecutedOnceCodeAge, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5278 | kLastCodeAge = kAfterLastCodeAge - 1, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5279 | kCodeAgeCount = kAfterLastCodeAge - kFirstCodeAge - 1, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5280 | kIsOldCodeAge = kSexagenarianCodeAge, |
| 5281 | kPreAgedCodeAge = kIsOldCodeAge - 1 |
| 5282 | }; |
| 5283 | #undef DECLARE_CODE_AGE_ENUM |
| 5284 | |
| 5285 | // Code aging. Indicates how many full GCs this code has survived without |
| 5286 | // being entered through the prologue. Used to determine when it is |
| 5287 | // relatively safe to flush this code object and replace it with the lazy |
| 5288 | // compilation stub. |
| 5289 | static void MakeCodeAgeSequenceYoung(byte* sequence, Isolate* isolate); |
| 5290 | static void MarkCodeAsExecuted(byte* sequence, Isolate* isolate); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5291 | void MakeYoung(Isolate* isolate); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 5292 | void PreAge(Isolate* isolate); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5293 | void MarkToBeExecutedOnce(Isolate* isolate); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5294 | void MakeOlder(MarkingParity); |
| 5295 | static bool IsYoungSequence(Isolate* isolate, byte* sequence); |
| 5296 | bool IsOld(); |
| 5297 | Age GetAge(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5298 | static inline Code* GetPreAgedCodeAgeStub(Isolate* isolate) { |
| 5299 | return GetCodeAgeStub(isolate, kNotExecutedCodeAge, NO_MARKING_PARITY); |
| 5300 | } |
| 5301 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5302 | void PrintDeoptLocation(FILE* out, Address pc); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5303 | bool CanDeoptAt(Address pc); |
| 5304 | |
| 5305 | #ifdef VERIFY_HEAP |
| 5306 | void VerifyEmbeddedObjectsDependency(); |
| 5307 | #endif |
| 5308 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5309 | #ifdef DEBUG |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5310 | enum VerifyMode { kNoContextSpecificPointers, kNoContextRetainingPointers }; |
| 5311 | void VerifyEmbeddedObjects(VerifyMode mode = kNoContextRetainingPointers); |
| 5312 | static void VerifyRecompiledCode(Code* old_code, Code* new_code); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5313 | #endif // DEBUG |
| 5314 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5315 | inline bool CanContainWeakObjects(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5316 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5317 | inline bool IsWeakObject(Object* object); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5318 | |
| 5319 | static inline bool IsWeakObjectInOptimizedCode(Object* object); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5320 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5321 | static Handle<WeakCell> WeakCellFor(Handle<Code> code); |
| 5322 | WeakCell* CachedWeakCell(); |
| 5323 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5324 | // Max loop nesting marker used to postpose OSR. We don't take loop |
| 5325 | // nesting that is deeper than 5 levels into account. |
| 5326 | static const int kMaxLoopNestingMarker = 6; |
| 5327 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5328 | static const int kConstantPoolSize = |
| 5329 | FLAG_enable_embedded_constant_pool ? kIntSize : 0; |
| 5330 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5331 | // Layout description. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5332 | static const int kRelocationInfoOffset = HeapObject::kHeaderSize; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5333 | static const int kHandlerTableOffset = kRelocationInfoOffset + kPointerSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5334 | static const int kDeoptimizationDataOffset = |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5335 | kHandlerTableOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5336 | // For FUNCTION kind, we store the type feedback info here. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5337 | static const int kTypeFeedbackInfoOffset = |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame] | 5338 | kDeoptimizationDataOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5339 | static const int kNextCodeLinkOffset = kTypeFeedbackInfoOffset + kPointerSize; |
| 5340 | static const int kGCMetadataOffset = kNextCodeLinkOffset + kPointerSize; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5341 | static const int kInstructionSizeOffset = kGCMetadataOffset + kPointerSize; |
| 5342 | static const int kICAgeOffset = kInstructionSizeOffset + kIntSize; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5343 | static const int kFlagsOffset = kICAgeOffset + kIntSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5344 | static const int kKindSpecificFlags1Offset = kFlagsOffset + kIntSize; |
| 5345 | static const int kKindSpecificFlags2Offset = |
| 5346 | kKindSpecificFlags1Offset + kIntSize; |
| 5347 | // Note: We might be able to squeeze this into the flags above. |
| 5348 | static const int kPrologueOffset = kKindSpecificFlags2Offset + kIntSize; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5349 | static const int kConstantPoolOffset = kPrologueOffset + kIntSize; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 5350 | static const int kBuiltinIndexOffset = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5351 | kConstantPoolOffset + kConstantPoolSize; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 5352 | static const int kHeaderPaddingStart = kBuiltinIndexOffset + kIntSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5353 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5354 | // Add padding to align the instruction start following right after |
| 5355 | // the Code object header. |
| 5356 | static const int kHeaderSize = |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5357 | (kHeaderPaddingStart + kCodeAlignmentMask) & ~kCodeAlignmentMask; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5358 | |
| 5359 | class BodyDescriptor; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5360 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5361 | // Byte offsets within kKindSpecificFlags1Offset. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5362 | static const int kFullCodeFlags = kKindSpecificFlags1Offset; |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 5363 | class FullCodeFlagsHasDeoptimizationSupportField: |
| 5364 | public BitField<bool, 0, 1> {}; // NOLINT |
| 5365 | class FullCodeFlagsHasDebugBreakSlotsField: public BitField<bool, 1, 1> {}; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5366 | class FullCodeFlagsHasRelocInfoForSerialization |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5367 | : public BitField<bool, 2, 1> {}; |
| 5368 | // Bit 3 in this bitfield is unused. |
| 5369 | class ProfilerTicksField : public BitField<int, 4, 28> {}; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5370 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 5371 | // Flags layout. BitField<type, shift, size>. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5372 | class ICStateField : public BitField<InlineCacheState, 0, 3> {}; |
| 5373 | class TypeField : public BitField<StubType, 3, 1> {}; |
| 5374 | class CacheHolderField : public BitField<CacheHolderFlag, 4, 2> {}; |
| 5375 | class KindField : public BitField<Kind, 6, 5> {}; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 5376 | class ExtraICStateField |
| 5377 | : public BitField<ExtraICState, 11, PlatformSmiTagging::kSmiValueSize - |
| 5378 | 11 + 1> {}; // NOLINT |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5379 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 5380 | // KindSpecificFlags1 layout (STUB, BUILTIN and OPTIMIZED_FUNCTION) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5381 | static const int kStackSlotsFirstBit = 0; |
| 5382 | static const int kStackSlotsBitCount = 24; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5383 | static const int kMarkedForDeoptimizationBit = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5384 | kStackSlotsFirstBit + kStackSlotsBitCount; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5385 | static const int kIsTurbofannedBit = kMarkedForDeoptimizationBit + 1; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5386 | static const int kCanHaveWeakObjects = kIsTurbofannedBit + 1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5387 | |
| 5388 | STATIC_ASSERT(kStackSlotsFirstBit + kStackSlotsBitCount <= 32); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5389 | STATIC_ASSERT(kCanHaveWeakObjects + 1 <= 32); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5390 | |
| 5391 | class StackSlotsField: public BitField<int, |
| 5392 | kStackSlotsFirstBit, kStackSlotsBitCount> {}; // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5393 | class MarkedForDeoptimizationField |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5394 | : public BitField<bool, kMarkedForDeoptimizationBit, 1> {}; // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5395 | class IsTurbofannedField : public BitField<bool, kIsTurbofannedBit, 1> { |
| 5396 | }; // NOLINT |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5397 | class CanHaveWeakObjectsField |
| 5398 | : public BitField<bool, kCanHaveWeakObjects, 1> {}; // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5399 | |
| 5400 | // KindSpecificFlags2 layout (ALL) |
| 5401 | static const int kIsCrankshaftedBit = 0; |
| 5402 | class IsCrankshaftedField: public BitField<bool, |
| 5403 | kIsCrankshaftedBit, 1> {}; // NOLINT |
| 5404 | |
| 5405 | // KindSpecificFlags2 layout (STUB and OPTIMIZED_FUNCTION) |
| 5406 | static const int kSafepointTableOffsetFirstBit = kIsCrankshaftedBit + 1; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5407 | static const int kSafepointTableOffsetBitCount = 30; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5408 | |
| 5409 | STATIC_ASSERT(kSafepointTableOffsetFirstBit + |
| 5410 | kSafepointTableOffsetBitCount <= 32); |
| 5411 | STATIC_ASSERT(1 + kSafepointTableOffsetBitCount <= 32); |
| 5412 | |
| 5413 | class SafepointTableOffsetField: public BitField<int, |
| 5414 | kSafepointTableOffsetFirstBit, |
| 5415 | kSafepointTableOffsetBitCount> {}; // NOLINT |
| 5416 | |
| 5417 | // KindSpecificFlags2 layout (FUNCTION) |
| 5418 | class BackEdgeTableOffsetField: public BitField<int, |
| 5419 | kIsCrankshaftedBit + 1, 27> {}; // NOLINT |
| 5420 | class AllowOSRAtLoopNestingLevelField: public BitField<int, |
| 5421 | kIsCrankshaftedBit + 1 + 27, 4> {}; // NOLINT |
| 5422 | STATIC_ASSERT(AllowOSRAtLoopNestingLevelField::kMax >= kMaxLoopNestingMarker); |
| 5423 | |
| 5424 | static const int kArgumentsBits = 16; |
| 5425 | static const int kMaxArguments = (1 << kArgumentsBits) - 1; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5426 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5427 | // This constant should be encodable in an ARM instruction. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5428 | static const int kFlagsNotUsedInLookup = |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 5429 | TypeField::kMask | CacheHolderField::kMask; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5430 | |
| 5431 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5432 | friend class RelocIterator; |
| 5433 | friend class Deoptimizer; // For FindCodeAgeSequence. |
| 5434 | |
| 5435 | void ClearInlineCaches(Kind* kind); |
| 5436 | |
| 5437 | // Code aging |
| 5438 | byte* FindCodeAgeSequence(); |
| 5439 | static void GetCodeAgeAndParity(Code* code, Age* age, |
| 5440 | MarkingParity* parity); |
| 5441 | static void GetCodeAgeAndParity(Isolate* isolate, byte* sequence, Age* age, |
| 5442 | MarkingParity* parity); |
| 5443 | static Code* GetCodeAgeStub(Isolate* isolate, Age age, MarkingParity parity); |
| 5444 | |
| 5445 | // Code aging -- platform-specific |
| 5446 | static void PatchPlatformCodeAge(Isolate* isolate, |
| 5447 | byte* sequence, Age age, |
| 5448 | MarkingParity parity); |
| 5449 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5450 | DISALLOW_IMPLICIT_CONSTRUCTORS(Code); |
| 5451 | }; |
| 5452 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5453 | class AbstractCode : public HeapObject { |
| 5454 | public: |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 5455 | // All code kinds and INTERPRETED_FUNCTION. |
| 5456 | enum Kind { |
| 5457 | #define DEFINE_CODE_KIND_ENUM(name) name, |
| 5458 | CODE_KIND_LIST(DEFINE_CODE_KIND_ENUM) |
| 5459 | #undef DEFINE_CODE_KIND_ENUM |
| 5460 | INTERPRETED_FUNCTION, |
| 5461 | }; |
| 5462 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5463 | int SourcePosition(int offset); |
| 5464 | int SourceStatementPosition(int offset); |
| 5465 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 5466 | // Returns the address of the first instruction. |
| 5467 | inline Address instruction_start(); |
| 5468 | |
| 5469 | // Returns the address right after the last instruction. |
| 5470 | inline Address instruction_end(); |
| 5471 | |
| 5472 | // Returns the of the code instructions. |
| 5473 | inline int instruction_size(); |
| 5474 | |
| 5475 | // Returns true if pc is inside this object's instructions. |
| 5476 | inline bool contains(byte* pc); |
| 5477 | |
| 5478 | // Returns the AbstractCode::Kind of the code. |
| 5479 | inline Kind kind(); |
| 5480 | |
| 5481 | // Calculate the size of the code object to report for log events. This takes |
| 5482 | // the layout of the code object into account. |
| 5483 | inline int ExecutableSize(); |
| 5484 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5485 | DECLARE_CAST(AbstractCode) |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5486 | inline Code* GetCode(); |
| 5487 | inline BytecodeArray* GetBytecodeArray(); |
| 5488 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5489 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5490 | // Dependent code is a singly linked list of fixed arrays. Each array contains |
| 5491 | // code objects in weak cells for one dependent group. The suffix of the array |
| 5492 | // can be filled with the undefined value if the number of codes is less than |
| 5493 | // the length of the array. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5494 | // |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5495 | // +------+-----------------+--------+--------+-----+--------+-----------+-----+ |
| 5496 | // | next | count & group 1 | code 1 | code 2 | ... | code n | undefined | ... | |
| 5497 | // +------+-----------------+--------+--------+-----+--------+-----------+-----+ |
| 5498 | // | |
| 5499 | // V |
| 5500 | // +------+-----------------+--------+--------+-----+--------+-----------+-----+ |
| 5501 | // | next | count & group 2 | code 1 | code 2 | ... | code m | undefined | ... | |
| 5502 | // +------+-----------------+--------+--------+-----+--------+-----------+-----+ |
| 5503 | // | |
| 5504 | // V |
| 5505 | // empty_fixed_array() |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5506 | // |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5507 | // The list of fixed arrays is ordered by dependency groups. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5508 | |
| 5509 | class DependentCode: public FixedArray { |
| 5510 | public: |
| 5511 | enum DependencyGroup { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5512 | // Group of code that weakly embed this map and depend on being |
| 5513 | // deoptimized when the map is garbage collected. |
| 5514 | kWeakCodeGroup, |
| 5515 | // Group of code that embed a transition to this map, and depend on being |
| 5516 | // deoptimized when the transition is replaced by a new version. |
| 5517 | kTransitionGroup, |
| 5518 | // Group of code that omit run-time prototype checks for prototypes |
| 5519 | // described by this map. The group is deoptimized whenever an object |
| 5520 | // described by this map changes shape (and transitions to a new map), |
| 5521 | // possibly invalidating the assumptions embedded in the code. |
| 5522 | kPrototypeCheckGroup, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5523 | // Group of code that depends on global property values in property cells |
| 5524 | // not being changed. |
| 5525 | kPropertyCellChangedGroup, |
| 5526 | // Group of code that omit run-time type checks for the field(s) introduced |
| 5527 | // by this map. |
| 5528 | kFieldTypeGroup, |
| 5529 | // Group of code that omit run-time type checks for initial maps of |
| 5530 | // constructors. |
| 5531 | kInitialMapChangedGroup, |
| 5532 | // Group of code that depends on tenuring information in AllocationSites |
| 5533 | // not being changed. |
| 5534 | kAllocationSiteTenuringChangedGroup, |
| 5535 | // Group of code that depends on element transition information in |
| 5536 | // AllocationSites not being changed. |
| 5537 | kAllocationSiteTransitionChangedGroup |
| 5538 | }; |
| 5539 | |
| 5540 | static const int kGroupCount = kAllocationSiteTransitionChangedGroup + 1; |
| 5541 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5542 | bool Contains(DependencyGroup group, WeakCell* code_cell); |
| 5543 | bool IsEmpty(DependencyGroup group); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5544 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5545 | static Handle<DependentCode> InsertCompilationDependencies( |
| 5546 | Handle<DependentCode> entries, DependencyGroup group, |
| 5547 | Handle<Foreign> info); |
| 5548 | |
| 5549 | static Handle<DependentCode> InsertWeakCode(Handle<DependentCode> entries, |
| 5550 | DependencyGroup group, |
| 5551 | Handle<WeakCell> code_cell); |
| 5552 | |
| 5553 | void UpdateToFinishedCode(DependencyGroup group, Foreign* info, |
| 5554 | WeakCell* code_cell); |
| 5555 | |
| 5556 | void RemoveCompilationDependencies(DependentCode::DependencyGroup group, |
| 5557 | Foreign* info); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5558 | |
| 5559 | void DeoptimizeDependentCodeGroup(Isolate* isolate, |
| 5560 | DependentCode::DependencyGroup group); |
| 5561 | |
| 5562 | bool MarkCodeForDeoptimization(Isolate* isolate, |
| 5563 | DependentCode::DependencyGroup group); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5564 | |
| 5565 | // The following low-level accessors should only be used by this class |
| 5566 | // and the mark compact collector. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5567 | inline DependentCode* next_link(); |
| 5568 | inline void set_next_link(DependentCode* next); |
| 5569 | inline int count(); |
| 5570 | inline void set_count(int value); |
| 5571 | inline DependencyGroup group(); |
| 5572 | inline void set_group(DependencyGroup group); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5573 | inline Object* object_at(int i); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5574 | inline void set_object_at(int i, Object* object); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5575 | inline void clear_at(int i); |
| 5576 | inline void copy(int from, int to); |
| 5577 | DECLARE_CAST(DependentCode) |
| 5578 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5579 | static const char* DependencyGroupName(DependencyGroup group); |
| 5580 | static void SetMarkedForDeoptimization(Code* code, DependencyGroup group); |
| 5581 | |
| 5582 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5583 | static Handle<DependentCode> Insert(Handle<DependentCode> entries, |
| 5584 | DependencyGroup group, |
| 5585 | Handle<Object> object); |
| 5586 | static Handle<DependentCode> New(DependencyGroup group, Handle<Object> object, |
| 5587 | Handle<DependentCode> next); |
| 5588 | static Handle<DependentCode> EnsureSpace(Handle<DependentCode> entries); |
| 5589 | // Compact by removing cleared weak cells and return true if there was |
| 5590 | // any cleared weak cell. |
| 5591 | bool Compact(); |
| 5592 | static int Grow(int number_of_entries) { |
| 5593 | if (number_of_entries < 5) return number_of_entries + 1; |
| 5594 | return number_of_entries * 5 / 4; |
| 5595 | } |
| 5596 | inline int flags(); |
| 5597 | inline void set_flags(int flags); |
| 5598 | class GroupField : public BitField<int, 0, 3> {}; |
| 5599 | class CountField : public BitField<int, 3, 27> {}; |
| 5600 | STATIC_ASSERT(kGroupCount <= GroupField::kMax + 1); |
| 5601 | static const int kNextLinkIndex = 0; |
| 5602 | static const int kFlagsIndex = 1; |
| 5603 | static const int kCodesStartIndex = 2; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5604 | }; |
| 5605 | |
| 5606 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5607 | class PrototypeInfo; |
| 5608 | |
| 5609 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5610 | // All heap objects have a Map that describes their structure. |
| 5611 | // A Map contains information about: |
| 5612 | // - Size information about the object |
| 5613 | // - How to iterate over an object (for garbage collection) |
| 5614 | class Map: public HeapObject { |
| 5615 | public: |
| 5616 | // Instance size. |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 5617 | // Size in bytes or kVariableSizeSentinel if instances do not have |
| 5618 | // a fixed size. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5619 | inline int instance_size(); |
| 5620 | inline void set_instance_size(int value); |
| 5621 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5622 | // Only to clear an unused byte, remove once byte is used. |
| 5623 | inline void clear_unused(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5624 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5625 | // [inobject_properties_or_constructor_function_index]: Provides access |
| 5626 | // to the inobject properties in case of JSObject maps, or the constructor |
| 5627 | // function index in case of primitive maps. |
| 5628 | inline int inobject_properties_or_constructor_function_index(); |
| 5629 | inline void set_inobject_properties_or_constructor_function_index(int value); |
| 5630 | // Count of properties allocated in the object (JSObject only). |
| 5631 | inline int GetInObjectProperties(); |
| 5632 | inline void SetInObjectProperties(int value); |
| 5633 | // Index of the constructor function in the native context (primitives only), |
| 5634 | // or the special sentinel value to indicate that there is no object wrapper |
| 5635 | // for the primitive (i.e. in case of null or undefined). |
| 5636 | static const int kNoConstructorFunctionIndex = 0; |
| 5637 | inline int GetConstructorFunctionIndex(); |
| 5638 | inline void SetConstructorFunctionIndex(int value); |
| 5639 | static MaybeHandle<JSFunction> GetConstructorFunction( |
| 5640 | Handle<Map> map, Handle<Context> native_context); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5641 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 5642 | // Retrieve interceptors. |
| 5643 | inline InterceptorInfo* GetNamedInterceptor(); |
| 5644 | inline InterceptorInfo* GetIndexedInterceptor(); |
| 5645 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5646 | // Instance type. |
| 5647 | inline InstanceType instance_type(); |
| 5648 | inline void set_instance_type(InstanceType value); |
| 5649 | |
| 5650 | // Tells how many unused property fields are available in the |
| 5651 | // instance (only used for JSObject in fast mode). |
| 5652 | inline int unused_property_fields(); |
| 5653 | inline void set_unused_property_fields(int value); |
| 5654 | |
| 5655 | // Bit field. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5656 | inline byte bit_field() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5657 | inline void set_bit_field(byte value); |
| 5658 | |
| 5659 | // Bit field 2. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5660 | inline byte bit_field2() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5661 | inline void set_bit_field2(byte value); |
| 5662 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5663 | // Bit field 3. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5664 | inline uint32_t bit_field3() const; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5665 | inline void set_bit_field3(uint32_t bits); |
| 5666 | |
| 5667 | class EnumLengthBits: public BitField<int, |
| 5668 | 0, kDescriptorIndexBitCount> {}; // NOLINT |
| 5669 | class NumberOfOwnDescriptorsBits: public BitField<int, |
| 5670 | kDescriptorIndexBitCount, kDescriptorIndexBitCount> {}; // NOLINT |
| 5671 | STATIC_ASSERT(kDescriptorIndexBitCount + kDescriptorIndexBitCount == 20); |
| 5672 | class DictionaryMap : public BitField<bool, 20, 1> {}; |
| 5673 | class OwnsDescriptors : public BitField<bool, 21, 1> {}; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5674 | class HasHiddenPrototype : public BitField<bool, 22, 1> {}; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5675 | class Deprecated : public BitField<bool, 23, 1> {}; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5676 | class IsUnstable : public BitField<bool, 24, 1> {}; |
| 5677 | class IsMigrationTarget : public BitField<bool, 25, 1> {}; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 5678 | // Bit 26 is free. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5679 | class NewTargetIsBase : public BitField<bool, 27, 1> {}; |
| 5680 | // Bit 28 is free. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5681 | |
| 5682 | // Keep this bit field at the very end for better code in |
| 5683 | // Builtins::kJSConstructStubGeneric stub. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5684 | // This counter is used for in-object slack tracking. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5685 | // The in-object slack tracking is considered enabled when the counter is |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5686 | // non zero. The counter only has a valid count for initial maps. For |
| 5687 | // transitioned maps only kNoSlackTracking has a meaning, namely that inobject |
| 5688 | // slack tracking already finished for the transition tree. Any other value |
| 5689 | // indicates that either inobject slack tracking is still in progress, or that |
| 5690 | // the map isn't part of the transition tree anymore. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5691 | class ConstructionCounter : public BitField<int, 29, 3> {}; |
| 5692 | static const int kSlackTrackingCounterStart = 7; |
| 5693 | static const int kSlackTrackingCounterEnd = 1; |
| 5694 | static const int kNoSlackTracking = 0; |
| 5695 | STATIC_ASSERT(kSlackTrackingCounterStart <= ConstructionCounter::kMax); |
| 5696 | |
| 5697 | |
| 5698 | // Inobject slack tracking is the way to reclaim unused inobject space. |
| 5699 | // |
| 5700 | // The instance size is initially determined by adding some slack to |
| 5701 | // expected_nof_properties (to allow for a few extra properties added |
| 5702 | // after the constructor). There is no guarantee that the extra space |
| 5703 | // will not be wasted. |
| 5704 | // |
| 5705 | // Here is the algorithm to reclaim the unused inobject space: |
| 5706 | // - Detect the first constructor call for this JSFunction. |
| 5707 | // When it happens enter the "in progress" state: initialize construction |
| 5708 | // counter in the initial_map. |
| 5709 | // - While the tracking is in progress initialize unused properties of a new |
| 5710 | // object with one_pointer_filler_map instead of undefined_value (the "used" |
| 5711 | // part is initialized with undefined_value as usual). This way they can |
| 5712 | // be resized quickly and safely. |
| 5713 | // - Once enough objects have been created compute the 'slack' |
| 5714 | // (traverse the map transition tree starting from the |
| 5715 | // initial_map and find the lowest value of unused_property_fields). |
| 5716 | // - Traverse the transition tree again and decrease the instance size |
| 5717 | // of every map. Existing objects will resize automatically (they are |
| 5718 | // filled with one_pointer_filler_map). All further allocations will |
| 5719 | // use the adjusted instance size. |
| 5720 | // - SharedFunctionInfo's expected_nof_properties left unmodified since |
| 5721 | // allocations made using different closures could actually create different |
| 5722 | // kind of objects (see prototype inheritance pattern). |
| 5723 | // |
| 5724 | // Important: inobject slack tracking is not attempted during the snapshot |
| 5725 | // creation. |
| 5726 | |
| 5727 | static const int kGenerousAllocationCount = |
| 5728 | kSlackTrackingCounterStart - kSlackTrackingCounterEnd + 1; |
| 5729 | |
| 5730 | // Starts the tracking by initializing object constructions countdown counter. |
| 5731 | void StartInobjectSlackTracking(); |
| 5732 | |
| 5733 | // True if the object constructions countdown counter is a range |
| 5734 | // [kSlackTrackingCounterEnd, kSlackTrackingCounterStart]. |
| 5735 | inline bool IsInobjectSlackTrackingInProgress(); |
| 5736 | |
| 5737 | // Does the tracking step. |
| 5738 | inline void InobjectSlackTrackingStep(); |
| 5739 | |
| 5740 | // Completes inobject slack tracking for the transition tree starting at this |
| 5741 | // initial map. |
| 5742 | void CompleteInobjectSlackTracking(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5743 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5744 | // Tells whether the object in the prototype property will be used |
| 5745 | // for instances created from this function. If the prototype |
| 5746 | // property is set to a value that is not a JSObject, the prototype |
| 5747 | // property will not be used to create instances of the function. |
| 5748 | // See ECMA-262, 13.2.2. |
| 5749 | inline void set_non_instance_prototype(bool value); |
| 5750 | inline bool has_non_instance_prototype(); |
| 5751 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5752 | // Tells whether the instance has a [[Construct]] internal method. |
| 5753 | // This property is implemented according to ES6, section 7.2.4. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5754 | inline void set_is_constructor(bool value); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5755 | inline bool is_constructor() const; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5756 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5757 | // Tells whether the instance with this map has a hidden prototype. |
| 5758 | inline void set_has_hidden_prototype(bool value); |
| 5759 | inline bool has_hidden_prototype() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5760 | |
| 5761 | // Records and queries whether the instance has a named interceptor. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5762 | inline void set_has_named_interceptor(); |
| 5763 | inline bool has_named_interceptor(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5764 | |
| 5765 | // Records and queries whether the instance has an indexed interceptor. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5766 | inline void set_has_indexed_interceptor(); |
| 5767 | inline bool has_indexed_interceptor(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5768 | |
| 5769 | // Tells whether the instance is undetectable. |
| 5770 | // An undetectable object is a special class of JSObject: 'typeof' operator |
| 5771 | // returns undefined, ToBoolean returns false. Otherwise it behaves like |
| 5772 | // a normal JS object. It is useful for implementing undetectable |
| 5773 | // document.all in Firefox & Safari. |
| 5774 | // See https://bugzilla.mozilla.org/show_bug.cgi?id=248549. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5775 | inline void set_is_undetectable(); |
| 5776 | inline bool is_undetectable(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5777 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5778 | // Tells whether the instance has a call-as-function handler. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5779 | inline void set_is_observed(); |
| 5780 | inline bool is_observed(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5781 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5782 | // Tells whether the instance has a [[Call]] internal method. |
| 5783 | // This property is implemented according to ES6, section 7.2.3. |
| 5784 | inline void set_is_callable(); |
| 5785 | inline bool is_callable() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5786 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5787 | inline void set_new_target_is_base(bool value); |
| 5788 | inline bool new_target_is_base(); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 5789 | inline void set_is_extensible(bool value); |
| 5790 | inline bool is_extensible(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5791 | inline void set_is_prototype_map(bool value); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5792 | inline bool is_prototype_map() const; |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 5793 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5794 | inline void set_elements_kind(ElementsKind elements_kind); |
| 5795 | inline ElementsKind elements_kind(); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 5796 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5797 | // Tells whether the instance has fast elements that are only Smis. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5798 | inline bool has_fast_smi_elements(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5799 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 5800 | // Tells whether the instance has fast elements. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5801 | inline bool has_fast_object_elements(); |
| 5802 | inline bool has_fast_smi_or_object_elements(); |
| 5803 | inline bool has_fast_double_elements(); |
| 5804 | inline bool has_fast_elements(); |
| 5805 | inline bool has_sloppy_arguments_elements(); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5806 | inline bool has_fast_string_wrapper_elements(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5807 | inline bool has_fixed_typed_array_elements(); |
| 5808 | inline bool has_dictionary_elements(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5809 | |
| 5810 | static bool IsValidElementsTransition(ElementsKind from_kind, |
| 5811 | ElementsKind to_kind); |
| 5812 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5813 | // Returns true if the current map doesn't have DICTIONARY_ELEMENTS but if a |
| 5814 | // map with DICTIONARY_ELEMENTS was found in the prototype chain. |
| 5815 | bool DictionaryElementsInPrototypeChainOnly(); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5816 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5817 | inline Map* ElementsTransitionMap(); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5818 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5819 | inline FixedArrayBase* GetInitialElements(); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5820 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5821 | // [raw_transitions]: Provides access to the transitions storage field. |
| 5822 | // Don't call set_raw_transitions() directly to overwrite transitions, use |
| 5823 | // the TransitionArray::ReplaceTransitions() wrapper instead! |
| 5824 | DECL_ACCESSORS(raw_transitions, Object) |
| 5825 | // [prototype_info]: Per-prototype metadata. Aliased with transitions |
| 5826 | // (which prototype maps don't have). |
| 5827 | DECL_ACCESSORS(prototype_info, Object) |
| 5828 | // PrototypeInfo is created lazily using this helper (which installs it on |
| 5829 | // the given prototype's map). |
| 5830 | static Handle<PrototypeInfo> GetOrCreatePrototypeInfo( |
| 5831 | Handle<JSObject> prototype, Isolate* isolate); |
| 5832 | static Handle<PrototypeInfo> GetOrCreatePrototypeInfo( |
| 5833 | Handle<Map> prototype_map, Isolate* isolate); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5834 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5835 | // [prototype chain validity cell]: Associated with a prototype object, |
| 5836 | // stored in that object's map's PrototypeInfo, indicates that prototype |
| 5837 | // chains through this object are currently valid. The cell will be |
| 5838 | // invalidated and replaced when the prototype chain changes. |
| 5839 | static Handle<Cell> GetOrCreatePrototypeChainValidityCell(Handle<Map> map, |
| 5840 | Isolate* isolate); |
| 5841 | static const int kPrototypeChainValid = 0; |
| 5842 | static const int kPrototypeChainInvalid = 1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5843 | |
| 5844 | Map* FindRootMap(); |
| 5845 | Map* FindFieldOwner(int descriptor); |
| 5846 | |
| 5847 | inline int GetInObjectPropertyOffset(int index); |
| 5848 | |
| 5849 | int NumberOfFields(); |
| 5850 | |
| 5851 | // TODO(ishell): candidate with JSObject::MigrateToMap(). |
| 5852 | bool InstancesNeedRewriting(Map* target, int target_number_of_fields, |
| 5853 | int target_inobject, int target_unused, |
| 5854 | int* old_number_of_fields); |
| 5855 | // TODO(ishell): moveit! |
| 5856 | static Handle<Map> GeneralizeAllFieldRepresentations(Handle<Map> map); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5857 | MUST_USE_RESULT static Handle<FieldType> GeneralizeFieldType( |
| 5858 | Representation rep1, Handle<FieldType> type1, Representation rep2, |
| 5859 | Handle<FieldType> type2, Isolate* isolate); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5860 | static void GeneralizeFieldType(Handle<Map> map, int modify_index, |
| 5861 | Representation new_representation, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5862 | Handle<FieldType> new_field_type); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5863 | static Handle<Map> ReconfigureProperty(Handle<Map> map, int modify_index, |
| 5864 | PropertyKind new_kind, |
| 5865 | PropertyAttributes new_attributes, |
| 5866 | Representation new_representation, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5867 | Handle<FieldType> new_field_type, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5868 | StoreMode store_mode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5869 | static Handle<Map> CopyGeneralizeAllRepresentations( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5870 | Handle<Map> map, int modify_index, StoreMode store_mode, |
| 5871 | PropertyKind kind, PropertyAttributes attributes, const char* reason); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5872 | |
| 5873 | static Handle<Map> PrepareForDataProperty(Handle<Map> old_map, |
| 5874 | int descriptor_number, |
| 5875 | Handle<Object> value); |
| 5876 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5877 | static Handle<Map> Normalize(Handle<Map> map, PropertyNormalizationMode mode, |
| 5878 | const char* reason); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5879 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5880 | // Tells whether the map is used for JSObjects in dictionary mode (ie |
| 5881 | // normalized objects, ie objects for which HasFastProperties returns false). |
| 5882 | // A map can never be used for both dictionary mode and fast mode JSObjects. |
| 5883 | // False by default and for HeapObjects that are not JSObjects. |
| 5884 | inline void set_dictionary_map(bool value); |
| 5885 | inline bool is_dictionary_map(); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5886 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5887 | // Tells whether the instance needs security checks when accessing its |
| 5888 | // properties. |
| 5889 | inline void set_is_access_check_needed(bool access_check_needed); |
| 5890 | inline bool is_access_check_needed(); |
| 5891 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5892 | // Returns true if map has a non-empty stub code cache. |
| 5893 | inline bool has_code_cache(); |
| 5894 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5895 | // [prototype]: implicit prototype object. |
| 5896 | DECL_ACCESSORS(prototype, Object) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5897 | // TODO(jkummerow): make set_prototype private. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5898 | static void SetPrototype( |
| 5899 | Handle<Map> map, Handle<Object> prototype, |
| 5900 | PrototypeOptimizationMode proto_mode = FAST_PROTOTYPE); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5901 | |
| 5902 | // [constructor]: points back to the function responsible for this map. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5903 | // The field overlaps with the back pointer. All maps in a transition tree |
| 5904 | // have the same constructor, so maps with back pointers can walk the |
| 5905 | // back pointer chain until they find the map holding their constructor. |
| 5906 | DECL_ACCESSORS(constructor_or_backpointer, Object) |
| 5907 | inline Object* GetConstructor() const; |
| 5908 | inline void SetConstructor(Object* constructor, |
| 5909 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| 5910 | // [back pointer]: points back to the parent map from which a transition |
| 5911 | // leads to this map. The field overlaps with the constructor (see above). |
| 5912 | inline Object* GetBackPointer(); |
| 5913 | inline void SetBackPointer(Object* value, |
| 5914 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5915 | |
| 5916 | // [instance descriptors]: describes the object. |
| 5917 | DECL_ACCESSORS(instance_descriptors, DescriptorArray) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5918 | |
| 5919 | // [layout descriptor]: describes the object layout. |
| 5920 | DECL_ACCESSORS(layout_descriptor, LayoutDescriptor) |
| 5921 | // |layout descriptor| accessor which can be used from GC. |
| 5922 | inline LayoutDescriptor* layout_descriptor_gc_safe(); |
| 5923 | inline bool HasFastPointerLayout() const; |
| 5924 | |
| 5925 | // |layout descriptor| accessor that is safe to call even when |
| 5926 | // FLAG_unbox_double_fields is disabled (in this case Map does not contain |
| 5927 | // |layout_descriptor| field at all). |
| 5928 | inline LayoutDescriptor* GetLayoutDescriptor(); |
| 5929 | |
| 5930 | inline void UpdateDescriptors(DescriptorArray* descriptors, |
| 5931 | LayoutDescriptor* layout_descriptor); |
| 5932 | inline void InitializeDescriptors(DescriptorArray* descriptors, |
| 5933 | LayoutDescriptor* layout_descriptor); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5934 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5935 | // [stub cache]: contains stubs compiled for this map. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5936 | DECL_ACCESSORS(code_cache, Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5937 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5938 | // [dependent code]: list of optimized codes that weakly embed this map. |
| 5939 | DECL_ACCESSORS(dependent_code, DependentCode) |
| 5940 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5941 | // [weak cell cache]: cache that stores a weak cell pointing to this map. |
| 5942 | DECL_ACCESSORS(weak_cell_cache, Object) |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5943 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5944 | inline PropertyDetails GetLastDescriptorDetails(); |
| 5945 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5946 | inline int LastAdded(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5947 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5948 | inline int NumberOfOwnDescriptors(); |
| 5949 | inline void SetNumberOfOwnDescriptors(int number); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5950 | |
| 5951 | inline Cell* RetrieveDescriptorsPointer(); |
| 5952 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5953 | // Checks whether all properties are stored either in the map or on the object |
| 5954 | // (inobject, properties, or elements backing store), requiring no special |
| 5955 | // checks. |
| 5956 | bool OnlyHasSimpleProperties(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5957 | inline int EnumLength(); |
| 5958 | inline void SetEnumLength(int length); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5959 | |
| 5960 | inline bool owns_descriptors(); |
| 5961 | inline void set_owns_descriptors(bool owns_descriptors); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5962 | inline void mark_unstable(); |
| 5963 | inline bool is_stable(); |
| 5964 | inline void set_migration_target(bool value); |
| 5965 | inline bool is_migration_target(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5966 | inline void set_construction_counter(int value); |
| 5967 | inline int construction_counter(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5968 | inline void deprecate(); |
| 5969 | inline bool is_deprecated(); |
| 5970 | inline bool CanBeDeprecated(); |
| 5971 | // Returns a non-deprecated version of the input. If the input was not |
| 5972 | // deprecated, it is directly returned. Otherwise, the non-deprecated version |
| 5973 | // 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] | 5974 | // descriptor array of the map. Returns MaybeHandle<Map>() if no updated map |
| 5975 | // is found. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5976 | static MaybeHandle<Map> TryUpdate(Handle<Map> map) WARN_UNUSED_RESULT; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5977 | |
| 5978 | // Returns a non-deprecated version of the input. This method may deprecate |
| 5979 | // existing maps along the way if encodings conflict. Not for use while |
| 5980 | // gathering type feedback. Use TryUpdate in those cases instead. |
| 5981 | static Handle<Map> Update(Handle<Map> map); |
| 5982 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5983 | static inline Handle<Map> CopyInitialMap(Handle<Map> map); |
| 5984 | static Handle<Map> CopyInitialMap(Handle<Map> map, int instance_size, |
| 5985 | int in_object_properties, |
| 5986 | int unused_property_fields); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5987 | static Handle<Map> CopyDropDescriptors(Handle<Map> map); |
| 5988 | static Handle<Map> CopyInsertDescriptor(Handle<Map> map, |
| 5989 | Descriptor* descriptor, |
| 5990 | TransitionFlag flag); |
| 5991 | |
| 5992 | MUST_USE_RESULT static MaybeHandle<Map> CopyWithField( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 5993 | Handle<Map> map, Handle<Name> name, Handle<FieldType> type, |
| 5994 | PropertyAttributes attributes, Representation representation, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5995 | TransitionFlag flag); |
| 5996 | |
| 5997 | MUST_USE_RESULT static MaybeHandle<Map> CopyWithConstant( |
| 5998 | Handle<Map> map, |
| 5999 | Handle<Name> name, |
| 6000 | Handle<Object> constant, |
| 6001 | PropertyAttributes attributes, |
| 6002 | TransitionFlag flag); |
| 6003 | |
| 6004 | // Returns a new map with all transitions dropped from the given map and |
| 6005 | // the ElementsKind set. |
| 6006 | static Handle<Map> TransitionElementsTo(Handle<Map> map, |
| 6007 | ElementsKind to_kind); |
| 6008 | |
| 6009 | static Handle<Map> AsElementsKind(Handle<Map> map, ElementsKind kind); |
| 6010 | |
| 6011 | static Handle<Map> CopyAsElementsKind(Handle<Map> map, |
| 6012 | ElementsKind kind, |
| 6013 | TransitionFlag flag); |
| 6014 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6015 | static Handle<Map> AsLanguageMode(Handle<Map> initial_map, |
| 6016 | LanguageMode language_mode, |
| 6017 | FunctionKind kind); |
| 6018 | |
| 6019 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6020 | static Handle<Map> CopyForObserved(Handle<Map> map); |
| 6021 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6022 | static Handle<Map> CopyForPreventExtensions(Handle<Map> map, |
| 6023 | PropertyAttributes attrs_to_add, |
| 6024 | Handle<Symbol> transition_marker, |
| 6025 | const char* reason); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6026 | |
| 6027 | static Handle<Map> FixProxy(Handle<Map> map, InstanceType type, int size); |
| 6028 | |
| 6029 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6030 | // Maximal number of fast properties. Used to restrict the number of map |
| 6031 | // transitions to avoid an explosion in the number of maps for objects used as |
| 6032 | // dictionaries. |
| 6033 | inline bool TooManyFastProperties(StoreFromKeyed store_mode); |
| 6034 | static Handle<Map> TransitionToDataProperty(Handle<Map> map, |
| 6035 | Handle<Name> name, |
| 6036 | Handle<Object> value, |
| 6037 | PropertyAttributes attributes, |
| 6038 | StoreFromKeyed store_mode); |
| 6039 | static Handle<Map> TransitionToAccessorProperty( |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 6040 | Handle<Map> map, Handle<Name> name, int descriptor, |
| 6041 | AccessorComponent component, Handle<Object> accessor, |
| 6042 | PropertyAttributes attributes); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6043 | static Handle<Map> ReconfigureExistingProperty(Handle<Map> map, |
| 6044 | int descriptor, |
| 6045 | PropertyKind kind, |
| 6046 | PropertyAttributes attributes); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6047 | |
| 6048 | inline void AppendDescriptor(Descriptor* desc); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6049 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6050 | // Returns a copy of the map, prepared for inserting into the transition |
| 6051 | // tree (if the |map| owns descriptors then the new one will share |
| 6052 | // descriptors with |map|). |
| 6053 | static Handle<Map> CopyForTransition(Handle<Map> map, const char* reason); |
| 6054 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6055 | // Returns a copy of the map, with all transitions dropped from the |
| 6056 | // instance descriptors. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6057 | static Handle<Map> Copy(Handle<Map> map, const char* reason); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6058 | static Handle<Map> Create(Isolate* isolate, int inobject_properties); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6059 | |
| 6060 | // Returns the next free property index (only valid for FAST MODE). |
| 6061 | int NextFreePropertyIndex(); |
| 6062 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 6063 | // Returns the number of properties described in instance_descriptors |
| 6064 | // filtering out properties with the specified attributes. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6065 | int NumberOfDescribedProperties(DescriptorFlag which = OWN_DESCRIPTORS, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6066 | PropertyFilter filter = ALL_PROPERTIES); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6067 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6068 | DECLARE_CAST(Map) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6069 | |
| 6070 | // Code cache operations. |
| 6071 | |
| 6072 | // Clears the code cache. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 6073 | inline void ClearCodeCache(Heap* heap); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6074 | |
| 6075 | // Update code cache. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 6076 | static void UpdateCodeCache(Handle<Map> map, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6077 | Handle<Name> name, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 6078 | Handle<Code> code); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6079 | |
| 6080 | // Extend the descriptor array of the map with the list of descriptors. |
| 6081 | // In case of duplicates, the latest descriptor is used. |
| 6082 | static void AppendCallbackDescriptors(Handle<Map> map, |
| 6083 | Handle<Object> descriptors); |
| 6084 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6085 | static inline int SlackForArraySize(int old_size, int size_limit); |
| 6086 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6087 | static void EnsureDescriptorSlack(Handle<Map> map, int slack); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6088 | |
| 6089 | // Returns the found code or undefined if absent. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6090 | Object* FindInCodeCache(Name* name, Code::Flags flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6091 | |
| 6092 | // Returns the non-negative index of the code object if it is in the |
| 6093 | // cache and -1 otherwise. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 6094 | int IndexInCodeCache(Object* name, Code* code); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6095 | |
| 6096 | // Removes a code object from the code cache at the given index. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6097 | void RemoveFromCodeCache(Name* name, Code* code, int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6098 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6099 | // Computes a hash value for this map, to be used in HashTables and such. |
| 6100 | int Hash(); |
| 6101 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 6102 | // Returns the map that this map transitions to if its elements_kind |
| 6103 | // is changed to |elements_kind|, or NULL if no such map is cached yet. |
| 6104 | // |safe_to_add_transitions| is set to false if adding transitions is not |
| 6105 | // allowed. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6106 | Map* LookupElementsTransitionMap(ElementsKind elements_kind); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 6107 | |
| 6108 | // Returns the transitioned map for this map with the most generic |
| 6109 | // elements_kind that's found in |candidates|, or null handle if no match is |
| 6110 | // found at all. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6111 | static Handle<Map> FindTransitionedMap(Handle<Map> map, |
| 6112 | MapHandleList* candidates); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 6113 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6114 | inline bool CanTransition(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6115 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6116 | inline bool IsBooleanMap(); |
| 6117 | inline bool IsPrimitiveMap(); |
| 6118 | inline bool IsJSReceiverMap(); |
| 6119 | inline bool IsJSObjectMap(); |
| 6120 | inline bool IsJSArrayMap(); |
| 6121 | inline bool IsJSFunctionMap(); |
| 6122 | inline bool IsStringMap(); |
| 6123 | inline bool IsJSProxyMap(); |
| 6124 | inline bool IsJSGlobalProxyMap(); |
| 6125 | inline bool IsJSGlobalObjectMap(); |
| 6126 | inline bool IsJSTypedArrayMap(); |
| 6127 | inline bool IsJSDataViewMap(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6128 | |
| 6129 | inline bool CanOmitMapChecks(); |
| 6130 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6131 | static void AddDependentCode(Handle<Map> map, |
| 6132 | DependentCode::DependencyGroup group, |
| 6133 | Handle<Code> code); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6134 | |
| 6135 | bool IsMapInArrayPrototypeChain(); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 6136 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6137 | static Handle<WeakCell> WeakCellForMap(Handle<Map> map); |
| 6138 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6139 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6140 | DECLARE_PRINTER(Map) |
| 6141 | DECLARE_VERIFIER(Map) |
| 6142 | |
| 6143 | #ifdef VERIFY_HEAP |
| 6144 | void DictionaryMapVerify(); |
| 6145 | void VerifyOmittedMapChecks(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6146 | #endif |
| 6147 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 6148 | inline int visitor_id(); |
| 6149 | inline void set_visitor_id(int visitor_id); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 6150 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6151 | static Handle<Map> TransitionToPrototype(Handle<Map> map, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6152 | Handle<Object> prototype, |
| 6153 | PrototypeOptimizationMode mode); |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 6154 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6155 | static const int kMaxPreAllocatedPropertyFields = 255; |
| 6156 | |
| 6157 | // Layout description. |
| 6158 | static const int kInstanceSizesOffset = HeapObject::kHeaderSize; |
| 6159 | static const int kInstanceAttributesOffset = kInstanceSizesOffset + kIntSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6160 | static const int kBitField3Offset = kInstanceAttributesOffset + kIntSize; |
| 6161 | static const int kPrototypeOffset = kBitField3Offset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6162 | static const int kConstructorOrBackPointerOffset = |
| 6163 | kPrototypeOffset + kPointerSize; |
| 6164 | // When there is only one transition, it is stored directly in this field; |
| 6165 | // otherwise a transition array is used. |
| 6166 | // For prototype maps, this slot is used to store this map's PrototypeInfo |
| 6167 | // struct. |
| 6168 | static const int kTransitionsOrPrototypeInfoOffset = |
| 6169 | kConstructorOrBackPointerOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6170 | static const int kDescriptorsOffset = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6171 | kTransitionsOrPrototypeInfoOffset + kPointerSize; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6172 | #if V8_DOUBLE_FIELDS_UNBOXING |
| 6173 | static const int kLayoutDecriptorOffset = kDescriptorsOffset + kPointerSize; |
| 6174 | static const int kCodeCacheOffset = kLayoutDecriptorOffset + kPointerSize; |
| 6175 | #else |
| 6176 | static const int kLayoutDecriptorOffset = 1; // Must not be ever accessed. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6177 | static const int kCodeCacheOffset = kDescriptorsOffset + kPointerSize; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6178 | #endif |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6179 | static const int kDependentCodeOffset = kCodeCacheOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6180 | static const int kWeakCellCacheOffset = kDependentCodeOffset + kPointerSize; |
| 6181 | static const int kSize = kWeakCellCacheOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 6182 | |
| 6183 | // Layout of pointer fields. Heap iteration code relies on them |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 6184 | // being continuously allocated. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 6185 | static const int kPointerFieldsBeginOffset = Map::kPrototypeOffset; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6186 | static const int kPointerFieldsEndOffset = kSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6187 | |
| 6188 | // Byte offsets within kInstanceSizesOffset. |
| 6189 | static const int kInstanceSizeOffset = kInstanceSizesOffset + 0; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6190 | static const int kInObjectPropertiesOrConstructorFunctionIndexByte = 1; |
| 6191 | static const int kInObjectPropertiesOrConstructorFunctionIndexOffset = |
| 6192 | kInstanceSizesOffset + kInObjectPropertiesOrConstructorFunctionIndexByte; |
| 6193 | // Note there is one byte available for use here. |
| 6194 | static const int kUnusedByte = 2; |
| 6195 | static const int kUnusedOffset = kInstanceSizesOffset + kUnusedByte; |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 6196 | static const int kVisitorIdByte = 3; |
| 6197 | static const int kVisitorIdOffset = kInstanceSizesOffset + kVisitorIdByte; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6198 | |
| 6199 | // Byte offsets within kInstanceAttributesOffset attributes. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6200 | #if V8_TARGET_LITTLE_ENDIAN |
| 6201 | // Order instance type and bit field together such that they can be loaded |
| 6202 | // together as a 16-bit word with instance type in the lower 8 bits regardless |
| 6203 | // of endianess. Also provide endian-independent offset to that 16-bit word. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6204 | static const int kInstanceTypeOffset = kInstanceAttributesOffset + 0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6205 | static const int kBitFieldOffset = kInstanceAttributesOffset + 1; |
| 6206 | #else |
| 6207 | static const int kBitFieldOffset = kInstanceAttributesOffset + 0; |
| 6208 | static const int kInstanceTypeOffset = kInstanceAttributesOffset + 1; |
| 6209 | #endif |
| 6210 | static const int kInstanceTypeAndBitFieldOffset = |
| 6211 | kInstanceAttributesOffset + 0; |
| 6212 | static const int kBitField2Offset = kInstanceAttributesOffset + 2; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6213 | static const int kUnusedPropertyFieldsByte = 3; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6214 | static const int kUnusedPropertyFieldsOffset = kInstanceAttributesOffset + 3; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6215 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6216 | STATIC_ASSERT(kInstanceTypeAndBitFieldOffset == |
| 6217 | Internals::kMapInstanceTypeAndBitFieldOffset); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6218 | |
| 6219 | // Bit positions for bit field. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6220 | static const int kHasNonInstancePrototype = 0; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6221 | static const int kIsCallable = 1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6222 | static const int kHasNamedInterceptor = 2; |
| 6223 | static const int kHasIndexedInterceptor = 3; |
| 6224 | static const int kIsUndetectable = 4; |
| 6225 | static const int kIsObserved = 5; |
| 6226 | static const int kIsAccessCheckNeeded = 6; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6227 | static const int kIsConstructor = 7; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6228 | |
| 6229 | // Bit positions for bit field 2 |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 6230 | static const int kIsExtensible = 0; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6231 | // Bit 1 is free. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6232 | class IsPrototypeMapBits : public BitField<bool, 2, 1> {}; |
| 6233 | class ElementsKindBits: public BitField<ElementsKind, 3, 5> {}; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6234 | |
| 6235 | // Derived values from bit field 2 |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6236 | static const int8_t kMaximumBitField2FastElementValue = static_cast<int8_t>( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6237 | (FAST_ELEMENTS + 1) << Map::ElementsKindBits::kShift) - 1; |
| 6238 | static const int8_t kMaximumBitField2FastSmiElementValue = |
| 6239 | static_cast<int8_t>((FAST_SMI_ELEMENTS + 1) << |
| 6240 | Map::ElementsKindBits::kShift) - 1; |
| 6241 | static const int8_t kMaximumBitField2FastHoleyElementValue = |
| 6242 | static_cast<int8_t>((FAST_HOLEY_ELEMENTS + 1) << |
| 6243 | Map::ElementsKindBits::kShift) - 1; |
| 6244 | static const int8_t kMaximumBitField2FastHoleySmiElementValue = |
| 6245 | static_cast<int8_t>((FAST_HOLEY_SMI_ELEMENTS + 1) << |
| 6246 | Map::ElementsKindBits::kShift) - 1; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6247 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 6248 | typedef FixedBodyDescriptor<kPointerFieldsBeginOffset, |
| 6249 | kPointerFieldsEndOffset, |
| 6250 | kSize> BodyDescriptor; |
| 6251 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6252 | // Compares this map to another to see if they describe equivalent objects. |
| 6253 | // If |mode| is set to CLEAR_INOBJECT_PROPERTIES, |other| is treated as if |
| 6254 | // it had exactly zero inobject properties. |
| 6255 | // The "shared" flags of both this map and |other| are ignored. |
| 6256 | bool EquivalentToForNormalization(Map* other, PropertyNormalizationMode mode); |
| 6257 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6258 | // Returns true if given field is unboxed double. |
| 6259 | inline bool IsUnboxedDoubleField(FieldIndex index); |
| 6260 | |
| 6261 | #if TRACE_MAPS |
| 6262 | static void TraceTransition(const char* what, Map* from, Map* to, Name* name); |
| 6263 | static void TraceAllTransitions(Map* map); |
| 6264 | #endif |
| 6265 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6266 | static inline Handle<Map> AddMissingTransitionsForTesting( |
| 6267 | Handle<Map> split_map, Handle<DescriptorArray> descriptors, |
| 6268 | Handle<LayoutDescriptor> full_layout_descriptor); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6269 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6270 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6271 | static void ConnectTransition(Handle<Map> parent, Handle<Map> child, |
| 6272 | Handle<Name> name, SimpleTransitionFlag flag); |
| 6273 | |
| 6274 | bool EquivalentToForTransition(Map* other); |
| 6275 | static Handle<Map> RawCopy(Handle<Map> map, int instance_size); |
| 6276 | static Handle<Map> ShareDescriptor(Handle<Map> map, |
| 6277 | Handle<DescriptorArray> descriptors, |
| 6278 | Descriptor* descriptor); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6279 | static Handle<Map> AddMissingTransitions( |
| 6280 | Handle<Map> map, Handle<DescriptorArray> descriptors, |
| 6281 | Handle<LayoutDescriptor> full_layout_descriptor); |
| 6282 | static void InstallDescriptors( |
| 6283 | Handle<Map> parent_map, Handle<Map> child_map, int new_descriptor, |
| 6284 | Handle<DescriptorArray> descriptors, |
| 6285 | Handle<LayoutDescriptor> full_layout_descriptor); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6286 | static Handle<Map> CopyAddDescriptor(Handle<Map> map, |
| 6287 | Descriptor* descriptor, |
| 6288 | TransitionFlag flag); |
| 6289 | static Handle<Map> CopyReplaceDescriptors( |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6290 | Handle<Map> map, Handle<DescriptorArray> descriptors, |
| 6291 | Handle<LayoutDescriptor> layout_descriptor, TransitionFlag flag, |
| 6292 | MaybeHandle<Name> maybe_name, const char* reason, |
| 6293 | SimpleTransitionFlag simple_flag); |
| 6294 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6295 | static Handle<Map> CopyReplaceDescriptor(Handle<Map> map, |
| 6296 | Handle<DescriptorArray> descriptors, |
| 6297 | Descriptor* descriptor, |
| 6298 | int index, |
| 6299 | TransitionFlag flag); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6300 | static MUST_USE_RESULT MaybeHandle<Map> TryReconfigureExistingProperty( |
| 6301 | Handle<Map> map, int descriptor, PropertyKind kind, |
| 6302 | PropertyAttributes attributes, const char** reason); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6303 | |
| 6304 | static Handle<Map> CopyNormalized(Handle<Map> map, |
| 6305 | PropertyNormalizationMode mode); |
| 6306 | |
| 6307 | // Fires when the layout of an object with a leaf map changes. |
| 6308 | // This includes adding transitions to the leaf map or changing |
| 6309 | // the descriptor array. |
| 6310 | inline void NotifyLeafMapLayoutChange(); |
| 6311 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6312 | void DeprecateTransitionTree(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6313 | |
| 6314 | void ReplaceDescriptors(DescriptorArray* new_descriptors, |
| 6315 | LayoutDescriptor* new_layout_descriptor); |
| 6316 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6317 | |
| 6318 | Map* FindLastMatchMap(int verbatim, int length, DescriptorArray* descriptors); |
| 6319 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6320 | // Update field type of the given descriptor to new representation and new |
| 6321 | // type. The type must be prepared for storing in descriptor array: |
| 6322 | // 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] | 6323 | void UpdateFieldType(int descriptor_number, Handle<Name> name, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6324 | Representation new_representation, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6325 | Handle<Object> new_wrapped_type); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6326 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6327 | void PrintReconfiguration(FILE* file, int modify_index, PropertyKind kind, |
| 6328 | PropertyAttributes attributes); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 6329 | void PrintGeneralization(FILE* file, const char* reason, int modify_index, |
| 6330 | int split, int descriptors, bool constant_to_field, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6331 | Representation old_representation, |
| 6332 | Representation new_representation, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 6333 | MaybeHandle<FieldType> old_field_type, |
| 6334 | MaybeHandle<Object> old_value, |
| 6335 | MaybeHandle<FieldType> new_field_type, |
| 6336 | MaybeHandle<Object> new_value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6337 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6338 | static const int kFastPropertiesSoftLimit = 12; |
| 6339 | static const int kMaxFastProperties = 128; |
| 6340 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6341 | DISALLOW_IMPLICIT_CONSTRUCTORS(Map); |
| 6342 | }; |
| 6343 | |
| 6344 | |
| 6345 | // An abstract superclass, a marker class really, for simple structure classes. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6346 | // It doesn't carry much functionality but allows struct classes to be |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6347 | // identified in the type system. |
| 6348 | class Struct: public HeapObject { |
| 6349 | public: |
| 6350 | inline void InitializeBody(int object_size); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6351 | DECLARE_CAST(Struct) |
| 6352 | }; |
| 6353 | |
| 6354 | |
| 6355 | // A simple one-element struct, useful where smis need to be boxed. |
| 6356 | class Box : public Struct { |
| 6357 | public: |
| 6358 | // [value]: the boxed contents. |
| 6359 | DECL_ACCESSORS(value, Object) |
| 6360 | |
| 6361 | DECLARE_CAST(Box) |
| 6362 | |
| 6363 | // Dispatched behavior. |
| 6364 | DECLARE_PRINTER(Box) |
| 6365 | DECLARE_VERIFIER(Box) |
| 6366 | |
| 6367 | static const int kValueOffset = HeapObject::kHeaderSize; |
| 6368 | static const int kSize = kValueOffset + kPointerSize; |
| 6369 | |
| 6370 | private: |
| 6371 | DISALLOW_IMPLICIT_CONSTRUCTORS(Box); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6372 | }; |
| 6373 | |
| 6374 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6375 | // Container for metadata stored on each prototype map. |
| 6376 | class PrototypeInfo : public Struct { |
| 6377 | public: |
| 6378 | static const int UNREGISTERED = -1; |
| 6379 | |
| 6380 | // [prototype_users]: WeakFixedArray containing maps using this prototype, |
| 6381 | // or Smi(0) if uninitialized. |
| 6382 | DECL_ACCESSORS(prototype_users, Object) |
| 6383 | // [registry_slot]: Slot in prototype's user registry where this user |
| 6384 | // is stored. Returns UNREGISTERED if this prototype has not been registered. |
| 6385 | inline int registry_slot() const; |
| 6386 | inline void set_registry_slot(int slot); |
| 6387 | // [validity_cell]: Cell containing the validity bit for prototype chains |
| 6388 | // going through this object, or Smi(0) if uninitialized. |
| 6389 | // When a prototype object changes its map, then both its own validity cell |
| 6390 | // and those of all "downstream" prototypes are invalidated; handlers for a |
| 6391 | // given receiver embed the currently valid cell for that receiver's prototype |
| 6392 | // during their compilation and check it on execution. |
| 6393 | DECL_ACCESSORS(validity_cell, Object) |
| 6394 | |
| 6395 | DECLARE_CAST(PrototypeInfo) |
| 6396 | |
| 6397 | // Dispatched behavior. |
| 6398 | DECLARE_PRINTER(PrototypeInfo) |
| 6399 | DECLARE_VERIFIER(PrototypeInfo) |
| 6400 | |
| 6401 | static const int kPrototypeUsersOffset = HeapObject::kHeaderSize; |
| 6402 | static const int kRegistrySlotOffset = kPrototypeUsersOffset + kPointerSize; |
| 6403 | static const int kValidityCellOffset = kRegistrySlotOffset + kPointerSize; |
| 6404 | static const int kConstructorNameOffset = kValidityCellOffset + kPointerSize; |
| 6405 | static const int kSize = kConstructorNameOffset + kPointerSize; |
| 6406 | |
| 6407 | private: |
| 6408 | DISALLOW_IMPLICIT_CONSTRUCTORS(PrototypeInfo); |
| 6409 | }; |
| 6410 | |
| 6411 | |
| 6412 | // Pair used to store both a ScopeInfo and an extension object in the extension |
| 6413 | // slot of a block context. Needed in the rare case where a declaration block |
| 6414 | // scope (a "varblock" as used to desugar parameter destructuring) also contains |
| 6415 | // a sloppy direct eval. (In no other case both are needed at the same time.) |
| 6416 | class SloppyBlockWithEvalContextExtension : public Struct { |
| 6417 | public: |
| 6418 | // [scope_info]: Scope info. |
| 6419 | DECL_ACCESSORS(scope_info, ScopeInfo) |
| 6420 | // [extension]: Extension object. |
| 6421 | DECL_ACCESSORS(extension, JSObject) |
| 6422 | |
| 6423 | DECLARE_CAST(SloppyBlockWithEvalContextExtension) |
| 6424 | |
| 6425 | // Dispatched behavior. |
| 6426 | DECLARE_PRINTER(SloppyBlockWithEvalContextExtension) |
| 6427 | DECLARE_VERIFIER(SloppyBlockWithEvalContextExtension) |
| 6428 | |
| 6429 | static const int kScopeInfoOffset = HeapObject::kHeaderSize; |
| 6430 | static const int kExtensionOffset = kScopeInfoOffset + kPointerSize; |
| 6431 | static const int kSize = kExtensionOffset + kPointerSize; |
| 6432 | |
| 6433 | private: |
| 6434 | DISALLOW_IMPLICIT_CONSTRUCTORS(SloppyBlockWithEvalContextExtension); |
| 6435 | }; |
| 6436 | |
| 6437 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6438 | // Script describes a script which has been added to the VM. |
| 6439 | class Script: public Struct { |
| 6440 | public: |
| 6441 | // Script types. |
| 6442 | enum Type { |
| 6443 | TYPE_NATIVE = 0, |
| 6444 | TYPE_EXTENSION = 1, |
| 6445 | TYPE_NORMAL = 2 |
| 6446 | }; |
| 6447 | |
| 6448 | // Script compilation types. |
| 6449 | enum CompilationType { |
| 6450 | COMPILATION_TYPE_HOST = 0, |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 6451 | COMPILATION_TYPE_EVAL = 1 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6452 | }; |
| 6453 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 6454 | // Script compilation state. |
| 6455 | enum CompilationState { |
| 6456 | COMPILATION_STATE_INITIAL = 0, |
| 6457 | COMPILATION_STATE_COMPILED = 1 |
| 6458 | }; |
| 6459 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6460 | // [source]: the script source. |
| 6461 | DECL_ACCESSORS(source, Object) |
| 6462 | |
| 6463 | // [name]: the script name. |
| 6464 | DECL_ACCESSORS(name, Object) |
| 6465 | |
| 6466 | // [id]: the script id. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6467 | DECL_INT_ACCESSORS(id) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6468 | |
| 6469 | // [line_offset]: script line offset in resource from where it was extracted. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6470 | DECL_INT_ACCESSORS(line_offset) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6471 | |
| 6472 | // [column_offset]: script column offset in resource from where it was |
| 6473 | // extracted. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6474 | DECL_INT_ACCESSORS(column_offset) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6475 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6476 | // [context_data]: context data for the context this script was compiled in. |
| 6477 | DECL_ACCESSORS(context_data, Object) |
| 6478 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6479 | // [wrapper]: the wrapper cache. This is either undefined or a WeakCell. |
| 6480 | DECL_ACCESSORS(wrapper, HeapObject) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6481 | |
| 6482 | // [type]: the script type. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6483 | DECL_INT_ACCESSORS(type) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6484 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6485 | // [line_ends]: FixedArray of line ends positions. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6486 | DECL_ACCESSORS(line_ends, Object) |
| 6487 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 6488 | // [eval_from_shared]: for eval scripts the shared function info for the |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6489 | // function from which eval was called. |
| 6490 | DECL_ACCESSORS(eval_from_shared, Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6491 | |
| 6492 | // [eval_from_instructions_offset]: the instruction offset in the code for the |
| 6493 | // function from which eval was called where eval was called. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6494 | DECL_INT_ACCESSORS(eval_from_instructions_offset) |
| 6495 | |
| 6496 | // [shared_function_infos]: weak fixed array containing all shared |
| 6497 | // function infos created from this script. |
| 6498 | DECL_ACCESSORS(shared_function_infos, Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6499 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6500 | // [flags]: Holds an exciting bitfield. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6501 | DECL_INT_ACCESSORS(flags) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6502 | |
| 6503 | // [source_url]: sourceURL from magic comment |
| 6504 | DECL_ACCESSORS(source_url, Object) |
| 6505 | |
| 6506 | // [source_url]: sourceMappingURL magic comment |
| 6507 | DECL_ACCESSORS(source_mapping_url, Object) |
| 6508 | |
| 6509 | // [compilation_type]: how the the script was compiled. Encoded in the |
| 6510 | // 'flags' field. |
| 6511 | inline CompilationType compilation_type(); |
| 6512 | inline void set_compilation_type(CompilationType type); |
| 6513 | |
| 6514 | // [compilation_state]: determines whether the script has already been |
| 6515 | // compiled. Encoded in the 'flags' field. |
| 6516 | inline CompilationState compilation_state(); |
| 6517 | inline void set_compilation_state(CompilationState state); |
| 6518 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6519 | // [hide_source]: determines whether the script source can be exposed as |
| 6520 | // function source. Encoded in the 'flags' field. |
| 6521 | inline bool hide_source(); |
| 6522 | inline void set_hide_source(bool value); |
| 6523 | |
| 6524 | // [origin_options]: optional attributes set by the embedder via ScriptOrigin, |
| 6525 | // and used by the embedder to make decisions about the script. V8 just passes |
| 6526 | // this through. Encoded in the 'flags' field. |
| 6527 | inline v8::ScriptOriginOptions origin_options(); |
| 6528 | inline void set_origin_options(ScriptOriginOptions origin_options); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6529 | |
| 6530 | DECLARE_CAST(Script) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6531 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 6532 | // If script source is an external string, check that the underlying |
| 6533 | // resource is accessible. Otherwise, always return true. |
| 6534 | inline bool HasValidSource(); |
| 6535 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 6536 | // Convert code offset into column number. |
| 6537 | static int GetColumnNumber(Handle<Script> script, int code_offset); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6538 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 6539 | // Convert code offset into (zero-based) line number. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6540 | // The non-handlified version does not allocate, but may be much slower. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 6541 | static int GetLineNumber(Handle<Script> script, int code_offset); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6542 | int GetLineNumber(int code_pos); |
| 6543 | |
| 6544 | static Handle<Object> GetNameOrSourceURL(Handle<Script> script); |
| 6545 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 6546 | // Init line_ends array with source code positions of line ends. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6547 | static void InitLineEnds(Handle<Script> script); |
| 6548 | |
| 6549 | // Get the JS object wrapping the given script; create it if none exists. |
| 6550 | static Handle<JSObject> GetWrapper(Handle<Script> script); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6551 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6552 | // Look through the list of existing shared function infos to find one |
| 6553 | // that matches the function literal. Return empty handle if not found. |
| 6554 | MaybeHandle<SharedFunctionInfo> FindSharedFunctionInfo(FunctionLiteral* fun); |
| 6555 | |
| 6556 | // Iterate over all script objects on the heap. |
| 6557 | class Iterator { |
| 6558 | public: |
| 6559 | explicit Iterator(Isolate* isolate); |
| 6560 | Script* Next(); |
| 6561 | |
| 6562 | private: |
| 6563 | WeakFixedArray::Iterator iterator_; |
| 6564 | DISALLOW_COPY_AND_ASSIGN(Iterator); |
| 6565 | }; |
| 6566 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6567 | // Dispatched behavior. |
| 6568 | DECLARE_PRINTER(Script) |
| 6569 | DECLARE_VERIFIER(Script) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6570 | |
| 6571 | static const int kSourceOffset = HeapObject::kHeaderSize; |
| 6572 | static const int kNameOffset = kSourceOffset + kPointerSize; |
| 6573 | static const int kLineOffsetOffset = kNameOffset + kPointerSize; |
| 6574 | static const int kColumnOffsetOffset = kLineOffsetOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6575 | static const int kContextOffset = kColumnOffsetOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6576 | static const int kWrapperOffset = kContextOffset + kPointerSize; |
| 6577 | static const int kTypeOffset = kWrapperOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6578 | static const int kLineEndsOffset = kTypeOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6579 | static const int kIdOffset = kLineEndsOffset + kPointerSize; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6580 | static const int kEvalFromSharedOffset = kIdOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6581 | static const int kEvalFrominstructionsOffsetOffset = |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6582 | kEvalFromSharedOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6583 | static const int kSharedFunctionInfosOffset = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6584 | kEvalFrominstructionsOffsetOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6585 | static const int kFlagsOffset = kSharedFunctionInfosOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6586 | static const int kSourceUrlOffset = kFlagsOffset + kPointerSize; |
| 6587 | static const int kSourceMappingUrlOffset = kSourceUrlOffset + kPointerSize; |
| 6588 | static const int kSize = kSourceMappingUrlOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6589 | |
| 6590 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6591 | int GetLineNumberWithArray(int code_pos); |
| 6592 | |
| 6593 | // Bit positions in the flags field. |
| 6594 | static const int kCompilationTypeBit = 0; |
| 6595 | static const int kCompilationStateBit = 1; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6596 | static const int kHideSourceBit = 2; |
| 6597 | static const int kOriginOptionsShift = 3; |
| 6598 | static const int kOriginOptionsSize = 3; |
| 6599 | static const int kOriginOptionsMask = ((1 << kOriginOptionsSize) - 1) |
| 6600 | << kOriginOptionsShift; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6601 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6602 | DISALLOW_IMPLICIT_CONSTRUCTORS(Script); |
| 6603 | }; |
| 6604 | |
| 6605 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6606 | // List of builtin functions we want to identify to improve code |
| 6607 | // generation. |
| 6608 | // |
| 6609 | // Each entry has a name of a global object property holding an object |
| 6610 | // optionally followed by ".prototype", a name of a builtin function |
| 6611 | // on the object (the one the id is set for), and a label. |
| 6612 | // |
| 6613 | // Installation of ids for the selected builtin functions is handled |
| 6614 | // by the bootstrapper. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 6615 | #define FUNCTIONS_WITH_ID_LIST(V) \ |
| 6616 | V(Array.prototype, indexOf, ArrayIndexOf) \ |
| 6617 | V(Array.prototype, lastIndexOf, ArrayLastIndexOf) \ |
| 6618 | V(Array.prototype, push, ArrayPush) \ |
| 6619 | V(Array.prototype, pop, ArrayPop) \ |
| 6620 | V(Array.prototype, shift, ArrayShift) \ |
| 6621 | V(Function.prototype, apply, FunctionApply) \ |
| 6622 | V(Function.prototype, call, FunctionCall) \ |
| 6623 | V(Object.prototype, hasOwnProperty, ObjectHasOwnProperty) \ |
| 6624 | V(String.prototype, charCodeAt, StringCharCodeAt) \ |
| 6625 | V(String.prototype, charAt, StringCharAt) \ |
| 6626 | V(String.prototype, concat, StringConcat) \ |
| 6627 | V(String.prototype, toLowerCase, StringToLowerCase) \ |
| 6628 | V(String.prototype, toUpperCase, StringToUpperCase) \ |
| 6629 | V(String, fromCharCode, StringFromCharCode) \ |
| 6630 | V(Math, random, MathRandom) \ |
| 6631 | V(Math, floor, MathFloor) \ |
| 6632 | V(Math, round, MathRound) \ |
| 6633 | V(Math, ceil, MathCeil) \ |
| 6634 | V(Math, abs, MathAbs) \ |
| 6635 | V(Math, log, MathLog) \ |
| 6636 | V(Math, exp, MathExp) \ |
| 6637 | V(Math, sqrt, MathSqrt) \ |
| 6638 | V(Math, pow, MathPow) \ |
| 6639 | V(Math, max, MathMax) \ |
| 6640 | V(Math, min, MathMin) \ |
| 6641 | V(Math, cos, MathCos) \ |
| 6642 | V(Math, sin, MathSin) \ |
| 6643 | V(Math, tan, MathTan) \ |
| 6644 | V(Math, acos, MathAcos) \ |
| 6645 | V(Math, asin, MathAsin) \ |
| 6646 | V(Math, atan, MathAtan) \ |
| 6647 | V(Math, atan2, MathAtan2) \ |
| 6648 | V(Math, imul, MathImul) \ |
| 6649 | V(Math, clz32, MathClz32) \ |
| 6650 | V(Math, fround, MathFround) \ |
| 6651 | V(Math, trunc, MathTrunc) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6652 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6653 | #define ATOMIC_FUNCTIONS_WITH_ID_LIST(V) \ |
| 6654 | V(Atomics, load, AtomicsLoad) \ |
| 6655 | V(Atomics, store, AtomicsStore) |
| 6656 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6657 | enum BuiltinFunctionId { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6658 | kArrayCode, |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 6659 | kGeneratorObjectNext, |
| 6660 | kGeneratorObjectReturn, |
| 6661 | kGeneratorObjectThrow, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6662 | #define DECLARE_FUNCTION_ID(ignored1, ignore2, name) \ |
| 6663 | k##name, |
| 6664 | FUNCTIONS_WITH_ID_LIST(DECLARE_FUNCTION_ID) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6665 | ATOMIC_FUNCTIONS_WITH_ID_LIST(DECLARE_FUNCTION_ID) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6666 | #undef DECLARE_FUNCTION_ID |
| 6667 | // Fake id for a special case of Math.pow. Note, it continues the |
| 6668 | // list of math functions. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6669 | kMathPowHalf |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6670 | }; |
| 6671 | |
| 6672 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6673 | // Result of searching in an optimized code map of a SharedFunctionInfo. Note |
| 6674 | // that both {code} and {literals} can be NULL to pass search result status. |
| 6675 | struct CodeAndLiterals { |
| 6676 | Code* code; // Cached optimized code. |
| 6677 | LiteralsArray* literals; // Cached literals array. |
| 6678 | }; |
| 6679 | |
| 6680 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6681 | // SharedFunctionInfo describes the JSFunction information that can be |
| 6682 | // shared by multiple instances of the function. |
| 6683 | class SharedFunctionInfo: public HeapObject { |
| 6684 | public: |
| 6685 | // [name]: Function name. |
| 6686 | DECL_ACCESSORS(name, Object) |
| 6687 | |
| 6688 | // [code]: Function code. |
| 6689 | DECL_ACCESSORS(code, Code) |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 6690 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 6691 | // Get the abstract code associated with the function, which will either be |
| 6692 | // a Code object or a BytecodeArray. |
| 6693 | inline AbstractCode* abstract_code(); |
| 6694 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6695 | inline void ReplaceCode(Code* code); |
| 6696 | |
| 6697 | // [optimized_code_map]: Map from native context to optimized code |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6698 | // and a shared literals array. |
| 6699 | DECL_ACCESSORS(optimized_code_map, FixedArray) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6700 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6701 | // Returns entry from optimized code map for specified context and OSR entry. |
| 6702 | // Note that {code == nullptr, literals == nullptr} indicates no matching |
| 6703 | // entry has been found, whereas {code, literals == nullptr} indicates that |
| 6704 | // code is context-independent. |
| 6705 | CodeAndLiterals SearchOptimizedCodeMap(Context* native_context, |
| 6706 | BailoutId osr_ast_id); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6707 | |
| 6708 | // Clear optimized code map. |
| 6709 | void ClearOptimizedCodeMap(); |
| 6710 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6711 | // We have a special root FixedArray with the right shape and values |
| 6712 | // to represent the cleared optimized code map. This predicate checks |
| 6713 | // if that root is installed. |
| 6714 | inline bool OptimizedCodeMapIsCleared() const; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6715 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6716 | // Removes a specific optimized code object from the optimized code map. |
| 6717 | // In case of non-OSR the code reference is cleared from the cache entry but |
| 6718 | // the entry itself is left in the map in order to proceed sharing literals. |
| 6719 | void EvictFromOptimizedCodeMap(Code* optimized_code, const char* reason); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6720 | |
| 6721 | // Trims the optimized code map after entries have been removed. |
| 6722 | void TrimOptimizedCodeMap(int shrink_by); |
| 6723 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 6724 | // 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] | 6725 | static void AddSharedCodeToOptimizedCodeMap(Handle<SharedFunctionInfo> shared, |
| 6726 | Handle<Code> code); |
| 6727 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 6728 | // Add or update entry in the optimized code map for context-dependent code. |
| 6729 | // If {code} is not given, then an existing entry's code won't be overwritten. |
| 6730 | static void AddToOptimizedCodeMap(Handle<SharedFunctionInfo> shared, |
| 6731 | Handle<Context> native_context, |
| 6732 | MaybeHandle<Code> code, |
| 6733 | Handle<LiteralsArray> literals, |
| 6734 | BailoutId osr_ast_id); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6735 | |
| 6736 | // Set up the link between shared function info and the script. The shared |
| 6737 | // function info is added to the list on the script. |
| 6738 | static void SetScript(Handle<SharedFunctionInfo> shared, |
| 6739 | Handle<Object> script_object); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6740 | |
| 6741 | // Layout description of the optimized code map. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6742 | static const int kSharedCodeIndex = 0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6743 | static const int kEntriesStart = 1; |
| 6744 | static const int kContextOffset = 0; |
| 6745 | static const int kCachedCodeOffset = 1; |
| 6746 | static const int kLiteralsOffset = 2; |
| 6747 | static const int kOsrAstIdOffset = 3; |
| 6748 | static const int kEntryLength = 4; |
| 6749 | static const int kInitialLength = kEntriesStart + kEntryLength; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6750 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6751 | static const int kNotFound = -1; |
| 6752 | |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 6753 | // [scope_info]: Scope info. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 6754 | DECL_ACCESSORS(scope_info, ScopeInfo) |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 6755 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6756 | // [construct stub]: Code stub for constructing instances of this function. |
| 6757 | DECL_ACCESSORS(construct_stub, Code) |
| 6758 | |
| 6759 | // Returns if this function has been compiled to native code yet. |
| 6760 | inline bool is_compiled(); |
| 6761 | |
| 6762 | // [length]: The function length - usually the number of declared parameters. |
| 6763 | // Use up to 2^30 parameters. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6764 | inline int length() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6765 | inline void set_length(int value); |
| 6766 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6767 | // [internal formal parameter count]: The declared number of parameters. |
| 6768 | // For subclass constructors, also includes new.target. |
| 6769 | // The size of function's frame is internal_formal_parameter_count + 1. |
| 6770 | inline int internal_formal_parameter_count() const; |
| 6771 | inline void set_internal_formal_parameter_count(int value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6772 | |
| 6773 | // Set the formal parameter count so the function code will be |
| 6774 | // called without using argument adaptor frames. |
| 6775 | inline void DontAdaptArguments(); |
| 6776 | |
| 6777 | // [expected_nof_properties]: Expected number of properties for the function. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6778 | inline int expected_nof_properties() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6779 | inline void set_expected_nof_properties(int value); |
| 6780 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6781 | // [feedback_vector] - accumulates ast node feedback from full-codegen and |
| 6782 | // (increasingly) from crankshafted code where sufficient feedback isn't |
| 6783 | // available. |
| 6784 | DECL_ACCESSORS(feedback_vector, TypeFeedbackVector) |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 6785 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6786 | // Unconditionally clear the type feedback vector (including vector ICs). |
| 6787 | void ClearTypeFeedbackInfo(); |
| 6788 | |
| 6789 | // Clear the type feedback vector with a more subtle policy at GC time. |
| 6790 | void ClearTypeFeedbackInfoAtGCTime(); |
| 6791 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6792 | #if TRACE_MAPS |
| 6793 | // [unique_id] - For --trace-maps purposes, an identifier that's persistent |
| 6794 | // even if the GC moves this SharedFunctionInfo. |
| 6795 | inline int unique_id() const; |
| 6796 | inline void set_unique_id(int value); |
| 6797 | #endif |
| 6798 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6799 | // [instance class name]: class name for instances. |
| 6800 | DECL_ACCESSORS(instance_class_name, Object) |
| 6801 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 6802 | // [function data]: This field holds some additional data for function. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6803 | // Currently it has one of: |
| 6804 | // - a FunctionTemplateInfo to make benefit the API [IsApiFunction()]. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6805 | // - a BytecodeArray for the interpreter [HasBytecodeArray()]. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6806 | DECL_ACCESSORS(function_data, Object) |
| 6807 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 6808 | inline bool IsApiFunction(); |
| 6809 | inline FunctionTemplateInfo* get_api_func_data(); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 6810 | inline void set_api_func_data(FunctionTemplateInfo* data); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6811 | inline bool HasBytecodeArray(); |
| 6812 | inline BytecodeArray* bytecode_array(); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 6813 | inline void set_bytecode_array(BytecodeArray* bytecode); |
| 6814 | inline void ClearBytecodeArray(); |
| 6815 | |
| 6816 | // [function identifier]: This field holds an additional identifier for the |
| 6817 | // function. |
| 6818 | // - a Smi identifying a builtin function [HasBuiltinFunctionId()]. |
| 6819 | // - a String identifying the function's inferred name [HasInferredName()]. |
| 6820 | // The inferred_name is inferred from variable or property |
| 6821 | // assignment of this function. It is used to facilitate debugging and |
| 6822 | // profiling of JavaScript code written in OO style, where almost |
| 6823 | // all functions are anonymous but are assigned to object |
| 6824 | // properties. |
| 6825 | DECL_ACCESSORS(function_identifier, Object) |
| 6826 | |
| 6827 | inline bool HasBuiltinFunctionId(); |
| 6828 | inline BuiltinFunctionId builtin_function_id(); |
| 6829 | inline void set_builtin_function_id(BuiltinFunctionId id); |
| 6830 | inline bool HasInferredName(); |
| 6831 | inline String* inferred_name(); |
| 6832 | inline void set_inferred_name(String* inferred_name); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 6833 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6834 | // [script info]: Script from which the function originates. |
| 6835 | DECL_ACCESSORS(script, Object) |
| 6836 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 6837 | // [num_literals]: Number of literals used by this function. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6838 | inline int num_literals() const; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 6839 | inline void set_num_literals(int value); |
| 6840 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6841 | // [start_position_and_type]: Field used to store both the source code |
| 6842 | // position, whether or not the function is a function expression, |
| 6843 | // and whether or not the function is a toplevel function. The two |
| 6844 | // least significants bit indicates whether the function is an |
| 6845 | // expression and the rest contains the source code position. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6846 | inline int start_position_and_type() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6847 | inline void set_start_position_and_type(int value); |
| 6848 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6849 | // The function is subject to debugging if a debug info is attached. |
| 6850 | inline bool HasDebugInfo(); |
| 6851 | inline DebugInfo* GetDebugInfo(); |
| 6852 | |
| 6853 | // A function has debug code if the compiled code has debug break slots. |
| 6854 | inline bool HasDebugCode(); |
| 6855 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6856 | // [debug info]: Debug information. |
| 6857 | DECL_ACCESSORS(debug_info, Object) |
| 6858 | |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 6859 | // The function's name if it is non-empty, otherwise the inferred name. |
| 6860 | String* DebugName(); |
| 6861 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 6862 | // Used for flags such as --hydrogen-filter. |
| 6863 | bool PassesFilter(const char* raw_filter); |
| 6864 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6865 | // Position of the 'function' token in the script source. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6866 | inline int function_token_position() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6867 | inline void set_function_token_position(int function_token_position); |
| 6868 | |
| 6869 | // Position of this function in the script source. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6870 | inline int start_position() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6871 | inline void set_start_position(int start_position); |
| 6872 | |
| 6873 | // End position of this function in the script source. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6874 | inline int end_position() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6875 | inline void set_end_position(int end_position); |
| 6876 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 6877 | // Is this function a named function expression in the source code. |
| 6878 | DECL_BOOLEAN_ACCESSORS(is_named_expression) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6879 | |
| 6880 | // Is this function a top-level function (scripts, evals). |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6881 | DECL_BOOLEAN_ACCESSORS(is_toplevel) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6882 | |
| 6883 | // Bit field containing various information collected by the compiler to |
| 6884 | // drive optimization. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6885 | inline int compiler_hints() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6886 | inline void set_compiler_hints(int value); |
| 6887 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6888 | inline int ast_node_count() const; |
Ben Murdoch | 8f9999f | 2012-04-23 10:39:17 +0100 | [diff] [blame] | 6889 | inline void set_ast_node_count(int count); |
| 6890 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6891 | inline int profiler_ticks() const; |
| 6892 | inline void set_profiler_ticks(int ticks); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 6893 | |
Ben Murdoch | 8f9999f | 2012-04-23 10:39:17 +0100 | [diff] [blame] | 6894 | // Inline cache age is used to infer whether the function survived a context |
| 6895 | // disposal or not. In the former case we reset the opt_count. |
| 6896 | inline int ic_age(); |
| 6897 | inline void set_ic_age(int age); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6898 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 6899 | // Indicates if this function can be lazy compiled. |
| 6900 | // This is used to determine if we can safely flush code from a function |
| 6901 | // 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] | 6902 | DECL_BOOLEAN_ACCESSORS(allows_lazy_compilation) |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 6903 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6904 | // Indicates if this function can be lazy compiled without a context. |
| 6905 | // This is used to determine if we can force compilation without reaching |
| 6906 | // the function through program execution but through other means (e.g. heap |
| 6907 | // iteration by the debugger). |
| 6908 | DECL_BOOLEAN_ACCESSORS(allows_lazy_compilation_without_context) |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 6909 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6910 | // Indicates whether optimizations have been disabled for this |
| 6911 | // shared function info. If a function is repeatedly optimized or if |
| 6912 | // we cannot optimize the function we disable optimization to avoid |
| 6913 | // spending time attempting to optimize it again. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6914 | DECL_BOOLEAN_ACCESSORS(optimization_disabled) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6915 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6916 | // Indicates the language mode. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6917 | inline LanguageMode language_mode(); |
| 6918 | inline void set_language_mode(LanguageMode language_mode); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 6919 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6920 | // False if the function definitely does not allocate an arguments object. |
| 6921 | DECL_BOOLEAN_ACCESSORS(uses_arguments) |
| 6922 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6923 | // Indicates that this function uses a super property (or an eval that may |
| 6924 | // use a super property). |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6925 | // This is needed to set up the [[HomeObject]] on the function instance. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6926 | DECL_BOOLEAN_ACCESSORS(needs_home_object) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6927 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6928 | // True if the function has any duplicated parameter names. |
| 6929 | DECL_BOOLEAN_ACCESSORS(has_duplicate_parameters) |
| 6930 | |
| 6931 | // Indicates whether the function is a native function. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 6932 | // These needs special treatment in .call and .apply since |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6933 | // null passed as the receiver should not be translated to the |
| 6934 | // global object. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6935 | DECL_BOOLEAN_ACCESSORS(native) |
| 6936 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6937 | // Indicate that this function should always be inlined in optimized code. |
| 6938 | DECL_BOOLEAN_ACCESSORS(force_inline) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6939 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6940 | // Indicates that the function was created by the Function function. |
| 6941 | // Though it's anonymous, toString should treat it as if it had the name |
| 6942 | // "anonymous". We don't set the name itself so that the system does not |
| 6943 | // see a binding for it. |
| 6944 | DECL_BOOLEAN_ACCESSORS(name_should_print_as_anonymous) |
| 6945 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 6946 | // Indicates that the function is either an anonymous expression |
| 6947 | // or an arrow function (the name field can be set through the API, |
| 6948 | // which does not change this flag). |
| 6949 | DECL_BOOLEAN_ACCESSORS(is_anonymous_expression) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6950 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 6951 | // Is this a function or top-level/eval code. |
| 6952 | DECL_BOOLEAN_ACCESSORS(is_function) |
| 6953 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6954 | // Indicates that code for this function cannot be compiled with Crankshaft. |
| 6955 | DECL_BOOLEAN_ACCESSORS(dont_crankshaft) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 6956 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6957 | // Indicates that code for this function cannot be flushed. |
| 6958 | DECL_BOOLEAN_ACCESSORS(dont_flush) |
| 6959 | |
| 6960 | // Indicates that this function is a generator. |
| 6961 | DECL_BOOLEAN_ACCESSORS(is_generator) |
| 6962 | |
| 6963 | // Indicates that this function is an arrow function. |
| 6964 | DECL_BOOLEAN_ACCESSORS(is_arrow) |
| 6965 | |
| 6966 | // Indicates that this function is a concise method. |
| 6967 | DECL_BOOLEAN_ACCESSORS(is_concise_method) |
| 6968 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 6969 | // Indicates that this function is a getter. |
| 6970 | DECL_BOOLEAN_ACCESSORS(is_getter_function) |
| 6971 | |
| 6972 | // Indicates that this function is a setter. |
| 6973 | DECL_BOOLEAN_ACCESSORS(is_setter_function) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6974 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6975 | // Indicates that this function is a default constructor. |
| 6976 | DECL_BOOLEAN_ACCESSORS(is_default_constructor) |
| 6977 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6978 | // Indicates that this function is an asm function. |
| 6979 | DECL_BOOLEAN_ACCESSORS(asm_function) |
| 6980 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6981 | // Indicates that the the shared function info is deserialized from cache. |
| 6982 | DECL_BOOLEAN_ACCESSORS(deserialized) |
| 6983 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6984 | // Indicates that the the shared function info has never been compiled before. |
| 6985 | DECL_BOOLEAN_ACCESSORS(never_compiled) |
| 6986 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 6987 | // Whether this function was created from a FunctionDeclaration. |
| 6988 | DECL_BOOLEAN_ACCESSORS(is_declaration) |
| 6989 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6990 | inline FunctionKind kind(); |
| 6991 | inline void set_kind(FunctionKind kind); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 6992 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6993 | // Indicates whether or not the code in the shared function support |
| 6994 | // deoptimization. |
| 6995 | inline bool has_deoptimization_support(); |
| 6996 | |
| 6997 | // Enable deoptimization support through recompiled code. |
| 6998 | void EnableDeoptimizationSupport(Code* recompiled); |
| 6999 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7000 | // Disable (further) attempted optimization of all functions sharing this |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7001 | // shared function info. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7002 | void DisableOptimization(BailoutReason reason); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7003 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 7004 | inline BailoutReason disable_optimization_reason(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7005 | |
| 7006 | // 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] | 7007 | // code, returns whether it asserted (i.e., always true if assertions are |
| 7008 | // disabled). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7009 | bool VerifyBailoutId(BailoutId id); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7010 | |
| 7011 | // [source code]: Source code for the function. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7012 | bool HasSourceCode() const; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7013 | Handle<Object> GetSourceCode(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7014 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7015 | // Number of times the function was optimized. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7016 | inline int opt_count(); |
| 7017 | inline void set_opt_count(int opt_count); |
| 7018 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7019 | // Number of times the function was deoptimized. |
| 7020 | inline void set_deopt_count(int value); |
| 7021 | inline int deopt_count(); |
| 7022 | inline void increment_deopt_count(); |
| 7023 | |
| 7024 | // Number of time we tried to re-enable optimization after it |
| 7025 | // was disabled due to high number of deoptimizations. |
| 7026 | inline void set_opt_reenable_tries(int value); |
| 7027 | inline int opt_reenable_tries(); |
| 7028 | |
| 7029 | inline void TryReenableOptimization(); |
| 7030 | |
| 7031 | // Stores deopt_count, opt_reenable_tries and ic_age as bit-fields. |
| 7032 | inline void set_counters(int value); |
| 7033 | inline int counters() const; |
| 7034 | |
| 7035 | // Stores opt_count and bailout_reason as bit-fields. |
| 7036 | inline void set_opt_count_and_bailout_reason(int value); |
| 7037 | inline int opt_count_and_bailout_reason() const; |
| 7038 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7039 | inline void set_disable_optimization_reason(BailoutReason reason); |
| 7040 | |
| 7041 | // Tells whether this function should be subject to debugging. |
| 7042 | inline bool IsSubjectToDebugging(); |
| 7043 | |
| 7044 | // Whether this function is defined in native code or extensions. |
| 7045 | inline bool IsBuiltin(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7046 | |
| 7047 | // Check whether or not this function is inlineable. |
| 7048 | bool IsInlineable(); |
| 7049 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7050 | // Source size of this function. |
| 7051 | int SourceSize(); |
| 7052 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7053 | // Returns `false` if formal parameters include rest parameters, optional |
| 7054 | // parameters, or destructuring parameters. |
| 7055 | // TODO(caitp): make this a flag set during parsing |
| 7056 | inline bool has_simple_parameters(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7057 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7058 | // Initialize a SharedFunctionInfo from a parsed function literal. |
| 7059 | static void InitFromFunctionLiteral(Handle<SharedFunctionInfo> shared_info, |
| 7060 | FunctionLiteral* lit); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7061 | |
| 7062 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7063 | DECLARE_PRINTER(SharedFunctionInfo) |
| 7064 | DECLARE_VERIFIER(SharedFunctionInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7065 | |
Ben Murdoch | 8f9999f | 2012-04-23 10:39:17 +0100 | [diff] [blame] | 7066 | void ResetForNewContext(int new_ic_age); |
| 7067 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7068 | // Iterate over all shared function infos. |
| 7069 | class Iterator { |
| 7070 | public: |
| 7071 | explicit Iterator(Isolate* isolate); |
| 7072 | SharedFunctionInfo* Next(); |
| 7073 | |
| 7074 | private: |
| 7075 | bool NextScript(); |
| 7076 | |
| 7077 | Script::Iterator script_iterator_; |
| 7078 | WeakFixedArray::Iterator sfi_iterator_; |
| 7079 | DisallowHeapAllocation no_gc_; |
| 7080 | DISALLOW_COPY_AND_ASSIGN(Iterator); |
| 7081 | }; |
| 7082 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7083 | DECLARE_CAST(SharedFunctionInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7084 | |
| 7085 | // Constants. |
| 7086 | static const int kDontAdaptArgumentsSentinel = -1; |
| 7087 | |
| 7088 | // Layout description. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 7089 | // Pointer fields. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7090 | static const int kNameOffset = HeapObject::kHeaderSize; |
| 7091 | static const int kCodeOffset = kNameOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7092 | static const int kOptimizedCodeMapOffset = kCodeOffset + kPointerSize; |
| 7093 | static const int kScopeInfoOffset = kOptimizedCodeMapOffset + kPointerSize; |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 7094 | static const int kConstructStubOffset = kScopeInfoOffset + kPointerSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 7095 | static const int kInstanceClassNameOffset = |
| 7096 | kConstructStubOffset + kPointerSize; |
| 7097 | static const int kFunctionDataOffset = |
| 7098 | kInstanceClassNameOffset + kPointerSize; |
| 7099 | static const int kScriptOffset = kFunctionDataOffset + kPointerSize; |
| 7100 | static const int kDebugInfoOffset = kScriptOffset + kPointerSize; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 7101 | static const int kFunctionIdentifierOffset = kDebugInfoOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7102 | static const int kFeedbackVectorOffset = |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 7103 | kFunctionIdentifierOffset + kPointerSize; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 7104 | #if TRACE_MAPS |
| 7105 | static const int kUniqueIdOffset = kFeedbackVectorOffset + kPointerSize; |
| 7106 | static const int kLastPointerFieldOffset = kUniqueIdOffset; |
| 7107 | #else |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7108 | // Just to not break the postmortrem support with conditional offsets |
| 7109 | static const int kUniqueIdOffset = kFeedbackVectorOffset; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 7110 | static const int kLastPointerFieldOffset = kFeedbackVectorOffset; |
| 7111 | #endif |
| 7112 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7113 | #if V8_HOST_ARCH_32_BIT |
| 7114 | // Smi fields. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 7115 | static const int kLengthOffset = kLastPointerFieldOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7116 | static const int kFormalParameterCountOffset = kLengthOffset + kPointerSize; |
| 7117 | static const int kExpectedNofPropertiesOffset = |
| 7118 | kFormalParameterCountOffset + kPointerSize; |
| 7119 | static const int kNumLiteralsOffset = |
| 7120 | kExpectedNofPropertiesOffset + kPointerSize; |
| 7121 | static const int kStartPositionAndTypeOffset = |
| 7122 | kNumLiteralsOffset + kPointerSize; |
| 7123 | static const int kEndPositionOffset = |
| 7124 | kStartPositionAndTypeOffset + kPointerSize; |
| 7125 | static const int kFunctionTokenPositionOffset = |
| 7126 | kEndPositionOffset + kPointerSize; |
| 7127 | static const int kCompilerHintsOffset = |
| 7128 | kFunctionTokenPositionOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7129 | static const int kOptCountAndBailoutReasonOffset = |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7130 | kCompilerHintsOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7131 | static const int kCountersOffset = |
| 7132 | kOptCountAndBailoutReasonOffset + kPointerSize; |
| 7133 | static const int kAstNodeCountOffset = |
| 7134 | kCountersOffset + kPointerSize; |
| 7135 | static const int kProfilerTicksOffset = |
| 7136 | kAstNodeCountOffset + kPointerSize; |
Ben Murdoch | 8f9999f | 2012-04-23 10:39:17 +0100 | [diff] [blame] | 7137 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7138 | // Total size. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7139 | static const int kSize = kProfilerTicksOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7140 | #else |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7141 | // The only reason to use smi fields instead of int fields is to allow |
| 7142 | // iteration without maps decoding during garbage collections. |
| 7143 | // To avoid wasting space on 64-bit architectures we use the following trick: |
| 7144 | // we group integer fields into pairs |
| 7145 | // The least significant integer in each pair is shifted left by 1. By doing |
| 7146 | // this we guarantee that LSB of each kPointerSize aligned word is not set and |
| 7147 | // thus this word cannot be treated as pointer to HeapObject during old space |
| 7148 | // traversal. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 7149 | #if V8_TARGET_LITTLE_ENDIAN |
| 7150 | static const int kLengthOffset = kLastPointerFieldOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7151 | static const int kFormalParameterCountOffset = |
| 7152 | kLengthOffset + kIntSize; |
| 7153 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7154 | static const int kExpectedNofPropertiesOffset = |
| 7155 | kFormalParameterCountOffset + kIntSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7156 | static const int kNumLiteralsOffset = |
| 7157 | kExpectedNofPropertiesOffset + kIntSize; |
| 7158 | |
| 7159 | static const int kEndPositionOffset = |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 7160 | kNumLiteralsOffset + kIntSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7161 | static const int kStartPositionAndTypeOffset = |
| 7162 | kEndPositionOffset + kIntSize; |
| 7163 | |
| 7164 | static const int kFunctionTokenPositionOffset = |
| 7165 | kStartPositionAndTypeOffset + kIntSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 7166 | static const int kCompilerHintsOffset = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7167 | kFunctionTokenPositionOffset + kIntSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7168 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7169 | static const int kOptCountAndBailoutReasonOffset = |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 7170 | kCompilerHintsOffset + kIntSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7171 | static const int kCountersOffset = |
| 7172 | kOptCountAndBailoutReasonOffset + kIntSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7173 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7174 | static const int kAstNodeCountOffset = |
| 7175 | kCountersOffset + kIntSize; |
| 7176 | static const int kProfilerTicksOffset = |
| 7177 | kAstNodeCountOffset + kIntSize; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7178 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 7179 | // Total size. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7180 | static const int kSize = kProfilerTicksOffset + kIntSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7181 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 7182 | #elif V8_TARGET_BIG_ENDIAN |
| 7183 | static const int kFormalParameterCountOffset = |
| 7184 | kLastPointerFieldOffset + kPointerSize; |
| 7185 | static const int kLengthOffset = kFormalParameterCountOffset + kIntSize; |
| 7186 | |
| 7187 | static const int kNumLiteralsOffset = kLengthOffset + kIntSize; |
| 7188 | static const int kExpectedNofPropertiesOffset = kNumLiteralsOffset + kIntSize; |
| 7189 | |
| 7190 | static const int kStartPositionAndTypeOffset = |
| 7191 | kExpectedNofPropertiesOffset + kIntSize; |
| 7192 | static const int kEndPositionOffset = kStartPositionAndTypeOffset + kIntSize; |
| 7193 | |
| 7194 | static const int kCompilerHintsOffset = kEndPositionOffset + kIntSize; |
| 7195 | static const int kFunctionTokenPositionOffset = |
| 7196 | kCompilerHintsOffset + kIntSize; |
| 7197 | |
| 7198 | static const int kCountersOffset = kFunctionTokenPositionOffset + kIntSize; |
| 7199 | static const int kOptCountAndBailoutReasonOffset = kCountersOffset + kIntSize; |
| 7200 | |
| 7201 | static const int kProfilerTicksOffset = |
| 7202 | kOptCountAndBailoutReasonOffset + kIntSize; |
| 7203 | static const int kAstNodeCountOffset = kProfilerTicksOffset + kIntSize; |
| 7204 | |
| 7205 | // Total size. |
| 7206 | static const int kSize = kAstNodeCountOffset + kIntSize; |
| 7207 | |
| 7208 | #else |
| 7209 | #error Unknown byte ordering |
| 7210 | #endif // Big endian |
| 7211 | #endif // 64-bit |
| 7212 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 7213 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 7214 | static const int kAlignedSize = POINTER_SIZE_ALIGN(kSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7215 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 7216 | typedef FixedBodyDescriptor<kNameOffset, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 7217 | kLastPointerFieldOffset + kPointerSize, |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 7218 | kSize> BodyDescriptor; |
| 7219 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7220 | // Bit positions in start_position_and_type. |
| 7221 | // The source code start position is in the 30 most significant bits of |
| 7222 | // the start_position_and_type field. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 7223 | static const int kIsNamedExpressionBit = 0; |
| 7224 | static const int kIsTopLevelBit = 1; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7225 | static const int kStartPositionShift = 2; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 7226 | static const int kStartPositionMask = ~((1 << kStartPositionShift) - 1); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7227 | |
| 7228 | // Bit positions in compiler_hints. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 7229 | enum CompilerHints { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7230 | // byte 0 |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 7231 | kAllowLazyCompilation, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7232 | kAllowLazyCompilationWithoutContext, |
| 7233 | kOptimizationDisabled, |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 7234 | kNeverCompiled, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 7235 | kNative, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7236 | kStrictModeFunction, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7237 | kUsesArguments, |
| 7238 | kNeedsHomeObject, |
| 7239 | // byte 1 |
| 7240 | kHasDuplicateParameters, |
| 7241 | kForceInline, |
| 7242 | kIsAsmFunction, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 7243 | kIsAnonymousExpression, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 7244 | kNameShouldPrintAsAnonymous, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7245 | kIsFunction, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7246 | kDontCrankshaft, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7247 | kDontFlush, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7248 | // byte 2 |
| 7249 | kFunctionKind, |
| 7250 | kIsArrow = kFunctionKind, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7251 | kIsGenerator, |
| 7252 | kIsConciseMethod, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 7253 | kIsDefaultConstructor, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7254 | kIsSubclassConstructor, |
| 7255 | kIsBaseConstructor, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 7256 | kIsGetterFunction, |
| 7257 | kIsSetterFunction, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7258 | // byte 3 |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 7259 | kDeserialized, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 7260 | kIsDeclaration, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7261 | kCompilerHintsCount, // Pseudo entry |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 7262 | }; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7263 | // Add hints for other modes when they're added. |
| 7264 | STATIC_ASSERT(LANGUAGE_END == 3); |
| 7265 | // kFunctionKind has to be byte-aligned |
| 7266 | STATIC_ASSERT((kFunctionKind % kBitsPerByte) == 0); |
| 7267 | // Make sure that FunctionKind and byte 2 are in sync: |
| 7268 | #define ASSERT_FUNCTION_KIND_ORDER(functionKind, compilerFunctionKind) \ |
| 7269 | STATIC_ASSERT(FunctionKind::functionKind == \ |
| 7270 | 1 << (compilerFunctionKind - kFunctionKind)) |
| 7271 | ASSERT_FUNCTION_KIND_ORDER(kArrowFunction, kIsArrow); |
| 7272 | ASSERT_FUNCTION_KIND_ORDER(kGeneratorFunction, kIsGenerator); |
| 7273 | ASSERT_FUNCTION_KIND_ORDER(kConciseMethod, kIsConciseMethod); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7274 | ASSERT_FUNCTION_KIND_ORDER(kDefaultConstructor, kIsDefaultConstructor); |
| 7275 | ASSERT_FUNCTION_KIND_ORDER(kSubclassConstructor, kIsSubclassConstructor); |
| 7276 | ASSERT_FUNCTION_KIND_ORDER(kBaseConstructor, kIsBaseConstructor); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 7277 | ASSERT_FUNCTION_KIND_ORDER(kGetterFunction, kIsGetterFunction); |
| 7278 | ASSERT_FUNCTION_KIND_ORDER(kSetterFunction, kIsSetterFunction); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7279 | #undef ASSERT_FUNCTION_KIND_ORDER |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7280 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7281 | class FunctionKindBits : public BitField<FunctionKind, kIsArrow, 8> {}; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7282 | |
| 7283 | class DeoptCountBits : public BitField<int, 0, 4> {}; |
| 7284 | class OptReenableTriesBits : public BitField<int, 4, 18> {}; |
| 7285 | class ICAgeBits : public BitField<int, 22, 8> {}; |
| 7286 | |
| 7287 | class OptCountBits : public BitField<int, 0, 22> {}; |
| 7288 | class DisabledOptimizationReasonBits : public BitField<int, 22, 8> {}; |
| 7289 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 7290 | private: |
| 7291 | #if V8_HOST_ARCH_32_BIT |
| 7292 | // On 32 bit platforms, compiler hints is a smi. |
| 7293 | static const int kCompilerHintsSmiTagSize = kSmiTagSize; |
| 7294 | static const int kCompilerHintsSize = kPointerSize; |
| 7295 | #else |
| 7296 | // On 64 bit platforms, compiler hints is not a smi, see comment above. |
| 7297 | static const int kCompilerHintsSmiTagSize = 0; |
| 7298 | static const int kCompilerHintsSize = kIntSize; |
| 7299 | #endif |
| 7300 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 7301 | STATIC_ASSERT(SharedFunctionInfo::kCompilerHintsCount <= |
| 7302 | SharedFunctionInfo::kCompilerHintsSize * kBitsPerByte); |
| 7303 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 7304 | public: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7305 | // Constants for optimizing codegen for strict mode function and |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7306 | // native tests when using integer-width instructions. |
| 7307 | static const int kStrictModeBit = |
| 7308 | kStrictModeFunction + kCompilerHintsSmiTagSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7309 | static const int kNativeBit = kNative + kCompilerHintsSmiTagSize; |
| 7310 | |
| 7311 | static const int kClassConstructorBits = |
| 7312 | FunctionKind::kClassConstructor |
| 7313 | << (kFunctionKind + kCompilerHintsSmiTagSize); |
| 7314 | |
| 7315 | // Constants for optimizing codegen for strict mode function and |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 7316 | // native tests. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7317 | // Allows to use byte-width instructions. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7318 | static const int kStrictModeBitWithinByte = kStrictModeBit % kBitsPerByte; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7319 | static const int kNativeBitWithinByte = kNativeBit % kBitsPerByte; |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 7320 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7321 | static const int kClassConstructorBitsWithinByte = |
| 7322 | FunctionKind::kClassConstructor << kCompilerHintsSmiTagSize; |
| 7323 | STATIC_ASSERT(kClassConstructorBitsWithinByte < (1 << kBitsPerByte)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7324 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7325 | #if defined(V8_TARGET_LITTLE_ENDIAN) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7326 | #define BYTE_OFFSET(compiler_hint) \ |
| 7327 | kCompilerHintsOffset + \ |
| 7328 | (compiler_hint + kCompilerHintsSmiTagSize) / kBitsPerByte |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7329 | #elif defined(V8_TARGET_BIG_ENDIAN) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7330 | #define BYTE_OFFSET(compiler_hint) \ |
| 7331 | kCompilerHintsOffset + (kCompilerHintsSize - 1) - \ |
| 7332 | ((compiler_hint + kCompilerHintsSmiTagSize) / kBitsPerByte) |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 7333 | #else |
| 7334 | #error Unknown byte ordering |
| 7335 | #endif |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7336 | static const int kStrictModeByteOffset = BYTE_OFFSET(kStrictModeFunction); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7337 | static const int kNativeByteOffset = BYTE_OFFSET(kNative); |
| 7338 | static const int kFunctionKindByteOffset = BYTE_OFFSET(kFunctionKind); |
| 7339 | #undef BYTE_OFFSET |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 7340 | |
| 7341 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7342 | // Returns entry from optimized code map for specified context and OSR entry. |
| 7343 | // The result is either kNotFound, kSharedCodeIndex for context-independent |
| 7344 | // entry or a start index of the context-dependent entry. |
| 7345 | int SearchOptimizedCodeMapEntry(Context* native_context, |
| 7346 | BailoutId osr_ast_id); |
| 7347 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7348 | DISALLOW_IMPLICIT_CONSTRUCTORS(SharedFunctionInfo); |
| 7349 | }; |
| 7350 | |
| 7351 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7352 | // Printing support. |
| 7353 | struct SourceCodeOf { |
| 7354 | explicit SourceCodeOf(SharedFunctionInfo* v, int max = -1) |
| 7355 | : value(v), max_length(max) {} |
| 7356 | const SharedFunctionInfo* value; |
| 7357 | int max_length; |
| 7358 | }; |
| 7359 | |
| 7360 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 7361 | std::ostream& operator<<(std::ostream& os, const SourceCodeOf& v); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7362 | |
| 7363 | |
| 7364 | class JSGeneratorObject: public JSObject { |
| 7365 | public: |
| 7366 | // [function]: The function corresponding to this generator object. |
| 7367 | DECL_ACCESSORS(function, JSFunction) |
| 7368 | |
| 7369 | // [context]: The context of the suspended computation. |
| 7370 | DECL_ACCESSORS(context, Context) |
| 7371 | |
| 7372 | // [receiver]: The receiver of the suspended computation. |
| 7373 | DECL_ACCESSORS(receiver, Object) |
| 7374 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 7375 | // [input]: The most recent input value. |
| 7376 | DECL_ACCESSORS(input, Object) |
| 7377 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7378 | // [continuation]: Offset into code of continuation. |
| 7379 | // |
| 7380 | // A positive offset indicates a suspended generator. The special |
| 7381 | // kGeneratorExecuting and kGeneratorClosed values indicate that a generator |
| 7382 | // cannot be resumed. |
| 7383 | inline int continuation() const; |
| 7384 | inline void set_continuation(int continuation); |
| 7385 | inline bool is_closed(); |
| 7386 | inline bool is_executing(); |
| 7387 | inline bool is_suspended(); |
| 7388 | |
| 7389 | // [operand_stack]: Saved operand stack. |
| 7390 | DECL_ACCESSORS(operand_stack, FixedArray) |
| 7391 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7392 | DECLARE_CAST(JSGeneratorObject) |
| 7393 | |
| 7394 | // Dispatched behavior. |
| 7395 | DECLARE_PRINTER(JSGeneratorObject) |
| 7396 | DECLARE_VERIFIER(JSGeneratorObject) |
| 7397 | |
| 7398 | // Magic sentinel values for the continuation. |
| 7399 | static const int kGeneratorExecuting = -1; |
| 7400 | static const int kGeneratorClosed = 0; |
| 7401 | |
| 7402 | // Layout description. |
| 7403 | static const int kFunctionOffset = JSObject::kHeaderSize; |
| 7404 | static const int kContextOffset = kFunctionOffset + kPointerSize; |
| 7405 | static const int kReceiverOffset = kContextOffset + kPointerSize; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 7406 | static const int kInputOffset = kReceiverOffset + kPointerSize; |
| 7407 | static const int kContinuationOffset = kInputOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7408 | static const int kOperandStackOffset = kContinuationOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7409 | static const int kSize = kOperandStackOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7410 | |
| 7411 | // Resume mode, for use by runtime functions. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 7412 | enum ResumeMode { NEXT, RETURN, THROW }; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7413 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7414 | private: |
| 7415 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGeneratorObject); |
| 7416 | }; |
| 7417 | |
| 7418 | |
| 7419 | // Representation for module instance objects. |
| 7420 | class JSModule: public JSObject { |
| 7421 | public: |
| 7422 | // [context]: the context holding the module's locals, or undefined if none. |
| 7423 | DECL_ACCESSORS(context, Object) |
| 7424 | |
| 7425 | // [scope_info]: Scope info. |
| 7426 | DECL_ACCESSORS(scope_info, ScopeInfo) |
| 7427 | |
| 7428 | DECLARE_CAST(JSModule) |
| 7429 | |
| 7430 | // Dispatched behavior. |
| 7431 | DECLARE_PRINTER(JSModule) |
| 7432 | DECLARE_VERIFIER(JSModule) |
| 7433 | |
| 7434 | // Layout description. |
| 7435 | static const int kContextOffset = JSObject::kHeaderSize; |
| 7436 | static const int kScopeInfoOffset = kContextOffset + kPointerSize; |
| 7437 | static const int kSize = kScopeInfoOffset + kPointerSize; |
| 7438 | |
| 7439 | private: |
| 7440 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSModule); |
| 7441 | }; |
| 7442 | |
| 7443 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7444 | // JSBoundFunction describes a bound function exotic object. |
| 7445 | class JSBoundFunction : public JSObject { |
| 7446 | public: |
| 7447 | // [length]: The bound function "length" property. |
| 7448 | DECL_ACCESSORS(length, Object) |
| 7449 | |
| 7450 | // [name]: The bound function "name" property. |
| 7451 | DECL_ACCESSORS(name, Object) |
| 7452 | |
| 7453 | // [bound_target_function]: The wrapped function object. |
| 7454 | DECL_ACCESSORS(bound_target_function, JSReceiver) |
| 7455 | |
| 7456 | // [bound_this]: The value that is always passed as the this value when |
| 7457 | // calling the wrapped function. |
| 7458 | DECL_ACCESSORS(bound_this, Object) |
| 7459 | |
| 7460 | // [bound_arguments]: A list of values whose elements are used as the first |
| 7461 | // arguments to any call to the wrapped function. |
| 7462 | DECL_ACCESSORS(bound_arguments, FixedArray) |
| 7463 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7464 | static MaybeHandle<Context> GetFunctionRealm( |
| 7465 | Handle<JSBoundFunction> function); |
| 7466 | |
| 7467 | DECLARE_CAST(JSBoundFunction) |
| 7468 | |
| 7469 | // Dispatched behavior. |
| 7470 | DECLARE_PRINTER(JSBoundFunction) |
| 7471 | DECLARE_VERIFIER(JSBoundFunction) |
| 7472 | |
| 7473 | // The bound function's string representation implemented according |
| 7474 | // to ES6 section 19.2.3.5 Function.prototype.toString ( ). |
| 7475 | static Handle<String> ToString(Handle<JSBoundFunction> function); |
| 7476 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 7477 | static MaybeHandle<String> GetName(Isolate* isolate, |
| 7478 | Handle<JSBoundFunction> function); |
| 7479 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7480 | // Layout description. |
| 7481 | static const int kBoundTargetFunctionOffset = JSObject::kHeaderSize; |
| 7482 | static const int kBoundThisOffset = kBoundTargetFunctionOffset + kPointerSize; |
| 7483 | static const int kBoundArgumentsOffset = kBoundThisOffset + kPointerSize; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 7484 | static const int kLengthOffset = kBoundArgumentsOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7485 | static const int kNameOffset = kLengthOffset + kPointerSize; |
| 7486 | static const int kSize = kNameOffset + kPointerSize; |
| 7487 | |
| 7488 | // Indices of in-object properties. |
| 7489 | static const int kLengthIndex = 0; |
| 7490 | static const int kNameIndex = 1; |
| 7491 | |
| 7492 | private: |
| 7493 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSBoundFunction); |
| 7494 | }; |
| 7495 | |
| 7496 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7497 | // JSFunction describes JavaScript functions. |
| 7498 | class JSFunction: public JSObject { |
| 7499 | public: |
| 7500 | // [prototype_or_initial_map]: |
| 7501 | DECL_ACCESSORS(prototype_or_initial_map, Object) |
| 7502 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 7503 | // [shared]: The information about the function that |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7504 | // can be shared by instances. |
| 7505 | DECL_ACCESSORS(shared, SharedFunctionInfo) |
| 7506 | |
| 7507 | // [context]: The context for this function. |
| 7508 | inline Context* context(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7509 | inline void set_context(Object* context); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7510 | inline JSObject* global_proxy(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7511 | inline Context* native_context(); |
| 7512 | |
| 7513 | static Handle<Context> GetFunctionRealm(Handle<JSFunction> function); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7514 | |
| 7515 | // [code]: The generated code object for this function. Executed |
| 7516 | // when the function is invoked, e.g. foo() or new foo(). See |
| 7517 | // [[Call]] and [[Construct]] description in ECMA-262, section |
| 7518 | // 8.6.2, page 27. |
| 7519 | inline Code* code(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7520 | inline void set_code(Code* code); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7521 | inline void set_code_no_write_barrier(Code* code); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7522 | inline void ReplaceCode(Code* code); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7523 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 7524 | // Get the abstract code associated with the function, which will either be |
| 7525 | // a Code object or a BytecodeArray. |
| 7526 | inline AbstractCode* abstract_code(); |
| 7527 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7528 | // Tells whether this function inlines the given shared function info. |
| 7529 | bool Inlines(SharedFunctionInfo* candidate); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7530 | |
| 7531 | // Tells whether or not this function has been optimized. |
| 7532 | inline bool IsOptimized(); |
| 7533 | |
| 7534 | // Mark this function for lazy recompilation. The function will be |
| 7535 | // recompiled the next time it is executed. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7536 | void MarkForOptimization(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 7537 | void AttemptConcurrentOptimization(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7538 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7539 | // Tells whether or not the function is already marked for lazy |
| 7540 | // recompilation. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7541 | inline bool IsMarkedForOptimization(); |
| 7542 | inline bool IsMarkedForConcurrentOptimization(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7543 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7544 | // Tells whether or not the function is on the concurrent recompilation queue. |
| 7545 | inline bool IsInOptimizationQueue(); |
| 7546 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7547 | // Completes inobject slack tracking on initial map if it is active. |
| 7548 | inline void CompleteInobjectSlackTrackingIfActive(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7549 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7550 | // [literals]: Fixed array holding the materialized literals. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7551 | // |
| 7552 | // If the function contains object, regexp or array literals, the |
| 7553 | // literals array prefix contains the object, regexp, and array |
| 7554 | // function to be used when creating these literals. This is |
| 7555 | // necessary so that we do not dynamically lookup the object, regexp |
| 7556 | // or array functions. Performing a dynamic lookup, we might end up |
| 7557 | // using the functions from a new context that we should not have |
| 7558 | // access to. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7559 | DECL_ACCESSORS(literals, LiteralsArray) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7560 | |
| 7561 | // The initial map for an object created by this constructor. |
| 7562 | inline Map* initial_map(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7563 | static void SetInitialMap(Handle<JSFunction> function, Handle<Map> map, |
| 7564 | Handle<Object> prototype); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7565 | inline bool has_initial_map(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7566 | static void EnsureHasInitialMap(Handle<JSFunction> function); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7567 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7568 | // Creates a map that matches the constructor's initial map, but with |
| 7569 | // [[prototype]] being new.target.prototype. Because new.target can be a |
| 7570 | // JSProxy, this can call back into JavaScript. |
| 7571 | static MUST_USE_RESULT MaybeHandle<Map> GetDerivedMap( |
| 7572 | Isolate* isolate, Handle<JSFunction> constructor, |
| 7573 | Handle<JSReceiver> new_target); |
| 7574 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7575 | // Get and set the prototype property on a JSFunction. If the |
| 7576 | // function has an initial map the prototype is set on the initial |
| 7577 | // map. Otherwise, the prototype is put in the initial map field |
| 7578 | // until an initial map is needed. |
| 7579 | inline bool has_prototype(); |
| 7580 | inline bool has_instance_prototype(); |
| 7581 | inline Object* prototype(); |
| 7582 | inline Object* instance_prototype(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7583 | static void SetPrototype(Handle<JSFunction> function, |
| 7584 | Handle<Object> value); |
| 7585 | static void SetInstancePrototype(Handle<JSFunction> function, |
| 7586 | Handle<Object> value); |
| 7587 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 7588 | // After prototype is removed, it will not be created when accessed, and |
| 7589 | // [[Construct]] from this function will not be allowed. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7590 | bool RemovePrototype(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7591 | |
| 7592 | // Returns if this function has been compiled to native code yet. |
| 7593 | inline bool is_compiled(); |
| 7594 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7595 | // [next_function_link]: Links functions into various lists, e.g. the list |
| 7596 | // of optimized functions hanging off the native_context. The CodeFlusher |
| 7597 | // uses this link to chain together flushing candidates. Treated weakly |
| 7598 | // by the garbage collector. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7599 | DECL_ACCESSORS(next_function_link, Object) |
| 7600 | |
| 7601 | // Prints the name of the function using PrintF. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7602 | void PrintName(FILE* out = stdout); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7603 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7604 | DECLARE_CAST(JSFunction) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7605 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7606 | // Calculate the instance size and in-object properties count. |
| 7607 | void CalculateInstanceSize(InstanceType instance_type, |
| 7608 | int requested_internal_fields, int* instance_size, |
| 7609 | int* in_object_properties); |
| 7610 | void CalculateInstanceSizeForDerivedClass(InstanceType instance_type, |
| 7611 | int requested_internal_fields, |
| 7612 | int* instance_size, |
| 7613 | int* in_object_properties); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 7614 | static void CalculateInstanceSizeHelper(InstanceType instance_type, |
| 7615 | int requested_internal_fields, |
| 7616 | int requested_in_object_properties, |
| 7617 | int* instance_size, |
| 7618 | int* in_object_properties); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7619 | // Visiting policy flags define whether the code entry or next function |
| 7620 | // should be visited or not. |
| 7621 | enum BodyVisitingPolicy { |
| 7622 | kVisitCodeEntry = 1 << 0, |
| 7623 | kVisitNextFunction = 1 << 1, |
| 7624 | |
| 7625 | kSkipCodeEntryAndNextFunction = 0, |
| 7626 | kVisitCodeEntryAndNextFunction = kVisitCodeEntry | kVisitNextFunction |
| 7627 | }; |
| 7628 | // Iterates the function object according to the visiting policy. |
| 7629 | template <BodyVisitingPolicy> |
| 7630 | class BodyDescriptorImpl; |
| 7631 | |
| 7632 | // Visit the whole object. |
| 7633 | typedef BodyDescriptorImpl<kVisitCodeEntryAndNextFunction> BodyDescriptor; |
| 7634 | |
| 7635 | // Don't visit next function. |
| 7636 | typedef BodyDescriptorImpl<kVisitCodeEntry> BodyDescriptorStrongCode; |
| 7637 | typedef BodyDescriptorImpl<kSkipCodeEntryAndNextFunction> |
| 7638 | BodyDescriptorWeakCode; |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 7639 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7640 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7641 | DECLARE_PRINTER(JSFunction) |
| 7642 | DECLARE_VERIFIER(JSFunction) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7643 | |
| 7644 | // Returns the number of allocated literals. |
| 7645 | inline int NumberOfLiterals(); |
| 7646 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7647 | // The function's name if it is configured, otherwise shared function info |
| 7648 | // debug name. |
| 7649 | static Handle<String> GetName(Handle<JSFunction> function); |
| 7650 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 7651 | // ES6 section 9.2.11 SetFunctionName |
| 7652 | // Because of the way this abstract operation is used in the spec, |
| 7653 | // it should never fail. |
| 7654 | static void SetName(Handle<JSFunction> function, Handle<Name> name, |
| 7655 | Handle<String> prefix); |
| 7656 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7657 | // The function's displayName if it is set, otherwise name if it is |
| 7658 | // configured, otherwise shared function info |
| 7659 | // debug name. |
| 7660 | static Handle<String> GetDebugName(Handle<JSFunction> function); |
| 7661 | |
| 7662 | // The function's string representation implemented according to |
| 7663 | // ES6 section 19.2.3.5 Function.prototype.toString ( ). |
| 7664 | static Handle<String> ToString(Handle<JSFunction> function); |
| 7665 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7666 | // Layout descriptors. The last property (from kNonWeakFieldsEndOffset to |
| 7667 | // kSize) is weak and has special handling during garbage collection. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7668 | static const int kPrototypeOrInitialMapOffset = JSObject::kHeaderSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7669 | static const int kSharedFunctionInfoOffset = |
| 7670 | kPrototypeOrInitialMapOffset + kPointerSize; |
| 7671 | static const int kContextOffset = kSharedFunctionInfoOffset + kPointerSize; |
| 7672 | static const int kLiteralsOffset = kContextOffset + kPointerSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7673 | static const int kNonWeakFieldsEndOffset = kLiteralsOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7674 | static const int kCodeEntryOffset = kNonWeakFieldsEndOffset; |
| 7675 | static const int kNextFunctionLinkOffset = kCodeEntryOffset + kPointerSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7676 | static const int kSize = kNextFunctionLinkOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7677 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7678 | private: |
| 7679 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunction); |
| 7680 | }; |
| 7681 | |
| 7682 | |
| 7683 | // JSGlobalProxy's prototype must be a JSGlobalObject or null, |
| 7684 | // and the prototype is hidden. JSGlobalProxy always delegates |
| 7685 | // property accesses to its prototype if the prototype is not null. |
| 7686 | // |
| 7687 | // A JSGlobalProxy can be reinitialized which will preserve its identity. |
| 7688 | // |
| 7689 | // Accessing a JSGlobalProxy requires security check. |
| 7690 | |
| 7691 | class JSGlobalProxy : public JSObject { |
| 7692 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7693 | // [native_context]: the owner native context of this global proxy object. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7694 | // 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] | 7695 | DECL_ACCESSORS(native_context, Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7696 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7697 | // [hash]: The hash code property (undefined if not initialized yet). |
| 7698 | DECL_ACCESSORS(hash, Object) |
| 7699 | |
| 7700 | DECLARE_CAST(JSGlobalProxy) |
| 7701 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7702 | inline bool IsDetachedFrom(JSGlobalObject* global) const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7703 | |
| 7704 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7705 | DECLARE_PRINTER(JSGlobalProxy) |
| 7706 | DECLARE_VERIFIER(JSGlobalProxy) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7707 | |
| 7708 | // Layout description. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7709 | static const int kNativeContextOffset = JSObject::kHeaderSize; |
| 7710 | static const int kHashOffset = kNativeContextOffset + kPointerSize; |
| 7711 | static const int kSize = kHashOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7712 | |
| 7713 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7714 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalProxy); |
| 7715 | }; |
| 7716 | |
| 7717 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7718 | // JavaScript global object. |
| 7719 | class JSGlobalObject : public JSObject { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7720 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7721 | // [native context]: the natives corresponding to this global object. |
| 7722 | DECL_ACCESSORS(native_context, Context) |
| 7723 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7724 | // [global proxy]: the global proxy object of the context |
| 7725 | DECL_ACCESSORS(global_proxy, JSObject) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7726 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7727 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7728 | static void InvalidatePropertyCell(Handle<JSGlobalObject> object, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 7729 | Handle<Name> name); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7730 | // Ensure that the global object has a cell for the given property name. |
| 7731 | static Handle<PropertyCell> EnsurePropertyCell(Handle<JSGlobalObject> global, |
| 7732 | Handle<Name> name); |
| 7733 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7734 | DECLARE_CAST(JSGlobalObject) |
| 7735 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7736 | inline bool IsDetached(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7737 | |
| 7738 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7739 | DECLARE_PRINTER(JSGlobalObject) |
| 7740 | DECLARE_VERIFIER(JSGlobalObject) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7741 | |
| 7742 | // Layout description. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7743 | static const int kNativeContextOffset = JSObject::kHeaderSize; |
| 7744 | static const int kGlobalProxyOffset = kNativeContextOffset + kPointerSize; |
| 7745 | static const int kHeaderSize = kGlobalProxyOffset + kPointerSize; |
| 7746 | static const int kSize = kHeaderSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7747 | |
| 7748 | private: |
| 7749 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalObject); |
| 7750 | }; |
| 7751 | |
| 7752 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7753 | // Representation for JS Wrapper objects, String, Number, Boolean, etc. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7754 | class JSValue: public JSObject { |
| 7755 | public: |
| 7756 | // [value]: the object being wrapped. |
| 7757 | DECL_ACCESSORS(value, Object) |
| 7758 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7759 | DECLARE_CAST(JSValue) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7760 | |
| 7761 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7762 | DECLARE_PRINTER(JSValue) |
| 7763 | DECLARE_VERIFIER(JSValue) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7764 | |
| 7765 | // Layout description. |
| 7766 | static const int kValueOffset = JSObject::kHeaderSize; |
| 7767 | static const int kSize = kValueOffset + kPointerSize; |
| 7768 | |
| 7769 | private: |
| 7770 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSValue); |
| 7771 | }; |
| 7772 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 7773 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7774 | class DateCache; |
| 7775 | |
| 7776 | // Representation for JS date objects. |
| 7777 | class JSDate: public JSObject { |
| 7778 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7779 | static MUST_USE_RESULT MaybeHandle<JSDate> New(Handle<JSFunction> constructor, |
| 7780 | Handle<JSReceiver> new_target, |
| 7781 | double tv); |
| 7782 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7783 | // If one component is NaN, all of them are, indicating a NaN time value. |
| 7784 | // [value]: the time value. |
| 7785 | DECL_ACCESSORS(value, Object) |
| 7786 | // [year]: caches year. Either undefined, smi, or NaN. |
| 7787 | DECL_ACCESSORS(year, Object) |
| 7788 | // [month]: caches month. Either undefined, smi, or NaN. |
| 7789 | DECL_ACCESSORS(month, Object) |
| 7790 | // [day]: caches day. Either undefined, smi, or NaN. |
| 7791 | DECL_ACCESSORS(day, Object) |
| 7792 | // [weekday]: caches day of week. Either undefined, smi, or NaN. |
| 7793 | DECL_ACCESSORS(weekday, Object) |
| 7794 | // [hour]: caches hours. Either undefined, smi, or NaN. |
| 7795 | DECL_ACCESSORS(hour, Object) |
| 7796 | // [min]: caches minutes. Either undefined, smi, or NaN. |
| 7797 | DECL_ACCESSORS(min, Object) |
| 7798 | // [sec]: caches seconds. Either undefined, smi, or NaN. |
| 7799 | DECL_ACCESSORS(sec, Object) |
| 7800 | // [cache stamp]: sample of the date cache stamp at the |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7801 | // moment when chached fields were cached. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7802 | DECL_ACCESSORS(cache_stamp, Object) |
| 7803 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7804 | DECLARE_CAST(JSDate) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7805 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7806 | // Returns the time value (UTC) identifying the current time. |
| 7807 | static double CurrentTimeValue(Isolate* isolate); |
| 7808 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7809 | // Returns the date field with the specified index. |
| 7810 | // See FieldIndex for the list of date fields. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7811 | static Object* GetField(Object* date, Smi* index); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7812 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7813 | static Handle<Object> SetValue(Handle<JSDate> date, double v); |
| 7814 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7815 | void SetValue(Object* value, bool is_value_nan); |
| 7816 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7817 | // ES6 section 20.3.4.45 Date.prototype [ @@toPrimitive ] |
| 7818 | static MUST_USE_RESULT MaybeHandle<Object> ToPrimitive( |
| 7819 | Handle<JSReceiver> receiver, Handle<Object> hint); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7820 | |
| 7821 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7822 | DECLARE_PRINTER(JSDate) |
| 7823 | DECLARE_VERIFIER(JSDate) |
| 7824 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7825 | // The order is important. It must be kept in sync with date macros |
| 7826 | // in macros.py. |
| 7827 | enum FieldIndex { |
| 7828 | kDateValue, |
| 7829 | kYear, |
| 7830 | kMonth, |
| 7831 | kDay, |
| 7832 | kWeekday, |
| 7833 | kHour, |
| 7834 | kMinute, |
| 7835 | kSecond, |
| 7836 | kFirstUncachedField, |
| 7837 | kMillisecond = kFirstUncachedField, |
| 7838 | kDays, |
| 7839 | kTimeInDay, |
| 7840 | kFirstUTCField, |
| 7841 | kYearUTC = kFirstUTCField, |
| 7842 | kMonthUTC, |
| 7843 | kDayUTC, |
| 7844 | kWeekdayUTC, |
| 7845 | kHourUTC, |
| 7846 | kMinuteUTC, |
| 7847 | kSecondUTC, |
| 7848 | kMillisecondUTC, |
| 7849 | kDaysUTC, |
| 7850 | kTimeInDayUTC, |
| 7851 | kTimezoneOffset |
| 7852 | }; |
| 7853 | |
| 7854 | // Layout description. |
| 7855 | static const int kValueOffset = JSObject::kHeaderSize; |
| 7856 | static const int kYearOffset = kValueOffset + kPointerSize; |
| 7857 | static const int kMonthOffset = kYearOffset + kPointerSize; |
| 7858 | static const int kDayOffset = kMonthOffset + kPointerSize; |
| 7859 | static const int kWeekdayOffset = kDayOffset + kPointerSize; |
| 7860 | static const int kHourOffset = kWeekdayOffset + kPointerSize; |
| 7861 | static const int kMinOffset = kHourOffset + kPointerSize; |
| 7862 | static const int kSecOffset = kMinOffset + kPointerSize; |
| 7863 | static const int kCacheStampOffset = kSecOffset + kPointerSize; |
| 7864 | static const int kSize = kCacheStampOffset + kPointerSize; |
| 7865 | |
| 7866 | private: |
| 7867 | inline Object* DoGetField(FieldIndex index); |
| 7868 | |
| 7869 | Object* GetUTCField(FieldIndex index, double value, DateCache* date_cache); |
| 7870 | |
| 7871 | // Computes and caches the cacheable fields of the date. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7872 | inline void SetCachedFields(int64_t local_time_ms, DateCache* date_cache); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7873 | |
| 7874 | |
| 7875 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSDate); |
| 7876 | }; |
| 7877 | |
| 7878 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 7879 | // Representation of message objects used for error reporting through |
| 7880 | // the API. The messages are formatted in JavaScript so this object is |
| 7881 | // a real JavaScript object. The information used for formatting the |
| 7882 | // error messages are not directly accessible from JavaScript to |
| 7883 | // prevent leaking information to user code called during error |
| 7884 | // formatting. |
| 7885 | class JSMessageObject: public JSObject { |
| 7886 | public: |
| 7887 | // [type]: the type of error message. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7888 | inline int type() const; |
| 7889 | inline void set_type(int value); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 7890 | |
| 7891 | // [arguments]: the arguments for formatting the error message. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7892 | DECL_ACCESSORS(argument, Object) |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 7893 | |
| 7894 | // [script]: the script from which the error message originated. |
| 7895 | DECL_ACCESSORS(script, Object) |
| 7896 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 7897 | // [stack_frames]: an array of stack frames for this error object. |
| 7898 | DECL_ACCESSORS(stack_frames, Object) |
| 7899 | |
| 7900 | // [start_position]: the start position in the script for the error message. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7901 | inline int start_position() const; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 7902 | inline void set_start_position(int value); |
| 7903 | |
| 7904 | // [end_position]: the end position in the script for the error message. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7905 | inline int end_position() const; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 7906 | inline void set_end_position(int value); |
| 7907 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7908 | DECLARE_CAST(JSMessageObject) |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 7909 | |
| 7910 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7911 | DECLARE_PRINTER(JSMessageObject) |
| 7912 | DECLARE_VERIFIER(JSMessageObject) |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 7913 | |
| 7914 | // Layout description. |
| 7915 | static const int kTypeOffset = JSObject::kHeaderSize; |
| 7916 | static const int kArgumentsOffset = kTypeOffset + kPointerSize; |
| 7917 | static const int kScriptOffset = kArgumentsOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7918 | static const int kStackFramesOffset = kScriptOffset + kPointerSize; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 7919 | static const int kStartPositionOffset = kStackFramesOffset + kPointerSize; |
| 7920 | static const int kEndPositionOffset = kStartPositionOffset + kPointerSize; |
| 7921 | static const int kSize = kEndPositionOffset + kPointerSize; |
| 7922 | |
| 7923 | typedef FixedBodyDescriptor<HeapObject::kMapOffset, |
| 7924 | kStackFramesOffset + kPointerSize, |
| 7925 | kSize> BodyDescriptor; |
| 7926 | }; |
| 7927 | |
| 7928 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7929 | // Regular expressions |
| 7930 | // The regular expression holds a single reference to a FixedArray in |
| 7931 | // the kDataOffset field. |
| 7932 | // The FixedArray contains the following data: |
| 7933 | // - tag : type of regexp implementation (not compiled yet, atom or irregexp) |
| 7934 | // - reference to the original source string |
| 7935 | // - reference to the original flag string |
| 7936 | // If it is an atom regexp |
| 7937 | // - a reference to a literal string to search for |
| 7938 | // If it is an irregexp regexp: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7939 | // - 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] | 7940 | // used for tracking the last usage (used for code flushing). |
| 7941 | // - a reference to code for UC16 inputs (bytecode or compiled), or a smi |
| 7942 | // used for tracking the last usage (used for code flushing).. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7943 | // - max number of registers used by irregexp implementations. |
| 7944 | // - number of capture registers (output values) of the regexp. |
| 7945 | class JSRegExp: public JSObject { |
| 7946 | public: |
| 7947 | // Meaning of Type: |
| 7948 | // NOT_COMPILED: Initial value. No data has been stored in the JSRegExp yet. |
| 7949 | // ATOM: A simple string to match against using an indexOf operation. |
| 7950 | // IRREGEXP: Compiled with Irregexp. |
| 7951 | // IRREGEXP_NATIVE: Compiled to native code with Irregexp. |
| 7952 | enum Type { NOT_COMPILED, ATOM, IRREGEXP }; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7953 | enum Flag { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7954 | kNone = 0, |
| 7955 | kGlobal = 1 << 0, |
| 7956 | kIgnoreCase = 1 << 1, |
| 7957 | kMultiline = 1 << 2, |
| 7958 | kSticky = 1 << 3, |
| 7959 | kUnicode = 1 << 4, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7960 | }; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7961 | typedef base::Flags<Flag> Flags; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7962 | |
| 7963 | DECL_ACCESSORS(data, Object) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7964 | DECL_ACCESSORS(flags, Object) |
| 7965 | DECL_ACCESSORS(source, Object) |
| 7966 | |
| 7967 | static MaybeHandle<JSRegExp> New(Handle<String> source, Flags flags); |
| 7968 | static MaybeHandle<JSRegExp> New(Handle<String> source, Handle<String> flags); |
| 7969 | static Handle<JSRegExp> Copy(Handle<JSRegExp> regexp); |
| 7970 | |
| 7971 | static MaybeHandle<JSRegExp> Initialize(Handle<JSRegExp> regexp, |
| 7972 | Handle<String> source, Flags flags); |
| 7973 | static MaybeHandle<JSRegExp> Initialize(Handle<JSRegExp> regexp, |
| 7974 | Handle<String> source, |
| 7975 | Handle<String> flags_string); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7976 | |
| 7977 | inline Type TypeTag(); |
| 7978 | inline int CaptureCount(); |
| 7979 | inline Flags GetFlags(); |
| 7980 | inline String* Pattern(); |
| 7981 | inline Object* DataAt(int index); |
| 7982 | // Set implementation data after the object has been prepared. |
| 7983 | inline void SetDataAt(int index, Object* value); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7984 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7985 | static int code_index(bool is_latin1) { |
| 7986 | if (is_latin1) { |
| 7987 | return kIrregexpLatin1CodeIndex; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7988 | } else { |
| 7989 | return kIrregexpUC16CodeIndex; |
| 7990 | } |
| 7991 | } |
| 7992 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7993 | static int saved_code_index(bool is_latin1) { |
| 7994 | if (is_latin1) { |
| 7995 | return kIrregexpLatin1CodeSavedIndex; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7996 | } else { |
| 7997 | return kIrregexpUC16CodeSavedIndex; |
| 7998 | } |
| 7999 | } |
| 8000 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8001 | DECLARE_CAST(JSRegExp) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8002 | |
| 8003 | // Dispatched behavior. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8004 | DECLARE_PRINTER(JSRegExp) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8005 | DECLARE_VERIFIER(JSRegExp) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8006 | |
| 8007 | static const int kDataOffset = JSObject::kHeaderSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8008 | static const int kSourceOffset = kDataOffset + kPointerSize; |
| 8009 | static const int kFlagsOffset = kSourceOffset + kPointerSize; |
| 8010 | static const int kSize = kFlagsOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8011 | |
| 8012 | // Indices in the data array. |
| 8013 | static const int kTagIndex = 0; |
| 8014 | static const int kSourceIndex = kTagIndex + 1; |
| 8015 | static const int kFlagsIndex = kSourceIndex + 1; |
| 8016 | static const int kDataIndex = kFlagsIndex + 1; |
| 8017 | // The data fields are used in different ways depending on the |
| 8018 | // value of the tag. |
| 8019 | // Atom regexps (literal strings). |
| 8020 | static const int kAtomPatternIndex = kDataIndex; |
| 8021 | |
| 8022 | static const int kAtomDataSize = kAtomPatternIndex + 1; |
| 8023 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8024 | // Irregexp compiled code or bytecode for Latin1. If compilation |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8025 | // fails, this fields hold an exception object that should be |
| 8026 | // thrown if the regexp is used again. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8027 | static const int kIrregexpLatin1CodeIndex = kDataIndex; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8028 | // Irregexp compiled code or bytecode for UC16. If compilation |
| 8029 | // fails, this fields hold an exception object that should be |
| 8030 | // thrown if the regexp is used again. |
| 8031 | static const int kIrregexpUC16CodeIndex = kDataIndex + 1; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 8032 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8033 | // Saved instance of Irregexp compiled code or bytecode for Latin1 that |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 8034 | // is a potential candidate for flushing. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8035 | static const int kIrregexpLatin1CodeSavedIndex = kDataIndex + 2; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 8036 | // Saved instance of Irregexp compiled code or bytecode for UC16 that is |
| 8037 | // a potential candidate for flushing. |
| 8038 | static const int kIrregexpUC16CodeSavedIndex = kDataIndex + 3; |
| 8039 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8040 | // Maximal number of registers used by either Latin1 or UC16. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8041 | // Only used to check that there is enough stack space |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 8042 | static const int kIrregexpMaxRegisterCountIndex = kDataIndex + 4; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8043 | // Number of captures in the compiled regexp. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 8044 | static const int kIrregexpCaptureCountIndex = kDataIndex + 5; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8045 | |
| 8046 | static const int kIrregexpDataSize = kIrregexpCaptureCountIndex + 1; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 8047 | |
| 8048 | // Offsets directly into the data fixed array. |
| 8049 | static const int kDataTagOffset = |
| 8050 | FixedArray::kHeaderSize + kTagIndex * kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8051 | static const int kDataOneByteCodeOffset = |
| 8052 | FixedArray::kHeaderSize + kIrregexpLatin1CodeIndex * kPointerSize; |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 8053 | static const int kDataUC16CodeOffset = |
| 8054 | FixedArray::kHeaderSize + kIrregexpUC16CodeIndex * kPointerSize; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 8055 | static const int kIrregexpCaptureCountOffset = |
| 8056 | FixedArray::kHeaderSize + kIrregexpCaptureCountIndex * kPointerSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8057 | |
| 8058 | // In-object fields. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8059 | static const int kLastIndexFieldIndex = 0; |
| 8060 | static const int kInObjectFieldCount = 1; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 8061 | |
| 8062 | // The uninitialized value for a regexp code object. |
| 8063 | static const int kUninitializedValue = -1; |
| 8064 | |
| 8065 | // The compilation error value for the regexp code object. The real error |
| 8066 | // object is in the saved code field. |
| 8067 | static const int kCompilationErrorValue = -2; |
| 8068 | |
| 8069 | // When we store the sweep generation at which we moved the code from the |
| 8070 | // code index to the saved code index we mask it of to be in the [0:255] |
| 8071 | // range. |
| 8072 | static const int kCodeAgeMask = 0xff; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8073 | }; |
| 8074 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8075 | DEFINE_OPERATORS_FOR_FLAGS(JSRegExp::Flags) |
| 8076 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8077 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 8078 | class CompilationCacheShape : public BaseShape<HashTableKey*> { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8079 | public: |
| 8080 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
| 8081 | return key->IsMatch(value); |
| 8082 | } |
| 8083 | |
| 8084 | static inline uint32_t Hash(HashTableKey* key) { |
| 8085 | return key->Hash(); |
| 8086 | } |
| 8087 | |
| 8088 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
| 8089 | return key->HashForObject(object); |
| 8090 | } |
| 8091 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8092 | static inline Handle<Object> AsHandle(Isolate* isolate, HashTableKey* key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8093 | |
| 8094 | static const int kPrefixSize = 0; |
| 8095 | static const int kEntrySize = 2; |
| 8096 | }; |
| 8097 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 8098 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8099 | // This cache is used in two different variants. For regexp caching, it simply |
| 8100 | // maps identifying info of the regexp to the cached regexp object. Scripts and |
| 8101 | // eval code only gets cached after a second probe for the code object. To do |
| 8102 | // so, on first "put" only a hash identifying the source is entered into the |
| 8103 | // cache, mapping it to a lifetime count of the hash. On each call to Age all |
| 8104 | // such lifetimes get reduced, and removed once they reach zero. If a second put |
| 8105 | // is called while such a hash is live in the cache, the hash gets replaced by |
| 8106 | // an actual cache entry. Age also removes stale live entries from the cache. |
| 8107 | // Such entries are identified by SharedFunctionInfos pointing to either the |
| 8108 | // recompilation stub, or to "old" code. This avoids memory leaks due to |
| 8109 | // premature caching of scripts and eval strings that are never needed later. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8110 | class CompilationCacheTable: public HashTable<CompilationCacheTable, |
| 8111 | CompilationCacheShape, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8112 | HashTableKey*> { |
| 8113 | public: |
| 8114 | // Find cached value for a string key, otherwise return null. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8115 | Handle<Object> Lookup( |
| 8116 | Handle<String> src, Handle<Context> context, LanguageMode language_mode); |
| 8117 | Handle<Object> LookupEval( |
| 8118 | Handle<String> src, Handle<SharedFunctionInfo> shared, |
| 8119 | LanguageMode language_mode, int scope_position); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8120 | Handle<Object> LookupRegExp(Handle<String> source, JSRegExp::Flags flags); |
| 8121 | static Handle<CompilationCacheTable> Put( |
| 8122 | Handle<CompilationCacheTable> cache, Handle<String> src, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8123 | Handle<Context> context, LanguageMode language_mode, |
| 8124 | Handle<Object> value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8125 | static Handle<CompilationCacheTable> PutEval( |
| 8126 | Handle<CompilationCacheTable> cache, Handle<String> src, |
| 8127 | Handle<SharedFunctionInfo> context, Handle<SharedFunctionInfo> value, |
| 8128 | int scope_position); |
| 8129 | static Handle<CompilationCacheTable> PutRegExp( |
| 8130 | Handle<CompilationCacheTable> cache, Handle<String> src, |
| 8131 | JSRegExp::Flags flags, Handle<FixedArray> value); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 8132 | void Remove(Object* value); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8133 | void Age(); |
| 8134 | static const int kHashGenerations = 10; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 8135 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8136 | DECLARE_CAST(CompilationCacheTable) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8137 | |
| 8138 | private: |
| 8139 | DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheTable); |
| 8140 | }; |
| 8141 | |
| 8142 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8143 | class CodeCache: public Struct { |
| 8144 | public: |
| 8145 | DECL_ACCESSORS(default_cache, FixedArray) |
| 8146 | DECL_ACCESSORS(normal_type_cache, Object) |
| 8147 | |
| 8148 | // Add the code object to the cache. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8149 | static void Update( |
| 8150 | Handle<CodeCache> cache, Handle<Name> name, Handle<Code> code); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8151 | |
| 8152 | // Lookup code object in the cache. Returns code object if found and undefined |
| 8153 | // if not. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8154 | Object* Lookup(Name* name, Code::Flags flags); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8155 | |
| 8156 | // Get the internal index of a code object in the cache. Returns -1 if the |
| 8157 | // code object is not in that cache. This index can be used to later call |
| 8158 | // RemoveByIndex. The cache cannot be modified between a call to GetIndex and |
| 8159 | // RemoveByIndex. |
| 8160 | int GetIndex(Object* name, Code* code); |
| 8161 | |
| 8162 | // Remove an object from the cache with the provided internal index. |
| 8163 | void RemoveByIndex(Object* name, Code* code, int index); |
| 8164 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8165 | DECLARE_CAST(CodeCache) |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8166 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8167 | // Dispatched behavior. |
| 8168 | DECLARE_PRINTER(CodeCache) |
| 8169 | DECLARE_VERIFIER(CodeCache) |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8170 | |
| 8171 | static const int kDefaultCacheOffset = HeapObject::kHeaderSize; |
| 8172 | static const int kNormalTypeCacheOffset = |
| 8173 | kDefaultCacheOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8174 | static const int kSize = kNormalTypeCacheOffset + kPointerSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8175 | |
| 8176 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8177 | static void UpdateDefaultCache( |
| 8178 | Handle<CodeCache> code_cache, Handle<Name> name, Handle<Code> code); |
| 8179 | static void UpdateNormalTypeCache( |
| 8180 | Handle<CodeCache> code_cache, Handle<Name> name, Handle<Code> code); |
| 8181 | Object* LookupDefaultCache(Name* name, Code::Flags flags); |
| 8182 | Object* LookupNormalTypeCache(Name* name, Code::Flags flags); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8183 | |
| 8184 | // Code cache layout of the default cache. Elements are alternating name and |
| 8185 | // code objects for non normal load/store/call IC's. |
| 8186 | static const int kCodeCacheEntrySize = 2; |
| 8187 | static const int kCodeCacheEntryNameOffset = 0; |
| 8188 | static const int kCodeCacheEntryCodeOffset = 1; |
| 8189 | |
| 8190 | DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCache); |
| 8191 | }; |
| 8192 | |
| 8193 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 8194 | class CodeCacheHashTableShape : public BaseShape<HashTableKey*> { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8195 | public: |
| 8196 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
| 8197 | return key->IsMatch(value); |
| 8198 | } |
| 8199 | |
| 8200 | static inline uint32_t Hash(HashTableKey* key) { |
| 8201 | return key->Hash(); |
| 8202 | } |
| 8203 | |
| 8204 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
| 8205 | return key->HashForObject(object); |
| 8206 | } |
| 8207 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8208 | static inline Handle<Object> AsHandle(Isolate* isolate, HashTableKey* key); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8209 | |
| 8210 | static const int kPrefixSize = 0; |
| 8211 | static const int kEntrySize = 2; |
| 8212 | }; |
| 8213 | |
| 8214 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8215 | class CodeCacheHashTable: public HashTable<CodeCacheHashTable, |
| 8216 | CodeCacheHashTableShape, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8217 | HashTableKey*> { |
| 8218 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8219 | Object* Lookup(Name* name, Code::Flags flags); |
| 8220 | static Handle<CodeCacheHashTable> Put( |
| 8221 | Handle<CodeCacheHashTable> table, |
| 8222 | Handle<Name> name, |
| 8223 | Handle<Code> code); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8224 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8225 | int GetIndex(Name* name, Code::Flags flags); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8226 | void RemoveByIndex(int index); |
| 8227 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8228 | DECLARE_CAST(CodeCacheHashTable) |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8229 | |
| 8230 | // Initial size of the fixed array backing the hash table. |
| 8231 | static const int kInitialSize = 64; |
| 8232 | |
| 8233 | private: |
| 8234 | DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCacheHashTable); |
| 8235 | }; |
| 8236 | |
| 8237 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 8238 | class PolymorphicCodeCache: public Struct { |
| 8239 | public: |
| 8240 | DECL_ACCESSORS(cache, Object) |
| 8241 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8242 | static void Update(Handle<PolymorphicCodeCache> cache, |
| 8243 | MapHandleList* maps, |
| 8244 | Code::Flags flags, |
| 8245 | Handle<Code> code); |
| 8246 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8247 | |
| 8248 | // Returns an undefined value if the entry is not found. |
| 8249 | Handle<Object> Lookup(MapHandleList* maps, Code::Flags flags); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 8250 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8251 | DECLARE_CAST(PolymorphicCodeCache) |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 8252 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8253 | // Dispatched behavior. |
| 8254 | DECLARE_PRINTER(PolymorphicCodeCache) |
| 8255 | DECLARE_VERIFIER(PolymorphicCodeCache) |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 8256 | |
| 8257 | static const int kCacheOffset = HeapObject::kHeaderSize; |
| 8258 | static const int kSize = kCacheOffset + kPointerSize; |
| 8259 | |
| 8260 | private: |
| 8261 | DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCache); |
| 8262 | }; |
| 8263 | |
| 8264 | |
| 8265 | class PolymorphicCodeCacheHashTable |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8266 | : public HashTable<PolymorphicCodeCacheHashTable, |
| 8267 | CodeCacheHashTableShape, |
| 8268 | HashTableKey*> { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 8269 | public: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8270 | Object* Lookup(MapHandleList* maps, int code_kind); |
| 8271 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8272 | static Handle<PolymorphicCodeCacheHashTable> Put( |
| 8273 | Handle<PolymorphicCodeCacheHashTable> hash_table, |
| 8274 | MapHandleList* maps, |
| 8275 | int code_kind, |
| 8276 | Handle<Code> code); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 8277 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8278 | DECLARE_CAST(PolymorphicCodeCacheHashTable) |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 8279 | |
| 8280 | static const int kInitialSize = 64; |
| 8281 | private: |
| 8282 | DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCacheHashTable); |
| 8283 | }; |
| 8284 | |
| 8285 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8286 | class TypeFeedbackInfo: public Struct { |
| 8287 | public: |
| 8288 | inline int ic_total_count(); |
| 8289 | inline void set_ic_total_count(int count); |
| 8290 | |
Ben Murdoch | 8f9999f | 2012-04-23 10:39:17 +0100 | [diff] [blame] | 8291 | inline int ic_with_type_info_count(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8292 | inline void change_ic_with_type_info_count(int delta); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8293 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8294 | inline int ic_generic_count(); |
| 8295 | inline void change_ic_generic_count(int delta); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8296 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8297 | inline void initialize_storage(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8298 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8299 | inline void change_own_type_change_checksum(); |
| 8300 | inline int own_type_change_checksum(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8301 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8302 | inline void set_inlined_type_change_checksum(int checksum); |
| 8303 | inline bool matches_inlined_type_change_checksum(int checksum); |
| 8304 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8305 | DECLARE_CAST(TypeFeedbackInfo) |
| 8306 | |
| 8307 | // Dispatched behavior. |
| 8308 | DECLARE_PRINTER(TypeFeedbackInfo) |
| 8309 | DECLARE_VERIFIER(TypeFeedbackInfo) |
| 8310 | |
| 8311 | static const int kStorage1Offset = HeapObject::kHeaderSize; |
| 8312 | static const int kStorage2Offset = kStorage1Offset + kPointerSize; |
| 8313 | static const int kStorage3Offset = kStorage2Offset + kPointerSize; |
| 8314 | static const int kSize = kStorage3Offset + kPointerSize; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8315 | |
| 8316 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8317 | static const int kTypeChangeChecksumBits = 7; |
| 8318 | |
| 8319 | class ICTotalCountField: public BitField<int, 0, |
| 8320 | kSmiValueSize - kTypeChangeChecksumBits> {}; // NOLINT |
| 8321 | class OwnTypeChangeChecksum: public BitField<int, |
| 8322 | kSmiValueSize - kTypeChangeChecksumBits, |
| 8323 | kTypeChangeChecksumBits> {}; // NOLINT |
| 8324 | class ICsWithTypeInfoCountField: public BitField<int, 0, |
| 8325 | kSmiValueSize - kTypeChangeChecksumBits> {}; // NOLINT |
| 8326 | class InlinedTypeChangeChecksum: public BitField<int, |
| 8327 | kSmiValueSize - kTypeChangeChecksumBits, |
| 8328 | kTypeChangeChecksumBits> {}; // NOLINT |
| 8329 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8330 | DISALLOW_IMPLICIT_CONSTRUCTORS(TypeFeedbackInfo); |
| 8331 | }; |
| 8332 | |
| 8333 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8334 | enum AllocationSiteMode { |
| 8335 | DONT_TRACK_ALLOCATION_SITE, |
| 8336 | TRACK_ALLOCATION_SITE, |
| 8337 | LAST_ALLOCATION_SITE_MODE = TRACK_ALLOCATION_SITE |
| 8338 | }; |
| 8339 | |
| 8340 | |
| 8341 | class AllocationSite: public Struct { |
| 8342 | public: |
| 8343 | static const uint32_t kMaximumArrayBytesToPretransition = 8 * 1024; |
| 8344 | static const double kPretenureRatio; |
| 8345 | static const int kPretenureMinimumCreated = 100; |
| 8346 | |
| 8347 | // Values for pretenure decision field. |
| 8348 | enum PretenureDecision { |
| 8349 | kUndecided = 0, |
| 8350 | kDontTenure = 1, |
| 8351 | kMaybeTenure = 2, |
| 8352 | kTenure = 3, |
| 8353 | kZombie = 4, |
| 8354 | kLastPretenureDecisionValue = kZombie |
| 8355 | }; |
| 8356 | |
| 8357 | const char* PretenureDecisionName(PretenureDecision decision); |
| 8358 | |
| 8359 | DECL_ACCESSORS(transition_info, Object) |
| 8360 | // nested_site threads a list of sites that represent nested literals |
| 8361 | // walked in a particular order. So [[1, 2], 1, 2] will have one |
| 8362 | // nested_site, but [[1, 2], 3, [4]] will have a list of two. |
| 8363 | DECL_ACCESSORS(nested_site, Object) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8364 | DECL_INT_ACCESSORS(pretenure_data) |
| 8365 | DECL_INT_ACCESSORS(pretenure_create_count) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8366 | DECL_ACCESSORS(dependent_code, DependentCode) |
| 8367 | DECL_ACCESSORS(weak_next, Object) |
| 8368 | |
| 8369 | inline void Initialize(); |
| 8370 | |
| 8371 | // This method is expensive, it should only be called for reporting. |
| 8372 | bool IsNestedSite(); |
| 8373 | |
| 8374 | // transition_info bitfields, for constructed array transition info. |
| 8375 | class ElementsKindBits: public BitField<ElementsKind, 0, 15> {}; |
| 8376 | class UnusedBits: public BitField<int, 15, 14> {}; |
| 8377 | class DoNotInlineBit: public BitField<bool, 29, 1> {}; |
| 8378 | |
| 8379 | // Bitfields for pretenure_data |
| 8380 | class MementoFoundCountBits: public BitField<int, 0, 26> {}; |
| 8381 | class PretenureDecisionBits: public BitField<PretenureDecision, 26, 3> {}; |
| 8382 | class DeoptDependentCodeBit: public BitField<bool, 29, 1> {}; |
| 8383 | STATIC_ASSERT(PretenureDecisionBits::kMax >= kLastPretenureDecisionValue); |
| 8384 | |
| 8385 | // Increments the mementos found counter and returns true when the first |
| 8386 | // memento was found for a given allocation site. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8387 | inline bool IncrementMementoFoundCount(int increment = 1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8388 | |
| 8389 | inline void IncrementMementoCreateCount(); |
| 8390 | |
| 8391 | PretenureFlag GetPretenureMode(); |
| 8392 | |
| 8393 | void ResetPretenureDecision(); |
| 8394 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8395 | inline PretenureDecision pretenure_decision(); |
| 8396 | inline void set_pretenure_decision(PretenureDecision decision); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8397 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8398 | inline bool deopt_dependent_code(); |
| 8399 | inline void set_deopt_dependent_code(bool deopt); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8400 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8401 | inline int memento_found_count(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8402 | inline void set_memento_found_count(int count); |
| 8403 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8404 | inline int memento_create_count(); |
| 8405 | inline void set_memento_create_count(int count); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8406 | |
| 8407 | // The pretenuring decision is made during gc, and the zombie state allows |
| 8408 | // us to recognize when an allocation site is just being kept alive because |
| 8409 | // a later traversal of new space may discover AllocationMementos that point |
| 8410 | // to this AllocationSite. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8411 | inline bool IsZombie(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8412 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8413 | inline bool IsMaybeTenure(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8414 | |
| 8415 | inline void MarkZombie(); |
| 8416 | |
| 8417 | inline bool MakePretenureDecision(PretenureDecision current_decision, |
| 8418 | double ratio, |
| 8419 | bool maximum_size_scavenge); |
| 8420 | |
| 8421 | inline bool DigestPretenuringFeedback(bool maximum_size_scavenge); |
| 8422 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8423 | inline ElementsKind GetElementsKind(); |
| 8424 | inline void SetElementsKind(ElementsKind kind); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8425 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8426 | inline bool CanInlineCall(); |
| 8427 | inline void SetDoNotInlineCall(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8428 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8429 | inline bool SitePointsToLiteral(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8430 | |
| 8431 | static void DigestTransitionFeedback(Handle<AllocationSite> site, |
| 8432 | ElementsKind to_kind); |
| 8433 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8434 | DECLARE_PRINTER(AllocationSite) |
| 8435 | DECLARE_VERIFIER(AllocationSite) |
| 8436 | |
| 8437 | DECLARE_CAST(AllocationSite) |
| 8438 | static inline AllocationSiteMode GetMode( |
| 8439 | ElementsKind boilerplate_elements_kind); |
| 8440 | static inline AllocationSiteMode GetMode(ElementsKind from, ElementsKind to); |
| 8441 | static inline bool CanTrack(InstanceType type); |
| 8442 | |
| 8443 | static const int kTransitionInfoOffset = HeapObject::kHeaderSize; |
| 8444 | static const int kNestedSiteOffset = kTransitionInfoOffset + kPointerSize; |
| 8445 | static const int kPretenureDataOffset = kNestedSiteOffset + kPointerSize; |
| 8446 | static const int kPretenureCreateCountOffset = |
| 8447 | kPretenureDataOffset + kPointerSize; |
| 8448 | static const int kDependentCodeOffset = |
| 8449 | kPretenureCreateCountOffset + kPointerSize; |
| 8450 | static const int kWeakNextOffset = kDependentCodeOffset + kPointerSize; |
| 8451 | static const int kSize = kWeakNextOffset + kPointerSize; |
| 8452 | |
| 8453 | // During mark compact we need to take special care for the dependent code |
| 8454 | // field. |
| 8455 | static const int kPointerFieldsBeginOffset = kTransitionInfoOffset; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8456 | static const int kPointerFieldsEndOffset = kWeakNextOffset; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8457 | |
| 8458 | // For other visitors, use the fixed body descriptor below. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 8459 | typedef FixedBodyDescriptor<HeapObject::kHeaderSize, kSize, kSize> |
| 8460 | BodyDescriptor; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8461 | |
| 8462 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8463 | inline bool PretenuringDecisionMade(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8464 | |
| 8465 | DISALLOW_IMPLICIT_CONSTRUCTORS(AllocationSite); |
| 8466 | }; |
| 8467 | |
| 8468 | |
| 8469 | class AllocationMemento: public Struct { |
| 8470 | public: |
| 8471 | static const int kAllocationSiteOffset = HeapObject::kHeaderSize; |
| 8472 | static const int kSize = kAllocationSiteOffset + kPointerSize; |
| 8473 | |
| 8474 | DECL_ACCESSORS(allocation_site, Object) |
| 8475 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8476 | inline bool IsValid(); |
| 8477 | inline AllocationSite* GetAllocationSite(); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 8478 | inline Address GetAllocationSiteUnchecked(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8479 | |
| 8480 | DECLARE_PRINTER(AllocationMemento) |
| 8481 | DECLARE_VERIFIER(AllocationMemento) |
| 8482 | |
| 8483 | DECLARE_CAST(AllocationMemento) |
| 8484 | |
| 8485 | private: |
| 8486 | DISALLOW_IMPLICIT_CONSTRUCTORS(AllocationMemento); |
| 8487 | }; |
| 8488 | |
| 8489 | |
| 8490 | // Representation of a slow alias as part of a sloppy arguments objects. |
| 8491 | // For fast aliases (if HasSloppyArgumentsElements()): |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8492 | // - the parameter map contains an index into the context |
| 8493 | // - all attributes of the element have default values |
| 8494 | // For slow aliases (if HasDictionaryArgumentsElements()): |
| 8495 | // - the parameter map contains no fast alias mapping (i.e. the hole) |
| 8496 | // - this struct (in the slow backing store) contains an index into the context |
| 8497 | // - all attributes are available as part if the property details |
| 8498 | class AliasedArgumentsEntry: public Struct { |
| 8499 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8500 | inline int aliased_context_slot() const; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8501 | inline void set_aliased_context_slot(int count); |
| 8502 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8503 | DECLARE_CAST(AliasedArgumentsEntry) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8504 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8505 | // Dispatched behavior. |
| 8506 | DECLARE_PRINTER(AliasedArgumentsEntry) |
| 8507 | DECLARE_VERIFIER(AliasedArgumentsEntry) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8508 | |
| 8509 | static const int kAliasedContextSlot = HeapObject::kHeaderSize; |
| 8510 | static const int kSize = kAliasedContextSlot + kPointerSize; |
| 8511 | |
| 8512 | private: |
| 8513 | DISALLOW_IMPLICIT_CONSTRUCTORS(AliasedArgumentsEntry); |
| 8514 | }; |
| 8515 | |
| 8516 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8517 | enum AllowNullsFlag {ALLOW_NULLS, DISALLOW_NULLS}; |
| 8518 | enum RobustnessFlag {ROBUST_STRING_TRAVERSAL, FAST_STRING_TRAVERSAL}; |
| 8519 | |
| 8520 | |
| 8521 | class StringHasher { |
| 8522 | public: |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 8523 | explicit inline StringHasher(int length, uint32_t seed); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8524 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8525 | template <typename schar> |
| 8526 | static inline uint32_t HashSequentialString(const schar* chars, |
| 8527 | int length, |
| 8528 | uint32_t seed); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8529 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8530 | // Reads all the data, even for long strings and computes the utf16 length. |
| 8531 | static uint32_t ComputeUtf8Hash(Vector<const char> chars, |
| 8532 | uint32_t seed, |
| 8533 | int* utf16_length_out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8534 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 8535 | // Calculated hash value for a string consisting of 1 to |
| 8536 | // String::kMaxArrayIndexSize digits with no leading zeros (except "0"). |
| 8537 | // value is represented decimal value. |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 8538 | static uint32_t MakeArrayIndexHash(uint32_t value, int length); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 8539 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 8540 | // No string is allowed to have a hash of zero. That value is reserved |
| 8541 | // for internal properties. If the hash calculation yields zero then we |
| 8542 | // use 27 instead. |
| 8543 | static const int kZeroHash = 27; |
| 8544 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8545 | // Reusable parts of the hashing algorithm. |
| 8546 | INLINE(static uint32_t AddCharacterCore(uint32_t running_hash, uint16_t c)); |
| 8547 | INLINE(static uint32_t GetHashCore(uint32_t running_hash)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8548 | INLINE(static uint32_t ComputeRunningHash(uint32_t running_hash, |
| 8549 | const uc16* chars, int length)); |
| 8550 | INLINE(static uint32_t ComputeRunningHashOneByte(uint32_t running_hash, |
| 8551 | const char* chars, |
| 8552 | int length)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8553 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8554 | protected: |
| 8555 | // Returns the value to store in the hash field of a string with |
| 8556 | // the given length and contents. |
| 8557 | uint32_t GetHashField(); |
| 8558 | // Returns true if the hash of this string can be computed without |
| 8559 | // looking at the contents. |
| 8560 | inline bool has_trivial_hash(); |
| 8561 | // Adds a block of characters to the hash. |
| 8562 | template<typename Char> |
| 8563 | inline void AddCharacters(const Char* chars, int len); |
| 8564 | |
| 8565 | private: |
| 8566 | // Add a character to the hash. |
| 8567 | inline void AddCharacter(uint16_t c); |
| 8568 | // Update index. Returns true if string is still an index. |
| 8569 | inline bool UpdateIndex(uint16_t c); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8570 | |
| 8571 | int length_; |
| 8572 | uint32_t raw_running_hash_; |
| 8573 | uint32_t array_index_; |
| 8574 | bool is_array_index_; |
| 8575 | bool is_first_char_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8576 | DISALLOW_COPY_AND_ASSIGN(StringHasher); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8577 | }; |
| 8578 | |
| 8579 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8580 | class IteratingStringHasher : public StringHasher { |
| 8581 | public: |
| 8582 | static inline uint32_t Hash(String* string, uint32_t seed); |
| 8583 | inline void VisitOneByteString(const uint8_t* chars, int length); |
| 8584 | inline void VisitTwoByteString(const uint16_t* chars, int length); |
| 8585 | |
| 8586 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8587 | inline IteratingStringHasher(int len, uint32_t seed); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8588 | void VisitConsString(ConsString* cons_string); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8589 | DISALLOW_COPY_AND_ASSIGN(IteratingStringHasher); |
| 8590 | }; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 8591 | |
| 8592 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8593 | // The characteristics of a string are stored in its map. Retrieving these |
| 8594 | // few bits of information is moderately expensive, involving two memory |
| 8595 | // loads where the second is dependent on the first. To improve efficiency |
| 8596 | // the shape of the string is given its own class so that it can be retrieved |
| 8597 | // once and used for several string operations. A StringShape is small enough |
| 8598 | // to be passed by value and is immutable, but be aware that flattening a |
| 8599 | // string can potentially alter its shape. Also be aware that a GC caused by |
| 8600 | // something else can alter the shape of a string due to ConsString |
| 8601 | // shortcutting. Keeping these restrictions in mind has proven to be error- |
| 8602 | // prone and so we no longer put StringShapes in variables unless there is a |
| 8603 | // concrete performance benefit at that particular point in the code. |
| 8604 | class StringShape BASE_EMBEDDED { |
| 8605 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8606 | inline explicit StringShape(const String* s); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8607 | inline explicit StringShape(Map* s); |
| 8608 | inline explicit StringShape(InstanceType t); |
| 8609 | inline bool IsSequential(); |
| 8610 | inline bool IsExternal(); |
| 8611 | inline bool IsCons(); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8612 | inline bool IsSliced(); |
| 8613 | inline bool IsIndirect(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8614 | inline bool IsExternalOneByte(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8615 | inline bool IsExternalTwoByte(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8616 | inline bool IsSequentialOneByte(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8617 | inline bool IsSequentialTwoByte(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8618 | inline bool IsInternalized(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8619 | inline StringRepresentationTag representation_tag(); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8620 | inline uint32_t encoding_tag(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8621 | inline uint32_t full_representation_tag(); |
| 8622 | inline uint32_t size_tag(); |
| 8623 | #ifdef DEBUG |
| 8624 | inline uint32_t type() { return type_; } |
| 8625 | inline void invalidate() { valid_ = false; } |
| 8626 | inline bool valid() { return valid_; } |
| 8627 | #else |
| 8628 | inline void invalidate() { } |
| 8629 | #endif |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 8630 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8631 | private: |
| 8632 | uint32_t type_; |
| 8633 | #ifdef DEBUG |
| 8634 | inline void set_valid() { valid_ = true; } |
| 8635 | bool valid_; |
| 8636 | #else |
| 8637 | inline void set_valid() { } |
| 8638 | #endif |
| 8639 | }; |
| 8640 | |
| 8641 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8642 | // The Name abstract class captures anything that can be used as a property |
| 8643 | // name, i.e., strings and symbols. All names store a hash value. |
| 8644 | class Name: public HeapObject { |
| 8645 | public: |
| 8646 | // Get and set the hash field of the name. |
| 8647 | inline uint32_t hash_field(); |
| 8648 | inline void set_hash_field(uint32_t value); |
| 8649 | |
| 8650 | // Tells whether the hash code has been computed. |
| 8651 | inline bool HasHashCode(); |
| 8652 | |
| 8653 | // Returns a hash value used for the property table |
| 8654 | inline uint32_t Hash(); |
| 8655 | |
| 8656 | // Equality operations. |
| 8657 | inline bool Equals(Name* other); |
| 8658 | inline static bool Equals(Handle<Name> one, Handle<Name> two); |
| 8659 | |
| 8660 | // Conversion. |
| 8661 | inline bool AsArrayIndex(uint32_t* index); |
| 8662 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8663 | // If the name is private, it can only name own properties. |
| 8664 | inline bool IsPrivate(); |
| 8665 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 8666 | inline bool IsUniqueName() const; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8667 | |
| 8668 | // Return a string version of this name that is converted according to the |
| 8669 | // rules described in ES6 section 9.2.11. |
| 8670 | MUST_USE_RESULT static MaybeHandle<String> ToFunctionName(Handle<Name> name); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8671 | |
| 8672 | DECLARE_CAST(Name) |
| 8673 | |
| 8674 | DECLARE_PRINTER(Name) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8675 | #if TRACE_MAPS |
| 8676 | void NameShortPrint(); |
| 8677 | int NameShortPrint(Vector<char> str); |
| 8678 | #endif |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8679 | |
| 8680 | // Layout description. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8681 | static const int kHashFieldSlot = HeapObject::kHeaderSize; |
| 8682 | #if V8_TARGET_LITTLE_ENDIAN || !V8_HOST_ARCH_64_BIT |
| 8683 | static const int kHashFieldOffset = kHashFieldSlot; |
| 8684 | #else |
| 8685 | static const int kHashFieldOffset = kHashFieldSlot + kIntSize; |
| 8686 | #endif |
| 8687 | static const int kSize = kHashFieldSlot + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8688 | |
| 8689 | // Mask constant for checking if a name has a computed hash code |
| 8690 | // and if it is a string that is an array index. The least significant bit |
| 8691 | // indicates whether a hash code has been computed. If the hash code has |
| 8692 | // been computed the 2nd bit tells whether the string can be used as an |
| 8693 | // array index. |
| 8694 | static const int kHashNotComputedMask = 1; |
| 8695 | static const int kIsNotArrayIndexMask = 1 << 1; |
| 8696 | static const int kNofHashBitFields = 2; |
| 8697 | |
| 8698 | // Shift constant retrieving hash code from hash field. |
| 8699 | static const int kHashShift = kNofHashBitFields; |
| 8700 | |
| 8701 | // Only these bits are relevant in the hash, since the top two are shifted |
| 8702 | // out. |
| 8703 | static const uint32_t kHashBitMask = 0xffffffffu >> kHashShift; |
| 8704 | |
| 8705 | // Array index strings this short can keep their index in the hash field. |
| 8706 | static const int kMaxCachedArrayIndexLength = 7; |
| 8707 | |
| 8708 | // For strings which are array indexes the hash value has the string length |
| 8709 | // mixed into the hash, mainly to avoid a hash value of zero which would be |
| 8710 | // the case for the string '0'. 24 bits are used for the array index value. |
| 8711 | static const int kArrayIndexValueBits = 24; |
| 8712 | static const int kArrayIndexLengthBits = |
| 8713 | kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields; |
| 8714 | |
| 8715 | STATIC_ASSERT((kArrayIndexLengthBits > 0)); |
| 8716 | |
| 8717 | class ArrayIndexValueBits : public BitField<unsigned int, kNofHashBitFields, |
| 8718 | kArrayIndexValueBits> {}; // NOLINT |
| 8719 | class ArrayIndexLengthBits : public BitField<unsigned int, |
| 8720 | kNofHashBitFields + kArrayIndexValueBits, |
| 8721 | kArrayIndexLengthBits> {}; // NOLINT |
| 8722 | |
| 8723 | // Check that kMaxCachedArrayIndexLength + 1 is a power of two so we |
| 8724 | // could use a mask to test if the length of string is less than or equal to |
| 8725 | // kMaxCachedArrayIndexLength. |
| 8726 | STATIC_ASSERT(IS_POWER_OF_TWO(kMaxCachedArrayIndexLength + 1)); |
| 8727 | |
| 8728 | static const unsigned int kContainsCachedArrayIndexMask = |
| 8729 | (~static_cast<unsigned>(kMaxCachedArrayIndexLength) |
| 8730 | << ArrayIndexLengthBits::kShift) | |
| 8731 | kIsNotArrayIndexMask; |
| 8732 | |
| 8733 | // Value of empty hash field indicating that the hash is not computed. |
| 8734 | static const int kEmptyHashField = |
| 8735 | kIsNotArrayIndexMask | kHashNotComputedMask; |
| 8736 | |
| 8737 | protected: |
| 8738 | static inline bool IsHashFieldComputed(uint32_t field); |
| 8739 | |
| 8740 | private: |
| 8741 | DISALLOW_IMPLICIT_CONSTRUCTORS(Name); |
| 8742 | }; |
| 8743 | |
| 8744 | |
| 8745 | // ES6 symbols. |
| 8746 | class Symbol: public Name { |
| 8747 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8748 | // [name]: The print name of a symbol, or undefined if none. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8749 | DECL_ACCESSORS(name, Object) |
| 8750 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8751 | DECL_INT_ACCESSORS(flags) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8752 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8753 | // [is_private]: Whether this is a private symbol. Private symbols can only |
| 8754 | // be used to designate own properties of objects. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8755 | DECL_BOOLEAN_ACCESSORS(is_private) |
| 8756 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8757 | // [is_well_known_symbol]: Whether this is a spec-defined well-known symbol, |
| 8758 | // or not. Well-known symbols do not throw when an access check fails during |
| 8759 | // a load. |
| 8760 | DECL_BOOLEAN_ACCESSORS(is_well_known_symbol) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8761 | |
| 8762 | DECLARE_CAST(Symbol) |
| 8763 | |
| 8764 | // Dispatched behavior. |
| 8765 | DECLARE_PRINTER(Symbol) |
| 8766 | DECLARE_VERIFIER(Symbol) |
| 8767 | |
| 8768 | // Layout description. |
| 8769 | static const int kNameOffset = Name::kSize; |
| 8770 | static const int kFlagsOffset = kNameOffset + kPointerSize; |
| 8771 | static const int kSize = kFlagsOffset + kPointerSize; |
| 8772 | |
| 8773 | typedef FixedBodyDescriptor<kNameOffset, kFlagsOffset, kSize> BodyDescriptor; |
| 8774 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8775 | void SymbolShortPrint(std::ostream& os); |
| 8776 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8777 | private: |
| 8778 | static const int kPrivateBit = 0; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8779 | static const int kWellKnownSymbolBit = 1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8780 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8781 | const char* PrivateSymbolToName() const; |
| 8782 | |
| 8783 | #if TRACE_MAPS |
| 8784 | friend class Name; // For PrivateSymbolToName. |
| 8785 | #endif |
| 8786 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8787 | DISALLOW_IMPLICIT_CONSTRUCTORS(Symbol); |
| 8788 | }; |
| 8789 | |
| 8790 | |
| 8791 | class ConsString; |
| 8792 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8793 | // The String abstract class captures JavaScript string values: |
| 8794 | // |
| 8795 | // Ecma-262: |
| 8796 | // 4.3.16 String Value |
| 8797 | // A string value is a member of the type String and is a finite |
| 8798 | // ordered sequence of zero or more 16-bit unsigned integer values. |
| 8799 | // |
| 8800 | // All string values have a length field. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8801 | class String: public Name { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8802 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8803 | enum Encoding { ONE_BYTE_ENCODING, TWO_BYTE_ENCODING }; |
| 8804 | |
| 8805 | // Array index strings this short can keep their index in the hash field. |
| 8806 | static const int kMaxCachedArrayIndexLength = 7; |
| 8807 | |
| 8808 | // For strings which are array indexes the hash value has the string length |
| 8809 | // mixed into the hash, mainly to avoid a hash value of zero which would be |
| 8810 | // the case for the string '0'. 24 bits are used for the array index value. |
| 8811 | static const int kArrayIndexValueBits = 24; |
| 8812 | static const int kArrayIndexLengthBits = |
| 8813 | kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields; |
| 8814 | |
| 8815 | STATIC_ASSERT((kArrayIndexLengthBits > 0)); |
| 8816 | |
| 8817 | class ArrayIndexValueBits : public BitField<unsigned int, kNofHashBitFields, |
| 8818 | kArrayIndexValueBits> {}; // NOLINT |
| 8819 | class ArrayIndexLengthBits : public BitField<unsigned int, |
| 8820 | kNofHashBitFields + kArrayIndexValueBits, |
| 8821 | kArrayIndexLengthBits> {}; // NOLINT |
| 8822 | |
| 8823 | // Check that kMaxCachedArrayIndexLength + 1 is a power of two so we |
| 8824 | // could use a mask to test if the length of string is less than or equal to |
| 8825 | // kMaxCachedArrayIndexLength. |
| 8826 | STATIC_ASSERT(IS_POWER_OF_TWO(kMaxCachedArrayIndexLength + 1)); |
| 8827 | |
| 8828 | static const unsigned int kContainsCachedArrayIndexMask = |
| 8829 | (~static_cast<unsigned>(kMaxCachedArrayIndexLength) |
| 8830 | << ArrayIndexLengthBits::kShift) | |
| 8831 | kIsNotArrayIndexMask; |
| 8832 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8833 | class SubStringRange { |
| 8834 | public: |
| 8835 | explicit inline SubStringRange(String* string, int first = 0, |
| 8836 | int length = -1); |
| 8837 | class iterator; |
| 8838 | inline iterator begin(); |
| 8839 | inline iterator end(); |
| 8840 | |
| 8841 | private: |
| 8842 | String* string_; |
| 8843 | int first_; |
| 8844 | int length_; |
| 8845 | }; |
| 8846 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8847 | // Representation of the flat content of a String. |
| 8848 | // A non-flat string doesn't have flat content. |
| 8849 | // 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] | 8850 | // one-byte chars or two-byte UC16. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8851 | // Returned by String::GetFlatContent(). |
| 8852 | class FlatContent { |
| 8853 | public: |
| 8854 | // Returns true if the string is flat and this structure contains content. |
| 8855 | bool IsFlat() { return state_ != NON_FLAT; } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8856 | // Returns true if the structure contains one-byte content. |
| 8857 | bool IsOneByte() { return state_ == ONE_BYTE; } |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8858 | // Returns true if the structure contains two-byte content. |
| 8859 | bool IsTwoByte() { return state_ == TWO_BYTE; } |
| 8860 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8861 | // Return the one byte content of the string. Only use if IsOneByte() |
| 8862 | // returns true. |
| 8863 | Vector<const uint8_t> ToOneByteVector() { |
| 8864 | DCHECK_EQ(ONE_BYTE, state_); |
| 8865 | return Vector<const uint8_t>(onebyte_start, length_); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8866 | } |
| 8867 | // Return the two-byte content of the string. Only use if IsTwoByte() |
| 8868 | // returns true. |
| 8869 | Vector<const uc16> ToUC16Vector() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8870 | DCHECK_EQ(TWO_BYTE, state_); |
| 8871 | return Vector<const uc16>(twobyte_start, length_); |
| 8872 | } |
| 8873 | |
| 8874 | uc16 Get(int i) { |
| 8875 | DCHECK(i < length_); |
| 8876 | DCHECK(state_ != NON_FLAT); |
| 8877 | if (state_ == ONE_BYTE) return onebyte_start[i]; |
| 8878 | return twobyte_start[i]; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8879 | } |
| 8880 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8881 | bool UsesSameString(const FlatContent& other) const { |
| 8882 | return onebyte_start == other.onebyte_start; |
| 8883 | } |
| 8884 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8885 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8886 | enum State { NON_FLAT, ONE_BYTE, TWO_BYTE }; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8887 | |
| 8888 | // Constructors only used by String::GetFlatContent(). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8889 | explicit FlatContent(const uint8_t* start, int length) |
| 8890 | : onebyte_start(start), length_(length), state_(ONE_BYTE) {} |
| 8891 | explicit FlatContent(const uc16* start, int length) |
| 8892 | : twobyte_start(start), length_(length), state_(TWO_BYTE) { } |
| 8893 | FlatContent() : onebyte_start(NULL), length_(0), state_(NON_FLAT) { } |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8894 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8895 | union { |
| 8896 | const uint8_t* onebyte_start; |
| 8897 | const uc16* twobyte_start; |
| 8898 | }; |
| 8899 | int length_; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8900 | State state_; |
| 8901 | |
| 8902 | friend class String; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8903 | friend class IterableSubString; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8904 | }; |
| 8905 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8906 | template <typename Char> |
| 8907 | INLINE(Vector<const Char> GetCharVector()); |
| 8908 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8909 | // Get and set the length of the string. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8910 | inline int length() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8911 | inline void set_length(int value); |
| 8912 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8913 | // Get and set the length of the string using acquire loads and release |
| 8914 | // stores. |
| 8915 | inline int synchronized_length() const; |
| 8916 | inline void synchronized_set_length(int value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8917 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8918 | // Returns whether this string has only one-byte chars, i.e. all of them can |
| 8919 | // 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] | 8920 | // two-byte. Such strings may appear when the embedder prefers |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8921 | // two-byte external representations even for one-byte data. |
| 8922 | inline bool IsOneByteRepresentation() const; |
| 8923 | inline bool IsTwoByteRepresentation() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8924 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8925 | // Cons and slices have an encoding flag that may not represent the actual |
| 8926 | // encoding of the underlying string. This is taken into account here. |
| 8927 | // Requires: this->IsFlat() |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8928 | inline bool IsOneByteRepresentationUnderneath(); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8929 | inline bool IsTwoByteRepresentationUnderneath(); |
| 8930 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 8931 | // NOTE: this should be considered only a hint. False negatives are |
| 8932 | // possible. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8933 | inline bool HasOnlyOneByteChars(); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8934 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8935 | // Get and set individual two byte chars in the string. |
| 8936 | inline void Set(int index, uint16_t value); |
| 8937 | // Get individual two byte char in the string. Repeated calls |
| 8938 | // to this method are not efficient unless the string is flat. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8939 | INLINE(uint16_t Get(int index)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8940 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8941 | // ES6 section 7.1.3.1 ToNumber Applied to the String Type |
| 8942 | static Handle<Object> ToNumber(Handle<String> subject); |
| 8943 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8944 | // Flattens the string. Checks first inline to see if it is |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 8945 | // necessary. Does nothing if the string is not a cons string. |
| 8946 | // Flattening allocates a sequential string with the same data as |
| 8947 | // the given string and mutates the cons string to a degenerate |
| 8948 | // form, where the first component is the new sequential string and |
| 8949 | // the second component is the empty string. If allocation fails, |
| 8950 | // this function returns a failure. If flattening succeeds, this |
| 8951 | // function returns the sequential string that is now the first |
| 8952 | // component of the cons string. |
| 8953 | // |
| 8954 | // Degenerate cons strings are handled specially by the garbage |
| 8955 | // collector (see IsShortcutCandidate). |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8956 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8957 | static inline Handle<String> Flatten(Handle<String> string, |
| 8958 | PretenureFlag pretenure = NOT_TENURED); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 8959 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8960 | // Tries to return the content of a flat string as a structure holding either |
| 8961 | // a flat vector of char or of uc16. |
| 8962 | // If the string isn't flat, and therefore doesn't have flat content, the |
| 8963 | // returned structure will report so, and can't provide a vector of either |
| 8964 | // kind. |
| 8965 | FlatContent GetFlatContent(); |
| 8966 | |
| 8967 | // Returns the parent of a sliced string or first part of a flat cons string. |
| 8968 | // Requires: StringShape(this).IsIndirect() && this->IsFlat() |
| 8969 | inline String* GetUnderlying(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8970 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8971 | // String relational comparison, implemented according to ES6 section 7.2.11 |
| 8972 | // Abstract Relational Comparison (step 5): The comparison of Strings uses a |
| 8973 | // simple lexicographic ordering on sequences of code unit values. There is no |
| 8974 | // attempt to use the more complex, semantically oriented definitions of |
| 8975 | // character or string equality and collating order defined in the Unicode |
| 8976 | // specification. Therefore String values that are canonically equal according |
| 8977 | // to the Unicode standard could test as unequal. In effect this algorithm |
| 8978 | // assumes that both Strings are already in normalized form. Also, note that |
| 8979 | // for strings containing supplementary characters, lexicographic ordering on |
| 8980 | // sequences of UTF-16 code unit values differs from that on sequences of code |
| 8981 | // point values. |
| 8982 | MUST_USE_RESULT static ComparisonResult Compare(Handle<String> x, |
| 8983 | Handle<String> y); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8984 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8985 | // String equality operations. |
| 8986 | inline bool Equals(String* other); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8987 | inline static bool Equals(Handle<String> one, Handle<String> two); |
| 8988 | bool IsUtf8EqualTo(Vector<const char> str, bool allow_prefix_match = false); |
| 8989 | bool IsOneByteEqualTo(Vector<const uint8_t> str); |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 8990 | bool IsTwoByteEqualTo(Vector<const uc16> str); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8991 | |
| 8992 | // Return a UTF8 representation of the string. The string is null |
| 8993 | // terminated but may optionally contain nulls. Length is returned |
| 8994 | // in length_output if length_output is not a null pointer The string |
| 8995 | // should be nearly flat, otherwise the performance of this method may |
| 8996 | // be very slow (quadratic in the length). Setting robustness_flag to |
| 8997 | // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it |
| 8998 | // handles unexpected data without causing assert failures and it does not |
| 8999 | // do any heap allocations. This is useful when printing stack traces. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9000 | base::SmartArrayPointer<char> ToCString(AllowNullsFlag allow_nulls, |
| 9001 | RobustnessFlag robustness_flag, |
| 9002 | int offset, int length, |
| 9003 | int* length_output = 0); |
| 9004 | base::SmartArrayPointer<char> ToCString( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9005 | AllowNullsFlag allow_nulls = DISALLOW_NULLS, |
| 9006 | RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL, |
| 9007 | int* length_output = 0); |
| 9008 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9009 | // Return a 16 bit Unicode representation of the string. |
| 9010 | // The string should be nearly flat, otherwise the performance of |
| 9011 | // of this method may be very bad. Setting robustness_flag to |
| 9012 | // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it |
| 9013 | // handles unexpected data without causing assert failures and it does not |
| 9014 | // do any heap allocations. This is useful when printing stack traces. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9015 | base::SmartArrayPointer<uc16> ToWideCString( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9016 | RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL); |
| 9017 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9018 | bool ComputeArrayIndex(uint32_t* index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9019 | |
| 9020 | // Externalization. |
| 9021 | bool MakeExternal(v8::String::ExternalStringResource* resource); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9022 | bool MakeExternal(v8::String::ExternalOneByteStringResource* resource); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9023 | |
| 9024 | // Conversion. |
| 9025 | inline bool AsArrayIndex(uint32_t* index); |
| 9026 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9027 | DECLARE_CAST(String) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9028 | |
| 9029 | void PrintOn(FILE* out); |
| 9030 | |
| 9031 | // For use during stack traces. Performs rudimentary sanity check. |
| 9032 | bool LooksValid(); |
| 9033 | |
| 9034 | // Dispatched behavior. |
| 9035 | void StringShortPrint(StringStream* accumulator); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 9036 | void PrintUC16(std::ostream& os, int start = 0, int end = -1); // NOLINT |
| 9037 | #if defined(DEBUG) || defined(OBJECT_PRINT) |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 9038 | char* ToAsciiArray(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 9039 | #endif |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9040 | DECLARE_PRINTER(String) |
| 9041 | DECLARE_VERIFIER(String) |
| 9042 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9043 | inline bool IsFlat(); |
| 9044 | |
| 9045 | // Layout description. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9046 | static const int kLengthOffset = Name::kSize; |
| 9047 | static const int kSize = kLengthOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9048 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 9049 | // Maximum number of characters to consider when trying to convert a string |
| 9050 | // value into an array index. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9051 | static const int kMaxArrayIndexSize = 10; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9052 | STATIC_ASSERT(kMaxArrayIndexSize < (1 << kArrayIndexLengthBits)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9053 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9054 | // Max char codes. |
| 9055 | static const int32_t kMaxOneByteCharCode = unibrow::Latin1::kMaxChar; |
| 9056 | static const uint32_t kMaxOneByteCharCodeU = unibrow::Latin1::kMaxChar; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9057 | static const int kMaxUtf16CodeUnit = 0xffff; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9058 | static const uint32_t kMaxUtf16CodeUnitU = kMaxUtf16CodeUnit; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 9059 | static const uc32 kMaxCodePoint = 0x10ffff; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 9060 | |
| 9061 | // Maximal string length. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9062 | static const int kMaxLength = (1 << 28) - 16; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 9063 | |
| 9064 | // Max length for computing hash. For strings longer than this limit the |
| 9065 | // string length is used as the hash value. |
| 9066 | static const int kMaxHashCalcLength = 16383; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9067 | |
| 9068 | // Limit for truncation in short printing. |
| 9069 | static const int kMaxShortPrintLength = 1024; |
| 9070 | |
| 9071 | // Support for regular expressions. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9072 | const uc16* GetTwoByteData(unsigned start); |
| 9073 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9074 | // Helper function for flattening strings. |
| 9075 | template <typename sinkchar> |
| 9076 | static void WriteToFlat(String* source, |
| 9077 | sinkchar* sink, |
| 9078 | int from, |
| 9079 | int to); |
| 9080 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9081 | // The return value may point to the first aligned word containing the first |
| 9082 | // non-one-byte character, rather than directly to the non-one-byte character. |
| 9083 | // If the return value is >= the passed length, the entire string was |
| 9084 | // one-byte. |
| 9085 | static inline int NonAsciiStart(const char* chars, int length) { |
| 9086 | const char* start = chars; |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 9087 | const char* limit = chars + length; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9088 | |
| 9089 | if (length >= kIntptrSize) { |
| 9090 | // Check unaligned bytes. |
| 9091 | while (!IsAligned(reinterpret_cast<intptr_t>(chars), sizeof(uintptr_t))) { |
| 9092 | if (static_cast<uint8_t>(*chars) > unibrow::Utf8::kMaxOneByteChar) { |
| 9093 | return static_cast<int>(chars - start); |
| 9094 | } |
| 9095 | ++chars; |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 9096 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9097 | // Check aligned words. |
| 9098 | DCHECK(unibrow::Utf8::kMaxOneByteChar == 0x7F); |
| 9099 | const uintptr_t non_one_byte_mask = kUintptrAllBitsSet / 0xFF * 0x80; |
| 9100 | while (chars + sizeof(uintptr_t) <= limit) { |
| 9101 | if (*reinterpret_cast<const uintptr_t*>(chars) & non_one_byte_mask) { |
| 9102 | return static_cast<int>(chars - start); |
| 9103 | } |
| 9104 | chars += sizeof(uintptr_t); |
| 9105 | } |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 9106 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9107 | // Check remaining unaligned bytes. |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 9108 | while (chars < limit) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9109 | if (static_cast<uint8_t>(*chars) > unibrow::Utf8::kMaxOneByteChar) { |
| 9110 | return static_cast<int>(chars - start); |
| 9111 | } |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 9112 | ++chars; |
| 9113 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9114 | |
| 9115 | return static_cast<int>(chars - start); |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 9116 | } |
| 9117 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9118 | static inline bool IsAscii(const char* chars, int length) { |
| 9119 | return NonAsciiStart(chars, length) >= length; |
| 9120 | } |
| 9121 | |
| 9122 | static inline bool IsAscii(const uint8_t* chars, int length) { |
| 9123 | return |
| 9124 | NonAsciiStart(reinterpret_cast<const char*>(chars), length) >= length; |
| 9125 | } |
| 9126 | |
| 9127 | static inline int NonOneByteStart(const uc16* chars, int length) { |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 9128 | const uc16* limit = chars + length; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9129 | const uc16* start = chars; |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 9130 | while (chars < limit) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9131 | if (*chars > kMaxOneByteCharCodeU) return static_cast<int>(chars - start); |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 9132 | ++chars; |
| 9133 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9134 | return static_cast<int>(chars - start); |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 9135 | } |
| 9136 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9137 | static inline bool IsOneByte(const uc16* chars, int length) { |
| 9138 | return NonOneByteStart(chars, length) >= length; |
| 9139 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9140 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9141 | template<class Visitor> |
| 9142 | static inline ConsString* VisitFlat(Visitor* visitor, |
| 9143 | String* string, |
| 9144 | int offset = 0); |
| 9145 | |
| 9146 | static Handle<FixedArray> CalculateLineEnds(Handle<String> string, |
| 9147 | bool include_ending_line); |
| 9148 | |
| 9149 | // Use the hash field to forward to the canonical internalized string |
| 9150 | // when deserializing an internalized string. |
| 9151 | inline void SetForwardedInternalizedString(String* string); |
| 9152 | inline String* GetForwardedInternalizedString(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9153 | |
| 9154 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9155 | friend class Name; |
| 9156 | friend class StringTableInsertionKey; |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 9157 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9158 | static Handle<String> SlowFlatten(Handle<ConsString> cons, |
| 9159 | PretenureFlag tenure); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 9160 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9161 | // Slow case of String::Equals. This implementation works on any strings |
| 9162 | // but it is most efficient on strings that are almost flat. |
| 9163 | bool SlowEquals(String* other); |
| 9164 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9165 | static bool SlowEquals(Handle<String> one, Handle<String> two); |
| 9166 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9167 | // Slow case of AsArrayIndex. |
| 9168 | bool SlowAsArrayIndex(uint32_t* index); |
| 9169 | |
| 9170 | // Compute and set the hash code. |
| 9171 | uint32_t ComputeAndSetHash(); |
| 9172 | |
| 9173 | DISALLOW_IMPLICIT_CONSTRUCTORS(String); |
| 9174 | }; |
| 9175 | |
| 9176 | |
| 9177 | // The SeqString abstract class captures sequential string values. |
| 9178 | class SeqString: public String { |
| 9179 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9180 | DECLARE_CAST(SeqString) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9181 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9182 | // Layout description. |
| 9183 | static const int kHeaderSize = String::kSize; |
| 9184 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9185 | // Truncate the string in-place if possible and return the result. |
| 9186 | // In case of new_length == 0, the empty string is returned without |
| 9187 | // truncating the original string. |
| 9188 | MUST_USE_RESULT static Handle<String> Truncate(Handle<SeqString> string, |
| 9189 | int new_length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9190 | private: |
| 9191 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqString); |
| 9192 | }; |
| 9193 | |
| 9194 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9195 | // The OneByteString class captures sequential one-byte string objects. |
| 9196 | // Each character in the OneByteString is an one-byte character. |
| 9197 | class SeqOneByteString: public SeqString { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9198 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9199 | static const bool kHasOneByteEncoding = true; |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 9200 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9201 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9202 | inline uint16_t SeqOneByteStringGet(int index); |
| 9203 | inline void SeqOneByteStringSet(int index, uint16_t value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9204 | |
| 9205 | // Get the address of the characters in this string. |
| 9206 | inline Address GetCharsAddress(); |
| 9207 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9208 | inline uint8_t* GetChars(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9209 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9210 | DECLARE_CAST(SeqOneByteString) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9211 | |
| 9212 | // Garbage collection support. This method is called by the |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9213 | // garbage collector to compute the actual size of an OneByteString |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9214 | // instance. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9215 | inline int SeqOneByteStringSize(InstanceType instance_type); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9216 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9217 | // Computes the size for an OneByteString instance of a given length. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9218 | static int SizeFor(int length) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 9219 | return OBJECT_POINTER_ALIGN(kHeaderSize + length * kCharSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9220 | } |
| 9221 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9222 | // Maximal memory usage for a single sequential one-byte string. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9223 | static const int kMaxSize = 512 * MB - 1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9224 | STATIC_ASSERT((kMaxSize - kHeaderSize) >= String::kMaxLength); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9225 | |
| 9226 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9227 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqOneByteString); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9228 | }; |
| 9229 | |
| 9230 | |
| 9231 | // The TwoByteString class captures sequential unicode string objects. |
| 9232 | // Each character in the TwoByteString is a two-byte uint16_t. |
| 9233 | class SeqTwoByteString: public SeqString { |
| 9234 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9235 | static const bool kHasOneByteEncoding = false; |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 9236 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9237 | // Dispatched behavior. |
| 9238 | inline uint16_t SeqTwoByteStringGet(int index); |
| 9239 | inline void SeqTwoByteStringSet(int index, uint16_t value); |
| 9240 | |
| 9241 | // Get the address of the characters in this string. |
| 9242 | inline Address GetCharsAddress(); |
| 9243 | |
| 9244 | inline uc16* GetChars(); |
| 9245 | |
| 9246 | // For regexp code. |
| 9247 | const uint16_t* SeqTwoByteStringGetData(unsigned start); |
| 9248 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9249 | DECLARE_CAST(SeqTwoByteString) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9250 | |
| 9251 | // Garbage collection support. This method is called by the |
| 9252 | // garbage collector to compute the actual size of a TwoByteString |
| 9253 | // instance. |
| 9254 | inline int SeqTwoByteStringSize(InstanceType instance_type); |
| 9255 | |
| 9256 | // Computes the size for a TwoByteString instance of a given length. |
| 9257 | static int SizeFor(int length) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 9258 | return OBJECT_POINTER_ALIGN(kHeaderSize + length * kShortSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9259 | } |
| 9260 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 9261 | // Maximal memory usage for a single sequential two-byte string. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9262 | static const int kMaxSize = 512 * MB - 1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9263 | STATIC_ASSERT(static_cast<int>((kMaxSize - kHeaderSize)/sizeof(uint16_t)) >= |
| 9264 | String::kMaxLength); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9265 | |
| 9266 | private: |
| 9267 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqTwoByteString); |
| 9268 | }; |
| 9269 | |
| 9270 | |
| 9271 | // The ConsString class describes string values built by using the |
| 9272 | // addition operator on strings. A ConsString is a pair where the |
| 9273 | // first and second components are pointers to other string values. |
| 9274 | // One or both components of a ConsString can be pointers to other |
| 9275 | // ConsStrings, creating a binary tree of ConsStrings where the leaves |
| 9276 | // are non-ConsString string values. The string value represented by |
| 9277 | // a ConsString can be obtained by concatenating the leaf string |
| 9278 | // values in a left-to-right depth-first traversal of the tree. |
| 9279 | class ConsString: public String { |
| 9280 | public: |
| 9281 | // First string of the cons cell. |
| 9282 | inline String* first(); |
| 9283 | // Doesn't check that the result is a string, even in debug mode. This is |
| 9284 | // useful during GC where the mark bits confuse the checks. |
| 9285 | inline Object* unchecked_first(); |
| 9286 | inline void set_first(String* first, |
| 9287 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| 9288 | |
| 9289 | // Second string of the cons cell. |
| 9290 | inline String* second(); |
| 9291 | // Doesn't check that the result is a string, even in debug mode. This is |
| 9292 | // useful during GC where the mark bits confuse the checks. |
| 9293 | inline Object* unchecked_second(); |
| 9294 | inline void set_second(String* second, |
| 9295 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| 9296 | |
| 9297 | // Dispatched behavior. |
| 9298 | uint16_t ConsStringGet(int index); |
| 9299 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9300 | DECLARE_CAST(ConsString) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9301 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9302 | // Layout description. |
| 9303 | static const int kFirstOffset = POINTER_SIZE_ALIGN(String::kSize); |
| 9304 | static const int kSecondOffset = kFirstOffset + kPointerSize; |
| 9305 | static const int kSize = kSecondOffset + kPointerSize; |
| 9306 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9307 | // Minimum length for a cons string. |
| 9308 | static const int kMinLength = 13; |
| 9309 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 9310 | typedef FixedBodyDescriptor<kFirstOffset, kSecondOffset + kPointerSize, kSize> |
| 9311 | BodyDescriptor; |
| 9312 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9313 | DECLARE_VERIFIER(ConsString) |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 9314 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9315 | private: |
| 9316 | DISALLOW_IMPLICIT_CONSTRUCTORS(ConsString); |
| 9317 | }; |
| 9318 | |
| 9319 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 9320 | // The Sliced String class describes strings that are substrings of another |
| 9321 | // sequential string. The motivation is to save time and memory when creating |
| 9322 | // a substring. A Sliced String is described as a pointer to the parent, |
| 9323 | // the offset from the start of the parent string and the length. Using |
| 9324 | // a Sliced String therefore requires unpacking of the parent string and |
| 9325 | // adding the offset to the start address. A substring of a Sliced String |
| 9326 | // are not nested since the double indirection is simplified when creating |
| 9327 | // such a substring. |
| 9328 | // Currently missing features are: |
| 9329 | // - handling externalized parent strings |
| 9330 | // - external strings as parent |
| 9331 | // - truncating sliced string to enable otherwise unneeded parent to be GC'ed. |
| 9332 | class SlicedString: public String { |
| 9333 | public: |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 9334 | inline String* parent(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9335 | inline void set_parent(String* parent, |
| 9336 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| 9337 | inline int offset() const; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 9338 | inline void set_offset(int offset); |
| 9339 | |
| 9340 | // Dispatched behavior. |
| 9341 | uint16_t SlicedStringGet(int index); |
| 9342 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9343 | DECLARE_CAST(SlicedString) |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 9344 | |
| 9345 | // Layout description. |
| 9346 | static const int kParentOffset = POINTER_SIZE_ALIGN(String::kSize); |
| 9347 | static const int kOffsetOffset = kParentOffset + kPointerSize; |
| 9348 | static const int kSize = kOffsetOffset + kPointerSize; |
| 9349 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 9350 | // Minimum length for a sliced string. |
| 9351 | static const int kMinLength = 13; |
| 9352 | |
| 9353 | typedef FixedBodyDescriptor<kParentOffset, |
| 9354 | kOffsetOffset + kPointerSize, kSize> |
| 9355 | BodyDescriptor; |
| 9356 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9357 | DECLARE_VERIFIER(SlicedString) |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 9358 | |
| 9359 | private: |
| 9360 | DISALLOW_IMPLICIT_CONSTRUCTORS(SlicedString); |
| 9361 | }; |
| 9362 | |
| 9363 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9364 | // The ExternalString class describes string values that are backed by |
| 9365 | // a string resource that lies outside the V8 heap. ExternalStrings |
| 9366 | // consist of the length field common to all strings, a pointer to the |
| 9367 | // external resource. It is important to ensure (externally) that the |
| 9368 | // resource is not deallocated while the ExternalString is live in the |
| 9369 | // V8 heap. |
| 9370 | // |
| 9371 | // The API expects that all ExternalStrings are created through the |
| 9372 | // API. Therefore, ExternalStrings should not be used internally. |
| 9373 | class ExternalString: public String { |
| 9374 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9375 | DECLARE_CAST(ExternalString) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9376 | |
| 9377 | // Layout description. |
| 9378 | static const int kResourceOffset = POINTER_SIZE_ALIGN(String::kSize); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9379 | static const int kShortSize = kResourceOffset + kPointerSize; |
| 9380 | static const int kResourceDataOffset = kResourceOffset + kPointerSize; |
| 9381 | static const int kSize = kResourceDataOffset + kPointerSize; |
| 9382 | |
| 9383 | // Return whether external string is short (data pointer is not cached). |
| 9384 | inline bool is_short(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9385 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9386 | STATIC_ASSERT(kResourceOffset == Internals::kStringResourceOffset); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9387 | |
| 9388 | private: |
| 9389 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalString); |
| 9390 | }; |
| 9391 | |
| 9392 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9393 | // The ExternalOneByteString class is an external string backed by an |
| 9394 | // one-byte string. |
| 9395 | class ExternalOneByteString : public ExternalString { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9396 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9397 | static const bool kHasOneByteEncoding = true; |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 9398 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9399 | typedef v8::String::ExternalOneByteStringResource Resource; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9400 | |
| 9401 | // The underlying resource. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9402 | inline const Resource* resource(); |
| 9403 | inline void set_resource(const Resource* buffer); |
| 9404 | |
| 9405 | // Update the pointer cache to the external character array. |
| 9406 | // The cached pointer is always valid, as the external character array does = |
| 9407 | // not move during lifetime. Deserialization is the only exception, after |
| 9408 | // which the pointer cache has to be refreshed. |
| 9409 | inline void update_data_cache(); |
| 9410 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9411 | inline const uint8_t* GetChars(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9412 | |
| 9413 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9414 | inline uint16_t ExternalOneByteStringGet(int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9415 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9416 | DECLARE_CAST(ExternalOneByteString) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9417 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9418 | class BodyDescriptor; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9419 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9420 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9421 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalOneByteString); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9422 | }; |
| 9423 | |
| 9424 | |
| 9425 | // The ExternalTwoByteString class is an external string backed by a UTF-16 |
| 9426 | // encoded string. |
| 9427 | class ExternalTwoByteString: public ExternalString { |
| 9428 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9429 | static const bool kHasOneByteEncoding = false; |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 9430 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9431 | typedef v8::String::ExternalStringResource Resource; |
| 9432 | |
| 9433 | // The underlying string resource. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9434 | inline const Resource* resource(); |
| 9435 | inline void set_resource(const Resource* buffer); |
| 9436 | |
| 9437 | // Update the pointer cache to the external character array. |
| 9438 | // The cached pointer is always valid, as the external character array does = |
| 9439 | // not move during lifetime. Deserialization is the only exception, after |
| 9440 | // which the pointer cache has to be refreshed. |
| 9441 | inline void update_data_cache(); |
| 9442 | |
| 9443 | inline const uint16_t* GetChars(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9444 | |
| 9445 | // Dispatched behavior. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9446 | inline uint16_t ExternalTwoByteStringGet(int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9447 | |
| 9448 | // For regexp code. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9449 | inline const uint16_t* ExternalTwoByteStringGetData(unsigned start); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9450 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9451 | DECLARE_CAST(ExternalTwoByteString) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9452 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9453 | class BodyDescriptor; |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 9454 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9455 | private: |
| 9456 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalTwoByteString); |
| 9457 | }; |
| 9458 | |
| 9459 | |
| 9460 | // Utility superclass for stack-allocated objects that must be updated |
| 9461 | // on gc. It provides two ways for the gc to update instances, either |
| 9462 | // iterating or updating after gc. |
| 9463 | class Relocatable BASE_EMBEDDED { |
| 9464 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 9465 | explicit inline Relocatable(Isolate* isolate); |
| 9466 | inline virtual ~Relocatable(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9467 | virtual void IterateInstance(ObjectVisitor* v) { } |
| 9468 | virtual void PostGarbageCollection() { } |
| 9469 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9470 | static void PostGarbageCollectionProcessing(Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9471 | static int ArchiveSpacePerThread(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 9472 | static char* ArchiveState(Isolate* isolate, char* to); |
| 9473 | static char* RestoreState(Isolate* isolate, char* from); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9474 | static void Iterate(Isolate* isolate, ObjectVisitor* v); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9475 | static void Iterate(ObjectVisitor* v, Relocatable* top); |
| 9476 | static char* Iterate(ObjectVisitor* v, char* t); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9477 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9478 | private: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 9479 | Isolate* isolate_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9480 | Relocatable* prev_; |
| 9481 | }; |
| 9482 | |
| 9483 | |
| 9484 | // A flat string reader provides random access to the contents of a |
| 9485 | // string independent of the character width of the string. The handle |
| 9486 | // must be valid as long as the reader is being used. |
| 9487 | class FlatStringReader : public Relocatable { |
| 9488 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 9489 | FlatStringReader(Isolate* isolate, Handle<String> str); |
| 9490 | FlatStringReader(Isolate* isolate, Vector<const char> input); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9491 | void PostGarbageCollection(); |
| 9492 | inline uc32 Get(int index); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 9493 | template <typename Char> |
| 9494 | inline Char Get(int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9495 | int length() { return length_; } |
| 9496 | private: |
| 9497 | String** str_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9498 | bool is_one_byte_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9499 | int length_; |
| 9500 | const void* start_; |
| 9501 | }; |
| 9502 | |
| 9503 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9504 | // This maintains an off-stack representation of the stack frames required |
| 9505 | // to traverse a ConsString, allowing an entirely iterative and restartable |
| 9506 | // traversal of the entire string |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 9507 | class ConsStringIterator { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9508 | public: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 9509 | inline ConsStringIterator() {} |
| 9510 | inline explicit ConsStringIterator(ConsString* cons_string, int offset = 0) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9511 | Reset(cons_string, offset); |
| 9512 | } |
| 9513 | inline void Reset(ConsString* cons_string, int offset = 0) { |
| 9514 | depth_ = 0; |
| 9515 | // Next will always return NULL. |
| 9516 | if (cons_string == NULL) return; |
| 9517 | Initialize(cons_string, offset); |
| 9518 | } |
| 9519 | // Returns NULL when complete. |
| 9520 | inline String* Next(int* offset_out) { |
| 9521 | *offset_out = 0; |
| 9522 | if (depth_ == 0) return NULL; |
| 9523 | return Continue(offset_out); |
| 9524 | } |
| 9525 | |
| 9526 | private: |
| 9527 | static const int kStackSize = 32; |
| 9528 | // Use a mask instead of doing modulo operations for stack wrapping. |
| 9529 | static const int kDepthMask = kStackSize-1; |
| 9530 | STATIC_ASSERT(IS_POWER_OF_TWO(kStackSize)); |
| 9531 | static inline int OffsetForDepth(int depth); |
| 9532 | |
| 9533 | inline void PushLeft(ConsString* string); |
| 9534 | inline void PushRight(ConsString* string); |
| 9535 | inline void AdjustMaximumDepth(); |
| 9536 | inline void Pop(); |
| 9537 | inline bool StackBlown() { return maximum_depth_ - depth_ == kStackSize; } |
| 9538 | void Initialize(ConsString* cons_string, int offset); |
| 9539 | String* Continue(int* offset_out); |
| 9540 | String* NextLeaf(bool* blew_stack); |
| 9541 | String* Search(int* offset_out); |
| 9542 | |
| 9543 | // Stack must always contain only frames for which right traversal |
| 9544 | // has not yet been performed. |
| 9545 | ConsString* frames_[kStackSize]; |
| 9546 | ConsString* root_; |
| 9547 | int depth_; |
| 9548 | int maximum_depth_; |
| 9549 | int consumed_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 9550 | DISALLOW_COPY_AND_ASSIGN(ConsStringIterator); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9551 | }; |
| 9552 | |
| 9553 | |
| 9554 | class StringCharacterStream { |
| 9555 | public: |
| 9556 | inline StringCharacterStream(String* string, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9557 | int offset = 0); |
| 9558 | inline uint16_t GetNext(); |
| 9559 | inline bool HasMore(); |
| 9560 | inline void Reset(String* string, int offset = 0); |
| 9561 | inline void VisitOneByteString(const uint8_t* chars, int length); |
| 9562 | inline void VisitTwoByteString(const uint16_t* chars, int length); |
| 9563 | |
| 9564 | private: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 9565 | ConsStringIterator iter_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9566 | bool is_one_byte_; |
| 9567 | union { |
| 9568 | const uint8_t* buffer8_; |
| 9569 | const uint16_t* buffer16_; |
| 9570 | }; |
| 9571 | const uint8_t* end_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9572 | DISALLOW_COPY_AND_ASSIGN(StringCharacterStream); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9573 | }; |
| 9574 | |
| 9575 | |
| 9576 | template <typename T> |
| 9577 | class VectorIterator { |
| 9578 | public: |
| 9579 | VectorIterator(T* d, int l) : data_(Vector<const T>(d, l)), index_(0) { } |
| 9580 | explicit VectorIterator(Vector<const T> data) : data_(data), index_(0) { } |
| 9581 | T GetNext() { return data_[index_++]; } |
| 9582 | bool has_more() { return index_ < data_.length(); } |
| 9583 | private: |
| 9584 | Vector<const T> data_; |
| 9585 | int index_; |
| 9586 | }; |
| 9587 | |
| 9588 | |
| 9589 | // The Oddball describes objects null, undefined, true, and false. |
| 9590 | class Oddball: public HeapObject { |
| 9591 | public: |
| 9592 | // [to_string]: Cached to_string computed at startup. |
| 9593 | DECL_ACCESSORS(to_string, String) |
| 9594 | |
| 9595 | // [to_number]: Cached to_number computed at startup. |
| 9596 | DECL_ACCESSORS(to_number, Object) |
| 9597 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 9598 | // [to_number]: Cached to_boolean computed at startup. |
| 9599 | DECL_ACCESSORS(to_boolean, Oddball) |
| 9600 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9601 | // [typeof]: Cached type_of computed at startup. |
| 9602 | DECL_ACCESSORS(type_of, String) |
| 9603 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9604 | inline byte kind() const; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 9605 | inline void set_kind(byte kind); |
| 9606 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9607 | // ES6 section 7.1.3 ToNumber for Boolean, Null, Undefined. |
| 9608 | MUST_USE_RESULT static inline Handle<Object> ToNumber(Handle<Oddball> input); |
| 9609 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9610 | DECLARE_CAST(Oddball) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9611 | |
| 9612 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9613 | DECLARE_VERIFIER(Oddball) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9614 | |
| 9615 | // Initialize the fields. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9616 | static void Initialize(Isolate* isolate, Handle<Oddball> oddball, |
| 9617 | const char* to_string, Handle<Object> to_number, |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 9618 | bool to_boolean, const char* type_of, byte kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9619 | |
| 9620 | // Layout description. |
| 9621 | static const int kToStringOffset = HeapObject::kHeaderSize; |
| 9622 | static const int kToNumberOffset = kToStringOffset + kPointerSize; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 9623 | static const int kToBooleanOffset = kToNumberOffset + kPointerSize; |
| 9624 | static const int kTypeOfOffset = kToBooleanOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9625 | static const int kKindOffset = kTypeOfOffset + kPointerSize; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 9626 | static const int kSize = kKindOffset + kPointerSize; |
| 9627 | |
| 9628 | static const byte kFalse = 0; |
| 9629 | static const byte kTrue = 1; |
| 9630 | static const byte kNotBooleanMask = ~1; |
| 9631 | static const byte kTheHole = 2; |
| 9632 | static const byte kNull = 3; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 9633 | static const byte kArgumentsMarker = 4; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 9634 | static const byte kUndefined = 5; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9635 | static const byte kUninitialized = 6; |
| 9636 | static const byte kOther = 7; |
| 9637 | static const byte kException = 8; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 9638 | static const byte kOptimizedOut = 9; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9639 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9640 | typedef FixedBodyDescriptor<kToStringOffset, kTypeOfOffset + kPointerSize, |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 9641 | kSize> BodyDescriptor; |
| 9642 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9643 | STATIC_ASSERT(kKindOffset == Internals::kOddballKindOffset); |
| 9644 | STATIC_ASSERT(kNull == Internals::kNullOddballKind); |
| 9645 | STATIC_ASSERT(kUndefined == Internals::kUndefinedOddballKind); |
| 9646 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9647 | private: |
| 9648 | DISALLOW_IMPLICIT_CONSTRUCTORS(Oddball); |
| 9649 | }; |
| 9650 | |
| 9651 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9652 | class Cell: public HeapObject { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9653 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9654 | // [value]: value of the cell. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9655 | DECL_ACCESSORS(value, Object) |
| 9656 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9657 | DECLARE_CAST(Cell) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9658 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9659 | static inline Cell* FromValueAddress(Address value) { |
| 9660 | Object* result = FromAddress(value - kValueOffset); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9661 | return static_cast<Cell*>(result); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 9662 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9663 | |
| 9664 | inline Address ValueAddress() { |
| 9665 | return address() + kValueOffset; |
| 9666 | } |
| 9667 | |
| 9668 | // Dispatched behavior. |
| 9669 | DECLARE_PRINTER(Cell) |
| 9670 | DECLARE_VERIFIER(Cell) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9671 | |
| 9672 | // Layout description. |
| 9673 | static const int kValueOffset = HeapObject::kHeaderSize; |
| 9674 | static const int kSize = kValueOffset + kPointerSize; |
| 9675 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 9676 | typedef FixedBodyDescriptor<kValueOffset, |
| 9677 | kValueOffset + kPointerSize, |
| 9678 | kSize> BodyDescriptor; |
| 9679 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9680 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9681 | DISALLOW_IMPLICIT_CONSTRUCTORS(Cell); |
| 9682 | }; |
| 9683 | |
| 9684 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9685 | class PropertyCell : public HeapObject { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9686 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9687 | // [property_details]: details of the global property. |
| 9688 | DECL_ACCESSORS(property_details_raw, Object) |
| 9689 | // [value]: value of the global property. |
| 9690 | DECL_ACCESSORS(value, Object) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9691 | // [dependent_code]: dependent code that depends on the type of the global |
| 9692 | // property. |
| 9693 | DECL_ACCESSORS(dependent_code, DependentCode) |
| 9694 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9695 | inline PropertyDetails property_details(); |
| 9696 | inline void set_property_details(PropertyDetails details); |
| 9697 | |
| 9698 | PropertyCellConstantType GetConstantType(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9699 | |
| 9700 | // 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] | 9701 | // without actually modifying the details. |
| 9702 | static PropertyCellType UpdatedType(Handle<PropertyCell> cell, |
| 9703 | Handle<Object> value, |
| 9704 | PropertyDetails details); |
| 9705 | static void UpdateCell(Handle<GlobalDictionary> dictionary, int entry, |
| 9706 | Handle<Object> value, PropertyDetails details); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9707 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9708 | static Handle<PropertyCell> InvalidateEntry( |
| 9709 | Handle<GlobalDictionary> dictionary, int entry); |
| 9710 | |
| 9711 | static void SetValueWithInvalidation(Handle<PropertyCell> cell, |
| 9712 | Handle<Object> new_value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9713 | |
| 9714 | DECLARE_CAST(PropertyCell) |
| 9715 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9716 | // Dispatched behavior. |
| 9717 | DECLARE_PRINTER(PropertyCell) |
| 9718 | DECLARE_VERIFIER(PropertyCell) |
| 9719 | |
| 9720 | // Layout description. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9721 | static const int kDetailsOffset = HeapObject::kHeaderSize; |
| 9722 | static const int kValueOffset = kDetailsOffset + kPointerSize; |
| 9723 | static const int kDependentCodeOffset = kValueOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9724 | static const int kSize = kDependentCodeOffset + kPointerSize; |
| 9725 | |
| 9726 | static const int kPointerFieldsBeginOffset = kValueOffset; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9727 | static const int kPointerFieldsEndOffset = kSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9728 | |
| 9729 | typedef FixedBodyDescriptor<kValueOffset, |
| 9730 | kSize, |
| 9731 | kSize> BodyDescriptor; |
| 9732 | |
| 9733 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9734 | DISALLOW_IMPLICIT_CONSTRUCTORS(PropertyCell); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9735 | }; |
| 9736 | |
| 9737 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 9738 | class WeakCell : public HeapObject { |
| 9739 | public: |
| 9740 | inline Object* value() const; |
| 9741 | |
| 9742 | // This should not be called by anyone except GC. |
| 9743 | inline void clear(); |
| 9744 | |
| 9745 | // This should not be called by anyone except allocator. |
| 9746 | inline void initialize(HeapObject* value); |
| 9747 | |
| 9748 | inline bool cleared() const; |
| 9749 | |
| 9750 | DECL_ACCESSORS(next, Object) |
| 9751 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9752 | inline void clear_next(Object* the_hole_value); |
| 9753 | |
| 9754 | inline bool next_cleared(); |
| 9755 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 9756 | DECLARE_CAST(WeakCell) |
| 9757 | |
| 9758 | DECLARE_PRINTER(WeakCell) |
| 9759 | DECLARE_VERIFIER(WeakCell) |
| 9760 | |
| 9761 | // Layout description. |
| 9762 | static const int kValueOffset = HeapObject::kHeaderSize; |
| 9763 | static const int kNextOffset = kValueOffset + kPointerSize; |
| 9764 | static const int kSize = kNextOffset + kPointerSize; |
| 9765 | |
| 9766 | typedef FixedBodyDescriptor<kValueOffset, kSize, kSize> BodyDescriptor; |
| 9767 | |
| 9768 | private: |
| 9769 | DISALLOW_IMPLICIT_CONSTRUCTORS(WeakCell); |
| 9770 | }; |
| 9771 | |
| 9772 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 9773 | // The JSProxy describes EcmaScript Harmony proxies |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 9774 | class JSProxy: public JSReceiver { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9775 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9776 | MUST_USE_RESULT static MaybeHandle<JSProxy> New(Isolate* isolate, |
| 9777 | Handle<Object>, |
| 9778 | Handle<Object>); |
| 9779 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 9780 | // [handler]: The handler property. |
| 9781 | DECL_ACCESSORS(handler, Object) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9782 | // [target]: The target property. |
| 9783 | DECL_ACCESSORS(target, JSReceiver) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9784 | // [hash]: The hash code property (undefined if not initialized yet). |
| 9785 | DECL_ACCESSORS(hash, Object) |
| 9786 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9787 | static MaybeHandle<Context> GetFunctionRealm(Handle<JSProxy> proxy); |
| 9788 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9789 | DECLARE_CAST(JSProxy) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9790 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9791 | INLINE(bool IsRevoked() const); |
| 9792 | static void Revoke(Handle<JSProxy> proxy); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 9793 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9794 | // ES6 9.5.1 |
| 9795 | static MaybeHandle<Object> GetPrototype(Handle<JSProxy> receiver); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9796 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9797 | // ES6 9.5.2 |
| 9798 | MUST_USE_RESULT static Maybe<bool> SetPrototype(Handle<JSProxy> proxy, |
| 9799 | Handle<Object> value, |
| 9800 | bool from_javascript, |
| 9801 | ShouldThrow should_throw); |
| 9802 | // ES6 9.5.3 |
| 9803 | MUST_USE_RESULT static Maybe<bool> IsExtensible(Handle<JSProxy> proxy); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 9804 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9805 | // ES6 9.5.4 (when passed DONT_THROW) |
| 9806 | MUST_USE_RESULT static Maybe<bool> PreventExtensions( |
| 9807 | Handle<JSProxy> proxy, ShouldThrow should_throw); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 9808 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9809 | // ES6 9.5.5 |
| 9810 | MUST_USE_RESULT static Maybe<bool> GetOwnPropertyDescriptor( |
| 9811 | Isolate* isolate, Handle<JSProxy> proxy, Handle<Name> name, |
| 9812 | PropertyDescriptor* desc); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 9813 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9814 | // ES6 9.5.6 |
| 9815 | MUST_USE_RESULT static Maybe<bool> DefineOwnProperty( |
| 9816 | Isolate* isolate, Handle<JSProxy> object, Handle<Object> key, |
| 9817 | PropertyDescriptor* desc, ShouldThrow should_throw); |
| 9818 | |
| 9819 | // ES6 9.5.7 |
| 9820 | MUST_USE_RESULT static Maybe<bool> HasProperty(Isolate* isolate, |
| 9821 | Handle<JSProxy> proxy, |
| 9822 | Handle<Name> name); |
| 9823 | |
| 9824 | // ES6 9.5.8 |
| 9825 | MUST_USE_RESULT static MaybeHandle<Object> GetProperty( |
| 9826 | Isolate* isolate, Handle<JSProxy> proxy, Handle<Name> name, |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 9827 | Handle<Object> receiver, bool* was_found); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9828 | |
| 9829 | // ES6 9.5.9 |
| 9830 | MUST_USE_RESULT static Maybe<bool> SetProperty(Handle<JSProxy> proxy, |
| 9831 | Handle<Name> name, |
| 9832 | Handle<Object> value, |
| 9833 | Handle<Object> receiver, |
| 9834 | LanguageMode language_mode); |
| 9835 | |
| 9836 | // ES6 9.5.10 (when passed SLOPPY) |
| 9837 | MUST_USE_RESULT static Maybe<bool> DeletePropertyOrElement( |
| 9838 | Handle<JSProxy> proxy, Handle<Name> name, LanguageMode language_mode); |
| 9839 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9840 | // ES6 9.5.12 |
| 9841 | MUST_USE_RESULT static Maybe<bool> OwnPropertyKeys( |
| 9842 | Isolate* isolate, Handle<JSReceiver> receiver, Handle<JSProxy> proxy, |
| 9843 | PropertyFilter filter, KeyAccumulator* accumulator); |
| 9844 | |
| 9845 | MUST_USE_RESULT static Maybe<PropertyAttributes> GetPropertyAttributes( |
| 9846 | LookupIterator* it); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9847 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9848 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9849 | DECLARE_PRINTER(JSProxy) |
| 9850 | DECLARE_VERIFIER(JSProxy) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 9851 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9852 | // Layout description. |
| 9853 | static const int kTargetOffset = JSReceiver::kHeaderSize; |
| 9854 | static const int kHandlerOffset = kTargetOffset + kPointerSize; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9855 | static const int kHashOffset = kHandlerOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9856 | static const int kSize = kHashOffset + kPointerSize; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 9857 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9858 | typedef FixedBodyDescriptor<JSReceiver::kPropertiesOffset, kSize, kSize> |
| 9859 | BodyDescriptor; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9860 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 9861 | static Handle<Object> GetIdentityHash(Isolate* isolate, |
| 9862 | Handle<JSProxy> receiver); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9863 | |
| 9864 | static Handle<Smi> GetOrCreateIdentityHash(Handle<JSProxy> proxy); |
| 9865 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 9866 | static Maybe<bool> SetPrivateProperty(Isolate* isolate, Handle<JSProxy> proxy, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9867 | Handle<Symbol> private_name, |
| 9868 | PropertyDescriptor* desc, |
| 9869 | ShouldThrow should_throw); |
| 9870 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 9871 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9872 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSProxy); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 9873 | }; |
| 9874 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 9875 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9876 | class JSCollection : public JSObject { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9877 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9878 | // [table]: the backing hash table |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9879 | DECL_ACCESSORS(table, Object) |
| 9880 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9881 | static const int kTableOffset = JSObject::kHeaderSize; |
| 9882 | static const int kSize = kTableOffset + kPointerSize; |
| 9883 | |
| 9884 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9885 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSCollection); |
| 9886 | }; |
| 9887 | |
| 9888 | |
| 9889 | // The JSSet describes EcmaScript Harmony sets |
| 9890 | class JSSet : public JSCollection { |
| 9891 | public: |
| 9892 | DECLARE_CAST(JSSet) |
| 9893 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9894 | static void Initialize(Handle<JSSet> set, Isolate* isolate); |
| 9895 | static void Clear(Handle<JSSet> set); |
| 9896 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9897 | // Dispatched behavior. |
| 9898 | DECLARE_PRINTER(JSSet) |
| 9899 | DECLARE_VERIFIER(JSSet) |
| 9900 | |
| 9901 | private: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9902 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSSet); |
| 9903 | }; |
| 9904 | |
| 9905 | |
| 9906 | // The JSMap describes EcmaScript Harmony maps |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9907 | class JSMap : public JSCollection { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9908 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9909 | DECLARE_CAST(JSMap) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9910 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9911 | static void Initialize(Handle<JSMap> map, Isolate* isolate); |
| 9912 | static void Clear(Handle<JSMap> map); |
| 9913 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9914 | // Dispatched behavior. |
| 9915 | DECLARE_PRINTER(JSMap) |
| 9916 | DECLARE_VERIFIER(JSMap) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9917 | |
| 9918 | private: |
| 9919 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSMap); |
| 9920 | }; |
| 9921 | |
| 9922 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9923 | // OrderedHashTableIterator is an iterator that iterates over the keys and |
| 9924 | // values of an OrderedHashTable. |
| 9925 | // |
| 9926 | // The iterator has a reference to the underlying OrderedHashTable data, |
| 9927 | // [table], as well as the current [index] the iterator is at. |
| 9928 | // |
| 9929 | // When the OrderedHashTable is rehashed it adds a reference from the old table |
| 9930 | // to the new table as well as storing enough data about the changes so that the |
| 9931 | // iterator [index] can be adjusted accordingly. |
| 9932 | // |
| 9933 | // When the [Next] result from the iterator is requested, the iterator checks if |
| 9934 | // there is a newer table that it needs to transition to. |
| 9935 | template<class Derived, class TableType> |
| 9936 | class OrderedHashTableIterator: public JSObject { |
| 9937 | public: |
| 9938 | // [table]: the backing hash table mapping keys to values. |
| 9939 | DECL_ACCESSORS(table, Object) |
| 9940 | |
| 9941 | // [index]: The index into the data table. |
| 9942 | DECL_ACCESSORS(index, Object) |
| 9943 | |
| 9944 | // [kind]: The kind of iteration this is. One of the [Kind] enum values. |
| 9945 | DECL_ACCESSORS(kind, Object) |
| 9946 | |
| 9947 | #ifdef OBJECT_PRINT |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 9948 | void OrderedHashTableIteratorPrint(std::ostream& os); // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9949 | #endif |
| 9950 | |
| 9951 | static const int kTableOffset = JSObject::kHeaderSize; |
| 9952 | static const int kIndexOffset = kTableOffset + kPointerSize; |
| 9953 | static const int kKindOffset = kIndexOffset + kPointerSize; |
| 9954 | static const int kSize = kKindOffset + kPointerSize; |
| 9955 | |
| 9956 | enum Kind { |
| 9957 | kKindKeys = 1, |
| 9958 | kKindValues = 2, |
| 9959 | kKindEntries = 3 |
| 9960 | }; |
| 9961 | |
| 9962 | // Whether the iterator has more elements. This needs to be called before |
| 9963 | // calling |CurrentKey| and/or |CurrentValue|. |
| 9964 | bool HasMore(); |
| 9965 | |
| 9966 | // Move the index forward one. |
| 9967 | void MoveNext() { |
| 9968 | set_index(Smi::FromInt(Smi::cast(index())->value() + 1)); |
| 9969 | } |
| 9970 | |
| 9971 | // Populates the array with the next key and value and then moves the iterator |
| 9972 | // forward. |
| 9973 | // This returns the |kind| or 0 if the iterator is already at the end. |
| 9974 | Smi* Next(JSArray* value_array); |
| 9975 | |
| 9976 | // Returns the current key of the iterator. This should only be called when |
| 9977 | // |HasMore| returns true. |
| 9978 | inline Object* CurrentKey(); |
| 9979 | |
| 9980 | private: |
| 9981 | // Transitions the iterator to the non obsolete backing store. This is a NOP |
| 9982 | // if the [table] is not obsolete. |
| 9983 | void Transition(); |
| 9984 | |
| 9985 | DISALLOW_IMPLICIT_CONSTRUCTORS(OrderedHashTableIterator); |
| 9986 | }; |
| 9987 | |
| 9988 | |
| 9989 | class JSSetIterator: public OrderedHashTableIterator<JSSetIterator, |
| 9990 | OrderedHashSet> { |
| 9991 | public: |
| 9992 | // Dispatched behavior. |
| 9993 | DECLARE_PRINTER(JSSetIterator) |
| 9994 | DECLARE_VERIFIER(JSSetIterator) |
| 9995 | |
| 9996 | DECLARE_CAST(JSSetIterator) |
| 9997 | |
| 9998 | // Called by |Next| to populate the array. This allows the subclasses to |
| 9999 | // populate the array differently. |
| 10000 | inline void PopulateValueArray(FixedArray* array); |
| 10001 | |
| 10002 | private: |
| 10003 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSSetIterator); |
| 10004 | }; |
| 10005 | |
| 10006 | |
| 10007 | class JSMapIterator: public OrderedHashTableIterator<JSMapIterator, |
| 10008 | OrderedHashMap> { |
| 10009 | public: |
| 10010 | // Dispatched behavior. |
| 10011 | DECLARE_PRINTER(JSMapIterator) |
| 10012 | DECLARE_VERIFIER(JSMapIterator) |
| 10013 | |
| 10014 | DECLARE_CAST(JSMapIterator) |
| 10015 | |
| 10016 | // Called by |Next| to populate the array. This allows the subclasses to |
| 10017 | // populate the array differently. |
| 10018 | inline void PopulateValueArray(FixedArray* array); |
| 10019 | |
| 10020 | private: |
| 10021 | // Returns the current value of the iterator. This should only be called when |
| 10022 | // |HasMore| returns true. |
| 10023 | inline Object* CurrentValue(); |
| 10024 | |
| 10025 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSMapIterator); |
| 10026 | }; |
| 10027 | |
| 10028 | |
| 10029 | // Base class for both JSWeakMap and JSWeakSet |
| 10030 | class JSWeakCollection: public JSObject { |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 10031 | public: |
| 10032 | // [table]: the backing hash table mapping keys to values. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10033 | DECL_ACCESSORS(table, Object) |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 10034 | |
| 10035 | // [next]: linked list of encountered weak maps during GC. |
| 10036 | DECL_ACCESSORS(next, Object) |
| 10037 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10038 | static void Initialize(Handle<JSWeakCollection> collection, Isolate* isolate); |
| 10039 | static void Set(Handle<JSWeakCollection> collection, Handle<Object> key, |
| 10040 | Handle<Object> value, int32_t hash); |
| 10041 | static bool Delete(Handle<JSWeakCollection> collection, Handle<Object> key, |
| 10042 | int32_t hash); |
| 10043 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 10044 | static const int kTableOffset = JSObject::kHeaderSize; |
| 10045 | static const int kNextOffset = kTableOffset + kPointerSize; |
| 10046 | static const int kSize = kNextOffset + kPointerSize; |
| 10047 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10048 | // Visiting policy defines whether the table and next collection fields |
| 10049 | // should be visited or not. |
| 10050 | enum BodyVisitingPolicy { kVisitStrong, kVisitWeak }; |
| 10051 | |
| 10052 | // Iterates the function object according to the visiting policy. |
| 10053 | template <BodyVisitingPolicy> |
| 10054 | class BodyDescriptorImpl; |
| 10055 | |
| 10056 | // Visit the whole object. |
| 10057 | typedef BodyDescriptorImpl<kVisitStrong> BodyDescriptor; |
| 10058 | |
| 10059 | // Don't visit table and next collection fields. |
| 10060 | typedef BodyDescriptorImpl<kVisitWeak> BodyDescriptorWeak; |
| 10061 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 10062 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10063 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSWeakCollection); |
| 10064 | }; |
| 10065 | |
| 10066 | |
| 10067 | // The JSWeakMap describes EcmaScript Harmony weak maps |
| 10068 | class JSWeakMap: public JSWeakCollection { |
| 10069 | public: |
| 10070 | DECLARE_CAST(JSWeakMap) |
| 10071 | |
| 10072 | // Dispatched behavior. |
| 10073 | DECLARE_PRINTER(JSWeakMap) |
| 10074 | DECLARE_VERIFIER(JSWeakMap) |
| 10075 | |
| 10076 | private: |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 10077 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSWeakMap); |
| 10078 | }; |
| 10079 | |
| 10080 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10081 | // The JSWeakSet describes EcmaScript Harmony weak sets |
| 10082 | class JSWeakSet: public JSWeakCollection { |
| 10083 | public: |
| 10084 | DECLARE_CAST(JSWeakSet) |
| 10085 | |
| 10086 | // Dispatched behavior. |
| 10087 | DECLARE_PRINTER(JSWeakSet) |
| 10088 | DECLARE_VERIFIER(JSWeakSet) |
| 10089 | |
| 10090 | private: |
| 10091 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSWeakSet); |
| 10092 | }; |
| 10093 | |
| 10094 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10095 | // Whether a JSArrayBuffer is a SharedArrayBuffer or not. |
| 10096 | enum class SharedFlag { kNotShared, kShared }; |
| 10097 | |
| 10098 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10099 | class JSArrayBuffer: public JSObject { |
| 10100 | public: |
| 10101 | // [backing_store]: backing memory for this array |
| 10102 | DECL_ACCESSORS(backing_store, void) |
| 10103 | |
| 10104 | // [byte_length]: length in bytes |
| 10105 | DECL_ACCESSORS(byte_length, Object) |
| 10106 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10107 | inline uint32_t bit_field() const; |
| 10108 | inline void set_bit_field(uint32_t bits); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10109 | |
| 10110 | inline bool is_external(); |
| 10111 | inline void set_is_external(bool value); |
| 10112 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 10113 | inline bool is_neuterable(); |
| 10114 | inline void set_is_neuterable(bool value); |
| 10115 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10116 | inline bool was_neutered(); |
| 10117 | inline void set_was_neutered(bool value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10118 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10119 | inline bool is_shared(); |
| 10120 | inline void set_is_shared(bool value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10121 | |
| 10122 | DECLARE_CAST(JSArrayBuffer) |
| 10123 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10124 | void Neuter(); |
| 10125 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10126 | static void Setup(Handle<JSArrayBuffer> array_buffer, Isolate* isolate, |
| 10127 | bool is_external, void* data, size_t allocated_length, |
| 10128 | SharedFlag shared = SharedFlag::kNotShared); |
| 10129 | |
| 10130 | static bool SetupAllocatingData(Handle<JSArrayBuffer> array_buffer, |
| 10131 | Isolate* isolate, size_t allocated_length, |
| 10132 | bool initialize = true, |
| 10133 | SharedFlag shared = SharedFlag::kNotShared); |
| 10134 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10135 | // Dispatched behavior. |
| 10136 | DECLARE_PRINTER(JSArrayBuffer) |
| 10137 | DECLARE_VERIFIER(JSArrayBuffer) |
| 10138 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10139 | static const int kByteLengthOffset = JSObject::kHeaderSize; |
| 10140 | static const int kBackingStoreOffset = kByteLengthOffset + kPointerSize; |
| 10141 | static const int kBitFieldSlot = kBackingStoreOffset + kPointerSize; |
| 10142 | #if V8_TARGET_LITTLE_ENDIAN || !V8_HOST_ARCH_64_BIT |
| 10143 | static const int kBitFieldOffset = kBitFieldSlot; |
| 10144 | #else |
| 10145 | static const int kBitFieldOffset = kBitFieldSlot + kIntSize; |
| 10146 | #endif |
| 10147 | static const int kSize = kBitFieldSlot + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10148 | |
| 10149 | static const int kSizeWithInternalFields = |
| 10150 | kSize + v8::ArrayBuffer::kInternalFieldCount * kPointerSize; |
| 10151 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10152 | // Iterates all fields in the object including internal ones except |
| 10153 | // kBackingStoreOffset and kBitFieldSlot. |
| 10154 | class BodyDescriptor; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10155 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10156 | class IsExternal : public BitField<bool, 1, 1> {}; |
| 10157 | class IsNeuterable : public BitField<bool, 2, 1> {}; |
| 10158 | class WasNeutered : public BitField<bool, 3, 1> {}; |
| 10159 | class IsShared : public BitField<bool, 4, 1> {}; |
| 10160 | |
| 10161 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10162 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSArrayBuffer); |
| 10163 | }; |
| 10164 | |
| 10165 | |
| 10166 | class JSArrayBufferView: public JSObject { |
| 10167 | public: |
| 10168 | // [buffer]: ArrayBuffer that this typed array views. |
| 10169 | DECL_ACCESSORS(buffer, Object) |
| 10170 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10171 | // [byte_offset]: offset of typed array in bytes. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10172 | DECL_ACCESSORS(byte_offset, Object) |
| 10173 | |
| 10174 | // [byte_length]: length of typed array in bytes. |
| 10175 | DECL_ACCESSORS(byte_length, Object) |
| 10176 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10177 | DECLARE_CAST(JSArrayBufferView) |
| 10178 | |
| 10179 | DECLARE_VERIFIER(JSArrayBufferView) |
| 10180 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10181 | inline bool WasNeutered() const; |
| 10182 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10183 | static const int kBufferOffset = JSObject::kHeaderSize; |
| 10184 | static const int kByteOffsetOffset = kBufferOffset + kPointerSize; |
| 10185 | static const int kByteLengthOffset = kByteOffsetOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10186 | static const int kViewSize = kByteLengthOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10187 | |
| 10188 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10189 | #ifdef VERIFY_HEAP |
| 10190 | DECL_ACCESSORS(raw_byte_offset, Object) |
| 10191 | DECL_ACCESSORS(raw_byte_length, Object) |
| 10192 | #endif |
| 10193 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10194 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSArrayBufferView); |
| 10195 | }; |
| 10196 | |
| 10197 | |
| 10198 | class JSTypedArray: public JSArrayBufferView { |
| 10199 | public: |
| 10200 | // [length]: length of typed array in elements. |
| 10201 | DECL_ACCESSORS(length, Object) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10202 | inline uint32_t length_value() const; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10203 | |
| 10204 | DECLARE_CAST(JSTypedArray) |
| 10205 | |
| 10206 | ExternalArrayType type(); |
| 10207 | size_t element_size(); |
| 10208 | |
| 10209 | Handle<JSArrayBuffer> GetBuffer(); |
| 10210 | |
| 10211 | // Dispatched behavior. |
| 10212 | DECLARE_PRINTER(JSTypedArray) |
| 10213 | DECLARE_VERIFIER(JSTypedArray) |
| 10214 | |
| 10215 | static const int kLengthOffset = kViewSize + kPointerSize; |
| 10216 | static const int kSize = kLengthOffset + kPointerSize; |
| 10217 | |
| 10218 | static const int kSizeWithInternalFields = |
| 10219 | kSize + v8::ArrayBufferView::kInternalFieldCount * kPointerSize; |
| 10220 | |
| 10221 | private: |
| 10222 | static Handle<JSArrayBuffer> MaterializeArrayBuffer( |
| 10223 | Handle<JSTypedArray> typed_array); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10224 | #ifdef VERIFY_HEAP |
| 10225 | DECL_ACCESSORS(raw_length, Object) |
| 10226 | #endif |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10227 | |
| 10228 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSTypedArray); |
| 10229 | }; |
| 10230 | |
| 10231 | |
| 10232 | class JSDataView: public JSArrayBufferView { |
| 10233 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10234 | DECLARE_CAST(JSDataView) |
| 10235 | |
| 10236 | // Dispatched behavior. |
| 10237 | DECLARE_PRINTER(JSDataView) |
| 10238 | DECLARE_VERIFIER(JSDataView) |
| 10239 | |
| 10240 | static const int kSize = kViewSize; |
| 10241 | |
| 10242 | static const int kSizeWithInternalFields = |
| 10243 | kSize + v8::ArrayBufferView::kInternalFieldCount * kPointerSize; |
| 10244 | |
| 10245 | private: |
| 10246 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSDataView); |
| 10247 | }; |
| 10248 | |
| 10249 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 10250 | // Foreign describes objects pointing from JavaScript to C structures. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 10251 | class Foreign: public HeapObject { |
| 10252 | public: |
| 10253 | // [address]: field containing the address. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10254 | inline Address foreign_address(); |
| 10255 | inline void set_foreign_address(Address value); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 10256 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10257 | DECLARE_CAST(Foreign) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 10258 | |
| 10259 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10260 | DECLARE_PRINTER(Foreign) |
| 10261 | DECLARE_VERIFIER(Foreign) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10262 | |
| 10263 | // Layout description. |
| 10264 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10265 | static const int kForeignAddressOffset = HeapObject::kHeaderSize; |
| 10266 | static const int kSize = kForeignAddressOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10267 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10268 | STATIC_ASSERT(kForeignAddressOffset == Internals::kForeignAddressOffset); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10269 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10270 | class BodyDescriptor; |
| 10271 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10272 | private: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 10273 | DISALLOW_IMPLICIT_CONSTRUCTORS(Foreign); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10274 | }; |
| 10275 | |
| 10276 | |
| 10277 | // The JSArray describes JavaScript Arrays |
| 10278 | // Such an array can be in one of two modes: |
| 10279 | // - fast, backing storage is a FixedArray and length <= elements.length(); |
| 10280 | // Please note: push and pop can be used to grow and shrink the array. |
| 10281 | // - slow, backing storage is a HashTable with numbers as keys. |
| 10282 | class JSArray: public JSObject { |
| 10283 | public: |
| 10284 | // [length]: The length property. |
| 10285 | DECL_ACCESSORS(length, Object) |
| 10286 | |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 10287 | // Overload the length setter to skip write barrier when the length |
| 10288 | // is set to a smi. This matches the set function on FixedArray. |
| 10289 | inline void set_length(Smi* length); |
| 10290 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 10291 | static bool HasReadOnlyLength(Handle<JSArray> array); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10292 | static bool WouldChangeReadOnlyLength(Handle<JSArray> array, uint32_t index); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 10293 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10294 | // Initialize the array with the given capacity. The function may |
| 10295 | // fail due to out-of-memory situations, but only if the requested |
| 10296 | // capacity is non-zero. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10297 | static void Initialize(Handle<JSArray> array, int capacity, int length = 0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10298 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10299 | // If the JSArray has fast elements, and new_length would result in |
| 10300 | // normalization, returns true. |
| 10301 | bool SetLengthWouldNormalize(uint32_t new_length); |
| 10302 | static inline bool SetLengthWouldNormalize(Heap* heap, uint32_t new_length); |
| 10303 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10304 | // Initializes the array to a certain length. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10305 | inline bool AllowsSetLength(); |
| 10306 | |
| 10307 | static void SetLength(Handle<JSArray> array, uint32_t length); |
| 10308 | // Same as above but will also queue splice records if |array| is observed. |
| 10309 | static MaybeHandle<Object> ObservableSetLength(Handle<JSArray> array, |
| 10310 | uint32_t length); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10311 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10312 | // Set the content of the array to the content of storage. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10313 | static inline void SetContent(Handle<JSArray> array, |
| 10314 | Handle<FixedArrayBase> storage); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10315 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10316 | // ES6 9.4.2.1 |
| 10317 | MUST_USE_RESULT static Maybe<bool> DefineOwnProperty( |
| 10318 | Isolate* isolate, Handle<JSArray> o, Handle<Object> name, |
| 10319 | PropertyDescriptor* desc, ShouldThrow should_throw); |
| 10320 | |
| 10321 | static bool AnythingToArrayLength(Isolate* isolate, |
| 10322 | Handle<Object> length_object, |
| 10323 | uint32_t* output); |
| 10324 | MUST_USE_RESULT static Maybe<bool> ArraySetLength(Isolate* isolate, |
| 10325 | Handle<JSArray> a, |
| 10326 | PropertyDescriptor* desc, |
| 10327 | ShouldThrow should_throw); |
| 10328 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 10329 | // Checks whether the Array has the current realm's Array.prototype as its |
| 10330 | // prototype. This function is best-effort and only gives a conservative |
| 10331 | // approximation, erring on the side of false, in particular with respect |
| 10332 | // to Proxies and objects with a hidden prototype. |
| 10333 | inline bool HasArrayPrototype(Isolate* isolate); |
| 10334 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10335 | DECLARE_CAST(JSArray) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10336 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10337 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10338 | DECLARE_PRINTER(JSArray) |
| 10339 | DECLARE_VERIFIER(JSArray) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10340 | |
| 10341 | // Number of element slots to pre-allocate for an empty array. |
| 10342 | static const int kPreallocatedArrayElements = 4; |
| 10343 | |
| 10344 | // Layout description. |
| 10345 | static const int kLengthOffset = JSObject::kHeaderSize; |
| 10346 | static const int kSize = kLengthOffset + kPointerSize; |
| 10347 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10348 | // 600 * KB is the Page::kMaxRegularHeapObjectSize defined in spaces.h which |
| 10349 | // we do not want to include in objects.h |
| 10350 | // Note that Page::kMaxRegularHeapObjectSize has to be in sync with |
| 10351 | // kInitialMaxFastElementArray which is checked in a DCHECK in heap.cc. |
| 10352 | static const int kInitialMaxFastElementArray = |
| 10353 | (600 * KB - FixedArray::kHeaderSize - kSize - AllocationMemento::kSize) / |
| 10354 | kPointerSize; |
| 10355 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10356 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10357 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSArray); |
| 10358 | }; |
| 10359 | |
| 10360 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10361 | Handle<Object> CacheInitialJSArrayMaps(Handle<Context> native_context, |
| 10362 | Handle<Map> initial_map); |
| 10363 | |
| 10364 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 10365 | // JSRegExpResult is just a JSArray with a specific initial map. |
| 10366 | // This initial map adds in-object properties for "index" and "input" |
| 10367 | // properties, as assigned by RegExp.prototype.exec, which allows |
| 10368 | // faster creation of RegExp exec results. |
| 10369 | // This class just holds constants used when creating the result. |
| 10370 | // After creation the result must be treated as a JSArray in all regards. |
| 10371 | class JSRegExpResult: public JSArray { |
| 10372 | public: |
| 10373 | // Offsets of object fields. |
| 10374 | static const int kIndexOffset = JSArray::kSize; |
| 10375 | static const int kInputOffset = kIndexOffset + kPointerSize; |
| 10376 | static const int kSize = kInputOffset + kPointerSize; |
| 10377 | // Indices of in-object properties. |
| 10378 | static const int kIndexIndex = 0; |
| 10379 | static const int kInputIndex = 1; |
| 10380 | private: |
| 10381 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSRegExpResult); |
| 10382 | }; |
| 10383 | |
| 10384 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10385 | // An accessor must have a getter, but can have no setter. |
| 10386 | // |
| 10387 | // When setting a property, V8 searches accessors in prototypes. |
| 10388 | // If an accessor was found and it does not have a setter, |
| 10389 | // the request is ignored. |
| 10390 | // |
| 10391 | // If the accessor in the prototype has the READ_ONLY property attribute, then |
| 10392 | // a new value is added to the derived object when the property is set. |
| 10393 | // This shadows the accessor in the prototype. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10394 | class AccessorInfo: public Struct { |
| 10395 | public: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10396 | DECL_ACCESSORS(name, Object) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10397 | DECL_INT_ACCESSORS(flag) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10398 | DECL_ACCESSORS(expected_receiver_type, Object) |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10399 | DECL_ACCESSORS(getter, Object) |
| 10400 | DECL_ACCESSORS(setter, Object) |
| 10401 | DECL_ACCESSORS(data, Object) |
| 10402 | |
| 10403 | // Dispatched behavior. |
| 10404 | DECLARE_PRINTER(AccessorInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10405 | |
| 10406 | inline bool all_can_read(); |
| 10407 | inline void set_all_can_read(bool value); |
| 10408 | |
| 10409 | inline bool all_can_write(); |
| 10410 | inline void set_all_can_write(bool value); |
| 10411 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10412 | inline bool is_special_data_property(); |
| 10413 | inline void set_is_special_data_property(bool value); |
| 10414 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 10415 | inline bool is_sloppy(); |
| 10416 | inline void set_is_sloppy(bool value); |
| 10417 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10418 | inline PropertyAttributes property_attributes(); |
| 10419 | inline void set_property_attributes(PropertyAttributes attributes); |
| 10420 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10421 | // Checks whether the given receiver is compatible with this accessor. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10422 | static bool IsCompatibleReceiverMap(Isolate* isolate, |
| 10423 | Handle<AccessorInfo> info, |
| 10424 | Handle<Map> map); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10425 | inline bool IsCompatibleReceiver(Object* receiver); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10426 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10427 | DECLARE_CAST(AccessorInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10428 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10429 | // Dispatched behavior. |
| 10430 | DECLARE_VERIFIER(AccessorInfo) |
| 10431 | |
| 10432 | // Append all descriptors to the array that are not already there. |
| 10433 | // Return number added. |
| 10434 | static int AppendUnique(Handle<Object> descriptors, |
| 10435 | Handle<FixedArray> array, |
| 10436 | int valid_descriptors); |
| 10437 | |
| 10438 | static const int kNameOffset = HeapObject::kHeaderSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10439 | static const int kFlagOffset = kNameOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10440 | static const int kExpectedReceiverTypeOffset = kFlagOffset + kPointerSize; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10441 | static const int kGetterOffset = kExpectedReceiverTypeOffset + kPointerSize; |
| 10442 | static const int kSetterOffset = kGetterOffset + kPointerSize; |
| 10443 | static const int kDataOffset = kSetterOffset + kPointerSize; |
| 10444 | static const int kSize = kDataOffset + kPointerSize; |
| 10445 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10446 | |
| 10447 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10448 | inline bool HasExpectedReceiverType(); |
| 10449 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10450 | // Bit positions in flag. |
| 10451 | static const int kAllCanReadBit = 0; |
| 10452 | static const int kAllCanWriteBit = 1; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10453 | static const int kSpecialDataProperty = 2; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 10454 | static const int kIsSloppy = 3; |
| 10455 | class AttributesField : public BitField<PropertyAttributes, 4, 3> {}; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10456 | |
| 10457 | DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorInfo); |
| 10458 | }; |
| 10459 | |
| 10460 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10461 | // Support for JavaScript accessors: A pair of a getter and a setter. Each |
| 10462 | // accessor can either be |
| 10463 | // * a pointer to a JavaScript function or proxy: a real accessor |
| 10464 | // * undefined: considered an accessor by the spec, too, strangely enough |
| 10465 | // * the hole: an accessor which has not been set |
| 10466 | // * a pointer to a map: a transition used to ensure map sharing |
| 10467 | class AccessorPair: public Struct { |
| 10468 | public: |
| 10469 | DECL_ACCESSORS(getter, Object) |
| 10470 | DECL_ACCESSORS(setter, Object) |
| 10471 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10472 | DECLARE_CAST(AccessorPair) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10473 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10474 | static Handle<AccessorPair> Copy(Handle<AccessorPair> pair); |
| 10475 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10476 | inline Object* get(AccessorComponent component); |
| 10477 | inline void set(AccessorComponent component, Object* value); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10478 | |
| 10479 | // Note: Returns undefined instead in case of a hole. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10480 | static Handle<Object> GetComponent(Handle<AccessorPair> accessor_pair, |
| 10481 | AccessorComponent component); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10482 | |
| 10483 | // Set both components, skipping arguments which are a JavaScript null. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10484 | inline void SetComponents(Object* getter, Object* setter); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10485 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10486 | inline bool Equals(AccessorPair* pair); |
| 10487 | inline bool Equals(Object* getter_value, Object* setter_value); |
| 10488 | |
| 10489 | inline bool ContainsAccessor(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10490 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10491 | // Dispatched behavior. |
| 10492 | DECLARE_PRINTER(AccessorPair) |
| 10493 | DECLARE_VERIFIER(AccessorPair) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10494 | |
| 10495 | static const int kGetterOffset = HeapObject::kHeaderSize; |
| 10496 | static const int kSetterOffset = kGetterOffset + kPointerSize; |
| 10497 | static const int kSize = kSetterOffset + kPointerSize; |
| 10498 | |
| 10499 | private: |
| 10500 | // Strangely enough, in addition to functions and harmony proxies, the spec |
| 10501 | // requires us to consider undefined as a kind of accessor, too: |
| 10502 | // var obj = {}; |
| 10503 | // Object.defineProperty(obj, "foo", {get: undefined}); |
| 10504 | // assertTrue("foo" in obj); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10505 | inline bool IsJSAccessor(Object* obj); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10506 | |
| 10507 | DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorPair); |
| 10508 | }; |
| 10509 | |
| 10510 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10511 | class AccessCheckInfo: public Struct { |
| 10512 | public: |
| 10513 | DECL_ACCESSORS(named_callback, Object) |
| 10514 | DECL_ACCESSORS(indexed_callback, Object) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10515 | DECL_ACCESSORS(callback, Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10516 | DECL_ACCESSORS(data, Object) |
| 10517 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10518 | DECLARE_CAST(AccessCheckInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10519 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10520 | // Dispatched behavior. |
| 10521 | DECLARE_PRINTER(AccessCheckInfo) |
| 10522 | DECLARE_VERIFIER(AccessCheckInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10523 | |
| 10524 | static const int kNamedCallbackOffset = HeapObject::kHeaderSize; |
| 10525 | static const int kIndexedCallbackOffset = kNamedCallbackOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10526 | static const int kCallbackOffset = kIndexedCallbackOffset + kPointerSize; |
| 10527 | static const int kDataOffset = kCallbackOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10528 | static const int kSize = kDataOffset + kPointerSize; |
| 10529 | |
| 10530 | private: |
| 10531 | DISALLOW_IMPLICIT_CONSTRUCTORS(AccessCheckInfo); |
| 10532 | }; |
| 10533 | |
| 10534 | |
| 10535 | class InterceptorInfo: public Struct { |
| 10536 | public: |
| 10537 | DECL_ACCESSORS(getter, Object) |
| 10538 | DECL_ACCESSORS(setter, Object) |
| 10539 | DECL_ACCESSORS(query, Object) |
| 10540 | DECL_ACCESSORS(deleter, Object) |
| 10541 | DECL_ACCESSORS(enumerator, Object) |
| 10542 | DECL_ACCESSORS(data, Object) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 10543 | DECL_BOOLEAN_ACCESSORS(can_intercept_symbols) |
| 10544 | DECL_BOOLEAN_ACCESSORS(all_can_read) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10545 | DECL_BOOLEAN_ACCESSORS(non_masking) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 10546 | |
| 10547 | inline int flags() const; |
| 10548 | inline void set_flags(int flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10549 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10550 | DECLARE_CAST(InterceptorInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10551 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10552 | // Dispatched behavior. |
| 10553 | DECLARE_PRINTER(InterceptorInfo) |
| 10554 | DECLARE_VERIFIER(InterceptorInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10555 | |
| 10556 | static const int kGetterOffset = HeapObject::kHeaderSize; |
| 10557 | static const int kSetterOffset = kGetterOffset + kPointerSize; |
| 10558 | static const int kQueryOffset = kSetterOffset + kPointerSize; |
| 10559 | static const int kDeleterOffset = kQueryOffset + kPointerSize; |
| 10560 | static const int kEnumeratorOffset = kDeleterOffset + kPointerSize; |
| 10561 | static const int kDataOffset = kEnumeratorOffset + kPointerSize; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 10562 | static const int kFlagsOffset = kDataOffset + kPointerSize; |
| 10563 | static const int kSize = kFlagsOffset + kPointerSize; |
| 10564 | |
| 10565 | static const int kCanInterceptSymbolsBit = 0; |
| 10566 | static const int kAllCanReadBit = 1; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10567 | static const int kNonMasking = 2; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10568 | |
| 10569 | private: |
| 10570 | DISALLOW_IMPLICIT_CONSTRUCTORS(InterceptorInfo); |
| 10571 | }; |
| 10572 | |
| 10573 | |
| 10574 | class CallHandlerInfo: public Struct { |
| 10575 | public: |
| 10576 | DECL_ACCESSORS(callback, Object) |
| 10577 | DECL_ACCESSORS(data, Object) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10578 | DECL_ACCESSORS(fast_handler, Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10579 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10580 | DECLARE_CAST(CallHandlerInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10581 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10582 | // Dispatched behavior. |
| 10583 | DECLARE_PRINTER(CallHandlerInfo) |
| 10584 | DECLARE_VERIFIER(CallHandlerInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10585 | |
| 10586 | static const int kCallbackOffset = HeapObject::kHeaderSize; |
| 10587 | static const int kDataOffset = kCallbackOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10588 | static const int kFastHandlerOffset = kDataOffset + kPointerSize; |
| 10589 | static const int kSize = kFastHandlerOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10590 | |
| 10591 | private: |
| 10592 | DISALLOW_IMPLICIT_CONSTRUCTORS(CallHandlerInfo); |
| 10593 | }; |
| 10594 | |
| 10595 | |
| 10596 | class TemplateInfo: public Struct { |
| 10597 | public: |
| 10598 | DECL_ACCESSORS(tag, Object) |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10599 | DECL_ACCESSORS(serial_number, Object) |
| 10600 | DECL_INT_ACCESSORS(number_of_properties) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10601 | DECL_ACCESSORS(property_list, Object) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10602 | DECL_ACCESSORS(property_accessors, Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10603 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10604 | DECLARE_VERIFIER(TemplateInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10605 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10606 | static const int kTagOffset = HeapObject::kHeaderSize; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10607 | static const int kSerialNumberOffset = kTagOffset + kPointerSize; |
| 10608 | static const int kNumberOfProperties = kSerialNumberOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10609 | static const int kPropertyListOffset = kNumberOfProperties + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10610 | static const int kPropertyAccessorsOffset = |
| 10611 | kPropertyListOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10612 | static const int kPropertyIntrinsicsOffset = |
| 10613 | kPropertyAccessorsOffset + kPointerSize; |
| 10614 | static const int kHeaderSize = kPropertyIntrinsicsOffset + kPointerSize; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10615 | |
| 10616 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10617 | DISALLOW_IMPLICIT_CONSTRUCTORS(TemplateInfo); |
| 10618 | }; |
| 10619 | |
| 10620 | |
| 10621 | class FunctionTemplateInfo: public TemplateInfo { |
| 10622 | public: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10623 | DECL_ACCESSORS(call_code, Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10624 | DECL_ACCESSORS(prototype_template, Object) |
| 10625 | DECL_ACCESSORS(parent_template, Object) |
| 10626 | DECL_ACCESSORS(named_property_handler, Object) |
| 10627 | DECL_ACCESSORS(indexed_property_handler, Object) |
| 10628 | DECL_ACCESSORS(instance_template, Object) |
| 10629 | DECL_ACCESSORS(class_name, Object) |
| 10630 | DECL_ACCESSORS(signature, Object) |
| 10631 | DECL_ACCESSORS(instance_call_handler, Object) |
| 10632 | DECL_ACCESSORS(access_check_info, Object) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10633 | DECL_INT_ACCESSORS(flag) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10634 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10635 | inline int length() const; |
| 10636 | inline void set_length(int value); |
| 10637 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10638 | // Following properties use flag bits. |
| 10639 | DECL_BOOLEAN_ACCESSORS(hidden_prototype) |
| 10640 | DECL_BOOLEAN_ACCESSORS(undetectable) |
| 10641 | // If the bit is set, object instances created by this function |
| 10642 | // requires access check. |
| 10643 | DECL_BOOLEAN_ACCESSORS(needs_access_check) |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 10644 | DECL_BOOLEAN_ACCESSORS(read_only_prototype) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10645 | DECL_BOOLEAN_ACCESSORS(remove_prototype) |
| 10646 | DECL_BOOLEAN_ACCESSORS(do_not_cache) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10647 | DECL_BOOLEAN_ACCESSORS(instantiated) |
| 10648 | DECL_BOOLEAN_ACCESSORS(accept_any_receiver) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10649 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10650 | DECLARE_CAST(FunctionTemplateInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10651 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10652 | // Dispatched behavior. |
| 10653 | DECLARE_PRINTER(FunctionTemplateInfo) |
| 10654 | DECLARE_VERIFIER(FunctionTemplateInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10655 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10656 | static const int kCallCodeOffset = TemplateInfo::kHeaderSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10657 | static const int kPrototypeTemplateOffset = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10658 | kCallCodeOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10659 | static const int kParentTemplateOffset = |
| 10660 | kPrototypeTemplateOffset + kPointerSize; |
| 10661 | static const int kNamedPropertyHandlerOffset = |
| 10662 | kParentTemplateOffset + kPointerSize; |
| 10663 | static const int kIndexedPropertyHandlerOffset = |
| 10664 | kNamedPropertyHandlerOffset + kPointerSize; |
| 10665 | static const int kInstanceTemplateOffset = |
| 10666 | kIndexedPropertyHandlerOffset + kPointerSize; |
| 10667 | static const int kClassNameOffset = kInstanceTemplateOffset + kPointerSize; |
| 10668 | static const int kSignatureOffset = kClassNameOffset + kPointerSize; |
| 10669 | static const int kInstanceCallHandlerOffset = kSignatureOffset + kPointerSize; |
| 10670 | static const int kAccessCheckInfoOffset = |
| 10671 | kInstanceCallHandlerOffset + kPointerSize; |
| 10672 | static const int kFlagOffset = kAccessCheckInfoOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10673 | static const int kLengthOffset = kFlagOffset + kPointerSize; |
| 10674 | static const int kSize = kLengthOffset + kPointerSize; |
| 10675 | |
| 10676 | // Returns true if |object| is an instance of this function template. |
| 10677 | bool IsTemplateFor(Object* object); |
| 10678 | bool IsTemplateFor(Map* map); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10679 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10680 | // Returns the holder JSObject if the function can legally be called with this |
| 10681 | // receiver. Returns Heap::null_value() if the call is illegal. |
| 10682 | Object* GetCompatibleReceiver(Isolate* isolate, Object* receiver); |
| 10683 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10684 | private: |
| 10685 | // Bit position in the flag, from least significant bit position. |
| 10686 | static const int kHiddenPrototypeBit = 0; |
| 10687 | static const int kUndetectableBit = 1; |
| 10688 | static const int kNeedsAccessCheckBit = 2; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 10689 | static const int kReadOnlyPrototypeBit = 3; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10690 | static const int kRemovePrototypeBit = 4; |
| 10691 | static const int kDoNotCacheBit = 5; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10692 | static const int kInstantiatedBit = 6; |
| 10693 | static const int kAcceptAnyReceiver = 7; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10694 | |
| 10695 | DISALLOW_IMPLICIT_CONSTRUCTORS(FunctionTemplateInfo); |
| 10696 | }; |
| 10697 | |
| 10698 | |
| 10699 | class ObjectTemplateInfo: public TemplateInfo { |
| 10700 | public: |
| 10701 | DECL_ACCESSORS(constructor, Object) |
| 10702 | DECL_ACCESSORS(internal_field_count, Object) |
| 10703 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10704 | DECLARE_CAST(ObjectTemplateInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10705 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10706 | // Dispatched behavior. |
| 10707 | DECLARE_PRINTER(ObjectTemplateInfo) |
| 10708 | DECLARE_VERIFIER(ObjectTemplateInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10709 | |
| 10710 | static const int kConstructorOffset = TemplateInfo::kHeaderSize; |
| 10711 | static const int kInternalFieldCountOffset = |
| 10712 | kConstructorOffset + kPointerSize; |
| 10713 | static const int kSize = kInternalFieldCountOffset + kPointerSize; |
| 10714 | }; |
| 10715 | |
| 10716 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10717 | // The DebugInfo class holds additional information for a function being |
| 10718 | // debugged. |
| 10719 | class DebugInfo: public Struct { |
| 10720 | public: |
| 10721 | // The shared function info for the source being debugged. |
| 10722 | DECL_ACCESSORS(shared, SharedFunctionInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10723 | // Code object for the patched code. This code object is the code object |
| 10724 | // currently active for the function. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10725 | DECL_ACCESSORS(abstract_code, AbstractCode) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10726 | // Fixed array holding status information for each active break point. |
| 10727 | DECL_ACCESSORS(break_points, FixedArray) |
| 10728 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10729 | // Check if there is a break point at a code offset. |
| 10730 | bool HasBreakPoint(int code_offset); |
| 10731 | // Get the break point info object for a code offset. |
| 10732 | Object* GetBreakPointInfo(int code_offset); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10733 | // Clear a break point. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10734 | static void ClearBreakPoint(Handle<DebugInfo> debug_info, int code_offset, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10735 | Handle<Object> break_point_object); |
| 10736 | // Set a break point. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10737 | static void SetBreakPoint(Handle<DebugInfo> debug_info, int code_offset, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10738 | int source_position, int statement_position, |
| 10739 | Handle<Object> break_point_object); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10740 | // Get the break point objects for a code offset. |
| 10741 | Handle<Object> GetBreakPointObjects(int code_offset); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10742 | // Find the break point info holding this break point object. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10743 | static Handle<Object> FindBreakPointInfo(Handle<DebugInfo> debug_info, |
| 10744 | Handle<Object> break_point_object); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10745 | // Get the number of break points for this function. |
| 10746 | int GetBreakPointCount(); |
| 10747 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10748 | static Smi* uninitialized() { return Smi::FromInt(0); } |
| 10749 | |
| 10750 | inline BytecodeArray* original_bytecode_array(); |
| 10751 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10752 | DECLARE_CAST(DebugInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10753 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10754 | // Dispatched behavior. |
| 10755 | DECLARE_PRINTER(DebugInfo) |
| 10756 | DECLARE_VERIFIER(DebugInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10757 | |
| 10758 | static const int kSharedFunctionInfoIndex = Struct::kHeaderSize; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10759 | static const int kAbstractCodeIndex = kSharedFunctionInfoIndex + kPointerSize; |
| 10760 | static const int kBreakPointsStateIndex = kAbstractCodeIndex + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10761 | static const int kSize = kBreakPointsStateIndex + kPointerSize; |
| 10762 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10763 | static const int kEstimatedNofBreakPointsInFunction = 16; |
| 10764 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10765 | private: |
| 10766 | static const int kNoBreakPointInfo = -1; |
| 10767 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10768 | // Lookup the index in the break_points array for a code offset. |
| 10769 | int GetBreakPointInfoIndex(int code_offset); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10770 | |
| 10771 | DISALLOW_IMPLICIT_CONSTRUCTORS(DebugInfo); |
| 10772 | }; |
| 10773 | |
| 10774 | |
| 10775 | // The BreakPointInfo class holds information for break points set in a |
| 10776 | // function. The DebugInfo object holds a BreakPointInfo object for each code |
| 10777 | // position with one or more break points. |
| 10778 | class BreakPointInfo: public Struct { |
| 10779 | public: |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10780 | // The code offset for the break point. |
| 10781 | DECL_INT_ACCESSORS(code_offset) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10782 | // The position in the source for the break position. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10783 | DECL_INT_ACCESSORS(source_position) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10784 | // The position in the source for the last statement before this break |
| 10785 | // position. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10786 | DECL_INT_ACCESSORS(statement_position) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10787 | // List of related JavaScript break points. |
| 10788 | DECL_ACCESSORS(break_point_objects, Object) |
| 10789 | |
| 10790 | // Removes a break point. |
| 10791 | static void ClearBreakPoint(Handle<BreakPointInfo> info, |
| 10792 | Handle<Object> break_point_object); |
| 10793 | // Set a break point. |
| 10794 | static void SetBreakPoint(Handle<BreakPointInfo> info, |
| 10795 | Handle<Object> break_point_object); |
| 10796 | // Check if break point info has this break point object. |
| 10797 | static bool HasBreakPointObject(Handle<BreakPointInfo> info, |
| 10798 | Handle<Object> break_point_object); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10799 | // Get the number of break points for this code offset. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10800 | int GetBreakPointCount(); |
| 10801 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10802 | DECLARE_CAST(BreakPointInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10803 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10804 | // Dispatched behavior. |
| 10805 | DECLARE_PRINTER(BreakPointInfo) |
| 10806 | DECLARE_VERIFIER(BreakPointInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10807 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10808 | static const int kCodeOffsetIndex = Struct::kHeaderSize; |
| 10809 | static const int kSourcePositionIndex = kCodeOffsetIndex + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10810 | static const int kStatementPositionIndex = |
| 10811 | kSourcePositionIndex + kPointerSize; |
| 10812 | static const int kBreakPointObjectsIndex = |
| 10813 | kStatementPositionIndex + kPointerSize; |
| 10814 | static const int kSize = kBreakPointObjectsIndex + kPointerSize; |
| 10815 | |
| 10816 | private: |
| 10817 | DISALLOW_IMPLICIT_CONSTRUCTORS(BreakPointInfo); |
| 10818 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10819 | |
| 10820 | |
| 10821 | #undef DECL_BOOLEAN_ACCESSORS |
| 10822 | #undef DECL_ACCESSORS |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10823 | #undef DECLARE_CAST |
| 10824 | #undef DECLARE_VERIFIER |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10825 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10826 | #define VISITOR_SYNCHRONIZATION_TAGS_LIST(V) \ |
| 10827 | V(kStringTable, "string_table", "(Internalized strings)") \ |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10828 | V(kExternalStringsTable, "external_strings_table", "(External strings)") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10829 | V(kStrongRootList, "strong_root_list", "(Strong roots)") \ |
| 10830 | V(kSmiRootList, "smi_root_list", "(Smi roots)") \ |
| 10831 | V(kBootstrapper, "bootstrapper", "(Bootstrapper)") \ |
| 10832 | V(kTop, "top", "(Isolate)") \ |
| 10833 | V(kRelocatable, "relocatable", "(Relocatable)") \ |
| 10834 | V(kDebug, "debug", "(Debugger)") \ |
| 10835 | V(kCompilationCache, "compilationcache", "(Compilation cache)") \ |
| 10836 | V(kHandleScope, "handlescope", "(Handle scope)") \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 10837 | V(kDispatchTable, "dispatchtable", "(Dispatch table)") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10838 | V(kBuiltins, "builtins", "(Builtins)") \ |
| 10839 | V(kGlobalHandles, "globalhandles", "(Global handles)") \ |
| 10840 | V(kEternalHandles, "eternalhandles", "(Eternal handles)") \ |
| 10841 | V(kThreadManager, "threadmanager", "(Thread manager)") \ |
| 10842 | V(kStrongRoots, "strong roots", "(Strong roots)") \ |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10843 | V(kExtensions, "Extensions", "(Extensions)") |
| 10844 | |
| 10845 | class VisitorSynchronization : public AllStatic { |
| 10846 | public: |
| 10847 | #define DECLARE_ENUM(enum_item, ignore1, ignore2) enum_item, |
| 10848 | enum SyncTag { |
| 10849 | VISITOR_SYNCHRONIZATION_TAGS_LIST(DECLARE_ENUM) |
| 10850 | kNumberOfSyncTags |
| 10851 | }; |
| 10852 | #undef DECLARE_ENUM |
| 10853 | |
| 10854 | static const char* const kTags[kNumberOfSyncTags]; |
| 10855 | static const char* const kTagNames[kNumberOfSyncTags]; |
| 10856 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10857 | |
| 10858 | // Abstract base class for visiting, and optionally modifying, the |
| 10859 | // pointers contained in Objects. Used in GC and serialization/deserialization. |
| 10860 | class ObjectVisitor BASE_EMBEDDED { |
| 10861 | public: |
| 10862 | virtual ~ObjectVisitor() {} |
| 10863 | |
| 10864 | // Visits a contiguous arrays of pointers in the half-open range |
| 10865 | // [start, end). Any or all of the values may be modified on return. |
| 10866 | virtual void VisitPointers(Object** start, Object** end) = 0; |
| 10867 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10868 | // Handy shorthand for visiting a single pointer. |
| 10869 | virtual void VisitPointer(Object** p) { VisitPointers(p, p + 1); } |
| 10870 | |
| 10871 | // Visit weak next_code_link in Code object. |
| 10872 | virtual void VisitNextCodeLink(Object** p) { VisitPointers(p, p + 1); } |
| 10873 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10874 | // To allow lazy clearing of inline caches the visitor has |
| 10875 | // a rich interface for iterating over Code objects.. |
| 10876 | |
| 10877 | // Visits a code target in the instruction stream. |
| 10878 | virtual void VisitCodeTarget(RelocInfo* rinfo); |
| 10879 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 10880 | // Visits a code entry in a JS function. |
| 10881 | virtual void VisitCodeEntry(Address entry_address); |
| 10882 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 10883 | // Visits a global property cell reference in the instruction stream. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10884 | virtual void VisitCell(RelocInfo* rinfo); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 10885 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10886 | // Visits a runtime entry in the instruction stream. |
| 10887 | virtual void VisitRuntimeEntry(RelocInfo* rinfo) {} |
| 10888 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10889 | // Visits the resource of an one-byte or two-byte string. |
| 10890 | virtual void VisitExternalOneByteString( |
| 10891 | v8::String::ExternalOneByteStringResource** resource) {} |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 10892 | virtual void VisitExternalTwoByteString( |
| 10893 | v8::String::ExternalStringResource** resource) {} |
| 10894 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10895 | // Visits a debug call target in the instruction stream. |
| 10896 | virtual void VisitDebugTarget(RelocInfo* rinfo); |
| 10897 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10898 | // Visits the byte sequence in a function's prologue that contains information |
| 10899 | // about the code's age. |
| 10900 | virtual void VisitCodeAgeSequence(RelocInfo* rinfo); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10901 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10902 | // Visit pointer embedded into a code object. |
| 10903 | virtual void VisitEmbeddedPointer(RelocInfo* rinfo); |
| 10904 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10905 | // Visits an external reference embedded into a code object. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10906 | virtual void VisitExternalReference(RelocInfo* rinfo); |
| 10907 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10908 | // Visits an external reference. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10909 | virtual void VisitExternalReference(Address* p) {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10910 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10911 | // Visits an (encoded) internal reference. |
| 10912 | virtual void VisitInternalReference(RelocInfo* rinfo) {} |
| 10913 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 10914 | // Visits a handle that has an embedder-assigned class ID. |
| 10915 | virtual void VisitEmbedderReference(Object** p, uint16_t class_id) {} |
| 10916 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10917 | // Intended for serialization/deserialization checking: insert, or |
| 10918 | // 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] | 10919 | // Also used for marking up GC roots in heap snapshots. |
| 10920 | virtual void Synchronize(VisitorSynchronization::SyncTag tag) {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10921 | }; |
| 10922 | |
| 10923 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10924 | // 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] | 10925 | class BooleanBit : public AllStatic { |
| 10926 | public: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10927 | static inline bool get(int value, int bit_position) { |
| 10928 | return (value & (1 << bit_position)) != 0; |
| 10929 | } |
| 10930 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10931 | static inline int set(int value, int bit_position, bool v) { |
| 10932 | if (v) { |
| 10933 | value |= (1 << bit_position); |
| 10934 | } else { |
| 10935 | value &= ~(1 << bit_position); |
| 10936 | } |
| 10937 | return value; |
| 10938 | } |
| 10939 | }; |
| 10940 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10941 | |
| 10942 | } // NOLINT, false-positive due to second-order macros. |
| 10943 | } // NOLINT, false-positive due to second-order macros. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10944 | |
| 10945 | #endif // V8_OBJECTS_H_ |