Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #ifndef V8_OBJECTS_H_ |
| 29 | #define V8_OBJECTS_H_ |
| 30 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 31 | #include "allocation.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 32 | #include "builtins.h" |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 33 | #include "list.h" |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 34 | #include "property-details.h" |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 35 | #include "smart-array-pointer.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 36 | #include "unicode-inl.h" |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 37 | #if V8_TARGET_ARCH_ARM |
| 38 | #include "arm/constants-arm.h" |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 39 | #elif V8_TARGET_ARCH_MIPS |
| 40 | #include "mips/constants-mips.h" |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 41 | #endif |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 42 | #include "v8checks.h" |
| 43 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 44 | |
| 45 | // |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 46 | // Most object types in the V8 JavaScript are described in this file. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 47 | // |
| 48 | // Inheritance hierarchy: |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 49 | // - MaybeObject (an object or a failure) |
| 50 | // - Failure (immediate for marking failed operation) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 51 | // - Object |
| 52 | // - Smi (immediate small integer) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 53 | // - HeapObject (superclass for everything allocated in the heap) |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 54 | // - JSReceiver (suitable for property access) |
| 55 | // - JSObject |
| 56 | // - JSArray |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 57 | // - JSSet |
| 58 | // - JSMap |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 59 | // - JSWeakMap |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 60 | // - JSRegExp |
| 61 | // - JSFunction |
| 62 | // - GlobalObject |
| 63 | // - JSGlobalObject |
| 64 | // - JSBuiltinsObject |
| 65 | // - JSGlobalProxy |
| 66 | // - JSValue |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 67 | // - JSDate |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 68 | // - JSMessageObject |
| 69 | // - JSProxy |
| 70 | // - JSFunctionProxy |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 71 | // - FixedArrayBase |
| 72 | // - ByteArray |
| 73 | // - FixedArray |
| 74 | // - DescriptorArray |
| 75 | // - HashTable |
| 76 | // - Dictionary |
| 77 | // - SymbolTable |
| 78 | // - CompilationCacheTable |
| 79 | // - CodeCacheHashTable |
| 80 | // - MapCache |
| 81 | // - Context |
| 82 | // - JSFunctionResultCache |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 83 | // - ScopeInfo |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 84 | // - FixedDoubleArray |
| 85 | // - ExternalArray |
| 86 | // - ExternalPixelArray |
| 87 | // - ExternalByteArray |
| 88 | // - ExternalUnsignedByteArray |
| 89 | // - ExternalShortArray |
| 90 | // - ExternalUnsignedShortArray |
| 91 | // - ExternalIntArray |
| 92 | // - ExternalUnsignedIntArray |
| 93 | // - ExternalFloatArray |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 94 | // - String |
| 95 | // - SeqString |
| 96 | // - SeqAsciiString |
| 97 | // - SeqTwoByteString |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 98 | // - SlicedString |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 99 | // - ConsString |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 100 | // - ExternalString |
| 101 | // - ExternalAsciiString |
| 102 | // - ExternalTwoByteString |
| 103 | // - HeapNumber |
| 104 | // - Code |
| 105 | // - Map |
| 106 | // - Oddball |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 107 | // - Foreign |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 108 | // - SharedFunctionInfo |
| 109 | // - Struct |
| 110 | // - AccessorInfo |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 111 | // - AccessorPair |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 112 | // - AccessCheckInfo |
| 113 | // - InterceptorInfo |
| 114 | // - CallHandlerInfo |
| 115 | // - TemplateInfo |
| 116 | // - FunctionTemplateInfo |
| 117 | // - ObjectTemplateInfo |
| 118 | // - Script |
| 119 | // - SignatureInfo |
| 120 | // - TypeSwitchInfo |
| 121 | // - DebugInfo |
| 122 | // - BreakPointInfo |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 123 | // - CodeCache |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 124 | // |
| 125 | // Formats of Object*: |
| 126 | // Smi: [31 bit signed int] 0 |
| 127 | // HeapObject: [32 bit direct pointer] (4 byte aligned) | 01 |
| 128 | // Failure: [30 bit signed int] 11 |
| 129 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 130 | namespace v8 { |
| 131 | namespace internal { |
| 132 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 133 | enum ElementsKind { |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 134 | // The "fast" kind for elements that only contain SMI values. Must be first |
| 135 | // to make it possible to efficiently check maps for this kind. |
| 136 | FAST_SMI_ONLY_ELEMENTS, |
| 137 | |
| 138 | // The "fast" kind for tagged values. Must be second to make it possible to |
| 139 | // efficiently check maps for this and the FAST_SMI_ONLY_ELEMENTS kind |
| 140 | // together at once. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 141 | FAST_ELEMENTS, |
| 142 | |
| 143 | // The "fast" kind for unwrapped, non-tagged double values. |
| 144 | FAST_DOUBLE_ELEMENTS, |
| 145 | |
| 146 | // The "slow" kind. |
| 147 | DICTIONARY_ELEMENTS, |
| 148 | NON_STRICT_ARGUMENTS_ELEMENTS, |
| 149 | // The "fast" kind for external arrays |
| 150 | EXTERNAL_BYTE_ELEMENTS, |
| 151 | EXTERNAL_UNSIGNED_BYTE_ELEMENTS, |
| 152 | EXTERNAL_SHORT_ELEMENTS, |
| 153 | EXTERNAL_UNSIGNED_SHORT_ELEMENTS, |
| 154 | EXTERNAL_INT_ELEMENTS, |
| 155 | EXTERNAL_UNSIGNED_INT_ELEMENTS, |
| 156 | EXTERNAL_FLOAT_ELEMENTS, |
| 157 | EXTERNAL_DOUBLE_ELEMENTS, |
| 158 | EXTERNAL_PIXEL_ELEMENTS, |
| 159 | |
| 160 | // Derived constants from ElementsKind |
| 161 | FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND = EXTERNAL_BYTE_ELEMENTS, |
| 162 | LAST_EXTERNAL_ARRAY_ELEMENTS_KIND = EXTERNAL_PIXEL_ELEMENTS, |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 163 | FIRST_ELEMENTS_KIND = FAST_SMI_ONLY_ELEMENTS, |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 164 | LAST_ELEMENTS_KIND = EXTERNAL_PIXEL_ELEMENTS |
| 165 | }; |
| 166 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 167 | enum CompareMapMode { |
| 168 | REQUIRE_EXACT_MAP, |
| 169 | ALLOW_ELEMENT_TRANSITION_MAPS |
| 170 | }; |
| 171 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 172 | enum KeyedAccessGrowMode { |
| 173 | DO_NOT_ALLOW_JSARRAY_GROWTH, |
| 174 | ALLOW_JSARRAY_GROWTH |
| 175 | }; |
| 176 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 177 | const int kElementsKindCount = LAST_ELEMENTS_KIND - FIRST_ELEMENTS_KIND + 1; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 178 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 179 | void PrintElementsKind(FILE* out, ElementsKind kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 180 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 181 | inline bool IsMoreGeneralElementsKindTransition(ElementsKind from_kind, |
| 182 | ElementsKind to_kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 183 | |
| 184 | // Setter that skips the write barrier if mode is SKIP_WRITE_BARRIER. |
| 185 | enum WriteBarrierMode { SKIP_WRITE_BARRIER, UPDATE_WRITE_BARRIER }; |
| 186 | |
| 187 | |
| 188 | // PropertyNormalizationMode is used to specify whether to keep |
| 189 | // inobject properties when normalizing properties of a JSObject. |
| 190 | enum PropertyNormalizationMode { |
| 191 | CLEAR_INOBJECT_PROPERTIES, |
| 192 | KEEP_INOBJECT_PROPERTIES |
| 193 | }; |
| 194 | |
| 195 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 196 | // NormalizedMapSharingMode is used to specify whether a map may be shared |
| 197 | // by different objects with normalized properties. |
| 198 | enum NormalizedMapSharingMode { |
| 199 | UNIQUE_NORMALIZED_MAP, |
| 200 | SHARED_NORMALIZED_MAP |
| 201 | }; |
| 202 | |
| 203 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 204 | // Indicates whether a get method should implicitly create the object looked up. |
| 205 | enum CreationFlag { |
| 206 | ALLOW_CREATION, |
| 207 | OMIT_CREATION |
| 208 | }; |
| 209 | |
| 210 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 211 | // Instance size sentinel for objects of variable size. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 212 | const int kVariableSizeSentinel = 0; |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 213 | |
| 214 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 215 | // All Maps have a field instance_type containing a InstanceType. |
| 216 | // It describes the type of the instances. |
| 217 | // |
| 218 | // As an example, a JavaScript object is a heap object and its map |
| 219 | // instance_type is JS_OBJECT_TYPE. |
| 220 | // |
| 221 | // The names of the string instance types are intended to systematically |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 222 | // mirror their encoding in the instance_type field of the map. The default |
| 223 | // encoding is considered TWO_BYTE. It is not mentioned in the name. ASCII |
| 224 | // encoding is mentioned explicitly in the name. Likewise, the default |
| 225 | // representation is considered sequential. It is not mentioned in the |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 226 | // name. The other representations (e.g. CONS, EXTERNAL) are explicitly |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 227 | // mentioned. Finally, the string is either a SYMBOL_TYPE (if it is a |
| 228 | // symbol) or a STRING_TYPE (if it is not a symbol). |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 229 | // |
| 230 | // NOTE: The following things are some that depend on the string types having |
| 231 | // instance_types that are less than those of all other types: |
| 232 | // HeapObject::Size, HeapObject::IterateBody, the typeof operator, and |
| 233 | // Object::IsString. |
| 234 | // |
| 235 | // NOTE: Everything following JS_VALUE_TYPE is considered a |
| 236 | // JSObject for GC purposes. The first four entries here have typeof |
| 237 | // 'object', whereas JS_FUNCTION_TYPE has typeof 'function'. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 238 | #define INSTANCE_TYPE_LIST_ALL(V) \ |
| 239 | V(SYMBOL_TYPE) \ |
| 240 | V(ASCII_SYMBOL_TYPE) \ |
| 241 | V(CONS_SYMBOL_TYPE) \ |
| 242 | V(CONS_ASCII_SYMBOL_TYPE) \ |
| 243 | V(EXTERNAL_SYMBOL_TYPE) \ |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 244 | V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 245 | V(EXTERNAL_ASCII_SYMBOL_TYPE) \ |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 246 | V(SHORT_EXTERNAL_SYMBOL_TYPE) \ |
| 247 | V(SHORT_EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE) \ |
| 248 | V(SHORT_EXTERNAL_ASCII_SYMBOL_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 249 | V(STRING_TYPE) \ |
| 250 | V(ASCII_STRING_TYPE) \ |
| 251 | V(CONS_STRING_TYPE) \ |
| 252 | V(CONS_ASCII_STRING_TYPE) \ |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 253 | V(SLICED_STRING_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 254 | V(EXTERNAL_STRING_TYPE) \ |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 255 | V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 256 | V(EXTERNAL_ASCII_STRING_TYPE) \ |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 257 | V(SHORT_EXTERNAL_STRING_TYPE) \ |
| 258 | V(SHORT_EXTERNAL_STRING_WITH_ASCII_DATA_TYPE) \ |
| 259 | V(SHORT_EXTERNAL_ASCII_STRING_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 260 | V(PRIVATE_EXTERNAL_ASCII_STRING_TYPE) \ |
| 261 | \ |
| 262 | V(MAP_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 263 | V(CODE_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 264 | V(ODDBALL_TYPE) \ |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 265 | V(JS_GLOBAL_PROPERTY_CELL_TYPE) \ |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 266 | \ |
| 267 | V(HEAP_NUMBER_TYPE) \ |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 268 | V(FOREIGN_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 269 | V(BYTE_ARRAY_TYPE) \ |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 270 | V(FREE_SPACE_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 271 | /* Note: the order of these external array */ \ |
| 272 | /* types is relied upon in */ \ |
| 273 | /* Object::IsExternalArray(). */ \ |
| 274 | V(EXTERNAL_BYTE_ARRAY_TYPE) \ |
| 275 | V(EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE) \ |
| 276 | V(EXTERNAL_SHORT_ARRAY_TYPE) \ |
| 277 | V(EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE) \ |
| 278 | V(EXTERNAL_INT_ARRAY_TYPE) \ |
| 279 | V(EXTERNAL_UNSIGNED_INT_ARRAY_TYPE) \ |
| 280 | V(EXTERNAL_FLOAT_ARRAY_TYPE) \ |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 281 | V(EXTERNAL_PIXEL_ARRAY_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 282 | V(FILLER_TYPE) \ |
| 283 | \ |
| 284 | V(ACCESSOR_INFO_TYPE) \ |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 285 | V(ACCESSOR_PAIR_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 286 | V(ACCESS_CHECK_INFO_TYPE) \ |
| 287 | V(INTERCEPTOR_INFO_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 288 | V(CALL_HANDLER_INFO_TYPE) \ |
| 289 | V(FUNCTION_TEMPLATE_INFO_TYPE) \ |
| 290 | V(OBJECT_TEMPLATE_INFO_TYPE) \ |
| 291 | V(SIGNATURE_INFO_TYPE) \ |
| 292 | V(TYPE_SWITCH_INFO_TYPE) \ |
| 293 | V(SCRIPT_TYPE) \ |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 294 | V(CODE_CACHE_TYPE) \ |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 295 | V(POLYMORPHIC_CODE_CACHE_TYPE) \ |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 296 | V(TYPE_FEEDBACK_INFO_TYPE) \ |
| 297 | V(ALIASED_ARGUMENTS_ENTRY_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 298 | \ |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 299 | V(FIXED_ARRAY_TYPE) \ |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 300 | V(FIXED_DOUBLE_ARRAY_TYPE) \ |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 301 | V(SHARED_FUNCTION_INFO_TYPE) \ |
| 302 | \ |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 303 | V(JS_MESSAGE_OBJECT_TYPE) \ |
| 304 | \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 305 | V(JS_VALUE_TYPE) \ |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 306 | V(JS_DATE_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 307 | V(JS_OBJECT_TYPE) \ |
| 308 | V(JS_CONTEXT_EXTENSION_OBJECT_TYPE) \ |
| 309 | V(JS_GLOBAL_OBJECT_TYPE) \ |
| 310 | V(JS_BUILTINS_OBJECT_TYPE) \ |
| 311 | V(JS_GLOBAL_PROXY_TYPE) \ |
| 312 | V(JS_ARRAY_TYPE) \ |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 313 | V(JS_PROXY_TYPE) \ |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 314 | V(JS_WEAK_MAP_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 315 | V(JS_REGEXP_TYPE) \ |
| 316 | \ |
| 317 | V(JS_FUNCTION_TYPE) \ |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 318 | V(JS_FUNCTION_PROXY_TYPE) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 319 | |
| 320 | #ifdef ENABLE_DEBUGGER_SUPPORT |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 321 | #define INSTANCE_TYPE_LIST_DEBUGGER(V) \ |
| 322 | V(DEBUG_INFO_TYPE) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 323 | V(BREAK_POINT_INFO_TYPE) |
| 324 | #else |
| 325 | #define INSTANCE_TYPE_LIST_DEBUGGER(V) |
| 326 | #endif |
| 327 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 328 | #define INSTANCE_TYPE_LIST(V) \ |
| 329 | INSTANCE_TYPE_LIST_ALL(V) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 330 | INSTANCE_TYPE_LIST_DEBUGGER(V) |
| 331 | |
| 332 | |
| 333 | // Since string types are not consecutive, this macro is used to |
| 334 | // iterate over them. |
| 335 | #define STRING_TYPE_LIST(V) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 336 | V(SYMBOL_TYPE, \ |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 337 | kVariableSizeSentinel, \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 338 | symbol, \ |
| 339 | Symbol) \ |
| 340 | V(ASCII_SYMBOL_TYPE, \ |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 341 | kVariableSizeSentinel, \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 342 | ascii_symbol, \ |
| 343 | AsciiSymbol) \ |
| 344 | V(CONS_SYMBOL_TYPE, \ |
| 345 | ConsString::kSize, \ |
| 346 | cons_symbol, \ |
| 347 | ConsSymbol) \ |
| 348 | V(CONS_ASCII_SYMBOL_TYPE, \ |
| 349 | ConsString::kSize, \ |
| 350 | cons_ascii_symbol, \ |
| 351 | ConsAsciiSymbol) \ |
| 352 | V(EXTERNAL_SYMBOL_TYPE, \ |
| 353 | ExternalTwoByteString::kSize, \ |
| 354 | external_symbol, \ |
| 355 | ExternalSymbol) \ |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 356 | V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE, \ |
| 357 | ExternalTwoByteString::kSize, \ |
| 358 | external_symbol_with_ascii_data, \ |
| 359 | ExternalSymbolWithAsciiData) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 360 | V(EXTERNAL_ASCII_SYMBOL_TYPE, \ |
| 361 | ExternalAsciiString::kSize, \ |
| 362 | external_ascii_symbol, \ |
| 363 | ExternalAsciiSymbol) \ |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 364 | V(SHORT_EXTERNAL_SYMBOL_TYPE, \ |
| 365 | ExternalTwoByteString::kShortSize, \ |
| 366 | short_external_symbol, \ |
| 367 | ShortExternalSymbol) \ |
| 368 | V(SHORT_EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE, \ |
| 369 | ExternalTwoByteString::kShortSize, \ |
| 370 | short_external_symbol_with_ascii_data, \ |
| 371 | ShortExternalSymbolWithAsciiData) \ |
| 372 | V(SHORT_EXTERNAL_ASCII_SYMBOL_TYPE, \ |
| 373 | ExternalAsciiString::kShortSize, \ |
| 374 | short_external_ascii_symbol, \ |
| 375 | ShortExternalAsciiSymbol) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 376 | V(STRING_TYPE, \ |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 377 | kVariableSizeSentinel, \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 378 | string, \ |
| 379 | String) \ |
| 380 | V(ASCII_STRING_TYPE, \ |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 381 | kVariableSizeSentinel, \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 382 | ascii_string, \ |
| 383 | AsciiString) \ |
| 384 | V(CONS_STRING_TYPE, \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 385 | ConsString::kSize, \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 386 | cons_string, \ |
| 387 | ConsString) \ |
| 388 | V(CONS_ASCII_STRING_TYPE, \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 389 | ConsString::kSize, \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 390 | cons_ascii_string, \ |
| 391 | ConsAsciiString) \ |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 392 | V(SLICED_STRING_TYPE, \ |
| 393 | SlicedString::kSize, \ |
| 394 | sliced_string, \ |
| 395 | SlicedString) \ |
| 396 | V(SLICED_ASCII_STRING_TYPE, \ |
| 397 | SlicedString::kSize, \ |
| 398 | sliced_ascii_string, \ |
| 399 | SlicedAsciiString) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 400 | V(EXTERNAL_STRING_TYPE, \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 401 | ExternalTwoByteString::kSize, \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 402 | external_string, \ |
| 403 | ExternalString) \ |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 404 | V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE, \ |
| 405 | ExternalTwoByteString::kSize, \ |
| 406 | external_string_with_ascii_data, \ |
| 407 | ExternalStringWithAsciiData) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 408 | V(EXTERNAL_ASCII_STRING_TYPE, \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 409 | ExternalAsciiString::kSize, \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 410 | external_ascii_string, \ |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 411 | ExternalAsciiString) \ |
| 412 | V(SHORT_EXTERNAL_STRING_TYPE, \ |
| 413 | ExternalTwoByteString::kShortSize, \ |
| 414 | short_external_string, \ |
| 415 | ShortExternalString) \ |
| 416 | V(SHORT_EXTERNAL_STRING_WITH_ASCII_DATA_TYPE, \ |
| 417 | ExternalTwoByteString::kShortSize, \ |
| 418 | short_external_string_with_ascii_data, \ |
| 419 | ShortExternalStringWithAsciiData) \ |
| 420 | V(SHORT_EXTERNAL_ASCII_STRING_TYPE, \ |
| 421 | ExternalAsciiString::kShortSize, \ |
| 422 | short_external_ascii_string, \ |
| 423 | ShortExternalAsciiString) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 424 | |
| 425 | // A struct is a simple object a set of object-valued fields. Including an |
| 426 | // object type in this causes the compiler to generate most of the boilerplate |
| 427 | // code for the class including allocation and garbage collection routines, |
| 428 | // casts and predicates. All you need to define is the class, methods and |
| 429 | // object verification routines. Easy, no? |
| 430 | // |
| 431 | // Note that for subtle reasons related to the ordering or numerical values of |
| 432 | // type tags, elements in this list have to be added to the INSTANCE_TYPE_LIST |
| 433 | // manually. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 434 | #define STRUCT_LIST_ALL(V) \ |
| 435 | V(ACCESSOR_INFO, AccessorInfo, accessor_info) \ |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 436 | V(ACCESSOR_PAIR, AccessorPair, accessor_pair) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 437 | V(ACCESS_CHECK_INFO, AccessCheckInfo, access_check_info) \ |
| 438 | V(INTERCEPTOR_INFO, InterceptorInfo, interceptor_info) \ |
| 439 | V(CALL_HANDLER_INFO, CallHandlerInfo, call_handler_info) \ |
| 440 | V(FUNCTION_TEMPLATE_INFO, FunctionTemplateInfo, function_template_info) \ |
| 441 | V(OBJECT_TEMPLATE_INFO, ObjectTemplateInfo, object_template_info) \ |
| 442 | V(SIGNATURE_INFO, SignatureInfo, signature_info) \ |
| 443 | V(TYPE_SWITCH_INFO, TypeSwitchInfo, type_switch_info) \ |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 444 | V(SCRIPT, Script, script) \ |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 445 | V(CODE_CACHE, CodeCache, code_cache) \ |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 446 | V(POLYMORPHIC_CODE_CACHE, PolymorphicCodeCache, polymorphic_code_cache) \ |
| 447 | V(TYPE_FEEDBACK_INFO, TypeFeedbackInfo, type_feedback_info) \ |
| 448 | V(ALIASED_ARGUMENTS_ENTRY, AliasedArgumentsEntry, aliased_arguments_entry) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 449 | |
| 450 | #ifdef ENABLE_DEBUGGER_SUPPORT |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 451 | #define STRUCT_LIST_DEBUGGER(V) \ |
| 452 | V(DEBUG_INFO, DebugInfo, debug_info) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 453 | V(BREAK_POINT_INFO, BreakPointInfo, break_point_info) |
| 454 | #else |
| 455 | #define STRUCT_LIST_DEBUGGER(V) |
| 456 | #endif |
| 457 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 458 | #define STRUCT_LIST(V) \ |
| 459 | STRUCT_LIST_ALL(V) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 460 | STRUCT_LIST_DEBUGGER(V) |
| 461 | |
| 462 | // We use the full 8 bits of the instance_type field to encode heap object |
| 463 | // instance types. The high-order bit (bit 7) is set if the object is not a |
| 464 | // string, and cleared if it is a string. |
| 465 | const uint32_t kIsNotStringMask = 0x80; |
| 466 | const uint32_t kStringTag = 0x0; |
| 467 | const uint32_t kNotStringTag = 0x80; |
| 468 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 469 | // Bit 6 indicates that the object is a symbol (if set) or not (if cleared). |
| 470 | // There are not enough types that the non-string types (with bit 7 set) can |
| 471 | // have bit 6 set too. |
| 472 | const uint32_t kIsSymbolMask = 0x40; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 473 | const uint32_t kNotSymbolTag = 0x0; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 474 | const uint32_t kSymbolTag = 0x40; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 475 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 476 | // If bit 7 is clear then bit 2 indicates whether the string consists of |
| 477 | // two-byte characters or one-byte characters. |
| 478 | const uint32_t kStringEncodingMask = 0x4; |
| 479 | const uint32_t kTwoByteStringTag = 0x0; |
| 480 | const uint32_t kAsciiStringTag = 0x4; |
| 481 | |
| 482 | // If bit 7 is clear, the low-order 2 bits indicate the representation |
| 483 | // of the string. |
| 484 | const uint32_t kStringRepresentationMask = 0x03; |
| 485 | enum StringRepresentationTag { |
| 486 | kSeqStringTag = 0x0, |
| 487 | kConsStringTag = 0x1, |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 488 | kExternalStringTag = 0x2, |
| 489 | kSlicedStringTag = 0x3 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 490 | }; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 491 | const uint32_t kIsIndirectStringMask = 0x1; |
| 492 | const uint32_t kIsIndirectStringTag = 0x1; |
| 493 | STATIC_ASSERT((kSeqStringTag & kIsIndirectStringMask) == 0); |
| 494 | STATIC_ASSERT((kExternalStringTag & kIsIndirectStringMask) == 0); |
| 495 | STATIC_ASSERT( |
| 496 | (kConsStringTag & kIsIndirectStringMask) == kIsIndirectStringTag); |
| 497 | STATIC_ASSERT( |
| 498 | (kSlicedStringTag & kIsIndirectStringMask) == kIsIndirectStringTag); |
| 499 | |
| 500 | // Use this mask to distinguish between cons and slice only after making |
| 501 | // sure that the string is one of the two (an indirect string). |
| 502 | const uint32_t kSlicedNotConsMask = kSlicedStringTag & ~kConsStringTag; |
| 503 | STATIC_ASSERT(IS_POWER_OF_TWO(kSlicedNotConsMask) && kSlicedNotConsMask != 0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 504 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 505 | // If bit 7 is clear, then bit 3 indicates whether this two-byte |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 506 | // string actually contains ASCII data. |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 507 | const uint32_t kAsciiDataHintMask = 0x08; |
| 508 | const uint32_t kAsciiDataHintTag = 0x08; |
| 509 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 510 | // If bit 7 is clear and string representation indicates an external string, |
| 511 | // then bit 4 indicates whether the data pointer is cached. |
| 512 | const uint32_t kShortExternalStringMask = 0x10; |
| 513 | const uint32_t kShortExternalStringTag = 0x10; |
| 514 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 515 | |
| 516 | // A ConsString with an empty string as the right side is a candidate |
| 517 | // for being shortcut by the garbage collector unless it is a |
| 518 | // symbol. It's not common to have non-flat symbols, so we do not |
| 519 | // shortcut them thereby avoiding turning symbols into strings. See |
| 520 | // heap.cc and mark-compact.cc. |
| 521 | const uint32_t kShortcutTypeMask = |
| 522 | kIsNotStringMask | |
| 523 | kIsSymbolMask | |
| 524 | kStringRepresentationMask; |
| 525 | const uint32_t kShortcutTypeTag = kConsStringTag; |
| 526 | |
| 527 | |
| 528 | enum InstanceType { |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 529 | // String types. |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 530 | SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kSeqStringTag, |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 531 | ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kSeqStringTag, |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 532 | CONS_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kConsStringTag, |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 533 | CONS_ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kConsStringTag, |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 534 | SHORT_EXTERNAL_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | |
| 535 | kExternalStringTag | kShortExternalStringTag, |
| 536 | SHORT_EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE = |
| 537 | kTwoByteStringTag | kSymbolTag | kExternalStringTag | |
| 538 | kAsciiDataHintTag | kShortExternalStringTag, |
| 539 | SHORT_EXTERNAL_ASCII_SYMBOL_TYPE = kAsciiStringTag | kExternalStringTag | |
| 540 | kSymbolTag | kShortExternalStringTag, |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 541 | EXTERNAL_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kExternalStringTag, |
| 542 | EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE = |
| 543 | kTwoByteStringTag | kSymbolTag | kExternalStringTag | kAsciiDataHintTag, |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 544 | EXTERNAL_ASCII_SYMBOL_TYPE = |
| 545 | kAsciiStringTag | kSymbolTag | kExternalStringTag, |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 546 | STRING_TYPE = kTwoByteStringTag | kSeqStringTag, |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 547 | ASCII_STRING_TYPE = kAsciiStringTag | kSeqStringTag, |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 548 | CONS_STRING_TYPE = kTwoByteStringTag | kConsStringTag, |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 549 | CONS_ASCII_STRING_TYPE = kAsciiStringTag | kConsStringTag, |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 550 | SLICED_STRING_TYPE = kTwoByteStringTag | kSlicedStringTag, |
| 551 | SLICED_ASCII_STRING_TYPE = kAsciiStringTag | kSlicedStringTag, |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 552 | SHORT_EXTERNAL_STRING_TYPE = |
| 553 | kTwoByteStringTag | kExternalStringTag | kShortExternalStringTag, |
| 554 | SHORT_EXTERNAL_STRING_WITH_ASCII_DATA_TYPE = |
| 555 | kTwoByteStringTag | kExternalStringTag | |
| 556 | kAsciiDataHintTag | kShortExternalStringTag, |
| 557 | SHORT_EXTERNAL_ASCII_STRING_TYPE = |
| 558 | kAsciiStringTag | kExternalStringTag | kShortExternalStringTag, |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 559 | EXTERNAL_STRING_TYPE = kTwoByteStringTag | kExternalStringTag, |
| 560 | EXTERNAL_STRING_WITH_ASCII_DATA_TYPE = |
| 561 | kTwoByteStringTag | kExternalStringTag | kAsciiDataHintTag, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 562 | // LAST_STRING_TYPE |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 563 | EXTERNAL_ASCII_STRING_TYPE = kAsciiStringTag | kExternalStringTag, |
| 564 | PRIVATE_EXTERNAL_ASCII_STRING_TYPE = EXTERNAL_ASCII_STRING_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 565 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 566 | // Objects allocated in their own spaces (never in new space). |
| 567 | MAP_TYPE = kNotStringTag, // FIRST_NONSTRING_TYPE |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 568 | CODE_TYPE, |
| 569 | ODDBALL_TYPE, |
| 570 | JS_GLOBAL_PROPERTY_CELL_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 571 | |
| 572 | // "Data", objects that cannot contain non-map-word pointers to heap |
| 573 | // objects. |
| 574 | HEAP_NUMBER_TYPE, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 575 | FOREIGN_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 576 | BYTE_ARRAY_TYPE, |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 577 | FREE_SPACE_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 578 | EXTERNAL_BYTE_ARRAY_TYPE, // FIRST_EXTERNAL_ARRAY_TYPE |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 579 | EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE, |
| 580 | EXTERNAL_SHORT_ARRAY_TYPE, |
| 581 | EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE, |
| 582 | EXTERNAL_INT_ARRAY_TYPE, |
| 583 | EXTERNAL_UNSIGNED_INT_ARRAY_TYPE, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 584 | EXTERNAL_FLOAT_ARRAY_TYPE, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 585 | EXTERNAL_DOUBLE_ARRAY_TYPE, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 586 | EXTERNAL_PIXEL_ARRAY_TYPE, // LAST_EXTERNAL_ARRAY_TYPE |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 587 | FIXED_DOUBLE_ARRAY_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 588 | FILLER_TYPE, // LAST_DATA_TYPE |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 589 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 590 | // Structs. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 591 | ACCESSOR_INFO_TYPE, |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 592 | ACCESSOR_PAIR_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 593 | ACCESS_CHECK_INFO_TYPE, |
| 594 | INTERCEPTOR_INFO_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 595 | CALL_HANDLER_INFO_TYPE, |
| 596 | FUNCTION_TEMPLATE_INFO_TYPE, |
| 597 | OBJECT_TEMPLATE_INFO_TYPE, |
| 598 | SIGNATURE_INFO_TYPE, |
| 599 | TYPE_SWITCH_INFO_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 600 | SCRIPT_TYPE, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 601 | CODE_CACHE_TYPE, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 602 | POLYMORPHIC_CODE_CACHE_TYPE, |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 603 | TYPE_FEEDBACK_INFO_TYPE, |
| 604 | ALIASED_ARGUMENTS_ENTRY_TYPE, |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 605 | // The following two instance types are only used when ENABLE_DEBUGGER_SUPPORT |
| 606 | // is defined. However as include/v8.h contain some of the instance type |
| 607 | // constants always having them avoids them getting different numbers |
| 608 | // depending on whether ENABLE_DEBUGGER_SUPPORT is defined or not. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 609 | DEBUG_INFO_TYPE, |
| 610 | BREAK_POINT_INFO_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 611 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 612 | FIXED_ARRAY_TYPE, |
| 613 | SHARED_FUNCTION_INFO_TYPE, |
| 614 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 615 | JS_MESSAGE_OBJECT_TYPE, |
| 616 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 617 | // All the following types are subtypes of JSReceiver, which corresponds to |
| 618 | // objects in the JS sense. The first and the last type in this range are |
| 619 | // the two forms of function. This organization enables using the same |
| 620 | // compares for checking the JS_RECEIVER/SPEC_OBJECT range and the |
| 621 | // NONCALLABLE_JS_OBJECT range. |
| 622 | JS_FUNCTION_PROXY_TYPE, // FIRST_JS_RECEIVER_TYPE, FIRST_JS_PROXY_TYPE |
| 623 | JS_PROXY_TYPE, // LAST_JS_PROXY_TYPE |
| 624 | |
| 625 | JS_VALUE_TYPE, // FIRST_JS_OBJECT_TYPE |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 626 | JS_DATE_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 627 | JS_OBJECT_TYPE, |
| 628 | JS_CONTEXT_EXTENSION_OBJECT_TYPE, |
| 629 | JS_GLOBAL_OBJECT_TYPE, |
| 630 | JS_BUILTINS_OBJECT_TYPE, |
| 631 | JS_GLOBAL_PROXY_TYPE, |
| 632 | JS_ARRAY_TYPE, |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 633 | JS_SET_TYPE, |
| 634 | JS_MAP_TYPE, |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 635 | JS_WEAK_MAP_TYPE, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 636 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 637 | JS_REGEXP_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 638 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 639 | JS_FUNCTION_TYPE, // LAST_JS_OBJECT_TYPE, LAST_JS_RECEIVER_TYPE |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 640 | |
| 641 | // Pseudo-types |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 642 | FIRST_TYPE = 0x0, |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 643 | LAST_TYPE = JS_FUNCTION_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 644 | INVALID_TYPE = FIRST_TYPE - 1, |
| 645 | FIRST_NONSTRING_TYPE = MAP_TYPE, |
| 646 | // Boundaries for testing for an external array. |
| 647 | FIRST_EXTERNAL_ARRAY_TYPE = EXTERNAL_BYTE_ARRAY_TYPE, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 648 | LAST_EXTERNAL_ARRAY_TYPE = EXTERNAL_PIXEL_ARRAY_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 649 | // Boundary for promotion to old data space/old pointer space. |
| 650 | LAST_DATA_TYPE = FILLER_TYPE, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 651 | // Boundary for objects represented as JSReceiver (i.e. JSObject or JSProxy). |
| 652 | // Note that there is no range for JSObject or JSProxy, since their subtypes |
| 653 | // are not continuous in this enum! The enum ranges instead reflect the |
| 654 | // external class names, where proxies are treated as either ordinary objects, |
| 655 | // or functions. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 656 | FIRST_JS_RECEIVER_TYPE = JS_FUNCTION_PROXY_TYPE, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 657 | LAST_JS_RECEIVER_TYPE = LAST_TYPE, |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 658 | // Boundaries for testing the types represented as JSObject |
| 659 | FIRST_JS_OBJECT_TYPE = JS_VALUE_TYPE, |
| 660 | LAST_JS_OBJECT_TYPE = LAST_TYPE, |
| 661 | // Boundaries for testing the types represented as JSProxy |
| 662 | FIRST_JS_PROXY_TYPE = JS_FUNCTION_PROXY_TYPE, |
| 663 | LAST_JS_PROXY_TYPE = JS_PROXY_TYPE, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 664 | // Boundaries for testing whether the type is a JavaScript object. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 665 | FIRST_SPEC_OBJECT_TYPE = FIRST_JS_RECEIVER_TYPE, |
| 666 | LAST_SPEC_OBJECT_TYPE = LAST_JS_RECEIVER_TYPE, |
| 667 | // Boundaries for testing the types for which typeof is "object". |
| 668 | FIRST_NONCALLABLE_SPEC_OBJECT_TYPE = JS_PROXY_TYPE, |
| 669 | LAST_NONCALLABLE_SPEC_OBJECT_TYPE = JS_REGEXP_TYPE, |
| 670 | // Note that the types for which typeof is "function" are not continuous. |
| 671 | // Define this so that we can put assertions on discrete checks. |
| 672 | NUM_OF_CALLABLE_SPEC_OBJECT_TYPES = 2 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 673 | }; |
| 674 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 675 | const int kExternalArrayTypeCount = |
| 676 | LAST_EXTERNAL_ARRAY_TYPE - FIRST_EXTERNAL_ARRAY_TYPE + 1; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 677 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 678 | STATIC_CHECK(JS_OBJECT_TYPE == Internals::kJSObjectType); |
| 679 | STATIC_CHECK(FIRST_NONSTRING_TYPE == Internals::kFirstNonstringType); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 680 | STATIC_CHECK(FOREIGN_TYPE == Internals::kForeignType); |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 681 | |
| 682 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 683 | enum CompareResult { |
| 684 | LESS = -1, |
| 685 | EQUAL = 0, |
| 686 | GREATER = 1, |
| 687 | |
| 688 | NOT_EQUAL = GREATER |
| 689 | }; |
| 690 | |
| 691 | |
| 692 | #define DECL_BOOLEAN_ACCESSORS(name) \ |
| 693 | inline bool name(); \ |
| 694 | inline void set_##name(bool value); \ |
| 695 | |
| 696 | |
| 697 | #define DECL_ACCESSORS(name, type) \ |
| 698 | inline type* name(); \ |
| 699 | inline void set_##name(type* value, \ |
| 700 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); \ |
| 701 | |
| 702 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 703 | class DictionaryElementsAccessor; |
| 704 | class ElementsAccessor; |
| 705 | class FixedArrayBase; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 706 | class ObjectVisitor; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 707 | class StringStream; |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 708 | class Failure; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 709 | |
| 710 | struct ValueInfo : public Malloced { |
| 711 | ValueInfo() : type(FIRST_TYPE), ptr(NULL), str(NULL), number(0) { } |
| 712 | InstanceType type; |
| 713 | Object* ptr; |
| 714 | const char* str; |
| 715 | double number; |
| 716 | }; |
| 717 | |
| 718 | |
| 719 | // A template-ized version of the IsXXX functions. |
| 720 | template <class C> static inline bool Is(Object* obj); |
| 721 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 722 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 723 | class MaybeObject BASE_EMBEDDED { |
| 724 | public: |
| 725 | inline bool IsFailure(); |
| 726 | inline bool IsRetryAfterGC(); |
| 727 | inline bool IsOutOfMemory(); |
| 728 | inline bool IsException(); |
| 729 | INLINE(bool IsTheHole()); |
| 730 | inline bool ToObject(Object** obj) { |
| 731 | if (IsFailure()) return false; |
| 732 | *obj = reinterpret_cast<Object*>(this); |
| 733 | return true; |
| 734 | } |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 735 | inline Failure* ToFailureUnchecked() { |
| 736 | ASSERT(IsFailure()); |
| 737 | return reinterpret_cast<Failure*>(this); |
| 738 | } |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 739 | inline Object* ToObjectUnchecked() { |
| 740 | ASSERT(!IsFailure()); |
| 741 | return reinterpret_cast<Object*>(this); |
| 742 | } |
| 743 | inline Object* ToObjectChecked() { |
| 744 | CHECK(!IsFailure()); |
| 745 | return reinterpret_cast<Object*>(this); |
| 746 | } |
| 747 | |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 748 | template<typename T> |
| 749 | inline bool To(T** obj) { |
| 750 | if (IsFailure()) return false; |
| 751 | *obj = T::cast(reinterpret_cast<Object*>(this)); |
| 752 | return true; |
| 753 | } |
| 754 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 755 | #ifdef OBJECT_PRINT |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 756 | // Prints this object with details. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 757 | inline void Print() { |
| 758 | Print(stdout); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 759 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 760 | inline void PrintLn() { |
| 761 | PrintLn(stdout); |
| 762 | } |
| 763 | void Print(FILE* out); |
| 764 | void PrintLn(FILE* out); |
| 765 | #endif |
| 766 | #ifdef DEBUG |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 767 | // Verifies the object. |
| 768 | void Verify(); |
| 769 | #endif |
| 770 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 771 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 772 | |
| 773 | #define OBJECT_TYPE_LIST(V) \ |
| 774 | V(Smi) \ |
| 775 | V(HeapObject) \ |
| 776 | V(Number) \ |
| 777 | |
| 778 | #define HEAP_OBJECT_TYPE_LIST(V) \ |
| 779 | V(HeapNumber) \ |
| 780 | V(String) \ |
| 781 | V(Symbol) \ |
| 782 | V(SeqString) \ |
| 783 | V(ExternalString) \ |
| 784 | V(ConsString) \ |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 785 | V(SlicedString) \ |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 786 | V(ExternalTwoByteString) \ |
| 787 | V(ExternalAsciiString) \ |
| 788 | V(SeqTwoByteString) \ |
| 789 | V(SeqAsciiString) \ |
| 790 | \ |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 791 | V(ExternalArray) \ |
| 792 | V(ExternalByteArray) \ |
| 793 | V(ExternalUnsignedByteArray) \ |
| 794 | V(ExternalShortArray) \ |
| 795 | V(ExternalUnsignedShortArray) \ |
| 796 | V(ExternalIntArray) \ |
| 797 | V(ExternalUnsignedIntArray) \ |
| 798 | V(ExternalFloatArray) \ |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 799 | V(ExternalDoubleArray) \ |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 800 | V(ExternalPixelArray) \ |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 801 | V(ByteArray) \ |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 802 | V(FreeSpace) \ |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 803 | V(JSReceiver) \ |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 804 | V(JSObject) \ |
| 805 | V(JSContextExtensionObject) \ |
| 806 | V(Map) \ |
| 807 | V(DescriptorArray) \ |
| 808 | V(DeoptimizationInputData) \ |
| 809 | V(DeoptimizationOutputData) \ |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 810 | V(TypeFeedbackCells) \ |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 811 | V(FixedArray) \ |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 812 | V(FixedDoubleArray) \ |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 813 | V(Context) \ |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 814 | V(GlobalContext) \ |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 815 | V(ScopeInfo) \ |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 816 | V(JSFunction) \ |
| 817 | V(Code) \ |
| 818 | V(Oddball) \ |
| 819 | V(SharedFunctionInfo) \ |
| 820 | V(JSValue) \ |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 821 | V(JSDate) \ |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 822 | V(JSMessageObject) \ |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 823 | V(StringWrapper) \ |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 824 | V(Foreign) \ |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 825 | V(Boolean) \ |
| 826 | V(JSArray) \ |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 827 | V(JSProxy) \ |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 828 | V(JSFunctionProxy) \ |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 829 | V(JSSet) \ |
| 830 | V(JSMap) \ |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 831 | V(JSWeakMap) \ |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 832 | V(JSRegExp) \ |
| 833 | V(HashTable) \ |
| 834 | V(Dictionary) \ |
| 835 | V(SymbolTable) \ |
| 836 | V(JSFunctionResultCache) \ |
| 837 | V(NormalizedMapCache) \ |
| 838 | V(CompilationCacheTable) \ |
| 839 | V(CodeCacheHashTable) \ |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 840 | V(PolymorphicCodeCacheHashTable) \ |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 841 | V(MapCache) \ |
| 842 | V(Primitive) \ |
| 843 | V(GlobalObject) \ |
| 844 | V(JSGlobalObject) \ |
| 845 | V(JSBuiltinsObject) \ |
| 846 | V(JSGlobalProxy) \ |
| 847 | V(UndetectableObject) \ |
| 848 | V(AccessCheckNeeded) \ |
| 849 | V(JSGlobalPropertyCell) \ |
| 850 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 851 | |
| 852 | class JSReceiver; |
| 853 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 854 | // Object is the abstract superclass for all classes in the |
| 855 | // object hierarchy. |
| 856 | // Object does not use any virtual functions to avoid the |
| 857 | // allocation of the C++ vtable. |
| 858 | // Since Smi and Failure are subclasses of Object no |
| 859 | // data members can be present in Object. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 860 | class Object : public MaybeObject { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 861 | public: |
| 862 | // Type testing. |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 863 | bool IsObject() { return true; } |
| 864 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 865 | #define IS_TYPE_FUNCTION_DECL(type_) inline bool Is##type_(); |
| 866 | OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL) |
| 867 | HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL) |
| 868 | #undef IS_TYPE_FUNCTION_DECL |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 869 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 870 | inline bool IsFixedArrayBase(); |
| 871 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 872 | // Returns true if this object is an instance of the specified |
| 873 | // function template. |
| 874 | inline bool IsInstanceOf(FunctionTemplateInfo* type); |
| 875 | |
| 876 | inline bool IsStruct(); |
| 877 | #define DECLARE_STRUCT_PREDICATE(NAME, Name, name) inline bool Is##Name(); |
| 878 | STRUCT_LIST(DECLARE_STRUCT_PREDICATE) |
| 879 | #undef DECLARE_STRUCT_PREDICATE |
| 880 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 881 | INLINE(bool IsSpecObject()); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 882 | INLINE(bool IsSpecFunction()); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 883 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 884 | // Oddball testing. |
| 885 | INLINE(bool IsUndefined()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 886 | INLINE(bool IsNull()); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 887 | INLINE(bool IsTheHole()); // Shadows MaybeObject's implementation. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 888 | INLINE(bool IsTrue()); |
| 889 | INLINE(bool IsFalse()); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 890 | inline bool IsArgumentsMarker(); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 891 | inline bool NonFailureIsHeapObject(); |
| 892 | |
| 893 | // Filler objects (fillers and free space objects). |
| 894 | inline bool IsFiller(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 895 | |
| 896 | // Extract the number. |
| 897 | inline double Number(); |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 898 | inline bool IsNaN(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 899 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 900 | // Returns true if the object is of the correct type to be used as a |
| 901 | // implementation of a JSObject's elements. |
| 902 | inline bool HasValidElements(); |
| 903 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 904 | inline bool HasSpecificClassOf(String* name); |
| 905 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 906 | MUST_USE_RESULT MaybeObject* ToObject(); // ECMA-262 9.9. |
| 907 | Object* ToBoolean(); // ECMA-262 9.2. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 908 | |
| 909 | // Convert to a JSObject if needed. |
| 910 | // global_context is used when creating wrapper object. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 911 | MUST_USE_RESULT MaybeObject* ToObject(Context* global_context); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 912 | |
| 913 | // Converts this to a Smi if possible. |
| 914 | // Failure is returned otherwise. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 915 | MUST_USE_RESULT inline MaybeObject* ToSmi(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 916 | |
| 917 | void Lookup(String* name, LookupResult* result); |
| 918 | |
| 919 | // Property access. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 920 | MUST_USE_RESULT inline MaybeObject* GetProperty(String* key); |
| 921 | MUST_USE_RESULT inline MaybeObject* GetProperty( |
| 922 | String* key, |
| 923 | PropertyAttributes* attributes); |
| 924 | MUST_USE_RESULT MaybeObject* GetPropertyWithReceiver( |
| 925 | Object* receiver, |
| 926 | String* key, |
| 927 | PropertyAttributes* attributes); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 928 | |
| 929 | static Handle<Object> GetProperty(Handle<Object> object, |
| 930 | Handle<Object> receiver, |
| 931 | LookupResult* result, |
| 932 | Handle<String> key, |
| 933 | PropertyAttributes* attributes); |
| 934 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 935 | MUST_USE_RESULT MaybeObject* GetProperty(Object* receiver, |
| 936 | LookupResult* result, |
| 937 | String* key, |
| 938 | PropertyAttributes* attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 939 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 940 | MUST_USE_RESULT MaybeObject* GetPropertyWithDefinedGetter(Object* receiver, |
| 941 | JSReceiver* getter); |
| 942 | |
| 943 | static Handle<Object> GetElement(Handle<Object> object, uint32_t index); |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 944 | MUST_USE_RESULT inline MaybeObject* GetElement(uint32_t index); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 945 | // For use when we know that no exception can be thrown. |
| 946 | inline Object* GetElementNoExceptionThrown(uint32_t index); |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 947 | MUST_USE_RESULT MaybeObject* GetElementWithReceiver(Object* receiver, |
| 948 | uint32_t index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 949 | |
| 950 | // Return the object's prototype (might be Heap::null_value()). |
| 951 | Object* GetPrototype(); |
| 952 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 953 | // Returns the permanent hash code associated with this object depending on |
| 954 | // the actual object type. Might return a failure in case no hash was |
| 955 | // created yet or GC was caused by creation. |
| 956 | MUST_USE_RESULT MaybeObject* GetHash(CreationFlag flag); |
| 957 | |
| 958 | // Checks whether this object has the same value as the given one. This |
| 959 | // function is implemented according to ES5, section 9.12 and can be used |
| 960 | // to implement the Harmony "egal" function. |
| 961 | bool SameValue(Object* other); |
| 962 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 963 | // Tries to convert an object to an array index. Returns true and sets |
| 964 | // the output parameter if it succeeds. |
| 965 | inline bool ToArrayIndex(uint32_t* index); |
| 966 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 967 | // Returns true if this is a JSValue containing a string and the index is |
| 968 | // < the length of the string. Used to implement [] on strings. |
| 969 | inline bool IsStringObjectWithCharacterAt(uint32_t index); |
| 970 | |
| 971 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 972 | // Verify a pointer is a valid object pointer. |
| 973 | static void VerifyPointer(Object* p); |
| 974 | #endif |
| 975 | |
| 976 | // Prints this object without details. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 977 | inline void ShortPrint() { |
| 978 | ShortPrint(stdout); |
| 979 | } |
| 980 | void ShortPrint(FILE* out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 981 | |
| 982 | // Prints this object without details to a message accumulator. |
| 983 | void ShortPrint(StringStream* accumulator); |
| 984 | |
| 985 | // Casting: This cast is only needed to satisfy macros in objects-inl.h. |
| 986 | static Object* cast(Object* value) { return value; } |
| 987 | |
| 988 | // Layout description. |
| 989 | static const int kHeaderSize = 0; // Object does not take up any space. |
| 990 | |
| 991 | private: |
| 992 | DISALLOW_IMPLICIT_CONSTRUCTORS(Object); |
| 993 | }; |
| 994 | |
| 995 | |
| 996 | // Smi represents integer Numbers that can be stored in 31 bits. |
| 997 | // Smis are immediate which means they are NOT allocated in the heap. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 998 | // The this pointer has the following format: [31 bit signed int] 0 |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 999 | // For long smis it has the following format: |
| 1000 | // [32 bit signed int] [31 bits zero padding] 0 |
| 1001 | // Smi stands for small integer. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1002 | class Smi: public Object { |
| 1003 | public: |
| 1004 | // Returns the integer value. |
| 1005 | inline int value(); |
| 1006 | |
| 1007 | // Convert a value to a Smi object. |
| 1008 | static inline Smi* FromInt(int value); |
| 1009 | |
| 1010 | static inline Smi* FromIntptr(intptr_t value); |
| 1011 | |
| 1012 | // Returns whether value can be represented in a Smi. |
| 1013 | static inline bool IsValid(intptr_t value); |
| 1014 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1015 | // Casting. |
| 1016 | static inline Smi* cast(Object* object); |
| 1017 | |
| 1018 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1019 | inline void SmiPrint() { |
| 1020 | SmiPrint(stdout); |
| 1021 | } |
| 1022 | void SmiPrint(FILE* out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1023 | void SmiPrint(StringStream* accumulator); |
| 1024 | #ifdef DEBUG |
| 1025 | void SmiVerify(); |
| 1026 | #endif |
| 1027 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1028 | static const int kMinValue = |
| 1029 | (static_cast<unsigned int>(-1)) << (kSmiValueSize - 1); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1030 | static const int kMaxValue = -(kMinValue + 1); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1031 | |
| 1032 | private: |
| 1033 | DISALLOW_IMPLICIT_CONSTRUCTORS(Smi); |
| 1034 | }; |
| 1035 | |
| 1036 | |
| 1037 | // Failure is used for reporting out of memory situations and |
| 1038 | // propagating exceptions through the runtime system. Failure objects |
| 1039 | // are transient and cannot occur as part of the object graph. |
| 1040 | // |
| 1041 | // Failures are a single word, encoded as follows: |
| 1042 | // +-------------------------+---+--+--+ |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 1043 | // |.........unused..........|sss|tt|11| |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1044 | // +-------------------------+---+--+--+ |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1045 | // 7 6 4 32 10 |
| 1046 | // |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1047 | // |
| 1048 | // The low two bits, 0-1, are the failure tag, 11. The next two bits, |
| 1049 | // 2-3, are a failure type tag 'tt' with possible values: |
| 1050 | // 00 RETRY_AFTER_GC |
| 1051 | // 01 EXCEPTION |
| 1052 | // 10 INTERNAL_ERROR |
| 1053 | // 11 OUT_OF_MEMORY_EXCEPTION |
| 1054 | // |
| 1055 | // The next three bits, 4-6, are an allocation space tag 'sss'. The |
| 1056 | // allocation space tag is 000 for all failure types except |
| 1057 | // RETRY_AFTER_GC. For RETRY_AFTER_GC, the possible values are the |
| 1058 | // allocation spaces (the encoding is found in globals.h). |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1059 | |
| 1060 | // Failure type tag info. |
| 1061 | const int kFailureTypeTagSize = 2; |
| 1062 | const int kFailureTypeTagMask = (1 << kFailureTypeTagSize) - 1; |
| 1063 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1064 | class Failure: public MaybeObject { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1065 | public: |
| 1066 | // RuntimeStubs assumes EXCEPTION = 1 in the compiler-generated code. |
| 1067 | enum Type { |
| 1068 | RETRY_AFTER_GC = 0, |
| 1069 | EXCEPTION = 1, // Returning this marker tells the real exception |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1070 | // is in Isolate::pending_exception. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1071 | INTERNAL_ERROR = 2, |
| 1072 | OUT_OF_MEMORY_EXCEPTION = 3 |
| 1073 | }; |
| 1074 | |
| 1075 | inline Type type() const; |
| 1076 | |
| 1077 | // Returns the space that needs to be collected for RetryAfterGC failures. |
| 1078 | inline AllocationSpace allocation_space() const; |
| 1079 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1080 | inline bool IsInternalError() const; |
| 1081 | inline bool IsOutOfMemoryException() const; |
| 1082 | |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 1083 | static inline Failure* RetryAfterGC(AllocationSpace space); |
| 1084 | static inline Failure* RetryAfterGC(); // NEW_SPACE |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1085 | static inline Failure* Exception(); |
| 1086 | static inline Failure* InternalError(); |
| 1087 | static inline Failure* OutOfMemoryException(); |
| 1088 | // Casting. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1089 | static inline Failure* cast(MaybeObject* object); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1090 | |
| 1091 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1092 | inline void FailurePrint() { |
| 1093 | FailurePrint(stdout); |
| 1094 | } |
| 1095 | void FailurePrint(FILE* out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1096 | void FailurePrint(StringStream* accumulator); |
| 1097 | #ifdef DEBUG |
| 1098 | void FailureVerify(); |
| 1099 | #endif |
| 1100 | |
| 1101 | private: |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1102 | inline intptr_t value() const; |
| 1103 | static inline Failure* Construct(Type type, intptr_t value = 0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1104 | |
| 1105 | DISALLOW_IMPLICIT_CONSTRUCTORS(Failure); |
| 1106 | }; |
| 1107 | |
| 1108 | |
| 1109 | // Heap objects typically have a map pointer in their first word. However, |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1110 | // during GC other data (e.g. mark bits, forwarding addresses) is sometimes |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1111 | // encoded in the first word. The class MapWord is an abstraction of the |
| 1112 | // value in a heap object's first word. |
| 1113 | class MapWord BASE_EMBEDDED { |
| 1114 | public: |
| 1115 | // Normal state: the map word contains a map pointer. |
| 1116 | |
| 1117 | // Create a map word from a map pointer. |
| 1118 | static inline MapWord FromMap(Map* map); |
| 1119 | |
| 1120 | // View this map word as a map pointer. |
| 1121 | inline Map* ToMap(); |
| 1122 | |
| 1123 | |
| 1124 | // Scavenge collection: the map word of live objects in the from space |
| 1125 | // contains a forwarding address (a heap object pointer in the to space). |
| 1126 | |
| 1127 | // True if this map word is a forwarding address for a scavenge |
| 1128 | // collection. Only valid during a scavenge collection (specifically, |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1129 | // 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] | 1130 | inline bool IsForwardingAddress(); |
| 1131 | |
| 1132 | // Create a map word from a forwarding address. |
| 1133 | static inline MapWord FromForwardingAddress(HeapObject* object); |
| 1134 | |
| 1135 | // View this map word as a forwarding address. |
| 1136 | inline HeapObject* ToForwardingAddress(); |
| 1137 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1138 | static inline MapWord FromRawValue(uintptr_t value) { |
| 1139 | return MapWord(value); |
| 1140 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1141 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1142 | inline uintptr_t ToRawValue() { |
| 1143 | return value_; |
| 1144 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1145 | |
| 1146 | private: |
| 1147 | // HeapObject calls the private constructor and directly reads the value. |
| 1148 | friend class HeapObject; |
| 1149 | |
| 1150 | explicit MapWord(uintptr_t value) : value_(value) {} |
| 1151 | |
| 1152 | uintptr_t value_; |
| 1153 | }; |
| 1154 | |
| 1155 | |
| 1156 | // HeapObject is the superclass for all classes describing heap allocated |
| 1157 | // objects. |
| 1158 | class HeapObject: public Object { |
| 1159 | public: |
| 1160 | // [map]: Contains a map which contains the object's reflective |
| 1161 | // information. |
| 1162 | inline Map* map(); |
| 1163 | inline void set_map(Map* value); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1164 | // The no-write-barrier version. This is OK if the object is white and in |
| 1165 | // new space, or if the value is an immortal immutable object, like the maps |
| 1166 | // of primitive (non-JS) objects like strings, heap numbers etc. |
| 1167 | inline void set_map_no_write_barrier(Map* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1168 | |
| 1169 | // During garbage collection, the map word of a heap object does not |
| 1170 | // necessarily contain a map pointer. |
| 1171 | inline MapWord map_word(); |
| 1172 | inline void set_map_word(MapWord map_word); |
| 1173 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1174 | // The Heap the object was allocated in. Used also to access Isolate. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1175 | inline Heap* GetHeap(); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1176 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1177 | // Convenience method to get current isolate. This method can be |
| 1178 | // accessed only when its result is the same as |
| 1179 | // Isolate::Current(), it ASSERTs this. See also comment for GetHeap. |
| 1180 | inline Isolate* GetIsolate(); |
| 1181 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1182 | // Converts an address to a HeapObject pointer. |
| 1183 | static inline HeapObject* FromAddress(Address address); |
| 1184 | |
| 1185 | // Returns the address of this HeapObject. |
| 1186 | inline Address address(); |
| 1187 | |
| 1188 | // Iterates over pointers contained in the object (including the Map) |
| 1189 | void Iterate(ObjectVisitor* v); |
| 1190 | |
| 1191 | // Iterates over all pointers contained in the object except the |
| 1192 | // first map pointer. The object type is given in the first |
| 1193 | // parameter. This function does not access the map pointer in the |
| 1194 | // object, and so is safe to call while the map pointer is modified. |
| 1195 | void IterateBody(InstanceType type, int object_size, ObjectVisitor* v); |
| 1196 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1197 | // Returns the heap object's size in bytes |
| 1198 | inline int Size(); |
| 1199 | |
| 1200 | // Given a heap object's map pointer, returns the heap size in bytes |
| 1201 | // Useful when the map pointer field is used for other purposes. |
| 1202 | // GC internal. |
| 1203 | inline int SizeFromMap(Map* map); |
| 1204 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1205 | // Returns the field at offset in obj, as a read/write Object* reference. |
| 1206 | // 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] | 1207 | // Does not invoke write barrier, so should only be assigned to |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1208 | // during marking GC. |
| 1209 | static inline Object** RawField(HeapObject* obj, int offset); |
| 1210 | |
| 1211 | // Casting. |
| 1212 | static inline HeapObject* cast(Object* obj); |
| 1213 | |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 1214 | // Return the write barrier mode for this. Callers of this function |
| 1215 | // must be able to present a reference to an AssertNoAllocation |
| 1216 | // object as a sign that they are not going to use this function |
| 1217 | // from code that allocates and thus invalidates the returned write |
| 1218 | // barrier mode. |
| 1219 | inline WriteBarrierMode GetWriteBarrierMode(const AssertNoAllocation&); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1220 | |
| 1221 | // Dispatched behavior. |
| 1222 | void HeapObjectShortPrint(StringStream* accumulator); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1223 | #ifdef OBJECT_PRINT |
| 1224 | inline void HeapObjectPrint() { |
| 1225 | HeapObjectPrint(stdout); |
| 1226 | } |
| 1227 | void HeapObjectPrint(FILE* out); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1228 | void PrintHeader(FILE* out, const char* id); |
| 1229 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1230 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1231 | #ifdef DEBUG |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1232 | void HeapObjectVerify(); |
| 1233 | inline void VerifyObjectField(int offset); |
| 1234 | inline void VerifySmiField(int offset); |
| 1235 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1236 | // Verify a pointer is a valid HeapObject pointer that points to object |
| 1237 | // areas in the heap. |
| 1238 | static void VerifyHeapPointer(Object* p); |
| 1239 | #endif |
| 1240 | |
| 1241 | // Layout description. |
| 1242 | // First field in a heap object is map. |
| 1243 | static const int kMapOffset = Object::kHeaderSize; |
| 1244 | static const int kHeaderSize = kMapOffset + kPointerSize; |
| 1245 | |
| 1246 | STATIC_CHECK(kMapOffset == Internals::kHeapObjectMapOffset); |
| 1247 | |
| 1248 | protected: |
| 1249 | // helpers for calling an ObjectVisitor to iterate over pointers in the |
| 1250 | // half-open range [start, end) specified as integer offsets |
| 1251 | inline void IteratePointers(ObjectVisitor* v, int start, int end); |
| 1252 | // as above, for the single element at "offset" |
| 1253 | inline void IteratePointer(ObjectVisitor* v, int offset); |
| 1254 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1255 | private: |
| 1256 | DISALLOW_IMPLICIT_CONSTRUCTORS(HeapObject); |
| 1257 | }; |
| 1258 | |
| 1259 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1260 | #define SLOT_ADDR(obj, offset) \ |
| 1261 | reinterpret_cast<Object**>((obj)->address() + offset) |
| 1262 | |
| 1263 | // This class describes a body of an object of a fixed size |
| 1264 | // in which all pointer fields are located in the [start_offset, end_offset) |
| 1265 | // interval. |
| 1266 | template<int start_offset, int end_offset, int size> |
| 1267 | class FixedBodyDescriptor { |
| 1268 | public: |
| 1269 | static const int kStartOffset = start_offset; |
| 1270 | static const int kEndOffset = end_offset; |
| 1271 | static const int kSize = size; |
| 1272 | |
| 1273 | static inline void IterateBody(HeapObject* obj, ObjectVisitor* v); |
| 1274 | |
| 1275 | template<typename StaticVisitor> |
| 1276 | static inline void IterateBody(HeapObject* obj) { |
| 1277 | StaticVisitor::VisitPointers(SLOT_ADDR(obj, start_offset), |
| 1278 | SLOT_ADDR(obj, end_offset)); |
| 1279 | } |
| 1280 | }; |
| 1281 | |
| 1282 | |
| 1283 | // This class describes a body of an object of a variable size |
| 1284 | // in which all pointer fields are located in the [start_offset, object_size) |
| 1285 | // interval. |
| 1286 | template<int start_offset> |
| 1287 | class FlexibleBodyDescriptor { |
| 1288 | public: |
| 1289 | static const int kStartOffset = start_offset; |
| 1290 | |
| 1291 | static inline void IterateBody(HeapObject* obj, |
| 1292 | int object_size, |
| 1293 | ObjectVisitor* v); |
| 1294 | |
| 1295 | template<typename StaticVisitor> |
| 1296 | static inline void IterateBody(HeapObject* obj, int object_size) { |
| 1297 | StaticVisitor::VisitPointers(SLOT_ADDR(obj, start_offset), |
| 1298 | SLOT_ADDR(obj, object_size)); |
| 1299 | } |
| 1300 | }; |
| 1301 | |
| 1302 | #undef SLOT_ADDR |
| 1303 | |
| 1304 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1305 | // The HeapNumber class describes heap allocated numbers that cannot be |
| 1306 | // represented in a Smi (small integer) |
| 1307 | class HeapNumber: public HeapObject { |
| 1308 | public: |
| 1309 | // [value]: number value. |
| 1310 | inline double value(); |
| 1311 | inline void set_value(double value); |
| 1312 | |
| 1313 | // Casting. |
| 1314 | static inline HeapNumber* cast(Object* obj); |
| 1315 | |
| 1316 | // Dispatched behavior. |
| 1317 | Object* HeapNumberToBoolean(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1318 | inline void HeapNumberPrint() { |
| 1319 | HeapNumberPrint(stdout); |
| 1320 | } |
| 1321 | void HeapNumberPrint(FILE* out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1322 | void HeapNumberPrint(StringStream* accumulator); |
| 1323 | #ifdef DEBUG |
| 1324 | void HeapNumberVerify(); |
| 1325 | #endif |
| 1326 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1327 | inline int get_exponent(); |
| 1328 | inline int get_sign(); |
| 1329 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1330 | // Layout description. |
| 1331 | static const int kValueOffset = HeapObject::kHeaderSize; |
| 1332 | // IEEE doubles are two 32 bit words. The first is just mantissa, the second |
| 1333 | // is a mixture of sign, exponent and mantissa. Our current platforms are all |
| 1334 | // little endian apart from non-EABI arm which is little endian with big |
| 1335 | // endian floating point word ordering! |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1336 | static const int kMantissaOffset = kValueOffset; |
| 1337 | static const int kExponentOffset = kValueOffset + 4; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1338 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1339 | static const int kSize = kValueOffset + kDoubleSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1340 | static const uint32_t kSignMask = 0x80000000u; |
| 1341 | static const uint32_t kExponentMask = 0x7ff00000u; |
| 1342 | static const uint32_t kMantissaMask = 0xfffffu; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1343 | static const int kMantissaBits = 52; |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 1344 | static const int kExponentBits = 11; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1345 | static const int kExponentBias = 1023; |
| 1346 | static const int kExponentShift = 20; |
| 1347 | static const int kMantissaBitsInTopWord = 20; |
| 1348 | static const int kNonMantissaBitsInTopWord = 12; |
| 1349 | |
| 1350 | private: |
| 1351 | DISALLOW_IMPLICIT_CONSTRUCTORS(HeapNumber); |
| 1352 | }; |
| 1353 | |
| 1354 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1355 | enum EnsureElementsMode { |
| 1356 | DONT_ALLOW_DOUBLE_ELEMENTS, |
| 1357 | ALLOW_COPIED_DOUBLE_ELEMENTS, |
| 1358 | ALLOW_CONVERTED_DOUBLE_ELEMENTS |
| 1359 | }; |
| 1360 | |
| 1361 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 1362 | // Indicates whether a property should be set or (re)defined. Setting of a |
| 1363 | // property causes attributes to remain unchanged, writability to be checked |
| 1364 | // and callbacks to be called. Defining of a property causes attributes to |
| 1365 | // be updated and callbacks to be overridden. |
| 1366 | enum SetPropertyMode { |
| 1367 | SET_PROPERTY, |
| 1368 | DEFINE_PROPERTY |
| 1369 | }; |
| 1370 | |
| 1371 | |
| 1372 | // Indicator for one component of an AccessorPair. |
| 1373 | enum AccessorComponent { |
| 1374 | ACCESSOR_GETTER, |
| 1375 | ACCESSOR_SETTER |
| 1376 | }; |
| 1377 | |
| 1378 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1379 | // JSReceiver includes types on which properties can be defined, i.e., |
| 1380 | // JSObject and JSProxy. |
| 1381 | class JSReceiver: public HeapObject { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1382 | public: |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1383 | enum DeleteMode { |
| 1384 | NORMAL_DELETION, |
| 1385 | STRICT_DELETION, |
| 1386 | FORCE_DELETION |
| 1387 | }; |
| 1388 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1389 | // Casting. |
| 1390 | static inline JSReceiver* cast(Object* obj); |
| 1391 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1392 | static Handle<Object> SetProperty(Handle<JSReceiver> object, |
| 1393 | Handle<String> key, |
| 1394 | Handle<Object> value, |
| 1395 | PropertyAttributes attributes, |
| 1396 | StrictModeFlag strict_mode); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1397 | // Can cause GC. |
| 1398 | MUST_USE_RESULT MaybeObject* SetProperty(String* key, |
| 1399 | Object* value, |
| 1400 | PropertyAttributes attributes, |
| 1401 | StrictModeFlag strict_mode); |
| 1402 | MUST_USE_RESULT MaybeObject* SetProperty(LookupResult* result, |
| 1403 | String* key, |
| 1404 | Object* value, |
| 1405 | PropertyAttributes attributes, |
| 1406 | StrictModeFlag strict_mode); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1407 | MUST_USE_RESULT MaybeObject* SetPropertyWithDefinedSetter(JSReceiver* setter, |
| 1408 | Object* value); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1409 | |
| 1410 | MUST_USE_RESULT MaybeObject* DeleteProperty(String* name, DeleteMode mode); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1411 | MUST_USE_RESULT MaybeObject* DeleteElement(uint32_t index, DeleteMode mode); |
| 1412 | |
| 1413 | // Set the index'th array element. |
| 1414 | // Can cause GC, or return failure if GC is required. |
| 1415 | MUST_USE_RESULT MaybeObject* SetElement(uint32_t index, |
| 1416 | Object* value, |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 1417 | PropertyAttributes attributes, |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1418 | StrictModeFlag strict_mode, |
| 1419 | bool check_prototype); |
| 1420 | |
| 1421 | // Tests for the fast common case for property enumeration. |
| 1422 | bool IsSimpleEnum(); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1423 | |
| 1424 | // Returns the class name ([[Class]] property in the specification). |
| 1425 | String* class_name(); |
| 1426 | |
| 1427 | // Returns the constructor name (the name (possibly, inferred name) of the |
| 1428 | // function that was used to instantiate the object). |
| 1429 | String* constructor_name(); |
| 1430 | |
| 1431 | inline PropertyAttributes GetPropertyAttribute(String* name); |
| 1432 | PropertyAttributes GetPropertyAttributeWithReceiver(JSReceiver* receiver, |
| 1433 | String* name); |
| 1434 | PropertyAttributes GetLocalPropertyAttribute(String* name); |
| 1435 | |
| 1436 | // Can cause a GC. |
| 1437 | inline bool HasProperty(String* name); |
| 1438 | inline bool HasLocalProperty(String* name); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1439 | inline bool HasElement(uint32_t index); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1440 | |
| 1441 | // Return the object's prototype (might be Heap::null_value()). |
| 1442 | inline Object* GetPrototype(); |
| 1443 | |
| 1444 | // Set the object's prototype (only JSReceiver and null are allowed). |
| 1445 | MUST_USE_RESULT MaybeObject* SetPrototype(Object* value, |
| 1446 | bool skip_hidden_prototypes); |
| 1447 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1448 | // Retrieves a permanent object identity hash code. The undefined value might |
| 1449 | // be returned in case no hash was created yet and OMIT_CREATION was used. |
| 1450 | inline MUST_USE_RESULT MaybeObject* GetIdentityHash(CreationFlag flag); |
| 1451 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1452 | // Lookup a property. If found, the result is valid and has |
| 1453 | // detailed information. |
| 1454 | void LocalLookup(String* name, LookupResult* result); |
| 1455 | void Lookup(String* name, LookupResult* result); |
| 1456 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1457 | protected: |
| 1458 | Smi* GenerateIdentityHash(); |
| 1459 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1460 | private: |
| 1461 | PropertyAttributes GetPropertyAttribute(JSReceiver* receiver, |
| 1462 | LookupResult* result, |
| 1463 | String* name, |
| 1464 | bool continue_search); |
| 1465 | |
| 1466 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSReceiver); |
| 1467 | }; |
| 1468 | |
| 1469 | // The JSObject describes real heap allocated JavaScript objects with |
| 1470 | // properties. |
| 1471 | // Note that the map of JSObject changes during execution to enable inline |
| 1472 | // caching. |
| 1473 | class JSObject: public JSReceiver { |
| 1474 | public: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1475 | // [properties]: Backing storage for properties. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1476 | // properties is a FixedArray in the fast case and a Dictionary in the |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1477 | // slow case. |
| 1478 | DECL_ACCESSORS(properties, FixedArray) // Get and set fast properties. |
| 1479 | inline void initialize_properties(); |
| 1480 | inline bool HasFastProperties(); |
| 1481 | inline StringDictionary* property_dictionary(); // Gets slow properties. |
| 1482 | |
| 1483 | // [elements]: The elements (properties with names that are integers). |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1484 | // |
| 1485 | // Elements can be in two general modes: fast and slow. Each mode |
| 1486 | // corrensponds to a set of object representations of elements that |
| 1487 | // have something in common. |
| 1488 | // |
| 1489 | // In the fast mode elements is a FixedArray and so each element can |
| 1490 | // be quickly accessed. This fact is used in the generated code. The |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1491 | // elements array can have one of three maps in this mode: |
| 1492 | // fixed_array_map, non_strict_arguments_elements_map or |
| 1493 | // fixed_cow_array_map (for copy-on-write arrays). In the latter case |
| 1494 | // the elements array may be shared by a few objects and so before |
| 1495 | // writing to any element the array must be copied. Use |
| 1496 | // EnsureWritableFastElements in this case. |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1497 | // |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1498 | // In the slow mode the elements is either a NumberDictionary, an |
| 1499 | // ExternalArray, or a FixedArray parameter map for a (non-strict) |
| 1500 | // arguments object. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1501 | DECL_ACCESSORS(elements, FixedArrayBase) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1502 | inline void initialize_elements(); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1503 | MUST_USE_RESULT inline MaybeObject* ResetElements(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1504 | inline ElementsKind GetElementsKind(); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1505 | inline ElementsAccessor* GetElementsAccessor(); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1506 | inline bool HasFastSmiOnlyElements(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1507 | inline bool HasFastElements(); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1508 | // Returns if an object has either FAST_ELEMENT or FAST_SMI_ONLY_ELEMENT |
| 1509 | // elements. TODO(danno): Rename HasFastTypeElements to HasFastElements() and |
| 1510 | // HasFastElements to HasFastObjectElements. |
| 1511 | inline bool HasFastTypeElements(); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1512 | inline bool HasFastDoubleElements(); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1513 | inline bool HasNonStrictArgumentsElements(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1514 | inline bool HasDictionaryElements(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1515 | inline bool HasExternalPixelElements(); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1516 | inline bool HasExternalArrayElements(); |
| 1517 | inline bool HasExternalByteElements(); |
| 1518 | inline bool HasExternalUnsignedByteElements(); |
| 1519 | inline bool HasExternalShortElements(); |
| 1520 | inline bool HasExternalUnsignedShortElements(); |
| 1521 | inline bool HasExternalIntElements(); |
| 1522 | inline bool HasExternalUnsignedIntElements(); |
| 1523 | inline bool HasExternalFloatElements(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1524 | inline bool HasExternalDoubleElements(); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1525 | bool HasFastArgumentsElements(); |
| 1526 | bool HasDictionaryArgumentsElements(); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1527 | inline SeededNumberDictionary* element_dictionary(); // Gets slow elements. |
| 1528 | |
| 1529 | inline void set_map_and_elements( |
| 1530 | Map* map, |
| 1531 | FixedArrayBase* value, |
| 1532 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1533 | |
| 1534 | // Requires: HasFastElements(). |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1535 | MUST_USE_RESULT inline MaybeObject* EnsureWritableFastElements(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1536 | |
| 1537 | // Collects elements starting at index 0. |
| 1538 | // Undefined values are placed after non-undefined values. |
| 1539 | // Returns the number of non-undefined values. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1540 | MUST_USE_RESULT MaybeObject* PrepareElementsForSort(uint32_t limit); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1541 | // As PrepareElementsForSort, but only on objects where elements is |
| 1542 | // a dictionary, and it will stay a dictionary. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1543 | MUST_USE_RESULT MaybeObject* PrepareSlowElementsForSort(uint32_t limit); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1544 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1545 | MUST_USE_RESULT MaybeObject* GetPropertyWithCallback(Object* receiver, |
| 1546 | Object* structure, |
| 1547 | String* name); |
| 1548 | |
| 1549 | // Can cause GC. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1550 | MUST_USE_RESULT MaybeObject* SetPropertyForResult(LookupResult* result, |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1551 | String* key, |
| 1552 | Object* value, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1553 | PropertyAttributes attributes, |
| 1554 | StrictModeFlag strict_mode); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1555 | MUST_USE_RESULT MaybeObject* SetPropertyWithFailedAccessCheck( |
| 1556 | LookupResult* result, |
| 1557 | String* name, |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 1558 | Object* value, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1559 | bool check_prototype, |
| 1560 | StrictModeFlag strict_mode); |
| 1561 | MUST_USE_RESULT MaybeObject* SetPropertyWithCallback( |
| 1562 | Object* structure, |
| 1563 | String* name, |
| 1564 | Object* value, |
| 1565 | JSObject* holder, |
| 1566 | StrictModeFlag strict_mode); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1567 | MUST_USE_RESULT MaybeObject* SetPropertyWithInterceptor( |
| 1568 | String* name, |
| 1569 | Object* value, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1570 | PropertyAttributes attributes, |
| 1571 | StrictModeFlag strict_mode); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1572 | MUST_USE_RESULT MaybeObject* SetPropertyPostInterceptor( |
| 1573 | String* name, |
| 1574 | Object* value, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1575 | PropertyAttributes attributes, |
| 1576 | StrictModeFlag strict_mode); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1577 | |
| 1578 | static Handle<Object> SetLocalPropertyIgnoreAttributes( |
| 1579 | Handle<JSObject> object, |
| 1580 | Handle<String> key, |
| 1581 | Handle<Object> value, |
| 1582 | PropertyAttributes attributes); |
| 1583 | |
| 1584 | // Can cause GC. |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 1585 | MUST_USE_RESULT MaybeObject* SetLocalPropertyIgnoreAttributes( |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1586 | String* key, |
| 1587 | Object* value, |
| 1588 | PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1589 | |
| 1590 | // Retrieve a value in a normalized object given a lookup result. |
| 1591 | // Handles the special representation of JS global objects. |
| 1592 | Object* GetNormalizedProperty(LookupResult* result); |
| 1593 | |
| 1594 | // Sets the property value in a normalized object given a lookup result. |
| 1595 | // Handles the special representation of JS global objects. |
| 1596 | Object* SetNormalizedProperty(LookupResult* result, Object* value); |
| 1597 | |
| 1598 | // Sets the property value in a normalized object given (key, value, details). |
| 1599 | // Handles the special representation of JS global objects. |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1600 | static Handle<Object> SetNormalizedProperty(Handle<JSObject> object, |
| 1601 | Handle<String> key, |
| 1602 | Handle<Object> value, |
| 1603 | PropertyDetails details); |
| 1604 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1605 | MUST_USE_RESULT MaybeObject* SetNormalizedProperty(String* name, |
| 1606 | Object* value, |
| 1607 | PropertyDetails details); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1608 | |
| 1609 | // Deletes the named property in a normalized object. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1610 | MUST_USE_RESULT MaybeObject* DeleteNormalizedProperty(String* name, |
| 1611 | DeleteMode mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1612 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1613 | // Retrieve interceptors. |
| 1614 | InterceptorInfo* GetNamedInterceptor(); |
| 1615 | InterceptorInfo* GetIndexedInterceptor(); |
| 1616 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1617 | // Used from JSReceiver. |
| 1618 | PropertyAttributes GetPropertyAttributePostInterceptor(JSObject* receiver, |
| 1619 | String* name, |
| 1620 | bool continue_search); |
| 1621 | PropertyAttributes GetPropertyAttributeWithInterceptor(JSObject* receiver, |
| 1622 | String* name, |
| 1623 | bool continue_search); |
| 1624 | PropertyAttributes GetPropertyAttributeWithFailedAccessCheck( |
| 1625 | Object* receiver, |
| 1626 | LookupResult* result, |
| 1627 | String* name, |
| 1628 | bool continue_search); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1629 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 1630 | static void DefineAccessor(Handle<JSObject> object, |
| 1631 | Handle<String> name, |
| 1632 | Handle<Object> getter, |
| 1633 | Handle<Object> setter, |
| 1634 | PropertyAttributes attributes); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1635 | MUST_USE_RESULT MaybeObject* DefineAccessor(String* name, |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 1636 | Object* getter, |
| 1637 | Object* setter, |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1638 | PropertyAttributes attributes); |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 1639 | Object* LookupAccessor(String* name, AccessorComponent component); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1640 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1641 | MUST_USE_RESULT MaybeObject* DefineAccessor(AccessorInfo* info); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1642 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1643 | // Used from Object::GetProperty(). |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 1644 | MUST_USE_RESULT MaybeObject* GetPropertyWithFailedAccessCheck( |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1645 | Object* receiver, |
| 1646 | LookupResult* result, |
| 1647 | String* name, |
| 1648 | PropertyAttributes* attributes); |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 1649 | MUST_USE_RESULT MaybeObject* GetPropertyWithInterceptor( |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1650 | JSReceiver* receiver, |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1651 | String* name, |
| 1652 | PropertyAttributes* attributes); |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 1653 | MUST_USE_RESULT MaybeObject* GetPropertyPostInterceptor( |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1654 | JSReceiver* receiver, |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1655 | String* name, |
| 1656 | PropertyAttributes* attributes); |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 1657 | MUST_USE_RESULT MaybeObject* GetLocalPropertyPostInterceptor( |
| 1658 | JSReceiver* receiver, |
| 1659 | String* name, |
| 1660 | PropertyAttributes* attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1661 | |
| 1662 | // Returns true if this is an instance of an api function and has |
| 1663 | // been modified since it was created. May give false positives. |
| 1664 | bool IsDirty(); |
| 1665 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1666 | // If the receiver is a JSGlobalProxy this method will return its prototype, |
| 1667 | // otherwise the result is the receiver itself. |
| 1668 | inline Object* BypassGlobalProxy(); |
| 1669 | |
| 1670 | // Accessors for hidden properties object. |
| 1671 | // |
| 1672 | // Hidden properties are not local properties of the object itself. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1673 | // Instead they are stored in an auxiliary structure kept as a local |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1674 | // property with a special name Heap::hidden_symbol(). But if the |
| 1675 | // receiver is a JSGlobalProxy then the auxiliary object is a property |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1676 | // of its prototype, and if it's a detached proxy, then you can't have |
| 1677 | // hidden properties. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1678 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1679 | // Sets a hidden property on this object. Returns this object if successful, |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1680 | // undefined if called on a detached proxy. |
| 1681 | static Handle<Object> SetHiddenProperty(Handle<JSObject> obj, |
| 1682 | Handle<String> key, |
| 1683 | Handle<Object> value); |
| 1684 | // Returns a failure if a GC is required. |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 1685 | MUST_USE_RESULT MaybeObject* SetHiddenProperty(String* key, Object* value); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1686 | // Gets the value of a hidden property with the given key. Returns undefined |
| 1687 | // if the property doesn't exist (or if called on a detached proxy), |
| 1688 | // otherwise returns the value set for the key. |
| 1689 | Object* GetHiddenProperty(String* key); |
| 1690 | // Deletes a hidden property. Deleting a non-existing property is |
| 1691 | // considered successful. |
| 1692 | void DeleteHiddenProperty(String* key); |
| 1693 | // Returns true if the object has a property with the hidden symbol as name. |
| 1694 | bool HasHiddenProperties(); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1695 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1696 | static int GetIdentityHash(Handle<JSObject> obj); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1697 | MUST_USE_RESULT MaybeObject* GetIdentityHash(CreationFlag flag); |
| 1698 | MUST_USE_RESULT MaybeObject* SetIdentityHash(Object* hash, CreationFlag flag); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1699 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1700 | static Handle<Object> DeleteProperty(Handle<JSObject> obj, |
| 1701 | Handle<String> name); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1702 | MUST_USE_RESULT MaybeObject* DeleteProperty(String* name, DeleteMode mode); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1703 | |
| 1704 | static Handle<Object> DeleteElement(Handle<JSObject> obj, uint32_t index); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1705 | MUST_USE_RESULT MaybeObject* DeleteElement(uint32_t index, DeleteMode mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1706 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1707 | inline void ValidateSmiOnlyElements(); |
| 1708 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1709 | // Makes sure that this object can contain HeapObject as elements. |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 1710 | MUST_USE_RESULT inline MaybeObject* EnsureCanContainHeapObjectElements(); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1711 | |
| 1712 | // Makes sure that this object can contain the specified elements. |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 1713 | MUST_USE_RESULT inline MaybeObject* EnsureCanContainElements( |
| 1714 | Object** elements, |
| 1715 | uint32_t count, |
| 1716 | EnsureElementsMode mode); |
| 1717 | MUST_USE_RESULT inline MaybeObject* EnsureCanContainElements( |
| 1718 | FixedArrayBase* elements, |
| 1719 | EnsureElementsMode mode); |
| 1720 | MUST_USE_RESULT MaybeObject* EnsureCanContainElements( |
| 1721 | Arguments* arguments, |
| 1722 | uint32_t first_arg, |
| 1723 | uint32_t arg_count, |
| 1724 | EnsureElementsMode mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1725 | |
| 1726 | // Do we want to keep the elements in fast case when increasing the |
| 1727 | // capacity? |
| 1728 | bool ShouldConvertToSlowElements(int new_capacity); |
| 1729 | // Returns true if the backing storage for the slow-case elements of |
| 1730 | // this object takes up nearly as much space as a fast-case backing |
| 1731 | // storage would. In that case the JSObject should have fast |
| 1732 | // elements. |
| 1733 | bool ShouldConvertToFastElements(); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1734 | // Returns true if the elements of JSObject contains only values that can be |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1735 | // represented in a FixedDoubleArray and has at least one value that can only |
| 1736 | // be represented as a double and not a Smi. |
| 1737 | bool ShouldConvertToFastDoubleElements(bool* has_smi_only_elements); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1738 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1739 | // Tells whether the index'th element is present. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1740 | bool HasElementWithReceiver(JSReceiver* receiver, uint32_t index); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1741 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1742 | // Computes the new capacity when expanding the elements of a JSObject. |
| 1743 | static int NewElementsCapacity(int old_capacity) { |
| 1744 | // (old_capacity + 50%) + 16 |
| 1745 | return old_capacity + (old_capacity >> 1) + 16; |
| 1746 | } |
| 1747 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1748 | // Tells whether the index'th element is present and how it is stored. |
| 1749 | enum LocalElementType { |
| 1750 | // There is no element with given index. |
| 1751 | UNDEFINED_ELEMENT, |
| 1752 | |
| 1753 | // Element with given index is handled by interceptor. |
| 1754 | INTERCEPTED_ELEMENT, |
| 1755 | |
| 1756 | // Element with given index is character in string. |
| 1757 | STRING_CHARACTER_ELEMENT, |
| 1758 | |
| 1759 | // Element with given index is stored in fast backing store. |
| 1760 | FAST_ELEMENT, |
| 1761 | |
| 1762 | // Element with given index is stored in slow backing store. |
| 1763 | DICTIONARY_ELEMENT |
| 1764 | }; |
| 1765 | |
| 1766 | LocalElementType HasLocalElement(uint32_t index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1767 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1768 | bool HasElementWithInterceptor(JSReceiver* receiver, uint32_t index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1769 | |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 1770 | MUST_USE_RESULT MaybeObject* SetFastElement(uint32_t index, |
| 1771 | Object* value, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1772 | StrictModeFlag strict_mode, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1773 | bool check_prototype); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1774 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 1775 | MUST_USE_RESULT MaybeObject* SetDictionaryElement( |
| 1776 | uint32_t index, |
| 1777 | Object* value, |
| 1778 | PropertyAttributes attributes, |
| 1779 | StrictModeFlag strict_mode, |
| 1780 | bool check_prototype, |
| 1781 | SetPropertyMode set_mode = SET_PROPERTY); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1782 | |
| 1783 | MUST_USE_RESULT MaybeObject* SetFastDoubleElement( |
| 1784 | uint32_t index, |
| 1785 | Object* value, |
| 1786 | StrictModeFlag strict_mode, |
| 1787 | bool check_prototype = true); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1788 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1789 | static Handle<Object> SetOwnElement(Handle<JSObject> object, |
| 1790 | uint32_t index, |
| 1791 | Handle<Object> value, |
| 1792 | StrictModeFlag strict_mode); |
| 1793 | |
| 1794 | // Empty handle is returned if the element cannot be set to the given value. |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 1795 | static MUST_USE_RESULT Handle<Object> SetElement( |
| 1796 | Handle<JSObject> object, |
| 1797 | uint32_t index, |
| 1798 | Handle<Object> value, |
| 1799 | PropertyAttributes attr, |
| 1800 | StrictModeFlag strict_mode, |
| 1801 | SetPropertyMode set_mode = SET_PROPERTY); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1802 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1803 | // A Failure object is returned if GC is needed. |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 1804 | MUST_USE_RESULT MaybeObject* SetElement( |
| 1805 | uint32_t index, |
| 1806 | Object* value, |
| 1807 | PropertyAttributes attributes, |
| 1808 | StrictModeFlag strict_mode, |
| 1809 | bool check_prototype = true, |
| 1810 | SetPropertyMode set_mode = SET_PROPERTY); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1811 | |
| 1812 | // Returns the index'th element. |
| 1813 | // The undefined object if index is out of bounds. |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 1814 | MUST_USE_RESULT MaybeObject* GetElementWithInterceptor(Object* receiver, |
| 1815 | uint32_t index); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1816 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1817 | enum SetFastElementsCapacityMode { |
| 1818 | kAllowSmiOnlyElements, |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1819 | kForceSmiOnlyElements, |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1820 | kDontAllowSmiOnlyElements |
| 1821 | }; |
| 1822 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1823 | // Replace the elements' backing store with fast elements of the given |
| 1824 | // capacity. Update the length for JSArrays. Returns the new backing |
| 1825 | // store. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1826 | MUST_USE_RESULT MaybeObject* SetFastElementsCapacityAndLength( |
| 1827 | int capacity, |
| 1828 | int length, |
| 1829 | SetFastElementsCapacityMode set_capacity_mode); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1830 | MUST_USE_RESULT MaybeObject* SetFastDoubleElementsCapacityAndLength( |
| 1831 | int capacity, |
| 1832 | int length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1833 | |
| 1834 | // Lookup interceptors are used for handling properties controlled by host |
| 1835 | // objects. |
| 1836 | inline bool HasNamedInterceptor(); |
| 1837 | inline bool HasIndexedInterceptor(); |
| 1838 | |
| 1839 | // Support functions for v8 api (needed for correct interceptor behavior). |
| 1840 | bool HasRealNamedProperty(String* key); |
| 1841 | bool HasRealElementProperty(uint32_t index); |
| 1842 | bool HasRealNamedCallbackProperty(String* key); |
| 1843 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1844 | // Get the header size for a JSObject. Used to compute the index of |
| 1845 | // internal fields as well as the number of internal fields. |
| 1846 | inline int GetHeaderSize(); |
| 1847 | |
| 1848 | inline int GetInternalFieldCount(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1849 | inline int GetInternalFieldOffset(int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1850 | inline Object* GetInternalField(int index); |
| 1851 | inline void SetInternalField(int index, Object* value); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1852 | inline void SetInternalField(int index, Smi* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1853 | |
| 1854 | // The following lookup functions skip interceptors. |
| 1855 | void LocalLookupRealNamedProperty(String* name, LookupResult* result); |
| 1856 | void LookupRealNamedProperty(String* name, LookupResult* result); |
| 1857 | void LookupRealNamedPropertyInPrototypes(String* name, LookupResult* result); |
| 1858 | void LookupCallbackSetterInPrototypes(String* name, LookupResult* result); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1859 | MUST_USE_RESULT MaybeObject* SetElementWithCallbackSetterInPrototypes( |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1860 | uint32_t index, Object* value, bool* found, StrictModeFlag strict_mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1861 | void LookupCallback(String* name, LookupResult* result); |
| 1862 | |
| 1863 | // Returns the number of properties on this object filtering out properties |
| 1864 | // with the specified attributes (ignoring interceptors). |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 1865 | int NumberOfLocalProperties(PropertyAttributes filter = NONE); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1866 | // Fill in details for properties into storage starting at the specified |
| 1867 | // index. |
| 1868 | void GetLocalPropertyNames(FixedArray* storage, int index); |
| 1869 | |
| 1870 | // Returns the number of properties on this object filtering out properties |
| 1871 | // with the specified attributes (ignoring interceptors). |
| 1872 | int NumberOfLocalElements(PropertyAttributes filter); |
| 1873 | // Returns the number of enumerable elements (ignoring interceptors). |
| 1874 | int NumberOfEnumElements(); |
| 1875 | // Returns the number of elements on this object filtering out elements |
| 1876 | // with the specified attributes (ignoring interceptors). |
| 1877 | int GetLocalElementKeys(FixedArray* storage, PropertyAttributes filter); |
| 1878 | // Count and fill in the enumerable elements into storage. |
| 1879 | // (storage->length() == NumberOfEnumElements()). |
| 1880 | // If storage is NULL, will count the elements without adding |
| 1881 | // them to any storage. |
| 1882 | // Returns the number of enumerable elements. |
| 1883 | int GetEnumElementKeys(FixedArray* storage); |
| 1884 | |
| 1885 | // Add a property to a fast-case object using a map transition to |
| 1886 | // new_map. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1887 | MUST_USE_RESULT MaybeObject* AddFastPropertyUsingMap(Map* new_map, |
| 1888 | String* name, |
| 1889 | Object* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1890 | |
| 1891 | // Add a constant function property to a fast-case object. |
| 1892 | // This leaves a CONSTANT_TRANSITION in the old map, and |
| 1893 | // if it is called on a second object with this map, a |
| 1894 | // normal property is added instead, with a map transition. |
| 1895 | // This avoids the creation of many maps with the same constant |
| 1896 | // function, all orphaned. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1897 | MUST_USE_RESULT MaybeObject* AddConstantFunctionProperty( |
| 1898 | String* name, |
| 1899 | JSFunction* function, |
| 1900 | PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1901 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1902 | MUST_USE_RESULT MaybeObject* ReplaceSlowProperty( |
| 1903 | String* name, |
| 1904 | Object* value, |
| 1905 | PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1906 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1907 | // Returns a new map with all transitions dropped from the object's current |
| 1908 | // map and the ElementsKind set. |
| 1909 | static Handle<Map> GetElementsTransitionMap(Handle<JSObject> object, |
| 1910 | ElementsKind to_kind); |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 1911 | inline MUST_USE_RESULT MaybeObject* GetElementsTransitionMap( |
| 1912 | Isolate* isolate, |
| 1913 | ElementsKind elements_kind); |
| 1914 | MUST_USE_RESULT MaybeObject* GetElementsTransitionMapSlow( |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1915 | ElementsKind elements_kind); |
| 1916 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1917 | static Handle<Object> TransitionElementsKind(Handle<JSObject> object, |
| 1918 | ElementsKind to_kind); |
| 1919 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1920 | MUST_USE_RESULT MaybeObject* TransitionElementsKind(ElementsKind to_kind); |
| 1921 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1922 | // Converts a descriptor of any other type to a real field, |
| 1923 | // backed by the properties array. Descriptors of visible |
| 1924 | // types, such as CONSTANT_FUNCTION, keep their enumeration order. |
| 1925 | // Converts the descriptor on the original object's map to a |
| 1926 | // map transition, and the the new field is on the object's new map. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1927 | MUST_USE_RESULT MaybeObject* ConvertDescriptorToFieldAndMapTransition( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1928 | String* name, |
| 1929 | Object* new_value, |
| 1930 | PropertyAttributes attributes); |
| 1931 | |
| 1932 | // Converts a descriptor of any other type to a real field, |
| 1933 | // backed by the properties array. Descriptors of visible |
| 1934 | // types, such as CONSTANT_FUNCTION, keep their enumeration order. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1935 | MUST_USE_RESULT MaybeObject* ConvertDescriptorToField( |
| 1936 | String* name, |
| 1937 | Object* new_value, |
| 1938 | PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1939 | |
| 1940 | // Add a property to a fast-case object. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1941 | MUST_USE_RESULT MaybeObject* AddFastProperty(String* name, |
| 1942 | Object* value, |
| 1943 | PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1944 | |
| 1945 | // Add a property to a slow-case object. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1946 | MUST_USE_RESULT MaybeObject* AddSlowProperty(String* name, |
| 1947 | Object* value, |
| 1948 | PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1949 | |
| 1950 | // Add a property to an object. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1951 | MUST_USE_RESULT MaybeObject* AddProperty(String* name, |
| 1952 | Object* value, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1953 | PropertyAttributes attributes, |
| 1954 | StrictModeFlag strict_mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1955 | |
| 1956 | // Convert the object to use the canonical dictionary |
| 1957 | // representation. If the object is expected to have additional properties |
| 1958 | // added this number can be indicated to have the backing store allocated to |
| 1959 | // an initial capacity for holding these properties. |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1960 | static void NormalizeProperties(Handle<JSObject> object, |
| 1961 | PropertyNormalizationMode mode, |
| 1962 | int expected_additional_properties); |
| 1963 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1964 | MUST_USE_RESULT MaybeObject* NormalizeProperties( |
| 1965 | PropertyNormalizationMode mode, |
| 1966 | int expected_additional_properties); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1967 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1968 | // Convert and update the elements backing store to be a |
| 1969 | // SeededNumberDictionary dictionary. Returns the backing after conversion. |
| 1970 | static Handle<SeededNumberDictionary> NormalizeElements( |
| 1971 | Handle<JSObject> object); |
| 1972 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1973 | MUST_USE_RESULT MaybeObject* NormalizeElements(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1974 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 1975 | static void UpdateMapCodeCache(Handle<JSObject> object, |
| 1976 | Handle<String> name, |
| 1977 | Handle<Code> code); |
| 1978 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1979 | MUST_USE_RESULT MaybeObject* UpdateMapCodeCache(String* name, Code* code); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1980 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1981 | // Transform slow named properties to fast variants. |
| 1982 | // Returns failure if allocation failed. |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1983 | static void TransformToFastProperties(Handle<JSObject> object, |
| 1984 | int unused_property_fields); |
| 1985 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1986 | MUST_USE_RESULT MaybeObject* TransformToFastProperties( |
| 1987 | int unused_property_fields); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1988 | |
| 1989 | // Access fast-case object properties at index. |
| 1990 | inline Object* FastPropertyAt(int index); |
| 1991 | inline Object* FastPropertyAtPut(int index, Object* value); |
| 1992 | |
| 1993 | // Access to in object properties. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1994 | inline int GetInObjectPropertyOffset(int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1995 | inline Object* InObjectPropertyAt(int index); |
| 1996 | inline Object* InObjectPropertyAtPut(int index, |
| 1997 | Object* value, |
| 1998 | WriteBarrierMode mode |
| 1999 | = UPDATE_WRITE_BARRIER); |
| 2000 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2001 | // Initializes the body after properties slot, properties slot is |
| 2002 | // initialized by set_properties. Fill the pre-allocated fields with |
| 2003 | // pre_allocated_value and the rest with filler_value. |
| 2004 | // Note: this call does not update write barrier, the caller is responsible |
| 2005 | // to ensure that |filler_value| can be collected without WB here. |
| 2006 | inline void InitializeBody(Map* map, |
| 2007 | Object* pre_allocated_value, |
| 2008 | Object* filler_value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2009 | |
| 2010 | // Check whether this object references another object |
| 2011 | bool ReferencesObject(Object* obj); |
| 2012 | |
| 2013 | // Casting. |
| 2014 | static inline JSObject* cast(Object* obj); |
| 2015 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2016 | // Disalow further properties to be added to the object. |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 2017 | static Handle<Object> PreventExtensions(Handle<JSObject> object); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2018 | MUST_USE_RESULT MaybeObject* PreventExtensions(); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2019 | |
| 2020 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2021 | // Dispatched behavior. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2022 | void JSObjectShortPrint(StringStream* accumulator); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2023 | #ifdef OBJECT_PRINT |
| 2024 | inline void JSObjectPrint() { |
| 2025 | JSObjectPrint(stdout); |
| 2026 | } |
| 2027 | void JSObjectPrint(FILE* out); |
| 2028 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2029 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2030 | void JSObjectVerify(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2031 | #endif |
| 2032 | #ifdef OBJECT_PRINT |
| 2033 | inline void PrintProperties() { |
| 2034 | PrintProperties(stdout); |
| 2035 | } |
| 2036 | void PrintProperties(FILE* out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2037 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2038 | inline void PrintElements() { |
| 2039 | PrintElements(stdout); |
| 2040 | } |
| 2041 | void PrintElements(FILE* out); |
| 2042 | #endif |
| 2043 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2044 | void PrintElementsTransition( |
| 2045 | FILE* file, ElementsKind from_kind, FixedArrayBase* from_elements, |
| 2046 | ElementsKind to_kind, FixedArrayBase* to_elements); |
| 2047 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2048 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2049 | // Structure for collecting spill information about JSObjects. |
| 2050 | class SpillInformation { |
| 2051 | public: |
| 2052 | void Clear(); |
| 2053 | void Print(); |
| 2054 | int number_of_objects_; |
| 2055 | int number_of_objects_with_fast_properties_; |
| 2056 | int number_of_objects_with_fast_elements_; |
| 2057 | int number_of_fast_used_fields_; |
| 2058 | int number_of_fast_unused_fields_; |
| 2059 | int number_of_slow_used_properties_; |
| 2060 | int number_of_slow_unused_properties_; |
| 2061 | int number_of_fast_used_elements_; |
| 2062 | int number_of_fast_unused_elements_; |
| 2063 | int number_of_slow_used_elements_; |
| 2064 | int number_of_slow_unused_elements_; |
| 2065 | }; |
| 2066 | |
| 2067 | void IncrementSpillStatistics(SpillInformation* info); |
| 2068 | #endif |
| 2069 | Object* SlowReverseLookup(Object* value); |
| 2070 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2071 | // Maximal number of fast properties for the JSObject. Used to |
| 2072 | // restrict the number of map transitions to avoid an explosion in |
| 2073 | // the number of maps for objects used as dictionaries. |
| 2074 | inline int MaxFastProperties(); |
| 2075 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2076 | // Maximal number of elements (numbered 0 .. kMaxElementCount - 1). |
| 2077 | // Also maximal value of JSArray's length property. |
| 2078 | static const uint32_t kMaxElementCount = 0xffffffffu; |
| 2079 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2080 | // Constants for heuristics controlling conversion of fast elements |
| 2081 | // to slow elements. |
| 2082 | |
| 2083 | // Maximal gap that can be introduced by adding an element beyond |
| 2084 | // the current elements length. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2085 | static const uint32_t kMaxGap = 1024; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2086 | |
| 2087 | // Maximal length of fast elements array that won't be checked for |
| 2088 | // being dense enough on expansion. |
| 2089 | static const int kMaxUncheckedFastElementsLength = 5000; |
| 2090 | |
| 2091 | // Same as above but for old arrays. This limit is more strict. We |
| 2092 | // don't want to be wasteful with long lived objects. |
| 2093 | static const int kMaxUncheckedOldFastElementsLength = 500; |
| 2094 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2095 | static const int kInitialMaxFastElementArray = 100000; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2096 | static const int kMaxFastProperties = 12; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2097 | static const int kMaxInstanceSize = 255 * kPointerSize; |
| 2098 | // When extending the backing storage for property values, we increase |
| 2099 | // its size by more than the 1 entry necessary, so sequentially adding fields |
| 2100 | // to the same object requires fewer allocations and copies. |
| 2101 | static const int kFieldsAdded = 3; |
| 2102 | |
| 2103 | // Layout description. |
| 2104 | static const int kPropertiesOffset = HeapObject::kHeaderSize; |
| 2105 | static const int kElementsOffset = kPropertiesOffset + kPointerSize; |
| 2106 | static const int kHeaderSize = kElementsOffset + kPointerSize; |
| 2107 | |
| 2108 | STATIC_CHECK(kHeaderSize == Internals::kJSObjectHeaderSize); |
| 2109 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2110 | class BodyDescriptor : public FlexibleBodyDescriptor<kPropertiesOffset> { |
| 2111 | public: |
| 2112 | static inline int SizeOf(Map* map, HeapObject* object); |
| 2113 | }; |
| 2114 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2115 | private: |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2116 | friend class DictionaryElementsAccessor; |
| 2117 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2118 | MUST_USE_RESULT MaybeObject* GetElementWithCallback(Object* receiver, |
| 2119 | Object* structure, |
| 2120 | uint32_t index, |
| 2121 | Object* holder); |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 2122 | MUST_USE_RESULT MaybeObject* SetElementWithCallback( |
| 2123 | Object* structure, |
| 2124 | uint32_t index, |
| 2125 | Object* value, |
| 2126 | JSObject* holder, |
| 2127 | StrictModeFlag strict_mode); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2128 | MUST_USE_RESULT MaybeObject* SetElementWithInterceptor( |
| 2129 | uint32_t index, |
| 2130 | Object* value, |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 2131 | PropertyAttributes attributes, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2132 | StrictModeFlag strict_mode, |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 2133 | bool check_prototype, |
| 2134 | SetPropertyMode set_mode); |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 2135 | MUST_USE_RESULT MaybeObject* SetElementWithoutInterceptor( |
| 2136 | uint32_t index, |
| 2137 | Object* value, |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 2138 | PropertyAttributes attributes, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2139 | StrictModeFlag strict_mode, |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 2140 | bool check_prototype, |
| 2141 | SetPropertyMode set_mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2142 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2143 | // Searches the prototype chain for a callback setter and sets the property |
| 2144 | // with the setter if it finds one. The '*found' flag indicates whether |
| 2145 | // a setter was found or not. |
| 2146 | // This function can cause GC and can return a failure result with |
| 2147 | // '*found==true'. |
| 2148 | MUST_USE_RESULT MaybeObject* SetPropertyWithCallbackSetterInPrototypes( |
| 2149 | String* name, |
| 2150 | Object* value, |
| 2151 | PropertyAttributes attributes, |
| 2152 | bool* found, |
| 2153 | StrictModeFlag strict_mode); |
| 2154 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2155 | MUST_USE_RESULT MaybeObject* DeletePropertyPostInterceptor(String* name, |
| 2156 | DeleteMode mode); |
| 2157 | MUST_USE_RESULT MaybeObject* DeletePropertyWithInterceptor(String* name); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2158 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2159 | MUST_USE_RESULT MaybeObject* DeleteElementWithInterceptor(uint32_t index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2160 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2161 | MUST_USE_RESULT MaybeObject* DeleteFastElement(uint32_t index); |
| 2162 | MUST_USE_RESULT MaybeObject* DeleteDictionaryElement(uint32_t index, |
| 2163 | DeleteMode mode); |
| 2164 | |
| 2165 | bool ReferencesObjectFromElements(FixedArray* elements, |
| 2166 | ElementsKind kind, |
| 2167 | Object* object); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2168 | |
| 2169 | // Returns true if most of the elements backing storage is used. |
| 2170 | bool HasDenseElements(); |
| 2171 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2172 | // Gets the current elements capacity and the number of used elements. |
| 2173 | void GetElementsCapacityAndUsage(int* capacity, int* used); |
| 2174 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2175 | bool CanSetCallback(String* name); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2176 | MUST_USE_RESULT MaybeObject* SetElementCallback( |
| 2177 | uint32_t index, |
| 2178 | Object* structure, |
| 2179 | PropertyAttributes attributes); |
| 2180 | MUST_USE_RESULT MaybeObject* SetPropertyCallback( |
| 2181 | String* name, |
| 2182 | Object* structure, |
| 2183 | PropertyAttributes attributes); |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 2184 | MUST_USE_RESULT MaybeObject* DefineElementAccessor( |
| 2185 | uint32_t index, |
| 2186 | Object* getter, |
| 2187 | Object* setter, |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2188 | PropertyAttributes attributes); |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 2189 | MUST_USE_RESULT MaybeObject* DefinePropertyAccessor( |
| 2190 | String* name, |
| 2191 | Object* getter, |
| 2192 | Object* setter, |
| 2193 | PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2194 | void LookupInDescriptor(String* name, LookupResult* result); |
| 2195 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2196 | // Returns the hidden properties backing store object, currently |
| 2197 | // a StringDictionary, stored on this object. |
| 2198 | // If no hidden properties object has been put on this object, |
| 2199 | // return undefined, unless create_if_absent is true, in which case |
| 2200 | // a new dictionary is created, added to this object, and returned. |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 2201 | MUST_USE_RESULT MaybeObject* GetHiddenPropertiesDictionary( |
| 2202 | bool create_if_absent); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2203 | // Updates the existing hidden properties dictionary. |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 2204 | MUST_USE_RESULT MaybeObject* SetHiddenPropertiesDictionary( |
| 2205 | StringDictionary* dictionary); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2206 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2207 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSObject); |
| 2208 | }; |
| 2209 | |
| 2210 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2211 | // Common superclass for FixedArrays that allow implementations to share |
| 2212 | // common accessors and some code paths. |
| 2213 | class FixedArrayBase: public HeapObject { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2214 | public: |
| 2215 | // [length]: length of the array. |
| 2216 | inline int length(); |
| 2217 | inline void set_length(int value); |
| 2218 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2219 | inline static FixedArrayBase* cast(Object* object); |
| 2220 | |
| 2221 | // Layout description. |
| 2222 | // Length is smi tagged when it is stored. |
| 2223 | static const int kLengthOffset = HeapObject::kHeaderSize; |
| 2224 | static const int kHeaderSize = kLengthOffset + kPointerSize; |
| 2225 | }; |
| 2226 | |
| 2227 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2228 | class FixedDoubleArray; |
| 2229 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2230 | // FixedArray describes fixed-sized arrays with element type Object*. |
| 2231 | class FixedArray: public FixedArrayBase { |
| 2232 | public: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2233 | // Setter and getter for elements. |
| 2234 | inline Object* get(int index); |
| 2235 | // Setter that uses write barrier. |
| 2236 | inline void set(int index, Object* value); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2237 | inline bool is_the_hole(int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2238 | |
| 2239 | // Setter that doesn't need write barrier). |
| 2240 | inline void set(int index, Smi* value); |
| 2241 | // Setter with explicit barrier mode. |
| 2242 | inline void set(int index, Object* value, WriteBarrierMode mode); |
| 2243 | |
| 2244 | // Setters for frequently used oddballs located in old space. |
| 2245 | inline void set_undefined(int index); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2246 | // TODO(isolates): duplicate. |
| 2247 | inline void set_undefined(Heap* heap, int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2248 | inline void set_null(int index); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2249 | // TODO(isolates): duplicate. |
| 2250 | inline void set_null(Heap* heap, int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2251 | inline void set_the_hole(int index); |
| 2252 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2253 | // Setters with less debug checks for the GC to use. |
| 2254 | inline void set_unchecked(int index, Smi* value); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2255 | inline void set_null_unchecked(Heap* heap, int index); |
| 2256 | inline void set_unchecked(Heap* heap, int index, Object* value, |
| 2257 | WriteBarrierMode mode); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2258 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2259 | // Gives access to raw memory which stores the array's data. |
| 2260 | inline Object** data_start(); |
| 2261 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 2262 | inline Object** GetFirstElementAddress(); |
| 2263 | inline bool ContainsOnlySmisOrHoles(); |
| 2264 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2265 | // Copy operations. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2266 | MUST_USE_RESULT inline MaybeObject* Copy(); |
| 2267 | MUST_USE_RESULT MaybeObject* CopySize(int new_length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2268 | |
| 2269 | // Add the elements of a JSArray to this FixedArray. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2270 | MUST_USE_RESULT MaybeObject* AddKeysFromJSArray(JSArray* array); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2271 | |
| 2272 | // Compute the union of this and other. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2273 | MUST_USE_RESULT MaybeObject* UnionOfKeys(FixedArray* other); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2274 | |
| 2275 | // Copy a sub array from the receiver to dest. |
| 2276 | void CopyTo(int pos, FixedArray* dest, int dest_pos, int len); |
| 2277 | |
| 2278 | // Garbage collection support. |
| 2279 | static int SizeFor(int length) { return kHeaderSize + length * kPointerSize; } |
| 2280 | |
| 2281 | // Code Generation support. |
| 2282 | static int OffsetOfElementAt(int index) { return SizeFor(index); } |
| 2283 | |
| 2284 | // Casting. |
| 2285 | static inline FixedArray* cast(Object* obj); |
| 2286 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2287 | // Maximal allowed size, in bytes, of a single FixedArray. |
| 2288 | // Prevents overflowing size computations, as well as extreme memory |
| 2289 | // consumption. |
Ben Murdoch | 692be65 | 2012-01-10 18:47:50 +0000 | [diff] [blame] | 2290 | static const int kMaxSize = 128 * MB * kPointerSize; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2291 | // Maximally allowed length of a FixedArray. |
| 2292 | static const int kMaxLength = (kMaxSize - kHeaderSize) / kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2293 | |
| 2294 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2295 | #ifdef OBJECT_PRINT |
| 2296 | inline void FixedArrayPrint() { |
| 2297 | FixedArrayPrint(stdout); |
| 2298 | } |
| 2299 | void FixedArrayPrint(FILE* out); |
| 2300 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2301 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2302 | void FixedArrayVerify(); |
| 2303 | // Checks if two FixedArrays have identical contents. |
| 2304 | bool IsEqualTo(FixedArray* other); |
| 2305 | #endif |
| 2306 | |
| 2307 | // Swap two elements in a pair of arrays. If this array and the |
| 2308 | // numbers array are the same object, the elements are only swapped |
| 2309 | // once. |
| 2310 | void SwapPairs(FixedArray* numbers, int i, int j); |
| 2311 | |
| 2312 | // Sort prefix of this array and the numbers array as pairs wrt. the |
| 2313 | // numbers. If the numbers array and the this array are the same |
| 2314 | // object, the prefix of this array is sorted. |
| 2315 | void SortPairs(FixedArray* numbers, uint32_t len); |
| 2316 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2317 | class BodyDescriptor : public FlexibleBodyDescriptor<kHeaderSize> { |
| 2318 | public: |
| 2319 | static inline int SizeOf(Map* map, HeapObject* object) { |
| 2320 | return SizeFor(reinterpret_cast<FixedArray*>(object)->length()); |
| 2321 | } |
| 2322 | }; |
| 2323 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2324 | protected: |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 2325 | // Set operation on FixedArray without using write barriers. Can |
| 2326 | // only be used for storing old space objects or smis. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2327 | static inline void NoWriteBarrierSet(FixedArray* array, |
| 2328 | int index, |
| 2329 | Object* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2330 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 2331 | // Set operation on FixedArray without incremental write barrier. Can |
| 2332 | // only be used if the object is guaranteed to be white (whiteness witness |
| 2333 | // is present). |
| 2334 | static inline void NoIncrementalWriteBarrierSet(FixedArray* array, |
| 2335 | int index, |
| 2336 | Object* value); |
| 2337 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2338 | private: |
| 2339 | DISALLOW_IMPLICIT_CONSTRUCTORS(FixedArray); |
| 2340 | }; |
| 2341 | |
| 2342 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2343 | // FixedDoubleArray describes fixed-sized arrays with element type double. |
| 2344 | class FixedDoubleArray: public FixedArrayBase { |
| 2345 | public: |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2346 | // Setter and getter for elements. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2347 | inline double get_scalar(int index); |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 2348 | inline int64_t get_representation(int index); |
| 2349 | MUST_USE_RESULT inline MaybeObject* get(int index); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2350 | inline void set(int index, double value); |
| 2351 | inline void set_the_hole(int index); |
| 2352 | |
| 2353 | // Checking for the hole. |
| 2354 | inline bool is_the_hole(int index); |
| 2355 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2356 | // Copy operations |
| 2357 | MUST_USE_RESULT inline MaybeObject* Copy(); |
| 2358 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2359 | // Garbage collection support. |
| 2360 | inline static int SizeFor(int length) { |
| 2361 | return kHeaderSize + length * kDoubleSize; |
| 2362 | } |
| 2363 | |
| 2364 | // Code Generation support. |
| 2365 | static int OffsetOfElementAt(int index) { return SizeFor(index); } |
| 2366 | |
| 2367 | inline static bool is_the_hole_nan(double value); |
| 2368 | inline static double hole_nan_as_double(); |
| 2369 | inline static double canonical_not_the_hole_nan_as_double(); |
| 2370 | |
| 2371 | // Casting. |
| 2372 | static inline FixedDoubleArray* cast(Object* obj); |
| 2373 | |
| 2374 | // Maximal allowed size, in bytes, of a single FixedDoubleArray. |
| 2375 | // Prevents overflowing size computations, as well as extreme memory |
| 2376 | // consumption. |
| 2377 | static const int kMaxSize = 512 * MB; |
| 2378 | // Maximally allowed length of a FixedArray. |
| 2379 | static const int kMaxLength = (kMaxSize - kHeaderSize) / kDoubleSize; |
| 2380 | |
| 2381 | // Dispatched behavior. |
| 2382 | #ifdef OBJECT_PRINT |
| 2383 | inline void FixedDoubleArrayPrint() { |
| 2384 | FixedDoubleArrayPrint(stdout); |
| 2385 | } |
| 2386 | void FixedDoubleArrayPrint(FILE* out); |
| 2387 | #endif |
| 2388 | |
| 2389 | #ifdef DEBUG |
| 2390 | void FixedDoubleArrayVerify(); |
| 2391 | #endif |
| 2392 | |
| 2393 | private: |
| 2394 | DISALLOW_IMPLICIT_CONSTRUCTORS(FixedDoubleArray); |
| 2395 | }; |
| 2396 | |
| 2397 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2398 | class IncrementalMarking; |
| 2399 | |
| 2400 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2401 | // DescriptorArrays are fixed arrays used to hold instance descriptors. |
| 2402 | // The format of the these objects is: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2403 | // TODO(1399): It should be possible to make room for bit_field3 in the map |
| 2404 | // without overloading the instance descriptors field in the map |
| 2405 | // (and storing it in the DescriptorArray when the map has one). |
| 2406 | // [0]: storage for bit_field3 for Map owning this object (Smi) |
| 2407 | // [1]: point to a fixed array with (value, detail) pairs. |
| 2408 | // [2]: next enumeration index (Smi), or pointer to small fixed array: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2409 | // [0]: next enumeration index (Smi) |
| 2410 | // [1]: pointer to fixed array with enum cache |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2411 | // [3]: first key |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2412 | // [length() - 1]: last key |
| 2413 | // |
| 2414 | class DescriptorArray: public FixedArray { |
| 2415 | public: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2416 | // Returns true for both shared empty_descriptor_array and for smis, which the |
| 2417 | // map uses to encode additional bit fields when the descriptor array is not |
| 2418 | // yet used. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2419 | inline bool IsEmpty(); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2420 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2421 | // Returns the number of descriptors in the array. |
| 2422 | int number_of_descriptors() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2423 | ASSERT(length() > kFirstIndex || IsEmpty()); |
| 2424 | int len = length(); |
| 2425 | return len <= kFirstIndex ? 0 : len - kFirstIndex; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2426 | } |
| 2427 | |
| 2428 | int NextEnumerationIndex() { |
| 2429 | if (IsEmpty()) return PropertyDetails::kInitialIndex; |
| 2430 | Object* obj = get(kEnumerationIndexIndex); |
| 2431 | if (obj->IsSmi()) { |
| 2432 | return Smi::cast(obj)->value(); |
| 2433 | } else { |
| 2434 | Object* index = FixedArray::cast(obj)->get(kEnumCacheBridgeEnumIndex); |
| 2435 | return Smi::cast(index)->value(); |
| 2436 | } |
| 2437 | } |
| 2438 | |
| 2439 | // Set next enumeration index and flush any enum cache. |
| 2440 | void SetNextEnumerationIndex(int value) { |
| 2441 | if (!IsEmpty()) { |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2442 | set(kEnumerationIndexIndex, Smi::FromInt(value)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2443 | } |
| 2444 | } |
| 2445 | bool HasEnumCache() { |
| 2446 | return !IsEmpty() && !get(kEnumerationIndexIndex)->IsSmi(); |
| 2447 | } |
| 2448 | |
| 2449 | Object* GetEnumCache() { |
| 2450 | ASSERT(HasEnumCache()); |
| 2451 | FixedArray* bridge = FixedArray::cast(get(kEnumerationIndexIndex)); |
| 2452 | return bridge->get(kEnumCacheBridgeCacheIndex); |
| 2453 | } |
| 2454 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2455 | // TODO(1399): It should be possible to make room for bit_field3 in the map |
| 2456 | // without overloading the instance descriptors field in the map |
| 2457 | // (and storing it in the DescriptorArray when the map has one). |
| 2458 | inline int bit_field3_storage(); |
| 2459 | inline void set_bit_field3_storage(int value); |
| 2460 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2461 | // Initialize or change the enum cache, |
| 2462 | // using the supplied storage for the small "bridge". |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 2463 | void SetEnumCache(FixedArray* bridge_storage, |
| 2464 | FixedArray* new_cache, |
| 2465 | Object* new_index_cache); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2466 | |
| 2467 | // Accessors for fetching instance descriptor at descriptor number. |
| 2468 | inline String* GetKey(int descriptor_number); |
| 2469 | inline Object* GetValue(int descriptor_number); |
| 2470 | inline Smi* GetDetails(int descriptor_number); |
| 2471 | inline PropertyType GetType(int descriptor_number); |
| 2472 | inline int GetFieldIndex(int descriptor_number); |
| 2473 | inline JSFunction* GetConstantFunction(int descriptor_number); |
| 2474 | inline Object* GetCallbacksObject(int descriptor_number); |
| 2475 | inline AccessorDescriptor* GetCallbacks(int descriptor_number); |
| 2476 | inline bool IsProperty(int descriptor_number); |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 2477 | inline bool IsTransitionOnly(int descriptor_number); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2478 | inline bool IsNullDescriptor(int descriptor_number); |
| 2479 | inline bool IsDontEnum(int descriptor_number); |
| 2480 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2481 | class WhitenessWitness { |
| 2482 | public: |
| 2483 | inline explicit WhitenessWitness(DescriptorArray* array); |
| 2484 | inline ~WhitenessWitness(); |
| 2485 | |
| 2486 | private: |
| 2487 | IncrementalMarking* marking_; |
| 2488 | }; |
| 2489 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2490 | // Accessor for complete descriptor. |
| 2491 | inline void Get(int descriptor_number, Descriptor* desc); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2492 | inline void Set(int descriptor_number, |
| 2493 | Descriptor* desc, |
| 2494 | const WhitenessWitness&); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2495 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 2496 | // Transfer a complete descriptor from the src descriptor array to the dst |
| 2497 | // one, dropping map transitions in CALLBACKS. |
| 2498 | static void CopyFrom(Handle<DescriptorArray> dst, |
| 2499 | int dst_index, |
| 2500 | Handle<DescriptorArray> src, |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2501 | int src_index, |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 2502 | const WhitenessWitness& witness); |
| 2503 | |
| 2504 | // Transfer a complete descriptor from the src descriptor array to this |
| 2505 | // descriptor array, dropping map transitions in CALLBACKS. |
| 2506 | MUST_USE_RESULT MaybeObject* CopyFrom(int dst_index, |
| 2507 | DescriptorArray* src, |
| 2508 | int src_index, |
| 2509 | const WhitenessWitness&); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2510 | |
| 2511 | // Copy the descriptor array, insert a new descriptor and optionally |
| 2512 | // remove map transitions. If the descriptor is already present, it is |
| 2513 | // replaced. If a replaced descriptor is a real property (not a transition |
| 2514 | // or null), its enumeration index is kept as is. |
| 2515 | // If adding a real property, map transitions must be removed. If adding |
| 2516 | // a transition, they must not be removed. All null descriptors are removed. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2517 | MUST_USE_RESULT MaybeObject* CopyInsert(Descriptor* descriptor, |
| 2518 | TransitionFlag transition_flag); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2519 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 2520 | // Return a copy of the array with all transitions and null descriptors |
| 2521 | // removed. Return a Failure object in case of an allocation failure. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2522 | MUST_USE_RESULT MaybeObject* RemoveTransitions(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2523 | |
| 2524 | // Sort the instance descriptors by the hash codes of their keys. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 2525 | // Does not check for duplicates. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2526 | void SortUnchecked(const WhitenessWitness&); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 2527 | |
| 2528 | // Sort the instance descriptors by the hash codes of their keys. |
| 2529 | // Checks the result for duplicates. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2530 | void Sort(const WhitenessWitness&); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2531 | |
| 2532 | // Search the instance descriptors for given name. |
| 2533 | inline int Search(String* name); |
| 2534 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2535 | // As the above, but uses DescriptorLookupCache and updates it when |
| 2536 | // necessary. |
| 2537 | inline int SearchWithCache(String* name); |
| 2538 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2539 | // Tells whether the name is present int the array. |
| 2540 | bool Contains(String* name) { return kNotFound != Search(name); } |
| 2541 | |
| 2542 | // Perform a binary search in the instance descriptors represented |
| 2543 | // by this fixed array. low and high are descriptor indices. If there |
| 2544 | // are three instance descriptors in this array it should be called |
| 2545 | // with low=0 and high=2. |
| 2546 | int BinarySearch(String* name, int low, int high); |
| 2547 | |
| 2548 | // Perform a linear search in the instance descriptors represented |
| 2549 | // by this fixed array. len is the number of descriptor indices that are |
| 2550 | // valid. Does not require the descriptors to be sorted. |
| 2551 | int LinearSearch(String* name, int len); |
| 2552 | |
| 2553 | // Allocates a DescriptorArray, but returns the singleton |
| 2554 | // empty descriptor array object if number_of_descriptors is 0. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2555 | MUST_USE_RESULT static MaybeObject* Allocate(int number_of_descriptors); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2556 | |
| 2557 | // Casting. |
| 2558 | static inline DescriptorArray* cast(Object* obj); |
| 2559 | |
| 2560 | // Constant for denoting key was not found. |
| 2561 | static const int kNotFound = -1; |
| 2562 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2563 | static const int kBitField3StorageIndex = 0; |
| 2564 | static const int kContentArrayIndex = 1; |
| 2565 | static const int kEnumerationIndexIndex = 2; |
| 2566 | static const int kFirstIndex = 3; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2567 | |
| 2568 | // The length of the "bridge" to the enum cache. |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 2569 | static const int kEnumCacheBridgeLength = 3; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2570 | static const int kEnumCacheBridgeEnumIndex = 0; |
| 2571 | static const int kEnumCacheBridgeCacheIndex = 1; |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 2572 | static const int kEnumCacheBridgeIndicesCacheIndex = 2; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2573 | |
| 2574 | // Layout description. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2575 | static const int kBitField3StorageOffset = FixedArray::kHeaderSize; |
| 2576 | static const int kContentArrayOffset = kBitField3StorageOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2577 | static const int kEnumerationIndexOffset = kContentArrayOffset + kPointerSize; |
| 2578 | static const int kFirstOffset = kEnumerationIndexOffset + kPointerSize; |
| 2579 | |
| 2580 | // Layout description for the bridge array. |
| 2581 | static const int kEnumCacheBridgeEnumOffset = FixedArray::kHeaderSize; |
| 2582 | static const int kEnumCacheBridgeCacheOffset = |
| 2583 | kEnumCacheBridgeEnumOffset + kPointerSize; |
| 2584 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2585 | #ifdef OBJECT_PRINT |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2586 | // Print all the descriptors. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2587 | inline void PrintDescriptors() { |
| 2588 | PrintDescriptors(stdout); |
| 2589 | } |
| 2590 | void PrintDescriptors(FILE* out); |
| 2591 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2592 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2593 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2594 | // Is the descriptor array sorted and without duplicates? |
| 2595 | bool IsSortedNoDuplicates(); |
| 2596 | |
| 2597 | // Are two DescriptorArrays equal? |
| 2598 | bool IsEqualTo(DescriptorArray* other); |
| 2599 | #endif |
| 2600 | |
| 2601 | // The maximum number of descriptors we want in a descriptor array (should |
| 2602 | // fit in a page). |
| 2603 | static const int kMaxNumberOfDescriptors = 1024 + 512; |
| 2604 | |
| 2605 | private: |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 2606 | // An entry in a DescriptorArray, represented as an (array, index) pair. |
| 2607 | class Entry { |
| 2608 | public: |
| 2609 | inline explicit Entry(DescriptorArray* descs, int index) : |
| 2610 | descs_(descs), index_(index) { } |
| 2611 | |
| 2612 | inline PropertyType type() { return descs_->GetType(index_); } |
| 2613 | inline Object* GetCallbackObject() { return descs_->GetValue(index_); } |
| 2614 | |
| 2615 | private: |
| 2616 | DescriptorArray* descs_; |
| 2617 | int index_; |
| 2618 | }; |
| 2619 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2620 | // Conversion from descriptor number to array indices. |
| 2621 | static int ToKeyIndex(int descriptor_number) { |
| 2622 | return descriptor_number+kFirstIndex; |
| 2623 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2624 | |
| 2625 | static int ToDetailsIndex(int descriptor_number) { |
| 2626 | return (descriptor_number << 1) + 1; |
| 2627 | } |
| 2628 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2629 | static int ToValueIndex(int descriptor_number) { |
| 2630 | return descriptor_number << 1; |
| 2631 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2632 | |
| 2633 | bool is_null_descriptor(int descriptor_number) { |
| 2634 | return PropertyDetails(GetDetails(descriptor_number)).type() == |
| 2635 | NULL_DESCRIPTOR; |
| 2636 | } |
| 2637 | // Swap operation on FixedArray without using write barriers. |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 2638 | static inline void NoIncrementalWriteBarrierSwap( |
| 2639 | FixedArray* array, int first, int second); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2640 | |
| 2641 | // Swap descriptor first and second. |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 2642 | inline void NoIncrementalWriteBarrierSwapDescriptors( |
| 2643 | int first, int second); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2644 | |
| 2645 | FixedArray* GetContentArray() { |
| 2646 | return FixedArray::cast(get(kContentArrayIndex)); |
| 2647 | } |
| 2648 | DISALLOW_IMPLICIT_CONSTRUCTORS(DescriptorArray); |
| 2649 | }; |
| 2650 | |
| 2651 | |
| 2652 | // HashTable is a subclass of FixedArray that implements a hash table |
| 2653 | // that uses open addressing and quadratic probing. |
| 2654 | // |
| 2655 | // In order for the quadratic probing to work, elements that have not |
| 2656 | // yet been used and elements that have been deleted are |
| 2657 | // distinguished. Probing continues when deleted elements are |
| 2658 | // encountered and stops when unused elements are encountered. |
| 2659 | // |
| 2660 | // - Elements with key == undefined have not been used yet. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2661 | // - Elements with key == the_hole have been deleted. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2662 | // |
| 2663 | // The hash table class is parameterized with a Shape and a Key. |
| 2664 | // Shape must be a class with the following interface: |
| 2665 | // class ExampleShape { |
| 2666 | // public: |
| 2667 | // // Tells whether key matches other. |
| 2668 | // static bool IsMatch(Key key, Object* other); |
| 2669 | // // Returns the hash value for key. |
| 2670 | // static uint32_t Hash(Key key); |
| 2671 | // // Returns the hash value for object. |
| 2672 | // static uint32_t HashForObject(Key key, Object* object); |
| 2673 | // // Convert key to an object. |
| 2674 | // static inline Object* AsObject(Key key); |
| 2675 | // // The prefix size indicates number of elements in the beginning |
| 2676 | // // of the backing storage. |
| 2677 | // static const int kPrefixSize = ..; |
| 2678 | // // The Element size indicates number of elements per entry. |
| 2679 | // static const int kEntrySize = ..; |
| 2680 | // }; |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2681 | // The prefix size indicates an amount of memory in the |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2682 | // beginning of the backing storage that can be used for non-element |
| 2683 | // information by subclasses. |
| 2684 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 2685 | template<typename Key> |
| 2686 | class BaseShape { |
| 2687 | public: |
| 2688 | static const bool UsesSeed = false; |
| 2689 | static uint32_t Hash(Key key) { return 0; } |
| 2690 | static uint32_t SeededHash(Key key, uint32_t seed) { |
| 2691 | ASSERT(UsesSeed); |
| 2692 | return Hash(key); |
| 2693 | } |
| 2694 | static uint32_t HashForObject(Key key, Object* object) { return 0; } |
| 2695 | static uint32_t SeededHashForObject(Key key, uint32_t seed, Object* object) { |
| 2696 | ASSERT(UsesSeed); |
| 2697 | return HashForObject(key, object); |
| 2698 | } |
| 2699 | }; |
| 2700 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2701 | template<typename Shape, typename Key> |
| 2702 | class HashTable: public FixedArray { |
| 2703 | public: |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 2704 | // Wrapper methods |
| 2705 | inline uint32_t Hash(Key key) { |
| 2706 | if (Shape::UsesSeed) { |
| 2707 | return Shape::SeededHash(key, |
| 2708 | GetHeap()->HashSeed()); |
| 2709 | } else { |
| 2710 | return Shape::Hash(key); |
| 2711 | } |
| 2712 | } |
| 2713 | |
| 2714 | inline uint32_t HashForObject(Key key, Object* object) { |
| 2715 | if (Shape::UsesSeed) { |
| 2716 | return Shape::SeededHashForObject(key, |
| 2717 | GetHeap()->HashSeed(), object); |
| 2718 | } else { |
| 2719 | return Shape::HashForObject(key, object); |
| 2720 | } |
| 2721 | } |
| 2722 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2723 | // Returns the number of elements in the hash table. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2724 | int NumberOfElements() { |
| 2725 | return Smi::cast(get(kNumberOfElementsIndex))->value(); |
| 2726 | } |
| 2727 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2728 | // Returns the number of deleted elements in the hash table. |
| 2729 | int NumberOfDeletedElements() { |
| 2730 | return Smi::cast(get(kNumberOfDeletedElementsIndex))->value(); |
| 2731 | } |
| 2732 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2733 | // Returns the capacity of the hash table. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2734 | int Capacity() { |
| 2735 | return Smi::cast(get(kCapacityIndex))->value(); |
| 2736 | } |
| 2737 | |
| 2738 | // ElementAdded should be called whenever an element is added to a |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2739 | // hash table. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2740 | void ElementAdded() { SetNumberOfElements(NumberOfElements() + 1); } |
| 2741 | |
| 2742 | // ElementRemoved should be called whenever an element is removed from |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2743 | // a hash table. |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2744 | void ElementRemoved() { |
| 2745 | SetNumberOfElements(NumberOfElements() - 1); |
| 2746 | SetNumberOfDeletedElements(NumberOfDeletedElements() + 1); |
| 2747 | } |
| 2748 | void ElementsRemoved(int n) { |
| 2749 | SetNumberOfElements(NumberOfElements() - n); |
| 2750 | SetNumberOfDeletedElements(NumberOfDeletedElements() + n); |
| 2751 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2752 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2753 | // Returns a new HashTable object. Might return Failure. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2754 | MUST_USE_RESULT static MaybeObject* Allocate( |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2755 | int at_least_space_for, |
| 2756 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2757 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2758 | // Computes the required capacity for a table holding the given |
| 2759 | // number of elements. May be more than HashTable::kMaxCapacity. |
| 2760 | static int ComputeCapacity(int at_least_space_for); |
| 2761 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2762 | // Returns the key at entry. |
| 2763 | Object* KeyAt(int entry) { return get(EntryToIndex(entry)); } |
| 2764 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2765 | // Tells whether k is a real key. The hole and undefined are not allowed |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2766 | // as keys and can be used to indicate missing or deleted elements. |
| 2767 | bool IsKey(Object* k) { |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2768 | return !k->IsTheHole() && !k->IsUndefined(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2769 | } |
| 2770 | |
| 2771 | // Garbage collection support. |
| 2772 | void IteratePrefix(ObjectVisitor* visitor); |
| 2773 | void IterateElements(ObjectVisitor* visitor); |
| 2774 | |
| 2775 | // Casting. |
| 2776 | static inline HashTable* cast(Object* obj); |
| 2777 | |
| 2778 | // Compute the probe offset (quadratic probing). |
| 2779 | INLINE(static uint32_t GetProbeOffset(uint32_t n)) { |
| 2780 | return (n + n * n) >> 1; |
| 2781 | } |
| 2782 | |
| 2783 | static const int kNumberOfElementsIndex = 0; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2784 | static const int kNumberOfDeletedElementsIndex = 1; |
| 2785 | static const int kCapacityIndex = 2; |
| 2786 | static const int kPrefixStartIndex = 3; |
| 2787 | static const int kElementsStartIndex = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2788 | kPrefixStartIndex + Shape::kPrefixSize; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2789 | static const int kEntrySize = Shape::kEntrySize; |
| 2790 | static const int kElementsStartOffset = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2791 | kHeaderSize + kElementsStartIndex * kPointerSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2792 | static const int kCapacityOffset = |
| 2793 | kHeaderSize + kCapacityIndex * kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2794 | |
| 2795 | // Constant used for denoting a absent entry. |
| 2796 | static const int kNotFound = -1; |
| 2797 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2798 | // Maximal capacity of HashTable. Based on maximal length of underlying |
| 2799 | // FixedArray. Staying below kMaxCapacity also ensures that EntryToIndex |
| 2800 | // cannot overflow. |
| 2801 | static const int kMaxCapacity = |
| 2802 | (FixedArray::kMaxLength - kElementsStartOffset) / kEntrySize; |
| 2803 | |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 2804 | // Find entry for key otherwise return kNotFound. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2805 | inline int FindEntry(Key key); |
| 2806 | int FindEntry(Isolate* isolate, Key key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2807 | |
| 2808 | protected: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2809 | // Find the entry at which to insert element with the given key that |
| 2810 | // has the given hash value. |
| 2811 | uint32_t FindInsertionEntry(uint32_t hash); |
| 2812 | |
| 2813 | // Returns the index for an entry (of the key) |
| 2814 | static inline int EntryToIndex(int entry) { |
| 2815 | return (entry * kEntrySize) + kElementsStartIndex; |
| 2816 | } |
| 2817 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2818 | // Update the number of elements in the hash table. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2819 | void SetNumberOfElements(int nof) { |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2820 | set(kNumberOfElementsIndex, Smi::FromInt(nof)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2821 | } |
| 2822 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2823 | // Update the number of deleted elements in the hash table. |
| 2824 | void SetNumberOfDeletedElements(int nod) { |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2825 | set(kNumberOfDeletedElementsIndex, Smi::FromInt(nod)); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2826 | } |
| 2827 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2828 | // Sets the capacity of the hash table. |
| 2829 | void SetCapacity(int capacity) { |
| 2830 | // To scale a computed hash code to fit within the hash table, we |
| 2831 | // use bit-wise AND with a mask, so the capacity must be positive |
| 2832 | // and non-zero. |
| 2833 | ASSERT(capacity > 0); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2834 | ASSERT(capacity <= kMaxCapacity); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 2835 | set(kCapacityIndex, Smi::FromInt(capacity)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2836 | } |
| 2837 | |
| 2838 | |
| 2839 | // Returns probe entry. |
| 2840 | static uint32_t GetProbe(uint32_t hash, uint32_t number, uint32_t size) { |
| 2841 | ASSERT(IsPowerOf2(size)); |
| 2842 | return (hash + GetProbeOffset(number)) & (size - 1); |
| 2843 | } |
| 2844 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2845 | static uint32_t FirstProbe(uint32_t hash, uint32_t size) { |
| 2846 | return hash & (size - 1); |
| 2847 | } |
| 2848 | |
| 2849 | static uint32_t NextProbe(uint32_t last, uint32_t number, uint32_t size) { |
| 2850 | return (last + number) & (size - 1); |
| 2851 | } |
| 2852 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2853 | // Rehashes this hash-table into the new table. |
| 2854 | MUST_USE_RESULT MaybeObject* Rehash(HashTable* new_table, Key key); |
| 2855 | |
| 2856 | // Attempt to shrink hash table after removal of key. |
| 2857 | MUST_USE_RESULT MaybeObject* Shrink(Key key); |
| 2858 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2859 | // Ensure enough space for n additional elements. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2860 | MUST_USE_RESULT MaybeObject* EnsureCapacity(int n, Key key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2861 | }; |
| 2862 | |
| 2863 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2864 | // HashTableKey is an abstract superclass for virtual key behavior. |
| 2865 | class HashTableKey { |
| 2866 | public: |
| 2867 | // Returns whether the other object matches this key. |
| 2868 | virtual bool IsMatch(Object* other) = 0; |
| 2869 | // Returns the hash value for this key. |
| 2870 | virtual uint32_t Hash() = 0; |
| 2871 | // Returns the hash value for object. |
| 2872 | virtual uint32_t HashForObject(Object* key) = 0; |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2873 | // Returns the key object for storing into the hash table. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2874 | // If allocations fails a failure object is returned. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2875 | MUST_USE_RESULT virtual MaybeObject* AsObject() = 0; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2876 | // Required. |
| 2877 | virtual ~HashTableKey() {} |
| 2878 | }; |
| 2879 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 2880 | |
| 2881 | class SymbolTableShape : public BaseShape<HashTableKey*> { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2882 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2883 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2884 | return key->IsMatch(value); |
| 2885 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2886 | static inline uint32_t Hash(HashTableKey* key) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2887 | return key->Hash(); |
| 2888 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2889 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2890 | return key->HashForObject(object); |
| 2891 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2892 | MUST_USE_RESULT static inline MaybeObject* AsObject(HashTableKey* key) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2893 | return key->AsObject(); |
| 2894 | } |
| 2895 | |
| 2896 | static const int kPrefixSize = 0; |
| 2897 | static const int kEntrySize = 1; |
| 2898 | }; |
| 2899 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2900 | class SeqAsciiString; |
| 2901 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2902 | // SymbolTable. |
| 2903 | // |
| 2904 | // No special elements in the prefix and the element size is 1 |
| 2905 | // because only the symbol itself (the key) needs to be stored. |
| 2906 | class SymbolTable: public HashTable<SymbolTableShape, HashTableKey*> { |
| 2907 | public: |
| 2908 | // Find symbol in the symbol table. If it is not there yet, it is |
| 2909 | // added. The return value is the symbol table which might have |
| 2910 | // been enlarged. If the return value is not a failure, the symbol |
| 2911 | // pointer *s is set to the symbol found. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2912 | MUST_USE_RESULT MaybeObject* LookupSymbol(Vector<const char> str, Object** s); |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 2913 | MUST_USE_RESULT MaybeObject* LookupAsciiSymbol(Vector<const char> str, |
| 2914 | Object** s); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2915 | MUST_USE_RESULT MaybeObject* LookupSubStringAsciiSymbol( |
| 2916 | Handle<SeqAsciiString> str, |
| 2917 | int from, |
| 2918 | int length, |
| 2919 | Object** s); |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 2920 | MUST_USE_RESULT MaybeObject* LookupTwoByteSymbol(Vector<const uc16> str, |
| 2921 | Object** s); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2922 | MUST_USE_RESULT MaybeObject* LookupString(String* key, Object** s); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2923 | |
| 2924 | // Looks up a symbol that is equal to the given string and returns |
| 2925 | // true if it is found, assigning the symbol to the given output |
| 2926 | // parameter. |
| 2927 | bool LookupSymbolIfExists(String* str, String** symbol); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2928 | bool LookupTwoCharsSymbolIfExists(uint32_t c1, uint32_t c2, String** symbol); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2929 | |
| 2930 | // Casting. |
| 2931 | static inline SymbolTable* cast(Object* obj); |
| 2932 | |
| 2933 | private: |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2934 | MUST_USE_RESULT MaybeObject* LookupKey(HashTableKey* key, Object** s); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2935 | |
| 2936 | DISALLOW_IMPLICIT_CONSTRUCTORS(SymbolTable); |
| 2937 | }; |
| 2938 | |
| 2939 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 2940 | class MapCacheShape : public BaseShape<HashTableKey*> { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2941 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2942 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2943 | return key->IsMatch(value); |
| 2944 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2945 | static inline uint32_t Hash(HashTableKey* key) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2946 | return key->Hash(); |
| 2947 | } |
| 2948 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2949 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2950 | return key->HashForObject(object); |
| 2951 | } |
| 2952 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2953 | MUST_USE_RESULT static inline MaybeObject* AsObject(HashTableKey* key) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2954 | return key->AsObject(); |
| 2955 | } |
| 2956 | |
| 2957 | static const int kPrefixSize = 0; |
| 2958 | static const int kEntrySize = 2; |
| 2959 | }; |
| 2960 | |
| 2961 | |
| 2962 | // MapCache. |
| 2963 | // |
| 2964 | // Maps keys that are a fixed array of symbols to a map. |
| 2965 | // Used for canonicalize maps for object literals. |
| 2966 | class MapCache: public HashTable<MapCacheShape, HashTableKey*> { |
| 2967 | public: |
| 2968 | // Find cached value for a string key, otherwise return null. |
| 2969 | Object* Lookup(FixedArray* key); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2970 | MUST_USE_RESULT MaybeObject* Put(FixedArray* key, Map* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2971 | static inline MapCache* cast(Object* obj); |
| 2972 | |
| 2973 | private: |
| 2974 | DISALLOW_IMPLICIT_CONSTRUCTORS(MapCache); |
| 2975 | }; |
| 2976 | |
| 2977 | |
| 2978 | template <typename Shape, typename Key> |
| 2979 | class Dictionary: public HashTable<Shape, Key> { |
| 2980 | public: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2981 | static inline Dictionary<Shape, Key>* cast(Object* obj) { |
| 2982 | return reinterpret_cast<Dictionary<Shape, Key>*>(obj); |
| 2983 | } |
| 2984 | |
| 2985 | // Returns the value at entry. |
| 2986 | Object* ValueAt(int entry) { |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 2987 | return this->get(HashTable<Shape, Key>::EntryToIndex(entry) + 1); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2988 | } |
| 2989 | |
| 2990 | // Set the value for entry. |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 2991 | void ValueAtPut(int entry, Object* value) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2992 | this->set(HashTable<Shape, Key>::EntryToIndex(entry) + 1, value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2993 | } |
| 2994 | |
| 2995 | // Returns the property details for the property at entry. |
| 2996 | PropertyDetails DetailsAt(int entry) { |
| 2997 | ASSERT(entry >= 0); // Not found is -1, which is not caught by get(). |
| 2998 | return PropertyDetails( |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2999 | Smi::cast(this->get(HashTable<Shape, Key>::EntryToIndex(entry) + 2))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3000 | } |
| 3001 | |
| 3002 | // Set the details for entry. |
| 3003 | void DetailsAtPut(int entry, PropertyDetails value) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3004 | this->set(HashTable<Shape, Key>::EntryToIndex(entry) + 2, value.AsSmi()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3005 | } |
| 3006 | |
| 3007 | // Sorting support |
| 3008 | void CopyValuesTo(FixedArray* elements); |
| 3009 | |
| 3010 | // Delete a property from the dictionary. |
| 3011 | Object* DeleteProperty(int entry, JSObject::DeleteMode mode); |
| 3012 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3013 | // Attempt to shrink the dictionary after deletion of key. |
| 3014 | MUST_USE_RESULT MaybeObject* Shrink(Key key); |
| 3015 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3016 | // Returns the number of elements in the dictionary filtering out properties |
| 3017 | // with the specified attributes. |
| 3018 | int NumberOfElementsFilterAttributes(PropertyAttributes filter); |
| 3019 | |
| 3020 | // Returns the number of enumerable elements in the dictionary. |
| 3021 | int NumberOfEnumElements(); |
| 3022 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3023 | enum SortMode { UNSORTED, SORTED }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3024 | // Copies keys to preallocated fixed array. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3025 | void CopyKeysTo(FixedArray* storage, |
| 3026 | PropertyAttributes filter, |
| 3027 | SortMode sort_mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3028 | // Fill in details for properties into storage. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3029 | void CopyKeysTo(FixedArray* storage, int index, SortMode sort_mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3030 | |
| 3031 | // Accessors for next enumeration index. |
| 3032 | void SetNextEnumerationIndex(int index) { |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 3033 | this->set(kNextEnumerationIndexIndex, Smi::FromInt(index)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3034 | } |
| 3035 | |
| 3036 | int NextEnumerationIndex() { |
| 3037 | return Smi::cast(FixedArray::get(kNextEnumerationIndexIndex))->value(); |
| 3038 | } |
| 3039 | |
| 3040 | // Returns a new array for dictionary usage. Might return Failure. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 3041 | MUST_USE_RESULT static MaybeObject* Allocate(int at_least_space_for); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3042 | |
| 3043 | // Ensure enough space for n additional elements. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 3044 | MUST_USE_RESULT MaybeObject* EnsureCapacity(int n, Key key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3045 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3046 | #ifdef OBJECT_PRINT |
| 3047 | inline void Print() { |
| 3048 | Print(stdout); |
| 3049 | } |
| 3050 | void Print(FILE* out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3051 | #endif |
| 3052 | // Returns the key (slow). |
| 3053 | Object* SlowReverseLookup(Object* value); |
| 3054 | |
| 3055 | // Sets the entry to (key, value) pair. |
| 3056 | inline void SetEntry(int entry, |
| 3057 | Object* key, |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3058 | Object* value); |
| 3059 | inline void SetEntry(int entry, |
| 3060 | Object* key, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3061 | Object* value, |
| 3062 | PropertyDetails details); |
| 3063 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 3064 | MUST_USE_RESULT MaybeObject* Add(Key key, |
| 3065 | Object* value, |
| 3066 | PropertyDetails details); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3067 | |
| 3068 | protected: |
| 3069 | // Generic at put operation. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 3070 | MUST_USE_RESULT MaybeObject* AtPut(Key key, Object* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3071 | |
| 3072 | // Add entry to dictionary. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 3073 | MUST_USE_RESULT MaybeObject* AddEntry(Key key, |
| 3074 | Object* value, |
| 3075 | PropertyDetails details, |
| 3076 | uint32_t hash); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3077 | |
| 3078 | // Generate new enumeration indices to avoid enumeration index overflow. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 3079 | MUST_USE_RESULT MaybeObject* GenerateNewEnumerationIndices(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3080 | static const int kMaxNumberKeyIndex = |
| 3081 | HashTable<Shape, Key>::kPrefixStartIndex; |
| 3082 | static const int kNextEnumerationIndexIndex = kMaxNumberKeyIndex + 1; |
| 3083 | }; |
| 3084 | |
| 3085 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3086 | class StringDictionaryShape : public BaseShape<String*> { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3087 | public: |
| 3088 | static inline bool IsMatch(String* key, Object* other); |
| 3089 | static inline uint32_t Hash(String* key); |
| 3090 | static inline uint32_t HashForObject(String* key, Object* object); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 3091 | MUST_USE_RESULT static inline MaybeObject* AsObject(String* key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3092 | static const int kPrefixSize = 2; |
| 3093 | static const int kEntrySize = 3; |
| 3094 | static const bool kIsEnumerable = true; |
| 3095 | }; |
| 3096 | |
| 3097 | |
| 3098 | class StringDictionary: public Dictionary<StringDictionaryShape, String*> { |
| 3099 | public: |
| 3100 | static inline StringDictionary* cast(Object* obj) { |
| 3101 | ASSERT(obj->IsDictionary()); |
| 3102 | return reinterpret_cast<StringDictionary*>(obj); |
| 3103 | } |
| 3104 | |
| 3105 | // Copies enumerable keys to preallocated fixed array. |
| 3106 | void CopyEnumKeysTo(FixedArray* storage, FixedArray* sort_array); |
| 3107 | |
| 3108 | // For transforming properties of a JSObject. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 3109 | MUST_USE_RESULT MaybeObject* TransformPropertiesToFastFor( |
| 3110 | JSObject* obj, |
| 3111 | int unused_property_fields); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 3112 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 3113 | // Find entry for key, otherwise return kNotFound. Optimized version of |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 3114 | // HashTable::FindEntry. |
| 3115 | int FindEntry(String* key); |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 3116 | |
| 3117 | bool ContainsTransition(int entry); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3118 | }; |
| 3119 | |
| 3120 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3121 | class NumberDictionaryShape : public BaseShape<uint32_t> { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3122 | public: |
| 3123 | static inline bool IsMatch(uint32_t key, Object* other); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 3124 | MUST_USE_RESULT static inline MaybeObject* AsObject(uint32_t key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3125 | static const int kEntrySize = 3; |
| 3126 | static const bool kIsEnumerable = false; |
| 3127 | }; |
| 3128 | |
| 3129 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3130 | class SeededNumberDictionaryShape : public NumberDictionaryShape { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3131 | public: |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3132 | static const bool UsesSeed = true; |
| 3133 | static const int kPrefixSize = 2; |
| 3134 | |
| 3135 | static inline uint32_t SeededHash(uint32_t key, uint32_t seed); |
| 3136 | static inline uint32_t SeededHashForObject(uint32_t key, |
| 3137 | uint32_t seed, |
| 3138 | Object* object); |
| 3139 | }; |
| 3140 | |
| 3141 | |
| 3142 | class UnseededNumberDictionaryShape : public NumberDictionaryShape { |
| 3143 | public: |
| 3144 | static const int kPrefixSize = 0; |
| 3145 | |
| 3146 | static inline uint32_t Hash(uint32_t key); |
| 3147 | static inline uint32_t HashForObject(uint32_t key, Object* object); |
| 3148 | }; |
| 3149 | |
| 3150 | |
| 3151 | class SeededNumberDictionary |
| 3152 | : public Dictionary<SeededNumberDictionaryShape, uint32_t> { |
| 3153 | public: |
| 3154 | static SeededNumberDictionary* cast(Object* obj) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3155 | ASSERT(obj->IsDictionary()); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3156 | return reinterpret_cast<SeededNumberDictionary*>(obj); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3157 | } |
| 3158 | |
| 3159 | // Type specific at put (default NONE attributes is used when adding). |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 3160 | MUST_USE_RESULT MaybeObject* AtNumberPut(uint32_t key, Object* value); |
| 3161 | MUST_USE_RESULT MaybeObject* AddNumberEntry(uint32_t key, |
| 3162 | Object* value, |
| 3163 | PropertyDetails details); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3164 | |
| 3165 | // Set an existing entry or add a new one if needed. |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3166 | // Return the updated dictionary. |
| 3167 | MUST_USE_RESULT static Handle<SeededNumberDictionary> Set( |
| 3168 | Handle<SeededNumberDictionary> dictionary, |
| 3169 | uint32_t index, |
| 3170 | Handle<Object> value, |
| 3171 | PropertyDetails details); |
| 3172 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 3173 | MUST_USE_RESULT MaybeObject* Set(uint32_t key, |
| 3174 | Object* value, |
| 3175 | PropertyDetails details); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3176 | |
| 3177 | void UpdateMaxNumberKey(uint32_t key); |
| 3178 | |
| 3179 | // If slow elements are required we will never go back to fast-case |
| 3180 | // for the elements kept in this dictionary. We require slow |
| 3181 | // elements if an element has been added at an index larger than |
| 3182 | // kRequiresSlowElementsLimit or set_requires_slow_elements() has been called |
| 3183 | // when defining a getter or setter with a number key. |
| 3184 | inline bool requires_slow_elements(); |
| 3185 | inline void set_requires_slow_elements(); |
| 3186 | |
| 3187 | // Get the value of the max number key that has been added to this |
| 3188 | // dictionary. max_number_key can only be called if |
| 3189 | // requires_slow_elements returns false. |
| 3190 | inline uint32_t max_number_key(); |
| 3191 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3192 | // Bit masks. |
| 3193 | static const int kRequiresSlowElementsMask = 1; |
| 3194 | static const int kRequiresSlowElementsTagSize = 1; |
| 3195 | static const uint32_t kRequiresSlowElementsLimit = (1 << 29) - 1; |
| 3196 | }; |
| 3197 | |
| 3198 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3199 | class UnseededNumberDictionary |
| 3200 | : public Dictionary<UnseededNumberDictionaryShape, uint32_t> { |
| 3201 | public: |
| 3202 | static UnseededNumberDictionary* cast(Object* obj) { |
| 3203 | ASSERT(obj->IsDictionary()); |
| 3204 | return reinterpret_cast<UnseededNumberDictionary*>(obj); |
| 3205 | } |
| 3206 | |
| 3207 | // Type specific at put (default NONE attributes is used when adding). |
| 3208 | MUST_USE_RESULT MaybeObject* AtNumberPut(uint32_t key, Object* value); |
| 3209 | MUST_USE_RESULT MaybeObject* AddNumberEntry(uint32_t key, Object* value); |
| 3210 | |
| 3211 | // Set an existing entry or add a new one if needed. |
| 3212 | // Return the updated dictionary. |
| 3213 | MUST_USE_RESULT static Handle<UnseededNumberDictionary> Set( |
| 3214 | Handle<UnseededNumberDictionary> dictionary, |
| 3215 | uint32_t index, |
| 3216 | Handle<Object> value); |
| 3217 | |
| 3218 | MUST_USE_RESULT MaybeObject* Set(uint32_t key, Object* value); |
| 3219 | }; |
| 3220 | |
| 3221 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 3222 | template <int entrysize> |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 3223 | class ObjectHashTableShape : public BaseShape<Object*> { |
Ben Murdoch | 2b4ba11 | 2012-01-20 14:57:15 +0000 | [diff] [blame] | 3224 | public: |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 3225 | static inline bool IsMatch(Object* key, Object* other); |
| 3226 | static inline uint32_t Hash(Object* key); |
| 3227 | static inline uint32_t HashForObject(Object* key, Object* object); |
| 3228 | MUST_USE_RESULT static inline MaybeObject* AsObject(Object* key); |
| 3229 | static const int kPrefixSize = 0; |
| 3230 | static const int kEntrySize = entrysize; |
| 3231 | }; |
| 3232 | |
| 3233 | |
| 3234 | // ObjectHashSet holds keys that are arbitrary objects by using the identity |
| 3235 | // hash of the key for hashing purposes. |
| 3236 | class ObjectHashSet: public HashTable<ObjectHashTableShape<1>, Object*> { |
| 3237 | public: |
| 3238 | static inline ObjectHashSet* cast(Object* obj) { |
| 3239 | ASSERT(obj->IsHashTable()); |
| 3240 | return reinterpret_cast<ObjectHashSet*>(obj); |
Ben Murdoch | 2b4ba11 | 2012-01-20 14:57:15 +0000 | [diff] [blame] | 3241 | } |
| 3242 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 3243 | // Looks up whether the given key is part of this hash set. |
| 3244 | bool Contains(Object* key); |
Ben Murdoch | 2b4ba11 | 2012-01-20 14:57:15 +0000 | [diff] [blame] | 3245 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 3246 | // Adds the given key to this hash set. |
| 3247 | MUST_USE_RESULT MaybeObject* Add(Object* key); |
| 3248 | |
| 3249 | // Removes the given key from this hash set. |
| 3250 | MUST_USE_RESULT MaybeObject* Remove(Object* key); |
Ben Murdoch | 2b4ba11 | 2012-01-20 14:57:15 +0000 | [diff] [blame] | 3251 | }; |
| 3252 | |
| 3253 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 3254 | // ObjectHashTable maps keys that are arbitrary objects to object values by |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3255 | // using the identity hash of the key for hashing purposes. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 3256 | class ObjectHashTable: public HashTable<ObjectHashTableShape<2>, Object*> { |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3257 | public: |
| 3258 | static inline ObjectHashTable* cast(Object* obj) { |
| 3259 | ASSERT(obj->IsHashTable()); |
| 3260 | return reinterpret_cast<ObjectHashTable*>(obj); |
| 3261 | } |
| 3262 | |
| 3263 | // Looks up the value associated with the given key. The undefined value is |
| 3264 | // returned in case the key is not present. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 3265 | Object* Lookup(Object* key); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3266 | |
| 3267 | // Adds (or overwrites) the value associated with the given key. Mapping a |
| 3268 | // key to the undefined value causes removal of the whole entry. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 3269 | MUST_USE_RESULT MaybeObject* Put(Object* key, Object* value); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3270 | |
| 3271 | private: |
| 3272 | friend class MarkCompactCollector; |
| 3273 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 3274 | void AddEntry(int entry, Object* key, Object* value); |
| 3275 | void RemoveEntry(int entry); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3276 | |
| 3277 | // Returns the index to the value of an entry. |
| 3278 | static inline int EntryToValueIndex(int entry) { |
| 3279 | return EntryToIndex(entry) + 1; |
| 3280 | } |
| 3281 | }; |
| 3282 | |
| 3283 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3284 | // JSFunctionResultCache caches results of some JSFunction invocation. |
| 3285 | // It is a fixed array with fixed structure: |
| 3286 | // [0]: factory function |
| 3287 | // [1]: finger index |
| 3288 | // [2]: current cache size |
| 3289 | // [3]: dummy field. |
| 3290 | // The rest of array are key/value pairs. |
| 3291 | class JSFunctionResultCache: public FixedArray { |
| 3292 | public: |
| 3293 | static const int kFactoryIndex = 0; |
| 3294 | static const int kFingerIndex = kFactoryIndex + 1; |
| 3295 | static const int kCacheSizeIndex = kFingerIndex + 1; |
| 3296 | static const int kDummyIndex = kCacheSizeIndex + 1; |
| 3297 | static const int kEntriesIndex = kDummyIndex + 1; |
| 3298 | |
| 3299 | static const int kEntrySize = 2; // key + value |
| 3300 | |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 3301 | static const int kFactoryOffset = kHeaderSize; |
| 3302 | static const int kFingerOffset = kFactoryOffset + kPointerSize; |
| 3303 | static const int kCacheSizeOffset = kFingerOffset + kPointerSize; |
| 3304 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3305 | inline void MakeZeroSize(); |
| 3306 | inline void Clear(); |
| 3307 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 3308 | inline int size(); |
| 3309 | inline void set_size(int size); |
| 3310 | inline int finger_index(); |
| 3311 | inline void set_finger_index(int finger_index); |
| 3312 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3313 | // Casting |
| 3314 | static inline JSFunctionResultCache* cast(Object* obj); |
| 3315 | |
| 3316 | #ifdef DEBUG |
| 3317 | void JSFunctionResultCacheVerify(); |
| 3318 | #endif |
| 3319 | }; |
| 3320 | |
| 3321 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 3322 | // ScopeInfo represents information about different scopes of a source |
| 3323 | // program and the allocation of the scope's variables. Scope information |
| 3324 | // is stored in a compressed form in ScopeInfo objects and is used |
| 3325 | // at runtime (stack dumps, deoptimization, etc.). |
| 3326 | |
| 3327 | // This object provides quick access to scope info details for runtime |
| 3328 | // routines. |
| 3329 | class ScopeInfo : public FixedArray { |
| 3330 | public: |
| 3331 | static inline ScopeInfo* cast(Object* object); |
| 3332 | |
| 3333 | // Return the type of this scope. |
| 3334 | ScopeType Type(); |
| 3335 | |
| 3336 | // Does this scope call eval? |
| 3337 | bool CallsEval(); |
| 3338 | |
| 3339 | // Return the language mode of this scope. |
| 3340 | LanguageMode language_mode(); |
| 3341 | |
| 3342 | // Does this scope make a non-strict eval call? |
| 3343 | bool CallsNonStrictEval() { |
| 3344 | return CallsEval() && (language_mode() == CLASSIC_MODE); |
| 3345 | } |
| 3346 | |
| 3347 | // Return the total number of locals allocated on the stack and in the |
| 3348 | // context. This includes the parameters that are allocated in the context. |
| 3349 | int LocalCount(); |
| 3350 | |
| 3351 | // Return the number of stack slots for code. This number consists of two |
| 3352 | // parts: |
| 3353 | // 1. One stack slot per stack allocated local. |
| 3354 | // 2. One stack slot for the function name if it is stack allocated. |
| 3355 | int StackSlotCount(); |
| 3356 | |
| 3357 | // Return the number of context slots for code if a context is allocated. This |
| 3358 | // number consists of three parts: |
| 3359 | // 1. Size of fixed header for every context: Context::MIN_CONTEXT_SLOTS |
| 3360 | // 2. One context slot per context allocated local. |
| 3361 | // 3. One context slot for the function name if it is context allocated. |
| 3362 | // Parameters allocated in the context count as context allocated locals. If |
| 3363 | // no contexts are allocated for this scope ContextLength returns 0. |
| 3364 | int ContextLength(); |
| 3365 | |
| 3366 | // Is this scope the scope of a named function expression? |
| 3367 | bool HasFunctionName(); |
| 3368 | |
| 3369 | // Return if this has context allocated locals. |
| 3370 | bool HasHeapAllocatedLocals(); |
| 3371 | |
| 3372 | // Return if contexts are allocated for this scope. |
| 3373 | bool HasContext(); |
| 3374 | |
| 3375 | // Return the function_name if present. |
| 3376 | String* FunctionName(); |
| 3377 | |
| 3378 | // Return the name of the given parameter. |
| 3379 | String* ParameterName(int var); |
| 3380 | |
| 3381 | // Return the name of the given local. |
| 3382 | String* LocalName(int var); |
| 3383 | |
| 3384 | // Return the name of the given stack local. |
| 3385 | String* StackLocalName(int var); |
| 3386 | |
| 3387 | // Return the name of the given context local. |
| 3388 | String* ContextLocalName(int var); |
| 3389 | |
| 3390 | // Return the mode of the given context local. |
| 3391 | VariableMode ContextLocalMode(int var); |
| 3392 | |
| 3393 | // Return the initialization flag of the given context local. |
| 3394 | InitializationFlag ContextLocalInitFlag(int var); |
| 3395 | |
| 3396 | // Lookup support for serialized scope info. Returns the |
| 3397 | // the stack slot index for a given slot name if the slot is |
| 3398 | // present; otherwise returns a value < 0. The name must be a symbol |
| 3399 | // (canonicalized). |
| 3400 | int StackSlotIndex(String* name); |
| 3401 | |
| 3402 | // Lookup support for serialized scope info. Returns the |
| 3403 | // context slot index for a given slot name if the slot is present; otherwise |
| 3404 | // returns a value < 0. The name must be a symbol (canonicalized). |
| 3405 | // If the slot is present and mode != NULL, sets *mode to the corresponding |
| 3406 | // mode for that variable. |
| 3407 | int ContextSlotIndex(String* name, |
| 3408 | VariableMode* mode, |
| 3409 | InitializationFlag* init_flag); |
| 3410 | |
| 3411 | // Lookup support for serialized scope info. Returns the |
| 3412 | // parameter index for a given parameter name if the parameter is present; |
| 3413 | // otherwise returns a value < 0. The name must be a symbol (canonicalized). |
| 3414 | int ParameterIndex(String* name); |
| 3415 | |
| 3416 | // Lookup support for serialized scope info. Returns the |
| 3417 | // function context slot index if the function name is present (named |
| 3418 | // function expressions, only), otherwise returns a value < 0. The name |
| 3419 | // must be a symbol (canonicalized). |
| 3420 | int FunctionContextSlotIndex(String* name, VariableMode* mode); |
| 3421 | |
| 3422 | static Handle<ScopeInfo> Create(Scope* scope); |
| 3423 | |
| 3424 | // Serializes empty scope info. |
| 3425 | static ScopeInfo* Empty(); |
| 3426 | |
| 3427 | #ifdef DEBUG |
| 3428 | void Print(); |
| 3429 | #endif |
| 3430 | |
| 3431 | // The layout of the static part of a ScopeInfo is as follows. Each entry is |
| 3432 | // numeric and occupies one array slot. |
| 3433 | // 1. A set of properties of the scope |
| 3434 | // 2. The number of parameters. This only applies to function scopes. For |
| 3435 | // non-function scopes this is 0. |
| 3436 | // 3. The number of non-parameter variables allocated on the stack. |
| 3437 | // 4. The number of non-parameter and parameter variables allocated in the |
| 3438 | // context. |
| 3439 | #define FOR_EACH_NUMERIC_FIELD(V) \ |
| 3440 | V(Flags) \ |
| 3441 | V(ParameterCount) \ |
| 3442 | V(StackLocalCount) \ |
| 3443 | V(ContextLocalCount) |
| 3444 | |
| 3445 | #define FIELD_ACCESSORS(name) \ |
| 3446 | void Set##name(int value) { \ |
| 3447 | set(k##name, Smi::FromInt(value)); \ |
| 3448 | } \ |
| 3449 | int name() { \ |
| 3450 | if (length() > 0) { \ |
| 3451 | return Smi::cast(get(k##name))->value(); \ |
| 3452 | } else { \ |
| 3453 | return 0; \ |
| 3454 | } \ |
| 3455 | } |
| 3456 | FOR_EACH_NUMERIC_FIELD(FIELD_ACCESSORS) |
| 3457 | #undef FIELD_ACCESSORS |
| 3458 | |
| 3459 | private: |
| 3460 | enum { |
| 3461 | #define DECL_INDEX(name) k##name, |
| 3462 | FOR_EACH_NUMERIC_FIELD(DECL_INDEX) |
| 3463 | #undef DECL_INDEX |
| 3464 | #undef FOR_EACH_NUMERIC_FIELD |
| 3465 | kVariablePartIndex |
| 3466 | }; |
| 3467 | |
| 3468 | // The layout of the variable part of a ScopeInfo is as follows: |
| 3469 | // 1. ParameterEntries: |
| 3470 | // This part stores the names of the parameters for function scopes. One |
| 3471 | // slot is used per parameter, so in total this part occupies |
| 3472 | // ParameterCount() slots in the array. For other scopes than function |
| 3473 | // scopes ParameterCount() is 0. |
| 3474 | // 2. StackLocalEntries: |
| 3475 | // Contains the names of local variables that are allocated on the stack, |
| 3476 | // in increasing order of the stack slot index. One slot is used per stack |
| 3477 | // local, so in total this part occupies StackLocalCount() slots in the |
| 3478 | // array. |
| 3479 | // 3. ContextLocalNameEntries: |
| 3480 | // Contains the names of local variables and parameters that are allocated |
| 3481 | // in the context. They are stored in increasing order of the context slot |
| 3482 | // index starting with Context::MIN_CONTEXT_SLOTS. One slot is used per |
| 3483 | // context local, so in total this part occupies ContextLocalCount() slots |
| 3484 | // in the array. |
| 3485 | // 4. ContextLocalInfoEntries: |
| 3486 | // Contains the variable modes and initialization flags corresponding to |
| 3487 | // the context locals in ContextLocalNameEntries. One slot is used per |
| 3488 | // context local, so in total this part occupies ContextLocalCount() |
| 3489 | // slots in the array. |
| 3490 | // 5. FunctionNameEntryIndex: |
| 3491 | // If the scope belongs to a named function expression this part contains |
| 3492 | // information about the function variable. It always occupies two array |
| 3493 | // slots: a. The name of the function variable. |
| 3494 | // b. The context or stack slot index for the variable. |
| 3495 | int ParameterEntriesIndex(); |
| 3496 | int StackLocalEntriesIndex(); |
| 3497 | int ContextLocalNameEntriesIndex(); |
| 3498 | int ContextLocalInfoEntriesIndex(); |
| 3499 | int FunctionNameEntryIndex(); |
| 3500 | |
| 3501 | // Location of the function variable for named function expressions. |
| 3502 | enum FunctionVariableInfo { |
| 3503 | NONE, // No function name present. |
| 3504 | STACK, // Function |
| 3505 | CONTEXT, |
| 3506 | UNUSED |
| 3507 | }; |
| 3508 | |
| 3509 | // Properties of scopes. |
| 3510 | class TypeField: public BitField<ScopeType, 0, 3> {}; |
| 3511 | class CallsEvalField: public BitField<bool, 3, 1> {}; |
| 3512 | class LanguageModeField: public BitField<LanguageMode, 4, 2> {}; |
| 3513 | class FunctionVariableField: public BitField<FunctionVariableInfo, 6, 2> {}; |
| 3514 | class FunctionVariableMode: public BitField<VariableMode, 8, 3> {}; |
| 3515 | |
| 3516 | // BitFields representing the encoded information for context locals in the |
| 3517 | // ContextLocalInfoEntries part. |
| 3518 | class ContextLocalMode: public BitField<VariableMode, 0, 3> {}; |
| 3519 | class ContextLocalInitFlag: public BitField<InitializationFlag, 3, 1> {}; |
| 3520 | }; |
| 3521 | |
| 3522 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3523 | // The cache for maps used by normalized (dictionary mode) objects. |
| 3524 | // Such maps do not have property descriptors, so a typical program |
| 3525 | // needs very limited number of distinct normalized maps. |
| 3526 | class NormalizedMapCache: public FixedArray { |
| 3527 | public: |
| 3528 | static const int kEntries = 64; |
| 3529 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 3530 | MUST_USE_RESULT MaybeObject* Get(JSObject* object, |
| 3531 | PropertyNormalizationMode mode); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3532 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3533 | void Clear(); |
| 3534 | |
| 3535 | // Casting |
| 3536 | static inline NormalizedMapCache* cast(Object* obj); |
| 3537 | |
| 3538 | #ifdef DEBUG |
| 3539 | void NormalizedMapCacheVerify(); |
| 3540 | #endif |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3541 | }; |
| 3542 | |
| 3543 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 3544 | // ByteArray represents fixed sized byte arrays. Used for the relocation info |
| 3545 | // that is attached to code objects. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3546 | class ByteArray: public FixedArrayBase { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3547 | public: |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 3548 | inline int Size() { return RoundUp(length() + kHeaderSize, kPointerSize); } |
| 3549 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3550 | // Setter and getter. |
| 3551 | inline byte get(int index); |
| 3552 | inline void set(int index, byte value); |
| 3553 | |
| 3554 | // Treat contents as an int array. |
| 3555 | inline int get_int(int index); |
| 3556 | |
| 3557 | static int SizeFor(int length) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3558 | return OBJECT_POINTER_ALIGN(kHeaderSize + length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3559 | } |
| 3560 | // We use byte arrays for free blocks in the heap. Given a desired size in |
| 3561 | // bytes that is a multiple of the word size and big enough to hold a byte |
| 3562 | // array, this function returns the number of elements a byte array should |
| 3563 | // have. |
| 3564 | static int LengthFor(int size_in_bytes) { |
| 3565 | ASSERT(IsAligned(size_in_bytes, kPointerSize)); |
| 3566 | ASSERT(size_in_bytes >= kHeaderSize); |
| 3567 | return size_in_bytes - kHeaderSize; |
| 3568 | } |
| 3569 | |
| 3570 | // Returns data start address. |
| 3571 | inline Address GetDataStartAddress(); |
| 3572 | |
| 3573 | // Returns a pointer to the ByteArray object for a given data start address. |
| 3574 | static inline ByteArray* FromDataStartAddress(Address address); |
| 3575 | |
| 3576 | // Casting. |
| 3577 | static inline ByteArray* cast(Object* obj); |
| 3578 | |
| 3579 | // Dispatched behavior. |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 3580 | inline int ByteArraySize() { |
| 3581 | return SizeFor(this->length()); |
| 3582 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3583 | #ifdef OBJECT_PRINT |
| 3584 | inline void ByteArrayPrint() { |
| 3585 | ByteArrayPrint(stdout); |
| 3586 | } |
| 3587 | void ByteArrayPrint(FILE* out); |
| 3588 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3589 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3590 | void ByteArrayVerify(); |
| 3591 | #endif |
| 3592 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3593 | // Layout description. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3594 | static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3595 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 3596 | // Maximal memory consumption for a single ByteArray. |
| 3597 | static const int kMaxSize = 512 * MB; |
| 3598 | // Maximal length of a single ByteArray. |
| 3599 | static const int kMaxLength = kMaxSize - kHeaderSize; |
| 3600 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3601 | private: |
| 3602 | DISALLOW_IMPLICIT_CONSTRUCTORS(ByteArray); |
| 3603 | }; |
| 3604 | |
| 3605 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 3606 | // FreeSpace represents fixed sized areas of the heap that are not currently in |
| 3607 | // use. Used by the heap and GC. |
| 3608 | class FreeSpace: public HeapObject { |
| 3609 | public: |
| 3610 | // [size]: size of the free space including the header. |
| 3611 | inline int size(); |
| 3612 | inline void set_size(int value); |
| 3613 | |
| 3614 | inline int Size() { return size(); } |
| 3615 | |
| 3616 | // Casting. |
| 3617 | static inline FreeSpace* cast(Object* obj); |
| 3618 | |
| 3619 | #ifdef OBJECT_PRINT |
| 3620 | inline void FreeSpacePrint() { |
| 3621 | FreeSpacePrint(stdout); |
| 3622 | } |
| 3623 | void FreeSpacePrint(FILE* out); |
| 3624 | #endif |
| 3625 | #ifdef DEBUG |
| 3626 | void FreeSpaceVerify(); |
| 3627 | #endif |
| 3628 | |
| 3629 | // Layout description. |
| 3630 | // Size is smi tagged when it is stored. |
| 3631 | static const int kSizeOffset = HeapObject::kHeaderSize; |
| 3632 | static const int kHeaderSize = kSizeOffset + kPointerSize; |
| 3633 | |
| 3634 | static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize); |
| 3635 | |
| 3636 | private: |
| 3637 | DISALLOW_IMPLICIT_CONSTRUCTORS(FreeSpace); |
| 3638 | }; |
| 3639 | |
| 3640 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3641 | // An ExternalArray represents a fixed-size array of primitive values |
| 3642 | // which live outside the JavaScript heap. Its subclasses are used to |
| 3643 | // implement the CanvasArray types being defined in the WebGL |
| 3644 | // specification. As of this writing the first public draft is not yet |
| 3645 | // available, but Khronos members can access the draft at: |
| 3646 | // https://cvs.khronos.org/svn/repos/3dweb/trunk/doc/spec/WebGL-spec.html |
| 3647 | // |
| 3648 | // The semantics of these arrays differ from CanvasPixelArray. |
| 3649 | // Out-of-range values passed to the setter are converted via a C |
| 3650 | // cast, not clamping. Out-of-range indices cause exceptions to be |
| 3651 | // raised rather than being silently ignored. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3652 | class ExternalArray: public FixedArrayBase { |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3653 | public: |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3654 | inline bool is_the_hole(int index) { return false; } |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3655 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3656 | // [external_pointer]: The pointer to the external memory area backing this |
| 3657 | // external array. |
| 3658 | DECL_ACCESSORS(external_pointer, void) // Pointer to the data store. |
| 3659 | |
| 3660 | // Casting. |
| 3661 | static inline ExternalArray* cast(Object* obj); |
| 3662 | |
| 3663 | // Maximal acceptable length for an external array. |
| 3664 | static const int kMaxLength = 0x3fffffff; |
| 3665 | |
| 3666 | // ExternalArray headers are not quadword aligned. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3667 | static const int kExternalPointerOffset = |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3668 | POINTER_SIZE_ALIGN(FixedArrayBase::kLengthOffset + kPointerSize); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3669 | static const int kHeaderSize = kExternalPointerOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3670 | static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3671 | |
| 3672 | private: |
| 3673 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalArray); |
| 3674 | }; |
| 3675 | |
| 3676 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3677 | // A ExternalPixelArray represents a fixed-size byte array with special |
| 3678 | // semantics used for implementing the CanvasPixelArray object. Please see the |
| 3679 | // specification at: |
| 3680 | |
| 3681 | // http://www.whatwg.org/specs/web-apps/current-work/ |
| 3682 | // multipage/the-canvas-element.html#canvaspixelarray |
| 3683 | // In particular, write access clamps the value written to 0 or 255 if the |
| 3684 | // value written is outside this range. |
| 3685 | class ExternalPixelArray: public ExternalArray { |
| 3686 | public: |
| 3687 | inline uint8_t* external_pixel_pointer(); |
| 3688 | |
| 3689 | // Setter and getter. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3690 | inline uint8_t get_scalar(int index); |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 3691 | MUST_USE_RESULT inline MaybeObject* get(int index); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3692 | inline void set(int index, uint8_t value); |
| 3693 | |
| 3694 | // This accessor applies the correct conversion from Smi, HeapNumber and |
| 3695 | // undefined and clamps the converted value between 0 and 255. |
| 3696 | Object* SetValue(uint32_t index, Object* value); |
| 3697 | |
| 3698 | // Casting. |
| 3699 | static inline ExternalPixelArray* cast(Object* obj); |
| 3700 | |
| 3701 | #ifdef OBJECT_PRINT |
| 3702 | inline void ExternalPixelArrayPrint() { |
| 3703 | ExternalPixelArrayPrint(stdout); |
| 3704 | } |
| 3705 | void ExternalPixelArrayPrint(FILE* out); |
| 3706 | #endif |
| 3707 | #ifdef DEBUG |
| 3708 | void ExternalPixelArrayVerify(); |
| 3709 | #endif // DEBUG |
| 3710 | |
| 3711 | private: |
| 3712 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalPixelArray); |
| 3713 | }; |
| 3714 | |
| 3715 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3716 | class ExternalByteArray: public ExternalArray { |
| 3717 | public: |
| 3718 | // Setter and getter. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3719 | inline int8_t get_scalar(int index); |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 3720 | MUST_USE_RESULT inline MaybeObject* get(int index); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3721 | inline void set(int index, int8_t value); |
| 3722 | |
| 3723 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3724 | // and undefined. |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 3725 | MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3726 | |
| 3727 | // Casting. |
| 3728 | static inline ExternalByteArray* cast(Object* obj); |
| 3729 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3730 | #ifdef OBJECT_PRINT |
| 3731 | inline void ExternalByteArrayPrint() { |
| 3732 | ExternalByteArrayPrint(stdout); |
| 3733 | } |
| 3734 | void ExternalByteArrayPrint(FILE* out); |
| 3735 | #endif |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3736 | #ifdef DEBUG |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3737 | void ExternalByteArrayVerify(); |
| 3738 | #endif // DEBUG |
| 3739 | |
| 3740 | private: |
| 3741 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalByteArray); |
| 3742 | }; |
| 3743 | |
| 3744 | |
| 3745 | class ExternalUnsignedByteArray: public ExternalArray { |
| 3746 | public: |
| 3747 | // Setter and getter. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3748 | inline uint8_t get_scalar(int index); |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 3749 | MUST_USE_RESULT inline MaybeObject* get(int index); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3750 | inline void set(int index, uint8_t value); |
| 3751 | |
| 3752 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3753 | // and undefined. |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 3754 | MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3755 | |
| 3756 | // Casting. |
| 3757 | static inline ExternalUnsignedByteArray* cast(Object* obj); |
| 3758 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3759 | #ifdef OBJECT_PRINT |
| 3760 | inline void ExternalUnsignedByteArrayPrint() { |
| 3761 | ExternalUnsignedByteArrayPrint(stdout); |
| 3762 | } |
| 3763 | void ExternalUnsignedByteArrayPrint(FILE* out); |
| 3764 | #endif |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3765 | #ifdef DEBUG |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3766 | void ExternalUnsignedByteArrayVerify(); |
| 3767 | #endif // DEBUG |
| 3768 | |
| 3769 | private: |
| 3770 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedByteArray); |
| 3771 | }; |
| 3772 | |
| 3773 | |
| 3774 | class ExternalShortArray: public ExternalArray { |
| 3775 | public: |
| 3776 | // Setter and getter. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3777 | inline int16_t get_scalar(int index); |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 3778 | MUST_USE_RESULT inline MaybeObject* get(int index); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3779 | inline void set(int index, int16_t value); |
| 3780 | |
| 3781 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3782 | // and undefined. |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 3783 | MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3784 | |
| 3785 | // Casting. |
| 3786 | static inline ExternalShortArray* cast(Object* obj); |
| 3787 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3788 | #ifdef OBJECT_PRINT |
| 3789 | inline void ExternalShortArrayPrint() { |
| 3790 | ExternalShortArrayPrint(stdout); |
| 3791 | } |
| 3792 | void ExternalShortArrayPrint(FILE* out); |
| 3793 | #endif |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3794 | #ifdef DEBUG |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3795 | void ExternalShortArrayVerify(); |
| 3796 | #endif // DEBUG |
| 3797 | |
| 3798 | private: |
| 3799 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalShortArray); |
| 3800 | }; |
| 3801 | |
| 3802 | |
| 3803 | class ExternalUnsignedShortArray: public ExternalArray { |
| 3804 | public: |
| 3805 | // Setter and getter. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3806 | inline uint16_t get_scalar(int index); |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 3807 | MUST_USE_RESULT inline MaybeObject* get(int index); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3808 | inline void set(int index, uint16_t value); |
| 3809 | |
| 3810 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3811 | // and undefined. |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 3812 | MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3813 | |
| 3814 | // Casting. |
| 3815 | static inline ExternalUnsignedShortArray* cast(Object* obj); |
| 3816 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3817 | #ifdef OBJECT_PRINT |
| 3818 | inline void ExternalUnsignedShortArrayPrint() { |
| 3819 | ExternalUnsignedShortArrayPrint(stdout); |
| 3820 | } |
| 3821 | void ExternalUnsignedShortArrayPrint(FILE* out); |
| 3822 | #endif |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3823 | #ifdef DEBUG |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3824 | void ExternalUnsignedShortArrayVerify(); |
| 3825 | #endif // DEBUG |
| 3826 | |
| 3827 | private: |
| 3828 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedShortArray); |
| 3829 | }; |
| 3830 | |
| 3831 | |
| 3832 | class ExternalIntArray: public ExternalArray { |
| 3833 | public: |
| 3834 | // Setter and getter. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3835 | inline int32_t get_scalar(int index); |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 3836 | MUST_USE_RESULT inline MaybeObject* get(int index); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3837 | inline void set(int index, int32_t value); |
| 3838 | |
| 3839 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3840 | // and undefined. |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 3841 | MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3842 | |
| 3843 | // Casting. |
| 3844 | static inline ExternalIntArray* cast(Object* obj); |
| 3845 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3846 | #ifdef OBJECT_PRINT |
| 3847 | inline void ExternalIntArrayPrint() { |
| 3848 | ExternalIntArrayPrint(stdout); |
| 3849 | } |
| 3850 | void ExternalIntArrayPrint(FILE* out); |
| 3851 | #endif |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3852 | #ifdef DEBUG |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3853 | void ExternalIntArrayVerify(); |
| 3854 | #endif // DEBUG |
| 3855 | |
| 3856 | private: |
| 3857 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalIntArray); |
| 3858 | }; |
| 3859 | |
| 3860 | |
| 3861 | class ExternalUnsignedIntArray: public ExternalArray { |
| 3862 | public: |
| 3863 | // Setter and getter. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3864 | inline uint32_t get_scalar(int index); |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 3865 | MUST_USE_RESULT inline MaybeObject* get(int index); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3866 | inline void set(int index, uint32_t value); |
| 3867 | |
| 3868 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3869 | // and undefined. |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 3870 | MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3871 | |
| 3872 | // Casting. |
| 3873 | static inline ExternalUnsignedIntArray* cast(Object* obj); |
| 3874 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3875 | #ifdef OBJECT_PRINT |
| 3876 | inline void ExternalUnsignedIntArrayPrint() { |
| 3877 | ExternalUnsignedIntArrayPrint(stdout); |
| 3878 | } |
| 3879 | void ExternalUnsignedIntArrayPrint(FILE* out); |
| 3880 | #endif |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3881 | #ifdef DEBUG |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3882 | void ExternalUnsignedIntArrayVerify(); |
| 3883 | #endif // DEBUG |
| 3884 | |
| 3885 | private: |
| 3886 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedIntArray); |
| 3887 | }; |
| 3888 | |
| 3889 | |
| 3890 | class ExternalFloatArray: public ExternalArray { |
| 3891 | public: |
| 3892 | // Setter and getter. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3893 | inline float get_scalar(int index); |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 3894 | MUST_USE_RESULT inline MaybeObject* get(int index); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3895 | inline void set(int index, float value); |
| 3896 | |
| 3897 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3898 | // and undefined. |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 3899 | MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3900 | |
| 3901 | // Casting. |
| 3902 | static inline ExternalFloatArray* cast(Object* obj); |
| 3903 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3904 | #ifdef OBJECT_PRINT |
| 3905 | inline void ExternalFloatArrayPrint() { |
| 3906 | ExternalFloatArrayPrint(stdout); |
| 3907 | } |
| 3908 | void ExternalFloatArrayPrint(FILE* out); |
| 3909 | #endif |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3910 | #ifdef DEBUG |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3911 | void ExternalFloatArrayVerify(); |
| 3912 | #endif // DEBUG |
| 3913 | |
| 3914 | private: |
| 3915 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalFloatArray); |
| 3916 | }; |
| 3917 | |
| 3918 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3919 | class ExternalDoubleArray: public ExternalArray { |
| 3920 | public: |
| 3921 | // Setter and getter. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3922 | inline double get_scalar(int index); |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 3923 | MUST_USE_RESULT inline MaybeObject* get(int index); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3924 | inline void set(int index, double value); |
| 3925 | |
| 3926 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3927 | // and undefined. |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 3928 | MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3929 | |
| 3930 | // Casting. |
| 3931 | static inline ExternalDoubleArray* cast(Object* obj); |
| 3932 | |
| 3933 | #ifdef OBJECT_PRINT |
| 3934 | inline void ExternalDoubleArrayPrint() { |
| 3935 | ExternalDoubleArrayPrint(stdout); |
| 3936 | } |
| 3937 | void ExternalDoubleArrayPrint(FILE* out); |
| 3938 | #endif // OBJECT_PRINT |
| 3939 | #ifdef DEBUG |
| 3940 | void ExternalDoubleArrayVerify(); |
| 3941 | #endif // DEBUG |
| 3942 | |
| 3943 | private: |
| 3944 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalDoubleArray); |
| 3945 | }; |
| 3946 | |
| 3947 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3948 | // DeoptimizationInputData is a fixed array used to hold the deoptimization |
| 3949 | // data for code generated by the Hydrogen/Lithium compiler. It also |
| 3950 | // contains information about functions that were inlined. If N different |
| 3951 | // functions were inlined then first N elements of the literal array will |
| 3952 | // contain these functions. |
| 3953 | // |
| 3954 | // It can be empty. |
| 3955 | class DeoptimizationInputData: public FixedArray { |
| 3956 | public: |
| 3957 | // Layout description. Indices in the array. |
| 3958 | static const int kTranslationByteArrayIndex = 0; |
| 3959 | static const int kInlinedFunctionCountIndex = 1; |
| 3960 | static const int kLiteralArrayIndex = 2; |
| 3961 | static const int kOsrAstIdIndex = 3; |
| 3962 | static const int kOsrPcOffsetIndex = 4; |
| 3963 | static const int kFirstDeoptEntryIndex = 5; |
| 3964 | |
| 3965 | // Offsets of deopt entry elements relative to the start of the entry. |
| 3966 | static const int kAstIdOffset = 0; |
| 3967 | static const int kTranslationIndexOffset = 1; |
| 3968 | static const int kArgumentsStackHeightOffset = 2; |
Ben Murdoch | 2b4ba11 | 2012-01-20 14:57:15 +0000 | [diff] [blame] | 3969 | static const int kPcOffset = 3; |
| 3970 | static const int kDeoptEntrySize = 4; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3971 | |
| 3972 | // Simple element accessors. |
| 3973 | #define DEFINE_ELEMENT_ACCESSORS(name, type) \ |
| 3974 | type* name() { \ |
| 3975 | return type::cast(get(k##name##Index)); \ |
| 3976 | } \ |
| 3977 | void Set##name(type* value) { \ |
| 3978 | set(k##name##Index, value); \ |
| 3979 | } |
| 3980 | |
| 3981 | DEFINE_ELEMENT_ACCESSORS(TranslationByteArray, ByteArray) |
| 3982 | DEFINE_ELEMENT_ACCESSORS(InlinedFunctionCount, Smi) |
| 3983 | DEFINE_ELEMENT_ACCESSORS(LiteralArray, FixedArray) |
| 3984 | DEFINE_ELEMENT_ACCESSORS(OsrAstId, Smi) |
| 3985 | DEFINE_ELEMENT_ACCESSORS(OsrPcOffset, Smi) |
| 3986 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3987 | #undef DEFINE_ELEMENT_ACCESSORS |
| 3988 | |
| 3989 | // Accessors for elements of the ith deoptimization entry. |
| 3990 | #define DEFINE_ENTRY_ACCESSORS(name, type) \ |
| 3991 | type* name(int i) { \ |
| 3992 | return type::cast(get(IndexForEntry(i) + k##name##Offset)); \ |
| 3993 | } \ |
| 3994 | void Set##name(int i, type* value) { \ |
| 3995 | set(IndexForEntry(i) + k##name##Offset, value); \ |
| 3996 | } |
| 3997 | |
| 3998 | DEFINE_ENTRY_ACCESSORS(AstId, Smi) |
| 3999 | DEFINE_ENTRY_ACCESSORS(TranslationIndex, Smi) |
| 4000 | DEFINE_ENTRY_ACCESSORS(ArgumentsStackHeight, Smi) |
Ben Murdoch | 2b4ba11 | 2012-01-20 14:57:15 +0000 | [diff] [blame] | 4001 | DEFINE_ENTRY_ACCESSORS(Pc, Smi) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4002 | |
| 4003 | #undef DEFINE_ENTRY_ACCESSORS |
| 4004 | |
| 4005 | int DeoptCount() { |
| 4006 | return (length() - kFirstDeoptEntryIndex) / kDeoptEntrySize; |
| 4007 | } |
| 4008 | |
| 4009 | // Allocates a DeoptimizationInputData. |
| 4010 | MUST_USE_RESULT static MaybeObject* Allocate(int deopt_entry_count, |
| 4011 | PretenureFlag pretenure); |
| 4012 | |
| 4013 | // Casting. |
| 4014 | static inline DeoptimizationInputData* cast(Object* obj); |
| 4015 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4016 | #ifdef ENABLE_DISASSEMBLER |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4017 | void DeoptimizationInputDataPrint(FILE* out); |
| 4018 | #endif |
| 4019 | |
| 4020 | private: |
| 4021 | static int IndexForEntry(int i) { |
| 4022 | return kFirstDeoptEntryIndex + (i * kDeoptEntrySize); |
| 4023 | } |
| 4024 | |
| 4025 | static int LengthFor(int entry_count) { |
| 4026 | return IndexForEntry(entry_count); |
| 4027 | } |
| 4028 | }; |
| 4029 | |
| 4030 | |
| 4031 | // DeoptimizationOutputData is a fixed array used to hold the deoptimization |
| 4032 | // data for code generated by the full compiler. |
| 4033 | // The format of the these objects is |
| 4034 | // [i * 2]: Ast ID for ith deoptimization. |
| 4035 | // [i * 2 + 1]: PC and state of ith deoptimization |
| 4036 | class DeoptimizationOutputData: public FixedArray { |
| 4037 | public: |
| 4038 | int DeoptPoints() { return length() / 2; } |
| 4039 | Smi* AstId(int index) { return Smi::cast(get(index * 2)); } |
| 4040 | void SetAstId(int index, Smi* id) { set(index * 2, id); } |
| 4041 | Smi* PcAndState(int index) { return Smi::cast(get(1 + index * 2)); } |
| 4042 | void SetPcAndState(int index, Smi* offset) { set(1 + index * 2, offset); } |
| 4043 | |
| 4044 | static int LengthOfFixedArray(int deopt_points) { |
| 4045 | return deopt_points * 2; |
| 4046 | } |
| 4047 | |
| 4048 | // Allocates a DeoptimizationOutputData. |
| 4049 | MUST_USE_RESULT static MaybeObject* Allocate(int number_of_deopt_points, |
| 4050 | PretenureFlag pretenure); |
| 4051 | |
| 4052 | // Casting. |
| 4053 | static inline DeoptimizationOutputData* cast(Object* obj); |
| 4054 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4055 | #if defined(OBJECT_PRINT) || defined(ENABLE_DISASSEMBLER) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4056 | void DeoptimizationOutputDataPrint(FILE* out); |
| 4057 | #endif |
| 4058 | }; |
| 4059 | |
| 4060 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 4061 | // Forward declaration. |
| 4062 | class JSGlobalPropertyCell; |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4063 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 4064 | // TypeFeedbackCells is a fixed array used to hold the association between |
| 4065 | // cache cells and AST ids for code generated by the full compiler. |
| 4066 | // The format of the these objects is |
| 4067 | // [i * 2]: Global property cell of ith cache cell. |
| 4068 | // [i * 2 + 1]: Ast ID for ith cache cell. |
| 4069 | class TypeFeedbackCells: public FixedArray { |
| 4070 | public: |
| 4071 | int CellCount() { return length() / 2; } |
| 4072 | static int LengthOfFixedArray(int cell_count) { return cell_count * 2; } |
| 4073 | |
| 4074 | // Accessors for AST ids associated with cache values. |
| 4075 | inline Smi* AstId(int index); |
| 4076 | inline void SetAstId(int index, Smi* id); |
| 4077 | |
| 4078 | // Accessors for global property cells holding the cache values. |
| 4079 | inline JSGlobalPropertyCell* Cell(int index); |
| 4080 | inline void SetCell(int index, JSGlobalPropertyCell* cell); |
| 4081 | |
| 4082 | // The object that indicates an uninitialized cache. |
| 4083 | static inline Handle<Object> UninitializedSentinel(Isolate* isolate); |
| 4084 | |
| 4085 | // The object that indicates a megamorphic state. |
| 4086 | static inline Handle<Object> MegamorphicSentinel(Isolate* isolate); |
| 4087 | |
| 4088 | // A raw version of the uninitialized sentinel that's safe to read during |
| 4089 | // garbage collection (e.g., for patching the cache). |
| 4090 | static inline Object* RawUninitializedSentinel(Heap* heap); |
| 4091 | |
| 4092 | // Casting. |
| 4093 | static inline TypeFeedbackCells* cast(Object* obj); |
| 4094 | |
| 4095 | static const int kForInFastCaseMarker = 0; |
| 4096 | static const int kForInSlowCaseMarker = 1; |
| 4097 | }; |
| 4098 | |
| 4099 | |
| 4100 | // Forward declaration. |
| 4101 | class SafepointEntry; |
| 4102 | class TypeFeedbackInfo; |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4103 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4104 | // Code describes objects with on-the-fly generated machine code. |
| 4105 | class Code: public HeapObject { |
| 4106 | public: |
| 4107 | // Opaque data type for encapsulating code flags like kind, inline |
| 4108 | // cache state, and arguments count. |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 4109 | // FLAGS_MIN_VALUE and FLAGS_MAX_VALUE are specified to ensure that |
| 4110 | // enumeration type has correct value range (see Issue 830 for more details). |
| 4111 | enum Flags { |
| 4112 | FLAGS_MIN_VALUE = kMinInt, |
| 4113 | FLAGS_MAX_VALUE = kMaxInt |
| 4114 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4115 | |
| 4116 | enum Kind { |
| 4117 | FUNCTION, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4118 | OPTIMIZED_FUNCTION, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4119 | STUB, |
| 4120 | BUILTIN, |
| 4121 | LOAD_IC, |
| 4122 | KEYED_LOAD_IC, |
| 4123 | CALL_IC, |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4124 | KEYED_CALL_IC, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4125 | STORE_IC, |
| 4126 | KEYED_STORE_IC, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4127 | UNARY_OP_IC, |
| 4128 | BINARY_OP_IC, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4129 | COMPARE_IC, |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 4130 | TO_BOOLEAN_IC, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4131 | // No more than 16 kinds. The value currently encoded in four bits in |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4132 | // Flags. |
| 4133 | |
| 4134 | // Pseudo-kinds. |
| 4135 | REGEXP = BUILTIN, |
| 4136 | FIRST_IC_KIND = LOAD_IC, |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 4137 | LAST_IC_KIND = TO_BOOLEAN_IC |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4138 | }; |
| 4139 | |
| 4140 | enum { |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 4141 | NUMBER_OF_KINDS = LAST_IC_KIND + 1 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4142 | }; |
| 4143 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4144 | typedef int ExtraICState; |
| 4145 | |
| 4146 | static const ExtraICState kNoExtraICState = 0; |
| 4147 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4148 | #ifdef ENABLE_DISASSEMBLER |
| 4149 | // Printing |
| 4150 | static const char* Kind2String(Kind kind); |
| 4151 | static const char* ICState2String(InlineCacheState state); |
| 4152 | static const char* PropertyType2String(PropertyType type); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 4153 | static void PrintExtraICState(FILE* out, Kind kind, ExtraICState extra); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4154 | inline void Disassemble(const char* name) { |
| 4155 | Disassemble(name, stdout); |
| 4156 | } |
| 4157 | void Disassemble(const char* name, FILE* out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4158 | #endif // ENABLE_DISASSEMBLER |
| 4159 | |
| 4160 | // [instruction_size]: Size of the native instructions |
| 4161 | inline int instruction_size(); |
| 4162 | inline void set_instruction_size(int value); |
| 4163 | |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 4164 | // [relocation_info]: Code relocation information |
| 4165 | DECL_ACCESSORS(relocation_info, ByteArray) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4166 | void InvalidateRelocation(); |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 4167 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 4168 | // [handler_table]: Fixed array containing offsets of exception handlers. |
| 4169 | DECL_ACCESSORS(handler_table, FixedArray) |
| 4170 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4171 | // [deoptimization_data]: Array containing data for deopt. |
| 4172 | DECL_ACCESSORS(deoptimization_data, FixedArray) |
| 4173 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 4174 | // [type_feedback_info]: Struct containing type feedback information. |
| 4175 | // Will contain either a TypeFeedbackInfo object, or undefined. |
| 4176 | DECL_ACCESSORS(type_feedback_info, Object) |
| 4177 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 4178 | // [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] | 4179 | // field does not have to be traced during garbage collection since |
| 4180 | // it is only used by the garbage collector itself. |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 4181 | DECL_ACCESSORS(gc_metadata, Object) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4182 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 4183 | // [ic_age]: Inline caching age: the value of the Heap::global_ic_age |
| 4184 | // at the moment when this object was created. |
| 4185 | inline void set_ic_age(int count); |
| 4186 | inline int ic_age(); |
| 4187 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4188 | // Unchecked accessors to be used during GC. |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 4189 | inline ByteArray* unchecked_relocation_info(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4190 | inline FixedArray* unchecked_deoptimization_data(); |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 4191 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4192 | inline int relocation_size(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4193 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4194 | // [flags]: Various code flags. |
| 4195 | inline Flags flags(); |
| 4196 | inline void set_flags(Flags flags); |
| 4197 | |
| 4198 | // [flags]: Access to specific code flags. |
| 4199 | inline Kind kind(); |
| 4200 | inline InlineCacheState ic_state(); // Only valid for IC stubs. |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4201 | inline ExtraICState extra_ic_state(); // Only valid for IC stubs. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4202 | inline PropertyType type(); // Only valid for monomorphic IC stubs. |
| 4203 | inline int arguments_count(); // Only valid for call IC stubs. |
| 4204 | |
| 4205 | // Testers for IC stub kinds. |
| 4206 | inline bool is_inline_cache_stub(); |
| 4207 | inline bool is_load_stub() { return kind() == LOAD_IC; } |
| 4208 | inline bool is_keyed_load_stub() { return kind() == KEYED_LOAD_IC; } |
| 4209 | inline bool is_store_stub() { return kind() == STORE_IC; } |
| 4210 | inline bool is_keyed_store_stub() { return kind() == KEYED_STORE_IC; } |
| 4211 | inline bool is_call_stub() { return kind() == CALL_IC; } |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4212 | inline bool is_keyed_call_stub() { return kind() == KEYED_CALL_IC; } |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 4213 | inline bool is_unary_op_stub() { return kind() == UNARY_OP_IC; } |
| 4214 | inline bool is_binary_op_stub() { return kind() == BINARY_OP_IC; } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4215 | inline bool is_compare_ic_stub() { return kind() == COMPARE_IC; } |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 4216 | inline bool is_to_boolean_ic_stub() { return kind() == TO_BOOLEAN_IC; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4217 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4218 | // [major_key]: For kind STUB or BINARY_OP_IC, the major key. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4219 | inline int major_key(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4220 | inline void set_major_key(int value); |
| 4221 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 4222 | // For stubs, tells whether they should always exist, so that they can be |
| 4223 | // called from other stubs. |
| 4224 | inline bool is_pregenerated(); |
| 4225 | inline void set_is_pregenerated(bool value); |
| 4226 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4227 | // [optimizable]: For FUNCTION kind, tells if it is optimizable. |
| 4228 | inline bool optimizable(); |
| 4229 | inline void set_optimizable(bool value); |
| 4230 | |
| 4231 | // [has_deoptimization_support]: For FUNCTION kind, tells if it has |
| 4232 | // deoptimization support. |
| 4233 | inline bool has_deoptimization_support(); |
| 4234 | inline void set_has_deoptimization_support(bool value); |
| 4235 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 4236 | // [has_debug_break_slots]: For FUNCTION kind, tells if it has |
| 4237 | // been compiled with debug break slots. |
| 4238 | inline bool has_debug_break_slots(); |
| 4239 | inline void set_has_debug_break_slots(bool value); |
| 4240 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 4241 | // [compiled_with_optimizing]: For FUNCTION kind, tells if it has |
| 4242 | // been compiled with IsOptimizing set to true. |
| 4243 | inline bool is_compiled_optimizable(); |
| 4244 | inline void set_compiled_optimizable(bool value); |
| 4245 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 4246 | // [has_self_optimization_header]: For FUNCTION kind, tells if it has |
| 4247 | // a self-optimization header. |
| 4248 | inline bool has_self_optimization_header(); |
| 4249 | inline void set_self_optimization_header(bool value); |
| 4250 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4251 | // [allow_osr_at_loop_nesting_level]: For FUNCTION kind, tells for |
| 4252 | // how long the function has been marked for OSR and therefore which |
| 4253 | // level of loop nesting we are willing to do on-stack replacement |
| 4254 | // for. |
| 4255 | inline void set_allow_osr_at_loop_nesting_level(int level); |
| 4256 | inline int allow_osr_at_loop_nesting_level(); |
| 4257 | |
| 4258 | // [stack_slots]: For kind OPTIMIZED_FUNCTION, the number of stack slots |
| 4259 | // reserved in the code prologue. |
| 4260 | inline unsigned stack_slots(); |
| 4261 | inline void set_stack_slots(unsigned slots); |
| 4262 | |
| 4263 | // [safepoint_table_start]: For kind OPTIMIZED_CODE, the offset in |
| 4264 | // the instruction stream where the safepoint table starts. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 4265 | inline unsigned safepoint_table_offset(); |
| 4266 | inline void set_safepoint_table_offset(unsigned offset); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4267 | |
| 4268 | // [stack_check_table_start]: For kind FUNCTION, the offset in the |
| 4269 | // instruction stream where the stack check table starts. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 4270 | inline unsigned stack_check_table_offset(); |
| 4271 | inline void set_stack_check_table_offset(unsigned offset); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4272 | |
| 4273 | // [check type]: For kind CALL_IC, tells how to check if the |
| 4274 | // receiver is valid for the given call. |
| 4275 | inline CheckType check_type(); |
| 4276 | inline void set_check_type(CheckType value); |
| 4277 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 4278 | // [type-recording unary op type]: For kind UNARY_OP_IC. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4279 | inline byte unary_op_type(); |
| 4280 | inline void set_unary_op_type(byte value); |
| 4281 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 4282 | // [type-recording binary op type]: For kind BINARY_OP_IC. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4283 | inline byte binary_op_type(); |
| 4284 | inline void set_binary_op_type(byte value); |
| 4285 | inline byte binary_op_result_type(); |
| 4286 | inline void set_binary_op_result_type(byte value); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4287 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 4288 | // [compare state]: For kind COMPARE_IC, tells what state the stub is in. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4289 | inline byte compare_state(); |
| 4290 | inline void set_compare_state(byte value); |
| 4291 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 4292 | // [to_boolean_foo]: For kind TO_BOOLEAN_IC tells what state the stub is in. |
| 4293 | inline byte to_boolean_state(); |
| 4294 | inline void set_to_boolean_state(byte value); |
| 4295 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 4296 | // [has_function_cache]: For kind STUB tells whether there is a function |
| 4297 | // cache is passed to the stub. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 4298 | inline bool has_function_cache(); |
| 4299 | inline void set_has_function_cache(bool flag); |
| 4300 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4301 | // Get the safepoint entry for the given pc. |
| 4302 | SafepointEntry GetSafepointEntry(Address pc); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4303 | |
| 4304 | // Mark this code object as not having a stack check table. Assumes kind |
| 4305 | // is FUNCTION. |
| 4306 | void SetNoStackCheckTable(); |
| 4307 | |
| 4308 | // Find the first map in an IC stub. |
| 4309 | Map* FindFirstMap(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4310 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 4311 | class ExtraICStateStrictMode: public BitField<StrictModeFlag, 0, 1> {}; |
| 4312 | class ExtraICStateKeyedAccessGrowMode: |
| 4313 | public BitField<KeyedAccessGrowMode, 1, 1> {}; // NOLINT |
| 4314 | |
| 4315 | static const int kExtraICStateGrowModeShift = 1; |
| 4316 | |
| 4317 | static inline StrictModeFlag GetStrictMode(ExtraICState extra_ic_state) { |
| 4318 | return ExtraICStateStrictMode::decode(extra_ic_state); |
| 4319 | } |
| 4320 | |
| 4321 | static inline KeyedAccessGrowMode GetKeyedAccessGrowMode( |
| 4322 | ExtraICState extra_ic_state) { |
| 4323 | return ExtraICStateKeyedAccessGrowMode::decode(extra_ic_state); |
| 4324 | } |
| 4325 | |
| 4326 | static inline ExtraICState ComputeExtraICState( |
| 4327 | KeyedAccessGrowMode grow_mode, |
| 4328 | StrictModeFlag strict_mode) { |
| 4329 | return ExtraICStateKeyedAccessGrowMode::encode(grow_mode) | |
| 4330 | ExtraICStateStrictMode::encode(strict_mode); |
| 4331 | } |
| 4332 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4333 | // Flags operations. |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4334 | static inline Flags ComputeFlags( |
| 4335 | Kind kind, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4336 | InlineCacheState ic_state = UNINITIALIZED, |
| 4337 | ExtraICState extra_ic_state = kNoExtraICState, |
| 4338 | PropertyType type = NORMAL, |
| 4339 | int argc = -1, |
| 4340 | InlineCacheHolderFlag holder = OWN_MAP); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4341 | |
| 4342 | static inline Flags ComputeMonomorphicFlags( |
| 4343 | Kind kind, |
| 4344 | PropertyType type, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4345 | ExtraICState extra_ic_state = kNoExtraICState, |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 4346 | InlineCacheHolderFlag holder = OWN_MAP, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4347 | int argc = -1); |
| 4348 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4349 | static inline InlineCacheState ExtractICStateFromFlags(Flags flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4350 | static inline PropertyType ExtractTypeFromFlags(Flags flags); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 4351 | static inline Kind ExtractKindFromFlags(Flags flags); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 4352 | static inline InlineCacheHolderFlag ExtractCacheHolderFromFlags(Flags flags); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 4353 | static inline ExtraICState ExtractExtraICStateFromFlags(Flags flags); |
| 4354 | static inline int ExtractArgumentsCountFromFlags(Flags flags); |
| 4355 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4356 | static inline Flags RemoveTypeFromFlags(Flags flags); |
| 4357 | |
| 4358 | // Convert a target address into a code object. |
| 4359 | static inline Code* GetCodeFromTargetAddress(Address address); |
| 4360 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 4361 | // Convert an entry address into an object. |
| 4362 | static inline Object* GetObjectFromEntryAddress(Address location_of_address); |
| 4363 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4364 | // Returns the address of the first instruction. |
| 4365 | inline byte* instruction_start(); |
| 4366 | |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 4367 | // Returns the address right after the last instruction. |
| 4368 | inline byte* instruction_end(); |
| 4369 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4370 | // Returns the size of the instructions, padding, and relocation information. |
| 4371 | inline int body_size(); |
| 4372 | |
| 4373 | // Returns the address of the first relocation info (read backwards!). |
| 4374 | inline byte* relocation_start(); |
| 4375 | |
| 4376 | // Code entry point. |
| 4377 | inline byte* entry(); |
| 4378 | |
| 4379 | // Returns true if pc is inside this object's instructions. |
| 4380 | inline bool contains(byte* pc); |
| 4381 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4382 | // Relocate the code by delta bytes. Called to signal that this code |
| 4383 | // object has been moved by delta bytes. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4384 | void Relocate(intptr_t delta); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4385 | |
| 4386 | // Migrate code described by desc. |
| 4387 | void CopyFrom(const CodeDesc& desc); |
| 4388 | |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 4389 | // Returns the object size for a given body (used for allocation). |
| 4390 | static int SizeFor(int body_size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4391 | ASSERT_SIZE_TAG_ALIGNED(body_size); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 4392 | return RoundUp(kHeaderSize + body_size, kCodeAlignment); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4393 | } |
| 4394 | |
| 4395 | // Calculate the size of the code object to report for log events. This takes |
| 4396 | // the layout of the code object into account. |
| 4397 | int ExecutableSize() { |
| 4398 | // Check that the assumptions about the layout of the code object holds. |
| 4399 | ASSERT_EQ(static_cast<int>(instruction_start() - address()), |
| 4400 | Code::kHeaderSize); |
| 4401 | return instruction_size() + Code::kHeaderSize; |
| 4402 | } |
| 4403 | |
| 4404 | // Locating source position. |
| 4405 | int SourcePosition(Address pc); |
| 4406 | int SourceStatementPosition(Address pc); |
| 4407 | |
| 4408 | // Casting. |
| 4409 | static inline Code* cast(Object* obj); |
| 4410 | |
| 4411 | // Dispatched behavior. |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 4412 | int CodeSize() { return SizeFor(body_size()); } |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 4413 | inline void CodeIterateBody(ObjectVisitor* v); |
| 4414 | |
| 4415 | template<typename StaticVisitor> |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4416 | inline void CodeIterateBody(Heap* heap); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4417 | #ifdef OBJECT_PRINT |
| 4418 | inline void CodePrint() { |
| 4419 | CodePrint(stdout); |
| 4420 | } |
| 4421 | void CodePrint(FILE* out); |
| 4422 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4423 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4424 | void CodeVerify(); |
| 4425 | #endif |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4426 | |
| 4427 | // Max loop nesting marker used to postpose OSR. We don't take loop |
| 4428 | // nesting that is deeper than 5 levels into account. |
| 4429 | static const int kMaxLoopNestingMarker = 6; |
| 4430 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4431 | // Layout description. |
| 4432 | static const int kInstructionSizeOffset = HeapObject::kHeaderSize; |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 4433 | static const int kRelocationInfoOffset = kInstructionSizeOffset + kIntSize; |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 4434 | static const int kHandlerTableOffset = kRelocationInfoOffset + kPointerSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4435 | static const int kDeoptimizationDataOffset = |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 4436 | kHandlerTableOffset + kPointerSize; |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 4437 | static const int kTypeFeedbackInfoOffset = |
| 4438 | kDeoptimizationDataOffset + kPointerSize; |
| 4439 | static const int kGCMetadataOffset = kTypeFeedbackInfoOffset + kPointerSize; |
| 4440 | static const int kICAgeOffset = |
| 4441 | kGCMetadataOffset + kPointerSize; |
| 4442 | static const int kFlagsOffset = kICAgeOffset + kIntSize; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4443 | static const int kKindSpecificFlagsOffset = kFlagsOffset + kIntSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4444 | static const int kKindSpecificFlagsSize = 2 * kIntSize; |
| 4445 | |
| 4446 | static const int kHeaderPaddingStart = kKindSpecificFlagsOffset + |
| 4447 | kKindSpecificFlagsSize; |
| 4448 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4449 | // Add padding to align the instruction start following right after |
| 4450 | // the Code object header. |
| 4451 | static const int kHeaderSize = |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4452 | (kHeaderPaddingStart + kCodeAlignmentMask) & ~kCodeAlignmentMask; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4453 | |
| 4454 | // Byte offsets within kKindSpecificFlagsOffset. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4455 | static const int kStubMajorKeyOffset = kKindSpecificFlagsOffset; |
| 4456 | static const int kOptimizableOffset = kKindSpecificFlagsOffset; |
| 4457 | static const int kStackSlotsOffset = kKindSpecificFlagsOffset; |
| 4458 | static const int kCheckTypeOffset = kKindSpecificFlagsOffset; |
| 4459 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4460 | static const int kUnaryOpTypeOffset = kStubMajorKeyOffset + 1; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4461 | static const int kBinaryOpTypeOffset = kStubMajorKeyOffset + 1; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 4462 | static const int kCompareStateOffset = kStubMajorKeyOffset + 1; |
| 4463 | static const int kToBooleanTypeOffset = kStubMajorKeyOffset + 1; |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 4464 | static const int kHasFunctionCacheOffset = kStubMajorKeyOffset + 1; |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 4465 | |
| 4466 | static const int kFullCodeFlags = kOptimizableOffset + 1; |
| 4467 | class FullCodeFlagsHasDeoptimizationSupportField: |
| 4468 | public BitField<bool, 0, 1> {}; // NOLINT |
| 4469 | class FullCodeFlagsHasDebugBreakSlotsField: public BitField<bool, 1, 1> {}; |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 4470 | class FullCodeFlagsIsCompiledOptimizable: public BitField<bool, 2, 1> {}; |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 4471 | class FullCodeFlagsHasSelfOptimizationHeader: public BitField<bool, 3, 1> {}; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4472 | |
| 4473 | static const int kBinaryOpReturnTypeOffset = kBinaryOpTypeOffset + 1; |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 4474 | |
| 4475 | static const int kAllowOSRAtLoopNestingLevelOffset = kFullCodeFlags + 1; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4476 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 4477 | static const int kSafepointTableOffsetOffset = kStackSlotsOffset + kIntSize; |
| 4478 | static const int kStackCheckTableOffsetOffset = kStackSlotsOffset + kIntSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4479 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 4480 | // Flags layout. BitField<type, shift, size>. |
| 4481 | class ICStateField: public BitField<InlineCacheState, 0, 3> {}; |
| 4482 | class TypeField: public BitField<PropertyType, 3, 4> {}; |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 4483 | class CacheHolderField: public BitField<InlineCacheHolderFlag, 7, 1> {}; |
| 4484 | class KindField: public BitField<Kind, 8, 4> {}; |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 4485 | class ExtraICStateField: public BitField<ExtraICState, 12, 2> {}; |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 4486 | class IsPregeneratedField: public BitField<bool, 14, 1> {}; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4487 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 4488 | // Signed field cannot be encoded using the BitField class. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 4489 | static const int kArgumentsCountShift = 15; |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 4490 | static const int kArgumentsCountMask = ~((1 << kArgumentsCountShift) - 1); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4491 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 4492 | // This constant should be encodable in an ARM instruction. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4493 | static const int kFlagsNotUsedInLookup = |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 4494 | TypeField::kMask | CacheHolderField::kMask; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4495 | |
| 4496 | private: |
| 4497 | DISALLOW_IMPLICIT_CONSTRUCTORS(Code); |
| 4498 | }; |
| 4499 | |
| 4500 | |
| 4501 | // All heap objects have a Map that describes their structure. |
| 4502 | // A Map contains information about: |
| 4503 | // - Size information about the object |
| 4504 | // - How to iterate over an object (for garbage collection) |
| 4505 | class Map: public HeapObject { |
| 4506 | public: |
| 4507 | // Instance size. |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 4508 | // Size in bytes or kVariableSizeSentinel if instances do not have |
| 4509 | // a fixed size. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4510 | inline int instance_size(); |
| 4511 | inline void set_instance_size(int value); |
| 4512 | |
| 4513 | // Count of properties allocated in the object. |
| 4514 | inline int inobject_properties(); |
| 4515 | inline void set_inobject_properties(int value); |
| 4516 | |
| 4517 | // Count of property fields pre-allocated in the object when first allocated. |
| 4518 | inline int pre_allocated_property_fields(); |
| 4519 | inline void set_pre_allocated_property_fields(int value); |
| 4520 | |
| 4521 | // Instance type. |
| 4522 | inline InstanceType instance_type(); |
| 4523 | inline void set_instance_type(InstanceType value); |
| 4524 | |
| 4525 | // Tells how many unused property fields are available in the |
| 4526 | // instance (only used for JSObject in fast mode). |
| 4527 | inline int unused_property_fields(); |
| 4528 | inline void set_unused_property_fields(int value); |
| 4529 | |
| 4530 | // Bit field. |
| 4531 | inline byte bit_field(); |
| 4532 | inline void set_bit_field(byte value); |
| 4533 | |
| 4534 | // Bit field 2. |
| 4535 | inline byte bit_field2(); |
| 4536 | inline void set_bit_field2(byte value); |
| 4537 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4538 | // Bit field 3. |
| 4539 | // TODO(1399): It should be possible to make room for bit_field3 in the map |
| 4540 | // without overloading the instance descriptors field (and storing it in the |
| 4541 | // DescriptorArray when the map has one). |
| 4542 | inline int bit_field3(); |
| 4543 | inline void set_bit_field3(int value); |
| 4544 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4545 | // Tells whether the object in the prototype property will be used |
| 4546 | // for instances created from this function. If the prototype |
| 4547 | // property is set to a value that is not a JSObject, the prototype |
| 4548 | // property will not be used to create instances of the function. |
| 4549 | // See ECMA-262, 13.2.2. |
| 4550 | inline void set_non_instance_prototype(bool value); |
| 4551 | inline bool has_non_instance_prototype(); |
| 4552 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4553 | // Tells whether function has special prototype property. If not, prototype |
| 4554 | // property will not be created when accessed (will return undefined), |
| 4555 | // and construction from this function will not be allowed. |
| 4556 | inline void set_function_with_prototype(bool value); |
| 4557 | inline bool function_with_prototype(); |
| 4558 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4559 | // Tells whether the instance with this map should be ignored by the |
| 4560 | // __proto__ accessor. |
| 4561 | inline void set_is_hidden_prototype() { |
| 4562 | set_bit_field(bit_field() | (1 << kIsHiddenPrototype)); |
| 4563 | } |
| 4564 | |
| 4565 | inline bool is_hidden_prototype() { |
| 4566 | return ((1 << kIsHiddenPrototype) & bit_field()) != 0; |
| 4567 | } |
| 4568 | |
| 4569 | // Records and queries whether the instance has a named interceptor. |
| 4570 | inline void set_has_named_interceptor() { |
| 4571 | set_bit_field(bit_field() | (1 << kHasNamedInterceptor)); |
| 4572 | } |
| 4573 | |
| 4574 | inline bool has_named_interceptor() { |
| 4575 | return ((1 << kHasNamedInterceptor) & bit_field()) != 0; |
| 4576 | } |
| 4577 | |
| 4578 | // Records and queries whether the instance has an indexed interceptor. |
| 4579 | inline void set_has_indexed_interceptor() { |
| 4580 | set_bit_field(bit_field() | (1 << kHasIndexedInterceptor)); |
| 4581 | } |
| 4582 | |
| 4583 | inline bool has_indexed_interceptor() { |
| 4584 | return ((1 << kHasIndexedInterceptor) & bit_field()) != 0; |
| 4585 | } |
| 4586 | |
| 4587 | // Tells whether the instance is undetectable. |
| 4588 | // An undetectable object is a special class of JSObject: 'typeof' operator |
| 4589 | // returns undefined, ToBoolean returns false. Otherwise it behaves like |
| 4590 | // a normal JS object. It is useful for implementing undetectable |
| 4591 | // document.all in Firefox & Safari. |
| 4592 | // See https://bugzilla.mozilla.org/show_bug.cgi?id=248549. |
| 4593 | inline void set_is_undetectable() { |
| 4594 | set_bit_field(bit_field() | (1 << kIsUndetectable)); |
| 4595 | } |
| 4596 | |
| 4597 | inline bool is_undetectable() { |
| 4598 | return ((1 << kIsUndetectable) & bit_field()) != 0; |
| 4599 | } |
| 4600 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4601 | // Tells whether the instance has a call-as-function handler. |
| 4602 | inline void set_has_instance_call_handler() { |
| 4603 | set_bit_field(bit_field() | (1 << kHasInstanceCallHandler)); |
| 4604 | } |
| 4605 | |
| 4606 | inline bool has_instance_call_handler() { |
| 4607 | return ((1 << kHasInstanceCallHandler) & bit_field()) != 0; |
| 4608 | } |
| 4609 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 4610 | inline void set_is_extensible(bool value); |
| 4611 | inline bool is_extensible(); |
| 4612 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 4613 | inline void set_elements_kind(ElementsKind elements_kind) { |
| 4614 | ASSERT(elements_kind < kElementsKindCount); |
| 4615 | ASSERT(kElementsKindCount <= (1 << kElementsKindBitCount)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4616 | set_bit_field2((bit_field2() & ~kElementsKindMask) | |
| 4617 | (elements_kind << kElementsKindShift)); |
| 4618 | ASSERT(this->elements_kind() == elements_kind); |
| 4619 | } |
| 4620 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 4621 | inline ElementsKind elements_kind() { |
| 4622 | return static_cast<ElementsKind>( |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4623 | (bit_field2() & kElementsKindMask) >> kElementsKindShift); |
| 4624 | } |
| 4625 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 4626 | // Tells whether the instance has fast elements that are only Smis. |
| 4627 | inline bool has_fast_smi_only_elements() { |
| 4628 | return elements_kind() == FAST_SMI_ONLY_ELEMENTS; |
| 4629 | } |
| 4630 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 4631 | // Tells whether the instance has fast elements. |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 4632 | inline bool has_fast_elements() { |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 4633 | return elements_kind() == FAST_ELEMENTS; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4634 | } |
| 4635 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4636 | inline bool has_fast_double_elements() { |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 4637 | return elements_kind() == FAST_DOUBLE_ELEMENTS; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 4638 | } |
| 4639 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 4640 | inline bool has_non_strict_arguments_elements() { |
| 4641 | return elements_kind() == NON_STRICT_ARGUMENTS_ELEMENTS; |
| 4642 | } |
| 4643 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4644 | inline bool has_external_array_elements() { |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 4645 | ElementsKind kind(elements_kind()); |
| 4646 | return kind >= FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND && |
| 4647 | kind <= LAST_EXTERNAL_ARRAY_ELEMENTS_KIND; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4648 | } |
| 4649 | |
| 4650 | inline bool has_dictionary_elements() { |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 4651 | return elements_kind() == DICTIONARY_ELEMENTS; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 4652 | } |
| 4653 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 4654 | inline bool has_slow_elements_kind() { |
| 4655 | return elements_kind() == DICTIONARY_ELEMENTS |
| 4656 | || elements_kind() == NON_STRICT_ARGUMENTS_ELEMENTS; |
| 4657 | } |
| 4658 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 4659 | static bool IsValidElementsTransition(ElementsKind from_kind, |
| 4660 | ElementsKind to_kind); |
| 4661 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4662 | // Tells whether the map is attached to SharedFunctionInfo |
| 4663 | // (for inobject slack tracking). |
| 4664 | inline void set_attached_to_shared_function_info(bool value); |
| 4665 | |
| 4666 | inline bool attached_to_shared_function_info(); |
| 4667 | |
| 4668 | // Tells whether the map is shared between objects that may have different |
| 4669 | // behavior. If true, the map should never be modified, instead a clone |
| 4670 | // should be created and modified. |
| 4671 | inline void set_is_shared(bool value); |
| 4672 | |
| 4673 | inline bool is_shared(); |
| 4674 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4675 | // Tells whether the instance needs security checks when accessing its |
| 4676 | // properties. |
| 4677 | inline void set_is_access_check_needed(bool access_check_needed); |
| 4678 | inline bool is_access_check_needed(); |
| 4679 | |
| 4680 | // [prototype]: implicit prototype object. |
| 4681 | DECL_ACCESSORS(prototype, Object) |
| 4682 | |
| 4683 | // [constructor]: points back to the function responsible for this map. |
| 4684 | DECL_ACCESSORS(constructor, Object) |
| 4685 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4686 | inline JSFunction* unchecked_constructor(); |
| 4687 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4688 | // Should only be called by the code that initializes map to set initial valid |
| 4689 | // value of the instance descriptor member. |
| 4690 | inline void init_instance_descriptors(); |
| 4691 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4692 | // [instance descriptors]: describes the object. |
| 4693 | DECL_ACCESSORS(instance_descriptors, DescriptorArray) |
| 4694 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4695 | // Sets the instance descriptor array for the map to be an empty descriptor |
| 4696 | // array. |
| 4697 | inline void clear_instance_descriptors(); |
| 4698 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4699 | // [stub cache]: contains stubs compiled for this map. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4700 | DECL_ACCESSORS(code_cache, Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4701 | |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 4702 | // [prototype transitions]: cache of prototype transitions. |
| 4703 | // Prototype transition is a transition that happens |
| 4704 | // when we change object's prototype to a new one. |
| 4705 | // Cache format: |
| 4706 | // 0: finger - index of the first free cell in the cache |
| 4707 | // 1 + 2 * i: prototype |
| 4708 | // 2 + 2 * i: target map |
| 4709 | DECL_ACCESSORS(prototype_transitions, FixedArray) |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 4710 | |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 4711 | inline FixedArray* unchecked_prototype_transitions(); |
| 4712 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4713 | static const int kProtoTransitionHeaderSize = 1; |
| 4714 | static const int kProtoTransitionNumberOfEntriesOffset = 0; |
| 4715 | static const int kProtoTransitionElementsPerEntry = 2; |
| 4716 | static const int kProtoTransitionPrototypeOffset = 0; |
| 4717 | static const int kProtoTransitionMapOffset = 1; |
| 4718 | |
| 4719 | inline int NumberOfProtoTransitions() { |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 4720 | FixedArray* cache = prototype_transitions(); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4721 | if (cache->length() == 0) return 0; |
| 4722 | return |
| 4723 | Smi::cast(cache->get(kProtoTransitionNumberOfEntriesOffset))->value(); |
| 4724 | } |
| 4725 | |
| 4726 | inline void SetNumberOfProtoTransitions(int value) { |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 4727 | FixedArray* cache = prototype_transitions(); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4728 | ASSERT(cache->length() != 0); |
| 4729 | cache->set_unchecked(kProtoTransitionNumberOfEntriesOffset, |
| 4730 | Smi::FromInt(value)); |
| 4731 | } |
| 4732 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4733 | // Lookup in the map's instance descriptors and fill out the result |
| 4734 | // with the given holder if the name is found. The holder may be |
| 4735 | // NULL when this function is used from the compiler. |
| 4736 | void LookupInDescriptors(JSObject* holder, |
| 4737 | String* name, |
| 4738 | LookupResult* result); |
| 4739 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 4740 | MUST_USE_RESULT MaybeObject* CopyDropDescriptors(); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4741 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 4742 | MUST_USE_RESULT MaybeObject* CopyNormalized(PropertyNormalizationMode mode, |
| 4743 | NormalizedMapSharingMode sharing); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4744 | |
| 4745 | // Returns a copy of the map, with all transitions dropped from the |
| 4746 | // instance descriptors. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 4747 | MUST_USE_RESULT MaybeObject* CopyDropTransitions(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4748 | |
| 4749 | // Returns the property index for name (only valid for FAST MODE). |
| 4750 | int PropertyIndexFor(String* name); |
| 4751 | |
| 4752 | // Returns the next free property index (only valid for FAST MODE). |
| 4753 | int NextFreePropertyIndex(); |
| 4754 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 4755 | // Returns the number of properties described in instance_descriptors |
| 4756 | // filtering out properties with the specified attributes. |
| 4757 | int NumberOfDescribedProperties(PropertyAttributes filter = NONE); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4758 | |
| 4759 | // Casting. |
| 4760 | static inline Map* cast(Object* obj); |
| 4761 | |
| 4762 | // Locate an accessor in the instance descriptor. |
| 4763 | AccessorDescriptor* FindAccessor(String* name); |
| 4764 | |
| 4765 | // Code cache operations. |
| 4766 | |
| 4767 | // Clears the code cache. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4768 | inline void ClearCodeCache(Heap* heap); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4769 | |
| 4770 | // Update code cache. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 4771 | static void UpdateCodeCache(Handle<Map> map, |
| 4772 | Handle<String> name, |
| 4773 | Handle<Code> code); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 4774 | MUST_USE_RESULT MaybeObject* UpdateCodeCache(String* name, Code* code); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4775 | |
| 4776 | // Returns the found code or undefined if absent. |
| 4777 | Object* FindInCodeCache(String* name, Code::Flags flags); |
| 4778 | |
| 4779 | // Returns the non-negative index of the code object if it is in the |
| 4780 | // cache and -1 otherwise. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4781 | int IndexInCodeCache(Object* name, Code* code); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4782 | |
| 4783 | // Removes a code object from the code cache at the given index. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4784 | void RemoveFromCodeCache(String* name, Code* code, int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4785 | |
| 4786 | // For every transition in this map, makes the transition's |
| 4787 | // target's prototype pointer point back to this map. |
| 4788 | // This is undone in MarkCompactCollector::ClearNonLiveTransitions(). |
| 4789 | void CreateBackPointers(); |
| 4790 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 4791 | void CreateOneBackPointer(Object* transition_target); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 4792 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4793 | // Set all map transitions from this map to dead maps to null. |
| 4794 | // Also, restore the original prototype on the targets of these |
| 4795 | // transitions, so that we do not process this map again while |
| 4796 | // following back pointers. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4797 | void ClearNonLiveTransitions(Heap* heap, Object* real_prototype); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4798 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 4799 | // Restore a possible back pointer in the prototype field of object. |
| 4800 | // Return true in that case and false otherwise. Set *keep_entry to |
| 4801 | // true when a live map transition has been found. |
| 4802 | bool RestoreOneBackPointer(Object* object, |
| 4803 | Object* real_prototype, |
| 4804 | bool* keep_entry); |
| 4805 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4806 | // Computes a hash value for this map, to be used in HashTables and such. |
| 4807 | int Hash(); |
| 4808 | |
| 4809 | // Compares this map to another to see if they describe equivalent objects. |
| 4810 | // If |mode| is set to CLEAR_INOBJECT_PROPERTIES, |other| is treated as if |
| 4811 | // it had exactly zero inobject properties. |
| 4812 | // The "shared" flags of both this map and |other| are ignored. |
| 4813 | bool EquivalentToForNormalization(Map* other, PropertyNormalizationMode mode); |
| 4814 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 4815 | // Returns the contents of this map's descriptor array for the given string. |
| 4816 | // May return NULL. |safe_to_add_transition| is set to false and NULL |
| 4817 | // is returned if adding transitions is not allowed. |
| 4818 | Object* GetDescriptorContents(String* sentinel_name, |
| 4819 | bool* safe_to_add_transitions); |
| 4820 | |
| 4821 | // Returns the map that this map transitions to if its elements_kind |
| 4822 | // is changed to |elements_kind|, or NULL if no such map is cached yet. |
| 4823 | // |safe_to_add_transitions| is set to false if adding transitions is not |
| 4824 | // allowed. |
| 4825 | Map* LookupElementsTransitionMap(ElementsKind elements_kind, |
| 4826 | bool* safe_to_add_transition); |
| 4827 | |
| 4828 | // Adds an entry to this map's descriptor array for a transition to |
| 4829 | // |transitioned_map| when its elements_kind is changed to |elements_kind|. |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 4830 | MUST_USE_RESULT MaybeObject* AddElementsTransition( |
| 4831 | ElementsKind elements_kind, Map* transitioned_map); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 4832 | |
| 4833 | // Returns the transitioned map for this map with the most generic |
| 4834 | // elements_kind that's found in |candidates|, or null handle if no match is |
| 4835 | // found at all. |
| 4836 | Handle<Map> FindTransitionedMap(MapHandleList* candidates); |
| 4837 | Map* FindTransitionedMap(MapList* candidates); |
| 4838 | |
| 4839 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4840 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4841 | #ifdef OBJECT_PRINT |
| 4842 | inline void MapPrint() { |
| 4843 | MapPrint(stdout); |
| 4844 | } |
| 4845 | void MapPrint(FILE* out); |
| 4846 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4847 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4848 | void MapVerify(); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4849 | void SharedMapVerify(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4850 | #endif |
| 4851 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 4852 | inline int visitor_id(); |
| 4853 | inline void set_visitor_id(int visitor_id); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 4854 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4855 | typedef void (*TraverseCallback)(Map* map, void* data); |
| 4856 | |
| 4857 | void TraverseTransitionTree(TraverseCallback callback, void* data); |
| 4858 | |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 4859 | static const int kMaxCachedPrototypeTransitions = 256; |
| 4860 | |
| 4861 | Object* GetPrototypeTransition(Object* prototype); |
| 4862 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 4863 | MUST_USE_RESULT MaybeObject* PutPrototypeTransition(Object* prototype, |
| 4864 | Map* map); |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 4865 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4866 | static const int kMaxPreAllocatedPropertyFields = 255; |
| 4867 | |
| 4868 | // Layout description. |
| 4869 | static const int kInstanceSizesOffset = HeapObject::kHeaderSize; |
| 4870 | static const int kInstanceAttributesOffset = kInstanceSizesOffset + kIntSize; |
| 4871 | static const int kPrototypeOffset = kInstanceAttributesOffset + kIntSize; |
| 4872 | static const int kConstructorOffset = kPrototypeOffset + kPointerSize; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4873 | // Storage for instance descriptors is overloaded to also contain additional |
| 4874 | // map flags when unused (bit_field3). When the map has instance descriptors, |
| 4875 | // the flags are transferred to the instance descriptor array and accessed |
| 4876 | // through an extra indirection. |
| 4877 | // TODO(1399): It should be possible to make room for bit_field3 in the map |
| 4878 | // without overloading the instance descriptors field, but the map is |
| 4879 | // currently perfectly aligned to 32 bytes and extending it at all would |
| 4880 | // double its size. After the increment GC work lands, this size restriction |
| 4881 | // could be loosened and bit_field3 moved directly back in the map. |
| 4882 | static const int kInstanceDescriptorsOrBitField3Offset = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4883 | kConstructorOffset + kPointerSize; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4884 | static const int kCodeCacheOffset = |
| 4885 | kInstanceDescriptorsOrBitField3Offset + kPointerSize; |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 4886 | static const int kPrototypeTransitionsOffset = |
| 4887 | kCodeCacheOffset + kPointerSize; |
| 4888 | static const int kPadStart = kPrototypeTransitionsOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4889 | static const int kSize = MAP_POINTER_ALIGN(kPadStart); |
| 4890 | |
| 4891 | // Layout of pointer fields. Heap iteration code relies on them |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 4892 | // being continuously allocated. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4893 | static const int kPointerFieldsBeginOffset = Map::kPrototypeOffset; |
| 4894 | static const int kPointerFieldsEndOffset = |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 4895 | Map::kPrototypeTransitionsOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4896 | |
| 4897 | // Byte offsets within kInstanceSizesOffset. |
| 4898 | static const int kInstanceSizeOffset = kInstanceSizesOffset + 0; |
| 4899 | static const int kInObjectPropertiesByte = 1; |
| 4900 | static const int kInObjectPropertiesOffset = |
| 4901 | kInstanceSizesOffset + kInObjectPropertiesByte; |
| 4902 | static const int kPreAllocatedPropertyFieldsByte = 2; |
| 4903 | static const int kPreAllocatedPropertyFieldsOffset = |
| 4904 | kInstanceSizesOffset + kPreAllocatedPropertyFieldsByte; |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 4905 | static const int kVisitorIdByte = 3; |
| 4906 | static const int kVisitorIdOffset = kInstanceSizesOffset + kVisitorIdByte; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4907 | |
| 4908 | // Byte offsets within kInstanceAttributesOffset attributes. |
| 4909 | static const int kInstanceTypeOffset = kInstanceAttributesOffset + 0; |
| 4910 | static const int kUnusedPropertyFieldsOffset = kInstanceAttributesOffset + 1; |
| 4911 | static const int kBitFieldOffset = kInstanceAttributesOffset + 2; |
| 4912 | static const int kBitField2Offset = kInstanceAttributesOffset + 3; |
| 4913 | |
| 4914 | STATIC_CHECK(kInstanceTypeOffset == Internals::kMapInstanceTypeOffset); |
| 4915 | |
| 4916 | // Bit positions for bit field. |
| 4917 | static const int kUnused = 0; // To be used for marking recently used maps. |
| 4918 | static const int kHasNonInstancePrototype = 1; |
| 4919 | static const int kIsHiddenPrototype = 2; |
| 4920 | static const int kHasNamedInterceptor = 3; |
| 4921 | static const int kHasIndexedInterceptor = 4; |
| 4922 | static const int kIsUndetectable = 5; |
| 4923 | static const int kHasInstanceCallHandler = 6; |
| 4924 | static const int kIsAccessCheckNeeded = 7; |
| 4925 | |
| 4926 | // Bit positions for bit field 2 |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 4927 | static const int kIsExtensible = 0; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4928 | static const int kFunctionWithPrototype = 1; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4929 | static const int kStringWrapperSafeForDefaultValueOf = 2; |
| 4930 | static const int kAttachedToSharedFunctionInfo = 3; |
| 4931 | // No bits can be used after kElementsKindFirstBit, they are all reserved for |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 4932 | // storing ElementKind. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4933 | static const int kElementsKindShift = 4; |
| 4934 | static const int kElementsKindBitCount = 4; |
| 4935 | |
| 4936 | // Derived values from bit field 2 |
| 4937 | static const int kElementsKindMask = (-1 << kElementsKindShift) & |
| 4938 | ((1 << (kElementsKindShift + kElementsKindBitCount)) - 1); |
| 4939 | static const int8_t kMaximumBitField2FastElementValue = static_cast<int8_t>( |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 4940 | (FAST_ELEMENTS + 1) << Map::kElementsKindShift) - 1; |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 4941 | static const int8_t kMaximumBitField2FastSmiOnlyElementValue = |
| 4942 | static_cast<int8_t>((FAST_SMI_ONLY_ELEMENTS + 1) << |
| 4943 | Map::kElementsKindShift) - 1; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4944 | |
| 4945 | // Bit positions for bit field 3 |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4946 | static const int kIsShared = 0; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4947 | |
| 4948 | // Layout of the default cache. It holds alternating name and code objects. |
| 4949 | static const int kCodeCacheEntrySize = 2; |
| 4950 | static const int kCodeCacheEntryNameOffset = 0; |
| 4951 | static const int kCodeCacheEntryCodeOffset = 1; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4952 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 4953 | typedef FixedBodyDescriptor<kPointerFieldsBeginOffset, |
| 4954 | kPointerFieldsEndOffset, |
| 4955 | kSize> BodyDescriptor; |
| 4956 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4957 | private: |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 4958 | String* elements_transition_sentinel_name(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4959 | DISALLOW_IMPLICIT_CONSTRUCTORS(Map); |
| 4960 | }; |
| 4961 | |
| 4962 | |
| 4963 | // An abstract superclass, a marker class really, for simple structure classes. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4964 | // It doesn't carry much functionality but allows struct classes to be |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4965 | // identified in the type system. |
| 4966 | class Struct: public HeapObject { |
| 4967 | public: |
| 4968 | inline void InitializeBody(int object_size); |
| 4969 | static inline Struct* cast(Object* that); |
| 4970 | }; |
| 4971 | |
| 4972 | |
| 4973 | // Script describes a script which has been added to the VM. |
| 4974 | class Script: public Struct { |
| 4975 | public: |
| 4976 | // Script types. |
| 4977 | enum Type { |
| 4978 | TYPE_NATIVE = 0, |
| 4979 | TYPE_EXTENSION = 1, |
| 4980 | TYPE_NORMAL = 2 |
| 4981 | }; |
| 4982 | |
| 4983 | // Script compilation types. |
| 4984 | enum CompilationType { |
| 4985 | COMPILATION_TYPE_HOST = 0, |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 4986 | COMPILATION_TYPE_EVAL = 1 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4987 | }; |
| 4988 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 4989 | // Script compilation state. |
| 4990 | enum CompilationState { |
| 4991 | COMPILATION_STATE_INITIAL = 0, |
| 4992 | COMPILATION_STATE_COMPILED = 1 |
| 4993 | }; |
| 4994 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4995 | // [source]: the script source. |
| 4996 | DECL_ACCESSORS(source, Object) |
| 4997 | |
| 4998 | // [name]: the script name. |
| 4999 | DECL_ACCESSORS(name, Object) |
| 5000 | |
| 5001 | // [id]: the script id. |
| 5002 | DECL_ACCESSORS(id, Object) |
| 5003 | |
| 5004 | // [line_offset]: script line offset in resource from where it was extracted. |
| 5005 | DECL_ACCESSORS(line_offset, Smi) |
| 5006 | |
| 5007 | // [column_offset]: script column offset in resource from where it was |
| 5008 | // extracted. |
| 5009 | DECL_ACCESSORS(column_offset, Smi) |
| 5010 | |
| 5011 | // [data]: additional data associated with this script. |
| 5012 | DECL_ACCESSORS(data, Object) |
| 5013 | |
| 5014 | // [context_data]: context data for the context this script was compiled in. |
| 5015 | DECL_ACCESSORS(context_data, Object) |
| 5016 | |
| 5017 | // [wrapper]: the wrapper cache. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5018 | DECL_ACCESSORS(wrapper, Foreign) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5019 | |
| 5020 | // [type]: the script type. |
| 5021 | DECL_ACCESSORS(type, Smi) |
| 5022 | |
| 5023 | // [compilation]: how the the script was compiled. |
| 5024 | DECL_ACCESSORS(compilation_type, Smi) |
| 5025 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 5026 | // [is_compiled]: determines whether the script has already been compiled. |
| 5027 | DECL_ACCESSORS(compilation_state, Smi) |
| 5028 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5029 | // [line_ends]: FixedArray of line ends positions. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5030 | DECL_ACCESSORS(line_ends, Object) |
| 5031 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5032 | // [eval_from_shared]: for eval scripts the shared funcion info for the |
| 5033 | // function from which eval was called. |
| 5034 | DECL_ACCESSORS(eval_from_shared, Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5035 | |
| 5036 | // [eval_from_instructions_offset]: the instruction offset in the code for the |
| 5037 | // function from which eval was called where eval was called. |
| 5038 | DECL_ACCESSORS(eval_from_instructions_offset, Smi) |
| 5039 | |
| 5040 | static inline Script* cast(Object* obj); |
| 5041 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 5042 | // If script source is an external string, check that the underlying |
| 5043 | // resource is accessible. Otherwise, always return true. |
| 5044 | inline bool HasValidSource(); |
| 5045 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5046 | #ifdef OBJECT_PRINT |
| 5047 | inline void ScriptPrint() { |
| 5048 | ScriptPrint(stdout); |
| 5049 | } |
| 5050 | void ScriptPrint(FILE* out); |
| 5051 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5052 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5053 | void ScriptVerify(); |
| 5054 | #endif |
| 5055 | |
| 5056 | static const int kSourceOffset = HeapObject::kHeaderSize; |
| 5057 | static const int kNameOffset = kSourceOffset + kPointerSize; |
| 5058 | static const int kLineOffsetOffset = kNameOffset + kPointerSize; |
| 5059 | static const int kColumnOffsetOffset = kLineOffsetOffset + kPointerSize; |
| 5060 | static const int kDataOffset = kColumnOffsetOffset + kPointerSize; |
| 5061 | static const int kContextOffset = kDataOffset + kPointerSize; |
| 5062 | static const int kWrapperOffset = kContextOffset + kPointerSize; |
| 5063 | static const int kTypeOffset = kWrapperOffset + kPointerSize; |
| 5064 | static const int kCompilationTypeOffset = kTypeOffset + kPointerSize; |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 5065 | static const int kCompilationStateOffset = |
| 5066 | kCompilationTypeOffset + kPointerSize; |
| 5067 | static const int kLineEndsOffset = kCompilationStateOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5068 | static const int kIdOffset = kLineEndsOffset + kPointerSize; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5069 | static const int kEvalFromSharedOffset = kIdOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5070 | static const int kEvalFrominstructionsOffsetOffset = |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5071 | kEvalFromSharedOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5072 | static const int kSize = kEvalFrominstructionsOffsetOffset + kPointerSize; |
| 5073 | |
| 5074 | private: |
| 5075 | DISALLOW_IMPLICIT_CONSTRUCTORS(Script); |
| 5076 | }; |
| 5077 | |
| 5078 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5079 | // List of builtin functions we want to identify to improve code |
| 5080 | // generation. |
| 5081 | // |
| 5082 | // Each entry has a name of a global object property holding an object |
| 5083 | // optionally followed by ".prototype", a name of a builtin function |
| 5084 | // on the object (the one the id is set for), and a label. |
| 5085 | // |
| 5086 | // Installation of ids for the selected builtin functions is handled |
| 5087 | // by the bootstrapper. |
| 5088 | // |
| 5089 | // NOTE: Order is important: math functions should be at the end of |
| 5090 | // the list and MathFloor should be the first math function. |
| 5091 | #define FUNCTIONS_WITH_ID_LIST(V) \ |
| 5092 | V(Array.prototype, push, ArrayPush) \ |
| 5093 | V(Array.prototype, pop, ArrayPop) \ |
Ben Murdoch | 42effa5 | 2011-08-19 16:40:31 +0100 | [diff] [blame] | 5094 | V(Function.prototype, apply, FunctionApply) \ |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5095 | V(String.prototype, charCodeAt, StringCharCodeAt) \ |
| 5096 | V(String.prototype, charAt, StringCharAt) \ |
| 5097 | V(String, fromCharCode, StringFromCharCode) \ |
| 5098 | V(Math, floor, MathFloor) \ |
| 5099 | V(Math, round, MathRound) \ |
| 5100 | V(Math, ceil, MathCeil) \ |
| 5101 | V(Math, abs, MathAbs) \ |
| 5102 | V(Math, log, MathLog) \ |
| 5103 | V(Math, sin, MathSin) \ |
| 5104 | V(Math, cos, MathCos) \ |
| 5105 | V(Math, tan, MathTan) \ |
| 5106 | V(Math, asin, MathASin) \ |
| 5107 | V(Math, acos, MathACos) \ |
| 5108 | V(Math, atan, MathATan) \ |
| 5109 | V(Math, exp, MathExp) \ |
| 5110 | V(Math, sqrt, MathSqrt) \ |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 5111 | V(Math, pow, MathPow) \ |
| 5112 | V(Math, random, MathRandom) \ |
| 5113 | V(Math, max, MathMax) \ |
| 5114 | V(Math, min, MathMin) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5115 | |
| 5116 | |
| 5117 | enum BuiltinFunctionId { |
| 5118 | #define DECLARE_FUNCTION_ID(ignored1, ignore2, name) \ |
| 5119 | k##name, |
| 5120 | FUNCTIONS_WITH_ID_LIST(DECLARE_FUNCTION_ID) |
| 5121 | #undef DECLARE_FUNCTION_ID |
| 5122 | // Fake id for a special case of Math.pow. Note, it continues the |
| 5123 | // list of math functions. |
| 5124 | kMathPowHalf, |
| 5125 | kFirstMathFunctionId = kMathFloor |
| 5126 | }; |
| 5127 | |
| 5128 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5129 | // SharedFunctionInfo describes the JSFunction information that can be |
| 5130 | // shared by multiple instances of the function. |
| 5131 | class SharedFunctionInfo: public HeapObject { |
| 5132 | public: |
| 5133 | // [name]: Function name. |
| 5134 | DECL_ACCESSORS(name, Object) |
| 5135 | |
| 5136 | // [code]: Function code. |
| 5137 | DECL_ACCESSORS(code, Code) |
| 5138 | |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 5139 | // [scope_info]: Scope info. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 5140 | DECL_ACCESSORS(scope_info, ScopeInfo) |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 5141 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5142 | // [construct stub]: Code stub for constructing instances of this function. |
| 5143 | DECL_ACCESSORS(construct_stub, Code) |
| 5144 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 5145 | inline Code* unchecked_code(); |
| 5146 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5147 | // Returns if this function has been compiled to native code yet. |
| 5148 | inline bool is_compiled(); |
| 5149 | |
| 5150 | // [length]: The function length - usually the number of declared parameters. |
| 5151 | // Use up to 2^30 parameters. |
| 5152 | inline int length(); |
| 5153 | inline void set_length(int value); |
| 5154 | |
| 5155 | // [formal parameter count]: The declared number of parameters. |
| 5156 | inline int formal_parameter_count(); |
| 5157 | inline void set_formal_parameter_count(int value); |
| 5158 | |
| 5159 | // Set the formal parameter count so the function code will be |
| 5160 | // called without using argument adaptor frames. |
| 5161 | inline void DontAdaptArguments(); |
| 5162 | |
| 5163 | // [expected_nof_properties]: Expected number of properties for the function. |
| 5164 | inline int expected_nof_properties(); |
| 5165 | inline void set_expected_nof_properties(int value); |
| 5166 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5167 | // Inobject slack tracking is the way to reclaim unused inobject space. |
| 5168 | // |
| 5169 | // The instance size is initially determined by adding some slack to |
| 5170 | // expected_nof_properties (to allow for a few extra properties added |
| 5171 | // after the constructor). There is no guarantee that the extra space |
| 5172 | // will not be wasted. |
| 5173 | // |
| 5174 | // Here is the algorithm to reclaim the unused inobject space: |
| 5175 | // - Detect the first constructor call for this SharedFunctionInfo. |
| 5176 | // When it happens enter the "in progress" state: remember the |
| 5177 | // constructor's initial_map and install a special construct stub that |
| 5178 | // counts constructor calls. |
| 5179 | // - While the tracking is in progress create objects filled with |
| 5180 | // one_pointer_filler_map instead of undefined_value. This way they can be |
| 5181 | // resized quickly and safely. |
| 5182 | // - Once enough (kGenerousAllocationCount) objects have been created |
| 5183 | // compute the 'slack' (traverse the map transition tree starting from the |
| 5184 | // initial_map and find the lowest value of unused_property_fields). |
| 5185 | // - Traverse the transition tree again and decrease the instance size |
| 5186 | // of every map. Existing objects will resize automatically (they are |
| 5187 | // filled with one_pointer_filler_map). All further allocations will |
| 5188 | // use the adjusted instance size. |
| 5189 | // - Decrease expected_nof_properties so that an allocations made from |
| 5190 | // another context will use the adjusted instance size too. |
| 5191 | // - Exit "in progress" state by clearing the reference to the initial_map |
| 5192 | // and setting the regular construct stub (generic or inline). |
| 5193 | // |
| 5194 | // The above is the main event sequence. Some special cases are possible |
| 5195 | // while the tracking is in progress: |
| 5196 | // |
| 5197 | // - GC occurs. |
| 5198 | // Check if the initial_map is referenced by any live objects (except this |
| 5199 | // SharedFunctionInfo). If it is, continue tracking as usual. |
| 5200 | // If it is not, clear the reference and reset the tracking state. The |
| 5201 | // tracking will be initiated again on the next constructor call. |
| 5202 | // |
| 5203 | // - The constructor is called from another context. |
| 5204 | // Immediately complete the tracking, perform all the necessary changes |
| 5205 | // to maps. This is necessary because there is no efficient way to track |
| 5206 | // multiple initial_maps. |
| 5207 | // Proceed to create an object in the current context (with the adjusted |
| 5208 | // size). |
| 5209 | // |
| 5210 | // - A different constructor function sharing the same SharedFunctionInfo is |
| 5211 | // called in the same context. This could be another closure in the same |
| 5212 | // context, or the first function could have been disposed. |
| 5213 | // This is handled the same way as the previous case. |
| 5214 | // |
| 5215 | // Important: inobject slack tracking is not attempted during the snapshot |
| 5216 | // creation. |
| 5217 | |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 5218 | static const int kGenerousAllocationCount = 8; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5219 | |
| 5220 | // [construction_count]: Counter for constructor calls made during |
| 5221 | // the tracking phase. |
| 5222 | inline int construction_count(); |
| 5223 | inline void set_construction_count(int value); |
| 5224 | |
| 5225 | // [initial_map]: initial map of the first function called as a constructor. |
| 5226 | // Saved for the duration of the tracking phase. |
| 5227 | // This is a weak link (GC resets it to undefined_value if no other live |
| 5228 | // object reference this map). |
| 5229 | DECL_ACCESSORS(initial_map, Object) |
| 5230 | |
| 5231 | // True if the initial_map is not undefined and the countdown stub is |
| 5232 | // installed. |
| 5233 | inline bool IsInobjectSlackTrackingInProgress(); |
| 5234 | |
| 5235 | // Starts the tracking. |
| 5236 | // Stores the initial map and installs the countdown stub. |
| 5237 | // IsInobjectSlackTrackingInProgress is normally true after this call, |
| 5238 | // except when tracking have not been started (e.g. the map has no unused |
| 5239 | // properties or the snapshot is being built). |
| 5240 | void StartInobjectSlackTracking(Map* map); |
| 5241 | |
| 5242 | // Completes the tracking. |
| 5243 | // IsInobjectSlackTrackingInProgress is false after this call. |
| 5244 | void CompleteInobjectSlackTracking(); |
| 5245 | |
| 5246 | // Clears the initial_map before the GC marking phase to ensure the reference |
| 5247 | // is weak. IsInobjectSlackTrackingInProgress is false after this call. |
| 5248 | void DetachInitialMap(); |
| 5249 | |
| 5250 | // Restores the link to the initial map after the GC marking phase. |
| 5251 | // IsInobjectSlackTrackingInProgress is true after this call. |
| 5252 | void AttachInitialMap(Map* map); |
| 5253 | |
| 5254 | // False if there are definitely no live objects created from this function. |
| 5255 | // True if live objects _may_ exist (existence not guaranteed). |
| 5256 | // May go back from true to false after GC. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 5257 | DECL_BOOLEAN_ACCESSORS(live_objects_may_exist) |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5258 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5259 | // [instance class name]: class name for instances. |
| 5260 | DECL_ACCESSORS(instance_class_name, Object) |
| 5261 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5262 | // [function data]: This field holds some additional data for function. |
| 5263 | // Currently it either has FunctionTemplateInfo to make benefit the API |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5264 | // or Smi identifying a builtin function. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5265 | // In the long run we don't want all functions to have this field but |
| 5266 | // we can fix that when we have a better model for storing hidden data |
| 5267 | // on objects. |
| 5268 | DECL_ACCESSORS(function_data, Object) |
| 5269 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5270 | inline bool IsApiFunction(); |
| 5271 | inline FunctionTemplateInfo* get_api_func_data(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5272 | inline bool HasBuiltinFunctionId(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5273 | inline BuiltinFunctionId builtin_function_id(); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5274 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5275 | // [script info]: Script from which the function originates. |
| 5276 | DECL_ACCESSORS(script, Object) |
| 5277 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5278 | // [num_literals]: Number of literals used by this function. |
| 5279 | inline int num_literals(); |
| 5280 | inline void set_num_literals(int value); |
| 5281 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5282 | // [start_position_and_type]: Field used to store both the source code |
| 5283 | // position, whether or not the function is a function expression, |
| 5284 | // and whether or not the function is a toplevel function. The two |
| 5285 | // least significants bit indicates whether the function is an |
| 5286 | // expression and the rest contains the source code position. |
| 5287 | inline int start_position_and_type(); |
| 5288 | inline void set_start_position_and_type(int value); |
| 5289 | |
| 5290 | // [debug info]: Debug information. |
| 5291 | DECL_ACCESSORS(debug_info, Object) |
| 5292 | |
| 5293 | // [inferred name]: Name inferred from variable or property |
| 5294 | // assignment of this function. Used to facilitate debugging and |
| 5295 | // profiling of JavaScript code written in OO style, where almost |
| 5296 | // all functions are anonymous but are assigned to object |
| 5297 | // properties. |
| 5298 | DECL_ACCESSORS(inferred_name, String) |
| 5299 | |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 5300 | // The function's name if it is non-empty, otherwise the inferred name. |
| 5301 | String* DebugName(); |
| 5302 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5303 | // Position of the 'function' token in the script source. |
| 5304 | inline int function_token_position(); |
| 5305 | inline void set_function_token_position(int function_token_position); |
| 5306 | |
| 5307 | // Position of this function in the script source. |
| 5308 | inline int start_position(); |
| 5309 | inline void set_start_position(int start_position); |
| 5310 | |
| 5311 | // End position of this function in the script source. |
| 5312 | inline int end_position(); |
| 5313 | inline void set_end_position(int end_position); |
| 5314 | |
| 5315 | // Is this function a function expression in the source code. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 5316 | DECL_BOOLEAN_ACCESSORS(is_expression) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5317 | |
| 5318 | // Is this function a top-level function (scripts, evals). |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 5319 | DECL_BOOLEAN_ACCESSORS(is_toplevel) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5320 | |
| 5321 | // Bit field containing various information collected by the compiler to |
| 5322 | // drive optimization. |
| 5323 | inline int compiler_hints(); |
| 5324 | inline void set_compiler_hints(int value); |
| 5325 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5326 | // A counter used to determine when to stress the deoptimizer with a |
| 5327 | // deopt. |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 5328 | inline int deopt_counter(); |
| 5329 | inline void set_deopt_counter(int counter); |
| 5330 | |
| 5331 | inline int profiler_ticks(); |
| 5332 | inline void set_profiler_ticks(int ticks); |
| 5333 | |
| 5334 | inline int ast_node_count(); |
| 5335 | inline void set_ast_node_count(int count); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5336 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5337 | // Add information on assignments of the form this.x = ...; |
| 5338 | void SetThisPropertyAssignmentsInfo( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5339 | bool has_only_simple_this_property_assignments, |
| 5340 | FixedArray* this_property_assignments); |
| 5341 | |
| 5342 | // Clear information on assignments of the form this.x = ...; |
| 5343 | void ClearThisPropertyAssignmentsInfo(); |
| 5344 | |
| 5345 | // Indicate that this function only consists of assignments of the form |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5346 | // this.x = y; where y is either a constant or refers to an argument. |
| 5347 | inline bool has_only_simple_this_property_assignments(); |
| 5348 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 5349 | // Indicates if this function can be lazy compiled. |
| 5350 | // This is used to determine if we can safely flush code from a function |
| 5351 | // 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] | 5352 | DECL_BOOLEAN_ACCESSORS(allows_lazy_compilation) |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 5353 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 5354 | // Indicates how many full GCs this function has survived with assigned |
| 5355 | // code object. Used to determine when it is relatively safe to flush |
| 5356 | // this code object and replace it with lazy compilation stub. |
| 5357 | // Age is reset when GC notices that the code object is referenced |
| 5358 | // from the stack or compilation cache. |
| 5359 | inline int code_age(); |
| 5360 | inline void set_code_age(int age); |
| 5361 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5362 | // Indicates whether optimizations have been disabled for this |
| 5363 | // shared function info. If a function is repeatedly optimized or if |
| 5364 | // we cannot optimize the function we disable optimization to avoid |
| 5365 | // spending time attempting to optimize it again. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 5366 | DECL_BOOLEAN_ACCESSORS(optimization_disabled) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5367 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 5368 | // Indicates the language mode of the function's code as defined by the |
| 5369 | // current harmony drafts for the next ES language standard. Possible |
| 5370 | // values are: |
| 5371 | // 1. CLASSIC_MODE - Unrestricted syntax and semantics, same as in ES5. |
| 5372 | // 2. STRICT_MODE - Restricted syntax and semantics, same as in ES5. |
| 5373 | // 3. EXTENDED_MODE - Only available under the harmony flag, not part of ES5. |
| 5374 | inline LanguageMode language_mode(); |
| 5375 | inline void set_language_mode(LanguageMode language_mode); |
| 5376 | |
| 5377 | // Indicates whether the language mode of this function is CLASSIC_MODE. |
| 5378 | inline bool is_classic_mode(); |
| 5379 | |
| 5380 | // Indicates whether the language mode of this function is EXTENDED_MODE. |
| 5381 | inline bool is_extended_mode(); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 5382 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 5383 | // False if the function definitely does not allocate an arguments object. |
| 5384 | DECL_BOOLEAN_ACCESSORS(uses_arguments) |
| 5385 | |
| 5386 | // True if the function has any duplicated parameter names. |
| 5387 | DECL_BOOLEAN_ACCESSORS(has_duplicate_parameters) |
| 5388 | |
| 5389 | // Indicates whether the function is a native function. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 5390 | // These needs special treatment in .call and .apply since |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5391 | // null passed as the receiver should not be translated to the |
| 5392 | // global object. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 5393 | DECL_BOOLEAN_ACCESSORS(native) |
| 5394 | |
| 5395 | // Indicates that the function was created by the Function function. |
| 5396 | // Though it's anonymous, toString should treat it as if it had the name |
| 5397 | // "anonymous". We don't set the name itself so that the system does not |
| 5398 | // see a binding for it. |
| 5399 | DECL_BOOLEAN_ACCESSORS(name_should_print_as_anonymous) |
| 5400 | |
| 5401 | // Indicates whether the function is a bound function created using |
| 5402 | // the bind function. |
| 5403 | DECL_BOOLEAN_ACCESSORS(bound) |
| 5404 | |
| 5405 | // Indicates that the function is anonymous (the name field can be set |
| 5406 | // through the API, which does not change this flag). |
| 5407 | DECL_BOOLEAN_ACCESSORS(is_anonymous) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5408 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 5409 | // Is this a function or top-level/eval code. |
| 5410 | DECL_BOOLEAN_ACCESSORS(is_function) |
| 5411 | |
| 5412 | // Indicates that the function cannot be optimized. |
| 5413 | DECL_BOOLEAN_ACCESSORS(dont_optimize) |
| 5414 | |
| 5415 | // Indicates that the function cannot be inlined. |
| 5416 | DECL_BOOLEAN_ACCESSORS(dont_inline) |
| 5417 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5418 | // Indicates whether or not the code in the shared function support |
| 5419 | // deoptimization. |
| 5420 | inline bool has_deoptimization_support(); |
| 5421 | |
| 5422 | // Enable deoptimization support through recompiled code. |
| 5423 | void EnableDeoptimizationSupport(Code* recompiled); |
| 5424 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5425 | // Disable (further) attempted optimization of all functions sharing this |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 5426 | // shared function info. |
| 5427 | void DisableOptimization(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5428 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5429 | // Lookup the bailout ID and ASSERT that it exists in the non-optimized |
| 5430 | // code, returns whether it asserted (i.e., always true if assertions are |
| 5431 | // disabled). |
| 5432 | bool VerifyBailoutId(int id); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 5433 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 5434 | // Check whether a inlined constructor can be generated with the given |
| 5435 | // prototype. |
| 5436 | bool CanGenerateInlineConstructor(Object* prototype); |
| 5437 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5438 | // Prevents further attempts to generate inline constructors. |
| 5439 | // To be called if generation failed for any reason. |
| 5440 | void ForbidInlineConstructor(); |
| 5441 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5442 | // For functions which only contains this property assignments this provides |
| 5443 | // access to the names for the properties assigned. |
| 5444 | DECL_ACCESSORS(this_property_assignments, Object) |
| 5445 | inline int this_property_assignments_count(); |
| 5446 | inline void set_this_property_assignments_count(int value); |
| 5447 | String* GetThisPropertyAssignmentName(int index); |
| 5448 | bool IsThisPropertyAssignmentArgument(int index); |
| 5449 | int GetThisPropertyAssignmentArgument(int index); |
| 5450 | Object* GetThisPropertyAssignmentConstant(int index); |
| 5451 | |
| 5452 | // [source code]: Source code for the function. |
| 5453 | bool HasSourceCode(); |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 5454 | Handle<Object> GetSourceCode(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5455 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5456 | inline int opt_count(); |
| 5457 | inline void set_opt_count(int opt_count); |
| 5458 | |
| 5459 | // Source size of this function. |
| 5460 | int SourceSize(); |
| 5461 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5462 | // Calculate the instance size. |
| 5463 | int CalculateInstanceSize(); |
| 5464 | |
| 5465 | // Calculate the number of in-object properties. |
| 5466 | int CalculateInObjectProperties(); |
| 5467 | |
| 5468 | // Dispatched behavior. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5469 | // Set max_length to -1 for unlimited length. |
| 5470 | void SourceCodePrint(StringStream* accumulator, int max_length); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5471 | #ifdef OBJECT_PRINT |
| 5472 | inline void SharedFunctionInfoPrint() { |
| 5473 | SharedFunctionInfoPrint(stdout); |
| 5474 | } |
| 5475 | void SharedFunctionInfoPrint(FILE* out); |
| 5476 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5477 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5478 | void SharedFunctionInfoVerify(); |
| 5479 | #endif |
| 5480 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 5481 | // Helpers to compile the shared code. Returns true on success, false on |
| 5482 | // failure (e.g., stack overflow during compilation). |
| 5483 | static bool EnsureCompiled(Handle<SharedFunctionInfo> shared, |
| 5484 | ClearExceptionFlag flag); |
| 5485 | static bool CompileLazy(Handle<SharedFunctionInfo> shared, |
| 5486 | ClearExceptionFlag flag); |
| 5487 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5488 | // Casting. |
| 5489 | static inline SharedFunctionInfo* cast(Object* obj); |
| 5490 | |
| 5491 | // Constants. |
| 5492 | static const int kDontAdaptArgumentsSentinel = -1; |
| 5493 | |
| 5494 | // Layout description. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5495 | // Pointer fields. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5496 | static const int kNameOffset = HeapObject::kHeaderSize; |
| 5497 | static const int kCodeOffset = kNameOffset + kPointerSize; |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 5498 | static const int kScopeInfoOffset = kCodeOffset + kPointerSize; |
| 5499 | static const int kConstructStubOffset = kScopeInfoOffset + kPointerSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5500 | static const int kInstanceClassNameOffset = |
| 5501 | kConstructStubOffset + kPointerSize; |
| 5502 | static const int kFunctionDataOffset = |
| 5503 | kInstanceClassNameOffset + kPointerSize; |
| 5504 | static const int kScriptOffset = kFunctionDataOffset + kPointerSize; |
| 5505 | static const int kDebugInfoOffset = kScriptOffset + kPointerSize; |
| 5506 | static const int kInferredNameOffset = kDebugInfoOffset + kPointerSize; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5507 | static const int kInitialMapOffset = |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5508 | kInferredNameOffset + kPointerSize; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5509 | static const int kThisPropertyAssignmentsOffset = |
| 5510 | kInitialMapOffset + kPointerSize; |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 5511 | static const int kProfilerTicksOffset = |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5512 | kThisPropertyAssignmentsOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 5513 | #if V8_HOST_ARCH_32_BIT |
| 5514 | // Smi fields. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5515 | static const int kLengthOffset = |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 5516 | kProfilerTicksOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 5517 | static const int kFormalParameterCountOffset = kLengthOffset + kPointerSize; |
| 5518 | static const int kExpectedNofPropertiesOffset = |
| 5519 | kFormalParameterCountOffset + kPointerSize; |
| 5520 | static const int kNumLiteralsOffset = |
| 5521 | kExpectedNofPropertiesOffset + kPointerSize; |
| 5522 | static const int kStartPositionAndTypeOffset = |
| 5523 | kNumLiteralsOffset + kPointerSize; |
| 5524 | static const int kEndPositionOffset = |
| 5525 | kStartPositionAndTypeOffset + kPointerSize; |
| 5526 | static const int kFunctionTokenPositionOffset = |
| 5527 | kEndPositionOffset + kPointerSize; |
| 5528 | static const int kCompilerHintsOffset = |
| 5529 | kFunctionTokenPositionOffset + kPointerSize; |
| 5530 | static const int kThisPropertyAssignmentsCountOffset = |
| 5531 | kCompilerHintsOffset + kPointerSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5532 | static const int kOptCountOffset = |
| 5533 | kThisPropertyAssignmentsCountOffset + kPointerSize; |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 5534 | static const int kAstNodeCountOffset = kOptCountOffset + kPointerSize; |
| 5535 | static const int kDeoptCounterOffset = |
| 5536 | kAstNodeCountOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 5537 | // Total size. |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 5538 | static const int kSize = kDeoptCounterOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 5539 | #else |
| 5540 | // The only reason to use smi fields instead of int fields |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5541 | // is to allow iteration without maps decoding during |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 5542 | // garbage collections. |
| 5543 | // To avoid wasting space on 64-bit architectures we use |
| 5544 | // the following trick: we group integer fields into pairs |
| 5545 | // First integer in each pair is shifted left by 1. |
| 5546 | // By doing this we guarantee that LSB of each kPointerSize aligned |
| 5547 | // word is not set and thus this word cannot be treated as pointer |
| 5548 | // to HeapObject during old space traversal. |
| 5549 | static const int kLengthOffset = |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 5550 | kProfilerTicksOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 5551 | static const int kFormalParameterCountOffset = |
| 5552 | kLengthOffset + kIntSize; |
| 5553 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5554 | static const int kExpectedNofPropertiesOffset = |
| 5555 | kFormalParameterCountOffset + kIntSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 5556 | static const int kNumLiteralsOffset = |
| 5557 | kExpectedNofPropertiesOffset + kIntSize; |
| 5558 | |
| 5559 | static const int kEndPositionOffset = |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5560 | kNumLiteralsOffset + kIntSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 5561 | static const int kStartPositionAndTypeOffset = |
| 5562 | kEndPositionOffset + kIntSize; |
| 5563 | |
| 5564 | static const int kFunctionTokenPositionOffset = |
| 5565 | kStartPositionAndTypeOffset + kIntSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5566 | static const int kCompilerHintsOffset = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5567 | kFunctionTokenPositionOffset + kIntSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 5568 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5569 | static const int kThisPropertyAssignmentsCountOffset = |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5570 | kCompilerHintsOffset + kIntSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5571 | static const int kOptCountOffset = |
| 5572 | kThisPropertyAssignmentsCountOffset + kIntSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 5573 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 5574 | static const int kAstNodeCountOffset = kOptCountOffset + kIntSize; |
| 5575 | static const int kDeoptCounterOffset = kAstNodeCountOffset + kIntSize; |
| 5576 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5577 | // Total size. |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 5578 | static const int kSize = kDeoptCounterOffset + kIntSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 5579 | |
| 5580 | #endif |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5581 | |
| 5582 | // The construction counter for inobject slack tracking is stored in the |
| 5583 | // most significant byte of compiler_hints which is otherwise unused. |
| 5584 | // Its offset depends on the endian-ness of the architecture. |
| 5585 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 5586 | static const int kConstructionCountOffset = kCompilerHintsOffset + 3; |
| 5587 | #elif __BYTE_ORDER == __BIG_ENDIAN |
| 5588 | static const int kConstructionCountOffset = kCompilerHintsOffset + 0; |
| 5589 | #else |
| 5590 | #error Unknown byte ordering |
| 5591 | #endif |
| 5592 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5593 | static const int kAlignedSize = POINTER_SIZE_ALIGN(kSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5594 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 5595 | typedef FixedBodyDescriptor<kNameOffset, |
| 5596 | kThisPropertyAssignmentsOffset + kPointerSize, |
| 5597 | kSize> BodyDescriptor; |
| 5598 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5599 | // Bit positions in start_position_and_type. |
| 5600 | // The source code start position is in the 30 most significant bits of |
| 5601 | // the start_position_and_type field. |
| 5602 | static const int kIsExpressionBit = 0; |
| 5603 | static const int kIsTopLevelBit = 1; |
| 5604 | static const int kStartPositionShift = 2; |
| 5605 | static const int kStartPositionMask = ~((1 << kStartPositionShift) - 1); |
| 5606 | |
| 5607 | // Bit positions in compiler_hints. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 5608 | static const int kCodeAgeSize = 3; |
| 5609 | static const int kCodeAgeMask = (1 << kCodeAgeSize) - 1; |
| 5610 | |
| 5611 | enum CompilerHints { |
| 5612 | kHasOnlySimpleThisPropertyAssignments, |
| 5613 | kAllowLazyCompilation, |
| 5614 | kLiveObjectsMayExist, |
| 5615 | kCodeAgeShift, |
| 5616 | kOptimizationDisabled = kCodeAgeShift + kCodeAgeSize, |
| 5617 | kStrictModeFunction, |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 5618 | kExtendedModeFunction, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 5619 | kUsesArguments, |
| 5620 | kHasDuplicateParameters, |
| 5621 | kNative, |
| 5622 | kBoundFunction, |
| 5623 | kIsAnonymous, |
| 5624 | kNameShouldPrintAsAnonymous, |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 5625 | kIsFunction, |
| 5626 | kDontOptimize, |
| 5627 | kDontInline, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 5628 | kCompilerHintsCount // Pseudo entry |
| 5629 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5630 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 5631 | private: |
| 5632 | #if V8_HOST_ARCH_32_BIT |
| 5633 | // On 32 bit platforms, compiler hints is a smi. |
| 5634 | static const int kCompilerHintsSmiTagSize = kSmiTagSize; |
| 5635 | static const int kCompilerHintsSize = kPointerSize; |
| 5636 | #else |
| 5637 | // On 64 bit platforms, compiler hints is not a smi, see comment above. |
| 5638 | static const int kCompilerHintsSmiTagSize = 0; |
| 5639 | static const int kCompilerHintsSize = kIntSize; |
| 5640 | #endif |
| 5641 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 5642 | STATIC_ASSERT(SharedFunctionInfo::kCompilerHintsCount <= |
| 5643 | SharedFunctionInfo::kCompilerHintsSize * kBitsPerByte); |
| 5644 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 5645 | public: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5646 | // Constants for optimizing codegen for strict mode function and |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 5647 | // native tests. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 5648 | // Allows to use byte-width instructions. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 5649 | static const int kStrictModeBitWithinByte = |
| 5650 | (kStrictModeFunction + kCompilerHintsSmiTagSize) % kBitsPerByte; |
| 5651 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 5652 | static const int kExtendedModeBitWithinByte = |
| 5653 | (kExtendedModeFunction + kCompilerHintsSmiTagSize) % kBitsPerByte; |
| 5654 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 5655 | static const int kNativeBitWithinByte = |
| 5656 | (kNative + kCompilerHintsSmiTagSize) % kBitsPerByte; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5657 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 5658 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 5659 | static const int kStrictModeByteOffset = kCompilerHintsOffset + |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5660 | (kStrictModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte; |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 5661 | static const int kExtendedModeByteOffset = kCompilerHintsOffset + |
| 5662 | (kExtendedModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 5663 | static const int kNativeByteOffset = kCompilerHintsOffset + |
| 5664 | (kNative + kCompilerHintsSmiTagSize) / kBitsPerByte; |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 5665 | #elif __BYTE_ORDER == __BIG_ENDIAN |
| 5666 | static const int kStrictModeByteOffset = kCompilerHintsOffset + |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5667 | (kCompilerHintsSize - 1) - |
| 5668 | ((kStrictModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 5669 | static const int kExtendedModeByteOffset = kCompilerHintsOffset + |
| 5670 | (kCompilerHintsSize - 1) - |
| 5671 | ((kExtendedModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 5672 | static const int kNativeByteOffset = kCompilerHintsOffset + |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5673 | (kCompilerHintsSize - 1) - |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 5674 | ((kNative + kCompilerHintsSmiTagSize) / kBitsPerByte); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 5675 | #else |
| 5676 | #error Unknown byte ordering |
| 5677 | #endif |
| 5678 | |
| 5679 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5680 | DISALLOW_IMPLICIT_CONSTRUCTORS(SharedFunctionInfo); |
| 5681 | }; |
| 5682 | |
| 5683 | |
| 5684 | // JSFunction describes JavaScript functions. |
| 5685 | class JSFunction: public JSObject { |
| 5686 | public: |
| 5687 | // [prototype_or_initial_map]: |
| 5688 | DECL_ACCESSORS(prototype_or_initial_map, Object) |
| 5689 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 5690 | // [shared]: The information about the function that |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5691 | // can be shared by instances. |
| 5692 | DECL_ACCESSORS(shared, SharedFunctionInfo) |
| 5693 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 5694 | inline SharedFunctionInfo* unchecked_shared(); |
| 5695 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5696 | // [context]: The context for this function. |
| 5697 | inline Context* context(); |
| 5698 | inline Object* unchecked_context(); |
| 5699 | inline void set_context(Object* context); |
| 5700 | |
| 5701 | // [code]: The generated code object for this function. Executed |
| 5702 | // when the function is invoked, e.g. foo() or new foo(). See |
| 5703 | // [[Call]] and [[Construct]] description in ECMA-262, section |
| 5704 | // 8.6.2, page 27. |
| 5705 | inline Code* code(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5706 | inline void set_code(Code* code); |
| 5707 | inline void ReplaceCode(Code* code); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5708 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 5709 | inline Code* unchecked_code(); |
| 5710 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5711 | // Tells whether this function is builtin. |
| 5712 | inline bool IsBuiltin(); |
| 5713 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5714 | // Tells whether or not the function needs arguments adaption. |
| 5715 | inline bool NeedsArgumentsAdaption(); |
| 5716 | |
| 5717 | // Tells whether or not this function has been optimized. |
| 5718 | inline bool IsOptimized(); |
| 5719 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 5720 | // Tells whether or not this function can be optimized. |
| 5721 | inline bool IsOptimizable(); |
| 5722 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5723 | // Mark this function for lazy recompilation. The function will be |
| 5724 | // recompiled the next time it is executed. |
| 5725 | void MarkForLazyRecompilation(); |
| 5726 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 5727 | // Helpers to compile this function. Returns true on success, false on |
| 5728 | // failure (e.g., stack overflow during compilation). |
| 5729 | static bool CompileLazy(Handle<JSFunction> function, |
| 5730 | ClearExceptionFlag flag); |
| 5731 | static bool CompileOptimized(Handle<JSFunction> function, |
| 5732 | int osr_ast_id, |
| 5733 | ClearExceptionFlag flag); |
| 5734 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5735 | // Tells whether or not the function is already marked for lazy |
| 5736 | // recompilation. |
| 5737 | inline bool IsMarkedForLazyRecompilation(); |
| 5738 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5739 | // Check whether or not this function is inlineable. |
| 5740 | bool IsInlineable(); |
| 5741 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 5742 | // [literals_or_bindings]: Fixed array holding either |
| 5743 | // the materialized literals or the bindings of a bound function. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5744 | // |
| 5745 | // If the function contains object, regexp or array literals, the |
| 5746 | // literals array prefix contains the object, regexp, and array |
| 5747 | // function to be used when creating these literals. This is |
| 5748 | // necessary so that we do not dynamically lookup the object, regexp |
| 5749 | // or array functions. Performing a dynamic lookup, we might end up |
| 5750 | // using the functions from a new context that we should not have |
| 5751 | // access to. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 5752 | // |
| 5753 | // On bound functions, the array is a (copy-on-write) fixed-array containing |
| 5754 | // the function that was bound, bound this-value and any bound |
| 5755 | // arguments. Bound functions never contain literals. |
| 5756 | DECL_ACCESSORS(literals_or_bindings, FixedArray) |
| 5757 | |
| 5758 | inline FixedArray* literals(); |
| 5759 | inline void set_literals(FixedArray* literals); |
| 5760 | |
| 5761 | inline FixedArray* function_bindings(); |
| 5762 | inline void set_function_bindings(FixedArray* bindings); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5763 | |
| 5764 | // The initial map for an object created by this constructor. |
| 5765 | inline Map* initial_map(); |
| 5766 | inline void set_initial_map(Map* value); |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 5767 | MUST_USE_RESULT inline MaybeObject* set_initial_map_and_cache_transitions( |
| 5768 | Map* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5769 | inline bool has_initial_map(); |
| 5770 | |
| 5771 | // Get and set the prototype property on a JSFunction. If the |
| 5772 | // function has an initial map the prototype is set on the initial |
| 5773 | // map. Otherwise, the prototype is put in the initial map field |
| 5774 | // until an initial map is needed. |
| 5775 | inline bool has_prototype(); |
| 5776 | inline bool has_instance_prototype(); |
| 5777 | inline Object* prototype(); |
| 5778 | inline Object* instance_prototype(); |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 5779 | MUST_USE_RESULT MaybeObject* SetInstancePrototype(Object* value); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 5780 | MUST_USE_RESULT MaybeObject* SetPrototype(Object* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5781 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5782 | // After prototype is removed, it will not be created when accessed, and |
| 5783 | // [[Construct]] from this function will not be allowed. |
| 5784 | Object* RemovePrototype(); |
| 5785 | inline bool should_have_prototype(); |
| 5786 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5787 | // Accessor for this function's initial map's [[class]] |
| 5788 | // property. This is primarily used by ECMA native functions. This |
| 5789 | // method sets the class_name field of this function's initial map |
| 5790 | // to a given value. It creates an initial map if this function does |
| 5791 | // not have one. Note that this method does not copy the initial map |
| 5792 | // if it has one already, but simply replaces it with the new value. |
| 5793 | // Instances created afterwards will have a map whose [[class]] is |
| 5794 | // set to 'value', but there is no guarantees on instances created |
| 5795 | // before. |
| 5796 | Object* SetInstanceClassName(String* name); |
| 5797 | |
| 5798 | // Returns if this function has been compiled to native code yet. |
| 5799 | inline bool is_compiled(); |
| 5800 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5801 | // [next_function_link]: Field for linking functions. This list is treated as |
| 5802 | // a weak list by the GC. |
| 5803 | DECL_ACCESSORS(next_function_link, Object) |
| 5804 | |
| 5805 | // Prints the name of the function using PrintF. |
| 5806 | inline void PrintName() { |
| 5807 | PrintName(stdout); |
| 5808 | } |
| 5809 | void PrintName(FILE* out); |
| 5810 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5811 | // Casting. |
| 5812 | static inline JSFunction* cast(Object* obj); |
| 5813 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 5814 | // Iterates the objects, including code objects indirectly referenced |
| 5815 | // through pointers to the first instruction in the code object. |
| 5816 | void JSFunctionIterateBody(int object_size, ObjectVisitor* v); |
| 5817 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5818 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5819 | #ifdef OBJECT_PRINT |
| 5820 | inline void JSFunctionPrint() { |
| 5821 | JSFunctionPrint(stdout); |
| 5822 | } |
| 5823 | void JSFunctionPrint(FILE* out); |
| 5824 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5825 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5826 | void JSFunctionVerify(); |
| 5827 | #endif |
| 5828 | |
| 5829 | // Returns the number of allocated literals. |
| 5830 | inline int NumberOfLiterals(); |
| 5831 | |
| 5832 | // Retrieve the global context from a function's literal array. |
| 5833 | static Context* GlobalContextFromLiterals(FixedArray* literals); |
| 5834 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5835 | // Layout descriptors. The last property (from kNonWeakFieldsEndOffset to |
| 5836 | // kSize) is weak and has special handling during garbage collection. |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 5837 | static const int kCodeEntryOffset = JSObject::kHeaderSize; |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 5838 | static const int kPrototypeOrInitialMapOffset = |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 5839 | kCodeEntryOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5840 | static const int kSharedFunctionInfoOffset = |
| 5841 | kPrototypeOrInitialMapOffset + kPointerSize; |
| 5842 | static const int kContextOffset = kSharedFunctionInfoOffset + kPointerSize; |
| 5843 | static const int kLiteralsOffset = kContextOffset + kPointerSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5844 | static const int kNonWeakFieldsEndOffset = kLiteralsOffset + kPointerSize; |
| 5845 | static const int kNextFunctionLinkOffset = kNonWeakFieldsEndOffset; |
| 5846 | static const int kSize = kNextFunctionLinkOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5847 | |
| 5848 | // Layout of the literals array. |
| 5849 | static const int kLiteralsPrefixSize = 1; |
| 5850 | static const int kLiteralGlobalContextIndex = 0; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 5851 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 5852 | // Layout of the bound-function binding array. |
| 5853 | static const int kBoundFunctionIndex = 0; |
| 5854 | static const int kBoundThisIndex = 1; |
| 5855 | static const int kBoundArgumentsStartIndex = 2; |
| 5856 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5857 | private: |
| 5858 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunction); |
| 5859 | }; |
| 5860 | |
| 5861 | |
| 5862 | // JSGlobalProxy's prototype must be a JSGlobalObject or null, |
| 5863 | // and the prototype is hidden. JSGlobalProxy always delegates |
| 5864 | // property accesses to its prototype if the prototype is not null. |
| 5865 | // |
| 5866 | // A JSGlobalProxy can be reinitialized which will preserve its identity. |
| 5867 | // |
| 5868 | // Accessing a JSGlobalProxy requires security check. |
| 5869 | |
| 5870 | class JSGlobalProxy : public JSObject { |
| 5871 | public: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5872 | // [context]: the owner global context of this global proxy object. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5873 | // It is null value if this object is not used by any context. |
| 5874 | DECL_ACCESSORS(context, Object) |
| 5875 | |
| 5876 | // Casting. |
| 5877 | static inline JSGlobalProxy* cast(Object* obj); |
| 5878 | |
| 5879 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5880 | #ifdef OBJECT_PRINT |
| 5881 | inline void JSGlobalProxyPrint() { |
| 5882 | JSGlobalProxyPrint(stdout); |
| 5883 | } |
| 5884 | void JSGlobalProxyPrint(FILE* out); |
| 5885 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5886 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5887 | void JSGlobalProxyVerify(); |
| 5888 | #endif |
| 5889 | |
| 5890 | // Layout description. |
| 5891 | static const int kContextOffset = JSObject::kHeaderSize; |
| 5892 | static const int kSize = kContextOffset + kPointerSize; |
| 5893 | |
| 5894 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5895 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalProxy); |
| 5896 | }; |
| 5897 | |
| 5898 | |
| 5899 | // Forward declaration. |
| 5900 | class JSBuiltinsObject; |
| 5901 | |
| 5902 | // Common super class for JavaScript global objects and the special |
| 5903 | // builtins global objects. |
| 5904 | class GlobalObject: public JSObject { |
| 5905 | public: |
| 5906 | // [builtins]: the object holding the runtime routines written in JS. |
| 5907 | DECL_ACCESSORS(builtins, JSBuiltinsObject) |
| 5908 | |
| 5909 | // [global context]: the global context corresponding to this global object. |
| 5910 | DECL_ACCESSORS(global_context, Context) |
| 5911 | |
| 5912 | // [global receiver]: the global receiver object of the context |
| 5913 | DECL_ACCESSORS(global_receiver, JSObject) |
| 5914 | |
| 5915 | // Retrieve the property cell used to store a property. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5916 | JSGlobalPropertyCell* GetPropertyCell(LookupResult* result); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5917 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 5918 | // This is like GetProperty, but is used when you know the lookup won't fail |
| 5919 | // by throwing an exception. This is for the debug and builtins global |
| 5920 | // objects, where it is known which properties can be expected to be present |
| 5921 | // on the object. |
| 5922 | Object* GetPropertyNoExceptionThrown(String* key) { |
| 5923 | Object* answer = GetProperty(key)->ToObjectUnchecked(); |
| 5924 | return answer; |
| 5925 | } |
| 5926 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5927 | // Ensure that the global object has a cell for the given property name. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 5928 | static Handle<JSGlobalPropertyCell> EnsurePropertyCell( |
| 5929 | Handle<GlobalObject> global, |
| 5930 | Handle<String> name); |
| 5931 | // TODO(kmillikin): This function can be eliminated once the stub cache is |
| 5932 | // full handlified (and the static helper can be written directly). |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 5933 | MUST_USE_RESULT MaybeObject* EnsurePropertyCell(String* name); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5934 | |
| 5935 | // Casting. |
| 5936 | static inline GlobalObject* cast(Object* obj); |
| 5937 | |
| 5938 | // Layout description. |
| 5939 | static const int kBuiltinsOffset = JSObject::kHeaderSize; |
| 5940 | static const int kGlobalContextOffset = kBuiltinsOffset + kPointerSize; |
| 5941 | static const int kGlobalReceiverOffset = kGlobalContextOffset + kPointerSize; |
| 5942 | static const int kHeaderSize = kGlobalReceiverOffset + kPointerSize; |
| 5943 | |
| 5944 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5945 | DISALLOW_IMPLICIT_CONSTRUCTORS(GlobalObject); |
| 5946 | }; |
| 5947 | |
| 5948 | |
| 5949 | // JavaScript global object. |
| 5950 | class JSGlobalObject: public GlobalObject { |
| 5951 | public: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5952 | // Casting. |
| 5953 | static inline JSGlobalObject* cast(Object* obj); |
| 5954 | |
| 5955 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5956 | #ifdef OBJECT_PRINT |
| 5957 | inline void JSGlobalObjectPrint() { |
| 5958 | JSGlobalObjectPrint(stdout); |
| 5959 | } |
| 5960 | void JSGlobalObjectPrint(FILE* out); |
| 5961 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5962 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5963 | void JSGlobalObjectVerify(); |
| 5964 | #endif |
| 5965 | |
| 5966 | // Layout description. |
| 5967 | static const int kSize = GlobalObject::kHeaderSize; |
| 5968 | |
| 5969 | private: |
| 5970 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalObject); |
| 5971 | }; |
| 5972 | |
| 5973 | |
| 5974 | // Builtins global object which holds the runtime routines written in |
| 5975 | // JavaScript. |
| 5976 | class JSBuiltinsObject: public GlobalObject { |
| 5977 | public: |
| 5978 | // Accessors for the runtime routines written in JavaScript. |
| 5979 | inline Object* javascript_builtin(Builtins::JavaScript id); |
| 5980 | inline void set_javascript_builtin(Builtins::JavaScript id, Object* value); |
| 5981 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5982 | // Accessors for code of the runtime routines written in JavaScript. |
| 5983 | inline Code* javascript_builtin_code(Builtins::JavaScript id); |
| 5984 | inline void set_javascript_builtin_code(Builtins::JavaScript id, Code* value); |
| 5985 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5986 | // Casting. |
| 5987 | static inline JSBuiltinsObject* cast(Object* obj); |
| 5988 | |
| 5989 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5990 | #ifdef OBJECT_PRINT |
| 5991 | inline void JSBuiltinsObjectPrint() { |
| 5992 | JSBuiltinsObjectPrint(stdout); |
| 5993 | } |
| 5994 | void JSBuiltinsObjectPrint(FILE* out); |
| 5995 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5996 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5997 | void JSBuiltinsObjectVerify(); |
| 5998 | #endif |
| 5999 | |
| 6000 | // Layout description. The size of the builtins object includes |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 6001 | // room for two pointers per runtime routine written in javascript |
| 6002 | // (function and code object). |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6003 | static const int kJSBuiltinsCount = Builtins::id_count; |
| 6004 | static const int kJSBuiltinsOffset = GlobalObject::kHeaderSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 6005 | static const int kJSBuiltinsCodeOffset = |
| 6006 | GlobalObject::kHeaderSize + (kJSBuiltinsCount * kPointerSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6007 | static const int kSize = |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 6008 | kJSBuiltinsCodeOffset + (kJSBuiltinsCount * kPointerSize); |
| 6009 | |
| 6010 | static int OffsetOfFunctionWithId(Builtins::JavaScript id) { |
| 6011 | return kJSBuiltinsOffset + id * kPointerSize; |
| 6012 | } |
| 6013 | |
| 6014 | static int OffsetOfCodeWithId(Builtins::JavaScript id) { |
| 6015 | return kJSBuiltinsCodeOffset + id * kPointerSize; |
| 6016 | } |
| 6017 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6018 | private: |
| 6019 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSBuiltinsObject); |
| 6020 | }; |
| 6021 | |
| 6022 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 6023 | // Representation for JS Wrapper objects, String, Number, Boolean, etc. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6024 | class JSValue: public JSObject { |
| 6025 | public: |
| 6026 | // [value]: the object being wrapped. |
| 6027 | DECL_ACCESSORS(value, Object) |
| 6028 | |
| 6029 | // Casting. |
| 6030 | static inline JSValue* cast(Object* obj); |
| 6031 | |
| 6032 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6033 | #ifdef OBJECT_PRINT |
| 6034 | inline void JSValuePrint() { |
| 6035 | JSValuePrint(stdout); |
| 6036 | } |
| 6037 | void JSValuePrint(FILE* out); |
| 6038 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6039 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6040 | void JSValueVerify(); |
| 6041 | #endif |
| 6042 | |
| 6043 | // Layout description. |
| 6044 | static const int kValueOffset = JSObject::kHeaderSize; |
| 6045 | static const int kSize = kValueOffset + kPointerSize; |
| 6046 | |
| 6047 | private: |
| 6048 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSValue); |
| 6049 | }; |
| 6050 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 6051 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 6052 | class DateCache; |
| 6053 | |
| 6054 | // Representation for JS date objects. |
| 6055 | class JSDate: public JSObject { |
| 6056 | public: |
| 6057 | // If one component is NaN, all of them are, indicating a NaN time value. |
| 6058 | // [value]: the time value. |
| 6059 | DECL_ACCESSORS(value, Object) |
| 6060 | // [year]: caches year. Either undefined, smi, or NaN. |
| 6061 | DECL_ACCESSORS(year, Object) |
| 6062 | // [month]: caches month. Either undefined, smi, or NaN. |
| 6063 | DECL_ACCESSORS(month, Object) |
| 6064 | // [day]: caches day. Either undefined, smi, or NaN. |
| 6065 | DECL_ACCESSORS(day, Object) |
| 6066 | // [weekday]: caches day of week. Either undefined, smi, or NaN. |
| 6067 | DECL_ACCESSORS(weekday, Object) |
| 6068 | // [hour]: caches hours. Either undefined, smi, or NaN. |
| 6069 | DECL_ACCESSORS(hour, Object) |
| 6070 | // [min]: caches minutes. Either undefined, smi, or NaN. |
| 6071 | DECL_ACCESSORS(min, Object) |
| 6072 | // [sec]: caches seconds. Either undefined, smi, or NaN. |
| 6073 | DECL_ACCESSORS(sec, Object) |
| 6074 | // [cache stamp]: sample of the date cache stamp at the |
| 6075 | // moment when local fields were cached. |
| 6076 | DECL_ACCESSORS(cache_stamp, Object) |
| 6077 | |
| 6078 | // Casting. |
| 6079 | static inline JSDate* cast(Object* obj); |
| 6080 | |
| 6081 | // Returns the date field with the specified index. |
| 6082 | // See FieldIndex for the list of date fields. |
| 6083 | static MaybeObject* GetField(Object* date, Smi* index); |
| 6084 | |
| 6085 | void SetValue(Object* value, bool is_value_nan); |
| 6086 | |
| 6087 | |
| 6088 | // Dispatched behavior. |
| 6089 | #ifdef OBJECT_PRINT |
| 6090 | inline void JSDatePrint() { |
| 6091 | JSDatePrint(stdout); |
| 6092 | } |
| 6093 | void JSDatePrint(FILE* out); |
| 6094 | #endif |
| 6095 | #ifdef DEBUG |
| 6096 | void JSDateVerify(); |
| 6097 | #endif |
| 6098 | // The order is important. It must be kept in sync with date macros |
| 6099 | // in macros.py. |
| 6100 | enum FieldIndex { |
| 6101 | kDateValue, |
| 6102 | kYear, |
| 6103 | kMonth, |
| 6104 | kDay, |
| 6105 | kWeekday, |
| 6106 | kHour, |
| 6107 | kMinute, |
| 6108 | kSecond, |
| 6109 | kFirstUncachedField, |
| 6110 | kMillisecond = kFirstUncachedField, |
| 6111 | kDays, |
| 6112 | kTimeInDay, |
| 6113 | kFirstUTCField, |
| 6114 | kYearUTC = kFirstUTCField, |
| 6115 | kMonthUTC, |
| 6116 | kDayUTC, |
| 6117 | kWeekdayUTC, |
| 6118 | kHourUTC, |
| 6119 | kMinuteUTC, |
| 6120 | kSecondUTC, |
| 6121 | kMillisecondUTC, |
| 6122 | kDaysUTC, |
| 6123 | kTimeInDayUTC, |
| 6124 | kTimezoneOffset |
| 6125 | }; |
| 6126 | |
| 6127 | // Layout description. |
| 6128 | static const int kValueOffset = JSObject::kHeaderSize; |
| 6129 | static const int kYearOffset = kValueOffset + kPointerSize; |
| 6130 | static const int kMonthOffset = kYearOffset + kPointerSize; |
| 6131 | static const int kDayOffset = kMonthOffset + kPointerSize; |
| 6132 | static const int kWeekdayOffset = kDayOffset + kPointerSize; |
| 6133 | static const int kHourOffset = kWeekdayOffset + kPointerSize; |
| 6134 | static const int kMinOffset = kHourOffset + kPointerSize; |
| 6135 | static const int kSecOffset = kMinOffset + kPointerSize; |
| 6136 | static const int kCacheStampOffset = kSecOffset + kPointerSize; |
| 6137 | static const int kSize = kCacheStampOffset + kPointerSize; |
| 6138 | |
| 6139 | private: |
| 6140 | inline Object* DoGetField(FieldIndex index); |
| 6141 | |
| 6142 | Object* GetUTCField(FieldIndex index, double value, DateCache* date_cache); |
| 6143 | |
| 6144 | // Computes and caches the cacheable fields of the date. |
| 6145 | inline void SetLocalFields(int64_t local_time_ms, DateCache* date_cache); |
| 6146 | |
| 6147 | |
| 6148 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSDate); |
| 6149 | }; |
| 6150 | |
| 6151 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 6152 | // Representation of message objects used for error reporting through |
| 6153 | // the API. The messages are formatted in JavaScript so this object is |
| 6154 | // a real JavaScript object. The information used for formatting the |
| 6155 | // error messages are not directly accessible from JavaScript to |
| 6156 | // prevent leaking information to user code called during error |
| 6157 | // formatting. |
| 6158 | class JSMessageObject: public JSObject { |
| 6159 | public: |
| 6160 | // [type]: the type of error message. |
| 6161 | DECL_ACCESSORS(type, String) |
| 6162 | |
| 6163 | // [arguments]: the arguments for formatting the error message. |
| 6164 | DECL_ACCESSORS(arguments, JSArray) |
| 6165 | |
| 6166 | // [script]: the script from which the error message originated. |
| 6167 | DECL_ACCESSORS(script, Object) |
| 6168 | |
| 6169 | // [stack_trace]: the stack trace for this error message. |
| 6170 | DECL_ACCESSORS(stack_trace, Object) |
| 6171 | |
| 6172 | // [stack_frames]: an array of stack frames for this error object. |
| 6173 | DECL_ACCESSORS(stack_frames, Object) |
| 6174 | |
| 6175 | // [start_position]: the start position in the script for the error message. |
| 6176 | inline int start_position(); |
| 6177 | inline void set_start_position(int value); |
| 6178 | |
| 6179 | // [end_position]: the end position in the script for the error message. |
| 6180 | inline int end_position(); |
| 6181 | inline void set_end_position(int value); |
| 6182 | |
| 6183 | // Casting. |
| 6184 | static inline JSMessageObject* cast(Object* obj); |
| 6185 | |
| 6186 | // Dispatched behavior. |
| 6187 | #ifdef OBJECT_PRINT |
| 6188 | inline void JSMessageObjectPrint() { |
| 6189 | JSMessageObjectPrint(stdout); |
| 6190 | } |
| 6191 | void JSMessageObjectPrint(FILE* out); |
| 6192 | #endif |
| 6193 | #ifdef DEBUG |
| 6194 | void JSMessageObjectVerify(); |
| 6195 | #endif |
| 6196 | |
| 6197 | // Layout description. |
| 6198 | static const int kTypeOffset = JSObject::kHeaderSize; |
| 6199 | static const int kArgumentsOffset = kTypeOffset + kPointerSize; |
| 6200 | static const int kScriptOffset = kArgumentsOffset + kPointerSize; |
| 6201 | static const int kStackTraceOffset = kScriptOffset + kPointerSize; |
| 6202 | static const int kStackFramesOffset = kStackTraceOffset + kPointerSize; |
| 6203 | static const int kStartPositionOffset = kStackFramesOffset + kPointerSize; |
| 6204 | static const int kEndPositionOffset = kStartPositionOffset + kPointerSize; |
| 6205 | static const int kSize = kEndPositionOffset + kPointerSize; |
| 6206 | |
| 6207 | typedef FixedBodyDescriptor<HeapObject::kMapOffset, |
| 6208 | kStackFramesOffset + kPointerSize, |
| 6209 | kSize> BodyDescriptor; |
| 6210 | }; |
| 6211 | |
| 6212 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6213 | // Regular expressions |
| 6214 | // The regular expression holds a single reference to a FixedArray in |
| 6215 | // the kDataOffset field. |
| 6216 | // The FixedArray contains the following data: |
| 6217 | // - tag : type of regexp implementation (not compiled yet, atom or irregexp) |
| 6218 | // - reference to the original source string |
| 6219 | // - reference to the original flag string |
| 6220 | // If it is an atom regexp |
| 6221 | // - a reference to a literal string to search for |
| 6222 | // If it is an irregexp regexp: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6223 | // - a reference to code for ASCII inputs (bytecode or compiled), or a smi |
| 6224 | // used for tracking the last usage (used for code flushing). |
| 6225 | // - a reference to code for UC16 inputs (bytecode or compiled), or a smi |
| 6226 | // used for tracking the last usage (used for code flushing).. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6227 | // - max number of registers used by irregexp implementations. |
| 6228 | // - number of capture registers (output values) of the regexp. |
| 6229 | class JSRegExp: public JSObject { |
| 6230 | public: |
| 6231 | // Meaning of Type: |
| 6232 | // NOT_COMPILED: Initial value. No data has been stored in the JSRegExp yet. |
| 6233 | // ATOM: A simple string to match against using an indexOf operation. |
| 6234 | // IRREGEXP: Compiled with Irregexp. |
| 6235 | // IRREGEXP_NATIVE: Compiled to native code with Irregexp. |
| 6236 | enum Type { NOT_COMPILED, ATOM, IRREGEXP }; |
| 6237 | enum Flag { NONE = 0, GLOBAL = 1, IGNORE_CASE = 2, MULTILINE = 4 }; |
| 6238 | |
| 6239 | class Flags { |
| 6240 | public: |
| 6241 | explicit Flags(uint32_t value) : value_(value) { } |
| 6242 | bool is_global() { return (value_ & GLOBAL) != 0; } |
| 6243 | bool is_ignore_case() { return (value_ & IGNORE_CASE) != 0; } |
| 6244 | bool is_multiline() { return (value_ & MULTILINE) != 0; } |
| 6245 | uint32_t value() { return value_; } |
| 6246 | private: |
| 6247 | uint32_t value_; |
| 6248 | }; |
| 6249 | |
| 6250 | DECL_ACCESSORS(data, Object) |
| 6251 | |
| 6252 | inline Type TypeTag(); |
| 6253 | inline int CaptureCount(); |
| 6254 | inline Flags GetFlags(); |
| 6255 | inline String* Pattern(); |
| 6256 | inline Object* DataAt(int index); |
| 6257 | // Set implementation data after the object has been prepared. |
| 6258 | inline void SetDataAt(int index, Object* value); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6259 | |
| 6260 | // Used during GC when flushing code or setting age. |
| 6261 | inline Object* DataAtUnchecked(int index); |
| 6262 | inline void SetDataAtUnchecked(int index, Object* value, Heap* heap); |
| 6263 | inline Type TypeTagUnchecked(); |
| 6264 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6265 | static int code_index(bool is_ascii) { |
| 6266 | if (is_ascii) { |
| 6267 | return kIrregexpASCIICodeIndex; |
| 6268 | } else { |
| 6269 | return kIrregexpUC16CodeIndex; |
| 6270 | } |
| 6271 | } |
| 6272 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6273 | static int saved_code_index(bool is_ascii) { |
| 6274 | if (is_ascii) { |
| 6275 | return kIrregexpASCIICodeSavedIndex; |
| 6276 | } else { |
| 6277 | return kIrregexpUC16CodeSavedIndex; |
| 6278 | } |
| 6279 | } |
| 6280 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6281 | static inline JSRegExp* cast(Object* obj); |
| 6282 | |
| 6283 | // Dispatched behavior. |
| 6284 | #ifdef DEBUG |
| 6285 | void JSRegExpVerify(); |
| 6286 | #endif |
| 6287 | |
| 6288 | static const int kDataOffset = JSObject::kHeaderSize; |
| 6289 | static const int kSize = kDataOffset + kPointerSize; |
| 6290 | |
| 6291 | // Indices in the data array. |
| 6292 | static const int kTagIndex = 0; |
| 6293 | static const int kSourceIndex = kTagIndex + 1; |
| 6294 | static const int kFlagsIndex = kSourceIndex + 1; |
| 6295 | static const int kDataIndex = kFlagsIndex + 1; |
| 6296 | // The data fields are used in different ways depending on the |
| 6297 | // value of the tag. |
| 6298 | // Atom regexps (literal strings). |
| 6299 | static const int kAtomPatternIndex = kDataIndex; |
| 6300 | |
| 6301 | static const int kAtomDataSize = kAtomPatternIndex + 1; |
| 6302 | |
| 6303 | // Irregexp compiled code or bytecode for ASCII. If compilation |
| 6304 | // fails, this fields hold an exception object that should be |
| 6305 | // thrown if the regexp is used again. |
| 6306 | static const int kIrregexpASCIICodeIndex = kDataIndex; |
| 6307 | // Irregexp compiled code or bytecode for UC16. If compilation |
| 6308 | // fails, this fields hold an exception object that should be |
| 6309 | // thrown if the regexp is used again. |
| 6310 | static const int kIrregexpUC16CodeIndex = kDataIndex + 1; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6311 | |
| 6312 | // Saved instance of Irregexp compiled code or bytecode for ASCII that |
| 6313 | // is a potential candidate for flushing. |
| 6314 | static const int kIrregexpASCIICodeSavedIndex = kDataIndex + 2; |
| 6315 | // Saved instance of Irregexp compiled code or bytecode for UC16 that is |
| 6316 | // a potential candidate for flushing. |
| 6317 | static const int kIrregexpUC16CodeSavedIndex = kDataIndex + 3; |
| 6318 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6319 | // Maximal number of registers used by either ASCII or UC16. |
| 6320 | // Only used to check that there is enough stack space |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6321 | static const int kIrregexpMaxRegisterCountIndex = kDataIndex + 4; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6322 | // Number of captures in the compiled regexp. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6323 | static const int kIrregexpCaptureCountIndex = kDataIndex + 5; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6324 | |
| 6325 | static const int kIrregexpDataSize = kIrregexpCaptureCountIndex + 1; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 6326 | |
| 6327 | // Offsets directly into the data fixed array. |
| 6328 | static const int kDataTagOffset = |
| 6329 | FixedArray::kHeaderSize + kTagIndex * kPointerSize; |
| 6330 | static const int kDataAsciiCodeOffset = |
| 6331 | FixedArray::kHeaderSize + kIrregexpASCIICodeIndex * kPointerSize; |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 6332 | static const int kDataUC16CodeOffset = |
| 6333 | FixedArray::kHeaderSize + kIrregexpUC16CodeIndex * kPointerSize; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 6334 | static const int kIrregexpCaptureCountOffset = |
| 6335 | FixedArray::kHeaderSize + kIrregexpCaptureCountIndex * kPointerSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 6336 | |
| 6337 | // In-object fields. |
| 6338 | static const int kSourceFieldIndex = 0; |
| 6339 | static const int kGlobalFieldIndex = 1; |
| 6340 | static const int kIgnoreCaseFieldIndex = 2; |
| 6341 | static const int kMultilineFieldIndex = 3; |
| 6342 | static const int kLastIndexFieldIndex = 4; |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 6343 | static const int kInObjectFieldCount = 5; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6344 | |
| 6345 | // The uninitialized value for a regexp code object. |
| 6346 | static const int kUninitializedValue = -1; |
| 6347 | |
| 6348 | // The compilation error value for the regexp code object. The real error |
| 6349 | // object is in the saved code field. |
| 6350 | static const int kCompilationErrorValue = -2; |
| 6351 | |
| 6352 | // When we store the sweep generation at which we moved the code from the |
| 6353 | // code index to the saved code index we mask it of to be in the [0:255] |
| 6354 | // range. |
| 6355 | static const int kCodeAgeMask = 0xff; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6356 | }; |
| 6357 | |
| 6358 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 6359 | class CompilationCacheShape : public BaseShape<HashTableKey*> { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6360 | public: |
| 6361 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
| 6362 | return key->IsMatch(value); |
| 6363 | } |
| 6364 | |
| 6365 | static inline uint32_t Hash(HashTableKey* key) { |
| 6366 | return key->Hash(); |
| 6367 | } |
| 6368 | |
| 6369 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
| 6370 | return key->HashForObject(object); |
| 6371 | } |
| 6372 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 6373 | MUST_USE_RESULT static MaybeObject* AsObject(HashTableKey* key) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6374 | return key->AsObject(); |
| 6375 | } |
| 6376 | |
| 6377 | static const int kPrefixSize = 0; |
| 6378 | static const int kEntrySize = 2; |
| 6379 | }; |
| 6380 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 6381 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6382 | class CompilationCacheTable: public HashTable<CompilationCacheShape, |
| 6383 | HashTableKey*> { |
| 6384 | public: |
| 6385 | // Find cached value for a string key, otherwise return null. |
| 6386 | Object* Lookup(String* src); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 6387 | Object* LookupEval(String* src, |
| 6388 | Context* context, |
| 6389 | LanguageMode language_mode, |
| 6390 | int scope_position); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6391 | Object* LookupRegExp(String* source, JSRegExp::Flags flags); |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 6392 | MUST_USE_RESULT MaybeObject* Put(String* src, Object* value); |
| 6393 | MUST_USE_RESULT MaybeObject* PutEval(String* src, |
| 6394 | Context* context, |
| 6395 | SharedFunctionInfo* value, |
| 6396 | int scope_position); |
| 6397 | MUST_USE_RESULT MaybeObject* PutRegExp(String* src, |
| 6398 | JSRegExp::Flags flags, |
| 6399 | FixedArray* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6400 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6401 | // Remove given value from cache. |
| 6402 | void Remove(Object* value); |
| 6403 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6404 | static inline CompilationCacheTable* cast(Object* obj); |
| 6405 | |
| 6406 | private: |
| 6407 | DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheTable); |
| 6408 | }; |
| 6409 | |
| 6410 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 6411 | class CodeCache: public Struct { |
| 6412 | public: |
| 6413 | DECL_ACCESSORS(default_cache, FixedArray) |
| 6414 | DECL_ACCESSORS(normal_type_cache, Object) |
| 6415 | |
| 6416 | // Add the code object to the cache. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 6417 | MUST_USE_RESULT MaybeObject* Update(String* name, Code* code); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 6418 | |
| 6419 | // Lookup code object in the cache. Returns code object if found and undefined |
| 6420 | // if not. |
| 6421 | Object* Lookup(String* name, Code::Flags flags); |
| 6422 | |
| 6423 | // Get the internal index of a code object in the cache. Returns -1 if the |
| 6424 | // code object is not in that cache. This index can be used to later call |
| 6425 | // RemoveByIndex. The cache cannot be modified between a call to GetIndex and |
| 6426 | // RemoveByIndex. |
| 6427 | int GetIndex(Object* name, Code* code); |
| 6428 | |
| 6429 | // Remove an object from the cache with the provided internal index. |
| 6430 | void RemoveByIndex(Object* name, Code* code, int index); |
| 6431 | |
| 6432 | static inline CodeCache* cast(Object* obj); |
| 6433 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6434 | #ifdef OBJECT_PRINT |
| 6435 | inline void CodeCachePrint() { |
| 6436 | CodeCachePrint(stdout); |
| 6437 | } |
| 6438 | void CodeCachePrint(FILE* out); |
| 6439 | #endif |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 6440 | #ifdef DEBUG |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 6441 | void CodeCacheVerify(); |
| 6442 | #endif |
| 6443 | |
| 6444 | static const int kDefaultCacheOffset = HeapObject::kHeaderSize; |
| 6445 | static const int kNormalTypeCacheOffset = |
| 6446 | kDefaultCacheOffset + kPointerSize; |
| 6447 | static const int kSize = kNormalTypeCacheOffset + kPointerSize; |
| 6448 | |
| 6449 | private: |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 6450 | MUST_USE_RESULT MaybeObject* UpdateDefaultCache(String* name, Code* code); |
| 6451 | MUST_USE_RESULT MaybeObject* UpdateNormalTypeCache(String* name, Code* code); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 6452 | Object* LookupDefaultCache(String* name, Code::Flags flags); |
| 6453 | Object* LookupNormalTypeCache(String* name, Code::Flags flags); |
| 6454 | |
| 6455 | // Code cache layout of the default cache. Elements are alternating name and |
| 6456 | // code objects for non normal load/store/call IC's. |
| 6457 | static const int kCodeCacheEntrySize = 2; |
| 6458 | static const int kCodeCacheEntryNameOffset = 0; |
| 6459 | static const int kCodeCacheEntryCodeOffset = 1; |
| 6460 | |
| 6461 | DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCache); |
| 6462 | }; |
| 6463 | |
| 6464 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 6465 | class CodeCacheHashTableShape : public BaseShape<HashTableKey*> { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 6466 | public: |
| 6467 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
| 6468 | return key->IsMatch(value); |
| 6469 | } |
| 6470 | |
| 6471 | static inline uint32_t Hash(HashTableKey* key) { |
| 6472 | return key->Hash(); |
| 6473 | } |
| 6474 | |
| 6475 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
| 6476 | return key->HashForObject(object); |
| 6477 | } |
| 6478 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 6479 | MUST_USE_RESULT static MaybeObject* AsObject(HashTableKey* key) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 6480 | return key->AsObject(); |
| 6481 | } |
| 6482 | |
| 6483 | static const int kPrefixSize = 0; |
| 6484 | static const int kEntrySize = 2; |
| 6485 | }; |
| 6486 | |
| 6487 | |
| 6488 | class CodeCacheHashTable: public HashTable<CodeCacheHashTableShape, |
| 6489 | HashTableKey*> { |
| 6490 | public: |
| 6491 | Object* Lookup(String* name, Code::Flags flags); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 6492 | MUST_USE_RESULT MaybeObject* Put(String* name, Code* code); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 6493 | |
| 6494 | int GetIndex(String* name, Code::Flags flags); |
| 6495 | void RemoveByIndex(int index); |
| 6496 | |
| 6497 | static inline CodeCacheHashTable* cast(Object* obj); |
| 6498 | |
| 6499 | // Initial size of the fixed array backing the hash table. |
| 6500 | static const int kInitialSize = 64; |
| 6501 | |
| 6502 | private: |
| 6503 | DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCacheHashTable); |
| 6504 | }; |
| 6505 | |
| 6506 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6507 | class PolymorphicCodeCache: public Struct { |
| 6508 | public: |
| 6509 | DECL_ACCESSORS(cache, Object) |
| 6510 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 6511 | static void Update(Handle<PolymorphicCodeCache> cache, |
| 6512 | MapHandleList* maps, |
| 6513 | Code::Flags flags, |
| 6514 | Handle<Code> code); |
| 6515 | |
| 6516 | MUST_USE_RESULT MaybeObject* Update(MapHandleList* maps, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6517 | Code::Flags flags, |
| 6518 | Code* code); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 6519 | |
| 6520 | // Returns an undefined value if the entry is not found. |
| 6521 | Handle<Object> Lookup(MapHandleList* maps, Code::Flags flags); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6522 | |
| 6523 | static inline PolymorphicCodeCache* cast(Object* obj); |
| 6524 | |
| 6525 | #ifdef OBJECT_PRINT |
| 6526 | inline void PolymorphicCodeCachePrint() { |
| 6527 | PolymorphicCodeCachePrint(stdout); |
| 6528 | } |
| 6529 | void PolymorphicCodeCachePrint(FILE* out); |
| 6530 | #endif |
| 6531 | #ifdef DEBUG |
| 6532 | void PolymorphicCodeCacheVerify(); |
| 6533 | #endif |
| 6534 | |
| 6535 | static const int kCacheOffset = HeapObject::kHeaderSize; |
| 6536 | static const int kSize = kCacheOffset + kPointerSize; |
| 6537 | |
| 6538 | private: |
| 6539 | DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCache); |
| 6540 | }; |
| 6541 | |
| 6542 | |
| 6543 | class PolymorphicCodeCacheHashTable |
| 6544 | : public HashTable<CodeCacheHashTableShape, HashTableKey*> { |
| 6545 | public: |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 6546 | Object* Lookup(MapHandleList* maps, int code_kind); |
| 6547 | |
| 6548 | MUST_USE_RESULT MaybeObject* Put(MapHandleList* maps, |
| 6549 | int code_kind, |
| 6550 | Code* code); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6551 | |
| 6552 | static inline PolymorphicCodeCacheHashTable* cast(Object* obj); |
| 6553 | |
| 6554 | static const int kInitialSize = 64; |
| 6555 | private: |
| 6556 | DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCacheHashTable); |
| 6557 | }; |
| 6558 | |
| 6559 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 6560 | class TypeFeedbackInfo: public Struct { |
| 6561 | public: |
| 6562 | inline int ic_total_count(); |
| 6563 | inline void set_ic_total_count(int count); |
| 6564 | |
| 6565 | inline int ic_with_typeinfo_count(); |
| 6566 | inline void set_ic_with_typeinfo_count(int count); |
| 6567 | |
| 6568 | DECL_ACCESSORS(type_feedback_cells, TypeFeedbackCells) |
| 6569 | |
| 6570 | static inline TypeFeedbackInfo* cast(Object* obj); |
| 6571 | |
| 6572 | #ifdef OBJECT_PRINT |
| 6573 | inline void TypeFeedbackInfoPrint() { |
| 6574 | TypeFeedbackInfoPrint(stdout); |
| 6575 | } |
| 6576 | void TypeFeedbackInfoPrint(FILE* out); |
| 6577 | #endif |
| 6578 | #ifdef DEBUG |
| 6579 | void TypeFeedbackInfoVerify(); |
| 6580 | #endif |
| 6581 | |
| 6582 | static const int kIcTotalCountOffset = HeapObject::kHeaderSize; |
| 6583 | static const int kIcWithTypeinfoCountOffset = |
| 6584 | kIcTotalCountOffset + kPointerSize; |
| 6585 | static const int kTypeFeedbackCellsOffset = |
| 6586 | kIcWithTypeinfoCountOffset + kPointerSize; |
| 6587 | static const int kSize = kTypeFeedbackCellsOffset + kPointerSize; |
| 6588 | |
| 6589 | private: |
| 6590 | DISALLOW_IMPLICIT_CONSTRUCTORS(TypeFeedbackInfo); |
| 6591 | }; |
| 6592 | |
| 6593 | |
| 6594 | // Representation of a slow alias as part of a non-strict arguments objects. |
| 6595 | // For fast aliases (if HasNonStrictArgumentsElements()): |
| 6596 | // - the parameter map contains an index into the context |
| 6597 | // - all attributes of the element have default values |
| 6598 | // For slow aliases (if HasDictionaryArgumentsElements()): |
| 6599 | // - the parameter map contains no fast alias mapping (i.e. the hole) |
| 6600 | // - this struct (in the slow backing store) contains an index into the context |
| 6601 | // - all attributes are available as part if the property details |
| 6602 | class AliasedArgumentsEntry: public Struct { |
| 6603 | public: |
| 6604 | inline int aliased_context_slot(); |
| 6605 | inline void set_aliased_context_slot(int count); |
| 6606 | |
| 6607 | static inline AliasedArgumentsEntry* cast(Object* obj); |
| 6608 | |
| 6609 | #ifdef OBJECT_PRINT |
| 6610 | inline void AliasedArgumentsEntryPrint() { |
| 6611 | AliasedArgumentsEntryPrint(stdout); |
| 6612 | } |
| 6613 | void AliasedArgumentsEntryPrint(FILE* out); |
| 6614 | #endif |
| 6615 | #ifdef DEBUG |
| 6616 | void AliasedArgumentsEntryVerify(); |
| 6617 | #endif |
| 6618 | |
| 6619 | static const int kAliasedContextSlot = HeapObject::kHeaderSize; |
| 6620 | static const int kSize = kAliasedContextSlot + kPointerSize; |
| 6621 | |
| 6622 | private: |
| 6623 | DISALLOW_IMPLICIT_CONSTRUCTORS(AliasedArgumentsEntry); |
| 6624 | }; |
| 6625 | |
| 6626 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6627 | enum AllowNullsFlag {ALLOW_NULLS, DISALLOW_NULLS}; |
| 6628 | enum RobustnessFlag {ROBUST_STRING_TRAVERSAL, FAST_STRING_TRAVERSAL}; |
| 6629 | |
| 6630 | |
| 6631 | class StringHasher { |
| 6632 | public: |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 6633 | explicit inline StringHasher(int length, uint32_t seed); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6634 | |
| 6635 | // Returns true if the hash of this string can be computed without |
| 6636 | // looking at the contents. |
| 6637 | inline bool has_trivial_hash(); |
| 6638 | |
| 6639 | // Add a character to the hash and update the array index calculation. |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 6640 | inline void AddCharacter(uint32_t c); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6641 | |
| 6642 | // Adds a character to the hash but does not update the array index |
| 6643 | // calculation. This can only be called when it has been verified |
| 6644 | // that the input is not an array index. |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 6645 | inline void AddCharacterNoIndex(uint32_t c); |
| 6646 | |
| 6647 | // Add a character above 0xffff as a surrogate pair. These can get into |
| 6648 | // the hasher through the routines that take a UTF-8 string and make a symbol. |
| 6649 | void AddSurrogatePair(uc32 c); |
| 6650 | void AddSurrogatePairNoIndex(uc32 c); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6651 | |
| 6652 | // Returns the value to store in the hash field of a string with |
| 6653 | // the given length and contents. |
| 6654 | uint32_t GetHashField(); |
| 6655 | |
| 6656 | // Returns true if the characters seen so far make up a legal array |
| 6657 | // index. |
| 6658 | bool is_array_index() { return is_array_index_; } |
| 6659 | |
| 6660 | bool is_valid() { return is_valid_; } |
| 6661 | |
| 6662 | void invalidate() { is_valid_ = false; } |
| 6663 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 6664 | // Calculated hash value for a string consisting of 1 to |
| 6665 | // String::kMaxArrayIndexSize digits with no leading zeros (except "0"). |
| 6666 | // value is represented decimal value. |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 6667 | static uint32_t MakeArrayIndexHash(uint32_t value, int length); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 6668 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 6669 | // No string is allowed to have a hash of zero. That value is reserved |
| 6670 | // for internal properties. If the hash calculation yields zero then we |
| 6671 | // use 27 instead. |
| 6672 | static const int kZeroHash = 27; |
| 6673 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6674 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6675 | uint32_t array_index() { |
| 6676 | ASSERT(is_array_index()); |
| 6677 | return array_index_; |
| 6678 | } |
| 6679 | |
| 6680 | inline uint32_t GetHash(); |
| 6681 | |
| 6682 | int length_; |
| 6683 | uint32_t raw_running_hash_; |
| 6684 | uint32_t array_index_; |
| 6685 | bool is_array_index_; |
| 6686 | bool is_first_char_; |
| 6687 | bool is_valid_; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6688 | friend class TwoCharHashTableKey; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6689 | }; |
| 6690 | |
| 6691 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 6692 | // Calculates string hash. |
| 6693 | template <typename schar> |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 6694 | inline uint32_t HashSequentialString(const schar* chars, |
| 6695 | int length, |
| 6696 | uint32_t seed); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 6697 | |
| 6698 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6699 | // The characteristics of a string are stored in its map. Retrieving these |
| 6700 | // few bits of information is moderately expensive, involving two memory |
| 6701 | // loads where the second is dependent on the first. To improve efficiency |
| 6702 | // the shape of the string is given its own class so that it can be retrieved |
| 6703 | // once and used for several string operations. A StringShape is small enough |
| 6704 | // to be passed by value and is immutable, but be aware that flattening a |
| 6705 | // string can potentially alter its shape. Also be aware that a GC caused by |
| 6706 | // something else can alter the shape of a string due to ConsString |
| 6707 | // shortcutting. Keeping these restrictions in mind has proven to be error- |
| 6708 | // prone and so we no longer put StringShapes in variables unless there is a |
| 6709 | // concrete performance benefit at that particular point in the code. |
| 6710 | class StringShape BASE_EMBEDDED { |
| 6711 | public: |
| 6712 | inline explicit StringShape(String* s); |
| 6713 | inline explicit StringShape(Map* s); |
| 6714 | inline explicit StringShape(InstanceType t); |
| 6715 | inline bool IsSequential(); |
| 6716 | inline bool IsExternal(); |
| 6717 | inline bool IsCons(); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 6718 | inline bool IsSliced(); |
| 6719 | inline bool IsIndirect(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6720 | inline bool IsExternalAscii(); |
| 6721 | inline bool IsExternalTwoByte(); |
| 6722 | inline bool IsSequentialAscii(); |
| 6723 | inline bool IsSequentialTwoByte(); |
| 6724 | inline bool IsSymbol(); |
| 6725 | inline StringRepresentationTag representation_tag(); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 6726 | inline uint32_t encoding_tag(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6727 | inline uint32_t full_representation_tag(); |
| 6728 | inline uint32_t size_tag(); |
| 6729 | #ifdef DEBUG |
| 6730 | inline uint32_t type() { return type_; } |
| 6731 | inline void invalidate() { valid_ = false; } |
| 6732 | inline bool valid() { return valid_; } |
| 6733 | #else |
| 6734 | inline void invalidate() { } |
| 6735 | #endif |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6736 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6737 | private: |
| 6738 | uint32_t type_; |
| 6739 | #ifdef DEBUG |
| 6740 | inline void set_valid() { valid_ = true; } |
| 6741 | bool valid_; |
| 6742 | #else |
| 6743 | inline void set_valid() { } |
| 6744 | #endif |
| 6745 | }; |
| 6746 | |
| 6747 | |
| 6748 | // The String abstract class captures JavaScript string values: |
| 6749 | // |
| 6750 | // Ecma-262: |
| 6751 | // 4.3.16 String Value |
| 6752 | // A string value is a member of the type String and is a finite |
| 6753 | // ordered sequence of zero or more 16-bit unsigned integer values. |
| 6754 | // |
| 6755 | // All string values have a length field. |
| 6756 | class String: public HeapObject { |
| 6757 | public: |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 6758 | // Representation of the flat content of a String. |
| 6759 | // A non-flat string doesn't have flat content. |
| 6760 | // A flat string has content that's encoded as a sequence of either |
| 6761 | // ASCII chars or two-byte UC16. |
| 6762 | // Returned by String::GetFlatContent(). |
| 6763 | class FlatContent { |
| 6764 | public: |
| 6765 | // Returns true if the string is flat and this structure contains content. |
| 6766 | bool IsFlat() { return state_ != NON_FLAT; } |
| 6767 | // Returns true if the structure contains ASCII content. |
| 6768 | bool IsAscii() { return state_ == ASCII; } |
| 6769 | // Returns true if the structure contains two-byte content. |
| 6770 | bool IsTwoByte() { return state_ == TWO_BYTE; } |
| 6771 | |
| 6772 | // Return the ASCII content of the string. Only use if IsAscii() returns |
| 6773 | // true. |
| 6774 | Vector<const char> ToAsciiVector() { |
| 6775 | ASSERT_EQ(ASCII, state_); |
| 6776 | return Vector<const char>::cast(buffer_); |
| 6777 | } |
| 6778 | // Return the two-byte content of the string. Only use if IsTwoByte() |
| 6779 | // returns true. |
| 6780 | Vector<const uc16> ToUC16Vector() { |
| 6781 | ASSERT_EQ(TWO_BYTE, state_); |
| 6782 | return Vector<const uc16>::cast(buffer_); |
| 6783 | } |
| 6784 | |
| 6785 | private: |
| 6786 | enum State { NON_FLAT, ASCII, TWO_BYTE }; |
| 6787 | |
| 6788 | // Constructors only used by String::GetFlatContent(). |
| 6789 | explicit FlatContent(Vector<const char> chars) |
| 6790 | : buffer_(Vector<const byte>::cast(chars)), |
| 6791 | state_(ASCII) { } |
| 6792 | explicit FlatContent(Vector<const uc16> chars) |
| 6793 | : buffer_(Vector<const byte>::cast(chars)), |
| 6794 | state_(TWO_BYTE) { } |
| 6795 | FlatContent() : buffer_(), state_(NON_FLAT) { } |
| 6796 | |
| 6797 | Vector<const byte> buffer_; |
| 6798 | State state_; |
| 6799 | |
| 6800 | friend class String; |
| 6801 | }; |
| 6802 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6803 | // Get and set the length of the string. |
| 6804 | inline int length(); |
| 6805 | inline void set_length(int value); |
| 6806 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6807 | // Get and set the hash field of the string. |
| 6808 | inline uint32_t hash_field(); |
| 6809 | inline void set_hash_field(uint32_t value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6810 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 6811 | // Returns whether this string has only ASCII chars, i.e. all of them can |
| 6812 | // be ASCII encoded. This might be the case even if the string is |
| 6813 | // two-byte. Such strings may appear when the embedder prefers |
| 6814 | // two-byte external representations even for ASCII data. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6815 | inline bool IsAsciiRepresentation(); |
| 6816 | inline bool IsTwoByteRepresentation(); |
| 6817 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 6818 | // Cons and slices have an encoding flag that may not represent the actual |
| 6819 | // encoding of the underlying string. This is taken into account here. |
| 6820 | // Requires: this->IsFlat() |
| 6821 | inline bool IsAsciiRepresentationUnderneath(); |
| 6822 | inline bool IsTwoByteRepresentationUnderneath(); |
| 6823 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 6824 | // NOTE: this should be considered only a hint. False negatives are |
| 6825 | // possible. |
| 6826 | inline bool HasOnlyAsciiChars(); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 6827 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6828 | // Get and set individual two byte chars in the string. |
| 6829 | inline void Set(int index, uint16_t value); |
| 6830 | // Get individual two byte char in the string. Repeated calls |
| 6831 | // to this method are not efficient unless the string is flat. |
| 6832 | inline uint16_t Get(int index); |
| 6833 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 6834 | // Try to flatten the string. Checks first inline to see if it is |
| 6835 | // necessary. Does nothing if the string is not a cons string. |
| 6836 | // Flattening allocates a sequential string with the same data as |
| 6837 | // the given string and mutates the cons string to a degenerate |
| 6838 | // form, where the first component is the new sequential string and |
| 6839 | // the second component is the empty string. If allocation fails, |
| 6840 | // this function returns a failure. If flattening succeeds, this |
| 6841 | // function returns the sequential string that is now the first |
| 6842 | // component of the cons string. |
| 6843 | // |
| 6844 | // Degenerate cons strings are handled specially by the garbage |
| 6845 | // collector (see IsShortcutCandidate). |
| 6846 | // |
| 6847 | // Use FlattenString from Handles.cc to flatten even in case an |
| 6848 | // allocation failure happens. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 6849 | inline MaybeObject* TryFlatten(PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6850 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 6851 | // Convenience function. Has exactly the same behavior as |
| 6852 | // TryFlatten(), except in the case of failure returns the original |
| 6853 | // string. |
| 6854 | inline String* TryFlattenGetString(PretenureFlag pretenure = NOT_TENURED); |
| 6855 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 6856 | // Tries to return the content of a flat string as a structure holding either |
| 6857 | // a flat vector of char or of uc16. |
| 6858 | // If the string isn't flat, and therefore doesn't have flat content, the |
| 6859 | // returned structure will report so, and can't provide a vector of either |
| 6860 | // kind. |
| 6861 | FlatContent GetFlatContent(); |
| 6862 | |
| 6863 | // Returns the parent of a sliced string or first part of a flat cons string. |
| 6864 | // Requires: StringShape(this).IsIndirect() && this->IsFlat() |
| 6865 | inline String* GetUnderlying(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6866 | |
| 6867 | // Mark the string as an undetectable object. It only applies to |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 6868 | // ASCII and two byte string types. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6869 | bool MarkAsUndetectable(); |
| 6870 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6871 | // Return a substring. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 6872 | MUST_USE_RESULT MaybeObject* SubString(int from, |
| 6873 | int to, |
| 6874 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6875 | |
| 6876 | // String equality operations. |
| 6877 | inline bool Equals(String* other); |
| 6878 | bool IsEqualTo(Vector<const char> str); |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 6879 | bool IsAsciiEqualTo(Vector<const char> str); |
| 6880 | bool IsTwoByteEqualTo(Vector<const uc16> str); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6881 | |
| 6882 | // Return a UTF8 representation of the string. The string is null |
| 6883 | // terminated but may optionally contain nulls. Length is returned |
| 6884 | // in length_output if length_output is not a null pointer The string |
| 6885 | // should be nearly flat, otherwise the performance of this method may |
| 6886 | // be very slow (quadratic in the length). Setting robustness_flag to |
| 6887 | // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it |
| 6888 | // handles unexpected data without causing assert failures and it does not |
| 6889 | // do any heap allocations. This is useful when printing stack traces. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 6890 | SmartArrayPointer<char> ToCString(AllowNullsFlag allow_nulls, |
| 6891 | RobustnessFlag robustness_flag, |
| 6892 | int offset, |
| 6893 | int length, |
| 6894 | int* length_output = 0); |
| 6895 | SmartArrayPointer<char> ToCString( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6896 | AllowNullsFlag allow_nulls = DISALLOW_NULLS, |
| 6897 | RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL, |
| 6898 | int* length_output = 0); |
| 6899 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6900 | // Return a 16 bit Unicode representation of the string. |
| 6901 | // The string should be nearly flat, otherwise the performance of |
| 6902 | // of this method may be very bad. Setting robustness_flag to |
| 6903 | // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it |
| 6904 | // handles unexpected data without causing assert failures and it does not |
| 6905 | // do any heap allocations. This is useful when printing stack traces. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 6906 | SmartArrayPointer<uc16> ToWideCString( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6907 | RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL); |
| 6908 | |
| 6909 | // Tells whether the hash code has been computed. |
| 6910 | inline bool HasHashCode(); |
| 6911 | |
| 6912 | // Returns a hash value used for the property table |
| 6913 | inline uint32_t Hash(); |
| 6914 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6915 | static uint32_t ComputeHashField(unibrow::CharacterStream* buffer, |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 6916 | int length, |
| 6917 | uint32_t seed); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6918 | |
| 6919 | static bool ComputeArrayIndex(unibrow::CharacterStream* buffer, |
| 6920 | uint32_t* index, |
| 6921 | int length); |
| 6922 | |
| 6923 | // Externalization. |
| 6924 | bool MakeExternal(v8::String::ExternalStringResource* resource); |
| 6925 | bool MakeExternal(v8::String::ExternalAsciiStringResource* resource); |
| 6926 | |
| 6927 | // Conversion. |
| 6928 | inline bool AsArrayIndex(uint32_t* index); |
| 6929 | |
| 6930 | // Casting. |
| 6931 | static inline String* cast(Object* obj); |
| 6932 | |
| 6933 | void PrintOn(FILE* out); |
| 6934 | |
| 6935 | // For use during stack traces. Performs rudimentary sanity check. |
| 6936 | bool LooksValid(); |
| 6937 | |
| 6938 | // Dispatched behavior. |
| 6939 | void StringShortPrint(StringStream* accumulator); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6940 | #ifdef OBJECT_PRINT |
| 6941 | inline void StringPrint() { |
| 6942 | StringPrint(stdout); |
| 6943 | } |
| 6944 | void StringPrint(FILE* out); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 6945 | |
| 6946 | char* ToAsciiArray(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6947 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6948 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6949 | void StringVerify(); |
| 6950 | #endif |
| 6951 | inline bool IsFlat(); |
| 6952 | |
| 6953 | // Layout description. |
| 6954 | static const int kLengthOffset = HeapObject::kHeaderSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 6955 | static const int kHashFieldOffset = kLengthOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 6956 | static const int kSize = kHashFieldOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6957 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6958 | // Maximum number of characters to consider when trying to convert a string |
| 6959 | // value into an array index. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6960 | static const int kMaxArrayIndexSize = 10; |
| 6961 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 6962 | // Max ASCII char code. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6963 | static const int kMaxAsciiCharCode = unibrow::Utf8::kMaxOneByteChar; |
| 6964 | static const unsigned kMaxAsciiCharCodeU = unibrow::Utf8::kMaxOneByteChar; |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 6965 | static const int kMaxUtf16CodeUnit = 0xffff; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6966 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6967 | // Mask constant for checking if a string has a computed hash code |
| 6968 | // and if it is an array index. The least significant bit indicates |
| 6969 | // whether a hash code has been computed. If the hash code has been |
| 6970 | // computed the 2nd bit tells whether the string can be used as an |
| 6971 | // array index. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 6972 | static const int kHashNotComputedMask = 1; |
| 6973 | static const int kIsNotArrayIndexMask = 1 << 1; |
| 6974 | static const int kNofHashBitFields = 2; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6975 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6976 | // Shift constant retrieving hash code from hash field. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 6977 | static const int kHashShift = kNofHashBitFields; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6978 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 6979 | // Only these bits are relevant in the hash, since the top two are shifted |
| 6980 | // out. |
| 6981 | static const uint32_t kHashBitMask = 0xffffffffu >> kHashShift; |
| 6982 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6983 | // Array index strings this short can keep their index in the hash |
| 6984 | // field. |
| 6985 | static const int kMaxCachedArrayIndexLength = 7; |
| 6986 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6987 | // For strings which are array indexes the hash value has the string length |
| 6988 | // mixed into the hash, mainly to avoid a hash value of zero which would be |
| 6989 | // the case for the string '0'. 24 bits are used for the array index value. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 6990 | static const int kArrayIndexValueBits = 24; |
| 6991 | static const int kArrayIndexLengthBits = |
| 6992 | kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields; |
| 6993 | |
| 6994 | STATIC_CHECK((kArrayIndexLengthBits > 0)); |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 6995 | STATIC_CHECK(kMaxArrayIndexSize < (1 << kArrayIndexLengthBits)); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 6996 | |
| 6997 | static const int kArrayIndexHashLengthShift = |
| 6998 | kArrayIndexValueBits + kNofHashBitFields; |
| 6999 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 7000 | static const int kArrayIndexHashMask = (1 << kArrayIndexHashLengthShift) - 1; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7001 | |
| 7002 | static const int kArrayIndexValueMask = |
| 7003 | ((1 << kArrayIndexValueBits) - 1) << kHashShift; |
| 7004 | |
| 7005 | // Check that kMaxCachedArrayIndexLength + 1 is a power of two so we |
| 7006 | // could use a mask to test if the length of string is less than or equal to |
| 7007 | // kMaxCachedArrayIndexLength. |
| 7008 | STATIC_CHECK(IS_POWER_OF_TWO(kMaxCachedArrayIndexLength + 1)); |
| 7009 | |
| 7010 | static const int kContainsCachedArrayIndexMask = |
| 7011 | (~kMaxCachedArrayIndexLength << kArrayIndexHashLengthShift) | |
| 7012 | kIsNotArrayIndexMask; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 7013 | |
| 7014 | // Value of empty hash field indicating that the hash is not computed. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7015 | static const int kEmptyHashField = |
| 7016 | kIsNotArrayIndexMask | kHashNotComputedMask; |
| 7017 | |
| 7018 | // Value of hash field containing computed hash equal to zero. |
| 7019 | static const int kZeroHash = kIsNotArrayIndexMask; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 7020 | |
| 7021 | // Maximal string length. |
| 7022 | static const int kMaxLength = (1 << (32 - 2)) - 1; |
| 7023 | |
| 7024 | // Max length for computing hash. For strings longer than this limit the |
| 7025 | // string length is used as the hash value. |
| 7026 | static const int kMaxHashCalcLength = 16383; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7027 | |
| 7028 | // Limit for truncation in short printing. |
| 7029 | static const int kMaxShortPrintLength = 1024; |
| 7030 | |
| 7031 | // Support for regular expressions. |
| 7032 | const uc16* GetTwoByteData(); |
| 7033 | const uc16* GetTwoByteData(unsigned start); |
| 7034 | |
| 7035 | // Support for StringInputBuffer |
| 7036 | static const unibrow::byte* ReadBlock(String* input, |
| 7037 | unibrow::byte* util_buffer, |
| 7038 | unsigned capacity, |
| 7039 | unsigned* remaining, |
| 7040 | unsigned* offset); |
| 7041 | static const unibrow::byte* ReadBlock(String** input, |
| 7042 | unibrow::byte* util_buffer, |
| 7043 | unsigned capacity, |
| 7044 | unsigned* remaining, |
| 7045 | unsigned* offset); |
| 7046 | |
| 7047 | // Helper function for flattening strings. |
| 7048 | template <typename sinkchar> |
| 7049 | static void WriteToFlat(String* source, |
| 7050 | sinkchar* sink, |
| 7051 | int from, |
| 7052 | int to); |
| 7053 | |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 7054 | static inline bool IsAscii(const char* chars, int length) { |
| 7055 | const char* limit = chars + length; |
| 7056 | #ifdef V8_HOST_CAN_READ_UNALIGNED |
| 7057 | ASSERT(kMaxAsciiCharCode == 0x7F); |
| 7058 | const uintptr_t non_ascii_mask = kUintptrAllBitsSet / 0xFF * 0x80; |
| 7059 | while (chars <= limit - sizeof(uintptr_t)) { |
| 7060 | if (*reinterpret_cast<const uintptr_t*>(chars) & non_ascii_mask) { |
| 7061 | return false; |
| 7062 | } |
| 7063 | chars += sizeof(uintptr_t); |
| 7064 | } |
| 7065 | #endif |
| 7066 | while (chars < limit) { |
| 7067 | if (static_cast<uint8_t>(*chars) > kMaxAsciiCharCodeU) return false; |
| 7068 | ++chars; |
| 7069 | } |
| 7070 | return true; |
| 7071 | } |
| 7072 | |
| 7073 | static inline bool IsAscii(const uc16* chars, int length) { |
| 7074 | const uc16* limit = chars + length; |
| 7075 | while (chars < limit) { |
| 7076 | if (*chars > kMaxAsciiCharCodeU) return false; |
| 7077 | ++chars; |
| 7078 | } |
| 7079 | return true; |
| 7080 | } |
| 7081 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7082 | protected: |
| 7083 | class ReadBlockBuffer { |
| 7084 | public: |
| 7085 | ReadBlockBuffer(unibrow::byte* util_buffer_, |
| 7086 | unsigned cursor_, |
| 7087 | unsigned capacity_, |
| 7088 | unsigned remaining_) : |
| 7089 | util_buffer(util_buffer_), |
| 7090 | cursor(cursor_), |
| 7091 | capacity(capacity_), |
| 7092 | remaining(remaining_) { |
| 7093 | } |
| 7094 | unibrow::byte* util_buffer; |
| 7095 | unsigned cursor; |
| 7096 | unsigned capacity; |
| 7097 | unsigned remaining; |
| 7098 | }; |
| 7099 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7100 | static inline const unibrow::byte* ReadBlock(String* input, |
| 7101 | ReadBlockBuffer* buffer, |
| 7102 | unsigned* offset, |
| 7103 | unsigned max_chars); |
| 7104 | static void ReadBlockIntoBuffer(String* input, |
| 7105 | ReadBlockBuffer* buffer, |
| 7106 | unsigned* offset_ptr, |
| 7107 | unsigned max_chars); |
| 7108 | |
| 7109 | private: |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 7110 | // Try to flatten the top level ConsString that is hiding behind this |
| 7111 | // string. This is a no-op unless the string is a ConsString. Flatten |
| 7112 | // mutates the ConsString and might return a failure. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 7113 | MUST_USE_RESULT MaybeObject* SlowTryFlatten(PretenureFlag pretenure); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 7114 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7115 | static inline bool IsHashFieldComputed(uint32_t field); |
| 7116 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7117 | // Slow case of String::Equals. This implementation works on any strings |
| 7118 | // but it is most efficient on strings that are almost flat. |
| 7119 | bool SlowEquals(String* other); |
| 7120 | |
| 7121 | // Slow case of AsArrayIndex. |
| 7122 | bool SlowAsArrayIndex(uint32_t* index); |
| 7123 | |
| 7124 | // Compute and set the hash code. |
| 7125 | uint32_t ComputeAndSetHash(); |
| 7126 | |
| 7127 | DISALLOW_IMPLICIT_CONSTRUCTORS(String); |
| 7128 | }; |
| 7129 | |
| 7130 | |
| 7131 | // The SeqString abstract class captures sequential string values. |
| 7132 | class SeqString: public String { |
| 7133 | public: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7134 | // Casting. |
| 7135 | static inline SeqString* cast(Object* obj); |
| 7136 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 7137 | // Layout description. |
| 7138 | static const int kHeaderSize = String::kSize; |
| 7139 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7140 | private: |
| 7141 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqString); |
| 7142 | }; |
| 7143 | |
| 7144 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 7145 | // The AsciiString class captures sequential ASCII string objects. |
| 7146 | // Each character in the AsciiString is an ASCII character. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7147 | class SeqAsciiString: public SeqString { |
| 7148 | public: |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 7149 | static const bool kHasAsciiEncoding = true; |
| 7150 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7151 | // Dispatched behavior. |
| 7152 | inline uint16_t SeqAsciiStringGet(int index); |
| 7153 | inline void SeqAsciiStringSet(int index, uint16_t value); |
| 7154 | |
| 7155 | // Get the address of the characters in this string. |
| 7156 | inline Address GetCharsAddress(); |
| 7157 | |
| 7158 | inline char* GetChars(); |
| 7159 | |
| 7160 | // Casting |
| 7161 | static inline SeqAsciiString* cast(Object* obj); |
| 7162 | |
| 7163 | // Garbage collection support. This method is called by the |
| 7164 | // garbage collector to compute the actual size of an AsciiString |
| 7165 | // instance. |
| 7166 | inline int SeqAsciiStringSize(InstanceType instance_type); |
| 7167 | |
| 7168 | // Computes the size for an AsciiString instance of a given length. |
| 7169 | static int SizeFor(int length) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7170 | return OBJECT_POINTER_ALIGN(kHeaderSize + length * kCharSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7171 | } |
| 7172 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 7173 | // Maximal memory usage for a single sequential ASCII string. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 7174 | static const int kMaxSize = 512 * MB - 1; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 7175 | // Maximal length of a single sequential ASCII string. |
| 7176 | // Q.v. String::kMaxLength which is the maximal size of concatenated strings. |
| 7177 | static const int kMaxLength = (kMaxSize - kHeaderSize); |
| 7178 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7179 | // Support for StringInputBuffer. |
| 7180 | inline void SeqAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 7181 | unsigned* offset, |
| 7182 | unsigned chars); |
| 7183 | inline const unibrow::byte* SeqAsciiStringReadBlock(unsigned* remaining, |
| 7184 | unsigned* offset, |
| 7185 | unsigned chars); |
| 7186 | |
| 7187 | private: |
| 7188 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqAsciiString); |
| 7189 | }; |
| 7190 | |
| 7191 | |
| 7192 | // The TwoByteString class captures sequential unicode string objects. |
| 7193 | // Each character in the TwoByteString is a two-byte uint16_t. |
| 7194 | class SeqTwoByteString: public SeqString { |
| 7195 | public: |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 7196 | static const bool kHasAsciiEncoding = false; |
| 7197 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7198 | // Dispatched behavior. |
| 7199 | inline uint16_t SeqTwoByteStringGet(int index); |
| 7200 | inline void SeqTwoByteStringSet(int index, uint16_t value); |
| 7201 | |
| 7202 | // Get the address of the characters in this string. |
| 7203 | inline Address GetCharsAddress(); |
| 7204 | |
| 7205 | inline uc16* GetChars(); |
| 7206 | |
| 7207 | // For regexp code. |
| 7208 | const uint16_t* SeqTwoByteStringGetData(unsigned start); |
| 7209 | |
| 7210 | // Casting |
| 7211 | static inline SeqTwoByteString* cast(Object* obj); |
| 7212 | |
| 7213 | // Garbage collection support. This method is called by the |
| 7214 | // garbage collector to compute the actual size of a TwoByteString |
| 7215 | // instance. |
| 7216 | inline int SeqTwoByteStringSize(InstanceType instance_type); |
| 7217 | |
| 7218 | // Computes the size for a TwoByteString instance of a given length. |
| 7219 | static int SizeFor(int length) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 7220 | return OBJECT_POINTER_ALIGN(kHeaderSize + length * kShortSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7221 | } |
| 7222 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 7223 | // Maximal memory usage for a single sequential two-byte string. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 7224 | static const int kMaxSize = 512 * MB - 1; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 7225 | // Maximal length of a single sequential two-byte string. |
| 7226 | // Q.v. String::kMaxLength which is the maximal size of concatenated strings. |
| 7227 | static const int kMaxLength = (kMaxSize - kHeaderSize) / sizeof(uint16_t); |
| 7228 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7229 | // Support for StringInputBuffer. |
| 7230 | inline void SeqTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 7231 | unsigned* offset_ptr, |
| 7232 | unsigned chars); |
| 7233 | |
| 7234 | private: |
| 7235 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqTwoByteString); |
| 7236 | }; |
| 7237 | |
| 7238 | |
| 7239 | // The ConsString class describes string values built by using the |
| 7240 | // addition operator on strings. A ConsString is a pair where the |
| 7241 | // first and second components are pointers to other string values. |
| 7242 | // One or both components of a ConsString can be pointers to other |
| 7243 | // ConsStrings, creating a binary tree of ConsStrings where the leaves |
| 7244 | // are non-ConsString string values. The string value represented by |
| 7245 | // a ConsString can be obtained by concatenating the leaf string |
| 7246 | // values in a left-to-right depth-first traversal of the tree. |
| 7247 | class ConsString: public String { |
| 7248 | public: |
| 7249 | // First string of the cons cell. |
| 7250 | inline String* first(); |
| 7251 | // Doesn't check that the result is a string, even in debug mode. This is |
| 7252 | // useful during GC where the mark bits confuse the checks. |
| 7253 | inline Object* unchecked_first(); |
| 7254 | inline void set_first(String* first, |
| 7255 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| 7256 | |
| 7257 | // Second string of the cons cell. |
| 7258 | inline String* second(); |
| 7259 | // Doesn't check that the result is a string, even in debug mode. This is |
| 7260 | // useful during GC where the mark bits confuse the checks. |
| 7261 | inline Object* unchecked_second(); |
| 7262 | inline void set_second(String* second, |
| 7263 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| 7264 | |
| 7265 | // Dispatched behavior. |
| 7266 | uint16_t ConsStringGet(int index); |
| 7267 | |
| 7268 | // Casting. |
| 7269 | static inline ConsString* cast(Object* obj); |
| 7270 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7271 | // Layout description. |
| 7272 | static const int kFirstOffset = POINTER_SIZE_ALIGN(String::kSize); |
| 7273 | static const int kSecondOffset = kFirstOffset + kPointerSize; |
| 7274 | static const int kSize = kSecondOffset + kPointerSize; |
| 7275 | |
| 7276 | // Support for StringInputBuffer. |
| 7277 | inline const unibrow::byte* ConsStringReadBlock(ReadBlockBuffer* buffer, |
| 7278 | unsigned* offset_ptr, |
| 7279 | unsigned chars); |
| 7280 | inline void ConsStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 7281 | unsigned* offset_ptr, |
| 7282 | unsigned chars); |
| 7283 | |
| 7284 | // Minimum length for a cons string. |
| 7285 | static const int kMinLength = 13; |
| 7286 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 7287 | typedef FixedBodyDescriptor<kFirstOffset, kSecondOffset + kPointerSize, kSize> |
| 7288 | BodyDescriptor; |
| 7289 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 7290 | #ifdef DEBUG |
| 7291 | void ConsStringVerify(); |
| 7292 | #endif |
| 7293 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7294 | private: |
| 7295 | DISALLOW_IMPLICIT_CONSTRUCTORS(ConsString); |
| 7296 | }; |
| 7297 | |
| 7298 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 7299 | // The Sliced String class describes strings that are substrings of another |
| 7300 | // sequential string. The motivation is to save time and memory when creating |
| 7301 | // a substring. A Sliced String is described as a pointer to the parent, |
| 7302 | // the offset from the start of the parent string and the length. Using |
| 7303 | // a Sliced String therefore requires unpacking of the parent string and |
| 7304 | // adding the offset to the start address. A substring of a Sliced String |
| 7305 | // are not nested since the double indirection is simplified when creating |
| 7306 | // such a substring. |
| 7307 | // Currently missing features are: |
| 7308 | // - handling externalized parent strings |
| 7309 | // - external strings as parent |
| 7310 | // - truncating sliced string to enable otherwise unneeded parent to be GC'ed. |
| 7311 | class SlicedString: public String { |
| 7312 | public: |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 7313 | inline String* parent(); |
| 7314 | inline void set_parent(String* parent); |
| 7315 | inline int offset(); |
| 7316 | inline void set_offset(int offset); |
| 7317 | |
| 7318 | // Dispatched behavior. |
| 7319 | uint16_t SlicedStringGet(int index); |
| 7320 | |
| 7321 | // Casting. |
| 7322 | static inline SlicedString* cast(Object* obj); |
| 7323 | |
| 7324 | // Layout description. |
| 7325 | static const int kParentOffset = POINTER_SIZE_ALIGN(String::kSize); |
| 7326 | static const int kOffsetOffset = kParentOffset + kPointerSize; |
| 7327 | static const int kSize = kOffsetOffset + kPointerSize; |
| 7328 | |
| 7329 | // Support for StringInputBuffer |
| 7330 | inline const unibrow::byte* SlicedStringReadBlock(ReadBlockBuffer* buffer, |
| 7331 | unsigned* offset_ptr, |
| 7332 | unsigned chars); |
| 7333 | inline void SlicedStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 7334 | unsigned* offset_ptr, |
| 7335 | unsigned chars); |
| 7336 | // Minimum length for a sliced string. |
| 7337 | static const int kMinLength = 13; |
| 7338 | |
| 7339 | typedef FixedBodyDescriptor<kParentOffset, |
| 7340 | kOffsetOffset + kPointerSize, kSize> |
| 7341 | BodyDescriptor; |
| 7342 | |
| 7343 | #ifdef DEBUG |
| 7344 | void SlicedStringVerify(); |
| 7345 | #endif |
| 7346 | |
| 7347 | private: |
| 7348 | DISALLOW_IMPLICIT_CONSTRUCTORS(SlicedString); |
| 7349 | }; |
| 7350 | |
| 7351 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7352 | // The ExternalString class describes string values that are backed by |
| 7353 | // a string resource that lies outside the V8 heap. ExternalStrings |
| 7354 | // consist of the length field common to all strings, a pointer to the |
| 7355 | // external resource. It is important to ensure (externally) that the |
| 7356 | // resource is not deallocated while the ExternalString is live in the |
| 7357 | // V8 heap. |
| 7358 | // |
| 7359 | // The API expects that all ExternalStrings are created through the |
| 7360 | // API. Therefore, ExternalStrings should not be used internally. |
| 7361 | class ExternalString: public String { |
| 7362 | public: |
| 7363 | // Casting |
| 7364 | static inline ExternalString* cast(Object* obj); |
| 7365 | |
| 7366 | // Layout description. |
| 7367 | static const int kResourceOffset = POINTER_SIZE_ALIGN(String::kSize); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 7368 | static const int kShortSize = kResourceOffset + kPointerSize; |
| 7369 | static const int kResourceDataOffset = kResourceOffset + kPointerSize; |
| 7370 | static const int kSize = kResourceDataOffset + kPointerSize; |
| 7371 | |
| 7372 | // Return whether external string is short (data pointer is not cached). |
| 7373 | inline bool is_short(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7374 | |
| 7375 | STATIC_CHECK(kResourceOffset == Internals::kStringResourceOffset); |
| 7376 | |
| 7377 | private: |
| 7378 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalString); |
| 7379 | }; |
| 7380 | |
| 7381 | |
| 7382 | // The ExternalAsciiString class is an external string backed by an |
| 7383 | // ASCII string. |
| 7384 | class ExternalAsciiString: public ExternalString { |
| 7385 | public: |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 7386 | static const bool kHasAsciiEncoding = true; |
| 7387 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7388 | typedef v8::String::ExternalAsciiStringResource Resource; |
| 7389 | |
| 7390 | // The underlying resource. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 7391 | inline const Resource* resource(); |
| 7392 | inline void set_resource(const Resource* buffer); |
| 7393 | |
| 7394 | // Update the pointer cache to the external character array. |
| 7395 | // The cached pointer is always valid, as the external character array does = |
| 7396 | // not move during lifetime. Deserialization is the only exception, after |
| 7397 | // which the pointer cache has to be refreshed. |
| 7398 | inline void update_data_cache(); |
| 7399 | |
| 7400 | inline const char* GetChars(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7401 | |
| 7402 | // Dispatched behavior. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 7403 | inline uint16_t ExternalAsciiStringGet(int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7404 | |
| 7405 | // Casting. |
| 7406 | static inline ExternalAsciiString* cast(Object* obj); |
| 7407 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 7408 | // Garbage collection support. |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 7409 | inline void ExternalAsciiStringIterateBody(ObjectVisitor* v); |
| 7410 | |
| 7411 | template<typename StaticVisitor> |
| 7412 | inline void ExternalAsciiStringIterateBody(); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 7413 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7414 | // Support for StringInputBuffer. |
| 7415 | const unibrow::byte* ExternalAsciiStringReadBlock(unsigned* remaining, |
| 7416 | unsigned* offset, |
| 7417 | unsigned chars); |
| 7418 | inline void ExternalAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 7419 | unsigned* offset, |
| 7420 | unsigned chars); |
| 7421 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7422 | private: |
| 7423 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalAsciiString); |
| 7424 | }; |
| 7425 | |
| 7426 | |
| 7427 | // The ExternalTwoByteString class is an external string backed by a UTF-16 |
| 7428 | // encoded string. |
| 7429 | class ExternalTwoByteString: public ExternalString { |
| 7430 | public: |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 7431 | static const bool kHasAsciiEncoding = false; |
| 7432 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7433 | typedef v8::String::ExternalStringResource Resource; |
| 7434 | |
| 7435 | // The underlying string resource. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 7436 | inline const Resource* resource(); |
| 7437 | inline void set_resource(const Resource* buffer); |
| 7438 | |
| 7439 | // Update the pointer cache to the external character array. |
| 7440 | // The cached pointer is always valid, as the external character array does = |
| 7441 | // not move during lifetime. Deserialization is the only exception, after |
| 7442 | // which the pointer cache has to be refreshed. |
| 7443 | inline void update_data_cache(); |
| 7444 | |
| 7445 | inline const uint16_t* GetChars(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7446 | |
| 7447 | // Dispatched behavior. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 7448 | inline uint16_t ExternalTwoByteStringGet(int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7449 | |
| 7450 | // For regexp code. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 7451 | inline const uint16_t* ExternalTwoByteStringGetData(unsigned start); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7452 | |
| 7453 | // Casting. |
| 7454 | static inline ExternalTwoByteString* cast(Object* obj); |
| 7455 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 7456 | // Garbage collection support. |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 7457 | inline void ExternalTwoByteStringIterateBody(ObjectVisitor* v); |
| 7458 | |
| 7459 | template<typename StaticVisitor> |
| 7460 | inline void ExternalTwoByteStringIterateBody(); |
| 7461 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 7462 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7463 | // Support for StringInputBuffer. |
| 7464 | void ExternalTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 7465 | unsigned* offset_ptr, |
| 7466 | unsigned chars); |
| 7467 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7468 | private: |
| 7469 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalTwoByteString); |
| 7470 | }; |
| 7471 | |
| 7472 | |
| 7473 | // Utility superclass for stack-allocated objects that must be updated |
| 7474 | // on gc. It provides two ways for the gc to update instances, either |
| 7475 | // iterating or updating after gc. |
| 7476 | class Relocatable BASE_EMBEDDED { |
| 7477 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 7478 | explicit inline Relocatable(Isolate* isolate); |
| 7479 | inline virtual ~Relocatable(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7480 | virtual void IterateInstance(ObjectVisitor* v) { } |
| 7481 | virtual void PostGarbageCollection() { } |
| 7482 | |
| 7483 | static void PostGarbageCollectionProcessing(); |
| 7484 | static int ArchiveSpacePerThread(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7485 | static char* ArchiveState(Isolate* isolate, char* to); |
| 7486 | static char* RestoreState(Isolate* isolate, char* from); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7487 | static void Iterate(ObjectVisitor* v); |
| 7488 | static void Iterate(ObjectVisitor* v, Relocatable* top); |
| 7489 | static char* Iterate(ObjectVisitor* v, char* t); |
| 7490 | private: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 7491 | Isolate* isolate_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7492 | Relocatable* prev_; |
| 7493 | }; |
| 7494 | |
| 7495 | |
| 7496 | // A flat string reader provides random access to the contents of a |
| 7497 | // string independent of the character width of the string. The handle |
| 7498 | // must be valid as long as the reader is being used. |
| 7499 | class FlatStringReader : public Relocatable { |
| 7500 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 7501 | FlatStringReader(Isolate* isolate, Handle<String> str); |
| 7502 | FlatStringReader(Isolate* isolate, Vector<const char> input); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7503 | void PostGarbageCollection(); |
| 7504 | inline uc32 Get(int index); |
| 7505 | int length() { return length_; } |
| 7506 | private: |
| 7507 | String** str_; |
| 7508 | bool is_ascii_; |
| 7509 | int length_; |
| 7510 | const void* start_; |
| 7511 | }; |
| 7512 | |
| 7513 | |
| 7514 | // Note that StringInputBuffers are not valid across a GC! To fix this |
| 7515 | // it would have to store a String Handle instead of a String* and |
| 7516 | // AsciiStringReadBlock would have to be modified to use memcpy. |
| 7517 | // |
| 7518 | // StringInputBuffer is able to traverse any string regardless of how |
| 7519 | // deeply nested a sequence of ConsStrings it is made of. However, |
| 7520 | // performance will be better if deep strings are flattened before they |
| 7521 | // are traversed. Since flattening requires memory allocation this is |
| 7522 | // not always desirable, however (esp. in debugging situations). |
| 7523 | class StringInputBuffer: public unibrow::InputBuffer<String, String*, 1024> { |
| 7524 | public: |
| 7525 | virtual void Seek(unsigned pos); |
| 7526 | inline StringInputBuffer(): unibrow::InputBuffer<String, String*, 1024>() {} |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 7527 | explicit inline StringInputBuffer(String* backing): |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7528 | unibrow::InputBuffer<String, String*, 1024>(backing) {} |
| 7529 | }; |
| 7530 | |
| 7531 | |
| 7532 | class SafeStringInputBuffer |
| 7533 | : public unibrow::InputBuffer<String, String**, 256> { |
| 7534 | public: |
| 7535 | virtual void Seek(unsigned pos); |
| 7536 | inline SafeStringInputBuffer() |
| 7537 | : unibrow::InputBuffer<String, String**, 256>() {} |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 7538 | explicit inline SafeStringInputBuffer(String** backing) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7539 | : unibrow::InputBuffer<String, String**, 256>(backing) {} |
| 7540 | }; |
| 7541 | |
| 7542 | |
| 7543 | template <typename T> |
| 7544 | class VectorIterator { |
| 7545 | public: |
| 7546 | VectorIterator(T* d, int l) : data_(Vector<const T>(d, l)), index_(0) { } |
| 7547 | explicit VectorIterator(Vector<const T> data) : data_(data), index_(0) { } |
| 7548 | T GetNext() { return data_[index_++]; } |
| 7549 | bool has_more() { return index_ < data_.length(); } |
| 7550 | private: |
| 7551 | Vector<const T> data_; |
| 7552 | int index_; |
| 7553 | }; |
| 7554 | |
| 7555 | |
| 7556 | // The Oddball describes objects null, undefined, true, and false. |
| 7557 | class Oddball: public HeapObject { |
| 7558 | public: |
| 7559 | // [to_string]: Cached to_string computed at startup. |
| 7560 | DECL_ACCESSORS(to_string, String) |
| 7561 | |
| 7562 | // [to_number]: Cached to_number computed at startup. |
| 7563 | DECL_ACCESSORS(to_number, Object) |
| 7564 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 7565 | inline byte kind(); |
| 7566 | inline void set_kind(byte kind); |
| 7567 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7568 | // Casting. |
| 7569 | static inline Oddball* cast(Object* obj); |
| 7570 | |
| 7571 | // Dispatched behavior. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7572 | #ifdef DEBUG |
| 7573 | void OddballVerify(); |
| 7574 | #endif |
| 7575 | |
| 7576 | // Initialize the fields. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 7577 | MUST_USE_RESULT MaybeObject* Initialize(const char* to_string, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 7578 | Object* to_number, |
| 7579 | byte kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7580 | |
| 7581 | // Layout description. |
| 7582 | static const int kToStringOffset = HeapObject::kHeaderSize; |
| 7583 | static const int kToNumberOffset = kToStringOffset + kPointerSize; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 7584 | static const int kKindOffset = kToNumberOffset + kPointerSize; |
| 7585 | static const int kSize = kKindOffset + kPointerSize; |
| 7586 | |
| 7587 | static const byte kFalse = 0; |
| 7588 | static const byte kTrue = 1; |
| 7589 | static const byte kNotBooleanMask = ~1; |
| 7590 | static const byte kTheHole = 2; |
| 7591 | static const byte kNull = 3; |
| 7592 | static const byte kArgumentMarker = 4; |
| 7593 | static const byte kUndefined = 5; |
| 7594 | static const byte kOther = 6; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7595 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 7596 | typedef FixedBodyDescriptor<kToStringOffset, |
| 7597 | kToNumberOffset + kPointerSize, |
| 7598 | kSize> BodyDescriptor; |
| 7599 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7600 | private: |
| 7601 | DISALLOW_IMPLICIT_CONSTRUCTORS(Oddball); |
| 7602 | }; |
| 7603 | |
| 7604 | |
| 7605 | class JSGlobalPropertyCell: public HeapObject { |
| 7606 | public: |
| 7607 | // [value]: value of the global property. |
| 7608 | DECL_ACCESSORS(value, Object) |
| 7609 | |
| 7610 | // Casting. |
| 7611 | static inline JSGlobalPropertyCell* cast(Object* obj); |
| 7612 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7613 | #ifdef DEBUG |
| 7614 | void JSGlobalPropertyCellVerify(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7615 | #endif |
| 7616 | #ifdef OBJECT_PRINT |
| 7617 | inline void JSGlobalPropertyCellPrint() { |
| 7618 | JSGlobalPropertyCellPrint(stdout); |
| 7619 | } |
| 7620 | void JSGlobalPropertyCellPrint(FILE* out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7621 | #endif |
| 7622 | |
| 7623 | // Layout description. |
| 7624 | static const int kValueOffset = HeapObject::kHeaderSize; |
| 7625 | static const int kSize = kValueOffset + kPointerSize; |
| 7626 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 7627 | typedef FixedBodyDescriptor<kValueOffset, |
| 7628 | kValueOffset + kPointerSize, |
| 7629 | kSize> BodyDescriptor; |
| 7630 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7631 | private: |
| 7632 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalPropertyCell); |
| 7633 | }; |
| 7634 | |
| 7635 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7636 | // The JSProxy describes EcmaScript Harmony proxies |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 7637 | class JSProxy: public JSReceiver { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7638 | public: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7639 | // [handler]: The handler property. |
| 7640 | DECL_ACCESSORS(handler, Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7641 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 7642 | // [hash]: The hash code property (undefined if not initialized yet). |
| 7643 | DECL_ACCESSORS(hash, Object) |
| 7644 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7645 | // Casting. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7646 | static inline JSProxy* cast(Object* obj); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7647 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 7648 | bool HasPropertyWithHandler(String* name); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 7649 | bool HasElementWithHandler(uint32_t index); |
| 7650 | |
| 7651 | MUST_USE_RESULT MaybeObject* GetPropertyWithHandler( |
| 7652 | Object* receiver, |
| 7653 | String* name); |
| 7654 | MUST_USE_RESULT MaybeObject* GetElementWithHandler( |
| 7655 | Object* receiver, |
| 7656 | uint32_t index); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 7657 | |
| 7658 | MUST_USE_RESULT MaybeObject* SetPropertyWithHandler( |
| 7659 | String* name, |
| 7660 | Object* value, |
| 7661 | PropertyAttributes attributes, |
| 7662 | StrictModeFlag strict_mode); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 7663 | MUST_USE_RESULT MaybeObject* SetElementWithHandler( |
| 7664 | uint32_t index, |
| 7665 | Object* value, |
| 7666 | StrictModeFlag strict_mode); |
| 7667 | |
| 7668 | // If the handler defines an accessor property, invoke its setter |
| 7669 | // (or throw if only a getter exists) and set *found to true. Otherwise false. |
| 7670 | MUST_USE_RESULT MaybeObject* SetPropertyWithHandlerIfDefiningSetter( |
| 7671 | String* name, |
| 7672 | Object* value, |
| 7673 | PropertyAttributes attributes, |
| 7674 | StrictModeFlag strict_mode, |
| 7675 | bool* found); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 7676 | |
| 7677 | MUST_USE_RESULT MaybeObject* DeletePropertyWithHandler( |
| 7678 | String* name, |
| 7679 | DeleteMode mode); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 7680 | MUST_USE_RESULT MaybeObject* DeleteElementWithHandler( |
| 7681 | uint32_t index, |
| 7682 | DeleteMode mode); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 7683 | |
| 7684 | MUST_USE_RESULT PropertyAttributes GetPropertyAttributeWithHandler( |
| 7685 | JSReceiver* receiver, |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 7686 | String* name); |
| 7687 | MUST_USE_RESULT PropertyAttributes GetElementAttributeWithHandler( |
| 7688 | JSReceiver* receiver, |
| 7689 | uint32_t index); |
| 7690 | |
| 7691 | MUST_USE_RESULT MaybeObject* GetIdentityHash(CreationFlag flag); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 7692 | |
| 7693 | // Turn this into an (empty) JSObject. |
| 7694 | void Fix(); |
| 7695 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 7696 | // Initializes the body after the handler slot. |
| 7697 | inline void InitializeBody(int object_size, Object* value); |
| 7698 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 7699 | // Invoke a trap by name. If the trap does not exist on this's handler, |
| 7700 | // but derived_trap is non-NULL, invoke that instead. May cause GC. |
| 7701 | Handle<Object> CallTrap(const char* name, |
| 7702 | Handle<Object> derived_trap, |
| 7703 | int argc, |
| 7704 | Handle<Object> args[]); |
| 7705 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7706 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7707 | #ifdef OBJECT_PRINT |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7708 | inline void JSProxyPrint() { |
| 7709 | JSProxyPrint(stdout); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7710 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7711 | void JSProxyPrint(FILE* out); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7712 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7713 | #ifdef DEBUG |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7714 | void JSProxyVerify(); |
| 7715 | #endif |
| 7716 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 7717 | // Layout description. We add padding so that a proxy has the same |
| 7718 | // size as a virgin JSObject. This is essential for becoming a JSObject |
| 7719 | // upon freeze. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7720 | static const int kHandlerOffset = HeapObject::kHeaderSize; |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 7721 | static const int kHashOffset = kHandlerOffset + kPointerSize; |
| 7722 | static const int kPaddingOffset = kHashOffset + kPointerSize; |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 7723 | static const int kSize = JSObject::kHeaderSize; |
| 7724 | static const int kHeaderSize = kPaddingOffset; |
| 7725 | static const int kPaddingSize = kSize - kPaddingOffset; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 7726 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 7727 | STATIC_CHECK(kPaddingSize >= 0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7728 | |
| 7729 | typedef FixedBodyDescriptor<kHandlerOffset, |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 7730 | kPaddingOffset, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7731 | kSize> BodyDescriptor; |
| 7732 | |
| 7733 | private: |
| 7734 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSProxy); |
| 7735 | }; |
| 7736 | |
| 7737 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 7738 | class JSFunctionProxy: public JSProxy { |
| 7739 | public: |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 7740 | // [call_trap]: The call trap. |
| 7741 | DECL_ACCESSORS(call_trap, Object) |
| 7742 | |
| 7743 | // [construct_trap]: The construct trap. |
| 7744 | DECL_ACCESSORS(construct_trap, Object) |
| 7745 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 7746 | // Casting. |
| 7747 | static inline JSFunctionProxy* cast(Object* obj); |
| 7748 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 7749 | // Dispatched behavior. |
| 7750 | #ifdef OBJECT_PRINT |
| 7751 | inline void JSFunctionProxyPrint() { |
| 7752 | JSFunctionProxyPrint(stdout); |
| 7753 | } |
| 7754 | void JSFunctionProxyPrint(FILE* out); |
| 7755 | #endif |
| 7756 | #ifdef DEBUG |
| 7757 | void JSFunctionProxyVerify(); |
| 7758 | #endif |
| 7759 | |
| 7760 | // Layout description. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 7761 | static const int kCallTrapOffset = JSProxy::kPaddingOffset; |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 7762 | static const int kConstructTrapOffset = kCallTrapOffset + kPointerSize; |
| 7763 | static const int kPaddingOffset = kConstructTrapOffset + kPointerSize; |
| 7764 | static const int kSize = JSFunction::kSize; |
| 7765 | static const int kPaddingSize = kSize - kPaddingOffset; |
| 7766 | |
| 7767 | STATIC_CHECK(kPaddingSize >= 0); |
| 7768 | |
| 7769 | typedef FixedBodyDescriptor<kHandlerOffset, |
| 7770 | kConstructTrapOffset + kPointerSize, |
| 7771 | kSize> BodyDescriptor; |
| 7772 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 7773 | private: |
| 7774 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunctionProxy); |
| 7775 | }; |
| 7776 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7777 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 7778 | // The JSSet describes EcmaScript Harmony sets |
| 7779 | class JSSet: public JSObject { |
| 7780 | public: |
| 7781 | // [set]: the backing hash set containing keys. |
| 7782 | DECL_ACCESSORS(table, Object) |
| 7783 | |
| 7784 | // Casting. |
| 7785 | static inline JSSet* cast(Object* obj); |
| 7786 | |
| 7787 | #ifdef OBJECT_PRINT |
| 7788 | inline void JSSetPrint() { |
| 7789 | JSSetPrint(stdout); |
| 7790 | } |
| 7791 | void JSSetPrint(FILE* out); |
| 7792 | #endif |
| 7793 | #ifdef DEBUG |
| 7794 | void JSSetVerify(); |
| 7795 | #endif |
| 7796 | |
| 7797 | static const int kTableOffset = JSObject::kHeaderSize; |
| 7798 | static const int kSize = kTableOffset + kPointerSize; |
| 7799 | |
| 7800 | private: |
| 7801 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSSet); |
| 7802 | }; |
| 7803 | |
| 7804 | |
| 7805 | // The JSMap describes EcmaScript Harmony maps |
| 7806 | class JSMap: public JSObject { |
| 7807 | public: |
| 7808 | // [table]: the backing hash table mapping keys to values. |
| 7809 | DECL_ACCESSORS(table, Object) |
| 7810 | |
| 7811 | // Casting. |
| 7812 | static inline JSMap* cast(Object* obj); |
| 7813 | |
| 7814 | #ifdef OBJECT_PRINT |
| 7815 | inline void JSMapPrint() { |
| 7816 | JSMapPrint(stdout); |
| 7817 | } |
| 7818 | void JSMapPrint(FILE* out); |
| 7819 | #endif |
| 7820 | #ifdef DEBUG |
| 7821 | void JSMapVerify(); |
| 7822 | #endif |
| 7823 | |
| 7824 | static const int kTableOffset = JSObject::kHeaderSize; |
| 7825 | static const int kSize = kTableOffset + kPointerSize; |
| 7826 | |
| 7827 | private: |
| 7828 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSMap); |
| 7829 | }; |
| 7830 | |
| 7831 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 7832 | // The JSWeakMap describes EcmaScript Harmony weak maps |
| 7833 | class JSWeakMap: public JSObject { |
| 7834 | public: |
| 7835 | // [table]: the backing hash table mapping keys to values. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 7836 | DECL_ACCESSORS(table, Object) |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 7837 | |
| 7838 | // [next]: linked list of encountered weak maps during GC. |
| 7839 | DECL_ACCESSORS(next, Object) |
| 7840 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 7841 | // Casting. |
| 7842 | static inline JSWeakMap* cast(Object* obj); |
| 7843 | |
| 7844 | #ifdef OBJECT_PRINT |
| 7845 | inline void JSWeakMapPrint() { |
| 7846 | JSWeakMapPrint(stdout); |
| 7847 | } |
| 7848 | void JSWeakMapPrint(FILE* out); |
| 7849 | #endif |
| 7850 | #ifdef DEBUG |
| 7851 | void JSWeakMapVerify(); |
| 7852 | #endif |
| 7853 | |
| 7854 | static const int kTableOffset = JSObject::kHeaderSize; |
| 7855 | static const int kNextOffset = kTableOffset + kPointerSize; |
| 7856 | static const int kSize = kNextOffset + kPointerSize; |
| 7857 | |
| 7858 | private: |
| 7859 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSWeakMap); |
| 7860 | }; |
| 7861 | |
| 7862 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7863 | // Foreign describes objects pointing from JavaScript to C structures. |
| 7864 | // Since they cannot contain references to JS HeapObjects they can be |
| 7865 | // placed in old_data_space. |
| 7866 | class Foreign: public HeapObject { |
| 7867 | public: |
| 7868 | // [address]: field containing the address. |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 7869 | inline Address foreign_address(); |
| 7870 | inline void set_foreign_address(Address value); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7871 | |
| 7872 | // Casting. |
| 7873 | static inline Foreign* cast(Object* obj); |
| 7874 | |
| 7875 | // Dispatched behavior. |
| 7876 | inline void ForeignIterateBody(ObjectVisitor* v); |
| 7877 | |
| 7878 | template<typename StaticVisitor> |
| 7879 | inline void ForeignIterateBody(); |
| 7880 | |
| 7881 | #ifdef OBJECT_PRINT |
| 7882 | inline void ForeignPrint() { |
| 7883 | ForeignPrint(stdout); |
| 7884 | } |
| 7885 | void ForeignPrint(FILE* out); |
| 7886 | #endif |
| 7887 | #ifdef DEBUG |
| 7888 | void ForeignVerify(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7889 | #endif |
| 7890 | |
| 7891 | // Layout description. |
| 7892 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 7893 | static const int kForeignAddressOffset = HeapObject::kHeaderSize; |
| 7894 | static const int kSize = kForeignAddressOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7895 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 7896 | STATIC_CHECK(kForeignAddressOffset == Internals::kForeignAddressOffset); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7897 | |
| 7898 | private: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 7899 | DISALLOW_IMPLICIT_CONSTRUCTORS(Foreign); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7900 | }; |
| 7901 | |
| 7902 | |
| 7903 | // The JSArray describes JavaScript Arrays |
| 7904 | // Such an array can be in one of two modes: |
| 7905 | // - fast, backing storage is a FixedArray and length <= elements.length(); |
| 7906 | // Please note: push and pop can be used to grow and shrink the array. |
| 7907 | // - slow, backing storage is a HashTable with numbers as keys. |
| 7908 | class JSArray: public JSObject { |
| 7909 | public: |
| 7910 | // [length]: The length property. |
| 7911 | DECL_ACCESSORS(length, Object) |
| 7912 | |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 7913 | // Overload the length setter to skip write barrier when the length |
| 7914 | // is set to a smi. This matches the set function on FixedArray. |
| 7915 | inline void set_length(Smi* length); |
| 7916 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 7917 | MUST_USE_RESULT MaybeObject* JSArrayUpdateLengthFromIndex(uint32_t index, |
| 7918 | Object* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7919 | |
| 7920 | // Initialize the array with the given capacity. The function may |
| 7921 | // fail due to out-of-memory situations, but only if the requested |
| 7922 | // capacity is non-zero. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 7923 | MUST_USE_RESULT MaybeObject* Initialize(int capacity); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7924 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 7925 | // Initializes the array to a certain length. |
| 7926 | inline bool AllowsSetElementsLength(); |
| 7927 | MUST_USE_RESULT MaybeObject* SetElementsLength(Object* length); |
| 7928 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7929 | // Set the content of the array to the content of storage. |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 7930 | MUST_USE_RESULT inline MaybeObject* SetContent(FixedArrayBase* storage); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7931 | |
| 7932 | // Casting. |
| 7933 | static inline JSArray* cast(Object* obj); |
| 7934 | |
| 7935 | // Uses handles. Ensures that the fixed array backing the JSArray has at |
| 7936 | // least the stated size. |
| 7937 | inline void EnsureSize(int minimum_size_of_backing_fixed_array); |
| 7938 | |
| 7939 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7940 | #ifdef OBJECT_PRINT |
| 7941 | inline void JSArrayPrint() { |
| 7942 | JSArrayPrint(stdout); |
| 7943 | } |
| 7944 | void JSArrayPrint(FILE* out); |
| 7945 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7946 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7947 | void JSArrayVerify(); |
| 7948 | #endif |
| 7949 | |
| 7950 | // Number of element slots to pre-allocate for an empty array. |
| 7951 | static const int kPreallocatedArrayElements = 4; |
| 7952 | |
| 7953 | // Layout description. |
| 7954 | static const int kLengthOffset = JSObject::kHeaderSize; |
| 7955 | static const int kSize = kLengthOffset + kPointerSize; |
| 7956 | |
| 7957 | private: |
| 7958 | // Expand the fixed array backing of a fast-case JSArray to at least |
| 7959 | // the requested size. |
| 7960 | void Expand(int minimum_size_of_backing_fixed_array); |
| 7961 | |
| 7962 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSArray); |
| 7963 | }; |
| 7964 | |
| 7965 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 7966 | // JSRegExpResult is just a JSArray with a specific initial map. |
| 7967 | // This initial map adds in-object properties for "index" and "input" |
| 7968 | // properties, as assigned by RegExp.prototype.exec, which allows |
| 7969 | // faster creation of RegExp exec results. |
| 7970 | // This class just holds constants used when creating the result. |
| 7971 | // After creation the result must be treated as a JSArray in all regards. |
| 7972 | class JSRegExpResult: public JSArray { |
| 7973 | public: |
| 7974 | // Offsets of object fields. |
| 7975 | static const int kIndexOffset = JSArray::kSize; |
| 7976 | static const int kInputOffset = kIndexOffset + kPointerSize; |
| 7977 | static const int kSize = kInputOffset + kPointerSize; |
| 7978 | // Indices of in-object properties. |
| 7979 | static const int kIndexIndex = 0; |
| 7980 | static const int kInputIndex = 1; |
| 7981 | private: |
| 7982 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSRegExpResult); |
| 7983 | }; |
| 7984 | |
| 7985 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7986 | // An accessor must have a getter, but can have no setter. |
| 7987 | // |
| 7988 | // When setting a property, V8 searches accessors in prototypes. |
| 7989 | // If an accessor was found and it does not have a setter, |
| 7990 | // the request is ignored. |
| 7991 | // |
| 7992 | // If the accessor in the prototype has the READ_ONLY property attribute, then |
| 7993 | // a new value is added to the local object when the property is set. |
| 7994 | // This shadows the accessor in the prototype. |
| 7995 | class AccessorInfo: public Struct { |
| 7996 | public: |
| 7997 | DECL_ACCESSORS(getter, Object) |
| 7998 | DECL_ACCESSORS(setter, Object) |
| 7999 | DECL_ACCESSORS(data, Object) |
| 8000 | DECL_ACCESSORS(name, Object) |
| 8001 | DECL_ACCESSORS(flag, Smi) |
| 8002 | |
| 8003 | inline bool all_can_read(); |
| 8004 | inline void set_all_can_read(bool value); |
| 8005 | |
| 8006 | inline bool all_can_write(); |
| 8007 | inline void set_all_can_write(bool value); |
| 8008 | |
| 8009 | inline bool prohibits_overwriting(); |
| 8010 | inline void set_prohibits_overwriting(bool value); |
| 8011 | |
| 8012 | inline PropertyAttributes property_attributes(); |
| 8013 | inline void set_property_attributes(PropertyAttributes attributes); |
| 8014 | |
| 8015 | static inline AccessorInfo* cast(Object* obj); |
| 8016 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 8017 | #ifdef OBJECT_PRINT |
| 8018 | inline void AccessorInfoPrint() { |
| 8019 | AccessorInfoPrint(stdout); |
| 8020 | } |
| 8021 | void AccessorInfoPrint(FILE* out); |
| 8022 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8023 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8024 | void AccessorInfoVerify(); |
| 8025 | #endif |
| 8026 | |
| 8027 | static const int kGetterOffset = HeapObject::kHeaderSize; |
| 8028 | static const int kSetterOffset = kGetterOffset + kPointerSize; |
| 8029 | static const int kDataOffset = kSetterOffset + kPointerSize; |
| 8030 | static const int kNameOffset = kDataOffset + kPointerSize; |
| 8031 | static const int kFlagOffset = kNameOffset + kPointerSize; |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 8032 | static const int kSize = kFlagOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8033 | |
| 8034 | private: |
| 8035 | // Bit positions in flag. |
| 8036 | static const int kAllCanReadBit = 0; |
| 8037 | static const int kAllCanWriteBit = 1; |
| 8038 | static const int kProhibitsOverwritingBit = 2; |
| 8039 | class AttributesField: public BitField<PropertyAttributes, 3, 3> {}; |
| 8040 | |
| 8041 | DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorInfo); |
| 8042 | }; |
| 8043 | |
| 8044 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 8045 | // Support for JavaScript accessors: A pair of a getter and a setter. Each |
| 8046 | // accessor can either be |
| 8047 | // * a pointer to a JavaScript function or proxy: a real accessor |
| 8048 | // * undefined: considered an accessor by the spec, too, strangely enough |
| 8049 | // * the hole: an accessor which has not been set |
| 8050 | // * a pointer to a map: a transition used to ensure map sharing |
| 8051 | class AccessorPair: public Struct { |
| 8052 | public: |
| 8053 | DECL_ACCESSORS(getter, Object) |
| 8054 | DECL_ACCESSORS(setter, Object) |
| 8055 | |
| 8056 | static inline AccessorPair* cast(Object* obj); |
| 8057 | |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 8058 | MUST_USE_RESULT MaybeObject* CopyWithoutTransitions(); |
| 8059 | |
| 8060 | // Note: Returns undefined instead in case of a hole. |
| 8061 | Object* GetComponent(AccessorComponent component); |
| 8062 | |
| 8063 | // Set both components, skipping arguments which are a JavaScript null. |
| 8064 | void SetComponents(Object* getter, Object* setter) { |
| 8065 | if (!getter->IsNull()) set_getter(getter); |
| 8066 | if (!setter->IsNull()) set_setter(setter); |
| 8067 | } |
| 8068 | |
| 8069 | bool ContainsAccessor() { |
| 8070 | return IsJSAccessor(getter()) || IsJSAccessor(setter()); |
| 8071 | } |
| 8072 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 8073 | #ifdef OBJECT_PRINT |
| 8074 | void AccessorPairPrint(FILE* out = stdout); |
| 8075 | #endif |
| 8076 | #ifdef DEBUG |
| 8077 | void AccessorPairVerify(); |
| 8078 | #endif |
| 8079 | |
| 8080 | static const int kGetterOffset = HeapObject::kHeaderSize; |
| 8081 | static const int kSetterOffset = kGetterOffset + kPointerSize; |
| 8082 | static const int kSize = kSetterOffset + kPointerSize; |
| 8083 | |
| 8084 | private: |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame^] | 8085 | // Strangely enough, in addition to functions and harmony proxies, the spec |
| 8086 | // requires us to consider undefined as a kind of accessor, too: |
| 8087 | // var obj = {}; |
| 8088 | // Object.defineProperty(obj, "foo", {get: undefined}); |
| 8089 | // assertTrue("foo" in obj); |
| 8090 | bool IsJSAccessor(Object* obj) { |
| 8091 | return obj->IsSpecFunction() || obj->IsUndefined(); |
| 8092 | } |
| 8093 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 8094 | DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorPair); |
| 8095 | }; |
| 8096 | |
| 8097 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8098 | class AccessCheckInfo: public Struct { |
| 8099 | public: |
| 8100 | DECL_ACCESSORS(named_callback, Object) |
| 8101 | DECL_ACCESSORS(indexed_callback, Object) |
| 8102 | DECL_ACCESSORS(data, Object) |
| 8103 | |
| 8104 | static inline AccessCheckInfo* cast(Object* obj); |
| 8105 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 8106 | #ifdef OBJECT_PRINT |
| 8107 | inline void AccessCheckInfoPrint() { |
| 8108 | AccessCheckInfoPrint(stdout); |
| 8109 | } |
| 8110 | void AccessCheckInfoPrint(FILE* out); |
| 8111 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8112 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8113 | void AccessCheckInfoVerify(); |
| 8114 | #endif |
| 8115 | |
| 8116 | static const int kNamedCallbackOffset = HeapObject::kHeaderSize; |
| 8117 | static const int kIndexedCallbackOffset = kNamedCallbackOffset + kPointerSize; |
| 8118 | static const int kDataOffset = kIndexedCallbackOffset + kPointerSize; |
| 8119 | static const int kSize = kDataOffset + kPointerSize; |
| 8120 | |
| 8121 | private: |
| 8122 | DISALLOW_IMPLICIT_CONSTRUCTORS(AccessCheckInfo); |
| 8123 | }; |
| 8124 | |
| 8125 | |
| 8126 | class InterceptorInfo: public Struct { |
| 8127 | public: |
| 8128 | DECL_ACCESSORS(getter, Object) |
| 8129 | DECL_ACCESSORS(setter, Object) |
| 8130 | DECL_ACCESSORS(query, Object) |
| 8131 | DECL_ACCESSORS(deleter, Object) |
| 8132 | DECL_ACCESSORS(enumerator, Object) |
| 8133 | DECL_ACCESSORS(data, Object) |
| 8134 | |
| 8135 | static inline InterceptorInfo* cast(Object* obj); |
| 8136 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 8137 | #ifdef OBJECT_PRINT |
| 8138 | inline void InterceptorInfoPrint() { |
| 8139 | InterceptorInfoPrint(stdout); |
| 8140 | } |
| 8141 | void InterceptorInfoPrint(FILE* out); |
| 8142 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8143 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8144 | void InterceptorInfoVerify(); |
| 8145 | #endif |
| 8146 | |
| 8147 | static const int kGetterOffset = HeapObject::kHeaderSize; |
| 8148 | static const int kSetterOffset = kGetterOffset + kPointerSize; |
| 8149 | static const int kQueryOffset = kSetterOffset + kPointerSize; |
| 8150 | static const int kDeleterOffset = kQueryOffset + kPointerSize; |
| 8151 | static const int kEnumeratorOffset = kDeleterOffset + kPointerSize; |
| 8152 | static const int kDataOffset = kEnumeratorOffset + kPointerSize; |
| 8153 | static const int kSize = kDataOffset + kPointerSize; |
| 8154 | |
| 8155 | private: |
| 8156 | DISALLOW_IMPLICIT_CONSTRUCTORS(InterceptorInfo); |
| 8157 | }; |
| 8158 | |
| 8159 | |
| 8160 | class CallHandlerInfo: public Struct { |
| 8161 | public: |
| 8162 | DECL_ACCESSORS(callback, Object) |
| 8163 | DECL_ACCESSORS(data, Object) |
| 8164 | |
| 8165 | static inline CallHandlerInfo* cast(Object* obj); |
| 8166 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 8167 | #ifdef OBJECT_PRINT |
| 8168 | inline void CallHandlerInfoPrint() { |
| 8169 | CallHandlerInfoPrint(stdout); |
| 8170 | } |
| 8171 | void CallHandlerInfoPrint(FILE* out); |
| 8172 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8173 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8174 | void CallHandlerInfoVerify(); |
| 8175 | #endif |
| 8176 | |
| 8177 | static const int kCallbackOffset = HeapObject::kHeaderSize; |
| 8178 | static const int kDataOffset = kCallbackOffset + kPointerSize; |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 8179 | static const int kSize = kDataOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8180 | |
| 8181 | private: |
| 8182 | DISALLOW_IMPLICIT_CONSTRUCTORS(CallHandlerInfo); |
| 8183 | }; |
| 8184 | |
| 8185 | |
| 8186 | class TemplateInfo: public Struct { |
| 8187 | public: |
| 8188 | DECL_ACCESSORS(tag, Object) |
| 8189 | DECL_ACCESSORS(property_list, Object) |
| 8190 | |
| 8191 | #ifdef DEBUG |
| 8192 | void TemplateInfoVerify(); |
| 8193 | #endif |
| 8194 | |
| 8195 | static const int kTagOffset = HeapObject::kHeaderSize; |
| 8196 | static const int kPropertyListOffset = kTagOffset + kPointerSize; |
| 8197 | static const int kHeaderSize = kPropertyListOffset + kPointerSize; |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 8198 | |
| 8199 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8200 | DISALLOW_IMPLICIT_CONSTRUCTORS(TemplateInfo); |
| 8201 | }; |
| 8202 | |
| 8203 | |
| 8204 | class FunctionTemplateInfo: public TemplateInfo { |
| 8205 | public: |
| 8206 | DECL_ACCESSORS(serial_number, Object) |
| 8207 | DECL_ACCESSORS(call_code, Object) |
| 8208 | DECL_ACCESSORS(property_accessors, Object) |
| 8209 | DECL_ACCESSORS(prototype_template, Object) |
| 8210 | DECL_ACCESSORS(parent_template, Object) |
| 8211 | DECL_ACCESSORS(named_property_handler, Object) |
| 8212 | DECL_ACCESSORS(indexed_property_handler, Object) |
| 8213 | DECL_ACCESSORS(instance_template, Object) |
| 8214 | DECL_ACCESSORS(class_name, Object) |
| 8215 | DECL_ACCESSORS(signature, Object) |
| 8216 | DECL_ACCESSORS(instance_call_handler, Object) |
| 8217 | DECL_ACCESSORS(access_check_info, Object) |
| 8218 | DECL_ACCESSORS(flag, Smi) |
| 8219 | |
| 8220 | // Following properties use flag bits. |
| 8221 | DECL_BOOLEAN_ACCESSORS(hidden_prototype) |
| 8222 | DECL_BOOLEAN_ACCESSORS(undetectable) |
| 8223 | // If the bit is set, object instances created by this function |
| 8224 | // requires access check. |
| 8225 | DECL_BOOLEAN_ACCESSORS(needs_access_check) |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8226 | DECL_BOOLEAN_ACCESSORS(read_only_prototype) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8227 | |
| 8228 | static inline FunctionTemplateInfo* cast(Object* obj); |
| 8229 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 8230 | #ifdef OBJECT_PRINT |
| 8231 | inline void FunctionTemplateInfoPrint() { |
| 8232 | FunctionTemplateInfoPrint(stdout); |
| 8233 | } |
| 8234 | void FunctionTemplateInfoPrint(FILE* out); |
| 8235 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8236 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8237 | void FunctionTemplateInfoVerify(); |
| 8238 | #endif |
| 8239 | |
| 8240 | static const int kSerialNumberOffset = TemplateInfo::kHeaderSize; |
| 8241 | static const int kCallCodeOffset = kSerialNumberOffset + kPointerSize; |
| 8242 | static const int kPropertyAccessorsOffset = kCallCodeOffset + kPointerSize; |
| 8243 | static const int kPrototypeTemplateOffset = |
| 8244 | kPropertyAccessorsOffset + kPointerSize; |
| 8245 | static const int kParentTemplateOffset = |
| 8246 | kPrototypeTemplateOffset + kPointerSize; |
| 8247 | static const int kNamedPropertyHandlerOffset = |
| 8248 | kParentTemplateOffset + kPointerSize; |
| 8249 | static const int kIndexedPropertyHandlerOffset = |
| 8250 | kNamedPropertyHandlerOffset + kPointerSize; |
| 8251 | static const int kInstanceTemplateOffset = |
| 8252 | kIndexedPropertyHandlerOffset + kPointerSize; |
| 8253 | static const int kClassNameOffset = kInstanceTemplateOffset + kPointerSize; |
| 8254 | static const int kSignatureOffset = kClassNameOffset + kPointerSize; |
| 8255 | static const int kInstanceCallHandlerOffset = kSignatureOffset + kPointerSize; |
| 8256 | static const int kAccessCheckInfoOffset = |
| 8257 | kInstanceCallHandlerOffset + kPointerSize; |
| 8258 | static const int kFlagOffset = kAccessCheckInfoOffset + kPointerSize; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8259 | static const int kSize = kFlagOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8260 | |
| 8261 | private: |
| 8262 | // Bit position in the flag, from least significant bit position. |
| 8263 | static const int kHiddenPrototypeBit = 0; |
| 8264 | static const int kUndetectableBit = 1; |
| 8265 | static const int kNeedsAccessCheckBit = 2; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 8266 | static const int kReadOnlyPrototypeBit = 3; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8267 | |
| 8268 | DISALLOW_IMPLICIT_CONSTRUCTORS(FunctionTemplateInfo); |
| 8269 | }; |
| 8270 | |
| 8271 | |
| 8272 | class ObjectTemplateInfo: public TemplateInfo { |
| 8273 | public: |
| 8274 | DECL_ACCESSORS(constructor, Object) |
| 8275 | DECL_ACCESSORS(internal_field_count, Object) |
| 8276 | |
| 8277 | static inline ObjectTemplateInfo* cast(Object* obj); |
| 8278 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 8279 | #ifdef OBJECT_PRINT |
| 8280 | inline void ObjectTemplateInfoPrint() { |
| 8281 | ObjectTemplateInfoPrint(stdout); |
| 8282 | } |
| 8283 | void ObjectTemplateInfoPrint(FILE* out); |
| 8284 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8285 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8286 | void ObjectTemplateInfoVerify(); |
| 8287 | #endif |
| 8288 | |
| 8289 | static const int kConstructorOffset = TemplateInfo::kHeaderSize; |
| 8290 | static const int kInternalFieldCountOffset = |
| 8291 | kConstructorOffset + kPointerSize; |
| 8292 | static const int kSize = kInternalFieldCountOffset + kPointerSize; |
| 8293 | }; |
| 8294 | |
| 8295 | |
| 8296 | class SignatureInfo: public Struct { |
| 8297 | public: |
| 8298 | DECL_ACCESSORS(receiver, Object) |
| 8299 | DECL_ACCESSORS(args, Object) |
| 8300 | |
| 8301 | static inline SignatureInfo* cast(Object* obj); |
| 8302 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 8303 | #ifdef OBJECT_PRINT |
| 8304 | inline void SignatureInfoPrint() { |
| 8305 | SignatureInfoPrint(stdout); |
| 8306 | } |
| 8307 | void SignatureInfoPrint(FILE* out); |
| 8308 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8309 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8310 | void SignatureInfoVerify(); |
| 8311 | #endif |
| 8312 | |
| 8313 | static const int kReceiverOffset = Struct::kHeaderSize; |
| 8314 | static const int kArgsOffset = kReceiverOffset + kPointerSize; |
| 8315 | static const int kSize = kArgsOffset + kPointerSize; |
| 8316 | |
| 8317 | private: |
| 8318 | DISALLOW_IMPLICIT_CONSTRUCTORS(SignatureInfo); |
| 8319 | }; |
| 8320 | |
| 8321 | |
| 8322 | class TypeSwitchInfo: public Struct { |
| 8323 | public: |
| 8324 | DECL_ACCESSORS(types, Object) |
| 8325 | |
| 8326 | static inline TypeSwitchInfo* cast(Object* obj); |
| 8327 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 8328 | #ifdef OBJECT_PRINT |
| 8329 | inline void TypeSwitchInfoPrint() { |
| 8330 | TypeSwitchInfoPrint(stdout); |
| 8331 | } |
| 8332 | void TypeSwitchInfoPrint(FILE* out); |
| 8333 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8334 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8335 | void TypeSwitchInfoVerify(); |
| 8336 | #endif |
| 8337 | |
| 8338 | static const int kTypesOffset = Struct::kHeaderSize; |
| 8339 | static const int kSize = kTypesOffset + kPointerSize; |
| 8340 | }; |
| 8341 | |
| 8342 | |
| 8343 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 8344 | // The DebugInfo class holds additional information for a function being |
| 8345 | // debugged. |
| 8346 | class DebugInfo: public Struct { |
| 8347 | public: |
| 8348 | // The shared function info for the source being debugged. |
| 8349 | DECL_ACCESSORS(shared, SharedFunctionInfo) |
| 8350 | // Code object for the original code. |
| 8351 | DECL_ACCESSORS(original_code, Code) |
| 8352 | // Code object for the patched code. This code object is the code object |
| 8353 | // currently active for the function. |
| 8354 | DECL_ACCESSORS(code, Code) |
| 8355 | // Fixed array holding status information for each active break point. |
| 8356 | DECL_ACCESSORS(break_points, FixedArray) |
| 8357 | |
| 8358 | // Check if there is a break point at a code position. |
| 8359 | bool HasBreakPoint(int code_position); |
| 8360 | // Get the break point info object for a code position. |
| 8361 | Object* GetBreakPointInfo(int code_position); |
| 8362 | // Clear a break point. |
| 8363 | static void ClearBreakPoint(Handle<DebugInfo> debug_info, |
| 8364 | int code_position, |
| 8365 | Handle<Object> break_point_object); |
| 8366 | // Set a break point. |
| 8367 | static void SetBreakPoint(Handle<DebugInfo> debug_info, int code_position, |
| 8368 | int source_position, int statement_position, |
| 8369 | Handle<Object> break_point_object); |
| 8370 | // Get the break point objects for a code position. |
| 8371 | Object* GetBreakPointObjects(int code_position); |
| 8372 | // Find the break point info holding this break point object. |
| 8373 | static Object* FindBreakPointInfo(Handle<DebugInfo> debug_info, |
| 8374 | Handle<Object> break_point_object); |
| 8375 | // Get the number of break points for this function. |
| 8376 | int GetBreakPointCount(); |
| 8377 | |
| 8378 | static inline DebugInfo* cast(Object* obj); |
| 8379 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 8380 | #ifdef OBJECT_PRINT |
| 8381 | inline void DebugInfoPrint() { |
| 8382 | DebugInfoPrint(stdout); |
| 8383 | } |
| 8384 | void DebugInfoPrint(FILE* out); |
| 8385 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8386 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8387 | void DebugInfoVerify(); |
| 8388 | #endif |
| 8389 | |
| 8390 | static const int kSharedFunctionInfoIndex = Struct::kHeaderSize; |
| 8391 | static const int kOriginalCodeIndex = kSharedFunctionInfoIndex + kPointerSize; |
| 8392 | static const int kPatchedCodeIndex = kOriginalCodeIndex + kPointerSize; |
| 8393 | static const int kActiveBreakPointsCountIndex = |
| 8394 | kPatchedCodeIndex + kPointerSize; |
| 8395 | static const int kBreakPointsStateIndex = |
| 8396 | kActiveBreakPointsCountIndex + kPointerSize; |
| 8397 | static const int kSize = kBreakPointsStateIndex + kPointerSize; |
| 8398 | |
| 8399 | private: |
| 8400 | static const int kNoBreakPointInfo = -1; |
| 8401 | |
| 8402 | // Lookup the index in the break_points array for a code position. |
| 8403 | int GetBreakPointInfoIndex(int code_position); |
| 8404 | |
| 8405 | DISALLOW_IMPLICIT_CONSTRUCTORS(DebugInfo); |
| 8406 | }; |
| 8407 | |
| 8408 | |
| 8409 | // The BreakPointInfo class holds information for break points set in a |
| 8410 | // function. The DebugInfo object holds a BreakPointInfo object for each code |
| 8411 | // position with one or more break points. |
| 8412 | class BreakPointInfo: public Struct { |
| 8413 | public: |
| 8414 | // The position in the code for the break point. |
| 8415 | DECL_ACCESSORS(code_position, Smi) |
| 8416 | // The position in the source for the break position. |
| 8417 | DECL_ACCESSORS(source_position, Smi) |
| 8418 | // The position in the source for the last statement before this break |
| 8419 | // position. |
| 8420 | DECL_ACCESSORS(statement_position, Smi) |
| 8421 | // List of related JavaScript break points. |
| 8422 | DECL_ACCESSORS(break_point_objects, Object) |
| 8423 | |
| 8424 | // Removes a break point. |
| 8425 | static void ClearBreakPoint(Handle<BreakPointInfo> info, |
| 8426 | Handle<Object> break_point_object); |
| 8427 | // Set a break point. |
| 8428 | static void SetBreakPoint(Handle<BreakPointInfo> info, |
| 8429 | Handle<Object> break_point_object); |
| 8430 | // Check if break point info has this break point object. |
| 8431 | static bool HasBreakPointObject(Handle<BreakPointInfo> info, |
| 8432 | Handle<Object> break_point_object); |
| 8433 | // Get the number of break points for this code position. |
| 8434 | int GetBreakPointCount(); |
| 8435 | |
| 8436 | static inline BreakPointInfo* cast(Object* obj); |
| 8437 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 8438 | #ifdef OBJECT_PRINT |
| 8439 | inline void BreakPointInfoPrint() { |
| 8440 | BreakPointInfoPrint(stdout); |
| 8441 | } |
| 8442 | void BreakPointInfoPrint(FILE* out); |
| 8443 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8444 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8445 | void BreakPointInfoVerify(); |
| 8446 | #endif |
| 8447 | |
| 8448 | static const int kCodePositionIndex = Struct::kHeaderSize; |
| 8449 | static const int kSourcePositionIndex = kCodePositionIndex + kPointerSize; |
| 8450 | static const int kStatementPositionIndex = |
| 8451 | kSourcePositionIndex + kPointerSize; |
| 8452 | static const int kBreakPointObjectsIndex = |
| 8453 | kStatementPositionIndex + kPointerSize; |
| 8454 | static const int kSize = kBreakPointObjectsIndex + kPointerSize; |
| 8455 | |
| 8456 | private: |
| 8457 | DISALLOW_IMPLICIT_CONSTRUCTORS(BreakPointInfo); |
| 8458 | }; |
| 8459 | #endif // ENABLE_DEBUGGER_SUPPORT |
| 8460 | |
| 8461 | |
| 8462 | #undef DECL_BOOLEAN_ACCESSORS |
| 8463 | #undef DECL_ACCESSORS |
| 8464 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 8465 | #define VISITOR_SYNCHRONIZATION_TAGS_LIST(V) \ |
| 8466 | V(kSymbolTable, "symbol_table", "(Symbols)") \ |
| 8467 | V(kExternalStringsTable, "external_strings_table", "(External strings)") \ |
| 8468 | V(kStrongRootList, "strong_root_list", "(Strong roots)") \ |
| 8469 | V(kSymbol, "symbol", "(Symbol)") \ |
| 8470 | V(kBootstrapper, "bootstrapper", "(Bootstrapper)") \ |
| 8471 | V(kTop, "top", "(Isolate)") \ |
| 8472 | V(kRelocatable, "relocatable", "(Relocatable)") \ |
| 8473 | V(kDebug, "debug", "(Debugger)") \ |
| 8474 | V(kCompilationCache, "compilationcache", "(Compilation cache)") \ |
| 8475 | V(kHandleScope, "handlescope", "(Handle scope)") \ |
| 8476 | V(kBuiltins, "builtins", "(Builtins)") \ |
| 8477 | V(kGlobalHandles, "globalhandles", "(Global handles)") \ |
| 8478 | V(kThreadManager, "threadmanager", "(Thread manager)") \ |
| 8479 | V(kExtensions, "Extensions", "(Extensions)") |
| 8480 | |
| 8481 | class VisitorSynchronization : public AllStatic { |
| 8482 | public: |
| 8483 | #define DECLARE_ENUM(enum_item, ignore1, ignore2) enum_item, |
| 8484 | enum SyncTag { |
| 8485 | VISITOR_SYNCHRONIZATION_TAGS_LIST(DECLARE_ENUM) |
| 8486 | kNumberOfSyncTags |
| 8487 | }; |
| 8488 | #undef DECLARE_ENUM |
| 8489 | |
| 8490 | static const char* const kTags[kNumberOfSyncTags]; |
| 8491 | static const char* const kTagNames[kNumberOfSyncTags]; |
| 8492 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8493 | |
| 8494 | // Abstract base class for visiting, and optionally modifying, the |
| 8495 | // pointers contained in Objects. Used in GC and serialization/deserialization. |
| 8496 | class ObjectVisitor BASE_EMBEDDED { |
| 8497 | public: |
| 8498 | virtual ~ObjectVisitor() {} |
| 8499 | |
| 8500 | // Visits a contiguous arrays of pointers in the half-open range |
| 8501 | // [start, end). Any or all of the values may be modified on return. |
| 8502 | virtual void VisitPointers(Object** start, Object** end) = 0; |
| 8503 | |
| 8504 | // To allow lazy clearing of inline caches the visitor has |
| 8505 | // a rich interface for iterating over Code objects.. |
| 8506 | |
| 8507 | // Visits a code target in the instruction stream. |
| 8508 | virtual void VisitCodeTarget(RelocInfo* rinfo); |
| 8509 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 8510 | // Visits a code entry in a JS function. |
| 8511 | virtual void VisitCodeEntry(Address entry_address); |
| 8512 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 8513 | // Visits a global property cell reference in the instruction stream. |
| 8514 | virtual void VisitGlobalPropertyCell(RelocInfo* rinfo); |
| 8515 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8516 | // Visits a runtime entry in the instruction stream. |
| 8517 | virtual void VisitRuntimeEntry(RelocInfo* rinfo) {} |
| 8518 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 8519 | // Visits the resource of an ASCII or two-byte string. |
| 8520 | virtual void VisitExternalAsciiString( |
| 8521 | v8::String::ExternalAsciiStringResource** resource) {} |
| 8522 | virtual void VisitExternalTwoByteString( |
| 8523 | v8::String::ExternalStringResource** resource) {} |
| 8524 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8525 | // Visits a debug call target in the instruction stream. |
| 8526 | virtual void VisitDebugTarget(RelocInfo* rinfo); |
| 8527 | |
| 8528 | // Handy shorthand for visiting a single pointer. |
| 8529 | virtual void VisitPointer(Object** p) { VisitPointers(p, p + 1); } |
| 8530 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 8531 | // Visit pointer embedded into a code object. |
| 8532 | virtual void VisitEmbeddedPointer(RelocInfo* rinfo); |
| 8533 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8534 | // Visits a contiguous arrays of external references (references to the C++ |
| 8535 | // heap) in the half-open range [start, end). Any or all of the values |
| 8536 | // may be modified on return. |
| 8537 | virtual void VisitExternalReferences(Address* start, Address* end) {} |
| 8538 | |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 8539 | virtual void VisitExternalReference(RelocInfo* rinfo); |
| 8540 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8541 | inline void VisitExternalReference(Address* p) { |
| 8542 | VisitExternalReferences(p, p + 1); |
| 8543 | } |
| 8544 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 8545 | // Visits a handle that has an embedder-assigned class ID. |
| 8546 | virtual void VisitEmbedderReference(Object** p, uint16_t class_id) {} |
| 8547 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8548 | // Intended for serialization/deserialization checking: insert, or |
| 8549 | // check for the presence of, a tag at this position in the stream. |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 8550 | // Also used for marking up GC roots in heap snapshots. |
| 8551 | virtual void Synchronize(VisitorSynchronization::SyncTag tag) {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8552 | }; |
| 8553 | |
| 8554 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 8555 | class StructBodyDescriptor : public |
| 8556 | FlexibleBodyDescriptor<HeapObject::kHeaderSize> { |
| 8557 | public: |
| 8558 | static inline int SizeOf(Map* map, HeapObject* object) { |
| 8559 | return map->instance_size(); |
| 8560 | } |
| 8561 | }; |
| 8562 | |
| 8563 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 8564 | // BooleanBit is a helper class for setting and getting a bit in an |
| 8565 | // integer or Smi. |
| 8566 | class BooleanBit : public AllStatic { |
| 8567 | public: |
| 8568 | static inline bool get(Smi* smi, int bit_position) { |
| 8569 | return get(smi->value(), bit_position); |
| 8570 | } |
| 8571 | |
| 8572 | static inline bool get(int value, int bit_position) { |
| 8573 | return (value & (1 << bit_position)) != 0; |
| 8574 | } |
| 8575 | |
| 8576 | static inline Smi* set(Smi* smi, int bit_position, bool v) { |
| 8577 | return Smi::FromInt(set(smi->value(), bit_position, v)); |
| 8578 | } |
| 8579 | |
| 8580 | static inline int set(int value, int bit_position, bool v) { |
| 8581 | if (v) { |
| 8582 | value |= (1 << bit_position); |
| 8583 | } else { |
| 8584 | value &= ~(1 << bit_position); |
| 8585 | } |
| 8586 | return value; |
| 8587 | } |
| 8588 | }; |
| 8589 | |
| 8590 | } } // namespace v8::internal |
| 8591 | |
| 8592 | #endif // V8_OBJECTS_H_ |