Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1 | // Copyright 2011 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" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 34 | #include "smart-pointer.h" |
| 35 | #include "unicode-inl.h" |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 36 | #if V8_TARGET_ARCH_ARM |
| 37 | #include "arm/constants-arm.h" |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 38 | #elif V8_TARGET_ARCH_MIPS |
| 39 | #include "mips/constants-mips.h" |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 40 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 41 | |
| 42 | // |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 43 | // Most object types in the V8 JavaScript are described in this file. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 44 | // |
| 45 | // Inheritance hierarchy: |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 46 | // - MaybeObject (an object or a failure) |
| 47 | // - Failure (immediate for marking failed operation) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 48 | // - Object |
| 49 | // - Smi (immediate small integer) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 50 | // - HeapObject (superclass for everything allocated in the heap) |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 51 | // - JSReceiver (suitable for property access) |
| 52 | // - JSObject |
| 53 | // - JSArray |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 54 | // - JSWeakMap |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 55 | // - JSRegExp |
| 56 | // - JSFunction |
| 57 | // - GlobalObject |
| 58 | // - JSGlobalObject |
| 59 | // - JSBuiltinsObject |
| 60 | // - JSGlobalProxy |
| 61 | // - JSValue |
| 62 | // - JSMessageObject |
| 63 | // - JSProxy |
| 64 | // - JSFunctionProxy |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 65 | // - FixedArrayBase |
| 66 | // - ByteArray |
| 67 | // - FixedArray |
| 68 | // - DescriptorArray |
| 69 | // - HashTable |
| 70 | // - Dictionary |
| 71 | // - SymbolTable |
| 72 | // - CompilationCacheTable |
| 73 | // - CodeCacheHashTable |
| 74 | // - MapCache |
| 75 | // - Context |
| 76 | // - JSFunctionResultCache |
| 77 | // - SerializedScopeInfo |
| 78 | // - FixedDoubleArray |
| 79 | // - ExternalArray |
| 80 | // - ExternalPixelArray |
| 81 | // - ExternalByteArray |
| 82 | // - ExternalUnsignedByteArray |
| 83 | // - ExternalShortArray |
| 84 | // - ExternalUnsignedShortArray |
| 85 | // - ExternalIntArray |
| 86 | // - ExternalUnsignedIntArray |
| 87 | // - ExternalFloatArray |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 88 | // - String |
| 89 | // - SeqString |
| 90 | // - SeqAsciiString |
| 91 | // - SeqTwoByteString |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 92 | // - SlicedString |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 93 | // - ConsString |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 94 | // - ExternalString |
| 95 | // - ExternalAsciiString |
| 96 | // - ExternalTwoByteString |
| 97 | // - HeapNumber |
| 98 | // - Code |
| 99 | // - Map |
| 100 | // - Oddball |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 101 | // - Foreign |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 102 | // - SharedFunctionInfo |
| 103 | // - Struct |
| 104 | // - AccessorInfo |
| 105 | // - AccessCheckInfo |
| 106 | // - InterceptorInfo |
| 107 | // - CallHandlerInfo |
| 108 | // - TemplateInfo |
| 109 | // - FunctionTemplateInfo |
| 110 | // - ObjectTemplateInfo |
| 111 | // - Script |
| 112 | // - SignatureInfo |
| 113 | // - TypeSwitchInfo |
| 114 | // - DebugInfo |
| 115 | // - BreakPointInfo |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 116 | // - CodeCache |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 117 | // |
| 118 | // Formats of Object*: |
| 119 | // Smi: [31 bit signed int] 0 |
| 120 | // HeapObject: [32 bit direct pointer] (4 byte aligned) | 01 |
| 121 | // Failure: [30 bit signed int] 11 |
| 122 | |
| 123 | // Ecma-262 3rd 8.6.1 |
| 124 | enum PropertyAttributes { |
| 125 | NONE = v8::None, |
| 126 | READ_ONLY = v8::ReadOnly, |
| 127 | DONT_ENUM = v8::DontEnum, |
| 128 | DONT_DELETE = v8::DontDelete, |
| 129 | ABSENT = 16 // Used in runtime to indicate a property is absent. |
| 130 | // ABSENT can never be stored in or returned from a descriptor's attributes |
| 131 | // bitfield. It is only used as a return value meaning the attributes of |
| 132 | // a non-existent property. |
| 133 | }; |
| 134 | |
| 135 | namespace v8 { |
| 136 | namespace internal { |
| 137 | |
| 138 | |
| 139 | // PropertyDetails captures type and attributes for a property. |
| 140 | // They are used both in property dictionaries and instance descriptors. |
| 141 | class PropertyDetails BASE_EMBEDDED { |
| 142 | public: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 143 | PropertyDetails(PropertyAttributes attributes, |
| 144 | PropertyType type, |
| 145 | int index = 0) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 146 | ASSERT(type != EXTERNAL_ARRAY_TRANSITION); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 147 | ASSERT(TypeField::is_valid(type)); |
| 148 | ASSERT(AttributesField::is_valid(attributes)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 149 | ASSERT(StorageField::is_valid(index)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 150 | |
| 151 | value_ = TypeField::encode(type) |
| 152 | | AttributesField::encode(attributes) |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 153 | | StorageField::encode(index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 154 | |
| 155 | ASSERT(type == this->type()); |
| 156 | ASSERT(attributes == this->attributes()); |
| 157 | ASSERT(index == this->index()); |
| 158 | } |
| 159 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 160 | PropertyDetails(PropertyAttributes attributes, |
| 161 | PropertyType type, |
| 162 | ExternalArrayType array_type) { |
| 163 | ASSERT(type == EXTERNAL_ARRAY_TRANSITION); |
| 164 | ASSERT(TypeField::is_valid(type)); |
| 165 | ASSERT(AttributesField::is_valid(attributes)); |
| 166 | ASSERT(StorageField::is_valid(static_cast<int>(array_type))); |
| 167 | |
| 168 | value_ = TypeField::encode(type) |
| 169 | | AttributesField::encode(attributes) |
| 170 | | StorageField::encode(static_cast<int>(array_type)); |
| 171 | |
| 172 | ASSERT(type == this->type()); |
| 173 | ASSERT(attributes == this->attributes()); |
| 174 | ASSERT(array_type == this->array_type()); |
| 175 | } |
| 176 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 177 | // Conversion for storing details as Object*. |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 178 | explicit inline PropertyDetails(Smi* smi); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 179 | inline Smi* AsSmi(); |
| 180 | |
| 181 | PropertyType type() { return TypeField::decode(value_); } |
| 182 | |
| 183 | bool IsTransition() { |
| 184 | PropertyType t = type(); |
| 185 | ASSERT(t != INTERCEPTOR); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 186 | return t == MAP_TRANSITION || t == CONSTANT_TRANSITION || |
| 187 | t == EXTERNAL_ARRAY_TRANSITION; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | bool IsProperty() { |
| 191 | return type() < FIRST_PHANTOM_PROPERTY_TYPE; |
| 192 | } |
| 193 | |
| 194 | PropertyAttributes attributes() { return AttributesField::decode(value_); } |
| 195 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 196 | int index() { return StorageField::decode(value_); } |
| 197 | |
| 198 | ExternalArrayType array_type() { |
| 199 | ASSERT(type() == EXTERNAL_ARRAY_TRANSITION); |
| 200 | return static_cast<ExternalArrayType>(StorageField::decode(value_)); |
| 201 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 202 | |
| 203 | inline PropertyDetails AsDeleted(); |
| 204 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 205 | static bool IsValidIndex(int index) { |
| 206 | return StorageField::is_valid(index); |
| 207 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 208 | |
| 209 | bool IsReadOnly() { return (attributes() & READ_ONLY) != 0; } |
| 210 | bool IsDontDelete() { return (attributes() & DONT_DELETE) != 0; } |
| 211 | bool IsDontEnum() { return (attributes() & DONT_ENUM) != 0; } |
| 212 | bool IsDeleted() { return DeletedField::decode(value_) != 0;} |
| 213 | |
| 214 | // Bit fields in value_ (type, shift, size). Must be public so the |
| 215 | // constants can be embedded in generated code. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 216 | class TypeField: public BitField<PropertyType, 0, 4> {}; |
| 217 | class AttributesField: public BitField<PropertyAttributes, 4, 3> {}; |
| 218 | class DeletedField: public BitField<uint32_t, 7, 1> {}; |
| 219 | class StorageField: public BitField<uint32_t, 8, 32-8> {}; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 220 | |
| 221 | static const int kInitialIndex = 1; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 222 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 223 | private: |
| 224 | uint32_t value_; |
| 225 | }; |
| 226 | |
| 227 | |
| 228 | // Setter that skips the write barrier if mode is SKIP_WRITE_BARRIER. |
| 229 | enum WriteBarrierMode { SKIP_WRITE_BARRIER, UPDATE_WRITE_BARRIER }; |
| 230 | |
| 231 | |
| 232 | // PropertyNormalizationMode is used to specify whether to keep |
| 233 | // inobject properties when normalizing properties of a JSObject. |
| 234 | enum PropertyNormalizationMode { |
| 235 | CLEAR_INOBJECT_PROPERTIES, |
| 236 | KEEP_INOBJECT_PROPERTIES |
| 237 | }; |
| 238 | |
| 239 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 240 | // NormalizedMapSharingMode is used to specify whether a map may be shared |
| 241 | // by different objects with normalized properties. |
| 242 | enum NormalizedMapSharingMode { |
| 243 | UNIQUE_NORMALIZED_MAP, |
| 244 | SHARED_NORMALIZED_MAP |
| 245 | }; |
| 246 | |
| 247 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 248 | // Instance size sentinel for objects of variable size. |
| 249 | static const int kVariableSizeSentinel = 0; |
| 250 | |
| 251 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 252 | // All Maps have a field instance_type containing a InstanceType. |
| 253 | // It describes the type of the instances. |
| 254 | // |
| 255 | // As an example, a JavaScript object is a heap object and its map |
| 256 | // instance_type is JS_OBJECT_TYPE. |
| 257 | // |
| 258 | // The names of the string instance types are intended to systematically |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 259 | // mirror their encoding in the instance_type field of the map. The default |
| 260 | // encoding is considered TWO_BYTE. It is not mentioned in the name. ASCII |
| 261 | // encoding is mentioned explicitly in the name. Likewise, the default |
| 262 | // representation is considered sequential. It is not mentioned in the |
| 263 | // name. The other representations (eg, CONS, EXTERNAL) are explicitly |
| 264 | // mentioned. Finally, the string is either a SYMBOL_TYPE (if it is a |
| 265 | // symbol) or a STRING_TYPE (if it is not a symbol). |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 266 | // |
| 267 | // NOTE: The following things are some that depend on the string types having |
| 268 | // instance_types that are less than those of all other types: |
| 269 | // HeapObject::Size, HeapObject::IterateBody, the typeof operator, and |
| 270 | // Object::IsString. |
| 271 | // |
| 272 | // NOTE: Everything following JS_VALUE_TYPE is considered a |
| 273 | // JSObject for GC purposes. The first four entries here have typeof |
| 274 | // 'object', whereas JS_FUNCTION_TYPE has typeof 'function'. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 275 | #define INSTANCE_TYPE_LIST_ALL(V) \ |
| 276 | V(SYMBOL_TYPE) \ |
| 277 | V(ASCII_SYMBOL_TYPE) \ |
| 278 | V(CONS_SYMBOL_TYPE) \ |
| 279 | V(CONS_ASCII_SYMBOL_TYPE) \ |
| 280 | V(EXTERNAL_SYMBOL_TYPE) \ |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 281 | V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 282 | V(EXTERNAL_ASCII_SYMBOL_TYPE) \ |
| 283 | V(STRING_TYPE) \ |
| 284 | V(ASCII_STRING_TYPE) \ |
| 285 | V(CONS_STRING_TYPE) \ |
| 286 | V(CONS_ASCII_STRING_TYPE) \ |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 287 | V(SLICED_STRING_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 288 | V(EXTERNAL_STRING_TYPE) \ |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 289 | V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 290 | V(EXTERNAL_ASCII_STRING_TYPE) \ |
| 291 | V(PRIVATE_EXTERNAL_ASCII_STRING_TYPE) \ |
| 292 | \ |
| 293 | V(MAP_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 294 | V(CODE_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 295 | V(ODDBALL_TYPE) \ |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 296 | V(JS_GLOBAL_PROPERTY_CELL_TYPE) \ |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 297 | \ |
| 298 | V(HEAP_NUMBER_TYPE) \ |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 299 | V(FOREIGN_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 300 | V(BYTE_ARRAY_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 301 | /* Note: the order of these external array */ \ |
| 302 | /* types is relied upon in */ \ |
| 303 | /* Object::IsExternalArray(). */ \ |
| 304 | V(EXTERNAL_BYTE_ARRAY_TYPE) \ |
| 305 | V(EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE) \ |
| 306 | V(EXTERNAL_SHORT_ARRAY_TYPE) \ |
| 307 | V(EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE) \ |
| 308 | V(EXTERNAL_INT_ARRAY_TYPE) \ |
| 309 | V(EXTERNAL_UNSIGNED_INT_ARRAY_TYPE) \ |
| 310 | V(EXTERNAL_FLOAT_ARRAY_TYPE) \ |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 311 | V(EXTERNAL_PIXEL_ARRAY_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 312 | V(FILLER_TYPE) \ |
| 313 | \ |
| 314 | V(ACCESSOR_INFO_TYPE) \ |
| 315 | V(ACCESS_CHECK_INFO_TYPE) \ |
| 316 | V(INTERCEPTOR_INFO_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 317 | V(CALL_HANDLER_INFO_TYPE) \ |
| 318 | V(FUNCTION_TEMPLATE_INFO_TYPE) \ |
| 319 | V(OBJECT_TEMPLATE_INFO_TYPE) \ |
| 320 | V(SIGNATURE_INFO_TYPE) \ |
| 321 | V(TYPE_SWITCH_INFO_TYPE) \ |
| 322 | V(SCRIPT_TYPE) \ |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 323 | V(CODE_CACHE_TYPE) \ |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 324 | V(POLYMORPHIC_CODE_CACHE_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 325 | \ |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 326 | V(FIXED_ARRAY_TYPE) \ |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 327 | V(FIXED_DOUBLE_ARRAY_TYPE) \ |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 328 | V(SHARED_FUNCTION_INFO_TYPE) \ |
| 329 | \ |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 330 | V(JS_MESSAGE_OBJECT_TYPE) \ |
| 331 | \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 332 | V(JS_VALUE_TYPE) \ |
| 333 | V(JS_OBJECT_TYPE) \ |
| 334 | V(JS_CONTEXT_EXTENSION_OBJECT_TYPE) \ |
| 335 | V(JS_GLOBAL_OBJECT_TYPE) \ |
| 336 | V(JS_BUILTINS_OBJECT_TYPE) \ |
| 337 | V(JS_GLOBAL_PROXY_TYPE) \ |
| 338 | V(JS_ARRAY_TYPE) \ |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 339 | V(JS_PROXY_TYPE) \ |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 340 | V(JS_WEAK_MAP_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 341 | V(JS_REGEXP_TYPE) \ |
| 342 | \ |
| 343 | V(JS_FUNCTION_TYPE) \ |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 344 | V(JS_FUNCTION_PROXY_TYPE) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 345 | |
| 346 | #ifdef ENABLE_DEBUGGER_SUPPORT |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 347 | #define INSTANCE_TYPE_LIST_DEBUGGER(V) \ |
| 348 | V(DEBUG_INFO_TYPE) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 349 | V(BREAK_POINT_INFO_TYPE) |
| 350 | #else |
| 351 | #define INSTANCE_TYPE_LIST_DEBUGGER(V) |
| 352 | #endif |
| 353 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 354 | #define INSTANCE_TYPE_LIST(V) \ |
| 355 | INSTANCE_TYPE_LIST_ALL(V) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 356 | INSTANCE_TYPE_LIST_DEBUGGER(V) |
| 357 | |
| 358 | |
| 359 | // Since string types are not consecutive, this macro is used to |
| 360 | // iterate over them. |
| 361 | #define STRING_TYPE_LIST(V) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 362 | V(SYMBOL_TYPE, \ |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 363 | kVariableSizeSentinel, \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 364 | symbol, \ |
| 365 | Symbol) \ |
| 366 | V(ASCII_SYMBOL_TYPE, \ |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 367 | kVariableSizeSentinel, \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 368 | ascii_symbol, \ |
| 369 | AsciiSymbol) \ |
| 370 | V(CONS_SYMBOL_TYPE, \ |
| 371 | ConsString::kSize, \ |
| 372 | cons_symbol, \ |
| 373 | ConsSymbol) \ |
| 374 | V(CONS_ASCII_SYMBOL_TYPE, \ |
| 375 | ConsString::kSize, \ |
| 376 | cons_ascii_symbol, \ |
| 377 | ConsAsciiSymbol) \ |
| 378 | V(EXTERNAL_SYMBOL_TYPE, \ |
| 379 | ExternalTwoByteString::kSize, \ |
| 380 | external_symbol, \ |
| 381 | ExternalSymbol) \ |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 382 | V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE, \ |
| 383 | ExternalTwoByteString::kSize, \ |
| 384 | external_symbol_with_ascii_data, \ |
| 385 | ExternalSymbolWithAsciiData) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 386 | V(EXTERNAL_ASCII_SYMBOL_TYPE, \ |
| 387 | ExternalAsciiString::kSize, \ |
| 388 | external_ascii_symbol, \ |
| 389 | ExternalAsciiSymbol) \ |
| 390 | V(STRING_TYPE, \ |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 391 | kVariableSizeSentinel, \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 392 | string, \ |
| 393 | String) \ |
| 394 | V(ASCII_STRING_TYPE, \ |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 395 | kVariableSizeSentinel, \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 396 | ascii_string, \ |
| 397 | AsciiString) \ |
| 398 | V(CONS_STRING_TYPE, \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 399 | ConsString::kSize, \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 400 | cons_string, \ |
| 401 | ConsString) \ |
| 402 | V(CONS_ASCII_STRING_TYPE, \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 403 | ConsString::kSize, \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 404 | cons_ascii_string, \ |
| 405 | ConsAsciiString) \ |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 406 | V(SLICED_STRING_TYPE, \ |
| 407 | SlicedString::kSize, \ |
| 408 | sliced_string, \ |
| 409 | SlicedString) \ |
| 410 | V(SLICED_ASCII_STRING_TYPE, \ |
| 411 | SlicedString::kSize, \ |
| 412 | sliced_ascii_string, \ |
| 413 | SlicedAsciiString) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 414 | V(EXTERNAL_STRING_TYPE, \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 415 | ExternalTwoByteString::kSize, \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 416 | external_string, \ |
| 417 | ExternalString) \ |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 418 | V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE, \ |
| 419 | ExternalTwoByteString::kSize, \ |
| 420 | external_string_with_ascii_data, \ |
| 421 | ExternalStringWithAsciiData) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 422 | V(EXTERNAL_ASCII_STRING_TYPE, \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 423 | ExternalAsciiString::kSize, \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 424 | external_ascii_string, \ |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 425 | ExternalAsciiString) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 426 | |
| 427 | // A struct is a simple object a set of object-valued fields. Including an |
| 428 | // object type in this causes the compiler to generate most of the boilerplate |
| 429 | // code for the class including allocation and garbage collection routines, |
| 430 | // casts and predicates. All you need to define is the class, methods and |
| 431 | // object verification routines. Easy, no? |
| 432 | // |
| 433 | // Note that for subtle reasons related to the ordering or numerical values of |
| 434 | // type tags, elements in this list have to be added to the INSTANCE_TYPE_LIST |
| 435 | // manually. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 436 | #define STRUCT_LIST_ALL(V) \ |
| 437 | V(ACCESSOR_INFO, AccessorInfo, accessor_info) \ |
| 438 | V(ACCESS_CHECK_INFO, AccessCheckInfo, access_check_info) \ |
| 439 | V(INTERCEPTOR_INFO, InterceptorInfo, interceptor_info) \ |
| 440 | V(CALL_HANDLER_INFO, CallHandlerInfo, call_handler_info) \ |
| 441 | V(FUNCTION_TEMPLATE_INFO, FunctionTemplateInfo, function_template_info) \ |
| 442 | V(OBJECT_TEMPLATE_INFO, ObjectTemplateInfo, object_template_info) \ |
| 443 | V(SIGNATURE_INFO, SignatureInfo, signature_info) \ |
| 444 | V(TYPE_SWITCH_INFO, TypeSwitchInfo, type_switch_info) \ |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 445 | V(SCRIPT, Script, script) \ |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 446 | V(CODE_CACHE, CodeCache, code_cache) \ |
| 447 | V(POLYMORPHIC_CODE_CACHE, PolymorphicCodeCache, polymorphic_code_cache) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 448 | |
| 449 | #ifdef ENABLE_DEBUGGER_SUPPORT |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 450 | #define STRUCT_LIST_DEBUGGER(V) \ |
| 451 | V(DEBUG_INFO, DebugInfo, debug_info) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 452 | V(BREAK_POINT_INFO, BreakPointInfo, break_point_info) |
| 453 | #else |
| 454 | #define STRUCT_LIST_DEBUGGER(V) |
| 455 | #endif |
| 456 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 457 | #define STRUCT_LIST(V) \ |
| 458 | STRUCT_LIST_ALL(V) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 459 | STRUCT_LIST_DEBUGGER(V) |
| 460 | |
| 461 | // We use the full 8 bits of the instance_type field to encode heap object |
| 462 | // instance types. The high-order bit (bit 7) is set if the object is not a |
| 463 | // string, and cleared if it is a string. |
| 464 | const uint32_t kIsNotStringMask = 0x80; |
| 465 | const uint32_t kStringTag = 0x0; |
| 466 | const uint32_t kNotStringTag = 0x80; |
| 467 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 468 | // Bit 6 indicates that the object is a symbol (if set) or not (if cleared). |
| 469 | // There are not enough types that the non-string types (with bit 7 set) can |
| 470 | // have bit 6 set too. |
| 471 | const uint32_t kIsSymbolMask = 0x40; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 472 | const uint32_t kNotSymbolTag = 0x0; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 473 | const uint32_t kSymbolTag = 0x40; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 474 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 475 | // If bit 7 is clear then bit 2 indicates whether the string consists of |
| 476 | // two-byte characters or one-byte characters. |
| 477 | const uint32_t kStringEncodingMask = 0x4; |
| 478 | const uint32_t kTwoByteStringTag = 0x0; |
| 479 | const uint32_t kAsciiStringTag = 0x4; |
| 480 | |
| 481 | // If bit 7 is clear, the low-order 2 bits indicate the representation |
| 482 | // of the string. |
| 483 | const uint32_t kStringRepresentationMask = 0x03; |
| 484 | enum StringRepresentationTag { |
| 485 | kSeqStringTag = 0x0, |
| 486 | kConsStringTag = 0x1, |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 487 | kExternalStringTag = 0x2, |
| 488 | kSlicedStringTag = 0x3 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 489 | }; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 490 | const uint32_t kIsIndirectStringMask = 0x1; |
| 491 | const uint32_t kIsIndirectStringTag = 0x1; |
| 492 | STATIC_ASSERT((kSeqStringTag & kIsIndirectStringMask) == 0); |
| 493 | STATIC_ASSERT((kExternalStringTag & kIsIndirectStringMask) == 0); |
| 494 | STATIC_ASSERT( |
| 495 | (kConsStringTag & kIsIndirectStringMask) == kIsIndirectStringTag); |
| 496 | STATIC_ASSERT( |
| 497 | (kSlicedStringTag & kIsIndirectStringMask) == kIsIndirectStringTag); |
| 498 | |
| 499 | // Use this mask to distinguish between cons and slice only after making |
| 500 | // sure that the string is one of the two (an indirect string). |
| 501 | const uint32_t kSlicedNotConsMask = kSlicedStringTag & ~kConsStringTag; |
| 502 | STATIC_ASSERT(IS_POWER_OF_TWO(kSlicedNotConsMask) && kSlicedNotConsMask != 0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 503 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 504 | // If bit 7 is clear, then bit 3 indicates whether this two-byte |
| 505 | // string actually contains ascii data. |
| 506 | const uint32_t kAsciiDataHintMask = 0x08; |
| 507 | const uint32_t kAsciiDataHintTag = 0x08; |
| 508 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 509 | |
| 510 | // A ConsString with an empty string as the right side is a candidate |
| 511 | // for being shortcut by the garbage collector unless it is a |
| 512 | // symbol. It's not common to have non-flat symbols, so we do not |
| 513 | // shortcut them thereby avoiding turning symbols into strings. See |
| 514 | // heap.cc and mark-compact.cc. |
| 515 | const uint32_t kShortcutTypeMask = |
| 516 | kIsNotStringMask | |
| 517 | kIsSymbolMask | |
| 518 | kStringRepresentationMask; |
| 519 | const uint32_t kShortcutTypeTag = kConsStringTag; |
| 520 | |
| 521 | |
| 522 | enum InstanceType { |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 523 | // String types. |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 524 | SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kSeqStringTag, |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 525 | ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kSeqStringTag, |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 526 | CONS_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kConsStringTag, |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 527 | CONS_ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kConsStringTag, |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 528 | EXTERNAL_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kExternalStringTag, |
| 529 | EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE = |
| 530 | kTwoByteStringTag | kSymbolTag | kExternalStringTag | kAsciiDataHintTag, |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 531 | EXTERNAL_ASCII_SYMBOL_TYPE = |
| 532 | kAsciiStringTag | kSymbolTag | kExternalStringTag, |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 533 | STRING_TYPE = kTwoByteStringTag | kSeqStringTag, |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 534 | ASCII_STRING_TYPE = kAsciiStringTag | kSeqStringTag, |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 535 | CONS_STRING_TYPE = kTwoByteStringTag | kConsStringTag, |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 536 | CONS_ASCII_STRING_TYPE = kAsciiStringTag | kConsStringTag, |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 537 | SLICED_STRING_TYPE = kTwoByteStringTag | kSlicedStringTag, |
| 538 | SLICED_ASCII_STRING_TYPE = kAsciiStringTag | kSlicedStringTag, |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 539 | EXTERNAL_STRING_TYPE = kTwoByteStringTag | kExternalStringTag, |
| 540 | EXTERNAL_STRING_WITH_ASCII_DATA_TYPE = |
| 541 | kTwoByteStringTag | kExternalStringTag | kAsciiDataHintTag, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 542 | // LAST_STRING_TYPE |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 543 | EXTERNAL_ASCII_STRING_TYPE = kAsciiStringTag | kExternalStringTag, |
| 544 | PRIVATE_EXTERNAL_ASCII_STRING_TYPE = EXTERNAL_ASCII_STRING_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 545 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 546 | // Objects allocated in their own spaces (never in new space). |
| 547 | MAP_TYPE = kNotStringTag, // FIRST_NONSTRING_TYPE |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 548 | CODE_TYPE, |
| 549 | ODDBALL_TYPE, |
| 550 | JS_GLOBAL_PROPERTY_CELL_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 551 | |
| 552 | // "Data", objects that cannot contain non-map-word pointers to heap |
| 553 | // objects. |
| 554 | HEAP_NUMBER_TYPE, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 555 | FOREIGN_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 556 | BYTE_ARRAY_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 557 | EXTERNAL_BYTE_ARRAY_TYPE, // FIRST_EXTERNAL_ARRAY_TYPE |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 558 | EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE, |
| 559 | EXTERNAL_SHORT_ARRAY_TYPE, |
| 560 | EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE, |
| 561 | EXTERNAL_INT_ARRAY_TYPE, |
| 562 | EXTERNAL_UNSIGNED_INT_ARRAY_TYPE, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 563 | EXTERNAL_FLOAT_ARRAY_TYPE, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 564 | EXTERNAL_DOUBLE_ARRAY_TYPE, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 565 | EXTERNAL_PIXEL_ARRAY_TYPE, // LAST_EXTERNAL_ARRAY_TYPE |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 566 | FIXED_DOUBLE_ARRAY_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 567 | FILLER_TYPE, // LAST_DATA_TYPE |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 568 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 569 | // Structs. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 570 | ACCESSOR_INFO_TYPE, |
| 571 | ACCESS_CHECK_INFO_TYPE, |
| 572 | INTERCEPTOR_INFO_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 573 | CALL_HANDLER_INFO_TYPE, |
| 574 | FUNCTION_TEMPLATE_INFO_TYPE, |
| 575 | OBJECT_TEMPLATE_INFO_TYPE, |
| 576 | SIGNATURE_INFO_TYPE, |
| 577 | TYPE_SWITCH_INFO_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 578 | SCRIPT_TYPE, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 579 | CODE_CACHE_TYPE, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 580 | POLYMORPHIC_CODE_CACHE_TYPE, |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 581 | // The following two instance types are only used when ENABLE_DEBUGGER_SUPPORT |
| 582 | // is defined. However as include/v8.h contain some of the instance type |
| 583 | // constants always having them avoids them getting different numbers |
| 584 | // depending on whether ENABLE_DEBUGGER_SUPPORT is defined or not. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 585 | DEBUG_INFO_TYPE, |
| 586 | BREAK_POINT_INFO_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 587 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 588 | FIXED_ARRAY_TYPE, |
| 589 | SHARED_FUNCTION_INFO_TYPE, |
| 590 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 591 | JS_MESSAGE_OBJECT_TYPE, |
| 592 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 593 | JS_VALUE_TYPE, // FIRST_NON_CALLABLE_OBJECT_TYPE, FIRST_JS_RECEIVER_TYPE |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 594 | JS_OBJECT_TYPE, |
| 595 | JS_CONTEXT_EXTENSION_OBJECT_TYPE, |
| 596 | JS_GLOBAL_OBJECT_TYPE, |
| 597 | JS_BUILTINS_OBJECT_TYPE, |
| 598 | JS_GLOBAL_PROXY_TYPE, |
| 599 | JS_ARRAY_TYPE, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 600 | JS_PROXY_TYPE, |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 601 | JS_WEAK_MAP_TYPE, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 602 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 603 | JS_REGEXP_TYPE, // LAST_NONCALLABLE_SPEC_OBJECT_TYPE |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 604 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 605 | JS_FUNCTION_TYPE, // FIRST_CALLABLE_SPEC_OBJECT_TYPE |
| 606 | JS_FUNCTION_PROXY_TYPE, // LAST_CALLABLE_SPEC_OBJECT_TYPE |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 607 | |
| 608 | // Pseudo-types |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 609 | FIRST_TYPE = 0x0, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 610 | LAST_TYPE = JS_FUNCTION_PROXY_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 611 | INVALID_TYPE = FIRST_TYPE - 1, |
| 612 | FIRST_NONSTRING_TYPE = MAP_TYPE, |
| 613 | // Boundaries for testing for an external array. |
| 614 | FIRST_EXTERNAL_ARRAY_TYPE = EXTERNAL_BYTE_ARRAY_TYPE, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 615 | LAST_EXTERNAL_ARRAY_TYPE = EXTERNAL_PIXEL_ARRAY_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 616 | // Boundary for promotion to old data space/old pointer space. |
| 617 | LAST_DATA_TYPE = FILLER_TYPE, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 618 | // Boundary for objects represented as JSReceiver (i.e. JSObject or JSProxy). |
| 619 | // Note that there is no range for JSObject or JSProxy, since their subtypes |
| 620 | // are not continuous in this enum! The enum ranges instead reflect the |
| 621 | // external class names, where proxies are treated as either ordinary objects, |
| 622 | // or functions. |
| 623 | FIRST_JS_RECEIVER_TYPE = JS_VALUE_TYPE, |
| 624 | LAST_JS_RECEIVER_TYPE = LAST_TYPE, |
| 625 | // Boundaries for testing the types for which typeof is "object". |
| 626 | FIRST_NONCALLABLE_SPEC_OBJECT_TYPE = JS_VALUE_TYPE, |
| 627 | LAST_NONCALLABLE_SPEC_OBJECT_TYPE = JS_REGEXP_TYPE, |
| 628 | // Boundaries for testing the types for which typeof is "function". |
| 629 | FIRST_CALLABLE_SPEC_OBJECT_TYPE = JS_FUNCTION_TYPE, |
| 630 | LAST_CALLABLE_SPEC_OBJECT_TYPE = JS_FUNCTION_PROXY_TYPE, |
| 631 | // Boundaries for testing whether the type is a JavaScript object. |
| 632 | FIRST_SPEC_OBJECT_TYPE = FIRST_NONCALLABLE_SPEC_OBJECT_TYPE, |
| 633 | LAST_SPEC_OBJECT_TYPE = LAST_CALLABLE_SPEC_OBJECT_TYPE |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 634 | }; |
| 635 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 636 | static const int kExternalArrayTypeCount = LAST_EXTERNAL_ARRAY_TYPE - |
| 637 | FIRST_EXTERNAL_ARRAY_TYPE + 1; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 638 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 639 | STATIC_CHECK(JS_OBJECT_TYPE == Internals::kJSObjectType); |
| 640 | STATIC_CHECK(FIRST_NONSTRING_TYPE == Internals::kFirstNonstringType); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 641 | STATIC_CHECK(FOREIGN_TYPE == Internals::kForeignType); |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 642 | |
| 643 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 644 | enum CompareResult { |
| 645 | LESS = -1, |
| 646 | EQUAL = 0, |
| 647 | GREATER = 1, |
| 648 | |
| 649 | NOT_EQUAL = GREATER |
| 650 | }; |
| 651 | |
| 652 | |
| 653 | #define DECL_BOOLEAN_ACCESSORS(name) \ |
| 654 | inline bool name(); \ |
| 655 | inline void set_##name(bool value); \ |
| 656 | |
| 657 | |
| 658 | #define DECL_ACCESSORS(name, type) \ |
| 659 | inline type* name(); \ |
| 660 | inline void set_##name(type* value, \ |
| 661 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); \ |
| 662 | |
| 663 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 664 | class DictionaryElementsAccessor; |
| 665 | class ElementsAccessor; |
| 666 | class FixedArrayBase; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 667 | class ObjectVisitor; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 668 | class StringStream; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 669 | |
| 670 | struct ValueInfo : public Malloced { |
| 671 | ValueInfo() : type(FIRST_TYPE), ptr(NULL), str(NULL), number(0) { } |
| 672 | InstanceType type; |
| 673 | Object* ptr; |
| 674 | const char* str; |
| 675 | double number; |
| 676 | }; |
| 677 | |
| 678 | |
| 679 | // A template-ized version of the IsXXX functions. |
| 680 | template <class C> static inline bool Is(Object* obj); |
| 681 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 682 | class Failure; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 683 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 684 | class MaybeObject BASE_EMBEDDED { |
| 685 | public: |
| 686 | inline bool IsFailure(); |
| 687 | inline bool IsRetryAfterGC(); |
| 688 | inline bool IsOutOfMemory(); |
| 689 | inline bool IsException(); |
| 690 | INLINE(bool IsTheHole()); |
| 691 | inline bool ToObject(Object** obj) { |
| 692 | if (IsFailure()) return false; |
| 693 | *obj = reinterpret_cast<Object*>(this); |
| 694 | return true; |
| 695 | } |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 696 | inline Failure* ToFailureUnchecked() { |
| 697 | ASSERT(IsFailure()); |
| 698 | return reinterpret_cast<Failure*>(this); |
| 699 | } |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 700 | inline Object* ToObjectUnchecked() { |
| 701 | ASSERT(!IsFailure()); |
| 702 | return reinterpret_cast<Object*>(this); |
| 703 | } |
| 704 | inline Object* ToObjectChecked() { |
| 705 | CHECK(!IsFailure()); |
| 706 | return reinterpret_cast<Object*>(this); |
| 707 | } |
| 708 | |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 709 | template<typename T> |
| 710 | inline bool To(T** obj) { |
| 711 | if (IsFailure()) return false; |
| 712 | *obj = T::cast(reinterpret_cast<Object*>(this)); |
| 713 | return true; |
| 714 | } |
| 715 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 716 | #ifdef OBJECT_PRINT |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 717 | // Prints this object with details. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 718 | inline void Print() { |
| 719 | Print(stdout); |
| 720 | }; |
| 721 | inline void PrintLn() { |
| 722 | PrintLn(stdout); |
| 723 | } |
| 724 | void Print(FILE* out); |
| 725 | void PrintLn(FILE* out); |
| 726 | #endif |
| 727 | #ifdef DEBUG |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 728 | // Verifies the object. |
| 729 | void Verify(); |
| 730 | #endif |
| 731 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 732 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 733 | |
| 734 | #define OBJECT_TYPE_LIST(V) \ |
| 735 | V(Smi) \ |
| 736 | V(HeapObject) \ |
| 737 | V(Number) \ |
| 738 | |
| 739 | #define HEAP_OBJECT_TYPE_LIST(V) \ |
| 740 | V(HeapNumber) \ |
| 741 | V(String) \ |
| 742 | V(Symbol) \ |
| 743 | V(SeqString) \ |
| 744 | V(ExternalString) \ |
| 745 | V(ConsString) \ |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 746 | V(SlicedString) \ |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 747 | V(ExternalTwoByteString) \ |
| 748 | V(ExternalAsciiString) \ |
| 749 | V(SeqTwoByteString) \ |
| 750 | V(SeqAsciiString) \ |
| 751 | \ |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 752 | V(ExternalArray) \ |
| 753 | V(ExternalByteArray) \ |
| 754 | V(ExternalUnsignedByteArray) \ |
| 755 | V(ExternalShortArray) \ |
| 756 | V(ExternalUnsignedShortArray) \ |
| 757 | V(ExternalIntArray) \ |
| 758 | V(ExternalUnsignedIntArray) \ |
| 759 | V(ExternalFloatArray) \ |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 760 | V(ExternalDoubleArray) \ |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 761 | V(ExternalPixelArray) \ |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 762 | V(ByteArray) \ |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 763 | V(JSReceiver) \ |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 764 | V(JSObject) \ |
| 765 | V(JSContextExtensionObject) \ |
| 766 | V(Map) \ |
| 767 | V(DescriptorArray) \ |
| 768 | V(DeoptimizationInputData) \ |
| 769 | V(DeoptimizationOutputData) \ |
| 770 | V(FixedArray) \ |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 771 | V(FixedDoubleArray) \ |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 772 | V(Context) \ |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 773 | V(GlobalContext) \ |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 774 | V(SerializedScopeInfo) \ |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 775 | V(JSFunction) \ |
| 776 | V(Code) \ |
| 777 | V(Oddball) \ |
| 778 | V(SharedFunctionInfo) \ |
| 779 | V(JSValue) \ |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 780 | V(JSMessageObject) \ |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 781 | V(StringWrapper) \ |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 782 | V(Foreign) \ |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 783 | V(Boolean) \ |
| 784 | V(JSArray) \ |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 785 | V(JSProxy) \ |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 786 | V(JSFunctionProxy) \ |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 787 | V(JSWeakMap) \ |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 788 | V(JSRegExp) \ |
| 789 | V(HashTable) \ |
| 790 | V(Dictionary) \ |
| 791 | V(SymbolTable) \ |
| 792 | V(JSFunctionResultCache) \ |
| 793 | V(NormalizedMapCache) \ |
| 794 | V(CompilationCacheTable) \ |
| 795 | V(CodeCacheHashTable) \ |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 796 | V(PolymorphicCodeCacheHashTable) \ |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 797 | V(MapCache) \ |
| 798 | V(Primitive) \ |
| 799 | V(GlobalObject) \ |
| 800 | V(JSGlobalObject) \ |
| 801 | V(JSBuiltinsObject) \ |
| 802 | V(JSGlobalProxy) \ |
| 803 | V(UndetectableObject) \ |
| 804 | V(AccessCheckNeeded) \ |
| 805 | V(JSGlobalPropertyCell) \ |
| 806 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 807 | // Object is the abstract superclass for all classes in the |
| 808 | // object hierarchy. |
| 809 | // Object does not use any virtual functions to avoid the |
| 810 | // allocation of the C++ vtable. |
| 811 | // Since Smi and Failure are subclasses of Object no |
| 812 | // data members can be present in Object. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 813 | class Object : public MaybeObject { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 814 | public: |
| 815 | // Type testing. |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 816 | #define IS_TYPE_FUNCTION_DECL(type_) inline bool Is##type_(); |
| 817 | OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL) |
| 818 | HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL) |
| 819 | #undef IS_TYPE_FUNCTION_DECL |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 820 | |
| 821 | // Returns true if this object is an instance of the specified |
| 822 | // function template. |
| 823 | inline bool IsInstanceOf(FunctionTemplateInfo* type); |
| 824 | |
| 825 | inline bool IsStruct(); |
| 826 | #define DECLARE_STRUCT_PREDICATE(NAME, Name, name) inline bool Is##Name(); |
| 827 | STRUCT_LIST(DECLARE_STRUCT_PREDICATE) |
| 828 | #undef DECLARE_STRUCT_PREDICATE |
| 829 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 830 | INLINE(bool IsSpecObject()); |
| 831 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 832 | // Oddball testing. |
| 833 | INLINE(bool IsUndefined()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 834 | INLINE(bool IsNull()); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 835 | INLINE(bool IsTheHole()); // Shadows MaybeObject's implementation. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 836 | INLINE(bool IsTrue()); |
| 837 | INLINE(bool IsFalse()); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 838 | inline bool IsArgumentsMarker(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 839 | |
| 840 | // Extract the number. |
| 841 | inline double Number(); |
| 842 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 843 | // Returns true if the object is of the correct type to be used as a |
| 844 | // implementation of a JSObject's elements. |
| 845 | inline bool HasValidElements(); |
| 846 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 847 | inline bool HasSpecificClassOf(String* name); |
| 848 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 849 | MUST_USE_RESULT MaybeObject* ToObject(); // ECMA-262 9.9. |
| 850 | Object* ToBoolean(); // ECMA-262 9.2. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 851 | |
| 852 | // Convert to a JSObject if needed. |
| 853 | // global_context is used when creating wrapper object. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 854 | MUST_USE_RESULT MaybeObject* ToObject(Context* global_context); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 855 | |
| 856 | // Converts this to a Smi if possible. |
| 857 | // Failure is returned otherwise. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 858 | MUST_USE_RESULT inline MaybeObject* ToSmi(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 859 | |
| 860 | void Lookup(String* name, LookupResult* result); |
| 861 | |
| 862 | // Property access. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 863 | MUST_USE_RESULT inline MaybeObject* GetProperty(String* key); |
| 864 | MUST_USE_RESULT inline MaybeObject* GetProperty( |
| 865 | String* key, |
| 866 | PropertyAttributes* attributes); |
| 867 | MUST_USE_RESULT MaybeObject* GetPropertyWithReceiver( |
| 868 | Object* receiver, |
| 869 | String* key, |
| 870 | PropertyAttributes* attributes); |
| 871 | MUST_USE_RESULT MaybeObject* GetProperty(Object* receiver, |
| 872 | LookupResult* result, |
| 873 | String* key, |
| 874 | PropertyAttributes* attributes); |
| 875 | MUST_USE_RESULT MaybeObject* GetPropertyWithCallback(Object* receiver, |
| 876 | Object* structure, |
| 877 | String* name, |
| 878 | Object* holder); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 879 | MUST_USE_RESULT MaybeObject* GetPropertyWithHandler(Object* receiver, |
| 880 | String* name, |
| 881 | Object* handler); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 882 | MUST_USE_RESULT MaybeObject* GetPropertyWithDefinedGetter(Object* receiver, |
| 883 | JSFunction* getter); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 884 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 885 | inline MaybeObject* GetElement(uint32_t index); |
| 886 | // For use when we know that no exception can be thrown. |
| 887 | inline Object* GetElementNoExceptionThrown(uint32_t index); |
| 888 | MaybeObject* GetElementWithReceiver(Object* receiver, uint32_t index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 889 | |
| 890 | // Return the object's prototype (might be Heap::null_value()). |
| 891 | Object* GetPrototype(); |
| 892 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 893 | // Tries to convert an object to an array index. Returns true and sets |
| 894 | // the output parameter if it succeeds. |
| 895 | inline bool ToArrayIndex(uint32_t* index); |
| 896 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 897 | // Returns true if this is a JSValue containing a string and the index is |
| 898 | // < the length of the string. Used to implement [] on strings. |
| 899 | inline bool IsStringObjectWithCharacterAt(uint32_t index); |
| 900 | |
| 901 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 902 | // Verify a pointer is a valid object pointer. |
| 903 | static void VerifyPointer(Object* p); |
| 904 | #endif |
| 905 | |
| 906 | // Prints this object without details. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 907 | inline void ShortPrint() { |
| 908 | ShortPrint(stdout); |
| 909 | } |
| 910 | void ShortPrint(FILE* out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 911 | |
| 912 | // Prints this object without details to a message accumulator. |
| 913 | void ShortPrint(StringStream* accumulator); |
| 914 | |
| 915 | // Casting: This cast is only needed to satisfy macros in objects-inl.h. |
| 916 | static Object* cast(Object* value) { return value; } |
| 917 | |
| 918 | // Layout description. |
| 919 | static const int kHeaderSize = 0; // Object does not take up any space. |
| 920 | |
| 921 | private: |
| 922 | DISALLOW_IMPLICIT_CONSTRUCTORS(Object); |
| 923 | }; |
| 924 | |
| 925 | |
| 926 | // Smi represents integer Numbers that can be stored in 31 bits. |
| 927 | // Smis are immediate which means they are NOT allocated in the heap. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 928 | // The this pointer has the following format: [31 bit signed int] 0 |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 929 | // For long smis it has the following format: |
| 930 | // [32 bit signed int] [31 bits zero padding] 0 |
| 931 | // Smi stands for small integer. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 932 | class Smi: public Object { |
| 933 | public: |
| 934 | // Returns the integer value. |
| 935 | inline int value(); |
| 936 | |
| 937 | // Convert a value to a Smi object. |
| 938 | static inline Smi* FromInt(int value); |
| 939 | |
| 940 | static inline Smi* FromIntptr(intptr_t value); |
| 941 | |
| 942 | // Returns whether value can be represented in a Smi. |
| 943 | static inline bool IsValid(intptr_t value); |
| 944 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 945 | // Casting. |
| 946 | static inline Smi* cast(Object* object); |
| 947 | |
| 948 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 949 | inline void SmiPrint() { |
| 950 | SmiPrint(stdout); |
| 951 | } |
| 952 | void SmiPrint(FILE* out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 953 | void SmiPrint(StringStream* accumulator); |
| 954 | #ifdef DEBUG |
| 955 | void SmiVerify(); |
| 956 | #endif |
| 957 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 958 | static const int kMinValue = (-1 << (kSmiValueSize - 1)); |
| 959 | static const int kMaxValue = -(kMinValue + 1); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 960 | |
| 961 | private: |
| 962 | DISALLOW_IMPLICIT_CONSTRUCTORS(Smi); |
| 963 | }; |
| 964 | |
| 965 | |
| 966 | // Failure is used for reporting out of memory situations and |
| 967 | // propagating exceptions through the runtime system. Failure objects |
| 968 | // are transient and cannot occur as part of the object graph. |
| 969 | // |
| 970 | // Failures are a single word, encoded as follows: |
| 971 | // +-------------------------+---+--+--+ |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 972 | // |.........unused..........|sss|tt|11| |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 973 | // +-------------------------+---+--+--+ |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 974 | // 7 6 4 32 10 |
| 975 | // |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 976 | // |
| 977 | // The low two bits, 0-1, are the failure tag, 11. The next two bits, |
| 978 | // 2-3, are a failure type tag 'tt' with possible values: |
| 979 | // 00 RETRY_AFTER_GC |
| 980 | // 01 EXCEPTION |
| 981 | // 10 INTERNAL_ERROR |
| 982 | // 11 OUT_OF_MEMORY_EXCEPTION |
| 983 | // |
| 984 | // The next three bits, 4-6, are an allocation space tag 'sss'. The |
| 985 | // allocation space tag is 000 for all failure types except |
| 986 | // RETRY_AFTER_GC. For RETRY_AFTER_GC, the possible values are the |
| 987 | // allocation spaces (the encoding is found in globals.h). |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 988 | |
| 989 | // Failure type tag info. |
| 990 | const int kFailureTypeTagSize = 2; |
| 991 | const int kFailureTypeTagMask = (1 << kFailureTypeTagSize) - 1; |
| 992 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 993 | class Failure: public MaybeObject { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 994 | public: |
| 995 | // RuntimeStubs assumes EXCEPTION = 1 in the compiler-generated code. |
| 996 | enum Type { |
| 997 | RETRY_AFTER_GC = 0, |
| 998 | EXCEPTION = 1, // Returning this marker tells the real exception |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 999 | // is in Isolate::pending_exception. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1000 | INTERNAL_ERROR = 2, |
| 1001 | OUT_OF_MEMORY_EXCEPTION = 3 |
| 1002 | }; |
| 1003 | |
| 1004 | inline Type type() const; |
| 1005 | |
| 1006 | // Returns the space that needs to be collected for RetryAfterGC failures. |
| 1007 | inline AllocationSpace allocation_space() const; |
| 1008 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1009 | inline bool IsInternalError() const; |
| 1010 | inline bool IsOutOfMemoryException() const; |
| 1011 | |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 1012 | static inline Failure* RetryAfterGC(AllocationSpace space); |
| 1013 | static inline Failure* RetryAfterGC(); // NEW_SPACE |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1014 | static inline Failure* Exception(); |
| 1015 | static inline Failure* InternalError(); |
| 1016 | static inline Failure* OutOfMemoryException(); |
| 1017 | // Casting. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1018 | static inline Failure* cast(MaybeObject* object); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1019 | |
| 1020 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1021 | inline void FailurePrint() { |
| 1022 | FailurePrint(stdout); |
| 1023 | } |
| 1024 | void FailurePrint(FILE* out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1025 | void FailurePrint(StringStream* accumulator); |
| 1026 | #ifdef DEBUG |
| 1027 | void FailureVerify(); |
| 1028 | #endif |
| 1029 | |
| 1030 | private: |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1031 | inline intptr_t value() const; |
| 1032 | static inline Failure* Construct(Type type, intptr_t value = 0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1033 | |
| 1034 | DISALLOW_IMPLICIT_CONSTRUCTORS(Failure); |
| 1035 | }; |
| 1036 | |
| 1037 | |
| 1038 | // Heap objects typically have a map pointer in their first word. However, |
| 1039 | // during GC other data (eg, mark bits, forwarding addresses) is sometimes |
| 1040 | // encoded in the first word. The class MapWord is an abstraction of the |
| 1041 | // value in a heap object's first word. |
| 1042 | class MapWord BASE_EMBEDDED { |
| 1043 | public: |
| 1044 | // Normal state: the map word contains a map pointer. |
| 1045 | |
| 1046 | // Create a map word from a map pointer. |
| 1047 | static inline MapWord FromMap(Map* map); |
| 1048 | |
| 1049 | // View this map word as a map pointer. |
| 1050 | inline Map* ToMap(); |
| 1051 | |
| 1052 | |
| 1053 | // Scavenge collection: the map word of live objects in the from space |
| 1054 | // contains a forwarding address (a heap object pointer in the to space). |
| 1055 | |
| 1056 | // True if this map word is a forwarding address for a scavenge |
| 1057 | // collection. Only valid during a scavenge collection (specifically, |
| 1058 | // when all map words are heap object pointers, ie. not during a full GC). |
| 1059 | inline bool IsForwardingAddress(); |
| 1060 | |
| 1061 | // Create a map word from a forwarding address. |
| 1062 | static inline MapWord FromForwardingAddress(HeapObject* object); |
| 1063 | |
| 1064 | // View this map word as a forwarding address. |
| 1065 | inline HeapObject* ToForwardingAddress(); |
| 1066 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1067 | // Marking phase of full collection: the map word of live objects is |
| 1068 | // marked, and may be marked as overflowed (eg, the object is live, its |
| 1069 | // children have not been visited, and it does not fit in the marking |
| 1070 | // stack). |
| 1071 | |
| 1072 | // True if this map word's mark bit is set. |
| 1073 | inline bool IsMarked(); |
| 1074 | |
| 1075 | // Return this map word but with its mark bit set. |
| 1076 | inline void SetMark(); |
| 1077 | |
| 1078 | // Return this map word but with its mark bit cleared. |
| 1079 | inline void ClearMark(); |
| 1080 | |
| 1081 | // True if this map word's overflow bit is set. |
| 1082 | inline bool IsOverflowed(); |
| 1083 | |
| 1084 | // Return this map word but with its overflow bit set. |
| 1085 | inline void SetOverflow(); |
| 1086 | |
| 1087 | // Return this map word but with its overflow bit cleared. |
| 1088 | inline void ClearOverflow(); |
| 1089 | |
| 1090 | |
| 1091 | // Compacting phase of a full compacting collection: the map word of live |
| 1092 | // objects contains an encoding of the original map address along with the |
| 1093 | // forwarding address (represented as an offset from the first live object |
| 1094 | // in the same page as the (old) object address). |
| 1095 | |
| 1096 | // Create a map word from a map address and a forwarding address offset. |
| 1097 | static inline MapWord EncodeAddress(Address map_address, int offset); |
| 1098 | |
| 1099 | // Return the map address encoded in this map word. |
| 1100 | inline Address DecodeMapAddress(MapSpace* map_space); |
| 1101 | |
| 1102 | // Return the forwarding offset encoded in this map word. |
| 1103 | inline int DecodeOffset(); |
| 1104 | |
| 1105 | |
| 1106 | // During serialization: the map word is used to hold an encoded |
| 1107 | // address, and possibly a mark bit (set and cleared with SetMark |
| 1108 | // and ClearMark). |
| 1109 | |
| 1110 | // Create a map word from an encoded address. |
| 1111 | static inline MapWord FromEncodedAddress(Address address); |
| 1112 | |
| 1113 | inline Address ToEncodedAddress(); |
| 1114 | |
| 1115 | // Bits used by the marking phase of the garbage collector. |
| 1116 | // |
| 1117 | // The first word of a heap object is normally a map pointer. The last two |
| 1118 | // bits are tagged as '01' (kHeapObjectTag). We reuse the last two bits to |
| 1119 | // mark an object as live and/or overflowed: |
| 1120 | // last bit = 0, marked as alive |
| 1121 | // second bit = 1, overflowed |
| 1122 | // An object is only marked as overflowed when it is marked as live while |
| 1123 | // the marking stack is overflowed. |
| 1124 | static const int kMarkingBit = 0; // marking bit |
| 1125 | static const int kMarkingMask = (1 << kMarkingBit); // marking mask |
| 1126 | static const int kOverflowBit = 1; // overflow bit |
| 1127 | static const int kOverflowMask = (1 << kOverflowBit); // overflow mask |
| 1128 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1129 | // Forwarding pointers and map pointer encoding. On 32 bit all the bits are |
| 1130 | // used. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1131 | // +-----------------+------------------+-----------------+ |
| 1132 | // |forwarding offset|page offset of map|page index of map| |
| 1133 | // +-----------------+------------------+-----------------+ |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1134 | // ^ ^ ^ |
| 1135 | // | | | |
| 1136 | // | | kMapPageIndexBits |
| 1137 | // | kMapPageOffsetBits |
| 1138 | // kForwardingOffsetBits |
| 1139 | static const int kMapPageOffsetBits = kPageSizeBits - kMapAlignmentBits; |
| 1140 | static const int kForwardingOffsetBits = kPageSizeBits - kObjectAlignmentBits; |
| 1141 | #ifdef V8_HOST_ARCH_64_BIT |
| 1142 | static const int kMapPageIndexBits = 16; |
| 1143 | #else |
| 1144 | // Use all the 32-bits to encode on a 32-bit platform. |
| 1145 | static const int kMapPageIndexBits = |
| 1146 | 32 - (kMapPageOffsetBits + kForwardingOffsetBits); |
| 1147 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1148 | |
| 1149 | static const int kMapPageIndexShift = 0; |
| 1150 | static const int kMapPageOffsetShift = |
| 1151 | kMapPageIndexShift + kMapPageIndexBits; |
| 1152 | static const int kForwardingOffsetShift = |
| 1153 | kMapPageOffsetShift + kMapPageOffsetBits; |
| 1154 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1155 | // Bit masks covering the different parts the encoding. |
| 1156 | static const uintptr_t kMapPageIndexMask = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1157 | (1 << kMapPageOffsetShift) - 1; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1158 | static const uintptr_t kMapPageOffsetMask = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1159 | ((1 << kForwardingOffsetShift) - 1) & ~kMapPageIndexMask; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1160 | static const uintptr_t kForwardingOffsetMask = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1161 | ~(kMapPageIndexMask | kMapPageOffsetMask); |
| 1162 | |
| 1163 | private: |
| 1164 | // HeapObject calls the private constructor and directly reads the value. |
| 1165 | friend class HeapObject; |
| 1166 | |
| 1167 | explicit MapWord(uintptr_t value) : value_(value) {} |
| 1168 | |
| 1169 | uintptr_t value_; |
| 1170 | }; |
| 1171 | |
| 1172 | |
| 1173 | // HeapObject is the superclass for all classes describing heap allocated |
| 1174 | // objects. |
| 1175 | class HeapObject: public Object { |
| 1176 | public: |
| 1177 | // [map]: Contains a map which contains the object's reflective |
| 1178 | // information. |
| 1179 | inline Map* map(); |
| 1180 | inline void set_map(Map* value); |
| 1181 | |
| 1182 | // During garbage collection, the map word of a heap object does not |
| 1183 | // necessarily contain a map pointer. |
| 1184 | inline MapWord map_word(); |
| 1185 | inline void set_map_word(MapWord map_word); |
| 1186 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1187 | // The Heap the object was allocated in. Used also to access Isolate. |
| 1188 | // This method can not be used during GC, it ASSERTs this. |
| 1189 | inline Heap* GetHeap(); |
| 1190 | // Convenience method to get current isolate. This method can be |
| 1191 | // accessed only when its result is the same as |
| 1192 | // Isolate::Current(), it ASSERTs this. See also comment for GetHeap. |
| 1193 | inline Isolate* GetIsolate(); |
| 1194 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1195 | // Converts an address to a HeapObject pointer. |
| 1196 | static inline HeapObject* FromAddress(Address address); |
| 1197 | |
| 1198 | // Returns the address of this HeapObject. |
| 1199 | inline Address address(); |
| 1200 | |
| 1201 | // Iterates over pointers contained in the object (including the Map) |
| 1202 | void Iterate(ObjectVisitor* v); |
| 1203 | |
| 1204 | // Iterates over all pointers contained in the object except the |
| 1205 | // first map pointer. The object type is given in the first |
| 1206 | // parameter. This function does not access the map pointer in the |
| 1207 | // object, and so is safe to call while the map pointer is modified. |
| 1208 | void IterateBody(InstanceType type, int object_size, ObjectVisitor* v); |
| 1209 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1210 | // Returns the heap object's size in bytes |
| 1211 | inline int Size(); |
| 1212 | |
| 1213 | // Given a heap object's map pointer, returns the heap size in bytes |
| 1214 | // Useful when the map pointer field is used for other purposes. |
| 1215 | // GC internal. |
| 1216 | inline int SizeFromMap(Map* map); |
| 1217 | |
| 1218 | // Support for the marking heap objects during the marking phase of GC. |
| 1219 | // True if the object is marked live. |
| 1220 | inline bool IsMarked(); |
| 1221 | |
| 1222 | // Mutate this object's map pointer to indicate that the object is live. |
| 1223 | inline void SetMark(); |
| 1224 | |
| 1225 | // Mutate this object's map pointer to remove the indication that the |
| 1226 | // object is live (ie, partially restore the map pointer). |
| 1227 | inline void ClearMark(); |
| 1228 | |
| 1229 | // True if this object is marked as overflowed. Overflowed objects have |
| 1230 | // been reached and marked during marking of the heap, but their children |
| 1231 | // have not necessarily been marked and they have not been pushed on the |
| 1232 | // marking stack. |
| 1233 | inline bool IsOverflowed(); |
| 1234 | |
| 1235 | // Mutate this object's map pointer to indicate that the object is |
| 1236 | // overflowed. |
| 1237 | inline void SetOverflow(); |
| 1238 | |
| 1239 | // Mutate this object's map pointer to remove the indication that the |
| 1240 | // object is overflowed (ie, partially restore the map pointer). |
| 1241 | inline void ClearOverflow(); |
| 1242 | |
| 1243 | // Returns the field at offset in obj, as a read/write Object* reference. |
| 1244 | // 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] | 1245 | // Does not invoke write barrier, so should only be assigned to |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1246 | // during marking GC. |
| 1247 | static inline Object** RawField(HeapObject* obj, int offset); |
| 1248 | |
| 1249 | // Casting. |
| 1250 | static inline HeapObject* cast(Object* obj); |
| 1251 | |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 1252 | // Return the write barrier mode for this. Callers of this function |
| 1253 | // must be able to present a reference to an AssertNoAllocation |
| 1254 | // object as a sign that they are not going to use this function |
| 1255 | // from code that allocates and thus invalidates the returned write |
| 1256 | // barrier mode. |
| 1257 | inline WriteBarrierMode GetWriteBarrierMode(const AssertNoAllocation&); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1258 | |
| 1259 | // Dispatched behavior. |
| 1260 | void HeapObjectShortPrint(StringStream* accumulator); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1261 | #ifdef OBJECT_PRINT |
| 1262 | inline void HeapObjectPrint() { |
| 1263 | HeapObjectPrint(stdout); |
| 1264 | } |
| 1265 | void HeapObjectPrint(FILE* out); |
| 1266 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1267 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1268 | void HeapObjectVerify(); |
| 1269 | inline void VerifyObjectField(int offset); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1270 | inline void VerifySmiField(int offset); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1271 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1272 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1273 | #ifdef OBJECT_PRINT |
| 1274 | void PrintHeader(FILE* out, const char* id); |
| 1275 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1276 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1277 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1278 | // Verify a pointer is a valid HeapObject pointer that points to object |
| 1279 | // areas in the heap. |
| 1280 | static void VerifyHeapPointer(Object* p); |
| 1281 | #endif |
| 1282 | |
| 1283 | // Layout description. |
| 1284 | // First field in a heap object is map. |
| 1285 | static const int kMapOffset = Object::kHeaderSize; |
| 1286 | static const int kHeaderSize = kMapOffset + kPointerSize; |
| 1287 | |
| 1288 | STATIC_CHECK(kMapOffset == Internals::kHeapObjectMapOffset); |
| 1289 | |
| 1290 | protected: |
| 1291 | // helpers for calling an ObjectVisitor to iterate over pointers in the |
| 1292 | // half-open range [start, end) specified as integer offsets |
| 1293 | inline void IteratePointers(ObjectVisitor* v, int start, int end); |
| 1294 | // as above, for the single element at "offset" |
| 1295 | inline void IteratePointer(ObjectVisitor* v, int offset); |
| 1296 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1297 | private: |
| 1298 | DISALLOW_IMPLICIT_CONSTRUCTORS(HeapObject); |
| 1299 | }; |
| 1300 | |
| 1301 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1302 | #define SLOT_ADDR(obj, offset) \ |
| 1303 | reinterpret_cast<Object**>((obj)->address() + offset) |
| 1304 | |
| 1305 | // This class describes a body of an object of a fixed size |
| 1306 | // in which all pointer fields are located in the [start_offset, end_offset) |
| 1307 | // interval. |
| 1308 | template<int start_offset, int end_offset, int size> |
| 1309 | class FixedBodyDescriptor { |
| 1310 | public: |
| 1311 | static const int kStartOffset = start_offset; |
| 1312 | static const int kEndOffset = end_offset; |
| 1313 | static const int kSize = size; |
| 1314 | |
| 1315 | static inline void IterateBody(HeapObject* obj, ObjectVisitor* v); |
| 1316 | |
| 1317 | template<typename StaticVisitor> |
| 1318 | static inline void IterateBody(HeapObject* obj) { |
| 1319 | StaticVisitor::VisitPointers(SLOT_ADDR(obj, start_offset), |
| 1320 | SLOT_ADDR(obj, end_offset)); |
| 1321 | } |
| 1322 | }; |
| 1323 | |
| 1324 | |
| 1325 | // This class describes a body of an object of a variable size |
| 1326 | // in which all pointer fields are located in the [start_offset, object_size) |
| 1327 | // interval. |
| 1328 | template<int start_offset> |
| 1329 | class FlexibleBodyDescriptor { |
| 1330 | public: |
| 1331 | static const int kStartOffset = start_offset; |
| 1332 | |
| 1333 | static inline void IterateBody(HeapObject* obj, |
| 1334 | int object_size, |
| 1335 | ObjectVisitor* v); |
| 1336 | |
| 1337 | template<typename StaticVisitor> |
| 1338 | static inline void IterateBody(HeapObject* obj, int object_size) { |
| 1339 | StaticVisitor::VisitPointers(SLOT_ADDR(obj, start_offset), |
| 1340 | SLOT_ADDR(obj, object_size)); |
| 1341 | } |
| 1342 | }; |
| 1343 | |
| 1344 | #undef SLOT_ADDR |
| 1345 | |
| 1346 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1347 | // The HeapNumber class describes heap allocated numbers that cannot be |
| 1348 | // represented in a Smi (small integer) |
| 1349 | class HeapNumber: public HeapObject { |
| 1350 | public: |
| 1351 | // [value]: number value. |
| 1352 | inline double value(); |
| 1353 | inline void set_value(double value); |
| 1354 | |
| 1355 | // Casting. |
| 1356 | static inline HeapNumber* cast(Object* obj); |
| 1357 | |
| 1358 | // Dispatched behavior. |
| 1359 | Object* HeapNumberToBoolean(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1360 | inline void HeapNumberPrint() { |
| 1361 | HeapNumberPrint(stdout); |
| 1362 | } |
| 1363 | void HeapNumberPrint(FILE* out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1364 | void HeapNumberPrint(StringStream* accumulator); |
| 1365 | #ifdef DEBUG |
| 1366 | void HeapNumberVerify(); |
| 1367 | #endif |
| 1368 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1369 | inline int get_exponent(); |
| 1370 | inline int get_sign(); |
| 1371 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1372 | // Layout description. |
| 1373 | static const int kValueOffset = HeapObject::kHeaderSize; |
| 1374 | // IEEE doubles are two 32 bit words. The first is just mantissa, the second |
| 1375 | // is a mixture of sign, exponent and mantissa. Our current platforms are all |
| 1376 | // little endian apart from non-EABI arm which is little endian with big |
| 1377 | // endian floating point word ordering! |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1378 | static const int kMantissaOffset = kValueOffset; |
| 1379 | static const int kExponentOffset = kValueOffset + 4; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1380 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1381 | static const int kSize = kValueOffset + kDoubleSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1382 | static const uint32_t kSignMask = 0x80000000u; |
| 1383 | static const uint32_t kExponentMask = 0x7ff00000u; |
| 1384 | static const uint32_t kMantissaMask = 0xfffffu; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1385 | static const int kMantissaBits = 52; |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 1386 | static const int kExponentBits = 11; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1387 | static const int kExponentBias = 1023; |
| 1388 | static const int kExponentShift = 20; |
| 1389 | static const int kMantissaBitsInTopWord = 20; |
| 1390 | static const int kNonMantissaBitsInTopWord = 12; |
| 1391 | |
| 1392 | private: |
| 1393 | DISALLOW_IMPLICIT_CONSTRUCTORS(HeapNumber); |
| 1394 | }; |
| 1395 | |
| 1396 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1397 | // JSReceiver includes types on which properties can be defined, i.e., |
| 1398 | // JSObject and JSProxy. |
| 1399 | class JSReceiver: public HeapObject { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1400 | public: |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1401 | enum DeleteMode { |
| 1402 | NORMAL_DELETION, |
| 1403 | STRICT_DELETION, |
| 1404 | FORCE_DELETION |
| 1405 | }; |
| 1406 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1407 | // Casting. |
| 1408 | static inline JSReceiver* cast(Object* obj); |
| 1409 | |
| 1410 | // Can cause GC. |
| 1411 | MUST_USE_RESULT MaybeObject* SetProperty(String* key, |
| 1412 | Object* value, |
| 1413 | PropertyAttributes attributes, |
| 1414 | StrictModeFlag strict_mode); |
| 1415 | MUST_USE_RESULT MaybeObject* SetProperty(LookupResult* result, |
| 1416 | String* key, |
| 1417 | Object* value, |
| 1418 | PropertyAttributes attributes, |
| 1419 | StrictModeFlag strict_mode); |
| 1420 | |
| 1421 | MUST_USE_RESULT MaybeObject* DeleteProperty(String* name, DeleteMode mode); |
| 1422 | |
| 1423 | // Returns the class name ([[Class]] property in the specification). |
| 1424 | String* class_name(); |
| 1425 | |
| 1426 | // Returns the constructor name (the name (possibly, inferred name) of the |
| 1427 | // function that was used to instantiate the object). |
| 1428 | String* constructor_name(); |
| 1429 | |
| 1430 | inline PropertyAttributes GetPropertyAttribute(String* name); |
| 1431 | PropertyAttributes GetPropertyAttributeWithReceiver(JSReceiver* receiver, |
| 1432 | String* name); |
| 1433 | PropertyAttributes GetLocalPropertyAttribute(String* name); |
| 1434 | |
| 1435 | // Can cause a GC. |
| 1436 | inline bool HasProperty(String* name); |
| 1437 | inline bool HasLocalProperty(String* name); |
| 1438 | |
| 1439 | // Return the object's prototype (might be Heap::null_value()). |
| 1440 | inline Object* GetPrototype(); |
| 1441 | |
| 1442 | // Set the object's prototype (only JSReceiver and null are allowed). |
| 1443 | MUST_USE_RESULT MaybeObject* SetPrototype(Object* value, |
| 1444 | bool skip_hidden_prototypes); |
| 1445 | |
| 1446 | // Lookup a property. If found, the result is valid and has |
| 1447 | // detailed information. |
| 1448 | void LocalLookup(String* name, LookupResult* result); |
| 1449 | void Lookup(String* name, LookupResult* result); |
| 1450 | |
| 1451 | private: |
| 1452 | PropertyAttributes GetPropertyAttribute(JSReceiver* receiver, |
| 1453 | LookupResult* result, |
| 1454 | String* name, |
| 1455 | bool continue_search); |
| 1456 | |
| 1457 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSReceiver); |
| 1458 | }; |
| 1459 | |
| 1460 | // The JSObject describes real heap allocated JavaScript objects with |
| 1461 | // properties. |
| 1462 | // Note that the map of JSObject changes during execution to enable inline |
| 1463 | // caching. |
| 1464 | class JSObject: public JSReceiver { |
| 1465 | public: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1466 | enum ElementsKind { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1467 | // The "fast" kind for tagged values. Must be first to make it possible |
| 1468 | // to efficiently check maps if they have fast elements. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1469 | FAST_ELEMENTS, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1470 | |
| 1471 | // The "fast" kind for unwrapped, non-tagged double values. |
| 1472 | FAST_DOUBLE_ELEMENTS, |
| 1473 | |
| 1474 | // The "slow" kind. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1475 | DICTIONARY_ELEMENTS, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1476 | NON_STRICT_ARGUMENTS_ELEMENTS, |
| 1477 | // The "fast" kind for external arrays |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1478 | EXTERNAL_BYTE_ELEMENTS, |
| 1479 | EXTERNAL_UNSIGNED_BYTE_ELEMENTS, |
| 1480 | EXTERNAL_SHORT_ELEMENTS, |
| 1481 | EXTERNAL_UNSIGNED_SHORT_ELEMENTS, |
| 1482 | EXTERNAL_INT_ELEMENTS, |
| 1483 | EXTERNAL_UNSIGNED_INT_ELEMENTS, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1484 | EXTERNAL_FLOAT_ELEMENTS, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1485 | EXTERNAL_DOUBLE_ELEMENTS, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1486 | EXTERNAL_PIXEL_ELEMENTS, |
| 1487 | |
| 1488 | // Derived constants from ElementsKind |
| 1489 | FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND = EXTERNAL_BYTE_ELEMENTS, |
| 1490 | LAST_EXTERNAL_ARRAY_ELEMENTS_KIND = EXTERNAL_PIXEL_ELEMENTS, |
| 1491 | FIRST_ELEMENTS_KIND = FAST_ELEMENTS, |
| 1492 | LAST_ELEMENTS_KIND = EXTERNAL_PIXEL_ELEMENTS |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1493 | }; |
| 1494 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1495 | static const int kElementsKindCount = |
| 1496 | LAST_ELEMENTS_KIND - FIRST_ELEMENTS_KIND + 1; |
| 1497 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1498 | // [properties]: Backing storage for properties. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1499 | // 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] | 1500 | // slow case. |
| 1501 | DECL_ACCESSORS(properties, FixedArray) // Get and set fast properties. |
| 1502 | inline void initialize_properties(); |
| 1503 | inline bool HasFastProperties(); |
| 1504 | inline StringDictionary* property_dictionary(); // Gets slow properties. |
| 1505 | |
| 1506 | // [elements]: The elements (properties with names that are integers). |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1507 | // |
| 1508 | // Elements can be in two general modes: fast and slow. Each mode |
| 1509 | // corrensponds to a set of object representations of elements that |
| 1510 | // have something in common. |
| 1511 | // |
| 1512 | // In the fast mode elements is a FixedArray and so each element can |
| 1513 | // be quickly accessed. This fact is used in the generated code. The |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1514 | // elements array can have one of three maps in this mode: |
| 1515 | // fixed_array_map, non_strict_arguments_elements_map or |
| 1516 | // fixed_cow_array_map (for copy-on-write arrays). In the latter case |
| 1517 | // the elements array may be shared by a few objects and so before |
| 1518 | // writing to any element the array must be copied. Use |
| 1519 | // EnsureWritableFastElements in this case. |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1520 | // |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1521 | // In the slow mode the elements is either a NumberDictionary, an |
| 1522 | // ExternalArray, or a FixedArray parameter map for a (non-strict) |
| 1523 | // arguments object. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 1524 | DECL_ACCESSORS(elements, FixedArrayBase) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1525 | inline void initialize_elements(); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1526 | MUST_USE_RESULT inline MaybeObject* ResetElements(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1527 | inline ElementsKind GetElementsKind(); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 1528 | inline ElementsAccessor* GetElementsAccessor(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1529 | inline bool HasFastElements(); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1530 | inline bool HasFastDoubleElements(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1531 | inline bool HasDictionaryElements(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1532 | inline bool HasExternalPixelElements(); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1533 | inline bool HasExternalArrayElements(); |
| 1534 | inline bool HasExternalByteElements(); |
| 1535 | inline bool HasExternalUnsignedByteElements(); |
| 1536 | inline bool HasExternalShortElements(); |
| 1537 | inline bool HasExternalUnsignedShortElements(); |
| 1538 | inline bool HasExternalIntElements(); |
| 1539 | inline bool HasExternalUnsignedIntElements(); |
| 1540 | inline bool HasExternalFloatElements(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1541 | inline bool HasExternalDoubleElements(); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1542 | bool HasFastArgumentsElements(); |
| 1543 | bool HasDictionaryArgumentsElements(); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1544 | inline bool AllowsSetElementsLength(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1545 | inline NumberDictionary* element_dictionary(); // Gets slow elements. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1546 | |
| 1547 | // Requires: HasFastElements(). |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1548 | MUST_USE_RESULT inline MaybeObject* EnsureWritableFastElements(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1549 | |
| 1550 | // Collects elements starting at index 0. |
| 1551 | // Undefined values are placed after non-undefined values. |
| 1552 | // Returns the number of non-undefined values. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1553 | MUST_USE_RESULT MaybeObject* PrepareElementsForSort(uint32_t limit); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1554 | // As PrepareElementsForSort, but only on objects where elements is |
| 1555 | // a dictionary, and it will stay a dictionary. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1556 | MUST_USE_RESULT MaybeObject* PrepareSlowElementsForSort(uint32_t limit); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1557 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1558 | MUST_USE_RESULT MaybeObject* SetPropertyForResult(LookupResult* result, |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1559 | String* key, |
| 1560 | Object* value, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1561 | PropertyAttributes attributes, |
| 1562 | StrictModeFlag strict_mode); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1563 | MUST_USE_RESULT MaybeObject* SetPropertyWithFailedAccessCheck( |
| 1564 | LookupResult* result, |
| 1565 | String* name, |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 1566 | Object* value, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1567 | bool check_prototype, |
| 1568 | StrictModeFlag strict_mode); |
| 1569 | MUST_USE_RESULT MaybeObject* SetPropertyWithCallback( |
| 1570 | Object* structure, |
| 1571 | String* name, |
| 1572 | Object* value, |
| 1573 | JSObject* holder, |
| 1574 | StrictModeFlag strict_mode); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1575 | MUST_USE_RESULT MaybeObject* SetPropertyWithDefinedSetter(JSFunction* setter, |
| 1576 | Object* value); |
| 1577 | MUST_USE_RESULT MaybeObject* SetPropertyWithInterceptor( |
| 1578 | String* name, |
| 1579 | Object* value, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1580 | PropertyAttributes attributes, |
| 1581 | StrictModeFlag strict_mode); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1582 | MUST_USE_RESULT MaybeObject* SetPropertyPostInterceptor( |
| 1583 | String* name, |
| 1584 | Object* value, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1585 | PropertyAttributes attributes, |
| 1586 | StrictModeFlag strict_mode); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 1587 | MUST_USE_RESULT MaybeObject* SetLocalPropertyIgnoreAttributes( |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1588 | String* key, |
| 1589 | Object* value, |
| 1590 | PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1591 | |
| 1592 | // Retrieve a value in a normalized object given a lookup result. |
| 1593 | // Handles the special representation of JS global objects. |
| 1594 | Object* GetNormalizedProperty(LookupResult* result); |
| 1595 | |
| 1596 | // Sets the property value in a normalized object given a lookup result. |
| 1597 | // Handles the special representation of JS global objects. |
| 1598 | Object* SetNormalizedProperty(LookupResult* result, Object* value); |
| 1599 | |
| 1600 | // Sets the property value in a normalized object given (key, value, details). |
| 1601 | // Handles the special representation of JS global objects. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1602 | MUST_USE_RESULT MaybeObject* SetNormalizedProperty(String* name, |
| 1603 | Object* value, |
| 1604 | PropertyDetails details); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1605 | |
| 1606 | // Deletes the named property in a normalized object. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1607 | MUST_USE_RESULT MaybeObject* DeleteNormalizedProperty(String* name, |
| 1608 | DeleteMode mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1609 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1610 | // Retrieve interceptors. |
| 1611 | InterceptorInfo* GetNamedInterceptor(); |
| 1612 | InterceptorInfo* GetIndexedInterceptor(); |
| 1613 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1614 | // Used from JSReceiver. |
| 1615 | PropertyAttributes GetPropertyAttributePostInterceptor(JSObject* receiver, |
| 1616 | String* name, |
| 1617 | bool continue_search); |
| 1618 | PropertyAttributes GetPropertyAttributeWithInterceptor(JSObject* receiver, |
| 1619 | String* name, |
| 1620 | bool continue_search); |
| 1621 | PropertyAttributes GetPropertyAttributeWithFailedAccessCheck( |
| 1622 | Object* receiver, |
| 1623 | LookupResult* result, |
| 1624 | String* name, |
| 1625 | bool continue_search); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1626 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1627 | MUST_USE_RESULT MaybeObject* DefineAccessor(String* name, |
| 1628 | bool is_getter, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1629 | Object* fun, |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1630 | PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1631 | Object* LookupAccessor(String* name, bool is_getter); |
| 1632 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1633 | MUST_USE_RESULT MaybeObject* DefineAccessor(AccessorInfo* info); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1634 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1635 | // Used from Object::GetProperty(). |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1636 | MaybeObject* GetPropertyWithFailedAccessCheck( |
| 1637 | Object* receiver, |
| 1638 | LookupResult* result, |
| 1639 | String* name, |
| 1640 | PropertyAttributes* attributes); |
| 1641 | MaybeObject* GetPropertyWithInterceptor( |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1642 | JSReceiver* receiver, |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1643 | String* name, |
| 1644 | PropertyAttributes* attributes); |
| 1645 | MaybeObject* GetPropertyPostInterceptor( |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1646 | JSReceiver* receiver, |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1647 | String* name, |
| 1648 | PropertyAttributes* attributes); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1649 | MaybeObject* GetLocalPropertyPostInterceptor(JSReceiver* receiver, |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1650 | String* name, |
| 1651 | PropertyAttributes* attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1652 | |
| 1653 | // Returns true if this is an instance of an api function and has |
| 1654 | // been modified since it was created. May give false positives. |
| 1655 | bool IsDirty(); |
| 1656 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1657 | // If the receiver is a JSGlobalProxy this method will return its prototype, |
| 1658 | // otherwise the result is the receiver itself. |
| 1659 | inline Object* BypassGlobalProxy(); |
| 1660 | |
| 1661 | // Accessors for hidden properties object. |
| 1662 | // |
| 1663 | // Hidden properties are not local properties of the object itself. |
| 1664 | // Instead they are stored on an auxiliary JSObject stored as a local |
| 1665 | // property with a special name Heap::hidden_symbol(). But if the |
| 1666 | // receiver is a JSGlobalProxy then the auxiliary object is a property |
| 1667 | // of its prototype. |
| 1668 | // |
| 1669 | // Has/Get/SetHiddenPropertiesObject methods don't allow the holder to be |
| 1670 | // a JSGlobalProxy. Use BypassGlobalProxy method above to get to the real |
| 1671 | // holder. |
| 1672 | // |
| 1673 | // These accessors do not touch interceptors or accessors. |
| 1674 | inline bool HasHiddenPropertiesObject(); |
| 1675 | inline Object* GetHiddenPropertiesObject(); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1676 | MUST_USE_RESULT inline MaybeObject* SetHiddenPropertiesObject( |
| 1677 | Object* hidden_obj); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1678 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 1679 | // Indicates whether the hidden properties object should be created. |
| 1680 | enum HiddenPropertiesFlag { ALLOW_CREATION, OMIT_CREATION }; |
| 1681 | |
| 1682 | // Retrieves the hidden properties object. |
| 1683 | // |
| 1684 | // The undefined value might be returned in case no hidden properties object |
| 1685 | // is present and creation was omitted. |
| 1686 | inline bool HasHiddenProperties(); |
| 1687 | MUST_USE_RESULT MaybeObject* GetHiddenProperties(HiddenPropertiesFlag flag); |
| 1688 | |
| 1689 | // Retrieves a permanent object identity hash code. |
| 1690 | // |
| 1691 | // The identity hash is stored as a hidden property. The undefined value might |
| 1692 | // be returned in case no hidden properties object is present and creation was |
| 1693 | // omitted. |
| 1694 | MUST_USE_RESULT MaybeObject* GetIdentityHash(HiddenPropertiesFlag flag); |
| 1695 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1696 | MUST_USE_RESULT MaybeObject* DeleteProperty(String* name, DeleteMode mode); |
| 1697 | MUST_USE_RESULT MaybeObject* DeleteElement(uint32_t index, DeleteMode mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1698 | |
| 1699 | // Tests for the fast common case for property enumeration. |
| 1700 | bool IsSimpleEnum(); |
| 1701 | |
| 1702 | // Do we want to keep the elements in fast case when increasing the |
| 1703 | // capacity? |
| 1704 | bool ShouldConvertToSlowElements(int new_capacity); |
| 1705 | // Returns true if the backing storage for the slow-case elements of |
| 1706 | // this object takes up nearly as much space as a fast-case backing |
| 1707 | // storage would. In that case the JSObject should have fast |
| 1708 | // elements. |
| 1709 | bool ShouldConvertToFastElements(); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1710 | // Returns true if the elements of JSObject contains only values that can be |
| 1711 | // represented in a FixedDoubleArray. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 1712 | bool CanConvertToFastDoubleElements(); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1713 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1714 | // Tells whether the index'th element is present. |
| 1715 | inline bool HasElement(uint32_t index); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1716 | bool HasElementWithReceiver(JSReceiver* receiver, uint32_t index); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1717 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1718 | // Computes the new capacity when expanding the elements of a JSObject. |
| 1719 | static int NewElementsCapacity(int old_capacity) { |
| 1720 | // (old_capacity + 50%) + 16 |
| 1721 | return old_capacity + (old_capacity >> 1) + 16; |
| 1722 | } |
| 1723 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1724 | // Tells whether the index'th element is present and how it is stored. |
| 1725 | enum LocalElementType { |
| 1726 | // There is no element with given index. |
| 1727 | UNDEFINED_ELEMENT, |
| 1728 | |
| 1729 | // Element with given index is handled by interceptor. |
| 1730 | INTERCEPTED_ELEMENT, |
| 1731 | |
| 1732 | // Element with given index is character in string. |
| 1733 | STRING_CHARACTER_ELEMENT, |
| 1734 | |
| 1735 | // Element with given index is stored in fast backing store. |
| 1736 | FAST_ELEMENT, |
| 1737 | |
| 1738 | // Element with given index is stored in slow backing store. |
| 1739 | DICTIONARY_ELEMENT |
| 1740 | }; |
| 1741 | |
| 1742 | LocalElementType HasLocalElement(uint32_t index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1743 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1744 | bool HasElementWithInterceptor(JSReceiver* receiver, uint32_t index); |
| 1745 | bool HasElementPostInterceptor(JSReceiver* receiver, uint32_t index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1746 | |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 1747 | MUST_USE_RESULT MaybeObject* SetFastElement(uint32_t index, |
| 1748 | Object* value, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1749 | StrictModeFlag strict_mode, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1750 | bool check_prototype); |
| 1751 | MUST_USE_RESULT MaybeObject* SetDictionaryElement(uint32_t index, |
| 1752 | Object* value, |
| 1753 | StrictModeFlag strict_mode, |
| 1754 | bool check_prototype); |
| 1755 | |
| 1756 | MUST_USE_RESULT MaybeObject* SetFastDoubleElement( |
| 1757 | uint32_t index, |
| 1758 | Object* value, |
| 1759 | StrictModeFlag strict_mode, |
| 1760 | bool check_prototype = true); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1761 | |
| 1762 | // Set the index'th array element. |
| 1763 | // A Failure object is returned if GC is needed. |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 1764 | MUST_USE_RESULT MaybeObject* SetElement(uint32_t index, |
| 1765 | Object* value, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1766 | StrictModeFlag strict_mode, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1767 | bool check_prototype); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1768 | |
| 1769 | // Returns the index'th element. |
| 1770 | // The undefined object if index is out of bounds. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1771 | MaybeObject* GetElementWithInterceptor(Object* receiver, uint32_t index); |
| 1772 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1773 | // Replace the elements' backing store with fast elements of the given |
| 1774 | // capacity. Update the length for JSArrays. Returns the new backing |
| 1775 | // store. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1776 | MUST_USE_RESULT MaybeObject* SetFastElementsCapacityAndLength(int capacity, |
| 1777 | int length); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1778 | MUST_USE_RESULT MaybeObject* SetFastDoubleElementsCapacityAndLength( |
| 1779 | int capacity, |
| 1780 | int length); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1781 | MUST_USE_RESULT MaybeObject* SetSlowElements(Object* length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1782 | |
| 1783 | // Lookup interceptors are used for handling properties controlled by host |
| 1784 | // objects. |
| 1785 | inline bool HasNamedInterceptor(); |
| 1786 | inline bool HasIndexedInterceptor(); |
| 1787 | |
| 1788 | // Support functions for v8 api (needed for correct interceptor behavior). |
| 1789 | bool HasRealNamedProperty(String* key); |
| 1790 | bool HasRealElementProperty(uint32_t index); |
| 1791 | bool HasRealNamedCallbackProperty(String* key); |
| 1792 | |
| 1793 | // Initializes the array to a certain length |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1794 | MUST_USE_RESULT MaybeObject* SetElementsLength(Object* length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1795 | |
| 1796 | // Get the header size for a JSObject. Used to compute the index of |
| 1797 | // internal fields as well as the number of internal fields. |
| 1798 | inline int GetHeaderSize(); |
| 1799 | |
| 1800 | inline int GetInternalFieldCount(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1801 | inline int GetInternalFieldOffset(int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1802 | inline Object* GetInternalField(int index); |
| 1803 | inline void SetInternalField(int index, Object* value); |
| 1804 | |
| 1805 | // Lookup a property. If found, the result is valid and has |
| 1806 | // detailed information. |
| 1807 | void LocalLookup(String* name, LookupResult* result); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1808 | |
| 1809 | // The following lookup functions skip interceptors. |
| 1810 | void LocalLookupRealNamedProperty(String* name, LookupResult* result); |
| 1811 | void LookupRealNamedProperty(String* name, LookupResult* result); |
| 1812 | void LookupRealNamedPropertyInPrototypes(String* name, LookupResult* result); |
| 1813 | void LookupCallbackSetterInPrototypes(String* name, LookupResult* result); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1814 | MUST_USE_RESULT MaybeObject* SetElementWithCallbackSetterInPrototypes( |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1815 | uint32_t index, Object* value, bool* found, StrictModeFlag strict_mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1816 | void LookupCallback(String* name, LookupResult* result); |
| 1817 | |
| 1818 | // Returns the number of properties on this object filtering out properties |
| 1819 | // with the specified attributes (ignoring interceptors). |
| 1820 | int NumberOfLocalProperties(PropertyAttributes filter); |
| 1821 | // Returns the number of enumerable properties (ignoring interceptors). |
| 1822 | int NumberOfEnumProperties(); |
| 1823 | // Fill in details for properties into storage starting at the specified |
| 1824 | // index. |
| 1825 | void GetLocalPropertyNames(FixedArray* storage, int index); |
| 1826 | |
| 1827 | // Returns the number of properties on this object filtering out properties |
| 1828 | // with the specified attributes (ignoring interceptors). |
| 1829 | int NumberOfLocalElements(PropertyAttributes filter); |
| 1830 | // Returns the number of enumerable elements (ignoring interceptors). |
| 1831 | int NumberOfEnumElements(); |
| 1832 | // Returns the number of elements on this object filtering out elements |
| 1833 | // with the specified attributes (ignoring interceptors). |
| 1834 | int GetLocalElementKeys(FixedArray* storage, PropertyAttributes filter); |
| 1835 | // Count and fill in the enumerable elements into storage. |
| 1836 | // (storage->length() == NumberOfEnumElements()). |
| 1837 | // If storage is NULL, will count the elements without adding |
| 1838 | // them to any storage. |
| 1839 | // Returns the number of enumerable elements. |
| 1840 | int GetEnumElementKeys(FixedArray* storage); |
| 1841 | |
| 1842 | // Add a property to a fast-case object using a map transition to |
| 1843 | // new_map. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1844 | MUST_USE_RESULT MaybeObject* AddFastPropertyUsingMap(Map* new_map, |
| 1845 | String* name, |
| 1846 | Object* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1847 | |
| 1848 | // Add a constant function property to a fast-case object. |
| 1849 | // This leaves a CONSTANT_TRANSITION in the old map, and |
| 1850 | // if it is called on a second object with this map, a |
| 1851 | // normal property is added instead, with a map transition. |
| 1852 | // This avoids the creation of many maps with the same constant |
| 1853 | // function, all orphaned. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1854 | MUST_USE_RESULT MaybeObject* AddConstantFunctionProperty( |
| 1855 | String* name, |
| 1856 | JSFunction* function, |
| 1857 | PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1858 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1859 | MUST_USE_RESULT MaybeObject* ReplaceSlowProperty( |
| 1860 | String* name, |
| 1861 | Object* value, |
| 1862 | PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1863 | |
| 1864 | // Converts a descriptor of any other type to a real field, |
| 1865 | // backed by the properties array. Descriptors of visible |
| 1866 | // types, such as CONSTANT_FUNCTION, keep their enumeration order. |
| 1867 | // Converts the descriptor on the original object's map to a |
| 1868 | // 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] | 1869 | MUST_USE_RESULT MaybeObject* ConvertDescriptorToFieldAndMapTransition( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1870 | String* name, |
| 1871 | Object* new_value, |
| 1872 | PropertyAttributes attributes); |
| 1873 | |
| 1874 | // Converts a descriptor of any other type to a real field, |
| 1875 | // backed by the properties array. Descriptors of visible |
| 1876 | // types, such as CONSTANT_FUNCTION, keep their enumeration order. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1877 | MUST_USE_RESULT MaybeObject* ConvertDescriptorToField( |
| 1878 | String* name, |
| 1879 | Object* new_value, |
| 1880 | PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1881 | |
| 1882 | // Add a property to a fast-case object. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1883 | MUST_USE_RESULT MaybeObject* AddFastProperty(String* name, |
| 1884 | Object* value, |
| 1885 | PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1886 | |
| 1887 | // Add a property to a slow-case object. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1888 | MUST_USE_RESULT MaybeObject* AddSlowProperty(String* name, |
| 1889 | Object* value, |
| 1890 | PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1891 | |
| 1892 | // Add a property to an object. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1893 | MUST_USE_RESULT MaybeObject* AddProperty(String* name, |
| 1894 | Object* value, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1895 | PropertyAttributes attributes, |
| 1896 | StrictModeFlag strict_mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1897 | |
| 1898 | // Convert the object to use the canonical dictionary |
| 1899 | // representation. If the object is expected to have additional properties |
| 1900 | // added this number can be indicated to have the backing store allocated to |
| 1901 | // an initial capacity for holding these properties. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1902 | MUST_USE_RESULT MaybeObject* NormalizeProperties( |
| 1903 | PropertyNormalizationMode mode, |
| 1904 | int expected_additional_properties); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1905 | |
| 1906 | // Convert and update the elements backing store to be a NumberDictionary |
| 1907 | // dictionary. Returns the backing after conversion. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1908 | MUST_USE_RESULT MaybeObject* NormalizeElements(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1909 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1910 | MUST_USE_RESULT MaybeObject* UpdateMapCodeCache(String* name, Code* code); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1911 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1912 | // Transform slow named properties to fast variants. |
| 1913 | // Returns failure if allocation failed. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1914 | MUST_USE_RESULT MaybeObject* TransformToFastProperties( |
| 1915 | int unused_property_fields); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1916 | |
| 1917 | // Access fast-case object properties at index. |
| 1918 | inline Object* FastPropertyAt(int index); |
| 1919 | inline Object* FastPropertyAtPut(int index, Object* value); |
| 1920 | |
| 1921 | // Access to in object properties. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1922 | inline int GetInObjectPropertyOffset(int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1923 | inline Object* InObjectPropertyAt(int index); |
| 1924 | inline Object* InObjectPropertyAtPut(int index, |
| 1925 | Object* value, |
| 1926 | WriteBarrierMode mode |
| 1927 | = UPDATE_WRITE_BARRIER); |
| 1928 | |
| 1929 | // initializes the body after properties slot, properties slot is |
| 1930 | // initialized by set_properties |
| 1931 | // Note: this call does not update write barrier, it is caller's |
| 1932 | // reponsibility to ensure that *v* can be collected without WB here. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1933 | inline void InitializeBody(int object_size, Object* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1934 | |
| 1935 | // Check whether this object references another object |
| 1936 | bool ReferencesObject(Object* obj); |
| 1937 | |
| 1938 | // Casting. |
| 1939 | static inline JSObject* cast(Object* obj); |
| 1940 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1941 | // Disalow further properties to be added to the object. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1942 | MUST_USE_RESULT MaybeObject* PreventExtensions(); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1943 | |
| 1944 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1945 | // Dispatched behavior. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1946 | void JSObjectShortPrint(StringStream* accumulator); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1947 | #ifdef OBJECT_PRINT |
| 1948 | inline void JSObjectPrint() { |
| 1949 | JSObjectPrint(stdout); |
| 1950 | } |
| 1951 | void JSObjectPrint(FILE* out); |
| 1952 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1953 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1954 | void JSObjectVerify(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1955 | #endif |
| 1956 | #ifdef OBJECT_PRINT |
| 1957 | inline void PrintProperties() { |
| 1958 | PrintProperties(stdout); |
| 1959 | } |
| 1960 | void PrintProperties(FILE* out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1961 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1962 | inline void PrintElements() { |
| 1963 | PrintElements(stdout); |
| 1964 | } |
| 1965 | void PrintElements(FILE* out); |
| 1966 | #endif |
| 1967 | |
| 1968 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1969 | // Structure for collecting spill information about JSObjects. |
| 1970 | class SpillInformation { |
| 1971 | public: |
| 1972 | void Clear(); |
| 1973 | void Print(); |
| 1974 | int number_of_objects_; |
| 1975 | int number_of_objects_with_fast_properties_; |
| 1976 | int number_of_objects_with_fast_elements_; |
| 1977 | int number_of_fast_used_fields_; |
| 1978 | int number_of_fast_unused_fields_; |
| 1979 | int number_of_slow_used_properties_; |
| 1980 | int number_of_slow_unused_properties_; |
| 1981 | int number_of_fast_used_elements_; |
| 1982 | int number_of_fast_unused_elements_; |
| 1983 | int number_of_slow_used_elements_; |
| 1984 | int number_of_slow_unused_elements_; |
| 1985 | }; |
| 1986 | |
| 1987 | void IncrementSpillStatistics(SpillInformation* info); |
| 1988 | #endif |
| 1989 | Object* SlowReverseLookup(Object* value); |
| 1990 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1991 | // Maximal number of fast properties for the JSObject. Used to |
| 1992 | // restrict the number of map transitions to avoid an explosion in |
| 1993 | // the number of maps for objects used as dictionaries. |
| 1994 | inline int MaxFastProperties(); |
| 1995 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1996 | // Maximal number of elements (numbered 0 .. kMaxElementCount - 1). |
| 1997 | // Also maximal value of JSArray's length property. |
| 1998 | static const uint32_t kMaxElementCount = 0xffffffffu; |
| 1999 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 2000 | // Constants for heuristics controlling conversion of fast elements |
| 2001 | // to slow elements. |
| 2002 | |
| 2003 | // Maximal gap that can be introduced by adding an element beyond |
| 2004 | // the current elements length. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2005 | static const uint32_t kMaxGap = 1024; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 2006 | |
| 2007 | // Maximal length of fast elements array that won't be checked for |
| 2008 | // being dense enough on expansion. |
| 2009 | static const int kMaxUncheckedFastElementsLength = 5000; |
| 2010 | |
| 2011 | // Same as above but for old arrays. This limit is more strict. We |
| 2012 | // don't want to be wasteful with long lived objects. |
| 2013 | static const int kMaxUncheckedOldFastElementsLength = 500; |
| 2014 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2015 | static const int kInitialMaxFastElementArray = 100000; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2016 | static const int kMaxFastProperties = 12; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2017 | static const int kMaxInstanceSize = 255 * kPointerSize; |
| 2018 | // When extending the backing storage for property values, we increase |
| 2019 | // its size by more than the 1 entry necessary, so sequentially adding fields |
| 2020 | // to the same object requires fewer allocations and copies. |
| 2021 | static const int kFieldsAdded = 3; |
| 2022 | |
| 2023 | // Layout description. |
| 2024 | static const int kPropertiesOffset = HeapObject::kHeaderSize; |
| 2025 | static const int kElementsOffset = kPropertiesOffset + kPointerSize; |
| 2026 | static const int kHeaderSize = kElementsOffset + kPointerSize; |
| 2027 | |
| 2028 | STATIC_CHECK(kHeaderSize == Internals::kJSObjectHeaderSize); |
| 2029 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2030 | class BodyDescriptor : public FlexibleBodyDescriptor<kPropertiesOffset> { |
| 2031 | public: |
| 2032 | static inline int SizeOf(Map* map, HeapObject* object); |
| 2033 | }; |
| 2034 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2035 | private: |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 2036 | friend class DictionaryElementsAccessor; |
| 2037 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2038 | MUST_USE_RESULT MaybeObject* GetElementWithCallback(Object* receiver, |
| 2039 | Object* structure, |
| 2040 | uint32_t index, |
| 2041 | Object* holder); |
| 2042 | MaybeObject* SetElementWithCallback(Object* structure, |
| 2043 | uint32_t index, |
| 2044 | Object* value, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2045 | JSObject* holder, |
| 2046 | StrictModeFlag strict_mode); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2047 | MUST_USE_RESULT MaybeObject* SetElementWithInterceptor( |
| 2048 | uint32_t index, |
| 2049 | Object* value, |
| 2050 | StrictModeFlag strict_mode, |
| 2051 | bool check_prototype); |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 2052 | MUST_USE_RESULT MaybeObject* SetElementWithoutInterceptor( |
| 2053 | uint32_t index, |
| 2054 | Object* value, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2055 | StrictModeFlag strict_mode, |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 2056 | bool check_prototype); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2057 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2058 | MUST_USE_RESULT MaybeObject* DeletePropertyPostInterceptor(String* name, |
| 2059 | DeleteMode mode); |
| 2060 | MUST_USE_RESULT MaybeObject* DeletePropertyWithInterceptor(String* name); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2061 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2062 | MUST_USE_RESULT MaybeObject* DeleteElementWithInterceptor(uint32_t index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2063 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2064 | MUST_USE_RESULT MaybeObject* DeleteFastElement(uint32_t index); |
| 2065 | MUST_USE_RESULT MaybeObject* DeleteDictionaryElement(uint32_t index, |
| 2066 | DeleteMode mode); |
| 2067 | |
| 2068 | bool ReferencesObjectFromElements(FixedArray* elements, |
| 2069 | ElementsKind kind, |
| 2070 | Object* object); |
| 2071 | bool HasElementInElements(FixedArray* elements, |
| 2072 | ElementsKind kind, |
| 2073 | uint32_t index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2074 | |
| 2075 | // Returns true if most of the elements backing storage is used. |
| 2076 | bool HasDenseElements(); |
| 2077 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 2078 | // Gets the current elements capacity and the number of used elements. |
| 2079 | void GetElementsCapacityAndUsage(int* capacity, int* used); |
| 2080 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2081 | bool CanSetCallback(String* name); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2082 | MUST_USE_RESULT MaybeObject* SetElementCallback( |
| 2083 | uint32_t index, |
| 2084 | Object* structure, |
| 2085 | PropertyAttributes attributes); |
| 2086 | MUST_USE_RESULT MaybeObject* SetPropertyCallback( |
| 2087 | String* name, |
| 2088 | Object* structure, |
| 2089 | PropertyAttributes attributes); |
| 2090 | MUST_USE_RESULT MaybeObject* DefineGetterSetter( |
| 2091 | String* name, |
| 2092 | PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2093 | |
| 2094 | void LookupInDescriptor(String* name, LookupResult* result); |
| 2095 | |
| 2096 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSObject); |
| 2097 | }; |
| 2098 | |
| 2099 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2100 | // Common superclass for FixedArrays that allow implementations to share |
| 2101 | // common accessors and some code paths. |
| 2102 | class FixedArrayBase: public HeapObject { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2103 | public: |
| 2104 | // [length]: length of the array. |
| 2105 | inline int length(); |
| 2106 | inline void set_length(int value); |
| 2107 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2108 | inline static FixedArrayBase* cast(Object* object); |
| 2109 | |
| 2110 | // Layout description. |
| 2111 | // Length is smi tagged when it is stored. |
| 2112 | static const int kLengthOffset = HeapObject::kHeaderSize; |
| 2113 | static const int kHeaderSize = kLengthOffset + kPointerSize; |
| 2114 | }; |
| 2115 | |
| 2116 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 2117 | class FixedDoubleArray; |
| 2118 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2119 | // FixedArray describes fixed-sized arrays with element type Object*. |
| 2120 | class FixedArray: public FixedArrayBase { |
| 2121 | public: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2122 | // Setter and getter for elements. |
| 2123 | inline Object* get(int index); |
| 2124 | // Setter that uses write barrier. |
| 2125 | inline void set(int index, Object* value); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 2126 | inline bool is_the_hole(int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2127 | |
| 2128 | // Setter that doesn't need write barrier). |
| 2129 | inline void set(int index, Smi* value); |
| 2130 | // Setter with explicit barrier mode. |
| 2131 | inline void set(int index, Object* value, WriteBarrierMode mode); |
| 2132 | |
| 2133 | // Setters for frequently used oddballs located in old space. |
| 2134 | inline void set_undefined(int index); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2135 | // TODO(isolates): duplicate. |
| 2136 | inline void set_undefined(Heap* heap, int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2137 | inline void set_null(int index); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2138 | // TODO(isolates): duplicate. |
| 2139 | inline void set_null(Heap* heap, int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2140 | inline void set_the_hole(int index); |
| 2141 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2142 | // Setters with less debug checks for the GC to use. |
| 2143 | inline void set_unchecked(int index, Smi* value); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2144 | inline void set_null_unchecked(Heap* heap, int index); |
| 2145 | inline void set_unchecked(Heap* heap, int index, Object* value, |
| 2146 | WriteBarrierMode mode); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2147 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2148 | // Gives access to raw memory which stores the array's data. |
| 2149 | inline Object** data_start(); |
| 2150 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2151 | // Copy operations. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2152 | MUST_USE_RESULT inline MaybeObject* Copy(); |
| 2153 | MUST_USE_RESULT MaybeObject* CopySize(int new_length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2154 | |
| 2155 | // Add the elements of a JSArray to this FixedArray. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2156 | MUST_USE_RESULT MaybeObject* AddKeysFromJSArray(JSArray* array); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2157 | |
| 2158 | // Compute the union of this and other. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2159 | MUST_USE_RESULT MaybeObject* UnionOfKeys(FixedArray* other); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2160 | |
| 2161 | // Copy a sub array from the receiver to dest. |
| 2162 | void CopyTo(int pos, FixedArray* dest, int dest_pos, int len); |
| 2163 | |
| 2164 | // Garbage collection support. |
| 2165 | static int SizeFor(int length) { return kHeaderSize + length * kPointerSize; } |
| 2166 | |
| 2167 | // Code Generation support. |
| 2168 | static int OffsetOfElementAt(int index) { return SizeFor(index); } |
| 2169 | |
| 2170 | // Casting. |
| 2171 | static inline FixedArray* cast(Object* obj); |
| 2172 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2173 | // Maximal allowed size, in bytes, of a single FixedArray. |
| 2174 | // Prevents overflowing size computations, as well as extreme memory |
| 2175 | // consumption. |
| 2176 | static const int kMaxSize = 512 * MB; |
| 2177 | // Maximally allowed length of a FixedArray. |
| 2178 | static const int kMaxLength = (kMaxSize - kHeaderSize) / kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2179 | |
| 2180 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2181 | #ifdef OBJECT_PRINT |
| 2182 | inline void FixedArrayPrint() { |
| 2183 | FixedArrayPrint(stdout); |
| 2184 | } |
| 2185 | void FixedArrayPrint(FILE* out); |
| 2186 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2187 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2188 | void FixedArrayVerify(); |
| 2189 | // Checks if two FixedArrays have identical contents. |
| 2190 | bool IsEqualTo(FixedArray* other); |
| 2191 | #endif |
| 2192 | |
| 2193 | // Swap two elements in a pair of arrays. If this array and the |
| 2194 | // numbers array are the same object, the elements are only swapped |
| 2195 | // once. |
| 2196 | void SwapPairs(FixedArray* numbers, int i, int j); |
| 2197 | |
| 2198 | // Sort prefix of this array and the numbers array as pairs wrt. the |
| 2199 | // numbers. If the numbers array and the this array are the same |
| 2200 | // object, the prefix of this array is sorted. |
| 2201 | void SortPairs(FixedArray* numbers, uint32_t len); |
| 2202 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2203 | class BodyDescriptor : public FlexibleBodyDescriptor<kHeaderSize> { |
| 2204 | public: |
| 2205 | static inline int SizeOf(Map* map, HeapObject* object) { |
| 2206 | return SizeFor(reinterpret_cast<FixedArray*>(object)->length()); |
| 2207 | } |
| 2208 | }; |
| 2209 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2210 | protected: |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 2211 | // Set operation on FixedArray without using write barriers. Can |
| 2212 | // only be used for storing old space objects or smis. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2213 | static inline void fast_set(FixedArray* array, int index, Object* value); |
| 2214 | |
| 2215 | private: |
| 2216 | DISALLOW_IMPLICIT_CONSTRUCTORS(FixedArray); |
| 2217 | }; |
| 2218 | |
| 2219 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2220 | // FixedDoubleArray describes fixed-sized arrays with element type double. |
| 2221 | class FixedDoubleArray: public FixedArrayBase { |
| 2222 | public: |
| 2223 | inline void Initialize(FixedArray* from); |
| 2224 | inline void Initialize(FixedDoubleArray* from); |
| 2225 | inline void Initialize(NumberDictionary* from); |
| 2226 | |
| 2227 | // Setter and getter for elements. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 2228 | inline double get_scalar(int index); |
| 2229 | inline MaybeObject* get(int index); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2230 | inline void set(int index, double value); |
| 2231 | inline void set_the_hole(int index); |
| 2232 | |
| 2233 | // Checking for the hole. |
| 2234 | inline bool is_the_hole(int index); |
| 2235 | |
| 2236 | // Garbage collection support. |
| 2237 | inline static int SizeFor(int length) { |
| 2238 | return kHeaderSize + length * kDoubleSize; |
| 2239 | } |
| 2240 | |
| 2241 | // Code Generation support. |
| 2242 | static int OffsetOfElementAt(int index) { return SizeFor(index); } |
| 2243 | |
| 2244 | inline static bool is_the_hole_nan(double value); |
| 2245 | inline static double hole_nan_as_double(); |
| 2246 | inline static double canonical_not_the_hole_nan_as_double(); |
| 2247 | |
| 2248 | // Casting. |
| 2249 | static inline FixedDoubleArray* cast(Object* obj); |
| 2250 | |
| 2251 | // Maximal allowed size, in bytes, of a single FixedDoubleArray. |
| 2252 | // Prevents overflowing size computations, as well as extreme memory |
| 2253 | // consumption. |
| 2254 | static const int kMaxSize = 512 * MB; |
| 2255 | // Maximally allowed length of a FixedArray. |
| 2256 | static const int kMaxLength = (kMaxSize - kHeaderSize) / kDoubleSize; |
| 2257 | |
| 2258 | // Dispatched behavior. |
| 2259 | #ifdef OBJECT_PRINT |
| 2260 | inline void FixedDoubleArrayPrint() { |
| 2261 | FixedDoubleArrayPrint(stdout); |
| 2262 | } |
| 2263 | void FixedDoubleArrayPrint(FILE* out); |
| 2264 | #endif |
| 2265 | |
| 2266 | #ifdef DEBUG |
| 2267 | void FixedDoubleArrayVerify(); |
| 2268 | #endif |
| 2269 | |
| 2270 | private: |
| 2271 | DISALLOW_IMPLICIT_CONSTRUCTORS(FixedDoubleArray); |
| 2272 | }; |
| 2273 | |
| 2274 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2275 | // DescriptorArrays are fixed arrays used to hold instance descriptors. |
| 2276 | // The format of the these objects is: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2277 | // TODO(1399): It should be possible to make room for bit_field3 in the map |
| 2278 | // without overloading the instance descriptors field in the map |
| 2279 | // (and storing it in the DescriptorArray when the map has one). |
| 2280 | // [0]: storage for bit_field3 for Map owning this object (Smi) |
| 2281 | // [1]: point to a fixed array with (value, detail) pairs. |
| 2282 | // [2]: next enumeration index (Smi), or pointer to small fixed array: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2283 | // [0]: next enumeration index (Smi) |
| 2284 | // [1]: pointer to fixed array with enum cache |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2285 | // [3]: first key |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2286 | // [length() - 1]: last key |
| 2287 | // |
| 2288 | class DescriptorArray: public FixedArray { |
| 2289 | public: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2290 | // Returns true for both shared empty_descriptor_array and for smis, which the |
| 2291 | // map uses to encode additional bit fields when the descriptor array is not |
| 2292 | // yet used. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2293 | inline bool IsEmpty(); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2294 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2295 | // Returns the number of descriptors in the array. |
| 2296 | int number_of_descriptors() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2297 | ASSERT(length() > kFirstIndex || IsEmpty()); |
| 2298 | int len = length(); |
| 2299 | return len <= kFirstIndex ? 0 : len - kFirstIndex; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2300 | } |
| 2301 | |
| 2302 | int NextEnumerationIndex() { |
| 2303 | if (IsEmpty()) return PropertyDetails::kInitialIndex; |
| 2304 | Object* obj = get(kEnumerationIndexIndex); |
| 2305 | if (obj->IsSmi()) { |
| 2306 | return Smi::cast(obj)->value(); |
| 2307 | } else { |
| 2308 | Object* index = FixedArray::cast(obj)->get(kEnumCacheBridgeEnumIndex); |
| 2309 | return Smi::cast(index)->value(); |
| 2310 | } |
| 2311 | } |
| 2312 | |
| 2313 | // Set next enumeration index and flush any enum cache. |
| 2314 | void SetNextEnumerationIndex(int value) { |
| 2315 | if (!IsEmpty()) { |
| 2316 | fast_set(this, kEnumerationIndexIndex, Smi::FromInt(value)); |
| 2317 | } |
| 2318 | } |
| 2319 | bool HasEnumCache() { |
| 2320 | return !IsEmpty() && !get(kEnumerationIndexIndex)->IsSmi(); |
| 2321 | } |
| 2322 | |
| 2323 | Object* GetEnumCache() { |
| 2324 | ASSERT(HasEnumCache()); |
| 2325 | FixedArray* bridge = FixedArray::cast(get(kEnumerationIndexIndex)); |
| 2326 | return bridge->get(kEnumCacheBridgeCacheIndex); |
| 2327 | } |
| 2328 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2329 | // TODO(1399): It should be possible to make room for bit_field3 in the map |
| 2330 | // without overloading the instance descriptors field in the map |
| 2331 | // (and storing it in the DescriptorArray when the map has one). |
| 2332 | inline int bit_field3_storage(); |
| 2333 | inline void set_bit_field3_storage(int value); |
| 2334 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2335 | // Initialize or change the enum cache, |
| 2336 | // using the supplied storage for the small "bridge". |
| 2337 | void SetEnumCache(FixedArray* bridge_storage, FixedArray* new_cache); |
| 2338 | |
| 2339 | // Accessors for fetching instance descriptor at descriptor number. |
| 2340 | inline String* GetKey(int descriptor_number); |
| 2341 | inline Object* GetValue(int descriptor_number); |
| 2342 | inline Smi* GetDetails(int descriptor_number); |
| 2343 | inline PropertyType GetType(int descriptor_number); |
| 2344 | inline int GetFieldIndex(int descriptor_number); |
| 2345 | inline JSFunction* GetConstantFunction(int descriptor_number); |
| 2346 | inline Object* GetCallbacksObject(int descriptor_number); |
| 2347 | inline AccessorDescriptor* GetCallbacks(int descriptor_number); |
| 2348 | inline bool IsProperty(int descriptor_number); |
| 2349 | inline bool IsTransition(int descriptor_number); |
| 2350 | inline bool IsNullDescriptor(int descriptor_number); |
| 2351 | inline bool IsDontEnum(int descriptor_number); |
| 2352 | |
| 2353 | // Accessor for complete descriptor. |
| 2354 | inline void Get(int descriptor_number, Descriptor* desc); |
| 2355 | inline void Set(int descriptor_number, Descriptor* desc); |
| 2356 | |
| 2357 | // Transfer complete descriptor from another descriptor array to |
| 2358 | // this one. |
| 2359 | inline void CopyFrom(int index, DescriptorArray* src, int src_index); |
| 2360 | |
| 2361 | // Copy the descriptor array, insert a new descriptor and optionally |
| 2362 | // remove map transitions. If the descriptor is already present, it is |
| 2363 | // replaced. If a replaced descriptor is a real property (not a transition |
| 2364 | // or null), its enumeration index is kept as is. |
| 2365 | // If adding a real property, map transitions must be removed. If adding |
| 2366 | // a transition, they must not be removed. All null descriptors are removed. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2367 | MUST_USE_RESULT MaybeObject* CopyInsert(Descriptor* descriptor, |
| 2368 | TransitionFlag transition_flag); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2369 | |
| 2370 | // Remove all transitions. Return a copy of the array with all transitions |
| 2371 | // removed, or a Failure object if the new array could not be allocated. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2372 | MUST_USE_RESULT MaybeObject* RemoveTransitions(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2373 | |
| 2374 | // Sort the instance descriptors by the hash codes of their keys. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 2375 | // Does not check for duplicates. |
| 2376 | void SortUnchecked(); |
| 2377 | |
| 2378 | // Sort the instance descriptors by the hash codes of their keys. |
| 2379 | // Checks the result for duplicates. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2380 | void Sort(); |
| 2381 | |
| 2382 | // Search the instance descriptors for given name. |
| 2383 | inline int Search(String* name); |
| 2384 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2385 | // As the above, but uses DescriptorLookupCache and updates it when |
| 2386 | // necessary. |
| 2387 | inline int SearchWithCache(String* name); |
| 2388 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2389 | // Tells whether the name is present int the array. |
| 2390 | bool Contains(String* name) { return kNotFound != Search(name); } |
| 2391 | |
| 2392 | // Perform a binary search in the instance descriptors represented |
| 2393 | // by this fixed array. low and high are descriptor indices. If there |
| 2394 | // are three instance descriptors in this array it should be called |
| 2395 | // with low=0 and high=2. |
| 2396 | int BinarySearch(String* name, int low, int high); |
| 2397 | |
| 2398 | // Perform a linear search in the instance descriptors represented |
| 2399 | // by this fixed array. len is the number of descriptor indices that are |
| 2400 | // valid. Does not require the descriptors to be sorted. |
| 2401 | int LinearSearch(String* name, int len); |
| 2402 | |
| 2403 | // Allocates a DescriptorArray, but returns the singleton |
| 2404 | // empty descriptor array object if number_of_descriptors is 0. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2405 | MUST_USE_RESULT static MaybeObject* Allocate(int number_of_descriptors); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2406 | |
| 2407 | // Casting. |
| 2408 | static inline DescriptorArray* cast(Object* obj); |
| 2409 | |
| 2410 | // Constant for denoting key was not found. |
| 2411 | static const int kNotFound = -1; |
| 2412 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2413 | static const int kBitField3StorageIndex = 0; |
| 2414 | static const int kContentArrayIndex = 1; |
| 2415 | static const int kEnumerationIndexIndex = 2; |
| 2416 | static const int kFirstIndex = 3; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2417 | |
| 2418 | // The length of the "bridge" to the enum cache. |
| 2419 | static const int kEnumCacheBridgeLength = 2; |
| 2420 | static const int kEnumCacheBridgeEnumIndex = 0; |
| 2421 | static const int kEnumCacheBridgeCacheIndex = 1; |
| 2422 | |
| 2423 | // Layout description. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2424 | static const int kBitField3StorageOffset = FixedArray::kHeaderSize; |
| 2425 | static const int kContentArrayOffset = kBitField3StorageOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2426 | static const int kEnumerationIndexOffset = kContentArrayOffset + kPointerSize; |
| 2427 | static const int kFirstOffset = kEnumerationIndexOffset + kPointerSize; |
| 2428 | |
| 2429 | // Layout description for the bridge array. |
| 2430 | static const int kEnumCacheBridgeEnumOffset = FixedArray::kHeaderSize; |
| 2431 | static const int kEnumCacheBridgeCacheOffset = |
| 2432 | kEnumCacheBridgeEnumOffset + kPointerSize; |
| 2433 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2434 | #ifdef OBJECT_PRINT |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2435 | // Print all the descriptors. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2436 | inline void PrintDescriptors() { |
| 2437 | PrintDescriptors(stdout); |
| 2438 | } |
| 2439 | void PrintDescriptors(FILE* out); |
| 2440 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2441 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2442 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2443 | // Is the descriptor array sorted and without duplicates? |
| 2444 | bool IsSortedNoDuplicates(); |
| 2445 | |
| 2446 | // Are two DescriptorArrays equal? |
| 2447 | bool IsEqualTo(DescriptorArray* other); |
| 2448 | #endif |
| 2449 | |
| 2450 | // The maximum number of descriptors we want in a descriptor array (should |
| 2451 | // fit in a page). |
| 2452 | static const int kMaxNumberOfDescriptors = 1024 + 512; |
| 2453 | |
| 2454 | private: |
| 2455 | // Conversion from descriptor number to array indices. |
| 2456 | static int ToKeyIndex(int descriptor_number) { |
| 2457 | return descriptor_number+kFirstIndex; |
| 2458 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2459 | |
| 2460 | static int ToDetailsIndex(int descriptor_number) { |
| 2461 | return (descriptor_number << 1) + 1; |
| 2462 | } |
| 2463 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2464 | static int ToValueIndex(int descriptor_number) { |
| 2465 | return descriptor_number << 1; |
| 2466 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2467 | |
| 2468 | bool is_null_descriptor(int descriptor_number) { |
| 2469 | return PropertyDetails(GetDetails(descriptor_number)).type() == |
| 2470 | NULL_DESCRIPTOR; |
| 2471 | } |
| 2472 | // Swap operation on FixedArray without using write barriers. |
| 2473 | static inline void fast_swap(FixedArray* array, int first, int second); |
| 2474 | |
| 2475 | // Swap descriptor first and second. |
| 2476 | inline void Swap(int first, int second); |
| 2477 | |
| 2478 | FixedArray* GetContentArray() { |
| 2479 | return FixedArray::cast(get(kContentArrayIndex)); |
| 2480 | } |
| 2481 | DISALLOW_IMPLICIT_CONSTRUCTORS(DescriptorArray); |
| 2482 | }; |
| 2483 | |
| 2484 | |
| 2485 | // HashTable is a subclass of FixedArray that implements a hash table |
| 2486 | // that uses open addressing and quadratic probing. |
| 2487 | // |
| 2488 | // In order for the quadratic probing to work, elements that have not |
| 2489 | // yet been used and elements that have been deleted are |
| 2490 | // distinguished. Probing continues when deleted elements are |
| 2491 | // encountered and stops when unused elements are encountered. |
| 2492 | // |
| 2493 | // - Elements with key == undefined have not been used yet. |
| 2494 | // - Elements with key == null have been deleted. |
| 2495 | // |
| 2496 | // The hash table class is parameterized with a Shape and a Key. |
| 2497 | // Shape must be a class with the following interface: |
| 2498 | // class ExampleShape { |
| 2499 | // public: |
| 2500 | // // Tells whether key matches other. |
| 2501 | // static bool IsMatch(Key key, Object* other); |
| 2502 | // // Returns the hash value for key. |
| 2503 | // static uint32_t Hash(Key key); |
| 2504 | // // Returns the hash value for object. |
| 2505 | // static uint32_t HashForObject(Key key, Object* object); |
| 2506 | // // Convert key to an object. |
| 2507 | // static inline Object* AsObject(Key key); |
| 2508 | // // The prefix size indicates number of elements in the beginning |
| 2509 | // // of the backing storage. |
| 2510 | // static const int kPrefixSize = ..; |
| 2511 | // // The Element size indicates number of elements per entry. |
| 2512 | // static const int kEntrySize = ..; |
| 2513 | // }; |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2514 | // The prefix size indicates an amount of memory in the |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2515 | // beginning of the backing storage that can be used for non-element |
| 2516 | // information by subclasses. |
| 2517 | |
| 2518 | template<typename Shape, typename Key> |
| 2519 | class HashTable: public FixedArray { |
| 2520 | public: |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2521 | // Returns the number of elements in the hash table. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2522 | int NumberOfElements() { |
| 2523 | return Smi::cast(get(kNumberOfElementsIndex))->value(); |
| 2524 | } |
| 2525 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2526 | // Returns the number of deleted elements in the hash table. |
| 2527 | int NumberOfDeletedElements() { |
| 2528 | return Smi::cast(get(kNumberOfDeletedElementsIndex))->value(); |
| 2529 | } |
| 2530 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2531 | // Returns the capacity of the hash table. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2532 | int Capacity() { |
| 2533 | return Smi::cast(get(kCapacityIndex))->value(); |
| 2534 | } |
| 2535 | |
| 2536 | // ElementAdded should be called whenever an element is added to a |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2537 | // hash table. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2538 | void ElementAdded() { SetNumberOfElements(NumberOfElements() + 1); } |
| 2539 | |
| 2540 | // ElementRemoved should be called whenever an element is removed from |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2541 | // a hash table. |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2542 | void ElementRemoved() { |
| 2543 | SetNumberOfElements(NumberOfElements() - 1); |
| 2544 | SetNumberOfDeletedElements(NumberOfDeletedElements() + 1); |
| 2545 | } |
| 2546 | void ElementsRemoved(int n) { |
| 2547 | SetNumberOfElements(NumberOfElements() - n); |
| 2548 | SetNumberOfDeletedElements(NumberOfDeletedElements() + n); |
| 2549 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2550 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2551 | // Returns a new HashTable object. Might return Failure. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2552 | MUST_USE_RESULT static MaybeObject* Allocate( |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2553 | int at_least_space_for, |
| 2554 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2555 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 2556 | // Computes the required capacity for a table holding the given |
| 2557 | // number of elements. May be more than HashTable::kMaxCapacity. |
| 2558 | static int ComputeCapacity(int at_least_space_for); |
| 2559 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2560 | // Returns the key at entry. |
| 2561 | Object* KeyAt(int entry) { return get(EntryToIndex(entry)); } |
| 2562 | |
| 2563 | // Tells whether k is a real key. Null and undefined are not allowed |
| 2564 | // as keys and can be used to indicate missing or deleted elements. |
| 2565 | bool IsKey(Object* k) { |
| 2566 | return !k->IsNull() && !k->IsUndefined(); |
| 2567 | } |
| 2568 | |
| 2569 | // Garbage collection support. |
| 2570 | void IteratePrefix(ObjectVisitor* visitor); |
| 2571 | void IterateElements(ObjectVisitor* visitor); |
| 2572 | |
| 2573 | // Casting. |
| 2574 | static inline HashTable* cast(Object* obj); |
| 2575 | |
| 2576 | // Compute the probe offset (quadratic probing). |
| 2577 | INLINE(static uint32_t GetProbeOffset(uint32_t n)) { |
| 2578 | return (n + n * n) >> 1; |
| 2579 | } |
| 2580 | |
| 2581 | static const int kNumberOfElementsIndex = 0; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2582 | static const int kNumberOfDeletedElementsIndex = 1; |
| 2583 | static const int kCapacityIndex = 2; |
| 2584 | static const int kPrefixStartIndex = 3; |
| 2585 | static const int kElementsStartIndex = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2586 | kPrefixStartIndex + Shape::kPrefixSize; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2587 | static const int kEntrySize = Shape::kEntrySize; |
| 2588 | static const int kElementsStartOffset = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2589 | kHeaderSize + kElementsStartIndex * kPointerSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2590 | static const int kCapacityOffset = |
| 2591 | kHeaderSize + kCapacityIndex * kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2592 | |
| 2593 | // Constant used for denoting a absent entry. |
| 2594 | static const int kNotFound = -1; |
| 2595 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2596 | // Maximal capacity of HashTable. Based on maximal length of underlying |
| 2597 | // FixedArray. Staying below kMaxCapacity also ensures that EntryToIndex |
| 2598 | // cannot overflow. |
| 2599 | static const int kMaxCapacity = |
| 2600 | (FixedArray::kMaxLength - kElementsStartOffset) / kEntrySize; |
| 2601 | |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 2602 | // Find entry for key otherwise return kNotFound. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2603 | inline int FindEntry(Key key); |
| 2604 | int FindEntry(Isolate* isolate, Key key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2605 | |
| 2606 | protected: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2607 | // Find the entry at which to insert element with the given key that |
| 2608 | // has the given hash value. |
| 2609 | uint32_t FindInsertionEntry(uint32_t hash); |
| 2610 | |
| 2611 | // Returns the index for an entry (of the key) |
| 2612 | static inline int EntryToIndex(int entry) { |
| 2613 | return (entry * kEntrySize) + kElementsStartIndex; |
| 2614 | } |
| 2615 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2616 | // Update the number of elements in the hash table. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2617 | void SetNumberOfElements(int nof) { |
| 2618 | fast_set(this, kNumberOfElementsIndex, Smi::FromInt(nof)); |
| 2619 | } |
| 2620 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2621 | // Update the number of deleted elements in the hash table. |
| 2622 | void SetNumberOfDeletedElements(int nod) { |
| 2623 | fast_set(this, kNumberOfDeletedElementsIndex, Smi::FromInt(nod)); |
| 2624 | } |
| 2625 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2626 | // Sets the capacity of the hash table. |
| 2627 | void SetCapacity(int capacity) { |
| 2628 | // To scale a computed hash code to fit within the hash table, we |
| 2629 | // use bit-wise AND with a mask, so the capacity must be positive |
| 2630 | // and non-zero. |
| 2631 | ASSERT(capacity > 0); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2632 | ASSERT(capacity <= kMaxCapacity); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2633 | fast_set(this, kCapacityIndex, Smi::FromInt(capacity)); |
| 2634 | } |
| 2635 | |
| 2636 | |
| 2637 | // Returns probe entry. |
| 2638 | static uint32_t GetProbe(uint32_t hash, uint32_t number, uint32_t size) { |
| 2639 | ASSERT(IsPowerOf2(size)); |
| 2640 | return (hash + GetProbeOffset(number)) & (size - 1); |
| 2641 | } |
| 2642 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2643 | static uint32_t FirstProbe(uint32_t hash, uint32_t size) { |
| 2644 | return hash & (size - 1); |
| 2645 | } |
| 2646 | |
| 2647 | static uint32_t NextProbe(uint32_t last, uint32_t number, uint32_t size) { |
| 2648 | return (last + number) & (size - 1); |
| 2649 | } |
| 2650 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2651 | // Rehashes this hash-table into the new table. |
| 2652 | MUST_USE_RESULT MaybeObject* Rehash(HashTable* new_table, Key key); |
| 2653 | |
| 2654 | // Attempt to shrink hash table after removal of key. |
| 2655 | MUST_USE_RESULT MaybeObject* Shrink(Key key); |
| 2656 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2657 | // Ensure enough space for n additional elements. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2658 | MUST_USE_RESULT MaybeObject* EnsureCapacity(int n, Key key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2659 | }; |
| 2660 | |
| 2661 | |
| 2662 | |
| 2663 | // HashTableKey is an abstract superclass for virtual key behavior. |
| 2664 | class HashTableKey { |
| 2665 | public: |
| 2666 | // Returns whether the other object matches this key. |
| 2667 | virtual bool IsMatch(Object* other) = 0; |
| 2668 | // Returns the hash value for this key. |
| 2669 | virtual uint32_t Hash() = 0; |
| 2670 | // Returns the hash value for object. |
| 2671 | virtual uint32_t HashForObject(Object* key) = 0; |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2672 | // Returns the key object for storing into the hash table. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2673 | // If allocations fails a failure object is returned. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2674 | MUST_USE_RESULT virtual MaybeObject* AsObject() = 0; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2675 | // Required. |
| 2676 | virtual ~HashTableKey() {} |
| 2677 | }; |
| 2678 | |
| 2679 | class SymbolTableShape { |
| 2680 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2681 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2682 | return key->IsMatch(value); |
| 2683 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2684 | static inline uint32_t Hash(HashTableKey* key) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2685 | return key->Hash(); |
| 2686 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2687 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2688 | return key->HashForObject(object); |
| 2689 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2690 | MUST_USE_RESULT static inline MaybeObject* AsObject(HashTableKey* key) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2691 | return key->AsObject(); |
| 2692 | } |
| 2693 | |
| 2694 | static const int kPrefixSize = 0; |
| 2695 | static const int kEntrySize = 1; |
| 2696 | }; |
| 2697 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2698 | class SeqAsciiString; |
| 2699 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2700 | // SymbolTable. |
| 2701 | // |
| 2702 | // No special elements in the prefix and the element size is 1 |
| 2703 | // because only the symbol itself (the key) needs to be stored. |
| 2704 | class SymbolTable: public HashTable<SymbolTableShape, HashTableKey*> { |
| 2705 | public: |
| 2706 | // Find symbol in the symbol table. If it is not there yet, it is |
| 2707 | // added. The return value is the symbol table which might have |
| 2708 | // been enlarged. If the return value is not a failure, the symbol |
| 2709 | // pointer *s is set to the symbol found. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2710 | MUST_USE_RESULT MaybeObject* LookupSymbol(Vector<const char> str, Object** s); |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 2711 | MUST_USE_RESULT MaybeObject* LookupAsciiSymbol(Vector<const char> str, |
| 2712 | Object** s); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2713 | MUST_USE_RESULT MaybeObject* LookupSubStringAsciiSymbol( |
| 2714 | Handle<SeqAsciiString> str, |
| 2715 | int from, |
| 2716 | int length, |
| 2717 | Object** s); |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 2718 | MUST_USE_RESULT MaybeObject* LookupTwoByteSymbol(Vector<const uc16> str, |
| 2719 | Object** s); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2720 | MUST_USE_RESULT MaybeObject* LookupString(String* key, Object** s); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2721 | |
| 2722 | // Looks up a symbol that is equal to the given string and returns |
| 2723 | // true if it is found, assigning the symbol to the given output |
| 2724 | // parameter. |
| 2725 | bool LookupSymbolIfExists(String* str, String** symbol); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2726 | bool LookupTwoCharsSymbolIfExists(uint32_t c1, uint32_t c2, String** symbol); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2727 | |
| 2728 | // Casting. |
| 2729 | static inline SymbolTable* cast(Object* obj); |
| 2730 | |
| 2731 | private: |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2732 | MUST_USE_RESULT MaybeObject* LookupKey(HashTableKey* key, Object** s); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2733 | |
| 2734 | DISALLOW_IMPLICIT_CONSTRUCTORS(SymbolTable); |
| 2735 | }; |
| 2736 | |
| 2737 | |
| 2738 | class MapCacheShape { |
| 2739 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2740 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2741 | return key->IsMatch(value); |
| 2742 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2743 | static inline uint32_t Hash(HashTableKey* key) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2744 | return key->Hash(); |
| 2745 | } |
| 2746 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2747 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2748 | return key->HashForObject(object); |
| 2749 | } |
| 2750 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2751 | MUST_USE_RESULT static inline MaybeObject* AsObject(HashTableKey* key) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2752 | return key->AsObject(); |
| 2753 | } |
| 2754 | |
| 2755 | static const int kPrefixSize = 0; |
| 2756 | static const int kEntrySize = 2; |
| 2757 | }; |
| 2758 | |
| 2759 | |
| 2760 | // MapCache. |
| 2761 | // |
| 2762 | // Maps keys that are a fixed array of symbols to a map. |
| 2763 | // Used for canonicalize maps for object literals. |
| 2764 | class MapCache: public HashTable<MapCacheShape, HashTableKey*> { |
| 2765 | public: |
| 2766 | // Find cached value for a string key, otherwise return null. |
| 2767 | Object* Lookup(FixedArray* key); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2768 | MUST_USE_RESULT MaybeObject* Put(FixedArray* key, Map* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2769 | static inline MapCache* cast(Object* obj); |
| 2770 | |
| 2771 | private: |
| 2772 | DISALLOW_IMPLICIT_CONSTRUCTORS(MapCache); |
| 2773 | }; |
| 2774 | |
| 2775 | |
| 2776 | template <typename Shape, typename Key> |
| 2777 | class Dictionary: public HashTable<Shape, Key> { |
| 2778 | public: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2779 | static inline Dictionary<Shape, Key>* cast(Object* obj) { |
| 2780 | return reinterpret_cast<Dictionary<Shape, Key>*>(obj); |
| 2781 | } |
| 2782 | |
| 2783 | // Returns the value at entry. |
| 2784 | Object* ValueAt(int entry) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2785 | return this->get(HashTable<Shape, Key>::EntryToIndex(entry)+1); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2786 | } |
| 2787 | |
| 2788 | // Set the value for entry. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2789 | // Returns false if the put wasn't performed due to property being read only. |
| 2790 | // Returns true on successful put. |
| 2791 | bool ValueAtPut(int entry, Object* value) { |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 2792 | // Check that this value can actually be written. |
| 2793 | PropertyDetails details = DetailsAt(entry); |
| 2794 | // If a value has not been initilized we allow writing to it even if |
| 2795 | // it is read only (a declared const that has not been initialized). |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2796 | if (details.IsReadOnly() && !ValueAt(entry)->IsTheHole()) { |
| 2797 | return false; |
| 2798 | } |
| 2799 | this->set(HashTable<Shape, Key>::EntryToIndex(entry) + 1, value); |
| 2800 | return true; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2801 | } |
| 2802 | |
| 2803 | // Returns the property details for the property at entry. |
| 2804 | PropertyDetails DetailsAt(int entry) { |
| 2805 | ASSERT(entry >= 0); // Not found is -1, which is not caught by get(). |
| 2806 | return PropertyDetails( |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2807 | Smi::cast(this->get(HashTable<Shape, Key>::EntryToIndex(entry) + 2))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2808 | } |
| 2809 | |
| 2810 | // Set the details for entry. |
| 2811 | void DetailsAtPut(int entry, PropertyDetails value) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2812 | this->set(HashTable<Shape, Key>::EntryToIndex(entry) + 2, value.AsSmi()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2813 | } |
| 2814 | |
| 2815 | // Sorting support |
| 2816 | void CopyValuesTo(FixedArray* elements); |
| 2817 | |
| 2818 | // Delete a property from the dictionary. |
| 2819 | Object* DeleteProperty(int entry, JSObject::DeleteMode mode); |
| 2820 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2821 | // Attempt to shrink the dictionary after deletion of key. |
| 2822 | MUST_USE_RESULT MaybeObject* Shrink(Key key); |
| 2823 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2824 | // Returns the number of elements in the dictionary filtering out properties |
| 2825 | // with the specified attributes. |
| 2826 | int NumberOfElementsFilterAttributes(PropertyAttributes filter); |
| 2827 | |
| 2828 | // Returns the number of enumerable elements in the dictionary. |
| 2829 | int NumberOfEnumElements(); |
| 2830 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2831 | enum SortMode { UNSORTED, SORTED }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2832 | // Copies keys to preallocated fixed array. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2833 | void CopyKeysTo(FixedArray* storage, |
| 2834 | PropertyAttributes filter, |
| 2835 | SortMode sort_mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2836 | // Fill in details for properties into storage. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2837 | void CopyKeysTo(FixedArray* storage, int index, SortMode sort_mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2838 | |
| 2839 | // Accessors for next enumeration index. |
| 2840 | void SetNextEnumerationIndex(int index) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2841 | this->fast_set(this, kNextEnumerationIndexIndex, Smi::FromInt(index)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2842 | } |
| 2843 | |
| 2844 | int NextEnumerationIndex() { |
| 2845 | return Smi::cast(FixedArray::get(kNextEnumerationIndexIndex))->value(); |
| 2846 | } |
| 2847 | |
| 2848 | // Returns a new array for dictionary usage. Might return Failure. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2849 | MUST_USE_RESULT static MaybeObject* Allocate(int at_least_space_for); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2850 | |
| 2851 | // Ensure enough space for n additional elements. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2852 | MUST_USE_RESULT MaybeObject* EnsureCapacity(int n, Key key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2853 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2854 | #ifdef OBJECT_PRINT |
| 2855 | inline void Print() { |
| 2856 | Print(stdout); |
| 2857 | } |
| 2858 | void Print(FILE* out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2859 | #endif |
| 2860 | // Returns the key (slow). |
| 2861 | Object* SlowReverseLookup(Object* value); |
| 2862 | |
| 2863 | // Sets the entry to (key, value) pair. |
| 2864 | inline void SetEntry(int entry, |
| 2865 | Object* key, |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2866 | Object* value); |
| 2867 | inline void SetEntry(int entry, |
| 2868 | Object* key, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2869 | Object* value, |
| 2870 | PropertyDetails details); |
| 2871 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2872 | MUST_USE_RESULT MaybeObject* Add(Key key, |
| 2873 | Object* value, |
| 2874 | PropertyDetails details); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2875 | |
| 2876 | protected: |
| 2877 | // Generic at put operation. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2878 | MUST_USE_RESULT MaybeObject* AtPut(Key key, Object* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2879 | |
| 2880 | // Add entry to dictionary. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2881 | MUST_USE_RESULT MaybeObject* AddEntry(Key key, |
| 2882 | Object* value, |
| 2883 | PropertyDetails details, |
| 2884 | uint32_t hash); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2885 | |
| 2886 | // Generate new enumeration indices to avoid enumeration index overflow. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2887 | MUST_USE_RESULT MaybeObject* GenerateNewEnumerationIndices(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2888 | static const int kMaxNumberKeyIndex = |
| 2889 | HashTable<Shape, Key>::kPrefixStartIndex; |
| 2890 | static const int kNextEnumerationIndexIndex = kMaxNumberKeyIndex + 1; |
| 2891 | }; |
| 2892 | |
| 2893 | |
| 2894 | class StringDictionaryShape { |
| 2895 | public: |
| 2896 | static inline bool IsMatch(String* key, Object* other); |
| 2897 | static inline uint32_t Hash(String* key); |
| 2898 | static inline uint32_t HashForObject(String* key, Object* object); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2899 | MUST_USE_RESULT static inline MaybeObject* AsObject(String* key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2900 | static const int kPrefixSize = 2; |
| 2901 | static const int kEntrySize = 3; |
| 2902 | static const bool kIsEnumerable = true; |
| 2903 | }; |
| 2904 | |
| 2905 | |
| 2906 | class StringDictionary: public Dictionary<StringDictionaryShape, String*> { |
| 2907 | public: |
| 2908 | static inline StringDictionary* cast(Object* obj) { |
| 2909 | ASSERT(obj->IsDictionary()); |
| 2910 | return reinterpret_cast<StringDictionary*>(obj); |
| 2911 | } |
| 2912 | |
| 2913 | // Copies enumerable keys to preallocated fixed array. |
| 2914 | void CopyEnumKeysTo(FixedArray* storage, FixedArray* sort_array); |
| 2915 | |
| 2916 | // For transforming properties of a JSObject. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2917 | MUST_USE_RESULT MaybeObject* TransformPropertiesToFastFor( |
| 2918 | JSObject* obj, |
| 2919 | int unused_property_fields); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 2920 | |
| 2921 | // Find entry for key otherwise return kNotFound. Optimzed version of |
| 2922 | // HashTable::FindEntry. |
| 2923 | int FindEntry(String* key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2924 | }; |
| 2925 | |
| 2926 | |
| 2927 | class NumberDictionaryShape { |
| 2928 | public: |
| 2929 | static inline bool IsMatch(uint32_t key, Object* other); |
| 2930 | static inline uint32_t Hash(uint32_t key); |
| 2931 | static inline uint32_t HashForObject(uint32_t key, Object* object); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2932 | MUST_USE_RESULT static inline MaybeObject* AsObject(uint32_t key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2933 | static const int kPrefixSize = 2; |
| 2934 | static const int kEntrySize = 3; |
| 2935 | static const bool kIsEnumerable = false; |
| 2936 | }; |
| 2937 | |
| 2938 | |
| 2939 | class NumberDictionary: public Dictionary<NumberDictionaryShape, uint32_t> { |
| 2940 | public: |
| 2941 | static NumberDictionary* cast(Object* obj) { |
| 2942 | ASSERT(obj->IsDictionary()); |
| 2943 | return reinterpret_cast<NumberDictionary*>(obj); |
| 2944 | } |
| 2945 | |
| 2946 | // Type specific at put (default NONE attributes is used when adding). |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2947 | MUST_USE_RESULT MaybeObject* AtNumberPut(uint32_t key, Object* value); |
| 2948 | MUST_USE_RESULT MaybeObject* AddNumberEntry(uint32_t key, |
| 2949 | Object* value, |
| 2950 | PropertyDetails details); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2951 | |
| 2952 | // Set an existing entry or add a new one if needed. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2953 | MUST_USE_RESULT MaybeObject* Set(uint32_t key, |
| 2954 | Object* value, |
| 2955 | PropertyDetails details); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2956 | |
| 2957 | void UpdateMaxNumberKey(uint32_t key); |
| 2958 | |
| 2959 | // If slow elements are required we will never go back to fast-case |
| 2960 | // for the elements kept in this dictionary. We require slow |
| 2961 | // elements if an element has been added at an index larger than |
| 2962 | // kRequiresSlowElementsLimit or set_requires_slow_elements() has been called |
| 2963 | // when defining a getter or setter with a number key. |
| 2964 | inline bool requires_slow_elements(); |
| 2965 | inline void set_requires_slow_elements(); |
| 2966 | |
| 2967 | // Get the value of the max number key that has been added to this |
| 2968 | // dictionary. max_number_key can only be called if |
| 2969 | // requires_slow_elements returns false. |
| 2970 | inline uint32_t max_number_key(); |
| 2971 | |
| 2972 | // Remove all entries were key is a number and (from <= key && key < to). |
| 2973 | void RemoveNumberEntries(uint32_t from, uint32_t to); |
| 2974 | |
| 2975 | // Bit masks. |
| 2976 | static const int kRequiresSlowElementsMask = 1; |
| 2977 | static const int kRequiresSlowElementsTagSize = 1; |
| 2978 | static const uint32_t kRequiresSlowElementsLimit = (1 << 29) - 1; |
| 2979 | }; |
| 2980 | |
| 2981 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 2982 | class ObjectHashTableShape { |
| 2983 | public: |
| 2984 | static inline bool IsMatch(JSObject* key, Object* other); |
| 2985 | static inline uint32_t Hash(JSObject* key); |
| 2986 | static inline uint32_t HashForObject(JSObject* key, Object* object); |
| 2987 | MUST_USE_RESULT static inline MaybeObject* AsObject(JSObject* key); |
| 2988 | static const int kPrefixSize = 0; |
| 2989 | static const int kEntrySize = 2; |
| 2990 | }; |
| 2991 | |
| 2992 | |
| 2993 | // ObjectHashTable maps keys that are JavaScript objects to object values by |
| 2994 | // using the identity hash of the key for hashing purposes. |
| 2995 | class ObjectHashTable: public HashTable<ObjectHashTableShape, JSObject*> { |
| 2996 | public: |
| 2997 | static inline ObjectHashTable* cast(Object* obj) { |
| 2998 | ASSERT(obj->IsHashTable()); |
| 2999 | return reinterpret_cast<ObjectHashTable*>(obj); |
| 3000 | } |
| 3001 | |
| 3002 | // Looks up the value associated with the given key. The undefined value is |
| 3003 | // returned in case the key is not present. |
| 3004 | Object* Lookup(JSObject* key); |
| 3005 | |
| 3006 | // Adds (or overwrites) the value associated with the given key. Mapping a |
| 3007 | // key to the undefined value causes removal of the whole entry. |
| 3008 | MUST_USE_RESULT MaybeObject* Put(JSObject* key, Object* value); |
| 3009 | |
| 3010 | private: |
| 3011 | friend class MarkCompactCollector; |
| 3012 | |
| 3013 | void AddEntry(int entry, JSObject* key, Object* value); |
| 3014 | void RemoveEntry(int entry, Heap* heap); |
| 3015 | inline void RemoveEntry(int entry); |
| 3016 | |
| 3017 | // Returns the index to the value of an entry. |
| 3018 | static inline int EntryToValueIndex(int entry) { |
| 3019 | return EntryToIndex(entry) + 1; |
| 3020 | } |
| 3021 | }; |
| 3022 | |
| 3023 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3024 | // JSFunctionResultCache caches results of some JSFunction invocation. |
| 3025 | // It is a fixed array with fixed structure: |
| 3026 | // [0]: factory function |
| 3027 | // [1]: finger index |
| 3028 | // [2]: current cache size |
| 3029 | // [3]: dummy field. |
| 3030 | // The rest of array are key/value pairs. |
| 3031 | class JSFunctionResultCache: public FixedArray { |
| 3032 | public: |
| 3033 | static const int kFactoryIndex = 0; |
| 3034 | static const int kFingerIndex = kFactoryIndex + 1; |
| 3035 | static const int kCacheSizeIndex = kFingerIndex + 1; |
| 3036 | static const int kDummyIndex = kCacheSizeIndex + 1; |
| 3037 | static const int kEntriesIndex = kDummyIndex + 1; |
| 3038 | |
| 3039 | static const int kEntrySize = 2; // key + value |
| 3040 | |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 3041 | static const int kFactoryOffset = kHeaderSize; |
| 3042 | static const int kFingerOffset = kFactoryOffset + kPointerSize; |
| 3043 | static const int kCacheSizeOffset = kFingerOffset + kPointerSize; |
| 3044 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3045 | inline void MakeZeroSize(); |
| 3046 | inline void Clear(); |
| 3047 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 3048 | inline int size(); |
| 3049 | inline void set_size(int size); |
| 3050 | inline int finger_index(); |
| 3051 | inline void set_finger_index(int finger_index); |
| 3052 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3053 | // Casting |
| 3054 | static inline JSFunctionResultCache* cast(Object* obj); |
| 3055 | |
| 3056 | #ifdef DEBUG |
| 3057 | void JSFunctionResultCacheVerify(); |
| 3058 | #endif |
| 3059 | }; |
| 3060 | |
| 3061 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3062 | // The cache for maps used by normalized (dictionary mode) objects. |
| 3063 | // Such maps do not have property descriptors, so a typical program |
| 3064 | // needs very limited number of distinct normalized maps. |
| 3065 | class NormalizedMapCache: public FixedArray { |
| 3066 | public: |
| 3067 | static const int kEntries = 64; |
| 3068 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 3069 | MUST_USE_RESULT MaybeObject* Get(JSObject* object, |
| 3070 | PropertyNormalizationMode mode); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3071 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3072 | void Clear(); |
| 3073 | |
| 3074 | // Casting |
| 3075 | static inline NormalizedMapCache* cast(Object* obj); |
| 3076 | |
| 3077 | #ifdef DEBUG |
| 3078 | void NormalizedMapCacheVerify(); |
| 3079 | #endif |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3080 | }; |
| 3081 | |
| 3082 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3083 | // ByteArray represents fixed sized byte arrays. Used by the outside world, |
| 3084 | // such as PCRE, and also by the memory allocator and garbage collector to |
| 3085 | // fill in free blocks in the heap. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 3086 | class ByteArray: public FixedArrayBase { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3087 | public: |
| 3088 | // Setter and getter. |
| 3089 | inline byte get(int index); |
| 3090 | inline void set(int index, byte value); |
| 3091 | |
| 3092 | // Treat contents as an int array. |
| 3093 | inline int get_int(int index); |
| 3094 | |
| 3095 | static int SizeFor(int length) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3096 | return OBJECT_POINTER_ALIGN(kHeaderSize + length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3097 | } |
| 3098 | // We use byte arrays for free blocks in the heap. Given a desired size in |
| 3099 | // bytes that is a multiple of the word size and big enough to hold a byte |
| 3100 | // array, this function returns the number of elements a byte array should |
| 3101 | // have. |
| 3102 | static int LengthFor(int size_in_bytes) { |
| 3103 | ASSERT(IsAligned(size_in_bytes, kPointerSize)); |
| 3104 | ASSERT(size_in_bytes >= kHeaderSize); |
| 3105 | return size_in_bytes - kHeaderSize; |
| 3106 | } |
| 3107 | |
| 3108 | // Returns data start address. |
| 3109 | inline Address GetDataStartAddress(); |
| 3110 | |
| 3111 | // Returns a pointer to the ByteArray object for a given data start address. |
| 3112 | static inline ByteArray* FromDataStartAddress(Address address); |
| 3113 | |
| 3114 | // Casting. |
| 3115 | static inline ByteArray* cast(Object* obj); |
| 3116 | |
| 3117 | // Dispatched behavior. |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 3118 | inline int ByteArraySize() { |
| 3119 | return SizeFor(this->length()); |
| 3120 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3121 | #ifdef OBJECT_PRINT |
| 3122 | inline void ByteArrayPrint() { |
| 3123 | ByteArrayPrint(stdout); |
| 3124 | } |
| 3125 | void ByteArrayPrint(FILE* out); |
| 3126 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3127 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3128 | void ByteArrayVerify(); |
| 3129 | #endif |
| 3130 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3131 | // Layout description. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3132 | static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3133 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 3134 | // Maximal memory consumption for a single ByteArray. |
| 3135 | static const int kMaxSize = 512 * MB; |
| 3136 | // Maximal length of a single ByteArray. |
| 3137 | static const int kMaxLength = kMaxSize - kHeaderSize; |
| 3138 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3139 | private: |
| 3140 | DISALLOW_IMPLICIT_CONSTRUCTORS(ByteArray); |
| 3141 | }; |
| 3142 | |
| 3143 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3144 | // An ExternalArray represents a fixed-size array of primitive values |
| 3145 | // which live outside the JavaScript heap. Its subclasses are used to |
| 3146 | // implement the CanvasArray types being defined in the WebGL |
| 3147 | // specification. As of this writing the first public draft is not yet |
| 3148 | // available, but Khronos members can access the draft at: |
| 3149 | // https://cvs.khronos.org/svn/repos/3dweb/trunk/doc/spec/WebGL-spec.html |
| 3150 | // |
| 3151 | // The semantics of these arrays differ from CanvasPixelArray. |
| 3152 | // Out-of-range values passed to the setter are converted via a C |
| 3153 | // cast, not clamping. Out-of-range indices cause exceptions to be |
| 3154 | // raised rather than being silently ignored. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 3155 | class ExternalArray: public FixedArrayBase { |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3156 | public: |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 3157 | |
| 3158 | inline bool is_the_hole(int index) { return false; } |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3159 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3160 | // [external_pointer]: The pointer to the external memory area backing this |
| 3161 | // external array. |
| 3162 | DECL_ACCESSORS(external_pointer, void) // Pointer to the data store. |
| 3163 | |
| 3164 | // Casting. |
| 3165 | static inline ExternalArray* cast(Object* obj); |
| 3166 | |
| 3167 | // Maximal acceptable length for an external array. |
| 3168 | static const int kMaxLength = 0x3fffffff; |
| 3169 | |
| 3170 | // ExternalArray headers are not quadword aligned. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3171 | static const int kExternalPointerOffset = |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 3172 | POINTER_SIZE_ALIGN(FixedArrayBase::kLengthOffset + kPointerSize); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3173 | static const int kHeaderSize = kExternalPointerOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3174 | static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3175 | |
| 3176 | private: |
| 3177 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalArray); |
| 3178 | }; |
| 3179 | |
| 3180 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3181 | // A ExternalPixelArray represents a fixed-size byte array with special |
| 3182 | // semantics used for implementing the CanvasPixelArray object. Please see the |
| 3183 | // specification at: |
| 3184 | |
| 3185 | // http://www.whatwg.org/specs/web-apps/current-work/ |
| 3186 | // multipage/the-canvas-element.html#canvaspixelarray |
| 3187 | // In particular, write access clamps the value written to 0 or 255 if the |
| 3188 | // value written is outside this range. |
| 3189 | class ExternalPixelArray: public ExternalArray { |
| 3190 | public: |
| 3191 | inline uint8_t* external_pixel_pointer(); |
| 3192 | |
| 3193 | // Setter and getter. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 3194 | inline uint8_t get_scalar(int index); |
| 3195 | inline MaybeObject* get(int index); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3196 | inline void set(int index, uint8_t value); |
| 3197 | |
| 3198 | // This accessor applies the correct conversion from Smi, HeapNumber and |
| 3199 | // undefined and clamps the converted value between 0 and 255. |
| 3200 | Object* SetValue(uint32_t index, Object* value); |
| 3201 | |
| 3202 | // Casting. |
| 3203 | static inline ExternalPixelArray* cast(Object* obj); |
| 3204 | |
| 3205 | #ifdef OBJECT_PRINT |
| 3206 | inline void ExternalPixelArrayPrint() { |
| 3207 | ExternalPixelArrayPrint(stdout); |
| 3208 | } |
| 3209 | void ExternalPixelArrayPrint(FILE* out); |
| 3210 | #endif |
| 3211 | #ifdef DEBUG |
| 3212 | void ExternalPixelArrayVerify(); |
| 3213 | #endif // DEBUG |
| 3214 | |
| 3215 | private: |
| 3216 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalPixelArray); |
| 3217 | }; |
| 3218 | |
| 3219 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3220 | class ExternalByteArray: public ExternalArray { |
| 3221 | public: |
| 3222 | // Setter and getter. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 3223 | inline int8_t get_scalar(int index); |
| 3224 | inline MaybeObject* get(int index); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3225 | inline void set(int index, int8_t value); |
| 3226 | |
| 3227 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3228 | // and undefined. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 3229 | MaybeObject* SetValue(uint32_t index, Object* value); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3230 | |
| 3231 | // Casting. |
| 3232 | static inline ExternalByteArray* cast(Object* obj); |
| 3233 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3234 | #ifdef OBJECT_PRINT |
| 3235 | inline void ExternalByteArrayPrint() { |
| 3236 | ExternalByteArrayPrint(stdout); |
| 3237 | } |
| 3238 | void ExternalByteArrayPrint(FILE* out); |
| 3239 | #endif |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3240 | #ifdef DEBUG |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3241 | void ExternalByteArrayVerify(); |
| 3242 | #endif // DEBUG |
| 3243 | |
| 3244 | private: |
| 3245 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalByteArray); |
| 3246 | }; |
| 3247 | |
| 3248 | |
| 3249 | class ExternalUnsignedByteArray: public ExternalArray { |
| 3250 | public: |
| 3251 | // Setter and getter. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 3252 | inline uint8_t get_scalar(int index); |
| 3253 | inline MaybeObject* get(int index); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3254 | inline void set(int index, uint8_t value); |
| 3255 | |
| 3256 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3257 | // and undefined. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 3258 | MaybeObject* SetValue(uint32_t index, Object* value); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3259 | |
| 3260 | // Casting. |
| 3261 | static inline ExternalUnsignedByteArray* cast(Object* obj); |
| 3262 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3263 | #ifdef OBJECT_PRINT |
| 3264 | inline void ExternalUnsignedByteArrayPrint() { |
| 3265 | ExternalUnsignedByteArrayPrint(stdout); |
| 3266 | } |
| 3267 | void ExternalUnsignedByteArrayPrint(FILE* out); |
| 3268 | #endif |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3269 | #ifdef DEBUG |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3270 | void ExternalUnsignedByteArrayVerify(); |
| 3271 | #endif // DEBUG |
| 3272 | |
| 3273 | private: |
| 3274 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedByteArray); |
| 3275 | }; |
| 3276 | |
| 3277 | |
| 3278 | class ExternalShortArray: public ExternalArray { |
| 3279 | public: |
| 3280 | // Setter and getter. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 3281 | inline int16_t get_scalar(int index); |
| 3282 | inline MaybeObject* get(int index); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3283 | inline void set(int index, int16_t value); |
| 3284 | |
| 3285 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3286 | // and undefined. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 3287 | MaybeObject* SetValue(uint32_t index, Object* value); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3288 | |
| 3289 | // Casting. |
| 3290 | static inline ExternalShortArray* cast(Object* obj); |
| 3291 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3292 | #ifdef OBJECT_PRINT |
| 3293 | inline void ExternalShortArrayPrint() { |
| 3294 | ExternalShortArrayPrint(stdout); |
| 3295 | } |
| 3296 | void ExternalShortArrayPrint(FILE* out); |
| 3297 | #endif |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3298 | #ifdef DEBUG |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3299 | void ExternalShortArrayVerify(); |
| 3300 | #endif // DEBUG |
| 3301 | |
| 3302 | private: |
| 3303 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalShortArray); |
| 3304 | }; |
| 3305 | |
| 3306 | |
| 3307 | class ExternalUnsignedShortArray: public ExternalArray { |
| 3308 | public: |
| 3309 | // Setter and getter. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 3310 | inline uint16_t get_scalar(int index); |
| 3311 | inline MaybeObject* get(int index); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3312 | inline void set(int index, uint16_t value); |
| 3313 | |
| 3314 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3315 | // and undefined. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 3316 | MaybeObject* SetValue(uint32_t index, Object* value); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3317 | |
| 3318 | // Casting. |
| 3319 | static inline ExternalUnsignedShortArray* cast(Object* obj); |
| 3320 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3321 | #ifdef OBJECT_PRINT |
| 3322 | inline void ExternalUnsignedShortArrayPrint() { |
| 3323 | ExternalUnsignedShortArrayPrint(stdout); |
| 3324 | } |
| 3325 | void ExternalUnsignedShortArrayPrint(FILE* out); |
| 3326 | #endif |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3327 | #ifdef DEBUG |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3328 | void ExternalUnsignedShortArrayVerify(); |
| 3329 | #endif // DEBUG |
| 3330 | |
| 3331 | private: |
| 3332 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedShortArray); |
| 3333 | }; |
| 3334 | |
| 3335 | |
| 3336 | class ExternalIntArray: public ExternalArray { |
| 3337 | public: |
| 3338 | // Setter and getter. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 3339 | inline int32_t get_scalar(int index); |
| 3340 | inline MaybeObject* get(int index); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3341 | inline void set(int index, int32_t value); |
| 3342 | |
| 3343 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3344 | // and undefined. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 3345 | MaybeObject* SetValue(uint32_t index, Object* value); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3346 | |
| 3347 | // Casting. |
| 3348 | static inline ExternalIntArray* cast(Object* obj); |
| 3349 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3350 | #ifdef OBJECT_PRINT |
| 3351 | inline void ExternalIntArrayPrint() { |
| 3352 | ExternalIntArrayPrint(stdout); |
| 3353 | } |
| 3354 | void ExternalIntArrayPrint(FILE* out); |
| 3355 | #endif |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3356 | #ifdef DEBUG |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3357 | void ExternalIntArrayVerify(); |
| 3358 | #endif // DEBUG |
| 3359 | |
| 3360 | private: |
| 3361 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalIntArray); |
| 3362 | }; |
| 3363 | |
| 3364 | |
| 3365 | class ExternalUnsignedIntArray: public ExternalArray { |
| 3366 | public: |
| 3367 | // Setter and getter. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 3368 | inline uint32_t get_scalar(int index); |
| 3369 | inline MaybeObject* get(int index); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3370 | inline void set(int index, uint32_t value); |
| 3371 | |
| 3372 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3373 | // and undefined. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 3374 | MaybeObject* SetValue(uint32_t index, Object* value); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3375 | |
| 3376 | // Casting. |
| 3377 | static inline ExternalUnsignedIntArray* cast(Object* obj); |
| 3378 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3379 | #ifdef OBJECT_PRINT |
| 3380 | inline void ExternalUnsignedIntArrayPrint() { |
| 3381 | ExternalUnsignedIntArrayPrint(stdout); |
| 3382 | } |
| 3383 | void ExternalUnsignedIntArrayPrint(FILE* out); |
| 3384 | #endif |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3385 | #ifdef DEBUG |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3386 | void ExternalUnsignedIntArrayVerify(); |
| 3387 | #endif // DEBUG |
| 3388 | |
| 3389 | private: |
| 3390 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedIntArray); |
| 3391 | }; |
| 3392 | |
| 3393 | |
| 3394 | class ExternalFloatArray: public ExternalArray { |
| 3395 | public: |
| 3396 | // Setter and getter. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 3397 | inline float get_scalar(int index); |
| 3398 | inline MaybeObject* get(int index); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3399 | inline void set(int index, float value); |
| 3400 | |
| 3401 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3402 | // and undefined. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 3403 | MaybeObject* SetValue(uint32_t index, Object* value); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3404 | |
| 3405 | // Casting. |
| 3406 | static inline ExternalFloatArray* cast(Object* obj); |
| 3407 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3408 | #ifdef OBJECT_PRINT |
| 3409 | inline void ExternalFloatArrayPrint() { |
| 3410 | ExternalFloatArrayPrint(stdout); |
| 3411 | } |
| 3412 | void ExternalFloatArrayPrint(FILE* out); |
| 3413 | #endif |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3414 | #ifdef DEBUG |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3415 | void ExternalFloatArrayVerify(); |
| 3416 | #endif // DEBUG |
| 3417 | |
| 3418 | private: |
| 3419 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalFloatArray); |
| 3420 | }; |
| 3421 | |
| 3422 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3423 | class ExternalDoubleArray: public ExternalArray { |
| 3424 | public: |
| 3425 | // Setter and getter. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 3426 | inline double get_scalar(int index); |
| 3427 | inline MaybeObject* get(int index); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3428 | inline void set(int index, double value); |
| 3429 | |
| 3430 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3431 | // and undefined. |
| 3432 | MaybeObject* SetValue(uint32_t index, Object* value); |
| 3433 | |
| 3434 | // Casting. |
| 3435 | static inline ExternalDoubleArray* cast(Object* obj); |
| 3436 | |
| 3437 | #ifdef OBJECT_PRINT |
| 3438 | inline void ExternalDoubleArrayPrint() { |
| 3439 | ExternalDoubleArrayPrint(stdout); |
| 3440 | } |
| 3441 | void ExternalDoubleArrayPrint(FILE* out); |
| 3442 | #endif // OBJECT_PRINT |
| 3443 | #ifdef DEBUG |
| 3444 | void ExternalDoubleArrayVerify(); |
| 3445 | #endif // DEBUG |
| 3446 | |
| 3447 | private: |
| 3448 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalDoubleArray); |
| 3449 | }; |
| 3450 | |
| 3451 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3452 | // DeoptimizationInputData is a fixed array used to hold the deoptimization |
| 3453 | // data for code generated by the Hydrogen/Lithium compiler. It also |
| 3454 | // contains information about functions that were inlined. If N different |
| 3455 | // functions were inlined then first N elements of the literal array will |
| 3456 | // contain these functions. |
| 3457 | // |
| 3458 | // It can be empty. |
| 3459 | class DeoptimizationInputData: public FixedArray { |
| 3460 | public: |
| 3461 | // Layout description. Indices in the array. |
| 3462 | static const int kTranslationByteArrayIndex = 0; |
| 3463 | static const int kInlinedFunctionCountIndex = 1; |
| 3464 | static const int kLiteralArrayIndex = 2; |
| 3465 | static const int kOsrAstIdIndex = 3; |
| 3466 | static const int kOsrPcOffsetIndex = 4; |
| 3467 | static const int kFirstDeoptEntryIndex = 5; |
| 3468 | |
| 3469 | // Offsets of deopt entry elements relative to the start of the entry. |
| 3470 | static const int kAstIdOffset = 0; |
| 3471 | static const int kTranslationIndexOffset = 1; |
| 3472 | static const int kArgumentsStackHeightOffset = 2; |
| 3473 | static const int kDeoptEntrySize = 3; |
| 3474 | |
| 3475 | // Simple element accessors. |
| 3476 | #define DEFINE_ELEMENT_ACCESSORS(name, type) \ |
| 3477 | type* name() { \ |
| 3478 | return type::cast(get(k##name##Index)); \ |
| 3479 | } \ |
| 3480 | void Set##name(type* value) { \ |
| 3481 | set(k##name##Index, value); \ |
| 3482 | } |
| 3483 | |
| 3484 | DEFINE_ELEMENT_ACCESSORS(TranslationByteArray, ByteArray) |
| 3485 | DEFINE_ELEMENT_ACCESSORS(InlinedFunctionCount, Smi) |
| 3486 | DEFINE_ELEMENT_ACCESSORS(LiteralArray, FixedArray) |
| 3487 | DEFINE_ELEMENT_ACCESSORS(OsrAstId, Smi) |
| 3488 | DEFINE_ELEMENT_ACCESSORS(OsrPcOffset, Smi) |
| 3489 | |
| 3490 | // Unchecked accessor to be used during GC. |
| 3491 | FixedArray* UncheckedLiteralArray() { |
| 3492 | return reinterpret_cast<FixedArray*>(get(kLiteralArrayIndex)); |
| 3493 | } |
| 3494 | |
| 3495 | #undef DEFINE_ELEMENT_ACCESSORS |
| 3496 | |
| 3497 | // Accessors for elements of the ith deoptimization entry. |
| 3498 | #define DEFINE_ENTRY_ACCESSORS(name, type) \ |
| 3499 | type* name(int i) { \ |
| 3500 | return type::cast(get(IndexForEntry(i) + k##name##Offset)); \ |
| 3501 | } \ |
| 3502 | void Set##name(int i, type* value) { \ |
| 3503 | set(IndexForEntry(i) + k##name##Offset, value); \ |
| 3504 | } |
| 3505 | |
| 3506 | DEFINE_ENTRY_ACCESSORS(AstId, Smi) |
| 3507 | DEFINE_ENTRY_ACCESSORS(TranslationIndex, Smi) |
| 3508 | DEFINE_ENTRY_ACCESSORS(ArgumentsStackHeight, Smi) |
| 3509 | |
| 3510 | #undef DEFINE_ENTRY_ACCESSORS |
| 3511 | |
| 3512 | int DeoptCount() { |
| 3513 | return (length() - kFirstDeoptEntryIndex) / kDeoptEntrySize; |
| 3514 | } |
| 3515 | |
| 3516 | // Allocates a DeoptimizationInputData. |
| 3517 | MUST_USE_RESULT static MaybeObject* Allocate(int deopt_entry_count, |
| 3518 | PretenureFlag pretenure); |
| 3519 | |
| 3520 | // Casting. |
| 3521 | static inline DeoptimizationInputData* cast(Object* obj); |
| 3522 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3523 | #ifdef ENABLE_DISASSEMBLER |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3524 | void DeoptimizationInputDataPrint(FILE* out); |
| 3525 | #endif |
| 3526 | |
| 3527 | private: |
| 3528 | static int IndexForEntry(int i) { |
| 3529 | return kFirstDeoptEntryIndex + (i * kDeoptEntrySize); |
| 3530 | } |
| 3531 | |
| 3532 | static int LengthFor(int entry_count) { |
| 3533 | return IndexForEntry(entry_count); |
| 3534 | } |
| 3535 | }; |
| 3536 | |
| 3537 | |
| 3538 | // DeoptimizationOutputData is a fixed array used to hold the deoptimization |
| 3539 | // data for code generated by the full compiler. |
| 3540 | // The format of the these objects is |
| 3541 | // [i * 2]: Ast ID for ith deoptimization. |
| 3542 | // [i * 2 + 1]: PC and state of ith deoptimization |
| 3543 | class DeoptimizationOutputData: public FixedArray { |
| 3544 | public: |
| 3545 | int DeoptPoints() { return length() / 2; } |
| 3546 | Smi* AstId(int index) { return Smi::cast(get(index * 2)); } |
| 3547 | void SetAstId(int index, Smi* id) { set(index * 2, id); } |
| 3548 | Smi* PcAndState(int index) { return Smi::cast(get(1 + index * 2)); } |
| 3549 | void SetPcAndState(int index, Smi* offset) { set(1 + index * 2, offset); } |
| 3550 | |
| 3551 | static int LengthOfFixedArray(int deopt_points) { |
| 3552 | return deopt_points * 2; |
| 3553 | } |
| 3554 | |
| 3555 | // Allocates a DeoptimizationOutputData. |
| 3556 | MUST_USE_RESULT static MaybeObject* Allocate(int number_of_deopt_points, |
| 3557 | PretenureFlag pretenure); |
| 3558 | |
| 3559 | // Casting. |
| 3560 | static inline DeoptimizationOutputData* cast(Object* obj); |
| 3561 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3562 | #if defined(OBJECT_PRINT) || defined(ENABLE_DISASSEMBLER) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3563 | void DeoptimizationOutputDataPrint(FILE* out); |
| 3564 | #endif |
| 3565 | }; |
| 3566 | |
| 3567 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 3568 | class SafepointEntry; |
| 3569 | |
| 3570 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3571 | // Code describes objects with on-the-fly generated machine code. |
| 3572 | class Code: public HeapObject { |
| 3573 | public: |
| 3574 | // Opaque data type for encapsulating code flags like kind, inline |
| 3575 | // cache state, and arguments count. |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 3576 | // FLAGS_MIN_VALUE and FLAGS_MAX_VALUE are specified to ensure that |
| 3577 | // enumeration type has correct value range (see Issue 830 for more details). |
| 3578 | enum Flags { |
| 3579 | FLAGS_MIN_VALUE = kMinInt, |
| 3580 | FLAGS_MAX_VALUE = kMaxInt |
| 3581 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3582 | |
| 3583 | enum Kind { |
| 3584 | FUNCTION, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3585 | OPTIMIZED_FUNCTION, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3586 | STUB, |
| 3587 | BUILTIN, |
| 3588 | LOAD_IC, |
| 3589 | KEYED_LOAD_IC, |
| 3590 | CALL_IC, |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3591 | KEYED_CALL_IC, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3592 | STORE_IC, |
| 3593 | KEYED_STORE_IC, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3594 | UNARY_OP_IC, |
| 3595 | BINARY_OP_IC, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3596 | COMPARE_IC, |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 3597 | TO_BOOLEAN_IC, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3598 | // 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] | 3599 | // Flags. |
| 3600 | |
| 3601 | // Pseudo-kinds. |
| 3602 | REGEXP = BUILTIN, |
| 3603 | FIRST_IC_KIND = LOAD_IC, |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 3604 | LAST_IC_KIND = TO_BOOLEAN_IC |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3605 | }; |
| 3606 | |
| 3607 | enum { |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 3608 | NUMBER_OF_KINDS = LAST_IC_KIND + 1 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3609 | }; |
| 3610 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 3611 | typedef int ExtraICState; |
| 3612 | |
| 3613 | static const ExtraICState kNoExtraICState = 0; |
| 3614 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3615 | #ifdef ENABLE_DISASSEMBLER |
| 3616 | // Printing |
| 3617 | static const char* Kind2String(Kind kind); |
| 3618 | static const char* ICState2String(InlineCacheState state); |
| 3619 | static const char* PropertyType2String(PropertyType type); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3620 | static void PrintExtraICState(FILE* out, Kind kind, ExtraICState extra); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3621 | inline void Disassemble(const char* name) { |
| 3622 | Disassemble(name, stdout); |
| 3623 | } |
| 3624 | void Disassemble(const char* name, FILE* out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3625 | #endif // ENABLE_DISASSEMBLER |
| 3626 | |
| 3627 | // [instruction_size]: Size of the native instructions |
| 3628 | inline int instruction_size(); |
| 3629 | inline void set_instruction_size(int value); |
| 3630 | |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 3631 | // [relocation_info]: Code relocation information |
| 3632 | DECL_ACCESSORS(relocation_info, ByteArray) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3633 | void InvalidateRelocation(); |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 3634 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3635 | // [deoptimization_data]: Array containing data for deopt. |
| 3636 | DECL_ACCESSORS(deoptimization_data, FixedArray) |
| 3637 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3638 | // [code_flushing_candidate]: Field only used during garbage |
| 3639 | // collection to hold code flushing candidates. The contents of this |
| 3640 | // field does not have to be traced during garbage collection since |
| 3641 | // it is only used by the garbage collector itself. |
| 3642 | DECL_ACCESSORS(next_code_flushing_candidate, Object) |
| 3643 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3644 | // Unchecked accessors to be used during GC. |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 3645 | inline ByteArray* unchecked_relocation_info(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3646 | inline FixedArray* unchecked_deoptimization_data(); |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 3647 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3648 | inline int relocation_size(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3649 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3650 | // [flags]: Various code flags. |
| 3651 | inline Flags flags(); |
| 3652 | inline void set_flags(Flags flags); |
| 3653 | |
| 3654 | // [flags]: Access to specific code flags. |
| 3655 | inline Kind kind(); |
| 3656 | inline InlineCacheState ic_state(); // Only valid for IC stubs. |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 3657 | inline ExtraICState extra_ic_state(); // Only valid for IC stubs. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3658 | inline InLoopFlag ic_in_loop(); // Only valid for IC stubs. |
| 3659 | inline PropertyType type(); // Only valid for monomorphic IC stubs. |
| 3660 | inline int arguments_count(); // Only valid for call IC stubs. |
| 3661 | |
| 3662 | // Testers for IC stub kinds. |
| 3663 | inline bool is_inline_cache_stub(); |
| 3664 | inline bool is_load_stub() { return kind() == LOAD_IC; } |
| 3665 | inline bool is_keyed_load_stub() { return kind() == KEYED_LOAD_IC; } |
| 3666 | inline bool is_store_stub() { return kind() == STORE_IC; } |
| 3667 | inline bool is_keyed_store_stub() { return kind() == KEYED_STORE_IC; } |
| 3668 | inline bool is_call_stub() { return kind() == CALL_IC; } |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3669 | inline bool is_keyed_call_stub() { return kind() == KEYED_CALL_IC; } |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 3670 | inline bool is_unary_op_stub() { return kind() == UNARY_OP_IC; } |
| 3671 | inline bool is_binary_op_stub() { return kind() == BINARY_OP_IC; } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3672 | inline bool is_compare_ic_stub() { return kind() == COMPARE_IC; } |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 3673 | inline bool is_to_boolean_ic_stub() { return kind() == TO_BOOLEAN_IC; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3674 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3675 | // [major_key]: For kind STUB or BINARY_OP_IC, the major key. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3676 | inline int major_key(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3677 | inline void set_major_key(int value); |
| 3678 | |
| 3679 | // [optimizable]: For FUNCTION kind, tells if it is optimizable. |
| 3680 | inline bool optimizable(); |
| 3681 | inline void set_optimizable(bool value); |
| 3682 | |
| 3683 | // [has_deoptimization_support]: For FUNCTION kind, tells if it has |
| 3684 | // deoptimization support. |
| 3685 | inline bool has_deoptimization_support(); |
| 3686 | inline void set_has_deoptimization_support(bool value); |
| 3687 | |
| 3688 | // [allow_osr_at_loop_nesting_level]: For FUNCTION kind, tells for |
| 3689 | // how long the function has been marked for OSR and therefore which |
| 3690 | // level of loop nesting we are willing to do on-stack replacement |
| 3691 | // for. |
| 3692 | inline void set_allow_osr_at_loop_nesting_level(int level); |
| 3693 | inline int allow_osr_at_loop_nesting_level(); |
| 3694 | |
| 3695 | // [stack_slots]: For kind OPTIMIZED_FUNCTION, the number of stack slots |
| 3696 | // reserved in the code prologue. |
| 3697 | inline unsigned stack_slots(); |
| 3698 | inline void set_stack_slots(unsigned slots); |
| 3699 | |
| 3700 | // [safepoint_table_start]: For kind OPTIMIZED_CODE, the offset in |
| 3701 | // the instruction stream where the safepoint table starts. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3702 | inline unsigned safepoint_table_offset(); |
| 3703 | inline void set_safepoint_table_offset(unsigned offset); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3704 | |
| 3705 | // [stack_check_table_start]: For kind FUNCTION, the offset in the |
| 3706 | // instruction stream where the stack check table starts. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3707 | inline unsigned stack_check_table_offset(); |
| 3708 | inline void set_stack_check_table_offset(unsigned offset); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3709 | |
| 3710 | // [check type]: For kind CALL_IC, tells how to check if the |
| 3711 | // receiver is valid for the given call. |
| 3712 | inline CheckType check_type(); |
| 3713 | inline void set_check_type(CheckType value); |
| 3714 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 3715 | // [type-recording unary op type]: For kind UNARY_OP_IC. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3716 | inline byte unary_op_type(); |
| 3717 | inline void set_unary_op_type(byte value); |
| 3718 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 3719 | // [type-recording binary op type]: For kind BINARY_OP_IC. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3720 | inline byte binary_op_type(); |
| 3721 | inline void set_binary_op_type(byte value); |
| 3722 | inline byte binary_op_result_type(); |
| 3723 | inline void set_binary_op_result_type(byte value); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3724 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 3725 | // [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] | 3726 | inline byte compare_state(); |
| 3727 | inline void set_compare_state(byte value); |
| 3728 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 3729 | // [to_boolean_foo]: For kind TO_BOOLEAN_IC tells what state the stub is in. |
| 3730 | inline byte to_boolean_state(); |
| 3731 | inline void set_to_boolean_state(byte value); |
| 3732 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 3733 | // Get the safepoint entry for the given pc. |
| 3734 | SafepointEntry GetSafepointEntry(Address pc); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3735 | |
| 3736 | // Mark this code object as not having a stack check table. Assumes kind |
| 3737 | // is FUNCTION. |
| 3738 | void SetNoStackCheckTable(); |
| 3739 | |
| 3740 | // Find the first map in an IC stub. |
| 3741 | Map* FindFirstMap(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3742 | |
| 3743 | // Flags operations. |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 3744 | static inline Flags ComputeFlags( |
| 3745 | Kind kind, |
| 3746 | InLoopFlag in_loop = NOT_IN_LOOP, |
| 3747 | InlineCacheState ic_state = UNINITIALIZED, |
| 3748 | ExtraICState extra_ic_state = kNoExtraICState, |
| 3749 | PropertyType type = NORMAL, |
| 3750 | int argc = -1, |
| 3751 | InlineCacheHolderFlag holder = OWN_MAP); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3752 | |
| 3753 | static inline Flags ComputeMonomorphicFlags( |
| 3754 | Kind kind, |
| 3755 | PropertyType type, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 3756 | ExtraICState extra_ic_state = kNoExtraICState, |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 3757 | InlineCacheHolderFlag holder = OWN_MAP, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3758 | InLoopFlag in_loop = NOT_IN_LOOP, |
| 3759 | int argc = -1); |
| 3760 | |
| 3761 | static inline Kind ExtractKindFromFlags(Flags flags); |
| 3762 | static inline InlineCacheState ExtractICStateFromFlags(Flags flags); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 3763 | static inline ExtraICState ExtractExtraICStateFromFlags(Flags flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3764 | static inline InLoopFlag ExtractICInLoopFromFlags(Flags flags); |
| 3765 | static inline PropertyType ExtractTypeFromFlags(Flags flags); |
| 3766 | static inline int ExtractArgumentsCountFromFlags(Flags flags); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 3767 | static inline InlineCacheHolderFlag ExtractCacheHolderFromFlags(Flags flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3768 | static inline Flags RemoveTypeFromFlags(Flags flags); |
| 3769 | |
| 3770 | // Convert a target address into a code object. |
| 3771 | static inline Code* GetCodeFromTargetAddress(Address address); |
| 3772 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 3773 | // Convert an entry address into an object. |
| 3774 | static inline Object* GetObjectFromEntryAddress(Address location_of_address); |
| 3775 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3776 | // Returns the address of the first instruction. |
| 3777 | inline byte* instruction_start(); |
| 3778 | |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 3779 | // Returns the address right after the last instruction. |
| 3780 | inline byte* instruction_end(); |
| 3781 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3782 | // Returns the size of the instructions, padding, and relocation information. |
| 3783 | inline int body_size(); |
| 3784 | |
| 3785 | // Returns the address of the first relocation info (read backwards!). |
| 3786 | inline byte* relocation_start(); |
| 3787 | |
| 3788 | // Code entry point. |
| 3789 | inline byte* entry(); |
| 3790 | |
| 3791 | // Returns true if pc is inside this object's instructions. |
| 3792 | inline bool contains(byte* pc); |
| 3793 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3794 | // Relocate the code by delta bytes. Called to signal that this code |
| 3795 | // object has been moved by delta bytes. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3796 | void Relocate(intptr_t delta); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3797 | |
| 3798 | // Migrate code described by desc. |
| 3799 | void CopyFrom(const CodeDesc& desc); |
| 3800 | |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 3801 | // Returns the object size for a given body (used for allocation). |
| 3802 | static int SizeFor(int body_size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3803 | ASSERT_SIZE_TAG_ALIGNED(body_size); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 3804 | return RoundUp(kHeaderSize + body_size, kCodeAlignment); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3805 | } |
| 3806 | |
| 3807 | // Calculate the size of the code object to report for log events. This takes |
| 3808 | // the layout of the code object into account. |
| 3809 | int ExecutableSize() { |
| 3810 | // Check that the assumptions about the layout of the code object holds. |
| 3811 | ASSERT_EQ(static_cast<int>(instruction_start() - address()), |
| 3812 | Code::kHeaderSize); |
| 3813 | return instruction_size() + Code::kHeaderSize; |
| 3814 | } |
| 3815 | |
| 3816 | // Locating source position. |
| 3817 | int SourcePosition(Address pc); |
| 3818 | int SourceStatementPosition(Address pc); |
| 3819 | |
| 3820 | // Casting. |
| 3821 | static inline Code* cast(Object* obj); |
| 3822 | |
| 3823 | // Dispatched behavior. |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 3824 | int CodeSize() { return SizeFor(body_size()); } |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 3825 | inline void CodeIterateBody(ObjectVisitor* v); |
| 3826 | |
| 3827 | template<typename StaticVisitor> |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3828 | inline void CodeIterateBody(Heap* heap); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3829 | #ifdef OBJECT_PRINT |
| 3830 | inline void CodePrint() { |
| 3831 | CodePrint(stdout); |
| 3832 | } |
| 3833 | void CodePrint(FILE* out); |
| 3834 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3835 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3836 | void CodeVerify(); |
| 3837 | #endif |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3838 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3839 | // Returns the isolate/heap this code object belongs to. |
| 3840 | inline Isolate* isolate(); |
| 3841 | inline Heap* heap(); |
| 3842 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3843 | // Max loop nesting marker used to postpose OSR. We don't take loop |
| 3844 | // nesting that is deeper than 5 levels into account. |
| 3845 | static const int kMaxLoopNestingMarker = 6; |
| 3846 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3847 | // Layout description. |
| 3848 | static const int kInstructionSizeOffset = HeapObject::kHeaderSize; |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 3849 | static const int kRelocationInfoOffset = kInstructionSizeOffset + kIntSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3850 | static const int kDeoptimizationDataOffset = |
| 3851 | kRelocationInfoOffset + kPointerSize; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3852 | static const int kNextCodeFlushingCandidateOffset = |
| 3853 | kDeoptimizationDataOffset + kPointerSize; |
| 3854 | static const int kFlagsOffset = |
| 3855 | kNextCodeFlushingCandidateOffset + kPointerSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3856 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3857 | static const int kKindSpecificFlagsOffset = kFlagsOffset + kIntSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3858 | static const int kKindSpecificFlagsSize = 2 * kIntSize; |
| 3859 | |
| 3860 | static const int kHeaderPaddingStart = kKindSpecificFlagsOffset + |
| 3861 | kKindSpecificFlagsSize; |
| 3862 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3863 | // Add padding to align the instruction start following right after |
| 3864 | // the Code object header. |
| 3865 | static const int kHeaderSize = |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3866 | (kHeaderPaddingStart + kCodeAlignmentMask) & ~kCodeAlignmentMask; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3867 | |
| 3868 | // Byte offsets within kKindSpecificFlagsOffset. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3869 | static const int kStubMajorKeyOffset = kKindSpecificFlagsOffset; |
| 3870 | static const int kOptimizableOffset = kKindSpecificFlagsOffset; |
| 3871 | static const int kStackSlotsOffset = kKindSpecificFlagsOffset; |
| 3872 | static const int kCheckTypeOffset = kKindSpecificFlagsOffset; |
| 3873 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3874 | static const int kUnaryOpTypeOffset = kStubMajorKeyOffset + 1; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3875 | static const int kBinaryOpTypeOffset = kStubMajorKeyOffset + 1; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 3876 | static const int kCompareStateOffset = kStubMajorKeyOffset + 1; |
| 3877 | static const int kToBooleanTypeOffset = kStubMajorKeyOffset + 1; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3878 | static const int kHasDeoptimizationSupportOffset = kOptimizableOffset + 1; |
| 3879 | |
| 3880 | static const int kBinaryOpReturnTypeOffset = kBinaryOpTypeOffset + 1; |
| 3881 | static const int kAllowOSRAtLoopNestingLevelOffset = |
| 3882 | kHasDeoptimizationSupportOffset + 1; |
| 3883 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3884 | static const int kSafepointTableOffsetOffset = kStackSlotsOffset + kIntSize; |
| 3885 | static const int kStackCheckTableOffsetOffset = kStackSlotsOffset + kIntSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3886 | |
| 3887 | // Flags layout. |
| 3888 | static const int kFlagsICStateShift = 0; |
| 3889 | static const int kFlagsICInLoopShift = 3; |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 3890 | static const int kFlagsTypeShift = 4; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3891 | static const int kFlagsKindShift = 8; |
| 3892 | static const int kFlagsICHolderShift = 12; |
| 3893 | static const int kFlagsExtraICStateShift = 13; |
| 3894 | static const int kFlagsArgumentsCountShift = 15; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3895 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3896 | static const int kFlagsICStateMask = 0x00000007; // 00000000111 |
| 3897 | static const int kFlagsICInLoopMask = 0x00000008; // 00000001000 |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3898 | static const int kFlagsTypeMask = 0x000000F0; // 00001110000 |
| 3899 | static const int kFlagsKindMask = 0x00000F00; // 11110000000 |
| 3900 | static const int kFlagsCacheInPrototypeMapMask = 0x00001000; |
| 3901 | static const int kFlagsExtraICStateMask = 0x00006000; |
| 3902 | static const int kFlagsArgumentsCountMask = 0xFFFF8000; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3903 | |
| 3904 | static const int kFlagsNotUsedInLookup = |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 3905 | (kFlagsICInLoopMask | kFlagsTypeMask | kFlagsCacheInPrototypeMapMask); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3906 | |
| 3907 | private: |
| 3908 | DISALLOW_IMPLICIT_CONSTRUCTORS(Code); |
| 3909 | }; |
| 3910 | |
| 3911 | |
| 3912 | // All heap objects have a Map that describes their structure. |
| 3913 | // A Map contains information about: |
| 3914 | // - Size information about the object |
| 3915 | // - How to iterate over an object (for garbage collection) |
| 3916 | class Map: public HeapObject { |
| 3917 | public: |
| 3918 | // Instance size. |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 3919 | // Size in bytes or kVariableSizeSentinel if instances do not have |
| 3920 | // a fixed size. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3921 | inline int instance_size(); |
| 3922 | inline void set_instance_size(int value); |
| 3923 | |
| 3924 | // Count of properties allocated in the object. |
| 3925 | inline int inobject_properties(); |
| 3926 | inline void set_inobject_properties(int value); |
| 3927 | |
| 3928 | // Count of property fields pre-allocated in the object when first allocated. |
| 3929 | inline int pre_allocated_property_fields(); |
| 3930 | inline void set_pre_allocated_property_fields(int value); |
| 3931 | |
| 3932 | // Instance type. |
| 3933 | inline InstanceType instance_type(); |
| 3934 | inline void set_instance_type(InstanceType value); |
| 3935 | |
| 3936 | // Tells how many unused property fields are available in the |
| 3937 | // instance (only used for JSObject in fast mode). |
| 3938 | inline int unused_property_fields(); |
| 3939 | inline void set_unused_property_fields(int value); |
| 3940 | |
| 3941 | // Bit field. |
| 3942 | inline byte bit_field(); |
| 3943 | inline void set_bit_field(byte value); |
| 3944 | |
| 3945 | // Bit field 2. |
| 3946 | inline byte bit_field2(); |
| 3947 | inline void set_bit_field2(byte value); |
| 3948 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3949 | // Bit field 3. |
| 3950 | // TODO(1399): It should be possible to make room for bit_field3 in the map |
| 3951 | // without overloading the instance descriptors field (and storing it in the |
| 3952 | // DescriptorArray when the map has one). |
| 3953 | inline int bit_field3(); |
| 3954 | inline void set_bit_field3(int value); |
| 3955 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3956 | // Tells whether the object in the prototype property will be used |
| 3957 | // for instances created from this function. If the prototype |
| 3958 | // property is set to a value that is not a JSObject, the prototype |
| 3959 | // property will not be used to create instances of the function. |
| 3960 | // See ECMA-262, 13.2.2. |
| 3961 | inline void set_non_instance_prototype(bool value); |
| 3962 | inline bool has_non_instance_prototype(); |
| 3963 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3964 | // Tells whether function has special prototype property. If not, prototype |
| 3965 | // property will not be created when accessed (will return undefined), |
| 3966 | // and construction from this function will not be allowed. |
| 3967 | inline void set_function_with_prototype(bool value); |
| 3968 | inline bool function_with_prototype(); |
| 3969 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3970 | // Tells whether the instance with this map should be ignored by the |
| 3971 | // __proto__ accessor. |
| 3972 | inline void set_is_hidden_prototype() { |
| 3973 | set_bit_field(bit_field() | (1 << kIsHiddenPrototype)); |
| 3974 | } |
| 3975 | |
| 3976 | inline bool is_hidden_prototype() { |
| 3977 | return ((1 << kIsHiddenPrototype) & bit_field()) != 0; |
| 3978 | } |
| 3979 | |
| 3980 | // Records and queries whether the instance has a named interceptor. |
| 3981 | inline void set_has_named_interceptor() { |
| 3982 | set_bit_field(bit_field() | (1 << kHasNamedInterceptor)); |
| 3983 | } |
| 3984 | |
| 3985 | inline bool has_named_interceptor() { |
| 3986 | return ((1 << kHasNamedInterceptor) & bit_field()) != 0; |
| 3987 | } |
| 3988 | |
| 3989 | // Records and queries whether the instance has an indexed interceptor. |
| 3990 | inline void set_has_indexed_interceptor() { |
| 3991 | set_bit_field(bit_field() | (1 << kHasIndexedInterceptor)); |
| 3992 | } |
| 3993 | |
| 3994 | inline bool has_indexed_interceptor() { |
| 3995 | return ((1 << kHasIndexedInterceptor) & bit_field()) != 0; |
| 3996 | } |
| 3997 | |
| 3998 | // Tells whether the instance is undetectable. |
| 3999 | // An undetectable object is a special class of JSObject: 'typeof' operator |
| 4000 | // returns undefined, ToBoolean returns false. Otherwise it behaves like |
| 4001 | // a normal JS object. It is useful for implementing undetectable |
| 4002 | // document.all in Firefox & Safari. |
| 4003 | // See https://bugzilla.mozilla.org/show_bug.cgi?id=248549. |
| 4004 | inline void set_is_undetectable() { |
| 4005 | set_bit_field(bit_field() | (1 << kIsUndetectable)); |
| 4006 | } |
| 4007 | |
| 4008 | inline bool is_undetectable() { |
| 4009 | return ((1 << kIsUndetectable) & bit_field()) != 0; |
| 4010 | } |
| 4011 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4012 | // Tells whether the instance has a call-as-function handler. |
| 4013 | inline void set_has_instance_call_handler() { |
| 4014 | set_bit_field(bit_field() | (1 << kHasInstanceCallHandler)); |
| 4015 | } |
| 4016 | |
| 4017 | inline bool has_instance_call_handler() { |
| 4018 | return ((1 << kHasInstanceCallHandler) & bit_field()) != 0; |
| 4019 | } |
| 4020 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 4021 | inline void set_is_extensible(bool value); |
| 4022 | inline bool is_extensible(); |
| 4023 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4024 | inline void set_elements_kind(JSObject::ElementsKind elements_kind) { |
| 4025 | ASSERT(elements_kind < JSObject::kElementsKindCount); |
| 4026 | ASSERT(JSObject::kElementsKindCount <= (1 << kElementsKindBitCount)); |
| 4027 | set_bit_field2((bit_field2() & ~kElementsKindMask) | |
| 4028 | (elements_kind << kElementsKindShift)); |
| 4029 | ASSERT(this->elements_kind() == elements_kind); |
| 4030 | } |
| 4031 | |
| 4032 | inline JSObject::ElementsKind elements_kind() { |
| 4033 | return static_cast<JSObject::ElementsKind>( |
| 4034 | (bit_field2() & kElementsKindMask) >> kElementsKindShift); |
| 4035 | } |
| 4036 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 4037 | // Tells whether the instance has fast elements. |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 4038 | // Equivalent to instance->GetElementsKind() == FAST_ELEMENTS. |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 4039 | inline bool has_fast_elements() { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4040 | return elements_kind() == JSObject::FAST_ELEMENTS; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4041 | } |
| 4042 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4043 | inline bool has_fast_double_elements() { |
| 4044 | return elements_kind() == JSObject::FAST_DOUBLE_ELEMENTS; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 4045 | } |
| 4046 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4047 | inline bool has_external_array_elements() { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4048 | JSObject::ElementsKind kind(elements_kind()); |
| 4049 | return kind >= JSObject::FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND && |
| 4050 | kind <= JSObject::LAST_EXTERNAL_ARRAY_ELEMENTS_KIND; |
| 4051 | } |
| 4052 | |
| 4053 | inline bool has_dictionary_elements() { |
| 4054 | return elements_kind() == JSObject::DICTIONARY_ELEMENTS; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 4055 | } |
| 4056 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4057 | // Tells whether the map is attached to SharedFunctionInfo |
| 4058 | // (for inobject slack tracking). |
| 4059 | inline void set_attached_to_shared_function_info(bool value); |
| 4060 | |
| 4061 | inline bool attached_to_shared_function_info(); |
| 4062 | |
| 4063 | // Tells whether the map is shared between objects that may have different |
| 4064 | // behavior. If true, the map should never be modified, instead a clone |
| 4065 | // should be created and modified. |
| 4066 | inline void set_is_shared(bool value); |
| 4067 | |
| 4068 | inline bool is_shared(); |
| 4069 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4070 | // Tells whether the instance needs security checks when accessing its |
| 4071 | // properties. |
| 4072 | inline void set_is_access_check_needed(bool access_check_needed); |
| 4073 | inline bool is_access_check_needed(); |
| 4074 | |
| 4075 | // [prototype]: implicit prototype object. |
| 4076 | DECL_ACCESSORS(prototype, Object) |
| 4077 | |
| 4078 | // [constructor]: points back to the function responsible for this map. |
| 4079 | DECL_ACCESSORS(constructor, Object) |
| 4080 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4081 | inline JSFunction* unchecked_constructor(); |
| 4082 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4083 | // Should only be called by the code that initializes map to set initial valid |
| 4084 | // value of the instance descriptor member. |
| 4085 | inline void init_instance_descriptors(); |
| 4086 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4087 | // [instance descriptors]: describes the object. |
| 4088 | DECL_ACCESSORS(instance_descriptors, DescriptorArray) |
| 4089 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4090 | // Sets the instance descriptor array for the map to be an empty descriptor |
| 4091 | // array. |
| 4092 | inline void clear_instance_descriptors(); |
| 4093 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4094 | // [stub cache]: contains stubs compiled for this map. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4095 | DECL_ACCESSORS(code_cache, Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4096 | |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 4097 | // [prototype transitions]: cache of prototype transitions. |
| 4098 | // Prototype transition is a transition that happens |
| 4099 | // when we change object's prototype to a new one. |
| 4100 | // Cache format: |
| 4101 | // 0: finger - index of the first free cell in the cache |
| 4102 | // 1 + 2 * i: prototype |
| 4103 | // 2 + 2 * i: target map |
| 4104 | DECL_ACCESSORS(prototype_transitions, FixedArray) |
| 4105 | inline FixedArray* unchecked_prototype_transitions(); |
| 4106 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4107 | static const int kProtoTransitionHeaderSize = 1; |
| 4108 | static const int kProtoTransitionNumberOfEntriesOffset = 0; |
| 4109 | static const int kProtoTransitionElementsPerEntry = 2; |
| 4110 | static const int kProtoTransitionPrototypeOffset = 0; |
| 4111 | static const int kProtoTransitionMapOffset = 1; |
| 4112 | |
| 4113 | inline int NumberOfProtoTransitions() { |
| 4114 | FixedArray* cache = unchecked_prototype_transitions(); |
| 4115 | if (cache->length() == 0) return 0; |
| 4116 | return |
| 4117 | Smi::cast(cache->get(kProtoTransitionNumberOfEntriesOffset))->value(); |
| 4118 | } |
| 4119 | |
| 4120 | inline void SetNumberOfProtoTransitions(int value) { |
| 4121 | FixedArray* cache = unchecked_prototype_transitions(); |
| 4122 | ASSERT(cache->length() != 0); |
| 4123 | cache->set_unchecked(kProtoTransitionNumberOfEntriesOffset, |
| 4124 | Smi::FromInt(value)); |
| 4125 | } |
| 4126 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4127 | // Lookup in the map's instance descriptors and fill out the result |
| 4128 | // with the given holder if the name is found. The holder may be |
| 4129 | // NULL when this function is used from the compiler. |
| 4130 | void LookupInDescriptors(JSObject* holder, |
| 4131 | String* name, |
| 4132 | LookupResult* result); |
| 4133 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 4134 | MUST_USE_RESULT MaybeObject* CopyDropDescriptors(); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4135 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 4136 | MUST_USE_RESULT MaybeObject* CopyNormalized(PropertyNormalizationMode mode, |
| 4137 | NormalizedMapSharingMode sharing); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4138 | |
| 4139 | // Returns a copy of the map, with all transitions dropped from the |
| 4140 | // instance descriptors. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 4141 | MUST_USE_RESULT MaybeObject* CopyDropTransitions(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4142 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4143 | // Returns this map if it already has elements that are fast, otherwise |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 4144 | // returns a copy of the map, with all transitions dropped from the |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4145 | // descriptors and the ElementsKind set to FAST_ELEMENTS. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 4146 | MUST_USE_RESULT inline MaybeObject* GetFastElementsMap(); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 4147 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4148 | // Returns this map if it already has fast elements that are doubles, |
| 4149 | // otherwise returns a copy of the map, with all transitions dropped from the |
| 4150 | // descriptors and the ElementsKind set to FAST_DOUBLE_ELEMENTS. |
| 4151 | MUST_USE_RESULT inline MaybeObject* GetFastDoubleElementsMap(); |
| 4152 | |
| 4153 | // Returns this map if already has dictionary elements, otherwise returns a |
| 4154 | // copy of the map, with all transitions dropped from the descriptors and the |
| 4155 | // ElementsKind set to DICTIONARY_ELEMENTS. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 4156 | MUST_USE_RESULT inline MaybeObject* GetSlowElementsMap(); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 4157 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4158 | // Returns a new map with all transitions dropped from the descriptors and the |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4159 | // ElementsKind set to one of the value corresponding to array_type. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4160 | MUST_USE_RESULT MaybeObject* GetExternalArrayElementsMap( |
| 4161 | ExternalArrayType array_type, |
| 4162 | bool safe_to_add_transition); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 4163 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4164 | // Returns the property index for name (only valid for FAST MODE). |
| 4165 | int PropertyIndexFor(String* name); |
| 4166 | |
| 4167 | // Returns the next free property index (only valid for FAST MODE). |
| 4168 | int NextFreePropertyIndex(); |
| 4169 | |
| 4170 | // Returns the number of properties described in instance_descriptors. |
| 4171 | int NumberOfDescribedProperties(); |
| 4172 | |
| 4173 | // Casting. |
| 4174 | static inline Map* cast(Object* obj); |
| 4175 | |
| 4176 | // Locate an accessor in the instance descriptor. |
| 4177 | AccessorDescriptor* FindAccessor(String* name); |
| 4178 | |
| 4179 | // Code cache operations. |
| 4180 | |
| 4181 | // Clears the code cache. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4182 | inline void ClearCodeCache(Heap* heap); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4183 | |
| 4184 | // Update code cache. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 4185 | MUST_USE_RESULT MaybeObject* UpdateCodeCache(String* name, Code* code); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4186 | |
| 4187 | // Returns the found code or undefined if absent. |
| 4188 | Object* FindInCodeCache(String* name, Code::Flags flags); |
| 4189 | |
| 4190 | // Returns the non-negative index of the code object if it is in the |
| 4191 | // cache and -1 otherwise. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4192 | int IndexInCodeCache(Object* name, Code* code); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4193 | |
| 4194 | // Removes a code object from the code cache at the given index. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4195 | void RemoveFromCodeCache(String* name, Code* code, int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4196 | |
| 4197 | // For every transition in this map, makes the transition's |
| 4198 | // target's prototype pointer point back to this map. |
| 4199 | // This is undone in MarkCompactCollector::ClearNonLiveTransitions(). |
| 4200 | void CreateBackPointers(); |
| 4201 | |
| 4202 | // Set all map transitions from this map to dead maps to null. |
| 4203 | // Also, restore the original prototype on the targets of these |
| 4204 | // transitions, so that we do not process this map again while |
| 4205 | // following back pointers. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4206 | void ClearNonLiveTransitions(Heap* heap, Object* real_prototype); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4207 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4208 | // Computes a hash value for this map, to be used in HashTables and such. |
| 4209 | int Hash(); |
| 4210 | |
| 4211 | // Compares this map to another to see if they describe equivalent objects. |
| 4212 | // If |mode| is set to CLEAR_INOBJECT_PROPERTIES, |other| is treated as if |
| 4213 | // it had exactly zero inobject properties. |
| 4214 | // The "shared" flags of both this map and |other| are ignored. |
| 4215 | bool EquivalentToForNormalization(Map* other, PropertyNormalizationMode mode); |
| 4216 | |
| 4217 | // Returns true if this map and |other| describe equivalent objects. |
| 4218 | // The "shared" flags of both this map and |other| are ignored. |
| 4219 | bool EquivalentTo(Map* other) { |
| 4220 | return EquivalentToForNormalization(other, KEEP_INOBJECT_PROPERTIES); |
| 4221 | } |
| 4222 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4223 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4224 | #ifdef OBJECT_PRINT |
| 4225 | inline void MapPrint() { |
| 4226 | MapPrint(stdout); |
| 4227 | } |
| 4228 | void MapPrint(FILE* out); |
| 4229 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4230 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4231 | void MapVerify(); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4232 | void SharedMapVerify(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4233 | #endif |
| 4234 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 4235 | inline int visitor_id(); |
| 4236 | inline void set_visitor_id(int visitor_id); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 4237 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4238 | // Returns the isolate/heap this map belongs to. |
| 4239 | inline Isolate* isolate(); |
| 4240 | inline Heap* heap(); |
| 4241 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4242 | typedef void (*TraverseCallback)(Map* map, void* data); |
| 4243 | |
| 4244 | void TraverseTransitionTree(TraverseCallback callback, void* data); |
| 4245 | |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 4246 | static const int kMaxCachedPrototypeTransitions = 256; |
| 4247 | |
| 4248 | Object* GetPrototypeTransition(Object* prototype); |
| 4249 | |
| 4250 | MaybeObject* PutPrototypeTransition(Object* prototype, Map* map); |
| 4251 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4252 | static const int kMaxPreAllocatedPropertyFields = 255; |
| 4253 | |
| 4254 | // Layout description. |
| 4255 | static const int kInstanceSizesOffset = HeapObject::kHeaderSize; |
| 4256 | static const int kInstanceAttributesOffset = kInstanceSizesOffset + kIntSize; |
| 4257 | static const int kPrototypeOffset = kInstanceAttributesOffset + kIntSize; |
| 4258 | static const int kConstructorOffset = kPrototypeOffset + kPointerSize; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4259 | // Storage for instance descriptors is overloaded to also contain additional |
| 4260 | // map flags when unused (bit_field3). When the map has instance descriptors, |
| 4261 | // the flags are transferred to the instance descriptor array and accessed |
| 4262 | // through an extra indirection. |
| 4263 | // TODO(1399): It should be possible to make room for bit_field3 in the map |
| 4264 | // without overloading the instance descriptors field, but the map is |
| 4265 | // currently perfectly aligned to 32 bytes and extending it at all would |
| 4266 | // double its size. After the increment GC work lands, this size restriction |
| 4267 | // could be loosened and bit_field3 moved directly back in the map. |
| 4268 | static const int kInstanceDescriptorsOrBitField3Offset = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4269 | kConstructorOffset + kPointerSize; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4270 | static const int kCodeCacheOffset = |
| 4271 | kInstanceDescriptorsOrBitField3Offset + kPointerSize; |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 4272 | static const int kPrototypeTransitionsOffset = |
| 4273 | kCodeCacheOffset + kPointerSize; |
| 4274 | static const int kPadStart = kPrototypeTransitionsOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4275 | static const int kSize = MAP_POINTER_ALIGN(kPadStart); |
| 4276 | |
| 4277 | // Layout of pointer fields. Heap iteration code relies on them |
| 4278 | // being continiously allocated. |
| 4279 | static const int kPointerFieldsBeginOffset = Map::kPrototypeOffset; |
| 4280 | static const int kPointerFieldsEndOffset = |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 4281 | Map::kPrototypeTransitionsOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4282 | |
| 4283 | // Byte offsets within kInstanceSizesOffset. |
| 4284 | static const int kInstanceSizeOffset = kInstanceSizesOffset + 0; |
| 4285 | static const int kInObjectPropertiesByte = 1; |
| 4286 | static const int kInObjectPropertiesOffset = |
| 4287 | kInstanceSizesOffset + kInObjectPropertiesByte; |
| 4288 | static const int kPreAllocatedPropertyFieldsByte = 2; |
| 4289 | static const int kPreAllocatedPropertyFieldsOffset = |
| 4290 | kInstanceSizesOffset + kPreAllocatedPropertyFieldsByte; |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 4291 | static const int kVisitorIdByte = 3; |
| 4292 | static const int kVisitorIdOffset = kInstanceSizesOffset + kVisitorIdByte; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4293 | |
| 4294 | // Byte offsets within kInstanceAttributesOffset attributes. |
| 4295 | static const int kInstanceTypeOffset = kInstanceAttributesOffset + 0; |
| 4296 | static const int kUnusedPropertyFieldsOffset = kInstanceAttributesOffset + 1; |
| 4297 | static const int kBitFieldOffset = kInstanceAttributesOffset + 2; |
| 4298 | static const int kBitField2Offset = kInstanceAttributesOffset + 3; |
| 4299 | |
| 4300 | STATIC_CHECK(kInstanceTypeOffset == Internals::kMapInstanceTypeOffset); |
| 4301 | |
| 4302 | // Bit positions for bit field. |
| 4303 | static const int kUnused = 0; // To be used for marking recently used maps. |
| 4304 | static const int kHasNonInstancePrototype = 1; |
| 4305 | static const int kIsHiddenPrototype = 2; |
| 4306 | static const int kHasNamedInterceptor = 3; |
| 4307 | static const int kHasIndexedInterceptor = 4; |
| 4308 | static const int kIsUndetectable = 5; |
| 4309 | static const int kHasInstanceCallHandler = 6; |
| 4310 | static const int kIsAccessCheckNeeded = 7; |
| 4311 | |
| 4312 | // Bit positions for bit field 2 |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 4313 | static const int kIsExtensible = 0; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4314 | static const int kFunctionWithPrototype = 1; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4315 | static const int kStringWrapperSafeForDefaultValueOf = 2; |
| 4316 | static const int kAttachedToSharedFunctionInfo = 3; |
| 4317 | // No bits can be used after kElementsKindFirstBit, they are all reserved for |
| 4318 | // storing ElementKind. for anything other than storing the ElementKind. |
| 4319 | static const int kElementsKindShift = 4; |
| 4320 | static const int kElementsKindBitCount = 4; |
| 4321 | |
| 4322 | // Derived values from bit field 2 |
| 4323 | static const int kElementsKindMask = (-1 << kElementsKindShift) & |
| 4324 | ((1 << (kElementsKindShift + kElementsKindBitCount)) - 1); |
| 4325 | static const int8_t kMaximumBitField2FastElementValue = static_cast<int8_t>( |
| 4326 | (JSObject::FAST_ELEMENTS + 1) << Map::kElementsKindShift) - 1; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4327 | |
| 4328 | // Bit positions for bit field 3 |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4329 | static const int kIsShared = 0; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4330 | |
| 4331 | // Layout of the default cache. It holds alternating name and code objects. |
| 4332 | static const int kCodeCacheEntrySize = 2; |
| 4333 | static const int kCodeCacheEntryNameOffset = 0; |
| 4334 | static const int kCodeCacheEntryCodeOffset = 1; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4335 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 4336 | typedef FixedBodyDescriptor<kPointerFieldsBeginOffset, |
| 4337 | kPointerFieldsEndOffset, |
| 4338 | kSize> BodyDescriptor; |
| 4339 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4340 | private: |
| 4341 | DISALLOW_IMPLICIT_CONSTRUCTORS(Map); |
| 4342 | }; |
| 4343 | |
| 4344 | |
| 4345 | // An abstract superclass, a marker class really, for simple structure classes. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4346 | // It doesn't carry much functionality but allows struct classes to be |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4347 | // identified in the type system. |
| 4348 | class Struct: public HeapObject { |
| 4349 | public: |
| 4350 | inline void InitializeBody(int object_size); |
| 4351 | static inline Struct* cast(Object* that); |
| 4352 | }; |
| 4353 | |
| 4354 | |
| 4355 | // Script describes a script which has been added to the VM. |
| 4356 | class Script: public Struct { |
| 4357 | public: |
| 4358 | // Script types. |
| 4359 | enum Type { |
| 4360 | TYPE_NATIVE = 0, |
| 4361 | TYPE_EXTENSION = 1, |
| 4362 | TYPE_NORMAL = 2 |
| 4363 | }; |
| 4364 | |
| 4365 | // Script compilation types. |
| 4366 | enum CompilationType { |
| 4367 | COMPILATION_TYPE_HOST = 0, |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 4368 | COMPILATION_TYPE_EVAL = 1 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4369 | }; |
| 4370 | |
| 4371 | // [source]: the script source. |
| 4372 | DECL_ACCESSORS(source, Object) |
| 4373 | |
| 4374 | // [name]: the script name. |
| 4375 | DECL_ACCESSORS(name, Object) |
| 4376 | |
| 4377 | // [id]: the script id. |
| 4378 | DECL_ACCESSORS(id, Object) |
| 4379 | |
| 4380 | // [line_offset]: script line offset in resource from where it was extracted. |
| 4381 | DECL_ACCESSORS(line_offset, Smi) |
| 4382 | |
| 4383 | // [column_offset]: script column offset in resource from where it was |
| 4384 | // extracted. |
| 4385 | DECL_ACCESSORS(column_offset, Smi) |
| 4386 | |
| 4387 | // [data]: additional data associated with this script. |
| 4388 | DECL_ACCESSORS(data, Object) |
| 4389 | |
| 4390 | // [context_data]: context data for the context this script was compiled in. |
| 4391 | DECL_ACCESSORS(context_data, Object) |
| 4392 | |
| 4393 | // [wrapper]: the wrapper cache. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4394 | DECL_ACCESSORS(wrapper, Foreign) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4395 | |
| 4396 | // [type]: the script type. |
| 4397 | DECL_ACCESSORS(type, Smi) |
| 4398 | |
| 4399 | // [compilation]: how the the script was compiled. |
| 4400 | DECL_ACCESSORS(compilation_type, Smi) |
| 4401 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4402 | // [line_ends]: FixedArray of line ends positions. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4403 | DECL_ACCESSORS(line_ends, Object) |
| 4404 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4405 | // [eval_from_shared]: for eval scripts the shared funcion info for the |
| 4406 | // function from which eval was called. |
| 4407 | DECL_ACCESSORS(eval_from_shared, Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4408 | |
| 4409 | // [eval_from_instructions_offset]: the instruction offset in the code for the |
| 4410 | // function from which eval was called where eval was called. |
| 4411 | DECL_ACCESSORS(eval_from_instructions_offset, Smi) |
| 4412 | |
| 4413 | static inline Script* cast(Object* obj); |
| 4414 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 4415 | // If script source is an external string, check that the underlying |
| 4416 | // resource is accessible. Otherwise, always return true. |
| 4417 | inline bool HasValidSource(); |
| 4418 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4419 | #ifdef OBJECT_PRINT |
| 4420 | inline void ScriptPrint() { |
| 4421 | ScriptPrint(stdout); |
| 4422 | } |
| 4423 | void ScriptPrint(FILE* out); |
| 4424 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4425 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4426 | void ScriptVerify(); |
| 4427 | #endif |
| 4428 | |
| 4429 | static const int kSourceOffset = HeapObject::kHeaderSize; |
| 4430 | static const int kNameOffset = kSourceOffset + kPointerSize; |
| 4431 | static const int kLineOffsetOffset = kNameOffset + kPointerSize; |
| 4432 | static const int kColumnOffsetOffset = kLineOffsetOffset + kPointerSize; |
| 4433 | static const int kDataOffset = kColumnOffsetOffset + kPointerSize; |
| 4434 | static const int kContextOffset = kDataOffset + kPointerSize; |
| 4435 | static const int kWrapperOffset = kContextOffset + kPointerSize; |
| 4436 | static const int kTypeOffset = kWrapperOffset + kPointerSize; |
| 4437 | static const int kCompilationTypeOffset = kTypeOffset + kPointerSize; |
| 4438 | static const int kLineEndsOffset = kCompilationTypeOffset + kPointerSize; |
| 4439 | static const int kIdOffset = kLineEndsOffset + kPointerSize; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4440 | static const int kEvalFromSharedOffset = kIdOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4441 | static const int kEvalFrominstructionsOffsetOffset = |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4442 | kEvalFromSharedOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4443 | static const int kSize = kEvalFrominstructionsOffsetOffset + kPointerSize; |
| 4444 | |
| 4445 | private: |
| 4446 | DISALLOW_IMPLICIT_CONSTRUCTORS(Script); |
| 4447 | }; |
| 4448 | |
| 4449 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4450 | // List of builtin functions we want to identify to improve code |
| 4451 | // generation. |
| 4452 | // |
| 4453 | // Each entry has a name of a global object property holding an object |
| 4454 | // optionally followed by ".prototype", a name of a builtin function |
| 4455 | // on the object (the one the id is set for), and a label. |
| 4456 | // |
| 4457 | // Installation of ids for the selected builtin functions is handled |
| 4458 | // by the bootstrapper. |
| 4459 | // |
| 4460 | // NOTE: Order is important: math functions should be at the end of |
| 4461 | // the list and MathFloor should be the first math function. |
| 4462 | #define FUNCTIONS_WITH_ID_LIST(V) \ |
| 4463 | V(Array.prototype, push, ArrayPush) \ |
| 4464 | V(Array.prototype, pop, ArrayPop) \ |
Ben Murdoch | 42effa5 | 2011-08-19 16:40:31 +0100 | [diff] [blame] | 4465 | V(Function.prototype, apply, FunctionApply) \ |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4466 | V(String.prototype, charCodeAt, StringCharCodeAt) \ |
| 4467 | V(String.prototype, charAt, StringCharAt) \ |
| 4468 | V(String, fromCharCode, StringFromCharCode) \ |
| 4469 | V(Math, floor, MathFloor) \ |
| 4470 | V(Math, round, MathRound) \ |
| 4471 | V(Math, ceil, MathCeil) \ |
| 4472 | V(Math, abs, MathAbs) \ |
| 4473 | V(Math, log, MathLog) \ |
| 4474 | V(Math, sin, MathSin) \ |
| 4475 | V(Math, cos, MathCos) \ |
| 4476 | V(Math, tan, MathTan) \ |
| 4477 | V(Math, asin, MathASin) \ |
| 4478 | V(Math, acos, MathACos) \ |
| 4479 | V(Math, atan, MathATan) \ |
| 4480 | V(Math, exp, MathExp) \ |
| 4481 | V(Math, sqrt, MathSqrt) \ |
| 4482 | V(Math, pow, MathPow) |
| 4483 | |
| 4484 | |
| 4485 | enum BuiltinFunctionId { |
| 4486 | #define DECLARE_FUNCTION_ID(ignored1, ignore2, name) \ |
| 4487 | k##name, |
| 4488 | FUNCTIONS_WITH_ID_LIST(DECLARE_FUNCTION_ID) |
| 4489 | #undef DECLARE_FUNCTION_ID |
| 4490 | // Fake id for a special case of Math.pow. Note, it continues the |
| 4491 | // list of math functions. |
| 4492 | kMathPowHalf, |
| 4493 | kFirstMathFunctionId = kMathFloor |
| 4494 | }; |
| 4495 | |
| 4496 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4497 | // SharedFunctionInfo describes the JSFunction information that can be |
| 4498 | // shared by multiple instances of the function. |
| 4499 | class SharedFunctionInfo: public HeapObject { |
| 4500 | public: |
| 4501 | // [name]: Function name. |
| 4502 | DECL_ACCESSORS(name, Object) |
| 4503 | |
| 4504 | // [code]: Function code. |
| 4505 | DECL_ACCESSORS(code, Code) |
| 4506 | |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 4507 | // [scope_info]: Scope info. |
| 4508 | DECL_ACCESSORS(scope_info, SerializedScopeInfo) |
| 4509 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4510 | // [construct stub]: Code stub for constructing instances of this function. |
| 4511 | DECL_ACCESSORS(construct_stub, Code) |
| 4512 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 4513 | inline Code* unchecked_code(); |
| 4514 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4515 | // Returns if this function has been compiled to native code yet. |
| 4516 | inline bool is_compiled(); |
| 4517 | |
| 4518 | // [length]: The function length - usually the number of declared parameters. |
| 4519 | // Use up to 2^30 parameters. |
| 4520 | inline int length(); |
| 4521 | inline void set_length(int value); |
| 4522 | |
| 4523 | // [formal parameter count]: The declared number of parameters. |
| 4524 | inline int formal_parameter_count(); |
| 4525 | inline void set_formal_parameter_count(int value); |
| 4526 | |
| 4527 | // Set the formal parameter count so the function code will be |
| 4528 | // called without using argument adaptor frames. |
| 4529 | inline void DontAdaptArguments(); |
| 4530 | |
| 4531 | // [expected_nof_properties]: Expected number of properties for the function. |
| 4532 | inline int expected_nof_properties(); |
| 4533 | inline void set_expected_nof_properties(int value); |
| 4534 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4535 | // Inobject slack tracking is the way to reclaim unused inobject space. |
| 4536 | // |
| 4537 | // The instance size is initially determined by adding some slack to |
| 4538 | // expected_nof_properties (to allow for a few extra properties added |
| 4539 | // after the constructor). There is no guarantee that the extra space |
| 4540 | // will not be wasted. |
| 4541 | // |
| 4542 | // Here is the algorithm to reclaim the unused inobject space: |
| 4543 | // - Detect the first constructor call for this SharedFunctionInfo. |
| 4544 | // When it happens enter the "in progress" state: remember the |
| 4545 | // constructor's initial_map and install a special construct stub that |
| 4546 | // counts constructor calls. |
| 4547 | // - While the tracking is in progress create objects filled with |
| 4548 | // one_pointer_filler_map instead of undefined_value. This way they can be |
| 4549 | // resized quickly and safely. |
| 4550 | // - Once enough (kGenerousAllocationCount) objects have been created |
| 4551 | // compute the 'slack' (traverse the map transition tree starting from the |
| 4552 | // initial_map and find the lowest value of unused_property_fields). |
| 4553 | // - Traverse the transition tree again and decrease the instance size |
| 4554 | // of every map. Existing objects will resize automatically (they are |
| 4555 | // filled with one_pointer_filler_map). All further allocations will |
| 4556 | // use the adjusted instance size. |
| 4557 | // - Decrease expected_nof_properties so that an allocations made from |
| 4558 | // another context will use the adjusted instance size too. |
| 4559 | // - Exit "in progress" state by clearing the reference to the initial_map |
| 4560 | // and setting the regular construct stub (generic or inline). |
| 4561 | // |
| 4562 | // The above is the main event sequence. Some special cases are possible |
| 4563 | // while the tracking is in progress: |
| 4564 | // |
| 4565 | // - GC occurs. |
| 4566 | // Check if the initial_map is referenced by any live objects (except this |
| 4567 | // SharedFunctionInfo). If it is, continue tracking as usual. |
| 4568 | // If it is not, clear the reference and reset the tracking state. The |
| 4569 | // tracking will be initiated again on the next constructor call. |
| 4570 | // |
| 4571 | // - The constructor is called from another context. |
| 4572 | // Immediately complete the tracking, perform all the necessary changes |
| 4573 | // to maps. This is necessary because there is no efficient way to track |
| 4574 | // multiple initial_maps. |
| 4575 | // Proceed to create an object in the current context (with the adjusted |
| 4576 | // size). |
| 4577 | // |
| 4578 | // - A different constructor function sharing the same SharedFunctionInfo is |
| 4579 | // called in the same context. This could be another closure in the same |
| 4580 | // context, or the first function could have been disposed. |
| 4581 | // This is handled the same way as the previous case. |
| 4582 | // |
| 4583 | // Important: inobject slack tracking is not attempted during the snapshot |
| 4584 | // creation. |
| 4585 | |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 4586 | static const int kGenerousAllocationCount = 8; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4587 | |
| 4588 | // [construction_count]: Counter for constructor calls made during |
| 4589 | // the tracking phase. |
| 4590 | inline int construction_count(); |
| 4591 | inline void set_construction_count(int value); |
| 4592 | |
| 4593 | // [initial_map]: initial map of the first function called as a constructor. |
| 4594 | // Saved for the duration of the tracking phase. |
| 4595 | // This is a weak link (GC resets it to undefined_value if no other live |
| 4596 | // object reference this map). |
| 4597 | DECL_ACCESSORS(initial_map, Object) |
| 4598 | |
| 4599 | // True if the initial_map is not undefined and the countdown stub is |
| 4600 | // installed. |
| 4601 | inline bool IsInobjectSlackTrackingInProgress(); |
| 4602 | |
| 4603 | // Starts the tracking. |
| 4604 | // Stores the initial map and installs the countdown stub. |
| 4605 | // IsInobjectSlackTrackingInProgress is normally true after this call, |
| 4606 | // except when tracking have not been started (e.g. the map has no unused |
| 4607 | // properties or the snapshot is being built). |
| 4608 | void StartInobjectSlackTracking(Map* map); |
| 4609 | |
| 4610 | // Completes the tracking. |
| 4611 | // IsInobjectSlackTrackingInProgress is false after this call. |
| 4612 | void CompleteInobjectSlackTracking(); |
| 4613 | |
| 4614 | // Clears the initial_map before the GC marking phase to ensure the reference |
| 4615 | // is weak. IsInobjectSlackTrackingInProgress is false after this call. |
| 4616 | void DetachInitialMap(); |
| 4617 | |
| 4618 | // Restores the link to the initial map after the GC marking phase. |
| 4619 | // IsInobjectSlackTrackingInProgress is true after this call. |
| 4620 | void AttachInitialMap(Map* map); |
| 4621 | |
| 4622 | // False if there are definitely no live objects created from this function. |
| 4623 | // True if live objects _may_ exist (existence not guaranteed). |
| 4624 | // May go back from true to false after GC. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4625 | DECL_BOOLEAN_ACCESSORS(live_objects_may_exist) |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4626 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4627 | // [instance class name]: class name for instances. |
| 4628 | DECL_ACCESSORS(instance_class_name, Object) |
| 4629 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4630 | // [function data]: This field holds some additional data for function. |
| 4631 | // Currently it either has FunctionTemplateInfo to make benefit the API |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4632 | // or Smi identifying a builtin function. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4633 | // In the long run we don't want all functions to have this field but |
| 4634 | // we can fix that when we have a better model for storing hidden data |
| 4635 | // on objects. |
| 4636 | DECL_ACCESSORS(function_data, Object) |
| 4637 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4638 | inline bool IsApiFunction(); |
| 4639 | inline FunctionTemplateInfo* get_api_func_data(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4640 | inline bool HasBuiltinFunctionId(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4641 | inline BuiltinFunctionId builtin_function_id(); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4642 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4643 | // [script info]: Script from which the function originates. |
| 4644 | DECL_ACCESSORS(script, Object) |
| 4645 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4646 | // [num_literals]: Number of literals used by this function. |
| 4647 | inline int num_literals(); |
| 4648 | inline void set_num_literals(int value); |
| 4649 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4650 | // [start_position_and_type]: Field used to store both the source code |
| 4651 | // position, whether or not the function is a function expression, |
| 4652 | // and whether or not the function is a toplevel function. The two |
| 4653 | // least significants bit indicates whether the function is an |
| 4654 | // expression and the rest contains the source code position. |
| 4655 | inline int start_position_and_type(); |
| 4656 | inline void set_start_position_and_type(int value); |
| 4657 | |
| 4658 | // [debug info]: Debug information. |
| 4659 | DECL_ACCESSORS(debug_info, Object) |
| 4660 | |
| 4661 | // [inferred name]: Name inferred from variable or property |
| 4662 | // assignment of this function. Used to facilitate debugging and |
| 4663 | // profiling of JavaScript code written in OO style, where almost |
| 4664 | // all functions are anonymous but are assigned to object |
| 4665 | // properties. |
| 4666 | DECL_ACCESSORS(inferred_name, String) |
| 4667 | |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 4668 | // The function's name if it is non-empty, otherwise the inferred name. |
| 4669 | String* DebugName(); |
| 4670 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4671 | // Position of the 'function' token in the script source. |
| 4672 | inline int function_token_position(); |
| 4673 | inline void set_function_token_position(int function_token_position); |
| 4674 | |
| 4675 | // Position of this function in the script source. |
| 4676 | inline int start_position(); |
| 4677 | inline void set_start_position(int start_position); |
| 4678 | |
| 4679 | // End position of this function in the script source. |
| 4680 | inline int end_position(); |
| 4681 | inline void set_end_position(int end_position); |
| 4682 | |
| 4683 | // Is this function a function expression in the source code. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4684 | DECL_BOOLEAN_ACCESSORS(is_expression) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4685 | |
| 4686 | // Is this function a top-level function (scripts, evals). |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4687 | DECL_BOOLEAN_ACCESSORS(is_toplevel) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4688 | |
| 4689 | // Bit field containing various information collected by the compiler to |
| 4690 | // drive optimization. |
| 4691 | inline int compiler_hints(); |
| 4692 | inline void set_compiler_hints(int value); |
| 4693 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4694 | // A counter used to determine when to stress the deoptimizer with a |
| 4695 | // deopt. |
| 4696 | inline Smi* deopt_counter(); |
| 4697 | inline void set_deopt_counter(Smi* counter); |
| 4698 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4699 | // Add information on assignments of the form this.x = ...; |
| 4700 | void SetThisPropertyAssignmentsInfo( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4701 | bool has_only_simple_this_property_assignments, |
| 4702 | FixedArray* this_property_assignments); |
| 4703 | |
| 4704 | // Clear information on assignments of the form this.x = ...; |
| 4705 | void ClearThisPropertyAssignmentsInfo(); |
| 4706 | |
| 4707 | // Indicate that this function only consists of assignments of the form |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4708 | // this.x = y; where y is either a constant or refers to an argument. |
| 4709 | inline bool has_only_simple_this_property_assignments(); |
| 4710 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4711 | // Indicates if this function can be lazy compiled. |
| 4712 | // This is used to determine if we can safely flush code from a function |
| 4713 | // 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] | 4714 | DECL_BOOLEAN_ACCESSORS(allows_lazy_compilation) |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4715 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 4716 | // Indicates how many full GCs this function has survived with assigned |
| 4717 | // code object. Used to determine when it is relatively safe to flush |
| 4718 | // this code object and replace it with lazy compilation stub. |
| 4719 | // Age is reset when GC notices that the code object is referenced |
| 4720 | // from the stack or compilation cache. |
| 4721 | inline int code_age(); |
| 4722 | inline void set_code_age(int age); |
| 4723 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4724 | // Indicates whether optimizations have been disabled for this |
| 4725 | // shared function info. If a function is repeatedly optimized or if |
| 4726 | // we cannot optimize the function we disable optimization to avoid |
| 4727 | // spending time attempting to optimize it again. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4728 | DECL_BOOLEAN_ACCESSORS(optimization_disabled) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4729 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 4730 | // Indicates whether the function is a strict mode function. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4731 | DECL_BOOLEAN_ACCESSORS(strict_mode) |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 4732 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4733 | // False if the function definitely does not allocate an arguments object. |
| 4734 | DECL_BOOLEAN_ACCESSORS(uses_arguments) |
| 4735 | |
| 4736 | // True if the function has any duplicated parameter names. |
| 4737 | DECL_BOOLEAN_ACCESSORS(has_duplicate_parameters) |
| 4738 | |
| 4739 | // Indicates whether the function is a native function. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4740 | // These needs special threatment in .call and .apply since |
| 4741 | // null passed as the receiver should not be translated to the |
| 4742 | // global object. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4743 | DECL_BOOLEAN_ACCESSORS(native) |
| 4744 | |
| 4745 | // Indicates that the function was created by the Function function. |
| 4746 | // Though it's anonymous, toString should treat it as if it had the name |
| 4747 | // "anonymous". We don't set the name itself so that the system does not |
| 4748 | // see a binding for it. |
| 4749 | DECL_BOOLEAN_ACCESSORS(name_should_print_as_anonymous) |
| 4750 | |
| 4751 | // Indicates whether the function is a bound function created using |
| 4752 | // the bind function. |
| 4753 | DECL_BOOLEAN_ACCESSORS(bound) |
| 4754 | |
| 4755 | // Indicates that the function is anonymous (the name field can be set |
| 4756 | // through the API, which does not change this flag). |
| 4757 | DECL_BOOLEAN_ACCESSORS(is_anonymous) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4758 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4759 | // Indicates whether or not the code in the shared function support |
| 4760 | // deoptimization. |
| 4761 | inline bool has_deoptimization_support(); |
| 4762 | |
| 4763 | // Enable deoptimization support through recompiled code. |
| 4764 | void EnableDeoptimizationSupport(Code* recompiled); |
| 4765 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4766 | // Disable (further) attempted optimization of all functions sharing this |
| 4767 | // shared function info. The function is the one we actually tried to |
| 4768 | // optimize. |
| 4769 | void DisableOptimization(JSFunction* function); |
| 4770 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4771 | // Lookup the bailout ID and ASSERT that it exists in the non-optimized |
| 4772 | // code, returns whether it asserted (i.e., always true if assertions are |
| 4773 | // disabled). |
| 4774 | bool VerifyBailoutId(int id); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 4775 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 4776 | // Check whether a inlined constructor can be generated with the given |
| 4777 | // prototype. |
| 4778 | bool CanGenerateInlineConstructor(Object* prototype); |
| 4779 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4780 | // Prevents further attempts to generate inline constructors. |
| 4781 | // To be called if generation failed for any reason. |
| 4782 | void ForbidInlineConstructor(); |
| 4783 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4784 | // For functions which only contains this property assignments this provides |
| 4785 | // access to the names for the properties assigned. |
| 4786 | DECL_ACCESSORS(this_property_assignments, Object) |
| 4787 | inline int this_property_assignments_count(); |
| 4788 | inline void set_this_property_assignments_count(int value); |
| 4789 | String* GetThisPropertyAssignmentName(int index); |
| 4790 | bool IsThisPropertyAssignmentArgument(int index); |
| 4791 | int GetThisPropertyAssignmentArgument(int index); |
| 4792 | Object* GetThisPropertyAssignmentConstant(int index); |
| 4793 | |
| 4794 | // [source code]: Source code for the function. |
| 4795 | bool HasSourceCode(); |
| 4796 | Object* GetSourceCode(); |
| 4797 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4798 | inline int opt_count(); |
| 4799 | inline void set_opt_count(int opt_count); |
| 4800 | |
| 4801 | // Source size of this function. |
| 4802 | int SourceSize(); |
| 4803 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4804 | // Calculate the instance size. |
| 4805 | int CalculateInstanceSize(); |
| 4806 | |
| 4807 | // Calculate the number of in-object properties. |
| 4808 | int CalculateInObjectProperties(); |
| 4809 | |
| 4810 | // Dispatched behavior. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4811 | // Set max_length to -1 for unlimited length. |
| 4812 | void SourceCodePrint(StringStream* accumulator, int max_length); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4813 | #ifdef OBJECT_PRINT |
| 4814 | inline void SharedFunctionInfoPrint() { |
| 4815 | SharedFunctionInfoPrint(stdout); |
| 4816 | } |
| 4817 | void SharedFunctionInfoPrint(FILE* out); |
| 4818 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4819 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4820 | void SharedFunctionInfoVerify(); |
| 4821 | #endif |
| 4822 | |
| 4823 | // Casting. |
| 4824 | static inline SharedFunctionInfo* cast(Object* obj); |
| 4825 | |
| 4826 | // Constants. |
| 4827 | static const int kDontAdaptArgumentsSentinel = -1; |
| 4828 | |
| 4829 | // Layout description. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4830 | // Pointer fields. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4831 | static const int kNameOffset = HeapObject::kHeaderSize; |
| 4832 | static const int kCodeOffset = kNameOffset + kPointerSize; |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 4833 | static const int kScopeInfoOffset = kCodeOffset + kPointerSize; |
| 4834 | static const int kConstructStubOffset = kScopeInfoOffset + kPointerSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4835 | static const int kInstanceClassNameOffset = |
| 4836 | kConstructStubOffset + kPointerSize; |
| 4837 | static const int kFunctionDataOffset = |
| 4838 | kInstanceClassNameOffset + kPointerSize; |
| 4839 | static const int kScriptOffset = kFunctionDataOffset + kPointerSize; |
| 4840 | static const int kDebugInfoOffset = kScriptOffset + kPointerSize; |
| 4841 | static const int kInferredNameOffset = kDebugInfoOffset + kPointerSize; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4842 | static const int kInitialMapOffset = |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4843 | kInferredNameOffset + kPointerSize; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4844 | static const int kThisPropertyAssignmentsOffset = |
| 4845 | kInitialMapOffset + kPointerSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4846 | static const int kDeoptCounterOffset = |
| 4847 | kThisPropertyAssignmentsOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4848 | #if V8_HOST_ARCH_32_BIT |
| 4849 | // Smi fields. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4850 | static const int kLengthOffset = |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4851 | kDeoptCounterOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4852 | static const int kFormalParameterCountOffset = kLengthOffset + kPointerSize; |
| 4853 | static const int kExpectedNofPropertiesOffset = |
| 4854 | kFormalParameterCountOffset + kPointerSize; |
| 4855 | static const int kNumLiteralsOffset = |
| 4856 | kExpectedNofPropertiesOffset + kPointerSize; |
| 4857 | static const int kStartPositionAndTypeOffset = |
| 4858 | kNumLiteralsOffset + kPointerSize; |
| 4859 | static const int kEndPositionOffset = |
| 4860 | kStartPositionAndTypeOffset + kPointerSize; |
| 4861 | static const int kFunctionTokenPositionOffset = |
| 4862 | kEndPositionOffset + kPointerSize; |
| 4863 | static const int kCompilerHintsOffset = |
| 4864 | kFunctionTokenPositionOffset + kPointerSize; |
| 4865 | static const int kThisPropertyAssignmentsCountOffset = |
| 4866 | kCompilerHintsOffset + kPointerSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4867 | static const int kOptCountOffset = |
| 4868 | kThisPropertyAssignmentsCountOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4869 | // Total size. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4870 | static const int kSize = kOptCountOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4871 | #else |
| 4872 | // The only reason to use smi fields instead of int fields |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4873 | // is to allow iteration without maps decoding during |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4874 | // garbage collections. |
| 4875 | // To avoid wasting space on 64-bit architectures we use |
| 4876 | // the following trick: we group integer fields into pairs |
| 4877 | // First integer in each pair is shifted left by 1. |
| 4878 | // By doing this we guarantee that LSB of each kPointerSize aligned |
| 4879 | // word is not set and thus this word cannot be treated as pointer |
| 4880 | // to HeapObject during old space traversal. |
| 4881 | static const int kLengthOffset = |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4882 | kDeoptCounterOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4883 | static const int kFormalParameterCountOffset = |
| 4884 | kLengthOffset + kIntSize; |
| 4885 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4886 | static const int kExpectedNofPropertiesOffset = |
| 4887 | kFormalParameterCountOffset + kIntSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4888 | static const int kNumLiteralsOffset = |
| 4889 | kExpectedNofPropertiesOffset + kIntSize; |
| 4890 | |
| 4891 | static const int kEndPositionOffset = |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4892 | kNumLiteralsOffset + kIntSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4893 | static const int kStartPositionAndTypeOffset = |
| 4894 | kEndPositionOffset + kIntSize; |
| 4895 | |
| 4896 | static const int kFunctionTokenPositionOffset = |
| 4897 | kStartPositionAndTypeOffset + kIntSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4898 | static const int kCompilerHintsOffset = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4899 | kFunctionTokenPositionOffset + kIntSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4900 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4901 | static const int kThisPropertyAssignmentsCountOffset = |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4902 | kCompilerHintsOffset + kIntSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4903 | static const int kOptCountOffset = |
| 4904 | kThisPropertyAssignmentsCountOffset + kIntSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4905 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4906 | // Total size. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4907 | static const int kSize = kOptCountOffset + kIntSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4908 | |
| 4909 | #endif |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4910 | |
| 4911 | // The construction counter for inobject slack tracking is stored in the |
| 4912 | // most significant byte of compiler_hints which is otherwise unused. |
| 4913 | // Its offset depends on the endian-ness of the architecture. |
| 4914 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 4915 | static const int kConstructionCountOffset = kCompilerHintsOffset + 3; |
| 4916 | #elif __BYTE_ORDER == __BIG_ENDIAN |
| 4917 | static const int kConstructionCountOffset = kCompilerHintsOffset + 0; |
| 4918 | #else |
| 4919 | #error Unknown byte ordering |
| 4920 | #endif |
| 4921 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4922 | static const int kAlignedSize = POINTER_SIZE_ALIGN(kSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4923 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 4924 | typedef FixedBodyDescriptor<kNameOffset, |
| 4925 | kThisPropertyAssignmentsOffset + kPointerSize, |
| 4926 | kSize> BodyDescriptor; |
| 4927 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4928 | // Bit positions in start_position_and_type. |
| 4929 | // The source code start position is in the 30 most significant bits of |
| 4930 | // the start_position_and_type field. |
| 4931 | static const int kIsExpressionBit = 0; |
| 4932 | static const int kIsTopLevelBit = 1; |
| 4933 | static const int kStartPositionShift = 2; |
| 4934 | static const int kStartPositionMask = ~((1 << kStartPositionShift) - 1); |
| 4935 | |
| 4936 | // Bit positions in compiler_hints. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4937 | static const int kCodeAgeSize = 3; |
| 4938 | static const int kCodeAgeMask = (1 << kCodeAgeSize) - 1; |
| 4939 | |
| 4940 | enum CompilerHints { |
| 4941 | kHasOnlySimpleThisPropertyAssignments, |
| 4942 | kAllowLazyCompilation, |
| 4943 | kLiveObjectsMayExist, |
| 4944 | kCodeAgeShift, |
| 4945 | kOptimizationDisabled = kCodeAgeShift + kCodeAgeSize, |
| 4946 | kStrictModeFunction, |
| 4947 | kUsesArguments, |
| 4948 | kHasDuplicateParameters, |
| 4949 | kNative, |
| 4950 | kBoundFunction, |
| 4951 | kIsAnonymous, |
| 4952 | kNameShouldPrintAsAnonymous, |
| 4953 | kCompilerHintsCount // Pseudo entry |
| 4954 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4955 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4956 | private: |
| 4957 | #if V8_HOST_ARCH_32_BIT |
| 4958 | // On 32 bit platforms, compiler hints is a smi. |
| 4959 | static const int kCompilerHintsSmiTagSize = kSmiTagSize; |
| 4960 | static const int kCompilerHintsSize = kPointerSize; |
| 4961 | #else |
| 4962 | // On 64 bit platforms, compiler hints is not a smi, see comment above. |
| 4963 | static const int kCompilerHintsSmiTagSize = 0; |
| 4964 | static const int kCompilerHintsSize = kIntSize; |
| 4965 | #endif |
| 4966 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4967 | STATIC_ASSERT(SharedFunctionInfo::kCompilerHintsCount <= |
| 4968 | SharedFunctionInfo::kCompilerHintsSize * kBitsPerByte); |
| 4969 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4970 | public: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4971 | // Constants for optimizing codegen for strict mode function and |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4972 | // native tests. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4973 | // Allows to use byte-widgh instructions. |
| 4974 | static const int kStrictModeBitWithinByte = |
| 4975 | (kStrictModeFunction + kCompilerHintsSmiTagSize) % kBitsPerByte; |
| 4976 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4977 | static const int kNativeBitWithinByte = |
| 4978 | (kNative + kCompilerHintsSmiTagSize) % kBitsPerByte; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4979 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4980 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 4981 | static const int kStrictModeByteOffset = kCompilerHintsOffset + |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4982 | (kStrictModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4983 | static const int kNativeByteOffset = kCompilerHintsOffset + |
| 4984 | (kNative + kCompilerHintsSmiTagSize) / kBitsPerByte; |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4985 | #elif __BYTE_ORDER == __BIG_ENDIAN |
| 4986 | static const int kStrictModeByteOffset = kCompilerHintsOffset + |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4987 | (kCompilerHintsSize - 1) - |
| 4988 | ((kStrictModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4989 | static const int kNativeByteOffset = kCompilerHintsOffset + |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4990 | (kCompilerHintsSize - 1) - |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4991 | ((kNative + kCompilerHintsSmiTagSize) / kBitsPerByte); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4992 | #else |
| 4993 | #error Unknown byte ordering |
| 4994 | #endif |
| 4995 | |
| 4996 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4997 | DISALLOW_IMPLICIT_CONSTRUCTORS(SharedFunctionInfo); |
| 4998 | }; |
| 4999 | |
| 5000 | |
| 5001 | // JSFunction describes JavaScript functions. |
| 5002 | class JSFunction: public JSObject { |
| 5003 | public: |
| 5004 | // [prototype_or_initial_map]: |
| 5005 | DECL_ACCESSORS(prototype_or_initial_map, Object) |
| 5006 | |
| 5007 | // [shared_function_info]: The information about the function that |
| 5008 | // can be shared by instances. |
| 5009 | DECL_ACCESSORS(shared, SharedFunctionInfo) |
| 5010 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 5011 | inline SharedFunctionInfo* unchecked_shared(); |
| 5012 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5013 | // [context]: The context for this function. |
| 5014 | inline Context* context(); |
| 5015 | inline Object* unchecked_context(); |
| 5016 | inline void set_context(Object* context); |
| 5017 | |
| 5018 | // [code]: The generated code object for this function. Executed |
| 5019 | // when the function is invoked, e.g. foo() or new foo(). See |
| 5020 | // [[Call]] and [[Construct]] description in ECMA-262, section |
| 5021 | // 8.6.2, page 27. |
| 5022 | inline Code* code(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5023 | inline void set_code(Code* code); |
| 5024 | inline void ReplaceCode(Code* code); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5025 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 5026 | inline Code* unchecked_code(); |
| 5027 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5028 | // Tells whether this function is builtin. |
| 5029 | inline bool IsBuiltin(); |
| 5030 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5031 | // Tells whether or not the function needs arguments adaption. |
| 5032 | inline bool NeedsArgumentsAdaption(); |
| 5033 | |
| 5034 | // Tells whether or not this function has been optimized. |
| 5035 | inline bool IsOptimized(); |
| 5036 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 5037 | // Tells whether or not this function can be optimized. |
| 5038 | inline bool IsOptimizable(); |
| 5039 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5040 | // Mark this function for lazy recompilation. The function will be |
| 5041 | // recompiled the next time it is executed. |
| 5042 | void MarkForLazyRecompilation(); |
| 5043 | |
| 5044 | // Tells whether or not the function is already marked for lazy |
| 5045 | // recompilation. |
| 5046 | inline bool IsMarkedForLazyRecompilation(); |
| 5047 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5048 | // Check whether or not this function is inlineable. |
| 5049 | bool IsInlineable(); |
| 5050 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5051 | // [literals]: Fixed array holding the materialized literals. |
| 5052 | // |
| 5053 | // If the function contains object, regexp or array literals, the |
| 5054 | // literals array prefix contains the object, regexp, and array |
| 5055 | // function to be used when creating these literals. This is |
| 5056 | // necessary so that we do not dynamically lookup the object, regexp |
| 5057 | // or array functions. Performing a dynamic lookup, we might end up |
| 5058 | // using the functions from a new context that we should not have |
| 5059 | // access to. |
| 5060 | DECL_ACCESSORS(literals, FixedArray) |
| 5061 | |
| 5062 | // The initial map for an object created by this constructor. |
| 5063 | inline Map* initial_map(); |
| 5064 | inline void set_initial_map(Map* value); |
| 5065 | inline bool has_initial_map(); |
| 5066 | |
| 5067 | // Get and set the prototype property on a JSFunction. If the |
| 5068 | // function has an initial map the prototype is set on the initial |
| 5069 | // map. Otherwise, the prototype is put in the initial map field |
| 5070 | // until an initial map is needed. |
| 5071 | inline bool has_prototype(); |
| 5072 | inline bool has_instance_prototype(); |
| 5073 | inline Object* prototype(); |
| 5074 | inline Object* instance_prototype(); |
| 5075 | Object* SetInstancePrototype(Object* value); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 5076 | MUST_USE_RESULT MaybeObject* SetPrototype(Object* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5077 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5078 | // After prototype is removed, it will not be created when accessed, and |
| 5079 | // [[Construct]] from this function will not be allowed. |
| 5080 | Object* RemovePrototype(); |
| 5081 | inline bool should_have_prototype(); |
| 5082 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5083 | // Accessor for this function's initial map's [[class]] |
| 5084 | // property. This is primarily used by ECMA native functions. This |
| 5085 | // method sets the class_name field of this function's initial map |
| 5086 | // to a given value. It creates an initial map if this function does |
| 5087 | // not have one. Note that this method does not copy the initial map |
| 5088 | // if it has one already, but simply replaces it with the new value. |
| 5089 | // Instances created afterwards will have a map whose [[class]] is |
| 5090 | // set to 'value', but there is no guarantees on instances created |
| 5091 | // before. |
| 5092 | Object* SetInstanceClassName(String* name); |
| 5093 | |
| 5094 | // Returns if this function has been compiled to native code yet. |
| 5095 | inline bool is_compiled(); |
| 5096 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5097 | // [next_function_link]: Field for linking functions. This list is treated as |
| 5098 | // a weak list by the GC. |
| 5099 | DECL_ACCESSORS(next_function_link, Object) |
| 5100 | |
| 5101 | // Prints the name of the function using PrintF. |
| 5102 | inline void PrintName() { |
| 5103 | PrintName(stdout); |
| 5104 | } |
| 5105 | void PrintName(FILE* out); |
| 5106 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5107 | // Casting. |
| 5108 | static inline JSFunction* cast(Object* obj); |
| 5109 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 5110 | // Iterates the objects, including code objects indirectly referenced |
| 5111 | // through pointers to the first instruction in the code object. |
| 5112 | void JSFunctionIterateBody(int object_size, ObjectVisitor* v); |
| 5113 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5114 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5115 | #ifdef OBJECT_PRINT |
| 5116 | inline void JSFunctionPrint() { |
| 5117 | JSFunctionPrint(stdout); |
| 5118 | } |
| 5119 | void JSFunctionPrint(FILE* out); |
| 5120 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5121 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5122 | void JSFunctionVerify(); |
| 5123 | #endif |
| 5124 | |
| 5125 | // Returns the number of allocated literals. |
| 5126 | inline int NumberOfLiterals(); |
| 5127 | |
| 5128 | // Retrieve the global context from a function's literal array. |
| 5129 | static Context* GlobalContextFromLiterals(FixedArray* literals); |
| 5130 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5131 | // Layout descriptors. The last property (from kNonWeakFieldsEndOffset to |
| 5132 | // kSize) is weak and has special handling during garbage collection. |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 5133 | static const int kCodeEntryOffset = JSObject::kHeaderSize; |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 5134 | static const int kPrototypeOrInitialMapOffset = |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 5135 | kCodeEntryOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5136 | static const int kSharedFunctionInfoOffset = |
| 5137 | kPrototypeOrInitialMapOffset + kPointerSize; |
| 5138 | static const int kContextOffset = kSharedFunctionInfoOffset + kPointerSize; |
| 5139 | static const int kLiteralsOffset = kContextOffset + kPointerSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5140 | static const int kNonWeakFieldsEndOffset = kLiteralsOffset + kPointerSize; |
| 5141 | static const int kNextFunctionLinkOffset = kNonWeakFieldsEndOffset; |
| 5142 | static const int kSize = kNextFunctionLinkOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5143 | |
| 5144 | // Layout of the literals array. |
| 5145 | static const int kLiteralsPrefixSize = 1; |
| 5146 | static const int kLiteralGlobalContextIndex = 0; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 5147 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5148 | private: |
| 5149 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunction); |
| 5150 | }; |
| 5151 | |
| 5152 | |
| 5153 | // JSGlobalProxy's prototype must be a JSGlobalObject or null, |
| 5154 | // and the prototype is hidden. JSGlobalProxy always delegates |
| 5155 | // property accesses to its prototype if the prototype is not null. |
| 5156 | // |
| 5157 | // A JSGlobalProxy can be reinitialized which will preserve its identity. |
| 5158 | // |
| 5159 | // Accessing a JSGlobalProxy requires security check. |
| 5160 | |
| 5161 | class JSGlobalProxy : public JSObject { |
| 5162 | public: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5163 | // [context]: the owner global context of this global proxy object. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5164 | // It is null value if this object is not used by any context. |
| 5165 | DECL_ACCESSORS(context, Object) |
| 5166 | |
| 5167 | // Casting. |
| 5168 | static inline JSGlobalProxy* cast(Object* obj); |
| 5169 | |
| 5170 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5171 | #ifdef OBJECT_PRINT |
| 5172 | inline void JSGlobalProxyPrint() { |
| 5173 | JSGlobalProxyPrint(stdout); |
| 5174 | } |
| 5175 | void JSGlobalProxyPrint(FILE* out); |
| 5176 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5177 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5178 | void JSGlobalProxyVerify(); |
| 5179 | #endif |
| 5180 | |
| 5181 | // Layout description. |
| 5182 | static const int kContextOffset = JSObject::kHeaderSize; |
| 5183 | static const int kSize = kContextOffset + kPointerSize; |
| 5184 | |
| 5185 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5186 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalProxy); |
| 5187 | }; |
| 5188 | |
| 5189 | |
| 5190 | // Forward declaration. |
| 5191 | class JSBuiltinsObject; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5192 | class JSGlobalPropertyCell; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5193 | |
| 5194 | // Common super class for JavaScript global objects and the special |
| 5195 | // builtins global objects. |
| 5196 | class GlobalObject: public JSObject { |
| 5197 | public: |
| 5198 | // [builtins]: the object holding the runtime routines written in JS. |
| 5199 | DECL_ACCESSORS(builtins, JSBuiltinsObject) |
| 5200 | |
| 5201 | // [global context]: the global context corresponding to this global object. |
| 5202 | DECL_ACCESSORS(global_context, Context) |
| 5203 | |
| 5204 | // [global receiver]: the global receiver object of the context |
| 5205 | DECL_ACCESSORS(global_receiver, JSObject) |
| 5206 | |
| 5207 | // Retrieve the property cell used to store a property. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5208 | JSGlobalPropertyCell* GetPropertyCell(LookupResult* result); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5209 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 5210 | // This is like GetProperty, but is used when you know the lookup won't fail |
| 5211 | // by throwing an exception. This is for the debug and builtins global |
| 5212 | // objects, where it is known which properties can be expected to be present |
| 5213 | // on the object. |
| 5214 | Object* GetPropertyNoExceptionThrown(String* key) { |
| 5215 | Object* answer = GetProperty(key)->ToObjectUnchecked(); |
| 5216 | return answer; |
| 5217 | } |
| 5218 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5219 | // Ensure that the global object has a cell for the given property name. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 5220 | MUST_USE_RESULT MaybeObject* EnsurePropertyCell(String* name); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5221 | |
| 5222 | // Casting. |
| 5223 | static inline GlobalObject* cast(Object* obj); |
| 5224 | |
| 5225 | // Layout description. |
| 5226 | static const int kBuiltinsOffset = JSObject::kHeaderSize; |
| 5227 | static const int kGlobalContextOffset = kBuiltinsOffset + kPointerSize; |
| 5228 | static const int kGlobalReceiverOffset = kGlobalContextOffset + kPointerSize; |
| 5229 | static const int kHeaderSize = kGlobalReceiverOffset + kPointerSize; |
| 5230 | |
| 5231 | private: |
| 5232 | friend class AGCCVersionRequiresThisClassToHaveAFriendSoHereItIs; |
| 5233 | |
| 5234 | DISALLOW_IMPLICIT_CONSTRUCTORS(GlobalObject); |
| 5235 | }; |
| 5236 | |
| 5237 | |
| 5238 | // JavaScript global object. |
| 5239 | class JSGlobalObject: public GlobalObject { |
| 5240 | public: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5241 | // Casting. |
| 5242 | static inline JSGlobalObject* cast(Object* obj); |
| 5243 | |
| 5244 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5245 | #ifdef OBJECT_PRINT |
| 5246 | inline void JSGlobalObjectPrint() { |
| 5247 | JSGlobalObjectPrint(stdout); |
| 5248 | } |
| 5249 | void JSGlobalObjectPrint(FILE* out); |
| 5250 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5251 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5252 | void JSGlobalObjectVerify(); |
| 5253 | #endif |
| 5254 | |
| 5255 | // Layout description. |
| 5256 | static const int kSize = GlobalObject::kHeaderSize; |
| 5257 | |
| 5258 | private: |
| 5259 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalObject); |
| 5260 | }; |
| 5261 | |
| 5262 | |
| 5263 | // Builtins global object which holds the runtime routines written in |
| 5264 | // JavaScript. |
| 5265 | class JSBuiltinsObject: public GlobalObject { |
| 5266 | public: |
| 5267 | // Accessors for the runtime routines written in JavaScript. |
| 5268 | inline Object* javascript_builtin(Builtins::JavaScript id); |
| 5269 | inline void set_javascript_builtin(Builtins::JavaScript id, Object* value); |
| 5270 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5271 | // Accessors for code of the runtime routines written in JavaScript. |
| 5272 | inline Code* javascript_builtin_code(Builtins::JavaScript id); |
| 5273 | inline void set_javascript_builtin_code(Builtins::JavaScript id, Code* value); |
| 5274 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5275 | // Casting. |
| 5276 | static inline JSBuiltinsObject* cast(Object* obj); |
| 5277 | |
| 5278 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5279 | #ifdef OBJECT_PRINT |
| 5280 | inline void JSBuiltinsObjectPrint() { |
| 5281 | JSBuiltinsObjectPrint(stdout); |
| 5282 | } |
| 5283 | void JSBuiltinsObjectPrint(FILE* out); |
| 5284 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5285 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5286 | void JSBuiltinsObjectVerify(); |
| 5287 | #endif |
| 5288 | |
| 5289 | // Layout description. The size of the builtins object includes |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5290 | // room for two pointers per runtime routine written in javascript |
| 5291 | // (function and code object). |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5292 | static const int kJSBuiltinsCount = Builtins::id_count; |
| 5293 | static const int kJSBuiltinsOffset = GlobalObject::kHeaderSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5294 | static const int kJSBuiltinsCodeOffset = |
| 5295 | GlobalObject::kHeaderSize + (kJSBuiltinsCount * kPointerSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5296 | static const int kSize = |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5297 | kJSBuiltinsCodeOffset + (kJSBuiltinsCount * kPointerSize); |
| 5298 | |
| 5299 | static int OffsetOfFunctionWithId(Builtins::JavaScript id) { |
| 5300 | return kJSBuiltinsOffset + id * kPointerSize; |
| 5301 | } |
| 5302 | |
| 5303 | static int OffsetOfCodeWithId(Builtins::JavaScript id) { |
| 5304 | return kJSBuiltinsCodeOffset + id * kPointerSize; |
| 5305 | } |
| 5306 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5307 | private: |
| 5308 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSBuiltinsObject); |
| 5309 | }; |
| 5310 | |
| 5311 | |
| 5312 | // Representation for JS Wrapper objects, String, Number, Boolean, Date, etc. |
| 5313 | class JSValue: public JSObject { |
| 5314 | public: |
| 5315 | // [value]: the object being wrapped. |
| 5316 | DECL_ACCESSORS(value, Object) |
| 5317 | |
| 5318 | // Casting. |
| 5319 | static inline JSValue* cast(Object* obj); |
| 5320 | |
| 5321 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5322 | #ifdef OBJECT_PRINT |
| 5323 | inline void JSValuePrint() { |
| 5324 | JSValuePrint(stdout); |
| 5325 | } |
| 5326 | void JSValuePrint(FILE* out); |
| 5327 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5328 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5329 | void JSValueVerify(); |
| 5330 | #endif |
| 5331 | |
| 5332 | // Layout description. |
| 5333 | static const int kValueOffset = JSObject::kHeaderSize; |
| 5334 | static const int kSize = kValueOffset + kPointerSize; |
| 5335 | |
| 5336 | private: |
| 5337 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSValue); |
| 5338 | }; |
| 5339 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 5340 | |
| 5341 | // Representation of message objects used for error reporting through |
| 5342 | // the API. The messages are formatted in JavaScript so this object is |
| 5343 | // a real JavaScript object. The information used for formatting the |
| 5344 | // error messages are not directly accessible from JavaScript to |
| 5345 | // prevent leaking information to user code called during error |
| 5346 | // formatting. |
| 5347 | class JSMessageObject: public JSObject { |
| 5348 | public: |
| 5349 | // [type]: the type of error message. |
| 5350 | DECL_ACCESSORS(type, String) |
| 5351 | |
| 5352 | // [arguments]: the arguments for formatting the error message. |
| 5353 | DECL_ACCESSORS(arguments, JSArray) |
| 5354 | |
| 5355 | // [script]: the script from which the error message originated. |
| 5356 | DECL_ACCESSORS(script, Object) |
| 5357 | |
| 5358 | // [stack_trace]: the stack trace for this error message. |
| 5359 | DECL_ACCESSORS(stack_trace, Object) |
| 5360 | |
| 5361 | // [stack_frames]: an array of stack frames for this error object. |
| 5362 | DECL_ACCESSORS(stack_frames, Object) |
| 5363 | |
| 5364 | // [start_position]: the start position in the script for the error message. |
| 5365 | inline int start_position(); |
| 5366 | inline void set_start_position(int value); |
| 5367 | |
| 5368 | // [end_position]: the end position in the script for the error message. |
| 5369 | inline int end_position(); |
| 5370 | inline void set_end_position(int value); |
| 5371 | |
| 5372 | // Casting. |
| 5373 | static inline JSMessageObject* cast(Object* obj); |
| 5374 | |
| 5375 | // Dispatched behavior. |
| 5376 | #ifdef OBJECT_PRINT |
| 5377 | inline void JSMessageObjectPrint() { |
| 5378 | JSMessageObjectPrint(stdout); |
| 5379 | } |
| 5380 | void JSMessageObjectPrint(FILE* out); |
| 5381 | #endif |
| 5382 | #ifdef DEBUG |
| 5383 | void JSMessageObjectVerify(); |
| 5384 | #endif |
| 5385 | |
| 5386 | // Layout description. |
| 5387 | static const int kTypeOffset = JSObject::kHeaderSize; |
| 5388 | static const int kArgumentsOffset = kTypeOffset + kPointerSize; |
| 5389 | static const int kScriptOffset = kArgumentsOffset + kPointerSize; |
| 5390 | static const int kStackTraceOffset = kScriptOffset + kPointerSize; |
| 5391 | static const int kStackFramesOffset = kStackTraceOffset + kPointerSize; |
| 5392 | static const int kStartPositionOffset = kStackFramesOffset + kPointerSize; |
| 5393 | static const int kEndPositionOffset = kStartPositionOffset + kPointerSize; |
| 5394 | static const int kSize = kEndPositionOffset + kPointerSize; |
| 5395 | |
| 5396 | typedef FixedBodyDescriptor<HeapObject::kMapOffset, |
| 5397 | kStackFramesOffset + kPointerSize, |
| 5398 | kSize> BodyDescriptor; |
| 5399 | }; |
| 5400 | |
| 5401 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5402 | // Regular expressions |
| 5403 | // The regular expression holds a single reference to a FixedArray in |
| 5404 | // the kDataOffset field. |
| 5405 | // The FixedArray contains the following data: |
| 5406 | // - tag : type of regexp implementation (not compiled yet, atom or irregexp) |
| 5407 | // - reference to the original source string |
| 5408 | // - reference to the original flag string |
| 5409 | // If it is an atom regexp |
| 5410 | // - a reference to a literal string to search for |
| 5411 | // If it is an irregexp regexp: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5412 | // - a reference to code for ASCII inputs (bytecode or compiled), or a smi |
| 5413 | // used for tracking the last usage (used for code flushing). |
| 5414 | // - a reference to code for UC16 inputs (bytecode or compiled), or a smi |
| 5415 | // used for tracking the last usage (used for code flushing).. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5416 | // - max number of registers used by irregexp implementations. |
| 5417 | // - number of capture registers (output values) of the regexp. |
| 5418 | class JSRegExp: public JSObject { |
| 5419 | public: |
| 5420 | // Meaning of Type: |
| 5421 | // NOT_COMPILED: Initial value. No data has been stored in the JSRegExp yet. |
| 5422 | // ATOM: A simple string to match against using an indexOf operation. |
| 5423 | // IRREGEXP: Compiled with Irregexp. |
| 5424 | // IRREGEXP_NATIVE: Compiled to native code with Irregexp. |
| 5425 | enum Type { NOT_COMPILED, ATOM, IRREGEXP }; |
| 5426 | enum Flag { NONE = 0, GLOBAL = 1, IGNORE_CASE = 2, MULTILINE = 4 }; |
| 5427 | |
| 5428 | class Flags { |
| 5429 | public: |
| 5430 | explicit Flags(uint32_t value) : value_(value) { } |
| 5431 | bool is_global() { return (value_ & GLOBAL) != 0; } |
| 5432 | bool is_ignore_case() { return (value_ & IGNORE_CASE) != 0; } |
| 5433 | bool is_multiline() { return (value_ & MULTILINE) != 0; } |
| 5434 | uint32_t value() { return value_; } |
| 5435 | private: |
| 5436 | uint32_t value_; |
| 5437 | }; |
| 5438 | |
| 5439 | DECL_ACCESSORS(data, Object) |
| 5440 | |
| 5441 | inline Type TypeTag(); |
| 5442 | inline int CaptureCount(); |
| 5443 | inline Flags GetFlags(); |
| 5444 | inline String* Pattern(); |
| 5445 | inline Object* DataAt(int index); |
| 5446 | // Set implementation data after the object has been prepared. |
| 5447 | inline void SetDataAt(int index, Object* value); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5448 | |
| 5449 | // Used during GC when flushing code or setting age. |
| 5450 | inline Object* DataAtUnchecked(int index); |
| 5451 | inline void SetDataAtUnchecked(int index, Object* value, Heap* heap); |
| 5452 | inline Type TypeTagUnchecked(); |
| 5453 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5454 | static int code_index(bool is_ascii) { |
| 5455 | if (is_ascii) { |
| 5456 | return kIrregexpASCIICodeIndex; |
| 5457 | } else { |
| 5458 | return kIrregexpUC16CodeIndex; |
| 5459 | } |
| 5460 | } |
| 5461 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5462 | static int saved_code_index(bool is_ascii) { |
| 5463 | if (is_ascii) { |
| 5464 | return kIrregexpASCIICodeSavedIndex; |
| 5465 | } else { |
| 5466 | return kIrregexpUC16CodeSavedIndex; |
| 5467 | } |
| 5468 | } |
| 5469 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5470 | static inline JSRegExp* cast(Object* obj); |
| 5471 | |
| 5472 | // Dispatched behavior. |
| 5473 | #ifdef DEBUG |
| 5474 | void JSRegExpVerify(); |
| 5475 | #endif |
| 5476 | |
| 5477 | static const int kDataOffset = JSObject::kHeaderSize; |
| 5478 | static const int kSize = kDataOffset + kPointerSize; |
| 5479 | |
| 5480 | // Indices in the data array. |
| 5481 | static const int kTagIndex = 0; |
| 5482 | static const int kSourceIndex = kTagIndex + 1; |
| 5483 | static const int kFlagsIndex = kSourceIndex + 1; |
| 5484 | static const int kDataIndex = kFlagsIndex + 1; |
| 5485 | // The data fields are used in different ways depending on the |
| 5486 | // value of the tag. |
| 5487 | // Atom regexps (literal strings). |
| 5488 | static const int kAtomPatternIndex = kDataIndex; |
| 5489 | |
| 5490 | static const int kAtomDataSize = kAtomPatternIndex + 1; |
| 5491 | |
| 5492 | // Irregexp compiled code or bytecode for ASCII. If compilation |
| 5493 | // fails, this fields hold an exception object that should be |
| 5494 | // thrown if the regexp is used again. |
| 5495 | static const int kIrregexpASCIICodeIndex = kDataIndex; |
| 5496 | // Irregexp compiled code or bytecode for UC16. If compilation |
| 5497 | // fails, this fields hold an exception object that should be |
| 5498 | // thrown if the regexp is used again. |
| 5499 | static const int kIrregexpUC16CodeIndex = kDataIndex + 1; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5500 | |
| 5501 | // Saved instance of Irregexp compiled code or bytecode for ASCII that |
| 5502 | // is a potential candidate for flushing. |
| 5503 | static const int kIrregexpASCIICodeSavedIndex = kDataIndex + 2; |
| 5504 | // Saved instance of Irregexp compiled code or bytecode for UC16 that is |
| 5505 | // a potential candidate for flushing. |
| 5506 | static const int kIrregexpUC16CodeSavedIndex = kDataIndex + 3; |
| 5507 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5508 | // Maximal number of registers used by either ASCII or UC16. |
| 5509 | // Only used to check that there is enough stack space |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5510 | static const int kIrregexpMaxRegisterCountIndex = kDataIndex + 4; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5511 | // Number of captures in the compiled regexp. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5512 | static const int kIrregexpCaptureCountIndex = kDataIndex + 5; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5513 | |
| 5514 | static const int kIrregexpDataSize = kIrregexpCaptureCountIndex + 1; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 5515 | |
| 5516 | // Offsets directly into the data fixed array. |
| 5517 | static const int kDataTagOffset = |
| 5518 | FixedArray::kHeaderSize + kTagIndex * kPointerSize; |
| 5519 | static const int kDataAsciiCodeOffset = |
| 5520 | FixedArray::kHeaderSize + kIrregexpASCIICodeIndex * kPointerSize; |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 5521 | static const int kDataUC16CodeOffset = |
| 5522 | FixedArray::kHeaderSize + kIrregexpUC16CodeIndex * kPointerSize; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 5523 | static const int kIrregexpCaptureCountOffset = |
| 5524 | FixedArray::kHeaderSize + kIrregexpCaptureCountIndex * kPointerSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5525 | |
| 5526 | // In-object fields. |
| 5527 | static const int kSourceFieldIndex = 0; |
| 5528 | static const int kGlobalFieldIndex = 1; |
| 5529 | static const int kIgnoreCaseFieldIndex = 2; |
| 5530 | static const int kMultilineFieldIndex = 3; |
| 5531 | static const int kLastIndexFieldIndex = 4; |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 5532 | static const int kInObjectFieldCount = 5; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5533 | |
| 5534 | // The uninitialized value for a regexp code object. |
| 5535 | static const int kUninitializedValue = -1; |
| 5536 | |
| 5537 | // The compilation error value for the regexp code object. The real error |
| 5538 | // object is in the saved code field. |
| 5539 | static const int kCompilationErrorValue = -2; |
| 5540 | |
| 5541 | // When we store the sweep generation at which we moved the code from the |
| 5542 | // code index to the saved code index we mask it of to be in the [0:255] |
| 5543 | // range. |
| 5544 | static const int kCodeAgeMask = 0xff; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5545 | }; |
| 5546 | |
| 5547 | |
| 5548 | class CompilationCacheShape { |
| 5549 | public: |
| 5550 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
| 5551 | return key->IsMatch(value); |
| 5552 | } |
| 5553 | |
| 5554 | static inline uint32_t Hash(HashTableKey* key) { |
| 5555 | return key->Hash(); |
| 5556 | } |
| 5557 | |
| 5558 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
| 5559 | return key->HashForObject(object); |
| 5560 | } |
| 5561 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 5562 | MUST_USE_RESULT static MaybeObject* AsObject(HashTableKey* key) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5563 | return key->AsObject(); |
| 5564 | } |
| 5565 | |
| 5566 | static const int kPrefixSize = 0; |
| 5567 | static const int kEntrySize = 2; |
| 5568 | }; |
| 5569 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 5570 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5571 | class CompilationCacheTable: public HashTable<CompilationCacheShape, |
| 5572 | HashTableKey*> { |
| 5573 | public: |
| 5574 | // Find cached value for a string key, otherwise return null. |
| 5575 | Object* Lookup(String* src); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 5576 | Object* LookupEval(String* src, Context* context, StrictModeFlag strict_mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5577 | Object* LookupRegExp(String* source, JSRegExp::Flags flags); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 5578 | MaybeObject* Put(String* src, Object* value); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 5579 | MaybeObject* PutEval(String* src, |
| 5580 | Context* context, |
| 5581 | SharedFunctionInfo* value); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 5582 | MaybeObject* PutRegExp(String* src, JSRegExp::Flags flags, FixedArray* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5583 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5584 | // Remove given value from cache. |
| 5585 | void Remove(Object* value); |
| 5586 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5587 | static inline CompilationCacheTable* cast(Object* obj); |
| 5588 | |
| 5589 | private: |
| 5590 | DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheTable); |
| 5591 | }; |
| 5592 | |
| 5593 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5594 | class CodeCache: public Struct { |
| 5595 | public: |
| 5596 | DECL_ACCESSORS(default_cache, FixedArray) |
| 5597 | DECL_ACCESSORS(normal_type_cache, Object) |
| 5598 | |
| 5599 | // Add the code object to the cache. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 5600 | MUST_USE_RESULT MaybeObject* Update(String* name, Code* code); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5601 | |
| 5602 | // Lookup code object in the cache. Returns code object if found and undefined |
| 5603 | // if not. |
| 5604 | Object* Lookup(String* name, Code::Flags flags); |
| 5605 | |
| 5606 | // Get the internal index of a code object in the cache. Returns -1 if the |
| 5607 | // code object is not in that cache. This index can be used to later call |
| 5608 | // RemoveByIndex. The cache cannot be modified between a call to GetIndex and |
| 5609 | // RemoveByIndex. |
| 5610 | int GetIndex(Object* name, Code* code); |
| 5611 | |
| 5612 | // Remove an object from the cache with the provided internal index. |
| 5613 | void RemoveByIndex(Object* name, Code* code, int index); |
| 5614 | |
| 5615 | static inline CodeCache* cast(Object* obj); |
| 5616 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5617 | #ifdef OBJECT_PRINT |
| 5618 | inline void CodeCachePrint() { |
| 5619 | CodeCachePrint(stdout); |
| 5620 | } |
| 5621 | void CodeCachePrint(FILE* out); |
| 5622 | #endif |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5623 | #ifdef DEBUG |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5624 | void CodeCacheVerify(); |
| 5625 | #endif |
| 5626 | |
| 5627 | static const int kDefaultCacheOffset = HeapObject::kHeaderSize; |
| 5628 | static const int kNormalTypeCacheOffset = |
| 5629 | kDefaultCacheOffset + kPointerSize; |
| 5630 | static const int kSize = kNormalTypeCacheOffset + kPointerSize; |
| 5631 | |
| 5632 | private: |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 5633 | MUST_USE_RESULT MaybeObject* UpdateDefaultCache(String* name, Code* code); |
| 5634 | MUST_USE_RESULT MaybeObject* UpdateNormalTypeCache(String* name, Code* code); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5635 | Object* LookupDefaultCache(String* name, Code::Flags flags); |
| 5636 | Object* LookupNormalTypeCache(String* name, Code::Flags flags); |
| 5637 | |
| 5638 | // Code cache layout of the default cache. Elements are alternating name and |
| 5639 | // code objects for non normal load/store/call IC's. |
| 5640 | static const int kCodeCacheEntrySize = 2; |
| 5641 | static const int kCodeCacheEntryNameOffset = 0; |
| 5642 | static const int kCodeCacheEntryCodeOffset = 1; |
| 5643 | |
| 5644 | DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCache); |
| 5645 | }; |
| 5646 | |
| 5647 | |
| 5648 | class CodeCacheHashTableShape { |
| 5649 | public: |
| 5650 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
| 5651 | return key->IsMatch(value); |
| 5652 | } |
| 5653 | |
| 5654 | static inline uint32_t Hash(HashTableKey* key) { |
| 5655 | return key->Hash(); |
| 5656 | } |
| 5657 | |
| 5658 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
| 5659 | return key->HashForObject(object); |
| 5660 | } |
| 5661 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 5662 | MUST_USE_RESULT static MaybeObject* AsObject(HashTableKey* key) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5663 | return key->AsObject(); |
| 5664 | } |
| 5665 | |
| 5666 | static const int kPrefixSize = 0; |
| 5667 | static const int kEntrySize = 2; |
| 5668 | }; |
| 5669 | |
| 5670 | |
| 5671 | class CodeCacheHashTable: public HashTable<CodeCacheHashTableShape, |
| 5672 | HashTableKey*> { |
| 5673 | public: |
| 5674 | Object* Lookup(String* name, Code::Flags flags); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 5675 | MUST_USE_RESULT MaybeObject* Put(String* name, Code* code); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5676 | |
| 5677 | int GetIndex(String* name, Code::Flags flags); |
| 5678 | void RemoveByIndex(int index); |
| 5679 | |
| 5680 | static inline CodeCacheHashTable* cast(Object* obj); |
| 5681 | |
| 5682 | // Initial size of the fixed array backing the hash table. |
| 5683 | static const int kInitialSize = 64; |
| 5684 | |
| 5685 | private: |
| 5686 | DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCacheHashTable); |
| 5687 | }; |
| 5688 | |
| 5689 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 5690 | class PolymorphicCodeCache: public Struct { |
| 5691 | public: |
| 5692 | DECL_ACCESSORS(cache, Object) |
| 5693 | |
| 5694 | MUST_USE_RESULT MaybeObject* Update(MapList* maps, |
| 5695 | Code::Flags flags, |
| 5696 | Code* code); |
| 5697 | Object* Lookup(MapList* maps, Code::Flags flags); |
| 5698 | |
| 5699 | static inline PolymorphicCodeCache* cast(Object* obj); |
| 5700 | |
| 5701 | #ifdef OBJECT_PRINT |
| 5702 | inline void PolymorphicCodeCachePrint() { |
| 5703 | PolymorphicCodeCachePrint(stdout); |
| 5704 | } |
| 5705 | void PolymorphicCodeCachePrint(FILE* out); |
| 5706 | #endif |
| 5707 | #ifdef DEBUG |
| 5708 | void PolymorphicCodeCacheVerify(); |
| 5709 | #endif |
| 5710 | |
| 5711 | static const int kCacheOffset = HeapObject::kHeaderSize; |
| 5712 | static const int kSize = kCacheOffset + kPointerSize; |
| 5713 | |
| 5714 | private: |
| 5715 | DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCache); |
| 5716 | }; |
| 5717 | |
| 5718 | |
| 5719 | class PolymorphicCodeCacheHashTable |
| 5720 | : public HashTable<CodeCacheHashTableShape, HashTableKey*> { |
| 5721 | public: |
| 5722 | Object* Lookup(MapList* maps, int code_kind); |
| 5723 | MUST_USE_RESULT MaybeObject* Put(MapList* maps, int code_kind, Code* code); |
| 5724 | |
| 5725 | static inline PolymorphicCodeCacheHashTable* cast(Object* obj); |
| 5726 | |
| 5727 | static const int kInitialSize = 64; |
| 5728 | private: |
| 5729 | DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCacheHashTable); |
| 5730 | }; |
| 5731 | |
| 5732 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5733 | enum AllowNullsFlag {ALLOW_NULLS, DISALLOW_NULLS}; |
| 5734 | enum RobustnessFlag {ROBUST_STRING_TRAVERSAL, FAST_STRING_TRAVERSAL}; |
| 5735 | |
| 5736 | |
| 5737 | class StringHasher { |
| 5738 | public: |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 5739 | explicit inline StringHasher(int length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5740 | |
| 5741 | // Returns true if the hash of this string can be computed without |
| 5742 | // looking at the contents. |
| 5743 | inline bool has_trivial_hash(); |
| 5744 | |
| 5745 | // Add a character to the hash and update the array index calculation. |
| 5746 | inline void AddCharacter(uc32 c); |
| 5747 | |
| 5748 | // Adds a character to the hash but does not update the array index |
| 5749 | // calculation. This can only be called when it has been verified |
| 5750 | // that the input is not an array index. |
| 5751 | inline void AddCharacterNoIndex(uc32 c); |
| 5752 | |
| 5753 | // Returns the value to store in the hash field of a string with |
| 5754 | // the given length and contents. |
| 5755 | uint32_t GetHashField(); |
| 5756 | |
| 5757 | // Returns true if the characters seen so far make up a legal array |
| 5758 | // index. |
| 5759 | bool is_array_index() { return is_array_index_; } |
| 5760 | |
| 5761 | bool is_valid() { return is_valid_; } |
| 5762 | |
| 5763 | void invalidate() { is_valid_ = false; } |
| 5764 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5765 | // Calculated hash value for a string consisting of 1 to |
| 5766 | // String::kMaxArrayIndexSize digits with no leading zeros (except "0"). |
| 5767 | // value is represented decimal value. |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 5768 | static uint32_t MakeArrayIndexHash(uint32_t value, int length); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5769 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5770 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5771 | uint32_t array_index() { |
| 5772 | ASSERT(is_array_index()); |
| 5773 | return array_index_; |
| 5774 | } |
| 5775 | |
| 5776 | inline uint32_t GetHash(); |
| 5777 | |
| 5778 | int length_; |
| 5779 | uint32_t raw_running_hash_; |
| 5780 | uint32_t array_index_; |
| 5781 | bool is_array_index_; |
| 5782 | bool is_first_char_; |
| 5783 | bool is_valid_; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5784 | friend class TwoCharHashTableKey; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5785 | }; |
| 5786 | |
| 5787 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 5788 | // Calculates string hash. |
| 5789 | template <typename schar> |
| 5790 | inline uint32_t HashSequentialString(const schar* chars, int length); |
| 5791 | |
| 5792 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5793 | // The characteristics of a string are stored in its map. Retrieving these |
| 5794 | // few bits of information is moderately expensive, involving two memory |
| 5795 | // loads where the second is dependent on the first. To improve efficiency |
| 5796 | // the shape of the string is given its own class so that it can be retrieved |
| 5797 | // once and used for several string operations. A StringShape is small enough |
| 5798 | // to be passed by value and is immutable, but be aware that flattening a |
| 5799 | // string can potentially alter its shape. Also be aware that a GC caused by |
| 5800 | // something else can alter the shape of a string due to ConsString |
| 5801 | // shortcutting. Keeping these restrictions in mind has proven to be error- |
| 5802 | // prone and so we no longer put StringShapes in variables unless there is a |
| 5803 | // concrete performance benefit at that particular point in the code. |
| 5804 | class StringShape BASE_EMBEDDED { |
| 5805 | public: |
| 5806 | inline explicit StringShape(String* s); |
| 5807 | inline explicit StringShape(Map* s); |
| 5808 | inline explicit StringShape(InstanceType t); |
| 5809 | inline bool IsSequential(); |
| 5810 | inline bool IsExternal(); |
| 5811 | inline bool IsCons(); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 5812 | inline bool IsSliced(); |
| 5813 | inline bool IsIndirect(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5814 | inline bool IsExternalAscii(); |
| 5815 | inline bool IsExternalTwoByte(); |
| 5816 | inline bool IsSequentialAscii(); |
| 5817 | inline bool IsSequentialTwoByte(); |
| 5818 | inline bool IsSymbol(); |
| 5819 | inline StringRepresentationTag representation_tag(); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 5820 | inline uint32_t encoding_tag(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5821 | inline uint32_t full_representation_tag(); |
| 5822 | inline uint32_t size_tag(); |
| 5823 | #ifdef DEBUG |
| 5824 | inline uint32_t type() { return type_; } |
| 5825 | inline void invalidate() { valid_ = false; } |
| 5826 | inline bool valid() { return valid_; } |
| 5827 | #else |
| 5828 | inline void invalidate() { } |
| 5829 | #endif |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 5830 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5831 | private: |
| 5832 | uint32_t type_; |
| 5833 | #ifdef DEBUG |
| 5834 | inline void set_valid() { valid_ = true; } |
| 5835 | bool valid_; |
| 5836 | #else |
| 5837 | inline void set_valid() { } |
| 5838 | #endif |
| 5839 | }; |
| 5840 | |
| 5841 | |
| 5842 | // The String abstract class captures JavaScript string values: |
| 5843 | // |
| 5844 | // Ecma-262: |
| 5845 | // 4.3.16 String Value |
| 5846 | // A string value is a member of the type String and is a finite |
| 5847 | // ordered sequence of zero or more 16-bit unsigned integer values. |
| 5848 | // |
| 5849 | // All string values have a length field. |
| 5850 | class String: public HeapObject { |
| 5851 | public: |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 5852 | // Representation of the flat content of a String. |
| 5853 | // A non-flat string doesn't have flat content. |
| 5854 | // A flat string has content that's encoded as a sequence of either |
| 5855 | // ASCII chars or two-byte UC16. |
| 5856 | // Returned by String::GetFlatContent(). |
| 5857 | class FlatContent { |
| 5858 | public: |
| 5859 | // Returns true if the string is flat and this structure contains content. |
| 5860 | bool IsFlat() { return state_ != NON_FLAT; } |
| 5861 | // Returns true if the structure contains ASCII content. |
| 5862 | bool IsAscii() { return state_ == ASCII; } |
| 5863 | // Returns true if the structure contains two-byte content. |
| 5864 | bool IsTwoByte() { return state_ == TWO_BYTE; } |
| 5865 | |
| 5866 | // Return the ASCII content of the string. Only use if IsAscii() returns |
| 5867 | // true. |
| 5868 | Vector<const char> ToAsciiVector() { |
| 5869 | ASSERT_EQ(ASCII, state_); |
| 5870 | return Vector<const char>::cast(buffer_); |
| 5871 | } |
| 5872 | // Return the two-byte content of the string. Only use if IsTwoByte() |
| 5873 | // returns true. |
| 5874 | Vector<const uc16> ToUC16Vector() { |
| 5875 | ASSERT_EQ(TWO_BYTE, state_); |
| 5876 | return Vector<const uc16>::cast(buffer_); |
| 5877 | } |
| 5878 | |
| 5879 | private: |
| 5880 | enum State { NON_FLAT, ASCII, TWO_BYTE }; |
| 5881 | |
| 5882 | // Constructors only used by String::GetFlatContent(). |
| 5883 | explicit FlatContent(Vector<const char> chars) |
| 5884 | : buffer_(Vector<const byte>::cast(chars)), |
| 5885 | state_(ASCII) { } |
| 5886 | explicit FlatContent(Vector<const uc16> chars) |
| 5887 | : buffer_(Vector<const byte>::cast(chars)), |
| 5888 | state_(TWO_BYTE) { } |
| 5889 | FlatContent() : buffer_(), state_(NON_FLAT) { } |
| 5890 | |
| 5891 | Vector<const byte> buffer_; |
| 5892 | State state_; |
| 5893 | |
| 5894 | friend class String; |
| 5895 | }; |
| 5896 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5897 | // Get and set the length of the string. |
| 5898 | inline int length(); |
| 5899 | inline void set_length(int value); |
| 5900 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5901 | // Get and set the hash field of the string. |
| 5902 | inline uint32_t hash_field(); |
| 5903 | inline void set_hash_field(uint32_t value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5904 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 5905 | // Returns whether this string has only ASCII chars, i.e. all of them can |
| 5906 | // be ASCII encoded. This might be the case even if the string is |
| 5907 | // two-byte. Such strings may appear when the embedder prefers |
| 5908 | // two-byte external representations even for ASCII data. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5909 | inline bool IsAsciiRepresentation(); |
| 5910 | inline bool IsTwoByteRepresentation(); |
| 5911 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 5912 | // Cons and slices have an encoding flag that may not represent the actual |
| 5913 | // encoding of the underlying string. This is taken into account here. |
| 5914 | // Requires: this->IsFlat() |
| 5915 | inline bool IsAsciiRepresentationUnderneath(); |
| 5916 | inline bool IsTwoByteRepresentationUnderneath(); |
| 5917 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 5918 | // NOTE: this should be considered only a hint. False negatives are |
| 5919 | // possible. |
| 5920 | inline bool HasOnlyAsciiChars(); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5921 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5922 | // Get and set individual two byte chars in the string. |
| 5923 | inline void Set(int index, uint16_t value); |
| 5924 | // Get individual two byte char in the string. Repeated calls |
| 5925 | // to this method are not efficient unless the string is flat. |
| 5926 | inline uint16_t Get(int index); |
| 5927 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 5928 | // Try to flatten the string. Checks first inline to see if it is |
| 5929 | // necessary. Does nothing if the string is not a cons string. |
| 5930 | // Flattening allocates a sequential string with the same data as |
| 5931 | // the given string and mutates the cons string to a degenerate |
| 5932 | // form, where the first component is the new sequential string and |
| 5933 | // the second component is the empty string. If allocation fails, |
| 5934 | // this function returns a failure. If flattening succeeds, this |
| 5935 | // function returns the sequential string that is now the first |
| 5936 | // component of the cons string. |
| 5937 | // |
| 5938 | // Degenerate cons strings are handled specially by the garbage |
| 5939 | // collector (see IsShortcutCandidate). |
| 5940 | // |
| 5941 | // Use FlattenString from Handles.cc to flatten even in case an |
| 5942 | // allocation failure happens. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 5943 | inline MaybeObject* TryFlatten(PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5944 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 5945 | // Convenience function. Has exactly the same behavior as |
| 5946 | // TryFlatten(), except in the case of failure returns the original |
| 5947 | // string. |
| 5948 | inline String* TryFlattenGetString(PretenureFlag pretenure = NOT_TENURED); |
| 5949 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 5950 | // Tries to return the content of a flat string as a structure holding either |
| 5951 | // a flat vector of char or of uc16. |
| 5952 | // If the string isn't flat, and therefore doesn't have flat content, the |
| 5953 | // returned structure will report so, and can't provide a vector of either |
| 5954 | // kind. |
| 5955 | FlatContent GetFlatContent(); |
| 5956 | |
| 5957 | // Returns the parent of a sliced string or first part of a flat cons string. |
| 5958 | // Requires: StringShape(this).IsIndirect() && this->IsFlat() |
| 5959 | inline String* GetUnderlying(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5960 | |
| 5961 | // Mark the string as an undetectable object. It only applies to |
| 5962 | // ascii and two byte string types. |
| 5963 | bool MarkAsUndetectable(); |
| 5964 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5965 | // Return a substring. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 5966 | MUST_USE_RESULT MaybeObject* SubString(int from, |
| 5967 | int to, |
| 5968 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5969 | |
| 5970 | // String equality operations. |
| 5971 | inline bool Equals(String* other); |
| 5972 | bool IsEqualTo(Vector<const char> str); |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 5973 | bool IsAsciiEqualTo(Vector<const char> str); |
| 5974 | bool IsTwoByteEqualTo(Vector<const uc16> str); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5975 | |
| 5976 | // Return a UTF8 representation of the string. The string is null |
| 5977 | // terminated but may optionally contain nulls. Length is returned |
| 5978 | // in length_output if length_output is not a null pointer The string |
| 5979 | // should be nearly flat, otherwise the performance of this method may |
| 5980 | // be very slow (quadratic in the length). Setting robustness_flag to |
| 5981 | // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it |
| 5982 | // handles unexpected data without causing assert failures and it does not |
| 5983 | // do any heap allocations. This is useful when printing stack traces. |
| 5984 | SmartPointer<char> ToCString(AllowNullsFlag allow_nulls, |
| 5985 | RobustnessFlag robustness_flag, |
| 5986 | int offset, |
| 5987 | int length, |
| 5988 | int* length_output = 0); |
| 5989 | SmartPointer<char> ToCString( |
| 5990 | AllowNullsFlag allow_nulls = DISALLOW_NULLS, |
| 5991 | RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL, |
| 5992 | int* length_output = 0); |
| 5993 | |
| 5994 | int Utf8Length(); |
| 5995 | |
| 5996 | // Return a 16 bit Unicode representation of the string. |
| 5997 | // The string should be nearly flat, otherwise the performance of |
| 5998 | // of this method may be very bad. Setting robustness_flag to |
| 5999 | // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it |
| 6000 | // handles unexpected data without causing assert failures and it does not |
| 6001 | // do any heap allocations. This is useful when printing stack traces. |
| 6002 | SmartPointer<uc16> ToWideCString( |
| 6003 | RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL); |
| 6004 | |
| 6005 | // Tells whether the hash code has been computed. |
| 6006 | inline bool HasHashCode(); |
| 6007 | |
| 6008 | // Returns a hash value used for the property table |
| 6009 | inline uint32_t Hash(); |
| 6010 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6011 | static uint32_t ComputeHashField(unibrow::CharacterStream* buffer, |
| 6012 | int length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6013 | |
| 6014 | static bool ComputeArrayIndex(unibrow::CharacterStream* buffer, |
| 6015 | uint32_t* index, |
| 6016 | int length); |
| 6017 | |
| 6018 | // Externalization. |
| 6019 | bool MakeExternal(v8::String::ExternalStringResource* resource); |
| 6020 | bool MakeExternal(v8::String::ExternalAsciiStringResource* resource); |
| 6021 | |
| 6022 | // Conversion. |
| 6023 | inline bool AsArrayIndex(uint32_t* index); |
| 6024 | |
| 6025 | // Casting. |
| 6026 | static inline String* cast(Object* obj); |
| 6027 | |
| 6028 | void PrintOn(FILE* out); |
| 6029 | |
| 6030 | // For use during stack traces. Performs rudimentary sanity check. |
| 6031 | bool LooksValid(); |
| 6032 | |
| 6033 | // Dispatched behavior. |
| 6034 | void StringShortPrint(StringStream* accumulator); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6035 | #ifdef OBJECT_PRINT |
| 6036 | inline void StringPrint() { |
| 6037 | StringPrint(stdout); |
| 6038 | } |
| 6039 | void StringPrint(FILE* out); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 6040 | |
| 6041 | char* ToAsciiArray(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6042 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6043 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6044 | void StringVerify(); |
| 6045 | #endif |
| 6046 | inline bool IsFlat(); |
| 6047 | |
| 6048 | // Layout description. |
| 6049 | static const int kLengthOffset = HeapObject::kHeaderSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 6050 | static const int kHashFieldOffset = kLengthOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 6051 | static const int kSize = kHashFieldOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6052 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6053 | // Maximum number of characters to consider when trying to convert a string |
| 6054 | // value into an array index. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6055 | static const int kMaxArrayIndexSize = 10; |
| 6056 | |
| 6057 | // Max ascii char code. |
| 6058 | static const int kMaxAsciiCharCode = unibrow::Utf8::kMaxOneByteChar; |
| 6059 | static const unsigned kMaxAsciiCharCodeU = unibrow::Utf8::kMaxOneByteChar; |
| 6060 | static const int kMaxUC16CharCode = 0xffff; |
| 6061 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6062 | // Minimum length for a cons string. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6063 | static const int kMinNonFlatLength = 13; |
| 6064 | |
| 6065 | // Mask constant for checking if a string has a computed hash code |
| 6066 | // and if it is an array index. The least significant bit indicates |
| 6067 | // whether a hash code has been computed. If the hash code has been |
| 6068 | // computed the 2nd bit tells whether the string can be used as an |
| 6069 | // array index. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 6070 | static const int kHashNotComputedMask = 1; |
| 6071 | static const int kIsNotArrayIndexMask = 1 << 1; |
| 6072 | static const int kNofHashBitFields = 2; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6073 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6074 | // Shift constant retrieving hash code from hash field. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 6075 | static const int kHashShift = kNofHashBitFields; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6076 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6077 | // Array index strings this short can keep their index in the hash |
| 6078 | // field. |
| 6079 | static const int kMaxCachedArrayIndexLength = 7; |
| 6080 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6081 | // For strings which are array indexes the hash value has the string length |
| 6082 | // mixed into the hash, mainly to avoid a hash value of zero which would be |
| 6083 | // 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] | 6084 | static const int kArrayIndexValueBits = 24; |
| 6085 | static const int kArrayIndexLengthBits = |
| 6086 | kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields; |
| 6087 | |
| 6088 | STATIC_CHECK((kArrayIndexLengthBits > 0)); |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 6089 | STATIC_CHECK(kMaxArrayIndexSize < (1 << kArrayIndexLengthBits)); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 6090 | |
| 6091 | static const int kArrayIndexHashLengthShift = |
| 6092 | kArrayIndexValueBits + kNofHashBitFields; |
| 6093 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6094 | static const int kArrayIndexHashMask = (1 << kArrayIndexHashLengthShift) - 1; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 6095 | |
| 6096 | static const int kArrayIndexValueMask = |
| 6097 | ((1 << kArrayIndexValueBits) - 1) << kHashShift; |
| 6098 | |
| 6099 | // Check that kMaxCachedArrayIndexLength + 1 is a power of two so we |
| 6100 | // could use a mask to test if the length of string is less than or equal to |
| 6101 | // kMaxCachedArrayIndexLength. |
| 6102 | STATIC_CHECK(IS_POWER_OF_TWO(kMaxCachedArrayIndexLength + 1)); |
| 6103 | |
| 6104 | static const int kContainsCachedArrayIndexMask = |
| 6105 | (~kMaxCachedArrayIndexLength << kArrayIndexHashLengthShift) | |
| 6106 | kIsNotArrayIndexMask; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6107 | |
| 6108 | // Value of empty hash field indicating that the hash is not computed. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 6109 | static const int kEmptyHashField = |
| 6110 | kIsNotArrayIndexMask | kHashNotComputedMask; |
| 6111 | |
| 6112 | // Value of hash field containing computed hash equal to zero. |
| 6113 | static const int kZeroHash = kIsNotArrayIndexMask; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6114 | |
| 6115 | // Maximal string length. |
| 6116 | static const int kMaxLength = (1 << (32 - 2)) - 1; |
| 6117 | |
| 6118 | // Max length for computing hash. For strings longer than this limit the |
| 6119 | // string length is used as the hash value. |
| 6120 | static const int kMaxHashCalcLength = 16383; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6121 | |
| 6122 | // Limit for truncation in short printing. |
| 6123 | static const int kMaxShortPrintLength = 1024; |
| 6124 | |
| 6125 | // Support for regular expressions. |
| 6126 | const uc16* GetTwoByteData(); |
| 6127 | const uc16* GetTwoByteData(unsigned start); |
| 6128 | |
| 6129 | // Support for StringInputBuffer |
| 6130 | static const unibrow::byte* ReadBlock(String* input, |
| 6131 | unibrow::byte* util_buffer, |
| 6132 | unsigned capacity, |
| 6133 | unsigned* remaining, |
| 6134 | unsigned* offset); |
| 6135 | static const unibrow::byte* ReadBlock(String** input, |
| 6136 | unibrow::byte* util_buffer, |
| 6137 | unsigned capacity, |
| 6138 | unsigned* remaining, |
| 6139 | unsigned* offset); |
| 6140 | |
| 6141 | // Helper function for flattening strings. |
| 6142 | template <typename sinkchar> |
| 6143 | static void WriteToFlat(String* source, |
| 6144 | sinkchar* sink, |
| 6145 | int from, |
| 6146 | int to); |
| 6147 | |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 6148 | static inline bool IsAscii(const char* chars, int length) { |
| 6149 | const char* limit = chars + length; |
| 6150 | #ifdef V8_HOST_CAN_READ_UNALIGNED |
| 6151 | ASSERT(kMaxAsciiCharCode == 0x7F); |
| 6152 | const uintptr_t non_ascii_mask = kUintptrAllBitsSet / 0xFF * 0x80; |
| 6153 | while (chars <= limit - sizeof(uintptr_t)) { |
| 6154 | if (*reinterpret_cast<const uintptr_t*>(chars) & non_ascii_mask) { |
| 6155 | return false; |
| 6156 | } |
| 6157 | chars += sizeof(uintptr_t); |
| 6158 | } |
| 6159 | #endif |
| 6160 | while (chars < limit) { |
| 6161 | if (static_cast<uint8_t>(*chars) > kMaxAsciiCharCodeU) return false; |
| 6162 | ++chars; |
| 6163 | } |
| 6164 | return true; |
| 6165 | } |
| 6166 | |
| 6167 | static inline bool IsAscii(const uc16* chars, int length) { |
| 6168 | const uc16* limit = chars + length; |
| 6169 | while (chars < limit) { |
| 6170 | if (*chars > kMaxAsciiCharCodeU) return false; |
| 6171 | ++chars; |
| 6172 | } |
| 6173 | return true; |
| 6174 | } |
| 6175 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6176 | protected: |
| 6177 | class ReadBlockBuffer { |
| 6178 | public: |
| 6179 | ReadBlockBuffer(unibrow::byte* util_buffer_, |
| 6180 | unsigned cursor_, |
| 6181 | unsigned capacity_, |
| 6182 | unsigned remaining_) : |
| 6183 | util_buffer(util_buffer_), |
| 6184 | cursor(cursor_), |
| 6185 | capacity(capacity_), |
| 6186 | remaining(remaining_) { |
| 6187 | } |
| 6188 | unibrow::byte* util_buffer; |
| 6189 | unsigned cursor; |
| 6190 | unsigned capacity; |
| 6191 | unsigned remaining; |
| 6192 | }; |
| 6193 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6194 | static inline const unibrow::byte* ReadBlock(String* input, |
| 6195 | ReadBlockBuffer* buffer, |
| 6196 | unsigned* offset, |
| 6197 | unsigned max_chars); |
| 6198 | static void ReadBlockIntoBuffer(String* input, |
| 6199 | ReadBlockBuffer* buffer, |
| 6200 | unsigned* offset_ptr, |
| 6201 | unsigned max_chars); |
| 6202 | |
| 6203 | private: |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 6204 | // Try to flatten the top level ConsString that is hiding behind this |
| 6205 | // string. This is a no-op unless the string is a ConsString. Flatten |
| 6206 | // mutates the ConsString and might return a failure. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 6207 | MUST_USE_RESULT MaybeObject* SlowTryFlatten(PretenureFlag pretenure); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 6208 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 6209 | static inline bool IsHashFieldComputed(uint32_t field); |
| 6210 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6211 | // Slow case of String::Equals. This implementation works on any strings |
| 6212 | // but it is most efficient on strings that are almost flat. |
| 6213 | bool SlowEquals(String* other); |
| 6214 | |
| 6215 | // Slow case of AsArrayIndex. |
| 6216 | bool SlowAsArrayIndex(uint32_t* index); |
| 6217 | |
| 6218 | // Compute and set the hash code. |
| 6219 | uint32_t ComputeAndSetHash(); |
| 6220 | |
| 6221 | DISALLOW_IMPLICIT_CONSTRUCTORS(String); |
| 6222 | }; |
| 6223 | |
| 6224 | |
| 6225 | // The SeqString abstract class captures sequential string values. |
| 6226 | class SeqString: public String { |
| 6227 | public: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6228 | // Casting. |
| 6229 | static inline SeqString* cast(Object* obj); |
| 6230 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6231 | private: |
| 6232 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqString); |
| 6233 | }; |
| 6234 | |
| 6235 | |
| 6236 | // The AsciiString class captures sequential ascii string objects. |
| 6237 | // Each character in the AsciiString is an ascii character. |
| 6238 | class SeqAsciiString: public SeqString { |
| 6239 | public: |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 6240 | static const bool kHasAsciiEncoding = true; |
| 6241 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6242 | // Dispatched behavior. |
| 6243 | inline uint16_t SeqAsciiStringGet(int index); |
| 6244 | inline void SeqAsciiStringSet(int index, uint16_t value); |
| 6245 | |
| 6246 | // Get the address of the characters in this string. |
| 6247 | inline Address GetCharsAddress(); |
| 6248 | |
| 6249 | inline char* GetChars(); |
| 6250 | |
| 6251 | // Casting |
| 6252 | static inline SeqAsciiString* cast(Object* obj); |
| 6253 | |
| 6254 | // Garbage collection support. This method is called by the |
| 6255 | // garbage collector to compute the actual size of an AsciiString |
| 6256 | // instance. |
| 6257 | inline int SeqAsciiStringSize(InstanceType instance_type); |
| 6258 | |
| 6259 | // Computes the size for an AsciiString instance of a given length. |
| 6260 | static int SizeFor(int length) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 6261 | return OBJECT_POINTER_ALIGN(kHeaderSize + length * kCharSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6262 | } |
| 6263 | |
| 6264 | // Layout description. |
| 6265 | static const int kHeaderSize = String::kSize; |
| 6266 | static const int kAlignedSize = POINTER_SIZE_ALIGN(kHeaderSize); |
| 6267 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 6268 | // Maximal memory usage for a single sequential ASCII string. |
| 6269 | static const int kMaxSize = 512 * MB; |
| 6270 | // Maximal length of a single sequential ASCII string. |
| 6271 | // Q.v. String::kMaxLength which is the maximal size of concatenated strings. |
| 6272 | static const int kMaxLength = (kMaxSize - kHeaderSize); |
| 6273 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6274 | // Support for StringInputBuffer. |
| 6275 | inline void SeqAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 6276 | unsigned* offset, |
| 6277 | unsigned chars); |
| 6278 | inline const unibrow::byte* SeqAsciiStringReadBlock(unsigned* remaining, |
| 6279 | unsigned* offset, |
| 6280 | unsigned chars); |
| 6281 | |
| 6282 | private: |
| 6283 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqAsciiString); |
| 6284 | }; |
| 6285 | |
| 6286 | |
| 6287 | // The TwoByteString class captures sequential unicode string objects. |
| 6288 | // Each character in the TwoByteString is a two-byte uint16_t. |
| 6289 | class SeqTwoByteString: public SeqString { |
| 6290 | public: |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 6291 | static const bool kHasAsciiEncoding = false; |
| 6292 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6293 | // Dispatched behavior. |
| 6294 | inline uint16_t SeqTwoByteStringGet(int index); |
| 6295 | inline void SeqTwoByteStringSet(int index, uint16_t value); |
| 6296 | |
| 6297 | // Get the address of the characters in this string. |
| 6298 | inline Address GetCharsAddress(); |
| 6299 | |
| 6300 | inline uc16* GetChars(); |
| 6301 | |
| 6302 | // For regexp code. |
| 6303 | const uint16_t* SeqTwoByteStringGetData(unsigned start); |
| 6304 | |
| 6305 | // Casting |
| 6306 | static inline SeqTwoByteString* cast(Object* obj); |
| 6307 | |
| 6308 | // Garbage collection support. This method is called by the |
| 6309 | // garbage collector to compute the actual size of a TwoByteString |
| 6310 | // instance. |
| 6311 | inline int SeqTwoByteStringSize(InstanceType instance_type); |
| 6312 | |
| 6313 | // Computes the size for a TwoByteString instance of a given length. |
| 6314 | static int SizeFor(int length) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 6315 | return OBJECT_POINTER_ALIGN(kHeaderSize + length * kShortSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6316 | } |
| 6317 | |
| 6318 | // Layout description. |
| 6319 | static const int kHeaderSize = String::kSize; |
| 6320 | static const int kAlignedSize = POINTER_SIZE_ALIGN(kHeaderSize); |
| 6321 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 6322 | // Maximal memory usage for a single sequential two-byte string. |
| 6323 | static const int kMaxSize = 512 * MB; |
| 6324 | // Maximal length of a single sequential two-byte string. |
| 6325 | // Q.v. String::kMaxLength which is the maximal size of concatenated strings. |
| 6326 | static const int kMaxLength = (kMaxSize - kHeaderSize) / sizeof(uint16_t); |
| 6327 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6328 | // Support for StringInputBuffer. |
| 6329 | inline void SeqTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 6330 | unsigned* offset_ptr, |
| 6331 | unsigned chars); |
| 6332 | |
| 6333 | private: |
| 6334 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqTwoByteString); |
| 6335 | }; |
| 6336 | |
| 6337 | |
| 6338 | // The ConsString class describes string values built by using the |
| 6339 | // addition operator on strings. A ConsString is a pair where the |
| 6340 | // first and second components are pointers to other string values. |
| 6341 | // One or both components of a ConsString can be pointers to other |
| 6342 | // ConsStrings, creating a binary tree of ConsStrings where the leaves |
| 6343 | // are non-ConsString string values. The string value represented by |
| 6344 | // a ConsString can be obtained by concatenating the leaf string |
| 6345 | // values in a left-to-right depth-first traversal of the tree. |
| 6346 | class ConsString: public String { |
| 6347 | public: |
| 6348 | // First string of the cons cell. |
| 6349 | inline String* first(); |
| 6350 | // Doesn't check that the result is a string, even in debug mode. This is |
| 6351 | // useful during GC where the mark bits confuse the checks. |
| 6352 | inline Object* unchecked_first(); |
| 6353 | inline void set_first(String* first, |
| 6354 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| 6355 | |
| 6356 | // Second string of the cons cell. |
| 6357 | inline String* second(); |
| 6358 | // Doesn't check that the result is a string, even in debug mode. This is |
| 6359 | // useful during GC where the mark bits confuse the checks. |
| 6360 | inline Object* unchecked_second(); |
| 6361 | inline void set_second(String* second, |
| 6362 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| 6363 | |
| 6364 | // Dispatched behavior. |
| 6365 | uint16_t ConsStringGet(int index); |
| 6366 | |
| 6367 | // Casting. |
| 6368 | static inline ConsString* cast(Object* obj); |
| 6369 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6370 | // Layout description. |
| 6371 | static const int kFirstOffset = POINTER_SIZE_ALIGN(String::kSize); |
| 6372 | static const int kSecondOffset = kFirstOffset + kPointerSize; |
| 6373 | static const int kSize = kSecondOffset + kPointerSize; |
| 6374 | |
| 6375 | // Support for StringInputBuffer. |
| 6376 | inline const unibrow::byte* ConsStringReadBlock(ReadBlockBuffer* buffer, |
| 6377 | unsigned* offset_ptr, |
| 6378 | unsigned chars); |
| 6379 | inline void ConsStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 6380 | unsigned* offset_ptr, |
| 6381 | unsigned chars); |
| 6382 | |
| 6383 | // Minimum length for a cons string. |
| 6384 | static const int kMinLength = 13; |
| 6385 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 6386 | typedef FixedBodyDescriptor<kFirstOffset, kSecondOffset + kPointerSize, kSize> |
| 6387 | BodyDescriptor; |
| 6388 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 6389 | #ifdef DEBUG |
| 6390 | void ConsStringVerify(); |
| 6391 | #endif |
| 6392 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6393 | private: |
| 6394 | DISALLOW_IMPLICIT_CONSTRUCTORS(ConsString); |
| 6395 | }; |
| 6396 | |
| 6397 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 6398 | // The Sliced String class describes strings that are substrings of another |
| 6399 | // sequential string. The motivation is to save time and memory when creating |
| 6400 | // a substring. A Sliced String is described as a pointer to the parent, |
| 6401 | // the offset from the start of the parent string and the length. Using |
| 6402 | // a Sliced String therefore requires unpacking of the parent string and |
| 6403 | // adding the offset to the start address. A substring of a Sliced String |
| 6404 | // are not nested since the double indirection is simplified when creating |
| 6405 | // such a substring. |
| 6406 | // Currently missing features are: |
| 6407 | // - handling externalized parent strings |
| 6408 | // - external strings as parent |
| 6409 | // - truncating sliced string to enable otherwise unneeded parent to be GC'ed. |
| 6410 | class SlicedString: public String { |
| 6411 | public: |
| 6412 | |
| 6413 | inline String* parent(); |
| 6414 | inline void set_parent(String* parent); |
| 6415 | inline int offset(); |
| 6416 | inline void set_offset(int offset); |
| 6417 | |
| 6418 | // Dispatched behavior. |
| 6419 | uint16_t SlicedStringGet(int index); |
| 6420 | |
| 6421 | // Casting. |
| 6422 | static inline SlicedString* cast(Object* obj); |
| 6423 | |
| 6424 | // Layout description. |
| 6425 | static const int kParentOffset = POINTER_SIZE_ALIGN(String::kSize); |
| 6426 | static const int kOffsetOffset = kParentOffset + kPointerSize; |
| 6427 | static const int kSize = kOffsetOffset + kPointerSize; |
| 6428 | |
| 6429 | // Support for StringInputBuffer |
| 6430 | inline const unibrow::byte* SlicedStringReadBlock(ReadBlockBuffer* buffer, |
| 6431 | unsigned* offset_ptr, |
| 6432 | unsigned chars); |
| 6433 | inline void SlicedStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 6434 | unsigned* offset_ptr, |
| 6435 | unsigned chars); |
| 6436 | // Minimum length for a sliced string. |
| 6437 | static const int kMinLength = 13; |
| 6438 | |
| 6439 | typedef FixedBodyDescriptor<kParentOffset, |
| 6440 | kOffsetOffset + kPointerSize, kSize> |
| 6441 | BodyDescriptor; |
| 6442 | |
| 6443 | #ifdef DEBUG |
| 6444 | void SlicedStringVerify(); |
| 6445 | #endif |
| 6446 | |
| 6447 | private: |
| 6448 | DISALLOW_IMPLICIT_CONSTRUCTORS(SlicedString); |
| 6449 | }; |
| 6450 | |
| 6451 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6452 | // The ExternalString class describes string values that are backed by |
| 6453 | // a string resource that lies outside the V8 heap. ExternalStrings |
| 6454 | // consist of the length field common to all strings, a pointer to the |
| 6455 | // external resource. It is important to ensure (externally) that the |
| 6456 | // resource is not deallocated while the ExternalString is live in the |
| 6457 | // V8 heap. |
| 6458 | // |
| 6459 | // The API expects that all ExternalStrings are created through the |
| 6460 | // API. Therefore, ExternalStrings should not be used internally. |
| 6461 | class ExternalString: public String { |
| 6462 | public: |
| 6463 | // Casting |
| 6464 | static inline ExternalString* cast(Object* obj); |
| 6465 | |
| 6466 | // Layout description. |
| 6467 | static const int kResourceOffset = POINTER_SIZE_ALIGN(String::kSize); |
| 6468 | static const int kSize = kResourceOffset + kPointerSize; |
| 6469 | |
| 6470 | STATIC_CHECK(kResourceOffset == Internals::kStringResourceOffset); |
| 6471 | |
| 6472 | private: |
| 6473 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalString); |
| 6474 | }; |
| 6475 | |
| 6476 | |
| 6477 | // The ExternalAsciiString class is an external string backed by an |
| 6478 | // ASCII string. |
| 6479 | class ExternalAsciiString: public ExternalString { |
| 6480 | public: |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 6481 | static const bool kHasAsciiEncoding = true; |
| 6482 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6483 | typedef v8::String::ExternalAsciiStringResource Resource; |
| 6484 | |
| 6485 | // The underlying resource. |
| 6486 | inline Resource* resource(); |
| 6487 | inline void set_resource(Resource* buffer); |
| 6488 | |
| 6489 | // Dispatched behavior. |
| 6490 | uint16_t ExternalAsciiStringGet(int index); |
| 6491 | |
| 6492 | // Casting. |
| 6493 | static inline ExternalAsciiString* cast(Object* obj); |
| 6494 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6495 | // Garbage collection support. |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 6496 | inline void ExternalAsciiStringIterateBody(ObjectVisitor* v); |
| 6497 | |
| 6498 | template<typename StaticVisitor> |
| 6499 | inline void ExternalAsciiStringIterateBody(); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6500 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6501 | // Support for StringInputBuffer. |
| 6502 | const unibrow::byte* ExternalAsciiStringReadBlock(unsigned* remaining, |
| 6503 | unsigned* offset, |
| 6504 | unsigned chars); |
| 6505 | inline void ExternalAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 6506 | unsigned* offset, |
| 6507 | unsigned chars); |
| 6508 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6509 | private: |
| 6510 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalAsciiString); |
| 6511 | }; |
| 6512 | |
| 6513 | |
| 6514 | // The ExternalTwoByteString class is an external string backed by a UTF-16 |
| 6515 | // encoded string. |
| 6516 | class ExternalTwoByteString: public ExternalString { |
| 6517 | public: |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 6518 | static const bool kHasAsciiEncoding = false; |
| 6519 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6520 | typedef v8::String::ExternalStringResource Resource; |
| 6521 | |
| 6522 | // The underlying string resource. |
| 6523 | inline Resource* resource(); |
| 6524 | inline void set_resource(Resource* buffer); |
| 6525 | |
| 6526 | // Dispatched behavior. |
| 6527 | uint16_t ExternalTwoByteStringGet(int index); |
| 6528 | |
| 6529 | // For regexp code. |
| 6530 | const uint16_t* ExternalTwoByteStringGetData(unsigned start); |
| 6531 | |
| 6532 | // Casting. |
| 6533 | static inline ExternalTwoByteString* cast(Object* obj); |
| 6534 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6535 | // Garbage collection support. |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 6536 | inline void ExternalTwoByteStringIterateBody(ObjectVisitor* v); |
| 6537 | |
| 6538 | template<typename StaticVisitor> |
| 6539 | inline void ExternalTwoByteStringIterateBody(); |
| 6540 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6541 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6542 | // Support for StringInputBuffer. |
| 6543 | void ExternalTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 6544 | unsigned* offset_ptr, |
| 6545 | unsigned chars); |
| 6546 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6547 | private: |
| 6548 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalTwoByteString); |
| 6549 | }; |
| 6550 | |
| 6551 | |
| 6552 | // Utility superclass for stack-allocated objects that must be updated |
| 6553 | // on gc. It provides two ways for the gc to update instances, either |
| 6554 | // iterating or updating after gc. |
| 6555 | class Relocatable BASE_EMBEDDED { |
| 6556 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 6557 | explicit inline Relocatable(Isolate* isolate); |
| 6558 | inline virtual ~Relocatable(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6559 | virtual void IterateInstance(ObjectVisitor* v) { } |
| 6560 | virtual void PostGarbageCollection() { } |
| 6561 | |
| 6562 | static void PostGarbageCollectionProcessing(); |
| 6563 | static int ArchiveSpacePerThread(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6564 | static char* ArchiveState(Isolate* isolate, char* to); |
| 6565 | static char* RestoreState(Isolate* isolate, char* from); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6566 | static void Iterate(ObjectVisitor* v); |
| 6567 | static void Iterate(ObjectVisitor* v, Relocatable* top); |
| 6568 | static char* Iterate(ObjectVisitor* v, char* t); |
| 6569 | private: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 6570 | Isolate* isolate_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6571 | Relocatable* prev_; |
| 6572 | }; |
| 6573 | |
| 6574 | |
| 6575 | // A flat string reader provides random access to the contents of a |
| 6576 | // string independent of the character width of the string. The handle |
| 6577 | // must be valid as long as the reader is being used. |
| 6578 | class FlatStringReader : public Relocatable { |
| 6579 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 6580 | FlatStringReader(Isolate* isolate, Handle<String> str); |
| 6581 | FlatStringReader(Isolate* isolate, Vector<const char> input); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6582 | void PostGarbageCollection(); |
| 6583 | inline uc32 Get(int index); |
| 6584 | int length() { return length_; } |
| 6585 | private: |
| 6586 | String** str_; |
| 6587 | bool is_ascii_; |
| 6588 | int length_; |
| 6589 | const void* start_; |
| 6590 | }; |
| 6591 | |
| 6592 | |
| 6593 | // Note that StringInputBuffers are not valid across a GC! To fix this |
| 6594 | // it would have to store a String Handle instead of a String* and |
| 6595 | // AsciiStringReadBlock would have to be modified to use memcpy. |
| 6596 | // |
| 6597 | // StringInputBuffer is able to traverse any string regardless of how |
| 6598 | // deeply nested a sequence of ConsStrings it is made of. However, |
| 6599 | // performance will be better if deep strings are flattened before they |
| 6600 | // are traversed. Since flattening requires memory allocation this is |
| 6601 | // not always desirable, however (esp. in debugging situations). |
| 6602 | class StringInputBuffer: public unibrow::InputBuffer<String, String*, 1024> { |
| 6603 | public: |
| 6604 | virtual void Seek(unsigned pos); |
| 6605 | inline StringInputBuffer(): unibrow::InputBuffer<String, String*, 1024>() {} |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 6606 | explicit inline StringInputBuffer(String* backing): |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6607 | unibrow::InputBuffer<String, String*, 1024>(backing) {} |
| 6608 | }; |
| 6609 | |
| 6610 | |
| 6611 | class SafeStringInputBuffer |
| 6612 | : public unibrow::InputBuffer<String, String**, 256> { |
| 6613 | public: |
| 6614 | virtual void Seek(unsigned pos); |
| 6615 | inline SafeStringInputBuffer() |
| 6616 | : unibrow::InputBuffer<String, String**, 256>() {} |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 6617 | explicit inline SafeStringInputBuffer(String** backing) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6618 | : unibrow::InputBuffer<String, String**, 256>(backing) {} |
| 6619 | }; |
| 6620 | |
| 6621 | |
| 6622 | template <typename T> |
| 6623 | class VectorIterator { |
| 6624 | public: |
| 6625 | VectorIterator(T* d, int l) : data_(Vector<const T>(d, l)), index_(0) { } |
| 6626 | explicit VectorIterator(Vector<const T> data) : data_(data), index_(0) { } |
| 6627 | T GetNext() { return data_[index_++]; } |
| 6628 | bool has_more() { return index_ < data_.length(); } |
| 6629 | private: |
| 6630 | Vector<const T> data_; |
| 6631 | int index_; |
| 6632 | }; |
| 6633 | |
| 6634 | |
| 6635 | // The Oddball describes objects null, undefined, true, and false. |
| 6636 | class Oddball: public HeapObject { |
| 6637 | public: |
| 6638 | // [to_string]: Cached to_string computed at startup. |
| 6639 | DECL_ACCESSORS(to_string, String) |
| 6640 | |
| 6641 | // [to_number]: Cached to_number computed at startup. |
| 6642 | DECL_ACCESSORS(to_number, Object) |
| 6643 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 6644 | inline byte kind(); |
| 6645 | inline void set_kind(byte kind); |
| 6646 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6647 | // Casting. |
| 6648 | static inline Oddball* cast(Object* obj); |
| 6649 | |
| 6650 | // Dispatched behavior. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6651 | #ifdef DEBUG |
| 6652 | void OddballVerify(); |
| 6653 | #endif |
| 6654 | |
| 6655 | // Initialize the fields. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 6656 | MUST_USE_RESULT MaybeObject* Initialize(const char* to_string, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 6657 | Object* to_number, |
| 6658 | byte kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6659 | |
| 6660 | // Layout description. |
| 6661 | static const int kToStringOffset = HeapObject::kHeaderSize; |
| 6662 | static const int kToNumberOffset = kToStringOffset + kPointerSize; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 6663 | static const int kKindOffset = kToNumberOffset + kPointerSize; |
| 6664 | static const int kSize = kKindOffset + kPointerSize; |
| 6665 | |
| 6666 | static const byte kFalse = 0; |
| 6667 | static const byte kTrue = 1; |
| 6668 | static const byte kNotBooleanMask = ~1; |
| 6669 | static const byte kTheHole = 2; |
| 6670 | static const byte kNull = 3; |
| 6671 | static const byte kArgumentMarker = 4; |
| 6672 | static const byte kUndefined = 5; |
| 6673 | static const byte kOther = 6; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6674 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 6675 | typedef FixedBodyDescriptor<kToStringOffset, |
| 6676 | kToNumberOffset + kPointerSize, |
| 6677 | kSize> BodyDescriptor; |
| 6678 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6679 | private: |
| 6680 | DISALLOW_IMPLICIT_CONSTRUCTORS(Oddball); |
| 6681 | }; |
| 6682 | |
| 6683 | |
| 6684 | class JSGlobalPropertyCell: public HeapObject { |
| 6685 | public: |
| 6686 | // [value]: value of the global property. |
| 6687 | DECL_ACCESSORS(value, Object) |
| 6688 | |
| 6689 | // Casting. |
| 6690 | static inline JSGlobalPropertyCell* cast(Object* obj); |
| 6691 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6692 | #ifdef DEBUG |
| 6693 | void JSGlobalPropertyCellVerify(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6694 | #endif |
| 6695 | #ifdef OBJECT_PRINT |
| 6696 | inline void JSGlobalPropertyCellPrint() { |
| 6697 | JSGlobalPropertyCellPrint(stdout); |
| 6698 | } |
| 6699 | void JSGlobalPropertyCellPrint(FILE* out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6700 | #endif |
| 6701 | |
| 6702 | // Layout description. |
| 6703 | static const int kValueOffset = HeapObject::kHeaderSize; |
| 6704 | static const int kSize = kValueOffset + kPointerSize; |
| 6705 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 6706 | typedef FixedBodyDescriptor<kValueOffset, |
| 6707 | kValueOffset + kPointerSize, |
| 6708 | kSize> BodyDescriptor; |
| 6709 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 6710 | // Returns the isolate/heap this cell object belongs to. |
| 6711 | inline Isolate* isolate(); |
| 6712 | inline Heap* heap(); |
| 6713 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6714 | private: |
| 6715 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalPropertyCell); |
| 6716 | }; |
| 6717 | |
| 6718 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6719 | // The JSProxy describes EcmaScript Harmony proxies |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6720 | class JSProxy: public JSReceiver { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6721 | public: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6722 | // [handler]: The handler property. |
| 6723 | DECL_ACCESSORS(handler, Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6724 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6725 | // [padding]: The padding slot (unused, see below). |
| 6726 | DECL_ACCESSORS(padding, Object) |
| 6727 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6728 | // Casting. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6729 | static inline JSProxy* cast(Object* obj); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6730 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6731 | bool HasPropertyWithHandler(String* name); |
| 6732 | |
| 6733 | MUST_USE_RESULT MaybeObject* SetPropertyWithHandler( |
| 6734 | String* name, |
| 6735 | Object* value, |
| 6736 | PropertyAttributes attributes, |
| 6737 | StrictModeFlag strict_mode); |
| 6738 | |
| 6739 | MUST_USE_RESULT MaybeObject* DeletePropertyWithHandler( |
| 6740 | String* name, |
| 6741 | DeleteMode mode); |
| 6742 | |
| 6743 | MUST_USE_RESULT PropertyAttributes GetPropertyAttributeWithHandler( |
| 6744 | JSReceiver* receiver, |
| 6745 | String* name, |
| 6746 | bool* has_exception); |
| 6747 | |
| 6748 | // Turn this into an (empty) JSObject. |
| 6749 | void Fix(); |
| 6750 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6751 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6752 | #ifdef OBJECT_PRINT |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6753 | inline void JSProxyPrint() { |
| 6754 | JSProxyPrint(stdout); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6755 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6756 | void JSProxyPrint(FILE* out); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6757 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6758 | #ifdef DEBUG |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6759 | void JSProxyVerify(); |
| 6760 | #endif |
| 6761 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6762 | // Layout description. We add padding so that a proxy has the same |
| 6763 | // size as a virgin JSObject. This is essential for becoming a JSObject |
| 6764 | // upon freeze. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6765 | static const int kHandlerOffset = HeapObject::kHeaderSize; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6766 | static const int kPaddingOffset = kHandlerOffset + kPointerSize; |
| 6767 | static const int kSize = kPaddingOffset + kPointerSize; |
| 6768 | |
| 6769 | STATIC_CHECK(kSize == JSObject::kHeaderSize); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6770 | |
| 6771 | typedef FixedBodyDescriptor<kHandlerOffset, |
| 6772 | kHandlerOffset + kPointerSize, |
| 6773 | kSize> BodyDescriptor; |
| 6774 | |
| 6775 | private: |
| 6776 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSProxy); |
| 6777 | }; |
| 6778 | |
| 6779 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6780 | // TODO(rossberg): Only a stub for now. |
| 6781 | class JSFunctionProxy: public JSProxy { |
| 6782 | public: |
| 6783 | // Casting. |
| 6784 | static inline JSFunctionProxy* cast(Object* obj); |
| 6785 | |
| 6786 | private: |
| 6787 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunctionProxy); |
| 6788 | }; |
| 6789 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6790 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 6791 | // The JSWeakMap describes EcmaScript Harmony weak maps |
| 6792 | class JSWeakMap: public JSObject { |
| 6793 | public: |
| 6794 | // [table]: the backing hash table mapping keys to values. |
| 6795 | DECL_ACCESSORS(table, ObjectHashTable) |
| 6796 | |
| 6797 | // [next]: linked list of encountered weak maps during GC. |
| 6798 | DECL_ACCESSORS(next, Object) |
| 6799 | |
| 6800 | // Unchecked accessors to be used during GC. |
| 6801 | inline ObjectHashTable* unchecked_table(); |
| 6802 | |
| 6803 | // Casting. |
| 6804 | static inline JSWeakMap* cast(Object* obj); |
| 6805 | |
| 6806 | #ifdef OBJECT_PRINT |
| 6807 | inline void JSWeakMapPrint() { |
| 6808 | JSWeakMapPrint(stdout); |
| 6809 | } |
| 6810 | void JSWeakMapPrint(FILE* out); |
| 6811 | #endif |
| 6812 | #ifdef DEBUG |
| 6813 | void JSWeakMapVerify(); |
| 6814 | #endif |
| 6815 | |
| 6816 | static const int kTableOffset = JSObject::kHeaderSize; |
| 6817 | static const int kNextOffset = kTableOffset + kPointerSize; |
| 6818 | static const int kSize = kNextOffset + kPointerSize; |
| 6819 | |
| 6820 | private: |
| 6821 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSWeakMap); |
| 6822 | }; |
| 6823 | |
| 6824 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6825 | // Foreign describes objects pointing from JavaScript to C structures. |
| 6826 | // Since they cannot contain references to JS HeapObjects they can be |
| 6827 | // placed in old_data_space. |
| 6828 | class Foreign: public HeapObject { |
| 6829 | public: |
| 6830 | // [address]: field containing the address. |
| 6831 | inline Address address(); |
| 6832 | inline void set_address(Address value); |
| 6833 | |
| 6834 | // Casting. |
| 6835 | static inline Foreign* cast(Object* obj); |
| 6836 | |
| 6837 | // Dispatched behavior. |
| 6838 | inline void ForeignIterateBody(ObjectVisitor* v); |
| 6839 | |
| 6840 | template<typename StaticVisitor> |
| 6841 | inline void ForeignIterateBody(); |
| 6842 | |
| 6843 | #ifdef OBJECT_PRINT |
| 6844 | inline void ForeignPrint() { |
| 6845 | ForeignPrint(stdout); |
| 6846 | } |
| 6847 | void ForeignPrint(FILE* out); |
| 6848 | #endif |
| 6849 | #ifdef DEBUG |
| 6850 | void ForeignVerify(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6851 | #endif |
| 6852 | |
| 6853 | // Layout description. |
| 6854 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6855 | static const int kAddressOffset = HeapObject::kHeaderSize; |
| 6856 | static const int kSize = kAddressOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6857 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6858 | STATIC_CHECK(kAddressOffset == Internals::kForeignAddressOffset); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6859 | |
| 6860 | private: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6861 | DISALLOW_IMPLICIT_CONSTRUCTORS(Foreign); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6862 | }; |
| 6863 | |
| 6864 | |
| 6865 | // The JSArray describes JavaScript Arrays |
| 6866 | // Such an array can be in one of two modes: |
| 6867 | // - fast, backing storage is a FixedArray and length <= elements.length(); |
| 6868 | // Please note: push and pop can be used to grow and shrink the array. |
| 6869 | // - slow, backing storage is a HashTable with numbers as keys. |
| 6870 | class JSArray: public JSObject { |
| 6871 | public: |
| 6872 | // [length]: The length property. |
| 6873 | DECL_ACCESSORS(length, Object) |
| 6874 | |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 6875 | // Overload the length setter to skip write barrier when the length |
| 6876 | // is set to a smi. This matches the set function on FixedArray. |
| 6877 | inline void set_length(Smi* length); |
| 6878 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 6879 | MUST_USE_RESULT MaybeObject* JSArrayUpdateLengthFromIndex(uint32_t index, |
| 6880 | Object* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6881 | |
| 6882 | // Initialize the array with the given capacity. The function may |
| 6883 | // fail due to out-of-memory situations, but only if the requested |
| 6884 | // capacity is non-zero. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 6885 | MUST_USE_RESULT MaybeObject* Initialize(int capacity); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6886 | |
| 6887 | // Set the content of the array to the content of storage. |
| 6888 | inline void SetContent(FixedArray* storage); |
| 6889 | |
| 6890 | // Casting. |
| 6891 | static inline JSArray* cast(Object* obj); |
| 6892 | |
| 6893 | // Uses handles. Ensures that the fixed array backing the JSArray has at |
| 6894 | // least the stated size. |
| 6895 | inline void EnsureSize(int minimum_size_of_backing_fixed_array); |
| 6896 | |
| 6897 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6898 | #ifdef OBJECT_PRINT |
| 6899 | inline void JSArrayPrint() { |
| 6900 | JSArrayPrint(stdout); |
| 6901 | } |
| 6902 | void JSArrayPrint(FILE* out); |
| 6903 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6904 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6905 | void JSArrayVerify(); |
| 6906 | #endif |
| 6907 | |
| 6908 | // Number of element slots to pre-allocate for an empty array. |
| 6909 | static const int kPreallocatedArrayElements = 4; |
| 6910 | |
| 6911 | // Layout description. |
| 6912 | static const int kLengthOffset = JSObject::kHeaderSize; |
| 6913 | static const int kSize = kLengthOffset + kPointerSize; |
| 6914 | |
| 6915 | private: |
| 6916 | // Expand the fixed array backing of a fast-case JSArray to at least |
| 6917 | // the requested size. |
| 6918 | void Expand(int minimum_size_of_backing_fixed_array); |
| 6919 | |
| 6920 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSArray); |
| 6921 | }; |
| 6922 | |
| 6923 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 6924 | // JSRegExpResult is just a JSArray with a specific initial map. |
| 6925 | // This initial map adds in-object properties for "index" and "input" |
| 6926 | // properties, as assigned by RegExp.prototype.exec, which allows |
| 6927 | // faster creation of RegExp exec results. |
| 6928 | // This class just holds constants used when creating the result. |
| 6929 | // After creation the result must be treated as a JSArray in all regards. |
| 6930 | class JSRegExpResult: public JSArray { |
| 6931 | public: |
| 6932 | // Offsets of object fields. |
| 6933 | static const int kIndexOffset = JSArray::kSize; |
| 6934 | static const int kInputOffset = kIndexOffset + kPointerSize; |
| 6935 | static const int kSize = kInputOffset + kPointerSize; |
| 6936 | // Indices of in-object properties. |
| 6937 | static const int kIndexIndex = 0; |
| 6938 | static const int kInputIndex = 1; |
| 6939 | private: |
| 6940 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSRegExpResult); |
| 6941 | }; |
| 6942 | |
| 6943 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6944 | // An accessor must have a getter, but can have no setter. |
| 6945 | // |
| 6946 | // When setting a property, V8 searches accessors in prototypes. |
| 6947 | // If an accessor was found and it does not have a setter, |
| 6948 | // the request is ignored. |
| 6949 | // |
| 6950 | // If the accessor in the prototype has the READ_ONLY property attribute, then |
| 6951 | // a new value is added to the local object when the property is set. |
| 6952 | // This shadows the accessor in the prototype. |
| 6953 | class AccessorInfo: public Struct { |
| 6954 | public: |
| 6955 | DECL_ACCESSORS(getter, Object) |
| 6956 | DECL_ACCESSORS(setter, Object) |
| 6957 | DECL_ACCESSORS(data, Object) |
| 6958 | DECL_ACCESSORS(name, Object) |
| 6959 | DECL_ACCESSORS(flag, Smi) |
| 6960 | |
| 6961 | inline bool all_can_read(); |
| 6962 | inline void set_all_can_read(bool value); |
| 6963 | |
| 6964 | inline bool all_can_write(); |
| 6965 | inline void set_all_can_write(bool value); |
| 6966 | |
| 6967 | inline bool prohibits_overwriting(); |
| 6968 | inline void set_prohibits_overwriting(bool value); |
| 6969 | |
| 6970 | inline PropertyAttributes property_attributes(); |
| 6971 | inline void set_property_attributes(PropertyAttributes attributes); |
| 6972 | |
| 6973 | static inline AccessorInfo* cast(Object* obj); |
| 6974 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6975 | #ifdef OBJECT_PRINT |
| 6976 | inline void AccessorInfoPrint() { |
| 6977 | AccessorInfoPrint(stdout); |
| 6978 | } |
| 6979 | void AccessorInfoPrint(FILE* out); |
| 6980 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6981 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6982 | void AccessorInfoVerify(); |
| 6983 | #endif |
| 6984 | |
| 6985 | static const int kGetterOffset = HeapObject::kHeaderSize; |
| 6986 | static const int kSetterOffset = kGetterOffset + kPointerSize; |
| 6987 | static const int kDataOffset = kSetterOffset + kPointerSize; |
| 6988 | static const int kNameOffset = kDataOffset + kPointerSize; |
| 6989 | static const int kFlagOffset = kNameOffset + kPointerSize; |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 6990 | static const int kSize = kFlagOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6991 | |
| 6992 | private: |
| 6993 | // Bit positions in flag. |
| 6994 | static const int kAllCanReadBit = 0; |
| 6995 | static const int kAllCanWriteBit = 1; |
| 6996 | static const int kProhibitsOverwritingBit = 2; |
| 6997 | class AttributesField: public BitField<PropertyAttributes, 3, 3> {}; |
| 6998 | |
| 6999 | DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorInfo); |
| 7000 | }; |
| 7001 | |
| 7002 | |
| 7003 | class AccessCheckInfo: public Struct { |
| 7004 | public: |
| 7005 | DECL_ACCESSORS(named_callback, Object) |
| 7006 | DECL_ACCESSORS(indexed_callback, Object) |
| 7007 | DECL_ACCESSORS(data, Object) |
| 7008 | |
| 7009 | static inline AccessCheckInfo* cast(Object* obj); |
| 7010 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7011 | #ifdef OBJECT_PRINT |
| 7012 | inline void AccessCheckInfoPrint() { |
| 7013 | AccessCheckInfoPrint(stdout); |
| 7014 | } |
| 7015 | void AccessCheckInfoPrint(FILE* out); |
| 7016 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7017 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7018 | void AccessCheckInfoVerify(); |
| 7019 | #endif |
| 7020 | |
| 7021 | static const int kNamedCallbackOffset = HeapObject::kHeaderSize; |
| 7022 | static const int kIndexedCallbackOffset = kNamedCallbackOffset + kPointerSize; |
| 7023 | static const int kDataOffset = kIndexedCallbackOffset + kPointerSize; |
| 7024 | static const int kSize = kDataOffset + kPointerSize; |
| 7025 | |
| 7026 | private: |
| 7027 | DISALLOW_IMPLICIT_CONSTRUCTORS(AccessCheckInfo); |
| 7028 | }; |
| 7029 | |
| 7030 | |
| 7031 | class InterceptorInfo: public Struct { |
| 7032 | public: |
| 7033 | DECL_ACCESSORS(getter, Object) |
| 7034 | DECL_ACCESSORS(setter, Object) |
| 7035 | DECL_ACCESSORS(query, Object) |
| 7036 | DECL_ACCESSORS(deleter, Object) |
| 7037 | DECL_ACCESSORS(enumerator, Object) |
| 7038 | DECL_ACCESSORS(data, Object) |
| 7039 | |
| 7040 | static inline InterceptorInfo* cast(Object* obj); |
| 7041 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7042 | #ifdef OBJECT_PRINT |
| 7043 | inline void InterceptorInfoPrint() { |
| 7044 | InterceptorInfoPrint(stdout); |
| 7045 | } |
| 7046 | void InterceptorInfoPrint(FILE* out); |
| 7047 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7048 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7049 | void InterceptorInfoVerify(); |
| 7050 | #endif |
| 7051 | |
| 7052 | static const int kGetterOffset = HeapObject::kHeaderSize; |
| 7053 | static const int kSetterOffset = kGetterOffset + kPointerSize; |
| 7054 | static const int kQueryOffset = kSetterOffset + kPointerSize; |
| 7055 | static const int kDeleterOffset = kQueryOffset + kPointerSize; |
| 7056 | static const int kEnumeratorOffset = kDeleterOffset + kPointerSize; |
| 7057 | static const int kDataOffset = kEnumeratorOffset + kPointerSize; |
| 7058 | static const int kSize = kDataOffset + kPointerSize; |
| 7059 | |
| 7060 | private: |
| 7061 | DISALLOW_IMPLICIT_CONSTRUCTORS(InterceptorInfo); |
| 7062 | }; |
| 7063 | |
| 7064 | |
| 7065 | class CallHandlerInfo: public Struct { |
| 7066 | public: |
| 7067 | DECL_ACCESSORS(callback, Object) |
| 7068 | DECL_ACCESSORS(data, Object) |
| 7069 | |
| 7070 | static inline CallHandlerInfo* cast(Object* obj); |
| 7071 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7072 | #ifdef OBJECT_PRINT |
| 7073 | inline void CallHandlerInfoPrint() { |
| 7074 | CallHandlerInfoPrint(stdout); |
| 7075 | } |
| 7076 | void CallHandlerInfoPrint(FILE* out); |
| 7077 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7078 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7079 | void CallHandlerInfoVerify(); |
| 7080 | #endif |
| 7081 | |
| 7082 | static const int kCallbackOffset = HeapObject::kHeaderSize; |
| 7083 | static const int kDataOffset = kCallbackOffset + kPointerSize; |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 7084 | static const int kSize = kDataOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7085 | |
| 7086 | private: |
| 7087 | DISALLOW_IMPLICIT_CONSTRUCTORS(CallHandlerInfo); |
| 7088 | }; |
| 7089 | |
| 7090 | |
| 7091 | class TemplateInfo: public Struct { |
| 7092 | public: |
| 7093 | DECL_ACCESSORS(tag, Object) |
| 7094 | DECL_ACCESSORS(property_list, Object) |
| 7095 | |
| 7096 | #ifdef DEBUG |
| 7097 | void TemplateInfoVerify(); |
| 7098 | #endif |
| 7099 | |
| 7100 | static const int kTagOffset = HeapObject::kHeaderSize; |
| 7101 | static const int kPropertyListOffset = kTagOffset + kPointerSize; |
| 7102 | static const int kHeaderSize = kPropertyListOffset + kPointerSize; |
| 7103 | protected: |
| 7104 | friend class AGCCVersionRequiresThisClassToHaveAFriendSoHereItIs; |
| 7105 | DISALLOW_IMPLICIT_CONSTRUCTORS(TemplateInfo); |
| 7106 | }; |
| 7107 | |
| 7108 | |
| 7109 | class FunctionTemplateInfo: public TemplateInfo { |
| 7110 | public: |
| 7111 | DECL_ACCESSORS(serial_number, Object) |
| 7112 | DECL_ACCESSORS(call_code, Object) |
| 7113 | DECL_ACCESSORS(property_accessors, Object) |
| 7114 | DECL_ACCESSORS(prototype_template, Object) |
| 7115 | DECL_ACCESSORS(parent_template, Object) |
| 7116 | DECL_ACCESSORS(named_property_handler, Object) |
| 7117 | DECL_ACCESSORS(indexed_property_handler, Object) |
| 7118 | DECL_ACCESSORS(instance_template, Object) |
| 7119 | DECL_ACCESSORS(class_name, Object) |
| 7120 | DECL_ACCESSORS(signature, Object) |
| 7121 | DECL_ACCESSORS(instance_call_handler, Object) |
| 7122 | DECL_ACCESSORS(access_check_info, Object) |
| 7123 | DECL_ACCESSORS(flag, Smi) |
| 7124 | |
| 7125 | // Following properties use flag bits. |
| 7126 | DECL_BOOLEAN_ACCESSORS(hidden_prototype) |
| 7127 | DECL_BOOLEAN_ACCESSORS(undetectable) |
| 7128 | // If the bit is set, object instances created by this function |
| 7129 | // requires access check. |
| 7130 | DECL_BOOLEAN_ACCESSORS(needs_access_check) |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 7131 | DECL_BOOLEAN_ACCESSORS(read_only_prototype) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7132 | |
| 7133 | static inline FunctionTemplateInfo* cast(Object* obj); |
| 7134 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7135 | #ifdef OBJECT_PRINT |
| 7136 | inline void FunctionTemplateInfoPrint() { |
| 7137 | FunctionTemplateInfoPrint(stdout); |
| 7138 | } |
| 7139 | void FunctionTemplateInfoPrint(FILE* out); |
| 7140 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7141 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7142 | void FunctionTemplateInfoVerify(); |
| 7143 | #endif |
| 7144 | |
| 7145 | static const int kSerialNumberOffset = TemplateInfo::kHeaderSize; |
| 7146 | static const int kCallCodeOffset = kSerialNumberOffset + kPointerSize; |
| 7147 | static const int kPropertyAccessorsOffset = kCallCodeOffset + kPointerSize; |
| 7148 | static const int kPrototypeTemplateOffset = |
| 7149 | kPropertyAccessorsOffset + kPointerSize; |
| 7150 | static const int kParentTemplateOffset = |
| 7151 | kPrototypeTemplateOffset + kPointerSize; |
| 7152 | static const int kNamedPropertyHandlerOffset = |
| 7153 | kParentTemplateOffset + kPointerSize; |
| 7154 | static const int kIndexedPropertyHandlerOffset = |
| 7155 | kNamedPropertyHandlerOffset + kPointerSize; |
| 7156 | static const int kInstanceTemplateOffset = |
| 7157 | kIndexedPropertyHandlerOffset + kPointerSize; |
| 7158 | static const int kClassNameOffset = kInstanceTemplateOffset + kPointerSize; |
| 7159 | static const int kSignatureOffset = kClassNameOffset + kPointerSize; |
| 7160 | static const int kInstanceCallHandlerOffset = kSignatureOffset + kPointerSize; |
| 7161 | static const int kAccessCheckInfoOffset = |
| 7162 | kInstanceCallHandlerOffset + kPointerSize; |
| 7163 | static const int kFlagOffset = kAccessCheckInfoOffset + kPointerSize; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 7164 | static const int kSize = kFlagOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7165 | |
| 7166 | private: |
| 7167 | // Bit position in the flag, from least significant bit position. |
| 7168 | static const int kHiddenPrototypeBit = 0; |
| 7169 | static const int kUndetectableBit = 1; |
| 7170 | static const int kNeedsAccessCheckBit = 2; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 7171 | static const int kReadOnlyPrototypeBit = 3; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7172 | |
| 7173 | DISALLOW_IMPLICIT_CONSTRUCTORS(FunctionTemplateInfo); |
| 7174 | }; |
| 7175 | |
| 7176 | |
| 7177 | class ObjectTemplateInfo: public TemplateInfo { |
| 7178 | public: |
| 7179 | DECL_ACCESSORS(constructor, Object) |
| 7180 | DECL_ACCESSORS(internal_field_count, Object) |
| 7181 | |
| 7182 | static inline ObjectTemplateInfo* cast(Object* obj); |
| 7183 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7184 | #ifdef OBJECT_PRINT |
| 7185 | inline void ObjectTemplateInfoPrint() { |
| 7186 | ObjectTemplateInfoPrint(stdout); |
| 7187 | } |
| 7188 | void ObjectTemplateInfoPrint(FILE* out); |
| 7189 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7190 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7191 | void ObjectTemplateInfoVerify(); |
| 7192 | #endif |
| 7193 | |
| 7194 | static const int kConstructorOffset = TemplateInfo::kHeaderSize; |
| 7195 | static const int kInternalFieldCountOffset = |
| 7196 | kConstructorOffset + kPointerSize; |
| 7197 | static const int kSize = kInternalFieldCountOffset + kPointerSize; |
| 7198 | }; |
| 7199 | |
| 7200 | |
| 7201 | class SignatureInfo: public Struct { |
| 7202 | public: |
| 7203 | DECL_ACCESSORS(receiver, Object) |
| 7204 | DECL_ACCESSORS(args, Object) |
| 7205 | |
| 7206 | static inline SignatureInfo* cast(Object* obj); |
| 7207 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7208 | #ifdef OBJECT_PRINT |
| 7209 | inline void SignatureInfoPrint() { |
| 7210 | SignatureInfoPrint(stdout); |
| 7211 | } |
| 7212 | void SignatureInfoPrint(FILE* out); |
| 7213 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7214 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7215 | void SignatureInfoVerify(); |
| 7216 | #endif |
| 7217 | |
| 7218 | static const int kReceiverOffset = Struct::kHeaderSize; |
| 7219 | static const int kArgsOffset = kReceiverOffset + kPointerSize; |
| 7220 | static const int kSize = kArgsOffset + kPointerSize; |
| 7221 | |
| 7222 | private: |
| 7223 | DISALLOW_IMPLICIT_CONSTRUCTORS(SignatureInfo); |
| 7224 | }; |
| 7225 | |
| 7226 | |
| 7227 | class TypeSwitchInfo: public Struct { |
| 7228 | public: |
| 7229 | DECL_ACCESSORS(types, Object) |
| 7230 | |
| 7231 | static inline TypeSwitchInfo* cast(Object* obj); |
| 7232 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7233 | #ifdef OBJECT_PRINT |
| 7234 | inline void TypeSwitchInfoPrint() { |
| 7235 | TypeSwitchInfoPrint(stdout); |
| 7236 | } |
| 7237 | void TypeSwitchInfoPrint(FILE* out); |
| 7238 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7239 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7240 | void TypeSwitchInfoVerify(); |
| 7241 | #endif |
| 7242 | |
| 7243 | static const int kTypesOffset = Struct::kHeaderSize; |
| 7244 | static const int kSize = kTypesOffset + kPointerSize; |
| 7245 | }; |
| 7246 | |
| 7247 | |
| 7248 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 7249 | // The DebugInfo class holds additional information for a function being |
| 7250 | // debugged. |
| 7251 | class DebugInfo: public Struct { |
| 7252 | public: |
| 7253 | // The shared function info for the source being debugged. |
| 7254 | DECL_ACCESSORS(shared, SharedFunctionInfo) |
| 7255 | // Code object for the original code. |
| 7256 | DECL_ACCESSORS(original_code, Code) |
| 7257 | // Code object for the patched code. This code object is the code object |
| 7258 | // currently active for the function. |
| 7259 | DECL_ACCESSORS(code, Code) |
| 7260 | // Fixed array holding status information for each active break point. |
| 7261 | DECL_ACCESSORS(break_points, FixedArray) |
| 7262 | |
| 7263 | // Check if there is a break point at a code position. |
| 7264 | bool HasBreakPoint(int code_position); |
| 7265 | // Get the break point info object for a code position. |
| 7266 | Object* GetBreakPointInfo(int code_position); |
| 7267 | // Clear a break point. |
| 7268 | static void ClearBreakPoint(Handle<DebugInfo> debug_info, |
| 7269 | int code_position, |
| 7270 | Handle<Object> break_point_object); |
| 7271 | // Set a break point. |
| 7272 | static void SetBreakPoint(Handle<DebugInfo> debug_info, int code_position, |
| 7273 | int source_position, int statement_position, |
| 7274 | Handle<Object> break_point_object); |
| 7275 | // Get the break point objects for a code position. |
| 7276 | Object* GetBreakPointObjects(int code_position); |
| 7277 | // Find the break point info holding this break point object. |
| 7278 | static Object* FindBreakPointInfo(Handle<DebugInfo> debug_info, |
| 7279 | Handle<Object> break_point_object); |
| 7280 | // Get the number of break points for this function. |
| 7281 | int GetBreakPointCount(); |
| 7282 | |
| 7283 | static inline DebugInfo* cast(Object* obj); |
| 7284 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7285 | #ifdef OBJECT_PRINT |
| 7286 | inline void DebugInfoPrint() { |
| 7287 | DebugInfoPrint(stdout); |
| 7288 | } |
| 7289 | void DebugInfoPrint(FILE* out); |
| 7290 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7291 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7292 | void DebugInfoVerify(); |
| 7293 | #endif |
| 7294 | |
| 7295 | static const int kSharedFunctionInfoIndex = Struct::kHeaderSize; |
| 7296 | static const int kOriginalCodeIndex = kSharedFunctionInfoIndex + kPointerSize; |
| 7297 | static const int kPatchedCodeIndex = kOriginalCodeIndex + kPointerSize; |
| 7298 | static const int kActiveBreakPointsCountIndex = |
| 7299 | kPatchedCodeIndex + kPointerSize; |
| 7300 | static const int kBreakPointsStateIndex = |
| 7301 | kActiveBreakPointsCountIndex + kPointerSize; |
| 7302 | static const int kSize = kBreakPointsStateIndex + kPointerSize; |
| 7303 | |
| 7304 | private: |
| 7305 | static const int kNoBreakPointInfo = -1; |
| 7306 | |
| 7307 | // Lookup the index in the break_points array for a code position. |
| 7308 | int GetBreakPointInfoIndex(int code_position); |
| 7309 | |
| 7310 | DISALLOW_IMPLICIT_CONSTRUCTORS(DebugInfo); |
| 7311 | }; |
| 7312 | |
| 7313 | |
| 7314 | // The BreakPointInfo class holds information for break points set in a |
| 7315 | // function. The DebugInfo object holds a BreakPointInfo object for each code |
| 7316 | // position with one or more break points. |
| 7317 | class BreakPointInfo: public Struct { |
| 7318 | public: |
| 7319 | // The position in the code for the break point. |
| 7320 | DECL_ACCESSORS(code_position, Smi) |
| 7321 | // The position in the source for the break position. |
| 7322 | DECL_ACCESSORS(source_position, Smi) |
| 7323 | // The position in the source for the last statement before this break |
| 7324 | // position. |
| 7325 | DECL_ACCESSORS(statement_position, Smi) |
| 7326 | // List of related JavaScript break points. |
| 7327 | DECL_ACCESSORS(break_point_objects, Object) |
| 7328 | |
| 7329 | // Removes a break point. |
| 7330 | static void ClearBreakPoint(Handle<BreakPointInfo> info, |
| 7331 | Handle<Object> break_point_object); |
| 7332 | // Set a break point. |
| 7333 | static void SetBreakPoint(Handle<BreakPointInfo> info, |
| 7334 | Handle<Object> break_point_object); |
| 7335 | // Check if break point info has this break point object. |
| 7336 | static bool HasBreakPointObject(Handle<BreakPointInfo> info, |
| 7337 | Handle<Object> break_point_object); |
| 7338 | // Get the number of break points for this code position. |
| 7339 | int GetBreakPointCount(); |
| 7340 | |
| 7341 | static inline BreakPointInfo* cast(Object* obj); |
| 7342 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7343 | #ifdef OBJECT_PRINT |
| 7344 | inline void BreakPointInfoPrint() { |
| 7345 | BreakPointInfoPrint(stdout); |
| 7346 | } |
| 7347 | void BreakPointInfoPrint(FILE* out); |
| 7348 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7349 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7350 | void BreakPointInfoVerify(); |
| 7351 | #endif |
| 7352 | |
| 7353 | static const int kCodePositionIndex = Struct::kHeaderSize; |
| 7354 | static const int kSourcePositionIndex = kCodePositionIndex + kPointerSize; |
| 7355 | static const int kStatementPositionIndex = |
| 7356 | kSourcePositionIndex + kPointerSize; |
| 7357 | static const int kBreakPointObjectsIndex = |
| 7358 | kStatementPositionIndex + kPointerSize; |
| 7359 | static const int kSize = kBreakPointObjectsIndex + kPointerSize; |
| 7360 | |
| 7361 | private: |
| 7362 | DISALLOW_IMPLICIT_CONSTRUCTORS(BreakPointInfo); |
| 7363 | }; |
| 7364 | #endif // ENABLE_DEBUGGER_SUPPORT |
| 7365 | |
| 7366 | |
| 7367 | #undef DECL_BOOLEAN_ACCESSORS |
| 7368 | #undef DECL_ACCESSORS |
| 7369 | |
| 7370 | |
| 7371 | // Abstract base class for visiting, and optionally modifying, the |
| 7372 | // pointers contained in Objects. Used in GC and serialization/deserialization. |
| 7373 | class ObjectVisitor BASE_EMBEDDED { |
| 7374 | public: |
| 7375 | virtual ~ObjectVisitor() {} |
| 7376 | |
| 7377 | // Visits a contiguous arrays of pointers in the half-open range |
| 7378 | // [start, end). Any or all of the values may be modified on return. |
| 7379 | virtual void VisitPointers(Object** start, Object** end) = 0; |
| 7380 | |
| 7381 | // To allow lazy clearing of inline caches the visitor has |
| 7382 | // a rich interface for iterating over Code objects.. |
| 7383 | |
| 7384 | // Visits a code target in the instruction stream. |
| 7385 | virtual void VisitCodeTarget(RelocInfo* rinfo); |
| 7386 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 7387 | // Visits a code entry in a JS function. |
| 7388 | virtual void VisitCodeEntry(Address entry_address); |
| 7389 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7390 | // Visits a global property cell reference in the instruction stream. |
| 7391 | virtual void VisitGlobalPropertyCell(RelocInfo* rinfo); |
| 7392 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7393 | // Visits a runtime entry in the instruction stream. |
| 7394 | virtual void VisitRuntimeEntry(RelocInfo* rinfo) {} |
| 7395 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 7396 | // Visits the resource of an ASCII or two-byte string. |
| 7397 | virtual void VisitExternalAsciiString( |
| 7398 | v8::String::ExternalAsciiStringResource** resource) {} |
| 7399 | virtual void VisitExternalTwoByteString( |
| 7400 | v8::String::ExternalStringResource** resource) {} |
| 7401 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7402 | // Visits a debug call target in the instruction stream. |
| 7403 | virtual void VisitDebugTarget(RelocInfo* rinfo); |
| 7404 | |
| 7405 | // Handy shorthand for visiting a single pointer. |
| 7406 | virtual void VisitPointer(Object** p) { VisitPointers(p, p + 1); } |
| 7407 | |
| 7408 | // Visits a contiguous arrays of external references (references to the C++ |
| 7409 | // heap) in the half-open range [start, end). Any or all of the values |
| 7410 | // may be modified on return. |
| 7411 | virtual void VisitExternalReferences(Address* start, Address* end) {} |
| 7412 | |
| 7413 | inline void VisitExternalReference(Address* p) { |
| 7414 | VisitExternalReferences(p, p + 1); |
| 7415 | } |
| 7416 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 7417 | // Visits a handle that has an embedder-assigned class ID. |
| 7418 | virtual void VisitEmbedderReference(Object** p, uint16_t class_id) {} |
| 7419 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7420 | #ifdef DEBUG |
| 7421 | // Intended for serialization/deserialization checking: insert, or |
| 7422 | // check for the presence of, a tag at this position in the stream. |
| 7423 | virtual void Synchronize(const char* tag) {} |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 7424 | #else |
| 7425 | inline void Synchronize(const char* tag) {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7426 | #endif |
| 7427 | }; |
| 7428 | |
| 7429 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 7430 | class StructBodyDescriptor : public |
| 7431 | FlexibleBodyDescriptor<HeapObject::kHeaderSize> { |
| 7432 | public: |
| 7433 | static inline int SizeOf(Map* map, HeapObject* object) { |
| 7434 | return map->instance_size(); |
| 7435 | } |
| 7436 | }; |
| 7437 | |
| 7438 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7439 | // BooleanBit is a helper class for setting and getting a bit in an |
| 7440 | // integer or Smi. |
| 7441 | class BooleanBit : public AllStatic { |
| 7442 | public: |
| 7443 | static inline bool get(Smi* smi, int bit_position) { |
| 7444 | return get(smi->value(), bit_position); |
| 7445 | } |
| 7446 | |
| 7447 | static inline bool get(int value, int bit_position) { |
| 7448 | return (value & (1 << bit_position)) != 0; |
| 7449 | } |
| 7450 | |
| 7451 | static inline Smi* set(Smi* smi, int bit_position, bool v) { |
| 7452 | return Smi::FromInt(set(smi->value(), bit_position, v)); |
| 7453 | } |
| 7454 | |
| 7455 | static inline int set(int value, int bit_position, bool v) { |
| 7456 | if (v) { |
| 7457 | value |= (1 << bit_position); |
| 7458 | } else { |
| 7459 | value &= ~(1 << bit_position); |
| 7460 | } |
| 7461 | return value; |
| 7462 | } |
| 7463 | }; |
| 7464 | |
| 7465 | } } // namespace v8::internal |
| 7466 | |
| 7467 | #endif // V8_OBJECTS_H_ |