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 |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 36 | #endif |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 37 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 38 | |
| 39 | // |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 40 | // Most object types in the V8 JavaScript are described in this file. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 41 | // |
| 42 | // Inheritance hierarchy: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 43 | // - Object |
| 44 | // - Smi (immediate small integer) |
| 45 | // - HeapObject (superclass for everything allocated in the heap) |
| 46 | // - JSReceiver (suitable for property access) |
| 47 | // - JSObject |
| 48 | // - JSArray |
| 49 | // - JSArrayBuffer |
| 50 | // - JSArrayBufferView |
| 51 | // - JSTypedArray |
| 52 | // - JSDataView |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 53 | // - JSBoundFunction |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 54 | // - JSCollection |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 55 | // - JSSet |
| 56 | // - JSMap |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 57 | // - JSSetIterator |
| 58 | // - JSMapIterator |
| 59 | // - JSWeakCollection |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 60 | // - JSWeakMap |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 61 | // - JSWeakSet |
| 62 | // - JSRegExp |
| 63 | // - JSFunction |
| 64 | // - JSGeneratorObject |
| 65 | // - JSModule |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 66 | // - JSGlobalObject |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 67 | // - JSGlobalProxy |
| 68 | // - JSValue |
| 69 | // - JSDate |
| 70 | // - JSMessageObject |
| 71 | // - JSProxy |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 72 | // - FixedArrayBase |
| 73 | // - ByteArray |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 74 | // - BytecodeArray |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 75 | // - FixedArray |
| 76 | // - DescriptorArray |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 77 | // - LiteralsArray |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 78 | // - HashTable |
| 79 | // - Dictionary |
| 80 | // - StringTable |
| 81 | // - CompilationCacheTable |
| 82 | // - CodeCacheHashTable |
| 83 | // - MapCache |
| 84 | // - OrderedHashTable |
| 85 | // - OrderedHashSet |
| 86 | // - OrderedHashMap |
| 87 | // - Context |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 88 | // - TypeFeedbackMetadata |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 89 | // - TypeFeedbackVector |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 90 | // - ScopeInfo |
| 91 | // - TransitionArray |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 92 | // - ScriptContextTable |
| 93 | // - WeakFixedArray |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 94 | // - FixedDoubleArray |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 95 | // - Name |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 96 | // - String |
| 97 | // - SeqString |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 98 | // - SeqOneByteString |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 99 | // - SeqTwoByteString |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 100 | // - SlicedString |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 101 | // - ConsString |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 102 | // - ExternalString |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 103 | // - ExternalOneByteString |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 104 | // - ExternalTwoByteString |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 105 | // - InternalizedString |
| 106 | // - SeqInternalizedString |
| 107 | // - SeqOneByteInternalizedString |
| 108 | // - SeqTwoByteInternalizedString |
| 109 | // - ConsInternalizedString |
| 110 | // - ExternalInternalizedString |
| 111 | // - ExternalOneByteInternalizedString |
| 112 | // - ExternalTwoByteInternalizedString |
| 113 | // - Symbol |
| 114 | // - HeapNumber |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 115 | // - Simd128Value |
| 116 | // - Float32x4 |
| 117 | // - Int32x4 |
| 118 | // - Uint32x4 |
| 119 | // - Bool32x4 |
| 120 | // - Int16x8 |
| 121 | // - Uint16x8 |
| 122 | // - Bool16x8 |
| 123 | // - Int8x16 |
| 124 | // - Uint8x16 |
| 125 | // - Bool8x16 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 126 | // - Cell |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 127 | // - PropertyCell |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 128 | // - Code |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 129 | // - AbstractCode, a wrapper around Code or BytecodeArray |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 130 | // - Map |
| 131 | // - Oddball |
| 132 | // - Foreign |
| 133 | // - SharedFunctionInfo |
| 134 | // - Struct |
| 135 | // - Box |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 136 | // - AccessorInfo |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 137 | // - AccessorPair |
| 138 | // - AccessCheckInfo |
| 139 | // - InterceptorInfo |
| 140 | // - CallHandlerInfo |
| 141 | // - TemplateInfo |
| 142 | // - FunctionTemplateInfo |
| 143 | // - ObjectTemplateInfo |
| 144 | // - Script |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 145 | // - DebugInfo |
| 146 | // - BreakPointInfo |
| 147 | // - CodeCache |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 148 | // - PrototypeInfo |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 149 | // - WeakCell |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 150 | // |
| 151 | // Formats of Object*: |
| 152 | // Smi: [31 bit signed int] 0 |
| 153 | // HeapObject: [32 bit direct pointer] (4 byte aligned) | 01 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 154 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 155 | namespace v8 { |
| 156 | namespace internal { |
| 157 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 158 | enum KeyedAccessStoreMode { |
| 159 | STANDARD_STORE, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 160 | STORE_TRANSITION_TO_OBJECT, |
| 161 | STORE_TRANSITION_TO_DOUBLE, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 162 | STORE_AND_GROW_NO_TRANSITION, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 163 | STORE_AND_GROW_TRANSITION_TO_OBJECT, |
| 164 | STORE_AND_GROW_TRANSITION_TO_DOUBLE, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 165 | STORE_NO_TRANSITION_IGNORE_OUT_OF_BOUNDS, |
| 166 | STORE_NO_TRANSITION_HANDLE_COW |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 167 | }; |
| 168 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 169 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 170 | // Valid hints for the abstract operation ToPrimitive, |
| 171 | // implemented according to ES6, section 7.1.1. |
| 172 | enum class ToPrimitiveHint { kDefault, kNumber, kString }; |
| 173 | |
| 174 | |
| 175 | // Valid hints for the abstract operation OrdinaryToPrimitive, |
| 176 | // implemented according to ES6, section 7.1.1. |
| 177 | enum class OrdinaryToPrimitiveHint { kNumber, kString }; |
| 178 | |
| 179 | |
| 180 | enum TypeofMode : int { INSIDE_TYPEOF, NOT_INSIDE_TYPEOF }; |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 181 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 182 | |
| 183 | enum MutableMode { |
| 184 | MUTABLE, |
| 185 | IMMUTABLE |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 186 | }; |
| 187 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 188 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 189 | enum ExternalArrayType { |
| 190 | kExternalInt8Array = 1, |
| 191 | kExternalUint8Array, |
| 192 | kExternalInt16Array, |
| 193 | kExternalUint16Array, |
| 194 | kExternalInt32Array, |
| 195 | kExternalUint32Array, |
| 196 | kExternalFloat32Array, |
| 197 | kExternalFloat64Array, |
| 198 | kExternalUint8ClampedArray, |
| 199 | }; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 200 | |
| 201 | |
| 202 | static inline bool IsTransitionStoreMode(KeyedAccessStoreMode store_mode) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 203 | return store_mode == STORE_TRANSITION_TO_OBJECT || |
| 204 | store_mode == STORE_TRANSITION_TO_DOUBLE || |
| 205 | store_mode == STORE_AND_GROW_TRANSITION_TO_OBJECT || |
| 206 | store_mode == STORE_AND_GROW_TRANSITION_TO_DOUBLE; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | |
| 210 | static inline KeyedAccessStoreMode GetNonTransitioningStoreMode( |
| 211 | KeyedAccessStoreMode store_mode) { |
| 212 | if (store_mode >= STORE_NO_TRANSITION_IGNORE_OUT_OF_BOUNDS) { |
| 213 | return store_mode; |
| 214 | } |
| 215 | if (store_mode >= STORE_AND_GROW_NO_TRANSITION) { |
| 216 | return STORE_AND_GROW_NO_TRANSITION; |
| 217 | } |
| 218 | return STANDARD_STORE; |
| 219 | } |
| 220 | |
| 221 | |
| 222 | static inline bool IsGrowStoreMode(KeyedAccessStoreMode store_mode) { |
| 223 | return store_mode >= STORE_AND_GROW_NO_TRANSITION && |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 224 | store_mode <= STORE_AND_GROW_TRANSITION_TO_DOUBLE; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 225 | } |
| 226 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 227 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 228 | enum IcCheckType { ELEMENT, PROPERTY }; |
| 229 | |
| 230 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 231 | // SKIP_WRITE_BARRIER skips the write barrier. |
| 232 | // UPDATE_WEAK_WRITE_BARRIER skips the marking part of the write barrier and |
| 233 | // only performs the generational part. |
| 234 | // UPDATE_WRITE_BARRIER is doing the full barrier, marking and generational. |
| 235 | enum WriteBarrierMode { |
| 236 | SKIP_WRITE_BARRIER, |
| 237 | UPDATE_WEAK_WRITE_BARRIER, |
| 238 | UPDATE_WRITE_BARRIER |
| 239 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 240 | |
| 241 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 242 | // Indicates whether a value can be loaded as a constant. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 243 | enum StoreMode { ALLOW_IN_DESCRIPTOR, FORCE_FIELD }; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 244 | |
| 245 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 246 | // PropertyNormalizationMode is used to specify whether to keep |
| 247 | // inobject properties when normalizing properties of a JSObject. |
| 248 | enum PropertyNormalizationMode { |
| 249 | CLEAR_INOBJECT_PROPERTIES, |
| 250 | KEEP_INOBJECT_PROPERTIES |
| 251 | }; |
| 252 | |
| 253 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 254 | // Indicates how aggressively the prototype should be optimized. FAST_PROTOTYPE |
| 255 | // will give the fastest result by tailoring the map to the prototype, but that |
| 256 | // will cause polymorphism with other objects. REGULAR_PROTOTYPE is to be used |
| 257 | // (at least for now) when dynamically modifying the prototype chain of an |
| 258 | // object using __proto__ or Object.setPrototypeOf. |
| 259 | enum PrototypeOptimizationMode { REGULAR_PROTOTYPE, FAST_PROTOTYPE }; |
| 260 | |
| 261 | |
| 262 | // Indicates whether transitions can be added to a source map or not. |
| 263 | enum TransitionFlag { |
| 264 | INSERT_TRANSITION, |
| 265 | OMIT_TRANSITION |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 266 | }; |
| 267 | |
| 268 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 269 | // Indicates whether the transition is simple: the target map of the transition |
| 270 | // either extends the current map with a new property, or it modifies the |
| 271 | // property that was added last to the current map. |
| 272 | enum SimpleTransitionFlag { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 273 | SIMPLE_PROPERTY_TRANSITION, |
| 274 | PROPERTY_TRANSITION, |
| 275 | SPECIAL_TRANSITION |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 276 | }; |
| 277 | |
| 278 | |
| 279 | // Indicates whether we are only interested in the descriptors of a particular |
| 280 | // map, or in all descriptors in the descriptor array. |
| 281 | enum DescriptorFlag { |
| 282 | ALL_DESCRIPTORS, |
| 283 | OWN_DESCRIPTORS |
| 284 | }; |
| 285 | |
| 286 | // The GC maintains a bit of information, the MarkingParity, which toggles |
| 287 | // from odd to even and back every time marking is completed. Incremental |
| 288 | // marking can visit an object twice during a marking phase, so algorithms that |
| 289 | // that piggy-back on marking can use the parity to ensure that they only |
| 290 | // perform an operation on an object once per marking phase: they record the |
| 291 | // MarkingParity when they visit an object, and only re-visit the object when it |
| 292 | // is marked again and the MarkingParity changes. |
| 293 | enum MarkingParity { |
| 294 | NO_MARKING_PARITY, |
| 295 | ODD_MARKING_PARITY, |
| 296 | EVEN_MARKING_PARITY |
| 297 | }; |
| 298 | |
| 299 | // ICs store extra state in a Code object. The default extra state is |
| 300 | // kNoExtraICState. |
| 301 | typedef int ExtraICState; |
| 302 | static const ExtraICState kNoExtraICState = 0; |
| 303 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 304 | // Instance size sentinel for objects of variable size. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 305 | const int kVariableSizeSentinel = 0; |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 306 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 307 | // We may store the unsigned bit field as signed Smi value and do not |
| 308 | // use the sign bit. |
| 309 | const int kStubMajorKeyBits = 7; |
| 310 | const int kStubMinorKeyBits = kSmiValueSize - kStubMajorKeyBits - 1; |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 311 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 312 | // All Maps have a field instance_type containing a InstanceType. |
| 313 | // It describes the type of the instances. |
| 314 | // |
| 315 | // As an example, a JavaScript object is a heap object and its map |
| 316 | // instance_type is JS_OBJECT_TYPE. |
| 317 | // |
| 318 | // The names of the string instance types are intended to systematically |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 319 | // 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] | 320 | // 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] | 321 | // encoding is mentioned explicitly in the name. Likewise, the default |
| 322 | // representation is considered sequential. It is not mentioned in the |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 323 | // name. The other representations (e.g. CONS, EXTERNAL) are explicitly |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 324 | // mentioned. Finally, the string is either a STRING_TYPE (if it is a normal |
| 325 | // string) or a INTERNALIZED_STRING_TYPE (if it is a internalized string). |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 326 | // |
| 327 | // NOTE: The following things are some that depend on the string types having |
| 328 | // instance_types that are less than those of all other types: |
| 329 | // HeapObject::Size, HeapObject::IterateBody, the typeof operator, and |
| 330 | // Object::IsString. |
| 331 | // |
| 332 | // NOTE: Everything following JS_VALUE_TYPE is considered a |
| 333 | // JSObject for GC purposes. The first four entries here have typeof |
| 334 | // 'object', whereas JS_FUNCTION_TYPE has typeof 'function'. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 335 | #define INSTANCE_TYPE_LIST(V) \ |
| 336 | V(STRING_TYPE) \ |
| 337 | V(ONE_BYTE_STRING_TYPE) \ |
| 338 | V(CONS_STRING_TYPE) \ |
| 339 | V(CONS_ONE_BYTE_STRING_TYPE) \ |
| 340 | V(SLICED_STRING_TYPE) \ |
| 341 | V(SLICED_ONE_BYTE_STRING_TYPE) \ |
| 342 | V(EXTERNAL_STRING_TYPE) \ |
| 343 | V(EXTERNAL_ONE_BYTE_STRING_TYPE) \ |
| 344 | V(EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE) \ |
| 345 | V(SHORT_EXTERNAL_STRING_TYPE) \ |
| 346 | V(SHORT_EXTERNAL_ONE_BYTE_STRING_TYPE) \ |
| 347 | V(SHORT_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE) \ |
| 348 | \ |
| 349 | V(INTERNALIZED_STRING_TYPE) \ |
| 350 | V(ONE_BYTE_INTERNALIZED_STRING_TYPE) \ |
| 351 | V(EXTERNAL_INTERNALIZED_STRING_TYPE) \ |
| 352 | V(EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE) \ |
| 353 | V(EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE) \ |
| 354 | V(SHORT_EXTERNAL_INTERNALIZED_STRING_TYPE) \ |
| 355 | V(SHORT_EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE) \ |
| 356 | V(SHORT_EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE) \ |
| 357 | \ |
| 358 | V(SYMBOL_TYPE) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 359 | V(SIMD128_VALUE_TYPE) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 360 | \ |
| 361 | V(MAP_TYPE) \ |
| 362 | V(CODE_TYPE) \ |
| 363 | V(ODDBALL_TYPE) \ |
| 364 | V(CELL_TYPE) \ |
| 365 | V(PROPERTY_CELL_TYPE) \ |
| 366 | \ |
| 367 | V(HEAP_NUMBER_TYPE) \ |
| 368 | V(MUTABLE_HEAP_NUMBER_TYPE) \ |
| 369 | V(FOREIGN_TYPE) \ |
| 370 | V(BYTE_ARRAY_TYPE) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 371 | V(BYTECODE_ARRAY_TYPE) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 372 | V(FREE_SPACE_TYPE) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 373 | \ |
| 374 | V(FIXED_INT8_ARRAY_TYPE) \ |
| 375 | V(FIXED_UINT8_ARRAY_TYPE) \ |
| 376 | V(FIXED_INT16_ARRAY_TYPE) \ |
| 377 | V(FIXED_UINT16_ARRAY_TYPE) \ |
| 378 | V(FIXED_INT32_ARRAY_TYPE) \ |
| 379 | V(FIXED_UINT32_ARRAY_TYPE) \ |
| 380 | V(FIXED_FLOAT32_ARRAY_TYPE) \ |
| 381 | V(FIXED_FLOAT64_ARRAY_TYPE) \ |
| 382 | V(FIXED_UINT8_CLAMPED_ARRAY_TYPE) \ |
| 383 | \ |
| 384 | V(FILLER_TYPE) \ |
| 385 | \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 386 | V(ACCESSOR_INFO_TYPE) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 387 | V(ACCESSOR_PAIR_TYPE) \ |
| 388 | V(ACCESS_CHECK_INFO_TYPE) \ |
| 389 | V(INTERCEPTOR_INFO_TYPE) \ |
| 390 | V(CALL_HANDLER_INFO_TYPE) \ |
| 391 | V(FUNCTION_TEMPLATE_INFO_TYPE) \ |
| 392 | V(OBJECT_TEMPLATE_INFO_TYPE) \ |
| 393 | V(SIGNATURE_INFO_TYPE) \ |
| 394 | V(TYPE_SWITCH_INFO_TYPE) \ |
| 395 | V(ALLOCATION_MEMENTO_TYPE) \ |
| 396 | V(ALLOCATION_SITE_TYPE) \ |
| 397 | V(SCRIPT_TYPE) \ |
| 398 | V(CODE_CACHE_TYPE) \ |
| 399 | V(POLYMORPHIC_CODE_CACHE_TYPE) \ |
| 400 | V(TYPE_FEEDBACK_INFO_TYPE) \ |
| 401 | V(ALIASED_ARGUMENTS_ENTRY_TYPE) \ |
| 402 | V(BOX_TYPE) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 403 | V(PROTOTYPE_INFO_TYPE) \ |
| 404 | V(SLOPPY_BLOCK_WITH_EVAL_CONTEXT_EXTENSION_TYPE) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 405 | \ |
| 406 | V(FIXED_ARRAY_TYPE) \ |
| 407 | V(FIXED_DOUBLE_ARRAY_TYPE) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 408 | V(SHARED_FUNCTION_INFO_TYPE) \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 409 | V(WEAK_CELL_TYPE) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 410 | V(TRANSITION_ARRAY_TYPE) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 411 | \ |
| 412 | V(JS_MESSAGE_OBJECT_TYPE) \ |
| 413 | \ |
| 414 | V(JS_VALUE_TYPE) \ |
| 415 | V(JS_DATE_TYPE) \ |
| 416 | V(JS_OBJECT_TYPE) \ |
| 417 | V(JS_CONTEXT_EXTENSION_OBJECT_TYPE) \ |
| 418 | V(JS_GENERATOR_OBJECT_TYPE) \ |
| 419 | V(JS_MODULE_TYPE) \ |
| 420 | V(JS_GLOBAL_OBJECT_TYPE) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 421 | V(JS_GLOBAL_PROXY_TYPE) \ |
| 422 | V(JS_ARRAY_TYPE) \ |
| 423 | V(JS_ARRAY_BUFFER_TYPE) \ |
| 424 | V(JS_TYPED_ARRAY_TYPE) \ |
| 425 | V(JS_DATA_VIEW_TYPE) \ |
| 426 | V(JS_PROXY_TYPE) \ |
| 427 | V(JS_SET_TYPE) \ |
| 428 | V(JS_MAP_TYPE) \ |
| 429 | V(JS_SET_ITERATOR_TYPE) \ |
| 430 | V(JS_MAP_ITERATOR_TYPE) \ |
| 431 | V(JS_WEAK_MAP_TYPE) \ |
| 432 | V(JS_WEAK_SET_TYPE) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 433 | V(JS_PROMISE_TYPE) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 434 | V(JS_REGEXP_TYPE) \ |
| 435 | \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 436 | V(JS_BOUND_FUNCTION_TYPE) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 437 | V(JS_FUNCTION_TYPE) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 438 | V(DEBUG_INFO_TYPE) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 439 | V(BREAK_POINT_INFO_TYPE) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 440 | |
| 441 | |
| 442 | // Since string types are not consecutive, this macro is used to |
| 443 | // iterate over them. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 444 | #define STRING_TYPE_LIST(V) \ |
| 445 | V(STRING_TYPE, kVariableSizeSentinel, string, String) \ |
| 446 | V(ONE_BYTE_STRING_TYPE, kVariableSizeSentinel, one_byte_string, \ |
| 447 | OneByteString) \ |
| 448 | V(CONS_STRING_TYPE, ConsString::kSize, cons_string, ConsString) \ |
| 449 | V(CONS_ONE_BYTE_STRING_TYPE, ConsString::kSize, cons_one_byte_string, \ |
| 450 | ConsOneByteString) \ |
| 451 | V(SLICED_STRING_TYPE, SlicedString::kSize, sliced_string, SlicedString) \ |
| 452 | V(SLICED_ONE_BYTE_STRING_TYPE, SlicedString::kSize, sliced_one_byte_string, \ |
| 453 | SlicedOneByteString) \ |
| 454 | V(EXTERNAL_STRING_TYPE, ExternalTwoByteString::kSize, external_string, \ |
| 455 | ExternalString) \ |
| 456 | V(EXTERNAL_ONE_BYTE_STRING_TYPE, ExternalOneByteString::kSize, \ |
| 457 | external_one_byte_string, ExternalOneByteString) \ |
| 458 | V(EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE, ExternalTwoByteString::kSize, \ |
| 459 | external_string_with_one_byte_data, ExternalStringWithOneByteData) \ |
| 460 | V(SHORT_EXTERNAL_STRING_TYPE, ExternalTwoByteString::kShortSize, \ |
| 461 | short_external_string, ShortExternalString) \ |
| 462 | V(SHORT_EXTERNAL_ONE_BYTE_STRING_TYPE, ExternalOneByteString::kShortSize, \ |
| 463 | short_external_one_byte_string, ShortExternalOneByteString) \ |
| 464 | V(SHORT_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE, \ |
| 465 | ExternalTwoByteString::kShortSize, \ |
| 466 | short_external_string_with_one_byte_data, \ |
| 467 | ShortExternalStringWithOneByteData) \ |
| 468 | \ |
| 469 | V(INTERNALIZED_STRING_TYPE, kVariableSizeSentinel, internalized_string, \ |
| 470 | InternalizedString) \ |
| 471 | V(ONE_BYTE_INTERNALIZED_STRING_TYPE, kVariableSizeSentinel, \ |
| 472 | one_byte_internalized_string, OneByteInternalizedString) \ |
| 473 | V(EXTERNAL_INTERNALIZED_STRING_TYPE, ExternalTwoByteString::kSize, \ |
| 474 | external_internalized_string, ExternalInternalizedString) \ |
| 475 | V(EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE, ExternalOneByteString::kSize, \ |
| 476 | external_one_byte_internalized_string, ExternalOneByteInternalizedString) \ |
| 477 | V(EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE, \ |
| 478 | ExternalTwoByteString::kSize, \ |
| 479 | external_internalized_string_with_one_byte_data, \ |
| 480 | ExternalInternalizedStringWithOneByteData) \ |
| 481 | V(SHORT_EXTERNAL_INTERNALIZED_STRING_TYPE, \ |
| 482 | ExternalTwoByteString::kShortSize, short_external_internalized_string, \ |
| 483 | ShortExternalInternalizedString) \ |
| 484 | V(SHORT_EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE, \ |
| 485 | ExternalOneByteString::kShortSize, \ |
| 486 | short_external_one_byte_internalized_string, \ |
| 487 | ShortExternalOneByteInternalizedString) \ |
| 488 | V(SHORT_EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE, \ |
| 489 | ExternalTwoByteString::kShortSize, \ |
| 490 | short_external_internalized_string_with_one_byte_data, \ |
| 491 | ShortExternalInternalizedStringWithOneByteData) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 492 | |
| 493 | // A struct is a simple object a set of object-valued fields. Including an |
| 494 | // object type in this causes the compiler to generate most of the boilerplate |
| 495 | // code for the class including allocation and garbage collection routines, |
| 496 | // casts and predicates. All you need to define is the class, methods and |
| 497 | // object verification routines. Easy, no? |
| 498 | // |
| 499 | // Note that for subtle reasons related to the ordering or numerical values of |
| 500 | // type tags, elements in this list have to be added to the INSTANCE_TYPE_LIST |
| 501 | // manually. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 502 | #define STRUCT_LIST(V) \ |
| 503 | V(BOX, Box, box) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 504 | V(ACCESSOR_INFO, AccessorInfo, accessor_info) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 505 | V(ACCESSOR_PAIR, AccessorPair, accessor_pair) \ |
| 506 | V(ACCESS_CHECK_INFO, AccessCheckInfo, access_check_info) \ |
| 507 | V(INTERCEPTOR_INFO, InterceptorInfo, interceptor_info) \ |
| 508 | V(CALL_HANDLER_INFO, CallHandlerInfo, call_handler_info) \ |
| 509 | V(FUNCTION_TEMPLATE_INFO, FunctionTemplateInfo, function_template_info) \ |
| 510 | V(OBJECT_TEMPLATE_INFO, ObjectTemplateInfo, object_template_info) \ |
| 511 | V(SCRIPT, Script, script) \ |
| 512 | V(ALLOCATION_SITE, AllocationSite, allocation_site) \ |
| 513 | V(ALLOCATION_MEMENTO, AllocationMemento, allocation_memento) \ |
| 514 | V(CODE_CACHE, CodeCache, code_cache) \ |
| 515 | V(POLYMORPHIC_CODE_CACHE, PolymorphicCodeCache, polymorphic_code_cache) \ |
| 516 | V(TYPE_FEEDBACK_INFO, TypeFeedbackInfo, type_feedback_info) \ |
| 517 | V(ALIASED_ARGUMENTS_ENTRY, AliasedArgumentsEntry, aliased_arguments_entry) \ |
| 518 | V(DEBUG_INFO, DebugInfo, debug_info) \ |
| 519 | V(BREAK_POINT_INFO, BreakPointInfo, break_point_info) \ |
| 520 | V(PROTOTYPE_INFO, PrototypeInfo, prototype_info) \ |
| 521 | V(SLOPPY_BLOCK_WITH_EVAL_CONTEXT_EXTENSION, \ |
| 522 | SloppyBlockWithEvalContextExtension, \ |
| 523 | sloppy_block_with_eval_context_extension) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 524 | |
| 525 | // We use the full 8 bits of the instance_type field to encode heap object |
| 526 | // instance types. The high-order bit (bit 7) is set if the object is not a |
| 527 | // string, and cleared if it is a string. |
| 528 | const uint32_t kIsNotStringMask = 0x80; |
| 529 | const uint32_t kStringTag = 0x0; |
| 530 | const uint32_t kNotStringTag = 0x80; |
| 531 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 532 | // Bit 6 indicates that the object is an internalized string (if set) or not. |
| 533 | // Bit 7 has to be clear as well. |
| 534 | const uint32_t kIsNotInternalizedMask = 0x40; |
| 535 | const uint32_t kNotInternalizedTag = 0x40; |
| 536 | const uint32_t kInternalizedTag = 0x0; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 537 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 538 | // If bit 7 is clear then bit 2 indicates whether the string consists of |
| 539 | // two-byte characters or one-byte characters. |
| 540 | const uint32_t kStringEncodingMask = 0x4; |
| 541 | const uint32_t kTwoByteStringTag = 0x0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 542 | const uint32_t kOneByteStringTag = 0x4; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 543 | |
| 544 | // If bit 7 is clear, the low-order 2 bits indicate the representation |
| 545 | // of the string. |
| 546 | const uint32_t kStringRepresentationMask = 0x03; |
| 547 | enum StringRepresentationTag { |
| 548 | kSeqStringTag = 0x0, |
| 549 | kConsStringTag = 0x1, |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 550 | kExternalStringTag = 0x2, |
| 551 | kSlicedStringTag = 0x3 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 552 | }; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 553 | const uint32_t kIsIndirectStringMask = 0x1; |
| 554 | const uint32_t kIsIndirectStringTag = 0x1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 555 | STATIC_ASSERT((kSeqStringTag & kIsIndirectStringMask) == 0); // NOLINT |
| 556 | STATIC_ASSERT((kExternalStringTag & kIsIndirectStringMask) == 0); // NOLINT |
| 557 | STATIC_ASSERT((kConsStringTag & |
| 558 | kIsIndirectStringMask) == kIsIndirectStringTag); // NOLINT |
| 559 | STATIC_ASSERT((kSlicedStringTag & |
| 560 | kIsIndirectStringMask) == kIsIndirectStringTag); // NOLINT |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 561 | |
| 562 | // Use this mask to distinguish between cons and slice only after making |
| 563 | // sure that the string is one of the two (an indirect string). |
| 564 | const uint32_t kSlicedNotConsMask = kSlicedStringTag & ~kConsStringTag; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 565 | STATIC_ASSERT(IS_POWER_OF_TWO(kSlicedNotConsMask)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 566 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 567 | // If bit 7 is clear, then bit 3 indicates whether this two-byte |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 568 | // string actually contains one byte data. |
| 569 | const uint32_t kOneByteDataHintMask = 0x08; |
| 570 | const uint32_t kOneByteDataHintTag = 0x08; |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 571 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 572 | // If bit 7 is clear and string representation indicates an external string, |
| 573 | // then bit 4 indicates whether the data pointer is cached. |
| 574 | const uint32_t kShortExternalStringMask = 0x10; |
| 575 | const uint32_t kShortExternalStringTag = 0x10; |
| 576 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 577 | |
| 578 | // A ConsString with an empty string as the right side is a candidate |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 579 | // for being shortcut by the garbage collector. We don't allocate any |
| 580 | // non-flat internalized strings, so we do not shortcut them thereby |
| 581 | // avoiding turning internalized strings into strings. The bit-masks |
| 582 | // below contain the internalized bit as additional safety. |
| 583 | // See heap.cc, mark-compact.cc and objects-visiting.cc. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 584 | const uint32_t kShortcutTypeMask = |
| 585 | kIsNotStringMask | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 586 | kIsNotInternalizedMask | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 587 | kStringRepresentationMask; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 588 | const uint32_t kShortcutTypeTag = kConsStringTag | kNotInternalizedTag; |
| 589 | |
| 590 | static inline bool IsShortcutCandidate(int type) { |
| 591 | return ((type & kShortcutTypeMask) == kShortcutTypeTag); |
| 592 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 593 | |
| 594 | |
| 595 | enum InstanceType { |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 596 | // String types. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 597 | INTERNALIZED_STRING_TYPE = kTwoByteStringTag | kSeqStringTag | |
| 598 | kInternalizedTag, // FIRST_PRIMITIVE_TYPE |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 599 | ONE_BYTE_INTERNALIZED_STRING_TYPE = |
| 600 | kOneByteStringTag | kSeqStringTag | kInternalizedTag, |
| 601 | EXTERNAL_INTERNALIZED_STRING_TYPE = |
| 602 | kTwoByteStringTag | kExternalStringTag | kInternalizedTag, |
| 603 | EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE = |
| 604 | kOneByteStringTag | kExternalStringTag | kInternalizedTag, |
| 605 | EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE = |
| 606 | EXTERNAL_INTERNALIZED_STRING_TYPE | kOneByteDataHintTag | |
| 607 | kInternalizedTag, |
| 608 | SHORT_EXTERNAL_INTERNALIZED_STRING_TYPE = EXTERNAL_INTERNALIZED_STRING_TYPE | |
| 609 | kShortExternalStringTag | |
| 610 | kInternalizedTag, |
| 611 | SHORT_EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE = |
| 612 | EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE | kShortExternalStringTag | |
| 613 | kInternalizedTag, |
| 614 | SHORT_EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE = |
| 615 | EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE | |
| 616 | kShortExternalStringTag | kInternalizedTag, |
| 617 | STRING_TYPE = INTERNALIZED_STRING_TYPE | kNotInternalizedTag, |
| 618 | ONE_BYTE_STRING_TYPE = |
| 619 | ONE_BYTE_INTERNALIZED_STRING_TYPE | kNotInternalizedTag, |
| 620 | CONS_STRING_TYPE = kTwoByteStringTag | kConsStringTag | kNotInternalizedTag, |
| 621 | CONS_ONE_BYTE_STRING_TYPE = |
| 622 | kOneByteStringTag | kConsStringTag | kNotInternalizedTag, |
| 623 | SLICED_STRING_TYPE = |
| 624 | kTwoByteStringTag | kSlicedStringTag | kNotInternalizedTag, |
| 625 | SLICED_ONE_BYTE_STRING_TYPE = |
| 626 | kOneByteStringTag | kSlicedStringTag | kNotInternalizedTag, |
| 627 | EXTERNAL_STRING_TYPE = |
| 628 | EXTERNAL_INTERNALIZED_STRING_TYPE | kNotInternalizedTag, |
| 629 | EXTERNAL_ONE_BYTE_STRING_TYPE = |
| 630 | EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE | kNotInternalizedTag, |
| 631 | EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE = |
| 632 | EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE | |
| 633 | kNotInternalizedTag, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 634 | SHORT_EXTERNAL_STRING_TYPE = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 635 | SHORT_EXTERNAL_INTERNALIZED_STRING_TYPE | kNotInternalizedTag, |
| 636 | SHORT_EXTERNAL_ONE_BYTE_STRING_TYPE = |
| 637 | SHORT_EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE | kNotInternalizedTag, |
| 638 | SHORT_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE = |
| 639 | SHORT_EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE | |
| 640 | kNotInternalizedTag, |
| 641 | |
| 642 | // Non-string names |
| 643 | SYMBOL_TYPE = kNotStringTag, // FIRST_NONSTRING_TYPE, LAST_NAME_TYPE |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 644 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 645 | // Other primitives (cannot contain non-map-word pointers to heap objects). |
| 646 | HEAP_NUMBER_TYPE, |
| 647 | SIMD128_VALUE_TYPE, |
| 648 | ODDBALL_TYPE, // LAST_PRIMITIVE_TYPE |
| 649 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 650 | // Objects allocated in their own spaces (never in new space). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 651 | MAP_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 652 | CODE_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 653 | |
| 654 | // "Data", objects that cannot contain non-map-word pointers to heap |
| 655 | // objects. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 656 | MUTABLE_HEAP_NUMBER_TYPE, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 657 | FOREIGN_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 658 | BYTE_ARRAY_TYPE, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 659 | BYTECODE_ARRAY_TYPE, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 660 | FREE_SPACE_TYPE, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 661 | FIXED_INT8_ARRAY_TYPE, // FIRST_FIXED_TYPED_ARRAY_TYPE |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 662 | FIXED_UINT8_ARRAY_TYPE, |
| 663 | FIXED_INT16_ARRAY_TYPE, |
| 664 | FIXED_UINT16_ARRAY_TYPE, |
| 665 | FIXED_INT32_ARRAY_TYPE, |
| 666 | FIXED_UINT32_ARRAY_TYPE, |
| 667 | FIXED_FLOAT32_ARRAY_TYPE, |
| 668 | FIXED_FLOAT64_ARRAY_TYPE, |
| 669 | FIXED_UINT8_CLAMPED_ARRAY_TYPE, // LAST_FIXED_TYPED_ARRAY_TYPE |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 670 | FIXED_DOUBLE_ARRAY_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 671 | FILLER_TYPE, // LAST_DATA_TYPE |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 672 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 673 | // Structs. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 674 | ACCESSOR_INFO_TYPE, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 675 | ACCESSOR_PAIR_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 676 | ACCESS_CHECK_INFO_TYPE, |
| 677 | INTERCEPTOR_INFO_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 678 | CALL_HANDLER_INFO_TYPE, |
| 679 | FUNCTION_TEMPLATE_INFO_TYPE, |
| 680 | OBJECT_TEMPLATE_INFO_TYPE, |
| 681 | SIGNATURE_INFO_TYPE, |
| 682 | TYPE_SWITCH_INFO_TYPE, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 683 | ALLOCATION_SITE_TYPE, |
| 684 | ALLOCATION_MEMENTO_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 685 | SCRIPT_TYPE, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 686 | CODE_CACHE_TYPE, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 687 | POLYMORPHIC_CODE_CACHE_TYPE, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 688 | TYPE_FEEDBACK_INFO_TYPE, |
| 689 | ALIASED_ARGUMENTS_ENTRY_TYPE, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 690 | BOX_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 691 | DEBUG_INFO_TYPE, |
| 692 | BREAK_POINT_INFO_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 693 | FIXED_ARRAY_TYPE, |
| 694 | SHARED_FUNCTION_INFO_TYPE, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 695 | CELL_TYPE, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 696 | WEAK_CELL_TYPE, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 697 | TRANSITION_ARRAY_TYPE, |
| 698 | PROPERTY_CELL_TYPE, |
| 699 | PROTOTYPE_INFO_TYPE, |
| 700 | SLOPPY_BLOCK_WITH_EVAL_CONTEXT_EXTENSION_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 701 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 702 | // All the following types are subtypes of JSReceiver, which corresponds to |
| 703 | // objects in the JS sense. The first and the last type in this range are |
| 704 | // the two forms of function. This organization enables using the same |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 705 | // compares for checking the JS_RECEIVER and the NONCALLABLE_JS_OBJECT range. |
| 706 | JS_PROXY_TYPE, // FIRST_JS_RECEIVER_TYPE |
| 707 | JS_VALUE_TYPE, // FIRST_JS_OBJECT_TYPE |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 708 | JS_MESSAGE_OBJECT_TYPE, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 709 | JS_DATE_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 710 | JS_OBJECT_TYPE, |
| 711 | JS_CONTEXT_EXTENSION_OBJECT_TYPE, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 712 | JS_GENERATOR_OBJECT_TYPE, |
| 713 | JS_MODULE_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 714 | JS_GLOBAL_OBJECT_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 715 | JS_GLOBAL_PROXY_TYPE, |
| 716 | JS_ARRAY_TYPE, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 717 | JS_ARRAY_BUFFER_TYPE, |
| 718 | JS_TYPED_ARRAY_TYPE, |
| 719 | JS_DATA_VIEW_TYPE, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 720 | JS_SET_TYPE, |
| 721 | JS_MAP_TYPE, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 722 | JS_SET_ITERATOR_TYPE, |
| 723 | JS_MAP_ITERATOR_TYPE, |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 724 | JS_WEAK_MAP_TYPE, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 725 | JS_WEAK_SET_TYPE, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 726 | JS_PROMISE_TYPE, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 727 | JS_REGEXP_TYPE, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 728 | JS_BOUND_FUNCTION_TYPE, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 729 | JS_FUNCTION_TYPE, // LAST_JS_OBJECT_TYPE, LAST_JS_RECEIVER_TYPE |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 730 | |
| 731 | // Pseudo-types |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 732 | FIRST_TYPE = 0x0, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 733 | LAST_TYPE = JS_FUNCTION_TYPE, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 734 | FIRST_NAME_TYPE = FIRST_TYPE, |
| 735 | LAST_NAME_TYPE = SYMBOL_TYPE, |
| 736 | FIRST_UNIQUE_NAME_TYPE = INTERNALIZED_STRING_TYPE, |
| 737 | LAST_UNIQUE_NAME_TYPE = SYMBOL_TYPE, |
| 738 | FIRST_NONSTRING_TYPE = SYMBOL_TYPE, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 739 | FIRST_PRIMITIVE_TYPE = FIRST_NAME_TYPE, |
| 740 | LAST_PRIMITIVE_TYPE = ODDBALL_TYPE, |
| 741 | FIRST_FUNCTION_TYPE = JS_BOUND_FUNCTION_TYPE, |
| 742 | LAST_FUNCTION_TYPE = JS_FUNCTION_TYPE, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 743 | // Boundaries for testing for a fixed typed array. |
| 744 | FIRST_FIXED_TYPED_ARRAY_TYPE = FIXED_INT8_ARRAY_TYPE, |
| 745 | LAST_FIXED_TYPED_ARRAY_TYPE = FIXED_UINT8_CLAMPED_ARRAY_TYPE, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 746 | // Boundary for promotion to old space. |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 747 | LAST_DATA_TYPE = FILLER_TYPE, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 748 | // Boundary for objects represented as JSReceiver (i.e. JSObject or JSProxy). |
| 749 | // Note that there is no range for JSObject or JSProxy, since their subtypes |
| 750 | // are not continuous in this enum! The enum ranges instead reflect the |
| 751 | // external class names, where proxies are treated as either ordinary objects, |
| 752 | // or functions. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 753 | FIRST_JS_RECEIVER_TYPE = JS_PROXY_TYPE, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 754 | LAST_JS_RECEIVER_TYPE = LAST_TYPE, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 755 | // Boundaries for testing the types represented as JSObject |
| 756 | FIRST_JS_OBJECT_TYPE = JS_VALUE_TYPE, |
| 757 | LAST_JS_OBJECT_TYPE = LAST_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 758 | }; |
| 759 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 760 | STATIC_ASSERT(JS_OBJECT_TYPE == Internals::kJSObjectType); |
| 761 | STATIC_ASSERT(FIRST_NONSTRING_TYPE == Internals::kFirstNonstringType); |
| 762 | STATIC_ASSERT(ODDBALL_TYPE == Internals::kOddballType); |
| 763 | STATIC_ASSERT(FOREIGN_TYPE == Internals::kForeignType); |
| 764 | |
| 765 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 766 | std::ostream& operator<<(std::ostream& os, InstanceType instance_type); |
| 767 | |
| 768 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 769 | #define FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(V) \ |
| 770 | V(FAST_ELEMENTS_SUB_TYPE) \ |
| 771 | V(DICTIONARY_ELEMENTS_SUB_TYPE) \ |
| 772 | V(FAST_PROPERTIES_SUB_TYPE) \ |
| 773 | V(DICTIONARY_PROPERTIES_SUB_TYPE) \ |
| 774 | V(MAP_CODE_CACHE_SUB_TYPE) \ |
| 775 | V(SCOPE_INFO_SUB_TYPE) \ |
| 776 | V(STRING_TABLE_SUB_TYPE) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 777 | V(DESCRIPTOR_ARRAY_SUB_TYPE) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 778 | |
| 779 | enum FixedArraySubInstanceType { |
| 780 | #define DEFINE_FIXED_ARRAY_SUB_INSTANCE_TYPE(name) name, |
| 781 | FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(DEFINE_FIXED_ARRAY_SUB_INSTANCE_TYPE) |
| 782 | #undef DEFINE_FIXED_ARRAY_SUB_INSTANCE_TYPE |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 783 | LAST_FIXED_ARRAY_SUB_TYPE = DESCRIPTOR_ARRAY_SUB_TYPE |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 784 | }; |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 785 | |
| 786 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 787 | // TODO(bmeurer): Remove this in favor of the ComparisonResult below. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 788 | enum CompareResult { |
| 789 | LESS = -1, |
| 790 | EQUAL = 0, |
| 791 | GREATER = 1, |
| 792 | |
| 793 | NOT_EQUAL = GREATER |
| 794 | }; |
| 795 | |
| 796 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 797 | // Result of an abstract relational comparison of x and y, implemented according |
| 798 | // to ES6 section 7.2.11 Abstract Relational Comparison. |
| 799 | enum class ComparisonResult { |
| 800 | kLessThan, // x < y |
| 801 | kEqual, // x = y |
| 802 | kGreaterThan, // x > y |
| 803 | kUndefined // at least one of x or y was undefined or NaN |
| 804 | }; |
| 805 | |
| 806 | |
| 807 | #define DECL_BOOLEAN_ACCESSORS(name) \ |
| 808 | inline bool name() const; \ |
| 809 | inline void set_##name(bool value); |
| 810 | |
| 811 | #define DECL_INT_ACCESSORS(name) \ |
| 812 | inline int name() const; \ |
| 813 | inline void set_##name(int value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 814 | |
| 815 | |
| 816 | #define DECL_ACCESSORS(name, type) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 817 | inline type* name() const; \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 818 | inline void set_##name(type* value, \ |
| 819 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); \ |
| 820 | |
| 821 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 822 | #define DECLARE_CAST(type) \ |
| 823 | INLINE(static type* cast(Object* object)); \ |
| 824 | INLINE(static const type* cast(const Object* object)); |
| 825 | |
| 826 | |
| 827 | class AccessorPair; |
| 828 | class AllocationSite; |
| 829 | class AllocationSiteCreationContext; |
| 830 | class AllocationSiteUsageContext; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 831 | class Cell; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 832 | class ConsString; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 833 | class ElementsAccessor; |
| 834 | class FixedArrayBase; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 835 | class FunctionLiteral; |
| 836 | class JSGlobalObject; |
| 837 | class KeyAccumulator; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 838 | class LayoutDescriptor; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 839 | class LiteralsArray; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 840 | class LookupIterator; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 841 | class FieldType; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 842 | class ObjectHashTable; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 843 | class ObjectVisitor; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 844 | class PropertyCell; |
| 845 | class PropertyDescriptor; |
| 846 | class SafepointEntry; |
| 847 | class SharedFunctionInfo; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 848 | class StringStream; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 849 | class TypeFeedbackInfo; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 850 | class TypeFeedbackVector; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 851 | class WeakCell; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 852 | class TransitionArray; |
| 853 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 854 | |
| 855 | // A template-ized version of the IsXXX functions. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 856 | template <class C> inline bool Is(Object* obj); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 857 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 858 | #ifdef VERIFY_HEAP |
| 859 | #define DECLARE_VERIFIER(Name) void Name##Verify(); |
| 860 | #else |
| 861 | #define DECLARE_VERIFIER(Name) |
| 862 | #endif |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 863 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 864 | #ifdef OBJECT_PRINT |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 865 | #define DECLARE_PRINTER(Name) void Name##Print(std::ostream& os); // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 866 | #else |
| 867 | #define DECLARE_PRINTER(Name) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 868 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 869 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 870 | #define OBJECT_TYPE_LIST(V) \ |
| 871 | V(Smi) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 872 | V(LayoutDescriptor) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 873 | V(HeapObject) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 874 | V(Primitive) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 875 | V(Number) |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 876 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 877 | #define HEAP_OBJECT_TYPE_LIST(V) \ |
| 878 | V(HeapNumber) \ |
| 879 | V(MutableHeapNumber) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 880 | V(Simd128Value) \ |
| 881 | V(Float32x4) \ |
| 882 | V(Int32x4) \ |
| 883 | V(Uint32x4) \ |
| 884 | V(Bool32x4) \ |
| 885 | V(Int16x8) \ |
| 886 | V(Uint16x8) \ |
| 887 | V(Bool16x8) \ |
| 888 | V(Int8x16) \ |
| 889 | V(Uint8x16) \ |
| 890 | V(Bool8x16) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 891 | V(Name) \ |
| 892 | V(UniqueName) \ |
| 893 | V(String) \ |
| 894 | V(SeqString) \ |
| 895 | V(ExternalString) \ |
| 896 | V(ConsString) \ |
| 897 | V(SlicedString) \ |
| 898 | V(ExternalTwoByteString) \ |
| 899 | V(ExternalOneByteString) \ |
| 900 | V(SeqTwoByteString) \ |
| 901 | V(SeqOneByteString) \ |
| 902 | V(InternalizedString) \ |
| 903 | V(Symbol) \ |
| 904 | \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 905 | V(FixedTypedArrayBase) \ |
| 906 | V(FixedUint8Array) \ |
| 907 | V(FixedInt8Array) \ |
| 908 | V(FixedUint16Array) \ |
| 909 | V(FixedInt16Array) \ |
| 910 | V(FixedUint32Array) \ |
| 911 | V(FixedInt32Array) \ |
| 912 | V(FixedFloat32Array) \ |
| 913 | V(FixedFloat64Array) \ |
| 914 | V(FixedUint8ClampedArray) \ |
| 915 | V(ByteArray) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 916 | V(BytecodeArray) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 917 | V(FreeSpace) \ |
| 918 | V(JSReceiver) \ |
| 919 | V(JSObject) \ |
| 920 | V(JSContextExtensionObject) \ |
| 921 | V(JSGeneratorObject) \ |
| 922 | V(JSModule) \ |
| 923 | V(Map) \ |
| 924 | V(DescriptorArray) \ |
| 925 | V(TransitionArray) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 926 | V(LiteralsArray) \ |
| 927 | V(TypeFeedbackMetadata) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 928 | V(TypeFeedbackVector) \ |
| 929 | V(DeoptimizationInputData) \ |
| 930 | V(DeoptimizationOutputData) \ |
| 931 | V(DependentCode) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 932 | V(HandlerTable) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 933 | V(FixedArray) \ |
| 934 | V(FixedDoubleArray) \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 935 | V(WeakFixedArray) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 936 | V(ArrayList) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 937 | V(Context) \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 938 | V(ScriptContextTable) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 939 | V(NativeContext) \ |
| 940 | V(ScopeInfo) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 941 | V(JSBoundFunction) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 942 | V(JSFunction) \ |
| 943 | V(Code) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 944 | V(AbstractCode) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 945 | V(Oddball) \ |
| 946 | V(SharedFunctionInfo) \ |
| 947 | V(JSValue) \ |
| 948 | V(JSDate) \ |
| 949 | V(JSMessageObject) \ |
| 950 | V(StringWrapper) \ |
| 951 | V(Foreign) \ |
| 952 | V(Boolean) \ |
| 953 | V(JSArray) \ |
| 954 | V(JSArrayBuffer) \ |
| 955 | V(JSArrayBufferView) \ |
| 956 | V(JSTypedArray) \ |
| 957 | V(JSDataView) \ |
| 958 | V(JSProxy) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 959 | V(JSSet) \ |
| 960 | V(JSMap) \ |
| 961 | V(JSSetIterator) \ |
| 962 | V(JSMapIterator) \ |
| 963 | V(JSWeakCollection) \ |
| 964 | V(JSWeakMap) \ |
| 965 | V(JSWeakSet) \ |
| 966 | V(JSRegExp) \ |
| 967 | V(HashTable) \ |
| 968 | V(Dictionary) \ |
| 969 | V(StringTable) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 970 | V(NormalizedMapCache) \ |
| 971 | V(CompilationCacheTable) \ |
| 972 | V(CodeCacheHashTable) \ |
| 973 | V(PolymorphicCodeCacheHashTable) \ |
| 974 | V(MapCache) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 975 | V(JSGlobalObject) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 976 | V(JSGlobalProxy) \ |
| 977 | V(UndetectableObject) \ |
| 978 | V(AccessCheckNeeded) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 979 | V(Callable) \ |
| 980 | V(Function) \ |
| 981 | V(Constructor) \ |
| 982 | V(TemplateInfo) \ |
| 983 | V(Filler) \ |
| 984 | V(FixedArrayBase) \ |
| 985 | V(External) \ |
| 986 | V(Struct) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 987 | V(Cell) \ |
| 988 | V(PropertyCell) \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 989 | V(WeakCell) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 990 | V(ObjectHashTable) \ |
| 991 | V(WeakHashTable) \ |
| 992 | V(OrderedHashTable) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 993 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 994 | #define ODDBALL_LIST(V) \ |
| 995 | V(Undefined) \ |
| 996 | V(Null) \ |
| 997 | V(TheHole) \ |
| 998 | V(Exception) \ |
| 999 | V(Uninitialized) \ |
| 1000 | V(True) \ |
| 1001 | V(False) \ |
| 1002 | V(ArgumentsMarker) |
| 1003 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1004 | // The element types selection for CreateListFromArrayLike. |
| 1005 | enum class ElementTypes { kAll, kStringAndSymbol }; |
| 1006 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1007 | // Object is the abstract superclass for all classes in the |
| 1008 | // object hierarchy. |
| 1009 | // Object does not use any virtual functions to avoid the |
| 1010 | // allocation of the C++ vtable. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1011 | // Since both Smi and HeapObject are subclasses of Object no |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1012 | // data members can be present in Object. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1013 | class Object { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1014 | public: |
| 1015 | // Type testing. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1016 | bool IsObject() const { return true; } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1017 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1018 | #define IS_TYPE_FUNCTION_DECL(type_) INLINE(bool Is##type_() const); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1019 | OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL) |
| 1020 | HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL) |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1021 | ODDBALL_LIST(IS_TYPE_FUNCTION_DECL) |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1022 | #undef IS_TYPE_FUNCTION_DECL |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1023 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1024 | // A non-keyed store is of the form a.x = foo or a["x"] = foo whereas |
| 1025 | // a keyed store is of the form a[expression] = foo. |
| 1026 | enum StoreFromKeyed { |
| 1027 | MAY_BE_STORE_FROM_KEYED, |
| 1028 | CERTAINLY_NOT_STORE_FROM_KEYED |
| 1029 | }; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1030 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1031 | enum ShouldThrow { THROW_ON_ERROR, DONT_THROW }; |
| 1032 | |
| 1033 | #define RETURN_FAILURE(isolate, should_throw, call) \ |
| 1034 | do { \ |
| 1035 | if ((should_throw) == DONT_THROW) { \ |
| 1036 | return Just(false); \ |
| 1037 | } else { \ |
| 1038 | isolate->Throw(*isolate->factory()->call); \ |
| 1039 | return Nothing<bool>(); \ |
| 1040 | } \ |
| 1041 | } while (false) |
| 1042 | |
| 1043 | #define MAYBE_RETURN(call, value) \ |
| 1044 | do { \ |
| 1045 | if ((call).IsNothing()) return value; \ |
| 1046 | } while (false) |
| 1047 | |
| 1048 | #define MAYBE_RETURN_NULL(call) MAYBE_RETURN(call, MaybeHandle<Object>()) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1049 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1050 | #define DECLARE_STRUCT_PREDICATE(NAME, Name, name) \ |
| 1051 | INLINE(bool Is##Name() const); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1052 | STRUCT_LIST(DECLARE_STRUCT_PREDICATE) |
| 1053 | #undef DECLARE_STRUCT_PREDICATE |
| 1054 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1055 | // ES6, section 7.2.2 IsArray. NOT to be confused with %_IsArray. |
| 1056 | MUST_USE_RESULT static Maybe<bool> IsArray(Handle<Object> object); |
| 1057 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1058 | INLINE(bool IsNameDictionary() const); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1059 | INLINE(bool IsGlobalDictionary() const); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1060 | INLINE(bool IsSeededNumberDictionary() const); |
| 1061 | INLINE(bool IsUnseededNumberDictionary() const); |
| 1062 | INLINE(bool IsOrderedHashSet() const); |
| 1063 | INLINE(bool IsOrderedHashMap() const); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1064 | static bool IsPromise(Handle<Object> object); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1065 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1066 | // Extract the number. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1067 | inline double Number() const; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1068 | INLINE(bool IsNaN() const); |
| 1069 | INLINE(bool IsMinusZero() const); |
| 1070 | bool ToInt32(int32_t* value); |
| 1071 | bool ToUint32(uint32_t* value); |
| 1072 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1073 | inline Representation OptimalRepresentation(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1074 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1075 | inline ElementsKind OptimalElementsKind(); |
| 1076 | |
| 1077 | inline bool FitsRepresentation(Representation representation); |
| 1078 | |
| 1079 | // Checks whether two valid primitive encodings of a property name resolve to |
| 1080 | // the same logical property. E.g., the smi 1, the string "1" and the double |
| 1081 | // 1 all refer to the same property, so this helper will return true. |
| 1082 | inline bool KeyEquals(Object* other); |
| 1083 | |
| 1084 | inline bool FilterKey(PropertyFilter filter); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1085 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1086 | Handle<FieldType> OptimalType(Isolate* isolate, |
| 1087 | Representation representation); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1088 | |
| 1089 | inline static Handle<Object> NewStorageFor(Isolate* isolate, |
| 1090 | Handle<Object> object, |
| 1091 | Representation representation); |
| 1092 | |
| 1093 | inline static Handle<Object> WrapForRead(Isolate* isolate, |
| 1094 | Handle<Object> object, |
| 1095 | Representation representation); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1096 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1097 | // Returns true if the object is of the correct type to be used as a |
| 1098 | // implementation of a JSObject's elements. |
| 1099 | inline bool HasValidElements(); |
| 1100 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1101 | inline bool HasSpecificClassOf(String* name); |
| 1102 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1103 | bool BooleanValue(); // ECMA-262 9.2. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1104 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1105 | // ES6 section 7.2.11 Abstract Relational Comparison |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1106 | MUST_USE_RESULT static Maybe<ComparisonResult> Compare(Handle<Object> x, |
| 1107 | Handle<Object> y); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1108 | |
| 1109 | // ES6 section 7.2.12 Abstract Equality Comparison |
| 1110 | MUST_USE_RESULT static Maybe<bool> Equals(Handle<Object> x, Handle<Object> y); |
| 1111 | |
| 1112 | // ES6 section 7.2.13 Strict Equality Comparison |
| 1113 | bool StrictEquals(Object* that); |
| 1114 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1115 | // Convert to a JSObject if needed. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1116 | // native_context is used when creating wrapper object. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1117 | MUST_USE_RESULT static inline MaybeHandle<JSReceiver> ToObject( |
| 1118 | Isolate* isolate, Handle<Object> object); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1119 | MUST_USE_RESULT static MaybeHandle<JSReceiver> ToObject( |
| 1120 | Isolate* isolate, Handle<Object> object, Handle<Context> context); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1121 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1122 | // ES6 section 7.1.14 ToPropertyKey |
| 1123 | MUST_USE_RESULT static MaybeHandle<Name> ToName(Isolate* isolate, |
| 1124 | Handle<Object> input); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1125 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1126 | // ES6 section 7.1.1 ToPrimitive |
| 1127 | MUST_USE_RESULT static inline MaybeHandle<Object> ToPrimitive( |
| 1128 | Handle<Object> input, ToPrimitiveHint hint = ToPrimitiveHint::kDefault); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1129 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1130 | // ES6 section 7.1.3 ToNumber |
| 1131 | MUST_USE_RESULT static MaybeHandle<Object> ToNumber(Handle<Object> input); |
| 1132 | |
| 1133 | // ES6 section 7.1.4 ToInteger |
| 1134 | MUST_USE_RESULT static MaybeHandle<Object> ToInteger(Isolate* isolate, |
| 1135 | Handle<Object> input); |
| 1136 | |
| 1137 | // ES6 section 7.1.5 ToInt32 |
| 1138 | MUST_USE_RESULT static MaybeHandle<Object> ToInt32(Isolate* isolate, |
| 1139 | Handle<Object> input); |
| 1140 | |
| 1141 | // ES6 section 7.1.6 ToUint32 |
| 1142 | MUST_USE_RESULT static MaybeHandle<Object> ToUint32(Isolate* isolate, |
| 1143 | Handle<Object> input); |
| 1144 | |
| 1145 | // ES6 section 7.1.12 ToString |
| 1146 | MUST_USE_RESULT static MaybeHandle<String> ToString(Isolate* isolate, |
| 1147 | Handle<Object> input); |
| 1148 | |
| 1149 | // ES6 section 7.1.15 ToLength |
| 1150 | MUST_USE_RESULT static MaybeHandle<Object> ToLength(Isolate* isolate, |
| 1151 | Handle<Object> input); |
| 1152 | |
| 1153 | // ES6 section 7.3.9 GetMethod |
| 1154 | MUST_USE_RESULT static MaybeHandle<Object> GetMethod( |
| 1155 | Handle<JSReceiver> receiver, Handle<Name> name); |
| 1156 | |
| 1157 | // ES6 section 7.3.17 CreateListFromArrayLike |
| 1158 | MUST_USE_RESULT static MaybeHandle<FixedArray> CreateListFromArrayLike( |
| 1159 | Isolate* isolate, Handle<Object> object, ElementTypes element_types); |
| 1160 | |
| 1161 | // Check whether |object| is an instance of Error or NativeError. |
| 1162 | static bool IsErrorObject(Isolate* isolate, Handle<Object> object); |
| 1163 | |
| 1164 | // ES6 section 12.5.6 The typeof Operator |
| 1165 | static Handle<String> TypeOf(Isolate* isolate, Handle<Object> object); |
| 1166 | |
| 1167 | // ES6 section 12.6 Multiplicative Operators |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1168 | MUST_USE_RESULT static MaybeHandle<Object> Multiply(Isolate* isolate, |
| 1169 | Handle<Object> lhs, |
| 1170 | Handle<Object> rhs); |
| 1171 | MUST_USE_RESULT static MaybeHandle<Object> Divide(Isolate* isolate, |
| 1172 | Handle<Object> lhs, |
| 1173 | Handle<Object> rhs); |
| 1174 | MUST_USE_RESULT static MaybeHandle<Object> Modulus(Isolate* isolate, |
| 1175 | Handle<Object> lhs, |
| 1176 | Handle<Object> rhs); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1177 | |
| 1178 | // ES6 section 12.7 Additive Operators |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1179 | MUST_USE_RESULT static MaybeHandle<Object> Add(Isolate* isolate, |
| 1180 | Handle<Object> lhs, |
| 1181 | Handle<Object> rhs); |
| 1182 | MUST_USE_RESULT static MaybeHandle<Object> Subtract(Isolate* isolate, |
| 1183 | Handle<Object> lhs, |
| 1184 | Handle<Object> rhs); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1185 | |
| 1186 | // ES6 section 12.8 Bitwise Shift Operators |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1187 | MUST_USE_RESULT static MaybeHandle<Object> ShiftLeft(Isolate* isolate, |
| 1188 | Handle<Object> lhs, |
| 1189 | Handle<Object> rhs); |
| 1190 | MUST_USE_RESULT static MaybeHandle<Object> ShiftRight(Isolate* isolate, |
| 1191 | Handle<Object> lhs, |
| 1192 | Handle<Object> rhs); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1193 | MUST_USE_RESULT static MaybeHandle<Object> ShiftRightLogical( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1194 | Isolate* isolate, Handle<Object> lhs, Handle<Object> rhs); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1195 | |
| 1196 | // ES6 section 12.9 Relational Operators |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1197 | MUST_USE_RESULT static inline Maybe<bool> GreaterThan(Handle<Object> x, |
| 1198 | Handle<Object> y); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1199 | MUST_USE_RESULT static inline Maybe<bool> GreaterThanOrEqual( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1200 | Handle<Object> x, Handle<Object> y); |
| 1201 | MUST_USE_RESULT static inline Maybe<bool> LessThan(Handle<Object> x, |
| 1202 | Handle<Object> y); |
| 1203 | MUST_USE_RESULT static inline Maybe<bool> LessThanOrEqual(Handle<Object> x, |
| 1204 | Handle<Object> y); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1205 | |
| 1206 | // ES6 section 12.11 Binary Bitwise Operators |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1207 | MUST_USE_RESULT static MaybeHandle<Object> BitwiseAnd(Isolate* isolate, |
| 1208 | Handle<Object> lhs, |
| 1209 | Handle<Object> rhs); |
| 1210 | MUST_USE_RESULT static MaybeHandle<Object> BitwiseOr(Isolate* isolate, |
| 1211 | Handle<Object> lhs, |
| 1212 | Handle<Object> rhs); |
| 1213 | MUST_USE_RESULT static MaybeHandle<Object> BitwiseXor(Isolate* isolate, |
| 1214 | Handle<Object> lhs, |
| 1215 | Handle<Object> rhs); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1216 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1217 | MUST_USE_RESULT static MaybeHandle<Object> GetProperty(LookupIterator* it); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1218 | |
| 1219 | // ES6 [[Set]] (when passed DONT_THROW) |
| 1220 | // Invariants for this and related functions (unless stated otherwise): |
| 1221 | // 1) When the result is Nothing, an exception is pending. |
| 1222 | // 2) When passed THROW_ON_ERROR, the result is never Just(false). |
| 1223 | // In some cases, an exception is thrown regardless of the ShouldThrow |
| 1224 | // argument. These cases are either in accordance with the spec or not |
| 1225 | // covered by it (eg., concerning API callbacks). |
| 1226 | MUST_USE_RESULT static Maybe<bool> SetProperty(LookupIterator* it, |
| 1227 | Handle<Object> value, |
| 1228 | LanguageMode language_mode, |
| 1229 | StoreFromKeyed store_mode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1230 | MUST_USE_RESULT static MaybeHandle<Object> SetProperty( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1231 | Handle<Object> object, Handle<Name> name, Handle<Object> value, |
| 1232 | LanguageMode language_mode, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1233 | StoreFromKeyed store_mode = MAY_BE_STORE_FROM_KEYED); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1234 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1235 | MUST_USE_RESULT static Maybe<bool> SetSuperProperty( |
| 1236 | LookupIterator* it, Handle<Object> value, LanguageMode language_mode, |
| 1237 | StoreFromKeyed store_mode); |
| 1238 | |
| 1239 | MUST_USE_RESULT static MaybeHandle<Object> ReadAbsentProperty( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1240 | LookupIterator* it); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1241 | MUST_USE_RESULT static MaybeHandle<Object> ReadAbsentProperty( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1242 | Isolate* isolate, Handle<Object> receiver, Handle<Object> name); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1243 | MUST_USE_RESULT static Maybe<bool> CannotCreateProperty( |
| 1244 | Isolate* isolate, Handle<Object> receiver, Handle<Object> name, |
| 1245 | Handle<Object> value, ShouldThrow should_throw); |
| 1246 | MUST_USE_RESULT static Maybe<bool> WriteToReadOnlyProperty( |
| 1247 | LookupIterator* it, Handle<Object> value, ShouldThrow should_throw); |
| 1248 | MUST_USE_RESULT static Maybe<bool> WriteToReadOnlyProperty( |
| 1249 | Isolate* isolate, Handle<Object> receiver, Handle<Object> name, |
| 1250 | Handle<Object> value, ShouldThrow should_throw); |
| 1251 | MUST_USE_RESULT static Maybe<bool> RedefineIncompatibleProperty( |
| 1252 | Isolate* isolate, Handle<Object> name, Handle<Object> value, |
| 1253 | ShouldThrow should_throw); |
| 1254 | MUST_USE_RESULT static Maybe<bool> SetDataProperty(LookupIterator* it, |
| 1255 | Handle<Object> value); |
| 1256 | MUST_USE_RESULT static Maybe<bool> AddDataProperty( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1257 | LookupIterator* it, Handle<Object> value, PropertyAttributes attributes, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1258 | ShouldThrow should_throw, StoreFromKeyed store_mode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1259 | MUST_USE_RESULT static inline MaybeHandle<Object> GetPropertyOrElement( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1260 | Handle<Object> object, Handle<Name> name); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1261 | MUST_USE_RESULT static inline MaybeHandle<Object> GetPropertyOrElement( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1262 | Handle<Object> receiver, Handle<Name> name, Handle<JSReceiver> holder); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1263 | MUST_USE_RESULT static inline MaybeHandle<Object> GetProperty( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1264 | Isolate* isolate, Handle<Object> object, const char* key); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1265 | MUST_USE_RESULT static inline MaybeHandle<Object> GetProperty( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1266 | Handle<Object> object, Handle<Name> name); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1267 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1268 | MUST_USE_RESULT static MaybeHandle<Object> GetPropertyWithAccessor( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1269 | LookupIterator* it); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1270 | MUST_USE_RESULT static Maybe<bool> SetPropertyWithAccessor( |
| 1271 | LookupIterator* it, Handle<Object> value, ShouldThrow should_throw); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1272 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1273 | MUST_USE_RESULT static MaybeHandle<Object> GetPropertyWithDefinedGetter( |
| 1274 | Handle<Object> receiver, |
| 1275 | Handle<JSReceiver> getter); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1276 | MUST_USE_RESULT static Maybe<bool> SetPropertyWithDefinedSetter( |
| 1277 | Handle<Object> receiver, Handle<JSReceiver> setter, Handle<Object> value, |
| 1278 | ShouldThrow should_throw); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1279 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1280 | MUST_USE_RESULT static inline MaybeHandle<Object> GetElement( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1281 | Isolate* isolate, Handle<Object> object, uint32_t index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1282 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1283 | MUST_USE_RESULT static inline MaybeHandle<Object> SetElement( |
| 1284 | Isolate* isolate, Handle<Object> object, uint32_t index, |
| 1285 | Handle<Object> value, LanguageMode language_mode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1286 | |
| 1287 | // Returns the permanent hash code associated with this object. May return |
| 1288 | // undefined if not yet created. |
| 1289 | Object* GetHash(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1290 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1291 | // Returns undefined for JSObjects, but returns the hash code for simple |
| 1292 | // objects. This avoids a double lookup in the cases where we know we will |
| 1293 | // add the hash to the JSObject if it does not already exist. |
| 1294 | Object* GetSimpleHash(); |
| 1295 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1296 | // Returns the permanent hash code associated with this object depending on |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1297 | // the actual object type. May create and store a hash code if needed and none |
| 1298 | // exists. |
| 1299 | static Handle<Smi> GetOrCreateHash(Isolate* isolate, Handle<Object> object); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1300 | |
| 1301 | // Checks whether this object has the same value as the given one. This |
| 1302 | // function is implemented according to ES5, section 9.12 and can be used |
| 1303 | // to implement the Harmony "egal" function. |
| 1304 | bool SameValue(Object* other); |
| 1305 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1306 | // Checks whether this object has the same value as the given one. |
| 1307 | // +0 and -0 are treated equal. Everything else is the same as SameValue. |
| 1308 | // This function is implemented according to ES6, section 7.2.4 and is used |
| 1309 | // by ES6 Map and Set. |
| 1310 | bool SameValueZero(Object* other); |
| 1311 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1312 | // ES6 section 9.4.2.3 ArraySpeciesCreate (part of it) |
| 1313 | MUST_USE_RESULT static MaybeHandle<Object> ArraySpeciesConstructor( |
| 1314 | Isolate* isolate, Handle<Object> original_array); |
| 1315 | |
| 1316 | // Tries to convert an object to an array length. Returns true and sets the |
| 1317 | // output parameter if it succeeds. |
| 1318 | inline bool ToArrayLength(uint32_t* index); |
| 1319 | |
| 1320 | // Tries to convert an object to an array index. Returns true and sets the |
| 1321 | // output parameter if it succeeds. Equivalent to ToArrayLength, but does not |
| 1322 | // allow kMaxUInt32. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1323 | inline bool ToArrayIndex(uint32_t* index); |
| 1324 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1325 | DECLARE_VERIFIER(Object) |
| 1326 | #ifdef VERIFY_HEAP |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1327 | // Verify a pointer is a valid object pointer. |
| 1328 | static void VerifyPointer(Object* p); |
| 1329 | #endif |
| 1330 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1331 | inline void VerifyApiCallResultType(); |
| 1332 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1333 | // ES6 19.1.3.6 Object.prototype.toString |
| 1334 | MUST_USE_RESULT static MaybeHandle<String> ObjectProtoToString( |
| 1335 | Isolate* isolate, Handle<Object> object); |
| 1336 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1337 | // Prints this object without details. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1338 | void ShortPrint(FILE* out = stdout); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1339 | |
| 1340 | // Prints this object without details to a message accumulator. |
| 1341 | void ShortPrint(StringStream* accumulator); |
| 1342 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1343 | void ShortPrint(std::ostream& os); // NOLINT |
| 1344 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1345 | DECLARE_CAST(Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1346 | |
| 1347 | // Layout description. |
| 1348 | static const int kHeaderSize = 0; // Object does not take up any space. |
| 1349 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1350 | #ifdef OBJECT_PRINT |
| 1351 | // For our gdb macros, we should perhaps change these in the future. |
| 1352 | void Print(); |
| 1353 | |
| 1354 | // Prints this object with details. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1355 | void Print(std::ostream& os); // NOLINT |
| 1356 | #else |
| 1357 | void Print() { ShortPrint(); } |
| 1358 | void Print(std::ostream& os) { ShortPrint(os); } // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1359 | #endif |
| 1360 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1361 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1362 | friend class LookupIterator; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1363 | friend class StringStream; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1364 | |
| 1365 | // Return the map of the root of object's prototype chain. |
| 1366 | Map* GetRootMap(Isolate* isolate); |
| 1367 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1368 | // Helper for SetProperty and SetSuperProperty. |
| 1369 | // Return value is only meaningful if [found] is set to true on return. |
| 1370 | MUST_USE_RESULT static Maybe<bool> SetPropertyInternal( |
| 1371 | LookupIterator* it, Handle<Object> value, LanguageMode language_mode, |
| 1372 | StoreFromKeyed store_mode, bool* found); |
| 1373 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1374 | DISALLOW_IMPLICIT_CONSTRUCTORS(Object); |
| 1375 | }; |
| 1376 | |
| 1377 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1378 | // In objects.h to be usable without objects-inl.h inclusion. |
| 1379 | bool Object::IsSmi() const { return HAS_SMI_TAG(this); } |
| 1380 | bool Object::IsHeapObject() const { return Internals::HasHeapObjectTag(this); } |
| 1381 | |
| 1382 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1383 | struct Brief { |
| 1384 | explicit Brief(const Object* const v) : value(v) {} |
| 1385 | const Object* value; |
| 1386 | }; |
| 1387 | |
| 1388 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1389 | std::ostream& operator<<(std::ostream& os, const Brief& v); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1390 | |
| 1391 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1392 | // Smi represents integer Numbers that can be stored in 31 bits. |
| 1393 | // Smis are immediate which means they are NOT allocated in the heap. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1394 | // The this pointer has the following format: [31 bit signed int] 0 |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1395 | // For long smis it has the following format: |
| 1396 | // [32 bit signed int] [31 bits zero padding] 0 |
| 1397 | // Smi stands for small integer. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1398 | class Smi: public Object { |
| 1399 | public: |
| 1400 | // Returns the integer value. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1401 | inline int value() const { return Internals::SmiValue(this); } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1402 | |
| 1403 | // Convert a value to a Smi object. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1404 | static inline Smi* FromInt(int value) { |
| 1405 | DCHECK(Smi::IsValid(value)); |
| 1406 | return reinterpret_cast<Smi*>(Internals::IntToSmi(value)); |
| 1407 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1408 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1409 | static inline Smi* FromIntptr(intptr_t value) { |
| 1410 | DCHECK(Smi::IsValid(value)); |
| 1411 | int smi_shift_bits = kSmiTagSize + kSmiShiftSize; |
| 1412 | return reinterpret_cast<Smi*>((value << smi_shift_bits) | kSmiTag); |
| 1413 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1414 | |
| 1415 | // Returns whether value can be represented in a Smi. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1416 | static inline bool IsValid(intptr_t value) { |
| 1417 | bool result = Internals::IsValidSmi(value); |
| 1418 | DCHECK_EQ(result, value >= kMinValue && value <= kMaxValue); |
| 1419 | return result; |
| 1420 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1421 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1422 | DECLARE_CAST(Smi) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1423 | |
| 1424 | // Dispatched behavior. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1425 | void SmiPrint(std::ostream& os) const; // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1426 | DECLARE_VERIFIER(Smi) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1427 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1428 | static const int kMinValue = |
| 1429 | (static_cast<unsigned int>(-1)) << (kSmiValueSize - 1); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1430 | static const int kMaxValue = -(kMinValue + 1); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1431 | |
| 1432 | private: |
| 1433 | DISALLOW_IMPLICIT_CONSTRUCTORS(Smi); |
| 1434 | }; |
| 1435 | |
| 1436 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1437 | // Heap objects typically have a map pointer in their first word. However, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1438 | // during GC other data (e.g. mark bits, forwarding addresses) is sometimes |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1439 | // encoded in the first word. The class MapWord is an abstraction of the |
| 1440 | // value in a heap object's first word. |
| 1441 | class MapWord BASE_EMBEDDED { |
| 1442 | public: |
| 1443 | // Normal state: the map word contains a map pointer. |
| 1444 | |
| 1445 | // Create a map word from a map pointer. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1446 | static inline MapWord FromMap(const Map* map); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1447 | |
| 1448 | // View this map word as a map pointer. |
| 1449 | inline Map* ToMap(); |
| 1450 | |
| 1451 | |
| 1452 | // Scavenge collection: the map word of live objects in the from space |
| 1453 | // contains a forwarding address (a heap object pointer in the to space). |
| 1454 | |
| 1455 | // True if this map word is a forwarding address for a scavenge |
| 1456 | // collection. Only valid during a scavenge collection (specifically, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1457 | // 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] | 1458 | inline bool IsForwardingAddress(); |
| 1459 | |
| 1460 | // Create a map word from a forwarding address. |
| 1461 | static inline MapWord FromForwardingAddress(HeapObject* object); |
| 1462 | |
| 1463 | // View this map word as a forwarding address. |
| 1464 | inline HeapObject* ToForwardingAddress(); |
| 1465 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1466 | static inline MapWord FromRawValue(uintptr_t value) { |
| 1467 | return MapWord(value); |
| 1468 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1469 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1470 | inline uintptr_t ToRawValue() { |
| 1471 | return value_; |
| 1472 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1473 | |
| 1474 | private: |
| 1475 | // HeapObject calls the private constructor and directly reads the value. |
| 1476 | friend class HeapObject; |
| 1477 | |
| 1478 | explicit MapWord(uintptr_t value) : value_(value) {} |
| 1479 | |
| 1480 | uintptr_t value_; |
| 1481 | }; |
| 1482 | |
| 1483 | |
| 1484 | // HeapObject is the superclass for all classes describing heap allocated |
| 1485 | // objects. |
| 1486 | class HeapObject: public Object { |
| 1487 | public: |
| 1488 | // [map]: Contains a map which contains the object's reflective |
| 1489 | // information. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1490 | inline Map* map() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1491 | inline void set_map(Map* value); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1492 | // The no-write-barrier version. This is OK if the object is white and in |
| 1493 | // new space, or if the value is an immortal immutable object, like the maps |
| 1494 | // of primitive (non-JS) objects like strings, heap numbers etc. |
| 1495 | inline void set_map_no_write_barrier(Map* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1496 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1497 | // Get the map using acquire load. |
| 1498 | inline Map* synchronized_map(); |
| 1499 | inline MapWord synchronized_map_word() const; |
| 1500 | |
| 1501 | // Set the map using release store |
| 1502 | inline void synchronized_set_map(Map* value); |
| 1503 | inline void synchronized_set_map_no_write_barrier(Map* value); |
| 1504 | inline void synchronized_set_map_word(MapWord map_word); |
| 1505 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1506 | // During garbage collection, the map word of a heap object does not |
| 1507 | // necessarily contain a map pointer. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1508 | inline MapWord map_word() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1509 | inline void set_map_word(MapWord map_word); |
| 1510 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1511 | // The Heap the object was allocated in. Used also to access Isolate. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1512 | inline Heap* GetHeap() const; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1513 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1514 | // Convenience method to get current isolate. |
| 1515 | inline Isolate* GetIsolate() const; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1516 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1517 | #define IS_TYPE_FUNCTION_DECL(type_) INLINE(bool Is##type_() const); |
| 1518 | HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL) |
| 1519 | ODDBALL_LIST(IS_TYPE_FUNCTION_DECL) |
| 1520 | #undef IS_TYPE_FUNCTION_DECL |
| 1521 | #define DECLARE_STRUCT_PREDICATE(NAME, Name, name) \ |
| 1522 | INLINE(bool Is##Name() const); |
| 1523 | STRUCT_LIST(DECLARE_STRUCT_PREDICATE) |
| 1524 | #undef DECLARE_STRUCT_PREDICATE |
| 1525 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1526 | // Converts an address to a HeapObject pointer. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1527 | static inline HeapObject* FromAddress(Address address) { |
| 1528 | DCHECK_TAG_ALIGNED(address); |
| 1529 | return reinterpret_cast<HeapObject*>(address + kHeapObjectTag); |
| 1530 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1531 | |
| 1532 | // Returns the address of this HeapObject. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1533 | inline Address address() { |
| 1534 | return reinterpret_cast<Address>(this) - kHeapObjectTag; |
| 1535 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1536 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1537 | // Iterates over pointers contained in the object (including the Map). |
| 1538 | // If it's not performance critical iteration use the non-templatized |
| 1539 | // version. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1540 | void Iterate(ObjectVisitor* v); |
| 1541 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1542 | template <typename ObjectVisitor> |
| 1543 | inline void IterateFast(ObjectVisitor* v); |
| 1544 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1545 | // Iterates over all pointers contained in the object except the |
| 1546 | // first map pointer. The object type is given in the first |
| 1547 | // parameter. This function does not access the map pointer in the |
| 1548 | // 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] | 1549 | // If it's not performance critical iteration use the non-templatized |
| 1550 | // version. |
| 1551 | void IterateBody(ObjectVisitor* v); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1552 | void IterateBody(InstanceType type, int object_size, ObjectVisitor* v); |
| 1553 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1554 | template <typename ObjectVisitor> |
| 1555 | inline void IterateBodyFast(ObjectVisitor* v); |
| 1556 | |
| 1557 | template <typename ObjectVisitor> |
| 1558 | inline void IterateBodyFast(InstanceType type, int object_size, |
| 1559 | ObjectVisitor* v); |
| 1560 | |
| 1561 | // Returns true if the object contains a tagged value at given offset. |
| 1562 | // It is used for invalid slots filtering. If the offset points outside |
| 1563 | // of the object or to the map word, the result is UNDEFINED (!!!). |
| 1564 | bool IsValidSlot(int offset); |
| 1565 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1566 | // Returns the heap object's size in bytes |
| 1567 | inline int Size(); |
| 1568 | |
| 1569 | // Given a heap object's map pointer, returns the heap size in bytes |
| 1570 | // Useful when the map pointer field is used for other purposes. |
| 1571 | // GC internal. |
| 1572 | inline int SizeFromMap(Map* map); |
| 1573 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1574 | // Returns the field at offset in obj, as a read/write Object* reference. |
| 1575 | // 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] | 1576 | // Does not invoke write barrier, so should only be assigned to |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1577 | // during marking GC. |
| 1578 | static inline Object** RawField(HeapObject* obj, int offset); |
| 1579 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1580 | // Adds the |code| object related to |name| to the code cache of this map. If |
| 1581 | // this map is a dictionary map that is shared, the map copied and installed |
| 1582 | // onto the object. |
| 1583 | static void UpdateMapCodeCache(Handle<HeapObject> object, |
| 1584 | Handle<Name> name, |
| 1585 | Handle<Code> code); |
| 1586 | |
| 1587 | DECLARE_CAST(HeapObject) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1588 | |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 1589 | // Return the write barrier mode for this. Callers of this function |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1590 | // must be able to present a reference to an DisallowHeapAllocation |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 1591 | // object as a sign that they are not going to use this function |
| 1592 | // from code that allocates and thus invalidates the returned write |
| 1593 | // barrier mode. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1594 | inline WriteBarrierMode GetWriteBarrierMode( |
| 1595 | const DisallowHeapAllocation& promise); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1596 | |
| 1597 | // Dispatched behavior. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1598 | void HeapObjectShortPrint(std::ostream& os); // NOLINT |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1599 | #ifdef OBJECT_PRINT |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1600 | void PrintHeader(std::ostream& os, const char* id); // NOLINT |
Ben Murdoch | 85b7179 | 2012-04-11 18:30:58 +0100 | [diff] [blame] | 1601 | #endif |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1602 | DECLARE_PRINTER(HeapObject) |
| 1603 | DECLARE_VERIFIER(HeapObject) |
| 1604 | #ifdef VERIFY_HEAP |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1605 | inline void VerifyObjectField(int offset); |
| 1606 | inline void VerifySmiField(int offset); |
| 1607 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1608 | // Verify a pointer is a valid HeapObject pointer that points to object |
| 1609 | // areas in the heap. |
| 1610 | static void VerifyHeapPointer(Object* p); |
| 1611 | #endif |
| 1612 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1613 | inline AllocationAlignment RequiredAlignment(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1614 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1615 | // Layout description. |
| 1616 | // First field in a heap object is map. |
| 1617 | static const int kMapOffset = Object::kHeaderSize; |
| 1618 | static const int kHeaderSize = kMapOffset + kPointerSize; |
| 1619 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1620 | STATIC_ASSERT(kMapOffset == Internals::kHeapObjectMapOffset); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1621 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1622 | private: |
| 1623 | DISALLOW_IMPLICIT_CONSTRUCTORS(HeapObject); |
| 1624 | }; |
| 1625 | |
| 1626 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1627 | template <int start_offset, int end_offset, int size> |
| 1628 | class FixedBodyDescriptor; |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1629 | |
| 1630 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1631 | template <int start_offset> |
| 1632 | class FlexibleBodyDescriptor; |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1633 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1634 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1635 | // The HeapNumber class describes heap allocated numbers that cannot be |
| 1636 | // represented in a Smi (small integer) |
| 1637 | class HeapNumber: public HeapObject { |
| 1638 | public: |
| 1639 | // [value]: number value. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1640 | inline double value() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1641 | inline void set_value(double value); |
| 1642 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1643 | DECLARE_CAST(HeapNumber) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1644 | |
| 1645 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1646 | bool HeapNumberBooleanValue(); |
| 1647 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1648 | void HeapNumberPrint(std::ostream& os); // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1649 | DECLARE_VERIFIER(HeapNumber) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1650 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1651 | inline int get_exponent(); |
| 1652 | inline int get_sign(); |
| 1653 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1654 | // Layout description. |
| 1655 | static const int kValueOffset = HeapObject::kHeaderSize; |
| 1656 | // 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] | 1657 | // is a mixture of sign, exponent and mantissa. The offsets of two 32 bit |
| 1658 | // words within double numbers are endian dependent and they are set |
| 1659 | // accordingly. |
| 1660 | #if defined(V8_TARGET_LITTLE_ENDIAN) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1661 | static const int kMantissaOffset = kValueOffset; |
| 1662 | static const int kExponentOffset = kValueOffset + 4; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1663 | #elif defined(V8_TARGET_BIG_ENDIAN) |
| 1664 | static const int kMantissaOffset = kValueOffset + 4; |
| 1665 | static const int kExponentOffset = kValueOffset; |
| 1666 | #else |
| 1667 | #error Unknown byte ordering |
| 1668 | #endif |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1669 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1670 | static const int kSize = kValueOffset + kDoubleSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1671 | static const uint32_t kSignMask = 0x80000000u; |
| 1672 | static const uint32_t kExponentMask = 0x7ff00000u; |
| 1673 | static const uint32_t kMantissaMask = 0xfffffu; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1674 | static const int kMantissaBits = 52; |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 1675 | static const int kExponentBits = 11; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1676 | static const int kExponentBias = 1023; |
| 1677 | static const int kExponentShift = 20; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1678 | static const int kInfinityOrNanExponent = |
| 1679 | (kExponentMask >> kExponentShift) - kExponentBias; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1680 | static const int kMantissaBitsInTopWord = 20; |
| 1681 | static const int kNonMantissaBitsInTopWord = 12; |
| 1682 | |
| 1683 | private: |
| 1684 | DISALLOW_IMPLICIT_CONSTRUCTORS(HeapNumber); |
| 1685 | }; |
| 1686 | |
| 1687 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1688 | // The Simd128Value class describes heap allocated 128 bit SIMD values. |
| 1689 | class Simd128Value : public HeapObject { |
| 1690 | public: |
| 1691 | DECLARE_CAST(Simd128Value) |
| 1692 | |
| 1693 | DECLARE_PRINTER(Simd128Value) |
| 1694 | DECLARE_VERIFIER(Simd128Value) |
| 1695 | |
| 1696 | static Handle<String> ToString(Handle<Simd128Value> input); |
| 1697 | |
| 1698 | // Equality operations. |
| 1699 | inline bool Equals(Simd128Value* that); |
| 1700 | static inline bool Equals(Handle<Simd128Value> one, Handle<Simd128Value> two); |
| 1701 | |
| 1702 | // Checks that another instance is bit-wise equal. |
| 1703 | bool BitwiseEquals(const Simd128Value* other) const; |
| 1704 | // Computes a hash from the 128 bit value, viewed as 4 32-bit integers. |
| 1705 | uint32_t Hash() const; |
| 1706 | // Copies the 16 bytes of SIMD data to the destination address. |
| 1707 | void CopyBits(void* destination) const; |
| 1708 | |
| 1709 | // Layout description. |
| 1710 | static const int kValueOffset = HeapObject::kHeaderSize; |
| 1711 | static const int kSize = kValueOffset + kSimd128Size; |
| 1712 | |
| 1713 | private: |
| 1714 | DISALLOW_IMPLICIT_CONSTRUCTORS(Simd128Value); |
| 1715 | }; |
| 1716 | |
| 1717 | |
| 1718 | // V has parameters (TYPE, Type, type, lane count, lane type) |
| 1719 | #define SIMD128_TYPES(V) \ |
| 1720 | V(FLOAT32X4, Float32x4, float32x4, 4, float) \ |
| 1721 | V(INT32X4, Int32x4, int32x4, 4, int32_t) \ |
| 1722 | V(UINT32X4, Uint32x4, uint32x4, 4, uint32_t) \ |
| 1723 | V(BOOL32X4, Bool32x4, bool32x4, 4, bool) \ |
| 1724 | V(INT16X8, Int16x8, int16x8, 8, int16_t) \ |
| 1725 | V(UINT16X8, Uint16x8, uint16x8, 8, uint16_t) \ |
| 1726 | V(BOOL16X8, Bool16x8, bool16x8, 8, bool) \ |
| 1727 | V(INT8X16, Int8x16, int8x16, 16, int8_t) \ |
| 1728 | V(UINT8X16, Uint8x16, uint8x16, 16, uint8_t) \ |
| 1729 | V(BOOL8X16, Bool8x16, bool8x16, 16, bool) |
| 1730 | |
| 1731 | #define SIMD128_VALUE_CLASS(TYPE, Type, type, lane_count, lane_type) \ |
| 1732 | class Type final : public Simd128Value { \ |
| 1733 | public: \ |
| 1734 | inline lane_type get_lane(int lane) const; \ |
| 1735 | inline void set_lane(int lane, lane_type value); \ |
| 1736 | \ |
| 1737 | DECLARE_CAST(Type) \ |
| 1738 | \ |
| 1739 | DECLARE_PRINTER(Type) \ |
| 1740 | \ |
| 1741 | static Handle<String> ToString(Handle<Type> input); \ |
| 1742 | \ |
| 1743 | inline bool Equals(Type* that); \ |
| 1744 | \ |
| 1745 | private: \ |
| 1746 | DISALLOW_IMPLICIT_CONSTRUCTORS(Type); \ |
| 1747 | }; |
| 1748 | SIMD128_TYPES(SIMD128_VALUE_CLASS) |
| 1749 | #undef SIMD128_VALUE_CLASS |
| 1750 | |
| 1751 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1752 | enum EnsureElementsMode { |
| 1753 | DONT_ALLOW_DOUBLE_ELEMENTS, |
| 1754 | ALLOW_COPIED_DOUBLE_ELEMENTS, |
| 1755 | ALLOW_CONVERTED_DOUBLE_ELEMENTS |
| 1756 | }; |
| 1757 | |
| 1758 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1759 | // Indicator for one component of an AccessorPair. |
| 1760 | enum AccessorComponent { |
| 1761 | ACCESSOR_GETTER, |
| 1762 | ACCESSOR_SETTER |
| 1763 | }; |
| 1764 | |
| 1765 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1766 | enum GetKeysConversion { KEEP_NUMBERS, CONVERT_TO_STRING }; |
| 1767 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1768 | enum KeyCollectionType { OWN_ONLY, INCLUDE_PROTOS }; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1769 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1770 | // JSReceiver includes types on which properties can be defined, i.e., |
| 1771 | // JSObject and JSProxy. |
| 1772 | class JSReceiver: public HeapObject { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1773 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1774 | // [properties]: Backing storage for properties. |
| 1775 | // properties is a FixedArray in the fast case and a Dictionary in the |
| 1776 | // slow case. |
| 1777 | DECL_ACCESSORS(properties, FixedArray) // Get and set fast properties. |
| 1778 | inline void initialize_properties(); |
| 1779 | inline bool HasFastProperties(); |
| 1780 | // Gets slow properties for non-global objects. |
| 1781 | inline NameDictionary* property_dictionary(); |
| 1782 | |
| 1783 | // Deletes an existing named property in a normalized object. |
| 1784 | static void DeleteNormalizedProperty(Handle<JSReceiver> object, |
| 1785 | Handle<Name> name, int entry); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1786 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1787 | DECLARE_CAST(JSReceiver) |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1788 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1789 | // ES6 section 7.1.1 ToPrimitive |
| 1790 | MUST_USE_RESULT static MaybeHandle<Object> ToPrimitive( |
| 1791 | Handle<JSReceiver> receiver, |
| 1792 | ToPrimitiveHint hint = ToPrimitiveHint::kDefault); |
| 1793 | MUST_USE_RESULT static MaybeHandle<Object> OrdinaryToPrimitive( |
| 1794 | Handle<JSReceiver> receiver, OrdinaryToPrimitiveHint hint); |
| 1795 | |
| 1796 | static MaybeHandle<Context> GetFunctionRealm(Handle<JSReceiver> receiver); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1797 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1798 | // Get the first non-hidden prototype. |
| 1799 | static inline MaybeHandle<Object> GetPrototype(Isolate* isolate, |
| 1800 | Handle<JSReceiver> receiver); |
| 1801 | |
| 1802 | MUST_USE_RESULT static Maybe<bool> HasInPrototypeChain( |
| 1803 | Isolate* isolate, Handle<JSReceiver> object, Handle<Object> proto); |
| 1804 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1805 | // Implementation of [[HasProperty]], ECMA-262 5th edition, section 8.12.6. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1806 | MUST_USE_RESULT static Maybe<bool> HasProperty(LookupIterator* it); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1807 | MUST_USE_RESULT static inline Maybe<bool> HasProperty( |
| 1808 | Handle<JSReceiver> object, Handle<Name> name); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1809 | MUST_USE_RESULT static inline Maybe<bool> HasElement( |
| 1810 | Handle<JSReceiver> object, uint32_t index); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1811 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1812 | MUST_USE_RESULT static inline Maybe<bool> HasOwnProperty( |
| 1813 | Handle<JSReceiver> object, Handle<Name> name); |
| 1814 | |
| 1815 | // Implementation of ES6 [[Delete]] |
| 1816 | MUST_USE_RESULT static Maybe<bool> DeletePropertyOrElement( |
| 1817 | Handle<JSReceiver> object, Handle<Name> name, |
| 1818 | LanguageMode language_mode = SLOPPY); |
| 1819 | MUST_USE_RESULT static Maybe<bool> DeleteProperty( |
| 1820 | Handle<JSReceiver> object, Handle<Name> name, |
| 1821 | LanguageMode language_mode = SLOPPY); |
| 1822 | MUST_USE_RESULT static Maybe<bool> DeleteProperty(LookupIterator* it, |
| 1823 | LanguageMode language_mode); |
| 1824 | MUST_USE_RESULT static Maybe<bool> DeleteElement( |
| 1825 | Handle<JSReceiver> object, uint32_t index, |
| 1826 | LanguageMode language_mode = SLOPPY); |
| 1827 | |
| 1828 | MUST_USE_RESULT static Object* DefineProperty(Isolate* isolate, |
| 1829 | Handle<Object> object, |
| 1830 | Handle<Object> name, |
| 1831 | Handle<Object> attributes); |
| 1832 | MUST_USE_RESULT static MaybeHandle<Object> DefineProperties( |
| 1833 | Isolate* isolate, Handle<Object> object, Handle<Object> properties); |
| 1834 | |
| 1835 | // "virtual" dispatcher to the correct [[DefineOwnProperty]] implementation. |
| 1836 | MUST_USE_RESULT static Maybe<bool> DefineOwnProperty( |
| 1837 | Isolate* isolate, Handle<JSReceiver> object, Handle<Object> key, |
| 1838 | PropertyDescriptor* desc, ShouldThrow should_throw); |
| 1839 | |
| 1840 | // ES6 7.3.4 (when passed DONT_THROW) |
| 1841 | MUST_USE_RESULT static Maybe<bool> CreateDataProperty( |
| 1842 | LookupIterator* it, Handle<Object> value, ShouldThrow should_throw); |
| 1843 | |
| 1844 | // ES6 9.1.6.1 |
| 1845 | MUST_USE_RESULT static Maybe<bool> OrdinaryDefineOwnProperty( |
| 1846 | Isolate* isolate, Handle<JSObject> object, Handle<Object> key, |
| 1847 | PropertyDescriptor* desc, ShouldThrow should_throw); |
| 1848 | MUST_USE_RESULT static Maybe<bool> OrdinaryDefineOwnProperty( |
| 1849 | LookupIterator* it, PropertyDescriptor* desc, ShouldThrow should_throw); |
| 1850 | // ES6 9.1.6.2 |
| 1851 | MUST_USE_RESULT static Maybe<bool> IsCompatiblePropertyDescriptor( |
| 1852 | Isolate* isolate, bool extensible, PropertyDescriptor* desc, |
| 1853 | PropertyDescriptor* current, Handle<Name> property_name, |
| 1854 | ShouldThrow should_throw); |
| 1855 | // ES6 9.1.6.3 |
| 1856 | // |it| can be NULL in cases where the ES spec passes |undefined| as the |
| 1857 | // receiver. Exactly one of |it| and |property_name| must be provided. |
| 1858 | MUST_USE_RESULT static Maybe<bool> ValidateAndApplyPropertyDescriptor( |
| 1859 | Isolate* isolate, LookupIterator* it, bool extensible, |
| 1860 | PropertyDescriptor* desc, PropertyDescriptor* current, |
| 1861 | ShouldThrow should_throw, Handle<Name> property_name = Handle<Name>()); |
| 1862 | |
| 1863 | MUST_USE_RESULT static Maybe<bool> GetOwnPropertyDescriptor( |
| 1864 | Isolate* isolate, Handle<JSReceiver> object, Handle<Object> key, |
| 1865 | PropertyDescriptor* desc); |
| 1866 | MUST_USE_RESULT static Maybe<bool> GetOwnPropertyDescriptor( |
| 1867 | LookupIterator* it, PropertyDescriptor* desc); |
| 1868 | |
| 1869 | typedef PropertyAttributes IntegrityLevel; |
| 1870 | |
| 1871 | // ES6 7.3.14 (when passed DONT_THROW) |
| 1872 | // 'level' must be SEALED or FROZEN. |
| 1873 | MUST_USE_RESULT static Maybe<bool> SetIntegrityLevel( |
| 1874 | Handle<JSReceiver> object, IntegrityLevel lvl, ShouldThrow should_throw); |
| 1875 | |
| 1876 | // ES6 7.3.15 |
| 1877 | // 'level' must be SEALED or FROZEN. |
| 1878 | MUST_USE_RESULT static Maybe<bool> TestIntegrityLevel( |
| 1879 | Handle<JSReceiver> object, IntegrityLevel lvl); |
| 1880 | |
| 1881 | // ES6 [[PreventExtensions]] (when passed DONT_THROW) |
| 1882 | MUST_USE_RESULT static Maybe<bool> PreventExtensions( |
| 1883 | Handle<JSReceiver> object, ShouldThrow should_throw); |
| 1884 | |
| 1885 | MUST_USE_RESULT static Maybe<bool> IsExtensible(Handle<JSReceiver> object); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1886 | |
| 1887 | // Tests for the fast common case for property enumeration. |
| 1888 | bool IsSimpleEnum(); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1889 | |
| 1890 | // Returns the class name ([[Class]] property in the specification). |
| 1891 | String* class_name(); |
| 1892 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1893 | // Returns the builtin string tag used in Object.prototype.toString. |
| 1894 | MUST_USE_RESULT static MaybeHandle<String> BuiltinStringTag( |
| 1895 | Handle<JSReceiver> object); |
| 1896 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1897 | // Returns the constructor name (the name (possibly, inferred name) of the |
| 1898 | // function that was used to instantiate the object). |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1899 | static Handle<String> GetConstructorName(Handle<JSReceiver> receiver); |
| 1900 | |
| 1901 | Context* GetCreationContext(); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1902 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1903 | MUST_USE_RESULT static inline Maybe<PropertyAttributes> GetPropertyAttributes( |
| 1904 | Handle<JSReceiver> object, Handle<Name> name); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1905 | MUST_USE_RESULT static inline Maybe<PropertyAttributes> |
| 1906 | GetOwnPropertyAttributes(Handle<JSReceiver> object, Handle<Name> name); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1907 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1908 | MUST_USE_RESULT static inline Maybe<PropertyAttributes> GetElementAttributes( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1909 | Handle<JSReceiver> object, uint32_t index); |
| 1910 | MUST_USE_RESULT static inline Maybe<PropertyAttributes> |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1911 | GetOwnElementAttributes(Handle<JSReceiver> object, uint32_t index); |
| 1912 | |
| 1913 | MUST_USE_RESULT static Maybe<PropertyAttributes> GetPropertyAttributes( |
| 1914 | LookupIterator* it); |
| 1915 | |
| 1916 | // Set the object's prototype (only JSReceiver and null are allowed values). |
| 1917 | MUST_USE_RESULT static Maybe<bool> SetPrototype(Handle<JSReceiver> object, |
| 1918 | Handle<Object> value, |
| 1919 | bool from_javascript, |
| 1920 | ShouldThrow should_throw); |
| 1921 | |
| 1922 | |
| 1923 | static Handle<Object> GetDataProperty(Handle<JSReceiver> object, |
| 1924 | Handle<Name> name); |
| 1925 | static Handle<Object> GetDataProperty(LookupIterator* it); |
| 1926 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1927 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1928 | // Retrieves a permanent object identity hash code. The undefined value might |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1929 | // be returned in case no hash was created yet. |
| 1930 | inline Object* GetIdentityHash(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1931 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1932 | // Retrieves a permanent object identity hash code. May create and store a |
| 1933 | // hash code if needed and none exists. |
| 1934 | inline static Handle<Smi> GetOrCreateIdentityHash( |
| 1935 | Handle<JSReceiver> object); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1936 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1937 | // ES6 [[OwnPropertyKeys]] (modulo return type) |
| 1938 | MUST_USE_RESULT static MaybeHandle<FixedArray> OwnPropertyKeys( |
| 1939 | Handle<JSReceiver> object) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1940 | return GetKeys(object, OWN_ONLY, ALL_PROPERTIES, CONVERT_TO_STRING); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1941 | } |
| 1942 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1943 | // Computes the enumerable keys for a JSObject. Used for implementing |
| 1944 | // "for (n in object) { }". |
| 1945 | MUST_USE_RESULT static MaybeHandle<FixedArray> GetKeys( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1946 | Handle<JSReceiver> object, KeyCollectionType type, PropertyFilter filter, |
| 1947 | GetKeysConversion keys_conversion = KEEP_NUMBERS); |
| 1948 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1949 | MUST_USE_RESULT static MaybeHandle<FixedArray> GetOwnValues( |
| 1950 | Handle<JSReceiver> object, PropertyFilter filter); |
| 1951 | |
| 1952 | MUST_USE_RESULT static MaybeHandle<FixedArray> GetOwnEntries( |
| 1953 | Handle<JSReceiver> object, PropertyFilter filter); |
| 1954 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1955 | // Layout description. |
| 1956 | static const int kPropertiesOffset = HeapObject::kHeaderSize; |
| 1957 | static const int kHeaderSize = HeapObject::kHeaderSize + kPointerSize; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1958 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1959 | private: |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1960 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSReceiver); |
| 1961 | }; |
| 1962 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1963 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1964 | // The JSObject describes real heap allocated JavaScript objects with |
| 1965 | // properties. |
| 1966 | // Note that the map of JSObject changes during execution to enable inline |
| 1967 | // caching. |
| 1968 | class JSObject: public JSReceiver { |
| 1969 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1970 | static MUST_USE_RESULT MaybeHandle<JSObject> New( |
| 1971 | Handle<JSFunction> constructor, Handle<JSReceiver> new_target, |
| 1972 | Handle<AllocationSite> site = Handle<AllocationSite>::null()); |
| 1973 | |
| 1974 | // Gets global object properties. |
| 1975 | inline GlobalDictionary* global_dictionary(); |
| 1976 | |
| 1977 | static MaybeHandle<Context> GetFunctionRealm(Handle<JSObject> object); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1978 | |
| 1979 | // [elements]: The elements (properties with names that are integers). |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1980 | // |
| 1981 | // Elements can be in two general modes: fast and slow. Each mode |
| 1982 | // corrensponds to a set of object representations of elements that |
| 1983 | // have something in common. |
| 1984 | // |
| 1985 | // In the fast mode elements is a FixedArray and so each element can |
| 1986 | // be quickly accessed. This fact is used in the generated code. The |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1987 | // elements array can have one of three maps in this mode: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1988 | // fixed_array_map, sloppy_arguments_elements_map or |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1989 | // fixed_cow_array_map (for copy-on-write arrays). In the latter case |
| 1990 | // the elements array may be shared by a few objects and so before |
| 1991 | // writing to any element the array must be copied. Use |
| 1992 | // EnsureWritableFastElements in this case. |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1993 | // |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1994 | // In the slow mode the elements is either a NumberDictionary, a |
| 1995 | // FixedArray parameter map for a (sloppy) arguments object. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1996 | DECL_ACCESSORS(elements, FixedArrayBase) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1997 | inline void initialize_elements(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1998 | static void ResetElements(Handle<JSObject> object); |
| 1999 | static inline void SetMapAndElements(Handle<JSObject> object, |
| 2000 | Handle<Map> map, |
| 2001 | Handle<FixedArrayBase> elements); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2002 | inline ElementsKind GetElementsKind(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2003 | ElementsAccessor* GetElementsAccessor(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2004 | // Returns true if an object has elements of FAST_SMI_ELEMENTS ElementsKind. |
| 2005 | inline bool HasFastSmiElements(); |
| 2006 | // Returns true if an object has elements of FAST_ELEMENTS ElementsKind. |
| 2007 | inline bool HasFastObjectElements(); |
| 2008 | // Returns true if an object has elements of FAST_ELEMENTS or |
| 2009 | // FAST_SMI_ONLY_ELEMENTS. |
| 2010 | inline bool HasFastSmiOrObjectElements(); |
| 2011 | // Returns true if an object has any of the fast elements kinds. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2012 | inline bool HasFastElements(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2013 | // Returns true if an object has elements of FAST_DOUBLE_ELEMENTS |
| 2014 | // ElementsKind. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2015 | inline bool HasFastDoubleElements(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2016 | // Returns true if an object has elements of FAST_HOLEY_*_ELEMENTS |
| 2017 | // ElementsKind. |
| 2018 | inline bool HasFastHoleyElements(); |
| 2019 | inline bool HasSloppyArgumentsElements(); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2020 | inline bool HasStringWrapperElements(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2021 | inline bool HasDictionaryElements(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2022 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2023 | inline bool HasFixedTypedArrayElements(); |
| 2024 | |
| 2025 | inline bool HasFixedUint8ClampedElements(); |
| 2026 | inline bool HasFixedArrayElements(); |
| 2027 | inline bool HasFixedInt8Elements(); |
| 2028 | inline bool HasFixedUint8Elements(); |
| 2029 | inline bool HasFixedInt16Elements(); |
| 2030 | inline bool HasFixedUint16Elements(); |
| 2031 | inline bool HasFixedInt32Elements(); |
| 2032 | inline bool HasFixedUint32Elements(); |
| 2033 | inline bool HasFixedFloat32Elements(); |
| 2034 | inline bool HasFixedFloat64Elements(); |
| 2035 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2036 | inline bool HasFastArgumentsElements(); |
| 2037 | inline bool HasSlowArgumentsElements(); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2038 | inline bool HasFastStringWrapperElements(); |
| 2039 | inline bool HasSlowStringWrapperElements(); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 2040 | inline SeededNumberDictionary* element_dictionary(); // Gets slow elements. |
| 2041 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2042 | // Requires: HasFastElements(). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2043 | static Handle<FixedArray> EnsureWritableFastElements( |
| 2044 | Handle<JSObject> object); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2045 | |
| 2046 | // Collects elements starting at index 0. |
| 2047 | // Undefined values are placed after non-undefined values. |
| 2048 | // Returns the number of non-undefined values. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2049 | static Handle<Object> PrepareElementsForSort(Handle<JSObject> object, |
| 2050 | uint32_t limit); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2051 | // As PrepareElementsForSort, but only on objects where elements is |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2052 | // a dictionary, and it will stay a dictionary. Collates undefined and |
| 2053 | // unexisting elements below limit from position zero of the elements. |
| 2054 | static Handle<Object> PrepareSlowElementsForSort(Handle<JSObject> object, |
| 2055 | uint32_t limit); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2056 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2057 | MUST_USE_RESULT static Maybe<bool> SetPropertyWithInterceptor( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2058 | LookupIterator* it, ShouldThrow should_throw, Handle<Object> value); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2059 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2060 | // The API currently still wants DefineOwnPropertyIgnoreAttributes to convert |
| 2061 | // AccessorInfo objects to data fields. We allow FORCE_FIELD as an exception |
| 2062 | // to the default behavior that calls the setter. |
| 2063 | enum AccessorInfoHandling { FORCE_FIELD, DONT_FORCE_FIELD }; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2064 | |
| 2065 | MUST_USE_RESULT static MaybeHandle<Object> DefineOwnPropertyIgnoreAttributes( |
| 2066 | LookupIterator* it, Handle<Object> value, PropertyAttributes attributes, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2067 | AccessorInfoHandling handling = DONT_FORCE_FIELD); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2068 | |
| 2069 | MUST_USE_RESULT static Maybe<bool> DefineOwnPropertyIgnoreAttributes( |
| 2070 | LookupIterator* it, Handle<Object> value, PropertyAttributes attributes, |
| 2071 | ShouldThrow should_throw, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2072 | AccessorInfoHandling handling = DONT_FORCE_FIELD); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2073 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2074 | MUST_USE_RESULT static MaybeHandle<Object> SetOwnPropertyIgnoreAttributes( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2075 | Handle<JSObject> object, Handle<Name> name, Handle<Object> value, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2076 | PropertyAttributes attributes); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2077 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2078 | MUST_USE_RESULT static MaybeHandle<Object> SetOwnElementIgnoreAttributes( |
| 2079 | Handle<JSObject> object, uint32_t index, Handle<Object> value, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2080 | PropertyAttributes attributes); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2081 | |
| 2082 | // Equivalent to one of the above depending on whether |name| can be converted |
| 2083 | // to an array index. |
| 2084 | MUST_USE_RESULT static MaybeHandle<Object> |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2085 | DefinePropertyOrElementIgnoreAttributes(Handle<JSObject> object, |
| 2086 | Handle<Name> name, |
| 2087 | Handle<Object> value, |
| 2088 | PropertyAttributes attributes = NONE); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2089 | |
| 2090 | // Adds or reconfigures a property to attributes NONE. It will fail when it |
| 2091 | // cannot. |
| 2092 | MUST_USE_RESULT static Maybe<bool> CreateDataProperty(LookupIterator* it, |
| 2093 | Handle<Object> value); |
| 2094 | |
| 2095 | static void AddProperty(Handle<JSObject> object, Handle<Name> name, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2096 | Handle<Object> value, PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2097 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2098 | MUST_USE_RESULT static Maybe<bool> AddDataElement( |
| 2099 | Handle<JSObject> receiver, uint32_t index, Handle<Object> value, |
| 2100 | PropertyAttributes attributes, ShouldThrow should_throw); |
| 2101 | MUST_USE_RESULT static MaybeHandle<Object> AddDataElement( |
| 2102 | Handle<JSObject> receiver, uint32_t index, Handle<Object> value, |
| 2103 | PropertyAttributes attributes); |
| 2104 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2105 | // Extend the receiver with a single fast property appeared first in the |
| 2106 | // passed map. This also extends the property backing store if necessary. |
| 2107 | static void AllocateStorageForMap(Handle<JSObject> object, Handle<Map> map); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2108 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2109 | // Migrates the given object to a map whose field representations are the |
| 2110 | // lowest upper bound of all known representations for that field. |
| 2111 | static void MigrateInstance(Handle<JSObject> instance); |
| 2112 | |
| 2113 | // Migrates the given object only if the target map is already available, |
| 2114 | // or returns false if such a map is not yet available. |
| 2115 | static bool TryMigrateInstance(Handle<JSObject> instance); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2116 | |
| 2117 | // Sets the property value in a normalized object given (key, value, details). |
| 2118 | // Handles the special representation of JS global objects. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2119 | static void SetNormalizedProperty(Handle<JSObject> object, Handle<Name> name, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2120 | Handle<Object> value, |
| 2121 | PropertyDetails details); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2122 | static void SetDictionaryElement(Handle<JSObject> object, uint32_t index, |
| 2123 | Handle<Object> value, |
| 2124 | PropertyAttributes attributes); |
| 2125 | static void SetDictionaryArgumentsElement(Handle<JSObject> object, |
| 2126 | uint32_t index, |
| 2127 | Handle<Object> value, |
| 2128 | PropertyAttributes attributes); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2129 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2130 | static void OptimizeAsPrototype(Handle<JSObject> object, |
| 2131 | PrototypeOptimizationMode mode); |
| 2132 | static void ReoptimizeIfPrototype(Handle<JSObject> object); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2133 | static void LazyRegisterPrototypeUser(Handle<Map> user, Isolate* isolate); |
| 2134 | static void UpdatePrototypeUserRegistration(Handle<Map> old_map, |
| 2135 | Handle<Map> new_map, |
| 2136 | Isolate* isolate); |
| 2137 | static bool UnregisterPrototypeUser(Handle<Map> user, Isolate* isolate); |
| 2138 | static void InvalidatePrototypeChains(Map* map); |
| 2139 | |
| 2140 | // Alternative implementation of WeakFixedArray::NullCallback. |
| 2141 | class PrototypeRegistryCompactionCallback { |
| 2142 | public: |
| 2143 | static void Callback(Object* value, int old_index, int new_index); |
| 2144 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2145 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2146 | // Retrieve interceptors. |
| 2147 | InterceptorInfo* GetNamedInterceptor(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2148 | inline InterceptorInfo* GetIndexedInterceptor(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2149 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2150 | // Used from JSReceiver. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2151 | MUST_USE_RESULT static Maybe<PropertyAttributes> |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2152 | GetPropertyAttributesWithInterceptor(LookupIterator* it); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2153 | MUST_USE_RESULT static Maybe<PropertyAttributes> |
| 2154 | GetPropertyAttributesWithFailedAccessCheck(LookupIterator* it); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2155 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2156 | // Retrieves an AccessorPair property from the given object. Might return |
| 2157 | // undefined if the property doesn't exist or is of a different kind. |
| 2158 | MUST_USE_RESULT static MaybeHandle<Object> GetAccessor( |
| 2159 | Handle<JSObject> object, |
| 2160 | Handle<Name> name, |
| 2161 | AccessorComponent component); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2162 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2163 | // Defines an AccessorPair property on the given object. |
| 2164 | // TODO(mstarzinger): Rename to SetAccessor(). |
| 2165 | static MaybeHandle<Object> DefineAccessor(Handle<JSObject> object, |
| 2166 | Handle<Name> name, |
| 2167 | Handle<Object> getter, |
| 2168 | Handle<Object> setter, |
| 2169 | PropertyAttributes attributes); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2170 | static MaybeHandle<Object> DefineAccessor(LookupIterator* it, |
| 2171 | Handle<Object> getter, |
| 2172 | Handle<Object> setter, |
| 2173 | PropertyAttributes attributes); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2174 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2175 | // Defines an AccessorInfo property on the given object. |
| 2176 | MUST_USE_RESULT static MaybeHandle<Object> SetAccessor( |
| 2177 | Handle<JSObject> object, |
| 2178 | Handle<AccessorInfo> info); |
| 2179 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2180 | // The result must be checked first for exceptions. If there's no exception, |
| 2181 | // the output parameter |done| indicates whether the interceptor has a result |
| 2182 | // or not. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2183 | MUST_USE_RESULT static MaybeHandle<Object> GetPropertyWithInterceptor( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2184 | LookupIterator* it, bool* done); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2185 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2186 | // Accessors for hidden properties object. |
| 2187 | // |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2188 | // Hidden properties are not own properties of the object itself. Instead |
| 2189 | // they are stored in an auxiliary structure kept as an own property with a |
| 2190 | // special name Heap::hidden_properties_symbol(). But if the receiver is a |
| 2191 | // JSGlobalProxy then the auxiliary object is a property of its prototype, and |
| 2192 | // 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] | 2193 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2194 | // Sets a hidden property on this object. Returns this object if successful, |
| 2195 | // undefined if called on a detached proxy. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2196 | static Handle<Object> SetHiddenProperty(Handle<JSObject> object, |
| 2197 | Handle<Name> key, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2198 | Handle<Object> value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2199 | // 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] | 2200 | // if the property doesn't exist (or if called on a detached proxy), |
| 2201 | // otherwise returns the value set for the key. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2202 | Object* GetHiddenProperty(Handle<Name> key); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2203 | // Deletes a hidden property. Deleting a non-existing property is |
| 2204 | // considered successful. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2205 | static void DeleteHiddenProperty(Handle<JSObject> object, |
| 2206 | Handle<Name> key); |
| 2207 | // Returns true if the object has a property with the hidden string as name. |
| 2208 | static bool HasHiddenProperties(Handle<JSObject> object); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2209 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2210 | static void SetIdentityHash(Handle<JSObject> object, Handle<Smi> hash); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2211 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2212 | static void ValidateElements(Handle<JSObject> object); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2213 | |
| 2214 | // Makes sure that this object can contain HeapObject as elements. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2215 | static inline void EnsureCanContainHeapObjectElements(Handle<JSObject> obj); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2216 | |
| 2217 | // Makes sure that this object can contain the specified elements. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2218 | static inline void EnsureCanContainElements( |
| 2219 | Handle<JSObject> object, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2220 | Object** elements, |
| 2221 | uint32_t count, |
| 2222 | EnsureElementsMode mode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2223 | static inline void EnsureCanContainElements( |
| 2224 | Handle<JSObject> object, |
| 2225 | Handle<FixedArrayBase> elements, |
| 2226 | uint32_t length, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2227 | EnsureElementsMode mode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2228 | static void EnsureCanContainElements( |
| 2229 | Handle<JSObject> object, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2230 | Arguments* arguments, |
| 2231 | uint32_t first_arg, |
| 2232 | uint32_t arg_count, |
| 2233 | EnsureElementsMode mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2234 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2235 | // Would we convert a fast elements array to dictionary mode given |
| 2236 | // an access at key? |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2237 | bool WouldConvertToSlowElements(uint32_t index); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 2238 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2239 | // Computes the new capacity when expanding the elements of a JSObject. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2240 | static uint32_t NewElementsCapacity(uint32_t old_capacity) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2241 | // (old_capacity + 50%) + 16 |
| 2242 | return old_capacity + (old_capacity >> 1) + 16; |
| 2243 | } |
| 2244 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2245 | // These methods do not perform access checks! |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2246 | static void UpdateAllocationSite(Handle<JSObject> object, |
| 2247 | ElementsKind to_kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2248 | |
| 2249 | // Lookup interceptors are used for handling properties controlled by host |
| 2250 | // objects. |
| 2251 | inline bool HasNamedInterceptor(); |
| 2252 | inline bool HasIndexedInterceptor(); |
| 2253 | |
| 2254 | // Support functions for v8 api (needed for correct interceptor behavior). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2255 | MUST_USE_RESULT static Maybe<bool> HasRealNamedProperty( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2256 | Handle<JSObject> object, Handle<Name> name); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2257 | MUST_USE_RESULT static Maybe<bool> HasRealElementProperty( |
| 2258 | Handle<JSObject> object, uint32_t index); |
| 2259 | MUST_USE_RESULT static Maybe<bool> HasRealNamedCallbackProperty( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2260 | Handle<JSObject> object, Handle<Name> name); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2261 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2262 | // Get the header size for a JSObject. Used to compute the index of |
| 2263 | // internal fields as well as the number of internal fields. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2264 | static inline int GetHeaderSize(InstanceType instance_type); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2265 | inline int GetHeaderSize(); |
| 2266 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2267 | static inline int GetInternalFieldCount(Map* map); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2268 | inline int GetInternalFieldCount(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2269 | inline int GetInternalFieldOffset(int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2270 | inline Object* GetInternalField(int index); |
| 2271 | inline void SetInternalField(int index, Object* value); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2272 | inline void SetInternalField(int index, Smi* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2273 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2274 | void CollectOwnPropertyNames(KeyAccumulator* keys, |
| 2275 | PropertyFilter filter = ALL_PROPERTIES); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2276 | |
| 2277 | // Returns the number of properties on this object filtering out properties |
| 2278 | // with the specified attributes (ignoring interceptors). |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2279 | // TODO(jkummerow): Deprecated, only used by Object.observe. |
| 2280 | int NumberOfOwnElements(PropertyFilter filter); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2281 | // Returns the number of elements on this object filtering out elements |
| 2282 | // with the specified attributes (ignoring interceptors). |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2283 | // TODO(jkummerow): Deprecated, only used by Object.observe. |
| 2284 | int GetOwnElementKeys(FixedArray* storage, PropertyFilter filter); |
| 2285 | |
| 2286 | static void CollectOwnElementKeys(Handle<JSObject> object, |
| 2287 | KeyAccumulator* keys, |
| 2288 | PropertyFilter filter); |
| 2289 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2290 | static Handle<FixedArray> GetEnumPropertyKeys(Handle<JSObject> object); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2291 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2292 | // Returns a new map with all transitions dropped from the object's current |
| 2293 | // map and the ElementsKind set. |
| 2294 | static Handle<Map> GetElementsTransitionMap(Handle<JSObject> object, |
| 2295 | ElementsKind to_kind); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2296 | static void TransitionElementsKind(Handle<JSObject> object, |
| 2297 | ElementsKind to_kind); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2298 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2299 | // Always use this to migrate an object to a new map. |
| 2300 | // |expected_additional_properties| is only used for fast-to-slow transitions |
| 2301 | // and ignored otherwise. |
| 2302 | static void MigrateToMap(Handle<JSObject> object, Handle<Map> new_map, |
| 2303 | int expected_additional_properties = 0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2304 | |
| 2305 | // Convert the object to use the canonical dictionary |
| 2306 | // representation. If the object is expected to have additional properties |
| 2307 | // added this number can be indicated to have the backing store allocated to |
| 2308 | // an initial capacity for holding these properties. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2309 | static void NormalizeProperties(Handle<JSObject> object, |
| 2310 | PropertyNormalizationMode mode, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2311 | int expected_additional_properties, |
| 2312 | const char* reason); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2313 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2314 | // Convert and update the elements backing store to be a |
| 2315 | // SeededNumberDictionary dictionary. Returns the backing after conversion. |
| 2316 | static Handle<SeededNumberDictionary> NormalizeElements( |
| 2317 | Handle<JSObject> object); |
| 2318 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2319 | void RequireSlowElements(SeededNumberDictionary* dictionary); |
| 2320 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2321 | // Transform slow named properties to fast variants. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2322 | static void MigrateSlowToFast(Handle<JSObject> object, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2323 | int unused_property_fields, const char* reason); |
| 2324 | |
| 2325 | inline bool IsUnboxedDoubleField(FieldIndex index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2326 | |
| 2327 | // Access fast-case object properties at index. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2328 | static Handle<Object> FastPropertyAt(Handle<JSObject> object, |
| 2329 | Representation representation, |
| 2330 | FieldIndex index); |
| 2331 | inline Object* RawFastPropertyAt(FieldIndex index); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2332 | inline double RawFastDoublePropertyAt(FieldIndex index); |
| 2333 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2334 | inline void FastPropertyAtPut(FieldIndex index, Object* value); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2335 | inline void RawFastPropertyAtPut(FieldIndex index, Object* value); |
| 2336 | inline void RawFastDoublePropertyAtPut(FieldIndex index, double value); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2337 | inline void WriteToField(int descriptor, PropertyDetails details, |
| 2338 | Object* value); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2339 | inline void WriteToField(int descriptor, Object* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2340 | |
| 2341 | // Access to in object properties. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2342 | inline int GetInObjectPropertyOffset(int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2343 | inline Object* InObjectPropertyAt(int index); |
| 2344 | inline Object* InObjectPropertyAtPut(int index, |
| 2345 | Object* value, |
| 2346 | WriteBarrierMode mode |
| 2347 | = UPDATE_WRITE_BARRIER); |
| 2348 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2349 | // Set the object's prototype (only JSReceiver and null are allowed values). |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2350 | MUST_USE_RESULT static Maybe<bool> SetPrototype(Handle<JSObject> object, |
| 2351 | Handle<Object> value, |
| 2352 | bool from_javascript, |
| 2353 | ShouldThrow should_throw); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2354 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2355 | // Initializes the body starting at |start_offset|. It is responsibility of |
| 2356 | // the caller to initialize object header. Fill the pre-allocated fields with |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2357 | // pre_allocated_value and the rest with filler_value. |
| 2358 | // Note: this call does not update write barrier, the caller is responsible |
| 2359 | // to ensure that |filler_value| can be collected without WB here. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2360 | inline void InitializeBody(Map* map, int start_offset, |
| 2361 | Object* pre_allocated_value, Object* filler_value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2362 | |
| 2363 | // Check whether this object references another object |
| 2364 | bool ReferencesObject(Object* obj); |
| 2365 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2366 | MUST_USE_RESULT static Maybe<bool> PreventExtensions( |
| 2367 | Handle<JSObject> object, ShouldThrow should_throw); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2368 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2369 | static bool IsExtensible(Handle<JSObject> object); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2370 | |
| 2371 | // Called the first time an object is observed with ES7 Object.observe. |
| 2372 | static void SetObserved(Handle<JSObject> object); |
| 2373 | |
| 2374 | // Copy object. |
| 2375 | enum DeepCopyHints { kNoHints = 0, kObjectIsShallow = 1 }; |
| 2376 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2377 | MUST_USE_RESULT static MaybeHandle<JSObject> DeepCopy( |
| 2378 | Handle<JSObject> object, |
| 2379 | AllocationSiteUsageContext* site_context, |
| 2380 | DeepCopyHints hints = kNoHints); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2381 | // Deep copies given object with special handling for JSFunctions which |
| 2382 | // 1) must be Api functions and 2) are not copied but left as is. |
| 2383 | MUST_USE_RESULT static MaybeHandle<JSObject> DeepCopyApiBoilerplate( |
| 2384 | Handle<JSObject> object); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2385 | MUST_USE_RESULT static MaybeHandle<JSObject> DeepWalk( |
| 2386 | Handle<JSObject> object, |
| 2387 | AllocationSiteCreationContext* site_context); |
| 2388 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2389 | DECLARE_CAST(JSObject) |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2390 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2391 | // Dispatched behavior. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2392 | void JSObjectShortPrint(StringStream* accumulator); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2393 | DECLARE_PRINTER(JSObject) |
| 2394 | DECLARE_VERIFIER(JSObject) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2395 | #ifdef OBJECT_PRINT |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2396 | void PrintProperties(std::ostream& os); // NOLINT |
| 2397 | void PrintElements(std::ostream& os); // NOLINT |
| 2398 | #endif |
| 2399 | #if defined(DEBUG) || defined(OBJECT_PRINT) |
| 2400 | void PrintTransitions(std::ostream& os); // NOLINT |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2401 | #endif |
| 2402 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2403 | static void PrintElementsTransition( |
| 2404 | FILE* file, Handle<JSObject> object, |
| 2405 | ElementsKind from_kind, Handle<FixedArrayBase> from_elements, |
| 2406 | ElementsKind to_kind, Handle<FixedArrayBase> to_elements); |
| 2407 | |
| 2408 | void PrintInstanceMigration(FILE* file, Map* original_map, Map* new_map); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2409 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2410 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2411 | // Structure for collecting spill information about JSObjects. |
| 2412 | class SpillInformation { |
| 2413 | public: |
| 2414 | void Clear(); |
| 2415 | void Print(); |
| 2416 | int number_of_objects_; |
| 2417 | int number_of_objects_with_fast_properties_; |
| 2418 | int number_of_objects_with_fast_elements_; |
| 2419 | int number_of_fast_used_fields_; |
| 2420 | int number_of_fast_unused_fields_; |
| 2421 | int number_of_slow_used_properties_; |
| 2422 | int number_of_slow_unused_properties_; |
| 2423 | int number_of_fast_used_elements_; |
| 2424 | int number_of_fast_unused_elements_; |
| 2425 | int number_of_slow_used_elements_; |
| 2426 | int number_of_slow_unused_elements_; |
| 2427 | }; |
| 2428 | |
| 2429 | void IncrementSpillStatistics(SpillInformation* info); |
| 2430 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2431 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2432 | #ifdef VERIFY_HEAP |
| 2433 | // If a GC was caused while constructing this object, the elements pointer |
| 2434 | // may point to a one pointer filler map. The object won't be rooted, but |
| 2435 | // our heap verification code could stumble across it. |
| 2436 | bool ElementsAreSafeToExamine(); |
| 2437 | #endif |
| 2438 | |
| 2439 | Object* SlowReverseLookup(Object* value); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2440 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2441 | // Maximal number of elements (numbered 0 .. kMaxElementCount - 1). |
| 2442 | // Also maximal value of JSArray's length property. |
| 2443 | static const uint32_t kMaxElementCount = 0xffffffffu; |
| 2444 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2445 | // Constants for heuristics controlling conversion of fast elements |
| 2446 | // to slow elements. |
| 2447 | |
| 2448 | // Maximal gap that can be introduced by adding an element beyond |
| 2449 | // the current elements length. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2450 | static const uint32_t kMaxGap = 1024; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2451 | |
| 2452 | // Maximal length of fast elements array that won't be checked for |
| 2453 | // being dense enough on expansion. |
| 2454 | static const int kMaxUncheckedFastElementsLength = 5000; |
| 2455 | |
| 2456 | // Same as above but for old arrays. This limit is more strict. We |
| 2457 | // don't want to be wasteful with long lived objects. |
| 2458 | static const int kMaxUncheckedOldFastElementsLength = 500; |
| 2459 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2460 | // This constant applies only to the initial map of "global.Object" and |
| 2461 | // not to arbitrary other JSObject maps. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2462 | static const int kInitialGlobalObjectUnusedPropertiesCount = 4; |
| 2463 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2464 | static const int kMaxInstanceSize = 255 * kPointerSize; |
| 2465 | // When extending the backing storage for property values, we increase |
| 2466 | // its size by more than the 1 entry necessary, so sequentially adding fields |
| 2467 | // to the same object requires fewer allocations and copies. |
| 2468 | static const int kFieldsAdded = 3; |
| 2469 | |
| 2470 | // Layout description. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2471 | static const int kElementsOffset = JSReceiver::kHeaderSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2472 | static const int kHeaderSize = kElementsOffset + kPointerSize; |
| 2473 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2474 | STATIC_ASSERT(kHeaderSize == Internals::kJSObjectHeaderSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2475 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2476 | typedef FlexibleBodyDescriptor<JSReceiver::kPropertiesOffset> BodyDescriptor; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2477 | |
| 2478 | // Enqueue change record for Object.observe. May cause GC. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2479 | MUST_USE_RESULT static MaybeHandle<Object> EnqueueChangeRecord( |
| 2480 | Handle<JSObject> object, const char* type, Handle<Name> name, |
| 2481 | Handle<Object> old_value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2482 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2483 | // Gets the number of currently used elements. |
| 2484 | int GetFastElementsUsage(); |
| 2485 | |
| 2486 | static bool AllCanRead(LookupIterator* it); |
| 2487 | static bool AllCanWrite(LookupIterator* it); |
| 2488 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2489 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2490 | friend class JSReceiver; |
| 2491 | friend class Object; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2492 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2493 | // Used from Object::GetProperty(). |
| 2494 | MUST_USE_RESULT static MaybeHandle<Object> GetPropertyWithFailedAccessCheck( |
| 2495 | LookupIterator* it); |
| 2496 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2497 | MUST_USE_RESULT static Maybe<bool> SetPropertyWithFailedAccessCheck( |
| 2498 | LookupIterator* it, Handle<Object> value, ShouldThrow should_throw); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2499 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2500 | // Add a property to a slow-case object. |
| 2501 | static void AddSlowProperty(Handle<JSObject> object, |
| 2502 | Handle<Name> name, |
| 2503 | Handle<Object> value, |
| 2504 | PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2505 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2506 | MUST_USE_RESULT static Maybe<bool> DeletePropertyWithInterceptor( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2507 | LookupIterator* it, ShouldThrow should_throw); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2508 | |
| 2509 | bool ReferencesObjectFromElements(FixedArray* elements, |
| 2510 | ElementsKind kind, |
| 2511 | Object* object); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2512 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2513 | // Return the hash table backing store or the inline stored identity hash, |
| 2514 | // whatever is found. |
| 2515 | MUST_USE_RESULT Object* GetHiddenPropertiesHashTable(); |
| 2516 | |
| 2517 | // Return the hash table backing store for hidden properties. If there is no |
| 2518 | // backing store, allocate one. |
| 2519 | static Handle<ObjectHashTable> GetOrCreateHiddenPropertiesHashtable( |
| 2520 | Handle<JSObject> object); |
| 2521 | |
| 2522 | // Set the hidden property backing store to either a hash table or |
| 2523 | // the inline-stored identity hash. |
| 2524 | static Handle<Object> SetHiddenPropertiesHashTable( |
| 2525 | Handle<JSObject> object, |
| 2526 | Handle<Object> value); |
| 2527 | |
| 2528 | MUST_USE_RESULT Object* GetIdentityHash(); |
| 2529 | |
| 2530 | static Handle<Smi> GetOrCreateIdentityHash(Handle<JSObject> object); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2531 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2532 | static Handle<SeededNumberDictionary> GetNormalizedElementDictionary( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2533 | Handle<JSObject> object, Handle<FixedArrayBase> elements); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2534 | |
| 2535 | // Helper for fast versions of preventExtensions, seal, and freeze. |
| 2536 | // attrs is one of NONE, SEALED, or FROZEN (depending on the operation). |
| 2537 | template <PropertyAttributes attrs> |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2538 | MUST_USE_RESULT static Maybe<bool> PreventExtensionsWithTransition( |
| 2539 | Handle<JSObject> object, ShouldThrow should_throw); |
| 2540 | |
| 2541 | MUST_USE_RESULT static Maybe<bool> SetPrototypeUnobserved( |
| 2542 | Handle<JSObject> object, Handle<Object> value, bool from_javascript, |
| 2543 | ShouldThrow should_throw); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2544 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2545 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSObject); |
| 2546 | }; |
| 2547 | |
| 2548 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2549 | // JSAccessorPropertyDescriptor is just a JSObject with a specific initial |
| 2550 | // map. This initial map adds in-object properties for "get", "set", |
| 2551 | // "enumerable" and "configurable" properties, as assigned by the |
| 2552 | // FromPropertyDescriptor function for regular accessor properties. |
| 2553 | class JSAccessorPropertyDescriptor: public JSObject { |
| 2554 | public: |
| 2555 | // Offsets of object fields. |
| 2556 | static const int kGetOffset = JSObject::kHeaderSize; |
| 2557 | static const int kSetOffset = kGetOffset + kPointerSize; |
| 2558 | static const int kEnumerableOffset = kSetOffset + kPointerSize; |
| 2559 | static const int kConfigurableOffset = kEnumerableOffset + kPointerSize; |
| 2560 | static const int kSize = kConfigurableOffset + kPointerSize; |
| 2561 | // Indices of in-object properties. |
| 2562 | static const int kGetIndex = 0; |
| 2563 | static const int kSetIndex = 1; |
| 2564 | static const int kEnumerableIndex = 2; |
| 2565 | static const int kConfigurableIndex = 3; |
| 2566 | |
| 2567 | private: |
| 2568 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSAccessorPropertyDescriptor); |
| 2569 | }; |
| 2570 | |
| 2571 | |
| 2572 | // JSDataPropertyDescriptor is just a JSObject with a specific initial map. |
| 2573 | // This initial map adds in-object properties for "value", "writable", |
| 2574 | // "enumerable" and "configurable" properties, as assigned by the |
| 2575 | // FromPropertyDescriptor function for regular data properties. |
| 2576 | class JSDataPropertyDescriptor: public JSObject { |
| 2577 | public: |
| 2578 | // Offsets of object fields. |
| 2579 | static const int kValueOffset = JSObject::kHeaderSize; |
| 2580 | static const int kWritableOffset = kValueOffset + kPointerSize; |
| 2581 | static const int kEnumerableOffset = kWritableOffset + kPointerSize; |
| 2582 | static const int kConfigurableOffset = kEnumerableOffset + kPointerSize; |
| 2583 | static const int kSize = kConfigurableOffset + kPointerSize; |
| 2584 | // Indices of in-object properties. |
| 2585 | static const int kValueIndex = 0; |
| 2586 | static const int kWritableIndex = 1; |
| 2587 | static const int kEnumerableIndex = 2; |
| 2588 | static const int kConfigurableIndex = 3; |
| 2589 | |
| 2590 | private: |
| 2591 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSDataPropertyDescriptor); |
| 2592 | }; |
| 2593 | |
| 2594 | |
| 2595 | // JSIteratorResult is just a JSObject with a specific initial map. |
| 2596 | // This initial map adds in-object properties for "done" and "value", |
| 2597 | // as specified by ES6 section 25.1.1.3 The IteratorResult Interface |
| 2598 | class JSIteratorResult: public JSObject { |
| 2599 | public: |
| 2600 | // Offsets of object fields. |
| 2601 | static const int kValueOffset = JSObject::kHeaderSize; |
| 2602 | static const int kDoneOffset = kValueOffset + kPointerSize; |
| 2603 | static const int kSize = kDoneOffset + kPointerSize; |
| 2604 | // Indices of in-object properties. |
| 2605 | static const int kValueIndex = 0; |
| 2606 | static const int kDoneIndex = 1; |
| 2607 | |
| 2608 | private: |
| 2609 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSIteratorResult); |
| 2610 | }; |
| 2611 | |
| 2612 | |
| 2613 | // Common superclass for JSSloppyArgumentsObject and JSStrictArgumentsObject. |
| 2614 | class JSArgumentsObject: public JSObject { |
| 2615 | public: |
| 2616 | // Offsets of object fields. |
| 2617 | static const int kLengthOffset = JSObject::kHeaderSize; |
| 2618 | static const int kHeaderSize = kLengthOffset + kPointerSize; |
| 2619 | // Indices of in-object properties. |
| 2620 | static const int kLengthIndex = 0; |
| 2621 | |
| 2622 | private: |
| 2623 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSArgumentsObject); |
| 2624 | }; |
| 2625 | |
| 2626 | |
| 2627 | // JSSloppyArgumentsObject is just a JSObject with specific initial map. |
| 2628 | // This initial map adds in-object properties for "length" and "callee". |
| 2629 | class JSSloppyArgumentsObject: public JSArgumentsObject { |
| 2630 | public: |
| 2631 | // Offsets of object fields. |
| 2632 | static const int kCalleeOffset = JSArgumentsObject::kHeaderSize; |
| 2633 | static const int kSize = kCalleeOffset + kPointerSize; |
| 2634 | // Indices of in-object properties. |
| 2635 | static const int kCalleeIndex = 1; |
| 2636 | |
| 2637 | private: |
| 2638 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSSloppyArgumentsObject); |
| 2639 | }; |
| 2640 | |
| 2641 | |
| 2642 | // JSStrictArgumentsObject is just a JSObject with specific initial map. |
| 2643 | // This initial map adds an in-object property for "length". |
| 2644 | class JSStrictArgumentsObject: public JSArgumentsObject { |
| 2645 | public: |
| 2646 | // Offsets of object fields. |
| 2647 | static const int kSize = JSArgumentsObject::kHeaderSize; |
| 2648 | |
| 2649 | private: |
| 2650 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSStrictArgumentsObject); |
| 2651 | }; |
| 2652 | |
| 2653 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2654 | // Common superclass for FixedArrays that allow implementations to share |
| 2655 | // common accessors and some code paths. |
| 2656 | class FixedArrayBase: public HeapObject { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2657 | public: |
| 2658 | // [length]: length of the array. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2659 | inline int length() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2660 | inline void set_length(int value); |
| 2661 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2662 | // Get and set the length using acquire loads and release stores. |
| 2663 | inline int synchronized_length() const; |
| 2664 | inline void synchronized_set_length(int value); |
| 2665 | |
| 2666 | DECLARE_CAST(FixedArrayBase) |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2667 | |
| 2668 | // Layout description. |
| 2669 | // Length is smi tagged when it is stored. |
| 2670 | static const int kLengthOffset = HeapObject::kHeaderSize; |
| 2671 | static const int kHeaderSize = kLengthOffset + kPointerSize; |
| 2672 | }; |
| 2673 | |
| 2674 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2675 | class FixedDoubleArray; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2676 | class IncrementalMarking; |
| 2677 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2678 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2679 | // FixedArray describes fixed-sized arrays with element type Object*. |
| 2680 | class FixedArray: public FixedArrayBase { |
| 2681 | public: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2682 | // Setter and getter for elements. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2683 | inline Object* get(int index) const; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2684 | static inline Handle<Object> get(FixedArray* array, int index, |
| 2685 | Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2686 | // Setter that uses write barrier. |
| 2687 | inline void set(int index, Object* value); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2688 | inline bool is_the_hole(int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2689 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2690 | // Setter that doesn't need write barrier. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2691 | inline void set(int index, Smi* value); |
| 2692 | // Setter with explicit barrier mode. |
| 2693 | inline void set(int index, Object* value, WriteBarrierMode mode); |
| 2694 | |
| 2695 | // Setters for frequently used oddballs located in old space. |
| 2696 | inline void set_undefined(int index); |
| 2697 | inline void set_null(int index); |
| 2698 | inline void set_the_hole(int index); |
| 2699 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2700 | inline Object** GetFirstElementAddress(); |
| 2701 | inline bool ContainsOnlySmisOrHoles(); |
| 2702 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2703 | // Gives access to raw memory which stores the array's data. |
| 2704 | inline Object** data_start(); |
| 2705 | |
| 2706 | inline void FillWithHoles(int from, int to); |
| 2707 | |
| 2708 | // Shrink length and insert filler objects. |
| 2709 | void Shrink(int length); |
| 2710 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2711 | // Copy a sub array from the receiver to dest. |
| 2712 | void CopyTo(int pos, FixedArray* dest, int dest_pos, int len); |
| 2713 | |
| 2714 | // Garbage collection support. |
| 2715 | static int SizeFor(int length) { return kHeaderSize + length * kPointerSize; } |
| 2716 | |
| 2717 | // Code Generation support. |
| 2718 | static int OffsetOfElementAt(int index) { return SizeFor(index); } |
| 2719 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2720 | // Garbage collection support. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2721 | inline Object** RawFieldOfElementAt(int index); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2722 | |
| 2723 | DECLARE_CAST(FixedArray) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2724 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2725 | // Maximal allowed size, in bytes, of a single FixedArray. |
| 2726 | // Prevents overflowing size computations, as well as extreme memory |
| 2727 | // consumption. |
Ben Murdoch | 692be65 | 2012-01-10 18:47:50 +0000 | [diff] [blame] | 2728 | static const int kMaxSize = 128 * MB * kPointerSize; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2729 | // Maximally allowed length of a FixedArray. |
| 2730 | static const int kMaxLength = (kMaxSize - kHeaderSize) / kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2731 | |
| 2732 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2733 | DECLARE_PRINTER(FixedArray) |
| 2734 | DECLARE_VERIFIER(FixedArray) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2735 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2736 | // Checks if two FixedArrays have identical contents. |
| 2737 | bool IsEqualTo(FixedArray* other); |
| 2738 | #endif |
| 2739 | |
| 2740 | // Swap two elements in a pair of arrays. If this array and the |
| 2741 | // numbers array are the same object, the elements are only swapped |
| 2742 | // once. |
| 2743 | void SwapPairs(FixedArray* numbers, int i, int j); |
| 2744 | |
| 2745 | // Sort prefix of this array and the numbers array as pairs wrt. the |
| 2746 | // numbers. If the numbers array and the this array are the same |
| 2747 | // object, the prefix of this array is sorted. |
| 2748 | void SortPairs(FixedArray* numbers, uint32_t len); |
| 2749 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2750 | typedef FlexibleBodyDescriptor<kHeaderSize> BodyDescriptor; |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2751 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2752 | protected: |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 2753 | // Set operation on FixedArray without using write barriers. Can |
| 2754 | // only be used for storing old space objects or smis. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2755 | static inline void NoWriteBarrierSet(FixedArray* array, |
| 2756 | int index, |
| 2757 | Object* value); |
| 2758 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2759 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2760 | STATIC_ASSERT(kHeaderSize == Internals::kFixedArrayHeaderSize); |
| 2761 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2762 | DISALLOW_IMPLICIT_CONSTRUCTORS(FixedArray); |
| 2763 | }; |
| 2764 | |
| 2765 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2766 | // FixedDoubleArray describes fixed-sized arrays with element type double. |
| 2767 | class FixedDoubleArray: public FixedArrayBase { |
| 2768 | public: |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2769 | // Setter and getter for elements. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2770 | inline double get_scalar(int index); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2771 | inline uint64_t get_representation(int index); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2772 | static inline Handle<Object> get(FixedDoubleArray* array, int index, |
| 2773 | Isolate* isolate); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2774 | inline void set(int index, double value); |
| 2775 | inline void set_the_hole(int index); |
| 2776 | |
| 2777 | // Checking for the hole. |
| 2778 | inline bool is_the_hole(int index); |
| 2779 | |
| 2780 | // Garbage collection support. |
| 2781 | inline static int SizeFor(int length) { |
| 2782 | return kHeaderSize + length * kDoubleSize; |
| 2783 | } |
| 2784 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2785 | // Gives access to raw memory which stores the array's data. |
| 2786 | inline double* data_start(); |
| 2787 | |
| 2788 | inline void FillWithHoles(int from, int to); |
| 2789 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2790 | // Code Generation support. |
| 2791 | static int OffsetOfElementAt(int index) { return SizeFor(index); } |
| 2792 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2793 | DECLARE_CAST(FixedDoubleArray) |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2794 | |
| 2795 | // Maximal allowed size, in bytes, of a single FixedDoubleArray. |
| 2796 | // Prevents overflowing size computations, as well as extreme memory |
| 2797 | // consumption. |
| 2798 | static const int kMaxSize = 512 * MB; |
| 2799 | // Maximally allowed length of a FixedArray. |
| 2800 | static const int kMaxLength = (kMaxSize - kHeaderSize) / kDoubleSize; |
| 2801 | |
| 2802 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2803 | DECLARE_PRINTER(FixedDoubleArray) |
| 2804 | DECLARE_VERIFIER(FixedDoubleArray) |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2805 | |
| 2806 | private: |
| 2807 | DISALLOW_IMPLICIT_CONSTRUCTORS(FixedDoubleArray); |
| 2808 | }; |
| 2809 | |
| 2810 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2811 | class WeakFixedArray : public FixedArray { |
| 2812 | public: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2813 | // 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] | 2814 | // This function does not check if the value exists already, callers must |
| 2815 | // ensure this themselves if necessary. |
| 2816 | static Handle<WeakFixedArray> Add(Handle<Object> maybe_array, |
| 2817 | Handle<HeapObject> value, |
| 2818 | int* assigned_index = NULL); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2819 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2820 | // Returns true if an entry was found and removed. |
| 2821 | bool Remove(Handle<HeapObject> value); |
| 2822 | |
| 2823 | class NullCallback { |
| 2824 | public: |
| 2825 | static void Callback(Object* value, int old_index, int new_index) {} |
| 2826 | }; |
| 2827 | |
| 2828 | template <class CompactionCallback> |
| 2829 | void Compact(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2830 | |
| 2831 | inline Object* Get(int index) const; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2832 | inline void Clear(int index); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2833 | inline int Length() const; |
| 2834 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2835 | inline bool IsEmptySlot(int index) const; |
| 2836 | static Object* Empty() { return Smi::FromInt(0); } |
| 2837 | |
| 2838 | class Iterator { |
| 2839 | public: |
| 2840 | explicit Iterator(Object* maybe_array) : list_(NULL) { Reset(maybe_array); } |
| 2841 | void Reset(Object* maybe_array); |
| 2842 | |
| 2843 | template <class T> |
| 2844 | inline T* Next(); |
| 2845 | |
| 2846 | private: |
| 2847 | int index_; |
| 2848 | WeakFixedArray* list_; |
| 2849 | #ifdef DEBUG |
| 2850 | int last_used_index_; |
| 2851 | DisallowHeapAllocation no_gc_; |
| 2852 | #endif // DEBUG |
| 2853 | DISALLOW_COPY_AND_ASSIGN(Iterator); |
| 2854 | }; |
| 2855 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2856 | DECLARE_CAST(WeakFixedArray) |
| 2857 | |
| 2858 | private: |
| 2859 | static const int kLastUsedIndexIndex = 0; |
| 2860 | static const int kFirstIndex = 1; |
| 2861 | |
| 2862 | static Handle<WeakFixedArray> Allocate( |
| 2863 | Isolate* isolate, int size, Handle<WeakFixedArray> initialize_from); |
| 2864 | |
| 2865 | static void Set(Handle<WeakFixedArray> array, int index, |
| 2866 | Handle<HeapObject> value); |
| 2867 | inline void clear(int index); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2868 | |
| 2869 | inline int last_used_index() const; |
| 2870 | inline void set_last_used_index(int index); |
| 2871 | |
| 2872 | // Disallow inherited setters. |
| 2873 | void set(int index, Smi* value); |
| 2874 | void set(int index, Object* value); |
| 2875 | void set(int index, Object* value, WriteBarrierMode mode); |
| 2876 | DISALLOW_IMPLICIT_CONSTRUCTORS(WeakFixedArray); |
| 2877 | }; |
| 2878 | |
| 2879 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2880 | // Generic array grows dynamically with O(1) amortized insertion. |
| 2881 | class ArrayList : public FixedArray { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2882 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2883 | enum AddMode { |
| 2884 | kNone, |
| 2885 | // Use this if GC can delete elements from the array. |
| 2886 | kReloadLengthAfterAllocation, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2887 | }; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2888 | static Handle<ArrayList> Add(Handle<ArrayList> array, Handle<Object> obj, |
| 2889 | AddMode mode = kNone); |
| 2890 | static Handle<ArrayList> Add(Handle<ArrayList> array, Handle<Object> obj1, |
| 2891 | Handle<Object> obj2, AddMode = kNone); |
| 2892 | inline int Length(); |
| 2893 | inline void SetLength(int length); |
| 2894 | inline Object* Get(int index); |
| 2895 | inline Object** Slot(int index); |
| 2896 | inline void Set(int index, Object* obj); |
| 2897 | inline void Clear(int index, Object* undefined); |
| 2898 | bool IsFull(); |
| 2899 | DECLARE_CAST(ArrayList) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2900 | |
| 2901 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2902 | static Handle<ArrayList> EnsureSpace(Handle<ArrayList> array, int length); |
| 2903 | static const int kLengthIndex = 0; |
| 2904 | static const int kFirstIndex = 1; |
| 2905 | DISALLOW_IMPLICIT_CONSTRUCTORS(ArrayList); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2906 | }; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2907 | |
| 2908 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2909 | // DescriptorArrays are fixed arrays used to hold instance descriptors. |
| 2910 | // The format of the these objects is: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2911 | // [0]: Number of descriptors |
| 2912 | // [1]: Either Smi(0) if uninitialized, or a pointer to small fixed array: |
| 2913 | // [0]: pointer to fixed array with enum cache |
| 2914 | // [1]: either Smi(0) or pointer to fixed array with indices |
| 2915 | // [2]: first key |
| 2916 | // [2 + number of descriptors * kDescriptorSize]: start of slack |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2917 | class DescriptorArray: public FixedArray { |
| 2918 | public: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2919 | // Returns true for both shared empty_descriptor_array and for smis, which the |
| 2920 | // map uses to encode additional bit fields when the descriptor array is not |
| 2921 | // yet used. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2922 | inline bool IsEmpty(); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2923 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2924 | // Returns the number of descriptors in the array. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2925 | inline int number_of_descriptors(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2926 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2927 | inline int number_of_descriptors_storage(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2928 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2929 | inline int NumberOfSlackDescriptors(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2930 | |
| 2931 | inline void SetNumberOfDescriptors(int number_of_descriptors); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2932 | inline int number_of_entries(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2933 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2934 | inline bool HasEnumCache(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2935 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2936 | inline void CopyEnumCacheFrom(DescriptorArray* array); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2937 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2938 | inline FixedArray* GetEnumCache(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2939 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2940 | inline bool HasEnumIndicesCache(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2941 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2942 | inline FixedArray* GetEnumIndicesCache(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2943 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2944 | inline Object** GetEnumCacheSlot(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2945 | |
| 2946 | void ClearEnumCache(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2947 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2948 | // Initialize or change the enum cache, |
| 2949 | // using the supplied storage for the small "bridge". |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2950 | static void SetEnumCache(Handle<DescriptorArray> descriptors, |
| 2951 | Isolate* isolate, Handle<FixedArray> new_cache, |
| 2952 | Handle<FixedArray> new_index_cache); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2953 | |
| 2954 | // Accessors for fetching instance descriptor at descriptor number. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2955 | inline Name* GetKey(int descriptor_number); |
| 2956 | inline Object** GetKeySlot(int descriptor_number); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2957 | inline Object* GetValue(int descriptor_number); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2958 | inline void SetValue(int descriptor_number, Object* value); |
| 2959 | inline Object** GetValueSlot(int descriptor_number); |
| 2960 | static inline int GetValueOffset(int descriptor_number); |
| 2961 | inline Object** GetDescriptorStartSlot(int descriptor_number); |
| 2962 | inline Object** GetDescriptorEndSlot(int descriptor_number); |
| 2963 | inline PropertyDetails GetDetails(int descriptor_number); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2964 | inline PropertyType GetType(int descriptor_number); |
| 2965 | inline int GetFieldIndex(int descriptor_number); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 2966 | FieldType* GetFieldType(int descriptor_number); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2967 | inline Object* GetConstant(int descriptor_number); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2968 | inline Object* GetCallbacksObject(int descriptor_number); |
| 2969 | inline AccessorDescriptor* GetCallbacks(int descriptor_number); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2970 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2971 | inline Name* GetSortedKey(int descriptor_number); |
| 2972 | inline int GetSortedKeyIndex(int descriptor_number); |
| 2973 | inline void SetSortedKey(int pointer, int descriptor_number); |
| 2974 | inline void SetRepresentation(int descriptor_number, |
| 2975 | Representation representation); |
| 2976 | |
| 2977 | // Accessor for complete descriptor. |
| 2978 | inline void Get(int descriptor_number, Descriptor* desc); |
| 2979 | inline void Set(int descriptor_number, Descriptor* desc); |
| 2980 | void Replace(int descriptor_number, Descriptor* descriptor); |
| 2981 | |
| 2982 | // Append automatically sets the enumeration index. This should only be used |
| 2983 | // to add descriptors in bulk at the end, followed by sorting the descriptor |
| 2984 | // array. |
| 2985 | inline void Append(Descriptor* desc); |
| 2986 | |
| 2987 | static Handle<DescriptorArray> CopyUpTo(Handle<DescriptorArray> desc, |
| 2988 | int enumeration_index, |
| 2989 | int slack = 0); |
| 2990 | |
| 2991 | static Handle<DescriptorArray> CopyUpToAddAttributes( |
| 2992 | Handle<DescriptorArray> desc, |
| 2993 | int enumeration_index, |
| 2994 | PropertyAttributes attributes, |
| 2995 | int slack = 0); |
| 2996 | |
| 2997 | // Sort the instance descriptors by the hash codes of their keys. |
| 2998 | void Sort(); |
| 2999 | |
| 3000 | // Search the instance descriptors for given name. |
| 3001 | INLINE(int Search(Name* name, int number_of_own_descriptors)); |
| 3002 | |
| 3003 | // As the above, but uses DescriptorLookupCache and updates it when |
| 3004 | // necessary. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 3005 | INLINE(int SearchWithCache(Isolate* isolate, Name* name, Map* map)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3006 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3007 | bool IsEqualUpTo(DescriptorArray* desc, int nof_descriptors); |
| 3008 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3009 | // Allocates a DescriptorArray, but returns the singleton |
| 3010 | // empty descriptor array object if number_of_descriptors is 0. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 3011 | static Handle<DescriptorArray> Allocate( |
| 3012 | Isolate* isolate, int number_of_descriptors, int slack, |
| 3013 | PretenureFlag pretenure = NOT_TENURED); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3014 | |
| 3015 | DECLARE_CAST(DescriptorArray) |
| 3016 | |
| 3017 | // Constant for denoting key was not found. |
| 3018 | static const int kNotFound = -1; |
| 3019 | |
| 3020 | static const int kDescriptorLengthIndex = 0; |
| 3021 | static const int kEnumCacheIndex = 1; |
| 3022 | static const int kFirstIndex = 2; |
| 3023 | |
| 3024 | // The length of the "bridge" to the enum cache. |
| 3025 | static const int kEnumCacheBridgeLength = 2; |
| 3026 | static const int kEnumCacheBridgeCacheIndex = 0; |
| 3027 | static const int kEnumCacheBridgeIndicesCacheIndex = 1; |
| 3028 | |
| 3029 | // Layout description. |
| 3030 | static const int kDescriptorLengthOffset = FixedArray::kHeaderSize; |
| 3031 | static const int kEnumCacheOffset = kDescriptorLengthOffset + kPointerSize; |
| 3032 | static const int kFirstOffset = kEnumCacheOffset + kPointerSize; |
| 3033 | |
| 3034 | // Layout description for the bridge array. |
| 3035 | static const int kEnumCacheBridgeCacheOffset = FixedArray::kHeaderSize; |
| 3036 | |
| 3037 | // Layout of descriptor. |
| 3038 | static const int kDescriptorKey = 0; |
| 3039 | static const int kDescriptorDetails = 1; |
| 3040 | static const int kDescriptorValue = 2; |
| 3041 | static const int kDescriptorSize = 3; |
| 3042 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3043 | #if defined(DEBUG) || defined(OBJECT_PRINT) |
| 3044 | // For our gdb macros, we should perhaps change these in the future. |
| 3045 | void Print(); |
| 3046 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3047 | // Print all the descriptors. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3048 | void PrintDescriptors(std::ostream& os); // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3049 | #endif |
| 3050 | |
| 3051 | #ifdef DEBUG |
| 3052 | // Is the descriptor array sorted and without duplicates? |
| 3053 | bool IsSortedNoDuplicates(int valid_descriptors = -1); |
| 3054 | |
| 3055 | // Is the descriptor array consistent with the back pointers in targets? |
| 3056 | bool IsConsistentWithBackPointers(Map* current_map); |
| 3057 | |
| 3058 | // Are two DescriptorArrays equal? |
| 3059 | bool IsEqualTo(DescriptorArray* other); |
| 3060 | #endif |
| 3061 | |
| 3062 | // Returns the fixed array length required to hold number_of_descriptors |
| 3063 | // descriptors. |
| 3064 | static int LengthFor(int number_of_descriptors) { |
| 3065 | return ToKeyIndex(number_of_descriptors); |
| 3066 | } |
| 3067 | |
| 3068 | private: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3069 | // An entry in a DescriptorArray, represented as an (array, index) pair. |
| 3070 | class Entry { |
| 3071 | public: |
| 3072 | inline explicit Entry(DescriptorArray* descs, int index) : |
| 3073 | descs_(descs), index_(index) { } |
| 3074 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3075 | inline PropertyType type(); |
| 3076 | inline Object* GetCallbackObject(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3077 | |
| 3078 | private: |
| 3079 | DescriptorArray* descs_; |
| 3080 | int index_; |
| 3081 | }; |
| 3082 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3083 | // Conversion from descriptor number to array indices. |
| 3084 | static int ToKeyIndex(int descriptor_number) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3085 | return kFirstIndex + |
| 3086 | (descriptor_number * kDescriptorSize) + |
| 3087 | kDescriptorKey; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3088 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 3089 | |
| 3090 | static int ToDetailsIndex(int descriptor_number) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3091 | return kFirstIndex + |
| 3092 | (descriptor_number * kDescriptorSize) + |
| 3093 | kDescriptorDetails; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 3094 | } |
| 3095 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3096 | static int ToValueIndex(int descriptor_number) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3097 | return kFirstIndex + |
| 3098 | (descriptor_number * kDescriptorSize) + |
| 3099 | kDescriptorValue; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3100 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3101 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3102 | // Transfer a complete descriptor from the src descriptor array to this |
| 3103 | // descriptor array. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3104 | void CopyFrom(int index, DescriptorArray* src); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3105 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3106 | inline void SetDescriptor(int descriptor_number, Descriptor* desc); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3107 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3108 | // Swap first and second descriptor. |
| 3109 | inline void SwapSortedKeys(int first, int second); |
| 3110 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3111 | DISALLOW_IMPLICIT_CONSTRUCTORS(DescriptorArray); |
| 3112 | }; |
| 3113 | |
| 3114 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3115 | enum SearchMode { ALL_ENTRIES, VALID_ENTRIES }; |
| 3116 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3117 | template <SearchMode search_mode, typename T> |
| 3118 | inline int Search(T* array, Name* name, int valid_entries = 0, |
| 3119 | int* out_insertion_index = NULL); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3120 | |
| 3121 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3122 | // HashTable is a subclass of FixedArray that implements a hash table |
| 3123 | // that uses open addressing and quadratic probing. |
| 3124 | // |
| 3125 | // In order for the quadratic probing to work, elements that have not |
| 3126 | // yet been used and elements that have been deleted are |
| 3127 | // distinguished. Probing continues when deleted elements are |
| 3128 | // encountered and stops when unused elements are encountered. |
| 3129 | // |
| 3130 | // - Elements with key == undefined have not been used yet. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3131 | // - Elements with key == the_hole have been deleted. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3132 | // |
| 3133 | // The hash table class is parameterized with a Shape and a Key. |
| 3134 | // Shape must be a class with the following interface: |
| 3135 | // class ExampleShape { |
| 3136 | // public: |
| 3137 | // // Tells whether key matches other. |
| 3138 | // static bool IsMatch(Key key, Object* other); |
| 3139 | // // Returns the hash value for key. |
| 3140 | // static uint32_t Hash(Key key); |
| 3141 | // // Returns the hash value for object. |
| 3142 | // static uint32_t HashForObject(Key key, Object* object); |
| 3143 | // // Convert key to an object. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3144 | // static inline Handle<Object> AsHandle(Isolate* isolate, Key key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3145 | // // The prefix size indicates number of elements in the beginning |
| 3146 | // // of the backing storage. |
| 3147 | // static const int kPrefixSize = ..; |
| 3148 | // // The Element size indicates number of elements per entry. |
| 3149 | // static const int kEntrySize = ..; |
| 3150 | // }; |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3151 | // The prefix size indicates an amount of memory in the |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3152 | // beginning of the backing storage that can be used for non-element |
| 3153 | // information by subclasses. |
| 3154 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3155 | template<typename Key> |
| 3156 | class BaseShape { |
| 3157 | public: |
| 3158 | static const bool UsesSeed = false; |
| 3159 | static uint32_t Hash(Key key) { return 0; } |
| 3160 | static uint32_t SeededHash(Key key, uint32_t seed) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3161 | DCHECK(UsesSeed); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3162 | return Hash(key); |
| 3163 | } |
| 3164 | static uint32_t HashForObject(Key key, Object* object) { return 0; } |
| 3165 | static uint32_t SeededHashForObject(Key key, uint32_t seed, Object* object) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3166 | DCHECK(UsesSeed); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3167 | return HashForObject(key, object); |
| 3168 | } |
| 3169 | }; |
| 3170 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3171 | |
| 3172 | class HashTableBase : public FixedArray { |
| 3173 | public: |
| 3174 | // Returns the number of elements in the hash table. |
| 3175 | inline int NumberOfElements(); |
| 3176 | |
| 3177 | // Returns the number of deleted elements in the hash table. |
| 3178 | inline int NumberOfDeletedElements(); |
| 3179 | |
| 3180 | // Returns the capacity of the hash table. |
| 3181 | inline int Capacity(); |
| 3182 | |
| 3183 | // ElementAdded should be called whenever an element is added to a |
| 3184 | // hash table. |
| 3185 | inline void ElementAdded(); |
| 3186 | |
| 3187 | // ElementRemoved should be called whenever an element is removed from |
| 3188 | // a hash table. |
| 3189 | inline void ElementRemoved(); |
| 3190 | inline void ElementsRemoved(int n); |
| 3191 | |
| 3192 | // Computes the required capacity for a table holding the given |
| 3193 | // number of elements. May be more than HashTable::kMaxCapacity. |
| 3194 | static inline int ComputeCapacity(int at_least_space_for); |
| 3195 | |
| 3196 | // Tells whether k is a real key. The hole and undefined are not allowed |
| 3197 | // as keys and can be used to indicate missing or deleted elements. |
| 3198 | inline bool IsKey(Object* k); |
| 3199 | |
| 3200 | // Compute the probe offset (quadratic probing). |
| 3201 | INLINE(static uint32_t GetProbeOffset(uint32_t n)) { |
| 3202 | return (n + n * n) >> 1; |
| 3203 | } |
| 3204 | |
| 3205 | static const int kNumberOfElementsIndex = 0; |
| 3206 | static const int kNumberOfDeletedElementsIndex = 1; |
| 3207 | static const int kCapacityIndex = 2; |
| 3208 | static const int kPrefixStartIndex = 3; |
| 3209 | |
| 3210 | // Constant used for denoting a absent entry. |
| 3211 | static const int kNotFound = -1; |
| 3212 | |
| 3213 | protected: |
| 3214 | // Update the number of elements in the hash table. |
| 3215 | inline void SetNumberOfElements(int nof); |
| 3216 | |
| 3217 | // Update the number of deleted elements in the hash table. |
| 3218 | inline void SetNumberOfDeletedElements(int nod); |
| 3219 | |
| 3220 | // Returns probe entry. |
| 3221 | static uint32_t GetProbe(uint32_t hash, uint32_t number, uint32_t size) { |
| 3222 | DCHECK(base::bits::IsPowerOfTwo32(size)); |
| 3223 | return (hash + GetProbeOffset(number)) & (size - 1); |
| 3224 | } |
| 3225 | |
| 3226 | inline static uint32_t FirstProbe(uint32_t hash, uint32_t size) { |
| 3227 | return hash & (size - 1); |
| 3228 | } |
| 3229 | |
| 3230 | inline static uint32_t NextProbe( |
| 3231 | uint32_t last, uint32_t number, uint32_t size) { |
| 3232 | return (last + number) & (size - 1); |
| 3233 | } |
| 3234 | }; |
| 3235 | |
| 3236 | |
| 3237 | template <typename Derived, typename Shape, typename Key> |
| 3238 | class HashTable : public HashTableBase { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3239 | public: |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3240 | // Wrapper methods |
| 3241 | inline uint32_t Hash(Key key) { |
| 3242 | if (Shape::UsesSeed) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3243 | return Shape::SeededHash(key, GetHeap()->HashSeed()); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3244 | } else { |
| 3245 | return Shape::Hash(key); |
| 3246 | } |
| 3247 | } |
| 3248 | |
| 3249 | inline uint32_t HashForObject(Key key, Object* object) { |
| 3250 | if (Shape::UsesSeed) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3251 | return Shape::SeededHashForObject(key, GetHeap()->HashSeed(), object); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3252 | } else { |
| 3253 | return Shape::HashForObject(key, object); |
| 3254 | } |
| 3255 | } |
| 3256 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3257 | // Returns a new HashTable object. |
| 3258 | MUST_USE_RESULT static Handle<Derived> New( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3259 | Isolate* isolate, int at_least_space_for, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3260 | MinimumCapacity capacity_option = USE_DEFAULT_MINIMUM_CAPACITY, |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3261 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3262 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3263 | DECLARE_CAST(HashTable) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3264 | |
| 3265 | // Garbage collection support. |
| 3266 | void IteratePrefix(ObjectVisitor* visitor); |
| 3267 | void IterateElements(ObjectVisitor* visitor); |
| 3268 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3269 | // Find entry for key otherwise return kNotFound. |
| 3270 | inline int FindEntry(Key key); |
| 3271 | inline int FindEntry(Isolate* isolate, Key key, int32_t hash); |
| 3272 | int FindEntry(Isolate* isolate, Key key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3273 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3274 | // Rehashes the table in-place. |
| 3275 | void Rehash(Key key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3276 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3277 | // Returns the key at entry. |
| 3278 | Object* KeyAt(int entry) { return get(EntryToIndex(entry)); } |
| 3279 | |
| 3280 | static const int kElementsStartIndex = kPrefixStartIndex + Shape::kPrefixSize; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 3281 | static const int kEntrySize = Shape::kEntrySize; |
| 3282 | static const int kElementsStartOffset = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3283 | kHeaderSize + kElementsStartIndex * kPointerSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3284 | static const int kCapacityOffset = |
| 3285 | kHeaderSize + kCapacityIndex * kPointerSize; |
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 | // Returns the index for an entry (of the key) |
| 3288 | static inline int EntryToIndex(int entry) { |
| 3289 | return (entry * kEntrySize) + kElementsStartIndex; |
| 3290 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3291 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3292 | protected: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3293 | friend class ObjectHashTable; |
| 3294 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3295 | // Find the entry at which to insert element with the given key that |
| 3296 | // has the given hash value. |
| 3297 | uint32_t FindInsertionEntry(uint32_t hash); |
| 3298 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3299 | // Attempt to shrink hash table after removal of key. |
| 3300 | MUST_USE_RESULT static Handle<Derived> Shrink(Handle<Derived> table, Key key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3301 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3302 | // Ensure enough space for n additional elements. |
| 3303 | MUST_USE_RESULT static Handle<Derived> EnsureCapacity( |
| 3304 | Handle<Derived> table, |
| 3305 | int n, |
| 3306 | Key key, |
| 3307 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3308 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3309 | // Returns true if this table has sufficient capacity for adding n elements. |
| 3310 | bool HasSufficientCapacity(int n); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 3311 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3312 | // Sets the capacity of the hash table. |
| 3313 | void SetCapacity(int capacity) { |
| 3314 | // To scale a computed hash code to fit within the hash table, we |
| 3315 | // use bit-wise AND with a mask, so the capacity must be positive |
| 3316 | // and non-zero. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3317 | DCHECK(capacity > 0); |
| 3318 | DCHECK(capacity <= kMaxCapacity); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3319 | set(kCapacityIndex, Smi::FromInt(capacity)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3320 | } |
| 3321 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3322 | // Maximal capacity of HashTable. Based on maximal length of underlying |
| 3323 | // FixedArray. Staying below kMaxCapacity also ensures that EntryToIndex |
| 3324 | // cannot overflow. |
| 3325 | static const int kMaxCapacity = |
| 3326 | (FixedArray::kMaxLength - kElementsStartOffset) / kEntrySize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3327 | |
| 3328 | private: |
| 3329 | // Returns _expected_ if one of entries given by the first _probe_ probes is |
| 3330 | // equal to _expected_. Otherwise, returns the entry given by the probe |
| 3331 | // number _probe_. |
| 3332 | uint32_t EntryForProbe(Key key, Object* k, int probe, uint32_t expected); |
| 3333 | |
| 3334 | void Swap(uint32_t entry1, uint32_t entry2, WriteBarrierMode mode); |
| 3335 | |
| 3336 | // Rehashes this hash-table into the new table. |
| 3337 | void Rehash(Handle<Derived> new_table, Key key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3338 | }; |
| 3339 | |
| 3340 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3341 | // HashTableKey is an abstract superclass for virtual key behavior. |
| 3342 | class HashTableKey { |
| 3343 | public: |
| 3344 | // Returns whether the other object matches this key. |
| 3345 | virtual bool IsMatch(Object* other) = 0; |
| 3346 | // Returns the hash value for this key. |
| 3347 | virtual uint32_t Hash() = 0; |
| 3348 | // Returns the hash value for object. |
| 3349 | virtual uint32_t HashForObject(Object* key) = 0; |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3350 | // Returns the key object for storing into the hash table. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3351 | MUST_USE_RESULT virtual Handle<Object> AsHandle(Isolate* isolate) = 0; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3352 | // Required. |
| 3353 | virtual ~HashTableKey() {} |
| 3354 | }; |
| 3355 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3356 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3357 | class StringTableShape : public BaseShape<HashTableKey*> { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3358 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3359 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3360 | return key->IsMatch(value); |
| 3361 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3362 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3363 | static inline uint32_t Hash(HashTableKey* key) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3364 | return key->Hash(); |
| 3365 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3366 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3367 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3368 | return key->HashForObject(object); |
| 3369 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3370 | |
| 3371 | static inline Handle<Object> AsHandle(Isolate* isolate, HashTableKey* key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3372 | |
| 3373 | static const int kPrefixSize = 0; |
| 3374 | static const int kEntrySize = 1; |
| 3375 | }; |
| 3376 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3377 | class SeqOneByteString; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3378 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3379 | // StringTable. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3380 | // |
| 3381 | // No special elements in the prefix and the element size is 1 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3382 | // because only the string itself (the key) needs to be stored. |
| 3383 | class StringTable: public HashTable<StringTable, |
| 3384 | StringTableShape, |
| 3385 | HashTableKey*> { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3386 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3387 | // Find string in the string table. If it is not there yet, it is |
| 3388 | // added. The return value is the string found. |
| 3389 | static Handle<String> LookupString(Isolate* isolate, Handle<String> key); |
| 3390 | static Handle<String> LookupKey(Isolate* isolate, HashTableKey* key); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3391 | static String* LookupKeyIfExists(Isolate* isolate, HashTableKey* key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3392 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3393 | // Tries to internalize given string and returns string handle on success |
| 3394 | // or an empty handle otherwise. |
| 3395 | MUST_USE_RESULT static MaybeHandle<String> InternalizeStringIfExists( |
| 3396 | Isolate* isolate, |
| 3397 | Handle<String> string); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3398 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3399 | // Looks up a string that is equal to the given string and returns |
| 3400 | // string handle if it is found, or an empty handle otherwise. |
| 3401 | MUST_USE_RESULT static MaybeHandle<String> LookupStringIfExists( |
| 3402 | Isolate* isolate, |
| 3403 | Handle<String> str); |
| 3404 | MUST_USE_RESULT static MaybeHandle<String> LookupTwoCharsStringIfExists( |
| 3405 | Isolate* isolate, |
| 3406 | uint16_t c1, |
| 3407 | uint16_t c2); |
| 3408 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3409 | static void EnsureCapacityForDeserialization(Isolate* isolate, int expected); |
| 3410 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3411 | DECLARE_CAST(StringTable) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3412 | |
| 3413 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3414 | template <bool seq_one_byte> |
| 3415 | friend class JsonParser; |
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 | DISALLOW_IMPLICIT_CONSTRUCTORS(StringTable); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3418 | }; |
| 3419 | |
| 3420 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3421 | template <typename Derived, typename Shape, typename Key> |
| 3422 | class Dictionary: public HashTable<Derived, Shape, Key> { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3423 | typedef HashTable<Derived, Shape, Key> DerivedHashTable; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3424 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3425 | public: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3426 | // Returns the value at entry. |
| 3427 | Object* ValueAt(int entry) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3428 | return this->get(Derived::EntryToIndex(entry) + 1); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3429 | } |
| 3430 | |
| 3431 | // Set the value for entry. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3432 | void ValueAtPut(int entry, Object* value) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3433 | this->set(Derived::EntryToIndex(entry) + 1, value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3434 | } |
| 3435 | |
| 3436 | // Returns the property details for the property at entry. |
| 3437 | PropertyDetails DetailsAt(int entry) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3438 | return Shape::DetailsAt(static_cast<Derived*>(this), entry); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3439 | } |
| 3440 | |
| 3441 | // Set the details for entry. |
| 3442 | void DetailsAtPut(int entry, PropertyDetails value) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3443 | Shape::DetailsAtPut(static_cast<Derived*>(this), entry, value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3444 | } |
| 3445 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3446 | // Returns true if property at given entry is deleted. |
| 3447 | bool IsDeleted(int entry) { |
| 3448 | return Shape::IsDeleted(static_cast<Derived*>(this), entry); |
| 3449 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3450 | |
| 3451 | // Delete a property from the dictionary. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3452 | static Handle<Object> DeleteProperty(Handle<Derived> dictionary, int entry); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3453 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3454 | // Attempt to shrink the dictionary after deletion of key. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3455 | MUST_USE_RESULT static inline Handle<Derived> Shrink( |
| 3456 | Handle<Derived> dictionary, |
| 3457 | Key key) { |
| 3458 | return DerivedHashTable::Shrink(dictionary, key); |
| 3459 | } |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3460 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3461 | // Sorting support |
| 3462 | // TODO(dcarney): templatize or move to SeededNumberDictionary |
| 3463 | void CopyValuesTo(FixedArray* elements); |
| 3464 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3465 | // Returns the number of elements in the dictionary filtering out properties |
| 3466 | // with the specified attributes. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3467 | // TODO(jkummerow): Deprecated, only used by Object.observe. |
| 3468 | int NumberOfElementsFilterAttributes(PropertyFilter filter); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3469 | |
| 3470 | // Returns the number of enumerable elements in the dictionary. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3471 | // TODO(jkummerow): Deprecated, only used by Object.observe. |
| 3472 | int NumberOfEnumElements() { |
| 3473 | return NumberOfElementsFilterAttributes(ENUMERABLE_STRINGS); |
| 3474 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3475 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3476 | // Returns true if the dictionary contains any elements that are non-writable, |
| 3477 | // non-configurable, non-enumerable, or have getters/setters. |
| 3478 | bool HasComplexElements(); |
| 3479 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3480 | enum SortMode { UNSORTED, SORTED }; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3481 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3482 | // Fill in details for properties into storage. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3483 | // Returns the number of properties added. |
| 3484 | // TODO(jkummerow): Deprecated, only used by Object.observe. |
| 3485 | int CopyKeysTo(FixedArray* storage, int index, PropertyFilter filter, |
| 3486 | SortMode sort_mode); |
| 3487 | // Collect the keys into the given KeyAccumulator, in ascending chronological |
| 3488 | // order of property creation. |
| 3489 | static void CollectKeysTo(Handle<Dictionary<Derived, Shape, Key> > dictionary, |
| 3490 | KeyAccumulator* keys, PropertyFilter filter); |
| 3491 | |
| 3492 | // Copies enumerable keys to preallocated fixed array. |
| 3493 | void CopyEnumKeysTo(FixedArray* storage); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3494 | |
| 3495 | // Accessors for next enumeration index. |
| 3496 | void SetNextEnumerationIndex(int index) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3497 | DCHECK(index != 0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3498 | this->set(kNextEnumerationIndexIndex, Smi::FromInt(index)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3499 | } |
| 3500 | |
| 3501 | int NextEnumerationIndex() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3502 | return Smi::cast(this->get(kNextEnumerationIndexIndex))->value(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3503 | } |
| 3504 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3505 | // Creates a new dictionary. |
| 3506 | MUST_USE_RESULT static Handle<Derived> New( |
| 3507 | Isolate* isolate, |
| 3508 | int at_least_space_for, |
| 3509 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3510 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3511 | // Ensures that a new dictionary is created when the capacity is checked. |
| 3512 | void SetRequiresCopyOnCapacityChange(); |
| 3513 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3514 | // Ensure enough space for n additional elements. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3515 | static Handle<Derived> EnsureCapacity(Handle<Derived> obj, int n, Key key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3516 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3517 | #ifdef OBJECT_PRINT |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3518 | void Print(std::ostream& os); // NOLINT |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3519 | #endif |
| 3520 | // Returns the key (slow). |
| 3521 | Object* SlowReverseLookup(Object* value); |
| 3522 | |
| 3523 | // Sets the entry to (key, value) pair. |
| 3524 | inline void SetEntry(int entry, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3525 | Handle<Object> key, |
| 3526 | Handle<Object> value); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3527 | inline void SetEntry(int entry, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3528 | Handle<Object> key, |
| 3529 | Handle<Object> value, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3530 | PropertyDetails details); |
| 3531 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3532 | MUST_USE_RESULT static Handle<Derived> Add( |
| 3533 | Handle<Derived> dictionary, |
| 3534 | Key key, |
| 3535 | Handle<Object> value, |
| 3536 | PropertyDetails details); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3537 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3538 | // Returns iteration indices array for the |dictionary|. |
| 3539 | // Values are direct indices in the |HashTable| array. |
| 3540 | static Handle<FixedArray> BuildIterationIndicesArray( |
| 3541 | Handle<Derived> dictionary); |
| 3542 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3543 | protected: |
| 3544 | // Generic at put operation. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3545 | MUST_USE_RESULT static Handle<Derived> AtPut( |
| 3546 | Handle<Derived> dictionary, |
| 3547 | Key key, |
| 3548 | Handle<Object> value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3549 | |
| 3550 | // Add entry to dictionary. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3551 | static void AddEntry( |
| 3552 | Handle<Derived> dictionary, |
| 3553 | Key key, |
| 3554 | Handle<Object> value, |
| 3555 | PropertyDetails details, |
| 3556 | uint32_t hash); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3557 | |
| 3558 | // Generate new enumeration indices to avoid enumeration index overflow. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3559 | // Returns iteration indices array for the |dictionary|. |
| 3560 | static Handle<FixedArray> GenerateNewEnumerationIndices( |
| 3561 | Handle<Derived> dictionary); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3562 | static const int kMaxNumberKeyIndex = DerivedHashTable::kPrefixStartIndex; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3563 | static const int kNextEnumerationIndexIndex = kMaxNumberKeyIndex + 1; |
| 3564 | }; |
| 3565 | |
| 3566 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3567 | template <typename Derived, typename Shape> |
| 3568 | class NameDictionaryBase : public Dictionary<Derived, Shape, Handle<Name> > { |
| 3569 | typedef Dictionary<Derived, Shape, Handle<Name> > DerivedDictionary; |
| 3570 | |
| 3571 | public: |
| 3572 | // Find entry for key, otherwise return kNotFound. Optimized version of |
| 3573 | // HashTable::FindEntry. |
| 3574 | int FindEntry(Handle<Name> key); |
| 3575 | }; |
| 3576 | |
| 3577 | |
| 3578 | template <typename Key> |
| 3579 | class BaseDictionaryShape : public BaseShape<Key> { |
| 3580 | public: |
| 3581 | template <typename Dictionary> |
| 3582 | static inline PropertyDetails DetailsAt(Dictionary* dict, int entry) { |
| 3583 | STATIC_ASSERT(Dictionary::kEntrySize == 3); |
| 3584 | DCHECK(entry >= 0); // Not found is -1, which is not caught by get(). |
| 3585 | return PropertyDetails( |
| 3586 | Smi::cast(dict->get(Dictionary::EntryToIndex(entry) + 2))); |
| 3587 | } |
| 3588 | |
| 3589 | template <typename Dictionary> |
| 3590 | static inline void DetailsAtPut(Dictionary* dict, int entry, |
| 3591 | PropertyDetails value) { |
| 3592 | STATIC_ASSERT(Dictionary::kEntrySize == 3); |
| 3593 | dict->set(Dictionary::EntryToIndex(entry) + 2, value.AsSmi()); |
| 3594 | } |
| 3595 | |
| 3596 | template <typename Dictionary> |
| 3597 | static bool IsDeleted(Dictionary* dict, int entry) { |
| 3598 | return false; |
| 3599 | } |
| 3600 | |
| 3601 | template <typename Dictionary> |
| 3602 | static inline void SetEntry(Dictionary* dict, int entry, Handle<Object> key, |
| 3603 | Handle<Object> value, PropertyDetails details); |
| 3604 | }; |
| 3605 | |
| 3606 | |
| 3607 | class NameDictionaryShape : public BaseDictionaryShape<Handle<Name> > { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3608 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3609 | static inline bool IsMatch(Handle<Name> key, Object* other); |
| 3610 | static inline uint32_t Hash(Handle<Name> key); |
| 3611 | static inline uint32_t HashForObject(Handle<Name> key, Object* object); |
| 3612 | static inline Handle<Object> AsHandle(Isolate* isolate, Handle<Name> key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3613 | static const int kPrefixSize = 2; |
| 3614 | static const int kEntrySize = 3; |
| 3615 | static const bool kIsEnumerable = true; |
| 3616 | }; |
| 3617 | |
| 3618 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3619 | class NameDictionary |
| 3620 | : public NameDictionaryBase<NameDictionary, NameDictionaryShape> { |
| 3621 | typedef NameDictionaryBase<NameDictionary, NameDictionaryShape> |
| 3622 | DerivedDictionary; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3623 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3624 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3625 | DECLARE_CAST(NameDictionary) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3626 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3627 | inline static Handle<FixedArray> DoGenerateNewEnumerationIndices( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3628 | Handle<NameDictionary> dictionary); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3629 | }; |
| 3630 | |
| 3631 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3632 | class GlobalDictionaryShape : public NameDictionaryShape { |
| 3633 | public: |
| 3634 | static const int kEntrySize = 2; // Overrides NameDictionaryShape::kEntrySize |
| 3635 | |
| 3636 | template <typename Dictionary> |
| 3637 | static inline PropertyDetails DetailsAt(Dictionary* dict, int entry); |
| 3638 | |
| 3639 | template <typename Dictionary> |
| 3640 | static inline void DetailsAtPut(Dictionary* dict, int entry, |
| 3641 | PropertyDetails value); |
| 3642 | |
| 3643 | template <typename Dictionary> |
| 3644 | static bool IsDeleted(Dictionary* dict, int entry); |
| 3645 | |
| 3646 | template <typename Dictionary> |
| 3647 | static inline void SetEntry(Dictionary* dict, int entry, Handle<Object> key, |
| 3648 | Handle<Object> value, PropertyDetails details); |
| 3649 | }; |
| 3650 | |
| 3651 | |
| 3652 | class GlobalDictionary |
| 3653 | : public NameDictionaryBase<GlobalDictionary, GlobalDictionaryShape> { |
| 3654 | public: |
| 3655 | DECLARE_CAST(GlobalDictionary) |
| 3656 | }; |
| 3657 | |
| 3658 | |
| 3659 | class NumberDictionaryShape : public BaseDictionaryShape<uint32_t> { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3660 | public: |
| 3661 | static inline bool IsMatch(uint32_t key, Object* other); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3662 | static inline Handle<Object> AsHandle(Isolate* isolate, uint32_t key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3663 | static const int kEntrySize = 3; |
| 3664 | static const bool kIsEnumerable = false; |
| 3665 | }; |
| 3666 | |
| 3667 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3668 | class SeededNumberDictionaryShape : public NumberDictionaryShape { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3669 | public: |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3670 | static const bool UsesSeed = true; |
| 3671 | static const int kPrefixSize = 2; |
| 3672 | |
| 3673 | static inline uint32_t SeededHash(uint32_t key, uint32_t seed); |
| 3674 | static inline uint32_t SeededHashForObject(uint32_t key, |
| 3675 | uint32_t seed, |
| 3676 | Object* object); |
| 3677 | }; |
| 3678 | |
| 3679 | |
| 3680 | class UnseededNumberDictionaryShape : public NumberDictionaryShape { |
| 3681 | public: |
| 3682 | static const int kPrefixSize = 0; |
| 3683 | |
| 3684 | static inline uint32_t Hash(uint32_t key); |
| 3685 | static inline uint32_t HashForObject(uint32_t key, Object* object); |
| 3686 | }; |
| 3687 | |
| 3688 | |
| 3689 | class SeededNumberDictionary |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3690 | : public Dictionary<SeededNumberDictionary, |
| 3691 | SeededNumberDictionaryShape, |
| 3692 | uint32_t> { |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3693 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3694 | DECLARE_CAST(SeededNumberDictionary) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3695 | |
| 3696 | // Type specific at put (default NONE attributes is used when adding). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3697 | MUST_USE_RESULT static Handle<SeededNumberDictionary> AtNumberPut( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3698 | Handle<SeededNumberDictionary> dictionary, uint32_t key, |
| 3699 | Handle<Object> value, bool used_as_prototype); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3700 | MUST_USE_RESULT static Handle<SeededNumberDictionary> AddNumberEntry( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3701 | Handle<SeededNumberDictionary> dictionary, uint32_t key, |
| 3702 | Handle<Object> value, PropertyDetails details, bool used_as_prototype); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3703 | |
| 3704 | // Set an existing entry or add a new one if needed. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3705 | // Return the updated dictionary. |
| 3706 | MUST_USE_RESULT static Handle<SeededNumberDictionary> Set( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3707 | Handle<SeededNumberDictionary> dictionary, uint32_t key, |
| 3708 | Handle<Object> value, PropertyDetails details, bool used_as_prototype); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3709 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3710 | void UpdateMaxNumberKey(uint32_t key, bool used_as_prototype); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3711 | |
| 3712 | // If slow elements are required we will never go back to fast-case |
| 3713 | // for the elements kept in this dictionary. We require slow |
| 3714 | // elements if an element has been added at an index larger than |
| 3715 | // kRequiresSlowElementsLimit or set_requires_slow_elements() has been called |
| 3716 | // when defining a getter or setter with a number key. |
| 3717 | inline bool requires_slow_elements(); |
| 3718 | inline void set_requires_slow_elements(); |
| 3719 | |
| 3720 | // Get the value of the max number key that has been added to this |
| 3721 | // dictionary. max_number_key can only be called if |
| 3722 | // requires_slow_elements returns false. |
| 3723 | inline uint32_t max_number_key(); |
| 3724 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3725 | // Bit masks. |
| 3726 | static const int kRequiresSlowElementsMask = 1; |
| 3727 | static const int kRequiresSlowElementsTagSize = 1; |
| 3728 | static const uint32_t kRequiresSlowElementsLimit = (1 << 29) - 1; |
| 3729 | }; |
| 3730 | |
| 3731 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3732 | class UnseededNumberDictionary |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3733 | : public Dictionary<UnseededNumberDictionary, |
| 3734 | UnseededNumberDictionaryShape, |
| 3735 | uint32_t> { |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3736 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3737 | DECLARE_CAST(UnseededNumberDictionary) |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3738 | |
| 3739 | // Type specific at put (default NONE attributes is used when adding). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3740 | MUST_USE_RESULT static Handle<UnseededNumberDictionary> AtNumberPut( |
| 3741 | Handle<UnseededNumberDictionary> dictionary, |
| 3742 | uint32_t key, |
| 3743 | Handle<Object> value); |
| 3744 | MUST_USE_RESULT static Handle<UnseededNumberDictionary> AddNumberEntry( |
| 3745 | Handle<UnseededNumberDictionary> dictionary, |
| 3746 | uint32_t key, |
| 3747 | Handle<Object> value); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3748 | |
| 3749 | // Set an existing entry or add a new one if needed. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3750 | // Return the updated dictionary. |
| 3751 | MUST_USE_RESULT static Handle<UnseededNumberDictionary> Set( |
| 3752 | Handle<UnseededNumberDictionary> dictionary, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3753 | uint32_t key, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3754 | Handle<Object> value); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3755 | }; |
| 3756 | |
| 3757 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3758 | class ObjectHashTableShape : public BaseShape<Handle<Object> > { |
Ben Murdoch | 2b4ba11 | 2012-01-20 14:57:15 +0000 | [diff] [blame] | 3759 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3760 | static inline bool IsMatch(Handle<Object> key, Object* other); |
| 3761 | static inline uint32_t Hash(Handle<Object> key); |
| 3762 | static inline uint32_t HashForObject(Handle<Object> key, Object* object); |
| 3763 | static inline Handle<Object> AsHandle(Isolate* isolate, Handle<Object> key); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 3764 | static const int kPrefixSize = 0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3765 | static const int kEntrySize = 2; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3766 | }; |
| 3767 | |
| 3768 | |
| 3769 | // ObjectHashTable maps keys that are arbitrary objects to object values by |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3770 | // using the identity hash of the key for hashing purposes. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3771 | class ObjectHashTable: public HashTable<ObjectHashTable, |
| 3772 | ObjectHashTableShape, |
| 3773 | Handle<Object> > { |
| 3774 | typedef HashTable< |
| 3775 | ObjectHashTable, ObjectHashTableShape, Handle<Object> > DerivedHashTable; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3776 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3777 | DECLARE_CAST(ObjectHashTable) |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3778 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3779 | // Attempt to shrink hash table after removal of key. |
| 3780 | MUST_USE_RESULT static inline Handle<ObjectHashTable> Shrink( |
| 3781 | Handle<ObjectHashTable> table, |
| 3782 | Handle<Object> key); |
| 3783 | |
| 3784 | // 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] | 3785 | // returned in case the key is not present. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3786 | Object* Lookup(Handle<Object> key); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3787 | Object* Lookup(Handle<Object> key, int32_t hash); |
| 3788 | Object* Lookup(Isolate* isolate, Handle<Object> key, int32_t hash); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3789 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3790 | // Adds (or overwrites) the value associated with the given key. |
| 3791 | static Handle<ObjectHashTable> Put(Handle<ObjectHashTable> table, |
| 3792 | Handle<Object> key, |
| 3793 | Handle<Object> value); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3794 | static Handle<ObjectHashTable> Put(Handle<ObjectHashTable> table, |
| 3795 | Handle<Object> key, Handle<Object> value, |
| 3796 | int32_t hash); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3797 | |
| 3798 | // Returns an ObjectHashTable (possibly |table|) where |key| has been removed. |
| 3799 | static Handle<ObjectHashTable> Remove(Handle<ObjectHashTable> table, |
| 3800 | Handle<Object> key, |
| 3801 | bool* was_present); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3802 | static Handle<ObjectHashTable> Remove(Handle<ObjectHashTable> table, |
| 3803 | Handle<Object> key, bool* was_present, |
| 3804 | int32_t hash); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3805 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3806 | protected: |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3807 | friend class MarkCompactCollector; |
| 3808 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3809 | void AddEntry(int entry, Object* key, Object* value); |
| 3810 | void RemoveEntry(int entry); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3811 | |
| 3812 | // Returns the index to the value of an entry. |
| 3813 | static inline int EntryToValueIndex(int entry) { |
| 3814 | return EntryToIndex(entry) + 1; |
| 3815 | } |
| 3816 | }; |
| 3817 | |
| 3818 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3819 | // OrderedHashTable is a HashTable with Object keys that preserves |
| 3820 | // insertion order. There are Map and Set interfaces (OrderedHashMap |
| 3821 | // and OrderedHashTable, below). It is meant to be used by JSMap/JSSet. |
| 3822 | // |
| 3823 | // Only Object* keys are supported, with Object::SameValueZero() used as the |
| 3824 | // equality operator and Object::GetHash() for the hash function. |
| 3825 | // |
| 3826 | // Based on the "Deterministic Hash Table" as described by Jason Orendorff at |
| 3827 | // https://wiki.mozilla.org/User:Jorend/Deterministic_hash_tables |
| 3828 | // Originally attributed to Tyler Close. |
| 3829 | // |
| 3830 | // Memory layout: |
| 3831 | // [0]: bucket count |
| 3832 | // [1]: element count |
| 3833 | // [2]: deleted element count |
| 3834 | // [3..(3 + NumberOfBuckets() - 1)]: "hash table", where each item is an |
| 3835 | // offset into the data table (see below) where the |
| 3836 | // first item in this bucket is stored. |
| 3837 | // [3 + NumberOfBuckets()..length]: "data table", an array of length |
| 3838 | // Capacity() * kEntrySize, where the first entrysize |
| 3839 | // items are handled by the derived class and the |
| 3840 | // item at kChainOffset is another entry into the |
| 3841 | // data table indicating the next entry in this hash |
| 3842 | // bucket. |
| 3843 | // |
| 3844 | // When we transition the table to a new version we obsolete it and reuse parts |
| 3845 | // of the memory to store information how to transition an iterator to the new |
| 3846 | // table: |
| 3847 | // |
| 3848 | // Memory layout for obsolete table: |
| 3849 | // [0]: bucket count |
| 3850 | // [1]: Next newer table |
| 3851 | // [2]: Number of removed holes or -1 when the table was cleared. |
| 3852 | // [3..(3 + NumberOfRemovedHoles() - 1)]: The indexes of the removed holes. |
| 3853 | // [3 + NumberOfRemovedHoles()..length]: Not used |
| 3854 | // |
| 3855 | template<class Derived, class Iterator, int entrysize> |
| 3856 | class OrderedHashTable: public FixedArray { |
| 3857 | public: |
| 3858 | // Returns an OrderedHashTable with a capacity of at least |capacity|. |
| 3859 | static Handle<Derived> Allocate( |
| 3860 | Isolate* isolate, int capacity, PretenureFlag pretenure = NOT_TENURED); |
| 3861 | |
| 3862 | // Returns an OrderedHashTable (possibly |table|) with enough space |
| 3863 | // to add at least one new element. |
| 3864 | static Handle<Derived> EnsureGrowable(Handle<Derived> table); |
| 3865 | |
| 3866 | // Returns an OrderedHashTable (possibly |table|) that's shrunken |
| 3867 | // if possible. |
| 3868 | static Handle<Derived> Shrink(Handle<Derived> table); |
| 3869 | |
| 3870 | // Returns a new empty OrderedHashTable and records the clearing so that |
| 3871 | // exisiting iterators can be updated. |
| 3872 | static Handle<Derived> Clear(Handle<Derived> table); |
| 3873 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3874 | // Returns a true if the OrderedHashTable contains the key |
| 3875 | static bool HasKey(Handle<Derived> table, Handle<Object> key); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3876 | |
| 3877 | int NumberOfElements() { |
| 3878 | return Smi::cast(get(kNumberOfElementsIndex))->value(); |
| 3879 | } |
| 3880 | |
| 3881 | int NumberOfDeletedElements() { |
| 3882 | return Smi::cast(get(kNumberOfDeletedElementsIndex))->value(); |
| 3883 | } |
| 3884 | |
| 3885 | int UsedCapacity() { return NumberOfElements() + NumberOfDeletedElements(); } |
| 3886 | |
| 3887 | int NumberOfBuckets() { |
| 3888 | return Smi::cast(get(kNumberOfBucketsIndex))->value(); |
| 3889 | } |
| 3890 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3891 | // Returns an index into |this| for the given entry. |
| 3892 | int EntryToIndex(int entry) { |
| 3893 | return kHashTableStartIndex + NumberOfBuckets() + (entry * kEntrySize); |
| 3894 | } |
| 3895 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3896 | int HashToBucket(int hash) { return hash & (NumberOfBuckets() - 1); } |
| 3897 | |
| 3898 | int HashToEntry(int hash) { |
| 3899 | int bucket = HashToBucket(hash); |
| 3900 | Object* entry = this->get(kHashTableStartIndex + bucket); |
| 3901 | return Smi::cast(entry)->value(); |
| 3902 | } |
| 3903 | |
| 3904 | int KeyToFirstEntry(Object* key) { |
| 3905 | Object* hash = key->GetHash(); |
| 3906 | // If the object does not have an identity hash, it was never used as a key |
| 3907 | if (hash->IsUndefined()) return kNotFound; |
| 3908 | return HashToEntry(Smi::cast(hash)->value()); |
| 3909 | } |
| 3910 | |
| 3911 | int NextChainEntry(int entry) { |
| 3912 | Object* next_entry = get(EntryToIndex(entry) + kChainOffset); |
| 3913 | return Smi::cast(next_entry)->value(); |
| 3914 | } |
| 3915 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3916 | Object* KeyAt(int entry) { return get(EntryToIndex(entry)); } |
| 3917 | |
| 3918 | bool IsObsolete() { |
| 3919 | return !get(kNextTableIndex)->IsSmi(); |
| 3920 | } |
| 3921 | |
| 3922 | // The next newer table. This is only valid if the table is obsolete. |
| 3923 | Derived* NextTable() { |
| 3924 | return Derived::cast(get(kNextTableIndex)); |
| 3925 | } |
| 3926 | |
| 3927 | // When the table is obsolete we store the indexes of the removed holes. |
| 3928 | int RemovedIndexAt(int index) { |
| 3929 | return Smi::cast(get(kRemovedHolesIndex + index))->value(); |
| 3930 | } |
| 3931 | |
| 3932 | static const int kNotFound = -1; |
| 3933 | static const int kMinCapacity = 4; |
| 3934 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3935 | static const int kNumberOfBucketsIndex = 0; |
| 3936 | static const int kNumberOfElementsIndex = kNumberOfBucketsIndex + 1; |
| 3937 | static const int kNumberOfDeletedElementsIndex = kNumberOfElementsIndex + 1; |
| 3938 | static const int kHashTableStartIndex = kNumberOfDeletedElementsIndex + 1; |
| 3939 | static const int kNextTableIndex = kNumberOfElementsIndex; |
| 3940 | |
| 3941 | static const int kNumberOfBucketsOffset = |
| 3942 | kHeaderSize + kNumberOfBucketsIndex * kPointerSize; |
| 3943 | static const int kNumberOfElementsOffset = |
| 3944 | kHeaderSize + kNumberOfElementsIndex * kPointerSize; |
| 3945 | static const int kNumberOfDeletedElementsOffset = |
| 3946 | kHeaderSize + kNumberOfDeletedElementsIndex * kPointerSize; |
| 3947 | static const int kHashTableStartOffset = |
| 3948 | kHeaderSize + kHashTableStartIndex * kPointerSize; |
| 3949 | static const int kNextTableOffset = |
| 3950 | kHeaderSize + kNextTableIndex * kPointerSize; |
| 3951 | |
| 3952 | static const int kEntrySize = entrysize + 1; |
| 3953 | static const int kChainOffset = entrysize; |
| 3954 | |
| 3955 | static const int kLoadFactor = 2; |
| 3956 | |
| 3957 | // NumberOfDeletedElements is set to kClearedTableSentinel when |
| 3958 | // the table is cleared, which allows iterator transitions to |
| 3959 | // optimize that case. |
| 3960 | static const int kClearedTableSentinel = -1; |
| 3961 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 3962 | protected: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3963 | static Handle<Derived> Rehash(Handle<Derived> table, int new_capacity); |
| 3964 | |
| 3965 | void SetNumberOfBuckets(int num) { |
| 3966 | set(kNumberOfBucketsIndex, Smi::FromInt(num)); |
| 3967 | } |
| 3968 | |
| 3969 | void SetNumberOfElements(int num) { |
| 3970 | set(kNumberOfElementsIndex, Smi::FromInt(num)); |
| 3971 | } |
| 3972 | |
| 3973 | void SetNumberOfDeletedElements(int num) { |
| 3974 | set(kNumberOfDeletedElementsIndex, Smi::FromInt(num)); |
| 3975 | } |
| 3976 | |
| 3977 | int Capacity() { |
| 3978 | return NumberOfBuckets() * kLoadFactor; |
| 3979 | } |
| 3980 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3981 | void SetNextTable(Derived* next_table) { |
| 3982 | set(kNextTableIndex, next_table); |
| 3983 | } |
| 3984 | |
| 3985 | void SetRemovedIndexAt(int index, int removed_index) { |
| 3986 | return set(kRemovedHolesIndex + index, Smi::FromInt(removed_index)); |
| 3987 | } |
| 3988 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3989 | static const int kRemovedHolesIndex = kHashTableStartIndex; |
| 3990 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3991 | static const int kMaxCapacity = |
| 3992 | (FixedArray::kMaxLength - kHashTableStartIndex) |
| 3993 | / (1 + (kEntrySize * kLoadFactor)); |
| 3994 | }; |
| 3995 | |
| 3996 | |
| 3997 | class JSSetIterator; |
| 3998 | |
| 3999 | |
| 4000 | class OrderedHashSet: public OrderedHashTable< |
| 4001 | OrderedHashSet, JSSetIterator, 1> { |
| 4002 | public: |
| 4003 | DECLARE_CAST(OrderedHashSet) |
| 4004 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4005 | static Handle<OrderedHashSet> Add(Handle<OrderedHashSet> table, |
| 4006 | Handle<Object> value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4007 | }; |
| 4008 | |
| 4009 | |
| 4010 | class JSMapIterator; |
| 4011 | |
| 4012 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4013 | class OrderedHashMap |
| 4014 | : public OrderedHashTable<OrderedHashMap, JSMapIterator, 2> { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4015 | public: |
| 4016 | DECLARE_CAST(OrderedHashMap) |
| 4017 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4018 | inline Object* ValueAt(int entry); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4019 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4020 | static const int kValueOffset = 1; |
| 4021 | }; |
| 4022 | |
| 4023 | |
| 4024 | template <int entrysize> |
| 4025 | class WeakHashTableShape : public BaseShape<Handle<Object> > { |
| 4026 | public: |
| 4027 | static inline bool IsMatch(Handle<Object> key, Object* other); |
| 4028 | static inline uint32_t Hash(Handle<Object> key); |
| 4029 | static inline uint32_t HashForObject(Handle<Object> key, Object* object); |
| 4030 | static inline Handle<Object> AsHandle(Isolate* isolate, Handle<Object> key); |
| 4031 | static const int kPrefixSize = 0; |
| 4032 | static const int kEntrySize = entrysize; |
| 4033 | }; |
| 4034 | |
| 4035 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4036 | // WeakHashTable maps keys that are arbitrary heap objects to heap object |
| 4037 | // values. The table wraps the keys in weak cells and store values directly. |
| 4038 | // Thus it references keys weakly and values strongly. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4039 | class WeakHashTable: public HashTable<WeakHashTable, |
| 4040 | WeakHashTableShape<2>, |
| 4041 | Handle<Object> > { |
| 4042 | typedef HashTable< |
| 4043 | WeakHashTable, WeakHashTableShape<2>, Handle<Object> > DerivedHashTable; |
| 4044 | public: |
| 4045 | DECLARE_CAST(WeakHashTable) |
| 4046 | |
| 4047 | // Looks up the value associated with the given key. The hole value is |
| 4048 | // returned in case the key is not present. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4049 | Object* Lookup(Handle<HeapObject> key); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4050 | |
| 4051 | // Adds (or overwrites) the value associated with the given key. Mapping a |
| 4052 | // key to the hole value causes removal of the whole entry. |
| 4053 | MUST_USE_RESULT static Handle<WeakHashTable> Put(Handle<WeakHashTable> table, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4054 | Handle<HeapObject> key, |
| 4055 | Handle<HeapObject> value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4056 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4057 | static Handle<FixedArray> GetValues(Handle<WeakHashTable> table); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4058 | |
| 4059 | private: |
| 4060 | friend class MarkCompactCollector; |
| 4061 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4062 | void AddEntry(int entry, Handle<WeakCell> key, Handle<HeapObject> value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4063 | |
| 4064 | // Returns the index to the value of an entry. |
| 4065 | static inline int EntryToValueIndex(int entry) { |
| 4066 | return EntryToIndex(entry) + 1; |
| 4067 | } |
| 4068 | }; |
| 4069 | |
| 4070 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4071 | // ScopeInfo represents information about different scopes of a source |
| 4072 | // program and the allocation of the scope's variables. Scope information |
| 4073 | // is stored in a compressed form in ScopeInfo objects and is used |
| 4074 | // at runtime (stack dumps, deoptimization, etc.). |
| 4075 | |
| 4076 | // This object provides quick access to scope info details for runtime |
| 4077 | // routines. |
| 4078 | class ScopeInfo : public FixedArray { |
| 4079 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4080 | DECLARE_CAST(ScopeInfo) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4081 | |
| 4082 | // Return the type of this scope. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4083 | ScopeType scope_type(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4084 | |
| 4085 | // Does this scope call eval? |
| 4086 | bool CallsEval(); |
| 4087 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4088 | // Return the language mode of this scope. |
| 4089 | LanguageMode language_mode(); |
| 4090 | |
| 4091 | // True if this scope is a (var) declaration scope. |
| 4092 | bool is_declaration_scope(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4093 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4094 | // Does this scope make a sloppy eval call? |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4095 | bool CallsSloppyEval() { return CallsEval() && is_sloppy(language_mode()); } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4096 | |
| 4097 | // Return the total number of locals allocated on the stack and in the |
| 4098 | // context. This includes the parameters that are allocated in the context. |
| 4099 | int LocalCount(); |
| 4100 | |
| 4101 | // Return the number of stack slots for code. This number consists of two |
| 4102 | // parts: |
| 4103 | // 1. One stack slot per stack allocated local. |
| 4104 | // 2. One stack slot for the function name if it is stack allocated. |
| 4105 | int StackSlotCount(); |
| 4106 | |
| 4107 | // Return the number of context slots for code if a context is allocated. This |
| 4108 | // number consists of three parts: |
| 4109 | // 1. Size of fixed header for every context: Context::MIN_CONTEXT_SLOTS |
| 4110 | // 2. One context slot per context allocated local. |
| 4111 | // 3. One context slot for the function name if it is context allocated. |
| 4112 | // Parameters allocated in the context count as context allocated locals. If |
| 4113 | // no contexts are allocated for this scope ContextLength returns 0. |
| 4114 | int ContextLength(); |
| 4115 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4116 | // Does this scope declare a "this" binding? |
| 4117 | bool HasReceiver(); |
| 4118 | |
| 4119 | // Does this scope declare a "this" binding, and the "this" binding is stack- |
| 4120 | // or context-allocated? |
| 4121 | bool HasAllocatedReceiver(); |
| 4122 | |
| 4123 | // Does this scope declare a "new.target" binding? |
| 4124 | bool HasNewTarget(); |
| 4125 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4126 | // Is this scope the scope of a named function expression? |
| 4127 | bool HasFunctionName(); |
| 4128 | |
| 4129 | // Return if this has context allocated locals. |
| 4130 | bool HasHeapAllocatedLocals(); |
| 4131 | |
| 4132 | // Return if contexts are allocated for this scope. |
| 4133 | bool HasContext(); |
| 4134 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4135 | // Return if this is a function scope with "use asm". |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4136 | inline bool IsAsmModule(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4137 | |
| 4138 | // Return if this is a nested function within an asm module scope. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4139 | inline bool IsAsmFunction(); |
| 4140 | |
| 4141 | inline bool HasSimpleParameters(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4142 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4143 | // Return the function_name if present. |
| 4144 | String* FunctionName(); |
| 4145 | |
| 4146 | // Return the name of the given parameter. |
| 4147 | String* ParameterName(int var); |
| 4148 | |
| 4149 | // Return the name of the given local. |
| 4150 | String* LocalName(int var); |
| 4151 | |
| 4152 | // Return the name of the given stack local. |
| 4153 | String* StackLocalName(int var); |
| 4154 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4155 | // Return the name of the given stack local. |
| 4156 | int StackLocalIndex(int var); |
| 4157 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4158 | // Return the name of the given context local. |
| 4159 | String* ContextLocalName(int var); |
| 4160 | |
| 4161 | // Return the mode of the given context local. |
| 4162 | VariableMode ContextLocalMode(int var); |
| 4163 | |
| 4164 | // Return the initialization flag of the given context local. |
| 4165 | InitializationFlag ContextLocalInitFlag(int var); |
| 4166 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4167 | // Return the initialization flag of the given context local. |
| 4168 | MaybeAssignedFlag ContextLocalMaybeAssignedFlag(int var); |
| 4169 | |
| 4170 | // Return true if this local was introduced by the compiler, and should not be |
| 4171 | // exposed to the user in a debugger. |
| 4172 | bool LocalIsSynthetic(int var); |
| 4173 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4174 | // Lookup support for serialized scope info. Returns the |
| 4175 | // 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] | 4176 | // present; otherwise returns a value < 0. The name must be an internalized |
| 4177 | // string. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4178 | int StackSlotIndex(String* name); |
| 4179 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4180 | // Lookup support for serialized scope info. Returns the local context slot |
| 4181 | // index for a given slot name if the slot is present; otherwise |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4182 | // returns a value < 0. The name must be an internalized string. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4183 | // If the slot is present and mode != NULL, sets *mode to the corresponding |
| 4184 | // mode for that variable. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4185 | static int ContextSlotIndex(Handle<ScopeInfo> scope_info, Handle<String> name, |
| 4186 | VariableMode* mode, InitializationFlag* init_flag, |
| 4187 | MaybeAssignedFlag* maybe_assigned_flag); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4188 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4189 | // Similar to ContextSlotIndex() but this method searches only among |
| 4190 | // global slots of the serialized scope info. Returns the context slot index |
| 4191 | // for a given slot name if the slot is present; otherwise returns a |
| 4192 | // value < 0. The name must be an internalized string. If the slot is present |
| 4193 | // and mode != NULL, sets *mode to the corresponding mode for that variable. |
| 4194 | static int ContextGlobalSlotIndex(Handle<ScopeInfo> scope_info, |
| 4195 | Handle<String> name, VariableMode* mode, |
| 4196 | InitializationFlag* init_flag, |
| 4197 | MaybeAssignedFlag* maybe_assigned_flag); |
| 4198 | |
| 4199 | // Lookup the name of a certain context slot by its index. |
| 4200 | String* ContextSlotName(int slot_index); |
| 4201 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4202 | // Lookup support for serialized scope info. Returns the |
| 4203 | // parameter index for a given parameter name if the parameter is present; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4204 | // otherwise returns a value < 0. The name must be an internalized string. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4205 | int ParameterIndex(String* name); |
| 4206 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4207 | // Lookup support for serialized scope info. Returns the function context |
| 4208 | // slot index if the function name is present and context-allocated (named |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4209 | // function expressions, only), otherwise returns a value < 0. The name |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4210 | // must be an internalized string. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4211 | int FunctionContextSlotIndex(String* name, VariableMode* mode); |
| 4212 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4213 | // Lookup support for serialized scope info. Returns the receiver context |
| 4214 | // slot index if scope has a "this" binding, and the binding is |
| 4215 | // context-allocated. Otherwise returns a value < 0. |
| 4216 | int ReceiverContextSlotIndex(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4217 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4218 | FunctionKind function_kind(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4219 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4220 | static Handle<ScopeInfo> Create(Isolate* isolate, Zone* zone, Scope* scope); |
| 4221 | static Handle<ScopeInfo> CreateGlobalThisBinding(Isolate* isolate); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4222 | |
| 4223 | // Serializes empty scope info. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4224 | static ScopeInfo* Empty(Isolate* isolate); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4225 | |
| 4226 | #ifdef DEBUG |
| 4227 | void Print(); |
| 4228 | #endif |
| 4229 | |
| 4230 | // The layout of the static part of a ScopeInfo is as follows. Each entry is |
| 4231 | // numeric and occupies one array slot. |
| 4232 | // 1. A set of properties of the scope |
| 4233 | // 2. The number of parameters. This only applies to function scopes. For |
| 4234 | // non-function scopes this is 0. |
| 4235 | // 3. The number of non-parameter variables allocated on the stack. |
| 4236 | // 4. The number of non-parameter and parameter variables allocated in the |
| 4237 | // context. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4238 | #define FOR_EACH_SCOPE_INFO_NUMERIC_FIELD(V) \ |
| 4239 | V(Flags) \ |
| 4240 | V(ParameterCount) \ |
| 4241 | V(StackLocalCount) \ |
| 4242 | V(ContextLocalCount) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 4243 | V(ContextGlobalCount) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4244 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4245 | #define FIELD_ACCESSORS(name) \ |
| 4246 | inline void Set##name(int value); \ |
| 4247 | inline int name(); |
| 4248 | FOR_EACH_SCOPE_INFO_NUMERIC_FIELD(FIELD_ACCESSORS) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4249 | #undef FIELD_ACCESSORS |
| 4250 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4251 | enum { |
| 4252 | #define DECL_INDEX(name) k##name, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4253 | FOR_EACH_SCOPE_INFO_NUMERIC_FIELD(DECL_INDEX) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4254 | #undef DECL_INDEX |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4255 | kVariablePartIndex |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4256 | }; |
| 4257 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4258 | private: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4259 | // The layout of the variable part of a ScopeInfo is as follows: |
| 4260 | // 1. ParameterEntries: |
| 4261 | // This part stores the names of the parameters for function scopes. One |
| 4262 | // slot is used per parameter, so in total this part occupies |
| 4263 | // ParameterCount() slots in the array. For other scopes than function |
| 4264 | // scopes ParameterCount() is 0. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4265 | // 2. StackLocalFirstSlot: |
| 4266 | // Index of a first stack slot for stack local. Stack locals belonging to |
| 4267 | // this scope are located on a stack at slots starting from this index. |
| 4268 | // 3. StackLocalEntries: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4269 | // Contains the names of local variables that are allocated on the stack, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4270 | // in increasing order of the stack slot index. First local variable has |
| 4271 | // a stack slot index defined in StackLocalFirstSlot (point 2 above). |
| 4272 | // One slot is used per stack local, so in total this part occupies |
| 4273 | // StackLocalCount() slots in the array. |
| 4274 | // 4. ContextLocalNameEntries: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4275 | // Contains the names of local variables and parameters that are allocated |
| 4276 | // in the context. They are stored in increasing order of the context slot |
| 4277 | // index starting with Context::MIN_CONTEXT_SLOTS. One slot is used per |
| 4278 | // context local, so in total this part occupies ContextLocalCount() slots |
| 4279 | // in the array. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4280 | // 5. ContextLocalInfoEntries: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4281 | // Contains the variable modes and initialization flags corresponding to |
| 4282 | // the context locals in ContextLocalNameEntries. One slot is used per |
| 4283 | // context local, so in total this part occupies ContextLocalCount() |
| 4284 | // slots in the array. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 4285 | // 6. RecieverEntryIndex: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4286 | // If the scope binds a "this" value, one slot is reserved to hold the |
| 4287 | // context or stack slot index for the variable. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 4288 | // 7. FunctionNameEntryIndex: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4289 | // If the scope belongs to a named function expression this part contains |
| 4290 | // information about the function variable. It always occupies two array |
| 4291 | // slots: a. The name of the function variable. |
| 4292 | // b. The context or stack slot index for the variable. |
| 4293 | int ParameterEntriesIndex(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4294 | int StackLocalFirstSlotIndex(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4295 | int StackLocalEntriesIndex(); |
| 4296 | int ContextLocalNameEntriesIndex(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4297 | int ContextGlobalNameEntriesIndex(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4298 | int ContextLocalInfoEntriesIndex(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4299 | int ContextGlobalInfoEntriesIndex(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4300 | int ReceiverEntryIndex(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4301 | int FunctionNameEntryIndex(); |
| 4302 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4303 | int Lookup(Handle<String> name, int start, int end, VariableMode* mode, |
| 4304 | VariableLocation* location, InitializationFlag* init_flag, |
| 4305 | MaybeAssignedFlag* maybe_assigned_flag); |
| 4306 | |
| 4307 | // Used for the function name variable for named function expressions, and for |
| 4308 | // the receiver. |
| 4309 | enum VariableAllocationInfo { NONE, STACK, CONTEXT, UNUSED }; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4310 | |
| 4311 | // Properties of scopes. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 4312 | class ScopeTypeField : public BitField<ScopeType, 0, 4> {}; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4313 | class CallsEvalField : public BitField<bool, ScopeTypeField::kNext, 1> {}; |
| 4314 | STATIC_ASSERT(LANGUAGE_END == 3); |
| 4315 | class LanguageModeField |
| 4316 | : public BitField<LanguageMode, CallsEvalField::kNext, 2> {}; |
| 4317 | class DeclarationScopeField |
| 4318 | : public BitField<bool, LanguageModeField::kNext, 1> {}; |
| 4319 | class ReceiverVariableField |
| 4320 | : public BitField<VariableAllocationInfo, DeclarationScopeField::kNext, |
| 4321 | 2> {}; |
| 4322 | class HasNewTargetField |
| 4323 | : public BitField<bool, ReceiverVariableField::kNext, 1> {}; |
| 4324 | class FunctionVariableField |
| 4325 | : public BitField<VariableAllocationInfo, HasNewTargetField::kNext, 2> {}; |
| 4326 | class FunctionVariableMode |
| 4327 | : public BitField<VariableMode, FunctionVariableField::kNext, 3> {}; |
| 4328 | class AsmModuleField : public BitField<bool, FunctionVariableMode::kNext, 1> { |
| 4329 | }; |
| 4330 | class AsmFunctionField : public BitField<bool, AsmModuleField::kNext, 1> {}; |
| 4331 | class HasSimpleParametersField |
| 4332 | : public BitField<bool, AsmFunctionField::kNext, 1> {}; |
| 4333 | class FunctionKindField |
| 4334 | : public BitField<FunctionKind, HasSimpleParametersField::kNext, 8> {}; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4335 | |
| 4336 | // BitFields representing the encoded information for context locals in the |
| 4337 | // ContextLocalInfoEntries part. |
| 4338 | class ContextLocalMode: public BitField<VariableMode, 0, 3> {}; |
| 4339 | class ContextLocalInitFlag: public BitField<InitializationFlag, 3, 1> {}; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4340 | class ContextLocalMaybeAssignedFlag |
| 4341 | : public BitField<MaybeAssignedFlag, 4, 1> {}; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4342 | |
| 4343 | friend class ScopeIterator; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4344 | }; |
| 4345 | |
| 4346 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4347 | // The cache for maps used by normalized (dictionary mode) objects. |
| 4348 | // Such maps do not have property descriptors, so a typical program |
| 4349 | // needs very limited number of distinct normalized maps. |
| 4350 | class NormalizedMapCache: public FixedArray { |
| 4351 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4352 | static Handle<NormalizedMapCache> New(Isolate* isolate); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4353 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4354 | MUST_USE_RESULT MaybeHandle<Map> Get(Handle<Map> fast_map, |
| 4355 | PropertyNormalizationMode mode); |
| 4356 | void Set(Handle<Map> fast_map, Handle<Map> normalized_map); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4357 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4358 | void Clear(); |
| 4359 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4360 | DECLARE_CAST(NormalizedMapCache) |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4361 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 4362 | static inline bool IsNormalizedMapCache(const HeapObject* obj); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4363 | |
| 4364 | DECLARE_VERIFIER(NormalizedMapCache) |
| 4365 | private: |
| 4366 | static const int kEntries = 64; |
| 4367 | |
| 4368 | static inline int GetIndex(Handle<Map> map); |
| 4369 | |
| 4370 | // The following declarations hide base class methods. |
| 4371 | Object* get(int index); |
| 4372 | void set(int index, Object* value); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4373 | }; |
| 4374 | |
| 4375 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4376 | // ByteArray represents fixed sized byte arrays. Used for the relocation info |
| 4377 | // that is attached to code objects. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 4378 | class ByteArray: public FixedArrayBase { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4379 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4380 | inline int Size(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4381 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4382 | // Setter and getter. |
| 4383 | inline byte get(int index); |
| 4384 | inline void set(int index, byte value); |
| 4385 | |
| 4386 | // Treat contents as an int array. |
| 4387 | inline int get_int(int index); |
| 4388 | |
| 4389 | static int SizeFor(int length) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4390 | return OBJECT_POINTER_ALIGN(kHeaderSize + length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4391 | } |
| 4392 | // We use byte arrays for free blocks in the heap. Given a desired size in |
| 4393 | // bytes that is a multiple of the word size and big enough to hold a byte |
| 4394 | // array, this function returns the number of elements a byte array should |
| 4395 | // have. |
| 4396 | static int LengthFor(int size_in_bytes) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4397 | DCHECK(IsAligned(size_in_bytes, kPointerSize)); |
| 4398 | DCHECK(size_in_bytes >= kHeaderSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4399 | return size_in_bytes - kHeaderSize; |
| 4400 | } |
| 4401 | |
| 4402 | // Returns data start address. |
| 4403 | inline Address GetDataStartAddress(); |
| 4404 | |
| 4405 | // Returns a pointer to the ByteArray object for a given data start address. |
| 4406 | static inline ByteArray* FromDataStartAddress(Address address); |
| 4407 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4408 | DECLARE_CAST(ByteArray) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4409 | |
| 4410 | // Dispatched behavior. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4411 | inline int ByteArraySize(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4412 | DECLARE_PRINTER(ByteArray) |
| 4413 | DECLARE_VERIFIER(ByteArray) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4414 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4415 | // Layout description. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4416 | static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4417 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4418 | // Maximal memory consumption for a single ByteArray. |
| 4419 | static const int kMaxSize = 512 * MB; |
| 4420 | // Maximal length of a single ByteArray. |
| 4421 | static const int kMaxLength = kMaxSize - kHeaderSize; |
| 4422 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4423 | private: |
| 4424 | DISALLOW_IMPLICIT_CONSTRUCTORS(ByteArray); |
| 4425 | }; |
| 4426 | |
| 4427 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4428 | // BytecodeArray represents a sequence of interpreter bytecodes. |
| 4429 | class BytecodeArray : public FixedArrayBase { |
| 4430 | public: |
| 4431 | static int SizeFor(int length) { |
| 4432 | return OBJECT_POINTER_ALIGN(kHeaderSize + length); |
| 4433 | } |
| 4434 | |
| 4435 | // Setter and getter |
| 4436 | inline byte get(int index); |
| 4437 | inline void set(int index, byte value); |
| 4438 | |
| 4439 | // Returns data start address. |
| 4440 | inline Address GetFirstBytecodeAddress(); |
| 4441 | |
| 4442 | // Accessors for frame size. |
| 4443 | inline int frame_size() const; |
| 4444 | inline void set_frame_size(int frame_size); |
| 4445 | |
| 4446 | // Accessor for register count (derived from frame_size). |
| 4447 | inline int register_count() const; |
| 4448 | |
| 4449 | // Accessors for parameter count (including implicit 'this' receiver). |
| 4450 | inline int parameter_count() const; |
| 4451 | inline void set_parameter_count(int number_of_parameters); |
| 4452 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 4453 | // Accessors for profiling count. |
| 4454 | inline int interrupt_budget() const; |
| 4455 | inline void set_interrupt_budget(int interrupt_budget); |
| 4456 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4457 | // Accessors for the constant pool. |
| 4458 | DECL_ACCESSORS(constant_pool, FixedArray) |
| 4459 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 4460 | // Accessors for handler table containing offsets of exception handlers. |
| 4461 | DECL_ACCESSORS(handler_table, FixedArray) |
| 4462 | |
| 4463 | // Accessors for source position table containing mappings between byte code |
| 4464 | // offset and source position. |
| 4465 | DECL_ACCESSORS(source_position_table, FixedArray) |
| 4466 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4467 | DECLARE_CAST(BytecodeArray) |
| 4468 | |
| 4469 | // Dispatched behavior. |
| 4470 | inline int BytecodeArraySize(); |
| 4471 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 4472 | inline int instruction_size(); |
| 4473 | |
| 4474 | int SourcePosition(int offset); |
| 4475 | int SourceStatementPosition(int offset); |
| 4476 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4477 | DECLARE_PRINTER(BytecodeArray) |
| 4478 | DECLARE_VERIFIER(BytecodeArray) |
| 4479 | |
| 4480 | void Disassemble(std::ostream& os); |
| 4481 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 4482 | void CopyBytecodesTo(BytecodeArray* to); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4483 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 4484 | // Layout description. |
| 4485 | static const int kConstantPoolOffset = FixedArrayBase::kHeaderSize; |
| 4486 | static const int kHandlerTableOffset = kConstantPoolOffset + kPointerSize; |
| 4487 | static const int kSourcePositionTableOffset = |
| 4488 | kHandlerTableOffset + kPointerSize; |
| 4489 | static const int kFrameSizeOffset = kSourcePositionTableOffset + kPointerSize; |
| 4490 | static const int kParameterSizeOffset = kFrameSizeOffset + kIntSize; |
| 4491 | static const int kInterruptBudgetOffset = kParameterSizeOffset + kIntSize; |
| 4492 | static const int kHeaderSize = kInterruptBudgetOffset + kIntSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4493 | |
| 4494 | // Maximal memory consumption for a single BytecodeArray. |
| 4495 | static const int kMaxSize = 512 * MB; |
| 4496 | // Maximal length of a single BytecodeArray. |
| 4497 | static const int kMaxLength = kMaxSize - kHeaderSize; |
| 4498 | |
| 4499 | class BodyDescriptor; |
| 4500 | |
| 4501 | private: |
| 4502 | DISALLOW_IMPLICIT_CONSTRUCTORS(BytecodeArray); |
| 4503 | }; |
| 4504 | |
| 4505 | |
| 4506 | // FreeSpace are fixed-size free memory blocks used by the heap and GC. |
| 4507 | // They look like heap objects (are heap object tagged and have a map) so that |
| 4508 | // the heap remains iterable. They have a size and a next pointer. |
| 4509 | // The next pointer is the raw address of the next FreeSpace object (or NULL) |
| 4510 | // in the free list. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4511 | class FreeSpace: public HeapObject { |
| 4512 | public: |
| 4513 | // [size]: size of the free space including the header. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4514 | inline int size() const; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4515 | inline void set_size(int value); |
| 4516 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4517 | inline int nobarrier_size() const; |
| 4518 | inline void nobarrier_set_size(int value); |
| 4519 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4520 | inline int Size(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4521 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4522 | // Accessors for the next field. |
| 4523 | inline FreeSpace* next(); |
| 4524 | inline void set_next(FreeSpace* next); |
| 4525 | |
| 4526 | inline static FreeSpace* cast(HeapObject* obj); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4527 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4528 | // Dispatched behavior. |
| 4529 | DECLARE_PRINTER(FreeSpace) |
| 4530 | DECLARE_VERIFIER(FreeSpace) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4531 | |
| 4532 | // Layout description. |
| 4533 | // Size is smi tagged when it is stored. |
| 4534 | static const int kSizeOffset = HeapObject::kHeaderSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4535 | static const int kNextOffset = POINTER_SIZE_ALIGN(kSizeOffset + kPointerSize); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4536 | |
| 4537 | private: |
| 4538 | DISALLOW_IMPLICIT_CONSTRUCTORS(FreeSpace); |
| 4539 | }; |
| 4540 | |
| 4541 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4542 | // V has parameters (Type, type, TYPE, C type, element_size) |
| 4543 | #define TYPED_ARRAYS(V) \ |
| 4544 | V(Uint8, uint8, UINT8, uint8_t, 1) \ |
| 4545 | V(Int8, int8, INT8, int8_t, 1) \ |
| 4546 | V(Uint16, uint16, UINT16, uint16_t, 2) \ |
| 4547 | V(Int16, int16, INT16, int16_t, 2) \ |
| 4548 | V(Uint32, uint32, UINT32, uint32_t, 4) \ |
| 4549 | V(Int32, int32, INT32, int32_t, 4) \ |
| 4550 | V(Float32, float32, FLOAT32, float, 4) \ |
| 4551 | V(Float64, float64, FLOAT64, double, 8) \ |
| 4552 | V(Uint8Clamped, uint8_clamped, UINT8_CLAMPED, uint8_t, 1) |
| 4553 | |
| 4554 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4555 | class FixedTypedArrayBase: public FixedArrayBase { |
| 4556 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4557 | // [base_pointer]: Either points to the FixedTypedArrayBase itself or nullptr. |
| 4558 | DECL_ACCESSORS(base_pointer, Object) |
| 4559 | |
| 4560 | // [external_pointer]: Contains the offset between base_pointer and the start |
| 4561 | // of the data. If the base_pointer is a nullptr, the external_pointer |
| 4562 | // therefore points to the actual backing store. |
| 4563 | DECL_ACCESSORS(external_pointer, void) |
| 4564 | |
| 4565 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4566 | DECLARE_CAST(FixedTypedArrayBase) |
| 4567 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4568 | static const int kBasePointerOffset = FixedArrayBase::kHeaderSize; |
| 4569 | static const int kExternalPointerOffset = kBasePointerOffset + kPointerSize; |
| 4570 | static const int kHeaderSize = |
| 4571 | DOUBLE_POINTER_ALIGN(kExternalPointerOffset + kPointerSize); |
| 4572 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4573 | static const int kDataOffset = kHeaderSize; |
| 4574 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4575 | class BodyDescriptor; |
| 4576 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4577 | inline int size(); |
| 4578 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4579 | static inline int TypedArraySize(InstanceType type, int length); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4580 | inline int TypedArraySize(InstanceType type); |
| 4581 | |
| 4582 | // Use with care: returns raw pointer into heap. |
| 4583 | inline void* DataPtr(); |
| 4584 | |
| 4585 | inline int DataSize(); |
| 4586 | |
| 4587 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4588 | static inline int ElementSize(InstanceType type); |
| 4589 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4590 | inline int DataSize(InstanceType type); |
| 4591 | |
| 4592 | DISALLOW_IMPLICIT_CONSTRUCTORS(FixedTypedArrayBase); |
| 4593 | }; |
| 4594 | |
| 4595 | |
| 4596 | template <class Traits> |
| 4597 | class FixedTypedArray: public FixedTypedArrayBase { |
| 4598 | public: |
| 4599 | typedef typename Traits::ElementType ElementType; |
| 4600 | static const InstanceType kInstanceType = Traits::kInstanceType; |
| 4601 | |
| 4602 | DECLARE_CAST(FixedTypedArray<Traits>) |
| 4603 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4604 | inline ElementType get_scalar(int index); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 4605 | static inline Handle<Object> get(FixedTypedArray* array, int index); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4606 | inline void set(int index, ElementType value); |
| 4607 | |
| 4608 | static inline ElementType from_int(int value); |
| 4609 | static inline ElementType from_double(double value); |
| 4610 | |
| 4611 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 4612 | // and undefined. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4613 | inline void SetValue(uint32_t index, Object* value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4614 | |
| 4615 | DECLARE_PRINTER(FixedTypedArray) |
| 4616 | DECLARE_VERIFIER(FixedTypedArray) |
| 4617 | |
| 4618 | private: |
| 4619 | DISALLOW_IMPLICIT_CONSTRUCTORS(FixedTypedArray); |
| 4620 | }; |
| 4621 | |
| 4622 | #define FIXED_TYPED_ARRAY_TRAITS(Type, type, TYPE, elementType, size) \ |
| 4623 | class Type##ArrayTraits { \ |
| 4624 | public: /* NOLINT */ \ |
| 4625 | typedef elementType ElementType; \ |
| 4626 | static const InstanceType kInstanceType = FIXED_##TYPE##_ARRAY_TYPE; \ |
| 4627 | static const char* Designator() { return #type " array"; } \ |
| 4628 | static inline Handle<Object> ToHandle(Isolate* isolate, \ |
| 4629 | elementType scalar); \ |
| 4630 | static inline elementType defaultValue(); \ |
| 4631 | }; \ |
| 4632 | \ |
| 4633 | typedef FixedTypedArray<Type##ArrayTraits> Fixed##Type##Array; |
| 4634 | |
| 4635 | TYPED_ARRAYS(FIXED_TYPED_ARRAY_TRAITS) |
| 4636 | |
| 4637 | #undef FIXED_TYPED_ARRAY_TRAITS |
| 4638 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 4639 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4640 | // DeoptimizationInputData is a fixed array used to hold the deoptimization |
| 4641 | // data for code generated by the Hydrogen/Lithium compiler. It also |
| 4642 | // contains information about functions that were inlined. If N different |
| 4643 | // functions were inlined then first N elements of the literal array will |
| 4644 | // contain these functions. |
| 4645 | // |
| 4646 | // It can be empty. |
| 4647 | class DeoptimizationInputData: public FixedArray { |
| 4648 | public: |
| 4649 | // Layout description. Indices in the array. |
| 4650 | static const int kTranslationByteArrayIndex = 0; |
| 4651 | static const int kInlinedFunctionCountIndex = 1; |
| 4652 | static const int kLiteralArrayIndex = 2; |
| 4653 | static const int kOsrAstIdIndex = 3; |
| 4654 | static const int kOsrPcOffsetIndex = 4; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4655 | static const int kOptimizationIdIndex = 5; |
| 4656 | static const int kSharedFunctionInfoIndex = 6; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4657 | static const int kWeakCellCacheIndex = 7; |
| 4658 | static const int kFirstDeoptEntryIndex = 8; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4659 | |
| 4660 | // Offsets of deopt entry elements relative to the start of the entry. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4661 | static const int kAstIdRawOffset = 0; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4662 | static const int kTranslationIndexOffset = 1; |
| 4663 | static const int kArgumentsStackHeightOffset = 2; |
Ben Murdoch | 2b4ba11 | 2012-01-20 14:57:15 +0000 | [diff] [blame] | 4664 | static const int kPcOffset = 3; |
| 4665 | static const int kDeoptEntrySize = 4; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4666 | |
| 4667 | // Simple element accessors. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4668 | #define DECLARE_ELEMENT_ACCESSORS(name, type) \ |
| 4669 | inline type* name(); \ |
| 4670 | inline void Set##name(type* value); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4671 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4672 | DECLARE_ELEMENT_ACCESSORS(TranslationByteArray, ByteArray) |
| 4673 | DECLARE_ELEMENT_ACCESSORS(InlinedFunctionCount, Smi) |
| 4674 | DECLARE_ELEMENT_ACCESSORS(LiteralArray, FixedArray) |
| 4675 | DECLARE_ELEMENT_ACCESSORS(OsrAstId, Smi) |
| 4676 | DECLARE_ELEMENT_ACCESSORS(OsrPcOffset, Smi) |
| 4677 | DECLARE_ELEMENT_ACCESSORS(OptimizationId, Smi) |
| 4678 | DECLARE_ELEMENT_ACCESSORS(SharedFunctionInfo, Object) |
| 4679 | DECLARE_ELEMENT_ACCESSORS(WeakCellCache, Object) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4680 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4681 | #undef DECLARE_ELEMENT_ACCESSORS |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4682 | |
| 4683 | // Accessors for elements of the ith deoptimization entry. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4684 | #define DECLARE_ENTRY_ACCESSORS(name, type) \ |
| 4685 | inline type* name(int i); \ |
| 4686 | inline void Set##name(int i, type* value); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4687 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4688 | DECLARE_ENTRY_ACCESSORS(AstIdRaw, Smi) |
| 4689 | DECLARE_ENTRY_ACCESSORS(TranslationIndex, Smi) |
| 4690 | DECLARE_ENTRY_ACCESSORS(ArgumentsStackHeight, Smi) |
| 4691 | DECLARE_ENTRY_ACCESSORS(Pc, Smi) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4692 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4693 | #undef DECLARE_ENTRY_ACCESSORS |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4694 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4695 | inline BailoutId AstId(int i); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4696 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4697 | inline void SetAstId(int i, BailoutId value); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4698 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4699 | inline int DeoptCount(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4700 | |
| 4701 | // Allocates a DeoptimizationInputData. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4702 | static Handle<DeoptimizationInputData> New(Isolate* isolate, |
| 4703 | int deopt_entry_count, |
| 4704 | PretenureFlag pretenure); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4705 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4706 | DECLARE_CAST(DeoptimizationInputData) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4707 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4708 | #ifdef ENABLE_DISASSEMBLER |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 4709 | void DeoptimizationInputDataPrint(std::ostream& os); // NOLINT |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4710 | #endif |
| 4711 | |
| 4712 | private: |
| 4713 | static int IndexForEntry(int i) { |
| 4714 | return kFirstDeoptEntryIndex + (i * kDeoptEntrySize); |
| 4715 | } |
| 4716 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4717 | |
| 4718 | static int LengthFor(int entry_count) { return IndexForEntry(entry_count); } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4719 | }; |
| 4720 | |
| 4721 | |
| 4722 | // DeoptimizationOutputData is a fixed array used to hold the deoptimization |
| 4723 | // data for code generated by the full compiler. |
| 4724 | // The format of the these objects is |
| 4725 | // [i * 2]: Ast ID for ith deoptimization. |
| 4726 | // [i * 2 + 1]: PC and state of ith deoptimization |
| 4727 | class DeoptimizationOutputData: public FixedArray { |
| 4728 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4729 | inline int DeoptPoints(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4730 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4731 | inline BailoutId AstId(int index); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4732 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4733 | inline void SetAstId(int index, BailoutId id); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4734 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4735 | inline Smi* PcAndState(int index); |
| 4736 | inline void SetPcAndState(int index, Smi* offset); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4737 | |
| 4738 | static int LengthOfFixedArray(int deopt_points) { |
| 4739 | return deopt_points * 2; |
| 4740 | } |
| 4741 | |
| 4742 | // Allocates a DeoptimizationOutputData. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4743 | static Handle<DeoptimizationOutputData> New(Isolate* isolate, |
| 4744 | int number_of_deopt_points, |
| 4745 | PretenureFlag pretenure); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4746 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4747 | DECLARE_CAST(DeoptimizationOutputData) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4748 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 4749 | #ifdef ENABLE_DISASSEMBLER |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 4750 | void DeoptimizationOutputDataPrint(std::ostream& os); // NOLINT |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4751 | #endif |
| 4752 | }; |
| 4753 | |
| 4754 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4755 | // A literals array contains the literals for a JSFunction. It also holds |
| 4756 | // the type feedback vector. |
| 4757 | class LiteralsArray : public FixedArray { |
| 4758 | public: |
| 4759 | static const int kVectorIndex = 0; |
| 4760 | static const int kFirstLiteralIndex = 1; |
| 4761 | static const int kOffsetToFirstLiteral = |
| 4762 | FixedArray::kHeaderSize + kPointerSize; |
| 4763 | |
| 4764 | static int OffsetOfLiteralAt(int index) { |
| 4765 | return SizeFor(index + kFirstLiteralIndex); |
| 4766 | } |
| 4767 | |
| 4768 | inline TypeFeedbackVector* feedback_vector() const; |
| 4769 | inline void set_feedback_vector(TypeFeedbackVector* vector); |
| 4770 | inline Object* literal(int literal_index) const; |
| 4771 | inline void set_literal(int literal_index, Object* literal); |
| 4772 | inline int literals_count() const; |
| 4773 | |
| 4774 | static Handle<LiteralsArray> New(Isolate* isolate, |
| 4775 | Handle<TypeFeedbackVector> vector, |
| 4776 | int number_of_literals, |
| 4777 | PretenureFlag pretenure); |
| 4778 | |
| 4779 | DECLARE_CAST(LiteralsArray) |
| 4780 | |
| 4781 | private: |
| 4782 | inline Object* get(int index) const; |
| 4783 | inline void set(int index, Object* value); |
| 4784 | inline void set(int index, Smi* value); |
| 4785 | inline void set(int index, Object* value, WriteBarrierMode mode); |
| 4786 | }; |
| 4787 | |
| 4788 | |
| 4789 | // HandlerTable is a fixed array containing entries for exception handlers in |
| 4790 | // the code object it is associated with. The tables comes in two flavors: |
| 4791 | // 1) Based on ranges: Used for unoptimized code. Contains one entry per |
| 4792 | // exception handler and a range representing the try-block covered by that |
| 4793 | // handler. Layout looks as follows: |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 4794 | // [ range-start , range-end , handler-offset , handler-data ] |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4795 | // 2) Based on return addresses: Used for turbofanned code. Contains one entry |
| 4796 | // per call-site that could throw an exception. Layout looks as follows: |
| 4797 | // [ return-address-offset , handler-offset ] |
| 4798 | class HandlerTable : public FixedArray { |
| 4799 | public: |
| 4800 | // Conservative prediction whether a given handler will locally catch an |
| 4801 | // exception or cause a re-throw to outside the code boundary. Since this is |
| 4802 | // undecidable it is merely an approximation (e.g. useful for debugger). |
| 4803 | enum CatchPrediction { UNCAUGHT, CAUGHT }; |
| 4804 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 4805 | // Getters for handler table based on ranges. |
| 4806 | inline int GetRangeStart(int index) const; |
| 4807 | inline int GetRangeEnd(int index) const; |
| 4808 | inline int GetRangeHandler(int index) const; |
| 4809 | inline int GetRangeData(int index) const; |
| 4810 | |
| 4811 | // Setters for handler table based on ranges. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4812 | inline void SetRangeStart(int index, int value); |
| 4813 | inline void SetRangeEnd(int index, int value); |
| 4814 | inline void SetRangeHandler(int index, int offset, CatchPrediction pred); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 4815 | inline void SetRangeData(int index, int value); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4816 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 4817 | // Setters for handler table based on return addresses. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4818 | inline void SetReturnOffset(int index, int value); |
| 4819 | inline void SetReturnHandler(int index, int offset, CatchPrediction pred); |
| 4820 | |
| 4821 | // Lookup handler in a table based on ranges. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 4822 | int LookupRange(int pc_offset, int* data, CatchPrediction* prediction); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4823 | |
| 4824 | // Lookup handler in a table based on return addresses. |
| 4825 | int LookupReturn(int pc_offset, CatchPrediction* prediction); |
| 4826 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 4827 | // Returns the conservative catch predication. |
| 4828 | inline CatchPrediction GetRangePrediction(int index) const; |
| 4829 | |
| 4830 | // Returns the number of entries in the table. |
| 4831 | inline int NumberOfRangeEntries() const; |
| 4832 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4833 | // Returns the required length of the underlying fixed array. |
| 4834 | static int LengthForRange(int entries) { return entries * kRangeEntrySize; } |
| 4835 | static int LengthForReturn(int entries) { return entries * kReturnEntrySize; } |
| 4836 | |
| 4837 | DECLARE_CAST(HandlerTable) |
| 4838 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 4839 | #ifdef ENABLE_DISASSEMBLER |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4840 | void HandlerTableRangePrint(std::ostream& os); // NOLINT |
| 4841 | void HandlerTableReturnPrint(std::ostream& os); // NOLINT |
| 4842 | #endif |
| 4843 | |
| 4844 | private: |
| 4845 | // Layout description for handler table based on ranges. |
| 4846 | static const int kRangeStartIndex = 0; |
| 4847 | static const int kRangeEndIndex = 1; |
| 4848 | static const int kRangeHandlerIndex = 2; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 4849 | static const int kRangeDataIndex = 3; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4850 | static const int kRangeEntrySize = 4; |
| 4851 | |
| 4852 | // Layout description for handler table based on return addresses. |
| 4853 | static const int kReturnOffsetIndex = 0; |
| 4854 | static const int kReturnHandlerIndex = 1; |
| 4855 | static const int kReturnEntrySize = 2; |
| 4856 | |
| 4857 | // Encoding of the {handler} field. |
| 4858 | class HandlerPredictionField : public BitField<CatchPrediction, 0, 1> {}; |
| 4859 | class HandlerOffsetField : public BitField<int, 1, 30> {}; |
| 4860 | }; |
| 4861 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4862 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4863 | // Code describes objects with on-the-fly generated machine code. |
| 4864 | class Code: public HeapObject { |
| 4865 | public: |
| 4866 | // Opaque data type for encapsulating code flags like kind, inline |
| 4867 | // cache state, and arguments count. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4868 | typedef uint32_t Flags; |
| 4869 | |
| 4870 | #define NON_IC_KIND_LIST(V) \ |
| 4871 | V(FUNCTION) \ |
| 4872 | V(OPTIMIZED_FUNCTION) \ |
| 4873 | V(STUB) \ |
| 4874 | V(HANDLER) \ |
| 4875 | V(BUILTIN) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4876 | V(REGEXP) \ |
| 4877 | V(WASM_FUNCTION) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4878 | |
| 4879 | #define IC_KIND_LIST(V) \ |
| 4880 | V(LOAD_IC) \ |
| 4881 | V(KEYED_LOAD_IC) \ |
| 4882 | V(CALL_IC) \ |
| 4883 | V(STORE_IC) \ |
| 4884 | V(KEYED_STORE_IC) \ |
| 4885 | V(BINARY_OP_IC) \ |
| 4886 | V(COMPARE_IC) \ |
| 4887 | V(COMPARE_NIL_IC) \ |
| 4888 | V(TO_BOOLEAN_IC) |
| 4889 | |
| 4890 | #define CODE_KIND_LIST(V) \ |
| 4891 | NON_IC_KIND_LIST(V) \ |
| 4892 | IC_KIND_LIST(V) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4893 | |
| 4894 | enum Kind { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4895 | #define DEFINE_CODE_KIND_ENUM(name) name, |
| 4896 | CODE_KIND_LIST(DEFINE_CODE_KIND_ENUM) |
| 4897 | #undef DEFINE_CODE_KIND_ENUM |
| 4898 | NUMBER_OF_KINDS |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4899 | }; |
| 4900 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4901 | // 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] | 4902 | // Flags. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4903 | STATIC_ASSERT(NUMBER_OF_KINDS <= 32); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4904 | |
| 4905 | static const char* Kind2String(Kind kind); |
| 4906 | |
| 4907 | // Types of stubs. |
| 4908 | enum StubType { |
| 4909 | NORMAL, |
| 4910 | FAST |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4911 | }; |
| 4912 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4913 | static const int kPrologueOffsetNotSet = -1; |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4914 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4915 | #ifdef ENABLE_DISASSEMBLER |
| 4916 | // Printing |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4917 | static const char* ICState2String(InlineCacheState state); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4918 | static const char* StubType2String(StubType type); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 4919 | static void PrintExtraICState(std::ostream& os, // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4920 | Kind kind, ExtraICState extra); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 4921 | void Disassemble(const char* name, std::ostream& os); // NOLINT |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4922 | #endif // ENABLE_DISASSEMBLER |
| 4923 | |
| 4924 | // [instruction_size]: Size of the native instructions |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4925 | inline int instruction_size() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4926 | inline void set_instruction_size(int value); |
| 4927 | |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 4928 | // [relocation_info]: Code relocation information |
| 4929 | DECL_ACCESSORS(relocation_info, ByteArray) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4930 | void InvalidateRelocation(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4931 | void InvalidateEmbeddedObjects(); |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 4932 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4933 | // [handler_table]: Fixed array containing offsets of exception handlers. |
| 4934 | DECL_ACCESSORS(handler_table, FixedArray) |
| 4935 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4936 | // [deoptimization_data]: Array containing data for deopt. |
| 4937 | DECL_ACCESSORS(deoptimization_data, FixedArray) |
| 4938 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4939 | // [raw_type_feedback_info]: This field stores various things, depending on |
| 4940 | // the kind of the code object. |
| 4941 | // FUNCTION => type feedback information. |
| 4942 | // STUB and ICs => major/minor key as Smi. |
| 4943 | DECL_ACCESSORS(raw_type_feedback_info, Object) |
| 4944 | inline Object* type_feedback_info(); |
| 4945 | inline void set_type_feedback_info( |
| 4946 | Object* value, WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| 4947 | inline uint32_t stub_key(); |
| 4948 | inline void set_stub_key(uint32_t key); |
| 4949 | |
| 4950 | // [next_code_link]: Link for lists of optimized or deoptimized code. |
| 4951 | // Note that storage for this field is overlapped with typefeedback_info. |
| 4952 | DECL_ACCESSORS(next_code_link, Object) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4953 | |
| 4954 | // [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] | 4955 | // field does not have to be traced during garbage collection since |
| 4956 | // it is only used by the garbage collector itself. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4957 | DECL_ACCESSORS(gc_metadata, Object) |
| 4958 | |
| 4959 | // [ic_age]: Inline caching age: the value of the Heap::global_ic_age |
| 4960 | // at the moment when this object was created. |
| 4961 | inline void set_ic_age(int count); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4962 | inline int ic_age() const; |
| 4963 | |
| 4964 | // [prologue_offset]: Offset of the function prologue, used for aging |
| 4965 | // FUNCTIONs and OPTIMIZED_FUNCTIONs. |
| 4966 | inline int prologue_offset() const; |
| 4967 | inline void set_prologue_offset(int offset); |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame] | 4968 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4969 | // [constant_pool offset]: Offset of the constant pool. |
| 4970 | // Valid for FLAG_enable_embedded_constant_pool only |
| 4971 | inline int constant_pool_offset() const; |
| 4972 | inline void set_constant_pool_offset(int offset); |
| 4973 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4974 | // Unchecked accessors to be used during GC. |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 4975 | inline ByteArray* unchecked_relocation_info(); |
| 4976 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4977 | inline int relocation_size(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4978 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4979 | // [flags]: Various code flags. |
| 4980 | inline Flags flags(); |
| 4981 | inline void set_flags(Flags flags); |
| 4982 | |
| 4983 | // [flags]: Access to specific code flags. |
| 4984 | inline Kind kind(); |
| 4985 | inline InlineCacheState ic_state(); // Only valid for IC stubs. |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4986 | inline ExtraICState extra_ic_state(); // Only valid for IC stubs. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4987 | |
| 4988 | inline StubType type(); // Only valid for monomorphic IC stubs. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4989 | |
| 4990 | // Testers for IC stub kinds. |
| 4991 | inline bool is_inline_cache_stub(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4992 | inline bool is_debug_stub(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 4993 | inline bool is_handler(); |
| 4994 | inline bool is_load_stub(); |
| 4995 | inline bool is_keyed_load_stub(); |
| 4996 | inline bool is_store_stub(); |
| 4997 | inline bool is_keyed_store_stub(); |
| 4998 | inline bool is_call_stub(); |
| 4999 | inline bool is_binary_op_stub(); |
| 5000 | inline bool is_compare_ic_stub(); |
| 5001 | inline bool is_compare_nil_ic_stub(); |
| 5002 | inline bool is_to_boolean_ic_stub(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5003 | inline bool is_keyed_stub(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5004 | inline bool is_optimized_code(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5005 | inline bool embeds_maps_weakly(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5006 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5007 | inline bool IsCodeStubOrIC(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5008 | inline bool IsJavaScriptCode(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5009 | |
| 5010 | inline void set_raw_kind_specific_flags1(int value); |
| 5011 | inline void set_raw_kind_specific_flags2(int value); |
| 5012 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 5013 | // Testers for interpreter builtins. |
| 5014 | inline bool is_interpreter_entry_trampoline(); |
| 5015 | inline bool is_interpreter_enter_bytecode_dispatch(); |
| 5016 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5017 | // [is_crankshafted]: For kind STUB or ICs, tells whether or not a code |
| 5018 | // object was generated by either the hydrogen or the TurboFan optimizing |
| 5019 | // compiler (but it may not be an optimized function). |
| 5020 | inline bool is_crankshafted(); |
| 5021 | inline bool is_hydrogen_stub(); // Crankshafted, but not a function. |
| 5022 | inline void set_is_crankshafted(bool value); |
| 5023 | |
| 5024 | // [is_turbofanned]: For kind STUB or OPTIMIZED_FUNCTION, tells whether the |
| 5025 | // code object was generated by the TurboFan optimizing compiler. |
| 5026 | inline bool is_turbofanned(); |
| 5027 | inline void set_is_turbofanned(bool value); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5028 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5029 | // [can_have_weak_objects]: For kind OPTIMIZED_FUNCTION, tells whether the |
| 5030 | // embedded objects in code should be treated weakly. |
| 5031 | inline bool can_have_weak_objects(); |
| 5032 | inline void set_can_have_weak_objects(bool value); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5033 | |
| 5034 | // [has_deoptimization_support]: For FUNCTION kind, tells if it has |
| 5035 | // deoptimization support. |
| 5036 | inline bool has_deoptimization_support(); |
| 5037 | inline void set_has_deoptimization_support(bool value); |
| 5038 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 5039 | // [has_debug_break_slots]: For FUNCTION kind, tells if it has |
| 5040 | // been compiled with debug break slots. |
| 5041 | inline bool has_debug_break_slots(); |
| 5042 | inline void set_has_debug_break_slots(bool value); |
| 5043 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5044 | // [has_reloc_info_for_serialization]: For FUNCTION kind, tells if its |
| 5045 | // reloc info includes runtime and external references to support |
| 5046 | // serialization/deserialization. |
| 5047 | inline bool has_reloc_info_for_serialization(); |
| 5048 | inline void set_has_reloc_info_for_serialization(bool value); |
| 5049 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5050 | // [allow_osr_at_loop_nesting_level]: For FUNCTION kind, tells for |
| 5051 | // how long the function has been marked for OSR and therefore which |
| 5052 | // level of loop nesting we are willing to do on-stack replacement |
| 5053 | // for. |
| 5054 | inline void set_allow_osr_at_loop_nesting_level(int level); |
| 5055 | inline int allow_osr_at_loop_nesting_level(); |
| 5056 | |
Ben Murdoch | 8f9999f | 2012-04-23 10:39:17 +0100 | [diff] [blame] | 5057 | // [profiler_ticks]: For FUNCTION kind, tells for how many profiler ticks |
| 5058 | // the code object was seen on the stack with no IC patching going on. |
| 5059 | inline int profiler_ticks(); |
| 5060 | inline void set_profiler_ticks(int ticks); |
| 5061 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5062 | // [builtin_index]: For BUILTIN kind, tells which builtin index it has. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5063 | // For builtins, tells which builtin index it has. |
| 5064 | // Note that builtins can have a code kind other than BUILTIN, which means |
| 5065 | // that for arbitrary code objects, this index value may be random garbage. |
| 5066 | // 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] | 5067 | inline int builtin_index(); |
| 5068 | inline void set_builtin_index(int id); |
| 5069 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5070 | // [stack_slots]: For kind OPTIMIZED_FUNCTION, the number of stack slots |
| 5071 | // reserved in the code prologue. |
| 5072 | inline unsigned stack_slots(); |
| 5073 | inline void set_stack_slots(unsigned slots); |
| 5074 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5075 | // [safepoint_table_start]: For kind OPTIMIZED_FUNCTION, the offset in |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5076 | // the instruction stream where the safepoint table starts. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 5077 | inline unsigned safepoint_table_offset(); |
| 5078 | inline void set_safepoint_table_offset(unsigned offset); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5079 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5080 | // [back_edge_table_start]: For kind FUNCTION, the offset in the |
| 5081 | // instruction stream where the back edge table starts. |
| 5082 | inline unsigned back_edge_table_offset(); |
| 5083 | inline void set_back_edge_table_offset(unsigned offset); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5084 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5085 | inline bool back_edges_patched_for_osr(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5086 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 5087 | // [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] | 5088 | inline uint16_t to_boolean_state(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5089 | |
| 5090 | // [marked_for_deoptimization]: For kind OPTIMIZED_FUNCTION tells whether |
| 5091 | // the code is going to be deoptimized because of dead embedded maps. |
| 5092 | inline bool marked_for_deoptimization(); |
| 5093 | inline void set_marked_for_deoptimization(bool flag); |
| 5094 | |
| 5095 | // [constant_pool]: The constant pool for this function. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5096 | inline Address constant_pool(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5097 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 5098 | // Get the safepoint entry for the given pc. |
| 5099 | SafepointEntry GetSafepointEntry(Address pc); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5100 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5101 | // Find an object in a stub with a specified map |
| 5102 | Object* FindNthObject(int n, Map* match_map); |
| 5103 | |
| 5104 | // Find the first allocation site in an IC stub. |
| 5105 | AllocationSite* FindFirstAllocationSite(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5106 | |
| 5107 | // Find the first map in an IC stub. |
| 5108 | Map* FindFirstMap(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5109 | void FindAllMaps(MapHandleList* maps); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5110 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5111 | // Find the first handler in an IC stub. |
| 5112 | Code* FindFirstHandler(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5113 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5114 | // Find |length| handlers and put them into |code_list|. Returns false if not |
| 5115 | // enough handlers can be found. |
| 5116 | bool FindHandlers(CodeHandleList* code_list, int length = -1); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5117 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5118 | // Find the handler for |map|. |
| 5119 | MaybeHandle<Code> FindHandlerForMap(Map* map); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5120 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5121 | // Find the first name in an IC stub. |
| 5122 | Name* FindFirstName(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5123 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5124 | class FindAndReplacePattern; |
| 5125 | // For each (map-to-find, object-to-replace) pair in the pattern, this |
| 5126 | // function replaces the corresponding placeholder in the code with the |
| 5127 | // object-to-replace. The function assumes that pairs in the pattern come in |
| 5128 | // the same order as the placeholders in the code. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5129 | // If the placeholder is a weak cell, then the value of weak cell is matched |
| 5130 | // against the map-to-find. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5131 | void FindAndReplace(const FindAndReplacePattern& pattern); |
| 5132 | |
| 5133 | // The entire code object including its header is copied verbatim to the |
| 5134 | // snapshot so that it can be written in one, fast, memcpy during |
| 5135 | // deserialization. The deserializer will overwrite some pointers, rather |
| 5136 | // like a runtime linker, but the random allocation addresses used in the |
| 5137 | // mksnapshot process would still be present in the unlinked snapshot data, |
| 5138 | // which would make snapshot production non-reproducible. This method wipes |
| 5139 | // out the to-be-overwritten header data for reproducible snapshots. |
| 5140 | inline void WipeOutHeader(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5141 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5142 | // Flags operations. |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 5143 | static inline Flags ComputeFlags( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5144 | Kind kind, InlineCacheState ic_state = UNINITIALIZED, |
| 5145 | ExtraICState extra_ic_state = kNoExtraICState, StubType type = NORMAL, |
| 5146 | CacheHolderFlag holder = kCacheOnReceiver); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5147 | |
| 5148 | static inline Flags ComputeMonomorphicFlags( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5149 | Kind kind, ExtraICState extra_ic_state = kNoExtraICState, |
| 5150 | CacheHolderFlag holder = kCacheOnReceiver, StubType type = NORMAL); |
| 5151 | |
| 5152 | static inline Flags ComputeHandlerFlags( |
| 5153 | Kind handler_kind, StubType type = NORMAL, |
| 5154 | CacheHolderFlag holder = kCacheOnReceiver); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5155 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5156 | static inline InlineCacheState ExtractICStateFromFlags(Flags flags); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5157 | static inline StubType ExtractTypeFromFlags(Flags flags); |
| 5158 | static inline CacheHolderFlag ExtractCacheHolderFromFlags(Flags flags); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 5159 | static inline Kind ExtractKindFromFlags(Flags flags); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 5160 | static inline ExtraICState ExtractExtraICStateFromFlags(Flags flags); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 5161 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5162 | static inline Flags RemoveTypeFromFlags(Flags flags); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5163 | static inline Flags RemoveTypeAndHolderFromFlags(Flags flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5164 | |
| 5165 | // Convert a target address into a code object. |
| 5166 | static inline Code* GetCodeFromTargetAddress(Address address); |
| 5167 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 5168 | // Convert an entry address into an object. |
| 5169 | static inline Object* GetObjectFromEntryAddress(Address location_of_address); |
| 5170 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5171 | // Returns the address of the first instruction. |
| 5172 | inline byte* instruction_start(); |
| 5173 | |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 5174 | // Returns the address right after the last instruction. |
| 5175 | inline byte* instruction_end(); |
| 5176 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5177 | // Returns the size of the instructions, padding, and relocation information. |
| 5178 | inline int body_size(); |
| 5179 | |
| 5180 | // Returns the address of the first relocation info (read backwards!). |
| 5181 | inline byte* relocation_start(); |
| 5182 | |
| 5183 | // Code entry point. |
| 5184 | inline byte* entry(); |
| 5185 | |
| 5186 | // Returns true if pc is inside this object's instructions. |
| 5187 | inline bool contains(byte* pc); |
| 5188 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5189 | // Relocate the code by delta bytes. Called to signal that this code |
| 5190 | // object has been moved by delta bytes. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5191 | void Relocate(intptr_t delta); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5192 | |
| 5193 | // Migrate code described by desc. |
| 5194 | void CopyFrom(const CodeDesc& desc); |
| 5195 | |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 5196 | // Returns the object size for a given body (used for allocation). |
| 5197 | static int SizeFor(int body_size) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5198 | DCHECK_SIZE_TAG_ALIGNED(body_size); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 5199 | return RoundUp(kHeaderSize + body_size, kCodeAlignment); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5200 | } |
| 5201 | |
| 5202 | // Calculate the size of the code object to report for log events. This takes |
| 5203 | // the layout of the code object into account. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5204 | inline int ExecutableSize(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5205 | |
| 5206 | // Locating source position. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 5207 | int SourcePosition(int code_offset); |
| 5208 | int SourceStatementPosition(int code_offset); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5209 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5210 | DECLARE_CAST(Code) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5211 | |
| 5212 | // Dispatched behavior. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5213 | inline int CodeSize(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5214 | |
| 5215 | DECLARE_PRINTER(Code) |
| 5216 | DECLARE_VERIFIER(Code) |
| 5217 | |
Ben Murdoch | 8f9999f | 2012-04-23 10:39:17 +0100 | [diff] [blame] | 5218 | void ClearInlineCaches(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5219 | void ClearInlineCaches(Kind kind); |
| 5220 | |
| 5221 | BailoutId TranslatePcOffsetToAstId(uint32_t pc_offset); |
| 5222 | uint32_t TranslateAstIdToPcOffset(BailoutId ast_id); |
| 5223 | |
| 5224 | #define DECLARE_CODE_AGE_ENUM(X) k##X##CodeAge, |
| 5225 | enum Age { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5226 | kToBeExecutedOnceCodeAge = -3, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5227 | kNotExecutedCodeAge = -2, |
| 5228 | kExecutedOnceCodeAge = -1, |
| 5229 | kNoAgeCodeAge = 0, |
| 5230 | CODE_AGE_LIST(DECLARE_CODE_AGE_ENUM) |
| 5231 | kAfterLastCodeAge, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5232 | kFirstCodeAge = kToBeExecutedOnceCodeAge, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5233 | kLastCodeAge = kAfterLastCodeAge - 1, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5234 | kCodeAgeCount = kAfterLastCodeAge - kFirstCodeAge - 1, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5235 | kIsOldCodeAge = kSexagenarianCodeAge, |
| 5236 | kPreAgedCodeAge = kIsOldCodeAge - 1 |
| 5237 | }; |
| 5238 | #undef DECLARE_CODE_AGE_ENUM |
| 5239 | |
| 5240 | // Code aging. Indicates how many full GCs this code has survived without |
| 5241 | // being entered through the prologue. Used to determine when it is |
| 5242 | // relatively safe to flush this code object and replace it with the lazy |
| 5243 | // compilation stub. |
| 5244 | static void MakeCodeAgeSequenceYoung(byte* sequence, Isolate* isolate); |
| 5245 | static void MarkCodeAsExecuted(byte* sequence, Isolate* isolate); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5246 | void MakeYoung(Isolate* isolate); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5247 | void MarkToBeExecutedOnce(Isolate* isolate); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5248 | void MakeOlder(MarkingParity); |
| 5249 | static bool IsYoungSequence(Isolate* isolate, byte* sequence); |
| 5250 | bool IsOld(); |
| 5251 | Age GetAge(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5252 | static inline Code* GetPreAgedCodeAgeStub(Isolate* isolate) { |
| 5253 | return GetCodeAgeStub(isolate, kNotExecutedCodeAge, NO_MARKING_PARITY); |
| 5254 | } |
| 5255 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5256 | void PrintDeoptLocation(FILE* out, Address pc); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5257 | bool CanDeoptAt(Address pc); |
| 5258 | |
| 5259 | #ifdef VERIFY_HEAP |
| 5260 | void VerifyEmbeddedObjectsDependency(); |
| 5261 | #endif |
| 5262 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5263 | #ifdef DEBUG |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5264 | enum VerifyMode { kNoContextSpecificPointers, kNoContextRetainingPointers }; |
| 5265 | void VerifyEmbeddedObjects(VerifyMode mode = kNoContextRetainingPointers); |
| 5266 | static void VerifyRecompiledCode(Code* old_code, Code* new_code); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5267 | #endif // DEBUG |
| 5268 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5269 | inline bool CanContainWeakObjects(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5270 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5271 | inline bool IsWeakObject(Object* object); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5272 | |
| 5273 | static inline bool IsWeakObjectInOptimizedCode(Object* object); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5274 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5275 | static Handle<WeakCell> WeakCellFor(Handle<Code> code); |
| 5276 | WeakCell* CachedWeakCell(); |
| 5277 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5278 | // Max loop nesting marker used to postpose OSR. We don't take loop |
| 5279 | // nesting that is deeper than 5 levels into account. |
| 5280 | static const int kMaxLoopNestingMarker = 6; |
| 5281 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5282 | static const int kConstantPoolSize = |
| 5283 | FLAG_enable_embedded_constant_pool ? kIntSize : 0; |
| 5284 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5285 | // Layout description. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5286 | static const int kRelocationInfoOffset = HeapObject::kHeaderSize; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5287 | static const int kHandlerTableOffset = kRelocationInfoOffset + kPointerSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5288 | static const int kDeoptimizationDataOffset = |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5289 | kHandlerTableOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5290 | // For FUNCTION kind, we store the type feedback info here. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5291 | static const int kTypeFeedbackInfoOffset = |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame] | 5292 | kDeoptimizationDataOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5293 | static const int kNextCodeLinkOffset = kTypeFeedbackInfoOffset + kPointerSize; |
| 5294 | static const int kGCMetadataOffset = kNextCodeLinkOffset + kPointerSize; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5295 | static const int kInstructionSizeOffset = kGCMetadataOffset + kPointerSize; |
| 5296 | static const int kICAgeOffset = kInstructionSizeOffset + kIntSize; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5297 | static const int kFlagsOffset = kICAgeOffset + kIntSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5298 | static const int kKindSpecificFlags1Offset = kFlagsOffset + kIntSize; |
| 5299 | static const int kKindSpecificFlags2Offset = |
| 5300 | kKindSpecificFlags1Offset + kIntSize; |
| 5301 | // Note: We might be able to squeeze this into the flags above. |
| 5302 | static const int kPrologueOffset = kKindSpecificFlags2Offset + kIntSize; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5303 | static const int kConstantPoolOffset = kPrologueOffset + kIntSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5304 | static const int kHeaderPaddingStart = |
| 5305 | kConstantPoolOffset + kConstantPoolSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5306 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5307 | // Add padding to align the instruction start following right after |
| 5308 | // the Code object header. |
| 5309 | static const int kHeaderSize = |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5310 | (kHeaderPaddingStart + kCodeAlignmentMask) & ~kCodeAlignmentMask; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5311 | |
| 5312 | class BodyDescriptor; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5313 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5314 | // Byte offsets within kKindSpecificFlags1Offset. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5315 | static const int kFullCodeFlags = kKindSpecificFlags1Offset; |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 5316 | class FullCodeFlagsHasDeoptimizationSupportField: |
| 5317 | public BitField<bool, 0, 1> {}; // NOLINT |
| 5318 | class FullCodeFlagsHasDebugBreakSlotsField: public BitField<bool, 1, 1> {}; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5319 | class FullCodeFlagsHasRelocInfoForSerialization |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5320 | : public BitField<bool, 2, 1> {}; |
| 5321 | // Bit 3 in this bitfield is unused. |
| 5322 | class ProfilerTicksField : public BitField<int, 4, 28> {}; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5323 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 5324 | // Flags layout. BitField<type, shift, size>. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5325 | class ICStateField : public BitField<InlineCacheState, 0, 3> {}; |
| 5326 | class TypeField : public BitField<StubType, 3, 1> {}; |
| 5327 | class CacheHolderField : public BitField<CacheHolderFlag, 4, 2> {}; |
| 5328 | class KindField : public BitField<Kind, 6, 5> {}; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5329 | class ExtraICStateField: public BitField<ExtraICState, 11, |
| 5330 | PlatformSmiTagging::kSmiValueSize - 11 + 1> {}; // NOLINT |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5331 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5332 | // KindSpecificFlags1 layout (STUB and OPTIMIZED_FUNCTION) |
| 5333 | static const int kStackSlotsFirstBit = 0; |
| 5334 | static const int kStackSlotsBitCount = 24; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5335 | static const int kMarkedForDeoptimizationBit = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5336 | kStackSlotsFirstBit + kStackSlotsBitCount; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5337 | static const int kIsTurbofannedBit = kMarkedForDeoptimizationBit + 1; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5338 | static const int kCanHaveWeakObjects = kIsTurbofannedBit + 1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5339 | |
| 5340 | STATIC_ASSERT(kStackSlotsFirstBit + kStackSlotsBitCount <= 32); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5341 | STATIC_ASSERT(kCanHaveWeakObjects + 1 <= 32); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5342 | |
| 5343 | class StackSlotsField: public BitField<int, |
| 5344 | kStackSlotsFirstBit, kStackSlotsBitCount> {}; // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5345 | class MarkedForDeoptimizationField |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5346 | : public BitField<bool, kMarkedForDeoptimizationBit, 1> {}; // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5347 | class IsTurbofannedField : public BitField<bool, kIsTurbofannedBit, 1> { |
| 5348 | }; // NOLINT |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5349 | class CanHaveWeakObjectsField |
| 5350 | : public BitField<bool, kCanHaveWeakObjects, 1> {}; // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5351 | |
| 5352 | // KindSpecificFlags2 layout (ALL) |
| 5353 | static const int kIsCrankshaftedBit = 0; |
| 5354 | class IsCrankshaftedField: public BitField<bool, |
| 5355 | kIsCrankshaftedBit, 1> {}; // NOLINT |
| 5356 | |
| 5357 | // KindSpecificFlags2 layout (STUB and OPTIMIZED_FUNCTION) |
| 5358 | static const int kSafepointTableOffsetFirstBit = kIsCrankshaftedBit + 1; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5359 | static const int kSafepointTableOffsetBitCount = 30; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5360 | |
| 5361 | STATIC_ASSERT(kSafepointTableOffsetFirstBit + |
| 5362 | kSafepointTableOffsetBitCount <= 32); |
| 5363 | STATIC_ASSERT(1 + kSafepointTableOffsetBitCount <= 32); |
| 5364 | |
| 5365 | class SafepointTableOffsetField: public BitField<int, |
| 5366 | kSafepointTableOffsetFirstBit, |
| 5367 | kSafepointTableOffsetBitCount> {}; // NOLINT |
| 5368 | |
| 5369 | // KindSpecificFlags2 layout (FUNCTION) |
| 5370 | class BackEdgeTableOffsetField: public BitField<int, |
| 5371 | kIsCrankshaftedBit + 1, 27> {}; // NOLINT |
| 5372 | class AllowOSRAtLoopNestingLevelField: public BitField<int, |
| 5373 | kIsCrankshaftedBit + 1 + 27, 4> {}; // NOLINT |
| 5374 | STATIC_ASSERT(AllowOSRAtLoopNestingLevelField::kMax >= kMaxLoopNestingMarker); |
| 5375 | |
| 5376 | static const int kArgumentsBits = 16; |
| 5377 | static const int kMaxArguments = (1 << kArgumentsBits) - 1; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5378 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5379 | // This constant should be encodable in an ARM instruction. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5380 | static const int kFlagsNotUsedInLookup = |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 5381 | TypeField::kMask | CacheHolderField::kMask; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5382 | |
| 5383 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5384 | friend class RelocIterator; |
| 5385 | friend class Deoptimizer; // For FindCodeAgeSequence. |
| 5386 | |
| 5387 | void ClearInlineCaches(Kind* kind); |
| 5388 | |
| 5389 | // Code aging |
| 5390 | byte* FindCodeAgeSequence(); |
| 5391 | static void GetCodeAgeAndParity(Code* code, Age* age, |
| 5392 | MarkingParity* parity); |
| 5393 | static void GetCodeAgeAndParity(Isolate* isolate, byte* sequence, Age* age, |
| 5394 | MarkingParity* parity); |
| 5395 | static Code* GetCodeAgeStub(Isolate* isolate, Age age, MarkingParity parity); |
| 5396 | |
| 5397 | // Code aging -- platform-specific |
| 5398 | static void PatchPlatformCodeAge(Isolate* isolate, |
| 5399 | byte* sequence, Age age, |
| 5400 | MarkingParity parity); |
| 5401 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5402 | DISALLOW_IMPLICIT_CONSTRUCTORS(Code); |
| 5403 | }; |
| 5404 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 5405 | class AbstractCode : public HeapObject { |
| 5406 | public: |
| 5407 | int SourcePosition(int offset); |
| 5408 | int SourceStatementPosition(int offset); |
| 5409 | |
| 5410 | DECLARE_CAST(AbstractCode) |
| 5411 | inline int Size(); |
| 5412 | inline Code* GetCode(); |
| 5413 | inline BytecodeArray* GetBytecodeArray(); |
| 5414 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5415 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5416 | // Dependent code is a singly linked list of fixed arrays. Each array contains |
| 5417 | // code objects in weak cells for one dependent group. The suffix of the array |
| 5418 | // can be filled with the undefined value if the number of codes is less than |
| 5419 | // the length of the array. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5420 | // |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5421 | // +------+-----------------+--------+--------+-----+--------+-----------+-----+ |
| 5422 | // | next | count & group 1 | code 1 | code 2 | ... | code n | undefined | ... | |
| 5423 | // +------+-----------------+--------+--------+-----+--------+-----------+-----+ |
| 5424 | // | |
| 5425 | // V |
| 5426 | // +------+-----------------+--------+--------+-----+--------+-----------+-----+ |
| 5427 | // | next | count & group 2 | code 1 | code 2 | ... | code m | undefined | ... | |
| 5428 | // +------+-----------------+--------+--------+-----+--------+-----------+-----+ |
| 5429 | // | |
| 5430 | // V |
| 5431 | // empty_fixed_array() |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5432 | // |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5433 | // The list of fixed arrays is ordered by dependency groups. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5434 | |
| 5435 | class DependentCode: public FixedArray { |
| 5436 | public: |
| 5437 | enum DependencyGroup { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5438 | // Group of code that weakly embed this map and depend on being |
| 5439 | // deoptimized when the map is garbage collected. |
| 5440 | kWeakCodeGroup, |
| 5441 | // Group of code that embed a transition to this map, and depend on being |
| 5442 | // deoptimized when the transition is replaced by a new version. |
| 5443 | kTransitionGroup, |
| 5444 | // Group of code that omit run-time prototype checks for prototypes |
| 5445 | // described by this map. The group is deoptimized whenever an object |
| 5446 | // described by this map changes shape (and transitions to a new map), |
| 5447 | // possibly invalidating the assumptions embedded in the code. |
| 5448 | kPrototypeCheckGroup, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5449 | // Group of code that depends on global property values in property cells |
| 5450 | // not being changed. |
| 5451 | kPropertyCellChangedGroup, |
| 5452 | // Group of code that omit run-time type checks for the field(s) introduced |
| 5453 | // by this map. |
| 5454 | kFieldTypeGroup, |
| 5455 | // Group of code that omit run-time type checks for initial maps of |
| 5456 | // constructors. |
| 5457 | kInitialMapChangedGroup, |
| 5458 | // Group of code that depends on tenuring information in AllocationSites |
| 5459 | // not being changed. |
| 5460 | kAllocationSiteTenuringChangedGroup, |
| 5461 | // Group of code that depends on element transition information in |
| 5462 | // AllocationSites not being changed. |
| 5463 | kAllocationSiteTransitionChangedGroup |
| 5464 | }; |
| 5465 | |
| 5466 | static const int kGroupCount = kAllocationSiteTransitionChangedGroup + 1; |
| 5467 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5468 | bool Contains(DependencyGroup group, WeakCell* code_cell); |
| 5469 | bool IsEmpty(DependencyGroup group); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5470 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5471 | static Handle<DependentCode> InsertCompilationDependencies( |
| 5472 | Handle<DependentCode> entries, DependencyGroup group, |
| 5473 | Handle<Foreign> info); |
| 5474 | |
| 5475 | static Handle<DependentCode> InsertWeakCode(Handle<DependentCode> entries, |
| 5476 | DependencyGroup group, |
| 5477 | Handle<WeakCell> code_cell); |
| 5478 | |
| 5479 | void UpdateToFinishedCode(DependencyGroup group, Foreign* info, |
| 5480 | WeakCell* code_cell); |
| 5481 | |
| 5482 | void RemoveCompilationDependencies(DependentCode::DependencyGroup group, |
| 5483 | Foreign* info); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5484 | |
| 5485 | void DeoptimizeDependentCodeGroup(Isolate* isolate, |
| 5486 | DependentCode::DependencyGroup group); |
| 5487 | |
| 5488 | bool MarkCodeForDeoptimization(Isolate* isolate, |
| 5489 | DependentCode::DependencyGroup group); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5490 | |
| 5491 | // The following low-level accessors should only be used by this class |
| 5492 | // and the mark compact collector. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5493 | inline DependentCode* next_link(); |
| 5494 | inline void set_next_link(DependentCode* next); |
| 5495 | inline int count(); |
| 5496 | inline void set_count(int value); |
| 5497 | inline DependencyGroup group(); |
| 5498 | inline void set_group(DependencyGroup group); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5499 | inline Object* object_at(int i); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5500 | inline void set_object_at(int i, Object* object); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5501 | inline void clear_at(int i); |
| 5502 | inline void copy(int from, int to); |
| 5503 | DECLARE_CAST(DependentCode) |
| 5504 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5505 | static const char* DependencyGroupName(DependencyGroup group); |
| 5506 | static void SetMarkedForDeoptimization(Code* code, DependencyGroup group); |
| 5507 | |
| 5508 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5509 | static Handle<DependentCode> Insert(Handle<DependentCode> entries, |
| 5510 | DependencyGroup group, |
| 5511 | Handle<Object> object); |
| 5512 | static Handle<DependentCode> New(DependencyGroup group, Handle<Object> object, |
| 5513 | Handle<DependentCode> next); |
| 5514 | static Handle<DependentCode> EnsureSpace(Handle<DependentCode> entries); |
| 5515 | // Compact by removing cleared weak cells and return true if there was |
| 5516 | // any cleared weak cell. |
| 5517 | bool Compact(); |
| 5518 | static int Grow(int number_of_entries) { |
| 5519 | if (number_of_entries < 5) return number_of_entries + 1; |
| 5520 | return number_of_entries * 5 / 4; |
| 5521 | } |
| 5522 | inline int flags(); |
| 5523 | inline void set_flags(int flags); |
| 5524 | class GroupField : public BitField<int, 0, 3> {}; |
| 5525 | class CountField : public BitField<int, 3, 27> {}; |
| 5526 | STATIC_ASSERT(kGroupCount <= GroupField::kMax + 1); |
| 5527 | static const int kNextLinkIndex = 0; |
| 5528 | static const int kFlagsIndex = 1; |
| 5529 | static const int kCodesStartIndex = 2; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5530 | }; |
| 5531 | |
| 5532 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5533 | class PrototypeInfo; |
| 5534 | |
| 5535 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5536 | // All heap objects have a Map that describes their structure. |
| 5537 | // A Map contains information about: |
| 5538 | // - Size information about the object |
| 5539 | // - How to iterate over an object (for garbage collection) |
| 5540 | class Map: public HeapObject { |
| 5541 | public: |
| 5542 | // Instance size. |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 5543 | // Size in bytes or kVariableSizeSentinel if instances do not have |
| 5544 | // a fixed size. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5545 | inline int instance_size(); |
| 5546 | inline void set_instance_size(int value); |
| 5547 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5548 | // Only to clear an unused byte, remove once byte is used. |
| 5549 | inline void clear_unused(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5550 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5551 | // [inobject_properties_or_constructor_function_index]: Provides access |
| 5552 | // to the inobject properties in case of JSObject maps, or the constructor |
| 5553 | // function index in case of primitive maps. |
| 5554 | inline int inobject_properties_or_constructor_function_index(); |
| 5555 | inline void set_inobject_properties_or_constructor_function_index(int value); |
| 5556 | // Count of properties allocated in the object (JSObject only). |
| 5557 | inline int GetInObjectProperties(); |
| 5558 | inline void SetInObjectProperties(int value); |
| 5559 | // Index of the constructor function in the native context (primitives only), |
| 5560 | // or the special sentinel value to indicate that there is no object wrapper |
| 5561 | // for the primitive (i.e. in case of null or undefined). |
| 5562 | static const int kNoConstructorFunctionIndex = 0; |
| 5563 | inline int GetConstructorFunctionIndex(); |
| 5564 | inline void SetConstructorFunctionIndex(int value); |
| 5565 | static MaybeHandle<JSFunction> GetConstructorFunction( |
| 5566 | Handle<Map> map, Handle<Context> native_context); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5567 | |
| 5568 | // Instance type. |
| 5569 | inline InstanceType instance_type(); |
| 5570 | inline void set_instance_type(InstanceType value); |
| 5571 | |
| 5572 | // Tells how many unused property fields are available in the |
| 5573 | // instance (only used for JSObject in fast mode). |
| 5574 | inline int unused_property_fields(); |
| 5575 | inline void set_unused_property_fields(int value); |
| 5576 | |
| 5577 | // Bit field. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5578 | inline byte bit_field() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5579 | inline void set_bit_field(byte value); |
| 5580 | |
| 5581 | // Bit field 2. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5582 | inline byte bit_field2() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5583 | inline void set_bit_field2(byte value); |
| 5584 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5585 | // Bit field 3. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5586 | inline uint32_t bit_field3() const; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5587 | inline void set_bit_field3(uint32_t bits); |
| 5588 | |
| 5589 | class EnumLengthBits: public BitField<int, |
| 5590 | 0, kDescriptorIndexBitCount> {}; // NOLINT |
| 5591 | class NumberOfOwnDescriptorsBits: public BitField<int, |
| 5592 | kDescriptorIndexBitCount, kDescriptorIndexBitCount> {}; // NOLINT |
| 5593 | STATIC_ASSERT(kDescriptorIndexBitCount + kDescriptorIndexBitCount == 20); |
| 5594 | class DictionaryMap : public BitField<bool, 20, 1> {}; |
| 5595 | class OwnsDescriptors : public BitField<bool, 21, 1> {}; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 5596 | class HasHiddenPrototype : public BitField<bool, 22, 1> {}; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5597 | class Deprecated : public BitField<bool, 23, 1> {}; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5598 | class IsUnstable : public BitField<bool, 24, 1> {}; |
| 5599 | class IsMigrationTarget : public BitField<bool, 25, 1> {}; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5600 | class IsStrong : public BitField<bool, 26, 1> {}; |
| 5601 | class NewTargetIsBase : public BitField<bool, 27, 1> {}; |
| 5602 | // Bit 28 is free. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5603 | |
| 5604 | // Keep this bit field at the very end for better code in |
| 5605 | // Builtins::kJSConstructStubGeneric stub. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5606 | // This counter is used for in-object slack tracking. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5607 | // The in-object slack tracking is considered enabled when the counter is |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 5608 | // non zero. The counter only has a valid count for initial maps. For |
| 5609 | // transitioned maps only kNoSlackTracking has a meaning, namely that inobject |
| 5610 | // slack tracking already finished for the transition tree. Any other value |
| 5611 | // indicates that either inobject slack tracking is still in progress, or that |
| 5612 | // the map isn't part of the transition tree anymore. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5613 | class ConstructionCounter : public BitField<int, 29, 3> {}; |
| 5614 | static const int kSlackTrackingCounterStart = 7; |
| 5615 | static const int kSlackTrackingCounterEnd = 1; |
| 5616 | static const int kNoSlackTracking = 0; |
| 5617 | STATIC_ASSERT(kSlackTrackingCounterStart <= ConstructionCounter::kMax); |
| 5618 | |
| 5619 | |
| 5620 | // Inobject slack tracking is the way to reclaim unused inobject space. |
| 5621 | // |
| 5622 | // The instance size is initially determined by adding some slack to |
| 5623 | // expected_nof_properties (to allow for a few extra properties added |
| 5624 | // after the constructor). There is no guarantee that the extra space |
| 5625 | // will not be wasted. |
| 5626 | // |
| 5627 | // Here is the algorithm to reclaim the unused inobject space: |
| 5628 | // - Detect the first constructor call for this JSFunction. |
| 5629 | // When it happens enter the "in progress" state: initialize construction |
| 5630 | // counter in the initial_map. |
| 5631 | // - While the tracking is in progress initialize unused properties of a new |
| 5632 | // object with one_pointer_filler_map instead of undefined_value (the "used" |
| 5633 | // part is initialized with undefined_value as usual). This way they can |
| 5634 | // be resized quickly and safely. |
| 5635 | // - Once enough objects have been created compute the 'slack' |
| 5636 | // (traverse the map transition tree starting from the |
| 5637 | // initial_map and find the lowest value of unused_property_fields). |
| 5638 | // - Traverse the transition tree again and decrease the instance size |
| 5639 | // of every map. Existing objects will resize automatically (they are |
| 5640 | // filled with one_pointer_filler_map). All further allocations will |
| 5641 | // use the adjusted instance size. |
| 5642 | // - SharedFunctionInfo's expected_nof_properties left unmodified since |
| 5643 | // allocations made using different closures could actually create different |
| 5644 | // kind of objects (see prototype inheritance pattern). |
| 5645 | // |
| 5646 | // Important: inobject slack tracking is not attempted during the snapshot |
| 5647 | // creation. |
| 5648 | |
| 5649 | static const int kGenerousAllocationCount = |
| 5650 | kSlackTrackingCounterStart - kSlackTrackingCounterEnd + 1; |
| 5651 | |
| 5652 | // Starts the tracking by initializing object constructions countdown counter. |
| 5653 | void StartInobjectSlackTracking(); |
| 5654 | |
| 5655 | // True if the object constructions countdown counter is a range |
| 5656 | // [kSlackTrackingCounterEnd, kSlackTrackingCounterStart]. |
| 5657 | inline bool IsInobjectSlackTrackingInProgress(); |
| 5658 | |
| 5659 | // Does the tracking step. |
| 5660 | inline void InobjectSlackTrackingStep(); |
| 5661 | |
| 5662 | // Completes inobject slack tracking for the transition tree starting at this |
| 5663 | // initial map. |
| 5664 | void CompleteInobjectSlackTracking(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5665 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5666 | // Tells whether the object in the prototype property will be used |
| 5667 | // for instances created from this function. If the prototype |
| 5668 | // property is set to a value that is not a JSObject, the prototype |
| 5669 | // property will not be used to create instances of the function. |
| 5670 | // See ECMA-262, 13.2.2. |
| 5671 | inline void set_non_instance_prototype(bool value); |
| 5672 | inline bool has_non_instance_prototype(); |
| 5673 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5674 | // Tells whether the instance has a [[Construct]] internal method. |
| 5675 | // This property is implemented according to ES6, section 7.2.4. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 5676 | inline void set_is_constructor(bool value); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5677 | inline bool is_constructor() const; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5678 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 5679 | // Tells whether the instance with this map has a hidden prototype. |
| 5680 | inline void set_has_hidden_prototype(bool value); |
| 5681 | inline bool has_hidden_prototype() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5682 | |
| 5683 | // Records and queries whether the instance has a named interceptor. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5684 | inline void set_has_named_interceptor(); |
| 5685 | inline bool has_named_interceptor(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5686 | |
| 5687 | // Records and queries whether the instance has an indexed interceptor. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5688 | inline void set_has_indexed_interceptor(); |
| 5689 | inline bool has_indexed_interceptor(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5690 | |
| 5691 | // Tells whether the instance is undetectable. |
| 5692 | // An undetectable object is a special class of JSObject: 'typeof' operator |
| 5693 | // returns undefined, ToBoolean returns false. Otherwise it behaves like |
| 5694 | // a normal JS object. It is useful for implementing undetectable |
| 5695 | // document.all in Firefox & Safari. |
| 5696 | // See https://bugzilla.mozilla.org/show_bug.cgi?id=248549. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5697 | inline void set_is_undetectable(); |
| 5698 | inline bool is_undetectable(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5699 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5700 | // Tells whether the instance has a call-as-function handler. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5701 | inline void set_is_observed(); |
| 5702 | inline bool is_observed(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5703 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5704 | // Tells whether the instance has a [[Call]] internal method. |
| 5705 | // This property is implemented according to ES6, section 7.2.3. |
| 5706 | inline void set_is_callable(); |
| 5707 | inline bool is_callable() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5708 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5709 | inline void set_is_strong(); |
| 5710 | inline bool is_strong(); |
| 5711 | inline void set_new_target_is_base(bool value); |
| 5712 | inline bool new_target_is_base(); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 5713 | inline void set_is_extensible(bool value); |
| 5714 | inline bool is_extensible(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5715 | inline void set_is_prototype_map(bool value); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5716 | inline bool is_prototype_map() const; |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 5717 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5718 | inline void set_elements_kind(ElementsKind elements_kind); |
| 5719 | inline ElementsKind elements_kind(); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 5720 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5721 | // Tells whether the instance has fast elements that are only Smis. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5722 | inline bool has_fast_smi_elements(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5723 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 5724 | // Tells whether the instance has fast elements. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5725 | inline bool has_fast_object_elements(); |
| 5726 | inline bool has_fast_smi_or_object_elements(); |
| 5727 | inline bool has_fast_double_elements(); |
| 5728 | inline bool has_fast_elements(); |
| 5729 | inline bool has_sloppy_arguments_elements(); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 5730 | inline bool has_fast_string_wrapper_elements(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5731 | inline bool has_fixed_typed_array_elements(); |
| 5732 | inline bool has_dictionary_elements(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5733 | |
| 5734 | static bool IsValidElementsTransition(ElementsKind from_kind, |
| 5735 | ElementsKind to_kind); |
| 5736 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5737 | // Returns true if the current map doesn't have DICTIONARY_ELEMENTS but if a |
| 5738 | // map with DICTIONARY_ELEMENTS was found in the prototype chain. |
| 5739 | bool DictionaryElementsInPrototypeChainOnly(); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5740 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5741 | inline Map* ElementsTransitionMap(); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5742 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5743 | inline FixedArrayBase* GetInitialElements(); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5744 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5745 | // [raw_transitions]: Provides access to the transitions storage field. |
| 5746 | // Don't call set_raw_transitions() directly to overwrite transitions, use |
| 5747 | // the TransitionArray::ReplaceTransitions() wrapper instead! |
| 5748 | DECL_ACCESSORS(raw_transitions, Object) |
| 5749 | // [prototype_info]: Per-prototype metadata. Aliased with transitions |
| 5750 | // (which prototype maps don't have). |
| 5751 | DECL_ACCESSORS(prototype_info, Object) |
| 5752 | // PrototypeInfo is created lazily using this helper (which installs it on |
| 5753 | // the given prototype's map). |
| 5754 | static Handle<PrototypeInfo> GetOrCreatePrototypeInfo( |
| 5755 | Handle<JSObject> prototype, Isolate* isolate); |
| 5756 | static Handle<PrototypeInfo> GetOrCreatePrototypeInfo( |
| 5757 | Handle<Map> prototype_map, Isolate* isolate); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5758 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5759 | // [prototype chain validity cell]: Associated with a prototype object, |
| 5760 | // stored in that object's map's PrototypeInfo, indicates that prototype |
| 5761 | // chains through this object are currently valid. The cell will be |
| 5762 | // invalidated and replaced when the prototype chain changes. |
| 5763 | static Handle<Cell> GetOrCreatePrototypeChainValidityCell(Handle<Map> map, |
| 5764 | Isolate* isolate); |
| 5765 | static const int kPrototypeChainValid = 0; |
| 5766 | static const int kPrototypeChainInvalid = 1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5767 | |
| 5768 | Map* FindRootMap(); |
| 5769 | Map* FindFieldOwner(int descriptor); |
| 5770 | |
| 5771 | inline int GetInObjectPropertyOffset(int index); |
| 5772 | |
| 5773 | int NumberOfFields(); |
| 5774 | |
| 5775 | // TODO(ishell): candidate with JSObject::MigrateToMap(). |
| 5776 | bool InstancesNeedRewriting(Map* target, int target_number_of_fields, |
| 5777 | int target_inobject, int target_unused, |
| 5778 | int* old_number_of_fields); |
| 5779 | // TODO(ishell): moveit! |
| 5780 | static Handle<Map> GeneralizeAllFieldRepresentations(Handle<Map> map); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 5781 | MUST_USE_RESULT static Handle<FieldType> GeneralizeFieldType( |
| 5782 | Representation rep1, Handle<FieldType> type1, Representation rep2, |
| 5783 | Handle<FieldType> type2, Isolate* isolate); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5784 | static void GeneralizeFieldType(Handle<Map> map, int modify_index, |
| 5785 | Representation new_representation, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 5786 | Handle<FieldType> new_field_type); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5787 | static Handle<Map> ReconfigureProperty(Handle<Map> map, int modify_index, |
| 5788 | PropertyKind new_kind, |
| 5789 | PropertyAttributes new_attributes, |
| 5790 | Representation new_representation, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 5791 | Handle<FieldType> new_field_type, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5792 | StoreMode store_mode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5793 | static Handle<Map> CopyGeneralizeAllRepresentations( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5794 | Handle<Map> map, int modify_index, StoreMode store_mode, |
| 5795 | PropertyKind kind, PropertyAttributes attributes, const char* reason); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5796 | |
| 5797 | static Handle<Map> PrepareForDataProperty(Handle<Map> old_map, |
| 5798 | int descriptor_number, |
| 5799 | Handle<Object> value); |
| 5800 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5801 | static Handle<Map> Normalize(Handle<Map> map, PropertyNormalizationMode mode, |
| 5802 | const char* reason); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5803 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5804 | // Tells whether the map is used for JSObjects in dictionary mode (ie |
| 5805 | // normalized objects, ie objects for which HasFastProperties returns false). |
| 5806 | // A map can never be used for both dictionary mode and fast mode JSObjects. |
| 5807 | // False by default and for HeapObjects that are not JSObjects. |
| 5808 | inline void set_dictionary_map(bool value); |
| 5809 | inline bool is_dictionary_map(); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5810 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5811 | // Tells whether the instance needs security checks when accessing its |
| 5812 | // properties. |
| 5813 | inline void set_is_access_check_needed(bool access_check_needed); |
| 5814 | inline bool is_access_check_needed(); |
| 5815 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5816 | // Returns true if map has a non-empty stub code cache. |
| 5817 | inline bool has_code_cache(); |
| 5818 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5819 | // [prototype]: implicit prototype object. |
| 5820 | DECL_ACCESSORS(prototype, Object) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5821 | // TODO(jkummerow): make set_prototype private. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5822 | static void SetPrototype( |
| 5823 | Handle<Map> map, Handle<Object> prototype, |
| 5824 | PrototypeOptimizationMode proto_mode = FAST_PROTOTYPE); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5825 | |
| 5826 | // [constructor]: points back to the function responsible for this map. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5827 | // The field overlaps with the back pointer. All maps in a transition tree |
| 5828 | // have the same constructor, so maps with back pointers can walk the |
| 5829 | // back pointer chain until they find the map holding their constructor. |
| 5830 | DECL_ACCESSORS(constructor_or_backpointer, Object) |
| 5831 | inline Object* GetConstructor() const; |
| 5832 | inline void SetConstructor(Object* constructor, |
| 5833 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| 5834 | // [back pointer]: points back to the parent map from which a transition |
| 5835 | // leads to this map. The field overlaps with the constructor (see above). |
| 5836 | inline Object* GetBackPointer(); |
| 5837 | inline void SetBackPointer(Object* value, |
| 5838 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5839 | |
| 5840 | // [instance descriptors]: describes the object. |
| 5841 | DECL_ACCESSORS(instance_descriptors, DescriptorArray) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5842 | |
| 5843 | // [layout descriptor]: describes the object layout. |
| 5844 | DECL_ACCESSORS(layout_descriptor, LayoutDescriptor) |
| 5845 | // |layout descriptor| accessor which can be used from GC. |
| 5846 | inline LayoutDescriptor* layout_descriptor_gc_safe(); |
| 5847 | inline bool HasFastPointerLayout() const; |
| 5848 | |
| 5849 | // |layout descriptor| accessor that is safe to call even when |
| 5850 | // FLAG_unbox_double_fields is disabled (in this case Map does not contain |
| 5851 | // |layout_descriptor| field at all). |
| 5852 | inline LayoutDescriptor* GetLayoutDescriptor(); |
| 5853 | |
| 5854 | inline void UpdateDescriptors(DescriptorArray* descriptors, |
| 5855 | LayoutDescriptor* layout_descriptor); |
| 5856 | inline void InitializeDescriptors(DescriptorArray* descriptors, |
| 5857 | LayoutDescriptor* layout_descriptor); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5858 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5859 | // [stub cache]: contains stubs compiled for this map. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5860 | DECL_ACCESSORS(code_cache, Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5861 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5862 | // [dependent code]: list of optimized codes that weakly embed this map. |
| 5863 | DECL_ACCESSORS(dependent_code, DependentCode) |
| 5864 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5865 | // [weak cell cache]: cache that stores a weak cell pointing to this map. |
| 5866 | DECL_ACCESSORS(weak_cell_cache, Object) |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5867 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5868 | inline PropertyDetails GetLastDescriptorDetails(); |
| 5869 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5870 | inline int LastAdded(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5871 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5872 | inline int NumberOfOwnDescriptors(); |
| 5873 | inline void SetNumberOfOwnDescriptors(int number); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5874 | |
| 5875 | inline Cell* RetrieveDescriptorsPointer(); |
| 5876 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 5877 | // Checks whether all properties are stored either in the map or on the object |
| 5878 | // (inobject, properties, or elements backing store), requiring no special |
| 5879 | // checks. |
| 5880 | bool OnlyHasSimpleProperties(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5881 | inline int EnumLength(); |
| 5882 | inline void SetEnumLength(int length); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5883 | |
| 5884 | inline bool owns_descriptors(); |
| 5885 | inline void set_owns_descriptors(bool owns_descriptors); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5886 | inline void mark_unstable(); |
| 5887 | inline bool is_stable(); |
| 5888 | inline void set_migration_target(bool value); |
| 5889 | inline bool is_migration_target(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5890 | inline void set_construction_counter(int value); |
| 5891 | inline int construction_counter(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5892 | inline void deprecate(); |
| 5893 | inline bool is_deprecated(); |
| 5894 | inline bool CanBeDeprecated(); |
| 5895 | // Returns a non-deprecated version of the input. If the input was not |
| 5896 | // deprecated, it is directly returned. Otherwise, the non-deprecated version |
| 5897 | // 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] | 5898 | // descriptor array of the map. Returns MaybeHandle<Map>() if no updated map |
| 5899 | // is found. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5900 | static MaybeHandle<Map> TryUpdate(Handle<Map> map) WARN_UNUSED_RESULT; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5901 | |
| 5902 | // Returns a non-deprecated version of the input. This method may deprecate |
| 5903 | // existing maps along the way if encodings conflict. Not for use while |
| 5904 | // gathering type feedback. Use TryUpdate in those cases instead. |
| 5905 | static Handle<Map> Update(Handle<Map> map); |
| 5906 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5907 | static inline Handle<Map> CopyInitialMap(Handle<Map> map); |
| 5908 | static Handle<Map> CopyInitialMap(Handle<Map> map, int instance_size, |
| 5909 | int in_object_properties, |
| 5910 | int unused_property_fields); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5911 | static Handle<Map> CopyDropDescriptors(Handle<Map> map); |
| 5912 | static Handle<Map> CopyInsertDescriptor(Handle<Map> map, |
| 5913 | Descriptor* descriptor, |
| 5914 | TransitionFlag flag); |
| 5915 | |
| 5916 | MUST_USE_RESULT static MaybeHandle<Map> CopyWithField( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 5917 | Handle<Map> map, Handle<Name> name, Handle<FieldType> type, |
| 5918 | PropertyAttributes attributes, Representation representation, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5919 | TransitionFlag flag); |
| 5920 | |
| 5921 | MUST_USE_RESULT static MaybeHandle<Map> CopyWithConstant( |
| 5922 | Handle<Map> map, |
| 5923 | Handle<Name> name, |
| 5924 | Handle<Object> constant, |
| 5925 | PropertyAttributes attributes, |
| 5926 | TransitionFlag flag); |
| 5927 | |
| 5928 | // Returns a new map with all transitions dropped from the given map and |
| 5929 | // the ElementsKind set. |
| 5930 | static Handle<Map> TransitionElementsTo(Handle<Map> map, |
| 5931 | ElementsKind to_kind); |
| 5932 | |
| 5933 | static Handle<Map> AsElementsKind(Handle<Map> map, ElementsKind kind); |
| 5934 | |
| 5935 | static Handle<Map> CopyAsElementsKind(Handle<Map> map, |
| 5936 | ElementsKind kind, |
| 5937 | TransitionFlag flag); |
| 5938 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5939 | static Handle<Map> AsLanguageMode(Handle<Map> initial_map, |
| 5940 | LanguageMode language_mode, |
| 5941 | FunctionKind kind); |
| 5942 | |
| 5943 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5944 | static Handle<Map> CopyForObserved(Handle<Map> map); |
| 5945 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5946 | static Handle<Map> CopyForPreventExtensions(Handle<Map> map, |
| 5947 | PropertyAttributes attrs_to_add, |
| 5948 | Handle<Symbol> transition_marker, |
| 5949 | const char* reason); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5950 | |
| 5951 | static Handle<Map> FixProxy(Handle<Map> map, InstanceType type, int size); |
| 5952 | |
| 5953 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5954 | // Maximal number of fast properties. Used to restrict the number of map |
| 5955 | // transitions to avoid an explosion in the number of maps for objects used as |
| 5956 | // dictionaries. |
| 5957 | inline bool TooManyFastProperties(StoreFromKeyed store_mode); |
| 5958 | static Handle<Map> TransitionToDataProperty(Handle<Map> map, |
| 5959 | Handle<Name> name, |
| 5960 | Handle<Object> value, |
| 5961 | PropertyAttributes attributes, |
| 5962 | StoreFromKeyed store_mode); |
| 5963 | static Handle<Map> TransitionToAccessorProperty( |
| 5964 | Handle<Map> map, Handle<Name> name, AccessorComponent component, |
| 5965 | Handle<Object> accessor, PropertyAttributes attributes); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5966 | static Handle<Map> ReconfigureExistingProperty(Handle<Map> map, |
| 5967 | int descriptor, |
| 5968 | PropertyKind kind, |
| 5969 | PropertyAttributes attributes); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5970 | |
| 5971 | inline void AppendDescriptor(Descriptor* desc); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5972 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5973 | // Returns a copy of the map, prepared for inserting into the transition |
| 5974 | // tree (if the |map| owns descriptors then the new one will share |
| 5975 | // descriptors with |map|). |
| 5976 | static Handle<Map> CopyForTransition(Handle<Map> map, const char* reason); |
| 5977 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5978 | // Returns a copy of the map, with all transitions dropped from the |
| 5979 | // instance descriptors. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5980 | static Handle<Map> Copy(Handle<Map> map, const char* reason); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5981 | static Handle<Map> Create(Isolate* isolate, int inobject_properties); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5982 | |
| 5983 | // Returns the next free property index (only valid for FAST MODE). |
| 5984 | int NextFreePropertyIndex(); |
| 5985 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5986 | // Returns the number of properties described in instance_descriptors |
| 5987 | // filtering out properties with the specified attributes. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5988 | int NumberOfDescribedProperties(DescriptorFlag which = OWN_DESCRIPTORS, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5989 | PropertyFilter filter = ALL_PROPERTIES); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5990 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5991 | DECLARE_CAST(Map) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5992 | |
| 5993 | // Code cache operations. |
| 5994 | |
| 5995 | // Clears the code cache. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 5996 | inline void ClearCodeCache(Heap* heap); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5997 | |
| 5998 | // Update code cache. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5999 | static void UpdateCodeCache(Handle<Map> map, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6000 | Handle<Name> name, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 6001 | Handle<Code> code); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6002 | |
| 6003 | // Extend the descriptor array of the map with the list of descriptors. |
| 6004 | // In case of duplicates, the latest descriptor is used. |
| 6005 | static void AppendCallbackDescriptors(Handle<Map> map, |
| 6006 | Handle<Object> descriptors); |
| 6007 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6008 | static inline int SlackForArraySize(int old_size, int size_limit); |
| 6009 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6010 | static void EnsureDescriptorSlack(Handle<Map> map, int slack); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6011 | |
| 6012 | // Returns the found code or undefined if absent. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6013 | Object* FindInCodeCache(Name* name, Code::Flags flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6014 | |
| 6015 | // Returns the non-negative index of the code object if it is in the |
| 6016 | // cache and -1 otherwise. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 6017 | int IndexInCodeCache(Object* name, Code* code); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6018 | |
| 6019 | // Removes a code object from the code cache at the given index. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6020 | void RemoveFromCodeCache(Name* name, Code* code, int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6021 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6022 | // Computes a hash value for this map, to be used in HashTables and such. |
| 6023 | int Hash(); |
| 6024 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 6025 | // Returns the map that this map transitions to if its elements_kind |
| 6026 | // is changed to |elements_kind|, or NULL if no such map is cached yet. |
| 6027 | // |safe_to_add_transitions| is set to false if adding transitions is not |
| 6028 | // allowed. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6029 | Map* LookupElementsTransitionMap(ElementsKind elements_kind); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 6030 | |
| 6031 | // Returns the transitioned map for this map with the most generic |
| 6032 | // elements_kind that's found in |candidates|, or null handle if no match is |
| 6033 | // found at all. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6034 | static Handle<Map> FindTransitionedMap(Handle<Map> map, |
| 6035 | MapHandleList* candidates); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 6036 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6037 | inline bool CanTransition(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6038 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6039 | inline bool IsBooleanMap(); |
| 6040 | inline bool IsPrimitiveMap(); |
| 6041 | inline bool IsJSReceiverMap(); |
| 6042 | inline bool IsJSObjectMap(); |
| 6043 | inline bool IsJSArrayMap(); |
| 6044 | inline bool IsJSFunctionMap(); |
| 6045 | inline bool IsStringMap(); |
| 6046 | inline bool IsJSProxyMap(); |
| 6047 | inline bool IsJSGlobalProxyMap(); |
| 6048 | inline bool IsJSGlobalObjectMap(); |
| 6049 | inline bool IsJSTypedArrayMap(); |
| 6050 | inline bool IsJSDataViewMap(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6051 | |
| 6052 | inline bool CanOmitMapChecks(); |
| 6053 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6054 | static void AddDependentCode(Handle<Map> map, |
| 6055 | DependentCode::DependencyGroup group, |
| 6056 | Handle<Code> code); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6057 | |
| 6058 | bool IsMapInArrayPrototypeChain(); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 6059 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6060 | static Handle<WeakCell> WeakCellForMap(Handle<Map> map); |
| 6061 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6062 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6063 | DECLARE_PRINTER(Map) |
| 6064 | DECLARE_VERIFIER(Map) |
| 6065 | |
| 6066 | #ifdef VERIFY_HEAP |
| 6067 | void DictionaryMapVerify(); |
| 6068 | void VerifyOmittedMapChecks(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6069 | #endif |
| 6070 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 6071 | inline int visitor_id(); |
| 6072 | inline void set_visitor_id(int visitor_id); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 6073 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6074 | static Handle<Map> TransitionToPrototype(Handle<Map> map, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6075 | Handle<Object> prototype, |
| 6076 | PrototypeOptimizationMode mode); |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 6077 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6078 | static const int kMaxPreAllocatedPropertyFields = 255; |
| 6079 | |
| 6080 | // Layout description. |
| 6081 | static const int kInstanceSizesOffset = HeapObject::kHeaderSize; |
| 6082 | static const int kInstanceAttributesOffset = kInstanceSizesOffset + kIntSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6083 | static const int kBitField3Offset = kInstanceAttributesOffset + kIntSize; |
| 6084 | static const int kPrototypeOffset = kBitField3Offset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6085 | static const int kConstructorOrBackPointerOffset = |
| 6086 | kPrototypeOffset + kPointerSize; |
| 6087 | // When there is only one transition, it is stored directly in this field; |
| 6088 | // otherwise a transition array is used. |
| 6089 | // For prototype maps, this slot is used to store this map's PrototypeInfo |
| 6090 | // struct. |
| 6091 | static const int kTransitionsOrPrototypeInfoOffset = |
| 6092 | kConstructorOrBackPointerOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6093 | static const int kDescriptorsOffset = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6094 | kTransitionsOrPrototypeInfoOffset + kPointerSize; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6095 | #if V8_DOUBLE_FIELDS_UNBOXING |
| 6096 | static const int kLayoutDecriptorOffset = kDescriptorsOffset + kPointerSize; |
| 6097 | static const int kCodeCacheOffset = kLayoutDecriptorOffset + kPointerSize; |
| 6098 | #else |
| 6099 | static const int kLayoutDecriptorOffset = 1; // Must not be ever accessed. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6100 | static const int kCodeCacheOffset = kDescriptorsOffset + kPointerSize; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6101 | #endif |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6102 | static const int kDependentCodeOffset = kCodeCacheOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6103 | static const int kWeakCellCacheOffset = kDependentCodeOffset + kPointerSize; |
| 6104 | static const int kSize = kWeakCellCacheOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 6105 | |
| 6106 | // Layout of pointer fields. Heap iteration code relies on them |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 6107 | // being continuously allocated. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 6108 | static const int kPointerFieldsBeginOffset = Map::kPrototypeOffset; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6109 | static const int kPointerFieldsEndOffset = kSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6110 | |
| 6111 | // Byte offsets within kInstanceSizesOffset. |
| 6112 | static const int kInstanceSizeOffset = kInstanceSizesOffset + 0; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6113 | static const int kInObjectPropertiesOrConstructorFunctionIndexByte = 1; |
| 6114 | static const int kInObjectPropertiesOrConstructorFunctionIndexOffset = |
| 6115 | kInstanceSizesOffset + kInObjectPropertiesOrConstructorFunctionIndexByte; |
| 6116 | // Note there is one byte available for use here. |
| 6117 | static const int kUnusedByte = 2; |
| 6118 | static const int kUnusedOffset = kInstanceSizesOffset + kUnusedByte; |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 6119 | static const int kVisitorIdByte = 3; |
| 6120 | static const int kVisitorIdOffset = kInstanceSizesOffset + kVisitorIdByte; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6121 | |
| 6122 | // Byte offsets within kInstanceAttributesOffset attributes. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6123 | #if V8_TARGET_LITTLE_ENDIAN |
| 6124 | // Order instance type and bit field together such that they can be loaded |
| 6125 | // together as a 16-bit word with instance type in the lower 8 bits regardless |
| 6126 | // of endianess. Also provide endian-independent offset to that 16-bit word. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6127 | static const int kInstanceTypeOffset = kInstanceAttributesOffset + 0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6128 | static const int kBitFieldOffset = kInstanceAttributesOffset + 1; |
| 6129 | #else |
| 6130 | static const int kBitFieldOffset = kInstanceAttributesOffset + 0; |
| 6131 | static const int kInstanceTypeOffset = kInstanceAttributesOffset + 1; |
| 6132 | #endif |
| 6133 | static const int kInstanceTypeAndBitFieldOffset = |
| 6134 | kInstanceAttributesOffset + 0; |
| 6135 | static const int kBitField2Offset = kInstanceAttributesOffset + 2; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6136 | static const int kUnusedPropertyFieldsByte = 3; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6137 | static const int kUnusedPropertyFieldsOffset = kInstanceAttributesOffset + 3; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6138 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6139 | STATIC_ASSERT(kInstanceTypeAndBitFieldOffset == |
| 6140 | Internals::kMapInstanceTypeAndBitFieldOffset); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6141 | |
| 6142 | // Bit positions for bit field. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6143 | static const int kHasNonInstancePrototype = 0; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6144 | static const int kIsCallable = 1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6145 | static const int kHasNamedInterceptor = 2; |
| 6146 | static const int kHasIndexedInterceptor = 3; |
| 6147 | static const int kIsUndetectable = 4; |
| 6148 | static const int kIsObserved = 5; |
| 6149 | static const int kIsAccessCheckNeeded = 6; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6150 | static const int kIsConstructor = 7; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6151 | |
| 6152 | // Bit positions for bit field 2 |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 6153 | static const int kIsExtensible = 0; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6154 | // Bit 1 is free. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6155 | class IsPrototypeMapBits : public BitField<bool, 2, 1> {}; |
| 6156 | class ElementsKindBits: public BitField<ElementsKind, 3, 5> {}; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6157 | |
| 6158 | // Derived values from bit field 2 |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6159 | static const int8_t kMaximumBitField2FastElementValue = static_cast<int8_t>( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6160 | (FAST_ELEMENTS + 1) << Map::ElementsKindBits::kShift) - 1; |
| 6161 | static const int8_t kMaximumBitField2FastSmiElementValue = |
| 6162 | static_cast<int8_t>((FAST_SMI_ELEMENTS + 1) << |
| 6163 | Map::ElementsKindBits::kShift) - 1; |
| 6164 | static const int8_t kMaximumBitField2FastHoleyElementValue = |
| 6165 | static_cast<int8_t>((FAST_HOLEY_ELEMENTS + 1) << |
| 6166 | Map::ElementsKindBits::kShift) - 1; |
| 6167 | static const int8_t kMaximumBitField2FastHoleySmiElementValue = |
| 6168 | static_cast<int8_t>((FAST_HOLEY_SMI_ELEMENTS + 1) << |
| 6169 | Map::ElementsKindBits::kShift) - 1; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6170 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 6171 | typedef FixedBodyDescriptor<kPointerFieldsBeginOffset, |
| 6172 | kPointerFieldsEndOffset, |
| 6173 | kSize> BodyDescriptor; |
| 6174 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6175 | // Compares this map to another to see if they describe equivalent objects. |
| 6176 | // If |mode| is set to CLEAR_INOBJECT_PROPERTIES, |other| is treated as if |
| 6177 | // it had exactly zero inobject properties. |
| 6178 | // The "shared" flags of both this map and |other| are ignored. |
| 6179 | bool EquivalentToForNormalization(Map* other, PropertyNormalizationMode mode); |
| 6180 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6181 | // Returns true if given field is unboxed double. |
| 6182 | inline bool IsUnboxedDoubleField(FieldIndex index); |
| 6183 | |
| 6184 | #if TRACE_MAPS |
| 6185 | static void TraceTransition(const char* what, Map* from, Map* to, Name* name); |
| 6186 | static void TraceAllTransitions(Map* map); |
| 6187 | #endif |
| 6188 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6189 | static inline Handle<Map> AddMissingTransitionsForTesting( |
| 6190 | Handle<Map> split_map, Handle<DescriptorArray> descriptors, |
| 6191 | Handle<LayoutDescriptor> full_layout_descriptor); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6192 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6193 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6194 | static void ConnectTransition(Handle<Map> parent, Handle<Map> child, |
| 6195 | Handle<Name> name, SimpleTransitionFlag flag); |
| 6196 | |
| 6197 | bool EquivalentToForTransition(Map* other); |
| 6198 | static Handle<Map> RawCopy(Handle<Map> map, int instance_size); |
| 6199 | static Handle<Map> ShareDescriptor(Handle<Map> map, |
| 6200 | Handle<DescriptorArray> descriptors, |
| 6201 | Descriptor* descriptor); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6202 | static Handle<Map> AddMissingTransitions( |
| 6203 | Handle<Map> map, Handle<DescriptorArray> descriptors, |
| 6204 | Handle<LayoutDescriptor> full_layout_descriptor); |
| 6205 | static void InstallDescriptors( |
| 6206 | Handle<Map> parent_map, Handle<Map> child_map, int new_descriptor, |
| 6207 | Handle<DescriptorArray> descriptors, |
| 6208 | Handle<LayoutDescriptor> full_layout_descriptor); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6209 | static Handle<Map> CopyAddDescriptor(Handle<Map> map, |
| 6210 | Descriptor* descriptor, |
| 6211 | TransitionFlag flag); |
| 6212 | static Handle<Map> CopyReplaceDescriptors( |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6213 | Handle<Map> map, Handle<DescriptorArray> descriptors, |
| 6214 | Handle<LayoutDescriptor> layout_descriptor, TransitionFlag flag, |
| 6215 | MaybeHandle<Name> maybe_name, const char* reason, |
| 6216 | SimpleTransitionFlag simple_flag); |
| 6217 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6218 | static Handle<Map> CopyReplaceDescriptor(Handle<Map> map, |
| 6219 | Handle<DescriptorArray> descriptors, |
| 6220 | Descriptor* descriptor, |
| 6221 | int index, |
| 6222 | TransitionFlag flag); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6223 | static MUST_USE_RESULT MaybeHandle<Map> TryReconfigureExistingProperty( |
| 6224 | Handle<Map> map, int descriptor, PropertyKind kind, |
| 6225 | PropertyAttributes attributes, const char** reason); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6226 | |
| 6227 | static Handle<Map> CopyNormalized(Handle<Map> map, |
| 6228 | PropertyNormalizationMode mode); |
| 6229 | |
| 6230 | // Fires when the layout of an object with a leaf map changes. |
| 6231 | // This includes adding transitions to the leaf map or changing |
| 6232 | // the descriptor array. |
| 6233 | inline void NotifyLeafMapLayoutChange(); |
| 6234 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6235 | void DeprecateTransitionTree(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6236 | |
| 6237 | void ReplaceDescriptors(DescriptorArray* new_descriptors, |
| 6238 | LayoutDescriptor* new_layout_descriptor); |
| 6239 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6240 | |
| 6241 | Map* FindLastMatchMap(int verbatim, int length, DescriptorArray* descriptors); |
| 6242 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6243 | // Update field type of the given descriptor to new representation and new |
| 6244 | // type. The type must be prepared for storing in descriptor array: |
| 6245 | // 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] | 6246 | void UpdateFieldType(int descriptor_number, Handle<Name> name, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6247 | Representation new_representation, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6248 | Handle<Object> new_wrapped_type); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6249 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6250 | void PrintReconfiguration(FILE* file, int modify_index, PropertyKind kind, |
| 6251 | PropertyAttributes attributes); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 6252 | void PrintGeneralization(FILE* file, const char* reason, int modify_index, |
| 6253 | int split, int descriptors, bool constant_to_field, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6254 | Representation old_representation, |
| 6255 | Representation new_representation, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 6256 | MaybeHandle<FieldType> old_field_type, |
| 6257 | MaybeHandle<Object> old_value, |
| 6258 | MaybeHandle<FieldType> new_field_type, |
| 6259 | MaybeHandle<Object> new_value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6260 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6261 | static const int kFastPropertiesSoftLimit = 12; |
| 6262 | static const int kMaxFastProperties = 128; |
| 6263 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6264 | DISALLOW_IMPLICIT_CONSTRUCTORS(Map); |
| 6265 | }; |
| 6266 | |
| 6267 | |
| 6268 | // An abstract superclass, a marker class really, for simple structure classes. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6269 | // It doesn't carry much functionality but allows struct classes to be |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6270 | // identified in the type system. |
| 6271 | class Struct: public HeapObject { |
| 6272 | public: |
| 6273 | inline void InitializeBody(int object_size); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6274 | DECLARE_CAST(Struct) |
| 6275 | }; |
| 6276 | |
| 6277 | |
| 6278 | // A simple one-element struct, useful where smis need to be boxed. |
| 6279 | class Box : public Struct { |
| 6280 | public: |
| 6281 | // [value]: the boxed contents. |
| 6282 | DECL_ACCESSORS(value, Object) |
| 6283 | |
| 6284 | DECLARE_CAST(Box) |
| 6285 | |
| 6286 | // Dispatched behavior. |
| 6287 | DECLARE_PRINTER(Box) |
| 6288 | DECLARE_VERIFIER(Box) |
| 6289 | |
| 6290 | static const int kValueOffset = HeapObject::kHeaderSize; |
| 6291 | static const int kSize = kValueOffset + kPointerSize; |
| 6292 | |
| 6293 | private: |
| 6294 | DISALLOW_IMPLICIT_CONSTRUCTORS(Box); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6295 | }; |
| 6296 | |
| 6297 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6298 | // Container for metadata stored on each prototype map. |
| 6299 | class PrototypeInfo : public Struct { |
| 6300 | public: |
| 6301 | static const int UNREGISTERED = -1; |
| 6302 | |
| 6303 | // [prototype_users]: WeakFixedArray containing maps using this prototype, |
| 6304 | // or Smi(0) if uninitialized. |
| 6305 | DECL_ACCESSORS(prototype_users, Object) |
| 6306 | // [registry_slot]: Slot in prototype's user registry where this user |
| 6307 | // is stored. Returns UNREGISTERED if this prototype has not been registered. |
| 6308 | inline int registry_slot() const; |
| 6309 | inline void set_registry_slot(int slot); |
| 6310 | // [validity_cell]: Cell containing the validity bit for prototype chains |
| 6311 | // going through this object, or Smi(0) if uninitialized. |
| 6312 | // When a prototype object changes its map, then both its own validity cell |
| 6313 | // and those of all "downstream" prototypes are invalidated; handlers for a |
| 6314 | // given receiver embed the currently valid cell for that receiver's prototype |
| 6315 | // during their compilation and check it on execution. |
| 6316 | DECL_ACCESSORS(validity_cell, Object) |
| 6317 | |
| 6318 | DECLARE_CAST(PrototypeInfo) |
| 6319 | |
| 6320 | // Dispatched behavior. |
| 6321 | DECLARE_PRINTER(PrototypeInfo) |
| 6322 | DECLARE_VERIFIER(PrototypeInfo) |
| 6323 | |
| 6324 | static const int kPrototypeUsersOffset = HeapObject::kHeaderSize; |
| 6325 | static const int kRegistrySlotOffset = kPrototypeUsersOffset + kPointerSize; |
| 6326 | static const int kValidityCellOffset = kRegistrySlotOffset + kPointerSize; |
| 6327 | static const int kConstructorNameOffset = kValidityCellOffset + kPointerSize; |
| 6328 | static const int kSize = kConstructorNameOffset + kPointerSize; |
| 6329 | |
| 6330 | private: |
| 6331 | DISALLOW_IMPLICIT_CONSTRUCTORS(PrototypeInfo); |
| 6332 | }; |
| 6333 | |
| 6334 | |
| 6335 | // Pair used to store both a ScopeInfo and an extension object in the extension |
| 6336 | // slot of a block context. Needed in the rare case where a declaration block |
| 6337 | // scope (a "varblock" as used to desugar parameter destructuring) also contains |
| 6338 | // a sloppy direct eval. (In no other case both are needed at the same time.) |
| 6339 | class SloppyBlockWithEvalContextExtension : public Struct { |
| 6340 | public: |
| 6341 | // [scope_info]: Scope info. |
| 6342 | DECL_ACCESSORS(scope_info, ScopeInfo) |
| 6343 | // [extension]: Extension object. |
| 6344 | DECL_ACCESSORS(extension, JSObject) |
| 6345 | |
| 6346 | DECLARE_CAST(SloppyBlockWithEvalContextExtension) |
| 6347 | |
| 6348 | // Dispatched behavior. |
| 6349 | DECLARE_PRINTER(SloppyBlockWithEvalContextExtension) |
| 6350 | DECLARE_VERIFIER(SloppyBlockWithEvalContextExtension) |
| 6351 | |
| 6352 | static const int kScopeInfoOffset = HeapObject::kHeaderSize; |
| 6353 | static const int kExtensionOffset = kScopeInfoOffset + kPointerSize; |
| 6354 | static const int kSize = kExtensionOffset + kPointerSize; |
| 6355 | |
| 6356 | private: |
| 6357 | DISALLOW_IMPLICIT_CONSTRUCTORS(SloppyBlockWithEvalContextExtension); |
| 6358 | }; |
| 6359 | |
| 6360 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6361 | // Script describes a script which has been added to the VM. |
| 6362 | class Script: public Struct { |
| 6363 | public: |
| 6364 | // Script types. |
| 6365 | enum Type { |
| 6366 | TYPE_NATIVE = 0, |
| 6367 | TYPE_EXTENSION = 1, |
| 6368 | TYPE_NORMAL = 2 |
| 6369 | }; |
| 6370 | |
| 6371 | // Script compilation types. |
| 6372 | enum CompilationType { |
| 6373 | COMPILATION_TYPE_HOST = 0, |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 6374 | COMPILATION_TYPE_EVAL = 1 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6375 | }; |
| 6376 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 6377 | // Script compilation state. |
| 6378 | enum CompilationState { |
| 6379 | COMPILATION_STATE_INITIAL = 0, |
| 6380 | COMPILATION_STATE_COMPILED = 1 |
| 6381 | }; |
| 6382 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6383 | // [source]: the script source. |
| 6384 | DECL_ACCESSORS(source, Object) |
| 6385 | |
| 6386 | // [name]: the script name. |
| 6387 | DECL_ACCESSORS(name, Object) |
| 6388 | |
| 6389 | // [id]: the script id. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6390 | DECL_INT_ACCESSORS(id) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6391 | |
| 6392 | // [line_offset]: script line offset in resource from where it was extracted. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6393 | DECL_INT_ACCESSORS(line_offset) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6394 | |
| 6395 | // [column_offset]: script column offset in resource from where it was |
| 6396 | // extracted. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6397 | DECL_INT_ACCESSORS(column_offset) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6398 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6399 | // [context_data]: context data for the context this script was compiled in. |
| 6400 | DECL_ACCESSORS(context_data, Object) |
| 6401 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6402 | // [wrapper]: the wrapper cache. This is either undefined or a WeakCell. |
| 6403 | DECL_ACCESSORS(wrapper, HeapObject) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6404 | |
| 6405 | // [type]: the script type. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6406 | DECL_INT_ACCESSORS(type) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6407 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6408 | // [line_ends]: FixedArray of line ends positions. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6409 | DECL_ACCESSORS(line_ends, Object) |
| 6410 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 6411 | // [eval_from_shared]: for eval scripts the shared function info for the |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6412 | // function from which eval was called. |
| 6413 | DECL_ACCESSORS(eval_from_shared, Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6414 | |
| 6415 | // [eval_from_instructions_offset]: the instruction offset in the code for the |
| 6416 | // function from which eval was called where eval was called. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6417 | DECL_INT_ACCESSORS(eval_from_instructions_offset) |
| 6418 | |
| 6419 | // [shared_function_infos]: weak fixed array containing all shared |
| 6420 | // function infos created from this script. |
| 6421 | DECL_ACCESSORS(shared_function_infos, Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6422 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6423 | // [flags]: Holds an exciting bitfield. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6424 | DECL_INT_ACCESSORS(flags) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6425 | |
| 6426 | // [source_url]: sourceURL from magic comment |
| 6427 | DECL_ACCESSORS(source_url, Object) |
| 6428 | |
| 6429 | // [source_url]: sourceMappingURL magic comment |
| 6430 | DECL_ACCESSORS(source_mapping_url, Object) |
| 6431 | |
| 6432 | // [compilation_type]: how the the script was compiled. Encoded in the |
| 6433 | // 'flags' field. |
| 6434 | inline CompilationType compilation_type(); |
| 6435 | inline void set_compilation_type(CompilationType type); |
| 6436 | |
| 6437 | // [compilation_state]: determines whether the script has already been |
| 6438 | // compiled. Encoded in the 'flags' field. |
| 6439 | inline CompilationState compilation_state(); |
| 6440 | inline void set_compilation_state(CompilationState state); |
| 6441 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6442 | // [hide_source]: determines whether the script source can be exposed as |
| 6443 | // function source. Encoded in the 'flags' field. |
| 6444 | inline bool hide_source(); |
| 6445 | inline void set_hide_source(bool value); |
| 6446 | |
| 6447 | // [origin_options]: optional attributes set by the embedder via ScriptOrigin, |
| 6448 | // and used by the embedder to make decisions about the script. V8 just passes |
| 6449 | // this through. Encoded in the 'flags' field. |
| 6450 | inline v8::ScriptOriginOptions origin_options(); |
| 6451 | inline void set_origin_options(ScriptOriginOptions origin_options); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6452 | |
| 6453 | DECLARE_CAST(Script) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6454 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 6455 | // If script source is an external string, check that the underlying |
| 6456 | // resource is accessible. Otherwise, always return true. |
| 6457 | inline bool HasValidSource(); |
| 6458 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 6459 | // Convert code offset into column number. |
| 6460 | static int GetColumnNumber(Handle<Script> script, int code_offset); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6461 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 6462 | // Convert code offset into (zero-based) line number. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6463 | // The non-handlified version does not allocate, but may be much slower. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 6464 | static int GetLineNumber(Handle<Script> script, int code_offset); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6465 | int GetLineNumber(int code_pos); |
| 6466 | |
| 6467 | static Handle<Object> GetNameOrSourceURL(Handle<Script> script); |
| 6468 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 6469 | // Init line_ends array with source code positions of line ends. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6470 | static void InitLineEnds(Handle<Script> script); |
| 6471 | |
| 6472 | // Get the JS object wrapping the given script; create it if none exists. |
| 6473 | static Handle<JSObject> GetWrapper(Handle<Script> script); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6474 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6475 | // Look through the list of existing shared function infos to find one |
| 6476 | // that matches the function literal. Return empty handle if not found. |
| 6477 | MaybeHandle<SharedFunctionInfo> FindSharedFunctionInfo(FunctionLiteral* fun); |
| 6478 | |
| 6479 | // Iterate over all script objects on the heap. |
| 6480 | class Iterator { |
| 6481 | public: |
| 6482 | explicit Iterator(Isolate* isolate); |
| 6483 | Script* Next(); |
| 6484 | |
| 6485 | private: |
| 6486 | WeakFixedArray::Iterator iterator_; |
| 6487 | DISALLOW_COPY_AND_ASSIGN(Iterator); |
| 6488 | }; |
| 6489 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6490 | // Dispatched behavior. |
| 6491 | DECLARE_PRINTER(Script) |
| 6492 | DECLARE_VERIFIER(Script) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6493 | |
| 6494 | static const int kSourceOffset = HeapObject::kHeaderSize; |
| 6495 | static const int kNameOffset = kSourceOffset + kPointerSize; |
| 6496 | static const int kLineOffsetOffset = kNameOffset + kPointerSize; |
| 6497 | static const int kColumnOffsetOffset = kLineOffsetOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6498 | static const int kContextOffset = kColumnOffsetOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6499 | static const int kWrapperOffset = kContextOffset + kPointerSize; |
| 6500 | static const int kTypeOffset = kWrapperOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6501 | static const int kLineEndsOffset = kTypeOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6502 | static const int kIdOffset = kLineEndsOffset + kPointerSize; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6503 | static const int kEvalFromSharedOffset = kIdOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6504 | static const int kEvalFrominstructionsOffsetOffset = |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6505 | kEvalFromSharedOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6506 | static const int kSharedFunctionInfosOffset = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6507 | kEvalFrominstructionsOffsetOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6508 | static const int kFlagsOffset = kSharedFunctionInfosOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6509 | static const int kSourceUrlOffset = kFlagsOffset + kPointerSize; |
| 6510 | static const int kSourceMappingUrlOffset = kSourceUrlOffset + kPointerSize; |
| 6511 | static const int kSize = kSourceMappingUrlOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6512 | |
| 6513 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6514 | int GetLineNumberWithArray(int code_pos); |
| 6515 | |
| 6516 | // Bit positions in the flags field. |
| 6517 | static const int kCompilationTypeBit = 0; |
| 6518 | static const int kCompilationStateBit = 1; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6519 | static const int kHideSourceBit = 2; |
| 6520 | static const int kOriginOptionsShift = 3; |
| 6521 | static const int kOriginOptionsSize = 3; |
| 6522 | static const int kOriginOptionsMask = ((1 << kOriginOptionsSize) - 1) |
| 6523 | << kOriginOptionsShift; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6524 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6525 | DISALLOW_IMPLICIT_CONSTRUCTORS(Script); |
| 6526 | }; |
| 6527 | |
| 6528 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6529 | // List of builtin functions we want to identify to improve code |
| 6530 | // generation. |
| 6531 | // |
| 6532 | // Each entry has a name of a global object property holding an object |
| 6533 | // optionally followed by ".prototype", a name of a builtin function |
| 6534 | // on the object (the one the id is set for), and a label. |
| 6535 | // |
| 6536 | // Installation of ids for the selected builtin functions is handled |
| 6537 | // by the bootstrapper. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 6538 | #define FUNCTIONS_WITH_ID_LIST(V) \ |
| 6539 | V(Array.prototype, indexOf, ArrayIndexOf) \ |
| 6540 | V(Array.prototype, lastIndexOf, ArrayLastIndexOf) \ |
| 6541 | V(Array.prototype, push, ArrayPush) \ |
| 6542 | V(Array.prototype, pop, ArrayPop) \ |
| 6543 | V(Array.prototype, shift, ArrayShift) \ |
| 6544 | V(Function.prototype, apply, FunctionApply) \ |
| 6545 | V(Function.prototype, call, FunctionCall) \ |
| 6546 | V(String.prototype, charCodeAt, StringCharCodeAt) \ |
| 6547 | V(String.prototype, charAt, StringCharAt) \ |
| 6548 | V(String.prototype, concat, StringConcat) \ |
| 6549 | V(String.prototype, toLowerCase, StringToLowerCase) \ |
| 6550 | V(String.prototype, toUpperCase, StringToUpperCase) \ |
| 6551 | V(String, fromCharCode, StringFromCharCode) \ |
| 6552 | V(Math, random, MathRandom) \ |
| 6553 | V(Math, floor, MathFloor) \ |
| 6554 | V(Math, round, MathRound) \ |
| 6555 | V(Math, ceil, MathCeil) \ |
| 6556 | V(Math, abs, MathAbs) \ |
| 6557 | V(Math, log, MathLog) \ |
| 6558 | V(Math, exp, MathExp) \ |
| 6559 | V(Math, sqrt, MathSqrt) \ |
| 6560 | V(Math, pow, MathPow) \ |
| 6561 | V(Math, max, MathMax) \ |
| 6562 | V(Math, min, MathMin) \ |
| 6563 | V(Math, cos, MathCos) \ |
| 6564 | V(Math, sin, MathSin) \ |
| 6565 | V(Math, tan, MathTan) \ |
| 6566 | V(Math, acos, MathAcos) \ |
| 6567 | V(Math, asin, MathAsin) \ |
| 6568 | V(Math, atan, MathAtan) \ |
| 6569 | V(Math, atan2, MathAtan2) \ |
| 6570 | V(Math, imul, MathImul) \ |
| 6571 | V(Math, clz32, MathClz32) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6572 | V(Math, fround, MathFround) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6573 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6574 | #define ATOMIC_FUNCTIONS_WITH_ID_LIST(V) \ |
| 6575 | V(Atomics, load, AtomicsLoad) \ |
| 6576 | V(Atomics, store, AtomicsStore) |
| 6577 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6578 | enum BuiltinFunctionId { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6579 | kArrayCode, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6580 | #define DECLARE_FUNCTION_ID(ignored1, ignore2, name) \ |
| 6581 | k##name, |
| 6582 | FUNCTIONS_WITH_ID_LIST(DECLARE_FUNCTION_ID) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6583 | ATOMIC_FUNCTIONS_WITH_ID_LIST(DECLARE_FUNCTION_ID) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6584 | #undef DECLARE_FUNCTION_ID |
| 6585 | // Fake id for a special case of Math.pow. Note, it continues the |
| 6586 | // list of math functions. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6587 | kMathPowHalf |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6588 | }; |
| 6589 | |
| 6590 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6591 | // Result of searching in an optimized code map of a SharedFunctionInfo. Note |
| 6592 | // that both {code} and {literals} can be NULL to pass search result status. |
| 6593 | struct CodeAndLiterals { |
| 6594 | Code* code; // Cached optimized code. |
| 6595 | LiteralsArray* literals; // Cached literals array. |
| 6596 | }; |
| 6597 | |
| 6598 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6599 | // SharedFunctionInfo describes the JSFunction information that can be |
| 6600 | // shared by multiple instances of the function. |
| 6601 | class SharedFunctionInfo: public HeapObject { |
| 6602 | public: |
| 6603 | // [name]: Function name. |
| 6604 | DECL_ACCESSORS(name, Object) |
| 6605 | |
| 6606 | // [code]: Function code. |
| 6607 | DECL_ACCESSORS(code, Code) |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 6608 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6609 | inline void ReplaceCode(Code* code); |
| 6610 | |
| 6611 | // [optimized_code_map]: Map from native context to optimized code |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6612 | // and a shared literals array. |
| 6613 | DECL_ACCESSORS(optimized_code_map, FixedArray) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6614 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6615 | // Returns entry from optimized code map for specified context and OSR entry. |
| 6616 | // Note that {code == nullptr, literals == nullptr} indicates no matching |
| 6617 | // entry has been found, whereas {code, literals == nullptr} indicates that |
| 6618 | // code is context-independent. |
| 6619 | CodeAndLiterals SearchOptimizedCodeMap(Context* native_context, |
| 6620 | BailoutId osr_ast_id); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6621 | |
| 6622 | // Clear optimized code map. |
| 6623 | void ClearOptimizedCodeMap(); |
| 6624 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6625 | // We have a special root FixedArray with the right shape and values |
| 6626 | // to represent the cleared optimized code map. This predicate checks |
| 6627 | // if that root is installed. |
| 6628 | inline bool OptimizedCodeMapIsCleared() const; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6629 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6630 | // Removes a specific optimized code object from the optimized code map. |
| 6631 | // In case of non-OSR the code reference is cleared from the cache entry but |
| 6632 | // the entry itself is left in the map in order to proceed sharing literals. |
| 6633 | void EvictFromOptimizedCodeMap(Code* optimized_code, const char* reason); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6634 | |
| 6635 | // Trims the optimized code map after entries have been removed. |
| 6636 | void TrimOptimizedCodeMap(int shrink_by); |
| 6637 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6638 | // Add a new entry to the optimized code map for context-independent code. |
| 6639 | static void AddSharedCodeToOptimizedCodeMap(Handle<SharedFunctionInfo> shared, |
| 6640 | Handle<Code> code); |
| 6641 | |
| 6642 | // Add a new entry to the optimized code map for context-dependent code. |
| 6643 | inline static void AddToOptimizedCodeMap(Handle<SharedFunctionInfo> shared, |
| 6644 | Handle<Context> native_context, |
| 6645 | Handle<Code> code, |
| 6646 | Handle<LiteralsArray> literals, |
| 6647 | BailoutId osr_ast_id); |
| 6648 | |
| 6649 | // We may already have cached the code, but want to store literals in the |
| 6650 | // cache. |
| 6651 | inline static void AddLiteralsToOptimizedCodeMap( |
| 6652 | Handle<SharedFunctionInfo> shared, Handle<Context> native_context, |
| 6653 | Handle<LiteralsArray> literals); |
| 6654 | |
| 6655 | // Set up the link between shared function info and the script. The shared |
| 6656 | // function info is added to the list on the script. |
| 6657 | static void SetScript(Handle<SharedFunctionInfo> shared, |
| 6658 | Handle<Object> script_object); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6659 | |
| 6660 | // Layout description of the optimized code map. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6661 | static const int kSharedCodeIndex = 0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6662 | static const int kEntriesStart = 1; |
| 6663 | static const int kContextOffset = 0; |
| 6664 | static const int kCachedCodeOffset = 1; |
| 6665 | static const int kLiteralsOffset = 2; |
| 6666 | static const int kOsrAstIdOffset = 3; |
| 6667 | static const int kEntryLength = 4; |
| 6668 | static const int kInitialLength = kEntriesStart + kEntryLength; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6669 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6670 | static const int kNotFound = -1; |
| 6671 | |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 6672 | // [scope_info]: Scope info. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 6673 | DECL_ACCESSORS(scope_info, ScopeInfo) |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 6674 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6675 | // [construct stub]: Code stub for constructing instances of this function. |
| 6676 | DECL_ACCESSORS(construct_stub, Code) |
| 6677 | |
| 6678 | // Returns if this function has been compiled to native code yet. |
| 6679 | inline bool is_compiled(); |
| 6680 | |
| 6681 | // [length]: The function length - usually the number of declared parameters. |
| 6682 | // Use up to 2^30 parameters. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6683 | inline int length() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6684 | inline void set_length(int value); |
| 6685 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6686 | // [internal formal parameter count]: The declared number of parameters. |
| 6687 | // For subclass constructors, also includes new.target. |
| 6688 | // The size of function's frame is internal_formal_parameter_count + 1. |
| 6689 | inline int internal_formal_parameter_count() const; |
| 6690 | inline void set_internal_formal_parameter_count(int value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6691 | |
| 6692 | // Set the formal parameter count so the function code will be |
| 6693 | // called without using argument adaptor frames. |
| 6694 | inline void DontAdaptArguments(); |
| 6695 | |
| 6696 | // [expected_nof_properties]: Expected number of properties for the function. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6697 | inline int expected_nof_properties() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6698 | inline void set_expected_nof_properties(int value); |
| 6699 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6700 | // [feedback_vector] - accumulates ast node feedback from full-codegen and |
| 6701 | // (increasingly) from crankshafted code where sufficient feedback isn't |
| 6702 | // available. |
| 6703 | DECL_ACCESSORS(feedback_vector, TypeFeedbackVector) |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 6704 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6705 | // Unconditionally clear the type feedback vector (including vector ICs). |
| 6706 | void ClearTypeFeedbackInfo(); |
| 6707 | |
| 6708 | // Clear the type feedback vector with a more subtle policy at GC time. |
| 6709 | void ClearTypeFeedbackInfoAtGCTime(); |
| 6710 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6711 | #if TRACE_MAPS |
| 6712 | // [unique_id] - For --trace-maps purposes, an identifier that's persistent |
| 6713 | // even if the GC moves this SharedFunctionInfo. |
| 6714 | inline int unique_id() const; |
| 6715 | inline void set_unique_id(int value); |
| 6716 | #endif |
| 6717 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6718 | // [instance class name]: class name for instances. |
| 6719 | DECL_ACCESSORS(instance_class_name, Object) |
| 6720 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 6721 | // [function data]: This field holds some additional data for function. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6722 | // Currently it has one of: |
| 6723 | // - a FunctionTemplateInfo to make benefit the API [IsApiFunction()]. |
| 6724 | // - a Smi identifying a builtin function [HasBuiltinFunctionId()]. |
| 6725 | // - a BytecodeArray for the interpreter [HasBytecodeArray()]. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6726 | // In the long run we don't want all functions to have this field but |
| 6727 | // we can fix that when we have a better model for storing hidden data |
| 6728 | // on objects. |
| 6729 | DECL_ACCESSORS(function_data, Object) |
| 6730 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 6731 | inline bool IsApiFunction(); |
| 6732 | inline FunctionTemplateInfo* get_api_func_data(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6733 | inline bool HasBuiltinFunctionId(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6734 | inline BuiltinFunctionId builtin_function_id(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6735 | inline bool HasBytecodeArray(); |
| 6736 | inline BytecodeArray* bytecode_array(); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 6737 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6738 | // [script info]: Script from which the function originates. |
| 6739 | DECL_ACCESSORS(script, Object) |
| 6740 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 6741 | // [num_literals]: Number of literals used by this function. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6742 | inline int num_literals() const; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 6743 | inline void set_num_literals(int value); |
| 6744 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6745 | // [start_position_and_type]: Field used to store both the source code |
| 6746 | // position, whether or not the function is a function expression, |
| 6747 | // and whether or not the function is a toplevel function. The two |
| 6748 | // least significants bit indicates whether the function is an |
| 6749 | // expression and the rest contains the source code position. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6750 | inline int start_position_and_type() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6751 | inline void set_start_position_and_type(int value); |
| 6752 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6753 | // The function is subject to debugging if a debug info is attached. |
| 6754 | inline bool HasDebugInfo(); |
| 6755 | inline DebugInfo* GetDebugInfo(); |
| 6756 | |
| 6757 | // A function has debug code if the compiled code has debug break slots. |
| 6758 | inline bool HasDebugCode(); |
| 6759 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6760 | // [debug info]: Debug information. |
| 6761 | DECL_ACCESSORS(debug_info, Object) |
| 6762 | |
| 6763 | // [inferred name]: Name inferred from variable or property |
| 6764 | // assignment of this function. Used to facilitate debugging and |
| 6765 | // profiling of JavaScript code written in OO style, where almost |
| 6766 | // all functions are anonymous but are assigned to object |
| 6767 | // properties. |
| 6768 | DECL_ACCESSORS(inferred_name, String) |
| 6769 | |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 6770 | // The function's name if it is non-empty, otherwise the inferred name. |
| 6771 | String* DebugName(); |
| 6772 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6773 | // Position of the 'function' token in the script source. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6774 | inline int function_token_position() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6775 | inline void set_function_token_position(int function_token_position); |
| 6776 | |
| 6777 | // Position of this function in the script source. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6778 | inline int start_position() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6779 | inline void set_start_position(int start_position); |
| 6780 | |
| 6781 | // End position of this function in the script source. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6782 | inline int end_position() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6783 | inline void set_end_position(int end_position); |
| 6784 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 6785 | // Is this function a named function expression in the source code. |
| 6786 | DECL_BOOLEAN_ACCESSORS(is_named_expression) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6787 | |
| 6788 | // Is this function a top-level function (scripts, evals). |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6789 | DECL_BOOLEAN_ACCESSORS(is_toplevel) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6790 | |
| 6791 | // Bit field containing various information collected by the compiler to |
| 6792 | // drive optimization. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6793 | inline int compiler_hints() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6794 | inline void set_compiler_hints(int value); |
| 6795 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6796 | inline int ast_node_count() const; |
Ben Murdoch | 8f9999f | 2012-04-23 10:39:17 +0100 | [diff] [blame] | 6797 | inline void set_ast_node_count(int count); |
| 6798 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6799 | inline int profiler_ticks() const; |
| 6800 | inline void set_profiler_ticks(int ticks); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 6801 | |
Ben Murdoch | 8f9999f | 2012-04-23 10:39:17 +0100 | [diff] [blame] | 6802 | // Inline cache age is used to infer whether the function survived a context |
| 6803 | // disposal or not. In the former case we reset the opt_count. |
| 6804 | inline int ic_age(); |
| 6805 | inline void set_ic_age(int age); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6806 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 6807 | // Indicates if this function can be lazy compiled. |
| 6808 | // This is used to determine if we can safely flush code from a function |
| 6809 | // 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] | 6810 | DECL_BOOLEAN_ACCESSORS(allows_lazy_compilation) |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 6811 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6812 | // Indicates if this function can be lazy compiled without a context. |
| 6813 | // This is used to determine if we can force compilation without reaching |
| 6814 | // the function through program execution but through other means (e.g. heap |
| 6815 | // iteration by the debugger). |
| 6816 | DECL_BOOLEAN_ACCESSORS(allows_lazy_compilation_without_context) |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 6817 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6818 | // Indicates whether optimizations have been disabled for this |
| 6819 | // shared function info. If a function is repeatedly optimized or if |
| 6820 | // we cannot optimize the function we disable optimization to avoid |
| 6821 | // spending time attempting to optimize it again. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6822 | DECL_BOOLEAN_ACCESSORS(optimization_disabled) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6823 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6824 | // Indicates the language mode. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6825 | inline LanguageMode language_mode(); |
| 6826 | inline void set_language_mode(LanguageMode language_mode); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 6827 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6828 | // False if the function definitely does not allocate an arguments object. |
| 6829 | DECL_BOOLEAN_ACCESSORS(uses_arguments) |
| 6830 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6831 | // Indicates that this function uses a super property (or an eval that may |
| 6832 | // use a super property). |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6833 | // This is needed to set up the [[HomeObject]] on the function instance. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6834 | DECL_BOOLEAN_ACCESSORS(needs_home_object) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6835 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6836 | // True if the function has any duplicated parameter names. |
| 6837 | DECL_BOOLEAN_ACCESSORS(has_duplicate_parameters) |
| 6838 | |
| 6839 | // Indicates whether the function is a native function. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 6840 | // These needs special treatment in .call and .apply since |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6841 | // null passed as the receiver should not be translated to the |
| 6842 | // global object. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6843 | DECL_BOOLEAN_ACCESSORS(native) |
| 6844 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6845 | // Indicate that this function should always be inlined in optimized code. |
| 6846 | DECL_BOOLEAN_ACCESSORS(force_inline) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6847 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6848 | // Indicates that the function was created by the Function function. |
| 6849 | // Though it's anonymous, toString should treat it as if it had the name |
| 6850 | // "anonymous". We don't set the name itself so that the system does not |
| 6851 | // see a binding for it. |
| 6852 | DECL_BOOLEAN_ACCESSORS(name_should_print_as_anonymous) |
| 6853 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 6854 | // Indicates that the function is either an anonymous expression |
| 6855 | // or an arrow function (the name field can be set through the API, |
| 6856 | // which does not change this flag). |
| 6857 | DECL_BOOLEAN_ACCESSORS(is_anonymous_expression) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6858 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 6859 | // Is this a function or top-level/eval code. |
| 6860 | DECL_BOOLEAN_ACCESSORS(is_function) |
| 6861 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6862 | // Indicates that code for this function cannot be compiled with Crankshaft. |
| 6863 | DECL_BOOLEAN_ACCESSORS(dont_crankshaft) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 6864 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6865 | // Indicates that code for this function cannot be flushed. |
| 6866 | DECL_BOOLEAN_ACCESSORS(dont_flush) |
| 6867 | |
| 6868 | // Indicates that this function is a generator. |
| 6869 | DECL_BOOLEAN_ACCESSORS(is_generator) |
| 6870 | |
| 6871 | // Indicates that this function is an arrow function. |
| 6872 | DECL_BOOLEAN_ACCESSORS(is_arrow) |
| 6873 | |
| 6874 | // Indicates that this function is a concise method. |
| 6875 | DECL_BOOLEAN_ACCESSORS(is_concise_method) |
| 6876 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 6877 | // Indicates that this function is a getter. |
| 6878 | DECL_BOOLEAN_ACCESSORS(is_getter_function) |
| 6879 | |
| 6880 | // Indicates that this function is a setter. |
| 6881 | DECL_BOOLEAN_ACCESSORS(is_setter_function) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6882 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6883 | // Indicates that this function is a default constructor. |
| 6884 | DECL_BOOLEAN_ACCESSORS(is_default_constructor) |
| 6885 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6886 | // Indicates that this function is an asm function. |
| 6887 | DECL_BOOLEAN_ACCESSORS(asm_function) |
| 6888 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6889 | // Indicates that the the shared function info is deserialized from cache. |
| 6890 | DECL_BOOLEAN_ACCESSORS(deserialized) |
| 6891 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6892 | // Indicates that the the shared function info has never been compiled before. |
| 6893 | DECL_BOOLEAN_ACCESSORS(never_compiled) |
| 6894 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 6895 | // Whether this function was created from a FunctionDeclaration. |
| 6896 | DECL_BOOLEAN_ACCESSORS(is_declaration) |
| 6897 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6898 | inline FunctionKind kind(); |
| 6899 | inline void set_kind(FunctionKind kind); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 6900 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6901 | // Indicates whether or not the code in the shared function support |
| 6902 | // deoptimization. |
| 6903 | inline bool has_deoptimization_support(); |
| 6904 | |
| 6905 | // Enable deoptimization support through recompiled code. |
| 6906 | void EnableDeoptimizationSupport(Code* recompiled); |
| 6907 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6908 | // Disable (further) attempted optimization of all functions sharing this |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 6909 | // shared function info. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6910 | void DisableOptimization(BailoutReason reason); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6911 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 6912 | inline BailoutReason disable_optimization_reason(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6913 | |
| 6914 | // 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] | 6915 | // code, returns whether it asserted (i.e., always true if assertions are |
| 6916 | // disabled). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6917 | bool VerifyBailoutId(BailoutId id); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6918 | |
| 6919 | // [source code]: Source code for the function. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6920 | bool HasSourceCode() const; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 6921 | Handle<Object> GetSourceCode(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6922 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6923 | // Number of times the function was optimized. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6924 | inline int opt_count(); |
| 6925 | inline void set_opt_count(int opt_count); |
| 6926 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6927 | // Number of times the function was deoptimized. |
| 6928 | inline void set_deopt_count(int value); |
| 6929 | inline int deopt_count(); |
| 6930 | inline void increment_deopt_count(); |
| 6931 | |
| 6932 | // Number of time we tried to re-enable optimization after it |
| 6933 | // was disabled due to high number of deoptimizations. |
| 6934 | inline void set_opt_reenable_tries(int value); |
| 6935 | inline int opt_reenable_tries(); |
| 6936 | |
| 6937 | inline void TryReenableOptimization(); |
| 6938 | |
| 6939 | // Stores deopt_count, opt_reenable_tries and ic_age as bit-fields. |
| 6940 | inline void set_counters(int value); |
| 6941 | inline int counters() const; |
| 6942 | |
| 6943 | // Stores opt_count and bailout_reason as bit-fields. |
| 6944 | inline void set_opt_count_and_bailout_reason(int value); |
| 6945 | inline int opt_count_and_bailout_reason() const; |
| 6946 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6947 | inline void set_disable_optimization_reason(BailoutReason reason); |
| 6948 | |
| 6949 | // Tells whether this function should be subject to debugging. |
| 6950 | inline bool IsSubjectToDebugging(); |
| 6951 | |
| 6952 | // Whether this function is defined in native code or extensions. |
| 6953 | inline bool IsBuiltin(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6954 | |
| 6955 | // Check whether or not this function is inlineable. |
| 6956 | bool IsInlineable(); |
| 6957 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6958 | // Source size of this function. |
| 6959 | int SourceSize(); |
| 6960 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6961 | // Returns `false` if formal parameters include rest parameters, optional |
| 6962 | // parameters, or destructuring parameters. |
| 6963 | // TODO(caitp): make this a flag set during parsing |
| 6964 | inline bool has_simple_parameters(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6965 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6966 | // Initialize a SharedFunctionInfo from a parsed function literal. |
| 6967 | static void InitFromFunctionLiteral(Handle<SharedFunctionInfo> shared_info, |
| 6968 | FunctionLiteral* lit); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6969 | |
| 6970 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6971 | DECLARE_PRINTER(SharedFunctionInfo) |
| 6972 | DECLARE_VERIFIER(SharedFunctionInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6973 | |
Ben Murdoch | 8f9999f | 2012-04-23 10:39:17 +0100 | [diff] [blame] | 6974 | void ResetForNewContext(int new_ic_age); |
| 6975 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 6976 | // Iterate over all shared function infos. |
| 6977 | class Iterator { |
| 6978 | public: |
| 6979 | explicit Iterator(Isolate* isolate); |
| 6980 | SharedFunctionInfo* Next(); |
| 6981 | |
| 6982 | private: |
| 6983 | bool NextScript(); |
| 6984 | |
| 6985 | Script::Iterator script_iterator_; |
| 6986 | WeakFixedArray::Iterator sfi_iterator_; |
| 6987 | DisallowHeapAllocation no_gc_; |
| 6988 | DISALLOW_COPY_AND_ASSIGN(Iterator); |
| 6989 | }; |
| 6990 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6991 | DECLARE_CAST(SharedFunctionInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6992 | |
| 6993 | // Constants. |
| 6994 | static const int kDontAdaptArgumentsSentinel = -1; |
| 6995 | |
| 6996 | // Layout description. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 6997 | // Pointer fields. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6998 | static const int kNameOffset = HeapObject::kHeaderSize; |
| 6999 | static const int kCodeOffset = kNameOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7000 | static const int kOptimizedCodeMapOffset = kCodeOffset + kPointerSize; |
| 7001 | static const int kScopeInfoOffset = kOptimizedCodeMapOffset + kPointerSize; |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 7002 | static const int kConstructStubOffset = kScopeInfoOffset + kPointerSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 7003 | static const int kInstanceClassNameOffset = |
| 7004 | kConstructStubOffset + kPointerSize; |
| 7005 | static const int kFunctionDataOffset = |
| 7006 | kInstanceClassNameOffset + kPointerSize; |
| 7007 | static const int kScriptOffset = kFunctionDataOffset + kPointerSize; |
| 7008 | static const int kDebugInfoOffset = kScriptOffset + kPointerSize; |
| 7009 | static const int kInferredNameOffset = kDebugInfoOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7010 | static const int kFeedbackVectorOffset = |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 7011 | kInferredNameOffset + kPointerSize; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 7012 | #if TRACE_MAPS |
| 7013 | static const int kUniqueIdOffset = kFeedbackVectorOffset + kPointerSize; |
| 7014 | static const int kLastPointerFieldOffset = kUniqueIdOffset; |
| 7015 | #else |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7016 | // Just to not break the postmortrem support with conditional offsets |
| 7017 | static const int kUniqueIdOffset = kFeedbackVectorOffset; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 7018 | static const int kLastPointerFieldOffset = kFeedbackVectorOffset; |
| 7019 | #endif |
| 7020 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7021 | #if V8_HOST_ARCH_32_BIT |
| 7022 | // Smi fields. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 7023 | static const int kLengthOffset = kLastPointerFieldOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7024 | static const int kFormalParameterCountOffset = kLengthOffset + kPointerSize; |
| 7025 | static const int kExpectedNofPropertiesOffset = |
| 7026 | kFormalParameterCountOffset + kPointerSize; |
| 7027 | static const int kNumLiteralsOffset = |
| 7028 | kExpectedNofPropertiesOffset + kPointerSize; |
| 7029 | static const int kStartPositionAndTypeOffset = |
| 7030 | kNumLiteralsOffset + kPointerSize; |
| 7031 | static const int kEndPositionOffset = |
| 7032 | kStartPositionAndTypeOffset + kPointerSize; |
| 7033 | static const int kFunctionTokenPositionOffset = |
| 7034 | kEndPositionOffset + kPointerSize; |
| 7035 | static const int kCompilerHintsOffset = |
| 7036 | kFunctionTokenPositionOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7037 | static const int kOptCountAndBailoutReasonOffset = |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7038 | kCompilerHintsOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7039 | static const int kCountersOffset = |
| 7040 | kOptCountAndBailoutReasonOffset + kPointerSize; |
| 7041 | static const int kAstNodeCountOffset = |
| 7042 | kCountersOffset + kPointerSize; |
| 7043 | static const int kProfilerTicksOffset = |
| 7044 | kAstNodeCountOffset + kPointerSize; |
Ben Murdoch | 8f9999f | 2012-04-23 10:39:17 +0100 | [diff] [blame] | 7045 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7046 | // Total size. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7047 | static const int kSize = kProfilerTicksOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7048 | #else |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7049 | // The only reason to use smi fields instead of int fields is to allow |
| 7050 | // iteration without maps decoding during garbage collections. |
| 7051 | // To avoid wasting space on 64-bit architectures we use the following trick: |
| 7052 | // we group integer fields into pairs |
| 7053 | // The least significant integer in each pair is shifted left by 1. By doing |
| 7054 | // this we guarantee that LSB of each kPointerSize aligned word is not set and |
| 7055 | // thus this word cannot be treated as pointer to HeapObject during old space |
| 7056 | // traversal. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 7057 | #if V8_TARGET_LITTLE_ENDIAN |
| 7058 | static const int kLengthOffset = kLastPointerFieldOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7059 | static const int kFormalParameterCountOffset = |
| 7060 | kLengthOffset + kIntSize; |
| 7061 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7062 | static const int kExpectedNofPropertiesOffset = |
| 7063 | kFormalParameterCountOffset + kIntSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7064 | static const int kNumLiteralsOffset = |
| 7065 | kExpectedNofPropertiesOffset + kIntSize; |
| 7066 | |
| 7067 | static const int kEndPositionOffset = |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 7068 | kNumLiteralsOffset + kIntSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7069 | static const int kStartPositionAndTypeOffset = |
| 7070 | kEndPositionOffset + kIntSize; |
| 7071 | |
| 7072 | static const int kFunctionTokenPositionOffset = |
| 7073 | kStartPositionAndTypeOffset + kIntSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 7074 | static const int kCompilerHintsOffset = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7075 | kFunctionTokenPositionOffset + kIntSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7076 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7077 | static const int kOptCountAndBailoutReasonOffset = |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 7078 | kCompilerHintsOffset + kIntSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7079 | static const int kCountersOffset = |
| 7080 | kOptCountAndBailoutReasonOffset + kIntSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7081 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7082 | static const int kAstNodeCountOffset = |
| 7083 | kCountersOffset + kIntSize; |
| 7084 | static const int kProfilerTicksOffset = |
| 7085 | kAstNodeCountOffset + kIntSize; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7086 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 7087 | // Total size. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7088 | static const int kSize = kProfilerTicksOffset + kIntSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7089 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 7090 | #elif V8_TARGET_BIG_ENDIAN |
| 7091 | static const int kFormalParameterCountOffset = |
| 7092 | kLastPointerFieldOffset + kPointerSize; |
| 7093 | static const int kLengthOffset = kFormalParameterCountOffset + kIntSize; |
| 7094 | |
| 7095 | static const int kNumLiteralsOffset = kLengthOffset + kIntSize; |
| 7096 | static const int kExpectedNofPropertiesOffset = kNumLiteralsOffset + kIntSize; |
| 7097 | |
| 7098 | static const int kStartPositionAndTypeOffset = |
| 7099 | kExpectedNofPropertiesOffset + kIntSize; |
| 7100 | static const int kEndPositionOffset = kStartPositionAndTypeOffset + kIntSize; |
| 7101 | |
| 7102 | static const int kCompilerHintsOffset = kEndPositionOffset + kIntSize; |
| 7103 | static const int kFunctionTokenPositionOffset = |
| 7104 | kCompilerHintsOffset + kIntSize; |
| 7105 | |
| 7106 | static const int kCountersOffset = kFunctionTokenPositionOffset + kIntSize; |
| 7107 | static const int kOptCountAndBailoutReasonOffset = kCountersOffset + kIntSize; |
| 7108 | |
| 7109 | static const int kProfilerTicksOffset = |
| 7110 | kOptCountAndBailoutReasonOffset + kIntSize; |
| 7111 | static const int kAstNodeCountOffset = kProfilerTicksOffset + kIntSize; |
| 7112 | |
| 7113 | // Total size. |
| 7114 | static const int kSize = kAstNodeCountOffset + kIntSize; |
| 7115 | |
| 7116 | #else |
| 7117 | #error Unknown byte ordering |
| 7118 | #endif // Big endian |
| 7119 | #endif // 64-bit |
| 7120 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 7121 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 7122 | static const int kAlignedSize = POINTER_SIZE_ALIGN(kSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7123 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 7124 | typedef FixedBodyDescriptor<kNameOffset, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 7125 | kLastPointerFieldOffset + kPointerSize, |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 7126 | kSize> BodyDescriptor; |
| 7127 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7128 | // Bit positions in start_position_and_type. |
| 7129 | // The source code start position is in the 30 most significant bits of |
| 7130 | // the start_position_and_type field. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 7131 | static const int kIsNamedExpressionBit = 0; |
| 7132 | static const int kIsTopLevelBit = 1; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7133 | static const int kStartPositionShift = 2; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 7134 | static const int kStartPositionMask = ~((1 << kStartPositionShift) - 1); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7135 | |
| 7136 | // Bit positions in compiler_hints. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 7137 | enum CompilerHints { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7138 | // byte 0 |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 7139 | kAllowLazyCompilation, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7140 | kAllowLazyCompilationWithoutContext, |
| 7141 | kOptimizationDisabled, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 7142 | kNative, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7143 | kStrictModeFunction, |
| 7144 | kStrongModeFunction, |
| 7145 | kUsesArguments, |
| 7146 | kNeedsHomeObject, |
| 7147 | // byte 1 |
| 7148 | kHasDuplicateParameters, |
| 7149 | kForceInline, |
| 7150 | kIsAsmFunction, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 7151 | kIsAnonymousExpression, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 7152 | kNameShouldPrintAsAnonymous, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7153 | kIsFunction, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7154 | kDontCrankshaft, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7155 | kDontFlush, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7156 | // byte 2 |
| 7157 | kFunctionKind, |
| 7158 | kIsArrow = kFunctionKind, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7159 | kIsGenerator, |
| 7160 | kIsConciseMethod, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 7161 | kIsDefaultConstructor, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7162 | kIsSubclassConstructor, |
| 7163 | kIsBaseConstructor, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 7164 | kIsGetterFunction, |
| 7165 | kIsSetterFunction, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7166 | // byte 3 |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 7167 | kDeserialized, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7168 | kNeverCompiled, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 7169 | kIsDeclaration, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7170 | kCompilerHintsCount, // Pseudo entry |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 7171 | }; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7172 | // Add hints for other modes when they're added. |
| 7173 | STATIC_ASSERT(LANGUAGE_END == 3); |
| 7174 | // kFunctionKind has to be byte-aligned |
| 7175 | STATIC_ASSERT((kFunctionKind % kBitsPerByte) == 0); |
| 7176 | // Make sure that FunctionKind and byte 2 are in sync: |
| 7177 | #define ASSERT_FUNCTION_KIND_ORDER(functionKind, compilerFunctionKind) \ |
| 7178 | STATIC_ASSERT(FunctionKind::functionKind == \ |
| 7179 | 1 << (compilerFunctionKind - kFunctionKind)) |
| 7180 | ASSERT_FUNCTION_KIND_ORDER(kArrowFunction, kIsArrow); |
| 7181 | ASSERT_FUNCTION_KIND_ORDER(kGeneratorFunction, kIsGenerator); |
| 7182 | ASSERT_FUNCTION_KIND_ORDER(kConciseMethod, kIsConciseMethod); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7183 | ASSERT_FUNCTION_KIND_ORDER(kDefaultConstructor, kIsDefaultConstructor); |
| 7184 | ASSERT_FUNCTION_KIND_ORDER(kSubclassConstructor, kIsSubclassConstructor); |
| 7185 | ASSERT_FUNCTION_KIND_ORDER(kBaseConstructor, kIsBaseConstructor); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 7186 | ASSERT_FUNCTION_KIND_ORDER(kGetterFunction, kIsGetterFunction); |
| 7187 | ASSERT_FUNCTION_KIND_ORDER(kSetterFunction, kIsSetterFunction); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7188 | #undef ASSERT_FUNCTION_KIND_ORDER |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7189 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7190 | class FunctionKindBits : public BitField<FunctionKind, kIsArrow, 8> {}; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7191 | |
| 7192 | class DeoptCountBits : public BitField<int, 0, 4> {}; |
| 7193 | class OptReenableTriesBits : public BitField<int, 4, 18> {}; |
| 7194 | class ICAgeBits : public BitField<int, 22, 8> {}; |
| 7195 | |
| 7196 | class OptCountBits : public BitField<int, 0, 22> {}; |
| 7197 | class DisabledOptimizationReasonBits : public BitField<int, 22, 8> {}; |
| 7198 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 7199 | private: |
| 7200 | #if V8_HOST_ARCH_32_BIT |
| 7201 | // On 32 bit platforms, compiler hints is a smi. |
| 7202 | static const int kCompilerHintsSmiTagSize = kSmiTagSize; |
| 7203 | static const int kCompilerHintsSize = kPointerSize; |
| 7204 | #else |
| 7205 | // On 64 bit platforms, compiler hints is not a smi, see comment above. |
| 7206 | static const int kCompilerHintsSmiTagSize = 0; |
| 7207 | static const int kCompilerHintsSize = kIntSize; |
| 7208 | #endif |
| 7209 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 7210 | STATIC_ASSERT(SharedFunctionInfo::kCompilerHintsCount <= |
| 7211 | SharedFunctionInfo::kCompilerHintsSize * kBitsPerByte); |
| 7212 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 7213 | public: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7214 | // Constants for optimizing codegen for strict mode function and |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7215 | // native tests when using integer-width instructions. |
| 7216 | static const int kStrictModeBit = |
| 7217 | kStrictModeFunction + kCompilerHintsSmiTagSize; |
| 7218 | static const int kStrongModeBit = |
| 7219 | kStrongModeFunction + kCompilerHintsSmiTagSize; |
| 7220 | static const int kNativeBit = kNative + kCompilerHintsSmiTagSize; |
| 7221 | |
| 7222 | static const int kClassConstructorBits = |
| 7223 | FunctionKind::kClassConstructor |
| 7224 | << (kFunctionKind + kCompilerHintsSmiTagSize); |
| 7225 | |
| 7226 | // Constants for optimizing codegen for strict mode function and |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 7227 | // native tests. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7228 | // Allows to use byte-width instructions. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7229 | static const int kStrictModeBitWithinByte = kStrictModeBit % kBitsPerByte; |
| 7230 | static const int kStrongModeBitWithinByte = kStrongModeBit % kBitsPerByte; |
| 7231 | static const int kNativeBitWithinByte = kNativeBit % kBitsPerByte; |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 7232 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7233 | static const int kClassConstructorBitsWithinByte = |
| 7234 | FunctionKind::kClassConstructor << kCompilerHintsSmiTagSize; |
| 7235 | STATIC_ASSERT(kClassConstructorBitsWithinByte < (1 << kBitsPerByte)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7236 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7237 | #if defined(V8_TARGET_LITTLE_ENDIAN) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7238 | #define BYTE_OFFSET(compiler_hint) \ |
| 7239 | kCompilerHintsOffset + \ |
| 7240 | (compiler_hint + kCompilerHintsSmiTagSize) / kBitsPerByte |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7241 | #elif defined(V8_TARGET_BIG_ENDIAN) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7242 | #define BYTE_OFFSET(compiler_hint) \ |
| 7243 | kCompilerHintsOffset + (kCompilerHintsSize - 1) - \ |
| 7244 | ((compiler_hint + kCompilerHintsSmiTagSize) / kBitsPerByte) |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 7245 | #else |
| 7246 | #error Unknown byte ordering |
| 7247 | #endif |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7248 | static const int kStrictModeByteOffset = BYTE_OFFSET(kStrictModeFunction); |
| 7249 | static const int kStrongModeByteOffset = BYTE_OFFSET(kStrongModeFunction); |
| 7250 | static const int kNativeByteOffset = BYTE_OFFSET(kNative); |
| 7251 | static const int kFunctionKindByteOffset = BYTE_OFFSET(kFunctionKind); |
| 7252 | #undef BYTE_OFFSET |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 7253 | |
| 7254 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7255 | // Returns entry from optimized code map for specified context and OSR entry. |
| 7256 | // The result is either kNotFound, kSharedCodeIndex for context-independent |
| 7257 | // entry or a start index of the context-dependent entry. |
| 7258 | int SearchOptimizedCodeMapEntry(Context* native_context, |
| 7259 | BailoutId osr_ast_id); |
| 7260 | |
| 7261 | // If code is undefined, then existing code won't be overwritten. |
| 7262 | static void AddToOptimizedCodeMapInternal(Handle<SharedFunctionInfo> shared, |
| 7263 | Handle<Context> native_context, |
| 7264 | Handle<HeapObject> code, |
| 7265 | Handle<LiteralsArray> literals, |
| 7266 | BailoutId osr_ast_id); |
| 7267 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7268 | DISALLOW_IMPLICIT_CONSTRUCTORS(SharedFunctionInfo); |
| 7269 | }; |
| 7270 | |
| 7271 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7272 | // Printing support. |
| 7273 | struct SourceCodeOf { |
| 7274 | explicit SourceCodeOf(SharedFunctionInfo* v, int max = -1) |
| 7275 | : value(v), max_length(max) {} |
| 7276 | const SharedFunctionInfo* value; |
| 7277 | int max_length; |
| 7278 | }; |
| 7279 | |
| 7280 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 7281 | std::ostream& operator<<(std::ostream& os, const SourceCodeOf& v); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7282 | |
| 7283 | |
| 7284 | class JSGeneratorObject: public JSObject { |
| 7285 | public: |
| 7286 | // [function]: The function corresponding to this generator object. |
| 7287 | DECL_ACCESSORS(function, JSFunction) |
| 7288 | |
| 7289 | // [context]: The context of the suspended computation. |
| 7290 | DECL_ACCESSORS(context, Context) |
| 7291 | |
| 7292 | // [receiver]: The receiver of the suspended computation. |
| 7293 | DECL_ACCESSORS(receiver, Object) |
| 7294 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 7295 | // [input]: The most recent input value. |
| 7296 | DECL_ACCESSORS(input, Object) |
| 7297 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7298 | // [continuation]: Offset into code of continuation. |
| 7299 | // |
| 7300 | // A positive offset indicates a suspended generator. The special |
| 7301 | // kGeneratorExecuting and kGeneratorClosed values indicate that a generator |
| 7302 | // cannot be resumed. |
| 7303 | inline int continuation() const; |
| 7304 | inline void set_continuation(int continuation); |
| 7305 | inline bool is_closed(); |
| 7306 | inline bool is_executing(); |
| 7307 | inline bool is_suspended(); |
| 7308 | |
| 7309 | // [operand_stack]: Saved operand stack. |
| 7310 | DECL_ACCESSORS(operand_stack, FixedArray) |
| 7311 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7312 | DECLARE_CAST(JSGeneratorObject) |
| 7313 | |
| 7314 | // Dispatched behavior. |
| 7315 | DECLARE_PRINTER(JSGeneratorObject) |
| 7316 | DECLARE_VERIFIER(JSGeneratorObject) |
| 7317 | |
| 7318 | // Magic sentinel values for the continuation. |
| 7319 | static const int kGeneratorExecuting = -1; |
| 7320 | static const int kGeneratorClosed = 0; |
| 7321 | |
| 7322 | // Layout description. |
| 7323 | static const int kFunctionOffset = JSObject::kHeaderSize; |
| 7324 | static const int kContextOffset = kFunctionOffset + kPointerSize; |
| 7325 | static const int kReceiverOffset = kContextOffset + kPointerSize; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 7326 | static const int kInputOffset = kReceiverOffset + kPointerSize; |
| 7327 | static const int kContinuationOffset = kInputOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7328 | static const int kOperandStackOffset = kContinuationOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7329 | static const int kSize = kOperandStackOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7330 | |
| 7331 | // Resume mode, for use by runtime functions. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 7332 | enum ResumeMode { NEXT, RETURN, THROW }; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7333 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7334 | private: |
| 7335 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGeneratorObject); |
| 7336 | }; |
| 7337 | |
| 7338 | |
| 7339 | // Representation for module instance objects. |
| 7340 | class JSModule: public JSObject { |
| 7341 | public: |
| 7342 | // [context]: the context holding the module's locals, or undefined if none. |
| 7343 | DECL_ACCESSORS(context, Object) |
| 7344 | |
| 7345 | // [scope_info]: Scope info. |
| 7346 | DECL_ACCESSORS(scope_info, ScopeInfo) |
| 7347 | |
| 7348 | DECLARE_CAST(JSModule) |
| 7349 | |
| 7350 | // Dispatched behavior. |
| 7351 | DECLARE_PRINTER(JSModule) |
| 7352 | DECLARE_VERIFIER(JSModule) |
| 7353 | |
| 7354 | // Layout description. |
| 7355 | static const int kContextOffset = JSObject::kHeaderSize; |
| 7356 | static const int kScopeInfoOffset = kContextOffset + kPointerSize; |
| 7357 | static const int kSize = kScopeInfoOffset + kPointerSize; |
| 7358 | |
| 7359 | private: |
| 7360 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSModule); |
| 7361 | }; |
| 7362 | |
| 7363 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7364 | // JSBoundFunction describes a bound function exotic object. |
| 7365 | class JSBoundFunction : public JSObject { |
| 7366 | public: |
| 7367 | // [length]: The bound function "length" property. |
| 7368 | DECL_ACCESSORS(length, Object) |
| 7369 | |
| 7370 | // [name]: The bound function "name" property. |
| 7371 | DECL_ACCESSORS(name, Object) |
| 7372 | |
| 7373 | // [bound_target_function]: The wrapped function object. |
| 7374 | DECL_ACCESSORS(bound_target_function, JSReceiver) |
| 7375 | |
| 7376 | // [bound_this]: The value that is always passed as the this value when |
| 7377 | // calling the wrapped function. |
| 7378 | DECL_ACCESSORS(bound_this, Object) |
| 7379 | |
| 7380 | // [bound_arguments]: A list of values whose elements are used as the first |
| 7381 | // arguments to any call to the wrapped function. |
| 7382 | DECL_ACCESSORS(bound_arguments, FixedArray) |
| 7383 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7384 | static MaybeHandle<Context> GetFunctionRealm( |
| 7385 | Handle<JSBoundFunction> function); |
| 7386 | |
| 7387 | DECLARE_CAST(JSBoundFunction) |
| 7388 | |
| 7389 | // Dispatched behavior. |
| 7390 | DECLARE_PRINTER(JSBoundFunction) |
| 7391 | DECLARE_VERIFIER(JSBoundFunction) |
| 7392 | |
| 7393 | // The bound function's string representation implemented according |
| 7394 | // to ES6 section 19.2.3.5 Function.prototype.toString ( ). |
| 7395 | static Handle<String> ToString(Handle<JSBoundFunction> function); |
| 7396 | |
| 7397 | // Layout description. |
| 7398 | static const int kBoundTargetFunctionOffset = JSObject::kHeaderSize; |
| 7399 | static const int kBoundThisOffset = kBoundTargetFunctionOffset + kPointerSize; |
| 7400 | static const int kBoundArgumentsOffset = kBoundThisOffset + kPointerSize; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 7401 | static const int kLengthOffset = kBoundArgumentsOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7402 | static const int kNameOffset = kLengthOffset + kPointerSize; |
| 7403 | static const int kSize = kNameOffset + kPointerSize; |
| 7404 | |
| 7405 | // Indices of in-object properties. |
| 7406 | static const int kLengthIndex = 0; |
| 7407 | static const int kNameIndex = 1; |
| 7408 | |
| 7409 | private: |
| 7410 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSBoundFunction); |
| 7411 | }; |
| 7412 | |
| 7413 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7414 | // JSFunction describes JavaScript functions. |
| 7415 | class JSFunction: public JSObject { |
| 7416 | public: |
| 7417 | // [prototype_or_initial_map]: |
| 7418 | DECL_ACCESSORS(prototype_or_initial_map, Object) |
| 7419 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 7420 | // [shared]: The information about the function that |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7421 | // can be shared by instances. |
| 7422 | DECL_ACCESSORS(shared, SharedFunctionInfo) |
| 7423 | |
| 7424 | // [context]: The context for this function. |
| 7425 | inline Context* context(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7426 | inline void set_context(Object* context); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7427 | inline JSObject* global_proxy(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7428 | inline Context* native_context(); |
| 7429 | |
| 7430 | static Handle<Context> GetFunctionRealm(Handle<JSFunction> function); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7431 | |
| 7432 | // [code]: The generated code object for this function. Executed |
| 7433 | // when the function is invoked, e.g. foo() or new foo(). See |
| 7434 | // [[Call]] and [[Construct]] description in ECMA-262, section |
| 7435 | // 8.6.2, page 27. |
| 7436 | inline Code* code(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7437 | inline void set_code(Code* code); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7438 | inline void set_code_no_write_barrier(Code* code); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7439 | inline void ReplaceCode(Code* code); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7440 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7441 | // Tells whether this function inlines the given shared function info. |
| 7442 | bool Inlines(SharedFunctionInfo* candidate); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7443 | |
| 7444 | // Tells whether or not this function has been optimized. |
| 7445 | inline bool IsOptimized(); |
| 7446 | |
| 7447 | // Mark this function for lazy recompilation. The function will be |
| 7448 | // recompiled the next time it is executed. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7449 | void MarkForOptimization(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 7450 | void AttemptConcurrentOptimization(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7451 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7452 | // Tells whether or not the function is already marked for lazy |
| 7453 | // recompilation. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7454 | inline bool IsMarkedForOptimization(); |
| 7455 | inline bool IsMarkedForConcurrentOptimization(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7456 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7457 | // Tells whether or not the function is on the concurrent recompilation queue. |
| 7458 | inline bool IsInOptimizationQueue(); |
| 7459 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7460 | // Completes inobject slack tracking on initial map if it is active. |
| 7461 | inline void CompleteInobjectSlackTrackingIfActive(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7462 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7463 | // [literals]: Fixed array holding the materialized literals. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7464 | // |
| 7465 | // If the function contains object, regexp or array literals, the |
| 7466 | // literals array prefix contains the object, regexp, and array |
| 7467 | // function to be used when creating these literals. This is |
| 7468 | // necessary so that we do not dynamically lookup the object, regexp |
| 7469 | // or array functions. Performing a dynamic lookup, we might end up |
| 7470 | // using the functions from a new context that we should not have |
| 7471 | // access to. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7472 | DECL_ACCESSORS(literals, LiteralsArray) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7473 | |
| 7474 | // The initial map for an object created by this constructor. |
| 7475 | inline Map* initial_map(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7476 | static void SetInitialMap(Handle<JSFunction> function, Handle<Map> map, |
| 7477 | Handle<Object> prototype); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7478 | inline bool has_initial_map(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7479 | static void EnsureHasInitialMap(Handle<JSFunction> function); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7480 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7481 | // Creates a map that matches the constructor's initial map, but with |
| 7482 | // [[prototype]] being new.target.prototype. Because new.target can be a |
| 7483 | // JSProxy, this can call back into JavaScript. |
| 7484 | static MUST_USE_RESULT MaybeHandle<Map> GetDerivedMap( |
| 7485 | Isolate* isolate, Handle<JSFunction> constructor, |
| 7486 | Handle<JSReceiver> new_target); |
| 7487 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7488 | // Get and set the prototype property on a JSFunction. If the |
| 7489 | // function has an initial map the prototype is set on the initial |
| 7490 | // map. Otherwise, the prototype is put in the initial map field |
| 7491 | // until an initial map is needed. |
| 7492 | inline bool has_prototype(); |
| 7493 | inline bool has_instance_prototype(); |
| 7494 | inline Object* prototype(); |
| 7495 | inline Object* instance_prototype(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7496 | static void SetPrototype(Handle<JSFunction> function, |
| 7497 | Handle<Object> value); |
| 7498 | static void SetInstancePrototype(Handle<JSFunction> function, |
| 7499 | Handle<Object> value); |
| 7500 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 7501 | // After prototype is removed, it will not be created when accessed, and |
| 7502 | // [[Construct]] from this function will not be allowed. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7503 | bool RemovePrototype(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7504 | |
| 7505 | // Returns if this function has been compiled to native code yet. |
| 7506 | inline bool is_compiled(); |
| 7507 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7508 | // [next_function_link]: Links functions into various lists, e.g. the list |
| 7509 | // of optimized functions hanging off the native_context. The CodeFlusher |
| 7510 | // uses this link to chain together flushing candidates. Treated weakly |
| 7511 | // by the garbage collector. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7512 | DECL_ACCESSORS(next_function_link, Object) |
| 7513 | |
| 7514 | // Prints the name of the function using PrintF. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7515 | void PrintName(FILE* out = stdout); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7516 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7517 | DECLARE_CAST(JSFunction) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7518 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7519 | // Calculate the instance size and in-object properties count. |
| 7520 | void CalculateInstanceSize(InstanceType instance_type, |
| 7521 | int requested_internal_fields, int* instance_size, |
| 7522 | int* in_object_properties); |
| 7523 | void CalculateInstanceSizeForDerivedClass(InstanceType instance_type, |
| 7524 | int requested_internal_fields, |
| 7525 | int* instance_size, |
| 7526 | int* in_object_properties); |
| 7527 | |
| 7528 | // Visiting policy flags define whether the code entry or next function |
| 7529 | // should be visited or not. |
| 7530 | enum BodyVisitingPolicy { |
| 7531 | kVisitCodeEntry = 1 << 0, |
| 7532 | kVisitNextFunction = 1 << 1, |
| 7533 | |
| 7534 | kSkipCodeEntryAndNextFunction = 0, |
| 7535 | kVisitCodeEntryAndNextFunction = kVisitCodeEntry | kVisitNextFunction |
| 7536 | }; |
| 7537 | // Iterates the function object according to the visiting policy. |
| 7538 | template <BodyVisitingPolicy> |
| 7539 | class BodyDescriptorImpl; |
| 7540 | |
| 7541 | // Visit the whole object. |
| 7542 | typedef BodyDescriptorImpl<kVisitCodeEntryAndNextFunction> BodyDescriptor; |
| 7543 | |
| 7544 | // Don't visit next function. |
| 7545 | typedef BodyDescriptorImpl<kVisitCodeEntry> BodyDescriptorStrongCode; |
| 7546 | typedef BodyDescriptorImpl<kSkipCodeEntryAndNextFunction> |
| 7547 | BodyDescriptorWeakCode; |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 7548 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7549 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7550 | DECLARE_PRINTER(JSFunction) |
| 7551 | DECLARE_VERIFIER(JSFunction) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7552 | |
| 7553 | // Returns the number of allocated literals. |
| 7554 | inline int NumberOfLiterals(); |
| 7555 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7556 | // Used for flags such as --hydrogen-filter. |
| 7557 | bool PassesFilter(const char* raw_filter); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7558 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7559 | // The function's name if it is configured, otherwise shared function info |
| 7560 | // debug name. |
| 7561 | static Handle<String> GetName(Handle<JSFunction> function); |
| 7562 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 7563 | // ES6 section 9.2.11 SetFunctionName |
| 7564 | // Because of the way this abstract operation is used in the spec, |
| 7565 | // it should never fail. |
| 7566 | static void SetName(Handle<JSFunction> function, Handle<Name> name, |
| 7567 | Handle<String> prefix); |
| 7568 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7569 | // The function's displayName if it is set, otherwise name if it is |
| 7570 | // configured, otherwise shared function info |
| 7571 | // debug name. |
| 7572 | static Handle<String> GetDebugName(Handle<JSFunction> function); |
| 7573 | |
| 7574 | // The function's string representation implemented according to |
| 7575 | // ES6 section 19.2.3.5 Function.prototype.toString ( ). |
| 7576 | static Handle<String> ToString(Handle<JSFunction> function); |
| 7577 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7578 | // Layout descriptors. The last property (from kNonWeakFieldsEndOffset to |
| 7579 | // kSize) is weak and has special handling during garbage collection. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7580 | static const int kPrototypeOrInitialMapOffset = JSObject::kHeaderSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7581 | static const int kSharedFunctionInfoOffset = |
| 7582 | kPrototypeOrInitialMapOffset + kPointerSize; |
| 7583 | static const int kContextOffset = kSharedFunctionInfoOffset + kPointerSize; |
| 7584 | static const int kLiteralsOffset = kContextOffset + kPointerSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7585 | static const int kNonWeakFieldsEndOffset = kLiteralsOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7586 | static const int kCodeEntryOffset = kNonWeakFieldsEndOffset; |
| 7587 | static const int kNextFunctionLinkOffset = kCodeEntryOffset + kPointerSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7588 | static const int kSize = kNextFunctionLinkOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7589 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7590 | private: |
| 7591 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunction); |
| 7592 | }; |
| 7593 | |
| 7594 | |
| 7595 | // JSGlobalProxy's prototype must be a JSGlobalObject or null, |
| 7596 | // and the prototype is hidden. JSGlobalProxy always delegates |
| 7597 | // property accesses to its prototype if the prototype is not null. |
| 7598 | // |
| 7599 | // A JSGlobalProxy can be reinitialized which will preserve its identity. |
| 7600 | // |
| 7601 | // Accessing a JSGlobalProxy requires security check. |
| 7602 | |
| 7603 | class JSGlobalProxy : public JSObject { |
| 7604 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7605 | // [native_context]: the owner native context of this global proxy object. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7606 | // 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] | 7607 | DECL_ACCESSORS(native_context, Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7608 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7609 | // [hash]: The hash code property (undefined if not initialized yet). |
| 7610 | DECL_ACCESSORS(hash, Object) |
| 7611 | |
| 7612 | DECLARE_CAST(JSGlobalProxy) |
| 7613 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7614 | inline bool IsDetachedFrom(JSGlobalObject* global) const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7615 | |
| 7616 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7617 | DECLARE_PRINTER(JSGlobalProxy) |
| 7618 | DECLARE_VERIFIER(JSGlobalProxy) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7619 | |
| 7620 | // Layout description. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7621 | static const int kNativeContextOffset = JSObject::kHeaderSize; |
| 7622 | static const int kHashOffset = kNativeContextOffset + kPointerSize; |
| 7623 | static const int kSize = kHashOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7624 | |
| 7625 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7626 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalProxy); |
| 7627 | }; |
| 7628 | |
| 7629 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7630 | // JavaScript global object. |
| 7631 | class JSGlobalObject : public JSObject { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7632 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7633 | // [native context]: the natives corresponding to this global object. |
| 7634 | DECL_ACCESSORS(native_context, Context) |
| 7635 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7636 | // [global proxy]: the global proxy object of the context |
| 7637 | DECL_ACCESSORS(global_proxy, JSObject) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7638 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7639 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7640 | static void InvalidatePropertyCell(Handle<JSGlobalObject> object, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 7641 | Handle<Name> name); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7642 | // Ensure that the global object has a cell for the given property name. |
| 7643 | static Handle<PropertyCell> EnsurePropertyCell(Handle<JSGlobalObject> global, |
| 7644 | Handle<Name> name); |
| 7645 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7646 | DECLARE_CAST(JSGlobalObject) |
| 7647 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7648 | inline bool IsDetached(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7649 | |
| 7650 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7651 | DECLARE_PRINTER(JSGlobalObject) |
| 7652 | DECLARE_VERIFIER(JSGlobalObject) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7653 | |
| 7654 | // Layout description. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7655 | static const int kNativeContextOffset = JSObject::kHeaderSize; |
| 7656 | static const int kGlobalProxyOffset = kNativeContextOffset + kPointerSize; |
| 7657 | static const int kHeaderSize = kGlobalProxyOffset + kPointerSize; |
| 7658 | static const int kSize = kHeaderSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7659 | |
| 7660 | private: |
| 7661 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalObject); |
| 7662 | }; |
| 7663 | |
| 7664 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7665 | // Representation for JS Wrapper objects, String, Number, Boolean, etc. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7666 | class JSValue: public JSObject { |
| 7667 | public: |
| 7668 | // [value]: the object being wrapped. |
| 7669 | DECL_ACCESSORS(value, Object) |
| 7670 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7671 | DECLARE_CAST(JSValue) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7672 | |
| 7673 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7674 | DECLARE_PRINTER(JSValue) |
| 7675 | DECLARE_VERIFIER(JSValue) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7676 | |
| 7677 | // Layout description. |
| 7678 | static const int kValueOffset = JSObject::kHeaderSize; |
| 7679 | static const int kSize = kValueOffset + kPointerSize; |
| 7680 | |
| 7681 | private: |
| 7682 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSValue); |
| 7683 | }; |
| 7684 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 7685 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7686 | class DateCache; |
| 7687 | |
| 7688 | // Representation for JS date objects. |
| 7689 | class JSDate: public JSObject { |
| 7690 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7691 | static MUST_USE_RESULT MaybeHandle<JSDate> New(Handle<JSFunction> constructor, |
| 7692 | Handle<JSReceiver> new_target, |
| 7693 | double tv); |
| 7694 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7695 | // If one component is NaN, all of them are, indicating a NaN time value. |
| 7696 | // [value]: the time value. |
| 7697 | DECL_ACCESSORS(value, Object) |
| 7698 | // [year]: caches year. Either undefined, smi, or NaN. |
| 7699 | DECL_ACCESSORS(year, Object) |
| 7700 | // [month]: caches month. Either undefined, smi, or NaN. |
| 7701 | DECL_ACCESSORS(month, Object) |
| 7702 | // [day]: caches day. Either undefined, smi, or NaN. |
| 7703 | DECL_ACCESSORS(day, Object) |
| 7704 | // [weekday]: caches day of week. Either undefined, smi, or NaN. |
| 7705 | DECL_ACCESSORS(weekday, Object) |
| 7706 | // [hour]: caches hours. Either undefined, smi, or NaN. |
| 7707 | DECL_ACCESSORS(hour, Object) |
| 7708 | // [min]: caches minutes. Either undefined, smi, or NaN. |
| 7709 | DECL_ACCESSORS(min, Object) |
| 7710 | // [sec]: caches seconds. Either undefined, smi, or NaN. |
| 7711 | DECL_ACCESSORS(sec, Object) |
| 7712 | // [cache stamp]: sample of the date cache stamp at the |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7713 | // moment when chached fields were cached. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7714 | DECL_ACCESSORS(cache_stamp, Object) |
| 7715 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7716 | DECLARE_CAST(JSDate) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7717 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7718 | // Returns the time value (UTC) identifying the current time. |
| 7719 | static double CurrentTimeValue(Isolate* isolate); |
| 7720 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7721 | // Returns the date field with the specified index. |
| 7722 | // See FieldIndex for the list of date fields. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7723 | static Object* GetField(Object* date, Smi* index); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7724 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7725 | static Handle<Object> SetValue(Handle<JSDate> date, double v); |
| 7726 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7727 | void SetValue(Object* value, bool is_value_nan); |
| 7728 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7729 | // ES6 section 20.3.4.45 Date.prototype [ @@toPrimitive ] |
| 7730 | static MUST_USE_RESULT MaybeHandle<Object> ToPrimitive( |
| 7731 | Handle<JSReceiver> receiver, Handle<Object> hint); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7732 | |
| 7733 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7734 | DECLARE_PRINTER(JSDate) |
| 7735 | DECLARE_VERIFIER(JSDate) |
| 7736 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7737 | // The order is important. It must be kept in sync with date macros |
| 7738 | // in macros.py. |
| 7739 | enum FieldIndex { |
| 7740 | kDateValue, |
| 7741 | kYear, |
| 7742 | kMonth, |
| 7743 | kDay, |
| 7744 | kWeekday, |
| 7745 | kHour, |
| 7746 | kMinute, |
| 7747 | kSecond, |
| 7748 | kFirstUncachedField, |
| 7749 | kMillisecond = kFirstUncachedField, |
| 7750 | kDays, |
| 7751 | kTimeInDay, |
| 7752 | kFirstUTCField, |
| 7753 | kYearUTC = kFirstUTCField, |
| 7754 | kMonthUTC, |
| 7755 | kDayUTC, |
| 7756 | kWeekdayUTC, |
| 7757 | kHourUTC, |
| 7758 | kMinuteUTC, |
| 7759 | kSecondUTC, |
| 7760 | kMillisecondUTC, |
| 7761 | kDaysUTC, |
| 7762 | kTimeInDayUTC, |
| 7763 | kTimezoneOffset |
| 7764 | }; |
| 7765 | |
| 7766 | // Layout description. |
| 7767 | static const int kValueOffset = JSObject::kHeaderSize; |
| 7768 | static const int kYearOffset = kValueOffset + kPointerSize; |
| 7769 | static const int kMonthOffset = kYearOffset + kPointerSize; |
| 7770 | static const int kDayOffset = kMonthOffset + kPointerSize; |
| 7771 | static const int kWeekdayOffset = kDayOffset + kPointerSize; |
| 7772 | static const int kHourOffset = kWeekdayOffset + kPointerSize; |
| 7773 | static const int kMinOffset = kHourOffset + kPointerSize; |
| 7774 | static const int kSecOffset = kMinOffset + kPointerSize; |
| 7775 | static const int kCacheStampOffset = kSecOffset + kPointerSize; |
| 7776 | static const int kSize = kCacheStampOffset + kPointerSize; |
| 7777 | |
| 7778 | private: |
| 7779 | inline Object* DoGetField(FieldIndex index); |
| 7780 | |
| 7781 | Object* GetUTCField(FieldIndex index, double value, DateCache* date_cache); |
| 7782 | |
| 7783 | // Computes and caches the cacheable fields of the date. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7784 | inline void SetCachedFields(int64_t local_time_ms, DateCache* date_cache); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 7785 | |
| 7786 | |
| 7787 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSDate); |
| 7788 | }; |
| 7789 | |
| 7790 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 7791 | // Representation of message objects used for error reporting through |
| 7792 | // the API. The messages are formatted in JavaScript so this object is |
| 7793 | // a real JavaScript object. The information used for formatting the |
| 7794 | // error messages are not directly accessible from JavaScript to |
| 7795 | // prevent leaking information to user code called during error |
| 7796 | // formatting. |
| 7797 | class JSMessageObject: public JSObject { |
| 7798 | public: |
| 7799 | // [type]: the type of error message. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7800 | inline int type() const; |
| 7801 | inline void set_type(int value); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 7802 | |
| 7803 | // [arguments]: the arguments for formatting the error message. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7804 | DECL_ACCESSORS(argument, Object) |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 7805 | |
| 7806 | // [script]: the script from which the error message originated. |
| 7807 | DECL_ACCESSORS(script, Object) |
| 7808 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 7809 | // [stack_frames]: an array of stack frames for this error object. |
| 7810 | DECL_ACCESSORS(stack_frames, Object) |
| 7811 | |
| 7812 | // [start_position]: the start position in the script for the error message. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7813 | inline int start_position() const; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 7814 | inline void set_start_position(int value); |
| 7815 | |
| 7816 | // [end_position]: the end position in the script for the error message. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7817 | inline int end_position() const; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 7818 | inline void set_end_position(int value); |
| 7819 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7820 | DECLARE_CAST(JSMessageObject) |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 7821 | |
| 7822 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7823 | DECLARE_PRINTER(JSMessageObject) |
| 7824 | DECLARE_VERIFIER(JSMessageObject) |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 7825 | |
| 7826 | // Layout description. |
| 7827 | static const int kTypeOffset = JSObject::kHeaderSize; |
| 7828 | static const int kArgumentsOffset = kTypeOffset + kPointerSize; |
| 7829 | static const int kScriptOffset = kArgumentsOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7830 | static const int kStackFramesOffset = kScriptOffset + kPointerSize; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 7831 | static const int kStartPositionOffset = kStackFramesOffset + kPointerSize; |
| 7832 | static const int kEndPositionOffset = kStartPositionOffset + kPointerSize; |
| 7833 | static const int kSize = kEndPositionOffset + kPointerSize; |
| 7834 | |
| 7835 | typedef FixedBodyDescriptor<HeapObject::kMapOffset, |
| 7836 | kStackFramesOffset + kPointerSize, |
| 7837 | kSize> BodyDescriptor; |
| 7838 | }; |
| 7839 | |
| 7840 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7841 | // Regular expressions |
| 7842 | // The regular expression holds a single reference to a FixedArray in |
| 7843 | // the kDataOffset field. |
| 7844 | // The FixedArray contains the following data: |
| 7845 | // - tag : type of regexp implementation (not compiled yet, atom or irregexp) |
| 7846 | // - reference to the original source string |
| 7847 | // - reference to the original flag string |
| 7848 | // If it is an atom regexp |
| 7849 | // - a reference to a literal string to search for |
| 7850 | // If it is an irregexp regexp: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7851 | // - 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] | 7852 | // used for tracking the last usage (used for code flushing). |
| 7853 | // - a reference to code for UC16 inputs (bytecode or compiled), or a smi |
| 7854 | // used for tracking the last usage (used for code flushing).. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7855 | // - max number of registers used by irregexp implementations. |
| 7856 | // - number of capture registers (output values) of the regexp. |
| 7857 | class JSRegExp: public JSObject { |
| 7858 | public: |
| 7859 | // Meaning of Type: |
| 7860 | // NOT_COMPILED: Initial value. No data has been stored in the JSRegExp yet. |
| 7861 | // ATOM: A simple string to match against using an indexOf operation. |
| 7862 | // IRREGEXP: Compiled with Irregexp. |
| 7863 | // IRREGEXP_NATIVE: Compiled to native code with Irregexp. |
| 7864 | enum Type { NOT_COMPILED, ATOM, IRREGEXP }; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7865 | enum Flag { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7866 | kNone = 0, |
| 7867 | kGlobal = 1 << 0, |
| 7868 | kIgnoreCase = 1 << 1, |
| 7869 | kMultiline = 1 << 2, |
| 7870 | kSticky = 1 << 3, |
| 7871 | kUnicode = 1 << 4, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7872 | }; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7873 | typedef base::Flags<Flag> Flags; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7874 | |
| 7875 | DECL_ACCESSORS(data, Object) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7876 | DECL_ACCESSORS(flags, Object) |
| 7877 | DECL_ACCESSORS(source, Object) |
| 7878 | |
| 7879 | static MaybeHandle<JSRegExp> New(Handle<String> source, Flags flags); |
| 7880 | static MaybeHandle<JSRegExp> New(Handle<String> source, Handle<String> flags); |
| 7881 | static Handle<JSRegExp> Copy(Handle<JSRegExp> regexp); |
| 7882 | |
| 7883 | static MaybeHandle<JSRegExp> Initialize(Handle<JSRegExp> regexp, |
| 7884 | Handle<String> source, Flags flags); |
| 7885 | static MaybeHandle<JSRegExp> Initialize(Handle<JSRegExp> regexp, |
| 7886 | Handle<String> source, |
| 7887 | Handle<String> flags_string); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7888 | |
| 7889 | inline Type TypeTag(); |
| 7890 | inline int CaptureCount(); |
| 7891 | inline Flags GetFlags(); |
| 7892 | inline String* Pattern(); |
| 7893 | inline Object* DataAt(int index); |
| 7894 | // Set implementation data after the object has been prepared. |
| 7895 | inline void SetDataAt(int index, Object* value); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7896 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7897 | static int code_index(bool is_latin1) { |
| 7898 | if (is_latin1) { |
| 7899 | return kIrregexpLatin1CodeIndex; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7900 | } else { |
| 7901 | return kIrregexpUC16CodeIndex; |
| 7902 | } |
| 7903 | } |
| 7904 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7905 | static int saved_code_index(bool is_latin1) { |
| 7906 | if (is_latin1) { |
| 7907 | return kIrregexpLatin1CodeSavedIndex; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7908 | } else { |
| 7909 | return kIrregexpUC16CodeSavedIndex; |
| 7910 | } |
| 7911 | } |
| 7912 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7913 | DECLARE_CAST(JSRegExp) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7914 | |
| 7915 | // Dispatched behavior. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7916 | DECLARE_PRINTER(JSRegExp) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7917 | DECLARE_VERIFIER(JSRegExp) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7918 | |
| 7919 | static const int kDataOffset = JSObject::kHeaderSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7920 | static const int kSourceOffset = kDataOffset + kPointerSize; |
| 7921 | static const int kFlagsOffset = kSourceOffset + kPointerSize; |
| 7922 | static const int kSize = kFlagsOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7923 | |
| 7924 | // Indices in the data array. |
| 7925 | static const int kTagIndex = 0; |
| 7926 | static const int kSourceIndex = kTagIndex + 1; |
| 7927 | static const int kFlagsIndex = kSourceIndex + 1; |
| 7928 | static const int kDataIndex = kFlagsIndex + 1; |
| 7929 | // The data fields are used in different ways depending on the |
| 7930 | // value of the tag. |
| 7931 | // Atom regexps (literal strings). |
| 7932 | static const int kAtomPatternIndex = kDataIndex; |
| 7933 | |
| 7934 | static const int kAtomDataSize = kAtomPatternIndex + 1; |
| 7935 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7936 | // Irregexp compiled code or bytecode for Latin1. If compilation |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7937 | // fails, this fields hold an exception object that should be |
| 7938 | // thrown if the regexp is used again. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7939 | static const int kIrregexpLatin1CodeIndex = kDataIndex; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7940 | // Irregexp compiled code or bytecode for UC16. If compilation |
| 7941 | // fails, this fields hold an exception object that should be |
| 7942 | // thrown if the regexp is used again. |
| 7943 | static const int kIrregexpUC16CodeIndex = kDataIndex + 1; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7944 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7945 | // Saved instance of Irregexp compiled code or bytecode for Latin1 that |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7946 | // is a potential candidate for flushing. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7947 | static const int kIrregexpLatin1CodeSavedIndex = kDataIndex + 2; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7948 | // Saved instance of Irregexp compiled code or bytecode for UC16 that is |
| 7949 | // a potential candidate for flushing. |
| 7950 | static const int kIrregexpUC16CodeSavedIndex = kDataIndex + 3; |
| 7951 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7952 | // Maximal number of registers used by either Latin1 or UC16. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7953 | // Only used to check that there is enough stack space |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7954 | static const int kIrregexpMaxRegisterCountIndex = kDataIndex + 4; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7955 | // Number of captures in the compiled regexp. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7956 | static const int kIrregexpCaptureCountIndex = kDataIndex + 5; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7957 | |
| 7958 | static const int kIrregexpDataSize = kIrregexpCaptureCountIndex + 1; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 7959 | |
| 7960 | // Offsets directly into the data fixed array. |
| 7961 | static const int kDataTagOffset = |
| 7962 | FixedArray::kHeaderSize + kTagIndex * kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7963 | static const int kDataOneByteCodeOffset = |
| 7964 | FixedArray::kHeaderSize + kIrregexpLatin1CodeIndex * kPointerSize; |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 7965 | static const int kDataUC16CodeOffset = |
| 7966 | FixedArray::kHeaderSize + kIrregexpUC16CodeIndex * kPointerSize; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 7967 | static const int kIrregexpCaptureCountOffset = |
| 7968 | FixedArray::kHeaderSize + kIrregexpCaptureCountIndex * kPointerSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 7969 | |
| 7970 | // In-object fields. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7971 | static const int kLastIndexFieldIndex = 0; |
| 7972 | static const int kInObjectFieldCount = 1; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7973 | |
| 7974 | // The uninitialized value for a regexp code object. |
| 7975 | static const int kUninitializedValue = -1; |
| 7976 | |
| 7977 | // The compilation error value for the regexp code object. The real error |
| 7978 | // object is in the saved code field. |
| 7979 | static const int kCompilationErrorValue = -2; |
| 7980 | |
| 7981 | // When we store the sweep generation at which we moved the code from the |
| 7982 | // code index to the saved code index we mask it of to be in the [0:255] |
| 7983 | // range. |
| 7984 | static const int kCodeAgeMask = 0xff; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7985 | }; |
| 7986 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7987 | DEFINE_OPERATORS_FOR_FLAGS(JSRegExp::Flags) |
| 7988 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7989 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 7990 | class CompilationCacheShape : public BaseShape<HashTableKey*> { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7991 | public: |
| 7992 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
| 7993 | return key->IsMatch(value); |
| 7994 | } |
| 7995 | |
| 7996 | static inline uint32_t Hash(HashTableKey* key) { |
| 7997 | return key->Hash(); |
| 7998 | } |
| 7999 | |
| 8000 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
| 8001 | return key->HashForObject(object); |
| 8002 | } |
| 8003 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8004 | static inline Handle<Object> AsHandle(Isolate* isolate, HashTableKey* key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8005 | |
| 8006 | static const int kPrefixSize = 0; |
| 8007 | static const int kEntrySize = 2; |
| 8008 | }; |
| 8009 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 8010 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8011 | // This cache is used in two different variants. For regexp caching, it simply |
| 8012 | // maps identifying info of the regexp to the cached regexp object. Scripts and |
| 8013 | // eval code only gets cached after a second probe for the code object. To do |
| 8014 | // so, on first "put" only a hash identifying the source is entered into the |
| 8015 | // cache, mapping it to a lifetime count of the hash. On each call to Age all |
| 8016 | // such lifetimes get reduced, and removed once they reach zero. If a second put |
| 8017 | // is called while such a hash is live in the cache, the hash gets replaced by |
| 8018 | // an actual cache entry. Age also removes stale live entries from the cache. |
| 8019 | // Such entries are identified by SharedFunctionInfos pointing to either the |
| 8020 | // recompilation stub, or to "old" code. This avoids memory leaks due to |
| 8021 | // premature caching of scripts and eval strings that are never needed later. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8022 | class CompilationCacheTable: public HashTable<CompilationCacheTable, |
| 8023 | CompilationCacheShape, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8024 | HashTableKey*> { |
| 8025 | public: |
| 8026 | // Find cached value for a string key, otherwise return null. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8027 | Handle<Object> Lookup( |
| 8028 | Handle<String> src, Handle<Context> context, LanguageMode language_mode); |
| 8029 | Handle<Object> LookupEval( |
| 8030 | Handle<String> src, Handle<SharedFunctionInfo> shared, |
| 8031 | LanguageMode language_mode, int scope_position); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8032 | Handle<Object> LookupRegExp(Handle<String> source, JSRegExp::Flags flags); |
| 8033 | static Handle<CompilationCacheTable> Put( |
| 8034 | Handle<CompilationCacheTable> cache, Handle<String> src, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8035 | Handle<Context> context, LanguageMode language_mode, |
| 8036 | Handle<Object> value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8037 | static Handle<CompilationCacheTable> PutEval( |
| 8038 | Handle<CompilationCacheTable> cache, Handle<String> src, |
| 8039 | Handle<SharedFunctionInfo> context, Handle<SharedFunctionInfo> value, |
| 8040 | int scope_position); |
| 8041 | static Handle<CompilationCacheTable> PutRegExp( |
| 8042 | Handle<CompilationCacheTable> cache, Handle<String> src, |
| 8043 | JSRegExp::Flags flags, Handle<FixedArray> value); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 8044 | void Remove(Object* value); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8045 | void Age(); |
| 8046 | static const int kHashGenerations = 10; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 8047 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8048 | DECLARE_CAST(CompilationCacheTable) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8049 | |
| 8050 | private: |
| 8051 | DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheTable); |
| 8052 | }; |
| 8053 | |
| 8054 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8055 | class CodeCache: public Struct { |
| 8056 | public: |
| 8057 | DECL_ACCESSORS(default_cache, FixedArray) |
| 8058 | DECL_ACCESSORS(normal_type_cache, Object) |
| 8059 | |
| 8060 | // Add the code object to the cache. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8061 | static void Update( |
| 8062 | Handle<CodeCache> cache, Handle<Name> name, Handle<Code> code); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8063 | |
| 8064 | // Lookup code object in the cache. Returns code object if found and undefined |
| 8065 | // if not. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8066 | Object* Lookup(Name* name, Code::Flags flags); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8067 | |
| 8068 | // Get the internal index of a code object in the cache. Returns -1 if the |
| 8069 | // code object is not in that cache. This index can be used to later call |
| 8070 | // RemoveByIndex. The cache cannot be modified between a call to GetIndex and |
| 8071 | // RemoveByIndex. |
| 8072 | int GetIndex(Object* name, Code* code); |
| 8073 | |
| 8074 | // Remove an object from the cache with the provided internal index. |
| 8075 | void RemoveByIndex(Object* name, Code* code, int index); |
| 8076 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8077 | DECLARE_CAST(CodeCache) |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8078 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8079 | // Dispatched behavior. |
| 8080 | DECLARE_PRINTER(CodeCache) |
| 8081 | DECLARE_VERIFIER(CodeCache) |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8082 | |
| 8083 | static const int kDefaultCacheOffset = HeapObject::kHeaderSize; |
| 8084 | static const int kNormalTypeCacheOffset = |
| 8085 | kDefaultCacheOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8086 | static const int kSize = kNormalTypeCacheOffset + kPointerSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8087 | |
| 8088 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8089 | static void UpdateDefaultCache( |
| 8090 | Handle<CodeCache> code_cache, Handle<Name> name, Handle<Code> code); |
| 8091 | static void UpdateNormalTypeCache( |
| 8092 | Handle<CodeCache> code_cache, Handle<Name> name, Handle<Code> code); |
| 8093 | Object* LookupDefaultCache(Name* name, Code::Flags flags); |
| 8094 | Object* LookupNormalTypeCache(Name* name, Code::Flags flags); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8095 | |
| 8096 | // Code cache layout of the default cache. Elements are alternating name and |
| 8097 | // code objects for non normal load/store/call IC's. |
| 8098 | static const int kCodeCacheEntrySize = 2; |
| 8099 | static const int kCodeCacheEntryNameOffset = 0; |
| 8100 | static const int kCodeCacheEntryCodeOffset = 1; |
| 8101 | |
| 8102 | DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCache); |
| 8103 | }; |
| 8104 | |
| 8105 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 8106 | class CodeCacheHashTableShape : public BaseShape<HashTableKey*> { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8107 | public: |
| 8108 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
| 8109 | return key->IsMatch(value); |
| 8110 | } |
| 8111 | |
| 8112 | static inline uint32_t Hash(HashTableKey* key) { |
| 8113 | return key->Hash(); |
| 8114 | } |
| 8115 | |
| 8116 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
| 8117 | return key->HashForObject(object); |
| 8118 | } |
| 8119 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8120 | static inline Handle<Object> AsHandle(Isolate* isolate, HashTableKey* key); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8121 | |
| 8122 | static const int kPrefixSize = 0; |
| 8123 | static const int kEntrySize = 2; |
| 8124 | }; |
| 8125 | |
| 8126 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8127 | class CodeCacheHashTable: public HashTable<CodeCacheHashTable, |
| 8128 | CodeCacheHashTableShape, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8129 | HashTableKey*> { |
| 8130 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8131 | Object* Lookup(Name* name, Code::Flags flags); |
| 8132 | static Handle<CodeCacheHashTable> Put( |
| 8133 | Handle<CodeCacheHashTable> table, |
| 8134 | Handle<Name> name, |
| 8135 | Handle<Code> code); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8136 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8137 | int GetIndex(Name* name, Code::Flags flags); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8138 | void RemoveByIndex(int index); |
| 8139 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8140 | DECLARE_CAST(CodeCacheHashTable) |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8141 | |
| 8142 | // Initial size of the fixed array backing the hash table. |
| 8143 | static const int kInitialSize = 64; |
| 8144 | |
| 8145 | private: |
| 8146 | DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCacheHashTable); |
| 8147 | }; |
| 8148 | |
| 8149 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 8150 | class PolymorphicCodeCache: public Struct { |
| 8151 | public: |
| 8152 | DECL_ACCESSORS(cache, Object) |
| 8153 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8154 | static void Update(Handle<PolymorphicCodeCache> cache, |
| 8155 | MapHandleList* maps, |
| 8156 | Code::Flags flags, |
| 8157 | Handle<Code> code); |
| 8158 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8159 | |
| 8160 | // Returns an undefined value if the entry is not found. |
| 8161 | Handle<Object> Lookup(MapHandleList* maps, Code::Flags flags); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 8162 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8163 | DECLARE_CAST(PolymorphicCodeCache) |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 8164 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8165 | // Dispatched behavior. |
| 8166 | DECLARE_PRINTER(PolymorphicCodeCache) |
| 8167 | DECLARE_VERIFIER(PolymorphicCodeCache) |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 8168 | |
| 8169 | static const int kCacheOffset = HeapObject::kHeaderSize; |
| 8170 | static const int kSize = kCacheOffset + kPointerSize; |
| 8171 | |
| 8172 | private: |
| 8173 | DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCache); |
| 8174 | }; |
| 8175 | |
| 8176 | |
| 8177 | class PolymorphicCodeCacheHashTable |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8178 | : public HashTable<PolymorphicCodeCacheHashTable, |
| 8179 | CodeCacheHashTableShape, |
| 8180 | HashTableKey*> { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 8181 | public: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8182 | Object* Lookup(MapHandleList* maps, int code_kind); |
| 8183 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8184 | static Handle<PolymorphicCodeCacheHashTable> Put( |
| 8185 | Handle<PolymorphicCodeCacheHashTable> hash_table, |
| 8186 | MapHandleList* maps, |
| 8187 | int code_kind, |
| 8188 | Handle<Code> code); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 8189 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8190 | DECLARE_CAST(PolymorphicCodeCacheHashTable) |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 8191 | |
| 8192 | static const int kInitialSize = 64; |
| 8193 | private: |
| 8194 | DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCacheHashTable); |
| 8195 | }; |
| 8196 | |
| 8197 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8198 | class TypeFeedbackInfo: public Struct { |
| 8199 | public: |
| 8200 | inline int ic_total_count(); |
| 8201 | inline void set_ic_total_count(int count); |
| 8202 | |
Ben Murdoch | 8f9999f | 2012-04-23 10:39:17 +0100 | [diff] [blame] | 8203 | inline int ic_with_type_info_count(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8204 | inline void change_ic_with_type_info_count(int delta); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8205 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8206 | inline int ic_generic_count(); |
| 8207 | inline void change_ic_generic_count(int delta); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8208 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8209 | inline void initialize_storage(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8210 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8211 | inline void change_own_type_change_checksum(); |
| 8212 | inline int own_type_change_checksum(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8213 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8214 | inline void set_inlined_type_change_checksum(int checksum); |
| 8215 | inline bool matches_inlined_type_change_checksum(int checksum); |
| 8216 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8217 | DECLARE_CAST(TypeFeedbackInfo) |
| 8218 | |
| 8219 | // Dispatched behavior. |
| 8220 | DECLARE_PRINTER(TypeFeedbackInfo) |
| 8221 | DECLARE_VERIFIER(TypeFeedbackInfo) |
| 8222 | |
| 8223 | static const int kStorage1Offset = HeapObject::kHeaderSize; |
| 8224 | static const int kStorage2Offset = kStorage1Offset + kPointerSize; |
| 8225 | static const int kStorage3Offset = kStorage2Offset + kPointerSize; |
| 8226 | static const int kSize = kStorage3Offset + kPointerSize; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8227 | |
| 8228 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8229 | static const int kTypeChangeChecksumBits = 7; |
| 8230 | |
| 8231 | class ICTotalCountField: public BitField<int, 0, |
| 8232 | kSmiValueSize - kTypeChangeChecksumBits> {}; // NOLINT |
| 8233 | class OwnTypeChangeChecksum: public BitField<int, |
| 8234 | kSmiValueSize - kTypeChangeChecksumBits, |
| 8235 | kTypeChangeChecksumBits> {}; // NOLINT |
| 8236 | class ICsWithTypeInfoCountField: public BitField<int, 0, |
| 8237 | kSmiValueSize - kTypeChangeChecksumBits> {}; // NOLINT |
| 8238 | class InlinedTypeChangeChecksum: public BitField<int, |
| 8239 | kSmiValueSize - kTypeChangeChecksumBits, |
| 8240 | kTypeChangeChecksumBits> {}; // NOLINT |
| 8241 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8242 | DISALLOW_IMPLICIT_CONSTRUCTORS(TypeFeedbackInfo); |
| 8243 | }; |
| 8244 | |
| 8245 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8246 | enum AllocationSiteMode { |
| 8247 | DONT_TRACK_ALLOCATION_SITE, |
| 8248 | TRACK_ALLOCATION_SITE, |
| 8249 | LAST_ALLOCATION_SITE_MODE = TRACK_ALLOCATION_SITE |
| 8250 | }; |
| 8251 | |
| 8252 | |
| 8253 | class AllocationSite: public Struct { |
| 8254 | public: |
| 8255 | static const uint32_t kMaximumArrayBytesToPretransition = 8 * 1024; |
| 8256 | static const double kPretenureRatio; |
| 8257 | static const int kPretenureMinimumCreated = 100; |
| 8258 | |
| 8259 | // Values for pretenure decision field. |
| 8260 | enum PretenureDecision { |
| 8261 | kUndecided = 0, |
| 8262 | kDontTenure = 1, |
| 8263 | kMaybeTenure = 2, |
| 8264 | kTenure = 3, |
| 8265 | kZombie = 4, |
| 8266 | kLastPretenureDecisionValue = kZombie |
| 8267 | }; |
| 8268 | |
| 8269 | const char* PretenureDecisionName(PretenureDecision decision); |
| 8270 | |
| 8271 | DECL_ACCESSORS(transition_info, Object) |
| 8272 | // nested_site threads a list of sites that represent nested literals |
| 8273 | // walked in a particular order. So [[1, 2], 1, 2] will have one |
| 8274 | // nested_site, but [[1, 2], 3, [4]] will have a list of two. |
| 8275 | DECL_ACCESSORS(nested_site, Object) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8276 | DECL_INT_ACCESSORS(pretenure_data) |
| 8277 | DECL_INT_ACCESSORS(pretenure_create_count) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8278 | DECL_ACCESSORS(dependent_code, DependentCode) |
| 8279 | DECL_ACCESSORS(weak_next, Object) |
| 8280 | |
| 8281 | inline void Initialize(); |
| 8282 | |
| 8283 | // This method is expensive, it should only be called for reporting. |
| 8284 | bool IsNestedSite(); |
| 8285 | |
| 8286 | // transition_info bitfields, for constructed array transition info. |
| 8287 | class ElementsKindBits: public BitField<ElementsKind, 0, 15> {}; |
| 8288 | class UnusedBits: public BitField<int, 15, 14> {}; |
| 8289 | class DoNotInlineBit: public BitField<bool, 29, 1> {}; |
| 8290 | |
| 8291 | // Bitfields for pretenure_data |
| 8292 | class MementoFoundCountBits: public BitField<int, 0, 26> {}; |
| 8293 | class PretenureDecisionBits: public BitField<PretenureDecision, 26, 3> {}; |
| 8294 | class DeoptDependentCodeBit: public BitField<bool, 29, 1> {}; |
| 8295 | STATIC_ASSERT(PretenureDecisionBits::kMax >= kLastPretenureDecisionValue); |
| 8296 | |
| 8297 | // Increments the mementos found counter and returns true when the first |
| 8298 | // memento was found for a given allocation site. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8299 | inline bool IncrementMementoFoundCount(int increment = 1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8300 | |
| 8301 | inline void IncrementMementoCreateCount(); |
| 8302 | |
| 8303 | PretenureFlag GetPretenureMode(); |
| 8304 | |
| 8305 | void ResetPretenureDecision(); |
| 8306 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8307 | inline PretenureDecision pretenure_decision(); |
| 8308 | inline void set_pretenure_decision(PretenureDecision decision); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8309 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8310 | inline bool deopt_dependent_code(); |
| 8311 | inline void set_deopt_dependent_code(bool deopt); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8312 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8313 | inline int memento_found_count(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8314 | inline void set_memento_found_count(int count); |
| 8315 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8316 | inline int memento_create_count(); |
| 8317 | inline void set_memento_create_count(int count); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8318 | |
| 8319 | // The pretenuring decision is made during gc, and the zombie state allows |
| 8320 | // us to recognize when an allocation site is just being kept alive because |
| 8321 | // a later traversal of new space may discover AllocationMementos that point |
| 8322 | // to this AllocationSite. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8323 | inline bool IsZombie(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8324 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8325 | inline bool IsMaybeTenure(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8326 | |
| 8327 | inline void MarkZombie(); |
| 8328 | |
| 8329 | inline bool MakePretenureDecision(PretenureDecision current_decision, |
| 8330 | double ratio, |
| 8331 | bool maximum_size_scavenge); |
| 8332 | |
| 8333 | inline bool DigestPretenuringFeedback(bool maximum_size_scavenge); |
| 8334 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8335 | inline ElementsKind GetElementsKind(); |
| 8336 | inline void SetElementsKind(ElementsKind kind); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8337 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8338 | inline bool CanInlineCall(); |
| 8339 | inline void SetDoNotInlineCall(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8340 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8341 | inline bool SitePointsToLiteral(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8342 | |
| 8343 | static void DigestTransitionFeedback(Handle<AllocationSite> site, |
| 8344 | ElementsKind to_kind); |
| 8345 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8346 | DECLARE_PRINTER(AllocationSite) |
| 8347 | DECLARE_VERIFIER(AllocationSite) |
| 8348 | |
| 8349 | DECLARE_CAST(AllocationSite) |
| 8350 | static inline AllocationSiteMode GetMode( |
| 8351 | ElementsKind boilerplate_elements_kind); |
| 8352 | static inline AllocationSiteMode GetMode(ElementsKind from, ElementsKind to); |
| 8353 | static inline bool CanTrack(InstanceType type); |
| 8354 | |
| 8355 | static const int kTransitionInfoOffset = HeapObject::kHeaderSize; |
| 8356 | static const int kNestedSiteOffset = kTransitionInfoOffset + kPointerSize; |
| 8357 | static const int kPretenureDataOffset = kNestedSiteOffset + kPointerSize; |
| 8358 | static const int kPretenureCreateCountOffset = |
| 8359 | kPretenureDataOffset + kPointerSize; |
| 8360 | static const int kDependentCodeOffset = |
| 8361 | kPretenureCreateCountOffset + kPointerSize; |
| 8362 | static const int kWeakNextOffset = kDependentCodeOffset + kPointerSize; |
| 8363 | static const int kSize = kWeakNextOffset + kPointerSize; |
| 8364 | |
| 8365 | // During mark compact we need to take special care for the dependent code |
| 8366 | // field. |
| 8367 | static const int kPointerFieldsBeginOffset = kTransitionInfoOffset; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8368 | static const int kPointerFieldsEndOffset = kWeakNextOffset; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8369 | |
| 8370 | // For other visitors, use the fixed body descriptor below. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 8371 | typedef FixedBodyDescriptor<HeapObject::kHeaderSize, kSize, kSize> |
| 8372 | BodyDescriptor; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8373 | |
| 8374 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8375 | inline bool PretenuringDecisionMade(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8376 | |
| 8377 | DISALLOW_IMPLICIT_CONSTRUCTORS(AllocationSite); |
| 8378 | }; |
| 8379 | |
| 8380 | |
| 8381 | class AllocationMemento: public Struct { |
| 8382 | public: |
| 8383 | static const int kAllocationSiteOffset = HeapObject::kHeaderSize; |
| 8384 | static const int kSize = kAllocationSiteOffset + kPointerSize; |
| 8385 | |
| 8386 | DECL_ACCESSORS(allocation_site, Object) |
| 8387 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8388 | inline bool IsValid(); |
| 8389 | inline AllocationSite* GetAllocationSite(); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 8390 | inline Address GetAllocationSiteUnchecked(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8391 | |
| 8392 | DECLARE_PRINTER(AllocationMemento) |
| 8393 | DECLARE_VERIFIER(AllocationMemento) |
| 8394 | |
| 8395 | DECLARE_CAST(AllocationMemento) |
| 8396 | |
| 8397 | private: |
| 8398 | DISALLOW_IMPLICIT_CONSTRUCTORS(AllocationMemento); |
| 8399 | }; |
| 8400 | |
| 8401 | |
| 8402 | // Representation of a slow alias as part of a sloppy arguments objects. |
| 8403 | // For fast aliases (if HasSloppyArgumentsElements()): |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8404 | // - the parameter map contains an index into the context |
| 8405 | // - all attributes of the element have default values |
| 8406 | // For slow aliases (if HasDictionaryArgumentsElements()): |
| 8407 | // - the parameter map contains no fast alias mapping (i.e. the hole) |
| 8408 | // - this struct (in the slow backing store) contains an index into the context |
| 8409 | // - all attributes are available as part if the property details |
| 8410 | class AliasedArgumentsEntry: public Struct { |
| 8411 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8412 | inline int aliased_context_slot() const; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8413 | inline void set_aliased_context_slot(int count); |
| 8414 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8415 | DECLARE_CAST(AliasedArgumentsEntry) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8416 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8417 | // Dispatched behavior. |
| 8418 | DECLARE_PRINTER(AliasedArgumentsEntry) |
| 8419 | DECLARE_VERIFIER(AliasedArgumentsEntry) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8420 | |
| 8421 | static const int kAliasedContextSlot = HeapObject::kHeaderSize; |
| 8422 | static const int kSize = kAliasedContextSlot + kPointerSize; |
| 8423 | |
| 8424 | private: |
| 8425 | DISALLOW_IMPLICIT_CONSTRUCTORS(AliasedArgumentsEntry); |
| 8426 | }; |
| 8427 | |
| 8428 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8429 | enum AllowNullsFlag {ALLOW_NULLS, DISALLOW_NULLS}; |
| 8430 | enum RobustnessFlag {ROBUST_STRING_TRAVERSAL, FAST_STRING_TRAVERSAL}; |
| 8431 | |
| 8432 | |
| 8433 | class StringHasher { |
| 8434 | public: |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 8435 | explicit inline StringHasher(int length, uint32_t seed); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8436 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8437 | template <typename schar> |
| 8438 | static inline uint32_t HashSequentialString(const schar* chars, |
| 8439 | int length, |
| 8440 | uint32_t seed); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8441 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8442 | // Reads all the data, even for long strings and computes the utf16 length. |
| 8443 | static uint32_t ComputeUtf8Hash(Vector<const char> chars, |
| 8444 | uint32_t seed, |
| 8445 | int* utf16_length_out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8446 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 8447 | // Calculated hash value for a string consisting of 1 to |
| 8448 | // String::kMaxArrayIndexSize digits with no leading zeros (except "0"). |
| 8449 | // value is represented decimal value. |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 8450 | static uint32_t MakeArrayIndexHash(uint32_t value, int length); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 8451 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 8452 | // No string is allowed to have a hash of zero. That value is reserved |
| 8453 | // for internal properties. If the hash calculation yields zero then we |
| 8454 | // use 27 instead. |
| 8455 | static const int kZeroHash = 27; |
| 8456 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8457 | // Reusable parts of the hashing algorithm. |
| 8458 | INLINE(static uint32_t AddCharacterCore(uint32_t running_hash, uint16_t c)); |
| 8459 | INLINE(static uint32_t GetHashCore(uint32_t running_hash)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8460 | INLINE(static uint32_t ComputeRunningHash(uint32_t running_hash, |
| 8461 | const uc16* chars, int length)); |
| 8462 | INLINE(static uint32_t ComputeRunningHashOneByte(uint32_t running_hash, |
| 8463 | const char* chars, |
| 8464 | int length)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8465 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8466 | protected: |
| 8467 | // Returns the value to store in the hash field of a string with |
| 8468 | // the given length and contents. |
| 8469 | uint32_t GetHashField(); |
| 8470 | // Returns true if the hash of this string can be computed without |
| 8471 | // looking at the contents. |
| 8472 | inline bool has_trivial_hash(); |
| 8473 | // Adds a block of characters to the hash. |
| 8474 | template<typename Char> |
| 8475 | inline void AddCharacters(const Char* chars, int len); |
| 8476 | |
| 8477 | private: |
| 8478 | // Add a character to the hash. |
| 8479 | inline void AddCharacter(uint16_t c); |
| 8480 | // Update index. Returns true if string is still an index. |
| 8481 | inline bool UpdateIndex(uint16_t c); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8482 | |
| 8483 | int length_; |
| 8484 | uint32_t raw_running_hash_; |
| 8485 | uint32_t array_index_; |
| 8486 | bool is_array_index_; |
| 8487 | bool is_first_char_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8488 | DISALLOW_COPY_AND_ASSIGN(StringHasher); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8489 | }; |
| 8490 | |
| 8491 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8492 | class IteratingStringHasher : public StringHasher { |
| 8493 | public: |
| 8494 | static inline uint32_t Hash(String* string, uint32_t seed); |
| 8495 | inline void VisitOneByteString(const uint8_t* chars, int length); |
| 8496 | inline void VisitTwoByteString(const uint16_t* chars, int length); |
| 8497 | |
| 8498 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8499 | inline IteratingStringHasher(int len, uint32_t seed); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8500 | void VisitConsString(ConsString* cons_string); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8501 | DISALLOW_COPY_AND_ASSIGN(IteratingStringHasher); |
| 8502 | }; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 8503 | |
| 8504 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8505 | // The characteristics of a string are stored in its map. Retrieving these |
| 8506 | // few bits of information is moderately expensive, involving two memory |
| 8507 | // loads where the second is dependent on the first. To improve efficiency |
| 8508 | // the shape of the string is given its own class so that it can be retrieved |
| 8509 | // once and used for several string operations. A StringShape is small enough |
| 8510 | // to be passed by value and is immutable, but be aware that flattening a |
| 8511 | // string can potentially alter its shape. Also be aware that a GC caused by |
| 8512 | // something else can alter the shape of a string due to ConsString |
| 8513 | // shortcutting. Keeping these restrictions in mind has proven to be error- |
| 8514 | // prone and so we no longer put StringShapes in variables unless there is a |
| 8515 | // concrete performance benefit at that particular point in the code. |
| 8516 | class StringShape BASE_EMBEDDED { |
| 8517 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8518 | inline explicit StringShape(const String* s); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8519 | inline explicit StringShape(Map* s); |
| 8520 | inline explicit StringShape(InstanceType t); |
| 8521 | inline bool IsSequential(); |
| 8522 | inline bool IsExternal(); |
| 8523 | inline bool IsCons(); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8524 | inline bool IsSliced(); |
| 8525 | inline bool IsIndirect(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8526 | inline bool IsExternalOneByte(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8527 | inline bool IsExternalTwoByte(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8528 | inline bool IsSequentialOneByte(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8529 | inline bool IsSequentialTwoByte(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8530 | inline bool IsInternalized(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8531 | inline StringRepresentationTag representation_tag(); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8532 | inline uint32_t encoding_tag(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8533 | inline uint32_t full_representation_tag(); |
| 8534 | inline uint32_t size_tag(); |
| 8535 | #ifdef DEBUG |
| 8536 | inline uint32_t type() { return type_; } |
| 8537 | inline void invalidate() { valid_ = false; } |
| 8538 | inline bool valid() { return valid_; } |
| 8539 | #else |
| 8540 | inline void invalidate() { } |
| 8541 | #endif |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 8542 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8543 | private: |
| 8544 | uint32_t type_; |
| 8545 | #ifdef DEBUG |
| 8546 | inline void set_valid() { valid_ = true; } |
| 8547 | bool valid_; |
| 8548 | #else |
| 8549 | inline void set_valid() { } |
| 8550 | #endif |
| 8551 | }; |
| 8552 | |
| 8553 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8554 | // The Name abstract class captures anything that can be used as a property |
| 8555 | // name, i.e., strings and symbols. All names store a hash value. |
| 8556 | class Name: public HeapObject { |
| 8557 | public: |
| 8558 | // Get and set the hash field of the name. |
| 8559 | inline uint32_t hash_field(); |
| 8560 | inline void set_hash_field(uint32_t value); |
| 8561 | |
| 8562 | // Tells whether the hash code has been computed. |
| 8563 | inline bool HasHashCode(); |
| 8564 | |
| 8565 | // Returns a hash value used for the property table |
| 8566 | inline uint32_t Hash(); |
| 8567 | |
| 8568 | // Equality operations. |
| 8569 | inline bool Equals(Name* other); |
| 8570 | inline static bool Equals(Handle<Name> one, Handle<Name> two); |
| 8571 | |
| 8572 | // Conversion. |
| 8573 | inline bool AsArrayIndex(uint32_t* index); |
| 8574 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8575 | // If the name is private, it can only name own properties. |
| 8576 | inline bool IsPrivate(); |
| 8577 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 8578 | inline bool IsUniqueName() const; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8579 | |
| 8580 | // Return a string version of this name that is converted according to the |
| 8581 | // rules described in ES6 section 9.2.11. |
| 8582 | MUST_USE_RESULT static MaybeHandle<String> ToFunctionName(Handle<Name> name); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8583 | |
| 8584 | DECLARE_CAST(Name) |
| 8585 | |
| 8586 | DECLARE_PRINTER(Name) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8587 | #if TRACE_MAPS |
| 8588 | void NameShortPrint(); |
| 8589 | int NameShortPrint(Vector<char> str); |
| 8590 | #endif |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8591 | |
| 8592 | // Layout description. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8593 | static const int kHashFieldSlot = HeapObject::kHeaderSize; |
| 8594 | #if V8_TARGET_LITTLE_ENDIAN || !V8_HOST_ARCH_64_BIT |
| 8595 | static const int kHashFieldOffset = kHashFieldSlot; |
| 8596 | #else |
| 8597 | static const int kHashFieldOffset = kHashFieldSlot + kIntSize; |
| 8598 | #endif |
| 8599 | static const int kSize = kHashFieldSlot + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8600 | |
| 8601 | // Mask constant for checking if a name has a computed hash code |
| 8602 | // and if it is a string that is an array index. The least significant bit |
| 8603 | // indicates whether a hash code has been computed. If the hash code has |
| 8604 | // been computed the 2nd bit tells whether the string can be used as an |
| 8605 | // array index. |
| 8606 | static const int kHashNotComputedMask = 1; |
| 8607 | static const int kIsNotArrayIndexMask = 1 << 1; |
| 8608 | static const int kNofHashBitFields = 2; |
| 8609 | |
| 8610 | // Shift constant retrieving hash code from hash field. |
| 8611 | static const int kHashShift = kNofHashBitFields; |
| 8612 | |
| 8613 | // Only these bits are relevant in the hash, since the top two are shifted |
| 8614 | // out. |
| 8615 | static const uint32_t kHashBitMask = 0xffffffffu >> kHashShift; |
| 8616 | |
| 8617 | // Array index strings this short can keep their index in the hash field. |
| 8618 | static const int kMaxCachedArrayIndexLength = 7; |
| 8619 | |
| 8620 | // For strings which are array indexes the hash value has the string length |
| 8621 | // mixed into the hash, mainly to avoid a hash value of zero which would be |
| 8622 | // the case for the string '0'. 24 bits are used for the array index value. |
| 8623 | static const int kArrayIndexValueBits = 24; |
| 8624 | static const int kArrayIndexLengthBits = |
| 8625 | kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields; |
| 8626 | |
| 8627 | STATIC_ASSERT((kArrayIndexLengthBits > 0)); |
| 8628 | |
| 8629 | class ArrayIndexValueBits : public BitField<unsigned int, kNofHashBitFields, |
| 8630 | kArrayIndexValueBits> {}; // NOLINT |
| 8631 | class ArrayIndexLengthBits : public BitField<unsigned int, |
| 8632 | kNofHashBitFields + kArrayIndexValueBits, |
| 8633 | kArrayIndexLengthBits> {}; // NOLINT |
| 8634 | |
| 8635 | // Check that kMaxCachedArrayIndexLength + 1 is a power of two so we |
| 8636 | // could use a mask to test if the length of string is less than or equal to |
| 8637 | // kMaxCachedArrayIndexLength. |
| 8638 | STATIC_ASSERT(IS_POWER_OF_TWO(kMaxCachedArrayIndexLength + 1)); |
| 8639 | |
| 8640 | static const unsigned int kContainsCachedArrayIndexMask = |
| 8641 | (~static_cast<unsigned>(kMaxCachedArrayIndexLength) |
| 8642 | << ArrayIndexLengthBits::kShift) | |
| 8643 | kIsNotArrayIndexMask; |
| 8644 | |
| 8645 | // Value of empty hash field indicating that the hash is not computed. |
| 8646 | static const int kEmptyHashField = |
| 8647 | kIsNotArrayIndexMask | kHashNotComputedMask; |
| 8648 | |
| 8649 | protected: |
| 8650 | static inline bool IsHashFieldComputed(uint32_t field); |
| 8651 | |
| 8652 | private: |
| 8653 | DISALLOW_IMPLICIT_CONSTRUCTORS(Name); |
| 8654 | }; |
| 8655 | |
| 8656 | |
| 8657 | // ES6 symbols. |
| 8658 | class Symbol: public Name { |
| 8659 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8660 | // [name]: The print name of a symbol, or undefined if none. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8661 | DECL_ACCESSORS(name, Object) |
| 8662 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8663 | DECL_INT_ACCESSORS(flags) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8664 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8665 | // [is_private]: Whether this is a private symbol. Private symbols can only |
| 8666 | // be used to designate own properties of objects. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8667 | DECL_BOOLEAN_ACCESSORS(is_private) |
| 8668 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8669 | // [is_well_known_symbol]: Whether this is a spec-defined well-known symbol, |
| 8670 | // or not. Well-known symbols do not throw when an access check fails during |
| 8671 | // a load. |
| 8672 | DECL_BOOLEAN_ACCESSORS(is_well_known_symbol) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8673 | |
| 8674 | DECLARE_CAST(Symbol) |
| 8675 | |
| 8676 | // Dispatched behavior. |
| 8677 | DECLARE_PRINTER(Symbol) |
| 8678 | DECLARE_VERIFIER(Symbol) |
| 8679 | |
| 8680 | // Layout description. |
| 8681 | static const int kNameOffset = Name::kSize; |
| 8682 | static const int kFlagsOffset = kNameOffset + kPointerSize; |
| 8683 | static const int kSize = kFlagsOffset + kPointerSize; |
| 8684 | |
| 8685 | typedef FixedBodyDescriptor<kNameOffset, kFlagsOffset, kSize> BodyDescriptor; |
| 8686 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8687 | void SymbolShortPrint(std::ostream& os); |
| 8688 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8689 | private: |
| 8690 | static const int kPrivateBit = 0; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8691 | static const int kWellKnownSymbolBit = 1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8692 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8693 | const char* PrivateSymbolToName() const; |
| 8694 | |
| 8695 | #if TRACE_MAPS |
| 8696 | friend class Name; // For PrivateSymbolToName. |
| 8697 | #endif |
| 8698 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8699 | DISALLOW_IMPLICIT_CONSTRUCTORS(Symbol); |
| 8700 | }; |
| 8701 | |
| 8702 | |
| 8703 | class ConsString; |
| 8704 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8705 | // The String abstract class captures JavaScript string values: |
| 8706 | // |
| 8707 | // Ecma-262: |
| 8708 | // 4.3.16 String Value |
| 8709 | // A string value is a member of the type String and is a finite |
| 8710 | // ordered sequence of zero or more 16-bit unsigned integer values. |
| 8711 | // |
| 8712 | // All string values have a length field. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8713 | class String: public Name { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8714 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8715 | enum Encoding { ONE_BYTE_ENCODING, TWO_BYTE_ENCODING }; |
| 8716 | |
| 8717 | // Array index strings this short can keep their index in the hash field. |
| 8718 | static const int kMaxCachedArrayIndexLength = 7; |
| 8719 | |
| 8720 | // For strings which are array indexes the hash value has the string length |
| 8721 | // mixed into the hash, mainly to avoid a hash value of zero which would be |
| 8722 | // the case for the string '0'. 24 bits are used for the array index value. |
| 8723 | static const int kArrayIndexValueBits = 24; |
| 8724 | static const int kArrayIndexLengthBits = |
| 8725 | kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields; |
| 8726 | |
| 8727 | STATIC_ASSERT((kArrayIndexLengthBits > 0)); |
| 8728 | |
| 8729 | class ArrayIndexValueBits : public BitField<unsigned int, kNofHashBitFields, |
| 8730 | kArrayIndexValueBits> {}; // NOLINT |
| 8731 | class ArrayIndexLengthBits : public BitField<unsigned int, |
| 8732 | kNofHashBitFields + kArrayIndexValueBits, |
| 8733 | kArrayIndexLengthBits> {}; // NOLINT |
| 8734 | |
| 8735 | // Check that kMaxCachedArrayIndexLength + 1 is a power of two so we |
| 8736 | // could use a mask to test if the length of string is less than or equal to |
| 8737 | // kMaxCachedArrayIndexLength. |
| 8738 | STATIC_ASSERT(IS_POWER_OF_TWO(kMaxCachedArrayIndexLength + 1)); |
| 8739 | |
| 8740 | static const unsigned int kContainsCachedArrayIndexMask = |
| 8741 | (~static_cast<unsigned>(kMaxCachedArrayIndexLength) |
| 8742 | << ArrayIndexLengthBits::kShift) | |
| 8743 | kIsNotArrayIndexMask; |
| 8744 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8745 | class SubStringRange { |
| 8746 | public: |
| 8747 | explicit inline SubStringRange(String* string, int first = 0, |
| 8748 | int length = -1); |
| 8749 | class iterator; |
| 8750 | inline iterator begin(); |
| 8751 | inline iterator end(); |
| 8752 | |
| 8753 | private: |
| 8754 | String* string_; |
| 8755 | int first_; |
| 8756 | int length_; |
| 8757 | }; |
| 8758 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8759 | // Representation of the flat content of a String. |
| 8760 | // A non-flat string doesn't have flat content. |
| 8761 | // 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] | 8762 | // one-byte chars or two-byte UC16. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8763 | // Returned by String::GetFlatContent(). |
| 8764 | class FlatContent { |
| 8765 | public: |
| 8766 | // Returns true if the string is flat and this structure contains content. |
| 8767 | bool IsFlat() { return state_ != NON_FLAT; } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8768 | // Returns true if the structure contains one-byte content. |
| 8769 | bool IsOneByte() { return state_ == ONE_BYTE; } |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8770 | // Returns true if the structure contains two-byte content. |
| 8771 | bool IsTwoByte() { return state_ == TWO_BYTE; } |
| 8772 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8773 | // Return the one byte content of the string. Only use if IsOneByte() |
| 8774 | // returns true. |
| 8775 | Vector<const uint8_t> ToOneByteVector() { |
| 8776 | DCHECK_EQ(ONE_BYTE, state_); |
| 8777 | return Vector<const uint8_t>(onebyte_start, length_); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8778 | } |
| 8779 | // Return the two-byte content of the string. Only use if IsTwoByte() |
| 8780 | // returns true. |
| 8781 | Vector<const uc16> ToUC16Vector() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8782 | DCHECK_EQ(TWO_BYTE, state_); |
| 8783 | return Vector<const uc16>(twobyte_start, length_); |
| 8784 | } |
| 8785 | |
| 8786 | uc16 Get(int i) { |
| 8787 | DCHECK(i < length_); |
| 8788 | DCHECK(state_ != NON_FLAT); |
| 8789 | if (state_ == ONE_BYTE) return onebyte_start[i]; |
| 8790 | return twobyte_start[i]; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8791 | } |
| 8792 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8793 | bool UsesSameString(const FlatContent& other) const { |
| 8794 | return onebyte_start == other.onebyte_start; |
| 8795 | } |
| 8796 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8797 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8798 | enum State { NON_FLAT, ONE_BYTE, TWO_BYTE }; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8799 | |
| 8800 | // Constructors only used by String::GetFlatContent(). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8801 | explicit FlatContent(const uint8_t* start, int length) |
| 8802 | : onebyte_start(start), length_(length), state_(ONE_BYTE) {} |
| 8803 | explicit FlatContent(const uc16* start, int length) |
| 8804 | : twobyte_start(start), length_(length), state_(TWO_BYTE) { } |
| 8805 | FlatContent() : onebyte_start(NULL), length_(0), state_(NON_FLAT) { } |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8806 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8807 | union { |
| 8808 | const uint8_t* onebyte_start; |
| 8809 | const uc16* twobyte_start; |
| 8810 | }; |
| 8811 | int length_; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8812 | State state_; |
| 8813 | |
| 8814 | friend class String; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8815 | friend class IterableSubString; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8816 | }; |
| 8817 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8818 | template <typename Char> |
| 8819 | INLINE(Vector<const Char> GetCharVector()); |
| 8820 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8821 | // Get and set the length of the string. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8822 | inline int length() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8823 | inline void set_length(int value); |
| 8824 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8825 | // Get and set the length of the string using acquire loads and release |
| 8826 | // stores. |
| 8827 | inline int synchronized_length() const; |
| 8828 | inline void synchronized_set_length(int value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8829 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8830 | // Returns whether this string has only one-byte chars, i.e. all of them can |
| 8831 | // 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] | 8832 | // two-byte. Such strings may appear when the embedder prefers |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8833 | // two-byte external representations even for one-byte data. |
| 8834 | inline bool IsOneByteRepresentation() const; |
| 8835 | inline bool IsTwoByteRepresentation() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8836 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8837 | // Cons and slices have an encoding flag that may not represent the actual |
| 8838 | // encoding of the underlying string. This is taken into account here. |
| 8839 | // Requires: this->IsFlat() |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8840 | inline bool IsOneByteRepresentationUnderneath(); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8841 | inline bool IsTwoByteRepresentationUnderneath(); |
| 8842 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 8843 | // NOTE: this should be considered only a hint. False negatives are |
| 8844 | // possible. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8845 | inline bool HasOnlyOneByteChars(); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 8846 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8847 | // Get and set individual two byte chars in the string. |
| 8848 | inline void Set(int index, uint16_t value); |
| 8849 | // Get individual two byte char in the string. Repeated calls |
| 8850 | // to this method are not efficient unless the string is flat. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8851 | INLINE(uint16_t Get(int index)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8852 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8853 | // ES6 section 7.1.3.1 ToNumber Applied to the String Type |
| 8854 | static Handle<Object> ToNumber(Handle<String> subject); |
| 8855 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8856 | // Flattens the string. Checks first inline to see if it is |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 8857 | // necessary. Does nothing if the string is not a cons string. |
| 8858 | // Flattening allocates a sequential string with the same data as |
| 8859 | // the given string and mutates the cons string to a degenerate |
| 8860 | // form, where the first component is the new sequential string and |
| 8861 | // the second component is the empty string. If allocation fails, |
| 8862 | // this function returns a failure. If flattening succeeds, this |
| 8863 | // function returns the sequential string that is now the first |
| 8864 | // component of the cons string. |
| 8865 | // |
| 8866 | // Degenerate cons strings are handled specially by the garbage |
| 8867 | // collector (see IsShortcutCandidate). |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8868 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8869 | static inline Handle<String> Flatten(Handle<String> string, |
| 8870 | PretenureFlag pretenure = NOT_TENURED); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 8871 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8872 | // Tries to return the content of a flat string as a structure holding either |
| 8873 | // a flat vector of char or of uc16. |
| 8874 | // If the string isn't flat, and therefore doesn't have flat content, the |
| 8875 | // returned structure will report so, and can't provide a vector of either |
| 8876 | // kind. |
| 8877 | FlatContent GetFlatContent(); |
| 8878 | |
| 8879 | // Returns the parent of a sliced string or first part of a flat cons string. |
| 8880 | // Requires: StringShape(this).IsIndirect() && this->IsFlat() |
| 8881 | inline String* GetUnderlying(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8882 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8883 | // String relational comparison, implemented according to ES6 section 7.2.11 |
| 8884 | // Abstract Relational Comparison (step 5): The comparison of Strings uses a |
| 8885 | // simple lexicographic ordering on sequences of code unit values. There is no |
| 8886 | // attempt to use the more complex, semantically oriented definitions of |
| 8887 | // character or string equality and collating order defined in the Unicode |
| 8888 | // specification. Therefore String values that are canonically equal according |
| 8889 | // to the Unicode standard could test as unequal. In effect this algorithm |
| 8890 | // assumes that both Strings are already in normalized form. Also, note that |
| 8891 | // for strings containing supplementary characters, lexicographic ordering on |
| 8892 | // sequences of UTF-16 code unit values differs from that on sequences of code |
| 8893 | // point values. |
| 8894 | MUST_USE_RESULT static ComparisonResult Compare(Handle<String> x, |
| 8895 | Handle<String> y); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8896 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8897 | // String equality operations. |
| 8898 | inline bool Equals(String* other); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8899 | inline static bool Equals(Handle<String> one, Handle<String> two); |
| 8900 | bool IsUtf8EqualTo(Vector<const char> str, bool allow_prefix_match = false); |
| 8901 | bool IsOneByteEqualTo(Vector<const uint8_t> str); |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 8902 | bool IsTwoByteEqualTo(Vector<const uc16> str); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8903 | |
| 8904 | // Return a UTF8 representation of the string. The string is null |
| 8905 | // terminated but may optionally contain nulls. Length is returned |
| 8906 | // in length_output if length_output is not a null pointer The string |
| 8907 | // should be nearly flat, otherwise the performance of this method may |
| 8908 | // be very slow (quadratic in the length). Setting robustness_flag to |
| 8909 | // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it |
| 8910 | // handles unexpected data without causing assert failures and it does not |
| 8911 | // do any heap allocations. This is useful when printing stack traces. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8912 | base::SmartArrayPointer<char> ToCString(AllowNullsFlag allow_nulls, |
| 8913 | RobustnessFlag robustness_flag, |
| 8914 | int offset, int length, |
| 8915 | int* length_output = 0); |
| 8916 | base::SmartArrayPointer<char> ToCString( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8917 | AllowNullsFlag allow_nulls = DISALLOW_NULLS, |
| 8918 | RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL, |
| 8919 | int* length_output = 0); |
| 8920 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8921 | // Return a 16 bit Unicode representation of the string. |
| 8922 | // The string should be nearly flat, otherwise the performance of |
| 8923 | // of this method may be very bad. Setting robustness_flag to |
| 8924 | // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it |
| 8925 | // handles unexpected data without causing assert failures and it does not |
| 8926 | // do any heap allocations. This is useful when printing stack traces. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8927 | base::SmartArrayPointer<uc16> ToWideCString( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8928 | RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL); |
| 8929 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8930 | bool ComputeArrayIndex(uint32_t* index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8931 | |
| 8932 | // Externalization. |
| 8933 | bool MakeExternal(v8::String::ExternalStringResource* resource); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8934 | bool MakeExternal(v8::String::ExternalOneByteStringResource* resource); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8935 | |
| 8936 | // Conversion. |
| 8937 | inline bool AsArrayIndex(uint32_t* index); |
| 8938 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8939 | DECLARE_CAST(String) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8940 | |
| 8941 | void PrintOn(FILE* out); |
| 8942 | |
| 8943 | // For use during stack traces. Performs rudimentary sanity check. |
| 8944 | bool LooksValid(); |
| 8945 | |
| 8946 | // Dispatched behavior. |
| 8947 | void StringShortPrint(StringStream* accumulator); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8948 | void PrintUC16(std::ostream& os, int start = 0, int end = -1); // NOLINT |
| 8949 | #if defined(DEBUG) || defined(OBJECT_PRINT) |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8950 | char* ToAsciiArray(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 8951 | #endif |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8952 | DECLARE_PRINTER(String) |
| 8953 | DECLARE_VERIFIER(String) |
| 8954 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8955 | inline bool IsFlat(); |
| 8956 | |
| 8957 | // Layout description. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8958 | static const int kLengthOffset = Name::kSize; |
| 8959 | static const int kSize = kLengthOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8960 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 8961 | // Maximum number of characters to consider when trying to convert a string |
| 8962 | // value into an array index. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8963 | static const int kMaxArrayIndexSize = 10; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8964 | STATIC_ASSERT(kMaxArrayIndexSize < (1 << kArrayIndexLengthBits)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8965 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8966 | // Max char codes. |
| 8967 | static const int32_t kMaxOneByteCharCode = unibrow::Latin1::kMaxChar; |
| 8968 | static const uint32_t kMaxOneByteCharCodeU = unibrow::Latin1::kMaxChar; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 8969 | static const int kMaxUtf16CodeUnit = 0xffff; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8970 | static const uint32_t kMaxUtf16CodeUnitU = kMaxUtf16CodeUnit; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 8971 | static const uc32 kMaxCodePoint = 0x10ffff; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 8972 | |
| 8973 | // Maximal string length. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8974 | static const int kMaxLength = (1 << 28) - 16; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 8975 | |
| 8976 | // Max length for computing hash. For strings longer than this limit the |
| 8977 | // string length is used as the hash value. |
| 8978 | static const int kMaxHashCalcLength = 16383; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8979 | |
| 8980 | // Limit for truncation in short printing. |
| 8981 | static const int kMaxShortPrintLength = 1024; |
| 8982 | |
| 8983 | // Support for regular expressions. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8984 | const uc16* GetTwoByteData(unsigned start); |
| 8985 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8986 | // Helper function for flattening strings. |
| 8987 | template <typename sinkchar> |
| 8988 | static void WriteToFlat(String* source, |
| 8989 | sinkchar* sink, |
| 8990 | int from, |
| 8991 | int to); |
| 8992 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8993 | // The return value may point to the first aligned word containing the first |
| 8994 | // non-one-byte character, rather than directly to the non-one-byte character. |
| 8995 | // If the return value is >= the passed length, the entire string was |
| 8996 | // one-byte. |
| 8997 | static inline int NonAsciiStart(const char* chars, int length) { |
| 8998 | const char* start = chars; |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 8999 | const char* limit = chars + length; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9000 | |
| 9001 | if (length >= kIntptrSize) { |
| 9002 | // Check unaligned bytes. |
| 9003 | while (!IsAligned(reinterpret_cast<intptr_t>(chars), sizeof(uintptr_t))) { |
| 9004 | if (static_cast<uint8_t>(*chars) > unibrow::Utf8::kMaxOneByteChar) { |
| 9005 | return static_cast<int>(chars - start); |
| 9006 | } |
| 9007 | ++chars; |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 9008 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9009 | // Check aligned words. |
| 9010 | DCHECK(unibrow::Utf8::kMaxOneByteChar == 0x7F); |
| 9011 | const uintptr_t non_one_byte_mask = kUintptrAllBitsSet / 0xFF * 0x80; |
| 9012 | while (chars + sizeof(uintptr_t) <= limit) { |
| 9013 | if (*reinterpret_cast<const uintptr_t*>(chars) & non_one_byte_mask) { |
| 9014 | return static_cast<int>(chars - start); |
| 9015 | } |
| 9016 | chars += sizeof(uintptr_t); |
| 9017 | } |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 9018 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9019 | // Check remaining unaligned bytes. |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 9020 | while (chars < limit) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9021 | if (static_cast<uint8_t>(*chars) > unibrow::Utf8::kMaxOneByteChar) { |
| 9022 | return static_cast<int>(chars - start); |
| 9023 | } |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 9024 | ++chars; |
| 9025 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9026 | |
| 9027 | return static_cast<int>(chars - start); |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 9028 | } |
| 9029 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9030 | static inline bool IsAscii(const char* chars, int length) { |
| 9031 | return NonAsciiStart(chars, length) >= length; |
| 9032 | } |
| 9033 | |
| 9034 | static inline bool IsAscii(const uint8_t* chars, int length) { |
| 9035 | return |
| 9036 | NonAsciiStart(reinterpret_cast<const char*>(chars), length) >= length; |
| 9037 | } |
| 9038 | |
| 9039 | static inline int NonOneByteStart(const uc16* chars, int length) { |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 9040 | const uc16* limit = chars + length; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9041 | const uc16* start = chars; |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 9042 | while (chars < limit) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9043 | if (*chars > kMaxOneByteCharCodeU) return static_cast<int>(chars - start); |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 9044 | ++chars; |
| 9045 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9046 | return static_cast<int>(chars - start); |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 9047 | } |
| 9048 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9049 | static inline bool IsOneByte(const uc16* chars, int length) { |
| 9050 | return NonOneByteStart(chars, length) >= length; |
| 9051 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9052 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9053 | template<class Visitor> |
| 9054 | static inline ConsString* VisitFlat(Visitor* visitor, |
| 9055 | String* string, |
| 9056 | int offset = 0); |
| 9057 | |
| 9058 | static Handle<FixedArray> CalculateLineEnds(Handle<String> string, |
| 9059 | bool include_ending_line); |
| 9060 | |
| 9061 | // Use the hash field to forward to the canonical internalized string |
| 9062 | // when deserializing an internalized string. |
| 9063 | inline void SetForwardedInternalizedString(String* string); |
| 9064 | inline String* GetForwardedInternalizedString(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9065 | |
| 9066 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9067 | friend class Name; |
| 9068 | friend class StringTableInsertionKey; |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 9069 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9070 | static Handle<String> SlowFlatten(Handle<ConsString> cons, |
| 9071 | PretenureFlag tenure); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 9072 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9073 | // Slow case of String::Equals. This implementation works on any strings |
| 9074 | // but it is most efficient on strings that are almost flat. |
| 9075 | bool SlowEquals(String* other); |
| 9076 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9077 | static bool SlowEquals(Handle<String> one, Handle<String> two); |
| 9078 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9079 | // Slow case of AsArrayIndex. |
| 9080 | bool SlowAsArrayIndex(uint32_t* index); |
| 9081 | |
| 9082 | // Compute and set the hash code. |
| 9083 | uint32_t ComputeAndSetHash(); |
| 9084 | |
| 9085 | DISALLOW_IMPLICIT_CONSTRUCTORS(String); |
| 9086 | }; |
| 9087 | |
| 9088 | |
| 9089 | // The SeqString abstract class captures sequential string values. |
| 9090 | class SeqString: public String { |
| 9091 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9092 | DECLARE_CAST(SeqString) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9093 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9094 | // Layout description. |
| 9095 | static const int kHeaderSize = String::kSize; |
| 9096 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9097 | // Truncate the string in-place if possible and return the result. |
| 9098 | // In case of new_length == 0, the empty string is returned without |
| 9099 | // truncating the original string. |
| 9100 | MUST_USE_RESULT static Handle<String> Truncate(Handle<SeqString> string, |
| 9101 | int new_length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9102 | private: |
| 9103 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqString); |
| 9104 | }; |
| 9105 | |
| 9106 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9107 | // The OneByteString class captures sequential one-byte string objects. |
| 9108 | // Each character in the OneByteString is an one-byte character. |
| 9109 | class SeqOneByteString: public SeqString { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9110 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9111 | static const bool kHasOneByteEncoding = true; |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 9112 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9113 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9114 | inline uint16_t SeqOneByteStringGet(int index); |
| 9115 | inline void SeqOneByteStringSet(int index, uint16_t value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9116 | |
| 9117 | // Get the address of the characters in this string. |
| 9118 | inline Address GetCharsAddress(); |
| 9119 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9120 | inline uint8_t* GetChars(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9121 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9122 | DECLARE_CAST(SeqOneByteString) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9123 | |
| 9124 | // Garbage collection support. This method is called by the |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9125 | // garbage collector to compute the actual size of an OneByteString |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9126 | // instance. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9127 | inline int SeqOneByteStringSize(InstanceType instance_type); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9128 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9129 | // Computes the size for an OneByteString instance of a given length. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9130 | static int SizeFor(int length) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 9131 | return OBJECT_POINTER_ALIGN(kHeaderSize + length * kCharSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9132 | } |
| 9133 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9134 | // Maximal memory usage for a single sequential one-byte string. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9135 | static const int kMaxSize = 512 * MB - 1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9136 | STATIC_ASSERT((kMaxSize - kHeaderSize) >= String::kMaxLength); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9137 | |
| 9138 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9139 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqOneByteString); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9140 | }; |
| 9141 | |
| 9142 | |
| 9143 | // The TwoByteString class captures sequential unicode string objects. |
| 9144 | // Each character in the TwoByteString is a two-byte uint16_t. |
| 9145 | class SeqTwoByteString: public SeqString { |
| 9146 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9147 | static const bool kHasOneByteEncoding = false; |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 9148 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9149 | // Dispatched behavior. |
| 9150 | inline uint16_t SeqTwoByteStringGet(int index); |
| 9151 | inline void SeqTwoByteStringSet(int index, uint16_t value); |
| 9152 | |
| 9153 | // Get the address of the characters in this string. |
| 9154 | inline Address GetCharsAddress(); |
| 9155 | |
| 9156 | inline uc16* GetChars(); |
| 9157 | |
| 9158 | // For regexp code. |
| 9159 | const uint16_t* SeqTwoByteStringGetData(unsigned start); |
| 9160 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9161 | DECLARE_CAST(SeqTwoByteString) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9162 | |
| 9163 | // Garbage collection support. This method is called by the |
| 9164 | // garbage collector to compute the actual size of a TwoByteString |
| 9165 | // instance. |
| 9166 | inline int SeqTwoByteStringSize(InstanceType instance_type); |
| 9167 | |
| 9168 | // Computes the size for a TwoByteString instance of a given length. |
| 9169 | static int SizeFor(int length) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 9170 | return OBJECT_POINTER_ALIGN(kHeaderSize + length * kShortSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9171 | } |
| 9172 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 9173 | // Maximal memory usage for a single sequential two-byte string. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9174 | static const int kMaxSize = 512 * MB - 1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9175 | STATIC_ASSERT(static_cast<int>((kMaxSize - kHeaderSize)/sizeof(uint16_t)) >= |
| 9176 | String::kMaxLength); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9177 | |
| 9178 | private: |
| 9179 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqTwoByteString); |
| 9180 | }; |
| 9181 | |
| 9182 | |
| 9183 | // The ConsString class describes string values built by using the |
| 9184 | // addition operator on strings. A ConsString is a pair where the |
| 9185 | // first and second components are pointers to other string values. |
| 9186 | // One or both components of a ConsString can be pointers to other |
| 9187 | // ConsStrings, creating a binary tree of ConsStrings where the leaves |
| 9188 | // are non-ConsString string values. The string value represented by |
| 9189 | // a ConsString can be obtained by concatenating the leaf string |
| 9190 | // values in a left-to-right depth-first traversal of the tree. |
| 9191 | class ConsString: public String { |
| 9192 | public: |
| 9193 | // First string of the cons cell. |
| 9194 | inline String* first(); |
| 9195 | // Doesn't check that the result is a string, even in debug mode. This is |
| 9196 | // useful during GC where the mark bits confuse the checks. |
| 9197 | inline Object* unchecked_first(); |
| 9198 | inline void set_first(String* first, |
| 9199 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| 9200 | |
| 9201 | // Second string of the cons cell. |
| 9202 | inline String* second(); |
| 9203 | // Doesn't check that the result is a string, even in debug mode. This is |
| 9204 | // useful during GC where the mark bits confuse the checks. |
| 9205 | inline Object* unchecked_second(); |
| 9206 | inline void set_second(String* second, |
| 9207 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| 9208 | |
| 9209 | // Dispatched behavior. |
| 9210 | uint16_t ConsStringGet(int index); |
| 9211 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9212 | DECLARE_CAST(ConsString) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9213 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9214 | // Layout description. |
| 9215 | static const int kFirstOffset = POINTER_SIZE_ALIGN(String::kSize); |
| 9216 | static const int kSecondOffset = kFirstOffset + kPointerSize; |
| 9217 | static const int kSize = kSecondOffset + kPointerSize; |
| 9218 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9219 | // Minimum length for a cons string. |
| 9220 | static const int kMinLength = 13; |
| 9221 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 9222 | typedef FixedBodyDescriptor<kFirstOffset, kSecondOffset + kPointerSize, kSize> |
| 9223 | BodyDescriptor; |
| 9224 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9225 | DECLARE_VERIFIER(ConsString) |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 9226 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9227 | private: |
| 9228 | DISALLOW_IMPLICIT_CONSTRUCTORS(ConsString); |
| 9229 | }; |
| 9230 | |
| 9231 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 9232 | // The Sliced String class describes strings that are substrings of another |
| 9233 | // sequential string. The motivation is to save time and memory when creating |
| 9234 | // a substring. A Sliced String is described as a pointer to the parent, |
| 9235 | // the offset from the start of the parent string and the length. Using |
| 9236 | // a Sliced String therefore requires unpacking of the parent string and |
| 9237 | // adding the offset to the start address. A substring of a Sliced String |
| 9238 | // are not nested since the double indirection is simplified when creating |
| 9239 | // such a substring. |
| 9240 | // Currently missing features are: |
| 9241 | // - handling externalized parent strings |
| 9242 | // - external strings as parent |
| 9243 | // - truncating sliced string to enable otherwise unneeded parent to be GC'ed. |
| 9244 | class SlicedString: public String { |
| 9245 | public: |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 9246 | inline String* parent(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9247 | inline void set_parent(String* parent, |
| 9248 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| 9249 | inline int offset() const; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 9250 | inline void set_offset(int offset); |
| 9251 | |
| 9252 | // Dispatched behavior. |
| 9253 | uint16_t SlicedStringGet(int index); |
| 9254 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9255 | DECLARE_CAST(SlicedString) |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 9256 | |
| 9257 | // Layout description. |
| 9258 | static const int kParentOffset = POINTER_SIZE_ALIGN(String::kSize); |
| 9259 | static const int kOffsetOffset = kParentOffset + kPointerSize; |
| 9260 | static const int kSize = kOffsetOffset + kPointerSize; |
| 9261 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 9262 | // Minimum length for a sliced string. |
| 9263 | static const int kMinLength = 13; |
| 9264 | |
| 9265 | typedef FixedBodyDescriptor<kParentOffset, |
| 9266 | kOffsetOffset + kPointerSize, kSize> |
| 9267 | BodyDescriptor; |
| 9268 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9269 | DECLARE_VERIFIER(SlicedString) |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 9270 | |
| 9271 | private: |
| 9272 | DISALLOW_IMPLICIT_CONSTRUCTORS(SlicedString); |
| 9273 | }; |
| 9274 | |
| 9275 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9276 | // The ExternalString class describes string values that are backed by |
| 9277 | // a string resource that lies outside the V8 heap. ExternalStrings |
| 9278 | // consist of the length field common to all strings, a pointer to the |
| 9279 | // external resource. It is important to ensure (externally) that the |
| 9280 | // resource is not deallocated while the ExternalString is live in the |
| 9281 | // V8 heap. |
| 9282 | // |
| 9283 | // The API expects that all ExternalStrings are created through the |
| 9284 | // API. Therefore, ExternalStrings should not be used internally. |
| 9285 | class ExternalString: public String { |
| 9286 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9287 | DECLARE_CAST(ExternalString) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9288 | |
| 9289 | // Layout description. |
| 9290 | static const int kResourceOffset = POINTER_SIZE_ALIGN(String::kSize); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9291 | static const int kShortSize = kResourceOffset + kPointerSize; |
| 9292 | static const int kResourceDataOffset = kResourceOffset + kPointerSize; |
| 9293 | static const int kSize = kResourceDataOffset + kPointerSize; |
| 9294 | |
| 9295 | // Return whether external string is short (data pointer is not cached). |
| 9296 | inline bool is_short(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9297 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9298 | STATIC_ASSERT(kResourceOffset == Internals::kStringResourceOffset); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9299 | |
| 9300 | private: |
| 9301 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalString); |
| 9302 | }; |
| 9303 | |
| 9304 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9305 | // The ExternalOneByteString class is an external string backed by an |
| 9306 | // one-byte string. |
| 9307 | class ExternalOneByteString : public ExternalString { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9308 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9309 | static const bool kHasOneByteEncoding = true; |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 9310 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9311 | typedef v8::String::ExternalOneByteStringResource Resource; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9312 | |
| 9313 | // The underlying resource. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9314 | inline const Resource* resource(); |
| 9315 | inline void set_resource(const Resource* buffer); |
| 9316 | |
| 9317 | // Update the pointer cache to the external character array. |
| 9318 | // The cached pointer is always valid, as the external character array does = |
| 9319 | // not move during lifetime. Deserialization is the only exception, after |
| 9320 | // which the pointer cache has to be refreshed. |
| 9321 | inline void update_data_cache(); |
| 9322 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9323 | inline const uint8_t* GetChars(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9324 | |
| 9325 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9326 | inline uint16_t ExternalOneByteStringGet(int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9327 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9328 | DECLARE_CAST(ExternalOneByteString) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9329 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9330 | class BodyDescriptor; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9331 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9332 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9333 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalOneByteString); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9334 | }; |
| 9335 | |
| 9336 | |
| 9337 | // The ExternalTwoByteString class is an external string backed by a UTF-16 |
| 9338 | // encoded string. |
| 9339 | class ExternalTwoByteString: public ExternalString { |
| 9340 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9341 | static const bool kHasOneByteEncoding = false; |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 9342 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9343 | typedef v8::String::ExternalStringResource Resource; |
| 9344 | |
| 9345 | // The underlying string resource. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9346 | inline const Resource* resource(); |
| 9347 | inline void set_resource(const Resource* buffer); |
| 9348 | |
| 9349 | // Update the pointer cache to the external character array. |
| 9350 | // The cached pointer is always valid, as the external character array does = |
| 9351 | // not move during lifetime. Deserialization is the only exception, after |
| 9352 | // which the pointer cache has to be refreshed. |
| 9353 | inline void update_data_cache(); |
| 9354 | |
| 9355 | inline const uint16_t* GetChars(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9356 | |
| 9357 | // Dispatched behavior. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9358 | inline uint16_t ExternalTwoByteStringGet(int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9359 | |
| 9360 | // For regexp code. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9361 | inline const uint16_t* ExternalTwoByteStringGetData(unsigned start); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9362 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9363 | DECLARE_CAST(ExternalTwoByteString) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9364 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9365 | class BodyDescriptor; |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 9366 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9367 | private: |
| 9368 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalTwoByteString); |
| 9369 | }; |
| 9370 | |
| 9371 | |
| 9372 | // Utility superclass for stack-allocated objects that must be updated |
| 9373 | // on gc. It provides two ways for the gc to update instances, either |
| 9374 | // iterating or updating after gc. |
| 9375 | class Relocatable BASE_EMBEDDED { |
| 9376 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 9377 | explicit inline Relocatable(Isolate* isolate); |
| 9378 | inline virtual ~Relocatable(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9379 | virtual void IterateInstance(ObjectVisitor* v) { } |
| 9380 | virtual void PostGarbageCollection() { } |
| 9381 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9382 | static void PostGarbageCollectionProcessing(Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9383 | static int ArchiveSpacePerThread(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 9384 | static char* ArchiveState(Isolate* isolate, char* to); |
| 9385 | static char* RestoreState(Isolate* isolate, char* from); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9386 | static void Iterate(Isolate* isolate, ObjectVisitor* v); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9387 | static void Iterate(ObjectVisitor* v, Relocatable* top); |
| 9388 | static char* Iterate(ObjectVisitor* v, char* t); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9389 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9390 | private: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 9391 | Isolate* isolate_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9392 | Relocatable* prev_; |
| 9393 | }; |
| 9394 | |
| 9395 | |
| 9396 | // A flat string reader provides random access to the contents of a |
| 9397 | // string independent of the character width of the string. The handle |
| 9398 | // must be valid as long as the reader is being used. |
| 9399 | class FlatStringReader : public Relocatable { |
| 9400 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 9401 | FlatStringReader(Isolate* isolate, Handle<String> str); |
| 9402 | FlatStringReader(Isolate* isolate, Vector<const char> input); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9403 | void PostGarbageCollection(); |
| 9404 | inline uc32 Get(int index); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 9405 | template <typename Char> |
| 9406 | inline Char Get(int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9407 | int length() { return length_; } |
| 9408 | private: |
| 9409 | String** str_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9410 | bool is_one_byte_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9411 | int length_; |
| 9412 | const void* start_; |
| 9413 | }; |
| 9414 | |
| 9415 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9416 | // This maintains an off-stack representation of the stack frames required |
| 9417 | // to traverse a ConsString, allowing an entirely iterative and restartable |
| 9418 | // traversal of the entire string |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 9419 | class ConsStringIterator { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9420 | public: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 9421 | inline ConsStringIterator() {} |
| 9422 | inline explicit ConsStringIterator(ConsString* cons_string, int offset = 0) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9423 | Reset(cons_string, offset); |
| 9424 | } |
| 9425 | inline void Reset(ConsString* cons_string, int offset = 0) { |
| 9426 | depth_ = 0; |
| 9427 | // Next will always return NULL. |
| 9428 | if (cons_string == NULL) return; |
| 9429 | Initialize(cons_string, offset); |
| 9430 | } |
| 9431 | // Returns NULL when complete. |
| 9432 | inline String* Next(int* offset_out) { |
| 9433 | *offset_out = 0; |
| 9434 | if (depth_ == 0) return NULL; |
| 9435 | return Continue(offset_out); |
| 9436 | } |
| 9437 | |
| 9438 | private: |
| 9439 | static const int kStackSize = 32; |
| 9440 | // Use a mask instead of doing modulo operations for stack wrapping. |
| 9441 | static const int kDepthMask = kStackSize-1; |
| 9442 | STATIC_ASSERT(IS_POWER_OF_TWO(kStackSize)); |
| 9443 | static inline int OffsetForDepth(int depth); |
| 9444 | |
| 9445 | inline void PushLeft(ConsString* string); |
| 9446 | inline void PushRight(ConsString* string); |
| 9447 | inline void AdjustMaximumDepth(); |
| 9448 | inline void Pop(); |
| 9449 | inline bool StackBlown() { return maximum_depth_ - depth_ == kStackSize; } |
| 9450 | void Initialize(ConsString* cons_string, int offset); |
| 9451 | String* Continue(int* offset_out); |
| 9452 | String* NextLeaf(bool* blew_stack); |
| 9453 | String* Search(int* offset_out); |
| 9454 | |
| 9455 | // Stack must always contain only frames for which right traversal |
| 9456 | // has not yet been performed. |
| 9457 | ConsString* frames_[kStackSize]; |
| 9458 | ConsString* root_; |
| 9459 | int depth_; |
| 9460 | int maximum_depth_; |
| 9461 | int consumed_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 9462 | DISALLOW_COPY_AND_ASSIGN(ConsStringIterator); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9463 | }; |
| 9464 | |
| 9465 | |
| 9466 | class StringCharacterStream { |
| 9467 | public: |
| 9468 | inline StringCharacterStream(String* string, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9469 | int offset = 0); |
| 9470 | inline uint16_t GetNext(); |
| 9471 | inline bool HasMore(); |
| 9472 | inline void Reset(String* string, int offset = 0); |
| 9473 | inline void VisitOneByteString(const uint8_t* chars, int length); |
| 9474 | inline void VisitTwoByteString(const uint16_t* chars, int length); |
| 9475 | |
| 9476 | private: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 9477 | ConsStringIterator iter_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9478 | bool is_one_byte_; |
| 9479 | union { |
| 9480 | const uint8_t* buffer8_; |
| 9481 | const uint16_t* buffer16_; |
| 9482 | }; |
| 9483 | const uint8_t* end_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9484 | DISALLOW_COPY_AND_ASSIGN(StringCharacterStream); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9485 | }; |
| 9486 | |
| 9487 | |
| 9488 | template <typename T> |
| 9489 | class VectorIterator { |
| 9490 | public: |
| 9491 | VectorIterator(T* d, int l) : data_(Vector<const T>(d, l)), index_(0) { } |
| 9492 | explicit VectorIterator(Vector<const T> data) : data_(data), index_(0) { } |
| 9493 | T GetNext() { return data_[index_++]; } |
| 9494 | bool has_more() { return index_ < data_.length(); } |
| 9495 | private: |
| 9496 | Vector<const T> data_; |
| 9497 | int index_; |
| 9498 | }; |
| 9499 | |
| 9500 | |
| 9501 | // The Oddball describes objects null, undefined, true, and false. |
| 9502 | class Oddball: public HeapObject { |
| 9503 | public: |
| 9504 | // [to_string]: Cached to_string computed at startup. |
| 9505 | DECL_ACCESSORS(to_string, String) |
| 9506 | |
| 9507 | // [to_number]: Cached to_number computed at startup. |
| 9508 | DECL_ACCESSORS(to_number, Object) |
| 9509 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9510 | // [typeof]: Cached type_of computed at startup. |
| 9511 | DECL_ACCESSORS(type_of, String) |
| 9512 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9513 | inline byte kind() const; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 9514 | inline void set_kind(byte kind); |
| 9515 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9516 | // ES6 section 7.1.3 ToNumber for Boolean, Null, Undefined. |
| 9517 | MUST_USE_RESULT static inline Handle<Object> ToNumber(Handle<Oddball> input); |
| 9518 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9519 | DECLARE_CAST(Oddball) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9520 | |
| 9521 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9522 | DECLARE_VERIFIER(Oddball) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9523 | |
| 9524 | // Initialize the fields. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9525 | static void Initialize(Isolate* isolate, Handle<Oddball> oddball, |
| 9526 | const char* to_string, Handle<Object> to_number, |
| 9527 | const char* type_of, byte kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9528 | |
| 9529 | // Layout description. |
| 9530 | static const int kToStringOffset = HeapObject::kHeaderSize; |
| 9531 | static const int kToNumberOffset = kToStringOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9532 | static const int kTypeOfOffset = kToNumberOffset + kPointerSize; |
| 9533 | static const int kKindOffset = kTypeOfOffset + kPointerSize; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 9534 | static const int kSize = kKindOffset + kPointerSize; |
| 9535 | |
| 9536 | static const byte kFalse = 0; |
| 9537 | static const byte kTrue = 1; |
| 9538 | static const byte kNotBooleanMask = ~1; |
| 9539 | static const byte kTheHole = 2; |
| 9540 | static const byte kNull = 3; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 9541 | static const byte kArgumentsMarker = 4; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 9542 | static const byte kUndefined = 5; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9543 | static const byte kUninitialized = 6; |
| 9544 | static const byte kOther = 7; |
| 9545 | static const byte kException = 8; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9546 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9547 | typedef FixedBodyDescriptor<kToStringOffset, kTypeOfOffset + kPointerSize, |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 9548 | kSize> BodyDescriptor; |
| 9549 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9550 | STATIC_ASSERT(kKindOffset == Internals::kOddballKindOffset); |
| 9551 | STATIC_ASSERT(kNull == Internals::kNullOddballKind); |
| 9552 | STATIC_ASSERT(kUndefined == Internals::kUndefinedOddballKind); |
| 9553 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9554 | private: |
| 9555 | DISALLOW_IMPLICIT_CONSTRUCTORS(Oddball); |
| 9556 | }; |
| 9557 | |
| 9558 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9559 | class Cell: public HeapObject { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9560 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9561 | // [value]: value of the cell. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9562 | DECL_ACCESSORS(value, Object) |
| 9563 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9564 | DECLARE_CAST(Cell) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9565 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9566 | static inline Cell* FromValueAddress(Address value) { |
| 9567 | Object* result = FromAddress(value - kValueOffset); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9568 | return static_cast<Cell*>(result); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 9569 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9570 | |
| 9571 | inline Address ValueAddress() { |
| 9572 | return address() + kValueOffset; |
| 9573 | } |
| 9574 | |
| 9575 | // Dispatched behavior. |
| 9576 | DECLARE_PRINTER(Cell) |
| 9577 | DECLARE_VERIFIER(Cell) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9578 | |
| 9579 | // Layout description. |
| 9580 | static const int kValueOffset = HeapObject::kHeaderSize; |
| 9581 | static const int kSize = kValueOffset + kPointerSize; |
| 9582 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 9583 | typedef FixedBodyDescriptor<kValueOffset, |
| 9584 | kValueOffset + kPointerSize, |
| 9585 | kSize> BodyDescriptor; |
| 9586 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9587 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9588 | DISALLOW_IMPLICIT_CONSTRUCTORS(Cell); |
| 9589 | }; |
| 9590 | |
| 9591 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9592 | class PropertyCell : public HeapObject { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9593 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9594 | // [property_details]: details of the global property. |
| 9595 | DECL_ACCESSORS(property_details_raw, Object) |
| 9596 | // [value]: value of the global property. |
| 9597 | DECL_ACCESSORS(value, Object) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9598 | // [dependent_code]: dependent code that depends on the type of the global |
| 9599 | // property. |
| 9600 | DECL_ACCESSORS(dependent_code, DependentCode) |
| 9601 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9602 | inline PropertyDetails property_details(); |
| 9603 | inline void set_property_details(PropertyDetails details); |
| 9604 | |
| 9605 | PropertyCellConstantType GetConstantType(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9606 | |
| 9607 | // 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] | 9608 | // without actually modifying the details. |
| 9609 | static PropertyCellType UpdatedType(Handle<PropertyCell> cell, |
| 9610 | Handle<Object> value, |
| 9611 | PropertyDetails details); |
| 9612 | static void UpdateCell(Handle<GlobalDictionary> dictionary, int entry, |
| 9613 | Handle<Object> value, PropertyDetails details); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9614 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9615 | static Handle<PropertyCell> InvalidateEntry( |
| 9616 | Handle<GlobalDictionary> dictionary, int entry); |
| 9617 | |
| 9618 | static void SetValueWithInvalidation(Handle<PropertyCell> cell, |
| 9619 | Handle<Object> new_value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9620 | |
| 9621 | DECLARE_CAST(PropertyCell) |
| 9622 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9623 | // Dispatched behavior. |
| 9624 | DECLARE_PRINTER(PropertyCell) |
| 9625 | DECLARE_VERIFIER(PropertyCell) |
| 9626 | |
| 9627 | // Layout description. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9628 | static const int kDetailsOffset = HeapObject::kHeaderSize; |
| 9629 | static const int kValueOffset = kDetailsOffset + kPointerSize; |
| 9630 | static const int kDependentCodeOffset = kValueOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9631 | static const int kSize = kDependentCodeOffset + kPointerSize; |
| 9632 | |
| 9633 | static const int kPointerFieldsBeginOffset = kValueOffset; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9634 | static const int kPointerFieldsEndOffset = kSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9635 | |
| 9636 | typedef FixedBodyDescriptor<kValueOffset, |
| 9637 | kSize, |
| 9638 | kSize> BodyDescriptor; |
| 9639 | |
| 9640 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9641 | DISALLOW_IMPLICIT_CONSTRUCTORS(PropertyCell); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9642 | }; |
| 9643 | |
| 9644 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 9645 | class WeakCell : public HeapObject { |
| 9646 | public: |
| 9647 | inline Object* value() const; |
| 9648 | |
| 9649 | // This should not be called by anyone except GC. |
| 9650 | inline void clear(); |
| 9651 | |
| 9652 | // This should not be called by anyone except allocator. |
| 9653 | inline void initialize(HeapObject* value); |
| 9654 | |
| 9655 | inline bool cleared() const; |
| 9656 | |
| 9657 | DECL_ACCESSORS(next, Object) |
| 9658 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9659 | inline void clear_next(Object* the_hole_value); |
| 9660 | |
| 9661 | inline bool next_cleared(); |
| 9662 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 9663 | DECLARE_CAST(WeakCell) |
| 9664 | |
| 9665 | DECLARE_PRINTER(WeakCell) |
| 9666 | DECLARE_VERIFIER(WeakCell) |
| 9667 | |
| 9668 | // Layout description. |
| 9669 | static const int kValueOffset = HeapObject::kHeaderSize; |
| 9670 | static const int kNextOffset = kValueOffset + kPointerSize; |
| 9671 | static const int kSize = kNextOffset + kPointerSize; |
| 9672 | |
| 9673 | typedef FixedBodyDescriptor<kValueOffset, kSize, kSize> BodyDescriptor; |
| 9674 | |
| 9675 | private: |
| 9676 | DISALLOW_IMPLICIT_CONSTRUCTORS(WeakCell); |
| 9677 | }; |
| 9678 | |
| 9679 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 9680 | // The JSProxy describes EcmaScript Harmony proxies |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 9681 | class JSProxy: public JSReceiver { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9682 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9683 | MUST_USE_RESULT static MaybeHandle<JSProxy> New(Isolate* isolate, |
| 9684 | Handle<Object>, |
| 9685 | Handle<Object>); |
| 9686 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 9687 | // [handler]: The handler property. |
| 9688 | DECL_ACCESSORS(handler, Object) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9689 | // [target]: The target property. |
| 9690 | DECL_ACCESSORS(target, JSReceiver) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9691 | // [hash]: The hash code property (undefined if not initialized yet). |
| 9692 | DECL_ACCESSORS(hash, Object) |
| 9693 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9694 | static MaybeHandle<Context> GetFunctionRealm(Handle<JSProxy> proxy); |
| 9695 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9696 | DECLARE_CAST(JSProxy) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9697 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9698 | INLINE(bool IsRevoked() const); |
| 9699 | static void Revoke(Handle<JSProxy> proxy); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 9700 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9701 | // ES6 9.5.1 |
| 9702 | static MaybeHandle<Object> GetPrototype(Handle<JSProxy> receiver); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9703 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9704 | // ES6 9.5.2 |
| 9705 | MUST_USE_RESULT static Maybe<bool> SetPrototype(Handle<JSProxy> proxy, |
| 9706 | Handle<Object> value, |
| 9707 | bool from_javascript, |
| 9708 | ShouldThrow should_throw); |
| 9709 | // ES6 9.5.3 |
| 9710 | MUST_USE_RESULT static Maybe<bool> IsExtensible(Handle<JSProxy> proxy); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 9711 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9712 | // ES6 9.5.4 (when passed DONT_THROW) |
| 9713 | MUST_USE_RESULT static Maybe<bool> PreventExtensions( |
| 9714 | Handle<JSProxy> proxy, ShouldThrow should_throw); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 9715 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9716 | // ES6 9.5.5 |
| 9717 | MUST_USE_RESULT static Maybe<bool> GetOwnPropertyDescriptor( |
| 9718 | Isolate* isolate, Handle<JSProxy> proxy, Handle<Name> name, |
| 9719 | PropertyDescriptor* desc); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 9720 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9721 | // ES6 9.5.6 |
| 9722 | MUST_USE_RESULT static Maybe<bool> DefineOwnProperty( |
| 9723 | Isolate* isolate, Handle<JSProxy> object, Handle<Object> key, |
| 9724 | PropertyDescriptor* desc, ShouldThrow should_throw); |
| 9725 | |
| 9726 | // ES6 9.5.7 |
| 9727 | MUST_USE_RESULT static Maybe<bool> HasProperty(Isolate* isolate, |
| 9728 | Handle<JSProxy> proxy, |
| 9729 | Handle<Name> name); |
| 9730 | |
| 9731 | // ES6 9.5.8 |
| 9732 | MUST_USE_RESULT static MaybeHandle<Object> GetProperty( |
| 9733 | Isolate* isolate, Handle<JSProxy> proxy, Handle<Name> name, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 9734 | Handle<Object> receiver); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9735 | |
| 9736 | // ES6 9.5.9 |
| 9737 | MUST_USE_RESULT static Maybe<bool> SetProperty(Handle<JSProxy> proxy, |
| 9738 | Handle<Name> name, |
| 9739 | Handle<Object> value, |
| 9740 | Handle<Object> receiver, |
| 9741 | LanguageMode language_mode); |
| 9742 | |
| 9743 | // ES6 9.5.10 (when passed SLOPPY) |
| 9744 | MUST_USE_RESULT static Maybe<bool> DeletePropertyOrElement( |
| 9745 | Handle<JSProxy> proxy, Handle<Name> name, LanguageMode language_mode); |
| 9746 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9747 | // ES6 9.5.12 |
| 9748 | MUST_USE_RESULT static Maybe<bool> OwnPropertyKeys( |
| 9749 | Isolate* isolate, Handle<JSReceiver> receiver, Handle<JSProxy> proxy, |
| 9750 | PropertyFilter filter, KeyAccumulator* accumulator); |
| 9751 | |
| 9752 | MUST_USE_RESULT static Maybe<PropertyAttributes> GetPropertyAttributes( |
| 9753 | LookupIterator* it); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9754 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9755 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9756 | DECLARE_PRINTER(JSProxy) |
| 9757 | DECLARE_VERIFIER(JSProxy) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 9758 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9759 | // Layout description. |
| 9760 | static const int kTargetOffset = JSReceiver::kHeaderSize; |
| 9761 | static const int kHandlerOffset = kTargetOffset + kPointerSize; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9762 | static const int kHashOffset = kHandlerOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9763 | static const int kSize = kHashOffset + kPointerSize; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 9764 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9765 | typedef FixedBodyDescriptor<JSReceiver::kPropertiesOffset, kSize, kSize> |
| 9766 | BodyDescriptor; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9767 | |
| 9768 | MUST_USE_RESULT Object* GetIdentityHash(); |
| 9769 | |
| 9770 | static Handle<Smi> GetOrCreateIdentityHash(Handle<JSProxy> proxy); |
| 9771 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 9772 | static Maybe<bool> SetPrivateProperty(Isolate* isolate, Handle<JSProxy> proxy, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9773 | Handle<Symbol> private_name, |
| 9774 | PropertyDescriptor* desc, |
| 9775 | ShouldThrow should_throw); |
| 9776 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 9777 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9778 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSProxy); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 9779 | }; |
| 9780 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 9781 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9782 | class JSCollection : public JSObject { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9783 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9784 | // [table]: the backing hash table |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9785 | DECL_ACCESSORS(table, Object) |
| 9786 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9787 | static const int kTableOffset = JSObject::kHeaderSize; |
| 9788 | static const int kSize = kTableOffset + kPointerSize; |
| 9789 | |
| 9790 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9791 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSCollection); |
| 9792 | }; |
| 9793 | |
| 9794 | |
| 9795 | // The JSSet describes EcmaScript Harmony sets |
| 9796 | class JSSet : public JSCollection { |
| 9797 | public: |
| 9798 | DECLARE_CAST(JSSet) |
| 9799 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9800 | static void Initialize(Handle<JSSet> set, Isolate* isolate); |
| 9801 | static void Clear(Handle<JSSet> set); |
| 9802 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9803 | // Dispatched behavior. |
| 9804 | DECLARE_PRINTER(JSSet) |
| 9805 | DECLARE_VERIFIER(JSSet) |
| 9806 | |
| 9807 | private: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9808 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSSet); |
| 9809 | }; |
| 9810 | |
| 9811 | |
| 9812 | // The JSMap describes EcmaScript Harmony maps |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9813 | class JSMap : public JSCollection { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9814 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9815 | DECLARE_CAST(JSMap) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9816 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9817 | static void Initialize(Handle<JSMap> map, Isolate* isolate); |
| 9818 | static void Clear(Handle<JSMap> map); |
| 9819 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9820 | // Dispatched behavior. |
| 9821 | DECLARE_PRINTER(JSMap) |
| 9822 | DECLARE_VERIFIER(JSMap) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9823 | |
| 9824 | private: |
| 9825 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSMap); |
| 9826 | }; |
| 9827 | |
| 9828 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9829 | // OrderedHashTableIterator is an iterator that iterates over the keys and |
| 9830 | // values of an OrderedHashTable. |
| 9831 | // |
| 9832 | // The iterator has a reference to the underlying OrderedHashTable data, |
| 9833 | // [table], as well as the current [index] the iterator is at. |
| 9834 | // |
| 9835 | // When the OrderedHashTable is rehashed it adds a reference from the old table |
| 9836 | // to the new table as well as storing enough data about the changes so that the |
| 9837 | // iterator [index] can be adjusted accordingly. |
| 9838 | // |
| 9839 | // When the [Next] result from the iterator is requested, the iterator checks if |
| 9840 | // there is a newer table that it needs to transition to. |
| 9841 | template<class Derived, class TableType> |
| 9842 | class OrderedHashTableIterator: public JSObject { |
| 9843 | public: |
| 9844 | // [table]: the backing hash table mapping keys to values. |
| 9845 | DECL_ACCESSORS(table, Object) |
| 9846 | |
| 9847 | // [index]: The index into the data table. |
| 9848 | DECL_ACCESSORS(index, Object) |
| 9849 | |
| 9850 | // [kind]: The kind of iteration this is. One of the [Kind] enum values. |
| 9851 | DECL_ACCESSORS(kind, Object) |
| 9852 | |
| 9853 | #ifdef OBJECT_PRINT |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 9854 | void OrderedHashTableIteratorPrint(std::ostream& os); // NOLINT |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9855 | #endif |
| 9856 | |
| 9857 | static const int kTableOffset = JSObject::kHeaderSize; |
| 9858 | static const int kIndexOffset = kTableOffset + kPointerSize; |
| 9859 | static const int kKindOffset = kIndexOffset + kPointerSize; |
| 9860 | static const int kSize = kKindOffset + kPointerSize; |
| 9861 | |
| 9862 | enum Kind { |
| 9863 | kKindKeys = 1, |
| 9864 | kKindValues = 2, |
| 9865 | kKindEntries = 3 |
| 9866 | }; |
| 9867 | |
| 9868 | // Whether the iterator has more elements. This needs to be called before |
| 9869 | // calling |CurrentKey| and/or |CurrentValue|. |
| 9870 | bool HasMore(); |
| 9871 | |
| 9872 | // Move the index forward one. |
| 9873 | void MoveNext() { |
| 9874 | set_index(Smi::FromInt(Smi::cast(index())->value() + 1)); |
| 9875 | } |
| 9876 | |
| 9877 | // Populates the array with the next key and value and then moves the iterator |
| 9878 | // forward. |
| 9879 | // This returns the |kind| or 0 if the iterator is already at the end. |
| 9880 | Smi* Next(JSArray* value_array); |
| 9881 | |
| 9882 | // Returns the current key of the iterator. This should only be called when |
| 9883 | // |HasMore| returns true. |
| 9884 | inline Object* CurrentKey(); |
| 9885 | |
| 9886 | private: |
| 9887 | // Transitions the iterator to the non obsolete backing store. This is a NOP |
| 9888 | // if the [table] is not obsolete. |
| 9889 | void Transition(); |
| 9890 | |
| 9891 | DISALLOW_IMPLICIT_CONSTRUCTORS(OrderedHashTableIterator); |
| 9892 | }; |
| 9893 | |
| 9894 | |
| 9895 | class JSSetIterator: public OrderedHashTableIterator<JSSetIterator, |
| 9896 | OrderedHashSet> { |
| 9897 | public: |
| 9898 | // Dispatched behavior. |
| 9899 | DECLARE_PRINTER(JSSetIterator) |
| 9900 | DECLARE_VERIFIER(JSSetIterator) |
| 9901 | |
| 9902 | DECLARE_CAST(JSSetIterator) |
| 9903 | |
| 9904 | // Called by |Next| to populate the array. This allows the subclasses to |
| 9905 | // populate the array differently. |
| 9906 | inline void PopulateValueArray(FixedArray* array); |
| 9907 | |
| 9908 | private: |
| 9909 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSSetIterator); |
| 9910 | }; |
| 9911 | |
| 9912 | |
| 9913 | class JSMapIterator: public OrderedHashTableIterator<JSMapIterator, |
| 9914 | OrderedHashMap> { |
| 9915 | public: |
| 9916 | // Dispatched behavior. |
| 9917 | DECLARE_PRINTER(JSMapIterator) |
| 9918 | DECLARE_VERIFIER(JSMapIterator) |
| 9919 | |
| 9920 | DECLARE_CAST(JSMapIterator) |
| 9921 | |
| 9922 | // Called by |Next| to populate the array. This allows the subclasses to |
| 9923 | // populate the array differently. |
| 9924 | inline void PopulateValueArray(FixedArray* array); |
| 9925 | |
| 9926 | private: |
| 9927 | // Returns the current value of the iterator. This should only be called when |
| 9928 | // |HasMore| returns true. |
| 9929 | inline Object* CurrentValue(); |
| 9930 | |
| 9931 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSMapIterator); |
| 9932 | }; |
| 9933 | |
| 9934 | |
| 9935 | // Base class for both JSWeakMap and JSWeakSet |
| 9936 | class JSWeakCollection: public JSObject { |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 9937 | public: |
| 9938 | // [table]: the backing hash table mapping keys to values. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 9939 | DECL_ACCESSORS(table, Object) |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 9940 | |
| 9941 | // [next]: linked list of encountered weak maps during GC. |
| 9942 | DECL_ACCESSORS(next, Object) |
| 9943 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9944 | static void Initialize(Handle<JSWeakCollection> collection, Isolate* isolate); |
| 9945 | static void Set(Handle<JSWeakCollection> collection, Handle<Object> key, |
| 9946 | Handle<Object> value, int32_t hash); |
| 9947 | static bool Delete(Handle<JSWeakCollection> collection, Handle<Object> key, |
| 9948 | int32_t hash); |
| 9949 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 9950 | static const int kTableOffset = JSObject::kHeaderSize; |
| 9951 | static const int kNextOffset = kTableOffset + kPointerSize; |
| 9952 | static const int kSize = kNextOffset + kPointerSize; |
| 9953 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9954 | // Visiting policy defines whether the table and next collection fields |
| 9955 | // should be visited or not. |
| 9956 | enum BodyVisitingPolicy { kVisitStrong, kVisitWeak }; |
| 9957 | |
| 9958 | // Iterates the function object according to the visiting policy. |
| 9959 | template <BodyVisitingPolicy> |
| 9960 | class BodyDescriptorImpl; |
| 9961 | |
| 9962 | // Visit the whole object. |
| 9963 | typedef BodyDescriptorImpl<kVisitStrong> BodyDescriptor; |
| 9964 | |
| 9965 | // Don't visit table and next collection fields. |
| 9966 | typedef BodyDescriptorImpl<kVisitWeak> BodyDescriptorWeak; |
| 9967 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 9968 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9969 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSWeakCollection); |
| 9970 | }; |
| 9971 | |
| 9972 | |
| 9973 | // The JSWeakMap describes EcmaScript Harmony weak maps |
| 9974 | class JSWeakMap: public JSWeakCollection { |
| 9975 | public: |
| 9976 | DECLARE_CAST(JSWeakMap) |
| 9977 | |
| 9978 | // Dispatched behavior. |
| 9979 | DECLARE_PRINTER(JSWeakMap) |
| 9980 | DECLARE_VERIFIER(JSWeakMap) |
| 9981 | |
| 9982 | private: |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 9983 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSWeakMap); |
| 9984 | }; |
| 9985 | |
| 9986 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9987 | // The JSWeakSet describes EcmaScript Harmony weak sets |
| 9988 | class JSWeakSet: public JSWeakCollection { |
| 9989 | public: |
| 9990 | DECLARE_CAST(JSWeakSet) |
| 9991 | |
| 9992 | // Dispatched behavior. |
| 9993 | DECLARE_PRINTER(JSWeakSet) |
| 9994 | DECLARE_VERIFIER(JSWeakSet) |
| 9995 | |
| 9996 | private: |
| 9997 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSWeakSet); |
| 9998 | }; |
| 9999 | |
| 10000 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10001 | // Whether a JSArrayBuffer is a SharedArrayBuffer or not. |
| 10002 | enum class SharedFlag { kNotShared, kShared }; |
| 10003 | |
| 10004 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10005 | class JSArrayBuffer: public JSObject { |
| 10006 | public: |
| 10007 | // [backing_store]: backing memory for this array |
| 10008 | DECL_ACCESSORS(backing_store, void) |
| 10009 | |
| 10010 | // [byte_length]: length in bytes |
| 10011 | DECL_ACCESSORS(byte_length, Object) |
| 10012 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10013 | inline uint32_t bit_field() const; |
| 10014 | inline void set_bit_field(uint32_t bits); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10015 | |
| 10016 | inline bool is_external(); |
| 10017 | inline void set_is_external(bool value); |
| 10018 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 10019 | inline bool is_neuterable(); |
| 10020 | inline void set_is_neuterable(bool value); |
| 10021 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10022 | inline bool was_neutered(); |
| 10023 | inline void set_was_neutered(bool value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10024 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10025 | inline bool is_shared(); |
| 10026 | inline void set_is_shared(bool value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10027 | |
| 10028 | DECLARE_CAST(JSArrayBuffer) |
| 10029 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10030 | void Neuter(); |
| 10031 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10032 | static void Setup(Handle<JSArrayBuffer> array_buffer, Isolate* isolate, |
| 10033 | bool is_external, void* data, size_t allocated_length, |
| 10034 | SharedFlag shared = SharedFlag::kNotShared); |
| 10035 | |
| 10036 | static bool SetupAllocatingData(Handle<JSArrayBuffer> array_buffer, |
| 10037 | Isolate* isolate, size_t allocated_length, |
| 10038 | bool initialize = true, |
| 10039 | SharedFlag shared = SharedFlag::kNotShared); |
| 10040 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10041 | // Dispatched behavior. |
| 10042 | DECLARE_PRINTER(JSArrayBuffer) |
| 10043 | DECLARE_VERIFIER(JSArrayBuffer) |
| 10044 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10045 | static const int kByteLengthOffset = JSObject::kHeaderSize; |
| 10046 | static const int kBackingStoreOffset = kByteLengthOffset + kPointerSize; |
| 10047 | static const int kBitFieldSlot = kBackingStoreOffset + kPointerSize; |
| 10048 | #if V8_TARGET_LITTLE_ENDIAN || !V8_HOST_ARCH_64_BIT |
| 10049 | static const int kBitFieldOffset = kBitFieldSlot; |
| 10050 | #else |
| 10051 | static const int kBitFieldOffset = kBitFieldSlot + kIntSize; |
| 10052 | #endif |
| 10053 | static const int kSize = kBitFieldSlot + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10054 | |
| 10055 | static const int kSizeWithInternalFields = |
| 10056 | kSize + v8::ArrayBuffer::kInternalFieldCount * kPointerSize; |
| 10057 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10058 | // Iterates all fields in the object including internal ones except |
| 10059 | // kBackingStoreOffset and kBitFieldSlot. |
| 10060 | class BodyDescriptor; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10061 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10062 | class IsExternal : public BitField<bool, 1, 1> {}; |
| 10063 | class IsNeuterable : public BitField<bool, 2, 1> {}; |
| 10064 | class WasNeutered : public BitField<bool, 3, 1> {}; |
| 10065 | class IsShared : public BitField<bool, 4, 1> {}; |
| 10066 | |
| 10067 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10068 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSArrayBuffer); |
| 10069 | }; |
| 10070 | |
| 10071 | |
| 10072 | class JSArrayBufferView: public JSObject { |
| 10073 | public: |
| 10074 | // [buffer]: ArrayBuffer that this typed array views. |
| 10075 | DECL_ACCESSORS(buffer, Object) |
| 10076 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10077 | // [byte_offset]: offset of typed array in bytes. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10078 | DECL_ACCESSORS(byte_offset, Object) |
| 10079 | |
| 10080 | // [byte_length]: length of typed array in bytes. |
| 10081 | DECL_ACCESSORS(byte_length, Object) |
| 10082 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10083 | DECLARE_CAST(JSArrayBufferView) |
| 10084 | |
| 10085 | DECLARE_VERIFIER(JSArrayBufferView) |
| 10086 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10087 | inline bool WasNeutered() const; |
| 10088 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10089 | static const int kBufferOffset = JSObject::kHeaderSize; |
| 10090 | static const int kByteOffsetOffset = kBufferOffset + kPointerSize; |
| 10091 | static const int kByteLengthOffset = kByteOffsetOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10092 | static const int kViewSize = kByteLengthOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10093 | |
| 10094 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10095 | #ifdef VERIFY_HEAP |
| 10096 | DECL_ACCESSORS(raw_byte_offset, Object) |
| 10097 | DECL_ACCESSORS(raw_byte_length, Object) |
| 10098 | #endif |
| 10099 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10100 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSArrayBufferView); |
| 10101 | }; |
| 10102 | |
| 10103 | |
| 10104 | class JSTypedArray: public JSArrayBufferView { |
| 10105 | public: |
| 10106 | // [length]: length of typed array in elements. |
| 10107 | DECL_ACCESSORS(length, Object) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10108 | inline uint32_t length_value() const; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10109 | |
| 10110 | DECLARE_CAST(JSTypedArray) |
| 10111 | |
| 10112 | ExternalArrayType type(); |
| 10113 | size_t element_size(); |
| 10114 | |
| 10115 | Handle<JSArrayBuffer> GetBuffer(); |
| 10116 | |
| 10117 | // Dispatched behavior. |
| 10118 | DECLARE_PRINTER(JSTypedArray) |
| 10119 | DECLARE_VERIFIER(JSTypedArray) |
| 10120 | |
| 10121 | static const int kLengthOffset = kViewSize + kPointerSize; |
| 10122 | static const int kSize = kLengthOffset + kPointerSize; |
| 10123 | |
| 10124 | static const int kSizeWithInternalFields = |
| 10125 | kSize + v8::ArrayBufferView::kInternalFieldCount * kPointerSize; |
| 10126 | |
| 10127 | private: |
| 10128 | static Handle<JSArrayBuffer> MaterializeArrayBuffer( |
| 10129 | Handle<JSTypedArray> typed_array); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10130 | #ifdef VERIFY_HEAP |
| 10131 | DECL_ACCESSORS(raw_length, Object) |
| 10132 | #endif |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10133 | |
| 10134 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSTypedArray); |
| 10135 | }; |
| 10136 | |
| 10137 | |
| 10138 | class JSDataView: public JSArrayBufferView { |
| 10139 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10140 | DECLARE_CAST(JSDataView) |
| 10141 | |
| 10142 | // Dispatched behavior. |
| 10143 | DECLARE_PRINTER(JSDataView) |
| 10144 | DECLARE_VERIFIER(JSDataView) |
| 10145 | |
| 10146 | static const int kSize = kViewSize; |
| 10147 | |
| 10148 | static const int kSizeWithInternalFields = |
| 10149 | kSize + v8::ArrayBufferView::kInternalFieldCount * kPointerSize; |
| 10150 | |
| 10151 | private: |
| 10152 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSDataView); |
| 10153 | }; |
| 10154 | |
| 10155 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 10156 | // Foreign describes objects pointing from JavaScript to C structures. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 10157 | class Foreign: public HeapObject { |
| 10158 | public: |
| 10159 | // [address]: field containing the address. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10160 | inline Address foreign_address(); |
| 10161 | inline void set_foreign_address(Address value); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 10162 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10163 | DECLARE_CAST(Foreign) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 10164 | |
| 10165 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10166 | DECLARE_PRINTER(Foreign) |
| 10167 | DECLARE_VERIFIER(Foreign) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10168 | |
| 10169 | // Layout description. |
| 10170 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10171 | static const int kForeignAddressOffset = HeapObject::kHeaderSize; |
| 10172 | static const int kSize = kForeignAddressOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10173 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10174 | STATIC_ASSERT(kForeignAddressOffset == Internals::kForeignAddressOffset); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10175 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10176 | class BodyDescriptor; |
| 10177 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10178 | private: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 10179 | DISALLOW_IMPLICIT_CONSTRUCTORS(Foreign); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10180 | }; |
| 10181 | |
| 10182 | |
| 10183 | // The JSArray describes JavaScript Arrays |
| 10184 | // Such an array can be in one of two modes: |
| 10185 | // - fast, backing storage is a FixedArray and length <= elements.length(); |
| 10186 | // Please note: push and pop can be used to grow and shrink the array. |
| 10187 | // - slow, backing storage is a HashTable with numbers as keys. |
| 10188 | class JSArray: public JSObject { |
| 10189 | public: |
| 10190 | // [length]: The length property. |
| 10191 | DECL_ACCESSORS(length, Object) |
| 10192 | |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 10193 | // Overload the length setter to skip write barrier when the length |
| 10194 | // is set to a smi. This matches the set function on FixedArray. |
| 10195 | inline void set_length(Smi* length); |
| 10196 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 10197 | static bool HasReadOnlyLength(Handle<JSArray> array); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10198 | static bool WouldChangeReadOnlyLength(Handle<JSArray> array, uint32_t index); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 10199 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10200 | // Initialize the array with the given capacity. The function may |
| 10201 | // fail due to out-of-memory situations, but only if the requested |
| 10202 | // capacity is non-zero. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10203 | static void Initialize(Handle<JSArray> array, int capacity, int length = 0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10204 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10205 | // If the JSArray has fast elements, and new_length would result in |
| 10206 | // normalization, returns true. |
| 10207 | bool SetLengthWouldNormalize(uint32_t new_length); |
| 10208 | static inline bool SetLengthWouldNormalize(Heap* heap, uint32_t new_length); |
| 10209 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10210 | // Initializes the array to a certain length. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10211 | inline bool AllowsSetLength(); |
| 10212 | |
| 10213 | static void SetLength(Handle<JSArray> array, uint32_t length); |
| 10214 | // Same as above but will also queue splice records if |array| is observed. |
| 10215 | static MaybeHandle<Object> ObservableSetLength(Handle<JSArray> array, |
| 10216 | uint32_t length); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10217 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10218 | // Set the content of the array to the content of storage. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10219 | static inline void SetContent(Handle<JSArray> array, |
| 10220 | Handle<FixedArrayBase> storage); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10221 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10222 | // ES6 9.4.2.1 |
| 10223 | MUST_USE_RESULT static Maybe<bool> DefineOwnProperty( |
| 10224 | Isolate* isolate, Handle<JSArray> o, Handle<Object> name, |
| 10225 | PropertyDescriptor* desc, ShouldThrow should_throw); |
| 10226 | |
| 10227 | static bool AnythingToArrayLength(Isolate* isolate, |
| 10228 | Handle<Object> length_object, |
| 10229 | uint32_t* output); |
| 10230 | MUST_USE_RESULT static Maybe<bool> ArraySetLength(Isolate* isolate, |
| 10231 | Handle<JSArray> a, |
| 10232 | PropertyDescriptor* desc, |
| 10233 | ShouldThrow should_throw); |
| 10234 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10235 | DECLARE_CAST(JSArray) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10236 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10237 | // Dispatched behavior. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10238 | DECLARE_PRINTER(JSArray) |
| 10239 | DECLARE_VERIFIER(JSArray) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10240 | |
| 10241 | // Number of element slots to pre-allocate for an empty array. |
| 10242 | static const int kPreallocatedArrayElements = 4; |
| 10243 | |
| 10244 | // Layout description. |
| 10245 | static const int kLengthOffset = JSObject::kHeaderSize; |
| 10246 | static const int kSize = kLengthOffset + kPointerSize; |
| 10247 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10248 | // 600 * KB is the Page::kMaxRegularHeapObjectSize defined in spaces.h which |
| 10249 | // we do not want to include in objects.h |
| 10250 | // Note that Page::kMaxRegularHeapObjectSize has to be in sync with |
| 10251 | // kInitialMaxFastElementArray which is checked in a DCHECK in heap.cc. |
| 10252 | static const int kInitialMaxFastElementArray = |
| 10253 | (600 * KB - FixedArray::kHeaderSize - kSize - AllocationMemento::kSize) / |
| 10254 | kPointerSize; |
| 10255 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10256 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10257 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSArray); |
| 10258 | }; |
| 10259 | |
| 10260 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10261 | Handle<Object> CacheInitialJSArrayMaps(Handle<Context> native_context, |
| 10262 | Handle<Map> initial_map); |
| 10263 | |
| 10264 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 10265 | // JSRegExpResult is just a JSArray with a specific initial map. |
| 10266 | // This initial map adds in-object properties for "index" and "input" |
| 10267 | // properties, as assigned by RegExp.prototype.exec, which allows |
| 10268 | // faster creation of RegExp exec results. |
| 10269 | // This class just holds constants used when creating the result. |
| 10270 | // After creation the result must be treated as a JSArray in all regards. |
| 10271 | class JSRegExpResult: public JSArray { |
| 10272 | public: |
| 10273 | // Offsets of object fields. |
| 10274 | static const int kIndexOffset = JSArray::kSize; |
| 10275 | static const int kInputOffset = kIndexOffset + kPointerSize; |
| 10276 | static const int kSize = kInputOffset + kPointerSize; |
| 10277 | // Indices of in-object properties. |
| 10278 | static const int kIndexIndex = 0; |
| 10279 | static const int kInputIndex = 1; |
| 10280 | private: |
| 10281 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSRegExpResult); |
| 10282 | }; |
| 10283 | |
| 10284 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 10285 | // An accessor must have a getter, but can have no setter. |
| 10286 | // |
| 10287 | // When setting a property, V8 searches accessors in prototypes. |
| 10288 | // If an accessor was found and it does not have a setter, |
| 10289 | // the request is ignored. |
| 10290 | // |
| 10291 | // If the accessor in the prototype has the READ_ONLY property attribute, then |
| 10292 | // a new value is added to the derived object when the property is set. |
| 10293 | // This shadows the accessor in the prototype. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10294 | class AccessorInfo: public Struct { |
| 10295 | public: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10296 | DECL_ACCESSORS(name, Object) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10297 | DECL_INT_ACCESSORS(flag) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10298 | DECL_ACCESSORS(expected_receiver_type, Object) |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 10299 | DECL_ACCESSORS(getter, Object) |
| 10300 | DECL_ACCESSORS(setter, Object) |
| 10301 | DECL_ACCESSORS(data, Object) |
| 10302 | |
| 10303 | // Dispatched behavior. |
| 10304 | DECLARE_PRINTER(AccessorInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10305 | |
| 10306 | inline bool all_can_read(); |
| 10307 | inline void set_all_can_read(bool value); |
| 10308 | |
| 10309 | inline bool all_can_write(); |
| 10310 | inline void set_all_can_write(bool value); |
| 10311 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10312 | inline bool is_special_data_property(); |
| 10313 | inline void set_is_special_data_property(bool value); |
| 10314 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10315 | inline PropertyAttributes property_attributes(); |
| 10316 | inline void set_property_attributes(PropertyAttributes attributes); |
| 10317 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10318 | // Checks whether the given receiver is compatible with this accessor. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10319 | static bool IsCompatibleReceiverMap(Isolate* isolate, |
| 10320 | Handle<AccessorInfo> info, |
| 10321 | Handle<Map> map); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10322 | inline bool IsCompatibleReceiver(Object* receiver); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10323 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10324 | DECLARE_CAST(AccessorInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10325 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10326 | // Dispatched behavior. |
| 10327 | DECLARE_VERIFIER(AccessorInfo) |
| 10328 | |
| 10329 | // Append all descriptors to the array that are not already there. |
| 10330 | // Return number added. |
| 10331 | static int AppendUnique(Handle<Object> descriptors, |
| 10332 | Handle<FixedArray> array, |
| 10333 | int valid_descriptors); |
| 10334 | |
| 10335 | static const int kNameOffset = HeapObject::kHeaderSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10336 | static const int kFlagOffset = kNameOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10337 | static const int kExpectedReceiverTypeOffset = kFlagOffset + kPointerSize; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 10338 | static const int kGetterOffset = kExpectedReceiverTypeOffset + kPointerSize; |
| 10339 | static const int kSetterOffset = kGetterOffset + kPointerSize; |
| 10340 | static const int kDataOffset = kSetterOffset + kPointerSize; |
| 10341 | static const int kSize = kDataOffset + kPointerSize; |
| 10342 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10343 | |
| 10344 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10345 | inline bool HasExpectedReceiverType(); |
| 10346 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10347 | // Bit positions in flag. |
| 10348 | static const int kAllCanReadBit = 0; |
| 10349 | static const int kAllCanWriteBit = 1; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10350 | static const int kSpecialDataProperty = 2; |
| 10351 | class AttributesField : public BitField<PropertyAttributes, 3, 3> {}; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10352 | |
| 10353 | DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorInfo); |
| 10354 | }; |
| 10355 | |
| 10356 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10357 | // Support for JavaScript accessors: A pair of a getter and a setter. Each |
| 10358 | // accessor can either be |
| 10359 | // * a pointer to a JavaScript function or proxy: a real accessor |
| 10360 | // * undefined: considered an accessor by the spec, too, strangely enough |
| 10361 | // * the hole: an accessor which has not been set |
| 10362 | // * a pointer to a map: a transition used to ensure map sharing |
| 10363 | class AccessorPair: public Struct { |
| 10364 | public: |
| 10365 | DECL_ACCESSORS(getter, Object) |
| 10366 | DECL_ACCESSORS(setter, Object) |
| 10367 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10368 | DECLARE_CAST(AccessorPair) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10369 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10370 | static Handle<AccessorPair> Copy(Handle<AccessorPair> pair); |
| 10371 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10372 | inline Object* get(AccessorComponent component); |
| 10373 | inline void set(AccessorComponent component, Object* value); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10374 | |
| 10375 | // Note: Returns undefined instead in case of a hole. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 10376 | static Handle<Object> GetComponent(Handle<AccessorPair> accessor_pair, |
| 10377 | AccessorComponent component); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10378 | |
| 10379 | // Set both components, skipping arguments which are a JavaScript null. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10380 | inline void SetComponents(Object* getter, Object* setter); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10381 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10382 | inline bool Equals(AccessorPair* pair); |
| 10383 | inline bool Equals(Object* getter_value, Object* setter_value); |
| 10384 | |
| 10385 | inline bool ContainsAccessor(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10386 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10387 | // Dispatched behavior. |
| 10388 | DECLARE_PRINTER(AccessorPair) |
| 10389 | DECLARE_VERIFIER(AccessorPair) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10390 | |
| 10391 | static const int kGetterOffset = HeapObject::kHeaderSize; |
| 10392 | static const int kSetterOffset = kGetterOffset + kPointerSize; |
| 10393 | static const int kSize = kSetterOffset + kPointerSize; |
| 10394 | |
| 10395 | private: |
| 10396 | // Strangely enough, in addition to functions and harmony proxies, the spec |
| 10397 | // requires us to consider undefined as a kind of accessor, too: |
| 10398 | // var obj = {}; |
| 10399 | // Object.defineProperty(obj, "foo", {get: undefined}); |
| 10400 | // assertTrue("foo" in obj); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10401 | inline bool IsJSAccessor(Object* obj); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10402 | |
| 10403 | DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorPair); |
| 10404 | }; |
| 10405 | |
| 10406 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10407 | class AccessCheckInfo: public Struct { |
| 10408 | public: |
| 10409 | DECL_ACCESSORS(named_callback, Object) |
| 10410 | DECL_ACCESSORS(indexed_callback, Object) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10411 | DECL_ACCESSORS(callback, Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10412 | DECL_ACCESSORS(data, Object) |
| 10413 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10414 | DECLARE_CAST(AccessCheckInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10415 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10416 | // Dispatched behavior. |
| 10417 | DECLARE_PRINTER(AccessCheckInfo) |
| 10418 | DECLARE_VERIFIER(AccessCheckInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10419 | |
| 10420 | static const int kNamedCallbackOffset = HeapObject::kHeaderSize; |
| 10421 | static const int kIndexedCallbackOffset = kNamedCallbackOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10422 | static const int kCallbackOffset = kIndexedCallbackOffset + kPointerSize; |
| 10423 | static const int kDataOffset = kCallbackOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10424 | static const int kSize = kDataOffset + kPointerSize; |
| 10425 | |
| 10426 | private: |
| 10427 | DISALLOW_IMPLICIT_CONSTRUCTORS(AccessCheckInfo); |
| 10428 | }; |
| 10429 | |
| 10430 | |
| 10431 | class InterceptorInfo: public Struct { |
| 10432 | public: |
| 10433 | DECL_ACCESSORS(getter, Object) |
| 10434 | DECL_ACCESSORS(setter, Object) |
| 10435 | DECL_ACCESSORS(query, Object) |
| 10436 | DECL_ACCESSORS(deleter, Object) |
| 10437 | DECL_ACCESSORS(enumerator, Object) |
| 10438 | DECL_ACCESSORS(data, Object) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 10439 | DECL_BOOLEAN_ACCESSORS(can_intercept_symbols) |
| 10440 | DECL_BOOLEAN_ACCESSORS(all_can_read) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10441 | DECL_BOOLEAN_ACCESSORS(non_masking) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 10442 | |
| 10443 | inline int flags() const; |
| 10444 | inline void set_flags(int flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10445 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10446 | DECLARE_CAST(InterceptorInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10447 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10448 | // Dispatched behavior. |
| 10449 | DECLARE_PRINTER(InterceptorInfo) |
| 10450 | DECLARE_VERIFIER(InterceptorInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10451 | |
| 10452 | static const int kGetterOffset = HeapObject::kHeaderSize; |
| 10453 | static const int kSetterOffset = kGetterOffset + kPointerSize; |
| 10454 | static const int kQueryOffset = kSetterOffset + kPointerSize; |
| 10455 | static const int kDeleterOffset = kQueryOffset + kPointerSize; |
| 10456 | static const int kEnumeratorOffset = kDeleterOffset + kPointerSize; |
| 10457 | static const int kDataOffset = kEnumeratorOffset + kPointerSize; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 10458 | static const int kFlagsOffset = kDataOffset + kPointerSize; |
| 10459 | static const int kSize = kFlagsOffset + kPointerSize; |
| 10460 | |
| 10461 | static const int kCanInterceptSymbolsBit = 0; |
| 10462 | static const int kAllCanReadBit = 1; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10463 | static const int kNonMasking = 2; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10464 | |
| 10465 | private: |
| 10466 | DISALLOW_IMPLICIT_CONSTRUCTORS(InterceptorInfo); |
| 10467 | }; |
| 10468 | |
| 10469 | |
| 10470 | class CallHandlerInfo: public Struct { |
| 10471 | public: |
| 10472 | DECL_ACCESSORS(callback, Object) |
| 10473 | DECL_ACCESSORS(data, Object) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10474 | DECL_ACCESSORS(fast_handler, Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10475 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10476 | DECLARE_CAST(CallHandlerInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10477 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10478 | // Dispatched behavior. |
| 10479 | DECLARE_PRINTER(CallHandlerInfo) |
| 10480 | DECLARE_VERIFIER(CallHandlerInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10481 | |
| 10482 | static const int kCallbackOffset = HeapObject::kHeaderSize; |
| 10483 | static const int kDataOffset = kCallbackOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10484 | static const int kFastHandlerOffset = kDataOffset + kPointerSize; |
| 10485 | static const int kSize = kFastHandlerOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10486 | |
| 10487 | private: |
| 10488 | DISALLOW_IMPLICIT_CONSTRUCTORS(CallHandlerInfo); |
| 10489 | }; |
| 10490 | |
| 10491 | |
| 10492 | class TemplateInfo: public Struct { |
| 10493 | public: |
| 10494 | DECL_ACCESSORS(tag, Object) |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 10495 | DECL_ACCESSORS(serial_number, Object) |
| 10496 | DECL_INT_ACCESSORS(number_of_properties) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10497 | DECL_ACCESSORS(property_list, Object) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10498 | DECL_ACCESSORS(property_accessors, Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10499 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10500 | DECLARE_VERIFIER(TemplateInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10501 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10502 | static const int kTagOffset = HeapObject::kHeaderSize; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 10503 | static const int kSerialNumberOffset = kTagOffset + kPointerSize; |
| 10504 | static const int kNumberOfProperties = kSerialNumberOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10505 | static const int kPropertyListOffset = kNumberOfProperties + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10506 | static const int kPropertyAccessorsOffset = |
| 10507 | kPropertyListOffset + kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10508 | static const int kPropertyIntrinsicsOffset = |
| 10509 | kPropertyAccessorsOffset + kPointerSize; |
| 10510 | static const int kHeaderSize = kPropertyIntrinsicsOffset + kPointerSize; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10511 | |
| 10512 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10513 | DISALLOW_IMPLICIT_CONSTRUCTORS(TemplateInfo); |
| 10514 | }; |
| 10515 | |
| 10516 | |
| 10517 | class FunctionTemplateInfo: public TemplateInfo { |
| 10518 | public: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10519 | DECL_ACCESSORS(call_code, Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10520 | DECL_ACCESSORS(prototype_template, Object) |
| 10521 | DECL_ACCESSORS(parent_template, Object) |
| 10522 | DECL_ACCESSORS(named_property_handler, Object) |
| 10523 | DECL_ACCESSORS(indexed_property_handler, Object) |
| 10524 | DECL_ACCESSORS(instance_template, Object) |
| 10525 | DECL_ACCESSORS(class_name, Object) |
| 10526 | DECL_ACCESSORS(signature, Object) |
| 10527 | DECL_ACCESSORS(instance_call_handler, Object) |
| 10528 | DECL_ACCESSORS(access_check_info, Object) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10529 | DECL_INT_ACCESSORS(flag) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10530 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10531 | inline int length() const; |
| 10532 | inline void set_length(int value); |
| 10533 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10534 | // Following properties use flag bits. |
| 10535 | DECL_BOOLEAN_ACCESSORS(hidden_prototype) |
| 10536 | DECL_BOOLEAN_ACCESSORS(undetectable) |
| 10537 | // If the bit is set, object instances created by this function |
| 10538 | // requires access check. |
| 10539 | DECL_BOOLEAN_ACCESSORS(needs_access_check) |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 10540 | DECL_BOOLEAN_ACCESSORS(read_only_prototype) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10541 | DECL_BOOLEAN_ACCESSORS(remove_prototype) |
| 10542 | DECL_BOOLEAN_ACCESSORS(do_not_cache) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10543 | DECL_BOOLEAN_ACCESSORS(instantiated) |
| 10544 | DECL_BOOLEAN_ACCESSORS(accept_any_receiver) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10545 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10546 | DECLARE_CAST(FunctionTemplateInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10547 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10548 | // Dispatched behavior. |
| 10549 | DECLARE_PRINTER(FunctionTemplateInfo) |
| 10550 | DECLARE_VERIFIER(FunctionTemplateInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10551 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 10552 | static const int kCallCodeOffset = TemplateInfo::kHeaderSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10553 | static const int kPrototypeTemplateOffset = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10554 | kCallCodeOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10555 | static const int kParentTemplateOffset = |
| 10556 | kPrototypeTemplateOffset + kPointerSize; |
| 10557 | static const int kNamedPropertyHandlerOffset = |
| 10558 | kParentTemplateOffset + kPointerSize; |
| 10559 | static const int kIndexedPropertyHandlerOffset = |
| 10560 | kNamedPropertyHandlerOffset + kPointerSize; |
| 10561 | static const int kInstanceTemplateOffset = |
| 10562 | kIndexedPropertyHandlerOffset + kPointerSize; |
| 10563 | static const int kClassNameOffset = kInstanceTemplateOffset + kPointerSize; |
| 10564 | static const int kSignatureOffset = kClassNameOffset + kPointerSize; |
| 10565 | static const int kInstanceCallHandlerOffset = kSignatureOffset + kPointerSize; |
| 10566 | static const int kAccessCheckInfoOffset = |
| 10567 | kInstanceCallHandlerOffset + kPointerSize; |
| 10568 | static const int kFlagOffset = kAccessCheckInfoOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10569 | static const int kLengthOffset = kFlagOffset + kPointerSize; |
| 10570 | static const int kSize = kLengthOffset + kPointerSize; |
| 10571 | |
| 10572 | // Returns true if |object| is an instance of this function template. |
| 10573 | bool IsTemplateFor(Object* object); |
| 10574 | bool IsTemplateFor(Map* map); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10575 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10576 | // Returns the holder JSObject if the function can legally be called with this |
| 10577 | // receiver. Returns Heap::null_value() if the call is illegal. |
| 10578 | Object* GetCompatibleReceiver(Isolate* isolate, Object* receiver); |
| 10579 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10580 | private: |
| 10581 | // Bit position in the flag, from least significant bit position. |
| 10582 | static const int kHiddenPrototypeBit = 0; |
| 10583 | static const int kUndetectableBit = 1; |
| 10584 | static const int kNeedsAccessCheckBit = 2; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 10585 | static const int kReadOnlyPrototypeBit = 3; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10586 | static const int kRemovePrototypeBit = 4; |
| 10587 | static const int kDoNotCacheBit = 5; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10588 | static const int kInstantiatedBit = 6; |
| 10589 | static const int kAcceptAnyReceiver = 7; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10590 | |
| 10591 | DISALLOW_IMPLICIT_CONSTRUCTORS(FunctionTemplateInfo); |
| 10592 | }; |
| 10593 | |
| 10594 | |
| 10595 | class ObjectTemplateInfo: public TemplateInfo { |
| 10596 | public: |
| 10597 | DECL_ACCESSORS(constructor, Object) |
| 10598 | DECL_ACCESSORS(internal_field_count, Object) |
| 10599 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10600 | DECLARE_CAST(ObjectTemplateInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10601 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10602 | // Dispatched behavior. |
| 10603 | DECLARE_PRINTER(ObjectTemplateInfo) |
| 10604 | DECLARE_VERIFIER(ObjectTemplateInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10605 | |
| 10606 | static const int kConstructorOffset = TemplateInfo::kHeaderSize; |
| 10607 | static const int kInternalFieldCountOffset = |
| 10608 | kConstructorOffset + kPointerSize; |
| 10609 | static const int kSize = kInternalFieldCountOffset + kPointerSize; |
| 10610 | }; |
| 10611 | |
| 10612 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10613 | // The DebugInfo class holds additional information for a function being |
| 10614 | // debugged. |
| 10615 | class DebugInfo: public Struct { |
| 10616 | public: |
| 10617 | // The shared function info for the source being debugged. |
| 10618 | DECL_ACCESSORS(shared, SharedFunctionInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10619 | // Code object for the patched code. This code object is the code object |
| 10620 | // currently active for the function. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 10621 | DECL_ACCESSORS(abstract_code, AbstractCode) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10622 | // Fixed array holding status information for each active break point. |
| 10623 | DECL_ACCESSORS(break_points, FixedArray) |
| 10624 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 10625 | // Check if there is a break point at a code offset. |
| 10626 | bool HasBreakPoint(int code_offset); |
| 10627 | // Get the break point info object for a code offset. |
| 10628 | Object* GetBreakPointInfo(int code_offset); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10629 | // Clear a break point. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 10630 | static void ClearBreakPoint(Handle<DebugInfo> debug_info, int code_offset, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10631 | Handle<Object> break_point_object); |
| 10632 | // Set a break point. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 10633 | static void SetBreakPoint(Handle<DebugInfo> debug_info, int code_offset, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10634 | int source_position, int statement_position, |
| 10635 | Handle<Object> break_point_object); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 10636 | // Get the break point objects for a code offset. |
| 10637 | Handle<Object> GetBreakPointObjects(int code_offset); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10638 | // Find the break point info holding this break point object. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10639 | static Handle<Object> FindBreakPointInfo(Handle<DebugInfo> debug_info, |
| 10640 | Handle<Object> break_point_object); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10641 | // Get the number of break points for this function. |
| 10642 | int GetBreakPointCount(); |
| 10643 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 10644 | static Smi* uninitialized() { return Smi::FromInt(0); } |
| 10645 | |
| 10646 | inline BytecodeArray* original_bytecode_array(); |
| 10647 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10648 | DECLARE_CAST(DebugInfo) |
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 | // Dispatched behavior. |
| 10651 | DECLARE_PRINTER(DebugInfo) |
| 10652 | DECLARE_VERIFIER(DebugInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10653 | |
| 10654 | static const int kSharedFunctionInfoIndex = Struct::kHeaderSize; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 10655 | static const int kAbstractCodeIndex = kSharedFunctionInfoIndex + kPointerSize; |
| 10656 | static const int kBreakPointsStateIndex = kAbstractCodeIndex + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10657 | static const int kSize = kBreakPointsStateIndex + kPointerSize; |
| 10658 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10659 | static const int kEstimatedNofBreakPointsInFunction = 16; |
| 10660 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10661 | private: |
| 10662 | static const int kNoBreakPointInfo = -1; |
| 10663 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 10664 | // Lookup the index in the break_points array for a code offset. |
| 10665 | int GetBreakPointInfoIndex(int code_offset); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10666 | |
| 10667 | DISALLOW_IMPLICIT_CONSTRUCTORS(DebugInfo); |
| 10668 | }; |
| 10669 | |
| 10670 | |
| 10671 | // The BreakPointInfo class holds information for break points set in a |
| 10672 | // function. The DebugInfo object holds a BreakPointInfo object for each code |
| 10673 | // position with one or more break points. |
| 10674 | class BreakPointInfo: public Struct { |
| 10675 | public: |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 10676 | // The code offset for the break point. |
| 10677 | DECL_INT_ACCESSORS(code_offset) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10678 | // The position in the source for the break position. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10679 | DECL_INT_ACCESSORS(source_position) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10680 | // The position in the source for the last statement before this break |
| 10681 | // position. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10682 | DECL_INT_ACCESSORS(statement_position) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10683 | // List of related JavaScript break points. |
| 10684 | DECL_ACCESSORS(break_point_objects, Object) |
| 10685 | |
| 10686 | // Removes a break point. |
| 10687 | static void ClearBreakPoint(Handle<BreakPointInfo> info, |
| 10688 | Handle<Object> break_point_object); |
| 10689 | // Set a break point. |
| 10690 | static void SetBreakPoint(Handle<BreakPointInfo> info, |
| 10691 | Handle<Object> break_point_object); |
| 10692 | // Check if break point info has this break point object. |
| 10693 | static bool HasBreakPointObject(Handle<BreakPointInfo> info, |
| 10694 | Handle<Object> break_point_object); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 10695 | // Get the number of break points for this code offset. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10696 | int GetBreakPointCount(); |
| 10697 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10698 | DECLARE_CAST(BreakPointInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10699 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10700 | // Dispatched behavior. |
| 10701 | DECLARE_PRINTER(BreakPointInfo) |
| 10702 | DECLARE_VERIFIER(BreakPointInfo) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10703 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 10704 | static const int kCodeOffsetIndex = Struct::kHeaderSize; |
| 10705 | static const int kSourcePositionIndex = kCodeOffsetIndex + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10706 | static const int kStatementPositionIndex = |
| 10707 | kSourcePositionIndex + kPointerSize; |
| 10708 | static const int kBreakPointObjectsIndex = |
| 10709 | kStatementPositionIndex + kPointerSize; |
| 10710 | static const int kSize = kBreakPointObjectsIndex + kPointerSize; |
| 10711 | |
| 10712 | private: |
| 10713 | DISALLOW_IMPLICIT_CONSTRUCTORS(BreakPointInfo); |
| 10714 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10715 | |
| 10716 | |
| 10717 | #undef DECL_BOOLEAN_ACCESSORS |
| 10718 | #undef DECL_ACCESSORS |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10719 | #undef DECLARE_CAST |
| 10720 | #undef DECLARE_VERIFIER |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10721 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10722 | #define VISITOR_SYNCHRONIZATION_TAGS_LIST(V) \ |
| 10723 | V(kStringTable, "string_table", "(Internalized strings)") \ |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10724 | V(kExternalStringsTable, "external_strings_table", "(External strings)") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10725 | V(kStrongRootList, "strong_root_list", "(Strong roots)") \ |
| 10726 | V(kSmiRootList, "smi_root_list", "(Smi roots)") \ |
| 10727 | V(kBootstrapper, "bootstrapper", "(Bootstrapper)") \ |
| 10728 | V(kTop, "top", "(Isolate)") \ |
| 10729 | V(kRelocatable, "relocatable", "(Relocatable)") \ |
| 10730 | V(kDebug, "debug", "(Debugger)") \ |
| 10731 | V(kCompilationCache, "compilationcache", "(Compilation cache)") \ |
| 10732 | V(kHandleScope, "handlescope", "(Handle scope)") \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 10733 | V(kDispatchTable, "dispatchtable", "(Dispatch table)") \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10734 | V(kBuiltins, "builtins", "(Builtins)") \ |
| 10735 | V(kGlobalHandles, "globalhandles", "(Global handles)") \ |
| 10736 | V(kEternalHandles, "eternalhandles", "(Eternal handles)") \ |
| 10737 | V(kThreadManager, "threadmanager", "(Thread manager)") \ |
| 10738 | V(kStrongRoots, "strong roots", "(Strong roots)") \ |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10739 | V(kExtensions, "Extensions", "(Extensions)") |
| 10740 | |
| 10741 | class VisitorSynchronization : public AllStatic { |
| 10742 | public: |
| 10743 | #define DECLARE_ENUM(enum_item, ignore1, ignore2) enum_item, |
| 10744 | enum SyncTag { |
| 10745 | VISITOR_SYNCHRONIZATION_TAGS_LIST(DECLARE_ENUM) |
| 10746 | kNumberOfSyncTags |
| 10747 | }; |
| 10748 | #undef DECLARE_ENUM |
| 10749 | |
| 10750 | static const char* const kTags[kNumberOfSyncTags]; |
| 10751 | static const char* const kTagNames[kNumberOfSyncTags]; |
| 10752 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10753 | |
| 10754 | // Abstract base class for visiting, and optionally modifying, the |
| 10755 | // pointers contained in Objects. Used in GC and serialization/deserialization. |
| 10756 | class ObjectVisitor BASE_EMBEDDED { |
| 10757 | public: |
| 10758 | virtual ~ObjectVisitor() {} |
| 10759 | |
| 10760 | // Visits a contiguous arrays of pointers in the half-open range |
| 10761 | // [start, end). Any or all of the values may be modified on return. |
| 10762 | virtual void VisitPointers(Object** start, Object** end) = 0; |
| 10763 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10764 | // Handy shorthand for visiting a single pointer. |
| 10765 | virtual void VisitPointer(Object** p) { VisitPointers(p, p + 1); } |
| 10766 | |
| 10767 | // Visit weak next_code_link in Code object. |
| 10768 | virtual void VisitNextCodeLink(Object** p) { VisitPointers(p, p + 1); } |
| 10769 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10770 | // To allow lazy clearing of inline caches the visitor has |
| 10771 | // a rich interface for iterating over Code objects.. |
| 10772 | |
| 10773 | // Visits a code target in the instruction stream. |
| 10774 | virtual void VisitCodeTarget(RelocInfo* rinfo); |
| 10775 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 10776 | // Visits a code entry in a JS function. |
| 10777 | virtual void VisitCodeEntry(Address entry_address); |
| 10778 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 10779 | // Visits a global property cell reference in the instruction stream. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10780 | virtual void VisitCell(RelocInfo* rinfo); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 10781 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10782 | // Visits a runtime entry in the instruction stream. |
| 10783 | virtual void VisitRuntimeEntry(RelocInfo* rinfo) {} |
| 10784 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10785 | // Visits the resource of an one-byte or two-byte string. |
| 10786 | virtual void VisitExternalOneByteString( |
| 10787 | v8::String::ExternalOneByteStringResource** resource) {} |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 10788 | virtual void VisitExternalTwoByteString( |
| 10789 | v8::String::ExternalStringResource** resource) {} |
| 10790 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10791 | // Visits a debug call target in the instruction stream. |
| 10792 | virtual void VisitDebugTarget(RelocInfo* rinfo); |
| 10793 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10794 | // Visits the byte sequence in a function's prologue that contains information |
| 10795 | // about the code's age. |
| 10796 | virtual void VisitCodeAgeSequence(RelocInfo* rinfo); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10797 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10798 | // Visit pointer embedded into a code object. |
| 10799 | virtual void VisitEmbeddedPointer(RelocInfo* rinfo); |
| 10800 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10801 | // Visits an external reference embedded into a code object. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 10802 | virtual void VisitExternalReference(RelocInfo* rinfo); |
| 10803 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10804 | // Visits an external reference. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10805 | virtual void VisitExternalReference(Address* p) {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10806 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10807 | // Visits an (encoded) internal reference. |
| 10808 | virtual void VisitInternalReference(RelocInfo* rinfo) {} |
| 10809 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 10810 | // Visits a handle that has an embedder-assigned class ID. |
| 10811 | virtual void VisitEmbedderReference(Object** p, uint16_t class_id) {} |
| 10812 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10813 | // Intended for serialization/deserialization checking: insert, or |
| 10814 | // 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] | 10815 | // Also used for marking up GC roots in heap snapshots. |
| 10816 | virtual void Synchronize(VisitorSynchronization::SyncTag tag) {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10817 | }; |
| 10818 | |
| 10819 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10820 | // 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] | 10821 | class BooleanBit : public AllStatic { |
| 10822 | public: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10823 | static inline bool get(int value, int bit_position) { |
| 10824 | return (value & (1 << bit_position)) != 0; |
| 10825 | } |
| 10826 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10827 | static inline int set(int value, int bit_position, bool v) { |
| 10828 | if (v) { |
| 10829 | value |= (1 << bit_position); |
| 10830 | } else { |
| 10831 | value &= ~(1 << bit_position); |
| 10832 | } |
| 10833 | return value; |
| 10834 | } |
| 10835 | }; |
| 10836 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10837 | |
| 10838 | } // NOLINT, false-positive due to second-order macros. |
| 10839 | } // NOLINT, false-positive due to second-order macros. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10840 | |
| 10841 | #endif // V8_OBJECTS_H_ |